
    <?php
/*include ('./laporan/cek_login.php');*/
 include_once(dirname(__FILE__).'/../cek_login.php');
 include('kalenderhijriah.php');
?>
<!DOCTYPE html>
<html lang="en">
     <head>
      <body>
<script type="text/javascript" src="./laporan/jquery.js"></script>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">
</script>


<link rel="stylesheet" href="https://cdn.datatables.net/1.10.22/css/dataTables.bootstrap4.min.css">
<script src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js">
</script>
<script src="https://cdn.datatables.net/1.10.22/js/dataTables.bootstrap4.min.js">
</script>            
<!-- <link href="docs/css/bootstrap.min.css" rel="stylesheet">  berfungsi untuk menampilkan icon --> 
 
</head>
</body>
        <!-- page content -->
        <!-- <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left">
                <h3>Form advanced</h3>
              </div>

            </div>
 -->

 

 <body>    
<link rel="stylesheet" type="text/css" href="desain.css">
            <div class="clearfix"></div>

            <div class="row">
              <!-- form input mask -->
              <div class="col-md-12 col-sm-12 ">
                <div class="x_panel" style=" background:  #73c6b6; margin-right: 0%;margin-left: 0%;">
                  <div class="x_title">
                    <h2 class="fonttebal"><b>INPUT PENABUNG NON MURID </h2></b>
                    <ul class="nav navbar-right panel_toolbox ">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li>
                      <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                        <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                            <a class="dropdown-item" href="#">Settings 1</a>
                            <a class="dropdown-item" href="#">Settings 2</a>
                          </div>
                      </li>
                      <li><a class="close-link"><i class="fa fa-close"></i></a>
                      </li>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                    <br />
                   <!-- <form class="form-horizontal form-label-left"> -->
           <div class="container">
            <div class="col-lg-6">
                    
                        <?php
                       include './koneksi.php';    
                        /*ini_set('display_errors',1);
                        error_reporting(E_ALL);   */                  
                          $a = mysqli_query($koneksi,"SELECT * FROM penabung ORDER BY rekening DESC LIMIT 1");

                           $b = mysqli_fetch_row($a)
  
  
                          ?>



<form  action="" method ="POST">
     
<link rel="stylesheet" href="select2.min.css" />
     <style>
.select2-dropdown {top: 7px !important; left: 2px !important;}
</style>

          
<!-- <form action="<?php //echo $_SERVER["PHP_SELF"];?>" method="POST"> -->
     
                     <label class="control-label col-md-3 col-sm-3 col-xs-3">Alamat Auto</label>
                     <div class="col-md-8 col-sm-8 col-xs-8">
                      <select id="desa" name="desa" class="form-control" onchange="this.form.submit();">
                       <!-- <option value=""></option>  -->
<?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>
                    
                        </div>

                    

                    <!-- <div class="from-group"> -->
                      <!-- <button type="submit" name="Tombol" class="btn btn-info"></button> -->
                    <button type="submit" name="Tombol" class="btn btn-white"></button>
                    <!-- </div> -->
                  
          

     
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> -->
<script src="select2.min.js"></script>
<script>
$("#desa").select2( {
 placeholder: "Pilih Alamat .",
 allowClear: true
 } );
</script>  <!-- https://www.allphptricks.com/select-box-with-search-option-using-jquery/ -->
      
     


    <label></label>
  </form>
<br/>

                          <?php

