<?php
	if(isset($_SESSION["ses_id_tpk"])){
		$qry=mysqli_query($mysqli,"SELECT * FROM m_desa WHERE id_desa='$_SESSION[ses_id_desa]' ");
	}else{
		$qry=mysqli_query($mysqli,"SELECT * FROM m_desa ORDER BY id_kecamatan ASC, nama_desa ASC");
	}
	if($_SESSION["ses_admin_level"]=="ULP"){
		echo "<h3 align=\"right\" style=\"padding-right:10px\"><a href='?action=add_desa' style=\"color:#FF0066\">Tambah Data Desa</a></h3>";
	}
	
	if(mysqli_num_rows($qry)>0){
		
		$no=1;
		
		echo "<table width='100%' align='center' cellpadding='0' cellspacing='0' border='1' bgcolor='#C4D9FF'>";
		echo "<tr bgcolor='#fffccc'>
				<th>No.</th>
				<th>Kecamatan</th>
				<th>Desa</th>
				<th>Alamat Kantor</th>
				<th>Nomor Telepon</th>
				<th>Fax</th>
				<th>Email</th>
				<th>Opsi</th>
			  </tr>";	
		while($data=mysqli_fetch_array($qry)){
			$qryx=mysqli_query($mysqli,"SELECT * FROM m_kecamatan WHERE id_kecamatan='$data[id_kecamatan]'");
			$datax=mysqli_fetch_array($qryx);
			$nama_kecamatan=$datax["nama_kecamatan"];
			$link="";
			if($_SESSION["ses_admin_level"]=="TPK"){
				if($data["id_desa"]==$_SESSION["ses_id_desa"]){
					$link="<a href=\"?action=edit_desa&id_desa=$data[id_desa]\"><img src=\"images/edit.gif\" /></a>";
				}
			}elseif($_SESSION["ses_admin_level"]=="ULP"){
				$link="<a href=\"?action=edit_desa&id_desa=$data[id_desa]\"><img src=\"images/edit.gif\" /></a>&nbsp;|&nbsp;<a href=\"_del_desa.php?id_desa=$data[id_desa]\" onclick=\"return confirm('Yakin akan menghapus data Desa $data[nama_desa] ?')\"><img src=\"images/delete.gif\" /></a>";
			}
			echo "<tr bgcolor=\"#fffcfc\">
					<td align=\"center\">$no</td>
					<td>$nama_kecamatan</td>
					<td>$data[nama_desa]</td>
					<td>$data[alamat_kantor]</td>
					<td>$data[telp_kantor]</td>
					<td>$data[fax_kantor]</td>
					<td>$data[email_kantor]</td>
					<td align=\"center\">$link</td>
					
			     </tr>";
			$no++;  
		}
		
		echo "</table>";
	}else{
	
		echo "<table width='100%' align='center' cellpadding='0' cellspacing='0' border='1' bgcolor='#C4D9FF'>";
		echo "<tr bgcolor='#fffccc'>
				<th>No.</th>
				<th>Kecamatan</th>
				<th>Desa</th>
				<th>Alamat Kantor</th>
				<th>Nomor Telepon</th>
				<th>Fax</th>
				<th>Email</th>
				<th>Opsi</th>
			  </tr>";
		
		echo "<tr>
					<td colspan='8' align='center'>Tidak ditemukan data Desa</td>
			     </tr>";		
		echo "</table>";
	}
?>