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,8 +3,8 @@
* Copyright (C) 2005 Davoleau Brice <brice.davoleau@gmail.com>
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006-2007 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2006-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
*
* 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;
}

View File

@ -1,6 +1,6 @@
<?php
/* 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) 2007 Patrick Raguin <patrick.raguin@gmail.com>
*
@ -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 "<br>";
if ($categorie->error)
if ($mesg)
{
print '<div class="error">';
print $categorie->error;
print $mesg;
print '</div>';
}

View File

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