<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title></title>

  <script type="text/javascript">
/*  https://erroz.wordpress.com/2009/03/30/fungsi-pindah-baris/
    function nextfield(ID)
{
if (event.keyCode == 13)
document.getElementById(ID).focus();
}*/
</script>
<!-- Validasi Muncul popup -->

<script language='javascript'>
  /*https://senterwebs.com/artikel-415/cara-mudah-membuat-validasi-angka-lengkap.html*/
function validAngka(a)
{
    if(!/^[0-9.]+$/.test(a.value))
    {
    a.value = a.value.substring(0,a.value.length-1000);
    }
}
</script>

<!-- Content Header (Page header) -->
<div class="content-header ">
  <div class="container-fluid">
    <div class="row mb-2">
      <div class="col-sm-12">
        <!-- <h1 class="m-0 text-dark">Judul Atas</h1> -->
      </div><!-- /.col -->
    </div><!-- /.row -->
  </div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->

<!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            <!-- Default box -->
            <div class="card">
              <div class="card-header bg-info">
                <h3 class="card-title ">Hapus Registrasi</h3>
                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
                    <i class="fas fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-card-widget="remove" title="Remove">
                    <i class="fas fa-times"></i>
                  </button>
                </div>
              </div>
              <!-- /.card-header -->
        <div class="card-body">

          <!-- Croping Photo -->



