card.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. <?php
  2. /* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
  3. * Copyright (C) 2013 Florian Henry <florian.henry@open-concpt.pro>
  4. * Copyright (C) 2013-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2018-2023 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/card.php
  22. * \ingroup cron
  23. * \brief Cron Jobs Card
  24. */
  25. // Load Dolibarr environment
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  28. // librairie jobs
  29. require_once DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php";
  30. require_once DOL_DOCUMENT_ROOT."/core/class/html.formcron.class.php";
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('admin', 'cron', 'members', 'bills'));
  34. $id = GETPOST('id', 'int');
  35. $action = GETPOST('action', 'aZ09');
  36. $confirm = GETPOST('confirm', 'alpha');
  37. $cancel = GETPOST('cancel', 'alpha');
  38. $backtopage = GETPOST('backtopage', 'alpha');
  39. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  40. $securitykey = GETPOST('securitykey', 'alpha');
  41. if (!$user->hasRight('cron', 'create')) {
  42. accessforbidden();
  43. }
  44. $permissiontoadd = $user->hasRight('cron', 'create');
  45. $permissiontoexecute = $user->hasRight('cron', 'execute');
  46. $permissiontodelete = $user->hasRight('cron', 'delete');
  47. /*
  48. * Actions
  49. */
  50. $object = new Cronjob($db);
  51. if (!empty($id)) {
  52. $result = $object->fetch($id);
  53. if ($result < 0) {
  54. setEventMessages($object->error, $object->errors, 'errors');
  55. }
  56. }
  57. if (!empty($cancel)) {
  58. if (!empty($id) && empty($backtopage)) {
  59. $action = '';
  60. } else {
  61. if ($backtopage) {
  62. header("Location: ".$backtopage);
  63. exit;
  64. } else {
  65. header("Location: ".DOL_URL_ROOT.'/cron/list.php');
  66. exit;
  67. }
  68. }
  69. }
  70. // Delete jobs
  71. if ($action == 'confirm_delete' && $confirm == "yes" && $permissiontodelete) {
  72. $result = $object->delete($user);
  73. if ($result < 0) {
  74. setEventMessages($object->error, $object->errors, 'errors');
  75. $action = 'edit';
  76. } else {
  77. Header("Location: ".DOL_URL_ROOT.'/cron/list.php');
  78. exit;
  79. }
  80. }
  81. // Execute jobs
  82. if ($action == 'confirm_execute' && $confirm == "yes" && $permissiontoexecute) {
  83. if (!empty($conf->global->CRON_KEY) && $conf->global->CRON_KEY != $securitykey) {
  84. setEventMessages('Security key '.$securitykey.' is wrong', null, 'errors');
  85. $action = '';
  86. } else {
  87. $now = dol_now(); // Date we start
  88. $result = $object->run_jobs($user->login);
  89. if ($result < 0) {
  90. setEventMessages($object->error, $object->errors, 'errors');
  91. $action = '';
  92. } else {
  93. $res = $object->reprogram_jobs($user->login, $now);
  94. if ($res > 0) {
  95. if ($object->lastresult > 0) {
  96. setEventMessages($langs->trans("JobFinished"), null, 'warnings');
  97. } else {
  98. setEventMessages($langs->trans("JobFinished"), null, 'mesgs');
  99. }
  100. $action = '';
  101. } else {
  102. setEventMessages($object->error, $object->errors, 'errors');
  103. $action = '';
  104. }
  105. }
  106. }
  107. }
  108. if ($action == 'add' && $permissiontoadd) {
  109. $object->jobtype = GETPOST('jobtype');
  110. $object->label = GETPOST('label');
  111. $object->command = GETPOST('command');
  112. $object->classesname = GETPOST('classesname', 'alphanohtml');
  113. $object->objectname = GETPOST('objectname', 'aZ09');
  114. $object->methodename = GETPOST('methodename', 'aZ09');
  115. $object->params = GETPOST('params');
  116. $object->md5params = GETPOST('md5params');
  117. $object->module_name = GETPOST('module_name');
  118. $object->note_private = GETPOST('note', 'restricthtml');
  119. $object->datestart = dol_mktime(GETPOST('datestarthour', 'int'), GETPOST('datestartmin', 'int'), 0, GETPOST('datestartmonth', 'int'), GETPOST('datestartday', 'int'), GETPOST('datestartyear', 'int'));
  120. $object->dateend = dol_mktime(GETPOST('dateendhour', 'int'), GETPOST('dateendmin', 'int'), 0, GETPOST('dateendmonth', 'int'), GETPOST('dateendday', 'int'), GETPOST('dateendyear', 'int'));
  121. $object->priority = GETPOST('priority', 'int');
  122. $object->datenextrun = dol_mktime(GETPOST('datenextrunhour', 'int'), GETPOST('datenextrunmin', 'int'), 0, GETPOST('datenextrunmonth', 'int'), GETPOST('datenextrunday', 'int'), GETPOST('datenextrunyear', 'int'));
  123. $object->unitfrequency = GETPOST('unitfrequency', 'int');
  124. $object->frequency = GETPOST('nbfrequency', 'int');
  125. $object->maxrun = GETPOST('maxrun', 'int');
  126. $object->email_alert = GETPOST('email_alert');
  127. // Add cron task
  128. $result = $object->create($user);
  129. // test du Resultat de la requete
  130. if ($result < 0) {
  131. setEventMessages($object->error, $object->errors, 'errors');
  132. $action = 'create';
  133. } else {
  134. setEventMessages($langs->trans('CronSaveSucess'), null, 'mesgs');
  135. $action = '';
  136. }
  137. }
  138. // Save parameters
  139. if ($action == 'update' && $permissiontoadd) {
  140. $object->id = $id;
  141. $object->jobtype = GETPOST('jobtype');
  142. $object->label = GETPOST('label');
  143. $object->command = GETPOST('command');
  144. $object->classesname = GETPOST('classesname', 'alphanohtml');
  145. $object->objectname = GETPOST('objectname', 'aZ09');
  146. $object->methodename = GETPOST('methodename', 'aZ09');
  147. $object->params = GETPOST('params');
  148. $object->md5params = GETPOST('md5params');
  149. $object->module_name = GETPOST('module_name');
  150. $object->note_private = GETPOST('note', 'restricthtml');
  151. $object->datestart = dol_mktime(GETPOST('datestarthour', 'int'), GETPOST('datestartmin', 'int'), 0, GETPOST('datestartmonth', 'int'), GETPOST('datestartday', 'int'), GETPOST('datestartyear', 'int'));
  152. $object->dateend = dol_mktime(GETPOST('dateendhour', 'int'), GETPOST('dateendmin', 'int'), 0, GETPOST('dateendmonth', 'int'), GETPOST('dateendday', 'int'), GETPOST('dateendyear', 'int'));
  153. $object->priority = GETPOST('priority', 'int');
  154. $object->datenextrun = dol_mktime(GETPOST('datenextrunhour', 'int'), GETPOST('datenextrunmin', 'int'), 0, GETPOST('datenextrunmonth', 'int'), GETPOST('datenextrunday', 'int'), GETPOST('datenextrunyear', 'int'));
  155. $object->unitfrequency = GETPOST('unitfrequency', 'int');
  156. $object->frequency = GETPOST('nbfrequency', 'int');
  157. $object->maxrun = GETPOST('maxrun', 'int');
  158. $object->email_alert = GETPOST('email_alert');
  159. // Add cron task
  160. $result = $object->update($user);
  161. // test du Resultat de la requete
  162. if ($result < 0) {
  163. setEventMessages($object->error, $object->errors, 'errors');
  164. $action = 'edit';
  165. } else {
  166. setEventMessages($langs->trans('CronSaveSucess'), null, 'mesgs');
  167. $action = '';
  168. }
  169. }
  170. if ($action == 'activate' && $permissiontoadd) {
  171. $object->status = 1;
  172. // Add cron task
  173. $result = $object->update($user);
  174. // test du Resultat de la requete
  175. if ($result < 0) {
  176. setEventMessages($object->error, $object->errors, 'errors');
  177. $action = 'edit';
  178. } else {
  179. setEventMessages($langs->trans('CronSaveSucess'), null, 'mesgs');
  180. $action = '';
  181. }
  182. }
  183. if ($action == 'inactive' && $permissiontoadd) {
  184. $object->status = 0;
  185. $object->processing = 0;
  186. // Add cron task
  187. $result = $object->update($user);
  188. // test du Resultat de la requete
  189. if ($result < 0) {
  190. setEventMessages($object->error, $object->errors, 'errors');
  191. $action = 'edit';
  192. } else {
  193. setEventMessages($langs->trans('CronSaveSucess'), null, 'mesgs');
  194. $action = '';
  195. }
  196. }
  197. // Action clone object
  198. if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
  199. if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
  200. setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
  201. } else {
  202. $objectutil = dol_clone($object, 1); // To avoid to denaturate loaded object when setting some properties for clone or if createFromClone modifies the object. We use native clone to keep this->db valid.
  203. $result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id));
  204. if (is_object($result) || $result > 0) {
  205. $newid = 0;
  206. if (is_object($result)) {
  207. $newid = $result->id;
  208. } else {
  209. $newid = $result;
  210. }
  211. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$newid); // Open record of new object
  212. exit;
  213. } else {
  214. setEventMessages($objectutil->error, $objectutil->errors, 'errors');
  215. $action = '';
  216. }
  217. }
  218. }
  219. /*
  220. * View
  221. */
  222. $form = new Form($db);
  223. $formCron = new FormCron($db);
  224. llxHeader('', $langs->trans("CronTask"));
  225. $head = cron_prepare_head($object);
  226. if ($action == 'create') {
  227. print load_fiche_titre($langs->trans("CronTask"), '', 'title_setup');
  228. }
  229. if ($conf->use_javascript_ajax) {
  230. print "\n".'<script type="text/javascript">';
  231. print 'jQuery(document).ready(function () {
  232. function initfields()
  233. {
  234. if ($("#jobtype option:selected").val()==\'method\') {
  235. $(".blockmethod").show();
  236. $(".blockcommand").hide();
  237. }
  238. if ($("#jobtype option:selected").val()==\'command\') {
  239. $(".blockmethod").hide();
  240. $(".blockcommand").show();
  241. }
  242. }
  243. initfields();
  244. jQuery("#jobtype").change(function() {
  245. initfields();
  246. });
  247. })';
  248. print '</script>'."\n";
  249. }
  250. $formconfirm = '';
  251. if ($action == 'delete') {
  252. $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("CronDelete"), $langs->trans("CronConfirmDelete"), "confirm_delete", '', '', 1);
  253. $action = '';
  254. }
  255. if ($action == 'execute') {
  256. $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id.'&securitykey='.$securitykey, $langs->trans("CronExecute"), $langs->trans("CronConfirmExecute"), "confirm_execute", '', '', 1);
  257. $action = '';
  258. }
  259. // Clone confirmation
  260. if ($action == 'clone') {
  261. // Create an array for form
  262. $formquestion = array();
  263. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  264. }
  265. // Print form confirm
  266. print $formconfirm;
  267. /*
  268. * Create Template
  269. */
  270. if (empty($object->status) && $action != 'create') {
  271. setEventMessages($langs->trans("CronTaskInactive"), null, 'warnings');
  272. }
  273. if (($action == "create") || ($action == "edit")) {
  274. print '<form name="cronform" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  275. print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
  276. print '<input type="hidden" name="backtopage" value="'.GETPOST('backtopage').'">'."\n";
  277. if (!empty($object->id)) {
  278. print '<input type="hidden" name="action" value="update">'."\n";
  279. print '<input type="hidden" name="id" value="'.$object->id.'">'."\n";
  280. } else {
  281. print '<input type="hidden" name="action" value="add">'."\n";
  282. }
  283. if ($action == "edit") {
  284. print dol_get_fiche_head($head, 'card', $langs->trans("CronTask"), 0, 'cron');
  285. } else {
  286. print dol_get_fiche_head('');
  287. }
  288. print '<table class="border centpercent">';
  289. print '<tr><td class="fieldrequired titlefieldcreate">';
  290. print $langs->trans('CronLabel')."</td>";
  291. print '<td><input type="text" class="width200" name="label" value="'.dol_escape_htmltag($object->label).'"> ';
  292. print "</td>";
  293. print "<td>";
  294. print "</td>";
  295. print "</tr>\n";
  296. print '<tr><td class="fieldrequired">';
  297. print $langs->trans('CronType')."</td><td>";
  298. print $formCron->select_typejob('jobtype', $object->jobtype);
  299. print "</td>";
  300. print "<td>";
  301. print "</td>";
  302. print "</tr>\n";
  303. print '<tr class="blockmethod"><td>';
  304. print $langs->trans('CronModule')."</td><td>";
  305. print '<input type="text" class="width200" name="module_name" value="'.dol_escape_htmltag($object->module_name).'"> ';
  306. print "</td>";
  307. print "<td>";
  308. print $form->textwithpicto('', $langs->trans("CronModuleHelp"), 1, 'help');
  309. print "</td>";
  310. print "</tr>\n";
  311. print '<tr class="blockmethod"><td>';
  312. print $langs->trans('CronClassFile')."</td><td>";
  313. print '<input type="text" class="minwidth300" name="classesname" value="'.dol_escape_htmltag($object->classesname).'"> ';
  314. print "</td>";
  315. print "<td>";
  316. print $form->textwithpicto('', $langs->trans("CronClassFileHelp"), 1, 'help');
  317. print "</td>";
  318. print "</tr>\n";
  319. print '<tr class="blockmethod"><td>';
  320. print $langs->trans('CronObject')."</td><td>";
  321. print '<input type="text" class="width200" name="objectname" value="'.dol_escape_htmltag($object->objectname).'"> ';
  322. print "</td>";
  323. print "<td>";
  324. print $form->textwithpicto('', $langs->trans("CronObjectHelp"), 1, 'help');
  325. print "</td>";
  326. print "</tr>\n";
  327. print '<tr class="blockmethod"><td>';
  328. print $langs->trans('CronMethod')."</td><td>";
  329. print '<input type="text" class="minwidth300" name="methodename" value="'.dol_escape_htmltag($object->methodename).'" /> ';
  330. print "</td>";
  331. print "<td>";
  332. print $form->textwithpicto('', $langs->trans("CronMethodHelp"), 1, 'help');
  333. print "</td>";
  334. print "</tr>\n";
  335. print '<tr class="blockmethod"><td>';
  336. print $langs->trans('CronArgs')."</td><td>";
  337. print '<input type="text" class="quatrevingtpercent" name="params" value="'.$object->params.'" /> ';
  338. print "</td>";
  339. print "<td>";
  340. print $form->textwithpicto('', $langs->trans("CronArgsHelp"), 1, 'help');
  341. print "</td>";
  342. print "</tr>\n";
  343. print '<tr class="blockcommand"><td>';
  344. print $langs->trans('CronCommand')."</td><td>";
  345. print '<input type="text" class="minwidth150" name="command" value="'.$object->command.'" /> ';
  346. print "</td>";
  347. print "<td>";
  348. print $form->textwithpicto('', $langs->trans("CronCommandHelp"), 1, 'help');
  349. print "</td>";
  350. print "</tr>\n";
  351. print '<tr><td>';
  352. print $langs->trans('CronNote')."</td><td>";
  353. $doleditor = new DolEditor('note', $object->note_private, '', 160, 'dolibarr_notes', 'In', true, false, 0, ROWS_4, '90%');
  354. $doleditor->Create();
  355. print "</td>";
  356. print "<td>";
  357. print "</td>";
  358. print "</tr>\n";
  359. print '<tr class="blockemailalert"><td>';
  360. print $langs->trans('EmailIfError')."</td><td>";
  361. print '<input type="text" class="minwidth150" name="email_alert" value="'.dol_escape_htmltag($object->email_alert).'" /> ';
  362. print "</td>";
  363. print "<td>";
  364. //print $form->textwithpicto('', $langs->trans("CronCommandHelp"), 1, 'help');
  365. print "</td>";
  366. print "</tr>\n";
  367. print '<tr><td class="fieldrequired">';
  368. print $langs->trans('CronEvery')."</td>";
  369. print "<td>";
  370. print '<select name="nbfrequency">';
  371. for ($i = 1; $i <= 60; $i++) {
  372. if ($object->frequency == $i) {
  373. print "<option value='".$i."' selected>".$i."</option>";
  374. } else {
  375. print "<option value='".$i."'>".$i."</option>";
  376. }
  377. }
  378. print "</select>";
  379. $input = " <input type=\"radio\" name=\"unitfrequency\" value=\"60\" id=\"frequency_minute\" ";
  380. if ($object->unitfrequency == "60") {
  381. $input .= ' checked />';
  382. } else {
  383. $input .= ' />';
  384. }
  385. $input .= "<label for=\"frequency_minute\">".$langs->trans('Minutes')."</label>";
  386. print $input;
  387. $input = " <input type=\"radio\" name=\"unitfrequency\" value=\"3600\" id=\"frequency_heures\" ";
  388. if ($object->unitfrequency == "3600") {
  389. $input .= ' checked />';
  390. } else {
  391. $input .= ' />';
  392. }
  393. $input .= "<label for=\"frequency_heures\">".$langs->trans('Hours')."</label>";
  394. print $input;
  395. $input = " <input type=\"radio\" name=\"unitfrequency\" value=\"86400\" id=\"frequency_jours\" ";
  396. if ($object->unitfrequency == "86400") {
  397. $input .= ' checked />';
  398. } else {
  399. $input .= ' />';
  400. }
  401. $input .= "<label for=\"frequency_jours\">".$langs->trans('Days')."</label>";
  402. print $input;
  403. $input = " <input type=\"radio\" name=\"unitfrequency\" value=\"604800\" id=\"frequency_semaine\" ";
  404. if ($object->unitfrequency == "604800") {
  405. $input .= ' checked />';
  406. } else {
  407. $input .= ' />';
  408. }
  409. $input .= "<label for=\"frequency_semaine\">".$langs->trans('Weeks')."</label>";
  410. print $input;
  411. $input = " <input type=\"radio\" name=\"unitfrequency\" value=\"2678400\" id=\"frequency_month\" ";
  412. if ($object->unitfrequency == "2678400") {
  413. $input .= ' checked />';
  414. } else {
  415. $input .= ' />';
  416. }
  417. $input .= "<label for=\"frequency_month\">".$langs->trans('Monthly')."</label>";
  418. print $input;
  419. print "</td>";
  420. print "<td>";
  421. print "</td>";
  422. print "</tr>\n";
  423. print "<tr><td>";
  424. print $langs->trans('CronDtStart')."</td><td>";
  425. if (!empty($object->datestart)) {
  426. print $form->selectDate($object->datestart, 'datestart', 1, 1, '', "cronform");
  427. } else {
  428. print $form->selectDate(-1, 'datestart', 1, 1, 1, "cronform");
  429. }
  430. print "</td>";
  431. print "<td>";
  432. print "</td>";
  433. print "</tr>\n";
  434. print "<tr><td>";
  435. print $langs->trans('CronDtEnd')."</td><td>";
  436. if (!empty($object->dateend)) {
  437. print $form->selectDate($object->dateend, 'dateend', 1, 1, '', "cronform");
  438. } else {
  439. print $form->selectDate(-1, 'dateend', 1, 1, 1, "cronform");
  440. }
  441. print "</td>";
  442. print "<td>";
  443. print "</td>";
  444. print "</tr>\n";
  445. print "<tr><td>";
  446. print $langs->trans('CronPriority')."</td>";
  447. $priority = 0;
  448. if (!empty($object->priority)) {
  449. $priority = $object->priority;
  450. }
  451. print '<td><input type="text" class="width50" name="priority" value="'.$priority.'" /> ';
  452. print "</td>";
  453. print "<td>";
  454. print "</td>";
  455. print "</tr>\n";
  456. print '<tr><td>';
  457. $maxrun = '';
  458. if (!empty($object->maxrun)) {
  459. $maxrun = $object->maxrun;
  460. }
  461. print $langs->trans('CronMaxRun')."</td>";
  462. print '<td><input type="text" class="width50" name="maxrun" value="'.$maxrun.'" /> ';
  463. print "</td>";
  464. print "<td>";
  465. print "</td>";
  466. print "</tr>\n";
  467. print '<tr><td class="fieldrequired">';
  468. print $langs->trans('CronDtNextLaunch');
  469. //print ' ('.$langs->trans('CronFrom').')';
  470. print "</td><td>";
  471. if (!empty($object->datenextrun)) {
  472. print $form->selectDate($object->datenextrun, 'datenextrun', 1, 1, '', "cronform");
  473. } else {
  474. print $form->selectDate(-1, 'datenextrun', 1, 1, '', "cronform", 1, 1);
  475. }
  476. print "</td>";
  477. print "<td>";
  478. print "</td>";
  479. print "</tr>";
  480. print '</table>';
  481. print dol_get_fiche_end();
  482. print $form->buttonsSaveCancel();
  483. print "</form>\n";
  484. } else {
  485. /*
  486. * view card
  487. */
  488. $now = dol_now();
  489. print dol_get_fiche_head($head, 'card', $langs->trans("CronTask"), -1, 'cron');
  490. $linkback = '<a href="'.DOL_URL_ROOT.'/cron/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  491. $reg = array();
  492. if (preg_match('/:(.*)$/', $object->label, $reg)) {
  493. $langs->load($reg[1]);
  494. }
  495. $labeltoshow = preg_replace('/:.*$/', '', $object->label);
  496. $morehtmlref = '<div class="refidno">';
  497. $morehtmlref .= $langs->trans($labeltoshow);
  498. $morehtmlref .= '</div>';
  499. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
  500. // box add_jobs_box
  501. print '<div class="fichecenter">';
  502. print '<div class="fichehalfleft">';
  503. print '<div class="underbanner clearboth"></div>';
  504. print '<table class="border centpercent tableforfield">';
  505. /*print '<tr><td class="titlefield">';
  506. print $langs->trans('CronLabel')."</td>";
  507. print "<td>".$langs->trans($object->label);
  508. print "</td></tr>";*/
  509. print '<tr><td class="titlefield">';
  510. print $langs->trans('CronType')."</td><td>";
  511. print $formCron->select_typejob('jobtype', $object->jobtype, 1);
  512. print "</td></tr>";
  513. print '<tr class="blockmethod"><td>';
  514. print $langs->trans('CronModule')."</td><td>";
  515. print dol_escape_htmltag($object->module_name);
  516. print "</td></tr>";
  517. print '<tr class="blockmethod"><td>';
  518. print $langs->trans('CronClassFile')."</td><td>";
  519. print dol_escape_htmltag($object->classesname);
  520. print "</td></tr>";
  521. print '<tr class="blockmethod"><td>';
  522. print $langs->trans('CronObject')."</td><td>";
  523. print dol_escape_htmltag($object->objectname);
  524. print "</td></tr>";
  525. print '<tr class="blockmethod"><td>';
  526. print $langs->trans('CronMethod')."</td><td>";
  527. print dol_escape_htmltag($object->methodename);
  528. print "</td></tr>";
  529. print '<tr class="blockmethod"><td>';
  530. print $langs->trans('CronArgs')."</td><td>";
  531. print dol_escape_htmltag($object->params);
  532. print "</td></tr>";
  533. print '<tr class="blockcommand"><td>';
  534. print $langs->trans('CronCommand')."</td><td>";
  535. print dol_escape_htmltag($object->command);
  536. print "</td></tr>";
  537. print '<tr><td>';
  538. print $langs->trans('CronNote')."</td><td>";
  539. if (!is_null($object->note_private) && $object->note_private != '') {
  540. print $langs->trans($object->note_private);
  541. }
  542. print "</td></tr>";
  543. print '<tr class="blockemailalert"><td>';
  544. print $langs->trans('EmailIfError')."</td><td>";
  545. print dol_escape_htmltag($object->email_alert);
  546. print "</td></tr>";
  547. if (isModEnabled('multicompany')) {
  548. print '<tr><td>';
  549. print $langs->trans('Entity')."</td><td>";
  550. if (empty($object->entity)) {
  551. print img_picto($langs->trans("AllEntities"), 'entity', 'class="pictofixedwidth"').$langs->trans("AllEntities");
  552. } else {
  553. $mc->getInfo($object->entity);
  554. print img_picto($langs->trans("AllEntities"), 'entity', 'class="pictofixedwidth"').$mc->label;
  555. }
  556. print "</td></tr>";
  557. }
  558. print '</table>';
  559. print '</div>';
  560. print '<div class="fichehalfright">';
  561. print '<div class="underbanner clearboth"></div>';
  562. print '<table class="border centpercent tableforfield">';
  563. print '<tr><td class="titlefield">';
  564. print $langs->trans('CronEvery')."</td>";
  565. print "<td>";
  566. if ($object->unitfrequency == "60") {
  567. print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Minutes');
  568. }
  569. if ($object->unitfrequency == "3600") {
  570. print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Hours');
  571. }
  572. if ($object->unitfrequency == "86400") {
  573. print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Days');
  574. }
  575. if ($object->unitfrequency == "604800") {
  576. print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Weeks');
  577. }
  578. if ($object->unitfrequency == "2678400") {
  579. print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Month');
  580. }
  581. print "</td></tr>";
  582. print '<tr><td>';
  583. print $langs->trans('CronDtStart')."</td><td>";
  584. if (!empty($object->datestart)) {
  585. print $form->textwithpicto(dol_print_date($object->datestart, 'dayhoursec'), $langs->trans("CurrentTimeZone"));
  586. }
  587. print "</td></tr>";
  588. print "<tr><td>";
  589. print $langs->trans('CronDtEnd')."</td><td>";
  590. if (!empty($object->dateend)) {
  591. print $form->textwithpicto(dol_print_date($object->dateend, 'dayhoursec'), $langs->trans("CurrentTimeZone"));
  592. }
  593. print "</td></tr>";
  594. print "<tr><td>";
  595. print $langs->trans('CronPriority')."</td>";
  596. print "<td>".$object->priority;
  597. print "</td></tr>";
  598. print "<tr><td>";
  599. print $langs->trans('CronMaxRun')."</td>";
  600. print "<td>";
  601. print $object->maxrun > 0 ? $object->maxrun : '';
  602. print "</td></tr>";
  603. print "<tr><td>";
  604. print $langs->trans('CronNbRun')."</td>";
  605. print "<td>".$object->nbrun;
  606. print "</td></tr>";
  607. // Date next run (from)
  608. print '<tr><td>';
  609. print $langs->trans('CronDtNextLaunch');
  610. print ' ('.$langs->trans('CronFrom').')';
  611. print "</td><td>";
  612. if (!$object->status) {
  613. print $langs->trans("Disabled");
  614. } elseif (!empty($object->datenextrun)) {
  615. print img_picto('', 'object_calendarday').' '.$form->textwithpicto(dol_print_date($object->datenextrun, 'dayhoursec'), $langs->trans("CurrentTimeZone"));
  616. } else {
  617. print $langs->trans('CronNone');
  618. }
  619. if ($object->status == Cronjob::STATUS_ENABLED) {
  620. if ($object->maxrun && $object->nbrun >= $object->maxrun) {
  621. print img_warning($langs->trans("MaxRunReached"));
  622. } elseif ($object->datenextrun && $object->datenextrun < $now) {
  623. print img_warning($langs->trans("Late"));
  624. }
  625. }
  626. print "</td></tr>";
  627. print '</table>';
  628. print '<br>';
  629. print '<div class="underbanner clearboth"></div>';
  630. print '<table class="border centpercent tableforfield">';
  631. print '<tr><td class="titlefield">';
  632. print $langs->trans('CronDtLastLaunch')."</td><td>";
  633. if (!empty($object->datelastrun)) {
  634. print $form->textwithpicto(dol_print_date($object->datelastrun, 'dayhoursec'), $langs->trans("CurrentTimeZone"));
  635. } else {
  636. print $langs->trans('CronNone');
  637. }
  638. print "</td></tr>";
  639. print '<tr><td>';
  640. print $langs->trans('CronDtLastResult')."</td><td>";
  641. if (!empty($object->datelastresult)) {
  642. print $form->textwithpicto(dol_print_date($object->datelastresult, 'dayhoursec'), $langs->trans("CurrentTimeZone"));
  643. } else {
  644. if (empty($object->datelastrun)) {
  645. print $langs->trans('CronNone');
  646. } else {
  647. // In progress
  648. }
  649. }
  650. print "</td></tr>";
  651. print '<tr><td>';
  652. print $langs->trans('CronLastResult')."</td><td>";
  653. if ($object->lastresult) {
  654. print '<span class="error">';
  655. }
  656. print $object->lastresult;
  657. if ($object->lastresult) {
  658. print '</span>';
  659. }
  660. print "</td></tr>";
  661. print '<tr><td>';
  662. print $langs->trans('CronLastOutput')."</td><td>";
  663. print '<span class="small">'.nl2br($object->lastoutput).'</span>';
  664. print "</td></tr>";
  665. print '</table>';
  666. print '</div>';
  667. print '<div class="clearboth"></div>';
  668. print dol_get_fiche_end();
  669. print "\n\n".'<div class="tabsAction">'."\n";
  670. if (!$user->rights->cron->create) {
  671. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("Edit").'</a>';
  672. } else {
  673. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Edit").'</a>';
  674. }
  675. if ((empty($user->rights->cron->execute))) {
  676. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("CronExecute").'</a>';
  677. } elseif (empty($object->status)) {
  678. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("JobDisabled")).'">'.$langs->trans("CronExecute").'</a>';
  679. } else {
  680. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=execute&token='.newToken().'&id='.$object->id.(empty($conf->global->CRON_KEY) ? '' : '&securitykey='.urlencode($conf->global->CRON_KEY)).'">'.$langs->trans("CronExecute").'</a>';
  681. }
  682. if (!$user->rights->cron->create) {
  683. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("CronStatusActiveBtn").'/'.$langs->trans("CronStatusInactiveBtn").'</a>';
  684. } else {
  685. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=clone&token='.newToken().'&id='.$object->id.'">'.$langs->trans("ToClone").'</a>';
  686. if (empty($object->status)) {
  687. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=activate&token='.newToken().'&id='.$object->id.'">'.$langs->trans("CronStatusActiveBtn").'</a>';
  688. } else {
  689. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=inactive&id='.$object->id.'">'.$langs->trans("CronStatusInactiveBtn").'</a>';
  690. }
  691. }
  692. if (!$user->rights->cron->delete) {
  693. print '<a class="butActionDeleteRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("Delete").'</a>';
  694. } else {
  695. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Delete").'</a>';
  696. }
  697. print '</div>';
  698. print '<br>';
  699. }
  700. llxFooter();
  701. $db->close();