-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1045 [QRCode] add: qr code generation
- Loading branch information
1 parent
b4edbc7
commit f84423d
Showing
5 changed files
with
141 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* Copyright (C) 2024 EVARISK <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* Library javascript to enable Browser notifications | ||
*/ | ||
|
||
/** | ||
* \file js/modules/qrcode.js | ||
* \ingroup saturne | ||
* \brief JavaScript qrcode file for module Saturne | ||
*/ | ||
|
||
/** | ||
* Init qrcode JS | ||
* | ||
* @since 1.2.0 | ||
* @version 1.2.0 | ||
*/ | ||
window.saturne.qrcode = {}; | ||
|
||
/** | ||
* QR Code init | ||
* | ||
* @since 1.2.0 | ||
* @version 1.2.0 | ||
* | ||
* @return {void} | ||
*/ | ||
window.saturne.qrcode.init = function() { | ||
window.saturne.qrcode.event(); | ||
}; | ||
|
||
/** | ||
* QR Code event | ||
* | ||
* @since 1.2.0 | ||
* @version 1.2.0 | ||
* | ||
* @return {void} | ||
*/ | ||
window.saturne.qrcode.event = function() { | ||
$(document).on('click', '.preview-qr-code', window.saturne.qrcode.previewQRCode); | ||
}; | ||
|
||
|
||
// Fonction pour afficher le QR code dans une modal | ||
window.saturne.qrcode.previewQRCode = function() { | ||
// Obtenir l'image du QR code à partir des données de l'élément | ||
let QRCodeBase64 = $(this).find('.qrcode-base64').val(); | ||
|
||
// Créer un élément d'image | ||
const img = document.createElement('img'); | ||
img.src = QRCodeBase64; | ||
img.alt = 'QR Code'; | ||
img.style.maxWidth = '100%'; | ||
|
||
// Insérer l'image dans le conteneur désigné | ||
const pdfPreview = document.getElementById('pdfPreview'); | ||
pdfPreview.innerHTML = ''; // Vider le conteneur d'abord | ||
pdfPreview.appendChild(img); | ||
|
||
// Afficher la modal | ||
$('#pdfModal').addClass('modal-active'); | ||
|
||
// Ajouter un bouton de téléchargement | ||
const downloadBtn = document.getElementById('downloadBtn'); | ||
downloadBtn.onclick = function() { | ||
const a = document.createElement('a'); | ||
a.href = QRCodeBase64; | ||
a.download = 'QRCode.png'; | ||
a.click(); | ||
}; | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,12 +52,15 @@ | |
*/ | ||
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 | ||
{ | ||
global $conf, $db, $form, $hookmanager, $langs; | ||
global $conf, $db, $form, $hookmanager, $langs, $user; | ||
|
||
if (!is_object($form)) { | ||
$form = new Form($db); | ||
} | ||
|
||
require_once __DIR__ . '/../class/saturneqrcode.class.php'; | ||
$QRCode = new SaturneQRCode($db); | ||
|
||
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; | ||
|
||
// Add entity in $param if not already exists | ||
|
@@ -288,6 +291,7 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str | |
$out .= $form->textwithpicto($langs->trans('Help'), $htmltooltip, 1, 0); | ||
$out .= '</span>'; | ||
} | ||
$out .= '</th><th>'; | ||
$out .= '</th>'; | ||
|
||
if (!empty($hookmanager->hooks['formfile'])) { | ||
|
@@ -308,6 +312,7 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str | |
$out .= '<td></td>'; | ||
$out .= get_document_title_search('date', 'Date', 'right'); | ||
$out .= '<td></td>'; | ||
$out .= '<td></td>'; | ||
$out .= '<td class="right ">'; | ||
$out .= '<i class="saturne-search-button fas fa-search" style="cursor: pointer;"></i>'; | ||
$out .= ' '; | ||
|
@@ -320,6 +325,7 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str | |
$out .= get_document_title_field($sortfield, $sortorder, 'Size', true, 'right'); | ||
$out .= get_document_title_field($sortfield, $sortorder, 'Date', true, 'right'); | ||
$out .= get_document_title_field($sortfield, $sortorder, 'PDF', false, 'right'); | ||
$out .= get_document_title_field($sortfield, $sortorder, 'QRCode', false, 'right'); | ||
$out .= get_document_title_field($sortfield, $sortorder, 'Action', false, 'right'); | ||
$out .= '</tr>'; | ||
|
||
|
@@ -353,6 +359,28 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str | |
$out .= '<table class="noborder centpercent" id="' . $modulepart . '_table">' . "\n"; | ||
} | ||
|
||
?> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/pdf-lib.min.js"></script> | ||
|
||
<?php | ||
|
||
$out .= '<div id="pdfModal" class="wpeo-modal"> | ||
<div class="modal-container"> | ||
<div class="modal-header"> | ||
<h2>QR Code</h2> | ||
</div> | ||
<div class="modal-content" style="display: flex; justify-content: center"> | ||
<div id="pdfPreview"> | ||
<!-- Le PDF sera affiché ici dans un iframe --> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button id="downloadBtn" style="margin-top: 10px;"><i class="fas fa-download fa-2x"></i></button> | ||
</div> | ||
</div> | ||
</div>'; | ||
|
||
|
||
// Loop on each file found | ||
if (is_array($fileList)) { | ||
foreach ($fileList as $file) { | ||
|
@@ -425,6 +453,26 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str | |
$out .= '</td>'; | ||
} | ||
|
||
//Show QR Code | ||
$documentQRCode = $QRCode->fetchAll('', '', 0, 0, ['url' => $documenturl . '?modulepart=' . $modulepart . '&file=' . urlencode($relativepath) . ($param ? '&' . $param : '')]); | ||
if (is_array($documentQRCode) && !empty($documentQRCode)) { | ||
$documentQRCode = array_shift($documentQRCode); | ||
} else { | ||
$QRCode->url = $documenturl . '?modulepart=' . $modulepart . '&file=' . urlencode($relativepath) . ($param ? '&' . $param : ''); | ||
$QRCode->encoded_qr_code = $QRCode->getQRCodeBase64($QRCode->url); | ||
$QRCode->status = 1; | ||
$QRCode->module_name = $modulepart; | ||
$QRCode->create($user); | ||
$documentQRCode = $QRCode; | ||
|
||
} | ||
|
||
$out .= '<td class="right preview-qr-code">'; | ||
$out .= '<input hidden class="qrcode-base64" value="'. $documentQRCode->encoded_qr_code .'">'; | ||
$out .= img_picto($langs->trans("QRCodeGeneration"), 'fontawesome_fa-qrcode_fas_blue'); | ||
$out .= ' ' . $form->textwithpicto('', $langs->trans('QRCodeGenerationTooltip')); | ||
$out .= '</td>'; | ||
|
||
if ($delallowed || $morepicto) { | ||
$out .= '<td class="right nowraponall">'; | ||
if ($delallowed) { | ||
|