dolibarr 24.0.0-beta
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$filter = array(); // Search filter built later, initialized here so it is always defined (e.g. when a hook intercepts the Actions section)
63
64$id = GETPOSTINT('id');
65
66// Load variable for pagination
67$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
68$sortfield = GETPOST('sortfield', 'aZ09comma');
69$sortorder = GETPOST('sortorder', 'aZ09comma');
70$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
71if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
72 // If $page is not defined, or '' or -1 or if we click on clear filters
73 $page = 0;
74}
75$offset = $limit * $page;
76$pageprev = $page - 1;
77$pagenext = $page + 1;
78
79$outputdir = $conf->cron->dir_output;
80if (empty($outputdir)) {
81 $outputdir = $conf->cronjob->dir_output;
82}
83
84// Initialize technical objects
85$object = new Cronjob($db);
86$extrafields = new ExtraFields($db);
87$diroutputmassaction = $outputdir.'/temp/massgeneration/'.$user->id;
88$hookmanager->initHooks(array('cronjoblist'));
89
90// Fetch optionals attributes and labels
91$extrafields->fetch_name_optionals_label($object->table_element);
92
93$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
94
95// Default sort order (if not yet defined by previous GETPOST)
96if (!$sortfield) {
97 $sortfield = 't.priority,t.status';
98}
99if (!$sortorder) {
100 $sortorder = 'ASC,DESC';
101}
102
103// List of fields to search into when doing a "search in all"
104$fieldstosearchall = array();
105// foreach ($object->fields as $key => $val) {
106// if (!empty($val['searchall'])) {
107// $fieldstosearchall['t.'.$key] = $val['label'];
108// }
109// }
110// $parameters = array('fieldstosearchall'=>$fieldstosearchall);
111// $reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
112// if ($reshook > 0) {
113// $fieldstosearchall = empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall'];
114// } elseif ($reshook == 0) {
115// $fieldstosearchall = array_merge($fieldstosearchall, empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall']);
116// }
117
118// Definition of array of fields for columns from ->fields
119$tableprefix = 't';
120$arrayfields = array();
121/*
122foreach ($object->fields as $key => $val) {
123 // If $val['visible']==0, then we never show the field
124 if (!empty($val['visible'])) {
125 $visible = (int) dol_eval((string) $val['visible'], 1);
126 $arrayfields[$tableprefix.'.'.$key] = array(
127 'label' => $val['label'],
128 'checked' => (($visible < 0) ? '0' : '1'),
129 'enabled' => (string) (int) (abs($visible) != 3 && (bool) dol_eval((string) $val['enabled'], 1)),
130 'position' => $val['position'],
131 'help' => isset($val['help']) ? $val['help'] : ''
132 );
133 }
134}
135*/
136
137$object->fields = dol_sort_array($object->fields, 'position');
138$arrayfields = dol_sort_array($arrayfields, 'position');
139
140
141$permissiontoread = $user->hasRight('cron', 'read');
142$permissiontoadd = $user->hasRight('cron', 'create') ? $user->hasRight('cron', 'create') : $user->hasRight('cron', 'write');
143$permissiontodelete = $user->hasRight('cron', 'delete');
144$permissiontoexecute = $user->hasRight('cron', 'execute');
145
146// Security
147if (!$permissiontoread) {
149}
150// after this test $permissiontoread is always true and never can't be false
151
152$error = 0;
153//var_dump($arrayfields);
154
155
156/*
157 * Actions
158 */
159
160if (GETPOST('cancel', 'alpha')) {
161 $action = 'list';
162 $massaction = '';
163}
164if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
165 $massaction = '';
166}
167
168$parameters = array('arrayfields' => &$arrayfields);
169$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
170if ($reshook < 0) {
171 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
172}
173
174if (empty($reshook)) {
175 // Selection of new fields
176 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
177
178 // Purge search criteria
179 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
180 $search_label = '';
181 $search_status = -1;
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 ($optioncss != '') {
252 $param .= '&optioncss='.urlencode($optioncss);
253 }
254 // Add $param from extra fields
255 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
256
257 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
258 exit;
259 }
260 }
261
262 // Mass actions
263 $objectclass = 'CronJob';
264 $objectlabel = 'CronJob';
265 $uploaddir = $conf->cron->dir_output;
266 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
267 if ($massaction && $permissiontoadd) {
268 $tmpcron = new Cronjob($db);
269 foreach ($toselect as $id) {
270 $result = $tmpcron->fetch($id);
271 if ($result) {
272 $result = 0;
273 if ($massaction == 'disable') {
274 $result = $tmpcron->setStatut(Cronjob::STATUS_DISABLED);
275 } elseif ($massaction == 'enable') {
276 $result = $tmpcron->setStatut(Cronjob::STATUS_ENABLED);
277 }
278 //else dol_print_error($db, 'Bad value for massaction');
279 if ($result < 0) {
280 setEventMessages($tmpcron->error, $tmpcron->errors, 'errors');
281 }
282 } else {
283 $error++;
284 }
285 }
286 }
287}
288
289
290/*
291 * View
292 */
293
294$now = dol_now();
295
296$form = new Form($db);
297$cronjob = new Cronjob($db);
298
299$title = $langs->trans("CronList");
300
301llxHeader('', $title, '', '', 0, 0, '', '', '', 'bodyforlist');
302
303$TTestNotAllowed = array();
304$sqlTest = 'SELECT rowid, test FROM '.MAIN_DB_PREFIX.'cronjob';
305$resultTest = $db->query($sqlTest);
306if ($resultTest) {
307 while ($objTest = $db->fetch_object($resultTest)) {
308 $veriftest = verifCond($objTest->test);
309 if (!$veriftest) {
310 $TTestNotAllowed[$objTest->rowid] = $objTest->rowid;
311 }
312 }
313}
314
315// Build and execute select
316// --------------------------------------------------------------------
317$sql = "SELECT";
318$sql .= " t.rowid,";
319$sql .= " t.tms,";
320$sql .= " t.datec,";
321$sql .= " t.jobtype,";
322$sql .= " t.label,";
323$sql .= " t.command,";
324$sql .= " t.classesname,";
325$sql .= " t.objectname,";
326$sql .= " t.methodename,";
327$sql .= " t.params,";
328$sql .= " t.md5params,";
329$sql .= " t.module_name,";
330$sql .= " t.priority,";
331$sql .= " t.processing,";
332$sql .= " t.datelastrun,";
333$sql .= " t.datenextrun,";
334$sql .= " t.dateend,";
335$sql .= " t.datestart,";
336$sql .= " t.lastresult,";
337$sql .= " t.datelastresult,";
338$sql .= " t.lastoutput,";
339$sql .= " t.unitfrequency,";
340$sql .= " t.frequency,";
341$sql .= " t.status,";
342$sql .= " t.fk_user_author,";
343$sql .= " t.fk_user_mod,";
344$sql .= " t.note,";
345$sql .= " t.maxrun,";
346$sql .= " t.nbrun,";
347$sql .= " t.libname,";
348$sql .= " t.test";
349$sql .= " FROM ".MAIN_DB_PREFIX."cronjob as t";
350$sql .= " WHERE entity IN (0,".$conf->entity.")";
351if (!empty($TTestNotAllowed)) {
352 $sql .= ' AND t.rowid NOT IN ('.$db->sanitize(implode(',', $TTestNotAllowed)).')';
353}
354if ($search_status >= 0 && $search_status < 2 && $search_status != '') {
355 $sql .= " AND t.status = ".(empty($search_status) ? '0' : '1');
356}
357if ($search_lastresult != '') {
358 $sql .= natural_search("t.lastresult", $search_lastresult, 1);
359}
360if (GETPOSTISSET('search_processing')) {
361 $sql .= " AND t.processing = ".((int) $search_processing);
362}
363// Manage filter
364if (count($filter) > 0) {
365 foreach ($filter as $key => $value) {
366 $sql .= " AND ".$db->sanitize($key)." LIKE '%".$db->escape($value)."%'";
367 }
368}
369if (!empty($search_module_name)) {
370 $sql .= natural_search("t.module_name", $search_module_name);
371}
372// Add where from extra fields
373include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
374// Add where from hooks
375$parameters = array();
376$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
377$sql .= $hookmanager->resPrint;
378
379
380// Count total nb of records
381$nbtotalofrecords = '';
382if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
383 $sqlforcount = $sql;
384
385 $resql = $db->query($sqlforcount);
386 if ($resql) {
387 $nbtotalofrecords = $db->num_rows($resql);
388 } else {
390 }
391
392 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
393 $page = 0;
394 $offset = 0;
395 }
396 $db->free($resql);
397}
398
399// Complete request and execute it with limit
400$sql .= $db->order($sortfield, $sortorder);
401if ($limit) {
402 $sql .= $db->plimit($limit + 1, $offset);
403}
404
405$resql = $db->query($sql);
406if (!$resql) {
408 exit;
409}
410
411$num = $db->num_rows($resql);
412
413$arrayofselected = is_array($toselect) ? $toselect : array();
414
415$param = '';
416if (!empty($mode)) {
417 $param .= '&mode='.urlencode($mode);
418}
419if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
420 $param .= '&contextpage='.urlencode($contextpage);
421}
422if ($limit > 0 && $limit != $conf->liste_limit) {
423 $param .= '&limit='.((int) $limit);
424}
425if ($optioncss != '') {
426 $param .= '&optioncss='.urlencode($optioncss);
427}
428if ($search_status) {
429 $param .= '&search_status='.urlencode($search_status);
430}
431if ($search_label) {
432 $param .= '&search_label='.urlencode($search_label);
433}
434if ($search_module_name) {
435 $param .= '&search_module_name='.urlencode($search_module_name);
436}
437if ($search_lastresult) {
438 $param .= '&search_lastresult='.urlencode($search_lastresult);
439}
440// Add $param from extra fields
441include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
442
443$stringcurrentdate = $langs->trans("CurrentHour").': '.dol_print_date(dol_now(), 'dayhour');
444
445if ($action == 'execute') {
446 print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id.'&securitykey='.$securitykey.$param, $langs->trans("CronExecute"), $langs->trans("CronConfirmExecute"), "confirm_execute", '', '', 1);
447}
448
449if ($action == 'delete' && empty($toselect)) { // Used when we make a delete on 1 line (not used for mass delete)
450 print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id.$param, $langs->trans("CronDelete"), $langs->trans("CronConfirmDelete"), "confirm_delete", '', '', 1);
451}
452
453// List of mass actions available
454$arrayofmassactions = array(
455//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
456//'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
457 'enable' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("CronStatusActiveBtn"),
458 'disable' => img_picto('', 'uncheck', 'class="pictofixedwidth"').$langs->trans("CronStatusInactiveBtn"),
459);
460if ($user->hasRight('cron', 'delete')) {
461 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
462}
463if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
464 $arrayofmassactions = array();
465}
466$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
467
468$head = [];
469if ($mode == 'modulesetup') {
470 $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>';
471 print load_fiche_titre($langs->trans("CronSetup"), $linkback, 'title_setup');
472
473 // Configuration header
474 $head = cronadmin_prepare_head();
475}
476
477print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" name="search_form">'."\n";
478if ($optioncss != '') {
479 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
480}
481print '<input type="hidden" name="token" value="'.newToken().'">';
482print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
483print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
484print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
485print '<input type="hidden" name="page" value="'.$page.'">';
486print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
487print '<input type="hidden" name="page_y" value="">';
488print '<input type="hidden" name="mode" value="'.$mode.'">';
489
490// Line with explanation and button new
491$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'));
492
493
494if ($mode == 'modulesetup') {
495 print dol_get_fiche_head($head, 'jobs', $langs->trans("Module2300Name"), -1, 'cron');
496
497 //print '<span class="opacitymedium">'.$langs->trans('CronInfo').'</span><br>';
498}
499
500
501print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, ($mode == 'modulesetup' ? '' : 'title_setup'), 0, $newcardbutton, '', $limit);
502
503// Add code for pre mass action (confirmation or email presend form)
504$topicmail = "SendCronRef";
505$modelmail = "cron";
506$objecttmp = new Cronjob($db);
507$trackid = 'cron'.$object->id;
508include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
509
510$text = $langs->trans("HoursOnThisPageAreOnServerTZ").' '.$stringcurrentdate.'<br>';
511if (getDolGlobalString('CRON_WARNING_DELAY_HOURS')) {
512 $text .= $langs->trans("WarningCronDelayed", getDolGlobalString('CRON_WARNING_DELAY_HOURS'));
513}
514print info_admin($text);
515//print '<br>';
516
517$moreforfilter = '';
518
519$parameters = array();
520$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
521if (empty($reshook)) {
522 $moreforfilter .= $hookmanager->resPrint;
523} else {
524 $moreforfilter = $hookmanager->resPrint;
525}
526$parameters = array(
527 'arrayfields' => &$arrayfields,
528);
529
530if (!empty($moreforfilter)) {
531 print '<div class="liste_titre liste_titre_bydiv centpercent">';
532 print $moreforfilter;
533 print '</div>';
534}
535
536$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
537$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields with user setup
538$selectedfields = (($mode != 'kanban' && $mode != 'kanbangroupby') ? $htmlofselectarray : '');
539$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
540
541print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
542print '<table class="tagtable nobottomiftotal noborder liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
543
544// Fields title search
545// --------------------------------------------------------------------
546print '<tr class="liste_titre_filter">';
547// Action column
548if ($conf->main_checkbox_left_column) {
549 print '<td class="liste_titre center maxwidthsearch">';
550 $searchpicto = $form->showFilterButtons('left');
551 print $searchpicto;
552 print '</td>';
553}
554print '<td class="liste_titre">&nbsp;</td>';
555print '<td class="liste_titre">';
556print '<input type="text" class="flat width75" name="search_label" value="'.$search_label.'">';
557print '</td>';
558print '<td class="liste_titre">&nbsp;</td>';
559print '<td class="liste_titre"><input type="text" class="width50" name="search_module_name" value="'.$search_module_name.'"></td>';
560print '<td class="liste_titre">&nbsp;</td>';
561print '<td class="liste_titre">&nbsp;</td>';
562//print '<td class="liste_titre">&nbsp;</td>';
563//print '<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">&nbsp;</td>';
567print '<td class="liste_titre center"><input type="text" class="width50" name="search_lastresult" value="'.$search_lastresult.'"></td>';
568print '<td class="liste_titre">&nbsp;</td>';
569print '<td class="liste_titre">&nbsp;</td>';
570print '<td class="liste_titre center">';
571print $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');
572print '</td>';
573print '<td class="liste_titre">&nbsp;</td>';
574// Action column
575if (!$conf->main_checkbox_left_column) {
576 print '<td class="liste_titre right">';
577 $searchpicto = $form->showFilterButtons();
578 print $searchpicto;
579 print '</td>';
580}
581print '</tr>'."\n";
582
583$totalarray = array();
584$totalarray['nbfield'] = 0;
585
586// Fields title label
587// --------------------------------------------------------------------
588print '<tr class="liste_titre">';
589// Action column
590if ($conf->main_checkbox_left_column) {
591 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'center maxwidthsearch ');
592}
593print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "t.rowid", "", $param, '', $sortfield, $sortorder);
594print_liste_field_titre("CronLabel", $_SERVER["PHP_SELF"], "t.label", "", $param, '', $sortfield, $sortorder);
595print_liste_field_titre("Priority", $_SERVER["PHP_SELF"], "t.priority", "", $param, '', $sortfield, $sortorder);
596print_liste_field_titre("CronModule", $_SERVER["PHP_SELF"], "t.module_name", "", $param, '', $sortfield, $sortorder);
597print_liste_field_titre("", '', '', "", $param, '', $sortfield, $sortorder, 'tdoverflowmax50 ');
598print_liste_field_titre("CronFrequency", '', "", "", $param, '', $sortfield, $sortorder);
599//print_liste_field_titre("CronDtStart", $_SERVER["PHP_SELF"], "t.datestart", "", $param, 'align="center"', $sortfield, $sortorder);
600//print_liste_field_titre("CronDtEnd", $_SERVER["PHP_SELF"], "t.dateend", "", $param, 'align="center"', $sortfield, $sortorder);
601print_liste_field_titre("CronNbRun", $_SERVER["PHP_SELF"], "t.nbrun", "", $param, '', $sortfield, $sortorder, 'right tdoverflowmax50 maxwidth50imp ');
602print_liste_field_titre("CronDtLastLaunch", $_SERVER["PHP_SELF"], "t.datelastrun", "", $param, '', $sortfield, $sortorder, 'center tdoverflowmax100 ');
603print_liste_field_titre("Duration", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'center ');
604print_liste_field_titre("CronLastResult", $_SERVER["PHP_SELF"], "t.lastresult", "", $param, '', $sortfield, $sortorder, 'center ');
605print_liste_field_titre("CronLastOutput", $_SERVER["PHP_SELF"], "t.lastoutput", "", $param, '', $sortfield, $sortorder);
606print_liste_field_titre("CronDtNextLaunch", $_SERVER["PHP_SELF"], "t.datenextrun", "", $param, '', $sortfield, $sortorder, 'center ');
607print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "t.status,t.priority", "", $param, '', $sortfield, $sortorder, 'center ');
608print_liste_field_titre("", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'center ');
609// Action column
610if (!$conf->main_checkbox_left_column) {
611 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'center maxwidthsearch ');
612}
613print '</tr>'."\n";
614
615// Loop on record
616// --------------------------------------------------------------------
617$i = 0;
618$savnbfield = $totalarray['nbfield'];
619$totalarray = array();
620$totalarray['nbfield'] = 0;
621$imaxinloop = ($limit ? min($num, $limit) : $num);
622
623if ($num > 0) {
624 // Loop on each job
625
626 while ($i < $imaxinloop) {
627 $obj = $db->fetch_object($resql);
628 if (empty($obj)) {
629 break;
630 }
631
632 $reg = array();
633 if (preg_match('/:(.*)$/', $obj->label, $reg)) {
634 $langs->load($reg[1]);
635 }
636
637 $object->id = $obj->rowid;
638 $object->ref = $obj->rowid;
639 $object->label = preg_replace('/:.*$/', '', $obj->label);
640 $object->status = $obj->status;
641 $object->priority = $obj->priority;
642 $object->processing = $obj->processing;
643 $object->lastresult = (string) $obj->lastresult;
644 $object->datestart = $db->jdate($obj->datestart);
645 $object->dateend = $db->jdate($obj->dateend);
646 $object->module_name = $obj->module_name;
647 $object->params = $obj->params;
648 $object->datelastrun = $db->jdate($obj->datelastrun);
649 $object->datenextrun = $db->jdate($obj->datenextrun);
650
651 $datelastrun = $db->jdate($obj->datelastrun);
652 $datelastresult = $db->jdate($obj->datelastresult);
653 $datefromto = (empty($datelastrun) ? '' : dol_print_date($datelastrun, 'dayhoursec', 'tzserver')).' - '.(empty($datelastresult) ? '' : dol_print_date($datelastresult, 'dayhoursec', 'tzserver'));
654
655
656 print '<tr class="oddeven row-with-select">';
657
658 // Action column
659 if ($conf->main_checkbox_left_column) {
660 print '<td class="nowraponall center">';
661 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
662 $selected = 0;
663 if (in_array($obj->rowid, $arrayofselected)) {
664 $selected = 1;
665 }
666 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect valignmiddle" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
667 }
668 print '</td>';
669 if (!$i) {
670 $totalarray['nbfield']++;
671 }
672 }
673
674 // Ref
675 print '<td class="nowraponall">';
676 print $object->getNomUrl(1);
677 print '</td>';
678 if (!$i) {
679 $totalarray['nbfield']++;
680 }
681
682 // Label
683 print '<td class="minwidth150">';
684 if (!empty($object->label)) {
685 $object->ref = $langs->trans($object->label);
686 print '<div class="small twolinesmax lineheightsmall minwidth150 maxwidth250 classfortooltip" title="'.dol_escape_htmltag($langs->trans($object->label), 0, 0).'">';
687 print $object->getNomUrl(0, '', 1);
688 print '</div>';
689 $object->ref = $obj->rowid;
690 } else {
691 //print $langs->trans('CronNone');
692 }
693 print '</td>';
694 if (!$i) {
695 $totalarray['nbfield']++;
696 }
697
698 // Priority
699 print '<td class="right">';
700 print dol_escape_htmltag($object->priority);
701 print '</td>';
702
703 // Module
704 print '<td>';
705 print dol_escape_htmltag($object->module_name);
706 print '</td>';
707 if (!$i) {
708 $totalarray['nbfield']++;
709 }
710
711 // Class/Method
712 print '<td class="nowraponall">';
713 if ($obj->jobtype == 'method') {
714 $text = img_picto('', 'code');
715 $texttoshow = '<b>'.$langs->trans("CronType_method").'</b><br><br>';
716 $texttoshow .= $langs->trans('CronModule').': '.$obj->module_name.'<br>';
717 $texttoshow .= $langs->trans('CronClass').': '.$obj->classesname.'<br>';
718 $texttoshow .= $langs->trans('CronObject').': '.$obj->objectname.'<br>';
719 $texttoshow .= $langs->trans('CronMethod').': '.$obj->methodename;
720 $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$obj->params;
721 $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($obj->note);
722 } elseif ($obj->jobtype == 'command') {
723 $text = img_picto('', 'terminal');
724 $texttoshow = '<b>'.$langs->trans('CronType_command').'</b><br><br>';
725 $texttoshow .= $langs->trans('CronCommand').': '.dol_trunc($obj->command);
726 $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$obj->params;
727 $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($obj->note);
728 } else {
729 $texttoshow = '';
730 $texttoshow = '';
731 }
732 print '<span class="classfortooltip" title="'.dol_escape_htmltag($texttoshow, 1, 1).'">'.$text.'</a>';
733 print '</td>';
734 if (!$i) {
735 $totalarray['nbfield']++;
736 }
737
738 // Frequency
739 $s = '';
740 if ($obj->unitfrequency == "60") {
741 $s = ($obj->frequency)." ".$langs->trans('MinuteShort');
742 } elseif ($obj->unitfrequency == "3600") {
743 $s = ($obj->frequency)." ".$langs->trans('HourShort');
744 } elseif ($obj->unitfrequency == "86400") {
745 $s = ($obj->frequency)." ".($obj->frequency > 1 ? $langs->trans('DurationDays') : $langs->trans('DurationDay'));
746 } elseif ($obj->unitfrequency == "604800") {
747 $s = ($obj->frequency)." ".($obj->frequency > 1 ? $langs->trans('DurationWeeks') : $langs->trans('DurationWeek'));
748 } elseif ($obj->unitfrequency == "2678400") {
749 $s = ($obj->frequency)." ".($obj->frequency > 1 ? $langs->trans('DurationMonths') : $langs->trans('DurationMonth'));
750 }
751 print '<td class="tdoverflowmax125 center" title="'.dol_escape_htmltag($s).'">';
752 print dol_escape_htmltag($s);
753 print '</td>';
754 if (!$i) {
755 $totalarray['nbfield']++;
756 }
757
758 /*
759 print '<td class="center">';
760 if (!empty($obj->datestart)) {
761 print dol_print_date($db->jdate($obj->datestart), 'dayhour', 'tzserver');
762 }
763 print '</td>';
764 if (!$i) {
765 $totalarray['nbfield']++;
766 }
767
768 print '<td class="center">';
769 if (!empty($obj->dateend)) {
770 print dol_print_date($db->jdate($obj->dateend), 'dayhour', 'tzserver');
771 }
772 print '</td>';
773 if (!$i) {
774 $totalarray['nbfield']++;
775 }
776 */
777
778 print '<td class="right">';
779 if (!empty($obj->nbrun)) {
780 print dol_escape_htmltag($obj->nbrun);
781 } else {
782 print '0';
783 }
784 if (!empty($obj->maxrun)) {
785 print ' <span class="'.$langs->trans("Max").'">/ '.dol_escape_htmltag($obj->maxrun).'</span>';
786 }
787 print '</td>';
788 if (!$i) {
789 $totalarray['nbfield']++;
790 }
791
792 // Date start last run
793 print '<td class="center celldateheight" title="'.dol_escape_htmltag($datefromto).'">';
794 if (!empty($datelastrun)) {
795 print dolOutputDates($datelastrun, null, 0, 1, '', 'tzserver');
796 }
797 print '</td>';
798 if (!$i) {
799 $totalarray['nbfield']++;
800 }
801
802 // Duration
803 print '<td class="center nowraponall" title="'.dol_escape_htmltag($datefromto).'">';
804 if (!empty($datelastresult) && ($datelastresult >= $datelastrun)) {
805 $nbseconds = max($datelastresult - $datelastrun, 1);
806 print $nbseconds.' '.$langs->trans("SecondShort");
807 }
808 print '</td>';
809 if (!$i) {
810 $totalarray['nbfield']++;
811 }
812
813 // Return code of last run
814 print '<td class="center tdlastresultcode" title="'.dol_escape_htmltag($obj->lastresult).'">';
815 if ($obj->lastresult != '') {
816 if (empty($obj->lastresult) || $obj->status == Cronjob::STATUS_DISABLED) {
817 print $obj->lastresult; // Print '0'
818 } else {
819 print '<span class="error">'.dol_escape_htmltag(dol_trunc($obj->lastresult)).'</div>';
820 }
821 }
822 print '</td>';
823 if (!$i) {
824 $totalarray['nbfield']++;
825 }
826
827 // Output of last run
828 print '<td class="small minwidth150">';
829 if (!empty($obj->lastoutput)) {
830 print '<div class="twolinesmax lineheightsmall classfortooltip" title="'.dolPrintHTMLForAttribute($obj->lastoutput).'">';
831 print dol_trunc(dolGetFirstLineOfText($obj->lastoutput, 2), 100);
832 print '</div>';
833 }
834 print '</td>';
835 if (!$i) {
836 $totalarray['nbfield']++;
837 }
838
839 // Next run date
840 print '<td class="center celldateheight">';
841 if (!empty($obj->datenextrun)) {
842 $datenextrun = $db->jdate($obj->datenextrun);
843 if (empty($obj->status)) {
844 print '<span class="opacitymedium strikefordisabled">';
845 }
846
847 $pictotoadd = '';
848 if ($obj->status == Cronjob::STATUS_ENABLED) {
849 if ($obj->maxrun && $obj->nbrun >= $obj->maxrun) {
850 $pictotoadd .= img_warning($langs->trans("MaxRunReached"));
851 } elseif ($datenextrun && $datenextrun < $now) {
852 $pictotoadd .= img_warning($langs->trans("Late"));
853 }
854 }
855
856 print dolOutputDates($datenextrun, null, 0, 1, $pictotoadd);
857
858 if (empty($obj->status)) {
859 print '</span>';
860 }
861 }
862 print '</td>';
863 if (!$i) {
864 $totalarray['nbfield']++;
865 }
866
867 // Status
868 print '<td class="center">';
869 print $object->getLibStatut(5);
870 print '</td>';
871 if (!$i) {
872 $totalarray['nbfield']++;
873 }
874
875 // Action
876 print '<td class="nowraponall right">';
877 $backtopage = urlencode($_SERVER["PHP_SELF"].'?'.$param.'&sortfield='.$sortfield.'&sortorder='.$sortorder);
878 if ($user->hasRight('cron', 'create')) {
879 print '<a class="editfielda" href="'.DOL_URL_ROOT."/cron/card.php?id=".$obj->rowid.'&action=edit&token='.newToken().'&sortfield='.$sortfield.'&sortorder='.$sortorder.$param;
880 print "&backtopage=".$backtopage."\" title=\"".dol_escape_htmltag($langs->trans('Edit'))."\">".img_picto($langs->trans('Edit'), 'edit')."</a> &nbsp;";
881 }
882 if ($user->hasRight('cron', 'delete')) {
883 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"]."?id=".$obj->rowid.'&action=delete&token='.newToken().($page ? '&page='.$page : '').'&sortfield='.$sortfield.'&sortorder='.$sortorder.$param;
884 print '" title="'.dol_escape_htmltag($langs->trans('CronDelete')).'">'.img_picto($langs->trans('CronDelete'), 'delete', '', 0, 0, 0, '', 'marginleftonly').'</a> &nbsp; ';
885 } else {
886 print '<a href="#" title="'.dol_escape_htmltag($langs->trans('NotEnoughPermissions')).'">'.img_picto($langs->trans('NotEnoughPermissions'), 'delete', '', 0, 0, 0, '', 'marginleftonly').'</a> &nbsp; ';
887 }
888 if ($user->hasRight('cron', 'execute')) {
889 if (!empty($obj->status)) {
890 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=execute&token='.newToken();
891 print (!getDolGlobalString('CRON_KEY') ? '' : '&securitykey=' . getDolGlobalString('CRON_KEY'));
892 print '&sortfield='.$sortfield;
893 print '&sortorder='.$sortorder;
894 print $param."\" title=\"".dol_escape_htmltag($langs->trans('CronExecute'))."\">".img_picto($langs->trans('CronExecute'), "play", '', 0, 0, 0, '', 'marginleftonly').'</a>';
895 } else {
896 print '<a href="#" class="cursordefault" title="'.dol_escape_htmltag($langs->trans('JobDisabled')).'">'.img_picto($langs->trans('JobDisabled'), "playdisabled", '', 0, 0, 0, '', 'marginleftonly').'</a>';
897 }
898 } else {
899 print '<a href="#" class="cursornotallowed" title="'.dol_escape_htmltag($langs->trans('NotEnoughPermissions')).'">'.img_picto($langs->trans('NotEnoughPermissions'), "playdisabled", '', 0, 0, 0, '', 'marginleftonly').'</a>';
900 }
901 print '</td>';
902 if (!$i) {
903 $totalarray['nbfield']++;
904 }
905
906 // Action column
907 if (!$conf->main_checkbox_left_column) {
908 print '<td class="nowraponall center">';
909 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
910 $selected = 0;
911 if (in_array($obj->rowid, $arrayofselected)) {
912 $selected = 1;
913 }
914 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect valignmiddle" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
915 }
916 print '</td>';
917 if (!$i) {
918 $totalarray['nbfield']++;
919 }
920 }
921
922 print '</tr>'."\n";
923
924 $i++;
925 }
926} else {
927 print '<tr><td colspan="16"><span class="opacitymedium">'.$langs->trans('CronNoJobs').'</span></td></tr>';
928}
929
930$db->free($resql);
931
932$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
933$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
934print $hookmanager->resPrint;
935
936print '</table>'."\n";
937print '</div>'."\n";
938
939print '</form>'."\n";
940
941if ($mode == 'modulesetup') {
942 print dol_get_fiche_end();
943}
944
945
946llxFooter();
947
948$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 list.php:497
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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='')
Show information in HTML for admin users or standard users.
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.
dolOutputDates($datep, $datef=null, $fullday=0, $addseconds=0, $pictotoadd='', $tzoutput='tzuserrel', $reduceformat=0)
Print decorated date-hour.
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...
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.
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...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.