<?php
session_start();
if (!isset($_SESSION["login"])) {
    header("Location: login.php");
    exit;
}
require 'header.php';
// query data mahasiswa berdasarkan id
$id = $_SESSION["akun"];
$mhs = query("SELECT * FROM user WHERE id= $id")[0];
$xx = $mhs["id"];
$jeniskeluhan = query("SELECT * FROM jeniskeluhan");
date_default_timezone_set('Asia/Jakarta');
$tanggal = date("l, d-m-Y h:i:s:a");

// cek apakah tombol subit sudah ditekan atau belum
if (isset($_POST["submit"])) {
    // ambil data dari tiap elemen dalam form

    //cek apakah data berhasil di ubah atau tidak
    if (tambahkeluhan($_POST) > 0) {
        echo "
            <script>
            alert('Keluhan berhasil dikirimkan!');
            document.location.href = 'User_DaftarKeluhan.php';
            </script>
            ";
    } else {
        echo "<script>
            alert('Gagal Mengirimkan keluhan!');
            document.location.href = 'UserDaftarKeluhan.php';
            </script>";
    }
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .ccc {
            float: right;
        }
    </style>
</head>

<body>
    <div class="container-sm">
        <form action="" method="POST" enctype="multipart/form-data">
            <input type="hidden" name="id_user" value="<?= $mhs["id"]; ?>">
            <input type="hidden" name="tanggal" id="tanggal" value="<?= $tanggal; ?>">
            <!-- membuat pilihan keluhan -->
            <div class="form-group row">
                <label for="jenis_k" class="col-sm-2 col-form-label">Lingkup Keluhan Anda</label>
                <div class="col-sm-10">
                    <select id="id_jenis" name="id_jenis" required>
                        <option id="id_jenis" name="id_jenis" value="">Lingkup Keluhan</option>
                        <?php foreach ($jeniskeluhan as $keluhan) : ?>
                            <option id="id_jenis" name="id_jenis" value="<?= $keluhan['id_jenis']; ?>"><?= $keluhan['jenis']; ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <!-- /membuat pilihan keluhan -->
            <div class="form-group row">
                <label for="subjek" class="col-sm-2 col-form-label">Subjek</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" name="subjek" id="subjek" required>
                </div>
            </div>
            <div class="form-group row">
                <label for="keluhan" class="col-sm-2 col-form-label">Keluhan</label>
                <div class="col-sm-10">
                    <textarea class="form-control" id="keluhan" name="keluhan" required cols="40" rows="30" required></textarea>
                </div>
            </div>
            <div class="form-group row">
                <label for="gambar1" class="col-sm-2 col-form-label">Masukkan gambar</label>
                <div class="col-sm-10">
                    :<input type="file" name="gambar1" id="gambar1">
                </div>
            </div>
            <div class="form-group row">
                <label for="gambar2" class="col-sm-2 col-form-label">Masukkan gambar</label>
                <div class="col-sm-10">
                    :<input type="file" name="gambar2" id="gambar2">
                </div>
            </div>
            <div class="form-group row">
                <div class="col-sm">
                    <button type="submit" class="btn btn-primary ccc" name="submit">Submit</button>
                </div>
            </div>
        </form>
    </div>
</body>
<?php
require 'footer.php';
?>

</html>