Skip to content
Snippets Groups Projects
Commit b326c508 authored by Regis Houssin's avatar Regis Houssin
Browse files

Works on enhancement of project tasks

parent 034c01db
No related branches found
No related tags found
No related merge requests found
......@@ -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 '<select class="flat" name="'.$htmlname.'">';
print '<option value="0" selected="true">&nbsp;</option>';
//print '<option value="0" selected="true">&nbsp;</option>';
$j=0;
$level=0;
PLineSelect($j, 0, $tasksarray, $level);
PLineSelect($j, 0, $tasksarray, $level, $selected);
print '</select>';
}
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 '<option value="'.$lines[$i]->projectid.'_'.$lines[$i]->id.'">';
print '<option value="'.$lines[$i]->projectid.'_'.$lines[$i]->id.'"';
if ($lines[$i]->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--;
}
}
......
......@@ -138,7 +138,7 @@ if ($_GET["action"] == 'create' && $user->rights->projet->creer)
print '</td></tr>';
print '<tr><td>'.$langs->trans("ChildOfTask").'</td><td>';
print $formother->selectProjectTasks($projectid, 'task_parent', $user->admin?0:1, 0, 1);
print $formother->selectProjectTasks('',$projectid, 'task_parent', $user->admin?0:1, 0);
print '</td></tr>';
print '<tr><td>'.$langs->trans("AffectedTo").'</td><td>';
......
......@@ -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)
......
......@@ -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 '<td><input size="30" name="label" value="'.$task->label.'"></td></tr>';
print '<tr><td>'.$langs->trans("Project").'</td><td colspan="3">';
print $projet->getNomUrl(1);
print $projectstatic->getNomUrl(1);
print '</td></tr>';
print '<td>'.$langs->trans("Company").'</td><td colspan="3">';
if ($projet->societe->id) print $projet->societe->getNomUrl(1);
if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1);
else print '&nbsp;';
print '</td></tr>';
print '<tr><td>'.$langs->trans("ChildOfTask").'</td><td>';
print $formother->selectProjectTasks($task->fk_task_parent,$projectstatic->id, 'task_parent', $user->admin?0:1, 0);
print '</td></tr>';
// Date start
print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
print $html->select_date($task->date_start,'dateo');
......@@ -204,11 +209,11 @@ if ($taskid)
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$task->label.'</td></tr>';
print '<tr><td>'.$langs->trans("Project").'</td><td colspan="3">';
print $projet->getNomUrl(1);
print $projectstatic->getNomUrl(1);
print '</td></tr>';
print '<td>'.$langs->trans("Company").'</td><td colspan="3">';
if ($projet->societe->id) print $projet->societe->getNomUrl(1);
if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1);
else print '&nbsp;';
print '</td></tr>';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment