From d9803ce0864f47bd07279725b118652f42dcfb90 Mon Sep 17 00:00:00 2001
From: Vincent Augagneur
Date: Tue, 24 Sep 2013 17:26:28 +0200
Subject: [PATCH] //newsletter now use bootstrap design
---
modules/newsletter/newsletter.php | 206 +++++++++++++++++++++---------
1 file changed, 148 insertions(+), 58 deletions(-)
diff --git a/modules/newsletter/newsletter.php b/modules/newsletter/newsletter.php
index e125305b9..9aac8ac88 100644
--- a/modules/newsletter/newsletter.php
+++ b/modules/newsletter/newsletter.php
@@ -93,9 +93,9 @@ class Newsletter extends Module
private function _postProcess()
{
- if (isset($_POST['submitExport']) AND isset($_POST['action']))
+ if (Tools::isSubmit('submitExport') && $action = Tools::getValue('action'))
{
- if ($_POST['action'] == 'customers')
+ if ($action == 'customers')
$result = $this->_getCustomers();
else
{
@@ -178,60 +178,6 @@ class Newsletter extends Module
$this->_postErrors[] = $this->l('Error: cannot write').' '.dirname(__FILE__).'/'.$this->_file.' !';
}
- private function _displayFormExport()
- {
- $this->_html .= '
-
-
-
- ';
- }
-
private function _displayForm()
{
$this->_displayFormExport();
@@ -239,13 +185,157 @@ class Newsletter extends Module
public function getContent()
{
- $this->_html .= ''.$this->displayName.'
';
+ $this->_html .= '';
if (!empty($_POST))
$this->_html .= $this->_postProcess();
- $this->_displayForm();
+ $this->_html .= $this->renderForm();
return $this->_html;
}
+
+ public function renderForm()
+ {
+
+ // Getting data...
+ $_countries = Country::getCountries($this->context->language->id);
+
+ // ...formatting array
+ $countries[0] = array('id' => 0, 'name' => $this->l('All countries'));
+ foreach ($_countries as $country)
+ $countries[] = array('id' => $country['id_country'], 'name' => $country['name']);
+
+ // And filling fields to show !
+ $this->_fieldsExport = array(
+ 'COUNTRY' => array(
+ 'title' => $this->l('Customers\' country'),
+ 'desc' => $this->l('Operate a filter on customers\' country.'),
+ 'type' => 'select',
+ 'value' => $countries,
+ 'value_default' => 0
+ ),
+ 'SUSCRIBERS' => array(
+ 'title' => $this->l('Newsletter subscribers'),
+ 'desc' => $this->l('Filter newsletter subscribers.'),
+ 'type' => 'select',
+ 'value' => array(0 => $this->l('All customers'), 2 => $this->l('Subscribers'), 1 => $this->l('Non-subscribers')),
+ 'value_default' => 2
+ ),
+ 'OPTIN' => array(
+ 'title' => $this->l('Opted-in subscribers'),
+ 'desc' => $this->l('Filter opted-in subscribers.'),
+ 'type' => 'select',
+ 'value' => array(0 => $this->l('All customers'), 2 => $this->l('Subscribers'), 1 => $this->l('Non-subscribers')),
+ 'value_default' => 0
+ ),
+ );
+
+ $fields_form_1 = array(
+ 'form' => array(
+ 'legend' => array(
+ 'title' => $this->l('Export Newsletter Subscribers'),
+ 'icon' => 'icon-envelope'
+ ),
+ 'desc' => array(
+ array('text' => $this->l('Generate a .CSV file based on BlockNewsletter subscribers data. Only subscribers without an account on the shop will be exported.'))
+ ),
+ 'submit' => array(
+ 'title' => $this->l('Export .CSV file'),
+ 'class' => 'btn btn-primary',
+ 'name' => 'submitExport',
+ )
+ ),
+ );
+
+ $fields_form_2 = array(
+ 'form' => array(
+ 'legend' => array(
+ 'title' => $this->l('Export customers'),
+ 'icon' => 'icon-envelope'
+ ),
+ 'input' => array(
+ array(
+ 'type' => 'select',
+ 'label' => $this->l('Customers\' country :'),
+ 'desc' => $this->l('Operate a filter on customers\' country.'),
+ 'name' => 'COUNTRY',
+ 'required' => false,
+ 'default_value' => (int)$this->context->country->id,
+ 'options' => array(
+ 'query' => $countries,
+ 'id' => 'id',
+ 'name' => 'name',
+ )
+ ),
+ array(
+ 'type' => 'select',
+ 'label' => $this->l('Newsletter subscribers :'),
+ 'desc' => $this->l('Filter newsletter subscribers.'),
+ 'name' => 'SUSCRIBERS',
+ 'required' => false,
+ 'default_value' => (int)$this->context->country->id,
+ 'options' => array(
+ 'query' => array(array('id' => 0, 'name' => $this->l('All customers')), array('id' => 2, 'name' => $this->l('Subscribers')), array('id' => 1, 'name' => $this->l('Non-subscribers'))),
+ 'id' => 'id',
+ 'name' => 'name',
+ )
+ ),
+ array(
+ 'type' => 'select',
+ 'label' => $this->l('Opted-in subscribers :'),
+ 'desc' => $this->l('Filter opted-in subscribers.'),
+ 'name' => 'OPTIN',
+ 'required' => false,
+ 'default_value' => (int)$this->context->country->id,
+ 'options' => array(
+ 'query' => array(array('id' => 0, 'name' => $this->l('All customers')), array('id' => 2, 'name' => $this->l('Subscribers')), array('id' => 1, 'name' => $this->l('Non-subscribers'))),
+ 'id' => 'id',
+ 'name' => 'name',
+ )
+ ),
+ array(
+ 'type' => 'hidden',
+ 'name' => 'action',
+ )
+ ),
+ 'submit' => array(
+ 'title' => $this->l('Export .CSV file'),
+ 'class' => 'btn btn-primary',
+ 'name' => 'submitExport',
+ )
+ ),
+ );
+
+ $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;
+ $this->fields_form = array();
+ $helper->id = (int)Tools::getValue('id_carrier');
+ $helper->identifier = $this->identifier;
+ $helper->submit_action = 'btnSubmit';
+ $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_1, $fields_form_2));
+ }
+
+ public function getConfigFieldsValues()
+ {
+ return array(
+ 'COUNTRY' => Tools::getValue('COUNTRY'),
+ 'SUSCRIBERS' => Tools::getValue('SUSCRIBERS'),
+ 'OPTIN' => Tools::getValue('OPTIN'),
+ 'action' => 'customers',
+ );
+ }
+
}