Fix: Debuggage fonction categorie et recriture de certaines fonctions:

Code plus simple, avec moins de requete. Une dizaine de fonctions remplaces par une seule nomme 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

File diff suppressed because it is too large Load Diff

View File

@ -36,9 +36,9 @@ if (!$user->rights->categorie->lire) accessforbidden();
* Affichage page accueil
*/
llxHeader("","",$langs->trans("Categories"));
llxHeader("","",$langs->trans("ProductsCategoriesArea"));
$html = new Form($db);
print_fiche_titre($langs->trans("CategoriesArea"));
print_fiche_titre($langs->trans("ProductsCategoriesArea"));
print '<table border="0" width="100%" class="notopnoleftnoright">';
@ -93,35 +93,105 @@ if($_POST['catname'])
print "</table>";
}
/*
* Catégories principales
*/
print '<table class="noborder" width="100%">';
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))
{
$var=true;
foreach($cate_arbo as $key => $value)
{
$var = ! $var;
print "\t<tr ".$bc[$var].">\n";
print '<td><a href="viewcat.php?id='.$value[1].'">'.$value[0].'</a></td>';
print "\t</td>\n";
print '<td>'.$c->get_desc($value[1]).'</td>';
print "\t</td>\n";
print "\t</tr>\n";
}
}
print "</table>";
print '</td></tr></table>';
print '<br>';
// Charge tableau des categories
$cate_arbo = $c->get_full_arbo();
/*
* 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 '<tr class="liste_titre"><td>'.$langs->trans("AllCats").'</td><td>'.$langs->trans("Desc").'</td></tr>';
if (is_array($cate_arbo))
{
$var=true;
foreach($cate_arbo as $key => $value)
{
$var = ! $var;
print "\t<tr ".$bc[$var].">\n";
print '<td><a href="viewcat.php?id='.$cate_arbo[$key]['id'].'">'.$cate_arbo[$key]['fulllabel'].'</a></td>';
print '<td>'.$c->get_desc($cate_arbo[$key]['id']).'</td>';
print "\t</td>\n";
print "\t</tr>\n";
}
}
print "</table>";
}
$db->close();
llxFooter('$Date$ - $Revision$');

View File

@ -1190,31 +1190,37 @@ class Form
}
}
/**
* \brief Retourne la ou les listes déroulante des catégories en fonction du nombre choisi
* \param selected nombre de catégorie à créer
/**
* \brief Retourne la ou les listes déroulante des catégories en fonction
* du nombre choisi
* \param selected nombre de catégorie à créer
*/
function select_all_categories($selected='',$select_name="")
{
global $langs;
$langs->load("categorie");
if($select_name=="")
$select_name="catMere";
if ($select_name=="") $select_name="catMere";
$cat = new Categorie ($this -> db);
$cat->get_categories_arbo();
$cate_arbo = $cat->get_arbo_each_cate();
$output = '<select name="'.$select_name.'">'; //creation des categories meres
$cate_arbo = $cat->get_full_arbo();
$output = '<select name="'.$select_name.'">';
$output.= '<option value="-1" id="choix">&nbsp;</option>';
if ($cate_arbo)
{
foreach($cate_arbo as $key => $value)
{
if($value[1] == $selected)
if ($cate_arbo[$key]['fulllabel'] == $selected)
{
$add = "selected='true' ";
}
else
{
$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_NO_FOREIGN_KEY_TO_DROP',
'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))
{
@ -208,8 +209,8 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade")
}
else
{
print '<tr><td valign="top">'.$langs->trans("Request").' '.($i+1).'</td>';
print '<td valign="top">'.$langs->trans("Error")." ".$db->errno()." ".$sql."<br>".$db->error()."</td>";
print '<tr><td valign="top" colspan="2">';
print '<div class="error">'.$langs->trans("Error")." ".$db->errno().": ".$sql."<br>".$db->error()."</font></td>";
print '</tr>';
dolibarr_install_syslog($langs->trans("Request").' '.($i+1)." ".$langs->trans("Error")." ".$db->errno()." ".$sql."<br>".$db->error());
$error++;
@ -234,7 +235,7 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade")
else
{
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;
}
}

View File

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

View File

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

View File

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

View File

@ -36,12 +36,47 @@ require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.php");
$langs->load("categories");
$mesg = '';
if (!$user->rights->produit->lire) accessforbidden();
$types[0] = $langs->trans("Product");
$types[1] = $langs->trans("Service");
$mesg = '';
/*
* 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
@ -54,6 +89,8 @@ if ($_GET["id"] || $_GET["ref"])
llxHeader("","",$langs->trans("CardProduct".$product->type));
}
$html = new Form($db);
@ -62,24 +99,6 @@ $html = new Form($db);
*/
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);
$titre=$langs->trans("CardProduct".$product->type);
dolibarr_fiche_head($head, 'category', $titre);
@ -189,7 +208,6 @@ if ($_GET["id"] || $_GET["ref"])
print "</td>";
print "</tr>\n";
}
}

View File

@ -793,11 +793,11 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
// Propals
if($user->rights->propale->creer)
if($conf->propal->enabled && $user->rights->propale->creer)
{
$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>';
if ($user->rights->commercial->client->voir)
@ -807,7 +807,7 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
}
else
{
print '<td width="50%" valign="top"></td>';
print '<td width="50%" valign="top">&nbsp;</td>';
}
print '</tr>';
@ -907,11 +907,11 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
// Commande
if($user->rights->commande->creer)
if($conf->commande->enabled && $user->rights->commande->creer)
{
$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>';
if ($user->rights->commercial->client->voir)
@ -1016,11 +1016,11 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
}
// Factures
if($user->rights->facture->creer)
if($conf->facture->enabled && $user->rights->facture->creer)
{
$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"));
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;
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_product (fk_product);
ALTER TABLE llx_categorie_product ADD 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_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);