From 354fa8a605627e86de5131587d915cb95e77c991 Mon Sep 17 00:00:00 2001
From: Regis Houssin <regis@dolibarr.fr>
Date: Thu, 28 Jan 2010 08:52:41 +0000
Subject: [PATCH] Works on enhancement of project tasks

---
 htdocs/html.form.class.php         |  2 +-
 htdocs/html.formother.class.php    | 39 +++++++++++++++++++++++++++---
 htdocs/lib/functions.lib.php       |  2 +-
 htdocs/lib/project.lib.php         | 32 +++++++++++++++++-------
 htdocs/projet/tasks/fiche.php      |  4 +--
 htdocs/projet/tasks/task.class.php |  8 +++---
 6 files changed, 66 insertions(+), 21 deletions(-)

diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index 73445151fed..9acbf91f282 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -4,7 +4,7 @@
  * Copyright (C) 2004      Benoit Mortier        <benoit.mortier@opensides.be>
  * Copyright (C) 2004      Sebastien Di Cintio   <sdicintio@ressource-toi.org>
  * Copyright (C) 2004      Eric Seigne           <eric.seigne@ryxeo.com>
- * Copyright (C) 2005-2009 Regis Houssin         <regis@dolibarr.fr>
+ * Copyright (C) 2005-2010 Regis Houssin         <regis@dolibarr.fr>
  * Copyright (C) 2006      Andre Cianfarani      <acianfa@free.fr>
  * Copyright (C) 2006      Marc Barilley/Ocebo   <marc@ocebo.com>
  * Copyright (C) 2007      Franky Van Liedekerke <franky.van.liedekerker@telenet.be>
diff --git a/htdocs/html.formother.class.php b/htdocs/html.formother.class.php
index 23fca351263..5e2ada84236 100644
--- a/htdocs/html.formother.class.php
+++ b/htdocs/html.formother.class.php
@@ -4,7 +4,7 @@
  * Copyright (C) 2004      Benoit Mortier       <benoit.mortier@opensides.be>
  * Copyright (C) 2004      Sebastien Di Cintio  <sdicintio@ressource-toi.org>
  * Copyright (C) 2004      Eric Seigne          <eric.seigne@ryxeo.com>
- * Copyright (C) 2005-2009 Regis Houssin        <regis@dolibarr.fr>
+ * Copyright (C) 2005-2010 Regis Houssin        <regis@dolibarr.fr>
  * Copyright (C) 2006      Andre Cianfarani     <acianfa@free.fr>
  * Copyright (C) 2006      Marc Barilley/Ocebo  <marc@ocebo.com>
  * Copyright (C) 2007      Franky Van Liedekerke <franky.van.liedekerker@telenet.be>
@@ -200,6 +200,37 @@ class FormOther
 		}
 	}
 
+	/**
+	 *    \brief     Retourne une liste de pourcentage
+	 *    \param     selected      pourcentage pre-selectionne
+	 *    \param     htmlname      nom de la liste deroulante
+	 *    \param     increment     increment value
+	 *    \param     start         start value
+	 *    \param     end           end value
+	 *    \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)
+			{
+				$return.= '<option value="'.$i.'" selected="true">';
+			}
+			else
+			{
+				$return.= '<option value="'.$i.'">';
+			}
+			$return.= $i.' % ';
+			$return.= '</option>';
+		}
+		
+		$return.= '</select>';
+		
+		return $return;
+	}
 
 	/**
 	 *	\brief     	Retourn list of project and tasks
@@ -217,7 +248,7 @@ class FormOther
 
 		//print $modeproject.'-'.$modetask;
 		$task=new Task($this->db);
-		$tasksarray=$task->getTasksArray($modetask?$user:0, $modeproject?$user:0, $mode);
+		$tasksarray=$task->getTasksArray($modetask?$user:0, $modeproject?$user:0, $selected);
 		if ($tasksarray)
 		{
 			print '<select class="flat" name="'.$htmlname.'">';
@@ -296,7 +327,7 @@ class FormOther
 		$couleur = imagecolorallocate($image,$rouge,$vert,$bleu);
 		//print $rouge.$vert.$bleu;
 		imagefill($image,0,0,$couleur); //on remplit l'image
-		// On cree la couleur et on l'attribue � une variable pour ne pas la perdre
+		// On cree la couleur et on l'attribue a une variable pour ne pas la perdre
 		ImagePng($image,$file); //renvoie une image sous format png
 		ImageDestroy($image);
 	}
@@ -366,7 +397,7 @@ function PLineSelect(&$inc, $parent, $lines, $level=0)
 				{
 					print "&nbsp;&nbsp;&nbsp;";
 				}
-				print $lines[$i]->title."</option>\n";
+				print $lines[$i]->label."</option>\n";
 				$inc++;
 			}
 
diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php
index 355a8bd1c86..c7fc1557a3b 100644
--- a/htdocs/lib/functions.lib.php
+++ b/htdocs/lib/functions.lib.php
@@ -5,7 +5,7 @@
  * Copyright (C) 2004      Sebastien Di Cintio  <sdicintio@ressource-toi.org>
  * Copyright (C) 2004      Benoit Mortier       <benoit.mortier@opensides.be>
  * Copyright (C) 2004      Christophe Combelles <ccomb@free.fr>
- * Copyright (C) 2005-2009 Regis Houssin        <regis@dolibarr.fr>
+ * Copyright (C) 2005-2010 Regis Houssin        <regis@dolibarr.fr>
  * Copyright (C) 2008      Raphael Bertrand (Resultic)       <raphael.bertrand@resultic.fr>
  *
  * This program is free software; you can redistribute it and/or modify
diff --git a/htdocs/lib/project.lib.php b/htdocs/lib/project.lib.php
index f82a00a6367..36712e7ed0a 100644
--- a/htdocs/lib/project.lib.php
+++ b/htdocs/lib/project.lib.php
@@ -137,12 +137,13 @@ function task_prepare_head($object)
  */
 function select_projects($socid, $selected='', $htmlname='projectid')
 {
-	global $db,$langs;
+	global $db,$conf,$langs;
 
 	// On recherche les projets
 	$sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc';
 	$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p';
-	$sql.= " WHERE (fk_soc='".$socid."' or fk_soc IS NULL)";
+	$sql.= " WHERE (p.fk_soc='".$socid."' OR p.fk_soc IS NULL)";
+	$sql.= " AND p.entity = ".$conf->entity;
 	$sql.= " ORDER BY p.title ASC";
 
 	dol_syslog("project.lib::select_projects sql=".$sql);
@@ -447,7 +448,9 @@ function clean_orphelins($db)
 
 	// There is orphelins. We clean that
 	$listofid=array();
-	$sql='SELECT rowid from '.MAIN_DB_PREFIX.'projet_task';
+	
+	$sql='SELECT rowid FROM '.MAIN_DB_PREFIX.'projet_task';
+	
 	$resql = $db->query($sql);
 	if ($resql)
 	{
@@ -469,13 +472,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 set fk_task_parent = 0 where fk_task_parent';
-		$sql.= ' NOT IN ('.join(',',$listofid).')';
-		$resql = $db->query($sql);
-		$nb=$db->affected_rows($sql);
+		
+		$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);		
+		if ($resql)
+		{
+			$nb=$db->affected_rows($sql);
+			
+			return $nb;
+		}
+		else
+		{
+			return -1;
+		}	
 	}
