*/
if (!defined("PARENT_INCLUDED") || !defined("IN_CONFIGURATION")) {
    exit;
} elseif (!isset($_SESSION["isAuthorized"]) || !$_SESSION["isAuthorized"]) {
    header("Location: " . ENTRADA_URL);
    exit;
} elseif (!$ENTRADA_ACL->amIAllowed('configuration', 'read')) {
    $ONLOAD[] = "setTimeout('window.location=\\'" . ENTRADA_URL . "/admin/" . $MODULE . "\\'', 15000)";
    $ERROR++;
    $ERRORSTR[] = "Your account does not have the permissions required to use this feature of this module.<br /><br />If you believe you are receiving this message in error please contact <a href=\"mailto:" . html_encode($AGENT_CONTACTS["administrator"]["email"]) . "\">" . html_encode($AGENT_CONTACTS["administrator"]["name"]) . "</a> for assistance.";
    echo display_error();
    application_log("error", "Group [" . $_SESSION["permissions"][$ENTRADA_USER->getAccessId()]["group"] . "] and role [" . $_SESSION["permissions"][$ENTRADA_USER->getAccessId()]["role"] . "] does not have access to this module [" . $MODULE . "]");
} else {
    if (defined("IN_CONFIGURATION") && IN_CONFIGURATION && (defined("EDIT_RESTRICTED_DAY") && EDIT_RESTRICTED_DAY || defined("ADD_RESTRICTED_DAY") && ADD_RESTRICTED_DAY)) {
        if (isset($day_id)) {
            $day = Models_RestrictedDays::fetchRow($day_id);
        } else {
            $day = new Models_RestrictedDays();
        }
        switch ($STEP) {
            case 2:
                if (isset($day_id)) {
                    $PROCESSED["orday_id"] = $day_id;
                }
                if (isset($_POST["date_type"]) && in_array($_POST["date_type"], array("specific", "weekly", "monthly", "yearly"))) {
                    $PROCESSED["date_type"] = $_POST["date_type"];
                } else {
                    add_error("The <strong>Date Type</strong> field is required.");
                }
                switch ($PROCESSED["date_type"]) {
                    case "specific":
    header("Location: " . ENTRADA_URL);
    exit;
} elseif (!$ENTRADA_ACL->amIAllowed('configuration', 'delete', false)) {
    $ONLOAD[] = "setTimeout('window.location=\\'" . ENTRADA_URL . "/admin/" . $MODULE . "\\'', 15000)";
    $ERROR++;
    $ERRORSTR[] = "Your account does not have the permissions required to use this feature of this module.<br /><br />If you believe you are receiving this message in error please contact <a href=\"mailto:" . html_encode($AGENT_CONTACTS["administrator"]["email"]) . "\">" . html_encode($AGENT_CONTACTS["administrator"]["name"]) . "</a> for assistance.";
    echo display_error();
    application_log("error", "Group [" . $_SESSION["permissions"][$ENTRADA_USER->getAccessId()]["group"] . "] and role [" . $_SESSION["permissions"][$ENTRADA_USER->getAccessId()]["role"] . "] does not have access to this module [" . $MODULE . "]");
} else {
    $BREADCRUMB[] = array("url" => ENTRADA_URL . "/admin/settings/manage/restricteddays?org=" . $ORGANISATION_ID . "&section=delete", "title" => "Delete Restricted Days");
    echo "<h1>Delete Restricted Days</h1>";
    if (isset($_POST["remove_ids"])) {
        foreach ($_POST["remove_ids"] as $day_id) {
            if ($tmp_input = clean_input($day_id, "numeric")) {
                $PROCESSED["delete"][] = $tmp_input;
                $days[] = Models_RestrictedDays::fetchRow($tmp_input);
            }
        }
    }
    switch ($STEP) {
        case 2:
            foreach ($days as $day) {
                $day_data = $day->toArray();
                $day_data["day_active"] = 0;
                if ($day->fromArray($day_data)->update()) {
                    add_statistic("restricted_days", "delete", "orday_id", $day->getID(), $ENTRADA_USER->getID());
                    if (!$ERROR) {
                        add_success("Successfully deleted the restricted day '<strong>" . $day->getName() . "</strong>'. You will now be redirected to the restricted days index; this will happen <strong>automatically</strong> in 5 seconds or <a href=\"" . ENTRADA_URL . "/admin/settings/manage/restricteddays?org=" . $ORGANISATION_ID . "\"><strong>click here</strong></a> to continue.");
                    }
                } else {
                    add_error("Failed to delete the restricted day '<strong>" . $day->getName() . "</strong>', an Administrator has been informed, please try again later. You will now be redirected to the restricted days index; this will happen <strong>automatically</strong> in 5 seconds or <a href=\"" . ENTRADA_URL . "/admin/settings/manage/restricteddays?org=" . $ORGANISATION_ID . "\"><strong>click here</strong></a> to continue.");