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