-
-	return $nb;
+	
 }
 
 ?>
\ No newline at end of file
diff --git a/htdocs/projet/tasks/fiche.php b/htdocs/projet/tasks/fiche.php
index 3829756aa0e..67faf57fea9 100644
--- a/htdocs/projet/tasks/fiche.php
+++ b/htdocs/projet/tasks/fiche.php
@@ -300,9 +300,9 @@ else
 	// 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=$task->getTasksArray(0, 0, 0);
+	$tasksarray=$task->getTasksArray(0, 0, $project->id);
 	// We load also tasks limited to a particular user
-	$tasksrole=($_REQUEST["mode"]=='mine' ? $task->getTasksRoleForUser($user) : '');
+	$tasksrole=($_REQUEST["mode"]=='mine' ? $task->getTasksRoleForUser($user,$project->id) : '');
 
 	print '<table class="noborder" width="100%">';
 	print '<tr class="liste_titre">';
diff --git a/htdocs/projet/tasks/task.class.php b/htdocs/projet/tasks/task.class.php
index 4f30480c8b9..f494fd4094a 100644
--- a/htdocs/projet/tasks/task.class.php
+++ b/htdocs/projet/tasks/task.class.php
@@ -417,7 +417,7 @@ class Task extends CommonObject
 	 * @param	mode	0=Return list of tasks and their projects, 1=Return projects and tasks if exists
 	 * @return 	array	Array of tasks
 	 */
-	function getTasksArray($usert=0, $userp=0, $mode=0, $socid=0)
+	function getTasksArray($usert=0, $userp=0, $projectid=0, $socid=0)
 	{
 		global $conf;
 
@@ -434,7 +434,7 @@ class Task extends CommonObject
 		$sql.= " WHERE t.fk_projet = p.rowid";
 		$sql.= " AND p.entity = ".$conf->entity;
 		if ($socid)	$sql.= " AND p.fk_soc = ".$socid;
-		if ($this->id) $sql.= " AND t.fk_projet =".$this->id;
+		if ($projectid) $sql.= " AND t.fk_projet =".$projectid;
 		$sql.= " ORDER BY p.ref, t.label";
 
 		dol_syslog("Project::getTasksArray sql=".$sql, LOG_DEBUG);
@@ -474,7 +474,7 @@ class Task extends CommonObject
 	 * @param unknown_type $user
 	 * @return unknown
 	 */
-	function getTasksRoleForUser($user)
+	function getTasksRoleForUser($user,$projectid=0)
 	{
 		$tasksrole = array();
 
@@ -487,7 +487,7 @@ class Task extends CommonObject
 		$sql.= " AND ctc.element = '".$this->element."'";
 		$sql.= " AND ctc.rowid = ec.fk_c_type_contact";
 		$sql.= " AND ec.fk_socpeople = ".$user->id;
-		if ($this->id) $sql.= " AND pt.fk_projet =".$this->id;
+		if ($projectid) $sql.= " AND pt.fk_projet =".$projectid;
 
 		$resql = $this->db->query($sql);
 		if ($resql)
-- 
GitLab