29require
'../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
34require_once DOL_DOCUMENT_ROOT.
"/cron/class/cronjob.class.php";
35require_once DOL_DOCUMENT_ROOT.
"/core/class/html.formcron.class.php";
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/cron.lib.php';
39$langs->loadLangs(array(
'admin',
'cron',
'members',
'bills'));
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');
50if (!$user->hasRight(
'cron',
'create')) {
54$permissiontoadd = $user->hasRight(
'cron',
'create');
55$permissiontoexecute = $user->hasRight(
'cron',
'execute');
56$permissiontodelete = $user->hasRight(
'cron',
'delete');
72 if (!empty($id) && empty($backtopage)) {
76 header(
"Location: ".$backtopage);
78 header(
"Location: ".DOL_URL_ROOT.
'/cron/list.php');
85if ($action ==
'confirm_delete' && $confirm ==
"yes" && $permissiontodelete) {
86 $result =
$object->delete($user);
92 header(
"Location: ".DOL_URL_ROOT.
'/cron/list.php');
98if ($action ==
'confirm_execute' && $confirm ==
"yes" && $permissiontoexecute) {
104 $result =
$object->run_jobs($user->login);
109 $res =
$object->reprogram_jobs($user->login, $now);
125if ($action ==
'add' && $permissiontoadd) {
148 $result =
$object->create($user);
161if ($action ==
'update' && $permissiontoadd) {
183 $result =
$object->update($user);
195if ($action ==
'activate' && $permissiontoadd) {
199 $result =
$object->update($user);
211if ($action ==
'inactive' && $permissiontoadd) {
216 $result =
$object->update($user);
229if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
230 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
235 $result = $objectutil->createFromClone($user, ((
$object->id > 0) ?
$object->id :
$id));
236 if (is_object($result) || $result > 0) {
238 if (is_object($result)) {
239 $newid = $result->id;
243 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$newid);
257$form =
new Form($db);
264if ($action ==
'create') {
268if ($conf->use_javascript_ajax) {
269 print
"\n".
'<script type="text/javascript">';
270 print
'jQuery(document).ready(function () {
271 function initfields()
273 if ($("#jobtype option:selected").val()==\'method\') {
274 $(".blockmethod").show();
275 $(".blockcommand").hide();
277 if ($("#jobtype option:selected").val()==\'command\') {
278 $(".blockmethod").hide();
279 $(".blockcommand").show();
283 jQuery("#jobtype").change(function() {
287 print
'</script>'.
"\n";
291if ($action ==
'delete') {
292 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id, $langs->trans(
"CronDelete"), $langs->trans(
"CronConfirmDelete"),
"confirm_delete",
'',
'', 1);
297if ($action ==
'execute') {
298 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id.
'&securitykey='.$securitykey, $langs->trans(
"CronExecute"), $langs->trans(
"CronConfirmExecute"),
"confirm_execute",
'',
'', 1);
304if ($action ==
'clone') {
306 $formquestion = array();
307 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneAsk',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
318if (empty(
$object->status) && $action !=
'create') {
322if (($action ==
"create") || ($action ==
"edit")) {
323 print
'<form name="cronform" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
324 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
325 print
'<input type="hidden" name="backtopage" value="'.GETPOST(
'backtopage').
'">'.
"\n";
327 print
'<input type="hidden" name="action" value="update">'.
"\n";
328 print
'<input type="hidden" name="id" value="'.$object->id.
'">'.
"\n";
330 print
'<input type="hidden" name="action" value="add">'.
"\n";
333 if ($action ==
"edit") {
339 print
'<table class="border centpercent">';
341 print
'<tr><td class="fieldrequired titlefieldcreate">';
342 print $langs->trans(
'CronLabel').
"</td>";
343 print
'<td><input type="text" class="width200" name="label" value="'.dol_escape_htmltag(
$object->label).
'"> ';
349 print
'<tr><td class="fieldrequired">';
350 print $langs->trans(
'CronType').
"</td><td>";
351 print $formCron->select_typejob(
'jobtype',
$object->jobtype);
357 print
'<tr class="blockmethod"><td>';
358 print $langs->trans(
'CronModule').
"</td><td>";
359 print
'<input type="text" class="width200" name="module_name" value="'.dol_escape_htmltag(
$object->module_name).
'"> ';
362 print $form->textwithpicto(
'', $langs->trans(
"CronModuleHelp"), 1,
'help');
366 print
'<tr class="blockmethod"><td>';
367 print $langs->trans(
'CronClassFile').
"</td><td>";
368 print
'<input type="text" class="minwidth300" name="classesname" value="'.dol_escape_htmltag(
$object->classesname).
'"> ';
371 print $form->textwithpicto(
'', $langs->trans(
"CronClassFileHelp"), 1,
'help');
375 print
'<tr class="blockmethod"><td>';
376 print $langs->trans(
'CronObject').
"</td><td>";
377 print
'<input type="text" class="width200" name="objectname" value="'.dol_escape_htmltag(
$object->objectname).
'"> ';
380 print $form->textwithpicto(
'', $langs->trans(
"CronObjectHelp"), 1,
'help');
384 print
'<tr class="blockmethod"><td>';
385 print $langs->trans(
'CronMethod').
"</td><td>";
386 print
'<input type="text" class="minwidth300" name="methodename" value="'.dol_escape_htmltag(
$object->methodename).
'" /> ';
389 print $form->textwithpicto(
'', $langs->trans(
"CronMethodHelp"), 1,
'help');
393 print
'<tr class="blockmethod"><td>';
394 print $langs->trans(
'CronArgs').
"</td><td>";
395 print
'<input type="text" class="quatrevingtpercent" name="params" value="'.$object->params.
'" /> ';
398 print $form->textwithpicto(
'', $langs->trans(
"CronArgsHelp"), 1,
'help');
402 print
'<tr class="blockcommand"><td>';
403 print $langs->trans(
'CronCommand').
"</td><td>";
404 print
'<input type="text" class="minwidth150" name="command" value="'.$object->command.
'" /> ';
407 print $form->textwithpicto(
'', $langs->trans(
"CronCommandHelp"), 1,
'help');
412 print $langs->trans(
'CronNote').
"</td><td>";
413 $doleditor =
new DolEditor(
'note',
$object->note_private,
'', 160,
'dolibarr_notes',
'In',
true,
false, 0, ROWS_4,
'90%');
414 $doleditor->Create();
420 print
'<tr class="blockemailalert"><td>';
421 print $langs->trans(
'EmailIfError').
"</td><td>";
422 print
'<input type="text" class="minwidth150" name="email_alert" value="'.dol_escape_htmltag(
$object->email_alert).
'" /> ';
429 print
'<tr><td class="fieldrequired">';
430 print $langs->trans(
'CronEvery').
"</td>";
432 print
'<select name="nbfrequency">';
433 for ($i = 1; $i <= 60; $i++) {
434 if (
$object->frequency == $i) {
435 print
"<option value='".$i.
"' selected>".$i.
"</option>";
437 print
"<option value='".$i.
"'>".$i.
"</option>";
441 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"60\" id=\"frequency_minute\" ";
442 if (
$object->unitfrequency ==
"60") {
443 $input .=
' checked />';
447 $input .=
"<label for=\"frequency_minute\">".$langs->trans(
'Minutes').
"</label>";
450 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"3600\" id=\"frequency_heures\" ";
451 if (
$object->unitfrequency ==
"3600") {
452 $input .=
' checked />';
456 $input .=
"<label for=\"frequency_heures\">".$langs->trans(
'Hours').
"</label>";
459 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"86400\" id=\"frequency_jours\" ";
460 if (
$object->unitfrequency ==
"86400") {
461 $input .=
' checked />';
465 $input .=
"<label for=\"frequency_jours\">".$langs->trans(
'Days').
"</label>";
468 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"604800\" id=\"frequency_semaine\" ";
469 if (
$object->unitfrequency ==
"604800") {
470 $input .=
' checked />';
474 $input .=
"<label for=\"frequency_semaine\">".$langs->trans(
'Weeks').
"</label>";
477 $input =
" <input type=\"radio\" name=\"unitfrequency\" value=\"2678400\" id=\"frequency_month\" ";
478 if (
$object->unitfrequency ==
"2678400") {
479 $input .=
' checked />';
483 $input .=
'<label for="frequency_month">'.$langs->trans(
'Months').
"</label>";
493 print $langs->trans(
'CronPriority').
"</td>";
495 if (!empty(
$object->priority)) {
498 print
'<td><input type="text" class="width50" name="priority" value="'.$priority.
'" /> ';
505 print $langs->trans(
'CronDtStart').
"</td><td>";
506 if (!empty(
$object->datestart)) {
507 print $form->selectDate(
$object->datestart,
'datestart', 1, 1, 0,
"cronform");
509 print $form->selectDate(-1,
'datestart', 1, 1, 1,
"cronform");
517 print $langs->trans(
'CronDtEnd').
"</td><td>";
518 if (!empty(
$object->dateend)) {
519 print $form->selectDate(
$object->dateend,
'dateend', 1, 1, 0,
"cronform");
521 print $form->selectDate(-1,
'dateend', 1, 1, 1,
"cronform");
533 print $langs->trans(
'CronMaxRun').
"</td>";
534 print
'<td><input type="text" class="width50" name="maxrun" value="'.$maxrun.
'" /> ';
540 print
'<tr><td class="fieldrequired">';
541 print $langs->trans(
'CronDtNextLaunch');
544 if (!empty(
$object->datenextrun)) {
545 print $form->selectDate(
$object->datenextrun,
'datenextrun', 1, 1, 0,
"cronform");
547 print $form->selectDate(-1,
'datenextrun', 1, 1, 0,
"cronform", 1, 1);
558 print $form->buttonsSaveCancel();
567 $linkback =
'<a href="'.DOL_URL_ROOT.
'/cron/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
570 if (preg_match(
'/:(.*)$/',
$object->label, $reg)) {
571 $langs->load($reg[1]);
574 $labeltoshow = preg_replace(
'/:.*$/',
'',
$object->label);
576 $morehtmlref =
'<div class="refidno">';
577 $morehtmlref .= $langs->trans($labeltoshow);
578 $morehtmlref .=
'</div>';
580 dol_banner_tab(
$object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref);
583 print
'<div class="fichecenter">';
584 print
'<div class="fichehalfleft">';
586 print
'<div class="underbanner clearboth"></div>';
587 print
'<table class="border centpercent tableforfield">';
594 print
'<tr><td class="titlefieldmiddle">';
595 print $langs->trans(
'CronType').
"</td><td>";
596 print $formCron->select_typejob(
'jobtype',
$object->jobtype, 1);
599 print
'<tr class="blockmethod"><td>';
600 print $langs->trans(
'CronModule').
"</td><td>";
604 print
'<tr class="blockmethod"><td>';
605 print $langs->trans(
'CronClassFile').
"</td><td>";
609 print
'<tr class="blockmethod"><td>';
610 print $langs->trans(
'CronObject').
"</td><td>";
614 print
'<tr class="blockmethod"><td>';
615 print $langs->trans(
'CronMethod').
"</td><td>";
619 print
'<tr class="blockmethod"><td>';
620 print $langs->trans(
'CronArgs').
"</td><td>";
624 print
'<tr class="blockcommand"><td>';
625 print $langs->trans(
'CronCommand').
"</td><td>";
630 print $langs->trans(
'CronNote').
"</td><td>";
631 if (!is_null(
$object->note_private) &&
$object->note_private !=
'') {
632 print
'<span class="small">'.$langs->trans(
$object->note_private).
'</small>';
636 print
'<tr class="blockemailalert"><td>';
637 print $langs->trans(
'EmailIfError').
"</td><td>";
641 if (isModEnabled(
'multicompany')) {
643 print $langs->trans(
'Entity').
"</td><td>";
645 print
img_picto($langs->trans(
"AllEntities"),
'entity',
'class="pictofixedwidth"').$langs->trans(
"AllEntities");
648 print
img_picto($langs->trans(
"AllEntities"),
'entity',
'class="pictofixedwidth"').$mc->label;
656 print
'<div class="fichehalfright">';
658 print
'<div class="underbanner clearboth"></div>';
659 print
'<table class="border centpercent tableforfield">';
661 print
'<tr><td class="titlefieldmiddle">';
662 print $langs->trans(
'CronEvery').
"</td>";
664 if (
$object->unitfrequency ==
"60") {
665 print $langs->trans(
'CronEach').
" ".(
$object->frequency).
" ".$langs->trans(
'Minutes');
667 if (
$object->unitfrequency ==
"3600") {
668 print $langs->trans(
'CronEach').
" ".(
$object->frequency).
" ".$langs->trans(
'Hours');
670 if (
$object->unitfrequency ==
"86400") {
671 print $langs->trans(
'CronEach').
" ".(
$object->frequency).
" ".$langs->trans(
'Days');
673 if (
$object->unitfrequency ==
"604800") {
674 print $langs->trans(
'CronEach').
" ".(
$object->frequency).
" ".$langs->trans(
'Weeks');
676 if (
$object->unitfrequency ==
"2678400") {
677 print $langs->trans(
'CronEach').
" ".(
$object->frequency).
" ".$langs->trans(
'Months');
683 print $langs->trans(
'CronPriority').
"</td>";
684 print
"<td>".$object->priority;
688 print $langs->trans(
'CronDtStart').
"</td><td>";
689 if (!empty(
$object->datestart)) {
690 print $form->textwithpicto(
dol_print_date(
$object->datestart,
'dayhoursec'), $langs->trans(
"CurrentTimeZone"));
695 print $langs->trans(
'CronDtEnd').
"</td><td>";
696 if (!empty(
$object->dateend)) {
697 print $form->textwithpicto(
dol_print_date(
$object->dateend,
'dayhoursec'), $langs->trans(
"CurrentTimeZone"));
702 print $langs->trans(
'CronMaxRun').
"</td>";
708 print $langs->trans(
'CronNbRun').
"</td>";
709 print
"<td>".$object->nbrun;
714 print $langs->trans(
'CronDtNextLaunch');
715 print
' ('.$langs->trans(
'CronFrom').
')';
718 print
img_picto(
'',
'object_calendarday').
' <span class="opacitymedium strikefordisabled">'.$form->textwithpicto(
dol_print_date(
$object->datenextrun,
'dayhoursec'), $langs->trans(
"CurrentTimeZone")).
'</span> ';
719 print $langs->trans(
"Disabled");
720 } elseif (!empty(
$object->datenextrun)) {
721 print
img_picto(
'',
'object_calendarday').
' '.$form->textwithpicto(
dol_print_date(
$object->datenextrun,
'dayhoursec'), $langs->trans(
"CurrentTimeZone"));
723 print
'<span class="opacitymedium">'.$langs->trans(
'CronNone').
'</span>';
725 if (
$object->status == Cronjob::STATUS_ENABLED) {
740 print
'<div class="underbanner clearboth"></div>';
741 print
'<table class="border centpercent tableforfield">';
743 print
'<tr><td class="titlefieldmiddle">';
744 print $langs->trans(
'CronDtLastLaunch').
"</td><td>";
745 if (!empty(
$object->datelastrun)) {
746 print $form->textwithpicto(
dol_print_date(
$object->datelastrun,
'dayhoursec'), $langs->trans(
"CurrentTimeZone"));
748 print
'<span class="opacitymedium">'.$langs->trans(
'CronNotYetRan').
'</span>';
753 print $langs->trans(
'CronDtLastResult').
"</td><td>";
754 if (!empty(
$object->datelastresult)) {
755 print $form->textwithpicto(
dol_print_date(
$object->datelastresult,
'dayhoursec'), $langs->trans(
"CurrentTimeZone"));
757 if (empty(
$object->datelastrun)) {
758 print
'<span class="opacitymedium">'.$langs->trans(
'CronNotYetRan').
'</span>';
766 print $langs->trans(
'CronLastResult').
"</td><td>";
768 print
'<span class="error">';
777 print $langs->trans(
'CronLastOutput').
"</td><td>";
778 print
'<span class="small">'.(!empty(
$object->lastoutput) ? nl2br(
$object->lastoutput) :
'').
'</span>';
785 print
'<div class="clearboth"></div>';
791 print
"\n\n".
'<div class="tabsAction">'.
"\n";
792 if (!$user->hasRight(
'cron',
'create')) {
793 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"Edit").
'</a>';
795 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"Edit").
'</a>';
798 if ((!$user->hasRight(
'cron',
'execute'))) {
799 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"CronExecute").
'</a>';
800 } elseif (empty(
$object->status)) {
801 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"JobDisabled")).
'">'.$langs->trans(
"CronExecute").
'</a>';
803 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>';
806 if (!$user->hasRight(
'cron',
'create')) {
807 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"CronStatusActiveBtn").
'/'.$langs->trans(
"CronStatusInactiveBtn").
'</a>';
809 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=clone&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"ToClone").
'</a>';
812 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=activate&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"CronStatusActiveBtn").
'</a>';
814 print
'<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=inactive&id='.
$object->id.
'">'.$langs->trans(
"CronStatusInactiveBtn").
'</a>';
818 if (!$user->hasRight(
'cron',
'delete')) {
819 print
'<a class="butActionDeleteRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"Delete").
'</a>';
821 print
'<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"Delete").
'</a>';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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_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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $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_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.