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";
 }
/**
 * Updates a room in the dbRooms table by deleting it and reinserting it.
 * @param $room the room to update
 */
function update_dbRooms($room)
{
    // Make sure the room is actually a room
    if (!$room instanceof Room) {
        // Print an erro
        echo "Invalid argument for update_dbRooms function call.";
        return false;
    }
    // Update the table
    if (delete_dbRooms($room->get_room_no())) {
        return insert_dbRooms($room);
    } else {
        echo mysql_error() . "unable to update dbRooms table: " . $room->get_room_no();
        return false;
    }
}
/**
 * function to delete a dbRoomLog entry from the database
 * @param $roomLogID the id of the room log
 */
function delete_dbRoomLog($roomLogID)
{
    // connect to the database
    connect();
    // first grab the rooms of the room log
    $query = "SELECT * FROM dbRoomLogs WHERE id ='" . $roomLogID . "'";
    $result = mysql_query($query);
    if (!$result) {
        // print an error
        echo mysql_error() . " could not delete rooms from room log: " . $roomLogID . "\n";
        return false;
    }
    // create an array from the rooms
    $result_row = mysql_fetch_assoc($result);
    $rooms = explode(',', $result_row['rooms']);
    // delete each room
    foreach ($rooms as $roomToDelete) {
        if (!delete_dbRooms($roomToDelete)) {
            //error
            echo mysql_error() . " could not delete a room from roomLog\n";
            return false;
        }
        connect();
    }
    // Delete the entry
    $query = "DELETE FROM dbRoomLogs WHERE id ='" . $roomLogID . "'";
    $result = mysql_query($query);
    // Check if successful
    if (!$result) {
        //print an error
        echo mysql_error() . " Unable to delete dbRoomLog :" . $roomLogID . "\n";
        return false;
    }
    //Success
    return true;
}