$sqlParams[] = 'UPDATE ' . _DB_PREFIX_ . 'configuration SET value = "' . pSQL($_GET['infosTimezone']) . '" WHERE name = \'PS_TIMEZONE\'';
     $sql_isocode = Db::getInstance()->getValue('SELECT `iso_code` FROM `' . _DB_PREFIX_ . 'country` WHERE `id_country` = ' . (int) $_GET['infosCountry']);
     $sqlParams[] = 'UPDATE ' . _DB_PREFIX_ . 'configuration SET value = \'' . pSQL($sql_isocode) . '\' WHERE name = \'PS_LOCALE_COUNTRY\'';
 }
 Language::loadLanguages();
 Configuration::loadConfiguration();
 require_once dirname(__FILE__) . '/../../config/defines.inc.php';
 require_once dirname(__FILE__) . '/../../classes/LocalizationPack.php';
 $context = stream_context_create(array('http' => array('timeout' => 5)));
 $localization_file = @Tools::file_get_contents('http://www.prestashop.com/download/localization_pack.php?country=' . $_GET['countryName'], false, $context);
 if (!$localization_file and file_exists(dirname(__FILE__) . '/../../localization/' . strtolower($_GET['countryName']) . '.xml')) {
     $localization_file = @file_get_contents(dirname(__FILE__) . '/../../localization/' . strtolower($_GET['countryName']) . '.xml');
 }
 if ($localization_file) {
     $localizationPack = new LocalizationPackCore();
     $localizationPack->loadLocalisationPack($localization_file, '', true);
     if (Configuration::get('PS_LANG_DEFAULT') == 1) {
         $sqlParams[] = 'UPDATE `' . _DB_PREFIX_ . 'configuration` SET `value` = (SELECT id_lang FROM ' . _DB_PREFIX_ . 'lang WHERE iso_code = \'' . pSQL($_GET['isoCode']) . '\') WHERE name = \'PS_LANG_DEFAULT\'';
         // This request is used when _PS_MODE_DEV_ is set to true
         $sqlParams[] = 'UPDATE `' . _DB_PREFIX_ . 'lang` SET `active` = 0 WHERE `iso_code` != \'' . pSQL($_GET['isoCode']) . '\'';
     } else {
         $sqlParams[] = 'UPDATE `' . _DB_PREFIX_ . 'lang` SET `active` = 0 WHERE `id_lang` != ' . Configuration::get('PS_LANG_DEFAULT');
     }
 }
 if (isset($_GET['infosMailMethod']) and $_GET['infosMailMethod'] == "smtp") {
     $sqlParams[] = "INSERT INTO " . _DB_PREFIX_ . "configuration (name, value, date_add, date_upd) VALUES ('PS_MAIL_SERVER', '" . pSQL($_GET['smtpSrv']) . "', NOW(), NOW())";
     $sqlParams[] = "INSERT INTO " . _DB_PREFIX_ . "configuration (name, value, date_add, date_upd) VALUES ('PS_MAIL_USER', '" . pSQL($_GET['smtpLogin']) . "', NOW(), NOW())";
     $sqlParams[] = "INSERT INTO " . _DB_PREFIX_ . "configuration (name, value, date_add, date_upd) VALUES ('PS_MAIL_PASSWD', '" . pSQL($_GET['smtpPassword']) . "', NOW(), NOW())";
     $sqlParams[] = "INSERT INTO " . _DB_PREFIX_ . "configuration (name, value, date_add, date_upd) VALUES ('PS_MAIL_SMTP_ENCRYPTION', '" . pSQL($_GET['smtpEnc']) . "', NOW(), NOW())";
     $sqlParams[] = "INSERT INTO " . _DB_PREFIX_ . "configuration (name, value, date_add, date_upd) VALUES ('PS_MAIL_SMTP_PORT', '" . pSQL($_GET['smtpPort']) . "', NOW(), NOW())";
 }
