diff --git a/admin-dev/themes/template/adminRequestSql.tpl b/admin-dev/themes/template/adminRequestSql.tpl deleted file mode 100644 index 7429f28ba..000000000 --- a/admin-dev/themes/template/adminRequestSql.tpl +++ /dev/null @@ -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 -* @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} -
- {l s ='How to create a new sql query?'} -
- -

-{/if} - -{if $warning} -
{l s ='Warning: when saving the query, only the request type "SELECT" are allowed.'}
-{/if} - -{if isset($view)} - {if isset($view['error'])} -

{l s ='This query has no result.'}

- {else} -

{$view['name']}

- - - {foreach $view['key'] AS $key} - - {/foreach} - - {foreach $view['results'] AS $result} - - {foreach $view['key'] AS $name} - {if isset($view['attributes'][$name])} - - {else} - - {/if} - {/foreach} - - {/foreach} -
{$key}
{$view['attributes'][$name]}{$result[$name]}
- - - {/if} -{elseif isset($tab_form)} -
- {if $tab_form['id']}{/if} -
{l s ='Request'} - -
- -
- -
- -
-
- -
-
* {l s ='Required field'}
-
-
-{/if} - -{$content} \ No newline at end of file diff --git a/admin-dev/themes/template/request_sql/view.tpl b/admin-dev/themes/template/request_sql/view.tpl new file mode 100644 index 000000000..1ef3217d0 --- /dev/null +++ b/admin-dev/themes/template/request_sql/view.tpl @@ -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 +* @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'])} +

{l s ='This query has no result.'}

+{else} +

{$view['name']}

+ + + + {foreach $view['key'] AS $key} + + {/foreach} + + + + {foreach $view['results'] AS $result} + + {foreach $view['key'] AS $name} + {if isset($view['attributes'][$name])} + + {else} + + {/if} + {/foreach} + + {/foreach} + +
{$key}
{$view['attributes'][$name]}{$result[$name]}
+ + +{/if} + +

+ +{if isset($back)} + {l s='Back to list'} +{/if} +
+ diff --git a/classes/AdminController.php b/classes/AdminController.php index 22909b13d..80ee37928 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -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); diff --git a/controllers/admin/AdminRequestSqlController.php b/controllers/admin/AdminRequestSqlController.php index cca728ee6..73fdf6f68 100644 --- a/controllers/admin/AdminRequestSqlController.php +++ b/controllers/admin/AdminRequestSqlController.php @@ -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(' + '.$this->l('How to create a new sql query?').' +
+ '); - 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(); - } - }