diff --git a/modules/blocknewsletter/blocknewsletter.php b/modules/blocknewsletter/blocknewsletter.php
index 7be501823..023771df5 100644
--- a/modules/blocknewsletter/blocknewsletter.php
+++ b/modules/blocknewsletter/blocknewsletter.php
@@ -90,55 +90,28 @@ class Blocknewsletter extends Module
public function getContent()
{
- $this->_html = '
'.$this->displayName.'
';
+ $this->_html = '';
if (Tools::isSubmit('submitUpdate'))
{
- if (isset($_POST['conf_email']) && Validate::isBool((int)$_POST['conf_email']))
- Configuration::updateValue('NW_CONFIRMATION_EMAIL', pSQL($_POST['conf_email']));
+ $conf_email = Tools::getValue('NW_CONFIRMATION_EMAIL');
+ if ($conf_email && Validate::isBool((int)$conf_email))
+ Configuration::updateValue('NW_CONFIRMATION_EMAIL', (int)$conf_email);
- if (isset($_POST['verif_email']) && Validate::isBool((int)$_POST['verif_email']))
- Configuration::updateValue('NW_VERIFICATION_EMAIL', (int)$_POST['verif_email']);
-
- if (!empty($_POST['voucher']) && !Validate::isDiscountName($_POST['voucher']))
- $this->_html .= ''.$this->l('The coucher code is invalid.').'
';
+ $verif_email = Tools::getValue('NW_VERIFICATION_EMAIL');
+ if ($verif_email && Validate::isBool((int)$verif_email))
+ Configuration::updateValue('NW_VERIFICATION_EMAIL', (int)$verif_email);
+
+ $voucher = Tools::getValue('NW_VOUCHER_CODE');
+ if ($voucher && !Validate::isDiscountName($voucher))
+ $this->_html .= $this->displayError($this->l('The coucher code is invalid.'));
else
{
- Configuration::updateValue('NW_VOUCHER_CODE', pSQL($_POST['voucher']));
- $this->_html .= ''.$this->l('Updated').'
';
+ Configuration::updateValue('NW_VOUCHER_CODE', pSQL($voucher));
+ $this->_html .= $this->displayConfirmation($this->l('Settings updated'));
}
}
- return $this->_displayForm();
- }
-
- private function _displayForm()
- {
- $this->_html .= '
- ';
-
- return $this->_html;
+ return $this->_html.$this->renderForm();
}
/**
@@ -530,4 +503,89 @@ class Blocknewsletter extends Module
return (bool)Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'newsletter WHERE id_shop='.(int)$id_shop.' AND email=\''.pSQL($email)."'");
return true;
}
+
+ public function renderForm()
+ {
+ $fields_form = array(
+ 'form' => array(
+ 'legend' => array(
+ 'title' => $this->l('Settings'),
+ 'icon' => 'icon-cogs'
+ ),
+ 'input' => array(
+ array(
+ 'type' => 'switch',
+ 'label' => $this->l('Would you like to send a verification email after subscription?'),
+ 'name' => 'NW_VERIFICATION_EMAIL',
+ 'values' => array(
+ array(
+ 'id' => 'active_on',
+ 'value' => 1,
+ 'label' => $this->l('Enabled')
+ ),
+ array(
+ 'id' => 'active_off',
+ 'value' => 0,
+ 'label' => $this->l('Disabled')
+ )
+ ),
+ ),
+ array(
+ 'type' => 'switch',
+ 'label' => $this->l('Would you like to send a confirmation email after subscription?'),
+ 'name' => 'NW_CONFIRMATION_EMAIL',
+ 'values' => array(
+ array(
+ 'id' => 'active_on',
+ 'value' => 1,
+ 'label' => $this->l('Enabled')
+ ),
+ array(
+ 'id' => 'active_off',
+ 'value' => 0,
+ 'label' => $this->l('Disabled')
+ )
+ ),
+ ),
+ array(
+ 'type' => 'text',
+ 'label' => $this->l('Welcome voucher code'),
+ 'name' => 'NW_VOUCHER_CODE',
+ 'class' => '.fixed-width-md',
+ 'desc' => $this->l('Leave blank to disable by default.')
+ ),
+ ),
+ 'submit' => array(
+ 'title' => $this->l('Save'),
+ 'class' => 'btn btn-primary')
+ ),
+ );
+
+ $helper = new HelperForm();
+ $helper->show_toolbar = false;
+ $helper->table = $this->table;
+ $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
+ $helper->default_form_language = $lang->id;
+ $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
+ $helper->identifier = $this->identifier;
+ $helper->submit_action = 'submitUpdate';
+ $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
+ $helper->token = Tools::getAdminTokenLite('AdminModules');
+ $helper->tpl_vars = array(
+ 'fields_value' => $this->getConfigFieldsValues(),
+ 'languages' => $this->context->controller->getLanguages(),
+ 'id_language' => $this->context->language->id
+ );
+
+ return $helper->generateForm(array($fields_form));
+ }
+
+ public function getConfigFieldsValues()
+ {
+ return array(
+ 'NW_VERIFICATION_EMAIL' => Tools::getValue('NW_VERIFICATION_EMAIL', Configuration::get('NW_VERIFICATION_EMAIL')),
+ 'NW_CONFIRMATION_EMAIL' => Tools::getValue('NW_CONFIRMATION_EMAIL', Configuration::get('NW_CONFIRMATION_EMAIL')),
+ 'NW_VOUCHER_CODE' => Tools::getValue('NW_VOUCHER_CODE', Configuration::get('NW_VOUCHER_CODE')),
+ );
+ }
}