download multiple qrcodes at once feature
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Dynamic Qr code
|
||||
*
|
||||
* @author Giandonato Inverso <info@giandonatoinverso.it>
|
||||
* @copyright Copyright (c) 2020-2021
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
session_start();
|
||||
require_once 'config/config.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$db = getDbInstance();
|
||||
$json = json_decode(file_get_contents('php://input'), true);
|
||||
$action = filter_var($json['action'], FILTER_SANITIZE_STRING);
|
||||
$params = $json['params'];
|
||||
$files = [];
|
||||
$type = filter_var($json['type'], FILTER_SANITIZE_STRING);
|
||||
|
||||
foreach ($params as $param) {
|
||||
$row = $db->where('id', $param);
|
||||
$row = $db->getOne("{$type}_qrcodes");
|
||||
$files[] = './saved_qrcode/' . $row['qrcode'];
|
||||
}
|
||||
|
||||
$zip = new ZipArchive();
|
||||
$relative_dir = './saved_qrcode/zip/qrcodes_'. $_SESSION['user_id'] .'.zip';
|
||||
unlink($relative_dir);
|
||||
$url_path = base_url() . '/saved_qrcode/zip/qrcodes_'. $_SESSION['user_id'] .'.zip';
|
||||
$zip->open($relative_dir, ZipArchive::CREATE);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$download_file = file_get_contents($file, true);
|
||||
$zip->addFromString(basename($file), $download_file);
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
|
||||
echo json_encode([
|
||||
'data' => $url_path,
|
||||
'status' => 200
|
||||
]);
|
||||
exit();
|
||||
} else {
|
||||
exit('Direct access to this script not allowed.');
|
||||
}
|
||||
?>
|
||||
Vendored
+4
@@ -7,3 +7,7 @@
|
||||
* @link https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
.bulk-action-wrapper {
|
||||
padding: 10px 0;
|
||||
}
|
||||
Vendored
+55
@@ -421,4 +421,59 @@
|
||||
$('.product-image-thumb.active').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
});
|
||||
|
||||
const bulk_action = $('input[name=bulk-select]');
|
||||
|
||||
if (bulk_action) {
|
||||
bulk_action.on('change', function() {
|
||||
if ($(this).prop('checked')) {
|
||||
$('input[name^=action]').each(function() {
|
||||
$(this).prop('checked', true);
|
||||
});
|
||||
} else {
|
||||
$('input[name^=action]').each(function() {
|
||||
$(this).prop('checked', false);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const bulk_form = $('form#bulk-action');
|
||||
|
||||
bulk_form.on('submit', function(e) {
|
||||
e.preventDefault();
|
||||
const paramsElements = document.querySelectorAll('input[name^=action]');
|
||||
console.log(paramsElements);
|
||||
let params = [];
|
||||
|
||||
paramsElements.forEach((val) => {
|
||||
if (val.checked) {
|
||||
params.push(val.value);
|
||||
}
|
||||
});
|
||||
|
||||
const data = {
|
||||
action: $('select[name=bulk-action]').val(),
|
||||
params: params,
|
||||
type: $('input[name=type]').val()
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: window.location.origin + '/bulk_action.php',
|
||||
method: "POST",
|
||||
data: JSON.stringify(data),
|
||||
dataType: "json",
|
||||
contentType: 'application/json',
|
||||
success: (res) => {
|
||||
if (res.status == 200) {
|
||||
window.location.href = res.data;
|
||||
}
|
||||
},
|
||||
error: (err) => {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
})(jQuery)
|
||||
@@ -1,10 +1,23 @@
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="bulk-action-wrapper">
|
||||
<form id="bulk-action" action="/bulk_action.php" method="POST">
|
||||
<button type="submit" class="btn btn-primary">Bulk Action</button>
|
||||
<select name="bulk-action">
|
||||
<option value="">------ Select Option -------</option>
|
||||
<option value="download">Download QRCode(s)</option>
|
||||
</select>
|
||||
<input type="hidden" name="type" value="dynamic">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-body table-responsive p-0">
|
||||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="5%"><input type="checkbox" name="bulk-select" value="1"></th>
|
||||
<th width="5%">ID</th>
|
||||
<th width="15%">Filename</th>
|
||||
<th width="18%">Unique redirect identifier</th>
|
||||
@@ -17,6 +30,7 @@
|
||||
<tbody>
|
||||
<?php foreach ($rows as $row): ?>
|
||||
<tr>
|
||||
<td><input type="checkbox" name="action[]" value="<?=$row['id']?>"></td>
|
||||
<td><?php echo $row['id']; ?></td>
|
||||
<td><?php echo htmlspecialchars($row['filename']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['identifier']); ?></td>
|
||||
@@ -73,4 +87,16 @@
|
||||
|
||||
</div><!-- /.Card -->
|
||||
</div><!-- /.col -->
|
||||
<div class="col-12">
|
||||
<div class="bulk-action-wrapper">
|
||||
<form id="bulk-action" action="/bulk_action.php" method="POST">
|
||||
<button type="submit" class="btn btn-primary">Bulk Action</button>
|
||||
<select name="bulk-action">
|
||||
<option value="">------ Select Option -------</option>
|
||||
<option value="download">Download QRCode(s)</option>
|
||||
</select>
|
||||
<input type="hidden" name="type" value="dynamic">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /.row -->
|
||||
@@ -1,10 +1,23 @@
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="bulk-action-wrapper">
|
||||
<form id="bulk-action" action="/bulk_action.php" method="POST">
|
||||
<button type="submit" class="btn btn-primary">Bulk Action</button>
|
||||
<select name="bulk-action">
|
||||
<option value="">------ Select Option -------</option>
|
||||
<option value="download">Download QRCode(s)</option>
|
||||
<input type="hidden" name="type" value="static">
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-body table-responsive p-0">
|
||||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="5%"><input type="checkbox" name="bulk-select" value="1"></th>
|
||||
<th width="5%">ID</th>
|
||||
<th width="12%">Filename</th>
|
||||
<th width="7%">Type</th>
|
||||
@@ -16,6 +29,7 @@
|
||||
<tbody>
|
||||
<?php foreach ($rows as $row): ?>
|
||||
<tr>
|
||||
<td><input type="checkbox" name="action[]" value="<?=$row['id']?>"></td>
|
||||
<td><?php echo $row['id']; ?></td>
|
||||
<td><?php echo htmlspecialchars($row['filename']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['type']); ?></td>
|
||||
@@ -71,4 +85,16 @@
|
||||
|
||||
</div><!-- /.Card -->
|
||||
</div><!-- /.col -->
|
||||
<div class="col-12">
|
||||
<div class="bulk-action-wrapper">
|
||||
<form id="bulk-action" action="/bulk_action.php" method="POST">
|
||||
<button type="submit" class="btn btn-primary">Bulk Action</button>
|
||||
<select name="bulk-action">
|
||||
<option value="">------ Select Option -------</option>
|
||||
<option value="download">Download QRCode(s)</option>
|
||||
<input type="hidden" name="type" value="static">
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /.row -->
|
||||
Reference in New Issue
Block a user