<aside class="main-sidebar">
    <section class="sidebar">
    <!-- and previlege_parent_id=391 -->
      <?php
      $sel_ut_privileg_parent="select distinct(previlege_parent_id) from add_admin_previleges where ut_id='".$_SESSION['ut_id']."' and status='active' and view_status='show' ";
      $ptr_ut_privileg_parent= mysql_query($sel_ut_privileg_parent);
      $tot=mysql_num_rows($ptr_ut_privileg_parent);
      $it=1;
      $prev_parent_id=array();
      $t=0;
      while($data_ut_privileg_parent=mysql_fetch_array($ptr_ut_privileg_parent))
      {
          $prev_parent_id[$t]= $data_ut_privileg_parent['previlege_parent_id'];
          $t++;
      }                                         
      $sel_admin_privileg_parentt="select distinct(previlege_parent_id) from admin_previleges where admin_id='".$_SESSION['admin_id']."' and status='active' and view_status='show'   ";
      $ptr_admin_privileg_parent=mysql_query($sel_admin_privileg_parentt);
      $d=$t;
      while($fetch_admin_privileg_admin=mysql_fetch_array($ptr_admin_privileg_parent))
      {      
          $prev_parent_id[$d]= $fetch_admin_privileg_admin['previlege_parent_id'];
          $d++;   
      }
      array_multisort($prev_parent_id, SORT_ASC,SORT_NUMERIC);
      $array_previ_parent=array_values(array_unique($prev_parent_id));

	    $sel_staff="select * from site_setting where admin_id='".$_SESSION['admin_id']."'";
	    $ptr_staff=mysql_query( $sel_staff);
	    $data_staff=mysql_fetch_array($ptr_staff);
	    ?>
      <div class="user-panel">
        <div class="pull-left image">
          <img src="../faculty_login/staff_photo/<?php echo $data_staff['photo']; ?>" class="img-circle" alt="User Image">
        </div>
        <div class="pull-left info">
          <p><?php echo ucwords($data_staff['name']);?></p>
          <a href="#"><i class="fa fa-circle text-success"></i> <?php echo ucwords($data_staff['status']); ?></a>
        </div>
      </div>
      <ul class="sidebar-menu" data-widget="tree">
        <?php
        if($_SESSION['type'] =='S' || $_SESSION['admin_id']=='283') 
        {
          "<br/>".$sel_parent="select previlege_name,privilege_id from previleges where 1 and status='active' and view_status='show' and privilege_type='tms' and privilege_parent_id=0 ORDER BY seq_no DESC";
          $ptr_parent=mysql_query($sel_parent);
          while($data_parent=mysql_fetch_array($ptr_parent))
          {
            ?>
            <!-- <li class=" treeview active"> -->
            <li class=" treeview">
              <a href="#">
                <span><?php echo Ucwords($data_parent['previlege_name']) ?></span>
                <span class="pull-right-container">
                  <i class="fa fa-angle-left pull-right"></i>
                </span>
              </a>
              <ul class="treeview-menu">
                <?php
                "<br/>".$sel_pri_parent="select * from previleges where 1 and status='active' and view_status='show' and privilege_type='tms' and privilege_parent_id='".$data_parent['privilege_id']."'  ORDER BY seq_no ASC";
                $ptr_pri_parent=mysql_query($sel_pri_parent);
                while($data_pri_parent=mysql_fetch_array($ptr_pri_parent))
                {
                  ?>
                  <li><a href="<?php echo $data_pri_parent['page_link']?>" ><img src="images/<?php echo $data_pri_parent['icon'];?>" width="23px" ; height="23px"; style="border-radius: 10px;"/>&nbsp;&nbsp;<?php echo $data_pri_parent['title']?></a></li>
                <?php
                }
                ?>
              </ul>
            </li>
            <?php
          }
        }
        else
        {
          for($e = 0; $e < count($array_previ_parent); $e++) 
          {       
            $sel_pri_parent = "SELECT * FROM previleges WHERE privilege_parent_id = 0 AND privilege_id = '".$array_previ_parent[$e]."' AND status = 'active' AND view_status = 'show' AND privilege_type = 'tms' ORDER BY seq_no ASC";
            $ptr_pri_parent = mysql_query($sel_pri_parent);
            if ($tot_prev = mysql_num_rows($ptr_pri_parent)) 
            {
                $data_pri_parent = mysql_fetch_array($ptr_pri_parent);
                ?>
                <li class="treeview">
                    <a href="#">
                        <span><?php echo ucwords($data_pri_parent['title']); ?></span>
                        <span class="pull-right-container">
                            <i class="fa fa-angle-left pull-right"></i>
                        </span>
                    </a>
                    <ul class="treeview-menu">
                        <?php
                        $sel_ut_privileg = "SELECT privilege_id FROM add_admin_previleges WHERE ut_id = '".$_SESSION['ut_id']."' AND previlege_parent_id = '".$array_previ_parent[$e]."' ORDER BY seq_no ASC";
                        $ptr_ut_privileg = mysql_query($sel_ut_privileg);
                        $tot = mysql_num_rows($ptr_ut_privileg);
                        $prev_id = [];
                        $s = 0;
                        while ($data_ut_privileg = mysql_fetch_array($ptr_ut_privileg)) {
                            $prev_id[$s] = $data_ut_privileg['privilege_id'];
                            $s++;
                        }
                        $sel_admin_privileg = "SELECT privilege_id FROM admin_previleges WHERE admin_id = '".$_SESSION['admin_id']."' AND previlege_parent_id = '".$array_previ_parent[$e]."' ORDER BY seq_no ASC";
                        $ptr_admin_privileg = mysql_query($sel_admin_privileg);
                        $p = $s;
                        while ($fetch_admin_privileg = mysql_fetch_array($ptr_admin_privileg)) {
                            $prev_id[$p] = $fetch_admin_privileg['privilege_id'];
                            $p++;   
                        }
                        for ($f = 0; $f < count($prev_id); $f++) 
                        {
                            $sel_pri_id = "SELECT * FROM previleges WHERE privilege_id = '".$prev_id[$f]."' AND privilege_parent_id = '".$array_previ_parent[$e]."' AND sub_privilege_id = '0' AND status = 'active' AND view_status = 'show' AND privilege_type = 'tms' ORDER BY seq_no ASC";
                            $ptr_pri_ids = mysql_query($sel_pri_id);
        
                            while ($data_pri_id = mysql_fetch_array($ptr_pri_ids)) 
                            {
                                ?>
                                <li>
                                    <a href="<?php echo $data_pri_id['page_link']; ?>">
                                        <img src="images/<?php echo $data_pri_id['icon']; ?>" width="23px" height="23px" style="border-radius: 10px;"/>
                                        &nbsp;&nbsp;<?php echo $data_pri_id['title']; ?>
                                    </a>
                                </li>
                                <?php
                            }
                        }
                        ?>
                    </ul>
                </li>
                <?php
            }
          }
        }
        ?>
        <li class="treeview">
          <a href="#">
            <i class="fa fa-user"></i> <span>Ticket System</span>
            <span class="pull-right-container">
              <i class="fa fa-angle-left pull-right"></i>
            </span>
          </a>
          <ul class="treeview-menu">
            <li><a href="ts_dashboard.php" target=""><i class="fa fa-list"></i>Dashboard</a></li>
            <li><a href="ts_add_ticket.php" target=""><i class="fa fa-list"></i>Add Ticket</a></li>
            <?php
            if($_SESSION['type']=='S')
            {
              ?>
              <li><a href="ts_ticket_report.php" target=""><i class="fa fa-list"></i>Ticket Report</a></li>
              <?php
            }
            ?>
          </ul>
        </li>
        <li><a href="my_account.php"><i class="fa fa-circle-o text-aqua"></i> <span>Profile</span></a></li>
      </ul>
    </section>
  </aside>

