6  * @subpackage PluginsFunction
 
  10  * Smarty {html_select_time} function plugin
 
  13  * Name:     html_select_time<br>
 
  14  * Purpose:  Prints the dropdowns for time selection
 
  16  * @link http://smarty.php.net/manual/en/language.function.html.select.time.php {html_select_time}
 
  17  *          (Smarty online manual)
 
  18  * @author Roberto Berto <roberto@berto.net> 
 
  19  * @credits Monte Ohrt <monte AT ohrt DOT com>
 
  20  * @param array $params parameters
 
  21  * @param object $template template object
 
  23  * @uses smarty_make_timestamp()
 
  25 function smarty_function_html_select_time($params, $template)
 
  27     require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
 
  28     require_once(SMARTY_PLUGINS_DIR . 'function.html_options.php');
 
  33     $display_hours = true;
 
  34     $display_minutes = true;
 
  35     $display_seconds = true;
 
  36     $display_meridian = true;
 
  40     /* Should the select boxes be part of an array when returned from PHP?
 
  41        e.g. setting it to "birthday", would create "birthday[Hour]",
 
  42        "birthday[Minute]", "birthday[Seconds]" & "birthday[Meridian]".
 
  43        Can be combined with prefix. */
 
  49     $meridian_extra = null;
 
  51     foreach ($params as $_key => $_value) {
 
  60             case 'meridian_extra':
 
  61                 $$_key = (string)$_value;
 
  65             case 'display_minutes':
 
  66             case 'display_seconds':
 
  67             case 'display_meridian':
 
  69                 $$_key = (bool)$_value;
 
  72             case 'minute_interval':
 
  73             case 'second_interval':
 
  74                 $$_key = (int)$_value;
 
  78                 trigger_error("[html_select_time] unknown parameter $_key", E_USER_WARNING);
 
  82     $time = smarty_make_timestamp($time);
 
  87         $hours = $use_24_hours ? range(0, 23) : range(1, 12);
 
  88         $hour_fmt = $use_24_hours ? '%H' : '%I';
 
  89         for ($i = 0, $for_max = count($hours); $i < $for_max; $i++)
 
  90         $hours[$i] = sprintf('%02d', $hours[$i]);
 
  91         $html_result .= '<select name=';
 
  92         if (null !== $field_array) {
 
  93             $html_result .= '"' . $field_array . '[' . $prefix . 'Hour]"';
 
  95             $html_result .= '"' . $prefix . 'Hour"';
 
  97         if (null !== $hour_extra) {
 
  98             $html_result .= ' ' . $hour_extra;
 
 100         if (null !== $all_extra) {
 
 101             $html_result .= ' ' . $all_extra;
 
 103         $html_result .= '>' . "\n";
 
 104         $html_result .= smarty_function_html_options(array('output' => $hours,
 
 106                 'selected' => strftime($hour_fmt, $time),
 
 107                 'print_result' => false),
 
 109         $html_result .= "</select>\n";
 
 112     if ($display_minutes) {
 
 113         $all_minutes = range(0, 59);
 
 114         for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i += $minute_interval)
 
 115         $minutes[] = sprintf('%02d', $all_minutes[$i]);
 
 116         $selected = intval(floor(strftime('%M', $time) / $minute_interval) * $minute_interval);
 
 117         $html_result .= '<select name=';
 
 118         if (null !== $field_array) {
 
 119             $html_result .= '"' . $field_array . '[' . $prefix . 'Minute]"';
 
 121             $html_result .= '"' . $prefix . 'Minute"';
 
 123         if (null !== $minute_extra) {
 
 124             $html_result .= ' ' . $minute_extra;
 
 126         if (null !== $all_extra) {
 
 127             $html_result .= ' ' . $all_extra;
 
 129         $html_result .= '>' . "\n";
 
 131         $html_result .= smarty_function_html_options(array('output' => $minutes,
 
 132                 'values' => $minutes,
 
 133                 'selected' => $selected,
 
 134                 'print_result' => false),
 
 136         $html_result .= "</select>\n";
 
 139     if ($display_seconds) {
 
 140         $all_seconds = range(0, 59);
 
 141         for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i += $second_interval)
 
 142         $seconds[] = sprintf('%02d', $all_seconds[$i]);
 
 143         $selected = intval(floor(strftime('%S', $time) / $second_interval) * $second_interval);
 
 144         $html_result .= '<select name=';
 
 145         if (null !== $field_array) {
 
 146             $html_result .= '"' . $field_array . '[' . $prefix . 'Second]"';
 
 148             $html_result .= '"' . $prefix . 'Second"';
 
 151         if (null !== $second_extra) {
 
 152             $html_result .= ' ' . $second_extra;
 
 154         if (null !== $all_extra) {
 
 155             $html_result .= ' ' . $all_extra;
 
 157         $html_result .= '>' . "\n";
 
 159         $html_result .= smarty_function_html_options(array('output' => $seconds,
 
 160                 'values' => $seconds,
 
 161                 'selected' => $selected,
 
 162                 'print_result' => false),
 
 164         $html_result .= "</select>\n";
 
 167     if ($display_meridian && !$use_24_hours) {
 
 168         $html_result .= '<select name=';
 
 169         if (null !== $field_array) {
 
 170             $html_result .= '"' . $field_array . '[' . $prefix . 'Meridian]"';
 
 172             $html_result .= '"' . $prefix . 'Meridian"';
 
 175         if (null !== $meridian_extra) {
 
 176             $html_result .= ' ' . $meridian_extra;
 
 178         if (null !== $all_extra) {
 
 179             $html_result .= ' ' . $all_extra;
 
 181         $html_result .= '>' . "\n";
 
 183         $html_result .= smarty_function_html_options(array('output' => array('AM', 'PM'),
 
 184                 'values' => array('am', 'pm'),
 
 185                 'selected' => strtolower(strftime('%p', $time)),
 
 186                 'print_result' => false),
 
 188         $html_result .= "</select>\n";