<?php
$host = "localhost";
$user = "root";
$password = "";
$dbname = "admission_system";

$conn = new mysqli($host, $user, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

echo "Checking System Administrator account...\n";

// Check system admin in users table
$check_users = $conn->query("SELECT id, email, role FROM users WHERE email = 'admin@uol.edu.pk'");
if($check_users->num_rows > 0) {
    $user = $check_users->fetch_assoc();
    echo "Found in users table:\n";
    echo "ID: {$user['id']}, Email: {$user['email']}, Role: {$user['role']}\n";
} else {
    echo "System admin not found in users table\n";
}

// Check system admin in admins table
$check_admins = $conn->query("SELECT id, username, email, role FROM admins WHERE email = 'admin@uol.edu.pk'");
if($check_admins->num_rows > 0) {
    $admin = $check_admins->fetch_assoc();
    echo "\nFound in admins table:\n";
    echo "ID: {$admin['id']}, Username: {$admin['username']}, Email: {$admin['email']}, Role: {$admin['role']}\n";
} else {
    echo "\nSystem admin not found in admins table\n";
}

// Update role in users table if needed
if($check_users->num_rows > 0) {
    $user = $check_users->fetch_assoc();
    if($user['role'] != 'system_admin') {
        echo "\nUpdating role in users table to system_admin...\n";
        $update = $conn->query("UPDATE users SET role = 'system_admin' WHERE email = 'admin@uol.edu.pk'");
        if($update) {
            echo "Role updated successfully in users table\n";
        } else {
            echo "Error updating role: " . $conn->error . "\n";
        }
    }
}

$conn->close();
?>
