<?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/realm_ads.db');
$table_name = 'realmads';
$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);
}

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)) {
			$realm_patch = '' . $file_path . $_FILES['image']['name'] . '';
			$adsimg = $realm_patch;
			$createdon = date('Y-m-d H:i:s');
			$extension = 'png';
			$adshv = $_POST['position'];
			$db->exec('INSERT INTO realmads(title, type, link, description, position, extension, createdon, thumbpath) VALUES(\'' . $_POST['title'] . '\',\'' . $_POST['type'] . '\',\'https://realmofapknpanels.com\',\'Realm Of APK n PANELS\',' . "\r\n\t" . '\'' . $adshv . '\',\'' . $extension . '\',\'' . $createdon . '\',\'' . $adsimg . '\')' . "\r\n\t");
			$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 saved Image file..';
			$createdon = date('Y-m-d H:i:s');
			$type = $_POST['type'];
			$adsimg = $url;
			$adshv = $_POST['position'];
			$extension = 'png';
			$db->exec('INSERT INTO realmads(title, type, link, description, position, extension, createdon, thumbpath) VALUES(\'' . $_POST['title'] . '\',\'' . $type . '\',\'https://realmofapknpanels.com\',\'Realm Of APK n PANELS\',' . "\r\n\t" . '\'' . $adshv . '\',\'' . $extension . '\',\'' . $createdon . '\',\'' . $adsimg . '\')' . "\r\n\t");
			$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);
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> Add A ADS Banner</h4>' . "\r\n" . '                        ' . "\r\n\t\t\t\t\t\t" . '</center>' . "\r\n\n";
echo '                </div>' . "\n";
echo "\r\n\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" . '                            ' . "\r\n" . '                                <div class="form-group">' . "\r\n" . '                                    <label class="form-label " for="title"><strong>Banner Name</strong></label>' . "\r\n" . '                                    <input class="form-control text-primary" id="title" name="title" type="text"/>' . "\r\n" . '                                </div>' . "\r\n" . '                           ' . "\r\n" . '                                <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" selected>Upload 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">Enter Banner Image External URL' . "\r\n\t\t\t\t\t\t\t\t\t\t" . '  </option>' . "\r\n\t\t\t\t\t\t\t\t\t" . '  </select>' . "\r\n" . '                                    </div>' . "\r\n" . '                                </div>' . "\r\n" . '                         <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" 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" . '                         <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\t\t\t\t\t\t\t\t\t" . '    <option value="horizontal" data-value="1" selected>Horizontal</option>' . "\r\n" . '                                        <option value="vertical" data-value="0">Vertical</option> ' . "\r\n" . '                          </select>' . "\r\n" . '                          ' . "\r\n" . '                        </div>' . "\r\n" . '                        ' . "\r\n" . '                        ' . "\r\n" . '                                <div align="center" class="form-group">' . "\r\n\t\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" name="submit" type="submit"><span class="icon text-white-50"><i class="fa fa-plus"></i>&nbsp;&nbsp;</span><span class="text"> Add A DNS</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\t\t\t" . '   <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/r3alm.php';
echo '      </body>' . "\n";

?>