New: Can edit root of a category

This commit is contained in:
Laurent Destailleur 2010-10-19 22:52:32 +00:00
parent 342f7963f6
commit 63b3cf65ec
5 changed files with 64 additions and 28 deletions

View File

@ -520,19 +520,19 @@ class Categorie
/** /**
* \brief Reconstruit l'arborescence des categories sous la forme d'un tableau * Reconstruit l'arborescence des categories sous la forme d'un tableau
* Renvoi un tableau de tableau('id','id_mere',...) trie selon * Renvoi un tableau de tableau('id','id_mere',...) trie selon arbre et avec:
* arbre et avec:
* id = id de la categorie * id = id de la categorie
* id_mere = id de la categorie mere * id_mere = id de la categorie mere
* id_children = tableau des id enfant * id_children = tableau des id enfant
* label = nom de la categorie * label = nom de la categorie
* fulllabel = nom avec chemin complet de la categorie * fulllabel = nom avec chemin complet de la categorie
* fullpath = chemin complet compose des id * fullpath = chemin complet compose des id
* \param type Type of categories (0=product, 1=suppliers, 2=customers, 3=members) * @param type Type of categories (0=product, 1=suppliers, 2=customers, 3=members)
* \return array Array of categories * @param markafterid Mark all categories after this leaf in category tree.
* @return array Array of categories
*/ */
function get_full_arbo($type) function get_full_arbo($type,$markafterid=0)
{ {
$this->cats = array(); $this->cats = array();
@ -540,6 +540,7 @@ class Categorie
$sql = "SELECT fk_categorie_mere as id_mere, fk_categorie_fille as id_fille"; $sql = "SELECT fk_categorie_mere as id_mere, fk_categorie_fille as id_fille";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie_association"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie_association";
// Load array this->motherof
dol_syslog("Categorie::get_full_arbo build motherof array sql=".$sql, LOG_DEBUG); dol_syslog("Categorie::get_full_arbo build motherof array sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
@ -588,14 +589,34 @@ class Categorie
return -1; return -1;
} }
// We add the fulpath property to each elements of first level (no parent exists) // We add the fullpath property to each elements of first level (no parent exists)
dol_syslog("Categorie::get_full_arbo call to build_path_from_id_categ", LOG_DEBUG); dol_syslog("Categorie::get_full_arbo call to build_path_from_id_categ", LOG_DEBUG);
foreach($this->cats as $key => $val) foreach($this->cats as $key => $val)
{ {
if (isset($this->motherof[$key])) continue; if (isset($this->motherof[$key])) continue;
$this->build_path_from_id_categ($key,0); // Process a path of a root category (no parent exists) $this->build_path_from_id_categ($key,0); // Process a branch from the root category key (this category has no parent)
} }
// Exclude tree for $markafterid
if ($markafterid)
{
//print "Look to discard category ".$markafterid."\n";
$keyfilter1='^'.$markafterid.'$';
$keyfilter2='_'.$markafterid.'$';
$keyfilter3='^'.$markafterid.'_';
$keyfilter4='_'.$markafterid.'_';
foreach($this->cats as $key => $val)
{
if (preg_match('/'.$keyfilter1.'/',$val['fullpath']) || preg_match('/'.$keyfilter2.'/',$val['fullpath'])
|| preg_match('/'.$keyfilter3.'/',$val['fullpath']) || preg_match('/'.$keyfilter4.'/',$val['fullpath']))
{
//print "Categ discarded ".$this->cats[$key]['fullpath']."\n";
//$this->cats[$key]['marked']=1;
unset($this->cats[$key]);
}
}
}
dol_syslog("Categorie::get_full_arbo dol_sort_array", LOG_DEBUG); dol_syslog("Categorie::get_full_arbo dol_sort_array", LOG_DEBUG);
$this->cats=dol_sort_array($this->cats, 'fulllabel', 'asc', true, false); $this->cats=dol_sort_array($this->cats, 'fulllabel', 'asc', true, false);
@ -605,9 +626,9 @@ class Categorie
} }
/** /**
* \brief For category id_categ and its child available in this->cats, define property fullpath and fulllabel * For category id_categ and its childs available in this->cats, define property fullpath and fulllabel
* \param id_categ id_categ entry to update * @param id_categ id_categ entry to update
* \param protection Deep counter to avoid infinite loop * @param protection Deep counter to avoid infinite loop
*/ */
function build_path_from_id_categ($id_categ,$protection=0) function build_path_from_id_categ($id_categ,$protection=0)
{ {

View File

@ -119,11 +119,14 @@ print '<input type="hidden" name="id" value="'.$categorie->id.'">';
print '<input type="hidden" name="type" value="'.$type.'">'; print '<input type="hidden" name="type" value="'.$type.'">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Ref
print '<tr><td class="fieldrequired">'; print '<tr><td class="fieldrequired">';
print $langs->trans("Ref").'</td>'; print $langs->trans("Ref").'</td>';
print '<td><input type="text" size="25" id="nom" name ="nom" value="'.$categorie->label.'" />'; print '<td><input type="text" size="25" id="nom" name ="nom" value="'.$categorie->label.'" />';
print '</tr>'; print '</tr>';
// Description
print '<tr>'; print '<tr>';
print '<td width="25%">'.$langs->trans("Description").'</td>'; print '<td width="25%">'.$langs->trans("Description").'</td>';
print '<td>'; print '<td>';
@ -131,6 +134,12 @@ require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
$doleditor=new DolEditor('description',$categorie->description,200,'dolibarr_notes','',false,true,$conf->fckeditor->enabled,ROWS_6,50); $doleditor=new DolEditor('description',$categorie->description,200,'dolibarr_notes','',false,true,$conf->fckeditor->enabled,ROWS_6,50);
$doleditor->Create(); $doleditor->Create();
print '</td></tr>'; print '</td></tr>';
// Parent category
print '<tr><td>'.$langs->trans ("In").'</td><td>';
print $html->select_all_categories($type,$categorie->id_mere,'catMere',64,$categorie->id);
print '</td></tr>';
print '</table>'; print '</table>';
print '<br>'; print '<br>';

View File

@ -220,15 +220,20 @@ if ($user->rights->categorie->creer)
} }
print '<table width="100%" class="border">'; print '<table width="100%" class="border">';
// Ref
print '<tr>'; print '<tr>';
print '<td width="25%" class="fieldrequired">'.$langs->trans("Ref").'</td><td><input name="nom" size="25" value="'.$categorie->label.'">'; print '<td width="25%" class="fieldrequired">'.$langs->trans("Ref").'</td><td><input name="nom" size="25" value="'.$categorie->label.'">';
print'</td></tr>'; print'</td></tr>';
// Description
print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>'; print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>';
require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
$doleditor=new DolEditor('description',$categorie->description,200,'dolibarr_notes','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC,ROWS_6,50); $doleditor=new DolEditor('description',$categorie->description,200,'dolibarr_notes','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC,ROWS_6,50);
$doleditor->Create(); $doleditor->Create();
print '</td></tr>'; print '</td></tr>';
// Parent category
print '<tr><td>'.$langs->trans ("AddIn").'</td><td>'; print '<tr><td>'.$langs->trans ("AddIn").'</td><td>';
print $html->select_all_categories($_GET['type'],$_REQUEST['catorigin']); print $html->select_all_categories($_GET['type'],$_REQUEST['catorigin']);
print '</td></tr>'; print '</td></tr>';

