<?php
$admin = 'admin';
$root = 'superadmin';
if ($this->ion_auth->in_group($root) or $this->ion_auth->in_group($admin)) {
    echo "<li class='nav-header'>MENU ADMINISTRATOR</li>";
    $hal = $this->uri->segment(1);
    $menu = $this->db->get_where('menu', array('is_parent' => 0, 'is_active' => 1));
    foreach ($menu->result() as $m) {
        if ($hal == $m->link) {
            $status_link = 'active';
        } else {
            $status_link = '';
        }
        $submenu = $this->db->get_where('menu', array('is_parent' => $m->id, 'is_active' => 1));
        if ($submenu->num_rows() > 0) {
            $cek_parent = $this->db->get_where('menu', array('is_parent' => $m->id, 'is_active' => 1, 'link' => $hal));
            if ($cek_parent->num_rows() > 0) {
                $status_link = 'active';
            } else {
                $status_link = '';
            }
            echo "<li class='has-sub  " . " " . $status_link . "'>";
            echo "<a href='javascript:;'>";
            echo "<b class='caret'></b>";
            echo "<i class='" . $m->icon . "'></i>";
            echo "<span>" . strtoupper($m->name) . "</span>";
            echo "</a>";
            echo "<ul class='sub-menu'>";
            foreach ($submenu->result() as $s) {
                if ($hal == $s->link) {
                    $status_link = 'active';
                } else {
                    $status_link = '';
                }
                echo "<li class='" . $status_link . "'>";
                echo "<a href='" . base_url() . $s->link . "'>";
                echo "<span>" . strtoupper($s->name) . "</span>";
                echo "</a>";
                echo "</li>";
            }
            echo "</ul>";
            echo "</li>";
        } else {
            echo "<li class='" . $status_link . "'>";
            echo "<a href='" . base_url() . $m->link . "'>";
            echo "<i class='" . $m->icon . "'></i>";
            echo "<span>" . strtoupper($m->name) . "</span>";
            echo "</a>";
            echo "</li>";
        }
    }
} else {
    $where = '(id != 1 AND id != 3)';
    $qr = $this->db->get_where('groups', $where);
    foreach ($qr->result() as $gr) {
        $id_gr = $gr->id;
        echo "<li class='nav-header'>MENU " . strtoupper($gr->description) . "</li>";
        $hal = $this->uri->segment(1);
        $menu = $this->db->get_where('menu', array('is_parent' => 0, 'is_active' => $id_gr));
        foreach ($menu->result() as $m) {
            if ($hal == $m->link) {
                $status_link = 'active';
            } else {
                $status_link = '';
            }
            $submenu = $this->db->get_where('menu', array('is_parent' => $m->id, 'is_active' => $id_gr));
            if ($submenu->num_rows() > 0) {
                $cek_parent = $this->db->get_where('menu', array('is_parent' => $m->id, 'is_active' => $id_gr, 'link' => $hal));
                if ($cek_parent->num_rows() > 0) {
                    $status_link = 'active';
                } else {
                    $status_link = '';
                }
                echo "<li class='has-sub  " . " " . $status_link . "'>";
                echo "<a href='javascript:;'>";
                echo "<b class='caret'></b>";
                echo "<i class='" . $m->icon . "'></i>";
                echo "<span>" . strtoupper($m->name) . "</span>";
                echo "</a>";
                echo "<ul class='sub-menu'>";
                foreach ($submenu->result() as $s) {
                    if ($hal == $s->link) {
                        $status_link = 'active';
                    } else {
                        $status_link = '';
                    }
                    echo "<li class='" . $status_link . "'>";
                    echo "<a href='" . base_url() . $s->link . "'>";
                    echo "<span>" . strtoupper($s->name) . "</span>";
                    echo "</a>";
                    echo "</li>";
                }
                echo "</ul>";
                echo "</li>";
            } else {
                echo "<li class='" . $status_link . "'>";
                echo "<a href='" . base_url() . $m->link . "'>";
                echo "<i class='" . $m->icon . "'></i>";
                echo "<span>" . strtoupper($m->name) . "</span>";
                echo "</a>";
                echo "</li>";
            }
        }
    }
}
echo "<li><a href='javascript:;' class='sidebar-minify-btn' data-click='sidebar-minify'><i class='ion-ios-arrow-back'></i> <span>Collapse</span></a></li>";
