class ShowDates
{
/**
* show a SELECT element for days in a HTML form
*
* @param string $fieldName Name of the field
* @param string|integer $selectedDay OPTIONAL Set to the value of the
* day which should be selected
* @return string HTML code of the SELECT element
*/
public static function showDaySelect($fieldName, $selectedDay = null)
{
// [color=#FF0000]if the selected day isn't given set it to the actual day[/color] if ($selectedDay == null) $selectedDay = date("d");
// set the start HTML of the select form
$htmlSelectForm = '<select name="' . $fieldName . '">';
// do this 31 times, one for every day
for ($i = 01; $i <= 31; $i++) {
$day = (string) $i;
// convert this to a string with two numbers,
// e.g.: 04 instade of 4
if ($i < 10) {
$day = (string) "0" . $i;
}
// if the actual day is the same as the given day
// set this day as selected
$selected = '';
if ($i == $selectedDay) {
$selected .= 'selected="selected" ';
}
// add the option the the HTML select form
$htmlSelectForm .= '<option ' . $selected
. 'value="' . $day . '">' . $day;
}
// close the select form
$htmlSelectForm .= "</select>";
// returns the HTML of the select form
return $htmlSelectForm;
}