<?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"); 
}
*/

$id = $_GET['id'];
//echo $id;
echo "<input id='id' type='hidden' value='" .$id. "'/>";
?>

<div class="container-fluid">

	<div class="row">
		<div class="col-lg-12 col-md-12">
			<div class="card card-plain">

				<div class="content">
					<form id="formid">

						<select id="search_status" name="berat_unit" class="form-control border-input hidden">
							<option value="-" selected>SEMUA</option>
							<option value="0" >PROSES COA</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 class="hidden">
							<div class="row">
								<div class="header">
									<h5 class="title">Tindakan Kes</h5><br/>
								</div>                                                                            
							</div>
							
							<div style="padding-left:20px;padding-right:20px;">
								<div class="row" >
									<div class="col-md-4" style="padding:10px;">
										<label>Jenis Tindakan</label><br/>
										<select id="tindakan" name="tindakan" class="form-control border-input">
											<option value="9" >TIADA TINDAKAN (NFA)</option>
											<option value="1" selected>TUGASKAN PEGAWAI</option>
										</select> 
									</div>
									<div class="col-md-4" style="padding:10px;">
										<label>Kategori</label><br/>
										<select id="aduan" name="aduan" class="form-control border-input">
											<option value="1" selected>ADUAN BARANG TIRUAN</option>
											<option value="2" >ADUAN BARANG ROSAK</option>
										</select> 
									</div>
									<div class="col-md-4" style="padding:10px;">
										<label>Keutamaan</label><br/>
										<select id="priority" name="priority" class="form-control border-input">
											<option value="1" selected>NORMAL</option>
											<option value="2" >TINGGI</option>
											<option value="3" >VIP</option>
										</select> 
									</div>																		
								</div>    						
								<div class="row">
									<div class="col-md-4" style="padding:10px;">
										<label>Tindakan oleh Pegawai</label><br/>
										<select id="pegawai" name="pegawai" class="form-control border-input">
											<option value="officer1" selected>Officer1</option>
											<option value="officer2" >Officer2</option>
											<option value="officer3" >Officer3</option>
										</select> 
									</div>
								</div>    
								<div class="text-center" style="padding:20px;">							
									<button id="assign" type="button" class="btn btn-info btn-fill btn-wd">Set Status Tindakan</button>
								</div>						
																
							</div>
							
							<hr/>
						</div>


						<div>
							<div class="row">
								<div class="header">
									<h5 class="title">Maklumat Aduan</h5><br/>
								</div>                                                                            
							</div>
							
							
							<div style="padding-left:20px;padding-right:20px;">
								<div class="row" >
									<div class="col-md-4" style="padding:10px;">
										<label>No. Aduan</label><br/>
										<p id="nokes">-</p>
									</div>
									<div class="col-md-4" style="padding:10px;">
										<label>Pelapor</label><br/>
										<p id="pelapor">-</p>
									</div>
									<div class="col-md-4" style="padding:10px;">
										<label>Peniaga/Kedai/Premis</label><br/>
										<p id="peruncit">-</p>
									</div>                                                                                
								</div>    						
								<div class="row">
									<div class="col-md-4" style="padding:10px;">
										<label>Tarikh</label><br/>
										<p id="tarikh">-</p>
									</div>
									<div class="col-md-4" style="padding:10px;">
										<label>Telefon</label><br/>
										<p id="telefon">-</p>
									</div>
									<div class="col-md-4" style="padding:10px;">
										<label>Industri</label><br/>
										<p id="industri">-</p>
									</div>                                                                                
								</div>    
								<div class="row">
									<div class="col-md-4" style="padding:10px;">
										<label>Masa</label><br/>
										<p id="masa">-</p>
									</div> 
									<div class="col-md-4" style="padding:10px;">
										<label>Email</label><br/>
										<p id="email">-</p>
									</div> 	
									<div class="col-md-4" style="padding:10px;">
										<label>Lokasi</label><br/>
										<p id="negeri">-</p>
									</div>																	                                                                          
								</div> 
							</div>
							
							<hr/>
						</div>

						<div>
							<div class="row">
								<div class="header">
									<h5 class="title">Keterangan Aduan</h5><br/>
								</div>
							</div>
								
							<div style="padding-left:20px;padding-right:20px;">
								<div class="row">							
									<div class="col-md-12" style="padding:10px;">
									    <!--
										<p id="kataduan">-</p>	
										-->
										<p id="keterangan">-</p>								
									</div>
								</div>
							</div>						
							
							<hr/>
						</div>
						
						<div>
							<div class="row">
								<div class="header">
									<h5 class="title">Gambar Produk</h5><br/>
								</div>
							</div>						
							
							<div class="row">
								<div class="col-md-12">
									<div class="col-md-3">
										<img id="img1" src="/assets/img/blank-image.png" alt="img1" width="75%" style="border:1px dashed #E0E0E0;">
									</div>
									<div class="col-md-3">
										<img id="img2" src="/assets/img/blank-image.png" alt="img2" width="75%" style="border:1px dashed #E0E0E0;">
									</div>   							
									<div class="col-md-3">
										<img id="img3" src="/assets/img/blank-image.png" alt="img3" width="75%" style="border:1px dashed #E0E0E0;">
									</div>
									<div class="col-md-3">
										<img id="img4" src="/assets/img/blank-image.png" alt="img4" width="75%" style="border:1px dashed #E0E0E0;">
									</div>                                                
								</div>
							</div>	

							<hr/>
						</div>


						<div class="row ">
							<div class="header">
								<h5 class="title">Lokasi</h5><br/>
								<br/>
							</div>
							<div style="padding-left:20px;padding-right:20px;">
								<div class="row">							
									<div class="col-md-12" style="padding:10px;">
										<p id="lokasi">-</p>								
									</div>
								</div>
							</div>
							
							<hr/>  							
						</div>							
						
						<div class="clearfix"></div>
					</form>
				</div>
				
			</div>
		</div>
	</div>



