<?php include 'header.php'; ?>

<div class="container">

 <div class="my-4 border-bottom">
   <h2 class="fw-semibold fs-3">USER OPERATOR</h2>
 </div>

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

    <div class="card-header d-flex justify-content-between">
      <span class="card-title fw-semibold align-self-start mb">Data Semua User</span>
      <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
      </button>
    </div>
    <div class="card-body">


      <!-- Modal -->
      <form action="a_user_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 User</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 class="form-label">Nama User <font color='#ff0000'><i>(Pilih dari Karyawan)</i></font color></label>
                <select class="form-control" name="xkar" required="required">
                  <option value="">- Pilih Karyawan -</option>
                  <?php 
                  $kar = mysqli_query($koneksi,"select * from karyawan");
                  while($rx = mysqli_fetch_array($kar)){
                    ?>
                    <option value="<?php echo $rx['id'] ?>"><?php echo $rx['id'] ?> - <?php echo $rx['angg_no'] ?> <?php echo $rx['nama'] ?> - <?php echo $rx['jabatan'] ?></option>
                    <?php 
                  }
                  ?>
                </select>
        	</div>                    
                <div class="form-group">
                  <label>Username</label>
                  <input type="text" name="xusername" required="required" class="form-control" placeholder="Isi Username-nya ..">
                </div>
                <div class="form-group">
                  <label>Password User</label>
                  <input type="password" name="xpassword" required="required" class="form-control" placeholder="Isi Password-nya ..">
                </div> 
        	<div class="form-group">
                <label class="form-label">User Level</label>
                <select class="form-control" name="xlevel" required="required">
                  <option value="">- Pilih Level -</option>
                  <?php 
                  $level = mysqli_query($koneksi,"select * from user_level");
                  while($l = mysqli_fetch_array($level)){
                    ?>
                    <option value="<?php echo $l['level_nama'] ?>"><?php echo $l['level_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">ID</th>
              <th width="5%" class="text-center">FOTO</th>
              <th width="25%" class="text-center">NAMA USER</th>
              <th width="10%" class="text-center">USERNAME</th>
              <th width="10%" class="text-center">LEVEL</th>
              <th width="5%" class="text-center">Kdc</th>
              <th width="5%" class="text-center">KDR</th>
              <th width="15%" class="text-center">Pasword Hash</th>
              <th width="1%" class="text-center">OPSI</th>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM user ORDER BY user_id ASC");
            while($d = mysqli_fetch_array($data)){
                $tkdr=$d['id_kar'];
                $hasil = substr($d['user_password_hash'], 5, 15);

                $sql2 = mysqli_query($koneksi, "SELECT foto AS nm_foto FROM karyawan_iden WHERE id='$tkdr'");
                list($nm_foto) = mysqli_fetch_array($sql2);   

                
                $iden = mysqli_query($koneksi,"select * from karyawan WHERE id='$tkdr'");
                $i = mysqli_fetch_assoc($iden);
                $angg = mysqli_query($koneksi,"select * from anggota where angg_no='$i[angg_no]'");
                $a = mysqli_fetch_assoc($angg);
                
                if ($i['ket']=='PP') { ;
                    $nm_kar=$a['nama'] ;
                } else {
                    $nm_kar=$i['nama'] ;
                }
  
                
                $jbt = mysqli_query($koneksi,"select * from kdpengurus where kd='$i[jabatan]'");
                $j = mysqli_fetch_assoc($jbt);            
                
              ?>
              <tr>
                <td align='center'><?php echo $d['user_id']; ?></td>
                <td>
                  <center>
                    <?php if($nm_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 $nm_foto ?>" style="width: 30px;height: auto">
                        </a>             
                    <?php } ?>
                  </center>      
                </td>       
                
                <td><?php echo $nm_kar; ?></td>
                <td><?php echo $d['user_username']; ?></td>
                <td><?php echo $d['user_level']; ?></td>
                <td align='center'><?php echo $d['kdc']; ?></td>
                <td align='center'><?php echo $d['user_kdr']; ?></td>
                <td align='center'><?php echo $hasil; ?></td>
                <td>    
                          <a onclick="return confirm('Yakin ingin hapus User <?php echo $d['user_nama']; ?>.....?')" class="btn btn-danger btn-sm" href="a_user_hapus.php?id=<?php echo $d['user_id'] ?>">
                            <i class="bi bi-trash"></i>
                          </a>

                </td>
              </tr>
              <?php 
            }
            ?>
          </tbody>
        </table>
      </div>
    </div>
    
  </div>
    </div>
  </div>
    <font color='#ff0000'><i>CATATAN : Tidak disediakan menu EDIT jika salah HAPUS SAJA kemudian buatkan lagi....; </i></font color>
</div>

<div class="modal fade" id="imagemodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">							   
    <div class="modal-content">         						      
     <div class="modal-body">
       <button type="button" class="close" data-dismiss="modal"><span 
       aria-hidden="true">&times;</span><span class="sr-only">tekan Esc </span></button>						        
      <img src="" class="imagepreview" style="width: 100%;">
     </div>							    
   </div>								   
  </div>
</div>


<?php include 'footer_ku.php'; ?>



<html>
<script>
   $(function() {
     $('.pop').on('click', function() {
       $('.imagepreview').attr('src',$(this).find('img').attr('src'));
       $('#imagemodal').modal('show');   
       });		
   });
</script>
</html>   