<?php
include "koneksi.php";

date_default_timezone_set('Asia/Jakarta');

if(isset($_POST['simpan'])){

    $nama = mysqli_real_escape_string(
        $koneksi,
        $_POST['nama']
    );

    $no_hp = mysqli_real_escape_string(
        $koneksi,
        $_POST['no_hp']
    );

    $instansi = mysqli_real_escape_string(
        $koneksi,
        $_POST['instansi']
    );

    $aktivitas = mysqli_real_escape_string(
        $koneksi,
        $_POST['aktivitas']
    );

    mysqli_query(
        $koneksi,
        "
        INSERT INTO buku_tamu
        (
            nama,
            no_hp,
            instansi,
            aktivitas,
            waktu_kunjungan
        )

        VALUES
        (
            '$nama',
            '$no_hp',
            '$instansi',
            '$aktivitas',
            NOW()
        )
        "
    );

    echo "
    <script>
        alert('Terima kasih sudah mengisi buku tamu');
        window.location='buku_tamu.php';
    </script>
    ";
}
?>

<!DOCTYPE html>
<html>
<head>

<meta charset="UTF-8">

<meta
name="viewport"
content="width=device-width, initial-scale=1">

<title>
Buku Tamu Perpustakaan
</title>

<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">

<style>

body{
    background: linear-gradient(
        135deg,
        #001F54,
        #1282A2
    );

    min-height:100vh;
}

.card{
    border:none;
    border-radius:20px;
    box-shadow:0 10px 25px rgba(0,0,0,0.2);
}

.logo{
    width:100px;
    margin-bottom:15px;
}

</style>

</head>

<body>

<div class="container">

    <div class="row justify-content-center">

        <div class="col-md-6">

            <br><br>

            <div class="card">

                <div class="card-body">

                    <div class="text-center">

                        <img
                        src="upload/logo_stikom.jpg"
                        class="logo">

                        <h2>
                            Buku Tamu Perpustakaan
                        </h2>

                        <p class="text-muted">
                            Silakan isi data kunjungan terlebih dahulu
                        </p>

                    </div>

                    <hr>

                    <form method="POST">

                        <label>Nama</label>

                        <input
                        type="text"
                        name="nama"
                        class="form-control"
                        required>

                        <br>

                        <label>No HP</label>

                        <input
                        type="text"
                        name="no_hp"
                        class="form-control"
                        required>

                        <br>

                        <label>Instansi</label>

                        <input
                        type="text"
                        name="instansi"
                        class="form-control">

                        <br>

                        <label>Aktivitas</label>

                        <select
                        name="aktivitas"
                        class="form-control">

                            <option>Membaca Buku</option>

                            <option>Meminjam Buku</option>

                            <option>Mengembalikan Buku</option>

                            <option>Referensi</option>

                        </select>

                        <br>

                        <button
                        class="btn btn-primary btn-block"
                        name="simpan">

                            Kirim

                        </button>

                    </form>

                    <hr>

                    <div class="text-center">

                        <p>
                            Scan QR Code untuk akses katalog buku
                        </p>

                        <img
                        src="upload/qr_bukutamu.jpg"
                        width="150">

                    </div>

                </div>
                </div>

        </div>

    </div>

</div>

</body>
</html>