Example #2
0
 /**
  * PROCESS : configureShop
  * Set default shop configuration
  */
 public function configureShop(array $data = array())
 {
     //clear image cache in tmp folder
     if (file_exists(_PS_TMP_IMG_DIR_)) {
         foreach (scandir(_PS_TMP_IMG_DIR_) as $file) {
             if ($file[0] != '.' && $file != 'index.php') {
                 Tools::deleteFile(_PS_TMP_IMG_DIR_ . $file);
             }
         }
     }
     $default_data = array('shop_name' => 'My Shop', 'shop_activity' => '', 'shop_country' => 'us', 'shop_timezone' => 'US/Eastern', 'use_smtp' => false, 'smtp_server' => '', 'smtp_login' => '', 'smtp_password' => '', 'smtp_encryption' => 'off', 'smtp_port' => 25);
     foreach ($default_data as $k => $v) {
         if (!isset($data[$k])) {
             $data[$k] = $v;
         }
     }
     Context::getContext()->shop = new Shop(1);
     Configuration::loadConfiguration();
     // use the old image system if the safe_mod is enabled otherwise the installer will fail with the fixtures installation
     if (InstallSession::getInstance()->safe_mode) {
         Configuration::updateGlobalValue('PS_LEGACY_IMAGES', 1);
     }
     $id_country = Country::getByIso($data['shop_country']);
     // Set default configuration
     Configuration::updateGlobalValue('PS_SHOP_DOMAIN', Tools::getHttpHost());
     Configuration::updateGlobalValue('PS_SHOP_DOMAIN_SSL', Tools::getHttpHost());
     Configuration::updateGlobalValue('PS_INSTALL_VERSION', _PS_INSTALL_VERSION_);
     Configuration::updateGlobalValue('PS_LOCALE_LANGUAGE', $this->language->getLanguageIso());
     Configuration::updateGlobalValue('PS_SHOP_NAME', $data['shop_name']);
     Configuration::updateGlobalValue('PS_SHOP_ACTIVITY', $data['shop_activity']);
     Configuration::updateGlobalValue('PS_COUNTRY_DEFAULT', $id_country);
     Configuration::updateGlobalValue('PS_LOCALE_COUNTRY', $data['shop_country']);
     Configuration::updateGlobalValue('PS_TIMEZONE', $data['shop_timezone']);
     Configuration::updateGlobalValue('PS_CONFIGURATION_AGREMENT', (int) $data['configuration_agrement']);
     // Set mails configuration
     Configuration::updateGlobalValue('PS_MAIL_METHOD', $data['use_smtp'] ? 2 : 1);
     Configuration::updateGlobalValue('PS_MAIL_SERVER', $data['smtp_server']);
     Configuration::updateGlobalValue('PS_MAIL_USER', $data['smtp_login']);
     Configuration::updateGlobalValue('PS_MAIL_PASSWD', $data['smtp_password']);
     Configuration::updateGlobalValue('PS_MAIL_SMTP_ENCRYPTION', $data['smtp_encryption']);
     Configuration::updateGlobalValue('PS_MAIL_SMTP_PORT', $data['smtp_port']);
     // Activate rijndael 128 encrypt algorihtm if mcrypt is activated
     Configuration::updateGlobalValue('PS_CIPHER_ALGORITHM', function_exists('mcrypt_encrypt') ? 1 : 0);
     // Set logo configuration
     if (file_exists(_PS_IMG_DIR_ . 'logo.jpg')) {
         list($width, $height) = getimagesize(_PS_IMG_DIR_ . 'logo.jpg');
         Configuration::updateGlobalValue('SHOP_LOGO_WIDTH', round($width));
         Configuration::updateGlobalValue('SHOP_LOGO_HEIGHT', round($height));
     }
     // Active only the country selected by the merchant
     Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'country SET active = 0 WHERE id_country != ' . (int) $id_country);
     // Set localization configuration
     $version = str_replace('.', '', _PS_VERSION_);
     $version = substr($version, 0, 2);
     $localization_file_content = @Tools::file_get_contents('http://api.prestashop.com/localization/' . $version . '/' . $data['shop_country'] . '.xml');
     if (!@simplexml_load_string($localization_file_content)) {
         $localization_file_content = false;
     }
     if (!$localization_file_content) {
         $localization_file = _PS_ROOT_DIR_ . '/localization/default.xml';
         if (file_exists(_PS_ROOT_DIR_ . '/localization/' . $data['shop_country'] . '.xml')) {
             $localization_file = _PS_ROOT_DIR_ . '/localization/' . $data['shop_country'] . '.xml';
         }
         $localization_file_content = file_get_contents($localization_file);
     }
     $locale = new LocalizationPackCore();
     $locale->loadLocalisationPack($localization_file_content, '', true);
     // Create default employee
     if (isset($data['admin_firstname']) && isset($data['admin_lastname']) && isset($data['admin_password']) && isset($data['admin_email'])) {
         $employee = new Employee();
         $employee->firstname = Tools::ucfirst($data['admin_firstname']);
         $employee->lastname = Tools::ucfirst($data['admin_lastname']);
         $employee->email = $data['admin_email'];
         $employee->passwd = md5(_COOKIE_KEY_ . $data['admin_password']);
         $employee->last_passwd_gen = date('Y-m-d h:i:s', strtotime('-360 minutes'));
         $employee->bo_theme = 'default';
         $employee->default_tab = 1;
         $employee->active = true;
         $employee->id_profile = 1;
         $employee->id_lang = Configuration::get('PS_LANG_DEFAULT');
         $employee->bo_show_screencast = 1;
         if (!$employee->add()) {
             $this->setError($this->language->l('Cannot create admin account'));
             return false;
         }
     } else {
         $this->setError($this->language->l('Cannot create admin account'));
         return false;
     }
     // Update default contact
     if (isset($data['admin_email'])) {
         Configuration::updateGlobalValue('PS_SHOP_EMAIL', $data['admin_email']);
         $contacts = new Collection('Contact');
         foreach ($contacts as $contact) {
             $contact->email = $data['admin_email'];
             $contact->update();
         }
     }
     return true;
 }
 /**
  * PROCESS : configureShop
  * Set default shop configuration
  */
 public function configureShop(array $data = array())
 {
     //clear image cache in tmp folder
     if (file_exists(_PS_TMP_IMG_DIR_)) {
         foreach (scandir(_PS_TMP_IMG_DIR_) as $file) {
             if ($file[0] != '.' && $file != 'index.php') {
                 Tools::deleteFile(_PS_TMP_IMG_DIR_ . $file);
             }
         }
     }
     $default_data = array('shop_name' => 'My Shop', 'shop_activity' => '', 'shop_country' => 'us', 'shop_timezone' => 'US/Eastern', 'use_smtp' => false, 'smtp_encryption' => 'off', 'smtp_port' => 25, 'rewrite_engine' => false);
     foreach ($default_data as $k => $v) {
         if (!isset($data[$k])) {
             $data[$k] = $v;
         }
     }
     Context::getContext()->shop = new Shop(1);
     Configuration::loadConfiguration();
     // use the old image system if the safe_mod is enabled otherwise the installer will fail with the fixtures installation
     if (InstallSession::getInstance()->safe_mode) {
         Configuration::updateGlobalValue('PS_LEGACY_IMAGES', 1);
     }
     $id_country = Country::getByIso($data['shop_country']);
     // Set default configuration
     Configuration::updateGlobalValue('PS_SHOP_DOMAIN', Tools::getHttpHost());
     Configuration::updateGlobalValue('PS_SHOP_DOMAIN_SSL', Tools::getHttpHost());
     Configuration::updateGlobalValue('PS_INSTALL_VERSION', _PS_INSTALL_VERSION_);
     Configuration::updateGlobalValue('PS_LOCALE_LANGUAGE', $this->language->getLanguageIso());
     Configuration::updateGlobalValue('PS_SHOP_NAME', $data['shop_name']);
     Configuration::updateGlobalValue('PS_SHOP_ACTIVITY', $data['shop_activity']);
     Configuration::updateGlobalValue('PS_COUNTRY_DEFAULT', $id_country);
     Configuration::updateGlobalValue('PS_LOCALE_COUNTRY', $data['shop_country']);
     Configuration::updateGlobalValue('PS_TIMEZONE', $data['shop_timezone']);
     Configuration::updateGlobalValue('PS_CONFIGURATION_AGREMENT', (int) $data['configuration_agrement']);
     // Set mails configuration
     Configuration::updateGlobalValue('PS_MAIL_METHOD', $data['use_smtp'] ? 2 : 1);
     Configuration::updateGlobalValue('PS_MAIL_SMTP_ENCRYPTION', $data['smtp_encryption']);
     Configuration::updateGlobalValue('PS_MAIL_SMTP_PORT', $data['smtp_port']);
     // Set default rewriting settings
     Configuration::updateGlobalValue('PS_REWRITING_SETTINGS', $data['rewrite_engine']);
     // Activate rijndael 128 encrypt algorihtm if mcrypt is activated
     Configuration::updateGlobalValue('PS_CIPHER_ALGORITHM', function_exists('mcrypt_encrypt') ? 1 : 0);
     $groups = Group::getGroups((int) Configuration::get('PS_LANG_DEFAULT'));
     $groups_default = Db::getInstance()->executeS('SELECT `name` FROM ' . _DB_PREFIX_ . 'configuration WHERE `name` LIKE "PS_%_GROUP" ORDER BY `id_configuration`');
     foreach ($groups_default as &$group_default) {
         if (is_array($group_default) && isset($group_default['name'])) {
             $group_default = $group_default['name'];
         }
     }
     if (is_array($groups) && count($groups)) {
         foreach ($groups as $key => $group) {
             if (Configuration::get($groups_default[$key]) != $groups[$key]['id_group']) {
                 Configuration::updateGlobalValue($groups_default[$key], (int) $groups[$key]['id_group']);
             }
         }
     }
     $states = Db::getInstance()->executeS('SELECT `id_order_state` FROM ' . _DB_PREFIX_ . 'order_state ORDER by `id_order_state`');
     $states_default = Db::getInstance()->executeS('SELECT MIN(`id_configuration`), `name` FROM ' . _DB_PREFIX_ . 'configuration WHERE `name` LIKE "PS_OS_%" GROUP BY `value` ORDER BY`id_configuration`');
     foreach ($states_default as &$state_default) {
         if (is_array($state_default) && isset($state_default['name'])) {
             $state_default = $state_default['name'];
         }
     }
     if (is_array($states) && count($states)) {
         foreach ($states as $key => $state) {
             if (Configuration::get($states_default[$key]) != $states[$key]['id_order_state']) {
                 Configuration::updateGlobalValue($states_default[$key], (int) $states[$key]['id_order_state']);
             }
         }
         /* deprecated order state */
         Configuration::updateGlobalValue('PS_OS_OUTOFSTOCK_PAID', (int) Configuration::get('PS_OS_OUTOFSTOCK'));
     }
     // Set logo configuration
     if (file_exists(_PS_IMG_DIR_ . 'logo.jpg')) {
         list($width, $height) = getimagesize(_PS_IMG_DIR_ . 'logo.jpg');
         Configuration::updateGlobalValue('SHOP_LOGO_WIDTH', round($width));
         Configuration::updateGlobalValue('SHOP_LOGO_HEIGHT', round($height));
     }
     // Disable cache for debug mode
     if (_PS_MODE_DEV_) {
         Configuration::updateGlobalValue('PS_SMARTY_CACHE', 1);
     }
     // Active only the country selected by the merchant
     Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'country SET active = 0 WHERE id_country != ' . (int) $id_country);
     // Set localization configuration
     $version = str_replace('.', '', _PS_VERSION_);
     $version = substr($version, 0, 2);
     $localization_file_content = $this->getLocalizationPackContent($version, $data['shop_country']);
     $locale = new LocalizationPackCore();
     $locale->loadLocalisationPack($localization_file_content, '', true);
     // Create default employee
     if (isset($data['admin_firstname']) && isset($data['admin_lastname']) && isset($data['admin_password']) && isset($data['admin_email'])) {
         $employee = new Employee();
         $employee->firstname = Tools::ucfirst($data['admin_firstname']);
         $employee->lastname = Tools::ucfirst($data['admin_lastname']);
         $employee->email = $data['admin_email'];
         $employee->passwd = md5(_COOKIE_KEY_ . $data['admin_password']);
         $employee->last_passwd_gen = date('Y-m-d h:i:s', strtotime('-360 minutes'));
         $employee->bo_theme = 'default';
         $employee->default_tab = 1;
         $employee->active = true;
         $employee->optin = (bool) $data['send_informations'];
         $employee->id_profile = 1;
         $employee->id_lang = Configuration::get('PS_LANG_DEFAULT');
         $employee->bo_menu = 1;
         if (!$employee->add()) {
             $this->setError($this->language->l('Cannot create admin account'));
             return false;
         }
     } else {
         $this->setError($this->language->l('Cannot create admin account'));
         return false;
     }
     // Update default contact
     if (isset($data['admin_email'])) {
         Configuration::updateGlobalValue('PS_SHOP_EMAIL', $data['admin_email']);
         $contacts = new PrestaShopCollection('Contact');
         foreach ($contacts as $contact) {
             $contact->email = $data['admin_email'];
             $contact->update();
         }
     }
     if (!@Tools::generateHtaccess(null, $data['rewrite_engine'])) {
         Configuration::updateGlobalValue('PS_REWRITING_SETTINGS', 0);
     }
     return true;
 }