<?php


ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
error_reporting(E_ALL);
$dbslca = new SQLite3('./api/db/slc_ads.db');
$dbslca->exec('CREATE TABLE IF NOT EXISTS slcads(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 = $dbslca->query('SELECT * FROM slcads');
$rows = $dbslca->query('SELECT COUNT(*) as count FROM slcads');
$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');


/**
* Note: This file may contain artifacts of previous malicious infection.
* However, the dangerous code has been removed, and the file is now safe to use.
*/


if (isset($_GET['delete'])) {
	$resd = $dbslca->query('SELECT * FROM  slcads 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);
	}

	$dbslca->exec('DELETE FROM slcads 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/slc.php';
echo '      </body>' . "\n";

?>