Hi,
I am getting a parse error with the following code. I realise that it is probably a bracket missing somewhere, but I can't see where.
<?php
/* Calendar.php
Display a calendar and allow user to move forward and backward
through months via form controls.
$month = last month displayed
$year = last year displayed
$calendar = TRUE if this script is calling, "mini" to
display miniature calendar
Form control (POST) Next = Next month
Form control (POST) Prev = Previous month
GET variable "display" overrides display - date to display
passed in (m-y) format (e.g., June 2003 = "?display=6-2003")
*/
// Globals for easy reference
global $month, $year, $calendar;
// Get the variables from POST or GET
function get_vars($type) {
global $month, $year, $calendar;
// Get POST vars
if ($type == "POST") {
foreach($POST as $key => $value) {
$$key = $value;
}
} else {
// GET data is in different format for
// simple calling, "display=m-y"
// Put the mdy into array $dt
$dt = explode("-",$GET['display']);
// If a valid date was passed, assign it to vars
if (checkdate($dt[0],1,$dt[1])) {
// Rearrange date to ISO 8601 format (yyyy-mm-dd)
// and get timestamp ($ts)
$ts = strtotime($dt[1]."-".$dt[0]."-1");
$month = date('n',$ts);
$year = date('Y',$ts);
} else {
// Not a valid date, use today
$month = date('n');
$year = date('Y');
}
// Get calendar value if passed
if (isset($GET['calendar'])) {
$calendar = $GET['calendar'];
} else {
// Set to default
$calendar = "TRUE";
}
}
}
// Set up the date to display
function set_date() {
global $month, $year, $calendar;
// If GET n/v pairs exist, they override POSTS
if (!empty($_GET)) {
get_vars("GET");
} else {
// If $calendar is set then we can assume that
// this call is under control of this script
// (or a well-behaved handler)
if (!isset($_POST["calendar"])) {
$calendar = "TRUE";
// Set today
$month = date('n');
$year = date('Y');
} else {
// Get POST data
get_vars("POST");
// If Next, then move month forward
if ($_POST["Next"] == ">>") {
$month = $month + 1;
if ($month == "13") {
$year = $year + 1;
$month = 1;
}
}
// If Prev, then move month backward
if ($_POST["Prev"] == "<<") {
$month = $month - 1;
if ($month == "0") {
$year = $year - 1;
$month = 12;
}
}
}
}
}
// Display the calendar form
function display_cal($month,$year,$calendar) {
// Determine today to mark it accordingly
$today = date("j-n-Y");
// Build calls to script, include calendar var if
// it has been set (!= default TRUE)
$this_script = $_SERVER['PHP_SELF'];
if ($calendar != "TRUE") {
$reset_script = $this_script."?calendar=".$calendar;
} else {
$reset_script = $this_script;
}
// Get timestamp for first day of current month/year
$timestamp = strtotime($year."-".$month."-01");
// What's the last day of this month? (28-31) t= number of days in given month
$lastday = date('t',$timestamp);
// What weekday does the first fall on?
$wkday = date('w',$timestamp); // w = day of week (0=Sunday 6=Saturday)
// Set monthtext and dow display according to size
// of calendar
if ($calendar != "mini") {
// Not mini-cal, use full text
$tblsize = 100;
$dow = array("Sunday","Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday");
$monthtext = date('F',$timestamp); // F = full text display of month
} else {
// Mini-cal, use single char days and 3 char month
$tblsize = 20;
$dow = array("S","M","T","W","T","F","S");
$monthtext = date('M',$timestamp);
}
// Print calendar header info
print <<<HTML
<html>
<title>Calendar</title>
<body>
<form action="$this_script" method="post">
<!-- Script control variables -->
<input type="hidden" name="calendar" value="$calendar">
<input type="hidden" name="month" value="$month ">
<input type="hidden" name="year" value="$year">
<!-- Month header with Prev/Next buttons -->
<table border=1>
<tr>
<td colspan="2" align="left">
<input type="submit" name="Prev" value="<<">
</td>
<td colspan="3" align="center">
<strong>
<a href="$reset_script".$getdata>$monthtext $year</a>
</strong>
</td>
<td colspan="2" align="right">
<input type="submit" name="Next" value=">>">
</td>
</tr>
<!-- Day of week header row -->
<tr>
<td width="$tblsize"><center><b>$dow[0]</b></center></td>
<td width="$tblsize"><center><b>$dow[1]</b></center></td>
<td width="$tblsize"><center><b>$dow[2]</b></center></td>
<td width="$tblsize"><center><b>$dow[3]</b></center></td>
<td width="$tblsize"><center><b>$dow[4]</b></center></td>
<td width="$tblsize"><center><b>$dow[5]</b></center></td>
<td width="$tblsize"><center><b>$dow[6]</b></center></td>
</tr>
<!-- Calendar starts here -->
HTML;
// Skip days of week up to first day of month
print "<tr> \n";
for ($x = 0; $x < $wkday; $x++) {
print "\t<td align=\"right\"
valign=\"top\" height=\"$tblsize\">";
print " ";
print "</td>\n";
}
// Step through month, 1st through last day (28, 30, or 31)
// Print table cell for each
for ($x = 1; $x <= $lastday; $x++) {
// Close row after each Sat, start next row with Sunday (0)
if ($wkday == "7") {
print "</tr>\n<tr>\n";
$wkday = 0;
}
print "\t<td align=\"right\"
valign=\"top\" height=\"$tblsize\">";
// If this is today, highlight it with red font
if ($today == $month."-".$x."-".$year) {
print "<font color=\"#ff0000\">"; }
print "$x";
if ($today == $month."-".$x."-".$year) {
print "</font>"; }
print "</td>\n";
$wkday++;
}
// Close out row
while ($wkday < 7) {
print "\t<td align=\"right\"
valign=\"top\" height=\"$tblsize\"> </td>\n";
$wkday++;
}
// Close open tags and page
print <<<HTML
</tr>
</table>
</form>
</body>
HTML;
}
// Main program body
// Set the dates to display
set_date();
// Display the calendar
display_cal($month,$year,$calendar);
?>