<?php foreach($kontak as $kontak) :   endforeach; ?>
<?php foreach($admin_login as $user) :   endforeach; ?> 
<?php 
	$username = $this->session->userdata("username");  
	$this->db->where('username',$username);
	$query = $this->db->get('tb_admin');
	$row = $query->row();

	$level = $row->level;

?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
	<!-- Content Header (Page header) -->
	<div class="content-header">
		<div class="container-fluid">
			<div class="row mb-2">
				<div class="col-sm-6">
					<h1 class="m-0 text-dark"> 
						<?php echo $title1; ?>
					</h1>
				</div><!-- /.col -->
				<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"><?php echo $title1; ?></li>
					</ol>
				</div><!-- /.col -->
			</div><!-- /.row -->
		</div><!-- /.container-fluid -->
	</div>
	<!-- /.content-header -->
	
	
	<!-- Main content -->
	<section class="content">
		<div class="container-fluid">
			<div class="card">
				<div class="card-header">
					<?php  
					if($level =='manager' ){
						?>  
						<button type="button" class="btn btn-info" data-toggle="modal" data-target="#modal-default">
							<i class="fa fa-plus"></i> Tambah Data
						</button>
					<?php }  ?>

				</div>
				<!-- /.card-header -->
				<div class="card-body">
					<table id="example1" class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>Foto</th>
								<th>Username</th>
								<th>Nama Admin</th>
								<th>Email</th>
								<th>Level</th>
								<th>Lokasi Tugas</th>
								<th>Aksi</th>
								
							</tr>
						</thead>
						<tbody>
							<?php foreach($admin as $rows) : ?> 
								<tr>
									<td><img width="50px" src="<?php echo base_url();?>images/admin/<?php  echo $rows->foto;   ?>" alt="<?php  echo $rows->foto;   ?>" class="brand-image img-circle elevation-2" style="opacity: .8"></td> 
									<td><?php echo $rows->username; ?></td>
									<td><?php echo $rows->nama_admin; ?></td>
									<td><?php echo $rows->email; ?></td>
									<td> <?php echo $rows->level; ?></td>
									<td> <?php 
									$id_kantor = $rows->id_kantor; 
									$sql_menu = "SELECT * FROM tb_kantor WHERE  id_kantor = '$id_kantor' ";
									$main_menu = $this->db->query($sql_menu)->result();
									foreach ($main_menu as $main) {
										echo $main->nama_kantor;
										$id_nama_kantor= $main->id_kantor;
										$tampil_nama_kantor= $main->nama_kantor;
										
									}
									?></td>
									<td>
										
									
										<?php  
										if($level =='manager' ){
											?>  
										<a href=""  type="button" data-toggle="modal" data-target="#modal-edit<?php echo $rows->id; ?>"><i class="fa fa-edit"></i></a> | 
											<?php  
										     	$akun = $this->session->userdata("username");
											if($akun =='rohim118899@gmail.com' ){
												?>  
										<a href="" style="color: green;"   type="button" data-toggle="modal" data-target="#modal-reset<?php echo $rows->id; ?>"><i class="fa fa-key"></i></a> |
												<?php } ?>


										<?php } ?>
										<a href="" style="color: red;"  type="button"  data-toggle="modal" data-target="#modal-hapus<?php echo $rows->id; ?>"><i class="fa fa-trash"></i></a>
										
										<!-- Edit -->
										<form class="form-horizontal" action="<?php echo base_url('admin/code_ubah'); ?>" method="POST" enctype="multipart/form-data" />  
											<div class="modal fade" id="modal-edit<?php echo $rows->id; ?>">
												<div class="modal-dialog">
													<div class="modal-content">
														<div class="modal-header">
															<h4 class="modal-title">Edit Data <?php echo $rows->nama_admin; ?></h4>
															<button type="button" class="close" data-dismiss="modal" aria-label="Close">
																<span aria-hidden="true">&times;</span>
															</button>
														</div>
														<div class="modal-body">
															
															<!-- id kirim -->
															<input type="hidden" name="id" value="<?php echo $rows->id; ?>">
															<div class="form-group">
																<label for="exampleInputEmail1">Nama Admin</label>
																<input type="text" class="form-control" value="<?php echo $rows->nama_admin; ?>" id="exampleInputEmail1" name="nama_admin" placeholder="">
															</div>
															<div class="form-group">
																<label for="exampleInputPassword1">Level</label>
																<select class="form-control" id="exampleInputPassword1" name="level">
																	<option value="<?php echo $rows->level; ?>"><?php echo $rows->level; ?></option>
																	<option value="kasir">kasir</option>
																	<option value="admin">admin</option>
																	<option value="manager">manager</option>

																</select>  
															</div>
															<div class="form-group">
																<label for="exampleInputPassword1">Posisi Kantor</label>
																<select class="form-control" id="exampleInputPassword1" name="id_kantor">


																	<option value="<?php echo $id_nama_kantor; ?>">  <?php echo $tampil_nama_kantor; ?> </option>

																	




																	<?php foreach($kantor as $kantor2) : ?>
																		<option value=" <?php echo $kantor2->id_kantor; ?>"><?php echo $kantor2->nama_kantor; ?></option>
																	<?php endforeach; ?> 

																</select>  
															</div>
															<div class="form-group">
																<label for="exampleInputFile">File Foto</label>
																<div class="input-group">

																	<input type="file" name="foto">


																</div>
															</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>
													</div>
													<!-- /.modal-content -->
												</div>
												<!-- /.modal-dialog -->
											</div>
										</form>

										<!-- Hapus -->
										
										<form class="form-horizontal" action="<?php echo base_url('admin/code_hapus'); ?>" method="POST" enctype="multipart/form-data" />  
											<div class="modal fade" id="modal-hapus<?php echo $rows->id; ?>">
												<div class="modal-dialog">
													<div class="modal-content bg-danger">
														<div class="modal-header">
															<h4 class="modal-title">Hapus Data </h4>
															<button type="button" class="close" data-dismiss="modal" aria-label="Close">
																<span aria-hidden="true">&times;</span>
															</button>
														</div>
														<div class="modal-body">
															<h4>Apakah Yakin Menghapus Data Ini, <?php echo $rows->nama_admin; ?> ?</h4>
															<!-- id kirim -->
															<input type="hidden" name="id" value="<?php echo $rows->id; ?>">
															
															
														</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">Hapus</button>
														</div>
													</div>
													<!-- /.modal-content -->
												</div>
												<!-- /.modal-dialog -->
											</div>
										</form>
										<form class="form-horizontal" action="<?php echo base_url('admin/code_reset_password'); ?>" method="POST" enctype="multipart/form-data" />  
											<div class="modal fade" id="modal-reset<?php echo $rows->id; ?>">
												<div class="modal-dialog">
													<div class="modal-content">
														<div class="modal-header">
															<h4 class="modal-title">Reset Password   <?php echo $rows->nama_admin; ?></h4>
															<button type="button" class="close" data-dismiss="modal" aria-label="Close">
																<span aria-hidden="true">&times;</span>
															</button>
														</div>
														<div class="modal-body">
															
															<!-- id kirim -->
															<input type="hidden" name="id" value="<?php echo $rows->id; ?>">
															<div class="form-group">
																<label class="control-label">Password Baru</label>
																<div class="col-md-9">                                            
																	<div class="input-group">

																		<input type="Password"  class="form-control" name="new_password"   required="" />
																	</div>                                            

																</div>
															</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>
													</div>
													<!-- /.modal-content -->
												</div>
												<!-- /.modal-dialog -->
											</div>
										</form>

									</td>
								</tr>
							<?php  endforeach; ?>

						</tbody>

					</table>
				</div>
				<!-- /.card-body -->
			</div>
		</div><!-- /.container-fluid -->
	</section>
	<!-- /.content -->
