* Copyright (C) 2024 Frédéric France * Copyright (C) 2025 Eduard Wisch * * 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 . */ /** * \file epcqr/admin/setup.php * \ingroup epcqr * \brief EPCQR Modul Einstellungen */ // Load Dolibarr environment $res = 0; if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; } $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; } if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) { $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; } if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) { $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; } if (!$res && file_exists("../../main.inc.php")) { $res = @include "../../main.inc.php"; } if (!$res && file_exists("../../../main.inc.php")) { $res = @include "../../../main.inc.php"; } if (!$res) { die("Include of main fails"); } // Libraries require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"; require_once DOL_DOCUMENT_ROOT."/core/class/html.form.class.php"; require_once '../lib/epcqr.lib.php'; /** * @var Conf $conf * @var DoliDB $db * @var HookManager $hookmanager * @var Translate $langs * @var User $user */ // Translations $langs->loadLangs(array("admin", "epcqr@epcqr")); // Access control if (!$user->admin) { accessforbidden(); } // Parameters $action = GETPOST('action', 'aZ09'); $error = 0; /* * Actions */ if ($action == 'update') { $bankDataSource = GETPOST('EPCQR_BANK_DATA_SOURCE', 'alpha'); $accountHolder = GETPOST('EPCQR_ACCOUNT_HOLDER', 'alphanohtml'); $iban = GETPOST('EPCQR_IBAN', 'alphanohtml'); $bic = GETPOST('EPCQR_BIC', 'alphanohtml'); $imageRatio = GETPOST('EPCQR_IMAGE_RATIO', 'alphanohtml'); // Validate IBAN format (basic check) if ($bankDataSource == 'manual' && !empty($iban)) { $iban = str_replace(' ', '', strtoupper($iban)); if (!preg_match('/^[A-Z]{2}[0-9]{2}[A-Z0-9]{4,30}$/', $iban)) { setEventMessages($langs->trans("InvalidIBAN"), null, 'errors'); $error++; } } // Validate BIC format (basic check) if ($bankDataSource == 'manual' && !empty($bic)) { $bic = str_replace(' ', '', strtoupper($bic)); if (!preg_match('/^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/', $bic)) { setEventMessages($langs->trans("InvalidBIC"), null, 'errors'); $error++; } } // Validate image ratio if (!empty($imageRatio)) { $imageRatio = str_replace(',', '.', $imageRatio); if (!is_numeric($imageRatio) || (float)$imageRatio <= 0 || (float)$imageRatio > 2) { setEventMessages($langs->trans("InvalidImageRatio"), null, 'errors'); $error++; } } // Extra field visibility settings $hideQrcode = GETPOST('EPCQR_HIDE_QRCODE', 'int') ? 1 : 0; $hideQrcodepfad = GETPOST('EPCQR_HIDE_QRCODEPFAD', 'int') ? 1 : 0; $hideQrcodepath = GETPOST('EPCQR_HIDE_QRCODEPATH', 'int') ? 1 : 0; // QR Code styling settings $fgColorPost = GETPOST('EPCQR_FG_COLOR', 'alphanohtml'); $bgTransparent = GETPOST('EPCQR_BG_TRANSPARENT', 'int') ? 1 : 0; $bgColorPost = $bgTransparent ? 'transparent' : GETPOST('EPCQR_BG_COLOR', 'alphanohtml'); $logoPathPost = GETPOST('EPCQR_LOGO_PATH', 'alphanohtml'); $logoSizePost = GETPOST('EPCQR_LOGO_SIZE', 'int'); // Validate colors (hex format) if (!preg_match('/^#[0-9A-Fa-f]{6}$/', $fgColorPost)) { $fgColorPost = '#000000'; } if (!$bgTransparent && !preg_match('/^#[0-9A-Fa-f]{6}$/', $bgColorPost)) { $bgColorPost = '#FFFFFF'; } // Validate logo size if ($logoSizePost < 5) $logoSizePost = 5; if ($logoSizePost > 30) $logoSizePost = 30; // Module style $moduleStylePost = GETPOST('EPCQR_MODULE_STYLE', 'alpha'); if (!in_array($moduleStylePost, array('square', 'rounded', 'dots', 'diamond'))) { $moduleStylePost = 'square'; } // Border style $borderStylePost = GETPOST('EPCQR_BORDER_STYLE', 'alpha'); if (!in_array($borderStylePost, array('none', 'simple', 'rounded', 'double', 'dashed'))) { $borderStylePost = 'none'; } if (!$error) { dolibarr_set_const($db, 'EPCQR_BANK_DATA_SOURCE', $bankDataSource, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'EPCQR_ACCOUNT_HOLDER', $accountHolder, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'EPCQR_IBAN', $iban, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'EPCQR_BIC', $bic, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'EPCQR_IMAGE_RATIO', $imageRatio, 'chaine', 0, '', $conf->entity); // Save visibility settings dolibarr_set_const($db, 'EPCQR_HIDE_QRCODE', $hideQrcode, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'EPCQR_HIDE_QRCODEPFAD', $hideQrcodepfad, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'EPCQR_HIDE_QRCODEPATH', $hideQrcodepath, 'chaine', 0, '', $conf->entity); // Save styling settings dolibarr_set_const($db, 'EPCQR_FG_COLOR', $fgColorPost, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'EPCQR_BG_COLOR', $bgColorPost, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'EPCQR_LOGO_PATH', $logoPathPost, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'EPCQR_LOGO_SIZE', $logoSizePost, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'EPCQR_MODULE_STYLE', $moduleStylePost, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'EPCQR_BORDER_STYLE', $borderStylePost, 'chaine', 0, '', $conf->entity); // Update extrafield visibility in database $extrafieldsToUpdate = array( 'qrcode' => $hideQrcode, 'qrcodepfad' => $hideQrcodepfad, 'qrcodepath' => $hideQrcodepath ); foreach ($extrafieldsToUpdate as $fieldname => $hidden) { // enabled = '0' means hidden, '1' means visible $enabled = $hidden ? '0' : '1'; $sql = "UPDATE ".MAIN_DB_PREFIX."extrafields SET enabled = '".$db->escape($enabled)."'"; $sql .= " WHERE name = '".$db->escape($fieldname)."' AND elementtype = 'facture'"; $db->query($sql); } setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } } // Clear cache action if ($action == 'clearcache') { require_once __DIR__.'/../lib/qrcode.class.php'; $qrGen = new QRCodeGenerator($db); $deleted = $qrGen->clearCache(); setEventMessages($langs->trans("CacheCleared", $deleted), null, 'mesgs'); } /* * View */ $form = new Form($db); $title = "EpcqrSetup"; llxHeader('', $langs->trans($title), '', '', 0, 0, '', '', '', 'mod-epcqr page-admin'); // Subheader $linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans($title), $linkback, 'title_setup'); // Configuration header $head = epcqrAdminPrepareHead(); print dol_get_fiche_head($head, 'settings', $langs->trans($title), -1, "epcqr@epcqr"); // Current values $bankDataSource = getDolGlobalString('EPCQR_BANK_DATA_SOURCE', 'manual'); $accountHolder = getDolGlobalString('EPCQR_ACCOUNT_HOLDER', ''); $iban = getDolGlobalString('EPCQR_IBAN', ''); $bic = getDolGlobalString('EPCQR_BIC', ''); $imageRatio = getDolGlobalString('EPCQR_IMAGE_RATIO', '0.3'); // Extra field visibility settings $hideQrcode = getDolGlobalInt('EPCQR_HIDE_QRCODE', 0); $hideQrcodepfad = getDolGlobalInt('EPCQR_HIDE_QRCODEPFAD', 0); $hideQrcodepath = getDolGlobalInt('EPCQR_HIDE_QRCODEPATH', 0); // QR Code styling settings $fgColor = getDolGlobalString('EPCQR_FG_COLOR', '#000000'); $bgColor = getDolGlobalString('EPCQR_BG_COLOR', '#FFFFFF'); $logoPath = getDolGlobalString('EPCQR_LOGO_PATH', ''); $logoSize = getDolGlobalInt('EPCQR_LOGO_SIZE', 20); $moduleStyle = getDolGlobalString('EPCQR_MODULE_STYLE', 'square'); $borderStyle = getDolGlobalString('EPCQR_BORDER_STYLE', 'none'); print '
'; print ''; print ''; // Bank Data Section print ''; print ''; print ''; print ''; // Bank Data Source Selection print ''; print ''; print ''; print ''; // Manual Bank Data Fields print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("BankDataSettings").'
'.$langs->trans("BankDataSource").''; print ''; print '
'.$langs->trans("AccountHolder").''; print ''; print '
'.$langs->trans("IBAN").''; print ''; print '
'.$langs->trans("BIC").''; print ''; print '
'; // QR Code Settings Section print '
'; print ''; print ''; print ''; print ''; // Image Ratio print ''; print ''; print ''; print ''; // Foreground Color print ''; print ''; print ''; print ''; // Background Color print ''; print ''; print ''; print ''; print ''; // Logo Path print ''; print ''; print ''; print ''; // Logo Size print ''; print ''; print ''; print ''; // Module Style print ''; print ''; print ''; print ''; // Border Style print ''; print ''; print ''; print ''; print '
'.$langs->trans("QRCodeSettings").'
'.$langs->trans("QRCodeSize").''; print ''; print ' '.$langs->trans("QRCodeSizeHelp").''; print '
'.$langs->trans("QRCodeFgColor").''; print ''; print ' '; print ' '.$langs->trans("QRCodeFgColorHelp").''; print '
'.$langs->trans("QRCodeBgColor").''; $isTransparent = (strtolower($bgColor) === 'transparent' || $bgColor === ''); print ''; print ' '; print '   '; print ''; print ' '; print ' '.$langs->trans("QRCodeBgColorHelp").''; print '
'.$langs->trans("QRCodeLogo").''; print ''; print '
'.$langs->trans("QRCodeLogoHelp").''; if (!empty($logoPath)) { if (file_exists($logoPath)) { print '
✓ '.$langs->trans("FileExists").''; } else { print '
✗ '.$langs->trans("FileNotFound").''; } } print '
'.$langs->trans("QRCodeLogoSize").''; print ''; print ' % '.$langs->trans("QRCodeLogoSizeHelp").''; print '
'.$langs->trans("QRCodeModuleStyle").''; print ''; print ' '.$langs->trans("QRCodeModuleStyleHelp").''; print '
'.$langs->trans("QRCodeBorderStyle").''; print ''; print ' '.$langs->trans("QRCodeBorderStyleHelp").''; print '
'; // Clear Cache Button print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("QRCodeCache").'
'.$langs->trans("ClearQRCodeCache").''; print ''.$langs->trans("ClearCache").''; print ' '.$langs->trans("ClearCacheHelp").''; print '
'; // Extra Field Visibility Section print '
'; print ''; print ''; print ''; print ''; // Hide QR Code field (HTML with image) print ''; print ''; print ''; print ''; // Hide QR Code URL field print ''; print ''; print ''; print ''; // Hide QR Code Path field (local file path) print ''; print ''; print ''; print ''; print '
'.$langs->trans("ExtraFieldVisibility").'
'.$langs->trans("HideQRCodeField").''; print ''; print ' '.$langs->trans("HideQRCodeFieldHelp").''; print '
'.$langs->trans("HideQRCodePfadField").''; print ''; print ' '.$langs->trans("HideQRCodePfadFieldHelp").''; print '
'.$langs->trans("HideQRCodePathField").''; print ''; print ' '.$langs->trans("HideQRCodePathFieldHelp").''; print '
'; // Submit button print '
'; print '
'; print ''; print '
'; print '
'; // JavaScript to show/hide manual fields based on selection print ''; // Info box about system bank account if ($bankDataSource == 'system') { print '
'; print '
'; print $langs->trans("SystemBankAccountInfo"); // Try to show configured bank accounts require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $bankAccount = new Account($db); $sql = "SELECT rowid, label, iban_prefix, bic FROM ".MAIN_DB_PREFIX."bank_account WHERE entity = ".((int) $conf->entity)." AND clos = 0"; $resql = $db->query($sql); if ($resql && $db->num_rows($resql) > 0) { print '

'.$langs->trans("AvailableBankAccounts").':
    '; while ($obj = $db->fetch_object($resql)) { print '
  • '.$obj->label; if (!empty($obj->iban_prefix)) { print ' - IBAN: '.substr($obj->iban_prefix, 0, 4).'****'.substr($obj->iban_prefix, -4); } print '
  • '; } print '
'; } else { print '

'.$langs->trans("NoBankAccountConfigured").''; } print '
'; } // Page end print dol_get_fiche_end(); llxFooter(); $db->close();