<?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'];
$json = $jsonapp['prebid'];
$prebid_enabled = $json['prebid_enabled'];
$Host = $json['Host'];
$Banner = $json['Banner'];
$Native = $json['Native'];
$AdUnitId = $json['AdUnitId'];
$Rewarded = $json['Rewarded'];
$AccountId = $json['AccountId'];
$Interstitial = $json['Interstitial'];
$Medium_Rectangle = $json['Medium_Rectangle'];
$prebidservercode = $json['prebidservercode'];
$message = '<div class="alert alert-primary" id="flash-msg"><h4><i class="icon fa fa-check"></i>Items Updated!</h4></div>';

if (isset($_POST['submitB'])) {
	$jsonData = file_get_contents('./api/json/slc_xcdata.json');
	$arrayData = json_decode($jsonData, true);
	$admobconfig = [
		'prebid' => ['prebid_enabled' => $_POST['prebid_enabled'], 'Host' => $_POST['Host'], 'Banner' => $_POST['Banner'], 'Native' => $_POST['Native'], 'AdUnitId' => $_POST['AdUnitId'], 'Rewarded' => $_POST['Rewarded'], 'AccountId' => $_POST['AccountId'], 'Interstitial' => $_POST['Interstitial'], 'Medium_Rectangle' => $_POST['Medium_Rectangle'], 'prebidservercode' => $_POST['prebidservercode']]
	];
	$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: adsPrebid.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 Prebid 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-info 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://prebid.org/" 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="prebid_enabled">' . "\n\t\t\t\t\t\t\t\t\t\t" . '<option value="yes" ';

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

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

if ($json['prebid_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="Host_ID" >Host</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="Host" value="' . $json['Host'] . '" type="text"/>' . "\n\t\t\t\t\t\t\t\t" . '</div>' . "\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" >Banner ID</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="Banner" value="' . $json['Banner'] . '" 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="Native_ID" >Native</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="Native" value="' . $json['Native'] . '" type="text"/>' . "\n\t\t\t\t\t\t\t\t" . '</div>' . "\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="AdUnitId" >Ad Unit Id</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="" value="AdUnitId' . $json['AdUnitId'] . '" type="text"/>' . "\n\t\t\t\t\t\t\t\t" . '</div>' . "\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="Rewarded" >Rewarded</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="Rewarded" value="' . $json['Rewarded'] . '" type="text"/>' . "\n\t\t\t\t\t\t\t\t" . '</div>' . "\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="AccountId" >Account Id</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="AccountId" value="' . $json['AccountId'] . '" type="text"/>' . "\n\t\t\t\t\t\t\t\t" . '</div>' . "\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" >Interstitial</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="Interstitial" value="' . $json['Interstitial'] . '" type="text"/>' . "\n\t\t\t\t\t\t\t\t" . '</div>' . "\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="Medium_Rectangle" >Medium_Rectangle</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="Medium_Rectangle" value="' . $json['Medium_Rectangle'] . '" type="text"/>' . "\n\t\t\t\t\t\t\t\t" . '</div>' . "\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="prebidservercode" >Prebid Server Code</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="prebidservercode" value="' . $json['prebidservercode'] . '" type="text"/>' . "\n\t\t\t\t\t\t\t\t" . '</div>' . "\n\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="submitB" 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";

?>