<?php

class ControllerModuleWg24ThemeOptionPanel extends Controller {

    private $error = array();

    public function index() {
        $language = $this->load->language('module/wg24themeoptionpanel');
        $this->data = array_merge($this->data, $language);
        $this->document->setTitle($this->language->get('heading_title'));
        $this->load->model('setting/setting');
        $this->load->model('tool/image');
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
            $this->model_setting_setting->editSetting('wg24themeoptionpanel', $this->request->post);

            $this->session->data['success'] = $this->language->get('text_success');

            $this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
        }

        $this->data['heading_title'] = $this->language->get('heading_title');

        $this->data['text_enabled'] = $this->language->get('text_enabled');
        $this->data['text_disabled'] = $this->language->get('text_disabled');
        $this->data['text_content_top'] = $this->language->get('text_content_top');
        $this->data['text_content_bottom'] = $this->language->get('text_content_bottom');
        $this->data['text_column_left'] = $this->language->get('text_column_left');
        $this->data['text_column_right'] = $this->language->get('text_column_right');

        //$this->data['base'] = $server;

        $this->data['entry_product'] = $this->language->get('entry_product');
        $this->data['entry_limit'] = $this->language->get('entry_limit');
        $this->data['entry_image'] = $this->language->get('entry_image');
        $this->data['entry_layout'] = $this->language->get('entry_layout');
        $this->data['entry_position'] = $this->language->get('entry_position');
        $this->data['entry_status'] = $this->language->get('entry_status');
        $this->data['entry_sort_order'] = $this->language->get('entry_sort_order');

