<?php
/**
**  Easy configure - Setup de configuração fácil do usuário
**  Por: Matheus Scarpelin
**/

class ControllerExtensionEasyconfigure extends Controller {

  private $error = array();

  // Na index() ira buscar todos os campos dos arrays $noValidateForm e $validateForm
  private $validateForm = array(
    // Step 3
    3 => array(
      'config_telephone',
      'config_email',
      'config_owner',
      'config_name',
      'config_cnpj',
      'config_ie',
      'easyconfig_postcode',
      'easyconfig_street',
      'easyconfig_number',
      'easyconfig_district',
      'easyconfig_city',
      'easyconfig_state',
      'config_time_zone'
    ),
    // Step 4
    4 => array(
      'config_title',
      'config_logo',
      'primary_color',
      'secondary_color'
    ),
    // Step 5
    5 => array(
      'config_smtp_host',
      'config_smtp_username',
      'config_smtp_password',
      'config_smtp_port',
      'config_alert_mail',
      'config_account_mail',
      'config_mail_protocol',
      'config_smtp_timeout',
      'config_email',
    ),
    // Step 6
    6 => array()
  );
  private $noValidateForm = array(
    'tipo_ramo',
    'config_telephone',
    'wg24_config_whatsapp',
    'config_email',
    'config_owner',
    'config_name',
    'config_cnpj',
    'config_ie',
    'easyconfig_postcode',
    'easyconfig_street',
    'easyconfig_number',
    'easyconfig_district',
    'easyconfig_complemento',
    'easyconfig_city',
    'easyconfig_state',
    'config_mode_orcamento',
    'config_mode_st',
    'config_title',
    'config_logo',
    'wg24_mm_bgcol',
    'wg24_l_body_tbc',
    'config_smtp_host',
    'config_email',
    'config_mail_parameter',
    'config_mail_protocol',
    'config_smtp_username',
    'config_smtp_password',
    'config_smtp_port',
    'config_smtp_timeout',
    'config_alert_mail',
    'config_account_mail',
    'config_alert_emails',
    'current_step',
    'finish_steps'
  );

