diff --git a/htdocs/lib/project.lib.php b/htdocs/lib/project.lib.php
new file mode 100644
index 0000000000000000000000000000000000000000..147cd191481910f4568a60c9b2ef747fefeedd14
--- /dev/null
+++ b/htdocs/lib/project.lib.php
@@ -0,0 +1,78 @@
+<?php
+/* Copyright (C) 2006 Laurent Destailleur  <eldy@users.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * or see http://www.gnu.org/
+ *
+ * $Id$
+ * $Source$
+ */
+
+/**
+	    \file       htdocs/lib/project.lib.php
+		\brief      Ensemble de fonctions de base pour le module projet
+        \ingroup    societe
+        \version    $Revision$
+
+		Ensemble de fonctions de base de dolibarr sous forme d'include
+*/
+
+function project_prepare_head($objsoc)
+{
+	global $langs, $conf, $user;
+	$h = 0;
+	$head = array();
+
+	$head[$h][0] = DOL_URL_ROOT.'/projet/fiche.php?id='.$objsoc->id;
+	$head[$h][1] = $langs->trans("Project");
+    $head[$h][2] = 'project';
+	$h++;
+
+	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/fiche.php?id='.$objsoc->id;
+	$head[$h][1] = $langs->trans("Tasks");
+    $head[$h][2] = 'tasks';
+	$h++;
+
+	if ($conf->propal->enabled)
+	{
+		$langs->load("propal");
+		$head[$h][0] = DOL_URL_ROOT.'/projet/propal.php?id='.$objsoc->id;
+		$head[$h][1] = $langs->trans("Proposals");
+	    $head[$h][2] = 'propal';
+		$h++;
+	}
+
+	if ($conf->commande->enabled)
+	{
+		$langs->load("orders");
+		$head[$h][0] = DOL_URL_ROOT.'/projet/commandes.php?id='.$objsoc->id;
+		$head[$h][1] = $langs->trans("Orders");
+	    $head[$h][2] = 'order';
+		$h++;
+	}
+
+	if ($conf->facture->enabled)
+	{
+		$langs->load("bills");
+		$head[$h][0] = DOL_URL_ROOT.'/projet/facture.php?id='.$objsoc->id;
+		$head[$h][1] = $langs->trans("Invoices");
+	    $head[$h][2] = 'invoice';
+		$h++;
+	}
+
+	return $head;
+}
+
+?>
\ No newline at end of file
diff --git a/htdocs/project.class.php b/htdocs/project.class.php
index e1348a35fbe36784509ac5c0560e4ac1a54dadb6..3886d0152adcd4f143c90c7769dde7b050fc8c1d 100644
--- a/htdocs/project.class.php
+++ b/htdocs/project.class.php
@@ -21,10 +21,10 @@
  */
 
 /**
-        \file       htdocs/project.class.php
-        \ingroup    projet
-        \brief      Fichier de la classe de gestion des projets
-        \version    $Revision$
+		\file       htdocs/project.class.php
+		\ingroup    projet
+		\brief      Fichier de la classe de gestion des projets
+		\version    $Revision$
 */
 
 /**
@@ -33,405 +33,469 @@
 */
 class Project
 {
-    var $id;
-    var $db;
-    var $ref;
-    var $title;
-    var $socid;
-    
-    /**
-     *    \brief  Constructeur de la classe
-     *    \param  DB          handler acc�s base de donn�es
-     */
-    function Project($DB)
-    {
-        $this->db = $DB;
-        $this->societe = new Societe($DB);
-    }
-  
-    /*
-     *    \brief      Cr�e un projet en base
-     *    \param      user        Id utilisateur qui cr�e
-     *    \return     int         <0 si ko, id du projet cr�e si ok
-     */
-    function create($user)
-    {
-        if (trim($this->ref))
-        {
-            $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref, title, fk_soc, fk_user_creat, dateo) ";
-            $sql .= " VALUES ('".addslashes($this->ref)."', '".addslashes($this->title)."', $this->socid, ".$user->id.",now()) ;";
-    
-            if ($this->db->query($sql) )
-            {
-                $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet");
-                $result = $this->id;
-            }
-            else
-            {
-                dolibarr_syslog("Project::Create error -2");
-                $this->error=$this->db->error();
-                $result = -2;
-            }
-        }
-        else
-        {
-            dolibarr_syslog("Project::Create error -1 ref null");
-            $result = -1;
-        }
-    
-        return $result;
-    }
-
-
-  function update($user)
-  {
-    if (strlen(trim($this->ref)) > 0)
-      {
-	$sql = "UPDATE ".MAIN_DB_PREFIX."projet";
-	$sql .= " SET ref='$this->ref'";
-	$sql .= " , title = '$this->title'";
-	$sql .= " WHERE rowid = ".$this->id;
-	
-	if ($this->db->query($sql) ) 
-	  {
-	    $result = 0;
-	  }
-	else
-	  {
-	    dolibarr_syslog($this->db->error());
-	    $result = -2;
-	  }    
-      }
-    else
-      {
-	dolibarr_syslog("Project::Update ref null");
-	$result = -1;
-      }    
-  
-    return $result;
-  }  
-
-
-  /*
-   *    \brief      Charge objet projet depuis la base
-   *    \param      rowid       id du projet � charger
-   */
-
-  function fetch($rowid)
-  {
-    
-    $sql = "SELECT title, ref, fk_soc FROM ".MAIN_DB_PREFIX."projet";
-    $sql .= " WHERE rowid=".$rowid;
-
-    $resql = $this->db->query($sql);
-    if ($resql)
-      {
-	if ($this->db->num_rows($resql))
-	  {
-	    $obj = $this->db->fetch_object($resql);
-	    
-	    $this->id = $rowid;
-	    $this->ref = $obj->ref;
-	    $this->title = $obj->title;
-	    $this->titre = $obj->title;
-	    $this->societe->id = $obj->fk_soc;
-	    
-	    $this->db->free($resql);
-
-	    return 0;
-	  }
-	else
-	  {
-	    return -1;
-	  }
-      }
-    else
-      {
-	print $this->db->error();
-	return -2;
-      }
-  }
-	
+	var $id;
+	var $db;
+	var $ref;
+	var $title;
+	var $socid;
+
+	/**
+	*    \brief  Constructeur de la classe
+	*    \param  DB          handler acc�s base de donn�es
+	*/
+	function Project($DB)
+	{
+		$this->db = $DB;
+		$this->societe = new Societe($DB);
+	}
 
