* Copyright (C) 2013-2016 Laurent Destailleur * Copyright (C) 2018-2021 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/cron/card.php * \ingroup cron * \brief Cron Jobs Card */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; // librairie jobs require_once DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php"; require_once DOL_DOCUMENT_ROOT."/core/class/html.formcron.class.php"; require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php'; // Load translation files required by the page $langs->loadLangs(array('admin', 'cron', 'members', 'bills')); $id = GETPOST('id', 'int'); $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha'); $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); $securitykey = GETPOST('securitykey', 'alpha'); $permissiontoadd = $user->rights->cron->create; if (!$user->rights->cron->create) { accessforbidden(); } /* * Actions */ $object = new Cronjob($db); if (!empty($id)) { $result = $object->fetch($id); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } if (!empty($cancel)) { if (!empty($id) && empty($backtopage)) { $action = ''; } else { if ($backtopage) { header("Location: ".$backtopage); exit; } else { header("Location: ".DOL_URL_ROOT.'/cron/list.php'); exit; } } } // Delete jobs if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->delete) { $result = $object->delete($user); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $action = 'edit'; } else { Header("Location: ".DOL_URL_ROOT.'/cron/list.php'); exit; } } // Execute jobs if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute) { if (!empty($conf->global->CRON_KEY) && $conf->global->CRON_KEY != $securitykey) { setEventMessages('Security key '.$securitykey.' is wrong', null, 'errors'); $action = ''; } else { $now = dol_now(); // Date we start $result = $object->run_jobs($user->login); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $action = ''; } else { $res = $object->reprogram_jobs($user->login, $now); if ($res > 0) { if ($object->lastresult > 0) { setEventMessages($langs->trans("JobFinished"), null, 'warnings'); } else { setEventMessages($langs->trans("JobFinished"), null, 'mesgs'); } $action = ''; } else { setEventMessages($object->error, $object->errors, 'errors'); $action = ''; } } } } if ($action == 'add') { $object->jobtype = GETPOST('jobtype'); $object->label = GETPOST('label'); $object->command = GETPOST('command'); $object->classesname = GETPOST('classesname', 'alphanohtml'); $object->objectname = GETPOST('objectname', 'aZ09'); $object->methodename = GETPOST('methodename', 'aZ09'); $object->params = GETPOST('params'); $object->md5params = GETPOST('md5params'); $object->module_name = GETPOST('module_name'); $object->note_private = GETPOST('note', 'restricthtml'); $object->datestart = dol_mktime(GETPOST('datestarthour', 'int'), GETPOST('datestartmin', 'int'), 0, GETPOST('datestartmonth', 'int'), GETPOST('datestartday', 'int'), GETPOST('datestartyear', 'int')); $object->dateend = dol_mktime(GETPOST('dateendhour', 'int'), GETPOST('dateendmin', 'int'), 0, GETPOST('dateendmonth', 'int'), GETPOST('dateendday', 'int'), GETPOST('dateendyear', 'int')); $object->priority = GETPOST('priority', 'int'); $object->datenextrun = dol_mktime(GETPOST('datenextrunhour', 'int'), GETPOST('datenextrunmin', 'int'), 0, GETPOST('datenextrunmonth', 'int'), GETPOST('datenextrunday', 'int'), GETPOST('datenextrunyear', 'int')); $object->unitfrequency = GETPOST('unitfrequency', 'int'); $object->frequency = GETPOST('nbfrequency', 'int'); $object->maxrun = GETPOST('maxrun', 'int'); // Add cron task $result = $object->create($user); // test du Resultat de la requete if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $action = 'create'; } else { setEventMessages($langs->trans('CronSaveSucess'), null, 'mesgs'); $action = ''; } } // Save parameters if ($action == 'update') { $object->id = $id; $object->jobtype = GETPOST('jobtype'); $object->label = GETPOST('label'); $object->command = GETPOST('command'); $object->classesname = GETPOST('classesname', 'alphanohtml'); $object->objectname = GETPOST('objectname', 'aZ09'); $object->methodename = GETPOST('methodename', 'aZ09'); $object->params = GETPOST('params'); $object->md5params = GETPOST('md5params'); $object->module_name = GETPOST('module_name'); $object->note_private = GETPOST('note', 'restricthtml'); $object->datestart = dol_mktime(GETPOST('datestarthour', 'int'), GETPOST('datestartmin', 'int'), 0, GETPOST('datestartmonth', 'int'), GETPOST('datestartday', 'int'), GETPOST('datestartyear', 'int')); $object->dateend = dol_mktime(GETPOST('dateendhour', 'int'), GETPOST('dateendmin', 'int'), 0, GETPOST('dateendmonth', 'int'), GETPOST('dateendday', 'int'), GETPOST('dateendyear', 'int')); $object->priority = GETPOST('priority', 'int'); $object->datenextrun = dol_mktime(GETPOST('datenextrunhour', 'int'), GETPOST('datenextrunmin', 'int'), 0, GETPOST('datenextrunmonth', 'int'), GETPOST('datenextrunday', 'int'), GETPOST('datenextrunyear', 'int')); $object->unitfrequency = GETPOST('unitfrequency', 'int'); $object->frequency = GETPOST('nbfrequency', 'int'); $object->maxrun = GETPOST('maxrun', 'int'); // Add cron task $result = $object->update($user); // test du Resultat de la requete if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $action = 'edit'; } else { setEventMessages($langs->trans('CronSaveSucess'), null, 'mesgs'); $action = ''; } } if ($action == 'activate') { $object->status = 1; // Add cron task $result = $object->update($user); // test du Resultat de la requete if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $action = 'edit'; } else { setEventMessages($langs->trans('CronSaveSucess'), null, 'mesgs'); $action = ''; } } if ($action == 'inactive') { $object->status = 0; $object->processing = 0; // Add cron task $result = $object->update($user); // test du Resultat de la requete if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $action = 'edit'; } else { setEventMessages($langs->trans('CronSaveSucess'), null, 'mesgs'); $action = ''; } } // Action clone object if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd)) { if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) { setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); } else { $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. $result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id)); if (is_object($result) || $result > 0) { $newid = 0; if (is_object($result)) { $newid = $result->id; } else { $newid = $result; } header("Location: ".$_SERVER['PHP_SELF'].'?id='.$newid); // Open record of new object exit; } else { setEventMessages($objectutil->error, $objectutil->errors, 'errors'); $action = ''; } } } /* * View */ $form = new Form($db); $formCron = new FormCron($db); llxHeader('', $langs->trans("CronTask")); $head = cron_prepare_head($object); if ($action == 'create') { print load_fiche_titre($langs->trans("CronTask"), '', 'title_setup'); } if ($conf->use_javascript_ajax) { print "\n".''."\n"; } $formconfirm = ''; if ($action == 'delete') { $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("CronDelete"), $langs->trans("CronConfirmDelete"), "confirm_delete", '', '', 1); $action = ''; } if ($action == 'execute') { $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id.'&securitykey='.$securitykey, $langs->trans("CronExecute"), $langs->trans("CronConfirmExecute"), "confirm_execute", '', '', 1); $action = ''; } // Clone confirmation if ($action == 'clone') { // Create an array for form $formquestion = array(); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); } // Print form confirm print $formconfirm; /* * Create Template */ if (empty($object->status) && $action != 'create') { setEventMessages($langs->trans("CronTaskInactive"), null, 'warnings'); } if (($action == "create") || ($action == "edit")) { print '
'; print ''."\n"; print ''."\n"; if (!empty($object->id)) { print ''."\n"; print ''."\n"; } else { print ''."\n"; } if ($action == "edit") { print dol_get_fiche_head($head, 'card', $langs->trans("CronTask"), 0, 'cron'); } else { print dol_get_fiche_head(''); } print ''; print '"; print ""; print ""; print "\n"; print '"; print ""; print "\n"; print '"; print ""; print "\n"; print '"; print ""; print "\n"; print '"; print ""; print "\n"; print '"; print ""; print "\n"; print '"; print ""; print "\n"; print '"; print ""; print "\n"; print '"; print ""; print "\n"; print '"; print ""; print ""; print "\n"; print ""; print ""; print "\n"; print ""; print ""; print "\n"; print ""; $priority = 0; if (!empty($object->priority)) { $priority = $object->priority; } print ""; print ""; print "\n"; print '"; print ""; print ""; print "\n"; print '"; print ""; print ""; print '
'; print $langs->trans('CronLabel')."label."\" /> "; print ""; print "
'; print $langs->trans('CronType').""; print $formCron->select_typejob('jobtype', $object->jobtype); print ""; print "
'; print $langs->trans('CronModule').""; print "module_name."\" /> "; print ""; print $form->textwithpicto('', $langs->trans("CronModuleHelp"), 1, 'help'); print "
'; print $langs->trans('CronClassFile').""; print ' '; print ""; print $form->textwithpicto('', $langs->trans("CronClassFileHelp"), 1, 'help'); print "
'; print $langs->trans('CronObject').""; print "objectname."\" /> "; print ""; print $form->textwithpicto('', $langs->trans("CronObjectHelp"), 1, 'help'); print "
'; print $langs->trans('CronMethod').""; print ' '; print ""; print $form->textwithpicto('', $langs->trans("CronMethodHelp"), 1, 'help'); print "
'; print $langs->trans('CronArgs').""; print ' '; print ""; print $form->textwithpicto('', $langs->trans("CronArgsHelp"), 1, 'help'); print "
'; print $langs->trans('CronCommand').""; print ' '; print ""; print $form->textwithpicto('', $langs->trans("CronCommandHelp"), 1, 'help'); print "
'; print $langs->trans('CronNote').""; $doleditor = new DolEditor('note', $object->note_private, '', 160, 'dolibarr_notes', 'In', true, false, 0, ROWS_4, '90%'); $doleditor->Create(); print ""; print "
'; print $langs->trans('CronEvery').""; print '"; $input = " unitfrequency == "60") { $input .= ' checked />'; } else { $input .= ' />'; } $input .= ""; print $input; $input = " unitfrequency == "3600") { $input .= ' checked />'; } else { $input .= ' />'; } $input .= ""; print $input; $input = " unitfrequency == "86400") { $input .= ' checked />'; } else { $input .= ' />'; } $input .= ""; print $input; $input = " unitfrequency == "604800") { $input .= ' checked />'; } else { $input .= ' />'; } $input .= ""; print $input; print ""; print "
"; print $langs->trans('CronDtStart').""; if (!empty($object->datestart)) { print $form->selectDate($object->datestart, 'datestart', 1, 1, '', "cronform"); } else { print $form->selectDate(-1, 'datestart', 1, 1, '', "cronform"); } print ""; print "
"; print $langs->trans('CronDtEnd').""; if (!empty($object->dateend)) { print $form->selectDate($object->dateend, 'dateend', 1, 1, '', "cronform"); } else { print $form->selectDate(-1, 'dateend', 1, 1, '', "cronform"); } print ""; print "
"; print $langs->trans('CronPriority')." "; print ""; print "
'; $maxrun = ''; if (!empty($object->maxrun)) { $maxrun = $object->maxrun; } print $langs->trans('CronMaxRun')." "; print ""; print "
'; print $langs->trans('CronDtNextLaunch'); print ' ('.$langs->trans('CronFrom').')'; print ""; if (!empty($object->datenextrun)) { print $form->selectDate($object->datenextrun, 'datenextrun', 1, 1, '', "cronform"); } else { print $form->selectDate(-1, 'datenextrun', 1, 1, '', "cronform"); } print ""; print "
'; print dol_get_fiche_end(); print $form->buttonsSaveCancel(); print "
\n"; } else { /* * view card */ $now = dol_now(); print dol_get_fiche_head($head, 'card', $langs->trans("CronTask"), -1, 'cron'); $linkback = ''.$langs->trans("BackToList").''; $morehtmlref = '
'; $morehtmlref .= $langs->trans($object->label); $morehtmlref .= '
'; dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref); // box add_jobs_box print '
'; print '
'; print '
'; print ''; /*print '"; print "";*/ print '"; print '"; print '"; print '"; print '"; print '"; print '"; print '"; if (!empty($conf->multicompany->enabled)) { print '"; } print '
'; print $langs->trans('CronLabel')."".$langs->trans($object->label); print "
'; print $langs->trans('CronType').""; print $formCron->select_typejob('jobtype', $object->jobtype, 1); print "
'; print $langs->trans('CronModule').""; print $object->module_name; print "
'; print $langs->trans('CronClassFile').""; print $object->classesname; print "
'; print $langs->trans('CronObject').""; print $object->objectname; print "
'; print $langs->trans('CronMethod').""; print $object->methodename; print "
'; print $langs->trans('CronArgs').""; print $object->params; print "
'; print $langs->trans('CronCommand').""; print $object->command; print "
'; print $langs->trans('CronNote').""; if (!is_null($object->note_private) && $object->note_private != '') { print $langs->trans($object->note_private); } print "
'; print $langs->trans('Entity').""; if (empty($object->entity)) { print img_picto($langs->trans("AllEntities"), 'entity', 'class="pictofixedwidth"').$langs->trans("AllEntities"); } else { $mc->getInfo($object->entity); print img_picto($langs->trans("AllEntities"), 'entity', 'class="pictofixedwidth"').$mc->label; } print "
'; print '
'; print '
'; print '
'; print ''; print '"; print ""; print '"; print ""; print ""; print ""; print ""; print ""; print ""; print ""; // Date next run (from) print '"; print '
'; print $langs->trans('CronEvery').""; if ($object->unitfrequency == "60") { print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Minutes'); } if ($object->unitfrequency == "3600") { print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Hours'); } if ($object->unitfrequency == "86400") { print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Days'); } if ($object->unitfrequency == "604800") { print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Weeks'); } print "
'; print $langs->trans('CronDtStart').""; if (!empty($object->datestart)) { print $form->textwithpicto(dol_print_date($object->datestart, 'dayhoursec'), $langs->trans("CurrentTimeZone")); } print "
"; print $langs->trans('CronDtEnd').""; if (!empty($object->dateend)) { print $form->textwithpicto(dol_print_date($object->dateend, 'dayhoursec'), $langs->trans("CurrentTimeZone")); } print "
"; print $langs->trans('CronPriority')."".$object->priority; print "
"; print $langs->trans('CronMaxRun').""; print $object->maxrun > 0 ? $object->maxrun : ''; print "
"; print $langs->trans('CronNbRun')."".$object->nbrun; print "
'; print $langs->trans('CronDtNextLaunch'); print ' ('.$langs->trans('CronFrom').')'; print ""; if (!$object->status) { print $langs->trans("Disabled"); } 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'); } if ($object->status == Cronjob::STATUS_ENABLED) { if ($object->maxrun && $object->nbrun >= $object->maxrun) { print img_warning($langs->trans("MaxRunReached")); } elseif ($object->datenextrun && $object->datenextrun < $now) { print img_warning($langs->trans("Late")); } } print "
'; print '
'; print '
'; print ''; print '"; print '"; print '"; print '"; print '
'; print $langs->trans('CronDtLastLaunch').""; if (!empty($object->datelastrun)) { print $form->textwithpicto(dol_print_date($object->datelastrun, 'dayhoursec'), $langs->trans("CurrentTimeZone")); } else { print $langs->trans('CronNone'); } print "
'; print $langs->trans('CronDtLastResult').""; if (!empty($object->datelastresult)) { print $form->textwithpicto(dol_print_date($object->datelastresult, 'dayhoursec'), $langs->trans("CurrentTimeZone")); } else { if (empty($object->datelastrun)) { print $langs->trans('CronNone'); } else { // In progress } } print "
'; print $langs->trans('CronLastResult').""; if ($object->lastresult) { print ''; } print $object->lastresult; if ($object->lastresult) { print ''; } print "
'; print $langs->trans('CronLastOutput').""; print nl2br($object->lastoutput); print "
'; print '
'; print '
'; print dol_get_fiche_end(); print "\n\n
\n"; if (!$user->rights->cron->create) { print ''.$langs->trans("Edit").''; } else { print ''.$langs->trans("Edit").''; } if ((empty($user->rights->cron->execute))) { print ''.$langs->trans("CronExecute").''; } elseif (empty($object->status)) { print ''.$langs->trans("CronExecute").''; } else { print ''.$langs->trans("CronExecute").''; } if (!$user->rights->cron->create) { print ''.$langs->trans("CronStatusActiveBtn").'/'.$langs->trans("CronStatusInactiveBtn").''; } else { print ''.$langs->trans("ToClone").''; if (empty($object->status)) { print ''.$langs->trans("CronStatusActiveBtn").''; } else { print ''.$langs->trans("CronStatusInactiveBtn").''; } } if (!$user->rights->cron->delete) { print ''.$langs->trans("Delete").''; } else { print ''.$langs->trans("Delete").''; } print '
'; print '
'; } llxFooter(); $db->close();