public function postProcess()
 {
     if (isset($_GET['delete' . $this->table]) || Tools::getValue('submitDel' . $this->table)) {
         $this->_errors[] = Tools::displayError('You cannot delete a country. If you do not want it available for customers, please disable it.');
     } elseif (Tools::getValue('submitAdd' . $this->table)) {
         if (!Tools::getValue('id_' . $this->table)) {
             if (Validate::isLanguageIsoCode(Tools::getValue('iso_code')) && Country::getByIso(Tools::getValue('iso_code'))) {
                 $this->_errors[] = Tools::displayError('This ISO code already exists, you cannot create two country with the same ISO code');
             }
         } else {
             if (Validate::isLanguageIsoCode(Tools::getValue('iso_code'))) {
                 $id_country = Country::getByIso(Tools::getValue('iso_code'));
                 if (!is_null($id_country) && $id_country != Tools::getValue('id_' . $this->table)) {
                     $this->_errors[] = Tools::displayError('This ISO code already exists, you cannot create two country with the same ISO code');
                 }
             }
         }
         if (Tools::isSubmit('standardization')) {
             Configuration::updateValue('PS_TAASC', (bool) Tools::getValue('standardization', false));
         }
         if (isset($this->_errors) && count($this->_errors)) {
             return false;
         }
     }
     return parent::postProcess();
 }
 /**
  * @param $address
  * @param $customer
  * @return int
  * @throws ShopgateLibraryException
  */
 public function createAddress(ShopgateAddress $address, $customer)
 {
     /** @var AddressCore | Address $addressModel */
     $addressItem = new Address();
     $addressItem->id_customer = $customer->id;
     $addressItem->lastname = $address->getLastName();
     $addressItem->firstname = $address->getFirstName();
     if ($address->getCompany()) {
         $addressItem->company = $address->getCompany();
     }
     $addressItem->address1 = $address->getStreet1();
     if ($address->getStreet2()) {
         $addressItem->address2 = $address->getStreet2();
     }
     $addressItem->city = $address->getCity();
     $addressItem->postcode = $address->getZipcode();
     if (!Validate::isLanguageIsoCode($address->getCountry())) {
         $customer->delete();
         throw new ShopgateLibraryException(ShopgateLibraryException::REGISTER_FAILED_TO_ADD_USER, 'invalid country code: ' . $address->getCountry(), true);
     }
     $addressItem->id_country = Country::getByIso($address->getCountry());
     /**
      * prepare states
      */
     $stateParts = explode('-', $address->getState());
     if (count($stateParts) == 2) {
         $address->setState($stateParts[1]);
     }
     if ($address->getState() && !Validate::isStateIsoCode($address->getState())) {
         $customer->delete();
         throw new ShopgateLibraryException(ShopgateLibraryException::REGISTER_FAILED_TO_ADD_USER, 'invalid state code: ' . $address->getState(), true);
     } else {
         $addressItem->id_state = State::getIdByIso($address->getState());
     }
     $addressItem->alias = $address->getIsDeliveryAddress() ? $this->getModule()->l('Default delivery address') : $this->getModule()->l('Default');
     $addressItem->alias = $address->getIsInvoiceAddress() ? $this->getModule()->l('Default invoice address') : $this->getModule()->l('Default');
     $addressItem->phone = $address->getPhone();
     $addressItem->phone_mobile = $address->getMobile();
     $shopgateCustomFieldsHelper = new ShopgateCustomFieldsHelper();
     $shopgateCustomFieldsHelper->saveCustomFields($addressItem, $address->getCustomFields());
     $validateMessage = $addressItem->validateFields(false, true);
     if ($validateMessage !== true) {
         $customer->delete();
         throw new ShopgateLibraryException(ShopgateLibraryException::REGISTER_FAILED_TO_ADD_USER, $validateMessage, true);
     }
     $addressItem->save();
     return $addressItem->id;
 }
 public function ajaxProcessCheckLangPack()
 {
     $this->json = true;
     if (!Tools::getValue('iso_lang') || !Validate::isLanguageIsoCode(Tools::getValue('iso_lang'))) {
         $this->status = 'error';
         $this->errors[] = $this->l('Iso code is not valid');
         return;
     }
     if (!Tools::getValue('ps_version') || !Validate::isPrestaShopVersion(Tools::getValue('ps_version'))) {
         $this->status = 'error';
         $this->errors[] = $this->l('Technical Error: ps_version is not valid');
         return;
     }
     // Get all iso code available
     if ($lang_packs = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . Tools::getValue('ps_version') . '&iso_lang=' . Tools::strtolower(Tools::getValue('iso_lang')))) {
         $result = Tools::jsonDecode($lang_packs);
         if ($lang_packs !== '' && $result && !isset($result->error)) {
             $this->status = 'ok';
             $this->content = $lang_packs;
         } else {
             $this->status = 'error';
             $this->errors[] = $this->l('Wrong ISO code, or the selected language pack is unavailable.');
         }
     } else {
         $this->status = 'error';
         $this->errors[] = $this->l('Technical Error: translation server unreachable.');
     }
 }
 public function postProcess()
 {
     if (!Tools::getValue('id_' . $this->table)) {
         if (Validate::isLanguageIsoCode(Tools::getValue('iso_code')) && Country::getByIso(Tools::getValue('iso_code'))) {
             $this->errors[] = Tools::displayError('This ISO code already exists.You cannot create two countries with the same ISO code.');
         }
     } else {
         if (Validate::isLanguageIsoCode(Tools::getValue('iso_code'))) {
             $id_country = Country::getByIso(Tools::getValue('iso_code'));
             if (!is_null($id_country) && $id_country != Tools::getValue('id_' . $this->table)) {
                 $this->errors[] = Tools::displayError('This ISO code already exists.You cannot create two countries with the same ISO code.');
             }
         }
     }
     return parent::postProcess();
 }
Example #5
0
/* Theme is missing or maintenance */
if (!is_dir(dirname(__FILE__) . '/themes/' . _THEME_NAME_)) {
    die(Tools::displayError('Current theme unavailable. Please check your theme directory name and permissions.'));
} elseif (basename($_SERVER['PHP_SELF']) != 'disabled.php' and !intval(Configuration::get('PS_SHOP_ENABLE'))) {
    $maintenance = true;
}
ob_start();
global $cart, $cookie, $_CONF, $link;
/* get page name to display it in body id */
$pathinfo = pathinfo(__FILE__);
$page_name = basename($_SERVER['PHP_SELF'], '.' . $pathinfo['extension']);
$page_name = preg_match('/^[0-9]/', $page_name) ? 'page_' . $page_name : $page_name;
// Init Cookie
$cookie = new Cookie('ps');
// Switch language if needed and init cookie language
if ($iso = Tools::getValue('isolang') and Validate::isLanguageIsoCode($iso) and $id_lang = intval(Language::getIdByIso($iso))) {
    $_GET['id_lang'] = $id_lang;
}
Tools::switchLanguage();
Tools::setCookieLanguage();
/* attribute id_lang is often needed, so we create a constant for performance reasons */
define('_USER_ID_LANG_', intval($cookie->id_lang));
if (isset($_GET['logout']) or $cookie->logged and Customer::isBanned(intval($cookie->id_customer))) {
    $cookie->logout();
    Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL);
} elseif (isset($_GET['mylogout'])) {
    $cookie->mylogout();
    Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL);
}
$iso = strtolower(Language::getIsoById($cookie->id_lang ? intval($cookie->id_lang) : 1));
@(include _PS_TRANSLATIONS_DIR_ . $iso . '/fields.php');
Example #6
0
 /**
  * Set cookie id_lang
  */
 public static function switchLanguage(Context $context = null)
 {
     if (!$context) {
         $context = Context::getContext();
     }
     // Install call the dispatcher and so the switchLanguage
     // Stop this method by checking the cookie
     if (!isset($context->cookie)) {
         return;
     }
     if (($iso = Tools::getValue('isolang')) && Validate::isLanguageIsoCode($iso) && ($id_lang = (int) Language::getIdByIso($iso))) {
         $_GET['id_lang'] = $id_lang;
     }
     // update language only if new id is different from old id
     // or if default language changed
     $cookie_id_lang = $context->cookie->id_lang;
     $configuration_id_lang = Configuration::get('PS_LANG_DEFAULT');
     if (($id_lang = (int) Tools::getValue('id_lang')) && Validate::isUnsignedId($id_lang) && $cookie_id_lang != (int) $id_lang || $id_lang == $configuration_id_lang && Validate::isUnsignedId($id_lang) && $id_lang != $cookie_id_lang) {
         $context->cookie->id_lang = $id_lang;
         $language = new Language($id_lang);
         if (Validate::isLoadedObject($language) && $language->active) {
             $context->language = $language;
         }
         $params = $_GET;
         if (Configuration::get('PS_REWRITING_SETTINGS') || !Language::isMultiLanguageActivated()) {
             unset($params['id_lang']);
         }
     }
 }
