<?php

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

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

    protected $module_config = array();

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

        $this->lang->load('resmng/install');
        // Set acl module name
        $this->module_config['module_acl_name'] = 'resmng';
        // Set title
        $this->module_config['module_title'] = $this->lang->line('module_name');
        // Set actions
        $this->module_config['module_actions'] = $this->lang->line('resmng_actions');
        // Set menu items
        $this->module_config['module_menu_items'] = array(
            array('manager', $this->lang->line('module_name'), '/' . $this->config->item('assets_folder') . '/' . $this->config->item('components_folder') . '/ciext/img/dev-tool/resmaneger.png', 'resmng_view')
        );
    }
    
    public function install() {
        $this->load->library('ciext/installer');
        $rs = $this->installer->install($this->module_config['module_acl_name'], $this->module_config['module_title'], $this->module_config['module_actions'], $this->module_config['module_menu_items']);
        if ($rs != 'installed') {
            
            return FALSE;
        }

        // Create table
        $file = dirname(__DIR__) . '/data/install.sql';
        if (file_exists($file)) {
            $sql = file_get_contents($file);
            foreach (explode(';', trim($sql)) as $table) {
                if (!empty($table)) {
                    $this->db->query($table);
                }
            }
        }
        
        // Upgrade module if needed
        $this->load->module('ciext/upgrade');
        $this->upgrade->upgrade($this->module_config['module_acl_name']);

        return array('content' => $this->lang->line('module_installed'), 'title' => $this->module_config['module_title']);
    }

    public function uninstall() {
//        $this->load->library('ciext/installer');
//        $this->installer->uninstall($this->module_config['module_acl_name']);

        return array('content' => $this->lang->line('module_removed'), 'title' => $this->module_config['module_title']);
    }

}

