<?php
// Apabila user belum login
if (empty($_SESSION['namauser']) AND empty($_SESSION['passuser'])){
  echo "<link href=\"../../css/style_login.css\" rel=\"stylesheet\" type=\"text/css\" />
        <div id=\"login\"><h1 class=\"fail\">Untuk mengakses modul, Anda harus login dulu.</h1>
        <p class=\"fail\"><a href=\"../../index.php\">LOGIN</a></p></div>";  
}
// Apabila user sudah login dengan benar, maka terbentuklah session
else{
  $aksi = "modul/mod_polling/aksi_polling.php";

  // mengatasi variabel yang belum di definisikan (notice undefined index)
  $act = isset($_GET['act']) ? $_GET['act'] : ''; 

  switch($act){
    // Tampil Polling
    default:
      echo "
<div class=\"bg-secondary rounded h-100 p-4\">
<div class=\"table-responsive\">


      <h2>Video</h2>
          <p><input type=\"button\" value=\"Tambah Video\" onclick=window.location.href=\"?module=polling&act=tambahpolling\" class=\"btn btn-sm btn-primary\"></p>
          <table class=\"table\">
          <thead>
          <tr><th>Video</th><th>Aksi</th></tr>
          </thead>
            <tbody>";
            
      $query  = "SELECT * FROM polling ORDER BY id_polling DESC";
      $tampil = mysqli_query($konek, $query);
 
      $no = 1;
      while ($r=mysqli_fetch_array($tampil)){  
        echo "<tr style=\"border-color:#6C7293\">  
                  <td>


                  <iframe width=\"350\" height=\"215\" src=\"https://www.youtube.com/embed/$r[pilihan]\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen></iframe>


                  </td>
                  
                  <td><a href=\"?module=polling&act=editpolling&id=$r[id_polling]\" class=\"btn btn-sm btn-primary\">Edit</a> | 
                      <a href=\"$aksi?module=polling&act=hapus&id=$r[id_polling]\" class=\"btn btn-sm btn-primary\">Hapus</a></td>
              </tr>";
        $no++;
      }
      echo "</tbody>
        </table></div></div>";
    break;

    case "tambahpolling":
      echo "<h2>Tambah Video</h2>
          <form method=\"POST\" action=\"$aksi?module=polling&act=input\">

<div class=\"row mb-3\">
                                    <label for=\"inputEmail3\" class=\"col-sm-2 col-form-label\">Link Youtube</label>

          <div class=\"col-sm-10\">

        <input type=\"text\" name=\"pilihan\" class=\"form-control\" style=\"background-color: #fff;\">

</div>
          </div>


 <br/>
         
         <div style=\"text-align: center !important;\">
          <tr><td colspan=\"2\"><input type=\"submit\" value=\"Simpan\" class=\"btn btn-primary\">
                                <input type=\"button\" value=\"Batal\" onclick=\"self.history.back()\" class=\"btn btn-primary\"></td></tr>
          </div>

          
          </form>";
    break;
 
    case "editpolling":
      $query = "SELECT * FROM polling WHERE id_polling='$_GET[id]'";
      $hasil = mysqli_query($konek, $query);
      $r     = mysqli_fetch_array($hasil);

      echo "<h2>Edit Video</h2>
          <form method=\"POST\" action=\"$aksi?module=polling&act=update\">
          <input type=\"hidden\" name=\"id\" value=\"$r[id_polling]\">


<div class=\"row mb-3\">
                                    <label for=\"inputEmail3\" class=\"col-sm-2 col-form-label\">Link Youtube</label>

          <div class=\"col-sm-10\">

        <input type=\"text\" name=\"pilihan\" value=\"$r[pilihan]\" class=\"form-control\" style=\"background-color: #fff;\">

</div>
          </div>


<br/>
         
         <div style=\"text-align: center !important;\">
          <tr><td colspan=\"2\"><input type=\"submit\" value=\"Update\" class=\"btn btn-primary\">
                                <input type=\"button\" value=\"Batal\" onclick=\"self.history.back()\" class=\"btn btn-primary\"></td></tr>
          </div>



          
            </form>";
    break;  
  }
}
?>
