From b7c5268a18d3203ec1f1d2b8679c99881971dbb4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 10 Sep 2008 11:14:45 +0000 Subject: [PATCH] New: Some enhancements in project module --- htdocs/projet/activity/index.php | 19 +- htdocs/projet/activity/myactivity.php | 44 +-- htdocs/projet/tasks/index.php | 191 ++++++------ htdocs/projet/tasks/mytasks.php | 6 +- htdocs/projet/tasks/task.php | 170 +++++------ htdocs/task.class.php | 412 ++++++++++++++++++++++---- 6 files changed, 554 insertions(+), 288 deletions(-) diff --git a/htdocs/projet/activity/index.php b/htdocs/projet/activity/index.php index b5685a92265..ab659ded27f 100644 --- a/htdocs/projet/activity/index.php +++ b/htdocs/projet/activity/index.php @@ -55,8 +55,8 @@ print ''; */ print ''; print ''; -print_liste_field_titre($langs->trans("Project"),"index.php","s.nom","","","",$sortfield,$sortorder); -print ''; +print_liste_field_titre($langs->trans("Project"),$_SERVER["PHP_SELF"],"s.nom","","","",$sortfield,$sortorder); +print ''; print "\n"; $sql = "SELECT p.title, p.rowid, count(t.rowid)"; @@ -82,7 +82,7 @@ if ( $resql ) $var=!$var; print ""; print ''; - print ''; + print ''; print "\n"; $i++; @@ -124,8 +124,8 @@ $dateendy=dolibarr_mktime(23,59,59,12,31,$info["year"]); /* Affichage de la liste des projets du mois */ print '
'.$langs->trans("NbOpenTasks").''.$langs->trans("NbOpenTasks").'
'.$row[0].''.$row[2].''.$row[2].'
'; print ''; -print ''; -print ''; +print ''; +print ''; print "\n"; $sql = "SELECT p.title, p.rowid, sum(tt.task_duration) as total"; @@ -169,8 +169,8 @@ print "
Activité sur les projets cette semaine'.$langs->trans("Hours").''.$langs->trans("ActivityOnProjectThisWeek").''.$langs->trans("Time").'

