From d0501369b695d0c7f6f2cc477470e5ce5e1e2972 Mon Sep 17 00:00:00 2001 From: Kaarel Rooparg Date: Tue, 23 Apr 2019 13:45:13 +0300 Subject: [PATCH 1/5] Initial changes due to workflows. Removed api key and autoresponder from opt-in form. Settings page has 3 tabs. New javascript error messages handling. Separate enable field for customer and cart cron. Removed api key from settings. Added option to remove credentials. No autoresponder required for opt-in settings. Cron tokens auto generated. Added help text for cron tokens. Cron url now dynamic. Abandoned cart delay now in minutes. Added spinner for showing loading. Translated admin js messages. No autoresponders created message in options list. Separate getAutoresponders function ajax call. Two separate files for cron tasks for better timing purposes. Subdomain url-parsing in admin settings. Using workflows api to get autoresponders. --- README.md | 4 + ...AdminSmailyforprestashopAjaxController.php | 77 ++- .../{SmailyCron.php => SmailyCartCron.php} | 118 +---- controllers/front/SmailyCustomerCron.php | 204 ++++++++ smailyforprestashop.php | 158 +++--- translations/et.php | 61 ++- views/js/smaily_module.js | 196 +++++--- views/templates/admin/smaily_configure.tpl | 474 ++++++++++-------- .../templates/hook/smaily_blocknewsletter.tpl | 5 +- 9 files changed, 780 insertions(+), 517 deletions(-) rename controllers/front/{SmailyCron.php => SmailyCartCron.php} (66%) create mode 100644 controllers/front/SmailyCustomerCron.php diff --git a/README.md b/README.md index 473afa0..74b6202 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,10 @@ Product category: {{ product_category_[1-10] }}. ## Changelog +### 1.2.0 + +Changes due to Smaily workflows automation + ### 1.1.0 - 2019 - New Feature. Added Abandoned cart support. diff --git a/controllers/admin/AdminSmailyforprestashopAjaxController.php b/controllers/admin/AdminSmailyforprestashopAjaxController.php index 476fbc2..2f44707 100644 --- a/controllers/admin/AdminSmailyforprestashopAjaxController.php +++ b/controllers/admin/AdminSmailyforprestashopAjaxController.php @@ -67,9 +67,23 @@ public function ajaxProcessSmailyValidate() $response = array('error' => $this->l('Please enter password!')); die(Tools::jsonEncode($response)); } + + $subdomain = Tools::getValue('subdomain'); + // Normalize subdomain. + // First, try to parse as full URL. If that fails, try to parse as subdomain.sendsmaily.net, and + // if all else fails, then clean up subdomain and pass as is. + if (filter_var($subdomain, FILTER_VALIDATE_URL)) { + $url = parse_url($subdomain); + $parts = explode('.', $url['host']); + $subdomain = count($parts) >= 3 ? $parts[0] : ''; + } elseif (preg_match('/^[^\.]+\.sendsmaily\.net$/', $subdomain)) { + $parts = explode('.', $subdomain); + $subdomain = $parts[0]; + } + $subdomain = preg_replace('/[^a-zA-Z0-9]+/', '', $subdomain); + // Clean user entered subdomain. - $subdomain = pSQL(Tools::getValue('subdomain')); - $subdomain = trim(Tools::stripslashes($subdomain)); + $subdomain = pSQL($subdomain); // Clean user entered username $username = pSQL(Tools::getValue('username')); $username = trim(Tools::stripslashes($username)); @@ -77,11 +91,47 @@ public function ajaxProcessSmailyValidate() $password = pSQL(Tools::getValue('password')); $password = trim(Tools::stripslashes($password)); // Make API call to Smaily to get autoresponders list. - $response = $this->callApi('autoresponder', $subdomain, $username, $password); + $response = $this->callApi( + 'workflows', + $subdomain, + $username, + $password, + ['trigger_type' => 'form_submitted'] + ); + // Failsafe for empty response. if (!$response) { $response = array('error' => $this->l('Invalid login details!')); die(Tools::jsonEncode($response)); } + // Add credentials to DB if successfully validated. + if (array_key_exists('success', $response)) { + Configuration::updateValue('SMAILY_SUBDOMAIN', $subdomain); + Configuration::updateValue('SMAILY_USERNAME', $username); + Configuration::updateValue('SMAILY_PASSWORD', $password); + } + die(Tools::jsonEncode($response)); + } + } + + public function ajaxProcessGetAutoresponders() + { + $response = []; + // Validate token and if request is ajax call. + if (Tools::getValue('ajax') && + Tools::getValue('token') === Tools::getAdminTokenLite('AdminSmailyforprestashopAjax') + ) { + // Get credentials from db. + $subdomain = pSQL(Configuration::get('SMAILY_SUBDOMAIN')); + $username = pSQL(Configuration::get('SMAILY_USERNAME')); + $password = pSQL(Configuration::get('SMAILY_PASSWORD')); + // Make API call to Smaily to get autoresponders list. + $response = $this->callApi( + 'workflows', + $subdomain, + $username, + $password, + ['trigger_type' => 'form_submitted'] + ); die(Tools::jsonEncode($response)); } } @@ -120,14 +170,23 @@ public function callApi($endpoint, $subdomain, $username, $password, $data = arr $result = json_decode(curl_exec($ch), true); $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); - if ((int) $http_status === 401) { - return $result = array('error' => $this->l('Check credentials, unauthorized!')); - } - - if (curl_errno($ch)) { + if (!curl_errno($ch)) { + switch ((int) $http_status) { + case 200: + return array('success' => true, 'autoresponders' => $result); + break; + case 401: + return $result = array('error' => $this->l('Check credentials, unauthorized!')); + break; + case 404: + return $result = array('error' => $this->l('Check subdomain, unauthorized!')); + break; + default: + return $result = array('error' => $this->l('Something went wrong with request to Smaily!')); + } + } else { return $result = array("error" => $this->l(curl_error($ch))); } curl_close($ch); - return array('success' => true, 'autoresponders' => $result); } } diff --git a/controllers/front/SmailyCron.php b/controllers/front/SmailyCartCron.php similarity index 66% rename from controllers/front/SmailyCron.php rename to controllers/front/SmailyCartCron.php index ebe130b..2552d8d 100644 --- a/controllers/front/SmailyCron.php +++ b/controllers/front/SmailyCartCron.php @@ -22,84 +22,20 @@ * @license GPL3 */ -class SmailyforprestashopSmailyCronModuleFrontController extends ModuleFrontController +class SmailyforprestashopSmailyCartCronModuleFrontController extends ModuleFrontController { public function init() { parent::init(); - if (Tools::getValue('token') == Configuration::get('SMAILY_CRON_TOKEN')) { - $this->syncContacts(); + header('Content-Type: text/plain'); + if (Tools::getValue('token') == Configuration::get('SMAILY_CART_CRON_TOKEN')) { $this->abandonedCart(); + die(); } else { die($this->l('Access denied! ')); } } - /** - * Synchronize prestashop contacts with smaily database. - * @return void - */ - private function syncContacts() - { - if (Configuration::get('SMAILY_ENABLE_CRON') === "1") { - /** - * Get unsubscribers from smaily database and unsubscribe these users in Prestashop. - */ - // Get unsubscribers from smaily. - $unsubscribers = $this->getUnsubscribers(); - // Unsubscribed emails array - $unsubscribers_email = array(); - if (!empty($unsubscribers)) { - foreach ($unsubscribers as $unsubscriber) { - $unsubscribers_email[] = $unsubscriber['email']; - } - } - // Get subscribed customers from store database. - $customers = Db::getInstance()->executeS("Select * from "._DB_PREFIX_."customer WHERE newsletter=1"); - // Subscribed customers email array. - $customers_subscribed = array(); - if (!empty($customers)) { - // Add customer emails to array. - foreach ($customers as $customer) { - $customers_subscribed[] = $customer['email']; - } - // Remove subscribed status for unsubscribers. - foreach ($customers_subscribed as $customer) { - if (in_array($customer, $unsubscribers_email)) { - $query = 'UPDATE ' . _DB_PREFIX_ . 'customer SET newsletter=0 WHERE email="' . - pSQL($customer) . '"'; - Db::getInstance()->execute($query); - } - } - } - /** - * Sends subscribed customer data to smaily based on settings from - * configuration page - */ - $update_data = array(); - if (!empty($customers)) { - foreach ($customers as $customer) { - $userdata = $this->getUserData($customer); - array_push($update_data, $userdata); - } - // Send subscribers to Smaily. - $response = $this->callApi('contact', $update_data, 'POST'); - // Response logging. - if (isset($response['success'])) { - $response = $response['result']['message']; - } else { - $response = $response['error']; - } - } else { - $response = 'No customers to update!'; - } - $this->logTofile('smaily-cron.txt', $response); - echo($this->l('User synchronization done! ')); - } else { - echo($this->l('User synchronization disabled! ')); - } - } - /** * Send abandoned cart emails to customers. * @@ -186,9 +122,9 @@ private function abandonedCart() } } } - echo($this->l('Abandoned carts emails sent! ')); + echo($this->l('Abandoned carts emails sent!')); } else { - echo($this->l('Abandoned cart disabled! ')); + echo($this->l('Abandoned cart disabled!')); } } @@ -226,48 +162,6 @@ private function checkEmailSent(int $id_cart) } } - - /** - * Get user data for costumer based on settings for Syncronize Additional. - * - * @param array $customer Customer array from Presta DB. - * @return array $userdata Customer field values based of settings in Syncronize Additional. - */ - private function getUserData($customer) - { - $userdata = array(); - $syncronize_additonal = unserialize(Configuration::get('SMAILY_SYNCRONIZE_ADDITIONAL')); - if (!empty($syncronize_additonal)) { - foreach ($syncronize_additonal as $sync_data) { - $userdata[pSQL($sync_data)] = $customer[pSQL($sync_data)]; - } - } - $userdata['email'] = pSQL($customer['email']); - return $userdata; - } - - /** - * Get unsubscribed users list from Smaily. - * - * @return array $unsubscribers Unsubscribers list from Smaily. - */ - private function getUnsubscribers() - { - $data = array( - 'list' => 2, - ); - // Api call to Smaily - $response = $this->callApi('contact', $data); - // If successful return unsubscribers. - if (isset($response['success'])) { - return $response['result']; - // If has errors save errors to log. - } else { - $this->logTofile('smaily-cron.txt', $response['error']); - return array(); - } - } - /** * Makes API call to Smaily. * diff --git a/controllers/front/SmailyCustomerCron.php b/controllers/front/SmailyCustomerCron.php new file mode 100644 index 0000000..b4eed8c --- /dev/null +++ b/controllers/front/SmailyCustomerCron.php @@ -0,0 +1,204 @@ +. + * + * @author Smaily + * @copyright 2018 Smaily + * @license GPL3 + */ + +class SmailyforprestashopSmailyCustomerCronModuleFrontController extends ModuleFrontController +{ + public function init() + { + parent::init(); + header('Content-Type: text/plain'); + if (Tools::getValue('token') == Configuration::get('SMAILY_CUSTOMER_CRON_TOKEN')) { + $module = Module::getInstanceByName('smailyforprestashop'); + $this->syncContacts(); + die(); + } else { + die($this->l('Access denied! ')); + } + } + + /** + * Synchronize prestashop contacts with smaily database. + * @return void + */ + private function syncContacts() + { + if (Configuration::get('SMAILY_ENABLE_CRON') === "1") { + /** + * Get unsubscribers from smaily database and unsubscribe these users in Prestashop. + */ + // Get unsubscribers from smaily. + $unsubscribers = $this->getUnsubscribers(); + // Unsubscribed emails array + $unsubscribers_email = array(); + if (!empty($unsubscribers)) { + foreach ($unsubscribers as $unsubscriber) { + $unsubscribers_email[] = $unsubscriber['email']; + } + } + // Get subscribed customers from store database. + $customers = Db::getInstance()->executeS("Select * from "._DB_PREFIX_."customer WHERE newsletter=1"); + // Subscribed customers email array. + $customers_subscribed = array(); + if (!empty($customers)) { + // Add customer emails to array. + foreach ($customers as $customer) { + $customers_subscribed[] = $customer['email']; + } + // Remove subscribed status for unsubscribers. + foreach ($customers_subscribed as $customer) { + if (in_array($customer, $unsubscribers_email)) { + $query = 'UPDATE ' . _DB_PREFIX_ . 'customer SET newsletter=0 WHERE email="' . + pSQL($customer) . '"'; + Db::getInstance()->execute($query); + } + } + } + /** + * Sends subscribed customer data to smaily based on settings from + * configuration page + */ + $update_data = array(); + if (!empty($customers)) { + foreach ($customers as $customer) { + $userdata = $this->getUserData($customer); + array_push($update_data, $userdata); + } + // Send subscribers to Smaily. + $response = $this->callApi('contact', $update_data, 'POST'); + // Response logging. + if (isset($response['success'])) { + $response = $response['result']['message']; + } else { + $response = $response['error']; + } + } else { + $response = 'No customers to update!'; + } + $this->logTofile('smaily-cron.txt', $response); + echo($this->l('User synchronization done! ')); + } else { + echo($this->l('User synchronization disabled! ')); + } + } + + /** + * Get user data for costumer based on settings for Syncronize Additional. + * + * @param array $customer Customer array from Presta DB. + * @return array $userdata Customer field values based of settings in Syncronize Additional. + */ + private function getUserData($customer) + { + $userdata = array(); + $syncronize_additonal = unserialize(Configuration::get('SMAILY_SYNCRONIZE_ADDITIONAL')); + if (!empty($syncronize_additonal)) { + foreach ($syncronize_additonal as $sync_data) { + $userdata[pSQL($sync_data)] = $customer[pSQL($sync_data)]; + } + } + $userdata['email'] = pSQL($customer['email']); + return $userdata; + } + + /** + * Get unsubscribed users list from Smaily. + * + * @return array $unsubscribers Unsubscribers list from Smaily. + */ + private function getUnsubscribers() + { + $data = array( + 'list' => 2, + ); + // Api call to Smaily + $response = $this->callApi('contact', $data); + // If successful return unsubscribers. + if (isset($response['success'])) { + return $response['result']; + // If has errors save errors to log. + } else { + $this->logTofile('smaily-cron.txt', $response['error']); + return array(); + } + } + + /** + * Makes API call to Smaily. + * + * @param string $endpoint Endpoint of smaily API without .php + * @param array $data Data to be sent to API. + * @param string $method 'GET' or 'POST' method. + * @return array $response Response from smaily api. + */ + private function callApi(string $endpoint, array $data, string $method = 'GET') + { + // Smaily api credentials. + $subdomain = pSQL(Configuration::get('SMAILY_SUBDOMAIN')); + $username = pSQL(Configuration::get('SMAILY_USERNAME')); + $password = pSQL(Configuration::get('SMAILY_PASSWORD')); + + // API call. + $apiUrl = "https://" . $subdomain . ".sendsmaily.net/api/" . trim($endpoint, '/') . ".php"; + $data = http_build_query($data); + if ($method == 'GET') { + $apiUrl = $apiUrl.'?'.$data; + } + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $apiUrl); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + if ($method == 'POST') { + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + } + curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + $result = json_decode(curl_exec($ch), true); + // Error handling + $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + if ((int) $http_status === 401) { + return $result = array('error' => $this->l('Check credentials, unauthorized!')); + } + if (curl_errno($ch)) { + return $result = array("error" => curl_error($ch)); + } + // Close connection and send response. + curl_close($ch); + return array('success' => true, 'result' => $result); + } + /** + * Log API response to text-file. + * + * @param string $filename Name of the file created. + * @param string $msg Text response from api. + * @return void + */ + private function logToFile($filename, $response) + { + $logger = new FileLogger(1); + $logger->setFilename(_PS_MODULE_DIR_. $this->module->name ."/" . $filename); + $logger->logInfo('Response from API - ' . $response); + } +} diff --git a/smailyforprestashop.php b/smailyforprestashop.php index ad3ae27..5314f94 100644 --- a/smailyforprestashop.php +++ b/smailyforprestashop.php @@ -32,7 +32,7 @@ public function __construct() { $this->name = 'smailyforprestashop'; $this->tab = 'advertising_marketing'; - $this->version = '1.1.0'; + $this->version = '1.2.0'; $this->author = 'Smaily'; $this->need_instance = 0; $this->ps_versions_compliancy = array( @@ -62,12 +62,11 @@ public function install() // Check that you can add Smaily settings field values. !Configuration::updateValue('SMAILY_ENABLE_CRON', 0) || !Configuration::updateValue('SMAILY_ENABLE_ABANDONED_CART', 0) || - !Configuration::updateValue('SMAILY_CRON_TOKEN', '') || + !Configuration::updateValue('SMAILY_CUSTOMER_CRON_TOKEN', '') || + !Configuration::updateValue('SMAILY_CART_CRON_TOKEN', '') || !Configuration::updateValue('SMAILY_SUBDOMAIN', '') || !Configuration::updateValue('SMAILY_USERNAME', '') || !Configuration::updateValue('SMAILY_PASSWORD', '') || - !Configuration::updateValue('SMAILY_API_KEY', '') || - !Configuration::updateValue('SMAILY_AUTORESPONDER', '') || !Configuration::updateValue('SMAILY_CART_AUTORESPONDER', '') || !Configuration::updateValue('SMAILY_ABANDONED_CART_TIME', '') || !Configuration::updateValue('SMAILY_SYNCRONIZE_ADDITIONAL', serialize(array())) || @@ -111,12 +110,11 @@ public function uninstall() // Delete settings created by module. !Configuration::deleteByName('SMAILY_ENABLE_CRON') || !Configuration::deleteByName('SMAILY_ENABLE_ABANDONED_CART') || - !Configuration::deleteByName('SMAILY_CRON_TOKEN') || + !Configuration::deleteByName('SMAILY_CUSTOMER_CRON_TOKEN') || + !Configuration::deleteByName('SMAILY_CART_CRON_TOKEN') || !Configuration::deleteByName('SMAILY_SUBDOMAIN') || !Configuration::deleteByName('SMAILY_USERNAME') || !Configuration::deleteByName('SMAILY_PASSWORD') || - !Configuration::deleteByName('SMAILY_API_KEY') || - !Configuration::deleteByName('SMAILY_AUTORESPONDER') || !Configuration::deleteByName('SMAILY_CART_AUTORESPONDER') || !Configuration::deleteByName('SMAILY_ABANDONED_CART_TIME') || !Configuration::deleteByName('SMAILY_SYNCRONIZE_ADDITIONAL') || @@ -145,36 +143,35 @@ public function getContent() $output = null; $this->context->controller->addJquery(); + if (Tools::isSubmit('smaily_remove_credentials')) { + if (Configuration::updateValue('SMAILY_SUBDOMAIN', '') && + Configuration::updateValue('SMAILY_USERNAME', '') && + Configuration::updateValue('SMAILY_PASSWORD', '') + ) { + // Disable customer sync. + Configuration::updateValue('SMAILY_ENABLE_CRON', 0); + // Disable abandoned cart cron and remove autoresponder. + Configuration::updateValue('SMAILY_ENABLE_ABANDONED_CART', 0); + Configuration::updateValue('SMAILY_CART_AUTORESPONDER', ''); + // Return success message. + $output .= $this->displayConfirmation($this->l('Credentials removed!')); + } else { + // Return error message + $output .= $this->displayError($this->l('Something went wrong removing credentials')); + } + } + + // Customer sync form. if (Tools::isSubmit('smaily_submit_configuration')) { // Enable Cron. $enable_cron = pSQL(Tools::getValue('SMAILY_ENABLE_CRON')); - // Cron token. - $cron_token = pSQL(Tools::getValue('SMAILY_CRON_TOKEN')); - $cron_token = trim(Tools::stripslashes($cron_token)); - // Subdomain. - $subdomain = pSQL(Tools::getValue('SMAILY_SUBDOMAIN')); - $subdomain = trim(Tools::stripslashes($subdomain)); - // Username - $username = pSQL(Tools::getValue('SMAILY_USERNAME')); - $username = trim(Tools::stripslashes($username)); - // Password. - $password = pSQL(Tools::getValue('SMAILY_PASSWORD')); - $password = trim(Tools::stripslashes($password)); - // Api key. - $api_key = pSQL(Tools::getValue('SMAILY_API_KEY')); - $api_key = trim(Tools::stripslashes($api_key)); - // Autoresponder. - $autoresponder = pSQL((Tools::getValue('SMAILY_AUTORESPONDER'))); - $autoresponder = str_replace('\"', '"', $autoresponder); - // Get autoresponder array from json string. - $autoresponder = Tools::jsonDecode($autoresponder); - // Clean autoresponder for inserting to database. - $escaped_autoresponder = array(); - if (!empty($autoresponder)) { - foreach ($autoresponder as $key => $value) { - $escaped_autoresponder[ pSQL($key)] = pSQL($value); - } + // Customer cron token. + $customer_cron_token = pSQL(Tools::getValue('SMAILY_CUSTOMER_CRON_TOKEN')); + $customer_cron_token = trim(Tools::stripslashes($customer_cron_token)); + if (empty($customer_cron_token)) { + $customer_cron_token = bin2hex(random_bytes(6)); } + // Syncronize additional. $syncronize_additional = Tools::getValue('SMAILY_SYNCRONIZE_ADDITIONAL'); $escaped_sync_additional = array(); @@ -183,40 +180,32 @@ public function getContent() $escaped_sync_additional[] = pSQL($value); } } - if (!$subdomain || - empty($subdomain) || - !$username || - empty($username) || - !$password || - empty($password) || - !$api_key || - empty($api_key) || - !$autoresponder || - empty($autoresponder) - ) { + // Check if subdomain is saved to db to verify that credentials are validated. + if (empty(Configuration::get('SMAILY_SUBDOMAIN'))) { // Display error message. - $output .= $this->displayError($this->l('Please fill out required fields.')); + $output .= $this->displayError($this->l('Please validate credentials before saving.')); } else { // Update settings. Configuration::updateValue('SMAILY_ENABLE_CRON', $enable_cron); - Configuration::updateValue('SMAILY_CRON_TOKEN', $cron_token); - Configuration::updateValue('SMAILY_SUBDOMAIN', $subdomain); - Configuration::updateValue('SMAILY_USERNAME', $username); - Configuration::updateValue('SMAILY_PASSWORD', $password); - Configuration::updateValue('SMAILY_API_KEY', $api_key); - Configuration::updateValue('SMAILY_AUTORESPONDER', serialize($escaped_autoresponder)); + Configuration::updateValue('SMAILY_CUSTOMER_CRON_TOKEN', $customer_cron_token); Configuration::updateValue('SMAILY_SYNCRONIZE_ADDITIONAL', serialize($escaped_sync_additional)); // Display success message. $output .= $this->displayConfirmation($this->l('Settings updated')); } } - + // Abandoned cart form. if (Tools::isSubmit('smaily_submit_abandoned_cart')) { // Enable Abandoned Cart. $enable_abandoned_cart = pSQL(Tools::getValue('SMAILY_ENABLE_ABANDONED_CART')); // Abandoned cart delay time $abandoned_cart_time = pSQL(Tools::getValue('SMAILY_ABANDONED_CART_TIME')); $abandoned_cart_time = (int) trim(Tools::stripslashes($abandoned_cart_time)); + // Cart cron token. + $cart_cron_token = pSQL(Tools::getValue('SMAILY_CART_CRON_TOKEN')); + $cart_cron_token = trim(Tools::stripslashes($cart_cron_token)); + if (empty($cart_cron_token)) { + $cart_cron_token = bin2hex(random_bytes(6)); + } // Abandoned cart Autoresponder $cart_autoresponder = pSQL((Tools::getValue('SMAILY_CART_AUTORESPONDER'))); $cart_autoresponder = str_replace('\"', '"', $cart_autoresponder); @@ -237,13 +226,18 @@ public function getContent() $cart_escaped_sync_additional[] = pSQL($value); } } - if ($abandoned_cart_time < 1) { + // Validate autoresponder time and autoresponder for cart. + if ($abandoned_cart_time < 15) { + // Display error message. + $output .= $this->displayError($this->l('Abandoned cart delay has to be atleast 15 minutes.')); + } elseif ((int)$enable_abandoned_cart === 1 && empty($cart_autoresponder)) { // Display error message. - $output .= $this->displayError($this->l('Abandoned cart delay has to be number value over 0.')); + $output .= $this->displayError($this->l('Select autoresponder for abandoned cart.')); } else { Configuration::updateValue('SMAILY_ENABLE_ABANDONED_CART', $enable_abandoned_cart); Configuration::updateValue('SMAILY_CART_AUTORESPONDER', serialize($escaped_cart_autoresponder)); Configuration::updateValue('SMAILY_ABANDONED_CART_TIME', $abandoned_cart_time); + Configuration::updateValue('SMAILY_CART_CRON_TOKEN', $cart_cron_token); Configuration::updateValue( 'SMAILY_CART_SYNCRONIZE_ADDITIONAL', serialize($cart_escaped_sync_additional) @@ -265,50 +259,62 @@ public function getContent() } else { $cart_sync_array = array(); } - // Get autoresponder values for template. - $autoresponder_for_template = pSQL((Configuration::get('SMAILY_AUTORESPONDER'))); - $autoresponder_for_template = str_replace('\"', '"', $autoresponder_for_template); - $autoresponder_for_template = unserialize($autoresponder_for_template); + // Get customer cron token or generate random string when not set. + if (false != Configuration::get('SMAILY_CUSTOMER_CRON_TOKEN')) { + $customer_cron_token = pSQL(Configuration::get('SMAILY_CUSTOMER_CRON_TOKEN')); + } else { + $customer_cron_token = bin2hex(random_bytes(6)); + } + // Get cart cron token or generate random string when not set. + if (false != Configuration::get('SMAILY_CART_CRON_TOKEN')) { + $cart_cron_token = pSQL(Configuration::get('SMAILY_CART_CRON_TOKEN')); + } else { + $cart_cron_token = bin2hex(random_bytes(6)); + } // Get abandoned cart autoresponder values for template. $cart_autoresponder_for_template = pSQL((Configuration::get('SMAILY_CART_AUTORESPONDER'))); $cart_autoresponder_for_template = str_replace('\"', '"', $cart_autoresponder_for_template); $cart_autoresponder_for_template = unserialize($cart_autoresponder_for_template); // Assign variables to template if available. - $this->context->smarty->assign(array( + $this->context->smarty->assign( + array( 'smaily_enable_cron' => pSQL(Configuration::get('SMAILY_ENABLE_CRON')), 'smaily_enable_abandoned_cart' => pSQL(Configuration::get('SMAILY_ENABLE_ABANDONED_CART')), - 'smaily_cron_token' => pSQL(Configuration::get('SMAILY_CRON_TOKEN')), + 'smaily_customer_cron_token' => $customer_cron_token, + 'smaily_cart_cron_token' => $cart_cron_token, 'smaily_subdomain' => pSQL(Configuration::get('SMAILY_SUBDOMAIN')), 'smaily_username' => pSQL(Configuration::get('SMAILY_USERNAME')), 'smaily_password' => pSQL(Configuration::get('SMAILY_PASSWORD')), - 'smaily_api_key' => pSQL(Configuration::get('SMAILY_API_KEY')), - 'smaily_autoresponder' => $autoresponder_for_template, 'smaily_cart_autoresponder' => $cart_autoresponder_for_template, 'smaily_abandoned_cart_time' => pSQL(Configuration::get('SMAILY_ABANDONED_CART_TIME')), 'smaily_syncronize_additional' => $sync_array, 'smaily_cart_syncronize_additional' => $cart_sync_array, 'token' => Tools::getAdminTokenLite('AdminSmailyforprestashopAjax'), 'smaily_rssfeed_url' => Context::getContext()->link->getModuleLink('smailyforprestashop', 'SmailyRssFeed'), - 'smaily_cron_url' => Context::getContext()->link->getModuleLink('smailyforprestashop', 'SmailyCron'), - )); + 'smaily_customer_cron_url' => Context::getContext()->link->getModuleLink( + 'smailyforprestashop', + 'SmailyCustomerCron' + ), + 'smaily_cart_cron_url' => Context::getContext()->link->getModuleLink( + 'smailyforprestashop', + 'SmailyCartCron' + ), + ) + ); // Display settings form. return $output .= $this->display(__FILE__, 'views/templates/admin/smaily_configure.tpl'); } - // Display Block Newsletter + // Display Block Newsletter in footer. public function hookDisplayFooterBefore($params) { - // Get autoresponder ID from settings. - $autoresponder = unserialize(Configuration::get('SMAILY_AUTORESPONDER')); - $autoresponder_id = pSQL($autoresponder['id']); - // Add values to template. + // Add subdomain to template. $this->context->smarty->assign(array( 'smaily_subdomain' => pSQL(Configuration::get('SMAILY_SUBDOMAIN')), - 'smaily_api_key' => pSQL(Configuration::get('SMAILY_API_KEY')), - 'smaily_autoresponder' => $autoresponder_id )); return $this->display(__FILE__, 'smaily_blocknewsletter.tpl'); } + // Add JQuerry and module javascript. public function hookDisplayBackOfficeHeader() { @@ -317,6 +323,16 @@ public function hookDisplayBackOfficeHeader() // Add JQuerry before module javascript. $this->context->controller->addJquery(); $this->context->controller->addJS(array($this->_path.'views/js/smaily_module.js')); + // Add translated text for js variables. + Media::addJsDef( + array( + 'smailymessages' => array( + 'no_autoresponders' => $this->l('No autoresponders created in Smaily!'), + 'no_connection' => $this->l('There seems to be some problem with connecting to Smaily!'), + 'credentials_validated' => $this->l('Smaily credentials validated!') + ) + ) + ); } } } diff --git a/translations/et.php b/translations/et.php index 4298024..d1af026 100644 --- a/translations/et.php +++ b/translations/et.php @@ -2,63 +2,74 @@ global $_MODULE; $_MODULE = array(); -$_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_d51392bec6ce4585c3b03031b2197109'] = 'Smaily Prestashopile'; +$_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_d51392bec6ce4585c3b03031b2197109'] = 'Smaily Moodul Prestashopile'; $_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_3e614e6ed6a76b403e9cc5ce027ac0a9'] = 'Smaily E-turunduse ja kontaktide automaatse sünkrooniseerimise moodul Prestashopile'; $_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_876f23178c29dc2552c0b48bf23cd9bd'] = 'Kas oled kindel, et tahad moodulit eemaldada?'; -$_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_26e461482198fecd4c7f37a9f4aeaa93'] = 'Palun täida kõik kohustuslikud väljad.'; +$_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_d5bec2f567bdc848c592895659d5c32e'] = 'Sisselogimisandmed eemaldatud!'; +$_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_6439004ba361747ed7f2d96474a8a051'] = 'Tõrge sisselogimisandmete eemaldamisel'; +$_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_6464751d51688e4b41837605fff13a95'] = 'Palun valideeri sisselogimisandmed enne salvestamist.'; $_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_c888438d14855d7d96a2724ee9c306bd'] = 'Seaded uuendatud'; -$_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_933e90911ed45ec810cc55bf129805ae'] = 'Unustatud ostukorvi meeldetuletuse viivitus peab olema number üle nulli.'; +$_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_8ec70278e10dea192b0a722461e8ee46'] = 'Unustatud ostukorvi viivitus peab olema vähemalt 15 minutit.'; +$_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_62a01c1290186dbd91f4d4602c476f58'] = 'Vali unustatud ostukorvi automaatvastaja'; $_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_daa6895e7a9ba2ad71b8e8094df4556b'] = 'Unustatud ostukorvi sätted salvestatud'; +$_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_d4fd3bc1732761a4497d35898051f6b3'] = 'Puuduvad Smaily automaatvastajad!'; +$_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_3bd9a770a0cdadf35e95645048e5fd23'] = 'Ilmnes tõrge Smaily teenusega ühildumisel!'; +$_MODULE['<{smailyforprestashop}prestashop>smailyforprestashop_95e979b91ee119662cd5ee6b85ee07e6'] = 'Sisselogimisandmed kinnitatud!'; $_MODULE['<{smailyforprestashop}prestashop>adminsmailyforprestashopajaxcontroller_04ce02c2ca2327bc6651fd8359e29959'] = 'Palun sisesta alamdomeen!'; $_MODULE['<{smailyforprestashop}prestashop>adminsmailyforprestashopajaxcontroller_544373e5036db114055a7273925d383d'] = 'Palun sisesta kasutajatunnus!'; $_MODULE['<{smailyforprestashop}prestashop>adminsmailyforprestashopajaxcontroller_afa29ddf9281626cc3c38c6916fc85f8'] = 'Palun sisesta parool!'; $_MODULE['<{smailyforprestashop}prestashop>adminsmailyforprestashopajaxcontroller_df512a7db3e4bf5e63c9ea0b21382b5b'] = 'Viga sisestatud andmetes!'; $_MODULE['<{smailyforprestashop}prestashop>adminsmailyforprestashopajaxcontroller_b55a2b2d84680417f12898a11647a1cb'] = 'Vale kasutajatunnus või parool!'; -$_MODULE['<{smailyforprestashop}prestashop>smailycron_b6961ca850d0a1eeee4221dd8c395e94'] = 'Ligipääs puudub!'; -$_MODULE['<{smailyforprestashop}prestashop>smailycron_0b95ad8777cb2e8bec39166257036f4a'] = 'Kasutajad sünkroonitud!'; -$_MODULE['<{smailyforprestashop}prestashop>smailycron_6fc744259b2bb6c969c9ce02ff2bbbed'] = 'Kasutajate sünkroonimine deaktiivne!'; -$_MODULE['<{smailyforprestashop}prestashop>smailycron_4ed11cf2a180d172836eac97c264122a'] = 'Unustatud ostukorvi emailid saadetud!'; -$_MODULE['<{smailyforprestashop}prestashop>smailycron_ff0f6b0cf4d70ad36a09f7079be3f546'] = 'Unustatud ostukorvi meeldetuletus deaktiveeritud!'; -$_MODULE['<{smailyforprestashop}prestashop>smailycron_b55a2b2d84680417f12898a11647a1cb'] = 'Vale kasutajatunnus või parool!'; +$_MODULE['<{smailyforprestashop}prestashop>adminsmailyforprestashopajaxcontroller_8806bbf77c1a0da89c5235fa868bc3cf'] = 'Vale alamdomeen!'; +$_MODULE['<{smailyforprestashop}prestashop>adminsmailyforprestashopajaxcontroller_e57cbdfe3a6c5715d95e860754b4101a'] = 'Ilmnes tõrge Smaily teenusega ühildumisel!'; +$_MODULE['<{smailyforprestashop}prestashop>smailycartcron_b6961ca850d0a1eeee4221dd8c395e94'] = 'Ligipääs puudub!'; +$_MODULE['<{smailyforprestashop}prestashop>smailycartcron_6b60fc1bb60fe0c4b72238ad755fb54c'] = 'Unustatud ostukovi kirjad saadetud!'; +$_MODULE['<{smailyforprestashop}prestashop>smailycartcron_5044b716f8e0cc4babdc5390d8d97144'] = 'Unustatud ostukorvi meeldetuletus ei ole aktiivne!'; +$_MODULE['<{smailyforprestashop}prestashop>smailycartcron_b55a2b2d84680417f12898a11647a1cb'] = 'Vale kasutajatunnus või parool!'; +$_MODULE['<{smailyforprestashop}prestashop>smailycustomercron_b6961ca850d0a1eeee4221dd8c395e94'] = 'Ligipääs puudub!'; +$_MODULE['<{smailyforprestashop}prestashop>smailycustomercron_0b95ad8777cb2e8bec39166257036f4a'] = 'Kasutajate sünkroniseerimine lõpetatud!'; +$_MODULE['<{smailyforprestashop}prestashop>smailycustomercron_6fc744259b2bb6c969c9ce02ff2bbbed'] = 'Kasutajate sünkroniseerimine ei ole aktiivne!'; +$_MODULE['<{smailyforprestashop}prestashop>smailycustomercron_b55a2b2d84680417f12898a11647a1cb'] = 'Vale kasutajatunnus või parool!'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_05118375527d94e35408da46efdce0e5'] = 'Smaily Mooduli Sätted'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_b689be7d5235c3ec45ec989d993c5355'] = 'Aktiveeri kasutajate sünkroniseerimine'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_93cba07454f06a4a960172bbd6e2a435'] = 'Jah'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_bafd7322c6e97d25b6299b5d6fe8920b'] = 'Ei'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_0db377921f4ce762c62526131097968f'] = 'Üldsätted'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_835f4314be00eb6e8637b68248251826'] = 'Kasutajate Sünkroniseerimine'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_7b02e2dc3e9cead891aa9c8f2421cf5a'] = 'Unustatud Ostukorv'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_beed05bccb8b6f21466910eb4a4f142b'] = 'Alamdomeen'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_e253c20d41b297237f90aa77a1ee1ae9'] = 'Näiteks demo - https://demo.sendsmaily.net/'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_f6039d44b29456b20f8f373155ae4973'] = 'Kasutajatunnus'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_dc647eb65e6711e155375218212b3964'] = 'Salasõna'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_d40b78b04f3f55d880966542e877bb50'] = 'Kuidas luua API kasutajatunnuseid?'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_656a6828d7ef1bb791e42087c4b5ee6e'] = 'API võti'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_3211a79776a5ac5c6db6cba697a25250'] = 'Et kasutada Smaily liitusmisvormi sisesta API võti'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_02fc733815720ddfef75bd9c81c79f5e'] = 'Kontrolli andmeid'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_fe760630d69004060a872c86c116d120'] = 'RSS-voog'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_e046e1a272245a642b1a3ee0b7b45e1d'] = 'Kopeeri see URL oma kirjapõhja väljale'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_ad3d06d03d94223fa652babc913de686'] = 'Kontrolli'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_872bc575218e7dd2c749633da28c24ab'] = 'Automaatvastaja'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_3c6afc2203f77fb15d7b584e12960540'] = 'Vali Automaatvastaja'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_99770d280600b3c7ecc14faec49165ed'] = '(valitud)'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_1063e38cb53d94d386f21227fcd84717'] = 'Eemalda'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_a69d72ba4abe9915e183bcd00d8fcc42'] = 'Aktiveeri Kasutajate Sünkroniseerimine'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_93cba07454f06a4a960172bbd6e2a435'] = 'Jah'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_bafd7322c6e97d25b6299b5d6fe8920b'] = 'Ei'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_c453535704cee5f76534f9feee2ad0d0'] = 'Lisa väljad sünkroniseerimiseks'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_04176f095283bc729f1e3926967e7034'] = 'Eesnimi'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_dff4bf10409100d989495c6d5486035e'] = 'Perekonnanimi'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_aac772216aecbeca0e86d06671fe985a'] = 'Sünnipäev'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_15bbb9d0bbf25e8d2978de1168c749dc'] = 'Veebileht'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_700712b0f6c113d523b2194a96a2b278'] = 'Vali lisa väljad, mida sünkroniseerida'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_fe760630d69004060a872c86c116d120'] = 'RSS-voog'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_e046e1a272245a642b1a3ee0b7b45e1d'] = 'Kopeeri see URL oma kirjapõhja väljale'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_d0970ede0a15189ccf60baf5761f665f'] = 'Cron sümbol'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_75b770f1f8c1fa8044b69e1fe59d5c61'] = 'Kui jätad välja tühjaks, siis saab Cron-i käivitada külastades Croni URL-i'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_d0970ede0a15189ccf60baf5761f665f'] = 'Cron identifikaator'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_bb7b3c6261b41de1bd1fefa377a75f43'] = 'Identifikaator on vajalik turvalisuse tagamiseks. Kasuta automaatselt loodud identifikaatorit või asenda enda valitud väärtusega. '; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_5588ea18ef47155105d7d11abcb7e4e1'] = 'Croni URL'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_58cd8c6380451ce17a7f2ee70294957f'] = 'Et aktiveerida automaatne kontaktide sünkroniseerimine seadistage Cron oma teenusepakkuja juures ning asendage antud URL-s vastav sümbol.'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_c9cc8cce247e49bae79f15173ce97354'] = 'Salvesta'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_0839d54929a9ddf2b6e72c622492cd69'] = 'Smaily Unustaud Ostukorvi Seaded'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_a27d20b558af715c91592bcee1019dee'] = 'Aktiveeri Unustaud Ostukorvi Meeldetuletus'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_361a2e0648660de5428f5dc6c8ea4e51'] = 'Unustatud Ostukorvi Viivitus'; -$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_a318664b7d6335b9d854381a9f48555d'] = 'Tund(i)'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_872bc575218e7dd2c749633da28c24ab'] = 'Automaatvastaja'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_3c6afc2203f77fb15d7b584e12960540'] = 'Vali Automaatvastaja'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_99770d280600b3c7ecc14faec49165ed'] = '(valitud)'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_b9aefa40a54680bb258f9f9569290fae'] = 'Toote Nimi'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_b5a7adde1af5c87d7fd797b6245c2a39'] = 'Kirjeldus'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_3601146c4e948c32b6424d2c0a7f0118'] = 'Hind'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_3adbdb3ac060038aa0e6e6c138ef9873'] = 'Kategooria'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_694e8d1f2ee056f98ee488bdc4982d73'] = 'Kogus'; $_MODULE['<{smailyforprestashop}prestashop>smaily_configure_4b3a8183e47ffda5b44eac6fb9b7c94c'] = 'Vali täiendavad väljad, mida soovid lisada unustaud ostukorvi kirjale. Ees- ja perekonnanime ning poe-url väljad on alati lisatud.'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_361a2e0648660de5428f5dc6c8ea4e51'] = 'Unustatud Ostukorvi Viivitus'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_f670ea66cfb0e90bd6090472ad692694'] = 'Minutit'; +$_MODULE['<{smailyforprestashop}prestashop>smaily_configure_e553d7a992213a4c4421d425404d5b61'] = 'Aeg pärast mida loetakse ostukorv hüljatuks kui klient on lisanud viimase toote. Miinimum väärtus 15 minutit.'; $_MODULE['<{smailyforprestashop}prestashop>smaily_blocknewsletter_3805f49499fa5010c394e219aa1fe7a0'] = 'Liitu meie uudiskirjaga ja saa infot sooduspakkumistest'; $_MODULE['<{smailyforprestashop}prestashop>smaily_blocknewsletter_198584454b0ce1101ff5b50323325aa8'] = 'Teie emaili aadress'; $_MODULE['<{smailyforprestashop}prestashop>smaily_blocknewsletter_c3d67cba349c7ecb5465ae92bdb38970'] = 'Te võite igal ajal oma uudiskirja tellimuse tühistada.'; diff --git a/views/js/smaily_module.js b/views/js/smaily_module.js index 4f2292d..c1c7f1a 100644 --- a/views/js/smaily_module.js +++ b/views/js/smaily_module.js @@ -22,18 +22,20 @@ * @license GPL3 */ $(document).ready(function() { - // Stop user from submitting form with enter key to make api validation mandatory - $("#smaily_configuration_form").bind("keypress", function(e) { - if (e.keyCode == 13) { - return false; - } + // Hide spinner. + $("#smaily-spinner").hide(); + // Active tab handler + $("#myTab a").click(function(e) { + e.preventDefault(); + $(this).tab("show"); }); - // Handles validation of autoresponder details and - // displays second part of settings form based of response from smaily autoresponder API - $("#smaily-validate-autoresponder").on("click", function() { + // Handles validation of credentials. + $("#smaily-validate-credentials").on("click", function() { var subdomain = $("#SMAILY_SUBDOMAIN").val(); var username = $("#SMAILY_USERNAME").val(); var password = $("#SMAILY_PASSWORD").val(); + // Show spinner. + $("#smaily-spinner").show(); $.ajax({ type: "POST", dataType: "json", @@ -48,100 +50,140 @@ $(document).ready(function() { password: password }, success: function success(result) { + // Hide spinner. + $("#smaily-spinner").hide(); //Display error messages above form. if (result["error"]) { - var errorMessage = - '' + - result["error"]; - $("#smaily_errormessages").html(errorMessage); - $("#smaily_errormessages").show(); + displayMessage(result["error"], true); } //Sucess message. if (result["success"] === true) { - // Hide error messages. - $("#smaily_errormessages").hide(); + // Display success message. + displayMessage(smailymessages.credentials_validated); // Hide validate section $("#smaily-validate-form-group").hide(); - // Append received autoresponders to Select Autoresponder options. - $.each(result["autoresponders"], function(index, item) { - $("#SMAILY_AUTORESPONDER").append( - $("