<?php
session_start();
if (!isset($_SESSION["login"])) {
    header("Location: login.php");
    exit;
}
require 'header.php';

// ambil id data di URL
$id = $_SESSION["akun"];
$mhs = query("SELECT * FROM keluhan WHERE id_user = $id");
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Daftar keluhan</title>
    <style>
        .tulisan {
            color: black;
        }
    </style>
</head>

<body>
    <div class="container">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th scope="col">No.</th>
                    <th scope="col">Kategori</th>
                    <th scope="col">Subjek</th>
                    <th scope="col">Date</th>
                    <th scope="col">Status</th>
                    <th scope="col">Aksi</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <?php $i = 1 ?>
                    <?php foreach ($mhs as $row) : ?>
                        <?php
                        $coba = $row['id_jenis'];
                        $cobalagi = query("SELECT * FROM jeniskeluhan WHERE id_jenis = $coba");
                        ?>
                        <td><?php echo $i; ?></td>
                        <td>
                            <?php foreach ($cobalagi as $row33) : ?>
                                <?= $row33["jenis"]; ?>
                            <?php endforeach; ?>
                        </td>
                        <td>
                            <a href="User_Keluhan.php?id_keluhan=<?php echo $row["id_keluhan"] ?>" class="tulisan"><?= $row["subjek"]; ?></a>
                        </td>
                        <td>
                            <?= $row["tanggal"]; ?>
                        </td>
                        <td>
                            <?php
                            $status = $row["status"] == "sudah";
                            ?>
                            <?php if ($status) : ?>
                                <button type="button" class="btn btn-outline-success">ANSWERED</button>
                            <?php endif; ?>
                            <?php if (!$status) : ?>
                                <button type="button" class="btn btn-outline-danger">WAIT</button>
                            <?php endif; ?>
                        </td>
                        <td>
                            <?php
                            $status = $row["status"] == "sudah";
                            ?>
                            <?php if (!$status) : ?>
                                <a href="hapuskeluhanUser.php?id=<?php echo $row["id_keluhan"] ?>" onclick="return confirm('yakin?');">hapus</a>
                            <?php endif; ?>
                        </td>
                </tr>
                <?php $i++; ?>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <p align="center">
        Butuh bantuan? Silahkan kirim keluhan anda <a href="User_BuatKeluhan.php"> disini</a>
    </p>
</body>

<?php
require 'footer.php';
?>

</html>