<?php 

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

class cache_admin extends MX_Controller {

    public function __construct() {
        $this->lang->load('cache/admin');
        $this->load->model('cache/cache_model_admin');
    }
    
    public function index() {
        // Acceess check
        if (!$this->rt_user->isAllowed('cache', 'edit_cache')) {
            $this->admin_lib->show_denied();
        }
        $this->load->library('rtgrid/rtgrid_api');
//        $crud = & $this->rtgrid_api;
        $crud = new rtgrid_api();

        $crud->set_table('resource_type_page');
        $crud->join('resource', 'resource.id_item=resource_type_page.id_resource_type_page AND resource.id_resource_type=3', 'left');
        
        // Hide private page
        if (!$this->rt_user->isAllowed('resmng', 'private')) {
            $crud->where('resource.private', FALSE);
        }
        
        $crud->columns('resource_type_page.name, resource_type_page.cache');
        
        $crud->callback('cache', 'active');
        
        $crud->unset_action('edit');
        $crud->unset_action('delete');
        $crud->unset_action('add');
        
        $crud->add_top_action(new rtgrid_top_action('active', '<i class="icon-ok"></i> ' . $this->lang->line('Activate cache'), array($this->cache_model_admin, 'activate_cache'), $this->lang->line('Activate cache?')));
        $crud->add_top_action(new rtgrid_top_action('deactive', '<i class="icon-remove"></i> ' . $this->lang->line('Deactivate cache'), array($this->cache_model_admin, 'deactivate_cache'), $this->lang->line('Deactivate cache?')));
        $crud->add_top_action(new rtgrid_top_action('clear', '<i class="icon-trash"></i> ' . $this->lang->line('Clear cache'), array($this->cache_model_admin, 'clear_cache'), $this->lang->line('Clear cache?')));

        // Set alias
        $aliases = $this->lang->line('display_as');
        foreach ($aliases as $key => $val) {
            $crud->display_as($key, $val);
        }
        
        return array(
            'content' => $crud->render(),
            'title' => $this->lang->line('module_name')
        );
    }

}

