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