<?php
// admin/check_users.php

// Koneksi database
try {
    $host = 'localhost';
    $dbname = 'soca_osce';
    $username = 'root';
    $password = '';
    
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    die("Koneksi database gagal: " . $e->getMessage());
}

// Ambil semua users
$users = $pdo->query("SELECT * FROM users ORDER BY role, id")->fetchAll();

echo "<h2>Data Users di Database</h2>";
echo "<table border='1' style='border-collapse: collapse;'>";
echo "<tr><th>ID</th><th>Username</th><th>Role</th><th>Password Hash</th></tr>";

foreach ($users as $user) {
    echo "<tr>";
    echo "<td>{$user['id']}</td>";
    echo "<td>{$user['username']}</td>";
    echo "<td>{$user['role']}</td>";
    echo "<td>" . substr($user['password'], 0, 20) . "...</td>";
    echo "</tr>";
}
echo "</table>";

echo "<br><h3>Login sebagai admin menggunakan salah satu username di atas yang role='admin'</h3>";
echo "<p><a href='../login.php'>Ke Halaman Login</a></p>";
?>