list.php 26 KB

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