Fix several bugs into projects

This commit is contained in:
Laurent Destailleur 2016-07-09 13:58:46 +02:00
parent 8504e09e72
commit 0e4dcb301c
8 changed files with 48 additions and 28 deletions

View File

@ -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 '<td align="right">';
$tmptimespent=$taskstatic->getSummaryOfTimeSpent();
$tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id);
if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin');
else print '--:--';
print "</td>\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 '<td align="right">';
$tmptimespent=$taskstatic->getSummaryOfTimeSpent();
$tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id);
if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin');
else print '--:--';
print "</td>\n";

View File

@ -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.

View File

@ -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
{

View File

@ -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))

View File

@ -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)

View File

@ -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 '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
if (! empty($object->id)) print '<input type="hidden" name="id" value="'.$object->id.'">';
if (! empty($mode)) print '<input type="hidden" name="mode" value="'.$mode.'">';
print '<input type="hidden" name="ref" value="'.($_POST["ref"]?$_POST["ref"]:$defaultref).'">';
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 '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("Ref").'</span></td><td>'.($_POST["ref"]?$_POST["ref"]:$defaultref).'</td></tr>';
print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("Ref").'</span></td><td>';
print ($_POST["ref"]?$_POST["ref"]:$defaultref);
print '<input type="hidden" name="taskref" value="'.($_POST["ref"]?$_POST["ref"]:$defaultref).'">';
print '</td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
print '<input type="text" size="25" name="label" class="flat" value="'.$label.'">';

View File

@ -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").'<br><br>';
else
{
if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("ProjectsDesc").'<br><br>';
else print $langs->trans("ProjectsPublicDesc").'<br><br>';
if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("TasksOnProjectsDesc").'<br><br>';
else print $langs->trans("TasksOnProjectsPublicDesc").'<br><br>';
}
if ($search_all)

View File

@ -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 = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';
// Ref
print '<tr><td width="30%">';
print '<tr><td class="titlefield">';
print $langs->trans("Ref");
print '</td><td>';
// Define a complementary filter for search of next/prev ref.
@ -310,11 +316,11 @@ if ($id > 0 || ! empty($ref))
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="30%">'.$langs->trans("Ref").'</td>';
print '<td><input size="12" name="ref" value="'.$object->ref.'"></td></tr>';
print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Ref").'</td>';
print '<td><input size="12" name="taskref" value="'.$object->ref.'"></td></tr>';
// Label
print '<tr><td>'.$langs->trans("Label").'</td>';
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td>';
print '<td><input size="30" name="label" value="'.$object->label.'"></td></tr>';
// Project
@ -399,7 +405,7 @@ if ($id > 0 || ! empty($ref))
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="30%">';
print '<tr><td class="titlefield">';
print $langs->trans("Ref");
print '</td><td colspan="3">';
if (! GETPOST('withproject') || empty($projectstatic->id))