• Publicity: Public Only All

ref-countries-procs.tcl

Country procs

Location:
packages/ref-countries/tcl/ref-countries-procs.tcl
Created:
2006-03-09
Author:
Malte Sussdorff <sussdorff@sussdorff.de>

Procedures in this file

Detailed information

ref_countries::get_country_code (public)

 ref_countries::get_country_code -country country

Gets the country code for a country

Switches:
-country (required)
Name of the country in English!

Partial Call Graph (max 5 caller/called nodes):
%3 test_get_country_code get_country_code (test ref-countries) ref_countries::get_country_code ref_countries::get_country_code test_get_country_code->ref_countries::get_country_code db_string db_string (public) ref_countries::get_country_code->db_string template::util::list_of_lists_to_array template::util::list_of_lists_to_array (public) ref_countries::get_country_code->template::util::list_of_lists_to_array

Testcases:
get_country_code
[ hide source ] | [ make this the default ]

Content File Source

ad_library {
    Country procs
    @author Malte Sussdorff (sussdorff@sussdorff.de)
    @creation-date 2006-03-09
}

namespace eval ref_countries {}

d_proc -public ref_countries::get_country_code {
    {-country:required}
} {
    Gets the country code for a country

    @param country Name of the country in English!
} {

    set country_code [db_string get_country_code "select iso from countries where default_name = upper(:country)" -default ""]

    if { $country_code eq "" } {

        # Lets try to be smart.
        set country_list [list \
                              [list England GB] \
                              [list "Great Britain" GB] \
                              [list Korea KR] \
                              [list Scotland GB] \
                              [list "South Korea" SK] \
                              [list "Taiwan, R.O.C." TW] \
                              [list "The Netherlands" NL] \
                              [list UK GB] \
                              [list USA US] \
                              [list "United States of America" US]]

        template::util::list_of_lists_to_array $country_list countries

        if {([info exists countries($country)] && $countries($country) ne "")} {
            set country_code $countries($country)
        }
    }

    return $country_code
}

# Local variables:
#    mode: tcl
#    tcl-indent-level: 4
#    indent-tabs-mode: nil
# End: