From a691947a84855cbdd8025e7aa5126a40cdfc8853 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Aug 2005 01:38:12 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20Meilleur=20gestion=20erreur=20sur=20cr?= =?UTF-8?q?=E9ation=20projet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/project.class.php | 104 ++++++++++++++++++++------------------- htdocs/projet/fiche.php | 25 +++++++--- 2 files changed, 70 insertions(+), 59 deletions(-) diff --git a/htdocs/project.class.php b/htdocs/project.class.php index 9d4bb331720..808faf6fa5f 100644 --- a/htdocs/project.class.php +++ b/htdocs/project.class.php @@ -21,66 +21,68 @@ * */ -/*! - \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$ */ -/*! +/** \class Project \brief Classe permettant la gestion des projets */ class Project { - var $id; - var $db; - var $ref; - var $title; - var $socidp; - - /** - * \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); - } + var $id; + var $db; + var $ref; + var $title; + var $socidp; + + /** + * \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 - */ + /* + * \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 ('$this->ref', '$this->title', $this->socidp, ".$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 create($user) - { - if (strlen(trim($this->ref)) > 0) - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref, title, fk_soc, fk_user_creat, dateo) "; - $sql .= " VALUES ('$this->ref', '$this->title', $this->socidp, ".$user->id.",now()) ;"; - - if ($this->db->query($sql) ) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet"); - $result = 0; - } - else - { - dolibarr_syslog($this->db->error()); - $result = -2; - } - } - else - { - dolibarr_syslog("Project::Create ref null"); - $result = -1; - } - - return $result; - } function update($user) { diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php index 9de9b486fef..ff2adf0b983 100644 --- a/htdocs/projet/fiche.php +++ b/htdocs/projet/fiche.php @@ -38,15 +38,21 @@ if (!$user->rights->projet->lire) accessforbidden(); if ($_POST["action"] == 'add' && $user->rights->projet->creer) { - $pro = new Project($db); - $pro->socidp = $_GET["socidp"]; - $pro->ref = $_POST["ref"]; - $pro->title = $_POST["title"]; - $result = $pro->create($user); - - if ($result == 0) + $pro = new Project($db); + $pro->socidp = $_GET["socidp"]; + $pro->ref = $_POST["ref"]; + $pro->title = $_POST["title"]; + $result = $pro->create($user); + + if ($result > 0) { - Header("Location:fiche.php?id=".$pro->id); + Header("Location:fiche.php?id=".$pro->id); + exit; + } + else + { + $mesg='
'.$pro->error.'
'; + $_GET["action"] = 'create'; } } @@ -86,6 +92,7 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user- } } + llxHeader("",$langs->trans("Project"),"Projet"); @@ -93,6 +100,8 @@ if ($_GET["action"] == 'create' && $user->rights->projet->creer) { print_titre($langs->trans("NewProject")); + if ($mesg) print $mesg; + print '
'; print '';