dolibarr 23.0.3
list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
3 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
4 * Copyright (C) 2013-2021 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2019-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_lastresult = '';
182 $search_all = '';
183 $toselect = array();
184 $search_array_options = array();
185 }
186 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
187 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
188 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
189 }
190
191 $filter = array();
192 if (!empty($search_label)) {
193 $filter['t.label'] = $search_label;
194 }
195
196 // Delete jobs
197 if ($action == 'confirm_delete' && $confirm == "yes" && $permissiontodelete) {
198 //Delete cron task
199 $object = new Cronjob($db);
200 $object->id = $id;
201 $result = $object->delete($user);
202
203 if ($result < 0) {
204 setEventMessages($object->error, $object->errors, 'errors');
205 }
206 }
207
208 // Execute jobs
209 if ($action == 'confirm_execute' && $confirm == "yes" && $permissiontoexecute) {
210 if (getDolGlobalString('CRON_KEY') && getDolGlobalString('CRON_KEY') != $securitykey) {
211 setEventMessages('Security key '.$securitykey.' is wrong', null, 'errors');
212 $action = '';
213 } else {
214 $object = new Cronjob($db);
215 $job = $object->fetch($id);
216
217 $now = dol_now(); // Date we start
218
219 $resrunjob = $object->run_jobs($user->login); // Return -1 if KO, 1 if OK
220 if ($resrunjob < 0) {
221 setEventMessages($object->error, $object->errors, 'errors');
222 }
223
224 // Plan next run
225 $res = $object->reprogram_jobs($user->login, $now);
226 if ($res > 0) {
227 if ($resrunjob >= 0) { // We show the result of reprogram only if no error message already reported
228 if ($object->lastresult >= 0) {
229 setEventMessages($langs->trans("JobFinished"), null, 'mesgs');
230 } else {
231 setEventMessages($langs->trans("JobFinished"), null, 'errors');
232 }
233 }
234 $action = '';
235 } else {
236 setEventMessages($object->error, $object->errors, 'errors');
237 $action = '';
238 }
239
240 $param = '&search_status='.urlencode($search_status);
241 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
242 $param .= '&contextpage='.urlencode($contextpage);
243 }
244 if ($limit > 0 && $limit != $conf->liste_limit) {
245 $param .= '&limit='.((int) $limit);
246 }
247 if ($search_label) {
248 $param .= '&search_label='.urlencode($search_label);
249 }
250 if ($optioncss != '') {
251 $param .= '&optioncss='.urlencode($optioncss);
252 }
253 // Add $param from extra fields
254 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
255
256 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
257 exit;
258 }
259 }
260
261 // Mass actions
262 $objectclass = 'CronJob';
263 $objectlabel = 'CronJob';
264 $uploaddir = $conf->cron->dir_output;
265 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
266 if ($massaction && $permissiontoadd) {
267 $tmpcron = new Cronjob($db);
268 foreach ($toselect as $id) {
269 $result = $tmpcron->fetch($id);
270 if ($result) {
271 $result = 0;
272 if ($massaction == 'disable') {
273 $result = $tmpcron->setStatut(Cronjob::STATUS_DISABLED);
274 } elseif ($massaction == 'enable') {
275 $result = $tmpcron->setStatut(Cronjob::STATUS_ENABLED);
276 }
277 //else dol_print_error($db, 'Bad value for massaction');
278 if ($result < 0) {
279 setEventMessages($tmpcron->error, $tmpcron->errors, 'errors');
280 }
281 } else {
282 $error++;
283 }
284 }
285 }
286}
287
288
289/*
290 * View
291 */
292
293$now = dol_now();
294
295$form = new Form($db);
296$cronjob = new Cronjob($db);
297
298$title = $langs->trans("CronList");
299
300llxHeader('', $title, '', '', 0, 0, '', '', '', 'bodyforlist');
301
302$TTestNotAllowed = array();
303$sqlTest = 'SELECT rowid, test FROM '.MAIN_DB_PREFIX.'cronjob';
304$resultTest = $db->query($sqlTest);
305if ($resultTest) {
306 while ($objTest = $db->fetch_object($resultTest)) {
307 $veriftest = verifCond($objTest->test);
308 if (!$veriftest) {
309 $TTestNotAllowed[$objTest->rowid] = $objTest->rowid;
310 }
311 }
312}
313
314// Build and execute select
315// --------------------------------------------------------------------
316$sql = "SELECT";
317$sql .= " t.rowid,";
318$sql .= " t.tms,";
319$sql .= " t.datec,";
320$sql .= " t.jobtype,";
321$sql .= " t.label,";
322$sql .= " t.command,";
323$sql .= " t.classesname,";
324$sql .= " t.objectname,";
325$sql .= " t.methodename,";
326$sql .= " t.params,";
327$sql .= " t.md5params,";
328$sql .= " t.module_name,";
329$sql .= " t.priority,";
330$sql .= " t.processing,";
331$sql .= " t.datelastrun,";
332$sql .= " t.datenextrun,";
333$sql .= " t.dateend,";
334$sql .= " t.datestart,";
335$sql .= " t.lastresult,";
336$sql .= " t.datelastresult,";
337$sql .= " t.lastoutput,";
338$sql .= " t.unitfrequency,";
339$sql .= " t.frequency,";
340$sql .= " t.status,";
341$sql .= " t.fk_user_author,";
342$sql .= " t.fk_user_mod,";
343$sql .= " t.note,";
344$sql .= " t.maxrun,";
345$sql .= " t.nbrun,";
346$sql .= " t.libname,";
347$sql .= " t.test";
348$sql .= " FROM ".MAIN_DB_PREFIX."cronjob as t";
349$sql .= " WHERE entity IN (0,".$conf->entity.")";
350if (!empty($TTestNotAllowed)) {
351 $sql .= ' AND t.rowid NOT IN ('.$db->sanitize(implode(',', $TTestNotAllowed)).')';
352}
353if ($search_status >= 0 && $search_status < 2 && $search_status != '') {
354 $sql .= " AND t.status = ".(empty($search_status) ? '0' : '1');
355}
356if ($search_lastresult != '') {
357 $sql .= natural_search("t.lastresult", $search_lastresult, 1);
358}
359if (GETPOSTISSET('search_processing')) {
360 $sql .= " AND t.processing = ".((int) $search_processing);
361}
362// Manage filter
363if (is_array($filter) && count($filter) > 0) {
364 foreach ($filter as $key => $value) {
365 $sql .= " AND ".$db->sanitize($key)." LIKE '%".$db->escape($value)."%'";
366 }
367}
368if (!empty($search_module_name)) {
369 $sql .= natural_search("t.module_name", $search_module_name);
370}
371// Add where from extra fields
372include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
373// Add where from hooks
374$parameters = array();
375$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
376$sql .= $hookmanager->resPrint;
377
378
379// Count total nb of records
380$nbtotalofrecords = '';
381if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
382 $sqlforcount = $sql;
383
384 $resql = $db->query($sqlforcount);
385 if ($resql) {
386 $nbtotalofrecords = $db->num_rows($resql);
387 } else {
388 dol_print_error($db);
389 }
390
391 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
392 $page = 0;
393 $offset = 0;
394 }
395 $db->free($resql);
396}
397
398// Complete request and execute it with limit
399$sql .= $db->order($sortfield, $sortorder);
400if ($limit) {
401 $sql .= $db->plimit($limit + 1, $offset);
402}
403
404$resql = $db->query($sql);
405if (!$resql) {
406 dol_print_error($db);
407 exit;
408}
409
410$num = $db->num_rows($resql);
411
412$arrayofselected = is_array($toselect) ? $toselect : array();
413
414$param = '';
415if (!empty($mode)) {
416 $param .= '&mode='.urlencode($mode);
417}
418if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
419 $param .= '&contextpage='.urlencode($contextpage);
420}
421if ($limit > 0 && $limit != $conf->liste_limit) {
422 $param .= '&limit='.((int) $limit);
423}
424if ($optioncss != '') {
425 $param .= '&optioncss='.urlencode($optioncss);
426}
427if ($search_status) {
428 $param .= '&search_status='.urlencode($search_status);
429}
430if ($search_label) {
431 $param .= '&search_label='.urlencode($search_label);
432}
433if ($search_module_name) {
434 $param .= '&search_module_name='.urlencode($search_module_name);
435}
436if ($search_lastresult) {
437 $param .= '&search_lastresult='.urlencode($search_lastresult);
438}
439// Add $param from extra fields
440include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
441
442$stringcurrentdate = $langs->trans("CurrentHour").': '.dol_print_date(dol_now(), 'dayhour');
443
444if ($action == 'execute') {
445 print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id.'&securitykey='.$securitykey.$param, $langs->trans("CronExecute"), $langs->trans("CronConfirmExecute"), "confirm_execute", '', '', 1);
446}
447
448if ($action == 'delete' && empty($toselect)) { // Used when we make a delete on 1 line (not used for mass delete)
449 print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id.$param, $langs->trans("CronDelete"), $langs->trans("CronConfirmDelete"), "confirm_delete", '', '', 1);
450}
451
452// List of mass actions available
453$arrayofmassactions = array(
454//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
455//'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
456 'enable' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("CronStatusActiveBtn"),
457 'disable' => img_picto('', 'uncheck', 'class="pictofixedwidth"').$langs->trans("CronStatusInactiveBtn"),
458);
459if ($user->hasRight('cron', 'delete')) {
460 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
461}
462if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
463 $arrayofmassactions = array();
464}
465$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
466
467$head = [];
468if ($mode == 'modulesetup') {
469 $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>';
470 print load_fiche_titre($langs->trans("CronSetup"), $linkback, 'title_setup');
471
472 // Configuration header
473 $head = cronadmin_prepare_head();
474}
475
476print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" name="search_form">'."\n";
477if ($optioncss != '') {
478 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
479}
480print '<input type="hidden" name="token" value="'.newToken().'">';
481print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
482print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
483print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
484print '<input type="hidden" name="page" value="'.$page.'">';
485print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
486print '<input type="hidden" name="page_y" value="">';
487print '<input type="hidden" name="mode" value="'.$mode.'">';
488
489// Line with explanation and button new
490$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'));
491
492
493if ($mode == 'modulesetup') {
494 print dol_get_fiche_head($head, 'jobs', $langs->trans("Module2300Name"), -1, 'cron');
495
496 //print '<span class="opacitymedium">'.$langs->trans('CronInfo').'</span><br>';
497}
498
499
500print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, ($mode == 'modulesetup' ? '' : 'title_setup'), 0, $newcardbutton, '', $limit);
501
502// Add code for pre mass action (confirmation or email presend form)
503$topicmail = "SendCronRef";
504$modelmail = "cron";
505$objecttmp = new Cronjob($db);
506$trackid = 'cron'.$object->id;
507include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
508
509$text = $langs->trans("HoursOnThisPageAreOnServerTZ").' '.$stringcurrentdate.'<br>';
510if (getDolGlobalString('CRON_WARNING_DELAY_HOURS')) {
511 $text .= $langs->trans("WarningCronDelayed", getDolGlobalString('CRON_WARNING_DELAY_HOURS'));
512}
513print info_admin($text);
514//print '<br>';
515
516$moreforfilter = '';
517
518$parameters = array();
519$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
520if (empty($reshook)) {
521 $moreforfilter .= $hookmanager->resPrint;
522} else {
523 $moreforfilter = $hookmanager->resPrint;
524}
525$parameters = array(
526 'arrayfields' => &$arrayfields,
527);
528
529if (!empty($moreforfilter)) {
530 print '<div class="liste_titre liste_titre_bydiv centpercent">';
531 print $moreforfilter;
532 print '</div>';
533}
534
535$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
536$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields with user setup
537$selectedfields = (($mode != 'kanban' && $mode != 'kanbangroupby') ? $htmlofselectarray : '');
538$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
539
540print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
541print '<table class="tagtable nobottomiftotal noborder liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
542
543// Fields title search
544// --------------------------------------------------------------------
545print '<tr class="liste_titre_filter">';
546// Action column
547if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
548 print '<td class="liste_titre center maxwidthsearch">';
549 $searchpicto = $form->showFilterButtons('left');
550 print $searchpicto;
551 print '</td>';
552}
553print '<td class="liste_titre">&nbsp;</td>';
554print '<td class="liste_titre">';
555print '<input type="text" class="flat width75" name="search_label" value="'.$search_label.'">';
556print '</td>';
557print '<td class="liste_titre">&nbsp;</td>';
558print '<td class="liste_titre"><input type="text" class="width50" name="search_module_name" value="'.$search_module_name.'"></td>';
559print '<td class="liste_titre">&nbsp;</td>';
560print '<td class="liste_titre">&nbsp;</td>';
561//print '<td class="liste_titre">&nbsp;</td>';
562//print '<td class="liste_titre">&nbsp;</td>';
563print '<td class="liste_titre">&nbsp;</td>';
564print '<td class="liste_titre">&nbsp;</td>';
565print '<td class="liste_titre">&nbsp;</td>';
566print '<td class="liste_titre center"><input type="text" class="width50" name="search_lastresult" value="'.$search_lastresult.'"></td>';
567print '<td class="liste_titre">&nbsp;</td>';
568print '<td class="liste_titre">&nbsp;</td>';
569print '<td class="liste_titre center">';
570print $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');
571print '</td>';
572print '<td class="liste_titre">&nbsp;</td>';
573// Action column
574if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
575 print '<td class="liste_titre right">';
576 $searchpicto = $form->showFilterButtons();
577 print $searchpicto;
578 print '</td>';
579}
580print '</tr>'."\n";
581
582$totalarray = array();
583$totalarray['nbfield'] = 0;
584
585// Fields title label
586// --------------------------------------------------------------------
587print '<tr class="liste_titre">';
588// Action column
589if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
590 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'center maxwidthsearch ');
591}
592print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "t.rowid", "", $param, '', $sortfield, $sortorder);
593print_liste_field_titre("CronLabel", $_SERVER["PHP_SELF"], "t.label", "", $param, '', $sortfield, $sortorder);
594print_liste_field_titre("Priority", $_SERVER["PHP_SELF"], "t.priority", "", $param, '', $sortfield, $sortorder);
595print_liste_field_titre("CronModule", $_SERVER["PHP_SELF"], "t.module_name", "", $param, '', $sortfield, $sortorder);
596print_liste_field_titre("", '', '', "", $param, '', $sortfield, $sortorder, 'tdoverflowmax50 ');
597print_liste_field_titre("CronFrequency", '', "", "", $param, '', $sortfield, $sortorder);
598//print_liste_field_titre("CronDtStart", $_SERVER["PHP_SELF"], "t.datestart", "", $param, 'align="center"', $sortfield, $sortorder);
599//print_liste_field_titre("CronDtEnd", $_SERVER["PHP_SELF"], "t.dateend", "", $param, 'align="center"', $sortfield, $sortorder);
600print_liste_field_titre("CronNbRun", $_SERVER["PHP_SELF"], "t.nbrun", "", $param, '', $sortfield, $sortorder, 'right tdoverflowmax50 maxwidth50imp ');
601print_liste_field_titre("CronDtLastLaunch", $_SERVER["PHP_SELF"], "t.datelastrun", "", $param, '', $sortfield, $sortorder, 'center tdoverflowmax100 ');
602print_liste_field_titre("Duration", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'center ');
603print_liste_field_titre("CronLastResult", $_SERVER["PHP_SELF"], "t.lastresult", "", $param, '', $sortfield, $sortorder, 'center ');
604print_liste_field_titre("CronLastOutput", $_SERVER["PHP_SELF"], "t.lastoutput", "", $param, '', $sortfield, $sortorder);
605print_liste_field_titre("CronDtNextLaunch", $_SERVER["PHP_SELF"], "t.datenextrun", "", $param, '', $sortfield, $sortorder, 'center ');
606print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "t.status,t.priority", "", $param, '', $sortfield, $sortorder, 'center ');
607print_liste_field_titre("", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'center ');
608// Action column
609if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
610 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'center maxwidthsearch ');
611}
612print '</tr>'."\n";
613
614// Loop on record
615// --------------------------------------------------------------------
616$i = 0;
617$savnbfield = $totalarray['nbfield'];
618$totalarray = array();
619$totalarray['nbfield'] = 0;
620$imaxinloop = ($limit ? min($num, $limit) : $num);
621
622if ($num > 0) {
623 // Loop on each job
624
625 while ($i < $imaxinloop) {
626 $obj = $db->fetch_object($resql);
627 if (empty($obj)) {
628 break;
629 }
630
631 $reg = array();
632 if (preg_match('/:(.*)$/', $obj->label, $reg)) {
633 $langs->load($reg[1]);
634 }
635
636 $object->id = $obj->rowid;
637 $object->ref = $obj->rowid;
638 $object->label = preg_replace('/:.*$/', '', $obj->label);
639 $object->status = $obj->status;
640 $object->priority = $obj->priority;
641 $object->processing = $obj->processing;
642 $object->lastresult = (string) $obj->lastresult;
643 $object->datestart = $db->jdate($obj->datestart);
644 $object->dateend = $db->jdate($obj->dateend);
645 $object->module_name = $obj->module_name;
646 $object->params = $obj->params;
647 $object->datelastrun = $db->jdate($obj->datelastrun);
648 $object->datenextrun = $db->jdate($obj->datenextrun);
649
650 $datelastrun = $db->jdate($obj->datelastrun);
651 $datelastresult = $db->jdate($obj->datelastresult);
652 $datefromto = (empty($datelastrun) ? '' : dol_print_date($datelastrun, 'dayhoursec', 'tzserver')).' - '.(empty($datelastresult) ? '' : dol_print_date($datelastresult, 'dayhoursec', 'tzserver'));
653
654
655 print '<tr class="oddeven row-with-select">';
656
657 // Action column
658 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
659 print '<td class="nowraponall center">';
660 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
661 $selected = 0;
662 if (in_array($obj->rowid, $arrayofselected)) {
663 $selected = 1;
664 }
665 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect valignmiddle" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
666 }
667 print '</td>';
668 if (!$i) {
669 $totalarray['nbfield']++;
670 }
671 }
672
673 // Ref
674 print '<td class="nowraponall">';
675 print $object->getNomUrl(1);
676 print '</td>';
677 if (!$i) {
678 $totalarray['nbfield']++;
679 }
680
681 // Label
682 print '<td class="minwidth150">';
683 if (!empty($object->label)) {
684 $object->ref = $langs->trans($object->label);
685 print '<div class="small twolinesmax lineheightsmall minwidth150 maxwidth250 classfortooltip" title="'.dol_escape_htmltag($langs->trans($object->label), 0, 0).'">';
686 print $object->getNomUrl(0, '', 1);
687 print '</div>';
688 $object->ref = $obj->rowid;
689 } else {
690 //print $langs->trans('CronNone');
691 }
692 print '</td>';
693 if (!$i) {
694 $totalarray['nbfield']++;
695 }
696
697 // Priority
698 print '<td class="right">';
699 print dol_escape_htmltag($object->priority);
700 print '</td>';
701
702 // Module
703 print '<td>';
704 print dol_escape_htmltag($object->module_name);
705 print '</td>';
706 if (!$i) {
707 $totalarray['nbfield']++;
708 }
709
710 // Class/Method
711 print '<td class="nowraponall">';
712 if ($obj->jobtype == 'method') {
713 $text = img_picto('', 'code');
714 $texttoshow = '<b>'.$langs->trans("CronType_method").'</b><br><br>';
715 $texttoshow .= $langs->trans('CronModule').': '.$obj->module_name.'<br>';
716 $texttoshow .= $langs->trans('CronClass').': '.$obj->classesname.'<br>';
717 $texttoshow .= $langs->trans('CronObject').': '.$obj->objectname.'<br>';
718 $texttoshow .= $langs->trans('CronMethod').': '.$obj->methodename;
719 $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$obj->params;
720 $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($obj->note);
721 } elseif ($obj->jobtype == 'command') {
722 $text = img_picto('', 'terminal');
723 $texttoshow = '<b>'.$langs->trans('CronType_command').'</b><br><br>';
724 $texttoshow .= $langs->trans('CronCommand').': '.dol_trunc($obj->command);
725 $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$obj->params;
726 $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($obj->note);
727 } else {
728 $texttoshow = '';
729 $texttoshow = '';
730 }
731 print '<span class="classfortooltip" title="'.dol_escape_htmltag($texttoshow, 1, 1).'">'.$text.'</a>';
732 print '</td>';
733 if (!$i) {
734 $totalarray['nbfield']++;
735 }
736
737 // Frequency
738 $s = '';
739 if ($obj->unitfrequency == "60") {
740 $s = ($obj->frequency)." ".$langs->trans('MinuteShort');
741 } elseif ($obj->unitfrequency == "3600") {
742 $s = ($obj->frequency)." ".$langs->trans('HourShort');
743 } elseif ($obj->unitfrequency == "86400") {
744 $s = ($obj->frequency)." ".($obj->frequency > 1 ? $langs->trans('DurationDays') : $langs->trans('DurationDay'));
745 } elseif ($obj->unitfrequency == "604800") {
746 $s = ($obj->frequency)." ".($obj->frequency > 1 ? $langs->trans('DurationWeeks') : $langs->trans('DurationWeek'));
747 } elseif ($obj->unitfrequency == "2678400") {
748 $s = ($obj->frequency)." ".($obj->frequency > 1 ? $langs->trans('DurationMonths') : $langs->trans('DurationMonth'));
749 }
750 print '<td class="tdoverflowmax125 center" title="'.dol_escape_htmltag($s).'">';
751 print dol_escape_htmltag($s);
752 print '</td>';
753 if (!$i) {
754 $totalarray['nbfield']++;
755 }
756
757 /*
758 print '<td class="center">';
759 if (!empty($obj->datestart)) {
760 print dol_print_date($db->jdate($obj->datestart), 'dayhour', 'tzserver');
761 }
762 print '</td>';
763 if (!$i) {
764 $totalarray['nbfield']++;
765 }
766
767 print '<td class="center">';
768 if (!empty($obj->dateend)) {
769 print dol_print_date($db->jdate($obj->dateend), 'dayhour', 'tzserver');
770 }
771 print '</td>';
772 if (!$i) {
773 $totalarray['nbfield']++;
774 }
775 */
776
777 print '<td class="right">';
778 if (!empty($obj->nbrun)) {
779 print dol_escape_htmltag($obj->nbrun);
780 } else {
781 print '0';
782 }
783 if (!empty($obj->maxrun)) {
784 print ' <span class="'.$langs->trans("Max").'">/ '.dol_escape_htmltag($obj->maxrun).'</span>';
785 }
786 print '</td>';
787 if (!$i) {
788 $totalarray['nbfield']++;
789 }
790
791 // Date start last run
792 print '<td class="center lineheightsmall" title="'.dol_escape_htmltag($datefromto).'">';
793 if (!empty($datelastrun)) {
794 print dol_print_date($datelastrun, 'dayhoursec', 'tzserver');
795 }
796 print '</td>';
797 if (!$i) {
798 $totalarray['nbfield']++;
799 }
800
801 // Duration
802 print '<td class="center nowraponall" title="'.dol_escape_htmltag($datefromto).'">';
803 if (!empty($datelastresult) && ($datelastresult >= $datelastrun)) {
804 $nbseconds = max($datelastresult - $datelastrun, 1);
805 print $nbseconds.' '.$langs->trans("SecondShort");
806 }
807 print '</td>';
808 if (!$i) {
809 $totalarray['nbfield']++;
810 }
811
812 // Return code of last run
813 print '<td class="center tdlastresultcode" title="'.dol_escape_htmltag($obj->lastresult).'">';
814 if ($obj->lastresult != '') {
815 if (empty($obj->lastresult) || $obj->status == Cronjob::STATUS_DISABLED) {
816 print $obj->lastresult; // Print '0'
817 } else {
818 print '<span class="error">'.dol_escape_htmltag(dol_trunc($obj->lastresult)).'</div>';
819 }
820 }
821 print '</td>';
822 if (!$i) {
823 $totalarray['nbfield']++;
824 }
825
826 // Output of last run
827 print '<td class="small minwidth150">';
828 if (!empty($obj->lastoutput)) {
829 print '<div class="twolinesmax lineheightsmall classfortooltip" title="'.dolPrintHTMLForAttribute($obj->lastoutput).'">';
830 print dol_trunc(dolGetFirstLineOfText($obj->lastoutput, 2), 100);
831 print '</div>';
832 }
833 print '</td>';
834 if (!$i) {
835 $totalarray['nbfield']++;
836 }
837
838 // Next run date
839 print '<td class="center lineheightsmall">';
840 if (!empty($obj->datenextrun)) {
841 $datenextrun = $db->jdate($obj->datenextrun);
842 if (empty($obj->status)) {
843 print '<span class="opacitymedium strikefordisabled">';
844 }
845 print dol_print_date($datenextrun, 'dayhoursec');
846 if ($obj->status == Cronjob::STATUS_ENABLED) {
847 if ($obj->maxrun && $obj->nbrun >= $obj->maxrun) {
848 print img_warning($langs->trans("MaxRunReached"));
849 } elseif ($datenextrun && $datenextrun < $now) {
850 print img_warning($langs->trans("Late"));
851 }
852 }
853 if (empty($obj->status)) {
854 print '</span>';
855 }
856 }
857 print '</td>';
858 if (!$i) {
859 $totalarray['nbfield']++;
860 }
861
862 // Status
863 print '<td class="center">';
864 print $object->getLibStatut(5);
865 print '</td>';
866 if (!$i) {
867 $totalarray['nbfield']++;
868 }
869
870 // Action
871 print '<td class="nowraponall right">';
872 $backtopage = urlencode($_SERVER["PHP_SELF"].'?'.$param.'&sortfield='.$sortfield.'&sortorder='.$sortorder);
873 if ($user->hasRight('cron', 'create')) {
874 print '<a class="editfielda" href="'.DOL_URL_ROOT."/cron/card.php?id=".$obj->rowid.'&action=edit&token='.newToken().'&sortfield='.$sortfield.'&sortorder='.$sortorder.$param;
875 print "&backtopage=".$backtopage."\" title=\"".dol_escape_htmltag($langs->trans('Edit'))."\">".img_picto($langs->trans('Edit'), 'edit')."</a> &nbsp;";
876 }
877 if ($user->hasRight('cron', 'delete')) {
878 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"]."?id=".$obj->rowid.'&action=delete&token='.newToken().($page ? '&page='.$page : '').'&sortfield='.$sortfield.'&sortorder='.$sortorder.$param;
879 print '" title="'.dol_escape_htmltag($langs->trans('CronDelete')).'">'.img_picto($langs->trans('CronDelete'), 'delete', '', 0, 0, 0, '', 'marginleftonly').'</a> &nbsp; ';
880 } else {
881 print '<a href="#" title="'.dol_escape_htmltag($langs->trans('NotEnoughPermissions')).'">'.img_picto($langs->trans('NotEnoughPermissions'), 'delete', '', 0, 0, 0, '', 'marginleftonly').'</a> &nbsp; ';
882 }
883 if ($user->hasRight('cron', 'execute')) {
884 if (!empty($obj->status)) {
885 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=execute&token='.newToken();
886 print (!getDolGlobalString('CRON_KEY') ? '' : '&securitykey=' . getDolGlobalString('CRON_KEY'));
887 print '&sortfield='.$sortfield;
888 print '&sortorder='.$sortorder;
889 print $param."\" title=\"".dol_escape_htmltag($langs->trans('CronExecute'))."\">".img_picto($langs->trans('CronExecute'), "play", '', 0, 0, 0, '', 'marginleftonly').'</a>';
890 } else {
891 print '<a href="#" class="cursordefault" title="'.dol_escape_htmltag($langs->trans('JobDisabled')).'">'.img_picto($langs->trans('JobDisabled'), "playdisabled", '', 0, 0, 0, '', 'marginleftonly').'</a>';
892 }
893 } else {
894 print '<a href="#" class="cursornotallowed" title="'.dol_escape_htmltag($langs->trans('NotEnoughPermissions')).'">'.img_picto($langs->trans('NotEnoughPermissions'), "playdisabled", '', 0, 0, 0, '', 'marginleftonly').'</a>';
895 }
896 print '</td>';
897 if (!$i) {
898 $totalarray['nbfield']++;
899 }
900
901 // Action column
902 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
903 print '<td class="nowraponall center">';
904 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
905 $selected = 0;
906 if (in_array($obj->rowid, $arrayofselected)) {
907 $selected = 1;
908 }
909 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect valignmiddle" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
910 }
911 print '</td>';
912 if (!$i) {
913 $totalarray['nbfield']++;
914 }
915 }
916
917 print '</tr>'."\n";
918
919 $i++;
920 }
921} else {
922 print '<tr><td colspan="16"><span class="opacitymedium">'.$langs->trans('CronNoJobs').'</span></td></tr>';
923}
924
925$db->free($resql);
926
927$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
928$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
929print $hookmanager->resPrint;
930
931print '</table>'."\n";
932print '</div>'."\n";
933
934print '</form>'."\n";
935
936if ($mode == 'modulesetup') {
937 print dol_get_fiche_end();
938}
939
940
941llxFooter();
942
943$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.