<?php

class RDI extends Base {

    // Variables.

    private $current_user_serial = 0;
    private $current_user_id = "";
    private $current_user_name = "";
    private $current_user_email = "";
    private $pagination_size = 20;
    private $pagination_page = 1;

    // =================
    // Class Constructor
    // =================

    public function __construct() {

        set_error_handler(array($this, "displayError"));

        date_default_timezone_set(self::TIMEZONE);

        $this->current_user_serial = $_SESSION[self::USER_SERIAL] ?? 0;
        $this->current_user_id = $_SESSION[self::USER_ID] ?? "";
        $this->current_user_name = $_SESSION[self::USER_NAME] ?? "";
        $this->current_user_email = $_SESSION[self::USER_EMAIL] ?? "";

        $this->pagination_page = $_SESSION[self::PAGINATION_PAGE] ?? 1;
    }

    // ==========
    // Manage RDI
    // ==========

    public function manageRDI() {

        $rdi = $this->getRDIPage();
        $popovers = (new Popovers())->getPopovers();

        $XML = $this->mergeXML($rdi, "<XML/>");
        $XML = $this->mergeXML($popovers, $XML);

        $content = $this->applyXSL($XML, $this->getXSL("manageRDI"));

        $this->displayContent($content);
    }

    // =======
    // Add RDI
    // =======

