function testdbPersonsModule()
 {
     // creates an empty dbPersons table
     $this->assertTrue(create_dbPersons());
     //creates some people to add to the database
     $person1 = new Person("Smith", "John", "123 College Street", "Brunswick", "ME", "04011", 2075551234, "", "*****@*****.**", "guest", "", "Jane Smith", "98-01-01", "parent", "");
     $person2 = new Person("Jones", "Bob", "100 Union Street", "Bangor", "ME", "04401", 2075555678, null, "*****@*****.**", "guest", "", "Dan Jones", "95-07-15", "grandfather", "");
     $person3 = new Person("Adams", "Will", "12 River Road", "Augusta", "ME", "04330", 207551212, 2075553434, "*****@*****.**", "socialworker", "", null, null, null, "");
     $person4 = new Person("Williams", "Elizabeth", "50 Main Street", "Portland", "ME", "04110", 2075555432, null, "*****@*****.**", "volunteer", "", null, null, null, "");
     $person5 = new Person("Roberts", "Jill", "200 Main Street", "Portland", "ME", "04110", 2075556666, 2075550000, "*****@*****.**", "manager", "", null, null, null, "");
     // tests the insert function
     $this->assertTrue(insert_dbPersons($person1));
     $this->assertTrue(insert_dbPersons($person2));
     $this->assertTrue(insert_dbPersons($person3));
     $this->assertTrue(insert_dbPersons($person4));
     $this->assertTrue(insert_dbPersons($person5));
     //tests the retrieve function
     $this->assertEqual(retrieve_dbPersons($person1->get_id())->get_id(), "John2075551234");
     $this->assertEqual(retrieve_dbPersons($person1->get_id())->get_first_name(), "John");
     $this->assertEqual(retrieve_dbPersons($person1->get_id())->get_last_name(), "Smith");
     $this->assertEqual(retrieve_dbPersons($person1->get_id())->get_address(), "123 College Street");
     $this->assertEqual(retrieve_dbPersons($person1->get_id())->get_city(), "Brunswick");
     $this->assertEqual(retrieve_dbPersons($person1->get_id())->get_state(), "ME");
     $this->assertEqual(retrieve_dbPersons($person1->get_id())->get_zip(), "04011");
     $this->assertEqual(retrieve_dbPersons($person1->get_id())->get_phone1(), 2075551234);
     $this->assertEqual(retrieve_dbPersons($person1->get_id())->get_phone2(), null);
     $this->assertEqual(retrieve_dbPersons($person1->get_id())->get_email(), "*****@*****.**");
     $this->assertEqual(retrieve_dbPersons($person1->get_id())->get_patient_name(), "Jane Smith");
     $this->assertEqual(retrieve_dbPersons($person1->get_id())->get_patient_birthdate(), "98-01-01");
     $this->assertEqual(retrieve_dbPersons($person1->get_id())->get_patient_relation(), "parent");
     $this->assertTrue(retrieve_dbPersons($person1->get_id())->check_type("guest"));
     //tests the update function
     $person2->set_address("5 Maine Street");
     $this->assertTrue(update_dbPersons($person2));
     $this->assertEqual(retrieve_dbPersons($person2->get_id())->get_address(), "5 Maine Street");
     $this->assertFalse(retrieve_dbPersons($person3->get_id())->check_type("guest"));
     $person3->add_type("guest");
     $this->assertTrue(update_dbPersons($person3));
     $p3 = retrieve_dbPersons($person3->get_id());
     $a = $p3->get_type();
     $this->assertTrue(retrieve_dbPersons($person3->get_id())->check_type("guest"));
     $this->assertTrue(retrieve_dbPersons($person3->get_id())->check_type("socialworker"));
     //tests the delete function
     $this->assertTrue(delete_dbPersons($person1->get_id()));
     $this->assertTrue(delete_dbPersons($person2->get_id()));
     $this->assertTrue(delete_dbPersons($person3->get_id()));
     $this->assertTrue(delete_dbPersons($person4->get_id()));
     $this->assertTrue(delete_dbPersons($person5->get_id()));
     $this->assertFalse(retrieve_dbPersons($person4->get_id()));
     echo "testdbPersons 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);
                }
            }
        }
    }
}
		<link rel="stylesheet" href="styles.css" type="text/css" />
	</head>
	<body>
		<div id="container">
			<?php 
