<?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_album/aksi_album.php";

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

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


      <h2>Metode Pembayaran</h2>
          <p><input type=\"button\" value=\"Add Photo\" onclick=window.location.href=\"?module=album&act=tambahalbum\" class=\"btn btn-sm btn-primary\"></p>



          <table class=\"table\">
          <thead>
          <tr>
          <tr><th>No</th><th>Photo</th><th>Action</th></tr>
          </thead>
            <tbody>"; 
            
      $query  = "SELECT * FROM album ORDER BY id_album DESC";
      $tampil = mysqli_query($konek, $query);
 
      $no = 1;
      while ($r=mysqli_fetch_array($tampil)){
          
      $query1  = "SELECT * FROM berita WHERE id_berita=$r[id_berita]";
      $tampil1 = mysqli_query($konek, $query1);
      $r1=mysqli_fetch_array($tampil1);


        echo "<tr style=\"border-color:#6C7293\"><td>$no</td>             
                  <td><img src=\"../foto_album/$r[gambar]\" width=\"200\" ></td>
                 
                  
                  <td> 
                      <a href=\"$aksi?module=album&act=hapus&id=$r[id_album]\" class=\"btn btn-sm btn-primary\">Delete</a></td>
              </tr>";
        $no++;
      }
      echo "</tbody>
        </table>


</div>
</div>



        ";
    break;
  
    // Form Tambah Album
    case "tambahalbum":
      echo "



      <h2>Add Image</h2>
      <br/>
          <form method=\"POST\" enctype=\"multipart/form-data\" action=\"$aksi?module=album&act=input\">
        

          
         
          
          

          <div class=\"row mb-3\">
                                    <label for=\"inputEmail3\" class=\"col-sm-2 col-form-label\">Foto</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=\"Save\" class=\"btn btn-primary\">
                                <input type=\"button\" value=\"Cancel\" onclick=\"self.history.back()\" class=\"btn btn-primary\"></td></tr>
          </div>
        
          </form>

        ";
    break;
  
    // Form Edit Album  
    case "editalbum":
      $query = "SELECT * FROM album WHERE id_album='$_GET[id]'";
      $hasil = mysqli_query($konek, $query);
      $r     = mysqli_fetch_array($hasil);

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


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

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

      <select name=\"berita\" class=\"form-control\" style=\"background-color: #fff;\">";
           
          if ($r['id_berita']==0){
            echo "<option value=\"0\" selected>- Select Produk -</option>";
          }   

          $query2 = "SELECT * FROM berita ORDER BY id_berita DESC";
          $tampil = mysqli_query($konek, $query2);

          while($w=mysqli_fetch_array($tampil)){
            if ($r['id_berita']==$w['id_berita']){
              echo "<option value=\"$w[id_berita]\" selected>$w[judul]</option>";
            }
            else{
              echo "<option value=\"$w[id_berita]\">$w[judul]</option>";
            }
          }

      echo "</select>

</div>
          </div>


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

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

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

</div>
          </div>


 <div class=\"row mb-3\">
                                    <label for=\"inputEmail3\" class=\"col-sm-2 col-form-label\">Replace Image</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;\"> - If the image is not replaced, just leave it blank.</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=\"Cancel\" onclick=\"self.history.back()\" class=\"btn btn-primary\"></td></tr>
          </div>


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