-  /*
-   *
-   *
-   *
-   */
-	 
-  function get_propal_list()
-    {
-      $propales = array();
-      $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal WHERE fk_projet=$this->id;";
-      
-      if ($this->db->query($sql) )
+	/*
+	*    \brief      Cr�e un projet en base
+	*    \param      user        Id utilisateur qui cr�e
+	*    \return     int         <0 si ko, id du projet cr�e si ok
+	*/
+	function create($user)
 	{
-	  $nump = $this->db->num_rows();
-	  if ($nump)
-	    {
-	      $i = 0;
-	      while ($i < $nump)
+		if (trim($this->ref))
 		{
-		  $obj = $this->db->fetch_object();
-	      
-		  $propales[$i] = $obj->rowid;
+			$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref, title, fk_soc, fk_user_creat, dateo) ";
+			$sql .= " VALUES ('".addslashes($this->ref)."', '".addslashes($this->title)."', $this->socid, ".$user->id.",now()) ;";
 
-		  $i++;
+			if ($this->db->query($sql) )
+			{
+				$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet");
+				$result = $this->id;
+			}
+			else
+			{
+				dolibarr_syslog("Project::Create error -2");
+				$this->error=$this->db->error();
+				$result = -2;
+			}
+		}
+		else
+		{
+			dolibarr_syslog("Project::Create error -1 ref null");
+			$result = -1;
 		}
-	      $this->db->free();
-	      /*
-	       *  Retourne un tableau contenant la liste des propales associees
-	       */
-	      return $propales;
-	    }
+
+		return $result;
 	}
-      else
-	{
-	  print $this->db->error() . '<br>' .$sql;
-	}      
-    }
 
