From 4464875a14ba08249edb728af5232574fd61cb5f Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Wed, 30 Aug 2023 19:00:30 +0530 Subject: [PATCH 01/10] Improve blocknewsletter module --- .../AdminCustomerPreferencesController.php | 7 -- .../admin/AdminCustomersController.php | 2 +- controllers/front/AuthController.php | 2 +- controllers/front/IdentityController.php | 2 +- controllers/front/OrderOpcController.php | 2 +- install/data/xml/configuration.xml | 3 - modules/blocknewsletter/blocknewsletter.php | 59 ++++++++--------- .../controllers/front/subscription.php | 52 +++++++++++++++ .../front/subscription_execution.tpl | 25 ++++++++ .../views/templates/hook/blocknewsletter.tpl | 64 ------------------- themes/hotel-reservation-theme/css/global.css | 14 ++-- .../blocknewsletter/blocknewsletter.css | 13 ++-- .../blocknewsletter/blocknewsletter.js | 53 ++++++--------- .../blocknewsletter/blocknewsletter.tpl | 30 ++++----- 14 files changed, 158 insertions(+), 170 deletions(-) create mode 100644 modules/blocknewsletter/controllers/front/subscription.php create mode 100644 modules/blocknewsletter/views/templates/front/subscription_execution.tpl diff --git a/controllers/admin/AdminCustomerPreferencesController.php b/controllers/admin/AdminCustomerPreferencesController.php index 00c2a9e68..d5599879b 100644 --- a/controllers/admin/AdminCustomerPreferencesController.php +++ b/controllers/admin/AdminCustomerPreferencesController.php @@ -99,13 +99,6 @@ class AdminCustomerPreferencesControllerCore extends AdminController 'cast' => 'intval', 'type' => 'bool' ), - 'PS_CUSTOMER_NWSL' => array( - 'title' => $this->l('Enable newsletter registration'), - 'hint' => $this->l('Display or not the newsletter registration tick box.'), - 'validation' => 'isBool', - 'cast' => 'intval', - 'type' => 'bool' - ), 'PS_CUSTOMER_OPTIN' => array( 'title' => $this->l('Enable opt-in'), 'hint' => $this->l('Display or not the opt-in tick box, to receive offers from the store\'s partners.'), diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index b7078a0f1..de8507cfc 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -458,7 +458,7 @@ class AdminCustomersControllerCore extends AdminController 'label' => $this->l('Disabled') ) ), - 'disabled' => (bool)!Configuration::get('PS_CUSTOMER_NWSL'), + 'disabled' => true, 'hint' => $this->l('This customer will receive your newsletter via email.') ), array( diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index 320da13dd..53fd39763 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -100,7 +100,7 @@ class AuthControllerCore extends FrontController $this->assignCountries(); - $newsletter = Configuration::get('PS_CUSTOMER_NWSL') || (Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active); + $newsletter = Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active; $this->context->smarty->assign('newsletter', $newsletter); $this->context->smarty->assign('optin', (bool)Configuration::get('PS_CUSTOMER_OPTIN')); diff --git a/controllers/front/IdentityController.php b/controllers/front/IdentityController.php index ea8c2af16..e41ba9476 100644 --- a/controllers/front/IdentityController.php +++ b/controllers/front/IdentityController.php @@ -151,7 +151,7 @@ class IdentityControllerCore extends FrontController 'HOOK_CUSTOMER_IDENTITY_FORM' => Hook::exec('displayCustomerIdentityForm'), )); - $newsletter = Configuration::get('PS_CUSTOMER_NWSL') || (Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active); + $newsletter = Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active; $this->context->smarty->assign('newsletter', $newsletter); $this->context->smarty->assign('optin', (bool)Configuration::get('PS_CUSTOMER_OPTIN')); diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 17ef02dcb..2c5c02b3d 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -519,7 +519,7 @@ class OrderOpcControllerCore extends ParentOrderController } Tools::safePostVars(); - $newsletter = Configuration::get('PS_CUSTOMER_NWSL') || (Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active); + $newsletter = Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active; $this->context->smarty->assign('newsletter', $newsletter); $this->context->smarty->assign('optin', (bool)Configuration::get('PS_CUSTOMER_OPTIN')); $this->context->smarty->assign('field_required', $this->context->customer->validateFieldsRequiredDatabase()); diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml index 935de20ba..746c940a6 100644 --- a/install/data/xml/configuration.xml +++ b/install/data/xml/configuration.xml @@ -878,9 +878,6 @@ 1 - - 1 - 1 diff --git a/modules/blocknewsletter/blocknewsletter.php b/modules/blocknewsletter/blocknewsletter.php index 1bca820ef..4049ab084 100644 --- a/modules/blocknewsletter/blocknewsletter.php +++ b/modules/blocknewsletter/blocknewsletter.php @@ -50,6 +50,7 @@ class Blocknewsletter extends Module $this->description = $this->l('Adds a block for newsletter subscription.'); $this->confirmUninstall = $this->l('Are you sure that you want to delete all of your contacts?'); $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); + $this->secure_key = Tools::encrypt($this->name); $this->version = '2.2.2'; $this->author = 'PrestaShop'; @@ -66,6 +67,8 @@ class Blocknewsletter extends Module $this->_searched_email = null; $this->_html = ''; + + $this->hookPrepared = false; } public function registerHooks() @@ -128,7 +131,7 @@ class Blocknewsletter extends Module public function uninstall() { - Db::getInstance()->execute('DROP TABLE '._DB_PREFIX_.'newsletter'); + Db::getInstance()->execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'newsletter'); return parent::uninstall(); } @@ -141,6 +144,8 @@ class Blocknewsletter extends Module $voucher = Tools::getValue('NW_VOUCHER_CODE'); if ($voucher && !Validate::isDiscountName($voucher)) { $this->_html .= $this->displayError($this->l('The voucher code is invalid.')); + } elseif (!CartRule::cartRuleExists($voucher)) { + $this->_html .= $this->displayError($this->l('The voucher code does not exist.')); } else { Configuration::updateValue('NW_VOUCHER_CODE', pSQL($voucher)); $this->_html .= $this->displayConfirmation($this->l('Settings updated')); @@ -292,7 +297,7 @@ class Blocknewsletter extends Module { $this->smarty->assign( array( - 'href' => 'index.php?controller=AdminCustomers&id_customer='.(int)$id.'&updatecustomer&token='. + 'href' => 'index.php?controller=AdminCustomers&id_customer='.(int)$id.'&viewcustomer&token='. Tools::getAdminTokenLite('AdminCustomers'), 'action' => $this->l('View'), 'disable' => !((int)$id > 0), @@ -368,14 +373,14 @@ class Blocknewsletter extends Module /** * Register in block newsletter */ - protected function newsletterRegistration() + public function newsletterRegistration() { if (empty($_POST['email']) || !Validate::isEmail($_POST['email'])) { return $this->error = $this->l('Invalid email address.'); } /* Unsubscription */ - elseif ($_POST['action'] == '1') { + elseif ($_POST['newsletter_action'] == '1') { $register_status = $this->isNewsletterRegistered($_POST['email']); if ($register_status < 1) { @@ -389,7 +394,7 @@ class Blocknewsletter extends Module return $this->valid = $this->l('Unsubscription successful.'); } /* Subscription */ - elseif ($_POST['action'] == '0') { + elseif ($_POST['newsletter_action'] == '0') { $register_status = $this->isNewsletterRegistered($_POST['email']); if ($register_status > 0) { return $this->error = $this->l('This email address is already registered.'); @@ -744,38 +749,25 @@ class Blocknewsletter extends Module protected function _prepareHook($params) { - if (Tools::isSubmit('submitNewsletter')) { - $this->newsletterRegistration(); - if ($this->error) { - $this->smarty->assign( - array( - 'color' => 'red', - 'msg' => $this->error, - 'nw_value' => isset($_POST['email']) ? pSQL($_POST['email']) : false, - 'nw_error' => true, - 'action' => $_POST['action'] - ) - ); - } elseif ($this->valid) { - $this->smarty->assign( - array( - 'color' => 'green', - 'msg' => $this->valid, - 'nw_error' => false - ) - ); - } + if (!$this->hookPrepared) { + $this->context->smarty->assign(array( + 'csrf_token' => $this->secure_key, + )); + + Media::addJsDef(array( + 'url_newsletter_subscription' => $this->context->link->getModuleLink($this->name, 'subscription'), + )); + + $this->hookPrepared = true; } - $this->smarty->assign('this_path', $this->_path); } public function hookDisplayLeftColumn($params) { - if (!isset($this->prepared) || !$this->prepared) { - $this->_prepareHook($params); - } - $this->prepared = true; + $this->_prepareHook($params); + $this->smarty->assign(array('id_module' => $this->id)); + return $this->display(__FILE__, 'blocknewsletter.tpl'); } @@ -872,7 +864,10 @@ class Blocknewsletter extends Module 'label' => $this->l('Welcome voucher code'), 'name' => 'NW_VOUCHER_CODE', 'class' => 'fixed-width-md', - 'desc' => $this->l('Leave blank to disable by default.') + 'desc' => sprintf( + $this->l('You can create a voucher from %s page. Leave blank to disable by default.'), + ''.$this->l('Cart Rules').'' + ) ), ), 'submit' => array( diff --git a/modules/blocknewsletter/controllers/front/subscription.php b/modules/blocknewsletter/controllers/front/subscription.php new file mode 100644 index 000000000..c6aa1bdd1 --- /dev/null +++ b/modules/blocknewsletter/controllers/front/subscription.php @@ -0,0 +1,52 @@ +content_only = true; + } + + public function checkAccess() + { + return strcmp(Tools::getValue('token', ''), $this->module->secure_key) === 0; + } + + public function displayAjaxSubscribeNewsletter() + { + $this->module->newsletterRegistration(); + + $this->context->smarty->assign(array( + 'message_type' => ($this->module->valid && !$this->module->error) ? 'success' : 'error', + 'message' => ($this->module->valid && !$this->module->error) ? $this->module->valid : $this->module->error, + )); + + $response = array( + 'status' => true, + 'message_html' => $this->context->smarty->fetch( + $this->module->getTemplatePath('subscription_execution.tpl') + ), + ); + + $this->ajaxDie(json_encode($response)); + } +} diff --git a/modules/blocknewsletter/views/templates/front/subscription_execution.tpl b/modules/blocknewsletter/views/templates/front/subscription_execution.tpl new file mode 100644 index 000000000..4e7a0985c --- /dev/null +++ b/modules/blocknewsletter/views/templates/front/subscription_execution.tpl @@ -0,0 +1,25 @@ +{** + * 2010-2023 Webkul. + * + * NOTICE OF LICENSE + * + * All right is reserved, + * Please go through LICENSE.txt file inside our module + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please refer to CustomizationPolicy.txt file inside our module for more information. + * + * @author Webkul IN + * @copyright 2010-2023 Webkul IN + * @license LICENSE.txt + *} + +{if isset($message_type) && isset($message)} +

+ {$message} + +

+{/if} diff --git a/modules/blocknewsletter/views/templates/hook/blocknewsletter.tpl b/modules/blocknewsletter/views/templates/hook/blocknewsletter.tpl index be560aac7..e69de29bb 100644 --- a/modules/blocknewsletter/views/templates/hook/blocknewsletter.tpl +++ b/modules/blocknewsletter/views/templates/hook/blocknewsletter.tpl @@ -1,64 +0,0 @@ -{* -* 2007-2015 PrestaShop -* -* NOTICE OF LICENSE -* -* This source file is subject to the Academic Free License (AFL 3.0) -* that is bundled with this package in the file LICENSE.txt. -* It is also available through the world-wide-web at this URL: -* http://opensource.org/licenses/afl-3.0.php -* If you did not receive a copy of the license and are unable to -* obtain it through the world-wide-web, please send an email -* to license@prestashop.com so we can send you a copy immediately. -* -* DISCLAIMER -* -* Do not edit or add to this file if you wish to upgrade PrestaShop to newer -* versions in the future. If you wish to customize PrestaShop for your -* needs please refer to http://www.prestashop.com for more information. -* -* @author PrestaShop SA -* @copyright 2007-2015 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*} - - -
-
- -
-
-
- - {* Hook added for GDPR *} - {if isset($id_module)} - {hook h='displayGDPRConsent' id_module=$id_module} - {/if} - - -
-
-
- {hook h="displayBlockNewsletterBottom" from='blocknewsletter'} -
-
- -{strip} -{if isset($msg) && $msg} -{addJsDef msg_newsl=$msg|@addcslashes:'\''} -{/if} -{if isset($nw_error)} -{addJsDef nw_error=$nw_error} -{/if} -{addJsDefL name=placeholder_blocknewsletter}{l s='Enter your e-mail' mod='blocknewsletter' js=1}{/addJsDefL} -{addJsDefL name=email_js_error}{l s='Please Enter Valid E-mail' mod='blocknewsletter' js=1}{/addJsDefL} -{if isset($msg) && $msg} - {addJsDefL name=alert_blocknewsletter}{l s='Newsletter : %1$s' sprintf=$msg js=1 mod="blocknewsletter"}{/addJsDefL} -{/if} -{/strip} \ No newline at end of file diff --git a/themes/hotel-reservation-theme/css/global.css b/themes/hotel-reservation-theme/css/global.css index 3cd05730d..ffd074a29 100644 --- a/themes/hotel-reservation-theme/css/global.css +++ b/themes/hotel-reservation-theme/css/global.css @@ -2941,6 +2941,7 @@ a.thumbnail:focus { color: #777777; } .alert { + position: relative; padding: 15px; margin-bottom: 18px; border: 1px solid transparent; @@ -2959,10 +2960,15 @@ a.thumbnail:focus { .alert-dismissable { padding-right: 35px; } .alert-dismissable .close { - position: relative; - top: -2px; - right: -21px; - color: inherit; } + position: absolute; + top: 0; + right: 0; + padding: 5px 10px; + opacity: 0.5; + color: #000; + text-shadow: none; } + .alert-dismissable .close:hover { + color: #000; } .alert-success { background-color: #55c65e; diff --git a/themes/hotel-reservation-theme/css/modules/blocknewsletter/blocknewsletter.css b/themes/hotel-reservation-theme/css/modules/blocknewsletter/blocknewsletter.css index c6eec2db6..c519ac430 100644 --- a/themes/hotel-reservation-theme/css/modules/blocknewsletter/blocknewsletter.css +++ b/themes/hotel-reservation-theme/css/modules/blocknewsletter/blocknewsletter.css @@ -115,23 +115,24 @@ } #newsletter-input::-webkit-input-placeholder { - color: #ffffff; + color: #bfbfbf; } #newsletter-input:-moz-placeholder { /* Firefox 18- */ - color: #ffffff; + color: #bfbfbf; } #newsletter-input::-moz-placeholder { /* Firefox 19+ */ - color: #ffffff; + color: #bfbfbf; } -#newsletter-input:-ms-input-placeholder { - color: #ffffff; +#newsletter-input:-ms-input-placeholder { + color: #bfbfbf; } /*# sourceMappingURL=blocknewsletter.css.map */ .button.button-medium.newsletter-btn { + position: relative; padding: 0px 20px; } #newsletter-input @@ -142,4 +143,4 @@ font-size: 13px; height: 42px; margin-bottom: 10px; -} \ No newline at end of file +} diff --git a/themes/hotel-reservation-theme/js/modules/blocknewsletter/blocknewsletter.js b/themes/hotel-reservation-theme/js/modules/blocknewsletter/blocknewsletter.js index 4aefdf0cc..b907c15ee 100644 --- a/themes/hotel-reservation-theme/js/modules/blocknewsletter/blocknewsletter.js +++ b/themes/hotel-reservation-theme/js/modules/blocknewsletter/blocknewsletter.js @@ -22,39 +22,28 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ -$(document).ready(function() { - $('#newsletter-input').on({ - focus: function() { - if ($(this).val() == placeholder_blocknewsletter || $(this).val() == msg_newsl) - $(this).val(''); +$(document).on('click', '#blocknewsletter .newsletter-btn', function (e) { + e.preventDefault(); + + $.ajax({ + url: url_newsletter_subscription, + type: 'POST', + dataType: 'JSON', + cache: false, + data: $(this).closest('form').serialize(), + beforeSend: function () { + let messageBlock = $('#blocknewsletter .message-block'); + $(messageBlock).fadeOut('fast'); }, - blur: function() { - if ($(this).val() == '') - $(this).val(placeholder_blocknewsletter); + success: function (response) { + let messageBlock = $('#blocknewsletter .message-block'); + $(messageBlock).html(response.message_html).stop(true, true).fadeIn('fast'); + }, + error: function (jqXHR) { + if (jqXHR.readyState == 0) { + showErrorMessage(no_internet_txt); + } } }); - - var cssClass = 'alert alert-danger'; - if (typeof nw_error != 'undefined' && !nw_error) - cssClass = 'alert alert-success'; - - if (typeof msg_newsl != 'undefined' && msg_newsl) - { - $('#columns').prepend('

' + alert_blocknewsletter + '

'); - $('html, body').animate({scrollTop: $('#columns').offset().top}, 'slow'); - } - - $(".submitNewsletter").on("click", function() - { - var email = $("#newsletter-input").val(); - if (email == "" || !validate_isEmail(email)) - { - $("#newsletter-input").popover({content: email_js_error, placement: "top", container: "body"}); - $("#newsletter-input").popover("show"); - return false; - } - - return true; - }); -}); \ No newline at end of file +}); diff --git a/themes/hotel-reservation-theme/modules/blocknewsletter/blocknewsletter.tpl b/themes/hotel-reservation-theme/modules/blocknewsletter/blocknewsletter.tpl index e902ecbc3..8fdbcaaf4 100644 --- a/themes/hotel-reservation-theme/modules/blocknewsletter/blocknewsletter.tpl +++ b/themes/hotel-reservation-theme/modules/blocknewsletter/blocknewsletter.tpl @@ -25,15 +25,20 @@
-
+
-
-
- + +
+ + + + + + {* Hook added for GDPR *} {if isset($id_module)} {hook h='displayGDPRConsent' id_module=$id_module} @@ -41,24 +46,13 @@ -
{hook h="displayBlockNewsletterBottom" from='blocknewsletter'}
+ +{addJsDefL name=no_internet_txt}{l s='No internet. Please try later.' mod='blocknewsletter' js=1}{/addJsDefL} + -{strip} -{if isset($msg) && $msg} -{addJsDef msg_newsl=$msg|@addcslashes:'\''} -{/if} -{if isset($nw_error)} -{addJsDef nw_error=$nw_error} -{/if} -{addJsDefL name=placeholder_blocknewsletter}{l s='Enter your e-mail' mod='blocknewsletter' js=1}{/addJsDefL} -{addJsDefL name=email_js_error}{l s='Please Enter Valid E-mail' mod='blocknewsletter' js=1}{/addJsDefL} -{if isset($msg) && $msg} - {addJsDefL name=alert_blocknewsletter}{l s='Newsletter : %1$s' sprintf=$msg js=1 mod="blocknewsletter"}{/addJsDefL} -{/if} -{/strip} From 22468f6c854146764f542e2a1657ec47616ff653 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 1 Sep 2023 13:31:29 +0530 Subject: [PATCH 02/10] Add newsletter enable option in module --- .../admin/AdminCustomersController.php | 2 +- controllers/front/AuthController.php | 2 +- controllers/front/IdentityController.php | 2 +- controllers/front/OrderOpcController.php | 2 +- install/data/xml/configuration.xml | 3 +++ modules/blocknewsletter/blocknewsletter.php | 19 +++++++++++++++++++ 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index de8507cfc..a9bc64895 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -458,7 +458,7 @@ class AdminCustomersControllerCore extends AdminController 'label' => $this->l('Disabled') ) ), - 'disabled' => true, + 'disabled' => (bool)!Configuration::get('PS_CUSTOMER_NEWSLETTER'), 'hint' => $this->l('This customer will receive your newsletter via email.') ), array( diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index 53fd39763..95c532e3d 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -100,7 +100,7 @@ class AuthControllerCore extends FrontController $this->assignCountries(); - $newsletter = Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active; + $newsletter = Module::isEnabled('blocknewsletter') && Configuration::get('PS_CUSTOMER_NEWSLETTER'); $this->context->smarty->assign('newsletter', $newsletter); $this->context->smarty->assign('optin', (bool)Configuration::get('PS_CUSTOMER_OPTIN')); diff --git a/controllers/front/IdentityController.php b/controllers/front/IdentityController.php index e41ba9476..39231664d 100644 --- a/controllers/front/IdentityController.php +++ b/controllers/front/IdentityController.php @@ -151,7 +151,7 @@ class IdentityControllerCore extends FrontController 'HOOK_CUSTOMER_IDENTITY_FORM' => Hook::exec('displayCustomerIdentityForm'), )); - $newsletter = Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active; + $newsletter = Module::isEnabled('blocknewsletter') && Configuration::get('PS_CUSTOMER_NEWSLETTER'); $this->context->smarty->assign('newsletter', $newsletter); $this->context->smarty->assign('optin', (bool)Configuration::get('PS_CUSTOMER_OPTIN')); diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 2c5c02b3d..4be955e76 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -519,7 +519,7 @@ class OrderOpcControllerCore extends ParentOrderController } Tools::safePostVars(); - $newsletter = Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active; + $newsletter = Module::isEnabled('blocknewsletter') && Configuration::get('PS_CUSTOMER_NEWSLETTER'); $this->context->smarty->assign('newsletter', $newsletter); $this->context->smarty->assign('optin', (bool)Configuration::get('PS_CUSTOMER_OPTIN')); $this->context->smarty->assign('field_required', $this->context->customer->validateFieldsRequiredDatabase()); diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml index 746c940a6..87d2dff7f 100644 --- a/install/data/xml/configuration.xml +++ b/install/data/xml/configuration.xml @@ -878,6 +878,9 @@ 1 + + 1 + 1 diff --git a/modules/blocknewsletter/blocknewsletter.php b/modules/blocknewsletter/blocknewsletter.php index 4049ab084..67b08eca6 100644 --- a/modules/blocknewsletter/blocknewsletter.php +++ b/modules/blocknewsletter/blocknewsletter.php @@ -138,6 +138,7 @@ class Blocknewsletter extends Module public function getContent() { if (Tools::isSubmit('submitUpdate')) { + Configuration::updateValue('PS_CUSTOMER_NEWSLETTER', (bool)Tools::getValue('PS_CUSTOMER_NEWSLETTER')); Configuration::updateValue('NW_CONFIRMATION_EMAIL', (bool)Tools::getValue('NW_CONFIRMATION_EMAIL')); Configuration::updateValue('NW_VERIFICATION_EMAIL', (bool)Tools::getValue('NW_VERIFICATION_EMAIL')); @@ -825,6 +826,23 @@ class Blocknewsletter extends Module 'icon' => 'icon-cogs' ), 'input' => array( + array( + 'type' => 'switch', + 'label' => $this->l('Enable newsletter registration'), + 'name' => 'PS_CUSTOMER_NEWSLETTER', + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Yes') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('No') + ) + ), + ), array( 'type' => 'switch', 'label' => $this->l('Would you like to send a verification email after subscription?'), @@ -971,6 +989,7 @@ class Blocknewsletter extends Module public function getConfigFieldsValues() { return array( + 'PS_CUSTOMER_NEWSLETTER' => Tools::getValue('PS_CUSTOMER_NEWSLETTER', Configuration::get('PS_CUSTOMER_NEWSLETTER')), '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')), From 1db2dc767208f1cb86dfc94c7f3de846c153d5ef Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 1 Sep 2023 14:17:13 +0530 Subject: [PATCH 03/10] Copy files from theme to module --- modules/blocknewsletter/blocknewsletter.css | 199 +++++++++++++----- modules/blocknewsletter/blocknewsletter.js | 49 +++++ .../views/templates/hook/blocknewsletter.tpl | 58 +++++ 3 files changed, 252 insertions(+), 54 deletions(-) diff --git a/modules/blocknewsletter/blocknewsletter.css b/modules/blocknewsletter/blocknewsletter.css index 8928dd158..986403c8b 100644 --- a/modules/blocknewsletter/blocknewsletter.css +++ b/modules/blocknewsletter/blocknewsletter.css @@ -1,56 +1,147 @@ /* Block newsletter */ -#newsletter_block_left { - padding:7px; - border:1px solid #ccc; - background:#eee; -} -#newsletter_block_left .title_block, #newsletter_block_left h4 { - padding:0 0 12px 28px; - color:#666; - text-shadow:0 1px 0 #fff; - background:url(img/icon/newsletter.png) no-repeat 0 0 transparent; -} -#newsletter_block_left p {padding:0;} - -#newsletter_block_left p.success_inline { - color: #418B19; - text-align: center; - font-weight: bold; -} -#newsletter_block_left p.warning_inline { - color: #DA0F00; - text-align: center; - font-weight: bold; -} - -#newsletter_block_left input.inputNew { +#columns #newsletter_block_left .form-group { + margin-bottom: 0; } + #columns #newsletter_block_left .form-group .form-control { + max-width: 222px; + display: inline-block; + margin-right: 6px; } + @media (min-width: 768px) and (max-width: 1199px) { + #columns #newsletter_block_left .form-group .form-control { + margin-bottom: 10px; + margin-right: 0; } } + #columns #newsletter_block_left .success_inline, #columns #newsletter_block_left .warning_inline { + text-align: left; + padding: 1px 0 0 0; + margin-bottom: -19px; } + #columns #newsletter_block_left .success_inline { + color: #418B19; } + #columns #newsletter_block_left .warning_inline { + color: #f13340; } + + /* Block newsletter footer */ + #footer #newsletter_block_left { + overflow: hidden; + /*width: 50%;*//*by webkul*/ + float: left; + padding: 13px 15px 7px 15px; + height: 70px;/*by webkul*/ + margin-bottom: 0; } + @media (max-width: 992px) { + #footer #newsletter_block_left { + height: 100px; } + #newsletter_block_left .block_content + { + width: 350px; + margin: 10px auto 0px; + }} + @media (max-width: 400px) { + #newsletter_block_left .block_content + { + width: 273px; + }} + @media (max-width: 767px) { + #footer #newsletter_block_left { + /*width: 100%;*/ + height: auto; } } + #footer #newsletter_block_left h4 { + background: none; + float: left; + padding: 7px 16px 5px 0; + text-transform: none; + font-size: 21px; + line-height: 25px; + border: none; } + #footer #newsletter_block_left h4:after { + display: none; } + #footer #newsletter_block_left .block_content { + overflow: hidden; } + #footer #newsletter_block_left .form-group { + margin-bottom: 0; } + #footer #newsletter_block_left .form-group .form-control { + height: 45px; + max-width: 267px; + background: #3c3c3c; + border-color: #515151; + color: #fff; + padding: 10px 43px 10px 12px; + display: inline-block; + float: left; } + @media (max-width: 400px) { + #footer #newsletter_block_left .form-group .form-control{ + padding: 7px 43px 7px 6px; + height: 37px; + } + } + #footer #newsletter_block_left .form-group .form-control:focus { + -moz-box-shadow: black 0px 0px 0px; + -webkit-box-shadow: black 0px 0px 0px; + box-shadow: black 0px 0px 0px; } + #footer #newsletter_block_left .form-group .button-small { + margin-left: -43px; + border: none; + background: none; + text-align: center; + color: #908f8f; + padding: 8px; } + #footer #newsletter_block_left .form-group .button-small:before { + content: "\f138"; + font-family: "FontAwesome"; + font-size: 28px; + line-height: 28px; } + #footer #newsletter_block_left .form-group .button-small:hover { + color: #fff !important; } + #footer #newsletter_block_left .form-group .button-small span { + display: none; } + #footer #newsletter_block_left .warning_inline { + display: block; + color: #f13340; + font-size: 13px; + line-height: 26px; + clear: both; } + @media (min-width: 1200px) { + #footer #newsletter_block_left .warning_inline { + display: inline-block; + position: relative; + top: -35px; + margin-bottom: -35px; + left: 15px; + clear: none; } } + #footer #newsletter_block_left .newsletter-input { + max-width: 230px !important; }/*by webkul original 300px*/ + @media (max-width: 400px) { + #footer #newsletter_block_left .newsletter-input { + max-width: 190px !important; + } + } + + #newsletter-input::-webkit-input-placeholder { + color: #bfbfbf; + } + + #newsletter-input:-moz-placeholder { /* Firefox 18- */ + color: #bfbfbf; + } + + #newsletter-input::-moz-placeholder { /* Firefox 19+ */ + color: #bfbfbf; + } + + #newsletter-input:-ms-input-placeholder { + color: #bfbfbf; + } + + /*# sourceMappingURL=blocknewsletter.css.map */ + .button.button-medium.newsletter-btn { position: relative; - top: -1px; - padding:0 5px; - height:20px; - width:148px; - border:1px solid #ccc; - border-right:none; - -moz-border-radius-topleft: 3px; - -moz-border-radius-bottomleft: 3px; - -webkit-border-radius-topleft: 3px; - -webkit-border-radius-bottomleft: 3px; - border-top-left-radius: 3px; - border-bottom-left-radius: 3px; - font-size:10px; - color:#999; -} -*:first-child+html #newsletter_block_left input.inputNew {position:static;}/* hack ie 7 */ - -#newsletter_block_left input.button_mini { - position:relative; - left:-2px; - height:23px; - width:24px; - border:0; - text-indent:-5000px; - background:url(img/bg_bt_newsletter_ok.png) no-repeat 0 0; - cursor:pointer -} -*:first-child+html #newsletter_block_left input.button_mini {padding-left:24px !important;}/* hack ie 7 */ - + padding: 0px 20px; + } + #newsletter-input + { + background-color: #3a3a3a; + border: 1px solid #868686; + color: #bfbfbf; + font-size: 13px; + height: 42px; + margin-bottom: 10px; + } + \ No newline at end of file diff --git a/modules/blocknewsletter/blocknewsletter.js b/modules/blocknewsletter/blocknewsletter.js index e69de29bb..b907c15ee 100644 --- a/modules/blocknewsletter/blocknewsletter.js +++ b/modules/blocknewsletter/blocknewsletter.js @@ -0,0 +1,49 @@ +/* +* 2007-2017 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2017 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +$(document).on('click', '#blocknewsletter .newsletter-btn', function (e) { + e.preventDefault(); + + $.ajax({ + url: url_newsletter_subscription, + type: 'POST', + dataType: 'JSON', + cache: false, + data: $(this).closest('form').serialize(), + beforeSend: function () { + let messageBlock = $('#blocknewsletter .message-block'); + $(messageBlock).fadeOut('fast'); + }, + success: function (response) { + let messageBlock = $('#blocknewsletter .message-block'); + $(messageBlock).html(response.message_html).stop(true, true).fadeIn('fast'); + }, + error: function (jqXHR) { + if (jqXHR.readyState == 0) { + showErrorMessage(no_internet_txt); + } + } + }); +}); diff --git a/modules/blocknewsletter/views/templates/hook/blocknewsletter.tpl b/modules/blocknewsletter/views/templates/hook/blocknewsletter.tpl index e69de29bb..8fdbcaaf4 100644 --- a/modules/blocknewsletter/views/templates/hook/blocknewsletter.tpl +++ b/modules/blocknewsletter/views/templates/hook/blocknewsletter.tpl @@ -0,0 +1,58 @@ +{* +* 2007-2017 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2017 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + + +
+
+ +
+
+
+ + + + + + + {* Hook added for GDPR *} + {if isset($id_module)} + {hook h='displayGDPRConsent' id_module=$id_module} + {/if} + +
+
+
+ {hook h="displayBlockNewsletterBottom" from='blocknewsletter'} +
+
+ +{addJsDefL name=no_internet_txt}{l s='No internet. Please try later.' mod='blocknewsletter' js=1}{/addJsDefL} + + From 79c541fc7c0e4d69cc9aea2153d48dff6af32c48 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 12 Sep 2023 12:28:03 +0530 Subject: [PATCH 04/10] Add admin controller to blocknewsletter module --- .../customers/helpers/required_fields.tpl | 69 -- .../AdminCustomerPreferencesController.php | 2 +- .../admin/AdminCustomersController.php | 3 - controllers/front/AuthController.php | 2 +- controllers/front/IdentityController.php | 2 - controllers/front/OrderOpcController.php | 2 +- install/data/xml/configuration.xml | 2 +- modules/blocknewsletter/blocknewsletter.php | 531 ++++------------ .../admin/AdminNewsletterController.php | 589 ++++++++++++++++++ .../admin/AdminParentNewsletterController.php | 28 + .../controllers/admin/index.php | 29 + modules/blocknewsletter/export/index.php | 29 + .../helpers/list/list_action_enable.tpl | 23 + .../helpers/list/view-customer-link.tpl | 23 + themes/hotel-reservation-theme/identity.tpl | 20 +- 15 files changed, 839 insertions(+), 515 deletions(-) delete mode 100644 admin/themes/default/template/controllers/customers/helpers/required_fields.tpl create mode 100644 modules/blocknewsletter/controllers/admin/AdminNewsletterController.php create mode 100644 modules/blocknewsletter/controllers/admin/AdminParentNewsletterController.php create mode 100644 modules/blocknewsletter/controllers/admin/index.php create mode 100644 modules/blocknewsletter/export/index.php create mode 100644 modules/blocknewsletter/views/templates/admin/newsletter/helpers/list/list_action_enable.tpl create mode 100644 modules/blocknewsletter/views/templates/admin/newsletter/helpers/list/view-customer-link.tpl diff --git a/admin/themes/default/template/controllers/customers/helpers/required_fields.tpl b/admin/themes/default/template/controllers/customers/helpers/required_fields.tpl deleted file mode 100644 index abf671a38..000000000 --- a/admin/themes/default/template/controllers/customers/helpers/required_fields.tpl +++ /dev/null @@ -1,69 +0,0 @@ -{* -* 2007-2017 PrestaShop -* -* NOTICE OF LICENSE -* -* This source file is subject to the Academic Free License (AFL 3.0) -* that is bundled with this package in the file LICENSE.txt. -* It is also available through the world-wide-web at this URL: -* http://opensource.org/licenses/afl-3.0.php -* If you did not receive a copy of the license and are unable to -* obtain it through the world-wide-web, please send an email -* to license@prestashop.com so we can send you a copy immediately. -* -* DISCLAIMER -* -* Do not edit or add to this file if you wish to upgrade PrestaShop to newer -* versions in the future. If you wish to customize PrestaShop for your -* needs please refer to http://www.prestashop.com for more information. -* -* @author PrestaShop SA -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*} - - {l s='Set required fields for this section'} - -
 
- diff --git a/controllers/admin/AdminCustomerPreferencesController.php b/controllers/admin/AdminCustomerPreferencesController.php index d5599879b..7a6670fe2 100644 --- a/controllers/admin/AdminCustomerPreferencesController.php +++ b/controllers/admin/AdminCustomerPreferencesController.php @@ -101,7 +101,7 @@ class AdminCustomerPreferencesControllerCore extends AdminController ), 'PS_CUSTOMER_OPTIN' => array( 'title' => $this->l('Enable opt-in'), - 'hint' => $this->l('Display or not the opt-in tick box, to receive offers from the store\'s partners.'), + 'hint' => $this->l('Display or not the opt-in tick box, to receive offers from your hotel partners.'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool' diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index a9bc64895..7914f2b47 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -39,8 +39,6 @@ class AdminCustomersControllerCore extends AdminController public function __construct() { $this->bootstrap = true; - $this->required_database = true; - $this->required_fields = array('newsletter','optin'); $this->table = 'customer'; $this->className = 'Customer'; $this->lang = false; @@ -458,7 +456,6 @@ class AdminCustomersControllerCore extends AdminController 'label' => $this->l('Disabled') ) ), - 'disabled' => (bool)!Configuration::get('PS_CUSTOMER_NEWSLETTER'), 'hint' => $this->l('This customer will receive your newsletter via email.') ), array( diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index 95c532e3d..ca7dc8aa0 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -100,7 +100,7 @@ class AuthControllerCore extends FrontController $this->assignCountries(); - $newsletter = Module::isEnabled('blocknewsletter') && Configuration::get('PS_CUSTOMER_NEWSLETTER'); + $newsletter = Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active && Configuration::get('PS_CUSTOMER_NWSL'); $this->context->smarty->assign('newsletter', $newsletter); $this->context->smarty->assign('optin', (bool)Configuration::get('PS_CUSTOMER_OPTIN')); diff --git a/controllers/front/IdentityController.php b/controllers/front/IdentityController.php index 39231664d..c1cc36b4b 100644 --- a/controllers/front/IdentityController.php +++ b/controllers/front/IdentityController.php @@ -151,8 +151,6 @@ class IdentityControllerCore extends FrontController 'HOOK_CUSTOMER_IDENTITY_FORM' => Hook::exec('displayCustomerIdentityForm'), )); - $newsletter = Module::isEnabled('blocknewsletter') && Configuration::get('PS_CUSTOMER_NEWSLETTER'); - $this->context->smarty->assign('newsletter', $newsletter); $this->context->smarty->assign('optin', (bool)Configuration::get('PS_CUSTOMER_OPTIN')); $this->context->smarty->assign('field_required', $this->context->customer->validateFieldsRequiredDatabase()); diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 4be955e76..62bb426c4 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -519,7 +519,7 @@ class OrderOpcControllerCore extends ParentOrderController } Tools::safePostVars(); - $newsletter = Module::isEnabled('blocknewsletter') && Configuration::get('PS_CUSTOMER_NEWSLETTER'); + $newsletter = Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active && Configuration::get('PS_CUSTOMER_NWSL'); $this->context->smarty->assign('newsletter', $newsletter); $this->context->smarty->assign('optin', (bool)Configuration::get('PS_CUSTOMER_OPTIN')); $this->context->smarty->assign('field_required', $this->context->customer->validateFieldsRequiredDatabase()); diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml index 87d2dff7f..935de20ba 100644 --- a/install/data/xml/configuration.xml +++ b/install/data/xml/configuration.xml @@ -878,7 +878,7 @@ 1 - + 1 diff --git a/modules/blocknewsletter/blocknewsletter.php b/modules/blocknewsletter/blocknewsletter.php index 67b08eca6..6dc973d11 100644 --- a/modules/blocknewsletter/blocknewsletter.php +++ b/modules/blocknewsletter/blocknewsletter.php @@ -35,6 +35,11 @@ class Blocknewsletter extends Module const GUEST_REGISTERED = 1; const CUSTOMER_REGISTERED = 2; + const EXPORT_ALL_SUBSCRIBERS = 1; + const EXPORT_SUBSCRIBERS_WITH_ACCOUNT = 2; + const EXPORT_SUBSCRIBERS_WITHOUT_ACCOUNT = 3; + const EXPORT_NON_SUBSCRIBERS = 4; + public function __construct() { $this->name = 'blocknewsletter'; @@ -64,8 +69,6 @@ class Blocknewsletter extends Module ) ); - $this->_searched_email = null; - $this->_html = ''; $this->hookPrepared = false; @@ -110,7 +113,7 @@ class Blocknewsletter extends Module public function install() { - if (!parent::install() || !$this->registerHooks()) { + if (!parent::install() || !$this->registerHooks() || !$this->installModuleTabs()) { return false; } Configuration::updateValue('NW_SALT', Tools::passwdGen(16)); @@ -129,209 +132,38 @@ class Blocknewsletter extends Module ); } - public function uninstall() + public function installModuleTabs() { - Db::getInstance()->execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'newsletter'); - return parent::uninstall(); + $result = $this->installTab('AdminParentNewsletter', 'Newsletter', false, true); + $result &= $this->installTab('AdminNewsletter', 'Configuration', 'AdminParentNewsletter', true); + + return $result; + } + + public function installTab($className, $tabName, $tabParentName = false, $hidden = false) + { + $tab = new Tab(); + $tab->active = 1; + $tab->class_name = $className; + $tab->name = array(); + foreach (Language::getLanguages(false) as $lang) { + $tab->name[$lang['id_lang']] = $tabName; + } + if ($tabParentName) { + $tab->id_parent = (int) Tab::getIdFromClassName($tabParentName); + } elseif ($hidden) { + $tab->id_parent = -1; + } else { + $tab->id_parent = 0; + } + $tab->module = $this->name; + + return $tab->add(); } public function getContent() { - if (Tools::isSubmit('submitUpdate')) { - Configuration::updateValue('PS_CUSTOMER_NEWSLETTER', (bool)Tools::getValue('PS_CUSTOMER_NEWSLETTER')); - Configuration::updateValue('NW_CONFIRMATION_EMAIL', (bool)Tools::getValue('NW_CONFIRMATION_EMAIL')); - Configuration::updateValue('NW_VERIFICATION_EMAIL', (bool)Tools::getValue('NW_VERIFICATION_EMAIL')); - - $voucher = Tools::getValue('NW_VOUCHER_CODE'); - if ($voucher && !Validate::isDiscountName($voucher)) { - $this->_html .= $this->displayError($this->l('The voucher code is invalid.')); - } elseif (!CartRule::cartRuleExists($voucher)) { - $this->_html .= $this->displayError($this->l('The voucher code does not exist.')); - } else { - Configuration::updateValue('NW_VOUCHER_CODE', pSQL($voucher)); - $this->_html .= $this->displayConfirmation($this->l('Settings updated')); - } - } elseif (Tools::isSubmit('subscribedmerged')) { - $id = Tools::getValue('id'); - - if (preg_match('/(^N)/', $id)) { - $id = (int)substr($id, 1); - $sql = 'UPDATE '._DB_PREFIX_.'newsletter SET active = 0 WHERE id = '.$id; - Db::getInstance()->execute($sql); - } else { - $c = new Customer((int)$id); - $c->newsletter = (int)!$c->newsletter; - $c->update(); - } - Tools::redirectAdmin( - $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&conf=4&token='. - Tools::getAdminTokenLite('AdminModules') - ); - } elseif (Tools::isSubmit('exportSubscribers')) { - $header = array('id', 'shop_name', 'gender', 'lastname', 'firstname', 'email', 'subscribed', 'subscribed_on'); // TODO - $array_to_export = array_merge(array($header), $this->getSubscribers()); - - $file_name = time().'.csv'; - $fd = fopen($this->getLocalPath().$file_name, 'w+'); - foreach ($array_to_export as $tab) { - $line = implode(';', $tab); - $line .= "\n"; - fwrite($fd, $line, 4096); - } - fclose($fd); - Tools::redirect(_PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/'.$file_name); - } elseif (Tools::isSubmit('exportOnlyBlockNews')) { - $array_to_export = $this->getBlockNewsletterSubscriber(); - - $file_name = time().'.csv'; - $fd = fopen($this->getLocalPath().$file_name, 'w+'); - foreach ($array_to_export as $tab) { - $line = implode(';', $tab); - $line .= "\n"; - fwrite($fd, $line, 4096); - } - fclose($fd); - Tools::redirect(_PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/'.$file_name); - } elseif (Tools::isSubmit('searchEmail')) { - $this->_searched_email = Tools::getValue('searched_email'); - } - - $this->_html .= $this->renderForm(); - $this->_html .= $this->renderSearchForm(); - $this->_html .= $this->renderList(); - - $this->_html .= ''; - - $this->_html .= $this->renderExportForm(); - - return $this->_html; - } - - public function renderList() - { - $fields_list = array( - - 'id' => array( - 'title' => $this->l('ID'), - 'search' => false, - ), - 'shop_name' => array( - 'title' => $this->l('Shop'), - 'search' => false, - ), - 'gender' => array( - 'title' => $this->l('Gender'), - 'search' => false, - ), - 'lastname' => array( - 'title' => $this->l('Lastname'), - 'search' => false, - ), - 'firstname' => array( - 'title' => $this->l('Firstname'), - 'search' => false, - ), - 'email' => array( - 'title' => $this->l('Email'), - 'search' => false, - ), - 'subscribed' => array( - 'title' => $this->l('Subscribed'), - 'type' => 'bool', - 'active' => 'subscribed', - 'search' => false, - ), - 'newsletter_date_add' => array( - 'title' => $this->l('Subscribed on'), - 'type' => 'date', - 'search' => false, - ) - ); - - if (!Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE')) { - unset($fields_list['shop_name']); - } - - $helper_list = new HelperList(); - $helper_list->module = $this; - $helper_list->title = $this->l('Newsletter registrations'); - $helper_list->shopLinkType = ''; - $helper_list->no_link = true; - $helper_list->show_toolbar = true; - $helper_list->simple_header = false; - $helper_list->identifier = 'id'; - $helper_list->table = 'merged'; - $helper_list->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name; - $helper_list->token = Tools::getAdminTokenLite('AdminModules'); - $helper_list->actions = array('viewCustomer'); - $helper_list->toolbar_btn['export'] = array( - 'href' => $helper_list->currentIndex.'&exportSubscribers&token='.$helper_list->token, - 'desc' => $this->l('Export') - ); - - /* Before 1.6.0.7 displayEnableLink() could not be overridden in Module class - we declare another row action instead */ - if (version_compare(_PS_VERSION_, '1.6.0.7', '<')) { - unset($fields_list['subscribed']); - $helper_list->actions = array_merge($helper_list->actions, array('unsubscribe')); - } - - // This is needed for displayEnableLink to avoid code duplication - $this->_helperlist = $helper_list; - - /* Retrieve list data */ - $subscribers = $this->getSubscribers(); - $helper_list->listTotal = count($subscribers); - - /* Paginate the result */ - $page = ($page = Tools::getValue('submitFilter'.$helper_list->table)) ? $page : 1; - $pagination = ($pagination = Tools::getValue($helper_list->table.'_pagination')) ? $pagination : 50; - $subscribers = $this->paginateSubscribers($subscribers, $page, $pagination); - - return $helper_list->generateList($subscribers, $fields_list); - } - - public function displayViewCustomerLink($token = null, $id, $name = null) - { - $this->smarty->assign( - array( - 'href' => 'index.php?controller=AdminCustomers&id_customer='.(int)$id.'&viewcustomer&token='. - Tools::getAdminTokenLite('AdminCustomers'), - 'action' => $this->l('View'), - 'disable' => !((int)$id > 0), - ) - ); - return $this->display(__FILE__, 'views/templates/admin/list_action_viewcustomer.tpl'); - } - - public function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null, $ajax = false) - { - $this->smarty->assign( - array( - 'ajax' => $ajax, - 'enabled' => (bool)$value, - 'url_enable' => $this->_helperlist->currentIndex.'&'.$this->_helperlist->identifier.'='.$id.'&'.$active. - $this->_helperlist->table.($ajax ? '&action='.$active.$this->_helperlist->table.'&ajax='. - (int)$ajax : '').((int)$id_category && (int)$id_product ? '&id_category='.(int)$id_category : ''). - '&token='.$token - ) - ); - return $this->display(__FILE__, 'views/templates/admin/list_action_enable.tpl'); - } - - public function displayUnsubscribeLink($token = null, $id, $name = null) - { - $this->smarty->assign( - array( - 'href' => $this->_helperlist->currentIndex.'&subscribedcustomer&'.$this->_helperlist->identifier.'='. - $id.'&token='.$token, - 'action' => $this->l('Unsubscribe'), - ) - ); - return $this->display(__FILE__, 'views/templates/admin/list_action_unsubscribe.tpl'); + Tools::redirectAdmin($this->context->link->getAdminLink('AdminNewsletter')); } /** @@ -435,47 +267,55 @@ class Blocknewsletter extends Module } } - public function getSubscribers() + public function getExportCsvHeader() { - $dbquery = new DbQuery(); - $dbquery->select('c.`id_customer` AS `id`, s.`name` AS `shop_name`, gl.`name` AS `gender`, c.`lastname`, c.`firstname`, c.`email`, c.`newsletter` AS `subscribed`, c.`newsletter_date_add`'); - $dbquery->from('customer', 'c'); - $dbquery->leftJoin('shop', 's', 's.id_shop = c.id_shop'); - $dbquery->leftJoin('gender', 'g', 'g.id_gender = c.id_gender'); - $dbquery->leftJoin( - 'gender_lang', 'gl', 'g.id_gender = gl.id_gender AND gl.id_lang = '.(int)$this->context->employee->id_lang + return array( + $this->l('ID'), + $this->l('Social Title'), + $this->l('Email'), + $this->l('First Name'), + $this->l('Last Name'), + $this->l('Subscribed'), + $this->l('Date Added'), ); - $dbquery->where('c.`newsletter` = 1'); - if ($this->_searched_email) { - $dbquery->where('c.`email` LIKE \'%'.pSQL($this->_searched_email).'%\' '); - } - - $customers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($dbquery->build()); - - $dbquery = new DbQuery(); - $dbquery->select( - 'CONCAT(\'N\', n.`id`) AS `id`, s.`name` AS `shop_name`, NULL AS `gender`, NULL AS `lastname`, NULL - AS `firstname`, n.`email`, n.`active` AS `subscribed`, n.`newsletter_date_add`' - ); - $dbquery->from('newsletter', 'n'); - $dbquery->leftJoin('shop', 's', 's.id_shop = n.id_shop'); - $dbquery->where('n.`active` = 1'); - if ($this->_searched_email) { - $dbquery->where('n.`email` LIKE \'%'.pSQL($this->_searched_email).'%\' '); - } - - $non_customers = Db::getInstance()->executeS($dbquery->build()); - - $subscribers = array_merge($customers, $non_customers); - - return $subscribers; } - public function paginateSubscribers($subscribers, $page = 1, $pagination = 50) + public function getSubscribers($subscribersType) { - if (count($subscribers) > $pagination) { - $subscribers = array_slice($subscribers, $pagination * ($page - 1), $pagination); + $subscribers = array(); + + if (in_array( + $subscribersType, + array( + self::EXPORT_ALL_SUBSCRIBERS, + self::EXPORT_SUBSCRIBERS_WITH_ACCOUNT, + self::EXPORT_NON_SUBSCRIBERS, + ) + )) { + $sqlCustomer = 'SELECT c.`id_customer` AS id, gl.`name` AS gender, c.`email`, c.`firstname`, c.`lastname`, + c.`newsletter` AS subscribed, c.`newsletter_date_add` + FROM `'._DB_PREFIX_.'customer` c + LEFT JOIN '._DB_PREFIX_.'gender_lang gl ON (gl.`id_gender` = c.`id_gender` AND gl.`id_lang` = '.(int) $this->context->language->id.') + WHERE c.`newsletter` = '.($subscribersType == self::EXPORT_NON_SUBSCRIBERS ? '0' : '1'); + + $subscribers = array_merge($subscribers, Db::getInstance()->executeS($sqlCustomer)); } + + if (in_array( + $subscribersType, + array( + self::EXPORT_ALL_SUBSCRIBERS, + self::EXPORT_SUBSCRIBERS_WITHOUT_ACCOUNT, + self::EXPORT_NON_SUBSCRIBERS, + ) + )) { + $sqlNewsletter = 'SELECT CONCAT(\'N\', n.`id`) AS id, NULL AS id_gender, n.`email`, NULL AS firstname, + NULL AS lastname, n.`active` AS subscribed, n.`newsletter_date_add` + FROM `'._DB_PREFIX_.'newsletter` n WHERE n.`active` = '.($subscribersType == self::EXPORT_NON_SUBSCRIBERS ? '0' : '1'); + + $subscribers = array_merge($subscribers, Db::getInstance()->executeS($sqlNewsletter)); + } + return $subscribers; } @@ -817,200 +657,39 @@ class Blocknewsletter extends Module return true; } - public function renderForm() + public function reset() { - $fields_form = array( - 'form' => array( - 'legend' => array( - 'title' => $this->l('Settings'), - 'icon' => 'icon-cogs' - ), - 'input' => array( - array( - 'type' => 'switch', - 'label' => $this->l('Enable newsletter registration'), - 'name' => 'PS_CUSTOMER_NEWSLETTER', - 'values' => array( - array( - 'id' => 'active_on', - 'value' => 1, - 'label' => $this->l('Yes') - ), - array( - 'id' => 'active_off', - 'value' => 0, - 'label' => $this->l('No') - ) - ), - ), - 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('Yes') - ), - array( - 'id' => 'active_off', - 'value' => 0, - 'label' => $this->l('No') - ) - ), - ), - 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('Yes') - ), - array( - 'id' => 'active_off', - 'value' => 0, - 'label' => $this->l('No') - ) - ), - ), - array( - 'type' => 'text', - 'label' => $this->l('Welcome voucher code'), - 'name' => 'NW_VOUCHER_CODE', - 'class' => 'fixed-width-md', - 'desc' => sprintf( - $this->l('You can create a voucher from %s page. Leave blank to disable by default.'), - ''.$this->l('Cart Rules').'' - ) - ), - ), - 'submit' => array( - 'title' => $this->l('Save'), - ) - ), - ); - - $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 renderExportForm() - { - $fields_form = array( - 'form' => array( - 'legend' => array( - 'title' => $this->l('Export Newsletter Subscribers'), - 'icon' => 'icon-envelope' - ), - 'description' => $this->l('Generate a .CSV file based on Newsletter subscribers data. Only subscribers without an account on your website will be exported.'), - 'submit' => array( - 'title' => $this->l('Export .CSV file'), - 'class' => 'btn btn-default pull-right', - 'name' => 'submitExportmodule', - ) - ), - ); - - $helper = new HelperForm(); - $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 = 'exportOnlyBlockNews'; - $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 renderSearchForm() - { - $fields_form = array( - 'form' => array( - 'legend' => array( - 'title' => $this->l('Search for addresses'), - 'icon' => 'icon-search' - ), - 'input' => array( - array( - 'type' => 'text', - 'label' => $this->l('Email address to search'), - 'name' => 'searched_email', - 'class' => 'fixed-width-xxl', - 'desc' => $this->l('Example: contact@qloapps.com or @qloapps.com') - ), - ), - 'submit' => array( - 'title' => $this->l('Search'), - 'icon' => 'process-icon-refresh', - ) - ), - ); - - $helper = new HelperForm(); - $helper->table = $this->table; - $helper->identifier = $this->identifier; - $helper->submit_action = 'searchEmail'; - $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' => array('searched_email' => $this->_searched_email), - 'languages' => $this->context->controller->getLanguages(), - 'id_language' => $this->context->language->id - ); - - return $helper->generateForm(array($fields_form)); - } - - public function getConfigFieldsValues() - { - return array( - 'PS_CUSTOMER_NEWSLETTER' => Tools::getValue('PS_CUSTOMER_NEWSLETTER', Configuration::get('PS_CUSTOMER_NEWSLETTER')), - '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')), - ); - } - - public function getBlockNewsletterSubscriber() - { - $rq_sql = 'SELECT `id`, `email`, `newsletter_date_add`, `ip_registration_newsletter` - FROM `'._DB_PREFIX_.'newsletter` - WHERE `active` = 1'; - - if (Context::getContext()->cookie->shopContext) { - $rq_sql .= ' AND `id_shop` = '.(int)Context::getContext()->shop->id; + if (!$this->uninstall(false)) { + return false; + } + if (!$this->install(false)) { + return false; } - $rq = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($rq_sql); + return true; + } - $header = array('id_customer', 'email', 'newsletter_date_add', 'ip_address', 'http_referer'); - $result = (is_array($rq) ? array_merge(array($header), $rq) : $header); + public function uninstall($keep = true) + { + if (!parent::uninstall() + || ($keep && !Db::getInstance()->execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'newsletter')) + || !$this->uninstallModuleTabs() + ) { + return false; + } - return $result; + return true; + } + + public function uninstallModuleTabs() + { + $moduleTabs = Tab::getCollectionFromModule($this->name); + if (!empty($moduleTabs)) { + foreach ($moduleTabs as $moduleTab) { + $moduleTab->delete(); + } + } + + return true; } } diff --git a/modules/blocknewsletter/controllers/admin/AdminNewsletterController.php b/modules/blocknewsletter/controllers/admin/AdminNewsletterController.php new file mode 100644 index 000000000..0956efe23 --- /dev/null +++ b/modules/blocknewsletter/controllers/admin/AdminNewsletterController.php @@ -0,0 +1,589 @@ +bootstrap = true; + $this->table = 'merged'; + $this->identifier = 'id_merged'; + $this->allow_export = true; + + $this->_filterCustomer = ''; + $this->_filterNewsletter = ''; + + parent::__construct(); + + $this->addRowAction('viewCustomer'); + + $genderList = array(); + $genders = Gender::getGenders($this->context->language->id); + foreach ($genders as $gender) { + $genderList[$gender->id_gender] = $gender->name; + } + + $this->fields_list = array( + 'id_merged' => array( + 'title' => $this->l('ID'), + 'filter_type' => 'int', + 'filter_keys' => array( + 'customer' => 'c.`id_customer`', + 'newsletter' => 'n.`id`', + ), + ), + 'id_gender' => array( + 'title' => $this->l('Social Title'), + 'type' => 'select', + 'list' => $genderList, + 'filter_type' => 'int', + 'filter_key' => 'id_gender', + 'filter_keys' => array( + 'customer' => 'c.`id_gender`', + ), + ), + 'firstname' => array( + 'title' => $this->l('First Name'), + 'filter_keys' => array( + 'customer' => 'c.`firstname`', + ), + ), + 'lastname' => array( + 'title' => $this->l('Last Name'), + 'filter_keys' => array( + 'customer' => 'c.`lastname`', + ), + ), + 'email' => array( + 'title' => $this->l('Email'), + 'filter_keys' => array( + 'customer' => 'c.`email`', + 'newsletter' => 'n.`email`', + ), + ), + 'subscribed' => array( + 'title' => $this->l('Subscribed'), + 'type' => 'bool', + 'active' => 'subscribed', + 'filter_keys' => array( + 'customer' => 'c.`newsletter`', + 'newsletter' => 'n.`active`', + ), + 'ajax' => true, + 'search' => false, + 'orderby' => false, + ), + 'newsletter_date_add' => array( + 'title' => $this->l('Subscribed On'), + 'type' => 'datetime', + 'filter_keys' => array( + 'customer' => 'c.`newsletter_date_add`', + 'newsletter' => 'n.`newsletter_date_add`', + ), + ), + ); + + $this->list_no_link = true; + + $this->bulk_actions = array( + 'enableSelection' => array( + 'text' => $this->l('Enable selection'), + 'icon' => 'icon-power-off text-success' + ), + 'disableSelection' => array( + 'text' => $this->l('Disable selection'), + 'icon' => 'icon-power-off text-danger' + ), + 'divider' => array( + 'text' => 'divider' + ), + 'delete' => array( + 'text' => $this->l('Delete selected'), + 'confirm' => $this->l('Delete selected items?'), + 'icon' => 'icon-trash' + ) + ); + + $this->_conf[101] = $this->l('The customer has been unsubscribed from newsletter successfully.'); + } + + public function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null) + { + $tpl = $this->context->smarty->createTemplate( + $this->module->getTemplatePath( + '/views/templates/admin/'.$this->tpl_folder.'/helpers/list/list_action_enable.tpl' + ) + ); + + $tpl->assign(array( + 'enabled' => (bool) $value, + 'url_enable' => self::$currentIndex.'&action=unsubscribeNewsletter&'.$this->identifier.'='.$id. + '&token='.($token != null ? $token : $this->token), + )); + + return $tpl->fetch(); + } + + public function displayViewCustomerLink($token = null, $id, $name = null) + { + $tpl = $this->context->smarty->createTemplate( + $this->module->getTemplatePath( + '/views/templates/admin/'.$this->tpl_folder.'/helpers/list/view-customer-link.tpl' + ) + ); + + $tpl->assign(array( + 'id_merged' => $id, + 'disabled' => !Validate::isUnsignedInt($id), + )); + + return $tpl->fetch(); + } + + public function initToolbar() + { + parent::initToolbar(); + + unset($this->toolbar_btn['save']); + $this->toolbar_btn['export'] = array( + 'href' => self::$currentIndex.'&export'.$this->table.'&token='.$this->token, + 'desc' => $this->l('Export') + ); + } + + public function initToolbarTitle() + { + $this->toolbar_title = $this->l('Configuration'); + } + + public function initContent() + { + parent::initContent(); + + if ($this->display == 'options') { + $this->content = $this->renderOptions(); + $this->content .= $this->renderList(); + $this->content .= $this->renderFormExport(); + $this->context->smarty->assign(array('content' => $this->content)); + + unset($this->toolbar_btn['save']); + } + } + + public function renderOptions() + { + $this->fields_options = array( + 'general' => array( + 'title' => $this->l('Configuration'), + 'icon' => 'icon-cogs', + 'fields' => array( + 'PS_CUSTOMER_NWSL' => array( + 'type' => 'bool', + 'title' => $this->l('Enable newsletter registration'), + 'validation' => 'isBool', + 'cast' => 'intval', + ), + 'NW_VERIFICATION_EMAIL' => array( + 'type' => 'bool', + 'title' => $this->l('Would you like to send a verification email after subscription?'), + 'validation' => 'isBool', + 'cast' => 'intval', + ), + 'NW_CONFIRMATION_EMAIL' => array( + 'type' => 'bool', + 'title' => $this->l('Would you like to send a confirmation email after subscription?'), + 'validation' => 'isBool', + 'cast' => 'intval', + ), + 'NW_VOUCHER_CODE' => array( + 'type' => 'text', + 'title' => $this->l('Welcome voucher code'), + 'desc' => sprintf( + $this->l('You can create a voucher from %s page. Leave blank to disable this feature.'), + ''.$this->l('Cart Rules').'' + ), + 'class' => 'fixed-width-xl', + 'validation' => 'isUnsignedInt', + 'required' => true, + 'cast' => 'intval', + ), + ), + 'submit' => array( + 'title' => $this->l('Save'), + 'name' => 'submitNewsletterOptions', + ) + ), + ); + + return parent::renderOptions(); + } + + public function renderList() + { + $this->tpl_list_vars['title'] = $this->l('Subscribers'); + $this->tpl_list_vars['icon'] = 'icon-list'; + + return parent::renderList(); + } + + public function renderFormExport() + { + $this->fields_form = array( + 'legend' => array( + 'title' => $this->l('Export Email Addresses'), + 'icon' => 'icon-share-alt' + ), + 'description' => $this->l('Use this option to export list of email addresses as a .CSV file.'), + 'input' => array( + array( + 'type' => 'select', + 'label' => $this->l('Newsletter subscribers'), + 'name' => 'subscribersType', + 'class' => 'fixed-width-xl', + 'options' => array( + 'query' => array( + array( + 'id' => Blocknewsletter::EXPORT_ALL_SUBSCRIBERS, + 'name' => $this->l('All subscribers'), + ), + array( + 'id' => Blocknewsletter::EXPORT_SUBSCRIBERS_WITH_ACCOUNT, + 'name' => $this->l('Subscribers with account'), + ), + array( + 'id' => Blocknewsletter::EXPORT_SUBSCRIBERS_WITHOUT_ACCOUNT, + 'name' => $this->l('Subscribers without account'), + ), + array( + 'id' => Blocknewsletter::EXPORT_NON_SUBSCRIBERS, + 'name' => $this->l('Non-subscribers'), + ), + ), + 'id' => 'id', + 'name' => 'name' + ), + 'desc' => $this->l('Filter customers who have subscribed to the newsletter or not, and who have an account or not.'), + ), + ), + 'submit' => array( + 'title' => $this->l('Export .CSV file'), + 'icon' => 'process-icon- icon-share-alt', + 'id' => 'submit-export-email-addresses', + 'name' => 'submitExportEmailAddresses', + ), + ); + + return parent::renderForm(); + } + + public function postProcess() + { + if (Tools::isSubmit('submitNewsletterOptions')) { + $voucherCode = trim(Tools::getValue('NW_VOUCHER_CODE')); + if ($voucherCode && !Validate::isDiscountName($voucherCode)) { + $this->errors[] = $this->l('The voucher code is invalid.'); + } elseif (!CartRule::cartRuleExists($voucherCode)) { + $this->errors[] = $this->l('The voucher code does not exist.'); + } + + if (!count($this->errors)) { + Configuration::updateValue('PS_CUSTOMER_NWSL', Tools::getValue('PS_CUSTOMER_NWSL')); + Configuration::updateValue('NW_VERIFICATION_EMAIL', Tools::getValue('NW_VERIFICATION_EMAIL')); + Configuration::updateValue('NW_CONFIRMATION_EMAIL', Tools::getValue('NW_CONFIRMATION_EMAIL')); + Configuration::updateValue('NW_VOUCHER_CODE', $voucherCode); + + Tools::redirectAdmin(self::$currentIndex.'&conf=6&token='.$this->token); + } + } elseif (Tools::isSubmit('submitExportEmailAddresses')) { + $subscribersType = Tools::getValue('subscribersType'); + $subscribers = $this->module->getSubscribers($subscribersType); + + if (count($subscribers)) { + array_unshift($subscribers, $this->module->getExportCsvHeader()); + + $fileName = 'newsletter_emails_'.date('YmdHis').'.csv'; + $filePath = $this->module->getLocalPath().'export/'.$fileName; + + $fileHandle = fopen($filePath, 'w+'); + foreach ($subscribers as $subscriber) { + fputcsv($fileHandle, $subscriber); + } + + if (Tools::file_exists_cache($filePath)) { + if (ob_get_level() && ob_get_length() > 0) { + ob_end_clean(); + } + + header('Content-Type: text/csv'); + header('Content-Type: application/force-download; charset=UTF-8'); + header('Cache-Control: no-store, no-cache'); + header('Content-Disposition: attachment; filename="'.$fileName.'"'); + + @set_time_limit(0); + readfile($filePath); + exit; + } + } else { + $this->errors[] = $this->l('No email addresses found to export.'); + } + } + + parent::postProcess(); + } + + public function processUnsubscribeNewsletter() + { + $idMerged = Tools::getValue('id_merged'); + + $result = false; + if (preg_match('/(^N)/', $idMerged)) { + $idMerged = (int) substr($idMerged, 1); + $result = $res = Db::getInstance()->update( + 'newsletter', + array('active' => 0), + 'id = '.(int) $idMerged + ); + } else { + $objCustomer = new Customer($idMerged); + $objCustomer->newsletter = 0; + $result = $objCustomer->update(); + } + + if ($result) { + Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token.'&conf=101'); + } else { + $this->errors[] = $this->l('Newsletter subscription failed. Please try again.'); + } + } + + public function getList( + $id_lang, + $orderBy = null, + $orderWay = null, + $start = 0, + $limit = null, + $idLangShop = false + ) { + $useLimit = true; + if ($limit === false) { + $useLimit = false; + } elseif (empty($limit)) { + if (isset($this->context->cookie->{$this->list_id.'_pagination'}) && $this->context->cookie->{$this->list_id.'_pagination'}) { + $limit = $this->context->cookie->{$this->list_id.'_pagination'}; + } else { + $limit = $this->_default_pagination; + } + } + + $prefix = 'newsletter'; + if (empty($orderBy)) { + if ($this->context->cookie->{$prefix.$this->list_id.'Orderby'}) { + $orderBy = $this->context->cookie->{$prefix.$this->list_id.'Orderby'}; + } elseif ($this->_orderBy) { + $orderBy = $this->_orderBy; + } else { + $orderBy = $this->_defaultOrderBy; + } + } + + if (empty($orderWay)) { + if ($this->context->cookie->{$prefix.$this->list_id.'Orderway'}) { + $orderWay = $this->context->cookie->{$prefix.$this->list_id.'Orderway'}; + } elseif ($this->_orderWay) { + $orderWay = $this->_orderWay; + } else { + $orderWay = $this->_defaultOrderWay; + } + } + + $sqlWhere = ''; + do { + $sqlWhere = ' '.(isset($this->_where) ? $this->_where.' ' : ''). + ($this->deleted ? 'AND a.`deleted` = 0 ' : ''). + (isset($this->_filter) ? $this->_filter : ''). + (isset($this->_group) ? $this->_group.' ' : ''); + + $this->_orderBy = $orderBy; + $this->_orderWay = $orderWay = Tools::strtoupper($orderWay); + + $sqlOrderBy = ' ORDER BY '.$orderBy.' '.pSQL($orderWay); + $sqlLimit = ' '.(($useLimit === true) ? ' LIMIT '.(int) $start.', '.(int) $limit : ''); + + $this->_listsql = 'SELECT c.`id_customer` AS id_merged, gl.`name` AS id_gender, c.`email`, c.`firstname`, c.`lastname`, c.`newsletter` AS subscribed, c.`newsletter_date_add` + FROM `'._DB_PREFIX_.'customer` c + LEFT JOIN '._DB_PREFIX_.'gender_lang gl ON (gl.`id_gender` = c.`id_gender` AND gl.`id_lang` = '.(int) $this->context->language->id.') + WHERE c.`newsletter` = 1 '.$this->_filterCustomer.' + UNION + SELECT CONCAT(\'N\', n.`id`) AS id_merged, NULL AS id_gender, n.`email`, NULL AS firstname, NULL AS lastname, n.`active` AS subscribed, n.`newsletter_date_add` + FROM `'._DB_PREFIX_.'newsletter` n WHERE n.`active` = 1 '.$this->_filterNewsletter.$sqlOrderBy; + + $listCount = 'SELECT FOUND_ROWS() AS `'._DB_PREFIX_.$this->table.'`'; + + $this->_list = Db::getInstance()->executeS($this->_listsql, true, false); + + if ($this->_list === false) { + $this->_list_error = Db::getInstance()->getMsgError(); + break; + } + + $this->_listTotal = Db::getInstance()->getValue($listCount, false); + + if ($useLimit === true) { + $start = (int) $start - (int) $limit; + if ($start < 0) { + break; + } + } else { + break; + } + } while (empty($this->_list)); + + Hook::exec('action'.$this->controller_name.'ListingResultsModifier', array( + 'list' => &$this->_list, + 'list_total' => &$this->_listTotal, + )); + } + + public function processFilter() + { + Hook::exec('action'.$this->controller_name.'ListingFieldsModifier', array( + 'fields' => &$this->fields_list, + )); + + $this->ensureListIdDefinition(); + + $prefix = $this->getCookieFilterPrefix(); + + if (isset($this->list_id)) { + foreach ($_POST as $key => $value) { + if ($value === '') { + unset($this->context->cookie->{$prefix.$key}); + } elseif (stripos($key, $this->list_id.'Filter_') === 0) { + $this->context->cookie->{$prefix.$key} = !is_array($value) ? $value : json_encode($value); + } elseif (stripos($key, 'submitFilter') === 0) { + $this->context->cookie->$key = !is_array($value) ? $value : json_encode($value); + } + } + + foreach ($_GET as $key => $value) { + if (stripos($key, $this->list_id.'Filter_') === 0) { + $this->context->cookie->{$prefix.$key} = !is_array($value) ? $value : json_encode($value); + } elseif (stripos($key, 'submitFilter') === 0) { + $this->context->cookie->$key = !is_array($value) ? $value : json_encode($value); + } + if (stripos($key, $this->list_id.'Orderby') === 0 && Validate::isOrderBy($value)) { + if ($value === '' || $value == $this->_defaultOrderBy) { + unset($this->context->cookie->{$prefix.$key}); + } else { + $this->context->cookie->{$prefix.$key} = $value; + } + } elseif (stripos($key, $this->list_id.'Orderway') === 0 && Validate::isOrderWay($value)) { + if ($value === '' || $value == $this->_defaultOrderWay) { + unset($this->context->cookie->{$prefix.$key}); + } else { + $this->context->cookie->{$prefix.$key} = $value; + } + } + } + } + + $filters = $this->context->cookie->getFamily($prefix.$this->list_id.'Filter_'); + foreach ($filters as $key => $value) { + if ($value != null && !strncmp($key, $prefix.$this->list_id.'Filter_', 7 + Tools::strlen($prefix.$this->list_id))) { + $key = Tools::substr($key, 7 + Tools::strlen($prefix.$this->list_id)); + + if (!array_key_exists($key, $this->fields_list)) { + continue; + } + + $field = $this->fields_list[$key]; + foreach ($field['filter_keys'] as $table => $filterKey) { + $key = $filterKey; + + $type = (array_key_exists('filter_type', $field) ? $field['filter_type'] : (array_key_exists('type', $field) ? $field['type'] : false)); + if (($type == 'date' || $type == 'datetime' || $type == 'range') && is_string($value)) { + $value = json_decode($value, true); + } + + $sqlFilter = ''; + // only for date filtering (from, to) + if (is_array($value)) { + if ($type == 'range') { + if (isset($value[0]) && !empty($value[0])) { + if (!Validate::isUnsignedInt($value[0])) { + $this->errors[] = Tools::displayError('The \'From\' value is invalid'); + } else { + $sqlFilter .= ' AND '.pSQL($key).' >= '.pSQL($value[0]); + } + } + if (isset($value[1]) && !empty($value[1])) { + if (!Validate::isUnsignedInt($value[1])) { + $this->errors[] = Tools::displayError('The \'From\' value is invalid'); + } elseif (isset($value[0]) && !empty($value[0]) && $value[0] > $value[1]) { + $this->errors[] = Tools::displayError('The \'To\' value cannot be less than from value'); + } else { + $sqlFilter .= ' AND '.pSQL($key).' <= '.pSQL($value[1]); + } + } + } else { + if (isset($value[0]) && !empty($value[0])) { + if (!Validate::isDate($value[0])) { + $this->errors[] = Tools::displayError('The \'From\' date format is invalid (YYYY-MM-DD)'); + } else { + $sqlFilter .= ' AND '.pSQL($key).' >= \''.pSQL(Tools::dateFrom($value[0])).'\''; + } + } + + if (isset($value[1]) && !empty($value[1])) { + if (!Validate::isDate($value[1])) { + $this->errors[] = Tools::displayError('The \'To\' date format is invalid (YYYY-MM-DD)'); + } elseif (isset($value[0]) && !empty($value[0]) && strtotime($value[0]) > strtotime($value[1])) { + $this->errors[] = Tools::displayError('The \'To\' date cannot be before than from date'); + } else { + $sqlFilter .= ' AND '.pSQL($key).' <= \''.pSQL(Tools::dateTo($value[1])).'\''; + } + } + } + } else { + $sqlFilter .= ' AND '; + if ($type == 'int' || $type == 'bool') { + $sqlFilter .= pSQL($key).' = '.(int) $value.' '; + } elseif ($type == 'decimal') { + $sqlFilter .= pSQL($key).' = '.(float) $value.' '; + } elseif ($type == 'select') { + $sqlFilter .= pSQL($key).' = \''.pSQL($value).'\' '; + } elseif ($type == 'price') { + $value = (float) str_replace(',', '.', $value); + $sqlFilter .= pSQL($key).' = '.pSQL(trim($value)).' '; + } else { + $sqlFilter .= pSQL($key).' LIKE \'%'.pSQL(trim($value)).'%\' '; + } + } + + if ($table == 'customer') { + $this->_filterCustomer .= $sqlFilter; + } elseif ($table == 'newsletter') { + $this->_filterNewsletter .= $sqlFilter; + } + } + } + } + } +} diff --git a/modules/blocknewsletter/controllers/admin/AdminParentNewsletterController.php b/modules/blocknewsletter/controllers/admin/AdminParentNewsletterController.php new file mode 100644 index 000000000..152aef943 --- /dev/null +++ b/modules/blocknewsletter/controllers/admin/AdminParentNewsletterController.php @@ -0,0 +1,28 @@ +context->link->getAdminLink('AdminNewsletter')); + } +} diff --git a/modules/blocknewsletter/controllers/admin/index.php b/modules/blocknewsletter/controllers/admin/index.php new file mode 100644 index 000000000..d6825e437 --- /dev/null +++ b/modules/blocknewsletter/controllers/admin/index.php @@ -0,0 +1,29 @@ + + + + diff --git a/modules/blocknewsletter/views/templates/admin/newsletter/helpers/list/view-customer-link.tpl b/modules/blocknewsletter/views/templates/admin/newsletter/helpers/list/view-customer-link.tpl new file mode 100644 index 000000000..418d973f6 --- /dev/null +++ b/modules/blocknewsletter/views/templates/admin/newsletter/helpers/list/view-customer-link.tpl @@ -0,0 +1,23 @@ +{** +* 2010-2023 Webkul. +* +* NOTICE OF LICENSE +* +* All right is reserved, +* Please go through LICENSE.txt file inside our module +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade this module to newer +* versions in the future. If you wish to customize this module for your +* needs please refer to CustomizationPolicy.txt file inside our module for more information. +* +* @author Webkul IN +* @copyright 2010-2023 Webkul IN +* @license LICENSE.txt +*} + + + + {l s='View' mod='blocknewsletter'} + diff --git a/themes/hotel-reservation-theme/identity.tpl b/themes/hotel-reservation-theme/identity.tpl index b84a30800..5b58ec5e8 100644 --- a/themes/hotel-reservation-theme/identity.tpl +++ b/themes/hotel-reservation-theme/identity.tpl @@ -147,17 +147,15 @@ - {if isset($newsletter) && $newsletter} -
- -
- {/if} +
+ +
{if isset($optin) && $optin}
diff --git a/themes/hotel-reservation-theme/css/modules/blocknewsletter/blocknewsletter.css b/themes/hotel-reservation-theme/css/modules/blocknewsletter/blocknewsletter.css index c519ac430..c743b3e60 100644 --- a/themes/hotel-reservation-theme/css/modules/blocknewsletter/blocknewsletter.css +++ b/themes/hotel-reservation-theme/css/modules/blocknewsletter/blocknewsletter.css @@ -1,3 +1,22 @@ +/** + * 2010-2023 Webkul. + * + * NOTICE OF LICENSE + * + * All right is reserved, + * Please go through LICENSE.txt file inside our module + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please refer to CustomizationPolicy.txt file inside our module for more information. + * + * @author Webkul IN + * @copyright 2010-2023 Webkul IN + * @license LICENSE.txt + */ + /* Block newsletter */ #columns #newsletter_block_left .form-group { margin-bottom: 0; } @@ -130,6 +149,31 @@ color: #bfbfbf; } +#blocknewsletter .loader { + margin-left: 10px; + position: relative; + top: 10px; +} + +#blocknewsletter .loader.loading { + display: inline-flex; + justify-content: center; +} + +#blocknewsletter .loader.loading::after { + content: ''; + width: 30px; + height: 30px; + border: 4px solid #dddddd; + border-top-color: transparent; + border-radius: 50%; + animation: loading 0.5s linear infinite; +} + +@-webkit-keyframes loading { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } +@-moz-keyframes loading { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } +@keyframes loading { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } + /*# sourceMappingURL=blocknewsletter.css.map */ .button.button-medium.newsletter-btn { position: relative; diff --git a/themes/hotel-reservation-theme/js/modules/blocknewsletter/blocknewsletter.js b/themes/hotel-reservation-theme/js/modules/blocknewsletter/blocknewsletter.js index b907c15ee..8635bd925 100644 --- a/themes/hotel-reservation-theme/js/modules/blocknewsletter/blocknewsletter.js +++ b/themes/hotel-reservation-theme/js/modules/blocknewsletter/blocknewsletter.js @@ -35,6 +35,8 @@ $(document).on('click', '#blocknewsletter .newsletter-btn', function (e) { beforeSend: function () { let messageBlock = $('#blocknewsletter .message-block'); $(messageBlock).fadeOut('fast'); + + $('#blocknewsletter .loader').show(); }, success: function (response) { let messageBlock = $('#blocknewsletter .message-block'); @@ -44,6 +46,9 @@ $(document).on('click', '#blocknewsletter .newsletter-btn', function (e) { if (jqXHR.readyState == 0) { showErrorMessage(no_internet_txt); } + }, + complete: function () { + $('#blocknewsletter .loader').hide(); } }); }); diff --git a/themes/hotel-reservation-theme/modules/blocknewsletter/blocknewsletter.tpl b/themes/hotel-reservation-theme/modules/blocknewsletter/blocknewsletter.tpl index 8fdbcaaf4..098f0889c 100644 --- a/themes/hotel-reservation-theme/modules/blocknewsletter/blocknewsletter.tpl +++ b/themes/hotel-reservation-theme/modules/blocknewsletter/blocknewsletter.tpl @@ -46,6 +46,7 @@ + From 336b64d7e12c83549d232c5f4869f514c5d267bc Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 14 Sep 2023 11:25:21 +0530 Subject: [PATCH 06/10] Update AdminNewsletterController.php --- .../controllers/admin/AdminNewsletterController.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/blocknewsletter/controllers/admin/AdminNewsletterController.php b/modules/blocknewsletter/controllers/admin/AdminNewsletterController.php index 0956efe23..bf0a67b78 100644 --- a/modules/blocknewsletter/controllers/admin/AdminNewsletterController.php +++ b/modules/blocknewsletter/controllers/admin/AdminNewsletterController.php @@ -296,11 +296,13 @@ class AdminNewsletterController extends ModuleAdminController public function postProcess() { if (Tools::isSubmit('submitNewsletterOptions')) { - $voucherCode = trim(Tools::getValue('NW_VOUCHER_CODE')); - if ($voucherCode && !Validate::isDiscountName($voucherCode)) { - $this->errors[] = $this->l('The voucher code is invalid.'); - } elseif (!CartRule::cartRuleExists($voucherCode)) { - $this->errors[] = $this->l('The voucher code does not exist.'); + $voucherCode = Tools::getValue('NW_VOUCHER_CODE'); + if (Tools::strlen($voucherCode) > 0) { + if (!Validate::isDiscountName($voucherCode)) { + $this->errors[] = $this->l('The voucher code is invalid.'); + } elseif (!CartRule::cartRuleExists($voucherCode)) { + $this->errors[] = $this->l('The voucher code does not exist.'); + } } if (!count($this->errors)) { From 792024ba9f8155ef0f28cf552a54e9a7a21824ee Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 29 Feb 2024 16:18:30 +0530 Subject: [PATCH 07/10] Undo Newsletter checkbox display and fix issues --- .../AdminCustomerPreferencesController.php | 7 + .../admin/AdminCustomersController.php | 4 +- controllers/front/AuthController.php | 2 +- controllers/front/IdentityController.php | 2 + modules/blocknewsletter/blocknewsletter.php | 27 ++-- .../admin/AdminNewsletterController.php | 128 ++++++++++++------ .../controllers/front/verification.php | 18 ++- modules/blocknewsletter/verification.php | 16 --- .../blocknewsletter/views/css/front/index.php | 35 +++++ .../views/css/front/verification.css | 53 ++++++++ modules/blocknewsletter/views/css/index.php | 35 +++++ .../blocknewsletter/views/js/front/index.php | 35 +++++ .../views/js/front/verification.js | 35 +++++ modules/blocknewsletter/views/js/index.php | 35 +++++ .../front/verification_execution.tpl | 19 ++- themes/hotel-reservation-theme/identity.tpl | 20 +-- 16 files changed, 388 insertions(+), 83 deletions(-) delete mode 100644 modules/blocknewsletter/verification.php create mode 100644 modules/blocknewsletter/views/css/front/index.php create mode 100644 modules/blocknewsletter/views/css/front/verification.css create mode 100644 modules/blocknewsletter/views/css/index.php create mode 100644 modules/blocknewsletter/views/js/front/index.php create mode 100644 modules/blocknewsletter/views/js/front/verification.js create mode 100644 modules/blocknewsletter/views/js/index.php diff --git a/controllers/admin/AdminCustomerPreferencesController.php b/controllers/admin/AdminCustomerPreferencesController.php index 1d4799239..a9e94ae53 100644 --- a/controllers/admin/AdminCustomerPreferencesController.php +++ b/controllers/admin/AdminCustomerPreferencesController.php @@ -106,6 +106,13 @@ class AdminCustomerPreferencesControllerCore extends AdminController 'cast' => 'intval', 'type' => 'bool' ), + 'PS_CUSTOMER_NWSL' => array( + 'title' => $this->l('Enable newsletter registration'), + 'hint' => $this->l('Display or not the newsletter registration tick box.'), + 'validation' => 'isBool', + 'cast' => 'intval', + 'type' => 'bool' + ), 'PS_CUSTOMER_OPTIN' => array( 'title' => $this->l('Enable opt-in'), 'hint' => $this->l('Display or not the opt-in tick box, to receive offers from your hotel partners.'), diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 5289958f5..b51123908 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -456,7 +456,9 @@ class AdminCustomersControllerCore extends AdminController 'label' => $this->l('Disabled') ) ), - 'hint' => $this->l('This customer will receive your newsletter via email.') + 'disabled' => (bool)!Configuration::get('PS_CUSTOMER_NWSL'), + 'hint' => $this->l('This customer will receive your newsletter via email.'), + 'desc' => (bool)!Configuration::get('PS_CUSTOMER_NWSL') ? sprintf($this->l('This field is disabled as option \'Enable newsletter registration\' is disabled. You can change it from %sPreferences > Customers%s page.'), '', '') : '', ), array( 'type' => 'switch', diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index eb299f5b6..723e7d86c 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -100,7 +100,7 @@ class AuthControllerCore extends FrontController $this->assignCountries(); - $newsletter = Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active && Configuration::get('PS_CUSTOMER_NWSL'); + $newsletter = Configuration::get('PS_CUSTOMER_NWSL') || (Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active); $this->context->smarty->assign('birthday', (bool) Configuration::get('PS_CUSTOMER_BIRTHDATE')); $this->context->smarty->assign('newsletter', $newsletter); diff --git a/controllers/front/IdentityController.php b/controllers/front/IdentityController.php index 4c7fd4fcc..525168380 100644 --- a/controllers/front/IdentityController.php +++ b/controllers/front/IdentityController.php @@ -155,7 +155,9 @@ class IdentityControllerCore extends FrontController 'HOOK_CUSTOMER_IDENTITY_FORM' => Hook::exec('displayCustomerIdentityForm'), )); + $newsletter = Configuration::get('PS_CUSTOMER_NWSL') || (Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active); $this->context->smarty->assign('birthday', (bool) Configuration::get('PS_CUSTOMER_BIRTHDATE')); + $this->context->smarty->assign('newsletter', $newsletter); $this->context->smarty->assign('optin', (bool)Configuration::get('PS_CUSTOMER_OPTIN')); $this->context->smarty->assign('field_required', $this->context->customer->validateFieldsRequiredDatabase()); diff --git a/modules/blocknewsletter/blocknewsletter.php b/modules/blocknewsletter/blocknewsletter.php index 6dc973d11..d6fded1af 100644 --- a/modules/blocknewsletter/blocknewsletter.php +++ b/modules/blocknewsletter/blocknewsletter.php @@ -176,7 +176,7 @@ class Blocknewsletter extends Module * 1 = registered in block * 2 = registered in customer */ - protected function isNewsletterRegistered($customer_email) + public function isNewsletterRegistered($customer_email) { $sql = 'SELECT `email` FROM '._DB_PREFIX_.'newsletter @@ -355,13 +355,13 @@ class Blocknewsletter extends Module return false; } - protected function unregister($email, $register_status) + public function unregister($email, $register_status) { if ($register_status == self::GUEST_REGISTERED) { - $sql = 'DELETE FROM '._DB_PREFIX_.'newsletter WHERE `email` = \''.pSQL($_POST['email']).'\' AND id_shop = '. + $sql = 'DELETE FROM '._DB_PREFIX_.'newsletter WHERE `email` = \''.pSQL($email).'\' AND id_shop = '. $this->context->shop->id; } elseif ($register_status == self::CUSTOMER_REGISTERED) { - $sql = 'UPDATE '._DB_PREFIX_.'customer SET `newsletter` = 0 WHERE `email` = \''.pSQL($_POST['email']). + $sql = 'UPDATE '._DB_PREFIX_.'customer SET `newsletter` = 0 WHERE `email` = \''.pSQL($email). '\' AND id_shop = '.$this->context->shop->id; } @@ -495,6 +495,7 @@ class Blocknewsletter extends Module */ public function confirmEmail($token) { + $errors = array(); $activated = false; if ($email = $this->getGuestEmailByToken($token)) { @@ -504,18 +505,20 @@ class Blocknewsletter extends Module } if (!$activated) { - return $this->l('This email is already registered and/or invalid.'); + $errors[] = $this->l('This email is already registered and/or invalid.'); } - if ($discount = Configuration::get('NW_VOUCHER_CODE')) { - $this->sendVoucher($email, $discount); + if (!count($errors)) { + if ($discount = Configuration::get('NW_VOUCHER_CODE')) { + $this->sendVoucher($email, $discount); + } + + if (Configuration::get('NW_CONFIRMATION_EMAIL')) { + $this->sendConfirmationEmail($email); + } } - if (Configuration::get('NW_CONFIRMATION_EMAIL')) { - $this->sendConfirmationEmail($email); - } - - return $this->l('Thank you for subscribing to our newsletter.'); + return $errors; } /** diff --git a/modules/blocknewsletter/controllers/admin/AdminNewsletterController.php b/modules/blocknewsletter/controllers/admin/AdminNewsletterController.php index bf0a67b78..752ab0154 100644 --- a/modules/blocknewsletter/controllers/admin/AdminNewsletterController.php +++ b/modules/blocknewsletter/controllers/admin/AdminNewsletterController.php @@ -33,6 +33,7 @@ class AdminNewsletterController extends ModuleAdminController parent::__construct(); $this->addRowAction('viewCustomer'); + $this->addRowAction('delete'); $genderList = array(); $genders = Gender::getGenders($this->context->language->id); @@ -103,14 +104,6 @@ class AdminNewsletterController extends ModuleAdminController $this->list_no_link = true; $this->bulk_actions = array( - 'enableSelection' => array( - 'text' => $this->l('Enable selection'), - 'icon' => 'icon-power-off text-success' - ), - 'disableSelection' => array( - 'text' => $this->l('Disable selection'), - 'icon' => 'icon-power-off text-danger' - ), 'divider' => array( 'text' => 'divider' ), @@ -122,6 +115,7 @@ class AdminNewsletterController extends ModuleAdminController ); $this->_conf[101] = $this->l('The customer has been unsubscribed from newsletter successfully.'); + $this->_conf[102] = $this->l('The selection has been unsubscribed from newsletter successfully.'); } public function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null) @@ -143,18 +137,22 @@ class AdminNewsletterController extends ModuleAdminController public function displayViewCustomerLink($token = null, $id, $name = null) { - $tpl = $this->context->smarty->createTemplate( - $this->module->getTemplatePath( - '/views/templates/admin/'.$this->tpl_folder.'/helpers/list/view-customer-link.tpl' - ) - ); + if (Customer::customerIdExistsStatic($id)) { + $tpl = $this->context->smarty->createTemplate( + $this->module->getTemplatePath( + '/views/templates/admin/'.$this->tpl_folder.'/helpers/list/view-customer-link.tpl' + ) + ); - $tpl->assign(array( - 'id_merged' => $id, - 'disabled' => !Validate::isUnsignedInt($id), - )); + $tpl->assign(array( + 'id_merged' => $id, + 'disabled' => !Validate::isUnsignedInt($id), + )); - return $tpl->fetch(); + return $tpl->fetch(); + } else { + $this->addRowActionSkipList('viewCustomer', $id); + } } public function initToolbar() @@ -194,12 +192,6 @@ class AdminNewsletterController extends ModuleAdminController 'title' => $this->l('Configuration'), 'icon' => 'icon-cogs', 'fields' => array( - 'PS_CUSTOMER_NWSL' => array( - 'type' => 'bool', - 'title' => $this->l('Enable newsletter registration'), - 'validation' => 'isBool', - 'cast' => 'intval', - ), 'NW_VERIFICATION_EMAIL' => array( 'type' => 'bool', 'title' => $this->l('Would you like to send a verification email after subscription?'), @@ -306,7 +298,6 @@ class AdminNewsletterController extends ModuleAdminController } if (!count($this->errors)) { - Configuration::updateValue('PS_CUSTOMER_NWSL', Tools::getValue('PS_CUSTOMER_NWSL')); Configuration::updateValue('NW_VERIFICATION_EMAIL', Tools::getValue('NW_VERIFICATION_EMAIL')); Configuration::updateValue('NW_CONFIRMATION_EMAIL', Tools::getValue('NW_CONFIRMATION_EMAIL')); Configuration::updateValue('NW_VOUCHER_CODE', $voucherCode); @@ -350,28 +341,83 @@ class AdminNewsletterController extends ModuleAdminController parent::postProcess(); } + private function unsubscribeNewsletter($idMerged) + { + $result = false; + $email = ''; + if (preg_match('/(^N)/', $idMerged)) { + $idMerged = (int) substr($idMerged, 1); + $email = Db::getInstance()->getValue( + 'SELECT n.`email` + FROM `'._DB_PREFIX_.'newsletter` n + WHERE n.`id` = '.(int) $idMerged + ); + } else { + $objCustomer = new Customer($idMerged); + if (Validate::isLoadedObject($objCustomer)) { + $email = $objCustomer->email; + } else { + $this->errors[] = $this->l('Customer object can not be loaded.'); + } + } + + if ($email && !count($this->errors)) { + $registrationStatus = $this->module->isNewsletterRegistered($email); + + if ($registrationStatus < 1) { + $this->errors[] = $this->l('This email address is not registered.'); + } + + if (!($result = $this->module->unregister($email, $registrationStatus))) { + $this->errors[] = $this->l('An error occurred while attempting to unsubscribe.'); + } + } + + return $result; + } + public function processUnsubscribeNewsletter() { $idMerged = Tools::getValue('id_merged'); - $result = false; - if (preg_match('/(^N)/', $idMerged)) { - $idMerged = (int) substr($idMerged, 1); - $result = $res = Db::getInstance()->update( - 'newsletter', - array('active' => 0), - 'id = '.(int) $idMerged - ); - } else { - $objCustomer = new Customer($idMerged); - $objCustomer->newsletter = 0; - $result = $objCustomer->update(); - } - - if ($result) { + if ($this->unsubscribeNewsletter($idMerged)) { Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token.'&conf=101'); } else { - $this->errors[] = $this->l('Newsletter subscription failed. Please try again.'); + $this->errors[] = $this->l('Newsletter unsubscription failed. Please try again.'); + } + } + + public function processDelete() + { + $idMerged = Tools::getValue('id_merged'); + + if ($this->unsubscribeNewsletter($idMerged)) { + Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token.'&conf=101'); + } else { + $this->errors[] = $this->l('Newsletter unsubscription failed. Please try again.'); + } + } + + public function processBulkDelete() + { + $result = true; + if (is_array($this->boxes) && !empty($this->boxes)) { + foreach ($this->boxes as $idMerged) { + $deleteOk = $this->unsubscribeNewsletter($idMerged); + $result &= $deleteOk; + + if (!$deleteOk) { + $this->errors[] = sprintf($this->l('Can\'t delete #%d'), $idMerged); + } + } + + if ($result) { + Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token.'&conf=2'); + } else { + $this->errors[] = $this->l('Something went wrong. Please try again.'); + } + } else { + $this->errors[] = $this->l('You must select at least one element to delete.'); } } diff --git a/modules/blocknewsletter/controllers/front/verification.php b/modules/blocknewsletter/controllers/front/verification.php index a1950245e..83232efae 100644 --- a/modules/blocknewsletter/controllers/front/verification.php +++ b/modules/blocknewsletter/controllers/front/verification.php @@ -36,7 +36,10 @@ class BlocknewsletterVerificationModuleFrontController extends ModuleFrontContro */ public function postProcess() { - $this->message = $this->module->confirmEmail(Tools::getValue('token')); + $this->errors = array_merge( + $this->errors, + $this->module->confirmEmail(Tools::getValue('token')) + ); } /** @@ -46,7 +49,18 @@ class BlocknewsletterVerificationModuleFrontController extends ModuleFrontContro { parent::initContent(); - $this->context->smarty->assign('message', $this->message); $this->setTemplate('verification_execution.tpl'); } + + public function setMedia() + { + parent::setMedia(); + + $this->addCSS($this->module->getPathUri().'views/css/front/verification.css'); + $this->addJS($this->module->getPathUri().'views/js/front/verification.js'); + + Media::addJsDef(array( + 'homepage_url' => $this->context->link->getPageLink('index'), + )); + } } diff --git a/modules/blocknewsletter/verification.php b/modules/blocknewsletter/verification.php deleted file mode 100644 index efcb8b3a4..000000000 --- a/modules/blocknewsletter/verification.php +++ /dev/null @@ -1,16 +0,0 @@ -name)) - exit; - -$token = Tools::getValue('token'); - -require_once(dirname(__FILE__).'/../../header.php'); -echo $module->confirmEmail($token); -require_once(dirname(__FILE__).'/../../footer.php'); diff --git a/modules/blocknewsletter/views/css/front/index.php b/modules/blocknewsletter/views/css/front/index.php new file mode 100644 index 000000000..2d4b752c4 --- /dev/null +++ b/modules/blocknewsletter/views/css/front/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2015 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit; diff --git a/modules/blocknewsletter/views/css/front/verification.css b/modules/blocknewsletter/views/css/front/verification.css new file mode 100644 index 000000000..4f113515d --- /dev/null +++ b/modules/blocknewsletter/views/css/front/verification.css @@ -0,0 +1,53 @@ +/* +* 2007-2017 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Open Software License (OSL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/osl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2017 PrestaShop SA +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +.msg-redirect { + font-size: 16px; + color: #333; +} + +.btn-homepage { + border: none; + margin-top: 10px; + border-radius: 2px; + font-size: 14px; + padding: 12px 20px; + font-weight: bold; + background-color: #1292FF; + color: #FFFFFF; +} + +.btn-homepage:hover { + background-color: #1292FF; + opacity: 0.8; +} + +.btn-homepage:focus { + background-color: #1292FF; +} + +.btn-homepage:hover span { + background: none; +} diff --git a/modules/blocknewsletter/views/css/index.php b/modules/blocknewsletter/views/css/index.php new file mode 100644 index 000000000..2d4b752c4 --- /dev/null +++ b/modules/blocknewsletter/views/css/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2015 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit; diff --git a/modules/blocknewsletter/views/js/front/index.php b/modules/blocknewsletter/views/js/front/index.php new file mode 100644 index 000000000..2d4b752c4 --- /dev/null +++ b/modules/blocknewsletter/views/js/front/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2015 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit; diff --git a/modules/blocknewsletter/views/js/front/verification.js b/modules/blocknewsletter/views/js/front/verification.js new file mode 100644 index 000000000..75ab192f9 --- /dev/null +++ b/modules/blocknewsletter/views/js/front/verification.js @@ -0,0 +1,35 @@ +/* +* 2007-2017 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Open Software License (OSL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/osl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2017 PrestaShop SA +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +$(document).ready(function () { + let intervalHandler = setInterval(function () { + let remainingSeconds = parseInt($('.countdown-seconds').text()); + $('.countdown-seconds').html(--remainingSeconds); + if (remainingSeconds <= 0) { + clearInterval(intervalHandler); + window.location = homepage_url; + } + }, 1000); +}); diff --git a/modules/blocknewsletter/views/js/index.php b/modules/blocknewsletter/views/js/index.php new file mode 100644 index 000000000..2d4b752c4 --- /dev/null +++ b/modules/blocknewsletter/views/js/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2015 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit; diff --git a/modules/blocknewsletter/views/templates/front/verification_execution.tpl b/modules/blocknewsletter/views/templates/front/verification_execution.tpl index b3b3aff95..33edc1983 100644 --- a/modules/blocknewsletter/views/templates/front/verification_execution.tpl +++ b/modules/blocknewsletter/views/templates/front/verification_execution.tpl @@ -22,4 +22,21 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} -{$message} \ No newline at end of file + +{include file="$tpl_dir./errors.tpl"} + +{if !count($errors)} +

+ {l s='Thank you for subscribing to our newsletter.' mod='blocknewsletter'} +

+ +

+ {l s='You will be redirected to home page in ' mod='blocknewsletter'} + {l s='5' mod='blocknewsletter'} + {l s='seconds.' mod='blocknewsletter'} +

+ + + {l s='Home Page' mod='blocknewsletter'} + +{/if} diff --git a/themes/hotel-reservation-theme/identity.tpl b/themes/hotel-reservation-theme/identity.tpl index fe5bd69c8..63d5645b5 100644 --- a/themes/hotel-reservation-theme/identity.tpl +++ b/themes/hotel-reservation-theme/identity.tpl @@ -149,15 +149,17 @@ -
- -
+ {if isset($newsletter) && $newsletter} +
+ +
+ {/if} {if isset($optin) && $optin}