27 require
'../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
32 require_once DOL_DOCUMENT_ROOT.
"/cron/class/cronjob.class.php";
33 require_once DOL_DOCUMENT_ROOT.
"/core/class/html.formcron.class.php";
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/cron.lib.php';
37 $langs->loadLangs(array(
'admin',
'cron',
'members',
'bills'));
40 $action =
GETPOST(
'action',
'aZ09');
41 $confirm =
GETPOST(
'confirm',
'alpha');
42 $cancel =
GETPOST(
'cancel',
'alpha');
43 $backtopage =
GETPOST(
'backtopage',
'alpha');
44 $backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
46 $securitykey =
GETPOST(
'securitykey',
'alpha');
48 $permissiontoadd = $user->rights->cron->create;
50 if (!$user->rights->cron->create) {
61 $result = $object->fetch($id);
67 if (!empty($cancel)) {
68 if (!empty($id) && empty($backtopage)) {
72 header(
"Location: ".$backtopage);
75 header(
"Location: ".DOL_URL_ROOT.
'/cron/list.php');
82 if ($action ==
'confirm_delete' && $confirm ==
"yes" && $user->rights->cron->delete) {
83 $result = $object->delete($user);
89 Header(
"Location: ".DOL_URL_ROOT.
'/cron/list.php');
95 if ($action ==
'confirm_execute' && $confirm ==
"yes" && $user->rights->cron->execute) {
96 if (!empty($conf->global->CRON_KEY) && $conf->global->CRON_KEY != $securitykey) {
102 $result = $object->run_jobs($user->login);
108 $res = $object->reprogram_jobs($user->login, $now);
110 if ($object->lastresult > 0) {
125 if ($action ==
'add') {
126 $object->jobtype =
GETPOST(
'jobtype');
127 $object->label =
GETPOST(
'label');
128 $object->command =
GETPOST(
'command');
129 $object->classesname =
GETPOST(
'classesname',
'alphanohtml');
130 $object->objectname =
GETPOST(
'objectname',
'aZ09');
131 $object->methodename =
GETPOST(
'methodename',
'aZ09');
132 $object->params =
GETPOST(
'params');
133 $object->md5params =
GETPOST(
'md5params');
134 $object->module_name =
GETPOST(
'module_name');
135 $object->note_private =
GETPOST(
'note',
'restricthtml');
136 $object->datestart =
dol_mktime(
GETPOST(
'datestarthour',
'int'),
GETPOST(
'datestartmin',
'int'), 0,
GETPOST(
'datestartmonth',
'int'),
GETPOST(
'datestartday',
'int'),
GETPOST(
'datestartyear',
'int'));
137 $object->dateend =
dol_mktime(
GETPOST(
'dateendhour',
'int'),
GETPOST(
'dateendmin',
'int'), 0,
GETPOST(
'dateendmonth',
'int'),
GETPOST(
'dateendday',
'int'),
GETPOST(
'dateendyear',
'int'));
138 $object->priority =
GETPOST(
'priority',
'int');
139 $object->datenextrun =
dol_mktime(
GETPOST(
'datenextrunhour',
'int'),
GETPOST(
'datenextrunmin',
'int'), 0,
GETPOST(
'datenextrunmonth',
'int'),
GETPOST(
'datenextrunday',
'int'),
GETPOST(
'datenextrunyear',
'int'));
140 $object->unitfrequency =
GETPOST(
'unitfrequency',
'int');
141 $object->frequency =
GETPOST(
'nbfrequency',
'int');
142 $object->maxrun =
GETPOST(
'maxrun',
'int');
145 $result = $object->create($user);
158 if ($action ==
'update') {
160 $object->jobtype =
GETPOST(
'jobtype');
161 $object->label =
GETPOST(
'label');
162 $object->command =
GETPOST(
'command');
163 $object->classesname =
GETPOST(
'classesname',
'alphanohtml');
164 $object->objectname =
GETPOST(
'objectname',
'aZ09');
165 $object->methodename =
GETPOST(
'methodename',
'aZ09');
166 $object->params =
GETPOST(
'params');
167 $object->md5params =
GETPOST(
'md5params');
168 $object->module_name =
GETPOST(
'module_name');
169 $object->note_private =
GETPOST(
'note',
'restricthtml');
170 $object->datestart =
dol_mktime(
GETPOST(
'datestarthour',
'int'),
GETPOST(
'datestartmin',
'int'), 0,
GETPOST(
'datestartmonth',
'int'),
GETPOST(
'datestartday',
'int'),
GETPOST(
'datestartyear',
'int'));
171 $object->dateend =
dol_mktime(
GETPOST(
'dateendhour',
'int'),
GETPOST(
'dateendmin',
'int'), 0,
GETPOST(
'dateendmonth',
'int'),
GETPOST(
'dateendday',
'int'),
GETPOST(
'dateendyear',
'int'));
172 $object->priority =
GETPOST(
'priority',
'int');
173 $object->datenextrun =
dol_mktime(
GETPOST(
'datenextrunhour',
'int'),
GETPOST(
'datenextrunmin',
'int'), 0,
GETPOST(
'datenextrunmonth',
'int'),
GETPOST(
'datenextrunday',
'int'),
GETPOST(
'datenextrunyear',
'int'));
174 $object->unitfrequency =
GETPOST(
'unitfrequency',
'int');
175 $object->frequency =
GETPOST(
'nbfrequency',
'int');
176 $object->maxrun =
GETPOST(
'maxrun',
'int');
179 $result = $object->update($user);
191 if ($action ==
'activate') {
195 $result = $object->update($user);
207 if ($action ==
'inactive') {
209 $object->processing = 0;
212 $result = $object->update($user);
225 if ($action ==
'confirm_clone' && $confirm ==
'yes' && !empty($permissiontoadd)) {
226 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
231 $result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id));
232 if (is_object($result) || $result > 0) {
234 if (is_object($result)) {
235 $newid = $result->id;
239 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$newid);
257 llxHeader(
'', $langs->trans(
"CronTask"));
261 if ($action ==
'create') {
265 if ($conf->use_javascript_ajax) {
266 print
"\n".
'<script type="text/javascript">';
267 print
'jQuery(document).ready(function () {
268 function initfields()
270 if ($("#jobtype option:selected").val()==\'method\') {
271 $(".blockmethod").show();
272 $(".blockcommand").hide();
274 if ($("#jobtype option:selected").val()==\'command\') {
275 $(".blockmethod").hide();
276 $(".blockcommand").show();
280 jQuery("#jobtype").change(function() {
284 print
'</script>'.
"\n";
288 if ($action ==
'delete') {
289 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"CronDelete"), $langs->trans(
"CronConfirmDelete"),
"confirm_delete",
'',
'', 1);
294 if ($action ==
'execute') {
295 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id.
'&securitykey='.$securitykey, $langs->trans(
"CronExecute"), $langs->trans(
"CronConfirmExecute"),
"confirm_execute",
'',
'', 1);
301 if ($action ==
'clone') {
303 $formquestion = array();
304 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneAsk', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
315 if (empty($object->status) && $action !=
'create') {
319 if (($action ==
"create") || ($action ==
"edit")) {
320 print
'<form name="cronform" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
321 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
322 print
'<input type="hidden" name="backtopage" value="'.GETPOST(
'backtopage').
'">'.
"\n";
323 if (!empty($object->id)) {
324 print
'<input type="hidden" name="action" value="update">'.
"\n";
325 print
'<input type="hidden" name="id" value="'.$object->id.
'">'.
"\n";
327 print
'<input type="hidden" name="action" value="add">'.
"\n";
330 if ($action ==
"edit") {
336 print
'<table class="border centpercent">';
338 print
'<tr><td class="fieldrequired titlefieldcreate">';
339 print $langs->trans(
'CronLabel').
"</td>";
340 print
"<td><input type=\"text\" size=\"30\" name=\"label\" value=\"".$object->label.
"\" /> ";
346 print
'<tr><td class="fieldrequired">';
347 print $langs->trans(
'CronType').
"</td><td>";
348 print $formCron->select_typejob(
'jobtype', $object->jobtype);
354 print
'<tr class="blockmethod"><td>';
355 print $langs->trans(
'CronModule').
"</td><td>";
356 print
"<input type=\"text\" class=\"width200\" name=\"module_name\" value=\"".$object->module_name.
"\" /> ";
359 print
$form->textwithpicto(
'', $langs->trans(
"CronModuleHelp"), 1,
'help');
363 print
'<tr class="blockmethod"><td>';
364 print $langs->trans(
'CronClassFile').
"</td><td>";
365 print
'<input type="text" class="minwidth300" name="classesname" value="'.$object->classesname.
'" /> ';
368 print
$form->textwithpicto(
'', $langs->trans(
"CronClassFileHelp"), 1,
'help');
372 print
'<tr class="blockmethod"><td>';
373 print $langs->trans(
'CronObject').
"</td><td>";
374 print
"<input type=\"text\" class=\"width200\" name=\"objectname\" value=\"".$object->objectname.
"\" /> ";
377 print
$form->textwithpicto(
'', $langs->trans(
"CronObjectHelp"), 1,
'help');
381 print
'<tr class="blockmethod"><td>';
382 print $langs->trans(
'CronMethod').
"</td><td>";
383 print
'<input type="text" class="minwidth300" name="methodename" value="'.$object->methodename.
'" /> ';
386 print
$form->textwithpicto(
'', $langs->trans(
"CronMethodHelp"), 1,
'help');
390 print
'<tr class="blockmethod"><td>';
391 print $langs->trans(
'CronArgs').
"</td><td>";
392 print
'<input type="text" class="quatrevingtpercent" name="params" value="'.$object->params.
'" /> ';
395 print
$form->textwithpicto(
'', $langs->trans(
"CronArgsHelp"), 1,
'help');
399 print
'<tr class="blockcommand"><td>';
400 print $langs->trans(
'CronCommand').
"</td><td>";
401 print
'<input type="text" class="minwidth150" name="command" value="'.$object->command.
'" /> ';
404 print
$form->textwithpicto(
'', $langs->trans(
"CronCommandHelp"), 1,
'help');
409 print $langs->trans(
'CronNote').
"</td><td>";
410 $doleditor =
new DolEditor(
'note', $object->note_private,
'', 160,
'dolibarr_notes',
'In',
true,
false, 0, ROWS_4,
'90%');
411 $doleditor->Create();
417 print
'<tr><td class="fieldrequired">';
418 print $langs->trans(
'CronEvery').
"</td>";
420 print
'<select name="nbfrequency">';
421 for ($i = 1; $i <= 60; $i++) {
422 if ($object->frequency == $i) {
423 print
"<option value='".$i.
"' selected>".$i.
"</option>";
425 print
"<option value='".$i.
"'>".$i.
"</option>";
429 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"60\" id=\"frequency_minute\" ";
430 if ($object->unitfrequency ==
"60") {
431 $input .=
' checked />';
435 $input .=
"<label for=\"frequency_minute\">".$langs->trans(
'Minutes').
"</label>";
438 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"3600\" id=\"frequency_heures\" ";
439 if ($object->unitfrequency ==
"3600") {
440 $input .=
' checked />';
444 $input .=
"<label for=\"frequency_heures\">".$langs->trans(
'Hours').
"</label>";
447 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"86400\" id=\"frequency_jours\" ";
448 if ($object->unitfrequency ==
"86400") {
449 $input .=
' checked />';
453 $input .=
"<label for=\"frequency_jours\">".$langs->trans(
'Days').
"</label>";
456 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"604800\" id=\"frequency_semaine\" ";
457 if ($object->unitfrequency ==
"604800") {
458 $input .=
' checked />';
462 $input .=
"<label for=\"frequency_semaine\">".$langs->trans(
'Weeks').
"</label>";
470 print $langs->trans(
'CronDtStart').
"</td><td>";
471 if (!empty($object->datestart)) {
472 print
$form->selectDate($object->datestart,
'datestart', 1, 1,
'',
"cronform");
474 print
$form->selectDate(-1,
'datestart', 1, 1,
'',
"cronform");
482 print $langs->trans(
'CronDtEnd').
"</td><td>";
483 if (!empty($object->dateend)) {
484 print
$form->selectDate($object->dateend,
'dateend', 1, 1,
'',
"cronform");
486 print
$form->selectDate(-1,
'dateend', 1, 1,
'',
"cronform");
494 print $langs->trans(
'CronPriority').
"</td>";
496 if (!empty($object->priority)) {
497 $priority = $object->priority;
499 print
"<td><input type=\"text\" size=\"2\" name=\"priority\" value=\"".$priority.
"\" /> ";
507 if (!empty($object->maxrun)) {
508 $maxrun = $object->maxrun;
510 print $langs->trans(
'CronMaxRun').
"</td>";
511 print
"<td><input type=\"text\" size=\"2\" name=\"maxrun\" value=\"".$maxrun.
"\" /> ";
517 print
'<tr><td class="fieldrequired">';
518 print $langs->trans(
'CronDtNextLaunch');
519 print
' ('.$langs->trans(
'CronFrom').
')';
521 if (!empty($object->datenextrun)) {
522 print
$form->selectDate($object->datenextrun,
'datenextrun', 1, 1,
'',
"cronform");
524 print
$form->selectDate(-1,
'datenextrun', 1, 1,
'',
"cronform");
535 print
$form->buttonsSaveCancel();
546 $linkback =
'<a href="'.DOL_URL_ROOT.
'/cron/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
548 $morehtmlref =
'<div class="refidno">';
549 $morehtmlref .= $langs->trans($object->label);
550 $morehtmlref .=
'</div>';
552 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref);
555 print
'<div class="fichecenter">';
556 print
'<div class="fichehalfleft">';
558 print
'<div class="underbanner clearboth"></div>';
559 print
'<table class="border centpercent tableforfield">';
566 print
'<tr><td class="titlefield">';
567 print $langs->trans(
'CronType').
"</td><td>";
568 print $formCron->select_typejob(
'jobtype', $object->jobtype, 1);
571 print
'<tr class="blockmethod"><td>';
572 print $langs->trans(
'CronModule').
"</td><td>";
573 print $object->module_name;
576 print
'<tr class="blockmethod"><td>';
577 print $langs->trans(
'CronClassFile').
"</td><td>";
578 print $object->classesname;
581 print
'<tr class="blockmethod"><td>';
582 print $langs->trans(
'CronObject').
"</td><td>";
583 print $object->objectname;
586 print
'<tr class="blockmethod"><td>';
587 print $langs->trans(
'CronMethod').
"</td><td>";
588 print $object->methodename;
591 print
'<tr class="blockmethod"><td>';
592 print $langs->trans(
'CronArgs').
"</td><td>";
593 print $object->params;
596 print
'<tr class="blockcommand"><td>';
597 print $langs->trans(
'CronCommand').
"</td><td>";
598 print $object->command;
602 print $langs->trans(
'CronNote').
"</td><td>";
603 if (!is_null($object->note_private) && $object->note_private !=
'') {
604 print $langs->trans($object->note_private);
608 if (!empty($conf->multicompany->enabled)) {
610 print $langs->trans(
'Entity').
"</td><td>";
611 if (empty($object->entity)) {
612 print
img_picto($langs->trans(
"AllEntities"),
'entity',
'class="pictofixedwidth"').$langs->trans(
"AllEntities");
614 $mc->getInfo($object->entity);
615 print
img_picto($langs->trans(
"AllEntities"),
'entity',
'class="pictofixedwidth"').$mc->label;
623 print
'<div class="fichehalfright">';
625 print
'<div class="underbanner clearboth"></div>';
626 print
'<table class="border centpercent tableforfield">';
628 print
'<tr><td class="titlefield">';
629 print $langs->trans(
'CronEvery').
"</td>";
631 if ($object->unitfrequency ==
"60") {
632 print $langs->trans(
'CronEach').
" ".($object->frequency).
" ".$langs->trans(
'Minutes');
634 if ($object->unitfrequency ==
"3600") {
635 print $langs->trans(
'CronEach').
" ".($object->frequency).
" ".$langs->trans(
'Hours');
637 if ($object->unitfrequency ==
"86400") {
638 print $langs->trans(
'CronEach').
" ".($object->frequency).
" ".$langs->trans(
'Days');
640 if ($object->unitfrequency ==
"604800") {
641 print $langs->trans(
'CronEach').
" ".($object->frequency).
" ".$langs->trans(
'Weeks');
646 print $langs->trans(
'CronDtStart').
"</td><td>";
647 if (!empty($object->datestart)) {
648 print
$form->textwithpicto(
dol_print_date($object->datestart,
'dayhoursec'), $langs->trans(
"CurrentTimeZone"));
653 print $langs->trans(
'CronDtEnd').
"</td><td>";
654 if (!empty($object->dateend)) {
655 print
$form->textwithpicto(
dol_print_date($object->dateend,
'dayhoursec'), $langs->trans(
"CurrentTimeZone"));
660 print $langs->trans(
'CronPriority').
"</td>";
661 print
"<td>".$object->priority;
665 print $langs->trans(
'CronMaxRun').
"</td>";
667 print $object->maxrun > 0 ? $object->maxrun :
'';
671 print $langs->trans(
'CronNbRun').
"</td>";
672 print
"<td>".$object->nbrun;
677 print $langs->trans(
'CronDtNextLaunch');
678 print
' ('.$langs->trans(
'CronFrom').
')';
680 if (!$object->status) {
681 print $langs->trans(
"Disabled");
682 } elseif (!empty($object->datenextrun)) {
683 print
img_picto(
'',
'object_calendarday').
' '.
$form->textwithpicto(
dol_print_date($object->datenextrun,
'dayhoursec'), $langs->trans(
"CurrentTimeZone"));
685 print $langs->trans(
'CronNone');
687 if ($object->status == Cronjob::STATUS_ENABLED) {
688 if ($object->maxrun && $object->nbrun >= $object->maxrun) {
690 } elseif ($object->datenextrun && $object->datenextrun < $now) {
702 print
'<div class="underbanner clearboth"></div>';
703 print
'<table class="border centpercent tableforfield">';
705 print
'<tr><td class="titlefield">';
706 print $langs->trans(
'CronDtLastLaunch').
"</td><td>";
707 if (!empty($object->datelastrun)) {
708 print
$form->textwithpicto(
dol_print_date($object->datelastrun,
'dayhoursec'), $langs->trans(
"CurrentTimeZone"));
710 print $langs->trans(
'CronNone');
715 print $langs->trans(
'CronDtLastResult').
"</td><td>";
716 if (!empty($object->datelastresult)) {
717 print
$form->textwithpicto(
dol_print_date($object->datelastresult,
'dayhoursec'), $langs->trans(
"CurrentTimeZone"));
719 if (empty($object->datelastrun)) {
720 print $langs->trans(
'CronNone');
728 print $langs->trans(
'CronLastResult').
"</td><td>";
729 if ($object->lastresult) {
730 print
'<span class="error">';
732 print $object->lastresult;
733 if ($object->lastresult) {
739 print $langs->trans(
'CronLastOutput').
"</td><td>";
740 print nl2br($object->lastoutput);
747 print
'<div class="clearboth"></div>';
753 print
"\n\n<div class=\"tabsAction\">\n";
754 if (!$user->rights->cron->create) {
755 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"Edit").
'</a>';
757 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.
newToken().
'&id='.$object->id.
'">'.$langs->trans(
"Edit").
'</a>';
760 if ((empty($user->rights->cron->execute))) {
761 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"CronExecute").
'</a>';
762 } elseif (empty($object->status)) {
763 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"JobDisabled")).
'">'.$langs->trans(
"CronExecute").
'</a>';
765 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=execute&token='.
newToken().
'&id='.$object->id.(empty($conf->global->CRON_KEY) ?
'' :
'&securitykey='.$conf->global->CRON_KEY).
'">'.$langs->trans(
"CronExecute").
'</a>';
768 if (!$user->rights->cron->create) {
769 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"CronStatusActiveBtn").
'/'.$langs->trans(
"CronStatusInactiveBtn").
'</a>';
771 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=clone&token='.
newToken().
'&id='.$object->id.
'">'.$langs->trans(
"ToClone").
'</a>';
773 if (empty($object->status)) {
774 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=activate&token='.
newToken().
'&id='.$object->id.
'">'.$langs->trans(
"CronStatusActiveBtn").
'</a>';
776 print
'<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=inactive&id='.$object->id.
'">'.$langs->trans(
"CronStatusInactiveBtn").
'</a>';
780 if (!$user->rights->cron->delete) {
781 print
'<a class="butActionDeleteRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"Delete").
'</a>';
783 print
'<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.
newToken().
'&id='.$object->id.
'">'.$langs->trans(
"Delete").
'</a>';