Re: bookings in month view - Gavin W
John Beranek <john <at> redux.org.uk>
2005-02-04 19:58:10 GMT
webmaster <at> bytesquad.net wrote:
> Hi :)
>
> I have just joined this mailing list (newbie to mailing lists so please
> forgive me if I'm not following the correct etiquette)
>
> I got the script up and running okay, but I would like to add a
> functionality that I found in the archived messages at sourceforge ..
Here you go, I've attached all the files Gavin wrote...
John.
--
John Beranek To generalise is to be an idiot.
http://redux.org.uk/ -- William Blake
0)
{
$time -= $weekday * 86400;
$day = date("d", $time);
$month = date("m", $time);
$year = date("Y", $time);
}
if (empty($area))
$area = get_default_area();
if (empty($room))
$room = get_default_room($area);
# Note $room will be 0 if there are no rooms; this is checked for below.
# print the page header
print_header($day, $month, $year, $area);
$format = "Gi";
if( $enable_periods ) {
$format = "i";
$resolution = 60;
$morningstarts = 12;
$morningstarts_minutes = 0;
$eveningends = 12;
$eveningends_minutes = count($periods)-1;
}
# ensure that $morningstarts_minutes defaults to zero if not set
if( empty( $morningstarts_minutes ) )
$morningstarts_minutes=0;
# Define the start and end of each day of the week in a way which is not
# affected by daylight saving...
for ($j = 0; $j no change
# 0 => entering DST
# 1 => leaving DST
$dst_change[$j] = is_dst($month,$day+$j,$year);
$am7[$j]=mktime($morningstarts,$morningstarts_minutes,0,$month,$day+$j,$year,is_dst($month,$day+$j,$year,$morningstarts));
$pm7[$j]=mktime($eveningends,$eveningends_minutes,0,$month,$day+$j,$year,is_dst($month,$day+$j,$year,$eveningends));
}
if ( $pview != 1 ) {
# Table with areas, rooms, minicals.
echo "
";
$this_area_name = "";
$this_room_name = "";
# Show all areas
echo "".get_vocab("areas")." ";
}
# show either a select box or the normal html list
if ($area_list_format == "select") {
echo make_area_select_html('week.php', $area, $year, $month, $day); # from functions.inc
$this_area_name = sql_query1("select area_name from $tbl_area where id=$area");
$this_room_name = sql_query1("select room_name from $tbl_room where id=$room");
} else {
$sql = "select id, area_name from $tbl_area order by area_name";
$res = sql_query($sql);
if ($res) for ($i = 0; ($row = sql_row($res, $i)); $i++)
{
if ( $pview != 1 )
echo "";
if ($row[0] == $area)
{
$this_area_name = htmlspecialchars($row[1]);
if ( $pview != 1 )
echo "$this_area_name \n";
}
else if ( $pview != 1 ) echo htmlspecialchars($row[1]) . " \n";
}
} # end area display if
if ( $pview != 1) {
echo " | \n";
# Show all rooms in the current area
echo "
";
}
if ( $pview != 1 ) {
echo " | \n";
#Draw the three month calendars
minicals($year, $month, $day, $area, $room, 'week');
echo "
\n";
}
# Don't continue if this area has no rooms:
if ($room ".get_vocab("no_rooms_for_area")."";
include "trailer.inc";
exit;
}
# Show area and room:
echo "
$this_area_name
\n";
#y? are year, month and day of the previous week.
#t? are year, month and day of the next week.
$i= mktime(12,0,0,$month,$day-7,$year);
$yy = date("Y",$i);
$ym = date("m",$i);
$yd = date("d",$i);
$i= mktime(12,0,0,$month,$day+7,$year);
$ty = date("Y",$i);
$tm = date("m",$i);
$td = date("d",$i);
if ( $pview != 1 ) {
#Show Go to week before and after links
echo "
";
}
$whereclause = array();
$room_array = array();
$sql = "select id, room_name from $tbl_room where area_id=$area order by room_name";
$res = sql_query($sql);
if ($res) for ($i = 0; ($row = sql_row($res, $i)); $i++)
{
$room_array[$row[0]] = $row[1];
$whereclause[] = "room_id = ".$row[0];
}
#Get all appointments for this week in the room that we care about
# row[0] = Start time
# row[1] = End time
# row[2] = Entry type
# row[3] = Entry name (brief description)
# row[4] = Entry ID
# row[5] = Complete description
# This data will be retrieved day-by-day
for ($j = 0; $j $am7[$j]";
# Each row returned from the query is a meeting. Build an array of the
# form: d[weekday][slot][x], where x = id, color, data, long_desc.
# [slot] is based at 000 (HHMM) for midnight, but only slots within
# the hours of interest (morningstarts : eveningends) are filled in.
# [id], [data] and [long_desc] are only filled in when the meeting
# should be labeled, which is once for each meeting on each weekday.
# Note: weekday here is relative to the $weekstarts configuration variable.
# If 0, then weekday=0 means Sunday. If 1, weekday=0 means Monday.
if ($debug_flag) echo "
DEBUG: query=$sql\n";
$res = sql_query($sql);
if (! $res) echo sql_error();
else for ($i = 0; ($row = sql_row($res, $i)); $i++)
{
if ($debug_flag)
echo "
DEBUG: result $i, id $row[4], starts $row[0], ends $row[1]\n";
# $d is a map of the screen that will be displayed
# It looks like:
# $d[Day][Time][id]
# [color]
# [data]
# where Day is in the range 0 to $num_of_days.
# Fill in the map for this meeting. Start at the meeting start time,
# or the day start time, whichever is later. End one slot before the
# meeting end time (since the next slot is for meetings which start then),
# or at the last slot in the day, whichever is earlier.
# Note: int casts on database rows for max may be needed for PHP3.
# Adjust the starting and ending times so that bookings which don't
# start or end at a recognized time still appear.
$start_t = max(round_t_down($row[0], $resolution, $am7[$j]), $am7[$j]);
$end_t = min(round_t_up($row[1], $resolution, $am7[$j]) - $resolution, $pm7[$j]);
for ($t = $start_t; $t DEBUG:\n";
echo "\$dst_change = ";
print_r( $dst_change );
print "\n";
print "\$am7 =\n";
foreach( $am7 as $am7_val)
print "$am7_val - " . date("r", $am7_val) . "\n";
print "\$pm7 =\n";
foreach( $pm7 as $pm7_val)
print "$pm7_val - " . date("r", $pm7_val) . "\n";
echo "
\$d =\n";
if (gettype($d) == "array")
while (list($w_k, $w_v) = each($d))
while (list($t_k, $t_v) = each($w_v))
while (list($k_k, $k_v) = each($t_v))
echo "d[$w_k][$t_k][$k_k] = '$k_v'\n";
else echo "d is not an array!\n";
echo "
\n";
}
// Include the active cell content management routines.
// Must be included before the beginnning of the main table.
if ($javascript_cursor) // If authorized in config.inc.php, include the javascript cursor management.
{
echo "\n";
echo "\n";
}
# URL for highlighting a time. Don't use REQUEST_URI or you will get
# the timetohighlight parameter duplicated each time you click.
$hilite_url="week_area.php?year=$year&month=$month&day=$day&area=$area&room=$room&timetohighlight";
#This is where we start displaying stuff
echo "
";
# The header row contains the weekday names and short dates.
echo " ".($enable_periods ? get_vocab("period") : get_vocab("time"))."";
if (empty($dateformat))
$dformat = "%a
%b %d";
else
$dformat = "%a
%d %b";
for (
$t = mktime($morningstarts, $morningstarts_minutes, 0, $month, $day+$j, $year);
$t "
. $periods[$time_t_stripped] . "";
} else {
echo ""
. utf8_date(hour_min_format(),$t) . "";
}
}
# next line to display times on right side
if ( FALSE != $times_right_side )
{
echo ""
. ( $enable_periods ? get_vocab("period") : get_vocab("time") )
. " ";
}
echo "
\n";
# This is the main bit of the display. Outer loop is for the time slots,
# inner loop is for days of the week.
# if the first day of the week to be displayed contains as DST change then
# move to the next day to get the hours in the day.
( $dst_change[0] != -1 ) ? $j = 1 : $j = 0;
$row_class = "even_row";
for ($thisday = 0; $thisday $room_name )
{
echo "";
tdcell("red");
echo $room_name ."";
if( $first_room )
{
tdcell("red", count($room_array));
$td = mktime( 12, 0, 0, $month, $day+$thisday, $year);
echo "" .
utf8_strftime($dformat, $td) . "\n";
}
# Color to use for empty cells: white, unless highlighting this row:
if (isset($timetohighlight) && $timetohighlight == $time_t)
$empty_color = "red";
else
$empty_color = "white";
# See note above: weekday==0 is day $weekstarts, not necessarily Sunday.
for (
$t = mktime($morningstarts, $morningstarts_minutes, 0, $month, $day+$j, $year);
$t \n\n";
}
echo "";
if( $enable_periods ) {
echo "";
} else {
echo "";
}
echo "";
if ($javascript_cursor)
{
echo "";
}
} else
echo ' ';
}
elseif ($descr != "")
{
#if it is booked then show
echo " $descr";
}
else
echo " \" ";
echo "\n";
}
# next lines to display times on right side
if ( FALSE != $times_right_side )
{
if( $first_room )
{
tdcell("red", count($room_array));
$td = mktime( 12, 0, 0, $month, $day+$thisday, $year);
echo "" .
utf8_strftime($dformat, $td) . "\n";
}
tdcell("red");
echo $room_name ."";
}
$first_room = 0;
echo "
\n";
}
}
echo " ".($enable_periods ? get_vocab("period") : get_vocab("time"))."";
if (empty($dateformat))
$dformat = "%a
%b %d";
else
$dformat = "%a
%d %b";
for (
$t = mktime($morningstarts, $morningstarts_minutes, 0, $month, $day+$j, $year);
$t "
. $periods[$time_t_stripped] . "";
} else {
echo ""
. utf8_date(hour_min_format(),$t) . "";
}
}
echo "
";
show_colour_key();
include "trailer.inc";
?>
0)
{
$time -= $weekday * 86400;
$day = date("d", $time);
$month = date("m", $time);
$year = date("Y", $time);
}
if (empty($area))
$area = get_default_area();
if (empty($room))
$room = get_default_room($area);
# Note $room will be 0 if there are no rooms; this is checked for below.
# print the page header
print_header($day, $month, $year, $area);
$format = "Gi";
if( $enable_periods ) {
$format = "i";
$resolution = 60;
$morningstarts = 12;
$morningstarts_minutes = 0;
$eveningends = 12;
$eveningends_minutes = count($periods)-1;
}
# ensure that $morningstarts_minutes defaults to zero if not set
if( empty( $morningstarts_minutes ) )
$morningstarts_minutes=0;
# Define the start and end of each day of the week in a way which is not
# affected by daylight saving...
for ($j = 0; $j no change
# 0 => entering DST
# 1 => leaving DST
$dst_change[$j] = is_dst($month,$day+$j,$year);
$am7[$j]=mktime($morningstarts,$morningstarts_minutes,0,$month,$day+$j,$year,is_dst($month,$day+$j,$year,$morningstarts));
$pm7[$j]=mktime($eveningends,$eveningends_minutes,0,$month,$day+$j,$year,is_dst($month,$day+$j,$year,$eveningends));
}
if ( $pview != 1 ) {
# Table with areas, rooms, minicals.
echo "
";
$this_area_name = "";
$this_room_name = "";
# Show all areas
echo "".get_vocab("areas")." ";
}
# show either a select box or the normal html list
if ($area_list_format == "select") {
echo make_area_select_html('week.php', $area, $year, $month, $day); # from functions.inc
$this_area_name = sql_query1("select area_name from $tbl_area where id=$area");
$this_room_name = sql_query1("select room_name from $tbl_room where id=$room");
} else {
$sql = "select id, area_name from $tbl_area order by area_name";
$res = sql_query($sql);
if ($res) for ($i = 0; ($row = sql_row($res, $i)); $i++)
{
if ( $pview != 1 )
echo "";
if ($row[0] == $area)
{
$this_area_name = htmlspecialchars($row[1]);
if ( $pview != 1 )
echo "$this_area_name \n";
}
else if ( $pview != 1 ) echo htmlspecialchars($row[1]) . " \n";
}
} # end area display if
if ( $pview != 1) {
echo " | \n";
# Show all rooms in the current area
echo "
";
}
if ( $pview != 1 ) {
echo " | \n";
#Draw the three month calendars
minicals($year, $month, $day, $area, $room, 'week');
echo "
\n";
}
# Don't continue if this area has no rooms:
if ($room ".get_vocab("no_rooms_for_area")."";
include "trailer.inc";
exit;
}
# Show area and room:
echo "
$this_area_name
\n";
#y? are year, month and day of the previous week.
#t? are year, month and day of the next week.
$i= mktime(12,0,0,$month,$day-7,$year);
$yy = date("Y",$i);
$ym = date("m",$i);
$yd = date("d",$i);
$i= mktime(12,0,0,$month,$day+7,$year);
$ty = date("Y",$i);
$tm = date("m",$i);
$td = date("d",$i);
if ( $pview != 1 ) {
#Show Go to week before and after links
echo "
";
}
$whereclause = array();
$room_array = array();
$sql = "select id, room_name from $tbl_room where area_id=$area order by room_name";
$res = sql_query($sql);
if ($res) for ($i = 0; ($row = sql_row($res, $i)); $i++)
{
$room_array[$row[0]] = $row[1];
$whereclause[] = "room_id = ".$row[0];
}
#Get all appointments for this week in the room that we care about
# row[0] = Start time
# row[1] = End time
# row[2] = Entry type
# row[3] = Entry name (brief description)
# row[4] = Entry ID
# row[5] = Complete description
# This data will be retrieved day-by-day
for ($j = 0; $j $am7[$j]";
# Each row returned from the query is a meeting. Build an array of the
# form: d[weekday][slot][x], where x = id, color, data, long_desc.
# [slot] is based at 000 (HHMM) for midnight, but only slots within
# the hours of interest (morningstarts : eveningends) are filled in.
# [id], [data] and [long_desc] are only filled in when the meeting
# should be labeled, which is once for each meeting on each weekday.
# Note: weekday here is relative to the $weekstarts configuration variable.
# If 0, then weekday=0 means Sunday. If 1, weekday=0 means Monday.
if ($debug_flag) echo "
DEBUG: query=$sql\n";
$res = sql_query($sql);
if (! $res) echo sql_error();
else for ($i = 0; ($row = sql_row($res, $i)); $i++)
{
if ($debug_flag)
echo "
DEBUG: result $i, id $row[4], starts $row[0], ends $row[1] called $row[3]\n";
# $d is a map of the screen that will be displayed
# It looks like:
# $d[Day][Time][id]
# [color]
# [data]
# where Day is in the range 0 to $num_of_days.
# Fill in the map for this meeting. Start at the meeting start time,
# or the day start time, whichever is later. End one slot before the
# meeting end time (since the next slot is for meetings which start then),
# or at the last slot in the day, whichever is earlier.
# Note: int casts on database rows for max may be needed for PHP3.
# Adjust the starting and ending times so that bookings which don't
# start or end at a recognized time still appear.
$start_t = max(round_t_down($row[0], $resolution, $am7[$j]), $am7[$j]);
$end_t = min(round_t_up($row[1], $resolution, $am7[$j]) - $resolution, $pm7[$j]);
for ($t = $start_t; $t DEBUG:\n";
echo "\$dst_change = ";
print_r( $dst_change );
print "\n";
print "\$am7 =\n";
foreach( $am7 as $am7_val)
print "$am7_val - " . date("r", $am7_val) . "\n";
print "\$pm7 =\n";
foreach( $pm7 as $pm7_val)
print "$pm7_val - " . date("r", $pm7_val) . "\n";
echo "
\$d =\n";
if (gettype($d) == "array")
while (list($w_k, $w_v) = each($d))
while (list($r_k, $r_v) = each($w_v))
while (list($t_k, $t_v) = each($r_v))
while (list($k_k, $k_v) = each($t_v))
echo "d[$w_k][$r_k][$t_k][$k_k] = '$k_v'\n";
else echo "d is not an array!\n";
echo "
\n";
}
// Include the active cell content management routines.
// Must be included before the beginnning of the main table.
if ($javascript_cursor) // If authorized in config.inc.php, include the javascript cursor management.
{
echo "\n";
echo "\n";
}
# URL for highlighting a time. Don't use REQUEST_URI or you will get
# the timetohighlight parameter duplicated each time you click.
$hilite_url="week.php?year=$year&month=$month&day=$day&area=$area&room=$room&timetohighlight";
#This is where we start displaying stuff
echo "
";
# The header row contains the weekday names and short dates.
echo "".($enable_periods ? get_vocab("period") : get_vocab("time"))."";
if (empty($dateformat))
$dformat = "%a %b %d";
else
$dformat = "%a %d %b";
$room_column_width = (int)(95 / count($room_array));
foreach( $room_array as $key => $value )
{
echo "
"
. htmlspecialchars($value) . "";
}
# next line to display times on right side
if ( FALSE != $times_right_side )
{
echo ""
. ( $enable_periods ? get_vocab("period") : get_vocab("time") )
. "";
}
echo "
\n";
# This is the main bit of the display. Outer loop is for the time slots,
# inner loop is for days of the week.
# if the first day of the week to be displayed contains as DST change then
# move to the next day to get the hours in the day.
( $dst_change[0] != -1 ) ? $j = 1 : $j = 0;
$row_class = "even_row";
for ($thisday = 0; $thisday";
tdcell("red", 1, (count($room_array) + ($times_right_side ? 2 : 1)));
$td = mktime( 12, 0, 0, $month, $day+$thisday, $year);
echo "" .
utf8_strftime($dformat, $td) . "\n";
echo "";
for (
$t = mktime($morningstarts, $morningstarts_minutes, 0, $month, $day+$j, $year);
$t ";
tdcell("red");
if( $enable_periods ){
$time_t_stripped = preg_replace( "/^0/", "", $time_t );
echo ""
. $periods[$time_t_stripped] . "";
} else {
echo ""
. utf8_date(hour_min_format(),$t) . "";
}
# Color to use for empty cells: white, unless highlighting this row:
if (isset($timetohighlight) && $timetohighlight == $time_t)
$empty_color = "red";
else
$empty_color = "white";
# See note above: weekday==0 is day $weekstarts, not necessarily Sunday.
# use hour:minute format
foreach( $room_array as $room_id => $room_name )
{
$time_t = date($format, $t);
# Three cases:
# color: id: Slot is: Color: Link to:
# ----- ----- -------- --------- -----------------------
# unset - empty white,red add new entry
# set unset used by type none (unlabelled slot)
# set set used by type view entry
$wt = mktime( 12, 0, 0, $month, $day+$thisday, $year );
$wday = date("d", $wt);
$wmonth = date("m", $wt);
$wyear = date("Y", $wt);
if(isset($d[$thisday][$room_id][$time_t]["id"]))
{
$id = $d[$thisday][$room_id][$time_t]["id"];
$color = $d[$thisday][$room_id][$time_t]["color"];
$descr = htmlspecialchars($d[$thisday][$room_id][$time_t]["data"]);
$long_descr = htmlspecialchars($d[$thisday][$room_id][$time_t]["long_descr"]);
}
else
unset($id);
# $c is the colour of the cell that the browser sees. White normally,
# red if were hightlighting that line and a nice attractive green if the room is booked.
# We tell if its booked by $id having something in it
if (isset($id))
$c = $color;
elseif (isset($timetohighlight) && ($time_t == $timetohighlight))
$c = "red";
else
$c = $row_class;
tdcell($c);
# If the room isnt booked then allow it to be booked
if(!isset($id))
{
$hour = date("H",$t);
$minute = date("i",$t);
if ( $pview != 1 ) {
if ($javascript_cursor)
{
echo "";
}
echo "";
if( $enable_periods ) {
echo "";
} else {
echo "";
}
echo "";
if ($javascript_cursor)
{
echo "";
}
} else
echo ' ';
}
elseif ($descr != "")
{
#if it is booked then show
echo " $descr";
}
else
echo " \" ";
echo "\n";
}
# next lines to display times on right side
if ( FALSE != $times_right_side )
{
tdcell("red");
if( $enable_periods ){
$time_t_stripped = preg_replace( "/^0/", "", $time_t );
echo ""
. $periods[$time_t_stripped] . "";
} else {
echo ""
. utf8_date(hour_min_format(),$t) . "";
}
}
echo "\n";
}
}
echo "".($enable_periods ? get_vocab("period") : get_vocab("time"))."";
foreach( $room_array as $key => $value )
{
echo "
"
. htmlspecialchars($value) . "";
}
# next line to display times on right side
if ( FALSE != $times_right_side )
{
echo ""
. ( $enable_periods ? get_vocab("period") : get_vocab("time") )
. "";
}
echo "
\n";
echo "
";
show_colour_key();
include "trailer.inc";
?>
= 60)
{
$dur /= 60;
if($dur >= 60)
{
$dur /= 60;
if(($dur >= 24) && ($dur % 24 == 0))
{
$dur /= 24;
if(($dur >= 7) && ($dur % 7 == 0))
{
$dur /= 7;
if(($dur >= 52) && ($dur % 52 == 0))
{
$dur /= 52;
$units = get_vocab("years");
}
else
$units = get_vocab("weeks");
}
else
$units = get_vocab("days");
}
else
$units = get_vocab("hours");
}
else
$units = get_vocab("minutes");
}
else
$units = get_vocab("seconds");
}
function toPeriodString($start_period, &$dur, &$units)
{
global $enable_periods;
global $periods;
$max_periods = count($periods);
$dur /= 60;
if( $dur >= $max_periods || $start_period == 0 )
{
if( $start_period == 0 && $dur == $max_periods )
{
$units = get_vocab("days");
$dur = 1;
return;
}
$dur /= 60;
if(($dur >= 24) && is_int($dur))
{
$dur /= 24;
$units = get_vocab("days");
return;
}
else
{
$dur *= 60;
$dur = ($dur % $max_periods) + floor( $dur/(24*60) ) * $max_periods;
$units = get_vocab("periods");
return;
}
}
else
$units = get_vocab("periods");
}
function genDateSelector($prefix, $day, $month, $year)
{
if($day == 0) $day = date("d");
if($month == 0) $month = date("m");
if($year == 0) $year = date("Y");
echo "\n";
for($i = 1; $i $i\n";
echo "";
echo "\n";
for($i = 1; $i $m\n";
}
echo "";
echo "\n";
$min = min($year, date("Y")) - 5;
$max = max($year, date("Y")) + 5;
for($i = $min; $i $i\n";
echo "";
}
# Error handler - this is used to display serious errors such as database
# errors without sending incomplete HTML pages. This is only used for
# errors which "should never happen", not those caused by bad inputs.
# If $need_header!=0 output the top of the page too, else assume the
# caller did that. Alway outputs the bottom of the page and exits.
function fatal_error($need_header, $message)
{
if ($need_header) print_header(0, 0, 0, 0);
echo $message;
include "trailer.inc";
exit;
}
# Apply backslash-escape quoting unless PHP is configured to do it
# automatically. Use this for GET/POST form parameters, since we
# cannot predict if the PHP configuration file has magic_quotes_gpc on.
function slashes($s)
{
if (get_magic_quotes_gpc()) return $s;
else return addslashes($s);
}
# Remove backslash-escape quoting if PHP is configured to do it with
# magic_quotes_gpc. Use this whenever you need the actual value of a GET/POST
# form parameter (which might have special characters) regardless of PHP's
# magic_quotes_gpc setting.
function unslashes($s)
{
if (get_magic_quotes_gpc()) return stripslashes($s);
else return $s;
}
# Return a default area; used if no area is already known. This returns the
# lowest area ID in the database (no guaranty there is an area 1).
# This could be changed to implement something like per-user defaults.
function get_default_area()
{
global $tbl_area;
$area = sql_query1("SELECT id FROM $tbl_area ORDER BY area_name LIMIT 1");
return ($area = count($periods) - 1 ) $p_num = count($periods ) - 1;
# I have made the separater a ',' as a '-' leads to an ambiguious
# display in report.php when showing end times.
return array($p_num, $periods[$p_num] . utf8_strftime(", %A %d %B %Y",$t));
}
function period_time_string($t, $mod_time=0)
{
global $periods;
$time = getdate($t);
$p_num = $time["minutes"] + $mod_time;
if( $p_num = count($periods) - 1 ) $p_num = count($periods ) - 1;
return $periods[$p_num];
}
function time_date_string($t)
{
global $twentyfourhour_format;
# This bit's necessary, because it seems %p in strftime format
# strings doesn't work
$ampm = utf8_date("a",$t);
if ($twentyfourhour_format)
{
return utf8_strftime("%H:%M:%S - %A %d %B %Y",$t);
}
else
{
return utf8_strftime("%I:%M:%S$ampm - %A %d %B %Y",$t);
}
}
# Output a start table cell tag
with color class and fallback color.
# $colclass is an entry type (A-J), "white" for empty, or "red" for highlighted.
# The colors for CSS browsers can be found in the style sheet. The colors
# in the array below are fallback for non-CSS browsers only.
function tdcell($colclass, $rowspan=NULL, $colspan=NULL)
{
$output = "";
# This should be 'static $ecolors = array(...)' but that crashes PHP3.0.12!
static $ecolors;
if (!isset($ecolors)) $ecolors = array("A"=>"#FFCCFF", "B"=>"#99CCCC",
"C"=>"#FF9999", "D"=>"#FFFF99", "E"=>"#C0E0FF", "F"=>"#FFCC99",
"G"=>"#FF6666", "H"=>"#66FFFF", "I"=>"#DDFFDD", "J"=>"#CCCCCC",
"red"=>"#FFF0F0", "white"=>"#FFFFFF");
if (isset($ecolors[$colclass]))
$output = " |
";
}
# Display the entry-type color key. This has up to 2 rows, up to 5 columns.
function show_colour_key()
{
global $typel;
echo "
\n";
$nct = 0;
for ($ct = "A"; $ct 5)
{
$nct = 0;
echo "
";
}
tdcell($ct);
echo "$typel[$ct]\n";
}
}
echo "
\n";
}
# Round time down to the nearest resolution
function round_t_down($t, $resolution, $am7)
{
return (int)$t - (int)abs(((int)$t-(int)$am7)
% $resolution);
}
# Round time up to the nearest resolution
function round_t_up($t, $resolution, $am7)
{
if (($t-$am7) % $resolution != 0)
{
return $t + $resolution - abs(((int)$t-(int)
$am7) % $resolution);
}
else
{
return $t;
}
}
# generates some html that can be used to select which area should be
# displayed.
function make_area_select_html( $link, $current, $year, $month, $day )
{
global $tbl_area;
$out_html = "
\n";
return $out_html;
} # end make_area_select_html
function make_room_select_html( $link, $area, $current, $year, $month, $day )
{
global $tbl_room;
$out_html = "
\n";
return $out_html;
} # end make_area_select_html
# This will return the appropriate value for isdst for mktime().
# The order of the arguments was chosen to match those of mktime.
# hour is added so that this function can when necessary only be
# run if the time is between midnight and 3am (all DST changes
# occur in this period.
function is_dst ( $month, $day, $year, $hour="-1" )
{
if( $hour != -1 && $hour > 3)
return( -1 );
# entering DST
if( !date( "I", mktime(12, 0, 0, $month, $day-1, $year)) &&
date( "I", mktime(12, 0, 0, $month, $day, $year)))
return( 0 );
# leaving DST
elseif( date( "I", mktime(12, 0, 0, $month, $day-1, $year)) &&
!date( "I", mktime(12, 0, 0, $month, $day, $year)))
return( 1 );
else
return( -1 );
}
# if crossing dst determine if you need to make a modification
# of 3600 seconds (1 hour) in either direction
function cross_dst ( $start, $end )
{
# entering DST
if( !date( "I", $start) && date( "I", $end))
$modification = -3600;
# leaving DST
elseif( date( "I", $start) && !date( "I", $end))
$modification = 3600;
else
$modification = 0;
return $modification;
}
?> |
".
function cmp3($a, $b)
{
if ($a ";
}
# Default parameters:
if (empty($debug_flag)) $debug_flag = 0;
if (empty($month) || empty($year) || !checkdate($month, 1, $year))
{
$month = date("m");
$year = date("Y");
}
$day = 1;
# print the page header
print_header($day, $month, $year, $area);
if (empty($area))
$area = get_default_area();
if (empty($room))
$room = get_default_room($area);
# Note $room will be 0 if there are no rooms; this is checked for below.
# Month view start time. This ignores morningstarts/eveningends because it
# doesn't make sense to not show all entries for the day, and it messes
# things up when entries cross midnight.
$month_start = mktime(0, 0, 0, $month, 1, $year);
# What column the month starts in: 0 means $weekstarts weekday.
$weekday_start = (date("w", $month_start) - $weekstarts + 7) % 7;
$days_in_month = date("t", $month_start);
$month_end = mktime(23, 59, 59, $month, $days_in_month, $year);
if( $enable_periods ) {
$resolution = 60;
$morningstarts = 12;
$eveningends = 12;
$eveningends_minutes = count($periods)-1;
}
# Define the start and end of each day of the month in a way which is not
# affected by daylight saving...
for ($j = 1; $j no change
# 0 => entering DST
# 1 => leaving DST
$dst_change[$j] = is_dst($month,$j,$year);
if(empty( $enable_periods )){
$midnight[$j]=mktime(0,0,0,$month,$j,$year, is_dst($month,$j,$year, 0));
$midnight_tonight[$j]=mktime(23,59,59,$month,$j,$year, is_dst($month,$j,$year, 23));
}
else {
$midnight[$j]=mktime(12,0,0,$month,$j,$year, is_dst($month,$j,$year, 0));
$midnight_tonight[$j]=mktime(12,count($periods),59,$month,$j,$year, is_dst($month,$j,$year, 23));
}
}
if ( $pview != 1 ) {
# Table with areas, rooms, minicals.
echo "
";
$this_area_name = "";
$this_room_name = "";
# Show all areas
echo "".get_vocab("areas")." ";
}
# show either a select box or the normal html list
if ($area_list_format == "select") {
echo make_area_select_html('month.php', $area, $year, $month, $day); # from functions.inc
$this_area_name = sql_query1("select area_name from $tbl_area where id=$area");
$this_room_name = sql_query1("select room_name from $tbl_room where id=$room");
} else {
$sql = "select id, area_name from $tbl_area order by area_name";
$res = sql_query($sql);
if ($res) for ($i = 0; ($row = sql_row($res, $i)); $i++)
{
if ( $pview != 1 )
echo "";
if ($row[0] == $area)
{
$this_area_name = htmlspecialchars($row[1]);
if ( $pview != 1 )
echo "$this_area_name \n";
}
else if ( $pview !=1 ) echo htmlspecialchars($row[1]) . " \n";
}
} # end select if
if ( $pview != 1 ) {
echo " | \n";
# Show all rooms in the current area:
echo "
";
}
if ( $pview != 1 ) {
echo " | \n";
#Draw the three month calendars
minicals($year, $month, $day, $area, $room, 'month');
echo "
\n";
}
# Don't continue if this area has no rooms:
if ($room ".get_vocab("no_rooms_for_area")."";
include "trailer.inc";
exit;
}
# Show Month, Year, Area, Room header:
echo "
" . utf8_strftime("%B %Y", $month_start)
. " - $this_area_name
\n";
# Show Go to month before and after links
#y? are year and month of the previous month.
#t? are year and month of the next month.
$i= mktime(12,0,0,$month-1,1,$year);
$yy = date("Y",$i);
$ym = date("n",$i);
$i= mktime(12,0,0,$month+1,1,$year);
$ty = date("Y",$i);
$tm = date("n",$i);
if ( $pview != 1 ) {
echo "
";
}
if ($debug_flag)
echo "
DEBUG: month=$month year=$year start=$weekday_start range=$month_start:$month_end\n";
# Used below: localized "all day" text but with non-breaking spaces:
$all_day = ereg_replace(" ", " ", get_vocab("all_day"));
$whereclause = array();
$room_array = array();
$sql = "select id, room_name from $tbl_room where area_id=$area order by room_name";
$res = sql_query($sql);
if ($res) for ($i = 0; ($row = sql_row($res, $i)); $i++)
{
$room_array[$row[0]] = $row[1];
$whereclause[] = "room_id = ".$row[0];
}
#Get all meetings for this month in the room that we care about
# row[0] = Start time
# row[1] = End time
# row[2] = Entry ID
# This data will be retrieved day-by-day fo the whole month
for ($day_num = 1; $day_num $midnight[$day_num]
AND $tbl_room.id = $tbl_entry.room_id
ORDER by room_name, start_time";
# Build an array of information about each day in the month.
# The information is stored as:
# d[monthday]["id"][] = ID of each entry, for linking.
# d[monthday]["data"][] = "start-stop" times or "name" of each entry.
$res = sql_query($sql);
if (! $res) echo sql_error();
else for ($i = 0; ($row = sql_row($res, $i)); $i++)
{
if ($debug_flag)
echo "
DEBUG: result $i, id $row[2], starts $row[0], ends $row[1]\n";
if ($debug_flag) echo "
DEBUG: Entry $row[2] day $day_num\n";
$d[$day_num]["id"][] = $row[2];
$d[$day_num]["room_id"][] = $row[4];
$d[$day_num]["shortdescrip"][] = $row[3];
# Describe the start and end time, accounting for "all day"
# and for entries starting before/ending after today.
# There are 9 cases, for start time midnight this morning,
# and end time midnight tonight.
# Use ~ (not -) to separate the start and stop times, because MSIE
# will incorrectly line break after a -.
if(empty( $enable_periods ) ){
switch (cmp3($row[0], $midnight[$day_num]) . cmp3($row[1], $midnight_tonight[$day_num] + 1))
{
case "> = ": # Starts after midnight, ends at midnight
$d[$day_num]["data"][] = date(hour_min_format(), $row[0]) . "~24:00";
break;
case "> > ": # Starts after midnight, continues tomorrow
$d[$day_num]["data"][] = date(hour_min_format(), $row[0]) . "~====>";
break;
case "= = ": # Starts at midnight, ends at midnight
$d[$day_num]["data"][] = $all_day;
break;
case "= > ": # Starts at midnight, continues tomorrow
$d[$day_num]["data"][] = $all_day . "====>";
break;
case " ": # Starts before today, continues tomorrow
$d[$day_num]["data"][] = "<====" . $all_day . "====>";
break;
}
}
else
{
$start_str = ereg_replace(" ", " ", period_time_string($row[0]));
$end_str = ereg_replace(" ", " ", period_time_string($row[1], -1));
switch (cmp3($row[0], $midnight[$day_num]) . cmp3($row[1], $midnight_tonight[$day_num] + 1))
{
case "> = ": # Starts after midnight, ends at midnight
$d[$day_num]["data"][] = $start_str . "~24:00";
break;
case "> > ": # Starts after midnight, continues tomorrow
$d[$day_num]["data"][] = $start_str . "~====>";
break;
case "= = ": # Starts at midnight, ends at midnight
$d[$day_num]["data"][] = $all_day;
break;
case "= > ": # Starts at midnight, continues tomorrow
$d[$day_num]["data"][] = $all_day . "====>";
break;
case " ": # Starts before today, continues tomorrow
$d[$day_num]["data"][] = "<====" . $all_day . "====>";
break;
}
}
}
}
if ($debug_flag)
{
echo "
DEBUG: Array of month day data:
\n";
for ($i = 1; $i \n";
}
// Include the active cell content management routines.
// Must be included before the beginnning of the main table.
if ($javascript_cursor) // If authorized in config.inc.php, include the javascript cursor management.
{
echo "\n";
echo "\n";
}
echo "
\n";
# Weekday name header row:
for ($weekcol = 0; $weekcol " . day_name(($weekcol + $weekstarts)%7) . "";
}
echo "
\n";
# Skip days in week before start of month:
for ($weekcol = 0; $weekcol \n";
}
# Draw the days of the month:
for ($cday = 1; $cday
\n";
echo "
";
# Anything to display for this day?
if (isset($d[$cday]["id"][0]))
{
echo "
| ";
$room = -1;
$entries_rm_day = 0;
$n = count($d[$cday]["id"]);
# Show the start/stop times, 2 per line, linked to view_entry.
# If there are 12 or fewer, show them, else show 11 and "...".
for ($i = 0; $i ";
if ( $pview != 1 ) {
if ($javascript_cursor)
{
echo "";
}
if( $enable_periods ) {
echo "";
} else {
echo "";
}
if ($javascript_cursor)
{
echo "";
}
}
else
echo ' ';
echo " |
";
}
if( $room != $d[$cday]["room_id"][$i] )
{
echo $room_array[$d[$cday]["room_id"][$i]];
$entries_rm_day = 0;
}
$entries_rm_day++;
echo "";
if ( ($entries_rm_day == 13 && $monthly_view_entries_details != "both") or
($entries_rm_day == 7 && $monthly_view_entries_details == "both") )
{
echo " ...\n";
}
if ( ($entries_rm_day >= 13 && $room == $d[$cday]["room_id"][$i]) or
($entries_rm_day >= 7 && $room == $d[$cday]["room_id"][$i]) )
{
continue;
}
if ( ($entries_rm_day > 0 && $entries_rm_day % 2 == 0) or
($monthly_view_entries_details == "both" && $entries_rm_day > 0) )
{
echo " ";
}
else
{
echo " ";
}
$room = $d[$cday]["room_id"][$i];
switch ($monthly_view_entries_details)
{
case "description":
{
echo ""
. substr($d[$cday]["shortdescrip"][$i], 0, 17)
. "";
break;
}
case "slot":
{
echo ""
. $d[$cday]["data"][$i] . "";
break;
}
case "both":
{
echo ""
. $d[$cday]["data"][$i] . " "
. substr($d[$cday]["shortdescrip"][$i], 0, 6) . "";
break;
}
default:
{
echo "error: unknown parameter";
}
}
echo "";
}
echo " ";
if ( $pview != 1 ) {
if ($javascript_cursor)
{
echo "";
}
if( $enable_periods ) {
echo "";
} else {
echo "";
}
if ($javascript_cursor)
{
echo "";
}
}
else
echo ' ';
echo " |
| \n";
}
if (++$weekcol == 7) $weekcol = 0;
}
# Skip from end of month to end of week:
if ($weekcol > 0) for (; $weekcol \n";
}
echo "
";
# Weekday name header row:
for ($weekcol = 0; $weekcol " . day_name(($weekcol + $weekstarts)%7) . "";
}
echo "
\n";
include "trailer.inc";
?>