mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-20 18:08:02 +02:00
- include US states from sbox
- methods to translate between country-code and -name - methods to return a translated country-list
This commit is contained in:
parent
fbb8eee4ee
commit
970ebe0784
@ -1,30 +1,30 @@
|
||||
<?php
|
||||
/**************************************************************************\
|
||||
* eGroupWare - Country Codes *
|
||||
* http://www.egroupware.org *
|
||||
* Written by Mark Peters <skeeter@phpgroupware.org> *
|
||||
* -------------------------------------------- *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU General Public License as published by the *
|
||||
* Free Software Foundation; either version 2 of the License, or (at your *
|
||||
* option) any later version. *
|
||||
\**************************************************************************/
|
||||
/**************************************************************************\
|
||||
* eGroupWare - Country Codes *
|
||||
* http://www.egroupware.org *
|
||||
* Written by Mark Peters <skeeter@phpgroupware.org> *
|
||||
* -------------------------------------------- *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU General Public License as published by the *
|
||||
* Free Software Foundation; either version 2 of the License, or (at your *
|
||||
* option) any later version. *
|
||||
\**************************************************************************/
|
||||
|
||||
/* $Id$ */
|
||||
/* $Id$ */
|
||||
|
||||
/**
|
||||
/**
|
||||
* 2-digit ISO 3166 Country codes
|
||||
*
|
||||
* http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html
|
||||
*/
|
||||
class country
|
||||
{
|
||||
var $country_array;
|
||||
|
||||
function country()
|
||||
{
|
||||
$this->country_array = array(
|
||||
' ' => 'Select One',
|
||||
class country
|
||||
{
|
||||
/**
|
||||
* array with 2-letter iso-3166 country-code => country-name pairs
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $country_array = array(
|
||||
'AF' => 'AFGHANISTAN',
|
||||
'AL' => 'ALBANIA',
|
||||
'DZ' => 'ALGERIA',
|
||||
@ -265,27 +265,180 @@
|
||||
'ZM' => 'ZAMBIA',
|
||||
'ZW' => 'ZIMBABWE'
|
||||
);
|
||||
/**
|
||||
* translated list, set by country::_translate
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $countries_translated;
|
||||
/**
|
||||
* List of US states as 2-letter code => name pairs
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $us_states_array = array(
|
||||
'--' => 'non US',
|
||||
'AL' => 'Alabama',
|
||||
'AK' => 'Alaska',
|
||||
'AZ' => 'Arizona',
|
||||
'AR' => 'Arkansas',
|
||||
'CA' => 'California',
|
||||
'CO' => 'Colorado',
|
||||
'CT' => 'Connecticut',
|
||||
'DE' => 'Delaware',
|
||||
'DC' => 'District of Columbia',
|
||||
'FL' => 'Florida',
|
||||
'GA' => 'Georgia',
|
||||
'HI' => 'Hawaii',
|
||||
'ID' => 'Idaho',
|
||||
'IL' => 'Illinois',
|
||||
'IN' => 'Indiana',
|
||||
'IA' => 'Iowa',
|
||||
'KS' => 'Kansas',
|
||||
'KY' => 'Kentucky',
|
||||
'LA' => 'Louisiana',
|
||||
'ME' => 'Maine',
|
||||
'MD' => 'Maryland',
|
||||
'MA' => 'Massachusetts',
|
||||
'MI' => 'Michigan',
|
||||
'MN' => 'Minnesota',
|
||||
'MO' => 'Missouri',
|
||||
'MS' => 'Mississippi',
|
||||
'MT' => 'Montana',
|
||||
'NC' => 'North Carolina',
|
||||
'ND' => 'Noth Dakota',
|
||||
'NE' => 'Nebraska',
|
||||
'NH' => 'New Hampshire',
|
||||
'NJ' => 'New Jersey',
|
||||
'NM' => 'New Mexico',
|
||||
'NV' => 'Nevada',
|
||||
'NY' => 'New York',
|
||||
'OH' => 'Ohio',
|
||||
'OK' => 'Oklahoma',
|
||||
'OR' => 'Oregon',
|
||||
'PA' => 'Pennsylvania',
|
||||
'RI' => 'Rhode Island',
|
||||
'SC' => 'South Carolina',
|
||||
'SD' => 'South Dakota',
|
||||
'TN' => 'Tennessee',
|
||||
'TX' => 'Texas',
|
||||
'UT' => 'Utah',
|
||||
'VA' => 'Virginia',
|
||||
'VT' => 'Vermont',
|
||||
'WA' => 'Washington',
|
||||
'WI' => 'Wisconsin',
|
||||
'WV' => 'West Virginia',
|
||||
'WY' => 'Wyoming'
|
||||
);
|
||||
|
||||
/**
|
||||
* Get list of US states
|
||||
*
|
||||
* @return array with code => name pairs
|
||||
*/
|
||||
function us_states()
|
||||
{
|
||||
return $this->us_states_array;
|
||||
}
|
||||
|
||||
function form_select($selected,$name='')
|
||||
/**
|
||||
* Selectbox for country-selection
|
||||
*
|
||||
* @deprecated use html::select with country_array
|
||||
* @param string $selected 2-letter iso country-code
|
||||
* @param string $name='country'
|
||||
* @return string
|
||||
*/
|
||||
function form_select($code,$name='country')
|
||||
{
|
||||
if($name=='')
|
||||
if (!is_object($GLOBALS['egw']->html))
|
||||
{
|
||||
$name = 'country';
|
||||
$GLOBALS['egw']->html =& CreateObject('phpgwapi.html');
|
||||
}
|
||||
$str = '<select name="'.$name.'">'."\n";
|
||||
reset($this->country_array);
|
||||
while(list($key,$value) = each($this->country_array))
|
||||
{
|
||||
$str .= ' <option value="'.$key.'"'.($selected == $key?' selected':'').'>'.$value.'</option>'."\n";
|
||||
}
|
||||
$str .= '</select>'."\n";
|
||||
return $str;
|
||||
return $GLOBALS['egw']->html->select($name,strtoupper($code),$this->country_array);
|
||||
}
|
||||
|
||||
function get_full_name($selected)
|
||||
/**
|
||||
* Get country-name from the 2-letter iso code
|
||||
*
|
||||
* @param string $selected 2-letter iso country-code
|
||||
* @param boolean $translated=true use translated name or english
|
||||
* @return string
|
||||
*/
|
||||
function get_full_name($code,$translated=true)
|
||||
{
|
||||
return($this->country_array[$selected]);
|
||||
if ($translated)
|
||||
{
|
||||
if (!$this->countries_translated) $this->_translate_countries();
|
||||
|
||||
return $this->countries_translated[strtoupper($code)];
|
||||
}
|
||||
return $this->country_array[strtoupper($code)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 2-letter code for a given country name
|
||||
*
|
||||
* @param string $name
|
||||
* @return string 2-letter code or $name if no code found
|
||||
*/
|
||||
function country_code($name)
|
||||
{
|
||||
// search case-insensitive all translations for the english phrase of given country $name
|
||||
// we do that to catch all possible cases of translations
|
||||
if (($name_en = $GLOBALS['egw']->translation->get_message_id($name,'common')))
|
||||
{
|
||||
$name = strtoupper($name_en);
|
||||
}
|
||||
if (($code = array_search(strtoupper($name),$this->country_array)) !== false)
|
||||
{
|
||||
return $code;
|
||||
}
|
||||
if (!$this->countries_translated) $this->_translate_countries();
|
||||
|
||||
if (($code = array_search(strtoupper($name),$this->countries_translated)) !== false ||
|
||||
($code = array_search($name,$this->countries_translated)) !== false)
|
||||
{
|
||||
return $code;
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of country names
|
||||
*
|
||||
* @param boolean $translated=true use translated names or english
|
||||
* @return array with 2-letter code => name pairs
|
||||
*/
|
||||
function countries($translated=true)
|
||||
{
|
||||
if ($translated)
|
||||
{
|
||||
$this->_translate_countries();
|
||||
|
||||
return $this->countries_translated;
|
||||
}
|
||||
return $this->country_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill and sort the translated countries array
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
function _translate_countries()
|
||||
{
|
||||
if ($this->countries_translated) return;
|
||||
|
||||
$this->countries_translated = $this->country_array;
|
||||
// try to translate them and sort alphabetic
|
||||
foreach($this->countries_translated as $k => $name)
|
||||
{
|
||||
if (($translated = lang($name)) != $name.'*')
|
||||
{
|
||||
$this->countries_translated[$k] = $translated;
|
||||
}
|
||||
}
|
||||
?>
|
||||
asort($this->countries_translated);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user