diff --git a/htdocs/categories/categorie.class.php b/htdocs/categories/categorie.class.php index 64b36a8cc3b..713f3ba4677 100644 --- a/htdocs/categories/categorie.class.php +++ b/htdocs/categories/categorie.class.php @@ -3,8 +3,8 @@ * Copyright (C) 2005 Davoleau Brice * Copyright (C) 2005 Rodolphe Quiedeville * Copyright (C) 2006-2007 Regis Houssin - * Copyright (C) 2006 Laurent Destailleur - * Copyright (C) 2007 Patrick Raguin + * Copyright (C) 2006-2007 Laurent Destailleur + * Copyright (C) 2007 Patrick Raguin * * 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 @@ -21,18 +21,29 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ - * $Source$ */ +/** + \file htdocs/categories/categorie.class.php + \ingroup categorie + \brief Fichier de la classe des categorie +*/ + require_once(DOL_DOCUMENT_ROOT."/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/fourn/fournisseur.class.php"); +/** + \class Categorie + \brief Classe permettant la gestion des categories +*/ class Categorie { + var $error; var $db; var $id; + var $id_mere; var $label; var $description; var $statut; @@ -41,8 +52,6 @@ class Categorie var $cats=array(); // Tableau en memoire des categories var $motherof = array(); // Tableau des correspondances id_fille -> id_mere - var $error; - /** * Constructeur @@ -64,19 +73,20 @@ class Categorie function fetch($id) { $sql = "SELECT rowid, label, description, visible, type"; - $sql.= " FROM ".MAIN_DB_PREFIX."categorie WHERE rowid = ".$id; + $sql.= " FROM ".MAIN_DB_PREFIX."categorie"; + $sql.= " WHERE rowid = ".$id; + dolibarr_syslog("Categorie::fetch sql=".$sql); $resql = $this->db->query ($sql); - if ($resql) { $res = $this->db->fetch_array($resql); - $this->id = $res['rowid']; - $this->label = $res['label']; - $this->description = stripslashes($res['description']); + $this->id = $res['rowid']; + $this->label = $res['label']; + $this->description = $res['description']; $this->visible = $res['visible']; - $this->type = $res['type']; + $this->type = $res['type']; $this->db->free($resql); } @@ -85,15 +95,18 @@ class Categorie dolibarr_print_error ($this->db); return -1; } + $sql = "SELECT fk_categorie_mere"; - $sql.= " FROM ".MAIN_DB_PREFIX."categorie_association WHERE fk_categorie_fille = '".$id."'"; + $sql.= " FROM ".MAIN_DB_PREFIX."categorie_association"; + $sql.= " WHERE fk_categorie_fille = '".$id."'"; + dolibarr_syslog("Categorie::fetch sql=".$sql); $resql = $this->db->query ($sql); - if ($resql) { $res = $this->db->fetch_array($resql); $this->id_mere = $res['fk_categorie_mere']; + return $this->id; } else { @@ -162,45 +175,56 @@ class Categorie */ function update() { + // Clean parameters + $this->label=trim($this->label); + $this->description=trim($this->description); + + + $this->db->begin(); $sql = 'delete from '.MAIN_DB_PREFIX.'categorie_association'; $sql .= ' WHERE fk_categorie_fille = "'.$this->id.'"'; + dolibarr_syslog("Categorie::update sql=".$sql); if (! $this->db->query($sql)) { + $this->db->rollback(); dolibarr_print_error($this->db); return -1; } - if($this->id_mere !="" && $this->id_mere!=$this->id) { - $sql = 'insert into '.MAIN_DB_PREFIX.'categorie_association(fk_categorie_mere,fk_categorie_fille)'; $sql .= ' VALUES ("'.$this->id_mere.'","'.$this->id.'")'; + + dolibarr_syslog("Categorie::update sql=".$sql); if (! $this->db->query($sql)) { + $this->db->rollback(); dolibarr_print_error($this->db); return -1; } } + $sql = "UPDATE ".MAIN_DB_PREFIX."categorie"; - $sql.= " SET label = '".trim(addslashes($this->label))."'"; - - if (strlen (trim($this->description)) > 0) + $sql.= " SET label = '".addslashes($this->label)."'"; + if ($this->description) { - $sql .= ", description = '".trim(addslashes($this->description))."'"; + $sql .= ", description = '".addslashes($this->description)."'"; } - $sql .= ", visible = '".$this->visible."'"; $sql .= " WHERE rowid = ".$this->id; + dolibarr_syslog("Categorie::update sql=".$sql); if ($this->db->query($sql)) { + $this->db->commit(); return 1; } else { + $this->db->rollback(); dolibarr_print_error($this->db); return -1; } diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index 1e7973a52ad..a9bec31337e 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -1,6 +1,6 @@ - * Copyright (C) 2006 Laurent Destailleur + * Copyright (C) 2006-2007 Laurent Destailleur * Copyright (C) 2005-2006 Regis Houssin * Copyright (C) 2007 Patrick Raguin * @@ -17,6 +17,8 @@ * 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$ */ /** @@ -36,29 +38,44 @@ if (!$user->rights->categorie->lire) // Action mise à jour d'une catégorie if ($_POST["action"] == 'update' && $user->rights->categorie->creer) { - $categorie = new Categorie ($db, $_REQUEST['id']); - + $categorie = new Categorie ($db); + $result=$categorie->fetch($_REQUEST['id']); + $categorie->label = $_POST["nom"]; $categorie->description = $_POST["description"]; $categorie->visible = $_POST["visible"]; + if($_POST['catMere'] != "-1") $categorie->id_mere = $_POST['catMere']; else $categorie->id_mere = ""; - if (!$categorie->label || !$categorie->description) + if (! $categorie->label) { $_GET["action"] = 'create'; - $categorie->error = "Le libellé ou la description n'a pas été renseigné"; + $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")); + } + if (! $categorie->description) + { + $_GET["action"] = 'create'; + $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Description")); } if (! $categorie->error) { - if ($categorie->update() > 0) + if ($categorie->update($user) > 0) { header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id); exit; } + else + { + $mesg=$categorie->error; + } + } + else + { + $mesg=$categorie->error; } } @@ -73,10 +90,10 @@ llxHeader("","",$langs->trans("Categories")); print_titre($langs->trans("ModifCat")); print "
"; -if ($categorie->error) +if ($mesg) { print '
'; - print $categorie->error; + print $mesg; print '
'; } diff --git a/htdocs/categories/fiche.php b/htdocs/categories/fiche.php index 57a840d9427..a0df9430c78 100644 --- a/htdocs/categories/fiche.php +++ b/htdocs/categories/fiche.php @@ -19,7 +19,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ - * $Source$ */ /**