  <?php
  $kelas    = str_replace("'","`",(isset($_GET['kelas'])) ? $_GET['kelas'] : "");
  $qkelas=mysqli_query($connect,"select * from tb_kelas where id_kelas='".$kelas."'");
  $rkelas=mysqli_fetch_array($qkelas);
  ?>
  <div id="loader" class="loader" style="display:none;"></div>


    <br>
    <!--
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-12">
            <h5>Data Kategori Sentra</h5>
          </div>
        </div>
      </div>
    </div>
    -->
    

    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-12">
            <div class="card card-info">
              <div class="card-header" style="background:#eb5d99;color:white;">
                <form action="">
                <input type="hidden" name="prefix" value="datasiswa">
                <h3 class="card-title">Data Siswa - Kelas 
                    
                    <select name="kelas" style="cursor:pointer;padding:3px;" onchange="this.form.submit()">
                        <?php 
                        $qk=mysqli_query($connect,"select * from tb_kelas order by nama_kelas asc");
                        while($rk=mysqli_fetch_array($qk)){
                        ?>
                        <option value="<?php echo $rk['id_kelas'];?>" <?php if($kelas==$rk['id_kelas']){echo"Selected";}?>><?php echo $rk['nama_kelas'];?></option>
                        <?php }?>
                      </select>
                    

                </h3>
                </form>
                <button data-idkelas="<?php echo $rkelas['id_kelas'];?>" type="button" class="importsiswa btn btn-default btn-sm" style="margin-top:-5px;float:right;margin-left:10px;">
                  <i class="fas fa-file-excel"></i> &nbsp; Import Data
                </button>

                <button data-idkelas="<?php echo $rkelas['id_kelas'];?>" type="button" class="tambahsiswa btn btn-default btn-sm" style="margin-top:-5px;float:right;">
                  <i class="fas fa-plus-square"></i> &nbsp; Tambah Data
                </button>



              </div>
              <!-- /.card-header -->
              <div class="card-body table-responsive p-0">
                

                <form method="POST" id="form-delete" action="multiplehapussiswa">
                <input type="hidden" name="kelas" value="<?php echo $_GET['kelas'];?>">


                <table class="table table-striped table projects">
                  <thead>                  
                    <tr>
                      <th><input type="checkbox" id="cek_all" onclick="cek_semua()"></th>
                      <th width="5%" style="text-align:center;">No</th>
                      <th width="5%">Foto</th>
                      <th width="45%">Nama Siswa</th>
                      <th width="15%">Username</th>
                      <th width="15%">Password</th>
                      <th width="20%" style="text-align:right;">Pilihan</th>
                    </tr>
                  </thead>
                  <tbody>
                  <?php
                  $bilangan=1;
                  $q=mysqli_query($connect,"select * from tb_siswa where id_kelas='".$kelas."'")or die(mysqli_error($connect));
                  while($r=mysqli_fetch_array($q)){

                  ?>
                    
                    <tr>
                      <td>
                        <input type="checkbox" class="check_item" id="check_item" name="id_siswa[]" value="<?php echo $r['id_siswa'];?>">
                      </td>
                      <td align="center"><?php echo $bilangan++;?></td>
                      <td>
                        <img onerror="this.src='assets/img/ava.png'" alt="Foto" class="table-avatar" src="../assets/foto/<?php echo md5($r['id_siswa']);?>.jpg?p=<?php echo date('s');?>">
                      </td>
                      <td>
                        <?php echo $r['nama_lengkap'];?>
                      </td>

                      <td><?php echo $r['username'];?></td>
                      <td><?php echo $r['password'];?></td>
                      
                      <td style="text-align:right;">


                        <a data-id="<?php echo $r['id_siswa'];?>" class='editsiswa btn btn-info btn-sm' title="Edit Data" style="color:white;">
                            <i class="fas fa-edit"></i>
                        </a>


                        <a data-id="<?php echo $r['id_siswa'];?>" class='editpasswordsiswa btn btn-success btn-sm' title="Reset Password" style="color:white;">
                            <i class="fas fa-key"></i>
                        </a>



                        <a data-id="<?php echo $r['id_siswa'];?>" data-kelas="<?php echo $kelas;?>" class='hapussiswa btn btn-danger btn-sm' style="color:white;" data-toggle="tooltip" data-placement="top" title="Hapus Data Siswa">
                            <i class="fas fa-trash"></i>
                        </a>
                        
     


                      </td>

                    </tr>

                    <?php }?>
                  </tbody>
                </table>


              </div>


              <div class="card-footer clearfix" style="border-top:2px solid #dee2e6;">
                
                <a style="color:white;" class="btn btn-danger" onclick="klik_hapus()"><i class="fa fa-trash"></i> Hapus data terpilih</a>
                </form>
              </div>

            </div>
            <!-- /.card -->
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
      </div><!-- /.container-fluid -->
    </section>




        <div class="modal fade" id="tambahsiswa" role="dialog">
          <div class="modal-dialog modal-md">
           <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title">Tambah Siswa</h5>
              <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>
            <div class="modal-body" id="modal-body-tambah">
       
            </div>
           </div>
          </div>
         </div>


         <div class="modal fade" id="importsiswa" role="dialog">
          <div class="modal-dialog modal-md">
           <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title">Import Data Siswa</h5>
              <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>
            <div class="modal-body" id="modal-body-import">
       
            </div>
           </div>
          </div>
         </div>


         <div class="modal fade" id="editsiswa" role="dialog">
          <div class="modal-dialog modal-md">
           <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title">Edit Siswa</h5>
              <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>
            <div class="modal-body" id="modal-body-edit">
       
            </div>
           </div>
          </div>
         </div>


         <div class="modal fade" id="editpasswordsiswa" role="dialog">
          <div class="modal-dialog">
           <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title">Ganti Password Siswa</h5>
              <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>
            <div class="modal-body" id="modal-body-editpassword">
       
            </div>
           </div>
          </div>
         </div>


         <div class="modal fade" id="hapussiswa" role="dialog">
          <div class="modal-dialog">
           <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title">Hapus Siswa ?</h5>
              <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>
            <div class="modal-body" id="modal-body-hapus">
       
            </div>
           </div>
          </div>
         </div>




          <style>
          .loader {
          position: fixed;
          left: 0px;
          top: 0px;
          width: 100%;
          height: 100%;
          z-index: 9999;
          background: url('assets/img/loading.gif') 50% 50%   no-repeat;    
          }
          </style>

          <script src="assets/js/jquery.min.js"></script>
          <script src="assets/plugins/select2/js/select2.full.min.js"></script>
          <script type='text/javascript'>
                  function tutup(){
                      location.reload();
                  }


                  function cek_semua(){
                    if ($('#cek_all').is(":checked"))
                      $(".check_item").prop("checked", true); // ceklis semua checkbox siswa dengan class "check-item"
                    else
                      $(".check_item").prop("checked", false);
                  }
                  
                  function klik_hapus(){
                    var confirm = window.confirm("Apakah Anda yakin ingin menghapus data-data yang terpilih?"); // Buat sebuah alert konfirmasi
                  
                    if(confirm){ // Jika user mengklik tombol "Ok"
                      $("#form-delete").submit(); // Submit form
                    }
                  }
                  
                  $(document).ready(function(){
                      
                   
                      

                      // MODAL TAMBAH SISWA
                      $('.tambahsiswa').click(function(){

                          $(".loader").show();
                          var idkelas = $(this).data('idkelas');

                          // AJAX request
                          $.ajax({
                              url: 'ajax/admin/siswa/tambah.php',
                              type: 'post',
                              data: {
                                  idkelas: idkelas
                              },
                              success: function(response){ 

                                  $('#modal-body-tambah').html(response); 
                                  $('#tambahsiswa').modal('show'); 
                                  $(".loader").hide();
                              }
                          });
                      });



                      // MODAL TAMBAH SISWA
                      $('.importsiswa').click(function(){

                          $(".loader").show();
                          var idkelas = $(this).data('idkelas');

                          // AJAX request
                          $.ajax({
                              url: 'ajax/admin/siswa/import.php',
                              type: 'post',
                              data: {
                                  idkelas: idkelas
                              },
                              success: function(response){ 

                                  $('#modal-body-import').html(response); 
                                  $('#importsiswa').modal('show'); 
                                  $(".loader").hide();
                              }
                          });
                      });


                      // MODAL EDIT SISWA
                      $('.editsiswa').click(function(){

                          $(".loader").show();
                          var id = $(this).data('id');
                          // AJAX request
                          $.ajax({
                              url: 'ajax/admin/siswa/edit.php',
                              type: 'post',
                              data: {
                                  id: id
                              },
                              success: function(response){ 

                                  $('#modal-body-edit').html(response); 
                                  $('#editsiswa').modal('show'); 
                                  $(".loader").hide();
                              }
                          });
                      });


                      // MODAL EDIT PASSWORD GURU
                      $('.editpasswordsiswa').click(function(){

                          $(".loader").show();
                          var id = $(this).data('id');
                          // AJAX request
                          $.ajax({
                              url: 'ajax/admin/siswa/editpassword.php',
                              type: 'post',
                              data: {
                                  id: id
                              },
                              success: function(response){ 

                                  $('#modal-body-editpassword').html(response); 
                                  $('#editpasswordsiswa').modal('show'); 
                                  $(".loader").hide();
                              }
                          });
                      });



                      // MODAL HAPUS TEMA
                      $('.hapussiswa').click(function(){

                          $(".loader").show();
                          var id = $(this).data('id');
                          // AJAX request
                          $.ajax({
                              url: 'ajax/admin/siswa/hapus.php',
                              type: 'post',
                              data: {
                                  id: id
                              },
                              success: function(response){ 

                                  $('#modal-body-hapus').html(response); 
                                  $('#hapussiswa').modal('show'); 
                                  $(".loader").hide();
                              }
                          });
                      });






                  });
          </script>

