diff --git a/admin-dev/tabs/AdminContact.php b/admin-dev/tabs/AdminContact.php
index 87c7d2602..cfba3ebdb 100644
--- a/admin-dev/tabs/AdminContact.php
+++ b/admin-dev/tabs/AdminContact.php
@@ -34,14 +34,13 @@ class AdminContact extends AdminPreferences
{
$this->className = 'Configuration';
$this->table = 'configuration';
-
- $temporyArrayFields = $this->_getDefaultFieldsContent();
- $this->_buildOrderedFieldsShop($temporyArrayFields);
parent::__construct();
+ $temporyArrayFields = $this->_getDefaultFieldsContent();
+ $this->_buildOrderedFieldsShop($temporyArrayFields);
}
-
+
private function _getDefaultFieldsContent()
{
$this->context = Context::getContext();
@@ -82,49 +81,64 @@ class AdminContact extends AdminPreferences
'PS_SHOP_COUNTRY_ID' => 'Country:name',
'PS_SHOP_PHONE' => 'phone');
- $this->_fieldsShop = array();
+ $fields = array();
$orderedFields = AddressFormat::getOrderedAddressFields(Configuration::get('PS_SHOP_COUNTRY_ID'), false, true);
foreach($orderedFields as $lineFields)
if (($patterns = explode(' ', $lineFields)))
foreach($patterns as $pattern)
if (($key = array_search($pattern, $associatedOrderKey)))
- $this->_fieldsShop[$key] = $formFields[$key];
+ $fields[$key] = $formFields[$key];
foreach($formFields as $key => $value)
- if (!isset($this->_fieldsShop[$key]))
- $this->_fieldsShop[$key] = $formFields[$key];
+ if (!isset($fields[$key]))
+ $fields[$key] = $formFields[$key];
+
+ $this->optionsList = array(
+ 'general' => array(
+ 'title' => $this->l('Contact details'),
+ 'icon' => 'tab-contact',
+ 'class' => 'width3',
+ 'fields' => $fields,
+ ),
+ );
}
-
- public function postProcess()
+
+ public function beforeUpdateOptions()
{
if (isset($_POST['PS_SHOP_STATE_ID']) && $_POST['PS_SHOP_STATE_ID'] != '0')
{
- $isStateOk = Db::getInstance()->getValue('SELECT `active` FROM `'._DB_PREFIX_.'state` WHERE `id_country` = '.(int)(Tools::getValue('PS_SHOP_COUNTRY_ID')).' AND `id_state` = '.(int)(Tools::getValue('PS_SHOP_STATE_ID')));
+ $sql = 'SELECT `active` FROM `'._DB_PREFIX_.'state`
+ WHERE `id_country` = '.(int)Tools::getValue('PS_SHOP_COUNTRY_ID').'
+ AND `id_state` = '.(int)Tools::getValue('PS_SHOP_STATE_ID');
+ $isStateOk = Db::getInstance()->getValue($sql);
if ($isStateOk != 1)
$this->_errors[] = Tools::displayError('This state is not in this country.');
}
- parent::postProcess();
}
- protected function _postConfig($fields)
+ public function updateOptionPsShopCountryId($value)
{
- if (!$this->_errors && isset($_POST['PS_SHOP_COUNTRY_ID']))
+ if (!$this->_errors && $value)
{
- $country = new Country($_POST['PS_SHOP_COUNTRY_ID'], $this->context->language->id);
- Configuration::updateValue('PS_SHOP_COUNTRY', pSQL($country->name));
+ $country = new Country($value, $this->context->language->id);
+ if ($country->id)
+ {
+ Configuration::updateValue('PS_SHOP_COUNTRY_ID', $value);
+ Configuration::updateValue('PS_SHOP_COUNTRY', pSQL($country->name));
+ }
}
- if (!$this->_errors && isset($_POST['PS_SHOP_STATE_ID']))
- {
- $state = new State((int)($_POST['PS_SHOP_STATE_ID']));
- Configuration::updateValue('PS_SHOP_STATE', pSQL($state->name));
- }
- parent::_postConfig($fields);
}
-
- public function display()
+
+ public function updateOptionPsShopStateId($value)
{
- $this->_displayForm('shop', $this->_fieldsShop, $this->l('Contact details'), 'width3', 'tab-contact');
+ if (!$this->_errors && $value)
+ {
+ $state = new State($value);
+ if ($state->id)
+ {
+ Configuration::updateValue('PS_SHOP_STATE_ID', $value);
+ Configuration::updateValue('PS_SHOP_STATE', pSQL($state->name));
+ }
+ }
}
}
-
-
diff --git a/admin-dev/tabs/AdminDb.php b/admin-dev/tabs/AdminDb.php
index fb276e67e..c0846e4bd 100644
--- a/admin-dev/tabs/AdminDb.php
+++ b/admin-dev/tabs/AdminDb.php
@@ -33,14 +33,23 @@ class AdminDb extends AdminPreferences
{
$this->className = 'Configuration';
$this->table = 'configuration';
-
- $this->_fieldsDatabase = array(
- 'db_server' => array('title' => $this->l('Server:'), 'desc' => $this->l('IP or server name; \'localhost\' will work in most cases'), 'size' => 30, 'type' => 'text', 'required' => true, 'visibility' => Shop::CONTEXT_ALL),
- 'db_name' => array('title' => $this->l('Database:'), 'desc' => $this->l('Database name (e.g., \'prestashop\')'), 'size' => 30, 'type' => 'text', 'required' => true, 'visibility' => Shop::CONTEXT_ALL),
- 'db_prefix' => array('title' => $this->l('Prefix:'), 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL),
- 'db_user' => array('title' => $this->l('User:'), 'size' => 30, 'type' => 'text', 'required' => true, 'visibility' => Shop::CONTEXT_ALL),
- 'db_passwd' => array('title' => $this->l('Password:'), 'size' => 30, 'type' => 'password', 'desc' => $this->l('Leave blank if no change')), 'visibility' => Shop::CONTEXT_ALL);
+
parent::__construct();
+
+ $this->optionsList = array(
+ 'database' => array(
+ 'title' => $this->l('Database'),
+ 'icon' => 'database_gear',
+ 'class' => 'width2',
+ 'fields' => array(
+ 'db_server' => array('title' => $this->l('Server:'), 'desc' => $this->l('IP or server name; \'localhost\' will work in most cases'), 'size' => 30, 'type' => 'text', 'required' => true, 'defaultValue' => _DB_SERVER_, 'visibility' => Shop::CONTEXT_ALL),
+ 'db_name' => array('title' => $this->l('Database:'), 'desc' => $this->l('Database name (e.g., \'prestashop\')'), 'size' => 30, 'type' => 'text', 'required' => true, 'defaultValue' => _DB_NAME_, 'visibility' => Shop::CONTEXT_ALL),
+ 'db_prefix' => array('title' => $this->l('Prefix:'), 'size' => 30, 'type' => 'text', 'defaultValue' => _DB_PREFIX_, 'visibility' => Shop::CONTEXT_ALL),
+ 'db_user' => array('title' => $this->l('User:'), 'size' => 30, 'type' => 'text', 'required' => true, 'defaultValue' => _DB_USER_, 'visibility' => Shop::CONTEXT_ALL),
+ 'db_passwd' => array('title' => $this->l('Password:'), 'size' => 30, 'type' => 'password', 'desc' => $this->l('Leave blank if no change'), 'defaultValue' => _DB_PASSWD_, 'visibility' => Shop::CONTEXT_ALL),
+ ),
+ ),
+ );
}
public function postProcess()
@@ -49,7 +58,7 @@ class AdminDb extends AdminPreferences
{
if ($this->tabAccess['edit'] === '1')
{
- foreach ($this->_fieldsDatabase AS $field => $values)
+ foreach ($this->optionsList['database']['fields'] AS $field => $values)
if (isset($values['required']) AND $values['required'])
if (($value = Tools::getValue($field)) == false AND (string)$value != '0')
$this->_errors[] = Tools::displayError('field').' '.$values['title'].' '.Tools::displayError('is required.');
@@ -58,8 +67,8 @@ class AdminDb extends AdminPreferences
{
/* Datas are not saved in database but in config/settings.inc.php */
$settings = array();
- foreach ($_POST as $k => $value)
- if ($value)
+ foreach ($this->optionsList['database']['fields'] as $k => $data)
+ if ($value = Tools::getValue($k))
$settings['_'.Tools::strtoupper($k).'_'] = $value;
rewriteSettingsFile(NULL, NULL, $settings);
Tools::redirectAdmin(self::$currentIndex.'&conf=6'.'&token='.$this->token);
@@ -68,6 +77,7 @@ class AdminDb extends AdminPreferences
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
+
if (Tools::isSubmit('submitEngine'))
{
if (!isset($_POST['tablesBox']) OR !sizeof($_POST['tablesBox']))
@@ -84,6 +94,7 @@ class AdminDb extends AdminPreferences
$engineType = pSQL(Tools::getValue('engineType'));
/* Datas are not saved in database but in config/settings.inc.php */
+ // @todo add a Db::trytoconnect()
$settings = array('_MYSQL_ENGINE_' => $engineType);
rewriteSettingsFile(NULL, NULL, $settings);
@@ -105,7 +116,7 @@ class AdminDb extends AdminPreferences
public function display()
{
echo $this->displayWarning($this->l('Be VERY CAREFUL with these settings, as changes may cause your PrestaShop online store to malfunction. For all issues, check the config/settings.inc.php file.')).'
';
- $this->_displayForm('database', $this->_fieldsDatabase, $this->l('Database'), 'width2', 'database_gear');
+ $this->displayOptionsList();
$engines = $this->_getEngines();
$irow = 0;
echo '