-		
-  /*
-   *
-   *
-   *
-   */
-  function liste_array($id_societe='')
-    {
-      $projets = array();
-
-      $sql = "SELECT rowid, title FROM ".MAIN_DB_PREFIX."projet";
-
-      if (isset($id_societe))
+
+	function update($user)
 	{
-	  $sql .= " WHERE fk_soc = $id_societe";
+		if (strlen(trim($this->ref)) > 0)
+		{
+			$sql = "UPDATE ".MAIN_DB_PREFIX."projet";
+			$sql .= " SET ref='$this->ref'";
+			$sql .= " , title = '$this->title'";
+			$sql .= " WHERE rowid = ".$this->id;
+
+			if ($this->db->query($sql) )
+			{
+				$result = 0;
+			}
+			else
+			{
+				dolibarr_syslog($this->db->error());
+				$result = -2;
+			}
+		}
+		else
+		{
+			dolibarr_syslog("Project::Update ref null");
+			$result = -1;
+		}
+
+		return $result;
 	}
-      
-      if ($this->db->query($sql) )
+
+
+	/*
+	*    \brief      Charge objet projet depuis la base
+	*    \param      rowid       id du projet � charger
+	*/
+	function fetch($rowid)
 	{
-	  $nump = $this->db->num_rows();
 
-	  if ($nump)
-	    {
-	      $i = 0;
-	      while ($i < $nump)
+		$sql = "SELECT title, ref, fk_soc FROM ".MAIN_DB_PREFIX."projet";
+		$sql .= " WHERE rowid=".$rowid;
+
+		$resql = $this->db->query($sql);
+		if ($resql)
 		{
-		  $obj = $this->db->fetch_object();
-	      
-		  $projets[$obj->rowid] = $obj->title;
-		  $i++;
+			if ($this->db->num_rows($resql))
+			{
+				$obj = $this->db->fetch_object($resql);
+
+				$this->id = $rowid;
+				$this->ref = $obj->ref;
+				$this->title = $obj->title;
+				$this->titre = $obj->title;
+				$this->societe->id = $obj->fk_soc;
+
+				$this->db->free($resql);
+
+				return 0;
+			}
+			else
+			{
+				return -1;
+			}
+		}
+		else
+		{
+			print $this->db->error();
+			return -2;
 		}
-	    }
-	  return $projets;
 	}
-      else
+
+
+	/*
+	*
+	*
+	*
+	*/
+	function get_propal_list()
 	{
-	  print $this->db->error();
+		$propales = array();
+		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal WHERE fk_projet=$this->id;";
+
+		if ($this->db->query($sql) )
+		{
+			$nump = $this->db->num_rows();
+			if ($nump)
+			{
+				$i = 0;
+				while ($i < $nump)
+				{
+					$obj = $this->db->fetch_object();
+
+					$propales[$i] = $obj->rowid;
+
+					$i++;
+				}
+				$this->db->free();
+				/*
+				*  Retourne un tableau contenant la liste des propales associees
+				*/
+				return $propales;
+			}
+		}
+		else
+		{
+			print $this->db->error() . '<br>' .$sql;
+		}
 	}
-      
-    }
-  /*
-   *
-   *
-   *
-   */
-  function get_facture_list()
-    {
-      $factures = array();
-      $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture WHERE fk_projet=$this->id;";
-      
-      $result=$this->db->query($sql);
-      if ($result)
+
+
+	/*
+	*
+	*
+	*
+	*/
+	function liste_array($id_societe='')
 	{
-	  $nump = $this->db->num_rows($result);
-	  if ($nump)
-	    {
-	      $i = 0;
-	      while ($i < $nump)
+		$projets = array();
+
+		$sql = "SELECT rowid, title FROM ".MAIN_DB_PREFIX."projet";
+
+		if (isset($id_societe))
+		{
+			$sql .= " WHERE fk_soc = $id_societe";
+		}
+
+		if ($this->db->query($sql) )
+		{
+			$nump = $this->db->num_rows();
+
+			if ($nump)
+			{
+				$i = 0;
+				while ($i < $nump)
+				{
+					$obj = $this->db->fetch_object();
+
+					$projets[$obj->rowid] = $obj->title;
+					$i++;
+				}
+			}
+			return $projets;
+		}
+		else
 		{
-		  $obj = $this->db->fetch_object($result);
-		  
-		  $factures[$i] = $obj->rowid;
-		  
-		  $i++;
+			print $this->db->error();
 		}
-	      $this->db->free($result);
-	      /*
-	       *  Retourne un tableau contenant la liste des factures associees
-	       */
-	      return $factures;
-	    }
+
 	}
-      else
+	/*
+	*
+	*
+	*
+	*/
+	function get_facture_list()
 	{
-	  dolibarr_print_error($this->db);
+		$factures = array();
+		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture WHERE fk_projet=$this->id;";
+
+		$result=$this->db->query($sql);
+		if ($result)
+		{
+			$nump = $this->db->num_rows($result);
+			if ($nump)
+			{
+				$i = 0;
+				while ($i < $nump)
+				{
+					$obj = $this->db->fetch_object($result);
+
+					$factures[$i] = $obj->rowid;
+
+					$i++;
+				}
+				$this->db->free($result);
+				/*
+				*  Retourne un tableau contenant la liste des factures associees
+				*/
+				return $factures;
+			}
+		}
+		else
+		{
+			dolibarr_print_error($this->db);
+		}
 	}
-    }
-  /**
-   * Renvoie la liste des commande associ�es au projet
-   *
-   *
-   */
-  function get_commande_list()
-    {
-      $commandes = array();
-      $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande WHERE fk_projet=$this->id;";
-      
-      $result=$this->db->query($sql);
-      if ($result)
+	/**
+	* Renvoie la liste des commande associ�es au projet
+	*
+	*
+	*/
+	function get_commande_list()
 	{
-	  $nump = $this->db->num_rows($result);
-	  if ($nump)
-	    {
-	      $i = 0;
-	      while ($i < $nump)
+		$commandes = array();
+		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande WHERE fk_projet=$this->id;";
+
+		$result=$this->db->query($sql);
+		if ($result)
 		{
-		  $obj = $this->db->fetch_object($result);
-		  
-		  $commandes[$i] = $obj->rowid;
-		  
-		  $i++;
+			$nump = $this->db->num_rows($result);
+			if ($nump)
+			{
+				$i = 0;
+				while ($i < $nump)
+				{
+					$obj = $this->db->fetch_object($result);
+
+					$commandes[$i] = $obj->rowid;
+
+					$i++;
+				}
+				$this->db->free($result);
+				/*
+				*  Retourne un tableau contenant la liste des commandes associees
+				*/
+				return $commandes;
+			}
+		}
+		else
+		{
+			dolibarr_print_error($this->db);
 		}
-	      $this->db->free($result);
-	      /*
-	       *  Retourne un tableau contenant la liste des commandes associees
-	       */
-	      return $commandes;
-	    }
 	}
-      else
+
+	/*
+	*    \brief    Supprime l'projet dans la base
+	*    \param    Utilisateur
+	*/
+
+	function delete($user)
 	{
-	  dolibarr_print_error($this->db);
+
+		$sql = "DELETE FROM ".MAIN_DB_PREFIX."projet";
+		$sql .= " WHERE rowid=".$this->id;
+
+		$resql = $this->db->query($sql);
+		if ($resql)
+		{
+			return 0;
+		}
+		else
+		{
+			return -1;
+		}
 	}
-    }
-
-  /*
-   *    \brief    Supprime l'projet dans la base
-   *    \param    Utilisateur
-   */
-
-  function delete($user)
-  {
-    
-    $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet";
-    $sql .= " WHERE rowid=".$this->id;
-
-    $resql = $this->db->query($sql);
-    if ($resql)
-      {
-	return 0;
-      }
-    else
-      {
-	return -1;
-      }
-  }
-
-  /*
-   *    \brief      Cr�e une tache dans le projet
-   *    \param      user        Id utilisateur qui cr�e
-   *    \param     title      titre de la t�che
-   *    \param      parent   tache parente
-   */
-  function CreateTask($user, $title, $parent = 0)
-  {
-    $result = 0;
-    if (trim($title))
-      {
-	$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task (fk_projet, title, fk_user_creat, fk_task_parent) ";
-	$sql .= " VALUES (".$this->id.",'$title', ".$user->id.",".$parent.") ;";
-	
-	if ($this->db->query($sql) )
-	  {
-	    $task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
-	    $result = 0;
-	  }
-	else
-	  {
-	    dolibarr_syslog("Project::CreateTask error -2",LOG_ERR);
-	    dolibarr_syslog($this->db->error(),LOG_ERR);
-	    $this->error=$this->db->error();
-	    $result = -2;
-	  }
-
-	if ($result ==0)
-	  {
-
-	    $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_actors (fk_projet_task, fk_user) ";
-	    $sql .= " VALUES (".$task_id.",".$user->id.") ;";
-	
-	    if ($this->db->query($sql) )
-	      {
+
+	/*
+	*    \brief      Cr�e une tache dans le projet
+	*    \param      user        Id utilisateur qui cr�e
+	*    \param     title      titre de la t�che
+	*    \param      parent   tache parente
+	*/
+	function CreateTask($user, $title, $parent = 0)
+	{
 		$result = 0;
-	      }
-	    else
-	      {
-		dolibarr_syslog("Project::CreateTask error -3",LOG_ERR);
-		$this->error=$this->db->error();
-		$result = -2;
-	      }
-	  }
-
-
-        }
-    else
-      {
-	dolibarr_syslog("Project::CreateTask error -1 ref null");
-	$result = -1;
-      }
-    
-    return $result;
-  }
-  /*
-   *    \brief      Cr�e une tache dans le projet
-   *    \param      user        Id utilisateur qui cr�e
-   *    \param     title      titre de la t�che
-   *    \param      parent   tache parente
-   */
-  function TaskAddTime($user, $task, $time, $date)
-  {
-    $result = 0;
-
-	$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time (fk_task, task_date, task_duration, fk_user)";
-	$sql .= " VALUES (".$task.",'".$this->db->idate($date)."',".$time.", ".$user->id.") ;";
-
-	if ($this->db->query($sql) )
-	  {
-	    $task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
-	    $result = 0;
-	  }
-	else
-	  {
-	    dolibarr_syslog("Project::TaskAddTime error -2",LOG_ERR);
-	    $this->error=$this->db->error();
-	    $result = -2;
-	  }
-
-	if ($result ==0)
-	  {
-
-	    $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
-	    $sql .= " SET duration_effective = duration_effective + '".ereg_replace(",",".",$time)."'";
-	    $sql .= " WHERE rowid = '".$task."';";
-	
-	    if ($this->db->query($sql) )
-	      {
+		if (trim($title))
+		{
+			$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task (fk_projet, title, fk_user_creat, fk_task_parent) ";
+			$sql .= " VALUES (".$this->id.",'$title', ".$user->id.",".$parent.") ;";
+
+			if ($this->db->query($sql) )
+			{
+				$task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
+				$result = 0;
+			}
+			else
+			{
+				dolibarr_syslog("Project::CreateTask error -2",LOG_ERR);
+				dolibarr_syslog($this->db->error(),LOG_ERR);
+				$this->error=$this->db->error();
+				$result = -2;
+			}
+
+			if ($result ==0)
+			{
+
+				$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_actors (fk_projet_task, fk_user) ";
+				$sql .= " VALUES (".$task_id.",".$user->id.") ;";
+
+				if ($this->db->query($sql) )
+				{
+					$result = 0;
+				}
+				else
+				{
+					dolibarr_syslog("Project::CreateTask error -3",LOG_ERR);
+					$this->error=$this->db->error();
+					$result = -2;
+				}
+			}
+
+
+		}
+		else
+		{
+			dolibarr_syslog("Project::CreateTask error -1 ref null");
+			$result = -1;
+		}
+
+		return $result;
+	}
+
+
+	/*
+	*    \brief      Cr�e une tache dans le projet
+	*    \param      user        Id utilisateur qui cr�e
+	*    \param     title      titre de la t�che
+	*    \param      parent   tache parente
+	*/
+	function TaskAddTime($user, $task, $time, $date)
+	{
 		$result = 0;
-	      }
-	    else
-	      {
-		dolibarr_syslog("Project::TaskAddTime error -3",LOG_ERR);
-		$this->error=$this->db->error();
-		$result = -2;
-	      }
-	  }
-	
 
+		$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time (fk_task, task_date, task_duration, fk_user)";
+		$sql .= " VALUES (".$task.",'".$this->db->idate($date)."',".$time.", ".$user->id.") ;";
+
+		if ($this->db->query($sql) )
+		{
+			$task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
+			$result = 0;
+		}
+		else
+		{
+			dolibarr_syslog("Project::TaskAddTime error -2",LOG_ERR);
+			$this->error=$this->db->error();
+			$result = -2;
+		}
+
+		if ($result ==0)
+		{
+			$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
+			$sql .= " SET duration_effective = duration_effective + '".ereg_replace(",",".",$time)."'";
+			$sql .= " WHERE rowid = '".$task."';";
+
+			if ($this->db->query($sql) )
+			{
+				$result = 0;
+			}
+			else
+			{
+				dolibarr_syslog("Project::TaskAddTime error -3",LOG_ERR);
+				$this->error=$this->db->error();
+				$result = -2;
+			}
+		}
+
+		return $result;
+	}
+
+
+	function getTasksRoleForUser($user)
+	{
+		$tasksrole = array();
+
+		/* Liste des taches et role sur la tache du user courant dans $tasksrole */
+		$sql = "SELECT a.fk_projet_task, a.role";
+		$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_actors as a";
+		$sql .= " WHERE a.fk_user = ".$user->id;
+
+		$resql = $this->db->query($sql);
+		if ($resql)
+		{
+			$num = $this->db->num_rows($resql);
+			$i = 0;
+			while ($i < $num)
+			{
+				$row = $this->db->fetch_row($resql);
+				$tasksrole[$row[0]] = $row[1];
+				$i++;
+			}
+			$this->db->free();
+		}
+		else
+		{
+			dolibarr_print_error($this->db);
+		}
+
+		return $tasksrole;
+	}
+
+
+	function getTasksArray()
+	{
+		$tasks = array();
 
+		/* Liste des t�ches dans $tasks */
+	
+		$sql = "SELECT t.rowid, t.title, t.fk_task_parent, t.duration_effective";
+		$sql .= " FROM ".MAIN_DB_PREFIX."projet_task as t";
+		$sql .= " WHERE t.fk_projet =".$this->id;
+		$sql .= " ORDER BY t.fk_task_parent";
+
+		$var=true;
+		$resql = $this->db->query($sql);
+		if ($resql)
+		{
+			$num = $this->db->num_rows($resql);
+			$i = 0;
+			while ($i < $num)
+			{
+				$obj = $this->db->fetch_object($resql);
+				$tasks[$i]->id    = $obj->rowid;
+				$tasks[$i]->title = $obj->title;
+				$tasks[$i]->fk_parent = $obj->fk_task_parent;
+				$tasks[$i]->duration  = $obj->duration_effective;
+				$i++;
+			}
+			$this->db->free();
+		}
+		else
+		{
+			dolibarr_print_error($this->db);
+		}
+		
+		return $tasks;
+	}
 
-    
-    return $result;
-  }
 }
 ?>
