From 3133e7ab27b55fd5611867e88653e0bd6b21d16d Mon Sep 17 00:00:00 2001 From: lLefevre Date: Wed, 5 Oct 2011 12:42:52 +0000 Subject: [PATCH] //added AdminStatesController git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9054 b9a71923-0436-4b27-9f14-aed3839534dd --- admin-dev/tabs/AdminStates.php | 158 -------------------- admin-dev/themes/template/adminStates.tpl | 78 ++++++++++ controllers/admin/AdminStatesController.php | 144 ++++++++++++++++++ 3 files changed, 222 insertions(+), 158 deletions(-) delete mode 100644 admin-dev/tabs/AdminStates.php create mode 100644 admin-dev/themes/template/adminStates.tpl create mode 100644 controllers/admin/AdminStatesController.php diff --git a/admin-dev/tabs/AdminStates.php b/admin-dev/tabs/AdminStates.php deleted file mode 100644 index c10cf4f3c..000000000 --- a/admin-dev/tabs/AdminStates.php +++ /dev/null @@ -1,158 +0,0 @@ - -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 6844 $ -* @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])) - { - // 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(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 { - $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) - { - parent::displayForm(); - - if (!($obj = $this->loadObject(true))) - return; - - echo ' -
- '.($obj->id ? '' : '').' -
'.$this->l('States').' - -
- * -

'.$this->l('State name to display in addresses and on invoices').'

-
- -
- * -

'.$this->l('1 to 4 letter ISO code (search on Wikipedia if you don\'t know)').'

-
- -
- -

'.$this->l('Country where state, region or city is located').'

-
- -
- -

'.$this->l('Geographical zone where this state is located').'
'.$this->l('Used for shipping').'

-
- -
- id OR $this->getFieldValue($obj, 'active')) ? 'checked="checked" ' : '').'/> - - getFieldValue($obj, 'active') AND $obj->id) ? 'checked="checked" ' : '').'/> - -

'.$this->l('Enabled or disabled').'

-
-
- -
-
* '.$this->l('Required field').'
-
-
'; - } -} - diff --git a/admin-dev/themes/template/adminStates.tpl b/admin-dev/themes/template/adminStates.tpl new file mode 100644 index 000000000..46d108e7d --- /dev/null +++ b/admin-dev/themes/template/adminStates.tpl @@ -0,0 +1,78 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 8897 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{if isset($tab_form)} + +
+ {if $tab_form['id']}{/if} +
+ {l s ='States'} + +
+ * +

{l s ='State name to display in addresses and on invoices'}

+
+ +
+ * +

{l s ='1 to 4 letter ISO code (search on Wikipedia if you don\'t know)'}

+
+ +
+ +

{l s ='Country where state, region or city is located'}

+
+ +
+ +

{l s ='Geographical zone where this state is located'}
{l s ='Used for shipping'}

+
+ +
+ + + + +

{l s ='Enabled or disabled'}

+
+
+ +
+
* {l s ='Required field'}
+
+
+ +{/if} + +{$content} \ No newline at end of file diff --git a/controllers/admin/AdminStatesController.php b/controllers/admin/AdminStatesController.php new file mode 100644 index 000000000..210561ccd --- /dev/null +++ b/controllers/admin/AdminStatesController.php @@ -0,0 +1,144 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 8971 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +class AdminStatesControllerCore extends AdminController +{ + public function __construct() + { + $this->table = 'state'; + $this->className = 'State'; + $this->lang = false; + $this->edit = true; + $this->delete = true; + $this->requiredDatabase = true; + + $this->context = Context::getContext(); + + if (!Tools::getValue('realedit')) + $this->deleted = false; + + $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); + + $this->_select = 'z.`name` AS zone'; + $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'zone` z ON (z.`id_zone` = a.`id_zone`)'; + + $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->template = 'adminStates.tpl'; + + parent::__construct(); + } + + public function postProcess() + { + if (!isset($this->table)) + return false; + + /* Delete object */ + if (isset($_GET['delete'.$this->table])) + { + // 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()) && isset($this->fieldImageSettings)) + { + if (!$object->isUsed()) + { + // check if request at least one object with noZeroObject + if (isset($object->noZeroObject) && count($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 + { + 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 + $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($is_main_tab = true) + { + $this->content = parent::displayForm($is_main_tab); + + if (!($obj = $this->loadObject(true))) + return; + $current_shop = Shop::initialize(); + + $this->context->smarty->assign('tab_form', array( + 'current' => self::$currentIndex, + 'table' => $this->table, + 'token' => $this->token, + 'id' => $obj->id, + 'name' => $this->getFieldValue($obj, 'name'), + 'iso_code' => $this->getFieldValue($obj, 'iso_code'), + 'countries' => Country::getCountries($this->context->language->id, false, true), + 'id_country' => $this->getFieldValue($obj, 'id_country'), + 'zones' => Zone::getZones(), + 'id_zone' => $this->getFieldValue($obj, 'id_zone'), + 'active' => $this->getFieldValue($obj, 'active') ? true : false + )); + } + + public function initContent() + { + if ($this->display != 'edit') + $this->display = 'list'; + + parent::initContent(); + } + +} + +