From bcd83acb8b28368e42d8d815aca8efcfa7c16da8 Mon Sep 17 00:00:00 2001 From: rMalie Date: Fri, 5 Aug 2011 13:21:40 +0000 Subject: [PATCH] // Refactoring of preferences --- admin-dev/tabs/AdminContact.php | 68 ++-- admin-dev/tabs/AdminDb.php | 33 +- admin-dev/tabs/AdminEmails.php | 75 ++-- admin-dev/tabs/AdminLocalization.php | 49 ++- admin-dev/tabs/AdminPDF.php | 53 +-- admin-dev/tabs/AdminPPreferences.php | 95 +++-- admin-dev/tabs/AdminPreferences.php | 581 ++++++--------------------- admin-dev/tabs/AdminSearchConf.php | 125 +++--- admin-dev/tabs/AdminStatsConf.php | 131 +++--- admin-dev/tabs/AdminStatsTab.php | 14 +- admin-dev/tabs/AdminThemes.php | 143 +++++-- classes/AdminTab.php | 536 ++++++++++++++++-------- js/admin.js | 26 +- 13 files changed, 961 insertions(+), 968 deletions(-) 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 '
'.$this->l('MySQL Engine').'
diff --git a/admin-dev/tabs/AdminEmails.php b/admin-dev/tabs/AdminEmails.php index 0f2480dd0..1a141f30f 100644 --- a/admin-dev/tabs/AdminEmails.php +++ b/admin-dev/tabs/AdminEmails.php @@ -39,39 +39,40 @@ class AdminEmails extends AdminPreferences foreach (Contact::getContacts($this->context->language->id) AS $contact) $arr[] = array('email_message' => $contact['id_contact'], 'name' => $contact['name']); - $this->_fieldsEmail = array( - 'PS_MAIL_EMAIL_MESSAGE' => array('title' => $this->l('Send e-mail to:'), 'desc' => $this->l('When customers send message from order page'), 'validation' => 'isUnsignedId', 'type' => 'select', 'cast' => 'intval', 'identifier' => 'email_message', 'list' => $arr), - 'PS_MAIL_METHOD' => array('title' => '', 'validation' => 'isGenericName', 'required' => true, 'type' => 'radio', 'choices' => array(1 => $this->l('Use PHP mail() function. Recommended; works in most cases'), 2 => $this->l('Set my own SMTP parameters. For advanced users ONLY')), 'js' => array(1 => 'onclick="$(\'#SMTP_CONTAINER\').slideUp();"', 2 => 'onclick="$(\'#SMTP_CONTAINER\').slideDown();"'), 'visibility' => Shop::CONTEXT_ALL), - 'PS_MAIL_TYPE' => array('title' => '', 'validation' => 'isGenericName', 'required' => true, 'type' => 'radio', 'choices' => array(1 => $this->l('Send e-mail as HTML'), 2 => $this->l('Send e-mail as Text'), 3 => $this->l('Both'))), - 'SMTP_CONTAINER' => array('title' => '', 'type' => 'container'), - 'PS_MAIL_DOMAIN' => array('title' => $this->l('Mail domain:'), 'desc' => $this->l('Fully qualified domain name (keep it empty if you do not know)'), 'validation' => 'isUrl', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), - 'PS_MAIL_SERVER' => array('title' => $this->l('SMTP server:'), 'desc' => $this->l('IP or server name (e.g., smtp.mydomain.com)'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), - 'PS_MAIL_USER' => array('title' => $this->l('SMTP user:'), 'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), - 'PS_MAIL_PASSWD' => array('title' => $this->l('SMTP password:'), 'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isAnything', 'size' => 30, 'type' => 'password', 'visibility' => Shop::CONTEXT_ALL), - 'PS_MAIL_SMTP_ENCRYPTION' => array('title' => $this->l('Encryption:'), 'desc' => $this->l('Use an encrypt protocol'), 'type' => 'select', 'cast' => 'strval', 'identifier' => 'mode', 'list' => array(array('mode' => 'off', 'name' => $this->l('None')), array('mode' => 'tls', 'name' => $this->l('TLS')), array('mode' => 'ssl', 'name' => $this->l('SSL'))), 'visibility' => Shop::CONTEXT_ALL), - 'PS_MAIL_SMTP_PORT' => array('title' => $this->l('Port:'), 'desc' => $this->l('Number of port to use'), 'validation' => 'isInt', 'size' => 5, 'type' => 'text', 'cast' => 'intval', 'visibility' => Shop::CONTEXT_ALL), - 'SMTP_CONTAINER_END' => array('title' => '', 'type' => 'container_end', 'content' => ''), + $this->optionsList = array( + 'email' => array( + 'title' => $this->l('E-mail'), + 'icon' => 'email', + 'fields' => array( + 'PS_MAIL_EMAIL_MESSAGE' => array('title' => $this->l('Send e-mail to:'), 'desc' => $this->l('When customers send message from order page'), 'validation' => 'isUnsignedId', 'type' => 'select', 'cast' => 'intval', 'identifier' => 'email_message', 'list' => $arr), + 'PS_MAIL_METHOD' => array('title' => '', 'validation' => 'isGenericName', 'type' => 'radio', 'required' => true, 'choices' => array(1 => $this->l('Use PHP mail() function. Recommended; works in most cases'), 2 => $this->l('Set my own SMTP parameters. For advanced users ONLY')), 'js' => array(1 => 'onclick="$(\'#smtp\').slideUp();"', 2 => 'onclick="$(\'#smtp\').slideDown();"'), 'visibility' => Shop::CONTEXT_ALL), + 'PS_MAIL_TYPE' => array('title' => '', 'validation' => 'isGenericName', 'type' => 'radio', 'required' => true, 'choices' => array(1 => $this->l('Send e-mail as HTML'), 2 => $this->l('Send e-mail as Text'), 3 => $this->l('Both'))), + ), + ), + 'smtp' => array( + 'title' => $this->l('E-mail'), + 'icon' => 'email', + 'fields' => array( + 'PS_MAIL_DOMAIN' => array('title' => $this->l('Mail domain:'), 'desc' => $this->l('Fully qualified domain name (keep it empty if you do not know)'), 'validation' => 'isUrl', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), + 'PS_MAIL_SERVER' => array('title' => $this->l('SMTP server:'), 'desc' => $this->l('IP or server name (e.g., smtp.mydomain.com)'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), + 'PS_MAIL_USER' => array('title' => $this->l('SMTP user:'), 'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), + 'PS_MAIL_PASSWD' => array('title' => $this->l('SMTP password:'), 'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isAnything', 'size' => 30, 'type' => 'password', 'visibility' => Shop::CONTEXT_ALL), + 'PS_MAIL_SMTP_ENCRYPTION' => array('title' => $this->l('Encryption:'), 'desc' => $this->l('Use an encrypt protocol'), 'type' => 'select', 'cast' => 'strval', 'identifier' => 'mode', 'list' => array(array('mode' => 'off', 'name' => $this->l('None')), array('mode' => 'tls', 'name' => $this->l('TLS')), array('mode' => 'ssl', 'name' => $this->l('SSL'))), 'visibility' => Shop::CONTEXT_ALL), + 'PS_MAIL_SMTP_PORT' => array('title' => $this->l('Port:'), 'desc' => $this->l('Number of port to use'), 'validation' => 'isInt', 'size' => 5, 'type' => 'text', 'cast' => 'intval', 'visibility' => Shop::CONTEXT_ALL), + ), + ), ); } - - public function postProcess() + + public function beforeUpdateOptions() { - if (isset($_POST['submitEmail'.$this->table])) - { - if ($this->tabAccess['edit'] === '1') - { - if ($_POST['PS_MAIL_METHOD'] == 2 AND (empty($_POST['PS_MAIL_SERVER']) OR empty($_POST['PS_MAIL_SMTP_PORT']))) - $this->_errors[] = Tools::displayError('You must define a SMTP server and a SMTP port. If you do not know, use the PHP mail() function instead.'); - else - $this->_postConfig($this->_fieldsEmail); - } - else - $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); - } + if ($_POST['PS_MAIL_METHOD'] == 2 AND (empty($_POST['PS_MAIL_SERVER']) OR empty($_POST['PS_MAIL_SMTP_PORT']))) + $this->_errors[] = Tools::displayError('You must define a SMTP server and a SMTP port. If you do not know, use the PHP mail() function instead.'); } - public function display() { - $this->_displayForm('email', $this->_fieldsEmail, $this->l('E-mail'), 'width2', 'email'); + public function display() + { + parent::display(); $this->_displayMailTest(); } @@ -104,4 +105,22 @@ class AdminEmails extends AdminPreferences '; } + + public function displayTopOptionCategory($category, $categoryData) + { + if ($category == 'smtp') + echo '
'; + } + + public function displayBottomOptionCategory($category, $categoryData) + { + if ($category == 'smtp') + echo ' +
'; + } } diff --git a/admin-dev/tabs/AdminLocalization.php b/admin-dev/tabs/AdminLocalization.php index e01737ef7..6586255e2 100644 --- a/admin-dev/tabs/AdminLocalization.php +++ b/admin-dev/tabs/AdminLocalization.php @@ -34,29 +34,35 @@ class AdminLocalization extends AdminPreferences $this->className = 'Configuration'; $this->table = 'configuration'; - $this->_fieldsLocalization = array( - 'PS_WEIGHT_UNIT' => array('title' => $this->l('Weight unit:'), 'desc' => $this->l('The weight unit of your shop (eg. kg or lbs)'), 'validation' => 'isWeightUnit', 'required' => true, 'type' => 'text'), - 'PS_DISTANCE_UNIT' => array('title' => $this->l('Distance unit:'), 'desc' => $this->l('The distance unit of your shop (eg. km or mi)'), 'validation' => 'isDistanceUnit', 'required' => true, 'type' => 'text'), - 'PS_VOLUME_UNIT' => array('title' => $this->l('Volume unit:'), 'desc' => $this->l('The volume unit of your shop'), 'validation' => 'isWeightUnit', 'required' => true, 'type' => 'text'), - 'PS_DIMENSION_UNIT' => array('title' => $this->l('Dimension unit:'), 'desc' => $this->l('The dimension unit of your shop (eg. cm or in)'), 'validation' => 'isDistanceUnit', 'required' => true, 'type' => 'text')); - $this->_fieldsOptions = array( - 'PS_LOCALE_LANGUAGE' => array('title' => $this->l('Language locale:'), 'desc' => $this->l('Your server\'s language locale.'), 'validation' => 'isLanguageIsoCode', 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), - 'PS_LOCALE_COUNTRY' => array('title' => $this->l('Country locale:'), 'desc' => $this->l('Your server\'s country locale.'), 'validation' => 'isLanguageIsoCode', 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL) - ); - parent::__construct(); + + $this->optionsList = array( + 'localization' => array( + 'title' => $this->l('Localization'), + 'width' => 'width2', + 'icon' => 'localization', + 'fields' => array( + 'PS_WEIGHT_UNIT' => array('title' => $this->l('Weight unit:'), 'desc' => $this->l('The weight unit of your shop (eg. kg or lbs)'), 'validation' => 'isWeightUnit', 'required' => true, 'type' => 'text'), + 'PS_DISTANCE_UNIT' => array('title' => $this->l('Distance unit:'), 'desc' => $this->l('The distance unit of your shop (eg. km or mi)'), 'validation' => 'isDistanceUnit', 'required' => true, 'type' => 'text'), + 'PS_VOLUME_UNIT' => array('title' => $this->l('Volume unit:'), 'desc' => $this->l('The volume unit of your shop'), 'validation' => 'isWeightUnit', 'required' => true, 'type' => 'text'), + 'PS_DIMENSION_UNIT' => array('title' => $this->l('Dimension unit:'), 'desc' => $this->l('The dimension unit of your shop (eg. cm or in)'), 'validation' => 'isDistanceUnit', 'required' => true, 'type' => 'text'), + ), + ), + 'options' => array( + 'title' => $this->l('Advanced'), + 'width' => 'width2', + 'icon' => 'localization', + 'fields' => array( + 'PS_LOCALE_LANGUAGE' => array('title' => $this->l('Language locale:'), 'desc' => $this->l('Your server\'s language locale.'), 'validation' => 'isLanguageIsoCode', 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), + 'PS_LOCALE_COUNTRY' => array('title' => $this->l('Country locale:'), 'desc' => $this->l('Your server\'s country locale.'), 'validation' => 'isLanguageIsoCode', 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL) + ), + ), + ); } public function postProcess() { - if (isset($_POST['submitLocalization'.$this->table])) - { - if ($this->tabAccess['edit'] === '1') - $this->_postConfig($this->_fieldsLocalization); - else - $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); - } - elseif (Tools::isSubmit('submitLocalizationPack')) + if (Tools::isSubmit('submitLocalizationPack')) { if (!$pack = @Tools::file_get_contents('http://www.prestashop.com/download/localization/'.Tools::getValue('iso_localization_pack').'.xml') AND !$pack = @Tools::file_get_contents(dirname(__FILE__).'/../../localization/'.Tools::getValue('iso_localization_pack').'.xml')) $this->_errors[] = Tools::displayError('Cannot load localization pack (from prestashop.com and from your local folder "localization")'); @@ -76,15 +82,15 @@ class AdminLocalization extends AdminPreferences else Tools::redirectAdmin(self::$currentIndex.'&conf=23&token='.$this->token); } - - } + parent::postProcess(); } public function display() { - $this->_displayForm('localization', $this->_fieldsLocalization, $this->l('Localization'), 'width2', 'localization'); + $this->displayOptionsList(); + echo '
@@ -122,6 +128,5 @@ class AdminLocalization extends AdminPreferences

'; - $this->_displayForm('options', $this->_fieldsOptions, $this->l('Advanced'), 'width2', 'localization'); } } diff --git a/admin-dev/tabs/AdminPDF.php b/admin-dev/tabs/AdminPDF.php index 0f4da987c..155a6ea07 100644 --- a/admin-dev/tabs/AdminPDF.php +++ b/admin-dev/tabs/AdminPDF.php @@ -33,6 +33,8 @@ class AdminPDF extends AdminPreferences { $this->className = 'Configuration'; $this->table = 'configuration'; + + parent::__construct(); /* Collect all font files and build array for combo box */ $fontFiles = scandir(_PS_FPDF_PATH_.'font'); @@ -59,41 +61,44 @@ class AdminPDF extends AdminPreferences array_push($encodingList, $arr); } - $this->_fieldsPDF = array( - 'PS_PDF_ENCODING' => array( - 'title' => $this->l('Encoding:'), - 'desc' => $this->l('Encoding for PDF invoice'), - 'type' => 'selectLang', - 'cast' => 'strval', - 'identifier' => 'mode', - 'list' => $encodingList), - 'PS_PDF_FONT' => array( - 'title' => $this->l('Font:'), - 'desc' => $this->l('Font for PDF invoice'), - 'type' => 'selectLang', - 'cast' => 'strval', - 'identifier' => 'mode', - 'list' => $fontList) + $this->optionsList = array( + 'PDF' => array( + 'title' => $this->l('PDF settings for the current language:').' '.$this->context->language->name, + 'icon' => 'pdf', + 'class' => 'width2', + 'fields' => array( + 'PS_PDF_ENCODING' => array( + 'title' => $this->l('Encoding:'), + 'desc' => $this->l('Encoding for PDF invoice'), + 'type' => 'selectLang', + 'cast' => 'strval', + 'identifier' => 'mode', + 'list' => $encodingList), + 'PS_PDF_FONT' => array( + 'title' => $this->l('Font:'), + 'desc' => $this->l('Font for PDF invoice'), + 'type' => 'selectLang', + 'cast' => 'strval', + 'identifier' => 'mode', + 'list' => $fontList), + ), + ), ); - - parent::__construct(); } public function postProcess() { if (isset($_POST['submitPDF'.$this->table])) { + // @todo automatize selectLang post process $fieldLangPDF = array(); $languages = Language::getLanguages(false); - foreach ($this->_fieldsPDF as $field => $fieldvalue) + foreach ($this->optionsList['PDF']['fields'] as $field => $fieldvalue) foreach ($languages as $lang) if (Tools::getValue($field.'_'.strtoupper($lang['iso_code']))) - $fieldLangPDF[$field.'_'.strtoupper($lang['iso_code'])] = array('type' => 'select', 'cast' => 'strval', 'identifier' => 'mode', 'list' => $fieldvalue['list']); + $this->optionsList['PDF']['fields'][$field.'_'.strtoupper($lang['iso_code'])] = array('type' => 'select', 'cast' => 'strval', 'identifier' => 'mode', 'list' => $fieldvalue['list']); - if ($this->tabAccess['edit'] === '1') - $this->_postConfig($fieldLangPDF); - else - $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); + parent::postProcess(); } } @@ -101,6 +106,6 @@ class AdminPDF extends AdminPreferences { if (!Validate::isLoadedObject($this->context->language)) die(Tools::displayError()); - $this->_displayForm('PDF', $this->_fieldsPDF, $this->l('PDF settings for the current language:').' '.$this->context->language->name, 'width2', 'pdf'); + $this->displayOptionsList(); } } diff --git a/admin-dev/tabs/AdminPPreferences.php b/admin-dev/tabs/AdminPPreferences.php index 07badc905..e13944dd9 100644 --- a/admin-dev/tabs/AdminPPreferences.php +++ b/admin-dev/tabs/AdminPPreferences.php @@ -33,65 +33,60 @@ class AdminPPreferences extends AdminPreferences { $this->className = 'Configuration'; $this->table = 'configuration'; - - $this->_fieldsProduct = array( - 'PS_CATALOG_MODE' => array('title' => $this->l('Catalog mode:'), 'desc' => $this->l('When active, all features for shopping will be disabled'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => true, 'type' => 'bool'), - 'PS_ORDER_OUT_OF_STOCK' => array('title' => $this->l('Allow ordering out-of-stock product:'), 'desc' => $this->l('Add to cart button is hidden when product is unavailable'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => true, 'type' => 'bool'), - 'PS_STOCK_MANAGEMENT' => array('title' => $this->l('Enable stock management:'), 'desc' => '', 'validation' => 'isBool', 'cast' => 'intval', 'required' => true, 'type' => 'bool', 'js' => array('on' => 'onchange="stockManagementActivationAuthorization()"', 'off' => 'onchange="stockManagementActivationAuthorization()"')), - 'PS_DISPLAY_QTIES' => array('title' => $this->l('Display available quantities on product page:'), 'desc' => '', 'validation' => 'isBool', 'cast' => 'intval', 'required' => true, 'type' => 'bool'), - 'PS_DISPLAY_JQZOOM' => array('title' => $this->l('Enable JqZoom instead of Thickbox on product page:'), 'desc' => '', 'validation' => 'isBool', 'cast' => 'intval', 'required' => true, 'type' => 'bool'), - 'PS_DISP_UNAVAILABLE_ATTR' => array('title' => $this->l('Display unavailable product attributes on product page:'), 'desc' => '', 'validation' => 'isBool', 'cast' => 'intval', 'required' => true, 'type' => 'bool'), - 'PS_ATTRIBUTE_CATEGORY_DISPLAY' => array('title' => $this->l('Display "add to cart" button when product has attributes:'), 'desc' => $this->l('Display or hide the "add to cart" button on category pages for products that have attributes to force customers to see the product detail'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), - 'PS_COMPARATOR_MAX_ITEM' => array('title' => $this->l('Max items in the comparator:'), 'desc' => $this->l('Set to 0 to disable this feature'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text'), - 'PS_PURCHASE_MINIMUM' => array('title' => $this->l('Minimum purchase total required in order to validate order:'), 'desc' => $this->l('Set to 0 to disable this feature'), 'validation' => 'isFloat', 'cast' => 'floatval', 'type' => 'price'), - 'PS_LAST_QTIES' => array('title' => $this->l('Display last quantities when qty is lower than:'), 'desc' => $this->l('Set to 0 to disable this feature'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text'), - 'PS_NB_DAYS_NEW_PRODUCT' => array('title' => $this->l('Number of days during which the product is considered \'new\':'), 'validation' => 'isUnsignedInt', 'cast' => 'intval', 'type' => 'text'), - 'PS_CART_REDIRECT' => array('title' => $this->l('Re-direction after adding product to cart:'), 'desc' => $this->l('Concerns only the non-AJAX version of the cart'), 'cast' => 'intval', 'show' => true, 'required' => true, 'type' => 'radio', 'validation' => 'isBool', 'choices' => array(0 => $this->l('previous page'), 1 => $this->l('cart summary'))), - 'PS_PRODUCTS_PER_PAGE' => array('title' => $this->l('Products per page:'), 'desc' => $this->l('Products displayed per page. Default is 10.'), 'validation' => 'isUnsignedInt', 'cast' => 'intval', 'type' => 'text'), - 'PS_PRODUCTS_ORDER_BY' => array('title' => $this->l('Default order by:'), 'desc' => $this->l('Default order by for product list'), 'type' => 'select', 'list' => - array( - array('id' => '0', 'name' => $this->l('Product name')), - array('id' => '1', 'name' => $this->l('Product price')), - array('id' => '2', 'name' => $this->l('Product added date')), - array('id' => '4', 'name' => $this->l('Position inside category')), - array('id' => '5', 'name' => $this->l('Manufacturer')), - array('id' => '3', 'name' => $this->l('Product modified date')) - ), 'identifier' => 'id'), - 'PS_PRODUCTS_ORDER_WAY' => array('title' => $this->l('Default order way:'), 'desc' => $this->l('Default order way for product list'), 'type' => 'select', 'list' => array(array('id' => '0', 'name' => $this->l('Ascending')), array('id' => '1', 'name' => $this->l('Descending'))), 'identifier' => 'id'), - 'PS_PRODUCT_SHORT_DESC_LIMIT' => array('title' => $this->l('Short description max size'), 'desc' => $this->l('Set the maximum size of product short description'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'text'), - 'PS_IMAGE_GENERATION_METHOD' => array('title' => $this->l('Image generated by:'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'select', 'list' => array(array('id' => '0', 'name' => $this->l('auto')), array('id' => '1', 'name' => $this->l('width')), array('id' => '2', 'name' => $this->l('height'))), 'identifier' => 'id', 'visibility' => Shop::CONTEXT_ALL), - 'PS_PRODUCT_PICTURE_MAX_SIZE' => array('title' => $this->l('Maximum size of product pictures:'), 'desc' => $this->l('The maximum size of pictures uploadable by customers (in Bytes)'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), - 'PS_PRODUCT_PICTURE_WIDTH' => array('title' => $this->l('Product pictures width:'), 'desc' => $this->l('The maximum width of pictures uploadable by customers'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), - 'PS_PRODUCT_PICTURE_HEIGHT' => array('title' => $this->l('Product pictures height:'), 'desc' => $this->l('The maximum height of pictures uploadable by customers'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), - 'PS_LEGACY_IMAGES' => array('title' => $this->l('Use the legacy image filesystem:'), 'desc' => $this->l('This should be set to yes unless you successfully moved images in Preferences > Images tab'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => true, 'type' => 'bool', 'visibility' => Shop::CONTEXT_ALL), - ); - + parent::__construct(); + + $this->optionsList = array( + 'products' => array( + 'title' => $this->l('Products'), + 'icon' => 'tab-orders', + 'class' => 'width3', + 'fields' => array( + 'PS_CATALOG_MODE' => array('title' => $this->l('Catalog mode:'), 'desc' => $this->l('When active, all features for shopping will be disabled'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => true, 'type' => 'bool'), + 'PS_ORDER_OUT_OF_STOCK' => array('title' => $this->l('Allow ordering out-of-stock product:'), 'desc' => $this->l('Add to cart button is hidden when product is unavailable'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => true, 'type' => 'bool'), + 'PS_STOCK_MANAGEMENT' => array('title' => $this->l('Enable stock management:'), 'desc' => '', 'validation' => 'isBool', 'cast' => 'intval', 'required' => true, 'type' => 'bool', 'js' => array('on' => 'onchange="stockManagementActivationAuthorization()"', 'off' => 'onchange="stockManagementActivationAuthorization()"')), + 'PS_DISPLAY_QTIES' => array('title' => $this->l('Display available quantities on product page:'), 'desc' => '', 'validation' => 'isBool', 'cast' => 'intval', 'required' => true, 'type' => 'bool'), + 'PS_DISPLAY_JQZOOM' => array('title' => $this->l('Enable JqZoom instead of Thickbox on product page:'), 'desc' => '', 'validation' => 'isBool', 'cast' => 'intval', 'required' => true, 'type' => 'bool'), + 'PS_DISP_UNAVAILABLE_ATTR' => array('title' => $this->l('Display unavailable product attributes on product page:'), 'desc' => '', 'validation' => 'isBool', 'cast' => 'intval', 'required' => true, 'type' => 'bool'), + 'PS_ATTRIBUTE_CATEGORY_DISPLAY' => array('title' => $this->l('Display "add to cart" button when product has attributes:'), 'desc' => $this->l('Display or hide the "add to cart" button on category pages for products that have attributes to force customers to see the product detail'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), + 'PS_COMPARATOR_MAX_ITEM' => array('title' => $this->l('Max items in the comparator:'), 'desc' => $this->l('Set to 0 to disable this feature'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text'), + 'PS_PURCHASE_MINIMUM' => array('title' => $this->l('Minimum purchase total required in order to validate order:'), 'desc' => $this->l('Set to 0 to disable this feature'), 'validation' => 'isFloat', 'cast' => 'floatval', 'type' => 'price'), + 'PS_LAST_QTIES' => array('title' => $this->l('Display last quantities when qty is lower than:'), 'desc' => $this->l('Set to 0 to disable this feature'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text'), + 'PS_NB_DAYS_NEW_PRODUCT' => array('title' => $this->l('Number of days during which the product is considered \'new\':'), 'validation' => 'isUnsignedInt', 'cast' => 'intval', 'type' => 'text'), + 'PS_CART_REDIRECT' => array('title' => $this->l('Re-direction after adding product to cart:'), 'desc' => $this->l('Concerns only the non-AJAX version of the cart'), 'cast' => 'intval', 'show' => true, 'required' => true, 'type' => 'radio', 'validation' => 'isBool', 'choices' => array(0 => $this->l('previous page'), 1 => $this->l('cart summary'))), + 'PS_PRODUCTS_PER_PAGE' => array('title' => $this->l('Products per page:'), 'desc' => $this->l('Products displayed per page. Default is 10.'), 'validation' => 'isUnsignedInt', 'cast' => 'intval', 'type' => 'text'), + 'PS_PRODUCTS_ORDER_BY' => array('title' => $this->l('Default order by:'), 'desc' => $this->l('Default order by for product list'), 'type' => 'select', 'list' => + array( + array('id' => '0', 'name' => $this->l('Product name')), + array('id' => '1', 'name' => $this->l('Product price')), + array('id' => '2', 'name' => $this->l('Product added date')), + array('id' => '4', 'name' => $this->l('Position inside category')), + array('id' => '5', 'name' => $this->l('Manufacturer')), + array('id' => '3', 'name' => $this->l('Product modified date')) + ), 'identifier' => 'id'), + 'PS_PRODUCTS_ORDER_WAY' => array('title' => $this->l('Default order way:'), 'desc' => $this->l('Default order way for product list'), 'type' => 'select', 'list' => array(array('id' => '0', 'name' => $this->l('Ascending')), array('id' => '1', 'name' => $this->l('Descending'))), 'identifier' => 'id'), + 'PS_PRODUCT_SHORT_DESC_LIMIT' => array('title' => $this->l('Short description max size'), 'desc' => $this->l('Set the maximum size of product short description'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'text'), + 'PS_IMAGE_GENERATION_METHOD' => array('title' => $this->l('Image generated by:'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'select', 'list' => array(array('id' => '0', 'name' => $this->l('auto')), array('id' => '1', 'name' => $this->l('width')), array('id' => '2', 'name' => $this->l('height'))), 'identifier' => 'id', 'visibility' => Shop::CONTEXT_ALL), + 'PS_PRODUCT_PICTURE_MAX_SIZE' => array('title' => $this->l('Maximum size of product pictures:'), 'desc' => $this->l('The maximum size of pictures uploadable by customers (in Bytes)'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), + 'PS_PRODUCT_PICTURE_WIDTH' => array('title' => $this->l('Product pictures width:'), 'desc' => $this->l('The maximum width of pictures uploadable by customers'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), + 'PS_PRODUCT_PICTURE_HEIGHT' => array('title' => $this->l('Product pictures height:'), 'desc' => $this->l('The maximum height of pictures uploadable by customers'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), + 'PS_LEGACY_IMAGES' => array('title' => $this->l('Use the legacy image filesystem:'), 'desc' => $this->l('This should be set to yes unless you successfully moved images in Preferences > Images tab'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => true, 'type' => 'bool', 'visibility' => Shop::CONTEXT_ALL), + ), + ), + ); } - public function postProcess() + public function beforeUpdateOptions() { - if (isset($_POST['submitProducts'.$this->table])) + if (!Tools::getValue('PS_STOCK_MANAGEMENT')) { - if ($this->tabAccess['add'] === '1') - { - if(!Tools::getValue('PS_STOCK_MANAGEMENT')) - { - $_POST['PS_ORDER_OUT_OF_STOCK'] = 1; - $_POST['PS_DISPLAY_QTIES'] = 0; - } - $this->_postConfig($this->_fieldsProduct); - } - else - $this->_errors[] = Tools::displayError('You do not have permission to add here.'); + $_POST['PS_ORDER_OUT_OF_STOCK'] = 1; + $_POST['PS_DISPLAY_QTIES'] = 0; } } - public function display() + public function displayBottomOptionCategory($category, $categoryData) { - $this->_displayForm('products', $this->_fieldsProduct, $this->l('Products'), 'width3', 'tab-orders'); echo ''; } } - - diff --git a/admin-dev/tabs/AdminPreferences.php b/admin-dev/tabs/AdminPreferences.php index 5c13c3b7a..370766932 100644 --- a/admin-dev/tabs/AdminPreferences.php +++ b/admin-dev/tabs/AdminPreferences.php @@ -33,501 +33,170 @@ class AdminPreferences extends AdminTab $this->className = 'Configuration'; $this->table = 'configuration'; - $timezones = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT name FROM '._DB_PREFIX_.'timezone'); - $taxes[] = array('id' => 0, 'name' => $this->l('None')); - foreach (Tax::getTaxes($this->context->language->id) as $tax) - $taxes[] = array('id' => $tax['id_tax'], 'name' => $tax['name']); - - $order_process_type = array( - array( - 'value' => PS_ORDER_PROCESS_STANDARD, - 'name' => $this->l('Standard (5 steps)') - ), - array( - 'value' => PS_ORDER_PROCESS_OPC, - 'name' => $this->l('One page checkout') - ) - ); - - $round_mode = array( - array( - 'value' => PS_ROUND_UP, - 'name' => $this->l('superior') - ), - array( - 'value' => PS_ROUND_DOWN, - 'name' => $this->l('inferior') - ), - array( - 'value' => PS_ROUND_HALF, - 'name' => $this->l('classical') - ) - ); - - $cms_tab = array(0 => - array( - 'id' => 0, - 'name' => $this->l('None') - ) - ); - foreach (CMS::listCms($this->context->language->id) as $cms_file) - $cms_tab[] = array('id' => $cms_file['id_cms'], 'name' => $cms_file['meta_title']); - $this->_fieldsGeneral = array( - 'PS_SHOP_ENABLE' => array('title' => $this->l('Enable Shop'), 'desc' => $this->l('Activate or deactivate your shop. Deactivate your shop while you perform maintenance on it. Please note that the webservice will not be disabled'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), - 'PS_MAINTENANCE_IP' => array('title' => $this->l('Maintenance IP'), 'desc' => $this->l('IP addresses allowed to access the Front Office even if shop is disabled. Use a comma to separate them (e.g., 42.24.4.2,127.0.0.1,99.98.97.96)'), 'validation' => 'isGenericName', 'type' => 'maintenance_ip', 'size' => 30, 'default' => ''), - 'PS_SSL_ENABLED' => array('title' => $this->l('Enable SSL'), 'desc' => $this->l('If your hosting provider allows SSL, you can activate SSL encryption (https://) for customer account identification and order processing'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'default' => '0'), - 'PS_COOKIE_CHECKIP' => array('title' => $this->l('Check IP on the cookie'), 'desc' => $this->l('Check the IP address of the cookie in order to avoid your cookie being stolen'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'default' => '0', 'visibility' => Shop::CONTEXT_ALL), - 'PS_TOKEN_ENABLE' => array('title' => $this->l('Increase Front Office security'), 'desc' => $this->l('Enable or disable token on the Front Office in order to improve PrestaShop security'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'default' => '0', 'visibility' => Shop::CONTEXT_ALL), - 'PS_HELPBOX' => array('title' => $this->l('Back Office help boxes'), 'desc' => $this->l('Enable yellow help boxes which are displayed under form fields in the Back Office'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'visibility' => Shop::CONTEXT_ALL), - 'PS_COOKIE_LIFETIME_FO' => array('title' => $this->l('Lifetime of the Front Office cookie'), 'desc' => $this->l('Indicate the number of hours'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'text', 'default' => '480', 'visibility' => Shop::CONTEXT_ALL), - 'PS_COOKIE_LIFETIME_BO' => array('title' => $this->l('Lifetime of the Back Office cookie'), 'desc' => $this->l('Indicate the number of hours'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'text', 'default' => '480', 'visibility' => Shop::CONTEXT_ALL), - 'PS_ORDER_PROCESS_TYPE' => array('title' => $this->l('Order process type'), 'desc' => $this->l('You can choose the order process type as either standard (5 steps) or One Page Checkout'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $order_process_type, 'identifier' => 'value'), - 'PS_GUEST_CHECKOUT_ENABLED' => array('title' => $this->l('Enable guest checkout'), 'desc' => $this->l('Your guest can make an order without registering'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), - 'PS_CONDITIONS' => array('title' => $this->l('Terms of service'), 'desc' => $this->l('Require customers to accept or decline terms of service before processing the order'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'js' => array('on' => 'onchange="changeCMSActivationAuthorization()"', 'off' => 'onchange="changeCMSActivationAuthorization()"')), - 'PS_CONDITIONS_CMS_ID' => array('title' => $this->l('Conditions of use CMS page'), 'desc' => $this->l('Choose the Conditions of use CMS page'), 'validation' => 'isInt', 'type' => 'select', 'list' => $cms_tab, 'identifier' => 'id', 'cast' => 'intval'), - 'PS_GIFT_WRAPPING' => array('title' => $this->l('Offer gift-wrapping'), 'desc' => $this->l('Suggest gift-wrapping to customer and possibility of leaving a message'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), - 'PS_GIFT_WRAPPING_PRICE' => array('title' => $this->l('Gift-wrapping price'), 'desc' => $this->l('Set a price for gift-wrapping'), 'validation' => 'isPrice', 'cast' => 'floatval', 'type' => 'price'), - 'PS_GIFT_WRAPPING_TAX' => array('title' => $this->l('Gift-wrapping tax'), 'desc' => $this->l('Set a tax for gift-wrapping'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $taxes, 'identifier' => 'id'), - 'PS_ATTACHMENT_MAXIMUM_SIZE' => array('title' => $this->l('Attachment maximum size'), 'desc' => $this->l('Set the maximum size of attachment files (in MegaBytes).').' '.$this->l('Maximum:').' '.((int)str_replace('M', '', ini_get('post_max_size')) > (int)str_replace('M', '', ini_get('upload_max_filesize')) ? ini_get('upload_max_filesize') : ini_get('post_max_size')), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'text', 'default' => '2'), - 'PS_RECYCLABLE_PACK' => array('title' => $this->l('Offer recycled packaging'), 'desc' => $this->l('Suggest recycled packaging to customer'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), - 'PS_CART_FOLLOWING' => array('title' => $this->l('Cart re-display at login'), 'desc' => $this->l('After customer logs in, recall and display contents of his/her last shopping cart'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), - 'PS_PRICE_ROUND_MODE' => array('title' => $this->l('Round mode'), 'desc' => $this->l('You can choose how to round prices: always round superior; always round inferior, or classic rounding'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $round_mode, 'identifier' => 'value'), - 'PRESTASTORE_LIVE' => array('title' => $this->l('Automatically check for module updates'), 'desc' => $this->l('New modules and updates are displayed on the modules page'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'visibility' => Shop::CONTEXT_ALL), - 'PS_HIDE_OPTIMIZATION_TIPS' => array('title' => $this->l('Hide optimization tips'), 'desc' => $this->l('Hide optimization tips on the back office homepage'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), - 'PS_DISPLAY_SUPPLIERS' => array('title' => $this->l('Display suppliers and manufacturers'), 'desc' => $this->l('Display manufacturers and suppliers list even if corresponding blocks are disabled'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), - 'PS_FORCE_SMARTY_2' => array('title' => $this->l('Use Smarty 2 instead of 3'), 'desc' => $this->l('Enable if your theme is incompatible with Smarty 3 (you should update your theme, since Smarty 2 will be unsupported from PrestaShop v1.5)'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'visibility' => Shop::CONTEXT_ALL), - ); + // Prevent classes which extend AdminPreferences to load useless data + if (get_class($this) == 'AdminPreferences') + { + $timezones = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT name FROM '._DB_PREFIX_.'timezone'); + $taxes[] = array('id' => 0, 'name' => $this->l('None')); + foreach (Tax::getTaxes($this->context->language->id) as $tax) + $taxes[] = array('id' => $tax['id_tax'], 'name' => $tax['name']); + + $order_process_type = array( + array( + 'value' => PS_ORDER_PROCESS_STANDARD, + 'name' => $this->l('Standard (5 steps)') + ), + array( + 'value' => PS_ORDER_PROCESS_OPC, + 'name' => $this->l('One page checkout') + ) + ); + + $round_mode = array( + array( + 'value' => PS_ROUND_UP, + 'name' => $this->l('superior') + ), + array( + 'value' => PS_ROUND_DOWN, + 'name' => $this->l('inferior') + ), + array( + 'value' => PS_ROUND_HALF, + 'name' => $this->l('classical') + ) + ); + + $cms_tab = array(0 => + array( + 'id' => 0, + 'name' => $this->l('None') + ) + ); + foreach (CMS::listCms($this->context->language->id) as $cms_file) + $cms_tab[] = array('id' => $cms_file['id_cms'], 'name' => $cms_file['meta_title']); + + $fields = array( + 'PS_SHOP_ENABLE' => array('title' => $this->l('Enable Shop'), 'desc' => $this->l('Activate or deactivate your shop. Deactivate your shop while you perform maintenance on it. Please note that the webservice will not be disabled'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), + 'PS_MAINTENANCE_IP' => array('title' => $this->l('Maintenance IP'), 'desc' => $this->l('IP addresses allowed to access the Front Office even if shop is disabled. Use a comma to separate them (e.g., 42.24.4.2,127.0.0.1,99.98.97.96)'), 'validation' => 'isGenericName', 'type' => 'maintenance_ip', 'size' => 30, 'default' => ''), + 'PS_SSL_ENABLED' => array('title' => $this->l('Enable SSL'), 'desc' => $this->l('If your hosting provider allows SSL, you can activate SSL encryption (https://) for customer account identification and order processing'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'default' => '0'), + 'PS_COOKIE_CHECKIP' => array('title' => $this->l('Check IP on the cookie'), 'desc' => $this->l('Check the IP address of the cookie in order to avoid your cookie being stolen'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'default' => '0', 'visibility' => Shop::CONTEXT_ALL), + 'PS_TOKEN_ENABLE' => array('title' => $this->l('Increase Front Office security'), 'desc' => $this->l('Enable or disable token on the Front Office in order to improve PrestaShop security'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'default' => '0', 'visibility' => Shop::CONTEXT_ALL), + 'PS_HELPBOX' => array('title' => $this->l('Back Office help boxes'), 'desc' => $this->l('Enable yellow help boxes which are displayed under form fields in the Back Office'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'visibility' => Shop::CONTEXT_ALL), + 'PS_COOKIE_LIFETIME_FO' => array('title' => $this->l('Lifetime of the Front Office cookie'), 'desc' => $this->l('Indicate the number of hours'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'text', 'default' => '480', 'visibility' => Shop::CONTEXT_ALL), + 'PS_COOKIE_LIFETIME_BO' => array('title' => $this->l('Lifetime of the Back Office cookie'), 'desc' => $this->l('Indicate the number of hours'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'text', 'default' => '480', 'visibility' => Shop::CONTEXT_ALL), + 'PS_ORDER_PROCESS_TYPE' => array('title' => $this->l('Order process type'), 'desc' => $this->l('You can choose the order process type as either standard (5 steps) or One Page Checkout'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $order_process_type, 'identifier' => 'value'), + 'PS_GUEST_CHECKOUT_ENABLED' => array('title' => $this->l('Enable guest checkout'), 'desc' => $this->l('Your guest can make an order without registering'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), + 'PS_CONDITIONS' => array('title' => $this->l('Terms of service'), 'desc' => $this->l('Require customers to accept or decline terms of service before processing the order'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'js' => array('on' => 'onchange="changeCMSActivationAuthorization()"', 'off' => 'onchange="changeCMSActivationAuthorization()"')), + 'PS_CONDITIONS_CMS_ID' => array('title' => $this->l('Conditions of use CMS page'), 'desc' => $this->l('Choose the Conditions of use CMS page'), 'validation' => 'isInt', 'type' => 'select', 'list' => $cms_tab, 'identifier' => 'id', 'cast' => 'intval'), + 'PS_GIFT_WRAPPING' => array('title' => $this->l('Offer gift-wrapping'), 'desc' => $this->l('Suggest gift-wrapping to customer and possibility of leaving a message'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), + 'PS_GIFT_WRAPPING_PRICE' => array('title' => $this->l('Gift-wrapping price'), 'desc' => $this->l('Set a price for gift-wrapping'), 'validation' => 'isPrice', 'cast' => 'floatval', 'type' => 'price'), + 'PS_GIFT_WRAPPING_TAX' => array('title' => $this->l('Gift-wrapping tax'), 'desc' => $this->l('Set a tax for gift-wrapping'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $taxes, 'identifier' => 'id'), + 'PS_ATTACHMENT_MAXIMUM_SIZE' => array('title' => $this->l('Attachment maximum size'), 'desc' => $this->l('Set the maximum size of attachment files (in MegaBytes).').' '.$this->l('Maximum:').' '.((int)str_replace('M', '', ini_get('post_max_size')) > (int)str_replace('M', '', ini_get('upload_max_filesize')) ? ini_get('upload_max_filesize') : ini_get('post_max_size')), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'text', 'default' => '2'), + 'PS_RECYCLABLE_PACK' => array('title' => $this->l('Offer recycled packaging'), 'desc' => $this->l('Suggest recycled packaging to customer'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), + 'PS_CART_FOLLOWING' => array('title' => $this->l('Cart re-display at login'), 'desc' => $this->l('After customer logs in, recall and display contents of his/her last shopping cart'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), + 'PS_PRICE_ROUND_MODE' => array('title' => $this->l('Round mode'), 'desc' => $this->l('You can choose how to round prices: always round superior; always round inferior, or classic rounding'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $round_mode, 'identifier' => 'value'), + 'PRESTASTORE_LIVE' => array('title' => $this->l('Automatically check for module updates'), 'desc' => $this->l('New modules and updates are displayed on the modules page'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'visibility' => Shop::CONTEXT_ALL), + 'PS_HIDE_OPTIMIZATION_TIPS' => array('title' => $this->l('Hide optimization tips'), 'desc' => $this->l('Hide optimization tips on the back office homepage'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), + 'PS_DISPLAY_SUPPLIERS' => array('title' => $this->l('Display suppliers and manufacturers'), 'desc' => $this->l('Display manufacturers and suppliers list even if corresponding blocks are disabled'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), + 'PS_FORCE_SMARTY_2' => array('title' => $this->l('Use Smarty 2 instead of 3'), 'desc' => $this->l('Enable if your theme is incompatible with Smarty 3 (you should update your theme, since Smarty 2 will be unsupported from PrestaShop v1.5)'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'visibility' => Shop::CONTEXT_ALL), + ); + if (function_exists('date_default_timezone_set')) - $this->_fieldsGeneral['PS_TIMEZONE'] = array('title' => $this->l('Time Zone:'), 'validation' => 'isAnything', 'type' => 'select', 'list' => $timezones, 'identifier' => 'name', 'visibility' => Shop::CONTEXT_ALL); + $fields['PS_TIMEZONE'] = array('title' => $this->l('Time Zone:'), 'validation' => 'isAnything', 'type' => 'select', 'list' => $timezones, 'identifier' => 'name', 'visibility' => Shop::CONTEXT_ALL); // No HTTPS activation if you haven't already. if (empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) == 'off') { - $this->_fieldsGeneral['PS_SSL_ENABLED']['type'] = 'disabled'; - $this->_fieldsGeneral['PS_SSL_ENABLED']['disabled'] = ''.$this->l('Please click here to use HTTPS protocol before enabling SSL.').''; + $fields['PS_SSL_ENABLED']['type'] = 'disabled'; + $fields['PS_SSL_ENABLED']['disabled'] = ''.$this->l('Please click here to use HTTPS protocol before enabling SSL.').''; } + + $this->optionsList = array( + 'general' => array( + 'title' => $this->l('General'), + 'icon' => 'tab-preferences', + 'fields' => $fields, + ), + ); + } parent::__construct(); } public function display() { - $this->_displayForm('general', $this->_fieldsGeneral, $this->l('General'), '', 'tab-preferences'); + $this->displayOptionsList(); } public function postProcess() { - if (Tools::getValue('PS_ATTACHMENT_MAXIMUM_SIZE')) - { - $uploadMaxSize = (int)str_replace('M', '',ini_get('upload_max_filesize')); - $postMaxSize = (int)str_replace('M', '', ini_get('post_max_size')); - $maxSize = $uploadMaxSize < $postMaxSize ? $uploadMaxSize : $postMaxSize; - - $_POST['PS_ATTACHMENT_MAXIMUM_SIZE'] = $maxSize < Tools::getValue('PS_ATTACHMENT_MAXIMUM_SIZE') ? $maxSize : Tools::getValue('PS_ATTACHMENT_MAXIMUM_SIZE'); - } - - if (isset($_POST['submitGeneral'.$this->table])) - { - Module::hookExec('categoryUpdate'); // We call this hook, for regenerate cache of categories - if (Tools::getValue('PS_CONDITIONS') == true AND (Tools::getValue('PS_CONDITIONS_CMS_ID') == 0 OR !Db::getInstance()->getValue(' - SELECT `id_cms` FROM `'._DB_PREFIX_.'cms` - WHERE id_cms = '.(int)(Tools::getValue('PS_CONDITIONS_CMS_ID'))))) - $this->_errors[] = Tools::displayError('Assign a valid CMS page if you want it to be read.'); - if ($this->tabAccess['edit'] === '1') - $this->_postConfig($this->_fieldsGeneral); - else - $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); - } - elseif (isset($_POST['submitShop'.$this->table])) - { - if ($this->tabAccess['edit'] === '1') - $this->_postConfig($this->_fieldsShop); - else - $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); - } - elseif (isset($_POST['submitAppearance'.$this->table])) - { - if ($this->tabAccess['edit'] === '1') - $this->_postConfig($this->_fieldsAppearance); - else - $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); - } - elseif (isset($_POST['submitThemes'.$this->table])) - { - if ($this->tabAccess['edit'] === '1') - { - if ($val = Tools::getValue('PS_THEME')) - { - if (rewriteSettingsFile(NULL, $val, NULL)) - Tools::redirectAdmin(self::$currentIndex.'&conf=6'.'&token='.$this->token); - else - $this->_errors[] = Tools::displayError('Cannot access settings file.'); - } - else - $this->_errors[] = Tools::displayError('You must choose a graphical theme.'); - } - else - $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); - } - - parent::postProcess(); - } - - /** - * Update settings in database and configuration files - * - * @params array $fields Fields settings - */ - protected function _postConfig($fields) - { - $languages = Language::getLanguages(false); - Tools::clearCache($this->context->smarty); - - /* Check required fields */ - foreach ($fields AS $field => $values) - if (isset($values['required']) AND $values['required'] && !isset($_POST['configUseDefault'][$field])) - if (isset($values['type']) AND $values['type'] == 'textLang') - { - foreach ($languages as $language) - if (($value = Tools::getValue($field.'_'.$language['id_lang'])) == false AND (string)$value != '0') - $this->_errors[] = Tools::displayError('field').' '.$values['title'].' '.Tools::displayError('is required.'); - } - elseif (($value = Tools::getValue($field)) == false AND (string)$value != '0') - $this->_errors[] = Tools::displayError('field').' '.$values['title'].' '.Tools::displayError('is required.'); - - /* Check fields validity */ - foreach ($fields AS $field => $values) - if (isset($values['type']) AND $values['type'] == 'textLang') - { - foreach ($languages as $language) - if (Tools::getValue($field.'_'.$language['id_lang']) AND isset($values['validation'])) - if (!Validate::$values['validation'](Tools::getValue($field.'_'.$language['id_lang']))) - $this->_errors[] = Tools::displayError('field').' '.$values['title'].' '.Tools::displayError('is invalid.'); - } - elseif (Tools::getValue($field) AND isset($values['validation'])) - if (!Validate::$values['validation'](Tools::getValue($field))) - $this->_errors[] = Tools::displayError('field').' '.$values['title'].' '.Tools::displayError('is invalid.'); - - /* Default value if null */ - foreach ($fields AS $field => $values) - if (!Tools::getValue($field) AND isset($values['default'])) - $_POST[$field] = $values['default']; - - /* Save process */ - if (!sizeof($this->_errors)) - { - if (Tools::isSubmit('submitAppearanceconfiguration')) - { - $id_shop = Context::getContext()->shop->getID(); - if (isset($_FILES['PS_LOGO']['tmp_name']) AND $_FILES['PS_LOGO']['tmp_name']) - { - if ($error = checkImage($_FILES['PS_LOGO'], 300000)) - $this->_errors[] = $error; - if (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES['PS_LOGO']['tmp_name'], $tmpName)) - return false; - if ($id_shop == Configuration::get('PS_SHOP_DEFAULT') && !@imageResize($tmpName, _PS_IMG_DIR_.'logo.jpg')) - $this->_errors[] = 'an error occurred during logo copy'; - if (!@imageResize($tmpName, _PS_IMG_DIR_.'logo-'.(int)$id_shop.'.jpg')) - $this->_errors[] = 'an error occurred during logo copy'; - - unlink($tmpName); - } - if (isset($_FILES['PS_LOGO_MAIL']['tmp_name']) AND $_FILES['PS_LOGO_MAIL']['tmp_name']) - { - if ($error = checkImage($_FILES['PS_LOGO_MAIL'], 300000)) - $this->_errors[] = $error; - if (!$tmpName == tempnam(_PS_TMP_IMG_DIR_, 'PS_MAIL') OR !move_uploaded_file($_FILES['PS_LOGO_MAIL']['tmp_name'], $tmpName)) - return false; - if ($id_shop == Configuration::get('PS_SHOP_DEFAULT') && !@imageResize($tmpName, _PS_IMG_DIR_.'logo_mail.jpg')) - $this->_errors[] = 'an error occurred during logo copy'; - if (!@imageResize($tmpName, _PS_IMG_DIR_.'logo_mail-'.(int)$id_shop.'.jpg')) - $this->_errors[] = 'an error occurred during logo copy'; - unlink($tmpName); - } - if (isset($_FILES['PS_LOGO_INVOICE']['tmp_name']) AND $_FILES['PS_LOGO_INVOICE']['tmp_name']) - { - if ($error = checkImage($_FILES['PS_LOGO_INVOICE'], 300000)) - $this->_errors[] = $error; - if (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS_INVOICE') OR !move_uploaded_file($_FILES['PS_LOGO_INVOICE']['tmp_name'], $tmpName)) - return false; - if ($id_shop == Configuration::get('PS_SHOP_DEFAULT') && !@imageResize($tmpName, _PS_IMG_DIR_.'logo_invoice.jpg')) - $this->_errors[] = 'an error occurred during logo copy'; - if (!@imageResize($tmpName, _PS_IMG_DIR_.'logo_invoice-'.(int)$id_shop.'.jpg')) - $this->_errors[] = 'an error occurred during logo copy'; - - unlink($tmpName); - } - if (isset($_FILES['PS_STORES_ICON']['tmp_name']) AND $_FILES['PS_STORES_ICON']['tmp_name']) - { - if ($error = checkImage($_FILES['PS_STORES_ICON'], 300000)) - $this->_errors[] = $error; - if (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS_STORES_ICON') OR !move_uploaded_file($_FILES['PS_STORES_ICON']['tmp_name'], $tmpName)) - return false; - if ($id_shop = Configuration::get('PS_SHOP_DEFAULT') && !@imageResize($tmpName, _PS_IMG_DIR_.'logo_stores.gif')) - $this->_errors[] = 'an error occurred during logo copy'; - if (!@imageResize($tmpName, _PS_IMG_DIR_.'logo_stores-'.(int)$id_shop.'.gif')) - $this->_errors[] = 'an error occurred during logo copy'; - unlink($tmpName); - } - if ($id_shop = Configuration::get('PS_SHOP_DEFAULT')) - $this->uploadIco('PS_FAVICON', _PS_IMG_DIR_.'favicon.ico'); - $this->uploadIco('PS_FAVICON', _PS_IMG_DIR_.'favicon-'.(int)$id_shop.'.ico'); - } - - /* Update settings in database */ - if (!sizeof($this->_errors)) - { - $this->submitConfiguration($fields); - Tools::redirectAdmin(self::$currentIndex.'&conf=6'.'&token='.$this->token); - } - } - } - - private function getVal($conf, $key) - { - return Tools::getValue($key, (isset($conf[$key]) ? $conf[$key] : '')); + parent::postProcess(); } private function getConf($fields, $languages) { - foreach ($fields AS $key => $field) - { - if ($field['type'] == 'textLang') - foreach ($languages as $language) - $tab[$key.'_'.$language['id_lang']] = Tools::getValue($key.'_'.$language['id_lang'], Configuration::get($key, $language['id_lang'])); - else - $tab[$key] = Tools::getValue($key, Configuration::get($key)); - } $tab['_MEDIA_SERVER_1_'] = _MEDIA_SERVER_1_; $tab['_MEDIA_SERVER_2_'] = _MEDIA_SERVER_2_; $tab['_MEDIA_SERVER_3_'] = _MEDIA_SERVER_3_; - $tab['db_type'] = _DB_TYPE_; - $tab['db_server'] = _DB_SERVER_; - $tab['db_name'] = _DB_NAME_; - $tab['db_prefix'] = _DB_PREFIX_; - $tab['db_user'] = _DB_USER_; - $tab['db_passwd'] = ''; return $tab; } - private function getDivLang($fields) + /** + * This method is called before we start to update options configuration + */ + public function beforeUpdateOptions() { - $tab = array(); - foreach ($fields AS $key => $field) - if ($field['type'] == 'textLang' || $field['type'] == 'selectLang') - $tab[] = $key; - return implode('¤', $tab); + if (get_class($this) != 'AdminPreferences') + return ; + + $sql = 'SELECT `id_cms` FROM `'._DB_PREFIX_.'cms` + WHERE id_cms = '.(int)Tools::getValue('PS_CONDITIONS_CMS_ID'); + if (Tools::getValue('PS_CONDITIONS') && (Tools::getValue('PS_CONDITIONS_CMS_ID') == 0 OR !Db::getInstance()->getValue($sql))) + $this->_errors[] = Tools::displayError('Assign a valid CMS page if you want it to be read.'); } /** - * Display configuration form - * - * @params string $name Form name - * @params array $fields Fields settings - */ - protected function _displayForm($name, $fields, $tabname, $size, $icon) + * Update PS_ATTACHMENT_MAXIMUM_SIZE + */ + public function updateOptionPsAttachementMaximumSize($value) { - $defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT')); - $languages = Language::getLanguages(false); - $confValues = $this->getConf($fields, $languages); - $divLangName = $this->getDivLang($fields); - $required = false; + if (!$value) + return ; - echo ' - - -
'.$tabname.''; - foreach ($fields AS $key => $field) - { - /* Specific line for e-mails settings */ - if (get_class($this) == 'Adminemails' AND $key == 'PS_MAIL_SERVER') - echo '
'; - if (isset($field['required']) AND $field['required']) - $required = true; - $val = $this->getVal($confValues, $key); - - // Check if var is invisible (can't edit it in current shop context), or disable (use default value for multishop) - $isDisabled = $isInvisible = false; - if (Shop::isMultiShopActivated()) - { - if (isset($field['visibility']) && $field['visibility'] > $this->context->shop->getContextType()) + /** + * Display option IP maintenance + */ + public function displayOptionTypeMaintenanceIp($key, $field, $value) + { + echo '
'; - - if(!is_writable(PS_ADMIN_DIR.'/../config/settings.inc.php') AND $name == 'themes') - echo '

'.$this->l('if you change the theme, the settings.inc.php file must be writable (CHMOD 755 / 777)').'

'; - - echo '
- -
- '.($required ? '
* '.$this->l('Required field', 'AdminPreferences').'
' : '').' -
- '; + '; + + $this->displayOptionTypeText($key, $field, $value); + echo (isset($field['next']) ? ' '.strval($field['next']) : ''); + echo '  '.$this->l('Add my IP').''; + } + public function displayBottomOptionCategory($category, $categoryData) + { if (get_class($this) == 'AdminPreferences') echo ''; } } - diff --git a/admin-dev/tabs/AdminSearchConf.php b/admin-dev/tabs/AdminSearchConf.php index 40a18321c..22d8f94c0 100644 --- a/admin-dev/tabs/AdminSearchConf.php +++ b/admin-dev/tabs/AdminSearchConf.php @@ -33,69 +33,74 @@ class AdminSearchConf extends AdminPreferences { $this->className = 'Configuration'; $this->table = 'configuration'; - - $this->_fieldsSearch = array( - 'PS_SEARCH_AJAX' => array('title' => $this->l('Ajax search'), 'validation' => 'isBool', 'type' => 'bool', 'cast' => 'intval', - 'desc' => $this->l('Enable the ajax search for your visitors.').'
'.$this->l('With the ajax search, the first 10 products matching the user query will appear in real time below the input field.')), - 'PS_INSTANT_SEARCH' => array('title' => $this->l('Instant search:'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', - 'desc' => $this->l('Enable the instant search for your visitors.').'
'.$this->l('With the instant search, the results will appear immediatly while the user write his query.')), - 'PS_SEARCH_MINWORDLEN' => array('title' => $this->l('Minimum word length'), 'desc' => $this->l('Only words from this size will be indexed.'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), - 'PS_SEARCH_BLACKLIST' => array('title' => $this->l('Blacklisted words'), 'size' => 35, 'validation' => 'isGenericName', 'desc' => $this->l('Please enter the words separated by a "|".'), 'type' => 'textLang') - ); - - $this->_fieldsWeight = array( - 'PS_SEARCH_WEIGHT_PNAME' => array('title' => $this->l('Product name weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), - 'PS_SEARCH_WEIGHT_REF' => array('title' => $this->l('Reference weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), - 'PS_SEARCH_WEIGHT_SHORTDESC' => array('title' => $this->l('Short description weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), - 'PS_SEARCH_WEIGHT_DESC' => array('title' => $this->l('Description weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), - 'PS_SEARCH_WEIGHT_CNAME' => array('title' => $this->l('Category weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), - 'PS_SEARCH_WEIGHT_MNAME' => array('title' => $this->l('Manufacturer weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), - 'PS_SEARCH_WEIGHT_TAG' => array('title' => $this->l('Tags weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), - 'PS_SEARCH_WEIGHT_ATTRIBUTE' => array('title' => $this->l('Attributes weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), - 'PS_SEARCH_WEIGHT_FEATURE' => array('title' => $this->l('Features weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval') - ); - + parent::__construct(); + + $this->optionsList = array( + 'search' => array( + 'title' => $this->l('Search'), + 'icon' => 'search', + 'class' => 'width2', + 'fields' => array( + 'PS_SEARCH_AJAX' => array('title' => $this->l('Ajax search'), 'validation' => 'isBool', 'type' => 'bool', 'cast' => 'intval', + 'desc' => $this->l('Enable the ajax search for your visitors.').'
'.$this->l('With the ajax search, the first 10 products matching the user query will appear in real time below the input field.')), + 'PS_INSTANT_SEARCH' => array('title' => $this->l('Instant search:'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', + 'desc' => $this->l('Enable the instant search for your visitors.').'
'.$this->l('With the instant search, the results will appear immediatly while the user write his query.')), + 'PS_SEARCH_MINWORDLEN' => array('title' => $this->l('Minimum word length'), 'desc' => $this->l('Only words from this size will be indexed.'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), + 'PS_SEARCH_BLACKLIST' => array('title' => $this->l('Blacklisted words'), 'size' => 35, 'validation' => 'isGenericName', 'desc' => $this->l('Please enter the words separated by a "|".'), 'type' => 'textLang') + ), + ), + 'weight' => array( + 'title' => $this->l('Weight'), + 'icon' => 'weight', + 'class' => 'width2', + 'fields' => array( + 'PS_SEARCH_WEIGHT_PNAME' => array('title' => $this->l('Product name weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), + 'PS_SEARCH_WEIGHT_REF' => array('title' => $this->l('Reference weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), + 'PS_SEARCH_WEIGHT_SHORTDESC' => array('title' => $this->l('Short description weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), + 'PS_SEARCH_WEIGHT_DESC' => array('title' => $this->l('Description weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), + 'PS_SEARCH_WEIGHT_CNAME' => array('title' => $this->l('Category weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), + 'PS_SEARCH_WEIGHT_MNAME' => array('title' => $this->l('Manufacturer weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), + 'PS_SEARCH_WEIGHT_TAG' => array('title' => $this->l('Tags weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), + 'PS_SEARCH_WEIGHT_ATTRIBUTE' => array('title' => $this->l('Attributes weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), + 'PS_SEARCH_WEIGHT_FEATURE' => array('title' => $this->l('Features weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval') + ), + ), + ); } - public function postProcess() - { - if (isset($_POST['submitSearch'.$this->table])) -{ if ($this->tabAccess['edit'] === '1') $this->_postConfig($this->_fieldsSearch); else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } -if (isset($_POST['submitWeight'.$this->table])) -{ if ($this->tabAccess['edit'] === '1') $this->_postConfig($this->_fieldsWeight); else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } - } - - public function display() + public function displayTopOptionCategory($category, $categoryData) { - $currentFileName = array_reverse(explode("/", $_SERVER['SCRIPT_NAME'])); - $cronUrl = Tools::getHttpHost(true, true).__PS_BASE_URI__.substr($_SERVER['SCRIPT_NAME'], strlen(__PS_BASE_URI__), -strlen($currentFileName['0'])).'searchcron.php?full=1&token='.substr(_COOKIE_KEY_, 34, 8); - list($total, $indexed) = Db::getInstance()->getRow('SELECT COUNT(*) as "0", SUM(indexed) as "1" FROM '._DB_PREFIX_.'product'); - echo ' -
- '.$this->l('Indexation').' -

- '.$this->l('The "indexed" products have been analysed by PrestaShop and will appear in the results of the front office search.').'
- '.$this->l('Indexed products:').' '.(int)($indexed).' / '.(int)($total).'. -

-

'.$this->l('Building the product index can take a few minutes or more. If your server stop the process before it ends, you can resume the indexation by clicking "Add missing products".').'

- -> '.$this->l('Add missing products to index.').'
- -> '.$this->l('Re-build entire index.').'

- '.$this->l('You can set a cron job that will re-build your index using the following URL:').' '.$cronUrl.'. -
-
 
'; - $this->_displayForm('search', $this->_fieldsSearch, $this->l('Search'), 'width2', 'search'); - echo ' -
 
-
- '.$this->l('Relevance').' - '.$this->l('The "weight" represents its importance and relevance for the ranking of the products when try a new search.').'
- '.$this->l('A word with a weight of 8 will have 4 times more value than a word with a weight of 2.').'

- '.$this->l('That\'s why we advize to set a greater weight for words which appear in the name or reference of a products than the ones of the description of category name. Thus, the search results will be as precised and releant as possible.').' -
-
 
'; - $this->_displayForm('weight', $this->_fieldsWeight, $this->l('Weight'), 'width2', 'search'); + switch ($category) + { + case 'search' : + $currentFileName = array_reverse(explode("/", $_SERVER['SCRIPT_NAME'])); + $cronUrl = Tools::getHttpHost(true, true).__PS_BASE_URI__.substr($_SERVER['SCRIPT_NAME'], strlen(__PS_BASE_URI__), -strlen($currentFileName['0'])).'searchcron.php?full=1&token='.substr(_COOKIE_KEY_, 34, 8); + list($total, $indexed) = Db::getInstance()->getRow('SELECT COUNT(*) as "0", SUM(indexed) as "1" FROM '._DB_PREFIX_.'product'); + echo '
+ '.$this->l('Indexation').' +

+ '.$this->l('The "indexed" products have been analysed by PrestaShop and will appear in the results of the front office search.').'
+ '.$this->l('Indexed products:').' '.(int)($indexed).' / '.(int)($total).'. +

+

'.$this->l('Building the product index can take a few minutes or more. If your server stop the process before it ends, you can resume the indexation by clicking "Add missing products".').'

+ -> '.$this->l('Add missing products to index.').'
+ -> '.$this->l('Re-build entire index.').'

+ '.$this->l('You can set a cron job that will re-build your index using the following URL:').' '.$cronUrl.'. +
+
 
'; + break; + + case 'weight' : + echo '
 
+
+ '.$this->l('Relevance').' + '.$this->l('The "weight" represents its importance and relevance for the ranking of the products when try a new search.').'
+ '.$this->l('A word with a weight of 8 will have 4 times more value than a word with a weight of 2.').'

+ '.$this->l('That\'s why we advize to set a greater weight for words which appear in the name or reference of a products than the ones of the description of category name. Thus, the search results will be as precised and releant as possible.').' +
+
 
'; + break; + } } } - - diff --git a/admin-dev/tabs/AdminStatsConf.php b/admin-dev/tabs/AdminStatsConf.php index 7b637ee71..2c6e62d71 100644 --- a/admin-dev/tabs/AdminStatsConf.php +++ b/admin-dev/tabs/AdminStatsConf.php @@ -32,86 +32,69 @@ class AdminStatsConf extends AdminPreferences { public function __construct() { - $this->_fieldsSettings = array( - 'PS_STATS_RENDER' => array('title' => $this->l('Graph engine'), 'validation' => 'isGenericName'), - 'PS_STATS_GRID_RENDER' => array('title' => $this->l('Grid engine'), 'validation' => 'isGenericName'), - 'PS_STATS_OLD_CONNECT_AUTO_CLEAN' => array( 'title' => $this->l('Auto-clean period'), 'validation' => 'isGenericName')); parent::__construct(); + + $autocleanPeriod = array( + array('value' => 'never', 'name' => $this->l('Never')), + array('value' => 'week', 'name' => $this->l('Week')), + array('value' => 'month', 'name' => $this->l('Month')), + array('value' => 'year', 'name' => $this->l('Year')), + ); + + $this->optionsList = array( + 'general' => array( + 'title' => $this->l('General'), + 'icon' => 'tab-preferences', + 'fields' => array( + 'PS_STATS_RENDER' => array('title' => $this->l('Graph engine'), 'validation' => 'isGenericName', 'cast' => 'strval', 'type' => 'selectEngine'), + 'PS_STATS_GRID_RENDER' => array('title' => $this->l('Grid engine'), 'validation' => 'isGenericName', 'cast' => 'strval', 'type' => 'selectGrid'), + 'PS_STATS_OLD_CONNECT_AUTO_CLEAN' => array('title' => $this->l('Auto-clean period'), 'validation' => 'isGenericName', 'type' => 'select', 'list' => $autocleanPeriod, 'identifier' => 'value'), + ), + ), + ); + } + + public function displayOptionTypeSelectEngine($key, $field, $value) + { + $listEngineDescription = array(); + $listEngine = array(); + foreach (ModuleGraphEngine::getGraphEngines() as $k => $engine) + { + $listEngine[] = array( + 'name' => $engine[0], + 'value' => $k, + ); + $listEngineDescription[$k] = $engine[1]; + } + + $field['list'] = $listEngine; + $field['identifier'] = 'value'; + $field['js'] = '$(\'#render_engine_description\').html(engineDescriptions[$(this).val()])'; + + echo ''; + $this->displayOptionTypeSelect($key, $field, $value); + echo '
'.$listEngineDescription[$value].'
'; } - public function postProcess() + public function displayOptionTypeSelectGrid($key, $field, $value) { - if (Tools::getValue('submitSettings')) + $listEngineDescription = array(); + $listEngine = array(); + foreach (ModuleGridEngine::getGridEngines() as $k => $engine) { - if ($this->tabAccess['edit'] === '1') - $this->_postConfig($this->_fieldsSettings); - else - $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); + $listEngine[] = array( + 'name' => $engine[0], + 'value' => $k, + ); + $listEngineDescription[$k] = $engine[1]; } - } - - public function display() - { - $graphEngine = Configuration::get('PS_STATS_RENDER'); - $gridEngine = Configuration::get('PS_STATS_GRID_RENDER'); - $autoclean = Configuration::get('PS_STATS_OLD_CONNECT_AUTO_CLEAN'); - $arrayGraphEngines = ModuleGraphEngine::getGraphEngines(); - $arrayGridEngines = ModuleGridEngine::getGridEngines(); - $autocleanPeriod = array('never' => $this->l('Never'), - 'week' => $this->l('Week'), - 'month' => $this->l('Month'), - 'year' => $this->l('Year')); - echo ' -
'.$this->l('Settings').''; - - #Graph Engines - echo '
'; - if (sizeof($arrayGraphEngines)) - { - foreach ($arrayGraphEngines as $k => $value) - echo '
'.$value[1].'
'; - echo '
-
'.$arrayGraphEngines[$graphEngine][1].'
-
'; - } - else - echo $this->l('No graph engine module installed'); - echo '
'; - - #Grid Engines - echo '
'; - if (sizeof($arrayGridEngines)) - { - foreach ($arrayGridEngines as $k => $value) - echo '
'.$value[1].'
'; - echo '
-
'.$arrayGridEngines[$gridEngine][1].'
-
'; - } - else - echo $this->l('No grid engine module installed'); - echo '
'; - - echo ' -
- -
'; - - #End Of Form - echo ' -
- '; + $field['list'] = $listEngine; + $field['identifier'] = 'value'; + $field['js'] = '$(\'#render_grid_description\').html(gridDescriptions[$(this).val()])'; + + echo ''; + $this->displayOptionTypeSelect($key, $field, $value); + echo '
'.$listEngineDescription[$value].'
'; } } - - diff --git a/admin-dev/tabs/AdminStatsTab.php b/admin-dev/tabs/AdminStatsTab.php index ebc75c6ce..b2d1a184c 100644 --- a/admin-dev/tabs/AdminStatsTab.php +++ b/admin-dev/tabs/AdminStatsTab.php @@ -29,15 +29,6 @@ include_once(PS_ADMIN_DIR.'/tabs/AdminPreferences.php'); abstract class AdminStatsTab extends AdminPreferences { - public function __construct() - { - $this->_fieldsSettings = array( - 'PS_STATS_RENDER' => array('title' => $this->l('Graph engine'), 'validation' => 'isGenericName'), - 'PS_STATS_GRID_RENDER' => array('title' => $this->l('Grid engine'), 'validation' => 'isGenericName') - ); - parent::__construct(); - } - public function postProcess() { $this->context = Context::getContext(); @@ -91,7 +82,8 @@ abstract class AdminStatsTab extends AdminPreferences if ($this->tabAccess['edit'] === '1') { self::$currentIndex .= '&module='.Tools::getValue('module'); - $this->_postConfig($this->_fieldsSettings); + Configuration::updateValue('PS_STATS_RENDER', Tools::getValue('PS_STATS_RENDER', Configuration::get('PS_STATS_RENDER'))); + Configuration::updateValue('PS_STATS_GRID_RENDER', Tools::getValue('PS_STATS_GRID_RENDER', Configuration::get('PS_STATS_GRID_RENDER'))); } else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); @@ -99,7 +91,7 @@ abstract class AdminStatsTab extends AdminPreferences if (sizeof($this->_errors)) AdminTab::displayErrors(); } - + protected function displayEngines() { $graphEngine = Configuration::get('PS_STATS_RENDER'); diff --git a/admin-dev/tabs/AdminThemes.php b/admin-dev/tabs/AdminThemes.php index f5fd1406e..5d4de0141 100644 --- a/admin-dev/tabs/AdminThemes.php +++ b/admin-dev/tabs/AdminThemes.php @@ -95,16 +95,25 @@ class AdminThemes extends AdminPreferences { $this->className = 'Configuration'; $this->table = 'configuration'; - $id_shop = Context::getContext()->shop->getID(); - $this->_fieldsAppearance = array( - 'PS_LOGO' => array('title' => $this->l('Header logo:'), 'desc' => $this->l('Will appear on main page'), 'type' => 'file', 'thumb' => array('file' => _PS_IMG_.'logo-'.(int)$id_shop.'.jpg?date='.time(), 'pos' => 'before')), - 'PS_LOGO_MAIL' => array('title' => $this->l('Mail logo:'), 'desc' => $this->l('Will appear on e-mail headers, if undefined the Header logo will be used'), 'type' => 'file', 'thumb' => array('file' => ((file_exists(_PS_IMG_DIR_.'logo_mail-'.(int)$id_shop.'.jpg')) ? _PS_IMG_.'logo_mail-'.(int)$id_shop.'.jpg?date='.time() : _PS_IMG_.'logo-'.(int)$id_shop.'.jpg?date='.time()), 'pos' => 'before')), - 'PS_LOGO_INVOICE' => array('title' => $this->l('Invoice logo:'), 'desc' => $this->l('Will appear on invoices headers, if undefined the Header logo will be used'), 'type' => 'file', 'thumb' => array('file' => (file_exists(_PS_IMG_DIR_.'logo_invoice-'.(int)$id_shop.'.jpg') ? _PS_IMG_.'logo_invoice-'.(int)$id_shop.'.jpg?date='.time() : _PS_IMG_.'logo-'.(int)$id_shop.'.jpg?date='.time()), 'pos' => 'before')), - 'PS_FAVICON' => array('title' => $this->l('Favicon:'), 'desc' => $this->l('Will appear in the address bar of your web browser'), 'type' => 'file', 'thumb' => array('file' => _PS_IMG_.'favicon-'.(int)$id_shop.'.ico?date='.time(), 'pos' => 'after')), - 'PS_STORES_ICON' => array('title' => $this->l('Store icon:'), 'desc' => $this->l('Will appear on the store locator (inside Google Maps)').'
'.$this->l('Suggested size: 30x30, Transparent GIF'), 'type' => 'file', 'thumb' => array('file' => _PS_IMG_.'logo_stores-'.(int)$id_shop.'.gif?date='.time(), 'pos' => 'before')), - 'PS_NAVIGATION_PIPE' => array('title' => $this->l('Navigation pipe:'), 'desc' => $this->l('Used for navigation path inside categories/product'), 'cast' => 'strval', 'type' => 'text', 'size' => 20), - ); + parent::__construct(); + + $id_shop = Context::getContext()->shop->getID(); + $this->optionsList = array( + 'appearance' => array( + 'title' => $this->l('Appearance'), + 'icon' => 'email', + 'class' => 'width3', + 'fields' => array( + 'PS_LOGO' => array('title' => $this->l('Header logo:'), 'desc' => $this->l('Will appear on main page'), 'type' => 'file', 'thumb' => array('file' => _PS_IMG_.'logo-'.(int)$id_shop.'.jpg?date='.time(), 'pos' => 'before')), + 'PS_LOGO_MAIL' => array('title' => $this->l('Mail logo:'), 'desc' => $this->l('Will appear on e-mail headers, if undefined the Header logo will be used'), 'type' => 'file', 'thumb' => array('file' => ((file_exists(_PS_IMG_DIR_.'logo_mail-'.(int)$id_shop.'.jpg')) ? _PS_IMG_.'logo_mail-'.(int)$id_shop.'.jpg?date='.time() : _PS_IMG_.'logo-'.(int)$id_shop.'.jpg?date='.time()), 'pos' => 'before')), + 'PS_LOGO_INVOICE' => array('title' => $this->l('Invoice logo:'), 'desc' => $this->l('Will appear on invoices headers, if undefined the Header logo will be used'), 'type' => 'file', 'thumb' => array('file' => (file_exists(_PS_IMG_DIR_.'logo_invoice-'.(int)$id_shop.'.jpg') ? _PS_IMG_.'logo_invoice-'.(int)$id_shop.'.jpg?date='.time() : _PS_IMG_.'logo-'.(int)$id_shop.'.jpg?date='.time()), 'pos' => 'before')), + 'PS_FAVICON' => array('title' => $this->l('Favicon:'), 'desc' => $this->l('Will appear in the address bar of your web browser'), 'type' => 'file', 'thumb' => array('file' => _PS_IMG_.'favicon-'.(int)$id_shop.'.ico?date='.time(), 'pos' => 'after')), + 'PS_STORES_ICON' => array('title' => $this->l('Store icon:'), 'desc' => $this->l('Will appear on the store locator (inside Google Maps)').'
'.$this->l('Suggested size: 30x30, Transparent GIF'), 'type' => 'file', 'thumb' => array('file' => _PS_IMG_.'logo_stores-'.(int)$id_shop.'.gif?date='.time(), 'pos' => 'before')), + 'PS_NAVIGATION_PIPE' => array('title' => $this->l('Navigation pipe:'), 'desc' => $this->l('Used for navigation path inside categories/product'), 'cast' => 'strval', 'type' => 'text', 'size' => 20), + ), + ), + ); } public function display() @@ -115,10 +124,12 @@ class AdminThemes extends AdminPreferences Configuration::updateValue('SHOP_LOGO_WIDTH', (int)round($width)); Configuration::updateValue('SHOP_LOGO_HEIGHT', (int)round($height)); } + // No cache for auto-refresh uploaded logo header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); - $this->_displayForm('appearance', $this->_fieldsAppearance, $this->l('Appearance'), 'width3', 'appearance'); + $this->displayOptionsList(); + echo '

'; if (@ini_get('allow_url_fopen') AND @fsockopen('addons.prestashop.com', 80, $errno, $errst, 3)) echo ' - '.(($this->formOptions) ? '' : '').' -
'; - echo ($optionTitle ? ' - ' - .$optionTitle.'' : ''); - if ($optionDescription) - echo '

'.$optionDescription.'

'; - - foreach ($fieldsOptions AS $key => $field) + echo ''; + + echo ''; + foreach ($this->optionsList as $category => $categoryData) { - $val = Tools::getValue($key, Configuration::get($key)); - if ($field['type'] != 'textLang') - if (!Validate::isCleanHtml($val)) - $val = Configuration::get($key); - - if (isset($field['defaultValue']) && !$val) - $val = $field['defaultValue']; + $required = false; + $this->displayTopOptionCategory($category, $categoryData); + echo '
'; - // Check if var is invisible (can't edit it in current shop context), or disable (use default value for multishop) - $isDisabled = $isInvisible = false; - if (Shop::isMultiShopActivated()) + // Options category title + $legend = ' '; + $legend .= ((isset($categoryData['title'])) ? $categoryData['title'] : $this->l('Options')); + echo ''.$legend.''; + + // Category fields + if (!isset($categoryData['fields'])) + continue; + + // Category description + if (isset($categoryData['description']) && $categoryData['description']) + echo '

'.$categoryData['description'].'

'; + + foreach ($categoryData['fields'] as $key => $field) { - if (isset($field['visibility']) && $field['visibility'] > $this->context->shop->getContextType()) + // Field value + $value = Tools::getValue($key, Configuration::get($key)); + if (!Validate::isCleanHtml($value)) + $value = Configuration::get($key); + + if (isset($field['defaultValue']) && !$value) + $value = $field['defaultValue']; + + // Check if var is invisible (can't edit it in current shop context), or disable (use default value for multishop) + $isDisabled = $isInvisible = false; + if (Shop::isMultiShopActivated()) { - $isDisabled = true; - $isInvisible = true; + if (isset($field['visibility']) && $field['visibility'] > $this->context->shop->getContextType()) + { + $isDisabled = true; + $isInvisible = true; + } + else if (Context::shop() != Shop::CONTEXT_ALL && !Configuration::isOverridenByCurrentContext($key)) + $isDisabled = true; } - else if (Context::shop() != Shop::CONTEXT_ALL && !Configuration::isOverridenByCurrentContext($key)) - $isDisabled = true; + + // Display title + echo '
'; + if ($field['title']) + { + echo ''; + } + + echo '
'; + + // Display option inputs + $method = 'displayOptionType'.Tools::toCamelCase($field['type'], true); + if (!method_exists($this, $method)) + echo 'Option method '.get_class($this).'->'.$method.'() not found
'; + else + $this->$method($key, $field, $value); + + // Multishop default value + if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && !$isInvisible) + echo '
+ +
'; + + // Field description + //echo (isset($field['desc']) ? '

'.((isset($field['thumb']) AND $field['thumb'] AND $field['thumb']['pos'] == 'after') ? ''.$field['title'].'' : '' ).$field['desc'].'

' : ''); + echo (isset($field['desc']) ? '

'.$field['desc'].'

' : ''); + + // Is this field invisible in current shop context ? + echo ($isInvisible) ? '

'.$this->l('You can\'t change the value of this configuration field in this shop context').'

' : ''; + + echo '
'; } - echo '
-
'; - switch ($field['type']) - { - case 'select': - echo ''; - break; - - case 'bool': - echo ' - - - - - '; - break; - - case 'textLang': - foreach ($this->_languages as $language) - { - $val = Tools::getValue($key.'_'.$language['id_lang'], Configuration::get($key, $language['id_lang'])); - if (!Validate::isCleanHtml($val)) - $val = Configuration::get($key); - echo ' -
- -
'; - } - $this->displayFlags($this->_languages, $defaultLanguage, $key, $key); - - echo '
'; - break; - - case 'textareaLang': - foreach ($this->_languages as $language) - { - $val = Configuration::get($key, $language['id_lang']); - echo ' -
- -
'; - } - $this->displayFlags($this->_languages, $defaultLanguage, $key, $key); - echo '
'; - break; - - case 'text': - - default: - echo ''.(isset($field['suffix']) ? $field['suffix'] : ''); - break; - } - - if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && !$isInvisible) - echo '
'; - - if (isset($field['required']) AND $field['required']) - echo ' *'; - - echo (isset($field['desc']) ? '

'.$field['desc'].'

' : ''); - echo ($isInvisible) ? '

'.$this->l('You can\'t change the value of this configuration field in this shop context').'

' : ''; - echo '
'; + echo '
'; + echo ''; + echo '
'; + if ($required) + echo '
* '.$this->l('Required field').'
'; + + echo '

'; + $this->displayBottomOptionCategory($category, $categoryData); } - echo '
- -
-
- '; - if ($this->formOptions) - echo ''; + echo ''; + } + + /** + * Can be overriden + */ + public function displayTopOptionCategory($category, $data) + { + } + + /** + * Can be overriden + */ + public function displayBottomOptionCategory($category, $data) + { + } + + /** + * Type = select + */ + public function displayOptionTypeSelect($key, $field, $value) + { + echo ''; + } + + /** + * Type = bool + */ + public function displayOptionTypeBool($key, $field, $value) + { + echo ''; + echo ''; + echo ''; + + echo ''; + echo ''; + echo ''; + } + + /** + * Type = radio + */ + public function displayOptionTypeRadio($key, $field, $value) + { + foreach ($field['choices'] as $k => $v) + echo '
'; + echo '
'; + } + + /** + * Type = text + */ + public function displayOptionTypeText($key, $field, $value) + { + echo ''.(isset($field['next']) ? ' '.(string)$field['next'] : ''); + } + + /** + * Type = password + */ + public function displayOptionTypePassword($key, $field, $value) + { + $this->displayOptionTypeText($key, $field, ''); + } + + /** + * Type = textarea + */ + public function displayOptionTypeTextarea($key, $field, $value) + { + echo ''; + } + + /** + * Type = file + */ + public function displayOptionTypeFile($key, $field, $value) + { + if (isset($field['thumb']) && $field['thumb'] && $field['thumb']['pos'] == 'before') + echo ''.$field['title'].'
'; + echo ''; + } + + /** + * Type = image + */ + public function displayOptionTypeImage($key, $field, $value) + { + echo '
'; + echo ''; + + /*if ($name == 'themes') + echo ' + + + + ';*/ + + $i = 0; + foreach ($field['list'] AS $theme) + { + echo ''; + if (isset($field['max']) AND ($i +1 ) % $field['max'] == 0) + echo ''; + $i++; + } + echo ''; + echo '
+ '.$this->l('In order to use a new theme, please follow these steps:', get_class()).' + +
'; + echo ''; + echo ''; + echo '
'; + echo ''; + echo '
'; + } + + /** + * Type = textLang + */ + public function displayOptionTypeTextLang($key, $field, $value) + { + $languages = Language::getLanguages(false); + foreach ($languages as $language) + { + $value = Tools::getValue($key.'_'.$language['id_lang'], Configuration::get($key, $language['id_lang'])); + echo '
'; + echo ''; + echo '
'; + } + $this->displayFlags($languages, $this->context->language->id, $key, $key); + } + + /** + * Type = selectLang + */ + public function displayOptionTypeSelectLang($key, $field, $value) + { + $languages = Language::getLanguages(false); + foreach ($languages as $language) + { + echo '
'; + echo ''; + echo '
'; + } + $this->displayFlags($languages, $this->context->language->id, $key, $key); + } + + /** + * Type = price + */ + public function displayOptionTypePrice($key, $field, $value) + { + echo $this->context->currency->getSign('left'); + $this->displayOptionTypeText($key, $field, $value); + echo $this->context->currency->getSign('right').' '.$this->l('(tax excl.)'); + } + + /** + * Type = disabled + */ + public function displayOptionTypeDisabled($key, $field, $value) + { + echo $field['disabled']; } /** @@ -2137,54 +2383,4 @@ EOF; $url = substr($url, 0, $len - 1); return $url; } - - /** - * Process the submission of a configuration form - * - * @param array $fields - */ - protected function submitConfiguration($fields) - { - $languages = Language::getLanguages(false); - foreach ($fields as $key => $options) - { - if (isset($options['visibility']) && $options['visibility'] > Context::getContext()->shop->getContextType()) - continue; - - if (Shop::isMultiShopActivated() && isset($_POST['configUseDefault'][$key])) - { - Configuration::deleteFromContext($key); - continue; - } - - if ($this->validateField(Tools::getValue($key), $options)) - { - // check if a method updateOptionFieldName is available - $method_name = 'updateOption'.Tools::toCamelCase($key, true); - if (method_exists($this, $method_name)) - $this->$method_name(Tools::getValue($key)); - else if (isset($options['type']) && in_array($options['type'], array('textLang', 'textareaLang'))) - { - $list = array(); - foreach ($languages as $language) - { - $val = (isset($options['cast']) ? $options['cast'](Tools::getValue($key.'_'.$language['id_lang'])) : Tools::getValue($key.'_'.$language['id_lang'])); - if (Validate::isCleanHtml($val)) - $list[$language['id_lang']] = $val; - else - $this->_errors[] = Tools::displayError('Can not add configuration '.$key.' for lang '.Language::getIsoById((int)$language['id_lang'])); - } - Configuration::updateValue($key, $list); - } - else - { - $val = (isset($options['cast']) ? $options['cast'](Tools::getValue($key)) : Tools::getValue($key)); - if (Validate::isCleanHtml($val)) - Configuration::updateValue($key, $val); - else - $this->_errors[] = Tools::displayError('Can not add configuration '.$key); - } - } - } - } } diff --git a/js/admin.js b/js/admin.js index be38bddce..7fbd96c61 100644 --- a/js/admin.js +++ b/js/admin.js @@ -829,18 +829,20 @@ function trackClickOnHelp(label, doc_version) $(document).ready(function() { - $('.multishop_config a').click(function(e) + $('.preference_default_multishop input[type=checkbox]').each(function(k, v) { - var input = $(this).parent().find('input[type=checkbox]'); - input.attr('checked', (!input.attr('checked')) ? true : false); - return false; + var key = $(v).attr('name'); + var len = key.length; + checkMultishopDefaultValue(v, key.substr(17, len - 18)); }); +}); - $('.multishop_config').hover(function() - { - $(this).find('div').fadeIn('fast'); - }, function() - { - $(this).find('div').fadeOut('fast'); - }); -}); \ No newline at end of file +function checkMultishopDefaultValue(obj, key) +{ + $('#conf_id_'+key+' input, #conf_id_'+key+' textarea, #conf_id_'+key+' select').attr('disabled', $(obj).attr('checked')); + $('#conf_id_'+key+' .preference_default_multishop input').attr('disabled', false); + if ($(obj).attr('checked')) + $('#conf_id_'+key+' label.conf_title').addClass('isDisabled'); + else + $('#conf_id_'+key+' label.conf_title').removeClass('isDisabled'); +} \ No newline at end of file