I'm trying to get a php read-only calendar to display dates from a Google Calendar, using jQuery to apply color to the background of the relevant cells. Code for each calendar table looks like this:
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_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;
}
if (!isset($_REQUEST["short-month"])) $_REQUEST["short-month"] = date("m");
$cShortMonth = $_REQUEST["short-month"];
?>
// Generate the calendar
<div class="month">
<?php $month_of_year = 1; ?>
<h2><?php echo $monthNames[$cMonth+$month_of_year-2].' '.$cYear; ?></h2>
<table class="cal">
<tr>
<td class="day-cell">S</td>
<td class="day-cell">M</td>
<td class="day-cell">T</td>
<td class="day-cell">W</td>
<td class="day-cell">T</td>
<td class="day-cell">F</td>
<td class="day-cell">S</td>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth+$month_of_year-1,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=0; $i<($maxday+$startday); $i++) {
$year_id = $cYear;
$month_id_raw = $cShortMonth+$month_of_year-1;
$month_id = str_pad($month_id_raw, 2, "0", STR_PAD_LEFT);
$day_id_raw = $i - $startday + 1;
$day_id = str_pad($day_id_raw, 2, "0", STR_PAD_LEFT);
if(($i % 7) == 0 ) echo "<tr>";
if($i < $startday) echo "<td></td>";
else echo "<td class='date-cell' id='" . $year_id . "-" . $month_id . "-" . $day_id . "'>" . ($i - $startday + 1) . "</td>";
if(($i % 7) == 6 ) echo "</tr>";
}?>
</table>
</div>
Which generates a calendar table that I've repeated x12:
It gives each date on the calendar a unique id in date format YYYY-MM-DD, which seems to be working. That is in preparation for the jQuery below (matches the JSON format in the XML), which is where I get stuck:
function GCalEvents() {
var calendar_json_url = "https://www.google.com/calendar/feeds/myemail%40googlemail.com/public/full?orderby=starttime&sortorder=ascending&max-results=3&futureevents=true&alt=json"
// Get list of upcoming events formatted in JSON
jQuery.getJSON(calendar_json_url, function(data){
// Parse and render each event
jQuery.each(data.feed.entry, function(i, item){
// Apply background to start dates.
var start_time_id = item.gd$when[0].startTime;
var end_time_id = item.gd$when[0].endTime;
jQuery("#" + start_time_id).css("background","red");
jQuery("#" + end_time_id).css("background","green");
});
});
}
As you can see, I can get jQuery to use the .startTime/.endTime as the ID, which allows me to colour the individual dates. But I need to color up all the days between .startTime and .endTime (usually a whole week) in one go. They don't have to be different colors - I've just done that to highlight start/end date.
So what I'm looking for is the way to colour up the whole week in one hit. If anyone can help I'd be very grateful as its proving to be beyond me.