00001 <?php
00002 if(!defined('__PRAGYAN_CMS'))
00003 {
00004 header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
00005 echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
00006 echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
00007 exit(1);
00008 }
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 class hospi implements module {
00039 private $userId;
00040 private $moduleComponentId;
00041 private $action;
00042
00043 public function getHtml($gotuid, $gotmoduleComponentId, $gotaction) {
00044 $this->userId = $gotuid;
00045 $this->moduleComponentId = $gotmoduleComponentId;
00046 $this->action = $gotaction;
00047
00048 if ($gotaction == 'view')
00049 return $this->actionView();
00050 if ($gotaction == 'post')
00051 return $this->actionPost();
00052 if ($gotaction == 'moderate')
00053 return $this->actionModerate();
00054 if ($gotaction == 'accomodate')
00055 return $this->actionAccomodate();
00056 if ($gotaction == 'addroom')
00057 return $this->actionAddroom();
00058
00059 }
00060
00061 public function viewall()
00062 {
00063 $hospiview=<<<VIEW
00064 <br><br>
00065 <a href="./+addRoom"> Add Room</a><br>
00066 <a href="./+addRoom&subaction=addhostel">Add Hostel</a><br>
00067 <!--a href="./+accomodate">Accomodate</a><br-->
00068 <a href="./+accomodate&quick"><b>Fast Accomodate</b></a><br>
00069 <a href="./+view&subaction=finduser">Search user</a><br>
00070 <a href="./+view&subaction=findroom">Search room</a><br>
00071 <a href="./+view&subaction=viewvacantrooms">View vacant rooms</a><br>
00072 <a href="./+view&subaction=viewstatus">View All Rooms</a><br>
00073
00074 VIEW;
00075 return $hospiview;
00076 }
00077
00078
00079 private function getEmailSuggestions($input) {
00080 $emailQuery ="SELECT `form_elementdata` FROM `form_elementdata` WHERE `page_modulecomponentid`=36 AND form_elementid IN (3,13,14,15) AND form_elementdata LIKE '%$input%' ";
00081 $emailResult = mysql_query($emailQuery);
00082 $suggestions = array($input);
00083 while($emailRow = mysql_fetch_row($emailResult)) {
00084 $suggestions[] = $emailRow[0];
00085 }
00086 $query ="SELECT `user_id` FROM `form_regdata` WHERE `page_modulecomponentid`=36 ";
00087 $result = mysql_query($query);
00088 while($temp=mysql_fetch_array($result))
00089 {
00090 $query1 = 'SELECT `user_email` FROM `' . MYSQL_DATABASE_PREFIX . 'users` WHERE `user_email` LIKE "%'.$input.'%" AND `user_id`='.$temp[0];
00091 $result1=mysql_query($query1);
00092 if(mysql_num_rows($result1)){
00093 $temp1=mysql_fetch_array($result1,MYSQL_NUM);
00094 $suggestions[] = $temp1[0];
00095 }
00096 }
00097 return join($suggestions, ',');
00098 }
00099
00100
00101 public function getUserDetails($email)
00102 {
00103 $query="SELECT * FROM `hospi_accomodation_status` WHERE `hospi_guest_email`='$email' ORDER BY `hospi_actual_checkin` DESC LIMIT 0,1";
00104 $result=mysql_query($query) or die (mysql_error()."in function getUserDetails in hospi") ;
00105 $temp=mysql_fetch_array($result,MYSQL_ASSOC);
00106 $query="SELECT `hospi_hostel_name`,`hospi_room_no` FROM `hospi_hostel` WHERE `hospi_room_id`=$temp[hospi_room_id]";
00107 $result=mysql_query($query) or die (mysql_error()."in function getUserDetails in hospi") ;
00108 $temp1=mysql_fetch_array($result,MYSQL_ASSOC);
00109 $userdetail=<<<UD
00110 <table border="1">
00111 <tr><td>Name</td><td>$temp[hospi_guest_name]</td></tr>
00112 <tr><td>Email</td><td>$temp[hospi_guest_email]</td></tr>
00113 <tr><td>Phone</td><td>$temp[hospi_guest_phone]</td></tr>
00114 <tr><td>Hostel</td><td>$temp1[hospi_hostel_name]</td></tr>
00115 <tr><td>Room</td><td>$temp1[hospi_room_no]</td></tr>
00116 </table>
00117 <a onClick="history.go(-1)">BACK</a>
00118 UD;
00119 return $userdetail;
00120
00121 }
00122
00123
00124
00125 public function actionAccomodate() {
00126 $i=0;
00127 static $j=0;
00128 foreach ($_GET as $var => $val) {
00129
00130
00131 if($j<(count($_GET)-1))
00132 {
00133 if ($i == 1)
00134 $action .= "&" . $var . "=" . $val;
00135 if ($val=='accomodate') {
00136 $action .= "+" . $val;
00137 $i = 1;
00138 }
00139 $j=$j+1;
00140
00141 }
00142 }
00143 $action='<a onClick="history.go(-1)">BACK</a>';
00144
00145 if(isset($_GET['displayUserDetails']))
00146 {
00147 return $this->getUserDetails($_GET['displayUserDetails']);
00148 }
00149
00150 if(isset($_GET['quick'])){
00151 global $sourceFolder,$cmsFolder;
00152 global $moduleFolder;
00153 global $urlRequestRoot;
00154 global $templateFolder;
00155 $calpath = "$urlRequestRoot/$cmsFolder/$moduleFolder";
00156 $scriptsFolder = "$urlRequestRoot/$cmsFolder/$templateFolder/common/scripts";
00157 $imagesFolder = "$urlRequestRoot/$cmsFolder/$templateFolder/common/images";
00158 $checkIn=<<<CHECKIN
00159 <link rel="stylesheet" type="text/css" media="all" href="$calpath/form/calendar/calendar.css" title="Aqua" />
00160 <script type="text/javascript" src="$calpath/form/calendar/calendar.js"></script>
00161
00162 <form name="hospi_check_in" method="POST" action="+accomodate&quick">
00163
00164
00165
00166 <table>
00167 <tr>
00168 <td>Guest Name:</td><td><input type="text" name="guest_name" size="20" maxlength="100" ></td>
00169 </tr><tr>
00170 <td>Email:</td><td><input type="text" name="guest_email" id="guest_email" size="20" maxlength="100" />
00171 <div id="suggestionsBox" style="background-color: white; width: 260px; border: 1px solid black; position: absolute; overflow-y: scroll; max-height: 180px; display: none"></div>
00172 </td>
00173 </tr><tr>
00174
00175 <td>Phone No.:</td><td><input type="text" name="guest_phone" size="20" maxlength="100" ></td>
00176 </tr><tr>
00177 <td>College:</td><td><input type="text" name="guest_college" size="20" maxlength="100" ></td>
00178 </tr><tr>
00179 <td>Expected Check out:</td>
00180 <td><input type="text" name="check_out" id="check_out" /><input name="calc" type="reset" value="Calendar" onclick="return showCalendar('check_out', '%Y-%m-%d %H:%M:%S', '24', true);" /></td>
00181 </tr><tr>
00182
00183
00184 <td>Cash Paid?</td><td><input type="checkbox" name="cash_paid"></td>
00185 </tr><tr>
00186 <td>Hostel allotted:</td></tr>
00187
00188 CHECKIN;
00189
00190 $query="SELECT DISTINCT `hospi_hostel_name` FROM `hospi_hostel` ";
00191 $result=mysql_query($query)or die(mysql_error());
00192 while($temp=mysql_fetch_array($result,MYSQL_ASSOC))
00193 {
00194 $hostel=$temp['hospi_hostel_name'];
00195 $checkIn.='<td><div><tr><td><b>'.$hostel.'</b></td><td>';
00196 $checkIn.="<select name=\"hostel_$hostel\"><option>Room No.</option>";
00197 $query1="SELECT `hospi_room_no` FROM `hospi_hostel` WHERE `hospi_hostel_name`='$hostel' AND `hospi_room_no`<>0";
00198 $result1=mysql_query($query1);
00199 while($temp1=mysql_fetch_array($result1,MYSQL_NUM)){
00200 foreach($temp1 as $room)
00201
00202 {
00203
00204 $query3="SELECT * FROM `hospi_hostel` WHERE `hospi_hostel_name`='$hostel' AND `hospi_room_no`=$room";
00205 $result3=mysql_query($query3);
00206 $temp3=mysql_fetch_array($result3, MYSQL_ASSOC);
00207 $query4="SELECT * FROM `hospi_accomodation_status` WHERE `hospi_room_id`=$temp3[hospi_room_id] AND `hospi_actual_checkout` IS NULL";
00208 $result4=mysql_query($query4);
00209 $num=mysql_num_rows($result4);
00210
00211 if ($num<$temp3['hospi_room_capacity'])
00212 $status="VACANT";
00213 else $status="FULL";
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 $checkIn.="<option value=\"$room\" id=\"$room\">".$room." ".$status." (".$num."/".$temp3[hospi_room_capacity].")"."</option>";
00224
00225 }
00226
00227
00228 }
00229 $checkIn.="</select></td></tr></div>";
00230 }
00231 $checkIn.='</td></tr><tr><td><input type="submit" value="Check In"></td></tr></table>';
00232 $checkIn.=<<<TAG
00233 <script type="text/javascript" language="javascript" src="$scriptsFolder/ajaxsuggestionbox.js">
00234
00235 </script>
00236 <script language="javascript">
00237 var userBox = new SuggestionBox(document.getElementById('guest_email'), document.getElementById('suggestionsBox'), "./+accomodate&subaction=getsuggestions&forwhat=%pattern%");
00238 userBox.loadingImageUrl = '$imagesFolder/ajaxloading.gif';
00239 </script>
00240
00241 </form>
00242 TAG;
00243
00244
00245
00246
00247 if(isset($_POST['guest_name']))
00248 {
00249 static $room_no,$hostel;
00250 $query="SELECT DISTINCT `hospi_hostel_name` FROM `hospi_hostel` ";
00251 $result=mysql_query($query)or die(mysql_error());
00252 while($temp=mysql_fetch_array($result,MYSQL_ASSOC))
00253 {
00254 $hostel_name="hostel_".$temp['hospi_hostel_name'];
00255 if(is_numeric($_POST[''.$hostel_name.'']))
00256 {
00257 if(is_numeric($room_no))
00258 {
00259 displayerror("More than one room selected!!");
00260 return '';
00261
00262 }
00263 $room_no=$_POST[''.$hostel_name.''];
00264 $hostel=$temp['hospi_hostel_name'];
00265 }
00266 }
00267
00268 $query="SELECT `hospi_room_id` FROM `hospi_hostel` WHERE `hospi_hostel_name`='$hostel' AND `hospi_room_no`=$room_no";
00269 $result1=mysql_query($query);
00270 $temp=mysql_fetch_assoc($result1);
00271 $room_Id=$temp['hospi_room_id'];
00272 if($room_Id==0)
00273 {
00274 displayerror("No room allotted!!");
00275 return;
00276 }
00277
00278 if(isset($_POST['cash_paid']))$paid=1;else $paid=0;
00279
00280 $query="INSERT INTO `hospi_accomodation_status` (`hospi_room_id`,`hospi_actual_checkin`,`hospi_checkedin_by`,`hospi_projected_checkout`,`hospi_cash_collected`,`hospi_guest_name`,`hospi_guest_college`,`hospi_guest_phone`,`hospi_guest_email`) VALUES ('$room_Id',NOW(),'$this->userId','$_POST[check_out]','$paid','$_POST[guest_name]','$_POST[guest_college]','$_POST[guest_phone]','$_POST[guest_email]')";
00281 $result=mysql_query($query) or displayerror(mysql_error());
00282 if(!(mysql_error()))
00283 displayinfo("$_POST[guest_name] checked in successfully");
00284 else displayerror("Failed to check in $_POST[guest_name]");
00285
00286 }
00287
00288 return $checkIn.$this->viewall();
00289 }
00290
00291
00292 $room.='<table border="1"><tr>';
00293 if(isset($_GET['subaction']) && $_GET['subaction'] == 'getsuggestions' && isset($_GET['forwhat'])) {
00294 echo $this->getEmailSuggestions($_GET['forwhat']);
00295 disconnect();
00296 exit();
00297
00298 }
00299 elseif(!isset($_GET['hostel'])){
00300 $query="SELECT DISTINCT `hospi_hostel_name` FROM `hospi_hostel` ";
00301 $result=mysql_query($query);
00302 while($temp=mysql_fetch_array($result,MYSQL_ASSOC))
00303 {
00304 $room.='<td > <a href="+accomodate&hostel='.$temp['hospi_hostel_name'].'">'. $temp['hospi_hostel_name'].' </td>';
00305 }
00306 $room.="</tr></table>";
00307 $room.=$action;
00308
00309 return $room.$this->viewall();
00310 }
00311 elseif(!isset($_GET['room_id']))
00312 {
00313 $query="SELECT * FROM `hospi_hostel` WHERE `hospi_hostel_name`='$_GET[hostel]' AND `hospi_room_id`!=0";
00314 $result=mysql_query($query);
00315 $room.='</tr><tr ><td >'.$_GET['hostel'].'</td>';
00316 while($temp=mysql_fetch_array($result,MYSQL_ASSOC))
00317 {
00318 $status="Vacant";
00319 $query1="SELECT * FROM `hospi_accomodation_status` WHERE `hospi_room_id`=$temp[hospi_room_id] AND `hospi_actual_checkout` IS NULL";
00320 $result1=mysql_query($query1);
00321 $temp1=mysql_fetch_array($result1, MYSQL_ASSOC);
00322 if(mysql_num_rows($result1)<$temp['hospi_room_capacity']);
00323 else $status="Full";
00324 $room.='<td > <a href="+accomodate&hostel='.$temp['hospi_hostel_name'].'&room_id='.$temp['hospi_room_id'].'">'.$temp['hospi_room_no'].' ' ;
00325 $room.="$status (".mysql_num_rows($result1)."/".$temp['hospi_room_capacity'].")";
00326 $room.='</td>';
00327 }
00328 $room.="</tr></table>";
00329 $room.=$action;;
00330 return $room.$this->viewall();
00331 }
00332 else{
00333
00334 if(isset($_GET['checkIn']))
00335 {
00336 if(isset($_POST['cash_paid']))$paid=1;else $paid=0;
00337 $userId=getUserIdFromEmail($_POST['txtUserEmail']);
00338 if($userId!=0){
00339 $query1="SELECT * FROM `hospi_accomodation_status` WHERE `user_id`=$userId AND `hospi_actual_checkout` IS NULL ";
00340 $result1=mysql_query($query1);
00341 $room1=mysql_fetch_assoc($result1);
00342 if(!(mysql_num_rows($result1))){
00343 $name=getUserFullName($userId);
00344 $email=getUserEmail($userId);
00345
00346
00347 $query="INSERT INTO `hospi_accomodation_status` (`hospi_room_id`,`user_id`,`hospi_actual_checkin`,`hospi_checkedin_by`,`hospi_projected_checkout`,`hospi_cash_collected`,`hospi_guest_name`,`hospi_guest_email`) VALUES ('$_GET[room_id]','$userId',NOW(),'$this->userId','$_POST[check_out]','$paid','$name','$email')";
00348 $result=mysql_query($query) or displayerror(mysql_error());
00349 if(!(mysql_error()))
00350 displayinfo("$_POST[txtUserEmail] checked in successfully");
00351 else displayerror("Failed to check in $_POST[txtUserEmail]");
00352 }
00353 else
00354 {
00355 $query="SELECT `hospi_hostel_name` FROM `hospi_hostel` WHERE `hospi_room_id`='$room1[hospi_room_id]'";
00356 $result=mysql_query($query) or die (mysql_error());
00357 $room2=mysql_fetch_row($result);
00358 displayerror("User is already checked in <a href=\"+accomodate&hostel=$room2[0]&room_id=$room1[hospi_room_id]\">here</a>");
00359 }
00360 }
00361 }
00362
00363
00364 if((isset($_GET['checkOut'])))
00365 {
00366 if(is_numeric($_GET['checkOut']))
00367 $cond='`user_id`='.$_GET['checkOut'].'';
00368 else $cond='`hospi_guest_name`=\''.$_GET['checkOut'].'\' AND `hospi_actual_checkin`=\''.$_GET['checkinTime'].'\' AND `hospi_checkedin_by`='.$_GET['by'].'';
00369 $query="UPDATE `hospi_accomodation_status` SET `hospi_actual_checkout`=NOW(),`hospi_checkedout_by`= '$this->userId' WHERE `hospi_room_id`='$_GET[room_id]' AND $cond AND `hospi_actual_checkout` IS NULL ";
00370 $result=mysql_query($query);
00371 if(mysql_error())displayerror(mysql_error());
00372
00373
00374 }
00375 global $urlRequestRoot;
00376 global $sourceFolder,$cmsFolder;
00377 global $templateFolder;
00378 $scriptsFolder = "$urlRequestRoot/$cmsFolder/$templateFolder/common/scripts";
00379 $imagesFolder = "$urlRequestRoot/$cmsFolder/$templateFolder/common/images";
00380
00381 $query="SELECT * FROM `hospi_accomodation_status` WHERE `hospi_room_id`=$_GET[room_id] AND `hospi_actual_checkout` IS NULL ";
00382 $result=mysql_query($query);
00383 $room.='</tr><tr ><td >'.$_GET['hostel'].'</td></tr>';
00384 while($temp=mysql_fetch_array($result,MYSQL_ASSOC))
00385 {
00386 if($temp['user_id']<>0)
00387 $room.="<tr><td><a href=\"+accomodate&displayUserDetails=$temp[hospi_guest_email] \">".getUserFullName($temp['user_id'])."</a></td><td><input type=\"submit\" value=\"Check Out\" onclick=\"window.location='./+accomodate&hostel=$_GET[hostel]&room_id=$_GET[room_id]&checkOut=$temp[user_id]'\"></td></tr>";
00388 else
00389 $room.="<tr><td><a href=\"+accomodate&displayUserDetails=$temp[hospi_guest_email]\">".$temp['hospi_guest_name']."</td><td><input type=\"submit\" value=\"Check Out\" onclick=\"window.location='./+accomodate&hostel=$_GET[hostel]&room_id=$_GET[room_id]&checkOut=$temp[hospi_guest_name]&checkinTime=$temp[hospi_actual_checkin]&by=$temp[hospi_checkedin_by]'\"></td></tr>";
00390
00391 }
00392 $room.="</tr></table>";
00393 global $sourceFolder,$cmsFolder;
00394 global $moduleFolder;
00395 global $urlRequestRoot;
00396
00397 $calpath = "$urlRequestRoot/$cmsFolder/$moduleFolder";
00398 $room.=<<<FORM
00399 <style type="text/css">
00400 <!--
00401 span.suggestion {
00402 padding: 2px 4px 2px 4px;
00403 display: block;
00404 background-color: white;
00405 cursor: pointer;
00406 }
00407 span.suggestion:hover {
00408 background-color: #DEDEDE;
00409 }
00410 -->
00411 </style>
00412 <link rel="stylesheet" type="text/css" media="all" href="$calpath/form/calendar/calendar.css" title="Aqua" />
00413 <script type="text/javascript" src="$calpath/form/calendar/calendar.js"></script>
00414
00415 <form method="POST" action="./+accomodate&hostel=$_GET[hostel]&room_id=$_GET[room_id]&checkIn=1">
00416
00417 Guest Name<input type="text" name="txtUserEmail" id="txtUserEmail" autocomplete="off" style="width: 256px" /><br>
00418
00419 Expected Check out<input type="text" name="check_out" id="check_out" /><input name="calc" type="reset" value="Calendar" onclick="return showCalendar('check_out', '%Y-%m-%d %H:%M:%S', '24', true);" />
00420
00421 <div id="suggestionsBox" style="background-color: white; width: 260px; border: 1px solid black; position: absolute; overflow-y: scroll; max-height: 180px; display: none"></div>
00422
00423 <br>Cash Paid?<input type="checkbox" name="cash_paid">
00424
00425 <br>
00426 <input type="submit" value="Check In" />
00427
00428 <script type="text/javascript" language="javascript" src="$scriptsFolder/ajaxsuggestionbox.js">
00429
00430 </script>
00431 <script language="javascript">
00432 var userBox = new SuggestionBox(document.getElementById('txtUserEmail'), document.getElementById('suggestionsBox'), "./+accomodate&subaction=getsuggestions&forwhat=%pattern%");
00433 userBox.loadingImageUrl = '$imagesFolder/ajaxloading.gif';
00434 </script>
00435
00436
00437 </form>
00438 FORM;
00439
00440 $room.=$action;
00441 return $room.$this->viewall();
00442
00443 }
00444 }
00445
00446
00447 public function actionAddroom() {
00448
00449
00450
00451
00452 /*
00453 * SELECT DISTINCT hospi_hostel_name FROM hospi_hostel
00454 * display each as an option in a dropdown menu
00455 * add room no. and capacity to the room
00456 * insert into hospi_hostel with hospi_room_id as
00457 *
00458 * $query = 'SELECT MAX(`hospi_room_id`) FROM `' . MYSQL_DATABASE_PREFIX . 'hospi_hostel`';
00459 * $result = mysql_query($query) or die(mysql_error());
00460 * $row = mysql_fetch_row($result);
00461 * $room_id = 1;
00462 * if(!is_null($row[0])) {
00463 * $room_id = $row[0] + 1;
00464 * }
00465 *
00466 *subaction=addHostel
00467 *
00468 *just a simple text box with add hostel if the hostel added is not already in db
00469 *
00470 *For Shruthi:: The user must be able to jump on to any page from any other page,
00471 * basically links for each action to be present in every action.
00472 * You can make this into a function and then call it every where else.
00473 *
00474 * */
00475
00476
00477
00478 $subaction=$_GET['subaction'];
00479 $i=0;
00480 static $j=0;
00481 foreach ($_GET as $var => $val) {
00482 if($j<(count($_GET)-1))
00483 {
00484 if ($i == 1)
00485 $action .= "&" . $var . "=" . $val;
00486 if ($val=='addRoom') {
00487 $action .= "+" . $val;
00488 $i = 1;
00489 }
00490 $j=$j+1;
00491 }
00492 }
00493 $action='<a onClick="history.go(-1)">BACK</a>';
00494 if(isset($_GET['subaction']))
00495 {
00496
00497 if($subaction=='submitaddroom')
00498 {
00499 if(($_POST['roomNo']=='')or($_POST['capacity']==''))
00500 {
00501 displayerror('All fields not entered');
00502 return'';
00503 }
00504 $query="SELECT * FROM `hospi_hostel` WHERE `hospi_room_no`={$_POST['roomNo']} AND `hospi_hostel_name`={$_POST['hostels']}";
00505 $result=mysql_query($query);
00506 if(mysql_num_rows($result))
00507 {
00508 displayerror('Room no. already exists in the database for the hostel.');
00509 return'';
00510 }
00511 $query = 'SELECT MAX(`hospi_room_id`) FROM `hospi_hostel`';
00512 $result = mysql_query($query) or die('error');
00513 $row = mysql_fetch_row($result);
00514
00515 if(!is_null($row[0])) {
00516 $room_id = $row[0] + 1;
00517 }
00518 $query="INSERT INTO `hospi_hostel` (`hospi_room_id`,`hospi_hostel_name`,`hospi_room_capacity`,`hospi_room_no`)".
00519 "VALUES('$room_id','{$_POST['hostels']}',{$_POST['capacity']},{$_POST['roomNo']}) ";
00520 $result=mysql_query($query);
00521 if(!$result)
00522 {
00523 displayerror('Error while adding room data');
00524 return'';
00525 }
00526 return $action.$this->viewall();
00527 }
00528 else if(isset($_POST['hostel']))
00529 {
00530 if($_POST['hostel']=='')
00531 {
00532 displayerror('Please enter a name for hostel');
00533 return'';
00534 }
00535
00536 $query = 'SELECT MAX(`hospi_room_id`) FROM `hospi_hostel`';
00537 $result = mysql_query($query) or die('error');
00538 $row = mysql_fetch_row($result);
00539
00540 if(!is_null($row[0])) {
00541 $room_id = $row[0] + 1;
00542 }
00543
00544 $query="INSERT INTO `hospi_hostel` (`hospi_hostel_name`,`hospi_room_id`) VALUES ('{$_POST['hostel']}','$room_id')";
00545 $result=mysql_query($query);
00546 if(!$result)
00547 {
00548 displayerror(mysql_error());
00549 return'';
00550 }
00551 $action;
00552 }
00553 else if($subaction=='addhostel')
00554 {
00555 $newhostel=<<<HOSTEL
00556 <form method="POST" action="./+addroom&subaction=addhostel">
00557 Hostel:<input type="text" name="hostel" id="hostel"><br>
00558 <input type="submit" value="Add Hostel"><br>
00559 HOSTEL;
00560 return $newhostel.$action.$this->viewall();
00561
00562 }
00563 }
00564
00565
00566
00567 $query="SELECT DISTINCT `hospi_hostel_name` FROM `hospi_hostel`";
00568 $result=mysql_query($query);
00569 $hostel.=<<<ROOM
00570 <form method="POST" action="+addroom&subaction=submitaddroom">
00571 <select name="hostels" id="hostels" >
00572 ROOM;
00573 while($temp=mysql_fetch_array($result,MYSQL_NUM))
00574 {
00575 foreach($temp as $hostelname)
00576 {
00577 $hostel.='<option value='.$hostelname.'>'.$hostelname.'</option>';
00578 }
00579
00580 }
00581 $hostel.=<<<HOSTEL
00582 </select>
00583 <br>
00584 Room No:<input type="text" name="roomNo" id="roomNo"><br>
00585 Capacity:<input type="text" name="capacity" id="capacity"><br>
00586 <input type="submit" value="Add Room"><br>
00587 </form>
00588 <br><a href="./+addroom&subaction=addhostel">Add hostel<br>
00589 HOSTEL;
00590
00591 return $hostel.$action.$this->viewall();
00592 }
00593
00594
00595 public function Uplevelroom()
00596 {
00597 foreach ($_GET as $var => $val) {
00598 $i=0;
00599 if ($i == 1)
00600 $action .= "&" . $var . "=" . $val;
00601 if ($val=='addroom') {
00602 $action .= "+" . $val;
00603 $i = 1;
00604 }}
00605 return $action.$this->viewall();
00606 }
00607 public function actionView() {
00608 $subaction=$_GET['subaction'];
00609 $i=0;
00610 static $j=0;
00611 foreach ($_GET as $var => $val) {
00612 if($j<(count($_GET)-1))
00613 {
00614 if ($i == 1)
00615 $action .= "&" . $var . "=" . $val;
00616 if ($val=='View') {
00617 $action .= "+" . $val;
00618 $i = 1;
00619 }
00620 $j=$j+1;
00621 }
00622 }
00623 $action='<a onClick="history.go(-1)">BACK</a>';
00624 if(isset($_GET['subaction']))
00625 {
00626 if($_GET['subaction'] == 'getsuggestions' && isset($_GET['forwhat'])) {
00627 echo $this->getEmailSuggestions($_GET['forwhat']);
00628 exit();
00629 }
00630 $subaction=$_GET['subaction'];
00631 if($subaction=='displayuser')
00632 {
00633
00634 $search=$_POST['txtUserEmail'];
00635 $userid=getUserIdFromEmail($_POST[txtUserEmail]);
00636 if(is_numeric($userid))
00637 $query="SELECT * FROM `hospi_accomodation_status` WHERE `user_id`=$userid";
00638 else
00639 $query="SELECT * FROM `hospi_accomodation_status` WHERE `hospi_guest_name` LIKE '%$search%' OR `hospi_guest_email` LIKE '%$search%' OR `hospi_guest_college` LIKE '%$search%'";
00640 $result=mysql_query($query);
00641 if(!$result)
00642 {
00643
00644 displayerror(mysql_error());
00645 return'';
00646 }
00647 if(!mysql_num_rows($result))
00648 {
00649 displayinfo('The user has not checked into any room');
00650 return'';
00651 }
00652 else
00653 {
00654 $details.=<<<USER
00655 <b>User Email:{$_POST['txtUserEmail']}</b><br>
00656 USER;
00657 while($row=mysql_fetch_array($result))
00658 {
00659 $query="SELECT * FROM `hospi_hostel` WHERE `hospi_room_id`={$row['hospi_room_id']}";
00660 $result1=mysql_query($query);
00661 $row1=mysql_fetch_array($result1);
00662 $details.=<<<USER
00663 <br>
00664 <table border="1">
00665 <tr>
00666 <td nowrap="nowrap">Name</td>
00667 <td nowrap="nowrap">{$row['hospi_guest_name']}</td>
00668 </tr>
00669 <tr>
00670 <td nowrap="nowrap">Email</td>
00671 <td nowrap="nowrap">{$row['hospi_guest_email']}</td>
00672 </tr>
00673 <tr>
00674 <td nowrap="nowrap">College</td>
00675 <td nowrap="nowrap">{$row['hospi_guest_college']}</td>
00676 </tr>
00677 <tr>
00678 <td nowrap="nowrap">Phone</td>
00679 <td nowrap="nowrap">{$row['hospi_guest_phone']}</td>
00680 </tr>
00681 <tr>
00682 <td nowrap="nowrap">Hostel</td>
00683 <td nowrap="nowrap">{$row1['hospi_hostel_name']}</td>
00684 </tr>
00685 <tr>
00686 <td nowrap="nowrap">Room no.</td>
00687 <td nowrap="nowrap">{$row1['hospi_room_no']}</td>
00688 </tr>
00689 <tr>
00690 <td nowrap="nowrap">Checked in on</td>
00691 <td nowrap="nowrap">{$row['hospi_actual_checkin']}</td>
00692 </tr>
00693
00694
00695
00696 USER;
00697 if($row['hospi_actual_checkout'])
00698 {
00699 $details.="<tr><th nowrap=\"nowrap\">Checked out on</th><th nowrap=\"nowrap\">{$row['hospi_actual_checkout']}</th></tr>";
00700 }
00701 $details.='</table>';
00702 }
00703 return $details.'<a onClick="history.go(-1)">BACK</a>'.$this->viewall();
00704
00705 }
00706 }
00707 if($subaction=='finduser')
00708 {
00709 global $urlRequestRoot,$sourceFolder,$templateFolder,$cmsFolder;
00710
00711 $scriptsFolder = "$urlRequestRoot/$cmsFolder/$templateFolder/common/scripts";
00712 $imagesFolder = "$urlRequestRoot/$cmsFolder/$templateFolder/common/images";
00713 $find=<<<USER
00714
00715
00716 <form method="POST" action="./+view&subaction=displayuser">
00717 Enter user:<input type="text" name="txtUserEmail" id="txtUserEmail" autocomplete="off" style="width: 256px" />
00718 <div id="suggestionsBox" style="background-color: white; width: 260px; border: 1px solid black; position: absolute; overflow-y: scroll; max-height: 180px; display: none"></div>
00719 <input type="submit" Value="Find User"/>
00720 <script type="text/javascript" language="javascript" src="$scriptsFolder/ajaxsuggestionbox.js">
00721 </script>
00722 <script language="javascript">
00723 var userBox = new SuggestionBox(document.getElementById('txtUserEmail'), document.getElementById('suggestionsBox'), "./+view&subaction=getsuggestions&forwhat=%pattern%");
00724 userBox.loadingImageUrl = '$imagesFolder/ajaxloading.gif';
00725 </script>
00726 </form>
00727
00728
00729
00730
00731 USER;
00732 return $find.$action.$this->viewall();
00733 }
00734
00735 if($subaction=="viewstatus")
00736 {
00737 $query="SELECT DISTINCT `hospi_hostel_name` FROM `hospi_hostel` ";
00738 $result4=mysql_query($query)or die(mysql_error());
00739 $statusall=<<<ROOM
00740 <table border="1">
00741
00742 ROOM;
00743 static $i;
00744 while($temp4=mysql_fetch_array($result4,MYSQL_ASSOC))
00745 {
00746 $query="SELECT * FROM `hospi_hostel` WHERE `hospi_hostel_name`='$temp4[hospi_hostel_name]' AND `hospi_room_no`<>0";
00747 $result=mysql_query($query)or die(mysql_error());
00748 $num=mysql_num_rows($result);
00749 $statusall.='<tr><td rowspan="'.($num+1).'">'.$temp4['hospi_hostel_name'].'</td>';
00750 while($temp=mysql_fetch_array($result,MYSQL_ASSOC))
00751 {
00752
00753 $statusall.="</tr>";
00754
00755
00756 $status="Vacant";
00757 $query1="SELECT * FROM `hospi_accomodation_status` WHERE `hospi_room_id`=$temp[hospi_room_id] AND `hospi_actual_checkout` IS NULL";
00758 $result1=mysql_query($query1);
00759
00760 if(mysql_num_rows($result1)<$temp['hospi_room_capacity']);
00761 else $status="Full";
00762 $statusall.='<tr><td> <a href="+accomodate&hostel='.$temp['hospi_hostel_name'].'&room_id='.$temp['hospi_room_id'].'">'.$temp['hospi_room_no'].' ' ;
00763 $statusall.="$status (".mysql_num_rows($result1)."/".$temp['hospi_room_capacity'].")";
00764 $statusall.='</td><td>';
00765 while($temp1=mysql_fetch_array($result1, MYSQL_ASSOC)){
00766
00767 {
00768 $statusall.="<a href=\"+accomodate&displayUserDetails=$temp1[hospi_guest_email]\" >$temp1[hospi_guest_name]</a>,";
00769
00770 }
00771 }
00772 $statusall.='</td></tr>';
00773
00774
00775 }
00776 }
00777 $statusall.='</tr></table>';
00778 return $statusall.$this->viewall();
00779
00780
00781
00782
00783
00784 }
00785
00786 if($subaction=='displayroom')
00787 {
00788 if($_POST['roomno']<>'')$cond="`hospi_room_no`={$_POST['roomno']} AND";
00789 $query="SELECT * FROM `hospi_hostel` WHERE $cond `hospi_hostel_name`='{$_POST['hostels']}' ";
00790 $result=mysql_query($query);
00791 if(!mysql_num_rows($result))
00792 {
00793 displayerror('Room not present');
00794 return'';
00795 }
00796 $row=mysql_fetch_array($result);
00797 $query="SELECT * FROM `hospi_accomodation_status` WHERE `hospi_room_id`={$row['hospi_room_id']} AND `hospi_actual_checkin` IS NOT NULL";
00798 $result1=mysql_query($query);
00799 $room=<<<DETAILS
00800 <table border="1">
00801 <tr>
00802 <th nowrap="nowrap">Hostel:</th>
00803 <th nowrap="nowrap">{$row['hospi_hostel_name']}</th>
00804 </tr>
00805 <tr>
00806 <th nowrap="nowrap">Room No.:</th>
00807 <th nowrap="nowrap">{$row['hospi_room_no']}</th>
00808 </tr>
00809 </table><br><br>
00810
00811 Guests alloted:<br>
00812
00813 DETAILS;
00814 while($row1=mysql_fetch_assoc($result1))
00815 {
00816 $username=getUserEmail($row1['user_id']);
00817 $room.=<<<DETAILS
00818 <br>
00819 <table border="1">
00820 <tr>
00821 <th nowrap="nowrap">email:</th>
00822 <th nowrap="nowrap">$username</th>
00823 </tr>
00824 <tr>
00825 <th nowrap="nowrap">Checked in on:</th>
00826 <th nowrap="nowrap">{$row1['hospi_actual_checkin']}</th>
00827 </tr>
00828 <tr>
00829 DETAILS;
00830 if($row1['hospi_actual_checkout'])
00831 {
00832 $room.="<th nowrap=\"nowrap\">Checked out on:</th><th nowrap=\"nowrap\">{$row1['hospi_actual_checkout']}</th></tr></table>";
00833 }
00834 else
00835 {
00836 $room.="<th nowrap=\"nowrap\">Projected check out:</th><th nowrap=\"nowrap\">{$row1['hospi_projected_checkout']}</th></tr></table>";
00837 }
00838 }
00839 return $room.'<a onClick="history.go(-1)">BACK</a>'.$this->viewall();
00840 }
00841 if($subaction=='findroom')
00842 {
00843 $query="SELECT DISTINCT `hospi_hostel_name` FROM `hospi_hostel`";
00844 $result=mysql_query($query);
00845 $room=<<<ROOM
00846 <form method="POST" action="./+view&subaction=displayroom">
00847 <select name="hostels" id="hostels" >
00848 ROOM;
00849 while($temp=mysql_fetch_array($result,MYSQL_NUM))
00850 {
00851 foreach($temp as $hostelname)
00852 {
00853 $room.='<option value='.$hostelname.'>'.$hostelname.'</option>';
00854 }
00855 }
00856 $room.=<<<ROOM
00857 </select><br>
00858 Room No.:<input type="text" name="roomno" />
00859 <input type="submit" Value="Find Room"/>
00860 </form>
00861 ROOM;
00862 return $room.$action.$this->viewall();
00863 }
00864 if($subaction=='displayvacantrooms')
00865 {
00866 if($_POST['hostels']=="all")
00867 {
00868 $query="SELECT DISTINCT `hospi_hostel_name` FROM `hospi_hostel`";
00869 $res=mysql_query($query);
00870 while($row=mysql_fetch_array($res))
00871 {
00872 $query="SELECT * FROM `hospi_hostel` WHERE `hospi_hostel_name`='{$row[hospi_hostel_name]}' ";
00873 $result=mysql_query($query);
00874 $room.='<table border="1"><tr>';
00875 $room.='</tr><tr ><td >'.$row['hospi_hostel_name'].'</td>';
00876 while($temp=mysql_fetch_array($result,MYSQL_ASSOC))
00877 {
00878 $status="Vacant";
00879 $query1="SELECT * FROM `hospi_accomodation_status` WHERE `hospi_room_id`=$temp[hospi_room_id] AND `hospi_actual_checkout` IS NULL";
00880 $result1=mysql_query($query1);
00881 $temp1=mysql_fetch_array($result1, MYSQL_ASSOC);
00882 if(mysql_num_rows($result1)<$temp['hospi_room_capacity'])
00883 {
00884 $room.='<td width="95" height="95"> <a href="+accomodate&hostel='.$temp['hospi_hostel_name'].'&room_id='.$temp['hospi_room_id'].'">'.$temp['hospi_room_no'].' ' ;
00885 $room.="$status (".mysql_num_rows($result1)."/".$temp['hospi_room_capacity'].")";
00886 $room.='</td>';
00887 }
00888 }
00889 $room.="</tr></table>";
00890 }
00891 $room.='<a onClick="history.go(-1)">BACK</a>';
00892 return $room.$this->viewall();
00893 }
00894 else
00895 {
00896 $query="SELECT * FROM `hospi_hostel` WHERE `hospi_hostel_name`='$_POST[hostels]' ";
00897 $result=mysql_query($query);
00898 $room.='<table border="1"><tr>';
00899 $room.='</tr><tr ><td >'.$_POST['hostels'].'</td>';
00900 while($temp=mysql_fetch_array($result,MYSQL_ASSOC))
00901 {
00902 $status="Vacant";
00903 $query1="SELECT * FROM `hospi_accomodation_status` WHERE `hospi_room_id`=$temp[hospi_room_id] AND `hospi_actual_checkout` IS NULL";
00904 $result1=mysql_query($query1);
00905 $temp1=mysql_fetch_array($result1, MYSQL_ASSOC);
00906 if(mysql_num_rows($result1)<$temp['hospi_room_capacity']);
00907 else $status="Full";
00908 if($status!='Full'){
00909 $room.='<td width="95" height="95"> <a href="+accomodate&hostel='.$temp['hospi_hostel_name'].'&room_id='.$temp['hospi_room_id'].'">'.$temp['hospi_room_no'].' ' ;
00910 $room.="$status (".mysql_num_rows($result1)."/".$temp['hospi_room_capacity'].")";
00911 $room.='</td>';}
00912 }
00913 $room.="</tr></table>";
00914 $room.='<a onClick="history.go(-1)">BACK</a>';
00915 return $room.$this->viewall();
00916 }
00917 }
00918 if($subaction=='viewvacantrooms')
00919 {
00920 $query="SELECT DISTINCT `hospi_hostel_name` FROM `hospi_hostel`";
00921 $result=mysql_query($query);
00922 $room=<<<ROOM
00923 <form method="POST" action="./+view&subaction=displayvacantrooms">
00924 Choose hostel:<select name="hostels" id="hostels" >
00925 ROOM;
00926 while($temp=mysql_fetch_array($result,MYSQL_NUM))
00927 {
00928 foreach($temp as $hostelname)
00929 {
00930 $room.='<option value='.$hostelname.'>'.$hostelname.'</option>';
00931 }
00932
00933 }
00934 $room.='<option value="all">All hostels</option></select><br><br>';
00935 $room.='<input type="submit" Value="Find Vacant Rooms"/></form>';
00936 return $room.$this->viewall();
00937 }
00938 }
00939 return($this->viewall());
00940 }
00941 public function deleteModule($moduleComponentId) {
00942
00943 }public function createModule(&$moduleComponentId) {
00944 $query = 'SELECT MAX(`hospi_room_id`) FROM `hospi_hostel`';
00945 $result = mysql_query($query) or die('error');
00946 $row = mysql_fetch_row($result);
00947
00948 if(!is_null($row[0])) {
00949 $room_id = $row[0] + 1;
00950 }
00951 $query="INSERT INTO `hospi_hostel` (`hospi_room_id`)".
00952 "VALUES('$room_id') ";
00953 $result=mysql_query($query);
00954
00955
00956 }
00957
00958
00959 public function copyModule($moduleComponentId)
00960 {
00961
00962 }
00963
00964 }