<?php if($lihat){?>
<?php
$q=mysqli_query($connect, "SELECT * FROM `users` where ID ='$lihat'") or die(mysqli_error($connect));
$b=mysqli_fetch_array($q);
$status=($b['user_status']=='1')?'<span class="label bg-blue">Aktif</span>':'<span class="label bg-red">Nonaktif</span>';
?>
<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 USER <?php echo $status;?></h2>
      </div>
      <div class="body">
        <form>
		  <div class="form-group">
            <label>Name</label>
            <div class="form-line">
              <?php echo $b['user_nama'];?>
            </div>
          </div>
		   <div class="form-group">
            <label>No. Hp</label>
            <div class="form-line">
              <?php echo $b['user_hp'];?>
            </div>
          </div>
		  <div class="form-group">
            <label>Email</label>
            <div class="form-line">
              <?php echo $b['user_email'];?>
            </div>
          </div>
           <div class="form-group">
            <label>Photo</label>
            <div class="form-line">
              <img src="assets/images/placeholder.png" data-src="<?php echo getConfig($connect, 'base_url');?>image.php?t=user&id=<?php echo $lihat;?>&s=90" style="height:100px;" class="center img">
            </div>
          </div>
         <div class="form-group">
            <label>Created/Modified</label>
            <div class="form-line">
              <?php echo $b['user_tgl']?>
            </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 `users` where 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 USER</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>Name</label>
            <div class="form-line">
              <input type="text" name="nama" class="form-control" required value="<?php echo $b['user_nama'];?>">
            </div>
          </div>
		   <div class="form-group">
            <label>No Hp</label>
            <div class="form-line">
              <input type="tel" name="no_hp" class="form-control" required value="<?php echo $b['user_hp'];?>">
            </div>
          </div>
		  <div class="form-group">
            <label>Email</label>
            <div class="form-line">
              <input type="email" name="email" class="form-control" required value="<?php echo $b['user_email'];?>">
            </div>
          </div>
		  <div class="form-group">
            <label>Password Login App</label>
            <div class="form-line">
              <input type="text" name="password" class="form-control" placeholder="(Kosongkan jika tidak diubah)">
            </div>
          </div>
          <div class="form-group">
            <label>Status</label>
            <div class="form-line">
              <input name="status" type="radio" value="1" id="tampilkan_1" class="radio-col-blue" <?php echo ($b['user_status']=='1')?'checked':'';?>>
              <label for="tampilkan_1">Aktif</label><br>
              <input name="status" type="radio" value="0" id="tampilkan_2" class="radio-col-red" <?php echo ($b['user_status']=='0')?'checked':'';?>>
              <label for="tampilkan_2">Nonaktif</label>
            </div>
          </div>
          <div class="form-group">
            <label>Photo</label>
            <div class="form-line">
				<input name="foto" id="inputFile99" accept="image/*" onChange="validateImage(this);" type="file"/>
                <?php if($b['user_foto']){?>
                <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=user&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 USERS</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>Photo</th>
				<th>Name</th>
                <th>No.Hp</th>
				<th>Email</th>
                <th>Status</th>
                <th>Register Date</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 User</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>Name</label>
            <div class="form-line">
              <input type="text" name="nama" class="form-control" required>
            </div>
          </div>
		   <div class="form-group">
            <label>No Hp</label>
            <div class="form-line">
              <input type="tel" name="no_hp" class="form-control" required>
            </div>
          </div>
		  <div class="form-group">
            <label>Email</label>
            <div class="form-line">
              <input type="email" name="email" class="form-control" required>
            </div>
          </div>
		  <div class="form-group">
            <label>Password Login App</label>
            <div class="form-line">
              <input type="text" name="password" class="form-control" required>
            </div>
          </div>
		   <div class="form-group">
            <label>Photo</label>
            <div class="form-line">
               <input name="foto" 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-center"},
			{"targets": 6,"className": "text-center"},
			{"targets": 7,"className": "text-center"}
			 ]
        }); 
});
</script>