* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7540 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminStates extends AdminTab
{
public function __construct()
{
$this->table = 'state';
$this->className = 'State';
$this->edit = true;
$this->delete = true;
$this->fieldsDisplay = array(
'id_state' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'name' => array('title' => $this->l('Name'), 'width' => 140, 'filter_key' => 'a!name'),
'iso_code' => array('title' => $this->l('ISO code'), 'align' => 'center', 'width' => 50),
'zone' => array('title' => $this->l('Zone'), 'width' => 100, 'filter_key' => 'z!name'));
$this->_select = 'z.`name` AS zone';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'zone` z ON (z.`id_zone` = a.`id_zone`)';
parent::__construct();
}
public function postProcess()
{
if (!isset($this->table)) return false;
/* Delete object */
if (isset($_GET['delete'.$this->table]))
{
global $currentIndex;
// set token
$token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
// Sub included tab postProcessing
$this->includeSubTab('postProcess', array('submitAdd1', 'submitDel', 'delete', 'submitFilter', 'submitReset'));
if ($this->tabAccess['delete'] === '1')
{
if (Validate::isLoadedObject($object = $this->loadObject()) AND isset($this->fieldImageSettings))
{
if (!$object->isUsed())
{
// check if request at least one object with noZeroObject
if (isset($object->noZeroObject) AND sizeof($taxes = call_user_func(array($this->className, $object->noZeroObject))) <= 1)
$this->_errors[] = Tools::displayError('You need at least one object.').' '.$this->table.'
'.Tools::displayError('You cannot delete all of the items.');
else
{
$this->deleteImage($object->id);
if ($this->deleted)
{
$object->deleted = 1;
if ($object->update()) Tools::redirectAdmin($currentIndex.'&conf=1&token='.$token);
}
elseif ($object->delete())
{
Tools::redirectAdmin($currentIndex.'&conf=1&token='.$token);
}
$this->_errors[] = Tools::displayError('An error occurred during deletion.');
}
} else {
$this->_errors[] = Tools::displayError('This state is currently in use');
}
}
else
$this->_errors[] = Tools::displayError('An error occurred while deleting object.').' '.$this->table.' '.Tools::displayError('(cannot load object)');
}
else
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
} else {
parent::postProcess();
}
}
public function displayForm($isMainTab = true)
{
global $currentIndex, $cookie;
parent::displayForm();
if (!($obj = $this->loadObject(true)))
return;
echo '