Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 096c239

Browse files
bug fix in read.php, bump version in footer, NEW: bulk delete
1 parent 5bdcb8e commit 096c239

File tree

9 files changed

+130
-58
lines changed

9 files changed

+130
-58
lines changed

src/bulk_action.php

Lines changed: 82 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,96 @@
66
$db = getDbInstance();
77
$json = json_decode(file_get_contents('php://input'), true);
88

9-
$params = $json['params'];
10-
$files = [];
9+
if($json["action"] == "download") {
10+
$params = $json['params'];
11+
$files = [];
12+
13+
if (isset($json['type'])) {
14+
$type = filter_var($json['type'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
15+
} else {
16+
echo json_encode([
17+
'data' => 'Type action field in the request.',
18+
'status' => 400
19+
]);
20+
exit();
21+
}
22+
23+
if (count($params) == 0) {
24+
echo json_encode([
25+
'data' => 'No qrcodes were selected.',
26+
'status' => 400
27+
]);
28+
exit();
29+
}
30+
31+
foreach ($params as $param) {
32+
$row = $db->where('id', $param);
33+
$row = $db->getOne("{$type}_qrcodes");
34+
@$files[] = SAVED_QRCODE_FOLDER . $row['qrcode'];
35+
}
36+
37+
$zip = new ZipArchive();
38+
$uniqid = uniqid();
39+
$relative_dir = SAVED_QRCODE_FOLDER . 'zip/qrcodes_' . $uniqid . '.zip';
40+
@unlink($relative_dir);
41+
$url_path = SAVED_QRCODE_URL . 'zip/qrcodes_' . $uniqid . '.zip';
42+
$zip->open($relative_dir, ZipArchive::CREATE);
43+
44+
foreach ($files as $file) {
45+
$download_file = @file_get_contents($file, true);
46+
$zip->addFromString(basename($file), $download_file);
47+
}
48+
49+
$zip->close();
1150

12-
if (isset($json['type'])) {
13-
$type = filter_var($json['type'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
14-
} else {
1551
echo json_encode([
16-
'data' => 'Type action field in the request.',
17-
'status' => 400
52+
'data' => $url_path,
53+
'status' => 200
1854
]);
1955
exit();
20-
}
56+
} else if($json["action"] == "delete") {
57+
$params = $json['params'];
58+
$files = [];
59+
60+
if (isset($json['type'])) {
61+
$type = filter_var($json['type'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
62+
} else {
63+
echo json_encode([
64+
'data' => 'Type action field in the request.',
65+
'status' => 400
66+
]);
67+
exit();
68+
}
69+
70+
if (count($params) == 0) {
71+
echo json_encode([
72+
'data' => 'No qrcodes were selected.',
73+
'status' => 400
74+
]);
75+
exit();
76+
}
77+
78+
if($type == "dynamic")
79+
$instance = new DynamicQrcode();
80+
else if($type == "static")
81+
$instance = new StaticQrcode();
82+
else
83+
die("Type not allowed");
84+
85+
foreach ($params as $param) {
86+
$a = 0;
87+
$instance->deleteQrcode($param, true);
88+
}
2189

22-
if (count($params) == 0) {
2390
echo json_encode([
24-
'data' => 'No qrcodes were selected.',
25-
'status' => 400
91+
'action' => "delete",
92+
'data' => "Qrcode deleted",
93+
'status' => 200
2694
]);
2795
exit();
28-
}
29-
30-
foreach ($params as $param) {
31-
$row = $db->where('id', $param);
32-
$row = $db->getOne("{$type}_qrcodes");
33-
@$files[] = SAVED_QRCODE_FOLDER . $row['qrcode'];
34-
}
35-
36-
$zip = new ZipArchive();
37-
$uniqid = uniqid();
38-
$relative_dir = SAVED_QRCODE_FOLDER. 'zip/qrcodes_'. $uniqid .'.zip';
39-
@unlink($relative_dir);
40-
$url_path = SAVED_QRCODE_URL . 'zip/qrcodes_'. $uniqid .'.zip';
41-
$zip->open($relative_dir, ZipArchive::CREATE);
42-
43-
foreach ($files as $file) {
44-
$download_file = @file_get_contents($file, true);
45-
$zip->addFromString(basename($file), $download_file);
46-
}
47-
48-
$zip->close();
49-
50-
echo json_encode([
51-
'data' => $url_path,
52-
'status' => 200
53-
]);
54-
exit();
96+
97+
} else
98+
exit("Action not allowed");
5599
} else {
56100
exit('Direct access to this script not allowed.');
57101
}

src/dist/js/custom.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@
459459
});
460460

461461
const data = {
462-
action: 'download',
462+
action: $('select[name=action]').val(),
463463
params: params,
464464
type: $('input[name=type]').val()
465465
}
@@ -472,8 +472,12 @@
472472
contentType: 'application/json',
473473
success: (res) => {
474474
if (res.status == 200) {
475-
window.location.href = res.data;
476-
$('#err-msg').css('display', 'none');
475+
if(data["action"] === "download") {
476+
window.location.href = res.data;
477+
$('#err-msg').css('display', 'none');
478+
} else if(data["action"] === "delete") {
479+
location.reload();
480+
}
477481
}
478482

479483
if (res.status == 400) {

src/forms/table_dynamic.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@
33
<div id="err-msg"></div>
44
<div class="bulk-action-wrapper">
55
<form id="bulk-action" action="bulk_action.php" method="POST">
6-
<button type="submit" class="btn btn-primary">Download selected</button>
7-
<input type="hidden" name="type" value="dynamic">
6+
<div class="col-sm-12 mb-2" style="margin-left: 10px">
7+
<div class="row">
8+
<div class="col-5 col-md-2">
9+
<div class="input-group">
10+
<select name="action" class="form-control">
11+
<option value="download" selected >Download</option>
12+
<option value="delete">Delete</option>
13+
</select>
14+
<input type="hidden" name="type" value="dynamic">
15+
<button type="submit" class="btn btn-primary">Apply</button>
16+
</div>
17+
</div>
18+
</div>
19+
</div>
820
</form>
921
</div>
1022
</div>

src/forms/table_static.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@
33
<div id="err-msg"></div>
44
<div class="bulk-action-wrapper">
55
<form id="bulk-action" action="bulk_action.php" method="POST">
6-
<button type="submit" class="btn btn-primary">Download selected</button>
7-
<input type="hidden" name="type" value="dynamic">
6+
<div class="col-sm-12 mb-2" style="margin-left: 10px">
7+
<div class="row">
8+
<div class="col-5 col-md-2">
9+
<div class="input-group">
10+
<select name="action" class="form-control">
11+
<option value="download" selected >Download</option>
12+
<option value="delete">Delete</option>
13+
</select>
14+
<input type="hidden" name="type" value="static">
15+
<button type="submit" class="btn btn-primary">Apply</button>
16+
</div>
17+
</div>
18+
</div>
19+
</div>
820
</form>
921
</div>
1022
</div>

src/includes/footer.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
<!-- Main Footer -->
88
<footer class="main-footer text-sm">
9-
<strong>Copyright &copy; <?php echo date("Y");?> <a href="#">PHP Qrcode Generator</a> - </strong>
10-
All rights reserved by Giandonato Inverso.
9+
<strong><a href="https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code" target="_blank">PHP Qrcode Generator</a> by </strong> Giandonato Inverso
1110
<div class="float-right d-none d-sm-inline-block">
12-
<b>Version</b> 2.2.1
11+
<b>Version</b> 2.2.4
1312
</div>
1413
</footer>
1514
</div>
@@ -23,7 +22,7 @@
2322
<!-- AdminLTE App -->
2423
<script src="dist/js/adminlte.js"></script>
2524
<!-- AdminLTE Custom-->
26-
<script src="dist/js/custom.js"></script>
25+
<script src="dist/js/custom.js?nocache=<?php print rand();?>"></script>
2726
<!-- Color picker -->
2827
<script src="plugins/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js"></script>
2928
<!-- date-range-picker -->

src/lib/DynamicQrcode/DynamicQrcode.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ public function editQrcode($input_data) {
8989
* Delete qr code
9090
*
9191
*/
92-
public function deleteQrcode($id) {
92+
public function deleteQrcode($id, $async = false) {
9393
if($_SESSION['type'] === "super") {
94-
$this->qrcode_instance->deleteQrcode($id);
94+
$this->qrcode_instance->deleteQrcode($id, $async);
9595
} else if ($_SESSION['type'] === "admin") {
9696
$qrcode = $this->getQrcode($id);
9797

@@ -103,7 +103,7 @@ public function deleteQrcode($id) {
103103
$user = $users->getUser($_SESSION['user_id']);
104104

105105
if($user["id"] === $qrcode["id_owner"])
106-
$this->qrcode_instance->deleteQrcode($id);
106+
$this->qrcode_instance->deleteQrcode($id, $async);
107107
else
108108
$this->failure("You cannot delete this qrcode because it's of another user");
109109
}

src/lib/Qrcode/Qrcode.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function editQrcode($input_data, $data_to_db) {
155155
* Delete qr code
156156
*
157157
*/
158-
public function deleteQrcode($id) {
158+
public function deleteQrcode($id, $async = false) {
159159
$db = getDbInstance();
160160

161161
$qrcode = $this->getQrcode($id);
@@ -171,7 +171,8 @@ public function deleteQrcode($id) {
171171
}
172172

173173
if ($status)
174-
$this->info('Qr code deleted successfully!');
174+
if (!$async)
175+
$this->info('Qr code deleted successfully!');
175176
else
176177
$this->failure('Unable to delete qr code');
177178
}

src/lib/StaticQrcode/StaticQrcode.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,9 @@ public function editQrcode($input_data) {
390390
* Delete qr code
391391
*
392392
*/
393-
public function deleteQrcode($id) {
393+
public function deleteQrcode($id, $async = false) {
394394
if($_SESSION['type'] === "super") {
395-
$this->qrcode_instance->deleteQrcode($id);
395+
$this->qrcode_instance->deleteQrcode($id, $async);
396396
} else if ($_SESSION['type'] === "admin") {
397397
$qrcode = $this->getQrcode($id);
398398

@@ -404,7 +404,7 @@ public function deleteQrcode($id) {
404404
$user = $users->getUser($_SESSION['user_id']);
405405

406406
if($user["id"] === $qrcode["id_owner"])
407-
$this->qrcode_instance->deleteQrcode($id);
407+
$this->qrcode_instance->deleteQrcode($id, $async);
408408
else
409409
$this->failure("You cannot delete this qrcode because it's of another user");
410410
}

src/read.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'scan' => $db->inc(1)
1414
);
1515
$db->where("identifier", $_GET['id']);
16-
$db->update (DATABASE_PREFIX.'dynamic_qrcodes', $data);
16+
$db->update ('dynamic_qrcodes', $data);
1717

1818
if($qrcode['state'] == 'enable'){
1919
echo '<meta http-equiv="refresh" content="0; URL='.$qrcode['link'].'" />';

0 commit comments

Comments
 (0)