From 382f11a51455a8745962813080ece27a4ec61076 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Sun, 7 Feb 2010 02:39:01 +0000
Subject: [PATCH] Fix and restore a lot of broken features in the project
 module. Must try to restore a stable module to start a release.

---
 htdocs/html.form.class.php                    |  1 +
 htdocs/html.formfile.class.php                |  7 +-
 htdocs/html.formother.class.php               | 12 +--
 .../modules/project/modules_project.php       |  1 +
 .../project/pdf/pdf_baleine.modules.php       |  2 +-
 htdocs/lib/project.lib.php                    | 22 ++---
 htdocs/projet/activity/list.php               |  2 +-
 htdocs/projet/contact.php                     | 45 +++++-----
 htdocs/projet/fiche.php                       | 14 ++-
 htdocs/projet/tasks/contact.php               | 65 +++++++-------
 htdocs/projet/tasks/fiche.php                 |  2 +-
 htdocs/projet/tasks/index.php                 |  2 +-
 htdocs/projet/tasks/note.php                  | 46 +++-------
 htdocs/projet/tasks/task.class.php            |  4 +-
 htdocs/projet/tasks/task.php                  | 89 +++++++------------
 htdocs/projet/tasks/time.php                  | 29 +-----
 16 files changed, 137 insertions(+), 206 deletions(-)

diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index 89147086324..135b644d705 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -2587,6 +2587,7 @@ class Form
 	 *	\param  option          Valeur de l'option en fonction du type choisi
 	 *	\param  translate       Traduire la valeur
 	 * 	\param	maxlen			Length maximum for labels
+	 * 	\return	string			HTML select string
 	 */
 	function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $optionType=0, $option='', $translate=0, $maxlen=0)
 	{
diff --git a/htdocs/html.formfile.class.php b/htdocs/html.formfile.class.php
index fc37e6e04c0..a70fbe6d83b 100644
--- a/htdocs/html.formfile.class.php
+++ b/htdocs/html.formfile.class.php
@@ -313,14 +313,15 @@ class FormFile
 			{
 				print '<td align="center">';
 				print $langs->trans('Model').' ';
-				$html->select_array('model',$modellist,$modelselected,0,0,1);
+				print $html->selectarray('model',$modellist,$modelselected,0,0,1);
+				print '</td>';
 			}
 			else
 			{
 				print '<td align="left">';
 				print $langs->trans("Files");
+				print '</td>';
 			}
-			print '</td>';
 			print '<td align="center">';
 			if($conf->global->MAIN_MULTILANGS && ! $forcenomultilang)
 			{
@@ -334,7 +335,7 @@ class FormFile
 			}
 			print '</td>';
 			print '<td align="center" colspan="'.($delallowed?'2':'1').'">';
-			print '<input class="button" type="submit" value="'.$buttonlabel.'">';
+			print '<input class="button" '.((is_array($modellist) && sizeof($modellist))?'':' disabled="true"').' type="submit" value="'.$buttonlabel.'">';
 			print '</td></tr>';
 		}
 
diff --git a/htdocs/html.formother.class.php b/htdocs/html.formother.class.php
index f5bdb67d821..b717cfb914c 100644
--- a/htdocs/html.formother.class.php
+++ b/htdocs/html.formother.class.php
@@ -207,12 +207,12 @@ class FormOther
 	 *    \param     increment     increment value
 	 *    \param     start         start value
 	 *    \param     end           end value
-	 *    \return    return        combo   
+	 *    \return    return        combo
 	 */
 	function select_percent($selected=0,$htmlname='percent',$increment=5,$start=0,$end=100)
 	{
 		$return = '<select class="flat" name="'.$htmlname.'">';
-		
+
 		for ($i = $start ; $i <= $end ; $i += $increment)
 		{
 			if ($selected == $i)
@@ -226,9 +226,9 @@ class FormOther
 			$return.= $i.' % ';
 			$return.= '</option>';
 		}
-		
+
 		$return.= '</select>';
-		
+
 		return $return;
 	}
 
