Fix: Error management
New: Autoselect category in list if there is only one element in list.
This commit is contained in:
parent
c4bc10b8eb
commit
327aa80ed0
@ -2,7 +2,7 @@
|
|||||||
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2005 Brice Davoleau <brice.davoleau@gmail.com>
|
* Copyright (C) 2005 Brice Davoleau <brice.davoleau@gmail.com>
|
||||||
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||||
* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
|
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
|
||||||
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
|
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
|
||||||
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
||||||
@ -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 DoliDb $db Database handler
|
||||||
* @param Object $object Object we want to see categories it can be classified into
|
* @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 == 3) $title = $langs->trans("MembersCategoriesShort");
|
||||||
if ($typeid == 4) $title = $langs->trans("ContactCategoriesShort");
|
if ($typeid == 4) $title = $langs->trans("ContactCategoriesShort");
|
||||||
|
|
||||||
// Formulaire ajout dans une categorie
|
// Form to add record into a category
|
||||||
print '<br>';
|
print '<br>';
|
||||||
print_fiche_titre($title,'','');
|
print_fiche_titre($title,'','');
|
||||||
print '<form method="post" action="'.DOL_URL_ROOT.'/categories/categorie.php">';
|
print '<form method="post" action="'.DOL_URL_ROOT.'/categories/categorie.php">';
|
||||||
@ -637,7 +637,7 @@ function formCategory($db,$object,$typeid,$socid=0)
|
|||||||
print '<table class="noborder" width="100%">';
|
print '<table class="noborder" width="100%">';
|
||||||
print '<tr class="liste_titre"><td width="40%">';
|
print '<tr class="liste_titre"><td width="40%">';
|
||||||
print $langs->trans("ClassifyInCategory").' ';
|
print $langs->trans("ClassifyInCategory").' ';
|
||||||
print $form->select_all_categories($typeid);
|
print $form->select_all_categories($typeid,'auto');
|
||||||
print '</td><td>';
|
print '</td><td>';
|
||||||
print '<input type="submit" class="button" value="'.$langs->trans("Classify").'"></td>';
|
print '<input type="submit" class="button" value="'.$langs->trans("Classify").'"></td>';
|
||||||
if ($user->rights->categorie->creer)
|
if ($user->rights->categorie->creer)
|
||||||
|
|||||||
@ -420,16 +420,27 @@ class Categorie
|
|||||||
{
|
{
|
||||||
$objparent = $this->db->fetch_object($resql);
|
$objparent = $this->db->fetch_object($resql);
|
||||||
|
|
||||||
if (!empty($objparent->fk_parent)) {
|
if (!empty($objparent->fk_parent))
|
||||||
|
{
|
||||||
$cat = new Categorie($this->db);
|
$cat = new Categorie($this->db);
|
||||||
$cat->id=$objparent->fk_parent;
|
$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
|
else
|
||||||
{
|
{
|
||||||
|
$error++;
|
||||||
$this->error=$this->db->lasterror();
|
$this->error=$this->db->lasterror();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($error)
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2407,7 +2407,7 @@ class Form
|
|||||||
* Return list of categories having choosed type
|
* Return list of categories having choosed type
|
||||||
*
|
*
|
||||||
* @param int $type Type de categories (0=product, 1=supplier, 2=customer, 3=member)
|
* @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 string $htmlname HTML field name
|
||||||
* @param int $maxlength Maximum length for labels
|
* @param int $maxlength Maximum length for labels
|
||||||
* @param int $excludeafterid Exclude all categories after this leaf in category tree.
|
* @param int $excludeafterid Exclude all categories after this leaf in category tree.
|
||||||
@ -2430,7 +2430,7 @@ class Form
|
|||||||
$output.= '<option value="-1"> </option>';
|
$output.= '<option value="-1"> </option>';
|
||||||
foreach($cate_arbo as $key => $value)
|
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" ';
|
$add = 'selected="selected" ';
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user