// Refactoring of preferences

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7907 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2011-08-05 13:21:40 +00:00
parent bd9366daf5
commit e4825ac555
13 changed files with 961 additions and 968 deletions
+41 -27
View File
@@ -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));
}
}
}
}
+22 -11
View File
@@ -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').' <b>'.$values['title'].'</b> '.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.')).'<br />';
$this->_displayForm('database', $this->_fieldsDatabase, $this->l('Database'), 'width2', 'database_gear');
$this->displayOptionsList();
$engines = $this->_getEngines();
$irow = 0;
echo '<br /><fieldset class="width2"><legend>'.$this->l('MySQL Engine').'</legend><form name="updateEngine" action="'.self::$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post"><table cellspacing="0" cellpadding="0" class="table width2 clear">
+47 -28
View File
@@ -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' => '<script type="text/javascript">if (getE("PS_MAIL_METHOD2_on").checked == false) { $(\'#SMTP_CONTAINER\').hide(); }</script>'),
$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
</div>
</fieldset>';
}
public function displayTopOptionCategory($category, $categoryData)
{
if ($category == 'smtp')
echo '<div id="smtp" style="display: '.((Configuration::get('PS_MAIL_METHOD') == 2) ? 'block' : 'none').';">';
}
public function displayBottomOptionCategory($category, $categoryData)
{
if ($category == 'smtp')
echo '<script type="text/javascript">
if (getE(\'PS_MAIL_METHOD2_on\').checked)
getE(\'smtp\').style.display = \'block\';
else
getE(\'smtp\').style.display = \'none\';
</script>
</div>';
}
}
+27 -22
View File
@@ -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 '<br />
<form method="post" action="'.self::$currentIndex.'&token='.$this->token.'" class="width2" enctype="multipart/form-data">
<fieldset>
@@ -122,6 +128,5 @@ class AdminLocalization extends AdminPreferences
</fieldset>
</form>
<br />';
$this->_displayForm('options', $this->_fieldsOptions, $this->l('Advanced'), 'width2', 'localization');
}
}
+29 -24
View File
@@ -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();
}
}
+45 -50
View File
@@ -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 '<script type="text/javascript">stockManagementActivationAuthorization();</script>';
}
}
+125 -456
View File
@@ -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'] = '<a href="https://'.Tools::getShopDomainSsl().$_SERVER['REQUEST_URI'].'">'.$this->l('Please click here to use HTTPS protocol before enabling SSL.').'</a>';
$fields['PS_SSL_ENABLED']['type'] = 'disabled';
$fields['PS_SSL_ENABLED']['disabled'] = '<a href="https://'.Tools::getShopDomainSsl().$_SERVER['REQUEST_URI'].'">'.$this->l('Please click here to use HTTPS protocol before enabling SSL.').'</a>';
}
$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').' <b>'.$values['title'].'</b> '.Tools::displayError('is required.');
}
elseif (($value = Tools::getValue($field)) == false AND (string)$value != '0')
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.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').' <b>'.$values['title'].'</b> '.Tools::displayError('is invalid.');
}
elseif (Tools::getValue($field) AND isset($values['validation']))
if (!Validate::$values['validation'](Tools::getValue($field)))
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.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 '
<script type="text/javascript">
id_language = Number('.$defaultLanguage.');
function addRemoteAddr(){
var length = $(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\').length;
if (length > 0)
$(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\',$(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\') +\','.Tools::getRemoteAddr().'\');
else
$(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\',\''.Tools::getRemoteAddr().'\');
}
$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;
Configuration::update('PS_ATTACHMENT_MAXIMUM_SIZE', ($maxSize < Tools::getValue('PS_ATTACHMENT_MAXIMUM_SIZE')) ? $maxSize : Tools::getValue('PS_ATTACHMENT_MAXIMUM_SIZE'));
}
</script>
<form action="'.self::$currentIndex.'&submit'.$name.$this->table.'=1&token='.$this->token.'" method="post" enctype="multipart/form-data">
<fieldset><legend><img src="../img/admin/'.strval($icon).'.gif" />'.$tabname.'</legend>';
foreach ($fields AS $key => $field)
{
/* Specific line for e-mails settings */
if (get_class($this) == 'Adminemails' AND $key == 'PS_MAIL_SERVER')
echo '<div id="smtp" style="display: '.((isset($confValues['PS_MAIL_METHOD']) AND $confValues['PS_MAIL_METHOD'] == 2) ? 'block' : 'none').';">';
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 '<script type="text/javascript">
function addRemoteAddr()
{
$isDisabled = true;
$isInvisible = true;
var length = $(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\').length;
if (length > 0)
$(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\',$(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\') +\','.Tools::getRemoteAddr().'\');
else
$(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\',\''.Tools::getRemoteAddr().'\');
}
else if (Context::shop() != Shop::CONTEXT_ALL && !Configuration::isOverridenByCurrentContext($key))
$isDisabled = true;
}
if (!in_array($field['type'], array('image', 'radio', 'container', 'container_end')) OR isset($field['show']))
{
echo '<div style="clear: both; padding-top:15px;" id="conf_id_'.$key.'">';
if ($field['title'])
echo '<label class="conf_title '.(($isDisabled) ? 'isDisabled' : '').'">'.$field['title'].'</label>';
echo '<div class="margin-form" style="padding-top:5px;">';
}
/* Display the appropriate input type for each field */
switch ($field['type'])
{
case 'disabled':
echo $field['disabled'];
break;
case 'select':
echo '
<select name="'.$key.'"'.(isset($field['js']) === true ? ' onchange="'.$field['js'].'"' : '').' id="'.$key.'" '.(($isDisabled) ? 'disabled="disabled"' : '').'>';
foreach ($field['list'] AS $k => $value)
echo '<option value="'.(isset($value['cast']) ? $value['cast']($value[$field['identifier']]) : $value[$field['identifier']]).'"'.(($val == $value[$field['identifier']]) ? ' selected="selected"' : '').'>'.$value['name'].'</option>';
echo '
</select>';
break;
case 'selectLang':
foreach ($languages as $language)
{
echo '
<div id="'.$key.'_'.$language['id_lang'].'" style="margin-bottom:8px; display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').'; float: left; vertical-align: top;">
<select name="'.$key.'_'.strtoupper($language['iso_code']).'">';
foreach ($field['list'] AS $k => $value)
echo '<option value="'.(isset($value['cast']) ? $value['cast']($value[$field['identifier']]) : $value[$field['identifier']]).'"'.((htmlentities(Tools::getValue($key.'_'.strtoupper($language['iso_code']), (Configuration::get($key.'_'.strtoupper($language['iso_code'])) ? Configuration::get($key.'_'.strtoupper($language['iso_code'])) : '')), ENT_COMPAT, 'UTF-8') == $value[$field['identifier']]) ? ' selected="selected"' : '').'>'.$value['name'].'</option>';
echo '
</select>
</div>';
}
$this->displayFlags($languages, $defaultLanguage, $divLangName, $key);
break;
case 'bool':
echo '<label class="t" for="'.$key.'_on"><img src="../img/admin/enabled.gif" alt="'.$this->l('Yes').'" title="'.$this->l('Yes').'" /></label>
<input type="radio" name="'.$key.'" id="'.$key.'_on" value="1"'.($val ? ' checked="checked"' : '').(isset($field['js']['on']) ? $field['js']['on'] : '').' '.(($isDisabled) ? 'disabled="disabled"' : '').' />
<label class="t" for="'.$key.'_on"> '.$this->l('Yes').'</label>
<label class="t" for="'.$key.'_off"><img src="../img/admin/disabled.gif" alt="'.$this->l('No').'" title="'.$this->l('No').'" style="margin-left: 10px;" /></label>
<input type="radio" name="'.$key.'" id="'.$key.'_off" value="0" '.(!$val ? 'checked="checked"' : '').(isset($field['js']['off']) ? $field['js']['off'] : '').' '.(($isDisabled) ? 'disabled="disabled"' : '').' />
<label class="t" for="'.$key.'_off"> '.$this->l('No').'</label>';
break;
case 'radio':
foreach ($field['choices'] AS $cValue => $cKey)
echo '<input type="radio" name="'.$key.'" id="'.$key.$cValue.'_on" value="'.(int)($cValue).'"'.(($cValue == $val) ? ' checked="checked"' : '').(isset($field['js'][$cValue]) ? ' '.$field['js'][$cValue] : '').' '.(($isDisabled) ? 'disabled="disabled"' : '').' /><label class="t" for="'.$key.$cValue.'_on"> '.$cKey.'</label><br />';
echo '<br />';
break;
case 'image':
echo '
<table cellspacing="0" cellpadding="0">
<tr>';
if ($name == 'themes')
echo '
<td colspan="'.sizeof($field['list']).'">
<b>'.$this->l('In order to use a new theme, please follow these steps:', get_class()).'</b>
<ul>
<li>'.$this->l('Import your theme using this module:', get_class()).' <a href="index.php?tab=AdminModules&token='.Tools::getAdminTokenLite('AdminModules').'&filtername=themeinstallator" style="text-decoration: underline;">'.$this->l('Theme installer', get_class()).'</a></li>
<li>'.$this->l('When your theme is imported, please select the theme in this page', get_class()).'</li>
</ul>
</td>
</tr>
<tr>
';
$i = 0;
foreach ($field['list'] AS $theme)
{
echo '<td class="center" style="width: 180px; padding:0px 20px 20px 0px;">
<input type="radio" name="'.$key.'" id="'.$key.'_'.$theme['name'].'_on" style="vertical-align: text-bottom;" value="'.$theme['name'].'"'.
(_THEME_NAME_ == $theme['name'] ? 'checked="checked"' : '').' '.(($isDisabled) ? 'disabled="disabled"' : '').' />
<label class="t" for="'.$key.'_'.$theme['name'].'_on"> '.Tools::strtolower($theme['name']).'</label>
<br />
<label class="t" for="'.$key.'_'.$theme['name'].'_on">
<img src="../themes/'.$theme['name'].'/preview.jpg" alt="'.Tools::strtolower($theme['name']).'">
</label>
</td>';
if (isset($field['max']) AND ($i+1) % $field['max'] == 0)
echo '</tr><tr>';
$i++;
}
echo '</tr>
</table>';
break;
case 'price':
echo $this->context->currency->getSign('left').'<input type="'.$field['type'].'" size="'.(isset($field['size']) ? (int)($field['size']) : 5).'" name="'.$key.'" value="'.($field['type'] == 'password' ? '' : htmlentities($val, ENT_COMPAT, 'UTF-8')).'" '.(($isDisabled) ? 'disabled="disabled"' : '').' />'.$this->context->currency->getSign('right').' '.$this->l('(tax excl.)');
break;
case 'textLang':
foreach ($languages as $language)
echo '
<div id="'.$key.'_'.$language['id_lang'].'" style="margin-bottom:8px; display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').'; float: left; vertical-align: top;">
<input type="text" size="'.(isset($field['size']) ? (int)($field['size']) : 5).'" name="'.$key.'_'.$language['id_lang'].'" value="'.htmlentities($this->getVal($confValues, $key.'_'.$language['id_lang']), ENT_COMPAT, 'UTF-8').'" '.(($isDisabled) ? 'disabled="disabled"' : '').' />
</div>';
$this->displayFlags($languages, $defaultLanguage, $divLangName, $key);
break;
case 'file':
if (isset($field['thumb']) AND $field['thumb'] AND $field['thumb']['pos'] == 'before')
echo '<img src="'.$field['thumb']['file'].'" alt="'.$field['title'].'" title="'.$field['title'].'" /><br />';
echo '<input type="file" name="'.$key.'" '.(($isDisabled) ? 'disabled="disabled"' : '').' />';
break;
case 'textarea':
echo '<textarea name='.$key.' cols="'.$field['cols'].'" rows="'.$field['rows'].'" '.(($isDisabled) ? 'disabled="disabled"' : '').'>'.htmlentities($val, ENT_COMPAT, 'UTF-8').'</textarea>';
break;
case 'container':
echo '<div id="'.$key.'">';
break;
case 'container_end':
echo (isset($field['content']) === true ? $field['content'] : '').'</div>';
break;
case 'maintenance_ip':
echo '<input type="'.$field['type'].'"'.(isset($field['id']) === true ? ' id="'.$field['id'].'"' : '').(($isDisabled) ? 'disabled="disabled"' : '').' size="'.(isset($field['size']) ? (int)($field['size']) : 5).'" name="'.$key.'" value="'.($field['type'] == 'password' ? '' : htmlentities($val, ENT_COMPAT, 'UTF-8')).'" />'.(isset($field['next']) ? '&nbsp;'.strval($field['next']) : '').' &nbsp<a href="#" class="button" onclick="addRemoteAddr(); return false;">'.$this->l('Add my IP').'</a>';
break;
case 'text':
default:
echo '<input type="'.$field['type'].'"'.(isset($field['id']) === true ? ' id="'.$field['id'].'"' : '').(($isDisabled) ? 'disabled="disabled"' : '').' size="'.(isset($field['size']) ? (int)($field['size']) : 5).'" name="'.$key.'" value="'.($field['type'] == 'password' ? '' : htmlentities($val, ENT_COMPAT, 'UTF-8')).'" />'.(isset($field['next']) ? '&nbsp;'.strval($field['next']) : '');
}
echo ((isset($field['required']) AND $field['required'] AND !in_array($field['type'], array('image', 'radio'))) ? ' <sup>*</sup>' : '');
if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && !$isInvisible)
echo '<div class="preference_default_multishop"><label><input type="checkbox" name="configUseDefault['.$key.']" value="1" '.(($isDisabled) ? 'checked="checked"' : '') .' onclick="$(\'#conf_id_'.$key.' input, #conf_id_'.$key.' textarea, #conf_id_'.$key.' select\').attr(\'disabled\', $(this).attr(\'checked\')); $(\'#conf_id_'.$key.' .preference_default_multishop input\').attr(\'disabled\', false); $(\'#conf_id_'.$key.' label.conf_title\').toggleClass(\'isDisabled\');" /> '.$this->l('Use default value').'</label></div>';
echo (isset($field['desc']) ? '<p class="preference_description">'.((isset($field['thumb']) AND $field['thumb'] AND $field['thumb']['pos'] == 'after') ? '<img src="'.$field['thumb']['file'].'" alt="'.$field['title'].'" title="'.$field['title'].'" style="float:left;" />' : '' ).$field['desc'].'</p>' : '');
echo ($isInvisible) ? '<p><img src="../img/admin/warning.gif" /> <b>'.$this->l('You can\'t change the value of this configuration field in this shop context').'</b></p>' : '';
if (!in_array($field['type'], array('image', 'radio', 'container', 'container_end')) OR isset($field['show']))
echo '</div></div>';
}
/* End of specific div for e-mails settings */
if (get_class($this) == 'Adminemails')
echo '<script type="text/javascript">if (getE(\'PS_MAIL_METHOD2_on\').checked) getE(\'smtp\').style.display = \'block\'; else getE(\'smtp\').style.display = \'none\';</script></div>';
if(!is_writable(PS_ADMIN_DIR.'/../config/settings.inc.php') AND $name == 'themes')
echo '<p><img src="../img/admin/warning.gif" alt="" /> '.$this->l('if you change the theme, the settings.inc.php file must be writable (CHMOD 755 / 777)').'</p>';
echo ' <div align="center" style="margin-top: 20px;">
<input type="submit" value="'.$this->l(' Save ', 'AdminPreferences').'" name="submit'.ucfirst($name).$this->table.'" class="button" />
</div>
'.($required ? '<div class="small"><sup>*</sup> '.$this->l('Required field', 'AdminPreferences').'</div>' : '').'
</fieldset>
</form>';
</script>';
$this->displayOptionTypeText($key, $field, $value);
echo (isset($field['next']) ? '&nbsp;'.strval($field['next']) : '');
echo ' &nbsp<a href="#" class="button" onclick="addRemoteAddr(); return false;">'.$this->l('Add my IP').'</a>';
}
public function displayBottomOptionCategory($category, $categoryData)
{
if (get_class($this) == 'AdminPreferences')
echo '<script type="text/javascript">changeCMSActivationAuthorization();</script>';
}
}
+65 -60
View File
@@ -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.').'<br />'.$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.').'<br />'.$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.').'<br />'.$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.').'<br />'.$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 '
<fieldset>
<legend><img src="../img/admin/search.gif" alt="" /> '.$this->l('Indexation').'</legend>
<p>
'.$this->l('The "indexed" products have been analysed by PrestaShop and will appear in the results of the front office search.').'<br />
'.$this->l('Indexed products:').' <b>'.(int)($indexed).' / '.(int)($total).'</b>.
</p>
<p>'.$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".').'</p>
-&gt; <a href="searchcron.php?token='.substr(_COOKIE_KEY_, 34, 8).'" class="bold">'.$this->l('Add missing products to index.').'</a><br />
-&gt; <a href="searchcron.php?full=1&token='.substr(_COOKIE_KEY_, 34, 8).'" class="bold">'.$this->l('Re-build entire index.').'</a><br /><br />
'.$this->l('You can set a cron job that will re-build your index using the following URL:').' <a href="'.$cronUrl.'">'.$cronUrl.'</a>.
</fieldset>
<div class="clear">&nbsp;</div>';
$this->_displayForm('search', $this->_fieldsSearch, $this->l('Search'), 'width2', 'search');
echo '
<div class="clear">&nbsp;</div>
<fieldset>
<legend><img src="../img/admin/search.gif" alt="" /> '.$this->l('Relevance').'</legend>
'.$this->l('The "weight" represents its importance and relevance for the ranking of the products when try a new search.').'<br />
'.$this->l('A word with a weight of 8 will have 4 times more value than a word with a weight of 2.').'<br /><br />
'.$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.').'
</fieldset>
<div class="clear">&nbsp;</div>';
$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 '<fieldset>
<legend><img src="../img/admin/search.gif" alt="" /> '.$this->l('Indexation').'</legend>
<p>
'.$this->l('The "indexed" products have been analysed by PrestaShop and will appear in the results of the front office search.').'<br />
'.$this->l('Indexed products:').' <b>'.(int)($indexed).' / '.(int)($total).'</b>.
</p>
<p>'.$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".').'</p>
-&gt; <a href="searchcron.php?token='.substr(_COOKIE_KEY_, 34, 8).'" class="bold">'.$this->l('Add missing products to index.').'</a><br />
-&gt; <a href="searchcron.php?full=1&token='.substr(_COOKIE_KEY_, 34, 8).'" class="bold">'.$this->l('Re-build entire index.').'</a><br /><br />
'.$this->l('You can set a cron job that will re-build your index using the following URL:').' <a href="'.$cronUrl.'">'.$cronUrl.'</a>.
</fieldset>
<div class="clear">&nbsp;</div>';
break;
case 'weight' :
echo '<div class="clear">&nbsp;</div>
<fieldset>
<legend><img src="../img/admin/search.gif" alt="" /> '.$this->l('Relevance').'</legend>
'.$this->l('The "weight" represents its importance and relevance for the ranking of the products when try a new search.').'<br />
'.$this->l('A word with a weight of 8 will have 4 times more value than a word with a weight of 2.').'<br /><br />
'.$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.').'
</fieldset>
<div class="clear">&nbsp;</div>';
break;
}
}
}
+57 -74
View File
@@ -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 '<script type="text/javascript">var engineDescriptions = '.Tools::jsonEncode($listEngineDescription).';</script>';
$this->displayOptionTypeSelect($key, $field, $value);
echo '<div id="render_engine_description">'.$listEngineDescription[$value].'</div>';
}
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 '<form action="'.self::$currentIndex.'&token='.$this->token.'&submitSettings=1" method="post">
<fieldset><legend><img src="../img/admin/tab-preferences.gif" />'.$this->l('Settings').'</legend>';
#Graph Engines
echo '<label class="clear">'.$this->l('Graph engine').': </label><div class="margin-form">';
if (sizeof($arrayGraphEngines))
{
foreach ($arrayGraphEngines as $k => $value)
echo '<div id="sgraphcontent_'.$k.'">'.$value[1].'</div><script language="javascript">getE(\'sgraphcontent_'.$k.'\').style.display = \'none\';</script>';
echo '<div style="float: left"><select name="PS_STATS_RENDER">';
foreach ($arrayGraphEngines as $k => $value)
echo '<option value="'.$k.'"'.($k == $graphEngine ? ' selected="selected"' : '').' onclick="getE(\'render_graph_content\').innerHTML = getE(\'sgraphcontent_'.$k.'\').innerHTML;">'.$value[0].'</option>';
echo '</select></div>
<div id="render_graph_content" style="float:left;margin-left:20px;width:400px;">'.$arrayGraphEngines[$graphEngine][1].'</div>
<div class="clear"></div>';
}
else
echo $this->l('No graph engine module installed');
echo '</div>';
#Grid Engines
echo '<label class="clear">'.$this->l('Grid engine').': </label><div class="margin-form">';
if (sizeof($arrayGridEngines))
{
foreach ($arrayGridEngines as $k => $value)
echo '<div id="sgridcontent_'.$k.'">'.$value[1].' </div><script language="javascript">getE(\'sgridcontent_'.$k.'\').style.display = \'none\';</script>';
echo '<div style="float: left"><select name="PS_STATS_GRID_RENDER">';
foreach ($arrayGridEngines as $k => $value)
echo '<option value="'.$k.'"'.($k == $gridEngine ? ' selected="selected"' : '').' onclick="getE(\'render_grid_content\').innerHTML = getE(\'sgridcontent_'.$k.'\').innerHTML;">'.$value[0].'</option>';
echo '</select></div>
<div id="render_grid_content" style="float:left;margin-left:20px;width:400px;">'.$arrayGridEngines[$gridEngine][1].'</div>
<div class="clear"></div>';
}
else
echo $this->l('No grid engine module installed');
echo '</div>';
echo '<label class="clear">'.$this->l('Clean automatically').': </label>
<div class="margin-form">
<select id="PS_STATS_OLD_CONNECT_AUTO_CLEAN" name="PS_STATS_OLD_CONNECT_AUTO_CLEAN">';
foreach ($autocleanPeriod as $k => $value)
echo ' <option value="'.$k.'"'.($k == $autoclean ? ' selected="selected"' : '').'>'.$value.'&nbsp;</option>';
echo ' </select>
</div>';
#End Of Form
echo '<input type="submit" value="'.$this->l(' Save ').'" name="submitSettings" class="button" />
</fieldset>
</form>';
$field['list'] = $listEngine;
$field['identifier'] = 'value';
$field['js'] = '$(\'#render_grid_description\').html(gridDescriptions[$(this).val()])';
echo '<script type="text/javascript">var gridDescriptions = '.Tools::jsonEncode($listEngineDescription).';</script>';
$this->displayOptionTypeSelect($key, $field, $value);
echo '<div id="render_grid_description">'.$listEngineDescription[$value].'</div>';
}
}
+3 -11
View File
@@ -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');
+120 -23
View File
@@ -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)').'<br />'.$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)').'<br />'.$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 '<br /><br />';
if (@ini_get('allow_url_fopen') AND @fsockopen('addons.prestashop.com', 80, $errno, $errst, 3))
echo '<script type="text/javascript">
@@ -129,14 +140,15 @@ class AdminThemes extends AdminPreferences
echo '<a href="http://addons.prestashop.com/3-prestashop-themes">'.$this->l('Find new themes on PrestaShop Addons!').'</a>';
}
/** This function checks if the theme designer has thunk to make his theme compatible 1.4,
* and noticed it on the $theme_dir/config.xml file. If not, some new functionnalities has
* to be desactivated
*
* @since 1.4
* @param string $theme_dir theme directory
* @return boolean Validity is ok or not
*/
/**
* This function checks if the theme designer has thunk to make his theme compatible 1.4,
* and noticed it on the $theme_dir/config.xml file. If not, some new functionnalities has
* to be desactivated
*
* @since 1.4
* @param string $theme_dir theme directory
* @return boolean Validity is ok or not
*/
private function _isThemeCompatible($theme_dir)
{
$all_errors='';
@@ -235,21 +247,106 @@ class AdminThemes extends AdminPreferences
return $return;
}
/** this functions make checks about AdminThemes configuration edition only.
/**
* This functions make checks about AdminThemes configuration edition only.
*
* @since 1.4
*/
public function postProcess()
{
global $smarty;
// new check compatibility theme feature (1.4) :
$val = Tools::getValue('PS_THEME');
Configuration::updateValue('PS_IMG_UPDATE_TIME', time());
if (!empty($val) AND !$this->_isThemeCompatible($val)) // don't submit if errors
unset($_POST['submitThemes'.$this->table]);
Tools::clearCache($smarty);
Tools::clearCache($this->context->smarty);
parent::postProcess();
}
}
/**
* Update PS_LOGO
*/
public function updateOptionPsLogo()
{
$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);
}
}
/**
* Update PS_LOGO_MAIL
*/
public function updateOptionPsLogoMail()
{
$id_shop = Context::getContext()->shop->getID();
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);
}
}
/**
* Update PS_LOGO_INVOICE
*/
public function updateOptionPsLogoInvoice()
{
$id_shop = Context::getContext()->shop->getID();
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);
}
}
/**
* Update PS_STORES_ICON
*/
public function updateOptionPsStoresIcon()
{
$id_shop = Context::getContext()->shop->getID();
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');
}
}
+366 -170
View File
@@ -888,18 +888,114 @@ abstract class AdminTabCore
Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.$this->table.'_'.$type.' (`'.pSQL($this->identifier).'`, id_'.$type.')
VALUES('.(int)$asso['id_object'].', '.(int)$asso['id_'.$type].')');
}
/**
* Update options and preferences
*
* @param string $token
*/
protected function updateOptions($token)
{
if ($this->tabAccess['edit'] === '1')
{
$this->submitConfiguration($this->_fieldsOptions);
$this->beforeUpdateOptions();
$languages = Language::getLanguages(false);
foreach ($this->optionsList as $category => $categoryData)
{
$fields = $categoryData['fields'];
/* 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').' <b>'.$values['title'].'</b> '.Tools::displayError('is required.');
}
elseif (($value = Tools::getValue($field)) == false AND (string)$value != '0')
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.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').' <b>'.$values['title'].'</b> '.Tools::displayError('is invalid.');
}
elseif (Tools::getValue($field) AND isset($values['validation']))
if (!Validate::$values['validation'](Tools::getValue($field)))
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.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'];
if (!sizeof($this->_errors))
{
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;
}
// 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 ($this->validateField($val, $options))
{
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 ($this->validateField($val, $options))
{
if (Validate::isCleanHtml($val))
Configuration::updateValue($key, $val);
else
$this->_errors[] = Tools::displayError('Can not add configuration '.$key);
}
}
}
}
}
if (count($this->_errors) <= 0)
Tools::redirectAdmin(self::$currentIndex.'&conf=6&token='.$token);
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
/**
* Can be overriden
*/
public function beforeUpdateOptions()
{
}
protected function validateField($value, $field)
{
@@ -1126,7 +1222,6 @@ abstract class AdminTabCore
*/
public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = false)
{
/* Manage default params values */
if (empty($limit))
$limit = ((!isset($this->context->cookie->{$this->table.'_pagination'})) ? $this->_pagination[1] : $limit = $this->context->cookie->{$this->table.'_pagination'});
@@ -1673,134 +1768,285 @@ abstract class AdminTabCore
/**
* Options lists
*
* @param array $fieldsOptions Since 1.5.0
* @param string $optionTitle Since 1.5.0
*/
public function displayOptionsList($fieldsOptions = null, $optionTitle = null, $optionDescription = null)
public function displayOptionsList()
{
if (is_null($fieldsOptions))
$fieldsOptions = $this->_fieldsOptions;
$tab = Tab::getTab($this->context->language->id, $this->id);
if (!isset($fieldsOptions) OR !sizeof($fieldsOptions))
return false;
if (is_null($optionTitle))
$optionTitle = $this->optionTitle;
$defaultLanguage = (int)$this->context->language->id;
$this->_languages = Language::getLanguages(false);
$tab = Tab::getTab($defaultLanguage, $this->id);
echo '<br /><br />';
echo ($optionTitle ? '<h2>'.$optionTitle.'</h2>' : '');
echo '
<script type="text/javascript">
id_language = Number('.$defaultLanguage.');
</script>
'.(($this->formOptions) ? '<form action="'.self::$currentIndex.'" id="'.$tab['name'].'" name="'.$tab['name'].'" method="post">' : '').'
<fieldset>';
echo ($optionTitle ? '<legend>
<img src="'.(!empty($tab['module']) && file_exists($_SERVER['DOCUMENT_ROOT']._MODULE_DIR_.$tab['module'].'/'.$tab['class_name'].'.gif') ? _MODULE_DIR_.$tab['module'].'/' : '../img/t/').$tab['class_name'].'.gif" />'
.$optionTitle.'</legend>' : '');
if ($optionDescription)
echo '<p class="optionsDescription">'.$optionDescription.'</p>';
foreach ($fieldsOptions AS $key => $field)
echo '<script type="text/javascript">
id_language = Number('.$this->context->language->id.');
</script>';
echo '<form action="'.self::$currentIndex.'&submitOptions'.$this->table.'=1&token='.$this->token.'" method="post" enctype="multipart/form-data">';
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 '<fieldset>';
// 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 = '<img src="'.(!empty($tab['module']) && file_exists($_SERVER['DOCUMENT_ROOT']._MODULE_DIR_.$tab['module'].'/'.$tab['class_name'].'.gif') ? _MODULE_DIR_.$tab['module'].'/' : '../img/t/').$tab['class_name'].'.gif" /> ';
$legend .= ((isset($categoryData['title'])) ? $categoryData['title'] : $this->l('Options'));
echo '<legend>'.$legend.'</legend>';
// Category fields
if (!isset($categoryData['fields']))
continue;
// Category description
if (isset($categoryData['description']) && $categoryData['description'])
echo '<p class="optionsDescription">'.$categoryData['description'].'</p>';
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 '<div style="clear: both; padding-top:15px;" id="conf_id_'.$key.'">';
if ($field['title'])
{
echo '<label class="conf_title">';
// Is this field required ?
if (isset($field['required']) && $field['required'])
{
$required = true;
echo '<sup>*</sup> ';
}
echo $field['title'].'</label>';
}
echo '<div class="margin-form" style="padding-top:5px;">';
// Display option inputs
$method = 'displayOptionType'.Tools::toCamelCase($field['type'], true);
if (!method_exists($this, $method))
echo 'Option method '.get_class($this).'-&gt;'.$method.'() not found<br />';
else
$this->$method($key, $field, $value);
// Multishop default value
if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && !$isInvisible)
echo '<div class="preference_default_multishop">
<label>
<input type="checkbox" name="configUseDefault['.$key.']" value="1" '.(($isDisabled) ? 'checked="checked"' : '').' onclick="checkMultishopDefaultValue(this, \''.$key.'\')" /> '.$this->l('Use default value').'
</label>
</div>';
// Field description
//echo (isset($field['desc']) ? '<p class="preference_description">'.((isset($field['thumb']) AND $field['thumb'] AND $field['thumb']['pos'] == 'after') ? '<img src="'.$field['thumb']['file'].'" alt="'.$field['title'].'" title="'.$field['title'].'" style="float:left;" />' : '' ).$field['desc'].'</p>' : '');
echo (isset($field['desc']) ? '<p class="preference_description">'.$field['desc'].'</p>' : '');
// Is this field invisible in current shop context ?
echo ($isInvisible) ? '<p><img src="../img/admin/warning.gif" /> <b>'.$this->l('You can\'t change the value of this configuration field in this shop context').'</b></p>' : '';
echo '</div></div>';
}
echo '<div id="conf_id_'.$key.'"><label>'.$field['title'].' </label>
<div class="margin-form">';
switch ($field['type'])
{
case 'select':
echo '<select name="'.$key.'" '.(($isDisabled) ? 'disabled="disabled"' : '').'>';
foreach ($field['list'] AS $value)
echo '<option value="'.(isset($field['cast']) ? $field['cast']($value[$field['identifier']]) : $value[$field['identifier']]).'"'.($val == $value[$field['identifier']] ? ' selected="selected"' : '').'>'.$value['name'].'</option>';
echo '</select>';
break;
case 'bool':
echo '<label class="t" for="'.$key.'_on"><img src="../img/admin/enabled.gif" alt="'.$this->l('Yes').'" title="'.$this->l('Yes').'" /></label>
<input type="radio" name="'.$key.'" id="'.$key.'_on" value="1"'.($val ? ' checked="checked"' : '').' '.(($isDisabled) ? 'disabled="disabled"' : '').' />
<label class="t" for="'.$key.'_on"> '.$this->l('Yes').'</label>
<label class="t" for="'.$key.'_off"><img src="../img/admin/disabled.gif" alt="'.$this->l('No').'" title="'.$this->l('No').'" style="margin-left: 10px;" /></label>
<input type="radio" name="'.$key.'" id="'.$key.'_off" value="0" '.(!$val ? 'checked="checked"' : '').' '.(($isDisabled) ? 'disabled="disabled"' : '').' />
<label class="t" for="'.$key.'_off"> '.$this->l('No').'</label>';
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 '
<div id="'.$key.'_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').'; float: left;">
<input size="'.$field['size'].'" type="text" name="'.$key.'_'.$language['id_lang'].'" value="'.$val.'" '.(($isDisabled) ? 'disabled="disabled"' : '').' />
</div>';
}
$this->displayFlags($this->_languages, $defaultLanguage, $key, $key);
echo '<br style="clear:both">';
break;
case 'textareaLang':
foreach ($this->_languages as $language)
{
$val = Configuration::get($key, $language['id_lang']);
echo '
<div id="'.$key.'_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').'; float: left;">
<textarea rows="'.(int)($field['rows']).'" cols="'.(int)($field['cols']).'" name="'.$key.'_'.$language['id_lang'].'" '.(($isDisabled) ? 'disabled="disabled"' : '').'>'.str_replace('\r\n', "\n", $val).'</textarea>
</div>';
}
$this->displayFlags($this->_languages, $defaultLanguage, $key, $key);
echo '<br style="clear:both">';
break;
case 'text':
default:
echo '<input type="text" name="'.$key.'" value="'.$val.'" size="'.$field['size'].'" '.(($isDisabled) ? 'disabled="disabled"' : '').' />'.(isset($field['suffix']) ? $field['suffix'] : '');
break;
}
if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && !$isInvisible)
echo '<div class="preference_default_multishop"><label><input type="checkbox" name="configUseDefault['.$key.']" value="1" '.(($isDisabled) ? 'checked="checked"' : '') .' onclick="$(\'#conf_id_'.$key.' input, #conf_id_'.$key.' textarea, #conf_id_'.$key.' select\').attr(\'disabled\', $(this).attr(\'checked\')); $(\'#conf_id_'.$key.' .preference_default_multishop input\').attr(\'disabled\', false); $(\'#conf_id_'.$key.' label.conf_title\').toggleClass(\'isDisabled\');" /> '.$this->l('Use default value').'</label></div>';
if (isset($field['required']) AND $field['required'])
echo ' <sup>*</sup>';
echo (isset($field['desc']) ? '<p>'.$field['desc'].'</p>' : '');
echo ($isInvisible) ? '<p><img src="../img/admin/warning.gif" /> <b>'.$this->l('You can\'t change the value of this configuration field in this shop context').'</b></p>' : '';
echo '</div></div>';
echo '<div align="center" style="margin-top: 20px;">';
echo '<input type="submit" value="'.$this->l(' Save ').'" name="submit'.ucfirst($category).$this->table.'" class="button" />';
echo '</div>';
if ($required)
echo '<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>';
echo '</fieldset><br />';
$this->displayBottomOptionCategory($category, $categoryData);
}
echo '<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitOptions'.$this->table.'" class="button" />
</div>
</fieldset>
<input type="hidden" name="token" value="'.$this->token.'" />';
if ($this->formOptions)
echo '</form>';
echo '</form>';
}
/**
* 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 '<select name="'.$key.'"'.(isset($field['js']) === true ? ' onchange="'.$field['js'].'"' : '').' id="'.$key.'">';
foreach ($field['list'] AS $k => $option)
echo '<option value="'.(isset($option['cast']) ? $option['cast']($option[$field['identifier']]) : $option[$field['identifier']]).'"'.(($value == $option[$field['identifier']]) ? ' selected="selected"' : '').'>'.$option['name'].'</option>';
echo '</select>';
}
/**
* Type = bool
*/
public function displayOptionTypeBool($key, $field, $value)
{
echo '<label class="t" for="'.$key.'_on"><img src="../img/admin/enabled.gif" alt="'.$this->l('Yes').'" title="'.$this->l('Yes').'" /></label>';
echo '<input type="radio" name="'.$key.'" id="'.$key.'_on" value="1" '.($value ? ' checked="checked" ' : '').(isset($field['js']['on']) ? $field['js']['on'] : '').' />';
echo '<label class="t" for="'.$key.'_on"> '.$this->l('Yes').'</label>';
echo '<label class="t" for="'.$key.'_off"><img src="../img/admin/disabled.gif" alt="'.$this->l('No').'" title="'.$this->l('No').'" style="margin-left: 10px;" /></label>';
echo '<input type="radio" name="'.$key.'" id="'.$key.'_off" value="0" '.(!$value ? ' checked="checked" ' : '').(isset($field['js']['off']) ? $field['js']['off'] : '').' />';
echo '<label class="t" for="'.$key.'_off"> '.$this->l('No').'</label>';
}
/**
* Type = radio
*/
public function displayOptionTypeRadio($key, $field, $value)
{
foreach ($field['choices'] as $k => $v)
echo '<input type="radio" name="'.$key.'" id="'.$key.$k.'_on" value="'.(int)$v.'"'.(($k == $value) ? ' checked="checked"' : '').(isset($field['js'][$k]) ? ' '.$field['js'][$k] : '').' /><label class="t" for="'.$key.$k.'_on"> '.$v.'</label><br />';
echo '<br />';
}
/**
* Type = text
*/
public function displayOptionTypeText($key, $field, $value)
{
echo '<input type="'.$field['type'].'"'.(isset($field['id']) ? ' id="'.$field['id'].'"' : '').' size="'.(isset($field['size']) ? (int)$field['size'] : 5).'" name="'.$key.'" value="'.htmlentities($value, ENT_COMPAT, 'UTF-8').'" />'.(isset($field['next']) ? '&nbsp;'.(string)$field['next'] : '');
}
/**
* Type = password
*/
public function displayOptionTypePassword($key, $field, $value)
{
$this->displayOptionTypeText($key, $field, '');
}
/**
* Type = textarea
*/
public function displayOptionTypeTextarea($key, $field, $value)
{
echo '<textarea name='.$key.' cols="'.$field['cols'].'" rows="'.$field['rows'].'">'.htmlentities($value, ENT_COMPAT, 'UTF-8').'</textarea>';
}
/**
* Type = file
*/
public function displayOptionTypeFile($key, $field, $value)
{
if (isset($field['thumb']) && $field['thumb'] && $field['thumb']['pos'] == 'before')
echo '<img src="'.$field['thumb']['file'].'" alt="'.$field['title'].'" title="'.$field['title'].'" /><br />';
echo '<input type="file" name="'.$key.'" />';
}
/**
* Type = image
*/
public function displayOptionTypeImage($key, $field, $value)
{
echo '<table cellspacing="0" cellpadding="0">';
echo '<tr>';
/*if ($name == 'themes')
echo '
<td colspan="'.sizeof($field['list']).'">
<b>'.$this->l('In order to use a new theme, please follow these steps:', get_class()).'</b>
<ul>
<li>'.$this->l('Import your theme using this module:', get_class()).' <a href="index.php?tab=AdminModules&token='.Tools::getAdminTokenLite('AdminModules').'&filtername=themeinstallator" style="text-decoration: underline;">'.$this->l('Theme installer', get_class()).'</a></li>
<li>'.$this->l('When your theme is imported, please select the theme in this page', get_class()).'</li>
</ul>
</td>
</tr>
<tr>
';*/
$i = 0;
foreach ($field['list'] AS $theme)
{
echo '<td class="center" style="width: 180px; padding:0px 20px 20px 0px;">';
echo '<input type="radio" name="'.$key.'" id="'.$key.'_'.$theme['name'].'_on" style="vertical-align: text-bottom;" value="'.$theme['name'].'"'.(_THEME_NAME_ == $theme['name'] ? 'checked="checked"' : '').' />';
echo '<label class="t" for="'.$key.'_'.$theme['name'].'_on"> '.Tools::strtolower($theme['name']).'</label>';
echo '<br />';
echo '<label class="t" for="'.$key.'_'.$theme['name'].'_on">';
echo '<img src="../themes/'.$theme['name'].'/preview.jpg" alt="'.Tools::strtolower($theme['name']).'">';
echo '</label>';
echo '</td>';
if (isset($field['max']) AND ($i +1 ) % $field['max'] == 0)
echo '</tr><tr>';
$i++;
}
echo '</tr>';
echo '</table>';
}
/**
* 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 '<div id="'.$key.'_'.$language['id_lang'].'" style="margin-bottom:8px; display: '.($language['id_lang'] == $this->context->language->id ? 'block' : 'none').'; float: left; vertical-align: top;">';
echo '<input type="text" size="'.(isset($field['size']) ? (int)$field['size'] : 5).'" name="'.$key.'_'.$language['id_lang'].'" value="'.htmlentities($value, ENT_COMPAT, 'UTF-8').'" />';
echo '</div>';
}
$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 '<div id="'.$key.'_'.$language['id_lang'].'" style="margin-bottom:8px; display: '.($language['id_lang'] == $this->context->language->id ? 'block' : 'none').'; float: left; vertical-align: top;">';
echo '<select name="'.$key.'_'.strtoupper($language['iso_code']).'">';
foreach ($field['list'] as $k => $v)
echo '<option value="'.(isset($v['cast']) ? $v['cast']($v[$field['identifier']]) : $v[$field['identifier']]).'"'.((htmlentities(Tools::getValue($key.'_'.strtoupper($language['iso_code']), (Configuration::get($key.'_'.strtoupper($language['iso_code'])) ? Configuration::get($key.'_'.strtoupper($language['iso_code'])) : '')), ENT_COMPAT, 'UTF-8') == $v[$field['identifier']]) ? ' selected="selected"' : '').'>'.$v['name'].'</option>';
echo '</select>';
echo '</div>';
}
$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);
}
}
}
}
}
+14 -12
View File
@@ -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');
});
});
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');
}