  public function index() {
    $this->load->model('user/user_group');
    $this->model_user_user_group->addPermission($this->user->getId(), 'access', 'module/wg24themeoptionpanel');
    $this->model_user_user_group->addPermission($this->user->getId(), 'modify', 'module/wg24themeoptionpanel');

    $language = $this->load->language('extension/easyconfigure');
    $this->data = array_merge($this->data, $language);

    $this->document->setTitle($this->language->get('heading_title'));
    $this->load->model('setting/setting');
    $this->load->dmodel('tool/image');
    $this->load->dmodel('wsceo/cadastro/empresa');
    $this->load->helper('ftr_geral');
    $this->load->type('tipocomum');

    $this->data['easyconfigure_js'] = $this->ftrgeralregistry->getScriptManifest('public/js/extension/easyconfigure.js', false);

    $this->data['ftr_geral'] = new ftr_geral();
    $this->data['Type_RamoEcommerce'] = $this->load->typeForTwig('Type_RamoEcommerce');
    $this->data['Type_Estados'] = $this->load->typeForTwig('Type_Estados');
    $this->data['Type_DsimDnao'] = $this->load->typeForTwig('Type_DsimDnao');
    $this->data['Type_EmailProtocol'] = $this->load->typeForTwig('Type_EmailProtocol');
    $this->data['Type_Phone'] = Type_Phone::getTypeForJs();

    $this->data['config_telephone'] =
        $this->config->get('config_telephone')
        ? array_values($this->config->get('config_telephone'))
        : array();

    $config_data = $this->noValidateForm;
    foreach ($this->validateForm as $key => $value) {
      $config_data = array_unique(array_merge($config_data, $value));
    }

    $this->data['logo_view'] = $this->dmodel_tool_image->resize($this->config->get('config_logo'), 80, 80);

    $logo = $this->config->get('config_logo');
    $logo_exists = file_exists(DIR_IMAGE . $logo) && is_file(DIR_IMAGE . $logo);
    $logo_preview = $logo && $logo_exists ? $logo : 'no_image.jpg';
    $this->data['logo'] = $this->dmodel_tool_image->resize(
        $logo_preview,
        Type_MiniatureMedium::Tp_width,
        Type_MiniatureMedium::Tp_height
    );

    $this->data['time_zones'] = DateTimeZone::listIdentifiers();

    foreach ($config_data as $conf) {
      if (isset($this->request->post[$conf])) {
        $this->data[$conf] = $this->request->post[$conf];
      } else {
        $this->data[$conf] = $this->config->get($conf);
      }
    }

    $empresas = $this->dmodel_wsceo_cadastro_empresa->consultarEmpresa();
    $this->data['empresas'] = array ();

    if (is_object($empresas)) {
        $this->data['error_ceo'] = $empresas;
    } else {
        foreach ($empresas as $key => $empresa) {
        $this->data['empresas'][] = array(
            'id'     => $empresa['id'],
            'name'   => $empresa['fantasia'],
            'select' => (ftr_geral::isIsset($this->config->get('futuracalcularst_usuario')) && ($this->config->get('futuracalcularst_usuario') == $empresa['id'])) ? true : false
        );
        }
    }

    $this->data['current_step'] = (isset($this->data['current_step']) && $this->data['current_step']) ? $this->data['current_step'] : 1;

    $this->data['finish_steps'] = (isset($this->data['finish_steps'] ) && $this->data['finish_steps'] ) ? $this->data['finish_steps']  : array('1');

    $steps_title = array(
      'Bem Vindo',
      'Negócio',
      'Empresa',
      'Visual',
      'E-mail',
      'Social',
      'Concluído'
    );

    foreach ($steps_title as $key => $value) {
      $this->data['steps'][$key+1] = array(
        'title'  => $value,
        'finish' => in_array($key+1, $this->data['finish_steps']) ? 1 : 0
      );
    }

    $this->data['socialNetwork'] = array(
      'wg24_facebook_url' => array(
        'url'        => $this->config->get('wg24_facebook_url'),
        'class'      => 'facebook-f',
        'title'      => 'Facebook'
      ),
      'wg24_twitter_url' => array(
        'url'        => $this->config->get('wg24_twitter_url'),
        'class'      => 'twitter',
        'title'      => 'Twitter'
      ),
      'wg24_google_url' => array(
        'url'        => $this->config->get('wg24_google_url'),
        'class'      => 'google-plus',
        'title'      => 'Google+'
      ),
      'wg24_rss_url' => array(
        'url'        => $this->config->get('wg24_rss_url'),
        'class'      => 'rss',
        'title'      => 'RSS'
      ),
      'wg24_pinterest_url' => array(
        'url'        => $this->config->get('wg24_pinterest_url'),
        'class'      => 'pinterest',
        'title'      => 'Pinterest'
      ),
      'wg24_linking_url' => array(
        'url'        => $this->config->get('wg24_linking_url'),
        'class'      => 'linkedin',
        'title'      => 'Linkedin'
      ),
      'wg24_youtub_url' => array(
        'url'        => $this->config->get('wg24_youtub_url'),
        'class'      => 'youtube',
        'title'      => 'Youtube'
      ),
      'wg24_instagram_url' => array(
        'url'        => $this->config->get('wg24_instagram_url'),
        'class'      => 'instagram',
        'title'      => 'Instagram'
      ),
      'wg24_blogger_url' => array(
        'url'        => $this->config->get('wg24_blogger_url'),
        'class'      => 'blogger',
        // 'icon_img'   => '../image/icones/icon-blogger.png',
        'title'      => 'Blogger'
      )
    );

    $this->data['token'] = $this->session->data['token'];

    $this->response->setOutput($this->render('extension/easyconfigure'));
  }

  private function setError($newerror){
    $this->error = array_merge($this->error, $newerror);
  }

  private function setErrorStr($keyError, $newerrorStr){
    $this->error = array_merge($this->error, [$keyError => $newerrorStr]);
  }

