* 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 supplierlink3/admin/setup.php * \ingroup supplierlink3 * \brief SupplierLink3 setup page. */ // 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 '../lib/supplierlink3.lib.php'; // Translations $langs->loadLangs(array("admin", "supplierlink3@supplierlink3")); // Access control if (!$user->admin) { accessforbidden(); } // Parameters $action = GETPOST('action', 'aZ09'); /* * Actions */ // Toggle display settings if ($action == 'set_enable_ordercard') { $value = GETPOST('value', 'int'); dolibarr_set_const($db, 'SUPPLIERLINK3_ENABLE_ORDERCARD', $value, 'chaine', 0, '', $conf->entity); setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); header("Location: ".$_SERVER["PHP_SELF"]); exit; } if ($action == 'set_enable_propalcard') { $value = GETPOST('value', 'int'); dolibarr_set_const($db, 'SUPPLIERLINK3_ENABLE_PROPALCARD', $value, 'chaine', 0, '', $conf->entity); setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); header("Location: ".$_SERVER["PHP_SELF"]); exit; } if ($action == 'set_enable_supplierorder') { $value = GETPOST('value', 'int'); dolibarr_set_const($db, 'SUPPLIERLINK3_ENABLE_SUPPLIERORDER', $value, 'chaine', 0, '', $conf->entity); setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); header("Location: ".$_SERVER["PHP_SELF"]); exit; } if ($action == 'set_enable_replenish') { $value = GETPOST('value', 'int'); dolibarr_set_const($db, 'SUPPLIERLINK3_ENABLE_REPLENISH', $value, 'chaine', 0, '', $conf->entity); setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); header("Location: ".$_SERVER["PHP_SELF"]); exit; } if ($action == 'set_enable_productcard') { $value = GETPOST('value', 'int'); dolibarr_set_const($db, 'SUPPLIERLINK3_ENABLE_PRODUCTCARD', $value, 'chaine', 0, '', $conf->entity); setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); header("Location: ".$_SERVER["PHP_SELF"]); exit; } // Save icon settings if ($action == 'save_icons') { $shopIcon = GETPOST('shop_icon', 'alpha'); $stockIcon = GETPOST('stock_icon', 'alpha'); // Validate FontAwesome class format if (!empty($shopIcon) && preg_match('/^fa[srb]?\s+fa-[\w-]+$/', $shopIcon)) { dolibarr_set_const($db, 'SUPPLIERLINK3_SHOP_ICON', $shopIcon, 'chaine', 0, '', $conf->entity); } elseif (empty($shopIcon)) { dolibarr_del_const($db, 'SUPPLIERLINK3_SHOP_ICON', $conf->entity); } if (!empty($stockIcon) && preg_match('/^fa[srb]?\s+fa-[\w-]+$/', $stockIcon)) { dolibarr_set_const($db, 'SUPPLIERLINK3_STOCK_ICON', $stockIcon, 'chaine', 0, '', $conf->entity); } elseif (empty($stockIcon)) { dolibarr_del_const($db, 'SUPPLIERLINK3_STOCK_ICON', $conf->entity); } setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); header("Location: ".$_SERVER["PHP_SELF"]); exit; } // Debug mode if ($action == 'setdebug') { $value = GETPOST('value', 'int'); dolibarr_set_const($db, 'SUPPLIERLINK3_DEBUG_MODE', $value, 'chaine', 0, '', $conf->entity); setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); header("Location: ".$_SERVER["PHP_SELF"]); exit; } if ($action == 'cleardebuglog') { $logFile = '/tmp/supplierlink3_debug.log'; if (file_exists($logFile)) { unlink($logFile); setEventMessages($langs->trans('SL3_DebugLogCleared'), null, 'mesgs'); } header("Location: ".$_SERVER["PHP_SELF"]); exit; } /* * View */ $form = new Form($db); $title = $langs->trans("SupplierLink3Setup"); llxHeader('', $title, '', '', 0, 0, '', '', '', 'mod-supplierlink3 page-admin'); // Subheader $linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($title, $linkback, 'title_setup'); // Configuration header $head = supplierlink3AdminPrepareHead(); print dol_get_fiche_head($head, 'settings', $title, -1, "supplierlink3@supplierlink3"); print ''.$langs->trans('SupplierLink3Description').'