Example #7
0
 public static function getCountry($address = null)
 {
     if ($id_country = Tools::getValue('id_country')) {
     } elseif (isset($address) && isset($address->id_country) && $address->id_country) {
         $id_country = $address->id_country;
     } elseif (Configuration::get('PS_DETECT_COUNTRY') && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         preg_match('#(?<=-)\\w\\w|\\w\\w(?!-)#', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $array);
         if (is_array($array) && isset($array[0]) && Validate::isLanguageIsoCode($array[0])) {
             $id_country = Country::getByIso($array[0], true);
         }
     }
     if (!isset($id_country) || !$id_country) {
         $id_country = Configuration::get('PS_COUNTRY_DEFAULT');
     }
     return (int) $id_country;
 }
 public function postProcess()
 {
     global $currentIndex;
     /* PrestaShop demo mode */
     if (_PS_MODE_DEMO_) {
         $this->_errors[] = Tools::displayError('This functionnality has been disabled.');
         return;
     }
     /* PrestaShop demo mode*/
     if (Tools::isSubmit('submitCopyLang')) {
         if ($this->tabAccess['add'] === '1') {
             $this->submitCopyLang();
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to add here.');
         }
     } elseif (Tools::isSubmit('submitExport')) {
         if ($this->tabAccess['add'] === '1') {
             $this->submitExportLang();
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to add here.');
         }
     } elseif (Tools::isSubmit('submitImport')) {
         if ($this->tabAccess['add'] === '1') {
             $this->submitImportLang();
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to add here.');
         }
     } elseif (Tools::isSubmit('submitAddLanguage')) {
         if ($this->tabAccess['add'] === '1') {
             $this->submitAddLang();
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to add here.');
         }
     } elseif (Tools::isSubmit('submitTranslationsFront')) {
         if ($this->tabAccess['edit'] === '1') {
             if (!Validate::isLanguageIsoCode(Tools::strtolower(Tools::getValue('lang')))) {
                 die(Tools::displayError());
             }
             $this->writeTranslationFile('Front', _PS_THEME_DIR_ . 'lang/' . Tools::strtolower(Tools::getValue('lang')) . '.php');
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
         }
     } elseif (Tools::isSubmit('submitTranslationsPDF')) {
         if ($this->tabAccess['edit'] === '1') {
             if (!Validate::isLanguageIsoCode(Tools::strtolower(Tools::getValue('lang')))) {
                 die(Tools::displayError());
             }
             $this->writeTranslationFile('PDF', _PS_TRANSLATIONS_DIR_ . Tools::strtolower(Tools::getValue('lang')) . '/pdf.php', 'PDF');
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
         }
     } elseif (Tools::isSubmit('submitTranslationsBack')) {
         if ($this->tabAccess['edit'] === '1') {
             if (!Validate::isLanguageIsoCode(Tools::strtolower(Tools::getValue('lang')))) {
                 die(Tools::displayError());
             }
             $this->writeTranslationFile('Back', _PS_TRANSLATIONS_DIR_ . Tools::strtolower(Tools::getValue('lang')) . '/admin.php', 'ADM');
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
         }
     } elseif (Tools::isSubmit('submitTranslationsErrors')) {
         if ($this->tabAccess['edit'] === '1') {
             if (!Validate::isLanguageIsoCode(Tools::strtolower(Tools::getValue('lang')))) {
                 die(Tools::displayError());
             }
             $this->writeTranslationFile('Errors', _PS_TRANSLATIONS_DIR_ . Tools::strtolower(Tools::getValue('lang')) . '/errors.php', false, 'ERRORS');
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
         }
     } elseif (Tools::isSubmit('submitTranslationsFields')) {
         if ($this->tabAccess['edit'] === '1') {
             if (!Validate::isLanguageIsoCode(Tools::strtolower(Tools::getValue('lang')))) {
                 die(Tools::displayError());
             }
             $this->writeTranslationFile('Fields', _PS_TRANSLATIONS_DIR_ . Tools::strtolower(Tools::getValue('lang')) . '/fields.php', false, 'FIELDS');
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
         }
     } elseif (Tools::isSubmit('submitTranslationsMails') || Tools::isSubmit('submitTranslationsMailsAndStay')) {
         if ($this->tabAccess['edit'] === '1' && ($id_lang = Language::getIdByIso(Tools::getValue('lang'))) > 0) {
             $this->submitTranslationsMails($id_lang);
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
         }
     } elseif (Tools::isSubmit('submitTranslationsModules')) {
         if ($this->tabAccess['edit'] === '1') {
             $array_lang_src = Language::getLanguages(false);
             foreach ($array_lang_src as $language) {
                 $this->all_iso_lang[] = $language['iso_code'];
             }
             $lang = Tools::strtolower($_POST['lang']);
             if (!Validate::isLanguageIsoCode($lang)) {
                 die(Tools::displayError());
             }
             if (!($modules = scandir(_PS_MODULE_DIR_))) {
                 $this->displayWarning(Tools::displayError('There are no modules in your copy of PrestaShop. Use the Modules tab to activate them or go to our Website to download additional Modules.'));
             } else {
                 $arr_find_and_write = array();
                 $arr_files = $this->getAllModuleFiles($modules, _PS_MODULE_DIR_, $lang, true);
                 $arr_find_and_write = array_merge($arr_find_and_write, $arr_files);
                 if (file_exists(_PS_THEME_DIR_ . '/modules/')) {
                     $modules = scandir(_PS_THEME_DIR_ . '/modules/');
                     $arr_files = $this->getAllModuleFiles($modules, _PS_THEME_DIR_ . 'modules/', $lang);
                     $arr_find_and_write = array_merge($arr_find_and_write, $arr_files);
                 }
                 foreach ($arr_find_and_write as $key => $value) {
                     $this->findAndWriteTranslationsIntoFile($value['file_name'], $value['files'], $value['theme'], $value['module'], $value['dir']);
                 }
                 Tools::redirectAdmin($currentIndex . '&conf=4&token=' . $this->token);
             }
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
         }
     }
 }
 public function postProcess()
 {
     global $currentIndex, $cookie;
     if (isset($_GET['delete' . $this->table])) {
         if ($this->tabAccess['delete'] === '1') {
             if (Validate::isLoadedObject($object = $this->loadObject()) and isset($this->fieldImageSettings)) {
                 // English is needed by the system (ex. translations)
                 if ($object->id == Language::getIdByIso('en')) {
                     $this->_errors[] = $this->l('You cannot delete the English language as it is a system requirement, you can only deactivate it.');
                 }
                 if ($object->id == Configuration::get('PS_LANG_DEFAULT')) {
                     $this->_errors[] = $this->l('you cannot delete the default language');
                 } elseif ($object->id == $cookie->id_lang) {
                     $this->_errors[] = $this->l('You cannot delete the language currently in use. Please change languages before deleting.');
                 } elseif ($this->deleteNoPictureImages((int) Tools::getValue('id_lang')) and $object->delete()) {
                     Tools::redirectAdmin($currentIndex . '&conf=1' . '&token=' . $this->token);
                 }
             } else {
                 $this->_errors[] = Tools::displayError('An error occurred while deleting object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
             }
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to delete here.');
         }
     } elseif (Tools::getValue('submitDel' . $this->table) and isset($_POST[$this->table . 'Box'])) {
         if ($this->tabAccess['delete'] === '1') {
             if (in_array(Configuration::get('PS_LANG_DEFAULT'), $_POST[$this->table . 'Box'])) {
                 $this->_errors[] = $this->l('you cannot delete the default language');
             } elseif (in_array($cookie->id_lang, $_POST[$this->table . 'Box'])) {
                 $this->_errors[] = $this->l('you cannot delete the language currently in use, please change languages before deleting');
             } else {
                 foreach ($_POST[$this->table . 'Box'] as $language) {
                     $this->deleteNoPictureImages($language);
                 }
                 parent::postProcess();
             }
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to delete here.');
         }
     } elseif (Tools::isSubmit('submitAddlang')) {
         /* New language */
         if ((int) Tools::getValue('id_' . $this->table) == 0) {
             if ($this->tabAccess['add'] === '1') {
                 if (isset($_POST['iso_code']) and !empty($_POST['iso_code']) and Validate::isLanguageIsoCode(Tools::getValue('iso_code')) and Language::getIdByIso($_POST['iso_code'])) {
                     $this->_errors[] = Tools::displayError('This ISO code is already linked to another language.');
                 }
                 if ((!empty($_FILES['no-picture']['tmp_name']) or !empty($_FILES['flag']['tmp_name'])) and Validate::isLanguageIsoCode(Tools::getValue('iso_code'))) {
                     if ($_FILES['no-picture']['error'] == UPLOAD_ERR_OK) {
                         $this->copyNoPictureImage(strtolower(Tools::getValue('iso_code')));
                     }
                     // class AdminTab deal with every $_FILES content, don't do that for no-picture
                     unset($_FILES['no-picture']);
                     parent::postProcess();
                 } else {
                     $this->validateRules();
                     $this->_errors[] = Tools::displayError('Flag and No-Picture image fields are required.');
                 }
             } else {
                 $this->_errors[] = Tools::displayError('You do not have permission to add here.');
             }
         } else {
             if ($this->tabAccess['edit'] === '1') {
                 if ((isset($_FILES['no-picture']) and !$_FILES['no-picture']['error'] or isset($_FILES['flag']) and !$_FILES['flag']['error']) and Validate::isLanguageIsoCode(Tools::getValue('iso_code'))) {
                     if ($_FILES['no-picture']['error'] == UPLOAD_ERR_OK) {
                         $this->copyNoPictureImage(strtolower(Tools::getValue('iso_code')));
                     }
                     // class AdminTab deal with every $_FILES content, don't do that for no-picture
                     unset($_FILES['no-picture']);
                     parent::postProcess();
                 }
                 if (!Validate::isLoadedObject($object = $this->loadObject())) {
                     die(Tools::displayError());
                 }
                 if ((int) $object->id == (int) Configuration::get('PS_LANG_DEFAULT') and (int) $_POST['active'] != (int) $object->active) {
                     $this->_errors[] = Tools::displayError('You cannot change the status of the default language.');
                 } else {
                     parent::postProcess();
                 }
                 $this->validateRules();
             } else {
                 $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
             }
         }
     } elseif (isset($_GET['status']) and isset($_GET['id_lang'])) {
         if ($this->tabAccess['edit'] === '1') {
             if (!Validate::isLoadedObject($object = $this->loadObject())) {
                 die(Tools::displayError());
             }
             if ((int) $object->id == (int) Configuration::get('PS_LANG_DEFAULT')) {
                 $this->_errors[] = Tools::displayError('You cannot change the status of the default language.');
             } else {
                 return parent::postProcess();
             }
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
         }
     } elseif (Tools::isSubmit('submitOptions' . $this->table)) {
         $lang = new Language((int) Tools::getValue('PS_LANG_DEFAULT'));
         if (!$lang->active) {
             $this->_errors[] = Tools::displayError('You cannot set this language as default language because it\'s disabled');
         } else {
             return parent::postProcess();
         }
     } else {
         return parent::postProcess();
     }
 }
 /**
  * Get each informations for each mails founded in the folder $dir.
  *
  * @since 1.4.0.14
  * @param string $dir
  * @param string $group_name
  * @return array : list of mails
  */
 public function getMailFiles($dir, $group_name = 'mail')
 {
     $arr_return = array();
     if (Language::getIdByIso('en')) {
         $default_language = 'en';
     } else {
         $default_language = Language::getIsoById((int) Configuration::get('PS_LANG_DEFAULT'));
     }
     if (!$default_language || !Validate::isLanguageIsoCode($default_language)) {
         return false;
     }
     // Very usefull to name input and textarea fields
     $arr_return['group_name'] = $group_name;
     $arr_return['empty_values'] = 0;
     $arr_return['total_filled'] = 0;
     $arr_return['directory'] = $dir;
     // Get path for english mail directory
     $dir_en = str_replace('/' . $this->lang_selected->iso_code . '/', '/' . $default_language . '/', $dir);
     if (Tools::file_exists_cache($dir_en)) {
         // Get all english files to compare with the language to translate
         foreach (scandir($dir_en) as $email_file) {
             if (strripos($email_file, '.html') > 0 || strripos($email_file, '.txt') > 0) {
                 $email_name = substr($email_file, 0, strripos($email_file, '.'));
                 $type = substr($email_file, strripos($email_file, '.') + 1);
                 if (!isset($arr_return['files'][$email_name])) {
                     $arr_return['files'][$email_name] = array();
                 }
                 // $email_file is from scandir ($dir), so we already know that file exists
                 $arr_return['files'][$email_name][$type]['en'] = $this->getMailContent($dir_en, $email_file);
                 // check if the file exists in the language to translate
                 if (Tools::file_exists_cache($dir . '/' . $email_file)) {
                     $arr_return['files'][$email_name][$type][$this->lang_selected->iso_code] = $this->getMailContent($dir, $email_file);
                     $this->total_expression++;
                 } else {
                     $arr_return['files'][$email_name][$type][$this->lang_selected->iso_code] = '';
                 }
                 if ($arr_return['files'][$email_name][$type][$this->lang_selected->iso_code] == '') {
                     $arr_return['empty_values']++;
                 } else {
                     $arr_return['total_filled']++;
                 }
             }
         }
     } else {
         $this->warnings[] = sprintf(Tools::displayError('A mail directory exists for %1$s but not for English in %2$s'), $this->lang_selected->iso_code, str_replace(_PS_ROOT_DIR_, '', $dir));
     }
     return $arr_return;
 }
 public function process()
 {
     parent::process();
     /* Secure restriction for guest */
     if (self::$cookie->is_guest) {
         Tools::redirect('addresses.php');
     }
     if (Tools::isSubmit('id_country') and Tools::getValue('id_country') != NULL and is_numeric(Tools::getValue('id_country'))) {
         $selectedCountry = (int) Tools::getValue('id_country');
     } elseif (isset($this->_address) and isset($this->_address->id_country) and !empty($this->_address->id_country) and is_numeric($this->_address->id_country)) {
         $selectedCountry = (int) $this->_address->id_country;
     } elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $array = preg_split('/,|-/', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
         if (!Validate::isLanguageIsoCode($array[0]) or !($selectedCountry = Country::getByIso($array[0]))) {
             $selectedCountry = (int) Configuration::get('PS_COUNTRY_DEFAULT');
         }
     } else {
         $selectedCountry = (int) Configuration::get('PS_COUNTRY_DEFAULT');
     }
     $countries = Country::getCountries((int) self::$cookie->id_lang, true);
     $countriesList = '';
     foreach ($countries as $country) {
         $countriesList .= '<option value="' . (int) $country['id_country'] . '" ' . ($country['id_country'] == $selectedCountry ? 'selected="selected"' : '') . '>' . htmlentities($country['name'], ENT_COMPAT, 'UTF-8') . '</option>';
     }
     if ((Configuration::get('VATNUMBER_MANAGEMENT') and file_exists(_PS_MODULE_DIR_ . 'vatnumber/vatnumber.php')) && VatNumber::isApplicable(Configuration::get('PS_COUNTRY_DEFAULT'))) {
         self::$smarty->assign('vat_display', 2);
     } else {
         if (Configuration::get('VATNUMBER_MANAGEMENT')) {
             self::$smarty->assign('vat_display', 1);
         } else {
             self::$smarty->assign('vat_display', 0);
         }
     }
     self::$smarty->assign('ajaxurl', _MODULE_DIR_);
     self::$smarty->assign(array('countries_list' => $countriesList, 'countries' => $countries, 'errors' => $this->errors, 'token' => Tools::getToken(false), 'select_address' => (int) Tools::getValue('select_address')));
 }
Example #12
0
    /**
     * Get a country ID with its iso code
     *
     * @param string $iso_code Country iso code
     * @param bool $active return only active coutries
     * @return int Country ID
     */
    public static function getByIso($iso_code, $active = false)
    {
        if (!Validate::isLanguageIsoCode($iso_code)) {
            die(Tools::displayError());
        }
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
			SELECT `id_country`
			FROM `' . _DB_PREFIX_ . 'country`
			WHERE `iso_code` = \'' . pSQL(strtoupper($iso_code)) . '\'' . ($active ? ' AND active = 1' : ''));
        if (isset($result['id_country'])) {
            return (int) $result['id_country'];
        }
        return false;
    }
