<?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>
					<form id="formid">
						<div class="row">
							<div class="header">
								<h5 class="title">Carian Produk</h5><br/>
							</div>                                                                            
						</div>
						<div class="row">
							<div class="col-md-4" style="padding:10px;">
								<label>No. SKU *</label>
								<input id="search_sku" name="search_sku" type="text" class="form-control border-input" placeholder="No. SKU" value="" >
							</div>
							<div class="col-md-4" style="padding:10px;">
								<label>No. COA</label>
								<input id="search_coa" name="search_coa" type="text" class="form-control border-input" placeholder="No. COA" 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 text-center">	
							<br/>
							<button id="search" type="button" class="btn btn-info btn-fill btn-wd">Carian</button>
						</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>Kategori</b></th>
							<th><b>No. SKU</b></th>
							<th><b>Jenama</b></th>
							<th><b>Model</b></th>
							<th><b>No. Sijil COA</b></th>
							<th><b>Status COA</b></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('data...', 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+  "</td>";
						tr = tr + "    <td>" +v.prod_year+ "</td>";
						tr = tr + "    <td>";
						tr = tr + "        <a href='show_prod.php?id=" +v.nfc+ "'>";
						tr = tr + "            <i class='ti-info-alt' title='Papar Maklumat'></i>&nbsp;&nbsp;&nbsp;";
						tr = tr + "        </a>";
						tr = tr + "        <a href='edit_prod.php?id=" +v.nfc+ "'>";
						tr = tr + "            <i class='ti-pencil' title='Kemaskini Maklumat'></i>&nbsp;&nbsp;&nbsp;";
						tr = tr + "        </a>";
						tr = tr + "    </td>";
						tr = tr + "</tr>";

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

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




				}                
			});	
		}


	});

</script>    