<?php

$cekID = new cekID();
$jmldata = $cekID->Cek('user', 'id', $id_page);

$user_admin = new crudData();
$editUser = $user_admin->editData('user', 'id', $id_page);
$data = $editUser->fetch(PDO::FETCH_OBJ);

?>
<style>
    .fontInput {
        font-size: 11px;
        font-family: arial;
    }
</style>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">

    <?php require('./layout/headerpage.php'); ?>

    <div class="container col-12 mb-4 pb-5">
        <div class="row">
            <div class="col-12">
                <div class="col-12">
                    <div class="card  mx-3">
                        <div class="timeline-header bg-primary py-2 pl-2">
                            <b class="text-light judul"><span class="bi bi-person"></span> Tambah User Siswa </b>
                        </div>
                        <div class="row col-md-12">
                            <div class="col-md-12">
                                <div class="card-body mt-4 px-1 mx-2">

                                    <div class="row">
                                        <div class="col-12 col-sm-6 col-md-12">
                                            <div class="info-box mb-3">
                                                <div class="info-box-content">
                                                    <div class="relative mb-0 pb-4">
                                                        <input name="judul" value="PROFIL USER" style="background-color: gainsboro;" class="form-control-sm col-sm-3 fontInput small bg-default mt-3 text-center" disabled>
                                                    </div>

                                                    <div class="col-sm-12 invoice-col pt-0">
                                                        <div class="card-body mb-4">
                                                            <div class="row mx-3 mt-3">
                                                                <div class="col-md-3">
                                                                    <div class="card-body mt-1 px-2 mx-3">
                                                                        <div class="row">

                                                                            <div class="col-sm-12 small">
                                                                                <div class="modal-body" align="left">
                                                                                    <?php
                                                                                    $view = new user;
                                                                                    echo $view->viewImage('../../asset/dokumen/foto/', $data->id, 'img-thumbnail', '150', '150'); ?>
                                                                                </div>
                                                                                <form action="" method="post" enctype="multipart/form-data">
                                                                                    <input type="file" name="fileFoto" class="pl-3" accept=".png,.jpg,.gif" required />
                                                                                    <input type="submit" name="uploadfoto" value="Upload" />
                                                                                </form>
                                                                            </div>
                                                                        </div>

                                                                    </div>
                                                                </div>




                                                                <div class="col-md-5">

                                                                    <div class="card-body mt-4 px-2 mx-3">
                                                                        <form action="" method="post">
                                                                            <div class="row">
                                                                                <label for="exampleEmail" class="col-sm-3 col-form-label">Nama User </label>
                                                                                <div class="col-sm-7">
                                                                                    <input type="text" name="nama" value="<?php echo $data->nama; ?>" class="form-control form-control-sm fontInput" placeholder="Nama User">
                                                                                </div>
                                                                            </div>
                                                                            <div class="row">
                                                                                <label class="col-sm-3 col-form-label">Jenis Kelamin</label>
                                                                                <div class="col-md-7">
                                                                                    <select name="kelamin" class="form-control form-control-sm fontInput small" required>
                                                                                        <option value="<?php echo $data->kelamin; ?>">
                                                                                            <?php if ($data->kelamin == 'L') {
                                                                                                echo "Laki-laki";
                                                                                            } else {
                                                                                                echo "Perempuan";
                                                                                            }; ?></option>
                                                                                        <option value="L">Laki-laki</option>
                                                                                        <option value="P">Perempuan</option>
                                                                                    </select>
                                                                                </div>
                                                                            </div>
                                                                            <div class="row">
                                                                                <label for="nis" class="col-sm-3 col-form-label">No. Telpon/WA</label>
                                                                                <div class="col-sm-7">
                                                                                    <input type="text" class="form-control form-control-sm fontInput" value="<?php echo $data->hp; ?>" placeholder="No Telpon User" name="hp">

                                                                                </div>
                                                                            </div>
                                                                            <div class="row">
                                                                                <label for="nis" class="col-sm-3 col-form-label">Email</label>
                                                                                <div class="col-sm-7">
                                                                                    <input type="email" class="form-control form-control-sm fontInput" value="<?php echo $data->email; ?>" placeholder="email@mail.com" name="email">

                                                                                </div>
                                                                            </div>
                                                                    </div>
                                                                </div>
                                                                <div class="col-md-4">
                                                                    <div class="card-body mt-4 px-2 mx-3">
                                                                        <div class="row">
                                                                            <label class="col-sm-3 col-form-label">Username</label>
                                                                            <div class="col-md-7">
                                                                                <input type="text" class="form-control form-control-sm fontInput" name="username_user" value="<?php echo $data->username; ?>" placeholder="Username">
                                                                            </div>
                                                                        </div>
                                                                        <div class="row">
                                                                            <label class="col-sm-3 col-form-label">Password</label>
                                                                            <div class="col-md-7">
                                                                                <input type="password" class="form-control form-control-sm fontInput" name="password_user" value="" placeholder="Password" required>
                                                                            </div>
                                                                        </div>

                                                                    </div>
                                                                </div>
                                                            </div>

                                                            <div class="my-2 pl-3 py-2 mx-3">
                                                                <div class="row">
                                                                    <div class="col-auto">
                                                                        <a <?php echo $link->page('beranda'); ?> class="btn btn-primary btn-xs float-right mx-2"><i class="bi-arrow-left-circle"></i> Cancel</a>
                                                                        <button type="submit" class="btn btn-primary btn-xs float-right" name="submit"><i class="bi-save"></i> Simpan</button>
                                                                    </div>
                                                                    <span class="small">
                                                                        Setelah Simpan Profil, akan Logout Aplikasi
                                                                    </span>
                                                                </div>
                                                            </div>
                                                            </form>
                                                        </div>
                                                    </div>
                                                </div>

                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
$profil = new user();
if (isset($_POST['submit'])) {
    $profil->saveProfil($id_page);
} elseif (isset($_POST['uploadfoto'])) {
    echo $profil->delImage('../../asset/dokumen/foto/', $id_page);
    echo $profil->UploadImage('../../asset/dokumen/foto/', $id_page, '50', 'fileFoto', 'uploadfoto', $id_page);
} else {
    echo '';
}