"; /* Affichage de la liste des projets du mois */ print ''; print ''; -print ''; -print ''; +print ''; +print ''; print "\n"; $sql = "SELECT p.title, p.rowid, sum(tt.task_duration) as total"; @@ -214,8 +214,8 @@ print "
'.$langs->trans("Project").' ce mois : '.strftime("%B %Y", $now).''.$langs->trans("Hours").''.$langs->trans("ActivityOnProjectThisMonth").': '.strftime("%B %Y", $now).''.$langs->trans("Time").'
"; /* Affichage de la liste des projets du mois */ print '
'; print ''; -print ''; -print ''; +print ''; +print ''; print "\n"; $sql = "SELECT p.title, p.rowid, sum(tt.task_duration) as total"; @@ -259,5 +259,6 @@ print "
'.$langs->trans("Project").' cette année : '.strftime("%Y", $now).''.$langs->trans("Hours").''.$langs->trans("ActivityOnProjectThisYear").': '.strftime("%Y", $now).''.$langs->trans("Time").'
"; print ''; $db->close(); + llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/projet/activity/myactivity.php b/htdocs/projet/activity/myactivity.php index 977b8adb15b..01313518105 100644 --- a/htdocs/projet/activity/myactivity.php +++ b/htdocs/projet/activity/myactivity.php @@ -54,8 +54,8 @@ print ''; */ print ''; print ''; -print_liste_field_titre($langs->trans("Project"),"index.php","s.nom","","","",$sortfield,$sortorder); -print ''; +print_liste_field_titre($langs->trans("Project"),$_SERVER["PHP_SELF"],"s.nom","","","",$sortfield,$sortorder); +print ''; print "\n"; $sql = "SELECT p.title, p.rowid, count(t.rowid)"; @@ -85,7 +85,7 @@ if ( $resql ) $var=!$var; print ""; print ''; - print ''; + print ''; print "\n"; $i++; @@ -103,7 +103,7 @@ print "
'.$langs->trans("NbOpenTasks").''.$langs->trans("NbOpenTasks").'
'.$row[0].''.$row[2].''.$row[2].'
"; print '
'; print ''; print ''; -print ''; +print ''; print "\n"; $sql = "SELECT p.title, p.rowid, sum(tt.task_duration)"; @@ -126,7 +126,7 @@ if ( $resql ) $var=!$var; print ""; print ''; - print ''; + print ''; print "\n"; $total += $row[2]; } @@ -139,7 +139,7 @@ else } print ''; print ''; -print ''; +print ''; print "\n"; print "
'.$langs->trans('Today').'Temps'.$langs->trans("Time").'
'.$row[0].''.$row[2].''.$row[2].'
'.$langs->trans('Total').''.$total.''.$total.'
"; @@ -147,7 +147,7 @@ print ""; print '
'; print ''; print ''; -print ''; +print ''; print "\n"; $sql = "SELECT p.title, p.rowid, sum(tt.task_duration)"; @@ -170,7 +170,7 @@ if ( $resql ) $var=!$var; print ""; print ''; - print ''; + print ''; print "\n"; $total += $row[2]; } @@ -183,7 +183,7 @@ else } print ''; print ''; -print ''; +print ''; print "\n"; print "
'.$langs->trans('Yesterday').'Temps'.$langs->trans("Time").'
'.$row[0].''.$row[2].''.$row[2].'
'.$langs->trans('Total').''.$total.''.$total.'
"; @@ -192,8 +192,8 @@ print ''; /* Affichage de la liste des projets de la semaine */ print ''; print ''; -print ''; -print ''; +print ''; +print ''; print "\n"; $sql = "SELECT p.title, p.rowid, sum(tt.task_duration)"; @@ -215,7 +215,7 @@ if ( $resql ) $var=!$var; print ""; print ''; - print ''; + print ''; print "\n"; $total += $row[2]; } @@ -228,15 +228,15 @@ else } print ''; print ''; -print ''; +print ''; print "\n"; print "
Activité sur les projets cette semaineTemps'.$langs->trans("ActivityOnProjectThisWeek").''.$langs->trans("Time").'
'.$row[0].''.$row[2].''.$row[2].'
'.$langs->trans('Total').''.$total.''.$total.'

