public function postProcess()
 {
     if (Tools::isSubmit('submitSmsTest')) {
         $number = (string) Tools::getValue('campaign_last_tester');
         if (empty($number) || !Validate::isPhoneNumber($number)) {
             $this->errors[] = $this->module->l('Invalid gsm number !', 'adminmarketingsstep6');
             return false;
         }
         $prefixe = EMTools::getShopPrefixeCountry();
         $number = EMTools::cleanNumber($number, $prefixe);
         if ($number[0] != '0' && $number[0] != '+') {
             $this->errors[] = $this->module->l('Invalid gsm number !', 'adminmarketingsstep6');
             return false;
         }
         $response_array = array();
         $parameters = array('campaign_id' => $this->campaign_api_message_id, 'recipient' => $number, 'text' => $this->module->l('[TEST]', 'adminmarketingsstep6') . ' ' . $this->campaign_sms_text);
         if ($this->session_api->call('sms', 'campaign', 'send_test', $parameters, $response_array)) {
             // We store the last fax number
             // ----------------------------
             Db::getInstance()->update('expressmailing_sms', array('campaign_last_tester' => pSQL($number)), 'campaign_id = ' . $this->campaign_id);
             $this->confirmations[] = sprintf($this->module->l('Please wait, your sms is processing to %s ...', 'adminmarketingsstep6'), $number);
             return true;
         }
         $this->errors[] = sprintf($this->module->l('Error while sending sms to the API : %s', 'adminmarketingsstep6'), $this->session_api->getError());
         return false;
     }
 }
 private function getFieldsValues()
 {
     $sql = new DbQuery();
     $sql->select('*');
     $sql->from('expressmailing_sms');
     $sql->where('campaign_id = ' . $this->campaign_id);
     $result = Db::getInstance()->getRow($sql);
     $file_copy = $result['path_to_import'];
     $preview = array();
     $preview = EMTools::getCSVPreview($file_copy);
     $this->context->smarty->assign('preview', $preview);
     $this->context->smarty->assign('campaign_id', $this->campaign_id);
     $this->context->smarty->assign('next_page', 'AdminMarketingSStep2');
     $this->context->smarty->assign('prev_page', 'AdminMarketingSStep2');
     return true;
 }
 public function postProcess()
 {
     if (Tools::isSubmit('submitFaxTest')) {
         $number_or_email = (string) Tools::getValue('campaign_last_tester');
         if (empty($number_or_email)) {
             $this->errors[] = $this->module->l('Invalid fax number !', 'adminmarketingfstep7');
             return false;
         }
         if (Tools::strpos($number_or_email, '@')) {
             if (!Validate::isEmail($number_or_email)) {
                 $this->errors[] = $this->module->l('Invalid email address !', 'adminmarketingfstep7');
                 return false;
             }
         } else {
             $prefixe = EMTools::getShopPrefixeCountry();
             $number_or_email = EMTools::cleanNumber($number_or_email, $prefixe);
             if (!Validate::isPhoneNumber($number_or_email)) {
                 $this->errors[] = $this->module->l('Invalid fax number !', 'adminmarketingfstep7');
                 return false;
             }
             if ($number_or_email[0] != '0' && $number_or_email[0] != '+') {
                 $this->errors[] = $this->module->l('Invalid fax number !', 'adminmarketingfstep7');
                 return false;
             }
         }
         $response_array = array();
         $parameters = array('campaign_id' => $this->campaign_api_message_id, 'recipient' => $number_or_email);
         if ($this->session_api->call('fax', 'campaign', 'send_test', $parameters, $response_array)) {
             // We store the last fax number
             // ----------------------------
             Db::getInstance()->update('expressmailing_fax', array('campaign_last_tester' => pSQL($number_or_email)), 'campaign_id = ' . $this->campaign_id);
             $this->confirmations[] = sprintf($this->module->l('Please wait, your fax is processing to %s ...', 'adminmarketingfstep7'), $number_or_email);
             return true;
         }
         $this->errors[] = sprintf($this->module->l('Error while sending fax to the API : %s', 'adminmarketingfstep7'), $this->session_api->getError());
         return false;
     }
 }
 public function renderList()
 {
     $output = '';
     if ($this->session_api->connectFromCredentials('email')) {
         Tools::clearCache($this->context->smarty);
         $response_array = array();
         $parameters = array('account_id' => $this->session_api->account_id, 'max_lines' => 20, 'campaign_id' => (int) Tools::getValue('campaign_id'));
         if ($this->session_api->call('email', 'campaign', 'enum_last_sent', $parameters, $response_array)) {
             if (is_array($response_array) && count($response_array)) {
                 // On retrouve tous les jours d'envoi (envois fractionnés sur plusieurs jours)
                 // ---------------------------------------------------------------------------
                 $tools = new EMTools();
                 $days = array();
                 foreach ($response_array as $day) {
                     $days[] = array('day_api' => $day['stat_date'], 'day_lang' => $tools->getLocalizableDate($day['stat_date']));
                 }
                 $this->context->smarty->assign(array('days' => $days, 'current_index' => AdminController::$currentIndex . '&campaign_id=' . $response_array[0]['campaign_id'], 'campaign_id' => $response_array[0]['campaign_id'], 'campaign_name' => Tools::htmlentitiesDecodeUTF8($response_array[0]['name'])));
                 // S'il y a un stat_date, il faut ré-intéroger l'API pour obtenir les stats du jour sélectionné
                 // --------------------------------------------------------------------------------------------
                 if (Tools::getValue('stat_date')) {
                     $stat_array = array();
                     $parameters = array('account_id' => $this->session_api->account_id, 'campaign_id' => (int) Tools::getValue('campaign_id'), 'stat_date' => (int) Tools::getValue('stat_date'));
                     if ($this->session_api->call('email', 'campaign', 'get_statistics', $parameters, $stat_array)) {
                         $response_array = array($stat_array);
                     }
                     // Pour rester compatible avec le code ci-dessous
                 }
                 // S'il n'y a pas de stat_date, l'API nous retourne directement les stats du dernier envoi
                 // ---------------------------------------------------------------------------------------
                 $this->context->smarty->assign(array('select_day' => $response_array[0]['stat_date'], 'sent' => $response_array[0]['sent'], 'not_sent' => $response_array[0]['not_sent'], 'delivered' => $response_array[0]['delivered'], 'not_delivered' => $response_array[0]['not_delivered'], 'opened' => $response_array[0]['opened'], 'not_opened' => $response_array[0]['not_opened'], 'unique_clickers' => $response_array[0]['unique_clickers'], 'all_clicks' => $response_array[0]['all_clicks'], 'unsubscribes' => $response_array[0]['unsubscribes'], 'abuses' => $response_array[0]['abuses'], 'ratio_sent' => $response_array[0]['ratio_sent'], 'ratio_not_sent' => $response_array[0]['ratio_not_sent'], 'ratio_delivered' => $response_array[0]['ratio_delivered'], 'ratio_not_delivered' => $response_array[0]['ratio_not_delivered'], 'ratio_opened' => $response_array[0]['ratio_opened'], 'ratio_not_opened' => $response_array[0]['ratio_not_opened'], 'ratio_unique_clickers' => $response_array[0]['ratio_unique_clickers'], 'ratio_unsubscribes' => $response_array[0]['ratio_unsubscribes'], 'ratio_abuses' => $response_array[0]['ratio_abuses']));
                 // On affiche le tableau des stats
                 // -------------------------------
                 $diplay = $this->getTemplatePath() . 'marketinge_stats/marketinge_stats.tpl';
                 $output = $this->context->smarty->fetch($diplay);
                 // On charge les données du graphique des "opened"
                 // -----------------------------------------------
                 $delivered = array();
                 /* ne pas utiliser le nom response_array SVP */
                 $parameters = array('account_id' => $this->session_api->account_id, 'campaign_id' => $response_array[0]['campaign_id'], 'stat_date' => $response_array[0]['stat_date']);
                 $this->session_api->call('email', 'campaign', 'get_graph_delivered_per_hour', $parameters, $delivered);
                 $this->context->smarty->assign('delivered', $delivered);
                 $graph = $this->getTemplatePath() . 'marketinge_stats/marketinge_graph.tpl';
                 $output .= $this->context->smarty->fetch($graph);
             } else {
                 // On affiche une liste vide
                 // -------------------------
                 $helper = new HelperList();
                 $helper->no_link = true;
                 $helper->shopLinkType = '';
                 $helper->simple_header = false;
                 // Mettre 'search' => false dans chaque fields_list
                 $helper->table = $this->table;
                 $helper->identifier = 'campaign_id';
                 $helper->show_toolbar = true;
                 $helper->toolbar_scroll = false;
                 $helper->token = Tools::getAdminTokenLite('AdminMarketingEStats');
                 $helper->currentIndex = $this->context->link->getAdminLink('AdminMarketingEStats', false);
                 $helper->allow_export = false;
                 $helper->title = '<i class="icon-bar-chart"></i> ' . $this->module->l('Broadcast evolution during last 24/48 hours', 'adminmarketingestats');
                 $helper->toolbar_btn = array('back' => array('href' => 'index.php?controller=AdminMarketingEList&token=' . Tools::getAdminTokenLite('AdminMarketingEList'), 'desc' => $this->module->l('Back to list', 'adminmarketingestats')));
                 $helper->actions = array('details');
                 $this->fields_list = array();
                 $output .= $helper->generateList($this->fields_list, $this->fields_list);
             }
         }
     }
     $footer = $this->getTemplatePath() . 'footer.tpl';
     $output .= $this->context->smarty->fetch($footer);
     return $output;
 }
 private function importCSVFile()
 {
     $this->csv_file = isset($_FILES['csv_file']) ? $_FILES['csv_file'] : false;
     if (empty($this->csv_file['tmp_name'])) {
         $this->errors[] = Tools::displayError('No file has been specified.');
         return false;
     }
     if (!empty($this->csv_file) && !empty($this->csv_file['tmp_name'])) {
         if (!EMTools::importFileSelectColumn($_FILES['csv_file'], 'sms', $this->campaign_id, $this->module->name)) {
             $this->errors[] = Tools::displayError('Cannot read the .CSV file');
         }
     }
 }
    public function postProcess()
    {
        if (Tools::isSubmit('importCsvStep3')) {
            $this->csv_file = isset($_FILES['csv_file']) ? $_FILES['csv_file'] : false;
            if (empty($this->csv_file['tmp_name'])) {
                $this->errors[] = Tools::displayError('No file has been specified.');
            } else {
                if (!empty($this->csv_file) && !empty($this->csv_file['tmp_name'])) {
                    if (!EMTools::importFileSelectColumn($_FILES['csv_file'], 'fax', $this->campaign_id, $this->module->name)) {
                        $this->errors[] = Tools::displayError('Cannot read the .CSV file');
                    }
                }
            }
        }
        if (Tools::isSubmit('clearRecipients')) {
            if (Db::getInstance()->delete('expressmailing_fax_recipients', 'campaign_id = ' . $this->campaign_id)) {
                $this->confirmations[] = $this->module->l('Clear succeed !', 'adminmarketingfstep3');
            }
            return Db::getInstance()->update('expressmailing_fax', array('campaign_date_update' => date('Y-m-d H:i:s'), 'recipients_modified' => 1), 'campaign_id = ' . $this->campaign_id);
        }
        if (Tools::isSubmit('indexCol')) {
            $index_col = (int) Tools::getValue('indexCol');
            $prefix = EMTools::getShopPrefixeCountry();
            return EMTools::importFile($index_col, 'fax', $this->campaign_id, $prefix);
        }
        if (Tools::isSubmit('clearDuplicate')) {
            $request = 'DELETE source
				FROM `' . _DB_PREFIX_ . 'expressmailing_fax_recipients` AS source
				LEFT OUTER JOIN (
					SELECT MIN(id) as id, target
					FROM `' . _DB_PREFIX_ . 'expressmailing_fax_recipients`
					WHERE campaign_id = ' . $this->campaign_id . '
					GROUP BY target
				) AS duplicates
				ON source.id = duplicates.id
				WHERE duplicates.id IS NULL';
            if (Db::getInstance()->execute($request)) {
                $this->confirmations[] = $this->module->l('Clear succeed !', 'adminmarketingfstep3');
            }
            Db::getInstance()->update('expressmailing_fax', array('campaign_date_update' => date('Y-m-d H:i:s'), 'recipients_modified' => '1'), 'campaign_id = ' . $this->campaign_id);
            return;
        }
        if (Tools::isSubmit('submitFaxStep3')) {
            // Selection must contain recipients
            // ---------------------------------
            if (count($this->getRecipientsDB())) {
                Tools::redirectAdmin('index.php?controller=AdminMarketingFStep5&campaign_id=' . $this->campaign_id . '&token=' . Tools::getAdminTokenLite('AdminMarketingFStep5'));
                exit;
            } else {
                $this->errors[] = $this->module->l('Your recipients selection is empty !', 'adminmarketingfstep3');
                return false;
            }
        }
    }
 /**
  * Copy a remote or local file to the local campaign storage
  * @param string $url
  * @param string $filename The name of the resulting file
  * @return mixed Null if fail or a string containing the path of the resulting image.
  */
 private function copyFileToStorage($url, $filename = null)
 {
     $dest = $this->module->getPreviewFolder();
     $dest .= $this->campaign_id . DIRECTORY_SEPARATOR;
     if (!Tools::file_exists_no_cache($dest)) {
         mkdir($dest, 0777, true);
         Tools::copy(_PS_MODULE_DIR_ . 'expressmailing/index.php', $dest . 'index.php');
     }
     if ($filename) {
         $dest .= (string) $filename;
     } else {
         $dest .= basename((string) $url);
     }
     $dest = urldecode($dest);
     $dest = str_replace(' ', '_', $dest);
     $dest = EMTools::removeAccents($dest);
     if (($pos = strpos($dest, '?')) !== false) {
         $dest = Tools::substr($dest, 0, $pos);
     }
     if (function_exists('curl_version')) {
         $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Mozilla/5.0';
         $ch = curl_init((string) $url);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
         curl_setopt($ch, CURLOPT_CRLF, 1);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         $raw = curl_exec($ch);
         curl_close($ch);
         if (file_exists($dest)) {
             unlink($dest);
         }
         $fp = fopen($dest, 'x');
         fwrite($fp, $raw);
         fclose($fp);
         if (file_exists($dest)) {
             return $dest;
         }
     } else {
         if (Tools::copy((string) $url, $dest)) {
             return $dest;
         }
     }
     return null;
 }
 public function postProcess()
 {
     // On construit un login pour le compte
     // ------------------------------------
     // Si PS_SHOP_EMAIL = info@axalone.com
     // Alors login      = ps-info-axalone
     //   1/ On ajoute 'ps-' devant l'email
     //   2/ On retire l'extention .com à la fin
     //   3/ On remplace toutes les lettres accentuées par leurs équivalents sans accent
     //   4/ On remplace tous les sigles par des tirets
     //   5/ Enfin on remplace les doubles/triples tirets par des simples
     // --------------------------------------------------------------------------------
     $company_login = '******' . Configuration::get('PS_SHOP_EMAIL');
     $company_login = Tools::substr($company_login, 0, strrpos($company_login, '.'));
     $company_login = EMTools::removeAccents($company_login);
     $company_login = Tools::strtolower($company_login);
     $company_login = preg_replace('/[^a-z0-9-]/', '-', $company_login);
     $company_login = preg_replace('/-{2,}/', '-', $company_login);
     $cart_product = (string) Tools::getValue('product', '');
     // Initialisation de l'API
     // -----------------------
     if (Tools::isSubmit('submitInscription')) {
         // On prépare l'ouverture du compte
         // --------------------------------
         $company_name = (string) Tools::getValue('company_name');
         $company_email = (string) Tools::getValue('company_email');
         $company_phone = (string) Tools::getValue('company_phone');
         $company_address1 = (string) Tools::getValue('company_address1');
         $company_address2 = (string) Tools::getValue('company_address2');
         $company_zipcode = (string) Tools::getValue('company_zipcode');
         $company_city = (string) Tools::getValue('company_city');
         $country_id = (int) Tools::getValue('country_id');
         $country = new Country($country_id);
         if (!is_object($country) || empty($country->id)) {
             $this->errors[] = Tools::displayError('Country is invalid');
         } else {
             $company_country = Country::getNameById($this->context->language->id, $country_id);
         }
         if (!Validate::isGenericName($company_name)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop name', 'AdminStores') . ' »');
         }
         if (!Validate::isEmail($company_email)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop email', 'AdminStores') . ' »');
         }
         if (!Validate::isPhoneNumber($company_phone)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Phone', 'AdminStores') . ' »');
         }
         if (!Validate::isAddress($company_address1)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop address line 1', 'AdminStores') . ' »');
         }
         if ($country->zip_code_format && !$country->checkZipCode($company_zipcode)) {
             $this->errors[] = Tools::displayError('Your Zip/postal code is incorrect.') . '<br />' . Tools::displayError('It must be entered as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
         } elseif (empty($company_zipcode) && $country->need_zip_code) {
             $this->errors[] = Tools::displayError('A Zip/postal code is required.');
         } elseif ($company_zipcode && !Validate::isPostCode($company_zipcode)) {
             $this->errors[] = Tools::displayError('The Zip/postal code is invalid.');
         }
         if (!Validate::isGenericName($company_city)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('City', 'AdminStores') . ' »');
         }
         // We save these informations in the database
         // ------------------------------------------
         Db::getInstance()->insert('expressmailing_order_address', array('id_address' => 1, 'company_name' => pSQL($company_name), 'company_email' => pSQL($company_email), 'company_address1' => pSQL($company_address1), 'company_address2' => pSQL($company_address2), 'company_zipcode' => pSQL($company_zipcode), 'company_city' => pSQL($company_city), 'country_id' => $country_id, 'company_country' => pSQL($company_country), 'company_phone' => pSQL($company_phone), 'product' => pSQL($cart_product)), false, false, Db::REPLACE);
         // If form contains 1 or more errors, we stop the process
         // ------------------------------------------------------
         if (is_array($this->errors) && count($this->errors)) {
             return false;
         }
         // Open a session on Express-Mailing API
         // -------------------------------------
         if ($this->session_api->openSession()) {
             // We create the account
             // ---------------------
             $response_array = array();
             $base_url = Configuration::get('PS_SSL_ENABLED') == 0 ? Tools::getShopDomain(true, true) : Tools::getShopDomainSsl(true, true);
             $module_dir = Tools::str_replace_once(_PS_ROOT_DIR_, '', _PS_MODULE_DIR_);
             $parameters = array('login' => $company_login, 'info_company' => $company_name, 'info_email' => $company_email, 'info_phone' => $company_phone, 'info_address' => $company_address1 . "\r\n" . $company_address2, 'info_country' => $company_country, 'info_zipcode' => $company_zipcode, 'info_city' => $company_city, 'info_phone' => $company_phone, 'info_contact_firstname' => $this->context->employee->firstname, 'info_contact_lastname' => $this->context->employee->lastname, 'email_report' => $this->context->employee->email, 'gift_code' => 'prestashop_' . Translate::getModuleTranslation('expressmailing', '3320', 'session_api'), 'INFO_WWW' => $base_url . $module_dir . $this->module->name . '/campaigns/index.php');
             if ($this->session_api->createAccount($parameters, $response_array)) {
                 // If the form include the buying process (field 'product')
                 // We initiate a new cart with the product selected
                 // --------------------------------------------------------
                 if ($cart_product) {
                     Tools::redirectAdmin('index.php?controller=AdminMarketingBuy&submitCheckout&campaign_id=' . $this->campaign_id . '&media=' . $this->next_controller . '&product=' . $cart_product . '&token=' . Tools::getAdminTokenLite('AdminMarketingBuy'));
                     exit;
                 }
                 // Else we back to the mailing process
                 // -----------------------------------
                 Tools::redirectAdmin($this->next_action);
                 exit;
             }
             if ($this->session_api->error == 11) {
                 // Account already existe, we print the rescue form (with password input)
                 // ----------------------------------------------------------------------
                 $response_array = array();
                 $parameters = array('login' => $company_login);
                 $this->session_api->resendPassword($parameters, $response_array);
                 $this->generateRescueForm();
                 return;
             } else {
                 // Other error
                 // -----------
                 $this->errors[] = sprintf($this->module->l('Unable to create an account : %s', 'adminmarketinginscription'), $this->session_api->getError());
                 return false;
             }
         } else {
             $this->errors[] = sprintf($this->module->l('Error during communication with Express-Mailing API : %s', 'adminmarketinginscription'), $this->session_api->getError());
             return false;
         }
     } elseif (Tools::isSubmit('submitRescue')) {
         // Rescue form : ask for existing password
         // ---------------------------------------
         if ($this->session_api->openSession()) {
             $response_array = array();
             $password = trim((string) Tools::getValue('api_password'));
             $parameters = array('login' => $company_login, 'password' => $password);
             if ($this->session_api->connectUser($parameters, $response_array)) {
                 Db::getInstance()->insert('expressmailing', array('api_login' => pSQL($company_login), 'api_password' => pSQL($password)), false, false, Db::REPLACE);
                 // If the form include the buying process (field 'product')
                 // We initiate a new cart with the product selected
                 // --------------------------------------------------------
                 if ($cart_product) {
                     Tools::redirectAdmin('index.php?controller=AdminMarketingBuy&submitCheckout&campaign_id=' . $this->campaign_id . '&media=' . $this->next_controller . '&product=' . $cart_product . '&token=' . Tools::getAdminTokenLite('AdminMarketingBuy'));
                     exit;
                 }
                 // Else we back to the mailing process
                 // -----------------------------------
                 Tools::redirectAdmin($this->next_action);
                 exit;
             }
         }
         $this->errors[] = sprintf($this->module->l('Error during communication with Express-Mailing API : %s', 'adminmarketinginscription'), $this->session_api->getError());
         return false;
     }
 }
示例#9
0
 public static function importFile($idx_col, $media, $campaign_id, $call_prefix)
 {
     switch ((string) $media) {
         case 'sms':
             break;
         case 'fax':
             break;
         default:
             Tools::redirectAdmin('index.php?controller=AdminMarketingX&token=' . Tools::getAdminTokenLite('AdminMarketingX'));
             exit;
     }
     $sql = new DbQuery();
     $sql->select('*');
     $sql->from('expressmailing_' . pSQL($media));
     $sql->where('campaign_id = ' . (int) $campaign_id);
     $result = Db::getInstance()->getRow($sql);
     $file_path = $result['path_to_import'];
     if (file_exists($file_path)) {
         $code_iso_country = $call_prefix;
         $request = EMTools::getCSVInsertRequest($file_path, $campaign_id, _DB_PREFIX_ . 'expressmailing_' . $media . '_recipients', (int) $idx_col, $code_iso_country);
         return Db::getInstance()->execute($request) && Db::getInstance()->update('expressmailing_' . pSQL($media), array('campaign_date_update' => date('Y-m-d H:i:s'), 'recipients_modified' => '1', 'path_to_import' => null), 'campaign_id = ' . (int) $campaign_id);
     }
     return false;
 }