From b72e2a3d034354a730259f22df0c5de7ffa23f54 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 20 Mar 2026 11:51:18 +0100 Subject: [PATCH] NEW Can enable/disable external calender per calendar. --- htdocs/admin/agenda_extsites.php | 120 +++++++++++------------------ htdocs/comm/action/index.php | 94 +++++++++++----------- htdocs/comm/action/peruser.php | 92 +++++++++++----------- htdocs/core/lib/usergroups.lib.php | 5 +- htdocs/user/agenda_extsites.php | 12 +-- 5 files changed, 136 insertions(+), 187 deletions(-) diff --git a/htdocs/admin/agenda_extsites.php b/htdocs/admin/agenda_extsites.php index 7ab2ac7508e..6d3e941d534 100644 --- a/htdocs/admin/agenda_extsites.php +++ b/htdocs/admin/agenda_extsites.php @@ -28,13 +28,6 @@ // 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'; - /** * @var Conf $conf * @var DoliDB $db @@ -42,6 +35,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; * @var Translate $langs * @var User $user */ +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(); @@ -53,10 +52,7 @@ $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'); +$MAXAGENDA = getDolGlobalInt('AGENDA_EXT_NB', 6); // List of available colors $colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', 'A4A4A5'); @@ -164,18 +160,6 @@ if (preg_match('/set_(.*)/', $action, $reg)) { $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'); @@ -217,59 +201,18 @@ print ''.$langs->trans("AgendaExtSitesDesc")."\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("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 ''; -print ''; +print ''; +print ''; print ""; $i = 1; @@ -283,22 +226,47 @@ while ($i <= $MAXAGENDA) { $default = 'AGENDA_EXT_ACTIVEBYDEFAULT' . $key; print ''; - // Nb @phan-suppress-next-line PhanPluginSuspiciousParamPosition - print '"; + + // Nb + print '"; + // Name - print ''; + print ''; + // URL - print ''; + print ''; + // Offset TZ print ''; + // Color (Possible colors are limited by Google) print ''; - // Calendar active by default - print ''; + + // Calendar active by default + print '
".$langs->trans("Parameter")."'.$langs->trans("AgendaExtNb", "")."".$langs->trans("Name")."".$langs->trans("ExtSiteUrlAgenda")." (".$langs->trans("Example").': http://yoursite/agenda/agenda.ics)".$langs->trans("ExtSiteUrlAgenda"); +print '
('.$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("Enabled").''.$langs->trans("ActiveByDefault").'
' . $langs->trans("AgendaExtNb", $key) . "' . ((int) $key) . "'; print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR" . $key) ? GETPOST("AGENDA_EXT_COLOR" . $key) : getDolGlobalString($color)), "AGENDA_EXT_COLOR" . $key, '', 1, array(), 'hideifnotset'); print ''; + + // Calendar enabled + print ''; if (!empty($conf->use_javascript_ajax)) { - print ajax_constantonoff('AGENDA_EXT_ACTIVEBYDEFAULT' . $key); + print ajax_constantonoff('AGENDA_EXT_ENABLED' . $key, array(), null, 0, 0, 1); + } 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 ''; + if (!empty($conf->use_javascript_ajax)) { + $disabled = getDolGlobalString('AGENDA_EXT_ENABLED'.$key) ? 0 : 1; + if ($disabled) { + print ajax_constantonoff('EMPTYPARAM', array(), null, 0, 0, 1, 2, 0, 0, '', '', 'inline-block', 0, '', $disabled); + } else { + print ajax_constantonoff('AGENDA_EXT_ACTIVEBYDEFAULT' . $key, array(), null, 0, 0, 1, 2, 0, 0, '', '', 'inline-block', 0, ''); + } } else { // @phan-suppress-next-line PhanPluginSuspiciousParamPosition if (getDolGlobalString($default)) { diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index f8897ef55a1..34905975345 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -49,7 +49,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; -$MAXAGENDA = getDolGlobalString('AGENDA_EXT_NB', 5); +$MAXAGENDA = getDolGlobalString('AGENDA_EXT_NB', 6); $DELAYFORCACHE = 300; // 300 seconds $action = GETPOST('action', 'aZ09'); @@ -269,60 +269,58 @@ $nowday = $nowarray['mday']; $listofextcals = array(); // Define list of external calendars (global admin setup) -if (!getDolGlobalString('AGENDA_DISABLE_EXT')) { - $i = 0; - while ($i < $MAXAGENDA) { - $i++; - $source = 'AGENDA_EXT_SRC'.$i; - $name = 'AGENDA_EXT_NAME'.$i; - $offsettz = 'AGENDA_EXT_OFFSETTZ'.$i; - $color = 'AGENDA_EXT_COLOR'.$i; - $default = 'AGENDA_EXT_ACTIVEBYDEFAULT'.$i; - $buggedfile = 'AGENDA_EXT_BUGGEDFILE'.$i; - if (getDolGlobalString($source) && getDolGlobalString($name)) { - // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight' - $listofextcals[] = array( - 'type' => 'globalsetup', - 'src' => getDolGlobalString($source), - 'name' => dol_string_nohtmltag(getDolGlobalString($name)), - 'offsettz' => (int) getDolGlobalInt($offsettz, 0), - 'color' => dol_string_nohtmltag(getDolGlobalString($color)), - // @phan-suppress-next-line PhanPluginSuspiciousParamPosition - 'default' => dol_string_nohtmltag(getDolGlobalString($default)), - 'buggedfile' => dol_string_nohtmltag(getDolGlobalString('buggedfile', '')) - ); - } +$i = 0; +while ($i < $MAXAGENDA) { + $i++; + $source = 'AGENDA_EXT_SRC'.$i; + $name = 'AGENDA_EXT_NAME'.$i; + $offsettz = 'AGENDA_EXT_OFFSETTZ'.$i; + $color = 'AGENDA_EXT_COLOR'.$i; + $enabled = 'AGENDA_EXT_ENABLED'.$i; + $default = 'AGENDA_EXT_ACTIVEBYDEFAULT'.$i; + $buggedfile = 'AGENDA_EXT_BUGGEDFILE'.$i; + if (getDolGlobalString($source) && getDolGlobalString($name) && getDolGlobalString($enabled)) { + // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight' + $listofextcals[] = array( + 'type' => 'globalsetup', + 'src' => getDolGlobalString($source), + 'name' => dol_string_nohtmltag(getDolGlobalString($name)), + 'offsettz' => (int) getDolGlobalInt($offsettz, 0), + 'color' => dol_string_nohtmltag(getDolGlobalString($color)), + // @phan-suppress-next-line PhanPluginSuspiciousParamPosition + 'default' => dol_string_nohtmltag(getDolGlobalString($default)), + 'buggedfile' => dol_string_nohtmltag(getDolGlobalString('buggedfile', '')) + ); } } // Define list of external calendars (user setup) -if (!getDolUserString('AGENDA_DISABLE_EXT')) { - $i = 0; - while ($i < $MAXAGENDA) { - $i++; - $source = 'AGENDA_EXT_SRC_'.$user->id.'_'.$i; - $name = 'AGENDA_EXT_NAME_'.$user->id.'_'.$i; - $offsettz = 'AGENDA_EXT_OFFSETTZ_'.$user->id.'_'.$i; - $color = 'AGENDA_EXT_COLOR_'.$user->id.'_'.$i; - $enabled = 'AGENDA_EXT_ENABLED_'.$user->id.'_'.$i; - $default = 'AGENDA_EXT_ACTIVEBYDEFAULT_'.$user->id.'_'.$i; - $buggedfile = 'AGENDA_EXT_BUGGEDFILE_'.$user->id.'_'.$i; +$i = 0; +while ($i < $MAXAGENDA) { + $i++; + $source = 'AGENDA_EXT_SRC_'.$user->id.'_'.$i; + $name = 'AGENDA_EXT_NAME_'.$user->id.'_'.$i; + $offsettz = 'AGENDA_EXT_OFFSETTZ_'.$user->id.'_'.$i; + $color = 'AGENDA_EXT_COLOR_'.$user->id.'_'.$i; + $enabled = 'AGENDA_EXT_ENABLED_'.$user->id.'_'.$i; + $default = 'AGENDA_EXT_ACTIVEBYDEFAULT_'.$user->id.'_'.$i; + $buggedfile = 'AGENDA_EXT_BUGGEDFILE_'.$user->id.'_'.$i; - if (getDolUserString($source) && getDolUserString($name)) { - // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight' - $listofextcals[] = array( - 'type' => 'usersetup', - 'src' => getDolUserString($source), - 'name' => dol_string_nohtmltag(getDolUserString($name)), - 'offsettz' => (int) (empty($user->conf->$offsettz) ? 0 : $user->conf->$offsettz), - 'color' => dol_string_nohtmltag(getDolUserString($color)), - // @phan-suppress-next-line PhanPluginSuspiciousParamPosition - 'default' => dol_string_nohtmltag(getDolUserString($default)), - 'buggedfile' => dol_string_nohtmltag(isset($user->conf->buggedfile) ? $user->conf->buggedfile : '') - ); - } + if (getDolUserString($source) && getDolUserString($name)) { + // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight' + $listofextcals[] = array( + 'type' => 'usersetup', + 'src' => getDolUserString($source), + 'name' => dol_string_nohtmltag(getDolUserString($name)), + 'offsettz' => (int) (empty($user->conf->$offsettz) ? 0 : $user->conf->$offsettz), + 'color' => dol_string_nohtmltag(getDolUserString($color)), + // @phan-suppress-next-line PhanPluginSuspiciousParamPosition + 'default' => dol_string_nohtmltag(getDolUserString($default)), + 'buggedfile' => dol_string_nohtmltag(isset($user->conf->buggedfile) ? $user->conf->buggedfile : '') + ); } } + $firstdaytoshow = 0; $max_day_in_month = 0; $lastdaytoshow = 0; diff --git a/htdocs/comm/action/peruser.php b/htdocs/comm/action/peruser.php index e3a9b13e963..3ff55e32e0f 100644 --- a/htdocs/comm/action/peruser.php +++ b/htdocs/comm/action/peruser.php @@ -48,7 +48,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; -$MAXAGENDA = getDolGlobalString('AGENDA_EXT_NB', 5); +$MAXAGENDA = getDolGlobalString('AGENDA_EXT_NB', 6); $DELAYFORCACHE = 300; // 300 seconds $disabledefaultvalues = GETPOSTINT('disabledefaultvalues'); @@ -248,58 +248,54 @@ $nowday = $nowarray['mday']; $listofextcals = array(); // Define list of all external calendars (global setup) -if (!getDolGlobalString('AGENDA_DISABLE_EXT')) { - $i = 0; - while ($i < $MAXAGENDA) { - $i++; - $source = 'AGENDA_EXT_SRC'.$i; - $name = 'AGENDA_EXT_NAME'.$i; - $offsettz = 'AGENDA_EXT_OFFSETTZ'.$i; - $color = 'AGENDA_EXT_COLOR'.$i; - $default = 'AGENDA_EXT_ACTIVEBYDEFAULT'.$i; - $buggedfile = 'AGENDA_EXT_BUGGEDFILE'.$i; - if (getDolGlobalString($source) && getDolGlobalString($name)) { - // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight' - $listofextcals[] = array( - 'type' => 'globalsetup', - 'src' => getDolGlobalString($source), - 'name' => dol_string_nohtmltag(getDolGlobalString($name)), - 'offsettz' => (int) getDolGlobalInt($offsettz, 0), - 'color' => dol_string_nohtmltag(getDolGlobalString($color)), - // @phan-suppress-next-line PhanPluginSuspiciousParamPosition - 'default' => dol_string_nohtmltag(getDolGlobalString($default)), - 'buggedfile' => dol_string_nohtmltag(getDolGlobalString('buggedfile', '')) - ); - } +$i = 0; +while ($i < $MAXAGENDA) { + $i++; + $source = 'AGENDA_EXT_SRC'.$i; + $name = 'AGENDA_EXT_NAME'.$i; + $offsettz = 'AGENDA_EXT_OFFSETTZ'.$i; + $color = 'AGENDA_EXT_COLOR'.$i; + $default = 'AGENDA_EXT_ACTIVEBYDEFAULT'.$i; + $buggedfile = 'AGENDA_EXT_BUGGEDFILE'.$i; + if (getDolGlobalString($source) && getDolGlobalString($name)) { + // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight' + $listofextcals[] = array( + 'type' => 'globalsetup', + 'src' => getDolGlobalString($source), + 'name' => dol_string_nohtmltag(getDolGlobalString($name)), + 'offsettz' => (int) getDolGlobalInt($offsettz, 0), + 'color' => dol_string_nohtmltag(getDolGlobalString($color)), + // @phan-suppress-next-line PhanPluginSuspiciousParamPosition + 'default' => dol_string_nohtmltag(getDolGlobalString($default)), + 'buggedfile' => dol_string_nohtmltag(getDolGlobalString('buggedfile', '')) + ); } } // Define list of external calendars (user setup) -if (!getDolUserString('AGENDA_DISABLE_EXT')) { - $i = 0; - while ($i < $MAXAGENDA) { - $i++; - $source = 'AGENDA_EXT_SRC_'.$user->id.'_'.$i; - $name = 'AGENDA_EXT_NAME_'.$user->id.'_'.$i; - $offsettz = 'AGENDA_EXT_OFFSETTZ_'.$user->id.'_'.$i; - $color = 'AGENDA_EXT_COLOR_'.$user->id.'_'.$i; - $enabled = 'AGENDA_EXT_ENABLED_'.$user->id.'_'.$i; - $default = 'AGENDA_EXT_ACTIVEBYDEFAULT_'.$user->id.'_'.$i; - $buggedfile = 'AGENDA_EXT_BUGGEDFILE_'.$user->id.'_'.$i; +$i = 0; +while ($i < $MAXAGENDA) { + $i++; + $source = 'AGENDA_EXT_SRC_'.$user->id.'_'.$i; + $name = 'AGENDA_EXT_NAME_'.$user->id.'_'.$i; + $offsettz = 'AGENDA_EXT_OFFSETTZ_'.$user->id.'_'.$i; + $color = 'AGENDA_EXT_COLOR_'.$user->id.'_'.$i; + $enabled = 'AGENDA_EXT_ENABLED_'.$user->id.'_'.$i; + $default = 'AGENDA_EXT_ACTIVEBYDEFAULT_'.$user->id.'_'.$i; + $buggedfile = 'AGENDA_EXT_BUGGEDFILE_'.$user->id.'_'.$i; - if (getDolUserString($source) && getDolUserString($name)) { - // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight' - $listofextcals[] = array( - 'type' => 'usersetup', - 'src' => getDolUserString($source), - 'name' => dol_string_nohtmltag(getDolUserString($name)), - 'offsettz' => (int) (empty($user->conf->$offsettz) ? 0 : $user->conf->$offsettz), - 'color' => dol_string_nohtmltag(getDolUserString($color)), - // @phan-suppress-next-line PhanPluginSuspiciousParamPosition - 'default' => dol_string_nohtmltag(getDolUserString($default)), - 'buggedfile' => dol_string_nohtmltag(isset($user->conf->buggedfile) ? $user->conf->buggedfile : '') - ); - } + if (getDolUserString($source) && getDolUserString($name)) { + // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight' + $listofextcals[] = array( + 'type' => 'usersetup', + 'src' => getDolUserString($source), + 'name' => dol_string_nohtmltag(getDolUserString($name)), + 'offsettz' => (int) (empty($user->conf->$offsettz) ? 0 : $user->conf->$offsettz), + 'color' => dol_string_nohtmltag(getDolUserString($color)), + // @phan-suppress-next-line PhanPluginSuspiciousParamPosition + 'default' => dol_string_nohtmltag(getDolUserString($default)), + 'buggedfile' => dol_string_nohtmltag(isset($user->conf->buggedfile) ? $user->conf->buggedfile : '') + ); } } diff --git a/htdocs/core/lib/usergroups.lib.php b/htdocs/core/lib/usergroups.lib.php index f1e24d565cb..2226c80de71 100644 --- a/htdocs/core/lib/usergroups.lib.php +++ b/htdocs/core/lib/usergroups.lib.php @@ -75,10 +75,7 @@ function user_prepare_head(User $object) $h++; if (isModEnabled('agenda')) { - if (!getDolGlobalString('AGENDA_EXT_NB')) { - $conf->global->AGENDA_EXT_NB = 5; - } - $MAXAGENDA = getDolGlobalString('AGENDA_EXT_NB'); + $MAXAGENDA = getDolGlobalString('AGENDA_EXT_NB', 6); $i = 1; $nbagenda = 0; diff --git a/htdocs/user/agenda_extsites.php b/htdocs/user/agenda_extsites.php index f5f7e1418d0..2e442bd96dd 100644 --- a/htdocs/user/agenda_extsites.php +++ b/htdocs/user/agenda_extsites.php @@ -52,10 +52,7 @@ $actiontest = GETPOST('test', 'alpha'); $actionsave = GETPOST('save', 'alpha'); $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'useragenda'; // To manage different context of search -if (!getDolGlobalString('AGENDA_EXT_NB')) { - $conf->global->AGENDA_EXT_NB = 5; -} -$MAXAGENDA = getDolGlobalString('AGENDA_EXT_NB'); +$MAXAGENDA = getDolGlobalString('AGENDA_EXT_NB', 6); // List of available colors $colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', 'A4A4A5'); @@ -229,13 +226,6 @@ print '
'; print ''.$langs->trans("AgendaExtSitesDesc")."
\n"; print "
\n"; -$selectedvalue = !getDolGlobalString('AGENDA_DISABLE_EXT') ? 0 : $conf->global->AGENDA_DISABLE_EXT; -if ($selectedvalue == 1) { - $selectedvalue = 0; -} else { - $selectedvalue = 1; -} - print '
'; print '';