<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

echo "<h2>Audit Sistem RSUD Lamadukelleng</h2>";

// 1. Cek File Config
if (file_exists('includes/config.php')) {
    echo "✅ File includes/config.php ditemukan.<br>";
    include 'includes/config.php';
} else {
    die("❌ Error: File includes/config.php TIDAK ditemukan. Silakan upload file tersebut.");
}

// 2. Cek Koneksi Database
if ($conn) {
    echo "✅ Koneksi database BERHASIL.<br>";
} else {
    die("❌ Koneksi database GAGAL: " . mysqli_connect_error());
}

// 3. Cek Tabel-Tabel Penting
$tables = ['users', 'settings', 'pendaftaran', 'dokter', 'berita', 'fasilitas', 'reviews'];
echo "<h3>Mengecek Tabel:</h3>";
foreach ($tables as $t) {
    $check = mysqli_query($conn, "SHOW TABLES LIKE '$t'");
    if (mysqli_num_rows($check) > 0) {
        echo "✅ Tabel <b>$t</b>: OK<br>";
    } else {
        echo "❌ Tabel <b>$t</b>: TIDAK DITEMUKAN! (Silakan impor database.sql di phpMyAdmin)<br>";
    }
}

// 4. Cek Konten Settings
echo "<h3>Audit Konten Settings:</h3>";
$res_settings = mysqli_query($conn, "SELECT id FROM settings WHERE id = 1");
if (mysqli_num_rows($res_settings) > 0) {
    echo "✅ Baris <b>settings (id=1)</b> ditemukan. Update akan berfungsi.<br>";
} else {
    echo "❌ Baris <b>settings (id=1)</b> TIDAK DITEMUKAN!<br>";
    echo "ℹ️ Mencoba membuat baris default... ";
    if (mysqli_query($conn, "INSERT INTO settings (id, nama_rs) VALUES (1, 'RSUD Lamadukelleng')")) {
        echo "✅ Berhasil dibuat otomatis.<br>";
    } else {
        echo "❌ Gagal membuat otomatis: " . mysqli_error($conn) . "<br>";
    }
}

echo "<br><b>Kesimpulan:</b> Jika semua sudah centang hijau (✅), maka fitur pengaturan admin seharusnya berfungsi dengan normal.";
?>