  public function saveData(){
    $this->load->type('tipocomum');
    $this->language->load('extension/easyconfigure');
    $this->load->model('setting/extension');

    $arrayWg24 = array();
    $config = array();

    $arrayWg24['wg24_exibe_contact']              = 'yes';
    $arrayWg24['wg24_type_configuration_contact'] = 'easy';

    $config['current_step'] = (isset($this->request->post['current_step'])) ? $this->request->post['current_step'] : array(1);
    $config['finish_steps'] = (isset($this->request->post['finish_steps'])) ? $this->request->post['finish_steps'] : 1 ;

    if (isset($this->request->post['step'])) {
      switch ($this->request->post['step']) {

        //================================= Step 2 =================================
        case 2:
          if ($this->validate($this->request->post['step'])) {
            if($this->request->post['tipo_ramo'] == Type_RamoEcommerce::Tp_RmEcmrc_B2B){
              $status = Type_CadastroPessoa::Tp_Juridico;
              //Configurando quantidade atacado...
              $this->installModule('futuraquantidadeatacado');

              $arrayWg24['wg24_home_redir_carrinho'] = Type_DsimDnao::Tp_Nao;
              $arrayWg24['wg24_futura_status_lista_desejos']    = Type_Status::Tp_Desabilitado;
              $arrayWg24['wg24_futura_status_lista_comparacao'] = Type_Status::Tp_Desabilitado;
              $arrayWg24['wg24_productbox_size']                = Type_Tamanho::Tp_Pequeno;
            } else {
              $status = Type_CadastroPessoa::Tp_Fisico;
              $arrayWg24['wg24_home_redir_carrinho'] = Type_DsimDnao::Tp_Sim;
              $arrayWg24['wg24_productbox_size']                = Type_Tamanho::Tp_Grande;
              $this->model_setting_extension->uninstallSetting('total', 'futuracalcularst');
            }

            $this->load->model('setting/setting');
            $arrayEdit = array(
              'fields_register_brazil_tipo_de_pessoa'         => $status,
              'fields_register_brazil_status_cnpgcpf'         => 1,
              'fields_register_brazil_status_telefone'        => 0,
              'fields_register_brazil_status_celular'         => 1,
              'fields_register_brazil_status_telefone2'       => 0,
              'fields_register_brazil_status_sexo'            => 0,
              'fields_register_brazil_status_data_nascimento' => 0,
              'fields_register_brazil_status_rg'              => 0
            );
            $this->model_setting_setting->editSetting('fields_register_brazil', $arrayEdit);

            $config['tipo_ramo'] = $this->request->post['tipo_ramo'];
          }
          break;

        //================================= Step 3 =================================
        case 3:
          if ($this->validate($this->request->post['step'])) {
            $config['config_telephone']      = $this->request->post['config_telephone'] ?? array();
            $config['config_name']           = $this->request->post['config_name'];
            $config['config_owner']          = $this->request->post['config_owner'];
            $config['config_cnpj']           = $this->request->post['config_cnpj'];
            $config['config_ie']             = $this->request->post['config_ie'];
            $config['config_mode_orcamento'] = (isset($this->request->post['config_mode_orcamento'])) ? $this->request->post['config_mode_orcamento'] : 0;
            $config['config_email']           = $this->request->post['config_email'];
            $config['easyconfig_postcode']    = $this->request->post['easyconfig_postcode'];
            $config['easyconfig_street']      = $this->request->post['easyconfig_street'];
            $config['easyconfig_number']      = $this->request->post['easyconfig_number'];
            $config['easyconfig_district']    = $this->request->post['easyconfig_district'];
            $config['easyconfig_complemento'] = $this->request->post['easyconfig_complemento'];
            $config['easyconfig_city']        = $this->request->post['easyconfig_city'];
            $config['easyconfig_state']       = $this->request->post['easyconfig_state'];

            $easyconfig_complemento = ($this->request->post['easyconfig_complemento']) ? $this->request->post['easyconfig_complemento'] . ", " : '';

            $config['config_address'] = '';
            $config['config_address'] .= $this->request->post['easyconfig_street'] . ", ";
            $config['config_address'] .= "N " . $this->request->post['easyconfig_number'] . ", ";
            $config['config_address'] .= $this->request->post['easyconfig_district'] . ", ";
            $config['config_address'] .= $easyconfig_complemento;
            $config['config_address'] .= $this->request->post['easyconfig_city'] . "-";
            $config['config_address'] .= Type_EstadosSigla::getNickFromValue($this->request->post['easyconfig_state']) . ", ";
            $config['config_address'] .= "CEP: " . $this->request->post['easyconfig_postcode'];

            $arrayWg24['config_email']           = $this->request->post['config_email'];

            $arrayWg24['wg24_tipo_rodape']           = Type_AutoOrPersonalizado::Tp_Automatico;
            $arrayWg24['wg24_bandeiras_automaticas'] = Type_DsimDnao::Tp_Sim;

            $arrayWg24['wg24_titulo_rodape'] = $this->language->get('easyconfig_titulo_rodape');
            $arrayWg24['config_address']     = $config['config_address'];

            $config['config_mode_st'] = (isset($this->request->post['config_mode_st'])) ? $this->request->post['config_mode_st'] : 0;
          }
          $languageDirectory = 'portuguese-br';
          if(isset($this->request->post['config_mode_orcamento']) && $this->request->post['config_mode_orcamento']){
            //--As configurações automáticas desses módulos devem ser colocados
            //--dentro da função de cada módulo, conforme a tarefa 981301
            $this->InstallShipping('freteacombinar');
            $this->installPayment('orcamento');
            $languageDirectory = 'portuguese-brOrc';
          }else{
            $this->model_setting_extension->uninstallSetting('shipping','freteacombinar');
            $this->model_setting_extension->uninstallSetting('payment','orcamento');
            $languageDirectory = 'portuguese-br';
          }

          $this->load->model('localisation/language');
          $arrayEdit = array(
            'name'       => 'Português (BR)',
            'code'       => 'pt-br',
            'locale'     => 'pt_BR.UTF-8, pt_BR, UTF-8',
            'image'      => 'br.png',
            'directory'  => $languageDirectory,
            'filename'   => 'portuguese-br',
            'status'     => 1,
            'sort_order' => 0,
          );
          $this->model_localisation_language->editLanguage(1, $arrayEdit);

          if(isset($this->request->post['config_mode_st']) && $this->request->post['config_mode_st']){
            $this->installTotal('futuracalcularst');
            $this->load->model('setting/setting');
            $arraySt = array(
              'futuracalcularst_status'   => 1,
              'futuracalcularst_usuario'  => $this->request->post['config_mode_st_idempresa']
            );
            $this->model_setting_setting->editSetting('futuracalcularst', $arraySt);
          }

          break;

        //================================= Step 4 =================================
        case 4:
          if ($this->validate($this->request->post['step'])) {
            $arrayWg24 = [];
            $arrayColors = $this->request->post['cores'] ?? [];
            $config['config_title'] = $this->request->post['config_title'];
            $config['config_logo']  = $this->request->post['config_logo'];

            //valores default para o banner principal
            $arrayWg24['wg24_habilitaBanner']   = 'enable';
            $arrayWg24['wg24_tipoconfiguracao'] = 'avancada';
            $arrayWg24['wg24_tipobanner']       = 'tnormal';
            $arrayWg24['wg24_hideresponsive']   = 1;
            $arrayWg24['wg24_banner_largura']   = 1140;
            $arrayWg24['wg24_banner_altura']    = 480;
            $arrayWg24['wg24_bannertime']       = 8;

            $this->load->model('catalog/product');

            $banner_dinamico = array ();

            $banner_dinamico[0] = array(
              'new' => 'false',
              'banner_dinamico_tipolista'    => 'latest',
              'banner_dinamico_quantidade'   => '5',
              'banner_dinamico_model'        => 'model-3',
              'banner_dinamico_ordem'        => 1,
            );

            $arrayWg24['banner_dinamico'] = $banner_dinamico ;

          }
          break;

        //================================= Step 5 =================================
        case 5:
          if ($this->validate($this->request->post['step'])) {
            $config['config_smtp_host']     = $this->request->post['config_smtp_host'];
            $config['config_email']         = $this->request->post['config_email'];
            // $config['config_mail_parameter'] = $this->request->post['config_mail_parameter'];
            $config['config_mail_protocol'] = $this->request->post['config_mail_protocol'];
            $config['config_smtp_username'] = $this->request->post['config_smtp_username'];
            $config['config_smtp_password'] = $this->request->post['config_smtp_password'];
            $config['config_smtp_port']     = $this->request->post['config_smtp_port'];
            $config['config_smtp_timeout']  = $this->request->post['config_smtp_timeout'];
            $config['config_alert_emails']  = $this->request->post['config_alert_emails'];
            $config['config_account_mail']  = $this->request->post['config_account_mail'];
            $config['config_alert_mail']    = $this->request->post['config_alert_mail'];
          }
          break;

        //================================= Step 6 =================================
        case 6:
          if ($this->validate($this->request->post['step'])) {
            $arrayWg24['wg24_facebook_url']  = isset($this->request->post['wg24_facebook_url']) ? $this->request->post['wg24_facebook_url'] : '';
            $arrayWg24['wg24_twitter_url']   = isset($this->request->post['wg24_twitter_url']) ? $this->request->post['wg24_twitter_url'] : '';
            $arrayWg24['wg24_google_url']    = isset($this->request->post['wg24_google_url']) ? $this->request->post['wg24_google_url'] : '';
            $arrayWg24['wg24_rss_url']       = isset($this->request->post['wg24_rss_url']) ? $this->request->post['wg24_rss_url'] : '';
            $arrayWg24['wg24_pinterest_url'] = isset($this->request->post['wg24_pinterest_url']) ? $this->request->post['wg24_pinterest_url'] : '';
            $arrayWg24['wg24_linking_url']   = isset($this->request->post['wg24_linking_url']) ? $this->request->post['wg24_linking_url'] : '';
            $arrayWg24['wg24_youtub_url']    = isset($this->request->post['wg24_youtub_url']) ? $this->request->post['wg24_youtub_url'] : '';
            $arrayWg24['wg24_instagram_url'] = isset($this->request->post['wg24_instagram_url']) ? $this->request->post['wg24_instagram_url'] : '';
            $arrayWg24['wg24_blogger_url']   = isset($this->request->post['wg24_blogger_url']) ? $this->request->post['wg24_blogger_url'] : '';
          }
          break;

        default:
          $this->setErrorStr('warning', $this->language->get('error_step'));
          break;
      }
    }

    // CONFIGS --------------------------------------
    $arrayWg24['step'] = $this->request->post['step'];
    if (!$this->error) {
      $this->saveSettings($config);
    }

    $this->load->controller('module/wg24themeoptionpanel');
    $themeOption = new ControllerModuleWg24ThemeOptionPanel($this->registry);

    $themeOption->setError();

    if ($themeOption->getError()) {
      $this->setError($themeOption->getError());
    } elseif (!$this->error) {
      if (!empty($arrayColors)){
          $arrayWg24['colors'] = $arrayColors;
      }
      $themeOption->sendData($arrayWg24);
    }

    if(!$this->error){
      $this->response->setOutput(json_encode(['success' => $this->language->get('easyconfig_success')])) ;
    }else{
      $this->response->setOutput(json_encode(['error' => $this->error]));
    }

  }