</div>
<!-- /.content-wrapper -->

<!-- Modal Tambah Data -->
<form class="form-horizontal" action="<?php echo base_url('admin/code_tambah'); ?>" method="POST" enctype="multipart/form-data" />  
	<div class="modal fade" id="modal-default">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<h4 class="modal-title">Tambah Data</h4>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<div class="modal-body">
					<div class="form-group">
						<label for="exampleInputEmail1">Nama Admin</label>
						<input type="text" class="form-control" id="exampleInputEmail1" name="nama_admin" placeholder="Isikan Nama Admin">
					</div>
					<div class="form-group">
						<label for="exampleInputEmail1">Email Admin</label>
						<input type="email" class="form-control" id="exampleInputEmail1" name="email" placeholder="Email akan otomatis menjadi username">
					</div>
					<div class="form-group">
						<label for="exampleInputPassword1">Password</label>
						<input type="password" class="form-control" id="exampleInputPassword1" name="password" placeholder="Password">
					</div>
					<div class="form-group">
						<label for="exampleInputPassword1">Level</label>
						<select class="form-control" id="exampleInputPassword1" name="level">
							<option value="kasir">kasir</option>
							<option value="admin">admin</option>
							<option value="manager">manager</option>

						</select>  
					</div>
					<div class="form-group">
						<label for="exampleInputPassword1">Posisi Kantor</label>
						<select class="form-control" id="exampleInputPassword1" name="id_kantor">
							<?php foreach($kantor as $kantor1) : ?>
								<option value=" <?php echo $kantor1->id_kantor; ?>"> <?php echo $kantor1->nama_kantor; ?></option>
							<?php endforeach; ?> 

						</select>  
					</div>
					<div class="form-group">
						<label for="exampleInputFile">File Foto</label>
						<div class="input-group">
							
							<input type="file" name="foto">
							

						</div>
					</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>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
</form>