Smarty
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file function.html_select_time.php

Documentation is available at function.html_select_time.php

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7.  
  8.  
  9. /**
  10.  * Smarty {html_select_time} function plugin
  11.  *
  12.  * Type:     function<br>
  13.  * Name:     html_select_time<br>
  14.  * Purpose:  Prints the dropdowns for time selection
  15.  * @link http://smarty.php.net/manual/en/language.function.html.select.time.php {html_select_time}
  16.  *           (Smarty online manual)
  17.  * @param array 
  18.  * @param Smarty 
  19.  * @return string 
  20.  */
  21. function smarty_function_html_select_time($params&$gBitSmarty)
  22. {
  23.     global $gBitSystem;
  24.     $gBitSmarty->loadPlugin'smarty_shared_make_timestamp' );
  25.     $gBitSmarty->loadPlugin'smarty_function_html_options' );
  26.     /* Default values. */
  27.     $prefix             "Time_";
  28.     $time               time();
  29.     $display_hours      true;
  30.     $display_minutes    true;
  31.     $display_seconds    true;
  32.     $display_meridian   true;
  33.     $use_24_hours       true;
  34.     $minute_interval    1;
  35.     $second_interval    1;
  36.     /* Should the select boxes be part of an array when returned from PHP?
  37.        e.g. setting it to "birthday", would create "birthday[Hour]",
  38.        "birthday[Minute]", "birthday[Seconds]" & "birthday[Meridian]".
  39.        Can be combined with prefix. */
  40.     $field_array        null;
  41.     $all_extra          null;
  42.     $hour_extra         null;
  43.     $minute_extra       null;
  44.     $second_extra       null;
  45.     $meridian_extra     null;
  46.  
  47.     extract($params);
  48.  
  49.     $date new BitDate(0);
  50.     // sets the offset for the user - necessary because BitDate is a bitwack
  51.     $offset $date->get_display_offset();
  52.     $disptime $date->getDisplayDateFromUTC$time );
  53.     $html_result '';
  54.  
  55.     if ($display_hours{
  56.         $hours       $use_24_hours range(023range(112);
  57.         $hour_fmt $use_24_hours '%H' '%I';
  58.     $selected $gBitSystem->mServerTimestamp->strftime($hour_fmt$disptimeTRUE);
  59.         for ($i 0$for_max count($hours)$i $for_max$i++)
  60.             $hours[$isprintf('%02d'$hours[$i]);
  61.         $html_result .= '<select name=';
  62.         if (null !== $field_array{
  63.             $html_result .= '"' $field_array '[' $prefix 'Hour]"';
  64.         else {
  65.             $html_result .= '"' $prefix 'Hour"';
  66.         }
  67.         if (null !== $hour_extra){
  68.             $html_result .= ' ' $hour_extra;
  69.         }
  70.         if (null !== $all_extra){
  71.             $html_result .= ' ' $all_extra;
  72.         }
  73.         $html_result .= '>'."\n";
  74.         $html_result .= smarty_function_html_options(array('output'          => $hours,
  75.                                                            'values'          => $hours,
  76.                                                            'selected'      => $selected,
  77.                                                            'print_result' => false),
  78.                                                      $gBitSmarty);
  79.         $html_result .= "</select>\n";
  80.     }
  81.  
  82.     if ($display_minutes{
  83.         $all_minutes range(059);
  84.         for ($i 0$for_max count($all_minutes)$i $for_max$i+= $minute_interval)
  85.             $minutes[sprintf('%02d'$all_minutes[$i]);
  86.         $selected intval(floor($gBitSystem->mServerTimestamp->strftime('%M'$disptimeTRUE$minute_interval$minute_interval);
  87.         $html_result .= '<select name=';
  88.         if (null !== $field_array{
  89.             $html_result .= '"' $field_array '[' $prefix 'Minute]"';
  90.         else {
  91.             $html_result .= '"' $prefix 'Minute"';
  92.         }
  93.         if (null !== $minute_extra){
  94.             $html_result .= ' ' $minute_extra;
  95.         }
  96.         if (null !== $all_extra){
  97.             $html_result .= ' ' $all_extra;
  98.         }
  99.         $html_result .= '>'."\n";
  100.  
  101.         $html_result .= smarty_function_html_options(array('output'          => $minutes,
  102.                                                            'values'          => $minutes,
  103.                                                            'selected'      => $selected,
  104.                                                            'print_result' => false),
  105.                                                      $gBitSmarty);
  106.         $html_result .= "</select>\n";
  107.     }
  108.  
  109.     if ($display_seconds{
  110.         $all_seconds range(059);
  111.         for ($i 0$for_max count($all_seconds)$i $for_max$i+= $second_interval)
  112.             $seconds[sprintf('%02d'$all_seconds[$i]);
  113.         $selected intval(floor($gBitSystem->mServerTimestamp->strftime('%S'$disptimeTRUE$second_interval$second_interval);
  114.         $html_result .= '<select name=';
  115.         if (null !== $field_array{
  116.             $html_result .= '"' $field_array '[' $prefix 'Second]"';
  117.         else {
  118.             $html_result .= '"' $prefix 'Second"';
  119.         }
  120.  
  121.         if (null !== $second_extra){
  122.             $html_result .= ' ' $second_extra;
  123.         }
  124.         if (null !== $all_extra){
  125.             $html_result .= ' ' $all_extra;
  126.         }
  127.         $html_result .= '>'."\n";
  128.  
  129.         $html_result .= smarty_function_html_options(array('output'          => $seconds,
  130.                                                            'values'          => $seconds,
  131.                                                            'selected'      => $selected,
  132.                                                            'print_result' => false),
  133.                                                      $gBitSmarty);
  134.         $html_result .= "</select>\n";
  135.     }
  136.  
  137.     if ($display_meridian && !$use_24_hours{
  138.         $html_result .= '<select name=';
  139.     $selected strtolower($gBitSystem->mServerTimestamp->strftime('%p'$disptimeTRUE));
  140.         if (null !== $field_array{
  141.             $html_result .= '"' $field_array '[' $prefix 'Meridian]"';
  142.         else {
  143.             $html_result .= '"' $prefix 'Meridian"';
  144.         }
  145.  
  146.         if (null !== $meridian_extra){
  147.             $html_result .= ' ' $meridian_extra;
  148.         }
  149.         if (null !== $all_extra){
  150.             $html_result .= ' ' $all_extra;
  151.         }
  152.         $html_result .= '>'."\n";
  153.  
  154.         $html_result .= smarty_function_html_options(array('output'          => array('AM''PM'),
  155.                                                            'values'          => array('am''pm'),
  156.                                                            'selected'      => $selected,
  157.                                                            'print_result' => false),
  158.                                                      $gBitSmarty);
  159.         $html_result .= "</select>\n";
  160.     }
  161.  
  162.     // date: 2003/02/12 21:23:52;  author: gilshwartz;  state: Exp;  lines: +1 -1
  163.     // Enforce LTR direction of time entry regardless of overall directionality.
  164.     // -    print $html_result;
  165.     // +    print '<span dir="ltr">'.$html_result.'</span>';
  166.  
  167.     $html_result '<span dir="ltr">' $html_result '</span>';
  168.  
  169.     return $html_result;
  170. }
  171.  
  172. /* vim: set expandtab: */
  173.  
  174. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:38 +0000 by phpDocumentor 1.5.0-lsces