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'));
42 $action =
GETPOST(
'action',
'aZ09');
43 $confirm =
GETPOST(
'confirm',
'alpha');
44 $cancel =
GETPOST(
'cancel',
'alpha');
45 $backtopage =
GETPOST(
'backtopage',
'alpha');
46 $backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
48 $securitykey =
GETPOST(
'securitykey',
'alpha');
58 $result = $object->fetch($id);
67 if (!empty($id) && empty($backtopage))
73 header(
"Location: ".$backtopage);
76 header(
"Location: ".DOL_URL_ROOT.
'/cron/list.php');
83 if ($action ==
'confirm_delete' && $confirm ==
"yes" && $user->rights->cron->delete)
85 $result = $object->delete($user);
92 Header(
"Location: ".DOL_URL_ROOT.
'/cron/list.php');
98 if ($action ==
'confirm_execute' && $confirm ==
"yes" && $user->rights->cron->execute)
100 if (!empty($conf->global->CRON_KEY) && $conf->global->CRON_KEY != $securitykey)
107 $result = $object->run_jobs($user->login);
114 $res = $object->reprogram_jobs($user->login, $now);
117 if ($object->lastresult > 0)
setEventMessages($langs->trans(
"JobFinished"), null,
'warnings');
129 if ($action ==
'add')
131 $object->jobtype =
GETPOST(
'jobtype');
132 $object->label =
GETPOST(
'label');
133 $object->command =
GETPOST(
'command');
134 $object->classesname =
GETPOST(
'classesname',
'alphanohtml');
135 $object->objectname =
GETPOST(
'objectname',
'aZ09');
136 $object->methodename =
GETPOST(
'methodename',
'aZ09');
137 $object->params =
GETPOST(
'params');
138 $object->md5params =
GETPOST(
'md5params');
139 $object->module_name =
GETPOST(
'module_name');
140 $object->note_private =
GETPOST(
'note',
'restricthtml');
141 $object->datestart =
dol_mktime(
GETPOST(
'datestarthour',
'int'),
GETPOST(
'datestartmin',
'int'), 0,
GETPOST(
'datestartmonth',
'int'),
GETPOST(
'datestartday',
'int'),
GETPOST(
'datestartyear',
'int'));
142 $object->dateend =
dol_mktime(
GETPOST(
'dateendhour',
'int'),
GETPOST(
'dateendmin',
'int'), 0,
GETPOST(
'dateendmonth',
'int'),
GETPOST(
'dateendday',
'int'),
GETPOST(
'dateendyear',
'int'));
143 $object->priority =
GETPOST(
'priority',
'int');
144 $object->datenextrun =
dol_mktime(
GETPOST(
'datenextrunhour',
'int'),
GETPOST(
'datenextrunmin',
'int'), 0,
GETPOST(
'datenextrunmonth',
'int'),
GETPOST(
'datenextrunday',
'int'),
GETPOST(
'datenextrunyear',
'int'));
145 $object->unitfrequency =
GETPOST(
'unitfrequency',
'int');
146 $object->frequency =
GETPOST(
'nbfrequency',
'int');
147 $object->maxrun =
GETPOST(
'maxrun',
'int');
150 $result = $object->create($user);
163 if ($action ==
'update')
166 $object->jobtype =
GETPOST(
'jobtype');
167 $object->label =
GETPOST(
'label');
168 $object->command =
GETPOST(
'command');
169 $object->classesname =
GETPOST(
'classesname',
'alphanohtml');
170 $object->objectname =
GETPOST(
'objectname',
'aZ09');
171 $object->methodename =
GETPOST(
'methodename',
'aZ09');
172 $object->params =
GETPOST(
'params');
173 $object->md5params =
GETPOST(
'md5params');
174 $object->module_name =
GETPOST(
'module_name');
175 $object->note_private =
GETPOST(
'note',
'restricthtml');
176 $object->datestart =
dol_mktime(
GETPOST(
'datestarthour',
'int'),
GETPOST(
'datestartmin',
'int'), 0,
GETPOST(
'datestartmonth',
'int'),
GETPOST(
'datestartday',
'int'),
GETPOST(
'datestartyear',
'int'));
177 $object->dateend =
dol_mktime(
GETPOST(
'dateendhour',
'int'),
GETPOST(
'dateendmin',
'int'), 0,
GETPOST(
'dateendmonth',
'int'),
GETPOST(
'dateendday',
'int'),
GETPOST(
'dateendyear',
'int'));
178 $object->priority =
GETPOST(
'priority',
'int');
179 $object->datenextrun =
dol_mktime(
GETPOST(
'datenextrunhour',
'int'),
GETPOST(
'datenextrunmin',
'int'), 0,
GETPOST(
'datenextrunmonth',
'int'),
GETPOST(
'datenextrunday',
'int'),
GETPOST(
'datenextrunyear',
'int'));
180 $object->unitfrequency =
GETPOST(
'unitfrequency',
'int');
181 $object->frequency =
GETPOST(
'nbfrequency',
'int');
182 $object->maxrun =
GETPOST(
'maxrun',
'int');
185 $result = $object->update($user);
197 if ($action ==
'activate')
202 $result = $object->update($user);
214 if ($action ==
'inactive')
217 $object->processing = 0;
220 $result = $object->update($user);
238 $form =
new Form($db);
241 llxHeader(
'', $langs->trans(
"CronTask"));
243 if ($action ==
'edit' || empty($action) || $action ==
'delete' || $action ==
'execute')
246 } elseif ($action ==
'create')
251 if ($conf->use_javascript_ajax)
253 print "\n".
'<script type="text/javascript" language="javascript">';
254 print 'jQuery(document).ready(function () {
255 function initfields()
257 if ($("#jobtype option:selected").val()==\'method\') {
258 $(".blockmethod").show();
259 $(".blockcommand").hide();
261 if ($("#jobtype option:selected").val()==\'command\') {
262 $(".blockmethod").hide();
263 $(".blockcommand").show();
267 jQuery("#jobtype").change(function() {
271 print '</script>'.
"\n";
274 if ($action ==
'delete')
276 print $form->formconfirm(
$_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"CronDelete"), $langs->trans(
"CronConfirmDelete"),
"confirm_delete",
'',
'', 1);
281 if ($action ==
'execute') {
282 print $form->formconfirm(
$_SERVER[
'PHP_SELF'].
"?id=".$object->id.
'&securitykey='.$securitykey, $langs->trans(
"CronExecute"), $langs->trans(
"CronConfirmExecute"),
"confirm_execute",
'',
'', 1);
293 if (empty($object->status) && $action !=
'create')
298 if (($action ==
"create") || ($action ==
"edit"))
300 print '<form name="cronform" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
301 print '<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
302 print '<input type="hidden" name="backtopage" value="'.GETPOST(
'backtopage').
'">'.
"\n";
303 if (!empty($object->id)) {
304 print '<input type="hidden" name="action" value="update">'.
"\n";
305 print '<input type="hidden" name="id" value="'.$object->id.
'">'.
"\n";
307 print '<input type="hidden" name="action" value="add">'.
"\n";
313 print '<table class="border centpercent">';
315 print '<tr><td class="fieldrequired titlefieldcreate">';
316 print $langs->trans(
'CronLabel').
"</td>";
317 print "<td><input type=\"text\" size=\"30\" name=\"label\" value=\"".$object->label.
"\" /> ";
323 print '<tr><td class="fieldrequired">';
324 print $langs->trans(
'CronType').
"</td><td>";
325 print $formCron->select_typejob(
'jobtype', $object->jobtype);
331 print '<tr class="blockmethod"><td>';
332 print $langs->trans(
'CronModule').
"</td><td>";
333 print "<input type=\"text\" size=\"20\" name=\"module_name\" value=\"".$object->module_name.
"\" /> ";
336 print $form->textwithpicto(
'', $langs->trans(
"CronModuleHelp"), 1,
'help');
340 print '<tr class="blockmethod"><td>';
341 print $langs->trans(
'CronClassFile').
"</td><td>";
342 print '<input type="text" class="minwidth300" name="classesname" value="'.$object->classesname.
'" /> ';
345 print $form->textwithpicto(
'', $langs->trans(
"CronClassFileHelp"), 1,
'help');
349 print '<tr class="blockmethod"><td>';
350 print $langs->trans(
'CronObject').
"</td><td>";
351 print "<input type=\"text\" size=\"20\" name=\"objectname\" value=\"".$object->objectname.
"\" /> ";
354 print $form->textwithpicto(
'', $langs->trans(
"CronObjectHelp"), 1,
'help');
358 print '<tr class="blockmethod"><td>';
359 print $langs->trans(
'CronMethod').
"</td><td>";
360 print '<input type="text" class="minwidth300" name="methodename" value="'.$object->methodename.
'" /> ';
363 print $form->textwithpicto(
'', $langs->trans(
"CronMethodHelp"), 1,
'help');
367 print '<tr class="blockmethod"><td>';
368 print $langs->trans(
'CronArgs').
"</td><td>";
369 print "<input type=\"text\" class=\"quatrevingtpercent\" name=\"params\" value=\"".$object->params.
"\" /> ";
372 print $form->textwithpicto(
'', $langs->trans(
"CronArgsHelp"), 1,
'help');
376 print '<tr class="blockcommand"><td>';
377 print $langs->trans(
'CronCommand').
"</td><td>";
378 print "<input type=\"text\" size=\"50\" name=\"command\" value=\"".$object->command.
"\" /> ";
381 print $form->textwithpicto(
'', $langs->trans(
"CronCommandHelp"), 1,
'help');
386 print $langs->trans(
'CronNote').
"</td><td>";
387 $doleditor =
new DolEditor(
'note', $object->note_private,
'', 160,
'dolibarr_notes',
'In',
true,
false, 0, ROWS_4,
'90%');
388 $doleditor->Create();
394 print '<tr><td class="fieldrequired">';
395 print $langs->trans(
'CronEvery').
"</td>";
397 print '<select name="nbfrequency">';
398 for ($i = 1; $i <= 60; $i++)
400 if ($object->frequency == $i)
402 print "<option value='".$i.
"' selected>".$i.
"</option>";
404 print "<option value='".$i.
"'>".$i.
"</option>";
408 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"60\" id=\"frequency_minute\" ";
409 if ($object->unitfrequency ==
"60")
411 $input .=
' checked />';
415 $input .=
"<label for=\"frequency_minute\">".$langs->trans(
'Minutes').
"</label>";
418 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"3600\" id=\"frequency_heures\" ";
419 if ($object->unitfrequency ==
"3600") {
420 $input .=
' checked />';
424 $input .=
"<label for=\"frequency_heures\">".$langs->trans(
'Hours').
"</label>";
427 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"86400\" id=\"frequency_jours\" ";
428 if ($object->unitfrequency ==
"86400") {
429 $input .=
' checked />';
433 $input .=
"<label for=\"frequency_jours\">".$langs->trans(
'Days').
"</label>";
436 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"604800\" id=\"frequency_semaine\" ";
437 if ($object->unitfrequency ==
"604800") {
438 $input .=
' checked />';
442 $input .=
"<label for=\"frequency_semaine\">".$langs->trans(
'Weeks').
"</label>";
450 print $langs->trans(
'CronDtStart').
"</td><td>";
451 if (!empty($object->datestart))
453 print $form->selectDate($object->datestart,
'datestart', 1, 1,
'',
"cronform");
455 print $form->selectDate(
'',
'datestart', 1, 1,
'',
"cronform");
463 print $langs->trans(
'CronDtEnd').
"</td><td>";
464 if (!empty($object->dateend)) {
465 print $form->selectDate($object->dateend,
'dateend', 1, 1,
'',
"cronform");
467 print $form->selectDate(-1,
'dateend', 1, 1, 1,
"cronform");
475 print $langs->trans(
'CronPriority').
"</td>";
477 if (!empty($object->priority)) {
478 $priority = $object->priority;
480 print "<td><input type=\"text\" size=\"2\" name=\"priority\" value=\"".$priority.
"\" /> ";
488 if (!empty($object->maxrun)) {
489 $maxrun = $object->maxrun;
491 print $langs->trans(
'CronMaxRun').
"</td>";
492 print "<td><input type=\"text\" size=\"2\" name=\"maxrun\" value=\"".$maxrun.
"\" /> ";
499 print $langs->trans(
'CronDtNextLaunch');
500 print ' ('.$langs->trans(
'CronFrom').
')';
502 if (!empty($object->datenextrun))
504 print $form->selectDate($object->datenextrun,
'datenextrun', 1, 1,
'',
"cronform");
506 print $form->selectDate(-1,
'datenextrun', 1, 1,
'',
"cronform");
517 print '<div align="center">';
518 print '<input type="submit" name="save" class="button button-save" value="'.$langs->trans(
"Save").
'">';
519 print ' ';
520 print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
532 $linkback =
'<a href="'.DOL_URL_ROOT.
'/cron/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
534 $morehtmlref =
'<div class="refidno">';
535 $morehtmlref .=
'</div>';
537 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref);
540 print '<div class="fichecenter">';
541 print '<div class="underbanner clearboth"></div>';
542 print '<table class="border centpercent tableforfield">';
544 print '<tr><td class="titlefield">';
545 print $langs->trans(
'CronLabel').
"</td>";
546 print "<td>".$langs->trans($object->label);
550 print $langs->trans(
'CronType').
"</td><td>";
551 print $formCron->select_typejob(
'jobtype', $object->jobtype, 1);
554 print '<tr class="blockmethod"><td>';
555 print $langs->trans(
'CronModule').
"</td><td>";
556 print $object->module_name;
559 print '<tr class="blockmethod"><td>';
560 print $langs->trans(
'CronClassFile').
"</td><td>";
561 print $object->classesname;
564 print '<tr class="blockmethod"><td>';
565 print $langs->trans(
'CronObject').
"</td><td>";
566 print $object->objectname;
569 print '<tr class="blockmethod"><td>';
570 print $langs->trans(
'CronMethod').
"</td><td>";
571 print $object->methodename;
574 print '<tr class="blockmethod"><td>';
575 print $langs->trans(
'CronArgs').
"</td><td>";
576 print $object->params;
579 print '<tr class="blockcommand"><td>';
580 print $langs->trans(
'CronCommand').
"</td><td>";
581 print $object->command;
585 print $langs->trans(
'CronNote').
"</td><td>";
586 if (!is_null($object->note_private) && $object->note_private !=
'') {
587 print $langs->trans($object->note_private);
591 if (!empty($conf->multicompany->enabled))
594 print $langs->trans(
'Entity').
"</td><td>";
595 if (!$object->entity)
597 print $langs->trans(
"AllEntities");
599 $mc->getInfo($object->entity);
611 print '<div class="fichecenter">';
612 print '<div class="underbanner clearboth"></div>';
613 print '<table class="border centpercent tableforfield">';
615 print '<tr><td class="titlefield">';
616 print $langs->trans(
'CronEvery').
"</td>";
618 if ($object->unitfrequency ==
"60")
print $langs->trans(
'CronEach').
" ".($object->frequency).
" ".$langs->trans(
'Minutes');
619 if ($object->unitfrequency ==
"3600")
print $langs->trans(
'CronEach').
" ".($object->frequency).
" ".$langs->trans(
'Hours');
620 if ($object->unitfrequency ==
"86400")
print $langs->trans(
'CronEach').
" ".($object->frequency).
" ".$langs->trans(
'Days');
621 if ($object->unitfrequency ==
"604800")
print $langs->trans(
'CronEach').
" ".($object->frequency).
" ".$langs->trans(
'Weeks');
625 print $langs->trans(
'CronDtStart').
"</td><td>";
626 if (!empty($object->datestart)) {
print $form->textwithpicto(
dol_print_date($object->datestart,
'dayhoursec'), $langs->trans(
"CurrentTimeZone")); }
630 print $langs->trans(
'CronDtEnd').
"</td><td>";
631 if (!empty($object->dateend)) {
print $form->textwithpicto(
dol_print_date($object->dateend,
'dayhoursec'), $langs->trans(
"CurrentTimeZone")); }
635 print $langs->trans(
'CronPriority').
"</td>";
636 print "<td>".$object->priority;
640 print $langs->trans(
'CronMaxRun').
"</td>";
642 print $object->maxrun > 0 ? $object->maxrun :
'';
646 print $langs->trans(
'CronNbRun').
"</td>";
647 print "<td>".$object->nbrun;
652 print $langs->trans(
'CronDtNextLaunch');
653 print ' ('.$langs->trans(
'CronFrom').
')';
655 if (!$object->status)
print $langs->trans(
"Disabled");
656 elseif (!empty($object->datenextrun)) {
print img_picto(
'',
'object_calendarday').
' '.$form->textwithpicto(
dol_print_date($object->datenextrun,
'dayhoursec'), $langs->trans(
"CurrentTimeZone")); }
else {
print $langs->trans(
'CronNone'); }
657 if ($object->status == Cronjob::STATUS_ENABLED)
659 if ($object->maxrun && $object->nbrun >= $object->maxrun)
print img_warning($langs->trans(
"MaxRunReached"));
660 elseif ($object->datenextrun && $object->datenextrun < $now)
print img_warning($langs->trans("Late"));
669 print '<div class="fichecenter">';
670 print '<div class="underbanner clearboth"></div>';
671 print '<table class="border centpercent tableforfield">';
673 print '<tr><td class="titlefield">';
674 print $langs->trans('CronDtLastLaunch')."</td><td>";
675 if (!empty($object->datelastrun)) {
print $form->textwithpicto(
dol_print_date($object->datelastrun,
'dayhoursec'), $langs->trans(
"CurrentTimeZone")); }
else {
print $langs->trans(
'CronNone'); }
679 print $langs->trans(
'CronDtLastResult').
"</td><td>";
680 if (!empty($object->datelastresult)) {
print $form->textwithpicto(
dol_print_date($object->datelastresult,
'dayhoursec'), $langs->trans(
"CurrentTimeZone")); }
else {
print $langs->trans(
'CronNone'); }
684 print $langs->trans(
'CronLastResult').
"</td><td>";
685 if ($object->lastresult)
print '<span class="error">';
686 print $object->lastresult;
687 if ($object->lastresult)
print '</span>';
691 print $langs->trans(
'CronLastOutput').
"</td><td>";
692 print nl2br($object->lastoutput);
701 print "\n\n<div class=\"tabsAction\">\n";
702 if (!$user->rights->cron->create) {
703 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"Edit").
'</a>';
705 print '<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&id='.$object->id.
'">'.$langs->trans(
"Edit").
'</a>';
708 if ((empty($user->rights->cron->execute)))
710 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"CronExecute").
'</a>';
711 } elseif (empty($object->status))
713 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"JobDisabled")).
'">'.$langs->trans(
"CronExecute").
'</a>';
715 print '<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=execute&id='.$object->id.(empty($conf->global->CRON_KEY) ?
'' :
'&securitykey='.$conf->global->CRON_KEY).
'">'.$langs->trans(
"CronExecute").
'</a>';
718 if (!$user->rights->cron->create) {
719 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"CronStatusActiveBtn").
'/'.$langs->trans(
"CronStatusInactiveBtn").
'</a>';
721 if (empty($object->status)) {
722 print '<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=activate&id='.$object->id.
'">'.$langs->trans(
"CronStatusActiveBtn").
'</a>';
724 print '<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=inactive&id='.$object->id.
'">'.$langs->trans(
"CronStatusInactiveBtn").
'</a>';
728 if (!$user->rights->cron->delete) {
729 print '<a class="butActionDeleteRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"Delete").
'</a>';
731 print '<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.
newToken().
'&id='.$object->id.
'">'.$langs->trans(
"Delete").
'</a>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
cron_prepare_head(Cronjob $object)
Return array of tabs to used on a cron job.
dol_now($mode= 'auto')
Return date for now.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.