<?php
include 'db_config.php';

$email = "officer@workforce.lk";
$password = password_hash("password123", PASSWORD_DEFAULT);
$role = "dme";

// Check if exists
$check = $conn->prepare("SELECT id FROM dme_login WHERE username = ?");
$check->bind_param("s", $email);
$check->execute();
$check->store_result();

if ($check->num_rows == 0) {
    $stmt = $conn->prepare("INSERT INTO dme_login (username, password, role) VALUES (?, ?, ?)");
    $stmt->bind_param("sss", $email, $password, $role);
    if ($stmt->execute()) {
        echo "New DME Officer created.\nEmail: $email\nPassword: password123";
    } else {
        echo "Error: " . $conn->error;
    }
} else {
    // Update password if exists
    $stmt = $conn->prepare("UPDATE dme_login SET password = ? WHERE username = ?");
    $stmt->bind_param("ss", $password, $email);
    if($stmt->execute()) {
         echo "DME Officer updated.\nEmail: $email\nPassword: password123";
    }
}
?>
