<?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">İletişim Mesajları</h5>
            <a href="iletisimbilgileri.php"><button type="button" class="btn btn-success">İletisim Bilgileri Düzenle</button></a>
            <div class="table-responsive">
            <table class="table table-striped datatable">
              <thead>
                <tr>
                  <th scope="col"> Ad Soyad </th>
                  <th scope="col"> E-Mail Adresi </th>
                  <th scope="col"> Konu </th>
                  <th scope="col"> Mesaj </th>
                  <th scope="col"> Oku </th>
                  <th scope="col"> Sil </th>
                </tr>
              </thead>
              <tbody>
                <?php
                $getir = mysqli_query($db, "SELECT * FROM iletisim ORDER BY id DESC");
                while ($listele = mysqli_fetch_array($getir)) {
                 ?>
                <tr>
                  <td><?php echo $listele["ad_soyad"] ?></td>
                  <td><?php echo $listele["email"]; ?></td>
                  <td><?php echo $listele["konu"]; ?></td>
                  <td><?php echo $listele["mesaj"]; ?></td>
                  <td><button type="button" class="btn btn-success btn-sm" data-bs-toggle="modal" data-bs-target="#exampleModal_<?php echo $listele["id"]; ?>"><i class="bi bi-gear"></i> OKU </button></td>
                  <td><button onclick="iletisimsil_<?php echo $listele["id"]; ?>()" type="button" class="btn btn-danger">Sil</button></td>
                </tr>
                <div class="modal fade" id="exampleModal_<?php echo $listele["id"]; ?>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
                  <div class="modal-dialog">
                    <div class="modal-content">
                      <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel"> İletişim Mesaj Paneli </h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                      </div>
                      <div class="modal-body">
                          <div class="row my-3">
                            <div class="col-lg-6">
                              <label class="form-label">Ad Soyad</label>
                              <input type="text" class="form-control" value="<?php echo $listele["ad_soyad"]; ?>" >
                            </div>
                            <div class="col-lg-6">
                              <label class="form-label">Konu</label>
                              <input type="text" class="form-control" value="<?php echo $listele["konu"]; ?>">
                            </div>
                          </div>
                          <div class="form-group">
                            <label for="exampleInputEmail1"> Mesaj </label>
                            <textarea type="text" class="form-control" rows="3"><?php echo $listele["mesaj"]; ?></textarea>
                          </div>
                      </div>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Pencereyi Kapat</button>
                      </div>
                    </div>
                  </div>
                </div>
                <script>
                function iletisimsil_<?php echo $listele["id"]; ?>() {
                    swal({
                  title: "İletişim Mesajını Silmek Üzeresiniz",
                  text: "Bu İşlem Geri Alınamaz Mesaj Silinir.",
                  icon: "warning",
                  buttons: true,
                  dangerMode: true,
                })
                .then((willDelete) => {
                  if (willDelete) {
                    swal("MEsaj Silindi.", {
                      icon: "success",
                    });
                    window.location.href = "postlar/get.php?iletisimsil=<?php echo $listele['id'] ?>";
                  } else {
                    swal("İşlem İptal Edildi.");
                  }
                });
                	}
                </script>
              <?php } ?>
              </tbody>
            </table>
          </div>
          </div>
        </div>
      </div>
    </div>
  </section>
</main>
<?php require 'footer.php'; ?>
<?php
if ($_POST) {
  $soru_baslik = $_POST["soru_baslik"];
  $soru_cevap = $_POST["soru_cevap"];
  $soruid = $_POST["soruid"];
  $duzenle = mysqli_query($db, "UPDATE sikcasorulan_sorular SET soru_baslik = '$soru_baslik', soru_cevap = '$soru_cevap' WHERE id = '$soruid'");
  if ($duzenle) {
    echo '<script>swal("Başarılı", "Soru Başarılı Bir Şekilde Düzenlendi", "success");setTimeout(function(){ window.location.assign("sksorular.php");}, 1500);</script>';
  }else {
    echo '<script>swal("Hata", "Beklenemdik Bir Hata Meydana Geldi Lütfen Tekrar Deneyin.", "error");</script>';
  }
}
 ?>
