<?php
include "koneksi.php";
include "time_ago.php";
include "random.php";
ob_start();
session_start();
if (isset($_SESSION['nama_pengguna_akun'])) {
  $nama_pengguna_akun_masuk = $_SESSION['nama_pengguna_akun'];
  $query_akun_masuk = mysqli_query($koneksi, "SELECT * FROM akun WHERE nama_pengguna_akun = '$nama_pengguna_akun_masuk'");
  $data_akun_masuk = mysqli_fetch_array($query_akun_masuk);
  $id_akun_masuk = $data_akun_masuk['id_akun'];
  $nama_akun_masuk = $data_akun_masuk['nama_akun'];
  $kata_sandi_akun_masuk = $data_akun_masuk['kata_sandi_akun'];
  $foto_akun_masuk = $data_akun_masuk['foto_akun'];
} else {
  header("location: masuk.php");
}
?>

<?php
include "koneksi.php";

// Cek apakah data ada di database
$qry_hadiah = mysqli_query($koneksi, "SELECT * FROM atur_situs WHERE id='1'")
  or die("Query Error: " . mysqli_error($koneksi));

$dt_bank = mysqli_fetch_array($qry_hadiah);

// Jika data tidak ditemukan, gunakan nilai default kosong
$nama_situs = $dt_bank['nama_situs'] ?? '';
$title_situs = $dt_bank['title_situs'] ?? '';
$meta_deskripsi = $dt_bank['meta_deskripsi'] ?? '';
$logo = $dt_bank['logo'] ?? '';
$favicon = $dt_bank['favicon'] ?? '';
$background_situs = $dt_bank['background_situs'] ?? ''; // Sesuai dengan tabel
$slider_banner = $dt_bank['slider_banner'] ?? '';
$link_daftar = $dt_bank['link_daftar'] ?? '';
$link_login = $dt_bank['link_login'] ?? '';
$link_klaim = $dt_bank['link_klaim'] ?? '';
?>

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>HALAMAN ADMIN</title>
  <meta content="" name="description">
  <meta content="" name="keywords">

  <!-- Favicons -->
  <link href="../img/<?php echo $favicon; ?>" rel="icon">
  <link href="../img/<?php echo $favicon; ?>" rel="apple-touch-icon">

  <!-- Google Fonts -->
  <link href="https://fonts.gstatic.com" rel="preconnect">
  <link
    href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i"
    rel="stylesheet">

  <!-- Vendor CSS Files -->
  <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
  <link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
  <link href="assets/vendor/quill/quill.snow.css" rel="stylesheet">
  <link href="assets/vendor/quill/quill.bubble.css" rel="stylesheet">
  <link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">
  <link href="assets/vendor/simple-datatables/style.css" rel="stylesheet">

  <!-- Template Main CSS File -->
  <link href="assets/css/style.css" rel="stylesheet">



</head>

