$output = "";
//Pulls the $month and $year out of $_GET.
$month = $_GET['month'];
$year = $_GET['year'];
//$row is used to calculate how many rows have been generated in the calendar
//If $row ends up being less than 6, the program will add rows until there are 6.
$row = 0;
//If $month and $year are null, the current month and year are saved into the variables using time()
if($month == '' && $year == '')
{
$time = time();
$month = date('n',$time);
$year = date('Y',$time);
} //end if
//The date submitted to the page and today's date are put into $date and $today.
$date = getdate(mktime(0,0,0,$month,1,$year));
$today = getdate();
//The time is divided up into variables.
$hours = $today['hours'];
$mins = $today['minutes'];
$secs = $today['seconds'];
//If the hours, minutes or seconds don't have two digits (i.e. less than 10), a 0 is inserted
//into the string before the value.
if(strlen($hours)<2)
$hours="0".$hours;
if(strlen($mins)<2)
$mins="0".$mins;
if(strlen($secs)<2)
$secs="0".$secs;
//Calculates the number of days in $month
$days=date("t",mktime(0,0,0,$month,1,$year));
//plugs the day of the week $month starts on and adds 1 to it (making Sunday = 1, and Saturday = 7)
$start = $date['wday']+1;
//Plugs the name of the month into $name
$name = $date['month'];
//Plugs the year into $year2
$year2 = $date['year'];
//Calculates the max number of squares needed to fit all the days, including the empty squares
//before the start of the month.
$offset = $days + $start - 1;
//When advancing to the next month, if $month is 12 (December),
//$month is set to 1(January), and $year is incrimented by 1.
//Otherwise $month is incrimented by 1 and $year stays the same.
if($month==12)
{
$nextm=1;
$nexty=$year + 1;
} //end if
else
{
$nextm=$month + 1;
$nexty=$year;
} //end else
//When recessing to the previous month, if $month is 1 (January),
//$month is set to 12 (December) and $year is decrimented by 1.
//Otherwise $month is decremented by 1 and $year stays the same.
if($month==1)
{
$prevm=12;
$prevy=$year - 1;
} //end if
else
{
$prevm=$month - 1;
$prevy=$year;
} //end else
//Calculates how many rows/squares will be displayed based on $offset.
if($offset <= 28)
$weeks=28;
elseif($offset > 35)
$weeks = 42;
else
$weeks = 35;
$output .= "
|
|
| Su |
M |
Tu |
W |
Th |
F |
Sa |
";
$col=1; //Sets the "pointer" at the first column.
$cur=1; //Sets the number being inserted into a square.
$next=0; //????????????????????????????????????
//For loop that goes through each of the 28, 35, or 42 squares to be in the calendar.
for($i=1;$i<=$weeks;$i++)
{
if($next==3)
$next=0;
if($col==1)
$output.="";
//if $i less than (the number of days in the month + the day of the week the month starts on less 1),
//AND it's greater than or equal the day of the week the month starts on, it inserts a number
//into the square. Otherwise it inserts a space into the square.
if($i <= ($days+($start-1)) && $i >= $start)
{
//If the current number being inserted into the square is the same as the same as the day of the month
//and the name of the month in $name is the same as the name of the current month, that particular
//square is highlighted differently to indicate "today".
if(($cur==$today[mday]) && ($name==$today[month]))
$output .= " | ";
else
$output .= " | ";
$output .= $cur . " | ";
$cur++; //Incriments the current day in the calendar being inserted.
$col++; //Incriments the column currently being used.
} //end if
else
{
$output .= " | ";
$col++; //Incriments the column currently being used.
} //end else
//If $col has reached 8, that means 7 days have been inserted and the pointer needs to be set to 1.
if($col==8)
{
$output .= "
";
$col=1;
$row++;
} //end if
} //end for
while($row <6)
{
$output .= " ";
$output .= " | | ";
$output .= " | ";
$output .= " | ";
$output .= " | ";
$output .= " | ";
$output .= " | ";
$output .= " | ";
$output .= "
";
$row++;
}
$output .= "
|
<< Prev
|
|
Next >>
|
";
echo $output;
?>