Fix: Debuggage fonction categorie et réecriture de certaines fonctions:

Code plus simple, avec moins de requete. Une dizaine de fonctions remplacées par une seule nommée get_full_arbo().
This commit is contained in:
Laurent Destailleur 2006-08-15 17:33:56 +00:00
parent 6e46ed4e31
commit b1a0de9797
11 changed files with 1003 additions and 902 deletions

View File

@ -3,6 +3,7 @@
* Copyright (C) 2005 Davoleau Brice <brice.davoleau@gmail.com> * Copyright (C) 2005 Davoleau Brice <brice.davoleau@gmail.com>
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> * Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006 Regis Houssin <regis.houssin@cap-networks.com> * Copyright (C) 2006 Regis Houssin <regis.houssin@cap-networks.com>
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -20,7 +21,6 @@
* *
* $Id$ * $Id$
* $Source$ * $Source$
*
*/ */
require_once(DOL_DOCUMENT_ROOT."/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php");
@ -35,6 +35,12 @@ class Categorie
var $description; var $description;
var $statut; var $statut;
var $cats=array(); // Tableau en memoire des categories
var $motherof = array(); // Tableau des correspondances id_fille -> id_mere
var $error;
/** /**
* Constructeur * Constructeur
* db : accès base de données * db : accès base de données
@ -111,7 +117,7 @@ class Categorie
} }
$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label, description, visible) "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label, description, visible) ";
$sql .= "VALUES ('".str_replace("'","''",$this->label)."', '".str_replace("'","''",$this->description)."', '".$this->visible."')"; $sql .= "VALUES ('".addslashes($this->label)."', '".addslashes($this->description)."', '".$this->visible."')";
$res = $this->db->query ($sql); $res = $this->db->query ($sql);
@ -176,11 +182,11 @@ class Categorie
} }
} }
$sql = "UPDATE ".MAIN_DB_PREFIX."categorie"; $sql = "UPDATE ".MAIN_DB_PREFIX."categorie";
$sql.= " SET label = '".trim(str_replace("'","''",$this->label))."'"; $sql.= " SET label = '".trim(addslashes($this->label))."'";
if (strlen (trim($this->description)) > 0) if (strlen (trim($this->description)) > 0)
{ {
$sql .= ", description = '".trim(str_replace("'","''",$this->description))."'"; $sql .= ", description = '".trim(addslashes($this->description))."'";
} }
$sql .= ", visible = '".$this->visible."'"; $sql .= ", visible = '".$this->visible."'";
@ -287,7 +293,7 @@ class Categorie
} }
else else
{ {
dolibarr_print_error($this->db); $this->error=$this->db->error().' sql='.$sql;
return -1; return -1;
} }
} }
@ -296,7 +302,7 @@ class Categorie
* Ajout d'un produit à la catégorie * Ajout d'un produit à la catégorie
* retour : 1 : OK * retour : 1 : OK
* -1 : erreur SQL * -1 : erreur SQL
* -2 : id non renseigné * -2 : id non renseign
*/ */
function add_product($prod) function add_product($prod)
{ {
@ -314,7 +320,7 @@ class Categorie
} }
else else
{ {
dolibarr_print_error($this->db); $this->error=$this->db->error().' sql='.$sql;
return -1; return -1;
} }
} }
@ -337,7 +343,7 @@ class Categorie
} }
else else
{ {
dolibarr_print_error($this->db); $this->error=$this->db->error().' sql='.$sql;
return -1; return -1;
} }
} }
@ -365,7 +371,7 @@ class Categorie
} }
else else
{ {
dolibarr_print_error ($this->db); $this->error=$this->db->error().' sql='.$sql;
return -1; return -1;
} }
} }
@ -395,33 +401,8 @@ class Categorie
return -1; return -1;
} }
} }
/**
* Retourne les filles de la catégorie structurée pour l'arbo
*/
function get_filles_arbo ($id_mere)
{
$sql = "SELECT c.rowid, c.label as label,ca.fk_categorie_fille as id FROM ";
$sql .= MAIN_DB_PREFIX."categorie as c,".MAIN_DB_PREFIX."categorie_association as ca";
$sql .= " WHERE c.rowid = ca.fk_categorie_fille and ca.fk_categorie_mere = '".$id_mere."'";
$res = $this->db->query ($sql);
if ($res)
{
$cat = array();
while ($rec = $this->db->fetch_array ($res))
{
$cat[$rec['label']]= array(0=>$rec['id']);
foreach($this -> get_filles_arbo($rec['id']) as $kf=>$vf)
$cat[$rec['label']][$kf] = $vf;
}
return $cat;
}
else
{
dolibarr_print_error ($this->db);
return -1;
}
}
/** /**
* retourne la description d'une catégorie * retourne la description d'une catégorie
*/ */
@ -435,6 +416,7 @@ class Categorie
return ($n[0]); return ($n[0]);
} }
/** /**
* La catégorie $fille est-elle une fille de cette catégorie ? * La catégorie $fille est-elle une fille de cette catégorie ?
*/ */
@ -450,128 +432,30 @@ class Categorie
return ($n[0] > 0); return ($n[0] > 0);
} }
/** /**
* Retourne toutes les catégories qui n'ont pas d'enfants ;-) * \brief Reconstruit l'arborescence des catégories sous la forme d'un tableau
* Renvoi un tableau de tableau('id','id_mere',...) trié 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
* \return array Tableau de array
*/ */
function get_steriles_categories () function get_full_arbo()
{ {
$sql = "SELECT fk_categorie_mere,fk_categorie_fille FROM "; // Charge tableau des meres
$sql .= MAIN_DB_PREFIX."categorie_association"; $sql = "SELECT fk_categorie_mere as id_mere, fk_categorie_fille as id_fille";
$res = $this->db->query ($sql); $sql.= " FROM ".MAIN_DB_PREFIX."categorie_association";
$cats_sterile = array();
while ($record = $this->db->fetch_array ($res))
{
$cats_sterile[] = $record['fk_categorie_mere'];
$cats_sterile[] = $record['fk_categorie_fille'];
}
$sql = "SELECT rowid,label FROM ";
$sql .= MAIN_DB_PREFIX."categorie";
$res = $this->db->query ($sql);
if ($res)
{
$cats = array ();
while ($record = $this->db->fetch_array ($res))
{
if(! in_array($record['rowid'],$cats_sterile))
$cats[$record['label']] = array(0=>$record['rowid']);
}
return $cats;
}
else
{
dolibarr_print_error ($this->db);
return -1;
}
}
/**
* fonction récursive uniquement utilisée par get_arbo_each_cate
* Recompose l'arborescence des catégories
*/
function fetch_cate_arbo($cate,$compl_path="")
{
$this->res;
$this->mere_encours;
foreach($cate as $nom_mere => $desc_mere)
{
// on est dans une sous-catégorie
if(is_array($desc_mere))
$this->res[]= array($this->mere_encours.$compl_path." >> ".$nom_mere,$desc_mere[0]);
else if($nom_mere != "0")
$this->res[]= array($this->mere_encours.$compl_path." >> ".$nom_mere,$desc_mere);
if(sizeof($desc_mere) >1)
{
$this ->fetch_cate_arbo($desc_mere," >> ".$nom_mere);
}
}
}
/**
* reconstruit l'arborescence des catégorie sous la forme d'un tableau
*
*/
function get_arbo_each_cate()
{
if(is_array($this -> cates))
{
foreach($this -> cates as $nom_mere => $desc_mere)
{
$this->mere_encours = $nom_mere;
$this->res[]= array($nom_mere,$desc_mere[0]);
if(sizeof($desc_mere) >1)
$this ->fetch_cate_arbo($desc_mere);
}
sort($this->res);
}
return $this->res;
}
/**
* Retourne l'arborescence des catégories, id et nom
* sous la forme d'un tableau
*/
function get_categories_arbo ()
{
$cates_steriles = $this -> get_steriles_categories();
$meres = $this -> get_all_meres();
foreach($meres as $k=>$v)
{
foreach($this -> get_filles_arbo($v[0]) as $kf=>$vf)
$meres[$k][$kf] = $vf;
}
// on concatène tout ça
foreach($meres as $k=>$v)
{
$this -> cates[$k]=$v;
}
foreach($cates_steriles as $k=>$v)
{
// print "<br>xxxxxxxx".$k;
$this -> cates[$k]=$v;
}
}
/**
* Retourne toutes les catégories qui ont au moins 1 fille
*/
function get_all_meres()
{
$sql = "SELECT fk_categorie_fille as id FROM ";
$sql .= MAIN_DB_PREFIX."categorie_association";
$res = $this->db->query ($sql); $res = $this->db->query ($sql);
if ($res) if ($res)
{ {
$ids_fille = array (); while ($obj= $this->db->fetch_object($res))
while ($record = $this->db->fetch_array ($res))
{ {
$ids_fille[] = $record['id']; $this->motherof[$obj->id_fille]=$obj->id_mere;
} }
} }
else else
@ -580,27 +464,133 @@ function get_arbo_each_cate()
return -1; return -1;
} }
$sql = "SELECT c.label as label,c.rowid,ca.fk_categorie_mere as id FROM "; // Charge tableau des categories
$sql .= MAIN_DB_PREFIX."categorie_association as ca,"; $sql = "SELECT c.rowid, c.label as label, ca.fk_categorie_fille as rowid_fille";
$sql .= MAIN_DB_PREFIX."categorie as c"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie as c";
$sql .= " where c.rowid=ca.fk_categorie_mere"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_association as ca";
$sql.= " ON c.rowid=ca.fk_categorie_mere";
$sql.= " ORDER BY c.label, c.rowid";
$res = $this->db->query ($sql); $res = $this->db->query ($sql);
if ($res) if ($res)
{ {
$cats = array (); $cats = array ();
while ($record = $this->db->fetch_array ($res)) $i=0;
while ($obj = $this->db->fetch_object($res))
{ {
if(! in_array($record['id'],$ids_fille)) $this->cats[$obj->rowid]['id'] = $obj->rowid;
$cats[$record['label']] = array(0=>$record['id']); $this->cats[$obj->rowid]['id_mere'] = $this->motherof[$obj->rowid];
$this->cats[$obj->rowid]['label'] = $obj->label;
if ($obj->rowid_fille)
{
if (is_array($this->cats[$obj->rowid]['id_children']))
{
$newelempos=sizeof($this->cats[$obj->rowid]['id_children']);
//print "this->cats[$i]['id_children'] est deja un tableau de $newelem elements<br>";
$this->cats[$obj->rowid]['id_children'][$newelempos]=$obj->rowid_fille;
}
else
{
//print "this->cats[".$obj->rowid."]['id_children'] n'est pas encore un tableau<br>";
$this->cats[$obj->rowid]['id_children']=array($obj->rowid_fille);
}
}
$i++;
} }
return $cats;
} }
else else
{ {
dolibarr_print_error ($this->db); dolibarr_print_error ($this->db);
return -1; return -1;
} }
// On ajoute la propriete fullpath a tous les éléments
foreach($this->cats as $key => $val)
{
if (isset($motherof[$key])) continue;
$this->build_path_from_id_categ($key,0);
} }
$this->cats=$this->sabsi($this->cats,'fulllabel', 'asc', true, false);
//$this->debug_cats();
return $this->cats;
}
/**
* \brief Advanced sort array by second index function, which produces
* ascending (default) or descending output and uses optionally
* natural case insensitive sorting (which can be optionally case
* sensitive as well).
*/
function sabsi ($array, $index, $order='asc', $natsort, $case_sensitive)
{
if (is_array($array) && count($array)>0)
{
foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index];
if (!$natsort) ($order=='asc') ? asort($temp) : arsort($temp);
else
{
($case_sensitive) ? natsort($temp) : natcasesort($temp);
if($order!='asc') $temp=array_reverse($temp,TRUE);
}
foreach(array_keys($temp) as $key) (is_numeric($key))? $sorted[]=$array[$key] : $sorted[$key]=$array[$key];
return $sorted;
}
return $array;
}
/**
* \brief Calcule les propriétés fullpath et fulllabel d'une categorie
* du tableau this->cats et de toutes ces enfants
*/
function build_path_from_id_categ($id_categ,$protection=0)
{
// Defini fullpath
if (isset($this->cats[$id_categ]['id_mere']))
{
$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'];
}
else
{
$this->cats[$id_categ]['fullpath']='_'.$id_categ;
$this->cats[$id_categ]['fulllabel']=$this->cats[$id_categ]['label'];
}
// Traite ces enfants
$protection++;
if ($protection > 20) return; // On ne traite pas plus de 20 niveaux
if (! is_array($this->cats[$id_categ]['id_children'])) return;
foreach($this->cats[$id_categ]['id_children'] as $key => $val)
{
$this->build_path_from_id_categ($val,$protection);
}
return;
}
/**
* \brief Affiche contenu de $this->cats
*/
function debug_cats()
{
// Affiche $this->cats
foreach($this->cats as $key => $val)
{
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 ' fullpath: '.$this->cats[$key]['fullpath'];
print ' fulllabel: '.$this->cats[$key]['fulllabel'];
print "<br>\n";
}
}
/** /**
* Retourne toutes les catégories * Retourne toutes les catégories
*/ */
@ -627,16 +617,17 @@ function get_arbo_each_cate()
} }
} }
/** /**
* Retourne le nombre total de catégories * \brief Retourne le nombre total de catégories
* \return int Nombre de categories
*/ */
function get_nb_categories () function get_nb_categories ()
{ {
$sql = "SELECT count(rowid) FROM ".MAIN_DB_PREFIX."categorie"; $sql = "SELECT count(rowid)";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie";
$res = $this->db->query ($sql); $res = $this->db->query ($sql);
if ($res) if ($res)
{ {
$res = $this->db->fetch_array (); $res = $this->db->fetch_array($res);
return $res[0]; return $res[0];
} }
else else
@ -653,7 +644,7 @@ function get_arbo_each_cate()
{ {
$sql = "SELECT count(c.rowid)"; $sql = "SELECT count(c.rowid)";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_association as ca"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_association as ca";
$sql.= " WHERE c.label = '".str_replace("'","''",$this -> label)."'"; $sql.= " WHERE c.label = '".addslashes($this -> label)."'";
if($this -> id_mere != "") if($this -> id_mere != "")
{ {
$sql.= " AND c.rowid = ca.fk_categorie_fille"; $sql.= " AND c.rowid = ca.fk_categorie_fille";
@ -678,7 +669,7 @@ function get_arbo_each_cate()
} }
/** /**
* Retourne les catégories de premier niveau * \brief Retourne les catégories de premier niveau (qui ne sont pas filles)
*/ */
function get_main_categories () function get_main_categories ()
{ {

View File

@ -36,9 +36,9 @@ if (!$user->rights->categorie->lire) accessforbidden();
* Affichage page accueil * Affichage page accueil
*/ */
llxHeader("","",$langs->trans("Categories")); llxHeader("","",$langs->trans("ProductsCategoriesArea"));
$html = new Form($db); $html = new Form($db);
print_fiche_titre($langs->trans("CategoriesArea")); print_fiche_titre($langs->trans("ProductsCategoriesArea"));
print '<table border="0" width="100%" class="notopnoleftnoright">'; print '<table border="0" width="100%" class="notopnoleftnoright">';
@ -93,15 +93,87 @@ if($_POST['catname'])
print "</table>"; print "</table>";
} }
print '</td></tr></table>';
print '<br>';
// Charge tableau des categories
$cate_arbo = $c->get_full_arbo();
/* /*
* Catégories principales * Catégories en javascript
*/ */
/*
if ($conf->use_javascript)
{
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td>'.$langs->trans("AllCats").'</td></tr>';
print '<tr><td>';
require_once(DOL_DOCUMENT_ROOT.'/includes/treemenu/TreeMenu.php');
$menu = new HTML_TreeMenu();
$icon = 'folder.gif';
$expandedIcon = 'folder-expanded.gif';
// Création noeud racine
$node=array();
$currentnode=-1;
$node[$currentnode] = new HTML_TreeNode(
array('text' => $langs->trans("AllCats"), 'link' => '', 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => true)
//,array('onclick' => "alert('foo'); return false", 'onexpand' => "alert('Expanded')")
);
$node1 = new HTML_TreeNode(
array('text' => $langs->trans("AllCats"), 'link' => '', 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => true)
//,array('onclick' => "alert('foo'); return false", 'onexpand' => "alert('Expanded')")
);
// Ajoute id_mere sur tableau cate_arbo
foreach ($cate_arbo as $key => $val)
{
print 'x '.$cate_arbo[$key]['id'].' '.$cate_arbo[$key]['level'].' '.$cate_arbo[$key]['id_mere'].'<br>';
}
$node1->addItem(new HTML_TreeNode(array('text' => "Second level, item y", 'link' => $_SERVER["PHP_SELF"], 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
$node1_1 = $node1->addItem(new HTML_TreeNode(array('text' => "Second level", 'link' => $_SERVER["PHP_SELF"], 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
$node1_1_1 = $node1_1->addItem(new HTML_TreeNode(array('text' => "Third level", 'link' => $_SERVER["PHP_SELF"], 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
$node1_1_1_1 = $node1_1_1->addItem(new HTML_TreeNode(array('text' => "Fourth level", 'link' => $_SERVER["PHP_SELF"], 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
$node1_1_1_1->addItem(new HTML_TreeNode(array('text' => "Fifth level", 'link' => $_SERVER["PHP_SELF"], 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'cssClass' => 'treeMenuBold')));
$node1_1->addItem(new HTML_TreeNode(array('text' => "Third Level, item 2", 'link' => $_SERVER["PHP_SELF"], 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
$node1->addItem(new HTML_TreeNode(array('text' => "Second level, item 3", 'link' => $_SERVER["PHP_SELF"], 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
$menu->addItem($node1);
// Affiche arbre
print '<script src="'.DOL_URL_ROOT.'/includes/treemenu/TreeMenu.js" language="JavaScript" type="text/javascript"></script>';
$treeMenu = new HTML_TreeMenu_DHTML($menu, array('images' => DOL_URL_ROOT.'/includes/treemenu/images', 'defaultClass' => 'treeMenuDefault', false));
$treeMenu->printMenu();
//$listBox = new HTML_TreeMenu_Listbox($menu, array('linkTarget' => '_self'));
//$listBox->printMenu();
print '</td></tr>';
print "</table>";
print '<br>';
}
*/
/*
* Catégories principales en HTML pure
*/
if (1 == 1)
{
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td>'.$langs->trans("AllCats").'</td><td>'.$langs->trans("Desc").'</td></tr>'; print '<tr class="liste_titre"><td>'.$langs->trans("AllCats").'</td><td>'.$langs->trans("Desc").'</td></tr>';
$c->get_categories_arbo();
$cate_arbo = $c->get_arbo_each_cate();
if (is_array($cate_arbo)) if (is_array($cate_arbo))
{ {
$var=true; $var=true;
@ -109,19 +181,17 @@ if (is_array($cate_arbo))
{ {
$var = ! $var; $var = ! $var;
print "\t<tr ".$bc[$var].">\n"; print "\t<tr ".$bc[$var].">\n";
print '<td><a href="viewcat.php?id='.$value[1].'">'.$value[0].'</a></td>'; print '<td><a href="viewcat.php?id='.$cate_arbo[$key]['id'].'">'.$cate_arbo[$key]['fulllabel'].'</a></td>';
print "\t</td>\n"; print '<td>'.$c->get_desc($cate_arbo[$key]['id']).'</td>';
print '<td>'.$c->get_desc($value[1]).'</td>';
print "\t</td>\n"; print "\t</td>\n";
print "\t</tr>\n"; print "\t</tr>\n";
} }
} }
print "</table>"; print "</table>";
}
print '</td></tr></table>';
$db->close(); $db->close();
llxFooter('$Date$ - $Revision$'); llxFooter('$Date$ - $Revision$');

View File

@ -1191,30 +1191,36 @@ class Form
} }
/** /**
* \brief Retourne la ou les listes déroulante des catégories en fonction du nombre choisi * \brief Retourne la ou les listes déroulante des catégories en fonction
* du nombre choisi
* \param selected nombre de catégorie ŕ créer * \param selected nombre de catégorie ŕ créer
*/ */
function select_all_categories($selected='',$select_name="") function select_all_categories($selected='',$select_name="")
{ {
global $langs; global $langs;
$langs->load("categorie"); $langs->load("categorie");
if($select_name=="")
$select_name="catMere"; if ($select_name=="") $select_name="catMere";
$cat = new Categorie ($this -> db); $cat = new Categorie ($this -> db);
$cat->get_categories_arbo(); $cate_arbo = $cat->get_full_arbo();
$cate_arbo = $cat->get_arbo_each_cate();
$output = '<select name="'.$select_name.'">'; //creation des categories meres $output = '<select name="'.$select_name.'">';
$output.= '<option value="-1" id="choix">&nbsp;</option>'; $output.= '<option value="-1" id="choix">&nbsp;</option>';
if ($cate_arbo) if ($cate_arbo)
{ {
foreach($cate_arbo as $key => $value) foreach($cate_arbo as $key => $value)
{ {
if($value[1] == $selected) if ($cate_arbo[$key]['fulllabel'] == $selected)
{
$add = "selected='true' "; $add = "selected='true' ";
}
else else
{
$add = ""; $add = "";
$output.= '<option '.$add.'value="'.$value[1].'">'.$value[0].'</option>'; }
$output.= '<option '.$add.'value="'.$cate_arbo[$key]['id'].'">'.$cate_arbo[$key]['fulllabel'].'</option>';
} }
} }

View File

@ -200,7 +200,8 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade")
'DB_ERROR_NOSUCHFIELD', 'DB_ERROR_NOSUCHFIELD',
'DB_ERROR_NO_FOREIGN_KEY_TO_DROP', 'DB_ERROR_NO_FOREIGN_KEY_TO_DROP',
'DB_ERROR_CANNOT_CREATE', // Qd contrainte deja existante 'DB_ERROR_CANNOT_CREATE', // Qd contrainte deja existante
'DB_ERROR_CANT_DROP_PRIMARY_KEY' 'DB_ERROR_CANT_DROP_PRIMARY_KEY',
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS'
); );
if (in_array($errno,$okerror)) if (in_array($errno,$okerror))
{ {
@ -208,8 +209,8 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade")
} }
else else
{ {
print '<tr><td valign="top">'.$langs->trans("Request").' '.($i+1).'</td>'; print '<tr><td valign="top" colspan="2">';
print '<td valign="top">'.$langs->trans("Error")." ".$db->errno()." ".$sql."<br>".$db->error()."</td>"; print '<div class="error">'.$langs->trans("Error")." ".$db->errno().": ".$sql."<br>".$db->error()."</font></td>";
print '</tr>'; print '</tr>';
dolibarr_install_syslog($langs->trans("Request").' '.($i+1)." ".$langs->trans("Error")." ".$db->errno()." ".$sql."<br>".$db->error()); dolibarr_install_syslog($langs->trans("Request").' '.($i+1)." ".$langs->trans("Error")." ".$db->errno()." ".$sql."<br>".$db->error());
$error++; $error++;
@ -234,7 +235,7 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade")
else else
{ {
print '<tr><td>'.$langs->trans("ProcessMigrateScript").'</td>'; print '<tr><td>'.$langs->trans("ProcessMigrateScript").'</td>';
print '<td align="right"><div class="error">'.$langs->trans("KO").'</div></td></tr>'; print '<td align="right"><font class="error">'.$langs->trans("KO").'</font></td></tr>';
$ok = 0; $ok = 0;
} }
} }

View File

@ -7,6 +7,7 @@ In=Dans
AddIn=Ajouter dans AddIn=Ajouter dans
modify=modifier modify=modifier
CategoriesArea=Espace catégories CategoriesArea=Espace catégories
ProductsCategoriesArea=Espace catégories de produits et services
MainCats=Catégories principales MainCats=Catégories principales
SubCats=Sous-catégories SubCats=Sous-catégories
CatStatistics=Statistiques CatStatistics=Statistiques

View File

@ -77,6 +77,7 @@ class DoliDb
1061 => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS', 1061 => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
1062 => 'DB_ERROR_RECORD_ALREADY_EXISTS', 1062 => 'DB_ERROR_RECORD_ALREADY_EXISTS',
1064 => 'DB_ERROR_SYNTAX', 1064 => 'DB_ERROR_SYNTAX',
1068 => 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS',
1075 => 'DB_ERROR_CANT_DROP_PRIMARY_KEY', 1075 => 'DB_ERROR_CANT_DROP_PRIMARY_KEY',
1091 => 'DB_ERROR_NOSUCHFIELD', 1091 => 'DB_ERROR_NOSUCHFIELD',
1100 => 'DB_ERROR_NOT_LOCKED', 1100 => 'DB_ERROR_NOT_LOCKED',

View File

@ -76,6 +76,7 @@ class DoliDb
1061 => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS', 1061 => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
1062 => 'DB_ERROR_RECORD_ALREADY_EXISTS', 1062 => 'DB_ERROR_RECORD_ALREADY_EXISTS',
1064 => 'DB_ERROR_SYNTAX', 1064 => 'DB_ERROR_SYNTAX',
1068 => 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS',
1075 => 'DB_ERROR_CANT_DROP_PRIMARY_KEY', 1075 => 'DB_ERROR_CANT_DROP_PRIMARY_KEY',
1091 => 'DB_ERROR_NOSUCHFIELD', 1091 => 'DB_ERROR_NOSUCHFIELD',
1100 => 'DB_ERROR_NOT_LOCKED', 1100 => 'DB_ERROR_NOT_LOCKED',

View File

@ -36,12 +36,47 @@ require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.php");
$langs->load("categories"); $langs->load("categories");
$mesg = '';
if (!$user->rights->produit->lire) accessforbidden(); if (!$user->rights->produit->lire) accessforbidden();
$types[0] = $langs->trans("Product"); $mesg = '';
$types[1] = $langs->trans("Service");
/*
* Actions
*/
//on veut supprimer une catégorie
if ($_REQUEST["removecat"] && $user->rights->produit->creer)
{
$product = new Product($db);
if ($_REQUEST["ref"]) $result = $product->fetch('',$_REQUEST["ref"]);
if ($_REQUEST["id"]) $result = $product->fetch($_REQUEST["id"]);
$cat = new Categorie($db,$_REQUEST["removecat"]);
$result=$cat->del_product($product);
}
//on veut ajouter une catégorie
if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0 && $user->rights->produit->creer)
{
$product = new Product($db);
if ($_REQUEST["ref"]) $result = $product->fetch('',$_REQUEST["ref"]);
if ($_REQUEST["id"]) $result = $product->fetch($_REQUEST["id"]);
$cat = new Categorie($db,$_REQUEST["catMere"]);
$result=$cat->add_product($product);
if ($result >= 0)
{
$mesg='<div class="ok">'.$langs->trans("Added").'</div>';
}
else
{
$mesg='<div class="error">'.$langs->trans("Error").' '.$cat->error.'</div>';
}
}
/* /*
* Creation de l'objet produit correspondant à l'id * Creation de l'objet produit correspondant à l'id
@ -54,6 +89,8 @@ if ($_GET["id"] || $_GET["ref"])
llxHeader("","",$langs->trans("CardProduct".$product->type)); llxHeader("","",$langs->trans("CardProduct".$product->type));
} }
$html = new Form($db); $html = new Form($db);
@ -62,24 +99,6 @@ $html = new Form($db);
*/ */
if ($_GET["id"] || $_GET["ref"]) if ($_GET["id"] || $_GET["ref"])
{ {
//on veut supprimer une catégorie
if ($_REQUEST["removecat"] && $user->rights->produit->creer)
{
$cat = new Categorie($db,$_REQUEST["removecat"]);
$cat->del_product($product);
}
//on veut ajouter une catégorie
if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0 && $user->rights->produit->creer)
{
$cat = new Categorie($db,$_REQUEST["catMere"]);
$cat->add_product($product);
}
/*
* En mode visu
*/
$head=product_prepare_head($product); $head=product_prepare_head($product);
$titre=$langs->trans("CardProduct".$product->type); $titre=$langs->trans("CardProduct".$product->type);
dolibarr_fiche_head($head, 'category', $titre); dolibarr_fiche_head($head, 'category', $titre);
@ -189,7 +208,6 @@ if ($_GET["id"] || $_GET["ref"])
print "</td>"; print "</td>";
print "</tr>\n"; print "</tr>\n";
} }
} }

