<?php
	header("Content-type: application/vnd-ms-excel");
	header("Content-Disposition: attachment; filename=Data Pemenang.xls");
	?>
<?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");
    }
?>
<!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="assets/img/favicon.webp" rel="icon">
  <link href="assets/img/apple-touch-icon.webp" 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>
<table class="table table-borderless datatable">
            <thead>
              <tr>
                <th scope="col">#</th>
                <th scope="col">Kode</th>
                <th scope="col">Nama</th>
				<th scope="col">User Game</th>
                <th scope="col">WhatsApp</th>
                <th scope="col">Voucher</th>
                <th scope="col">Hadiah</th>
                <th scope="col">Tanggal</th>
              </tr>
            </thead>
            <tbody>
              <?php
                $no = 1;
                $qry_pemenang = mysqli_query($koneksi, "SELECT * FROM pemenang");
                while ($dt_pemenang = mysqli_fetch_array($qry_pemenang)) {
                  $id_pemenang = $dt_pemenang['id_pemenang'];
                  $kode_pemenang = $dt_pemenang['kode_pemenang'];
                  $nama_pemenang = $dt_pemenang['nama_pemenang'];
				  $user_game = $dt_pemenang['user_game'];
                  $whatsapp_pemenang = $dt_pemenang['whatsapp_pemenang'];
                  $id_voucher_pemenang = $dt_pemenang['id_voucher_pemenang'];
                  $id_hadiah_pemenang = $dt_pemenang['id_hadiah_pemenang'];
                  $tanggal_pemenang = $dt_pemenang['tanggal_pemenang'];
                  $status_pemenang = $dt_pemenang['status_pemenang'];

                  $qry_voucher = mysqli_query($koneksi, "SELECT * FROM voucher WHERE id_voucher = '$id_voucher_pemenang'");
                  $dt_voucher = mysqli_fetch_array($qry_voucher);
                  $kode_voucher = $dt_voucher['kode_voucher'];

                  $qry_hadiah = mysqli_query($koneksi, "SELECT * FROM hadiah WHERE id_hadiah = '$id_hadiah_pemenang'");
                  $dt_hadiah = mysqli_fetch_array($qry_hadiah);
                  $nama_hadiah = $dt_hadiah['nama_hadiah'];
              ?>
              <tr>
                <th><?php echo $no++; ?></th>
                <td><?php echo $kode_pemenang; ?></td>
                <td><?php echo $nama_pemenang; ?></td>
				<td><?php echo $user_game; ?></td>
                <td><?php echo $whatsapp_pemenang; ?></td>
                <td><?php echo $kode_voucher; ?></td>
                <td><?php echo $nama_hadiah; ?></td>
                <td><?php echo $tanggal_pemenang; ?></td>
              </tr>
              <?php } ?>
            </tbody>
          </table>