/**
 * Render select box for USA States
 * 
 * Parameters:
 * 
 * - all HTML attributes
 * - value - value of selected company
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_select_usa_state($params, &$smarty)
{
    $value = null;
    if (isset($params['value'])) {
        $value = (int) array_var($params, 'value');
        unset($params['value']);
    }
    // if
    $states = get_usa_states();
    $options = array();
    foreach ($states as $code => $state) {
        $option_attributes = $value == $code ? array('selected' => true) : null;
        $options[] = option_tag($state, $code, $option_attributes);
    }
    // if
    return select_box($options, $params);
}
Esempio n. 2
0
/**
 * Return name of state based on its code
 *
 * @param string $code
 * @return string
 */
function get_state_name($code)
{
    $code = strtoupper($code);
    $states = array_merge(get_usa_states(), get_canada_states());
    return isset($states[$code]) ? $states[$code] : $code;
}