pdo statements
Das Menü
Navigation
<div id="nav-menue">
<a title="Menü öffnen" class="menue-button menue-button-open" href="#nav-menue">=</a>
<a title="Menü schließen" class="menue-button menue-button-zu" href="#">?</a>
<div id="menu">
<ul class="liner">
= = &#8801; und ? = &#215;
<?php
Das Haupt-Menü
$parent_menu = array();
$sub_menu = array();
$items=$pdo->prepare("SELECT id,label,ziel,parent_id FROM test_menu ORDER BY parent_id,id ASC");
$items->execute();
while ($obj=$items->fetchObject())
{
if ($obj->parent_id == 0)
{
$parent_menu[$obj->id]['label']=$obj->label;
$parent_menu[$obj->id]['link']=$obj->ziel;
}
else
{
$sub_menu[$obj->id]['parent']=$obj->parent_id;
$sub_menu[$obj->id]['label']=$obj->label;
$sub_menu[$obj->id]['link']=$obj->ziel;
if (empty($parent_menu[$obj->parent_id]['count']))
{
$parent_menu[$obj->parent_id]['count']=0;
}
$parent_menu[$obj->parent_id]['count']++;
}
}
function test_menu($parent_array,$sub_array,$qs_val="pid")
{
$page=isset($_GET['page']) ? $_GET['page'] : '';
$menu = "";
foreach($parent_array as $pkey=>$pval)
{
if (!empty($pval['count']))
{
if (($page)==$pval["link"])
{
$menu.='<ul><li>'.$pval['label'].'</li></ul>';
}
else
$menu.='<ul><li>
<a href="index.php?page='.$pval['link'].'&'.$qs_val.'='.$pkey.'">'.$pval['label'].'</a>
</li></ul>';
}
else
{
if (($page) == $pval["link"])
{
$menu.='<li>'.$pval['label'].'</li>';
}
else
$menu.='<li><a href="index.php?page='.$pval['link'].'">'.$pval['label'].'</a></li>';
}
if (!empty($_REQUEST[$qs_val]))
{
$menu.='<ul>';
foreach($sub_array as $sval)
{
if ($pkey == $_REQUEST[$qs_val] && $pkey == $sval['parent'])
{
if (($page) == $sval["link"])
{
$menu.= '<li class="raus">'.$sval['label'].'</li>';
}
else
$menu.='<ul><li class="raus"><a href="index.php?page='.rebuild_link($sval['link'], $qs_val, $sval['parent']).'">'.$sval['label'].'</a></li></ul>';
}
}
$menu.='</ul>';
}
}
return $menu;
}
function rebuild_link($link, $parent_var, $parent_val)
{
$link_parts=explode("&", $link);
$base_var="&".$parent_var."=".$parent_val;
return $link_parts[0].$base_var;
}
echo test_menu($parent_menu, $sub_menu);
Das log_menu
if(!isset($_SESSION))
{
session_start();
}
if(!isset($_SESSION["loggedin"]))
{
$stmt=$pdo->prepare("SELECT labbel,ziele FROM log_menu");
$stmt->bindColumn(1,$labbel);
$stmt->bindColumn(2,$ziele);
$stmt->execute();
while($stmt->fetch())
{
if(($page)==$ziele)
{
echo'<ul><li class="menua">'.$labbel.'</li></ul>';
}
else
{
echo'<ul><li class="menud"><a href="index.php?page='.$ziele.'">'.$labbel.'</a></li></ul>';
}
}
echo'</ul>';
}
else
{
echo'<div id="user">';
echo'<div class="hallo">';
echo 'Hallo <span>'.htmlspecialchars($_SESSION["username"]).'</span>';
echo '</div>';
echo'<ul class="liner">';
if (isset($_SESSION["id"]) && $_SESSION["id"]==1)
{
if(($page)=="99")
{
echo'<li class="menua">Admin-Center</li>';
}
else
{
echo'<li class="menud"><a href="index.php?page=99">Admin-Center</a></li>';
}
}
if(isset($_SESSION['loggedin']))
{
if(($page)=="96")
{
echo'<li class="menua">Profil</li>';
}
else
{
echo'<li class="menud"><a href="index.php?page=96">Profil</a></li>';
}
if(($page)=="98")
{
echo'<li class="menua">Logout</li>';
}
else
{
echo'<li class="menud"><a href="index.php?page=98">Logout</a></li>';
}
}
echo'</ul>';
echo'</div>'; // Ende id=user
}
?>
</div> // Ende id=menu
</div> // Ende id=nav-menue
Top
Top