From 3c86e1ec5f22ab50cf47c12ce60752bc4986084e Mon Sep 17 00:00:00 2001 From: lLefevre Date: Thu, 20 Oct 2011 09:32:13 +0000 Subject: [PATCH] [*] BO #PSFV-94 : Added AdminCountriesController --- admin-dev/tabs/AdminCountries.php | 353 -------------- admin-dev/themes/template/countries/form.tpl | 349 ++++++++++++++ admin-dev/themes/template/list_header.tpl | 8 +- classes/AdminController.php | 7 + classes/Country.php | 121 ++--- .../admin/AdminCountriesController.php | 443 ++++++++++++++++++ 6 files changed, 868 insertions(+), 413 deletions(-) delete mode 100644 admin-dev/tabs/AdminCountries.php create mode 100644 admin-dev/themes/template/countries/form.tpl create mode 100644 controllers/admin/AdminCountriesController.php diff --git a/admin-dev/tabs/AdminCountries.php b/admin-dev/tabs/AdminCountries.php deleted file mode 100644 index b8cb72fb0..000000000 --- a/admin-dev/tabs/AdminCountries.php +++ /dev/null @@ -1,353 +0,0 @@ - -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 7310 $ -* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -include_once(_PS_ADMIN_DIR_.'/../classes/AdminTab.php'); - -class AdminCountries extends AdminTab -{ - public function __construct() - { - $this->table = 'country'; - $this->className = 'Country'; - $this->lang = true; - $this->edit = true; - $this->deleted = false; - $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_country' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), - 'name' => array('title' => $this->l('Country'), 'width' => 130, 'filter_key' => 'b!name'), - 'iso_code' => array('title' => $this->l('ISO code'), 'width' => 70, 'align' => 'center'), - 'call_prefix' => array('title' => $this->l('Call prefix'), 'width' => 40, 'align' => 'center', 'callback' => 'displayCallPrefix'), - 'zone' => array('title' => $this->l('Zone'), 'width' => 100, 'filter_key' => 'z!name'), - 'a!active' => array('title' => $this->l('Enabled'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'filter_key' => 'a!active'), - ); - - $this->optionsList = array( - 'general' => array( - 'title' => $this->l('Countries options'), - 'fields' => array( - 'PS_COUNTRY_DEFAULT' => array('title' => $this->l('Default country:'), 'desc' => $this->l('The default country used in shop'), 'cast' => 'intval', 'type' => 'select', 'identifier' => 'id_country', 'list' => Country::getCountries(Context::getContext()->language->id)), - 'PS_RESTRICT_DELIVERED_COUNTRIES' => array('title' => $this->l('Restrict countries in FO by those delivered by active carriers'), 'cast' => 'intval', 'type' => 'bool', 'default' => '0') - ), - ), - ); - - parent::__construct(); - } - - public function postProcess() - { - if (isset($_GET['delete'.$this->table]) OR Tools::getValue('submitDel'.$this->table)) - $this->_errors[] = Tools::displayError('You cannot delete a country. If you do not want it available for customers, please disable it.'); - else - { - if (Tools::getValue('submitAdd'.$this->table)) - { - $id_country = Tools::getValue('id_country'); - $tmp_addr_format = new AddressFormat($id_country); - - $save_status = false; - - $is_new = is_null($tmp_addr_format->id_country); - if ($is_new) - { - $tmp_addr_format = new AddressFormat(); - $tmp_addr_format->id_country = $id_country; - } - - $tmp_addr_format->format = Tools::getValue('address_layout'); - - if (strlen($tmp_addr_format->format) > 0) - { - if ($tmp_addr_format->checkFormatFields()) - $save_status = ($is_new) ? $tmp_addr_format->save(): $tmp_addr_format->update(); - else - { - $errorList = $tmp_addr_format->getErrorList(); - foreach($errorList as $numError => $error) - $this->_errors[] = $error; - } - - - if (!$save_status) - $this->_errors[] = Tools::displayError('Invalid address layout'.Db::getInstance()->getMsgError()); - } - unset($tmp_addr_format); - } - - return parent::postProcess(); - } - } - - private function _displayValidFields() - { - $html = ''; - } - - public function displayForm($isMainTab = true) - { - parent::displayForm(); - - $defaultLayout = ''; - - $defaultLayoutTab = array( - array('firstname', 'lastname'), - array('company'), - array('vat_number'), - array('address1'), - array('address2'), - array('postcode', 'city'), - array('Country:name'), - array('phone')); - - if (!($obj = $this->loadObject(true))) - return; - - foreach ($defaultLayoutTab as $line) - $defaultLayout .= implode(' ', $line)."\r\n"; - - echo ' - - -
- '.($obj->id ? '' : '').' -
'.$this->l('Countries').' - -
'; - - foreach ($this->_languages as $language) - echo ' -
- * - '.$this->l('Invalid characters:').' <>;=#{}  -
'; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'name', 'name'); - echo '

'.$this->l('Name of country').'

-
- -
- * -

'.$this->l('2- or 3-letter ISO code, e.g., FR for France').'. '.$this->l('Official list here').'.

-
- -
- * -

'.$this->l('International call prefix, e.g., 33 for France.').'.

-
- -
- -
- -
- -

'.$this->l('Geographical zone where country is located').'

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

'.$this->l('National zip code (L for a letter, N for a number and C for the Iso code), e.g., NNNNN for France. No verification if undefined').'.

