<?php
session_start();
// 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{
  include "../../../config/koneksi.php";
  include "../../../config/library.php";

  $module = $_GET['module'];
  $act    = $_GET['act'];

  // Hapus menu
  if ($module=='menu' AND $act=='hapus'){
    $query = "DELETE FROM menu WHERE id_menu='$_GET[id]'";
    mysqli_query($konek, $query);
    header("location:../../media.php?module=".$module);
  }

  // Input menu
  elseif ($module=='menu' AND $act=='input'){
    $nama_menu = addslashes($_POST['nama_menu']);
    $link      = addslashes($_POST['link']);
    $hari = addslashes($_POST['hari']);
    $jam      = addslashes($_POST['jam']);
   

    $input = "INSERT INTO menu(nama_menu, 
                               link,
                               hari,
                               jam) 
                        VALUES('$nama_menu', 
                               '$link',
                               '$hari',
                               '$jam')";
    mysqli_query($konek, $input);

    header("location:../../media.php?module=".$module);
  } 

  // Update menu
  elseif ($module=='menu' AND $act=='update'){
    $id        = $_POST['id'];
     $nama_menu = addslashes($_POST['nama_menu']);
    $link      = addslashes($_POST['link']);
    $hari = addslashes($_POST['hari']);
    $jam      = addslashes($_POST['jam']);

    $update = "UPDATE menu SET nama_menu = '$nama_menu',
                               link      = '$link', 
                               hari     = '$hari', 
                               jam = '$jam'
                         WHERE id_menu   = '$id'";
    mysqli_query($konek, $update);
      
    header("location:../../media.php?module=".$module);
  }
}
?>
