<!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>
<?php
$kode= $_SESSION['kode'];
?>

<!-- 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 ">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 -->

<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.min.css">
 -->  
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/croppie/2.6.2/croppie.min.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/croppie/2.6.2/croppie.js"></script>

    
    

      <!-- <div class="row">
        <div class="col-md-4 text-center">
        <div id="upload-demo"></div>
        </div>
        <div class="col-md-4" style="padding:5%;">
        <strong>Cari Photo:</strong>
        <input type="file" id="image" nama="image" onkeypress="nextfield('crop')">

        <button di="crop" nama="crop" class="btn btn-info btn-block btn-upload-image" style="margin-top:2%">Crop</button>

        </div>

        <div class="col-md-4">
        <div id="preview-crop-image" style="background:#9d9d9d;width:300px;padding:50px 50px;height:300px;"></div>
        </div>
      </div> -->

    

<!-- https://www-devopsschool-com.translate.goog/blog/image-upload-and-crop-using-php-and-jquery/?_x_tr_sl=en&_x_tr_tl=id&_x_tr_hl=id&_x_tr_pto=tc -->

<!-- <script type="text/javascript">


var resize = $('#upload-demo').croppie({
    enableExif: true,
    enableOrientation: true,    
    viewport: { // Default { width: 100, height: 100, type: 'square' } 
        width: 200,
        height: 200,
        type: 'square' //square
    },
    boundary: {
        width: 300,
        height: 300
    }
});


$('#image').on('change', function () { 
  var reader = new FileReader();
    reader.onload = function (e) {
      resize.croppie('bind',{
        url: e.target.result
      }).then(function(){
        console.log('jQuery bind complete');
      });
    }
    reader.readAsDataURL(this.files[0]);
});


$('.btn-upload-image').on('click', function (ev) {
  resize.croppie('result', {
    type: 'canvas',
    size: 'viewport'
  }).then(function (img) {
    $.ajax({
      url: "menu/croppie.php",
      type: "POST",
      data: {"image":img},
      success: function (data) {
        html = '<img src="' + img + '" />';
        $("#preview-crop-image").html(html);
      }
    });
  });
});

