bug fix in read.php, bump version in footer, NEW: bulk delete

This commit is contained in:
giandonato.inverso@edempg.it
2024-04-18 20:33:20 +02:00
parent eba0ebbba7
commit 9f2d14abf8
9 changed files with 129 additions and 57 deletions
+46 -2
View File
@@ -6,6 +6,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$db = getDbInstance();
$json = json_decode(file_get_contents('php://input'), true);
if($json["action"] == "download") {
$params = $json['params'];
$files = [];
@@ -35,9 +36,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$zip = new ZipArchive();
$uniqid = uniqid();
$relative_dir = SAVED_QRCODE_FOLDER. 'zip/qrcodes_'. $uniqid .'.zip';
$relative_dir = SAVED_QRCODE_FOLDER . 'zip/qrcodes_' . $uniqid . '.zip';
@unlink($relative_dir);
$url_path = SAVED_QRCODE_URL . 'zip/qrcodes_'. $uniqid .'.zip';
$url_path = SAVED_QRCODE_URL . 'zip/qrcodes_' . $uniqid . '.zip';
$zip->open($relative_dir, ZipArchive::CREATE);
foreach ($files as $file) {
@@ -52,6 +53,49 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
'status' => 200
]);
exit();
} else if($json["action"] == "delete") {
$params = $json['params'];
$files = [];
if (isset($json['type'])) {
$type = filter_var($json['type'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
} else {
echo json_encode([
'data' => 'Type action field in the request.',
'status' => 400
]);
exit();
}
if (count($params) == 0) {
echo json_encode([
'data' => 'No qrcodes were selected.',
'status' => 400
]);
exit();
}
if($type == "dynamic")
$instance = new DynamicQrcode();
else if($type == "static")
$instance = new StaticQrcode();
else
die("Type not allowed");
foreach ($params as $param) {
$a = 0;
$instance->deleteQrcode($param, true);
}
echo json_encode([
'action' => "delete",
'data' => "Qrcode deleted",
'status' => 200
]);
exit();
} else
exit("Action not allowed");
} else {
exit('Direct access to this script not allowed.');
}
+5 -1
View File
@@ -459,7 +459,7 @@
});
const data = {
action: 'download',
action: $('select[name=action]').val(),
params: params,
type: $('input[name=type]').val()
}
@@ -472,8 +472,12 @@
contentType: 'application/json',
success: (res) => {
if (res.status == 200) {
if(data["action"] === "download") {
window.location.href = res.data;
$('#err-msg').css('display', 'none');
} else if(data["action"] === "delete") {
location.reload();
}
}
if (res.status == 400) {
+13 -1
View File
@@ -3,8 +3,20 @@
<div id="err-msg"></div>
<div class="bulk-action-wrapper">
<form id="bulk-action" action="bulk_action.php" method="POST">
<button type="submit" class="btn btn-primary">Download selected</button>
<div class="col-sm-12 mb-2" style="margin-left: 10px">
<div class="row">
<div class="col-5 col-md-2">
<div class="input-group">
<select name="action" class="form-control">
<option value="download" selected >Download</option>
<option value="delete">Delete</option>
</select>
<input type="hidden" name="type" value="dynamic">
<button type="submit" class="btn btn-primary">Apply</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
+14 -2
View File
@@ -3,8 +3,20 @@
<div id="err-msg"></div>
<div class="bulk-action-wrapper">
<form id="bulk-action" action="bulk_action.php" method="POST">
<button type="submit" class="btn btn-primary">Download selected</button>
<input type="hidden" name="type" value="dynamic">
<div class="col-sm-12 mb-2" style="margin-left: 10px">
<div class="row">
<div class="col-5 col-md-2">
<div class="input-group">
<select name="action" class="form-control">
<option value="download" selected >Download</option>
<option value="delete">Delete</option>
</select>
<input type="hidden" name="type" value="static">
<button type="submit" class="btn btn-primary">Apply</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
+3 -4
View File
@@ -6,10 +6,9 @@
<!-- Main Footer -->
<footer class="main-footer text-sm">
<strong>Copyright &copy; <?php echo date("Y");?> <a href="#">PHP Qrcode Generator</a> - </strong>
All rights reserved by Giandonato Inverso.
<strong><a href="https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code" target="_blank">PHP Qrcode Generator</a> by </strong> Giandonato Inverso
<div class="float-right d-none d-sm-inline-block">
<b>Version</b> 2.2.1
<b>Version</b> 2.2.4
</div>
</footer>
</div>
@@ -23,7 +22,7 @@
<!-- AdminLTE App -->
<script src="dist/js/adminlte.js"></script>
<!-- AdminLTE Custom-->
<script src="dist/js/custom.js"></script>
<script src="dist/js/custom.js?nocache=<?php print rand();?>"></script>
<!-- Color picker -->
<script src="plugins/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js"></script>
<!-- date-range-picker -->
+3 -3
View File
@@ -89,9 +89,9 @@ class DynamicQrcode {
* Delete qr code
*
*/
public function deleteQrcode($id) {
public function deleteQrcode($id, $async = false) {
if($_SESSION['type'] === "super") {
$this->qrcode_instance->deleteQrcode($id);
$this->qrcode_instance->deleteQrcode($id, $async);
} else if ($_SESSION['type'] === "admin") {
$qrcode = $this->getQrcode($id);
@@ -103,7 +103,7 @@ class DynamicQrcode {
$user = $users->getUser($_SESSION['user_id']);
if($user["id"] === $qrcode["id_owner"])
$this->qrcode_instance->deleteQrcode($id);
$this->qrcode_instance->deleteQrcode($id, $async);
else
$this->failure("You cannot delete this qrcode because it's of another user");
}
+2 -1
View File
@@ -155,7 +155,7 @@ class Qrcode {
* Delete qr code
*
*/
public function deleteQrcode($id) {
public function deleteQrcode($id, $async = false) {
$db = getDbInstance();
$qrcode = $this->getQrcode($id);
@@ -171,6 +171,7 @@ class Qrcode {
}
if ($status)
if (!$async)
$this->info('Qr code deleted successfully!');
else
$this->failure('Unable to delete qr code');
+3 -3
View File
@@ -390,9 +390,9 @@ class StaticQrcode {
* Delete qr code
*
*/
public function deleteQrcode($id) {
public function deleteQrcode($id, $async = false) {
if($_SESSION['type'] === "super") {
$this->qrcode_instance->deleteQrcode($id);
$this->qrcode_instance->deleteQrcode($id, $async);
} else if ($_SESSION['type'] === "admin") {
$qrcode = $this->getQrcode($id);
@@ -404,7 +404,7 @@ class StaticQrcode {
$user = $users->getUser($_SESSION['user_id']);
if($user["id"] === $qrcode["id_owner"])
$this->qrcode_instance->deleteQrcode($id);
$this->qrcode_instance->deleteQrcode($id, $async);
else
$this->failure("You cannot delete this qrcode because it's of another user");
}
+1 -1
View File
@@ -13,7 +13,7 @@ $data = array (
'scan' => $db->inc(1)
);
$db->where("identifier", $_GET['id']);
$db->update (DATABASE_PREFIX.'dynamic_qrcodes', $data);
$db->update ('dynamic_qrcodes', $data);
if($qrcode['state'] == 'enable'){
echo '<meta http-equiv="refresh" content="0; URL='.$qrcode['link'].'" />';