|
6 | 6 | $db = getDbInstance(); |
7 | 7 | $json = json_decode(file_get_contents('php://input'), true); |
8 | 8 |
|
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(); |
11 | 50 |
|
12 | | - if (isset($json['type'])) { |
13 | | - $type = filter_var($json['type'], FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
14 | | - } else { |
15 | 51 | echo json_encode([ |
16 | | - 'data' => 'Type action field in the request.', |
17 | | - 'status' => 400 |
| 52 | + 'data' => $url_path, |
| 53 | + 'status' => 200 |
18 | 54 | ]); |
19 | 55 | 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 | + } |
21 | 89 |
|
22 | | - if (count($params) == 0) { |
23 | 90 | echo json_encode([ |
24 | | - 'data' => 'No qrcodes were selected.', |
25 | | - 'status' => 400 |
| 91 | + 'action' => "delete", |
| 92 | + 'data' => "Qrcode deleted", |
| 93 | + 'status' => 200 |
26 | 94 | ]); |
27 | 95 | 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"); |
55 | 99 | } else { |
56 | 100 | exit('Direct access to this script not allowed.'); |
57 | 101 | } |
|
0 commit comments