[*] BO #PSFV-94 : Added AdminCountriesController

This commit is contained in:
lLefevre
2011-10-20 09:32:13 +00:00
parent d21add0fed
commit 3c86e1ec5f
6 changed files with 868 additions and 413 deletions
-353
View File
@@ -1,353 +0,0 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-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 <contact@prestashop.com>
* @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 = '<ul>';
$appendContainer = '';
$objectList = AddressFormat::getLiableClass('Address');
$objectList['Address'] = NULL;
// Get the available properties for each class
foreach($objectList as $className => &$object)
{
$fields = array();
$html .= '<li>
<a href="javascript:void(0);" onClick="displayAvailableFields(\''.$className.'\')">'.$className.'</a>';
foreach(AddressFormat::getValidateFields($className) as $name)
$fields[] = '<a style="color:#4B8;" href="javascript:void(0);" class="addPattern" id="'.$className.':'.$name.'">
'.$name.'</a>';
$html .= '
<div class="availableFieldsList" id="availableListFieldsFor_'.$className.'" style="width:300px;">
'.implode(', ', $fields).'</div></li>';
unset($object);
}
return $html .= '</ul>';
}
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 '
<script type="text/javascript" language="javascript" src="'._PS_JS_DIR_.'jquery/jquery-fieldselection.js"></script>
<script type="text/javascript" language="javascript">
lastLayoutModified = "";
$(document).ready(function()
{
$(".availableFieldsList").css("display", "none");
$(".addPattern").click(function()
{
addFieldsToCursorPosition($(this).attr("id"))
lastLayoutModified = $("#ordered_fields").val();
});
$("#ordered_fields").keyup(function()
{
lastLayoutModified = $(this).val();
});
$("#useLastDefaultLayout").mouseover(function()
{
switchExplanationText("'.$this->l('Will display back your last registered layout').'");
});
$("#useDefaultLayoutSystem").mouseover(function()
{
switchExplanationText("'.$this->l('Will display a default layout for this country').'");
});
$("#useCurrentLastModifiedLayout").mouseover(function()
{
switchExplanationText("'.$this->l('Will display back you\'re current editing layout').'");
});
$("#eraseCurrentLayout").mouseover(function()
{
switchExplanationText("'.$this->l('Will delete the current layout').'");
});
});
function switchExplanationText(text)
{
$("#explanationText").fadeOut("fast", function()
{
$(this).html(text);
$(this).fadeIn("fast");
});
}
function addFieldsToCursorPosition(pattern)
{
$("#ordered_fields").replaceSelection(pattern + " ");
}
function displayAvailableFields(containerName)
{
$(".availableFieldsList").each( function (){
if ($(this).attr(\'id\') != \'availableListFieldsFor_\'+containerName)
$(this).slideUp();
});
$("#availableListFieldsFor_" + containerName).slideToggle();
}
function resetLayout(defaultLayout, type)
{
if (confirm("'.$this->l('Are you sure to apply this selection ?').'"))
{
$("#ordered_fields").val(unescape(defaultLayout.replace(/\+/g, " ")));
}
}
</script>
<form action="'.self::$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post">
'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
<fieldset><legend><img src="../img/admin/world.gif" />'.$this->l('Countries').'</legend>
<label>'.$this->l('Country:').' </label>
<div class="margin-form">';
foreach ($this->_languages as $language)
echo '
<div id="name_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input size="30" type="text" name="name_'.$language['id_lang'].'" value="'.htmlentities($this->getFieldValue($obj, 'name', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'" /><sup> *</sup>
<span class="hint" name="help_box">'.$this->l('Invalid characters:').' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
</div>';
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'name', 'name');
echo ' <p style="clear: both">'.$this->l('Name of country').'</p>
</div>
<label>'.$this->l('ISO code:').' </label>
<div class="margin-form">
<input type="text" size="4" maxlength="3" name="iso_code" value="'.htmlentities($this->getFieldValue($obj, 'iso_code'), ENT_COMPAT, 'UTF-8').'" style="text-transform: uppercase;" /> <sup>*</sup>
<p>'.$this->l('2- or 3-letter ISO code, e.g., FR for France').'. <a href="http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html" target="_blank">'.$this->l('Official list here').'</a>.</p>
</div>
<label>'.$this->l('Call prefix:').' </label>
<div class="margin-form">
<input type="text" size="4" maxlength="3" name="call_prefix" value="'.(int)($this->getFieldValue($obj, 'call_prefix')).'" style="text-transform: uppercase;" /> <sup>*</sup>
<p>'.$this->l('International call prefix, e.g., 33 for France.').'.</p>
</div>
<label>'.$this->l('Default currency:').' </label>
<div class="margin-form">
<select name="id_currency">
<option value="0" '.(Tools::getValue('id_currency', $obj->id_currency) == 0 ? 'selected' : '').'>'.$this->l('Default store currency').'</option>
';
$currencies = Currency::getCurrencies();
foreach ($currencies AS $currency)
echo '<option value="'.intval($currency['id_currency']).'" '.(Tools::getValue('id_currency', $obj->id_currency) == $currency['id_currency'] ? 'selected' : '').'>'.Tools::htmlentitiesUTF8($currency['name']).'</option>';
echo '
</select>
</div>
<label>'.$this->l('Zone:').' </label>
<div class="margin-form">
<select name="id_zone">';
$zones = Zone::getZones();
foreach ($zones AS $zone)
echo ' <option value="'.(int)($zone['id_zone']).'"'.(($this->getFieldValue($obj, 'id_zone') == $zone['id_zone']) ? ' selected="selected"' : '').'>'.$zone['name'].'</option>';
$address_layout = AddressFormat::getAddressCountryFormat($obj->id);
if ($value = Tools::getValue('address_layout'))
$address_layout = $value;
echo ' </select>
<p>'.$this->l('Geographical zone where country is located').'</p>
</div>
<label>'.$this->l('Need zip code:').' </label>
<div class="margin-form">
<input type="radio" name="need_zip_code" id="need_zip_code_on" value="1" onchange="disableZipFormat();" '.((!$obj->id OR $this->getFieldValue($obj, 'need_zip_code')) ? 'checked="checked" ' : '').'/>
<label class="t" for="need_zip_code_on"> <img src="../img/admin/enabled.gif" alt="" title="'.$this->l('Yes').'" /></label>
<input type="radio" name="need_zip_code" id="need_zip_code_off" value="0" onchange="disableZipFormat();" '.((!$this->getFieldValue($obj, 'need_zip_code') AND $obj->id) ? 'checked="checked" ' : '').'/>
<label class="t" for="need_zip_code_off"> <img src="../img/admin/disabled.gif" alt="" title="'.$this->l('No').'" /></label>
</div>
<label class="zip_code_format">'.$this->l('Zip code format:').' </label>
<div class="margin-form zip_code_format">
<input type="text" name="zip_code_format" id="zip_code_format" value="'.$this->getFieldValue($obj, 'zip_code_format').'" onkeyup="$(\'#zip_code_format\').val($(\'#zip_code_format\').val().toUpperCase());" /> <sup>*</sup>
<p>'.$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').'.</p>
</div>
<label class="address_layout">'.$this->l('Address layout:').' </label>
<div class="margin-form" style="vertical-align: top;">
<div style="float:left">
<textarea id="ordered_fields" name="address_layout" style="width: 300px;height: 140px;">'.$address_layout.'</textarea>
</div>
<div style="float:left; margin-left:20px; width:340px;">
'.$this->l('Liable fields for the address information (click to have more details)').': '.$this->_displayValidFields().'
</div>
<div class="clear"></div>
<div style="margin:10px 0 10px 0;">
<a id="useLastDefaultLayout" style="margin-left:5px;" href="javascript:void(0)" onClick="resetLayout(\''.urlencode($address_layout).'\', \'lastDefault\');" class="button">'.
$this->l('Use the last registered layout').'</a>
<a id="useDefaultLayoutSystem" style="margin-left:5px;" href="javascript:void(0)" onClick="resetLayout(\''.urlencode($defaultLayout).'\', \'defaultSystem\');" class="button">'.
$this->l('Use a default layout').'</a>
<a id="useCurrentLastModifiedLayout" style="margin-left:5px;" href="javascript:void(0)" onClick="resetLayout(lastLayoutModified, \'currentModified\')" class="button">'.
$this->l('Use my current modified layout').'</a>
<a id="eraseCurrentLayout" style="margin-left:5px;" href="javascript:void(0)" onClick="resetLayout(\'\', \'erase\');" class="button">'.
$this->l('Clean layout').'</a>
<div style="margin-top:10px; padding-top:5px; height:10px;" id="explanationText"></div>
</div>
</div>
<label>'.$this->l('Status:').' </label>
<div class="margin-form">
<input type="radio" name="active" id="active_on" value="1" '.((!$obj->id OR $this->getFieldValue($obj, 'active')) ? 'checked="checked" ' : '').'/>
<label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="" title="'.$this->l('Enabled').'" /></label>
<input type="radio" name="active" id="active_off" value="0" '.((!$this->getFieldValue($obj, 'active') AND $obj->id) ? 'checked="checked" ' : '').'/>
<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="" title="'.$this->l('Disabled').'" /></label>
<p>'.$this->l('Enabled or disabled').'</p>
</div>
<label>'.$this->l('Contains states:').' </label>
<div class="margin-form">
<input type="radio" name="contains_states" id="contains_states_on" value="1" '.((!$obj->id OR $this->getFieldValue($obj, 'contains_states')) ? 'checked="checked" ' : '').'/>
<label class="t" for="contains_states_on"> <img src="../img/admin/enabled.gif" alt="" title="" />'.$this->l('Yes').'</label>
<input type="radio" name="contains_states" id="contains_states_off" value="0" '.((!$this->getFieldValue($obj, 'contains_states') AND $obj->id) ? 'checked="checked" ' : '').'/>
<label class="t" for="contains_states_off"> <img src="../img/admin/disabled.gif" alt="" title="" />'.$this->l('No').'</label>
</div>
<label>'.$this->l('Need tax identification number?').' </label>
<div class="margin-form">
<input type="radio" name="need_identification_number" id="need_identification_number_on" value="1" '.((!$obj->id OR $this->getFieldValue($obj, 'need_identification_number')) ? 'checked="checked" ' : '').'/>
<label class="t" for="need_identification_number_on"> <img src="../img/admin/enabled.gif" alt="" title="" />'.$this->l('Yes').'</label>
<input type="radio" name="need_identification_number" id="need_identification_number_off" value="0" '.((!$this->getFieldValue($obj, 'need_identification_number') AND $obj->id) ? 'checked="checked" ' : '').'/>
<label class="t" for="need_identification_number_off"> <img src="../img/admin/disabled.gif" alt="" title="" />'.$this->l('No').'</label>
</div>
<div class="clear"></div>
<label>'.$this->l('Display tax label:').' </label>
<div class="margin-form">
<input type="radio" name="display_tax_label" id="display_tax_label_on" value="1" '.((!$obj->id OR $this->getFieldValue($obj, 'display_tax_label')) ? 'checked="checked" ' : '').'/>
<label class="t" for="display_tax_label_on"> <img src="../img/admin/enabled.gif" alt="" title="" />'.$this->l('Yes').'</label>
<input type="radio" name="display_tax_label" id="display_tax_label_off" value="0" '.((!$this->getFieldValue($obj, 'display_tax_label') AND $obj->id) ? 'checked="checked" ' : '').'/>
<label class="t" for="display_tax_label_off"> <img src="../img/admin/disabled.gif" alt="" title="" />'.$this->l('No').'</label>
</div>';
if (Shop::isFeatureActive())
{
echo '<label>'.$this->l('Shop association:').'</label><div class="margin-form">';
$this->displayAssoShop();
echo '</div>';
}
echo '
<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
</div>
<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
</fieldset>
</form>
<script type="text/javascript">disableZipFormat();</script>';
}
}
@@ -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 <contact@prestashop.com>
* @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}
<script type="text/javascript" language="javascript" src="../js/jquery/jquery-fieldselection.js"></script>
<script type="text/javascript">
var vat_number = {$vat_number};
var module_dir = '{$module_dir}';
var id_language = {$defaultFormLanguage};
var languages = new Array();
var lastLayoutModified = "";
$(document).ready(function() {ldelim}
{foreach $languages as $k => $language}
languages[{$k}] = {ldelim}
id_lang: {$language.id_lang},
iso_code: '{$language.iso_code}',
name: '{$language.name}'
{rdelim};
{/foreach}
displayFlags(languages, id_language, {$allowEmployeeFormLang});
{if isset($fields_value.id_state)}
if ($('#id_country') && $('#id_state'))
{ldelim}
ajaxStates({$fields_value.id_state});
$('#id_country').change(function() {ldelim}
ajaxStates();
{rdelim});
{rdelim}
{/if}
$('.availableFieldsList').css("display", "none");
$('.addPattern').click(function() {ldelim}
addFieldsToCursorPosition($(this).attr("id"))
lastLayoutModified = $("#ordered_fields").val();
{rdelim});
$('#ordered_fields').keyup(function() {ldelim}
lastLayoutModified = $(this).val();
{rdelim});
$('#useLastDefaultLayout').mouseover(function() {ldelim}
switchExplanationText("{l s='Will display back your last registered layout'}");
{rdelim});
$('#useDefaultLayoutSystem').mouseover(function() {ldelim}
switchExplanationText("{l s='Will display a default layout for this country'}");
{rdelim});
$('#useCurrentLastModifiedLayout').mouseover(function() {ldelim}
switchExplanationText("{l s='Will display back you\'re current editing layout'}");
{rdelim});
$('#eraseCurrentLayout').mouseover(function() {ldelim}
switchExplanationText("{l s='Will delete the current layout'}");
{rdelim});
$('#need_zip_code_on, #need_zip_code_off').change(function() {ldelim}
disableZipFormat();
{rdelim});
{rdelim});
function switchExplanationText(text) {ldelim}
$("#explanationText").fadeOut("fast", function() {ldelim}
$(this).html(text);
$(this).fadeIn("fast");
{rdelim});
{rdelim}
function addFieldsToCursorPosition(pattern) {ldelim}
$("#ordered_fields").replaceSelection(pattern + " ");
{rdelim}
function displayAvailableFields(containerName) {ldelim}
$(".availableFieldsList").each( function () {ldelim}
if ($(this).attr('id') != 'availableListFieldsFor_'+containerName)
$(this).slideUp();
{rdelim});
$("#availableListFieldsFor_" + containerName).slideToggle();
{rdelim}
function resetLayout(defaultLayout, type) {ldelim}
if (confirm("{l s='Are you sure to apply this selection ?'}"))
$("#ordered_fields").val(unescape(defaultLayout.replace(/\+/g, " ")));
{rdelim}
</script>
<script type="text/javascript" src="../js/form.js"></script>
{/if}
<form action="{$current}&submitAdd{$table}=1&token={$token}" method="post" enctype="multipart/form-data">
{if $form_id}
<input type="hidden" name="id_{$table}" value="{$form_id}" />
{/if}
<fieldset>
{foreach $fields as $key => $field}
{if $key == 'legend'}
<legend>
{if isset($field.image)}<img src="{$field.image}" alt="{$field.title}" />{/if}
{$field.title}
</legend>
{elseif $key == 'input'}
{foreach $field as $input}
{if $input.name == 'id_state'}
<div id="contains_states" {if $contains_states}style="display:none;"{/if}>
{/if}
{if isset($input.label)}
<label>{$input.label} </label>
{/if}
<div class="margin-form">
{if $input.type == 'text'}
{if isset($input.lang) && isset($input.attributeLang)}
{foreach $languages as $language}
<div id="{$input.name}_{$language.id_lang}" style="display:{if $language.id_lang == $defaultFormLanguage}block{else}none{/if}; float: left;">
<input type="text"
name="{$input.name}_{$language.id_lang}"
value="{$fields_value[$input.name][$language.id_lang]}"
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.maxlength)}maxlength="{$input.maxlength}"{/if}
{if isset($input.class)}class="{$input.class}"{/if}
{if isset($input.readonly) && $input.readonly}readonly="readonly"{/if} />
{if isset($input.hint)}<span class="hint" name="help_box">{$input.hint}<span class="hint-pointer">&nbsp;</span></span>{/if}
</div>
{/foreach}
{if count($languages) > 1}
<div class="displayed_flag">
<img src="../img/l/{$defaultFormLanguage}.jpg"
class="pointer"
id="language_current_{$input.name}"
onclick="toggleLanguageFlags(this);" />
</div>
<div id="languages_{$input.name}" class="language_flags">
{l s='Choose language:'}<br /><br />
{foreach $languages as $language}
<img src="../img/l/{$language.id_lang}.jpg"
class="pointer"
alt="{$language.name}"
title="{$language.name}"
onclick="changeLanguage('{$input.name}', '{$input.attributeLang}', {$language.id_lang}, '{$language.iso_code}');" />
{/foreach}
</div>
{/if}
{else}
<input type="text"
name="{$input.name}"
id="{$input.name}"
value="{$fields_value[$input.name]}"
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.maxlength)}maxlength="{$input.maxlength}"{/if}
{if isset($input.class)}class="{$input.class}"{/if}
{if isset($input.readonly) && $input.readonly}readonly="readonly"{/if} />
{if isset($input.hint)}<span class="hint" name="help_box">{$input.hint}<span class="hint-pointer">&nbsp;</span></span>{/if}
{/if}
{elseif $input.type == 'hidden'}
<input type="hidden" name="{$input.name}" value="{$fields_value[$input.name]}" />
{elseif $input.type == 'select'}
<select name="{$input.name}" id="{$input.name}" {if isset($input.multiple)}multiple="multiple" {/if}{if isset($input.onchange)}onchange="{$input.onchange}"{/if}>
{if isset($input.options.default)}
<option value="{$input.options.default.value}">{$input.options.default.label}</option>
{/if}
{if isset($input.options.optiongroup)}
{foreach $input.options.optiongroup.query AS $optiongroup}
<optgroup label="{$optiongroup[$input.options.optiongroup.label]}">
{foreach $optiongroup[$input.options.options.query] as $option}
<option value="{$option[$input.options.options.id]}"
{if isset($input.multiple)}
{foreach $fields_value[$input.name] as $field_value}
{if $field_value == $option[$input.options.options.id]}selected="selected"{/if}
{/foreach}
{else}
{if $fields_value[$input.name] == $option[$input.options.options.id]}selected="selected"{/if}
{/if}
>{$option[$input.options.options.name]|escape:'htmlall':'UTF-8'}</option>
{/foreach}
</optgroup>
{/foreach}
{else}
{foreach $input.options.query AS $option}
<option value="{$option[$input.options.id]}"
{if isset($input.multiple)}
{foreach $fields_value[$input.name] as $field_value}
{$field_value}
{if $field_value == $option[$input.options.id]}selected="selected"{/if}
{/foreach}
{else}
{if $fields_value[$input.name] == $option[$input.options.id]}selected="selected"{/if}
{/if}
>{$option[$input.options.name]|escape:'htmlall':'UTF-8'}</option>
{/foreach}
{/if}
</select>
{if isset($input.hint)}<span class="hint" name="help_box">{$input.hint}<span class="hint-pointer">&nbsp;</span></span>{/if}
{elseif $input.type == 'radio'}
{foreach $input.values as $value}
<input type="radio"
name="{$input.name}"
id="{$value.id}"
value="{$value.value|escape:'htmlall':'UTF-8'}"
{if $fields_value[$input.name] == $value.value}checked="checked"{/if} />
<label {if isset($input.class)}class="{$input.class}"{/if} for="{$value.id}">
{if isset($input.is_bool) && $input.is_bool == true}
{if $value.value == 1}
<img src="../img/admin/enabled.gif" alt="{$value.label}" title="{$value.label}" />
{else}
<img src="../img/admin/disabled.gif" alt="{$value.label}" title="{$value.label}" />
{/if}
{else}
{$value.label}
{/if}
</label>
{if isset($input.br) && $input.br}<br />{/if}
{/foreach}
{elseif $input.type == 'textarea'}
{if isset($input.lang) && isset($input.attributeLang)}
{foreach $languages as $language}
<div id="{$input.name}_{$language.id_lang}" style="display:{if $language.id_lang == $defaultFormLanguage}block{else}none{/if}; float: left;">
<textarea cols="{$input.cols}" rows="{$input.rows}" name="{$input.name}_{$language.id_lang}">{$fields_value[$input.name][$language.id_lang]}</textarea>
</div>
{/foreach}
{if count($languages) > 1}
<div class="displayed_flag">
<img src="../img/l/{$defaultFormLanguage}.jpg"
class="pointer"
id="language_current_{$input.name}"
onclick="toggleLanguageFlags(this);" />
</div>
<div id="languages_{$input.name}" class="language_flags">
{l s='Choose language:'}<br /><br />
{foreach $languages as $language}
<img src="../img/l/{$language.id_lang}.jpg"
class="pointer"
alt="{$language.name}"
title="{$language.name}"
onclick="changeLanguage('{$input.name}', '{$input.attributeLang}', {$language.id_lang}, '{$language.iso_code}');" />
{/foreach}
</div>
{/if}
{else}
<textarea name="{$input.name}" id="{$input.name}" cols="{$input.cols}" rows="{$input.rows}">{$fields_value[$input.name]}</textarea>
{/if}
{elseif $input.type == 'checkbox'}
{foreach $input.values.query as $value}
{assign var=id_checkbox value=$input.name|cat:'_'|cat:$value[$input.values.id]}
<input type="checkbox" name="{$id_checkbox}" id="{$id_checkbox}" {if $fields_value[$id_checkbox]}checked="checked"{/if} />
<label for="{$id_checkbox}" class="t"><strong>{$value[$input.values.name]}</strong></label><br />
{/foreach}
{elseif $input.type == 'file'}
<input type="file" name="{$input.name}" />
<img src="{$fields_value[$input.name]}" />
{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}
<label>{l s='Shop association:'}</label>
<div class="margin-form">
{$asso_shop}
</div>
{elseif $input.type == 'address_layout'}
<div style="float:left">
<textarea id="ordered_fields" name="address_layout" style="width: 300px;height: 140px;">{$input.address_layout}</textarea>
</div>
<div style="float:left; margin-left:20px; width:340px;">
{l s='Liable fields for the address information (click to have more details):'} {$input.display_valid_fields}
</div>
<div class="clear"></div>
<div style="margin:10px 0 10px 0;">
<a id="useLastDefaultLayout" style="margin-left:5px;" href="javascript:void(0)" onClick="resetLayout('{$input.encoding_address_layout}', 'lastDefault');" class="button">
{l s='Use the last registered layout'}</a>
<a id="useDefaultLayoutSystem" style="margin-left:5px;" href="javascript:void(0)" onClick="resetLayout('{$input.encoding_default_layout}', 'defaultSystem');" class="button">
{l s='Use a default layout'}</a>
<a id="useCurrentLastModifiedLayout" style="margin-left:5px;" href="javascript:void(0)" onClick="resetLayout(lastLayoutModified, 'currentModified')" class="button">
{l s='Use my current modified layout'}</a>
<a id="eraseCurrentLayout" style="margin-left:5px;" href="javascript:void(0)" onClick="resetLayout('', 'erase');" class="button">
{l s='Clean layout'}</a>
<div style="margin-top:10px; padding-top:5px; height:10px;" id="explanationText"></div>
</div>
{/if}
{if isset($input.required) && $input.required} <sup>*</sup>{/if}
{if isset($input.p)}
<p class="clear">
{if is_array($input.p)}
{foreach $input.p as $p}
{if is_array($p)}
<span id="{$p.id}">{$p.text}</span><br />
{else}
{$p}<br />
{/if}
{/foreach}
{else}
{$input.p}
{/if}
</p>
{/if}
{if isset($languages)}<div class="clear"></div>{/if}
</div>
{if $input.name == 'id_state'}
</div>
{/if}
{/foreach}
{elseif $key == 'submit'}
<div class="margin-form">
<input type="submit" value="{$field.title}" name="submitAdd{$table}" {if isset($field.class)}class="{$field.class}"{/if} />
</div>
{/if}
{/foreach}
{if $required_fields}
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
{/if}
</fieldset>
</form>
<script type="text/javascript">disableZipFormat();</script>
<br /><br />
{if $firstCall}
{if $back}
<a href="{$back}"><img src="../img/admin/arrow2.gif" />{l s='Back'}</a>
{else}
<a href="{$current}&token={$token}"><img src="../img/admin/arrow2.gif" />{l s='Back to list'}</a>
{/if}
<br />
{/if}
+4 -4
View File
@@ -69,13 +69,13 @@
<td style="vertical-align: bottom;">
<span style="float: left;">
{if $page > 1}
<input type="image" src="../img/admin/list-prev2.gif" onclick="getE(\'submitFilter{$table}\').value=1"/>&nbsp;
<input type="image" src="../img/admin/list-prev.gif" onclick="getE(\'submitFilter{$table}\').value={$page - 1}"/>
<input type="image" src="../img/admin/list-prev2.gif" onclick="getE('submitFilter{$table}').value=1"/>&nbsp;
<input type="image" src="../img/admin/list-prev.gif" onclick="getE('submitFilter{$table}').value={$page - 1}"/>
{/if}
{l s='Page '}<b>{$page}</b> / {$total_pages}
{if $page < $total_pages}
<input type="image" src="../img/admin/list-next.gif" onclick="getE(\'submitFilter{$table}\').value={$page + 1}"/>&nbsp;
<input type="image" src="../img/admin/list-next2.gif" onclick="getE(\'submitFilter{$table}'\').value={$total_pages}"/>
<input type="image" src="../img/admin/list-next.gif" onclick="getE('submitFilter{$table}').value={$page + 1}"/>&nbsp;
<input type="image" src="../img/admin/list-next2.gif" onclick="getE('submitFilter{$table}'').value={$total_pages}"/>
{/if}
| {l s='Display'}
<select name="pagination">
+7
View File
@@ -538,6 +538,10 @@ class AdminControllerCore extends Controller
/* Table alias could be specified using a ! eg. alias!field */
$tmp_tab = explode('!', $key);
$key = (count($tmp_tab) > 1 ? $tmp_tab[1] : $tmp_tab[0]);
// init list declaration
$this->initList();
if (array_key_exists($key, $this->fieldsDisplay))
unset($this->context->cookie->$cookie_key);
}
@@ -746,6 +750,9 @@ class AdminControllerCore extends Controller
protected function filterToField($key, $filter)
{
// init list declaration
$this->initList();
foreach ($this->fieldsDisplay as $field)
if (array_key_exists('filter_key', $field) && $field['filter_key'] == $key)
return $field;
+65 -56
View File
@@ -27,53 +27,65 @@
class CountryCore extends ObjectModel
{
public $id;
public $id;
/** @var integer Zone id which country belongs */
public $id_zone;
public $id_zone;
/** @var integer Currency id which country belongs */
public $id_currency;
public $id_currency;
/** @var string 2 letters iso code */
public $iso_code;
public $iso_code;
/** @var integer international call prefix */
public $call_prefix;
public $call_prefix;
/** @var string Name */
public $name;
public $name;
/** @var boolean Contain states */
public $contains_states;
public $contains_states;
/** @var boolean Need identification number dni/nif/nie */
public $need_identification_number;
public $need_identification_number;
/** @var boolean Need Zip Code */
public $need_zip_code;
public $need_zip_code;
/** @var string Zip Code Format */
public $zip_code_format;
public $zip_code_format;
/** @var boolean Display or not the tax incl./tax excl. mention in the front office */
public $display_tax_label = true;
/** @var boolean Status for delivery */
public $active = true;
public $active = true;
protected static $_idZones = array();
protected $tables = array ('country', 'country_lang');
protected $tables = array ('country', 'country_lang');
protected $fieldsRequired = array('id_zone', 'id_currency', 'iso_code', 'contains_states', 'need_identification_number', 'display_tax_label');
protected $fieldsSize = array('iso_code' => 3);
protected $fieldsValidate = array('id_zone' => 'isUnsignedId', 'id_currency' => 'isUnsignedId', 'call_prefix' => 'isInt', 'iso_code' => 'isLanguageIsoCode', 'active' => 'isBool', 'contains_states' => 'isBool', 'need_identification_number' => 'isBool', 'need_zip_code' => 'isBool', 'zip_code_format' => 'isZipCodeFormat', 'display_tax_label' => 'isBool');
protected $fieldsRequiredLang = array('name');
protected $fieldsSizeLang = array('name' => 64);
protected $fieldsValidateLang = array('name' => 'isGenericName');
protected $fieldsRequired = array('id_zone', 'id_currency', 'iso_code', 'contains_states', 'need_identification_number', 'display_tax_label');
protected $fieldsSize = array('iso_code' => 3);
protected $fieldsValidate = array(
'id_zone' => 'isUnsignedId',
'id_currency' => 'isUnsignedId',
'call_prefix' => 'isInt',
'iso_code' => 'isLanguageIsoCode',
'active' => 'isBool',
'contains_states' => 'isBool',
'need_identification_number' => 'isBool',
'need_zip_code' => 'isBool',
'zip_code_format' => 'isZipCodeFormat',
'display_tax_label' => 'isBool'
);
protected $webserviceParameters = array(
protected $fieldsRequiredLang = array('name');
protected $fieldsSizeLang = array('name' => 64);
protected $fieldsValidateLang = array('name' => 'isGenericName');
protected $webserviceParameters = array(
'objectsNodeName' => 'countries',
'fields' => array(
'id_zone' => array('sqlId' => 'id_zone', 'xlink_resource'=> 'zones'),
@@ -81,20 +93,20 @@ class CountryCore extends ObjectModel
),
);
protected $table = 'country';
protected $identifier = 'id_country';
protected $table = 'country';
protected $identifier = 'id_country';
public function getFields()
{
$this->validateFields();
$fields['id_zone'] = (int)($this->id_zone);
$fields['id_currency'] = (int)($this->id_currency);
$fields['id_zone'] = (int)$this->id_zone;
$fields['id_currency'] = (int)$this->id_currency;
$fields['iso_code'] = pSQL(strtoupper($this->iso_code));
$fields['call_prefix'] = (int)($this->call_prefix);
$fields['active'] = (int)($this->active);
$fields['contains_states'] = (int)($this->contains_states);
$fields['need_identification_number'] = (int)($this->need_identification_number);
$fields['need_zip_code'] = (int)($this->need_zip_code);
$fields['call_prefix'] = (int)$this->call_prefix;
$fields['active'] = (int)$this->active;
$fields['contains_states'] = (int)$this->contains_states;
$fields['need_identification_number'] = (int)$this->need_identification_number;
$fields['need_zip_code'] = (int)$this->need_zip_code;
$fields['zip_code_format'] = $this->zip_code_format;
$fields['display_tax_label'] = $this->display_tax_label;
return $fields;
@@ -118,14 +130,14 @@ class CountryCore extends ObjectModel
* @param boolean $active return only active coutries
* @return array Countries and corresponding zones
*/
static public function getCountries($id_lang, $active = false, $containStates = NULL, Shop $shop = null)
public static function getCountries($id_lang, $active = false, $contain_states = null, Shop $shop = null)
{
if (!Validate::isBool($active))
die(Tools::displayError());
if (!$shop)
$shop = Context::getContext()->shop;
$states = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT s.*
FROM `'._DB_PREFIX_.'state` s
@@ -138,13 +150,13 @@ class CountryCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'zone` z ON z.`id_zone` = c.`id_zone`
WHERE 1'
.($active ? ' AND c.active = 1' : '')
.(!is_null($containStates) ? ' AND c.`contains_states` = '.(int)($containStates) : '').'
.(!is_null($contain_states) ? ' AND c.`contains_states` = '.(int)$contain_states : '').'
ORDER BY cl.name ASC';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
$countries = array();
foreach ($result AS &$country)
foreach ($result as &$country)
$countries[$country['id_country']] = $country;
foreach ($states AS &$state)
foreach ($states as &$state)
if (isset($countries[$state['id_country']])) /* Does not keep the state if its country has been disabled and not selected */
$countries[$state['id_country']]['states'][] = $state;
@@ -180,7 +192,7 @@ class CountryCore extends ObjectModel
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT `id_zone`
FROM `'._DB_PREFIX_.'country`
WHERE `id_country` = '.(int)($id_country));
WHERE `id_country` = '.(int)$id_country);
self::$_idZones[$id_country] = $result['id_zone'];
return $result['id_zone'];
@@ -196,10 +208,11 @@ class CountryCore extends ObjectModel
public static function getNameById($id_lang, $id_country)
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT `name`
FROM `'._DB_PREFIX_.'country_lang`
WHERE `id_lang` = '.(int)($id_lang).'
AND `id_country` = '.(int)($id_country));
SELECT `name`
FROM `'._DB_PREFIX_.'country_lang`
WHERE `id_lang` = '.(int)$id_lang.'
AND `id_country` = '.(int)$id_country
);
return $result['name'];
}
@@ -213,9 +226,10 @@ class CountryCore extends ObjectModel
public static function getIsoById($id_country)
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT `iso_code`
FROM `'._DB_PREFIX_.'country`
WHERE `id_country` = '.(int)($id_country));
SELECT `iso_code`
FROM `'._DB_PREFIX_.'country`
WHERE `id_country` = '.(int)$id_country
);
return $result['iso_code'];
}
@@ -227,45 +241,40 @@ class CountryCore extends ObjectModel
* @param string $country Country Name
* @return intval Country id
*/
public static function getIdByName($id_lang = NULL, $country)
public static function getIdByName($id_lang = null, $country)
{
$sql = '
SELECT `id_country`
FROM `'._DB_PREFIX_.'country_lang`
WHERE `name` LIKE \''.pSQL($country).'\'';
if ($id_lang)
$sql .= ' AND `id_lang` = '.(int)($id_lang);
$sql .= ' AND `id_lang` = '.(int)$id_lang;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
return ((int)($result['id_country']));
return (int)$result['id_country'];
}
public static function getNeedZipCode($id_country)
{
if (!(int)($id_country))
if (!(int)$id_country)
return false;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT `need_zip_code`
FROM `'._DB_PREFIX_.'country`
WHERE `id_country` = '.(int)($id_country));
WHERE `id_country` = '.(int)$id_country);
}
public static function getZipCodeFormat($id_country)
{
if (!(int)($id_country))
if (!(int)$id_country)
return false;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT `zip_code_format`
FROM `'._DB_PREFIX_.'country`
WHERE `id_country` = '.(int)($id_country));
}
public static function displayCallPrefix($prefix)
{
return ((int)($prefix) ? '+'.$prefix : '-');
WHERE `id_country` = '.(int)$id_country);
}
/**
@@ -282,12 +291,12 @@ class CountryCore extends ObjectModel
public static function getCountriesByZoneId($id_zone, $id_lang, Shop $shop = null)
{
if (empty($id_zone) OR empty($id_lang))
if (empty($id_zone) || empty($id_lang))
die(Tools::displayError());
if (!$shop)
$shop = Context::getContext()->shop;
$sql = ' SELECT DISTINCT c.*, cl.*
FROM `'._DB_PREFIX_.'country` c
'.$shop->addSqlAssociation('country', 'c', false).'
@@ -0,0 +1,443 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-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 <contact@prestashop.com>
* @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 AdminCountriesControllerCore extends AdminController
{
public function __construct()
{
$this->table = 'country';
$this->className = 'Country';
$this->lang = true;
$this->deleted = false;
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->requiredDatabase = true;
$this->context = Context::getContext();
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
$this->fieldImageSettings = array(
'name' => 'logo',
'dir' => 'st'
);
parent::__construct();
}
public function initList()
{
$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'
),
'active' => array(
'title' => $this->l('Enabled'),
'align' => 'center',
'active' => 'status',
'type' => 'bool',
'orderby' => false,
'filter_key' => 'a!active'
)
);
}
public function initOptions()
{
$this->options = 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'
)
),
'submit' => array()
)
);
}
public function initForm()
{
if (!($obj = $this->loadObject(true)))
return;
$address_layout = AddressFormat::getAddressCountryFormat($obj->id);
if ($value = Tools::getValue('address_layout'))
$address_layout = $value;
$default_layout = '';
$default_layout_tab = array(
array('firstname', 'lastname'),
array('company'),
array('vat_number'),
array('address1'),
array('address2'),
array('postcode', 'city'),
array('Country:name'),
array('phone'));
foreach ($default_layout_tab as $line)
$default_layout .= implode(' ', $line)."\r\n";
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Countries'),
'image' => '../img/admin/world.gif'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Country:'),
'name' => 'name',
'lang' => true,
'attributeLang' => 'name',
'size' => 30,
'required' => true,
'hint' => $this->l('Invalid characters:').' <>;=#{}',
'p' => $this->l('Name of country')
),
array(
'type' => 'text',
'label' => $this->l('ISO code:'),
'name' => 'iso_code',
'size' => 4,
'maxlength' => 3,
'class' => 'uppercase',
'required' => true,
'p' => $this->l('2- or 3-letter ISO code, e.g., FR for France').'.
<a href="http://www.iso.org/iso/country_codes/iso_3166_code_lists/country_names_and_code_elements.htm" target="_blank">'.
$this->l('Official list here').'
</a>.'
),
array(
'type' => 'text',
'label' => $this->l('Call prefix:'),
'name' => 'call_prefix',
'size' => 4,
'maxlength' => 3,
'class' => 'uppercase',
'required' => true,
'p' => $this->l('International call prefix, e.g., 33 for France.')
),
array(
'type' => 'select',
'label' => $this->l('Default currency:'),
'name' => 'id_currency',
'options' => array(
'query' => Currency::getCurrencies(),
'id' => 'id_currency',
'name' => 'name',
'default' => array(
'label' => $this->l('Default store currency'),
'value' => 0
)
)
),
array(
'type' => 'select',
'label' => $this->l('Zone:'),
'name' => 'id_zone',
'options' => array(
'query' => Zone::getZones(),
'id' => 'id_zone',
'name' => 'name'
),
'p' => $this->l('Geographical zone where country is located')
),
array(
'type' => 'radio',
'label' => $this->l('Need zip code:'),
'name' => 'need_zip_code',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'need_zip_code_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'need_zip_code_off',
'value' => 0,
'label' => $this->l('No')
)
)
),
array(
'type' => 'text',
'label' => $this->l('Zip code format:'),
'name' => 'zip_code_format',
'class' => 'uppercase',
'required' => true,
'p' => $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')
),
array(
'type' => 'address_layout',
'label' => $this->l('Address layout:'),
'name' => 'address_layout',
'address_layout' => $address_layout,
'encoding_address_layout' => urlencode($address_layout),
'encoding_default_layout' => urlencode($default_layout),
'display_valid_fields' => $this->displayValidFields()
),
array(
'type' => 'radio',
'label' => $this->l('Status:'),
'name' => 'active',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
'p' => $this->l('Display or not this store')
),
array(
'type' => 'radio',
'label' => $this->l('Contains states:'),
'name' => 'contains_states',
'required' => false,
'class' => 't',
'values' => array(
array(
'id' => 'contains_states_on',
'value' => 1,
'label' => '<img src="../img/admin/enabled.gif" alt="'.$this->l('Yes').'" title="'.$this->l('Yes').'" />'.$this->l('Yes')
),
array(
'id' => 'contains_states_off',
'value' => 0,
'label' => '<img src="../img/admin/disabled.gif" alt="'.$this->l('No').'" title="'.$this->l('No').'" />'.$this->l('No')
)
)
),
array(
'type' => 'radio',
'label' => $this->l('Need tax identification number?'),
'name' => 'need_identification_number',
'required' => false,
'class' => 't',
'values' => array(
array(
'id' => 'need_identification_number_on',
'value' => 1,
'label' => '<img src="../img/admin/enabled.gif" alt="'.$this->l('Yes').'" title="'.$this->l('Yes').'" />'.$this->l('Yes')
),
array(
'id' => 'need_identification_number_off',
'value' => 0,
'label' => '<img src="../img/admin/disabled.gif" alt="'.$this->l('No').'" title="'.$this->l('No').'" />'.$this->l('No')
)
)
),
array(
'type' => 'radio',
'label' => $this->l('Display tax label:'),
'name' => 'display_tax_label',
'required' => false,
'class' => 't',
'values' => array(
array(
'id' => 'display_tax_label_on',
'value' => 1,
'label' => '<img src="../img/admin/enabled.gif" alt="'.$this->l('Yes').'" title="'.$this->l('Yes').'" />'.$this->l('Yes')
),
array(
'id' => 'display_tax_label_off',
'value' => 0,
'label' => '<img src="../img/admin/disabled.gif" alt="'.$this->l('No').'" title="'.$this->l('No').'" />'.$this->l('No')
)
)
)
)
);
if (Shop::isFeatureActive())
{
$this->fields_form['input'][] = array(
'type' => 'shop',
'label' => $this->l('Shop association:'),
'name' => 'checkBoxShopAsso',
'values' => Shop::getTree()
);
//Added values of object Shop
if ($obj->id)
{
$assos = array();
$sql = 'SELECT `id_shop`, `'.pSQL($this->identifier).'`
FROM `'._DB_PREFIX_.pSQL($this->table).'_shop`
WHERE `'.pSQL($this->identifier).'` = '.(int)$obj->id;
foreach (Db::getInstance()->executeS($sql) as $row)
$this->fields_value['shop'][$row['id_shop']][] = $row[$this->identifier];
}
}
$this->fields_form['submit'] = array(
'title' => $this->l(' Save '),
'class' => 'button'
);
}
public function postProcess()
{
if (isset($_GET['delete'.$this->table]) || 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;
}
$object = new $this->className();
$this->updateAssoShop($object->id);
$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
{
$error_list = $tmp_addr_format->getErrorList();
foreach ($error_list as $num_error => $error)
$this->_errors[] = $error;
}
if (!$save_status)
$this->_errors[] = Tools::displayError('Invalid address layout'.Db::getInstance()->getMsgError());
}
unset($tmp_addr_format);
}
return parent::postProcess();
}
}
public function initContent()
{
if ($this->display != 'edit' && $this->display != 'add')
$this->display = 'list';
parent::initContent();
}
private function displayValidFields()
{
$html = '<ul>';
$object_list = AddressFormat::getLiableClass('Address');
$object_list['Address'] = null;
// Get the available properties for each class
foreach ($object_list as $class_name => &$object)
{
$fields = array();
$html .= '<li>
<a href="javascript:void(0);" onClick="displayAvailableFields(\''.$class_name.'\')">'.$class_name.'</a>';
foreach (AddressFormat::getValidateFields($class_name) as $name)
$fields[] = '<a style="color:#4B8;" href="javascript:void(0);" class="addPattern" id="'.$class_name.':'.$name.'">
'.$name.'</a>';
$html .= '
<div class="availableFieldsList" id="availableListFieldsFor_'.$class_name.'" style="width:300px;">
'.implode(', ', $fields).'</div></li>';
unset($object);
}
return $html .= '</ul>';
}
public static function displayCallPrefix($prefix)
{
return ((int)$prefix ? '+'.$prefix : '-');
}
}