<?php 


if (isset($_POST['submit']))
{
    $jsonData = file_get_contents("./api/main.json");
    $arrayData = json_decode($jsonData, true);
    $replacementData = array(
        'app' => array(
            'version_code' => $_POST["version_code"],
            'apkurl' => $_POST["apkurl"],
            'backupurl' => $_POST["backupurl"],
            'apkautoupdate' => $_POST["apkautoupdate"]
        )
    );
    $newArrayData = array_replace_recursive($arrayData, $replacementData);
    $newJsonData = json_encode($newArrayData, JSON_PRETTY_PRINT);
    file_put_contents("./api/main.json", $newJsonData);

    header("Location: ". basename($_SERVER["SCRIPT_NAME"])."?status=1");
}
$jsondata = file_get_contents("./api/main.json");
$dataA = json_decode($jsondata, true);
$json = $dataA['app'];
include ('includes/header.php');

$version_code = $json['version_code'];

$apkautoupdate = $json['apkautoupdate']=='yes'?'selected':'';
$apkautoupdate1 = $json['apkautoupdate']=='no'?'selected':'';

$apkurl = $json['apkurl'];
@$backup = $json['backup'];

echo "        <div class=\"col-md-8 mx-auto\">\n";
echo "            <div class=\"card-body\">\n";
echo "                <div class=\"card bg-primary text-white\">\n";
echo "                    <div class=\"card-header card-header-warning\">\n";
echo "                        <center>\n";
echo "                            <h2><i class=\"icon icon-cloud-upload\"></i> Create Update</h2>\n";
echo "                        </center>\n";
echo "                    </div>\n";
echo "                    <div class=\"card-body\">\n";
echo "                        <div class=\"form-group\">\n";
echo "                            <form method=\"post\">\n";
echo "                                <div class=\"form-group form-float form-group-lg\">\n";
echo "                                    <label class=\"form-label\">Current Application Build N??</label>\n";
echo "                                    <div class=\"input-group\">\n";
echo "                                        <input class=\"form-control\" id=\"version_code\" name=\"version_code\" value=\"$version_code\" type=\"text\"/>\n";
echo "                                    </div>\n";
echo "                                </div>\n";
echo "\n";
echo "                                <div class=\"form-group form-float form-group-lg\">\n";
echo "                                    <label class=\"form-label\">Foce Update Application</label>\n";
echo "                                    <select class=\"form-control\" id=\"select\" name=\"apkautoupdate\">\n";
echo "                                        <option value=\"yes\" $apkautoupdate>Enabled</option>\n";
echo "                                        <option value=\"no\" $apkautoupdate1>Disabled</option>\n";
echo "                                    </select>\n";
echo "                                </div>\n";
echo "\n";
echo "                                <div class=\"form-group form-float form-group-lg\">\n";
echo "                                    <label class=\"form-label\">Application Update URL (direct link)</label>\n";
echo "                                    <input type=\"text\" class=\"form-control\" name=\"apkurl\" id=\"apkurl\" value=\"$apkurl\">\n";
echo "                                </div>\n";
echo "\n";
echo "                                <div class=\"form-group form-float form-group-lg\">\n";
echo "                                    <label class=\"form-label\">Application Backup URL (direct link)</label>\n";
echo "                                    <input type=\"text\" class=\"form-control\" name=\"backupurl\" id=\"backupurl\" value=\"$backup\">\n";
echo "                                </div>\n";
echo "\n";
echo "                                <hr>\n";
echo "\n";
echo "                                <div class=\"form-group\">\n";
echo "                                    <center>\n";
echo "                                        <button class=\"btn btn-info\" name=\"submit\" type=\"submit\">\n";
echo "                                            <i class=\"icon icon-check\"></i>Push Update\n";
echo "                                        </button>\n";
echo "                                    </center>\n";
echo "                                </div>\n";
echo "                            </form>\n";
echo "                        </div>\n";
echo "                    </div>\n";
echo "                </div>\n";
echo "            </div>\n";
echo "        </div>\n";
echo "\n";
echo "\n";
include ('includes/footer.php');
echo "\n";
echo "</body>\n";
echo "</html>\n";


?>