I'm using a calendar (the script I found on this website and modified it somewhat to fit my needs for the project) to allow users to click on dates that they are available to work. These dates are then stored in a table in the database id | user_id | a_date | user_name
Everything works perfectly, but I'm trying to modify the code further so that when the user pulls up the calendar, it will highlight any dates that he/she has clicked on previously to indicate their availability. In other words, the script would look to the table "availability" and find any entries where the user's id # was in the 'user_id' column, and it would highlight the corresponding date on the calendar.
I'm really desperate for help on this, I've been working on it on and off over the past 2 months while doing other parts of the project as well, and thus far I've been completely unable to get the highlight feature added.
I will admit I'm fairly inexperienced with PHP, so the problem probably isn't helped by the fact that I really am not even sure where to put such code, let alone what the code should be, and its got me so frustrated right now I thought I would kindly request some assistance.
Thank you GREATLY in advance if you can help.
The code is quite long and I'm unsure of exactly what part I need to show (ie: where the highlighting script needs to go), so I appologize that it will take up 2 posts, but hopefully someone can see what I'm trying to do.
Thanks.
<?php
/*
This an extension to the class I wrote, v 2.5.1 written by: David Hernandez Sanz
(davidhdezsanz@terra.es) [url]http://www.dhs.sitio.net/[/url]
This class is intended to be an extension, so make sure you download 2.5.1 first.
It includes a lot of improvements, and also allows for some european calendar option.
*/
//require("file:///C|/Documents%20and%20Settings/User/My%20Documents/My%20Webs/cal.php");
class Calendar {
function getDayOfWeek($dd, $mm, $yy){
//returns int giving day of week for a date
$dateArray = getdate(mktime(0,0,0,$mm,$dd,$yy));
return $dateArray['wday'];
}
function daysInMonth($month,$year) {
$date = getdate(mktime(0,0,0,$month+1,0,$year));
return $date["mday"];
}
function startCalendar($myCal) {
if ((isset($_GET['month']) && isset($_GET['year']))) {
$thecalendar = $this->displayCalendar($_GET['month'],$_GET['year'],$myCal);
}
else {
$now = date('n,Y');
$myDate = explode(",",$now);
$thecalendar = $this->displayCalendar($myDate[0],$myDate[1],$myCal);
}
return $thecalendar;
}
function checkDate($month,$year) {
if (!is_numeric($month) || !is_numeric($year)) {
return $this->myError("Either the month of year was non-numeric.");
}
else if ($month > 12 || $month < 1) {
return $this->myError("The number passed for the month value is not valid.");
}
else if ($year > 2037 || $year < 1970) {
return $this->myError("The number passed for the year value is not valid.");
}
else {
return "passed";
}
}
function next($month,$year) {
if ($month == 12) {
$next['month'] = 1;
$next['year'] = $year + 1;
}
else {
$next['month'] = $month + 1;
$next['year'] = $year;
}
return $next;
}
function last($month,$year) {
if ($month == 1) {
$last['month'] = 12;
$last['year'] = $year - 1;
}
else {
$last['month'] = $month - 1;
$last['year'] = $year;
}
return $last;
}
function monthName($month) {
$monthName = array(1 => "January",
2 => "February",
3 => "March",
4 => "April",
5 => "May",
6 => "June",
7 => "July",
8 => "August",
9 => "September",
10 => "October",
11 => "November",
12 => "December");
return $monthName[$month];
}
function displayCalendar($month,$year,$myCal){
// Make sure that we have a valid month and year.
$check = $this->checkDate($month,$year);
if ($check != "passed") {
return $check;
die();
}
if ($myCal) {
extract($myCal);
}
$monthName = $this->monthName($month);
$next = $this->next($month,$year);
$last = $this->last($month,$year);
$myCalendar = '
<table border="1" cellpadding="0" cellspacing="0" style="font-size: 8pt; font-family: tahoma, arial, sans-serif;">
<tr>
<td colspan="7" align="center">
<table bgcolor="' . $headerBgcolor . '" border="0" cellpadding="1" cellspacing="0" width="100%" style="font-family: tahoma, arial, sans-serif; font-size: 8pt;">
<tr>
<td align="center" width="30">
<a href="' . $_SERVER['PHP_SELF'] . '?month=' . $last['month'] . '&year=' . $last['year'] . '" style="text-decoration: none;"><<</a>
</td>
<td align="center" style="font-size: 10pt; color: ' . $headerColor . '">
' . $monthName . ' ' . $year . '
</td>
<td align="center" width="30">
<a href="' . $_SERVER['PHP_SELF'] . '?month=' . $next['month'] . '&year=' . $next['year'] . '" style="text-decoration: none;">>></a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="' . $dayBgcolor . '" width="27" align="center"valign="middle" style="color: ' . $dayColor . '">
Sun
</td>
<td bgcolor="' . $dayBgcolor . '" width="27" align="center"valign="middle" style="color: ' . $dayColor . '">
Mon
</td>
<td bgcolor="' . $dayBgcolor . '" width="27" align="center"valign="middle" style="color: ' . $dayColor . '">
Tue
</td>
<td bgcolor="' . $dayBgcolor . '" width="27" align="center"valign="middle" style="color: ' . $dayColor . '">
Wed
</td>
<td bgcolor="' . $dayBgcolor . '" width="27" align="center"valign="middle" style="color: ' . $dayColor . '">
Thu
</td>
<td bgcolor="' . $dayBgcolor . '" width="27" align="center"valign="middle" style="color: ' . $dayColor . '">
Fri
</td>
<td bgcolor="' . $dayBgcolor . '" width="27" align="center"valign="middle" style="color: ' . $dayColor . '">
Sat
</td>
</tr>';
$dom = 1;
//scan thru calendar grid
for ($r=1; $r<=6; $r++){
for ($c=0; $c<=7; $c++){
if ($c == 0){
$myCalendar .= "
<tr>";
}
else {
if ($c == 1 + $this->getDayOfWeek($dom,$month,$year)){
$myCalendar .= '
<td align="center" valign="middle" bgcolor="' . $cellBgcolor . '" style="color: ' . $cellColor . '">
' . $dom . '
</td>';
//if there are no more days, skip drawing the rest
if ($dom < $this->daysInMonth($month,$year)){
$dom++;
}
else {
$r=7;
}
}
else {
$myCalendar .= '
<td bgcolor="' . $cellBgcolor . '">
</td>';
}
}
if ($c == 7){
$myCalendar .= "
</tr>";
}
}
}
$myCalendar .= "
</table>";
return $myCalendar;
}
function myError($myError) {
$returnError = '<div>
<strong>The following calendar error has occured:</strong><br />
' . $myError . '
</div>';
return $returnError;
}
}