From 4e12effab15e82594201950766fd14c43195f2c1 Mon Sep 17 00:00:00 2001
From: Regis Houssin <regis@dolibarr.fr>
Date: Sat, 6 Nov 2010 20:55:52 +0000
Subject: [PATCH] =?UTF-8?q?Fix:=20add=20patch=20of=20Fran=8Dois=20LEGASTEL?=
 =?UTF-8?q?OIS?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 htdocs/projet/activity/list.php | 53 ++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 27 deletions(-)

diff --git a/htdocs/projet/activity/list.php b/htdocs/projet/activity/list.php
index 840a8f9f9f9..e4531668b5d 100644
--- a/htdocs/projet/activity/list.php
+++ b/htdocs/projet/activity/list.php
@@ -2,6 +2,7 @@
 /* Copyright (C) 2005      Rodolphe Quiedeville <rodolphe@quiedeville.org>
  * Copyright (C) 2004-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005-2010 Regis Houssin        <regis@dolibarr.fr>
+ * Copyright (C) 2010      François Legastelois <flegastelois@teclib.com>
  *
  * 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
@@ -68,33 +69,31 @@ if ($_POST["action"] == 'createtask' && $user->rights->projet->creer)
 
 if ($_POST["action"] == 'addtime' && $user->rights->projet->creer)
 {
-	// TODO probleme si que des minutes
-	foreach ($_POST as $key => $time)
-	{
-		if (substr($key,-4) == 'hour')
-  		{
-  			if ($time > 0)
-		  	{
-				$id = str_replace("hour","",$key);
-
-				$task = new Task($db);
-				$task->fetch($id);
-
-		  		$task->timespent_fk_user = $user->id;
-				$task->timespent_duration = $_POST[$id."hour"]*60*60;	// We store duration in seconds
-		  		$task->timespent_duration+= $_POST[$id."min"]*60;		// We store duration in seconds
-				$task->timespent_date = dol_mktime(12,0,0,$_POST["$id"."month"],$_POST["$id"."day"],$_POST["$id"."year"]);
-
-		  		$task->addTimeSpent($user);
-		  	}
-		  	else
-		  	{
-		  		if ($time != '') $mesg='<div class="error">'.$langs->trans("ErrorBadValue").'</div>';
-		  	}
-		}
-	}
-}
-
+	foreach($_POST as $key => $time)
+ 	{
+		if(intval($time)>0)
+		{
+			// Hours or minutes
+			if(preg_match("/([0-9]+)(hour|min)/",$key,$matches))
+			{
+ 				$task = new Task($db);
+				$task->fetch($matches[1]);
+				
+				// We store HOURS in seconds
+				if($matches[2]=='hour') $task->timespent_duration = $time*60*60;
+
+				// We store MINUTES in seconds
+				if($matches[2]=='min') $task->timespent_duration = $time*60;
+					
+				$task->timespent_fk_user = $user->id;
+				$task->timespent_date = dol_mktime(12,0,0,$_POST["{$matches[1]}month"],$_POST["{$matches[1]}day"],$_POST["{$matches[1]}year"]);	
+				$task->addTimeSpent($user);
+			}
+ 		}
+
+		if(intval($time)<0) $mesg='<div class="error">'.$langs->trans("ErrorBadValue").'</div>';
+	}	
+ }
 
 /*
  * View
-- 
GitLab