<?php
// panggil berkas koneksi.php
require 'koneksi2.php';

// buat koneksi ke database mysql
koneksi_buka();

?>

<table class="table table-condensed table-bordered table-hover" cellpadding="0" cellspacing="0">
<thead>
	<tr>
		<th style="width:20px">#</th>
		<th style="width:120px">No. Registrasi</th>
		<th style="width:200px">Nama</th>
		<th>NIP Baru</th>
		
		
		<th style="width:120px">Jabatan</th>
		<th style="width:120px">No HP</th>
		
		
		<th style="width:120px">Tempat Tugas</th>
		
		
		<th style="width:120px">Foto</th>
		<!-- <th style="width:120px">Formulir</th> -->
		<th style="width:250px">Aksi</th>
	</tr>
</thead>
<tbody>
	<?php 
		$i = 1;
		$jml_per_halaman = 10; // jumlah data yg ditampilkan perhalaman
		$jml_data = mysql_num_rows(mysql_query("SELECT * FROM tbl_user"));
		$jml_halaman = ceil($jml_data / $jml_per_halaman);
		// query pada saat mode pencarian
		if(isset($_POST['cari'])) {
			$kunci = $_POST['cari'];
			echo "<strong>Hasil pencarian untuk kata kunci $kunci</strong>";
			$query = mysql_query("
				SELECT * FROM tbl_user 
				WHERE nama_depan LIKE '%$kunci%' 
				OR nama_belakang LIKE '%$kunci%'
				OR email LIKE '%$kunci%'
				OR password LIKE '%$kunci%'
				OR kelamin LIKE '%$kunci%'
				OR unit_org LIKE '%$kunci%'
				
			");
		// query jika nomor halaman sudah ditentukan
		} elseif(isset($_POST['halaman'])) {
			$halaman = $_POST['halaman'];
			$i = ($halaman - 1) * $jml_per_halaman  + 1;
			$query = mysql_query("SELECT * FROM tbl_user LIMIT ".(($halaman - 1) * $jml_per_halaman).", $jml_per_halaman");
		// query ketika tidak ada parameter halaman maupun pencarian
		} else {
			$query = mysql_query("SELECT * FROM tbl_user LIMIT 0, $jml_per_halaman");
		}
		
		// tampilkan data mahasiswa selama masih ada
		while($data = mysql_fetch_array($query)) {
			if($data['status']==1) {
				$status = "Aktif";
			} else {
				$status = "Tidak Aktif";
			}
	?>
	<tr>
		<td><?php echo $i ?></td>
		<td><?php echo $data['email'] ?></td>
		<td><?php echo $data['nama_depan'] ?></td>
		<td><?php echo $data['nama_belakang'] ?></td>
		<td><?php echo $data['kelamin'] ?></td>
		<td><?php echo $data['password'] ?></td>
		
		<td><?php echo $data['unit_org'] ?></td>
		
		
		
		<td><a href="./photo/<?php echo $data['photo'];?>" target="_blank"><img src="./photo/<?php echo $data['photo'];?>" width="75" height="75" title="<?php echo $data['photo'];?>"></a></td>
		
		<!--
		<td><a href="./photo/<?php echo $data['photo'];?>" target="_blank"><img src="./photo/<?php echo $data['photo'];?>" width="75" height="75" title="<?php echo $data['photo'];?>"></a></td>
		
		-->
		
		
		<!-- 
		<td><?php echo $status ?></td>
		-->
		
		<td>
		
		<!--    starrrrr -->
		
		<a href="delete.php?id_user=<?php echo $data['id_user'];?>" onClick="return confirm('Apakah Anda yakin?')">Delete</a> |
		<a href="edit.php?id_user=<?php echo $data['id_user'];?>">Edit</a>
		
		
		<!--
		<td>
			<a href="#dialog-mahasiswa" id="<?php echo $data['id_user'] ?>" class="ubah" data-toggle="modal">
				<i class="icon-pencil"></i>
			</a>
			<a href="#" id="<?php echo $data['id_user'] ?>" class="hapus">
				<i class="icon-trash"></i>
			</a>
		</td>
		
		
		
		<!-- ennnnnnnndddd  -->
		
		
			
		</td>
	</tr>
	<?php
		$i++;
		}
	?>
</tbody>
</table>

<?php if(!isset($_POST['cari'])) { ?>
<!-- untuk menampilkan menu halaman -->
<div class="pagination pagination-right">
  <ul>
    <?php for($i = 1; $i <= $jml_halaman; $i++) { ?>
    <li class="halaman" id="<?php echo $i ?>"><a href="#"><?php echo $i ?></a></li>
    <?php } ?>
  </ul>
</div>
<?php } ?>

<?php 
// tutup koneksi ke database mysql
koneksi_tutup(); 
?>
