Skip to content

Commit f84423d

Browse files
committed
#1045 [QRCode] add: qr code generation
1 parent b4edbc7 commit f84423d

File tree

5 files changed

+141
-4
lines changed

5 files changed

+141
-4
lines changed

Diff for: admin/qrcode.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@
102102
print '<table class="noborder centpercent">';
103103
print '<tr class="liste_titre">';
104104
print '<td>' . $langs->trans('URL') . '</td>';
105-
print '<td class="center">' . $langs->trans('QR Code') . '</td>';
105+
print '<td class="text-blank
106+
">' . $langs->trans('QR Code') . '</td>';
106107
print '<td class="center">' . $langs->trans('ModuleName') . '</td>';
107108
print '<td class="center">' . $langs->trans('Action') . '</td>';
108109
print '</tr>';

Diff for: class/saturneqrcode.class.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
* \brief This file is a CRUD class file for SaturneQRCode (Create/Read/Update/Delete).
2222
*/
2323

24-
// Load Saturne libraries.
24+
// Load Saturne libraries
2525
require_once __DIR__ . '/saturneobject.class.php';
2626

27+
// Load QRCode library
28+
require_once DOL_DOCUMENT_ROOT . '/includes/tecnickcom/tcpdf/tcpdf_barcodes_2d.php';
29+
2730
class SaturneQRCode extends SaturneObject
2831
{
2932
/**

Diff for: js/modules/qrcode.js

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/* Copyright (C) 2024 EVARISK <[email protected]>
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
15+
*
16+
* Library javascript to enable Browser notifications
17+
*/
18+
19+
/**
20+
* \file js/modules/qrcode.js
21+
* \ingroup saturne
22+
* \brief JavaScript qrcode file for module Saturne
23+
*/
24+
25+
/**
26+
* Init qrcode JS
27+
*
28+
* @since 1.2.0
29+
* @version 1.2.0
30+
*/
31+
window.saturne.qrcode = {};
32+
33+
/**
34+
* QR Code init
35+
*
36+
* @since 1.2.0
37+
* @version 1.2.0
38+
*
39+
* @return {void}
40+
*/
41+
window.saturne.qrcode.init = function() {
42+
window.saturne.qrcode.event();
43+
};
44+
45+
/**
46+
* QR Code event
47+
*
48+
* @since 1.2.0
49+
* @version 1.2.0
50+
*
51+
* @return {void}
52+
*/
53+
window.saturne.qrcode.event = function() {
54+
$(document).on('click', '.preview-qr-code', window.saturne.qrcode.previewQRCode);
55+
};
56+
57+
58+
// Fonction pour afficher le QR code dans une modal
59+
window.saturne.qrcode.previewQRCode = function() {
60+
// Obtenir l'image du QR code à partir des données de l'élément
61+
let QRCodeBase64 = $(this).find('.qrcode-base64').val();
62+
63+
// Créer un élément d'image
64+
const img = document.createElement('img');
65+
img.src = QRCodeBase64;
66+
img.alt = 'QR Code';
67+
img.style.maxWidth = '100%';
68+
69+
// Insérer l'image dans le conteneur désigné
70+
const pdfPreview = document.getElementById('pdfPreview');
71+
pdfPreview.innerHTML = ''; // Vider le conteneur d'abord
72+
pdfPreview.appendChild(img);
73+
74+
// Afficher la modal
75+
$('#pdfModal').addClass('modal-active');
76+
77+
// Ajouter un bouton de téléchargement
78+
const downloadBtn = document.getElementById('downloadBtn');
79+
downloadBtn.onclick = function() {
80+
const a = document.createElement('a');
81+
a.href = QRCodeBase64;
82+
a.download = 'QRCode.png';
83+
a.click();
84+
};
85+
};

Diff for: js/saturne.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: lib/documents.lib.php

+49-1
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@
5252
*/
5353
function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, string $urlsource, $genallowed, int $delallowed = 0, string $modelselected = '', int $allowgenifempty = 1, int $forcenomultilang = 0, int $notused = 0, int $noform = 0, string $param = '', string $title = '', string $buttonlabel = '', string $codelang = '', string $morepicto = '', $object = null, int $hideifempty = 0, string $removeaction = 'remove_file', int $active = 1, string $tooltiptext = '', string $sortfield = '', string $sortorder = ''): string
5454
{
55-
global $conf, $db, $form, $hookmanager, $langs;
55+
global $conf, $db, $form, $hookmanager, $langs, $user;
5656

5757
if (!is_object($form)) {
5858
$form = new Form($db);
5959
}
6060

61+
require_once __DIR__ . '/../class/saturneqrcode.class.php';
62+
$QRCode = new SaturneQRCode($db);
63+
6164
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
6265

6366
// Add entity in $param if not already exists
@@ -288,6 +291,7 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str
288291
$out .= $form->textwithpicto($langs->trans('Help'), $htmltooltip, 1, 0);
289292
$out .= '</span>';
290293
}
294+
$out .= '</th><th>';
291295
$out .= '</th>';
292296

