<?php
include 'db_connect.php';

// 1. Delete old data to start fresh
$conn->query("SET FOREIGN_KEY_CHECKS = 0");
$conn->query("TRUNCATE TABLE users");
$conn->query("TRUNCATE TABLE agencies");
$conn->query("SET FOREIGN_KEY_CHECKS = 1");

// 2. Insert Agency
$conn->query("INSERT INTO agencies (id, agency_name, owner_name, email, expiry_date, status) 
              VALUES (1, 'Super Admin Portal', 'Admin', 'admin@admin.com', '2030-12-31', 'Active')");

// 3. Create Password Hash using YOUR local system
$password = "123456";
$hashed_password = password_hash($password, PASSWORD_DEFAULT);

// 4. Insert User
$stmt = $conn->prepare("INSERT INTO users (agency_id, name, email, password, role) VALUES (1, 'Super Admin', 'admin@admin.com', ?, 'SuperAdmin')");
$stmt->bind_param("s", $hashed_password);

if ($stmt->execute()) {
    echo "<h1>Success!</h1>";
    echo "<p>The login has been fixed. Your local computer created the password hash.</p>";
    echo "<p><b>Email:</b> admin@admin.com</p>";
    echo "<p><b>Password:</b> 123456</p>";
    echo "<br><a href='login.php'>Go to Login Page</a>";
} else {
    echo "Error: " . $conn->error;
}
?>