<?php 
ini_set('display_errors', 0);
$jsondata = file_get_contents("./api/main.json");
$data = json_decode($jsondata, true);
$json = $data['app']['ort_settings'];
$json_p = $data['app'];


if(isset($_POST['submit'])){
	$vlc = array('app' => 
					array('ort_settings' => array(
						'vlc_hw' => $_POST["vlc_hw"],
						'last_volume_vlc' => $_POST["last_volume_vlc"],
						'plyer_vlc_buffer' => $_POST["plyer_vlc_buffer"],
						'video_resize_vlc' => $_POST["video_resize_vlc"],
						'video_subtiltes_vlc' =>  $_POST["video_subtiltes_vlc"]
	)));

	$exo = array('app' => 
				array('ort_settings' => array(
					'exo_hw' => $_POST["exo_hw"],
					'last_volume_exo' => $_POST["last_volume_exo"],
					'plyer_exo_buffer' => $_POST["plyer_exo_buffer"],
					'video_resize_exo' => $_POST["video_resize_exo"],
					'video_subtiltes_exo' => $_POST["video_subtiltes_exo"]
	)));
	
	$player = array(
		'app' => array(
			'player' => $_POST["player"],
			'player_tv' => $_POST["player_tv"],
			'player_vod' => $_POST["player_vod"],
			'player_series' => $_POST["player_series"]
		)
	);
	
	if ($_POST['submit'] == "vlc"){
		$replacementData = $vlc;
	}elseif ($_POST['submit'] == "exo") {
		$replacementData = $exo;
	}elseif ($_POST['submit'] == "player"){
		$replacementData = $player;
	}

	$newArrayData = array_replace_recursive($data, $replacementData);
	$newJsonData = json_encode($newArrayData, JSON_PRETTY_PRINT);
	file_put_contents("./api/main.json", $newJsonData);

	header("Location: ". basename($_SERVER["SCRIPT_NAME"])."?status=1");
}

