<?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 "Fixing admin@uol.edu.pk role...\n\n";

// Update admin@uol.edu.pk account role
$email = "admin@uol.edu.pk";
$role = "system_admin";

// Update the role
$sql = "UPDATE users SET role = '$role' WHERE email = '$email'";
if ($conn->query($sql) === TRUE) {
    echo "Role updated successfully to: $role\n";
} else {
    echo "Error updating role: " . $conn->error . "\n";
}

// Verify the account
echo "\n=== Final Verification ===\n";
$result = $conn->query("SELECT email, role FROM users WHERE email = '$email'");
if($result->num_rows > 0) {
    $row = $result->fetch_assoc();
    echo "Account details:\n";
    echo "Email: {$row['email']}\n";
    echo "Role: {$row['role']}\n";
    
    // Test password
    $password = "admin123";
    $verify_result = $conn->query("SELECT password FROM users WHERE email = '$email'");
    $pass_row = $verify_result->fetch_assoc();
    if(password_verify($password, $pass_row['password'])) {
        echo "Password verification: SUCCESS\n";
    } else {
        echo "Password verification: FAILED\n";
    }
    
    echo "\nLogin credentials ready:\n";
    echo "Email: admin@uol.edu.pk\n";
    echo "Password: admin123\n";
    echo "Role: system_admin\n";
} else {
    echo "Account not found!\n";
}

$conn->close();
?>
