// AdminStates code cleaning
This commit is contained in:
1 parent
337b7333a2
commit
a7f9f23b73
1 file changed
+16
-70
@@ -116,13 +116,6 @@ class AdminStatesControllerCore extends AdminController
|
|||||||
parent::initPageHeaderToolbar();
|
parent::initPageHeaderToolbar();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderList()
|
|
||||||
{
|
|
||||||
$this->tpl_list_vars['zones'] = $this->zones;
|
|
||||||
$this->tpl_list_vars['countries'] = $this->countries;
|
|
||||||
return parent::renderList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function renderForm()
|
public function renderForm()
|
||||||
{
|
{
|
||||||
$this->fields_form = array(
|
$this->fields_form = array(
|
||||||
@@ -146,26 +139,26 @@ class AdminStatesControllerCore extends AdminController
|
|||||||
'maxlength' => 7,
|
'maxlength' => 7,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'class' => 'uppercase',
|
'class' => 'uppercase',
|
||||||
'hint' => $this->l('1 to 4 letter ISO code')
|
'hint' => $this->l('1 to 4 letter ISO code.').' '.$this->l('You can prefix it with the country ISO code if needed.')
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'label' => $this->l('Country:'),
|
'label' => $this->l('Country:'),
|
||||||
'name' => 'id_country',
|
'name' => 'id_country',
|
||||||
'required' => false,
|
'required' => true,
|
||||||
'default_value' => (int)$this->context->country->id,
|
'default_value' => (int)$this->context->country->id,
|
||||||
'options' => array(
|
'options' => array(
|
||||||
'query' => Country::getCountries($this->context->language->id, false, true),
|
'query' => Country::getCountries($this->context->language->id, false, true),
|
||||||
'id' => 'id_country',
|
'id' => 'id_country',
|
||||||
'name' => 'name',
|
'name' => 'name',
|
||||||
),
|
),
|
||||||
'hint' => $this->l('Country where the state, region or city is located')
|
'hint' => $this->l('Country where the state is located.').' '.$this->l('Only the countries with the option "contains states" enabled are displayed.')
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'label' => $this->l('Zone:'),
|
'label' => $this->l('Zone:'),
|
||||||
'name' => 'id_zone',
|
'name' => 'id_zone',
|
||||||
'required' => false,
|
'required' => true,
|
||||||
'options' => array(
|
'options' => array(
|
||||||
'query' => Zone::getZones(),
|
'query' => Zone::getZones(),
|
||||||
'id' => 'id_zone',
|
'id' => 'id_zone',
|
||||||
@@ -180,7 +173,7 @@ class AdminStatesControllerCore extends AdminController
|
|||||||
'type' => 'switch',
|
'type' => 'switch',
|
||||||
'label' => $this->l('Status:'),
|
'label' => $this->l('Status:'),
|
||||||
'name' => 'active',
|
'name' => 'active',
|
||||||
'required' => false,
|
'required' => true,
|
||||||
'values' => array(
|
'values' => array(
|
||||||
array(
|
array(
|
||||||
'id' => 'active_on',
|
'id' => 'active_on',
|
||||||
@@ -192,8 +185,7 @@ class AdminStatesControllerCore extends AdminController
|
|||||||
'value' => 0,
|
'value' => 0,
|
||||||
'label' => '<img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" />'
|
'label' => '<img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" />'
|
||||||
)
|
)
|
||||||
),
|
)
|
||||||
'hint' => $this->l('Enabled or disabled')
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
'submit' => array(
|
'submit' => array(
|
||||||
@@ -210,48 +202,31 @@ class AdminStatesControllerCore extends AdminController
|
|||||||
if (Tools::isSubmit($this->table.'Orderby') || Tools::isSubmit($this->table.'Orderway'))
|
if (Tools::isSubmit($this->table.'Orderby') || Tools::isSubmit($this->table.'Orderway'))
|
||||||
$this->filter = true;
|
$this->filter = true;
|
||||||
|
|
||||||
if (!isset($this->table))
|
// Idiot-proof controls
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!Tools::getValue('id_'.$this->table))
|
if (!Tools::getValue('id_'.$this->table))
|
||||||
{
|
{
|
||||||
if (Validate::isStateIsoCode(Tools::getValue('iso_code')) && State::getIdByIso(Tools::getValue('iso_code'), Tools::getValue('id_country')))
|
if (Validate::isStateIsoCode(Tools::getValue('iso_code')) && State::getIdByIso(Tools::getValue('iso_code'), Tools::getValue('id_country')))
|
||||||
$this->errors[] = Tools::displayError('This ISO code already exists. You cannot create two states with the same ISO code.');
|
$this->errors[] = Tools::displayError('This ISO code already exists. You cannot create two states with the same ISO code.');
|
||||||
}
|
}
|
||||||
else if (Validate::isStateIsoCode(Tools::getValue('iso_code')))
|
elseif (Validate::isStateIsoCode(Tools::getValue('iso_code')))
|
||||||
{
|
{
|
||||||
$id_state = State::getIdByIso(Tools::getValue('iso_code'), Tools::getValue('id_country'));
|
$id_state = State::getIdByIso(Tools::getValue('iso_code'), Tools::getValue('id_country'));
|
||||||
if ($id_state && $id_state != Tools::getValue('id_'.$this->table))
|
if ($id_state && $id_state != Tools::getValue('id_'.$this->table))
|
||||||
$this->errors[] = Tools::displayError('This ISO code already exists. You cannot create two states with the same ISO code.');
|
$this->errors[] = Tools::displayError('This ISO code already exists. You cannot create two states with the same ISO code.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delete object */
|
/* Delete state */
|
||||||
if (isset($_GET['delete'.$this->table]))
|
if (Tools::isSubmit('delete'.$this->table))
|
||||||
{
|
{
|
||||||
// set token
|
|
||||||
$token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
|
|
||||||
|
|
||||||
if ($this->tabAccess['delete'] === '1')
|
if ($this->tabAccess['delete'] === '1')
|
||||||
{
|
{
|
||||||
if (Validate::isLoadedObject($object = $this->loadObject()) && isset($this->fieldImageSettings))
|
if (Validate::isLoadedObject($object = $this->loadObject()))
|
||||||
{
|
{
|
||||||
if (!$object->isUsed())
|
if (!$object->isUsed())
|
||||||
{
|
{
|
||||||
// check if request at least one object with noZeroObject
|
if ($object->delete())
|
||||||
if (isset($object->noZeroObject) && count($taxes = call_user_func(array($this->className, $object->noZeroObject))) <= 1)
|
Tools::redirectAdmin(self::$currentIndex.'&conf=1&token='.(Tools::getValue('token') ? Tools::getValue('token') : $this->token));
|
||||||
$this->errors[] = Tools::displayError('You need at least one object.').' <b>'.$this->table.'</b><br />'.Tools::displayError('You cannot delete all of the items.');
|
$this->errors[] = Tools::displayError('An error occurred during deletion.');
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($this->deleted)
|
|
||||||
{
|
|
||||||
$object->deleted = 1;
|
|
||||||
if ($object->update())
|
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&conf=1&token='.$token);
|
|
||||||
}
|
|
||||||
else if ($object->delete())
|
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&conf=1&token='.$token);
|
|
||||||
$this->errors[] = Tools::displayError('An error occurred during deletion.');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$this->errors[] = Tools::displayError('This state was used in at least one address. It cannot be removed.');
|
$this->errors[] = Tools::displayError('This state was used in at least one address. It cannot be removed.');
|
||||||
@@ -262,37 +237,8 @@ class AdminStatesControllerCore extends AdminController
|
|||||||
else
|
else
|
||||||
$this->errors[] = Tools::displayError('You do not have permission to delete this.');
|
$this->errors[] = Tools::displayError('You do not have permission to delete this.');
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (!count($this->errors))
|
||||||
parent::postProcess();
|
parent::postProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function displayAjaxStates()
|
|
||||||
{
|
|
||||||
if ($this->tabAccess['view'] === '1')
|
|
||||||
{
|
|
||||||
$states = Db::getInstance()->executeS('
|
|
||||||
SELECT s.id_state, s.name
|
|
||||||
FROM '._DB_PREFIX_.'state s
|
|
||||||
LEFT JOIN '._DB_PREFIX_.'country c ON (s.`id_country` = c.`id_country`)
|
|
||||||
WHERE s.id_country = '.(int)(Tools::getValue('id_country')).' AND s.active = 1 AND c.`contains_states` = 1
|
|
||||||
ORDER BY s.`name` ASC');
|
|
||||||
|
|
||||||
if (is_array($states) AND !empty($states))
|
|
||||||
{
|
|
||||||
$list = '';
|
|
||||||
if (Tools::getValue('no_empty') != true)
|
|
||||||
{
|
|
||||||
$empty_value = (Tools::isSubmit('empty_value')) ? Tools::getValue('empty_value') : '----------';
|
|
||||||
$list = '<option value="0">'.Tools::htmlentitiesUTF8($empty_value).'</option>'."\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($states AS $state)
|
|
||||||
$list .= '<option value="'.(int)($state['id_state']).'"'.((isset($_GET['id_state']) AND $_GET['id_state'] == $state['id_state']) ? ' selected="selected"' : '').'>'.$state['name'].'</option>'."\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$list = 'false';
|
|
||||||
|
|
||||||
die($list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user