<!-- Left side column. contains the logo and sidebar -->
<aside class="main-sidebar" style="width:100%; height: 95px;">
<!-- sidebar: style can be found in sidebar.less -->
<section class="sidebar">
<!-- Sidebar user panel -->
<!-- sidebar menu: : style can be found in sidebar.less -->
<ul class="sidebar-menu">
<?php
if($_SESSION['master'] == 1){

$SelecionaMenus = Seleciona("menus", "WHERE liberado='sim'", "ORDER BY ordem ASC");
}else{
//VERIFICO MENUS DOS USUÁRIO
$SelecionaMenuUsuario = Seleciona("usuarios_programas", "WHERE idusuario='".$_SESSION['usuarioID']."' AND acao <> ''", "GROUP BY idmenu");
while($menu_usuario = mysql_fetch_array($SelecionaMenuUsuario)){
$IdMenuBd[] = $menu_usuario['idmenu'];
}
$IdsMenu = join(',',$IdMenuBd); 

$SelecionaMenus = Seleciona("menus", "WHERE idmenu IN ($IdsMenu) AND liberado='sim'", "ORDER BY ordem ASC");
}
while($menu = mysql_fetch_array($SelecionaMenus)){
?>
<li class="treeview" style="float:left; width: 145px;">
 <a href="<?php echo $DiretorioVirtual;?><?php echo $menu['url'];?>" style=" border-left:none;">
    <i class="fa fa-table"></i> <span style="font-size:12px;"><?php echo $menu['titulo'];?></span>
    <i class="fa fa-angle-left pull-right"></i>
  </a>
<?php 
//VERIRICA SE EXISTE PROGRAMAS
$SelecionaProgramaExiste = Seleciona("programas", "WHERE idmenu='".$menu['idmenu']."' AND liberado='sim'", "");
$TotalProgramas = mysql_num_rows($SelecionaProgramaExiste);
if($TotalProgramas > 0){
?>  
  <ul class="treeview-menu" style="float:left;">
<?php
if($_SESSION['master'] == 1){
$SelecionaProgramas = Seleciona("programas", "WHERE idmenu='".$menu['idmenu']."'  AND liberado='sim'", "ORDER BY titulo ASC");
}else{

//VERIFICO PROGRAMAS DOS USUÁRIO
$SelecionaProgramasUsuario = Seleciona("usuarios_programas", "WHERE idusuario='".$_SESSION['usuarioID']."' AND idmenu='".$menu['idmenu']."' AND acao <> ''", "");
while($programa_usuario = mysql_fetch_array($SelecionaProgramasUsuario)){
$IdProgramaBd[] = $programa_usuario['idprograma'];
}
$IdsPrograma = join(',',$IdProgramaBd); 
$SelecionaProgramas = Seleciona("programas", "WHERE idprograma IN ($IdsPrograma) AND idmenu='".$menu['idmenu']."'  AND liberado='sim'", "ORDER BY titulo ASC");
}

    
while($programas = mysql_fetch_array($SelecionaProgramas)){    
    
//VERIFICA SE USUÁRIO POSSUI ID PROGRAMA    

    $VerificaProgramaAtual = Seleciona("usuarios_programas", "WHERE idprograma='".$programas['idprograma']."' AND idusuario='".$_SESSION['usuarioID']."' AND acao <> ''", "") or die(mysql_error());
    $TotalProgramaAtual = mysql_num_rows($VerificaProgramaAtual);

    if($_SESSION['master'] == 1){
        $TotalProgramaAtual = 1;
    }    
    
    if($TotalProgramaAtual > 0){
    
?>
    <li style="width:250px; height:40px; padding-top:5px;" ><a href="<?php echo $DiretorioVirtual;?><?php echo $programas['url'];?>" target="<?php echo $programas['target'];?>"><i class="fa fa-circle-o"></i><span style="font-size:11px;"> <?php echo $programas['titulo'];?></span></a></li>
<?php } }?>              
  </ul>
<?php }?>  
</li>
<?php }?>
</ul>
</section>
<!-- /.sidebar -->
</aside>
<div class="menuresponsivo">
    <nav id="nav" role="navigation">
        <a href="#nav" title="Show navigation">Abrir Menu</a>
        <a href="#" title="Hide navigation">Fechar Menu</a>
        <ul>

<?php
if($_SESSION['master'] == 1){

$SelecionaMenus = Seleciona("menus", "WHERE liberado='sim'", "ORDER BY ordem ASC");
}else{
//VERIFICO MENUS DOS USUÁRIO
$SelecionaMenuUsuario = Seleciona("usuarios_programas", "WHERE idusuario='".$_SESSION['usuarioID']."' AND acao <> ''", "GROUP BY idmenu");
while($menu_usuario = mysql_fetch_array($SelecionaMenuUsuario)){
$IdMenuBd[] = $menu_usuario['idmenu'];
}
$IdsMenu = join(',',$IdMenuBd); 

$SelecionaMenus = Seleciona("menus", "WHERE idmenu IN ($IdsMenu) AND liberado='sim'", "ORDER BY ordem ASC");
}
while($menu = mysql_fetch_array($SelecionaMenus)){
?>            
            <li>
                <a href="#" aria-haspopup="true" style="color:white;"><?php echo $menu['titulo'];?></a>
<?php 
//VERIRICA SE EXISTE PROGRAMAS
$SelecionaProgramaExiste = Seleciona("programas", "WHERE idmenu='".$menu['idmenu']."' AND liberado='sim'", "");
$TotalProgramas = mysql_num_rows($SelecionaProgramaExiste);
if($TotalProgramas > 0){
?>                  
                <ul>
<?php
if($_SESSION['master'] == 1){
$SelecionaProgramas = Seleciona("programas", "WHERE idmenu='".$menu['idmenu']."'  AND liberado='sim'", "ORDER BY titulo ASC");
}else{

//VERIFICO PROGRAMAS DOS USUÁRIO
$SelecionaProgramasUsuario = Seleciona("usuarios_programas", "WHERE idusuario='".$_SESSION['usuarioID']."' AND idmenu='".$menu['idmenu']."' AND acao <> ''", "");
while($programa_usuario = mysql_fetch_array($SelecionaProgramasUsuario)){
$IdProgramaBd[] = $programa_usuario['idprograma'];
}
$IdsPrograma = join(',',$IdProgramaBd); 
$SelecionaProgramas = Seleciona("programas", "WHERE idprograma IN ($IdsPrograma) AND idmenu='".$menu['idmenu']."'  AND liberado='sim'", "ORDER BY titulo ASC");
}

    
while($programas = mysql_fetch_array($SelecionaProgramas)){    
    
//VERIFICA SE USUÁRIO POSSUI ID PROGRAMA    

    $VerificaProgramaAtual = Seleciona("usuarios_programas", "WHERE idprograma='".$programas['idprograma']."' AND idusuario='".$_SESSION['usuarioID']."' AND acao <> ''", "") or die(mysql_error());
    $TotalProgramaAtual = mysql_num_rows($VerificaProgramaAtual);

    if($_SESSION['master'] == 1){
        $TotalProgramaAtual = 1;
    }    
    
    if($TotalProgramaAtual > 0){
    
?>                   
                    <li><a href="<?php echo $DiretorioVirtual;?><?php echo $programas['url'];?>"><?php echo $programas['titulo'];?></a></li>
<?php } }?>                                        
                </ul>
<?php }?>                
            </li>
<?php }?>            
        </ul>
    </nav>
</div>