<?php 
$PID = "master_kamar";
$SC = $_SERVER["SCRIPT_NAME"];

require_once("lib/dbconn.php");
require_once("lib/form.php");
require_once("lib/functions.php");
require_once("lib/function_query.php");

if (strlen($_GET[jns]) > 0 ) {
	$ket = getFromTable("select keterangan from tbl_referensi where id = '000' and kd = '".$_GET[jns]."'");
}

title("<img src='images/judul-setting.png' width='65' align='absmiddle' >  Master Referensi $ket");
echo "<BR>";

if($_POST[actions] == "tambah"){
	$cek1 = getFromTable("select count(kd) from tbl_referensi where kd = '".$_POST[jns]."'");
	$cek2 = str_pad(((int) $cek1), 3, "0", STR_PAD_LEFT);
	
	mysql_query("insert into tbl_referensi (id, kd, keterangan) values ('$cek2', '".$_POST[jns]."', '".$_POST[ket]."')");
	//echo "insert into tbl_referensi (id, kd, keterangan) values ('$cek2', '".$_POST[jns]."', '".$_POST[ket]."')";
	echo "<script language='JavaScript'>document.location='$SC?p=$PID&jns=".$_POST[jns]."'</script>";
}



if ($_GET[act] == "tambah") {
    
    ?>
    <form method="POST">
    <input type="hidden" name="p" value="<?php echo $_GET[p];?>" />
    <input type="hidden" name="jns" value="<?php echo $_GET[jns];?>" />
    <input type="hidden" name="actions" value="tambah" />
        <table width="40%" border="0" class="gridtable_form">
            <tr>
                <td>Description</td>
                <td>: <input type="text" name="ket" value="" required="required"></td>   
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>: <input type="submit" value="Simpan"></td>   
            </tr>
        </table>
    </form>
    <?php
} else {
    ?>
    <div class="ui three column stackable grid">
  		<div class="column">
		<h4 class="ui top attached block header">Select Type</h4>
		<form>
			<input type="hidden" name="p" value="<?php echo $PID;?>"/>
			<?php echo query_referensi("jns",$_GET[jns]," and kd not in ('ROM') "," onChange='submit()'");?>
		</form> 
		</div>
	</div>
		
    <?php
    $sql = "select * from tbl_referensi where kd = '".$_GET[jns]."' and id != '000' ";
    @$r1 = mysql_query($sql,$con);
    @$n1 = mysql_num_rows($r1);
    ?>
    <table border="1" width="100%" id='mytable' class="gridtable tableWithFloatingHeader">
        <tr>
            <th class="gridtable_th">
            <?php if (strlen($_GET[jns]) > 0 ) { ?>
            <a href="<?php echo "$SC?p=$PID&act=tambah&jns=$_GET[jns]"; ?>"><img src="images/icon-checklist.png" title="Tambah Kecamatan"/></a>
            <?php } else { echo "&nbsp;"; } ?>
            </th>
            <th class="gridtable_th">ID</th>
            <th class="gridtable_th">TYPE</th>
            <th class="gridtable_th">DESCRIPTION</th>
        </tr>
        <?php
            while (@$row = mysql_fetch_array($r1)) {
        ?>
        <tr>
            <td class="gridtable_td" align="center">
                <a href="<?php echo "$SC?p=$PID&act=hapus&idx=$row[id]&jns=$_GET[jns]";?>"><img src="images/icon-delete.png" /></a>
            </td>
            <td class="gridtable_td" align="center"><?php echo $row["id"];?></td>
            <td class="gridtable_td" align="center"><?php echo $row["kd"];?></td>
            <td class="gridtable_td"><?php echo ucwords(strtolower($row["keterangan"]));?></td>
        </tr>
        <?php
            }
        ?>
    </table>
    <?php
}
?>
