<?php
  session_start();
  $user=$_SESSION['username'];
  include 'database.php';
  $que = "SELECT * FROM tbl_userpa where nama_pa = '$user'";
  $result = mysqli_query($koneksi, $que);
  $query = "SELECT * FROM tb_perkara_pa where nama_pa = '$user' ORDER BY id DESC";
  $mysql = mysqli_query($koneksi, $query);
  while($data = mysqli_fetch_array($result))
      {
        $satker=$data['nama_satker'];
  ?>

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <link rel="stylesheet" href="style-homepage.css">
    <link rel="stylesheet" href="fontawesome/fontawesome-free-5.15.4-web/css/all.min.css">

    <title>HOMEPAGE | Simari KING</title>
  </head>
  <body>
<!-- navbar H-->
    <nav class="navbar navbar-expand-lg navbar-dark bg-success fixed-top" style="font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;">
        <div class="container">
          <a class="navbar-brand" href="#">SELAMAT DATANG ADMIN | <b style="font-size: 14px;"><?php echo $satker;?></b></a>
                <form class="d-flex">
                    <input class="form-control me-2" type="search" placeholder="Pencarian" aria-label="Search">
                    <button class="btn btn-outline-warning" type="submit">CARI</button>
                </form>

                <div class="icon ms-auto">
                    <h5>
                        <i class="fas fa-envelope me-2" data-toggle="tooltip" title="Pesan Masuk"></i>
                        <i class="fas fa-bell me-2" data-toggle="tooltip" title="Notifikasi"></i>
                        <i class="fas fa-sign-out-alt me-2" data-toggle="tooltip" title="Keluar"></i>
                    </h5>
                </div>
            </div>
      </nav>
<!-- end navbar H-->

<!-- nav vertikal -->
<div class="container">
    <div class="row no-gutters mt-5">
        <div class="row-md-2 bg-dark mt-2" style="width: 16rem; height: 100%;">
            <ul class="nav flex-column pb-5 pt-4" style="font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;">
                <li class="nav-item">
                <a class="nav-link active text-light" aria-current="page" href="#"><i class="fas fa-tachometer-alt"></i> DASHBOARD</a><hr class="bg-warning">
                </li>
                <li class="nav-item">
                <a class="nav-link text-light" href="#"><i class="fas fa-balance-scale"></i> PERMOHONAN BANDING</a><hr class="bg-warning">
                </li>
                <li class="nav-item">
                <a class="nav-link text-light" href="#"><i class="far fa-calendar-alt"></i> MONITORING BANDING</a><hr class="bg-warning">
                </li>
                <li class="nav-item">
                <a class="nav-link text-light" href="#"><i class="fas fa-tools"></i> SETTING</a><hr class="bg-warning">
                </li>
                <li class="nav-item">
                <a class="nav-link text-danger" href="#"><i class="fas fa-sign-out-alt"></i> KELUAR</a><hr class="bg-warning">
                </li>
            </ul>
        </div>

        <div class="row-md-10 bg-light p-4" style="width: 55rem; height: 100%;">
        <h3><i class="fas fa-balance-scale"></i> PERMOHONAN BANDING</h3><hr>
          
        <div class="row pt-4 gx-4 gy-4">
          <!-- tabel -->
            <div id="employee_table">
            <table class="table table-striped table-hover table-bordered" style="font-size: 14px;">
              <thead>
                <tr class="bg-secondary text-center">
                  <th scope="col" width="3%">No</th>
                  <th scope="col" width="25%">Nomor Perkara</th>
                  <th scope="col" width="25%">Tanggal Pengajuan</th>
                  <th scope="col" width="25%">Tanggal Pengiriman</th>
                  <th scope="col" colspan="3" widht="30%">Aksi</th>
                </tr>
              </thead>        
                      <?php
                      while($row = mysqli_fetch_array($mysql))
                      {
                      ?>
              <tbody>
                <tr>
                  <th scope="row">1</th>
                  <td><?php echo $row["nomor_perkarapa"]; ?><br /><?php echo $row["jenis_perkarapa"]; ?></td>
                  <td><?php $format = date('d-F-Y', strtotime($row["tgl_pengajuan_banding"]));
                      echo $format;?><br>
                      <?php
                      include 'database.php';
                      $id=$row["id"];
                      $querypa = "SELECT * FROM tb_perkara_pa WHERE id = $id";
                      $resultpa = mysqli_query($koneksi, $querypa);
                      while($rowpa = mysqli_fetch_array($resultpa))
                      {
                      $date1=date('d F Y', strtotime($rowpa["tgl_pengajuan_banding"]));
                      $date2=date("d F Y");
                      $date3=$rowpa["tgl_kirim_berkaspa"];
                      $datetime1 = new DateTime($date1);
                      $datetime2 = new DateTime($date2);
                      $datetime3 = new DateTime($date3);
                      if ($date3==NULL){
                      $difference = $datetime1->diff($datetime2);
                      echo '<div style="color:#FF0000"> Proses Berjalan: '.$difference->days. ' Hari</div>';
                      }
                      else
                      {
                      $difference1 = $datetime1->diff($datetime3);
                      echo 'Proses Berakhir: ' .$difference1->days. ' Hari';
                      }
                      }
                      ?>
                  </td>
                  <td><?php
                      $kirim = $row["tgl_kirim_berkaspa"]; 
                      if($kirim <> "") {
                      $formatkirim = date('d-F-Y', strtotime($row["tgl_kirim_berkaspa"]));
                          echo $formatkirim;
                      }else{
                      echo '-';
                      }
                      ?>
                    </td>
                  <td><div class="text-center"><button name="view" id="<?php echo $row["id"]; ?>" class="btn btn-xs view_data"><i class="fas fa-eye text-info" data-toggle="tooltip" title="Lihat Data"></i></button></div></td>
                  <td><div class="text-center"><button name="edit" id="<?php echo $row["id"]; ?>" class="btn btn-xs edit_data"><i class="fas fa-edit text-succes" data-toggle="tooltip" title="Ubah Data"></i></button></div></td>
                  <td><div class="text-center"><button name="delete" id="<?php echo $row["id"]; ?>" class="btn btn-xs hapus_data"><i class="fas fa-trash-alt text-danger" data-toggle="tooltip" title="Hapus Data"></i></button></div></td>
                </tr>
              </tbody>
                      <?php
                      }
                      ?>
            </table>
            </div>
          <!-- end tabel -->        
          </div>
        </div>
    </div>
</div>

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

  <!-- footer -->
  <div class="container-fluid text-center bg-success text-light fixed-bottom">
    <span style="font-size: 12px; font-style: italic;">Pengadilan Tinggi Agama Jambi &copy; ferdian_ITP (2021)</span>
  </div>
  <!-- end footer -->

  <!-- javascrip -->
  <script src="js/homepage.js" type="text/javascrip"></script>
<?php
      }
      ?>

  </body>