@@ -241,7 +241,7 @@ class FormOther
 	 * 	\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='', $projectid=0, $htmlname='task_parent', $modeproject=0, $modetask=0)
+	function selectProjectTasks($selected='', $projectid=0, $htmlname='task_parent', $modeproject=0, $modetask=0, $mode=0)
 	{
 		global $user, $langs;
 
@@ -249,7 +249,7 @@ class FormOther
 
 		//print $modeproject.'-'.$modetask;
 		$task=new Task($this->db);
-		$tasksarray=$task->getTasksArray($modetask?$user:0, $modeproject?$user:0, $projectid);
+		$tasksarray=$task->getTasksArray($modetask?$user:0, $modeproject?$user:0, $projectid, 0, $mode);
 		if ($tasksarray)
 		{
 			print '<select class="flat" name="'.$htmlname.'">';
diff --git a/htdocs/includes/modules/project/modules_project.php b/htdocs/includes/modules/project/modules_project.php
index 375350c6734..93ffbec831a 100644
--- a/htdocs/includes/modules/project/modules_project.php
+++ b/htdocs/includes/modules/project/modules_project.php
@@ -189,6 +189,7 @@ function project_pdf_create($db, $comid, $modele,$outputlangs)
 			return 0;
 		}
 	}
+
 	// Charge le modele
 	$file = "pdf_".$modele.".modules.php";
 	if (file_exists($dir.$file))
diff --git a/htdocs/includes/modules/project/pdf/pdf_baleine.modules.php b/htdocs/includes/modules/project/pdf/pdf_baleine.modules.php
index 8681fcfde15..cba20f7a950 100644
--- a/htdocs/includes/modules/project/pdf/pdf_baleine.modules.php
+++ b/htdocs/includes/modules/project/pdf/pdf_baleine.modules.php
@@ -158,7 +158,7 @@ class pdf_baleine extends ModelePDFProjects
 
 				// Complete object by loading several other informations
 				$task = new Task($this->db);
-				$tasksarray = $task->getTasksArray(0,0,1);
+				$tasksarray = $task->getTasksArray(0,0,$object->id);
 
 				$pdf->Open();
 				$pagenb=0;
diff --git a/htdocs/lib/project.lib.php b/htdocs/lib/project.lib.php
index 1b166d44988..5b9a64f9ff3 100644
--- a/htdocs/lib/project.lib.php
+++ b/htdocs/lib/project.lib.php
@@ -57,7 +57,7 @@ function project_prepare_head($object)
 	    $head[$h][2] = 'element';
 		$h++;
 	}
-	
+
 	$head[$h][0] = DOL_URL_ROOT.'/projet/note.php?id='.$object->id;
 	$head[$h][1] = $langs->trans('Notes');
 	$head[$h][2] = 'note';
@@ -110,7 +110,7 @@ function task_prepare_head($object)
 	$head[$h][1] = $langs->trans("Affectations");
 	$head[$h][2] = 'contact';
 	$h++;
-	
+
 	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.$object->id;
 	$head[$h][1] = $langs->trans('Notes');
 	$head[$h][2] = 'note';
@@ -287,7 +287,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 task filtered on a particular user
+ * @param	$taskrole			Array of tasks filtered on a particular user
  */
 function PLines(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole)
 {
@@ -458,9 +458,9 @@ function clean_orphelins($db)
 
 	// There is orphelins. We clean that
 	$listofid=array();
-	
+
 	$sql='SELECT rowid FROM '.MAIN_DB_PREFIX.'projet_task';
-	
+
 	$resql = $db->query($sql);
 	if ($resql)
 	{
@@ -482,24 +482,24 @@ function clean_orphelins($db)
 	{
 		// Removed orphelins records
 		print 'Some orphelins were found and restored to be parents so records are visible again.';
-		
+
 		$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
 		$sql.= " SET fk_task_parent = 0";
 		$sql.= " WHERE fk_task_parent NOT IN (".join(',',$listofid).")";
-		
-		$resql = $db->query($sql);		
+
+		$resql = $db->query($sql);
 		if ($resql)
 		{
 			$nb=$db->affected_rows($sql);
-			
+
 			return $nb;
 		}
 		else
 		{
 			return -1;
-		}	
+		}
 	}
-	
+
 }
 
 ?>
