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

Commit a6b2b29

Browse files
Merge pull request #36 from 0xRenegade/feature/download-multiple-qr-img-at-once
Feature/download multiple qr img at once
2 parents b5aec38 + dac89ba commit a6b2b29

File tree

8 files changed

+182
-1
lines changed

8 files changed

+182
-1
lines changed

qrcode/bulk_action.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* PHP Dynamic Qr code
4+
*
5+
* @author Giandonato Inverso <[email protected]>
6+
* @copyright Copyright (c) 2020-2021
7+
* @license https://opensource.org/licenses/MIT MIT License
8+
* @link https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code
9+
* @version 1.0
10+
*/
11+
12+
session_start();
13+
require_once 'config/config.php';
14+
15+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
16+
$db = getDbInstance();
17+
$json = json_decode(file_get_contents('php://input'), true);
18+
$action = filter_var($json['action'], FILTER_SANITIZE_STRING);
19+
$params = $json['params'];
20+
$files = [];
21+
$type = filter_var($json['type'], FILTER_SANITIZE_STRING);
22+
23+
foreach ($params as $param) {
24+
$row = $db->where('id', $param);
25+
$row = $db->getOne("{$type}_qrcodes");
26+
$files[] = './saved_qrcode/' . $row['qrcode'];
27+
}
28+
29+
$zip = new ZipArchive();
30+
$relative_dir = './saved_qrcode/zip/qrcodes_'. $_SESSION['user_id'] .'.zip';
31+
unlink($relative_dir);
32+
$url_path = base_url() . '/saved_qrcode/zip/qrcodes_'. $_SESSION['user_id'] .'.zip';
33+
$zip->open($relative_dir, ZipArchive::CREATE);
34+
35+
foreach ($files as $file) {
36+
$download_file = file_get_contents($file, true);
37+
$zip->addFromString(basename($file), $download_file);
38+
}
39+
40+
$zip->close();
41+
42+
echo json_encode([
43+
'data' => $url_path,
44+
'status' => 200
45+
]);
46+
exit();
47+
} else {
48+
exit('Direct access to this script not allowed.');
49+
}
50+
?>

qrcode/dist/css/custom.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* PHP Dynamic Qr code
3+
*
4+
* @author Giandonato Inverso <[email protected]>
5+
* @copyright Copyright (c) 2020-2021
6+
* @license https://opensource.org/licenses/MIT MIT License
7+
* @link https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code
8+
* @version 1.0
9+
*/
10+
11+
.bulk-action-wrapper {
12+
padding: 10px 0;
13+
}

qrcode/dist/js/custom.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,59 @@
421421
$('.product-image-thumb.active').removeClass('active');
422422
$(this).addClass('active');
423423
});
424+
425+
const bulk_action = $('input[name=bulk-select]');
426+
427+
if (bulk_action) {
428+
bulk_action.on('change', function() {
429+
if ($(this).prop('checked')) {
430+
$('input[name^=action]').each(function() {
431+
$(this).prop('checked', true);
432+
});
433+
} else {
434+
$('input[name^=action]').each(function() {
435+
$(this).prop('checked', false);
436+
});
437+
}
438+
});
439+
}
440+
441+
const bulk_form = $('form#bulk-action');
442+
443+
bulk_form.on('submit', function(e) {
444+
e.preventDefault();
445+
const paramsElements = document.querySelectorAll('input[name^=action]');
446+
console.log(paramsElements);
447+
let params = [];
448+
449+
paramsElements.forEach((val) => {
450+
if (val.checked) {
451+
params.push(val.value);
452+
}
453+
});
454+
455+
const data = {
456+
action: $('select[name=bulk-action]').val(),
457+
params: params,
458+
type: $('input[name=type]').val()
459+
}
460+
461+
$.ajax({
462+
url: window.location.origin + '/bulk_action.php',
463+
method: "POST",
464+
data: JSON.stringify(data),
465+
dataType: "json",
466+
contentType: 'application/json',
467+
success: (res) => {
468+
if (res.status == 200) {
469+
window.location.href = res.data;
470+
}
471+
},
472+
error: (err) => {
473+
console.log(err);
474+
}
475+
});
476+
477+
return false;
478+
});
424479
})(jQuery)

