<?php
$db = new SQLite3('./api/appsnscripts_smart.db');
$tsn = date('Y-m-d h:i:s');
$message = '<div class="alert alert-primary" id="flash-msg"><h4><i class="icon fa fa-check"></i>Notification Updated!</h4></div>';
$mess = '<div class="alert alert-primary" id="flash-msg"><h4><i class="icon fa fa-check"></i>Notification Deleted!</h4></div>';
$res = $db->query('SELECT * ' . "\r\n\t\t\t\t" . '  FROM notifications ' . "\r\n\t\t\t\t" . '  WHERE id=\'' . $_GET['update'] . '\'');

while ($row = $res->fetchArray()) {
	$id = $row['id'];
	$a = $row['Title'];
	$b = $row['Description'];
	$c = $row['CreateDate'];
}

if (isset($_POST['submit'])) {
	$db->exec('UPDATE notifications SET Title=\'' . $_POST['a'] . '\',' . "\r\n\t\t\t\t\t\t\t" . '  Description=\'' . $_POST['b'] . '\',' . "\r\n\t\t\t\t\t\t\t" . '  CreateDate=\'' . $tsn . '\'' . "\r\n\t\t\t\t\t\t" . '  WHERE ' . "\r\n\t\t\t\t\t\t\t" . '  id=\'' . $_POST['id'] . '\'');
	header('Location: notifications.php?m=' . $message);
}

include 'includes/header.php';
echo ' <!-- Begin Page Content -->' . "\n";
echo '        <div class="container-fluid">' . "\n";
echo "\n";

if (isset($_GET['m'])) {
	echo $_GET['m'];
}

echo '          <!-- Page Heading -->' . "\n";
echo '          <h1 class="h3 mb-1 text-gray-800"> Notifications Manager</h1>' . "\n";
echo "\n";
echo '              <!-- Custom codes -->' . "\n";
echo '                <div class="card border-left-primary shadow h-100 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="fa fa-android"></i> Edit Notification</h6>' . "\n";
echo '                </div>' . "\n";
echo '                <div class="card-body">' . "\n";
echo '                        <form method="post">' . "\n";
echo '                        <div class="form control">' . "\n";
echo '                                    <label class="control-label " for="a"><strong>' . "\n";
echo '                                        Title</strong>' . "\n";
echo '                                    </label>' . "\n";
echo '                                    <div class="input-group">' . "\n";
echo '                                        <input class="form-control text-primary" id="a" name="a"  value="' . $a . '" type="text"/>' . "\r\n" . '<input class="hidden" id="id" name="id"  value="' . $id . '" type="text"/>' . "\n";
echo '                                    </div></br>' . "\n";
echo '                                    ' . "\n";
echo '                                <div class="form-group ">' . "\n";
echo '                                    <label class="control-label " for="b">' . "\n";
echo '                                        <strong>Description</strong>' . "\n";
echo '                                    </label>' . "\n";
echo '                                    <div class="input-group">' . "\n";
echo '                                        <input type="text" class="form-control text-primary" name="b"  id="b" value="' . $b . '"> ' . "\n";
echo '                                    </div>' . "\n";
echo '                                 </div>' . "\n";
echo '                                <div class="form-group">' . "\n";
echo '                                    <div>' . "\n";
echo '                                        <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 '                                    </div>' . "\n";
echo "\n";
echo '                                </div>' . "\n";
echo '                            </form>' . "\n";
echo '                </div>' . "\n";
echo '              </div>' . "\n";
echo '            </div>';
include 'includes/footer.php';
require 'includes/appsnscripts.php';
echo '</body>' . "\n";

?>