Example #13
0
 public function getContent()
 {
     include_once dirname(__FILE__) . '/backward_compatibility/backward.php';
     $output = '';
     $shopgateConfig = new ShopgateConfigPresta();
     $bools = array('true' => true, 'false' => false);
     if (Tools::isSubmit('saveConfigurations')) {
         $configs = Tools::getValue('configs', array());
         foreach ($configs as $name => $value) {
             if (isset($bools[$value])) {
                 $configs[$name] = $bools[$value];
             }
             $configs[$name] = htmlentities($configs[$name]);
         }
         $configs['use_stock'] = !(bool) Configuration::get('PS_ORDER_OUT_OF_STOCK');
         $settings = Tools::getValue('settings', array());
         foreach ($settings as $key => $value) {
             if (in_array($key, array('SHOPGATE_SHIPPING_SERVICE', 'SHOPGATE_MIN_QUANTITY_CHECK', 'SHOPGATE_MIN_QUANTITY_CHECK', 'SHOPGATE_OUT_OF_STOCK_CHECK', 'SHOPGATE_OUT_OF_STOCK_CHECK'))) {
                 Configuration::updateValue($key, htmlentities($value, ENT_QUOTES));
             }
         }
         $languageID = Configuration::get('PS_LANG_DEFAULT');
         if (Validate::isLanguageIsoCode($configs["language"])) {
             $languageID = Language::getIdByIso($configs["language"]);
         }
         Configuration::updateValue('SHOPGATE_LANGUAGE_ID', $languageID);
         try {
             $shopgateConfig->loadArray($configs);
             $shopgateConfig->saveFile(array_keys($configs));
             $output .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->l('Confirmation') . '" />' . $this->l('Configurations updated') . '</div>';
         } catch (ShopgateLibraryException $e) {
             $output .= '<div class="conf error"><img src="../img/admin/error.png" alt="' . $this->l('Error') . '" />' . $this->l('Error') . ': ' . $e->getAdditionalInformation() . '</div>';
         }
     }
     $langs = array();
     foreach (Language::getLanguages() as $id => $l) {
         $langs[strtoupper($l['iso_code'])] = $l['name'];
     }
     $servers = array('live' => $this->l('Live'), 'pg' => $this->l('Playground'), 'custom' => $this->l('Custom'));
     $enables = array();
     $settings = Configuration::getMultiple(array('SHOPGATE_SHIPPING_SERVICE', 'SHOPGATE_MIN_QUANTITY_CHECK', 'SHOPGATE_OUT_OF_STOCK_CHECK'));
     $shopgateConfig = new ShopgateConfigPresta();
     $configs = $shopgateConfig->toArray();
     $this->context->smarty->assign('settings', $settings);
     $this->context->smarty->assign('shipping_service_list', $this->shipping_service_list);
     $this->context->smarty->assign('langs', $langs);
     $this->context->smarty->assign('currencies', Currency::getCurrencies());
     $this->context->smarty->assign('servers', $servers);
     $this->context->smarty->assign('enables', $enables);
     $this->context->smarty->assign('configs', $configs);
     $this->context->smarty->assign('mod_dir', $this->_path);
     $this->context->smarty->assign('api_url', Tools::getHttpHost(true, true) . $this->_path . 'api.php');
     $this->context->smarty->assign('shopgate_offer_url', $this->_getOfferLink(Context::getContext()->language->language_code));
     return $output . $this->display(__FILE__, 'views/templates/admin/configurations.tpl');
 }
 public function init()
 {
     global $useSSL, $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files;
     if (self::$initialized) {
         return;
     }
     self::$initialized = true;
     // If current URL use SSL, set it true (used a lot for module redirect)
     if (Tools::usingSecureMode()) {
         $useSSL = $this->ssl = true;
     }
     $css_files = array();
     $js_files = array();
     if ($this->ssl && !Tools::usingSecureMode() && _PS_SSL_ENABLED_) {
         header('HTTP/1.1 301 Moved Permanently');
         header('Cache-Control: no-cache');
         header('Location: ' . Tools::getShopDomainSsl(true) . $_SERVER['REQUEST_URI']);
         exit;
     } elseif (_PS_SSL_ENABLED_ && Tools::usingSecureMode() && !$this->ssl) {
         header('HTTP/1.1 301 Moved Permanently');
         header('Cache-Control: no-cache');
         header('Location: ' . Tools::getShopDomain(true) . $_SERVER['REQUEST_URI']);
         exit;
     }
     ob_start();
     /* Loading default country */
     $defaultCountry = new Country((int) _PS_COUNTRY_DEFAULT_, (int) _PS_LANG_DEFAULT_);
     $cookie = new Cookie('ps', '', time() + ((int) Configuration::get('PS_COOKIE_LIFETIME_FO') > 0 ? (int) Configuration::get('PS_COOKIE_LIFETIME_FO') : 1) * 3600);
     $link = new Link();
     if ($this->auth && !$cookie->isLogged($this->guestAllowed)) {
         Tools::redirect('authentication.php' . ($this->authRedirection ? '?back=' . $this->authRedirection : ''));
     }
     /* Theme is missing or maintenance */
     if (!file_exists(_PS_THEME_DIR_)) {
         die(Tools::displayError('Current theme unavailable. Please check your theme directory name and permissions.'));
     } elseif (basename($_SERVER['PHP_SELF']) != 'disabled.php' && !(int) Configuration::get('PS_SHOP_ENABLE')) {
         $this->maintenance = true;
     } elseif (_PS_GEOLOCATION_ENABLED_) {
         $this->geolocationManagement();
     }
     // Switch language if needed and init cookie language
     $iso = Tools::getValue('isolang');
     if ($iso && Validate::isLanguageIsoCode($iso)) {
         $id_lang = (int) Language::getIdByIso($iso);
         if ($id_lang) {
             $_GET['id_lang'] = $id_lang;
         }
     }
     Tools::switchLanguage();
     Tools::setCookieLanguage();
     /* attribute id_lang is often needed, so we create a constant for performance reasons */
     if (!defined('_USER_ID_LANG_')) {
         define('_USER_ID_LANG_', (int) $cookie->id_lang);
     }
     if (isset($_GET['logout']) || $cookie->logged && Customer::isBanned((int) $cookie->id_customer)) {
         $cookie->logout();
         Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
     } elseif (isset($_GET['mylogout'])) {
         $cookie->mylogout();
         Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
     }
     global $currency;
     $currency = Tools::setCurrency();
     /* Cart already exists */
     if ((int) $cookie->id_cart) {
         $cart = new Cart((int) $cookie->id_cart);
         if ($cart->OrderExists()) {
             unset($cookie->id_cart, $cart, $cookie->checkedTOS);
         } elseif (_PS_GEOLOCATION_ENABLED_ && !in_array(strtoupper($cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) && $cart->nbProducts() && (int) Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') != -1 && !self::isInWhitelistForGeolocation()) {
             unset($cookie->id_cart, $cart);
         } elseif ($cookie->id_customer != $cart->id_customer || $cookie->id_lang != $cart->id_lang || $cookie->id_currency != $cart->id_currency) {
             if ($cookie->id_customer) {
                 $cart->id_customer = (int) $cookie->id_customer;
             }
             $cart->id_lang = (int) $cookie->id_lang;
             $cart->id_currency = (int) $cookie->id_currency;
             $cart->update();
         }
         /* Select an address if not set */
         if (isset($cart) && (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0 || !isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) && $cookie->id_customer) {
             $to_update = false;
             if (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0) {
                 $to_update = true;
                 $cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer);
             }
             if (!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) {
                 $to_update = true;
                 $cart->id_address_invoice = (int) Address::getFirstCustomerAddressId($cart->id_customer);
             }
             if ($to_update) {
                 $cart->update();
             }
         }
     }
     if (!isset($cart) || !$cart->id) {
         $cart = new Cart();
         $cart->id_lang = (int) $cookie->id_lang;
         $cart->id_currency = (int) $cookie->id_currency;
         $cart->id_guest = (int) $cookie->id_guest;
         if ($cookie->id_customer) {
             $cart->id_customer = (int) $cookie->id_customer;
             $cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer);
             $cart->id_address_invoice = $cart->id_address_delivery;
         } else {
             $cart->id_address_delivery = 0;
             $cart->id_address_invoice = 0;
         }
     }
     if (!$cart->nbProducts()) {
         $cart->id_carrier = null;
     }
     $locale = strtolower(Configuration::get('PS_LOCALE_LANGUAGE')) . '_' . strtoupper(Configuration::get('PS_LOCALE_COUNTRY') . '.UTF-8');
     setlocale(LC_COLLATE, $locale);
     setlocale(LC_CTYPE, $locale);
     setlocale(LC_TIME, $locale);
     setlocale(LC_NUMERIC, 'en_US.UTF-8');
     if (Validate::isLoadedObject($currency)) {
         $smarty->ps_currency = $currency;
     }
     if (Validate::isLoadedObject($ps_language = new Language((int) $cookie->id_lang))) {
         $smarty->ps_language = $ps_language;
     }
     /* get page name to display it in body id */
     $page_name = isset($this->php_self) ? preg_replace('/\\.php$/', '', $this->php_self) : '';
     if (preg_match('#^' . __PS_BASE_URI__ . '(|' . ((int) Configuration::get('PS_REWRITING_SETTINGS') && isset($smarty->ps_language) && !empty($smarty->ps_language) ? $smarty->ps_language->iso_code . '/' : '') . ')modules/([a-zA-Z0-9_-]+?)/(.*)$#', $_SERVER['REQUEST_URI'], $m)) {
         $page_name = 'module-' . $m[2] . '-' . str_replace(array('.php', '/'), array('', '-'), $m[3]);
     }
     $smarty->assign(Tools::getMetaTags($cookie->id_lang, $page_name));
     $protocol_link = _PS_SSL_ENABLED_ || Tools::usingSecureMode() ? 'https://' : 'http://';
     $useSSL = isset($this->ssl) && $this->ssl && _PS_SSL_ENABLED_ || Tools::usingSecureMode();
     $protocol_content = $useSSL ? 'https://' : 'http://';
     if (!defined('_PS_BASE_URL_')) {
         define('_PS_BASE_URL_', Tools::getShopDomain(true));
     }
     if (!defined('_PS_BASE_URL_SSL_')) {
         define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
     }
     $link->preloadPageLinks();
     $this->canonicalRedirection();
     Product::initPricesComputation();
     $display_tax_label = $defaultCountry->display_tax_label;
     if (Validate::isLoadedObject($cart) && ($tmp = (int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) {
         $infos = Address::getCountryAndState($tmp);
         $country = new Country((int) $infos['id_country']);
         if (Validate::isLoadedObject($country)) {
             $display_tax_label = $country->display_tax_label;
         }
     }
     $smarty->assign(array('request_uri' => Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])), 'navigationPipe' => Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>', 'link' => $link, 'cart' => $cart, 'currency' => $currency, 'cookie' => $cookie, 'page_name' => $page_name, 'base_dir' => _PS_BASE_URL_ . __PS_BASE_URI__, 'base_dir_ssl' => $protocol_link . Tools::getShopDomainSsl() . __PS_BASE_URI__, 'content_dir' => $protocol_content . Tools::getHttpHost() . __PS_BASE_URI__, 'tpl_dir' => _PS_THEME_DIR_, 'modules_dir' => _MODULE_DIR_, 'mail_dir' => _MAIL_DIR_, 'lang_iso' => $ps_language->iso_code, 'come_from' => Tools::getHttpHost(true, true) . Tools::htmlentitiesUTF8(str_replace('\'', '', urldecode($_SERVER['REQUEST_URI']))), 'cart_qties' => (int) $cart->nbProducts(), 'currencies' => Currency::getCurrencies(), 'languages' => Language::getLanguages(), 'priceDisplay' => Product::getTaxCalculationMethod(), 'add_prod_display' => (int) Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'roundMode' => (int) Configuration::get('PS_PRICE_ROUND_MODE'), 'use_taxes' => (int) Configuration::get('PS_TAX'), 'display_tax_label' => (bool) $display_tax_label, 'vat_management' => (int) Configuration::get('VATNUMBER_MANAGEMENT'), 'opc' => (bool) Configuration::get('PS_ORDER_PROCESS_TYPE'), 'PS_CATALOG_MODE' => (bool) Configuration::get('PS_CATALOG_MODE'), 'id_currency_cookie' => (int) $currency->id, 'logged' => $cookie->isLogged(), 'customerName' => $cookie->logged ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : false));
     // TODO for better performances (cache usage), remove these assign and use a smarty function to get the right media server in relation to the full ressource name
     $assignArray = array('img_ps_dir' => _PS_IMG_, 'img_cat_dir' => _THEME_CAT_DIR_, 'img_lang_dir' => _THEME_LANG_DIR_, 'img_prod_dir' => _THEME_PROD_DIR_, 'img_manu_dir' => _THEME_MANU_DIR_, 'img_sup_dir' => _THEME_SUP_DIR_, 'img_ship_dir' => _THEME_SHIP_DIR_, 'img_store_dir' => _THEME_STORE_DIR_, 'img_col_dir' => _THEME_COL_DIR_, 'img_dir' => _THEME_IMG_DIR_, 'css_dir' => _THEME_CSS_DIR_, 'js_dir' => _THEME_JS_DIR_, 'pic_dir' => _THEME_PROD_PIC_DIR_);
     foreach ($assignArray as $assignKey => $assignValue) {
         if (substr($assignValue, 0, 1) == '/' || $protocol_content == 'https://') {
             $smarty->assign($assignKey, $protocol_content . Tools::getMediaServer($assignValue) . $assignValue);
         } else {
             $smarty->assign($assignKey, $assignValue);
         }
     }
     // setting properties from global var
     self::$cookie = $cookie;
     self::$cart = $cart;
     self::$smarty = $smarty;
     self::$link = $link;
     if ($this->maintenance) {
         $this->displayMaintenancePage();
     }
     if ($this->restrictedCountry) {
         $this->displayRestrictedCountryPage();
     }
     /* Check Live Edit parameters */
     if (Tools::isSubmit('live_edit')) {
         $ad = Tools::getValue('ad');
         if (!$ad || Tools::getValue('liveToken') != sha1($ad . _COOKIE_KEY_) || !is_dir(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . $ad)) {
             die(Tools::displayError());
         }
     }
     $this->iso = $iso;
     $this->setMedia();
 }
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     $this->context->smarty->assign('genders', Gender::getGenders());
     $this->assignDate();
     $this->assignCountries();
     $this->context->smarty->assign('newsletter', 1);
     $back = Tools::getValue('back');
     $key = Tools::safeOutput(Tools::getValue('key'));
     if (!empty($key)) {
         $back .= (strpos($back, '?') !== false ? '&' : '?') . 'key=' . $key;
     }
     if ($back == Tools::secureReferrer(Tools::getValue('back'))) {
         $this->context->smarty->assign('back', html_entity_decode($back));
     } else {
         $this->context->smarty->assign('back', Tools::safeOutput($back));
     }
     if (Tools::getValue('display_guest_checkout')) {
         if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) {
             $countries = Carrier::getDeliveredCountries($this->context->language->id, true, true);
         } else {
             $countries = Country::getCountries($this->context->language->id, true);
         }
         if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
             // get all countries as language (xy) or language-country (wz-XY)
             $array = array();
             preg_match("#(?<=-)\\w\\w|\\w\\w(?!-)#", $_SERVER['HTTP_ACCEPT_LANGUAGE'], $array);
             if (!Validate::isLanguageIsoCode($array[0]) || !($sl_country = Country::getByIso($array[0]))) {
                 $sl_country = (int) Configuration::get('PS_COUNTRY_DEFAULT');
             }
         } else {
             $sl_country = (int) Tools::getValue('id_country', Configuration::get('PS_COUNTRY_DEFAULT'));
         }
         $this->context->smarty->assign(array('inOrderProcess' => true, 'PS_GUEST_CHECKOUT_ENABLED' => Configuration::get('PS_GUEST_CHECKOUT_ENABLED'), 'PS_REGISTRATION_PROCESS_TYPE' => Configuration::get('PS_REGISTRATION_PROCESS_TYPE'), 'sl_country' => (int) $sl_country, 'countries' => $countries));
     }
     if (Tools::getValue('create_account')) {
         $this->context->smarty->assign('email_create', 1);
     }
     if (Tools::getValue('multi-shipping') == 1) {
         $this->context->smarty->assign('multi_shipping', true);
     } else {
         $this->context->smarty->assign('multi_shipping', false);
     }
     $this->assignAddressFormat();
     // Call a hook to display more information on form
     $this->context->smarty->assign(array('HOOK_CREATE_ACCOUNT_FORM' => Hook::exec('displayCustomerAccountForm'), 'HOOK_CREATE_ACCOUNT_TOP' => Hook::exec('displayCustomerAccountFormTop')));
     // Just set $this->template value here in case it's used by Ajax
     $this->setTemplate(_PS_THEME_DIR_ . 'authentication.tpl');
     if ($this->ajax) {
         // Call a hook to display more information on form
         $this->context->smarty->assign(array('PS_REGISTRATION_PROCESS_TYPE' => Configuration::get('PS_REGISTRATION_PROCESS_TYPE'), 'genders' => Gender::getGenders()));
         $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'page' => $this->context->smarty->fetch($this->template), 'token' => Tools::getToken(false));
         die(Tools::jsonEncode($return));
     }
 }
 public static function downloadAndInstallLanguagePack($iso, $version = null, $params = null, $install = true)
 {
     if (!Validate::isLanguageIsoCode((string) $iso)) {
         return false;
     }
     if ($version == null) {
         $version = _PS_VERSION_;
     }
     $lang_pack = false;
     $lang_pack_ok = false;
     $errors = array();
     $file = _PS_TRANSLATIONS_DIR_ . (string) $iso . '.gzip';
     if (!($lang_pack_link = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . $version . '&iso_lang=' . Tools::strtolower((string) $iso)))) {
         $errors[] = Tools::displayError('Archive cannot be downloaded from prestashop.com.');
     } elseif (!($lang_pack = Tools::jsonDecode($lang_pack_link))) {
         $errors[] = Tools::displayError('Error occurred when language was checked according to your Prestashop version.');
     } elseif (empty($lang_pack->error) && ($content = Tools::file_get_contents('http://translations.prestashop.com/download/lang_packs/gzip/' . $lang_pack->version . '/' . Tools::strtolower($lang_pack->iso_code . '.gzip')))) {
         if (!@file_put_contents($file, $content)) {
             if (is_writable(dirname($file))) {
                 @unlink($file);
                 @file_put_contents($file, $content);
             } elseif (!is_writable($file)) {
                 $errors[] = Tools::displayError('Server does not have permissions for writing.') . ' (' . $file . ')';
             }
         }
     }
     if (!file_exists($file)) {
         $errors[] = Tools::displayError('No language pack is available for your version.');
     } elseif ($install) {
         require_once _PS_TOOL_DIR_ . 'tar/Archive_Tar.php';
         $gz = new Archive_Tar($file, true);
         $files_list = AdminTranslationsController::filterTranslationFiles(Language::getLanguagePackListContent((string) $iso, $gz));
         $files_paths = AdminTranslationsController::filesListToPaths($files_list);
         $i = 0;
         $tmp_array = array();
         foreach ($files_paths as $files_path) {
             $path = dirname($files_path);
             if (is_dir(_PS_TRANSLATIONS_DIR_ . '../' . $path) && !is_writable(_PS_TRANSLATIONS_DIR_ . '../' . $path) && !in_array($path, $tmp_array)) {
                 $errors[] = (!$i++ ? Tools::displayError('The archive cannot be extracted.') . ' ' : '') . Tools::displayError('The server does not have permissions for writing.') . ' ' . sprintf(Tools::displayError('Please check rights for %s'), $path);
                 $tmp_array[] = $path;
             }
         }
         if (defined('_PS_HOST_MODE_')) {
             $mails_files = array();
             $other_files = array();
             foreach ($files_list as $key => $data) {
                 if (substr($data['filename'], 0, 5) == 'mails') {
                     $mails_files[] = $data;
                 } else {
                     $other_files[] = $data;
                 }
             }
             $files_list = $other_files;
         }
         if (!$gz->extractList(AdminTranslationsController::filesListToPaths($files_list), _PS_TRANSLATIONS_DIR_ . '../')) {
             $errors[] = sprintf(Tools::displayError('Cannot decompress the translation file for the following language: %s'), (string) $iso);
         }
         // Clear smarty modules cache
         Tools::clearCache();
         if (!Language::checkAndAddLanguage((string) $iso, $lang_pack, false, $params)) {
             $errors[] = sprintf(Tools::displayError('An error occurred while creating the language: %s'), (string) $iso);
         } else {
             // Reset cache
             Language::loadLanguages();
             AdminTranslationsController::checkAndAddMailsFiles((string) $iso, $files_list);
             AdminTranslationsController::addNewTabs((string) $iso, $files_list);
         }
     }
     return count($errors) ? $errors : true;
 }
