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

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

// Fetching the user's name
$sql = "SELECT Admin_Name FROM admin WHERE Admin_ID = '$AccID'";
$result = mysqli_query($conn, $sql);
$user = mysqli_fetch_assoc($result);
$userName = $user['Admin_Name'];
?>

<html lang="en">
<head>
    <title>RentList | UITM BAZAAR</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 type="text/css">
        .table-common {
            margin-left: 30px;
            border-collapse: collapse;
        }
        #table-1 {
            border: 1px solid white;
            font-size: 15px;
            padding: 10px;
        }
        #table-1 tr {
            border: 1px solid white;
            font-size: 15px;
            padding: 10px;
        }
        #table-1 td {
            border: 1px solid white;
            font-size: 15px;
            padding: 10px;
        }
        #table-1 tr:nth-child(even) {
            background-color: black;
        }
        #table-1 tr:hover {
            background-color:  #de55de;
            transform: scale(1.03); /* Add pop-up effect */
            transition: transform 0.3s ease;
        }
    </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="adminmenu.php">Main Menu</a>
        </li>
        <hr>
        <h4>Advanced</h4>
        <li>
          <span class="material-symbols-outlined"><img src="pic/admin.png"></span>
          <a href="newAdmin.php">New Admin Acc</a>
        </li>
        <hr>
        <h4>Account</h4>
        <li>
          <span class="material-symbols-outlined"><img src="pic/profile2.png"></span>
          <a href="adminProfile.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="logoutAdmin.php">Logout</a>
        </li>
      </ul>
    </aside>
    <header class = "header">
        <a href= "adminmenu.php" class = "logo">
        <span><?php echo $userName; ?>'s</span></a>
        
        <i class="fa-solid fa-bars" id="menu-icon"></i>
        
        <nav class="navbar">            
            <a href="report.php">Report</a> 
            <a href="renterList.php">Renter List</a>    
            <a href="viewFeedback.php">Feedback</a>
            <a href="approval.php">Order</a>
            <a href="postEvents.php">Events</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>RENTER DATABASE</h1></td>
                    </tr>
                </tbody>
            </table>
            <table class="table-common" id="table-1" width="882" height="152" border="1" align="center" cellpadding="1" cellspacing="1">
                <tbody>
                    <tr align="center" style="background-color: purple; transform: none; transition: none;">
                        <td width="300">RENTER ID</td>
                        <td width="500">RENTER NAME</td>
                        <td width="200">PHONE NUMBER</td>
                        <td width="50">AGE</td>
                        <td width="200">EMAIL</td>
                        <td width="200">PLACE NUMBER</td>
                        <td width="400">DATES</td>
                    </tr>
                    <?php
                    $conn = mysqli_connect("localhost", "root", "", "groupproject");
                    if ($conn->connect_error) {
                        die("Connection failed: " . $conn->connect_error);
                    }

                    $sql = "SELECT renter.Renter_ID, renter.Renter_Name, renter.Renter_PhoneNum, renter.Renter_Age, renter.Renter_Email, orders.Place_Num, orders.Dates FROM renter INNER JOIN orders ON renter.Renter_ID = orders.Renter_ID ORDER BY orders.dates";
                    $result = $conn->query($sql);

                    if ($result->num_rows > 0) {
                        while ($row = $result->fetch_assoc()) {
                            echo "<tr>";

                            echo "<td>" . $row["Renter_ID"] . "</td>";
                            echo "<td>" . $row["Renter_Name"] . "</td>";
                            echo "<td>" . $row["Renter_PhoneNum"] . "</td>";
                            echo "<td>" . $row["Renter_Age"] . "</td>";
                            echo "<td>" . $row["Renter_Email"] . "</td>";
                            echo "<td>" . $row["Place_Num"] . "</td>";
                            echo "<td>" . $row["Dates"] . "</td>";

                            echo "</tr>";
                        }
                    } else {
                        echo "<tr><td colspan='5'>No results found</td></tr>";
                    }

                    $conn->close();
                    ?>
                </tbody>
            </table>
        </div>
    </section>
    <footer class="footer" id="footer" style="margin-bottom: 200px;">
        <p class="copyright">
            NextGen Techne © | All Rights Reserved
        </p>
    </footer>
    <script src="script.js"></script>
</body>
</html>