include ('includes/header.php');
?>


		<div class="card bg-primary text-white">
			<div class="card-header card-header-warning">
				<center>
					<h2><i class="fa fa-cogs"></i>Player Settings</h2>
				</center>
			</div>
			<div class="alert alert-info alert-dismissible" role="alert">
				<center>
					Update one section at a time.
				</center>
			</div>
			<div class="row">
				<div class="card-body">
					<div class="card bg-primary text-white">
						<div class="card-header card-header-warning">
							<center>
								<h3><i class="fa fa-play-circle"></i> EXO-Player Settings</h3>
							</center>
						</div>
						<div class="card-body bg-primary">
							<form method="post">
								<div class="form-group mb-3">
									<label class="control-label" for="plyer_exo_buffer">
										<strong> Set Buffer Size:</strong>
									</label>
									<select class="form-control" id="select" name="plyer_exo_buffer">
										<option value="10000" <?=$json['plyer_exo_buffer']=='10000'?'selected':'' ?>>10 Seconds</option>
										<option value="20000" <?=$json['plyer_exo_buffer']=='20000'?'selected':'' ?>>20 Seconds</option>
										<option value="30000" <?=$json['plyer_exo_buffer']=='30000'?'selected':'' ?>>30 Seconds</option>
										<option value="40000" <?=$json['plyer_exo_buffer']=='40000'?'selected':'' ?>>40 Seconds</option>
										<option value="50000" <?=$json['plyer_exo_buffer']=='50000'?'selected':'' ?>>50 Seconds</option>
									</select>
								</div>
								<div class="form-group mb-3">
									<label class="control-label" for="video_resize_exo">
										<strong> Set Zoom:</strong>
									</label>
									<select class="form-control" id="select" name="video_resize_exo">
										<option value="0" <?=$json['video_resize_exo']=='0'?'selected':'' ?>>Best Fit</option>
										<option value="1" <?=$json['video_resize_exo']=='1'?'selected':'' ?>>Fixed Height</option>
										<option value="2" <?=$json['video_resize_exo']=='2'?'selected':'' ?>>Fixed Width</option>
										<option value="3" <?=$json['video_resize_exo']=='3'?'selected':'' ?>>Fill</option>
										<option value="4" <?=$json['video_resize_exo']=='4'?'selected':'' ?>>Zoom</option>
									</select>
								</div>
								<div class="form-group mb-3">
									<label class="control-label" for="exo_hw">
										<strong> Enable Hardware Decoder:</strong>
									</label>
									<select class="form-control" id="select" name="exo_hw">
										<option value="yes" <?=$json['exo_hw']=='yes'?'selected':'' ?>>Yes</option>
										<option value="no" <?=$json['exo_hw']=='no'?'selected':'' ?>>No</option>
									</select>
								</div>
								<div class="form-group mb-3">
									<label class="control-label" for="video_subtiltes_exo">
										<strong> Enable Subtitles:</strong>
									</label>
									<select class="form-control" id="select" name="video_subtiltes_exo">
										<option value="yes" <?=$json['video_subtiltes_exo']=='yes'?'selected':'' ?>>Yes</option>
										<option value="no" <?=$json['video_subtiltes_exo']=='no'?'selected':'' ?>>No</option>
									</select>
								</div>
								<div class="form-group mb-3">
									<label class="control-label" for="last_volume_exo">
										<strong> Set Default Volume:</strong>
									</label>
									<select class="form-control" id="select" name="last_volume_exo">
										<option value="60" <?=$json['last_volume_exo']=='60'?'selected':'' ?>>60%</option>
										<option value="70" <?=$json['last_volume_exo']=='70'?'selected':'' ?>>70%</option>
										<option value="80" <?=$json['last_volume_exo']=='80'?'selected':'' ?>>80%</option>
										<option value="90" <?=$json['last_volume_exo']=='90'?'selected':'' ?>>90%</option>
										<option value="100" <?=$json['last_volume_exo']=='100'?'selected':'' ?>>100%</option>
									</select>
									<hr>
								</div>
								<div class="form-group">
									<center>
									<button class="btn btn-info" name="submit" value="exo" type="submit">
										<i class="fa fa-check"></i> Update
									</button>
									</center>
								</div>
							</form>
						</div>
					</div>
				</div>




				<div class="card-body">
					<div class="card bg-primary text-white">
						<div class="card-header card-header-warning">
							<center>
								<h3><i class="fa fa-play-circle"></i> VLC-Player Settings</h3>
							</center>
						</div>
						<div class="card-body bg-primary">
							<form method="post">
								<div class="form-group mb-3">
									<label class="control-label" for="plyer_vlc_buffer">
										<strong> Set Buffer Size:</strong>
									</label>
									<select class="form-control" id="select" name="plyer_vlc_buffer">
										<option value="300" <?=$json['plyer_vlc_buffer']=='60'?'selected':'' ?>>300 Miliseconds</option>
										<option value="1000" <?=$json['plyer_vlc_buffer']=='1000'?'selected':'' ?>>1 Second</option>
										<option value="2000" <?=$json['plyer_vlc_buffer']=='2000'?'selected':'' ?>>2 Second</option>
										<option value="3000" <?=$json['plyer_vlc_buffer']=='3000'?'selected':'' ?>>3 Second</option>
										<option value="5000" <?=$json['plyer_vlc_buffer']=='5000'?'selected':'' ?>>5 Second</option>
									</select>
								</div>
								<div class="form-group mb-3">
									<label class="control-label" for="video_resize_vlc">
										<strong> Set Zoom:</strong>
									</label>
									<select class="form-control" id="select" name="video_resize_vlc">
										<option value="0" <?=$json['video_resize_vlc']=='0'?'selected':'' ?>>Best Fit</option>
										<option value="1" <?=$json['video_resize_vlc']=='1'?'selected':'' ?>>16:9</option>
										<option value="2" <?=$json['video_resize_vlc']=='2'?'selected':'' ?>>4:3</option>
										<option value="3" <?=$json['video_resize_vlc']=='3'?'selected':'' ?>>Original</option>
										<option value="4" <?=$json['video_resize_vlc']=='4'?'selected':'' ?>>Fill</option>
									</select>
								</div>
								<div class="form-group mb-3">
									<label class="control-label" for="vlc_hw">
										<strong> Enable Hardware Decoder:</strong>
									</label>
									<select class="form-control" id="select" name="vlc_hw">
										<option value="yes" <?=$json['vlc_hw']=='yes'?'selected':'' ?>>Yes</option>
										<option value="no" <?=$json['vlc_hw']=='no'?'selected':'' ?>>No</option>
									</select>
								</div>
								<div class="form-group mb-3">
									<label class="control-label" for="video_subtiltes_vlc">
										<strong> Enable Subtitles:</strong>
									</label>
									<select class="form-control" id="select" name="video_subtiltes_vlc">
										<option value="yes" <?=$json['video_subtiltes_vlc']=='yes'?'selected':'' ?>>Yes</option>
										<option value="no" <?=$json['video_subtiltes_vlc']=='no'?'selected':'' ?>>No</option>
									</select>
								</div>
								<div class="form-group mb-3">
									<label class="control-label" for="last_volume_vlc">
										<strong> Set Default Volume:</strong>
									</label>
									<select class="form-control" id="select" name="last_volume_vlc">
										<option value="60" <?=$json['last_volume_vlc']=='60'?'selected':'' ?>>60%</option>
										<option value="70" <?=$json['last_volume_vlc']=='70'?'selected':'' ?>>70%</option>
										<option value="80" <?=$json['last_volume_vlc']=='80'?'selected':'' ?>>80%</option>
										<option value="90" <?=$json['last_volume_vlc']=='90'?'selected':'' ?>>90%</option>
										<option value="100" <?=$json['last_volume_vlc']=='100'?'selected':'' ?>>100%</option>
									</select>
									<hr>
								</div>
								<div class="form-group">
									<center>
									<button class="btn btn-info" name="submit" value="vlc" type="submit">
										<i class="fa fa-check"></i> Update
									</button>
									</center>
								</div>
							</form>
						</div>
					</div>
				</div>



				<div class="card-body">
					<div class="card bg-primary text-white">
						<div class="card-header card-header-warning">
							<center>
								<h2><i class="fa fa-play-circle"></i> Player Selection</h2>
							</center>
						</div>
						<div class="card-body">
							<form method="post">
								<div class="form-group ">
									<label class="form-label">Choose Live video player</label>
									<select class="form-control" id="select" name="player">
										<option value="EXO" <?=$json_p['player']=='EXO'?'selected':'' ?>>EXO Player</option>
										<option value="VLC" <?=$json_p['player']=='VLC'?'selected':'' ?>>VLC Player</option>
									</select>			
								</div>
	
								<div class="form-group ">
									<label class="form-label">Choose EPG video player</label>
									<select class="form-control" id="select" name="player_tv">
										<option value="EXO" <?=$json_p['player_tv']=='EXO'?'selected':'' ?>>EXO Player</option>
										<option value="VLC" <?=$json_p['player_tv']=='VLC'?'selected':'' ?>>VLC Player</option>
									</select>			
								</div>
	
								<div class="form-group ">
									<label class="form-label">Choose VOD video player</label>
									<select class="form-control" id="select" name="player_vod">
										<option value="EXO" <?=$json_p['player_vod']=='EXO'?'selected':'' ?>>EXO Player</option>
										<option value="VLC" <?=$json_p['player_vod']=='VLC'?'selected':'' ?>>VLC Player</option>
									</select>			
								</div>
	
								<div class="form-group ">
									<label class="form-label">Choose Series video player</label>
									<select class="form-control" id="select" name="player_series">
										<option value="EXO" <?=$json_p['player_series']=='EXO'?'selected':'' ?>>EXO Player</option>
										<option value="VLC" <?=$json_p['player_series']=='VLC'?'selected':'' ?>>VLC Player</option>
									</select>			
								</div>
	
								<hr>
	
								<div class="form-group">
									<center>
									<button class="btn btn-info" name="submit" value="player" type="submit">
										<i class="fa fa-check"></i> Update
									</button>
									</center>
								</div>
							</form>
						</div>
					</div>
				</div>

		</div>
		<!-- Column -->
		<?php include ('includes/footer.php');?>
	</div>