Location: PHPKode > projects > Online Resource Management system > storms/user/user_edit_room_booking.php
<?php
/*******************************************
 *   Edit Room Booking
 *   maintained by: Wing Sin
 *   Create Date: 14 Mar 20001
 *   Last Update: 6 May 2001
 *   Input: Room Booking data
 *   Output: Nil
 *   Purpose: Used to Edit Room Booking data
 ******************************************/

include("../includes/session_mysql.inc");
include("../includes/global-vars.inc");
include("../includes/command.php");
	
session_start();
session_register("user_class");
session_register("username");
session_register("name");
session_register("lang");

include("$lang.inc");

mysql_connect($dbhost, $dbuser, $dbpasswd);
	
?>
<html>
<head>
<title><?php print $msg_room_booking_edit_title; ?></title>
<?php print $doc_encoding; ?>
<link rel="stylesheet" href="../style_<?php print $lang; ?>.css" type="text/css">
</head>
<SCRIPT LANGUAGE="JavaScript">
function isValidText(the_text, msg)
{
	if (the_text=="")
	{
		alert(msg);
		return false;
	}
	else
		return true;
}

function frmChk(me)
{
	if ((!isValidText(me.in_class.value, "<?php print $msg_room_booking_add_error_class; ?>")))
		return false
	else
		return true
}
</script>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" bottommargin="0" rightmargin="0">
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
		<td width="160" bgcolor="#FFFFFF" valign="top"> 
<?php include("menu.inc"); ?>
		</td>
		<td valign="top">
		<!--- Beginning of Edit Room Booking Code --->
		<h3 class="heading"><?php print $msg_room_booking_edit_title; ?></h3>
		<span class="text10point">User Account: </span>
		<span class="text10pointbold"><?php print $username ?></span>
		<br>
