<script type="text/javascript">
$(document).ready(function() {
    $(function() {
        $("#theList tr:even").addClass("stripe1");
        $("#theList tr:odd").addClass("stripe2");

        $("#theList tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });	
});

	function edit_data(ID){
		
		var user = ID;
		$.ajax({
			type		: "POST",
			url		: "spv/users/cari.php",
			data	: "user="+user,
			dataType	: "json",
			success	: function(data){
				$("#txt_user").val(user);				
				$("#txt_nama").val(data.nama);
				
				if(data.level=='Direktur') {
					$("#radio_admin").attr("checked","checked");
				}
				$("#info").html("Data sudah di tampung pada tab inputan, silahkan klik");
			}
		});
	}
	
	function hapus_data(ID){	
		var pilih = confirm('Data yang akan dihapus user = '+ID+ '?');
		if (pilih==true) {
		var user = ID;
		$.ajax({
			type		: "POST",
			url		: "spv/users/hapus.php",
			data	: "user="+user,
			success	: function(data){
				$("#info").html(data);
				$("#tampil_data").load('spv/users/tampil_data.php');
			}
		});
		}
	}

</script>
<?php
include '../../inc/inc.koneksi.php';
$level	= $_GET['level'];
$cari	= $_GET['cari'];
$hal	= $_GET['hal'] ? $_GET['hal'] : 0;
$lim	= 15;
	if (!empty($level)){
		if($level=='All'){
			$query2	= "SELECT * FROM admins";
		}
		else{
			$query2	= "SELECT * FROM admins WHERE level='$level'";
		}
	}
	else{
		$query2	= "SELECT * FROM admins";
	}
	$data2	= mysql_query($query2);
	
echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>User Name</th>
			<th>Nama Lengkap</th>
			<th>Level</th>
			<th>IP Address</th>
			<th>Aksi</th>
		</tr>";
	if (!empty($level)){
		if($level=='All'){
			$sql	= "SELECT * FROM admins ORDER BY username";
		}
		else{
			$sql	= "SELECT * FROM admins WHERE level='$level' ORDER BY username";
		}
	}
	else{
		$sql	= "SELECT * FROM admins ORDER BY username";
	}
						
		//echo $sql;
		$query = mysql_query($sql);
		
		$no=1;
		while($r_data=mysql_fetch_array($query)){
			echo "<tr>
				<td align='center'>$no</td>
				<td>$r_data[username]</td>
				<td>$r_data[nama_lengkap]</td>
				<td>$r_data[level]</td>
				<td align='center'>$r_data[ipaddress]</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"edit_data('$r_data[username]')\">
						<img src='icon/thumb_up.png' border='0' id='edit' title='Edit' width='12' height='12' >
					</a>
					<a href='javascript:void(0)' onClick=\"hapus_data('$r_data[username]')\">
						<img src='icon/thumb_down.png' border='0' id='hapus' title='Hapus' width='12' height='12' >
					</a>					
				</td>
			</tr>";
			$no++;
		}
	echo "</table>";
?>