<?php require 'ust.php'; ?>
<main id="main" class="main">
  <section class="section dashboard">
    <div class="row">
      <div class="col-12">
        <div class="card">
          <div class="card-body">
            <h5 class="card-title">Admin Profil Düzenleme Paneli</h5>
            <?php $adminid = $_SESSION['adminid']; $adminbilgileri = mysqli_fetch_array(mysqli_query($db, "SELECT * FROM admin WHERE id = '$adminid'")); ?>
            <form method="post">
            <div class="form-group">
              <label> Kullanıcı Adı </label>
              <input name="kadi" type="text" class="form-control" value="<?php echo $adminbilgileri["kadi"]; ?>" required>
            </div>
            <div class="form-group my-3">
              <label for="exampleInputPassword1">Şifreniz</label>
              <input name="sifre" type="password" class="form-control" required>
            </div>
            <button name="admindüzen" type="submit" class="btn btn-primary">Güncelle</button>
          </form>
          </div>
        </div>
      </div>
    </div>
  </section>
</main>
<?php require 'footer.php'; ?>
<?php
if(isset($_POST["admindüzen"])){

  $kadi = $_POST["kadi"];
  $sifre = md5(md5($_POST["sifre"]));
  $duzenle = mysqli_query($db, "UPDATE admin SET kadi = '$kadi', sifre = '$sifre' WHERE id = '$adminid'");
  if ($duzenle) {
    echo '<script>swal("Başarılı", "Admin Bilgileri Düzenlendi", "success");setTimeout(function(){ window.location.assign("adminprofil.php");}, 2000);</script>';
  }else {
    echo '<script>swal("Hata", "Beklenmedik Bir Sorun Meydana Geldi", "error");setTimeout(function(){ window.location.assign("adminprofil.php");}, 2000);</script>';
  }
}
 ?>