</html>


<div id="add_data_Modal" class="modal fade">
 <div class="modal-dialog">
  <div class="modal-content">
   <div class="modal-header">
    <button type="button" class="btn-close" data-bs-dismiss="modal">&times;</button>
    </div>
   <div class="modal-body">
    <form method="post" id="insert_form">
    <?php
	include 'database.php';
$user=$_SESSION['username'];
    $query1 = mysqli_query($koneksi,"select * from tbl_userpa where nama_pa = '$user'");
					while($data1 = mysqli_fetch_array($query1))
					{
					?>
     <label>Nama Pengadilan</label>
     <input type="text" name="nama_pa" id="nama_pa" class="form-control"  value="<?php echo $data1['nama_pa'];?>" readonly/>
     <label>Nomor Perkara </label>
     <input type="text" name="nomor_perkarapa" id="nomor_perkarapa" class="form-control" value="/Pdt.G/2021/<?php echo $data1['kode_perkara'];?>"/>
      <?php
	 }
	 ?>
     <label>Jenis Perkara</label>
     <input type="text" name="jenis_perkarapa" id="jenis_perkarapa" class="form-control" />   
     <label>Nama Pihak Pembanding</label>
     <input type="text" name="nama_pembanding" id="nama_pembanding" class="form-control" />
     <label>Nama Pihak Terbanding</label>
     <input type="text" name="nama_terbanding" id="nama_terbanding" class="form-control" /> 
     <label>Tanggal Putusan Tingkat Pertama</label>
     <input type="date" name="tgl_putusan" id="tgl_putusan" class="form-control" />
     <label>Tanggal Pengajuan Banding</label>
     <input type="date" name="tgl_pengajuan_banding" id="tgl_pengajuan_banding" class="form-control" />
      <label>File Surat Pengantar</label>
     <input type="text" name="suratpengantar" id="suratpengantar" class="form-control" placeholder="copy link google drive file Surat Pengantar"/>
     <label>File Checklist Berkas</label>
     <input type="text" name="ceklisberkas" id="ceklisberkas" class="form-control" placeholder="copy link google drive file Checklist Berkas"/>
     <label>File Bundel A</label>
     <input type="text" name="bundel_a" id="bundel_a" class="form-control" placeholder="copy link google drive file bundel A"/>
     <label>File Bundel B</label>
     <input type="text" name="bundel_b" id="bundel_b" class="form-control" placeholder="copy link google drive file bundel B"/>
     <label>File Word (File Putusan, File Memori Banding, File Kontra Memori Banding)</label>
     <input type="text" name="ceklis_bundel_b" id="ceklis_bundel_b" class="form-control" placeholder="copy link google drive file Word"/>
     <label>Tanggal Pengiriman Berkas Banding ke PTA</label>
     <input type="date" name="tgl_kirim_berkaspa" id="tgl_kirim_berkaspa" class="form-control" />
     <br />
     <input type="submit" name="insert" id="insert" value="Simpan Data Perkara" class="btn btn-success" />

    </form>
   </div>
   <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
   </div>
  </div>
 </div>
