Skip to content

Commit b4edbc7

Browse files
committed
#1045 [QRCode] add: qr code config page & rename sql files
1 parent 0b05904 commit b4edbc7

File tree

5 files changed

+172
-1
lines changed

5 files changed

+172
-1
lines changed

admin/qrcode.php

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?php
2+
/* Copyright (C) 2021-2023 EVARISK
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
/**
19+
* \file admin/redirections.php
20+
* \ingroup saturne
21+
* \brief Saturne redirections page
22+
*/
23+
24+
// Load Saturne environment
25+
if (file_exists('../saturne.main.inc.php')) {
26+
require_once __DIR__ . '/../saturne.main.inc.php';
27+
} elseif (file_exists('../../saturne.main.inc.php')) {
28+
require_once __DIR__ . '/../../saturne.main.inc.php';
29+
} else {
30+
die('Include of saturne main fails');
31+
}
32+
33+
// Get module parameters
34+
$moduleName = GETPOST('module_name', 'alpha');
35+
$moduleNameLowerCase = strtolower($moduleName);
36+
37+
// Load Dolibarr libraries
38+
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
39+
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
40+
require_once DOL_DOCUMENT_ROOT . '/includes/tecnickcom/tcpdf/tcpdf_barcodes_2d.php';
41+
42+
// Load Module libraries
43+
require_once __DIR__ . '/../lib/saturne.lib.php';
44+
require_once __DIR__ . '/../class/saturneqrcode.class.php';
45+
46+
// Global variables definitions
47+
global $conf, $db, $hookmanager, $langs, $user;
48+
49+
// Load translation files required by the page
50+
saturne_load_langs(['admin']);
51+
52+
// Initialize view objects
53+
$form = new Form($db);
54+
55+
// Get parameters
56+
$action = GETPOST('action', 'alpha');
57+
$url = GETPOST('url', 'alpha');
58+
59+
// Initialize Redirection Manager
60+
$saturneQRCode = new SaturneQRCode($db);
61+
62+
// Security check - Protection if external user
63+
$permissiontoread = $user->rights->saturne->adminpage->read;
64+
saturne_check_access($permissiontoread);
65+
66+
/*
67+
* Actions
68+
*/
69+
70+
// Add a redirection
71+
if ($action == 'add') {
72+
$saturneQRCode->url = $url;
73+
$saturneQRCode->encoded_qr_code = $saturneQRCode->getQRCodeBase64($url);
74+
$saturneQRCode->module_name = 'saturne';
75+
$saturneQRCode->status = 1;
76+
$saturneQRCode->create($user);
77+
}
78+
79+
// Remove a redirection
80+
if ($action == 'remove') {
81+
$saturneQRCode->fetch(GETPOST('id'));
82+
$saturneQRCode->delete($user, false, false);
83+
}
84+
85+
/*
86+
* View
87+
*/
88+
89+
$title = $langs->trans('RedirectionsSetup', $moduleName);
90+
$help_url = 'FR:Module_' . $moduleName;
91+
92+
saturne_header(0, '', $title, $help_url);
93+
94+
print load_fiche_titre($title, '', 'title_setup');
95+
96+
// Configuration header
97+
$preHead = $moduleNameLowerCase . '_admin_prepare_head';
98+
$head = $preHead();
99+
print dol_get_fiche_head($head, 'qrcode', $title, -1, $moduleNameLowerCase . '_color@' . $moduleNameLowerCase);
100+
$QRCodes = $saturneQRCode->fetchAll();
101+
102+
print '<table class="noborder centpercent">';
103+
print '<tr class="liste_titre">';
104+
print '<td>' . $langs->trans('URL') . '</td>';
105+
print '<td class="center">' . $langs->trans('QR Code') . '</td>';
106+
print '<td class="center">' . $langs->trans('ModuleName') . '</td>';
107+
print '<td class="center">' . $langs->trans('Action') . '</td>';
108+
print '</tr>';
109+
110+
if (is_array($QRCodes) && !empty($QRCodes)) {
111+
foreach ($QRCodes as $QRCode) {
112+
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '">';
113+
print '<input type="hidden" name="token" value="' . newToken() . '">';
114+
print '<input type="hidden" name="action" value="remove">';
115+
print '<tr class="oddeven"><td>';
116+
print $QRCode->url;
117+
print '</td><td class="center">';
118+
print '<img src="' . $QRCode->encoded_qr_code . '" alt="QR Code" width="100" height="100">';
119+
print '</td><td class="center">';
120+
print ucfirst($QRCode->module_name);
121+
print '</td><td class="center">';
122+
print '<input type="hidden" name="id" value="' . $QRCode->id . '">';
123+
print '<input type="submit" class="button" value="' . $langs->trans('Remove') . '">';
124+
print '</td></tr>';
125+
print '</form>';
126+
}
127+
}
128+
129+
130+
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '">';
131+
print '<input type="hidden" name="token" value="' . newToken() . '">';
132+
print '<input type="hidden" name="action" value="add">';
133+
134+
print '<tr class="oddeven"><td>';
135+
print '<input placeholder="'. $langs->trans('URLToEncode') .'" type="text" name="url" value="' . $url . '">';
136+
print "&nbsp;" . $form->textwithpicto($langs->trans('Help'), $langs->trans('HowToUseURLToEncode'));
137+
print '</td><td class="center">';
138+
print '</td><td class="center">';
139+
print '</td><td class="center">';
140+
print '<input type="submit" class="button" value="' . $langs->trans('Add') . '">';
141+
print '</td></tr>';
142+
143+
print '</table>';
144+
print '</form>';
145+
146+
print dol_get_fiche_end();
147+
llxFooter();
148+
$db->close();
149+
?>

