Location: PHPKode > projects > ARBS > arbs-1.5.1.78/day.php
<?php
/*
 * ARBS - Advanced Resource Booking System
 * Copyright (C) 2005-2007 ITMC der TU Dortmund
 * Based on MRBS by Daniel Gardner <http://mrbs.sourceforge.net/>
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */


include_once("glob_inc.inc.php");
if(isset($_GET['room']))
	$room=(int)$_GET['room'];
$timetohighlight=(int)$_GET['timetohighlight'];

if(!isset($_GET['area']))
	$area=get_default_area();
else
	$area=(int)$_GET['area'];
# If we don't know the right date then use today:
if (!isset($_GET['day']) or !isset($_GET['month']) or !isset($_GET['year'])){
	$day   = date("d",time());
	$month = date("m",time());
	$year  = date("Y",time());
}
else {
# Make the date valid if day is more then number of days in month:
	$day=(int)$_GET['day'];
	$month=(int)$_GET['month'];
	$year=(int)$_GET['year'];
	while (!checkdate($month, $day, $year))
		$day--;
}



# print the page header
print_header($day, $month, $year, $area);

# Define the start and end of the day.
$am7=mktime($morningstarts,0,0,$month,$day,$year);
$pm7=mktime($eveningends,$eveningends_minutes,0,$month,$day,$year);


include "roomlist.php";

#y? are year, month and day of yesterday
#t? are year, month and day of tomorrow

$i= mktime(0,0,0,$month,$day-1,$year);
$yy = date("Y",$i);
$ym = date("m",$i);
$yd = date("d",$i);

$i= mktime(0,0,0,$month,$day+1,$year);
$ty = date("Y",$i);
$tm = date("m",$i);
$td = date("d",$i);

#Show current date

#We want to build an array containing all the data we want to show
#and then spit it out.

#Get all appointments for today in the area that we care about
#Note: The predicate clause 'start_time <= ...' is an equivalent but simpler
#form of the original which had 3 BETWEEN parts. It selects all entries which
#occur on or cross the current day.
$sql = "SELECT r.id, e.start_time, e.end_time, e.title, e.id, e.type
   FROM mrbs_entry as e left join mrbs_room as r on e.room_id=r.id
   WHERE area_id = $area
   AND start_time <= $pm7 AND end_time > $am7
   AND r.hidden='false'";
   
$res = sql_query($sql);
if (! $res)
	fatal_error(0, sql_error());
for ($i = 0; ($row = sql_row($res, $i)); $i++) {
	# Each row weve got here is an appointment.
	#Row[0] = Room ID
	#row[1] = start time
	#row[2] = end time
	#row[3] = short description
	#row[4] = id of this booking
	#row[5] = type (internal/external)

	# $today is a map of the screen that will be displayed
	# It looks like:
	#     $today[Room ID][Time][id]
	#                          [color]
	#                          [data]

	# 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[1], $resolution), $am7);
	$end_t = min(round_t_up($row[2], $resolution) - $resolution, $pm7);
	for ($t = $start_t; $t <= $end_t; $t += $resolution){
		$today[$row[0]][$t]["id"]    = $row[4];
		$today[$row[0]][$t]["color"] = $row[5];
		$today[$row[0]][$t]["data"]  = "";
	}

	# Show the name of the booker in the first segment that the booking
	# happens in, or at the start of the day if it started before today.
	if ($row[1] < $am7)
		$today[$row[0]][$am7]["data"] = $row[3];
	else
		$today[$row[0]][$start_t]["data"] = $row[3];
}

$sql = "select r.room_name, r.capacity, r.id from mrbs_room AS r LEFT JOIN mrbs_multicat AS m  ON r.ID=m.RID WHERE r.area_id=$area AND r.hidden='false'";
$res = sql_query($sql);

# It might be that there are no rooms defined for this area.
# If there are none then show an error and dont bother doing anything
# else
if (! $res)
	fatal_error(0, sql_error());
if (sql_count($res) == 0){
	echo "<h1>", _("The area / the category has no rooms"), "</h1>";
	sql_free($res);
}
else{
	echo "<h2 align=center>" . parseDate(strftime("%A %d %B %Y", $am7)) . "</h2>\n";

	if ( $pview != 1 ) {
		#Show Go to day before and after links
		if (empty($category)){
			echo "<table width=\"100%\"><tr><td><a href=\"day.php?year=$yy&month=$ym&day=$yd&area=$area\">&lt;&lt; " . _("Go to previous day") . "</a></td>
		      <td align=center><a href=\"day.php?area=$area\">" . _("Go to today") . "</a></td>
		      <td align=right><a href=\"day.php?year=$ty&month=$tm&day=$td&area=$area\">" . _("Go to next day") . " &gt;&gt;</a></td></tr></table>";
		}
		else{
			echo "<table width=\"100%\"><tr><td><a href=\"day.php?year=$yy&month=$ym&day=$yd&area=$area&category=$category\">&lt;&lt; " . _("Go to previous day") . "</a></td>
		      <td align=center><a href=\"day.php?area=$area&category=$category\">" . _("Go to today") . "</a></td>
		      <td align=right><a href=\"day.php?year=$ty&month=$tm&day=$td&area=$area&category=$category\">" . _("Go to next day") . " &gt;&gt;</a></td></tr></table>";
		}
	}

	#This is where we start displaying stuff
	echo "<table cellspacing=0 border=1 width=\"100%\">";
	echo "<tr><th width=\"1%\">$lang[time]</th>";

	$room_column_width = (int)(95 / sql_count($res));
	for ($i = 0; ($row = sql_row($res, $i)); $i++){
		echo "<th width=\"$room_column_width%\">" . htmlspecialchars($row[0]). "</th>";
		$rooms[] = $row[2];
		$room_capacity[$row[2]]=$row[1];
	}
	echo "</tr>\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="day.php?year=$year&month=$month&day=$day&area=$area&timetohighlight";

	# This is the main bit of the display
	# We loop through unixtime and then the rooms we just got

	for ($t = $am7; $t <= $pm7; $t += $resolution){
		# Show the time linked to the URL for highlighting that time
		echo "<tr>";
		tdcell("red");
		echo "<a href=\"$hilite_url=$t\">" . date("H:i",$t) . "</a></td>";

		# Loop through the list of rooms we have for this area
		while (list($key, $room) = each($rooms)){
			if(isset($today[$room][$t]["id"])){
				$id    = $today[$room][$t]["id"];
				$color = $today[$room][$t]["color"];
				$descr = htmlspecialchars($today[$room][$t]["data"]);
			}
			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 = "white";
			elseif (isset($timetohighlight) && ($t == $timetohighlight))
				$c = "red";
			else
				$c = "white";

#------------------------------------------------------------------------------------------------
#get the information we need
drawTimeTableColum($room,$room_capacity[$room],$t);		
}
		echo "</tr>\n";
		reset($rooms);
	}
	echo "</table>";
	if ( $pview != 1 )
		show_colour_key();
}
//get a room from this area for the trailer
$room = sql_query1("select min(id) from mrbs_room where area_id=$area && hidden='false'");
include("trailer.inc.php");

if($pview==0)echo "<p align=right><a href=day.php?year=",$year,"&month=",$month,"&day=",$day,"&area=",$area,"&room=",$room,"&pview=1>", _("Print view"), "</a></p>";
else
echo "<p align=right><a href=javascript:history.back()>", _("Back"), "</a></p>";
?>
Return current item: ARBS