<?php
if (!isset($action))
{
	if (!isset($in_bookingID))
	{
		on_error(10);
		exit;
	}
	// Call the room booking record
	$query_booking = "SELECT bookings.room_bookingID, bookings.roomID, rooms.room_code, bookings.class, bookings.room_booking_desc, bookings.userID, bookings.room_booking_type, " .
			" DATE_FORMAT(bookings.room_booking_start_time, '%Y-%m-%d') AS full_date, DATE_FORMAT(bookings.room_booking_start_time, '%Y%m%d') AS pure_date, " .
			" hour(bookings.room_booking_start_time) AS s_hour, hour(bookings.room_booking_end_time) AS e_hour, " .
			" minute(bookings.room_booking_start_time) AS s_minute, minute(bookings.room_booking_end_time) AS e_minute " .
			" FROM bookings, rooms " .
			" WHERE bookings.room_bookingID = '$in_bookingID' " . 
			" AND rooms.roomID = bookings.roomID ";
	if ($result_booking = mysql_db_query($dbname, $query_booking))
	{
		if (!mysql_num_rows($result_booking))
		{
			mysql_free_result($result_booking);
			on_error(10);
			exit();
		}
	}
	else
	{
		on_error(10);
		exit();
	}
	$row_booking = mysql_fetch_array($result_booking);
?>
		<form name="form1" method="post" action="user_edit_room_booking.php?action=edit" onsubmit="return frmChk(this);">
		<input type="hidden" name="room_type" value="<?php echo $room_type; ?>">
		<input type="hidden" name="in_bookingID" value="<?php echo $in_bookingID; ?>">
		<input type="hidden" name="in_userID" value="<?php echo $row_booking["userID"]; ?>">
		<input type="hidden" name="in_date" value="<?php echo $row_booking["pure_date"]; ?>">
		<input type="hidden" name="full_date" value="<?php echo $row_booking["full_date"]; ?>">
		<table width="100%" border="0" cellspacing="0" cellpadding="2">
			<tr> 
				<td nowrap class="text10point" width="50%" align="right"> 
				<?php print $msg_room_booking_roomcode; ?>
				</td>
				<td class="textfield" width="50%">
<?php
	echo $row_booking["room_code"];
	echo "\t\t\t\t<input type=\"hidden\" name=\"in_roomID\" value=\"".$row_booking["roomID"]."\">\n"; ?></td>
			</tr>
			<tr> 
				<td nowrap class="text10point" width="50%" align="right"> 
				<?php print $msg_room_booking_class; ?>
				</td>
				<td class="textfield" width="50%"> 
					<INPUT TYPE="TEXT" NAME="in_class" VALUE="<?php echo $row_booking["class"]; ?>" SIZE=10 ALIGN="LEFT" MAXLENGTH=10>
				</td>
			</tr>
			<tr> 
				<td nowrap class="text10point" width="50%" align="right"> 
				<?php print $msg_room_booking_purpose; ?>
				</td>
				<td class="textfield" width="50%"> 
					<select name="in_type" class="textfield">
						<option value="Lecture"<?php if ($row_booking["room_booking_type"] == "Lecture") echo " selected"; ?>>Lecture</option>
						<option value="Lab"<?php if ($row_booking["room_booking_type"] == "Lab") echo " selected"; ?>>Lab</option>
						<option value="Tutorial"<?php if ($row_booking["room_booking_type"] == "Tutorial") echo " selected"; ?>>Tutorial</option>
						<option value="Test"<?php if ($row_booking["room_booking_type"] == "Test") echo " selected"; ?>>Test</option>
						<option value="Others"<?php if ($row_booking["room_booking_type"] == "Others") echo " selected"; ?>>Others</option>
					</SELECT>
				</td>
			</tr>
			<tr> 
				<td nowrap class="text10point" width="50%" align="right"> 
				<?php print $msg_room_booking_edit_date; ?>
				</td>
				<td class="textfield" width="50%"><?php echo $row_booking["full_date"]; ?></td>
			</tr>
			<tr> 
				<td nowrap class="text10point" width="50%" align="right"> 
				<?php print $msg_room_booking_time_start; ?>
				</td>
				<td class="textfield" width="50%">
				<select name="in_start_time" class="textfield">
<?php
	for ($i=8; $i<17; $i++)
	{
		if ($i < 10)
		{
			if ($row_booking["s_hour"] == $i)
			{
				echo "\t\t\t\t\t<option value=\"0".$i."3000\" selected>".$i.":30</option>\n";
			}
			else
			{
				echo "\t\t\t\t\t<option value=\"0".$i."3000\">".$i.":30</option>\n";
			}
		}
		else
		{
			if ($row_booking["s_hour"] == $i)
			{
				echo "\t\t\t\t\t<option value=\"".$i."3000\" selected>".$i.":30</option>\n";
			}
			else
			{
				echo "\t\t\t\t\t<option value=\"".$i."3000\">".$i.":30</option>\n";
			}
		}
	}
?>
				</select>
				</td>
			</tr>
			<tr> 
				<td nowrap class="text10point" width="50%" align="right"> 
				<?php print $msg_room_booking_time_end ; ?>
				</td>
				<td class="textfield" width="50%"> 
					<select name="in_end_time" class="textfield">
<?php
	for ($i=9; $i<18; $i++)
	{
		if ($i < 10)
		{
			if ($row_booking["e_hour"] == $i)
			{
				echo "\t\t\t\t\t<option value=\"0".$i."3000\" selected>".$i.":30</option>\n";
			}
			else
			{
				echo "\t\t\t\t\t<option value=\"0".$i."3000\">".$i.":30</option>\n";
			}
		}
		else
		{
			if ($row_booking["e_hour"] == $i)
			{
				echo "\t\t\t\t\t<option value=\"".$i."3000\" selected>".$i.":30</option>\n";
			}
			else
			{
				echo "\t\t\t\t\t<option value=\"".$i."3000\">".$i.":30</option>\n";
			}
		}
	}
?>
					</select>
				</td>
			</tr>
			<tr> 
				<td nowrap class="text10point" width="50%" align="right"> 
		        	<?php print $msg_room_booking_desc; ?>
				</td>
				<td class="textfield" width="50%"> 
					<textarea name="in_desc" wrap=physical cols=30 rows=5><?php echo $row_booking["room_booking_desc"]; ?></textarea>
				</td>
			</tr>
			<tr>
				<td class="text10white" bordercolor="0" height="25">&nbsp;</td>
			</tr>
			<tr> 
				<td nowrap class="text10point" colspan="2" align="center"> 
					<input type="image" name="Submit" value="Submit" src="../image/update.png" border="0">
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a href="user_edit_room_booking.php?in_bookingID=<?php echo $in_bookingID; ?>"><img src="../image/reset.png" border="0"></a>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a href="<?php print $HTTP_REFERER; ?>"><img src="../image/cancel.png"border="0"></a>
				</td>
			</tr>
		</table>
		</form>
<?php
	mysql_free_result($result_booking);
	// To edit the room booking data
}
elseif ($action=="edit")
{
	// room_type
	// in_bookingID
	// in_userID
	// in_date "20011231"
	// full_date "2001-12-31"
	// in_class
	// in_type
	// in_start_time "123000"
	// in_end_time
	// in_desc
	
	$start_time = $in_date . $in_start_time;
	$end_time = $in_date . $in_end_time;
	if ($in_start_time >= $in_end_time)
	{
		on_error(15);
		exit();
	}
	
	// Check if room available for booking
	$query_ava = "SELECT room_bookingID, DATE_FORMAT(room_booking_start_time, '%Y%m%d') AS s_date, DATE_FORMAT(room_booking_end_time, '%Y%m%d') AS e_date, " .
					"TIME_FORMAT(room_booking_start_time, '%H%i') AS s_time, TIME_FORMAT(room_booking_end_time, '%H%i') AS e_time " .
					"FROM bookings " .
					"WHERE DATE_FORMAT(room_booking_start_time, '%Y%m%d') = '$in_date' " .
					" AND (TIME_FORMAT(room_booking_start_time, '%H%i%s') = '$in_start_time' " .
					" OR TIME_FORMAT(room_booking_end_time, '%H%i%s') = '$in_end_time' " .
					" OR (TIME_FORMAT(room_booking_start_time, '%H%i%s') > '$in_start_time' AND TIME_FORMAT(room_booking_start_time, '%H%i%s') < '$in_end_time') " .
					" OR (TIME_FORMAT(room_booking_end_time, '%H%i%s') > '$in_start_time' AND TIME_FORMAT(room_booking_end_time, '%H%i%s') < '$in_end_time')) " .
					" AND roomID = '$in_roomID' AND room_bookingID <> '$in_bookingID'";
	$result_ava = mysql_db_query($dbname, $query_ava);
	if (mysql_num_rows($result_ava) > 0)
	{
		mysql_free_result($result_ava);
		on_error(12);
		exit();
	}
	
	// Used to update the room booking data
	$updateStmt = "UPDATE bookings SET userID = '$in_userID', class = '$in_class', room_booking_start_time = '$start_time', room_booking_end_time = '$end_time', " .
					"room_booking_type = '$in_type', room_booking_desc = '$in_desc' " . 
					"WHERE room_bookingID = '$in_bookingID'";
	if (!mysql_db_query($dbname, $updateStmt))
	{
		on_error(6);
		exit();
	}
?>
	<form name="form1" method="post" action="user_room_booking_main.php">
		<P>
		<div align="center" class="heading">
			<?php print $msg_room_booking_edit_success; ?>
			<BR><BR>
			<input type="image" name="Submit" src="../image/ok.png" border="0">
		</div>
	</p>
	</form>
<?php
}
?>
		<!--- End of Edit Room Booking Code --->
		</td>		
	</tr>
</table>
</body>
</html>
Return current item: Online Resource Management system