<?php 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$db = new SQLite3('./api/.ltq_db.db');

$db->exec("CREATE TABLE IF NOT EXISTS notifications(id INTEGER PRIMARY KEY NOT NULL, title VARCHAR(25), description VARCHAR(25), backdrop VARCHAR(50), reference VARCHAR(50))");
//$db->exec("INSERT INTO notifications(title, description , backdrop, reference ) VALUES('test', 'hello world', 'img.jpg', 'url to point to')");
$res = $db->query('SELECT * FROM notifications');

if(isset($_GET['delete'])){
$db->exec("DELETE FROM notifications WHERE id=".$_GET['delete']);
$db->close();
header("Location: notifications.php");

}

include ('header.php');
?>


<div class="main-panel">
      <!-- Navbar -->

    <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">
                <div class="modal-header">
                    <h2>Confirm</h2>
                </div>
                <div class="modal-body">
                    Do you really want to delete?
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <a class="btn btn-danger btn-ok">Delete</a>
                </div>
            </div>
        </div>
    </div>


<div id="main">
   <br><h2>&nbsp;&nbsp;Notifications</h2>
   &nbsp;&nbsp;&nbsp;&nbsp;<a id="button"  href="./notifications_create.php" class="btn btn-warning">Create</a><br>
     </div>
      <div class="card-body">
        <div class="table-responsive">
          <table class="table">
            <thead class=" text-primary">
                <tr>
                  <th>Id</th>
                  <th>title</th>
                  <th>Description</th>
                  <th>Banner</th>
				  <th>reference url</th>
				  <th>Edit</th>
                  <th>Delete</th>
                </tr>
              </thead>
			  <?php while ($row = $res->fetchArray()) {?>
              <tbody class=" text-dark">
                <tr>
                  <td><?=$row['id'] ?></td>
                  <td><?=$row['title'] ?></td>
                  <td><?=$row['description'] ?></td>
                  <td><img src="<?=$row['backdrop'] ?>" alt="" border=3 height=80 width=120></img></td>
                  <td><?=$row['reference'] ?></td>
				  <td><a href="./notifications_update.php?update=<?=$row['id'] ?>"><i class="fa fa-pencil-square-o" style="font-size:24px;color:blue"></i></a></td>
                  <td><a href="#" data-href="./notifications.php?delete=<?=$row['id'] ?>" data-toggle="modal" data-target="#confirm-delete"><i class="fa fa-trash-o" style="font-size:24px;color:red"></i></a></td>
                </tr>
              </tbody>
			  <?php }?>
            </table>
          </div>
		</div>

</div>
    <br><br><br>
<?php include ('footer.php');?>
    <script>
$('#confirm-delete').on('show.bs.modal', function(e) {
    $(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
});
</script>
</body>

</html>