  private function installTotal($moduleTotal){
    $this->load->model('user/user_group');
    $this->model_user_user_group->addPermission($this->user->getId(), 'access', 'total/' . $moduleTotal);
    $this->model_user_user_group->addPermission($this->user->getId(), 'modify', 'total/' . $moduleTotal);

    $this->load->model('setting/extension');
    $this->model_setting_extension->install('total', $moduleTotal);

    $this->load->controller('total/' . $moduleTotal);

    $class = 'ControllerTotal' . str_replace('_', '', $moduleTotal);
    $class = new $class($this->registry);

    if (method_exists($class, 'install')) {
      $class->install();
    }
  }

  private function installModule($moduleName){
    $this->load->model('user/user_group');
    $this->model_user_user_group->addPermission($this->user->getId(), 'access', 'module/' . $moduleName);
    $this->model_user_user_group->addPermission($this->user->getId(), 'modify', 'module/' . $moduleName);

    $this->load->model('setting/extension');
    $this->model_setting_extension->install('module', $moduleName);

    $this->load->model('setting/setting');
    $this->model_setting_setting->editSetting($moduleName, array('futuraquantidadeatacado_status' => 1));

    $this->load->controller('module/' . $moduleName);

    $class = 'ControllerModule' . str_replace('_', '', $moduleName);
    $class = new $class($this->registry);

    if (method_exists($class, 'install')) {
      $class->install();
    }
  }