    public function addRDI() {

        $step = filter_input(INPUT_POST, "step") ?: "prompt";

        switch ($step) {

            case "prompt":

                $constants = $this->getConstants();
                $counties = (new Counties())->getCounties();

                $XML = $this->mergeXML($constants, "<XML/>");
                $XML = $this->mergeXML($counties, $XML);

                $content = $this->applyXSL($XML, $this->getXSL("addRDI"));

                $this->displayContent($content);

                break;

            case "add":

                $rdi_permit_facts_id = filter_input(INPUT_POST, "rdi_permit_facts_id", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_permit_number = filter_input(INPUT_POST, "rdi_permit_number") ?: '';
                $rdi_entry_date = filter_input(INPUT_POST, "rdi_entry_date") ?: '';
                $rdi_permit_date = filter_input(INPUT_POST, "rdi_permit_date") ?: '';
                $rdi_sub_div_name = filter_input(INPUT_POST, "rdi_sub_div_name") ?: '';
                $rdi_project_type = filter_input(INPUT_POST, "rdi_project_type") ?: '';
                $rdi_county = filter_input(INPUT_POST, "rdi_county") ?: '';
                $rdi_company = filter_input(INPUT_POST, "rdi_company") ?: '';
                $rdi_phone = filter_input(INPUT_POST, "rdi_phone") ?: '';
                $rdi_project_addr = filter_input(INPUT_POST, "rdi_project_addr") ?: '';
                $rdi_city = filter_input(INPUT_POST, "rdi_city") ?: '';
                $rdi_state = filter_input(INPUT_POST, "rdi_state") ?: '';
                $rdi_zip = filter_input(INPUT_POST, "rdi_zip", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_project_city = filter_input(INPUT_POST, "rdi_project_city") ?: '';
                $rdi_project_state = filter_input(INPUT_POST, "rdi_project_state") ?: '';
                $rdi_value = filter_input(INPUT_POST, "rdi_value", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_lot = filter_input(INPUT_POST, "rdi_lot", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_dist_ll = filter_input(INPUT_POST, "rdi_dist_ll", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_owner_name = filter_input(INPUT_POST, "rdi_owner_name") ?: '';
                $rdi_owner_phone = filter_input(INPUT_POST, "rdi_owner_phone", FILTER_SANITIZE_NUMBER_INT) ?: '';
                $rdi_owner_address = filter_input(INPUT_POST, "rdi_owner_address") ?: '';
                $rdi_owner_city = filter_input(INPUT_POST, "rdi_owner_city") ?: '';
                $rdi_owner_state = filter_input(INPUT_POST, "rdi_owner_state") ?: '';
                $rdi_owner_zip = filter_input(INPUT_POST, "rdi_owner_zip", FILTER_SANITIZE_NUMBER_INT) ?: '';
                $rdi_size = filter_input(INPUT_POST, "rdi_size", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_units = filter_input(INPUT_POST, "rdi_units", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_building_type = filter_input(INPUT_POST, "rdi_building_type", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_work_type = filter_input(INPUT_POST, "rdi_work_type", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_ct1 = filter_input(INPUT_POST, "rdi_ct1", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_ytd_permits = filter_input(INPUT_POST, "rdi_ytd_permits", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_ytd_value = filter_input(INPUT_POST, "rdi_ytd_value") ?: 0;
                $rdi_12mth_prev_permits = filter_input(INPUT_POST, "rdi_12mth_prev_permits", FILTER_SANITIZE_NUMBER_INT) ?: 0;

                $rdi_entry_date = date("Y-m-d", strtotime($rdi_entry_date));
                $rdi_permit_date = date("Y-m-d", strtotime($rdi_permit_date));
                $rdi_value = str_replace(",", "", $rdi_value);

                $SQL = "INSERT INTO rdis (
                                    rdi_permit_facts_id,
                                    rdi_permit_number,
                                    rdi_entry_date,
                                    rdi_permit_date,
                                    rdi_sub_div_name,
                                    rdi_project_type,
                                    rdi_county,
                                    rdi_company,
                                    rdi_phone,
                                    rdi_project_addr,
                                    rdi_city,
                                    rdi_state,
                                    rdi_zip,
                                    rdi_project_city,
                                    rdi_project_state,
                                    rdi_value,
                                    rdi_lot,
                                    rdi_dist_ll,
                                    rdi_owner_name,
                                    rdi_owner_phone,
                                    rdi_owner_address,
                                    rdi_owner_city,
                                    rdi_owner_state,
                                    rdi_owner_zip,
                                    rdi_size,
                                    rdi_units,
                                    rdi_building_type,
                                    rdi_work_type,
                                    rdi_ct1,
                                    rdi_ytd_permits,
                                    rdi_ytd_value,
                                    rdi_12mth_prev_permits
                        ) VALUES (
                                    :rdi_permit_facts_id,
                                    :rdi_permit_number,
                                    :rdi_entry_date,
                                    :rdi_permit_date,
                                    :rdi_sub_div_name,
                                    :rdi_project_type,
                                    :rdi_county,
                                    :rdi_company,
                                    :rdi_phone,
                                    :rdi_project_addr,
                                    :rdi_city,
                                    :rdi_state,
                                    :rdi_zip,
                                    :rdi_project_city,
                                    :rdi_project_state,
                                    :rdi_value,
                                    :rdi_lot,
                                    :rdi_dist_ll,
                                    :rdi_owner_name,
                                    :rdi_owner_phone,
                                    :rdi_owner_address,
                                    :rdi_owner_city,
                                    :rdi_owner_state,
                                    :rdi_owner_zip,
                                    :rdi_size,
                                    :rdi_units,
                                    :rdi_building_type,
                                    :rdi_work_type,
                                    :rdi_ct1,
                                    :rdi_ytd_permits,
                                    :rdi_ytd_value,
                                    :rdi_12mth_prev_permits
                                )";

                $statement = $this->connect()->prepare($SQL);

                $statement->bindValue(":rdi_permit_facts_id", $rdi_permit_facts_id);
                $statement->bindValue(":rdi_permit_number", $rdi_permit_number);
                $statement->bindValue(":rdi_entry_date", $rdi_entry_date);
                $statement->bindValue(":rdi_permit_date", $rdi_permit_date);
                $statement->bindValue(":rdi_sub_div_name", $rdi_sub_div_name);
                $statement->bindValue(":rdi_project_type", $rdi_project_type);
                $statement->bindValue(":rdi_county", $rdi_county);
                $statement->bindValue(":rdi_company", $rdi_company);
                $statement->bindValue(":rdi_phone", $rdi_phone);
                $statement->bindValue(":rdi_project_addr", $rdi_project_addr);
                $statement->bindValue(":rdi_city", $rdi_city);
                $statement->bindValue(":rdi_state", $rdi_state);
                $statement->bindValue(":rdi_zip", $rdi_zip);
                $statement->bindValue(":rdi_project_city", $rdi_project_city);
                $statement->bindValue(":rdi_project_state", $rdi_project_state);
                $statement->bindValue(":rdi_value", $rdi_value);
                $statement->bindValue(":rdi_lot", $rdi_lot);
                $statement->bindValue(":rdi_dist_ll", $rdi_dist_ll);
                $statement->bindValue(":rdi_owner_name", $rdi_owner_name);
                $statement->bindValue(":rdi_owner_phone", $rdi_owner_phone);
                $statement->bindValue(":rdi_owner_address", $rdi_owner_address);
                $statement->bindValue(":rdi_owner_city", $rdi_owner_city);
                $statement->bindValue(":rdi_owner_state", $rdi_owner_state);
                $statement->bindValue(":rdi_owner_zip", $rdi_owner_zip);
                $statement->bindValue(":rdi_size", $rdi_size);
                $statement->bindValue(":rdi_units", $rdi_units);
                $statement->bindValue(":rdi_building_type", $rdi_building_type);
                $statement->bindValue(":rdi_work_type", $rdi_work_type);
                $statement->bindValue(":rdi_ct1", $rdi_ct1);
                $statement->bindValue(":rdi_ytd_permits", $rdi_ytd_permits);
                $statement->bindValue(":rdi_ytd_value", $rdi_ytd_value);
                $statement->bindValue(":rdi_12mth_prev_permits", $rdi_12mth_prev_permits);

                $statement->execute();

                break;

            default:

                $this->displayHome();
        }
    }

    // ==========
    // Delete RDI
    // ==========

    public function deleteRDI() {

        $rdi_serial = filter_input(INPUT_POST, "rdi_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;

        $rdi = $this->getRDI($rdi_serial);

        if ($rdi->count() == 0) {
            $this->logError("Invalid RDI ({$rdi_serial}). " . __METHOD__);
        }

        $SQL = "delete from rdis
                  where rdi_serial = {$rdi_serial}";

        $this->executeSQL($SQL);
    }

    // ==========
    // Edit a RDI
    // ==========

    public function editRDI() {

        $step = filter_input(INPUT_POST, "step") ?: "prompt";

        switch ($step) {

            case "prompt":

                $rdi_serial = filter_input(INPUT_POST, "rdi_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;

                $rdi = $this->getRDI($rdi_serial);

                if ($rdi->count() == 0) {
                    $this->logError("Invalid RDI ({$rdi_serial}). " . __METHOD__);
                }

                $constants = $this->getConstants();
                $counties = (new Counties())->getCounties();

                $XML = $this->mergeXML($rdi, "<XML/>");
                $XML = $this->mergeXML($constants, $XML);
                $XML = $this->mergeXML($counties, $XML);

                $content = $this->applyXSL($XML, $this->getXSL("editRDI"));
                $this->displayContent($content);

                break;

            case "update":

                $rdi_serial = filter_input(INPUT_POST, "rdi_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_permit_facts_id = filter_input(INPUT_POST, "rdi_permit_facts_id", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_permit_number = filter_input(INPUT_POST, "rdi_permit_number") ?: '';
                $rdi_entry_date = filter_input(INPUT_POST, "rdi_entry_date") ?: '';
                $rdi_permit_date = filter_input(INPUT_POST, "rdi_permit_date") ?: '';
                $rdi_sub_div_name = filter_input(INPUT_POST, "rdi_sub_div_name") ?: '';
                $rdi_project_type = filter_input(INPUT_POST, "rdi_project_type") ?: '';
                $rdi_county = filter_input(INPUT_POST, "rdi_county") ?: '';
                $rdi_company = filter_input(INPUT_POST, "rdi_company") ?: '';
                $rdi_phone = filter_input(INPUT_POST, "rdi_phone") ?: '';
                $rdi_project_addr = filter_input(INPUT_POST, "rdi_project_addr") ?: '';
                $rdi_city = filter_input(INPUT_POST, "rdi_city") ?: '';
                $rdi_state = filter_input(INPUT_POST, "rdi_state") ?: '';
                $rdi_zip = filter_input(INPUT_POST, "rdi_zip", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_project_city = filter_input(INPUT_POST, "rdi_project_city") ?: '';
                $rdi_project_state = filter_input(INPUT_POST, "rdi_project_state") ?: '';
                $rdi_value = filter_input(INPUT_POST, "rdi_value", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_lot = filter_input(INPUT_POST, "rdi_lot", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_dist_ll = filter_input(INPUT_POST, "rdi_dist_ll", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_owner_name = filter_input(INPUT_POST, "rdi_owner_name") ?: '';
                $rdi_owner_phone = filter_input(INPUT_POST, "rdi_owner_phone", FILTER_SANITIZE_NUMBER_INT) ?: '';
                $rdi_owner_address = filter_input(INPUT_POST, "rdi_owner_address") ?: '';
                $rdi_owner_city = filter_input(INPUT_POST, "rdi_owner_city") ?: '';
                $rdi_owner_state = filter_input(INPUT_POST, "rdi_owner_state") ?: '';
                $rdi_owner_zip = filter_input(INPUT_POST, "rdi_owner_zip", FILTER_SANITIZE_NUMBER_INT) ?: '';
                $rdi_size = filter_input(INPUT_POST, "rdi_size", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_units = filter_input(INPUT_POST, "rdi_units", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_building_type = filter_input(INPUT_POST, "rdi_building_type", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_work_type = filter_input(INPUT_POST, "rdi_work_type", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_ct1 = filter_input(INPUT_POST, "rdi_ct1", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_ytd_permits = filter_input(INPUT_POST, "rdi_ytd_permits", FILTER_SANITIZE_NUMBER_INT) ?: 0;
                $rdi_ytd_value = filter_input(INPUT_POST, "rdi_ytd_value") ?: 0;
                $rdi_12mth_prev_permits = filter_input(INPUT_POST, "rdi_12mth_prev_permits", FILTER_SANITIZE_NUMBER_INT) ?: 0;

                $rdi_entry_date = date("Y-m-d", strtotime($rdi_entry_date));
                $rdi_permit_date = date("Y-m-d", strtotime($rdi_permit_date));
                $rdi_value = str_replace(",", "", $rdi_value);

                // Verify the RDI
                $rdi = $this->getRDI($rdi_serial);

                if ($rdi->count() == 0) {
                    $this->logError("Invalid RDI ({$rdi_serial}). " . __METHOD__);
                }

                $SQL = "UPDATE rdis 
                           SET rdi_permit_facts_id        = :rdi_permit_facts_id,
                               rdi_permit_number          = :rdi_permit_number,
                               rdi_entry_date             = :rdi_entry_date,
                               rdi_permit_date            = :rdi_permit_date,
                               rdi_sub_div_name           = :rdi_sub_div_name,
                               rdi_project_type           = :rdi_project_type,
                               rdi_county                 = :rdi_county,
                               rdi_company                = :rdi_company,
                               rdi_phone                  = :rdi_phone,
                               rdi_project_addr           = :rdi_project_addr,
                               rdi_city                   = :rdi_city,
                               rdi_state                  = :rdi_state,
                               rdi_zip                    = :rdi_zip,
                               rdi_project_city           = :rdi_project_city,
                               rdi_project_state          = :rdi_project_state,
                               rdi_value                  = :rdi_value,
                               rdi_lot                    = :rdi_lot,
                               rdi_dist_ll                = :rdi_dist_ll,
                               rdi_owner_name             = :rdi_owner_name,
                               rdi_owner_phone            = :rdi_owner_phone,
                               rdi_owner_address          = :rdi_owner_address,
                               rdi_owner_city             = :rdi_owner_city,
                               rdi_owner_state            = :rdi_owner_state,
                               rdi_owner_zip              = :rdi_owner_zip,
                               rdi_size                   = :rdi_size,
                               rdi_units                  = :rdi_units,
                               rdi_building_type          = :rdi_building_type,
                               rdi_work_type              = :rdi_work_type,
                               rdi_ct1                    = :rdi_ct1,
                               rdi_ytd_permits            = :rdi_ytd_permits,
                               rdi_ytd_value              = :rdi_ytd_value,
                               rdi_12mth_prev_permits     = :rdi_12mth_prev_permits
                         WHERE rdi_serial                 = :rdi_serial";

                $statement = $this->connect()->prepare($SQL);

                $statement->bindValue(":rdi_serial", $rdi_serial);
                $statement->bindValue(":rdi_permit_facts_id", $rdi_permit_facts_id);
                $statement->bindValue(":rdi_permit_number", $rdi_permit_number);
                $statement->bindValue(":rdi_entry_date", $rdi_entry_date);
                $statement->bindValue(":rdi_permit_date", $rdi_permit_date);
                $statement->bindValue(":rdi_sub_div_name", $rdi_sub_div_name);
                $statement->bindValue(":rdi_project_type", $rdi_project_type);
                $statement->bindValue(":rdi_county", $rdi_county);
                $statement->bindValue(":rdi_company", $rdi_company);
                $statement->bindValue(":rdi_phone", $rdi_phone);
                $statement->bindValue(":rdi_project_addr", $rdi_project_addr);
                $statement->bindValue(":rdi_city", $rdi_city);
                $statement->bindValue(":rdi_state", $rdi_state);
                $statement->bindValue(":rdi_zip", $rdi_zip);
                $statement->bindValue(":rdi_project_city", $rdi_project_city);
                $statement->bindValue(":rdi_project_state", $rdi_project_state);
                $statement->bindValue(":rdi_value", $rdi_value);
                $statement->bindValue(":rdi_lot", $rdi_lot);
                $statement->bindValue(":rdi_dist_ll", $rdi_dist_ll);
                $statement->bindValue(":rdi_owner_name", $rdi_owner_name);
                $statement->bindValue(":rdi_owner_phone", $rdi_owner_phone);
                $statement->bindValue(":rdi_owner_address", $rdi_owner_address);
                $statement->bindValue(":rdi_owner_city", $rdi_owner_city);
                $statement->bindValue(":rdi_owner_state", $rdi_owner_state);
                $statement->bindValue(":rdi_owner_zip", $rdi_owner_zip);
                $statement->bindValue(":rdi_size", $rdi_size);
                $statement->bindValue(":rdi_units", $rdi_units);
                $statement->bindValue(":rdi_building_type", $rdi_building_type);
                $statement->bindValue(":rdi_work_type", $rdi_work_type);
                $statement->bindValue(":rdi_ct1", $rdi_ct1);
                $statement->bindValue(":rdi_ytd_permits", $rdi_ytd_permits);
                $statement->bindValue(":rdi_ytd_value", $rdi_ytd_value);
                $statement->bindValue(":rdi_12mth_prev_permits", $rdi_12mth_prev_permits);

                $statement->execute();

                break;

            default:

                $this->displayHome();
        }
    }

    // ================================
    // Return an Active RDI Object
    // ================================

    public function getActiveRDI() {

        $SQL = "select view_rdis.*
              from view_rdis
             where rdi_status is true";

        return $this->getTable("rdis", $SQL);
    }

    // ========================
    // Return an RDI Object
    // ========================

    public function getRDI($rdi_serial = 0) {

        $SQL = "select view_rdis.*
              from view_rdis
             where rdi_serial = {$rdi_serial}";

        return $this->getTable("rdis", $SQL);
    }

    // ========================
    // Return a RDI Object
    // ========================

    public function getRDIs() {

        $SQL = "select view_rdis.*
              from view_rdis";

        return $this->getTable("rdis", $SQL);
    }

    // ========================
    // Return a RDI Page Object
    // ========================

    public function getRDIPage() {

        // Find Criteria

        $find_rdi = filter_input(INPUT_POST, "find_rdi") ?: "";
        $find_rdi = $this->sanitizeString($find_rdi);

        $this->pagination_size = filter_input(INPUT_POST, "rdis_per_page", FILTER_SANITIZE_NUMBER_INT) ?: $this->pagination_size;

        $rdis_order_by = filter_input(INPUT_POST, "rdis_order_by") ?: "";
        $rdis_order_direction = filter_input(INPUT_POST, "rdis_order_direction") ?: "";

        if ($rdis_order_by === "") {
            $orderby = "rdi_permit_number desc";
        } else {
            $orderby = $rdis_order_by . " " . $rdis_order_direction;
        }

        // Record Count

        $connection = $this->connect();

        $SQL = "select count(*) as count
                  from view_rdis
                 where rdi_permit_number        regexp :rdi_permit_number 
                    or rdi_entry_date_verbose   regexp :rdi_entry_date_verbose 
                    or rdi_permit_date_verbose  regexp :rdi_permit_date_verbose
                    or rdi_sub_div_name         regexp :rdi_sub_div_name 
                    or rdi_project_type         regexp :rdi_project_type";

        $statement = $connection->prepare($SQL);

        $statement->bindValue(":rdi_permit_number", $find_rdi);
        $statement->bindValue(":rdi_entry_date_verbose", $find_rdi);
        $statement->bindValue(":rdi_permit_date_verbose", $find_rdi);
        $statement->bindValue(":rdi_sub_div_name", $find_rdi);
        $statement->bindValue(":rdi_project_type", $find_rdi);

        $statement->execute();

        $recordset = $statement->fetch(PDO::FETCH_ASSOC);

        $count = (count($recordset) > 0) ? (integer) $recordset["count"] : (integer) 0;

        // Pagination

        $pagination = filter_input(INPUT_POST, "pagination") ?: "";

        switch ($pagination) {

            case "first" : $this->pagination_page = 1;
                break;
            case "previous" : $this->pagination_page = max(($this->pagination_page - 1), 1);
                break;
            case "next" : $this->pagination_page = ($this->pagination_page + 1);
                break;
            case "last" : $this->pagination_page = ($count / $this->pagination_size);
                break;
        }

        $offset = (($this->pagination_page * $this->pagination_size) - $this->pagination_size);
        $start = ($offset + 1);
        $end = min($count, (($start + $this->pagination_size) - 1));

        // Data

        $SQL = "select view_rdis.*
                  from view_rdis
                 where rdi_permit_number        regexp :rdi_permit_number 
                    or rdi_entry_date_verbose   regexp :rdi_entry_date_verbose 
                    or rdi_permit_date_verbose  regexp :rdi_permit_date_verbose
                    or rdi_sub_div_name         regexp :rdi_sub_div_name 
                    or rdi_project_type         regexp :rdi_project_type
              order by {$orderby}
                 limit {$this->pagination_size}
                offset {$offset}";

        $statement = $connection->prepare($SQL);

        $statement->bindValue(":rdi_permit_number", $find_rdi);
        $statement->bindValue(":rdi_entry_date_verbose", $find_rdi);
        $statement->bindValue(":rdi_permit_date_verbose", $find_rdi);
        $statement->bindValue(":rdi_sub_div_name", $find_rdi);
        $statement->bindValue(":rdi_project_type", $find_rdi);

        $statement->execute();

        $rdis = $this->getTableXML("rdis", $statement);

        // Insert Pagination Attributes

        $rdis->addAttribute("count", $count);
        $rdis->addAttribute("start", $start);
        $rdis->addAttribute("end", $end);
        $rdis->addAttribute("page", $this->pagination_page);

        $_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;

        return $rdis;
    }
}

?>
