<?php
include 'C:\xampp\htdocs\admission_portal\includes\db.php';

$full_name = "System Administrator";
$email = "admin@uol.edu.pk";
$cnic = "0000000000000";
$phone = "00000000000";
$password = "admin123"; // Default password
$role = "system_admin"; // Set as system administrator

// Check if admin exists in users table
$check = $conn->query("SELECT id FROM users WHERE email='$email'");
if ($check->num_rows == 0) {
    $hashed_password = password_hash($password, PASSWORD_DEFAULT);
    $sql = "INSERT INTO users (full_name, email, cnic, phone, password, role) 
            VALUES ('$full_name', '$email', '$cnic', '$phone', '$hashed_password', '$role')";
    
    if ($conn->query($sql) === TRUE) {
        echo "System administrator user created successfully in users table.<br>";
        echo "Email: $email<br>";
        echo "Password: $password<br>";
        echo "Role: $role<br>";
    } else {
        echo "Error creating admin in users table: " . $conn->error;
    }
} else {
    echo "Admin user already exists in users table.";
}

// Also create in admins table
$check_admins = $conn->query("SELECT id FROM admins WHERE email='$email'");
if ($check_admins->num_rows == 0) {
    $hashed_password = password_hash($password, PASSWORD_DEFAULT);
    $sql_admins = "INSERT INTO admins (username, email, password, role) 
                    VALUES ('admin', '$email', '$hashed_password', '$role')";
    
    if ($conn->query($sql_admins) === TRUE) {
        echo "<br>System administrator created successfully in admins table.<br>";
    } else {
        echo "<br>Error creating admin in admins table: " . $conn->error;
    }
} else {
    echo "<br>Admin user already exists in admins table.";
}
?>
