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

include("connection.php");
$AccID = $_SESSION['AccID'];

// Fetching the user's name
$sql = "SELECT Renter_Name FROM renter WHERE Renter_ID = '$AccID'";
$result = mysqli_query($conn, $sql);
$user = mysqli_fetch_assoc($result);
$userName = $user['Renter_Name'];

// Retrieve data from the previous page
$Renter_ID = $AccID;
$OrderID = $_POST['OrderID'];
$Place_Num = $_POST['Place_Num'];
$License = $_POST['License'];
$Dates = $_POST['Dates'];

// Check if the payment button was clicked
if (isset($_POST['payment_type'])) {
    // Update the payment status in the database
    $sql = "UPDATE orders SET Pay_Status = 1 WHERE OrderID = '$OrderID'";
    $result = mysqli_query($conn, $sql);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <title>User Website</title>
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="style2.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"> 
    <style>
        .button-row  a {
            margin-top: 30px;
            font-size: 15px;
            width: 100px;
            margin-left: 50px;
            padding: 10px 20px;
            background-color: var(--main-color, purple);
            color: white;
            border: none;
            border-radius: 5px;
            margin-left: 50%;
        }
        .button-row  a:hover {
            background-color: #6b1c6e;
        }
    </style>
</head>
<body>
    <aside class="sidebar">
      <div class="logo">
        <img src="pic/profiles.png" alt="logo">
        <h2><?php echo $userName; ?>'s</h2>
      </div>
      <ul class="links">
        <h4>Main Menu</h4>
        <li>
          <span class="material-symbols-outlined"><img src="pic/home.png"></span>
          <a href="rentermenu.php">Main Menu</a>
        </li>
        <hr>
        <h4>Advanced</h4>
        <li>
          <span class="material-symbols-outlined"><img src="pic/receipt.png"></span>
          <a href="selectReceipt.php">Receipt</a>
        </li>
        <hr>
        <h4>Account</h4>
        <li>
          <span class="material-symbols-outlined"><img src="pic/profile2.png"></span>
          <a href="renterProfile.php">Profile</a>
        </li>
        <hr>
        <h4>Sign Out</h4>
        <li class="logout-link">
          <span class="material-symbols-outlined"><i class="fa-solid fa-right-from-bracket"></i></span>
          <a href="logout.php">Logout</a>
        </li>
      </ul>
    </aside>
    <header class = "header">
        <a href= "rentermenu.php" class = "logo">Welcome
        <span><?php echo $userName; ?>'s</span></a>

        <i class="fa-solid fa-bars" id="menu-icon"></i>

        <nav class="navbar">
            <a href="rentPlace.php">Rent Place</a>
            <a href="sawEvents.php">Event</a>
            <a href="payment.php">Payment</a>
            <a href="sentFeedback.php">Sent Feedback</a>  
            </nav>      
    </header>
    <section class="home" id="home">
        <div class="home-content">
            <br><br>
            <table width="882" border="0">
                <tbody>
                    <tr>
                        <td align="center"><h1>Payment Site</h1></td>
                    </tr>
                </tbody>
            </table>
            <form action="receipt.php" method="post">
                <input type="hidden" name="OrderID" value="<?php echo $OrderID; ?>">
                <input type="hidden" name="Renter_ID" value="<?php echo $AccID; ?>">
                <input type="hidden" name="Place_Num" value="<?php echo $Place_Num; ?>">
                <input type="hidden" name="License" value="<?php echo $License; ?>">
                <input type="hidden" name="Dates" value="<?php echo $Dates; ?>">
                <table width="883" height="125" border="0" align="center">
                    <tbody>
                        <tr>
                            <td align="center">
                                <button type="submit" name="payment_type" value="Debit credit">
                                    <img src="pic/debit.png" width="336" height="336" alt=""/>
                                </button>
                            </td>
                            <td align="center">
                                <button type="submit" name="payment_type" value="Online banking">
                                    <img src="pic/onlinebank.png" width="346" height="319" alt=""/>
                                </button>
                            </td>
                        </tr>
                        <tr>
                            <td align="center">
                                <br><button type="submit" name="payment_type" value="Debit credit" style="background: none; border: none; color: white;">Debit / Credit Card</button>
                            </td>
                            <td align="center">
                                <br><button type="submit" name="payment_type" value="Online banking" style="background: none; border: none; color: white;">Online Banking</button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </form>
        <div class="button-row">
            <a href="payment.php" class="button">BACK</a>
        </div>
        </div>
    </section>
    <footer class="footer" id="footer">
        <div class="social">
            <a onclick="showPopup()"><i class="fa-solid fa-phone"></i></a>
            <a onclick="showPopup2()"><i class="fa-solid fa-envelope"></i></a>
        </div>
        <div id="popup" class="popup">
            <h2>This is Our No Phone!</h2><br>
            <p>016-430 6562</p>
            <button class="btns" onclick="closePopup()">Close</button>
        </div>
        <div id="popup2" class="popup">
            <h2>This is Our Email!</h2><br>
            <p>uitm@student.uitm.edu.my</p>
            <button class="btns" onclick="closePopup2()">Close</button>
        </div>
        <ul class="list">
            <li><a href="sentFeedback.php">Rate Us</a></li>
            <li><a href="sawEvents.php">Event</a></li>
            <li><a href="renterProfile.php">Profile</a></li>
            <li><a href="https://bendahari.uitm.edu.my/index.php/component/contact/category/55-cawangan-negeri-perak-kampus-tapah">Website</a></li>
        </ul>
        <p class="copyright">
            © NextGen Techne | All Rights Reserved
        </p>
    </footer>
    <script src="script.js"></script>
</body>
</html>
