
<?php 
    include 'header.php'; 

    $id  = $_GET['id'];
    
    $sql1 = mysqli_query($koneksi, "SELECT status FROM kdstatus WHERE id=$id ");
                list($status) = mysqli_fetch_array($sql1);    
?>              


<div class="container">
 <div class="my-2 border-bottom">
   <h2 class="fw-semibold fs-3"></h2>
 </div>
  <div class="row justify-content-center">
    <div class="col-lg-12">
        
        <?php 
        /////////////////////   ALERT   ////////////////////////
        if(isset($_GET['alert'])){
          if($_GET['alert'] == "sukses"){
            echo "<div class='alert alert-success'>Data anggota berhasil diganti!</div>";
          }
        }
        ?>
        
       <div class="card">
    <div class="card-header d-flex justify-content-between">
      <span class="card-title fw-semibold align-self-start mb">Daftar Anggota Status <?php echo $status ?> </span>
      <button type="button" class="btn btn-primary btn-sm align-self-end" data-bs-toggle="modal" data-bs-target="#exampleModal">
       <a href="kode_status.php?rw=<?php echo $rw ?>" class="btn btn-primary btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali</a> 
      </button>
    </div>
    <div class="card-body">
      <div class="table-responsive">
        <table class="table table-bordered table-striped" id="table-datatable">
          <thead>
            <tr>
              <th width="1%" class="text-center" style="text-align:left; font-size: 9pt; font-weight:normal;">No</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 9pt; font-weight:normal;">Foto</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 9pt; font-weight:normal;">NoAng</th>
              <th width="16%" class="text-center">NAMA</th>
              <th width="16%" class="text-center">Tanggal Lahir</th>
              <th width="21%" class="text-center">Alamat</th>
              <th width="10%" class="text-center">Kecamatan</th>
              <th width="10%" class="text-center">KTP</th>
              <th width="10%" class="text-center">KK</th>
              <th width="4%" class="text-center">Tanggal</th>
              <th width="12%" class="text-center">OPSI</th>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            if ($hari=='SEMUA') {
                $data = mysqli_query($koneksi,"SELECT * FROM anggota WHERE status='$id' ORDER BY angg_no DESC LIMIT 2000");
            } else {
                $data = mysqli_query($koneksi,"SELECT * FROM anggota WHERE status='$id' ORDER BY angg_no DESC LIMIT 1000");
            }
            
            while($d = mysqli_fetch_array($data)){
                $noang=$d['angg_no'] ;

                $sql2 = mysqli_query($koneksi, "SELECT count(pinj_angg_no) AS tno_pinj FROM pinjaman WHERE pinj_angg_no='$noang' ");
                list($tno_pinj) = mysqli_fetch_array($sql2);
                
                
                $sql4 = mysqli_query($koneksi, "SELECT count(m_angg_no) AS tno_angg FROM permohonan WHERE m_angg_no='$noang' ");
                list($tno_angg) = mysqli_fetch_array($sql4); 
                           
              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td>
                  <center>
                    <?php
                        $foto_diri  =$d['foto_diri'] ;
                        $angg_id    =$d['angg_id'] ;
                        $noang      =$d['angg_no'] ;
                    ?>
                    <a href="angg_kartu.php?id=<?php echo $angg_id ?>&no=<?php echo $noang ?>" data-placement='top' title='Lihat Detail & Foto <?php echo $d['angg_no'] ?> a/n <?php echo $d['nama']; ?>' >								    
                        <?php if($foto_diri == ""){ ?>
                          <img src="../gambar/user.png" style="width: 20px;height: auto">  
                        <?php }else{ ?>
                          <img src="../gambar/diri/<?php echo $foto_diri ?>" style="width: 20px;height: auto">
                        <?php } ?>                    
                    </a>                                   
                  </center>         
                </td>                 
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['angg_no'] ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['nama']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['tpt_tgl_lhr']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['alamat']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['kec']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['ktp']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['kk']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo date('d/m/Y', strtotime($d['tglmasuk'])); ?></td>
                <td>    
<!--                     <a data-toggle='tooltip' data-placement='top' title='Kartu Histori <?php echo $d['angg_no'] ?> a/n <?php echo $d['nama']; ?>' style='margin-right:3px' class="btn btn-primary btn-sm" href="angg_kartu.php?id=<?php echo $d['angg_id'] ?>&no=<?php echo $noang ?>"><i class="bi bi-person-square"></i></a>
                       -->
                <a data-toggle='tooltip' data-placement='top' title='Kirim WA Konfirmasi Data ke <?php echo $d['hp'] ?> a/n <?php echo $d['nama']; ?>' style='margin-right:3px' class="btn btn-info btn-sm" href="wa_konfir_data_cus.php?id=<?php echo $d['angg_id'] ?>&hp=<?php echo $d['hp'] ?>"><i class="bi bi-chat-left-text"></i></a>
                <a class="btn btn-warning btn-sm" title="Edit Data Customer <?php echo $d['nama'] ?>" data-bs-toggle="modal" data-bs-target="#edit_custom_<?php echo $d['angg_id'] ?>"><i class="bi bi-gear"></i></a>
                <?php if($tno_angg<=0) {;?>
                  <a onclick="return confirm('Yakin ingin hapus data No <?php echo $d['angg_no']; ?> a/n <?php echo $d['nama']; ?> - <?php echo $d['alamat']; ?> ?')" class="btn btn-danger btn-sm" href="angg_hapus.php?id=<?php echo $d['angg_id'] ?>&oleh=<?php echo $oleh ?>">
                    <i class="bi bi-trash"></i>
                  </a>
                <?php };?>  
                
<!---- FORM EDIT ANGGOTA  ---------->                  
                  <form action="angg_update_act.php" method="post">
                    <div class="modal fade" id="edit_custom_<?php echo $d['angg_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 Customer Id <?php echo $d['angg_id']; ?> NoCust <?php echo $d['angg_no']; ?></h1>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                          </div>
                          <div class="modal-body">
                            <div class="form-group">
                              <label><font color="#000fff">Kabupaten</font></label>
                              <input type="text" name="ekab" readonly="readonly" class="form-control" placeholder="Kabupaten .." value="<?php echo $d['kab']; ?>"
                            </div>                                    
                            <div class="form-group" style="width:100%">
                              <label><font color="#000fff">Nama Customer</font></label>
                              <input type="hidden" name="tkab" required="required" class="form-control" value="<?php echo $kab; ?>">
                              <input type="hidden" name="tkd_kab" required="required" class="form-control" value="<?php echo $id; ?>">
                              <input type="hidden" name="tkdc" required="required" class="form-control" value="<?php echo $kdc; ?>">
                              <input type="hidden" name="tid" required="required" class="form-control" value="<?php echo $d['angg_id']; ?>">
                              <input type="text" name="tnama" required="required" class="form-control" placeholder="Nama Anggota .." value="<?php echo $d['nama']; ?>" style="width:100%">
                            </div>
                            <div class="form-group">
                              <label><font color="#000fff">Alamat</font></label>
                              <input type="text" name="talamat" required="required" class="form-control" placeholder="Alamat .." value="<?php echo $d['alamat']; ?>"
                            </div>
            	<div class="form-group">
                    <label class="form-label"><font color="#000fff">Kecamatan </font><?php echo $d['kec']; ?> <font color='#ff0000'><i>(Pilih Kecamatan)</i></font color></label>
                    <select class="form-control" name="tkd_kec" required="required">
                      <option value="">- Pilih Kecamatan -</option>
                      <?php 
                      $kec = mysqli_query($koneksi,"select * from kdkecamatan WHERE kdkab='$id'");
                      while($rx = mysqli_fetch_array($kec)){
                        ?>
                        <option value="<?php echo $rx['kd'] ?>"><?php echo $rx['kd'] ?> - <?php echo $rx['kecamatan'] ?></option>
                        <?php 
                      }
                      ?>
                    </select>
            	</div>          
                      
                            <div class="form-group">
                              <label><font color="#000fff">Tempat Tgl Lahir</font></label>
                              <input type="text" name="ttempat" required="required" class="form-control" placeholder="tempat .." value="<?php echo $d['tpt_tgl_lhr']; ?>"
                            </div>
                            <div class="form-group">
                              <label><font color="#000fff">Umur (Th)</font></label>
                              <input type="text" name="tumur" required="required" class="form-control" placeholder="Umur .." value="<?php echo $d['umur']; ?>"
                            </div>                            
                            <div class="form-group">
                              <label><font color="#000fff">No. KTP</font></label>
                              <input type="text" minlength="16" maxlength = "16" name="tktp" required="required" class="form-control" placeholder="Nomor KTP .." value="<?php echo $d['ktp']; ?>"
                            </div>                
                        
                            <div class="form-group">
                              <label><font color="#000fff">No KK</font></label>
                              <input type="text" minlength="16" maxlength = "16" name="tkk" required="required" class="form-control" placeholder="Nomor KK .." value="<?php echo $d['kk']; ?>"
                            </div>                
                            <div class="form-group">
                              <label><font color="#000fff">Nama Suami/Istri/Orang Tua</font></label>
                              <input type="text" name="tsuami" required="required" class="form-control" value="<?php echo $d['suami']; ?>"
                            </div>              
                            <div class="form-group">
                              <label><font color="#000fff">Nama Tersebut sebagai </font></label>
                              <input type="text" name="tsebagai" required="required" class="form-control" value="<?php echo $d['sebagai']; ?>"
                            </div>                                          
                            <div class="form-group">
                              <label><font color="#000fff">Jenis Kelamin</font></label>
                              <input type="text" name="tjekel" required="required" class="form-control" value="<?php echo $d['jekel']; ?>"
                            </div>              
                            <div class="form-group">
                              <label><font color="#000fff">Pekerjaan</font></label>
                              <input type="text" name="tpekerjaan" required="required" class="form-control" value="<?php echo $d['pekerjaan']; ?>"
                            </div>              
                            <div class="form-group">
                              <label><font color="#000fff">Status Marital</font></label>
                              <input type="text" name="tmarital" required="required" class="form-control" value="<?php echo $d['marital']; ?>"
                            </div>                                          
                          </div>
                            <div class="form-group">
                              <label><font color="#000fff">Nomor HP Customer</font></label>
                              <input type="text" name="hp" required="required" class="form-control" value="<?php echo $d['hp']; ?>"
                            </div>
                            <div class="form-group">
                              <label><font color="#000fff">Nomor HP Kerabat Customer Untuk Konfirmasi</font></label>
                              <input type="text" name="hp_2" required="required" class="form-control" value="<?php echo $d['hp_2']; ?>"
                            </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>
                  </form>
<!---- FORM EDIT ANGGOTA  ---------->     
                </td>
              </tr>
              <?php 
            }
            ?>
          </tbody>
        </table>
      </div>
    </div>

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

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