include 'header.php';
?>
			<div id="content">
				<?php 
include_once 'database/dbPersons.php';
include_once 'domain/Person.php';
include_once 'database/dbBookings.php';
include_once 'domain/Booking.php';
include_once 'database/dbLog.php';
if ($_SESSION['_id'] != "guest") {
    $person = retrieve_dbPersons($_SESSION['_id']);
    $first_name = $person->get_first_name();
    echo "<p>Welcome, " . $first_name . ", to RMH Homeroom!";
} else {
    echo "<p>Welcome to RMH Homeroom!";
}
?>
				<p>
			    <?php 
if ($_SESSION['access_level'] == 0) {
    echo '<p> To request a room at the Ronald McDonald House, go <a href="' . $path . 'newBooking.php?id=' . 'new' . '">here</a>.';
}
?>

				<br>If you want to learn about this software, select <a href="<?php 
echo $path;
 function compute_agecounts($allBookings)
 {
     $this->agecounts = array();
     $this->agecounts["unknown"] = 0;
     $this->ageguestcounts = array();
     $this->ageguestcounts["unknown"] = 0;
     foreach ($allBookings as $aBooking) {
         $g = $aBooking->get_guest_id();
         $bGuest = retrieve_dbPersons($g);
         $bGuests = sizeof($aBooking->get_occupants());
         if ($bGuest && $bGuest->get_patient_birthdate() != "") {
             $bDate1 = mktime(0, 0, 0, substr($bGuest->get_patient_birthdate(), 3, 2), substr($bGuest->get_patient_birthdate(), 6, 2), substr($bGuest->get_patient_birthdate(), 0, 2));
             $bDate2 = mktime(0, 0, 0, substr($aBooking->get_date_out(), 3, 2), substr($aBooking->get_date_out(), 6, 2), substr($aBooking->get_date_out(), 0, 2));
             $bAge = ($bDate2 - $bDate1) / 31536000;
             // years = 365*60*60*24 seconds (approximately)
         } else {
             $bAge = "unknown";
         }
         if (!$this->agecounts[$bAge]) {
             $this->agecounts[$bAge] = 1;
             $this->ageguestcounts[$bAge] = $bGuests;
         } else {
             $this->agecounts[$bAge] += 1;
             $this->ageguestcounts[$bAge] += $bGuests;
         }
     }
 }
