<?php 
defined('BASEPATH') or EXIT('Ação não permitida');

class Home extends CI_Controller {

    public function __construct() {
        parent::__construct();

        //Valid session?
        if (!$this->ion_auth->is_admin()) {
            redirect('restricted/auth');
        }
    }

    public function index(){
        // Get the user id through session
        $user_id = $this->session->user_id;
        
        $data = array(
            'title' => 'Painel de controle',
            'styles'  =>  array(
                'css/custom.css',
            ),
            'scripts' => array(
                'vendor/chart.js/Chart.min.js',
                'js/demo/chart-area-demo.js',
                'js/chapter_details.js',
            ),
            'messages'                      => $this->core_model->get_all('messages', array('comment_destination' => $user_id)),
            'unread_messages'               => count($this->core_model->get_all('messages', array('comment_destination' => $user_id, 'was_read' => 0))),
            'alerts'                        => $this->core_model->get_all('alerts', array('user_id' => $user_id)),
            'unread_alerts'                 => count($this->core_model->get_all('alerts', array('user_id' => $user_id, 'was_read' => 0))),
            'books_count'                   => count($this->core_model->get_all('books')),
            'books'                         => $this->core_model->get_all('books'),
            'users'                         => count($this->core_model->get_all('users')),
            'chapters'                      => $this->core_model->get_all('chapters'),
            'chapters_waiting_review'       => count($this->core_model->get_all('chapters', array('status' => 'waiting_review'))),
        );
        $this->load->view('restricted/layout/header', $data);
        $this->load->view('restricted/admin/index');
        $this->load->view('restricted/layout/footer');
    }

}
