* * @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7465 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ include_once(PS_ADMIN_DIR.'/tabs/AdminPreferences.php'); class AdminDb extends AdminPreferences { public function __construct() { $this->className = 'Configuration'; $this->table = 'configuration'; 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() { if (isset($_POST['submitDatabase'.$this->table])) { if ($this->tabAccess['edit'] === '1') { foreach ($this->optionsList['database']['fields'] AS $field => $values) if (isset($values['required']) AND $values['required']) if (($value = Tools::getValue($field)) == false AND (string)$value != '0') $this->_errors[] = Tools::displayError('field').' '.$values['title'].' '.Tools::displayError('is required.'); if (!sizeof($this->_errors)) { /* Datas are not saved in database but in config/settings.inc.php */ $settings = array(); foreach ($this->optionsList['database']['fields'] as $k => $data) if ($value = Tools::getValue($k)) $settings['_'.Tools::strtoupper($k).'_'] = $value; if (Db::checkConnection( isset($settings['_DB_SERVER_']) ? $settings['_DB_SERVER_'] : _DB_SERVER_, isset($settings['_DB_USER_']) ? $settings['_DB_USER_'] : _DB_USER_, isset($settings['_DB_PASSWD_']) ? $settings['_DB_PASSWD_'] : _DB_PASSWD_, isset($settings['_DB_NAME_']) ? $settings['_DB_NAME_'] : _DB_NAME_, true ) == 0) { rewriteSettingsFile(NULL, NULL, $settings); Tools::redirectAdmin(self::$currentIndex.'&conf=6'.'&token='.$this->token); } else $this->_errors[] = Tools::displayError('Unable to connect to a database with these identifiers.'); } } 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'])) $this->_errors[] = Tools::displayError('You did not select any tables'); else { $available_engines = $this->_getEngines(); $tables_status = $this->_getTablesStatus(); $tables_engine = array(); foreach ($tables_status AS $table) $tables_engine[$table['Name']] = $table['Engine']; $engineType = pSQL(Tools::getValue('engineType')); /* Datas are not saved in database but in config/settings.inc.php */ $settings = array('_MYSQL_ENGINE_' => $engineType); rewriteSettingsFile(NULL, NULL, $settings); foreach ($_POST['tablesBox'] AS $table) { if ($engineType == $tables_engine[$table]) $this->_errors[] = $table.' '.$this->l('is already in').' '.$engineType; else if (!Db::getInstance()->Execute('ALTER TABLE '.pSQL($table).' ENGINE='.pSQL($engineType))) $this->_errors[] = $this->l('Can\'t change engine for').' '.$table; else echo '
'.$this->l('Engine change of').' '.$table.' '.$this->l('to').' '.$engineType.'