<?php
include "koneksi.php";

date_default_timezone_set('Asia/Jakarta');

// SIMPAN DATA
if(isset($_POST['simpan'])){

$nama       = mysqli_real_escape_string($koneksi,$_POST['nama']);
$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,
barcode

)

VALUES
(

'$nama',

'$hp',

'$instansi',

'$aktivitas',

NOW(),

''

)
"
);

echo "

<script>

alert(
'Terima kasih sudah mengisi buku tamu'
);

window.location='buku_tamu.php';

</script>

";

}
?>

<?php include "template/header.php"; ?>

<div class="hold-transition sidebar-mini layout-fixed">

<div class="wrapper">

<?php include "template/h_menu.php"; ?>

<?php include "sidebar.php"; ?>


<div class="content-wrapper">

<section class="content-header">

<div class="container-fluid">

<div class="row mb-2">

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

<h1>

Buku Tamu

</h1>

</div>

</div>

</div>

</section>


<section class="content">

<div class="container-fluid">

<div class="row">
    <div class="col-md-12">

<div class="card">

<div class="card-header bg-success">

<h3 class="card-title">

Riwayat Pengunjung

</h3>

</div>

<div class="card-body">

<table
id="example1"
class="table table-bordered table-striped">

<thead>

<tr>

<th>No</th>

<th>Nama</th>

<th>Instansi</th>

<th>Aktivitas</th>

<th>Waktu</th>

</tr>

</thead>

<tbody>

<?php

$no=1;

$q=
mysqli_query(
$koneksi,
"
SELECT *
FROM buku_tamu
ORDER BY
id_tamu DESC
"
);

while(
$d=
mysqli_fetch_assoc($q)
){

?>

<tr>

<td>

<?= $no++ ?>

</td>

<td>

<?= htmlspecialchars($d['nama']) ?>

</td>

<td>

<?= htmlspecialchars($d['instansi']) ?>

</td>

<td>

<?= htmlspecialchars($d['aktivitas']) ?>

</td>

<td>

<?= date(
'd-m-Y H:i',
strtotime(
$d['waktu_kunjungan']
)
) ?>

</td>

</tr>

<?php } ?>

</tbody>

</table>

</div>

</div>

</div>

</div>

</div>

</section>

</div>

</div>

<?php include "template/footer.php"; ?>