<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 nogol = ID;
		$.ajax({
			type	: "POST",
			url	: "modul/gol_akun/cari.php",
			data	: "nogol="+nogol,
			dataType	: "json",
			success	: function(data){
				$("#txt_nogol").val(nogol);
				$("#txt_nagol").val(data.nagol);
				$("#txt_kode").val(data.kode);
				$("#txt_nokel").val(data.nokel);
				$("#akses").val(data.akses);
				alert("Data sudah di tampung pada tab inputan, silahkan klik");
			}
		});
	}
	function hapus_data(ID){
		var pilih = confirm('Data yang akan dihapus kode = '+ID+ '?');
		if (pilih==true) {
		var nogol = ID;
		$.ajax({
			type	: "POST",
			url	: "modul/gol_akun/hapus.php",
			data	: "nogol="+nogol,
			success	: function(data){
				$("#info").html(data);
				$("#tampil_data").load('modul/gol_akun/tampil_data.php');
				$("#akses").val('');
			}
		});
		}
	}

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

$cari	  = $_GET[cari];
echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Golongan</th>
			<th>D/K</th>
			<th>Aksi</th>
		</tr>";
		
		if (!empty($cari)){
			$query1= "SELECT * FROM gol_akun WHERE (nagol LIKE '%$cari%' or nogol LIKE '%$cari%')";
		}
		else{
			$query1= "SELECT * FROM gol_akun";
		}
		$data1	= mysql_query($query1);
		$jml	= mysql_num_rows($data1);
		
		$query2= "SELECT * FROM gol_akun GROUP BY nokel";
		$data2	= mysql_query($query2);		
		while($r_data2=mysql_fetch_array($data2)){
			$nokel=$r_data2[nokel];

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

	echo "<table width='100%'>
		<tr>
			<td>Jumlah Data : $jml</td>
		</tr>
		</table>";
echo "</div>";
?>