</script>
-->
<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>  
     


              <form action="" method="POST">
              <div class="row">
              <div class="col-sm-6">
              <div class="form-group row ">
              <label for="nama" class="col-sm-3">Pilih Alamat </label>
              <select id="desa" name="desa" class="form-control select2 col-sm-7" onchange="this.form.submit();">
                     <?php
                     include 'koneksi.php';
                      // ambil data dari database
                        $query = "SELECT * FROM alamat order by kec,desa";  /*ORDER BY divisi*/                /*https://kodingbagus.blogspot.com/2019/08/cara-membuat-pencarian-di-selectoption.html*/
                        $hasil = mysqli_query($koneksi, $query);
                        while ($row = mysqli_fetch_array($hasil)) {
                          $ket="";
                          if(isset($_POST['desa'])){
                            $desa=trim($_POST['desa']);
                            if($desa==$row['desa'])
                            {
                              $ket="selected";
                            }
                          }
                            ?>
                          
                            <div class="pertama"><option  <?php echo $ket ?> value="<?php echo $row['kode']; ?>"><?php echo $row['dusun']; ?>-<?php echo $row['rtrw']; ?>-<?php echo $row['desa']; ?>-<?php echo $row['kec'];?>-<?php echo $row['kab'];?></option></div>
                            <?php
                        }
                        ?>
                          <!-- https://kelasprogrammer.com/menampilkan-data-berdasarkan-pilihan-combo-box-di-php/ -->

                    </select>
                    
                        
                <!-- <input type="text"name="query" class="form-control select2 col-sm-8"  placeholder="Ketik ID/Nama/ayah" autofocus/> --> <!-- readonly -->
                <button type="submit" name="search" class="btn btn-info"  value="cari"><i class="fas fa-search"></i></button>
              </div>
            </form>
              

              <?php
                                           
                 $a = mysqli_query($koneksi,"SELECT count(id)+1 as no FROM registrasi where kode='$kode' ");
                  $id = mysqli_fetch_row($a) ;
              ?>
              <form action="" class="form-simpanregister"  id="form-simpanregister">
              
              <div class="form-group row">
                <label for="nama" class="col-sm-3">No Registrasi</label>
                <input type="text" name="r_register" id="r_register" class="form-control col-sm-8" value="<?php echo $kode.".". sprintf("%06d",$id['0']+1) ?>" readonly="r_register"  onkeypress="nextfield('r_tgl')"> 
              </div>

              <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');?>" 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" required="" placeholder="Tulis No KTP" 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" class="form-control col-sm-8" onkeypress='return harusHuruf(event)' placeholder="Tulis Nama Sesuai KTP"required="" onkeyup="this.value = this.value.toUpperCase()" onkeypress='return harusHuruf(event)' onKeyDown="changeFocus(event,'r_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" class="form-control col-sm-8"required=""  placeholder="Tulis Tempat Lahir Anda" onkeyup="this.value = this.value.toLowerCase()" 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" class="form-control col-sm-8" placeholder="Tulis Keterangan" required="" onKeyDown="changeFocus(event,'r_ibu')">      
            </div>

          </div>
                      <?php
                      error_reporting(E_ALL^(E_NOTICE|E_WARNING));
                      ini_set('display_errors',1);
                      error_reporting(0);
                  if(isset($_POST['desa'])){                  

                      $desa=$_POST["desa"];
                   
                        $query1 = "SELECT * FROM alamat where kode='".$desa."' ";
                         /*https://kodingbagus.blogspot.com/2019/08/cara-membuat-pencarian-di-selectoption.html*/
                         /*https://apayangkamu.com/cara-menggunakan-cek-data-kosong-php#:~:text=include%20%22koneksi.php%22%3B%20%24sql%20%3D%20%22select%20%2A%20from%20pengunjung,%2F%2FPengecekan%20apakah%20data%20ada%20%24cek%20%3D%20mysqli_num_rows%20%28%24query%29%3B*/
                        $hasil2 = mysqli_query($koneksi, $query1);
                        $row = mysqli_fetch_assoc($hasil2);       
                       } ?>

            <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" class="form-control col-sm-8"required="" placeholder="Tulis nama ibu yang melahirkan"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"required="" class="form-control col-sm-8" placeholder="Tulis Pekerjaan"onkeyup="this.value = this.value.toLowerCase()" 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" class="form-control col-sm-8"required="" placeholder="Tidak usan nulis angka 0/nol" minlength="11" maxlength="14" onkeyup="validAngka(this)" onkeypress="return hanyaAngka(event)" onKeyDown="changeFocus(event,'r_nohp2')">      
            </div>
            

            <div class="form-group row">
                <label for="nama" class="col-sm-3">No Hp-2</label>
                <input type="text" name="r_nohp2" id="r_nohp2" class="form-control col-sm-8"required="" placeholder="Tidak usan nulis angka 0/nol" minlength="11" maxlength="14" onkeyup="validAngka(this)" onkeypress="return hanyaAngka(event)" onKeyDown="changeFocus(event,'simpanregister')">      
            </div>
        <script>
    function addPrefix(phoneInput) {
        // Ambil nilai dari input
        let inputValue = phoneInput.value;

        // Cek apakah inputValue sudah diawali dengan "62"
        if (inputValue && !inputValue.startsWith('62')) {
            // Menghapus angka yang terdapat sebelum 0
            if (inputValue.startsWith('0')) {
                inputValue = inputValue.substring(1);
            }
            // Menambahkan prefix "62"
            phoneInput.value = '62' + inputValue;
        }
    }

    document.getElementById('r_nohp').addEventListener('input', function() {
        addPrefix(this);
    });

    document.getElementById('r_nohp2').addEventListener('input', function() {
        addPrefix(this);
    });
