Fix activation of cron jobs by external module

Clean code for task lists pages.
This commit is contained in:
Laurent Destailleur 2016-01-19 23:45:03 +01:00
parent 7c445a6d66
commit 03461d124a
13 changed files with 360 additions and 244 deletions

View File

@ -179,7 +179,7 @@ class modMyModule extends DolibarrModules
// Cronjobs
$this->cronjobs = array(); // List of cron jobs entries to add
// Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600),
// Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600),
// 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24)
// );

View File

@ -504,43 +504,6 @@ class FactureRec extends Facture
}
}
/**
* Rend la facture automatique
*
* @param User $user User object
* @param int $freq Freq
* @param string $courant Courant
* @return int 0 if OK, <0 if KO
*/
function set_auto($user, $freq, $courant)
{
if ($user->rights->facture->creer)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_rec ";
$sql .= " SET frequency = '".$freq."', last_gen='".$courant."'";
$sql .= " WHERE rowid = ".$this->id;
$resql = $this->db->query($sql);
if ($resql)
{
$this->frequency = $freq;
$this->last_gen = $courant;
return 0;
}
else
{
dol_print_error($this->db);
return -1;
}
}
else
{
return -2;
}
}
/**
* Return clicable name (with picto eventually)
*

View File

@ -251,7 +251,7 @@ function project_admin_prepare_head()
* @param string $inc Line number (start to 0, then increased by recursive call)
* @param string $parent Id of parent project to show (0 to show all)
* @param Task[] $lines Array of lines
* @param int $level Level (start to 0, then increased/decrease by recursive call)
* @param int $level Level (start to 0, then increased/decrease by recursive call), or -1 to show all level in order of $lines without the recursive groupment feature.
* @param string $var Color
* @param int $showproject Show project columns
* @param int $taskrole Array of roles of user for each tasks
@ -281,12 +281,12 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t
for ($i = 0 ; $i < $numlines ; $i++)
{
if ($parent == 0) $level = 0;
if ($parent == 0 && $level >= 0) $level = 0; // if $level = -1, we dont' use sublevel recursion, we show all lines
// Process line
// print "i:".$i."-".$lines[$i]->fk_project.'<br>';
if ($lines[$i]->fk_parent == $parent)
if ($lines[$i]->fk_parent == $parent || $level < 0) // if $level = -1, we dont' use sublevel recursion, we show all lines
{
// Show task line.
$showline=1;
@ -459,9 +459,13 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t
if (! $showlineingray) $inc++;
$level++;
if ($lines[$i]->id) projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick);
$level--;
if ($level >= 0) // Call sublevels
{
$level++;
if ($lines[$i]->id) projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick);
$level--;
}
$total_projectlinesa_spent += $lines[$i]->duration;
$total_projectlinesa_planned += $lines[$i]->planned_workload;
if ($lines[$i]->planned_workload) $total_projectlinesa_spent_if_planned += $lines[$i]->duration;
@ -473,7 +477,7 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t
}
}
if (($total_projectlinesa_planned > 0 || $total_projectlinesa_spent > 0) && $level==0)
if (($total_projectlinesa_planned > 0 || $total_projectlinesa_spent > 0) && $level <= 0)
{
print '<tr class="liste_total nodrag nodrop">';
print '<td class="liste_total">'.$langs->trans("Total").'</td>';

View File

@ -265,7 +265,7 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3703__+MAX_llx_menu__, 'project', '', 3700__+MAX_llx_menu__, '/projet/activity/perweek.php?leftmenu=projects', 'NewTimeSpent', 1, 'projects', '$user->rights->projet->lire', '', 2, 3, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3800__+MAX_llx_menu__, 'project', '', 7__+MAX_llx_menu__, '/projet/activity/index.php?leftmenu=projects&amp;mode=mine', 'MyActivities', 0, 'projects', '$user->rights->projet->lire', '', 2, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3801__+MAX_llx_menu__, 'project', '', 3800__+MAX_llx_menu__, '/projet/tasks.php?leftmenu=projects&amp;action=create&amp;mode=mine', 'NewTask', 1, 'projects', '$user->rights->projet->creer', '', 2, 1, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3801__+MAX_llx_menu__, 'project', '', 3800__+MAX_llx_menu__, '/projet/tasks.php?leftmenu=projects&amp;action=create', 'NewTask', 1, 'projects', '$user->rights->projet->creer', '', 2, 1, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3802__+MAX_llx_menu__, 'project', '', 3800__+MAX_llx_menu__, '/projet/tasks/list.php?leftmenu=projects&amp;mode=mine', 'List', 1, 'projects', '$user->rights->projet->lire', '', 2, 2, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3803__+MAX_llx_menu__, 'project', '', 3800__+MAX_llx_menu__, '/projet/activity/perweek.php?leftmenu=projects&amp;mode=mine', 'NewTimeSpent', 1, 'projects', '$user->rights->projet->lire', '', 2, 3, __ENTITY__);
-- Tools

View File

@ -1191,7 +1191,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
{
// Project affected to user
$newmenu->add("/projet/activity/index.php?mode=mine", $langs->trans("MyActivities"), 0, $user->rights->projet->lire);
$newmenu->add("/projet/tasks.php?action=create&mode=mine", $langs->trans("NewTask"), 1, $user->rights->projet->creer);
$newmenu->add("/projet/tasks.php?action=create", $langs->trans("NewTask"), 1, $user->rights->projet->creer);
$newmenu->add("/projet/tasks/list.php?mode=mine", $langs->trans("List"), 1, $user->rights->projet->lire);
$newmenu->add("/projet/activity/perweek.php?mode=mine", $langs->trans("NewTimeSpent"), 1, $user->rights->projet->creer);

View File

@ -906,6 +906,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
$label = isset($this->cronjobs[$key]['label'])?$this->cronjobs[$key]['label']:'';
$jobtype = isset($this->cronjobs[$key]['jobtype'])?$this->cronjobs[$key]['jobtype']:'';
$class = isset($this->cronjobs[$key]['class'])?$this->cronjobs[$key]['class']:'';
$objectname = isset($this->cronjobs[$key]['objectname'])?$this->cronjobs[$key]['objectname']:'';
$method = isset($this->cronjobs[$key]['method'])?$this->cronjobs[$key]['method']:'';
$command = isset($this->cronjobs[$key]['command'])?$this->cronjobs[$key]['command']:'';
$parameters = isset($this->cronjobs[$key]['parameters'])?$this->cronjobs[$key]['parameters']:'';
@ -917,6 +918,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
$sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."cronjob";
$sql.= " WHERE module_name = '".$this->db->escape($this->rights_class)."'";
if ($class) $sql.= " AND classesname = '".$this->db->escape($class)."'";
if ($objectname) $sql.= " AND objectname = '".$this->db->escape($objectname)."'";
if ($method) $sql.= " AND methodename = '".$this->db->escape($method)."'";
if ($command) $sql.= " AND command = '".$this->db->escape($command)."'";
$sql.= " AND entity = ".$conf->entity;
@ -934,13 +936,14 @@ class DolibarrModules // Can not be abstract, because we need to insta
if (! $err)
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob (module_name, datec, label, jobtype, classesname, methodename, command, params, note, frequency, unitfrequency, entity)";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob (module_name, datec, label, jobtype, classesname, objectname, methodename, command, params, note, frequency, unitfrequency, entity)";
$sql.= " VALUES (";
$sql.= "'".$this->db->escape($this->rights_class)."', ";
$sql.= "'".$this->db->idate($now)."', ";
$sql.= "'".$this->db->escape($label)."', ";
$sql.= "'".$this->db->escape($jobtype)."', ";
$sql.= ($class?"'".$this->db->escape($class)."'":"null").",";
$sql.= ($objectname?"'".$this->db->escape($objectname)."'":"null").",";
$sql.= ($method?"'".$this->db->escape($method)."'":"null").",";
$sql.= ($command?"'".$this->db->escape($command)."'":"null").",";
$sql.= ($parameters?"'".$this->db->escape($parameters)."'":"null").",";
@ -949,7 +952,6 @@ class DolibarrModules // Can not be abstract, because we need to insta
$sql.= "'".$this->db->escape($unitfrequency)."', ";
$sql.= $conf->entity;
$sql.= ")";
print $sql;
dol_syslog(get_class($this)."::insert_cronjobs", LOG_DEBUG);
$resql=$this->db->query($sql);

View File

@ -107,7 +107,7 @@ class modFacture extends DolibarrModules
// Cronjobs
$this->cronjobs = array(
0=>array('label'=>'RecurringInvoices', 'jobtype'=>'method', 'class'=>'Facture', 'method'=>'generateRecurringInvoices', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24),
0=>array('label'=>'RecurringInvoices', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture-rec.class.php', 'objectname'=>'Facture', 'method'=>'generateRecurringInvoices', 'parameters'=>'', 'comment'=>'Generate recurring invoices', 'frequency'=>1, 'unitfrequency'=>3600*24),
// 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>3600, 'unitfrequency'=>3600)
);
// List of cron jobs entries to add

View File

@ -42,6 +42,7 @@ $id=GETPOST('id','int');
$action=GETPOST('action','alpha');
$confirm=GETPOST('confirm','alpha');
$cancel=GETPOST('cancel');
$backtourl=GETPOST('backtourl','alpha');
/*
@ -60,14 +61,22 @@ if (!empty($id))
if (!empty($cancel))
{
if (!empty($id))
if (!empty($id) && empty($backtourl))
{
$action='';
}
else
{
Header("Location: ".DOL_URL_ROOT.'/cron/list.php?status=-2');
exit;
if ($backtourl)
{
header("Location: ".$backtourl);
exit;
}
else
{
header("Location: ".DOL_URL_ROOT.'/cron/list.php?status=-2');
exit;
}
}
}
@ -134,8 +143,9 @@ if ($action=='add')
$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->unitfrequency=GETPOST('unitfrequency','int');
$object->frequency=$object->unitfrequency * GETPOST('nbfrequency','int');
$object->frequency=GETPOST('nbfrequency','int');
$object->maxrun=GETPOST('maxrun','int');
// Add cron task
$result = $object->create($user);
@ -168,8 +178,9 @@ if ($action=='update')
$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->unitfrequency=GETPOST('unitfrequency','int');
$object->frequency=$object->unitfrequency * GETPOST('nbfrequency','int');
$object->frequency=GETPOST('nbfrequency','int');
$object->maxrun=GETPOST('maxrun','int');
// Add cron task
$result = $object->update($user);
@ -291,6 +302,7 @@ if (($action=="create") || ($action=="edit"))
{
print '<form name="cronform" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'."\n";
print '<input type="hidden" name="backtourl" value="'.GETPOST('backtourl').'">'."\n";
if (!empty($object->id)) {
print '<input type="hidden" name="action" value="update">'."\n";
print '<input type="hidden" name="id" value="'.$object->id.'">'."\n";
@ -318,105 +330,6 @@ if (($action=="create") || ($action=="edit"))
print "</td>";
print "</tr>\n";
print "<tr><td>";
print $langs->trans('CronDtStart')."</td><td>";
if(!empty($object->datestart))
{
$form->select_date($object->datestart,'datestart',1,1,'',"cronform");
}
else
{
$form->select_date('','datestart',1,1,'',"cronform");
}
print "</td>";
print "<td>";
print "</td>";
print "</tr>\n";
print "<tr><td>";
print $langs->trans('CronDtEnd')."</td><td>";
if(!empty($object->dateend)){
$form->select_date($object->dateend,'dateend',1,1,'',"cronform");
}
else{
$form->select_date('','dateend',1,1,1,"cronform");
}
print "</td>";
print "<td>";
print "</td>";
print "</tr>\n";
print "<tr><td>";
print $langs->trans('CronPriority')."</td>";
$priority=0;
if (!empty($object->priority)) {
$priority=$object->priority;
}
print "<td><input type=\"text\" size=\"2\" name=\"priority\" value=\"".$priority."\" /> ";
print "</td>";
print "<td>";
print "</td>";
print "</tr>\n";
print "<tr><td>";
print $langs->trans('CronEvery')."</td>";
print "<td><select name=\"nbfrequency\">";
for($i=1; $i<=60; $i++)
{
if (! empty($object->unitfrequency) && ($object->frequency/$object->unitfrequency) == $i)
{
print "<option value='".$i."' selected>".$i."</option>";
}
else
{
print "<option value='".$i."'>".$i."</option>";
}
}
$input = "<input type=\"radio\" name=\"unitfrequency\" value=\"60\" id=\"frequency_minute\" ";
if($object->unitfrequency=="60")
{
$input .= ' checked />';
}
else{
$input .= ' />';
}
$input .= "<label for=\"frequency_minute\">".$langs->trans('Minutes')."</label>";
print $input;
$input = "<input type=\"radio\" name=\"unitfrequency\" value=\"3600\" id=\"frequency_heures\" ";
if($object->unitfrequency=="3600"){
$input .= ' checked />';
}
else{
$input .= ' />';
}
$input .= "<label for=\"frequency_heures\">".$langs->trans('Hours')."</label>";
print $input;
$input = "<input type=\"radio\" name=\"unitfrequency\" value=\"86400\" id=\"frequency_jours\" ";
if($object->unitfrequency=="86400"){
$input .= ' checked />';
}
else{
$input .= ' />';
}
$input .= "<label for=\"frequency_jours\">".$langs->trans('Days')."</label>";
print $input;
$input = "<input type=\"radio\" name=\"unitfrequency\" value=\"604800\" id=\"frequency_semaine\" ";
if($object->unitfrequency=="604800"){
$input .= ' checked />';
}
else{
$input .= ' />';
}
$input .= "<label for=\"frequency_semaine\">".$langs->trans('Weeks')."</label>";
print $input;
print "</td>";
print "<td>";
print "</td>";
print "</tr>\n";
print '<tr class="blockmethod"><td>';
print $langs->trans('CronModule')."</td><td>";
print "<input type=\"text\" size=\"20\" name=\"module_name\" value=\"".$object->module_name."\" /> ";
@ -480,6 +393,119 @@ if (($action=="create") || ($action=="edit"))
print "</td>";
print "</tr>\n";
print "<tr><td>";
print $langs->trans('CronEvery')."</td>";
print "<td>";
print "<select name=\"nbfrequency\">";
for($i=1; $i<=60; $i++)
{
if (! empty($object->unitfrequency) && ($object->frequency/$object->unitfrequency) == $i)
{
print "<option value='".$i."' selected>".$i."</option>";
}
else
{
print "<option value='".$i."'>".$i."</option>";
}
}
print "</select>";
$input = " <input type=\"radio\" name=\"unitfrequency\" value=\"60\" id=\"frequency_minute\" ";
if($object->unitfrequency=="60")
{
$input .= ' checked />';
}
else{
$input .= ' />';
}
$input .= "<label for=\"frequency_minute\">".$langs->trans('Minutes')."</label>";
print $input;
$input = " <input type=\"radio\" name=\"unitfrequency\" value=\"3600\" id=\"frequency_heures\" ";
if($object->unitfrequency=="3600"){
$input .= ' checked />';
}
else{
$input .= ' />';
}
$input .= "<label for=\"frequency_heures\">".$langs->trans('Hours')."</label>";
print $input;
$input = " <input type=\"radio\" name=\"unitfrequency\" value=\"86400\" id=\"frequency_jours\" ";
if($object->unitfrequency=="86400"){
$input .= ' checked />';
}
else{
$input .= ' />';
}
$input .= "<label for=\"frequency_jours\">".$langs->trans('Days')."</label>";
print $input;
$input = " <input type=\"radio\" name=\"unitfrequency\" value=\"604800\" id=\"frequency_semaine\" ";
if($object->unitfrequency=="604800"){
$input .= ' checked />';
}
else{
$input .= ' />';
}
$input .= "<label for=\"frequency_semaine\">".$langs->trans('Weeks')."</label>";
print $input;
print "</td>";
print "<td>";
print "</td>";
print "</tr>\n";
print "<tr><td>";
print $langs->trans('CronDtStart')."</td><td>";
if(!empty($object->datestart))
{
$form->select_date($object->datestart,'datestart',1,1,'',"cronform");
}
else
{
$form->select_date('','datestart',1,1,'',"cronform");
}
print "</td>";
print "<td>";
print "</td>";
print "</tr>\n";
print "<tr><td>";
print $langs->trans('CronDtEnd')."</td><td>";
if(!empty($object->dateend)){
$form->select_date($object->dateend,'dateend',1,1,'',"cronform");
}
else{
$form->select_date('','dateend',1,1,1,"cronform");
}
print "</td>";
print "<td>";
print "</td>";
print "</tr>\n";
print "<tr><td>";
print $langs->trans('CronPriority')."</td>";
$priority=0;
if (!empty($object->priority)) {
$priority=$object->priority;
}
print "<td><input type=\"text\" size=\"2\" name=\"priority\" value=\"".$priority."\" /> ";
print "</td>";
print "<td>";
print "</td>";
print "</tr>\n";
print '<tr><td width="30%">';
$maxrun='';
if (!empty($object->maxrun)) {
$maxrun=$object->maxrun;
}
print $langs->trans('CronMaxRun')."</td>";
print "<td><input type=\"text\" size=\"2\" name=\"maxrun\" value=\"".$maxrun."\" /> ";
print "</td>";
print "<td>";
print "</td>";
print "</tr>\n";
print '</table>';
dol_fiche_end();
@ -501,12 +527,14 @@ else
dol_fiche_head($head, 'card', $langs->trans("CronTask"), 0, 'cron');
$linkback = '<a href="' . DOL_URL_ROOT . '/cron/list.php?status=-2">' . $langs->trans("BackToList") . '</a>';
// box add_jobs_box
print '<table class="border" width="100%">';
print '<tr><td width="30%">';
print $langs->trans('CronId')."</td>";
print "<td>".$form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'id');
print "<td>".$form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'id', '', '', 0);
print "</td></tr>\n";
print '<tr><td>';
@ -519,43 +547,6 @@ else
print $formCron->select_typejob('jobtype',$object->jobtype,1);
print "</td></tr>";
print "<tr><td>";
print $langs->trans('CronDtStart')."</td><td>";
if(!empty($object->datestart)) {print dol_print_date($object->datestart,'dayhourtext');}
print "</td></tr>";
print "<tr><td>";
print $langs->trans('CronDtEnd')."</td><td>";
if(!empty($object->dateend)) {print dol_print_date($object->dateend,'dayhourtext');}
print "</td></tr>";
print '<tr><td>';
print $langs->trans('CronDtNextLaunch');
print ' ('.$langs->trans('CronFrom').')';
print "</td><td>";
if(!empty($object->datenextrun)) {print dol_print_date($object->datenextrun,'dayhoursec');} else {print $langs->trans('CronNone');}
print "</td></tr>";
print "<tr><td>";
print $langs->trans('CronPriority')."</td>";
print "<td>".$object->priority;
print "</td></tr>";
print "<tr><td>";
print $langs->trans('CronNbRun')."</td>";
print "<td>".$object->nbrun;
print "</td></tr>";
print "<tr><td>";
print $langs->trans('CronEvery')."</td>";
print "<td>";
if($object->unitfrequency == "60") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Minutes');
if($object->unitfrequency == "3600") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Hours');
if($object->unitfrequency == "86400") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Days');
if($object->unitfrequency == "604800") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Weeks');
print "</td></tr>";
print '<tr class="blockmethod"><td>';
print $langs->trans('CronModule')."</td><td>";
print $object->module_name;
@ -601,6 +592,53 @@ else
print '<br>';
print '<table class="border" width="100%">';
print "<tr><td>";
print $langs->trans('CronEvery')."</td>";
print "<td>";
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 "</td></tr>";
print '<tr><td width="30%">';
print $langs->trans('CronDtStart')."</td><td>";
if(!empty($object->datestart)) {print dol_print_date($object->datestart,'dayhourtext');}
print "</td></tr>";
print "<tr><td>";
print $langs->trans('CronDtEnd')."</td><td>";
if(!empty($object->dateend)) {print dol_print_date($object->dateend,'dayhourtext');}
print "</td></tr>";
print "<tr><td>";
print $langs->trans('CronPriority')."</td>";
print "<td>".$object->priority;
print "</td></tr>";
print "<tr><td>";
print $langs->trans('CronMaxRun')."</td>";
print "<td>".$object->maxrun;
print "</td></tr>";
print "<tr><td>";
print $langs->trans('CronNbRun')."</td>";
print "<td>".$object->nbrun;
print "</td></tr>";
print '<tr><td>';
print $langs->trans('CronDtNextLaunch');
print ' ('.$langs->trans('CronFrom').')';
print "</td><td>";
if(!empty($object->datenextrun)) {print dol_print_date($object->datenextrun,'dayhoursec');} else {print $langs->trans('CronNone');}
print "</td></tr>";
print '</table>';
print '<br>';
print '<table class="border" width="100%">';
print '<tr><td width="30%">';

View File

@ -175,8 +175,9 @@ class Cronjob extends CommonObject
$sql.= "fk_user_author,";
$sql.= "fk_user_mod,";
$sql.= "note,";
$sql.= "nbrun";
$sql .= ",libname";
$sql.= "nbrun,";
$sql.= "maxrun,";
$sql.= "libname";
$sql.= ") VALUES (";
@ -206,12 +207,10 @@ class Cronjob extends CommonObject
$sql.= " ".$user->id.",";
$sql.= " ".(! isset($this->note)?'NULL':"'".$this->db->escape($this->note)."'").",";
$sql.= " ".(! isset($this->nbrun)?'0':"'".$this->db->escape($this->nbrun)."'").",";
$sql.= " ".(empty($this->maxrun)?'null':"'".$this->db->escape($this->maxrun)."'").",";
$sql.= " ".(! isset($this->libname)?'NULL':"'".$this->db->escape($this->libname)."'")."";
$sql.= ")";
$this->db->begin();
dol_syslog(get_class($this)."::create", LOG_DEBUG);
@ -291,8 +290,9 @@ class Cronjob extends CommonObject
$sql.= " t.fk_user_author,";
$sql.= " t.fk_user_mod,";
$sql.= " t.note,";
$sql.= " t.nbrun";
$sql .= ", t.libname";
$sql.= " t.nbrun,";
$sql.= " t.maxrun,";
$sql.= " t.libname";
$sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t";
@ -335,6 +335,7 @@ class Cronjob extends CommonObject
$this->fk_user_mod = $obj->fk_user_mod;
$this->note = $obj->note;
$this->nbrun = $obj->nbrun;
$this->maxrun = $obj->maxrun;
$this->libname = $obj->libname;
}
@ -517,6 +518,7 @@ class Cronjob extends CommonObject
if (isset($this->status)) $this->status=trim($this->status);
if (isset($this->note)) $this->note=trim($this->note);
if (isset($this->nbrun)) $this->nbrun=trim($this->nbrun);
if (isset($this->maxrun)) $this->maxrun=trim($this->maxrun);
if (isset($this->libname)) $this->libname = trim($this->libname);
// Check parameters
@ -585,10 +587,9 @@ class Cronjob extends CommonObject
$sql.= " status=".(isset($this->status)?$this->status:"null").",";
$sql.= " fk_user_mod=".$user->id.",";
$sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").",";
$sql.= " nbrun=".(isset($this->nbrun)?$this->nbrun:"null");
$sql.= ", libname=".(isset($this->libname)?"'".$this->db->escape($this->libname)."'":"null");
$sql.= " nbrun=".(isset($this->nbrun)?$this->nbrun:"null").",";
$sql.= " maxrun=".(isset($this->maxrun)?$this->maxrun:"null").",";
$sql.= " libname=".(isset($this->libname)?"'".$this->db->escape($this->libname)."'":"null");
$sql.= " WHERE rowid=".$this->id;
$this->db->begin();
@ -786,6 +787,7 @@ class Cronjob extends CommonObject
$this->fk_user_mod='';
$this->note='';
$this->nbrun='';
$this->maxrun=100;
$this->libname = '';
}
@ -1087,7 +1089,7 @@ class Cronjob extends CommonObject
if (empty($this->datenextrun))
{
$this->datenextrun = $now + $this->frequency;
$this->datenextrun = $now + ($this->frequency * $this->unitfrequency);
}
else
{
@ -1096,12 +1098,14 @@ class Cronjob extends CommonObject
// Loop until date is after future
while ($this->datenextrun < $now)
{
$this->datenextrun += $this->frequency;
$this->datenextrun += ($this->frequency * $this->unitfrequency);
// TODO For exact frequency (every month, every year, ...), use instead a dol_time_plus_duree($time, $duration_value, $duration_unit)
}
}
else
{
//$this->datenextrun=$this->datenextrun+$this->frequency;
//$this->datenextrun=$this->datenextrun + ($this->frequency * $this->unitfrequency);
}
}

View File

@ -31,6 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php';
$langs->load("admin");
$langs->load("cron");
$langs->load("bills");
if (!$user->rights->cron->read) accessforbidden();
@ -174,12 +175,12 @@ print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans("ID"),$_SERVER["PHP_SELF"],"t.rowid","",$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("CronLabel"),$_SERVER["PHP_SELF"],"t.label","",$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("CronTask"),'','',"",$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("CronFrequency"),'',"","",$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("CronDtStart"),$_SERVER["PHP_SELF"],"t.datestart","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("CronDtEnd"),$_SERVER["PHP_SELF"],"t.dateend","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("CronDtNextLaunch"),$_SERVER["PHP_SELF"],"t.datenextrun","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("CronFrequency"),'',"","",$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("CronMaxRun"),$_SERVER["PHP_SELF"],"t.maxrun","",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("CronNbRun"),$_SERVER["PHP_SELF"],"t.nbrun","",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("CronDtNextLaunch"),$_SERVER["PHP_SELF"],"t.datenextrun","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("CronDtLastLaunch"),$_SERVER["PHP_SELF"],"t.datelastrun","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("CronLastResult"),$_SERVER["PHP_SELF"],"t.lastresult","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("CronLastOutput"),$_SERVER["PHP_SELF"],"t.lastoutput","",$param,'',$sortfield,$sortorder);
@ -233,7 +234,7 @@ if ($num > 0)
print '<td>';
if (! empty($line->label))
{
print '<a href="'.DOL_URL_ROOT.'/cron/card.php?id='.$line->id.'">'.$line->label.'</a>';
print '<a href="'.DOL_URL_ROOT.'/cron/card.php?id='.$line->id.'">'.$langs->trans($line->label).'</a>';
}
else
{
@ -244,20 +245,31 @@ if ($num > 0)
print '<td>';
if ($line->jobtype=='method')
{
print $langs->trans('CronModule').':'.$line->module_name.'<BR>';
print $langs->trans('CronClass').':'. $line->classesname.'<BR>';
print $langs->trans('CronObject').':'. $line->objectname.'<BR>';
print $langs->trans('CronMethod').':'. $line->methodename;
$text=$langs->trans("CronClass");
$texttoshow=$langs->trans('CronModule').':'.$line->module_name.'<br>';
$texttoshow.=$langs->trans('CronClass').':'. $line->classesname.'<br>';
$texttoshow.=$langs->trans('CronObject').':'. $line->objectname.'<br>';
$texttoshow.=$langs->trans('CronMethod').':'. $line->methodename;
if(!empty($line->params)) {
print '<br>'.$langs->trans('CronArgs').':'. $line->params;
}
}elseif ($line->jobtype=='command') {
print $langs->trans('CronCommand').':'. dol_trunc($line->command);
if(!empty($line->params)) {
print '<br>'.$langs->trans('CronArgs').':'. $line->params;
$texttoshow.='<br>'.$langs->trans('CronArgs').':'. $line->params;
}
}
elseif ($line->jobtype=='command')
{
$text=$langs->trans('CronCommand');
$texttoshow=$langs->trans('CronCommand').': '.dol_trunc($line->command);
if(!empty($line->params)) {
$texttoshow='<br>'.$langs->trans('CronArgs').':'. $line->params;
}
}
print $form->textwithpicto($text, $texttoshow, 1);
print '</td>';
print '<td>';
if($line->unitfrequency == "60") print $langs->trans('CronEach')." ".($line->frequency)." ".$langs->trans('Minutes');
if($line->unitfrequency == "3600") print $langs->trans('CronEach')." ".($line->frequency)." ".$langs->trans('Hours');
if($line->unitfrequency == "86400") print $langs->trans('CronEach')." ".($line->frequency)." ".$langs->trans('Days');
if($line->unitfrequency == "604800") print $langs->trans('CronEach')." ".($line->frequency)." ".$langs->trans('Weeks');
print '</td>';
print '<td class="center">';
@ -268,17 +280,6 @@ if ($num > 0)
if(!empty($line->dateend)) {print dol_print_date($line->dateend,'dayhour');}
print '</td>';
print '<td class="center">';
if(!empty($line->datenextrun)) {print dol_print_date($line->datenextrun,'dayhour');}
print '</td>';
print '<td>';
if($line->unitfrequency == "60") print $langs->trans('CronEach')." ".($line->frequency/$line->unitfrequency)." ".$langs->trans('Minutes');
if($line->unitfrequency == "3600") print $langs->trans('CronEach')." ".($line->frequency/$line->unitfrequency)." ".$langs->trans('Hours');
if($line->unitfrequency == "86400") print $langs->trans('CronEach')." ".($line->frequency/$line->unitfrequency)." ".$langs->trans('Days');
if($line->unitfrequency == "604800") print $langs->trans('CronEach')." ".($line->frequency/$line->unitfrequency)." ".$langs->trans('Weeks');
print '</td>';
print '<td align="right">';
if (!empty($line->maxrun)) {print $line->maxrun;}
print '</td>';
@ -287,6 +288,10 @@ if ($num > 0)
if (!empty($line->nbrun)) {print $line->nbrun;} else {print '0';}
print '</td>';
print '<td class="center">';
if(!empty($line->datenextrun)) {print dol_print_date($line->datenextrun,'dayhour');}
print '</td>';
print '<td class="center">';
if(!empty($line->datelastrun)) {print dol_print_date($line->datelastrun,'dayhour');}
print '</td>';
@ -307,6 +312,10 @@ if ($num > 0)
print '</td>';
print '<td align="right" class="nowrap">';
if ($user->rights->cron->create)
{
print "<a href=\"".DOL_URL_ROOT."/cron/card.php?id=".$line->id."&action=edit&backtourl=".urlencode($_SERVER["PHP_SELF"])."\" title=\"".dol_escape_htmltag($langs->trans('Edit'))."\">".img_picto($langs->trans('Edit'),'edit')."</a> &nbsp;";
}
if ($user->rights->cron->delete)
{
print "<a href=\"".$_SERVER["PHP_SELF"]."?id=".$line->id."&status=".$status."&action=delete\" title=\"".dol_escape_htmltag($langs->trans('CronDelete'))."\">".img_picto($langs->trans('CronDelete'),'delete')."</a> &nbsp;";

View File

@ -224,6 +224,7 @@ NonPercuRecuperable=Non-recoverable
SetConditions=Set payment terms
SetMode=Set payment mode
Billed=Billed
RecurringInvoices=Recurring invoices
RepeatableInvoice=Template invoice
RepeatableInvoices=Template invoices
Repeatable=Template

View File

@ -78,12 +78,12 @@ $optioncss = GETPOST('optioncss','alpha');
$mine = $_REQUEST['mode']=='mine' ? 1 : 0;
if ($mine) $search_user = $user->id;
$day = GETPOST('day','int');
$month = GETPOST('month','int');
$year = GETPOST('year','int');
$sday = GETPOST('sday','int');
$smonth = GETPOST('smonth','int');
$syear = GETPOST('syear','int');
$day = GETPOST('day','int');
$month = GETPOST('month','int');
$year = GETPOST('year','int');
if ($search_status == '') $search_status=-1; // -1 or 1
@ -150,12 +150,12 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP
$search_public="";
$search_sale="";
$search_user='';
$day="";
$month="";
$year="";
$sday="";
$smonth="";
$syear="";
$day="";
$month="";
$year="";
$search_array_options=array();
}

View File

@ -28,6 +28,7 @@ require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
$langs->load('projects');
$langs->load('users');
@ -46,6 +47,13 @@ $search_task_user=GETPOST('search_task_user');
$mine = $_REQUEST['mode']=='mine' ? 1 : 0;
if ($mine) $search_task_user = $user->id;
$sday = GETPOST('sday','int');
$smonth = GETPOST('smonth','int');
$syear = GETPOST('syear','int');
$day = GETPOST('day','int');
$month = GETPOST('month','int');
$year = GETPOST('year','int');
// Security check
$socid=0;
if ($user->societe_id > 0) $socid = $user->societe_id;
@ -67,6 +75,12 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP
$search_task_label="";
$search_task_user=-1;
$search_project_user=-1;
$sday='';
$smonth='';
$syear='';
$day='';
$month='';
$year='';
}
if (empty($search_projectstatus) && $search_projectstatus == '') $search_projectstatus=1;
@ -74,7 +88,35 @@ if (empty($search_projectstatus) && $search_projectstatus == '') $search_project
$fieldstosearchall = array(
't.ref'=>"Ref",
't.label'=>"Label",
't.note_public'=>"NotePublic",
);
if (empty($user->socid)) $fieldstosearchall['t.note_private']="NotePrivate";
$arrayfields=array(
'p.ref'=>array('label'=>$langs->trans("Project"), 'checked'=>1),
'p.title'=>array('label'=>$langs->trans("ProjectLabel"), 'checked'=>1),
'p.fk_statut'=>array('label'=>$langs->trans("ProjectStatus"), 'checked'=>1),
//'s.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
't.title'=>array('label'=>$langs->trans("TaskLabel"), 'checked'=>1, 'position'=>80),
't.dateo'=>array('label'=>$langs->trans("DateStart"), 'checked'=>1, 'position'=>100),
't.datee'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1, 'position'=>101),
't.planned_workload'=>array('label'=>$langs->trans("Workload"), 'checked'=>1, 'position'=>102),
't.duration_effective'=>array('label'=>$langs->trans("TimeConsumed"), 'checked'=>1, 'position'=>103),
// Calculated progression
't.progress'=>array('label'=>$langs->trans("TimeDeclared"), 'checked'=>1, 'position'=>105),
't.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
't.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
't.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
);
// Extra fields
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
{
foreach($extrafields->attribute_label as $key => $val)
{
$arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
}
}
/*
@ -89,6 +131,7 @@ $fieldstosearchall = array(
*/
$form=new Form($db);
$formother=new FormOther($db);
$projectstatic = new Project($db);
$taskstatic = new Task($db);
$puser=new User($db);
@ -121,15 +164,43 @@ else
$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1,$socid);
//var_dump($projectsListId);
// Get list of tasks in tasksarray and taskarrayfiltered
// We need all tasks (even not limited to a user because a task assigned to a user can have a parent that is not assigned to him and we need such parents).
$morewherefilter='';
if ($search_all) $morewherefilter.=natural_search(array_keys($fieldstosearchall), $search_all);
if ($search_task_ref) $morewherefilter.=natural_search('t.ref', $search_task_ref);
if ($search_task_label) $morewherefilter.=natural_search('t.label', $search_task_label);
if ($smonth > 0)
{
if ($syear > 0 && empty($sday))
$morewherefilter.= " AND t.dateo BETWEEN '".$db->idate(dol_get_first_day($syear,$smonth,false))."' AND '".$db->idate(dol_get_last_day($syear,$smonth,false))."'";
else if ($syear > 0 && ! empty($sday))
$morewherefilter.= " AND t.dateo BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $smonth, $sday, $syear))."'";
else
$morewherefilter.= " AND date_format(t.dateo, '%m') = '".$smonth."'";
}
else if ($syear > 0)
{
$morewherefilter.= " AND t.dateo BETWEEN '".$db->idate(dol_get_first_day($syear,1,false))."' AND '".$db->idate(dol_get_last_day($syear,12,false))."'";
}
if ($month > 0)
{
if ($year > 0 && empty($day))
$morewherefilter.= " AND t.datee BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
else if ($year > 0 && ! empty($day))
$morewherefilter.= " AND t.datee BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
else
$morewherefilter.= " AND date_format(t.datee, '%m') = '".$month."'";
}
else if ($year > 0)
{
$morewherefilter.= " AND t.datee BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
}
$tasksarray=$taskstatic->getTasksArray(0, 0, $projectstatic->id, $socid, 0, $search_project, $search_projectstatus, $morewherefilter, $search_project_user, 0); // We don't use filter on task user. Because sometimes a task is assigned but not the parent one and we want to show also parent, so filtering is done during output
$tasksrole=$taskstatic->getUserRolesForProjectsOrTasks(0, ($tuser->id?$tuser:null), $projectstatic->id, 0, $search_projectstatus); // We load also tasks limited to a particular user
//$tasksarray=$taskstatic->getTasksArray(0, 0, $projectstatic->id, $socid, 0, $search_project, $search_projectstatus, $morewherefilter, $search_project_user, 0); // We don't use filter on task user. Because sometimes a task is assigned but not the parent one and we want to show also parent, so filtering is done during output
//$tasksrole=$taskstatic->getUserRolesForProjectsOrTasks(0, ($tuser->id?$tuser:null), $projectstatic->id, 0, $search_projectstatus); // We load also tasks limited to a particular user
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
@ -142,7 +213,7 @@ print '<input type="hidden" name="type" value="'.$type.'">';
if ($search_all)
{
foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
print $langs->trans("FilterOnInto", $search_all, join(', ',$fieldstosearchall));
print $langs->trans("FilterOnInto", $search_all) . join(', ',$fieldstosearchall);
}
@ -205,15 +276,34 @@ print '</td>';
print '<td class="liste_titre">';
print '<input type="text" class="flat" name="search_task_label" value="'.dol_escape_htmltag($search_task_label).'" size="8">';
print '</td>';
print '<td class="liste_titre" colspan="5">';
// Start date
if (! empty($arrayfields['t.dateo']['checked']))
{
print '<td class="liste_titre center">';
if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="sday" value="'.$sday.'">';
print '<input class="flat" type="text" size="1" maxlength="2" name="smonth" value="'.$smonth.'">';
$formother->select_year($syear?$syear:-1,'syear',1, 20, 5);
print '</td>';
}
// End date
if (! empty($arrayfields['t.datee']['checked']))
{
print '<td class="liste_titre center">';
if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
$formother->select_year($year?$year:-1,'year',1, 20, 5);
print '</td>';
}
print '<td class="liste_titre" colspan="3">';
print '&nbsp;';
print '<td class="liste_titre nowrap" align="right">';
print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("RemoveFilter"),'searchclear.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
print '</td>';
print '</tr>';
/*
$max=10000;
if (count($tasksarray) > (empty($conf->global->PROJECT_LIMIT_TASK_PROJECT_AREA)?$max:$conf->global->PROJECT_LIMIT_TASK_PROJECT_AREA))
{
$langs->load("errors");
@ -226,9 +316,14 @@ else
{
// Show all lines in taskarray (recursive function to go down on tree)
$j=0; $level=0;
if ($morewherefilter) $level=-1; // No recursive output when there is search criteria
//var_dump($tasksarray);
$nboftaskshown=projectLinesa($j, 0, $tasksarray, $level, true, 1, $tasksrole, $projectsListId, 0);
}
*/
print "</table>";