Skip to content

Commit

Permalink
Evarisk#1045 [QRCode] add: qr code config page & rename sql files
Browse files Browse the repository at this point in the history
  • Loading branch information
theodaviddd committed Aug 6, 2024
1 parent 0b05904 commit b4edbc7
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 1 deletion.
149 changes: 149 additions & 0 deletions admin/qrcode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php
/* Copyright (C) 2021-2023 EVARISK
*
* 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/>.
*/

/**
* \file admin/redirections.php
* \ingroup saturne
* \brief Saturne redirections page
*/

// Load Saturne environment
if (file_exists('../saturne.main.inc.php')) {
require_once __DIR__ . '/../saturne.main.inc.php';
} elseif (file_exists('../../saturne.main.inc.php')) {
require_once __DIR__ . '/../../saturne.main.inc.php';
} else {
die('Include of saturne main fails');
}

// Get module parameters
$moduleName = GETPOST('module_name', 'alpha');
$moduleNameLowerCase = strtolower($moduleName);

// Load Dolibarr libraries
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT . '/includes/tecnickcom/tcpdf/tcpdf_barcodes_2d.php';

// Load Module libraries
require_once __DIR__ . '/../lib/saturne.lib.php';
require_once __DIR__ . '/../class/saturneqrcode.class.php';

// Global variables definitions
global $conf, $db, $hookmanager, $langs, $user;

// Load translation files required by the page
saturne_load_langs(['admin']);

// Initialize view objects
$form = new Form($db);

// Get parameters
$action = GETPOST('action', 'alpha');
$url = GETPOST('url', 'alpha');

// Initialize Redirection Manager
$saturneQRCode = new SaturneQRCode($db);

// Security check - Protection if external user
$permissiontoread = $user->rights->saturne->adminpage->read;
saturne_check_access($permissiontoread);

/*
* Actions
*/

// Add a redirection
if ($action == 'add') {
$saturneQRCode->url = $url;
$saturneQRCode->encoded_qr_code = $saturneQRCode->getQRCodeBase64($url);
$saturneQRCode->module_name = 'saturne';
$saturneQRCode->status = 1;
$saturneQRCode->create($user);
}

// Remove a redirection
if ($action == 'remove') {
$saturneQRCode->fetch(GETPOST('id'));
$saturneQRCode->delete($user, false, false);
}

/*
* View
*/

$title = $langs->trans('RedirectionsSetup', $moduleName);
$help_url = 'FR:Module_' . $moduleName;

saturne_header(0, '', $title, $help_url);

print load_fiche_titre($title, '', 'title_setup');

// Configuration header
$preHead = $moduleNameLowerCase . '_admin_prepare_head';
$head = $preHead();
print dol_get_fiche_head($head, 'qrcode', $title, -1, $moduleNameLowerCase . '_color@' . $moduleNameLowerCase);
$QRCodes = $saturneQRCode->fetchAll();

print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>' . $langs->trans('URL') . '</td>';
print '<td class="center">' . $langs->trans('QR Code') . '</td>';
print '<td class="center">' . $langs->trans('ModuleName') . '</td>';
print '<td class="center">' . $langs->trans('Action') . '</td>';
print '</tr>';

if (is_array($QRCodes) && !empty($QRCodes)) {
foreach ($QRCodes as $QRCode) {
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="remove">';
print '<tr class="oddeven"><td>';
print $QRCode->url;
print '</td><td class="center">';
print '<img src="' . $QRCode->encoded_qr_code . '" alt="QR Code" width="100" height="100">';
print '</td><td class="center">';
print ucfirst($QRCode->module_name);
print '</td><td class="center">';
print '<input type="hidden" name="id" value="' . $QRCode->id . '">';
print '<input type="submit" class="button" value="' . $langs->trans('Remove') . '">';
print '</td></tr>';
print '</form>';
}
}


print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="add">';

print '<tr class="oddeven"><td>';
print '<input placeholder="'. $langs->trans('URLToEncode') .'" type="text" name="url" value="' . $url . '">';
print "&nbsp;" . $form->textwithpicto($langs->trans('Help'), $langs->trans('HowToUseURLToEncode'));
print '</td><td class="center">';
print '</td><td class="center">';
print '</td><td class="center">';
print '<input type="submit" class="button" value="' . $langs->trans('Add') . '">';
print '</td></tr>';

print '</table>';
print '</form>';

print dol_get_fiche_end();
llxFooter();
$db->close();
?>
17 changes: 17 additions & 0 deletions class/qrcode.class.php → class/saturneqrcode.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,23 @@ public function __construct(DoliDB $db, string $moduleNameLowerCase = 'saturne',
{
parent::__construct($db, $moduleNameLowerCase, $objectType);
}

/**
* Get QR Code base64
*
* @param string $url URL to encode
*
* @return string Encoded QR Code
*/
public function getQRCodeBase64(string $url): string
{
// Create QR Code
$barcodeObject = new TCPDF2DBarcode($url, 'QRCODE,H');
$qrCodePng = $barcodeObject->getBarcodePngData(6, 6);
$qrCodeBase64 = 'data:image/png;base64,' . base64_encode($qrCodePng);

return $qrCodeBase64;
}
}

?>
5 changes: 5 additions & 0 deletions lib/saturne.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ function saturne_admin_prepare_head(): array
$head[$h][2] = 'information';
$h++;

$head[$h][0] = dol_buildpath('/saturne/admin/qrcode.php', 1) . '?filename=saturne_dev&tab_name=qrcode';
$head[$h][1] = '<i class="fas fa-qrcode pictofixedwidth"></i>' . $langs->trans('QRCode');
$head[$h][2] = 'qrcode';
$h++;

$head[$h][0] = dol_buildpath('/saturne/admin/information.php', 1) . '?filename=evarisk_modules&tab_name=evariskModule';
$head[$h][1] = '<i class="fas fa-cogs pictofixedwidth"></i>' . $langs->trans('SaturneModule', 'Evarisk');
$head[$h][2] = 'evariskModule';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ CREATE TABLE llx_saturne_qrcode(
status integer DEFAULT 1 NOT NULL,
module_name varchar(255),
url text,
encoded_qr_code text,
encoded_qr_code longtext,
fk_user_creat integer NOT NULL
) ENGINE=innodb;

0 comments on commit b4edbc7

Please sign in to comment.