|
| 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 " " . $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 | +?> |
0 commit comments