// Split AdminController::init() in init() and initProcess()
This commit is contained in:
1 parent
19c7177e91
commit
e37b922e8e
2 files changed
+78
-72
No files matched your search
+66
-72
@@ -358,46 +358,13 @@ class AdminControllerCore extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo uses redirectAdmin only if !$this->ajax
|
* Set the filters used for the list display
|
||||||
*/
|
*/
|
||||||
public function postProcess()
|
public function processFilter()
|
||||||
{
|
{
|
||||||
if ($this->ajax)
|
$filters = $this->context->cookie->getFamily($this->table.'Filter_');
|
||||||
{
|
|
||||||
// from ajax-tab.php
|
|
||||||
$action = Tools::getValue('action');
|
|
||||||
// no need to use displayConf() here
|
|
||||||
if (!empty($action) && method_exists($this, 'ajaxProcess'.Tools::toCamelCase($action)))
|
|
||||||
return $this->{'ajaxProcess'.Tools::toCamelCase($action)}();
|
|
||||||
else if (method_exists($this, 'ajaxProcess'))
|
|
||||||
return $this->ajaxProcess();
|
|
||||||
|
|
||||||
// @TODO We should use a displayAjaxError
|
foreach ($filters as $key => $value)
|
||||||
/*$this->displayErrors();
|
|
||||||
if (!empty($action) && method_exists($this, 'displayAjax'.Tools::toCamelCase($action)))
|
|
||||||
$this->{'displayAjax'.$action}();
|
|
||||||
else
|
|
||||||
$this->displayAjax(); */
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!isset($this->table))
|
|
||||||
return false;
|
|
||||||
// set token
|
|
||||||
$token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
|
|
||||||
|
|
||||||
if (!empty($this->action) && method_exists($this, 'process'.ucfirst(Tools::toCamelCase($this->action))))
|
|
||||||
return $this->{'process'.Tools::toCamelCase($this->action)}($token);
|
|
||||||
else if (method_exists($this, $this->action))
|
|
||||||
return call_user_func(array($this, $this->action), $this->boxes);
|
|
||||||
|
|
||||||
// @todo put list filtering somewhere else
|
|
||||||
/* Manage list filtering */
|
|
||||||
if ($this->filter)
|
|
||||||
{
|
|
||||||
$_POST = array_merge($this->context->cookie->getFamily($this->table.'Filter_'), (isset($_POST) ? $_POST : array()));
|
|
||||||
|
|
||||||
foreach ($_POST as $key => $value)
|
|
||||||
{
|
{
|
||||||
/* Extracting filters from $_POST on key filter_ */
|
/* Extracting filters from $_POST on key filter_ */
|
||||||
if ($value != null && !strncmp($key, $this->table.'Filter_', 7 + Tools::strlen($this->table)))
|
if ($value != null && !strncmp($key, $this->table.'Filter_', 7 + Tools::strlen($this->table)))
|
||||||
@@ -413,6 +380,8 @@ class AdminControllerCore extends Controller
|
|||||||
if (($type == 'date' || $type == 'datetime') && is_string($value))
|
if (($type == 'date' || $type == 'datetime') && is_string($value))
|
||||||
$value = unserialize($value);
|
$value = unserialize($value);
|
||||||
$key = isset($tmp_tab[1]) ? $tmp_tab[0].'.`'.$tmp_tab[1].'`' : '`'.$tmp_tab[0].'`';
|
$key = isset($tmp_tab[1]) ? $tmp_tab[0].'.`'.$tmp_tab[1].'`' : '`'.$tmp_tab[0].'`';
|
||||||
|
|
||||||
|
// Assignement by reference
|
||||||
if (array_key_exists('tmpTableFilter', $field))
|
if (array_key_exists('tmpTableFilter', $field))
|
||||||
$sql_filter = & $this->_tmpTableFilter;
|
$sql_filter = & $this->_tmpTableFilter;
|
||||||
else if (array_key_exists('havingFilter', $field))
|
else if (array_key_exists('havingFilter', $field))
|
||||||
@@ -457,6 +426,43 @@ class AdminControllerCore extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @todo uses redirectAdmin only if !$this->ajax
|
||||||
|
*/
|
||||||
|
public function postProcess()
|
||||||
|
{
|
||||||
|
if ($this->ajax)
|
||||||
|
{
|
||||||
|
// from ajax-tab.php
|
||||||
|
$action = Tools::getValue('action');
|
||||||
|
// no need to use displayConf() here
|
||||||
|
if (!empty($action) && method_exists($this, 'ajaxProcess'.Tools::toCamelCase($action)))
|
||||||
|
return $this->{'ajaxProcess'.Tools::toCamelCase($action)}();
|
||||||
|
else if (method_exists($this, 'ajaxProcess'))
|
||||||
|
return $this->ajaxProcess();
|
||||||
|
|
||||||
|
/*if (!empty($action) && method_exists($this, 'displayAjax'.Tools::toCamelCase($action)))
|
||||||
|
$this->{'displayAjax'.$action}();
|
||||||
|
else
|
||||||
|
$this->displayAjax(); */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!isset($this->table))
|
||||||
|
return false;
|
||||||
|
// set token
|
||||||
|
$token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
|
||||||
|
|
||||||
|
// Process list filtering
|
||||||
|
if ($this->filter)
|
||||||
|
$this->processFilter();
|
||||||
|
|
||||||
|
if (!empty($this->action) && method_exists($this, 'process'.ucfirst(Tools::toCamelCase($this->action))))
|
||||||
|
return $this->{'process'.Tools::toCamelCase($this->action)}($token);
|
||||||
|
else if (method_exists($this, $this->action))
|
||||||
|
return call_user_func(array($this, $this->action), $this->boxes);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -544,12 +550,6 @@ class AdminControllerCore extends Controller
|
|||||||
|
|
||||||
/* Object update */
|
/* Object update */
|
||||||
if (isset($id) && !empty($id))
|
if (isset($id) && !empty($id))
|
||||||
{
|
|
||||||
if ($this->tabAccess['edit'] === '1' || (
|
|
||||||
$this->table == 'employee' &&
|
|
||||||
$this->context->employee->id == Tools::getValue('id_employee') &&
|
|
||||||
Tools::isSubmit('updateemployee')
|
|
||||||
))
|
|
||||||
{
|
{
|
||||||
$object = new $this->className($id);
|
$object = new $this->className($id);
|
||||||
if (Validate::isLoadedObject($object))
|
if (Validate::isLoadedObject($object))
|
||||||
@@ -614,14 +614,9 @@ class AdminControllerCore extends Controller
|
|||||||
$this->_errors[] = Tools::displayError('An error occurred while updating object.').
|
$this->_errors[] = Tools::displayError('An error occurred while updating object.').
|
||||||
' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
|
' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
|
||||||
}
|
}
|
||||||
else
|
|
||||||
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Object creation */
|
/* Object creation */
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if ($this->tabAccess['add'] === '1')
|
|
||||||
{
|
{
|
||||||
$object = new $this->className();
|
$object = new $this->className();
|
||||||
$this->copyFromPost($object, $this->table);
|
$this->copyFromPost($object, $this->table);
|
||||||
@@ -647,9 +642,6 @@ class AdminControllerCore extends Controller
|
|||||||
$this->redirect_after = self::$currentIndex.($parent_id ? '&'.$this->identifier.'='.$object->id : '').'&conf=3&token='.$token;
|
$this->redirect_after = self::$currentIndex.($parent_id ? '&'.$this->identifier.'='.$object->id : '').'&conf=3&token='.$token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_errors = array_unique($this->_errors);
|
$this->_errors = array_unique($this->_errors);
|
||||||
@@ -1597,7 +1589,8 @@ class AdminControllerCore extends Controller
|
|||||||
*/
|
*/
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
// ob_start();
|
parent::init();
|
||||||
|
|
||||||
if (Tools::getValue('ajax'))
|
if (Tools::getValue('ajax'))
|
||||||
$this->ajax = '1';
|
$this->ajax = '1';
|
||||||
|
|
||||||
@@ -1620,12 +1613,6 @@ class AdminControllerCore extends Controller
|
|||||||
$current_index .= '&back='.urlencode($back);
|
$current_index .= '&back='.urlencode($back);
|
||||||
self::$currentIndex = $current_index;
|
self::$currentIndex = $current_index;
|
||||||
|
|
||||||
|
|
||||||
// @todo : put the definitions in Controller class
|
|
||||||
if (!defined('_PS_BASE_URL_'))
|
|
||||||
define('_PS_BASE_URL_', Tools::getShopDomain(true));
|
|
||||||
if (!defined('_PS_BASE_URL_SSL_'))
|
|
||||||
define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
|
|
||||||
if ((int)Tools::getValue('liteDisplaying'))
|
if ((int)Tools::getValue('liteDisplaying'))
|
||||||
{
|
{
|
||||||
$this->display_header = false;
|
$this->display_header = false;
|
||||||
@@ -1665,7 +1652,24 @@ class AdminControllerCore extends Controller
|
|||||||
|
|
||||||
$this->context->shop = new Shop($shop_id);
|
$this->context->shop = new Shop($shop_id);
|
||||||
|
|
||||||
/* Filter memorization */
|
if ($this->ajax && method_exists($this, 'ajaxPreprocess'))
|
||||||
|
$this->ajaxPreProcess();
|
||||||
|
|
||||||
|
$this->context->smarty->assign(array(
|
||||||
|
'table' => $this->table,
|
||||||
|
'current' => self::$currentIndex,
|
||||||
|
'token' => $this->token,
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->initProcess();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve GET and POST value and translate them to actions
|
||||||
|
*/
|
||||||
|
public function initProcess()
|
||||||
|
{
|
||||||
|
// Filter memorization
|
||||||
if (isset($_POST) && !empty($_POST) && isset($this->table))
|
if (isset($_POST) && !empty($_POST) && isset($this->table))
|
||||||
foreach ($_POST as $key => $value)
|
foreach ($_POST as $key => $value)
|
||||||
if (is_array($this->table))
|
if (is_array($this->table))
|
||||||
@@ -1687,7 +1691,7 @@ class AdminControllerCore extends Controller
|
|||||||
else if (strncmp($key, $this->table.'OrderBy', 7) === 0 || strncmp($key, $this->table.'Orderway', 12) === 0)
|
else if (strncmp($key, $this->table.'OrderBy', 7) === 0 || strncmp($key, $this->table.'Orderway', 12) === 0)
|
||||||
$this->context->cookie->$key = $value;
|
$this->context->cookie->$key = $value;
|
||||||
|
|
||||||
/* Manage list filtering */
|
// Manage list filtering
|
||||||
if (Tools::isSubmit('submitFilter'.$this->table) || $this->context->cookie->{'submitFilter'.$this->table} !== false)
|
if (Tools::isSubmit('submitFilter'.$this->table) || $this->context->cookie->{'submitFilter'.$this->table} !== false)
|
||||||
$this->filter = true;
|
$this->filter = true;
|
||||||
|
|
||||||
@@ -1763,8 +1767,7 @@ class AdminControllerCore extends Controller
|
|||||||
}
|
}
|
||||||
else if (isset($_GET['update'.$this->table]) && isset($_GET['id_'.$this->table]))
|
else if (isset($_GET['update'.$this->table]) && isset($_GET['id_'.$this->table]))
|
||||||
{
|
{
|
||||||
// @TODO move the employee condition to AdminEmployee
|
if ($this->tabAccess['edit'] === '1')
|
||||||
if ($this->tabAccess['edit'] === '1' || ($this->table == 'employee' && $this->context->employee->id == Tools::getValue('id_employee')))
|
|
||||||
$this->display = 'edit';
|
$this->display = 'edit';
|
||||||
else
|
else
|
||||||
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
||||||
@@ -1799,15 +1802,6 @@ class AdminControllerCore extends Controller
|
|||||||
}
|
}
|
||||||
else if (!empty($this->options) && empty($this->fieldsDisplay))
|
else if (!empty($this->options) && empty($this->fieldsDisplay))
|
||||||
$this->display = 'options';
|
$this->display = 'options';
|
||||||
|
|
||||||
if ($this->ajax && method_exists($this, 'ajaxPreprocess'))
|
|
||||||
$this->ajaxPreProcess();
|
|
||||||
|
|
||||||
$this->context->smarty->assign(array(
|
|
||||||
'table' => $this->table,
|
|
||||||
'current' => self::$currentIndex,
|
|
||||||
'token' => $this->token,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2504,6 +2498,7 @@ EOF;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @TODO delete method after AdminProducts cleanup
|
||||||
* Display flags in forms for translations
|
* Display flags in forms for translations
|
||||||
*
|
*
|
||||||
* @param array $languages All languages available
|
* @param array $languages All languages available
|
||||||
@@ -2512,7 +2507,6 @@ EOF;
|
|||||||
* @param string $id Current div id]
|
* @param string $id Current div id]
|
||||||
* @param boolean $use_vars_instead_of_ids use an js vars instead of ids seperate by "¤"
|
* @param boolean $use_vars_instead_of_ids use an js vars instead of ids seperate by "¤"
|
||||||
*
|
*
|
||||||
* @todo : delete return params :
|
|
||||||
* @param return define the return way : false for a display, true for a return
|
* @param return define the return way : false for a display, true for a return
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
|||||||
@@ -338,6 +338,18 @@ class AdminEmployeesControllerCore extends AdminController
|
|||||||
}
|
}
|
||||||
return parent::postProcess();
|
return parent::postProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function initProcess()
|
||||||
|
{
|
||||||
|
// If employee is editing its own entry, its ok
|
||||||
|
if ($this->tabAccess['edit'] !== '1'
|
||||||
|
&& $this->table == 'employee'
|
||||||
|
&& $this->context->employee->id == Tools::getValue('id_employee')
|
||||||
|
&& Tools::isSubmit('updateemployee'))
|
||||||
|
$this->tabAccess['edit'] = 1;
|
||||||
|
|
||||||
|
parent::initProcess();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user