<?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'];
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Profile's | UITM BAZAAR</title>
    <link rel="stylesheet" type="text/css" 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">
        body {
            margin-top: 300px;
            font-family: Arial, sans-serif;
            padding: 20px;
            background: #161616;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }
        .images img {
            border-radius: 50%;
            margin-bottom: 30px;
            position: center;
            width: 170px;
        }
        html, body {
            height: 50%;
        }
        button {
            margin-left: 125px;
            padding: 10px 15px;
            color: white;
            background-color: purple;
            transition: 0.5s;
            letter-spacing: 4px;
        }
        .right-container {
            align-items: center;
            background: black;
            width: 400px;
            height: 500px;
            padding: 20px;
            border-radius: 30px;
        }
        h2 {
            font-size: 24px;
            margin-bottom: 5px;
        }
        h3 {
            text-align: center;
            font-size: 24px;
            margin-bottom: 5px;
        }
        .gradienttext {
            margin-top: 37rem;
            margin-bottom: 3rem;
            font-size: 30px;
        }
        p {
            font-size: 18px;
            margin-bottom: 20px;
            color: aliceblue;
        }
        table {
            width: 100%;
            color: white;
        }
        table td {
            padding: 10px 0;
            font-size: 17px;
        }
        table td input {
            width: calc(100% - 20px);
            padding: 8px;
            margin: 1px 0;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        .credit a {
            text-decoration: none;
            color: #fff;
            font-weight: 800;
        }
        .credit {
            color: #fff;
            text-align: center;
            margin-top: 10px;
            font-family: Verdana, Geneva, Tahoma, sans-serif;
        }
        .footer {
            margin-top: 100px;
            width: 120%;
        }
    </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>
    <?php
    $AccID = $_SESSION['AccAdminID'];

    // Fetching the user's details
    $sql = "SELECT * FROM admin WHERE Admin_ID = '$AccID'";
    $data = mysqli_query($conn, $sql);
    $check_event = mysqli_num_rows($data) > 0;
    if ($check_event) {
        while ($row = mysqli_fetch_assoc($data)) {
    ?>
    <h3 class="gradienttext">PROFILE DETAILS</h3>
    <div class="images"><img src="pic/profiles.png"></div>
    <div class="right-container">
        <form method="post" action="adminProfile2.php">
            <table>
                <tr>
                    <td><label for="ID">Id :</label></td>
                    <td><input id="ID" name="ID" type="text" value="<?php echo $row['Admin_ID']; ?>" required></td>
                </tr>
                <tr>
                    <td><label for="Pass">Password :</label></td>
                    <td><input id="Pass" name="Pass" type="text" value="<?php echo $row['Admin_Pass']; ?>" required></td>
                </tr>
                <tr>
                    <td><label for="Name">Name :</label></td>
                    <td><input id="Name" name="Name" type="text" value="<?php echo $row['Admin_Name']; ?>" required></td>
                </tr>
                <tr>
                    <td><label for="PhoneNum">Phone Number :</label></td>
                    <td><input id="PhoneNum" name="PhoneNum" type="number" value="<?php echo $row['Admin_PhoneNum']; ?>" required></td>
                </tr>
            </table>
            <button type="submit" value="submit" name="submit">Update</button>
        </form>
    </div>

    <?php
        }
    } else {
        echo "<p>No profile details found.</p>";
    }
    ?>

    <footer class="footer" id="footer">
        <p class="copyright">
            NextGen Techne © | All Rights Reserved
        </p>
    </footer>
</body>
</html>
