<?php 
$PID = "master_menu";
$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");


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

if ($_GET[jns] == "hapus") {
    mysql_query("delete from tbl_group_menu where kd_rule = ".$_GET[idx]);
    ECho "<script language='JavaScript'>document.location='index2.php?p=$PID&gr=$_GET[gr]'</script>";
}elseif ($_GET[jns] == "tambah") {
    
    $sql = "select a.* 
            from tbl_menu a 
            left JOIN tbl_group_menu b on b.kode_menu = a.kd_menu and b.kd_group_user = ".$_GET[gr]."
            where a.is_group = 'N' and b.kode_menu IS NULL order by kd_menu";
    @$r1 = mysql_query($sql);
    @$n1 = mysql_num_rows($r1);
    
    ?>
    <form action="actions/master_menu_actions.php" method="POST">
    <INPUT type="hidden" name="p" value="<?php echo $_GET[p];?>" />
    <INPUT type="hidden" name="gr" value="<?php echo $_GET[gr];?>" />
        <table width="40%" border="0">
            <tr>
                <td class="JUDUL_INPUT">Select Access</td>
                <td>&nbsp;</td>
            </tr>
            <?php
            while (@$row = mysql_fetch_array($r1)) {
                ?>
            <tr>
                <td class="FORM_INPUT" align="right"><input type="checkbox" name="id[]" value="<?php echo $row[kd_menu];?>"></td>
                <td class="FORM_INPUT">: <?php echo $row[nama_menu];?></td>   
            </tr>
            <?php
            }
            ?>
            <tr>
                <td class="FORM_INPUT" align="right">&nbsp;</td>
                <td class="FORM_INPUT">: <input type="submit" value="Simpan"></td>   
            </tr>
        </table>
    </form>
    <?php
} else {
    ?>
    <form method="GET" name="Form1">
        <INPUT type="hidden" name="p" value="<?php echo $_GET[p];?>" />
        <table width="40%" border="0">
            <tr>
                <td class="JUDUL_INPUT" colspan="2">Search</td>
            </tr>
            <tr>
                <td class="FORM_INPUT" align="right" width="20%">Group User</td>
                <td class="FORM_INPUT">: <?php echo query_user("gr",$_GET[gr]);?></td>   
            </tr>
            <tr>
                <td class="FORM_INPUT">&nbsp;</td>
                <td class="FORM_INPUT" >: <input type="Submit" value="Cari"></td>
            </tr>
        </table>
    </form>  
    <?php
    $sql = "select a.*, b.nama_menu from tbl_group_menu a join tbl_menu b on b.kd_menu = a.kode_menu where a.kd_group_user = ".$_GET[gr];
    @$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"><a href="<?php echo "$SC?p=$PID&jns=tambah&gr=$_GET[gr]"; ?>"><img src="images/icon-checklist.png" title="Tambah Kecamatan"/></a></th>
            <th class="gridtable_th">ID MASTER</th>
            <th class="gridtable_th">MENU</th>
        </tr>
        <?php
            while (@$row = mysql_fetch_array($r1)) {
        ?>
        <tr>
            <td class="gridtable_td" align="center">
                <a href="<?php echo "$SC?p=$PID&jns=hapus&idx=$row[kd_rule]&gr=$_GET[gr]";?>"><img src="images/icon-delete.png" /></a>
            </td>
            <td class="gridtable_td"><?php echo $row["kode_menu"];?></td>
            <td class="gridtable_td"><?php echo ucwords(strtolower($row["nama_menu"]));?></td>
        </tr>
        <?php
            }
        ?>
    </table>
    <?php
}

?>
