<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 noakun = ID;
		
		$.ajax({
			type		: "POST",
			url		: "modul/akun_bb/cari.php",
			data	: "noakun="+noakun,
			dataType: "json",
			success	: function(data){
				$("#txt_noakun").val(noakun);
				$("#txt_naakun").val(data.naakun);
				$("#txt_kode").val(data.kode);
				$("#txt_level").val(data.level);
				$("#txt_nosub").val(data.nosub);
				$("#txt_nogol").val(data.nogol);
				$("#akses").val(data.akses);
				alert("Data sudah di tampung pada tab inputan, silahkan klik");
			}
		});
	}
	
	function hapus_data(ID){
		var pilih = confirm('Data akun yang akan dihapus kode = '+ID+ '?');
		if (pilih==true) {
		var noakun = ID;
		$.ajax({
			type		: "POST",
			url		: "modul/akun_bb/hapus.php",
			data	: "noakun="+noakun,
			success	: function(data){
				$("#info").html(data);
				$("#tampil_data_ak").load('modul/akun_bb/tampil_data_ak.php');
				$("#akses").val('');
			}
		});
		}
	}

</script>
<?php
include '../../inc/inc.koneksi.php';

$cari= $_GET[cari];
echo "<table id='theList' width='100%'>
		<tr>			
			<th>Kode</th>
			<th>Nama Akun</th>
			<th>Level</th>
			<th>D/K</th>
			<th>Aksi</th>
		</tr>";
		
		if(!empty($cari))
			$query1= "SELECT nogol FROM akun_bb WHERE (naakun LIKE '%$cari%' or noakun LIKE '%$cari%') GROUP BY nogol";
		else
			$query1= "SELECT nogol FROM akun_bb GROUP BY nogol";

		$data1	= mysql_query($query1);
		$jml=1;		
		while($r1=mysql_fetch_array($data1)){
			$nogol=$r1[nogol];
			
			$sql		= mysql_query("SELECT * FROM gol_akun WHERE nogol='$nogol' ");
			$data	= mysql_fetch_assoc($sql);
			$nagol= $data[nagol];

			echo "<tr>
				<td><b>$nogol</b></td>			
				<td><b>$nagol</b></td>
			</tr>";
			
			if (!empty($cari))
				$query= mysql_query("SELECT * FROM akun_bb WHERE (naakun LIKE '%$cari%' or noakun LIKE '%$cari%') AND nogol='$nogol' ORDER BY noakun");
			else
				$query= mysql_query("SELECT * FROM akun_bb WHERE nogol='$nogol' ORDER BY noakun");
					
			while($r=mysql_fetch_array($query)){
				
				echo "<tr>					
					<td>$r[noakun]</td>
					<td>$r[naakun]</td>
					<td align='center'>$r[level]</td>
					<td align='center'>$r[kode]</td>
					<td align='center'>
						<a href='javascript:void(0)' onClick=\"edit_data('$r[noakun]')\">
							<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[noakun]')\">
							<img src='icon/thumb_down.png' border='0' id='hapus' title='Hapus' width='12' height='12' >
						</a>					
					</td>
				</tr>";				
				$jml++;
			}
		}	
	echo "</table>
	<table width='100%'>
		<tr>
			<td>Jumlah Data : $jml</td>
		</tr>
	</table>";
?>