<?php 
    include 'header.php'; 

    $kd         =$_GET['kd'] ;
    $kdc        =$_SESSION['kdc'] ;
    
    $sql1 = mysqli_query($koneksi, "SELECT kelurahan,kecamatan,kota FROM kdkanca WHERE kd='$kdc' ");
                list($kelurahan,$kecamatan,$kota) = mysqli_fetch_array($sql1);
                
    $sql2 = mysqli_query($koneksi, "SELECT kd AS tkd FROM kdkecamatan WHERE kdkab='$kd' ORDER BY kd DESC limit 1 ");
                list($tkd) = mysqli_fetch_array($sql2);
    $no_kd= $tkd+1 ;           
?>

<div class="container">

 <div class="my-2 border-bottom">
   <h4 class="fw-semibold fs-4">Daftar Jenis Status Warga di Kel. <?php echo $kelurahan; ?>, Kec. <?php echo $kecamatan; ?>, Kab/Kota <?php echo $kota; ?></h4>
 </div>

  <div class="row justify-content-center">
    <div class="col-lg-6">
       <div class="card">

    <div class="card-header d-flex justify-content-between">
      <span class="card-title fw-semibold align-self-start mb"> </span>

      <button type="button" class="btn btn-success btn-sm align-self-end" data-bs-toggle="modal" data-bs-target="#exampleModal">
       <i class="bi bi-calendar-plus"></i> Tambah
      </button>        

        <a href="index.php" class="btn btn-primary btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali/Home</a> 
    </div>
    <div class="card-body">


      <!-- Modal -->
      <form action="kode_status_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">Tambah Data Status</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">
                            <div class="form-group" style="width:100%">
                              <label>Nama Jenis Status </label>
                              <input type="hidden" name="tid" required="required" class="form-control" value="<?php echo $kd; ?>">
                              <input type="text" name="tnama" required="required" class="form-control" placeholder="Nama Jenis Pekerjaan .." value="<?php echo $d['nama']; ?>" style="width:100%">
                            </div>
        	</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">No.</th>
              <th width="1%" class="text-center">KD</th>
              <th width="25%" class="text-center">Jenis Status</th>
              <th width="15%" class="text-center">Jumlah Angg</th>
              <th width="8%" class="text-center">Opsi</th>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            $tgl_skr= date('Y-m-d');
            $data = mysqli_query($koneksi,"SELECT * FROM kdstatus ORDER BY id ASC");
            while($k = mysqli_fetch_array($data)){
                $id_pek=$k['id'];

                $sql1 = mysqli_query($koneksi, "SELECT count(angg_no) AS tangg_no_1 FROM anggota WHERE status='$id_pek' and hapus<>'HAPUS' ");
                list($tangg_no_1) = mysqli_fetch_array($sql1);
              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td><?php echo $k['id']; ?></td>
                <td><?php echo $k['status']; ?></td>
                <td><?php echo "" . number_format("$tangg_no_1", 0, ",", "."); ?>
                  <?php if($tangg_no_1 >= 1) { ?>
                    <a data-toggle='tooltip' data-placement='top' title='Lihat Daftar Anggota <?php echo $k['status']; ?>' style='margin-right:3px' class="btn btn-info btn-sm" href="angg_rkp_adm_daftar_status.php?id=<?php echo $k['id']; ?>"><i class="bi bi-chat-left-text-fill">  Lihat Angg</i></a>
                  <?php } ?>
                </td> 
                <td>
                    <a class="btn btn-warning btn-sm" title="Edit Data <?php echo $d['status'] ?>" data-bs-toggle="modal" data-bs-target="#edit_status_<?php echo $k['id'] ?>"><i class="bi bi-gear"></i></a>
                    <?php if ($tangg_no_1+$tangg_no_2<=0) { ;?>
                          <a onclick="return confirm('Yakin ingin hapus jenis status <?php echo $k['status']; ?> id <?php echo $k['id']; ?> .....?')" class="btn btn-danger btn-sm" href="kode_status_hapus.php?id=<?php echo $k['id'] ?>">
                            <i class="bi bi-trash"></i>
                          </a>                        
                    <?php } ;?>
<!---- FORM EDIT ANGGOTA  ---------->                  
                  <form action="kode_status_edit_act.php" method="post">
                    <div class="modal fade" id="edit_status_<?php echo $k['id'];?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                      <div class="modal-dialog" role="document">
                        <div class="modal-content">
                          <div class="modal-header">
                            <h1 class="modal-title fs-5" id="exampleModalLabel">Edit Data <?php echo $k['status']; ?> Id <?php echo $k['id']; ?></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" style="width:100%">
                              <label><font color="#000fff">Jenis Status</font></label>
                              <input type="hidden" name="tid" required="required" class="form-control" value="<?php echo $k['id']; ?>">
                              <input type="text" name="tusaha" required="required" class="form-control" placeholder="Nama  .." value="<?php echo $k['status']; ?>" style="width:100%">
                            </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>
<!---- FORM EDIT ANGGOTA  ---------->                         
                </td>
              </tr>
              <?php 
            }
            ?>
          </tbody>
        </table>
      </div>
    </div>

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

</div>
<?php include 'footer.php'; ?>