I am a firefighter and I designed our website. It has a calendar that we use to show who is off on what days. Its mysql driven. While I have it functioning properly, I want to add a cosmetic addition to it. Our department has 3 24 hour shifts. Shift 1, Shift 2 & Shift 3 respectively. I want to color the days on the calendar with red, black & green. This is a standard format for firefighter calendars. Im not sure how to start. I thought I might be able to use a looping array, but I'm unsure. Below is my calendar code. Any tips, help or a push in the right direction would be appreciated.
$shift = 1;
if ($shift == 1) {
$cal_events = "cal_events1";
} elseif ($shift == 2) {
$cal_events = "cal_events2";
} elseif ($shift == 3) {
$cal_events = "cal_events3";
}
if (isset($_POST['submit'])) {
$month_now = (isset($_POST['month_now'])) ? $_POST['month_now'] : '';
$year_now = (isset($_POST['year_now'])) ? $_POST['year_now'] : '';
if ($_POST['submit'] == "Prev") {
$month_now--;
} else {
$month_now++;
}
$date = getdate(mktime(0,0,0,$month_now,1,$year_now));
} else {
$date = getdate();
}
$month_num = $date["mon"];
$month_name = $date["month"];
$year = $date["year"];
$date_today = getdate(mktime(0,0,0,$month_num,1,$year));
$first_week_day = $date_today["wday"];
$cont = true;
$today = 27;
while (($today <= 32) && ($cont)) {
$date_today = getdate(mktime(0,0,0,$month_num,$today,$year));
if ($date_today["mon"] != $month_num) {
$lastday = $today - 1;
$cont = false;
}
$today++;
}
// allow for form submission to the script for forward and backwards
include_once ('includes/header.php');
echo "<div id=\"content\">"
."<div class=\"site\">";
echo "<form action=\"calendar1.php\" method=\"post\" name=\"calendar\">"
."<input type=\"hidden\" name=\"month_now\" value=\"$month_num\">"
."<input type=\"hidden\" name=\"year_now\" value=\"$year\">"
."<h2>Shift $shift Calendar</h2>"
."<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
."<tr>"
."<td align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Prev\"></td>"
."<td align=\"center\"><b>$month_name $year</b></td>"
."<td align=\"left\"><input type=\"submit\" name=\"submit\" value=\"Next\"></td>"
."</tr>"
."</table>"
."</form>"
."<table id=\"calendar\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">"
."<tr>"
."<th width=\"14%\">Sunday</th>"
."<th width=\"14%\">Monday</th>"
."<th width=\"14%\">Tuesday</th>"
."<th width=\"14%\">Wednesday</th>"
."<th width=\"14%\">Thursday</th>"
."<th width=\"14%\">Friday</th>"
."<th width=\"14%\">Saturday</th>"
."</tr>";
// placement of days to beginning weekday
$day = 1;
$wday = $first_week_day;
$firstweek = true;
while ( $day <= $lastday) {
if ($firstweek) {
echo "<tr>";
for ($i=1; $i<=$first_week_day; $i++) {
echo "<td class=\"blank\"></td>";
}
$firstweek = false;
}
if ($wday==0) {
echo "<tr>";
}
if ( intval($month_num) < 10) {
$new_month_num = "0$month_num";
}
elseif (intval($month_num) >= 10) {
$new_month_num = $month_num;
}
if ( intval($day) < 10) {
$new_day = "0$day";
}
elseif (intval($day) >= 10) {
$new_day = $day;
}
$link_date = "$year-$new_month_num-$new_day";
$today = date('d');
$month = date('m');
if ($day == $today && $month == $month_num) {
echo "<td class=\"day\"><a href=calendar_functions.php?op=results&event_date=$link_date&shift=$shift onclick=\"NewWindow(this.href,'name','650','300','yes');return false\" target=\"_blank\">$day<br />";
} else {
echo "<td><a href=calendar_functions.php?op=results&event_date=$link_date&shift=$shift onclick=\"NewWindow(this.href,'name','650','300','yes');return false\" target=\"_blank\">$day<br />";
}
$query = "SELECT * FROM $cal_events WHERE MONTH(event_date) = '$month_num' AND DAYOFMONTH(event_date) = '$day' AND YEAR(event_date) = '$year' ORDER BY event_priority ASC";
$result = mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
$query2 = "SELECT cat_color FROM cal_categories WHERE cat_id=".$row['cat_id']."";
$result2 = mysql_query($query2) or die(mysql_error());
$row2 = mysql_fetch_array($result2);
$fcolor = $row2['cat_color'];
$event = $row['event_name'];
$event_id = $row['event_id'];
$priority = $row['event_priority'];
echo " <font color=\"$fcolor\">$priority. $event</font><br />";
}
echo "</td>";
if ($wday==6) {
echo "</a></tr>\n";
}
$wday++;
$wday = $wday % 7;
$day++;
}
echo "</table>"
."<img src=\"images/calendar-legend.jpg\" border=\"0\">"
."</div></div>";