<?php
session_start();
/*
try {
    if (isset($_COOKIE["session"])) { 
        //echo 'Cookie is active!';
        $lifetime=60*60;
        setcookie("session", "1", time() + $lifetime, "/");
    } else{ 
        //echo 'Cookie is NOT active!';
        header("Location: /login.php"); 
    }
    $auth = $_SESSION["auth"];
    if (!$auth){
        header("Location: /login.php"); 
    }
} catch(Exception $e){
    header("Location: /login.php"); 
}
*/
?>

<div class="container-fluid">
	<div class="row">

		<div class="col-md-12">
			<div class="card card-plain">
			
				<div class="hidden">
					<form id="formid">
						<div class="row">
							<div class="col-md-4" style="padding:10px;">
								<label>Teks Carian</label>
								<input id="search_text" name="search_text" type="text" class="form-control border-input" placeholder="Teks carian" value="" >
							</div>
							<div class="col-md-4" style="padding:10px;">
								<label>Status COA</label>
								<select id="search_status" name="berat_unit" class="form-control border-input">
									<option value="0" selected>SEMUA</option>
									<option value="1" >AKTIF</option>
									<option value="2" >SEMAK SEMULA</option>
									<option value="3" >GAGAL</option>
									<option value="4" >COA LUPUT</option>
									<option value="5" >PENGGANTUNGAN</option>
								</select>  
							</div>
						</div>  
						<div class="row">
							<div class="col-md-8" style="padding:10px;text-align:center;">
								<button id="search" type="button" class="btn btn-info btn-fill btn-wd">Cari Produk</button>
							</div>
						</div>
					</form>
					<hr/>
				</div>
			
				<div class="header">
					<p class="category">Jumlah Rekod: <span id="totalrow">0</span></p>
				</div>
				<div class="content table-responsive table-full-width">
					<table id="listing" class="table table-hover">
						<thead style="background-color:#E0E0E0;">
							<th>#</th>
							<th><b>No. PO</b></th>
							<th><b>Tarikh PO</b></th>
							<th><b>Jenama</b></th>
							<th><b>Model/Produk/Tahun</b></th>
							<th><b>Kuantiti Pelekat</b></th>
							<th><b>Status Pelekat</b></th>
							<th>[Tindakan]</th>
						</thead>
						<tbody>
							<!-- jquery to fill -->
						</tbody>
					</table>
				</div>
				<hr/>
			</div>
		</div>

	</div>
</div>


<!--   Core JS Files   -->
<script src="/assets/js/jquery-1.10.2.js" type="text/javascript"></script>
<script src="/assets/js/bootstrap.min.js" type="text/javascript"></script>

<!--  Checkbox, Radio & Switch Plugins -->
<script src="/assets/js/bootstrap-checkbox-radio.js"></script>

<!--  Notifications Plugin    -->
<script src="/assets/js/bootstrap-notify.js"></script>

<!-- Paper Dashboard Core javascript and methods for Demo purpose -->
<script src="/assets/js/paper-dashboard.js"></script>

<script src="/assets/js/app.js"></script>


<script type="text/javascript">
$(document).ready(function() {

$.ajaxSetup({
	cache: false
});	


var id = $('#id').val();
//console.log('id...', id);
id = "M00001";

var url = "";
url = getBase();

getData();

function getData(){
	$.ajax({
		type: "get",
		url: url + "/m/ws/get_products.php?id=" + id
		}).done(function(json) { 
		//console.log(json);
		var data = $.parseJSON(json);
		console.log('list_produk:getdata...', data);
		
		if (data && data.length > 0) {
			$("#listing tbody").empty();

			var loop = 0;
			$.each(data, function(k, v) {

				var tr = "";
				loop++;
				tr = tr + "<tr>";
				tr = tr + "    <td>" +loop+ "</td>";
				tr = tr + "    <td>" +v.type+ "</td>";
				tr = tr + "    <td>" +""+ "</td>";
				tr = tr + "    <td>" +v.jenama+ "</td>";
				tr = tr + "    <td>" +v.model+" / "+v.produk+ " / " +v.prod_year+ "</td>";
				tr = tr + "    <td>" +""+ "</td>";
				tr = tr + "    <td>" +""+ "</td>";
				tr = tr + "    <td>";
				tr = tr + "        <span style='cursor:pointer;'><i class='ti-info-alt show-info' title='Papar Maklumat' data1='" +v.nfc+ "'></i>";
				tr = tr + "        <i class='ti-pencil' title='Kemaskini Maklumat'></i></span>";
				tr = tr + "    </td>";
				tr = tr + "</tr>";

				//console.log('tr...', tr);
				$("#listing tbody").append(tr);
			});

			$("#totalrow").html(loop).change();
		}                
	});	
}



$(document).on('click', '.show-info' , function() {
	event.preventDefault();
	$(document).off('click', '.show-info');
	var data1 = $(this).attr('data1');
	//console.log('data1:', data1);
	setPage(this, 'Info Produk', './info_produk.php?id='+data1);
});   


function setPage(li, title, page){
	$("#app-title").text(title.toUpperCase());
	$("#app-content").empty();
	try {
		$("#app-content").load(page, function(txt, sts, xhr) {
			//console.log("xhr", xhr);
			if (xhr && xhr.status === 200) {}
			else {
				//alert("Load Page Error: " + xhr.status + " ResponseText: " + xhr.responseText);
				$("#app-title").html("<h3><b>" + title.toUpperCase() + "</b> - Error: " + xhr.status + " | Page: " + xhr.statusText + " </h3>");
			}
		});
	} catch(err) {
		console.log("catchErr:", err);
	}
} 


});

</script>    