<?php

$jsondata = file_get_contents("./api/json/slc_xcdata.json");
$data = json_decode($jsondata, true);
$json = $data["app"];
$applang = $json["app_language"] == "en" ? "selected" : "";
$applang1 = $json["app_language"] == "ar" ? "selected" : "";
$applang2 = $json["app_language"] == "bn" ? "selected" : "";
$applang3 = $json["app_language"] == "zh" ? "selected" : "";
$applang4 = $json["app_language"] == "fr" ? "selected" : "";
$applang5 = $json["app_language"] == "hi" ? "selected" : "";
$applang6 = $json["app_language"] == "it" ? "selected" : "";
$applang7 = $json["app_language"] == "ml" ? "selected" : "";
$applang8 = $json["app_language"] == "pt" ? "selected" : "";
$applang9 = $json["app_language"] == "es" ? "selected" : "";
$applang10 = $json["app_language"] == "ru" ? "selected" : "";
$message = "<div class=\"alert alert-primary\" 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_xcdata.json");
    $arrayData = json_decode($jsonData, true);
    $replacementData = ["app" => ["app_language" => $_POST["app_language"], "language" => $_POST["app_language"]]];
    $newArrayData = array_replace_recursive($arrayData, $replacementData);
    $newJsonData = json_encode($newArrayData, JSON_PRETTY_PRINT);
    file_put_contents("./api/json/slc_xcdata.json", $newJsonData);
    header("Location: language.php?message=" . $message);
}
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-primary\">\n                <div class=\"card-header bg-primary py-3\">\n                <center><h4 align=\"center\" class=\"m-0 text-white\"><i class=\"fa fa-globe\"\n                                    style=\"font-size:20px\">&nbsp;&nbsp;</i> Language Available</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=\"control-label requiredField text-primary\" for=\"app_language\" >\n                            <strong> Pick Your App Language</strong>\n                            </label>\n                            <select class=\"select form-control text-primary\" id=\"select\" name=\"app_language\">\n";
echo "\t\t\t\t\t\t\t\t<option value=\"en\"" . $applang . ">English</option>" . "\n";
echo "                                <option value=\"ar\" " . $applang1 . ">Arabic</option>" . "\n";
echo "\t\t\t\t\t\t\t\t<option value=\"bn\"" . $applang2 . ">Bengali</option>" . "\n";
echo "\t\t\t\t\t\t\t\t<option value=\"zh\"" . $applang3 . ">Chinese</option>" . "\n";
echo "\t\t\t\t\t\t\t\t<option value=\"fr\" " . $applang4 . ">French</option>" . "\n";
echo "                                <option value=\"hi\"" . $applang5 . ">Hindi</option>" . "\n";
echo "                                <option value=\"it\"" . $applang6 . ">Italian</option>" . "\n";
echo "\t\t\t\t\t\t\t\t<option value=\"ml\"" . $applang7 . ">Malayalam</option>" . "\n";
echo "\t\t\t\t\t\t\t\t<option value=\"pt\"" . $applang8 . ">Portugese</option>" . "\n";
echo "\t\t\t\t\t\t\t\t<option value=\"es\"" . $applang9 . ">Spanish</option>" . "\n";
echo "                                <option value=\"ru\"" . $applang10 . ">Russian</option>" . "\n";
echo "                            </select>\n\t\t\t\t\t\t\t</div>\n                            <div class=\"form-group\">\n                            <div>\n                            </div>\n                            </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>\n                            </div>\n                            </form>\n                </div>\n              </div>\n            </div>\n            </div>            </div>\n    <br><br><br>";
include "includes/footer.php";
require "includes/slc.php";
echo "</body>\n";

?>