mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
New: Can edit root of a category
This commit is contained in:
parent
342f7963f6
commit
63b3cf65ec
|
|
@ -520,19 +520,19 @@ class Categorie
|
|||
|
||||
|
||||
/**
|
||||
* \brief Reconstruit l'arborescence des categories sous la forme d'un tableau
|
||||
* Renvoi un tableau de tableau('id','id_mere',...) trie selon
|
||||
* arbre et avec:
|
||||
* Reconstruit l'arborescence des categories sous la forme d'un tableau
|
||||
* Renvoi un tableau de tableau('id','id_mere',...) trie selon arbre et avec:
|
||||
* id = id de la categorie
|
||||
* id_mere = id de la categorie mere
|
||||
* id_children = tableau des id enfant
|
||||
* label = nom de la categorie
|
||||
* fulllabel = nom avec chemin complet de la categorie
|
||||
* fullpath = chemin complet compose des id
|
||||
* \param type Type of categories (0=product, 1=suppliers, 2=customers, 3=members)
|
||||
* \return array Array of categories
|
||||
* @param type Type of categories (0=product, 1=suppliers, 2=customers, 3=members)
|
||||
* @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();
|
||||
|
||||
|
|
@ -540,6 +540,7 @@ class Categorie
|
|||
$sql = "SELECT fk_categorie_mere as id_mere, fk_categorie_fille as id_fille";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."categorie_association";
|
||||
|
||||
// Load array this->motherof
|
||||
dol_syslog("Categorie::get_full_arbo build motherof array sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
|
|
@ -588,14 +589,34 @@ class Categorie
|
|||
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);
|
||||
foreach($this->cats as $key => $val)
|
||||
{
|
||||
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);
|
||||
$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
|
||||
* \param id_categ id_categ entry to update
|
||||
* \param protection Deep counter to avoid infinite loop
|
||||
* 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 protection Deep counter to avoid infinite loop
|
||||
*/
|
||||
function build_path_from_id_categ($id_categ,$protection=0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -119,11 +119,14 @@ print '<input type="hidden" name="id" value="'.$categorie->id.'">';
|
|||
print '<input type="hidden" name="type" value="'.$type.'">';
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
// Ref
|
||||
print '<tr><td class="fieldrequired">';
|
||||
print $langs->trans("Ref").'</td>';
|
||||
print '<td><input type="text" size="25" id="nom" name ="nom" value="'.$categorie->label.'" />';
|
||||
print '</tr>';
|
||||
|
||||
// Description
|
||||
print '<tr>';
|
||||
print '<td width="25%">'.$langs->trans("Description").'</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->Create();
|
||||
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 '<br>';
|
||||
|
||||
|
|
|
|||
|
|
@ -220,15 +220,20 @@ if ($user->rights->categorie->creer)
|
|||
}
|
||||
|
||||
print '<table width="100%" class="border">';
|
||||
|
||||
// Ref
|
||||
print '<tr>';
|
||||
print '<td width="25%" class="fieldrequired">'.$langs->trans("Ref").'</td><td><input name="nom" size="25" value="'.$categorie->label.'">';
|
||||
print'</td></tr>';
|
||||
|
||||
// Description
|
||||
print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>';
|
||||
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->Create();
|
||||
print '</td></tr>';
|
||||
|
||||
// Parent category
|
||||
print '<tr><td>'.$langs->trans ("AddIn").'</td><td>';
|
||||
print $html->select_all_categories($_GET['type'],$_REQUEST['catorigin']);
|
||||
print '</td></tr>';
|
||||
|
|
|
|||
|
|
@ -161,8 +161,7 @@ print "</div>";
|
|||
|
||||
|
||||
|
||||
|
||||
$cats = $c->get_filles ();
|
||||
$cats = $c->get_filles();
|
||||
if ($cats < 0)
|
||||
{
|
||||
dol_print_error();
|
||||
|
|
@ -209,7 +208,7 @@ 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";
|
||||
}
|
||||
|
|
@ -227,7 +226,7 @@ if ($c->type == 0)
|
|||
{
|
||||
print "<br>";
|
||||
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)
|
||||
{
|
||||
|
|
@ -248,7 +247,7 @@ if ($c->type == 0)
|
|||
}
|
||||
else
|
||||
{
|
||||
print "<tr><td>".$langs->trans("ThisCategoryHasNoProduct")."</td></tr>";
|
||||
print "<tr ".$bc[false].'><td colspan="2">'.$langs->trans("ThisCategoryHasNoProduct")."</td></tr>";
|
||||
}
|
||||
print "</table>\n";
|
||||
}
|
||||
|
|
@ -286,7 +285,7 @@ if ($c->type == 1)
|
|||
}
|
||||
else
|
||||
{
|
||||
print "<tr><td>".$langs->trans ("ThisCategoryHasNoSupplier")."</td></tr>";
|
||||
print "<tr ".$bc[false]."><td>".$langs->trans ("ThisCategoryHasNoSupplier")."</td></tr>";
|
||||
}
|
||||
print "</table>\n";
|
||||
}
|
||||
|
|
@ -323,7 +322,7 @@ if($c->type == 2)
|
|||
}
|
||||
else
|
||||
{
|
||||
print "<tr><td>".$langs->trans("ThisCategoryHasNoCustomer")."</td></tr>";
|
||||
print "<tr ".$bc[false]."><td>".$langs->trans("ThisCategoryHasNoCustomer")."</td></tr>";
|
||||
}
|
||||
print "</table>\n";
|
||||
}
|
||||
|
|
@ -343,7 +342,7 @@ if ($c->type == 3)
|
|||
{
|
||||
print "<br>";
|
||||
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)
|
||||
{
|
||||
|
|
@ -364,7 +363,7 @@ if ($c->type == 3)
|
|||
}
|
||||
else
|
||||
{
|
||||
print "<tr><td>".$langs->trans("ThisCategoryHasNoMember")."</td></tr>";
|
||||
print "<tr ".$bc[false].'><td colspan="3">'.$langs->trans("ThisCategoryHasNoMember")."</td></tr>";
|
||||
}
|
||||
print "</table>\n";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1005,7 +1005,7 @@ class Form
|
|||
}
|
||||
$opt.= '>';
|
||||
$opt.= $langs->convToOutputCharset($objp->ref).' - '.$langs->convToOutputCharset(dol_trunc($label,32)).' - ';
|
||||
|
||||
|
||||
$objRef = $objp->ref;
|
||||
if ($filterkey && $filterkey != '') $objRef=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$objRef,1);
|
||||
$outval.=$objRef.' - '.dol_trunc($label,32).' - ';
|
||||
|
|
@ -1227,7 +1227,7 @@ class Form
|
|||
if ($selected == $objp->idprodfournprice) $opt.= ' selected="true"';
|
||||
if ($objp->fprice == '') $opt.=' disabled="disabled"';
|
||||
$opt.= '>';
|
||||
|
||||
|
||||
$objRef = $objp->ref;
|
||||
if ($filterkey && $filterkey != '') $objRef=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$objRef,1);
|
||||
$objRefFourn = $objp->ref_fourn;
|
||||
|
|
@ -1749,12 +1749,14 @@ class Form
|
|||
}
|
||||
|
||||
/**
|
||||
* \brief Retourne la liste des categories du type choisi
|
||||
* \param type Type de categories (0=produit, 1=fournisseur, 2=client)
|
||||
* \param selected Id categorie preselectionnee
|
||||
* \param select_name Nom formulaire HTML
|
||||
* Return list of categories having choosed type
|
||||
* @param type Type de categories (0=product, 1=supplier, 2=customer, 3=member)
|
||||
* @param selected Id of category preselected
|
||||
* @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;
|
||||
$langs->load("categories");
|
||||
|
|
@ -1762,7 +1764,7 @@ class Form
|
|||
if ($select_name=="") $select_name="catMere";
|
||||
|
||||
$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.'">';
|
||||
if (is_array($cate_arbo))
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user