<?php
$query = $this->db->query("SELECT * FROM user WHERE status=1 ORDER BY level")->result();
?>
<div class="content-wrapper">
	<section class="content-header">
		<div class="container-fluid">
			<div class="row mb-2">
				<div class="col-sm-6">
					<h1><?= $title; ?></h1>
				</div>
				<div class="col-sm-6">
					<ol class="breadcrumb float-sm-right">
						<li class="breadcrumb-item"><a href="#"><?= $root; ?></a></li>
						<li class="breadcrumb-item active"><?= $title; ?></li>
					</ol>
				</div>
			</div>
		</div><!-- /.container-fluid -->
	</section>
	<div class="container">
		<div class="card">
			<div class="card-header text-center">
				<h2>Kelola Data User</h2>
			</div>
			<div class="card-body">
				<?php echo $this->session->flashdata('message'); ?>
				<div class="row">
					<div class="col-2">
						<!-- Button trigger modal -->
						<button type="button" class="btn btn-primary btn-sm pd-left" data-toggle="modal" data-target="#exampleModal"><i class="fas fa-plus"></i>&nbsp;&nbsp;Tambah User</button>
                <!-- Modal -->
                <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                		 <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">Tambah Inventaris</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                    <form method="post" action="<?= base_url('admin/tambahuser'); ?>">
                            <div class="form-group">
                            <label for="exampleFormControlSelect1">Nama Lengkap</label>
							<input type="text" name="nama_lengkap" class="form-control" required="">
                             </div>
                             <div class="form-group">
                                    <label  id="kondisi" >Username</label>
                                    <input type="text" id="usernamedaftar" name="username" class="form-control usernamedaftar"  required="">
                            </div>
                            <div class="form-group">
                            <label for="exampleFormControlSelect1">Password</label>
							<input type="password" name="password" id="password" class="form-control" required="">
                             </div>
                             <div class="form-group">
                             <label for="exampleFormControlSelect1">Konfirmasi Password</label>
							 <input type="password" name="password2" id="password2" class="form-control" required="">
                            </div>
                            <div class="form-group">
                                <label for="exampleFormControlSelect1">NIP/NIS</label>
								<input type="text" id="nip" name="nip" class="form-control" onkeypress="return isNumberKey(event)" onkeyup="return ceknip()" required="">
                             </div>
							 <div class="form-group">
                                    <label  id="kondisi" >Level</label>
                                    <select class="form-control"name="level" id="FormControl" required="">
                                        <option>Admin</option>
                                        <option>Peminjam</option>
                                        <option>Kepala Sekolah</option>
                                    </select>
                            </div>
                             <div class="text-center">
                                    <button type="submit" class="btn btn-outline-success btn-user btn-block">Tambah User </button>
                            </div>
                    </form>
                    </div>
                   
                   </div>
               </div>
               </div>

            </div>
					</div>
					<div class="col-12"><br></div>
				</div>
				<div class="table-responsive">
					<table id="tabel" class="table table-bordered table-hover">
						<thead>
							<tr>
								<th>No.</th>
								<th>Nama Lengkap</th>
								<th>Username</th>
								<th>NIP</th>
								<th>Level</th>
								<th class="col-xs-2">Aksi</th>
							</tr>
						</thead>
						<tbody>
							<?php $no = 1; ?>
							<?php foreach ($query as $u) : ?>
								<tr>
									<td><?php echo $no++; ?></td>
									<td><?php echo $u->nama_lengkap; ?></td>
									<td><?php echo $u->username; ?></td>
									<td><?php echo $u->nip; ?></td>
									<td><?php echo $u->level; ?></td>
									<td>
										<?php if ($u->level == "Peminjam") : ?>
											<a href="<?php echo base_url('admin/deleteuser/' . $u->id_user) ?>" onclick="return confirm('Hapus?')" class="badge badge-danger">Hapus</a>
										<?php else : ?>
											<?php if ($u->id_user != $this->session->userdata('id_user')) : ?>
												<a href="<?php echo base_url('admin/deleteuser/' . $u->id_user) ?>" onclick="return confirm('Hapus?')" class="badge badge-danger">Hapus</a>
											<?php else : ?>
												<a href="<?php echo base_url('admin/myprofile/' . $this->session->userdata('id_user')) ?>" class="badge badge-primary">Profil Saya</a>
											<?php endif ?>
										<?php endif; ?>
									</td>
								</tr>
							<?php endforeach; ?>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>