<style>
.admin_userinfo{color: #fff;}
</style>
<?php
	$menu_modules = unserialize($this->request->session()->read('modules'));
	$user_permissions = $this->request->session()->read('user_permissions');
	$username = $this->request->session()->read('Auth.User.username');
	$img_path = $this->request->session()->read('Auth.User.img_path');
	$profile_picture = (empty($img_path)) ? $this->request->webroot."media/companies/default.jpg" : $this->request->webroot.$img_path;
?>
<!-- Left side column. contains the logo and sidebar -->
<aside class="main-sidebar">
    <!-- sidebar: style can be found in sidebar.less -->
    <section class="sidebar">
      <!-- Sidebar user panel -->
      <div class="user-panel">
        <div class="pull-left image">
          <img src="<?php echo $profile_picture;?>" class="img-circle" alt="User Image">
        </div>
        <div class="pull-left info">
          <p class="admin_userinfo"><?php echo $username; ?></p>
          <a href="#"><i class="fa fa-circle text-success"></i> Online</a>
        </div>
      </div>

      <!-- sidebar menu: : style can be found in sidebar.less -->
      <?php
      $access_module=array();
      foreach($user_permissions as $row){
      if(!in_array($row['module_id'],$access_module))
      $access_module[]=$row['module_id'];
      }
      $access_submodule=array();
      foreach($user_permissions as $row){
      if(!in_array($row['submodule_id'],$access_submodule))
      $access_submodule[]=$row['submodule_id'];
      }
      $request_controller=strtolower($this->request->params['controller']);
      
      ?>

      <ul class="sidebar-menu">
      <?php foreach($menu_modules as $module){
        if(in_array($module['id'],$access_module)){   
           $icon='<i class="fa fa-codepen" aria-hidden="true"></i>';
           if($module['icon']!=""){
           $icon=$module['icon'];
           }
      ?>
      <?php
       $submodule_controller_arr=array();
        foreach($module['sub_modules'] as $submodule ){
        $submodule_controller_arr[]= strtolower($submodule['controller_name']);
        }
       ?>
     <li class=" treeview <?php echo in_array( $request_controller,$submodule_controller_arr)?'active':'' ?>" >
          <a href="">
         <?php echo  $icon.'<span>'. __($module['name']).'</span>' ?><i class="fa fa-angle-left pull-right"></i>
          </a>
                                   
          <ul class="treeview-menu">
           <?php foreach($module['sub_modules'] as $submodule ){ 
         
           if(in_array($submodule['id'],$access_submodule) && $submodule['id'] != DEPLOYMENT_SUBMODULE_ID){
           $sub_icon='<i class="fa fa-circle-o"></i>';
           if($submodule['icon']!=""){
           $sub_icon=$submodule['icon'];
           }
            
           ?>
            <li class="<?php echo strtolower($submodule['controller_name'])==$request_controller?'active':'' ?>"><a href="<?php  echo $this->Url->build(["controller" =>$submodule['controller_name'] ,"action" => "index"]); ?>"><?php echo $sub_icon; echo __($submodule['name']); ?></a> </li> 
             
          <?php }else if($submodule['id'] == DEPLOYMENT_SUBMODULE_ID && in_array($_SESSION['Auth']['User']['id'], AUTH_ID_FOR_DEPLOYMENT)){
         ?>
            <li class="<?php echo strtolower($submodule['controller_name'])==$request_controller?'active':'' ?>"><a href="<?php  echo $this->Url->build("/Deployment/"); ?>"><?php echo $sub_icon; echo __($submodule['name']); ?></a> </li> 
        <?php    
          }
          } 
          ?>
          </ul>
        </li>
        <?php 
        }
        } ?>
        
      </ul>



<?php if(!empty($allForms)): ?>
    <ul class="sidebar-menu">
        <?php foreach ($allForms as $key => $category) : ?>
            <li class="treeview ">
                <a href="">
                    <i class="fa fa-list-ul"></i><span><?php echo substr($category['sub_category_name'], 0,20).'...'; ?></span><i class="fa fa-angle-left pull-right"></i>
                </a>
                
                <?php if(!empty($category['forms'])): ?>
                    <ul class="treeview-menu menu-open">
                        <?php foreach ($category['forms'] as $key => $form) : ?>
                            <li class=""><a href="<?php echo $base_url; ?>dashboard/form/<?php echo $form['form_id']; ?>"><i class="fa  fa-angle-double-right"></i><?php echo substr($form['form_long_name'], 0,20).'...'; ?></a></li> 
                        <?php endforeach; ?>
                    </ul>
                <?php endif; ?>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>


    </section>
    <!-- /.sidebar -->
</aside>