View File

@ -161,8 +161,7 @@ print "</div>";
$cats = $c->get_filles();
$cats = $c->get_filles ();
if ($cats < 0) if ($cats < 0)
{ {
dol_print_error(); dol_print_error();
@ -209,7 +208,7 @@ else
} }
else else
{ {
print "<tr><td>".$langs->trans("NoSubCat")."</td></tr>"; print "<tr ".$bc[false].'><td colspan="3">'.$langs->trans("NoSubCat")."</td></tr>";
} }
print "</table>\n"; print "</table>\n";
} }
@ -227,7 +226,7 @@ if ($c->type == 0)
{ {
print "<br>"; print "<br>";
print "<table class='noborder' width='100%'>\n"; print "<table class='noborder' width='100%'>\n";
print "<tr class='liste_titre'><td colspan='2'>".$langs->trans("ProductsAndServices")."</td></tr>\n"; print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("ProductsAndServices")."</td></tr>\n";
if (sizeof ($prods) > 0) if (sizeof ($prods) > 0)
{ {
@ -248,7 +247,7 @@ if ($c->type == 0)
} }
else else
{ {
print "<tr><td>".$langs->trans("ThisCategoryHasNoProduct")."</td></tr>"; print "<tr ".$bc[false].'><td colspan="2">'.$langs->trans("ThisCategoryHasNoProduct")."</td></tr>";
} }
print "</table>\n"; print "</table>\n";
} }
@ -286,7 +285,7 @@ if ($c->type == 1)
} }
else else
{ {
print "<tr><td>".$langs->trans ("ThisCategoryHasNoSupplier")."</td></tr>"; print "<tr ".$bc[false]."><td>".$langs->trans ("ThisCategoryHasNoSupplier")."</td></tr>";
} }
print "</table>\n"; print "</table>\n";
} }
@ -323,7 +322,7 @@ if($c->type == 2)
} }
else else
{ {
print "<tr><td>".$langs->trans("ThisCategoryHasNoCustomer")."</td></tr>"; print "<tr ".$bc[false]."><td>".$langs->trans("ThisCategoryHasNoCustomer")."</td></tr>";
} }
print "</table>\n"; print "</table>\n";
} }
@ -343,7 +342,7 @@ if ($c->type == 3)
{ {
print "<br>"; print "<br>";
print "<table class='noborder' width='100%'>\n"; print "<table class='noborder' width='100%'>\n";
print "<tr class='liste_titre'><td colspan='3'>".$langs->trans("Member")."</td></tr>\n"; print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Member")."</td></tr>\n";
if (sizeof ($prods) > 0) if (sizeof ($prods) > 0)
{ {
@ -364,7 +363,7 @@ if ($c->type == 3)
} }
else else
{ {
print "<tr><td>".$langs->trans("ThisCategoryHasNoMember")."</td></tr>"; print "<tr ".$bc[false].'><td colspan="3">'.$langs->trans("ThisCategoryHasNoMember")."</td></tr>";
} }
print "</table>\n"; print "</table>\n";
} }