Example #17
0
 /**
  * Change language in cookie while clicking on a flag
  *
  * @return string iso code
  */
 public static function setCookieLanguage()
 {
     global $cookie;
     /* If language does not exist or is disabled, erase it */
     if ($cookie->id_lang) {
         $lang = new Language((int) $cookie->id_lang);
         if (!Validate::isLoadedObject($lang) or !$lang->active) {
             $cookie->id_lang = NULL;
         }
     }
     /* Automatically detect language if not already defined */
     if (!$cookie->id_lang and isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $array = explode(',', self::strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
         if (self::strlen($array[0]) > 2) {
             $tab = explode('-', $array[0]);
             $string = $tab[0];
         } else {
             $string = $array[0];
         }
         if (Validate::isLanguageIsoCode($string)) {
             $lang = new Language((int) Language::getIdByIso($string));
             if (Validate::isLoadedObject($lang) and $lang->active) {
                 $cookie->id_lang = (int) $lang->id;
             }
         }
     }
     /* If language file not present, you must use default language file */
     if (!$cookie->id_lang or !Validate::isUnsignedId($cookie->id_lang)) {
         $cookie->id_lang = (int) Configuration::get('PS_LANG_DEFAULT');
     }
     $iso = Language::getIsoById((int) $cookie->id_lang);
     @(include_once _PS_THEME_DIR_ . 'lang/' . $iso . '.php');
     return $iso;
 }
Example #18
0
 public function init()
 {
     global $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files;
     if (self::$initialized) {
         return;
     }
     self::$initialized = true;
     $css_files = array();
     $js_files = array();
     if ($this->ssl and (empty($_SERVER['HTTPS']) or strtolower($_SERVER['HTTPS']) == 'off') and Configuration::get('PS_SSL_ENABLED')) {
         header('HTTP/1.1 301 Moved Permanently');
         header('Location: ' . Tools::getShopDomainSsl(true) . $_SERVER['REQUEST_URI']);
         exit;
     }
     ob_start();
     /* Loading default country */
     $defaultCountry = new Country((int) Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
     $cookie = new Cookie('ps');
     $link = new Link();
     if ($this->auth and !$cookie->isLogged($this->guestAllowed)) {
         Tools::redirect('authentication.php' . ($this->authRedirection ? '?back=' . $this->authRedirection : ''));
     }
     /* Theme is missing or maintenance */
     if (!is_dir(_PS_THEME_DIR_)) {
         die(Tools::displayError('Current theme unavailable. Please check your theme directory name and permissions.'));
     } elseif (basename($_SERVER['PHP_SELF']) != 'disabled.php' and !(int) Configuration::get('PS_SHOP_ENABLE')) {
         $this->maintenance = true;
     } elseif (Configuration::get('PS_GEOLOCATION_ENABLED')) {
         if (!isset($cookie->iso_code_country)) {
             if ($cookie->logged) {
                 $id_country = Customer::getCurrentCountry((int) $cookie->id_customer);
                 $cookie->iso_code_country = Country::getIsoById($id_country);
             } else {
                 $this->geolocationManagement();
             }
         }
         if (!isset($cookie->iso_code_country)) {
             $current_country_id = Customer::getCurrentCountry((int) $cookie->id_customer);
         } else {
             $current_country_id = Country::getByIso($cookie->iso_code_country);
         }
         $current_country = new Country($current_country_id, 1);
         $cookie->id_country = $current_country->id;
         $smarty->assign('current_country', $current_country->name);
         $smarty->assign('current_country_id', $current_country->id);
         if ($cookie->id_country == 110 && !isset($cookie->id_currency)) {
             $cookie->id_currency = 4;
         }
     }
     //set imagesize if not set
     if (!isset($cookie->image_size)) {
         $cookie->image_size = IMAGE_SIZE_LARGE;
         $cookie->write();
     }
     if (!isset($cookie->greetings) && !$cookie->logged) {
         $cookie->greetings = 1;
         $cookie->write();
         $smarty->assign('show_greetings', 1);
     }
     //echo $cookie->image_size;
     if ($image_size = Tools::getValue("is")) {
         if ($image_size == "s" && $cookie->image_size == IMAGE_SIZE_LARGE) {
             $cookie->image_size = IMAGE_SIZE_SMALL;
             $cookie->write();
         } else {
             if ($image_size == "l" && $cookie->image_size == IMAGE_SIZE_SMALL) {
                 $cookie->image_size = IMAGE_SIZE_LARGE;
                 $cookie->write();
             }
         }
     }
     // Switch language if needed and init cookie language
     if ($iso = Tools::getValue('isolang') and Validate::isLanguageIsoCode($iso) and $id_lang = (int) Language::getIdByIso($iso)) {
         $_GET['id_lang'] = $id_lang;
     }
     Tools::switchLanguage();
     Tools::setCookieLanguage();
     /* attribute id_lang is often needed, so we create a constant for performance reasons */
     if (!defined('_USER_ID_LANG_')) {
         define('_USER_ID_LANG_', (int) $cookie->id_lang);
     }
     if (isset($_GET['logout']) or $cookie->logged and Customer::isBanned((int) $cookie->id_customer)) {
         $cookie->logout();
         Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL);
     } elseif (isset($_GET['mylogout'])) {
         $this->logoutFacebook();
         $cookie->mylogout();
         Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL);
     }
     if ($source = Tools::getValue('utm_source')) {
         $cookie->last_source = $source;
         $cookie->write();
     }
     if ($ref_source = Tools::getValue('vbref')) {
         $cookie->last_ref_source = $ref_source;
         $cookie->write();
     }
     /*else 
     		{
     			if(!isset($cookie->last_ref_source))
     			{
     				$cookie->last_ref_source = 0;
     				$cookie->write();
     			}
     		}*/
     global $currency;
     $currency = Tools::setCurrency();
     $_MODULES = array();
     /* Cart already exists */
     if ((int) $cookie->id_cart) {
         $cart = new Cart((int) $cookie->id_cart);
         if ($cart->OrderExists()) {
             unset($cookie->id_cart, $cart, $cookie->checkedTOS);
         } elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) and !in_array(strtoupper($cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) and $cart->nbProducts() and intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 and !self::isInWhitelistForGeolocation()) {
             unset($cookie->id_cart, $cart);
         } elseif ($cookie->id_customer != $cart->id_customer or $cookie->id_lang != $cart->id_lang or $cookie->id_currency != $cart->id_currency) {
             if ($cookie->id_customer) {
                 $cart->id_customer = (int) $cookie->id_customer;
             }
             $cart->id_lang = (int) $cookie->id_lang;
             $cart->id_currency = (int) $cookie->id_currency;
             $cart->update();
         }
         /* Select an address if not set */
         if (isset($cart) && (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0 || !isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) && $cookie->id_customer) {
             $to_update = false;
             if (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0) {
                 $to_update = true;
                 $cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer);
             }
             if (!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) {
                 $to_update = true;
                 $cart->id_address_invoice = (int) Address::getFirstCustomerAddressId($cart->id_customer);
             }
             if ($to_update) {
                 $cart->update();
             }
         }
     }
     if (!isset($cart) or !$cart->id) {
         $this->checkIDS();
         $cart = new Cart();
         $cart->id_lang = (int) $cookie->id_lang;
         $cart->id_currency = (int) $cookie->id_currency;
         $cart->id_guest = (int) $cookie->id_guest;
         if ($cookie->id_customer) {
             $cart->id_customer = (int) $cookie->id_customer;
             $cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer);
             $cart->id_address_invoice = $cart->id_address_delivery;
         } else {
             $cart->id_address_delivery = 0;
             $cart->id_address_invoice = 0;
         }
     }
     if (!$cart->nbProducts()) {
         $cart->id_carrier = NULL;
     }
     $locale = strtolower(Configuration::get('PS_LOCALE_LANGUAGE')) . '_' . strtoupper(Configuration::get('PS_LOCALE_COUNTRY') . '.UTF-8');
     setlocale(LC_COLLATE, $locale);
     setlocale(LC_CTYPE, $locale);
     setlocale(LC_TIME, $locale);
     setlocale(LC_NUMERIC, 'en_US.UTF-8');
     if (Validate::isLoadedObject($currency)) {
         $smarty->ps_currency = $currency;
     }
     if (Validate::isLoadedObject($ps_language = new Language((int) $cookie->id_lang))) {
         $smarty->ps_language = $ps_language;
     }
     /* get page name to display it in body id */
     $pathinfo = pathinfo(__FILE__);
     $page_name = basename($_SERVER['PHP_SELF'], '.' . $pathinfo['extension']);
     $page_name = preg_match('/^[0-9]/', $page_name) ? 'page_' . $page_name : $page_name;
     $smarty->assign(Tools::getMetaTags($cookie->id_lang, $page_name));
     $smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
     /* Breadcrumb */
     $navigationPipe = Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>';
     $smarty->assign('navigationPipe', $navigationPipe);
     $protocol_link = (Configuration::get('PS_SSL_ENABLED') or !empty($_SERVER['HTTPS']) and strtolower($_SERVER['HTTPS']) != 'off') ? 'https://' : 'http://';
     $protocol_content = (isset($useSSL) and $useSSL and Configuration::get('PS_SSL_ENABLED') or !empty($_SERVER['HTTPS']) and strtolower($_SERVER['HTTPS']) != 'off') ? 'https://' : 'http://';
     if (!defined('_PS_BASE_URL_')) {
         define('_PS_BASE_URL_', Tools::getShopDomain(true));
     }
     if (!defined('_PS_BASE_URL_SSL_')) {
         define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
     }
     $link->preloadPageLinks();
     $this->canonicalRedirection();
     Product::initPricesComputation();
     $display_tax_label = $defaultCountry->display_tax_label;
     if ($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) {
         $infos = Address::getCountryAndState((int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
         $country = new Country((int) $infos['id_country']);
         if (Validate::isLoadedObject($country)) {
             $display_tax_label = $country->display_tax_label;
         }
     }
     global $isBetaUser, $conversion_rate_inr;
     $conversion_rate_inr = 55;
     if (!$cookie->isLogged()) {
         $this->initFacebook();
     } else {
         $customer_groups = Customer::getGroupsStatic((int) $cookie->id_customer);
         if (in_array(2, $customer_groups)) {
             $smarty->assign('internal_vb_user', 1);
         }
         if (in_array(3, $customer_groups)) {
             $isBetaUser = true;
         } else {
             $isBetaUser = false;
         }
         /*$reward_points = VBRewards::getCustomerPoints($cookie->id_customer);
         		$can_redeem = VBRewards::checkPointsValidity($cookie->id_customer, 0);
         		if($can_redeem)
                                    $smarty->assign('can_redeem_points', 1);
         		$smarty->assign('balance_points', $reward_points);*/
     }
     $smarty->assign('img_version', IMG_VERSION);
     $this->setRecaptchaHTML();
     if ($page_name === "index") {
         $sql = "select title,image_path,url from ps_banner where is_active = 1 order by display_order asc";
         $home_banners = Db::getInstance()->ExecuteS($sql);
         $smarty->assign("home_banners", $home_banners);
     }
     $smarty->assign(array('lazy' => 1, 'link' => $link, 'cart' => $cart, 'currency' => $currency, 'cookie' => $cookie, 'page_name' => $page_name, 'base_dir' => _PS_BASE_URL_ . __PS_BASE_URI__, 'base_dir_ssl' => $protocol_link . Tools::getShopDomainSsl() . __PS_BASE_URI__, 'content_dir' => $protocol_content . Tools::getShopDomain() . __PS_BASE_URI__, 'tpl_dir' => _PS_THEME_DIR_, 'modules_dir' => _MODULE_DIR_, 'mail_dir' => _MAIL_DIR_, 'lang_iso' => $ps_language->iso_code, 'come_from' => Tools::getHttpHost(true, true) . Tools::htmlentitiesUTF8(str_replace('\'', '', urldecode($_SERVER['REQUEST_URI']))), 'cart_qties' => (int) $cart->nbProducts(), 'currencies' => Currency::getCurrencies(), 'languages' => Language::getLanguages(), 'priceDisplay' => Product::getTaxCalculationMethod(), 'add_prod_display' => (int) Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'roundMode' => (int) Configuration::get('PS_PRICE_ROUND_MODE'), 'use_taxes' => (int) Configuration::get('PS_TAX'), 'display_tax_label' => (bool) $display_tax_label, 'vat_management' => (int) Configuration::get('VATNUMBER_MANAGEMENT'), 'opc' => (bool) Configuration::get('PS_ORDER_PROCESS_TYPE'), 'PS_CATALOG_MODE' => (bool) Configuration::get('PS_CATALOG_MODE'), 'conversion_rate' => $conversion_rate_inr));
     // Deprecated
     $smarty->assign(array('id_currency_cookie' => (int) $currency->id, 'logged' => $cookie->isLogged(), 'customerName' => $cookie->logged ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : false));
     // TODO for better performances (cache usage), remove these assign and use a smarty function to get the right media server in relation to the full ressource name
     $assignArray = array('img_ps_dir' => _PS_IMG_, 'img_cat_dir' => _THEME_CAT_DIR_, 'img_lang_dir' => _THEME_LANG_DIR_, 'img_prod_dir' => _THEME_PROD_DIR_, 'img_manu_dir' => _THEME_MANU_DIR_, 'img_sup_dir' => _THEME_SUP_DIR_, 'img_ship_dir' => _THEME_SHIP_DIR_, 'img_store_dir' => _THEME_STORE_DIR_, 'img_col_dir' => _THEME_COL_DIR_, 'img_dir' => _THEME_IMG_DIR_, 'css_dir' => _THEME_CSS_DIR_, 'js_dir' => _THEME_JS_DIR_, 'pic_dir' => _THEME_PROD_PIC_DIR_);
     foreach ($assignArray as $assignKey => $assignValue) {
         if (substr($assignValue, 0, 1) == '/' or $protocol_content == 'https://') {
             $smarty->assign($assignKey, $protocol_content . Tools::getMediaServer($assignValue) . $assignValue);
         } else {
             $smarty->assign($assignKey, $assignValue);
         }
     }
     // setting properties from global var
     self::$cookie = $cookie;
     self::$cart = $cart;
     self::$smarty = $smarty;
     self::$link = $link;
     if ($this->maintenance) {
         $this->displayMaintenancePage();
     }
     if ($this->restrictedCountry) {
         $this->displayRestrictedCountryPage();
     }
     //live edit
     if (Tools::isSubmit('live_edit') and $ad = Tools::getValue('ad') and Tools::getValue('liveToken') == sha1(Tools::getValue('ad') . _COOKIE_KEY_)) {
         if (!is_dir(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . $ad)) {
             die(Tools::displayError());
         }
     }
     $this->iso = $iso;
     $this->setMedia();
     //For sokrati pixel
     self::$smarty->assign("new_customer_regd", false);
     if ((int) self::$cookie->new_reg === 1) {
         self::$smarty->assign("new_customer_regd", true);
         unset(self::$cookie->new_reg);
     }
     if (self::$cookie->id_customer) {
         self::$smarty->assign("balance_points", VBRewards::getCustomerPoints(self::$cookie->id_customer));
     }
 }
Example #19
0
    /**
     * Return id from iso code
     *
     * @param string $iso_code Iso code
     * @return integer Language ID
     */
    public static function getIdByIso($iso_code)
    {
        if (!Validate::isLanguageIsoCode($iso_code)) {
            die(Tools::displayError());
        }
        $result = Db::getInstance()->getRow('
		SELECT `id_lang`
		FROM `' . _DB_PREFIX_ . 'lang`
		WHERE `iso_code` = \'' . pSQL(strtolower($iso_code)) . '\'');
        if (isset($result['id_lang'])) {
            return intval($result['id_lang']);
        }
    }
 /**
  * Add new translations tabs by code ISO
  *
  * @param array $iso_code
  * @param array $files
  */
 public static function addNewTabs($iso_code, $files)
 {
     foreach ($files as $file) {
         // Check if file is a file theme
         if (preg_match('#^translations\\/' . $iso_code . '\\/tabs.php#Ui', $file['filename'], $matches) && Validate::isLanguageIsoCode($iso_code)) {
             // Include array width new translations tabs
             $tabs = (include _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . $file['filename']);
             foreach ($tabs as $class_name => $translations) {
                 // Get instance of this tab by class name
                 $tab = Tab::getInstanceFromClassName($class_name);
                 //Check if class name exists
                 if (isset($tab->class_name) && !empty($tab->class_name)) {
                     $id_lang = Language::getIdByIso($iso_code);
                     $tab->name[(int) $id_lang] = pSQL($translations);
                     // Update this tab
                     $tab->update();
                 }
             }
         }
     }
 }
 protected function copyFromPost(&$object, $table)
 {
     if ($object->id && $object->iso_code != $_POST['iso_code']) {
         if (Validate::isLanguageIsoCode($_POST['iso_code'])) {
             $object->moveToIso($_POST['iso_code']);
         }
     }
     parent::copyFromPost($object, $table);
 }
    /**
     * Load default routes group by languages
     */
    protected function loadRoutes($id_shop = null)
    {
        $context = Context::getContext();
        // Load custom routes from modules
        $modules_routes = Hook::exec('moduleRoutes', array('id_shop' => $id_shop), null, true, false);
        if (is_array($modules_routes) && count($modules_routes)) {
            foreach ($modules_routes as $module_route) {
                if (is_array($module_route) && count($module_route)) {
                    foreach ($module_route as $route => $route_details) {
                        if (array_key_exists('controller', $route_details) && array_key_exists('rule', $route_details) && array_key_exists('keywords', $route_details) && array_key_exists('params', $route_details)) {
                            if (!isset($this->default_routes[$route])) {
                                $this->default_routes[$route] = array();
                            }
                            $this->default_routes[$route] = array_merge($this->default_routes[$route], $route_details);
                        }
                    }
                }
            }
        }
        $languages = array();
        if (isset($context->language) && !in_array($context->language->id, $languages = Language::getLanguages())) {
            $languages[] = (int) $context->language->id;
            // Set default routes
            foreach ($languages as $lang) {
                foreach ($this->default_routes as $id => $route) {
                    $this->addRoute($id, $route['rule'], $route['controller'], $lang['id_lang'], $route['keywords'], isset($route['params']) ? $route['params'] : array(), $id_shop);
                }
            }
        }
        // Load the custom routes prior the defaults to avoid infinite loops
        if ($this->use_routes) {
            // Get iso lang
            $iso_lang = Tools::getValue('isolang');
            if (isset($context->language)) {
                $id_lang = (int) $context->language->id;
            }
            if (!empty($iso_lang) && Validate::isLanguageIsoCode($iso_lang) || !isset($id_lang)) {
                $id_lang = Language::getIdByIso($iso_lang);
            }
            // Load routes from meta table
            $sql = 'SELECT m.page, ml.url_rewrite, ml.id_lang
					FROM `' . _DB_PREFIX_ . 'meta` m
					LEFT JOIN `' . _DB_PREFIX_ . 'meta_lang` ml ON (m.id_meta = ml.id_meta' . Shop::addSqlRestrictionOnLang('ml', $id_shop) . ')
					ORDER BY LENGTH(ml.url_rewrite) DESC';
            if ($results = Db::getInstance()->executeS($sql)) {
                foreach ($results as $row) {
                    if ($row['url_rewrite']) {
                        $this->addRoute($row['page'], $row['url_rewrite'], $row['page'], $row['id_lang'], array(), array(), $id_shop);
                    }
                }
            }
            // Set default empty route if no empty route (that's weird I know)
            if (!$this->empty_route) {
                $this->empty_route = array('routeID' => 'index', 'rule' => '', 'controller' => 'index');
            }
            // Load custom routes
            foreach ($this->default_routes as $route_id => $route_data) {
                if ($custom_route = Configuration::get('PS_ROUTE_' . $route_id, null, null, $id_shop)) {
                    if (isset($context->language) && !in_array($context->language->id, $languages = Language::getLanguages())) {
                        $languages[] = (int) $context->language->id;
                    }
                    foreach ($languages as $lang) {
                        $this->addRoute($route_id, $custom_route, $route_data['controller'], $lang['id_lang'], $route_data['keywords'], isset($route_data['params']) ? $route_data['params'] : array(), $id_shop);
                    }
                }
            }
        }
    }
Example #23
0
 public static function getLanguageCodeByIso($iso_code)
 {
     if (!Validate::isLanguageIsoCode($iso_code)) {
         die(Tools::displayError('Fatal error : iso code is not correct : ') . $iso_code);
     }
     return Db::getInstance()->getValue('SELECT `language_code` FROM `' . _DB_PREFIX_ . 'lang` WHERE `iso_code` = \'' . pSQL(strtolower($iso_code)) . '\'');
 }
 public function postProcess()
 {
     if (!Tools::getValue('id_' . $this->table)) {
         if (Validate::isLanguageIsoCode(Tools::getValue('iso_code')) && Country::getByIso(Tools::getValue('iso_code'))) {
             $this->errors[] = Tools::displayError('This ISO code already exists.You cannot create two countries with the same ISO code.');
         }
     } else {
         if (Validate::isLanguageIsoCode(Tools::getValue('iso_code'))) {
             $id_country = Country::getByIso(Tools::getValue('iso_code'));
             if (!is_null($id_country) && $id_country != Tools::getValue('id_' . $this->table)) {
                 $this->errors[] = Tools::displayError('This ISO code already exists.You cannot create two countries with the same ISO code.');
             }
         }
     }
     if (Tools::isSubmit('standardization')) {
         Configuration::updateValue('PS_TAASC', (bool) Tools::getValue('standardization', false));
     }
     return parent::postProcess();
 }
Example #25
0
    }
    $years = Tools::dateYears();
    if (isset($_POST['months']) and is_numeric($_POST['months'])) {
        $selectedMonths = intval($_POST['months']);
    }
    $months = Tools::dateMonths();
    if (isset($_POST['days']) and is_numeric($_POST['days'])) {
        $selectedDays = intval($_POST['days']);
    }
    $days = Tools::dateDays();
    /* Select the most appropriate country */
    if (isset($_POST['id_country']) and is_numeric($_POST['id_country'])) {
        $selectedCountry = intval($_POST['id_country']);
    } elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        $array = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
        if (Validate::isLanguageIsoCode($array[0])) {
            $selectedCountry = Country::getByIso($array[0]);
            if (!$selectedCountry) {
                $selectedCountry = intval(Configuration::get('PS_COUNTRY_DEFAULT'));
            }
        }
    }
    if (!isset($selectedCountry)) {
        $selectedCountry = intval(Configuration::get('PS_COUNTRY_DEFAULT'));
    }
    $countries = Country::getCountries(intval($cookie->id_lang), true);
    $smarty->assign(array('years' => $years, 'sl_year' => isset($selectedYears) ? $selectedYears : 0, 'months' => $months, 'sl_month' => isset($selectedMonths) ? $selectedMonths : 0, 'days' => $days, 'sl_day' => isset($selectedDays) ? $selectedDays : 0, 'countries' => $countries, 'sl_country' => isset($selectedCountry) ? $selectedCountry : 0));
    /* Call a hook to display more information on form */
    $smarty->assign(array('HOOK_CREATE_ACCOUNT_FORM' => Module::hookExec('createAccountForm'), 'HOOK_CREATE_ACCOUNT_TOP' => Module::hookExec('createAccountTop')));
}
include dirname(__FILE__) . '/header.php';
Example #26
0
    /**
     * Get a country ID with its iso code
     *
     * @param string $iso_code Country iso code
     * @return integer Country ID
     */
    public static function getByIso($iso_code)
    {
        if (!Validate::isLanguageIsoCode($iso_code)) {
            die(Tools::displayError());
        }
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
		SELECT `id_country`
		FROM `' . _DB_PREFIX_ . 'country`
		WHERE `iso_code` = \'' . pSQL(strtoupper($iso_code)) . '\'');
        return $result['id_country'];
    }
