list.php 27 KB

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