<?php
function currenturl($url, $echo)
{
  if (current_url() == base_url('admin/' . $url)) {
    echo $echo;
  }
}
?>
<aside class="main-sidebar sidebar-white-primary elevation-4">
  <!-- Brand Logo -->
  <?php $site = $this->db->get('site')->result(); ?>
  <a href="<?php echo base_url() ?>" class="brand-link text-center">
    <img src="<?php echo base_url('files/site/' . $site[0]->logo) ?>" alt="Logo" style="opacity: .8; width: 50px"><br>
    <span class="text-sm"><?php echo $site[0]->title ?></span>
  </a>

  <!-- Sidebar -->
  <div class="sidebar">

    <!-- Sidebar Menu -->
    <nav class="mt-2">
      <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">

        <!-- HOME -->
        <li class="nav-item">
          <a href="<?php echo base_url() ?>" class="nav-link">
            <i class="nav-icon fas fa-home"></i>
            <p>
              Beranda
            </p>
          </a>
        </li>

        <!-- USER MANAGEMENT -->
        <li class="nav-item has-treeview <?php currenturl('newuser', 'menu-open');
                                          currenturl('users', 'menu-open'); ?>">
          <a href="#" class="nav-link <?php currenturl('newuser', 'active');
                                      currenturl('users', 'active'); ?>">
            <i class="nav-icon fas fa-users"></i>
            <?php $query = "SELECT count(*) as total FROM user WHERE status=0";
            $row = $this->db->query($query)->result(); ?>
            <p>
              Manajemen Pengguna
            </p>
            <?php if ($row[0]->total == 0) {
            } else { ?>
              <span class="badge badge-primary">
                <?php echo $row[0]->total; ?>
              </span>
            <?php } ?>
          </a>
          <ul class="nav nav-treeview">
            <li class="nav-item <?php currenturl('newuser', 'active') ?>">
              <a href="<?php echo base_url('admin/newuser') ?>" class="nav-link <?php currenturl('newuser', 'active') ?>">
                <i class="nav-icon far fa-circle"></i>
                <p>
                  Pendaftar Baru &nbsp;&nbsp;&nbsp;
                  <?php if ($row[0]->total > 0) { ?>
                    <span class="badge badge-primary">
                      <?php echo $row[0]->total; ?>
                    </span>
                  <?php } ?>
                </p>
              </a>
            </li>
            <li class="nav-item <?php currenturl('users', 'active') ?>">
              <a href="<?php echo base_url('admin/users') ?>" class="nav-link <?php currenturl('users', 'active') ?>">
                <i class="nav-icon far fa-circle"></i>
                <p>
                  Kelola Data User
                </p>
              </a>
            </li>
          </ul>
        </li>

        <!-- LOANS MANAGEMENT -->
        <li class="nav-item has-treeview <?php currenturl('request', 'menu-open');
                                          currenturl('jadwal', 'menu-open'); ?>">
          <a href="#" class="nav-link <?php currenturl('request', 'active');
                                      currenturl('jadwal', 'active'); ?>">
            <i class="nav-icon fas fa-bookmark"></i>
            <?php
            $query2 = "SELECT count(*) as total FROM peminjaman WHERE status_peminjaman=0";
            $row2 = $this->db->query($query2)->result(); ?>
            <p>
              Kelola Peminjaman
            </p>
            <?php if ($row2[0]->total == 0) {
            } else { ?>
              <span class="badge badge-primary">
                <?php echo $row2[0]->total; ?>
              </span>
            <?php } ?>
          </a>
          <ul class="nav nav-treeview">
            <?php
            $query2 = "SELECT count(*) as total FROM peminjaman WHERE status_peminjaman=0";
            $row2 = $this->db->query($query2)->result(); ?>
            <li class="nav-item <?php currenturl('request', 'active'); ?>">
              <a href="<?php echo base_url('admin/request') ?>" class="nav-link <?php currenturl('request', 'active'); ?>">
                <i class="nav-icon far fa-circle"></i>
                <p>
                  Peminjaman &nbsp;&nbsp;&nbsp;
                  <?php if ($row2[0]->total > 0) { ?>
                    <span class="badge badge-primary">
                      <?php echo $row2[0]->total; ?>
                    </span>
                  <?php } ?>
                </p>
              </a>
            </li>
            <li class="nav-item <?php currenturl('jadwal', 'active') ?>">
              <a href="<?php echo base_url('admin/jadwal') ?>" class="nav-link <?php currenturl('jadwal', 'active') ?>">
                <i class="nav-icon far fa-circle"></i>
                <p>
                  Jadwal
                </p>
              </a>
            </li>
          </ul>
        </li>

        <!-- LOANS Inventaris -->
        <li class="nav-item has-treeview <?php currenturl('inventaris', 'menu-open');
                                          currenturl('kelola inventaris', 'menu-open'); ?>">
          <a href="#" class="nav-link <?php currenturl('inventaris', 'active');
                                      currenturl('inventaris', 'active'); ?>">
            <i class="nav-icon fas fa-bookmark"></i>
            <?php
            $query3 = "SELECT count(*) as total FROM inventaris WHERE id_inv";
            $row3 = $this->db->query($query3)->result(); ?>
            <p>
              Kelola Inventaris
            </p>
            
          </a>
          <ul class="nav nav-treeview">
            <?php
            $query3 = "SELECT count(*) as total FROM inventaris WHERE id_inv";
            $row3 = $this->db->query($query3)->result(); ?>
            <li class="nav-item <?php currenturl('inventaris', 'active'); ?>">
              <a href="<?php echo base_url('inventaris') ?>" class="nav-link <?php currenturl('inventaris', 'active'); ?>">
                <i class="nav-icon far fa-circle"></i>
                <p>
                  Inventaris &nbsp;&nbsp;&nbsp;
                  <?php if ($row3[0]->total > 0) { ?>
                    <span class="badge badge-primary">
                      <?php echo $row3[0]->total; ?>
                    </span>
                  <?php } ?>
                </p>
              </a>
            </li>
            <?php
            $query4 = "SELECT count(*) as total FROM pinjam_inv WHERE id_pinjam";
            $row4 = $this->db->query($query4)->result(); ?>
            <li class="nav-item <?php currenturl('inventaris', 'active') ?>">
              <a href="<?php echo base_url('inventaris/peminjaman_inv') ?>" class="nav-link <?php currenturl('inventaris', 'active') ?>">
                <i class="nav-icon far fa-circle"></i>
                <p>
                  Peminjaman Inventaris &nbsp;&nbsp;&nbsp;
                  <?php if ($row4[0]->total > 0) { ?>
                    <span class="badge badge-primary">
                      <?php echo $row4[0]->total; ?>
                    </span>
                  <?php } ?>
                </p>
              </a>
            </li>
            <?php
            $query5 = "SELECT count(*) as total FROM pengembalian_inv WHERE id_pengembalian";
            $row5 = $this->db->query($query5)->result(); ?>
            <li class="nav-item <?php currenturl('inventaris', 'active') ?>">
              <a href="<?php echo base_url('inventaris/pengembalian_inv') ?>" class="nav-link <?php currenturl('inventaris', 'active') ?>">
                <i class="nav-icon far fa-circle"></i>
                <p>
                  pengembalian Inventaris &nbsp;&nbsp;&nbsp;
                  <?php if ($row5[0]->total > 0) { ?>
                    <span class="badge badge-primary">
                      <?php echo $row5[0]->total; ?>
                    </span>
                  <?php } ?>
                </p>
              </a>
            </li>
          </ul>
        </li>


        <!-- REPORT -->
        <li class="nav-item has-treeview <?php currenturl('laporan', 'menu-open');
                                          currenturl('laporan', 'menu-open'); ?>">
          <a href="#" class="nav-link <?php currenturl('request', 'active');
           currenturl('jadwalreport', 'active'); ?>">
            <i class="nav-icon fas fa-file-pdf"></i>
            <p>
              Laporan
            </p>
          </a>
          <ul class="nav nav-treeview">
            <li class="nav-item <?php currenturl('laporan', 'active') ?>">
              <a href="<?php echo base_url('admin/jadwalreport') ?>" class="nav-link <?php currenturl('laporan', 'active') ?>">
                <i class="nav-icon far fa-circle"></i>
                <p>
                  Laporan Jadwal
                </p>
              </a>
            </li>
            <li class="nav-item <?php currenturl('laporan', 'active') ?>">
              <a href="<?php echo base_url('inventaris/laporaninventaris') ?>" class="nav-link <?php currenturl('laporan inv', 'active') ?>">
                <i class="nav-icon far fa-circle"></i>
                <p>
                  Laporan inventaris Rusak
                </p>
              </a>
            </li>
            <li class="nav-item <?php currenturl('laporan', 'active') ?>">
              <a href="<?php echo base_url('inventaris/laporanpinjam') ?>" class="nav-link <?php currenturl('laporan inv', 'active') ?>">
                <i class="nav-icon far fa-circle"></i>
                <p>
                  Laporan Peminjaman Inventaris
                </p>
              </a>
            </li>
          </ul>
        </li>
        
        <!-- HELP -->
        <li class="nav-item <?php currenturl('help', 'active'); ?>">
          <a href="<?php echo base_url('admin/help') ?>" class="nav-link <?php currenturl('help', 'active'); ?>">
            <i class="nav-icon fas fa-question"></i>
            <?php $query3 = $this->db->query('SELECT count(*) AS total FROM ask')->result(); ?>
            <p>
              Bantuan
            </p>
            <?php if ($query3[0]->total == 0) {
            } else { ?>
              <span class="badge badge-primary">
                <?php echo $query3[0]->total; ?>
              </span>
            <?php } ?>
          </a>
        </li>

        <!-- SETTING -->
        <li class="nav-item has-treeview <?php currenturl('myprofile/' . $this->session->userdata('id_user'), 'menu-open'); ?>">

          <ul class="nav nav-treeview">
            <li class="nav-item <?php currenturl('myprofile/' . $this->session->userdata('id_user'), 'active'); ?>">

            </li>
            <li class="nav-item <?php currenturl('sitesetting', 'active'); ?>">\
            
            </li>
          </ul>
        </li>
      </ul>
    </nav>
    <!-- /.sidebar-menu -->
  </div>
  <!-- /.sidebar -->
</aside>