<?php
//include './veriflog.php'; 


$isAdmin = $dba->checkAdminUser($_SESSION['ownerId']);




//$res = $dba->getAllModules();   ## Old Module fonction
//$res = $dba->getModulesByUserRole($_SESSION['ownerId']) ;

$mbuilder = $dba->BuildHeaderMenu($_SESSION['ownerId']);

$applist = "";

//var_dump( $dba );


/*
  for ($i = 0; $i < count($res); $i++) {
  $applist .='<li><a href="leftmenu_builder.php?mid='.$res[$i]['module_id_n'].'" class="svm-menu-item" >'.$res[$i]['module_name_v']." ".$res[$i]['version_v'].'</a></li>' ;
  }
 */
/*
  for ($i = 0; $i < count($res); $i++) {
  $applist .='<li><a href="#" onclick="getPage(\\\'leftmenu_builder.php?moduleId='.$res[$i]['module_id_n'].'\\\', \\\'sidebar\\\');">'.$res[$i]['module_name_v']." ".$res[$i]['version_v'].'</a></li>' ;
  }
 * 
 * 
 */
?>

<header class="main-header">

    <a href="main.php" class="logo">
        <!--  mini logo for sidebar mini 50x50 pixels 
         <span class="logo-mini"><b>A</b>LT</span>-->
        <!-- logo for regular state and mobile devices -->
        <span class="logo-lg"><img src="images/logo.png"   /></span> 
    </a>

    <!-- Header Navbar -->

    <nav class="navbar navbar-static-top">

        <div class="navbar-svm-custom-menu"> 

            <ul class="nav navbar-nav">

<?php
$mcnt = 0;
for ($jp = 0; $jp < count($mbuilder); $jp++) {
    $applist[$mcnt]['menuData'] = "";

    if ($mbuilder[$jp]['totalMenu'] == 1) {

        $menuData = $dba->getMenuBuilderItemByLevel($mbuilder[$jp]['level_id_n']);
       // print_r($menuData);
        ?>

                        <li ><a onclick="getPage('<?php echo $menuData['page_link_v']; ?>','content-wrapper')"  href="#" ></i><h4 style="color:#FFFFFF"><?php echo $mbuilder[$jp]['menu_name_v']; ?></h4></a></li>


                        <?php
                    } elseif ($mbuilder[$jp]['totalMenu'] > 1) {
                        
                       echo "########### MENU = ".$mcnt." #############";
                        $appres = $dba->getModulesByHeaderId($mbuilder[$jp]['level_id_n'],$_SESSION['ownerId'] );
                        $applist[$mcnt]['menuId'] = $mbuilder[$jp]['level_id_n'];
                        for ($i = 0; $i < count($appres); $i++) {

                            $applist[$mcnt]['menuData'] .= '<li><a href="#" onclick="getPage(\\\'leftmenu_builder.php?moduleId=' . $appres[$i]['module_id_n'] . '\\\', \\\'sidebar\\\');">' . $appres[$i]['module_name_v'] . " " . $appres[$i]['version_v'] . '</a></li>';
                        }
                        
                        
                        ?>


                        <li class="dropdown user user-menu"> 
                            <a href="#" id="appId<?php echo $mbuilder[$jp]['level_id_n']; ?>">
                                <span class="hidden-xs"><h4 style="color:#FFFFFF"><?php echo $mbuilder[$jp]['menu_name_v']; ?></h4></span> 
                            </a>


                        </li>




        <?php
          $mcnt++;
      
    }
    
   // print_r($applist);
}
?> 




            </ul>
        </div>


        <div class="navbar-custom-menu">
            <ul class="nav navbar-nav">
                <!-- Orders -->

                <!-- Messages -->
             
                <!-- Notifications -->
             
                <!-- Tasks -->


                <!-- user -->
                <li class="dropdown dropdown-user">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <img src="assets/dist/img/avatar5.png" class="img-circle" width="45" height="45" alt="user"></a>
                    <ul class="dropdown-menu" >
                         <li>
                            <a href="#" onclick="getPage('myprofile.php','content-wrapper')" >
                                <i class="fa fa-user"></i> Mon Profile</a>
                        </li>
                      
                        <li><a href="logout.php">
                                <i class="fa fa-sign-out"></i> Deconnexion </a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </nav>
</header>


