Serveur preprod f0c0c48223 first push
2016-04-14 16:14:31 +02:00

186 lines
5.3 KiB
PHP
Executable File

<?php
/**
* 2013 Antadis
*
* This module is about exporting / Importing
* datas by CronJob for Wes Program.
*
* @author Antadis <contact@antadis.com>
* @copyright 2013-2014 Antadis
* @version 1.0
*/
if (!defined('_PS_VERSION_'))
exit;
class CookiesInfos extends Module
{
public function __construct()
{
$this->name = 'cookiesinfos';
$this->tab = 'font_office_featues';
$this->version = '1.0';
$this->author = 'Antadis';
parent::__construct();
$this->displayName = $this->l('Cookies Informatiosn');
$this->description = $this->l('Display a cookies informations top bar with link to redirect where you want');
if (!Configuration::get('COOKIESINFO_LINK') ||
!Configuration::get('COOKIESINFO_INTRO'))
$this->warning = $this->l('Wrong settings');
}
public function install()
{
if(!parent::install() ||
!$this->registerHook('displayTop') ||
!$this->registerHook('displayHeader') ||
!Configuration::updateValue('COOKIESINFO_LINK', '') ||
!Configuration::updateValue('COOKIESINFO_INTRO', ''))
return false;
return true;
}
public function uninstall()
{
if (!parent::uninstall() ||
!Configuration::updateValue('COOKIESINFO_LINK', '') ||
!Configuration::updateValue('COOKIESINFO_INTRO', ''))
return false;
return true;
}
public function getContent()
{
$output = '';
if (Tools::isSubmit('submit' . $this->name))
{
$COOKIESINFO_LINK = strval(Tools::getValue('COOKIESINFO_LINK'));
$COOKIESINFO_INTRO = strval(Tools::getValue('COOKIESINFO_INTRO'));
if (!$COOKIESINFO_LINK ||
empty($COOKIESINFO_LINK) ||
!Validate::isGenericName($COOKIESINFO_LINK))
{
$output .= $this->displayError($this->l('Invalid cookies disclaimer Link'));
}
if (!$COOKIESINFO_INTRO ||
empty($COOKIESINFO_INTRO))
{
$output .= $this->displayError($this->l('Invalid Cookies intro message'));
} else
{
Configuration::updateValue('COOKIESINFO_LINK', $COOKIESINFO_LINK);
Configuration::updateValue('COOKIESINFO_INTRO', $COOKIESINFO_INTRO);
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
}
return $output . $this->displayForm();
}
public function displayForm()
{
// Get default Language
$default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
//Init Fields form array
$fields_form[0]['form'] = array(
'legend' => array(
'title' => $this->l('Cookies disclaimer Settings')
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Intro'),
'name' => 'COOKIESINFO_INTRO',
'size' => 100,
'required' => true,
'desc' => $this->l('The introduction text that displayed on top of the front office')
),
array(
'type' => 'text',
'label' => $this->l('Link'),
'name' => 'COOKIESINFO_LINK',
'size' => 50,
'required' => true,
'desc' => $this->l("Link to redirect when clicking on cookies top information bar on front office")
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'button'
)
);
$helper = new HelperForm();
//Module, Token and currentIndex
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name;
//Language
$helper->default_form_language = $default_lang;
$helper->allow_employee_form_lang = $default_lang;
//Title and toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true;
$helper->toolbar_scroll = true;
$helper->submit_action = 'submit' . $this->name;
$helper->toolbar_btn = array(
'save' => array(
'desc' => $this->l('Save'),
'href' => AdminController::$currentIndex . '&configure=' . $this->name . '&save' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules')
),
'back' => array(
'href' => AdminController::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Back to list')
)
);
//Load current value
$helper->fields_value['COOKIESINFO_LINK'] = Configuration::get('COOKIESINFO_LINK');
$helper->fields_value['COOKIESINFO_INTRO'] = Configuration::get('COOKIESINFO_INTRO');
return $helper->generateForm($fields_form);
}
public function hookDisplayHeader($params)
{
if(!$this->context->cookie->cookies_info_viewed || $this->context->cookie->cookies_info_viewed == 'unviewed')
{
if(!$this->context->cookie->cookies_info_viewed)
$this->context->cookie->__set('cookies_info_viewed', 'unviewed');
else
$this->context->cookie->__set('cookies_info_viewed', 'viewed');
$this->context->controller->addCSS($this->_path.'css/cookiesinfo.css', 'all');
$this->context->controller->addJS($this->_path.'js/cookiesinfo.js', 'all');
}
else
$this->context->cookie->__set('cookies_info_viewed', 'viewed');
}
public function hookDisplayFooter($params)
{
if($this->context->cookie->cookies_info_viewed == 'viewed')
return false;
else
{
$this->context->smarty->assign(array(
'cookies_intro' => Configuration::get('COOKIESINFO_INTRO'),
'cookies_link' => Configuration::get('COOKIESINFO_LINK')
));
return $this->display($this->_path, 'views/templates/hook/displayTop.tpl');
}
}
public function hookDisplayTop($params)
{
return $this->hookDisplayFooter($params);
}
}