<?php if($lihat){?>
<?php
$q=mysqli_query($connect, "select * from produk where ID_user='$_SESSION[id_user]' and ID ='$lihat'") or die(mysqli_error($connect));
$b=mysqli_fetch_array($q);
?>
<div class="row clearfix">
  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    <div class="card">
      <div class="header">
        <h2>VIEW DATA STORE</h2>
      </div>
      <div class="body">
        <form>
		<div class="form-group">
            <label>Category</label>
            <div class="form-line">
              <?php echo ucwords($b['jenis']);?>
            </div>
          </div>
		  <div class="form-group">
            <label>Barcode</label>
            <div class="form-line">
              <?php echo $b['barcode'];?>
            </div>
          </div>
          <div class="form-group">
            <label>Product Name</label>
            <div class="form-line">
              <?php echo $b['nama_produk'];?>
            </div>
          </div>
		  <div class="form-group">
            <label>Buying Price</label>
            <div class="form-line">
              <?php echo number_format($b['harga_beli'],0,',','.');?>
            </div>
          </div>
		  <div class="form-group">
            <label>Selling Price</label>
            <div class="form-line">
              <?php echo number_format($b['harga_jual'],0,',','.');?>
            </div>
          </div>
		  <div class="form-group">
            <label>Product Picture</label>
            <div class="form-line">
				<img src="assets/images/placeholder.png" data-src="<?php echo getConfig($connect, 'base_url');?>image.php?t=produk&id=<?php echo $lihat;?>&s=90" style="height:100px;" class="center">
              </div>
          </div>
        <div class="form-group">
          <button type="button" class="btn btn-sm bg-blue-grey waves-effect back">Back</button>
        </div>
      </form>
      </div>
    </div>
  </div>
</div>
<?php }elseif($edit){?>
<?php
$q=mysqli_query($connect, "select * from produk where ID_user='$_SESSION[id_user]' and ID ='$edit'") or die(mysqli_error($connect));
$b=mysqli_fetch_array($q);
?>
<div class="row clearfix">
  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    <div class="card">
      <div class="header">
        <h2>EDIT PRODUCT</h2>
      </div>
      <div class="body">
        <form class="form_ajax">
        <input type="hidden" name="p" value="<?php echo $page;?>">
        <input type="hidden" name="t" value="update">
        <input type="hidden" name="token" value="<?php echo getToken();?>">
        <input type="hidden" name="id" value="<?php echo $b['ID'];?>">
		<div class="form-group">
            <label>Category</label>
            <div class="form-line">
              <select name="jenis_produk" class="form-control" required>
			  	<option value="umum" <?php echo ($b['jenis']=='umum')?'selected':'';?>>General</option>
				<option value="tiket" <?php echo ($b['jenis']=='tiket')?'selected':'';?>>Ticket</option>
			  </select>
            </div>
          </div>
		  <div class="form-group">
            <label>Barcode</label>
            <div class="form-line">
              <input type="text" name="barcode" value="<?php echo $b['barcode'];?>" class="form-control">
            </div>
          </div>
          <div class="form-group">
            <label>Product Name</label>
            <div class="form-line">
              <input type="text" name="nama_produk" class="form-control" value="<?php echo $b['nama_produk'];?>" required>
            </div>
          </div>
		  <div class="form-group">
            <label>Buying Price</label>
            <div class="form-line">
              <input type="text" name="harga_beli" class="form-control formatNumber" value="<?php echo $b['harga_beli'];?>">
            </div>
          </div>
		  <div class="form-group">
            <label>Selling Price</label>
            <div class="form-line">
              <input type="text" name="harga_jual" class="form-control formatNumber" required value="<?php echo $b['harga_jual'];?>">
            </div>
          </div>
		  <div class="form-group">
            <label>Product Picture</label>
            <div class="form-line">
				<input name="gambar_produk" id="inputFile99" accept="image/*" onChange="validateImage(this);" type="file"/>
                <?php if($b['gambar_produk']){?>
                <p align="center" id="img-view99" class="img-view" style="text-align:center;"><img src="assets/images/placeholder.png" data-src="<?php echo getConfig($connect, 'base_url');?>image.php?t=produk&id=<?php echo $edit;?>&s=90" style="height:100px;" class="center">
                  <button type="button" class="btn bg-red waves-effect no-padding btn-xs" onClick="$('#img-view99').remove();$('#inputFile99').val('');"><i class="material-icons">delete</i></button>
                  <input type="hidden" name="old_img" value="1">
                </p>
                <?php } ?>
              </div>
          </div>
        <div class="form-group">
          <button type="submit" class="btn btn-sm bg-blue-grey waves-effect">Submit</button>&nbsp;
          <button type="reset" class="btn btn-sm bg-red waves-effect back">Back</button>
        <div class="preloader pl-size-xs pull-right" style="display:none;" id="loading">
            <div class="spinner-layer pl-blue-grey">
              <div class="circle-clipper left">
                <div class="circle"></div>
              </div>
              <div class="circle-clipper right">
                <div class="circle"></div>
              </div>
            </div>
          </div>
        </div>
      </form>
      </div>
    </div>
  </div>
</div>
<?php }else{?>
<div class="row clearfix">
  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    <div class="card">
      <div class="header">
        <h2>DATA PRODUCT</h2>
      </div>
      <div class="body">
      	<button type="button" data-toggle="modal" data-target="#defaultModal" data-controls-modal="#defaultModal" data-backdrop="static" class="btn bg-blue-grey waves-effect"><i class="material-icons">add</i><span style="top:-4px !important;">ENTRY DATA</span></button>
        <table class="table table-bordered table-striped table-hover dataTable js-exportable">
            <thead>
              <tr>
                <th>#</th>
                <th>Picture</th>
				<th>Category</th>
				<th>Name</th>
                <th>Barcode</th>
				<th>Buying Price</th>
				<th>Selling Price</th>
                <th>Action</th>
              </tr>
            </thead>
            <tbody>
            </tbody>
          </table>
      </div>
    </div>
  </div>
</div>
<div class="modal" id="defaultModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title" id="defaultModalLabel">Add Product</h4>
      </div>
      <form class="form_ajax">
        <input type="hidden" name="p" value="<?php echo $page;?>">
        <input type="hidden" name="t" value="create">
        <input type="hidden" name="token" value="<?php echo getToken();?>">
        <div class="modal-body">
		  <div class="form-group">
            <label>Category</label>
            <div class="form-line">
              <select name="jenis_produk" class="form-control" required>
			  	<option value="umum">General</option>
				<option value="tiket">Ticket</option>
			  </select>
            </div>
          </div>
		  <div class="form-group">
            <label>Barcode</label>
            <div class="form-line">
              <input type="text" name="barcode" class="form-control">
            </div>
          </div>
          <div class="form-group">
            <label>Product Name</label>
            <div class="form-line">
              <input type="text" name="nama_produk" class="form-control" required>
            </div>
          </div>
		  <div class="form-group">
            <label>Buying Price</label>
            <div class="form-line">
              <input type="text" name="harga_beli" class="form-control formatNumber">
            </div>
          </div>
		  <div class="form-group">
            <label>Selling Price</label>
            <div class="form-line">
              <input type="text" name="harga_jual" class="form-control formatNumber" required>
            </div>
          </div>
		   <div class="form-group">
            <label>Product Picture</label>
            <div class="form-line">
               <input name="gambar_produk" id="inputFile" accept="image/*" onChange="validateImage(this);" type="file"/>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <div class="preloader pl-size-xs pull-left" style="display:none" id="loading">
            <div class="spinner-layer pl-blue-grey">
              <div class="circle-clipper left">
                <div class="circle"></div>
              </div>
              <div class="circle-clipper right">
                <div class="circle"></div>
              </div>
            </div>
          </div>
          <button type="submit" class="btn btn-sm bg-blue-grey waves-effect">SUBMIT</button>
          <button type="reset" class="btn btn-sm bg-blue-grey waves-effect" data-dismiss="modal">CANCEL</button>
        </div>
      </form>
    </div>
  </div>
</div>
<?php } ?>
<script type="text/javascript">
$( document ).ready(function() {
$('table').DataTable({
		 "bSort":false,
		 "bProcessing": true,
         "serverSide": true,
         "ajax":{
            url :"<?php echo getConfig($connect, 'base_url');?>processData.php",
            type: "post",
			data:{p:'<?php echo $page;?>'},
            error: function(a,e,t){
				swal({
					title: "Something Wrong!",
					text: formatErrorMessage(a,e),
					type: "error",
					showCancelButton: !1,
					closeOnConfirm: !0
				}, function() {
					if(a.responseText){
						$("#hasil").html(a.responseText);
					}else{
						$("#hasil").html("Error : "+formatErrorMessage(a,e));
					}
				});
              	$("table").css("display","none");
            },
			complete: function(a,e,t){
				noClick2();
				initAjax(true);
			}
          },
		 responsive: !1,
		 width:'100%',
		 "autoWidth": false,
		 columnDefs: [
		 	{"targets": 0,"className": "text-center"},
			{"targets": 1,"className": "text-center"},
			{"targets": 5,"className": "text-right"},
			{"targets": 6,"className": "text-right"},
			{"targets": 7,"className": "text-center"}
			 ]
        }); 
});
</script>