<?php 
    session_start();
    include 'header.php'; 
    $kdk = $_GET['kdk'];
    $kab = $_GET['kab'];

    $tgl_ini=date('d-m-Y') ;
    $tgl_ini2=date('Y-m-d') ; 
    
    $oleh=$_SESSION['id_kar'];
    $kdc=$_SESSION['kdc'];
?>            
<div class="container">

  <div class="my-4 border-bottom">
    <h4 class="fw-semibold fs-4">Daftar Warga/Donatur
    </h4>  
  </div>
  <section class="content">
    <div class="row">
      <section class="col-lg-14">
        <div class="box box-info">
          <div class="box-header">
          <div class="box-body">
            <form method="get" action="">

            </form>
          </div>
        </div>
        
        <div class="box box-info">
          <div class="box-header">
            <h6 class="box-title"></h6>
          </div>
          <div class="box-body">
            <?php 
            if(isset($_GET['tanggal_s']) && isset($_GET['tanggal_d'])){
              $tgl_d = $_GET['tanggal_d'];
              $tgl_s = $_GET['tanggal_s'];
              
              $tgl_pertama    =strtotime("$tgl_d");
              $tgl_kemarin    =date('Y-m-d', strtotime("-1 day", $tgl_pertama));       
            } else { ;
                $tgl_d    = $tgl_awal;
                $tgl_s    = $_SESSION['tgl_sd'];
            }
              ?>

              <div class="row">
                <div class="col-lg-8">
                  <table class="table table-bordered">
                    <tr>
                      <th>Lanjutan </th>
                      <th>:</th>
                      <td>
                          <button type="button" class="btn btn-primary btn-sm align-self-end" data-bs-toggle="modal" data-bs-target="#exampleModal">
                          <i class="bi bi-plus-lg"></i> Tambah
                          </button>                               
                          <a href="index.php" class="btn btn-info btn-sm pull-right"><i class="bi bi-reply"></i> &nbsp; Kembali</a> 
                      </td>
                    </tr>                       
                  </table>
                </div>
              </div>

      <!-- Modal -->
      <form action="tugas_angg_tambah_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</h1>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
              </div>
              <div class="modal-body">
                  <?php
              // fungsi untuk membuat kode transaksi
                $sql1 = mysqli_query($koneksi, "SELECT right(angg_no,7) as kode3 FROM anggota ORDER BY angg_no DESC LIMIT 1");
                list($kode3) = mysqli_fetch_array($sql1);
              $count3 = mysqli_num_rows($sql1);

              if ($count3 <> 0) {
                  // mengambil data kode transaksi
                  $data_id3 = mysqli_fetch_assoc($sql1);
                  $kode3    = $kode3+1;
                  $no_angg  = $kode3 ;
              } else {
                  $no_angg = '1000001';
              } 
              ?>
