From 8e675a9c01a7365ad2ef940ef88ef2a89e6e6ba2 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Sun, 21 Feb 2010 00:16:47 +0000
Subject: [PATCH] A lot of fix in project module

---
 htdocs/html.formother.class.php    |  4 +-
 htdocs/langs/en_US/projects.lang   | 10 +++--
 htdocs/lib/project.lib.php         | 72 ++++++++++++++++--------------
 htdocs/projet/activity/list.php    |  8 ++--
 htdocs/projet/tasks/fiche.php      |  5 ++-
 htdocs/projet/tasks/index.php      | 10 +++--
 htdocs/projet/tasks/task.class.php | 19 +++++---
 7 files changed, 71 insertions(+), 57 deletions(-)

diff --git a/htdocs/html.formother.class.php b/htdocs/html.formother.class.php
index 2b4abbe6a21..0b1faa03aa2 100644
--- a/htdocs/html.formother.class.php
+++ b/htdocs/html.formother.class.php
@@ -366,11 +366,11 @@ function PLineSelect(&$inc, $parent, $lines, $level=0, $selected=0)
 					print $langs->trans("Project").' '.$lines[$i]->projectref;
 					if (empty($lines[$i]->public))
 					{
-						print ' ('.$langs->trans("PrivateProject").')';
+						print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
 					}
 					else
 					{
-						print ' ('.$langs->trans("SharedProject").')';
+						print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
 					}
 					//print '-'.$parent.'-'.$lines[$i]->projectid.'-'.$lastprojectid;
 					print "</option>\n";
diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang
index 8c71ee8c278..18d179a7a83 100755
--- a/htdocs/langs/en_US/projects.lang
+++ b/htdocs/langs/en_US/projects.lang
@@ -4,10 +4,12 @@ Project=Project
 Projects=Projects
 SharedProject=Everybody
 PrivateProject=Contacts of project
