<?php 
    session_start();
    include 'header.php'; 
    $kdc=$_SESSION['kdc'];
    $kdkanca = mysqli_query($koneksi,"select * from kdkanca where kd='$kdc'");
    $k = mysqli_fetch_assoc($kdkanca);
    
    //$kdpeng = mysqli_query($koneksi,"select * from kdpengurus");
    //$kp = mysqli_fetch_assoc($kdpeng);    
?>

<div class="container">

 <div class="my-4 border-bottom">
   <h2 class="fw-semibold fs-3"></h2>
 </div>

  <div class="row justify-content-center">
    <div class="col-lg-12">
       <?php 
        if(isset($_GET['alert'])){
          if($_GET['alert'] == "berhasil"){
            ?>
            <div class="alert alert-success">
              Para penandatangan laporan, telah diupdate!
            </div>
            <?php
          }
        }
        ?>
       <div class="card">
    <div class="card-header d-flex justify-content-between">
      <span class="card-title fw-semibold align-self-start mb">Data Tanda Tangan Laporan</span>
      <button type="button" class="btn btn-primary btn-sm align-self-end" data-bs-toggle="modal" data-bs-target="#exampleModal">
        <i class="bi bi-subtract"></i> Ganti/Edit
      </button>
    </div>
    <div class="card-body">


      <!-- Modal -->
      <form action="00_ttd_laporan_act.php" method="post">
        <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">
                <h1 class="modal-title fs-5" id="exampleModalLabel">Ganti / Edit</h1>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
              </div>
              <div class="modal-body">
<div style="background-color: <?php echo$_SESSION['warna_bag']; ?>; padding: 15px; border-radius: 15px; box-shadow: 0 0 15px <?php echo$_SESSION['warna_bag']; ?>;">                  
<div class="form-group"> 
  <label class="form-label">Nama Petugas Kasir</label> 
  <select class="form-control" name="kasir" required="required"> 
    <option value=""></option> 
    <?php 
    $kar = mysqli_query($koneksi,"select * from karyawan"); 
    while($rx = mysqli_fetch_array($kar)){ 
    ?> 
    <option value="<?php echo $rx['nama'] ?>" <?php if($rx['nama'] == $k['kasir']) echo 'selected'; ?>><?php echo $rx['nama'] ?></option> 
    <?php } ?> 
  </select> 
</div>

<div class="form-group"> 
  <label class="form-label">Pejabat TTD I</label> 
  <select class="form-control" name="ttd_1" required="required"> 
    <option value=""></option> 
    <?php 
    $kar4 = mysqli_query($koneksi,"select * from karyawan WHERE ket='PP' "); 
    while($rx4 = mysqli_fetch_array($kar4)){ 
    ?> 
    <option value="<?php echo $rx4['jab'] ?>" <?php if($rx4['jab'] == $k['ttd_1']) echo 'selected'; ?>> <?php echo $rx4['jab'] ?></option> 
    <?php } ?> 
  </select> 
</div> 
<div class="form-group"> 
  <label class="form-label">Pejabat TTD II</label> 
  <select class="form-control" name="ttd_2" required="required"> 
    <option value=""></option> 
    <?php 
    $kar5 = mysqli_query($koneksi,"select * from karyawan WHERE ket='PP' "); 
    while($rx5 = mysqli_fetch_array($kar5)){ 
    ?> 
    <option value="<?php echo $rx5['jab'] ?>" <?php if($rx5['jab'] == $k['ttd_2']) echo 'selected'; ?>> <?php echo $rx5['jab'] ?></option> 
    <?php } ?> 
  </select> 
</div>        
<div class="form-group"> 
  <label class="form-label">Pejabat TTD III</label> 
  <select class="form-control" name="ttd_3" required="required"> 
    <option value=""></option> 
    <?php 
    $kar6 = mysqli_query($koneksi,"select * from karyawan WHERE ket='PP' "); 
    while($rx6 = mysqli_fetch_array($kar6)){ 
    ?> 
    <option value="<?php echo $rx6['jab'] ?>" <?php if($rx6['jab'] == $k['ttd_3']) echo 'selected'; ?>> <?php echo $rx6['jab'] ?></option> 
    <?php } ?> 
  </select> 
</div>    
        	</div>  
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
                <button type="submit" class="btn btn-primary">Simpan</button>
              </div>
            </div>
          </div>
        </div>
        </div>
      </form>

      <div class="table-responsive">
        <table class="table table-bordered table-striped" id="table-datatable">
          <thead>
            <tr>
              <th width="1%" class="text-center">Kd</th>    
              <th width="5%" class="text-center">Nama</th>
              <th width="5%" class="text-center">Kasir</th>
              <th width="5%" class="text-center">Pertama</th>
              <th width="5%" class="text-center">Nama ke1</th>
              <th width="5%" class="text-center">Kedua</th>
              <th width="5%" class="text-center">Nama ke2</th>
              <th width="5%" class="text-center">Ketiga</th>
              <th width="5%" class="text-center">Nama ke3</th>              
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM kdkanca ORDER BY id ASC");
            while($d = mysqli_fetch_array($data)){
                $kdkanca = mysqli_query($koneksi,"select * from anggota where kd='$kdc'");
                $k = mysqli_fetch_assoc($kdkanca);
                
                $jbt1 = mysqli_query($koneksi,"select * from kdpengurus where nama='$d[ttd_1]'");
                $j1 = mysqli_fetch_assoc($jbt1);        
                
                $jbt2 = mysqli_query($koneksi,"select * from kdpengurus where nama='$d[ttd_2]'");
                $j2 = mysqli_fetch_assoc($jbt2); 
                
                $jbt3 = mysqli_query($koneksi,"select * from kdpengurus where nama='$d[ttd_3]'");
                $j3 = mysqli_fetch_assoc($jbt3);                 
              ?>
              <tr>
                <td><?php echo $d['kd']; ?></td>
                <td><?php echo $d['nama_singkat']; ?></td>
                <td><?php echo $d['kasir']; ?></td>
                <td><?php echo $d['ttd_1']; ?></td>
                <td><?php echo $d['nama_ttd_1']; ?></td>
                <td><?php echo $d['ttd_2']; ?></td>
                <td><?php echo $d['nama_ttd_2']; ?></td>
                <td><?php echo $d['ttd_3']; ?></td>
                <td><?php echo $d['nama_ttd_3']; ?></td>                
              </tr>
              <?php 
            }
            ?>
          </tbody>
        </table>
      </div>
    </div>
    
  </div>
    </div>
  </div>
</div>
<?php include 'footer.php'; ?>