qrcode/forms/dynamic_table.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
<div class="row">
2+
<div class="col-12">
3+
<div class="bulk-action-wrapper">
4+
<form id="bulk-action" action="/bulk_action.php" method="POST">
5+
<button type="submit" class="btn btn-primary">Bulk Action</button>
6+
<select name="bulk-action">
7+
<option value="">------ Select Option -------</option>
8+
<option value="download">Download QRCode(s)</option>
9+
</select>
10+
<input type="hidden" name="type" value="dynamic">
11+
</form>
12+
</div>
13+
</div>
214
<div class="col-12">
315
<div class="card">
416
<div class="card-body table-responsive p-0">
517
<table class="table table-striped table-bordered">
618
<thead>
719
<tr>
20+
<th width="5%"><input type="checkbox" name="bulk-select" value="1"></th>
821
<th width="5%">ID</th>
922
<th width="15%">Filename</th>
1023
<th width="18%">Unique redirect identifier</th>
@@ -17,6 +30,7 @@
1730
<tbody>
1831
<?php foreach ($rows as $row): ?>
1932
<tr>
33+
<td><input type="checkbox" name="action[]" value="<?=$row['id']?>"></td>
2034
<td><?php echo $row['id']; ?></td>
2135
<td><?php echo htmlspecialchars($row['filename']); ?></td>
2236
<td><?php echo htmlspecialchars($row['identifier']); ?></td>
@@ -73,4 +87,16 @@
7387

7488
</div><!-- /.Card -->
7589
</div><!-- /.col -->
90+
<div class="col-12">
91+
<div class="bulk-action-wrapper">
92+
<form id="bulk-action" action="/bulk_action.php" method="POST">
93+
<button type="submit" class="btn btn-primary">Bulk Action</button>
94+
<select name="bulk-action">
95+
<option value="">------ Select Option -------</option>
96+
<option value="download">Download QRCode(s)</option>
97+
</select>
98+
<input type="hidden" name="type" value="dynamic">
99+
</form>
100+
</div>
101+
</div>
76102
</div><!-- /.row -->

qrcode/forms/static_table.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
<div class="row">
2+
<div class="col-12">
3+
<div class="bulk-action-wrapper">
4+
<form id="bulk-action" action="/bulk_action.php" method="POST">
5+
<button type="submit" class="btn btn-primary">Bulk Action</button>
6+
<select name="bulk-action">
7+
<option value="">------ Select Option -------</option>
8+
<option value="download">Download QRCode(s)</option>
9+
<input type="hidden" name="type" value="static">
10+
</select>
11+
</form>
12+
</div>
13+
</div>
214
<div class="col-12">
315
<div class="card">
416
<div class="card-body table-responsive p-0">
517
<table class="table table-striped table-bordered">
618
<thead>
719
<tr>
20+
<th width="5%"><input type="checkbox" name="bulk-select" value="1"></th>
821
<th width="5%">ID</th>
922
<th width="12%">Filename</th>
1023
<th width="7%">Type</th>
@@ -16,6 +29,7 @@
1629
<tbody>
1730
<?php foreach ($rows as $row): ?>
1831
<tr>
32+
<td><input type="checkbox" name="action[]" value="<?=$row['id']?>"></td>
1933
<td><?php echo $row['id']; ?></td>
2034
<td><?php echo htmlspecialchars($row['filename']); ?></td>
2135
<td><?php echo htmlspecialchars($row['type']); ?></td>
@@ -71,4 +85,16 @@
7185

7286
</div><!-- /.Card -->
7387
</div><!-- /.col -->
88+
<div class="col-12">
89+
<div class="bulk-action-wrapper">
90+
<form id="bulk-action" action="/bulk_action.php" method="POST">
91+
<button type="submit" class="btn btn-primary">Bulk Action</button>
92+
<select name="bulk-action">
93+
<option value="">------ Select Option -------</option>
94+
<option value="download">Download QRCode(s)</option>
95+
<input type="hidden" name="type" value="static">
96+
</select>
97+
</form>
98+
</div>
99+
</div>
74100
</div><!-- /.row -->

qrcode/helpers/helpers.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,12 @@ function paginationLinks($current_page, $total_pages, $base_url) {
116116

117117
return $html;
118118
}
119+
120+
function base_url(){
121+
return sprintf(
122+
"%s://%s:%s",
123+
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
124+
$_SERVER['SERVER_NAME'],
125+
$_SERVER['SERVER_PORT']
126+
);
127+
}

qrcode/includes/head.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515
<!-- Overlay Scrollbar -->
1616
<link type="text/css" href="plugins/overlayScrollbars/css/OverlayScrollbars.css" rel="stylesheet"/>
1717
<!-- Google Font: Source Sans Pro -->
18-
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
18+
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
19+
<!-- Custom Styles -->
20+
<link rel="stylesheet" href="dist/css/custom.css">

qrcode/saved_qrcode/zip/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)