<?php


ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
error_reporting(E_ALL);
$jsondata = file_get_contents('./api/json/slc_xcdata.json');
$data = json_decode($jsondata, true);
$jsonapp = $data['app'];
$admob_banner_id = $jsonapp['admob_banner_id'];
$admob_interstitial_id = $jsonapp['admob_interstitial_id'];
$json = $jsonapp['admobconfig'];
$admob_enabled = $json['admob_enabled'];
$Banner_ID = $json['Banner_ID'];
$AdMob_App_ID = $json['AdMob_App_ID'];
$Interstitial_ID = $json['Interstitial_ID'];
$message = '<div class="alert alert-primary" id="flash-msg"><h4><i class="icon fa fa-check"></i>Items Updated!</h4></div>';

if (isset($_POST['submitA'])) {
	$jsonData = file_get_contents('./api/json/slc_xcdata.json');
	$arrayData = json_decode($jsonData, true);
	$admobconfig = [
		'admobconfig' => ['admob_enabled' => $_POST['admob_enabled'], 'Banner_ID' => $_POST['Banner_ID'], 'AdMob_App_ID' => $_POST['AdMob_App_ID'], 'Interstitial_ID' => $_POST['Interstitial_ID']]
	];
	$replacementData = ['app' => $admobconfig];
	$newArrayData = array_replace_recursive($arrayData, $replacementData);
	$newJsonData = json_encode($newArrayData, JSON_PRETTY_PRINT);
	file_put_contents('./api/json/slc_xcdata.json', $newJsonData);
	header('Location: adsAdmob.php?message=' . $message);
}

include 'includes/header.php';
echo ' <!-- Begin Page Content -->' . "\n";
echo '        <div class="container-fluid">' . "\n";
echo "\n";

if (isset($_GET['message'])) {
	echo $_GET['message'];
}

echo '          <!-- Content Row -->' . "\n";
echo '          <div class="row">' . "\n";
echo "\n";
echo '            <!-- First Column -->' . "\n";
echo '            <div class="col-lg-12">' . "\n";
echo "\n";
echo '              <!-- Custom codes -->' . "\n";
echo '                <div class="card text-text-primary">' . "\n";
echo '                <div class="card-header bg-primary py-3">' . "\n";
echo ' ' . "\t\t\t\n\t\t\t\t\t\t" . '<center>' . "\n\t\t\t\t\t\t\t" . '<h4 align="center" class="m-0 text-white"><i class="fa fa-money"></i> In-app Admob Advertisements</h4>' . "\n\t\t\t\t\t\t" . '</center>' . "\n\t\t\t\t\t" . '</div>' . "\n\t\t\t\t\t" . '<div class="alert-danger alert-dismissible" role="alert">' . "\n\t\t\t\t\t\t" . '<center>' . "\n\t\t\t\t\t\t\t" . 'Earm more with your app. Click <a href="https://apps.admob.com/signup/" style="color:green!important;">here</a>' . "\n\t\t\t\t\t\t\t" . 'to get more information.' . "\n\t\t\t\t\t\t" . '</center>' . "\n\t\t\t\t\t" . '</div>' . "\n\t\t\t\t\t" . '<div class="card-body">' . "\n\t\t\t\t\t\t\t" . '<form method="post">' . "\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t" . '<div class="form-group form-float form-group-lg">' . "\n\t\t\t\t\t\t\t\t\t" . '<label class="form-label" for="admob_enabled" >Admob Enabled</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<select class="form-control" id="select" name="admob_enabled">' . "\n\t\t\t\t\t\t\t\t\t\t" . '<option value="yes" ';

if ($json['admob_enabled'] == 'yes') {
	echo 'selected';
}

echo '> Enabled</option>' . "\n\t\t\t\t\t\t\t\t\t\t" . '<option value="no" ';

if ($json['admob_enabled'] == 'no') {
	echo 'selected';
}

echo '> Disabled</option>' . "\n\t\t\t\t\t\t\t\t\t" . '</select>' . "\t\t\t\t\t\t\t\t" . ' ' . "\n\t\t\t\t\t\t\t\t" . '</div>' . "\n\n\t\t\t\t\t\t\t\t" . '<div class="form-group form-float form-group-lg">' . "\n\t\t\t\t\t\t\t\t\t" . '<label class="form-label" for="Banner_ID" >Admob Banner ID</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="Banner_ID" value="' . $json['Banner_ID'] . '" type="text"/>' . "\n\t\t\t\t\t\t\t\t" . '</div>' . "\n\n\t\t\t\t\t\t\t\t" . '<div class="form-group form-float form-group-lg">' . "\n\t\t\t\t\t\t\t\t\t" . '<label class="form-label" for="AdMob_App_ID" >Admob App ID</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="AdMob_App_ID" value="' . $json['AdMob_App_ID'] . '" type="text"/>' . "\n\t\t\t\t\t\t\t\t" . '</div>' . "\n\n\t\t\t\t\t\t\t\t" . '<div class="form-group form-float form-group-lg">' . "\n\t\t\t\t\t\t\t\t\t" . '<label class="form-label" for="Interstitial_ID" >Admob Interstitial ID</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="Interstitial_ID" value="' . $json['Interstitial_ID'] . '" type="text"/>' . "\n\t\t\t\t\t\t\t\t" . '</div>' . "\n\n\t\t\t\t\t\t\t\t" . '<hr>' . "\n\n\t\t\t\t\t\t\t\t" . '<div class="form-group">' . "\n\t\t\t\t\t\t\t\t\t" . '<center>' . "\n\t\t\t\t\t\t\t\t\t\t" . '<button class="btn btn-info" name="submitA" type="submit">' . "\n\t\t\t\t\t\t\t\t\t\t\t" . '<i class="fa fa-check"></i> Update Adverts' . "\n\t\t\t\t\t\t\t\t\t\t" . '</button>' . "\n\t\t\t\t\t\t\t\t\t" . '</center>' . "\n\t\t\t\t\t\t\t\t" . '</div>' . "\n\t\t\t\t\t\t\t" . '</form>' . "\n";
echo '                </div>' . "\n";
echo '                </div>' . "\n";
echo '              </div>' . "\n";
echo '            </div>' . "\n";
echo '            </div>' . "\n";
echo "\n";
echo '    <br><br><br>';
include 'includes/footer.php';
require 'includes/slc.php';
echo '      </body>' . "\n";

?>