dolibarr 22.0.5
list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
3 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
4 * Copyright (C) 2013-2021 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/cron/class/cronjob.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35
44// Load translation files required by the page
45$langs->loadLangs(array("admin", "cron", "bills", "members"));
46
47$action = GETPOST('action', 'aZ09');
48$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
49$confirm = GETPOST('confirm', 'alpha');
50$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
51$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'cronjoblist'; // To manage different context of search
52
53$id = GETPOSTINT('id');
54
55$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
56$sortfield = GETPOST('sortfield', 'aZ09comma');
57$sortorder = GETPOST('sortorder', 'aZ09comma');
58$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
59if (empty($page) || $page == -1) {
60 $page = 0;
61} // If $page is not defined, or '' or -1
62$offset = $limit * $page;
63$pageprev = $page - 1;
64$pagenext = $page + 1;
65if (!$sortfield) {
66 $sortfield = 't.priority,t.status';
67}
68if (!$sortorder) {
69 $sortorder = 'ASC,DESC';
70}
71$optioncss = GETPOST('optioncss', 'alpha');
72$mode = GETPOST('mode', 'aZ09');
73//Search criteria
74$search_status = GETPOST('search_status', 'intcomma');
75$search_label = GETPOST("search_label", 'alpha');
76$search_module_name = GETPOST("search_module_name", 'alpha');
77$search_lastresult = GETPOST("search_lastresult", "alphawithlgt");
78$search_processing = GETPOST("search_processing", 'int');
79$securitykey = GETPOST('securitykey', 'alpha');
80
81$outputdir = $conf->cron->dir_output;
82if (empty($outputdir)) {
83 $outputdir = $conf->cronjob->dir_output;
84}
85$diroutputmassaction = $outputdir.'/temp/massgeneration/'.$user->id;
86
87$object = new Cronjob($db);
88
89// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
90$hookmanager->initHooks(array('cronjoblist'));
91$extrafields = new ExtraFields($db);
92
93// fetch optionals attributes and labels
94$extrafields->fetch_name_optionals_label($object->table_element);
95
96$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
97
98// Security
99if (!$user->hasRight('cron', 'read')) {
101}
102
103$permissiontoread = $user->hasRight('cron', 'read');
104$permissiontoadd = $user->hasRight('cron', 'create') ? $user->hasRight('cron', 'create') : $user->hasRight('cron', 'write');
105$permissiontodelete = $user->hasRight('cron', 'delete');
106$permissiontoexecute = $user->hasRight('cron', 'execute');
107
108
109/*
110 * Actions
111 */
112$error = 0;
113
114if (GETPOST('cancel', 'alpha')) {
115 $action = 'list';
116 $massaction = '';
117}
118if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
119 $massaction = '';
120}
121
122$parameters = array();
123$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
124if ($reshook < 0) {
125 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
126}
127
128if (empty($reshook)) {
129 // Selection of new fields
130 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
131
132 // Purge search criteria
133 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
134 $search_label = '';
135 $search_status = -1;
136 $search_module_name = '';
137 $search_lastresult = '';
138 $toselect = array();
139 $search_array_options = array();
140 }
141 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
142 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
143 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
144 }
145
146 $filter = array();
147 if (!empty($search_label)) {
148 $filter['t.label'] = $search_label;
149 }
150
151 // Delete jobs
152 if ($action == 'confirm_delete' && $confirm == "yes" && $permissiontodelete) {
153 //Delete cron task
154 $object = new Cronjob($db);
155 $object->id = $id;
156 $result = $object->delete($user);
157
158 if ($result < 0) {
159 setEventMessages($object->error, $object->errors, 'errors');
160 }
161 }
162
163 // Execute jobs
164 if ($action == 'confirm_execute' && $confirm == "yes" && $permissiontoexecute) {
165 if (getDolGlobalString('CRON_KEY') && $conf->global->CRON_KEY != $securitykey) {
166 setEventMessages('Security key '.$securitykey.' is wrong', null, 'errors');
167 $action = '';
168 } else {
169 $object = new Cronjob($db);
170 $job = $object->fetch($id);
171
172 $now = dol_now(); // Date we start
173
174 $resrunjob = $object->run_jobs($user->login); // Return -1 if KO, 1 if OK
175 if ($resrunjob < 0) {
176 setEventMessages($object->error, $object->errors, 'errors');
177 }
178
179 // Plan next run
180 $res = $object->reprogram_jobs($user->login, $now);
181 if ($res > 0) {
182 if ($resrunjob >= 0) { // We show the result of reprogram only if no error message already reported
183 if ($object->lastresult >= 0) {
184 setEventMessages($langs->trans("JobFinished"), null, 'mesgs');
185 } else {
186 setEventMessages($langs->trans("JobFinished"), null, 'errors');
187 }
188 }
189 $action = '';
190 } else {
191 setEventMessages($object->error, $object->errors, 'errors');
192 $action = '';
193 }
194
195 $param = '&search_status='.urlencode($search_status);
196 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
197 $param .= '&contextpage='.urlencode($contextpage);
198 }
199 if ($limit > 0 && $limit != $conf->liste_limit) {
200 $param .= '&limit='.((int) $limit);
201 }
202 if ($search_label) {
203 $param .= '&search_label='.urlencode($search_label);
204 }
205 if ($search_module_name) {
206 $param .= '&search_module_name='.urlencode($search_module_name);
207 }
208 if ($search_lastresult) {
209 $param .= '&search_lastresult='.urlencode($search_lastresult);
210 }
211 if ($mode) {
212 $param .= '&mode='.urlencode($mode);
213 }
214 if ($optioncss != '') {
215 $param .= '&optioncss='.urlencode($optioncss);
216 }
217 // Add $param from extra fields
218 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
219
220 header("Location: ".DOL_URL_ROOT.'/cron/list.php?'.$param.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '')); // Make a redirect to avoid to run twice the job when using back
221 exit;
222 }
223 }
224
225 // Mass actions
226 $objectclass = 'CronJob';
227 $objectlabel = 'CronJob';
228 $uploaddir = $conf->cron->dir_output;
229 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
230 if ($massaction && $permissiontoadd) {
231 $tmpcron = new Cronjob($db);
232 foreach ($toselect as $id) {
233 $result = $tmpcron->fetch($id);
234 if ($result) {
235 $result = 0;
236 if ($massaction == 'disable') {
237 $result = $tmpcron->setStatut(Cronjob::STATUS_DISABLED);
238 } elseif ($massaction == 'enable') {
239 $result = $tmpcron->setStatut(Cronjob::STATUS_ENABLED);
240 }
241 //else dol_print_error($db, 'Bad value for massaction');
242 if ($result < 0) {
243 setEventMessages($tmpcron->error, $tmpcron->errors, 'errors');
244 }
245 } else {
246 $error++;
247 }
248 }
249 }
250}
251
252
253/*
254 * View
255 */
256
257$form = new Form($db);
258$cronjob = new Cronjob($db);
259
260$title = $langs->trans("CronList");
261
262llxHeader('', $title, '', '', 0, 0, '', '', '', 'bodyforlist');
263
264$TTestNotAllowed = array();
265$sqlTest = 'SELECT rowid, test FROM '.MAIN_DB_PREFIX.'cronjob';
266$resultTest = $db->query($sqlTest);
267if ($resultTest) {
268 while ($objTest = $db->fetch_object($resultTest)) {
269 $veriftest = verifCond($objTest->test);
270 if (!$veriftest) {
271 $TTestNotAllowed[$objTest->rowid] = $objTest->rowid;
272 }
273 }
274}
275
276$sql = "SELECT";
277$sql .= " t.rowid,";
278$sql .= " t.tms,";
279$sql .= " t.datec,";
280$sql .= " t.jobtype,";
281$sql .= " t.label,";
282$sql .= " t.command,";
283$sql .= " t.classesname,";
284$sql .= " t.objectname,";
285$sql .= " t.methodename,";
286$sql .= " t.params,";
287$sql .= " t.md5params,";
288$sql .= " t.module_name,";
289$sql .= " t.priority,";
290$sql .= " t.processing,";
291$sql .= " t.datelastrun,";
292$sql .= " t.datenextrun,";
293$sql .= " t.dateend,";
294$sql .= " t.datestart,";
295$sql .= " t.lastresult,";
296$sql .= " t.datelastresult,";
297$sql .= " t.lastoutput,";
298$sql .= " t.unitfrequency,";
299$sql .= " t.frequency,";
300$sql .= " t.status,";
301$sql .= " t.fk_user_author,";
302$sql .= " t.fk_user_mod,";
303$sql .= " t.note,";
304$sql .= " t.maxrun,";
305$sql .= " t.nbrun,";
306$sql .= " t.libname,";
307$sql .= " t.test";
308$sql .= " FROM ".MAIN_DB_PREFIX."cronjob as t";
309$sql .= " WHERE entity IN (0,".$conf->entity.")";
310if (!empty($TTestNotAllowed)) {
311 $sql .= ' AND t.rowid NOT IN ('.$db->sanitize(implode(',', $TTestNotAllowed)).')';
312}
313if ($search_status >= 0 && $search_status < 2 && $search_status != '') {
314 $sql .= " AND t.status = ".(empty($search_status) ? '0' : '1');
315}
316if ($search_lastresult != '') {
317 $sql .= natural_search("t.lastresult", $search_lastresult, 1);
318}
319if (GETPOSTISSET('search_processing')) {
320 $sql .= " AND t.processing = ".((int) $search_processing);
321}
322// Manage filter
323if (is_array($filter) && count($filter) > 0) {
324 foreach ($filter as $key => $value) {
325 $sql .= " AND ".$db->sanitize($key)." LIKE '%".$db->escape($value)."%'";
326 }
327}
328if (!empty($search_module_name)) {
329 $sql .= natural_search("t.module_name", $search_module_name);
330}
331// Add where from extra fields
332include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
333// Add where from hooks
334$parameters = array();
335$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
336$sql .= $hookmanager->resPrint;
337
338$sql .= $db->order($sortfield, $sortorder);
339// Count total nb of records
340$nbtotalofrecords = '';
341if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
342 $result = $db->query($sql);
343 $nbtotalofrecords = $db->num_rows($result);
344 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
345 $page = 0;
346 $offset = 0;
347 }
348}
349
350$sql .= $db->plimit($limit + 1, $offset);
351
352$result = $db->query($sql);
353if (!$result) {
354 dol_print_error($db);
355}
356
357$num = $db->num_rows($result);
358
359$arrayofselected = is_array($toselect) ? $toselect : array();
360
361$param = '';
362if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
363 $param .= '&contextpage='.urlencode($contextpage);
364}
365if ($limit > 0 && $limit != $conf->liste_limit) {
366 $param .= '&limit='.((int) $limit);
367}
368if ($search_status) {
369 $param .= '&search_status='.urlencode($search_status);
370}
371if ($search_label) {
372 $param .= '&search_label='.urlencode($search_label);
373}
374if ($search_module_name) {
375 $param .= '&search_module_name='.urlencode($search_module_name);
376}
377if ($search_lastresult) {
378 $param .= '&search_lastresult='.urlencode($search_lastresult);
379}
380if ($mode) {
381 $param .= '&mode='.urlencode($mode);
382}
383if ($optioncss != '') {
384 $param .= '&optioncss='.urlencode($optioncss);
385}
386// Add $param from extra fields
387include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
388
389$stringcurrentdate = $langs->trans("CurrentHour").': '.dol_print_date(dol_now(), 'dayhour');
390
391if ($action == 'execute') {
392 print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id.'&securitykey='.$securitykey.$param, $langs->trans("CronExecute"), $langs->trans("CronConfirmExecute"), "confirm_execute", '', '', 1);
393}
394
395if ($action == 'delete' && empty($toselect)) { // Used when we make a delete on 1 line (not used for mass delete)
396 print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id.$param, $langs->trans("CronDelete"), $langs->trans("CronConfirmDelete"), "confirm_delete", '', '', 1);
397}
398
399// List of mass actions available
400$arrayofmassactions = array(
401//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
402//'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
403 'enable' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("CronStatusActiveBtn"),
404 'disable' => img_picto('', 'uncheck', 'class="pictofixedwidth"').$langs->trans("CronStatusInactiveBtn"),
405);
406if ($user->hasRight('cron', 'delete')) {
407 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
408}
409if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
410 $arrayofmassactions = array();
411}
412$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
413
414$head = [];
415if ($mode == 'modulesetup') {
416 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
417 print load_fiche_titre($langs->trans("CronSetup"), $linkback, 'title_setup');
418
419 // Configuration header
420 $head = cronadmin_prepare_head();
421}
422
423print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" name="search_form">'."\n";
424if ($optioncss != '') {
425 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
426}
427print '<input type="hidden" name="token" value="'.newToken().'">';
428print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
429print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
430print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
431print '<input type="hidden" name="page" value="'.$page.'">';
432print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
433print '<input type="hidden" name="mode" value="'.$mode.'">';
434
435// Line with explanation and button new
436$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->hasRight('cron', 'create'));
437
438
439if ($mode == 'modulesetup') {
440 print dol_get_fiche_head($head, 'jobs', $langs->trans("Module2300Name"), -1, 'cron');
441
442 //print '<span class="opacitymedium">'.$langs->trans('CronInfo').'</span><br>';
443}
444
445
446print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, ($mode == 'modulesetup' ? '' : 'title_setup'), 0, $newcardbutton, '', $limit);
447
448// Add code for pre mass action (confirmation or email presend form)
449$topicmail = "SendCronRef";
450$modelmail = "cron";
451$objecttmp = new Cronjob($db);
452$trackid = 'cron'.$object->id;
453include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
454
455$text = $langs->trans("HoursOnThisPageAreOnServerTZ").' '.$stringcurrentdate.'<br>';
456if (getDolGlobalString('CRON_WARNING_DELAY_HOURS')) {
457 $text .= $langs->trans("WarningCronDelayed", getDolGlobalString('CRON_WARNING_DELAY_HOURS'));
458}
459print info_admin($text);
460//print '<br>';
461
462//$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
463$selectedfields = '';
464//$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
465$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
466
467print '<div class="div-table-responsive">';
468print '<table class="noborder liste">';
469
470print '<tr class="liste_titre_filter">';
471// Action column
472if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
473 print '<td class="liste_titre right">';
474 $searchpicto = $form->showFilterButtons();
475 print $searchpicto;
476 print '</td>';
477}
478print '<td class="liste_titre">&nbsp;</td>';
479print '<td class="liste_titre">';
480print '<input type="text" class="flat width75" name="search_label" value="'.$search_label.'">';
481print '</td>';
482//print '<td class="liste_titre">&nbsp;</td>';
483print '<td class="liste_titre"><input type="text" class="width50" name="search_module_name" value="'.$search_module_name.'"></td>';
484print '<td class="liste_titre">&nbsp;</td>';
485print '<td class="liste_titre">&nbsp;</td>';
486//print '<td class="liste_titre">&nbsp;</td>';
487//print '<td class="liste_titre">&nbsp;</td>';
488print '<td class="liste_titre">&nbsp;</td>';
489print '<td class="liste_titre">&nbsp;</td>';
490print '<td class="liste_titre">&nbsp;</td>';
491print '<td class="liste_titre center"><input type="text" class="width50" name="search_lastresult" value="'.$search_lastresult.'"></td>';
492print '<td class="liste_titre">&nbsp;</td>';
493print '<td class="liste_titre">&nbsp;</td>';
494print '<td class="liste_titre center">';
495print $form->selectarray('search_status', array('0' => $langs->trans("Disabled"), '1' => $langs->trans("Scheduled")), $search_status, 1, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage');
496print '</td>';
497print '<td class="liste_titre">&nbsp;</td>';
498// Action column
499if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
500 print '<td class="liste_titre right">';
501 $searchpicto = $form->showFilterButtons();
502 print $searchpicto;
503 print '</td>';
504}
505print '</tr>';
506
507print '<tr class="liste_titre">';
508// Action column
509if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
510 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'center maxwidthsearch ');
511}
512print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "t.rowid", "", $param, '', $sortfield, $sortorder);
513print_liste_field_titre("CronLabel", $_SERVER["PHP_SELF"], "t.label", "", $param, '', $sortfield, $sortorder);
514//print_liste_field_titre("Priority", $_SERVER["PHP_SELF"], "t.priority", "", $param, '', $sortfield, $sortorder);
515print_liste_field_titre("CronModule", $_SERVER["PHP_SELF"], "t.module_name", "", $param, '', $sortfield, $sortorder);
516print_liste_field_titre("", '', '', "", $param, '', $sortfield, $sortorder, 'tdoverflowmax50 ');
517print_liste_field_titre("CronFrequency", '', "", "", $param, '', $sortfield, $sortorder);
518//print_liste_field_titre("CronDtStart", $_SERVER["PHP_SELF"], "t.datestart", "", $param, 'align="center"', $sortfield, $sortorder);
519//print_liste_field_titre("CronDtEnd", $_SERVER["PHP_SELF"], "t.dateend", "", $param, 'align="center"', $sortfield, $sortorder);
520print_liste_field_titre("CronNbRun", $_SERVER["PHP_SELF"], "t.nbrun", "", $param, '', $sortfield, $sortorder, 'right tdoverflowmax50 maxwidth50imp ');
521print_liste_field_titre("CronDtLastLaunch", $_SERVER["PHP_SELF"], "t.datelastrun", "", $param, '', $sortfield, $sortorder, 'center tdoverflowmax100 ');
522print_liste_field_titre("Duration", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'center ');
523print_liste_field_titre("CronLastResult", $_SERVER["PHP_SELF"], "t.lastresult", "", $param, '', $sortfield, $sortorder, 'center ');
524print_liste_field_titre("CronLastOutput", $_SERVER["PHP_SELF"], "t.lastoutput", "", $param, '', $sortfield, $sortorder);
525print_liste_field_titre("CronDtNextLaunch", $_SERVER["PHP_SELF"], "t.datenextrun", "", $param, '', $sortfield, $sortorder, 'center ');
526print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "t.status,t.priority", "", $param, '', $sortfield, $sortorder, 'center ');
527print_liste_field_titre("", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'center ');
528// Action column
529if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
530 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'center maxwidthsearch ');
531}
532print "</tr>\n";
533
534
535if ($num > 0) {
536 // Loop on each job
537 $now = dol_now();
538 $i = 0;
539
540 while ($i < min($num, $limit)) {
541 $obj = $db->fetch_object($result);
542
543 if (empty($obj)) {
544 break;
545 }
546
547 $reg = array();
548 if (preg_match('/:(.*)$/', $obj->label, $reg)) {
549 $langs->load($reg[1]);
550 }
551
552 $object->id = $obj->rowid;
553 $object->ref = $obj->rowid;
554 $object->label = preg_replace('/:.*$/', '', $obj->label);
555 $object->status = $obj->status;
556 $object->priority = $obj->priority;
557 $object->processing = $obj->processing;
558 $object->lastresult = (string) $obj->lastresult;
559 $object->datestart = $db->jdate($obj->datestart);
560 $object->dateend = $db->jdate($obj->dateend);
561 $object->module_name = $obj->module_name;
562 $object->params = $obj->params;
563 $object->datelastrun = $db->jdate($obj->datelastrun);
564 $object->datenextrun = $db->jdate($obj->datenextrun);
565
566 $datelastrun = $db->jdate($obj->datelastrun);
567 $datelastresult = $db->jdate($obj->datelastresult);
568
569 print '<tr class="oddeven">';
570
571 // Action column
572 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
573 print '<td class="nowraponall center">';
574 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
575 $selected = 0;
576 if (in_array($obj->rowid, $arrayofselected)) {
577 $selected = 1;
578 }
579 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect valignmiddle" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
580 }
581 print '</td>';
582 }
583
584 // Ref
585 print '<td class="nowraponall">';
586 print $object->getNomUrl(1);
587 print '</td>';
588
589 // Label
590 print '<td class="minwidth150">';
591 if (!empty($object->label)) {
592 $object->ref = $langs->trans($object->label);
593 print '<div class="small twolinesmax lineheightsmall minwidth150 maxwidth250 classfortooltip" title="'.dol_escape_htmltag($langs->trans($object->label), 0, 0).'">';
594 print $object->getNomUrl(0, '', 1);
595 print '</div>';
596 $object->ref = $obj->rowid;
597 } else {
598 //print $langs->trans('CronNone');
599 }
600 print '</td>';
601
602 // Priority
603 /*print '<td class="right">';
604 print dol_escape_htmltag($object->priority);
605 print '</td>';*/
606
607 // Module
608 print '<td>';
609 print dol_escape_htmltag($object->module_name);
610 print '</td>';
611
612 // Class/Method
613 print '<td class="nowraponall">';
614 if ($obj->jobtype == 'method') {
615 $text = img_picto('', 'code');
616 $texttoshow = '<b>'.$langs->trans("CronType_method").'</b><br><br>';
617 $texttoshow .= $langs->trans('CronModule').': '.$obj->module_name.'<br>';
618 $texttoshow .= $langs->trans('CronClass').': '.$obj->classesname.'<br>';
619 $texttoshow .= $langs->trans('CronObject').': '.$obj->objectname.'<br>';
620 $texttoshow .= $langs->trans('CronMethod').': '.$obj->methodename;
621 $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$obj->params;
622 $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($obj->note);
623 } elseif ($obj->jobtype == 'command') {
624 $text = img_picto('', 'terminal');
625 $texttoshow = '<b>'.$langs->trans('CronType_command').'</b><br><br>';
626 $texttoshow .= $langs->trans('CronCommand').': '.dol_trunc($obj->command);
627 $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$obj->params;
628 $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($obj->note);
629 } else {
630 $texttoshow = '';
631 $texttoshow = '';
632 }
633 print '<span class="classfortooltip" title="'.dol_escape_htmltag($texttoshow, 1, 1).'">'.$text.'</a>';
634 print '</td>';
635
636 // Frequency
637 $s = '';
638 if ($obj->unitfrequency == "60") {
639 $s = ($obj->frequency)." ".$langs->trans('MinuteShort');
640 } elseif ($obj->unitfrequency == "3600") {
641 $s = ($obj->frequency)." ".$langs->trans('HourShort');
642 } elseif ($obj->unitfrequency == "86400") {
643 $s = ($obj->frequency)." ".($obj->frequency > 1 ? $langs->trans('DurationDays') : $langs->trans('DurationDay'));
644 } elseif ($obj->unitfrequency == "604800") {
645 $s = ($obj->frequency)." ".($obj->frequency > 1 ? $langs->trans('DurationWeeks') : $langs->trans('DurationWeek'));
646 } elseif ($obj->unitfrequency == "2678400") {
647 $s = ($obj->frequency)." ".($obj->frequency > 1 ? $langs->trans('DurationMonths') : $langs->trans('DurationMonth'));
648 }
649 print '<td class="tdoverflowmax125 center" title="'.dol_escape_htmltag($s).'">';
650 print dol_escape_htmltag($s);
651 print '</td>';
652
653 /*
654 print '<td class="center">';
655 if (!empty($obj->datestart)) {
656 print dol_print_date($db->jdate($obj->datestart), 'dayhour', 'tzserver');
657 }
658 print '</td>';
659
660 print '<td class="center">';
661 if (!empty($obj->dateend)) {
662 print dol_print_date($db->jdate($obj->dateend), 'dayhour', 'tzserver');
663 }
664 print '</td>';
665 */
666
667 print '<td class="right">';
668 if (!empty($obj->nbrun)) {
669 print dol_escape_htmltag($obj->nbrun);
670 } else {
671 print '0';
672 }
673 if (!empty($obj->maxrun)) {
674 print ' <span class="'.$langs->trans("Max").'">/ '.dol_escape_htmltag($obj->maxrun).'</span>';
675 }
676 print '</td>';
677
678 $datefromto = (empty($datelastrun) ? '' : dol_print_date($datelastrun, 'dayhoursec', 'tzserver')).' - '.(empty($datelastresult) ? '' : dol_print_date($datelastresult, 'dayhoursec', 'tzserver'));
679
680 // Date start last run
681 print '<td class="center lineheightsmall" title="'.dol_escape_htmltag($datefromto).'">';
682 if (!empty($datelastrun)) {
683 print dol_print_date($datelastrun, 'dayhoursec', 'tzserver');
684 }
685 print '</td>';
686
687 // Duration
688 print '<td class="center nowraponall" title="'.dol_escape_htmltag($datefromto).'">';
689 if (!empty($datelastresult) && ($datelastresult >= $datelastrun)) {
690 $nbseconds = max($datelastresult - $datelastrun, 1);
691 print $nbseconds.' '.$langs->trans("SecondShort");
692 }
693 print '</td>';
694
695 // Return code of last run
696 print '<td class="center tdlastresultcode" title="'.dol_escape_htmltag($obj->lastresult).'">';
697 if ($obj->lastresult != '') {
698 if (empty($obj->lastresult)) {
699 print $obj->lastresult; // Print '0'
700 } else {
701 print '<span class="error">'.dol_escape_htmltag(dol_trunc($obj->lastresult)).'</div>';
702 }
703 }
704 print '</td>';
705
706 // Output of last run
707 print '<td class="small minwidth150">';
708 if (!empty($obj->lastoutput)) {
709 print '<div class="twolinesmax lineheightsmall classfortooltip" title="'.dol_escape_htmltag($obj->lastoutput, 1, 1).'">';
710 print dol_trunc(dolGetFirstLineOfText($obj->lastoutput, 2), 100);
711 print '</div>';
712 }
713 print '</td>';
714
715 // Next run date
716 print '<td class="center lineheightsmall">';
717 if (!empty($obj->datenextrun)) {
718 $datenextrun = $db->jdate($obj->datenextrun);
719 if (empty($obj->status)) {
720 print '<span class="opacitymedium strikefordisabled">';
721 }
722 print dol_print_date($datenextrun, 'dayhoursec');
723 if ($obj->status == Cronjob::STATUS_ENABLED) {
724 if ($obj->maxrun && $obj->nbrun >= $obj->maxrun) {
725 print img_warning($langs->trans("MaxRunReached"));
726 } elseif ($datenextrun && $datenextrun < $now) {
727 print img_warning($langs->trans("Late"));
728 }
729 }
730 if (empty($obj->status)) {
731 print '</span>';
732 }
733 }
734 print '</td>';
735
736 // Status
737 print '<td class="center">';
738 print $object->getLibStatut(5);
739 print '</td>';
740
741 print '<td class="nowraponall right">';
742
743 $backtopage = urlencode($_SERVER["PHP_SELF"].'?'.$param.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : ''));
744 if ($user->hasRight('cron', 'create')) {
745 print '<a class="editfielda" href="'.DOL_URL_ROOT."/cron/card.php?id=".$obj->rowid.'&action=edit&token='.newToken().($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '').$param;
746 print "&backtopage=".$backtopage."\" title=\"".dol_escape_htmltag($langs->trans('Edit'))."\">".img_picto($langs->trans('Edit'), 'edit')."</a> &nbsp;";
747 }
748 if ($user->hasRight('cron', 'delete')) {
749 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"]."?id=".$obj->rowid.'&action=delete&token='.newToken().($page ? '&page='.$page : '').($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '').$param;
750 print '" title="'.dol_escape_htmltag($langs->trans('CronDelete')).'">'.img_picto($langs->trans('CronDelete'), 'delete', '', 0, 0, 0, '', 'marginleftonly').'</a> &nbsp; ';
751 } else {
752 print '<a href="#" title="'.dol_escape_htmltag($langs->trans('NotEnoughPermissions')).'">'.img_picto($langs->trans('NotEnoughPermissions'), 'delete', '', 0, 0, 0, '', 'marginleftonly').'</a> &nbsp; ';
753 }
754 if ($user->hasRight('cron', 'execute')) {
755 if (!empty($obj->status)) {
756 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=execute&token='.newToken();
757 print(!getDolGlobalString('CRON_KEY') ? '' : '&securitykey=' . getDolGlobalString('CRON_KEY'));
758 print($sortfield ? '&sortfield='.$sortfield : '');
759 print($sortorder ? '&sortorder='.$sortorder : '');
760 print $param."\" title=\"".dol_escape_htmltag($langs->trans('CronExecute'))."\">".img_picto($langs->trans('CronExecute'), "play", '', 0, 0, 0, '', 'marginleftonly').'</a>';
761 } else {
762 print '<a href="#" class="cursordefault" title="'.dol_escape_htmltag($langs->trans('JobDisabled')).'">'.img_picto($langs->trans('JobDisabled'), "playdisabled", '', 0, 0, 0, '', 'marginleftonly').'</a>';
763 }
764 } else {
765 print '<a href="#" class="cursornotallowed" title="'.dol_escape_htmltag($langs->trans('NotEnoughPermissions')).'">'.img_picto($langs->trans('NotEnoughPermissions'), "playdisabled", '', 0, 0, 0, '', 'marginleftonly').'</a>';
766 }
767
768 print '</td>';
769
770 // Action column
771 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
772 print '<td class="nowraponall center">';
773 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
774 $selected = 0;
775 if (in_array($obj->rowid, $arrayofselected)) {
776 $selected = 1;
777 }
778 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect valignmiddle" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
779 }
780 print '</td>';
781 }
782
783 print '</tr>';
784
785 $i++;
786 }
787} else {
788 print '<tr><td colspan="16"><span class="opacitymedium">'.$langs->trans('CronNoJobs').'</span></td></tr>';
789}
790
791print '</table>';
792print '</div>';
793
794print '</from>';
795
796if ($mode == 'modulesetup') {
797 print dol_get_fiche_end();
798}
799
800
801llxFooter();
802
803$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Cron Job class.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
cronadmin_prepare_head()
Return array of tabs to used on pages to setup cron module.
Definition cron.lib.php:32
verifCond($strToEvaluate, $onlysimplestring='1')
Verify if condition in string is ok or not.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.