public function postProcess() { global $currentIndex; if (Tools::getValue('submitAdd' . $this->table)) { /* Checking fields validity */ $this->validateRules(); if (!sizeof($this->_errors)) { $id = (int) Tools::getValue('id_' . $this->table); /* Object update */ if (isset($id) and !empty($id)) { if ($this->tabAccess['edit'] === '1') { $object = new $this->className($id); if (Validate::isLoadedObject($object)) { Db::getInstance()->Execute('DELETE FROM ' . _DB_PREFIX_ . 'carrier_group WHERE id_carrier = ' . (int) $id); $object->deleted = 1; $object->update(); $objectNew = new $this->className(); $this->copyFromPost($objectNew, $this->table); $result = $objectNew->add(); if (Validate::isLoadedObject($objectNew)) { $this->afterDelete($objectNew, $object->id); Hook::updateCarrier((int) $object->id, $objectNew); } $this->changeGroups($objectNew->id); if (!$result) { $this->_errors[] = Tools::displayError('An error occurred while updating object.') . ' <b>' . $this->table . '</b>'; } elseif ($this->postImage($objectNew->id)) { $this->changeZones($objectNew->id); Tools::redirectAdmin($currentIndex . '&id_' . $this->table . '=' . $object->id . '&conf=4' . '&token=' . $this->token); } } else { $this->_errors[] = Tools::displayError('An error occurred while updating object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } else { if ($this->tabAccess['add'] === '1') { $object = new $this->className(); $this->copyFromPost($object, $this->table); if (!$object->add()) { $this->_errors[] = Tools::displayError('An error occurred while creating object.') . ' <b>' . $this->table . '</b>'; } elseif ($_POST['id_' . $this->table] = $object->id and $this->postImage($object->id) and $this->_redirect) { $this->changeZones($object->id); $this->changeGroups($object->id); Tools::redirectAdmin($currentIndex . '&id_' . $this->table . '=' . $object->id . '&conf=3' . '&token=' . $this->token); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } } } elseif ((isset($_GET['status' . $this->table]) or isset($_GET['status'])) and Tools::getValue($this->identifier)) { if ($this->tabAccess['edit'] === '1') { if (Tools::getValue('id_carrier') == Configuration::get('PS_CARRIER_DEFAULT')) { $this->_errors[] = Tools::displayError('You can\'t disable the default carrier, please change your default carrier first.'); } else { parent::postProcess(); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } else { if (Tools::isSubmit('submitDel' . $this->table) && in_array(Configuration::get('PS_CARRIER_DEFAULT'), Tools::getValue('carrierBox')) or isset($_GET['delete' . $this->table]) and Tools::getValue('id_carrier') == Configuration::get('PS_CARRIER_DEFAULT')) { $this->_errors[] = $this->l('Please set another carrier as default before deleting'); } else { parent::postProcess(); } } }
public function postProcess() { global $currentIndex; if (Tools::getValue('submitAdd' . $this->table)) { /* Checking fields validity */ $this->validateRules(); if (!sizeof($this->_errors)) { $id = intval(Tools::getValue('id_' . $this->table)); /* Object update */ if (isset($id) and !empty($id)) { if ($this->tabAccess['edit'] === '1') { $object = new $this->className($id); if (Validate::isLoadedObject($object)) { $object->deleted = 1; $object->update(); $objectNew = new $this->className(); $this->copyFromPost($objectNew, $this->table); $result = $objectNew->add(); if (Validate::isLoadedObject($objectNew)) { $this->afterDelete($objectNew, $object->id); Hook::updateCarrier(intval($object->id), $objectNew); } if (!$result) { $this->_errors[] = Tools::displayError('an error occurred while updating object') . ' <b>' . $this->table . '</b>'; } elseif ($this->postImage($objectNew->id)) { $this->changeZones($objectNew->id); Tools::redirectAdmin($currentIndex . '&id_' . $this->table . '=' . $object->id . '&conf=4' . '&token=' . $this->token); } } else { $this->_errors[] = Tools::displayError('an error occurred while updating object') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } } else { if ($this->tabAccess['add'] === '1') { $object = new $this->className(); $this->copyFromPost($object, $this->table); if (!$object->add()) { $this->_errors[] = Tools::displayError('an error occurred while creating object') . ' <b>' . $this->table . '</b>'; } elseif ($_POST['id_' . $this->table] = $object->id and $this->postImage($object->id) and $this->_redirect) { $this->changeZones($object->id); Tools::redirectAdmin($currentIndex . '&id_' . $this->table . '=' . $object->id . '&conf=3' . '&token=' . $this->token); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add anything here.'); } } } } else { if (isset($_GET['delete' . $this->table]) and Tools::getValue('id_carrier') == Configuration::get('PS_CARRIER_DEFAULT')) { $this->_errors[] = $this->l('Please set another carrier as default before deleting'); } else { parent::postProcess(); } } }