        $this->data['button_save'] = $this->language->get('button_save');
        $this->data['button_cancel'] = $this->language->get('button_cancel');
        $this->data['button_add_module'] = $this->language->get('button_add_module');
        $this->data['button_remove'] = $this->language->get('button_remove');
        $config_data = array(
            'wg24_responsivedesign',
            'wg24_faceb',
            'wg24_faceb',
            'wg24_faceleft_right',
            'wg24_quick',
            'wg24_l_rating',
            'wg24_l_hover',
            'wg24_scrol_to_top',
            'wg24_l_sale_icon_style',
            'wg24_home_f_box',
            'wg24_home_s_b_f_box',
            'wg24_home_ofer_baner',
            'wg24_l_c_psub',
            'wg24_cate_list_grid',
            'wg24_p_pag_sidebar',
            'wg24_l_sideb_cc',
            'wg24_l_custom_tab',
            'wg24_l_tab_title',
            'wg24_l_tabc',
            'wg24_l_load_color',
            'wg24_l_bodyb',
            'wg24_l_body_tbc',
            'wg24_l_body_fc',
            'wg24_l_linkc',
            'wg24_l_hcolor',
            'wg24_l_header_color',
            'wg24_l_fld_bg',
            'wg24_l_fld_tx',
            'wg24_l_fld_bdr',
            'wg24_l_extra_bcolor',
            'wg24_category_dbb',
            'wg24_category_des_bbc',
            'wg24_category_descolor',
            'wg24_header_bgcolor',
            'wg24_header_menulcolor',
            'wg24_header_menulhcolor',
            'wg24_heade_m_lin_bg_c',
            'wg24_head_m_curlan_lin_colo',
            'wg24_header_cur_lan_lhco',
            'wg24_h_curlan_lin_hbgc',
            'wg24_top_cart_bgcol',
            'wg24_topcart_te_colo',
            'wg24_mm_bgcol',
            'wg24_mainm_brcol',
            'wg24_menum_lcolor',
            'wg24_mainm_lhcolor',
            'wg24_mainm_lhcolor',
            'wg24_menu_hbgcolor',
            'wg24_mainm_2lbgcolor',
            'wg24_mainm_2lbcolor',
            'wg24_mainm_3lbbgcolor',
            'wg24_mainm_scolor',
            'wg24_mainm_shcolor',
            'wg24_homsheding1_co',
            'wg24_home_sdec',
            'wg24_homsheding2_co',
            'wg24_home_sbtn_bgcol',
            'wg24_home_sbtn_hbr_bgclr',
            'wg24_home_btn_hbr_txclr',
            'wg24_home_fboxbg_col',
            'wg24_home_fbox_itmbg_col',
            'wg24_hom_fe_boxitem_icnbgcol',
            'wg24_hom_fe_boxbbor_col',
            'wg24_hom_fe_boxheadng_col',
            'wg24_hom_fe_boxdes_col',
            'wg24_product_bx_bgclr',
            'wg24_product_bx_bdrclr',
            'wg24_product_bx_hvr_bgclr',
            'wg24_product_box_sicon_bgcolor',
            'wg24_product_box_sale_nicontcolor',
            'wg24_product_box_n_col',
            'wg24_product_box_nhov_col',
            'wg24_product_box_price_col',
            'wg24_product_box_oldprce_col',
            'wg24_btn_1bg_col',
            'wg24_btn_2bg_col',
            'wg24_btn_hbg_col',
            'wg24_btn_text_col',
            'wg24_footer_bg_col',
            'wg24_fotheadin_col',
            'wg24_fotaout_des_col',
            'wg24_fotlin_col',
            'wg24_fotlin_h_col',
            'wg24_fot_flow_iconbg_col',
            'wg24_fot_addre_iconbg_col',
            'wg24_fot_bbg_col',
            'wg24_fot_powerred_col',
            'wg24_backgroun_image_show',
            'wg24_body_cus_pattan',
            'we24_default_parttern',
            'wg24_bg_repeat',
            'wg24_bg_attachment',
            'wg24_bg_positin',
            'wg24_body_font_source',
            'wg24_body_fontto_google',
            'wg24_body_fontto_system',
            'wg24_body_font_size',
            'wg24_header_font_source',
            'wg24_header_fontto_system',
            'wg24_header_fontto_google',
            'wg24_heading_transfrom',
            'wg24_produt_h_font_size',
            'wg24_page_h_font_size',
            'wg24_left_rig_h_font_size',
            'wg24_footer_h_font_size',
            'wg24_scrol_to+top_custom_htmlm',
            'wg24_l_custom_bmenu',
            'wg24_l_add_tcode',
            'wg24_l_add_custom_css',
            'wg24_l_add_custom_jss',
            'wg24_l_add_slider',
            'wg24_facebook_lbox',
            'wg24_facebook_purl',
            'wg24_twitter_fbox',
            'wg24_twitter_id',
            'wg24_tweets_tshow',
            'wg24_logo_image',
            'wg24_footer_coninfo',
            'wg24_contact_info_page_of',
            'wg24_facebook_url',
            'wg24_twitter_url',
            'wg24_google_url',
            'wg24_rss_url',
            'wg24_pinterest_url',
            'wg24_linking_url',
            'wg24_youtub_url',
            'wg24_copyr_text',
            'wg24_facebook_like',
            'wg24_paypal_url',
            'wg24_visaelectron_ur',
            'wg24_discover_url',
            'wg24_visa_url',
            'wg24_mastercard_url',
            'wg24_maestro_url',
            'wg24_americanexpress_url',
        );
        $this->load->model('localisation/language');
        $this->data['languages'] = $this->model_localisation_language->getLanguages();

        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);
            }
        }
        if (isset($this->error['warning'])) {
            $this->data['error_warning'] = $this->error['warning'];
        } else {
            $this->data['error_warning'] = '';
        }

        if (isset($this->error['image'])) {
            $this->data['error_image'] = $this->error['image'];
        } else {
            $this->data['error_image'] = array();
        }

        $this->data['breadcrumbs'] = array();

        $this->data['breadcrumbs'][] = array(
            'text' => $this->language->get('text_home'),
            'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
            'separator' => false
        );

        $this->data['breadcrumbs'][] = array(
            'text' => $this->language->get('text_module'),
            'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
            'separator' => ' :: '
        );

        $this->data['breadcrumbs'][] = array(
            'text' => $this->language->get('heading_title'),
            'href' => $this->url->link('module/themesdevoptionpanel', 'token=' . $this->session->data['token'], 'SSL'),
            'separator' => ' :: '
        );


        $this->data['action'] = $this->url->link('module/wg24themeoptionpanel', 'token=' . $this->session->data['token'], 'SSL');

        $this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');

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

        $this->data['thislang'] = $this->language->get('default');



        $this->load->model('design/layout');


        if (isset($this->data['wg24_body_cus_pattan']) && $this->data['wg24_body_cus_pattan'] != "" && file_exists(DIR_IMAGE . $this->data['wg24_body_cus_pattan'])) {
            $this->data['wg24_body_sub_class_thumb'] = $this->model_tool_image->resize($this->data['wg24_body_cus_pattan'], 100, 100);
        } else {
            $this->data['wg24_body_sub_class_thumb'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
        }

        $this->data['no_image'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);




        $this->data['layouts'] = $this->model_design_layout->getLayouts();

        $this->template = 'module/wg24themeoptionpanel.tpl';
        $this->children = array(
            'common/header',
            'common/footer'
        );

        $this->response->setOutput($this->render());
    }

    private function validate() {
        if (!$this->user->hasPermission('modify', 'module/wg24themeoptionpanel')) {
            $this->error['warning'] = $this->language->get('error_permission');
        }

        if (isset($this->request->post['wg24themeoptionpanel_module'])) {
            foreach ($this->request->post['wg24themeoptionpanel_module'] as $key => $value) {
                if (!$value['image_width'] || !$value['image_height']) {
                    $this->error['image'][$key] = $this->language->get('error_image');
                }
            }
        }

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

}

?>