<?php

if(isset($_POST['btnLogout']))
{
	session_start();
	session_destroy();
} 


include('rights.php');
include('config.php');
include('includes/_admin_top.php');
?>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.15/datatables.min.css">


<div class="flex flex-col md:flex-row">

        <?php include('includes/_admin_menus.php') ?>

        <div class="main-content flex-1 bg-gray-100 md:mt-2 pb-24 md:pb-5">
            <div class="bg-blue-800 p-2 shadow text-xl text-white">
                <div class="d-table">
                	<div class="pull-left">
                	<h3 class="font-bold pl-2">Sticker Packs</h3>
                </div>
                <div class="pull-right">
                	<a href="newpack.php" style="float:right;" class="btn btn-success"><i class="fa fa-plus-square" aria-hidden="true"></i> Create New</a>
                </div>
                </div>
            </div>
            <div class="flex flex-wrap" id="stickerpackstable">
                Loading...
            </div>
        </div>
</div>

<?php  include('includes/_admin_bottom.php')?>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.15/datatables.min.js"></script>

<script id="table-template" type="text/x-handlebars-template"> 

	<table class="table table-bordered" id="StickerPackTable">
		<thead>
			<th>
				Id
			</th>
			<th>
				Name
			</th>
			<th>
			
			</th>
			<th>
			
			</th>
		</thead>
		<tbody>
			{{#sticker_packs}}
				<tr>
					<td>
						{{identifier}}
					</td>
					<td>
						{{name}}
					</td>
					<td>
						<img src="apis/userdata/{{identifier}}_small/{{tray_image_file}}">
					</td>
					<td>
						<div class="btn-group btn-group-sm" role="group" aria-label="Basic example">
						  <a href="viewpack.php?id={{identifier}}" class="btn btn-secondary"> <i class="fa fa-eye"></i> </a>
						  <a href="editpack.php?id={{identifier}}" class="btn btn-primary"> <i class="fa fa-edit"></i> </a>
						  <a href="viewpack.php?id={{identifier}}&remove=true" class="btn btn-danger""> <i class="fa fa-trash"></i> </a>
						</div>
					</td>
				</tr>
			{{/sticker_packs}}
		</tbody>
	</table>

</script>

<script>
	$(document).ready(function(){
		_readData();
		
	});
	
	function _readData()
	{
		$.ajax({
			url:'apis/alldata.php',
			success:function(data){
				var _stickerData=JSON.parse(data);
				var source = $("#table-template").html(); 
				var template = Handlebars.compile(source); 
				$('#stickerpackstable').html(template(_stickerData));
				$('#StickerPackTable').DataTable();
			}
		});
		
	}

	function RemovePack(id)
	{
		// alert(id);
		// window.location.href="viewpack.php?id="
	}

</script>