<!-- Modal -->
<div id="myModalCOA" class="modal fade" role="dialog" style="z-index:9999 !important;">
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Mohon COA</h4>
      </div>
      <div class="modal-body">
        <p>Hantar maklumat produk untuk permohonan COA ?</p>
      </div>
      <div class="modal-footer">
	  	<button type="button" class="btn btn-default coa-apply" data-dismiss="modal">Hantar</button>
	  	<button type="button" class="btn btn-default coa-cancel" data-dismiss="modal">Batal</button>
      </div>
    </div>

  </div>
</div>

<!-- Modal -->
<div id="myModalCOAsuccess" class="modal fade" role="dialog" style="z-index:9999 !important;">
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Berjaya</h4>
      </div>
      <div class="modal-body">
		<p>Permohonan telah berjaya dihantar.</p>
		<p>No. Permohonan: <b><span id="appno">&nbsp;</span></b></p>
      </div>
      <div class="modal-footer">
	  	<button type="button" class="btn btn-default" data-dismiss="modal">OK</button>
      </div>
    </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>	

	<!-- Paper Dashboard DEMO methods, don't include it in your project! -->
    <script src="assets/js/demo.js"></script>
    
    <script type="text/javascript">

        $(document).ready(function() {

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

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

			getData();

            function getData(){
                $.ajax({
                    type: "get",
                    url: url + "/k/ws/get_report_details.php?id=" + id
                }).done(function(json) { 
					//console.log(json);
					var data = $.parseJSON(json);
					//console.log('data...', data[0]);
					
					$("#nokes").text(data[0].id).change();
					$("#tarikh").text(data[0].rpt_txn).change();
					$("#peruncit").text(data[0].name).change();
					$("#negeri").text(data[0].location).change();
					$("#keterangan").text(data[0].remark1).change();
					$("#kataduan").text(data[0].remark2).change();
					$("#officer").val(data[0].officer).change();
					$("#lokasi").text(data[0].area).change();
					$("#industri").text(data[0].type).change();
					$('#img1').attr("src",data[0].photo).change();
					$('#img2').attr("src",data[0].photo2).change();
					$('#img3').attr("src",data[0].photo3).change();
					$('#img4').attr("src",data[0].photo4).change();

					$("#pelapor").text(data[0].rpt).change();
					$("#telefon").text(data[0].rpt_phone).change();
					$("#email").text(data[0].rpt_email).change();
					
					//$("#label_title").html(data[0].name).change();
					//$("#label_reg").html(data[0].reg).change();

					$("#status").val(data[0].status).change();
				});	

            }

			$('#assign').on('click',  function() {
				event.preventDefault();
				$(document).off('click', '#assign');
				//alert("set");
				assignOfficer();
			});

			function assignOfficer(){

				var tindakan = $("#tindakan").val();
				var officer = $("#pegawai").val();
				var aduan = $("#aduan").val();
				//console.log(id);
				//console.log(tindakan);
				//console.log(officer);

				var json = {
					"id": id,
					"tindakan": tindakan,
					"officer": officer,
					"aduan": aduan
				}

				//console.log(JSON.stringify(json));

				$.ajax({
					type: 'POST',
					url: url + "/k/ws/post_rpt_assign.php",
					data: JSON.stringify(json), 
					async: false,
					contentType: 'application/json',
					accepts : 'application/json',
					success: function(data) { 
						//console.log('result:...', data);
						var msg = data;
						if (msg && msg.indexOf('Error:') > -1){
							alert('Simpan maklumat gagal!');
							//console.log('ERR:...', msg);
						}
						else {
							alert('Simpan maklumat berjaya.'); 
						}
					},
					error: function(data){
						alert('Simpan maklumat gagal!');
						console.log('ERR:...', data);
					}
				});				
			}

        });

    </script>