Example #27
0
 /**
  * Returns the default country Id
  *
  * @return integer default country id
  */
 public static function getDefaultCountryId()
 {
     global $cookie;
     if (Configuration::get('PS_GEOLOCATION_ENABLED') && $cookie && isset($cookie->iso_code_country) && Validate::isLanguageIsoCode($cookie->iso_code_country)) {
         $id_country = (int) Country::getByIso($cookie->iso_code_country);
     } else {
         $id_country = (int) Configuration::get('PS_COUNTRY_DEFAULT');
     }
     return $id_country;
 }
 public function postProcess()
 {
     if (!Tools::getValue('id_' . $this->table)) {
         if (Validate::isLanguageIsoCode(Tools::getValue('iso_code')) && Country::getByIso(Tools::getValue('iso_code'))) {
             $this->errors[] = Tools::displayError('This ISO code already exists, you cannot create two country with the same ISO code');
         }
     } else {
         if (Validate::isLanguageIsoCode(Tools::getValue('iso_code'))) {
             $id_country = Country::getByIso(Tools::getValue('iso_code'));
             if (!is_null($id_country) && $id_country != Tools::getValue('id_' . $this->table)) {
                 $this->errors[] = Tools::displayError('This ISO code already exists, you cannot create two country with the same ISO code');
             }
         }
     }
     if (!count($this->errors)) {
         $res = parent::postProcess();
     } else {
         return false;
     }
     if (Tools::getValue('submitAdd' . $this->table) && $res) {
         $id_country = ($id_country = Tools::getValue('id_country')) ? $id_country : $res['id'];
         $tmp_addr_format = new AddressFormat($id_country);
         $save_status = false;
         $is_new = is_null($tmp_addr_format->id_country);
         if ($is_new) {
             $tmp_addr_format = new AddressFormat();
             $tmp_addr_format->id_country = $id_country;
         }
         $tmp_addr_format->format = Tools::getValue('address_layout');
         if (strlen($tmp_addr_format->format) > 0) {
             if ($tmp_addr_format->checkFormatFields()) {
                 $save_status = $is_new ? $tmp_addr_format->save() : $tmp_addr_format->update();
             } else {
                 $error_list = $tmp_addr_format->getErrorList();
                 foreach ($error_list as $num_error => $error) {
                     $this->errors[] = $error;
                 }
             }
             if (!$save_status) {
                 $this->errors[] = Tools::displayError('Invalid address layout' . Db::getInstance()->getMsgError());
             }
         }
         unset($tmp_addr_format);
     }
     return $res;
 }
