bebeboutik/modules/cookiesinfos/cookiesinfos.php
Srv Bebeboutik 6c0978166c add modules
2016-01-04 12:49:26 +01:00

139 lines
4.3 KiB
PHP
Executable File

<?php
/**
*
* @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('header') ||
!$this->registerHook('footer') ||
!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() {
global $cookie;
/* Language */
$defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
$languages = Language::getLanguages(FALSE);
$divLangName = 'link¤intro';
if (Tools::isSubmit('submitConfig')) {
foreach ($languages as $language) {
Configuration::updateValue('COOKIESINFO_LINK'.'_'.$language['id_lang'], Tools::getValue('link'.'_'.$language['id_lang']));
Configuration::updateValue('COOKIESINFO_INTRO'.'_'.$language['id_lang'], Tools::getValue('intro'.'_'.$language['id_lang']));
}
echo '<div class="conf">Mise à jour avec succès</div>';
}
echo '
<script type="text/javascript">
id_language = Number('.$defaultLanguage.');
</script>
<fieldset>
<legend>Configuration</legend>
<form method="post" action="'.$_SERVER['REQUEST_URI'].'">
<label>Link</label>
<div class="margin-form">';
foreach ($languages as $language) {
echo '<div id="link_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').'; float: left;">';
echo '<input type="text" value="'.Configuration::get('COOKIESINFO_LINK'.'_'.$language['id_lang']).'" name="link_'.$language['id_lang'].'" />';
echo '</div>';
}
echo $this->displayFlags($languages, $defaultLanguage, $divLangName, 'link', true);
echo '<div class="clear"></div>
</div>
<label>Intro text</label>
<div class="margin-form">';
foreach ($languages as $language) {
echo '<div id="intro_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').'; float: left;">';
echo '<input type="text" value="'.Configuration::get('COOKIESINFO_INTRO'.'_'.$language['id_lang']).'" name="intro_'.$language['id_lang'].'" />';
echo '</div>';
}
echo $this->displayFlags($languages, $defaultLanguage, $divLangName, 'intro', true);
echo '<div class="clear"></div>
</div>
<div style="margin:20px 20px 0 0">
<input class="button" type="submit" name="submitConfig" value="Enregistrer" />
<input type="hidden" id="languageFirst" value="'.$languages[0]['id_lang'].'" />
<input type="hidden" id="languageNb" value="'.sizeof($languages).'" />
</div>
</form>
</fieldset>
';
}
public function hookHeader($params)
{
if (Tools::getValue('cookie') ) {
setcookie('cookie_info', 1, time() + (365 * 24 * 60 * 60) , '/');
Tools::redirect($_SERVER['HTTP_REFERER']);
}
if(!isset($_COOKIE['cookie_info']) || $_COOKIE['cookie_info'] != 1) {
Tools::addCSS(($this->_path).'css/cookiesinfo.css', 'all');
Tools::addJS(($this->_path).'js/cookiesinfo.js');
}
}
public function hookFooter($params)
{
global $smarty, $cookie;
if(isset($_COOKIE['cookie_info']) && $_COOKIE['cookie_info'] == 1
|| isset($_GET['lp'])
|| isset($_GET['sponsor'])
) {
return FALSE;
} else {
$smarty->assign(array(
'cookies_intro' => Configuration::get('COOKIESINFO_INTRO_'.$cookie->id_lang),
'cookies_link' => Configuration::get('COOKIESINFO_LINK_'.$cookie->id_lang)
));
return $this->display($this->_path, 'views/templates/hook/displayTop.tpl');
}
}
}