Fix: [task #146] Remove table llx_categorie_association

Conflicts:
	htdocs/install/mysql/migration/3.2.0-3.3.0.sql
This commit is contained in:
Regis Houssin 2012-10-08 19:27:02 +02:00
parent 67c41721f5
commit 0975918cc6
11 changed files with 235 additions and 350 deletions

View File

@ -40,15 +40,13 @@ class Categorie
public $table_element='category';
var $id;
var $id_mere;
var $fk_parent;
var $label;
var $description;
var $socid;
var $type; // 0=Product, 1=Supplier, 2=Customer/Prospect, 3=Member
var $parentId;
var $cats=array(); // Tableau en memoire des categories
var $motherof = array(); // Tableau des correspondances id_fille -> id_mere
/**
@ -69,7 +67,7 @@ class Categorie
*/
function fetch($id)
{
$sql = "SELECT rowid, entity, label, description, fk_soc, visible, type";
$sql = "SELECT rowid, fk_parent, entity, label, description, fk_soc, visible, type";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie";
$sql.= " WHERE rowid = ".$id;
@ -80,6 +78,7 @@ class Categorie
$res = $this->db->fetch_array($resql);
$this->id = $res['rowid'];
$this->fk_parent = $res['fk_parent'];
$this->label = $res['label'];
$this->description = $res['description'];
$this->socid = $res['fk_soc'];
@ -88,25 +87,8 @@ class Categorie
$this->entity = $res['entity'];
$this->db->free($resql);
}
else
{
dol_print_error($this->db);
return -1;
}
$sql = "SELECT fk_categorie_mere";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie_association";
$sql.= " WHERE fk_categorie_fille = ".$id;
dol_syslog("Categorie::fetch sql=".$sql);
$resql = $this->db->query($sql);
if ($resql)
{
$res = $this->db->fetch_array($resql);
$this->id_mere = $res['fk_categorie_mere'];
$this->parentId = $res['fk_categorie_mere'] ? $res['fk_categorie_mere'] : 0;
return $this->id;
return 1;
}
else
{
@ -133,7 +115,7 @@ class Categorie
// Clean parameters
if (empty($this->visible)) $this->visible=0;
$this->parentId = ($this->id_mere) != "" ? intval($this->id_mere) : 0;
$this->fk_parent = ($this->fk_parent != "" ? intval($this->fk_parent) : 0);
if ($this->already_exists())
{
@ -146,7 +128,7 @@ class Categorie
$this->db->begin();
dol_syslog(get_class($this).'::create sql='.$sql);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label, description,";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (fk_parent, label, description,";
if (! empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER))
{
$sql.= "fk_soc,";
@ -154,15 +136,13 @@ class Categorie
$sql.= " visible,";
$sql.= " type,";
$sql.= " entity";
//$sql.= ", fk_parent_id";
$sql.= ")";
$sql.= " VALUES ('".$this->db->escape($this->label)."', '".$this->db->escape($this->description)."',";
$sql.= " VALUES (".$this->fk_parent.",'".$this->db->escape($this->label)."', '".$this->db->escape($this->description)."',";
if (! empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER))
{
$sql.= ($this->socid != -1 ? $this->socid : 'null').",";
}
$sql.= "'".$this->visible."',".$this->type.",".$conf->entity;
//$sql.= ",".$this->parentId;
$sql.= ")";
dol_syslog(get_class($this).'::create sql='.$sql);
@ -174,15 +154,6 @@ class Categorie
if ($id > 0)
{
$this->id = $id;
if($this->id_mere != "")
{
if($this->add_fille() < 0)
{
$this->error=$langs->trans("ImpossibleAssociateCategory");
$this->db->rollback();
return -3;
}
}
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
@ -226,8 +197,8 @@ class Categorie
// Clean parameters
$this->label=trim($this->label);
$this->description=trim($this->description);
$this->parentId = ($this->id_mere) != "" ? intval($this->id_mere) : 0;
$this->visible = ($this->visible) != "" ? intval($this->visible) : 0;
$this->fk_parent = ($this->fk_parent != "" ? intval($this->fk_parent) : 0);
$this->visible = ($this->visible != "" ? intval($this->visible) : 0);
if ($this->already_exists())
{
@ -238,34 +209,9 @@ class Categorie
$this->db->begin();
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'categorie_association';
$sql.= ' WHERE fk_categorie_fille = '.$this->id;
dol_syslog("Categorie::update sql=".$sql);
if (! $this->db->query($sql))
{
$this->db->rollback();
dol_print_error($this->db);
return -1;
}
if($this->id_mere !="" && $this->id_mere!=$this->id)
{
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'categorie_association(fk_categorie_mere,fk_categorie_fille)';
$sql.= ' VALUES ('.$this->id_mere.', '.$this->id.')';
dol_syslog("Categorie::update sql=".$sql);
if (! $this->db->query($sql))
{
$this->db->rollback();
dol_print_error($this->db);
return -1;
}
}
$sql = "UPDATE ".MAIN_DB_PREFIX."categorie";
$sql.= " SET label = '".$this->db->escape($this->label)."'";
if ($this->description)
if (! empty($this->description))
{
$sql .= ", description = '".$this->db->escape($this->description)."'";
}
@ -274,7 +220,7 @@ class Categorie
$sql .= ", fk_soc = ".($this->socid != -1 ? $this->socid : 'null');
}
$sql .= ", visible = '".$this->visible."'";
//$sql .= ", fk_parent_id = ".$this->parentId;
$sql .= ", fk_parent = ".$this->fk_parent;
$sql .= " WHERE rowid = ".$this->id;
dol_syslog("Categorie::update sql=".$sql);
@ -360,20 +306,6 @@ class Categorie
}
}
// Link childs to parent
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_association";
$sql .= " WHERE fk_categorie_mere = ".$this->id;
$sql .= " OR fk_categorie_fille = ".$this->id;
if (!$this->db->query($sql))
{
$this->error=$this->db->lasterror();
dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR);
$error++;
}
}
// Delete category
if (! $error)
{
@ -408,58 +340,6 @@ class Categorie
}
}
/**
* Ajout d'une sous-categorie
*
* @return int 1 : OK
* -2 : $fille est deja dans la famille de $this
* -3 : categorie ($this ou $fille) invalide
*/
function add_fille()
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_association (fk_categorie_mere, fk_categorie_fille)";
$sql.= " VALUES (".$this->id_mere.", ".$this->id.")";
if ($this->db->query($sql))
{
return 1;
}
else
{
dol_print_error($this->db);
return -1;
}
}
/**
* Suppression d'une sous-categorie (seulement "desassociation")
*
* @param Category $fille Objet category
* @return int 1 : OK
* -3 : categorie ($this ou $fille) invalide
*/
function del_fille($fille)
{
if (!$this->check() || !$fille->check())
{
return -3;
}
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_association";
$sql .= " WHERE fk_categorie_mere = ".$this->id." and fk_categorie_fille = ".$fille->id;
if ($this->db->query($sql))
{
return 1;
}
else
{
$this->error=$this->db->error().' sql='.$sql;
return -1;
}
}
/**
* Link an object to the category
*
@ -540,9 +420,9 @@ class Categorie
$sql = "SELECT c.fk_".$field;
$sql.= " FROM ".MAIN_DB_PREFIX."categorie_".$category_table." as c";
$sql.= ", ".MAIN_DB_PREFIX.$object_table." as o";
$sql.= " WHERE c.fk_categorie = ".$this->id;
$sql.= " WHERE o.entity IN (".getEntity($field, 1).")";
$sql.= " AND c.fk_categorie = ".$this->id;
$sql.= " AND c.fk_".$field." = o.rowid";
$sql.= " AND o.entity IN (".getEntity($field, 1).")";
dol_syslog(get_class($this)."::get_type sql=".$sql);
$resql = $this->db->query($sql);
@ -572,8 +452,8 @@ class Categorie
*/
function get_filles()
{
$sql = "SELECT fk_categorie_fille FROM ".MAIN_DB_PREFIX."categorie_association ";
$sql .= "WHERE fk_categorie_mere = ".$this->id;
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie";
$sql.= " WHERE fk_parent = ".$this->id;
$res = $this->db->query($sql);
@ -583,7 +463,7 @@ class Categorie
while ($rec = $this->db->fetch_array($res))
{
$cat = new Categorie($this->db);
$cat->fetch($rec['fk_categorie_fille']);
$cat->fetch($rec['rowid']);
$cats[] = $cat;
}
return $cats;
@ -601,6 +481,7 @@ class Categorie
*
* @param int $cate Category id
* @return string Description
* @deprecated function not used ?
*/
function get_desc($cate)
{
@ -616,13 +497,14 @@ class Categorie
/**
* La categorie $fille est-elle une fille de cette categorie ?
*
* @param Category $fille Object category
* @param Category $child Object category
* @return void
* @deprecated function not used ?
*/
function is_fille($fille)
function is_fille($child)
{
$sql = "SELECT count(fk_categorie_fille) FROM ".MAIN_DB_PREFIX."categorie_association ";
$sql .= "WHERE fk_categorie_mere = ".$this->id." AND fk_categorie_fille = ".$fille->id;
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie";
$sql.= " WHERE fk_parent = ".$this->id." AND rowid = ".$child->id;
$res = $this->db->query($sql);
$n = $this->db->fetch_array($res);
@ -649,37 +531,11 @@ class Categorie
{
$this->cats = array();
// Charge tableau des meres
$sql = "SELECT ca.fk_categorie_mere as id_mere, ca.fk_categorie_fille as id_fille";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie_association ca";
$sql.= ", ".MAIN_DB_PREFIX."categorie as c";
$sql.= " WHERE ca.fk_categorie_mere = c.rowid";
$sql.= " AND c.entity IN (".getEntity('category',1).")";
// Load array this->motherof
dol_syslog("Categorie::get_full_arbo build motherof array sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
while ($obj=$this->db->fetch_object($resql))
{
$this->motherof[$obj->id_fille]=$obj->id_mere;
}
}
else
{
dol_print_error($this->db);
return -1;
}
// Init $this->cats array
$sql = "SELECT DISTINCT c.rowid, c.label as label, ca.fk_categorie_fille as rowid_fille"; // Distinct reduce pb with old tables with duplicates
$sql = "SELECT DISTINCT c.rowid, c.label, c.description, c.fk_parent"; // Distinct reduce pb with old tables with duplicates
$sql.= " FROM ".MAIN_DB_PREFIX."categorie as c";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_association as ca";
$sql.= " ON c.rowid = ca.fk_categorie_mere";
$sql.= " WHERE c.type = ".$type;
$sql.= " AND c.entity IN (".getEntity('category',1).")";
$sql.= " ORDER BY c.label, c.rowid";
$sql.= " WHERE c.entity IN (".getEntity('category',1).")";
$sql.= " AND c.type = ".$type;
dol_syslog("Categorie::get_full_arbo get category list sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
@ -688,16 +544,12 @@ class Categorie
$i=0;
while ($obj = $this->db->fetch_object($resql))
{
$this->cats[$obj->rowid]['rowid'] = $obj->rowid;
$this->cats[$obj->rowid]['id'] = $obj->rowid;
if (isset($this->motherof[$obj->rowid])) $this->cats[$obj->rowid]['id_mere'] = $this->motherof[$obj->rowid];
$this->cats[$obj->rowid]['fk_parent'] = $obj->fk_parent;
$this->cats[$obj->rowid]['label'] = $obj->label;
if ($obj->rowid_fille)
{
$this->cats[$obj->rowid]['id_children'][]=$obj->rowid_fille;
}
$this->cats[$obj->rowid]['description'] = $obj->description;
$i++;
}
}
else
@ -710,7 +562,6 @@ class Categorie
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 branch from the root category key (this category has no parent)
}
@ -761,21 +612,22 @@ class Categorie
//}
// Define fullpath and fulllabel
if (isset($this->cats[$id_categ]['id_mere']))
if (! empty($this->cats[$id_categ]['fk_parent']))
{
$this->cats[$id_categ]['fullpath'] =$this->cats[$this->cats[$id_categ]['id_mere']]['fullpath'];
$this->cats[$id_categ]['fullpath'].='_'.$id_categ;
$this->cats[$id_categ]['fulllabel'] =$this->cats[$this->cats[$id_categ]['id_mere']]['fulllabel'];
$this->cats[$id_categ]['fulllabel'].=' >> '.$this->cats[$id_categ]['label'];
$this->cats[$id_categ]['fullpath'] = $this->cats[$this->cats[$id_categ]['fk_parent']]['fullpath'];
$this->cats[$id_categ]['fullpath'].= '_'.$id_categ;
$this->cats[$id_categ]['fulllabel'] = $this->cats[$this->cats[$id_categ]['fk_parent']]['fulllabel'];
$this->cats[$id_categ]['fulllabel'].= ' >> '.$this->cats[$id_categ]['label'];
}
else
{
$this->cats[$id_categ]['fullpath']='_'.$id_categ;
$this->cats[$id_categ]['fulllabel']=$this->cats[$id_categ]['label'];
$this->cats[$id_categ]['fullpath'] = '_'.$id_categ;
$this->cats[$id_categ]['fulllabel'] = $this->cats[$id_categ]['label'];
}
// We count number of _ to have level
$this->cats[$id_categ]['level']=dol_strlen(preg_replace('/[^_]/i','',$this->cats[$id_categ]['fullpath']));
/*
// Process all childs on several levels of this category
$protection++;
if ($protection > 10) return; // On ne traite pas plus de 10 niveaux de profondeurs
@ -791,6 +643,7 @@ class Categorie
$this->build_path_from_id_categ($idchild,$protection);
}
*/
return;
}
@ -807,8 +660,8 @@ class Categorie
{
print 'id: '.$this->cats[$key]['id'];
print ' label: '.$this->cats[$key]['label'];
print ' mother: '.$this->cats[$key]['id_mere'];
print ' children: '.(is_array($this->cats[$key]['id_children'])?join(',',$this->cats[$key]['id_children']):'');
print ' mother: '.$this->cats[$key]['fk_parent'];
//print ' children: '.(is_array($this->cats[$key]['id_children'])?join(',',$this->cats[$key]['id_children']):'');
print ' fullpath: '.$this->cats[$key]['fullpath'];
print ' fulllabel: '.$this->cats[$key]['fulllabel'];
print "<br>\n";
@ -819,12 +672,18 @@ class Categorie
/**
* Retourne toutes les categories
*
* @param int Type of category
* @param boolean Just parent categories if true
* @return array Tableau d'objet Categorie
*/
function get_all_categories ()
function get_all_categories($type=null, $parent=false)
{
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie";
$sql.= " WHERE entity IN (".getEntity('category',1).")";
if (! is_null($type))
$sql.= " AND type = ".$type;
if ($parent)
$sql.= " AND fk_parent = 0";
$res = $this->db->query($sql);
if ($res)
@ -834,7 +693,7 @@ class Categorie
{
$cat = new Categorie($this->db);
$cat->fetch($rec['rowid']);
$cats[$record['rowid']] = $cat;
$cats[$rec['rowid']] = $cat;
}
return $cats;
}
@ -849,6 +708,7 @@ class Categorie
* Retourne le nombre total de categories
*
* @return int Nombre de categories
* @deprecated function not used ?
*/
function get_nb_categories()
{
@ -870,37 +730,21 @@ class Categorie
/**
* Check if no category with same label already exists for this cat's parent or root and for this cat's type
* TODO For the moment, the unique key is on the type, label, entity. We must remove table llx_categorie_association
* to replace with a field fk_parent. This will allow to extend unique key with the level.
*
* @return boolean 1 if already exist, 0 otherwise, -1 if error
*/
function already_exists()
{
if($this->id_mere != "") // mother_id defined
{
/* We have to select any rowid from llx_categorie which category's mother and label
* are equals to those of the calling category
*/
$sql = "SELECT c.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie as c ";
$sql.= " JOIN ".MAIN_DB_PREFIX."categorie_association as ca";
$sql.= " ON c.rowid=ca.fk_categorie_fille";
$sql.= " WHERE ca.fk_categorie_mere=".$this->id_mere;
$sql.= " AND c.label='".$this->db->escape($this->label)."'";
$sql.= " AND c.entity IN (".getEntity('category',1).")";
}
else // mother_id undefined (so it's root)
{
/* We have to select any rowid from llx_categorie that is not at root level
*/
$sql = "SELECT c.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie as c ";
$sql.= " WHERE c.type=".$this->type;
$sql.= " AND c.label='".$this->db->escape($this->label)."'";
$sql.= " AND c.entity IN (".getEntity('category',1).")";
$sql.= " AND c.rowid NOT IN (SELECT ca.fk_categorie_fille FROM ".MAIN_DB_PREFIX."categorie_association as ca)";
}
/* We have to select any rowid from llx_categorie which category's mother and label
* are equals to those of the calling category
*/
$sql = "SELECT c.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie as c ";
$sql.= " WHERE c.entity IN (".getEntity('category',1).")";
$sql.= " AND c.type = ".$this->type;
$sql.= " AND c.fk_parent = ".$this->fk_parent;
$sql.= " AND c.label = '".$this->db->escape($this->label)."'";
dol_syslog(get_class($this)."::already_exists sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
@ -933,30 +777,12 @@ class Categorie
/**
* Retourne les categories de premier niveau (qui ne sont pas filles)
*
* @param int Type of category
* @return void
*/
function get_main_categories()
function get_main_categories($type=null)
{
$allcats = $this->get_all_categories();
$maincats = array ();
$filles = array ();
$sql = "SELECT fk_categorie_fille FROM ".MAIN_DB_PREFIX."categorie_association";
$res = $this->db->query($sql);
while ($res = $this->db->fetch_array($res))
{
$filles[] = $res['fk_categorie_fille'];
}
foreach ($allcats as $cat)
{
if (! in_array($cat->id, $filles))
{
$maincats[] = $cat;
}
}
return $maincats;
return $this->get_all_categories($type, true);
}
/**
@ -967,7 +793,7 @@ class Categorie
* @param string $url Url
* @return void
*/
function print_all_ways ($sep = " &gt;&gt; ", $url='')
function print_all_ways($sep = " &gt;&gt; ", $url='')
{
$ways = array ();
@ -998,10 +824,11 @@ class Categorie
* @param int $id Id of category
* @param string $type Type of category
* @return void
* @deprecated function not used ?
*/
function get_primary_way($id, $type="")
{
$primary_way = Array("taille"=>-1,"chemin"=>Array());
$primary_way = array("taille" => -1, "chemin" => array());
$meres = $this->containing($id,$type);
foreach ($meres as $mere)
{
@ -1026,10 +853,11 @@ class Categorie
* @param string $url Url
* @param string $type Type
* @return void
* @deprecated function not used ?
*/
function print_primary_way($id, $sep= " &gt;&gt; ", $url="", $type="")
{
$primary_way = Array();
$primary_way = array();
$way = $this->get_primary_way($id,$type);
$w = array();
foreach ($way as $cat)
@ -1054,10 +882,10 @@ class Categorie
*/
function get_meres()
{
$meres = array();
$parents = array();
$sql = "SELECT fk_categorie_mere FROM ".MAIN_DB_PREFIX."categorie_association ";
$sql .= "WHERE fk_categorie_fille = ".$this->id;
$sql = "SELECT fk_parent FROM ".MAIN_DB_PREFIX."categorie";
$sql.= " WHERE rowid = ".$this->id;
$res = $this->db->query($sql);
@ -1065,11 +893,14 @@ class Categorie
{
while ($rec = $this->db->fetch_array($res))
{
$cat = new Categorie($this->db);
$cat->fetch($rec['fk_categorie_mere']);
$meres[] = $cat;
if ($rec['fk_parent'] > 0)
{
$cat = new Categorie($this->db);
$cat->fetch($rec['fk_parent']);
$parents[] = $cat;
}
}
return $meres;
return $parents;
}
else
{
@ -1084,7 +915,7 @@ class Categorie
*
* @return void
*/
function get_all_ways ()
function get_all_ways()
{
$ways = array();
@ -1398,7 +1229,7 @@ class Categorie
// Initialise parametres
$this->id=0;
$this->id_mere=0;
$this->fk_parent=0;
$this->label = 'SPECIMEN';
$this->specimen=1;
$this->description = 'This is a description';

View File

@ -38,7 +38,7 @@ $socid=GETPOST('socid','int');
$nom=GETPOST('nom');
$description=GETPOST('description');
$visible=GETPOST('visible');
$catMere=GETPOST('catMere');
$parent=GETPOST('parent');
if ($id == "")
{
@ -66,20 +66,20 @@ if ($action == 'update' && $user->rights->categorie->creer)
$categorie->socid = ($socid ? $socid : 'null');
$categorie->visible = $visible;
if ($catMere != "-1")
$categorie->id_mere = $catMere;
if ($parent != "-1")
$categorie->fk_parent = $parent;
else
$categorie->id_mere = "";
$categorie->fk_parent = "";
if (! $categorie->label)
if (empty($categorie->label))
{
$_GET["action"] = 'create';
$action = 'create';
$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Label"));
}
if (! $categorie->description)
if (empty($categorie->description))
{
$_GET["action"] = 'create';
$action = 'create';
$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Description"));
}
if (empty($categorie->error))
@ -149,7 +149,7 @@ print '</td></tr>';
// Parent category
print '<tr><td>'.$langs->trans("In").'</td><td>';
print $form->select_all_categories($type,$object->id_mere,'catMere',64,$object->id);
print $form->select_all_categories($type,$object->fk_parent,'parent',64,$object->id);
print '</td></tr>';
print '</table>';

View File

@ -45,7 +45,7 @@ $socid=GETPOST('socid','int');
$nom=GETPOST('nom');
$description=GETPOST('description');
$visible=GETPOST('visible');
$catMere=GETPOST('catMere');
$parent=GETPOST('parent');
if ($origin)
{
@ -113,7 +113,7 @@ if ($action == 'add' && $user->rights->categorie->creer)
$object->visible = $visible;
$object->type = $type;
if ($catMere != "-1") $object->id_mere = $catMere;
if ($parent != "-1") $object->fk_parent = $parent;
if (! $object->label)
{
@ -222,7 +222,7 @@ if ($user->rights->categorie->creer)
// Parent category
print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
print $form->select_all_categories($type,$catorigin);
print $form->select_all_categories($type, $catorigin);
print '</td></tr>';
print '</table>';

View File

@ -154,13 +154,16 @@ print '</tr>';
// Define fullpathselected ( _x_y_z ) of $section parameter
$fullpathselected='';
foreach($fulltree as $key => $val)
if (! empty($section))
{
//print $val['id']."-".$section."<br>";
if ($val['id'] == $section)
foreach($fulltree as $key => $val)
{
$fullpathselected=$val['fullpath'];
break;
//print $val['id']."-".$section."<br>";
if ($val['id'] == $section)
{
$fullpathselected=$val['fullpath'];
break;
}
}
}
//print "fullpathselected=".$fullpathselected."<br>";
@ -169,7 +172,7 @@ foreach($fulltree as $key => $val)
$expandedsectionarray=array();
if (isset($_SESSION['dol_catexpandedsectionarray'.$type])) $expandedsectionarray=explode(',',$_SESSION['dol_catexpandedsectionarray'.$type]);
if ($section && $_GET['sectionexpand'] == 'true')
if (! empty($section) && $_GET['sectionexpand'] == 'true')
{
// We add all sections that are parent of opened section
$pathtosection=explode('_',$fullpathselected);
@ -182,7 +185,7 @@ if ($section && $_GET['sectionexpand'] == 'true')
}
$_SESSION['dol_catexpandedsectionarray'.$type]=join(',',$expandedsectionarray);
}
if ($section && $_GET['sectionexpand'] == 'false')
if (! empty($section) && $_GET['sectionexpand'] == 'false')
{
// We removed all expanded sections that are child of the closed section
$oldexpandedsectionarray=$expandedsectionarray;
@ -207,10 +210,7 @@ foreach($fulltree as $key => $val)
$showline=0;
// If directory is son of expanded directory, we show line
if (isset($val['id_mere']) && in_array($val['id_mere'],$expandedsectionarray)) $showline=4;
// If directory is brother of selected directory, we show line
// FIXME $ecmdirstatic not exist or not instantiate ?
//elseif (isset($val['id_mere']) && $val['id'] != $section && $val['id_mere'] == $ecmdirstatic->motherof[$section]) $showline=3;
if (isset($val['fk_parent']) && in_array($val['fk_parent'],$expandedsectionarray)) $showline=4;
// If directory is parent of selected directory or is selected directory, we show line
elseif (preg_match('/'.$val['fullpath'].'_/i',$fullpathselected.'_')) $showline=2;
// If we are level one we show line
@ -239,8 +239,6 @@ foreach($fulltree as $key => $val)
print '<td valign="top">';
//print $val['fullpath']."(".$showline.")";
$n='2';
// FIXME $b not define ?
//if ($b == 0 || ! in_array($val['id'],$expandedsectionarray)) $n='3';
if (! in_array($val['id'],$expandedsectionarray)) $n='3';
if (! in_array($val['id'],$expandedsectionarray)) $ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/plustop'.$n.'.gif','',1);
else $ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/minustop'.$n.'.gif','',1);
@ -269,7 +267,7 @@ foreach($fulltree as $key => $val)
// Description
print '<td>';
print dol_trunc($categstatic->get_desc($val['id']),48);
print dol_trunc($val['description'],48);
print '</td>';
// Link to category card

View File

@ -2133,22 +2133,20 @@ class Form
*
* @param int $type Type de categories (0=product, 1=supplier, 2=customer, 3=member)
* @param string $selected Id of category preselected
* @param string $select_name HTML field name
* @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.
* @return void
*/
function select_all_categories($type, $selected='', $select_name="", $maxlength=64, $excludeafterid=0)
function select_all_categories($type, $selected='', $htmlname="parent", $maxlength=64, $excludeafterid=0)
{
global $langs;
$langs->load("categories");
if ($select_name=="") $select_name="catMere";
$cat = new Categorie($this->db);
$cate_arbo = $cat->get_full_arbo($type,$excludeafterid);
$output = '<select class="flat" name="'.$select_name.'">';
$output = '<select class="flat" name="'.$htmlname.'">';
if (is_array($cate_arbo))
{
if (! count($cate_arbo)) $output.= '<option value="-1" disabled="disabled">'.$langs->trans("NoCategoriesDefined").'</option>';

View File

@ -764,4 +764,12 @@ ALTER TABLE llx_user ADD COLUMN job varchar(128) AFTER firstname;
ALTER TABLE llx_commande_fournisseurdet ADD COLUMN import_key varchar(14) AFTER info_bits;
ALTER TABLE llx_entrepot ADD COLUMN import_key varchar(14) AFTER fk_user_author;
ALTER TABLE llx_product_fournisseur_price ADD COLUMN import_key varchar(14) AFTER fk_user;
ALTER TABLE llx_product_stock ADD COLUMN import_key varchar(14) AFTER pmp;
ALTER TABLE llx_product_stock ADD COLUMN import_key varchar(14) AFTER pmp;
-- [ task #146 ] Remove table llx_categorie_association
ALTER TABLE llx_categorie DROP INDEX uk_categorie_ref;
ALTER TABLE llx_categorie ADD COLUMN fk_parent integer DEFAULT 0 NOT NULL AFTER rowid;
ALTER TABLE llx_categorie MODIFY COLUMN label varchar(255) NOT NULL;
ALTER TABLE llx_categorie ADD UNIQUE INDEX uk_categorie_ref (entity, fk_parent, label, type);
ALTER TABLE llx_categorie ADD INDEX idx_categorie_type (type);
ALTER TABLE llx_categorie ADD INDEX idx_categorie_label (label);

View File

@ -1,6 +1,6 @@
-- ============================================================================
-- Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
-- Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2009-2012 Regis Houssin <regis@dolibarr.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@ -17,6 +17,7 @@
--
-- ============================================================================
ALTER TABLE llx_categorie ADD UNIQUE INDEX uk_categorie_ref (label,type,entity);
ALTER TABLE llx_categorie ADD UNIQUE INDEX uk_categorie_ref (entity, fk_parent, label, type);
ALTER TABLE llx_categorie ADD INDEX idx_categorie_type (type);
ALTER TABLE llx_categorie ADD INDEX idx_categorie_label (label);

View File

@ -1,7 +1,7 @@
-- ============================================================================
-- Copyright (C) 2005 Brice Davoleau <e1davole@iu-vannes.fr>
-- Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
-- Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
-- Copyright (C) 2005 Brice Davoleau <e1davole@iu-vannes.fr>
-- Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
-- Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@ -21,13 +21,15 @@
create table llx_categorie
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
label varchar(255), -- category name
type tinyint DEFAULT 1 NOT NULL, -- category type (product, supplier, customer)
entity integer DEFAULT 1 NOT NULL, -- multi company id
description text, -- description of the category
fk_soc integer DEFAULT NULL, -- attribution of the category has a company (for product only)
visible tinyint DEFAULT 1 NOT NULL, -- determine if the products are visible or not
import_key varchar(14) -- Import key
entity integer DEFAULT 1 NOT NULL, -- multi company id
fk_parent integer DEFAULT 0 NOT NULL,
label varchar(255) NOT NULL, -- category name
type tinyint DEFAULT 1 NOT NULL, -- category type (product, supplier, customer)
description text, -- description of the category
fk_soc integer DEFAULT NULL, -- attribution of the category has a company (for product only)
visible tinyint DEFAULT 1 NOT NULL, -- determine if the products are visible or not
import_key varchar(14) -- Import key
)ENGINE=innodb;
--
@ -37,11 +39,3 @@ create table llx_categorie
-- 1 : supplier
-- 2 : customer
--
--
-- List of codes for the field entity
--
-- 1 : first company category type
-- 2 : second company category type
-- 3 : etc...
--

View File

@ -1,26 +0,0 @@
-- ============================================================================
-- Copyright (C) 2005 Brice Davoleau <e1davole@iu-vannes.fr>
-- Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
-- Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- ============================================================================
ALTER TABLE llx_categorie_association ADD UNIQUE INDEX uk_categorie_association (fk_categorie_mere, fk_categorie_fille);
ALTER TABLE llx_categorie_association ADD UNIQUE INDEX uk_categorie_association_fk_categorie_fille (fk_categorie_fille);
ALTER TABLE llx_categorie_association ADD CONSTRAINT fk_categorie_asso_fk_categorie_mere FOREIGN KEY (fk_categorie_mere) REFERENCES llx_categorie (rowid);
ALTER TABLE llx_categorie_association ADD CONSTRAINT fk_categorie_asso_fk_categorie_fille FOREIGN KEY (fk_categorie_fille) REFERENCES llx_categorie (rowid);

View File

@ -1,24 +0,0 @@
-- ============================================================================
-- Copyright (C) 2005 Brice Davoleau <e1davole@iu-vannes.fr>
-- Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- ============================================================================
create table llx_categorie_association
(
fk_categorie_mere integer NOT NULL,
fk_categorie_fille integer NOT NULL
)ENGINE=innodb;

View File

@ -319,6 +319,19 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action')))
migrate_reload_menu($db,$langs,$conf,$versionto);
}
// Script for VX (X<3.3) -> V3.3
$afterversionarray=explode('.','3.2.9');
$beforeversionarray=explode('.','3.3.9');
if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0)
{
migrate_categorie_association($db,$langs,$conf);
// Reload modules
migrate_reload_modules($db,$langs,$conf);
// Reload menus
migrate_reload_menu($db,$langs,$conf,$versionto);
}
print '<tr><td colspan="4"><br>'.$langs->trans("MigrationFinished").'</td></tr>';
@ -3352,6 +3365,98 @@ function migrate_mode_reglement($db,$langs,$conf)
print '</td></tr>';
}
/**
* Migrate categorie association
*
* @param DoliDB $db Database handler
* @param Translate $langs Object langs
* @param Conf $conf Object conf
* @return void
*/
function migrate_categorie_association($db,$langs,$conf)
{
print '<tr><td colspan="4">';
print '<br>';
print '<b>'.$langs->trans('MigrationCategorieAssociation')."</b><br>\n";
$error = 0;
if ($db->DDLInfoTable(MAIN_DB_PREFIX."categorie_association"))
{
dolibarr_install_syslog("upgrade2::migrate_categorie_association");
$db->begin();
$sqlSelect = "SELECT fk_categorie_mere, fk_categorie_fille";
$sqlSelect.= " FROM ".MAIN_DB_PREFIX."categorie_association";
$resql = $db->query($sqlSelect);
if ($resql)
{
$i = 0;
$num = $db->num_rows($resql);
if ($num)
{
while ($i < $num)
{
$obj = $db->fetch_object($resql);
$sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."categorie SET ";
$sqlUpdate.= "fk_parent = ".$obj->fk_categorie_mere;
$sqlUpdate.= " WHERE rowid = ".$obj->fk_categorie_fille;
$result=$db->query($sqlUpdate);
if (! $result)
{
$error++;
dol_print_error($db);
}
print ". ";
$i++;
}
}
else
{
print $langs->trans('AlreadyDone')."<br>\n";
}
if (! $error)
{
// TODO DROP table in the next release
/*
$sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX."categorie_association";
if ($db->query($sqlDrop))
{
$db->commit();
}
else
{
$db->rollback();
}
*/
$db->commit();
}
else
{
$db->rollback();
}
}
else
{
dol_print_error($db);
$db->rollback();
}
}
else
{
print $langs->trans('AlreadyDone')."<br>\n";
}
print '</td></tr>';
}
/**
* Migration directory