diff --git a/htdocs/categories/categorie.class.php b/htdocs/categories/categorie.class.php index 54aef117192..55563dd6d43 100644 --- a/htdocs/categories/categorie.class.php +++ b/htdocs/categories/categorie.class.php @@ -874,23 +874,29 @@ class Categorie } /** - * Retourne les catégories dont le nom correspond à $nom - * ajoute des wildcards sauf si $exact = true + * \brief Retourne les catégories dont l'id ou le nom correspond + * ajoute des wildcards au nom sauf si $exact = true */ - function rechercher_par_nom ($nom, $exact = false) + function rechercher($id, $nom, $exact = false) { $cats = array (); - if (!$exact) + // Generation requete recherche + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie "; + if ($nom) { - $nom = '%'.str_replace ('*', '%', $nom).'%'; + if (! $exact) + { + $nom = '%'.str_replace ('*', '%', $nom).'%'; + } + $sql.= "WHERE label LIKE '".$nom."'"; + } + if ($id) + { + $sql.="WHERE rowid = '".$id."'"; } - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie "; - $sql .= "WHERE label LIKE '".$nom."'"; - $res = $this->db->query ($sql); - if ($res) { while ($id = $this->db->fetch_array ($res)) @@ -902,7 +908,10 @@ class Categorie } else { - return 0; + $this->error=$this->db->error().' sql='.$sql; + //dolibarr_syslog($this->error); + dolibarr_print_error('',$this->error); + return -1; } } } diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index 802f9e78334..34d15923011 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -31,26 +31,11 @@ $user->getrights(); if (!$user->rights->categorie->lire) accessforbidden(); - -/* - * Affichage fiche - */ - -llxHeader("","",$langs->trans("Categories")); - -print_titre($langs->trans("ModifCat")); - -print '
| ';
-
-$categorie = new Categorie ($db, $_REQUEST['id']);
-$html = new Form($db);
-
-
// Action mise à jour d'une catégorie
if ($_POST["action"] == 'update' && $user->rights->categorie->creer)
{
+ $categorie = new Categorie ($db, $_REQUEST['id']);
+
$categorie->label = $_POST["nom"];
$categorie->description = $_POST["description"];
$categorie->visible = $_POST["visible"];
@@ -69,22 +54,43 @@ if ($_POST["action"] == 'update' && $user->rights->categorie->creer)
{
if ($categorie->update() > 0)
{
- $_GET["action"] = 'confirmed';
- $_POST["addcat"] = '';
+ header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id);
+ exit;
}
}
}
+
+
+
+/*
+ * Affichage fiche
+ */
+
+llxHeader("","",$langs->trans("Categories"));
+
+print_titre($langs->trans("ModifCat"));
+print " "; + if ($categorie->error) { print ' ';
print $categorie->error;
print ' ';
}
-print ' | |
';
+
+$categorie = new Categorie ($db, $_REQUEST['id']);
+$html = new Form($db);
+
+print '
|