$ERRORSTR[] = "In order to reject an accommodation you must provide a detailed explanation as to why this accommodation is unacceptable to you.";
         }
         if (!$ERROR) {
             $query = "DELETE FROM `" . CLERKSHIP_DATABASE . "`.`apartment_schedule` WHERE `aschedule_id` = " . $db->qstr($ASCHEDULE_ID) . " AND `apartment_id` = " . $db->qstr($APARTMENT_INFO["apartment_id"]) . " AND `proxy_id` = " . $db->qstr($ENTRADA_USER->getID());
             if ($db->Execute($query) && $db->Affected_Rows() == 1) {
                 if ($EVENT_INFO && $EVENT_INFO["event_id"]) {
                     /**
                      * Reset the requires_apartment flag so this person is put back on the Regional Education dashboard.
                      */
                     if (!$db->AutoExecute(CLERKSHIP_DATABASE . ".events", array("requires_apartment" => 1), "UPDATE", "event_id=" . $db->qstr($EVENT_INFO["event_id"]))) {
                         application_log("error", "Unable to set requires_apartment to 1 for event_id [" . $EVENT_INFO["event_id"] . "] after proxy_id [" . $ENTRADA_USER->getID() . "] rejeceted aschedule_id [" . $ASCHEDULE_ID . "]. Database said: " . $db->ErrorMsg());
                     }
                 }
                 $message_variables = array("to_fullname" => $AGENT_CONTACTS["agent-regionaled"][$APARTMENT_INFO["department_id"]]["name"], "from_firstname" => $_SESSION["details"]["firstname"], "from_lastname" => $_SESSION["details"]["lastname"], "region" => $APARTMENT_INFO["region_name"], "reason" => $rejection_reason, "apartment_address" => strip_tags($apartment_address), "inhabiting_start" => date(DEFAULT_DATE_FORMAT, $APARTMENT_INFO["inhabiting_start"]), "inhabiting_finish" => date(DEFAULT_DATE_FORMAT, $APARTMENT_INFO["inhabiting_finish"]), "application_name" => APPLICATION_NAME, "department_id" => $APARTMENT_INFO["department_id"]);
                 $recipient = array("email" => $AGENT_CONTACTS["agent-regionaled"][$APARTMENT_INFO["department_id"]]["email"], "firstname" => $AGENT_CONTACTS["agent-regionaled"][$APARTMENT_INFO["department_id"]]["name"], "lastname" => "Contact");
                 regionaled_apartment_notification("rejected", $recipient, $message_variables);
             } else {
                 application_log("error", "Unable to delete aschedule_id [" . $ASCHEDULE_ID . "] from the database when an accommodation was rejected. Database said: " . $db->ErrorMsg());
                 $ERROR++;
                 $ERRORSTR[] = "We were unable to complete the accommodation rejection at this time. The system administrator was notified of this error, please try again later or contact the " . $APARTMENT_INFO["department_title"] . " Office directly.";
             }
         }
         if (!$ERROR) {
             header("Location: " . ENTRADA_URL . "/regionaled");
             exit;
         }
     }
     break;
 default:
     continue;
     break;
                /**
                 * Reset the requires_apartment flag so this person is put back on the Regional Education dashboard.
                 */
                if (!$db->AutoExecute(CLERKSHIP_DATABASE . ".events", array("requires_apartment" => 1), "UPDATE", "event_id=" . $db->qstr($ASCHEDULE_INFO["event_id"]))) {
                    $NOTICE++;
                    $NOTICESSTR[] = "We were unable to add this learners event back onto the " . $APARTMENT_INFO["department_title"] . " dashboard as a todo task.";
                    application_log("error", "Unable to set requires_apartment to 1 for event_id [" . $ASCHEDULE_INFO["event_id"] . "] after proxy_id [" . $ASCHEDULE_INFO["proxy_id"] . "] had been removed from aschedule_id [" . $ASCHEDULE_ID . "]. Database said: " . $db->ErrorMsg());
                }
            }
            if (isset($_POST["notify"]) && (int) $_POST["notify"] == 1) {
                $apartment_address = ($APARTMENT_INFO["apartment_number"] != "" ? $APARTMENT_INFO["apartment_number"] . "-" : "") . $APARTMENT_INFO["apartment_address"] . "\n";
                $apartment_address .= $APARTMENT_INFO["region_name"] . ($APARTMENT_INFO["province"] ? ", " . $APARTMENT_INFO["province"] : "") . "\n";
                $apartment_address .= $APARTMENT_INFO["apartment_postcode"] . ", " . $APARTMENT_INFO["country"];
                $message_variables = array("to_firstname" => $ASCHEDULE_INFO["firstname"], "to_lastname" => $ASCHEDULE_INFO["lastname"], "from_firstname" => $_SESSION["details"]["firstname"], "from_lastname" => $_SESSION["details"]["lastname"], "region" => $APARTMENT_INFO["region_name"], "apartment_address" => $apartment_address, "inhabiting_start" => date(DEFAULT_DATE_FORMAT, $ASCHEDULE_INFO["inhabiting_start"]), "inhabiting_finish" => date(DEFAULT_DATE_FORMAT, $ASCHEDULE_INFO["inhabiting_finish"]), "application_name" => APPLICATION_NAME, "department_title" => $APARTMENT_INFO["department_title"], "department_id" => $APARTMENT_INFO["department_id"]);
                $recipient = array("email" => $ASCHEDULE_INFO["email"], "firstname" => $ASCHEDULE_INFO["firstname"], "lastname" => $ASCHEDULE_INFO["lastname"]);
                regionaled_apartment_notification("delete", $recipient, $message_variables);
            }
        } else {
            $ERROR++;
            $ERRORSTR[] = "Unable to remove <strong>" . html_encode($ASCHEDULE_INFO["firstname"] . " " . $ASCHEDULE_INFO["lastname"]) . "</strong> from <strong>" . html_encode($APARTMENT_INFO["apartment_title"]) . "</strong> at this time. The system administrator has been notified of this issue, please try again later.<br /><br />You will now be redirected to the apartment schedule; this will happen <strong>automatically</strong> in 5 seconds or <a href=\"" . ENTRADA_URL . $url . "\" style=\"font-weight: bold\">click here</a> to continue.";
            application_log("error", "Unable to remove proxy_id [" . $ASCHEDULE_INFO["proxy_id"] . "] from apartment_id [" . $APARTMENT_ID . "] / aschedule_id [" . $ASCHEDULE_ID . "]. Database said: " . $db->ErrorMsg());
        }
    } else {
        $url = "/admin/regionaled/apartments/manage/schedule?id=" . $APARTMENT_ID . "&sid=" . $ASCHEDULE_ID;
        $ERROR++;
        $ERRORSTR[] = "You must confirm that you wish to remove <strong>" . html_encode($ASCHEDULE_INFO["firstname"] . " " . $ASCHEDULE_INFO["lastname"]) . "</strong> from <strong>" . html_encode($APARTMENT_INFO["apartment_title"]) . "</strong>.<br /><br />You will now be redirected to the apartment schedule; this will happen <strong>automatically</strong> in 5 seconds or <a href=\"" . ENTRADA_URL . $url . "\" style=\"font-weight: bold\">click here</a> to continue.";
        application_log("error", "The remove request for proxy_id [" . $ASCHEDULE_INFO["proxy_id"] . "] from apartment_id [" . $APARTMENT_ID . "] / aschedule_id [" . $ASCHEDULE_ID . "] was not confirmed. This step shouldn't have been accessible otherwise.");
    }
    $ONLOAD[] = "setTimeout('window.location=\\'" . ENTRADA_URL . $url . "\\'', 5000)";
    display_status_messages();
}
    application_log("error", "Group [" . $GROUP . "] and role [" . $ROLE . "] does not have access to this module [" . $MODULE . "]");
} else {
    if (isset($_POST["remind"]) && is_array($_POST["remind"]) && count($_POST["remind"])) {
        $recipients = array();
        foreach ($_POST["remind"] as $aschedule_id) {
            $aschedule_id = clean_input($aschedule_id, array("nows", "int"));
            if ($aschedule_id) {
                $query = "\tSELECT a.*, c.`region_name`, d.`firstname`, d.`lastname`, d.`email`, g.`department_id`, g.`department_title`\n\t\t\t\t\t\t\tFROM `" . CLERKSHIP_DATABASE . "`.`apartment_schedule` AS a\n\t\t\t\t\t\t\tLEFT JOIN `" . CLERKSHIP_DATABASE . "`.`apartments` AS b\n\t\t\t\t\t\t\tON b.`apartment_id` = a.`apartment_id`\n\t\t\t\t\t\t\tLEFT JOIN `" . CLERKSHIP_DATABASE . "`.`regions` AS c\n\t\t\t\t\t\t\tON c.`region_id` = b.`region_id`\n\t\t\t\t\t\t\tLEFT JOIN `" . AUTH_DATABASE . "`.`user_data` AS d\n\t\t\t\t\t\t\tON d.`id` = a.`proxy_id`\n\t\t\t\t\t\t\tLEFT JOIN `" . CLERKSHIP_DATABASE . "`.`apartment_contacts` AS f\n\t\t\t\t\t\t\tON a.`apartment_id` = f.`apartment_id`\n\t\t\t\t\t\t\tLEFT JOIN `" . AUTH_DATABASE . "`.`departments` AS g\n\t\t\t\t\t\t\tON f.`department_id` = g.`department_id`\n\t\t\t\t\t\t\tWHERE a.`aschedule_id` = " . $db->qstr($aschedule_id) . "\n\t\t\t\t\t\t\tAND a.`proxy_id` > 0\n\t\t\t\t\t\t\tAND a.`confirmed` = 0\n\t\t\t\t\t\t\tAND f.`proxy_id` = " . $db->qstr($ENTRADA_USER->getId());
                $result = $db->GetRow($query);
                if ($result) {
                    /**
                     * Resend notification to the selected learner that they are required to confirm their apartment status.
                     */
                    $recipient = array("email" => $result["email"], "firstname" => $result["firstname"], "lastname" => $result["lastname"]);
                    $message_variables = array("to_firstname" => $recipient["firstname"], "to_lastname" => $recipient["lastname"], "from_firstname" => $_SESSION["details"]["firstname"], "from_lastname" => $_SESSION["details"]["lastname"], "region" => $result["region_name"], "confirmation_url" => ENTRADA_URL . "/regionaled/view?id=" . $aschedule_id, "application_name" => APPLICATION_NAME, "department_title" => $result["department_title"], "department_id" => $result["department_id"]);
                    if (regionaled_apartment_notification("confirmation", $recipient, $message_variables)) {
                        $recipients[] = html_encode($recipient["firstname"] . " " . $recipient["lastname"] . " <" . $recipient["email"] . ">");
                    }
                }
            }
        }
        $url = ENTRADA_URL . "/admin/regionaled";
        if (count($recipients)) {
            $SUCCESS++;
            $SUCCESSSTR[$SUCCESS] = "You have successfully sent accommodation confirmation reminder e-mails to the following recipients:\n";
            $SUCCESSSTR[$SUCCESS] .= "<ul>\n";
            $SUCCESSSTR[$SUCCESS] .= "\t<li>" . implode("</li>\n<li>", $recipients) . "</li>\n";
            $SUCCESSSTR[$SUCCESS] .= "</ul>";
            $SUCCESSSTR[$SUCCESS] .= "<p>You will now be redirected to the " . $result["department_titile"] . " dashboard; this will happen <strong>automatically</strong> in 15 seconds or <a href=\"" . $url . "\" style=\"font-weight: bold\">click here</a> to continue.</p>";
        }
        $ONLOAD[] = "setTimeout('window.location=\\'" . $url . "\\'', 15000)";