I'm trying to make this calendar script to work, but... I can't figure out how to make events show in the calendar, and how to set "Monday" as the first day... Can somebody please help...
The script:
$result = mysql_query("SELECT DATE_FORMAT(matchstart, '%Y-%c-%e') as date FROM fb_matches");
while($row = mysql_fetch_array($result)){
$starttime[] = $row['date'];
}
if(isset($_REQUEST['prev'])){
if($_REQUEST['prev'] == 'prev'){
$monthnum = $_REQUEST['monthnow']--;
}else{
$monthnum = $_REQUEST['monthnow']++;
}
$date = getdate(mktime(0,0,0,$_REQUEST['monthnow'],1,$_REQUEST['yearnow']));
}else{
$date = getdate();
}
if(isset($_REQUEST['all'])){
$monthnum = $_REQUEST['monthnow'];
$date = getdate(mktime(0,0,0,$_REQUEST['monthnow'],1,$_REQUEST['yearnow']));
}
$monthnum = $date['mon'];
$monthname = $date['month'];
$year = $date['year'];
$datetoday = getdate(mktime(0,0,0,$monthnum,1,$year));
$firstweekay = $datetoday['wday'];
$cont = true;
$today = 27;
while(($today <= 32) && ($cont)){
$datetoday = getdate(mktime(0,0,0,$monthnum,$today,$year));
if($datetoday['mon'] != $monthnum) {
$lastday = $today - 1;
$cont = false;
}
$today++;
}
echo '<br /><form action="'.$_SERVER['PHP_SELF'].'?action=calendar" method="post">
<table width="160" align="center" border="1" cellpadding="1" cellspacing="1" bordercolor="#CCCCCC" bgcolor="#ffffff">
<tr>
<td align="center" style="padding: 6px" colspan="7" bgcolor="#6D84B4">
<a href="'.$_SERVER['PHP_SELF'].'?action=calendar&all&prev=prev&monthnow='.$monthnum.'&yearnow='.$year.'"><<<</a>
<select name="monthnow" onChange="form.submit()">
<option '.( $monthnum=='1' ? 'selected' : '' ).' value="1">Jan</option>
<option '.( $monthnum=='2' ? 'selected' : '' ).' value="2">Feb</option>
<option '.( $monthnum=='3' ? 'selected' : '' ).' value="3">Mar</option>
<option '.( $monthnum=='4' ? 'selected' : '' ).' value="4">Apr</option>
<option '.( $monthnum=='5' ? 'selected' : '' ).' value="5">May</option>
<option '.( $monthnum=='6' ? 'selected' : '' ).' value="6">Jun</option>
<option '.( $monthnum=='7' ? 'selected' : '' ).' value="7">Jul</option>
<option '.( $monthnum=='8' ? 'selected' : '' ).' value="8">Aug</option>
<option '.( $monthnum=='9' ? 'selected' : '' ).' value="9">Sep</option>
<option '.( $monthnum=='10' ? 'selected' : '' ).' value="10">Oct</option>
<option '.( $monthnum=='11' ? 'selected' : '' ).' value="11">Nov</option>
<option '.( $monthnum=='12' ? 'selected' : '' ).' value="12">Dec</option>
<input name="all" type="hidden" value="">
</select>
<select name="yearnow" onChange="form.submit()">
<option '.( $year=='2007' ? 'selected' : '' ).' value="2007">2007</option>
<option '.( $year=='2008' ? 'selected' : '' ).' value="2008">2008</option>
<option '.( $year=='2009' ? 'selected' : '' ).' value="2009">2009</option>
<option '.( $year=='2010' ? 'selected' : '' ).' value="2010">2010</option>
</select>
<a href="'.$_SERVER['PHP_SELF'].'?action=calendar&all&prev&monthnow='.$monthnum.'&yearnow='.$year.'">>>></a>
</td>
</tr>
<tr>
<td style="padding: 6px" align="center" bgcolor="#D8DFEA"><b>Sun</b></td>
<td style="padding: 6px" align="center" bgcolor="#D8DFEA"><b>Mon</b></td>
<td style="padding: 6px" align="center" bgcolor="#D8DFEA"><b>Tue</b></td>
<td style="padding: 6px" align="center" bgcolor="#D8DFEA"><b>Wed</b></td>
<td style="padding: 6px" align="center" bgcolor="#D8DFEA"><b>Thu</b></td>
<td style="padding: 6px" align="center" bgcolor="#D8DFEA"><b>Fri</b></td>
<td style="padding: 6px" align="center" bgcolor="#D8DFEA"><b>Sat</b></td>
</tr>';
$day = 1;
$wday = $firstweekay;
$firstweek = true;
while ($day <= $lastday){
if($firstweek){
echo '<tr>';
for ($i=1; $i<=$firstweekay; $i++){
echo '<td></td>';
}
$firstweek = false;
}
if ($wday==0){
echo '<tr>';
}
if(intval($monthnum) < 10) {
$newmonthnum = '0'.$monthnum.'';
}
elseif (intval($monthnum) >= 10) {
$newmonthnum = $monthnum;
}
if(intval($day) < 10) {
$newday = '0'.$day.'';
}
elseif(intval($day) >= 10) {
$newday = $day;
}
$mtodaydate = "$year-$newmonthnum-$newday";
$todaysdate = date("Y-m-d");
$eventday = "$year-$monthnum-$day";
switch( @$starttime[ $eventday ] )
{
case 1: $color = '#990000'; break;
case 2: $color = '#990000'; break;
case 3: $color = "#990000"; break;
default: $color = $todaysdate == $mtodaydate ? "#F0F0FF" : '#FFFFFF';
}
echo '<td height="42" width="42" valign="top" style="padding: 2px" align="left" bgcolor="'.$color.'">'.$day.'</td>';
if($wday==6) {
echo '</tr>';
}
$wday++;
$wday = $wday % 7;
$day++;
}
echo '</table>';
if(($monthnum != date('n')) || ($year != date('Y'))) {
echo '<center>View '.date('F').' '.date('Y').' <b><a href="'.$_SERVER['PHP_SELF'].'?action=calendar">here</a></b></center>';
}
echo '</form>';