* @copyright PrestaShop * @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0 * @version 1.3 * */ include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); class AdminTaxes extends AdminTab { public function __construct() { $this->table = 'tax'; $this->className = 'Tax'; $this->lang = true; $this->edit = true; $this->delete = true; $this->fieldsDisplay = array( 'id_tax' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'name' => array('title' => $this->l('Name'), 'width' => 140), 'rate' => array('title' => $this->l('Rate'), 'align' => 'center', 'suffix' => '%', 'width' => 50)); $this->optionTitle = $this->l('Tax options'); $this->_fieldsOptions = array( 'PS_TAX' => array('title' => $this->l('Enable tax:'), 'desc' => $this->l('Select whether or not to include tax on purchases'), 'cast' => 'intval', 'type' => 'bool'), ); parent::__construct(); } public function displayForm($isMainTab = true) { global $currentIndex, $cookie; parent::displayForm(); $obj = $this->loadObject(true); $tax_zones = $obj->getZones(); $zones = Zone::getZones(true); $tax_states = $obj->getStates(); $states = State::getStates(intval($cookie->id_lang)); echo '
'; } 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)) { $this->copyFromPost($object, $this->table); $result = $object->update(false, false); if (!$result) $this->_errors[] = Tools::displayError('an error occurred while updating object').' '.$this->table.''; elseif ($this->postImage($object->id)) { $this->changeZones($object->id); $this->changeStates($object->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').' '.$this->table.' '.Tools::displayError('(cannot load object)'); } else $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } /* Object creation */ 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').' '.$this->table.''; elseif (($_POST['id_'.$this->table] = $object->id /* voluntary */) AND $this->postImage($object->id) AND $this->_redirect) { $this->changeZones($object->id); $this->changeStates($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 parent::postProcess(); } function changeZones($id) { $tax = new $this->className($id); if (!Validate::isLoadedObject($tax)) die (Tools::displayError('object cannot be loaded')); $zones = Zone::getZones(true); foreach ($zones as $zone) if (sizeof($tax->getZone($zone['id_zone']))) { if (!isset($_POST['zone_'.$zone['id_zone']]) OR !$_POST['zone_'.$zone['id_zone']]) $tax->deleteZone($zone['id_zone']); } elseif (isset($_POST['zone_'.$zone['id_zone']]) AND $_POST['zone_'.$zone['id_zone']]) $tax->addZone($zone['id_zone']); } function changeStates($id) { global $cookie; $tax = new $this->className($id); if (!Validate::isLoadedObject($tax)) die (Tools::displayError('object cannot be loaded')); $states = State::getStates(intval($cookie->id_lang), true); foreach ($states as $state) if ($tax->getState($state['id_state'])) { if (!isset($_POST['state_'.$state['id_state']]) OR !$_POST['state_'.$state['id_state']]) $tax->deleteState($state['id_state']); } elseif (isset($_POST['state_'.$state['id_state']]) AND $_POST['state_'.$state['id_state']]) $tax->addState($state['id_state']); } } ?>