<?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);
$dbbrboxa = new SQLite3('./api/db/brbox_ads.db');
$dbbrboxa->exec('CREATE TABLE IF NOT EXISTS brboxads(id INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL,title VARCHAR(100), type VARCHAR(100), link VARCHAR(100), description VARCHAR(100), position VARCHAR(100), extension VARCHAR(100),createdon VARCHAR(100),thumbpath VARCHAR(100))');
$res = $dbbrboxa->query('SELECT * FROM brboxads');
$rows = $dbbrboxa->query('SELECT COUNT(*) as count FROM brboxads');
$row = $rows->fetchArray();
$numRows = $row['count'];
$HOSTa = $lurl = (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] !== 'off') ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/banner/demo.png';
$date = date('Y-m-d H:i:s');

if ($numRows == 0) {
	$dbbrboxa->exec('INSERT INTO brboxads(title, type, link, description, position, extension, createdon, thumbpath) VALUES(\'Sample\',\'image\',\'https://brboxofapknpanels.com\',\'brbox Of APK n PANELS\',\'vertical\',\'png\',\'' . $date . '\',\'' . $HOSTa . '\')');
}

if (isset($_GET['delete'])) {
	$resd = $dbbrboxa->query('SELECT * FROM  brboxads WHERE id=' . $_GET['delete']);
	$rowd = $resd->fetchArray();
	$url = $rowd['thumbpath'];
	$file_to_delete = basename(parse_url($url, PHP_URL_PATH));
	$file_to_delete = 'banners/' . $file_to_delete;

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

	$dbbrboxa->exec('DELETE FROM brboxads WHERE id=' . $_GET['delete']);
	header('Location: ads.php');
}

include 'includes/header.php';
echo ' <!-- Begin Page Content -->' . "\n";
echo '        <div class="container-fluid">' . "\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> ADS Banner Management</h4>' . "\r\n" . '                        ' . "\r\n\t\t\t\t\t\t" . '</center>' . "\r\n\n";
echo '                </div>' . "\n";
echo '                                       <div class="card-body">' . "\r\n" . '<a button class="btn btn-success btn-icon-split" href="./ads_create.php">' . "\r\n" . '    <span class="icon text-white-50"><i class="fas fa-plus" ></i></span><span class="text"> Add A ADS</span></button></a>' . "\r\n" . '<hr>' . "\r\n\t\t\t\t\t\t" . '<div class="table-responsive">' . "\r\n\t\t\t\t\t\t\t" . '<table class="table table-striped table-sm">' . "\r\n\t\t\t\t\t\t\t" . '<thead align="center" class="text-primary">' . "\r\n\t\t\t\t\t\t\t\t" . '<tr>' . "\r\n\t\t\t\t\t\t\t\t" . '<th><strong>Banner Preview</strong></th>' . "\r\n\t\t\t\t\t\t\t\t" . '<th><strong>Banner Name / Date Add</strong></th>' . "\r\n\t\t\t\t\t\t\t\t" . '<th><strong>Banner Type</strong></th>' . "\r\n\t\t\t\t\t\t\t\t" . '<th><strong>Banner URL</strong></th>' . "\r\n\t\t\t\t\t\t\t\t" . '<th><strong>Banner Position H/V</strong></th>' . "\r\n\t\t\t\t\t\t\t\t" . '<th><strong>Edit</strong></th>' . "\r\n\t\t\t\t\t\t\t\t" . '<th><strong>Delete</strong></th>' . "\r\n\t\t\t\t\t\t\t\t" . '</tr>' . "\r\n\t\t\t\t\t\t\t" . '</thead>' . "\n";

while ($row = $res->fetchArray()) {
	echo '  ' . "\r\n\t\t\t\t\t\t\t" . '<tbody align="center">' . "\r\n\t\t\t\t\t\t\t\t" . '<tr class="text-primary">' . "\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t" . '<td><img src="' . $row['thumbpath'] . '" alt="" border=3 height=80 width=160></img></td>' . "\r\n\t\t\t\t\t\t\t\t" . '<td>' . $row['title'] . '<br>' . $row['createdon'] . '</td>' . "\r\n\t\t\t\t\t\t\t\t" . '<td>' . $row['type'] . '</td>' . "\r\n\t\t\t\t\t\t\t\t" . '<td title="' . $row['thumbpath'] . '">Mouse over to show</td>' . "\r\n\t\t\t\t\t\t\t\t" . '<td>' . $row['position'] . '</td>' . "\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t" . '<td><a class="btn btn-success btn-icon" href="./ads_update.php?update=' . $row['id'] . '"><i class="fas fa-edit"></i></a></td>' . "\r\n\r\n\t\t\t\t\t\t\t\t" . '<td><a class="btn btn-danger btn-icon" href="./ads.php?delete=' . $row['id'] . '"><i class="fas fa-trash"></i></a></td>' . "\r\n\r\n\r\n\t\t\t\t\t\t\t\t" . '</tr>' . "\r\n\t\t\t\t\t\t\t" . '</tbody>' . "\r\n\t\t\t\t\t\t\t" . "\n";
}

echo ' ' . "\t\t\t\t\t\t" . '</table>' . "\r\n\t\t\t\t\t\t" . '</div>' . "\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\r\n" . '    <br><br><br>';
include 'includes/footer.php';
require 'includes/brbox.php';
echo '      </body>' . "\n";

?>