Fix: A lot of fix in project permissions

This commit is contained in:
Laurent Destailleur 2010-02-21 17:01:45 +00:00
parent fdda3198e1
commit bda51b47a6
9 changed files with 43 additions and 33 deletions

View File

@ -211,7 +211,7 @@ function select_projects($socid, $selected='', $htmlname='projectid')
* @param unknown_type $tasksrole
* @return unknown
*/
function PLinesb(&$inc, $parent, $lines, &$level, &$tasksrole)
function PLinesb(&$inc, $parent, $lines, &$level, &$projectsrole)
{
global $user, $bc, $langs;
global $form;
@ -235,6 +235,8 @@ function PLinesb(&$inc, $parent, $lines, &$level, &$tasksrole)
print "<td>";
$projectstatic->id=$lines[$i]->projectid;
$projectstatic->ref=$lines[$i]->projectref;
$projectstatic->public=$lines[$i]->public;
$projectstatic->label=$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->projectid];
print $projectstatic->getNomUrl(1);
print "</td>";
@ -262,14 +264,17 @@ function PLinesb(&$inc, $parent, $lines, &$level, &$tasksrole)
print '<td align="right">'.$heure."&nbsp;h&nbsp;".$minutes."</td>\n";
$disabled=1;
//print "x".$lines[$i]->projectid;
//var_dump($lines[$i]);
//var_dump($projectsrole[$lines[$i]->projectid]);
// If at least one role for project
if (! empty($tasksrole[$lines[$i]->id])
&& sizeof($tasksrole[$lines[$i]->id]) > 0) $disabled=0;
if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->projectid])) $disabled=0;
print '<td nowrap="nowrap">';
print $form->select_date('',$lines[$i]->id,'','','',"addtime");
print '&nbsp;<input size="4" type="text" class="flat"'.($disabled?' disabled="true"':'').' name="task'.$lines[$i]->id.'" value="">';
print '&nbsp;<input type="submit" class="button"'.($disabled?' disabled="true"':'').' value="'.$langs->trans("Add").'">';
if ((! $lines[$i]->public) && $disabled) print '('.$langs->trans("YouAreNotContactOfProject").')';
print '</td>';
print "<td>&nbsp;";
print '</td>';
@ -277,7 +282,7 @@ function PLinesb(&$inc, $parent, $lines, &$level, &$tasksrole)
print "</tr>\n";
$inc++;
$level++;
if ($lines[$i]->id) PLinesb($inc, $lines[$i]->id, $lines, $level, $tasksrole);
if ($lines[$i]->id) PLinesb($inc, $lines[$i]->id, $lines, $level, $projectsrole);
$level--;
}
else
@ -298,7 +303,7 @@ function PLinesb(&$inc, $parent, $lines, &$level, &$tasksrole)
* @param $level Level of task
* @param $var Color
* @param $showproject Show project columns
* @param $taskrole Array of tasks filtered on a particular user
* @param $taskrole Array of roles of user for each tasks
*/
function PLines(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole)
{
@ -358,9 +363,11 @@ function PLines(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole
if ($showproject)
{
print "<td>";
//var_dump($taskrole);
if ($showlineingray) print '<i>';
$projectstatic->id=$lines[$i]->projectid;
$projectstatic->ref=$lines[$i]->projectref;
$projectstatic->public=$lines[$i]->public;
print $projectstatic->getNomUrl(1);
if ($showlineingray) print '</i>';
print "</td>";
@ -376,6 +383,7 @@ function PLines(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole
{
$taskstatic->id=$lines[$i]->id;
$taskstatic->ref=$lines[$i]->id;
$taskstatic->label=($taskrole[$lines[$i]->id]?$langs->trans("YourRole").': '.$taskrole[$lines[$i]->id]:'');
print $taskstatic->getNomUrl(1);
}
print '</td>';

View File

@ -112,9 +112,9 @@ print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorde
if ($mesg) print $mesg;
$tasksarray=$task->getTasksArray(0,0,$project->id,$socid);
$tasksrole=$task->getUserRolesForProjectsOrTasks($user,0,$project->id,0);
$projectsrole=$task->getUserRolesForProjectsOrTasks($user,0,$project->id,0);
//var_dump($tasksarray);
//var_dump($tasksrole);
//var_dump($projectsrole);
print '<form name="addtime" method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$project->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@ -128,7 +128,7 @@ print '<td>'.$langs->trans("LabelTask").'</td>';
print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
print '<td colspan="2">'.$langs->trans("AddDuration").'</td>';
print "</tr>\n";
PLinesb($j, 0, $tasksarray, $level, $tasksrole);
PLinesb($j, 0, $tasksarray, $level, $projectsrole);
print '</form>';

View File

@ -179,7 +179,7 @@ if ($id > 0 || ! empty($ref))
$userAccess = $project->restrictedProjectArea($user);
$head = project_prepare_head($project);
dol_fiche_head($head, 'contact', $langs->trans("Project"), 0, 'project');
dol_fiche_head($head, 'contact', $langs->trans("Project"), 0, ($project->public?'projectpub':'project'));
/*

View File

@ -73,7 +73,7 @@ $project->societe->fetch($project->societe->id);
$userAccess = $project->restrictedProjectArea($user);
$head=project_prepare_head($project);
dol_fiche_head($head, 'element', $langs->trans("Project"),0,'project');
dol_fiche_head($head, 'element', $langs->trans("Project"),0,($project->public?'projectpub':'project'));
print '<table class="border" width="100%">';

View File

@ -318,7 +318,7 @@ else
$userAccess = $project->restrictedProjectArea($user);
$head=project_prepare_head($project);
dol_fiche_head($head, 'project', $langs->trans("Project"),0,'project');
dol_fiche_head($head, 'project', $langs->trans("Project"),0,($project->public?'projectpub':'project'));
// Confirmation validation
if ($_GET['action'] == 'validate')

View File

@ -109,7 +109,7 @@ if ($id > 0 || ! empty($ref))
$userAccess = $project->restrictedProjectArea($user);
$head = project_prepare_head($project);
dol_fiche_head($head, 'note', $langs->trans('Project'), 0, 'project');
dol_fiche_head($head, 'note', $langs->trans('Project'), 0, ($project->public?'projectpub':'project'));
print '<table class="border" width="100%">';

View File

@ -519,9 +519,10 @@ class Project extends CommonObject
$lien = '<a href="'.DOL_URL_ROOT.'/projet/fiche.php?id='.$this->id.'">';
$lienfin='</a>';
$picto='project';
$picto='projectpub';
if (! $this->public) $picto='project';
$label=$langs->trans("ShowProject").': '.$this->ref;
$label=$langs->trans("ShowProject").': '.$this->ref.($this->label?' - '.$this->label:'');
if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin);
if ($withpicto && $withpicto != 2) $result.=' ';
@ -604,7 +605,7 @@ class Project extends CommonObject
$xnbp++;
}
}
/**
* \brief Check permissions
*/
@ -622,7 +623,7 @@ class Project extends CommonObject
{
$userRole = $this->liste_contact(4,$source);
$num=sizeof($userRole);
$i = 0;
while ($i < $num)
{
@ -634,7 +635,7 @@ class Project extends CommonObject
}
}
}
if (!$userAccess && !$this->public)
{
if (!$list)
@ -645,12 +646,12 @@ class Project extends CommonObject
{
return -1;
}
}
return $userAccess;
}
/**
* Return array of projects authorized for a user
*
@ -669,7 +670,7 @@ class Project extends CommonObject
$sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
$sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
$sql.= " WHERE p.entity = ".$conf->entity;
if ($mine)
{
$sql.= " AND ec.element_id = p.rowid";
@ -699,9 +700,9 @@ class Project extends CommonObject
$temp[] = $row[0];
$i++;
}
$this->db->free($resql);
if ($list)
{
if (empty($temp)) return 0;

View File

@ -206,7 +206,7 @@ else
if ($_REQUEST["mode"]=='mine') $tab='mytasks';
$head=project_prepare_head($project);
dol_fiche_head($head, $tab, $langs->trans("Project"),0,'project');
dol_fiche_head($head, $tab, $langs->trans("Project"),0,($project->public?'projectpub':'project'));
$param=($_REQUEST["mode"]=='mine'?'&mode=mine':'');

View File

@ -398,7 +398,7 @@ class Task extends CommonObject
$picto='projecttask';
$label=$langs->trans("ShowTask").': '.$this->ref;
$label=$langs->trans("ShowTask").': '.$this->ref.($this->label?' - '.$this->label:'');
if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin);
if ($withpicto && $withpicto != 2) $result.=' ';
@ -520,6 +520,7 @@ class Task extends CommonObject
*/
function getUserRolesForProjectsOrTasks($userp,$usert,$projectid=0,$taskid=0)
{
$projectsrole = array();
$tasksrole = array();
dol_syslog("Task::getUserRolesForProjectsOrTasks userp=".is_object($userp)." usert=".is_object($usert)." projectid=".$projectid." taskid=".$taskid);
@ -531,8 +532,8 @@ class Task extends CommonObject
return -1;
}
/* Liste des taches et role sur la tache du user courant dans $tasksrole */
$sql = "SELECT ec.element_id, ctc.code";
/* Liste des taches et role sur les projets ou taches */
$sql = "SELECT pt.rowid as pid, ec.element_id, ctc.code";
if ($userp) $sql.= " FROM ".MAIN_DB_PREFIX."projet as pt";
if ($usert) $sql.= " FROM ".MAIN_DB_PREFIX."projet_task as pt";
$sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
@ -546,8 +547,8 @@ class Task extends CommonObject
$sql.= " AND ec.statut = 4";
if ($projectid)
{
if ($userp || $usert) $sql.= " AND pt.fk_projet = ".$projectid;
//if ($usert) $sql.= " AND pt.rowid = ".$taskid;
if ($userp) $sql.= " AND pt.rowid = ".$projectid;
//if ($usert) $sql.= " AND pt.fk_projet = ".$projectid;
}
if ($taskid)
{
@ -564,9 +565,9 @@ class Task extends CommonObject
$i = 0;
while ($i < $num)
{
$row = $this->db->fetch_row($resql);
if (empty($tasksrole[$row[0]])) $tasksrole[$row[0]] = $row[1];
else $tasksrole[$row[0]].=','.$row[1];
$obj = $this->db->fetch_object($resql);
if (empty($projectsrole[$obj->pid])) $projectsrole[$obj->pid] = $obj->code;
else $projectsrole[$obj->pid].=','.$obj->code;
$i++;
}
$this->db->free($resql);
@ -576,7 +577,7 @@ class Task extends CommonObject
dol_print_error($this->db);
}
return $tasksrole;
return $projectsrole;
}
/**