<?php 
if (session_status() === PHP_SESSION_NONE){session_start();}
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$str_data = file_get_contents("api/zyx.json");
$data = json_decode($str_data, true);
 
$update ="";
$res = $_GET['update'];



//$id = $row['id'];
$name = $data["plugin_list"][$res]["name"];
$version = $data["plugin_list"][$res]["version"];
$playstore_url = $data["plugin_list"][$res]["playstore_url"];
$apk_url = $data["plugin_list"][$res]["apk_url"];
$status = $data["plugin_list"][$res]["status"];
$pkg_name = $data["plugin_list"][$res]["pkg_name"];


if(isset($_POST['submit'])){
    $jsonData = file_get_contents("./api/zyx.json");
$arrayData = json_decode($jsonData, true);
$replacementData = array($res=> array('plugin_list' =>array(
	"name"             => $_POST["name"],
    "version"               => $_POST["version"],
    "playstore_url"           => $_POST["playstore_url"],
    "apk_url"                 => $_POST["apk_url"],
    "status"    => $_POST["status"],
    "pkg_name"         => $_POST["pkg_name"])))
   ;
    $newArrayData = array_replace_recursive($arrayData, $replacementData);
$newJsonData = json_encode($newArrayData, JSON_PRETTY_PRINT);
file_put_contents("./api/zyx.json", $newJsonData);

header("Location: plugin.php");
}
include ('includes/header.php');

?>

<!-- Begin Page Content -->
        <div class="container-fluid">

          <!-- Page Heading -->
          <h1 class="h3 mb-1 text-gray-800"> Update Plugin Package</h1>

              <!-- Custom codes -->
                <div class="card border-left-primary alert-primary shadow h-100 card shadow mb-4">
                <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary"><i class="fa fa-android"></i> Enter Plugin Details</h6>
                </div>
                
                <div class="card-body">
                    <?
echo "                  <form  method=\"post\">\n";
echo "                      <div>\n";
echo "                        <div class=\"form-group\">\n";
echo "                          <label class=\"bmd-label-floating\">Name</label>\n";
echo "						   <input type=\"hidden\" name=\"id\" value=\"$res\">\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"name\" value=\"$name\">\n";
echo "                        </div>\n";
echo "                      </div>\n";
echo "                      <div>\n";
echo "                        <div class=\"form-group\">\n";
echo "                          <label class=\"bmd-label-floating\">Version</label>\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"version\" value=\"$version\">\n";
echo "                        </div>\n";
echo "                      </div>\n";
echo "                      <div>\n";
echo "                        <div class=\"form-group\">\n";
echo "                          <label class=\"bmd-label-floating\">Playstore_url</label>\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"playstore_url\" value=\"$playstore_url\">\n";
echo "                        </div>\n";
echo "                      </div>\n";
echo "                      <div>\n";
echo "                        <div class=\"form-group\">\n";
echo "                          <label class=\"bmd-label-floating\">apk_url</label>\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"apk_url\" value=\"$apk_url\">\n";
echo "                        </div>\n";
echo "                      </div>\n";
echo "                      <div>\n";
echo "                        <div class=\"form-group\">\n";
echo "                          <label class=\"bmd-label-floating\">Status</label>\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"status\" value=\"$status\">\n";
echo "                        </div>\n";
echo "                      </div>\n";
echo "                      <div>\n";
echo "                        <div class=\"form-group\">\n";
echo "                          <label class=\"bmd-label-floating\">pkg_name</label>\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"pkg_name\" value=\"$pkg_name\">\n";
echo "                        </div>\n";
echo "                      </div>\n";
echo "                      <div>\n";
echo "                       <div>\n";
echo "					<br><button type=\"submit\" name=\"submit\" class=\"btn btn-primary pull-right\">Submit</button>\n";
echo "				</form>\n";
echo "				</div>\n";
echo "              </div>\n";
echo "            </div>\n";
echo "          </div>\n";
echo "    <br><br><br>\n";
include ('includes/footer.php');
echo "</body>\n";
echo "\n";
echo "</html>\n";
