<?php
$jsondata_admin1 = file_get_contents('./includes/boxbr.json');
$data_admin1 = json_decode($jsondata_admin1, true);
$json_admin1 = $data_admin1['info'];
$col_admin1 = $json_admin1['zz'];

if ($col_admin1 == '0') {
	header('Location: dns.php');
	exit();
}

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$message = '<div class="alert alert-primary" id="flash-msg"><h4><i class="icon fa fa-check"></i>Items Updated!</h4></div>';
$db = new SQLite3('./a/.boxbrdb.db');
$db->exec('CREATE TABLE IF NOT EXISTS sport(id INTEGER PRIMARY KEY NOT NULL, title VARCHAR(25), url VARCHAR(100))');
$rows = $db->query('SELECT COUNT(*) as count FROM sport');
$row = $rows->fetchArray();
$numRows = $row['count'];

if ($numRows == 0) {
	$db->exec('INSERT INTO sport(id, title, url) VALUES(\'1\', \'Default\', \'https://www.tvsportguide.com/widget/5cc316f797659/?heading=Events&border_color=custom&autoscroll=0&custom_colors=\')');
}

$res = $db->query('SELECT * ' . "\r\n\t\t\t\t" . '  FROM sport ' . "\r\n\t\t\t\t" . '  WHERE id=\'1\'');
$row = $res->fetchArray();
$id = $row['id'];
$title = $row['title'];
$url = $row['url'];

if (isset($_POST['submit'])) {
	$db->exec('UPDATE sport SET' . "\t" . 'title=\'' . $_POST['title'] . '\', ' . "\r\n\t\t\t\t\t\t\t\t" . 'url=\'' . $_POST['url'] . '\'' . "\r\n\t\t\t\t\t\t" . '  WHERE ' . "\r\n\t\t\t\t\t\t\t\t" . 'id=\'1\' ');
	header('Location: sports.php');
}

include 'includes/header.php';
echo '       <div class="container-fluid">' . "\n";
echo "\n";
echo '          <!-- Page Heading -->' . "\n";
echo '          <h1 class="h3 mb-1 text-gray-800">Sport Guide</h1>' . "\n";
echo '         ' . "\n";
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 border-left-primary shadow card shadow mb-4">' . "\n";
echo '                <div class="card-header py-3">' . "\n";
echo '                <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-futbol"></i> Edit Sport Guide</h6>' . "\n";
echo '                </div>' . "\n";
echo '                  <div class="card-body">' . "\n";
echo '                    <form method="post">' . "\n";
echo '                        <div class="form-group">' . "\n";
echo '                          <label class="control-label"for="title">' . "\n";
echo '                              <strong>Title</strong>' . "\n";
echo '                            </label>' . "\n";
echo '                          <input type="text" class="form-control" name="title" value="' . $title . '">' . "\n";
echo '                        </div>' . "\n";
echo '                            <div class="form-group ">' . "\n";
echo '                            <label class="control-label " for="url">' . "\n";
echo '                            <strong>URL</strong>' . "\n";
echo '                            </label>' . "\n";
echo '                            <div class="input-group">' . "\n";
echo '                            <input class="form-control" id="url" name="url" value="' . $url . '">' . "\n";
echo '                        </div>' . "\n";
echo '                      </div>' . "\n";
echo '                      <div class="form-group">' . "\n";
echo "\t\t\t\t\t" . '<br><button class="btn btn-success btn-icon-split" name="submit" type="submit">' . "\n";
echo '                        <span class="icon text-white-50"><i class="fas fa-check"></i></span><span class="text">Submit</span>' . "\n";
echo '                        </button>' . "\n";
echo "\t\t\t\t" . '</form>' . "\n";
echo "\t\t\t\t" . '</div>' . "\n";
echo '              </div>' . "\n";
echo '            </div>' . "\n";
echo '          </div>' . "\n";
echo '      </div>' . "\n";
echo "\t" . ' </div>' . "\n";
echo '    <br><br><br>' . "\n";
include 'includes/footer.php';
echo '</body>' . "\n";
echo ' <script> ' . "\n";
echo '$(document).ready(function () {' . "\n";
echo '    $(\'#flash-msg\').delay(3000).fadeOut(\'slow\');' . "\n";
echo '});' . "\n";
echo '  </script>' . "\n";
echo "\n";
echo '</html>';

?>