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

require_once(dirname(__FILE__) . '\header.php');

// ambil id data di URL
$id = $_GET["id_keluhan"];

// query data mahasiswa berdasarkan id
$mhs = query("SELECT * FROM keluhan WHERE id_keluhan= $id")[0];

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

        .atas {
            background-color: red;
            color: white;
            height: 50px;
        }
    </style>
</head>

<body>
    <div class="container-sm">
        <form action="" method="POST" enctype="multipart/form-data">
            <!-- membuat pilihan keluhan -->
            <div class="atas">
                <h1><a style="float: left; margin-left:10px; "><?= $mhs["subjek"] ?></a></h1>
            </div>
            <div class="tengah">
                <?php
                $coba = $mhs['id_jenis'];
                $cobalagi = query("SELECT * FROM jeniskeluhan WHERE id_jenis = $coba")[0];
                ?>
                <a style="color: red"><b><?= $cobalagi['jenis']; ?></b></a> | <?= $mhs["tanggal"]; ?>
            </div>
            <div class="hampir_isi">
                <hr>
            </div>
            <div class="isi">
                <textarea class="form-control" id="keluhan" name="keluhan" required cols="40" rows="20" readonly><?= $mhs["keluhan"]; ?></textarea>
            </div>
            <div class="gambar">
                <?php
                // $gambar = $mhs['gambar1'] && $mhs['gambar2'] > 1;
                $gambar2 = $mhs['gambar1'] > 1;
                $gambar3 = $mhs['gambar2'] > 1;
                ?>

                <div class="container">
                    <div class="form-group row">
                        <?php if ($gambar2) : ?>
                            <img src="imgKeluhan/<?= $mhs['gambar1']; ?>" width="520" height="500" style="margin-left : 25px; margin-top: 20px;">
                        <?php endif; ?>
                        <?php if ($gambar3) : ?>
                            <img src="imgKeluhan/<?= $mhs['gambar2']; ?>" width="520" height="500" style="margin-left : 25px; margin-top: 20px;">
                    </div>
                    <br>
                </div>
            <?php endif; ?>
            </div>

            <div class="hampir_bawah">
                <hr color="red">
            </div>
            <div>
                <?php
                $status = $mhs["status"] == "sudah";
                ?>
                <?php if (!$status) : ?>
                    <a href="hapuskeluhanUser.php?id=<?php echo $mhs["id_keluhan"] ?>" class="btn btn-danger btn-lg active" role="button" aria-pressed="true" style="float : right; margin-right: 20px;" onclick="return confirm('yakin?');">Hapus</a>
                    <br><br><br><br>
                <?php endif; ?>
            </div>
            <?php
            $status = $mhs["status"] == 'sudah';
            if ($status) : ?>
                <?php
                $coba22 = $mhs['id_keluhan'];
                $cobalagi22 = query("SELECT * FROM jawaban WHERE id_keluhan = $coba22");
                ?>
                <div class="jawaban">
                    <?php foreach ($cobalagi22 as $row22) : ?>
                        <a style="color: red"><b>ADMINISTRATOR</b></a> | <?php echo $row22["tanggal_jawaban"]; ?>
                    <?php endforeach; ?>
                </div>
                <div>
                    <br>
                    <form action="" method="" enctype="">
                        <input type="hidden" name="id_keluhan" value="<?= $mhs["id_keluhan"]; ?>">
                        <input type="hidden" name="tanggal" id="tanggal" value="<?= $tanggal; ?>">
                        <input type="hidden" name="status" value="sudah">
                        <div class="jawaban">
                            <?php foreach ($cobalagi22 as $row22) : ?>
                                <textarea class="form-control" id="jawaban" name="jawaban" required cols="40" rows="20" readonly><?= $row22["jawaban"]; ?></textarea>
                            <?php endforeach; ?>

                        </div>
                        <div>
                            Terima kasih telah menghubungi kami, semoga sukses selalu.<br><br>

                            * Keluhan masuk yang sudah kami balas, tidak akan bisa kamu balas lagi.<br>
                            * Untuk kelanjutan permasalahan kamu, silahkan kirimkan keluhan baru.<br><br>

                            Salam Hangat~ ^^
                        </div>

                </div>
            <?php endif; ?>
        </form>
    </div>
</body>
<?php
require 'footer.php';
?>

</html>