[*] BO : #PSFV-94 - added AdminDbController
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9452 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -1,182 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @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()
|
||||
{
|
||||
/* PrestaShop demo mode */
|
||||
if (_PS_MODE_DEMO_)
|
||||
{
|
||||
$this->_errors[] = Tools::displayError('This functionnality has been disabled.');
|
||||
return;
|
||||
}
|
||||
/* PrestaShop demo mode*/
|
||||
|
||||
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').' <b>'.$values['title'].'</b> '.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 `'.bqSQL($table).'` ENGINE=`'.bqSQL($engineType).'`'))
|
||||
$this->_errors[] = $this->l('Can\'t change engine for').' '.$table;
|
||||
else
|
||||
echo '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.$this->l('Engine change of').' '.$table.' '.$this->l('to').' '.$engineType.'</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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->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">
|
||||
<tr><th><input type="checkbox" onclick="checkDelBoxes(this.form, \'tablesBox[]\', this.checked)" class="noborder" name="checkme"></th><th>'.$this->l('Table').'</th><th>'.$this->l('Table Engine').'</th></tr>';
|
||||
$tables_status = $this->_getTablesStatus();
|
||||
foreach ($tables_status AS $table)
|
||||
{
|
||||
if (!preg_match('/^'._DB_PREFIX_.'.*/Ui', $table['Name']))
|
||||
continue;
|
||||
echo '<tr class="'.($irow++ % 2 ? 'alt_row' : '').'">
|
||||
<td class="noborder"><input type="checkbox" name="tablesBox[]" value="'.$table['Name'].'"/></td><td>'.$table['Name'].'</td><td>'.$table['Engine'].'</td>
|
||||
</tr>';
|
||||
}
|
||||
echo '</table><br />
|
||||
<label for="dbEngine">'.$this->l('Change Engine to').'</label>
|
||||
<div class="margin-form">
|
||||
<select name="engineType">';
|
||||
foreach ($engines AS $engine)
|
||||
echo '<option value="'.$engine.'">'.$engine.'</option>';
|
||||
echo '</select>
|
||||
<input style="margin-left:15px;" class="button" type="submit" value="Submit" name="submitEngine" />
|
||||
</div>
|
||||
</fieldset>';
|
||||
}
|
||||
|
||||
private function _getEngines()
|
||||
{
|
||||
$engines = Db::getInstance()->executeS('SHOW ENGINES');
|
||||
$allowed_engines = array();
|
||||
foreach ($engines AS $engine)
|
||||
{
|
||||
if (in_array($engine['Engine'], array('InnoDB', 'MyISAM')) AND in_array($engine['Support'], array('DEFAULT', 'YES')))
|
||||
$allowed_engines[] = $engine['Engine'];
|
||||
}
|
||||
return $allowed_engines;
|
||||
}
|
||||
|
||||
private function _getTablesStatus()
|
||||
{
|
||||
return Db::getInstance()->executeS('SHOW TABLE STATUS');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
{/foreach}
|
||||
{if $requiredFields}
|
||||
{if $required_fields}
|
||||
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
|
||||
{/if}
|
||||
</fieldset>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
{*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
|
||||
<br />
|
||||
{$content}
|
||||
<br />
|
||||
<fieldset class="width2">
|
||||
<legend>{l s='MySQL Engine'}</legend>
|
||||
<form name="updateEngine" action="{$update_url}" method="post">
|
||||
<table cellspacing="0" cellpadding="0" class="table width2 clear">
|
||||
<tr>
|
||||
<th><input type="checkbox" onclick="checkDelBoxes(this.form, 'tablesBox[]', this.checked)" class="noborder" name="checkme"></th>
|
||||
<th>{l s='Table'}</th><th>{l s='Table Engine'}</th>
|
||||
</tr>
|
||||
{foreach $table_status AS $table}
|
||||
<tr class="{if $table@iteration is even}alt_row{/if}">
|
||||
<td class="noborder"><input type="checkbox" name="tablesBox[]" value="{$table['Name']}"/></td><td>{$table['Name']}</td><td>{$table['Engine']}</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
<br />
|
||||
<label for="dbEngine">{l s='Change Engine to'}</label>
|
||||
<div class="margin-form">
|
||||
<select name="engineType">
|
||||
{foreach $engines AS $engine}
|
||||
<option value="{$engine}">{$engine}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
<input style="margin-left:15px;" class="button" type="submit" value="Submit" name="submitEngine" />
|
||||
</div>
|
||||
</form>
|
||||
</fieldset>
|
||||
@@ -248,7 +248,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
{/foreach}
|
||||
{if $requiredFields}
|
||||
{if $required_fields}
|
||||
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
|
||||
{/if}
|
||||
</fieldset>
|
||||
|
||||
@@ -145,7 +145,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
{/foreach}
|
||||
{if $requiredFields}
|
||||
{if $required_fields}
|
||||
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
|
||||
{/if}
|
||||
</fieldset>
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
{/foreach}
|
||||
{if $requiredFields}
|
||||
{if $required_fields}
|
||||
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
|
||||
{/if}
|
||||
</fieldset>
|
||||
|
||||
@@ -25,75 +25,74 @@
|
||||
*}
|
||||
|
||||
{if !$simple_header}
|
||||
|
||||
<link href="../css/admin.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$('.filter').keypress(function(event){
|
||||
formSubmit(event, 'submitFilterButton{$table}')
|
||||
})
|
||||
});
|
||||
</script>
|
||||
{* Display column names and arrows for ordering (ASC, DESC) *}
|
||||
{if $is_order_position}
|
||||
<script type="text/javascript" src="../js/jquery/jquery.tablednd_0_5.js"></script>
|
||||
<link href="../css/admin.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
var token = '{$token}';
|
||||
var come_from = '{$table}';
|
||||
var alternate = {if $order_way == 'DESC'}'1'{else}'0'{/if};
|
||||
$(document).ready(function() {
|
||||
$('.filter').keypress(function(event){
|
||||
formSubmit(event, 'submitFilterButton{$table}')
|
||||
})
|
||||
});
|
||||
</script>
|
||||
<script type="text/javascript" src="../js/admin-dnd.js"></script>
|
||||
{/if}
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
if ($(".datepicker").length > 0)
|
||||
$(".datepicker").datepicker({
|
||||
prevText: '',
|
||||
nextText: ''
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
{if $add_button}
|
||||
<br /><a href="{$currentIndex}&add{$table}&token={$token}"><img src="../img/admin/add.gif" border="0" /> {l s='Add new'}</a><br /><br />
|
||||
{/if}
|
||||
<a name="{$table}"> </a>
|
||||
|
||||
<form method="post" action="{$action}" class="form">
|
||||
{* Display column names and arrows for ordering (ASC, DESC) *}
|
||||
{if $is_order_position}
|
||||
<script type="text/javascript" src="../js/jquery/jquery.tablednd_0_5.js"></script>
|
||||
<script type="text/javascript">
|
||||
var token = '{$token}';
|
||||
var come_from = '{$table}';
|
||||
var alternate = {if $order_way == 'DESC'}'1'{else}'0'{/if};
|
||||
</script>
|
||||
<script type="text/javascript" src="../js/admin-dnd.js"></script>
|
||||
{/if}
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
if ($(".datepicker").length > 0)
|
||||
$(".datepicker").datepicker({
|
||||
prevText: '',
|
||||
nextText: ''
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
{if $add_button}
|
||||
<br /><a href="{$currentIndex}&add{$table}&token={$token}"><img src="../img/admin/add.gif" border="0" /> {l s='Add new'}</a><br /><br />
|
||||
{/if}
|
||||
<a name="{$table}"> </a>
|
||||
|
||||
<form method="post" action="{$action}" class="form">
|
||||
{/if}{* End if simple_header *}
|
||||
<input type="hidden" id="submitFilter{$table}" name="submitFilter{$table}" value="0"/>
|
||||
<table style="table-layout: fixed; width: 100%;">
|
||||
{if !$simple_header}
|
||||
<tr>
|
||||
<td style="vertical-align: bottom;">
|
||||
<span style="float: left;">
|
||||
{if $page > 1}
|
||||
<input type="image" src="../img/admin/list-prev2.gif" onclick="getE(\'submitFilter{$table}\').value=1"/>
|
||||
<input type="image" src="../img/admin/list-prev.gif" onclick="getE(\'submitFilter{$table}\').value={$page - 1}"/>
|
||||
{/if}
|
||||
{l s='Page '}<b>{$page}</b> / {$total_pages}
|
||||
{if $page < $total_pages}
|
||||
<input type="image" src="../img/admin/list-next.gif" onclick="getE(\'submitFilter{$table}\').value={$page + 1}"/>
|
||||
<input type="image" src="../img/admin/list-next2.gif" onclick="getE(\'submitFilter{$table}'\').value={$total_pages}"/>
|
||||
{/if}
|
||||
| {l s='Display'}
|
||||
<select name="pagination">
|
||||
{* Choose number of results per page *}
|
||||
{foreach $pagination AS $value}
|
||||
<option value="{$value|intval}"{if $selected_pagination == $value} selected="selected" {elseif $selected_pagination == NULL && $value == $pagination[1]} selected="selected2"{/if}>{$value|intval}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
/ {$list_total} {l s='result(s)'}
|
||||
</span>
|
||||
<span style="float: right;">
|
||||
<input type="submit" name="submitReset{$table}" value="{l s='Reset'}" class="button" />
|
||||
<input type="submit" id="submitFilterButton{$table}" name="submitFilter" value="{l s='Filter'}" class="button" />
|
||||
</span>
|
||||
<span class="clear"></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="vertical-align: bottom;">
|
||||
<span style="float: left;">
|
||||
{if $page > 1}
|
||||
<input type="image" src="../img/admin/list-prev2.gif" onclick="getE(\'submitFilter{$table}\').value=1"/>
|
||||
<input type="image" src="../img/admin/list-prev.gif" onclick="getE(\'submitFilter{$table}\').value={$page - 1}"/>
|
||||
{/if}
|
||||
{l s='Page '}<b>{$page}</b> / {$total_pages}
|
||||
{if $page < $total_pages}
|
||||
<input type="image" src="../img/admin/list-next.gif" onclick="getE(\'submitFilter{$table}\').value={$page + 1}"/>
|
||||
<input type="image" src="../img/admin/list-next2.gif" onclick="getE(\'submitFilter{$table}'\').value={$total_pages}"/>
|
||||
{/if}
|
||||
| {l s='Display'}
|
||||
<select name="pagination">
|
||||
{* Choose number of results per page *}
|
||||
{foreach $pagination AS $value}
|
||||
<option value="{$value|intval}"{if $selected_pagination == $value} selected="selected" {elseif $selected_pagination == NULL && $value == $pagination[1]} selected="selected2"{/if}>{$value|intval}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
/ {$list_total} {l s='result(s)'}
|
||||
</span>
|
||||
<span style="float: right;">
|
||||
<input type="submit" name="submitReset{$table}" value="{l s='Reset'}" class="button" />
|
||||
<input type="submit" id="submitFilterButton{$table}" name="submitFilter" value="{l s='Filter'}" class="button" />
|
||||
</span>
|
||||
<span class="clear"></span>
|
||||
</td>
|
||||
</tr>
|
||||
{/if}
|
||||
<tr>
|
||||
<td{if $simple_header} style="border:none;"{/if}>
|
||||
|
||||
@@ -154,8 +154,8 @@
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
{if $field['required']}
|
||||
<div class="small"><sup>*</sup> {l s='Required field'}</div>
|
||||
{if $required_fields}
|
||||
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
|
||||
{/if}
|
||||
</fieldset><br />
|
||||
{if isset($categoryData['bottom'])}{$categoryData['bottom']}{/if}
|
||||
|
||||
@@ -206,7 +206,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
{/foreach}
|
||||
{if $requiredFields}
|
||||
{if $required_fields}
|
||||
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
|
||||
{/if}
|
||||
</fieldset>
|
||||
|
||||
@@ -277,7 +277,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
{/foreach}
|
||||
{if $requiredFields}
|
||||
{if $required_fields}
|
||||
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
|
||||
{/if}
|
||||
</fieldset>
|
||||
|
||||
Reference in New Issue
Block a user