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

if (isset($_POST['submit'])){
	$jsonData = file_get_contents("./api/main.json");
	$arrayData = json_decode($jsonData, true);
	$replacementData = array(
		'app' => array('admobconfig' => array(
			'admob_enabled' => $_POST["admob_enabled"],
			'Banner_ID' => $_POST["Banner_ID"],
			'Interstitial_ID' => $_POST["Interstitial_ID"],
			'AdMob_App_ID' => $_POST["AdMob_App_ID"]
		)));
	$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");
}
include ('includes/header.php');
?>

		<div class="col-md-8 mx-auto">
			<div class="card-body">
				<div class="card bg-primary text-white">
					<div class="card-header">
						<center>
							<h2><i class="fa fa-money"></i> Anúncios na aplicação</h2>
						</center>
					</div>
					<div class="alert alert-info alert-dismissible" role="alert">
						<center>
							Earm mais com a sua aplicação. Clique em <a href="https://apps.admob.com/signup/" style="color:green!important;">aqui</a>
							para obter mais informações.
						</center>
					</div>
					<div class="card-body">
							<form method="post">
							
							
							<div class="form-group form-float form-group-lg">
									<label class="form-label" for="admob_enabled" >Admob ativado</label>
									<select class="form-control" id="select" name="admob_enabled">
										<option value="yes"<?=$json['admob_enabled']=='yes'?'selected':'' ?>>Ativado</option>
										<option value="no" <?=$json['admob_enabled']=='no'?'selected':'' ?>>Desativado</option>
									</select>								 
								</div>

								<div class="form-group form-float form-group-lg">
									<label class="form-label" for="Banner_ID" >ID do banner Admob</label>
									<input class="form-control" id="description" name="Banner_ID" value="<?=$json['Banner_ID']?>" type="text"/>
								</div>

								<div class="form-group form-float form-group-lg">
									<label class="form-label" for="AdMob_App_ID" >ID de aplicação Admob</label>
									<input class="form-control" id="description" name="AdMob_App_ID" value="<?=$json['AdMob_App_ID']?>" type="text"/>
								</div>

								<div class="form-group form-float form-group-lg">
									<label class="form-label" for="Interstitial_ID" >ID intersticial da Admob</label>
									<input class="form-control" id="description" name="Interstitial_ID" value="<?=$json['Interstitial_ID']?>" type="text"/>
								</div>

								<hr>

								<div class="form-group">
									<center>
										<button class="btn btn-info" name="submit" type="submit">
											<i class="fa fa-check"></i> Atualizar anúncios
										</button>
									</center>
								</div>
							</form>
					</div>
				</div>
			</div>
		</div>


<?php include ('includes/footer.php'); ?>

</body>
</html>