<?php

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

/**
 * Upgrade Callme module to version 3.2.0
 *
 * @author CIEXT skeleton
 */
class Callme_upgrade_3_1_0 extends Abstract_upgrade
{

    public function up()
    {
        $ci = & get_instance();
        $ci->db->where('acl_resource', 'callme')
                ->where('acl_action', 'configuration')
                ->update('admin_menu', ['active' => '0']);

        $ci->load->library('ciext/configurator');
        $ci->configurator->set_resource('callme');
        $configuration = $ci->configurator->get_config();
        $subject = !empty($configuration['subject']) ? $configuration['subject'] : 'Call me';
        $message = !empty($configuration['template']) ? str_replace([
                    '{in_name}',
                    '{in_email}',
                    '{in_phone}',
                    '{in_text}'
                        ], [
                    '[[in_name]]',
                    '[[in_email]]',
                    '[[in_phone]]',
                    '[[in_text]]'
                        ], $configuration['template']) : '[[in_name]] [[in_email]] [[in_phone]] [[in_text]]';
        $ci->load->library('emailmng/emailmng_installer')
                ->set_subject($subject, '')
                ->set_message($message, '[[in_name]] [[in_email]] [[in_phone]] [[in_text]]')
                ->add_template('callme_me_tpl');

        return '3.2.0';
    }

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

}
