<?php

class ContactController extends ContactControllerCore
{
    /*
    * module: pagecache
    * date: 2017-03-09 11:29:30
    * version: 3.17
    */
    public function displayAjax()
    {
        $result = array();
        $index = 0;
        do
        {
            $val = Tools::getValue('hook_' . $index);
            if ($val !== false)
            {
                list($hook_name, $id_module) = explode('|', $val);
                if (Validate::isHookName($hook_name)) {
                    $result[$hook_name . '_' . (int)$id_module] = Hook::exec($hook_name, array() , (int)$id_module);
                }
            }
            $index++;
        } while ($val !== false);
        if (Tools::version_compare(_PS_VERSION_,'1.6','>')) {
            Media::addJsDef(array(
                'isLogged' => (bool)$this->context->customer->isLogged(),
                'isGuest' => (bool)$this->context->customer->isGuest(),
                'comparedProductsIds' => $this->context->smarty->getTemplateVars('compared_products'),
            ));
            $this->context->smarty->assign(array(
                    'js_def' => Media::getJsDef(),
            ));
            $result['js'] = $this->context->smarty->fetch(_PS_ALL_THEMES_DIR_.'javascript.tpl');
        }
        $this->context->cookie->write();
        die(Tools::jsonEncode($result));
    }
    /*
    * module: recaptcha
    * date: 2018-03-13 17:56:07
    * version: 1.2.0
    */
    public function preProcess()
    {
        if (version_compare(_PS_VERSION_, '1.5', '<')) {
            self::$smarty->assign('HOOK_CONTACT_FORM_BOTTOM', Module::hookExec('contactFormBottom'));
        }
        if (version_compare(_PS_VERSION_, '1.5', '<') &&
            Tools::isSubmit('submitMessage') && Module::isInstalled('recaptcha')) {
            require_once(_PS_ROOT_DIR_.'/modules/recaptcha/recaptcha.php');
            $recaptcha = new Recaptcha();
            if (!$recaptcha->validateCaptcha()) {
                $this->errors[] = $recaptcha->l('Invalid captcha.');
                unset($_POST['submitMessage']);
            }
        }
        parent::preProcess();
    }
    /*
    * module: recaptcha
    * date: 2018-03-13 17:56:07
    * version: 1.2.0
    */
    public function postProcess()
    {
        if (Tools::isSubmit('submitMessage') && version_compare(_PS_VERSION_, '1.7', '<')) {
            Hook::exec('contactCaptchaValidate');
        }
        if (empty($this->errors)) {
            parent::postProcess();
        }
    }
    /*
    * module: recaptcha
    * date: 2018-03-13 17:56:07
    * version: 1.2.0
    */
    public function init()
    {
        if (version_compare(_PS_VERSION_, '1.5', '>=')) {
            $this->context->smarty->assign('HOOK_CONTACT_FORM_BOTTOM', Hook::exec('contactFormBottom'));
        }
        parent::init();
    }
    /*
    * module: recaptcha
    * date: 2018-03-13 17:56:07
    * version: 1.2.0
    */
    public function initContent()
    {
        parent::initContent();
        if (version_compare(_PS_VERSION_, '1.7.0', '<')&&Module::isInstalled('recaptcha')) {
            if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) {
                $html = _PS_MODULE_DIR_ . 'recaptcha/views/templates/front/front-contact-form-1-6.tpl';
            } //1.5
            else {
                $html = _PS_MODULE_DIR_ . 'recaptcha/views/templates/front/front-contact-form-1-5.tpl';
            }
            $this->setTemplate($html);
        }
    }
}
