<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	    : "md_dir/users/cari.php",
			data	: "user="+user,
			dataType: "json",
			success	: function(data){
				$("#txt_user").val(user);
				$("#txt_kodecab").val(data.kodecab);
				$("#txt_nama").val(data.nama);
				$("#txt_status").val(data.stat);
				$("#txt_level").val(data.level);
				$("#txt_jamawal").val(data.jamawal);
				$("#txt_jamakhir").val(data.jamakhir);
				$("#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'];
$kodecab= $_GET['kodecab'];

echo "<table id='theList' width='100%'>
		<tr>
			<th width='2%'>No.</th>
			<th>User Name</th>
			<th>Nama Lengkap</th>
			<th>Cabang</th>
			<th>Level</th>
			<th>IP Address</th>
			<th>Status</th>
			<th>Jam Akses</th>
			<th>Aksi</th>
		</tr>";
		
		if(!empty($level)){
			if($level=='All'){
			    if($kodecab=='')
				    $sql= "SELECT * FROM admins ORDER BY username";
				else
				    $sql= "SELECT * FROM admins WHERE kode_cab='$kodecab' ORDER BY username";
			}else{
			    if($kodecab=='')
			        $sql= "SELECT * FROM admins WHERE level='$level' ORDER BY username";
			    else
			        $sql= "SELECT * FROM admins WHERE level='$level' AND kode_cab='$kodecab' ORDER BY username";
			}
		}
		else{
		    if($kodecab=='')
		        $sql= "SELECT * FROM admins WHERE 1 ORDER BY username";
		    else
		        $sql= "SELECT * FROM admins WHERE kode_cab='$kodecab' ORDER BY username";
		        
		}
		$query = mysql_query($sql);
		
		$no=1;
		while($r=mysql_fetch_array($query)){
		    $kodecab= $r['kode_cab'];
		    
		    $sql1   = mysql_query("SELECT * FROM cabang WHERE kode_cab='$kodecab' ");
		    $r1     = mysql_fetch_assoc($sql1);
		    $namacab= $r1['nama_cab'];
		    
			echo "<tr>
				<td align='center'>$no</td>
				<td>$r[username]</td>
				<td>$r[nama_lengkap]</td>
				<td>$namacab</td>
				<td>$r[level]</td>
				<td align='center'>$r[ipaddress]</td>
				<td>$r[status]</td>
				<td>$r[jam_awal] - $r[jam_akhir]</td>
				<td align='center'>
				    <a href='javascript:void(0)' onClick=\"edit_data('$r[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[username]')\">
					<img src='icon/thumb_down.png' border='0' id='hapus' title='Hapus' width='12' height='12' >
					</a>					
				</td>
			</tr>";
			$no++;
		}
	echo "</table>";
?>