<?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_menu/aksi_menu.php";

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

  switch($act){  
    // Tampil Menu 
    default:
      echo "<h2>Menu Website</h2>
          
          <div class=\"table-responsive\">
          <table class=\"table text-start align-middle table-bordered table-hover mb-0\">
          <thead>
          <tr>
          <tr class=\"text-white\"><th>No</th><th>Nama Menu</th><th>Link</th><th>Aktif</th><th>Aksi</th></tr>
          </thead>
            <tbody>"; 
            
      $query  = "SELECT * FROM menu ORDER BY id_menu ASC";
      $tampil = mysqli_query($konek, $query);
 
      $no = 1;
      while ($r=mysqli_fetch_array($tampil)){
        echo "<tr><td>$no</td>             
                  <td>$r[nama_menu]</td>
                  <td>$r[link]</td>
                  <td>$r[aktif]</td>
                       
              <td><a href=\"?module=menu&act=editmenu&id=$r[id_menu]\" class=\"btn btn-sm btn-primary\">Edit</a></td></tr>";
        $no++;
      }
 
      echo "</tbody>
        </table></div>";
    break;

    // Form Tambah Menu
    case "tambahmenu":  
      echo "<h2>Tambah Menu</h1>
            <form method=\"POST\" action=\"$aksi?module=menu&act=input\">   
            <table class=\"table text-start align-middle table-bordered table-hover mb-0\">
            <tr class=\"text-white\"><td>Nama Menu  </td><td> <input type=\"text\" name=\"nama_menu\" class=\"form-control\" style=\"background-color: #fff;\"></td></tr>
            
            
         

<tr class=\"text-white\"><td>Keterangan</td><td>   <textarea name=\"keterangan\"  style=\"width: 100%; height: 350px;\"></textarea></td></tr>






            <tr class=\"text-white\"><td>Link       </td><td> <input type=\"text\" name=\"link\" class=\"form-control\" style=\"background-color: #fff;\"></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;

    // Form Edit Menu
    case "editmenu":
      $query = "SELECT * FROM menu WHERE id_menu='$_GET[id]'";
      $hasil = mysqli_query($konek, $query);
      $r     = mysqlI_fetch_array($hasil);
		  
      echo "<h2>Edit Menu Website</h1>
            <form method=\"POST\" action=\"$aksi?module=menu&act=update\">
            <input type=\"hidden\" name=\"id\" value=\"$r[id_menu]\">
            <table class=\"table text-start align-middle table-bordered table-hover mb-0\">
		        <tr class=\"text-white\"><td>Nama Menu</td><td> <input type=\"text\" name=\"nama_menu\" value=\"$r[nama_menu]\"  class=\"form-control\" style=\"background-color: #fff;\"></td></tr>
		        
		         
		        
		        <tr class=\"text-white\"><td>Keterangan</td><td> 
            <textarea  name=\"keterangan\" style=\"width: 100%; height: 350px;\">$r[keterangan]</textarea></td></tr>
		        
		        
		        
		        <tr class=\"text-white\"><td>Link      </td><td> <input type=\"text\" name=\"link\" value=\"$r[link]\"  class=\"form-control\" style=\"background-color: #fff;\"></td></tr>
            

            ";?>
            
      <tr class="text-white">
  <td>Status</td>
  <td>
    <select name="aktif" class="form-control" style="background-color:#fff;">
      <option value="Y" <?= ($r['aktif'] == 'Y') ? 'selected' : '' ?>>Aktif</option>
      <option value="N" <?= ($r['aktif'] == 'N') ? 'selected' : '' ?>>Non Aktif</option>
    </select>
  </td>
</tr>


            
            
            <?php
     
      						
      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;  
  }
}
?>