diff --git a/htdocs/projet/commandes.php b/htdocs/projet/commandes.php
index a3fd01c80604b5aaf8acf7fc33d63ac6deec7e5d..eae79bc9efcfcd41a04237dd1e39fb53ca93e750 100644
--- a/htdocs/projet/commandes.php
+++ b/htdocs/projet/commandes.php
@@ -31,6 +31,7 @@ require("./pre.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
 require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
 require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php");
 
 if ($conf->projet->enabled) $langs->load("projects");
 $langs->load("companies");
@@ -72,43 +73,13 @@ llxHeader("","../");
 
 $projet = new Project($db);
 $projet->fetch($_GET["id"]);
+$projet->societe->fetch($projet->societe->id);
 
-$h=0;
-$head[$h][0] = DOL_URL_ROOT.'/projet/fiche.php?id='.$projet->id;
-$head[$h][1] = $langs->trans("Project");
-$h++;
-
-$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/fiche.php?id='.$projet->id;
-$head[$h][1] = $langs->trans("Tasks");
-$h++;
-
-if ($conf->propal->enabled) {
-  $langs->load("propal");
-  $head[$h][0] = DOL_URL_ROOT.'/projet/propal.php?id='.$projet->id;
-  $head[$h][1] = $langs->trans("Proposals");
-  $h++;
-}  
-
-if ($conf->commande->enabled) {
-  $langs->load("orders");
-  $head[$h][0] = DOL_URL_ROOT.'/projet/commandes.php?id='.$projet->id;
-  $head[$h][1] = $langs->trans("Orders");
-  $hselected=$h;
-  $h++;
-}
+$head=project_prepare_head($projet);
+dolibarr_fiche_head($head, 'order', $langs->trans("Project"));
 
-if ($conf->facture->enabled) {
-  $langs->load("bills");
-  $head[$h][0] = DOL_URL_ROOT.'/projet/facture.php?id='.$projet->id;
-  $head[$h][1] = $langs->trans("Bills");
-  $h++;
-}
- 
-dolibarr_fiche_head($head, $hselected, $langs->trans("Project").": ".$projet->ref);
 
 
-$projet->societe->fetch($projet->societe->id);
-
 print '<table class="border" width="100%">';
 
 print '<tr><td>'.$langs->trans("Ref").'</td><td>'.$projet->ref.'</td></tr>';
diff --git a/htdocs/projet/facture.php b/htdocs/projet/facture.php
index 31efd1d76e921218062675c24baa4ddc92cb4893..1079f54eff40d12591d2d59e269fd5480e8a3c8f 100644
--- a/htdocs/projet/facture.php
+++ b/htdocs/projet/facture.php
@@ -31,6 +31,7 @@ require("./pre.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
 require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
 require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php");
 
 $langs->load("projects");
 $langs->load("companies");
@@ -73,42 +74,11 @@ llxHeader("","../");
 
 $projet = new Project($db);
 $projet->fetch($_GET["id"]);
+$projet->societe->fetch($projet->societe->id);
 
-$h=0;
-$head[$h][0] = DOL_URL_ROOT.'/projet/fiche.php?id='.$projet->id;
-$head[$h][1] = $langs->trans("Project");
-$h++;
-
-$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/fiche.php?id='.$projet->id;
-$head[$h][1] = $langs->trans("Tasks");
-$h++;
-
-if ($conf->propal->enabled) {
-  $langs->load("propal");
-  $head[$h][0] = DOL_URL_ROOT.'/projet/propal.php?id='.$projet->id;
-  $head[$h][1] = $langs->trans("Proposals");
-  $h++;
-}  
-
-if ($conf->commande->enabled) {
-  $langs->load("orders");
-  $head[$h][0] = DOL_URL_ROOT.'/projet/commandes.php?id='.$projet->id;
-  $head[$h][1] = $langs->trans("Orders");
-  $h++;
-}
-
-if ($conf->facture->enabled) {
-  $langs->load("bills");
-  $head[$h][0] = DOL_URL_ROOT.'/projet/facture.php?id='.$projet->id;
-  $head[$h][1] = $langs->trans("Bills");
-  $hselected=$h;
-  $h++;
-}
- 
-dolibarr_fiche_head($head, $hselected, $langs->trans("Project").": ".$projet->ref);
-
+$head=project_prepare_head($projet);
+dolibarr_fiche_head($head, 'invoice', $langs->trans("Project"));
 
-$projet->societe->fetch($projet->societe->id);
 
 print '<table class="border" width="100%">';
 
diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php
index a0fcf64707cc451199b6ef01c3c43c56b8b8cbed..9e5aa0af00130f6122329e3b11caff3e61340c7b 100644
--- a/htdocs/projet/fiche.php
+++ b/htdocs/projet/fiche.php
@@ -31,6 +31,7 @@ require("./pre.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
 require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
 require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php");
 
 if (!$user->rights->projet->lire) accessforbidden();
 
@@ -44,7 +45,7 @@ if ($projetid == '' && ($_GET['action'] != "create" && $_POST['action'] != "add"
 
 if ($user->societe_id > 0) 
 {
-  $socid = $user->societe_id;
+	$socid = $user->societe_id;
 }
 
 // Protection restriction commercial
@@ -56,7 +57,7 @@ if ($projetid && !$user->rights->commercial->client->voir)
 	$sql.= " WHERE p.rowid = ".$projetid;
 	if (!$user->rights->commercial->client->voir) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id;
 	if ($socid) $sql .= " AND p.fk_soc = ".$socid;
-	
+
 	if ( $db->query($sql) )
 	{
 		if ( $db->num_rows() == 0) accessforbidden();
@@ -66,61 +67,63 @@ if ($projetid && !$user->rights->commercial->client->voir)
 
 if ($_POST["action"] == 'add' && $user->rights->projet->creer)
 {
-  $pro = new Project($db);
-  $pro->socid = $_GET["socid"];
-  $pro->ref = $_POST["ref"];
-  $pro->title = $_POST["title"];
-  $result = $pro->create($user);
-  
-  if ($result > 0)
-    {
-      Header("Location:fiche.php?id=".$pro->id);
-      exit;
-    }
-  else
-    {
-      $mesg='<div class="error">'.$pro->error.'</div>';
-      $_GET["action"] = 'create';
-    }
+	$pro = new Project($db);
+	$pro->socid = $_GET["socid"];
+	$pro->ref = $_POST["ref"];
+	$pro->title = $_POST["title"];
+	$result = $pro->create($user);
+
+	if ($result > 0)
+	{
+		Header("Location:fiche.php?id=".$pro->id);
+		exit;
+	}
+	else
+	{
+		$mesg='<div class="error">'.$pro->error.'</div>';
+		$_GET["action"] = 'create';
+	}
 }
 
 if ($_POST["action"] == 'update' && $user->rights->projet->creer)
 {
-  if (! $_POST["cancel"])
-    {
-      if (!(empty($_POST["id"]) || empty($_POST["ref"]) || empty($_POST["title"])))
+	if (! $_POST["cancel"])
 	{
-	  $projet = new Project($db);
-	  $projet->id = $_POST["id"];
-	  $projet->ref = $_POST["ref"];
-	  $projet->title = $_POST["title"];
-	  $projet->update($user);
-	  
-	  $_GET["id"]=$projet->id;  // On retourne sur la fiche projet
+		if (!(empty($_POST["id"]) || empty($_POST["ref"]) || empty($_POST["title"])))
+		{
+			$projet = new Project($db);
+			$projet->id = $_POST["id"];
+			$projet->ref = $_POST["ref"];
+			$projet->title = $_POST["title"];
+			$projet->update($user);
+
+			$_GET["id"]=$projet->id;  // On retourne sur la fiche projet
+		}
+		else
+		{
+			$_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
+		}
 	}
-      else
+	else
 	{
-	  $_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
+		$_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
 	}
-    }
-  else
-    {
-      $_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
-    }
 }
 
 if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->projet->supprimer)
 {
-  $projet = new Project($db);
-  $projet->id = $_GET["id"];
-  if ($projet->delete($user) == 0)
-    {
-      Header("Location: index.php");
-    }
-  else
-    {
-      Header("Location: fiche.php?id=".$projet->id);
-    }
+	$projet = new Project($db);
+	$projet->id = $_GET["id"];
+	if ($projet->delete($user) == 0)
+	{
+		Header("Location: index.php");
+		exit;
+	}
+	else
+	{
+		Header("Location: fiche.php?id=".$projet->id);
+		exit;
+	}
 }
 
 
@@ -158,109 +161,76 @@ if ($_GET["action"] == 'create' && $user->rights->projet->creer)
 
 } else {
 
-  /*
-   * Fiche projet en mode visu
-   *
-   */
+	/*
+	* Fiche projet en mode visu
+	*
+	*/
 
-  $projet = new Project($db);
-  $projet->fetch($_GET["id"]);
-  $projet->societe->fetch($projet->societe->id);
-  
-  $h=0;
-  $head[$h][0] = DOL_URL_ROOT.'/projet/fiche.php?id='.$projet->id;
-  $head[$h][1] = $langs->trans("Project");
-  $hselected=$h;
-  $h++;
-  
-  $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/fiche.php?id='.$projet->id;
-  $head[$h][1] = $langs->trans("Tasks");
-  $h++;
-
-  if ($conf->propal->enabled)
-    {
-      $langs->load("propal");
-      $head[$h][0] = DOL_URL_ROOT.'/projet/propal.php?id='.$projet->id;
-      $head[$h][1] = $langs->trans("Proposals");
-      $h++;
-    }  
-  
-  if ($conf->commande->enabled)
-    {
-      $langs->load("orders");
-      $head[$h][0] = DOL_URL_ROOT.'/projet/commandes.php?id='.$projet->id;
-      $head[$h][1] = $langs->trans("Orders");
-      $h++;
-    }
-  
-  if ($conf->facture->enabled)
-    {
-      $langs->load("bills");
-      $head[$h][0] = DOL_URL_ROOT.'/projet/facture.php?id='.$projet->id;
-      $head[$h][1] = $langs->trans("Bills");
-      $h++;
-    }
- 
-  dolibarr_fiche_head($head,  $hselected, $langs->trans("Project").": ".$projet->ref);
-
-
-    if ($_GET["action"] == 'delete')
-    {
-      $htmls = new Form($db);
-      $htmls->form_confirm("fiche.php?id=".$_GET["id"],$langs->trans("DeleteAProject"),$langs->trans("ConfirmDeleteAProject"),"confirm_delete");
-      print "<br>";
-    }
-
-  if ($_GET["action"] == 'edit')
-    {  
-      print '<form method="post" action="fiche.php">';
-      print '<input type="hidden" name="action" value="update">';
-      print '<input type="hidden" name="id" value="'.$_GET["id"].'">';
-
-      print '<table class="border" width="100%">';
-
-	// Ref
-      print '<tr><td>'.$langs->trans("Ref").'</td><td><input size="8" name="ref" value="'.$projet->ref.'"></td></tr>';
+	$projet = new Project($db);
+	$projet->fetch($_GET["id"]);
+	$projet->societe->fetch($projet->societe->id);
 
-	// Label
-      print '<tr><td>'.$langs->trans("Label").'</td><td><input size="30" name="title" value="'.$projet->title.'"></td></tr>';      
-
-      print '<tr><td>'.$langs->trans("Company").'</td><td>'.$projet->societe->getNomUrl(1).'</td></tr>';
-      print '<tr><td align="center" colspan="2"><input name="update" class="button" type="submit" value="'.$langs->trans("Modify").'"> &nbsp; <input type="submit" class="button" name="cancel" Value="'.$langs->trans("Cancel").'"></td></tr>';
-      print '</table>';
-      print '</form>';
-    }
-  else
-    {
-      print '<table class="border" width="100%">';
-
-      print '<tr><td>'.$langs->trans("Ref").'</td><td>'.$projet->ref.'</td></tr>';
-      print '<tr><td>'.$langs->trans("Label").'</td><td>'.$projet->title.'</td></tr>';      
-
-      print '<tr><td>'.$langs->trans("Company").'</td><td>'.$projet->societe->getNomUrl(1).'</td></tr>';
-      print '</table>';
-    }
-
-  print '</div>';
-
-  /*
-   * Boutons actions
-   */
-  print '<div class="tabsAction">';
-  
-  if ($_GET["action"] != "edit")
+	$head=project_prepare_head($projet);
+	dolibarr_fiche_head($head, 'project', $langs->trans("Project"));
+
+
+	if ($_GET["action"] == 'delete')
+	{
+		$htmls = new Form($db);
+		$htmls->form_confirm("fiche.php?id=".$_GET["id"],$langs->trans("DeleteAProject"),$langs->trans("ConfirmDeleteAProject"),"confirm_delete");
+		print "<br>";
+	}
+
+	if ($_GET["action"] == 'edit')
+	{
+		print '<form method="post" action="fiche.php">';
+		print '<input type="hidden" name="action" value="update">';
+		print '<input type="hidden" name="id" value="'.$_GET["id"].'">';
+
+		print '<table class="border" width="100%">';
+
+		// Ref
+		print '<tr><td>'.$langs->trans("Ref").'</td><td><input size="8" name="ref" value="'.$projet->ref.'"></td></tr>';
+
+		// Label
+		print '<tr><td>'.$langs->trans("Label").'</td><td><input size="30" name="title" value="'.$projet->title.'"></td></tr>';
+
+		print '<tr><td>'.$langs->trans("Company").'</td><td>'.$projet->societe->getNomUrl(1).'</td></tr>';
+		print '<tr><td align="center" colspan="2"><input name="update" class="button" type="submit" value="'.$langs->trans("Modify").'"> &nbsp; <input type="submit" class="button" name="cancel" Value="'.$langs->trans("Cancel").'"></td></tr>';
+		print '</table>';
+		print '</form>';
+	}
+	else
+	{
+		print '<table class="border" width="100%">';
+
+		print '<tr><td>'.$langs->trans("Ref").'</td><td>'.$projet->ref.'</td></tr>';
+		print '<tr><td>'.$langs->trans("Label").'</td><td>'.$projet->title.'</td></tr>';
+
+		print '<tr><td>'.$langs->trans("Company").'</td><td>'.$projet->societe->getNomUrl(1).'</td></tr>';
+		print '</table>';
+	}
+
+	print '</div>';
+
+	/*
+	* Boutons actions
+	*/
+	print '<div class="tabsAction">';
+
+	if ($_GET["action"] != "edit")
 	{
 		if ($user->rights->projet->creer)
-    {
-    	print '<a class="butAction" href="fiche.php?id='.$projet->id.'&amp;action=edit">'.$langs->trans("Edit").'</a>';
-    }
-    if ($user->rights->projet->supprimer)
-    {
-    	print '<a class="butActionDelete" href="fiche.php?id='.$projet->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
-    }
-  }
-
-  print "</div>";
+		{
+			print '<a class="butAction" href="fiche.php?id='.$projet->id.'&amp;action=edit">'.$langs->trans("Edit").'</a>';
+		}
+		if ($user->rights->projet->supprimer)
+		{
+			print '<a class="butActionDelete" href="fiche.php?id='.$projet->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
+		}
+	}
+
+	print "</div>";
 
 }
 
diff --git a/htdocs/projet/propal.php b/htdocs/projet/propal.php
index 98fb28b83d416b515be65f949ae08113be8b10d9..c57400936efe73ee1dd8353782211aaf9809c207 100644
--- a/htdocs/projet/propal.php
+++ b/htdocs/projet/propal.php
@@ -31,6 +31,7 @@ require("./pre.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
 require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
 require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php");
 
 $langs->load("projects");
 $langs->load("companies");
@@ -72,45 +73,15 @@ llxHeader("","../");
 
 $projet = new Project($db);
 $projet->fetch($_GET["id"]);
+$projet->societe->fetch($projet->societe->id);
 
-$h=0;
-$head[$h][0] = DOL_URL_ROOT.'/projet/fiche.php?id='.$projet->id;
-$head[$h][1] = $langs->trans("Project");
-$h++;
-
-$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/fiche.php?id='.$projet->id;
-$head[$h][1] = $langs->trans("Tasks");
-$h++;
-
-if ($conf->propal->enabled) {
-  $langs->load("propal");
-  $head[$h][0] = DOL_URL_ROOT.'/projet/propal.php?id='.$projet->id;
-  $head[$h][1] = $langs->trans("Proposals");
-  $hselected=$h;
-  $h++;
-}  
-
-if ($conf->commande->enabled) {
-  $langs->load("orders");
-  $head[$h][0] = DOL_URL_ROOT.'/projet/commandes.php?id='.$projet->id;
-  $head[$h][1] = $langs->trans("Orders");
-  $h++;
-}
 
-if ($conf->facture->enabled) {
-  $langs->load("bills");
-  $head[$h][0] = DOL_URL_ROOT.'/projet/facture.php?id='.$projet->id;
-  $head[$h][1] = $langs->trans("Bills");
-  $h++;
-}
- 
-dolibarr_fiche_head($head, $hselected, $langs->trans("Project").": ".$projet->ref);
+$head=project_prepare_head($projet);
+dolibarr_fiche_head($head, 'propal', $langs->trans("Project"));
 
 
 $propales = array();
 
-$projet->societe->fetch($projet->societe->id);
-
 print '<table class="border" width="100%">';
 print '<tr><td>'.$langs->trans("Ref").'</td><td>'.$projet->ref.'</td></tr>';
 print '<tr><td>'.$langs->trans("Label").'</td><td>'.$projet->title.'</td></tr>';      
diff --git a/htdocs/projet/tasks/fiche.php b/htdocs/projet/tasks/fiche.php
index a7b95901021fa98f5f76f60d6abb986386736704..d1f38b9bddfd2eeb3d7f6eaeaaed995a1789814b 100644
--- a/htdocs/projet/tasks/fiche.php
+++ b/htdocs/projet/tasks/fiche.php
@@ -28,6 +28,7 @@
 */
 
 require("./pre.inc.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php");
 
 $user->getrights('projet');
 
@@ -61,85 +62,90 @@ if ($projetid && !$user->rights->commercial->client->voir)
         }
 }
 
-Function PLines(&$inc, $parent, $lines, &$level, $actors)
+Function PLines(&$inc, $parent, $lines, &$level, $tasksrole)
 {
-  $form = new Form($db); // $db est null ici mais inutile pour la fonction select_date()
-  global $user, $bc, $langs;
-  for ($i = 0 ; $i < sizeof($lines) ; $i++)
-    {
-      if ($parent == 0)
-	$level = 0;
+	$form = new Form($db); // $db est null ici mais inutile pour la fonction select_date()
+	global $user, $bc, $langs;
 
-      if ($lines[$i][1] == $parent)
+	for ($i = 0 ; $i < sizeof($lines) ; $i++)
 	{
-	  $var = !$var;
-	  print "<tr $bc[$var]>\n<td>";
-
-	  for ($k = 0 ; $k < $level ; $k++)
-	    {
-	      print "&nbsp;&nbsp;&nbsp;";
-	    }
-
-	  print '<a href="task.php?id='.$lines[$i][2].'">'.$lines[$i][0]."</a></td>\n";
-
-	  $heure = intval($lines[$i][3]);
-	  $minutes = (($lines[$i][3] - $heure) * 60);
-	  $minutes = substr("00"."$minutes", -2);
-
-	  print '<td align="right">'.$heure."&nbsp;h&nbsp;".$minutes."</td>\n";
-
-	  // TODO am�liorer le test
+		if ($parent == 0)
+		$level = 0;
 
-	  if ($actors[$lines[$i][2]] == 'admin')
-	    {
-	      print '<td><input size="4" type="text" class="flat" name="task'.$lines[$i][2].'" value="">';
-	      print '&nbsp;<input type="submit" class="button" value="'.$langs->trans("Save").'"></td>';
-	      print "\n<td>";
-	      print $form->select_date('',$lines[$i][2],'','','',"addtime");
-	      print '</td>';
-	    }
-	  else
-	    {
-	      print '<td colspan="2">&nbsp;</td>';
-	    }
-	  print "</tr>\n";
-	  $inc++;
-	  $level++;
-	  PLines($inc, $lines[$i][2], $lines, $level, $actors);
-	  $level--;
-	}
-      else
-	{
-	  //$level--;
+		if ($lines[$i]->fk_parent == $parent)
+		{
+			$var = !$var;
+			print "<tr $bc[$var]>\n";
+
+			print "<td>".$lines[$i]->id."</td>";
+
+			print "<td>";
+
+			for ($k = 0 ; $k < $level ; $k++)
+			{
+				print "&nbsp;&nbsp;&nbsp;";
+			}
+
+			print '<a href="task.php?id='.$lines[$i]->id.'">'.$lines[$i]->title."</a></td>\n";
+
+			$heure = intval($lines[$i]->duration);
+			$minutes = (($lines[$i]->duration - $heure) * 60);
+			$minutes = substr("00"."$minutes", -2);
+
+			print '<td align="right">'.$heure."&nbsp;h&nbsp;".$minutes."</td>\n";
+
+			// TODO am�liorer le test
+
+			if ($tasksrole[$lines[$i]->id] == 'admin')
+			{
+				print '<td><input size="4" type="text" class="flat" name="task'.$lines[$i]->id.'" value="">';
+				print '&nbsp;<input type="submit" class="button" value="'.$langs->trans("Save").'"></td>';
+				print "\n<td>";
+				print $form->select_date('',$lines[$i]->id,'','','',"addtime");
+				print '</td>';
+			}
+			else
+			{
+				print '<td colspan="2">&nbsp;</td>';
+			}
+			print "</tr>\n";
+			$inc++;
+			$level++;
+			PLines($inc, $lines[$i]->id, $lines, $level, $tasksrole);
+			$level--;
+		}
+		else
+		{
+			//$level--;
+		}
 	}
-    }
 }
 
 Function PLineSelect(&$inc, $parent, $lines, &$level)
 {
-  for ($i = 0 ; $i < sizeof($lines) ; $i++)
-    {
-      if ($parent == 0)
-	$level = 0;
-
-      if ($lines[$i][1] == $parent)
+	for ($i = 0 ; $i < sizeof($lines) ; $i++)
 	{
-	  $var = !$var;
-	  print '<option value="'.$lines[$i][2].'">';
+		if ($parent == 0)
+		$level = 0;
 
-	  for ($k = 0 ; $k < $level ; $k++)
-	    {
-	      print "&nbsp;&nbsp;&nbsp;";
-	    }
+		if ($lines[$i]->fk_parent == $parent)
+		{
+			$var = !$var;
+			print '<option value="'.$lines[$i]->id.'">';
 
-	  print $lines[$i][0]."</option>\n";
+			for ($k = 0 ; $k < $level ; $k++)
+			{
+				print "&nbsp;&nbsp;&nbsp;";
+			}
 
-	  $inc++;
-	  $level++;
-	  PLineSelect($inc, $lines[$i][2], $lines, $level);
-	  $level--;
+			print $lines[$i]->title."</option>\n";
+
+			$inc++;
+			$level++;
+			PLineSelect($inc, $lines[$i]->id, $lines, $level);
+			$level--;
+		}
 	}
-    }
 }
 
 
@@ -181,6 +187,7 @@ if ($_POST["action"] == 'addtime' && $user->rights->projet->creer)
 	}
       
       Header("Location:fiche.php?id=".$pro->id);
+      exit;
     }
 }
 
