<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>DATA PENGGUNA</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="#">Home</a></li>
                        <li class="breadcrumb-item active">DATA PENGGUNA</li>
                    </ol>
                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content centered">
        <div class="container-fluid ">
            <div class="row">
                <!-- left column -->
                <div class="col-md-12">
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">Data Pengguna</h3>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body">
                            <table id="table-pgn" class="table table-bordered table-striped">
                                <thead>
                                    <tr class="text-center">
                                        <th>No</th>
                                        <th>Nama</th>
                                        <th>Email</th>
                                        <th>Role</th>
                                        <?php if ($pengguna['role_id'] == 1) : ?>
                                            <th>Status</th>
                                        <?php endif ?>
                                        <?php if ($pengguna['role_id'] == 1) : ?>
                                            <th>Aksi</th>
                                        <?php endif ?>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $no = 1 ?>
                                    <?php foreach ($pgn as $u) {
                                    ?>
                                        <tr>
                                            <td><?= $no++ ?></td>
                                            <td><?= $u->username ?></td>
                                            <td><?= $u->email ?></td>

                                            <?php if ($u->role_id == 1) : ?>
                                                <td>Admin</td>
                                            <?php else : ?>
                                                <td>Pengguna</td>
                                            <?php endif; ?>
                                            <?php if ($pengguna['role_id'] == 1) : ?>
                                                <?php if ($u->status == 1) : ?>
                                                    <td>Aktif</td>
                                                <?php else : ?>
                                                    <td>Non-Aktif</td>
                                                <?php endif; ?>
                                            <?php endif; ?>
                                            <?php if ($pengguna['role_id'] == 1) : ?>
                                                <td class="text-center"><a class="btn btn-info ubahpengguna btn-sm mb-2" data-idpgn="<?= $u->idpgn ?>" data-toggle="modal" data-target="#modal-ubahpengguna" href="">
                                                        <i class="fas fa-pencil-alt">
                                                        </i>
                                                        Ubah Data Pengguna
                                                    </a>
                                                    <a class="btn btn-danger hapuspengguna btn-sm mb-2" href="<?= base_url(''); ?>kelola_pengguna/deletepengguna/<?= $u->idpgn ?>"">
                                                        <i class=" fas fa-trash">
                                                        </i>
                                                        Hapus Data Pengguna
                                                    </a>
                                                </td>
                                            <?php endif ?>

                                        </tr>
                                    <?php } ?>
                                </tbody>
                                <!-- <tfoot>
                                    <tr>
                                        <th>Rendering engine</th>
                                        <th>Browser</th>
                                        <th>Platform(s)</th>
                                        <th>Engine version</th>
                                        <th>CSS grade</th>
                                    </tr>
                                </tfoot> -->
                            </table>
                        </div>
                        <!-- /.card-body -->
                    </div>

                </div>

            </div>

            <!-- <div class="row">
                <div class="col-12 mb-2">
                    <a href="<?= base_url() ?>" class="btn btn-secondary">Cancel</a>
                    <a href="<?= base_url() ?>tambah_ruta/lanjutan" class="btn btn-success float-right">Selanjutnnya</a>
                </div>
            </div> -->
        </div><!-- /.container-fluid -->
    </section>

    <!-- /.content -->
</div>
<div class="modal fade" id="modal-ubahpengguna">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Ubah Data Pengguna</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" method="post" action="<?= base_url(''); ?>kelola_pengguna/ubahpengguna">
                    <div class="card-body">
                        <input type="hidden" class="form-control" name="id2" id="id2" placeholder="id2">
                        <div class="form-group">
                            <label for="kabupaten">Email</label>
                            <input type="email" class="form-control" name="email2" id="email2" placeholder="Email">
                            <?= form_error('email2', '<small class ="text-danger pl-3">', '</small>'); ?>
                        </div>
                        <div class="form-group">
                            <label for="kabupaten">Username</label>
                            <input type="text" class="form-control" name="username2" id="username2" placeholder="username">
                            <?= form_error('username2', '<small class ="text-danger pl-3">', '</small>'); ?>
                        </div>
                        <div class="form-group">
                            <label for="role">Role</label>
                            <select class="select form-control role" id="role2" name="role2" tabindex="-1">
                                <option disabled selected value="0">Pilih Role</option>
                                <option value="1">Admin</option>
                                <option value="2">Pengguna</option>
                            </select>
                            <?= form_error('role', '<small class ="text-danger pl-3">', '</small>'); ?>
                        </div>
                        <div class="form-group">
                            <label for="status">Status</label>
                            <select class="select form-control status" id="status2" name="status2" tabindex="-1">
                                <option disabled selected value="0">Pilih Status</option>
                                <option value="1">Aktif</option>
                                <option value="2">Non-Aktif</option>
                            </select>
                            <?= form_error('status', '<small class ="text-danger pl-3">', '</small>'); ?>
                        </div>

                    </div>
                    <div class="modal-footer justify-content-between">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-primary">Simpan</button>
                    </div>
                </form>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<?php
if (isset($_SESSION['informasi'])) {
    echo $_SESSION['informasi'];
    unset($_SESSION['informasi']);
}
?>
<?php
if (isset($_SESSION['error'])) {
    echo $_SESSION['error'];
    unset($_SESSION['error']);
}
?>