'; // ============================================================================= // DISPLAY SETTINGS // ============================================================================= print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Customer Orders (ordercard) $enableOrderCard = getDolGlobalInt('SUPPLIERLINK3_ENABLE_ORDERCARD', 1); print ''; print ''; print ''; print ''; print ''; // Proposals (propalcard) $enablePropalCard = getDolGlobalInt('SUPPLIERLINK3_ENABLE_PROPALCARD', 1); print ''; print ''; print ''; print ''; print ''; // Supplier Orders (ordersuppliercard) $enableSupplierOrder = getDolGlobalInt('SUPPLIERLINK3_ENABLE_SUPPLIERORDER', 1); print ''; print ''; print ''; print ''; print ''; // Stock Replenishment (stockreplenishlist) $enableReplenish = getDolGlobalInt('SUPPLIERLINK3_ENABLE_REPLENISH', 1); print ''; print ''; print ''; print ''; print ''; // Product Card (productcard) $enableProductCard = getDolGlobalInt('SUPPLIERLINK3_ENABLE_PRODUCTCARD', 1); print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans('SL3_DisplaySettings').'
'.$langs->trans('SL3_DisplaySettingsDesc').'
'.$langs->trans('SL3_EnableOrderCard').''; if ($enableOrderCard) { print ''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; } else { print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print ''; } print ''.$langs->trans('SL3_EnableOrderCardDesc').'
'.$langs->trans('SL3_EnablePropalCard').''; if ($enablePropalCard) { print ''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; } else { print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print ''; } print ''.$langs->trans('SL3_EnablePropalCardDesc').'
'.$langs->trans('SL3_EnableSupplierOrder').''; if ($enableSupplierOrder) { print ''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; } else { print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print ''; } print ''.$langs->trans('SL3_EnableSupplierOrderDesc').'
'.$langs->trans('SL3_EnableReplenish').''; if ($enableReplenish) { print ''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; } else { print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print ''; } print ''.$langs->trans('SL3_EnableReplenishDesc').'
'.$langs->trans('SL3_EnableProductCard').''; if ($enableProductCard) { print ''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; } else { print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print ''; } print ''.$langs->trans('SL3_EnableProductCardDesc').'
'; print '
'; // ============================================================================= // ICON SETTINGS // ============================================================================= print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Shop Icon $shopIcon = getDolGlobalString('SUPPLIERLINK3_SHOP_ICON', 'fas fa-store'); print ''; print ''; print ''; print ''; print ''; // Stock Icon (optional, for future use) $stockIcon = getDolGlobalString('SUPPLIERLINK3_STOCK_ICON', ''); print ''; print ''; print ''; print ''; print ''; // Icon preview row print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans('SL3_IconSettings').'
'.$langs->trans('SL3_IconSettingsDesc').'
'.$langs->trans('SL3_ShopIcon').''; print ''; print ' '; print ''.$langs->trans('SL3_ShopIconDesc').'
'.$langs->trans('SL3_StockIcon').''; print ''; if (!empty($stockIcon)) { print ' '; } print ''.$langs->trans('SL3_StockIconDesc').'
'.$langs->trans('SL3_IconPreview').''; print '
'; // Preview: Shop link with stock badge print '
'; print ''; print ''; print ''; print ''; print '42'; print ''; print '
'; print '
'; print ''; print ''; print ''; print ''; print '8'; print ''; print '
'; print '
'; print ''; print ''; print '0'; print ''; print '
'; print '
'; print '
'; print ''; print '
'; print '
'; print '
'; // ============================================================================= // DEBUG SETTINGS // ============================================================================= print ''; print ''; print ''; print ''; // Debug-Modus (default: OFF) $debugMode = getDolGlobalInt('SUPPLIERLINK3_DEBUG_MODE', 0); print ''; print ''; print ''; print ''; print ''; // Debug-Log anzeigen $logFile = '/tmp/supplierlink3_debug.log'; print ''; print ''; print ''; print ''; print '
'.$langs->trans('SL3_DebugSettings').'
'.$langs->trans('SL3_DebugMode').''; if ($debugMode) { print ''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; } else { print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print ''; } print ''.$langs->trans('SL3_DebugModeDesc').'
'.$langs->trans('SL3_DebugLog').''; if (file_exists($logFile)) { $logContent = file_get_contents($logFile); $logSize = filesize($logFile); print ''.$langs->trans('SL3_DebugLogFile').': '.$logFile.' ('.$langs->trans('SL3_DebugLogSize').': '.round($logSize/1024, 2).' KB)
'; print ''.$langs->trans('SL3_DebugLogClear').''; print '

'; print ''.$langs->trans('SL3_DebugLogLastEntries').':
'; print ''; } else { print ''.$langs->trans('SL3_DebugLogEmpty').''; } print '
'; print '
'; // ============================================================================= // REGISTERED HOOKS // ============================================================================= print ''; print ''; print ''; print ''; $hooks = array( 'ordersuppliercard' => $langs->trans('SL3_HookOrderSupplier'), 'ordercard' => $langs->trans('SL3_HookOrderCard'), 'propalcard' => $langs->trans('SL3_HookPropalCard'), 'productcard' => $langs->trans('SL3_HookProductCard'), 'productpricecard' => $langs->trans('SL3_HookProductPrice'), 'stockreplenishlist' => $langs->trans('SL3_HookReplenish'), ); // Check which hooks are enabled $enabledHooks = array( 'ordersuppliercard' => getDolGlobalInt('SUPPLIERLINK3_ENABLE_SUPPLIERORDER', 1), 'ordercard' => getDolGlobalInt('SUPPLIERLINK3_ENABLE_ORDERCARD', 1), 'propalcard' => getDolGlobalInt('SUPPLIERLINK3_ENABLE_PROPALCARD', 1), 'productcard' => getDolGlobalInt('SUPPLIERLINK3_ENABLE_PRODUCTCARD', 1), 'productpricecard' => getDolGlobalInt('SUPPLIERLINK3_ENABLE_PRODUCTCARD', 1), 'stockreplenishlist' => getDolGlobalInt('SUPPLIERLINK3_ENABLE_REPLENISH', 1), ); foreach ($hooks as $hook => $desc) { $isEnabled = $enabledHooks[$hook] ?? 1; print ''; print ''; print ''; print ''; print ''; } print '
'.$langs->trans('SL3_RegisteredHooks').'
'.$hook.''.$desc.''; if ($isEnabled) { print ''.$langs->trans("Activated").''; } else { print ''.$langs->trans("Disabled").''; } print '
'; // Page end print dol_get_fiche_end(); // JavaScript for live icon preview print ''; llxFooter(); $db->close();