<?php
require_once '../koneksi.php';
include 'layout_header.php';

// 1. Ambil ID dari URL
$id = $_GET['id'];

// 2. Query untuk mengambil data berdasarkan ID
$query = mysqli_query($koneksi, "SELECT * FROM master_guru WHERE id_guru='$id'");
$d = mysqli_fetch_array($query);

// 3. Pastikan data ditemukan
if (!$d) {
    echo "<div class='alert alert-danger'>Data tidak ditemukan!</div>";
    include 'layout_footer.php';
    exit;
}
?>

<div class="container-fluid">
    <div class="card shadow-sm">
        <div class="card-body">
            <h5 class="mb-4">Edit Profil Guru</h5>
            
            <form action="guru_edit_aksi.php" method="post" enctype="multipart/form-data">
                <input type="hidden" name="id_guru" value="<?= $d['id_guru']; ?>">
                
                <div class="mb-3">
                    <label>Nama Guru</label>
                    <input type="text" name="nama" class="form-control" value="<?= htmlspecialchars($d['nama']); ?>" required>
                </div>
                
                <div class="mb-3">
                    <label>NIP</label>
                    <input type="text" name="nip" class="form-control" value="<?= htmlspecialchars($d['nip']); ?>">
                </div>

                <div class="mb-3">
                    <label>Ganti Foto (Opsional)</label>
                    <input type="file" name="foto" class="form-control">
                    <small class="text-muted">Biarkan kosong jika tidak ingin mengubah foto. Foto saat ini: <?= $d['foto']; ?></small>
                </div>
                
                <button type="submit" name="update" class="btn btn-success">Simpan Perubahan</button>
                <a href="guru.php" class="btn btn-secondary">Kembali</a>
            </form>
        </div>
    </div>
</div>

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