<?php
/*
 * @ https://hospedagem.matrixch.store 
 * @ PHP 7.4
 * @ Decoder version: 1.0.2
 * @ Release: 17/06/2024
*/

include "includes/header.php";
$table_name = "playlist";
$res = $db->select($table_name, "*", "", "");
if (isset($_POST["submit"])) {
    unset($_POST["submit"]);
    $db->insert($table_name, $_POST);
    $db->close();
    echo "<script>window.location.href='" . basename($_SERVER["SCRIPT_NAME"]) . "?status=1'</script>";
}
$resU = @$db->select($table_name, "*", "id = :id", "", [":id" => $_GET["update"]]);
if (isset($_POST["submitU"])) {
    unset($_POST["submitU"]);
    $updateData = $_POST;
    $db->update($table_name, $updateData, "id = :id", [":id" => $_GET["update"]]);
    echo "<script>window.location.href='" . basename($_SERVER["SCRIPT_NAME"]) . "?status=1'</script>";
}
if (isset($_GET["delete"])) {
    $db->delete($table_name, "id = :id", [":id" => $_GET["delete"]]);
    echo "<script>window.location.href='" . basename($_SERVER["SCRIPT_NAME"]) . "?status=2'</script>";
}
echo "<div class=\"modal fade\" id=\"confirm-delete\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"myModalLabel\" aria-hidden=\"true\">\n    <div class=\"modal-dialog\">\n        <div class=\"modal-content\">\n            <div class=\"modal-header\">\n                <h2>CONFIRMAR</h2>\n            </div>\n            <div class=\"modal-body\">\n                \n            </div>\n            <div class=\"modal-footer\">\n                <button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">CANCELAR</button>\n                <a class=\"btn btn-danger btn-ok\">EXCLUIR</a>\n            </div>\n        </div>\n    </div>\n</div>\n";
if (isset($_GET["create"])) {
    echo "        <div class=\"col-md-8 mx-auto\">\n            <div class=\"card-body\">\n                <div class=\"card bg-primary text-white\">\n                    <div class=\"card-header card-header-warning\">\n                        <center>\n                            <h2><i class=\"icon icon-bullhorn\"></i>ADICIONAR</h2>\n                        </center>\n                    </div>\n                    \n                    <div class=\"card-body\">\n                        <div class=\"col-12\">\n                            <h3></h3>\n                        </div>\n                            <form method=\"post\">\n                                <div class=\"form-group\">\n                                    <label class=\"form-label \" for=\"title\">DNS</label>\n\t\t\t\t\t\t\t\t\t<select class=\"form-control\" name=\"dns_id\">\n                                       <option selected=\"selected\">ESCOLHA UMA</option>\n                                       ";
    $dnss = $db->select("dns", "*", "", "");
    foreach ($dnss as $dns) {
        echo "                                           <option value=\"";
        echo $dns["id"];
        echo "\">";
        echo $dns["title"];
        echo "</option>\n                                       ";
    }
    echo "                                     </select> \n                                </div>\n                                <div class=\"form-group\">\n                                    <label class=\"form-label \" for=\"dns\">ENDEREÇO  MAC</label>\n                                        <input class=\"form-control\" id=\"mac\" name=\"mac_address\" placeholder=\"MAC Address\" type=\"text\"/>\n                                </div>\n                                <script>\n                                    document.getElementById(\"mac\").addEventListener('keyup', function() { \n                                      this.value = \n                                        (this.value.toUpperCase()\n                                        .replace(/[^\\d|A-Z]/g, '')\n                                        .match(/.{1,2}/g) || [])\n                                        .join(\":\")\n                                    });\n                                </script>\n                                <div class=\"form-group\">\n                                    <label class=\"form-label \" for=\"title\">USUÁRIO</label>\n                                        <input class=\"form-control\" id=\"description\" name=\"username\" placeholder=\"Username\" type=\"text\"/>\n                                </div>\n                                <div class=\"form-group\">\n                                    <label class=\"form-label \" for=\"dns\">SENHA</label>\n                                        <input class=\"form-control\" id=\"description\" name=\"password\" placeholder=\"Password\" type=\"text\"/>\n                                </div>\n                                <div class=\"form-group\">\n                                    <label class=\"form-label \" for=\"dns\">CONTROLE DOS PAIS</label>\n                                        <input class=\"form-control\" id=\"description\" name=\"pin\" placeholder=\"Parental Pin\" type=\"text\" value=\"0000\"/>\n                                </div>\n                                <div class=\"form-group\">\n                                    <center>\n                                        <button class=\"btn btn-info \" name=\"submit\" type=\"submit\">\n                                            <i class=\"icon icon-check\"></i> SALVAR\n                                        </button>\n                                    </center>\n                                </div>\n                            </form>\n                    </div>\n                </div>\n            </div>\n        </div>\n";
} else {
    if (isset($_GET["update"])) {
        echo "        <div class=\"col-md-8 mx-auto\">\n            <div class=\"card-body\">\n                <div class=\"card bg-primary text-white\">\n                    <div class=\"card-header card-header-warning\">\n                        <center>\n                            <h2><i class=\"icon icon-bullhorn\"></i> EDITAR USE</h2>\n                        </center>\n                    </div>\n                    \n                    <div class=\"card-body\">\n                        <div class=\"col-12\">\n                            <h3></h3>\n                        </div>\n                            <form method=\"post\">\n                                <div class=\"form-group\">\n                                    <label class=\"form-label \" for=\"title\">DNS ID</label>\n                                        <input class=\"form-control\" id=\"description\" name=\"id\" value=\"";
        echo $resU[0]["id"];
        echo "\" readonly type=\"text\" />\n                                </div>\n                                <div class=\"form-group\">\n                                    <label class=\"form-label \" for=\"dns\">ENDEREÇO MAC</label>\n                                        <input class=\"form-control\" id=\"description\" name=\"mac_address\" value=\"";
        echo $resU[0]["mac_address"];
        echo "\" type=\"text\"/>\n                                </div>\n                                <div class=\"form-group\">\n                                    <label class=\"form-label \" for=\"title\">USUÁRIO</label>\n                                        <input class=\"form-control\" id=\"description\" name=\"username\" placeholder=\"Username\" value=\"";
        echo $resU[0]["username"];
        echo "\" type=\"text\"/>\n                                </div>\n                                <div class=\"form-group\">\n                                    <label class=\"form-label \" for=\"dns\">SENHA</label>\n                                        <input class=\"form-control\" id=\"description\" name=\"password\" placeholder=\"Password\" value=\"";
        echo $resU[0]["password"];
        echo "\" type=\"text\"/>\n                                </div>\n                                <div class=\"form-group\">\n                                    <label class=\"form-label \" for=\"dns\">CONTROLE DOS PAIS</label>\n                                        <input class=\"form-control\" id=\"description\" name=\"pin\" placeholder=\"Parental Pin\" value=\"";
        echo $resU[0]["pin"];
        echo "\" type=\"text\"/>\n                                </div>\n                                <div class=\"form-group\">\n                                    <center>\n                                        <button class=\"btn btn-info \" name=\"submitU\" type=\"submit\">\n                                            <i class=\"icon icon-check\"></i> SALVAR\n                                        </button>\n                                    </center>\n                                </div>\n                            </form>\n                    </div>\n                </div>\n            </div>\n        </div>\n";
    } else {
        echo "        <div class=\"col-md-12 mx-auto\">\n            <div class=\"card-body\">\n                <div class=\"card bg-primary text-white\">\n                    <div class=\"card-header card-header-warning\">\n                        <center>\n                            <h2><i class=\"icon icon-commenting\"></i>USUÁRIOS</h2>\n                        </center>\n                    </div>\n\n                    <div class=\"card-body\">\n                        <div class=\"col-12\">\n                        \t<center>\n\t        \t\t\t\t\t<a id=\"button\" href=\"./";
        echo basename($_SERVER["SCRIPT_NAME"]);
        echo "?create\" class=\"btn btn-info\">CRIAR USUÁRIO</a>\n\t        \t\t\t\t</center>\n    \t\t\t\t\t</div>\n\t\t\t\t\t\t<br>\n\t\t\t\t\t\t<div class=\"table-responsive\">\n\t\t\t\t\t\t\t<input class=\"form-control\" Type=\"text\" id=\"search\" onkeyup=\"func2()\" placeholder=\"Pesquisa\">\n\t\t\t\t\t\t\t<table id=\"users\" class=\"table table-striped table-sm\">\n\t\t\t\t\t\t\t<thead style=\"color:white!important\">\n\t\t\t\t\t\t\t\t<tr class=\"header\">\n\t\t\t\t\t\t\t\t<th>DNS ID</th>\n\t\t\t\t\t\t\t\t<th>MAC</th>\n\t\t\t\t\t\t\t\t<th>USUÁRIO </th>\n\t\t\t\t\t\t\t\t<th>SENHA</th>\n\t\t\t\t\t\t\t\t<th>CONTROLE DOS PAIS</th>\n\t\t\t\t\t\t\t\t<th>EDITAR &nbsp&nbsp&nbspEXCLUIR</th>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</thead>\n\t\t\t\t\t\t\t";
        foreach ($res as $row) {
            echo "\t\t\t\t\t\t\t<tbody>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>";
            echo $row["dns_id"];
            echo "</td>\n\t\t\t\t\t\t\t\t<td>";
            echo $row["mac_address"];
            echo "</a></td>\n\t\t\t\t\t\t\t\t<td>";
            echo $row["username"];
            echo "</td>\n\t\t\t\t\t\t\t\t<td>";
            echo $row["password"];
            echo "</td>\n\t\t\t\t\t\t\t\t<td>";
            echo $row["pin"];
            echo "</td>\n\t\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t<a class=\"btn btn-info btn-ok\" href=\"./";
            echo basename($_SERVER["SCRIPT_NAME"]);
            echo "?update=";
            echo $row["id"];
            echo "\"><i class=\"fa fa-pencil-square-o\"></i></a>\n\t\t\t\t\t\t\t\t&nbsp&nbsp&nbsp\n\t\t\t\t\t\t\t\t<a class=\"btn btn-danger btn-ok\" href=\"#\" data-href=\"./";
            echo basename($_SERVER["SCRIPT_NAME"]);
            echo "?delete=";
            echo $row["id"];
            echo "\" data-toggle=\"modal\" data-target=\"#confirm-delete\"><i class=\"fa fa-trash-o\"></i></a>\n\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</tbody>\n\t\t\t\t\t\t\t";
        }
        echo "\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n";
    }
}
echo "\n";
include "includes/footer.php";
echo "\n</body>\n</html>";

?>