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

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

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

if ($_GET[jns] == "editx") {
    mysql_query("update tbl_group_user set nm_bagian = '".$_GET[nm_group]."' where kd_group = ".$_GET[idx]);
    
   echo "<script language='JavaScript'>document.location='index2.php?p=$PID'</script>";
} elseif ($_GET[jns] == "tambahx") {
    $cek = getFromTable("select max(kd_group) + 1 from tbl_group_user");
    mysql_query("insert into tbl_group_user (kd_group,nm_bagian) values ($cek, '".$_GET[nm_group]."')"); 
    echo "<script language='JavaScript'>document.location='index2.php?p=$PID'</script>"; 
} elseif ($_GET[jns] == "edit" || $_GET[jns] == "tambah") {
    
    if($_GET[jns] == "edit"){
        $r = mysql_query("select * from tbl_group_user where kd_group = '".$_GET[idx]."'");
        $n = mysql_num_rows($r);
        if($n > 0) $d = mysql_fetch_object($r);
        mysql_free_result($r);
        
    } 
    ?>
    <form method="GET">
    <INPUT type="hidden" name="p" value="<?php echo $_GET[p];?>" />
    <INPUT type="hidden" name="idx" value="<?php echo $_GET[idx];?>" />
        <table width="40%" border="0">
            <tr>
                <td class="JUDUL_INPUT">Input Group</td>
                <td>&nbsp;</td>
            </tr>
            <?php if($_GET[jns] == "edit"){ ?>
            <INPUT type="hidden" name="jns" value="editx" />
            <tr>
                <td class="FORM_INPUT" width="40%">ID Group</td>
                <td class="FORM_INPUT" >: <input type="text" name="id" size = "40" value="<?php echo $d->kd_group;?>" readonly="readonly"></td>
            </tr>
            <?php } else { ?>
            <INPUT type="hidden" name="jns" value="tambahx" />
            <tr>
                <td class="FORM_INPUT" width="40%">ID Group</td>
                <td class="FORM_INPUT" >: <input type="text" name="id" size = "40" value="OTOMATIS" disabled="disabled"></td>
            </tr>
            <?php }  ?>
            
            <tr>
                <td class="FORM_INPUT">Name Group</td>
                <td class="FORM_INPUT" >: <input type="text" size = "40" name="nm_group" value="<?php echo $d->nm_bagian;?>" required="required"></td>
            </tr>
            <tr>
                <td class="FORM_INPUT">&nbsp;</td>
                <td class="FORM_INPUT" >: <input type="Submit" value="Simpan"></td>
            </tr>
        </table>
    </form>
    <?php
} else {
    $sql = "select * from tbl_group_user ";
    @$r1 = mysql_query($sql,$con);
    @$n1 = mysql_num_rows($r1);
    ?>
    <form method="GET" name="Form1">
    <INPUT type="hidden" name="p" value="<?php echo $_GET[p];?>" />
    <INPUT type="submit" style="display: none;" />
    <table border="1" width="100%" id='mytable' class="gridtable tableWithFloatingHeader">
        <tr>
            <th class="gridtable_th"><a href="<?php echo "$SC?p=$PID&jns=tambah"; ?>"><img src="images/icon-checklist.png" title="Tambah Kecamatan"/></a></th>
            <th class="gridtable_th">ID MASTER</th>
            <th class="gridtable_th">POSITION</th>
        </tr>
        <?php
            while (@$row = mysql_fetch_array($r1)) {
        ?>
        <tr>
            <td class="gridtable_td" align="center">
                <a href="<?php echo "$SC?p=$PID&jns=edit&idx=$row[kd_group]";?>"><img src="images/icon-edit.png" /></a>
                <a href="<?php echo "$SC?p=$PID&jns=aktif&idx=$row[kd_group]&stat=$row[status]";?>"><img src="images/icon-ok.png" /></a>
                <a href="<?php echo "$SC?p=$PID&jns=hapus&idx=$row[kd_group]";?>"><img src="images/icon-delete.png" /></a>
            </td>
            <td class="gridtable_td"><?php echo $row["kd_group"];?></td>
            <td class="gridtable_td"><?php echo ucwords(strtolower($row["nm_bagian"]));?></td>
        </tr>
        <?php
            }
        ?>
    </table>
    </form>
    <?php
}

?>