From 35345559096d0b05cdbf0dda173063691ca15bc6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 21 Nov 2020 14:14:53 +0100 Subject: [PATCH] Fix setup of scheduled jobs --- htdocs/admin/agenda_reminder.php | 75 ++++++++++++------------- htdocs/comm/action/card.php | 26 +++------ htdocs/core/class/html.form.class.php | 14 +++-- htdocs/core/lib/agenda.lib.php | 11 ++-- htdocs/core/lib/cron.lib.php | 5 ++ htdocs/core/modules/modAgenda.class.php | 2 +- htdocs/cron/admin/cron.php | 6 +- htdocs/cron/card.php | 12 ++-- htdocs/cron/list.php | 40 +++++++++---- htdocs/langs/en_US/admin.lang | 5 +- htdocs/langs/en_US/agenda.lang | 2 +- htdocs/langs/en_US/cron.lang | 4 +- 12 files changed, 110 insertions(+), 92 deletions(-) diff --git a/htdocs/admin/agenda_reminder.php b/htdocs/admin/agenda_reminder.php index e34536e648a..7dfbeff82f6 100644 --- a/htdocs/admin/agenda_reminder.php +++ b/htdocs/admin/agenda_reminder.php @@ -179,53 +179,52 @@ print ' '."\n"; print ''.$langs->trans("Value").''."\n"; print ''."\n"; +// AGENDA REMINDER BROWSER +print ''."\n"; +print ''.$langs->trans('AGENDA_REMINDER_BROWSER').''."\n"; +print ' '."\n"; +print ''."\n"; + +if (empty($conf->global->AGENDA_REMINDER_BROWSER)) { + print ''.img_picto($langs->trans('Disabled'), 'switch_off').''; + print ''."\n"; +} else { + print ''.img_picto($langs->trans('Enabled'), 'switch_on').''; + print ''."\n"; + + print ''."\n"; + print ''.$langs->trans('AGENDA_REMINDER_BROWSER_SOUND').''."\n"; + print ' '."\n"; + print ''."\n"; + + if (empty($conf->global->AGENDA_REMINDER_BROWSER_SOUND)) { + print ''.img_picto($langs->trans('Disabled'), 'switch_off').''; + } else { + print ''.img_picto($langs->trans('Enabled'), 'switch_on').''; + } + + print ''."\n"; +} // AGENDA REMINDER EMAIL -if ($conf->global->MAIN_FEATURES_LEVEL == 2) -{ - print ''."\n"; - print ''.$langs->trans('AGENDA_REMINDER_EMAIL', $langs->transnoentities("Module2300Name")).''."\n"; - print ' '."\n"; - print ''."\n"; +print ''."\n"; +print ''.$langs->trans('AGENDA_REMINDER_EMAIL', $langs->transnoentities("Module2300Name")).''."\n"; +print ' '."\n"; +print ''."\n"; +if (empty($conf->cron->enabled)) { + print ''.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Module2300Name")).''; +} else { if (empty($conf->global->AGENDA_REMINDER_EMAIL)) { print ''.img_picto($langs->trans('Disabled'), 'switch_off').''; - print ''."\n"; } else { print ''.img_picto($langs->trans('Enabled'), 'switch_on').''; - print ''."\n"; - } -} - -// AGENDA REMINDER BROWSER -if ($conf->global->MAIN_FEATURES_LEVEL == 2) -{ - print ''."\n"; - print ''.$langs->trans('AGENDA_REMINDER_BROWSER').''."\n"; - print ' '."\n"; - print ''."\n"; - - if (empty($conf->global->AGENDA_REMINDER_BROWSER)) { - print ''.img_picto($langs->trans('Disabled'), 'switch_off').''; - print ''."\n"; - } else { - print ''.img_picto($langs->trans('Enabled'), 'switch_on').''; - print ''."\n"; - - print ''."\n"; - print ''.$langs->trans('AGENDA_REMINDER_BROWSER_SOUND').''."\n"; - print ' '."\n"; - print ''."\n"; - - if (empty($conf->global->AGENDA_REMINDER_BROWSER_SOUND)) { - print ''.img_picto($langs->trans('Disabled'), 'switch_off').''; - } else { - print ''.img_picto($langs->trans('Enabled'), 'switch_on').''; - } - - print ''."\n"; + // Get the max frequency of reminder + + print '
'.$langs->trans("AGENDA_REMINDER_EMAIL_NOTE", $langs->transnoentitiesnoconv("Module2300Name")).''; } } +print ''."\n"; print ''; diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 0b1eba637d4..6d51a16ddc2 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -117,8 +117,8 @@ $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); $TRemindTypes = array(); -if (!empty($conf->global->AGENDA_REMINDER_EMAIL)) $TRemindTypes['email'] = $langs->trans('EMail'); -if (!empty($conf->global->AGENDA_REMINDER_BROWSER)) $TRemindTypes['browser'] = $langs->trans('BrowserPush'); +if (!empty($conf->global->AGENDA_REMINDER_BROWSER)) $TRemindTypes['browser'] = array('label'=>$langs->trans('BrowserPush'), 'disabled'=>(empty($conf->global->AGENDA_REMINDER_BROWSER) ? 1 : 0)); +if (!empty($conf->global->AGENDA_REMINDER_EMAIL)) $TRemindTypes['email'] = array('label'=>$langs->trans('EMail'), 'disabled'=>(empty($conf->global->AGENDA_REMINDER_EMAIL) ? 1 : 0)); $TDurationTypes = array('y'=>$langs->trans('Years'), 'm'=>$langs->trans('Month'), 'w'=>$langs->trans('Weeks'), 'd'=>$langs->trans('Days'), 'h'=>$langs->trans('Hours'), 'i'=>$langs->trans('Minutes')); @@ -1247,12 +1247,7 @@ if ($action == 'create') //Reminder print ''.$langs->trans("ReminderTime").''; - print ''; - print ''; - - //Time Type - print ''.$langs->trans("TimeType").''; - print $form->selectTypeDuration('offsetunit', 'i'); + print ' '.$form->selectTypeDuration('offsetunit', 'i'); print ''; //Reminder Type @@ -1731,20 +1726,13 @@ if ($id > 0) print ''; - //Reminder + // Reminder print ''; - //Time Type - print ''; - - //Reminder Type + // Reminder Type $TRemindTypes = array(); - if (!empty($conf->global->AGENDA_REMINDER_EMAIL)) $TRemindTypes['email'] = $langs->trans('EMail'); - if (!empty($conf->global->AGENDA_REMINDER_BROWSER)) $TRemindTypes['browser'] = $langs->trans('BrowserPush'); print ''; @@ -1752,7 +1740,7 @@ if ($id > 0) $hide = ''; if ($actionCommReminder->typeremind == 'browser') $hide = 'style="display:none;"'; - //Mail Model + // Mail Model print ''; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 0173e03730e..a7bcc562a9b 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6259,7 +6259,7 @@ class Form * Note: Do not apply langs->trans function on returned content, content may be entity encoded twice. * * @param string $htmlname Name of html select area. Must start with "multi" if this is a multiselect - * @param array $array Array like array(key => value) or array(key=>array('label'=>..., 'data-...'=>...)) + * @param array $array Array like array(key => value) or array(key=>array('label'=>..., 'data-...'=>..., 'disabled'=>..., 'css'=>...)) * @param string|string[] $id Preselected key or preselected keys for multiselect * @param int|string $show_empty 0 no empty value allowed, 1 or string to add an empty value into list (key is -1 and value is '' or ' ' if 1, key is -1 and value is text if string), <0 to add an empty value with key that is this value. * @param int $key_in_label 1 to show key into label with format "[key] value" @@ -6331,10 +6331,14 @@ class Form foreach ($array as $key => $tmpvalue) { - if (is_array($tmpvalue)) $value = $tmpvalue['label']; - else $value = $tmpvalue; - - $disabled = ''; $style = ''; + if (is_array($tmpvalue)) { + $value = $tmpvalue['label']; + $disabled = empty($tmpvalue['disabled']) ? '' : ' disabled'; + $style = empty($tmpvalue['css']) ? ' class="'.$tmpvalue['css'].'"' : ''; + } else { + $value = $tmpvalue; + $disabled = ''; $style = ''; + } if (!empty($disablebademail)) { if (($disablebademail == 1 && !preg_match('/<.+@.+>/', $value)) diff --git a/htdocs/core/lib/agenda.lib.php b/htdocs/core/lib/agenda.lib.php index 599ee983296..8241b415726 100644 --- a/htdocs/core/lib/agenda.lib.php +++ b/htdocs/core/lib/agenda.lib.php @@ -356,13 +356,10 @@ function agenda_prepare_head() $head[$h][2] = 'autoactions'; $h++; - if ($conf->global->MAIN_FEATURES_LEVEL > 0) - { - $head[$h][0] = DOL_URL_ROOT."/admin/agenda_reminder.php"; - $head[$h][1] = $langs->trans("Reminders"); - $head[$h][2] = 'reminders'; - $h++; - } + $head[$h][0] = DOL_URL_ROOT."/admin/agenda_reminder.php"; + $head[$h][1] = $langs->trans("Reminders"); + $head[$h][2] = 'reminders'; + $h++; $head[$h][0] = DOL_URL_ROOT."/admin/agenda_xcal.php"; $head[$h][1] = $langs->trans("ExportCal"); diff --git a/htdocs/core/lib/cron.lib.php b/htdocs/core/lib/cron.lib.php index 084b781d3b4..fda122be7bf 100644 --- a/htdocs/core/lib/cron.lib.php +++ b/htdocs/core/lib/cron.lib.php @@ -39,6 +39,11 @@ function cronadmin_prepare_head() $head[$h][2] = 'setup'; $h++; + $head[$h][0] = dol_buildpath('/cron/list.php?mode=modulesetup', 1); + $head[$h][1] = $langs->trans("Module2300Name"); + $head[$h][2] = 'jobs'; + $h++; + complete_head_from_modules($conf, $langs, null, $head, $h, 'cronadmin'); complete_head_from_modules($conf, $langs, null, $head, $h, 'cronadmin', 'remove'); diff --git a/htdocs/core/modules/modAgenda.class.php b/htdocs/core/modules/modAgenda.class.php index 0712adc59fb..559260a77c2 100644 --- a/htdocs/core/modules/modAgenda.class.php +++ b/htdocs/core/modules/modAgenda.class.php @@ -113,7 +113,7 @@ class modAgenda extends DolibarrModules //------------ $datestart = dol_now(); $this->cronjobs = array( - 0=>array('label'=>'SendEmailsReminders', 'jobtype'=>'method', 'class'=>'comm/action/class/actioncomm.class.php', 'objectname'=>'ActionComm', 'method'=>'sendEmailsReminder', 'parameters'=>'', 'comment'=>'SendEMailsReminder', 'frequency'=>10, 'unitfrequency'=>60, 'priority'=>10, 'status'=>1, 'test'=>'$conf->agenda->enabled', 'datestart'=>$datestart), + 0=>array('label'=>'SendEmailsReminders', 'jobtype'=>'method', 'class'=>'comm/action/class/actioncomm.class.php', 'objectname'=>'ActionComm', 'method'=>'sendEmailsReminder', 'parameters'=>'', 'comment'=>'SendEMailsReminder', 'frequency'=>5, 'unitfrequency'=>60, 'priority'=>10, 'status'=>1, 'test'=>'$conf->agenda->enabled', 'datestart'=>$datestart), ); // Permissions diff --git a/htdocs/cron/admin/cron.php b/htdocs/cron/admin/cron.php index fc3ca7c63b6..b0431f40dee 100644 --- a/htdocs/cron/admin/cron.php +++ b/htdocs/cron/admin/cron.php @@ -35,7 +35,7 @@ $langs->loadLangs(array('admin', 'cron')); if (!$user->admin) accessforbidden(); -$actionsave = GETPOST("save"); +$actionsave = GETPOST("save", 'alphanohtml'); // Save parameters if (!empty($actionsave)) @@ -75,6 +75,8 @@ print ''; print dol_get_fiche_head($head, 'setup', $langs->trans("Module2300Name"), -1, 'cron'); +print ''.$langs->trans('CronInfo').'
'; + print "
\n"; print '
'.$langs->trans("ReminderTime").''; - print ''; + print ' '.$form->selectTypeDuration('offsetunit', $actionCommReminder->offsetunit); print '
'.$langs->trans("TimeType").''; - print $form->selectTypeDuration('offsetunit', $actionCommReminder->offsetunit); - print '
'.$langs->trans("ReminderType").''; print $form->selectarray('selectremindertype', $TRemindTypes, $actionCommReminder->typeremind); print '
'.$langs->trans("EMailTemplates").''; print $form->selectModelMail('actioncommsend', 'actioncomm_send', 1); print '
'; @@ -116,7 +118,7 @@ print ''; print '


