diff --git a/htdocs/html.formother.class.php b/htdocs/html.formother.class.php index 5e2ada84236..f5bdb67d821 100644 --- a/htdocs/html.formother.class.php +++ b/htdocs/html.formother.class.php @@ -235,12 +235,13 @@ class FormOther /** * \brief Retourn list of project and tasks * \param selected Pre-selected value + * \param projectid Project id * \param htmlname Name of html select * \param modeproject 1 to restrict on projects owned by user * \param modetask 1 to restrict on tasks associated to user * \param mode 0=Return list of tasks and their projects, 1=Return projects and tasks if exists */ - function selectProjectTasks($selected='',$htmlname='task_parent', $modeproject=0, $modetask=0, $mode) + function selectProjectTasks($selected='', $projectid=0, $htmlname='task_parent', $modeproject=0, $modetask=0) { global $user, $langs; @@ -248,14 +249,14 @@ class FormOther //print $modeproject.'-'.$modetask; $task=new Task($this->db); - $tasksarray=$task->getTasksArray($modetask?$user:0, $modeproject?$user:0, $selected); + $tasksarray=$task->getTasksArray($modetask?$user:0, $modeproject?$user:0, $projectid); if ($tasksarray) { print ''; - print ' '; + //print ' '; $j=0; $level=0; - PLineSelect($j, 0, $tasksarray, $level); + PLineSelect($j, 0, $tasksarray, $level, $selected); print ''; } else @@ -343,7 +344,7 @@ class FormOther * @param unknown_type $lines * @param unknown_type $level */ -function PLineSelect(&$inc, $parent, $lines, $level=0) +function PLineSelect(&$inc, $parent, $lines, $level=0, $selected=0) { global $langs, $user, $conf; @@ -382,7 +383,9 @@ function PLineSelect(&$inc, $parent, $lines, $level=0) // Print task if ($lines[$i]->id > 0) { - print ''; + print 'id == $selected) print ' selected="true"'; + print '>'; print $langs->trans("Project").' '.$lines[$i]->projectref; if ($lines[$i]->name || $lines[$i]->fistname) { @@ -402,7 +405,7 @@ function PLineSelect(&$inc, $parent, $lines, $level=0) } $level++; - if ($lines[$i]->id) PLineSelect($inc, $lines[$i]->id, $lines, $level); + if ($lines[$i]->id) PLineSelect($inc, $lines[$i]->id, $lines, $level, $selected); $level--; } } diff --git a/htdocs/projet/tasks/fiche.php b/htdocs/projet/tasks/fiche.php index d82c1d91de2..648d7c4b00b 100644 --- a/htdocs/projet/tasks/fiche.php +++ b/htdocs/projet/tasks/fiche.php @@ -138,7 +138,7 @@ if ($_GET["action"] == 'create' && $user->rights->projet->creer) print ''; print ''.$langs->trans("ChildOfTask").''; - print $formother->selectProjectTasks($projectid, 'task_parent', $user->admin?0:1, 0, 1); + print $formother->selectProjectTasks('',$projectid, 'task_parent', $user->admin?0:1, 0); print ''; print ''.$langs->trans("AffectedTo").''; diff --git a/htdocs/projet/tasks/task.class.php b/htdocs/projet/tasks/task.class.php index 262c06c2327..e4a99d43fe4 100644 --- a/htdocs/projet/tasks/task.class.php +++ b/htdocs/projet/tasks/task.class.php @@ -443,7 +443,6 @@ class Task extends CommonObject $sql.= ", t.rowid, t.label, t.description, t.fk_task_parent, t.duration_effective"; $sql.= " FROM ".MAIN_DB_PREFIX."projet_task as t"; $sql.= ", ".MAIN_DB_PREFIX."projet as p"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid"; $sql.= " WHERE t.fk_projet = p.rowid"; $sql.= " AND p.entity = ".$conf->entity; if ($socid) $sql.= " AND p.fk_soc = ".$socid; @@ -458,20 +457,33 @@ class Task extends CommonObject $i = 0; while ($i < $num) { + $error=0; + $obj = $this->db->fetch_object($resql); - $tasks[$i]->id = $obj->rowid; - $tasks[$i]->projectid = $obj->projectid; - $tasks[$i]->projectref = $obj->ref; - $tasks[$i]->projectlabel = $obj->plabel; - $tasks[$i]->label = $obj->label; - $tasks[$i]->description = $obj->description; - $tasks[$i]->fk_parent = $obj->fk_task_parent; - $tasks[$i]->duration = $obj->duration_effective; - $tasks[$i]->name = $obj->name; // Name of project leader - $tasks[$i]->firstname = $obj->firstname; // Firstname of project leader + + if ($usert || $userp) + { + if (! $this->getTasksRoleForUser($usert?$usert:$userp,$userp?$obj->projectid:0,$usert?$obj->rowid:0)) + { + $error++; + } + } + + if (!$error) + { + $tasks[$i]->id = $obj->rowid; + $tasks[$i]->projectid = $obj->projectid; + $tasks[$i]->projectref = $obj->ref; + $tasks[$i]->projectlabel = $obj->plabel; + $tasks[$i]->label = $obj->label; + $tasks[$i]->description = $obj->description; + $tasks[$i]->fk_parent = $obj->fk_task_parent; + $tasks[$i]->duration = $obj->duration_effective; + } + $i++; } - $this->db->free(); + $this->db->free($resql); } else { @@ -482,12 +494,12 @@ class Task extends CommonObject } /** - * Return array of role of user for each projects + * Return array of role of user for each projects or tasks * * @param unknown_type $user * @return unknown */ - function getTasksRoleForUser($user,$projectid=0) + function getTasksRoleForUser($user,$projectid=0,$taskid=0) { $tasksrole = array(); @@ -500,7 +512,8 @@ class Task extends CommonObject $sql.= " AND ctc.element = '".$this->element."'"; $sql.= " AND ctc.rowid = ec.fk_c_type_contact"; $sql.= " AND ec.fk_socpeople = ".$user->id; - if ($projectid) $sql.= " AND pt.fk_projet =".$projectid; + if ($projectid) $sql.= " AND pt.fk_projet = ".$projectid; + if ($taskid) $sql.= " AND pt.rowid = ".$taskid; $resql = $this->db->query($sql); if ($resql) diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index 3dc308602bf..2c482ac013a 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -51,10 +51,14 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->projet- { $task = new Task($db); $task->fetch($_POST["id"]); + + $tmparray=explode('_',$_POST['task_parent']); + $task_parent=$tmparray[1]; + if (empty($task_parent)) $task_parent = 0; // If task_parent is '' $task->label = $_POST["label"]; $task->description = $_POST['description']; - //$task->fk_task_parent = $task_parent; + $task->fk_task_parent = $task_parent; $task->date_start = dol_mktime(12,0,0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear']); $task->date_end = dol_mktime(12,0,0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear']); $task->progress = $_POST['progress']; @@ -106,18 +110,15 @@ llxHeader("",$langs->trans("Task")); $html = new Form($db); $formother = new FormOther($db); -$projectstatic = new Project($db); - - if ($taskid) { $task = new Task($db); + $projectstatic = new Project($db); if ($task->fetch($taskid) >= 0 ) { - $projet = new Project($db); - $result=$projet->fetch($task->fk_project); - if (! empty($projet->socid)) $projet->societe->fetch($projet->socid); + $result=$projectstatic->fetch($task->fk_project); + if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); $head=task_prepare_head($task); @@ -143,14 +144,18 @@ if ($taskid) print ''; print ''.$langs->trans("Project").''; - print $projet->getNomUrl(1); + print $projectstatic->getNomUrl(1); print ''; print ''.$langs->trans("Company").''; - if ($projet->societe->id) print $projet->societe->getNomUrl(1); + if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1); else print ' '; print ''; + print ''.$langs->trans("ChildOfTask").''; + print $formother->selectProjectTasks($task->fk_task_parent,$projectstatic->id, 'task_parent', $user->admin?0:1, 0); + print ''; + // Date start print ''.$langs->trans("DateStart").''; print $html->select_date($task->date_start,'dateo'); @@ -204,11 +209,11 @@ if ($taskid) print ''.$langs->trans("Label").''.$task->label.''; print ''.$langs->trans("Project").''; - print $projet->getNomUrl(1); + print $projectstatic->getNomUrl(1); print ''; print ''.$langs->trans("Company").''; - if ($projet->societe->id) print $projet->societe->getNomUrl(1); + if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1); else print ' '; print '';