<?php
session_start();
require '../functions.php';
$user_id = $_SESSION['id'];
?>

<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- my font -->
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../testimoni/fontawesome/css/all.min.css">
    
    <link rel="stylesheet" href="testimoni.css">

    <title>Villahayati.</title>
</head>
<body>
<nav class="navbar navbar-expand-lg">
    <div class="container">
        <a class="navbar-brand"><span class="stay">Villa</span>hayati.</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
            <div class="navbar-nav ml-auto">
                <a class="nav-link" href="../detail/detail.php">Home</a>
                <a class="nav-link" href="../pemesanan/pemesanan.php">Pemesanan</a>
                <a class="nav-link" href="../aboutus/aboutUs.php">About us</a>
                <?php
                
                    // Query untuk mengecek apakah user memiliki testimoni yang belum ditambahkan
                    $query = "SELECT * FROM tb_booklog LEFT JOIN tb_testimoni ON tb_booklog.user_id = tb_testimoni.user_id WHERE tb_booklog.status_pembayaran = 'berhasil' AND (tb_testimoni.user_id IS NULL) AND tb_booklog.user_id = $user_id";
                    $result = mysqli_query($conn, $query);

                    // Jika hasil query tidak kosong, tampilkan tombol Tambah Testimoni
                    if (mysqli_num_rows($result) > 0) {
                        echo '<a class="nav-link" href="form-testimoni.php">Tambah Testimoni</a>';
                    }
                ?>
                <a class="nav-link" href="../login/login.php">Logout</a>
            </div>
        </div>
    </div>
</nav>

    <!-- end of nav -->
    
     <div class="testimonials">
        <div class="header">
            <h2>Testimonial Pelanggan</h2>
        </div>
        <div class="main">
            <div id="slider">
            <?php
				// Ambil data dari tabel testimoni
				$sql = "SELECT * FROM tb_booklog INNER join tb_testimoni ON tb_testimoni.user_id = tb_booklog.user_id";
				$result = $conn->query($sql);

				if ($result->num_rows > 0) {
					// Loop untuk setiap baris data
					while ($row = $result->fetch_assoc()) {
						$nama = $row['nama'];
						$komentar = $row['komentar'];
                        $tanggal_pesan = $row['tanggal_pesan'];
						$rating = "";
						for ($i = 1; $i <= 5; $i++) {
							if ($i <= $row['rating']) {
								$rating .= '<i class="fa fa-star" style ="color : orange"></i>'; // Menggunakan fontawesome untuk icon bintang
							} else {
								$rating .= '<i class="fa fa-star-o" style ="color : orange"></i>';
							}
						}

						// Tampilkan data dalam bentuk card
						echo "<div class='card'>
                        <div class='profile'>
                        <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIYAAACGCAMAAAAvpwKjAAAAMFBMVEXk5ueutLersbXKz9Hn6eq2u77c3+Cxt7qor7LW2dvg4uPq7O3AxcfR1Na5vsHIzM7SD8wbAAADHElEQVR4nO2a23LjIAxAAQsMmMv//+3iuGnSbGokgkh2h/PS6UwfzugCRbIQk8lkMplMJpPJZDL5bwGAHz/f4rD5mEPSWqeQndje4gAuS6uUPFDW6uiHhwSclleFK0omM1QETLLyCUoFMU4EwlOJIzlxkAcY/ZiOHyJhjIX7qygePPQQi18T8s3KXiDgzkPxFQ/PrGHqErtH4j3LAGWx1ylnWiAgUnKBs28x5XllZbMQYkVbMKYFFmxKLh6GS4NiwXaaQiRpSMukoUkWUmWW6jD4NjlguVsg03JSYCnSRLVgyYonHBpfaIabxZBzIiVDNIjtusNwguFvtTtc93Bs5Aot0eh/zW7Ew+uisfTXoDcKR8dOjR8aH1IbqeHc6N8pDTebVK63RTlFqfd80WB4NX3IndJwwyYGDSCf5jb2tyA+Dy7wPBE+4n9RclaYnrHUd4rkkNg9SL3C9EyhhkPxSOwQqoPhWrsChJOUcxyIPzvYxgqHx+lkdkhKDlDdwjuB2/EfYYGZjKrELiH2G78yMx8Qi52TPYYcUJ03j/jrEkGtAzdd4IN9JqLksFAcbD7Ih9Qoq5fxe1AQMa3H7lEV5BrMwD3bvQgIE5dQyIt7k8Mhst14g0WJg/fGLTmElLROKZWIRGe8GFccJRVL2MvitpPeC1SV32VK2ZU/YHaBzbus7dNm/e4Xu4Zo+KIC4GOSCrPyK32TmWoWXKosYB9U9NJdBHx+PK0QJjZ0/XQADCkQdyJSu14hARHaJA6T1GVGCyKfNQYCm/zLI/yTOx0fEJVfywyIhsHbM5H1lVqtfiOBx7a/aFuGf7+idGtiWlYXJx6NiUE+0Ai0tG63srhhyR61x0gbiurRPyOHB6k+sA/3Bg/C/LppvYcEP36Bhik9GvwLFzM7eMEDOS6lD8eJ4CwI3xE1gUsLbQjbgkWM51jr8wvMnqVhw0imHo4BwUBUR8sXAQ0e1WjwnZ/3GpWzg7wzadSofZrGeJvcU/twcUSfFGzloh3QJzvqfDdK/tKtVeP8vRCtGoI9PzlcXsZQWVjDKM41JpPJZPIP8gcPtSX90uGNGAAAAABJRU5ErkJggg==' alt='' alt=''>
                        <div class='name_job'>
                            <h2>$nama</h2>
                            <p>Penyewa pada tanggal $tanggal_pesan</p>
                            <p>Rating : $rating</p>
                        </div>
                    </div>
                    <p>
                        $komentar
                    </p>
						</div>";
					}
				} else {
					echo "Belum ada testimoni";
				}

				$conn->close();
			?>
            </div>

            <div class="sliderbar">
                <span id="leftArrow">
                    <i class="fas fa-arrow-left"></i>
                </span>
                <span id="rightArrow">
                    <i class="fas fa-arrow-right"></i>
                </span>
            </div>

        </div>
     </div>
     <script src="main.js"></script>
    <!-- end of about -->

    <!-- footer -->
    <?php include '../footer/footer.php'; ?>
    <!-- end of footer -->

    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
    <!-- <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script> -->

    <!-- Option 2: jQuery, Popper.js, and Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js" integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>
</body>
</html>
