// update to AdminController init() and postProcess()

This commit is contained in:
tDidierjean
2011-09-29 17:20:16 +00:00
parent 8c1e2b8bf2
commit db83f020cd
+81 -50
View File
@@ -199,20 +199,17 @@ class AdminControllerCore extends Controller
// Sub included tab postProcessing // Sub included tab postProcessing
$this->includeSubTab('postProcess', array('status', 'submitAdd1', 'submitDel', 'delete', 'submitFilter', 'submitReset')); $this->includeSubTab('postProcess', array('status', 'submitAdd1', 'submitDel', 'delete', 'submitFilter', 'submitReset'));
/* Delete object image */ switch ($this->action)
if (isset($_GET['deleteImage']))
{ {
/* Delete object image */
case 'delete_image':
if (Validate::isLoadedObject($object = $this->loadObject())) if (Validate::isLoadedObject($object = $this->loadObject()))
if (($object->deleteImage())) if (($object->deleteImage()))
Tools::redirectAdmin(self::$currentIndex.'&add'.$this->table.'&'.$this->identifier.'='.Tools::getValue($this->identifier).'&conf=7&token='.$token); Tools::redirectAdmin(self::$currentIndex.'&add'.$this->table.'&'.$this->identifier.'='.Tools::getValue($this->identifier).'&conf=7&token='.$token);
$this->_errors[] = Tools::displayError('An error occurred during image deletion (cannot load object).'); $this->_errors[] = Tools::displayError('An error occurred during image deletion (cannot load object).');
} break;
/* Delete object */ /* Delete object */
elseif (isset($_GET['delete'.$this->table])) case 'delete':
{
if ($this->tabAccess['delete'] === '1')
{
if (Validate::isLoadedObject($object = $this->loadObject()) AND isset($this->fieldImageSettings)) if (Validate::isLoadedObject($object = $this->loadObject()) AND isset($this->fieldImageSettings))
{ {
// check if request at least one object with noZeroObject // check if request at least one object with noZeroObject
@@ -238,16 +235,10 @@ class AdminControllerCore extends Controller
} }
else else
$this->_errors[] = Tools::displayError('An error occurred while deleting object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)'); $this->_errors[] = Tools::displayError('An error occurred while deleting object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
} break;
else
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
}
/* Change object statuts (active, inactive) */ /* Change object statuts (active, inactive) */
elseif ((isset($_GET['status'.$this->table]) OR isset($_GET['status'])) AND Tools::getValue($this->identifier)) case 'status':
{
if ($this->tabAccess['edit'] === '1')
{
if (Validate::isLoadedObject($object = $this->loadObject())) if (Validate::isLoadedObject($object = $this->loadObject()))
{ {
if ($object->toggleStatus()) if ($object->toggleStatus())
@@ -257,28 +248,21 @@ class AdminControllerCore extends Controller
} }
else else
$this->_errors[] = Tools::displayError('An error occurred while updating status for object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)'); $this->_errors[] = Tools::displayError('An error occurred while updating status for object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
} break;
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
/* Move an object */ /* Move an object */
elseif (isset($_GET['position'])) case 'position':
{ if (!Validate::isLoadedObject($object = $this->loadObject()))
if ($this->tabAccess['edit'] !== '1')
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
elseif (!Validate::isLoadedObject($object = $this->loadObject()))
$this->_errors[] = Tools::displayError('An error occurred while updating status for object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)'); $this->_errors[] = Tools::displayError('An error occurred while updating status for object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
elseif (!$object->updatePosition((int)(Tools::getValue('way')), (int)(Tools::getValue('position')))) elseif (!$object->updatePosition((int)(Tools::getValue('way')), (int)(Tools::getValue('position'))))
$this->_errors[] = Tools::displayError('Failed to update the position.'); $this->_errors[] = Tools::displayError('Failed to update the position.');
else else
Tools::redirectAdmin(self::$currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.(($id_category = (int)(Tools::getValue($this->identifier))) ? ('&'.$this->identifier.'='.$id_category) : '').'&token='.$token); Tools::redirectAdmin(self::$currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.(($id_category = (int)(Tools::getValue($this->identifier))) ? ('&'.$this->identifier.'='.$id_category) : '').'&token='.$token);
Tools::redirectAdmin(self::$currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.((($id_category = (int)(Tools::getValue('id_category'))) AND Tools::getValue('id_product')) ? '&id_category='.$id_category : '').'&token='.$token); Tools::redirectAdmin(self::$currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.((($id_category = (int)(Tools::getValue('id_category'))) AND Tools::getValue('id_product')) ? '&id_category='.$id_category : '').'&token='.$token);
} break;
/* Delete multiple objects */ /* Delete multiple objects */
elseif (Tools::getValue('submitDel'.$this->table)) case 'multiple_delete':
{
if ($this->tabAccess['delete'] === '1')
{
if (isset($_POST[$this->table.'Box'])) if (isset($_POST[$this->table.'Box']))
{ {
$object = new $this->className(); $object = new $this->className();
@@ -308,14 +292,10 @@ class AdminControllerCore extends Controller
} }
else else
$this->_errors[] = Tools::displayError('You must select at least one element to delete.'); $this->_errors[] = Tools::displayError('You must select at least one element to delete.');
} break;
else
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
}
/* Create or update an object */ /* Create or update an object */
elseif (Tools::getValue('submitAdd'.$this->table)) case 'save':
{
/* Checking fields validity */ /* Checking fields validity */
$this->validateRules(); $this->validateRules();
if (!sizeof($this->_errors)) if (!sizeof($this->_errors))
@@ -416,11 +396,10 @@ class AdminControllerCore extends Controller
} }
} }
$this->_errors = array_unique($this->_errors); $this->_errors = array_unique($this->_errors);
} break;
/* Cancel all filters for this tab */ /* Cancel all filters for this tab */
elseif (isset($_POST['submitReset'.$this->table])) case 'reset_filters':
{
$filters = $this->context->cookie->getFamily($this->table.'Filter_'); $filters = $this->context->cookie->getFamily($this->table.'Filter_');
foreach ($filters AS $cookieKey => $filter) foreach ($filters AS $cookieKey => $filter)
if (strncmp($cookieKey, $this->table.'Filter_', 7 + Tools::strlen($this->table)) == 0) if (strncmp($cookieKey, $this->table.'Filter_', 7 + Tools::strlen($this->table)) == 0)
@@ -439,17 +418,15 @@ class AdminControllerCore extends Controller
if (isset($this->context->cookie->{$this->table.'Orderway'})) if (isset($this->context->cookie->{$this->table.'Orderway'}))
unset($this->context->cookie->{$this->table.'Orderway'}); unset($this->context->cookie->{$this->table.'Orderway'});
unset($_POST); unset($_POST);
} break;
/* Submit options list */ /* Submit options list */
elseif (Tools::getValue('submitOptions'.$this->table)) case 'update_options':
{
$this->updateOptions($token); $this->updateOptions($token);
} break;
/* Manage list filtering */ /* Manage list filtering */
elseif (Tools::isSubmit('submitFilter'.$this->table) OR $this->context->cookie->{'submitFilter'.$this->table} !== false) case 'update_filters':
{
$_POST = array_merge($this->context->cookie->getFamily($this->table.'Filter_'), (isset($_POST) ? $_POST : array())); $_POST = array_merge($this->context->cookie->getFamily($this->table.'Filter_'), (isset($_POST) ? $_POST : array()));
foreach ($_POST AS $key => $value) foreach ($_POST AS $key => $value)
{ {
@@ -507,9 +484,9 @@ class AdminControllerCore extends Controller
} }
} }
} }
} break;
elseif(Tools::isSubmit('submitFields') AND $this->requiredDatabase AND $this->tabAccess['add'] === '1' AND $this->tabAccess['delete'] === '1')
{ case 'update_fields':
if (!is_array($fields = Tools::getValue('fieldsBox'))) if (!is_array($fields = Tools::getValue('fieldsBox')))
$fields = array(); $fields = array();
@@ -518,6 +495,7 @@ class AdminControllerCore extends Controller
$this->_errors[] = Tools::displayError('Error in updating required fields'); $this->_errors[] = Tools::displayError('Error in updating required fields');
else else
Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$token); Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$token);
break;
} }
} }
} }
@@ -590,7 +568,7 @@ class AdminControllerCore extends Controller
else else
$this->_errors[] = Tools::displayError('Object cannot be loaded (identifier missing or invalid)'); $this->_errors[] = Tools::displayError('Object cannot be loaded (identifier missing or invalid)');
$this->displayErrors(); $this->content = $this->displayErrors();
} }
/** /**
@@ -1028,7 +1006,60 @@ class AdminControllerCore extends Controller
$this->context->cookie->$key = $value; $this->context->cookie->$key = $value;
// Code from postProcess // Code from postProcess
if (isset($_GET['update'.$this->table]) && isset($_GET['id_'.$this->table])) /* Delete object image */
if (isset($_GET['deleteImage']))
{
$this->action = 'delete_image';
if (Validate::isLoadedObject($object = $this->loadObject()))
if (($object->deleteImage()))
Tools::redirectAdmin(self::$currentIndex.'&add'.$this->table.'&'.$this->identifier.'='.Tools::getValue($this->identifier).'&conf=7&token='.$token);
$this->_errors[] = Tools::displayError('An error occurred during image deletion (cannot load object).');
}
/* Delete object */
elseif (isset($_GET['delete'.$this->table]))
{
if ($this->tabAccess['delete'] === '1')
$this->action = 'delete';
else
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
}
/* Change object statuts (active, inactive) */
elseif ((isset($_GET['status'.$this->table]) OR isset($_GET['status'])) AND Tools::getValue($this->identifier))
{
if ($this->tabAccess['edit'] === '1')
$this->action = 'status';
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
/* Move an object */
elseif (isset($_GET['position']))
{
if ($this->tabAccess['edit'] == '1')
$this->action = 'position';
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
elseif (Tools::getValue('submitDel'.$this->table))
{
if ($this->tabAccess['delete'] === '1')
$this->action = 'multiple_delete';
else
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
}
elseif (Tools::getValue('submitAdd'.$this->table))
$this->action = 'save';
/* Cancel all filters for this tab */
elseif (isset($_POST['submitReset'.$this->table]))
$this->action = 'reset_filters';
/* Submit options list */
elseif (Tools::getValue('submitOptions'.$this->table))
$this->action = 'update_options';
/* Manage list filtering */
elseif (Tools::isSubmit('submitFilter'.$this->table) OR $this->context->cookie->{'submitFilter'.$this->table} !== false)
$this->action = 'update_filters';
elseif(Tools::isSubmit('submitFields') AND $this->requiredDatabase AND $this->tabAccess['add'] === '1' AND $this->tabAccess['delete'] === '1')
$this->action = 'update_fields';
elseif (isset($_GET['update'.$this->table]) && isset($_GET['id_'.$this->table]))
{ {
if ($this->tabAccess['edit'] === '1' OR ($this->table == 'employee' AND $this->context->employee->id == Tools::getValue('id_employee'))) if ($this->tabAccess['edit'] === '1' OR ($this->table == 'employee' AND $this->context->employee->id == Tools::getValue('id_employee')))
{ {