"; /* Affichage de la liste des projets du mois */ print ''; print ''; -print ''; -print ''; +print ''; +print ''; print "\n"; $sql = "SELECT p.title, p.rowid, sum(tt.task_duration)"; @@ -249,7 +249,7 @@ $sql .= " AND tt.fk_user = ".$user->id; $sql .= " AND month(task_date) = ".strftime("%m",$now); $sql .= " GROUP BY p.rowid"; -$var=true; +$var=false; $resql = $db->query($sql); if ( $resql ) { @@ -257,7 +257,7 @@ if ( $resql ) { print ""; print ''; - print ''; + print ''; print "\n"; $var=!$var; } @@ -272,8 +272,8 @@ print "
'.$langs->trans("Project").' ce mois : '.strftime("%B %Y", $now).'Nb heures'.$langs->trans("ActivityOnProjectThisMonth").': '.strftime("%B %Y", $now).''.$langs->trans("Time").'
'.$row[0].''.$row[2].''.$row[2].'
"; /* Affichage de la liste des projets de l'année */ print '
'; print ''; -print ''; -print ''; +print ''; +print ''; print "\n"; $sql = "SELECT p.title, p.rowid, sum(tt.task_duration)"; @@ -286,7 +286,7 @@ $sql .= " AND tt.fk_user = ".$user->id; $sql .= " AND YEAR(task_date) = ".strftime("%Y",$now); $sql .= " GROUP BY p.rowid"; -$var=true; +$var=false; $resql = $db->query($sql); if ( $resql ) { @@ -294,7 +294,7 @@ if ( $resql ) { print ""; print ''; - print ''; + print ''; print "\n"; $var=!$var; } @@ -310,5 +310,5 @@ print '
'.$langs->trans("Project").' cette année : '.strftime("%Y", $now).'Nb heures'.$langs->trans("ActivityOnProjectThisYear").': '.strftime("%Y", $now).''.$langs->trans("Time").'
'.$row[0].''.$row[2].''.$row[2].'
'; $db->close(); -llxFooter("Dernière modification $Date$ révision $Revision$"); +llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/projet/tasks/index.php b/htdocs/projet/tasks/index.php index dd68d299205..93492e9b7ee 100644 --- a/htdocs/projet/tasks/index.php +++ b/htdocs/projet/tasks/index.php @@ -1,8 +1,7 @@ - * Copyright (C) 2004-2006 Laurent Destailleur - * Copyright (C) 2005-2006 Regis Houssin - * +/* Copyright (C) 2005 Rodolphe Quiedeville + * Copyright (C) 2006-2008 Laurent Destailleur + * * 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 @@ -16,148 +15,126 @@ * 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. - * - * $Id$ - * $Source$ */ /** - \file htdocs/projet/tasks/index.php - \ingroup projet - \brief Page des taches du module projet - \version $Revision$ + \file htdocs/projet/tasks/mytasks.php + \ingroup projet + \brief Fiche tâches d'un projet + \version $Id$ */ require("./pre.inc.php"); if (!$user->rights->projet->lire) accessforbidden(); -// Sécurité accés client -if ($user->societe_id > 0) +$langs->load('projects'); + +Function PLines(&$inc, $parent, $lines, &$level, &$var) { - $action = ''; - $socid = $user->societe_id; + $form = new Form($db); // $db est null ici mais inutile pour la fonction select_date() + global $bc, $langs; + for ($i = 0 ; $i < sizeof($lines) ; $i++) + { + if ($parent == 0) + { + $level = 0; + $var = !$var; + } + + if ($lines[$i][1] == $parent) + { + print "\n"; + print ''.$lines[$i][4]."\n"; + + for ($k = 0 ; $k < $level ; $k++) + { + print "   "; + } + + print ''.$lines[$i][0]."\n"; + + $heure = intval($lines[$i][3]); + $minutes = (($lines[$i][3] - $heure) * 60); + $minutes = substr("00"."$minutes", -2); + + print ''.$heure." h ".$minutes."\n"; + print "\n"; + $inc++; + $level++; + PLines($inc, $lines[$i][2], $lines, $level, $var); + $level--; + } + else + { + //$level--; + } + } } -llxHeader("",$langs->trans("Projects"),"Projet"); - -print_fiche_titre($langs->trans("ProjectsArea")); - - -print ''; -print '
'; +llxHeader("",$langs->trans("Mytasks"),"Projet"); /* + * Fiche projet en mode visu * - * Affichage de la liste des projets - * */ -print ''; -print ''; -print_liste_field_titre($langs->trans("Project"),"index.php","s.nom","","","",$sortfield,$sortorder); -print ''; -print "\n"; -$sql = "SELECT p.title, p.rowid, count(t.rowid)"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user"; -$sql .= " FROM ".MAIN_DB_PREFIX."projet as p"; -$sql .= " , ".MAIN_DB_PREFIX."projet_task as t"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; -$sql .= " WHERE t.fk_projet = p.rowid"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; +$h=0; +$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/index.php'; +$head[$h][1] = $langs->trans("Tasks"); +$h++; -if ($socid) -{ - $sql .= " AND s.rowid = ".$socid; -} -$sql .= " GROUP BY p.rowid"; +dolibarr_fiche_head($head, $hselected, $langs->trans("Tasks")); + +/* Liste des tâches */ + +$sql = "SELECT t.rowid, t.title, t.fk_task_parent, t.duration_effective"; +$sql .= " , p.rowid as prowid, p.title as ptitle"; +$sql .= " FROM ".MAIN_DB_PREFIX."projet_task as t"; +$sql .= " , ".MAIN_DB_PREFIX."projet_task_actors as a"; +$sql .= " , ".MAIN_DB_PREFIX."projet as p"; +$sql .= " WHERE p.rowid = t.fk_projet"; +$sql .= " AND a.fk_projet_task = t.rowid"; +$sql .= " ORDER BY p.rowid, t.fk_task_parent"; -$var=true; $resql = $db->query($sql); -if ( $resql ) +if ($resql) { $num = $db->num_rows($resql); $i = 0; - + $tasks = array(); while ($i < $num) { - $row = $db->fetch_row( $resql); - $var=!$var; - print ""; - print ''; - print ''; - print "\n"; - + $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; + $tasks[$i][4] = $obj->ptitle; + $tasks[$i][5] = $obj->prowid; $i++; } - - $db->free($resql); + $db->free(); } else { dolibarr_print_error($db); } -print "
'.$langs->trans("NbOpenTasks").'
'.$row[0].''.$row[2].'
"; -print '
'; - -/* - * - * Affichage de la liste des projets - * - */ print ''; print ''; -print_liste_field_titre($langs->trans("Company"),"index.php","s.nom","","","",$sortfield,$sortorder); -print ''; -print "\n"; - -$sql = "SELECT p.title, p.rowid, sum(tt.task_duration)"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user"; -$sql .= " FROM ".MAIN_DB_PREFIX."projet as p"; -$sql .= " , ".MAIN_DB_PREFIX."projet_task as t"; -$sql .= " , ".MAIN_DB_PREFIX."projet_task_time as tt"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; -$sql .= " WHERE t.fk_projet = p.rowid"; -$sql .= " AND tt.fk_task = t.rowid"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; - -if ($socid) -{ - $sql .= " AND s.rowid = ".$socid; -} -$sql .= " GROUP BY p.rowid"; - +print ''; +print ''; +print ''; +print "\n"; $var=true; -$resql = $db->query($sql); -if ( $resql ) -{ - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $row = $db->fetch_row( $resql); - $var=!$var; - print ""; - print ''; - print ''; - print "\n"; - - $i++; - } - - $db->free($resql); -} -else -{ - dolibarr_print_error($db); -} -print "
Nb heures
'.$langs->trans("Project").''.$langs->trans("Task").''.$langs->trans("DurationEffective").'
'.$row[0].''.$row[2].'
"; +PLines($j, 0, $tasks, $level, $var); -print '
'; +print ""; +print ''; $db->close(); -llxFooter("Dernière modification $Date$ révision $Revision$"); +llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/projet/tasks/mytasks.php b/htdocs/projet/tasks/mytasks.php index cf4e5befc4b..3e491cc2f40 100644 --- a/htdocs/projet/tasks/mytasks.php +++ b/htdocs/projet/tasks/mytasks.php @@ -1,5 +1,6 @@ + * Copyright (C) 2006-2008 Laurent Destailleur * * 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 @@ -14,16 +15,13 @@ * 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. - * - * $Id$ - * $Source$ */ /** \file htdocs/projet/tasks/mytasks.php \ingroup projet \brief Fiche tâches d'un projet - \version $Revision$ + \version $Id$ */ require("./pre.inc.php"); diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index cd0b14f0abd..28656b32afb 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -1,7 +1,7 @@ - * Copyright (C) 2006 Laurent Destailleur - * +/* Copyright (C) 2005 Rodolphe Quiedeville + * Copyright (C) 2006-2008 Laurent Destailleur + * * 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 @@ -18,11 +18,11 @@ */ /** - \file htdocs/projet/tasks/task.php - \ingroup projet - \brief Fiche tâches d'un projet - \version $Id$ -*/ + \file htdocs/projet/tasks/task.php + \ingroup projet + \brief Fiche tâches d'un projet + \version $Id$ + */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php"); @@ -37,90 +37,92 @@ llxHeader("",$langs->trans("Task")); if ($_GET["id"] > 0) { - - /* - * Fiche projet en mode visu - * - */ - $task = new Task($db); - if ($task->fetch($_GET["id"]) == 0 ) - { - $projet = new Project($db); - $projet->fetch($task->projet_id); - $projet->societe->fetch($projet->societe->id); - - $h=0; - $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$task->id; - $head[$h][1] = $langs->trans("Tasks"); - $head[$h][2] = 'tasks'; - $h++; - - dolibarr_fiche_head($head, 'tasks', $langs->trans("Tasks")); - - print '
'; - print ''; - print ''; - - print ''; - print ''; - - print ''; - print ''; - - /* Liste des tâches */ - - $sql = "SELECT t.task_date, t.task_duration, t.fk_user, u.login"; - $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t"; - $sql .= " , ".MAIN_DB_PREFIX."user as u"; - $sql .= " WHERE t.fk_task =".$task->id; - $sql .= " AND t.fk_user = u.rowid"; - $sql .= " ORDER BY t.task_date DESC"; - - $var=true; - $resql = $db->query($sql); - if ($resql) + /* + * Fiche projet en mode visu + * + */ + $task = new Task($db); + if ($task->fetch($_GET["id"]) >= 0 ) { - $num = $db->num_rows($resql); - $i = 0; - $tasks = array(); - while ($i < $num) - { - $row = $db->fetch_row($resql); - $tasks[$i] = $row; - $i++; - } - $db->free(); - } - else - { - dolibarr_print_error($db); - } - - - /* Nouvelle tâche */ - print '
'.$langs->trans("Ref").''.$projet->ref.'
'.$langs->trans("Label").''.$projet->title.'
'.$langs->trans("Company").''.$projet->societe->getNomUrl(1).'
'.$langs->trans("Task").''.$task->title.'

