<?php

$jsondata = file_get_contents("./api/json/slc_parental.json");
$json = json_decode($jsondata, true);
$message = "<div class=\"alert alert-success\" id=\"flash-msg\"><h4><i class=\"icon fa fa-check\"></i>Items Updated!</h4></div>";
if (isset($_POST["submit"])) {
    $jsonData = file_get_contents("./api/json/slc_parental.json");
    $arrayData = json_decode($jsonData, true);
    $replacementData = [1 => $_POST[1], 2 => $_POST[2], 3 => $_POST[3], 4 => $_POST[4], 5 => $_POST[5]];
    $newArrayData = array_replace_recursive($arrayData, $replacementData);
    $newJsonData = json_encode($newArrayData, JSON_PRETTY_PRINT);
    file_put_contents("./api/json/slc_parental.json", $newJsonData);
    header("Location: parental.php?message=" . $message);
}
list($input1, $input5) = $json;
$num1 = ord($input1);
$num5 = ord($input5);
include "includes/header.php";
echo "<!-- Begin Page Content -->\n        <div class=\"container-fluid\">\n\n";
if (isset($_GET["message"])) {
    echo $_GET["message"];
}
echo "          <!-- Content Row -->\n          <div class=\"row\">\n\n            <!-- First Column -->\n            <div class=\"col-lg-12\">\n\n              <!-- Custom codes -->\n                <div class=\"card text-text-primary\">\n                <div class=\"card-header bg-primary py-3\">\n                <center><h4 align=\"center\" class=\"m-0 text-white\"><i class=\"fa fa-lock\"\n                                    style=\"font-size:20px\">&nbsp;&nbsp;</i> Parental Password Reset</h4>\n                        \n\t\t\t\t\t\t</center>\n\n            </div>\n                <div class=\"card-body\">\n                            <form method=\"post\">\n\t\t\t\t\t\t\t<div class=\"form-group \">\n                            <label class=\"text-primary control-label\" for=\"mastercode\">\n                            <strong> Enter Reset Code</strong>\n                            </label>\n                            <div class=\"input-group\">\n                            <input style=\"text-align:center;\" class=\"inputs text-primary\" id=\"1\" name=\"1\" placeholder=\"【🅑】\" maxlength=\"1\" size=\"3\" value= \"\" />\n                            <input style=\"text-align:center;\" class=\"inputs text-primary\" id=\"2\" name=\"2\" placeholder=\"【🅞】\" maxlength=\"1\" size=\"3\" value= \"\"/>\n                            <input style=\"text-align:center;\" class=\"inputs text-primary\" id=\"3\" name=\"3\" placeholder=\"【🅧】\" maxlength=\"1\" size=\"3\" value= \"\" />\n                            <input style=\"text-align:center;\" class=\"inputs text-primary\" id=\"4\" name=\"4\" placeholder=\"【🅑】\" maxlength=\"1\" size=\"3\" value= \"\" />\n                            <input style=\"text-align:center;\" class=\"inputs text-primary\" id=\"5\" name=\"5\" placeholder=\"【🅡】\" maxlength=\"1\" size=\"3\"  />\n                            <br>\n                            </div></div>\n                            <div class=\"form-group\">\n                            <div>\n                            <button class=\"btn btn-success btn-icon-split\" name=\"submit\" type=\"submit\">\n                            <span class=\"icon text-white-50\"><i class=\"fas fa-check\"></i></span><span class=\"text\">Submit</span>\n                            </button>\n                            </div></div>\n                            <form method=\"post\">\n                            <div class=\"form-group \">\n                            <label class=\"text-primary control-label\" for=\"code\">\n                            <strong> Generated Reset Code</strong> \n                            </label>\n                            <div class=\"input-group\">\n";
echo "                            <input class=\"inputs text-primary\"  style=\"text-align:center;\" id=\"code\" name=\"code\" placeholder=\"Reset\"  placeholder=\"【🅡】\" size=\"15\" value= \"" . $num1 . $num5 . "\" disabled>" . "\n";
echo "                            </div>\n                            </div>\n                            </div>\n                            </form>\n                </div>\n              </div>\n            </div>\n            </div>\n\n";
include "includes/footer.php";
echo "</body>\n<script>\n    \$(\".inputs\").keyup(function() {\n  if (this.value.length == this.maxLength) {\n    \$(this).nextAll('.inputs:enabled:first').focus();\n  }\n});\n</script>\n</html>\n";

?>