function testdbBookingsModule() { // create a booking and test inserting and retrieving it from dbBookings $today = date('y-m-d'); $b = new Booking($today, "", "Meghan2075551234", "pending", "", "Tiny", array("Meghan:mother", "Jean:father", "Teeny:sibling"), array(), "", "", "Millie2073631234", "Maine Med", "SCU", "00000000000", "\$10 per night", "", "", "", "new"); $this->assertTrue(insert_dbBookings($b)); $this->assertTrue(retrieve_dbBookings($b->get_id())); //$this->assertTrue(in_array("Meghan2077291234", $b->get_guest_id())); //checks that the initial status is "pending" $this->assertTrue(retrieve_dbBookings($b->get_id())->get_status(), "pending"); //checks that initial flag is "new" $this->assertTrue(retrieve_dbBookings($b->get_id())->get_flag(), "new"); $pending_bookings = retrieve_all_pending_dbBookings(); // $this->assertEqual($pending_bookings[0]->get_id(), $b->get_id()); // make some changes and test updating it in the database // Add a loaner to the booking $b->add_loaner("remote3"); $b->add_occupant("Jordan", "brother"); $b->set_flag("viewed"); $this->assertTrue($b->assign_room("126", $today)); $bretrieved = retrieve_dbBookings($b->get_id()); $this->assertTrue(in_array("Jordan: brother", $bretrieved->get_occupants())); $this->assertTrue(in_array("remote3", $bretrieved->get_loaners())); $this->assertEqual($bretrieved->get_status(), "active"); $this->assertEqual($bretrieved->get_id(), $b->get_id()); $this->assertEqual($bretrieved->get_room_no(), "126"); $today = date('y-m-d'); $this->assertEqual($bretrieved->get_date_in(), $today); $this->assertEqual($bretrieved->get_flag(), "viewed"); //tests updating after a checkout $this->assertTrue($bretrieved->check_out($today)); $bretrieved2 = retrieve_dbBookings($b->get_id()); $this->assertEqual($bretrieved2->get_status(), "closed"); $this->assertEqual($bretrieved2->get_date_out(), $today); //tests the delete function $this->assertTrue(delete_dbBookings($b->get_id())); $this->assertFalse(retrieve_dbBookings($b->get_id())); echo "testdbBookings complete"; }
function update_room_info($currentRoom) { // Get the info of the user who is making the update $user = retrieve_dbPersons($_SESSION['_id']); $name = $user->get_first_name() . " " . $user->get_last_name(); // Grab all of the variables and sanitize them $newBeds = sanitize($_POST['beds']); $newCapacity = sanitize($_POST['capacity']); $newBath = sanitize($_POST['bath']); if ($newBath == "Yes") { $newBath = "y"; } else { $newBath = "n"; } $newStatus = sanitize($_POST['status']); $newRoomNotes = sanitize($_POST['room_notes']); $newBooking = sanitize($_POST['assign_booking']); if ($newBooking == "Leave Room Unassigned" || $newBooking == "No") { // don't update the booking $newBooking = false; } // Now update the current room object. // Update the booking last // Note that the room class automatically updates the database // Only update the status if you're a volunteer or manager // social workers cannot edit rooms if ($_SESSION['access_level'] == 1 || $_SESSION['access_level'] == 3) { // add a log only if the status actually changed // then update the status if ($newStatus != $currentRoom->get_status() && $currentRoom->get_status() != "booked") { $currentRoom->set_status($newStatus); // Create the log message $message = "<a href='viewPerson.php?id=" . $_SESSION['_id'] . "'>" . $name . "</a>" . " has changed the status of <a href='room.php?room=" . $currentRoom->get_room_no() . "'>room " . $currentRoom->get_room_no() . "</a>"; add_log_entry($message); } } // Update everything else only if you're a manager if ($_SESSION['access_level'] == 3) { $currentRoom->set_beds($newBeds); $currentRoom->set_capacity($newCapacity); $currentRoom->set_bath($newBath); $currentRoom->set_room_notes($newRoomNotes); if ($newBooking) { // Checkout the booking if the option was selected if ($newBooking == "Yes") { $currentRoom->set_status("dirty"); //retrieve the booking and check it out $newBooking = retrieve_dbBookings($currentRoom->get_booking_id()); if ($newBooking) { $newBooking->check_out(date("y-m-d")); // Add a log to show that the family was checked out // Get the info of the primary guest $pGuest = retrieve_dbPersons($newBooking->get_guest_id()); if ($pGuest) { $guestName = $pGuest->get_first_name() . " " . $pGuest->get_last_name(); // Create the log message $message = "<a href='viewPerson.php?id=" . $_SESSION['_id'] . "'>" . $name . "</a>" . " has checked out <a href='viewPerson.php?id=" . $pGuests[0] . "'>" . $guestName . "</a>"; add_log_entry($message); } } } else { // retrieve the booking and update it $newBooking = retrieve_dbBookings($newBooking); //$newBooking->assign_room($currentRoom->get_room_no()); // Add a log to show that the family was checked in // Get the info of the primary guest $pGuest = retrieve_dbPersons($newBooking->get_guest_id()); $guestName = $pGuest->get_first_name() . " " . $pGuest->get_last_name(); // Create the log message $message = "<a href='viewPerson.php?id=" . $_SESSION['_id'] . "'>" . $name . "</a>" . " has checked in <a href='viewPerson.php?id=" . $pGuests[0] . "'>" . $guestName . "</a>"; // quick fix: don't add a log if the check in was not successful if ($newBooking->assign_room($currentRoom->get_room_no(), date('y-m-d'))) { add_log_entry($message); } } } } }
function build_POST_booking($primaryGuest, $referralid) { $current_date = date("y-m-d"); $referred_by = trim(str_replace("'", "\\'", htmlentities($_POST['referred_by']))); $hospital = trim(str_replace("'", "\\'", htmlentities($_POST['hospital']))); $department = trim(str_replace("'", "\\'", htmlentities($_POST['dept']))); if ($_POST['payment'] != "other") { $payment = "10 per night"; } else { $payment = trim(str_replace("'", "\\'", htmlentities($_POST['payment_description']))); } $notes = trim(str_replace("'", "\\'", htmlentities($_POST['notes']))); $healthvalues = array("flu", "shingles", "tb", "strep", "lice", "whoopingcough", "measles", "nomeaslesshot", "chickenpox", "chickenpoxshot", "hepatitisb"); $health_questions = ""; for ($i = 1; $i <= 11; $i++) { if ($_POST['health'] && in_array($healthvalues[$i - 1], $_POST['health'])) { $health_questions .= "1"; } else { $health_questions .= "0"; } } if ($_POST['visitOrWC'] == "Will Call") { $date_in = "Will Call"; } else { if ($_POST['date_in_year'] && $_POST['date_in_month'] && $_POST['date_in_day']) { $date_in = $_POST['date_in_year'] . '-' . $_POST['date_in_month'] . '-' . $_POST['date_in_day']; } } if ($referralid) { $pendingBooking = retrieve_dbBookings($referralid); $pendingBooking->set_health_questions($health_questions); $pendingBooking->set_payment_arrangement($payment); $pendingBooking->set_mgr_notes($notes); $pendingBooking->set_referred_by($referred_by); $pendingBooking->set_hospital($hospital); $pendingBooking->set_department($department); $pendingBooking->remove_occupants(); } else { $pendingBooking = new Booking($current_date, $date_in, $primaryGuest->get_id(), "pending", "", $primaryGuest->get_patient_name(), array(), array(), null, null, $referred_by, $hospital, $department, $health_questions, $payment, $_POST['overnight'], $_POST['day'], $notes, "new"); } $pendingBooking->add_occupant($primaryGuest->get_first_name() . " " . $primaryGuest->get_last_name(), $primaryGuest->get_patient_relation()); for ($count = 1; $count <= 4; $count++) { if ($_POST['additional_guest_' . $count] != "") { $pendingBooking->add_occupant($_POST['additional_guest_' . $count], $_POST['additional_guest_' . $count . '_relation']); } } insert_dbBookings($pendingBooking); return $pendingBooking; }
function close_booking($b_id) { $b = retrieve_dbBookings($b_id); $b->check_out($d); }