'; + $projet = new Project($db); + $result=$projet->fetch($task->fk_projet); + if (! empty($projet->socid)) + { + $projet->societe->fetch($projet->socid); + } - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - foreach ($tasks as $task_time) - { - $var=!$var; + $h=0; + $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$task->id; + $head[$h][1] = $langs->trans("Tasks"); + $head[$h][2] = 'tasks'; + $h++; + + dolibarr_fiche_head($head, 'tasks', $langs->trans("Tasks")); + + print ''; + print ''; + print '
'.$langs->trans("Date").''.$langs->trans("DurationEffective").''.$langs->trans("User").'
'; + + print ''; + print ''; + + print ''; + print ''; + + /* Liste des tâches */ + + $sql = "SELECT t.task_date, t.task_duration, t.fk_user, u.login"; + $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t"; + $sql .= " , ".MAIN_DB_PREFIX."user as u"; + $sql .= " WHERE t.fk_task =".$task->id; + $sql .= " AND t.fk_user = u.rowid"; + $sql .= " ORDER BY t.task_date DESC"; + + $var=true; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + $tasks = array(); + while ($i < $num) + { + $row = $db->fetch_row($resql); + $tasks[$i] = $row; + $i++; + } + $db->free(); + } + else + { + dolibarr_print_error($db); + } + + + /* Nouvelle tâche */ + print '
'.$langs->trans("Ref").''.$projet->ref.'
'.$langs->trans("Label").''.$projet->title.'
'.$langs->trans("Company").''.$projet->societe->getNomUrl(1).'
'.$langs->trans("Task").''.$task->title.'

'; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + foreach ($tasks as $task_time) + { + $var=!$var; print ""; print ''; print ''; print ''; print "\n"; + } + + print "
'.$langs->trans("Date").''.$langs->trans("DurationEffective").''.$langs->trans("User").'
'.dolibarr_print_date($task_time[0]).''.$task_time[1].''.$task_time[3].'
"; + print ''; } - - print ""; - print ''; - } } $db->close(); diff --git a/htdocs/task.class.php b/htdocs/task.class.php index 47f40a8272b..bbef879017c 100644 --- a/htdocs/task.class.php +++ b/htdocs/task.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2008 Laurent Destailleur * * 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 @@ -14,75 +14,363 @@ * 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. - * - * $Id$ - * $Source$ - * */ /** - \file htdocs/task.class.php - \ingroup projet - \brief Fichier de la classe de gestion des taches - \version $Revision$ + \file task.class.php + \ingroup project + \brief This file is a CRUD class file for Taks (Create/Read/Update/Delete) + \version $Id$ + \remarks Initialy built by build_class_from_table on 2008-09-10 12:41 */ +// Put here all includes required by your class file +//require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php"); +//require_once(DOL_DOCUMENT_ROOT."/societe.class.php"); +//require_once(DOL_DOCUMENT_ROOT."/product.class.php"); + + /** - \class Task - \brief Classe permettant la gestion des taches + \class Projet_task + \brief Put here description of your class + \remarks Initialy built by build_class_from_table on 2008-09-10 12:41 */ - -class Task { - var $id; - var $db; - - /** - * \brief Constructeur de la classe - * \param DB handler accès base de données - */ - function Task($DB) - { - $this->db = $DB; - } - - /* - * \brief Charge objet projet depuis la base - * \param rowid id du projet à charger - */ - - function fetch($rowid) - { +class Task // extends CommonObject +{ + var $db; //!< To store db handler + var $error; //!< To return error code (or message) + var $errors=array(); //!< To return several error codes (or messages) + //var $element='projet_task'; //!< Id that identify managed objects + //var $table_element='projet_task'; //!< Name of table without prefix where object is stored - $sql = "SELECT title, fk_projet, duration_effective, statut"; - $sql .= " FROM ".MAIN_DB_PREFIX."projet_task"; - $sql .= " WHERE rowid=".$rowid; + var $id; - $resql = $this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { - $obj = $this->db->fetch_object($resql); - - $this->id = $rowid; - $this->title = $obj->title; - $this->statut = $obj->statut; - $this->projet_id = $obj->fk_projet; - - $this->db->free($resql); + var $fk_projet; + var $fk_task_parent; + var $title; + var $duration_effective; + var $fk_user_creat; + var $statut; + var $note; + + + + + /** + * \brief Constructor + * \param DB Database handler + */ + function Task($DB) + { + $this->db = $DB; + return 1; + } + + + /** + * \brief Create in database + * \param user User that create + * \param notrigger 0=launch triggers after, 1=disable triggers + * \return int <0 if KO, Id of created object if OK + */ + function create($user, $notrigger=0) + { + global $conf, $langs; + $error=0; + + // Clean parameters + + if (isset($this->fk_projet)) $this->fk_projet=trim($this->fk_projet); + if (isset($this->fk_task_parent)) $this->fk_task_parent=trim($this->fk_task_parent); + if (isset($this->title)) $this->title=trim($this->title); + if (isset($this->duration_effective)) $this->duration_effective=trim($this->duration_effective); + if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); + if (isset($this->statut)) $this->statut=trim($this->statut); + if (isset($this->note)) $this->note=trim($this->note); + + + + // Check parameters + // Put here code to add control on parameters values + + // Insert request + $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task("; + + $sql.= "fk_projet,"; + $sql.= "fk_task_parent,"; + $sql.= "title,"; + $sql.= "duration_effective,"; + $sql.= "fk_user_creat,"; + $sql.= "statut,"; + $sql.= "note"; + + + $sql.= ") VALUES ("; + + $sql.= " ".(! isset($this->fk_projet)?'NULL':"'".$this->fk_projet."'").","; + $sql.= " ".(! isset($this->fk_task_parent)?'NULL':"'".$this->fk_task_parent."'").","; + $sql.= " ".(! isset($this->title)?'NULL':"'".$this->title."'").","; + $sql.= " ".(! isset($this->duration_effective)?'NULL':"'".$this->duration_effective."'").","; + $sql.= " ".(! isset($this->fk_user_creat)?'NULL':"'".$this->fk_user_creat."'").","; + $sql.= " ".(! isset($this->statut)?'NULL':"'".$this->statut."'").","; + $sql.= " ".(! isset($this->note)?'NULL':"'".$this->note."'").""; + + + $sql.= ")"; + + $this->db->begin(); + + dolibarr_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task"); + + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. + + //// Call triggers + //include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dolibarr_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return $this->id; + } + } + + + /** + * \brief Load object in memory from database + * \param id id object + * \return int <0 if KO, >0 if OK + */ + function fetch($id) + { + global $langs; + $sql = "SELECT"; + $sql.= " t.rowid,"; + + $sql.= " t.fk_projet,"; + $sql.= " t.fk_task_parent,"; + $sql.= " t.title,"; + $sql.= " t.duration_effective,"; + $sql.= " t.fk_user_creat,"; + $sql.= " t.statut,"; + $sql.= " t.note"; + + + $sql.= " FROM ".MAIN_DB_PREFIX."projet_task as t"; + $sql.= " WHERE t.rowid = ".$id; + + dolibarr_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + + $this->fk_projet = $obj->fk_projet; + $this->fk_task_parent = $obj->fk_task_parent; + $this->title = $obj->title; + $this->duration_effective = $obj->duration_effective; + $this->fk_user_creat = $obj->fk_user_creat; + $this->statut = $obj->statut; + $this->note = $obj->note; + + + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dolibarr_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); + return -1; + } + } + + + /** + * \brief Update database + * \param user User that modify + * \param notrigger 0=launch triggers after, 1=disable triggers + * \return int <0 if KO, >0 if OK + */ + function update($user=0, $notrigger=0) + { + global $conf, $langs; + $error=0; + + // Clean parameters + + if (isset($this->fk_projet)) $this->fk_projet=trim($this->fk_projet); + if (isset($this->fk_task_parent)) $this->fk_task_parent=trim($this->fk_task_parent); + if (isset($this->title)) $this->title=trim($this->title); + if (isset($this->duration_effective)) $this->duration_effective=trim($this->duration_effective); + if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); + if (isset($this->statut)) $this->statut=trim($this->statut); + if (isset($this->note)) $this->note=trim($this->note); + + + + // Check parameters + // Put here code to add control on parameters values + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET"; + + $sql.= " fk_projet=".(isset($this->fk_projet)?$this->fk_projet:"null").","; + $sql.= " fk_task_parent=".(isset($this->fk_task_parent)?$this->fk_task_parent:"null").","; + $sql.= " title=".(isset($this->title)?"'".addslashes($this->title)."'":"null").","; + $sql.= " duration_effective=".(isset($this->duration_effective)?$this->duration_effective:"null").","; + $sql.= " fk_user_creat=".(isset($this->fk_user_creat)?$this->fk_user_creat:"null").","; + $sql.= " statut=".(isset($this->statut)?$this->statut:"null").","; + $sql.= " note=".(isset($this->note)?"'".addslashes($this->note)."'":"null").""; + + + $sql.= " WHERE rowid=".$this->id; + + $this->db->begin(); + + dolibarr_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. + + //// Call triggers + //include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dolibarr_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + /** + * \brief Delete object in database + * \param user User that delete + * \param notrigger 0=launch triggers after, 1=disable triggers + * \return int <0 if KO, >0 if OK + */ + function delete($user, $notrigger=0) + { + global $conf, $langs; + $error=0; + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task"; + $sql.= " WHERE rowid=".$this->id; + + $this->db->begin(); + + dolibarr_syslog(get_class($this)."::delete sql=".$sql); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. + + //// Call triggers + //include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dolibarr_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + /** + * \brief Initialise object with example values + * \remarks id must be 0 if object instance is a specimen. + */ + function initAsSpecimen() + { + $this->id=0; + + $this->fk_projet=''; + $this->fk_task_parent=''; + $this->title=''; + $this->duration_effective=''; + $this->fk_user_creat=''; + $this->statut=''; + $this->note=''; + + + } - return 0; - } - else - { - return -1; - } - } - else - { - print $this->db->error(); - return -2; - } - } } -?> +?> \ No newline at end of file