<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Welcome to CodeIgniter 4!</title>
    <meta name="description" content="The small framework with powerful features">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" type="image/png" href="/favicon.ico">

    <!-- STYLES -->
    <link rel="stylesheet" href="/bootstrap-4.0.0/dist/css/bootstrap.min.css"
          integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
            integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
            crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js"
            integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
            crossorigin="anonymous"></script>
    <script src="bootstrap-4.0.0/dist/js/bootstrap.min.js"
            integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
            crossorigin="anonymous"></script>

</head>
<body
    style="font-size: 14px; margin-top: auto; margin-bottom: auto; text-align: center; background-color: #fafac9; padding: 15px">

<div class="container-fluid">
    <span style="font-size: 60px; margin-top: auto; margin-bottom: auto; text-align: center;">
    MERMS Provision <?= $label_env ?? '' ?>
</span>
    <div class="row">
        <div class="col-sm">
            <h3>
                Ongoing Provisions
            </h3>
            <table class="table table-hover table-dark">
                <thead>
                <tr>
                    <th scope="col">#</th>
                    <th scope="col">Default URL</th>
                    <th scope="col">Added</th>
                    <th scope="col">Prov. Status</th>
                </tr>
                </thead>
                <tbody>
                <?php
                foreach ($starting_list ?? [] as $pr) {
                    ?>
                    <tr>
                        <th scope="row"><?= $pr->id ?></th>
                        <td><?= $pr->internal_url ?></td>
                        <td><?= $pr->added ?></td>
                        <td><?= $pr->status ?></td>
                    </tr>
                    <?php
                }
                ?>
                </tbody>
            </table>
        </div>
        <div class="col-sm">
            <h3>
                Hanging Provisions
            </h3>
            <table class="table table-hover table-dark">
                <thead>
                <tr>
                    <th scope="col">#</th>
                    <th scope="col">Default URL</th>
                    <th scope="col">Added</th>
                    <th scope="col">Prov. Status</th>
                    <th scope="col">Action</th>
                </tr>
                </thead>
                <tbody>
                <?php
                foreach ($hanging_list ?? [] as $pr) {
                    ?>
                    <tr style="text-align: left;">
                        <th scope="row"><?= $pr->id ?></th>
                        <td><a href="https://<?= $pr->internal_url ?>" target="_blank"><?= $pr->internal_url ?></a>
                            <br><b>PORT:</b><?=$pr->provision_port ?>
                        </td>
                        <td><?= $pr->added ?></td>
                        <td><?= $pr->status ?></td>
                        <td><button id="<?= $pr->uid ?>" class="btn btn-info  btn-xs" onclick="return restartProvsion('<?= $pr->uid ?>');" >Restart</button></td>
                    </tr>
                    <?php
                }
                ?>
                </tbody>
            </table>
        </div>
        <div class="col-sm">
            <h3>
                Completed Provisions
            </h3>
            <table class="table table-hover table-dark">
                <thead>
                <tr>
                    <th scope="col">#</th>
                    <th scope="col">Default URL</th>
                    <th scope="col">Added</th>
                    <th scope="col">Prov. Status</th>
                </tr>
                </thead>
                <tbody>
                <?php
                foreach ($completed_list ?? [] as $pr) {
                    ?>
                    <tr>
                        <th scope="row"><?= $pr->id ?></th>
                        <td><a href="https://<?= $pr->internal_url ?>" target="_blank"><?= $pr->internal_url ?></a></td>
                        <td><?= $pr->added ?></td>
                        <td><?= $pr->status ?></td>
                    </tr>
                    <?php
                }
                ?>
                </tbody>
            </table>
        </div>
    </div>


</div>

<script type="text/javascript">
    <!--
    function restartProvsion(link_id) {
        if (confirm("Are you sure you want to restart this provisioning?")) {
// do something
        } else {
            return false;
        }

        $(link_id).prop('disabled', true);
        $.ajax({
            url: "/home/resend_pending?link_id=" + link_id
        }).done(function (data) {
            $(link_id).prop('disabled', false);
        });
        return false;
    }




</script>
</body>
</html>
