Location: PHPKode > projects > ARBS > arbs-1.5.1.78/week.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.
 */


# mrbs/week.php - Week-at-a-time view

include_once("glob_inc.inc.php");

//delete old entrys
//DONT!
#sql_query("DELETE FROM `mrbs_entry` WHERE date_add( from_unixtime( timestamp ) ,  INTERVAL 60 minute )  < NOW(  )  && confirmed =0");
#

if(!isset($_GET['area']))
	$area=get_default_area();
else
	$area=(int)$_GET['area'];
$room=(int)$_GET['room'];
$timetohighlight=(int)$_GET['timetohighlight'];
# 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--;
}

# Set the date back to the previous $weekstarts day (Sunday, if 0):
$time = mktime(0, 0, 0, $month, $day, $year);
$weekday = (date("w", $time) - $weekstarts + 7) % 7;
if ($weekday > 0){
	$timeNew = $time - $weekday * 86400;
	$time=$timeNew;
	$day   = date("d", $timeNew);
	$month = date("m", $timeNew);
	$year  = date("Y", $timeNew);
}



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

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

# Start and end of week:
$week_midnight = mktime(0, 0, 0, $month, $day, $year);
$week_start = $am7;
$week_end = mktime($eveningends, $eveningends_minutes, 0, $month, $day+6, $year);

include "roomlist.php";

//this usually happens when the user changes the instance in another browser window or if the session was lost
if(!isset($room_capacity[$room])){
	echo _("This room couldn't be found."), "<br/>", $startpage;
	exit;
}


# Show area and room:
echo "<h2 align=center>$this_area_name - $this_room_name";
if($infolink!=""){
	echo " (<a target=_blank href=$infolink>", _("Info"), "</a>)";
}
echo "</h2>\n";

#show room comment if there is one
if($room_comment[$room]!=""){
	echo "<table align=center cellspacing=2 cellpadding=0 bgcolor=#ff0000><tr><td><table width=100% bgcolor=#ffffff cellspacing=0 cellpadding=4><tr><td>",$room_comment[$room],"</td></tr></table></td></tr></table>";
}

#y? are year, month and day of the previous week.
#t? are year, month and day of the next week.

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

$i= mktime(0,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 "<table width=\"100%\"><tr><td>
		<a href=\"week.php?year=$yy&month=$ym&day=$yd&area=$area&room=$room\">&lt;&lt; ",
		_("go to last week"),
		"</a></td><td align=center><a href=\"week.php?area=$area&room=$room\">",
		_("go to this week"),
		"</a></td><td align=right><a href=\"week.php?year=$ty&month=$tm&day=$td&area=$area&room=$room\">",
	  	_("go to next week"),
	  	"&gt;&gt;</a></td></tr></table>";
}


$first_slot = $morningstarts * 3600 / $resolution;
$last_slot = ($eveningends * 3600 + $eveningends_minutes * 60) / $resolution;

#This is where we start displaying stuff
echo "<table cellspacing=0 border=1 width=\"100%\">";

# The header row contains the weekday names and short dates.
echo "<tr><th width=\"1%\"><br>", _("Start time"), "</th>";
if (empty($dateformat))
	$dformat = "%a<br>%b %d";
else
	$dformat = "%a<br>%d %b";
for ($t = $week_start; $t < $week_end; $t += 86400)
	echo "<th width=\"14%\">" . parseDate(strftime($dformat, $t)) . "</th>\n";
echo "</tr>\n";


# This is the main bit of the display. Outer loop is for the time slots,
# inner loop is for days of the week.

# 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";

# $t is the date/time for the first day of the week (Sunday, if $weekstarts=0).
# $wt is for the weekday in the inner loop.
$wt=0;
$t = $am7;
for ($slot = $first_slot; $slot <= $last_slot; $slot++){
	# 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>";

	$wt = $t;

	# Color to use for empty cells: white, unless highlighting this row:
	if (isset($timetohighlight) && $timetohighlight == $t)
		$empty_color = "red";
	else
		$empty_color = "white";

	# See note above: weekday==0 is day $weekstarts, not necessarily Sunday.
	for ($weekday = 0; $weekday < 7; $weekday++){
		drawTimeTableColum($room,$room_capacity[$room],$wt);	
		$wt += 86400;#+one day in seconds
	}
	echo "</tr>\n";
	$t += $resolution;
}
echo "</table>";

if ( $pview != 1 )
	show_colour_key();
include("trailer.inc.php");
?>
Return current item: ARBS