This calendar body code uses the header code I posted here on the forum. The code works fine except for one glitch. The starting day of the month always defaults to Wednesday. If I use the Previous/Next Month functions in the calendar header code to move forward or back, the day sets correctly. It's just when the calendar starts with no "Month" or "Year" URL parameters that it glitches.
Below is the body code. I would appreciate it if anyone could figure out why this code wants to use Wednesday as some sort of default and how I should fix it.
<?php
// This assumes the Calendar Header was written with the Calendar_Header()
// function in the library.php code library.
//First, get the information needed to choose what calendar to display
$Month=$_GET['Month'];
$Year=$_GET['Year'];
//If no month or year to get, set to current month and year...
$now=time();
if ($Month=="")
$Month=date("F",$now);
if ($Year=="")
$Year=date("F",$now);
//How many days in the month?
switch($Month)
{
case "January" :
$days="31";
break;
case "February" :
if ($Year%4=="0") $days="29";
else $days="28";
break;
case "March" :
$days="31";
break;
case "April" :
$days="30";
break;
case "May" :
$days="31";
break;
case "June" :
$days="30";
break;
case "July" :
$days="31";
break;
case "August" :
$days="31";
break;
case "September" :
$days="30";
break;
case "October" :
$days="31";
break;
case "November" :
$days="30";
break;
case "December" :
$days="31";
break;
}
//Next we determine what day of the week is the first day of the month
$day="Sunday";
$daynum=strtotime("$Month 1 $Year");
$day=date("l",$daynum);
//Assign positions to days of week and identify the starting day
switch($day)
{
case "Monday" :
$startpos="2";
break;
case "Tuesday" :
$startpos="3";
break;
case "Wednesday" :
$startpos="4";
break;
case "Thursday" :
$startpos="5";
break;
case "Friday" :
$startpos="6";
break;
case "Saturday" :
$startpos="7";
break;
case "Sunday" :
$startpos="1";
break;
}
//next we need to determine how many rows of seven columns we need
$basenum=$startpos+$days-1;
$rows=ceil($basenum/7);
//Next, we draw the calendar body
$rowcount="1";
$daycount="1";
$calendar_day=0;
while ($rowcount<=$rows)
{
echo "<tr>";
$day_column=1;
while ($day_column<=7)
{
echo "<td>";
if ($daycount<$startpos)
echo " ";
elseif (($daycount-$startpos+1)>$days)
echo " ";
else
{
$calendar_day=$calendar_day+1;
echo "$calendar_day";
}
$daycount=$daycount+1;
echo "</td>";
$day_column=$day_column+1;
}
echo "</tr>";
$rowcount=$rowcount+1;
}
//Finally, we finish the table
echo "</table>";
//echo test variables
echo "start position is $startpos<br/>";
echo "Month is $Month<br/>";
echo "Year is $Year<br/>";
echo "Starting Day is $day<br/>";
?>