View File

@ -1749,12 +1749,14 @@ class Form
} }
/** /**
* \brief Retourne la liste des categories du type choisi * Return list of categories having choosed type
* \param type Type de categories (0=produit, 1=fournisseur, 2=client) * @param type Type de categories (0=product, 1=supplier, 2=customer, 3=member)
* \param selected Id categorie preselectionnee * @param selected Id of category preselected
* \param select_name Nom formulaire HTML * @param select_name HTML field name
* @param maxlength Maximum length for labels
* @param excludeafterid Exclude all categories after this leaf in category tree.
*/ */
function select_all_categories($type,$selected='',$select_name="",$maxlength=64) function select_all_categories($type, $selected='', $select_name="", $maxlength=64, $excludeafterid=0)
{ {
global $langs; global $langs;
$langs->load("categories"); $langs->load("categories");
@ -1762,7 +1764,7 @@ class Form
if ($select_name=="") $select_name="catMere"; if ($select_name=="") $select_name="catMere";
$cat = new Categorie($this->db); $cat = new Categorie($this->db);
$cate_arbo = $cat->get_full_arbo($type); $cate_arbo = $cat->get_full_arbo($type,$excludeafterid);
$output = '<select class="flat" name="'.$select_name.'">'; $output = '<select class="flat" name="'.$select_name.'">';
if (is_array($cate_arbo)) if (is_array($cate_arbo))