<?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['vastconfig'];
$vast_enabled = $json['vast_enabled'];
$mid_roll_interval = $json['mid_roll_interval'];
$post_roll_start_at = $json['post_roll_start_at'];
$vod_post_roll_url = $json['vod_post_roll_url'];
$vod_pre_roll_url = $json['vod_pre_roll_url'];
$vod_mid_roll_url = $json['vod_mid_roll_url'];
$vod_mid_roll_interval = $json['vod_mid_roll_interval'];
$series_post_roll_url = $json['series_post_roll_url'];
$series_pre_roll_url = $json['series_pre_roll_url'];
$series_mid_roll_url = $json['series_mid_roll_url'];
$series_mid_roll_interval = $json['series_mid_roll_interval'];
$message = '<div class="alert alert-primary" id="flash-msg"><h4><i class="icon fa fa-check"></i>Items Updated!</h4></div>';

if (isset($_POST['submitC'])) {
	$jsonData = file_get_contents('./api/json/slc_xcdata.json');
	$arrayData = json_decode($jsonData, true);
	$vastconfig = [
		'vastconfig' => ['vast_enabled' => $_POST['vast_enabled'], 'mid_roll_interval' => $_POST['mid_roll_interval'], 'post_roll_start_at' => $_POST['post_roll_start_at'], 'vod_post_roll_url' => $_POST['vod_post_roll_url'], 'vod_pre_roll_url' => $_POST['vod_pre_roll_url'], 'vod_mid_roll_url' => $_POST['vod_mid_roll_url'], 'vod_mid_roll_interval' => $_POST['vod_mid_roll_interval'], 'series_post_roll_url' => $_POST['series_post_roll_url'], 'series_pre_roll_url' => $_POST['series_pre_roll_url'], 'series_mid_roll_url' => $_POST['series_mid_roll_url'], 'series_mid_roll_interval' => $_POST['series_mid_roll_interval']]
	];
	$replacementData = ['app' => $vastconfig];
	$newArrayData = array_replace_recursive($arrayData, $replacementData);
	$newJsonData = json_encode($newArrayData, JSON_PRETTY_PRINT);
	file_put_contents('./api/json/slc_xcdata.json', $newJsonData);
	header('Location: adsVast.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 VAST 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://developers.google.com/third-party-ads/adx-vendors" 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="vast_enabled" >VAST Enabled</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<select class="form-control" id="select" name="vast_enabled">' . "\n\t\t\t\t\t\t\t\t\t\t" . '<option value="yes" ';

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

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

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

echo "\t\t\t\t\t\t\t\t\t\t";
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="mid_roll_interval" >Mid Roll Interval</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="mid_roll_interval" value="' . $json['mid_roll_interval'] . '" 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="post_roll_start_at" >Post Roll Start At</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="post_roll_start_at" value="' . $json['post_roll_start_at'] . '" 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="vod_post_roll_url" >Vod Post Roll Url</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="vod_post_roll_url" value="' . $json['vod_post_roll_url'] . '" 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="vod_pre_roll_url" >Vod Pre Roll Url</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="vod_pre_roll_url" value="' . $json['vod_pre_roll_url'] . '" 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="vod_mid_roll_url" >Vod Mid Roll Url</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="vod_mid_roll_url" value="' . $json['vod_mid_roll_url'] . '" 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="vod_mid_roll_interval" >Vod Mid Roll Interval</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="vod_mid_roll_interval" value="' . $json['vod_mid_roll_interval'] . '" 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="series_post_roll_url" >Series Post Roll Url</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="series_post_roll_url" value="' . $json['series_post_roll_url'] . '" 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="series_pre_roll_url" >Series Pre Roll Url</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="series_pre_roll_url" value="' . $json['series_pre_roll_url'] . '" 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="series_mid_roll_url" >Series Mid Roll Url</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="series_mid_roll_url" value="' . $json['series_mid_roll_url'] . '" 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="series_mid_roll_interval" >Series Mid Roll Interval</label>' . "\n\t\t\t\t\t\t\t\t\t" . '<input class="form-control" id="description" name="series_mid_roll_interval" value="' . $json['series_mid_roll_interval'] . '" 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="submitC" 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";

?>