<?php 
    include 'header.php'; 

    $level=$_SESSION['level'];
    $thn = date('Y');
    $bln = date('m');   
    $oleh=$_SESSION['id'];
    $kdc=$_SESSION['kdc'];
?>

<div class="container">

 <div class="my-4 border-bottom">
   <h2 class="fw-semibold fs-3">KARYAWAN & MANAGER</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 Karyawan & Manager (oleh : <?php echo $level; ?>)  </span>


    
    <?php if ($level='SUB') { ;?>
<!--
    <div>
      <button type="button" class="btn btn-danger btn-sm align-self-end" data-bs-toggle="modal" >
        <a href="b_karyawan_print.php?bln=<?php echo $bln; ?>&thn=<?php echo $thn; ?>" target="_blank" class="btn btn-warning btn-sm"><i class="bi bi-printer-fill"></i> &nbsp Cetak ke Printer</a>   
      </button>
    </div>    
    <div>
      <button type="button" class="btn btn-info btn-sm align-self-end" data-bs-toggle="modal" >
        <a href="b_karyawan_gaji.php" class="btn btn-secondary btn-sm"><i class="bi bi-amd"></i> &nbsp Edit Gaji dll</a>   
      </button>
    </div>
    <div>
      <button type="button" class="btn btn-primary btn-sm align-self-end" data-bs-toggle="modal">
        <a href="b_karyawan_data.php?bln=<?php echo $bln; ?>&thn=<?php echo $thn; ?>" class="btn btn-info btn-sm"><i class="bi bi-bag-heart-fill"></i> &nbsp Edit Data Lainnya</a>   
      </button>
    </div>    
-->
      <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 Karyawan 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">


      <!-- Modal -->
      <form action="b_karyawan_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">
                  <label>Nama Karyawan</label>
                  <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" >
                  <input type="text" name="nama" required="required" class="form-control" placeholder="Isi Nama ..">
                </div>
                <div class="form-group">
                  <label>Alamat</label>
                  <input type="text" name="alamat" required="required" class="form-control" placeholder="Isi alamate ..">
                </div>      
                <div class="form-group">
                  <label>Jabatan</label>
                  <input type="text" name="jabatan" required="required" class="form-control" placeholder="Isi jabatane ..">
                </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="12%" class="text-center">NAMA</th>
              <th width="28%" class="text-center">ALAMAT</th>
              <th width="15%" class="text-center">JABATAN</th>
              <th width="10%" class="text-center">NIK</th>
              <th width="1%" class="text-center">KDM</th>
              <th width="1%" class="text-center">ACC</th>
              <th width="1%" class="text-center">Kc</th>
              <th width="11%" 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 id 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);
              ?>
              <tr>
               <td><?php echo $no++; ?></td>
               <td>                    
                  <center>
                    <?php if($i['foto'] == ""){ ?>
                      <img src="../gambar/user.png" style="width: 30px;height: auto">  
                    <?php }else{ ?>
                        <a href="#" class="pop">								    
                           <img width="80" height="80" 
                        src="../gambar/karyawan/<?php echo $i['foto'] ?>" style="width: 30px;height: auto">
                        </a>             
                    <?php } ?>
                  </center>
               </td>                
                <td><?php echo $d['nama']; ?></td>
                <td align='left'><?php echo $d['alamat']; ?></td>
                <td align='left'><?php echo $d['jabatan']; ?></td>
                <td align='left'><?php echo $i['nip']; ?></td>
                <td align='left'><?php echo $d['jab']; ?></td>
                <td align='left'><?php echo $d['acc']; ?></td>                
<!--                <td><?php if($d['k_latitude'] != "" && $d['k_longitude'] != ""){ echo $d['k_latitude'] .", ". $d['k_longitude']; } ?></td>
-->
                <td align='left'><?php echo $d['kdc']; ?></td>
                <td>    
                    <a class="btn btn-warning btn-sm" href="b_karyawan_top_edit.php?id=<?php echo $d['id'] ?>"><i class="bi bi-gear"></i></a>                
                    <a class="btn btn-dark btn-sm" href="b_karyawan_detail.php?id=<?php echo $d['id'] ?>"><i class="bi bi-person-square"></i></a>
<!--                    
                    <a class="btn btn-success btn-sm" href="https://www.google.com/search?q=google+map+<?php echo $i['k_latitude'] ?>%2C+<?php echo $i['k_longitude'] ?>" target="_blank"><i class="bi bi-shop"></i></a>
-->                
                          <a onclick="return confirm('Yakin ingin hapus data <?php echo $d['nama']; ?>.....?')" class="btn btn-danger btn-sm" href="b_karyawan_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'; ?>