list.php 30 KB

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