From 9cf354910be04f8cc7a546a0c2a0291339f1cb29 Mon Sep 17 00:00:00 2001 From: 0xRenegade Date: Sat, 24 Sep 2022 15:14:20 -0500 Subject: [PATCH] download multiple qrcodes at once feature --- qrcode/bulk_action.php | 50 +++++++++++++++++++++++++++++ qrcode/dist/css/custom.css | 6 +++- qrcode/dist/js/custom.js | 55 ++++++++++++++++++++++++++++++++ qrcode/forms/dynamic_table.php | 26 +++++++++++++++ qrcode/forms/static_table.php | 26 +++++++++++++++ qrcode/saved_qrcode/zip/.gitkeep | 0 6 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 qrcode/bulk_action.php create mode 100644 qrcode/saved_qrcode/zip/.gitkeep diff --git a/qrcode/bulk_action.php b/qrcode/bulk_action.php new file mode 100644 index 0000000..9e33274 --- /dev/null +++ b/qrcode/bulk_action.php @@ -0,0 +1,50 @@ + +* @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.'); +} +?> \ No newline at end of file diff --git a/qrcode/dist/css/custom.css b/qrcode/dist/css/custom.css index 44e5f47..bdce243 100644 --- a/qrcode/dist/css/custom.css +++ b/qrcode/dist/css/custom.css @@ -6,4 +6,8 @@ * @license https://opensource.org/licenses/MIT MIT License * @link https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code * @version 1.0 -*/ \ No newline at end of file +*/ + +.bulk-action-wrapper { + padding: 10px 0; +} \ No newline at end of file diff --git a/qrcode/dist/js/custom.js b/qrcode/dist/js/custom.js index 595fce1..c132f2b 100644 --- a/qrcode/dist/js/custom.js +++ b/qrcode/dist/js/custom.js @@ -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) \ No newline at end of file diff --git a/qrcode/forms/dynamic_table.php b/qrcode/forms/dynamic_table.php index f910cc6..3db28f5 100644 --- a/qrcode/forms/dynamic_table.php +++ b/qrcode/forms/dynamic_table.php @@ -1,10 +1,23 @@
+
+
+
+ + + +
+
+
+ @@ -17,6 +30,7 @@ + @@ -73,4 +87,16 @@ +
+
+
+ + + + +
+
\ No newline at end of file diff --git a/qrcode/forms/static_table.php b/qrcode/forms/static_table.php index d210bb6..12888e1 100644 --- a/qrcode/forms/static_table.php +++ b/qrcode/forms/static_table.php @@ -1,10 +1,23 @@
+
+
+
+ + + + +
+
ID Filename Unique redirect identifier
+ @@ -16,6 +29,7 @@ + @@ -71,4 +85,16 @@ +
+
+
+ + + + +
+
\ No newline at end of file diff --git a/qrcode/saved_qrcode/zip/.gitkeep b/qrcode/saved_qrcode/zip/.gitkeep new file mode 100644 index 0000000..e69de29
ID Filename Type