'; -print $langs->trans("UseMenuModuleToolsToAddCronJobs", dol_buildpath('/cron/list.php?leftmenu=admintools', 1)).'
'; +//print $langs->trans("UseMenuModuleToolsToAddCronJobs", dol_buildpath('/cron/list.php?leftmenu=admintools', 1)).'
'; if (!empty($conf->global->CRON_WARNING_DELAY_HOURS)) print info_admin($langs->trans("WarningCronDelayed", $conf->global->CRON_WARNING_DELAY_HOURS)).'
'; print '
'; diff --git a/htdocs/cron/card.php b/htdocs/cron/card.php index 9c3a2b38f02..a67b7633044 100644 --- a/htdocs/cron/card.php +++ b/htdocs/cron/card.php @@ -42,7 +42,9 @@ $id = GETPOST('id', 'int'); $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); -$backtourl = GETPOST('backtourl', 'alpha'); +$backtopage = GETPOST('backtopage', 'alpha'); +$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); + $securitykey = GETPOST('securitykey', 'alpha'); @@ -62,13 +64,13 @@ if (!empty($id)) if (!empty($cancel)) { - if (!empty($id) && empty($backtourl)) + if (!empty($id) && empty($backtopage)) { $action = ''; } else { - if ($backtourl) + if ($backtopage) { - header("Location: ".$backtourl); + header("Location: ".$backtopage); exit; } else { header("Location: ".DOL_URL_ROOT.'/cron/list.php'); @@ -297,7 +299,7 @@ if (($action == "create") || ($action == "edit")) { print ''; print ''."\n"; - print ''."\n"; + print ''."\n"; if (!empty($object->id)) { print ''."\n"; print ''."\n"; diff --git a/htdocs/cron/list.php b/htdocs/cron/list.php index ec1143cd89a..b80f67b25bd 100644 --- a/htdocs/cron/list.php +++ b/htdocs/cron/list.php @@ -55,10 +55,12 @@ $pagenext = $page + 1; if (!$sortfield) $sortfield = 't.status,t.priority'; if (!$sortorder) $sortorder = 'DESC,ASC'; -$search_status = (GETPOSTISSET('search_status') ?GETPOST('search_status', 'int') : GETPOST('status', 'int')); - +$mode = GETPOST('mode', 'aZ09'); //Search criteria +$search_status = (GETPOSTISSET('search_status') ?GETPOST('search_status', 'int') : GETPOST('status', 'int')); $search_label = GETPOST("search_label", 'alpha'); +$search_module_name = GETPOST("search_module_name", 'alpha'); + $securitykey = GETPOST('securitykey', 'alpha'); $diroutputmassaction = $conf->cronjob->dir_output.'/temp/massgeneration/'.$user->id; @@ -211,7 +213,6 @@ $pagetitle = $langs->trans("CronList"); llxHeader('', $pagetitle); - $sql = "SELECT"; $sql .= " t.rowid,"; $sql .= " t.tms,"; @@ -254,8 +255,8 @@ if (is_array($filter) && count($filter) > 0) { } } $sqlwhere = array(); -if (!empty($module_name)) { - $sqlwhere[] = '(t.module_name='.$db->escape($module_name).')'; +if (!empty($search_module_name)) { + $sqlwhere[] = '(t.module_name='.$db->escape($search_module_name).')'; } if (count($sqlwhere) > 0) { $sql .= " WHERE ".implode(' AND ', $sqlwhere); @@ -296,6 +297,8 @@ if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&co if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); if ($search_status) $param .= '&search_status='.urlencode($search_status); if ($search_label) $param .= '&search_label='.urlencode($search_label); +if ($search_module_name) $param .= '&search_module_name='.urlencode($search_module_name); +if ($mode) $param .= '&mode='.urlencode($mode); if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -322,6 +325,13 @@ if ($user->rights->mymodule->delete) $arrayofmassactions['predelete'] = 'selectMassAction('', $arrayofmassactions); +if ($mode == 'modulesetup') { + $linkback = ''.$langs->trans("BackToModuleList").''; + print load_fiche_titre($langs->trans("CronSetup"), $linkback, 'title_setup'); + + // Configuration header + $head = cronadmin_prepare_head(); +} print ''."\n"; if ($optioncss != '') print ''; @@ -332,15 +342,21 @@ print ''; print ''; print ''; print ''; +print ''; // Line with explanation and button new -$newcardbutton = dolGetButtonTitle($langs->trans('New'), $langs->trans('CronCreateJob'), 'fa fa-plus-circle', DOL_URL_ROOT.'/cron/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $user->rights->cron->create); +$newcardbutton = dolGetButtonTitle($langs->trans('New'), $langs->trans('CronCreateJob'), 'fa fa-plus-circle', DOL_URL_ROOT.'/cron/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF'].'?mode=modulesetup'), '', $user->rights->cron->create); -print_barre_liste($pagetitle, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_setup', 0, $newcardbutton, '', $limit); +if ($mode == 'modulesetup') { + print dol_get_fiche_head($head, 'jobs', $langs->trans("Module2300Name"), -1, 'cron'); + + //print ''.$langs->trans('CronInfo').'
'; +} -print ''.$langs->trans('CronInfo').'
'; +print_barre_liste($pagetitle, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, ($mode == 'modulesetup' ? '' : 'title_setup'), 0, $newcardbutton, '', $limit); + $text = $langs->trans("HoursOnThisPageAreOnServerTZ").' '.$stringcurrentdate.'
'; if (!empty($conf->global->CRON_WARNING_DELAY_HOURS)) $text .= $langs->trans("WarningCronDelayed", $conf->global->CRON_WARNING_DELAY_HOURS); @@ -533,11 +549,11 @@ if ($num > 0) print '
'; - $backtourl = urlencode($_SERVER["PHP_SELF"].'?'.$param.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '')); + $backtopage = urlencode($_SERVER["PHP_SELF"].'?'.$param.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '')); if ($user->rights->cron->create) { print 'trans('Edit'))."\">".img_picto($langs->trans('Edit'), 'edit')."  "; + print "&backtopage=".$backtopage."\" title=\"".dol_escape_htmltag($langs->trans('Edit'))."\">".img_picto($langs->trans('Edit'), 'edit')."  "; } if ($user->rights->cron->delete) { @@ -581,6 +597,10 @@ print ''; print ''; +if ($mode == 'modulesetup') { + print dol_get_fiche_end(); +} + print '

'; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index dd8e6fe6538..bcd038334ba 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1738,9 +1738,10 @@ AGENDA_USE_EVENT_TYPE_DEFAULT=Automatically set this default value for type of e AGENDA_DEFAULT_FILTER_TYPE=Automatically set this type of event in search filter of agenda view AGENDA_DEFAULT_FILTER_STATUS=Automatically set this status for events in search filter of agenda view AGENDA_DEFAULT_VIEW=Which view do you want to open by default when selecting menu Agenda -AGENDA_REMINDER_EMAIL=Enable event reminder by emails (remind option/delay can be defined on each event). Note: Module %s must be enabled and correctly setup to have reminder sent at the correct frequency. -AGENDA_REMINDER_BROWSER=Enable event reminder on user's browser (when event date is reached, each user is able to refuse this from the browser confirmation question) +AGENDA_REMINDER_BROWSER=Enable event reminder on user's browser (When remind date is reached, a popup is shown by the browser. Each user can disable such notifications from its browser notification setup). AGENDA_REMINDER_BROWSER_SOUND=Enable sound notification +AGENDA_REMINDER_EMAIL=Enable event reminder by emails (remind option/delay can be defined on each event). +AGENDA_REMINDER_EMAIL_NOTE=Note: Module %s must be enabled and correctly setup to have reminder sent at the correct frequency. AGENDA_SHOW_LINKED_OBJECT=Show linked object into agenda view ##### Clicktodial ##### ClickToDialSetup=Click To Dial module setup diff --git a/htdocs/langs/en_US/agenda.lang b/htdocs/langs/en_US/agenda.lang index 479155fb2a9..8971e80a8f8 100644 --- a/htdocs/langs/en_US/agenda.lang +++ b/htdocs/langs/en_US/agenda.lang @@ -166,4 +166,4 @@ TimeType=Duration type ReminderType=Callback type AddReminder=Create an automatic reminder notification for this event ErrorReminderActionCommCreation=Error creating the reminder notification for this event -BrowserPush=Browser Notification \ No newline at end of file +BrowserPush=Browser Popup Notification \ No newline at end of file diff --git a/htdocs/langs/en_US/cron.lang b/htdocs/langs/en_US/cron.lang index 9921f21851d..753b37da438 100644 --- a/htdocs/langs/en_US/cron.lang +++ b/htdocs/langs/en_US/cron.lang @@ -7,8 +7,8 @@ Permission23103 = Delete Scheduled job Permission23104 = Execute Scheduled job # Admin CronSetup=Scheduled job management setup -URLToLaunchCronJobs=URL to check and launch qualified cron jobs -OrToLaunchASpecificJob=Or to check and launch a specific job +URLToLaunchCronJobs=URL to check and launch qualified cron jobs from a browser +OrToLaunchASpecificJob=Or to check and launch a specific job from a browser KeyForCronAccess=Security key for URL to launch cron jobs FileToLaunchCronJobs=Command line to check and launch qualified cron jobs CronExplainHowToRunUnix=On Unix environment you should use the following crontab entry to run the command line each 5 minutes