View File

@ -793,11 +793,11 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
// Propals // Propals
if($user->rights->propale->creer) if($conf->propal->enabled && $user->rights->propale->creer)
{ {
$langs->load("propal"); $langs->load("propal");
print '<tr><td width="50%" valign="top">'; print '<tr class="liste_titre"><td width="50%" valign="top">';
print_titre($langs->trans("AddToMyProposals")) . '</td>'; print_titre($langs->trans("AddToMyProposals")) . '</td>';
if ($user->rights->commercial->client->voir) if ($user->rights->commercial->client->voir)
@ -807,7 +807,7 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
} }
else else
{ {
print '<td width="50%" valign="top"></td>'; print '<td width="50%" valign="top">&nbsp;</td>';
} }
print '</tr>'; print '</tr>';
@ -907,11 +907,11 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
// Commande // Commande
if($user->rights->commande->creer) if($conf->commande->enabled && $user->rights->commande->creer)
{ {
$langs->load("orders"); $langs->load("orders");
print '<tr><td width="50%" valign="top">'; print '<tr class="liste_titre"><td width="50%" valign="top">';
print_titre($langs->trans("AddToMyOrders")) . '</td>'; print_titre($langs->trans("AddToMyOrders")) . '</td>';
if ($user->rights->commercial->client->voir) if ($user->rights->commercial->client->voir)
@ -1016,11 +1016,11 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
} }
// Factures // Factures
if($user->rights->facture->creer) if($conf->facture->enabled && $user->rights->facture->creer)
{ {
$langs->load("bills"); $langs->load("bills");
print '<tr><td width="50%" valign="top">'; print '<tr class="liste_titre"><td width="50%" valign="top">';
print_titre($langs->trans("AddToMyBills")); print_titre($langs->trans("AddToMyBills"));
if ($user->rights->commercial->client->voir) if ($user->rights->commercial->client->voir)

View File

@ -348,3 +348,15 @@ insert into llx_action_def (rowid,code,titre,description,objet_type) values (3,'
drop table if exists llx_sqltables; drop table if exists llx_sqltables;
ALTER IGNORE TABLE llx_categorie_product DROP FOREIGN KEY llx_categorie_product_ibfk_1;
ALTER IGNORE TABLE llx_categorie_product DROP FOREIGN KEY llx_categorie_product_ibfk_2;
ALTER IGNORE TABLE llx_categorie_product DROP FOREIGN KEY llx_categorie_product_ibfk_3;
ALTER IGNORE TABLE llx_categorie_product DROP FOREIGN KEY llx_categorie_product_ibfk_4;
ALTER IGNORE TABLE llx_categorie_product DROP FOREIGN KEY llx_categorie_product_ibfk_5;
ALTER TABLE llx_categorie_product ADD CONSTRAINT fk_categorie_product_categorie_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid);
ALTER TABLE llx_categorie_product ADD CONSTRAINT fk_categorie_product_product_rowid FOREIGN KEY (fk_product) REFERENCES llx_product (rowid);
ALTER TABLE llx_categorie_product ADD PRIMARY KEY (fk_categorie, fk_product);

View File

@ -19,9 +19,9 @@
-- --
-- ============================================================================ -- ============================================================================
ALTER TABLE llx_categorie_product ADD PRIMARY KEY (fk_categorie, fk_product);
ALTER TABLE llx_categorie_product ADD INDEX idx_categorie_product_fk_categorie (fk_categorie); ALTER TABLE llx_categorie_product ADD INDEX idx_categorie_product_fk_categorie (fk_categorie);
ALTER TABLE llx_categorie_product ADD INDEX idx_categorie_product_fk_product (fk_product); ALTER TABLE llx_categorie_product ADD INDEX idx_categorie_product_fk_product (fk_product);
ALTER TABLE llx_categorie_product ADD FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid); ALTER TABLE llx_categorie_product ADD CONSTRAINT fk_categorie_product_categorie_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid);
ALTER TABLE llx_categorie_product ADD FOREIGN KEY (fk_product) REFERENCES llx_product (rowid); ALTER TABLE llx_categorie_product ADD CONSTRAINT fk_categorie_product_product_rowid FOREIGN KEY (fk_product) REFERENCES llx_product (rowid);