<style>
    .fontInput {
        font-size: 13px;
        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-file-earmark-plus"></span> Tambah User Operator</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="INPUT USER OPERATOR" style="background-color: gainsboro;" class="form-control-sm col-sm-2 fontInput small bg-default mt-3 text-center" disabled>
                                                    </div>

                                                    <div class="col-sm-12 invoice-col pt-0">
                                                        <form action="" method="post">

                                                            <div class="row mx-3 mt-0">
                                                                <div class="col-md-6">
                                                                    <div class="card-body mt-4 px-2 mx-3">
                                                                        <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="" 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="">--Pilih Jenis Kelamin--</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="" 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="" placeholder="email@mail.com" name="email">

                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="col-md-6">
                                                                    <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="" 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">
                                                                            </div>
                                                                        </div>
                                                                        <div class="row">
                                                                            <label class="col-sm-3 col-form-label">Level User</label>
                                                                            <div class="col-md-7">
                                                                                <select name="level_user" class="form-control form-control-sm fontInput small" required>
                                                                                    <option value="">--Pilih Level User--</option>
                                                                                    <option value="admin">Admin</option>
                                                                                    <option value="teller">Teller</option>
                                                                                    <option value="bendahara">Bendahara</option>
                                                                                    <option value="monitoring">Monitoring</option>
                                                                                    <option value="tabungan">Tabungan</option>
                                                                                </select>
                                                                            </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('seting/userAdmin/user_read'); ?> 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>
                                                                </div>
                                                            </div>
                                                        </form>
                                                    </div>
                                                </div>
                                            </div>

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

<?php
if (isset($_POST['submit'])) {
    $id_user = substr(md5(htmlspecialchars($_POST['nama'])), 3, 20);
    $nama = htmlspecialchars($_POST['nama']);
    $kelamin = htmlspecialchars($_POST['kelamin']);
    $email = htmlspecialchars($_POST['email']);
    $hp = htmlspecialchars($_POST['hp']);
    $username_user = htmlspecialchars($_POST['username_user']);
    $password_user = md5($_POST['password_user']);
    $level_user = htmlspecialchars($_POST['level_user']);

    $user_admin = new crudData();

    $dataarray = [
        'id_user' => $id_user,
        'nama' => $nama,
        'kelamin' => $kelamin,
        'email' => $email,
        'hp' => $hp,
        'username' => $username_user,
        'password' => $password_user,
        'level' => $level_user,
        'status' => 'Aktif',
        'id' => $id_user
    ];
    $user_admin->insertData('user', $dataarray);

    $direct = new toast();
    echo  $direct->redirect('toast', 'save', 'seting/userAdmin/user_read');
} else {
    echo '';
}

?>