<?php

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

/**
 * Upgrade Callme module to version 3.1.0
 *
 * @author CIEXT skeleton
 */
class Callme_upgrade_1_1_0 extends Abstract_upgrade
{

    public function up()
    {
        $ci = & get_instance();
        if (!$this->is_table_exist('captcha')) {
            $ci->db->query('CREATE TABLE captcha (
                    id_captcha bigint(13) unsigned NOT NULL auto_increment,
                    captcha_time int(10) unsigned NOT NULL,
                    ip_address varchar(45) NOT NULL,
                    word varchar(20) NOT NULL,
                    filename varchar(255) NOT NULL,
                    PRIMARY KEY `id_captcha` (`id_captcha`),
                    KEY `word` (`word`)
                    );');
        }

        $ci->load->config('callme/captcha');
      
        if (!file_exists($ci->config->item('captcha_config')['img_path'])) {
            if (!mkdir($ci->config->item('captcha_config')['img_path'], 0775, true)) {
                show_error('Directory ' . $ci->config->item('captcha_config')['img_path'] . ' can`t be created. Please, check access to main direcrory.');
            }
        }

        return '3.1.0';
    }

    public function down()
    {
        return '1.1.0';
    }

}
