<?php include 'header.php'; ?>
<?php 
include '../koneksi.php';
    session_start();
    $id = $_SESSION['id'];
    $query = mysqli_query($koneksi, "SELECT * FROM user WHERE user_id='$_SESSION[id]'") 
                                  or die('Ada kesalahan pada query tampil data user : '.mysqli_error($mysqli));
    $data  = mysqli_fetch_assoc($query);       
                $sql2 = mysqli_query($koneksi, "SELECT foto FROM karyawan_iden WHERE id=$data[id_kar] ");
                list($foto) = mysqli_fetch_array($sql2);   
?>

<div class="container">

  <div class="my-4 border-bottom">
    <h2 class="fw-semibold fs-3">Edit Profil Karyawan ID <?php echo $data['id_kar'];?> - ID User <?php echo $data['user_id'];?></h2>
  </div>

  <section class="content">
    <div class="row justify-content-center">
      <section class="col-lg-5">

        <?php 
        if(isset($_GET['alert'])){
          if($_GET['alert'] == "sukses"){
            echo "<div class='alert alert-success'>Profil berhasil diganti!</div>";
          }
        }
        if(isset($_GET['alert'])){
          if($_GET['alert'] == "ra_sukses"){
            echo "<div class='alert alert-success'>Profil ORA berhasil diganti!</div>";
          }
        }    
        if(isset($_GET['alert'])){
          if($_GET['alert'] == "kebesaren"){
            echo "<div class='alert alert-success'>Profil ORA berhasil diganti - kebesaren ukuran foto..!</div>";
          }
        }        
        ?>

        <div class="card card-info">

          <div class="card-header">
            <span class="card-title fw-semibold">Edit Profil ID No. <?php echo $data['user_id'];?></span>
          </div>
          <div class="card-body">
             
              <div class="form-group mb-2">
                <label class="form-label">Foto Profil</label>
                <div>
                    <center>
                    <?php if($foto == ""){ ?>
                      <img src="../gambar/user.png" style="width: 130px;height: auto">
                    <?php }else{ ?>
                      <img src="../gambar/karyawan/<?php echo $foto ?>" style="width: 230px;height: auto">
                    <?php } ?>
                    </center>
                </div>
              </div>
              
            <form action="a_user_profil_update.php" method="post">
              <div class="form-group mb-2">
                <input type="hidden" name="id" value="<?php echo $data['user_id']; ?>">
              </div> 
              <div class="form-group mb-2">
                <label class="form-label">Username</label>
                  <input type="text" class="form-control" name="username" autocomplete="off" value="<?php echo $data['user_username']; ?>" style="width:100%" required>
              </div>
              <div class="form-group mb-2">
                <label class="form-label">Nama</label>
                  <input type="text" class="form-control" name="nama" autocomplete="off" value="<?php echo $data['user_nama']; ?>" style="width:100%" required>
              </div>

                <div class="form-group mb-2">
                  <label class="form-label">Foto</label>
                  <input type="file" name="foto" class="form-control">
                  <p>Kosong Jika tidak ingin di ganti</p>
                </div>
              
                <div class="form-group mb-2">
                  <input type="submit" class="btn btn-primary" value="Simpan">
                </div>

            </form>
          </div>

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

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