Sources for file plugins/smarty/function.html_select_time.php in version 2.0 Beta 4



Click on a comment to hide it. Click here to show all comments.

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     function
 * Name:     html_select_time
 * Purpose:  Prints the dropdowns for time selection
 * -------------------------------------------------------------
 */
require_once $this->_get_plugin_filepath('shared','make_timestamp');
require_once 
$this->_get_plugin_filepath('function','html_options');
function 
smarty_function_html_select_time($params, &$smarty)
{
    
/* Default values. */
    
$prefix             "Time_";
    
$time               time();
    
$display_hours      true;
    
$display_minutes    true;
    
$display_seconds    true;
    
$display_meridian   true;
    
$use_24_hours       true;
    
$minute_interval    1;
    
$second_interval    1;
    
/* Should the select boxes be part of an array when returned from PHP?
       e.g. setting it to "birthday", would create "birthday[Hour]",
       "birthday[Minute]", "birthday[Seconds]" & "birthday[Meridian]".
       Can be combined with prefix. */
    
$field_array        null;
    
$post_array        null;
    
$all_extra          null;
    
$hour_extra         null;
    
$minute_extra       null;
    
$second_extra       null;
    
$meridian_extra     null;

    
extract($params);

    
$time smarty_make_timestamp($time);

    
$html_result '';

    if (
$display_hours) {
        
$hours       $use_24_hours range(023) : range(112);
        
$hour_fmt $use_24_hours '%H' '%I';
        for (
$i 0$for_max count($hours); $i $for_max$i++)
            
$hours[$i] = sprintf('%02d'$hours[$i]);
        
$html_result .= '<select name=';
        if (
null !== $field_array) {
            
$html_result .= '"' $field_array '[' $prefix 'hour]';
        } else {
            
$html_result .= '"' $prefix 'hour';
        }
    if (
null !== $post_array){
            
$html_result .= '[' $post_array .']';
    }
    
$html_result .= '"';
        if (
null !== $hour_extra){
            
$html_result .= ' ' $hour_extra;
        }
        if (
null !== $all_extra){
            
$html_result .= ' ' $all_extra;
        }
        
$html_result .= '>'."\n";
        
$html_result .= smarty_function_html_options(array('output'          => $hours,
                                                           
'values'          => $hours,
                                                           
'selected'      => strftime($hour_fmt,
$time),
                                                           
'print_result' => false),
                                                     
$smarty);
        
$html_result .= "</select>\n";
    }

    if (
$display_minutes) {
        
$all_minutes range(059);
        for (
$i 0$for_max count($all_minutes); $i $for_max$i+= $minute_interval)
            
$minutes[] = sprintf('%02d'$all_minutes[$i]);
        
$selected intval(floor(strftime('%M'$time) / $minute_interval) * $minute_interval);
        
$html_result .= '<select name=';
        if (
null !== $field_array) {
            
$html_result .= '"' $field_array '[' $prefix 'minute]';
        } else {
            
$html_result .= '"' $prefix 'minute';
        }
    if (
null !== $post_array){
            
$html_result .= '[' $post_array .']';
    }
    
$html_result .= '"';
        if (
null !== $minute_extra){
            
$html_result .= ' ' $minute_extra;
        }
        if (
null !== $all_extra){
            
$html_result .= ' ' $all_extra;
        }
        
$html_result .= '>'."\n";
        
        
$html_result .= smarty_function_html_options(array('output'          => $minutes,
                                                           
'values'          => $minutes,
                                                           
'selected'      => $selected,
                                                           
'print_result' => false),
                                                     
$smarty);
        
$html_result .= "</select>\n";
    }

    if (
$display_seconds) {
        
$all_seconds range(059);
        for (
$i 0$for_max count($all_seconds); $i $for_max$i+= $second_interval)
            
$seconds[] = sprintf('%02d'$all_seconds[$i]);
        
$selected intval(floor(strftime('%S'$time) / $second_interval) * $second_interval);
        
$html_result .= '<select name=';
        if (
null !== $field_array) {
            
$html_result .= '"' $field_array '[' $prefix 'second]';
        } else {
            
$html_result .= '"' $prefix 'second';
        }
    if (
null !== $post_array){
            
$html_result .= '[' $post_array .']';
    }        
    
$html_result .= '"';
        if (
null !== $second_extra){
            
$html_result .= ' ' $second_extra;
        }
        if (
null !== $all_extra){
            
$html_result .= ' ' $all_extra;
        }
        
$html_result .= '>'."\n";
        
        
$html_result .= smarty_function_html_options(array('output'          => $seconds,
                                                           
'values'          => $seconds,
                                                           
'selected'      => $selected,
                                                           
'print_result' => false),
                                                     
$smarty);
        
$html_result .= "</select>\n";
    }

    if (
$display_meridian && !$use_24_hours) {
        
$html_result .= '<select name=';
        if (
null !== $field_array) {
            
$html_result .= '"' $field_array '[' $prefix 'meridian]';
        } else {
            
$html_result .= '"' $prefix 'meridian';
        }
    if (
null !== $post_array){
            
$html_result .= '[]';
    }
    
$html_result .= '"';
        if (
null !== $meridian_extra){
            
$html_result .= '[' $post_array .']';
        }
        if (
null !== $all_extra){
            
$html_result .= ' ' $all_extra;
        }
        
$html_result .= '>'."\n";
        
        
$html_result .= smarty_function_html_options(array('output'          => array('AM''PM'),
                                                           
'values'          => array('am''pm'),
                                                           
'selected'      =>
strtolower(strftime('%p'$time)),
                                                           
'print_result' => false),
                                                     
$smarty);
        
$html_result .= "</select>\n";
    }

    print 
$html_result;
}

/* vim: set expandtab: */

?>


Website is Copyright © Odynia.org 2000-2005 - Xnyo is released under a BSD license.