error_reporting(E_ALL^(E_NOTICE|E_WARNING));
ini_set('display_errors',1);
error_reporting(0);
?>

               <form  class="form-user" id="formProduk"  method ="POST" enctype="multipart/form-data" name="formPendaftaran"  onsubmit="return validateForm()" onsubmit="return validasi_data(this)" onsubmit="return validate()" onsubmit="return cekData();">      
                     
                    
                     

                      <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">ID</label>
                        <div class="col-md-8 col-sm-8 col-xs-8">

                          <input type="text" class="form-control" readonly="nip" name ="nip" size="11" value="<?php echo  sprintf("%08d",$b['1']+1) ?>">                        
                        </div>
                      </div>
                      
                    <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">Tgl</label>
                        <div class="col-md-8 col-sm-8 col-xs-8">
            <input type="text" class="form-control" name="tgl"readonly="tgl" value="<?php echo sprintf("%02d",$hijri [1])."-".sprintf("%02d",$hijri[0])."-". $hijri[2]; ?>">                          
                        </div>
                      </div>

                      <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">NIK</label>
                        <div class="col-md-8 col-sm-8 col-xs-8">
                          <input type="text" class="form-control" name="nik" minlength="16" maxlength="16" id="chek" data-minlength="6" onkeypress="return hanyaAngka(event)" placeholder="" value="351416">
                          </div>
                      </div>
                     
                      <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">Nama</label>
                        <div class="col-md-8 col-sm-8 col-xs-8">
                          <input type="text" class="form-control" name="nama" id="nama"onkeyup="myFunction()"  required onkeypress='return harusHuruf(event)'placeholder="">
                          
                        </div>
                      </div>

           
                      <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">Jenis</label>
                        <div class="col-md-8 col-sm-8 col-xs-8">
                          <div class="pertama form-control">
                           <input type='radio' name='jenis' onClick="validasi()" value='L' /> Laki-laki
                           <input type='radio' name='jenis' onClick="validasi()" align="right" value='P' /> Perempuan</br></div>
                           
                           
                        </div>
                      </div>
                      <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">Tgl Lahir</label>
                        <div class="col-md-8 col-sm-8 col-xs-8">

                          <input type="date" class="form-control" name="tgllahir" id="tgllahir" placeholder=""> 
                          <!-- <i class="fa fa-fw fa-check-circle"></i> -->
                          <!-- <b>Format Tanggal:</b> Tanggal/Bulan/Tahun</td> -->
                          
                        </div>
                      </div>
                      <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">Tmp. Lahir</label>
                        <div class="col-md-8 col-sm-8 col-xs-8">
                          <input type="text" class="form-control" name="tempatlahir" id="tempatlahir" onkeyup="myFunction()" required onkeypress='return harusHuruf(event)' placeholder="">
                          
                        </div>
                      </div>


                       <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">Angkatan</label>
                        <div class="col-md-8 col-sm-8 col-xs-8">
                          <input type="text" class="form-control" name="angkatan" value="<?php echo $hijri[2];?>-<?php echo $hijri[2]+1;?> " placeholder="">
                          
                        </div>
                      </div>
                      


                      
                      </div>
                      </div>

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





                          

                      <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3" >Nama Ibu</label>
                        <div class="col-md-8 col-sm-8 col-xs-8">
                          <input type="text" class="form-control" name="ibu" id="ibu" onkeyup="myFunction()" required onkeypress='return harusHuruf(event)'placeholder="">
                          
                        </div>
                      </div>
   
                      
                        <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">Suami/Istri</label>
                        <div class="col-md-8 col-sm-8 col-xs-8">
                          <input type="text" class="form-control" name="pasangan" id="pasangan"onkeyup="myFunction()"  required onkeypress='return harusHuruf(event)'placeholder="">
                          
                        </div>
                      </div>

                      <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">No. Hp</label>
                        <div class="col-md-8 col-sm-8 col-xs-8">
                          <input type="text" class="form-control" name="nohp" onkeypress="return hanyaAngka(event)" placeholder="">
                          
                        </div>
                      </div>
                                                               
                      
                      <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">Kpl. MMU</label>
                        <div class="col-md-8 col-sm-8 col-xs-8">
                          <input type="text" class="form-control" name="kplmmu" id="kplmmu" onkeyup="myFunction()" required onkeypress='return harusHuruf(event)' placeholder="" value="M ASMUI">
                          
                        </div>
                      </div>

      <?php
      if(isset($_POST['desa'])){
        $desa=$_POST["desa"];
    
    
                        // ambil data dari database
                        $query1 = "SELECT * FROM alamat where kode='".$desa."' ";                 /*https://kodingbagus.blogspot.com/2019/08/cara-membuat-pencarian-di-selectoption.html*/
                    
                        $hasil2 = mysqli_query($koneksi, $query1);

                        $data = mysqli_fetch_assoc($hasil2);
                               
   }
   ?>
   

                    <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">Alamat</label>
                        <div class="col-md-8 col-sm-8 col-xs-8">
                          <input type="text" class="form-control" name="dusun" id="dusun" onkeyup="myFunction()" required onkeypress='return harusHuruf(event)' readonly="dusun" value="<?php echo $data['dusun']; ?>" >
                          
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">RT/RW</label>
                        <div class="col-md-8 col-sm-8 col-xs-8">
                          <input type="text" class="form-control" name="rtrw" readonly="rtrw" value="<?php echo $data['rtrw']; ?>" >
                          
                        </div>
                      </div>

                       <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">Desa</label>
                        <div class="col-md-2 col-sm-2 col-xs-2">
                          <input type="text" class="form-control" name="desa" readonly="desa" value="<?php echo $data['k_desa']; ?>" >
                          </div>
                          <div class="col-md-6 col-sm-6 col-xs-6">
                          <input type="text" class="form-control"  readonly="desa" value="<?php echo $data['desa']; ?>" >
                          
                        </div>
                      </div>
                    

                       <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">Kecamatan</label>
                        <div class="col-md-2 col-sm-2 col-xs-2">
                          <input type="text" class="form-control" name="kecamatan" readonly="kecamatan" value="<?php echo $data['k_kec']; ?>">
                          </div>
                          <div class="col-md-6 col-sm-6 col-xs-6">
                          <input type="text" class="form-control"  readonly="kecamatan" value="<?php echo $data['kec'] ?>">
                        </div>
                      </div>
                       <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">Kota</label>
                        <div class="col-md-2 col-sm-2 col-xs-2">
                          <input type="text" class="form-control" name="kota" readonly="kota"  value="<?php echo $data['k_kab']; ?>">
                        </div>
                        <div class="col-md-6 col-sm-6 col-xs-6">
                          <input type="text" class="form-control"  readonly="kota"  value="<?php echo $data['kab']; ?>">
                        </div>
                      </div>

                       

                       <div class="form-group row">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3">Photo</label>
                        <div class="col-md-8 col-sm-8 col-xs-8">

                        <td><input type="file" name="foto"></td>

                        
                        </div>
                      </div>

                    





                      <div class="form-group row">
                        <div class="col-md-9 offset-md-3">
                          <td><button type="submit"  class="tombol-simpan btn btn-success" name="simpan" onclick="return radioValidation();">Simpan</button></td>
                          <button type="reset" class="btn btn-primary">Cancel</button> 
                           
                        </div>
                      </div>

                    </div>
                  
                  </div>
                </div>
              </div>
              </div>
              </form>

