<?php
define("ADAY", (60*60*24) );
$month = $_POST['month'];
$year = $_POST['year'];
$data = file('events.txt');
foreach ($data as $line){
$events = explode('|',$line);
$daysofevents[] =  $events[1];
}

if (!checkdate( $month, 1, $year ) )
 {
$nowArray = getdate();
$month = $nowArray[mon];
$year = $nowArray[year];
}
$start = mktime ( 0, 0, 0, $month, 1, $year );
$firstDayArray = getdate($start);
?>
<html>
 <head>
<title><?php print "Calendar: $firstDayArray[month]
$firstDayArray[year]" ?></title>

<style type="text/css">
.str<?= date('M_d_Y');?> {
	color:red;
}
</style>
<head>
<body>


<form action="<? print $_SERVER['PHP_SELF']; ?>" method="post">
<select name="month">
<?php
$months = Array("January", "February", "March", "April",
"May", "June", "July", "August", "September",
"October", "November", "December");
for ( $x=1; $x <= count( $months ); $x++ )
{
print "\t<option value=\"$x\"";
print ($x == $month)?" SELECTED":"";
print ">".$months[$x- 1]."\n";
}
?>
</select>
<select name="year">
<?php
for ( $x=1980; $x<2020; $x++ )
{
print "\t<option";
print ($x == $year)?" selected=\"selected\" ":"";
print ">$x\n";
 }
 ?>
</select>
<input type="submit" value="Go!">
</form>
<p>
<?php
$days = Array("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday");
 print "<table border = 1 cellpadding=5>\n";
foreach ( $days as $day )
print "\t<td><b>$day</b></td>\n";
for ( $count=0; $count < (6*7); $count++ )
{
$dayArray = getdate( $start );
if ( (($count) % 7) == 0 )
{
if ( $dayArray[mon] != $month )
break;
print "</tr><tr>\n";
 }
 if ( $count < $firstDayArray[wday] || $dayArray[mon] != $month )
 {
 print "\t<td><br></td>\n";
 }
 else
{
	//duplicate days 1st week november

		
 $class = date('M_d_Y',$start);
$numday= date('j',$start);

if (in_array($numday,$dayswithevents)){
echo "\t<td class=\"str".$class."\"><a href=\"someevent.php?day=".$class."\">".$numday."</a></td>\n";
 }
 else
 {
echo "\t<td class=\"str".$class."\">".$numday."</td>\n";

 }

 $start += ADAY;
	
	
 }
 }
 print "</tr></table>";
 ?>
 </body>
 </html>