  private function InstallShipping($moduleName){
    $this->load->model('setting/extension');

    $this->model_setting_extension->install('shipping', $moduleName);

    $this->load->model('user/user_group');

    $this->model_user_user_group->addPermission($this->user->getId(), 'access', 'shipping/' . $moduleName);
    $this->model_user_user_group->addPermission($this->user->getId(), 'modify', 'shipping/' . $moduleName);

    $this->load->controller('shipping/' . $moduleName);

    $class = 'ControllerShipping' . str_replace('_', '', $moduleName);
    $class = new $class($this->registry);

    if (method_exists($class, 'install')) {
      $class->install();
    }
    $this->load->model('setting/setting');
    $arrayEdit = array(
      'freteacombinar_titulo'     => 'Frete a combinar',
      'freteacombinar_status'     => 1,
      'freteacombinar_sort_order' => 0
    );
    $this->model_setting_setting->editSetting($moduleName, $arrayEdit);
  }

  private function installPayment($moduleName){
    $this->load->model('setting/extension');

    $this->model_setting_extension->install('payment', $moduleName);

    $this->load->model('user/user_group');

    $this->model_user_user_group->addPermission($this->user->getId(), 'access', 'payment/' . $moduleName);
    $this->model_user_user_group->addPermission($this->user->getId(), 'modify', 'payment/' . $moduleName);

    $this->load->controller('payment/' . $moduleName);

    $class = 'ControllerPayment' . str_replace('_', '', $moduleName);
    $class = new $class($this->registry);

    if (method_exists($class, 'install')) {
      $class->install();
    }
    $this->load->model('setting/setting');
    $arrayEdit = array(
      'orcamento_status'           => 1,
      'orcamento_status_iniciado'  => 1,
      'orcamento_status_baixa'     => 1,
      'orcamento_instrucoes'       => '<p>Em breve entraremos em contato</p>',
      'orcamento_descricao'        => 'Orçamento'
    );
    $this->model_setting_setting->editSetting($moduleName, $arrayEdit);
  }