<body>

  <!-- ======= Header ======= -->
  <header id="header" class="header fixed-top d-flex align-items-center">

    <div class="d-flex align-items-center justify-content-between">
      <a href="index.php" class="logo d-flex justify-content-center align-items-center">
        <img src="../img/<?php echo $logo; ?>" alt="Logo">
        <!--<span class="d-none d-lg-block">NiceAdmin</span>-->
      </a>
      <i class="bi bi-list toggle-sidebar-btn"></i>
    </div><!-- End Logo -->

    <nav class="header-nav ms-auto">
      <ul class="d-flex align-items-center">



        <li class="nav-item dropdown pe-3">

          <a class="nav-link nav-profile d-flex align-items-center pe-0" href="#" data-bs-toggle="dropdown">
            <img src="assets/img/<?php echo $foto_akun_masuk; ?>" alt="Profile" class="rounded-circle">
            <span class="d-none d-md-block dropdown-toggle ps-2"><?php echo $nama_akun_masuk; ?></span>
          </a><!-- End Profile Iamge Icon -->

          <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow profile">
            <li class="dropdown-header">
              <h6><?php echo $nama_akun_masuk; ?></h6>
              <span>Administrator</span>
            </li>
            <li>
              <hr class="dropdown-divider">
            </li>

            <li>
              <a class="dropdown-item d-flex align-items-center" href="index.php?page=akun">
                <i class="bi bi-person"></i>
                <span>Akun</span>
              </a>
            </li>
            <li>
              <hr class="dropdown-divider">
            </li>

            <li>
              <a class="dropdown-item d-flex align-items-center" href="keluar.php">
                <i class="bi bi-box-arrow-right"></i>
                <span>Keluar</span>
              </a>
            </li>

          </ul><!-- End Profile Dropdown Items -->
        </li><!-- End Profile Nav -->

      </ul>
    </nav><!-- End Icons Navigation -->

  </header><!-- End Header -->

  <?php
  include "sidebar.php";

  if (isset($_GET['page'])) {
    if ($_GET['page'] == "dashboard") {
      include_once "dashboard.php";
    } else if ($_GET['page'] == "hadiah") {
      include_once "hadiah.php";
    } else if ($_GET['page'] == "atur_slider") {
      include_once "atur_slider.php";
    } else if ($_GET['page'] == "pemenang") {
      include_once "pemenang.php";
    } else if ($_GET['page'] == "voucher") {
      include_once "voucher.php";
    } else if ($_GET['page'] == "edit_post") {
      include_once "edit_post.php";
    } else if ($_GET['page'] == "posting") {
      include_once "posting.php";
    } else if ($_GET['page'] == "aturspin") {
      include_once "aturspin.php";
    } else if ($_GET['page'] == "akun") {
      include_once "akun.php";
    } else if ($_GET['page'] == "tutorial") {
      include_once "tutorial.php";
    } else {
      include_once "dashboard.php";
    }
  } else {
    include_once "dashboard.php";
  }
  ?>

  <!-- ======= Footer ======= -->
  <footer id="footer" class="footer">
    <div class="copyright">
      &copy; Copyright <strong><span>WKS</span></strong>. All Rights Reserved
    </div>
  </footer><!-- End Footer -->
  <style>
    .cke_notification {
      display: none !important;
    }
  </style>
  <a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i
      class="bi bi-arrow-up-short"></i></a>

  <!-- Vendor JS Files -->
  <script src="../vendor/jquery/jquery-3.6.0.js"></script>
  <script src="assets/vendor/apexcharts/apexcharts.min.js"></script>
  <script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
  <script src="assets/vendor/chart.js/chart.min.js"></script>
  <script src="assets/vendor/echarts/echarts.min.js"></script>
  <script src="assets/vendor/quill/quill.min.js"></script>
  <script src="assets/vendor/simple-datatables/simple-datatables.js"></script>
  <script src="assets/vendor/tinymce/tinymce.min.js"></script>
  <script src="assets/vendor/php-email-form/validate.js"></script>




  <!-- Template Main JS File -->
  <script src="assets/js/main.js"></script>

  <script>
    function randomStringToInput(clicked_element) {
      var self = $(clicked_element);
      var random_string = generateRandomString2(10);
      $('input[name=kode_voucher]').val(random_string);
    }

    function generateRandomString2(string_length) {
      var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
      var string = '';

      for (var i = 0; i <= string_length; i++) {
        var rand = Math.round(Math.random() * (characters.length - 1));
        var character = characters.substr(rand, 1);
        string = string + character;
      }

      return string;
    }
  </script>




  <script src="https://cdn.tiny.cloud/1/no-api-key/tinymce/6/tinymce.min.js" referrerpolicy="origin"></script>
  <script>
    $('#tambah_data').on('shown.bs.modal', function () {
      tinymce.init({
        selector: '#editor_konten',
        menubar: false,
        plugins: 'advlist autolink lists link charmap print preview anchor',
        toolbar: 'bold italic underline | alignleft aligncenter alignright alignjustify',
        setup: function (editor) {
          editor.on('change', function () {
            editor.save();
          });
        }
      });
    });

    $('#tambah_data').on('hidden.bs.modal', function () {
      tinymce.remove('#editor_konten');
    });
  </script>


</body>

</html>