<?php

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

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

    protected $module_config = array();

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

        $this->lang->load('filemanager/install');
        // Set acl module name
        $this->module_config['module_acl_name'] = 'filemanager';
        // Set title
        $this->module_config['module_title'] = $this->lang->line('module_name');
        // Set actions
        $this->module_config['module_actions'] = array(
                'edit_file' => $this->lang->line('edit_module'),
                'edit_all_file' => $this->lang->line('edit_all_module')
        );
        // Set menu items
        $this->module_config['module_menu_items'] = array(
            array('manage', $this->lang->line('module_name'), '', 'edit_file')
        );
    }

    public function install() {
        // Create table
//        $query = "
//            CREATE TABLE IF NOT EXISTS `portfolio_image` (
//              `id_image` int(11) NOT NULL AUTO_INCREMENT,
//              `id_project` smallint(5) NOT NULL,
//              `photo` varchar(128) NOT NULL,
//              `thumbnail` tinyint(1) NOT NULL DEFAULT '0',
//              PRIMARY KEY (`id_image`)
//            ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
//
//            CREATE TABLE IF NOT EXISTS `portfolio_partner` (
//              `id_partner` int(11) NOT NULL AUTO_INCREMENT,
//              `name` varchar(32) NOT NULL,
//              `url` varchar(64) NOT NULL,
//              `active` tinyint(1) NOT NULL DEFAULT '1',
//              PRIMARY KEY (`id_partner`)
//            ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
//        ";
//        foreach (explode(';', trim($query)) as $table) {
//            if (!empty($table)) {
//                $this->db->query($table);
//            }
//        }

        $this->load->library('ciext/installer');
        $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']);

        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']);
    }

}