</script>
        
              <div class="form-group row">
                <label for="nama" class="col-sm-3">Alamat</label>  
                <input type="hidden" name="r_alamat" id="r_alamat" class="form-control col-sm-1" placeholder="Tulis Alama Sama dg KTP" required="" value="<?php echo $row['dusun']; ?>" onkeypress="nextfield('r_desa')">
                <input type="text"  class="form-control col-sm-8"required="" readonly="r_alamat" value="<?php echo $row['dusun']; ?>" onkeypress="nextfield('r_desa')">  </div>

                <div class="form-group row">
                <label for="nama" class="col-sm-3">RT/RW</label>  
                <input type="text" name="r_rtrw" id="r_rtrw" class="form-control col-sm-8"required="" readonly="r_rtrw" value="<?php echo $row['rtrw']; ?>" onkeypress="nextfield('r_desa')">  
              </div>
              
                <div class="form-group row">
                <label for="nama"  class="col-sm-3">Desa</label>
                <input type="hidden" name="r_desa" id="r_desa" class="form-control col-sm-1" placeholder="Tulis Nominal" required="" readonly="desa" value="<?php echo $row['k_desa']; ?>" >
                <input type="text"  class="form-control col-sm-8" required="" readonly="r_desa" value="<?php echo $row['desa']; ?>">
              </div>
              
            <div class="form-group row">
                <label for="nama"  class="col-sm-3">Kecamatan</label>
               <input type="hidden" name="r_kecamatan" id="r_kecamatan" class="form-control col-sm-1" readonly="kecamatan" value="<?php echo $row['k_kec']; ?>" required="">
               <input type="text"  class="form-control col-sm-8" readonly="kecamatan" value="<?php echo $row['kec']; ?>" required="" onkeypress="nextfield('r_kabupaten')">
                    
                </div>
                <div class="form-group row">
                <label for="nama" class="col-sm-3">Kabupaten</label>
                <input type="hidden" name="r_kabupaten" id="r_kabupaten" class="form-control col-sm-1" required="" readonly="kota"  value="<?php echo $row['k_kab']?>" onkeypress="nextfield('r_ibu')"> 
                
                <input type="text"  class="form-control col-sm-8" required="" readonly="kota"  value="<?php echo $row['kab']; ?>" onkeypress="nextfield('r_ibu')">      
                
            </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_nama == ""){
 alert("nama harus diisi");
 }else if (!cekhuruf(r_nama)) {
 alert("Isi Dengan Huruh");
 r_nama.focus();
 return false; 
 https://www.kursuswebsite.org/cara-membuat-form-validasi-wajib-huruf-dengan-javascript/
 https://kursuswebdesign.org/cara-membuat-validasi-input-form-hanya-text-dengan-javascript/
}*/

      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>'
});
/*https://sweetalert2.github.io/*/
       /* alert ("Data Masih ada yang kosong 1");*/
        //window.location.href='/rakerugt/home.php?page=cap_realita';
      
    } 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'
);
        /*alert ("Data Masih ada yang kosong 2");*/
       
    }else{

      $.ajax({
        type: 'POST',
        url: 'simpan/simpan_register.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) => {
 
  if (result.dismiss === Swal.DismissReason.timer) {
    console.log('I was closed by the timer')
  }
})*/
         Swal.fire({
  title: 'Alhamdulillah...Data Sukses Tersimpan...!!!!',
  text: 'Bisa Anda Cek...!!!',
  imageUrl: 'img/logougt.png',
  imageWidth: 75,
  imageHeight: 80,
  imageAlt: 'Custom image',
  animation: false
})

         alert("Data Sukses Disimpan");
         window.location.href='home.php?home=4b7f5c754b59efd711f61deb0d0541db'; 
        },
        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>

<script type="text/javascript">
  function isValidDate(dateString)
{
    // First check for the pattern
    var regex_date = /^\d{4}\-\d{1,2}\-\d{1,2}$/;

    if(!regex_date.test(dateString))
    {
        return false;
    }

    // Parse the date parts to integers
    var parts   = dateString.split("-");
    var day     = parseInt(parts[2], 10);
    var month   = parseInt(parts[1], 10);
    var year    = parseInt(parts[0], 10);

    // Check the ranges of month and year
    if(year < 1000 || year > 3000 || month == 0 || month > 12)
    {
        return false;
    }

    var monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];

    // Adjust for leap years
    if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
    {
        monthLength[1] = 29;
    }

    // Check the range of the day
    return day > 0 && day <= monthLength[month - 1];
}
</script>
</head>
</html>