<?php
// Start the session
session_start();

// Check if the user is logged in
if (!isset($_SESSION['alogin'])) {
    header("Location: adminlogin.php");
    exit();
}

// Include the PDO database connection
include('includes/db_pdo.php');

// Fetch user data from the database based on the username in the session
$username = $_SESSION['alogin'];  // Get the username from session

// Prepare the query to fetch user data
$query = "SELECT * FROM admin WHERE UserName = :username";
$stmt = $conn->prepare($query);
$stmt->bindParam(':username', $username, PDO::PARAM_STR);

// Execute the statement
$stmt->execute();

// Fetch user data
$userData = $stmt->fetch(PDO::FETCH_ASSOC);

// Handle the case where user data does not exist (in case the session is invalidated)
if (!$userData) {
    // Redirect the user to login page if user data is not found
    header("Location: adminlogin.php");
    exit();
} else {
    // Assign the values if the user data is found
    $username = $userData['UserName'];
    $fullName = $userData['UserName'];  // Assuming FullName exists in the `admin` table
}

// Close the database connection
$conn = null;
?>