<script type="text/javascript" src="jquery.js"></script>
<!-- https://www.maribelajarcoding.com/2019/05/upload-gambar-dengan-ajax-php-dan-mysql.html -->
 <script type="text/javascript">
    $("form").submit(function(e) {
        e.preventDefault();
        var form = $('#formProduk')[0];
        var data = new FormData(form);
        $.ajax({
            url: './simpan/simpan_penabung.php',
            type: 'post',
            enctype: 'multipart/form-data',
            data: data,
            processData: false,
            contentType: false,
            cache: false,
            success: function(data) {
             
              alert(data);

              //reload tabel tampilData 
              $("#tampilData").load(" #tampilData > *");
            }
        });
    });
  </script>


              
 <!-- <script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript"> /*https://www.malasngoding.com/input-data-ke-database-tanpa-reload-dengan-ajax-jquery/*/
  $(document).ready(function(){
    $(".tombol-simpan").click(function(){
      var data = $('.form-user').serialize();
      $.ajax({
        type: 'POST',
        enctype: 'multipart/form-data',
        url: "./simpan/simpan_register.php",
        data: data,
        success: function() {
          $('.tampildata').load("./laporan/1lap_tabungan.php");
        }
      });
    });
  });
  </script> -->


                     <!--  <script>
                      $(function(){
                        $('input[type="submit"]').prop('disabled',true);
                        $('check').on('input',function(e){
                          if(this.value.length===6){
                            $('input[type="submit"]').prop('disabled',false);
                          }else{
                            $('input[type="submit"]').prop('disabled',true);
                          }
                          });
                        });
                        </script>  -->