<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>Kode</label>        
                    <input type="hidden" name="xkdc" required="required" class="form-control" value=<?php echo $kdc; ?> readonly required >
                    <input type="hidden" name="xoleh" required="required" class="form-control" value=<?php echo $oleh; ?> readonly required >
                    <input type="text" name="xnoang" class="form-control" value=<?php echo $no_angg; ?> readonly required >
                </div>                     
                <div class="form-group">
                  <label> <font color="#000fff">Nama</font></label>
                  <input type="text" name="xnama" required="required" class="form-control" placeholder="Isikan Nama ..">
                </div>
                <div class="form-group">
                  <label><font color="#000fff">Kampung atau Jalan </font></label>
                  <input type="text" name="xalamat" required="required" class="form-control" placeholder="Isikan nama Kampung atau Jalan ..">
                </div> 
            	<div class="form-group">
                    <label><font color="#000fff">RT </font></label>
                    <input type="text" minlength="2" maxlength="2" name="xrt" required="required" class="form-control" placeholder="Isikan RT misal 01 atau 10...">
            	</div>                         
            	<div class="form-group">
                    <label><font color="#000fff">RW </font></label>
                    <input type="text" minlength="2" maxlength="2" name="xrw" required="required" class="form-control" placeholder="Isikan RW misal 01 atau 10...">
            	</div>                                   
            	<div class="form-group">
                    <label><font color="#000fff">Kelurahan </font></label>
                    <input type="text" name="xkel" required="required" class="form-control" placeholder="Isikan Kelurahan ..">
            	</div> 
            	<div class="form-group">
                    <label><font color="#000fff">Kecamatan </font></label>
                    <input type="text" name="xkec" required="required" class="form-control" placeholder="Isikan Kecamatan ..">
            	</div> 
            	<div class="form-group">
                    <label><font color="#000fff">Kota / Kabupaten </font></label>
                    <input type="text" name="xkab" required="required" class="form-control" placeholder="Isikan Kab/Kota ..">
            	</div>             	
                <div class="form-group">
                  <label><font color="#000fff">Nomor HP</font></label>
                  <input type="text" name="xhp" required="required" class="form-control" placeholder="Isikan nomor HP ....">
                </div>
              </div>  
                </div>              
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
                <button type="submit" class="btn btn-primary">Simpan</button>
              </div>
            </div>
          </div>
        </div>
              <div class="table-responsive">
                <table class="table table-bordered table-striped" id="table-datatable">
          <thead>
            <tr>
              <th width="5%" class="text-center" style="text-align:left; font-size: 9pt; font-weight:normal;">No</th>
              <th width="5%" class="text-center" style="text-align:left; font-size: 9pt; font-weight:normal;">Foto</th>
              <th width="5%" class="text-center" style="text-align:left; font-size: 9pt; font-weight:normal;">NoAng</th>
              <th width="20%" class="text-center">NAMA</th>
              <th width="50%" class="text-center">Alamat</th>
              <th width="5%" class="text-center">No WA</th>
              <th width="5%" class="text-center">Edit</th>
              <th width="5%" class="text-center">Hapus</th>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM anggota WHERE tglmasuk>='$tgl_d' and tglmasuk<='$tgl_s' and hapus<>'HAPUS' ");
            while($d = mysqli_fetch_array($data)){
                $noang  =$d['angg_no'] ;
                $rt   =$d['rt'] ;
                $rw   =$d['rw'] ;
                $kerja   =$d['pekerjaan'] ;
                $usaha   =$d['usaha'] ;
                $jekel   =$d['jekel'] ;
                if ($jekel=='1') {
                    $lp='L' ;
                } else {
                    $lp='P';
                }
                //'.$d['kel'].' '.$d['kec'].' '.$d['kab'].'
                $alamat_lengkap=''.$d['alamat'].' '.$d['rt'].' '.$d['rw'].' ' ;
                $no_hp=$d['hp'] ;
                        $foto_diri  =$d['foto_diri'] ;
                        $angg_id    =$d['angg_id'] ;
                        $noang      =$d['angg_no'] ;

               $sql4 = mysqli_query($koneksi, "SELECT count(angg_no) AS t_ang_sim FROM anggota_trans WHERE angg_no='$noang' ");
                       list($t_ang_sim) = mysqli_fetch_array($sql4);
               $sql5 = mysqli_query($koneksi, "SELECT count(angg_no) AS t_ang_sim_ao FROM anggota_trans_ao WHERE angg_no='$noang' ");
                       list($t_ang_sim_ao) = mysqli_fetch_array($sql5);    
               $pernah_transaksi=$t_ang_sim_ao+$t_ang_sim ;           
              ?>
              <tr>
                <td style="text-align:center; font-size: 8pt; font-weight:normal;"><?php echo $no++; ?></td>
                <td>
                  <center>
                    <a href="angg_foto_diri.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: 8pt; font-weight:normal;"><a data-toggle='tooltip' data-placement='top' title='Lihat Kartu Anggota <?php echo $d['nama']; ?>' style='margin-right:3px' class="btn btn-warning btn-sm" href="tugas_angg_kartu.php?id=<?php echo $angg_id; ?>"><?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 $alamat_lengkap; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $no_hp; ?></td>
                <td>    
                <a class="btn btn-warning btn-sm" title="Edit Data Donatur <?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>
                </td>
                <td>
                <?php if($pernah_transaksi<=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="tugas_hapus_donatur.php?id=<?php echo $d['angg_id'] ?>&oleh=<?php echo $oleh ?>">
                    <i class="bi bi-trash"></i>
                  </a>
                <?php };?>

<!---- FORM EDIT ANGGOTA  ---------->  
                  <form action="tugas_angg_edit_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 Donatur 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 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">Nama Donatur</font></label>
                                  <input type="hidden" name="tid" required="required" class="form-control" value="<?php echo $d['angg_id']; ?>">
                                  <input type="text" name="qnama" 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="qalamat" required="required" class="form-control" placeholder="Alamat .." value="<?php echo $d['alamat']; ?>"
                                </div>
                            	<div class="form-group">
                                    <label><font color="#000fff">RT</font></label>
                                    <input type="text" minlength="2" maxlength="2" name="qrt" required="required" class="form-control" placeholder="Isikan RT .." value="<?php echo $d['rt']; ?>">
                            	</div>                         
                            	<div class="form-group">
                                    <label><font color="#000fff">RW</font></label>
                                    <input type="text" minlength="2" maxlength="2" name="qrw" required="required" class="form-control" placeholder="Isikan RW .."  value="<?php echo $d['rw']; ?>">
                            	</div>                                   
                                <div class="form-group">
                                  <label><font color="#000fff">Kelurahan </font></label>
                                  <input type="text" name="qkel" required="required" class="form-control" value="<?php echo $d['kel']; ?>"
                                </div>
                                <div class="form-group">
                                  <label><font color="#000fff">Kecamatan </font></label>
                                  <input type="text" name="qkec" required="required" class="form-control" value="<?php echo $d['kec']; ?>"
                                </div>
                                <div class="form-group">
                                  <label><font color="#000fff">Kota/Kab </font></label>
                                  <input type="text" name="qkab" required="required" class="form-control" value="<?php echo $d['kab']; ?>"
                                </div>                            
                                <div class="form-group">
                                  <label><font color="#000fff">Nomor HP </font></label>
                                  <input type="text" name="qhp" required="required" class="form-control" value="<?php echo $d['hp']; ?>"
                                </div>
                                </div>
                                </div>
                              <div class="modal-footer">
                                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
                                <button type="submit" class="btn btn-primary">Simpan</button>
                              </div>
                            </div>
                        
                        
                        </div>
                        </div>
                        </div>
                        </div>
            </div>
        </div>
    </div>
</form>
<!---- FORM EDIT ANGGOTA  ---------->     


                </td>
              </tr>
              <?php 
            }
            ?>
          </tbody>
        
        </table>
        
        
              </div>

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

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