<?php
function query_user($name, $defval, $ext = ""){
    $sql = "select * from tbl_group_user where kd_group != 0 order by nm_bagian";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[0] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[0]'>$d[1]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}

function query_inisial($name, $defval, $ext = ""){
    $sql = "select * from tbl_referensi where id != '000' and kd = 'INS' ";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[0] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[0]'>$d[2]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}

function query_negara($name, $defval, $ext = ""){
    $sql = "select * from tbl_referensi where id != '000' and kd = 'NGR' ";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[0] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[0]'>$d[2]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}

function query_jnskamar($name, $defval, $ext = ""){
    $sql = "select * from tbl_referensi where id != '000' and kd = 'ROM' ";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
	$gr_user .= '<OPTION value=""><OPTION>';
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[0] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[0]'>$d[2]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}

function query_carabayar($name, $defval, $ext = ""){
    $sql = "select * from tbl_referensi where id != '000' and kd = 'CAB' ";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[0] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[0]'>$d[2]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}

function query_carabayar2($name, $defval, $ext = ""){
    $sql = "select '' as id, '- All Method -' as keterangan union select id, keterangan from tbl_referensi where id != '000' and kd = 'CAB' ";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[id] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[id]'>$d[keterangan]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}

function query_materai($name, $defval, $ext = ""){
    $sql = "select * from tbl_referensi where id != '000' and kd = 'MAT' ";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[0] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[0]'>$d[2]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}

function query_alasan($name, $defval, $ext = ""){
    $sql = "select * from tbl_referensi where id != '000' and kd = 'ALS' ";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[0] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[0]'>$d[2]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}

function query_statbayar($name, $where,$defval, $ext = ""){
    $sql = "select * from tbl_referensi where id != '000' and kd = 'STP' $where ";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[0] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[0]'>$d[2]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}

function query_pointsale($name, $defval, $ext = ""){
    $sql = "select '' as keterangan2, '- All -' as keterangan union 
            select keterangan2, keterangan from tbl_referensi where id != '000' and kd = 'POS' ";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[keterangan2] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[keterangan2]'>$d[keterangan]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}

function query_jnsbayar($name, $defval, $ext = ""){
    $sql = "select '' as keterangan2, '- All -' as keterangan union 
            select keterangan2, keterangan from tbl_referensi where id != '000' and kd = 'JBY' ";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[keterangan2] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[keterangan2]'>$d[keterangan]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}


function query_referensi($name, $defval, $where,$ext = ""){
    $sql = "select '' as kd, '- All -' as keterangan union 
            select kd, keterangan from tbl_referensi where id = '000' $where ";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[kd] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[kd]'>$d[keterangan]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}

function query_jnsroom($name, $defval, $where,$ext = ""){
    $sql = "select '' as id, '- All -' as keterangan union 
            select id, keterangan from tbl_referensi where id != '000' and kd = 'ROM' $where ";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[id] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[id]'>$d[keterangan]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}

function query_jnsguest($name, $defval, $where,$ext = ""){
    $sql = "select id, keterangan from tbl_referensi where id != '000' and kd = 'JPG' $where ";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[id] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[id]'>$d[keterangan]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}

function query_master_pos($name, $defval, $ext = ""){
    $sql = "select '' as id, '- All -' as keterangan union 
            select id, keterangan from tbl_referensi where id != '000' and kd = 'POS' ";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[id] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[id]'>$d[keterangan]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}


function query_jns_layanan($name, $defval, $ext = ""){
    $sql = "select keterangan, keterangan from tbl_referensi where id != '000' and kd = 'JPS' ";
    $gr_user = "<SELECT $ext NAME=$name  >\n";
    $r = @mysql_query($sql);
    while($d = @mysql_fetch_array($r)) {
        $gr_user .= "<OPTION ";
        if($d[keterangan] == $defval) 
        $gr_user .= "SELECTED ";
        $gr_user .= "VALUE='$d[keterangan]'>$d[keterangan]</OPTION>\n";
    }
    @mysql_free_result($r);
    $gr_user .= "</SELECT>\n";
    return $gr_user."\n";
}
?>