Fix: Error management in categories creation

This commit is contained in:
Laurent Destailleur 2009-08-28 16:37:45 +00:00
parent 0b12c2de44
commit 8371684535
5 changed files with 25 additions and 25 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 53 KiB

View File

@ -700,26 +700,21 @@ class Categorie
} }
/** /**
* Check if no category with same label already exists * \brief Check if no category with same label already exists
* \return boolean 1 if already exist, 0 otherwise, -1 if error
*/ */
function already_exists() function already_exists()
{ {
$sql = "SELECT count(c.rowid)"; $sql = "SELECT count(c.rowid)";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_association as ca"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_association as ca";
$sql.= " WHERE c.label = '".addslashes($this -> label)."' AND type=".$this->type; $sql.= " WHERE c.label = '".addslashes($this -> label)."' AND type=".$this->type;
/*if($this -> id_mere != "")
{
$sql.= " AND c.rowid = ca.fk_categorie_fille";
$sql.= " AND ca.fk_categorie_mere = '".$this -> id_mere."'";
}
*/
dol_syslog("Categorie::already_exists sql=".$sql); dol_syslog("Categorie::already_exists sql=".$sql);
$res = $this->db->query($sql); $res = $this->db->query($sql);
if ($res) if ($res)
{ {
$obj = $this->db->fetch_array($res); $obj = $this->db->fetch_array($res);
if($obj[0] > 0) return true; if($obj[0] > 0) return 1;
else return false; else return 0;
} }
else else
{ {

View File

@ -1,8 +1,8 @@
<?php <?php
/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org> /* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2006-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2008 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2008 Regis Houssin <regis@dolibarr.fr>
* 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
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,11 +20,11 @@
*/ */
/** /**
\file htdocs/categories/fiche.php * \file htdocs/categories/fiche.php
\ingroup category * \ingroup category
\brief Page creation nouvelle categorie * \brief Page to create a new category
\version $Id$ * \version $Id$
*/ */
require "./pre.inc.php"; require "./pre.inc.php";
require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.php"); require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.php");
@ -128,7 +128,8 @@ if ($_POST["action"] == 'add' && $user->rights->categorie->creer)
$_GET["action"] = 'create'; $_GET["action"] = 'create';
} }
if ($categorie->error =="") // Create category in database
if (! $categorie->error)
{ {
$result = $categorie->create(); $result = $categorie->create();
if ($result > 0) if ($result > 0)
@ -171,6 +172,9 @@ if ($_POST["action"] == 'add' && $user->rights->categorie->creer)
} }
/*
* View
*/
llxHeader("","",$langs->trans("Categories")); llxHeader("","",$langs->trans("Categories"));
$html = new Form($db); $html = new Form($db);
@ -182,12 +186,6 @@ if ($user->rights->categorie->creer)
*/ */
if ($_GET["action"] == 'create' || $_POST["addcat"] == 'addcat') if ($_GET["action"] == 'create' || $_POST["addcat"] == 'addcat')
{ {
if($categorie->error != "")
{
print '<div class="error">';
print $categorie->error;
print '</div>';
}
print '<form action="'.$_SERVER['PHP_SELF'].'?type='.$_GET['type'].'" method="post">'; print '<form action="'.$_SERVER['PHP_SELF'].'?type='.$_GET['type'].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
@ -207,6 +205,13 @@ if ($user->rights->categorie->creer)
print_fiche_titre($langs->trans("CreateCat")); print_fiche_titre($langs->trans("CreateCat"));
if ($categorie->error)
{
print '<div class="error">';
print $categorie->error;
print '</div>';
}
print '<table width="100%" class="border">'; print '<table width="100%" class="border">';
print '<tr>'; print '<tr>';
print '<td width="25%">'.$langs->trans("Ref").'</td><td><input name="nom" size="25" value="'.$categorie->label.'">'; print '<td width="25%">'.$langs->trans("Ref").'</td><td><input name="nom" size="25" value="'.$categorie->label.'">';

View File

@ -53,7 +53,7 @@ SupplierHasNoCategory=This supplier is not in any categories
CompanyHasNoCategory=This company is not in any categories CompanyHasNoCategory=This company is not in any categories
ClassifyInCategory=Classify in category ClassifyInCategory=Classify in category
NoneCategory=None NoneCategory=None
CategoryExistsAtSameLevel=This category already exists at same place CategoryExistsAtSameLevel=This category already exists with this ref
ReturnInProduct=Back to product/service card ReturnInProduct=Back to product/service card
ReturnInSupplier=Back to supplier card ReturnInSupplier=Back to supplier card
ReturnInCompany=Back to customer/prospect card ReturnInCompany=Back to customer/prospect card

View File

@ -53,7 +53,7 @@ SupplierHasNoCategory=Ce fournisseur n'est dans aucune catégorie en particulier
CompanyHasNoCategory=Cette societé n'est dans aucune catégorie en particulier CompanyHasNoCategory=Cette societé n'est dans aucune catégorie en particulier
ClassifyInCategory=Classer dans la catégorie ClassifyInCategory=Classer dans la catégorie
NoneCategory=Aucune NoneCategory=Aucune
CategoryExistsAtSameLevel=Cette catégorie existe déjà au même endroit CategoryExistsAtSameLevel=Cette catégorie existe déjà pour cette référence
ReturnInProduct=Retour sur la fiche produit/service ReturnInProduct=Retour sur la fiche produit/service
ReturnInSupplier=Retour sur la fiche fournisseur ReturnInSupplier=Retour sur la fiche fournisseur
ReturnInCompany=Retour sur la fiche client/prospect ReturnInCompany=Retour sur la fiche client/prospect