I have been working on an appointment booking application for the company I work for. I looked for several “out of the box” solutions, but none met the needs of the company. The dispatcher needed a way to go paperless, assign work to repair technicians and give them a daily print out of their work. One of the first tasks way developing a clickable calendar sof the dispatcher to switch days.
The first part is generating a static calendar.
The next part is generating the calendar with links to previous and next months
<table width="100%" cellpadding="0" cellspacing="0">
<tr align="center">
<td align="center"colspan="7" style="color:#000; white-space:nowrap; font-family: Verdana, Geneva, sans-serif; font-size: 14px;"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
<td width="10%" align="left" class="style2"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#144cef"><img border="0" src="img/back_cal.png" width="16" height="16" /></a></td>
<td width="10%" align="left" class="style2"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#144cef"><img border="0" src="img/next_cal.png" width="16" height="16" /></a></td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">Su</td>
<td align="center">Mo</td>
<td align="center">Tu</td>
<td align="center">We</td>
<td align="center">Th</td>
<td align="center">Fr</td>
<td align="center" class="style1">Sa</td>
</tr>
<?php
# Print The calendar with links to the days w/ postback</code>
$monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("m");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
if (!isset($_REQUEST["day"])) $_REQUEST["day"] = date("d");
if (empty($_REQUEST["day"]) || empty($_REQUEST["year"]) || empty ($_REQUEST["month"])) {
$day=date('d',mktime(0,0,0,date('m'), date('d'), date('Y')));
$month=date('m',mktime(0,0,0,date('m'), date('d'), date('Y')));
$year=date('Y',mktime(0,0,0,date('m'), date('d'), date('Y')));
}else{
$day=$_REQUEST["day"];
}
$cMonth=$_REQUEST["month"];
$cYear =$_REQUEST["year"];
$cdaydo=date('Y-m-d',mktime(0,0,0, date($_REQUEST["month"]), date($day), date ($_REQUEST["year"])));
$cdaydo2=date('l, F j',mktime(0,0,0, date($_REQUEST["month"]), date($day), date ($_REQUEST["year"])));
$prev_year=$cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month==0) {
$prev_month=12;
$prev_year=$cYear-1;
}
if ($next_month==13 ) {
$next_month=1;
$next_year=$cYear+1;
}
?>
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=0; $i<($maxday+$startday); $i++) {
#color the tds for current date, date selected, unassigned, locked, all assigned, still need assigned
$real = date("Y-m-d");
$dafont = ($i - $startday + 1);
$tod = date("Y-m-d", mktime(0,0,0,$cMonth,$dafont,$cYear));
$tod2 = date("Y-m-d", mktime(0,0,0,$cMonth,$day,$cYear));
if ($real == $tod) {$st = "border: 1px dashed red;";}else{$st = "";}
if ($tod2 == $tod) {$st1 = "border: 1px solid black;";}else{$st1 = "";}
if($totalRows_Recordset1 > 0 && $tech_id == 0){$st2 = "background-color: #EEEED8;";}else{$st2 = "";}
if($totalRows_Recordset1 > 0 && $tech_id > 0){$st3 = "background-color: #77EE00;";}else{$st3 = "";}
#add the styles up and apply them
$style = $st . $st1 . $st2 . $st3;
#end coloring and borders
if(($i % 7) == 0 ) echo "<tr>\n";
if($i < $startday) echo "<td></td>\n";
else
#change manage.php to the php file with this code in it.
echo "<td style='" . $style . "' align='center' valign='center' height='25px' width='25px'><a href ='manage.php?&year=" . $cYear . "&month=" . $cMonth . "&day=" . $daydo =($i - $startday + 1) . "'>" . ($i - $startday + 1) . "</a></td>\n";
$style = "";
if(($i % 7) == 6 ) echo "</tr>\n";
}
# End Print the Calendar
?>