<?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_halamanstatis/aksi_halamanstatis.php";

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

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

      <h2>Profil</h2>
        
        <table class=\"table\">
          <thead>
          <tr class=\"text-white\"><th>No</th><th>Judul</th><th>Aksi</th></tr>
          </thead>
            <tbody>";
            
      $query  = "SELECT * FROM halamanstatis ORDER BY id_halaman ASC";
      $tampil = mysqli_query($konek, $query);
 
      $no = 1;
      while ($r=mysqli_fetch_array($tampil)){  
        $tanggal = tgl_indo($r['tanggal']);
        echo "<tr><td>$no</td>
                  <td>$r[judul]</td>
                 
                  <td><a href=\"?module=halamanstatis&act=edithalamanstatis&id=$r[id_halaman]\" class=\"btn btn-sm btn-primary\">Edit</a></td>
              </tr>";
        $no++;
      }
      echo "</tbody>
        </table>
       
       </div></div>";
    break;

    case "tambahhalamanstatis":
      echo "<h2>Tambah Halaman Statis</h2>
            <form method=\"POST\" enctype=\"multipart/form-data\" action=\"$aksi?module=halamanstatis&act=input\">
            <table class=\"table text-start align-middle table-bordered table-hover mb-0\">
            <tr class=\"text-white\"><td>Judul</td>      <td> <input type=\"text\" name=\"judul\"></td></tr>
            <tr class=\"text-white\"><td>Isi Halaman</td><td>   <textarea name=\"isi_halaman\" id=\"lokomedia\" style=\"width: 800px; height: 350px;\"></textarea></td></tr>
            <tr class=\"text-white\"><td>Gambar     </td><td> <input type=\"file\" name=\"foto\" size=\"50\"><br> 
                                           - Tipe gambar harus JPG (disarankan lebar gambar 600 pixel).</td></tr>
            <tr><td colspan=\"2\"><input type=\"submit\" value=\"Simpan\" class=\"btn btn-sm btn-primary\">
                                 <input type=\"button\" value=\"Batal\" onclick=\"self.history.back()\" class=\"btn btn-sm btn-primary\"></td></tr>
            </table>
            </form>";
     break;
    
    case "edithalamanstatis":
      $query = "SELECT * FROM halamanstatis WHERE id_halaman='$_GET[id]'";
      $hasil = mysqli_query($konek, $query);
      $r     = mysqli_fetch_array($hasil);

      echo "<h2>Edit Profil</h2>
            <form method=\"POST\" enctype=\"multipart/form-data\" action=\"$aksi?module=halamanstatis&act=update\">
            <input type=\"hidden\" name=\"id\" value=\"$r[id_halaman]\">
            <table class=\"table text-start align-middle table-bordered table-hover mb-0\">
            <tr class=\"text-white\"><td>Judul      </td><td> <input type=\"text\" name=\"judul\" value=\"$r[judul]\"></td></tr>
            <tr class=\"text-white\"><td>Isi Halaman</td><td>   <textarea name=\"isi_halaman\" id=\"lokomedia\" style=\"width: 800px; height: 350px;\">$r[isi_halaman]</textarea>
            </td></tr>";
 if ($r['gambar']!=''){
            echo"
            <tr class=\"text-white\"><td>Gambar     </td><td> ";
            if ($r['gambar']!=''){
              echo "<img src=\"../foto_banner/$r[gambar]\" width=\"200\">";  
            }
            else{
              echo "Tidak ada gambar";
            }
      echo "</td></tr>
            <tr class=\"text-white\"><td>Ganti Gambar</td><td> <input type=\"file\" name=\"foto\" size=\"50\"><br>
                                            - Apabila gambar tidak diganti, dikosongkan saja.</td></tr>";
}
            else{
              echo "";
            }
             echo"                               
            <tr><td colspan=\"2\"><input type=\"submit\" value=\"Update\" class=\"btn btn-sm btn-primary\">
                                  <input type=\"button\" value=\"Batal\" onclick=\"self.history.back()\" class=\"btn btn-sm btn-primary\"></td></tr>
            </table>
            </form>";
    break;  
  }
}
?>
