<?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> In-app Advertisements</h2>
						</center>
					</div>
					<div class="alert alert-info alert-dismissible" role="alert">
						<center>
							Earm more with your app. Click <a href="https://apps.admob.com/signup/" style="color:green!important;">here</a>
							to get more information.
						</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 Enabled</label>
									<select class="form-control" id="select" name="admob_enabled">
										<option value="yes"<?=$json['admob_enabled']=='yes'?'selected':'' ?>>Enabled</option>
										<option value="no" <?=$json['admob_enabled']=='no'?'selected':'' ?>>Disabled</option>
									</select>								 
								</div>

								<div class="form-group form-float form-group-lg">
									<label class="form-label" for="Banner_ID" >Admob Banner ID</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" >Admob App ID</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" >Admob Interstitial ID</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> Update Adverts
										</button>
									</center>
								</div>
							</form>
					</div>
				</div>
			</div>
		</div>


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

</body>
</html>