[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] phpgwapi/doc generate-class-country.php
From: |
Dave Hall |
Subject: |
[Phpgroupware-cvs] phpgwapi/doc generate-class-country.php |
Date: |
Wed, 27 Sep 2006 02:33:28 +0000 |
CVSROOT: /cvsroot/phpgwapi
Module name: phpgwapi
Changes by: Dave Hall <skwashd> 06/09/27 02:33:28
Added files:
doc : generate-class-country.php
Log message:
make it easier to maintain list of country codes in
class.country.inc.php
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/phpgwapi/doc/generate-class-country.php?cvsroot=phpgwapi&rev=1.1
Patches:
Index: generate-class-country.php
===================================================================
RCS file: generate-class-country.php
diff -N generate-class-country.php
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ generate-class-country.php 27 Sep 2006 02:33:28 -0000 1.1
@@ -0,0 +1,107 @@
+#!/usr/bin/php
+<?php
+ /**
+ * @ignore
+ */
+
+ /*
+ * Generate a new version of phpgwapi/inc/class.country.inc.php
+ *
+ * Usage:
+ * $ /path/to/phpgroupware/phpgwapi/doc/generate-class-country.php >
/path/to/phpgroupware/phpgwapi/inc/class.country.inc.php
+ */
+ echo"<?php\n";
+?>
+ /**
+ * Countries
+ * @author Mark Peters <address@hidden>
+ * @auhtor Dave Hall skwashd at phpGroupWare.org
+ * @copyright Portions Copyright (C) 2001 - 2006 Free Software
Foundation http://www.fsf.org/
+ * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
+ * @interal do not edit, edit and run
phpgwapi/doc/generate-class-country.php to regenerate this class
+ * @package phpgwapi
+ * @subpackage contacts
+ * @version $Id: generate-class-country.php,v 1.1 2006/09/27 02:33:28
skwashd Exp $
+ */
+
+ /**
+ * Countries
+ *
+ * @package phpgwapi
+ * @subpackage contacts
+ */
+ class country
+ {
+<?php
+ // Do not change this, it ensures we are using utf-8 :)
+ setlocale(LC_ALL, 'en_US.UTF-8');
+
+ $raw_file =
file_get_contents('http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1-semic.txt');
+ $cc_list = explode("\r\n", $raw_file);
+ if ( count($cc_list) < 3 )
+ {
+ echo "Invalid country code list, exiting\n";
+ exit;
+ }
+ unset($cc_list[0]);
+
+ echo "\n\t\t/**\n\t\t* @var array \$country_array list of ISO 3166
country codes\n\t\t*/\n\t\tvar \$country_array = array\n\t\t(\n\t\t\t' '\t=>
'Select One',\n";
+ sort($cc_list, SORT_LOCALE_STRING);
+ foreach ( $cc_list as $entry )
+ {
+ if ( !trim($entry) ) //ignore the empties
+ {
+ continue;
+ }
+
+ $country = explode(';', iconv('ISO-8859-1', 'UTF-8', $entry));
+ echo "\t\t\t'" . trim($country[1]) . "'\t=> '" .
addslashes(trim($country[0])) . "',\n";
+ }
+ echo "\t\t);\n\n";
+?>
+ /**
+ * @constructor
+ */
+ function country()
+ {
+ }
+
+ /**
+ * Create a select box filled with countries
+ *
+ * @param string $selected the currently selected country
+ * @param string $name the name of the select box element in the
form, used for both the id and name attributes
+ * @return string the html for a select box form element
+ */
+ function form_select($selected,$name='')
+ {
+ if($name=='')
+ {
+ $name = 'country';
+ }
+ $str = "<select name=\"$name\" id=\"$name\">\n";
+ reset($this->country_array);
+ while(list($key,$value) = each($this->country_array))
+ {
+ $str .= ' <option value="'.$key.'"'.($selected
== $key?' selected="selected"':'').'>'.$value.'</option>'."\n";
+ }
+ $str .= '</select>'."\n";
+ return $str;
+ }
+
+ /**
+ * Get the name of a country from the 2 letter iso 3166 country
code
+ *
+ * @param string $code the 2 letter iso 3166 code
+ * @return string the country name, empty string if invalid
+ */
+ function get_full_name($selected)
+ {
+ if ( isset($this->country_array[$selected]) )
+ {
+ return($this->country_array[$selected]);
+ }
+ return '';
+ }
+ }
+<?php echo '?>';?>
- [Phpgroupware-cvs] phpgwapi/doc generate-class-country.php,
Dave Hall <=