\ No newline at end of file
diff --git a/htdocs/projet/activity/list.php b/htdocs/projet/activity/list.php
index 04cd492a751..8e29bb06648 100644
--- a/htdocs/projet/activity/list.php
+++ b/htdocs/projet/activity/list.php
@@ -111,7 +111,7 @@ print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorde
 if ($mesg) print $mesg;
 
 $tasksarray=$task->getTasksArray(0,0,$project->id,0);
-$tasksrole=$task->getTasksForProjectOwnedByAUser($user,0,$project->id,0);
+$tasksrole=$task->getUserRolesForProjetsOrTasks($user,0,$project->id,0);
 //var_dump($tasksarray);
 
 print '<form name="addtime" method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$project->id.'">';
diff --git a/htdocs/projet/contact.php b/htdocs/projet/contact.php
index 95ed37e6ad0..dcfe819f058 100644
--- a/htdocs/projet/contact.php
+++ b/htdocs/projet/contact.php
@@ -273,30 +273,33 @@ if ($id > 0 || ! empty($ref))
 			print '<input type="hidden" name="source" value="external">';
 			print '<input type="hidden" name="id" value="'.$id.'">';
 
-			// Ligne ajout pour contact externe
-			$var=!$var;
-			print "<tr $bc[$var]>";
+			// Line to add external contact. Only if project is linked to a third party.
+			if ($project->societe->id)
+			{
+				$var=!$var;
+				print "<tr $bc[$var]>";
 
-			print '<td nowrap="nowrap">';
-			print img_object('','contact').' '.$langs->trans("ThirdPartyContacts");
-			print '</td>';
+				print '<td nowrap="nowrap">';
+				print img_object('','contact').' '.$langs->trans("ThirdPartyContacts");
+				print '</td>';
 
-			print '<td colspan="1">';
-			$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$project->societe->id;
-			$selectedCompany = $formcompany->selectCompaniesForNewContact($project, 'id', $selectedCompany, 'newcompany');
-			print '</td>';
+				print '<td colspan="1">';
+				$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$project->societe->id;
+				$selectedCompany = $formcompany->selectCompaniesForNewContact($project, 'id', $selectedCompany, 'newcompany');
+				print '</td>';
 
-			print '<td colspan="1">';
-			$nbofcontacts=$html->select_contacts($selectedCompany,'','contactid',0);
-			if ($nbofcontacts == 0) print $langs->trans("NoContactDefined");
-			print '</td>';
-			print '<td>';
-			$formcompany->selectTypeContact($project, '', 'type','external','rowid');
-			print '</td>';
-			print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"';
-			if (! $nbofcontacts) print ' disabled="true"';
-			print '></td>';
-			print '</tr>';
+				print '<td colspan="1">';
+				$nbofcontacts=$html->select_contacts($selectedCompany,'','contactid',0);
+				if ($nbofcontacts == 0) print $langs->trans("NoContactDefined");
+				print '</td>';
+				print '<td>';
+				$formcompany->selectTypeContact($project, '', 'type','external','rowid');
+				print '</td>';
+				print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"';
+				if (! $nbofcontacts) print ' disabled="true"';
+				print '></td>';
+				print '</tr>';
+			}
 
 			print "</form>";
 
diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php
index eee1341bdcb..ff3a08def96 100644
--- a/htdocs/projet/fiche.php
+++ b/htdocs/projet/fiche.php
@@ -253,16 +253,14 @@ if ($_GET["action"] == 'create' && $user->rights->projet->creer)
 	$project = new Project($db);
 
 	$defaultref='';
