game/onyx2/modules/templates/smarty/plugins/function.html_select_time.php

198 lines
6.4 KiB
PHP
Raw Normal View History

2009-11-01 11:00:00 +00:00
<?php
/**
2020-11-15 15:12:32 +00:00
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsFunction
*/
2009-11-01 11:00:00 +00:00
/**
2020-11-15 15:12:32 +00:00
* Smarty {html_select_time} function plugin
*
* Type: function<br>
* Name: html_select_time<br>
* Purpose: Prints the dropdowns for time selection
*
* @link http://smarty.php.net/manual/en/language.function.html.select.time.php {html_select_time}
(Smarty online manual)
* @author Roberto Berto <roberto@berto.net>
* @credits Monte Ohrt <monte AT ohrt DOT com>
* @param array $params parameters
* @param object $smarty Smarty object
* @param object $template template object
* @return string
* @uses smarty_make_timestamp()
*/
function smarty_function_html_select_time($params, $smarty, $template)
2009-11-01 11:00:00 +00:00
{
2020-11-15 15:12:32 +00:00
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
require_once(SMARTY_PLUGINS_DIR . 'function.html_options.php');
//$smarty->loadPlugin('Smarty_shared_make_timestamp');
//$smarty->loadPlugin('Smarty_function_html_options');
2009-11-01 11:00:00 +00:00
/* Default values. */
2020-11-15 15:12:32 +00:00
$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;
2009-11-01 11:00:00 +00:00
/* 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. */
2020-11-15 15:12:32 +00:00
$field_array = null;
$all_extra = null;
$hour_extra = null;
$minute_extra = null;
$second_extra = null;
$meridian_extra = null;
foreach ($params as $_key => $_value) {
2009-11-01 11:00:00 +00:00
switch ($_key) {
case 'prefix':
case 'time':
case 'field_array':
case 'all_extra':
case 'hour_extra':
case 'minute_extra':
case 'second_extra':
case 'meridian_extra':
$$_key = (string)$_value;
break;
case 'display_hours':
case 'display_minutes':
case 'display_seconds':
case 'display_meridian':
case 'use_24_hours':
$$_key = (bool)$_value;
break;
case 'minute_interval':
case 'second_interval':
$$_key = (int)$_value;
break;
default:
2020-11-15 15:12:32 +00:00
throw new Exception ("[html_select_time] unknown parameter $_key", E_USER_WARNING);
}
}
2009-11-01 11:00:00 +00:00
$time = smarty_make_timestamp($time);
$html_result = '';
if ($display_hours) {
2020-11-15 15:12:32 +00:00
$hours = $use_24_hours ? range(0, 23) : range(1, 12);
2009-11-01 11:00:00 +00:00
$hour_fmt = $use_24_hours ? '%H' : '%I';
for ($i = 0, $for_max = count($hours); $i < $for_max; $i++)
2020-11-15 15:12:32 +00:00
$hours[$i] = sprintf('%02d', $hours[$i]);
2009-11-01 11:00:00 +00:00
$html_result .= '<select name=';
if (null !== $field_array) {
$html_result .= '"' . $field_array . '[' . $prefix . 'Hour]"';
} else {
$html_result .= '"' . $prefix . 'Hour"';
2020-11-15 15:12:32 +00:00
}
if (null !== $hour_extra) {
2009-11-01 11:00:00 +00:00
$html_result .= ' ' . $hour_extra;
2020-11-15 15:12:32 +00:00
}
if (null !== $all_extra) {
2009-11-01 11:00:00 +00:00
$html_result .= ' ' . $all_extra;
2020-11-15 15:12:32 +00:00
}
$html_result .= '>' . "\n";
$html_result .= smarty_function_html_options(array('output' => $hours,
'values' => $hours,
'selected' => strftime($hour_fmt, $time),
'print_result' => false),
$smarty, $template);
2009-11-01 11:00:00 +00:00
$html_result .= "</select>\n";
2020-11-15 15:12:32 +00:00
}
2009-11-01 11:00:00 +00:00
if ($display_minutes) {
$all_minutes = range(0, 59);
2020-11-15 15:12:32 +00:00
for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i += $minute_interval)
$minutes[] = sprintf('%02d', $all_minutes[$i]);
2009-11-01 11:00:00 +00:00
$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"';
2020-11-15 15:12:32 +00:00
}
if (null !== $minute_extra) {
2009-11-01 11:00:00 +00:00
$html_result .= ' ' . $minute_extra;
2020-11-15 15:12:32 +00:00
}
if (null !== $all_extra) {
2009-11-01 11:00:00 +00:00
$html_result .= ' ' . $all_extra;
2020-11-15 15:12:32 +00:00
}
$html_result .= '>' . "\n";
$html_result .= smarty_function_html_options(array('output' => $minutes,
'values' => $minutes,
'selected' => $selected,
'print_result' => false),
$smarty, $template);
2009-11-01 11:00:00 +00:00
$html_result .= "</select>\n";
2020-11-15 15:12:32 +00:00
}
2009-11-01 11:00:00 +00:00
if ($display_seconds) {
$all_seconds = range(0, 59);
2020-11-15 15:12:32 +00:00
for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i += $second_interval)
$seconds[] = sprintf('%02d', $all_seconds[$i]);
2009-11-01 11:00:00 +00:00
$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"';
2020-11-15 15:12:32 +00:00
}
if (null !== $second_extra) {
2009-11-01 11:00:00 +00:00
$html_result .= ' ' . $second_extra;
2020-11-15 15:12:32 +00:00
}
if (null !== $all_extra) {
2009-11-01 11:00:00 +00:00
$html_result .= ' ' . $all_extra;
2020-11-15 15:12:32 +00:00
}
$html_result .= '>' . "\n";
$html_result .= smarty_function_html_options(array('output' => $seconds,
'values' => $seconds,
'selected' => $selected,
'print_result' => false),
$smarty, $template);
2009-11-01 11:00:00 +00:00
$html_result .= "</select>\n";
2020-11-15 15:12:32 +00:00
}
2009-11-01 11:00:00 +00:00
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"';
2020-11-15 15:12:32 +00:00
}
if (null !== $meridian_extra) {
2009-11-01 11:00:00 +00:00
$html_result .= ' ' . $meridian_extra;
2020-11-15 15:12:32 +00:00
}
if (null !== $all_extra) {
2009-11-01 11:00:00 +00:00
$html_result .= ' ' . $all_extra;
2020-11-15 15:12:32 +00:00
}
$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, $template);
2009-11-01 11:00:00 +00:00
$html_result .= "</select>\n";
2020-11-15 15:12:32 +00:00
}
2009-11-01 11:00:00 +00:00
return $html_result;
2020-11-15 15:12:32 +00:00
}
2009-11-01 11:00:00 +00:00
?>