<?php
// Assuming you have established a database connection
// Include necessary files and start session
require_once '../config.php';
session_start();
var_dump($_SESSION);
// Check if the user is logged in as a system admin
if (!isset($_SESSION['userType']) || $_SESSION['userType'] !== 'member') {
    header('Location: ../indexX.php');
    exit;
}

$connection = mysqli_connect($db_host, $db_user, $db_password, $db_name);


// Fetch the zone_ministry_centre from the users table
$userId = $_SESSION['id']; // Assuming you have stored the user ID in the session
echo '$userId equals '. $userId;
$query = "SELECT zone,id FROM users WHERE id = $userId";
$result = mysqli_query($connection, $query);

if ($result) {
    $row = mysqli_fetch_assoc($result);
    $zoneMinistryCentre = $row['zone'];
    $myUserID =  $row['id'];
} else {
    // Handle database error
    $zoneMinistryCentre = ""; // Set the default value to an empty string
}

/*
// Retrieve the nominee records from the database
//$selectQuery = "SELECT * FROM NomineeData WHERE user_id = '$userId'";
$selectQuery = "SELECT * FROM NomineeData WHERE user_id = '69'";
$nomineesResult = mysqli_query($connection, $selectQuery);

// Close the database connection
mysqli_close($connection);

if ($nomineesResult) {
    // Process the fetched nominee data
    while ($row = mysqli_fetch_assoc($nomineesResult)) {
        // Access the data using $row['column_name']
        // Example: $nomineeName = $row['nominee_name'];
    }
} else {
    // Handle database error or no rows found
    // Example: echo "Error: " . mysqli_error($connection);
}
*/
function getUsers() {
    // Add your logic to fetch the list of users from the database
    // Add the global keyword to access the $connection variable within the function
    global $connection;

    $query = "SELECT * FROM NomineeData WHERE user_id = '69'";
    $result = mysqli_query($connection, $query);
    $row = mysqli_fetch_all($result, MYSQLI_ASSOC);
    return $row;
}

include('../headerspecial.php');

?>

<!DOCTYPE html>
<html>
<head>
    <title>Nominees Directory</title>
    <!-- Add any necessary CSS or JavaScript files -->
</head>
<body>
    <h1>Nominees Directory</h1>

    <?php
    // Display the nominee records if available
    if (mysqli_num_rows($nomineesResult) > 0) {
        echo '<table>';
        echo '<tr><th>Title</th><th>Nominee Name</th><th>Group Name</th><th>Church Name</th></tr>';

        while ($row = mysqli_fetch_assoc($nomineesResult)) {
            echo '<tr>';
            echo '<td>' . $row['title'] . '</td>';
            echo '<td>' . $row['nominee_name'] . '</td>';
            echo '<td>' . $row['group_name'] . '</td>';
            echo '<td>' . $row['church_name'] . '</td>';
            echo '</tr>';
        }



        echo '</table>';
    } else {
        echo '<p>No nominees found.</p>';
    }
    ?>



    <!-- Add any additional HTML or PHP code as needed -->
</body>
</html>