-MyProjectsDesc=Cette vue projet est restreinte aux projets pour lesquels vous êtes un contact affecté (quelqu'en soit le type).
-ProjectsDesc=Cette vue présente tous les projets ayant pour visibilité "Tout le monde".
-MyTasksDesc=Cette vue est restreinte aux projets et taches pour lesquels vous êtes un contact affecté à au moins une tache (quelqu'en soit le type).
-TasksDesc=Cette vue présente tous les projets ayant pour visibilité "Tout le monde".
+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.
+ProjectsDesc=This view presents 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).
+TasksPublicDesc=This view presents all projects and tasks you are allowed to read.
+TasksDesc=This view presents all projects and tasks (your user permissions grant you permission to view everything).
 Myprojects=My projects
 ProjectsArea=Projects area
 NewProject=New project
diff --git a/htdocs/lib/project.lib.php b/htdocs/lib/project.lib.php
index 34731a4535a..34c76408037 100644
--- a/htdocs/lib/project.lib.php
+++ b/htdocs/lib/project.lib.php
@@ -217,6 +217,7 @@ function PLinesb(&$inc, $parent, $lines, &$level, &$tasksrole)
 	global $form;
 
 	$projectstatic = new Project($db);
+	$taskstatic = new Task($db);
 
 	$var=true;
 
@@ -230,8 +231,19 @@ function PLinesb(&$inc, $parent, $lines, &$level, &$tasksrole)
 			$var = !$var;
 			print "<tr $bc[$var]>\n";
 
+			// Project
+			print "<td>";
+			$projectstatic->id=$lines[$i]->projectid;
+			$projectstatic->ref=$lines[$i]->projectref;
+			print $projectstatic->getNomUrl(1);
+			print "</td>";
+
 			// Ref
-			print '<td><a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$lines[$i]->id.'">'.$lines[$i]->id.'</a></td>';
+			print '<td>';
+			$taskstatic->id=$lines[$i]->id;
+			$taskstatic->ref=$lines[$i]->id;
+			print $taskstatic->getNomUrl(1);
+			print '</td>';
 
 			// Label task
 			print "<td>";
@@ -244,32 +256,24 @@ function PLinesb(&$inc, $parent, $lines, &$level, &$tasksrole)
 			print $lines[$i]->label;
 			print "</td>\n";
 
-			// Project
-			print "<td>";
-			$projectstatic->id=$lines[$i]->projectid;
-			$projectstatic->ref=$lines[$i]->projectref;
-			print $projectstatic->getNomUrl(1);
-			print "</td>";
-
 			$heure = intval($lines[$i]->duration);
 			$minutes = round((($lines[$i]->duration - $heure) * 60),0);
 			$minutes = substr("00"."$minutes", -2);
 			print '<td align="right">'.$heure."&nbsp;h&nbsp;".$minutes."</td>\n";
 
-			if ($tasksrole[$lines[$i]->id] == 'TASKEXECUTIVE')
-			{
-				print '<td nowrap="nowrap">';
-				print $form->select_date('',$lines[$i]->id,'','','',"addtime");
-				print '&nbsp;<input size="4" type="text" class="flat" name="task'.$lines[$i]->id.'" value="">';
-				print '&nbsp;<input type="submit" class="button" value="'.$langs->trans("Add").'">';
-				print '</td>';
-				print "<td>&nbsp;";
-				print '</td>';
-			}
-			else
-			{
-				print '<td colspan="2">&nbsp;</td>';
-			}
+			$disabled=1;
+			// If at least one role for project
+			if (! empty($tasksrole[$lines[$i]->id])
+				&& sizeof($tasksrole[$lines[$i]->id]) > 0) $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").'">';
+			print '</td>';
+			print "<td>&nbsp;";
+			print '</td>';
+
 			print "</tr>\n";
 			$inc++;
 			$level++;
@@ -350,6 +354,18 @@ function PLines(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole
 
 				print "<tr ".$bc[$var].">\n";
 
+				// Project
+				if ($showproject)
+				{
+					print "<td>";
+					if ($showlineingray) print '<i>';
+					$projectstatic->id=$lines[$i]->projectid;
+					$projectstatic->ref=$lines[$i]->projectref;
+					print $projectstatic->getNomUrl(1);
+					if ($showlineingray) print '</i>';
+					print "</td>";
+				}
+
 				// Ref of task
 				print '<td>';
 				if ($showlineingray)
@@ -377,18 +393,6 @@ function PLines(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole
 				else print '</a>';
 				print "</td>\n";
 
-				// Project
-				if ($showproject)
-				{
-					print "<td>";
-					if ($showlineingray) print '<i>';
-					$projectstatic->id=$lines[$i]->projectid;
-					$projectstatic->ref=$lines[$i]->projectref;
-					print $projectstatic->getNomUrl(1);
-					if ($showlineingray) print '</i>';
-					print "</td>";
-				}
-
 				$heure = intval($lines[$i]->duration);
 				$minutes = round((($lines[$i]->duration - $heure) * 60),0);
 				$minutes = substr("00"."$minutes", -2);
diff --git a/htdocs/projet/activity/list.php b/htdocs/projet/activity/list.php
index 9c2e52ab971..1696239a0be 100644
--- a/htdocs/projet/activity/list.php
+++ b/htdocs/projet/activity/list.php
@@ -1,6 +1,6 @@
 <?php
 /* Copyright (C) 2005      Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2004-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005-2010 Regis Houssin        <regis@dolibarr.fr>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  */
 
 /**
- *	\file       htdocs/projet/tasks/fiche.php
+ *	\file       htdocs/projet/activity/list.php
  *	\ingroup    projet
- *	\brief      Fiche taches d'un projet
+ *	\brief      List activities of tasks
  *	\version    $Id$
  */
 
@@ -122,9 +122,9 @@ print '<input type="hidden" name="action" value="addtime">';
 
 print '<table class="noborder" width="100%">';
 print '<tr class="liste_titre">';
+print '<td>'.$langs->trans("Project").'</td>';
 print '<td>'.$langs->trans("RefTask").'</td>';
 print '<td>'.$langs->trans("LabelTask").'</td>';
-print '<td>'.$langs->trans("Project").'</td>';
 print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
 print '<td colspan="2">'.$langs->trans("AddDuration").'</td>';
 print "</tr>\n";
diff --git a/htdocs/projet/tasks/fiche.php b/htdocs/projet/tasks/fiche.php
index e57448d661a..526566153b1 100644
--- a/htdocs/projet/tasks/fiche.php
+++ b/htdocs/projet/tasks/fiche.php
@@ -149,6 +149,7 @@ if ($_GET["action"] == 'create' && $user->rights->projet->creer && (empty($proje
 	print '<input type="text" size="25" name="label" class="flat" value="'.$_POST["label"].'">';
 	print '</td></tr>';
 
+	// List of projects
 	print '<tr><td class="fieldrequired">'.$langs->trans("ChildOfTask").'</td><td>';
 	print $formother->selectProjectTasks('',$projectid, 'task_parent', 0, 0, 1, 1);
 	print '</td></tr>';
@@ -244,9 +245,9 @@ else
 	 */
 	print '<div class="tabsAction">';
 
-	if ($user->rights->projet->creer)
+	if ($user->rights->projet->all->creer || $user->rights->projet->creer)
 	{
-		if ($userAccess)
+		if ($project->public || $userAccess)
 		{
 			print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$project->id.'&action=create'.$param.'">'.$langs->trans('AddTask').'</a>';
 		}
diff --git a/htdocs/projet/tasks/index.php b/htdocs/projet/tasks/index.php
index 4c25650311e..f95f406eecf 100644
--- a/htdocs/projet/tasks/index.php
+++ b/htdocs/projet/tasks/index.php
@@ -1,6 +1,6 @@
 <?php
 /* Copyright (C) 2005      Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2006-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2006-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2006-2010 Regis Houssin        <regis@dolibarr.fr>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -21,12 +21,14 @@
 /**
  *	\file       htdocs/projet/tasks/index.php
  *	\ingroup    project
- *	\brief      Fiche taches d'un projet
+ *	\brief      List all task of a project
  *	\version    $Id$
  */
 
 require("./pre.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/projet/project.class.php");
+require_once(DOL_DOCUMENT_ROOT."/projet/tasks/task.class.php");
 
 $langs->load('projects');
 
@@ -68,15 +70,15 @@ print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorde
 // Get list of tasks in tasksarray and taskarrayfiltered
 // We need all tasks (even not limited to a user because a task to user
 // can have a parent that is not affected to him).
-$tasksarray=$taskstatic->getTasksArray(0, 0, $projectstatic->id, $socid);
+$tasksarray=$taskstatic->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
 // We load also tasks limited to a particular user
 $tasksrole=($mine ? $taskstatic->getUserRolesForProjectsOrTasks(0,$user,$projectstatic->id,0) : '');
 
 print '<table class="noborder" width="100%">';
 print '<tr class="liste_titre">';
+print '<td>'.$langs->trans("Project").'</td>';
 print '<td width="80">'.$langs->trans("RefTask").'</td>';
 print '<td>'.$langs->trans("LabelTask").'</td>';
-print '<td>'.$langs->trans("Project").'</td>';
 print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
 print "</tr>\n";
 // Show all lines in taskarray (recursive function to go down on tree)
diff --git a/htdocs/projet/tasks/task.class.php b/htdocs/projet/tasks/task.class.php
index e77a59cf2a6..9544d573f83 100644
--- a/htdocs/projet/tasks/task.class.php
+++ b/htdocs/projet/tasks/task.class.php
@@ -495,6 +495,7 @@ class Task extends CommonObject
 					$tasks[$i]->description  = $obj->description;
 					$tasks[$i]->fk_parent    = $obj->fk_task_parent;
 					$tasks[$i]->duration     = $obj->duration_effective;
+					$tasks[$i]->public       = $obj->public;
 				}
 
 				$i++;
@@ -510,17 +511,19 @@ class Task extends CommonObject
 	}
 
 	/**
-	 * Return Array of role of user for each projects or each tasks
+	 * Return list of roles for a user for each projects or each tasks (or a particular project or task)
 	 * @param 	userp
-	 * @param	usert
-	 * @param 	projectid
-	 * @param 	taskid
-	 * @return 	array			Array of role of user for each projects or each tasks
+	 * @param	usert			Deprecated. Permissions are on project.
+	 * @param 	projectid		Project id to filter on a project
+	 * @param 	taskid			Task id to filter on a task
+	 * @return 	array			Array (projectid => 'list of roles for project')
 	 */
 	function getUserRolesForProjectsOrTasks($userp,$usert,$projectid=0,$taskid=0)
 	{
 		$tasksrole = array();
 
+		dol_syslog("Task::getUserRolesForProjectsOrTasks userp=".is_object($userp)." usert=".is_object($usert)." projectid=".$projectid." taskid=".$taskid);
+
 		// We want role of user for projet or role of user for task. Both are not possible.
 		if (empty($userp) && empty($usert))
 		{
@@ -552,7 +555,8 @@ class Task extends CommonObject
 			if ($usert) $sql.= " AND pt.rowid = ".$taskid;
 		}
 
-		dol_syslog("Task::getTasksForProjectOwnedByAUser sql=".$sql);
+		//print $sql;
+		dol_syslog("Task::getUserRolesForProjectsOrTasks sql=".$sql);
 		$resql = $this->db->query($sql);
 		if ($resql)
 		{
@@ -561,7 +565,8 @@ class Task extends CommonObject
 			while ($i < $num)
 			{
 				$row = $this->db->fetch_row($resql);
-				$tasksrole[$row[0]] = $row[1];
+				if (empty($tasksrole[$row[0]])) $tasksrole[$row[0]] = $row[1];
+				else $tasksrole[$row[0]].=','.$row[1];
 				$i++;
 			}
 			$this->db->free($resql);
-- 
GitLab