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