<?php
    $user_id=$_SESSION['user'];
    $username=$_SESSION['user_name'];
    $branch_id=$_SESSION['branch_id'];
    $ho_access=$_SESSION['ha'];
?>
<aside id="left-panel" class="left-panel">
    <nav class="navbar navbar-expand-sm navbar-default">
		<div id="main-menu" class="main-menu collapse navbar-collapse">
			<ul class="nav navbar-nav">
				<li class="active">
					<a href="<?php echo URL; ?>"><i class="menu-icon fa fa-laptop"></i>Dashboard </a>
				</li>
				<!-- /.menu-title -->
				<?php
	            $manu=mysqli_query($con ,"select distinct m.id,m.menu_name,m.m_class from role_detail d join menu_master m on m.id=d.menu_id join role_mapping rm on rm.code=d.code join user_master u on u.user_id=rm.user_id where rm.user_id='$user_id' and d.view_only<>'' and rm.status=0 order by m.id");
                while($main_manu=mysqli_fetch_array($manu))
                {
                $subid=$main_manu['id'];
                ?>
	            <li class="menu-item-has-children dropdown">
	                <a   href="#" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <i class="<?php echo $main_manu['m_class'] ; ?>"></i>&nbsp<?php echo $main_manu['menu_name'] ;?> </a>
	                <ul class="sub-menu  dropdown-menu">           
            		<?php
            		if($ho_access=='yes')
            		{
            		    $where = "where rm.user_id='$user_id' and m.id='$subid' and d.view_only<>'' and rm.status=0 order by s.submenu_order";
            		}
            		else
            		{
            		    $where = "where rm.user_id='$user_id' and m.id='$subid' and d.view_only<>'' and rm.status=0 and s.id!=39 order by s.submenu_order";
            		
            		}
            		$submenu_master=mysqli_query($con ,"select distinct s.id,s.submenu_code,s.submenu_class,s.submenu_url,s.submenu_order from role_detail d join menu_master m on m.id=d.menu_id join submenu_master s on s.id=d.submenu_id join role_mapping rm on rm.code=d.code join user_master u on u.user_id=rm.user_id $where");
                	while($submenu=mysqli_fetch_array($submenu_master))
                	{ 
                	?>
                		<li>
                			<i class="<?php echo $submenu['submenu_class'] ; ?>"></i>
                			<a href="<?php echo URL; ?><?php echo $submenu['submenu_url']; ?>"><?php echo $submenu['submenu_code'] ;?></a>
                		</li>
                		<?php  }  ?>
                	</ul>
            	</li>
				<!-- /.menu-title -->
                <?php } ?>
			</ul>
		</div><!-- /.navbar-collapse -->
    </nav>
</aside>