From b2a265a1a8c1de9a7484f31836e53d8d1b5c9a5c Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 27 Jan 2010 07:58:31 +0000 Subject: [PATCH] Works on enhancement of project tasks --- htdocs/lib/project.lib.php | 4 +- htdocs/main.inc.php | 27 ------------ htdocs/projet/activity/list.php | 21 +++++----- htdocs/projet/project.class.php | 67 ++++-------------------------- htdocs/projet/tasks/fiche.php | 8 ++-- htdocs/projet/tasks/task.class.php | 57 +++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 102 deletions(-) diff --git a/htdocs/lib/project.lib.php b/htdocs/lib/project.lib.php index fe625511fe3..f82a00a6367 100644 --- a/htdocs/lib/project.lib.php +++ b/htdocs/lib/project.lib.php @@ -223,7 +223,7 @@ function PLinesb(&$inc, $parent, $lines, &$level, &$tasksrole) print "   "; } - print $lines[$i]->title; + print $lines[$i]->label; print "\n"; // Project @@ -238,7 +238,7 @@ function PLinesb(&$inc, $parent, $lines, &$level, &$tasksrole) $minutes = substr("00"."$minutes", -2); print ''.$heure." h ".$minutes."\n"; - if ($tasksrole[$lines[$i]->id] == 'admin') + if ($tasksrole[$lines[$i]->id] == 'TASKEXECUTIVE') { print ''; print $form->select_date('',$lines[$i]->id,'','','',"addtime"); diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index c9a9eabeeb8..c8c2b4576c6 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -227,7 +227,6 @@ if (! empty($_SESSION["disablemodules"])) } // Init Smarty -// TODO activer smarty par defaut ? if (sizeof($conf->need_smarty) > 0 || $conf->global->MAIN_SMARTY) { // Usage of const in conf.php file can overwrite default dir. @@ -249,32 +248,6 @@ if (sizeof($conf->need_smarty) > 0 || $conf->global->MAIN_SMARTY) } } -// Init Dwoo -if ($conf->global->MAIN_DWOO2) -{ - // Usage of const in conf.php file can overwrite default dir. - if (empty($dolibarr_dwoo_libs_dir)) $dolibarr_dwoo_libs_dir=DOL_DOCUMENT_ROOT.'/includes/dwoo/'; - if (empty($dolibarr_dwoo_compile)) $dolibarr_dwoo_compile=DOL_DATA_ROOT.'/dwoo/templates/temp'; - if (empty($dolibarr_dwoo_cache)) $dolibarr_dwoo_cache=DOL_DATA_ROOT.'/dwoo/cache/temp'; - - //$dwoo_libs = $dolibarr_dwoo_libs_dir. "dwooAutoload.php"; - $dwoo_libs = $dolibarr_dwoo_libs_dir. "Dwoo.php"; - $dwoo_smarty_adapter = $dolibarr_dwoo_libs_dir. "Dwoo/Smarty/Adapter.php"; - - if (include_once($dwoo_libs) && include_once($dwoo_smarty_adapter)) - { - //$dwoo = new Dwoo($dolibarr_dwoo_compile,$dolibarr_dwoo_cache); - $smarty = new Dwoo_Smarty_Adapter(); - $smarty->show_compat_errors = true; - $smarty->compile_dir = $dolibarr_smarty_compile; - $smarty->cache_dir = $dolibarr_smarty_cache; - } - else - { - dol_print_error('',"Library Dwoo ".$dwoo_libs." not found."); - } -} - /* * Phase authentication / login */ diff --git a/htdocs/projet/activity/list.php b/htdocs/projet/activity/list.php index 24adcf8b14e..7b5498c335f 100644 --- a/htdocs/projet/activity/list.php +++ b/htdocs/projet/activity/list.php @@ -31,7 +31,7 @@ require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php"); $mode=$_REQUEST["mode"]; $projectid=''; -$projectid=isset($_GET["id"])?$_GET["id"]:$_POST["projetid"]; +$projectid=isset($_GET["id"])?$_GET["id"]:$_POST["projectid"]; // Security check if ($user->societe_id) $socid=$user->societe_id; @@ -74,11 +74,8 @@ if ($_POST["action"] == 'addtime' && $user->rights->projet->creer) $task=new Task($db); $task->fetch($id); - $project = new Project($db); - $result = $project->fetch($task->fk_projet); - $date = dol_mktime(12,0,0,$_POST["$id"."month"],$_POST["$id"."day"],$_POST["$id"."year"]); - $project->TaskAddTime($user, $id , $post, $date); + $task->addTimeSpent($user, $post, $date); } else { @@ -100,11 +97,13 @@ if ($mode == 'mine') $title=$langs->trans("MyTimeSpent"); llxHeader("",$title,""); -$projet = new Project($db); +$project = new Project($db); +$task = new Task($db); + if ($_GET["id"]) { - $projet->fetch($_GET["id"]); - $projet->societe->fetch($projet->societe->id); + $project->fetch($_GET["id"]); + $project->societe->fetch($project->societe->id); } @@ -117,11 +116,11 @@ print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorde if ($mesg) print $mesg; -$tasksrole=$projet->getTasksRoleForUser($user); -$tasksarray=$projet->getTasksArray(0,0); +$tasksrole=$task->getTasksRoleForUser($user); +$tasksarray=$task->getTasksArray(0,0); //var_dump($tasksarray); -print '
'; +print ''; print ''; print ''; diff --git a/htdocs/projet/project.class.php b/htdocs/projet/project.class.php index 39d6bbd7e68..8d1e2e2e940 100644 --- a/htdocs/projet/project.class.php +++ b/htdocs/projet/project.class.php @@ -209,18 +209,18 @@ class Project extends CommonObject /** * \brief Return list of projects - * \param id_societe To filter on a particular third party + * \param socid To filter on a particular third party * \return array Liste of projects */ - function liste_array($id_societe='') + function liste_array($socid='') { - $projets = array(); + global $conf; + + $projects = array(); $sql = "SELECT rowid, title FROM ".MAIN_DB_PREFIX."projet"; - if (! empty($id_societe)) - { - $sql .= " WHERE fk_soc = ".$id_societe; - } + $sql.= " WHERE entity = ".$conf->entity; + if (! empty($socid)) $sql.= " AND fk_soc = ".$socid; $resql=$this->db->query($sql); if ($resql) @@ -234,11 +234,11 @@ class Project extends CommonObject { $obj = $this->db->fetch_object($resql); - $projets[$obj->rowid] = $obj->title; + $projects[$obj->rowid] = $obj->title; $i++; } } - return $projets; + return $projects; } else { @@ -500,55 +500,6 @@ class Project extends CommonObject return $result; } - - /** - * \brief Cree une tache dans le projet - * \param user Id utilisateur qui cree - * \param title titre de la tache - * \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.")"; - - dol_syslog("Project::TaskAddTime sql=".$sql, LOG_DEBUG); - if ($this->db->query($sql) ) - { - $task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task"); - $result = 0; - } - else - { - $this->error=$this->db->lasterror(); - dol_syslog("Project::TaskAddTime error -2 ".$this->error,LOG_ERR); - $result = -2; - } - - if ($result == 0) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task"; - $sql .= " SET duration_effective = duration_effective + '".price2num($time)."'"; - $sql .= " WHERE rowid = '".$task."';"; - - dol_syslog("Project::TaskAddTime sql=".$sql, LOG_DEBUG); - if ($this->db->query($sql) ) - { - $result = 0; - } - else - { - $this->error=$this->db->lasterror(); - dol_syslog("Project::TaskAddTime error -3 ".$this->error, LOG_ERR); - $result = -2; - } - } - - return $result; - } - /** * \brief Return status label of object * \param mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto diff --git a/htdocs/projet/tasks/fiche.php b/htdocs/projet/tasks/fiche.php index fb6c948d436..3829756aa0e 100644 --- a/htdocs/projet/tasks/fiche.php +++ b/htdocs/projet/tasks/fiche.php @@ -98,8 +98,8 @@ if ($_POST["action"] == 'createtask' && $user->rights->projet->creer) if ($_POST["action"] == 'addtime' && $user->rights->projet->creer) { - $project = new Project($db); - $result = $project->fetch($_GET["id"]); + $task = new Task($db); + $result = $task->fetch($_GET["id"]); if ($result == 0) { @@ -116,12 +116,12 @@ if ($_POST["action"] == 'addtime' && $user->rights->projet->creer) $id = str_replace("task","",$key); $date = dol_mktime(12,0,0,$_POST["$id"."month"],$_POST["$id"."day"],$_POST["$id"."year"]); - $project->TaskAddTime($user, $id , $post, $date); + $task->addTimeSpent($user, $post, $date); } } } - Header("Location:fiche.php?id=".$project->id); + Header("Location:fiche.php?id=".$task->id); exit; } } diff --git a/htdocs/projet/tasks/task.class.php b/htdocs/projet/tasks/task.class.php index 3c9c9eecff2..4f30480c8b9 100644 --- a/htdocs/projet/tasks/task.class.php +++ b/htdocs/projet/tasks/task.class.php @@ -509,6 +509,63 @@ class Task extends CommonObject return $tasksrole; } + + /** + * \brief Add time spent + * \param user Id utilisateur qui cree + * \param time Time spent + * \param date date + */ + function addTimeSpent($user, $time, $date) + { + $result = 0; + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time ("; + $sql.= "fk_task"; + $sql.= ", task_date"; + $sql.= ", task_duration"; + $sql.= ", fk_user"; + $sql.= ") VALUES ("; + $sql.= $this->id; + $sql.= ", '".$this->db->idate($date)."'"; + $sql.= ", ".$time; + $sql.= ", ".$user->id; + $sql.= ")"; + + dol_syslog("Project::addTimeSpent sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql) ) + { + $task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task"); + $result = 0; + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog("Project::addTimeSpent error -2 ".$this->error,LOG_ERR); + $result = -2; + } + + if ($result == 0) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task"; + $sql.= " SET duration_effective = duration_effective + '".price2num($time)."'"; + $sql.= " WHERE rowid = ".$this->id; + + dol_syslog("Project::addTimeSpent sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql) ) + { + $result = 0; + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog("Project::addTimeSpent error -3 ".$this->error, LOG_ERR); + $result = -2; + } + } + + return $result; + } } ?> \ No newline at end of file