[eluser]xwero[/eluser]
It's a nasty looking hack because you hard coded your options
Code:
function timezone_menu($default = 'UTC', $class = "", $name = 'timezones',$limittz = '')
{
$CI =& get_instance();
$CI->lang->load('date');
if ($default == 'GMT')
$default = 'UTC';
$menu = '<select name="'.$name.'"';
if ($class != '')
{
$menu .= ' class="'.$class.'"';
}
$menu .= ">\n";
$timezones = (is_array($limittz)?timezones($limittz):timezones();
foreach ($timezones as $key => $val)
{
$selected = ($default == $key) ? " selected='selected'" : '';
$menu .= "<option value='{$key}'{$selected}>".$CI->lang->line($key)."</option>\n";
}
$menu .= "</select>";
return $menu;
}
// ------------------------------------------------------------------------
/**
* Timezones
*
* Returns an array of timezones. This is a helper function
* for various other ones in this library
*
* @access public
* @param string timezone
* @return string
*/
function timezones($tz = '')
{
// Note: Don't change the order of these even though
// some items appear to be in the wrong order
$zones = array(
'UM12' => -12,
'UM11' => -11,
'UM10' => -10,
'UM9' => -9,
'UM8' => -8,
'UM7' => -7,
'UM6' => -6,
'UM5' => -5,
'UM4' => -4,
'UM25' => -2.5,
'UM3' => -3,
'UM2' => -2,
'UM1' => -1,
'UTC' => 0,
'UP1' => +1,
'UP2' => +2,
'UP3' => +3,
'UP25' => +2.5,
'UP4' => +4,
'UP35' => +3.5,
'UP5' => +5,
'UP45' => +4.5,
'UP6' => +6,
'UP7' => +7,
'UP8' => +8,
'UP9' => +9,
'UP85' => +8.5,
'UP10' => +10,
'UP11' => +11,
'UP12' => +12
);
if ($tz == '' && !is_array($tz))
{
return $zones;
}
if(is_array($tz))
{
$return = array();
foreach($tz as $t)
{
if(isset($zones[$t])){ $return[$t] = $zones[$t]; }
}
return $return;
}
if($tz != '')
{
if ($tz == 'GMT'){ $tz = 'UTC'; }
return ( ! isset($zones[$tz])) ? 0 : $zones[$tz];
}
}
Now you have two enchantments instead of one
- limit the timezones of the timezone menu
- get a limited, the full timezones array or just one timezone from the timezones function