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