<?php
// Include necessary files and start session
require_once '../config.php';
session_start();

// Check if the user is logged in as a system admin
$connection = mysqli_connect($db_host, $db_user, $db_password, $db_name);

//echo $db_host;
if (!isset($_SESSION['userType']) || $_SESSION['userType'] !== 'admin') {
    header('Location: ../indexX.php');
    exit;
}

// Function to retrieve the total number of zones
function getTotalZones() {
  global $connection;
    // Add your logic to fetch the total number of zones from the database
    // Example:
    $query = "SELECT COUNT(*) AS total FROM users where user_type='member'";
    $result = mysqli_query($connection, $query);
    $row = mysqli_fetch_assoc($result);
    return $row['total'];

    // Replace the return statement with your own logic
    //return 10;
}

// Function to retrieve the total number of payments
function getTotalPayments() {
    // Add your logic to fetch the total number of payments from the database
    // Replace the return statement with your own logic
    return 50;
}

// Function to retrieve the total number of nominees
function getTotalNominees() {
    // Add your logic to fetch the total number of nominees from the database
    // Replace the return statement with your own logic
    global $connection;
      // Add your logic to fetch the total number of zones from the database
      // Example:
      $query = "SELECT COUNT(*) AS total FROM NomineeData";
      $result = mysqli_query($connection, $query);
      $row = mysqli_fetch_assoc($result);
      return $row['total'];
    //return 100;
}

// Function to retrieve the total number of certificates
function getTotalCertificates() {
    // Add your logic to fetch the total number of certificates from the database
    // Replace the return statement with your own logic
    return 75;
}

// Function to retrieve the list of zones
function getZones() {
    // Add your logic to fetch the list of zones from the database
    // Example:
    // $query = "SELECT * FROM zones";
    // $result = mysqli_query($connection, $query);
    // $zones = mysqli_fetch_all($result, MYSQLI_ASSOC);
    // return $zones;

    // Replace the return statement with your own logic
    return [
        ['zone_id' => 1, 'zone_name' => 'Zone A'],
        ['zone_id' => 2, 'zone_name' => 'Zone B'],
        ['zone_id' => 3, 'zone_name' => 'Zone C'],
        ['zone_id' => 4, 'zone_name' => 'Zone D'],
    ];
}

// Render the dashboard page
include('../headerspecial.php');
?>

<!DOCTYPE html>
<html>
<head>
    <title>System Admin Dashboard</title>
    <!-- Add your CSS and JS files here -->
</head>
<body>
    <h1>System Admin Dashboard</h1>
    <div>
        <h3>Statistics:</h3>
        <ul>
            <li><a href="usermanagement.php">Total Zones</a>: <?php echo getTotalZones(); ?></li>
            <li>Total Payments: <?php echo getTotalPayments(); ?></li>
            <li>Total Nominees: <?php echo getTotalNominees(); ?></li>
            <li>Total Certificates: <?php echo getTotalCertificates(); ?></li>
        </ul>
    </div>
    <!-- Add other content and functionalities as needed -->
</body>
</html>