  private function validate($step) {

    $this->load->helper('ftr_geral');
    $this->load->helper('ftr_validacao');

    if (!$this->user->hasPermission('modify', 'setting/setting')) {
      $this->setErrorStr('warning', $this->language->get('error_permission'));
    }

    switch ($step) {
      case 3:
        if ($this->notEmpty($this->validateForm[3])) {
          if ((utf8_strlen($this->request->post['config_owner']) < 3) || (utf8_strlen($this->request->post['config_owner']) > 64)) {
            $this->setErrorStr('config_owner', $this->language->get('error_config_owner'));
          }
          if (!ftr_validacao::isCnpj($this->request->post['config_cnpj'])) {
            $this->setErrorStr('config_cnpj', $this->language->get('error_config_cnpj'));
          }
          if ((utf8_strlen($this->request->post['config_email']) > 96) || !preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['config_email']) || !filter_var($this->request->post['config_email'], FILTER_VALIDATE_EMAIL) || !preg_match('/^[a-zA-Z0-9\._-]+@/', $this->request->post['config_email']) ) {
            $this->setErrorStr('config_email', $this->language->get('error_config_email'));
          }
        }

        break;

      case 4:
        $this->notEmpty($this->validateForm[4]);
        break;

      case 5:
        $this->notEmpty($this->validateForm[5]);
        break;

      case 6:
        $this->notEmpty($this->validateForm[6]);
        break;
    }

    if ($this->error && !isset($this->error['warning'])) {
      $this->setErrorStr('warning', $this->language->get('error_warning'));
    }

    if (!$this->error) {
      return true;
    } else {
      return false;
    }
  }

  private function notEmpty($array) {
    foreach ($array as $key) {
      if (isset($this->request->post[$key]) && $this->request->post[$key] == '') {
        $this->setErrorStr($key, $this->language->get('error_required_field'));
      }
    }
    if (!$this->error) {
      return true;
    } else {
      return false;
    }
  }

  public function rememberOrCancel() {
    $config = array();
    if (isset($this->request->post['quick_config'])) {
      $config['quick_config'] = array( $this->user->getId() => array(
        'status' => $this->request->post['quick_config'],
        'date'   => date('Y-m-d'))
      );

    }
    $this->saveSettings($config);
    $this->response->setOutput(json_encode(['success' => $this->language->get('easyconfig_success')])) ;
  }

  public function updateCurrentStep() {
    $config['current_step'] = (isset($this->request->post['current_step'])) ? $this->request->post['current_step'] : array(1);
    $this->saveSettings($config);
  }
  public function updateFinishStep() {
    $config['finish_steps'] = (isset($this->request->post['finish_steps'])) ? $this->request->post['finish_steps'] : array(1);
    $this->saveSettings($config);
  }

  private function saveSettings($config) {
    $this->load->model('setting/setting');
    $this->model_setting_setting->editSettingForKey('config', $config);
  }

}
