Problème sur menu arborescent dynamique php

Fermé
jpcreation - 12 févr. 2014 à 15:36
Bonjour,

voici mon problème. Dans le code ci-dessous l'arborescence fonctionne très bien à un détail près :

les entrées de niveaux 0 sont bien en place, si je clique cela déroule bien le premier niveau enfant mais si je clique sur ce dernier cela referme le menu au lieu de m'afficher le niveau enfant suivant.

Merci par avance à ceux qui pourront m'aider.



function construit_menu_arborescent_cat(&$sortie_cat, &$selectionne_cat, $parent_cat=0, $indent_cat=-1)
{
global $wwwroot, $catid;
$indent_cat +=1;
if(is_array($catid)) $catid=0;
// Recherche de tous les noeuds ayant $parent comme noeud parent
$qid = mysql_query("SELECT id, parent_id, nb, nom_".$_SESSION['langue']." FROM peel_categories WHERE parent_id = $parent_cat AND etat = '1' ORDER BY position");
// Si la requete a abouti
if($qid){
// Pour toutes les entrées
while($cat = mysql_fetch_array($qid)){
// Boucle pour ajouter l'indentation (une image vide)
// Pour aller plus loin on peut gérer des lignes de suite
for($i=0;$i<$indent_cat;$i++){
$sortie_cat .= "<img src='$wwwroot/images/mnu_empty.gif' border=0>";
}
// Recherche d'enfant pour déterminer l'aspect de l'icone (feuille ou dossier)
$fils_cat = mysql_query("SELECT id, parent_id, nom_".$_SESSION['langue']." FROM peel_categories WHERE parent_id = ".$cat['id']." AND etat = '1' ORDER BY position");
$div_cat = mysql_num_rows($fils_cat);
// Si il y a des enfants
if ($div_cat) {
// Ajout de l'icone du dossier
$sortie_cat .= "<img src='$wwwroot/images/menplus.gif' border=0> ";
// Ajout du lien (identique à construit menu)
$sortie_cat .= "<a class=menuleft href=$wwwroot/achat/index.php?catid=" . $cat['id'] .">";
// Test si le noeud est le noeud actif (id), si oui, ajoute du gras (plus visuel)
if($cat['id']==$catid) $sortie_cat .= "<b>";
// Ajoute le nom de la catégorie et débute un calque DIV ayant pour ID l'Id de la catégorie
$sortie_cat .= html_entity_decode($cat['nom_'.$_SESSION['langue'].'']);

$nb = calcul_nbprod_parcat($cat['id']);

if (!empty($nb)) {$sortie_cat .= " (".$nb.") "; }

$sortie_cat .= "</a></b><br /><DIV id=".$cat['id'];
// Recherche si le noeud fait partie de l'arborescence du noeud actif
parent_noeud_cat($cat['id'], $catid, $actif_cat=0);
// Si Oui,
if(($cat['id'] == $catid) || ($actif_cat == 1)){
// Rends le calque visible
$sortie_cat.= " style=\"display:yes\">\n";
}
else{
// Sinon, rends le calque invisible
$sortie_cat.= " style=\"display:none\">\n";
}
}
// Sinon, c'est un document
else{
// Ajoute l'image du document
$sortie_cat .= "<img src='$wwwroot/images/menminus.gif' border=0> ";
// Ajoute le lien (identique à construit_menu)
$sortie_cat .= "<a class=menuleft href=$wwwroot/achat/index.php?catid=" . $cat['id'] .">";
// Si c'est la feuille active, la met en gras
if($cat['id']==$catid) $sortie_cat .= "<b>";
// Ajoute le nom
$sortie_cat .= html_entity_decode($cat['nom_'.$_SESSION['langue'].'']);

$nb = calcul_nbprod_parcat($cat['id']);

if (!empty($nb)) {$sortie_cat .= " (".$nb.") "; }

$sortie_cat .= "</a></b><br />";
}
// Si c'est un noeud (catégorie)
if($div_cat){
// Appel récursif pour ajout des enfants
construit_menu_arborescent_cat($sortie_cat, $selectionne_cat, $cat['id'], $indent_cat);
// Ferme le calque
$sortie_cat.="</div>";
}
}
}
}

A voir également: