dprichard
02-07-2008, 02:41 PM
I am working on a calendar and want to show times that employees have requested off by changing the color and highlighting the days off. So, if the employee has off from Jan 1st - 5th, then those days will be highlighted. I have this working, but the problem I am running into is that if they requested off for Jan 1st - 5th and Jan 20th - 25th, then only one request shows highlighted. The other request does not. Any help from you PHP Gurus would be greatly appreciated.
<?php
include '../config.php';
include ('../functions.php');
permission_admin();
// Pulls in employee information from the database.
$employees = mysql_query("SELECT emp_id, emp_fname, emp_lname FROM employee ORDER BY emp_lname ASC") or die(mysql_error());
$row_employees = mysql_fetch_array($employees);
//Variables used in testing to show every month in 2008
$firstmonth = 1;
$lastmonth = 12;
while ($firstmonth <= $lastmonth) {
//Starts the first calendar at Jan 2008 for Testing
$date = strtotime("1-$firstmonth-2008");
//$date = time();
//This puts the day, month, and year in seperate variables
$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);
//Generate the first day of the month
$first_day = mktime(0,0,0,$month, 1, $year);
//Generate the month
$title = date('F', $first_day);
//Find out what day of the week the first day falls on
$day_of_week = date('D', $first_day);
//Get the days in the current month
$days_in_month = cal_days_in_month(0, $month, $year);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Calendar</title>
<style>
.calendar_table {
border: solid;
border-color: #0c4a93;
border-size: 1px;
margin: 0 0 30px 0;
}
.calendar_table td {
}
.cal_month_title {
background-color: #0c4a93;
text-align: center;
font-size: 12px;
color: #FFFFFF;
font-family: Verdana;
}
.cal_day_title {
background-color: #688ebd;
text-align: center;
font-size: 12px;
color: #FFFFFF;
font-family: Verdana;
font-weight: bold;
padding: 0 8px 0 8px;
width: 3%;
}
.cal_day_blank {
background-color: #999999;
width: 3%;
}
.cal_day_current {
background-color: #d3481f;
text-align: center;
font-size: 12px;
color: #FFF;
font-family: Verdana;
font-weight: bold;
}
.cal_day {
background-color: #bccde1;
text-align: center;
font-size: 12px;
color: #FFF;
font-family: Verdana;
font-weight: bold;
}
.cal_emp_title {
background-color: #688ebd;
text-align: right;
font-size: 12px;
color: #FFFFFF;
font-family: Verdana;
font-weight: bold;
padding: 0 8px 0 8px;
}
.cal_emp_name {
background-color: #8fb0d9;
text-align: right;
font-size: 12px;
color: #FFFFFF;
font-family: Verdana;
font-weight: bold;
padding: 0 8px 0 8px;
}
</style>
</head>
<body>
<?php
echo "<table width='100%' class='calendar_table'>";
echo "<tr><th colspan=42 class='cal_month_title'> $title $year </th></tr>";
echo "<tr>";
$day_count = 1;
echo "<tr><td nowrap class='cal_emp_title'>Employee Name</td>";
//Sets the first day of the month to 1
$day_num = 1;
//count up the days, until we have done them all in the month
while ($day_num <= $days_in_month) {
echo "<td class='cal_day_title'>".date('D', mktime(0,0,0,$month, $day_num, $year))."</td>";
$day_num++;
$day_count++;
} echo "</tr>";
$day_count = 1;
do {
echo "<tr><td nowrap class='cal_emp_name'>".$row_employees['emp_id']." - ".$row_employees['emp_lname'].", ".$row_employees['emp_fname']."</td>";
$emp_id = '';
$emp_id = mysql_real_escape_string($row_employees['emp_id']);
$time_off = mysql_query("SELECT to_request_start_date, to_request_end_date, to_request_id FROM to_request WHERE to_request_emp_id = '$emp_id'") or die(mysql_error());
$row_time_off = mysql_fetch_array($time_off);
$request_start = $row_time_off['to_request_start_date'];
$request_end = $row_time_off['to_request_end_date'];
//Sets the first day of the month to 1
$day_num = 1;
//count up the days, until we have done them all in the month
while ($day_num <= $days_in_month) {
$comp_date = strtotime($year . '-' . $month . '-' . $day_num);
$request_start_comp = strtotime($request_start);
$request_end_comp = strtotime($request_end);
$start = date('Y-m-j',strtotime($request_start));
$end = date('Y-m-j',strtotime($request_end));
if ($comp_date >= $request_start_comp && $comp_date <= $request_end_comp) {
echo "<td class='cal_day_current'>";
echo $day_num;
echo"</td>";
} else {
echo "<td class='cal_day'>";
echo $day_num; }
$day_num++;
$day_count++;
}
while ( $day_count >1 && $day_count <=7 )
{
echo "<td class='cal_day_blank'> </td>";
$day_count++;
}
echo "</tr>";
} while ($row_employees = mysql_fetch_array($employees));
mysql_data_seek($employees, 0);
echo "</table>";
$firstmonth++;
}
?>
</body>
</html>
<?php
include '../config.php';
include ('../functions.php');
permission_admin();
// Pulls in employee information from the database.
$employees = mysql_query("SELECT emp_id, emp_fname, emp_lname FROM employee ORDER BY emp_lname ASC") or die(mysql_error());
$row_employees = mysql_fetch_array($employees);
//Variables used in testing to show every month in 2008
$firstmonth = 1;
$lastmonth = 12;
while ($firstmonth <= $lastmonth) {
//Starts the first calendar at Jan 2008 for Testing
$date = strtotime("1-$firstmonth-2008");
//$date = time();
//This puts the day, month, and year in seperate variables
$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);
//Generate the first day of the month
$first_day = mktime(0,0,0,$month, 1, $year);
//Generate the month
$title = date('F', $first_day);
//Find out what day of the week the first day falls on
$day_of_week = date('D', $first_day);
//Get the days in the current month
$days_in_month = cal_days_in_month(0, $month, $year);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Calendar</title>
<style>
.calendar_table {
border: solid;
border-color: #0c4a93;
border-size: 1px;
margin: 0 0 30px 0;
}
.calendar_table td {
}
.cal_month_title {
background-color: #0c4a93;
text-align: center;
font-size: 12px;
color: #FFFFFF;
font-family: Verdana;
}
.cal_day_title {
background-color: #688ebd;
text-align: center;
font-size: 12px;
color: #FFFFFF;
font-family: Verdana;
font-weight: bold;
padding: 0 8px 0 8px;
width: 3%;
}
.cal_day_blank {
background-color: #999999;
width: 3%;
}
.cal_day_current {
background-color: #d3481f;
text-align: center;
font-size: 12px;
color: #FFF;
font-family: Verdana;
font-weight: bold;
}
.cal_day {
background-color: #bccde1;
text-align: center;
font-size: 12px;
color: #FFF;
font-family: Verdana;
font-weight: bold;
}
.cal_emp_title {
background-color: #688ebd;
text-align: right;
font-size: 12px;
color: #FFFFFF;
font-family: Verdana;
font-weight: bold;
padding: 0 8px 0 8px;
}
.cal_emp_name {
background-color: #8fb0d9;
text-align: right;
font-size: 12px;
color: #FFFFFF;
font-family: Verdana;
font-weight: bold;
padding: 0 8px 0 8px;
}
</style>
</head>
<body>
<?php
echo "<table width='100%' class='calendar_table'>";
echo "<tr><th colspan=42 class='cal_month_title'> $title $year </th></tr>";
echo "<tr>";
$day_count = 1;
echo "<tr><td nowrap class='cal_emp_title'>Employee Name</td>";
//Sets the first day of the month to 1
$day_num = 1;
//count up the days, until we have done them all in the month
while ($day_num <= $days_in_month) {
echo "<td class='cal_day_title'>".date('D', mktime(0,0,0,$month, $day_num, $year))."</td>";
$day_num++;
$day_count++;
} echo "</tr>";
$day_count = 1;
do {
echo "<tr><td nowrap class='cal_emp_name'>".$row_employees['emp_id']." - ".$row_employees['emp_lname'].", ".$row_employees['emp_fname']."</td>";
$emp_id = '';
$emp_id = mysql_real_escape_string($row_employees['emp_id']);
$time_off = mysql_query("SELECT to_request_start_date, to_request_end_date, to_request_id FROM to_request WHERE to_request_emp_id = '$emp_id'") or die(mysql_error());
$row_time_off = mysql_fetch_array($time_off);
$request_start = $row_time_off['to_request_start_date'];
$request_end = $row_time_off['to_request_end_date'];
//Sets the first day of the month to 1
$day_num = 1;
//count up the days, until we have done them all in the month
while ($day_num <= $days_in_month) {
$comp_date = strtotime($year . '-' . $month . '-' . $day_num);
$request_start_comp = strtotime($request_start);
$request_end_comp = strtotime($request_end);
$start = date('Y-m-j',strtotime($request_start));
$end = date('Y-m-j',strtotime($request_end));
if ($comp_date >= $request_start_comp && $comp_date <= $request_end_comp) {
echo "<td class='cal_day_current'>";
echo $day_num;
echo"</td>";
} else {
echo "<td class='cal_day'>";
echo $day_num; }
$day_num++;
$day_count++;
}
while ( $day_count >1 && $day_count <=7 )
{
echo "<td class='cal_day_blank'> </td>";
$day_count++;
}
echo "</tr>";
} while ($row_employees = mysql_fetch_array($employees));
mysql_data_seek($employees, 0);
echo "</table>";
$firstmonth++;
}
?>
</body>
</html>