* @copyright PrestaShop * @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0 * @version 1.3 * */ include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); class AdminPreferences extends AdminTab { public function __construct() { global $cookie; $this->className = 'Configuration'; $this->table = 'configuration'; $tmz = Tools::getTimezones(); $txs = Tax::getTaxes(intval($cookie->id_lang)); $timezone = array(); foreach ($tmz as $id => $name) $timezone[] = array('id' => $id, 'name' => $name); $taxes[] = array('id' => 0, 'name' => $this->l('None')); foreach ($txs as $tax) $taxes[] = array('id' => $tax['id_tax'], 'name' => $tax['name']); $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') ) ); $this->_fieldsGeneral = array( 'PS_BASE_URI' => array('title' => $this->l('PS directory:'), 'desc' => $this->l('Name of the PrestaShop directory on your Web server, bracketed by forward slashes (e.g., /shop/)'), 'validation' => 'isGenericName', 'type' => 'text', 'size' => 20, 'default' => '/'), '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'), '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 coma to separate them (e.g., 42.24.4.2,127.0.0.1,99.98.97.96)'), 'validation' => 'isGenericName', 'type' => 'text', 'size' => 15, '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_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'), 'PS_REWRITING_SETTINGS' => array('title' => $this->l('Friendly URL:'), 'desc' => $this->l('Enable only if your server allows URL rewriting (recommended)').'

'.$this->l('If you turn on this feature, you must').' '.$this->l('generate a .htaccess file').'

', 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), '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'), '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'), '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_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 the rounding of prices, rounding always superior, inferior or classical rounding.'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $round_mode, 'identifier' => 'value'), 'PRESTASTORE_LIVE' => array('title' => $this->l('Automatically check updates to modules'), 'desc' => $this->l('New modules and updates are displayed on the modules page'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool')); if (function_exists('date_default_timezone_set')) $this->_fieldsGeneral['PS_TIMEZONE'] = array('title' => $this->l('Timezone:'), 'validation' => 'isUnsignedId', 'cast' => 'intval', 'type' => 'select', 'list' => $timezone, 'identifier' => 'id'); $this->_fieldsGeneral['PS_THEME_V11'] = array('title' => $this->l('v1.1 theme compatibility:'), 'desc' => $this->l('My shop use a PrestaShop v1.1 theme (SSL will generate warnings in customer browser)'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'); parent::__construct(); } public function display() { $this->_displayForm('general', $this->_fieldsGeneral, $this->l('General'), 'width2', 'tab-preferences'); } public function postProcess() { global $currentIndex; if (isset($_POST['submitGeneral'.$this->table])) { if ($this->tabAccess['edit'] === '1') $this->_postConfig($this->_fieldsGeneral); else $this->_errors[] = Tools::displayError('You do not have permission to edit anything 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 anything 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 anything 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($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 anything here.'); } } /** * Update settings in database and configuration files * * @params array $fields Fields settings * * @global string $currentIndex Current URL in order to keep current Tab */ protected function _postConfig($fields) { global $currentIndex; $languages = Language::getLanguages(); /* Check required fields */ foreach ($fields AS $field => $values) if (isset($values['required']) AND $values['required']) if ($values['type'] == 'textLang') { foreach ($languages as $language) if (($value = Tools::getValue($field.'_'.$language['id_lang'])) == false AND (string)$value != '0') $this->_errors[] = Tools::displayError('field').' '.$values['title'].' '.Tools::displayError('is required'); } elseif (($value = Tools::getValue($field)) == false AND (string)$value != '0') $this->_errors[] = Tools::displayError('field').' '.$values['title'].' '.Tools::displayError('is required'); /* Check fields validity */ foreach ($fields AS $field => $values) if ($values['type'] == 'textLang') { foreach ($languages as $language) if (Tools::getValue($field.'_'.$language['id_lang']) AND isset($values['validation'])) if (!Validate::$values['validation'](Tools::getValue($field.'_'.$language['id_lang']))) $this->_errors[] = Tools::displayError('field').' '.$values['title'].' '.Tools::displayError('is invalid'); } elseif (Tools::getValue($field) AND isset($values['validation'])) if (!Validate::$values['validation'](Tools::getValue($field))) $this->_errors[] = Tools::displayError('field').' '.$values['title'].' '.Tools::displayError('is invalid'); /* Default value if null */ foreach ($fields AS $field => $values) if (!Tools::getValue($field) AND isset($values['default'])) $_POST[$field] = $values['default']; /* Save process */ if (!sizeof($this->_errors)) { if (isset($_POST['submitGeneral'.$this->table])) { rewriteSettingsFile(isset($_POST['PS_BASE_URI']) ? $_POST['PS_BASE_URI'] : '', NULL, NULL); unset($this->_fieldsGeneral['PS_BASE_URI']); } elseif (isset($_POST['submitAppearance'.$this->table])) { 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; elseif (!@imageResize($tmpName, _PS_IMG_DIR_.'logo.jpg')) $this->_errors[] = 'an error occured during logo copy'; unlink($tmpName); } $this->uploadIco('PS_FAVICON', _PS_IMG_DIR_.'favicon.ico'); } /* Update settings in database */ if (!sizeof($this->_errors)) { foreach ($fields AS $field => $values) { unset($val); if ($values['type'] == 'textLang') foreach ($languages as $language) $val[$language['id_lang']] = isset($values['cast']) ? $values['cast'](Tools::getValue($field.'_'.$language['id_lang'])) : Tools::getValue($field.'_'.$language['id_lang']); else $val = isset($values['cast']) ? $values['cast'](Tools::getValue($field)) : Tools::getValue($field); Configuration::updateValue($field, $val); } Tools::redirectAdmin($currentIndex.'&conf=6'.'&token='.$this->token); } } } private function getVal($conf, $key) { return Tools::getValue($key, (isset($conf[$key]) ? $conf[$key] : '')); } 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['PS_BASE_URI'] = __PS_BASE_URI__; $tab['PS_THEME'] = _THEME_NAME_; $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) { $tab = array(); foreach ($fields AS $key => $field) if ($field['type'] == 'textLang') $tab[] = $key; return implode('ยค', $tab); } /** * Display configuration form * * @params string $name Form name * @params array $fields Fields settings * * @global string $currentIndex Current URL in order to keep current Tab */ protected function _displayForm($name, $fields, $tabname, $size, $icon) { global $currentIndex; $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT')); $languages = Language::getLanguages(); $confValues = $this->getConf($fields, $languages); $divLangName = $this->getDivLang($fields); $required = false; echo '
'.$tabname.''; foreach ($fields AS $key => $field) { /* Specific line for e-mails settings */ if (get_class($this) == 'Adminemails' AND $key == 'PS_MAIL_SERVER') echo '
'; if (isset($field['required']) AND $field['required']) $required = true; $val = $this->getVal($confValues, $key); if (!in_array($field['type'], array('image', 'radio', 'container', 'container_end')) OR isset($field['show'])) echo '
'.($field['title'] ? '' : '').'
'; /* Display the appropriate input type for each field */ switch ($field['type']) { case 'select': echo ' '; break; case 'bool': echo ' '; break; case 'radio': foreach ($field['choices'] AS $cValue => $cKey) echo '
'; echo '
'; break; case 'image': echo ' '; $i = 0; foreach ($field['list'] AS $theme) { echo ''; if (isset($field['max']) AND ($i+1) % $field['max'] == 0) echo ''; $i++; } echo '

'; break; case 'price': $default_currency = new Currency(intval(Configuration::get("PS_CURRENCY_DEFAULT"))); echo $default_currency->getSign('left').''.$default_currency->getSign('right').' '.$this->l('(tax excl.)'); break; case 'textLang': foreach ($languages as $language) echo '
'; $this->displayFlags($languages, $defaultLanguage, $divLangName, $key); break; case 'file': if (isset($field['thumb']) AND $field['thumb'] AND $field['thumb']['pos'] == 'before') echo ''.$field['title'].'
'; echo ''; break; case 'textarea': echo ''; break; case 'container': echo '
'; break; case 'container_end': echo (isset($field['content']) === true ? $field['content'] : '').'
'; break; case 'text': default: echo ''.(isset($field['next']) ? ' '.strval($field['next']) : ''); } echo ((isset($field['required']) AND $field['required'] AND !in_array($field['type'], array('image', 'radio'))) ? ' *' : ''); echo (isset($field['desc']) ? '

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

' : ''); if (!in_array($field['type'], array('image', 'radio', 'container', 'container_end')) OR isset($field['show'])) echo '
'; } /* End of specific div for e-mails settings */ if (get_class($this) == 'Adminemails') echo '
'; if(!is_writable(PS_ADMIN_DIR.'/../config/settings.inc.php') AND $name == 'themes') echo '

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

'; echo '
'.($required ? '
* '.$this->l('Required field', 'AdminPreferences').'
' : '').'
'; } } ?>