<?php

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

/**
 * Description of callme_admin
 *
 * @author Igor Ratsun
 */
class callme_admin extends MX_Controller {

    public function __construct() {
        $this->lang->load('callme/admin');
    }

    public function manager() {
        // Acceess check
        if (!$this->rt_user->isAllowed('callme', 'manager')) {
            $this->admin_lib->show_denied();
        }
        
        $this->load->config('callme/admin');
        $this->load->library('rtgrid/rtgrid_api');
        $crud = & $this->rtgrid_api;
        $crud->set_table('callme');
        
        $crud->columns($this->config->item('manager_columns'));
        $crud->fields($this->config->item('manager_fields'));

        // Unset buttons
        $crud->unset_action('add');
        // Acceess check
        if (!$this->rt_user->isAllowed('callme', 'delete')) {
            $crud->unset_action('delete');
        }

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

        $crud->callback('text', 'textarea');
        $crud->callback('date_add', 'date');
        $crud->callback('worked_out', 'active');

        return array(
            'content' => $crud->render(),
            'title' => $this->lang->line('title'),
        );
    }

    public function configuration() {
        // Acceess check
        if (!$this->rt_user->isAllowed('callme', 'configuration')) {
            $this->admin_lib->show_denied();
        }
        
        $this->load->library('ciext/configurator');
        $configurator = new configurator();
        $configurator->set_resource('callme');
        $configurator->add_input('email');
        $configurator->add_input('subject');
        $configurator->add_textarea('template');

        foreach ($this->lang->line('config_aliases') as $key => $value) {
            $configurator->display_as($key, $value);
        }

        $content = array(
            'msg_ok' => $this->lang->line('msg_ok'),
            'btn_save' => $this->lang->line('btn_save')
        );
        
        $this->js_css->parse_css('callme/css/admin.css');

        return array(
            'content' => $this->parser->parse_string($configurator->render(), $content, TRUE),
            'title' => $this->lang->line('title'),
        );
    }

}