/**
* process_form sanitizes data, concatenates needed data, and enters it all into the database
*/
function process_form($id, $person)
{
    // 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();
    $first_name = trim(str_replace("'", "\\'", htmlentities(str_replace('&', 'and', $_POST['first_name']))));
    $last_name = trim(str_replace("'", "\\'", htmlentities($_POST['last_name'])));
    $address = trim(str_replace("'", "\\'", htmlentities($_POST['address'])));
    $city = trim(str_replace("'", "\\'", htmlentities($_POST['city'])));
    $state = $_POST['state'];
    $zip = trim(htmlentities($_POST['zip']));
    $phone1 = trim(str_replace(' ', '', htmlentities($_POST['phone1'])));
    $clean_phone1 = ereg_replace("[^0-9]", "", $phone1);
    $phone2 = trim(str_replace(' ', '', htmlentities($_POST['phone2'])));
    $clean_phone2 = ereg_replace("[^0-9]", "", $phone2);
    $email = trim(str_replace("'", "\\'", htmlentities($_POST['email'])));
    $patient_name = trim(str_replace("'", "\\'", htmlentities($_POST['patient_name'])));
    $patient_birthdate = $_POST['DateOfBirth_Year'] . '-' . $_POST['DateOfBirth_Month'] . '-' . $_POST['DateOfBirth_Day'];
    $patient_relation = trim(str_replace('\\\'', '\'', htmlentities($_POST['patient_relation'])));
    $type = implode(',', $_POST['type']);
    $prior_bookings = implode(',', $person->get_prior_bookings());
    $newperson = new Person($last_name, $first_name, $address, $city, $state, $zip, $clean_phone1, $clean_phone2, $email, $type, $prior_bookings, $patient_name, $patient_birthdate, $patient_relation, "");
    if (!retrieve_dbPersons($newperson->get_id())) {
        insert_dbPersons($newperson);
        return $newperson;
    } else {
        if ($_POST['deleteMe'] != "DELETE" && $_POST['reset_pass'] != "RESET") {
            update_dbPersons($newperson);
            return $newperson;
        }
    }
    //step two: try to make the deletion or password change
    if ($_POST['deleteMe'] == "DELETE") {
        $result = retrieve_dbPersons($id);
        if (!$result) {
            echo '<p>Unable to delete. ' . $first_name . ' ' . $last_name . ' is not in the database. <br>Please report this error to the House Manager.';
        } else {
            //What if they're the last remaining manager account?
            if (strpos($type, 'manager') !== false) {
                //They're a manager, we need to check that they can be deleted
                $managers = getall_type('manager');
                if (!$managers || mysql_num_rows($managers) <= 1) {
                    echo '<p class="error">You cannot remove the last remaining manager from the database.</p>';
                } else {
                    $result = delete_dbPersons($id);
                    echo "<p>You have successfully removed " . $first_name . " " . $last_name . " from the database.</p>";
                    if ($id == $_SESSION['_id']) {
                        session_unset();
                        session_destroy();
                    }
                }
            } else {
                $result = delete_dbPersons($id);
                echo "<p>You have successfully removed " . $first_name . " " . $last_name . " from the database.</p>";
                if ($id == $_SESSION['_id']) {
                    session_unset();
                    session_destroy();
                }
            }
            // Create the log message
            $message = "<a href='viewPerson.php?id=" . $_SESSION['_id'] . "'>" . $name . "</a>" . " has removed " . $first_name . " " . $last_name . " from the database";
            add_log_entry($message);
        }
        return $person;
    } else {
        if ($_POST['reset_pass'] == "RESET") {
            $id = $_POST['old_id'];
            // $result = delete_dbPersons($id);
            // $pass = $first_name . $phone1;
            $person = new Person($last_name, $first_name, $address, $city, $state, $zip, $clean_phone1, $clean_phone2, $email, $type, implode(',', $person->get_prior_bookings()), $patient_name, $patient_birthdate, $patient_relation, "");
            $result = insert_dbPersons($person);
            if (!$result) {
                echo '<p class="error">Unable to reset ' . $first_name . ' ' . $last_name . "'s password.. <br>Please report this error to the House Manager.";
            } else {
                echo "<p>You have successfully reset " . $first_name . " " . $last_name . "'s password.</p>";
                // Create the log message
                $message = "<a href='viewPerson.php?id=" . $_SESSION['_id'] . "'>" . $name . "</a>" . " has reset the password for <a href='viewPerson.php?id=" . $id . "'>" . $first_name . " " . $last_name . "</a>";
                add_log_entry($message);
            }
            return $person;
        }
    }
}
    display_navigation($date);
}
?>
			
			<!-- Display a list of pending bookings -->
			<h4 style="text-align:center"> Pending Bookings (and dates submitted)</h4>
			<form style="text-align:center" name="chooseBooking" action="viewBookings.php" target="_blank">
			<select name="bookingid">
			<?php 
// Grab a list of all pending bookings
$pendingBookings = retrieve_all_pending_dbBookings(date("y-m-d"));
if ($pendingBookings) {
    // Make each booking id a menu item
    foreach ($pendingBookings as $booking) {
        echo "<option value='" . $booking->get_id() . "'>";
        $person = retrieve_dbPersons(substr($booking->get_id(), 8));
        if ($person) {
            echo $person->get_first_name() . " " . $person->get_last_name() . " (" . date_string(substr($booking->get_id(), 0, 8)) . ")";
        } else {
            echo $booking->get_id();
        }
        echo "</option>";
    }
    // Then add a button
    echo "<input type=\"submit\" value=\"View Booking\"/>";
}
?>
			</select></form>
			
			<!-- Have an option for saving the room log -->
			<?php 
