<?php 
$jsondata = file_get_contents("./api/main.json");
$data = json_decode($jsondata, true);
$json = $data['app'];
$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/main.json");

$arrayData = json_decode($jsonData, true);
	$replacementData = array('app' =>  array(
										'player'		=>	$_POST["player"],
										'player_tv'		=>	$_POST["player_tv"],
										'player_vod'	=>	$_POST["player_vod"],
										'player_series'	=>	$_POST["player_series"]
										));
$newArrayData = array_replace_recursive($arrayData, $replacementData);
$newJsonData = json_encode($newArrayData, JSON_PRETTY_PRINT);
file_put_contents("./api/main.json", $newJsonData);
header("Location: player.php?message=$message");
		}
include ('includes/header.php');
?>
<div class="content-wrapper">
	<div class="container-fluid">
	<?if(isset($_GET['message'])){echo $_GET['message'];}?>
	<div class="card mb-3">
	<div class="card-header">
	<i class="fa fa-play-circle fa-lg"></i> Alterar Player</div>
	<div class="card-body">
	<div class="alert alert-light" role="alert">
	<div class="row">
	<div class="col-md-8">
	<form method="post">
		<div class="row">
			<div class="col-12">
                <h3>Player</h3>
            </div>
			<div class="col-md-12">
				<div class="form-group ">
					<input type="radio" id="vlc_player" name="player" value="VLC" <?=$json['player']=='VLC'?'checked':'' ?>>
					<label class="control-label requiredField" for="vlc_player" >VLC Player</label>
					<input type="radio" id="exo_player" name="player" value="EXO" <?=$json['player']=='EXO'?'checked':'' ?>>
					<label class="control-label requiredField" for="exo_player" >EXO Player</label>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-12">
                <h3>LiveTV Player</h3>
            </div>
			<div class="col-md-12">
				<div class="form-group ">
					<input type="radio" id="vlc_tv" name="player_tv" value="VLC" <?=$json['player_tv']=='VLC'?'checked':'' ?>>
					<label class="control-label requiredField" for="vlc_tv" >VLC Player</label>
					<input type="radio" id="exo_tv" name="player_tv" value="EXO" <?=$json['player_tv']=='EXO'?'checked':'' ?>>
					<label class="control-label requiredField" for="exo_tv" >EXO Player</label>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-12">
                <h3>VOD Player</h3>
            </div>
			<div class="col-md-12">
				<div class="form-group ">
					<input type="radio" id="vlc_vod" name="player_vod" value="VLC" <?=$json['player_vod']=='VLC'?'checked':'' ?>>
					<label class="control-label requiredField" for="vlc_vod" >VLC Player</label>
					<input type="radio" id="exo_vod" name="player_vod" value="EXO" <?=$json['player_vod']=='EXO'?'checked':'' ?>>
					<label class="control-label requiredField" for="exo_vod" >EXO Player</label>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-12">
                <h3>Series Player</h3>
            </div>
			<div class="col-md-12">
				<div class="form-group ">
					<input type="radio" id="vlc_series" name="player_series" value="VLC" <?=$json['player_series']=='VLC'?'checked':'' ?>>
					<label class="control-label requiredField" for="vlc_series" >VLC Player</label>
					<input type="radio" id="exo_series" name="player_series" value="EXO" <?=$json['player_series']=='EXO'?'checked':'' ?>>
					<label class="control-label requiredField" for="exo_series" >EXO Player</label>
				</div>
			</div>
		</div>
		<div class="form-group">
			<div>
				<button class="btn btn-info " name="submit" type="submit">
				<i class="fa fa-check"></i> Submit
				</button>
			</div>
		</div>
	</form>
</div>
<div style="width:700px; margin:0 auto;">
<?php include ('includes/footer.php');?>
	<script> 
		$(document).ready(function () {
		    $("#flash-msg").delay(3000).fadeOut("slow");
		});
	</script>
</body>

</html>