<?php
if (isset($_GET['act']) && $_GET['act'] == "input") {
?>
<div class="row">
    <div class="col-lg-12">
        <h1 class="page-header">Input Data User</h1>
    </div>
</div>

<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-primary">
            <div class="panel-heading">Input Data User</div>
            <div class="panel-body">
                <form method="post" action="./module/simpan.php?act=input_user">
                    <div class="col-lg-6">

                        <div class="form-group">
                            <label>Username</label>
                            <input class="form-control" name="nama" required>
                        </div>

                        <div class="form-group">
                            <label>Password</label>
                            <input class="form-control" name="pass" type="password" required>
                        </div>

                        <div class="form-group">
                            <label>Sekolah</label>
                            <select class="form-control" name="sekolah" required>
                                <?php
                                $sqla = mysqli_query($koneksi, "SELECT * FROM sekolah");
                                while ($rsa = mysqli_fetch_assoc($sqla)) {
                                    echo "<option value='{$rsa['id']}'>{$rsa['nama']}</option>";
                                }
                                ?>
                            </select>
                        </div>

                        <button type="submit" class="btn btn-success">Simpan</button>

                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<?php } ?>

<?php
if (isset($_GET['act']) && $_GET['act'] == "edit_user") {

    $sql = mysqli_query($koneksi, "SELECT * FROM user WHERE idu='$_GET[idu]'");
    $rs  = mysqli_fetch_assoc($sql);
?>
<div class="row">
    <div class="col-lg-12">
        <h1 class="page-header">Edit Data User</h1>
    </div>
</div>

<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-primary">
            <div class="panel-heading">Edit Data User</div>
            <div class="panel-body">
                <form method="post" action="./module/simpan.php?act=edit_user">
                    <input type="hidden" name="idu" value="<?= $_GET['idu']; ?>">

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

                        <div class="form-group">
                            <label>Username</label>
                            <input class="form-control" name="nama" value="<?= $rs['nama']; ?>" required>
                        </div>

                        <div class="form-group">
                            <label>Password (kosongkan jika tidak diganti)</label>
                            <input class="form-control" name="pass" type="password">
                        </div>

                        <div class="form-group">
                            <label>Sekolah</label>
                            <select class="form-control" name="sekolah">
                                <?php
                                $sqla = mysqli_query($koneksi, "SELECT * FROM sekolah");
                                while ($rsa = mysqli_fetch_assoc($sqla)) {
                                    $sel = ($rs['id'] == $rsa['id']) ? "selected" : "";
                                    echo "<option value='{$rsa['id']}' $sel>{$rsa['nama']}</option>";
                                }
                                ?>
                            </select>
                        </div>

                        <button type="submit" class="btn btn-success">Update</button>

                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<?php } ?>
