<?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 appstore(id INTEGER PRIMARY KEY NOT NULL, app_name VARCHAR(25), app_id VARCHAR(25), app_description VARCHAR(50), app_banner VARCHAR(25), app_install_url VARCHAR(75))");
//$db->exec("INSERT INTO appstore(app_name, app_id , app_description, app_banner , app_install_url) VALUES('testtest', 'test.test.test', 'app description', 'banner.jpg', 'http://app_install_url.com')");
$res = $db->query('SELECT * FROM appstore');

if(isset($_GET['delete'])){
$db->exec("DELETE FROM appstore WHERE id=".$_GET['delete']);
header("Location: appstore.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; Appstore</h2>
           &nbsp;&nbsp;&nbsp;&nbsp;<a id="button"  href="./appstore_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>APP Name</th>
                  <th>App ID (Package Name)</th>
                  <th>App Description</th>
                  <th>App Banner</th>
				  <th>App Install 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['app_name'] ?></td>
                  <td><?=$row['app_id'] ?></td>
                  <td><?=$row['app_description'] ?></td>
                  <td><img src="<?=$row['app_banner'] ?>" alt="" border=3 height=80 width=120></img></td>
                  <td><?=$row['app_install_url'] ?></td>
				  <td><a href="./appstore_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="./appstore.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>
    <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>