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 Frédéric France <frederic.france@netlogic.fr> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <https://www.gnu.org/licenses/>. 19 */ 20 21/** 22 * \file htdocs/cron/list.php 23 * \ingroup cron 24 * \brief Lists Jobs 25 */ 26 27require '../main.inc.php'; 28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; 29require_once DOL_DOCUMENT_ROOT.'/cron/class/cronjob.class.php'; 30require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php'; 31require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; 32 33// Load translation files required by the page 34$langs->loadLangs(array("admin", "cron", "bills", "members")); 35 36if (!$user->rights->cron->read) { 37 accessforbidden(); 38} 39 40$action = GETPOST('action', 'aZ09'); 41$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) 42$confirm = GETPOST('confirm', 'alpha'); 43$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list 44$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'cronjoblist'; // To manage different context of search 45 46$id = GETPOST('id', 'int'); 47 48$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; 49$sortfield = GETPOST("sortfield", 'alpha'); 50$sortorder = GETPOST("sortorder", 'alpha'); 51$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); 52if (empty($page) || $page == -1) { 53 $page = 0; 54} // If $page is not defined, or '' or -1 55$offset = $limit * $page; 56$pageprev = $page - 1; 57$pagenext = $page + 1; 58if (!$sortfield) { 59 $sortfield = 't.status,t.priority'; 60} 61if (!$sortorder) { 62 $sortorder = 'DESC,ASC'; 63} 64$optioncss = GETPOST('optioncss', 'alpha'); 65$mode = GETPOST('mode', 'aZ09'); 66//Search criteria 67$search_status = (GETPOSTISSET('search_status') ?GETPOST('search_status', 'int') : GETPOST('status', 'int')); 68$search_label = GETPOST("search_label", 'alpha'); 69$search_module_name = GETPOST("search_module_name", 'alpha'); 70$search_lastresult = GETPOST("search_lastresult", "alphawithlgt"); 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 91 92/* 93 * Actions 94 */ 95 96if (GETPOST('cancel', 'alpha')) { 97 $action = 'list'; $massaction = ''; 98} 99if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { 100 $massaction = ''; 101} 102 103$parameters = array(); 104$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks 105if ($reshook < 0) { 106 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); 107} 108 109if (empty($reshook)) { 110 // Selection of new fields 111 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; 112 113 // Purge search criteria 114 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 115 $search_label = ''; 116 $search_status = -1; 117 $search_lastresult = ''; 118 $toselect = ''; 119 $search_array_options = array(); 120 } 121 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') 122 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) { 123 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation 124 } 125 126 $filter = array(); 127 if (!empty($search_label)) { 128 $filter['t.label'] = $search_label; 129 } 130 131 // Delete jobs 132 if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->delete) { 133 //Delete cron task 134 $object = new Cronjob($db); 135 $object->id = $id; 136 $result = $object->delete($user); 137 138 if ($result < 0) { 139 setEventMessages($object->error, $object->errors, 'errors'); 140 } 141 } 142 143 // Execute jobs 144 if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute) { 145 if (!empty($conf->global->CRON_KEY) && $conf->global->CRON_KEY != $securitykey) { 146 setEventMessages('Security key '.$securitykey.' is wrong', null, 'errors'); 147 $action = ''; 148 } else { 149 $object = new Cronjob($db); 150 $job = $object->fetch($id); 151 152 $now = dol_now(); // Date we start 153 154 $resrunjob = $object->run_jobs($user->login); // Return -1 if KO, 1 if OK 155 if ($resrunjob < 0) { 156 setEventMessages($object->error, $object->errors, 'errors'); 157 } 158 159 // Programm next run 160 $res = $object->reprogram_jobs($user->login, $now); 161 if ($res > 0) { 162 if ($resrunjob >= 0) { // We show the result of reprogram only if no error message already reported 163 if ($object->lastresult >= 0) { 164 setEventMessages($langs->trans("JobFinished"), null, 'mesgs'); 165 } else { 166 setEventMessages($langs->trans("JobFinished"), null, 'errors'); 167 } 168 } 169 $action = ''; 170 } else { 171 setEventMessages($object->error, $object->errors, 'errors'); 172 $action = ''; 173 } 174 175 $param = '&search_status='.urlencode($search_status); 176 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { 177 $param .= '&contextpage='.urlencode($contextpage); 178 } 179 if ($limit > 0 && $limit != $conf->liste_limit) { 180 $param .= '&limit='.urlencode($limit); 181 } 182 if ($search_label) { 183 $param .= '&search_label='.urlencode($search_label); 184 } 185 if ($optioncss != '') { 186 $param .= '&optioncss='.urlencode($optioncss); 187 } 188 // Add $param from extra fields 189 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; 190 191 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 192 exit; 193 } 194 } 195 196 // Mass actions 197 $objectclass = 'CronJob'; 198 $objectlabel = 'CronJob'; 199 $permissiontoread = $user->rights->cron->read; 200 $permissiontoadd = $user->rights->cron->create ? $user->rights->cron->create : $user->rights->cron->write; 201 $permissiontodelete = $user->rights->cron->delete; 202 $uploaddir = $conf->cron->dir_output; 203 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; 204 if ($massaction && $permissiontoadd) { 205 $tmpcron = new Cronjob($db); 206 foreach ($toselect as $id) { 207 $result = $tmpcron->fetch($id); 208 if ($result) { 209 $result = 0; 210 if ($massaction == 'disable') { 211 $result = $tmpcron->setStatut(Cronjob::STATUS_DISABLED); 212 } elseif ($massaction == 'enable') { 213 $result = $tmpcron->setStatut(Cronjob::STATUS_ENABLED); 214 } 215 //else dol_print_error($db, 'Bad value for massaction'); 216 if ($result < 0) { 217 setEventMessages($tmpcron->error, $tmpcron->errors, 'errors'); 218 } 219 } else { 220 $error++; 221 } 222 } 223 } 224} 225 226 227/* 228 * View 229 */ 230 231$form = new Form($db); 232$cronjob = new Cronjob($db); 233 234$pagetitle = $langs->trans("CronList"); 235 236llxHeader('', $pagetitle); 237 238$sql = "SELECT"; 239$sql .= " t.rowid,"; 240$sql .= " t.tms,"; 241$sql .= " t.datec,"; 242$sql .= " t.jobtype,"; 243$sql .= " t.label,"; 244$sql .= " t.command,"; 245$sql .= " t.classesname,"; 246$sql .= " t.objectname,"; 247$sql .= " t.methodename,"; 248$sql .= " t.params,"; 249$sql .= " t.md5params,"; 250$sql .= " t.module_name,"; 251$sql .= " t.priority,"; 252$sql .= " t.processing,"; 253$sql .= " t.datelastrun,"; 254$sql .= " t.datenextrun,"; 255$sql .= " t.dateend,"; 256$sql .= " t.datestart,"; 257$sql .= " t.lastresult,"; 258$sql .= " t.datelastresult,"; 259$sql .= " t.lastoutput,"; 260$sql .= " t.unitfrequency,"; 261$sql .= " t.frequency,"; 262$sql .= " t.status,"; 263$sql .= " t.fk_user_author,"; 264$sql .= " t.fk_user_mod,"; 265$sql .= " t.note,"; 266$sql .= " t.maxrun,"; 267$sql .= " t.nbrun,"; 268$sql .= " t.libname,"; 269$sql .= " t.test"; 270$sql .= " FROM ".MAIN_DB_PREFIX."cronjob as t"; 271$sql .= " WHERE entity IN (0,".$conf->entity.")"; 272if ($search_status >= 0 && $search_status < 2 && $search_status != '') { 273 $sql .= " AND t.status = ".(empty($search_status) ? '0' : '1'); 274} 275if ($search_lastresult != '') { 276 $sql .= natural_search("t.lastresult", $search_lastresult, 1); 277} 278//Manage filter 279if (is_array($filter) && count($filter) > 0) { 280 foreach ($filter as $key => $value) { 281 $sql .= ' AND '.$key.' LIKE \'%'.$db->escape($value).'%\''; 282 } 283} 284$sqlwhere = array(); 285if (!empty($search_module_name)) { 286 $sqlwhere[] = '(t.module_name='.$db->escape($search_module_name).')'; 287} 288if (count($sqlwhere) > 0) { 289 $sql .= " WHERE ".implode(' AND ', $sqlwhere); 290} 291// Add where from extra fields 292include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; 293// Add where from hooks 294$parameters = array(); 295$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook 296$sql .= $hookmanager->resPrint; 297 298$sql .= $db->order($sortfield, $sortorder); 299 300// Count total nb of records 301$nbtotalofrecords = ''; 302if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { 303 $result = $db->query($sql); 304 $nbtotalofrecords = $db->num_rows($result); 305 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 306 $page = 0; 307 $offset = 0; 308 } 309} 310 311$sql .= $db->plimit($limit + 1, $offset); 312 313$result = $db->query($sql); 314if (!$result) { 315 dol_print_error($db); 316} 317 318$num = $db->num_rows($result); 319 320$arrayofselected = is_array($toselect) ? $toselect : array(); 321 322$param = ''; 323if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { 324 $param .= '&contextpage='.urlencode($contextpage); 325} 326if ($limit > 0 && $limit != $conf->liste_limit) { 327 $param .= '&limit='.urlencode($limit); 328} 329if ($search_status) { 330 $param .= '&search_status='.urlencode($search_status); 331} 332if ($search_label) { 333 $param .= '&search_label='.urlencode($search_label); 334} 335if ($search_module_name) { 336 $param .= '&search_module_name='.urlencode($search_module_name); 337} 338if ($search_lastresult) { 339 $param .= '&search_lastresult='.urlencode($search_lastresult); 340} 341if ($mode) { 342 $param .= '&mode='.urlencode($mode); 343} 344if ($optioncss != '') { 345 $param .= '&optioncss='.urlencode($optioncss); 346} 347// Add $param from extra fields 348include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; 349 350$stringcurrentdate = $langs->trans("CurrentHour").': '.dol_print_date(dol_now(), 'dayhour'); 351 352if ($action == 'execute') { 353 print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id.'&securitykey='.$securitykey.$param, $langs->trans("CronExecute"), $langs->trans("CronConfirmExecute"), "confirm_execute", '', '', 1); 354} 355 356// List of mass actions available 357$arrayofmassactions = array( 358//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), 359//'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), 360 'enable'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("CronStatusActiveBtn"), 361 'disable'=>img_picto('', 'uncheck', 'class="pictofixedwidth"').$langs->trans("CronStatusInactiveBtn"), 362); 363if ($user->rights->cron->delete) { 364 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); 365} 366if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) { 367 $arrayofmassactions = array(); 368} 369$massactionbutton = $form->selectMassAction('', $arrayofmassactions); 370 371if ($mode == 'modulesetup') { 372 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; 373 print load_fiche_titre($langs->trans("CronSetup"), $linkback, 'title_setup'); 374 375 // Configuration header 376 $head = cronadmin_prepare_head(); 377} 378 379print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" name="search_form">'."\n"; 380if ($optioncss != '') { 381 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">'; 382} 383print '<input type="hidden" name="token" value="'.newToken().'">'; 384print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; 385print '<input type="hidden" name="action" value="list">'; 386print '<input type="hidden" name="sortfield" value="'.$sortfield.'">'; 387print '<input type="hidden" name="sortorder" value="'.$sortorder.'">'; 388print '<input type="hidden" name="page" value="'.$page.'">'; 389print '<input type="hidden" name="contextpage" value="'.$contextpage.'">'; 390print '<input type="hidden" name="mode" value="'.$mode.'">'; 391 392// Line with explanation and button new 393$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->rights->cron->create); 394 395 396if ($mode == 'modulesetup') { 397 print dol_get_fiche_head($head, 'jobs', $langs->trans("Module2300Name"), -1, 'cron'); 398 399 //print '<span class="opacitymedium">'.$langs->trans('CronInfo').'</span><br>'; 400} 401 402 403print_barre_liste($pagetitle, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, ($mode == 'modulesetup' ? '' : 'title_setup'), 0, $newcardbutton, '', $limit); 404 405// Add code for pre mass action (confirmation or email presend form) 406$topicmail = "SendCronRef"; 407$modelmail = "cron"; 408$objecttmp = new Cronjob($db); 409$trackid = 'cron'.$object->id; 410include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; 411 412$text = $langs->trans("HoursOnThisPageAreOnServerTZ").' '.$stringcurrentdate.'<br>'; 413if (!empty($conf->global->CRON_WARNING_DELAY_HOURS)) { 414 $text .= $langs->trans("WarningCronDelayed", $conf->global->CRON_WARNING_DELAY_HOURS); 415} 416print info_admin($text); 417print '<br>'; 418 419//$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; 420$selectedfields = ''; 421//$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields 422$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : ''); 423 424print '<div class="div-table-responsive">'; 425print '<table class="noborder">'; 426 427print '<tr class="liste_titre_filter">'; 428print '<td class="liste_titre"> </td>'; 429print '<td class="liste_titre">'; 430print '<input type="text" class="flat" name="search_label" value="'.$search_label.'">'; 431print '</td>'; 432print '<td class="liste_titre"> </td>'; 433print '<td class="liste_titre"> </td>'; 434print '<td class="liste_titre"> </td>'; 435print '<td class="liste_titre"> </td>'; 436print '<td class="liste_titre"> </td>'; 437print '<td class="liste_titre"> </td>'; 438print '<td class="liste_titre"> </td>'; 439print '<td class="liste_titre"> </td>'; 440print '<td class="liste_titre center"><input type="text" class="width50" name="search_lastresult" value="'.$search_lastresult.'"></td>'; 441print '<td class="liste_titre"> </td>'; 442print '<td class="liste_titre"> </td>'; 443print '<td class="liste_titre" align="center">'; 444print $form->selectarray('search_status', array('0'=>$langs->trans("Disabled"), '1'=>$langs->trans("Scheduled")), $search_status, 1); 445print '</td><td class="liste_titre right">'; 446$searchpicto = $form->showFilterButtons(); 447print $searchpicto; 448print '</td>'; 449print '</tr>'; 450 451print '<tr class="liste_titre">'; 452print_liste_field_titre("ID", $_SERVER["PHP_SELF"], "t.rowid", "", $param, '', $sortfield, $sortorder); 453print_liste_field_titre("CronLabel", $_SERVER["PHP_SELF"], "t.label", "", $param, '', $sortfield, $sortorder); 454print_liste_field_titre("Prority", $_SERVER["PHP_SELF"], "t.priority", "", $param, '', $sortfield, $sortorder); 455print_liste_field_titre("CronTask", '', '', "", $param, '', $sortfield, $sortorder); 456print_liste_field_titre("CronFrequency", '', "", "", $param, '', $sortfield, $sortorder); 457print_liste_field_titre("CronDtStart", $_SERVER["PHP_SELF"], "t.datestart", "", $param, 'align="center"', $sortfield, $sortorder); 458print_liste_field_titre("CronDtEnd", $_SERVER["PHP_SELF"], "t.dateend", "", $param, 'align="center"', $sortfield, $sortorder); 459print_liste_field_titre("CronNbRun", $_SERVER["PHP_SELF"], "t.nbrun", "", $param, 'align="right"', $sortfield, $sortorder); 460print_liste_field_titre("CronDtLastLaunch", $_SERVER["PHP_SELF"], "t.datelastrun", "", $param, 'align="center"', $sortfield, $sortorder); 461print_liste_field_titre("Duration", $_SERVER["PHP_SELF"], "", "", $param, 'align="center"', $sortfield, $sortorder); 462print_liste_field_titre("CronLastResult", $_SERVER["PHP_SELF"], "t.lastresult", "", $param, 'align="center"', $sortfield, $sortorder); 463print_liste_field_titre("CronLastOutput", $_SERVER["PHP_SELF"], "t.lastoutput", "", $param, '', $sortfield, $sortorder); 464print_liste_field_titre("CronDtNextLaunch", $_SERVER["PHP_SELF"], "t.datenextrun", "", $param, 'align="center"', $sortfield, $sortorder); 465print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "t.status,t.priority", "", $param, 'align="center"', $sortfield, $sortorder); 466print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", "", $param, 'align="center"', $sortfield, $sortorder, 'maxwidthsearch '); 467print "</tr>\n"; 468 469 470if ($num > 0) { 471 // Loop on each job 472 $now = dol_now(); 473 $i = 0; 474 475 while ($i < min($num, $limit)) { 476 $obj = $db->fetch_object($result); 477 478 if (empty($obj)) { 479 break; 480 } 481 if (!verifCond($obj->test)) { 482 continue; // Discard line with test = false 483 } 484 485 $object->id = $obj->rowid; 486 $object->ref = $obj->rowid; 487 $object->label = $obj->label; 488 $object->status = $obj->status; 489 $object->priority = $obj->priority; 490 $object->processing = $obj->processing; 491 $object->lastresult = $obj->lastresult; 492 493 $datelastrun = $db->jdate($obj->datelastrun); 494 $datelastresult = $db->jdate($obj->datelastresult); 495 496 print '<tr class="oddeven">'; 497 498 // Ref 499 print '<td class="nowraponall">'; 500 print $object->getNomUrl(1); 501 print '</td>'; 502 503 // Label 504 print '<td class="tdoverflowmax300">'; 505 if (!empty($obj->label)) { 506 $object->ref = $langs->trans($obj->label); 507 print '<span title="'.dol_escape_htmltag($langs->trans($obj->label)).'">'.$object->getNomUrl(0, '', 1).'</span>'; 508 $object->ref = $obj->rowid; 509 } else { 510 //print $langs->trans('CronNone'); 511 } 512 print '</td>'; 513 514 // Priority 515 print '<td class="right">'; 516 print $object->priority; 517 print '</td>'; 518 519 print '<td class="nowraponall">'; 520 if ($obj->jobtype == 'method') { 521 $text = $langs->trans("CronClass"); 522 $texttoshow = $langs->trans('CronModule').': '.$obj->module_name.'<br>'; 523 $texttoshow .= $langs->trans('CronClass').': '.$obj->classesname.'<br>'; 524 $texttoshow .= $langs->trans('CronObject').': '.$obj->objectname.'<br>'; 525 $texttoshow .= $langs->trans('CronMethod').': '.$obj->methodename; 526 $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$obj->params; 527 $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($obj->note); 528 } elseif ($obj->jobtype == 'command') { 529 $text = $langs->trans('CronCommand'); 530 $texttoshow = $langs->trans('CronCommand').': '.dol_trunc($obj->command); 531 $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$obj->params; 532 $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($obj->note); 533 } 534 print $form->textwithpicto($text, $texttoshow, 1); 535 print '</td>'; 536 537 print '<td>'; 538 if ($obj->unitfrequency == "60") { 539 print $langs->trans('CronEach')." ".($obj->frequency)." ".$langs->trans('Minutes'); 540 } 541 if ($obj->unitfrequency == "3600") { 542 print $langs->trans('CronEach')." ".($obj->frequency)." ".$langs->trans('Hours'); 543 } 544 if ($obj->unitfrequency == "86400") { 545 print $langs->trans('CronEach')." ".($obj->frequency)." ".$langs->trans('Days'); 546 } 547 if ($obj->unitfrequency == "604800") { 548 print $langs->trans('CronEach')." ".($obj->frequency)." ".$langs->trans('Weeks'); 549 } 550 print '</td>'; 551 552 print '<td class="center">'; 553 if (!empty($obj->datestart)) { 554 print dol_print_date($db->jdate($obj->datestart), 'dayhour', 'tzserver'); 555 } 556 print '</td>'; 557 558 print '<td class="center">'; 559 if (!empty($obj->dateend)) { 560 print dol_print_date($db->jdate($obj->dateend), 'dayhour', 'tzserver'); 561 } 562 print '</td>'; 563 564 print '<td class="right">'; 565 if (!empty($obj->nbrun)) { 566 print $obj->nbrun; 567 } else { 568 print '0'; 569 } 570 if (!empty($obj->maxrun)) { 571 print ' <span class="'.$langs->trans("Max").'">/ '.$obj->maxrun.'</span>'; 572 } 573 print '</td>'; 574 575 // Date start last run 576 print '<td class="center">'; 577 if (!empty($datelastrun)) { 578 print dol_print_date($datelastrun, 'dayhoursec', 'tzserver'); 579 } 580 print '</td>'; 581 582 // Duration 583 print '<td class="center">'; 584 if (!empty($datelastresult) && ($datelastresult >= $datelastrun)) { 585 print convertSecondToTime(max($datelastresult - $datelastrun, 1), 'allhourminsec'); 586 //print '<br>'.($datelastresult - $datelastrun).' '.$langs->trans("seconds"); 587 } 588 print '</td>'; 589 590 // Return code of last run 591 print '<td class="center">'; 592 if ($obj->lastresult != '') { 593 if (empty($obj->lastresult)) { 594 print $obj->lastresult; 595 } else { 596 print '<span class="error">'.dol_trunc($obj->lastresult).'</div>'; 597 } 598 } 599 print '</td>'; 600 601 // Output of last run 602 print '<td class="small">'; 603 if (!empty($obj->lastoutput)) { 604 print dol_trunc(nl2br($obj->lastoutput), 50); 605 } 606 print '</td>'; 607 608 print '<td class="center">'; 609 if (!empty($obj->datenextrun)) { 610 $datenextrun = $db->jdate($obj->datenextrun); 611 if (empty($obj->status)) { 612 print '<span class="opacitymedium">'; 613 } 614 print dol_print_date($datenextrun, 'dayhoursec'); 615 if ($obj->status == Cronjob::STATUS_ENABLED) { 616 if ($obj->maxrun && $obj->nbrun >= $obj->maxrun) { 617 print img_warning($langs->trans("MaxRunReached")); 618 } elseif ($datenextrun && $datenextrun < $now) { 619 print img_warning($langs->trans("Late")); 620 } 621 } 622 if (empty($obj->status)) { 623 print '</span>'; 624 } 625 } 626 print '</td>'; 627 628 // Status 629 print '<td class="center">'; 630 print $object->getLibStatut(5); 631 print '</td>'; 632 633 print '<td class="nowraponall right">'; 634 635 $backtopage = urlencode($_SERVER["PHP_SELF"].'?'.$param.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '')); 636 if ($user->rights->cron->create) { 637 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; 638 print "&backtopage=".$backtopage."\" title=\"".dol_escape_htmltag($langs->trans('Edit'))."\">".img_picto($langs->trans('Edit'), 'edit')."</a> "; 639 } 640 if ($user->rights->cron->delete) { 641 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; 642 print "\" title=\"".dol_escape_htmltag($langs->trans('CronDelete'))."\">".img_picto($langs->trans('CronDelete'), 'delete', '', false, 0, 0, '', 'marginleftonly')."</a> "; 643 } else { 644 print "<a href=\"#\" title=\"".dol_escape_htmltag($langs->trans('NotEnoughPermissions'))."\">".img_picto($langs->trans('NotEnoughPermissions'), 'delete', '', false, 0, 0, '', 'marginleftonly')."</a> "; 645 } 646 if ($user->rights->cron->execute) { 647 if (!empty($obj->status)) { 648 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=execute'; 649 print (empty($conf->global->CRON_KEY) ? '' : '&securitykey='.$conf->global->CRON_KEY); 650 print ($sortfield ? '&sortfield='.$sortfield : ''); 651 print ($sortorder ? '&sortorder='.$sortorder : ''); 652 print $param."\" title=\"".dol_escape_htmltag($langs->trans('CronExecute'))."\">".img_picto($langs->trans('CronExecute'), "play", '', false, 0, 0, '', 'marginleftonly').'</a>'; 653 } else { 654 print '<a href="#" class="cursordefault" title="'.dol_escape_htmltag($langs->trans('JobDisabled')).'">'.img_picto($langs->trans('JobDisabled'), "playdisabled", '', false, 0, 0, '', 'marginleftonly').'</a>'; 655 } 656 } else { 657 print '<a href="#" class="cursornotallowed" title="'.dol_escape_htmltag($langs->trans('NotEnoughPermissions')).'">'.img_picto($langs->trans('NotEnoughPermissions'), "playdisabled", '', false, 0, 0, '', 'marginleftonly').'</a>'; 658 } 659 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined 660 $selected = 0; 661 if (in_array($obj->rowid, $arrayofselected)) { 662 $selected = 1; 663 } 664 print ' <input id="cb'.$obj->rowid.'" class="flat checkforselect valignmiddle" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>'; 665 } 666 print '</td>'; 667 668 print '</tr>'; 669 670 $i++; 671 } 672} else { 673 print '<tr><td colspan="15" class="opacitymedium">'.$langs->trans('CronNoJobs').'</td></tr>'; 674} 675 676print '</table>'; 677print '</div>'; 678 679print '</from>'; 680 681if ($mode == 'modulesetup') { 682 print dol_get_fiche_end(); 683} 684 685 686llxFooter(); 687 688$db->close(); 689