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