Example #29
0
 protected function geolocationManagement($default_country)
 {
     if (!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) {
         /* Check if Maxmind Database exists */
         if (file_exists(_PS_GEOIP_DIR_ . 'GeoLiteCity.dat')) {
             if (!isset($this->context->cookie->iso_code_country) || isset($this->context->cookie->iso_code_country) && !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES')))) {
                 include_once _PS_GEOIP_DIR_ . 'geoipcity.inc';
                 $gi = geoip_open(realpath(_PS_GEOIP_DIR_ . 'GeoLiteCity.dat'), GEOIP_STANDARD);
                 $record = geoip_record_by_addr($gi, Tools::getRemoteAddr());
                 if (is_object($record)) {
                     if (!in_array(strtoupper($record->country_code), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) && !FrontController::isInWhitelistForGeolocation()) {
                         if (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_) {
                             $this->restrictedCountry = true;
                         } elseif (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_) {
                             $this->context->smarty->assign(array('restricted_country_mode' => true, 'geolocation_country' => $record->country_name));
                         }
                     } else {
                         $has_been_set = !isset($this->context->cookie->iso_code_country);
                         $this->context->cookie->iso_code_country = strtoupper($record->country_code);
                     }
                 }
             }
             if (isset($this->context->cookie->iso_code_country) && $this->context->cookie->iso_code_country && !Validate::isLanguageIsoCode($this->context->cookie->iso_code_country)) {
                 $this->context->cookie->iso_code_country = Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'));
             }
             if (isset($this->context->cookie->iso_code_country) && ($id_country = Country::getByIso(strtoupper($this->context->cookie->iso_code_country)))) {
                 /* Update defaultCountry */
                 if ($default_country->iso_code != $this->context->cookie->iso_code_country) {
                     $default_country = new Country($id_country);
                 }
                 if (isset($has_been_set) && $has_been_set) {
                     $this->context->cookie->id_currency = (int) Currency::getCurrencyInstance($default_country->id_currency ? (int) $default_country->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id;
                 }
                 return $default_country;
             } elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_ && !FrontController::isInWhitelistForGeolocation()) {
                 $this->restrictedCountry = true;
             } elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_ && !FrontController::isInWhitelistForGeolocation()) {
                 $this->context->smarty->assign(array('restricted_country_mode' => true, 'geolocation_country' => 'Undefined'));
             }
         } else {
             Configuration::updateValue('PS_GEOLOCATION_ENABLED', 0);
         }
     }
     return false;
 }