<script language="javascript" type="text/javascript">
/*https://www.diskusiweb.com/discussion/31709/entry-pake-key-enter-kok-gak-berhasil*/
var fromEnter = false ;
function changeFocus (event,nextFocus)
{
if (event.keyCode==13)
{
var obj = document.getElementsByName( nextFocus )[ 0 ] ;
if (obj)
obj.focus() ;
}
fromEnter = true ;
}
function checkSubmit ()
{
fromEnter = !fromEnter ;
return fromEnter ;
}
</script>  
    
              <?php
               error_reporting(E_ALL^(E_NOTICE|E_WARNING));
              ini_set('display_errors',1);
              error_reporting(0);
              if(isset($_POST['r_register'])){
                $register=$_POST['r_register'];
                
                if($_POST['r_register']=="")
                $where ="where id= '0' ";
                  else
                  $where ="where id='$register' "; 
                }

                include 'koneksi.php';
                 $queryer = "SELECT * FROM registrasi $where ";
                $hasilr = mysqli_query($koneksi, $queryer);
                $regis = mysqli_fetch_assoc($hasilr); 
                extract($regis);
              
              ?>

              <form action="" method="POST">
                <div class="row">
              <div class="col-sm-6">
              <div class="form-group row ">

              <label for="nama" class="col-sm-3">Register </label>
                 
                <input type="text" name="r_register" id="r_register" class="form-control col-sm-7" value="<?php echo $_POST['r_register'];  ?>"/> 

                <button type="submit" name="search" class="btn btn-info"  value="cari"><i class="fas fa-search"></i></button>
              </div>
            </form>
              

              
      <form action="" class="form-simpanregister"  id="form-simpanregister">
      
      <input type="hidden" name="r_register" id="r_register" class="form-control col-sm-8" value="<?php echo $_POST['r_register'];  ?>"/> 
      <div class="form-group row">
        <label for="nama" class="col-sm-3">Tanggal</label>
        <input type="date" name="r_tgl" id="r_tgl" class="form-control col-sm-8" value="<?php echo date('Y-m-d',strtotime($tgl));?>" max="<?=date('Y-m-d')?>" placeholder="Inputkan Tanggal" required="" onKeyDown="changeFocus(event,'r_nik')"autofocus/>
      </div>


       <div class="form-group row">
        <label for="nama" class="col-sm-3">NIK</label>
        <input type="text" name="r_nik" id="r_nik" class="form-control col-sm-8" value="<?php echo $nik; ?>" onkeyup="validAngka(this)" onKeyDown="changeFocus(event,'r_nama')">      
    </div>
    <div class="form-group row">
        <label for="nama" class="col-sm-3">Nama</label>
        <input type="text" name="r_nama" id="r_nama" value="<?php echo $nama; ?>" class="form-control col-sm-8" onkeypress='return harusHuruf(event)' required="" onkeyup="this.value = this.value.toUpperCase()" onkeypress='return harusHuruf(event)' onKeyDown="changeFocus(event,'kelamin')">      
    </div>
    <div class="form-group row">
        <label for="nama" class="col-sm-3">Kelamin</label>
        <div class="custom-control custom-radio col-sm-3 ">
        <input class="custom-control-input " type="radio" id="customRadio1" name="r_kelamin" value="L" onKeyDown="changeFocus(event,'r_ttl')" checked>
        <label for="customRadio1" class="custom-control-label">Laki-laki </label>
      </div>
      <div class="custom-control custom-radio col-sm-4">
        <input class="custom-control-input " type="radio" id="customRadio2" name="r_kelamin" value="P" onKeyDown="changeFocus(event,'r_ttl')" >
        <label for="customRadio2" class="custom-control-label">Prempuan</label>
      </div>
    </div>

    <div class="form-group row">
        <label for="nama" class="col-sm-3">TTL</label>
        <input type="text" name="r_ttl" id="r_ttl" value="<?php echo $ttl; ?>" class="form-control col-sm-8" onkeyup="this.value = this.value.toUpperCase()" onkeypress='return harusHuruf(event)' onKeyDown="changeFocus(event,'r_tgll')">      
    </div>

    <div class="form-group row">
        <label for="nama" class="col-sm-3">Tgl Lahir</label>
        <input type="date" name="r_tgll" id="r_tgll" value="<?php echo date('Y-m-d',strtotime($tgll));?>" max="<?=date('Y-m-d')?>" class="form-control col-sm-8" placeholder="Tulis Keterangan" required="" onKeyDown="changeFocus(event,'r_ibu')">      
    </div>
  </div>
                            

    <div class="col-sm-6">

      <div class="form-group row">
        <label for="nama" class="col-sm-3">Ibu Kandung</label>
        <input type="text" name="r_ibu" id="r_ibu" value="<?php echo $ibu; ?>" class="form-control col-sm-8" onkeyup="this.value = this.value.toUpperCase()" onkeypress='return harusHuruf(event)' onKeyDown="changeFocus(event,'r_pekerjaan')">      
    </div>
    <div class="form-group row">
        <label for="nama" class="col-sm-3">Pekerjaan</label>
        <input type="text" name="r_pekerjaan" id="r_pekerjaan" value="<?php echo $wali; ?>" class="form-control col-sm-8" onkeyup="this.value = this.value.toUpperCase()" onkeypress='return harusHuruf(event)' onKeyDown="changeFocus(event,'r_nohp')">      
    </div>
    <div class="form-group row">
        <label for="nama" class="col-sm-3">No Hp</label>
        <input type="text" name="r_nohp" id="r_nohp" value="<?php echo $nohp; ?>" class="form-control col-sm-8" minlength="11" maxlength="12" onkeyup="validAngka(this)" onkeypress="return hanyaAngka(event)" onKeyDown="changeFocus(event,'simpanregister')">      
    </div>

      <div class="form-group row">
        <label for="nama" class="col-sm-3">Alamat</label>  
        <select id="r_alamat" name="r_alamat" class="form-control select2 col-sm-8" >
             <?php                    
      // ambil data dari database
        $queryer = "SELECT b.desa,b.kec,b.kab,a.dusun,a.desa,a.kec,a.kab,a.k_desa,a.k_kec,a.k_kab FROM alamat a left join registrasi b on a.k_kab=b.kab and a.k_kec=k_kec and a.k_desa=b.desa "; 
        $hasil = mysqli_query($koneksi, $queryer);
        while ($row = mysqli_fetch_array($hasil)) {
          $ket="";
          if(isset($_POST['dusun'])){
            $desa=trim($_POST['dusun']);
            if($desa==$row['dusun']){
              $ket="selected";
            } }
            ?>
                  
                    <div class="pertama">
                    <option  <?php echo $ket;?> value="<?php echo $row['dusun'] ?>"><?php echo $row['dusun']; ?></option></div>
                    <?php
                }
                ?>
                  <!-- https://kelasprogrammer.com/menampilkan-data-berdasarkan-pilihan-combo-box-di-php/ -->
            </select>
         </div>
        <div class="form-group row">
        <label for="nama" class="col-sm-3">RT/RW</label>  
        <select id="r_rtrw" name="r_rtrw" class="form-control select2 col-sm-8" >
       <?php
        // ambil data dari database
          $query = "SELECT a.rtrw,b.desa,b.kec,b.kab,a.dusun,a.desa,a.kec,a.kab,a.k_desa,a.k_kec,a.k_kab FROM alamat a left join registrasi b on a.k_kab=b.kab and a.k_kec=k_kec and a.k_desa=b.desa "; 
          $hasil = mysqli_query($koneksi, $query);
          while ($row = mysqli_fetch_array($hasil)) {
            $ket="";
            if(isset($_POST['rtrw'])){
              $desa=trim($_POST['rtrw']);
              if($desa==$row['rtrw']){
                $ket="selected";
              }  }
              ?>
                  
                    <div class="pertama">
                    <option  <?php echo $ket;?> value="<?php echo $row['rtrw'] ?>"><?php echo $row['rtrw']; ?></option></div>
                    <?php
                }
                ?>
                  <!-- https://kelasprogrammer.com/menampilkan-data-berdasarkan-pilihan-combo-box-di-php/ -->

            </select>
      </div>
      
        <div class="form-group row">
        <label for="nama"  class="col-sm-3">Desa</label>
        <select id="r_desa" name="r_desa" class="form-control select2 col-sm-8" >
       <?php
        // ambil data dari database
          $query = "SELECT a.rtrw,b.desa,b.kec,b.kab,a.dusun,a.desa,a.kec,a.kab,a.k_desa,a.k_kec,a.k_kab FROM alamat a left join registrasi b on a.k_kab=b.kab and a.k_kec=k_kec and a.k_desa=b.desa "; 
          $hasil = mysqli_query($koneksi, $query);
          while ($row = mysqli_fetch_array($hasil)) {
            $ket="";
            if(isset($_POST['desa'])){
              $desa=trim($_POST['rtrw']);
              if($desa==$row['desa']){
                $ket="selected";
              }  }
              ?>
              <div class="pertama">
              <option  <?php echo $ket;?> value="<?php echo $row['k_desa'] ?>"><?php echo $row['desa']; ?></option></div>
              <?php
          }
          ?>
                  <!-- https://kelasprogrammer.com/menampilkan-data-berdasarkan-pilihan-combo-box-di-php/ -->

            </select>
      </div>
      
    <div class="form-group row">
        <label for="nama"  class="col-sm-3">Kecamatan</label>
       <select id="r_kecamatan" name="r_kecamatan" class="form-control select2 col-sm-8" >
       <?php
      
        // ambil data dari database
          $query = "SELECT a.dusun,a.desa,a.kec,a.kab,a.k_desa,a.k_kec,a.k_kab FROM alamat a left join registrasi b on a.k_kab=b.kab and a.k_kec=k_kec and a.k_desa=b.desa "; 
          $hasil = mysqli_query($koneksi, $query);
          while ($row = mysqli_fetch_array($hasil)) {
            $ket="";
            if(isset($_POST['kec'])){
              $desa=trim($_POST['kec']);
              if($desa==$row['kec']){
                $ket="selected";
              }
            }
              ?>
            
              <div class="pertama">
              <option  <?php echo $ket;?> value="<?php echo $row['k_kec'] ?>"><?php echo $row['kec']; ?></option></div>
              <?php
          }
          ?>
            <!-- https://kelasprogrammer.com/menampilkan-data-berdasarkan-pilihan-combo-box-di-php/ -->

      </select>
            
        </div>
        <div class="form-group row">
        <label for="nama" class="col-sm-3">Kabupaten</label>
        <select id="r_kabupaten" name="r_kabupaten" class="form-control select2 col-sm-8" >
             <?php                    
              // ambil data dari database
                $query = "SELECT a.rtrw,b.desa,b.kec,b.kab,a.dusun,a.desa,a.kec,a.kab,a.k_desa,a.k_kec,a.k_kab FROM alamat a left join registrasi b on a.k_kab=b.kab and a.k_kec=k_kec and a.k_desa=b.desa "; 
                $hasil = mysqli_query($koneksi, $query);
                while ($row = mysqli_fetch_array($hasil)) {
                  $ket="";
                  if(isset($_POST['kab'])){
                    $desa=trim($_POST['kab']);
                    if($desa==$row['kab']){
                      $ket="selected";
                    }
                  }
                    ?>
                  
                    <div class="pertama">
                    <option  <?php echo $ket;?> value="<?php echo $row['k_kab'] ?>"><?php echo $row['kab']; ?></option></div>
                    <?php
                }
                ?>
                  <!-- https://kelasprogrammer.com/menampilkan-data-berdasarkan-pilihan-combo-box-di-php/ -->
            </select>           
          </div>
          </div>
          </div>
              
            <!-- /.card-body -->
            <div class="card-footer ">
              <input type="button" name="simpanregister" id="simpanregister" 
              class="btn btn-primary" value="Simpan">
              <a href="home.php?home=<?php echo md5("registrasi");?>" class="btn btn-secondary">
                Tambah
              </a>
              <a href="home.php?home=<?php echo md5("edit_registrasi");?>" class="btn btn-warning">
                Edit 
              </a>
              <a href="home.php?home=<?php echo md5("lap_register");?>" class="btn btn-info">
                Lihat
              </a>
              <a href="home.php?home=<?php echo md5("delet_registrasi");?>" class="btn btn-danger">
                Hapus
              </a>
            </div>
            
          </form>
        </div>
        <!-- /.card -->
      </div>
      <!--/.col (left) -->
    </div>
    <!-- /.row -->
  </div><!-- /.container-fluid -->
