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