<?php
/**
 * =====================================================
 * SIMPAS v1.0
 * Modul : Data Siswa
 * File   : edit.php
 * =====================================================
 */

include "../../config/koneksi.php";
include "../../config/session.php";

include "../../templates/header.php";
include "../../templates/navbar.php";
include "../../templates/sidebar.php";

$id = intval($_GET['id']);

$siswa = mysqli_query($conn,"
SELECT *
FROM siswa
WHERE id_siswa='$id'
");

$data = mysqli_fetch_assoc($siswa);

$kelas = mysqli_query($conn,"
SELECT *
FROM kelas
ORDER BY nama_kelas ASC
");

?>

<div class="content-wrapper">

<section class="content-header">

<div class="container-fluid">

<div class="row mb-2">

<div class="col-sm-6">

<h1>

<i class="fas fa-user-edit"></i>

Edit Data Siswa

</h1>

</div>

<div class="col-sm-6 text-right">

<a href="index.php" class="btn btn-secondary">

<i class="fas fa-arrow-left"></i>

Kembali

</a>

</div>

</div>

</div>

</section>

<section class="content">

<div class="container-fluid">

<div class="card shadow">

<div class="card-header bg-primary">

<h3 class="card-title">

Form Edit Data Siswa

</h3>

</div>

<div class="card-body">

<form
action="update.php"
method="POST"
enctype="multipart/form-data">

<input
type="hidden"
name="id_siswa"
value="<?= $data['id_siswa']; ?>">

<input
type="hidden"
name="foto_lama"
value="<?= $data['foto']; ?>">

<div class="form-group">

<label>NIS</label>

<input
type="text"
name="nis"
class="form-control"
value="<?= htmlspecialchars($data['nis']); ?>"
required>

</div>

<div class="form-group">

<label>NISN</label>

<input
type="text"
name="nisn"
class="form-control"
value="<?= htmlspecialchars($data['nisn']); ?>">

</div>

<div class="form-group">

<label>Nama Siswa</label>

<input
type="text"
name="nama_siswa"
class="form-control"
value="<?= htmlspecialchars($data['nama_siswa']); ?>"
required>

</div>

<div class="form-group">

<label>Jenis Kelamin</label>

<br>

<label class="mr-3">

<input
type="radio"
name="jk"
value="L"
<?= ($data['jk']=="L") ? "checked" : ""; ?>>

Laki-laki

</label>

<label>

<input
type="radio"
name="jk"
value="P"
<?= ($data['jk']=="P") ? "checked" : ""; ?>>

Perempuan

</label>

</div>

<div class="form-group">

<label>Kelas</label>

<select
name="id_kelas"
class="form-control"
required>

<?php while($k=mysqli_fetch_assoc($kelas)): ?>

<option
value="<?= $k['id_kelas']; ?>"
<?= ($data['id_kelas']==$k['id_kelas']) ? "selected" : ""; ?>>

<?= $k['nama_kelas']; ?>

</option>

<?php endwhile; ?>

</select>

</div>
<div class="form-group">

    <label>Foto Saat Ini</label>

    <br>

    <?php

    if($data['foto']=="default.png" || empty($data['foto'])){

        $foto="../../uploads/foto/default.png";

    }else{

        $foto="../../uploads/foto/".$data['foto'];

    }

    ?>

    <img src="<?= $foto; ?>"
         width="120"
         class="img-thumbnail">

</div>

<div class="form-group">

    <label>Ganti Foto</label>

    <input
        type="file"
        name="foto"
        class="form-control"
        accept=".jpg,.jpeg,.png">

    <small class="text-muted">

        Kosongkan jika foto tidak ingin diganti.

    </small>

</div>

<div class="form-group">

    <label>Status</label>

    <select
        name="status"
        class="form-control"
        required>

        <option value="Aktif"
        <?= ($data['status']=="Aktif") ? "selected" : ""; ?>>

            Aktif

        </option>

        <option value="Lulus"
        <?= ($data['status']=="Lulus") ? "selected" : ""; ?>>

            Lulus

        </option>

        <option value="Pindah"
        <?= ($data['status']=="Pindah") ? "selected" : ""; ?>>

            Pindah

        </option>

    </select>

</div>

<hr>

<div class="text-center">

    <button
        type="submit"
        class="btn btn-primary">

        <i class="fas fa-save"></i>

        Update Data

    </button>

    <a
        href="index.php"
        class="btn btn-secondary">

        <i class="fas fa-arrow-left"></i>

        Kembali

    </a>

</div>

</form>

</div>

</div>

</div>

</section>

</div>

<?php
include "../../templates/footer.php";
?>