<!-- Validasi Tidak Boleh ada yg Kosong -->
<script> /*https://belajarphp.net/tutorial-validasi-form-menggunakan-html-dan-javascript/*/

        function validateForm() {
            if (document.forms["formPendaftaran"]["nama"].value == "") {
                alert("Ma'af...! Nama Belum diisi");
                document.forms["formPendaftaran"]["nama"].focus();
                return false;
            }
            if (document.forms["formPendaftaran"]["tempatlahir"].value == "") {
                alert("Ma'af...! tempat Lahir Belum diisi");
                document.forms["formPendaftaran"]["tempatlahir"].focus();
                return false;
            }
            if (document.forms["formPendaftaran"]["nohp"].value == "") {
                alert("Ma'af...! No Hp Belum diisi");
                document.forms["formPendaftaran"]["nohp"].focus();
                return false;
            }
            
            if (document.forms["formPendaftaran"]["nik"].value == "") {
                alert("Ma'af...! No NIK Belum diisi");
                document.forms["formPendaftaran"]["nik"].focus();
                return false;
            }
            
            if (document.forms["formPendaftaran"]["ibu"].value == "") {
                alert("Ma'af...! Ibu Belum diisi");
                document.forms["formPendaftaran"]["ibu"].focus();
                return false;
            }
            if (document.forms["formPendaftaran"]["pasangan"].value == "") {
                alert("Ma'af...! Wali Belum diisi");
                document.forms["formPendaftaran"]["pasangan"].focus();
                return false;
            }

            if (document.forms["formPendaftaran"]["dusun"].value == "") {
                alert("Ma'af...! Alamat Lengkap Belum diisi");
                document.forms["formPendaftaran"]["dusun"].focus();
                return false;
            }


           
            if (document.forms["formPendaftaran"]["jenis"].selectedIndex < 1) {
                alert("Pilih Jenis Tabungan.");
                document.forms["formPendaftaran"]["jenis"].focus();
                return false;
            }
        }
    </script>
<!-- Validasi Harus Angka/Tidak Boleh Huruf -->
 <script>
    function hanyaAngka(evt) {
      /*https://www.malasngoding.com/membuat-inputan-hanya-angka-dengan-javascript/*/
      var charCode = (evt.which) ? evt.which : event.keyCode
       if (charCode > 31 && (charCode < 48 || charCode > 57))
 
        return false;
      return true;
    }
  </script>   
  <!-- Validasi Harus Huruf/Tidak boleh angka -->
<script>
function harusHuruf(evt){
  /*https://kursuswebdesign.org/cara-membuat-validasi-input-form-hanya-text-dengan-javascript/*/
        var charCode = (evt.which) ? evt.which : event.keyCode
        if ((charCode < 65 || charCode > 90)&&(charCode < 97 || charCode > 122)&&charCode>32)
            return false;
        return true;
}
</script>

<!-- Validasi Huruf Capital/Besar -->
      <script>