@@ -217,144 +224,61 @@ if ($_GET["action"] == 'create' && $user->rights->projet->creer)
 
 } else {
 
-  /*
-   * Fiche projet en mode visu
-   *
-   */
+	/*
+	* Fiche projet en mode visu
+	*
+	*/
 
-  $projet = new Project($db);
-  $projet->fetch($_GET["id"]);
-  $projet->societe->fetch($projet->societe->id);
-  
-  $h=0;
-  $head[$h][0] = DOL_URL_ROOT.'/projet/fiche.php?id='.$projet->id;
-  $head[$h][1] = $langs->trans("Project");
-  $h++;
-  
-  $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/fiche.php?id='.$projet->id;
-  $head[$h][1] = $langs->trans("Tasks");
-  $hselected=$h;
-  $h++;
+	$projet = new Project($db);
+	$projet->fetch($_GET["id"]);
+	$projet->societe->fetch($projet->societe->id);
 
-  if ($conf->propal->enabled)
-    {
-      $langs->load("propal");
-      $head[$h][0] = DOL_URL_ROOT.'/projet/propal.php?id='.$projet->id;
-      $head[$h][1] = $langs->trans("Proposals");
-      $h++;
-    }  
-  
-  if ($conf->commande->enabled)
-    {
-      $langs->load("orders");
-      $head[$h][0] = DOL_URL_ROOT.'/projet/commandes.php?id='.$projet->id;
-      $head[$h][1] = $langs->trans("Orders");
-      $h++;
-    }
-  
-  if ($conf->facture->enabled)
-    {
-      $langs->load("bills");
-      $head[$h][0] = DOL_URL_ROOT.'/projet/facture.php?id='.$projet->id;
-      $head[$h][1] = $langs->trans("Bills");
-      $h++;
-    }
- 
-  dolibarr_fiche_head($head,  $hselected, $langs->trans("Project").": ".$projet->ref);
+	$head=project_prepare_head($projet);
+	dolibarr_fiche_head($head, 'tasks', $langs->trans("Project"));
 
-  print '<form method="POST" action="fiche.php?id='.$projet->id.'">';
-  print '<input type="hidden" name="action" value="createtask">';
-  print '<table class="border" width="100%">';
 
-	print '<tr><td>'.$langs->trans("Ref").'</td><td>'.$projet->ref.'</td></tr>';
-	print '<tr><td>'.$langs->trans("Label").'</td><td>'.$projet->title.'</td></tr>';      
+	print '<form method="POST" action="fiche.php?id='.$projet->id.'">';
+	print '<input type="hidden" name="action" value="createtask">';
+	print '<table class="border" width="100%">';
 
-  print '<td>'.$langs->trans("Company").'</td><td>'.$projet->societe->getNomUrl(1).'</td></tr>';
+	print '<tr><td>'.$langs->trans("Ref").'</td><td>'.$projet->ref.'</td></tr>';
+	print '<tr><td>'.$langs->trans("Label").'</td><td>'.$projet->title.'</td></tr>';
 
+	print '<td>'.$langs->trans("Company").'</td><td>'.$projet->societe->getNomUrl(1).'</td></tr>';
 
-  /* Liste des acteurs */
-  $sql = "SELECT a.fk_projet_task, a.role";
-  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_actors as a";
-  $sql .= " WHERE a.fk_user = ".$user->id;
-  
-  $resql = $db->query($sql);
-  if ($resql)
-    {
-      $num = $db->num_rows($resql);
-      $i = 0;
-      $actors = array();      
-      while ($i < $num)
-	{
-	  $row = $db->fetch_row($resql);
-	  $actors[$row[0]] = $row[1]; 
-	  $i++;
-	}
-      $db->free();
-    }
-  else
-    {
-      dolibarr_print_error($db);
-    }
-  
-  /* Liste des t�ches */
+	$tasksrole=$projet->getTasksRoleForUser($user);
 
-  $sql = "SELECT t.rowid, t.title, t.fk_task_parent, t.duration_effective";
-  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task as t";
-  $sql .= " WHERE t.fk_projet =".$projet->id;
-  $sql .= " ORDER BY t.fk_task_parent";
+	$tasksarray=$projet->getTasksArray();
+	
+	/* Nouvelle t�che */
+	print '<tr><td>'.$langs->trans("NewTask").'</td><td colspan="3">';
+	print '<input type="text" size="25" name="task_name" class="flat">&nbsp;';
+	print '<select class="flat" name="task_parent">';
+	print '<option value="0" selected="true">&nbsp;</option>';
+	PLineSelect($j, 0, $tasksarray, $level);
+	print '</select>&nbsp;';
+	print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
+	print '</td></tr>';
 
-  $var=true;
-  $resql = $db->query($sql);
-  if ($resql)
-    {
-      $num = $db->num_rows($resql);
-      $i = 0;
-      $tasks = array();      
-      while ($i < $num)
-	{
-	  $obj = $db->fetch_object($resql);
-	  $tasks[$i][0] = $obj->title; 
-	  $tasks[$i][1] = $obj->fk_task_parent; 
-	  $tasks[$i][2] = $obj->rowid;
-	  $tasks[$i][3] = $obj->duration_effective; 
-	  $i++;
-	}
-      $db->free();
-    }
-  else
-    {
-      dolibarr_print_error($db);
-    }
+	print '</table></form><br />';
 
+	print '<form name="addtime" method="POST" action="fiche.php?id='.$projet->id.'">';
+	print '<input type="hidden" name="action" value="addtime">';
 
-  /* Nouvelle t�che */
+	print '<table class="noborder" width="100%">';
+	print '<tr class="liste_titre">';
+	print '<td>'.$langs->trans("ID").'</td>';
+	print '<td>'.$langs->trans("Task").'</td>';
+	print '<td align="right">'.$langs->trans("DurationEffective").'</td>';
+	print '<td colspan="2">'.$langs->trans("AddDuration").'</td>';
+	print "</tr>\n";
+	PLines($j, 0, $tasksarray, $level, $tasksrole);
+	print '</form>';
 
-  print '<tr><td>'.$langs->trans("NewTask").'</td><td colspan="3">';
-  print '<input type="text" size="25" name="task_name" class="flat">&nbsp;';
-  print '<select class="flat" name="task_parent">';
-  print '<option value="0" selected="true">&nbsp;</option>';
-  PLineSelect($j, 0, $tasks, $level);  
-  print '</select>&nbsp;';
-  print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
-  print '</td></tr>';
 
-  print '</table></form><br />';
-
-  print '<form name="addtime" method="POST" action="fiche.php?id='.$projet->id.'">';
-  print '<input type="hidden" name="action" value="addtime">';
-  print '<table class="noborder" width="100%">';
-  print '<tr class="liste_titre">';
-  print '<td>'.$langs->trans("Task").'</td>';
-  print '<td align="right">'.$langs->trans("DurationEffective").'</td>';
-  print '<td colspan="2">'.$langs->trans("AddDuration").'</td>';
-  print "</tr>\n";      
-  PLines($j, 0, $tasks, $level, $actors);
-  print '</form>';
+	print "</table>";
+	print '</div>';
 
-  
-  print "</table>";    
-  print '</div>';
-  
 
 }