include_once ROOT_DIR . '/mail/functions.php';
include_once ROOT_DIR . '/domain/Family.php';
include_once ROOT_DIR . '/database/dbFamilyProfile.php';
error_log("in EditFamilyProfile");
$showForm = false;
$showResult = false;
$message = array();
// the first time the site is visited
// if the user clicked on the patient name in the table of family profiles, then a new request
// is sent with $id set to the family profile id, and this section of code is invoked
// function displayProfile( $familyProfile )//should this be pass by ref and set as const?
if (isset($_GET['id'])) {
    //gets the familyid passed down by the family profile search and when the profile is selected(clicked)
    $familyID = sanitize($_GET['id']);
    error_log("family profile id is {$familyID}");
    $familyProfile = retrieve_FamilyProfile($familyID);
    if ($familyProfile) {
        $showForm = TRUE;
    } else {
        echo ' cannot retrieve family profile record';
    }
}
// end stuff that is done the first time the form is visited
if (isset($_POST['form_token']) && validateTokenField($_POST)) {
    error_log('will process the editing form');
    //   $activityType = "Edit";
    $profileActitivityStatus = "Unconfirmed";
    //retrieves the sw, and gets id, firstname and lastname
    $currentUser = getUserProfileID();
    $sw = retrieve_UserProfile_SW($currentUser);
    // what if the current user is a RMH staff?
function familyProfileVar($familyID)
{
    $Profile = array();
    $familyProfile = retrieve_FamilyProfile($familyID);
    $Profile['parentfname'] = $familyProfile->get_parentfname();
    $Profile['parentlname'] = $familyProfile->get_parentlname();
    $Profile['parentemail'] = $familyProfile->get_parentemail();
    $Profile['parentphone1'] = $familyProfile->get_parentphone1();
    $Profile['parentphone2'] = $familyProfile->get_parentphone2();
    $Profile['parentAddr'] = $familyProfile->get_parentaddress();
    $Profile['parentcity'] = $familyProfile->get_parentcity();
    $Profile['parentstate'] = $familyProfile->get_parentstate();
    $Profile['parentzip'] = $familyProfile->get_parentzip();
    $Profile['parentcountry'] = $familyProfile->get_parentcountry();
    $Profile['patientfname'] = $familyProfile->get_patientfname();
    $Profile['patientlname'] = $familyProfile->get_patientlname();
    $Profile['patientrelation'] = $familyProfile->get_patientRelation();
    $Profile['patientdob'] = $familyProfile->get_patientdob();
    $Profile['patientformpdf'] = $familyProfile->get_patientformpdf();
    $Profile['patientnotes'] = $familyProfile->get_patientnotes();
    return $Profile;
}
 <tr>
 <th>#</th>
 <th>Begin Date</th>
 <th>End Date</th>
 <th>Parent Name</th>
 <th>Patient Name</th>
 <th>Social Worker</th>
 <th>Status</th>
 </thead>
 <tbody>';
 foreach ($theReservations as $reservation) {
     $beginDate = date('m/d/Y', strtotime($reservation->get_beginDate()));
     $endDate = date('m/d/Y', strtotime($reservation->get_endDate()));
     $parentName = $reservation->get_parentLastName() . ", " . $reservation->get_parentFirstName();
     $familyId = $reservation->get_familyProfileId();
     $family = retrieve_FamilyProfile($familyId);
     $patientName = $family->get_patientlname() . ", " . $family->get_patientfname();
     $swName = $reservation->get_swLastName() . ", " . $reservation->get_swFirstName();
     $status = $reservation->get_status();
     $numReservations++;
     echo '<tr>';
     echo '<td align="center"><b>' . $numReservations . '</b></font></td>
       <td align="center">' . $beginDate . '</td>
       <td align="center">' . $endDate . '</td>
       <td align="center">' . $parentName . '</td>
       <td align="center">' . $patientName . '</td>
       <td align="center">' . $swName . '</td>
       <td align="center">' . $status . '</td>';
     echo '</tr>';
 }
 echo '</table>';
$showForm = false;
$showResult = false;
$message = array();
error_log("in referralForm");
//get family values from database to fill into form
if (isset($_GET['id'])) {
    $familyID = sanitize($_GET['id']);
    $family = retrieve_FamilyProfile($familyID);
    $patientfname = $family->get_patientfname();
    $patientlname = $family->get_patientlname();
    $patientnotes = $family->get_patientnotes();
    $parentfname = $family->get_parentfname();
    $parentlname = $family->get_parentlname();
    setFamilyID($familyID);
} else {
    $family = retrieve_FamilyProfile($_SESSION['familyID']);
    $patientfname = $family->get_patientfname();
    $patientlname = $family->get_patientlname();
    $patientnotes = $family->get_patientnotes();
    $parentfname = $family->get_parentfname();
    $parentlname = $family->get_parentlname();
}
//if token works
if (isset($_POST['form_token']) && validateTokenField($_POST)) {
    //startDate is not set
    if (empty($_POST['begindate'])) {
        $message['BeginningDate'] = '<p><font color="red">You must select a beginning date!</font></p>';
        $showForm = true;
    }
    //endDate is not set
    if (empty($_POST['enddate'])) {
function FamilyConfirm($familyID, $StartDate, $EndDate, $tempURL)
{
    $family = retrieve_FamilyProfile($familyID);
    $familyname = $family->get_parentlname();
    $subject = "The  Room request for {$familyname} has been confimred ";
    $message = "Your request has been confirmed for {$StartDate}-{$EndDate}, go to {$tempURL} for more details";
    $to = $family->get_parentemail();
    email($to, $subject, $message);
}