function myFunction() {
  /*https://kursuswebdesign.org/membuat-inputan-otomatis-huruf-capital-dengan-javascript/*/
    var x = document.getElementById("nama");
    x.value = x.value.toUpperCase();
    var x = document.getElementById("tempatlahir");
    x.value = x.value.toUpperCase();
    var x = document.getElementById("pasangan");
    x.value = x.value.toUpperCase();
    var x = document.getElementById("ibu");
    x.value = x.value.toUpperCase();
    var x = document.getElementById("wali");
    x.value = x.value.toUpperCase();
    var x = document.getElementById("kplmmu");
    x.value = x.value.toUpperCase();
}
</script>
  
<!-- Validasi cekbok -->
<script type="text/javascript">
    function radioValidation(){
/*https://www.jasa-website.net/artikel/validasi-radio-button-dengan-javascript*/

        var gender = document.getElementsByName('jenis');
        
        var genValue = false;

        for(var i=0; i<gender.length;i++){
            if(gender[i].checked == true){
                genValue = true;    
            }
        }
        if(!genValue){
            alert("Mohon Maaf Ust..!! Ust Belum Memilih Jenis...!!!");
            return false;
        }


    }
</script>

<!-- Validasi Tanggal -->
<?php
function CekTLS_tanggal($data){
 if(!preg_match("/^[0-9-\-]*$/",$data)){
  return true;
 }else{
  return false;
 }
}
function BCA_tanggal($data){
  $ar=explode("-", $data);
  //cek tahun
  if(strlen($ar[0])<4){
   return false;
  }
  //cek bulan
  elseif($ar[1]>12){ 
   return false;
  }elseif(strlen($ar[1])<2){
   return false;
  //cek tanggal
  }
  elseif($ar[2]>31){
   return false;   
  }elseif(strlen($ar[2]<2)){    
   return false;
  }else{
   return true;
  } 

}


$tanggal_err = "";
/*if($_SERVER['REQUEST_METHOD']=='POST'){*/
 //mengecek data apakah kosong atau tidak
 if(empty(trim($_POST['tgllahir']))){
  $tanggal_err='Tanggal masih kosong';
 //mengecek panjang karakter apakah kurang atau lebih dari 10 karakter atau tidak
 }elseif(strlen($_POST['tgllahir'])!=10){
  $tanggal_err='Format penulisan tanggal lahir salah';
 //memanggil fungsi untuk mengecek format penulisan apakah itu karakter angka dan mengandung karakter dash atau tidak
 }elseif(CekTLS_tanggal($_POST['tgllahir'])){
  $tanggal_err='Format penulisan tanggal lahir salah. Harus Tahun-Bln-Tgl';
 
 }
 else{
  //memanggil fungsi untuk melakukan validasi terhadap nilai - nilai tanggal yang diinputkan
  if(!BCA_tanggal($_POST['tgllahir'])):
   $tanggal_err='Format penulisan tanggal salah. Contoh harusnya 2000-07-30';
  else:
   $tanggal=htmlspecialchars($_POST['tgllahir']);
  endif;
 }
 if(empty($tanggal_err)){
   echo ''.$tanggal.' format penulisan tanggal lahir benar<br>';
   var_dump($tanggal);
 }

/* https://www.akutans193.co.id/2020/01/tutorial-validasi-penulisan-format.html*/
/*}*/

?>

<script>
  $( function() {
    $( "#tgllahir" ).datepicker({                  
        minDate: moment().add('d', 1).toDate(),
    });
  } );
  </script>



 


              <!-- /form input mask -->

              <!-- form color picker -->
            
  <script type="text/javascript">
  function runScript(e) {
    //See notes about 'which' and 'key'
    if (e.keyCode == 13) {
        var tb = document.getElementById("scriptBox");
        eval(tb.value);
        return false;
    }
}


function (event) {
    if (event.which == 13 || event.keyCode == 13) {
        //code to execute here
        return false;
    }
    return true;
};
</script>                     


    
  </body>
</html>
 