[*] BO #PSFV-94 : update of the displayform method by helperForm in AdminRequestSqlController
This commit is contained in:
@@ -1,97 +0,0 @@
|
||||
{*
|
||||
* 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: 8897 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
|
||||
{if $info}
|
||||
<div class="hint clear" style="display:block;">
|
||||
<b>{l s ='How to create a new sql query?'}</b>
|
||||
<br />
|
||||
<ul>
|
||||
<li>{l s ='Click "Add new".'}<br /></li>
|
||||
<li>{l s ='Fill in the fields and click "Save".'}</li>
|
||||
<li>{l s ='You can then view the query results by clicking on the tab: '} <img src="../img/admin/details.gif"></li>
|
||||
<li>{l s ='You can then export the query results as a file. Csv file by clicking on the tab: '} <img src="../img/admin/export.gif"></li>
|
||||
</ul>
|
||||
</div><br />
|
||||
{/if}
|
||||
|
||||
{if $warning}
|
||||
<div class="warn"><img src="../img/admin/warn2.png">{l s ='Warning: when saving the query, only the request type "SELECT" are allowed.'}</div>
|
||||
{/if}
|
||||
|
||||
{if isset($view)}
|
||||
{if isset($view['error'])}
|
||||
<p>{l s ='This query has no result.'}</p>
|
||||
{else}
|
||||
<h2>{$view['name']}</h2>
|
||||
<table cellpadding="0" cellspacing="0" class="table" id="viewRequestSql">
|
||||
<tr>
|
||||
{foreach $view['key'] AS $key}
|
||||
<th align="center">{$key}</th>
|
||||
{/foreach}
|
||||
</tr>
|
||||
{foreach $view['results'] AS $result}
|
||||
<tr>
|
||||
{foreach $view['key'] AS $name}
|
||||
{if isset($view['attributes'][$name])}
|
||||
<td>{$view['attributes'][$name]}</td>
|
||||
{else}
|
||||
<td>{$result[$name]}</td>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
var width = $('#viewRequestSql').width();
|
||||
if (width > 990){
|
||||
$('#viewRequestSql').css('display','block').css('overflow-x', 'scroll');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{/if}
|
||||
{elseif isset($tab_form)}
|
||||
<form action="{$tab_form['current']}" method="post">
|
||||
{if $tab_form['id']}<input type="hidden" name="id_{$tab_form['table']}" value="{$tab_form['id']}" />{/if}
|
||||
<fieldset><legend><img src="../img/admin/subdomain.gif" />{l s ='Request'}</legend>
|
||||
<label>{l s ='Name:'} <sup>*</sup></label>
|
||||
<div class="margin-form">
|
||||
<input type="text" name="name" value="{$tab_form['name']}" size="103" />
|
||||
</div>
|
||||
<label>{l s ='Request:'} <sup>*</sup></label>
|
||||
<div class="margin-form">
|
||||
<textarea name="sql" cols="100" rows="10">{$tab_form['sql']}</textarea>
|
||||
</div>
|
||||
<div class="margin-form">
|
||||
<input type="submit" value="{l s ='Save'}" name="submitAdd{$tab_form['table']}" class="button" />
|
||||
</div>
|
||||
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
{/if}
|
||||
|
||||
{$content}
|
||||
@@ -0,0 +1,70 @@
|
||||
{*
|
||||
* 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: 8897 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
|
||||
{if isset($view['error'])}
|
||||
<p>{l s ='This query has no result.'}</p>
|
||||
{else}
|
||||
<h2>{$view['name']}</h2>
|
||||
<table cellpadding="0" cellspacing="0" class="table" id="viewRequestSql">
|
||||
<thead>
|
||||
<tr>
|
||||
{foreach $view['key'] AS $key}
|
||||
<th align="center">{$key}</th>
|
||||
{/foreach}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach $view['results'] AS $result}
|
||||
<tr>
|
||||
{foreach $view['key'] AS $name}
|
||||
{if isset($view['attributes'][$name])}
|
||||
<td>{$view['attributes'][$name]}</td>
|
||||
{else}
|
||||
<td>{$result[$name]}</td>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
var width = $('#viewRequestSql').width();
|
||||
if (width > 990){
|
||||
$('#viewRequestSql').css('display','block').css('overflow-x', 'scroll');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{/if}
|
||||
|
||||
<br /><br />
|
||||
|
||||
{if isset($back)}
|
||||
<a href="{$back}"><img src="../img/admin/arrow2.gif" />{l s='Back to list'}</a>
|
||||
{/if}
|
||||
<br />
|
||||
|
||||
@@ -911,7 +911,6 @@ class AdminControllerCore extends Controller
|
||||
$helper::$currentIndex = self::$currentIndex;
|
||||
$helper->token = $this->token;
|
||||
$helper->table = $this->table;
|
||||
$helper->table = $this->table;
|
||||
$helper->id = $obj->id;
|
||||
$helper->fields_value = $this->getFieldsValue($obj);
|
||||
$this->content .= $helper->generateForm($this->fields_form);
|
||||
|
||||
@@ -27,9 +27,6 @@
|
||||
|
||||
class AdminRequestSqlControllerCore extends AdminController
|
||||
{
|
||||
private $info = true;
|
||||
private $warning = true;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = 'request_sql';
|
||||
@@ -53,23 +50,125 @@ class AdminRequestSqlControllerCore extends AdminController
|
||||
'sql' => array('title' => $this->l('Request'), 'width' => 500)
|
||||
);
|
||||
|
||||
$this->template = 'adminRequestSql.tpl';
|
||||
$this->fields_form = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Request')
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Name:'),
|
||||
'name' => 'name',
|
||||
'size' => 103,
|
||||
'required' => true
|
||||
),
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Request:'),
|
||||
'name' => 'sql',
|
||||
'cols' => 100,
|
||||
'rows' => 10,
|
||||
'required' => true
|
||||
)
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l(' Save '),
|
||||
'class' => 'button'
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
public function viewRequestSql()
|
||||
{
|
||||
if (!($obj = $this->loadObject(true)))
|
||||
return;
|
||||
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT `id_request_sql`
|
||||
FROM `'._DB_PREFIX_.'request_sql`
|
||||
$content = array();
|
||||
|
||||
if ($results = Db::getInstance()->executeS($obj->sql))
|
||||
{
|
||||
foreach (array_keys($results[0]) as $key)
|
||||
$tab_key[] = $key;
|
||||
|
||||
$content['name'] = $obj->name;
|
||||
$content['key'] = $tab_key;
|
||||
$content['results'] = $results;
|
||||
|
||||
$request_sql = new RequestSql();
|
||||
$content['attributes'] = $request_sql->attributes;
|
||||
}
|
||||
else
|
||||
$content['error'] = true;
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function _childValidation()
|
||||
{
|
||||
if (Tools::getValue('submitAdd'.$this->table) && $sql = Tools::getValue('sql'))
|
||||
{
|
||||
$request_sql = new RequestSql();
|
||||
$parser = $request_sql->parsingSql($sql);
|
||||
$validate = $request_sql->validateParser($parser, false, $sql);
|
||||
|
||||
if (!$validate || !empty($request_sql->error_sql))
|
||||
$this->displayError($request_sql->error_sql);
|
||||
}
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
if (isset($_GET['view'.$this->table]) && isset($_GET['id_'.$this->table]))
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1' || ($this->table == 'employee' && $this->context->employee->id == Tools::getValue('id_employee')))
|
||||
$this->display = 'view';
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
||||
}
|
||||
parent::init();
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
$this->displayWarning($this->l('When saving the query, only the request type "SELECT" are allowed.'));
|
||||
$this->displayInformation('
|
||||
<strong>'.$this->l('How to create a new sql query?').'</strong>
|
||||
<br />
|
||||
<ul>
|
||||
<li>'.$this->l('Click "Add new".').'<br /></li>
|
||||
<li>'.$this->l('Fill in the fields and click "Save".').'</li>
|
||||
<li>'.$this->l('You can then view the query results by clicking on the tab: ').' <img src="../img/admin/details.gif"></li>
|
||||
<li>'.$this->l('You can then export the query results as a file. Csv file by clicking on the tab: ').' <img src="../img/admin/export.gif"></li>
|
||||
</ul>
|
||||
');
|
||||
|
||||
if (!count($this->_errors))
|
||||
parent::postProcess();
|
||||
$smarty = $this->context->smarty;
|
||||
switch ($this->display)
|
||||
{
|
||||
case 'edit':
|
||||
$this->informations = false;
|
||||
break;
|
||||
|
||||
case 'view':
|
||||
$this->warnings = false;
|
||||
$this->informations = false;
|
||||
|
||||
if (Tools::getValue('back'))
|
||||
$smarty->assign('back', Tools::safeOutput(Tools::getValue('back')));
|
||||
else
|
||||
$smarty->assign('back', Tools::safeOutput(self::$currentIndex.'&token='.$this->token));
|
||||
|
||||
$smarty->assign('view', $this->viewRequestSql());
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->display = 'list';
|
||||
break;
|
||||
}
|
||||
|
||||
parent::initContent();
|
||||
}
|
||||
|
||||
public function bulkexport($boxes)
|
||||
@@ -134,43 +233,6 @@ class AdminRequestSqlControllerCore extends AdminController
|
||||
return $val;
|
||||
}
|
||||
|
||||
public function viewRequest_sql()
|
||||
{
|
||||
if (!($obj = $this->loadObject(true)))
|
||||
return;
|
||||
|
||||
$view = array();
|
||||
|
||||
if ($results = Db::getInstance()->executeS($obj->sql))
|
||||
{
|
||||
foreach (array_keys($results[0]) as $key)
|
||||
$tab_key[] = $key;
|
||||
|
||||
$view['name'] = $obj->name;
|
||||
$view['key'] = $tab_key;
|
||||
$view['results'] = $results;
|
||||
|
||||
$request_sql = new RequestSql();
|
||||
$view['attributes'] = $request_sql->attributes;
|
||||
}
|
||||
else
|
||||
$view['error'] = true;
|
||||
return $view;
|
||||
}
|
||||
|
||||
public function _childValidation()
|
||||
{
|
||||
if (Tools::getValue('submitAdd'.$this->table) && $sql = Tools::getValue('sql'))
|
||||
{
|
||||
$request_sql = new RequestSql();
|
||||
$parser = $request_sql->parsingSql($sql);
|
||||
$validate = $request_sql->validateParser($parser, false, $sql);
|
||||
|
||||
if (!$validate || !empty($request_sql->error_sql))
|
||||
$this->displayError($request_sql->error_sql);
|
||||
}
|
||||
}
|
||||
|
||||
public function displayError($e)
|
||||
{
|
||||
foreach (array_keys($e) as $key)
|
||||
@@ -257,62 +319,6 @@ class AdminRequestSqlControllerCore extends AdminController
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function displayForm($isMainTab = true)
|
||||
{
|
||||
$this->content .= parent::displayForm();
|
||||
|
||||
if (!($obj = $this->loadObject(true)))
|
||||
return;
|
||||
|
||||
$smarty = $this->context->smarty;
|
||||
$smarty->assign('tab_form', array(
|
||||
'current' => self::$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token,
|
||||
'id' => $obj->id,
|
||||
'table' => $this->table,
|
||||
'name' => $this->getFieldValue($obj, 'name'),
|
||||
'sql' => $this->getFieldValue($obj, 'sql')
|
||||
));
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
if (isset($_GET['view'.$this->table]) && isset($_GET['id_'.$this->table]))
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1' || ($this->table == 'employee' && $this->context->employee->id == Tools::getValue('id_employee')))
|
||||
$this->display = 'view';
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
||||
}
|
||||
parent::init();
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
$smarty = $this->context->smarty;
|
||||
switch ($this->display)
|
||||
{
|
||||
case 'edit':
|
||||
$this->info = false;
|
||||
break;
|
||||
case 'view':
|
||||
$this->info = false;
|
||||
$this->warning = false;
|
||||
$smarty->assign('view', $this->viewRequest_sql());
|
||||
break;
|
||||
default:
|
||||
$this->display = 'list';
|
||||
break;
|
||||
}
|
||||
|
||||
$smarty->assign(array(
|
||||
'info' => $this->info,
|
||||
'warning' =>$this->warning,
|
||||
));
|
||||
|
||||
parent::initContent();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user