<?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 admin login credentials...\n\n";

// Check all admin users in users table
echo "=== Users Table ===\n";
$result = $conn->query("SELECT id, email, full_name, role, created_at FROM users WHERE role IN ('admin', 'system_admin')");
if($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "ID: {$row['id']}, Email: {$row['email']}, Name: {$row['full_name']}, Role: {$row['role']}, Created: {$row['created_at']}\n";
    }
} else {
    echo "No admin users found in users table\n";
}

// Check all admin users in admins table
echo "\n=== Admins Table ===\n";
$result = $conn->query("SELECT id, username, email, role, created_at FROM admins");
if($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "ID: {$row['id']}, Username: {$row['username']}, Email: {$row['email']}, Role: {$row['role']}, Created: {$row['created_at']}\n";
    }
} else {
    echo "No admin users found in admins table\n";
}

// Check for the specific email mentioned by user
echo "\n=== Checking admin@uole.du.pk ===\n";
$check_email = "admin@uole.du.pk";
$result = $conn->query("SELECT * FROM users WHERE email = '$check_email'");
if($result->num_rows > 0) {
    echo "Found admin@uole.du.pk in users table\n";
    $row = $result->fetch_assoc();
    echo "ID: {$row['id']}, Email: {$row['email']}, Role: {$row['role']}\n";
} else {
    echo "admin@uole.du.pk NOT found in users table\n";
}

// Check for the correct email
echo "\n=== Checking admin@uol.edu.pk ===\n";
$check_email2 = "admin@uol.edu.pk";
$result = $conn->query("SELECT * FROM users WHERE email = '$check_email2'");
if($result->num_rows > 0) {
    echo "Found admin@uol.edu.pk in users table\n";
    $row = $result->fetch_assoc();
    echo "ID: {$row['id']}, Email: {$row['email']}, Role: {$row['role']}\n";
    
    // Test password verification
    $password = "admin123";
    if(password_verify($password, $row['password'])) {
        echo "Password verification: SUCCESS\n";
    } else {
        echo "Password verification: FAILED\n";
        echo "Stored hash: {$row['password']}\n";
    }
} else {
    echo "admin@uol.edu.pk NOT found in users table\n";
}

$conn->close();
?>
