privilegedemarque/modules/ant_nw_frequences/controllers/front/frequence.php

72 lines
2.1 KiB
PHP

<?php
/**
* @company Antadis
*/
class ant_nw_frequencesfrequenceModuleFrontController extends ModuleFrontController
{
public function init()
{
parent::init();
if (!$this->context->customer->isLogged()){
Tools::redirect('index.php?controller=authentication&back=modules/ant_nw_frequences/ant_nw_frequences-frequence.php');
}
$this->customer = $this->context->customer;
}
public function initContent()
{
parent::initContent();
if (Module::isInstalled('blocknewsletter')) {
$this->context->smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active);
}
if ((int)$this->customer->newsletter == 1) {
$this->context->smarty->assign('frequence_nw', $this->customer->frequence_nw);
}
else {
$this->context->smarty->assign('frequence_nw', 'unsub');
}
$this->setTemplate('frequence.tpl');
}
public function postProcess()
{
$origin_newsletter = (bool)$this->customer->newsletter;
if (Tools::isSubmit('submitFrequence')){
$freq = Tools::getValue('frequence_nw', '0');
if ($freq == 'unsub') {
$this->customer->newsletter = 0;
}
else {
if (!$origin_newsletter) {
$this->customer->newsletter = 1;
if ($module_newsletter = Module::getInstanceByName('blocknewsletter')) {
if ($module_newsletter->active) {
$module_newsletter->confirmSubscription($this->customer->email);
}
}
}
$this->customer->frequence_nw = (int)$freq;
}
if ($this->customer->update()) {
if ($freq == 'unsub') {
$this->context->smarty->assign('confirmation_unsub', 1);
}
else {
$this->context->smarty->assign('confirmation', 1);
}
}
}
return true;
}
}