From 6c2cf4377a9253915c14d1a1fa6496f542474132 Mon Sep 17 00:00:00 2001 From: lvessiller Date: Tue, 31 Aug 2021 18:14:16 +0200 Subject: [PATCH 1/6] NEW can enable/disable external calendar by default --- htdocs/admin/agenda_extsites.php | 69 +++++++++++++++++++++++++++++--- htdocs/comm/action/index.php | 22 +++++++++- htdocs/langs/en_US/agenda.lang | 3 +- htdocs/langs/fr_FR/agenda.lang | 1 + 4 files changed, 88 insertions(+), 7 deletions(-) diff --git a/htdocs/admin/agenda_extsites.php b/htdocs/admin/agenda_extsites.php index 272da835741..bf6c8bdee2a 100644 --- a/htdocs/admin/agenda_extsites.php +++ b/htdocs/admin/agenda_extsites.php @@ -41,8 +41,7 @@ if (!$user->admin) { $langs->loadLangs(array('agenda', 'admin', 'other')); $def = array(); -$actiontest = GETPOST('test', 'alpha'); -$actionsave = GETPOST('save', 'alpha'); +$action = GETPOST('action', 'alpha'); if (empty($conf->global->AGENDA_EXT_NB)) { $conf->global->AGENDA_EXT_NB = 5; @@ -57,14 +56,57 @@ $colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', ' * Actions */ -if ($actionsave) { +$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; - $error = 0; // Save agendas while ($i <= $MAXAGENDA) { @@ -159,6 +201,10 @@ print dol_get_fiche_head($head, 'extsites', $langs->trans("Agenda"), -1, 'action print ''.$langs->trans("AgendaExtSitesDesc")."
\n"; print "
\n"; + +$selectedvalue=$conf->global->AGENDA_DISABLE_EXT; +if ($selectedvalue==1) $selectedvalue=0; else $selectedvalue=1; + print ""; print ""; @@ -203,6 +249,7 @@ print ""; print "'; print "'; print ''; +print ''; print ""; $i = 1; @@ -213,7 +260,7 @@ while ($i <= $MAXAGENDA) { $offsettz = 'AGENDA_EXT_OFFSETTZ'.$key; $color = 'AGENDA_EXT_COLOR'.$key; $enabled = 'AGENDA_EXT_ENABLED'.$key; - + $default = 'AGENDA_EXT_ACTIVEBYDEFAULT'.$key; print ''; // Nb @@ -229,6 +276,18 @@ while ($i <= $MAXAGENDA) { //print $formadmin->selectColor($conf->global->$color, "google_agenda_color".$key, $colorlist); print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR".$key) ?GETPOST("AGENDA_EXT_COLOR".$key) : getDolGlobalString($color)), "AGENDA_EXT_COLOR".$key, 'extsitesconfig', 1, '', 'hideifnotset'); print ''; + // Calendar active by default + print ''; print ""; $i++; } diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index 19aff1699c8..321457445aa 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -265,6 +265,7 @@ if (empty($conf->global->AGENDA_DISABLE_EXT)) { $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 (!empty($conf->global->$source) && !empty($conf->global->$name)) { // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight' @@ -273,6 +274,7 @@ if (empty($conf->global->AGENDA_DISABLE_EXT)) { 'name'=>$conf->global->$name, 'offsettz' => (!empty($conf->global->$offsettz) ? $conf->global->$offsettz : 0), 'color'=>$conf->global->$color, + 'default'=>$conf->global->$default, 'buggedfile'=>(isset($conf->global->buggedfile) ? $conf->global->buggedfile : 0) ); } @@ -288,6 +290,7 @@ if (empty($user->conf->AGENDA_DISABLE_EXT)) { $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 (!empty($user->conf->$source) && !empty($user->conf->$name)) { // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight' @@ -296,6 +299,7 @@ if (empty($user->conf->AGENDA_DISABLE_EXT)) { 'name'=>$user->conf->$name, 'offsettz' => (!empty($user->conf->$offsettz) ? $user->conf->$offsettz : 0), 'color'=>$user->conf->$color, + 'default'=>$user->conf->$default, 'buggedfile'=>(isset($user->conf->buggedfile) ? $user->conf->buggedfile : 0) ); } @@ -576,6 +580,15 @@ if (!empty($conf->use_javascript_ajax)) { // If javascript on if (is_array($showextcals) && count($showextcals) > 0) { $s .= '
".$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").'
'; + if ($conf->use_javascript_ajax) { + print ajax_constantonoff('AGENDA_EXT_ACTIVEBYDEFAULT'.$key); + } else { + if (empty($conf->global->{$default})) { + print ''.img_picto($langs->trans("Enabled"), 'on').''; + } else { + print ''.img_picto($langs->trans("Disabled"), 'off').''; + } + } + print '