|
function short_monthname($month)
{
$months = array("Jan", "Feb", "Mar", "Apr", "May",
"Jun", "Jul", "Aug", "Sep", "Oct",
"Nov", "Dec");
return($months[$month - 1]);
}
function long_monthname($month)
{
$months = array("January", "February", "March", "April", "May",
"June", "July", "August", "September", "October",
"November", "December");
return($months[$month - 1]);
}
function first_of_next_month($fdate)
{
$year = (int) substr($fdate, 0, 4);
$month = (int) substr($fdate, 5, 2);
$month++;
if ($month > 12) {
$month = 1;
$year++;
}
$sdate = sprintf("%4d-%02d-%02d", $year, $month, 1);
return($sdate);
}
function last_of_month($fdate)
{
$thisyear = (int) substr($fdate, 0, 4);
$thismonth = (int) substr($fdate, 5, 2);
$thisday = 31;
while(!checkdate($thismonth, $thisday, $thisyear)) {
$thisday--;
}
$monthend = sprintf("%4d-%02d-%02d", $thisyear, $thismonth, $thisday);
return($monthend);
}
function first_of_month($fdate)
{
$thisyear = substr($fdate, 0, 4);
$thismonth = substr($fdate, 5, 2);
$thisday = substr($fdate, 8, 2);
$thismonthstart = $thisyear . "-" . $thismonth . "-01";
return($thismonthstart);
}
function display_cal_month($fdate, $ongoing)
{
$thisyear = substr($fdate, 0, 4);
$thismonth = substr($fdate, 5, 2);
$thisday = substr($fdate, 8, 2);
$thismonthstart = first_of_month($fdate);
$thismonthend = last_of_month($fdate);
$menddate = $thisyear . "-" . $thismonth . "31";
$month = (int) $thismonth;
$sql = "SELECT title, startdate, enddate, description, url, contact, phone, email, seq from calendar
WHERE
( startdate >= \"$fdate\" AND startdate <= '$menddate' AND enddate = '0000-00-00')
OR
(enddate != '0000-00-00' AND enddate >= '$thismonthstart' AND enddate <= '$thismonthend')
OR
(enddate != '0000-00-00' AND startdate >= '$thismonthstart' AND startdate <= '$thismonthend')
";
# ( enddate >= '$fdate' AND startdate >= '$thismonthstart')
# want to say: startdate within month, or enddate within month.
if ($ongoing) {
$sql .= " OR startdate = '0000-00-00'";
}
$sql .= " ORDER BY startdate, title";
$result = mysql_query($sql);
if (!$result) {
printf("%s ", mysql_error());
return;
}
?>
| |