293297
if (!empty($hookmanager->hooks['formfile'])) {
@@ -308,6 +312,7 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str
308312
$out .= '<td></td>';
309313
$out .= get_document_title_search('date', 'Date', 'right');
310314
$out .= '<td></td>';
315+
$out .= '<td></td>';
311316
$out .= '<td class="right ">';
312317
$out .= '<i class="saturne-search-button fas fa-search" style="cursor: pointer;"></i>';
313318
$out .= '&nbsp;&nbsp;&nbsp;';
@@ -320,6 +325,7 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str
320325
$out .= get_document_title_field($sortfield, $sortorder, 'Size', true, 'right');
321326
$out .= get_document_title_field($sortfield, $sortorder, 'Date', true, 'right');
322327
$out .= get_document_title_field($sortfield, $sortorder, 'PDF', false, 'right');
328+
$out .= get_document_title_field($sortfield, $sortorder, 'QRCode', false, 'right');
323329
$out .= get_document_title_field($sortfield, $sortorder, 'Action', false, 'right');
324330
$out .= '</tr>';
325331

@@ -353,6 +359,28 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str
353359
$out .= '<table class="noborder centpercent" id="' . $modulepart . '_table">' . "\n";
354360
}
355361

362+
?>
363+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/pdf-lib.min.js"></script>
364+
365+
<?php
366+
367+
$out .= '<div id="pdfModal" class="wpeo-modal">
368+
<div class="modal-container">
369+
<div class="modal-header">
370+
<h2>QR Code</h2>
371+
</div>
372+
<div class="modal-content" style="display: flex; justify-content: center">
373+
<div id="pdfPreview">
374+
<!-- Le PDF sera affiché ici dans un iframe -->
375+
</div>
376+
</div>
377+
<div class="modal-footer">
378+
<button id="downloadBtn" style="margin-top: 10px;"><i class="fas fa-download fa-2x"></i></button>
379+
</div>
380+
</div>
381+
</div>';
382+
383+
356384
// Loop on each file found
357385
if (is_array($fileList)) {
358386
foreach ($fileList as $file) {
@@ -425,6 +453,26 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str
425453
$out .= '</td>';
426454
}
427455

456+
//Show QR Code
457+
$documentQRCode = $QRCode->fetchAll('', '', 0, 0, ['url' => $documenturl . '?modulepart=' . $modulepart . '&amp;file=' . urlencode($relativepath) . ($param ? '&' . $param : '')]);
458+
if (is_array($documentQRCode) && !empty($documentQRCode)) {
459+
$documentQRCode = array_shift($documentQRCode);
460+
} else {
461+
$QRCode->url = $documenturl . '?modulepart=' . $modulepart . '&amp;file=' . urlencode($relativepath) . ($param ? '&' . $param : '');
462+
$QRCode->encoded_qr_code = $QRCode->getQRCodeBase64($QRCode->url);
463+
$QRCode->status = 1;
464+
$QRCode->module_name = $modulepart;
465+
$QRCode->create($user);
466+
$documentQRCode = $QRCode;
467+
468+
}
469+
470+
$out .= '<td class="right preview-qr-code">';
471+
$out .= '<input hidden class="qrcode-base64" value="'. $documentQRCode->encoded_qr_code .'">';
472+
$out .= img_picto($langs->trans("QRCodeGeneration"), 'fontawesome_fa-qrcode_fas_blue');
473+
$out .= ' ' . $form->textwithpicto('', $langs->trans('QRCodeGenerationTooltip'));
474+
$out .= '</td>';
475+
428476
if ($delallowed || $morepicto) {
429477
$out .= '<td class="right nowraponall">';
430478
if ($delallowed) {

0 commit comments

Comments
 (0)