-
- -
-
- -
-
- '.$this->l('Liable fields for the address information (click to have more details)').': '.$this->_displayValidFields().' -
-
-
- '. - $this->l('Use the last registered layout').' - '. - $this->l('Use a default layout').' - '. - $this->l('Use my current modified layout').' - '. - $this->l('Clean layout').' -
-
-
- -
- id OR $this->getFieldValue($obj, 'active')) ? 'checked="checked" ' : '').'/> - - getFieldValue($obj, 'active') AND $obj->id) ? 'checked="checked" ' : '').'/> - -

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

-
- -
- id OR $this->getFieldValue($obj, 'contains_states')) ? 'checked="checked" ' : '').'/> - - getFieldValue($obj, 'contains_states') AND $obj->id) ? 'checked="checked" ' : '').'/> - -
- -
- id OR $this->getFieldValue($obj, 'need_identification_number')) ? 'checked="checked" ' : '').'/> - - getFieldValue($obj, 'need_identification_number') AND $obj->id) ? 'checked="checked" ' : '').'/> - -
-
- -
- id OR $this->getFieldValue($obj, 'display_tax_label')) ? 'checked="checked" ' : '').'/> - - getFieldValue($obj, 'display_tax_label') AND $obj->id) ? 'checked="checked" ' : '').'/> - -
'; - if (Shop::isFeatureActive()) - { - echo '
'; - $this->displayAssoShop(); - echo '
'; - } - echo ' -
- -
-
* '.$this->l('Required field').'
-
-
- '; - } -} - diff --git a/admin-dev/themes/template/countries/form.tpl b/admin-dev/themes/template/countries/form.tpl new file mode 100644 index 000000000..416bdff81 --- /dev/null +++ b/admin-dev/themes/template/countries/form.tpl @@ -0,0 +1,349 @@ +{* +* 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: 8971 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{if $firstCall} + + + +{/if} + +
+ {if $form_id} + + {/if} +
+ {foreach $fields as $key => $field} + {if $key == 'legend'} + + {if isset($field.image)}{$field.title}{/if} + {$field.title} + + {elseif $key == 'input'} + {foreach $field as $input} + {if $input.name == 'id_state'} +
+ {/if} + {if isset($input.label)} + + {/if} +
+ {if $input.type == 'text'} + {if isset($input.lang) && isset($input.attributeLang)} + {foreach $languages as $language} +
+ + {if isset($input.hint)}{$input.hint} {/if} +
+ {/foreach} + {if count($languages) > 1} +
+ +
+
+ {l s='Choose language:'}

+ {foreach $languages as $language} + {$language.name} + {/foreach} +
+ {/if} + {else} + + {if isset($input.hint)}{$input.hint} {/if} + {/if} + {elseif $input.type == 'hidden'} + + {elseif $input.type == 'select'} + + {if isset($input.hint)}{$input.hint} {/if} + {elseif $input.type == 'radio'} + {foreach $input.values as $value} + + + {if isset($input.br) && $input.br}
{/if} + {/foreach} + {elseif $input.type == 'textarea'} + {if isset($input.lang) && isset($input.attributeLang)} + {foreach $languages as $language} +
+ +
+ {/foreach} + {if count($languages) > 1} +
+ +
+
+ {l s='Choose language:'}

+ {foreach $languages as $language} + {$language.name} + {/foreach} +
+ {/if} + {else} + + {/if} + {elseif $input.type == 'checkbox'} + {foreach $input.values.query as $value} + {assign var=id_checkbox value=$input.name|cat:'_'|cat:$value[$input.values.id]} + +
+ {/foreach} + {elseif $input.type == 'file'} + + + {elseif $input.type == 'group'} + {assign var=groups value=$input.values} + {include file='form_group.tpl'} + {elseif $input.type == 'shop' OR $input.type == 'group_shop'} + {include file='form_shop.tpl'} + {elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop} + +
+ {$asso_shop} +
+ {elseif $input.type == 'address_layout'} +
+ +
+
+ {l s='Liable fields for the address information (click to have more details):'} {$input.display_valid_fields} +
+
+ + {/if} + {if isset($input.required) && $input.required} *{/if} + {if isset($input.p)} +

+ {if is_array($input.p)} + {foreach $input.p as $p} + {if is_array($p)} + {$p.text}
+ {else} + {$p}
+ {/if} + {/foreach} + {else} + {$input.p} + {/if} +

+ {/if} + {if isset($languages)}
{/if} +
+ {if $input.name == 'id_state'} +
+ {/if} + {/foreach} + {elseif $key == 'submit'} +
+ +
+ {/if} + {/foreach} + {if $required_fields} +
* {l s ='Required field'}
+ {/if} +
+
+ + +

+{if $firstCall} + {if $back} + {l s='Back'} + {else} + {l s='Back to list'} + {/if} +
+{/if} diff --git a/admin-dev/themes/template/list_header.tpl b/admin-dev/themes/template/list_header.tpl index 8786db544..ddb47c74a 100644 --- a/admin-dev/themes/template/list_header.tpl +++ b/admin-dev/themes/template/list_header.tpl @@ -69,13 +69,13 @@ {if $page > 1} -   - +   + {/if} {l s='Page '}{$page} / {$total_pages} {if $page < $total_pages} -   - +   + {/if} | {l s='Display'}