</div>

<div id="dataModal" class="modal fade">
 <div class="modal-dialog">
  <div class="modal-content">
   <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title">Detail Data Perkara</h4>
   </div>
   <div class="modal-body" id="detail_pegawai">
    
   </div>
   <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
   </div>
  </div>
 </div>
</div>


<div id="editModal" class="modal fade">
 <div class="modal-dialog">
  <div class="modal-content">
   <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title">Edit Data Perkaraa</h4>
   </div>
   <div class="modal-body" id="form_edit">
    
   </div>
   <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
   </div>
  </div>
 </div>
</div>

<script>  
$(document).ready(function(){
// Begin Aksi Insert
 $('#insert_form').on("submit", function(event){  
  event.preventDefault();  
  if($('#nomor_perkarapa').val() == "")  
  {  
   alert("Mohon Isi Nomor_Perkara");  
  }  
  else if($('#jenis_perkarapa').val() == '')  
  {  
   alert("Mohon Isi Jenis Perkara");  
  } 
   else if($('#nama_pembanding').val() == '')  
  {  
   alert("Mohon Isi Nama Pihak Pembanding");  
  } 
   else if($('#nama_terbanding').val() == '')  
  {  
   alert("Mohon Isi Nama Pihak Terbanding");  
  }  
 
  else  
  {  
   $.ajax({  
    url:"insert.php",  
    method:"POST",  
    data:$('#insert_form').serialize(),  
    beforeSend:function(){  
     $('#insert').val("Inserting");  
    },  
    success:function(data){  
     $('#insert_form')[0].reset();  
     $('#add_data_Modal').modal('hide');  
     $('#employee_table').html(data);  
    }  
   });  
  }  
 });
//END Aksi Insert

//Begin Tampil Detail Karyawan
 $(document).on('click', '.view_data', function(){
  var employee_id = $(this).attr("id");
  $.ajax({
   url:"select.php",
   method:"POST",
   data:{employee_id:employee_id},
   success:function(data){
    $('#detail_pegawai').html(data);
    $('#dataModal').modal('show');
   }
  });
 });
//End Tampil Detail Karyawan
 
//Begin Tampil Form Edit
  $(document).on('click', '.edit_data', function(){
  var employee_id = $(this).attr("id");
  $.ajax({
   url:"edit.php",
   method:"POST",
   data:{employee_id:employee_id},
   success:function(data){
    $('#form_edit').html(data);
    $('#editModal').modal('show');
   }
  });
 });
//End Tampil Form Edit

//Begin Aksi Delete Data
 $(document).on('click', '.hapus_data', function(){
  var employee_id = $(this).attr("id");
  $.ajax({
   url:"delete.php",
   method:"POST",
   data:{employee_id:employee_id},
   success:function(data){
   $('#employee_table').html(data);  
   }
  });
 });
}); 
//End Aksi Delete Data
 </script>