1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
<html>
<head>
<script type="text/javascript">
<!--
function showmenu(menu) {
if (menu.style.display == 'none') menu.style.display = 'block';
else menu.style.display = 'none';
}
//-->
</script>
</head>
<body>
<?php
$cat[0] = array("id" => 1, "parent" => 0, "nom" => "Informatique_racine");
$cat[1] = array("id" => 2, "parent" => 1, "nom" => "ss-info");
$cat[2] = array("id" => 3, "parent" => 1, "nom" => "Internet/Messagerie");
$cat[3] = array("id" => 4, "parent" => 3, "nom" => "FTP");
$cat[4] = array("id" => 5, "parent" => 3, "nom" => "Acces WIFI client");
$cat[5] = array("id" => 6, "parent" => 2, "nom" => "test");
$cat[6] = array("id" => 7, "parent" => 0, "nom" => "test-racine");
function afficher_menu($parent, $niveau, $array) {
$html = "";
$niveau_precedent = 0;
if (!$niveau && !$niveau_precedent)
$html .= "\n<ul>\n";
foreach ($array AS $noeud)
{
if ($parent == $noeud['parent']) {
if ($niveau_precedent < $niveau)
$html .= "\n<ul>\n";
$html .= "<li><a href=\"?categorie=" . $noeud['id'] . "\">" . $noeud['nom'] . "</a>";
$niveau_precedent = $niveau;
$html .= afficher_menu($noeud['id'], ($niveau + 1), $array);
}
}
if (($niveau_precedent == $niveau) && ($niveau_precedent != 0)) $html .= "</ul>\n</li>\n";
else if ($niveau_precedent == $niveau)
$html .= "</ul>\n";
else $html .= "</li>\n";
return $html;
}
echo afficher_menu(0, 0, $cat);
?>
</body>
</html> |
Partager