<?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"> Falcı Yorumları Paneli </h5>
            <div class="table-responsive">
            <table class="table table-striped datatable">
              <thead>
                <tr>
                  <th scope="col"> Yorumcu Kullanıcı Adı </th>
                  <th scope="col"> Yorum </th>
                  <th scope="col"> Yorum Tarihi </th>
                  <th scope="col"> Düzenle </th>
                  <th scope="col"> Sil </th>
                </tr>
              </thead>
              <tbody>
                <?php
                $getir = mysqli_query($db, "SELECT * FROM yorumcu_yorumlari");
                while ($listele = mysqli_fetch_array($getir)) {
                  $yider = $listele["yorumcu_id"];
                  $ygetir = mysqli_query($db, "SELECT * FROM yorumcular WHERE id = '$yider'");
                  $ydetay = mysqli_fetch_array($ygetir);
                 ?>
                <tr>
                  <td><?php echo $ydetay["kadi"] ?></td>
                  <td><?php echo $listele["yorum"]; ?></td>
                  <td><?php echo $listele["tarih"]; ?></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> Düzenle</button></td>
                  <td><button onclick="yorumsil_<?php echo $listele["id"]; ?>()" type="button" class="btn btn-danger btnl-sm">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 modal-lg">
                    <div class="modal-content">
                      <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel"><?php echo $ydetay["kadi"]; ?> Yorumcuya Yapılan Yorumu Düzenleme Paneli </h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                      </div>
                      <div class="modal-body">
                        <form method="post">
                          <div class="form-group my-3">
                              <label for="exampleFormControlTextarea1"> Yapılan Yorum </label>
                              <textarea name="yorum" class="form-control" id="exampleFormControlTextarea1" rows="3"><?php echo $listele["yorum"]; ?></textarea>
                              <input name="yorumid" type="hidden" value="<?php echo $listele["id"]; ?>">
                            </div>
                            <button type="submit" name="paketislem" class="btn btn-primary">Uygula</button>
                          </form>
                      </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 yorumsil_<?php echo $listele["id"]; ?>() {
                    swal({
                  title: "Yorumu Silmek Üzeresiniz",
                  text: "Bu İşlem Geri Alınamaz Yorum Silinir.",
                  icon: "warning",
                  buttons: true,
                  dangerMode: true,
                })
                .then((willDelete) => {
                  if (willDelete) {
                    swal("Duyuru Silindi.", {
                      icon: "success",
                    });
                    window.location.href = "postlar/get.php?yorumsil=<?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){
  $yorumid = $_POST["yorumid"];
  $yorum = $_POST["yorum"];
  $guncelle = mysqli_query($db, "UPDATE yorumcu_yorumlari SET yorum = '$yorum' WHERE id = '$yorumid'");
  if ($guncelle) {
    echo '<script>swal("Başarılı", "Yorum Başarılı Bir Şekilde Düzenlendi", "success");setTimeout(function(){ window.location.assign("fyorumlar.php");}, 1500);</script>';
  }else {
    echo '<script>swal("Hata", "Beklenemdik Bir Hata Meydana Geldi Lütfen Tekrar Deneyin.", "error");</script>';
  }

}
 ?>
