Fix: Correction divers edition categorie

This commit is contained in:
Laurent Destailleur 2007-11-12 21:03:22 +00:00
parent 7a94fb2255
commit 947f034a3b
3 changed files with 69 additions and 29 deletions

View File

@ -3,7 +3,7 @@
* Copyright (C) 2005 Davoleau Brice <brice.davoleau@gmail.com> * Copyright (C) 2005 Davoleau Brice <brice.davoleau@gmail.com>
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> * Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006-2007 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2006-2007 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2006-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com> * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -21,18 +21,29 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* *
* $Id$ * $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."/product.class.php");
require_once(DOL_DOCUMENT_ROOT."/fourn/fournisseur.class.php"); require_once(DOL_DOCUMENT_ROOT."/fourn/fournisseur.class.php");
/**
\class Categorie
\brief Classe permettant la gestion des categories
*/
class Categorie class Categorie
{ {
var $error;
var $db; var $db;
var $id; var $id;
var $id_mere;
var $label; var $label;
var $description; var $description;
var $statut; var $statut;
@ -41,8 +52,6 @@ class Categorie
var $cats=array(); // Tableau en memoire des categories var $cats=array(); // Tableau en memoire des categories
var $motherof = array(); // Tableau des correspondances id_fille -> id_mere var $motherof = array(); // Tableau des correspondances id_fille -> id_mere
var $error;
/** /**
* Constructeur * Constructeur
@ -64,17 +73,18 @@ class Categorie
function fetch($id) function fetch($id)
{ {
$sql = "SELECT rowid, label, description, visible, type"; $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); $resql = $this->db->query ($sql);
if ($resql) if ($resql)
{ {
$res = $this->db->fetch_array($resql); $res = $this->db->fetch_array($resql);
$this->id = $res['rowid']; $this->id = $res['rowid'];
$this->label = $res['label']; $this->label = $res['label'];
$this->description = stripslashes($res['description']); $this->description = $res['description'];
$this->visible = $res['visible']; $this->visible = $res['visible'];
$this->type = $res['type']; $this->type = $res['type'];
@ -85,15 +95,18 @@ class Categorie
dolibarr_print_error ($this->db); dolibarr_print_error ($this->db);
return -1; return -1;
} }
$sql = "SELECT fk_categorie_mere"; $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); $resql = $this->db->query ($sql);
if ($resql) if ($resql)
{ {
$res = $this->db->fetch_array($resql); $res = $this->db->fetch_array($resql);
$this->id_mere = $res['fk_categorie_mere']; $this->id_mere = $res['fk_categorie_mere'];
return $this->id;
} }
else else
{ {
@ -162,45 +175,56 @@ class Categorie
*/ */
function update() 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 = 'delete from '.MAIN_DB_PREFIX.'categorie_association';
$sql .= ' WHERE fk_categorie_fille = "'.$this->id.'"'; $sql .= ' WHERE fk_categorie_fille = "'.$this->id.'"';
dolibarr_syslog("Categorie::update sql=".$sql);
if (! $this->db->query($sql)) if (! $this->db->query($sql))
{ {
$this->db->rollback();
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
return -1; return -1;
} }
if($this->id_mere !="" && $this->id_mere!=$this->id) if($this->id_mere !="" && $this->id_mere!=$this->id)
{ {
$sql = 'insert into '.MAIN_DB_PREFIX.'categorie_association(fk_categorie_mere,fk_categorie_fille)'; $sql = 'insert into '.MAIN_DB_PREFIX.'categorie_association(fk_categorie_mere,fk_categorie_fille)';
$sql .= ' VALUES ("'.$this->id_mere.'","'.$this->id.'")'; $sql .= ' VALUES ("'.$this->id_mere.'","'.$this->id.'")';
dolibarr_syslog("Categorie::update sql=".$sql);
if (! $this->db->query($sql)) if (! $this->db->query($sql))
{ {
$this->db->rollback();
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
return -1; return -1;
} }
} }
$sql = "UPDATE ".MAIN_DB_PREFIX."categorie"; $sql = "UPDATE ".MAIN_DB_PREFIX."categorie";
$sql.= " SET label = '".trim(addslashes($this->label))."'"; $sql.= " SET label = '".addslashes($this->label)."'";
if ($this->description)
if (strlen (trim($this->description)) > 0)
{ {
$sql .= ", description = '".trim(addslashes($this->description))."'"; $sql .= ", description = '".addslashes($this->description)."'";
} }
$sql .= ", visible = '".$this->visible."'"; $sql .= ", visible = '".$this->visible."'";
$sql .= " WHERE rowid = ".$this->id; $sql .= " WHERE rowid = ".$this->id;
dolibarr_syslog("Categorie::update sql=".$sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
$this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->db->rollback();
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
return -1; return -1;
} }

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org> /* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2006-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2006 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2006 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com> * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* *
@ -17,6 +17,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 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 // Action mise à jour d'une catégorie
if ($_POST["action"] == 'update' && $user->rights->categorie->creer) 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->label = $_POST["nom"];
$categorie->description = $_POST["description"]; $categorie->description = $_POST["description"];
$categorie->visible = $_POST["visible"]; $categorie->visible = $_POST["visible"];
if($_POST['catMere'] != "-1") if($_POST['catMere'] != "-1")
$categorie->id_mere = $_POST['catMere']; $categorie->id_mere = $_POST['catMere'];
else else
$categorie->id_mere = ""; $categorie->id_mere = "";
if (!$categorie->label || !$categorie->description) if (! $categorie->label)
{ {
$_GET["action"] = 'create'; $_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->error)
{ {
if ($categorie->update() > 0) if ($categorie->update($user) > 0)
{ {
header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id); header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id);
exit; exit;
} }
else
{
$mesg=$categorie->error;
}
}
else
{
$mesg=$categorie->error;
} }
} }
@ -73,10 +90,10 @@ llxHeader("","",$langs->trans("Categories"));
print_titre($langs->trans("ModifCat")); print_titre($langs->trans("ModifCat"));
print "<br>"; print "<br>";
if ($categorie->error) if ($mesg)
{ {
print '<div class="error">'; print '<div class="error">';
print $categorie->error; print $mesg;
print '</div>'; print '</div>';
} }

View File

@ -19,7 +19,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* *
* $Id$ * $Id$
* $Source$
*/ */
/** /**