</section>
<!-- /.content -->

<!-- <script type="text/javascript" src="jquery.js"></script> -->
<script type="text/javascript">

 $(document).ready(function(){
    $("#simpanregister").click(function(){
      var data = $('#form-simpanregister').serialize();
      var r_register= $('#r_register').val();
      var r_tgl= $('#r_tgl').val();
      var r_nik= $('#r_nik').val();
      var r_nama= $('#r_nama').val();
      var r_kelamin= $('#r_kelamin').val();
      var r_ttl= $('#r_ttl').val();
      var r_tgll= $('#r_tgll').val();
      var r_alamat= $('#r_alamat').val();
      var r_rtrw= $('#r_rtrw').val();
      var r_desa= $('#r_desa').val();
      var r_kecamatan= $('#r_kecamatan').val();
      var r_kabupaten= $('#r_kabupaten').val();
      var r_ibu= $('#r_ibu').val();
      var r_pekerjaan= $('#r_pekerjaan').val();
      var r_nohp= $('#r_nohp').val();
      

      if(r_register== "0"|| r_tgl=="0" ||r_nik=="0"||r_nama=="0"||r_kelamin=="0"||r_ttl=="0"||r_tgll=="0"||r_alamat=="0"||r_rtrw=="0"||r_desa=="0"||r_kecamatan=="0"||r_kabupaten=="0"||r_ibu=="0"||r_pekerjaan=="0"||r_nohp=="0"){ 
Swal.fire({
  icon: 'error',
  title: 'Hati-hati...',
  text: 'Data masih ada yg belum diisi!',
  footer: '<a href="">Anda Perlu teliti sedikit lagi?</a>'
});

    } else if(r_register== ""|| r_tgl==""||r_nik==""||r_nama==""||r_kelamin==""||r_ttl==""||r_tgll==""||r_alamat==""||r_rtrw==""||r_desa==""||r_kecamatan==""||r_kabupaten==""||r_ibu==""||r_pekerjaan==""||r_nohp==""){ 

      Swal.fire(
  'Data Masih ada yang Kosong !',
  'Mohon data dilengkapi dlu !',
  'question'
);
        
       
    }else{

      $.ajax({
        type: 'POST',
        url: 'simpan/simpan_register_delet.php',
        data: data,
        success: function(data) {
         console.log(data)
         let timerInterval
Swal.fire({
  title: 'Alhamdulillah..! Data Tersimpan.',
  html: 'Silahkan Cek <b></b> Sendiri.',
  timer: 3000,
  timerProgressBar: true,
  didOpen: () => {
    Swal.showLoading()
    const b = Swal.getHtmlContainer().querySelector('b')
    timerInterval = setInterval(() => {
      b.textContent = Swal.getTimerLeft()
    }, 100)
  },
  willClose: () => {
    clearInterval(timerInterval)
  }
}).then((result) => {
  /* Read more about handling dismissals below */
  if (result.dismiss === Swal.DismissReason.timer) {
    console.log('I was closed by the timer')
  }
})

         alert("Data Berhasil Dihapus...!");
         window.location.href='home.php?home=2ac87a434540d7c95ddc342a53f0f122'; 
        },
        error: function(error){
          console.log(`error ${error}`)
         
        }
      });
    }
    });
  });
  
</script>
<script type="text/javascript">
  function cekhuruf(a) {
valid = /^[A-Za-z]{1,}$/;
return valid.test(a);
}
</script>
<script>
  /*required onkeypress='return harusHuruf(event)' tinggal pasang ke input
  https://kursuswebdesign.org/cara-membuat-validasi-input-form-hanya-text-dengan-javascript/*/
function harusHuruf(evt){
        var charCode = (evt.which) ? evt.which : event.keyCode
        if ((charCode < 65 || charCode > 90)&&(charCode < 97 || charCode > 122)&&charCode>32)
            return false;
        return true;
}
</script>

<script>
    function hanyaAngka(evt) {
      var charCode = (evt.which) ? evt.which : event.keyCode
       if (charCode > 31 && (charCode < 48 || charCode > 57))
 
        return false;
      return true;
    }
  </script>


</head>
</html>