Example #30
0
 /**
  * Assign template vars related to countries display
  */
 protected function assignCountries()
 {
     // Get selected country
     if (Tools::isSubmit('id_country') && !is_null(Tools::getValue('id_country')) && is_numeric(Tools::getValue('id_country'))) {
         $selected_country = (int) Tools::getValue('id_country');
     } else {
         if (isset($this->_address) && isset($this->_address->id_country) && !empty($this->_address->id_country) && is_numeric($this->_address->id_country)) {
             $selected_country = (int) $this->_address->id_country;
         } else {
             if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                 // get all countries as language (xy) or language-country (wz-XY)
                 $array = array();
                 preg_match("#(?<=-)\\w\\w|\\w\\w(?!-)#", $_SERVER['HTTP_ACCEPT_LANGUAGE'], $array);
                 if (!Validate::isLanguageIsoCode($array[0]) || !($selected_country = Country::getByIso($array[0]))) {
                     $selected_country = (int) Configuration::get('PS_COUNTRY_DEFAULT');
                 }
             } else {
                 $selected_country = (int) Configuration::get('PS_COUNTRY_DEFAULT');
             }
         }
     }
     // Generate countries list
     if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) {
         $countries = Carrier::getDeliveredCountries($this->context->language->id, true, true);
     } else {
         $countries = Country::getCountries($this->context->language->id, true);
     }
     // @todo use helper
     $list = '';
     foreach ($countries as $country) {
         $selected = $country['id_country'] == $selected_country ? 'selected="selected"' : '';
         $list .= '<option value="' . (int) $country['id_country'] . '" ' . $selected . '>' . htmlentities($country['name'], ENT_COMPAT, 'UTF-8') . '</option>';
     }
     // Assign vars
     $this->context->smarty->assign(array('countries_list' => $list, 'countries' => $countries));
 }