-	$obj = $conf->global->PROJECT_ADDON;
-	if ($obj)
+	$obj = empty($conf->global->PROJECT_ADDON)?'mod_project_simple':$conf->global->PROJECT_ADDON;
+	if (! empty($conf->global->PROJECT_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/includes/modules/project/".$conf->global->PROJECT_ADDON.".php"))
 	{
-		if (! empty($conf->global->PROJECT_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/includes/modules/project/".$conf->global->PROJECT_ADDON.".php"))
-		{
-			require_once(DOL_DOCUMENT_ROOT ."/includes/modules/project/".$conf->global->PROJECT_ADDON.".php");
-			$modProject = new $obj;
-			$defaultref = $modProject->getNextValue($soc,$project);
-		}
+		require_once(DOL_DOCUMENT_ROOT ."/includes/modules/project/".$conf->global->PROJECT_ADDON.".php");
+		$modProject = new $obj;
+		$defaultref = $modProject->getNextValue($soc,$project);
 	}
+	if (empty($defaultref)) $defaultref='';
 
 	// Ref
 	print '<tr><td><span class="fieldrequired">'.$langs->trans("Ref").'</span></td><td><input size="12" type="text" name="ref" value="'.($_POST["ref"]?$_POST["ref"]:$defaultref).'"></td></tr>';
diff --git a/htdocs/projet/tasks/contact.php b/htdocs/projet/tasks/contact.php
index 93f4bfffdf8..29a74d1a918 100644
--- a/htdocs/projet/tasks/contact.php
+++ b/htdocs/projet/tasks/contact.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) 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/who.php
+ *	\file       htdocs/projet/tasks/contact.php
  *	\ingroup    project
- *	\brief      Fiche taches d'un projet
+ *	\brief      Actors of a task
  *	\version    $Id$
  */
 
@@ -156,7 +156,7 @@ llxHeader('', $langs->trans("Task"));
 $html = new Form($db);
 $formcompany   = new FormCompany($db);
 $contactstatic = new Contact($db);
-$projectstatic = new Project($db);
+$project = new Project($db);
 
 
 /* *************************************************************************** */
@@ -174,8 +174,8 @@ if ($id > 0 || ! empty($ref))
 
 	if ( $task->fetch($id,$ref) > 0)
 	{
-		$result=$projectstatic->fetch($task->fk_project);
-		if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);
+		$result=$project->fetch($task->fk_project);
+		if (! empty($project->socid)) $project->societe->fetch($project->socid);
 
 		$head = task_prepare_head($task);
 		dol_fiche_head($head, 'contact', $langs->trans("Task"), 0, 'projecttask');
@@ -190,21 +190,21 @@ if ($id > 0 || ! empty($ref))
 
 		// Ref
 		print '<tr><td width="30%">'.$langs->trans('Ref').'</td><td colspan="3">';
-		print $html->showrefnav($task,'ref',$linkback,1,'ref','ref','');
+		print $html->showrefnav($task,'id','',1,'rowid','ref','','');
 		print '</td></tr>';
 
 		// Label
 		print '<tr><td>'.$langs->trans("Label").'</td><td>'.$task->label.'</td></tr>';
-		
+
 		// Project
 		print '<tr><td>'.$langs->trans("Project").'</td><td>';
-		print $projectstatic->getNomUrl(1);
+		print $project->getNomUrl(1);
 		print '</td></tr>';
 
 		// Customer
 		print "<tr><td>".$langs->trans("Company")."</td>";
 		print '<td colspan="3">';
-		if ($projectstatic->societe->id > 0) print $projectstatic->societe->getNomUrl(1);
+		if ($project->societe->id > 0) print $project->societe->getNomUrl(1);
 		else print '&nbsp;';
 		print '</td></tr>';
 
@@ -268,30 +268,33 @@ if ($id > 0 || ! empty($ref))
 			print '<input type="hidden" name="source" value="external">';
 			print '<input type="hidden" name="id" value="'.$id.'">';
 
-			// Ligne ajout pour contact externe
-			$var=!$var;
-			print "<tr $bc[$var]>";
+			// Line to add an external contact. Only if project linked to a third party.
+			if ($project->socid)
+			{
+				$var=!$var;
+				print "<tr $bc[$var]>";
 
-			print '<td nowrap="nowrap">';
-			print img_object('','contact').' '.$langs->trans("ThirdPartyContacts");
-			print '</td>';
+				print '<td nowrap="nowrap">';
+				print img_object('','contact').' '.$langs->trans("ThirdPartyContacts");
+				print '</td>';
 
-			print '<td colspan="1">';
-			$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$projectstatic->societe->id;
-			$selectedCompany = $formcompany->selectCompaniesForNewContact($task, 'id', $selectedCompany, 'newcompany');
-			print '</td>';
+				print '<td colspan="1">';
+				$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$project->societe->id;
+				$selectedCompany = $formcompany->selectCompaniesForNewContact($task, 'id', $selectedCompany, 'newcompany');
+				print '</td>';
 
-			print '<td colspan="1">';
-			$nbofcontacts=$html->select_contacts($selectedCompany,'','contactid',0);
-			if ($nbofcontacts == 0) print $langs->trans("NoContactDefined");
-			print '</td>';
-			print '<td>';
-			$formcompany->selectTypeContact($task, '', 'type','external','rowid');
-			print '</td>';
-			print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"';
-			if (! $nbofcontacts) print ' disabled="true"';
-			print '></td>';
-			print '</tr>';
+				print '<td colspan="1">';
+				$nbofcontacts=$html->select_contacts($selectedCompany,'','contactid',0);
+				if ($nbofcontacts == 0) print $langs->trans("NoContactDefined");
+				print '</td>';
+				print '<td>';
+				$formcompany->selectTypeContact($task, '', 'type','external','rowid');
+				print '</td>';
+				print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"';
+				if (! $nbofcontacts) print ' disabled="true"';
+				print '></td>';
+				print '</tr>';
+			}
 
 			print "</form>";
 
diff --git a/htdocs/projet/tasks/fiche.php b/htdocs/projet/tasks/fiche.php
index dcf29f28f4d..0fafd70ec8a 100644
--- a/htdocs/projet/tasks/fiche.php
+++ b/htdocs/projet/tasks/fiche.php
@@ -263,7 +263,7 @@ else
 	// can have a parent that is not affected to him).
 	$tasksarray=$task->getTasksArray(0, 0, $project->id, $socid, 0);
 	// We load also tasks limited to a particular user
-	$tasksrole=($_REQUEST["mode"]=='mine' ? $task->getTasksForProjectOwnedByAUser(0,$user,$project->id,0) : '');
+	$tasksrole=($_REQUEST["mode"]=='mine' ? $task->getUserRolesForProjetsOrTasks(0,$user,$project->id,0) : '');
 
 	print '<table class="noborder" width="100%">';
 	print '<tr class="liste_titre">';
diff --git a/htdocs/projet/tasks/index.php b/htdocs/projet/tasks/index.php
index 30225b095a3..34146948302 100644
--- a/htdocs/projet/tasks/index.php
+++ b/htdocs/projet/tasks/index.php
@@ -77,7 +77,7 @@ $task = new Task($db);
 // can have a parent that is not affected to him).
 $tasksarray=$task->getTasksArray(0, 0, $project->id, $socid);
 // We load also tasks limited to a particular user
-$tasksrole=($_REQUEST["mode"]=='mine' ? $task->getTasksForProjectOwnedByAUser(0,$user,$project->id,0) : '');
+$tasksrole=($_REQUEST["mode"]=='mine' ? $task->getUserRolesForProjetsOrTasks(0,$user,$project->id,0) : '');
 
 print '<table class="noborder" width="100%">';
 print '<tr class="liste_titre">';
diff --git a/htdocs/projet/tasks/note.php b/htdocs/projet/tasks/note.php
index 0dc99d3f996..79f64cfa52e 100644
--- a/htdocs/projet/tasks/note.php
+++ b/htdocs/projet/tasks/note.php
@@ -81,10 +81,9 @@ if ($_POST['action'] == 'update_private' && $user->rights->projet->task->creer)
 }
 
 
-
-/******************************************************************************/
-/* Affichage fiche                                                            */
-/******************************************************************************/
+/*
+ * View
+ */
 
 llxHeader();
 
@@ -101,19 +100,19 @@ if ($id > 0 || ! empty($ref))
 	$task = new Task($db);
 	$projectstatic = new Project($db);
 	$userstatic = new User($db);
-	
+
 	if ($task->fetch($id, $ref))
 	{
 		$result=$projectstatic->fetch($task->fk_project);
 		if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);
-		
+
 		// To verify role of users
 		$userAccess = 0;
 		foreach(array('internal','external') as $source)
 		{
 			$userRole = $projectstatic->liste_contact(4,$source);
 			$num=sizeof($userRole);
-			
+
 			$i = 0;
 			while ($i < $num)
 			{
@@ -124,7 +123,7 @@ if ($id > 0 || ! empty($ref))
 				$i++;
 			}
 		}
-		
+
 		$head = task_prepare_head($task);
 		dol_fiche_head($head, 'note', $langs->trans('Task'), 0, 'projecttask');
 
@@ -134,12 +133,12 @@ if ($id > 0 || ! empty($ref))
 
 		// Ref
 		print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>';
-		print $html->showrefnav($task,'ref','',1,'ref','ref');
+		print $html->showrefnav($task,'id','',1,'rowid','ref','','');
 		print '</td></tr>';
-			
+
 		// Label
 		print '<tr><td>'.$langs->trans("Label").'</td><td>'.$task->label.'</td></tr>';
-		
+
 		// Project
 		print '<tr><td>'.$langs->trans("Project").'</td><td colspan="3">';
 		print $projectstatic->getNomUrl(1);
@@ -150,31 +149,6 @@ if ($id > 0 || ! empty($ref))
 		if ($projectstatic->societe->id > 0) print $projectstatic->societe->getNomUrl(1);
 		else print'&nbsp;';
 		print '</td></tr>';
-			
-		// Task executive
-		print '<tr><td>'.$langs->trans("TaskExecutive").'</td><td>';
-		$contact = $task->liste_contact(4,'internal');
-		$num=sizeof($contact);
-		if ($num)
-		{
-			$i = 0;
-			while ($i < $num)
-			{
-				if ($contact[$i]['code'] == 'TASKEXECUTIVE')
-				{
-					$userstatic->id = $contact[$i]['id'];
-					$userstatic->fetch();
-					print $userstatic->getNomUrl(1);
-					print '<br>';
-				}
-				$i++;
-			}
-		}
-		else
-		{
-			print $langs->trans('SharedTask');
-		}
-		print '</td></tr>';
 
 		// Note publique
 		print '<tr><td valign="top">'.$langs->trans("NotePublic").' :</td>';
diff --git a/htdocs/projet/tasks/task.class.php b/htdocs/projet/tasks/task.class.php
index e0c902e8f49..3c10f323f4d 100644
--- a/htdocs/projet/tasks/task.class.php
+++ b/htdocs/projet/tasks/task.class.php
@@ -503,7 +503,7 @@ class Task extends CommonObject
 
 				if ((! $obj->public) && ($userp || $usert))	// If not public and we ask a filter on user
 				{
-					if (! $this->getTasksForProjectOwnedByAUser($userp, $usert, $obj->projectid, $obj->rowid))
+					if (! $this->getUserRolesForProjetsOrTasks($userp, $usert, $obj->projectid, $obj->rowid))
 					{
 						$error++;
 					}
@@ -541,7 +541,7 @@ class Task extends CommonObject
 	 * @param 	taskid
 	 * @return 	array			Array of role of user for each projects or each tasks
 	 */
-	function getTasksForProjectOwnedByAUser($userp,$usert,$projectid=0,$taskid=0)
+	function getUserRolesForProjetsOrTasks($userp,$usert,$projectid=0,$taskid=0)
 	{
 		$tasksrole = array();
 
diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php
index 2213707c091..c3785ced8ee 100644
--- a/htdocs/projet/tasks/task.php
+++ b/htdocs/projet/tasks/task.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) 2010      Regis Houssin        <regis@dolibarr.fr>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -51,7 +51,7 @@ 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 ''
@@ -115,72 +115,72 @@ if ($taskid)
 	$task = new Task($db);
 	$projectstatic = new Project($db);
 	$userstatic = new User($db);
-	
+
 	if ($task->fetch($taskid) >= 0 )
 	{
 		$result=$projectstatic->fetch($task->fk_project);
 		if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);
-			
+
 		$head=task_prepare_head($task);
-			
+
 		dol_fiche_head($head, 'task', $langs->trans("Task"),0,'projecttask');
-		
+
 		if ($_GET["action"] == 'edit' && $user->rights->projet->task->creer)
 		{
 			print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
 			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 			print '<input type="hidden" name="action" value="update">';
 			print '<input type="hidden" name="id" value="'.$task->id.'">';
-			
+
 			print '<table class="border" width="100%">';
-			
+
 			if ($mesg) print $mesg.'<br>';
-			
+
 			// Ref
 			print '<tr><td width="30%">'.$langs->trans("Ref").'</td>';
 			print '<td>'.$task->ref.'</td></tr>';
-			
+
 			// Label
 			print '<tr><td>'.$langs->trans("Label").'</td>';
 			print '<td><input size="30" name="label" value="'.$task->label.'"></td></tr>';
-			
+
 			// Project
 			print '<tr><td>'.$langs->trans("Project").'</td><td colspan="3">';
 			print $projectstatic->getNomUrl(1);
 			print '</td></tr>';
-			
+
 			// Third party
 			print '<td>'.$langs->trans("Company").'</td><td colspan="3">';
 			if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1);
 			else print '&nbsp;';
 			print '</td></tr>';
-			
+
 			// Task parent
 			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');
 			print '</td></tr>';
-			
+
 			// Date end
 			print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
 			print $html->select_date($task->date_end?$task->date_end:-1,'datee');
 			print '</td></tr>';
-			
+
 			// Progress
 			print '<tr><td>'.$langs->trans("Progress").'</td><td colspan="3">';
 			print $formother->select_percent($task->progress,'progress');
 			print '</td></tr>';
-			
+
 			// Description
 			print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
 			print '<td>';
 			print '<textarea name="description" wrap="soft" cols="80" rows="'.ROWS_3.'">'.$task->description.'</textarea>';
 			print '</td></tr>';
-			
+
 			print '<tr><td align="center" colspan="2">';
 			print '<input type="submit" class="button" name="update" value="'.$langs->trans("Modify").'"> &nbsp; ';
 			print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
@@ -192,7 +192,7 @@ if ($taskid)
 			/*
 			 * Fiche tache en mode visu
 			 */
-			
+
 			if ($_GET["action"] == 'delete')
 			{
 				$ret=$html->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"],$langs->trans("DeleteATask"),$langs->trans("ConfirmDeleteATask"),"confirm_delete");
@@ -200,7 +200,7 @@ if ($taskid)
 			}
 
 			print '<table class="border" width="100%">';
-			
+
 			// Ref
 			print '<tr><td width="30%">';
 			print $langs->trans("Ref");
@@ -208,74 +208,49 @@ if ($taskid)
 			print $html->showrefnav($task,'id','',1,'rowid','ref','','');
 			print '</td>';
 			print '</tr>';
-			
+
 			// Label
 			print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$task->label.'</td></tr>';
-			
+
 			// Project
 			print '<tr><td>'.$langs->trans("Project").'</td><td colspan="3">';
 			print $projectstatic->getNomUrl(1);
 			print '</td></tr>';
-			
+
 			// Third party
 			print '<td>'.$langs->trans("Company").'</td><td colspan="3">';
 			if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1);
 			else print '&nbsp;';
 			print '</td></tr>';
-			
-			// Task executive
-			print '<tr><td>'.$langs->trans("TaskExecutive").'</td><td>';
-			$contact = $task->liste_contact(4,'internal');
-			$num=sizeof($contact);
-			if ($num)
-			{
-				$i = 0;
-				while ($i < $num)
-				{
-					if ($contact[$i]['code'] == 'TASKEXECUTIVE')
-					{
-						$userstatic->id = $contact[$i]['id'];
-						$userstatic->fetch();
-						print $userstatic->getNomUrl(1);
-						print '<br>';
-					}
-					$i++;
-				}
-			}
-			else
-			{
-				print $langs->trans('SharedTask');
-			}
-			print '</td></tr>';
-			
+
 			// Date start
 			print '<tr><td>'.$langs->trans("DateStart").'</td><td colspan="3">';
 			print dol_print_date($task->date_start,'day');
 			print '</td></tr>';
-			
+
 			// Date end
 			print '<tr><td>'.$langs->trans("DateEnd").'</td><td colspan="3">';
 			print dol_print_date($task->date_end,'day');
 			print '</td></tr>';
-			
+
 			// Progress
 			print '<tr><td>'.$langs->trans("Progress").'</td><td colspan="3">';
 			print $task->progress.' %';
 			print '</td></tr>';
-			
+
 			// Description
 			print '<td valign="top">'.$langs->trans("Description").'</td><td colspan="3">';
 			print nl2br($task->description);
 			print '</td></tr>';
-			
+
 			print '</table></form>';
 			print '</div>';
-			
+
 			/*
 			 * Actions
 			 */
 			print '<div class="tabsAction">';
-			
+
 			// Modify
 			if ($user->rights->projet->task->creer)
 			{
@@ -285,7 +260,7 @@ if ($taskid)
 			{
 				print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Modify').'</a>';
 			}
-			
+
 			// Delete
 			if ($user->rights->projet->task->supprimer)
 			{
@@ -295,7 +270,7 @@ if ($taskid)
 			{
 				print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Delete').'</a>';
 			}
-			
+
 			print '</div>';
 		}
 	}
diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php
index dbb07caa810..d37992a192d 100644
--- a/htdocs/projet/tasks/time.php
+++ b/htdocs/projet/tasks/time.php
@@ -55,7 +55,7 @@ if ($_GET["id"] > 0)
 	$task = new Task($db);
 	$projectstatic = new Project($db);
 	$userstatic = new User($db);
-	
+
 	if ($task->fetch($_GET["id"]) >= 0 )
 	{
 		$result=$projectstatic->fetch($task->fk_project);
@@ -92,34 +92,9 @@ if ($_GET["id"] > 0)
 		if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1);
 		else print '&nbsp;';
 		print '</td></tr>';
-		
-		// Task executive
-		print '<tr><td>'.$langs->trans("TaskExecutive").'</td><td>';
-		$contact = $task->liste_contact(4,'internal');
-		$num=sizeof($contact);
-		if ($num)
-		{
-			$i = 0;
-			while ($i < $num)
-			{
-				if ($contact[$i]['code'] == 'TASKEXECUTIVE')
-				{
-					$userstatic->id = $contact[$i]['id'];
-					$userstatic->fetch();
-					print $userstatic->getNomUrl(1);
-					print '<br>';
-				}
-				$i++;
-			}
-		}
-		else
-		{
-			print $langs->trans('SharedTask');
-		}
-		print '</td></tr>';
 
 		/*
-		 *  List of time spent 
+		 *  List of time spent
 		 */
 		$sql = "SELECT t.task_date, t.task_duration, t.fk_user, u.login, u.rowid";
 		$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
-- 
GitLab