function testdbRoomsModule() { // Create some rooms to add to the database $room1 = new Room("126", "2T", "3", "y", "clean", null, ""); $room2 = new Room("223", "Q", "2", "n", "clean", null, ""); // Test the insert function $this->assertTrue(insert_dbRooms($room1)); $this->assertTrue(insert_dbRooms($room2)); $this->assertTrue(retrieve_dbRooms($room1->get_room_no())); // Set status for room 1 $room1->set_status("dirty"); // Can't book a dirty room $this->assertFalse($room1->book_me("11-02-07Meghan2077291234")); // but can book a clean room $this->assertTrue($room2->book_me("11-01-01Jones2077311154")); // test the retrieve function $this->assertEqual(retrieve_dbRooms($room2->get_room_no())->get_room_no(), "223"); $this->assertEqual(retrieve_dbRooms($room2->get_room_no())->get_status(), "booked"); // Test the update functions -- check that unbooking leaves the room dirty $this->assertTrue($room2->unbook_me("11-01-01Jones2077311154")); $this->assertEqual(retrieve_dbRooms($room2->get_room_no())->get_status(), "dirty"); // Test the delete functions $this->assertTrue(delete_dbRooms($room1->get_room_no())); $this->assertTrue(delete_dbRooms($room2->get_room_no())); // Restore the rooms in the database $this->assertTrue(insert_dbRooms(new Room("126", "2T", "3", "y", "clean", null, ""))); $this->assertTrue(insert_dbRooms(new Room("223", "Q", "2", "n", "clean", null, ""))); echo "testdbRooms complete"; }
<!-- Content div goes here now --> <div id="content"> <?php // Prep work for the room // Retrieve the room object $currentRoom = retrieve_dbRooms($roomID); // Check if the room is valid and if any data was recently change // by the user if ($currentRoom instanceof Room) { // Check if the room has been modified if ($_POST['submit'] == "Submit") { //update the room update_room_info($currentRoom); echo "<h3 style=\"text-align:center\">Room has been updated</h3>"; // get the updated room $currentRoom = retrieve_dbRooms($roomID); echo "<script>location.href='roomLog.php?date=today'</script>"; } // Display the room's information include_once "roomView.inc"; } ?> <!-- include the footer at the end --> <?php include_once "footer.inc"; ?> </div> </div> <!-- useful functions --> <?php
function unbook_me($booking_id) { $r = retrieve_dbRooms($this->room_no); if ($r && $r->booking == $booking_id) { // *** comment out the next line for a temporary fix to facilitate dbImport... room stays perpetually clean $r->status = "dirty"; $r->booking = null; update_dbRooms($r); return $r; } else { return false; } // can't unbook if not booked }
function check_out($date) { $r = retrieve_dbRooms($this->room_no); $p = retrieve_dbPersons(substr($this->id, 8)); if ($r && $r->unbook_me($this->id)) { $this->status = "closed"; $this->date_out = $date; update_dbBookings($this); if ($p) { $p->add_prior_booking($this->id); update_dbPersons($p); } return $this; } else { return false; } }