30require
'../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
42require_once DOL_DOCUMENT_ROOT.
"/cron/class/cronjob.class.php";
43require_once DOL_DOCUMENT_ROOT.
"/core/class/html.formcron.class.php";
44require_once DOL_DOCUMENT_ROOT.
'/core/lib/cron.lib.php';
47$langs->loadLangs(array(
'admin',
'cron',
'members',
'bills'));
50$action =
GETPOST(
'action',
'aZ09');
51$confirm =
GETPOST(
'confirm',
'alpha');
52$cancel =
GETPOST(
'cancel',
'alpha');
53$backtopage =
GETPOST(
'backtopage',
'alpha');
54$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
56$securitykey =
GETPOST(
'securitykey',
'alpha');
59$permissiontoadd = $user->hasRight(
'cron',
'write') && $user->admin;
60$permissiontoexecute = $user->hasRight(
'cron',
'write') && $user->admin;
61$permissiontodelete = $user->hasRight(
'cron',
'delete');
63if (!$permissiontoadd) {
81 if (!empty($id) && empty($backtopage)) {
85 header(
"Location: ".$backtopage);
87 header(
"Location: ".DOL_URL_ROOT.
'/cron/list.php');
94if ($action ==
'confirm_delete' && $confirm ==
"yes" && $permissiontodelete) {
96 $result =
$object->delete($user);
102 header(
"Location: ".DOL_URL_ROOT.
'/cron/list.php');
108if ($action ==
'confirm_execute' && $confirm ==
"yes" && $permissiontoexecute) {
110 setEventMessages(
'Security key '.$securitykey.
' is wrong',
null,
'errors');
114 $result =
$object->run_jobs($user->login);
119 $res =
$object->reprogram_jobs($user->login, $now);
122 setEventMessages($langs->trans(
"JobFinished"),
null,
'warnings');
124 setEventMessages($langs->trans(
"JobFinished"),
null,
'mesgs');
135if ($action ==
'add') {
158 $result =
$object->create($user);
165 setEventMessages($langs->trans(
'CronSaveSucess'),
null,
'mesgs');
171if ($action ==
'update') {
193 $result =
$object->update($user);
200 setEventMessages($langs->trans(
'CronSaveSucess'),
null,
'mesgs');
205if ($action ==
'activate') {
209 $result =
$object->update($user);
216 setEventMessages($langs->trans(
'CronSaveSucess'),
null,
'mesgs');
221if ($action ==
'inactive') {
226 $result =
$object->update($user);
233 setEventMessages($langs->trans(
'CronSaveSucess'),
null,
'mesgs');
239if ($action ==
'confirm_clone' && $confirm ==
'yes') {
241 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
242 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
246 $result = $objectutil->createFromClone($user, ((
$object->id > 0) ?
$object->id :
$id));
247 if (is_object($result) || $result > 0) {
249 if (is_object($result)) {
250 $newid = $result->id;
254 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$newid);
257 setEventMessages($objectutil->error, $objectutil->errors,
'errors');
268$form =
new Form($db);
275if ($action ==
'create') {
279if (
$conf->use_javascript_ajax) {
280 print
"\n".
'<script type="text/javascript">';
281 print
'jQuery(document).ready(function () {
282 function initfields()
284 if ($("#jobtype option:selected").val()==\'method\') {
285 $(".blockmethod").show();
286 $(".blockcommand").hide();
288 if ($("#jobtype option:selected").val()==\'command\') {
289 $(".blockmethod").hide();
290 $(".blockcommand").show();
294 jQuery("#jobtype").change(function() {
298 print
'</script>'.
"\n";
302if ($action ==
'delete') {
303 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id, $langs->trans(
"CronDelete"), $langs->trans(
"CronConfirmDelete"),
"confirm_delete",
'',
'', 1);
308if ($action ==
'execute') {
309 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id.
'&securitykey='.$securitykey, $langs->trans(
"CronExecute"), $langs->trans(
"CronConfirmExecute"),
"confirm_execute",
'',
'', 1);
315if ($action ==
'clone') {
317 $formquestion = array();
318 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneAsk',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
329if (empty(
$object->status) && $action !=
'create') {
330 setEventMessages($langs->trans(
"CronTaskInactive"),
null,
'warnings');
333if (($action ==
"create") || ($action ==
"edit")) {
334 print
'<form name="cronform" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
335 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
336 print
'<input type="hidden" name="backtopage" value="'.GETPOST(
'backtopage').
'">'.
"\n";
338 print
'<input type="hidden" name="action" value="update">'.
"\n";
339 print
'<input type="hidden" name="id" value="'.$object->id.
'">'.
"\n";
341 print
'<input type="hidden" name="action" value="add">'.
"\n";
344 if ($action ==
"edit") {
350 print
'<table class="border centpercent">';
352 print
'<tr><td class="fieldrequired titlefieldcreate">';
353 print $langs->trans(
'CronLabel').
"</td>";
354 print
'<td><input type="text" class="width200" name="label" value="'.dol_escape_htmltag(
$object->label).
'" spellcheck="false"> ';
360 print
'<tr><td class="fieldrequired">';
361 print $langs->trans(
'CronType').
"</td><td>";
362 print $formCron->select_typejob(
'jobtype',
$object->jobtype);
368 print
'<tr class="blockmethod"><td>';
369 print $langs->trans(
'CronModule').
"</td><td>";
370 print
'<input type="text" class="width200" name="module_name" value="'.dol_escape_htmltag(
$object->module_name).
'" spellcheck="false"> ';
373 print $form->textwithpicto(
'', $langs->trans(
"CronModuleHelp"), 1,
'help');
377 print
'<tr class="blockmethod"><td>';
378 print $langs->trans(
'CronClassFile').
"</td><td>";
379 print
'<input type="text" class="minwidth300" name="classesname" value="'.dol_escape_htmltag(
$object->classesname).
'" spellcheck="false"> ';
382 print $form->textwithpicto(
'', $langs->trans(
"CronClassFileHelp"), 1,
'help');
386 print
'<tr class="blockmethod"><td>';
387 print $langs->trans(
'CronObject').
"</td><td>";
388 print
'<input type="text" class="width200" name="objectname" value="'.dol_escape_htmltag(
$object->objectname).
'" spellcheck="false"> ';
391 print $form->textwithpicto(
'', $langs->trans(
"CronObjectHelp"), 1,
'help');
395 print
'<tr class="blockmethod"><td>';
396 print $langs->trans(
'CronMethod').
"</td><td>";
397 print
'<input type="text" class="minwidth300" name="methodename" value="'.dol_escape_htmltag(
$object->methodename).
'" spellcheck="false"> ';
400 print $form->textwithpicto(
'', $langs->trans(
"CronMethodHelp"), 1,
'help');
404 print
'<tr class="blockmethod"><td>';
405 print $langs->trans(
'CronArgs').
"</td><td>";
406 print
'<input type="text" class="quatrevingtpercent" name="params" value="'.dol_escape_htmltag(
$object->params).
'" spellcheck="false"> ';
409 print $form->textwithpicto(
'', $langs->trans(
"CronArgsHelp"), 1,
'help');
413 print
'<tr class="blockcommand"><td>';
414 print $langs->trans(
'CronCommand').
"</td><td>";
415 print
'<input type="text" class="minwidth150" name="command" value="'.dol_escape_htmltag(
$object->command).
'" spellcheck="false" /> ';
418 print $form->textwithpicto(
'', $langs->trans(
"CronCommandHelp"), 1,
'help');
423 print $langs->trans(
'CronNote').
"</td><td>";
424 $doleditor =
new DolEditor(
'note',
$object->note_private,
'', 160,
'dolibarr_notes',
'In',
true,
false, 0, ROWS_4,
'90%');
425 $doleditor->Create();
431 print
'<tr class="blockemailalert"><td>';
432 print $langs->trans(
'EmailIfError').
"</td><td>";
433 print
'<input type="text" class="minwidth150" name="email_alert" value="'.dol_escape_htmltag(
$object->email_alert).
'" /> ';
440 print
'<tr><td class="fieldrequired">';
441 print $langs->trans(
'CronEvery').
"</td>";
443 print img_picto(
'',
'recurring',
'class="pictofixedwidth"');
444 print
'<select name="nbfrequency" id="nbfrequency" class="width50 maxwidth50imp">';
445 for ($i = 1; $i <= 60; $i++) {
446 if (
$object->frequency == $i) {
447 print
"<option value='".$i.
"' selected>".$i.
"</option>";
449 print
"<option value='".$i.
"'>".$i.
"</option>";
454 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"60\" id=\"frequency_minute\" ";
455 if (
$object->unitfrequency ==
"60") {
456 $input .=
' checked />';
460 $input .=
"<label for=\"frequency_minute\">".$langs->trans(
'Minutes').
"</label>";
463 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"3600\" id=\"frequency_heures\" ";
464 if (
$object->unitfrequency ==
"3600") {
465 $input .=
' checked />';
469 $input .=
"<label for=\"frequency_heures\">".$langs->trans(
'Hours').
"</label>";
472 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"86400\" id=\"frequency_jours\" ";
473 if (
$object->unitfrequency ==
"86400") {
474 $input .=
' checked />';
478 $input .=
"<label for=\"frequency_jours\">".$langs->trans(
'Days').
"</label>";
481 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"604800\" id=\"frequency_semaine\" ";
482 if (
$object->unitfrequency ==
"604800") {
483 $input .=
' checked />';
487 $input .=
"<label for=\"frequency_semaine\">".$langs->trans(
'Weeks').
"</label>";
490 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"2678400\" id=\"frequency_month\" ";
491 if (
$object->unitfrequency ==
"2678400") {
492 $input .=
' checked />';
496 $input .=
'<label for="frequency_month">'.$langs->trans(
'Months').
"</label>";
506 print $langs->trans(
'CronPriority').
"</td>";
508 if (!empty(
$object->priority)) {
511 print
'<td><input type="text" class="width50" name="priority" value="'.$priority.
'" /> ';
518 print $langs->trans(
'CronDtStart').
"</td><td>";
519 if (!empty(
$object->datestart)) {
520 print $form->selectDate(
$object->datestart,
'datestart', 1, 1, 0,
"cronform");
522 print $form->selectDate(-1,
'datestart', 1, 1, 1,
"cronform");
530 print $langs->trans(
'CronDtEnd').
"</td><td>";
531 if (!empty(
$object->dateend)) {
532 print $form->selectDate(
$object->dateend,
'dateend', 1, 1, 0,
"cronform");
534 print $form->selectDate(-1,
'dateend', 1, 1, 1,
"cronform");
546 print $langs->trans(
'CronMaxRun').
"</td>";
547 print
'<td><input type="text" class="width50" name="maxrun" value="'.$maxrun.
'" /> ';
553 print
'<tr><td class="fieldrequired">';
554 print $langs->trans(
'CronDtNextLaunch');
557 if (!empty(
$object->datenextrun)) {
558 print $form->selectDate(
$object->datenextrun,
'datenextrun', 1, 1, 0,
"cronform");
560 print $form->selectDate(-1,
'datenextrun', 1, 1, 0,
"cronform", 1, 1);
571 print $form->buttonsSaveCancel();
580 $linkback =
'<a href="'.DOL_URL_ROOT.
'/cron/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
583 if (preg_match(
'/:(.*)$/',
$object->label, $reg)) {
584 $langs->load($reg[1]);
587 $labeltoshow = preg_replace(
'/:.*$/',
'',
$object->label);
589 $morehtmlref =
'<div class="refidno">';
590 $morehtmlref .= $langs->trans($labeltoshow);
591 $morehtmlref .=
'</div>';
593 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref);
596 print
'<div class="fichecenter">';
597 print
'<div class="fichehalfleft">';
599 print
'<div class="underbanner clearboth"></div>';
600 print
'<table class="border centpercent tableforfield">';
607 print
'<tr><td class="titlefieldmiddle">';
608 print $langs->trans(
'CronType').
"</td><td>";
609 print $formCron->select_typejob(
'jobtype',
$object->jobtype, 1);
612 print
'<tr class="blockmethod"><td>';
613 print $langs->trans(
'CronModule').
"</td><td>";
617 print
'<tr class="blockmethod"><td>';
618 print $langs->trans(
'CronClassFile').
"</td><td>";
622 print
'<tr class="blockmethod"><td>';
623 print $langs->trans(
'CronObject').
"</td><td>";
627 print
'<tr class="blockmethod"><td>';
628 print $langs->trans(
'CronMethod').
"</td><td>";
632 print
'<tr class="blockmethod"><td>';
633 print $langs->trans(
'CronArgs').
"</td><td>";
637 print
'<tr class="blockcommand"><td>';
638 print $langs->trans(
'CronCommand').
"</td><td>";
643 print $langs->trans(
'CronNote').
"</td><td>";
644 if (!is_null(
$object->note_private) &&
$object->note_private !=
'') {
645 print
'<div class="small lineheightsmall">'.$langs->trans(
$object->note_private).
'</div>';
649 print
'<tr class="blockemailalert"><td>';
650 print $langs->trans(
'EmailIfError').
"</td><td>";
656 print $langs->trans(
'Entity').
"</td><td>";
658 print img_picto($langs->trans(
"AllEntities"),
'entity',
'class="pictofixedwidth"').$langs->trans(
"AllEntities");
661 print img_picto($langs->trans(
"AllEntities"),
'entity',
'class="pictofixedwidth"').$mc->label;
669 print
'<div class="fichehalfright">';
671 print
'<div class="underbanner clearboth"></div>';
672 print
'<table class="border centpercent tableforfield">';
674 print
'<tr><td class="titlefieldmiddle">';
675 print $langs->trans(
'CronEvery').
"</td>";
677 print img_picto(
'',
'recurring',
'class="pictofixedwidth"');
678 if (
$object->unitfrequency ==
"60") {
679 print $langs->trans(
'CronEach').
" ".(
$object->frequency).
" ".$langs->trans(
'Minutes');
681 if (
$object->unitfrequency ==
"3600") {
682 print $langs->trans(
'CronEach').
" ".(
$object->frequency).
" ".$langs->trans(
'Hours');
684 if (
$object->unitfrequency ==
"86400") {
685 print $langs->trans(
'CronEach').
" ".(
$object->frequency).
" ".$langs->trans(
'Days');
687 if (
$object->unitfrequency ==
"604800") {
688 print $langs->trans(
'CronEach').
" ".(
$object->frequency).
" ".$langs->trans(
'Weeks');
690 if (
$object->unitfrequency ==
"2678400") {
691 print $langs->trans(
'CronEach').
" ".(
$object->frequency).
" ".$langs->trans(
'Months');
697 print $langs->trans(
'CronPriority').
"</td>";
698 print
"<td>".$object->priority;
702 print $langs->trans(
'CronDtStart').
"</td><td>";
703 if (!empty(
$object->datestart)) {
704 print $form->textwithpicto(
dol_print_date(
$object->datestart,
'dayhoursec'), $langs->trans(
"CurrentTimeZone"));
709 print $langs->trans(
'CronDtEnd').
"</td><td>";
710 if (!empty(
$object->dateend)) {
711 print $form->textwithpicto(
dol_print_date(
$object->dateend,
'dayhoursec'), $langs->trans(
"CurrentTimeZone"));
716 print $langs->trans(
'CronMaxRun').
"</td>";
722 print $langs->trans(
'CronNbRun').
"</td>";
723 print
"<td>".$object->nbrun;
728 print $langs->trans(
'CronDtNextLaunch');
729 print
' ('.$langs->trans(
'CronFrom').
')';
732 print img_picto(
'',
'object_calendarday').
' <span class="opacitymedium strikefordisabled">'.$form->textwithpicto(
dol_print_date(
$object->datenextrun,
'dayhoursec'), $langs->trans(
"CurrentTimeZone")).
'</span> ';
733 print $langs->trans(
"Disabled");
734 } elseif (!empty(
$object->datenextrun)) {
735 print img_picto(
'',
'object_calendarday').
' '.$form->textwithpicto(
dol_print_date(
$object->datenextrun,
'dayhoursec'), $langs->trans(
"CurrentTimeZone"));
737 print
'<span class="opacitymedium">'.$langs->trans(
'CronNone').
'</span>';
739 if (
$object->status == Cronjob::STATUS_ENABLED) {
741 print img_warning($langs->trans(
"MaxRunReached"));
743 print img_warning($langs->trans(
"Late"));
754 print
'<div class="underbanner clearboth"></div>';
755 print
'<table class="border centpercent tableforfield">';
757 print
'<tr><td class="titlefieldmiddle">';
758 print $langs->trans(
'CronDtLastLaunch').
"</td><td>";
759 if (!empty(
$object->datelastrun)) {
760 print $form->textwithpicto(
dol_print_date(
$object->datelastrun,
'dayhoursec'), $langs->trans(
"CurrentTimeZone"));
762 print
'<span class="opacitymedium">'.$langs->trans(
'CronNotYetRan').
'</span>';
767 print $langs->trans(
'CronDtLastResult').
"</td><td>";
768 if (!empty(
$object->datelastresult)) {
769 print $form->textwithpicto(
dol_print_date(
$object->datelastresult,
'dayhoursec'), $langs->trans(
"CurrentTimeZone"));
771 if (empty(
$object->datelastrun)) {
772 print
'<span class="opacitymedium">'.$langs->trans(
'CronNotYetRan').
'</span>';
780 print $langs->trans(
'CronLastResult').
"</td><td>";
782 print
'<span class="error">';
791 print $langs->trans(
'CronLastOutput').
"</td><td>";
792 print
'<span class="small">'.(!empty(
$object->lastoutput) ? nl2br(
$object->lastoutput) :
'').
'</span>';
799 print
'<div class="clearboth"></div>';
805 print
"\n\n".
'<div class="tabsAction">'.
"\n";
806 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"Edit").
'</a>';
808 if (!$permissiontoexecute) {
809 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"CronExecute").
'</a>';
810 } elseif (empty(
$object->status)) {
811 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"JobDisabled")).
'">'.$langs->trans(
"CronExecute").
'</a>';
813 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=execute&token='.
newToken().
'&id='.
$object->id.(!
getDolGlobalString(
'CRON_KEY') ?
'' :
'&securitykey='.urlencode(
getDolGlobalString(
'CRON_KEY'))).
'">'.$langs->trans(
"CronExecute").
'</a>';
817 print dolGetButtonAction($langs->trans(
"ToClone"), $langs->trans(
"ToClone"),
'clone', $_SERVER[
'PHP_SELF'].
'?action=clone&token='.
newToken().
'&id='.
$object->id,
'', $permissiontoadd, array(
'attr' => array(
'class' =>
'reposition')));
820 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=activate&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"CronStatusActiveBtn").
'</a>';
822 print
'<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=inactive&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"CronStatusInactiveBtn").
'</a>';
826 if (!$permissiontodelete) {
827 print
'<a class="butActionDeleteRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"Delete").
'</a>';
829 print dolGetButtonAction($langs->trans(
"Delete"), $langs->trans(
"Delete"),
'delete', $_SERVER[
'PHP_SELF'].
'?action=delete&token='.
newToken().
'&id='.
$object->id,
'',
true, array(
'attr' => array(
'class' =>
'reposition'))).
"\n";
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='', $placeholder='')
Convert a html select field into an ajax combobox.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage a WYSIWYG editor.
cron_prepare_head(Cronjob $object)
Return array of tabs to used on a cron job.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.