<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Weblib {

    var $base_url;

    function __construct() {
        $this->CI = & get_instance();
        $this->CI->load->database('default', true);
        $this->base_url = base_url();
    }

    function load_admin_menu() {
        $this->CI->load->database('default', true);
        $this->CI->db->select('*');
        $this->CI->db->from('admin_menu_lte');
        $this->CI->db->where('parent', null);
        $this->CI->db->where('status', '1');
        return $this->CI->db->get()->result();
    }

    function load_admin_submenu() {
        $this->CI->load->database('default', true);
        $main_menu = $this->CI->uri->segment('2');
        $this->CI->db->select('*');
        $this->CI->db->from('admin_menu_lte');
        $this->CI->db->where('address', $main_menu);
        $this->CI->db->where('status', '1');
        $result = $this->CI->db->get()->result();
        if (!empty($result)) {
            foreach ($result as $row) {
                $id_main_menu = $row->menuid;
            }
            $this->CI->db->select('*');
            $this->CI->db->from('admin_menu_lte');
            $this->CI->db->where('parent', $id_main_menu);
            $this->CI->db->where('status', '1');
            return $this->CI->db->get()->result();
        } else {
            return null;
        }
    }

    function superadmin_menu() {
        $this->CI->load->database('default', true);
        $username = $this->CI->session->userdata('username');
        $password = $this->CI->session->userdata('password');

        $this->CI->db->select('username, password, realname');
        $this->CI->db->from('user');
        $this->CI->db->where('username', $username);
        $this->CI->db->where('password', $password);
        $this->CI->db->where('access_level', '1');
        $query = $this->CI->db->get();

        if ($query->num_rows() == 1) {
            return TRUE;
        } else {
            return FALSE;
        }
    }

    function admin_menu() {
        $this->CI->load->database('default', true);
        $username = $this->CI->session->userdata('username');
        $password = $this->CI->session->userdata('password');

        $this->CI->db->select('username, password, realname');
        $this->CI->db->from('user');
        $this->CI->db->where('username', $username);
        $this->CI->db->where('password', $password);
        $this->CI->db->where('access_level', '2');
        $query = $this->CI->db->get();

        if ($query->num_rows() == 1) {
            return TRUE;
        } else {
            return FALSE;
        }
    }

}

?>
