<?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_video1/aksi_video1.php";

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

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

      <h2>video1</h2>
            <p><input type=\"button\" value=\"Tambah video1\" onclick=window.location.href=\"?module=video1&act=tambahvideo1\" class=\"btn btn-sm btn-primary\"></p>
        
        <table class=\"table\">
          <thead>
          <tr><th>No</th><th>Gambar</th><th>Judul</th><th>Aksi</th></tr>
          </thead>
            <tbody>"; 
            
      $query  = "SELECT * FROM video1 ORDER BY id_video1 DESC";
      $tampil = mysqli_query($konek, $query);
                  
      $no = 1;
      while ($r=mysqli_fetch_array($tampil)){
        echo "<tr style=\"border-color:#6C7293\">
             <td>$no</td>         
             <td align=\"center\"><img src=\"../foto_video/$r[gambar]\" width=\"200\"></td>
             <td>$r[judul_video1]</td>
             <td><a href=\"?module=video1&act=editvideo1&id=$r[id_video1]\" class=\"btn btn-sm btn-primary\">Edit</a> | 
                 <a href=\"$aksi?module=video1&act=hapus&id=$r[id_video1]\" class=\"btn btn-sm btn-primary\">Hapus</a></td>
             </tr>";
        $no++;
      }
      echo "</tbody>
        </table>


        </div></div>";
    break;
  
    case "tambahvideo1":
      echo "<h2>Tambah video1</h2>
          <form method=\"POST\" enctype=\"multipart/form-data\" action=\"$aksi?module=video1&act=input\">



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

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

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

</div>
          </div>

<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=\"link_youtube\" class=\"form-control\" style=\"background-color: #fff;\">

</div>
          </div>

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

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

       <textarea name=\"deskripsi\" id=\"lokomedia\" name=\"deskripsi\" style=\"width: 800px; height: 250px; class=\"form-control\"\">
                                          </textarea>

</div>
          </div>






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

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

        <input type=\"file\" name=\"foto\" class=\"form-control bg-dark\">

</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 "editvideo1":
      $query = "SELECT * FROM video1 WHERE id_video1='$_GET[id]'";
      $hasil = mysqli_query($konek, $query);
      $r     = mysqli_fetch_array($hasil);

      echo "<h2>Edit video1</h2>
          <form method=\"POST\" enctype=\"multipart/form-data\" action=\"$aksi?module=video1&act=update\">
          <input type=\"hidden\" name=\"id\" value=\"$r[id_video1]\">




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

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

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

</div>
          </div>



<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=\"link_youtube\" class=\"form-control\" style=\"background-color: #fff;\" value=\"$r[link_youtube]\">

</div>
          </div>



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

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

        <textarea name=\"deskripsi\" id=\"lokomedia\" name=\"deskripsi\" style=\"width: 800px; height: 250px;\">$r[deskripsi]
                                          </textarea>

</div>
          </div>







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

          <div class=\"col-sm-10\" style=\"text-align: left !important;\">

        ";
          if ($r['gambar']!=''){
            echo "<img src=\"../foto_video/$r[gambar]\" width=\"200\">";  
          }
          else{
            echo "Belum ada gambar";
          }
          echo"

</div>
          </div>


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

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

        <input type=\"file\" name=\"foto\" class=\"form-control bg-dark\">
<label for=\"formFileLg\" class=\"form-control bg-dark\" style=\"text-align: left !important;\"> - Apabila gambar tidak diganti, dikosongkan saja.</label>
</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;  
  }
}    
?>
