<?php
// Koneksi ke database
include '../koneksi.php'; // Pastikan path ini benar
include 'header.php';

// Ambil ID poli dari parameter query
$id_poli = isset($_GET['id']) ? mysqli_real_escape_string($koneksi, $_GET['id']) : 0;

// Query untuk mendapatkan data dari tabel 'tbl_poli' berdasarkan ID poli
$poli_query = "SELECT * FROM tbl_poli WHERE id_poli = '$id_poli'";
$poli_result = mysqli_query($koneksi, $poli_query);

// Periksa jika query gagal
if (!$poli_result) {
    die("Query Error: " . mysqli_error($koneksi));
}

$poli = mysqli_fetch_assoc($poli_result);

// Jika poli tidak ditemukan
if (!$poli) {
    die("Data poli tidak ditemukan.");
}
?>

<div id="wrapper">
    <div id="content-wrapper" class="d-flex flex-column">
        <div id="content">
            <div class="container-fluid">
                <h1 class="h3 mb-4 text-gray-800">Edit Poli</h1>
                
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary">Edit Data Poli</h6>
                    </div>
                    <div class="card-body">
                        <form action="poli_update.php" method="POST" enctype="multipart/form-data">
                            <input type="hidden" name="id_poli" value="<?php echo $poli['id_poli']; ?>">
                            
                            <div class="form-group mb-3">
                                <label for="nama_poli">Nama Poli</label>
                                <input type="text" class="form-control" id="nama_poli" name="nama_poli" value="<?php echo htmlspecialchars($poli['nama_poli']); ?>" placeholder="Masukkan Nama Poli" required>
                            </div>
                            
                            <div class="form-group mb-3">
                                <label for="keterangan">Keterangan</label>
                                <input type="text" class="form-control" id="keterangan" name="keterangan" value="<?php echo htmlspecialchars($poli['keterangan']); ?>" placeholder="Masukkan Keterangan" required>
                            </div>

                            <div class="form-group">
                                <div class="row">
                                    <div class="col-lg-2">
                                        <input type="submit" class="btn btn-sm btn-primary" value="Simpan">
                                    </div>
                                    <div class="col-lg-2">
                                        <a href="poli.php" class="btn btn-danger btn-sm">Kembali</a>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php include 'footer.php'; ?>
