diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 20145bd0b0d..fecead20822 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -527,6 +527,7 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t * * @param string $inc Line number (start to 0, then increased by recursive call) * @param string $parent Id of parent task to show (0 to show all) + * @param User|null $fuser Restrict list to user if defined * @param Task[] $lines Array of lines * @param int $level Level (start to 0, then increased/decrease by recursive call) * @param string $projectsrole Array of roles user has on project @@ -537,13 +538,13 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t * @param boolean $var Var for css of lines * @return $inc */ -function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask=1, $preselectedday='', $var=false) +function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask=1, $preselectedday='', $var=false) { global $db, $user, $bc, $langs; global $form, $formother, $projectstatic, $taskstatic; $lastprojectid=0; - $workloadloadforid=array(); + $workloadforid=array(); $lineswithoutlevel0=array(); $numlines=count($lines); @@ -647,7 +648,7 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t // Time spent by user print ''; - $tmptimespent=$taskstatic->getSummaryOfTimeSpent(); + $tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id); if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin'); else print '--:--'; print "\n"; @@ -704,8 +705,8 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t $level++; if ($lines[$i]->id > 0) { - if ($parent == 0) projectLinesPerDay($inc, $lines[$i]->id, $lineswithoutlevel0, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $var); - else projectLinesPerDay($inc, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $var); + if ($parent == 0) projectLinesPerDay($inc, $lines[$i]->id, $fuser, $lineswithoutlevel0, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $var); + else projectLinesPerDay($inc, $lines[$i]->id, $fuser, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $var); } $level--; } @@ -744,7 +745,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ $numlines=count($lines); $lastprojectid=0; - $workloadloadforid=array(); + $workloadforid=array(); $lineswithoutlevel0=array(); // Create a smaller array with sublevels only to be used later. This increase dramatically performances. @@ -840,7 +841,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ // Time spent by user print ''; - $tmptimespent=$taskstatic->getSummaryOfTimeSpent(); + $tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id); if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin'); else print '--:--'; print "\n"; diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index eb5e3f9402b..fe21b3558ba 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -11,8 +11,10 @@ SharedProject=Everybody PrivateProject=Project contacts MyProjectsDesc=This view is limited to projects you are a contact for (whatever is the type). ProjectsPublicDesc=This view presents all projects you are allowed to read. +TasksOnProjectsPublicDesc=This view presents all tasks on projects you are allowed to read. ProjectsPublicTaskDesc=This view presents all projects and tasks you are allowed to read. ProjectsDesc=This view presents all projects (your user permissions grant you permission to view everything). +TasksOnProjectsDesc=This view presents all tasks on all projects (your user permissions grant you permission to view everything). MyTasksDesc=This view is limited to projects or tasks you are a contact for (whatever is the type). OnlyOpenedProject=Only open projects are visible (projects in draft or closed status are not visible). ClosedProjectsAreHidden=Closed projects are not visible. diff --git a/htdocs/projet/activity/perday.php b/htdocs/projet/activity/perday.php index ada7e0bb7d4..07918c4bfbf 100644 --- a/htdocs/projet/activity/perday.php +++ b/htdocs/projet/activity/perday.php @@ -87,7 +87,7 @@ if (GETPOST('submitdateselect')) } -if ($action == 'addtime' && GETPOST('assigntask')) +if ($action == 'addtime' && $user->rights->projet->lire && GETPOST('assigntask')) { $action = 'assigntask'; @@ -163,7 +163,7 @@ if ($action == 'addtime' && GETPOST('assigntask')) $action=''; } -if ($action == 'addtime' && $user->rights->projet->creer) +if ($action == 'addtime' && $user->rights->projet->lire) { $timespent_duration=array(); @@ -395,7 +395,7 @@ $restrictviewformytask=(empty($conf->global->PROJECT_TIME_SHOW_TASK_NOT_ASSIGNED if (count($tasksarray) > 0) { $j=0; - projectLinesPerDay($j, 0, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restrictviewformytask, $daytoparse); + projectLinesPerDay($j, 0, $usertoprocess, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restrictviewformytask, $daytoparse); } else { diff --git a/htdocs/projet/activity/perweek.php b/htdocs/projet/activity/perweek.php index 57da487aee0..5bf60d426d8 100644 --- a/htdocs/projet/activity/perweek.php +++ b/htdocs/projet/activity/perweek.php @@ -176,7 +176,7 @@ if ($action == 'addtime' && GETPOST('assigntask')) $action=''; } -if ($action == 'addtime' && $user->rights->projet->creer) +if ($action == 'addtime' && $user->rights->projet->lire) { $timetoadd=$_POST['task']; if (empty($timetoadd)) diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 42260a9b66f..631b2684246 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -914,9 +914,10 @@ class Task extends CommonObject /** * Calculate total of time spent for task * + * @param int $userid Filter on user id. 0=No filter * @return array Array of info for task array('min_date', 'max_date', 'total_duration') */ - function getSummaryOfTimeSpent() + function getSummaryOfTimeSpent($userid=0) { global $langs; @@ -935,7 +936,8 @@ class Task extends CommonObject $sql.= " SUM(t.task_duration) as total_duration"; $sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time as t"; $sql.= " WHERE t.fk_task = ".$id; - + if ($userid > 0) $sql.=" AND t.fk_user = ".$userid; + dol_syslog(get_class($this)."::getSummaryOfTimeSpent", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php index 3d61c96299b..9def807c746 100644 --- a/htdocs/projet/tasks.php +++ b/htdocs/projet/tasks.php @@ -37,6 +37,7 @@ $langs->load("projects"); $action = GETPOST('action', 'alpha'); $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); +$taskref = GETPOST('taskref', 'alpha'); $backtopage=GETPOST('backtopage','alpha'); $cancel=GETPOST('cancel'); @@ -88,7 +89,13 @@ if ($action == 'createtask' && $user->rights->projet->creer) if (! $cancel) { - if (empty($label)) + if (empty($taskref)) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors'); + $action='create'; + $error++; + } + if (empty($label)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); $action='create'; @@ -112,7 +119,7 @@ if ($action == 'createtask' && $user->rights->projet->creer) $task = new Task($db); $task->fk_project = $projectid; - $task->ref = GETPOST('ref','alpha'); + $task->ref = $taskref; $task->label = $label; $task->description = $description; $task->planned_workload = $planned_workload; @@ -121,7 +128,7 @@ if ($action == 'createtask' && $user->rights->projet->creer) $task->date_start = $date_start; $task->date_end = $date_end; $task->progress = $progress; - + // Fill array 'array_options' with data from add form $ret = $extrafields_task->setOptionalsFromPost($extralabels_task,$task); @@ -279,7 +286,6 @@ if ($action == 'create' && $user->rights->projet->creer && (empty($object->third print ''; if (! empty($object->id)) print ''; if (! empty($mode)) print ''; - print ''; dol_fiche_head(''); @@ -297,7 +303,10 @@ if ($action == 'create' && $user->rights->projet->creer && (empty($object->third if (is_numeric($defaultref) && $defaultref <= 0) $defaultref=''; // Ref - print ''.$langs->trans("Ref").''.($_POST["ref"]?$_POST["ref"]:$defaultref).''; + print ''.$langs->trans("Ref").''; + print ($_POST["ref"]?$_POST["ref"]:$defaultref); + print ''; + print ''; print ''.$langs->trans("Label").''; print ''; diff --git a/htdocs/projet/tasks/list.php b/htdocs/projet/tasks/list.php index cbef511bae7..47083e9032d 100644 --- a/htdocs/projet/tasks/list.php +++ b/htdocs/projet/tasks/list.php @@ -241,7 +241,7 @@ if ($search_task_user > 0) } $sql.= " WHERE t.fk_projet = p.rowid"; $sql.= " AND p.entity IN (".getEntity('project',1).')'; -if (! $user->rights->projet->all->lire) $sql.=" p.rowid IN (".join(',',$projectsListId).")"; // public and assigned to projects, or restricted to company for external users +if (! $user->rights->projet->all->lire) $sql.=" AND p.rowid IN (".($projectsListId?$projectsListId:'0').")"; // public and assigned to projects, or restricted to company for external users // No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; if ($search_project_ref) $sql .= natural_search('p.ref', $search_project_ref); @@ -307,7 +307,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) } $sql.= $db->plimit($limit + 1,$offset); - +//print $sql; dol_syslog("list allowed project", LOG_DEBUG); //print $sql; @@ -362,8 +362,8 @@ if ($resql) if ($search_task_user == $user->id) print $langs->trans("MyTasksDesc").'

'; else { - if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("ProjectsDesc").'

'; - else print $langs->trans("ProjectsPublicDesc").'

'; + if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("TasksOnProjectsDesc").'

'; + else print $langs->trans("TasksOnProjectsPublicDesc").'

'; } if ($search_all) diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index 5b3b8c9fe61..55b286047d9 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -38,6 +38,7 @@ $langs->load("companies"); $id=GETPOST('id','int'); $ref=GETPOST("ref",'alpha',1); +$taskref=GETPOST("taskref",'alpha'); $action=GETPOST('action','alpha'); $confirm=GETPOST('confirm','alpha'); $withproject=GETPOST('withproject','int'); @@ -68,6 +69,11 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer) { $error=0; + if (empty($taskref)) + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors'); + } if (empty($_POST["label"])) { $error++; @@ -81,7 +87,7 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer) $task_parent=$tmparray[1]; if (empty($task_parent)) $task_parent = 0; // If task_parent is '' - $object->ref = GETPOST("ref",'alpha',2); + $object->ref = $taskref?$taskref:GETPOST("ref",'alpha',2); $object->label = $_POST["label"]; $object->description = $_POST['description']; $object->fk_task_parent = $task_parent; @@ -223,7 +229,7 @@ if ($id > 0 || ! empty($ref)) $linkback = ''.$langs->trans("BackToList").''; // Ref - print ''; + print ''; print $langs->trans("Ref"); print ''; // Define a complementary filter for search of next/prev ref. @@ -310,11 +316,11 @@ if ($id > 0 || ! empty($ref)) print ''; // Ref - print ''; - print ''; + print ''; + print ''; // Label - print ''; + print ''; print ''; // Project @@ -399,7 +405,7 @@ if ($id > 0 || ! empty($ref)) print '
'.$langs->trans("Ref").'
'.$langs->trans("Ref").'
'.$langs->trans("Label").'
'.$langs->trans("Label").'
'; // Ref - print '
'; + print '
'; print $langs->trans("Ref"); print ''; if (! GETPOST('withproject') || empty($projectstatic->id))