diff --git a/htdocs/categories/categorie.php b/htdocs/categories/categorie.php index f77c04b07d4..0eba0baa68c 100644 --- a/htdocs/categories/categorie.php +++ b/htdocs/categories/categorie.php @@ -2,7 +2,7 @@ /* Copyright (C) 2001-2007 Rodolphe Quiedeville * Copyright (C) 2005 Brice Davoleau * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2006-2011 Laurent Destailleur + * Copyright (C) 2006-2013 Laurent Destailleur * Copyright (C) 2007 Patrick Raguin * Copyright (C) 2010 Juanjo Menent * Copyright (C) 2013 Florian Henry @@ -608,7 +608,7 @@ else if ($id || $ref) /** - * Function to output a HTML select for a category + * Function to output a form to add object into a category * * @param DoliDb $db Database handler * @param Object $object Object we want to see categories it can be classified into @@ -626,7 +626,7 @@ function formCategory($db,$object,$typeid,$socid=0) if ($typeid == 3) $title = $langs->trans("MembersCategoriesShort"); if ($typeid == 4) $title = $langs->trans("ContactCategoriesShort"); - // Formulaire ajout dans une categorie + // Form to add record into a category print '
'; print_fiche_titre($title,'',''); print '
'; @@ -637,7 +637,7 @@ function formCategory($db,$object,$typeid,$socid=0) print ''; print ''; if ($user->rights->categorie->creer) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index ac71c22d612..268681a8b46 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -420,16 +420,27 @@ class Categorie { $objparent = $this->db->fetch_object($resql); - if (!empty($objparent->fk_parent)) { + if (!empty($objparent->fk_parent)) + { $cat = new Categorie($this->db); $cat->id=$objparent->fk_parent; - $cat->add_type($obj, $type); + $result=$cat->add_type($obj, $type); + if ($result < 0) + { + $this->error=$cat->error; + $error++; + } } } } else { + $error++; $this->error=$this->db->lasterror(); + } + + if ($error) + { return -1; } } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index bef2f1465af..b63703d5785 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2407,7 +2407,7 @@ class Form * Return list of categories having choosed type * * @param int $type Type de categories (0=product, 1=supplier, 2=customer, 3=member) - * @param string $selected Id of category preselected + * @param string $selected Id of category preselected or 'auto' (autoselect category if there is only one element) * @param string $htmlname HTML field name * @param int $maxlength Maximum length for labels * @param int $excludeafterid Exclude all categories after this leaf in category tree. @@ -2430,7 +2430,7 @@ class Form $output.= ''; foreach($cate_arbo as $key => $value) { - if ($cate_arbo[$key]['id'] == $selected) + if ($cate_arbo[$key]['id'] == $selected || ($selected == 'auto' && count($cate_arbo) == 1)) { $add = 'selected="selected" '; }
'; print $langs->trans("ClassifyInCategory").'  '; - print $form->select_all_categories($typeid); + print $form->select_all_categories($typeid,'auto'); print ''; print '