<?php
/**
*
* @ This file is created by http://DeZender.Net
* @ deZender (PHP7 Decoder for SourceGuardian Encoder)
*
* @ Version			:	5.0.1.0
* @ Author			:	DeZender
* @ Release on		:	22.04.2022
* @ Official site	:	http://DeZender.Net
*
*/


ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
error_reporting(E_ALL);
$db = new SQLite3('./api/db/brbox_ads.db');
$table_name = 'brboxads';
$base_file = basename($_SERVER['SCRIPT_NAME']);
$target_dir = 'banners/';
$file_path = (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] !== 'off') ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/' . $target_dir;

if (!file_exists($target_dir)) {
	mkdir($target_dir, 511, true);
}

$res = $db->query('SELECT * FROM brboxads WHERE id=\'' . $_GET['update'] . '\'');
$row = $res->fetchArray();

if (isset($_POST['submit'])) {
	if ($_POST['type'] == '0') {
		$target_file = $target_dir . $_FILES['image']['name'];
		$uploadOk = 1;
		$file_ext = strtolower(end(explode('.', $_FILES['image']['name'])));
		$extensions = ['gif', 'GIF', 'png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'bmp', 'BMP'];

		if (file_exists($target_file)) {
			unlink($target_file);
			$msg = '?messageA=The file already exists and has been replaced.';
		}
		else {
			$msg = '?messageS=Success, Image File uploaded.';
		}

		$uploadOk = 1;

		if (5000000 < $_FILES['image']['size']) {
			$msg = '?messageE=Sorry, your file is too large.';
			$uploadOk = 0;
		}

		if (is_int(in_array($file_ext, $extensions))) {
			$msg = '?messageE=Sorry, only JPEG or PNG or GIF files are allowed.';
			$uploadOk = 0;
		}

		if ($uploadOk == 0) {
			header('Location: ' . $base_file . $msg);
		}
		else if (move_uploaded_file($_FILES['image']['tmp_name'], $target_file)) {
			$brbox_patch = '' . $file_path . $_FILES['image']['name'] . '';
			$adsimg = $brbox_patch;
			$createdon = date('Y-m-d H:i:s');
			$extension = 'png';
			$adshv = $_POST['position'];
			$db->exec('UPDATE brboxads SET ' . "\r\n\t" . 'title=\'' . $_POST['title'] . '\', ' . "\r\n\t" . 'type=\'' . $_POST['type'] . '\', ' . "\r\n\t" . 'link=\'https://brboxofapknpanels.com\', ' . "\r\n\t" . 'description=\'brbox Of APK n PANELS\', ' . "\r\n\t" . 'position=\'' . $adshv . '\', ' . "\r\n\t" . 'extension=\'' . $extension . '\', ' . "\r\n\t" . 'createdon=\'' . $createdon . '\', ' . "\r\n\t" . 'thumbpath=\'' . $adsimg . '\'' . "\r\n\t" . 'WHERE   id=\'' . $_POST['id'] . '\'');
			$urld = $row['thumbpath'];
			$file_to_delete = basename(parse_url($urld, PHP_URL_PATH));
			$file_to_delete = 'banners/' . $file_to_delete;

			if (file_exists($file_to_delete)) {
				unlink($file_to_delete);
			}

			$db->close();
			header('Location: ads.php' . $msg);
		}
	}
	else {
		$url = $_POST['url'];
		$target_file = $target_dir . basename($url);
		$file_ext = strtolower(end(explode('.', $url)));
		$extensions = ['jpeg', 'jpg', 'png', 'gif', 'JPEG', 'JPG', 'PNG', 'GIF'];

		if (is_int(in_array($file_ext, $extensions))) {
			$msg = '?messageE=Sorry, only JPG or PNG or GIF files are allowed.';
			header('Location: ' . $base_file . $msg);
		}
		else {
			$msg = '?messageS=Saved!, Url of updated Image file..';
			$urld = $row['thumbpath'];
			$file_to_delete = basename(parse_url($urld, PHP_URL_PATH));
			$file_to_delete = 'banners/' . $file_to_delete;

			if (file_exists($file_to_delete)) {
				unlink($file_to_delete);
			}

			$createdon = date('Y-m-d H:i:s');
			$type = $_POST['type'];
			$adsimg = $url;
			$adshv = $_POST['position'];
			$extension = 'png';
			$db->exec('UPDATE brboxads SET ' . "\r\n\t" . 'title=\'' . $_POST['title'] . '\', ' . "\r\n\t" . 'type=\'' . $_POST['type'] . '\', ' . "\r\n\t" . 'link=\'https://brboxofapknpanels.com\', ' . "\r\n\t" . 'description=\'brbox Of APK n PANELS\', ' . "\r\n\t" . 'position=\'' . $adshv . '\', ' . "\r\n\t" . 'extension=\'' . $extension . '\', ' . "\r\n\t" . 'createdon=\'' . $createdon . '\', ' . "\r\n\t" . 'thumbpath=\'' . $adsimg . '\'' . "\r\n\t" . 'WHERE   id=\'' . $_POST['id'] . '\'');
			$db->close();
			header('Location: ads.php' . $msg);
		}
	}
}

include 'includes/header.php';
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
error_reporting(E_ALL);
$id = $row['id'];
$title = $row['title'];
$thumbpath = $row['thumbpath'];
$createdon = $row['createdon'];
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
error_reporting(E_ALL);
echo ' <!-- Begin Page Content -->' . "\n";
echo '        <div class="container-fluid">' . "\n";
echo "\n";

if (isset($_GET['message'])) {
	echo '<div class="alert alert-danger bg-primary py-3" id="flash-msg"><h4 align="center" class="m-0 font-weight-bold text-white"><i class="icon fa fa-check"></i> ' . $_GET['message'] . '</h4></div>';
}

if (isset($_GET['messageA'])) {
	echo '<div class="alert alert-danger bg-primary py-3" id="flash-msg"><h4 align="center" class="m-0 font-weight-bold text-white"><i class="icon fa fa-check"></i> ' . $_GET['messageA'] . '</h4></div>';
}

if (isset($_GET['messageE'])) {
	echo '<div class="alert alert-danger bg-danger py-3" id="flash-msg"><h4 align="center" class="m-0 font-weight-bold text-white"><i class="icon fa fa-times"></i> ' . $_GET['messageE'] . '</h4></div>';
}

if (isset($_GET['messageS'])) {
	echo '<div class="alert alert-danger bg-success py-3" id="flash-msg"><h4 align="center" class="m-0 font-weight-bold text-white"><i class="icon fa fa-check"></i> ' . $_GET['messageS'] . '</h4></div>';
}

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 '                <center><h4 align="center" class="m-0 text-white"><i class="fas fa-server" style="font-size:20px">&nbsp;&nbsp;</i> Edit A ADS Banner</h4>' . "\r\n" . '                        ' . "\r\n\t\t\t\t\t\t" . '</center>' . "\r\n\n";
echo '                </div>' . "\n";
echo "\r\n" . '                         <div class="card-body">' . "\r\n\t\t\t\t\t\t\t\t" . '<form method="post" enctype="multipart/form-data">' . "\r\n" . '                        <div  type="hidden" class="form-group">' . "\r\n\t\t\t\t\t\t" . '   <input type="hidden" name="id" value="';
echo $row['id'];
echo '">' . "\r\n" . '                          <input type="hidden" id="id" class="form-control text-primary" name="id" value="';
echo $row['id'];
echo '">' . "\r\n" . '                        </div>' . "\r\n" . '                         <div class="form-group">' . "\r\n" . '                          <label class="bmd-label-floating"><strong>Banner Name</strong></label>' . "\r\n\r\n" . '                          <input type="text" id="title" class="form-control text-primary" name="title" value="';
echo $row['title'];
echo '">' . "\r\n\r\n" . '                        </div>' . "\r\n\t\t\t\t\t\t" . '                                <div class="form-group ">' . "\r\n" . '                                   <label class="control-label " for="vpn_config">' . "\r\n" . '                                       <strong>Select Banner Image File Type</strong>' . "\r\n" . '                                  </label>' . "\r\n" . '                                 <div class="input-group">' . "\r\n\t\t\t\t\t\t\t\t\t" . '  <select class="form-control type" id="type" name="type">' . "\r\n\t\t\t\t\t\t\t\t\t\t" . '  <option data-value="op0" value="0" ';
echo $row['type'] == '0' ? 'selected' : '';
echo '>Upload Banner Image File' . "\r\n\t\t\t\t\t\t\t\t\t\t" . '  </option>' . "\r\n\t\t\t\t\t\t\t\t\t\t" . '  <option data-value="op1" value="1" ';
echo $row['type'] == '1' ? 'selected' : '';
echo '>Enter Banner Image External URL' . "\r\n\t\t\t\t\t\t\t\t\t" . '  </select>' . "\r\n" . '                                    </div>' . "\r\n" . '                                </div>' . "\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t" . '  ' . "\r\n\t\t\t\t\t\t" . '    <div class="activeu">' . "\r\n\t\t\t\t\t\t\t" . '<div class="form-group ">' . "\r\n" . '                             <label class="control-label"><strong> Enter Banner Image External Url</strong></label>' . "\r\n" . '                                <div class="input-group">' . "\r\n" . '                                 <input  class="form-control" type="text" name="url" value="';
echo $row['thumbpath'];
echo '" placeholder="Enter URL file.gif or file.png or file.jpg...">' . "\r\n" . '                                </div>' . "\r\n" . '                             </div>' . "\r\n" . '                         </div>' . "\r\n\t\t\t\t\t\t" . ' ' . "\r\n\t\t\t\t\t\t" . '                       <div class="actived">' . "\r\n" . '                        <div class="form-group ">' . "\r\n" . '                            <label class="control-label"> <strong> Upload Banner Image File</strong></label>' . "\r\n\t\t\t\t\t\t" . '      <div class="input-group">' . "\r\n\t\t\t\t\t\t" . '      ' . "\t" . '<div class="custom-file">' . "\r\n\t\t\t\t\t" . '        ' . "\t" . '<input type="file" class="custom-file-input" name="image" id="intro" placeholder="Choose Intro" onchange="uploadintro(this)" aria-describedby="intro">' . "\r\n\t\t\t" . '<label class="custom-file-label" for="intro" placeholder="Choose Background Image"><span id="image-intro"></span></label>' . "\r\n\t\t\t\t" . '          ' . "\t" . '   </div>' . "\r\n\t\t\t" . '                </div>' . "\r\n\t\t" . '        ' . "\t" . '     </div>' . "\r\n\t\t" . '    ' . "\t" . '       </div>' . "\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\t\r\n" . '                         <div class="form-group">' . "\r\n" . '                          <label class="bmd-label-floating"><strong>Banner Position</strong></label>' . "\r\n\r\n" . '<select class="select form-control type" id="position" name="position">' . "\r\n" . '                                        <option value="vertical" data-value="0" ';
echo $PHV == 'vertical' ? 'selected' : '';
echo '>Vertical</option> ' . "\r\n\t\t\t\t\t\t\t\t\t" . '    <option value="horizontal" data-value="1"  ';
echo $PHV == 'horizontal' ? 'selected' : '';
echo '>Horizontal</option>' . "\r\n" . '                          </select>' . "\r\n" . '                          ' . "\r\n" . '                        </div>' . "\r\n" . '                        ' . "\r\n" . '                        ' . "\r\n" . '                        <div align="center" class="form-group mb-3">' . "\r\n\t\t\t\t\t\t\t\t\t" . '<br>' . "\r\n\t\t\t\t\t\t\t\t\t\t" . '<button class="btn btn-success btn-icon-split" name="submit" type="submit"><span class="icon text-white-50"><i class="fas fa-save"></i>&nbsp;&nbsp;</span><span class="text"> Save Settings</span></button>' . "\r\n" . '                                </div>' . "\r\n" . '                            </form>' . "\r\n" . '                            </div>' . "\r\n" . '                        </div>' . "\r\n" . '                    </div>' . "\r\n" . '                    <!-- Column -->' . "\r\n" . '                </div>' . "\r\n" . '            </div>' . "\r\n" . '            <!-- ============================================================== -->' . "\r\n" . '            <!-- End Container fluid  -->' . "\r\n" . '            <!-- ============================================================== -->' . "\r\n" . '        </div>' . "\r\n" . '        <!-- ============================================================== -->' . "\r\n" . '        <!-- End Page wrapper  -->' . "\r\n" . '        <!-- ============================================================== -->' . "\r\n" . '    </div>' . "\r\n\r\n" . '    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>' . "\r\n" . '    <script>' . "\r\n" . '//select activecode form' . "\r\n" . '//var response = {};' . "\r\n" . '//response.val = "op2";' . "\r\n" . '//$("#codemode option[data-value=\'" + response.val +"\']").attr("selected","selected");' . "\r\n\r\n" . '//hide activecode form' . "\r\n" . '$(\'.actived\').show(); ' . "\r\n\r\n" . '$(\'.activeu\').hide(); ' . "\r\n\r\n\r\n" . '//Show/hide activecode select' . "\r\n" . '$(document).ready(function(){' . "\r\n" . '  $(\'.type\').change(function(){' . "\r\n" . '    if($(\'.type\').val() > 0) {' . "\r\n" . '      $(\'.actived\').hide(); ' . "\r\n" . '      $(\'.activeu\').show(); ' . "\r\n" . '    } else {' . "\r\n" . '      $(\'.activeu\').hide(); ' . "\r\n" . '      $(\'.actived\').show(); ' . "\r\n" . '     document.getElementById("activeu").value = \' \';' . "\r\n" . '    } ' . "\r\n" . '  });' . "\r\n" . '  $(\'.type\').ready(function(){' . "\r\n" . '    if($(\'.type\').val() > 0) {' . "\r\n" . '      $(\'.actived\').hide(); ' . "\r\n" . '      $(\'.activeu\').show(); ' . "\r\n" . '    }else {' . "\r\n" . '      $(\'.activeu\').hide(); ' . "\r\n" . '      $(\'.actived\').show(); ' . "\r\n" . '     document.getElementById("actived").value = \' \';' . "\r\n" . '      ' . "\r\n" . '    } ' . "\r\n" . '  });' . "\r\n" . '});' . "\r\n" . '</script>' . "\r\n" . '<script>' . "\r\n" . 'function formSubmit(radioObj){' . "\r\n" . '  if(radioObj.checked){' . "\r\n" . '    document.getElementById("onoff").submit();' . "\r\n\r\n" . '  }' . "\r\n" . '}' . "\r\n" . '</script>' . "\r\n";
echo '<script>';
echo 'function uploadintro(target) {' . "\n";
echo "\t" . 'document.getElementById("image-intro").innerHTML = target.files[0].name;' . "\n";
echo '}' . "\n";
echo "\n";
echo '$(document).ready(function() {' . "\n";
echo '    if (location.hash) {' . "\n";
echo '        $("a[href=\'" + location.hash + "\']").tab("show");' . "\n";
echo '    }' . "\n";
echo '    $(document.body).on("click", "a[data-toggle=\'tab\']", function(event) {' . "\n";
echo '        location.hash = this.getAttribute("href");' . "\n";
echo '    });' . "\n";
echo '});' . "\n";
echo '$(window).on("popstate", function() {' . "\n";
echo '    var anchor = location.hash || $("a[data-toggle=\'tab\']").first().attr("href");' . "\n";
echo '    $("a[href=\'" + anchor + "\']").tab("show");' . "\n";
echo '});' . "\n";
echo "\n";
echo '</script>';
echo '    <br><br><br>';
include 'includes/footer.php';
require 'includes/brbox.php';
echo '      </body>' . "\n";

?>