1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
<?php
/**
* The Widgets class provides various functions used to generate and
* handle form input for Nag.
*
* $Horde: nag/lib/Widgets.php,v 1.2.12.7 2006/01/01 21:29:07 jan Exp $
*
* Copyright 2002-2006 Jon Parise <jon@horde.org>
* Copyright 2003-2006 Michael Slusarz <slusarz@bigworm.colorado.edu>
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
*
* @author Jon Parise <jon@horde.org>
* @author Michael Slusarz <slusarz@bigworm.colorado.edu>
* @package Nag
*/
class Widgets {
/**
* Generates the HTML for a day selection widget.
*
* @param string $name The name of the widget.
* @param integer $default The value to select by default. Range: 1-31
* @param string $params Any additional parameters to include in the <a>
* tag.
*
* @return string The HTML <select> widget.
*/
function buildDayWidget($name, $default = null, $params = null)
{
$html = '<select id="' . $name . '" name="' . $name. '"';
if (!is_null($params)) {
$html .= ' ' . $params;
}
$html .= '>';
for ($day = 1; $day <= 31; $day++) {
$html .= '<option value="' . $day . '"';
$html .= ($day == $default) ? ' selected="selected">' : '>';
$html .= $day . '</option>';
}
return $html . "</select>\n";
}
/**
* Generates the HTML for a month selection widget.
*
* @param string $name The name of the widget.
* @param integer $default The value to select by default.
* @param string $params Any additional parameters to include in the <a>
* tag.
*
* @return string The HTML <select> widget.
*/
function buildMonthWidget($name, $default = null, $params = null)
{
$html = '<select id="' . $name . '" name="' . $name. '"';
if (!is_null($params)) {
$html .= ' ' . $params;
}
$html .= '>';
for ($month = 1; $month <= 12; $month++) {
$html .= '<option value="' . $month . '"';
$html .= ($month == $default) ? ' selected="selected">' : '>';
$html .= strftime('%B', mktime(0, 0, 0, $month, 1)) . '</option>';
}
return $html . "</select>\n";
}
/**
* Generates the HTML for a year selection widget.
*
* @param integer $name The name of the widget.
* @param integer $years The number of years to include.
* If (+): future years
* If (-): past years
* @param string $default The timestamp to select by default.
* @param string $params Any additional parameters to include in the <a>
* tag.
*
* @return string The HTML <select> widget.
*/
function buildYearWidget($name, $years, $default = null, $params = null)
{
$curr_year = date('Y');
$yearlist = array();
$startyear = (!is_null($default) && ($default < $curr_year) && ($years > 0)) ? $default : $curr_year;
$startyear = min($startyear, $startyear + $years);
for ($i = 0; $i <= abs($years); $i++) {
$yearlist[] = $startyear++;
}
if ($years < 0) {
$yearlist = array_reverse($yearlist);
}
$html = '<select id="' . $name . '" name="' . $name. '"';
if (!is_null($params)) {
$html .= ' ' . $params;
}
$html .= '>';
foreach ($yearlist as $year) {
$html .= '<option value="' . $year . '"';
$html .= ($year == $default) ? ' selected="selected">' : '>';
$html .= $year . '</option>';
}
return $html . "</select>\n";
}
/**
* Generates the HTML for an hour selection widget.
*
* @param string $name The name of the widget.
* @param integer $default The timestamp to select by default.
* @param string $params Any additional parameters to include in the <a>
* tag.
*
* @return string The HTML <select> widget.
*/
function buildHourWidget($name, $default = null, $params = null)
{
global $prefs;
if (!$prefs->getValue('twentyFour')) {
$default = ($default + 24) % 12;
}
$html = '<select name="' . $name. '"';
if (!is_null($params)) {
$html .= ' ' . $params;
}
$html .= '>';
$min = $prefs->getValue('twentyFour') ? 0 : 1;
$max = $prefs->getValue('twentyFour') ? 23 : 12;
for ($hour = $min; $hour <= $max; $hour++) {
$html .= '<option value="' . $hour . '"';
$html .= ($hour == $default) ? ' selected="selected">' : '>';
$html .= $hour . '</option>';
}
return $html . '</select>';
}
function buildAmPmWidget($name, $default = 'am', $amParams = null, $pmParams = null)
{
global $prefs;
if ($prefs->getValue('twentyFour')) {
return;
}
if (is_numeric($default)) {
$default = date('a', mktime($default));
}
if ($default == 'am') {
$am = ' checked="checked"';
$pm = '';
} else {
$am = '';
$pm = ' checked="checked"';
}
$html = '<input id="' . $name . '_am" type="radio" name="' . $name . '" value="am"' . $am . (!empty($amParams) ? ' ' . $amParams : '') . ' /><label for="' . $name . '_am"' . (!empty($amParams) ? ' ' . $amParams : '') . '">AM</label> ';
$html .= '<input id="' . $name . '_pm" type="radio" name="' . $name . '" value="pm"' . $pm . (!empty($pmParams) ? ' ' . $pmParams : '') . ' /><label for="' . $name . '_pm"' . (!empty($pmParams) ? ' ' . $pmParams : '') . '">PM</label>';
return $html;
}
/**
* Generates the HTML for a minute selection widget.
*
* @param string $name The name of the widget.
* @param integer $increment The increment between minutes.
* @param integer $default The timestamp to select by default.
* @param string $params Any additional parameters to include in the
* <a> tag.
*
* @return string The HTML <select> widget.
*/
function buildMinuteWidget($name, $increment = 1, $default = null,
$params = null)
{
$html = '<select name="' . $name. '"';
if (!is_null($params)) {
$html .= ' ' . $params;
}
$html .= '>';
for ($minute = 0; $minute < 60; $minute += $increment) {
$html .= '<option value="' . $minute . '"';
$html .= ($minute == $default) ? ' selected="selected">' : '>';
$html .= sprintf("%02d", $minute) . '</option>';
}
return $html . "</select>\n";
}
}
|