<?php 
    session_start();
    include 'header.php'; 

    $level=$_SESSION['level'];
    $thn = date('Y');
    $bln = date('m');   
    $oleh=$_SESSION['id'];
    $kdc=$_SESSION['kdc'];
    
    $kanca = mysqli_query($koneksi,"select * from kdkanca where kd='$kdc'");
    $c = mysqli_fetch_assoc($kanca);  
    $tgl_dr=$c['tgl_dr']; 
    $tgl_sd=$c['tgl_sd'];
?>

<div class="container">

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

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

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


    
    <?php if ($level='TOP') { ;?>
      <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"></i> Tambah Pengurus Baru 
       <a href="javascript:history.go(-1)" class="btn btn-info btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali</a> 
      </button>        
    <?php } ;?>
    </div>
    <div class="card-body">

              <div class="row">
                <div class="col-lg-10">
                  <table class="table table-bordered">
                    <tr>
                      <th width="30%">PERIODE KEPENGURUSAN</th>
                      <th width="1%">:</th>
                      <td><?php echo date('d-m-Y', strtotime($tgl_dr)); ?> S/D <?php echo date('d-m-Y', strtotime($tgl_sd)); ?></td>
                    </tr>
                    <tr>
                      <th>Menu Lanjutan </th>
                      <th>:</th>
                      <td>
                      <a href="b_pengurus_print.php" target="_blank" class="btn btn-warning btn-sm"><i class="bi bi-printer"></i> &nbsp Print</a>
<!--                      <a href="b_pengurus_pdf.php" target="_blank" class="btn btn-info btn-sm"><i class="bi bi-file-earmark-pdf"></i> &nbsp Print PDF</a>
                      <a href="b_pengurus_excell.php" class="btn btn-success btn-sm"><i class="bi bi-file-word"></i> &nbsp Excell</a>
-->
                      </td>
                    </tr>   
                  </table>
                </div>
              </div>
              
      <!-- Modal -->
      <form action="b_pengurus_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 Karyawan</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">
                  <input type="hidden" name="oleh" value="<?php echo $oleh ?>" readonly="readonly" class="form-control" >
                  <input type="hidden" name="kdc" value="<?php echo $kdc ?>" readonly="readonly" class="form-control" >
                </div>                     
                        	<div class="form-group" style="width:100%">
                        	    <label class="form-label">Pilih Anggota <font color='#ff00ff'><i>(pilih anggota)</i></font color></label>
                                <?php
                                $query = mysqli_query($koneksi, "SELECT * FROM anggota Where hapus<>'HAPUS' order by angg_no ASC");
                                
                                // Membuat array untuk menyimpan data
                                $datax = array();
                                while ($row = mysqli_fetch_assoc($query)) {
                                  $datax[] = $row;
                                }
                                ?>
                                  <input class="form-control" type="text" name="tnoang" list="options">
                                  <datalist id="options">
                                    <?php foreach ($datax as $row) { ?>
                                      <option value="<?php echo $row['angg_no']; ?> - <?php echo $row['nama']; ?>"><?php echo $row['nama']; ?> - <?php echo $row['alamat']; ?></option>
                                    <?php } ?>
                                  </datalist>
        	                </div>                     

                        	<div class="form-group">
                                <label class="form-label">Jabatan <font color='#ff0000'><i>(pilih Jabatan)</i></font color></label>
                                <select class="form-control" name="kd_jab" required="required">
                                  <option value="">- Pilih Jabatan -</option>
                                  <?php 
                                  $kode_2 = mysqli_query($koneksi,"select * from kdpengurus order by kd ASC");
                                  while($k = mysqli_fetch_array($kode_2)){
                                    ?>
                                    <option value="<?php echo $k['kd'] ?>"><?php echo $k['kd'] ?> - <?php echo $k['nama'] ?></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">No</th>
              <th width="1%" class="text-center">Foto</th>
              <th width="20%" class="text-center">NAMA</th>
              <th width="35%" class="text-center">ALAMAT</th>
              <th width="15%" class="text-center">JABATAN</th>
              <th width="10%" class="text-center">OPSI</th>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM karyawan WHERE hapus<>'HAPUS' and ket='PP' ORDER BY jabatan ASC");
            while($d = mysqli_fetch_array($data)){
                $id=$d['id'];
                
                $gapok = mysqli_query($koneksi,"select * from karyawan_gapok where id='$id'");
                $g = mysqli_fetch_assoc($gapok);
                
                $iden = mysqli_query($koneksi,"select * from karyawan_iden where id='$id'");
                $i = mysqli_fetch_assoc($iden);
                
                $angg = mysqli_query($koneksi,"select * from anggota where angg_no='$d[angg_no]'");
                $a = mysqli_fetch_assoc($angg);  
                    $foto_diri=$a['foto_diri'];
                $jbt = mysqli_query($koneksi,"select * from kdpengurus where kd='$d[jabatan]'");
                $j = mysqli_fetch_assoc($jbt);              
                
                mysqli_query($koneksi, "update karyawan set nama='$a[nama]',alamat='$a[alamat]',jab='$j[nama]' where angg_no='$d[angg_no]'");
              ?>
              <tr>
               <td><?php echo $no++; ?></td>
                <td>
                  <center>
                    <a href="angg_foto_tampil.php?id=<?php echo $a['angg_id'] ?>&no=<?php echo $a['angg_no'] ?>" data-placement='top' title='Lihat Detail & Foto <?php echo $a['angg_no'] ?> a/n <?php echo $a['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><?php echo $a['nama']; ?></td>
                <td align='left'><?php echo $a['alamat']; ?>, RT <?php echo $a['rt']; ?>, RW <?php echo $a['rw']; ?>, Kel. <?php echo $c['kelurahan']; ?>, Kec. <?php echo $c['kecamatan']; ?>, <?php echo $c['kota']; ?></td>
                <td align='left'><?php echo $j['nama']; ?></td>
                <td>    
                    <a data-toggle='tooltip' data-placement='top' title='Lihat Kartu Anggota <?php echo $a['nama']; ?>' style='margin-right:3px' class="btn btn-warning btn-sm" href="angg_kartu.php?id=<?php echo $a['angg_id'] ?>"><?php echo $d['angg_no'] ?></a>
                          <a onclick="return confirm('Yakin ingin hapus data <?php echo $j['nama']; ?> <?php echo $a['nama']; ?>.....?')" class="btn btn-danger btn-sm" href="b_pengurus_hapus.php?id=<?php echo $d['id'] ?>">
                            <i class="bi bi-trash"></i>
                          </a>
              </tr>
              <?php 
            }
            ?>
          </tbody>
        </table>
        
        
        
      </div>
    </div>
  </div>
    </div>
  </div>
</div>
<?php include 'foot_ku.php'; ?>