<?php

$menuid=isset($_GET['menuid']) ? $_GET['menuid'] : NULL;
$usermenu="";
$qpm="SELECT * 
						FROM $db_parent_menus 
						ORDER BY parentmenuid ASC
						";
$rpm=mysqli_query($dbConnection, $qpm);
while ($dpm=mysqli_fetch_array($rpm))
{ $usersubmenu="";
		if ($_SESSION['SES_GROUPID']!='1')
		{ $qq="SELECT a.appmenuid,
																b.appmenuname,
																b.appmenulink
									FROM $db_appauthorizations a, 
														$db_appmenus b
									WHERE a.appgroupid='".$_SESSION['SES_GROUPID']."'
															AND b.appmenuid=a.appmenuid
															AND b.parentid='".$dpm['parentmenuid']."'
									ORDER BY b.appmenuid ASC";
				}
		else
		{ $qq="SELECT appmenuid, 
																appmenuname,
																appmenulink
									FROM $db_appmenus
									WHERE parentid='".$dpm['parentmenuid']."'
									ORDER BY appmenuid ASC
									";
				}		
		$rr=mysqli_query($dbConnection, $qq);
		if (mysqli_num_rows($rr)>0)
		{ $usersubmenu="<ul class='submenu'>";
				while($data=mysqli_fetch_array($rr))
				{ if ($data['appmenuid']==$menuid)
						{ $usersubmenu.="<li><a href='".$data['appmenulink']."?menuid=".$data['appmenuid']."' style='color:#ff0000'>".$data['appmenuname']."</a></li>";
								}
						else
						{ $usersubmenu.="<li><a href='".$data['appmenulink']."?menuid=".$data['appmenuid']."'>".$data['appmenuname']."</a></li>";
								}
						}
				$usersubmenu.="</ul>";
				}
		if ($usersubmenu!="")
		{ $usermenu.="<h3 class='headerbar'>".$dpm['parentmenuname']."</h3>".$usersubmenu;
				}
		}		

$highlight0="";
$highlight1="";
$highlight2="";
if ($menuid==0)
{ $highlight0=" style='color:#849dab'";
		$highlight1="";
		$highlight2="";
		}
else if ($menuid==1)
{ $highlight1=" style='color:#849dab'";
		$highlight0="";
		$highlight2="";
		}
else if ($menuid==2)
{ $highlight2=" style='color:#849dab'";
		$highlight0="";
		$highlight1="";
		}

$webmenu="<div class='menuhead'>
											<h3 class='headerbar'>Halaman Utama</h3>
											<ul class='submenu'>
												<li>
													<a href='index.php?menuid=0'".$highlight0."><img src='images/dashboard.png' style='padding:0; margin:0; padding-right:8px; margin-bottom:3px; vertical-align:middle'>Dashboard</a>
												</li>
											</ul>	
											<h3 class='headerbar'>Akun</h3>
											<ul class='submenu'>
												<!--
												<li>
													<a href='changeemail.php?menuid=1'".$highlight1."><img src='images/email.png' style='padding:0; margin:0; padding-right:8px; margin-bottom:3px; vertical-align:middle'>Ubah E-mail</a>
												</li>
												-->
												<li>
													<a href='changepassword.php?menuid=2'".$highlight2."><img src='images/password.png' style='padding:0; margin:0; padding-right:8px; margin-bottom:3px; vertical-align:middle'>Change Password</a>
												</li>
												<li>
													<a href='logout.php'><img src='images/logout.png' style='padding:0; margin:0; padding-right:8px; margin-bottom:3px; vertical-align:middle'>Logout</a>
												</li>
											</ul>														
											".$usermenu."
										</div>
										";

?>