diff --git a/admin-dev/themes/template/addresses/form.tpl b/admin-dev/themes/template/addresses/form.tpl new file mode 100644 index 000000000..232038379 --- /dev/null +++ b/admin-dev/themes/template/addresses/form.tpl @@ -0,0 +1,182 @@ +{* +* 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$ +* @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_customer'} + {if isset($customer)} + + + + + {else} + +
+ * +
+ {/if} + {else} + {if $input.name == 'vat_number'} + {if $vat == 'is_applicable'} +
+ {else if $vat == 'management'} +
+ {else} +
+ {/if} + {else if $input.name == 'id_state'} +
+ {/if} + +
+ {if $input.type == 'text'} + + {elseif $input.type == 'select'} + + {elseif $input.type == 'radio'} + {foreach $input.values as $value} + + + {/foreach} + {elseif $input.type == 'textarea'} + + {elseif $input.type == 'checkbox'} + + {/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 $input.name == 'id_state' || $input.name == 'vat_number'} +
+ {/if} + {/if} + {/foreach} + {elseif $key == 'submit'} +
+ +
+ {/if} + {/foreach} + {if $requiredFields} +
* {l s ='Required field'}
+ {/if} +
+
+ +

+{if $firstCall} + {if $back} + {l s='Back'} + {else} + {l s='Back to list'} + {/if} +
+{/if} \ No newline at end of file diff --git a/admin-dev/themes/template/form.tpl b/admin-dev/themes/template/form.tpl index c074e6094..5b74d9903 100644 --- a/admin-dev/themes/template/form.tpl +++ b/admin-dev/themes/template/form.tpl @@ -42,7 +42,7 @@ displayFlags(languages, id_language, {$allowEmployeeFormLang}); {literal} - if ($('#id_country')) + if ($('#id_country') && $('#id_state')) { ajaxStates(); $('#id_country').change(function() { diff --git a/classes/HelperForm.php b/classes/HelperForm.php index d721b5951..72246de73 100644 --- a/classes/HelperForm.php +++ b/classes/HelperForm.php @@ -87,7 +87,7 @@ class HelperFormCore extends Helper 'requiredFields' => $this->getFieldsRequired(), 'vat_number' => file_exists(_PS_MODULE_DIR_.'vatnumber/ajax.php'), 'module_dir' => _MODULE_DIR_, - 'contains_states' => Country::containsStates($this->fields_value['id_country']) + 'contains_states' => (isset($this->fields_value['id_country']) && isset($this->fields_value['id_state'])) ? Country::containsStates($this->fields_value['id_country']) : null )); return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->tpl); diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php index e4903b94a..9834a5104 100644 --- a/controllers/admin/AdminAddressesController.php +++ b/controllers/admin/AdminAddressesController.php @@ -49,7 +49,8 @@ class AdminAddressesControllerCore extends AdminController $this->deleted = true; $this->_select = 'cl.`name` as country'; $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON - (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)$this->context->language->id.')'; + (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)$this->context->language->id.')'; + $this->_where = 'AND a.id_customer != 0'; $countries = Country::getCountries($this->context->language->id); foreach ($countries AS $country) @@ -64,46 +65,174 @@ class AdminAddressesControllerCore extends AdminController 'city' => array('title' => $this->l('City'), 'width' => 150), 'country' => array('title' => $this->l('Country'), 'width' => 100, 'type' => 'select', 'select' => $this->countriesArray, 'filter_key' => 'cl!id_country')); + $this->fields_form = array( + 'legend' => array( + 'title' => $this->l('Addresses'), + 'image' => '../img/admin/contact.gif' + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Customer'), + 'name' => 'id_customer', + 'size' => 33, + 'required' => true, + ), + array( + 'type' => 'text', + 'label' => $this->l('Identification Number'), + 'name' => 'dni', + 'size' => 30, + 'required' => false, + 'p' => $this->l('DNI / NIF / NIE') + ), + array( + 'type' => 'text', + 'label' => $this->l('Alias'), + 'name' => 'alias', + 'size' => 33, + 'required' => true, + 'p' => ''.$this->l('Invalid characters:').' <>;=#{} ' + ), + array( + 'type' => 'text', + 'label' => $this->l('First name'), + 'name' => 'firstname', + 'size' => 33, + 'required' => true, + 'p' => ''.$this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%: ' + ), + array( + 'type' => 'text', + 'label' => $this->l('Last name'), + 'name' => 'lastname', + 'size' => 33, + 'required' => true, + 'p' => ''.$this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%: ' + ), + array( + 'type' => 'text', + 'label' => $this->l('Company'), + 'name' => 'company', + 'size' => 33, + 'required' => false, + 'p' => ''.$this->l('Invalid characters:').' <>;=#{} ' + ), + array( + 'type' => 'text', + 'label' => $this->l('VAT number'), + 'name' => 'vat_number', + 'size' => 33, + '' + ), + array( + 'type' => 'text', + 'label' => $this->l('Address'), + 'name' => 'address1', + 'size' => 33, + 'required' => true, + ), + array( + 'type' => 'text', + 'label' => $this->l('Address').' (2)', + 'name' => 'address2', + 'size' => 33, + 'required' => false, + ), + array( + 'type' => 'text', + 'label' => $this->l('Postcode/ Zip Code'), + 'name' => 'postcode', + 'size' => 33, + 'required' => false, + ), + array( + 'type' => 'text', + 'label' => $this->l('City'), + 'name' => 'city', + 'size' => 33, + 'required' => true, + ), + array( + 'type' => 'select', + 'label' => $this->l('Country:'), + 'name' => 'id_country', + 'required' => false, + 'options' => array( + 'query' => Country::getCountries($this->context->language->id), + 'id' => 'id_country', + 'name' => 'name' + ), + ), + array( + 'type' => 'select', + 'label' => $this->l('State'), + 'name' => 'id_state', + 'required' => false, + 'options' => array( + 'id' => 'id_state', + 'name' => 'name' + ), + ), + array( + 'type' => 'text', + 'label' => $this->l('Home phone'), + 'name' => 'phone', + 'size' => 33, + 'required' => false, + ), + array( + 'type' => 'text', + 'label' => $this->l('Mobile phone'), + 'name' => 'phone_mobile', + 'size' => 33, + 'required' => false, + ), + array( + 'type' => 'textarea', + 'label' => $this->l('Other'), + 'name' => 'other', + 'cols' => 36, + 'rows' => 4, + 'required' => false, + 'p' => ''.$this->l('Forbidden characters:').' <>;=#{} ' + ), + ), + 'submit' => array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ) + ); + parent::__construct(); } public function postProcess() { - if (isset($_POST['submitAdd'.$this->table])) + if ($this->action == 'save') { // Transform e-mail in id_customer for parent processing - if ($this->addressType == 'customer') + if (Validate::isEmail(Tools::getValue('email'))) { - if (Validate::isEmail(Tools::getValue('email'))) - { - $customer = new Customer(); - $customer->getByEmail(Tools::getValue('email')); - if (Validate::isLoadedObject($customer)) - $_POST['id_customer'] = $customer->id; - else - $this->_errors[] = Tools::displayError('This e-mail address is not registered.'); - } - elseif ($id_customer = Tools::getValue('id_customer')) - { - $customer = new Customer((int)($id_customer)); - if (Validate::isLoadedObject($customer)) - $_POST['id_customer'] = $customer->id; - else - $this->_errors[] = Tools::displayError('Unknown customer'); - } + $customer = new Customer(); + $customer->getByEmail(Tools::getValue('email')); + if (Validate::isLoadedObject($customer)) + $_POST['id_customer'] = $customer->id; + else + $this->_errors[] = Tools::displayError('This e-mail address is not registered.'); + } + elseif ($id_customer = Tools::getValue('id_customer')) + { + $customer = new Customer((int)($id_customer)); + if (Validate::isLoadedObject($customer)) + $_POST['id_customer'] = $customer->id; else $this->_errors[] = Tools::displayError('Unknown customer'); - if (Country::isNeedDniByCountryId(Tools::getValue('id_country')) AND !Tools::getValue('dni')) - $this->_errors[] = Tools::displayError('Identification number is incorrect or has already been used.'); - } - - // Check manufacturer selected - if ($this->addressType == 'manufacturer') - { - $manufacturer = new Manufacturer((int)(Tools::getValue('id_manufacturer'))); - if (!Validate::isLoadedObject($manufacturer)) - $this->_errors[] = Tools::displayError('Manufacturer selected is not valid.'); } + else + $this->_errors[] = Tools::displayError('Unknown customer'); + if (Country::isNeedDniByCountryId(Tools::getValue('id_country')) AND !Tools::getValue('dni')) + $this->_errors[] = Tools::displayError('Identification number is incorrect or has already been used.'); /* If the selected country does not contain states */ $id_state = (int)(Tools::getValue('id_state')); @@ -150,7 +279,7 @@ class AdminAddressesControllerCore extends AdminController /* Reassignation of the order's new (invoice or delivery) address */ $address_type = ((int)(Tools::getValue('address_type')) == 2 ? 'invoice' : ((int)(Tools::getValue('address_type')) == 1 ? 'delivery' : '')); - if (isset($_POST['submitAdd'.$this->table]) AND ($id_order = (int)(Tools::getValue('id_order'))) AND !sizeof($this->_errors) AND !empty($address_type)) + if ($this->action == 'save' AND ($id_order = (int)(Tools::getValue('id_order'))) AND !sizeof($this->_errors) AND !empty($address_type)) { if(!Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'orders SET `id_address_'.$address_type.'` = '.Db::getInstance()->Insert_ID().' WHERE `id_order` = '.$id_order)) $this->_errors[] = Tools::displayError('An error occurred while linking this address to its order.'); @@ -173,55 +302,38 @@ class AdminAddressesControllerCore extends AdminController '.(Tools::getValue('realedit') ? '' : '').'
'.$this->l('Addresses').''; - switch ($this->addressType) - { - case 'manufacturer': - $content .= ' -
'; - $manufacturers = Manufacturer::getManufacturers(); - $content .= ''; - $content .= '
'; - $content .= ''; - break; - case 'customer': - default: - if ($obj->id) - { - $customer = new Customer($obj->id_customer); - $tokenCustomer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id); - $content .= ' - - - - '; - } - else - { - $content .= - ' -
- * -
'; - } - $content .= ' - -
- -

'.$this->l('DNI / NIF / NIE').'

-
'; - $content .= ' -
- * - '.$this->l('Invalid characters:').' <>;=#{}  -
'; - break; + if ($obj->id) + { + $customer = new Customer($obj->id_customer); + $tokenCustomer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id); + $content .= ' + + + + '; } + else + { + $content .= + ' +
+ * +
'; + } + $content .= ' + +
+ +

'.$this->l('DNI / NIF / NIE').'

+
'; + + $content .= ' +
+ * + '.$this->l('Invalid characters:').' <>;=#{}  +
'; + $addresses_fields = $this->processAddressFormat(); $addresses_fields = $addresses_fields["dlv_all_fields"]; // we use delivery address @@ -230,27 +342,24 @@ class AdminAddressesControllerCore extends AdminController { if ($addr_field_item == 'company') { - if ($this->addressType != 'manufacturer') - { - $content .= ' -
- - '.$this->l('Invalid characters:').' <>;=#{}  -
'; + $content .= ' +
+ + '.$this->l('Invalid characters:').' <>;=#{}  +
'; - if ((Configuration::get('VATNUMBER_MANAGEMENT') AND file_exists(_PS_MODULE_DIR_.'vatnumber/vatnumber.php')) && VatNumber::isApplicable(Configuration::get('PS_COUNTRY_DEFAULT'))) - $content .= '
'; - else if(Configuration::get('VATNUMBER_MANAGEMENT')) - $content .= '
'; - else - $content .='
'; + if ((Configuration::get('VATNUMBER_MANAGEMENT') AND file_exists(_PS_MODULE_DIR_.'vatnumber/vatnumber.php')) && VatNumber::isApplicable(Configuration::get('PS_COUNTRY_DEFAULT'))) + $content .= '
'; + else if(Configuration::get('VATNUMBER_MANAGEMENT')) + $content .= '
'; + else + $content .='
'; - $content .= ' -
- -
-
'; - } + $content .= ' +
+ +
+
'; } elseif ($addr_field_item == 'lastname') { @@ -441,8 +550,29 @@ class AdminAddressesControllerCore extends AdminController public function initContent() { - if ($this->display != 'edit') + if ($this->display != 'edit' && $this->display != 'add') $this->display = 'list'; + + if (!($address = $this->loadObject(true))) + return false; + + if (Validate::isLoadedObject($address)) + { + $customer = new Customer($address->id_customer); + $tokenCustomer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id); + } + + if (Configuration::get('VATNUMBER_MANAGEMENT')) + if (file_exists(_PS_MODULE_DIR_.'vatnumber/vatnumber.php') && VatNumber::isApplicable(Configuration::get('PS_COUNTRY_DEFAULT'))) + $vat = 'is_applicable'; + else + $vat = 'management'; + + $this->context->smarty->assign(array( + 'vat' => isset($vat) ? $vat : null, + 'customer' => isset($customer) ? $customer : null, + 'tokenCustomer' => isset ($tokenCustomer) ? $tokenCustomer : null + )); parent::initContent(); }