class/qrcode.class.php renamed to class/saturneqrcode.class.php

+17
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,23 @@ public function __construct(DoliDB $db, string $moduleNameLowerCase = 'saturne',
144144
{
145145
parent::__construct($db, $moduleNameLowerCase, $objectType);
146146
}
147+
148+
/**
149+
* Get QR Code base64
150+
*
151+
* @param string $url URL to encode
152+
*
153+
* @return string Encoded QR Code
154+
*/
155+
public function getQRCodeBase64(string $url): string
156+
{
157+
// Create QR Code
158+
$barcodeObject = new TCPDF2DBarcode($url, 'QRCODE,H');
159+
$qrCodePng = $barcodeObject->getBarcodePngData(6, 6);
160+
$qrCodeBase64 = 'data:image/png;base64,' . base64_encode($qrCodePng);
161+
162+
return $qrCodeBase64;
163+
}
147164
}
148165

149166
?>

lib/saturne.lib.php

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ function saturne_admin_prepare_head(): array
5353
$head[$h][2] = 'information';
5454
$h++;
5555

56+
$head[$h][0] = dol_buildpath('/saturne/admin/qrcode.php', 1) . '?filename=saturne_dev&tab_name=qrcode';
57+
$head[$h][1] = '<i class="fas fa-qrcode pictofixedwidth"></i>' . $langs->trans('QRCode');
58+
$head[$h][2] = 'qrcode';
59+
$h++;
60+
5661
$head[$h][0] = dol_buildpath('/saturne/admin/information.php', 1) . '?filename=evarisk_modules&tab_name=evariskModule';
5762
$head[$h][1] = '<i class="fas fa-cogs pictofixedwidth"></i>' . $langs->trans('SaturneModule', 'Evarisk');
5863
$head[$h][2] = 'evariskModule';

sql/qrcode/llx_saturne_object_documents.sql renamed to sql/qrcode/llx_saturne_qrcode.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ CREATE TABLE llx_saturne_qrcode(
2222
status integer DEFAULT 1 NOT NULL,
2323
module_name varchar(255),
2424
url text,
25-
encoded_qr_code text,
25+
encoded_qr_code longtext,
2626
fk_user_creat integer NOT NULL
2727
) ENGINE=innodb;

0 commit comments

Comments
 (0)