<?php 
include ('includes/header.php');

//table name
$table_name = "ads";

//current file var
$base_file = basename($_SERVER["SCRIPT_NAME"]);

//create if not
$adb->exec("CREATE TABLE IF NOT EXISTS {$table_name}(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, title VARCHAR(100), url TEXT)");

//table call
$res = $adb->query("SELECT * FROM {$table_name}");

//update call
@$resU = $adb->query("SELECT * FROM {$table_name} WHERE id='{$_GET['update']}'");
@$rowU=$resU->fetchArray();
if(isset($_POST['submitU'])){
    $adb->exec("UPDATE {$table_name} SET title='{$_POST['title']}',url='{$_POST['url']}' WHERE  id='{$_POST['id']}'");
    $adb->close();
    //header("Location: {$base_file}");
    echo "<script>window.location.href='mRTXBGads.php';</script>";
    exit;
}

//submit new
if (isset($_POST['submit'])){
    $adb->exec("INSERT INTO {$table_name}(title, url) VALUES('{$_POST['title']}', '{$_POST['url']}')");
    //header("Location: {$base_file}");
    echo "<script>window.location.href='mRTXBGads.php';</script>";
    exit;
}

//delete row
if(isset($_GET['delete'])){
    $adb->exec("DELETE FROM {$table_name} WHERE id={$_GET['delete']}");
    //header("Location: {$base_file}");
    echo "<script>window.location.href='mRTXBGads.php';</script>";
    exit;
}

?>
<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content" style="background-color: black;">
            <div class="modal-header">
                <h2 style="color: white;">Confirm</h2>
            </div>
            <div class="modal-body" style="color: white;">
                Do you really want to delete?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>
                <a style="color: white;" class="btn btn-danger btn-ok">Delete</a>
            </div>
        </div>
    </div>
</div>

<!-- Adicione o formulário de criação aqui -->
<div class="col-md-8 mx-auto">
    <center>
        <h1 class="colorboard">New Advertisement</h1>
    </center>
    <div class="card bg-primary text-white">
        <div class="card-header">
            <center>
                <h2><i class="fa fa-eye"></i> Add new advertisement</h2>
            </center>
        </div>
        <div class="card-body">
            <form method="post">
                <div class="form-group">
                    <label for="title">Title</label>
                    <input class="form-control" type="text" name="title" id="title">
                </div>
                <div class="form-group">
                    <label for="url">Ad Url ( GIF, PNG, JPG, SVG )</label>
                    <input class="form-control" type="text" name="url" id="url">
                </div>  
                <div class="col-12">
                    <button type="submit" name="submit" class="btn btn-info">Submit</button>
                </div>
            </form>
        </
