<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class Admin extends MX_Controller {

    public function index() {
        if (empty($this->rt_user->id_user)) {
            redirect(base_url($this->config->item('admin_page') . '/login'));
        } else {
            $this->load->library('ciext/admin_lib');
            if (!$this->rt_user->isAllowed('system', 'view_admin')) {
                $this->admin_lib->show_denied();
            }

            $this->ciext->load_bootstrap();
            $this->js_css->parse_js('ciext/dashboard/js/dashboard.js', array());
            $this->load->model('ciext/dashboard_model');

            $data = $this->dashboard_model->get_items(20);

            $content = array(
                'items' => $data,
                'message' => (empty($data)) ? '<div class="alert"><button type="button" class="close" data-dismiss="alert">&times;</button>' . $this->lang->line('no data found') . '</div>' : ''
            );
            
            // If development
            if (ENVIRONMENT == 'development') {
                $content['message'] = '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">&times;</button>' . $this->lang->line('Warning! Project is in development mode') . '</div>';
            }

            $this->admin_lib->show(array(
                'content' => $this->parser->parse('ciext/dashboard/dashboard', $content, TRUE),
                'title' => $this->lang->line('page_admin'),
            ));
        }
    }

    public function get_more() {
        // Prepare data
        $from = intval($this->input->post('from'));
        $this->load->model('ciext/dashboard_model');
        $data = $this->dashboard_model->get_items(20, $from);

        $content = array(
            'items' => $data,
            'message' => ''
        );
        
        die(trim($this->parser->parse('ciext/dashboard/dashboard', $content, TRUE)));
    }

}

/* End of file admin.php */
/* Location: ./application/modules/ciext/admin.php */
