* Copyright (C) 2011-2015 Juanjo Menent * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2016 Raphaël Doursenaud * Copyright (C) 2021 Frédéric France * Copyright (C) 2024 MDW * * 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 htdocs/admin/agenda_extsites.php * \ingroup agenda * \brief Page to setup external calendars for agenda module */ // Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; if (!$user->admin) { accessforbidden(); } // Load translation files required by the page $langs->loadLangs(array('agenda', 'admin', 'other')); $def = array(); $action = GETPOST('action', 'alpha'); if (!getDolGlobalString('AGENDA_EXT_NB')) { $conf->global->AGENDA_EXT_NB = 5; } $MAXAGENDA = getDolGlobalString('AGENDA_EXT_NB'); // List of available colors $colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', 'A4A4A5'); $reg = array(); /* * Actions */ $error = 0; $errors = array(); if (preg_match('/set_(.*)/', $action, $reg)) { $db->begin(); $code = $reg[1]; $value = (GETPOST($code) ? GETPOST($code) : 1); $res = dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity); if (!($res > 0)) { $error++; $errors[] = $db->lasterror(); } if ($error) { $db->rollback(); setEventMessages('', $errors, 'errors'); } else { $db->commit(); setEventMessage($langs->trans('SetupSaved')); header('Location: ' . $_SERVER["PHP_SELF"]); exit(); } } elseif (preg_match('/del_(.*)/', $action, $reg)) { $db->begin(); $code = $reg[1]; $res = dolibarr_del_const($db, $code, $conf->entity); if (!($res > 0)) { $error++; $errors[] = $db->lasterror(); } if ($error) { $db->rollback(); setEventMessages('', $errors, 'errors'); } else { $db->commit(); setEventMessage($langs->trans('SetupSaved')); header('Location: ' . $_SERVER["PHP_SELF"]); exit(); } } elseif ($action == 'save') { $db->begin(); $disableext = GETPOST('AGENDA_DISABLE_EXT', 'alpha'); $res = dolibarr_set_const($db, 'AGENDA_DISABLE_EXT', $disableext, 'chaine', 0, '', $conf->entity); $i = 1; $errorsaved = 0; // Save agendas while ($i <= $MAXAGENDA) { $name = trim(GETPOST('AGENDA_EXT_NAME'.$i, 'alpha')); $src = trim(GETPOST('AGENDA_EXT_SRC'.$i, 'alpha')); $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ'.$i, 'alpha')); $color = trim(GETPOST('AGENDA_EXT_COLOR'.$i, 'alpha')); if ($color == '-1') { $color = ''; } $enabled = trim(GETPOST('AGENDA_EXT_ENABLED'.$i, 'alpha')); if (!empty($src) && !dol_is_url($src)) { setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors'); $error++; $errorsaved++; break; } //print '-name='.$name.'-color='.$color; // @phan-suppress-next-line PhanPluginSuspiciousParamPosition $res = dolibarr_set_const($db, 'AGENDA_EXT_NAME'.$i, $name, 'chaine', 0, '', $conf->entity); if (!($res > 0)) { $error++; } $res = dolibarr_set_const($db, 'AGENDA_EXT_SRC'.$i, $src, 'chaine', 0, '', $conf->entity); if (!($res > 0)) { $error++; } $res = dolibarr_set_const($db, 'AGENDA_EXT_OFFSETTZ'.$i, $offsettz, 'chaine', 0, '', $conf->entity); if (!($res > 0)) { $error++; } $res = dolibarr_set_const($db, 'AGENDA_EXT_COLOR'.$i, $color, 'chaine', 0, '', $conf->entity); if (!($res > 0)) { $error++; } $res = dolibarr_set_const($db, 'AGENDA_EXT_ENABLED'.$i, $enabled, 'chaine', 0, '', $conf->entity); if (!($res > 0)) { $error++; } $i++; } // Save nb of agenda if (!$error) { $res = dolibarr_set_const($db, 'AGENDA_EXT_NB', GETPOSTINT('AGENDA_EXT_NB'), 'chaine', 0, '', $conf->entity); if (!($res > 0)) { $error++; } if (!getDolGlobalString('AGENDA_EXT_NB')) { $conf->global->AGENDA_EXT_NB = 5; } $MAXAGENDA = getDolGlobalInt('AGENDA_EXT_NB', 5); } if (!$error) { $db->commit(); setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { $db->rollback(); if (empty($errorsaved)) { setEventMessages($langs->trans("Error"), null, 'errors'); } } } /* * View */ $form = new Form($db); $formadmin = new FormAdmin($db); $formother = new FormOther($db); $arrayofjs = array(); $arrayofcss = array(); $wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda|DE:Modul_Terminplanung'; llxHeader('', $langs->trans("AgendaSetup"), $wikihelp, '', 0, 0, $arrayofjs, $arrayofcss, '', 'mod-admin page-agenda-extsites'); $linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup'); print '
'; print ''; print ''; $head = agenda_prepare_head(); print dol_get_fiche_head($head, 'extsites', $langs->trans("Agenda"), -1, 'action'); print ''.$langs->trans("AgendaExtSitesDesc")."
\n"; print "
\n"; $selectedvalue = getDolGlobalInt('AGENDA_DISABLE_EXT'); if ($selectedvalue == 1) { $selectedvalue = 0; } else { $selectedvalue = 1; } print ""; print ""; print '"; print '"; print ""; // Show external agenda print ''; print ""; print '"; print ""; // Nb of agenda print ''; print ""; print '"; print ""; print "
'.$langs->trans("Parameter")."'.$langs->trans("Value")."
".$langs->trans("ExtSitesEnableThisTool")."'; if ($conf->use_javascript_ajax) { print ajax_constantonoff('AGENDA_DISABLE_EXT', array('enabled' => array(0 => '.hideifnotset')), null, 1); } else { if (!getDolGlobalString('AGENDA_DISABLE_EXT')) { print ''.img_picto($langs->trans("Enabled"), 'on').''; } else { print ''.img_picto($langs->trans("Disabled"), 'off').''; } } print "
".$langs->trans("ExtSitesNbOfAgenda")."'; print ''; print "
"; print "
"; print '
'; print ''."\n"; print ''; print ""; print ""; print "'; print "'; print ''; print ''; print ""; $i = 1; while ($i <= $MAXAGENDA) { $key = $i; $name = 'AGENDA_EXT_NAME' . $key; $src = 'AGENDA_EXT_SRC' . $key; $offsettz = 'AGENDA_EXT_OFFSETTZ' . $key; $color = 'AGENDA_EXT_COLOR' . $key; $enabled = 'AGENDA_EXT_ENABLED' . $key; $default = 'AGENDA_EXT_ACTIVEBYDEFAULT' . $key; print ''; // Nb @phan-suppress-next-line PhanPluginSuspiciousParamPosition print '"; // Name print ''; // URL print ''; // Offset TZ print ''; // Color (Possible colors are limited by Google) print ''; // Calendar active by default print ''; print ""; $i++; } print '
".$langs->trans("Parameter")."".$langs->trans("Name")."".$langs->trans("ExtSiteUrlAgenda")." (".$langs->trans("Example").': http://yoursite/agenda/agenda.ics)".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).''.$langs->trans("Color").''.$langs->trans("ActiveByDefault").'
' . $langs->trans("AgendaExtNb", $key) . "'; print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR" . $key) ? GETPOST("AGENDA_EXT_COLOR" . $key) : getDolGlobalString($color)), "AGENDA_EXT_COLOR" . $key, 'extsitesconfig', 1, '', 'hideifnotset'); print ''; if (!empty($conf->use_javascript_ajax)) { print ajax_constantonoff('AGENDA_EXT_ACTIVEBYDEFAULT' . $key); } else { // @phan-suppress-next-line PhanPluginSuspiciousParamPosition if (getDolGlobalString($default)) { print '' . img_picto($langs->trans("Disabled"), 'off') . ''; } else { print '' . img_picto($langs->trans("Enabled"), 'on') . ''; } } print '
'; print '
'; print dol_get_fiche_end(); print '
'; print ''; print '
'; print "
\n"; // End of page llxFooter(); $db->close();