<?php

session_start();
session_cache_expire(30);
include_once 'database/dbPersons.php';
include_once 'domain/Person.php';
$id = $_GET["id"];
$person = retrieve_dbPersons($id);
?>
<!-- page generated by the BowdoinRMH software package -->
<html>
	<head>
		<title>
			Viewing <?php 
echo $person->get_first_name() . " " . $person->get_last_name();
?>
		</title>
		<link rel="stylesheet" href="styles.css" type="text/css" />
	</head>
	<body>
		<div id="container">
			<?php 
include 'header.php';
?>
			<div id="content">
				<?php 
if (!$person) {
    //there is no person
    echo '<p id="error">Error: there\'s no person with this id in the database</p>';
    include 'footer.inc';
    echo '</div></div></body></html>';
 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;
     }
 }
 echo '<hr size="1" width="30%" align="left">';
 // boolean to display admins
 echo '<p><table class="searchResults">';
 if (mysql_num_rows($result)) {
     echo '<tr><td class=searchResults><strong>Guest(s)</strong></td>';
 }
 echo "<td class=searchResults><strong>Patient</strong></td>";
 echo "<td class=searchResults><strong>Status</strong></td>";
 echo "<td class=searchResults><strong>Submitted</strong></td>";
 echo "<td class=searchResults><strong>Room</strong></td></tr>";
 while ($thisRow = mysql_fetch_array($result, MYSQL_ASSOC)) {
     // beging grabbing more results
     // Appends a 20 so it reads 2011-...
     $dateIn = "20" . substr($thisRow['date_submitted'], 0, 8);
     echo "<tr><td class=searchResults>";
     $primaryGuest = retrieve_dbPersons($thisRow['guest_id']);
     if ($primaryGuest) {
         $pFirstName = $primaryGuest->get_first_name();
         $pLastName = $primaryGuest->get_last_name();
         $string = $pFirstName . " " . $pLastName;
     }
     // Begin creating a row for each entry
     echo "<tr><td class=searchResults>" . $string . "</td>" . "<td class=searchResults>" . $thisRow['patient'] . "</td>" . "<td class=searchResults>" . $thisRow['status'] . "</td>" . "<td class=searchResults>" . $dateIn . "</td>" . "<td class=searchResults>" . $thisRow['room_no'] . "</td>" . "<td class=searchResults><a href=\"viewBookings.php?id=update&bookingid=" . $thisRow['id'] . "\">view</td>";
     if ($thisRow['status'] == "pending") {
         echo "<td class=searchResults><a href=viewBookings.php?id=delete&bookingid=" . $thisRow['id'] . ">delete</a></td>";
     } else {
         if ($thisRow['status'] == "closed") {
             echo "<td class=searchResults><a href=referralForm.php?id=" . $thisRow['guest_id'] . ">create new referral</a></td>";
         }
     }
     echo "</tr>";
function process_form()
{
    $first_name = trim(str_replace("'", "\\'", htmlentities(str_replace('&', 'and', $_POST['first_name_1']))));
    $last_name = trim(str_replace("'", "\\'", htmlentities($_POST['last_name_1'])));
    $address = trim(str_replace("'", "\\'", htmlentities($_POST['address_1'])));
    $city = trim(str_replace("'", "\\'", htmlentities($_POST['city_1'])));
    $state = $_POST['state_1'];
    $zip = trim(htmlentities($_POST['zip_1']));
    $phone1 = $_POST['phone1_area_1'] . $_POST['phone1_middle_1'] . $_POST['phone1_end_1'];
    $phone2 = $_POST['phone2_area_1'] . $_POST['phone2_middle_1'] . $_POST['phone2_end_1'];
    $email = trim(str_replace("'", "\\'", htmlentities($_POST['email_1'])));
    $patient_name = trim(str_replace("'", "\\'", htmlentities($_POST['patient_name'])));
    $patient_birthdate = $_POST['patient_birth_year'] . '-' . $_POST['patient_birth_month'] . '-' . $_POST['patient_birth_day'];
    $patient_relation = trim(str_replace('\\\'', '\'', htmlentities($_POST['patient_relation_1'])));
    $currentEntry = retrieve_dbPersons($first_name . $phone1);
    if (!$currentEntry) {
        $currentEntry = new Person($last_name, $first_name, $address, $city, $state, $zip, $phone1, $phone2, $email, "guest", "", $patient_name, $patient_birthdate, $patient_relation, "");
    } else {
        $currentEntry->set_patient_name($patient_name);
        $currentEntry->set_patient_birthdate($patient_birthdate);
        $currentEntry->set_patient_relation($patient_relation);
        $currentEntry->add_type("guest");
    }
    insert_dbPersons($currentEntry);
    return $currentEntry;
}
     $color = "Yellow";
 } elseif ($flag == "confirmed") {
     $color = "LightGreen";
 } elseif ($flag == "requires attention") {
     $color = "LightCoral";
 } elseif ($flag == "past arrival date") {
     $color = "LightGrey";
 }
 echo "<tr>";
 //prints the date submitted
 echo '<td align="center" bgcolor=' . $color . '>' . date_string($current_booking->get_date_submitted()) . '</td>' . '<td align="center" bgcolor=' . $color . '>';
 //pulls out array of primary guest id's
 $guest_id = $current_booking->get_guest_id();
 //prints the name of each primary guest as a
 //link to the corresponding viewPerson page
 $current_guest = retrieve_dbPersons($guest_id);
 //handles when no guest with the corresponding ID in databse
 if ($current_guest == false) {
     echo "Error: This booking contains a guestID for a person not in the database";
 } else {
     echo "<a href = viewPerson.php?id=" . $current_id . " >" . $current_guest->get_first_name() . " " . $current_guest->get_last_name() . " </a>";
 }
 //prints patient name
 echo '</td>' . '<td align="center" bgcolor=' . $color . '>' . $current_booking->get_patient() . '</td>';
 //pulls out date in
 $date = $current_booking->get_date_in();
 //formats date if not "Will Call"
 if ($date != "Will Call") {
     $date = date_string($date);
 }
 //prints datein and flag
					<li> Your Username is your first name followed by your phone number. ' . '';
    echo ' If you do not remember your Password, please contact the <a href="mailto:housemngr@rmhportland.org">House Manager</a>.</ul>';
    echo '<p><table><form method="post"><input type="hidden" name="_submit_check" value="true"><tr><td>Username:</td><td><input type="text" name="user" tabindex="1"></td></tr><tr><td>Password:</td><td><input type="password" name="pass" tabindex="2"></td></tr><tr><td colspan="2" align="center"><input type="submit" name="Login" value="Login"></td></tr></table>';
} else {
    //check if they logged in as a guest:
    //		if($_POST['user']=="guest" && $_POST['pass']==""){
    //			$_SESSION['logged_in']=1;
    //			$_SESSION['access_level']=0;
    //			$_SESSION['_id']="guest";
    //			echo "<script type=\"text/javascript\">window.location = \"index.php\";</script>";
    //		}
    //otherwise authenticate their password
    //		else {
    $db_pass = md5($_POST['pass']);
    $db_id = $_POST['user'];
    $person = retrieve_dbPersons($db_id);
    //	echo $person->get_id() . " = retrieved person_id<br>";
    if ($person) {
        //avoids null results
        if ($person->get_password() == $db_pass) {
            //if the passwords match, login
            $_SESSION['logged_in'] = 1;
            if (in_array('volunteer', $person->get_type())) {
                $_SESSION['access_level'] = 1;
            } else {
                if (in_array('socialworker', $person->get_type())) {
                    $_SESSION['access_level'] = 2;
                } else {
                    if (in_array('manager', $person->get_type())) {
                        $_SESSION['access_level'] = 3;
                    } else {