<?php

class UctVw {
    var $direct_execute_sql = false;
    
    // version control variables
    var $script_version;
            
    // MySQL variables -------------------------
    var $id;
    var $form;
    var $mode;
    var $order;
    var $ordertype;
    var $status;
    var $modul_name;

    function strModule($modul_name) {
        $this->modul_name = $modul_name;
    }

    // properties variables -------------------------
    var $arrTL = array();
    var $arrTR = array();
    var $arrBL = array();
    var $arrBR = array();
    var $arrGrid = array();
    var $num_array_grid;
    var $num_rows_grid = array();
    // view variables -------------------------
    var $view_table;
    var $view_name;
    var $view_sql;
    var $view_caption;
    var $view_action;
    var $view_search;
    var $view_period;
    // form variables -------------------------
    var $form_name;
    var $form_sql;
    var $form_caption;
    var $form_position;
    var $form_locked;
    var $form_value;
    var $form_script;
    var $form_js;
    var $form_autonumber;
    var $form_hidden;
    var $form_save_method = "INSERT";
    var $form_layout;
    var $form_size;
    // grid variables -------------------------
    var $grid_type;
    var $grid_name;
    var $grid_sql;
    var $grid_caption;
    var $grid_size;
    //defaul size
    var $size_object = array("string" => "30",
                                "time" => "12",
                                "date" => "12",
                                "int" => "5",
                                "real" => "18",
                                "lookup2" => "30");
    var $grid_locked;
    var $grid_hidden;
    var $grid_script;
    var $grid_layout;
    var $grid_allowaddnew;
    var $grid_allowdelete;
    var $grid_allowupdate;
    var $grid_scroll;
    var $grid_scroll_width;
    var $grid_reindex = array();
    var $grid_auto_add = array();
    var $lengt_object = true;
    
    // lookup variables -------------------------
    var $lookup = array();
    var $lookup_grid;
    var $lookup_magic_quotes = False;
    
    // button variables -------------------------
    var $button = array("baru" => array("Baru", "icon_baru.png"),
                        "reset" => array("Reset", "icon_reset.png"),
                        "simpan" => array("Simpan", "icon_simpan.png"),
                        "simpan_revisi" => array("Simpan Revisi", "icon_kwitansi.png"),
                        "simpan_bank" => array("Simpan Bank", "icon_simpan.png"),
                        "simpan_penerimaan" => array("Simpan Penerimaan", "icon_simpan.png"),
                        "update" => array("Update", "icon_simpan.png"),
                        "update_status" => array("Update Status", "icon_simpan.png"),
                        "update_qty_limit" => array("Update Qty Limit", "icon_simpan.png"),
                        "update_qty_reject" => array("Update Qty Reject", "icon_simpan.png"),
                        "update_schedule_delivery" => array("Update Schedule Delivery", "icon_simpan.png"),
                        "update_waktu_pengajian" => array("Update Waktu Pengajian", "icon_simpan.png"),
                        "update_siap_bayar" => array("Update Status Siap Bayar", "icon_simpan.png") ,
                        "batal" => array("Batal", "icon_batal.png"),
                        "hapus" => array("Hapus", "icon_hapus.png"),
                        "tutup" => array("Tutup", "icon_tutup.png"),
                        "final" => array("Final", "icon_post.png"),
                        "final_approve" => array("Approve", "icon_post.png"),
                        "final_bank" => array("Final Bank", "icon_post.png"),
                        "final_penerimaan" => array("Final Penerimaan", "icon_post.png"),
                        "revisi" => array("Revisi", "icon_kwitansi.png"),
                        "close_po" => array("Close PO", "icon_post.png"),
                        "close_pr" => array("Close PR", "icon_post.png"),
                        "close_so" => array("Close SO", "icon_post.png"),
                        "post" => array("Post", "icon_post.png"),
                        "cetak" => array("Cetak", "icon_cetak.png"),
                        "cetak_so" => array("Cetak SO", "icon_cetak.png"),
                        "cetak_do" => array("Cetak DO", "icon_cetak.png"),
                        "cetak_si" => array("Cetak SI", "icon_cetak.png"),
                        "cetak_daftar" => array("Cetak Daftar", "icon_cetak.png"),
                        "cetak_non_harga" => array("Cetak Non Harga", "icon_cetak.png"),
                        "cetak_non_pt" => array("Cetak Non PT", "icon_cetak.png"),
                        "cetak_customer" => array("Cetak Customer", "icon_cetak.png"),
                        "cetak_sementara" => array("Cetak Sementara", "icon_cetak.png"),
                        "cetak_bank" => array("Cetak Bank", "icon_cetak.png"),
                        "cetak_penerimaan" => array("Cetak Penerimaan", "icon_cetak.png"),
                        "cetak_slip_crosstab" => array("Cetak(Cross Tab)", "icon_cetak.png"),
                        "cetak_slip_lembur" => array("Cetak(Lemburan)", "icon_cetak.png"),
                        "cetak_slip_lembur_tertunda" => array("Cetak(Lemburan Tertunda)", "icon_cetak.png"),
                        "cetak_tanpa_nama_company" => array("Cetak (Tanpa Nama Company)", "icon_cetak.png"),
                        "faktur" => array("Faktur", "icon_faktur.png"),
                        "faktur_pajak" => array("Faktur Pajak", "icon_cetak.png"),
                        "faktur_pajak_standar" => array("Faktur Pajak Standar","icon_cetak.png"),
                        "faktur_non_pt" => array("Faktur Non PT","icon_cetak.png"),
                        "sales_invoice" => array("Invoice", "icon_faktur.png"),
                        "kwitansi" => array("Kwitansi", "icon_kwitansi.png"),
                        "surat_jalan" => array("Surat Jalan", "icon_kwitansi.png"),
                        "retur" => array("Retur", "icon_retur.png"),
                        "nota_selisih" => array("Nota Selisih", "icon_retur.png"),
                        "unlock" => array("Unlock", "icon_batal.png"),
                        "terima" => array("Terima", "icon_post.png"),
                        "tolak" => array("Tolak", "icon_post.png"),
                        "refresh" => array("Refresh Harga", "icon_reset.png"),
                        "generate_report" => array("Generate Report", "icon_baru.png",""),
                        "print_report" => array("Cetak", "icon_cetak.png",""),
                        "export_excel" => array("Export Excel", "icon_export.png"),
                        "export_excel_report" => array("Export To Excel (Report)", "icon_export.png"),
                        "export_pdf_report" => array("Export To Pdf (Report)", "icon_export.png"),					);
    //var $button_caption;
    //var $button_icon;
    //var $button_locked;
    var $button_show;
    
    // script variables -------------------------
    var $script_global;
    
    // Allow Action
    var $Allow_Save = true;
    var $Allow_Delete = true;
    var $Allow_Update = true;
    var $Allow_Cancel = true;
    var $Allow_Revisi = true;
    var $Allow_Final = false;
        
    function Allow_Save($Allow = true) {
        $this->Allow_Save = $Allow;
    }

    function Allow_Delete($Allow = true) {
        $this->Allow_Delete = $Allow;
    }

    function Allow_Update($Allow = true) {
        $this->Allow_Update = $Allow;
    }

    function Allow_Cancel($Allow = true) {
        $this->Allow_Cancel = $Allow;
    }

    function Allow_Revisi($Allow = true) {
        $this->Allow_Revisi = $Allow;
    }

    function Allow_Final($Allow = true) {
        $this->Allow_Final = $Allow;
    }

    function ViewName($value) {
        $this->view_name = $value;
    }

    function ViewTable($value) {
        $this->view_table = $value;
    }

    function ViewSQL($value) {
        // this->view_sql = $value; 
        $this->view_sql = str_replace('|','\\',$value) ;
    }

    function ViewCaption($value) {
        $this->view_caption = $this->str_to_array($value);
    }

    function ViewAction($value) {
        $this->view_action = $value;
    }

    function ViewSearch($value) {
        $this->view_search = $value;
    }

    function ViewPeriod($value) {
        $this->view_period = $value;
    }

    function ViewNewWindow($value) {
        $this->view_new_window = $value;
    }

    function FormName($value) {
        $this->form_name = $value;
    }

    function FormSQL($value) {
        $this->form_sql = $value;
    }

    function FormCaption($value) {
        $this->form_caption = $this->str_to_array($value);
    }

    function FormPosition($value) {
        $this->form_position = $this->str_to_array($value);
    }

    function FormSize($value) {
        $this->form_size = $this->str_to_array($value);
    }

    function FormLocked($value) {
        $this->form_locked = $this->str_to_array($value);
    }

    function FormValue($index, $value) {
        $this->form_value[$index] = $value;
    }

    function FormScript($index, $value) {
        $this->form_script[$index] = $value;
    }

    function FormJS($value) {
        $this->form_js = $value;
    }

    function FormAutoNumber($value) {
        $this->form_autonumber = $value;
    }

    function FormHidden($value) {
        $this->form_hidden = $value;
    }

    function FormLayout($index, $value) {
        $this->form_layout[$index] = $value;
    }

    function GridType($index, $value) {
        $this->grid_type[$index] = $value;
    }

    function GridName($index, $value) {
        $this->grid_name[$index] = $value;
    }

    function GridSQL($index, $value) {
        $this->grid_sql[$index] = $value;
        $this->grid_reindex[$index] = true;
        $this->grid_auto_add[$index] = true;
    }

    function GridCaption($index, $value) {
        $this->grid_caption[$index] = $this->str_to_array($value);
    }

    function GridSize($index, $value) {
        $this->grid_size[$index] = $this->str_to_array($value);
    }

    function GridLocked($index, $value) {
        $this->grid_locked[$index] = $this->str_to_array($value);
    }

    function GridHidden($index, $value) {
        $this->grid_hidden[$index] = $this->str_to_array($value);
    }

    function GridScript($index, $field, $value) {
        $this->grid_script[$index][$field] = $value;
    }

    function GridLayout($index, $field, $value) {
        $this->grid_layout[$index][$field] = $value;
    }

    function GridAutoAdd($index, $value) {
        $this->grid_auto_add[$index] = $value;
    }

    function GridButton($index, $value) {
        $this->grid_button[$index] = $value;
    }

    function GridAllowAddNew($index, $value = FALSE) {
        $this->grid_allowaddnew[$index] = $value;
    }

    function GridAllowDelete($index, $value = FALSE) {
        $this->grid_allowdelete[$index] = $value;
    }

    function GridAllowUpdate($index, $value = TRUE) {
        $this->grid_allowupdate[$index] = $value;
    }

    function GridReplace($index, $value = "") {
        $this->grid_replace[$index] = $value;
    }

    function GridDelJS($index, $value) {
        $this->grid_del_js[$index] = $value;
    }

    function GridAddJS($index, $value) {
        $this->grid_add_js[$index] = $value;
    }

    function GridScroll($index, $value, $width) {
        $this->grid_scroll[$index] = $value;
        $this->grid_scroll_width[$index] = $width;
    }

    function GridReindex($index, $value) {
        $this->grid_reindex[$index] = $value;
    }

    function ScriptGlobal($value) {
        $this->script_global = $value;
    }

    function SetStatus($value) {
        $this->status = $this->str_to_array($value);
        // --------------------------------------------------
        // check ID for button setting (Form)
        // --------------------------------------------------
        $this->id = $_REQUEST["id"];
        $this->status["id"] = $this->id;

        // --------------------------------------------------
        // check status for button setting (Form)
        // --------------------------------------------------

        if ($this->id == "")
            $query = $this->form_sql;
        else
            $query = $this->form_sql . " WHERE fnid = " . $this->id;


        if ($this->id <> "") {
            $result = mysql_query($query) or die($query);
            $num_fields = mysql_num_fields($result);
            $fetch_row = mysql_fetch_row($result);
            //echo " 2 ". $query ." " ;
            //echo "<script>alert( 'shdfgydh ' );</script>";
            for ($i = 0; $i < $num_fields; $i++) {
                //echo "<script>alert(' $field_name ');</script>";
                $field_name = mysql_field_name($result, $i);
                if (in_array($field_name, $this->status)) {
                    $this->status[$field_name] = $fetch_row[$i];
                }
            }
            mysql_free_result($result);
        }
    }

    function GetStatus($value) {
        return $this->status[$value];
    }

    function Lookup($FieldName, $LookupTable, $LinkField, $DisplayField, $DefaultValue, $State, $Param = "") {

        $this->lookup[$FieldName][0] = $LookupTable;
        $this->lookup[$FieldName][1] = $LinkField;
        $this->lookup[$FieldName][2] = $DisplayField;
        $this->lookup[$FieldName][3] = $DefaultValue;
        $this->lookup[$FieldName][4] = $State;
        $this->lookup[$FieldName][5] = $Param;
        //echo $Param;
    }

    function LookupGrid($index, $FieldName, $LookupTable, $LinkField, $DisplayField, $DefaultValue, $State, $Param = "") {
        $this->lookup_grid[$index][$FieldName][0] = $LookupTable;
        $this->lookup_grid[$index][$FieldName][1] = $LinkField;
        $this->lookup_grid[$index][$FieldName][2] = $DisplayField;
        $this->lookup_grid[$index][$FieldName][3] = $DefaultValue;
        $this->lookup_grid[$index][$FieldName][4] = $State;
        $this->lookup_grid[$index][$FieldName][5] = $Param;
    }

    function LookupMagicQuotes($value) {
        $this->lookup_magic_quotes = $value;
    }

    function ButtonShow($value) {
        $this->button_show = $this->str_to_array($value);
    }

    function ReportPeriod($value) {
        $this->ReportPeriod = $value;
    }

    var $arrReportFilter = array();

    function ReportFilter($Index, $Caption, $Name, $SQL, $Range) {
        $this->arrReportFilter[$Index][0] = $Caption;
        $this->arrReportFilter[$Index][1] = $Name;
        $this->arrReportFilter[$Index][2] = $SQL;
        $this->arrReportFilter[$Index][3] = $Range;
    }

    function Process() {

        // --------------------------------------------------
        // set ID
        // --------------------------------------------------
        $this->id = $_REQUEST["id"];

        // --------------------------------------------------
        // Form Header & Footer Properties
        // --------------------------------------------------
        if ($this->id == "") {
            $query = $this->form_sql;
        } else {
            $query = $this->form_sql . " WHERE fnid = " . $this->id;

            $result_form = mysql_query($query);

            $num_fields_form = mysql_num_fields($result_form) or die($query);
            $row_form = mysql_fetch_array($result_form);
            for ($i = 0; $i < $num_fields_form; $i++) {
                // --------------------------------------------------
                // get MySQL fields properties (Form)
                // --------------------------------------------------
                $name_form = mysql_field_name($result_form, $i);
                $len_form = mysql_field_len($result_form, $i);
                if (isset($this->lookup[$name_form][0])) {

                    if ($this->lookup[$name_form][4])
                        $type_form = "lookup";
                    else
                        $type_form = "lookup2";
                } else {
                    if ($len_form == 1)
                        $type_form = "bool";
                    else
                        $type_form = mysql_field_type($result_form, $i);
                }

                // --------------------------------------------------
                // get MySQL primary keys (Form)
                // --------------------------------------------------
                $flags_form = explode(" ", mysql_field_flags($result_form, $i));
                if (in_array("primary_key", $flags_form)) {
                    if (isset($filter_grid))
                        $filter_grid .= " AND ";
                    $filter_grid .= $name_form . "='" . $row_form[$name_form] . "'";
                }

                $layout_form = $this->form_layout[$i];
                $script_form = $this->form_script[$i];
                $locked_form = $this->form_locked[$i];
                $caption_form = $this->form_caption[$i] . " : ";
                $size_form = $this->form_size[$i];
                //$caption_form = $name_form;
                // --------------------------------------------------
                // set MySQL fields position in GUI (Form)
                // --------------------------------------------------
                switch ($this->form_position[$i]) {
                    case "TL":
                        $this->arrTL[] = array($name_form, $type_form, $len_form, $row_form[$name_form], $script_form, $locked_form, $caption_form, $layout_form, $size_form);
                        break;
                    case "TR":
                        $this->arrTR[] = array($name_form, $type_form, $len_form, $row_form[$name_form], $script_form, $locked_form, $caption_form, $layout_form, $size_form);
                        break;
                    case "BL":
                        $this->arrBL[] = array($name_form, $type_form, $len_form, $row_form[$name_form], $script_form, $locked_form, $caption_form, $layout_form, $size_form);
                        break;
                    case "BR":
                        $this->arrBR[] = array($name_form, $type_form, $len_form, $row_form[$name_form], $script_form, $locked_form, $caption_form, $layout_form, $size_form);
                        break;
                    case "HD":
                        $this->arrHD[] = array($name_form, "hidden", $len_form, $row_form[$name_form], $script_form, $locked_form, $caption_form, $layout_form, $size_form);
                        break;
                }
            }
            mysql_free_result($result_form);
            $this->primary_keys = ($filter_grid);
            $this->filter_grid = $filter_grid;
        }
    }

    function WriteHtmlTable() {
        // reset saved search parameter
        if ($_REQUEST["search"] == "new") {
            $_SESSION["search"] = "";
            $_SESSION["page"] = "";
            $_SESSION["order_type"] = "";
            $_SESSION["order_field"] = "";
        }
        
        //$this->ViewTable("");
        $this->url = $_SERVER["PHP_SELF"];
        $this->form = $_REQUEST["form"];
        if (isset($_GET['q'])) {
            $form = $_GET["form"];
            $page = $_GET["page"];
            $order_type = $_GET["order_type"];
            $order_field = $_GET["order_field"];

            $search = (base64_decode($_GET["q"]));

            $_SESSION["search"] = $search;
            $_SESSION["page"] = $page;
            $_SESSION["order_type"] = $order_type;
            $_SESSION["order_field"] = $order_field;

            $this->listData($form, $search, $page, $order_field, $order_type);
            echo "|";
            $this->pageData($form, $search, $page, $order_field, $order_type);
            exit;
        }// --------------------------------------------------
        // get URL path
        // --------------------------------------------------
        // version control
        include('class/version.php');
        ?>
        <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                <script type="text/javascript" src="script/script.js?ver=<?php echo $this->script_version;?>"></script>
                <script type="text/javascript" src="script/QxJavaScriptUtils.js"></script>
                <script type="text/javascript" src="script/ajax.js?ver=<?php echo $this->script_version;?>"></script>
                <script type="text/javascript" src="script/ajax2.js"></script>
                <script type="text/javascript" src="script/QxPopup.js"></script>
                <script type="text/javascript" src="script/iframe.js"></script>
                <script type="text/javascript" src="script/sack.js"></script>
                <script type="text/javascript" src="script/ajax-dynamic-list.js"></script>
                <script type="text/javascript" src="script_custom/ValidasiForm.js?ver=<?php echo $this->script_version;?>"></script>
                <link href="css/project1.css" rel="stylesheet" type="text/css" />
                <link href="css/styles.css" type="text/css" rel="stylesheet">
                <?php include('class/link_css.php'); ?>
                
            </head>


            <body>
                <iframe name="gToday:KalenderIndonesia:agenda.js" id="gToday:KalenderIndonesia:agenda.js" src="KalenderIndonesia.htm" style="visibility: visible; z-index: 999; position: absolute; left: -500px; top: 0px;" frameborder="0" height="189" scrolling="no" width="174"></iframe>

                <script type='text/javascript' >  
                    /* check session exist, if not automatic logout */
                    if (( '<?php echo $_SESSION['username'];?>' == '' ) || ( '<?php echo $_SESSION['strbranch'];?>' == '' )) {
                        alert('Sesi Login anda berakhir / bermasalah. Harap Login kembali. ');
                        window.location='logout.php';
                    }        
                    
                    /* reload latest script */
                    function reloadScripts(key) {
                        var scripts = document.getElementsByTagName('script');
                        var toRefreshList = ['script.js', 'ValidasiForm.js'] ; // list of js to be refresh
                        
                        for(var i = 0; i < scripts.length; i++) {
                            var aScript = scripts[i];
                            // alert(aScript.src);
                            
                            for(var j = 0; j < toRefreshList.length; j++) {
                                var toRefresh = toRefreshList[j];
                                if(aScript.src && (aScript.src.indexOf(toRefresh) > -1)) {
                                    new_src = aScript.src.replace(toRefresh, toRefresh + '?k=' + key);
                                    /* console.log('Force refresh on cached script files. From: ' + aScript.src + ' to ' + new_src) */
                                    aScript.src = new_src;
                                }
                            }
                        }
                    }     

                    /* force refresh script */
                    /* var today = new Date().getTime();
                    reloadScripts(today); */
    
                </script>        

                <?
                if (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "view") {
                    $this->order_field = $_GET["order_field"];
                    $this->order_type = $_GET["order_type"];
                    $this->viewData($this->url, $this->form, $this->page, $this->order_field, $this->order_type);
                } elseif (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "edit") {
                    $this->mode = $_REQUEST["mode"];
                    $this->editData($this->url, $this->form, $this->mode);
                } elseif (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "preview") {
                    $this->mode = $_REQUEST["mode"];
                    $this->previewData($this->url, $this->form, $this->mode);
                } elseif (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "batal") {
                    $this->cancelData($this->url, $this->form);
                } elseif (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "hapus") {
                    $this->deleteData($this->url, $this->form);
                } elseif (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "simpan_bank") {
                    $this->saveData($this->url, $this->form);
                } elseif (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "simpan") {
                    $this->saveData($this->url, $this->form);
                } elseif (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "simpan_penerimaan") {
                    $this->saveData($this->url, $this->form);
                } elseif (substr(isset($_REQUEST["mode"]), 0, 6) && substr($_REQUEST["mode"], 0, 6) == "update") {
                    $this->updateData($this->url, $this->form);
                } elseif (substr(isset($_REQUEST["mode"]), 0, 5) && substr($_REQUEST["mode"], 0, 5) == "close") {
                    $this->updateData($this->url, $this->form);
                    //} elseif(isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "update_schedule_delivery") {
                    //	$this->updateData($this->url, $this->form);
                    //} elseif(isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "update") {
                    //	$this->updateData($this->url, $this->form);
                } elseif (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "final") {
                    $this->finalData($this->url, $this->form);
                } elseif (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "final_bank") {
                    $this->finalData($this->url, $this->form);
                } elseif (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "final_approve") {
                    $this->finalData($this->url, $this->form);
                }elseif (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "final_penerimaan") {
                    $this->finalData($this->url, $this->form);
                } elseif (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "accept") {
                    $this->acceptData($this->url, $this->form);
                } elseif (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "reject") {
                    $this->rejectData($this->url, $this->form);
                } elseif (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "revisi") {
                    $this->revisiData($this->url, $this->form);
                } elseif (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "simpan_revisi") {
                    $this->revisiData($this->url, $this->form);
                } else {
                    if (empty($_REQUEST["page"]) || $_REQUEST["page"] == "") {
                        $this->page = 1;
                    } else {
                        $this->page = $_REQUEST["page"];
                    }

                    $this->order = $_REQUEST["order"];
                    $this->ordertype = $_REQUEST["ordertype"];
                    $this->viewData($this->url, $this->form, $this->page, $this->order, $this->ordertype);
                }

                echo "<script>
                            {$this->form_js}
                            ElementCurrencyALL();
                      </script>";
                echo "</body> </html>";
            }

            function acceptData($url, $form) {
                $strSQL = AcceptData(str_replace(" ", "", $this->form_name));
                for ($i = 0; $i < count($strSQL); $i++) {
                    $hasil = mysql_query($strSQL[$i]);
                }
                header("Location: $url?form=$form");
            }

            function rejectData($url, $form) {
                $strSQL = RejectData(str_replace(" ", "", $this->form_name));
				for ($i = 0; $i < count($strSQL); $i++) {
					$hasil = mysql_query($strSQL[$i]);
                }
				header("Location: $url?form=$form");
            }

            function SetDirectExecuteSql($value) {
                if ($this->direct_execute_sql != $value) {
                    $this->direct_execute_sql = $value;
                    mysql_query("BEGIN");
                }
                if ($this->direct_execute_sql) {
                    $_REQUEST['DIRECT_EXECUTE_SQL'] = 1;
                } else {
                    $_REQUEST['DIRECT_EXECUTE_SQL'] = 0;
                }
            }

            function Query_SqlArr($arr, $FlagMsg = "") {

                if (!($_REQUEST['DIRECT_EXECUTE_SQL'] == 1)) {
                    mysql_query("BEGIN");
                    foreach ($arr as $key1 => $value1) {
                        if (count($value1) <= 0)
                            continue;
                        foreach ($value1 as $key2 => $value2) {
                            echo "<script>alert($value2);</script>";

                            // print out each query value
                            if ($_SESSION['username'] == "admin") {
                                pr("show :" . $value2);
                            }

                            // continue;
                            if (!mysql_query($value2)) {
                                mysql_query("ROLLBACK");
                                pr("ERROR :" . $value2);
                                die("<hr>");
                            }
                            $i++;
                        }
                    }
                } else {
                    $i = 1;
                }

                // die("m");
                mysql_query("COMMIT");
                if ($i && ($FlagMsg != "")) {
                    switch ($_REQUEST['mode']) {
                        case "simpan":
                            //echo "<script>alert('Data Sudah Tersimpan...');</script>";
                            break;
                        case "simpan_bank":
                            echo "<script>alert('Data Sudah Tersimpan...');</script>";
                            break;
                        case "simpan_penerimaan":
                            echo "<script>alert('Data Sudah Tersimpan...');</script>";
                            break;
                        case "final_bank":
                            echo "<script>alert('Data Sudah difinal...');</script>";
                            break;
                        case "final_penerimaan":
                            echo "<script>alert('Data Sudah difinal...');</script>";
                            break;
						case "final_approve":
                            echo "<script>alert('Data Sudah difinal...');</script>";
                            break;							
                        case "final":
                            echo "<script>alert('Data Sudah difinal...');</script>";
                            break;
                        case "update":
                            echo "<script>alert('Data Sudah diupdate...');</script>";
                            break;
                        case "batal":
                            echo "<script>alert('Data Sudah dibatalkan...');</script>";
                            break;
                        case "hapus":
                            echo "<script>alert('Data Sudah dihapus...');</script>";
                            break;
                        case "revisi":
                            echo "<script>alert('Data Sudah direvisi...');</script>";
                            break;
                        case "simpan_revisi":
                            echo "<script>alert('Data Sudah direvisi...');</script>";
                            break;
                    }
                }
            }

            function GetSqlGridSave($ssql, $index, $strPK) {
                $result = @mysql_query($ssql);
                $table = @mysql_field_table($result, 0);
                @mysql_free_result($result);

                $result2 = mysql_query("SELECT * FROM " . $table . " where fnid = 0");

                $fields = @mysql_num_fields($result2);
                $total_column_name = 0;
                // pr($fields);

                for ($i = 0; $i < $fields; $i++) {
                    $name = mysql_field_name($result2, $i);
                    $alias = mysql_field_name($result2, $i) . "D{$index}";
                    $type = mysql_field_type($result2, $i);

                    if (strtolower($name) == "fnid")
                        continue;

                    //  pr($alias . "-" . $_REQUEST[$alias]);
                    if (isset($_REQUEST[$alias]) && is_array($_REQUEST[$alias])) {
                        if (count($_REQUEST[$alias]) > 0) {
                            for ($j = 0; $j < count($_REQUEST[$alias]); $j++) {
                                $column_name[$total_column_name][$j] = $name;
                                $FiendValue = $_REQUEST[$alias][$j];
                                switch ($type) {
                                    case "string":
                                        $FiendValue = js_esc($FiendValue);    
                                        break;
                                    case "blob":
                                        $FiendValue = js_esc($FiendValue);        
                                        break;
                                    case "date":
                                        $FiendValue = CDate($FiendValue);
                                        break;
                                    case "int":
                                        $FiendValue = CCur($FiendValue);
                                        break;
                                    case "bool":
                                        break;
                                    case "real":
                                        $FiendValue = CCur($FiendValue);
                                        break;
                                    case "number":
                                        $FiendValue = CCur($FiendValue);
                                        break;
                                }
                                $_REQUEST[$alias][$j] = $FiendValue;
                                // pr($_REQUEST[$alias][$j]);
                                $column_value[$total_column_name][$j] = $_REQUEST[$alias][$j];
                            }
                            $total_column_value = count($_REQUEST[$alias]);
                            $total_column_name++;
                        }
                    }
                }

                @mysql_free_result($result2);

                for ($i = 0; $i < count($strPK); $i++) {
                    $strInsert7 = $strInsert7 . $strPK[$i] . ", ";
                    $strInsert8 = $strInsert8 . "'" . $_REQUEST[$strPK[$i]] . "', ";
                }

                $fnindex = 0;
                $k = 0;
                //pr($strInsert7); pr($strInsert8);
                //pr($total_column_value);pr("test1");
                for ($i = 1; $i < $total_column_value; $i++) {
                    $strInsert5 = "";
                    $strInsert6 = "";
                    //pr("test2");pr($i); pr($total_column_name);
                    for ($j = 0; $j < $total_column_name; $j++) {
                        if (strtolower($column_name[$j][$i]) == "fnindex") {
                            $column_value[$j][$i] = ++$fnindex;
                            $strInsert5 = $strInsert5 . $column_name[$j][$i] . ", ";
                            $strInsert6 = $strInsert6 . "'" . $column_value[$j][$i] . "', ";
                        } else {
                            $strInsert5 = $strInsert5 . $column_name[$j][$i] . ", ";
                            $strInsert6 = $strInsert6 . "'" . $column_value[$j][$i] . "', ";
                        }
                    }

                    $strInsert5 = $strInsert5 . " ftbranch_code, ftcreated_user, fdcreated_date, ftmodified_user, fdmodified_date";
                    //$strInsert5 = $strInsert5 . "ftbranch_code, ftcreated_user, fdcreated_date, ftmodified_user, fdmodified_date";

                    $strInsert6 = $strInsert6 . "'" . $_SESSION['strbranch'] . "', '" . $_SESSION['username'] . "', NOW(), '" . $_SESSION['username'] . "', NOW()";
                    //$strInsert6 = $strInsert6 . "'" . $_SESSION['strbranch'] . "','" . $_SESSION['username'] . "', NOW(), '" . $_SESSION['username'] . "', NOW()";
                    $ssql = "INSERT INTO $table (" . $strInsert7 . $strInsert5 . ") VALUES (" . $strInsert8 . $strInsert6 . ")";
                    $strInsert[$k++] = $ssql;
                    // pr($ssql);
                    if ($_REQUEST['DIRECT_EXECUTE_SQL'] == 1) {
                        mysql_query($ssql) or die("SQL ERROR :{$ssql}");
                    }
                }


                return $strInsert;
            }

            function saveData($url, $form) {
                
                if (function_exists("SaveData")) {
                    $strSQL = SaveData();
                }

                
                $strPK = array();
                if ($this->Allow_Save) {
                    $result = mysql_query($this->form_sql . " WHERE fnid =" . $this->id);
                    $table = mysql_field_table($result, 0);
                    $jml = mysql_num_fields($result);
                    
                    for ($i = 0; $i < $jml; $i++) {
                        $FiendName = mysql_field_name($result, $i);
                        $FiendValue = $_REQUEST[$FiendName];

                        //$arrStrFrom = array("'",'"');
                        //$arrStrTo = array("\'","\"");
                        //$FiendValue = str_replace($arrStrFrom,$arrStrTo,$FiendValue);
            
                        $FiendType = mysql_field_type($result, $i);

                        $strSQL1 = $strSQL1 . "$FiendName, ";
                        switch ($FiendType) {
                            case "string":
                                $FiendValue = js_esc($FiendValue);                 
                                break;
                            case "blob":
                                $FiendValue = js_esc($FiendValue);                 
                                break;
                            case "date":
                                $FiendValue = CDate($FiendValue);
                                break;
                            case "int":
                                $FiendValue = CCur($FiendValue);
                                break;
                            case "bool":
                                break;
                            case "real":
                                $FiendValue = CCur($FiendValue);
                                break;
                            case "number":
                                $FiendValue = CCur($FiendValue);
                                break;
                        }
                        $strSQL2 = $strSQL2 . "'$FiendValue', ";
                        $flags_form = explode(" ", mysql_field_flags($result, $i));

                        if (in_array("primary_key", $flags_form)) {
                            $strPK[] = $FiendName;
                        }
                    }

                    if ((strstr(strtolower($this->grid_sql[0]), "where"))) {
                        
                    } else {
                        $this->grid_sql[0] = $this->grid_sql[0] . " where fnid = 0";
                    }

                    $ssql = $this->form_save_method . " INTO " . $table . " (" . $strSQL1 . "ftbranch_code,fdcreated_date,fdmodified_date,ftcreated_user, ftmodified_user) VALUES (" . $strSQL2 . "'{$_SESSION[strbranch]}',NOW(),NOW(),'{$_SESSION[username]}', '{$_SESSION[username]}')";
                    $strSQL["Form Hdr"][] = $ssql;

                    if ($_REQUEST['DIRECT_EXECUTE_SQL'] == 1) {
                        mysql_query($ssql) or die("SQL ERROR :{$ssql}");
                    }
                    for ($j = 0; $j < count($this->grid_sql); $j++) {
                        // pr($this->grid_sql[$j]."-".$j."-".$strPK);
                        $strSQL["Insert Detail_" . $j] = $this->GetSqlGridSave($this->grid_sql[$j], $j, $strPK);
                    }
                }

                
                if (function_exists("SaveDataLast")) {
                    $m = SaveDataLast();
                    $strSQL = array_merge_recursive($strSQL, $m);
                }
                
                // die("");
                
                $this->Query_SqlArr($strSQL);
                
                // Call Function After Commit SQL
                if(function_exists("SaveDataAfter")) {
                     $strSQL2=SaveDataAfter();
                     $this->Query_SqlArr($strSQL2);
                }
                
                //Proses FIFO
                fifo_save();

                // Call Function Process General Ledger
                if(function_exists("ProcessGL")) {
                    $m = ProcessGL();
                    $this->Query_SqlArr($m,"1");
                    pr("proses GL : " . $m);
                }

                $idx = GetId();

                // die("");

                if ($form == "penyusutan_asset" || $form == "saldoawal_perkiraan" || $form == "giro_mundur_hutang" || $form == "giro_mundur_piutang") {
                    echo "<script>window.location='{$url}?form={$form}';</script>";
                } else {
                    echo "<script>window.location='{$url}?form={$form}&mode=edit&id={$idx}';</script>";
                }
                die("");
            }

            function updateData($url, $form) {
                if (function_exists("UpdateData")) {
                    $strSQL = UpdateData();
                }

                if ($this->Allow_Update) {

                    $result = mysql_query($this->form_sql);
                    $table = mysql_field_table($result, 0);

                    $jml = mysql_num_fields($result);
                    $filter_grid = "";
                    $strSQL1 = "";
                    for ($i = 0; $i < $jml; $i++) {
                        $FiendName = mysql_field_name($result, $i);
                        $FiendValue = $_REQUEST[$FiendName];
                        $FiendType = mysql_field_type($result, $i);
                        switch ($FiendType) {
                            case "string":
                                $FiendValue = js_esc($FiendValue);     
                                break;
                            case "blob":
                                $FiendValue = js_esc($FiendValue);    
                                break;
                            case "date":
                                $FiendValue = CDate($FiendValue);
                                break;
                            case "int":
                                $FiendValue = CCur($FiendValue);
                                break;
                            case "bool":
                                break;
                            case "real":
                                $FiendValue = CCur($FiendValue);
                                break;
                            case "number":
                                $FiendValue = CCur($FiendValue);
                                break;
                        }
                        $strSQL1 = $strSQL1 . "{$FiendName}='{$FiendValue}', ";

                        $flags_form = explode(" ", mysql_field_flags($result, $i));

                        if (in_array("primary_key", $flags_form)) {
                            if ($filter_grid)
                                $filter_grid .= " AND ";
                            $filter_grid .= $FiendName . "='" . $FiendValue . "'";
                        }
                    }

                    $ssql = "UPDATE " . $table . " SET " . $strSQL1 . "fdmodified_date=NOW(),ftmodified_user='{$_SESSION[username]}' WHERE {$filter_grid}";
                    $strSQL["Update"][] = $ssql;
                    if ($_REQUEST['DIRECT_EXECUTE_SQL'] == 1) {
                        mysql_query($ssql) or die("SQL ERROR :{$ssql}");
                    }
                    
                    // Delete Grid before update (re-insert detail)
                    $ssql = "DELETE FROM " . $table . " WHERE {$filter_grid}'";
                    mysql_query($ssql);
           
                    for ($j = 0; $j < count($this->grid_sql); $j++) {
                        // pr($this->grid_sql[$j]."-".$j."-".$strPK);
                        $strSQL["Insert Detail_" . $j] = $this->GetSqlGridSave($this->grid_sql[$j], $j, $strPK);
                    }
                    
                    // die($ssql);
                }


                if (function_exists("UpdateDataLast")) {
                    $m = UpdateDataLast();
                    $strSQL = array_merge_recursive($strSQL, $m);
                }

                $this->Query_SqlArr($strSQL);

                // Call Function After Commit SQL
                if (function_exists("UpdateDataAfter")) {
                    $strSQL2 = UpdateDataAfter();
                    $this->Query_SqlArr($strSQL2);
                }
                
                // Temporary (Venom) : Update SI status draft -> auto Create DO
                if ($form == "sales_invoice") {
                    //Proses FIFO
                    fifo_save();

                    // Call Function Process General Ledger
                    if(function_exists("ProcessGL")) {
                        $m = ProcessGL();
                        $this->Query_SqlArr($m,"1");
                        pr("proses GL : " . $m);
                    }
                }
                
                $idx = GetId();
                if ($idx != 0) {
                    echo "<script>window.location='{$url}?form={$form}&mode=edit&id={$idx}&page={$_REQUEST['page']}';
                          </script>";
                } else {
                    echo "<script>window.location='{$url}?form={$form}';
                          </script>";
                }
                die("");
            }

            function cancelData($url, $form) {

                if (function_exists("CancelData")) {
                    $strSQL = CancelData();
                }
                if ($this->Allow_Cancel) {
                    $result = mysql_query($this->form_sql);
                    $table = mysql_field_table($result, 0);

                    $jml = mysql_num_fields($result);
                    $filter_grid = "";
                    for ($i = 0; $i < $jml; $i++) {
                        $FiendName = mysql_field_name($result, $i);
                        $FiendValue = $_REQUEST[$FiendName];


                        $flags_form = explode(" ", mysql_field_flags($result, $i));

                        if (in_array("primary_key", $flags_form)) {
                            if ($filter_grid)
                                $filter_grid .= " AND ";
                            $filter_grid .= $FiendName . "='" . $FiendValue . "'";
                        }
                    }
                    $ssql = "UPDATE $table SET fnstatus=9 WHERE {$filter_grid}";
                    $strSQL["Batal " . $table][] = $ssql;
                    if ($_REQUEST['DIRECT_EXECUTE_SQL'] == 1) {
                        mysql_query($ssql) or die("SQL ERROR :{$ssql}");
                    }
                }

                if (function_exists("CancelDataLast")) {
                    $m = CancelDataLast();
                    $strSQL = array_merge_recursive($strSQL, $m);
                }

                $this->Query_SqlArr($strSQL);
                
                // Call Function After Commit SQL
                if(function_exists("CancelDataAfter")) {
                     $strSQL2=CancelDataAfter();
                     $this->Query_SqlArr($strSQL2);
                }
                
                // Call Function Cancel General Ledger
                if (function_exists("CancelGL")) {
                    $m = CancelGL();
                    $this->Query_SqlArr($m,"1");
                    pr("cancel GL : " . $m);
                }
                
                //Proses FIFO
                fifo_save();
                //die("");
                
                echo "<script>window.location='{$url}?form={$form}'; </script>";
                die("");
            }

            function revisiData($url, $form) {
                if (function_exists("RevisiData")) {
                    $strSQL = RevisiData();
                }

                $strPK = array();

                if ($this->Allow_Revisi) {
                    $result = mysql_query($this->form_sql);
                    $table = mysql_field_table($result, 0);

                    $jml = mysql_num_fields($result);
                    for ($i = 0; $i < $jml; $i++) {
                        $FiendName = mysql_field_name($result, $i);
                        $FiendValue = $_REQUEST[$FiendName];
                        $FiendType = mysql_field_type($result, $i);

                        $strSQL1 = $strSQL1 . "$FiendName, ";
                        switch ($FiendType) {
                            case "string":
                                $FiendValue = js_esc($FiendValue);  
                                break;
                            case "blob":
                                $FiendValue = js_esc($FiendValue);
                                break;
                            case "date":
                                $FiendValue = CDate($FiendValue);
                                break;
                            case "int":
                                $FiendValue = CCur($FiendValue);
                                break;
                            case "bool":
                                break;
                            case "real":
                                $FiendValue = CCur($FiendValue);
                                break;
                            case "number":
                                $FiendValue = CCur($FiendValue);
                                break;
                        }
                        $strSQL2 = $strSQL2 . "'$FiendValue', ";
                        $flags_form = explode(" ", mysql_field_flags($result, $i));

                        if (in_array("primary_key", $flags_form)) {
                            $strPK[] = $FiendName;
                        }
                    }
                    $ssql = $this->form_save_method . " INTO " . $table . " (" . $strSQL1 . "ftbranch_code,fdcreated_date,fdmodified_date,ftcreated_user, ftmodified_user) VALUES (" . $strSQL2 . "'{$_SESSION[strbranch]}',NOW(),NOW(),'{$_SESSION[username]}', '{$_SESSION[username]}')";
                    $strSQL["Form Hdr"][] = $ssql;

                    if ($_REQUEST['DIRECT_EXECUTE_SQL'] == 1) {
                        mysql_query($ssql) or die("SQL ERROR :{$ssql}");
                    }

                    for ($j = 0; $j < count($this->grid_sql); $j++) {
                        $strSQL["Insert Detail_" . $j] = $this->GetSqlGridSave($this->grid_sql[$j], $j, $strPK);
                    }
                }
                
                if (function_exists("RevisiDataLast")) {
                    $m = RevisiDataLast();
                    $strSQL = array_merge_recursive($strSQL, $m);
                }
                // die("");
                $this->Query_SqlArr($strSQL);

                // Call Function After Commit SQL
                if(function_exists("RevisiDataAfter")) {
                    $strSQL2=RevisiDataAfter();
                    $this->Query_SqlArr($strSQL2);
                }

                //Proses FIFO
                fifo_save();

                // Call Function Process General Ledger
                if(function_exists("ProcessGL")) {
                    $m = ProcessGL();
                    $this->Query_SqlArr($m);
                }

                // die("");
                echo "<script>window.location='{$url}?form={$form}';
                      </script>";
                die("");
            }

            function deleteData($url, $form) {

                if (function_exists("DeleteData")) {
                    $strSQL = DeleteData();
                }

                if ($this->Allow_Delete)
                    ;
                {

                    $result = mysql_query($this->form_sql);
                    $table = mysql_field_table($result, 0);

                    $jml = mysql_num_fields($result);
                    $filter_grid = "";
                    for ($i = 0; $i < $jml; $i++) {
                        $FiendName = mysql_field_name($result, $i);
                        $FiendValue = $_REQUEST[$FiendName];


                        $flags_form = explode(" ", mysql_field_flags($result, $i));

                        if (in_array("primary_key", $flags_form)) {
                            if ($filter_grid)
                                $filter_grid .= " AND ";
                            $filter_grid .= $FiendName . "='" . $FiendValue . "'";
                        }
                    }
                    $ssql = "DELETE FROM $table WHERE {$filter_grid}";
                    $strSQL["DELETE " . $table][] = $ssql;
                    if ($_REQUEST['DIRECT_EXECUTE_SQL'] == 1) {
                        mysql_query($ssql) or die("SQL ERROR :{$ssql}");
                    }
                }

                $this->Query_SqlArr($strSQL);


                echo "<script>window.location='{$url}?form={$form}';
                                  </script>";
                die("");
            }

            function finalData($url, $form) {

                if (function_exists("FinalData")) {
                    $strSQL = FinalData();
                }
                $strPK = array();

                if ($this->Allow_Final) {

                    $result = mysql_query($this->form_sql);
                    $table = mysql_field_table($result, 0);

                    $jml = mysql_num_fields($result);
                    for ($i = 0; $i < $jml; $i++) {
                        $FiendName = mysql_field_name($result, $i);
                        $FiendValue = $_REQUEST[$FiendName];

                        $FiendType = mysql_field_type($result, $i);


                        $strSQL1 = $strSQL1 . "$FiendName, ";
                        switch ($FiendType) {
                            case "string":
                                $FiendValue = js_esc($FiendValue);    
                                break;
                            case "blob":
                                $FiendValue = js_esc($FiendValue);
                                break;
                            case "date":
                                $FiendValue = CDate($FiendValue);
                                break;
                            case "int":
                                $FiendValue = CCur($FiendValue);
                                break;
                            case "bool":
                                break;
                            case "real":
                                $FiendValue = CCur($FiendValue);
                                break;
                            case "number":
                                $FiendValue = CCur($FiendValue);
                                break;
                        }
                        $strSQL2 = $strSQL2 . "'$FiendValue', ";
                        $flags_form = explode(" ", mysql_field_flags($result, $i));

                        if (in_array("primary_key", $flags_form)) {
                            $strPK[] = $FiendName;
                        }
                    }

                    //$ssql= $this->form_save_method." INTO " . $table . " (" . $strSQL1 . "ftbranch_code,fdcreated_date,fdmodified_date,ftcreated_user, ftmodified_user) VALUES (" . $strSQL2 . "'{$_SESSION[strbranch]}',NOW(),NOW(),'{$_SESSION[username]}', '{$_SESSION[username]}')";
                    $ssql = $this->form_save_method . " INTO " . $table . " (" . $strSQL1 . "ftbranch_code,fdcreated_date,fdmodified_date,ftcreated_user, ftmodified_user) VALUES (" . $strSQL2 . "'{$_SESSION[strbranch]}',NOW(),NOW(),'{$_SESSION[username]}', '{$_SESSION[username]}')";
                    $strSQL["Form Hdr"][] = $ssql;

                    if ($_REQUEST['DIRECT_EXECUTE_SQL'] == 1) {
                        mysql_query($ssql) or die("SQL ERROR :{$ssql}");
                    }

                    for ($j = 0; $j < count($this->grid_sql); $j++) {
                        $strSQL["Insert Detail_" . $j] = $this->GetSqlGridSave($this->grid_sql[$j], $j, $strPK);
                    }

                }

                if(function_exists("FinalDataLast")) {
                    $m = FinalDataLast();
                    $strSQL = array_merge_recursive($strSQL, $m);
                }
                 
                $this->Query_SqlArr($strSQL);
                
                // Call Function After Commit SQL
                if(function_exists("FinalDataAfter")) {
                     $strSQL2=FinalDataAfter();
                     $this->Query_SqlArr($strSQL2);
                }
                
                //Proses FIFO
                fifo_save();

                // Call Function Process General Ledger
                if(function_exists("ProcessGL")) {
                    $m = ProcessGL();
                    $this->Query_SqlArr($m);
                }
                
                $idx = GetId();
                if ($idx != 0) {
                    echo "<script>window.location='{$url}?form={$form}&mode=edit&id={$idx}';
                          </script>";
                } else {
                    echo "<script>window.location='{$url}?form={$form}';
                          </script>";
                }
                
                // echo "<script>window.location='{$url}?form={$form}&mode=edit&id=0';</script>";

                die("");
            }

            function str_to_array($str) {
                $arr = explode(",", $str);
                for ($i = 0; $i < count($arr); $i++) {
                    $arr[$i] = trim($arr[$i]);
                }
                return $arr;
            }

            function setObject($index, $row, $name, $type, $len, $value, $script, $locked, $layout = "", $size_object = "") {
                if ($size_object != "") {
                    $size = $size_object;
                } else {
                    $size = $this->size_object[$type];
                }
                if ($index == -1) {
                    $alias_id = $name;
                    $alias_name = $name;
                } else {
                    if ($row == -1) {
                        $alias_id = $name . "D" . $index . "_N_";
                        $alias_name = $name . "D" . $index . "[]";
                        if ($name == "fnindex") {
                            $value = "";
                        }
                    } else {
                        $alias_id = $name . "D" . $index . $row;
                        $alias_name = $name . "D" . $index . "[]";
                        $script = str_replace("_N_", $row, $script);
                        $layout = str_replace("_N_", $row, $layout);
                    }
                }


                $locked5 = " style=\"text-align: right;\"";
                if ($locked) {
                    $locked1 = "readonly style='background-color: #E0E0E0'";
                    $locked2 = "disabled";
                    $locked3 = "  onFocus='this.initialSelect = this.selectedIndex;' onClick='this.initialSelect = this.selectedIndex;'  onChange='this.selectedIndex = this.initialSelect;' style='background-color: #E0E0E0'";
                    $locked4 = "style='background-color: #E0E0E0'";

                    $locked5 = "readonly style=\"text-align: right;background-color: #E0E0E0\"";
                }
                echo "<table  class=\"is_edit_table\"  cellpadding=\"0\" cellspacing=\"0\" width=\"90%\"><tr><td>";
                echo "<div id=\"DivCtl_{$alias_id}\">";
                if ($this->lengt_object) {

                    $maxlength = " maxlength='$len' ";
                } else {
                    $maxlength = "";
                }
                
                $arrStrFrom = array("'",'"');
                $arrStrTo = array("&apos;",'&quot;');
                $value = str_replace($arrStrFrom,$arrStrTo,$value);
            
                switch ($type) {
                    case "string":
                        if ($len > 60)
                            $len = 60;
                        ?>
                        <input class="form-control input-sm" type="text" class="form-control" id="<?= $alias_id ?>" name="<?= $alias_name ?>"  size="<?= $size ?>"     <?= $maxlength ?> value='<?= $value ?>' <?= $locked1 ?> <?= $script ?>>
                        <?
                        break;
                    case "year":
                        ?>
                        <input class="form-control input-sm" type="file" class="form-control" id="<?= $alias_id ?>" name="<?= $alias_name ?>"  size="<?= $size ?>"     <?= $maxlength ?> value='<?= $value ?>' <?= $locked1 ?> <?= $script ?>>
                        <?
                        break;
						
                    case "time":
                        list($jam, $mnt, $dtk) = explode(':', $value);
                        $value = isset($value) ? $jam . ':' . $mnt . ':' . $dtk : date("H:i:s");
                        ?>
                        <input class="form-control input-sm" type="text" class="form-control" id="<?= $alias_id ?>" name="<?= $alias_name ?>"  size="<?= $size ?>"    <?= $maxlength ?>  value="<?= $value ?>" <?= $locked1 ?> <?= $script ?>>
                        <?
                        break;
                    case "hidden":
                        ?>
                        <input type="hidden" id="<?= $alias_id ?>" name="<?= $alias_name ?>"   <?= $maxlength ?>  value="<?= $value ?>">
                        <?
                        break;
                    case "blob":
                        ?>
                        <textarea class="form-control input-sm" class="form-control" id="<?= $alias_id ?>" name="<?= $alias_name ?>" cols="40" rows="4" <?= $locked1 ?> <?= $script ?>><?= $value ?></textarea>
                            <?
                            break;
                    case "date":
                            list($thn, $bln, $tgl) = explode('-', $value);
                            $value = ($value) ? $tgl . '/' . $bln . '/' . $thn : date("d/m/Y");
                            ?>
                        <table border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td>
                                    <input  size="12"  id="<?= $alias_id ?>" name="<?= $alias_name ?>"  size="<?= $size ?>"   <?= $maxlength ?>  value="<?= $value ?>" readonly <?= $script ?> <?= $locked4 ?>></td><td><input type="button" onClick="if (self.gfPop)
                                                            gfPop.fPopCalendar(document.frmMain.<?= $alias_id ?>);
                                                        return false;" id ="cmdTanggal" name="cmdTanggal" value="..." <?= $locked2 ?>>
                                </td>
                            </tr>
                        </table>
                            <?
                            break;
                    case "int":
                            if ($value == "") {
                                ?>
                            <input type="text" class="form-control" id="<?= $alias_id ?>" name="<?= $alias_name ?>"  size="<?= $size ?>"    maxlength="5" value="_N_" <?= $locked1 ?> <?= $script ?>>
                                <?
                            } else {
                                ?>
                            <input type="text" class="form-control" id="<?= $alias_id ?>" name="<?= $alias_name ?>"  size="<?= $size ?>"     maxlength="5" value="<?= $value ?>" <?= $locked1 ?> <?= $script ?>>
                                <?
                            }
                            break;
                    case "bool":
                            if ($value)
                                $ya = "checked";
                            else
                                $tidak = "checked";
                            ?>
                        <table cellpadding="0" cellspacing="0" class="is_edit_table">
                            <tr>
                                <td><input type=radio id="<?= $alias_id ?>" name="<?= $alias_name ?>" value="1" <?= $ya ?> <?= $script ?> <?= $locked2 ?>></td><td>Ya</td>

                                <td><input type=radio id="<?= $alias_id ?>" name="<?= $alias_name ?>" value="0" <?= $tidak ?> <?= $script ?> <?= $locked2 ?>></td><td>Tidak</td>
                            </tr>
                        </table>
                        <?
                        break;
                    case "real":
                        ?>
                        <input class="form-control" id="<?= $alias_id ?>" name="<?= $alias_name ?>"  size="<?= $size ?>"  type="text"  <?= $maxlength ?>     value="<?= empty($value) ? 0 : $value ?>" onBlur="ElementCurrencyOnBlur(this);" onFocus="ElementCurrencyOnBlur(this);
                                                        this.select();"  <?= $locked5 ?> <?= $script ?>>
                        <?
                        break;
                    case "lookup":
                        ?>
                        <select class="form-control input-sm"  id="<?= $alias_id ?>" name="<?= $alias_name ?>" class="text" <?= $locked3 ?> <?= $script ?>>
                            <option value="" selected>--- Pilih ---</option>
                        <?php
                        $i = 0;

                        if ($index == -1) {
                            $lookupx = $this->lookup[$name];
                        } else {
                            if (isset($this->lookup_grid[$index][$name][0])) {
                                $lookupx = $this->lookup_grid[$index][$name];
                            } else {
                                $lookupx = $this->lookup[$name];
                            }
                        }
                                        
                        $result2 = mysql_query($lookupx[0]);
                        if ($this->id == 0) {
                            while ($row2 = mysql_fetch_array($result2)) {
                                if (strtolower($i) == strtolower($lookupx[3]))
                                    $selected = "selected";
                                else
                                    $selected = "";
                                ?>
                                    <option value="<?= $row2[$lookupx[1]] ?>" <?= $selected ?>><?= $row2[$lookupx[1]] ?> -- <?= $row2[$lookupx[2]] ?></option>
                            <?php
                            $i++;
                            }
                        } else {
                            while ($row2 = mysql_fetch_array($result2)) {
                                if (strtolower($row2[$lookupx[1]]) == strtolower($value))
                                    $selected = "selected";
                                else
                                    $selected = "";
                                ?>
                                    <option value="<?= $row2[$lookupx[1]] ?>" <?= $selected ?>><?= $row2[$lookupx[1]] ?> -- <?= $row2[$lookupx[2]] ?></option>
                                        <?php
                                        $i++;
                                    }
                                }
                                ?>
                        </select>
                                <?php
                                mysql_free_result($result2);
                                break;
                    case "lookup2":
                        if ($index == -1) {
                            $lookupx = $this->lookup[$name];
                        } else {
                            if (isset($this->lookup_grid[$index][$name][0])) {
                                $lookupx = $this->lookup_grid[$index][$name];
                            } else {
                                $lookupx = $this->lookup[$name];
                            }
                        }

                        if (!$locked) {
                            if ($lookupx[5] == "") {
                                $lookupx[5] = "''";
                            }
                            
                            // untuk javascript function jangan tambahkan escape char
                            if (strpos($lookupx[0], "'+") !== false) {
                                $m = " onkeyup=\"ajax_showOptions(this, 'getCountriesByLetters', event, '" . $lookupx[0] . "', '" . $lookupx[1] . "', '" . $lookupx[2] . "',{$lookupx[5]})\"";
                            // tambahkan escape char untuk single quote
                            } else if (strpos($lookupx[0], "'") !== false) {
                                $m = " onkeyup=\"ajax_showOptions(this, 'getCountriesByLetters', event, '" . str_replace("'", "\'", $lookupx[0]) . "', '" . $lookupx[1] . "', '" . $lookupx[2] . "',{$lookupx[5]})\"";
                            } else {
                                $m = " onkeyup=\"ajax_showOptions(this, 'getCountriesByLetters', event, '" . $lookupx[0] . "', '" . $lookupx[1] . "', '" . $lookupx[2] . "',{$lookupx[5]})\"";
                            }
                                    
                            /* 
                            if ($this->lookup_magic_quotes) {
                                $m = " onkeyup=\"ajax_showOptions(this, 'getCountriesByLetters', event, '" . str_replace("'", "\'", $lookupx[0]) . "', '" . $lookupx[1] . "', '" . $lookupx[2] . "',{$lookupx[5]})\"";
                            } else {
                                $m = " onkeyup=\"ajax_showOptions(this, 'getCountriesByLetters', event, '" . $lookupx[0] . "', '" . $lookupx[1] . "', '" . $lookupx[2] . "',{$lookupx[5]})\"";
                            } */
                            
                        } else {
                            $m = "";
                        }
                        ?>
								
                        <table cellpadding="0" cellspacing="0" border="0"  class="is_edit_table"  width='100%'>
                            <tr>
                                <td width="50px;">
                                    <input class="form-control" type="text" id="<?= $alias_id ?>" name="<?= $alias_name ?>" size="20" value="<?= $value ?>" <?php echo $m; ?> <?= $script ?> <?= $locked1 ?> <?= $enter ?>>
                                </td>
                                    <?
                                    //$value = str_replace("&amp;","&",$value);
                                    //echo $value;
                                    if ($value != "") {
                                        if ((strstr(strtolower($lookupx[0]), "order by"))) {
                                            $ssql = "select * from (" . $lookupx[0] . ") mm where " . $lookupx[1] . " = '" . $value . "'";
                                        } else if ((strstr(strtolower($lookupx[0]), "union all"))) {
                                            $ssql = "select * from (" . $lookupx[0] . ") mm where " . $lookupx[1] . " = '" . $value . "'";
                                        } elseif (strstr(strtolower($lookupx[0]), "where")) {
                                            $ssql = $lookupx[0] . " and " . $lookupx[1] . " = '" . $value . "'";
                                        } else {
                                            $ssql = $lookupx[0] . " WHERE " . $lookupx[1] . " = '" . $value . "'";
                                        }
                                        $result = mysql_query($ssql) or die($ssql);
                                        $row = mysql_fetch_array($result);
                                        $value_desc = $row[1];
                                    }
                                    if ($locked) {
                                        $type = "hidden";
                                        $m = "{$value_desc}";
                                        $m = "";
                                    } else {
                                        $type = "hidden";
                                        $m = "";
                                    }
                                    ?>
                                <td> 
                                    <?php 
                                    // header or footer dispkay
                                    if ($index == -1) {
                                        $span_layout = "&nbsp; - ";
                                        $span_style = "";
                                    // grid display    
                                    } else {
                                        $span_layout = "";
                                        $span_style = "white-space: pre;";
                                    }
                                    ?>
                                    <?= $span_layout ?> <?= $m ?><span  style='<?= $span_style ?>'  id='span_<?php echo $alias_id; ?>' name='span_<?php echo $alias_name; ?>' <?= $maxlength ?> > <?php echo $value_desc; ?></span><input type="<?= $type ?>" id="hidden_<?= $alias_id ?>" name="hidden_<?= $alias_name ?>"   value="<?= $value_desc ?>" readonly style="background-color: #E0E0E0" <?= $enter ?>> 
                                </td>
                            </tr>
                        </table>
                        <?
                        break;
                }

                echo "</div></td>";
                if ($layout != "") {
                    echo "<td><div id='formLayout' style='margin-left:10px;'>$layout</div></td>";
                }
                echo "</tr></table>";
            }

            function previewData($url, $form, $mode) {

                $result_master = mysql_query("SELECT * FROM tlreport WHERE fnid = " . $this->id);
                $row_master = mysql_fetch_array($result_master);

                $result_detail = mysql_query("SELECT * FROM tlreport_filter WHERE ftReport_Code = '" . $row_master["ftReport_Code"] . "'");
                while ($row_detail = mysql_fetch_array($result_detail, MYSQL_ASSOC)) {
                    $arrField[] = $row_detail["ftFilter_Field"];
                    $arrSQL[] = $row_detail["ftFilter_SQL"];
                }
                ?>
                <form name="frmMain" id="frmMain" method="post" enctype="multipart/form-data" action="<?= $PHP_SELF ?>">
                    <table width="100%" border="0" cellspacing="0" cellpadding="5">
                        <tr>
                            <td colspan="3"><span class="phpmaker"><b><?= $row_master["ftReport_Name"] ?></b></span></td>
                        </tr>
                        <tr>
                            <td width="50%" valign="top">
                                <table class="ewTable">
                                <?
                                $MySQL_Username = _USER_DB;
                                $MySQL_Password = _PASS_DB;
                                $MySQL_Host = _SERVER_DB;
                                $MySQL_Database_Name = _NAME_DB;
                                $link = mysqli_connect($MySQL_Host, $MySQL_Username, $MySQL_Password);
                                mysqli_select_db($link, $MySQL_Database_Name);

                                $ReportSQL = $row_master["ftReport_SQL"];
                                $ReportSQL = str_replace("fdFrom_Date", "'2008-01-01'", $ReportSQL);
                                $ReportSQL = str_replace("fdEnd_Date", "'2008-12-31'", $ReportSQL);
                                //$result2 = mysqli_query($link, $ReportSQL) or die(mysql_error() . "\n");
                                ?>
                                </table>
                                <input type="submit" name="btnGenerate" id="btnGenerate" value="Generate">
                            </td>
                        </tr>
                        <tr>
                            <td width="50%" valign="top">

                                <?
                                $result2 = mysqli_query($link, $ReportSQL) or die(mysql_error() . "\n");
                                while ($finfo = $result2->fetch_field()) {
                                    $field_name[] = $finfo->name;
                                    $field_type[] = $finfo->type;

                                    echo $finfo->name . "\t | \t";
                                }
                                echo "<br>";

                                while ($row2 = mysqli_fetch_array($result2, MYSQL_ASSOC)) {


                                    $j = 0;

                                    foreach ($row2 as $key => $value) {
                                        if ($key == "Supplier" || $key == "Kategori" || $key == "Tipe Barang") {
                                            if ($supplier_temp == $row2["Supplier"] && $kategori_temp == $row2["Kategori"]) {
                                                $value = "";
                                                if ($tipe_temp == $row2["Tipe Barang"]) {
                                                    $value2 = "";
                                                } else {
                                                    $value2 = $row2[$key];
                                                    $total_temp = 0;
                                                }

                                                if ($key == "Tipe Barang") {
                                                    $value = $value2;
                                                    $tipe_temp = $row2["Tipe Barang"];
                                                    $total_temp = $total_temp + $row2["Total Harga"];
                                                }
                                            } else {
                                                $value = $row2[$key];
                                            }

                                            if ($key == "Kategori") {
                                                $supplier_temp = $row2["Supplier"];
                                                $kategori_temp = $row2["Kategori"];
                                            }
                                        }

                                        echo $value . "\t | \t";
                                    }
                                    echo "<br>";
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3">
                                <!-- BEGIN: Button -->
                                        <?= $this->setButton() ?>
                                <!-- END: Button	-->
                            </td>
                        </tr>
                    </table>
                </form>
                <!-- END: Form Preview -->
        <?
    }

    /* form edit master vino ** */

    function editData($url, $form, $mode) {
        ?>
        <script>
		$(document).ready(function(){	
		//$("#search").hide();
			$('#search', window.parent.document).hide();
			$('#btn-query', window.parent.document).hide();
			$(".kiri", window.parent.document).show();	
	
	
			$('.sublinksub', window.parent.document).collapse('hide');
			$(".menhid", window.parent.document).hide();

			$(".menhid2", window.parent.document).hide();
			$(".menhid", window.parent.document).hide();				
			$(".kiri", window.parent.document).addClass('kiri-min');
			$(".kirihead", window.parent.document).addClass('kirihead-min');
			$(".kanan", window.parent.document).removeClass('kanan-max').addClass('kanan-min');
			$(".kananhead", window.parent.document).addClass('kananhead-min');
		});

        </script>		
                <div class="container" style="padding-top:12px">
                    <!-- BEGIN: Form master-Detail -->
                    <form name="frmMain" id="frmMain"  enctype="multipart/form-data" method="post" action="<?= $PHP_SELF ?>">
                        <div class="pagestop" style="max-height:40vh;overflow:auto">
                        <table style="font-size:12px" width="100%" border="0" cellspacing="0" cellpadding="5">
                            <!-- <tr bgcolor="#3E8C3E" style="height:40px;border:1px solid #E1E1E8"> -->
                            <tr id="form-title-color" style="height:40px;border:1px solid">    
                                <td colspan="3"><h2 class="section-heading">&nbsp;<?= $this->form_name ?></h2></td>
                            </tr>
                            <tr bgcolor="#F7F7F9" style="border:1px solid #E1E1E8">
                                <td width="50%" valign="top">
                                    <br>
                                    <!-- BEGIN: Form Header TL (Top Left) -->
                                    <table width="100%" style="font-size:12px" >
                                        <?php
                                        // --------------------------------------------------
                                        // set TL (Top Left) Position
                                        // --------------------------------------------------
                                        if (isset($this->arrTL)) {
                                            foreach ($this->arrTL as $val) {
                                                ?>
                                                <tr valign="top">
                                                    <td  align="right" style="padding-bottom:5px;"><div id='divCap_<?= $val[0] ?>'><?= $val[6] ?> &nbsp;</div></td>
                                                    <td style="padding-bottom:5px;"><?= $this->setObject(-1, -1, $val[0], $val[1], $val[2], $val[3], $val[4], $val[5], $val[7], $val[8]); ?></td>
                                                </tr>
                                                <?php
                                            }
                                        }
                                        ?>
                                    </table>
                                    <!-- END: Form Header TL (Top Left) -->
                                    <br>
                                </td>
                                <td>&nbsp;</td>
                                <td width="50%" valign="top" >
                                    <br>
                                    <!-- BEGIN: Form Header TR (Top Right) -->
                                    <table width="100%" style="font-size:12px">
                                    <?php
                                    // --------------------------------------------------
                                    // set TR (Top Right) Position
                                    // --------------------------------------------------
                                    if (isset($this->arrTR)) {
                                        foreach ($this->arrTR as $val) {
                                            ?>
                                                <tr valign="top">
                                                    <td align="right" style="padding-bottom:5px;"><div id='divCap_<?= $val[0] ?>'><?= $val[6] ?> &nbsp;</div></td>
                                                    <td style="padding-bottom:5px;"><?= $this->setObject(-1, -1, $val[0], $val[1], $val[2], $val[3], $val[4], $val[5], $val[7], $val[8]); ?></td>
                                                </tr>
                                                <?php
                                            }
                                        }
                                        ?>
                                    </table>
                                    <!-- END: Form Header TL (Top Left) -->
                                </td>
                            </tr>

                            <?php if (count($this->grid_sql) > 0) { ?>
                                <tr class="is_edit_row2" >
                                    <td colspan="3">
                                        <br>
                                        <?= $this->grid_element; ?>
                                        <!-- BEGIN: Form Detail GRID -->
                                        <?php
                                        $this->setGrid(count($this->grid_sql));
                                        ?>
                                        <!-- END: Form Detail GRID -->
                                    </td>
                                </tr>
                            <?php } ?>

                            <tr bgcolor="#F7F7F9">
                                <td width="50%" valign="top">
                                    <br>
                                    <!-- BEGIN: Form Header BL (Bottom Left) -->
                                    <table width="100%" style="font-size:12px;">
                                        <?php
                                        // --------------------------------------------------
                                        // set BL (Bottom Left) Position
                                        // --------------------------------------------------
                                        if (isset($this->arrBL)) {
                                            foreach ($this->arrBL as $val) {
                                                ?>
                                                <tr style="margin-bottom:5px;">
                                                    <td align="right" valign="top" style="padding-bottom:5px;"><div id='divCap_<?= $val[0] ?>'><?= $val[6] ?> &nbsp;&nbsp;</div></td>
                                                    <td style="padding-bottom:5px;"><?= $this->setObject(-1, -1, $val[0], $val[1], $val[2], $val[3], $val[4], $val[5], $val[7], $val[8]); ?></td>
                                                </tr>
                                                <?php
                                            }
                                            
                                        }
                                        ?>
                                    </table>
                                    <!-- END: Form Header BL (Bottom Left) -->
                                </td>
                                <td>&nbsp;</td>
                                <td width="50%" valign="top" >
                                    <br>
                                    <!-- BEGIN: Form Header BR (Bottom Right) -->
                                    <table width="100%" style="font-size:12px">
                                    <?php
                                    // --------------------------------------------------
                                    // set BR (Bottom Right) Position
                                    // --------------------------------------------------
                                    if (isset($this->arrBR)) {
                                        foreach ($this->arrBR as $val) {
                                            ?>
                                                <tr style="margin-bottom:5px;">
                                                    <td align="right" valign="top" style="padding-bottom:5px;"><div  id='divCap_<?= $val[0] ?>'><?= $val[6] ?> &nbsp;&nbsp;</div></td>
                                                    <td style="padding-bottom:5px;"><?= $this->setObject(-1, -1, $val[0], $val[1], $val[2], $val[3], $val[4], $val[5], $val[7], $val[8]); ?></td>
                                                </tr>
                                            <?php
                                        }
                                    }
                                    ?>
                                    </table>
                                    <!-- BEGIN: Form Header BR (Bottom Right) -->
                                </td>
                            </tr>
                            <tr class="is_footer_row" style="border-top:1px solid #ddd;">
                                <td colspan="3"  style="border-top:1px solid #ddd;">
                                 
                                </td>
                            </tr>
                        </table></div>
						
                        <!-- BEGIN: Button -->
                        <?= $this->setButton() ?>
                        <!-- END: Button	-->						
                        <input type="hidden" name="mode" id="mode" value="<?= $this->mode ?>">
                        <input type="hidden" name="form" id="form" value="<?= $this->form ?>">
                <?= $this->form_hidden ?>
                <?
                if (isset($this->arrHD)) {
                    foreach ($this->arrHD as $val) {
                        ?>
                        <?= $this->setObject(-1, -1, $val[0], $val[1], $val[2], $val[3], $val[4], $val[5], $val[7], $val[8]); ?>
                    <?
                    }
                }
                ?>
                    </form>
                    <!-- END: Form master-Detail -->
                </div>

                <!-- BEGIN: global startup script -->
                <script language="JavaScript" type="text/javascript">
                <!--
                <?= $this->script_global ?>
                -->
                </script>


                <?
            }

            function setGrid($num_array_grid) {
                for ($i = 0; $i < $num_array_grid; $i++) {
                    if ($i > 0) {
                        echo "<br>";
                    }
                    if (isset($this->grid_replace[$i])) {
                        // echo "<div id='txtHint{$i}' style=\"max-height:40vh;width:97vw;overflow:auto\">";
                        echo "<div id='txtHint{$i}' style=\"width:97vw;overflow:auto\">";
                        echo $this->grid_replace[$i];
                        echo "</div>";
                    } else {
                        //echo "<div id='txtHint{$i}' style=\"max-height:40vh;overflow:auto\">";
                        echo "<div id='txtHint{$i}' style=\"overflow:auto\">";
                        $this->setGrid1($i);
                        echo "</div>";
                        $this->setGridJS($i, $this->num_rows_grid[$i]);
                    }
                }
            }

            function AjaxSetGrid($index) {
                ob_start();
                $this->Process();
                $this->setGrid1($index);
                $html = ob_get_contents();
                ob_end_clean();
                ?>
                div = document.getElementById('txtHint<?php echo $index; ?>');
                var m='<?php echo js_esc($html); ?>';
                div.innerHTML =m.replace(/^\s*|\s*$/g,"");
                TransactionDetailRowID<?php echo $index; ?> =document.getElementsByName('fnindexD<?php echo $index; ?>[]').length;
                <?
            }

            function setGrid1($i) {


                // --------------------------------------------------
                // Detail Grid Properties
                // --------------------------------------------------
                // BUAT $this->arrGrid
                $filter_grid = $this->filter_grid;
                if (isset($filter_grid)) {
                    $query = $this->grid_sql[$i] . " WHERE " . $filter_grid;
                } else {
                    $query = $this->grid_sql[$i] . " WHERE fnid = 0";
                }
                if (isset($this->grid_filter[$i])) {
                    $query .= $this->grid_filter[$i];
                }
                //echo $query."||";
                $result_grid = mysql_query($query);
                $num_rows_grid = mysql_num_rows($result_grid);
                $num_fields_grid = mysql_num_fields($result_grid);


                $this->num_rows_grid[$i] = $num_rows_grid;
                $k = 0;

                for ($j = 0; $j < $num_fields_grid; $j++) {
                    // --------------------------------------------------
                    // get MySQL fields properties (Grid)
                    // --------------------------------------------------
                    $name_grid = mysql_field_name($result_grid, $j);
                    $len_grid = mysql_field_len($result_grid, $j);
                    unset($lookupx);

                    if (isset($this->lookup_grid[$i][$name_grid][0])) {
                        $lookupx = $this->lookup_grid[$i][$name_grid];
                    } elseif (isset($this->lookup[$name_grid])) {
                        $lookupx = $this->lookup[$name_grid];
                    }

                    if (isset($lookupx)) {
                        if ($lookupx[4])
                            $type_grid = "lookup";
                        else
                            $type_grid = "lookup2";
                    } else {
                        if ($len_grid == 1)
                            $type_grid = "bool";
                        else
                            $type_grid = mysql_field_type($result_grid, $j);
                    }
                    $script_grid = $this->grid_script[$i][$j];
                    $locked_grid = $this->grid_locked[$i][$j];
                    $caption_grid = $this->grid_caption[$i][$j];
                    $size_grid = $this->grid_size[$i][$j];
                    //$caption_grid = $name_grid;
                    if ($this->grid_hidden[$i][$j] == 1)
                        $type_grid = "hidden";
                    $layout_grid = $this->grid_layout[$i][$j];

                    $this->arrGrid[$i][0][] = array($name_grid, $type_grid, $len_grid, $row_grid[$name_grid], $script_grid, $locked_grid, $caption_grid, $layout_grid, $hidden_grid, $size_grid);
                }
                //======================================


                $num_fields_grid = count($this->arrGrid[$i][0]);
                ?>
				
                <div class="table-responsive" style="width:93vw">
                <table id="TransactionDetail<?= $i ?>" name="TransactionDetail<?= $i ?>" class="table table-bordered" width="100%" cellspacing="1" cellpadding="3">

                <!-- BEGIN: Grid Name -->
                <?
                if (!isset($this->grid_name[$i])) {
                    $style_grid_name = " style=\"display: none;\"";
                }
                ?>

                        <?php
                        $hidden_count = 0;
                        $j1 = 0;
                        if (isset($this->grid_hidden[$i])) {
                            foreach ($this->grid_hidden[$i] as $val) {
                                if ($this->grid_hidden[$i][$j1] == 1) {
                                    $hidden_count++;
                                }
                                $j1++;
                            }
                        }
                        ?>
                    <tr class="ewTableHeader" bgcolor="#656565">
                        <td colspan="<?= ($num_fields_grid - $hidden_count) ?>" <?= $style_grid_name ?>><?= $this->grid_name[$i] ?> </td>
						
                    </tr>

                    <!-- END: Grid Name -->

                    <!-- BEGIN: Grid ColumnHeader -->
                    <tr  class="is_edit_header_row" bgcolor="#B5B5B5" style="color:#000">
                        <?
                        $j1 = 0;
                        foreach ($this->arrGrid[$i][0] as $val) {
                            ?>

            <?php
            $grid_layout = $this->grid_layout[$i][$j1];
            if ($this->grid_hidden[$i][$j1] == 1) {
                $style = " style=\"display:none;\" ";
            } else {
                $style = "  ";
            }
            $j1++;
            ?>


                            <td  <?php echo $style; ?>  class="is_edit_header_data" valign="top" ><?= $val[6] ?></td>
                            <?
                        }

                        if ($this->grid_allowdelete[$i]) {
                            ?>
                            <td style="background-color:#B5B5B5" class="is_edit_header_data" nowrap>

							
							</td>
                        <? } ?>
                    </tr>
                    <!-- END: Grid ColumnHeader -->

                    <!-- BEGIN: Grid Template -->
                    <tr class="is_edit_grid_row" bgcolor="#F7F7F9" id="TransactionDetailBlankRow<?= $i ?>" name="TransactionDetailBlankRow<?= $i ?>" style="display: none;">
                        <?
                        $j1 = 0;
                        foreach ($this->arrGrid[$i][0] as $val) {
                            if ($this->grid_hidden[$i][$j1] == 1) {
                                $style = " style=\"display:none;\" ";
                            } else {
                                $style = "  ";
                            }
                            $j1++;
                            ?>
                            <td  <?php echo $style; ?> class="is_edit_grid_data"  >
                        <?= $this->setObject($i, -1, $val[0], $val[1], $val[2], "", $val[4], $val[5], $val[7], $val[9]); ?>
                            </td>
                        <?
                    }
                    if ($this->grid_allowdelete[$i]) {
                        if ($this->grid_scriptdelete[$i]) {
                            ?>
                                <td class="is_edit_grid_data" nowrap><input type="button" value="Hapus" class="btn btn-danger" onClick="if (deleteRow(_N_))
                                    TransactionDetailReset<?= $i ?>(this);" onKeyPress="return handleEnter(this, event)"></td>
                        <? } else { ?>
                                <td class="is_edit_grid_data" nowrap><input type="button" value="Hapus" class="btn btn-danger" onClick="TransactionDetailReset<?= $i ?>(this); submitbutton('Hapus Grid');" onKeyPress="return handleEnter(this, event)"></td>
                        <? }
                    }
                    ?>
                    </tr>
                    <!-- END: Grid Template -->

                    <!-- BEGIN: Grid Revision -->
                        <?
                        if ($this->num_rows_grid[$i] > 0) {
//                                $num_array_grid1 = count($this->arrGrid[$i]);
                            #for($j=0; $j < $num_array_grid1; $j++) {
                            $j = 0;

                            while ($row_grid = mysql_fetch_array($result_grid)) {
                                $j++
                                ?>
                            <tr class="is_edit_grid_row" id="TransactionDetailBlankRow<?= $i ?>" name="TransactionDetailBlankRow<?= $i ?>">
                                <?
                                $j1 = 0;
                                foreach ($this->arrGrid[$i][0] as $val) {
                                    if ($val[0] == "fnindex") {
                                        $row_grid[$val[0]] = $j;
                                    }
                                    if ($this->grid_hidden[$i][$j1] == 1) {
                                        $style = " style=\"display:none;\" ";
                                    } else {
                                        $style = "  ";
                                    }
                                    $j1++;
                                    ?>


                                    <td class="is_edit_grid_data"   <?php echo $style; ?> >
                                        <?= $this->setObject($i, $j, $val[0], $val[1], $val[2], $row_grid[$val[0]], $val[4], $val[5], $val[7], $val[9]); ?>
                                    </td>
                                    <?
                                    }
                                    if ($this->grid_allowdelete[$i]) {
                                        if ($this->grid_scriptdelete[$i]) {
                                        ?>
                                            <td class="is_edit_grid_data" nowrap><input type="button" class="btn btn-danger" value="Hapus" onClick="if (deleteRow(<?= $j ?>))
                                                    TransactionDetailReset<?= $i ?>(this);" onKeyPress="return handleEnter(this, event)"></td>
                                        <? } else { ?>
                                            <td class="is_edit_grid_data" nowrap><input type="button" class="btn btn-danger" value="Hapus" onClick="TransactionDetailReset<?= $i ?>(this);
                                                                                                                    submitbutton('Hapus Grid');" onKeyPress="return handleEnter(this, event)"></td>
                                        <? }
                                    }
                                    ?>
                            </tr>
                        <? }
                        }
                        ?>
                <!-- END: Grid Revision -->

                </table>
                </div>

                <!--buton tambah detail-->
                <? if ($this->grid_allowaddnew[$i]) { ?>
                    <div align="left" style="padding-right:5px;margin-top:10px;margin-bottom:10px;">
                        <input type="button" class="btn btn-danger" value="Tambah Detail" onClick="TransactionDetailAddRow<?= $i ?>();if (document.getElementById('TransactionDetail<?= $i ?>').rows.length == 4) { }" ></div>
                <? } else { ?>	
                   <div align="left" style="padding-right:5px;margin-bottom:10px;"></div>
                <? } ?>	
                
                <!--buton tambah detail-->
                <!-- <hr> -->
				
                <input id="TransactionDetailCount<?= $i ?>" name="TransactionDetailCount<?= $i ?>" value="<?= $num_array_grid1 ?>" type="hidden">
                <input id="PopupTransactionDetailCount<?= $i ?>" name="PopupTransactionDetailCount<?= $i ?>" value="<?= $num_array_grid1 ?>" type="hidden">


				
				<?

            }

            function setGrid2($i) {
                $this->setGrid1($i);
            }

	function setStartUpJS($i)
	{
		?>
		<script language="JavaScript" type="text/javascript">
		<!--
		InitialTransactionDetailCount<?=$i?> = 1;
		for (var i=0; i < InitialTransactionDetailCount<?=$i?>; i++) {
			TransactionDetailAddRow<?=$i?>();
		};
		-->
		</script>
		<?
	}

	function setGridJS($i, $num_array_grid1)
	{
		?>
		<script type="text/javascript">
		<!--

		var TransactionDetailRowID<?=$i?> = <?=$num_array_grid1?>;
                try {
                    TransactionDetailRowID<?php echo $i; ?> =document.getElementsByName('fnindexD<?php echo $i; ?>[]').length-1;
                }
                catch(ex) {

                }

		function TransactionDetailAddRow<?=$i?>() {
                	var TransactionDetail<?=$i?> = document.getElementById("TransactionDetail<?=$i?>");
			TransactionDetailRowID<?=$i?> = TableAddRow<?=$i?>("TransactionDetailBlankRow<?=$i?>", TransactionDetail<?=$i?>, TransactionDetailRowID<?=$i?>);
			document.getElementById("TransactionDetailCount<?=$i?>").value = TransactionDetailRowID<?=$i?>;
                        <?php if(isset($this->grid_add_js[$i])) echo $this->grid_add_js[$i]; ?>
                }

		function TransactionDetailReset<?=$i?>(r)
		{       
			var i = r.parentNode.parentNode.rowIndex;
			document.getElementById("TransactionDetail<?=$i?>").deleteRow(i);
                        RowIndex<?=$i?>();
                        <?php if(isset($this->grid_del_js[$i])) echo $this->grid_del_js[$i]; ?>
                        
		}

		function TableAddRow<?=$i?>(blankRowID, table, rowID)
		{

			var blankRowA;
			blankRowA= document.getElementById(blankRowID);
			rowID++;

			var newRow = table.insertRow(-1);
			newRow.id = rowID;
                        var Row0= table.rows[1];
			for (var i=0; i < blankRowA.cells.length; i++) {
				var A = newRow.insertCell(-1);
				A.className = "is_edit_grid_row";
				A.innerHTML = blankRowA.cells[i].innerHTML.replace(/_N_/g, (rowID));
                                A.style.display = Row0.cells[i].style.display;
			}

			if ((rowID%2)==0) {
				newRow.className = "is_edit_grid_data";
			} else {
				newRow.className = "is_edit_grid_data";
			}


                        RowIndex<?=$i?>();
			return rowID;
		}

                function TableAddRowFirst<?=$i?>() {
                        if(document.getElementById("TransactionDetail<?=$i?>") != null) {
                               InitialTransactionDetailCount<?=$i?> = 1;
                               for (var i=0; i < InitialTransactionDetailCount<?=$i?>; i++) {
                                       //TransactionDetailAddRow<?=$i?>();
                               };
                       }
                }

                function RowIndex<?=$i?>() {
                        <?php
                        if($this->grid_reindex[$i]) {
                            ?>

                            var jj =document.getElementsByName('fnindexD<?=$i?>[]').length;
                            for(var ii=0;ii<jj;ii++) {
                               document.getElementsByName('fnindexD<?=$i?>[]')[ii].value=ii;
                            }
                            document.getElementById("TransactionDetailCount<?=$i?>").value = jj;
                            <?php
                        }
                        ?>

                }

                function RowBuild<?=$i?>() {
                        document.getElementById('TransactionDetailCount<?=$i?>').value=0;
                        TransactionDetailRowID<?=$i?>=0;
                        InitialTransactionDetailCount<?=$i?> = 1;
                        for (var i=0; i < InitialTransactionDetailCount<?=$i?>; i++) {
                            TransactionDetailAddRow<?=$i?>();

                        };
                }
                
                //shortcuts Ctrl+Alt+D add new row
                var isCtrl = false;
                var isShift = false;
                document.onkeyup=function(e) {
                    if(e.which == 17) isCtrl=false;
                    if(e.which == 18) isShift=false;
                }
                document.onkeydown=function(e){
                    if(e.which == 17) isCtrl=true;
                    if(e.which == 18) isShift=true;
                    if(e.which == 68 && isShift == true && isCtrl == true) {
                         //TableAddRow<?=$i?>("TransactionDetailBlankRow<?=$i?>", TransactionDetail<?=$i?>, TransactionDetailRowID<?=$i?>);
                         TransactionDetailAddRow<?=$i?>();
                         return false;
                    }
                }
		-->
               <?php
                #}
                if($this->grid_auto_add[$i]) {
                    if(($this->id == 0)) { ?>
                         RowBuild<?=$i?>();
                    <?
                    }
                }
		?>
		</script>
		<?

	}

        function setButton() {
            // --------------------------------------------------
            // set Button
            // --------------------------------------------------
            ?>
                <table  cellspacing="3" cellpadding="3" style="margin-left:15px;margin-top:5px;margin-bottom:10px;">
                    <tr class="ewTableRow" >
                        <?php
                        $num_array_button = count($this->button_show);
                        for ($i = 0; $i < $num_array_button; $i++) {
                            $ButName = $this->button_show[$i];
                            $ButCap = $this->button[$ButName][0];
                            $ButIco = $this->button[$ButName][1];
                            $ButJs = $this->button[$ButName][2];
                            $m = "";
                            if ($ButJs == "") {
                                if ($ButName == "simpan") {
                                    $m = " if(Val" . str_replace(" ", "", $this->form_name) . "()==false) { return false;} ";
                                }
                            } else {
                                $m = $ButJs;
                            }

                            $url_plus = "''";
                            if ($ButCap == 'Generate Report') {
                                echo "<script>";
                                echo "function furl_plus(url_plus) { var temp='';
                                        ";
                                $result1 = mysql_query($this->form_sql);
                                $jml = mysql_num_fields($result1);
                                for ($ii = 0; $ii < $jml; $ii++) {
                                    $FiendName = mysql_field_name($result1, $ii);
                                    echo "
                                                try {
                                                    temp=document.getElementById('hidden_{$FiendName}').value;
                                                } catch(ex) {
                                                    temp='';
                                                }
                                                temp='&hidden_{$FiendName}='+base64_encode(temp);
                                                temp_value = encodeURIComponent(document.getElementById('{$FiendName}').value);
                                                url_plus=url_plus+ temp+'&{$FiendName}='+temp_value;";
                                } 
                                echo "  return url_plus;
													}";
                                echo "function furl_plusx(p) { ";
                                echo "  submitbutton('" . $ButCap . "','" . str_replace(" ", "", strtolower($this->modul_name)) . "','" . str_replace(" ", "", strtolower($this->form_name)) . "','" . $this->id . "',furl_plus(p),'" . $_REQUEST['form'] . "');

													}
													</script>";
                                $url_plus = "furl_plus('')";
                            }
                            if ($ButName == 'print_report') {

                                $m = " printIframe('iframe_laporan'); ";
                                $m2 = "";
                            } elseif ($ButName == 'cetak_daftar') {
                                $m = " printSelection('divDetail'); ";
                                $m2 = "";
                            } else if ($ButName == 'simpan_revisi') {
                                $m = " if(Revisi" . str_replace(" ", "", $this->form_name) . "()==false) { return false;} ";
                                $m2 = " submitbutton('" . $ButCap . "','" . str_replace(" ", "", strtolower($this->modul_name)) . "','" . str_replace(" ", "", strtolower($this->form_name)) . "','" . $this->id . "'," . $url_plus . ",'" . $_REQUEST['form'] . "');";
                            } else if ($ButName == 'final') {
                                $m = " if(Final" . str_replace(" ", "", $this->form_name) . "()==false) { return false;} ";
                                $m2 = " submitbutton('" . $ButCap . "','" . str_replace(" ", "", strtolower($this->modul_name)) . "','" . str_replace(" ", "", strtolower($this->form_name)) . "','" . $this->id . "'," . $url_plus . ",'" . $_REQUEST['form'] . "');";
                            } else if ($ButName == 'update') {
                                $m = "if (function_exists('Update" . str_replace(" ", "", $this->form_name) . "')) { if(Update" . str_replace(" ", "", $this->form_name) . "()==false) { return false;} }";
                                $m2 = " $m submitbutton('" . $ButCap . "','" . str_replace(" ", "", strtolower($this->modul_name)) . "','" . str_replace(" ", "", strtolower($this->form_name)) . "','" . $this->id . "'," . $url_plus . ",'" . $_REQUEST['form'] . "');";
                            } else {
                                $m2 = "  submitbutton('" . $ButCap . "','" . str_replace(" ", "", strtolower($this->modul_name)) . "','" . str_replace(" ", "", strtolower($this->form_name)) . "','" . $this->id . "'," . $url_plus . ",'" . $_REQUEST['form'] . "');";
                            }
                            $menu = $_REQUEST['form'] . "_" . $ButName;

                            if (!$this->GetSecurity($menu)) {
                                $m2 = base64_encode($m2);
                                $m = " window.open('approval.php?m={$m2}&menu={$menu}','approve','height='+300+',width='+500+',top='+200+',left='+200+',scrollbars=0,resizable=1,menubar=0,status=0,fullscreen  =1');";
                                $m2 = "";
                            } else {
                                ?>
                                <!--<img src="icon/<?= $ButIco ?>" alt="<?= $ButCap ?>" name="<?= $ButCap ?>" title="<?= $ButCap ?>" align="middle" border="0" /><br /><?= $ButCap ?>-->
                                <td  valign="top" align="center" >
                                    <button type="button" class="btn btn-success" id="<?= $ButCap ?>" onClick="<?php echo $m . " " . $m2; ?>"><i class="fa fa-check"></i> <?= $ButCap ?></button>&nbsp;
                                </td>
                                <?
                            }
                }
                ?>
                    </tr>


                </table>
        <?php
    }

    /* Ajax & Layout Pencarian (begin) */

    function viewData($url, $form, $page, $order_field, $order_type) {
        ?>
		<script>
		$(document).ready(function(){	

                    $('#search', window.parent.document).show();
                    $('.sublinksub', window.parent.document).collapse('hide');
                    $(".menhid", window.parent.document).hide();

                    $(".menhid2", window.parent.document).hide();
                    $(".menhid", window.parent.document).hide();				
				
                    $(".kiri", window.parent.document).addClass('kiri-min');
                    $(".kirihead", window.parent.document).addClass('kirihead-min');
                    $(".kanan", window.parent.document).addClass('kanan-min');
                    $(".kananhead", window.parent.document).addClass('kananhead-min');

                    $('#btn-query', window.parent.document).show();
		
		});
		</script>
                
                <script type="text/javascript">
                    <!--
                    var firstrowoffset = 1; // First data row start at
                    var lastrowoffset = 0; // Last data row end at
                    var EW_LIST_TABLE_NAME = 'ewlistmain'; // Table name for list page
                    var rowclass = 'ewTableRow'; // Row class
                    var rowaltclass = 'ewTableAltRow'; // Row alternate class
                    var rowmoverclass = 'ewTableHighlightRow'; // Row mouse over class
                    var rowselectedclass = 'ewTableSelectRow'; // Row selected class
                    var roweditclass = 'ewTableEditRow'; // Row edit class

                    function resetSearch() {
                        for (var i=0; i < document.forms[0].elements.length; i++) {
                                var element = document.forms[0].elements[i];
                                if (element.type == "checkbox") {
                                        element.checked = false;
                                        document.getElementById("div"+element.name).style.display = "none";
                                }
                        }
                    }    
                    //-->
			
                </script>
                
                <div id="mySidenav" class="sidenav">
                                <div class="panel-group" id="accordion" style="width:98%;margin-left:2px;border:1px solid #ccc">
                                    <div class="panel panel-default">
                                        <div class="panel-heading">
                                            <h4 class="panel-title">
                                               Menu Pencarian 
                                            </h4>
                                        </div>
                                        <div id="collapseOne" style="background-color:#fff" class="panel-collapse collapse in">
                                            <div class="panel-body">


                                        <!--<img src="icon/icon_filter.png" align="center">&nbsp;<a href="javascript:void(0);" onClick="if(document.getElementById('tdSearch').style.display == 'none') { document.getElementById('tdSearch').style.display=''; } else { document.getElementById('tdSearch').style.display='none'; }">Pencarian</a>&nbsp;&nbsp;&nbsp;-->

                                                <!-- START SEARCH-->		
                                                <div class="col-md-12" valign="top" id="tdSearch" name="tdSearch">
                                                    <?
                                                    //
                                                    if ($this->view_period) {
                                                        $search = "WHERE fdtrans_date >= '" . date("Y/m/01") . "' AND fdtrans_date <= '" . date("Y/m/t") . "' ";
                                                    }

                                                    if ($this->view_table == "") {
                                                        $query2 = "SELECT * FROM ( ";
                                                        $query2 .= $this->view_sql;
                                                        if (empty($order_field) || $order_field == "") {
                                                            $query2 .= " ) a $search ";
                                                        } else {
                                                            $query2 .= " ) a $search ORDER BY $order_field $order_type ";
                                                        }
                                                    } else {
                                                        $query2 = "SELECT * FROM  ";
                                                        $query2 .= $this->view_table;
                                                        if (empty($order_field) || $order_field == "") {
                                                            $query2 .= "  $search ";
                                                        } else {
                                                            $query2 .= "  $search ORDER BY $order_field $order_type ";
                                                        }
                                                    }
                                                    $query2 .= " LIMIT " . LIMIT_PAGE_TRANSACTION;
                                                    $result2 = mysql_query($query2);
                                                    $fields2 = mysql_num_fields($result2);
                                                    $num_rows2 = mysql_num_rows($result2);
                                                    $table2 = mysql_field_table($result2, 0);

                                                    for ($i = 0; $i < $fields2; $i++) {

                                                        $type2[] = mysql_field_type($result2, $i);
                                                        $name2[] = mysql_field_name($result2, $i);
                                                        $len2[] = mysql_field_len($result2, $i);
                                                        $flags2[] = mysql_field_flags($result2, $i);
                                                        $caption2[] = $this->view_caption[$i];
                                                    }

                                                    $num_arr2 = count($name2);
                                                    ?>
                                                    <form name="frmSearch" id="frmSearch">
                                                        <table>

                                                            <tr>
                                                                <td>
                                                                    <table width="100%" cellpadding=2 style="font-size:12px">
                                                                        <?
                                                                        if ($this->view_period) {
                                                                            $filter_checked = "checked";
                                                                            $date_selected = "selected";
                                                                            $date_value1 = date('01/m/Y');
                                                                            $date_value2 = date('t/m/Y');
                                                                        } else {
                                                                            $filter_checked = "";
                                                                            $date_selected = "";
                                                                            $date_value1 = date('d/m/Y');
                                                                            $date_value2 = date('d/m/Y');
                                                                        }

                                                                        for ($i = 1; $i < $num_arr2; $i++) {
                                                                            if ($this->view_period && $name2[$i] == "fdtrans_date") {
                                                                                //$filter_checked = "checked";
                                                                                $filter_checked = "";
                                                                                $div_style = "display: block;";
                                                                            } else {
                                                                                $filter_checked = "";
                                                                                $div_style = "display: none;";
                                                                            }
                                                                            ?>

                                                                            <tr valign="top" >
                                                                                <td>
                                                                                    <input type="checkbox" id="<?= $name2[$i] ?>" name="<?= $name2[$i] ?>" onClick="setActiveSearch(this)" onKeyPress="return handleEnter(this, event)" <?= $filter_checked ?>>&nbsp; <label class="control-label"><?= $caption2[$i] ?></label>
                                                                                    &nbsp;
                                                                                    &nbsp;<br>

                                                                                    <div id="div<?= $name2[$i] ?>" name="div<?= $name2[$i] ?>" style="<?= $div_style ?>">

                                                                                        <?
                                                                                        switch ($type2[$i]) {
                                                                                            case "string":
                                                                                            case "blob":
                                                                                                ?>
                                                                                                Kriteria: <select class="form-control input-sm"  id="cbo<?= $name2[$i] ?>" name="cbo<?= $name2[$i] ?>" onKeyPress="return handleEnter(this, event)"><option value="sama dengan">sama dengan</option><option selected value="seperti">seperti</option></select> 
                                                                                                Yang dicari: <br><input type="text" id="txt<?= $name2[$i] ?>" name="txt<?= $name2[$i] ?>" size="15" maxlength="<?= $len2[$i] ?>" onKeyPress="return handleEnter(this, event)">
                                                                                                <?
                                                                                                break;
                                                                                            case "date":
                                                                                                ?>
                                                                                                Kriteria: <select class="form-control input-sm"  id="cbo<?= $name2[$i] ?>" name="cbo<?= $name2[$i] ?>" onKeyPress="return handleEnter(this, event)"><option value="<"><</option><option value="<="><=</option><option value="=">=</option><option value=">=">>=</option><option value=">">></option><option value="antara" <?= $date_selected ?>>antara</option></select> 
                                                                                                Yang dicari: <br><input size="12" type="text" id="dtp<?= $name2[$i] ?>1" name="dtp<?= $name2[$i] ?>1" maxlength="<?= $len2[$i] ?>" value="<?= $date_value1 ?>" readonly onKeyPress="return handleEnter(this, event)">&nbsp;<input type="button" onClick="if (self.gfPop)
                                                                                                                                        gfPop.fPopCalendar(document.getElementById('dtp<?= $name2[$i] ?>1'));
                                                                                                                                    return false;" id ="cmdTanggal1" name="cmdTanggal1" value="..." onKeyPress="return handleEnter(this, event)"><br>
                                                                                                <input size="12" type="text" id="dtp<?= $name2[$i] ?>2" name="dtp<?= $name2[$i] ?>2" maxlength="<?= $len2[$i] ?>" value="<?= $date_value2 ?>" readonly onKeyPress="return handleEnter(this, event)">&nbsp;<input type="button" onClick="if (self.gfPop)
                                                                                                                                        gfPop.fPopCalendar(document.getElementById('dtp<?= $name2[$i] ?>2'));
                                                                                                                                    return false;" id ="cmdTanggal2" name="cmdTanggal2" value="..." onKeyPress="return handleEnter(this, event)">
                                                                                                <?
                                                                                                break;
                                                                                            case "bool":
                                                                                                ?>
                                                                                                <input type=radio id="opt<?= $name2[$i] ?>" name="opt<?= $name2[$i] ?>" value="1" onKeyPress="return handleEnter(this, event)">Ya
                                                                                                <input type=radio id="opt<?= $name2[$i] ?>" name="opt<?= $name2[$i] ?>" value="0" onKeyPress="return handleEnter(this, event)">Tidak
                                                                                                <?
                                                                                                break;
                                                                                            case "int":
                                                                                            case "real":
                                                                                                ?>
                                                                                                Kriteria: <select class="form-control input-sm"  id="cbo<?= $name2[$i] ?>" name="cbo<?= $name2[$i] ?>" onKeyPress="return handleEnter(this, event)"><option value="<"><</option><option value="<="><=</option><option selected value="=">=</option><option value=">=">>=</option><option value=">">></option></select> 
                                                                                                Yang dicari: <br><input id="cur<?= $name2[$i] ?>" name="cur<?= $name2[$i] ?>" type="text" maxlength="<?= $len2 ?>" size="15" onBlur="ElementCurrencyOnBlur(this);" onFocus="ElementCurrencyOnBlur(this); this.select();" style="text-align: right" onKeyPress="return handleEnter(this, event)">
                                                                                                <?
                                                                                                break;
                                                                                        }
                                                                                        ?>
                                                                                    </div>
                                                                                </td>
                                                                            </tr>
                                                                        <? } ?>
                                                                    </table>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td colspan="2"><br>
                                                                    <input type="button" id="btnCari" class="btn btn-success" name="btnCari" value="Cari" onClick="showList(this, '<?= $this->url ?>?form=<?= $this->form ?>', 'view', 0, '', '<?= $this->order_field ?>', '<?= $this->order_type ?>');" onKeyPress="return handleEnter(this, event)">&nbsp;
                                                                    <input type="button" class="btn btn-success" id="btnSemua" name="btnCari" value="Semua" onClick="showList(this, '<?= $this->url ?>?form=<?= $this->form ?>', 'view', 0, '', '<?= $this->order_field ?>', '<?= $this->order_type ?>');" onKeyPress="return handleEnter(this, event)">&nbsp;<br><br>
                                                                    <input type="button" id="btnReset" class="btn btn-success" name="btnReset" value="Reset Pencarian" onClick="resetSearch();"  onKeyPress="return handleEnter(this, event)"></td>
                                                            </tr>
                                                        </table>
                                                        <input type="hidden" name="mode" id="mode" value="<?= $this->mode ?>">
                                                        <input type="hidden" name="form" id="form" value="<?= $this->form ?>">
                                                        <input type="hidden" name="url" id="url" value="<?= $this->url ?>">
                                                        <input type="hidden" name="keyword" id="keyword" value="<?= $name2[1] ?>">
                                                        <input type="hidden" name="period" id="period" value="fdtrans_date">
                                                    </form>		


                                                    <!-- END SEARCH-->	
                                                    <br>
                                                    <br>
                                                   

                                                </div>			

                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- END ACCORDION -->		
                </div>
				
                <div class="page-content" id="pagecont">
                    <div class="container">		
                        <div class="row">
						
                            <!-- START PERIOD-->	
                            <div align="left" style="margin-left:15px;margin-top:5px;margin-bottom:2px;font-size:12px;">							
                                <form id="frmPeriod" name="frmPeriod">
                                        <? if ($this->view_period) { ?>

                                        <!--Periode : <select class="form-control input-sm"  id="cboPeriod" name="cboPeriod" onKeyPress="return handleEnter(this, event)" onChange="showList(this, '<?= $this->url ?>?form=<?= $this->form ?>', 'view', 0, 'All', '<?= $order_field ?>', '<?= $order_type ?>');"><option value="Seluruh">Seluruh</option>-->
                                        <!-- <br><div style="width:400px;margin-top:-15px;margin-bottom:-17px"> -->
                                        Periode : <select class="form-control input-sm" style="height:30px;display:inline" id="cboPeriod" name="cboPeriod" onKeyPress="return handleEnter(this, event)" onChange="showList('period', '<?= $this->url ?>?form=<?= $this->form ?>', '', '0', '<?= $this->order_field ?>', '<?= $this->order_type ?>');"><option value="Seluruh">Seluruh</option>
                                            <?
                                            $bln_skrg = date("m");
                                            $thn = date("Y");
                                            for ($bln = 1; $bln <= 12; $bln++) {
                                                if ($bln == $bln_skrg)
                                                    $selected = "selected";
                                                else
                                                    $selected = "";
                                                ?>
                                                <option <?= $selected ?> value="<?= date("d/m/Y", strtotime($thn . "-" . $bln . "-01")) . "-" . date("t/m/Y", strtotime($thn . "-" . $bln . "-01")) ?>"><?= date("d M Y", strtotime($thn . "-" . $bln . "-01")) ?> s/d <?= date("t M Y", strtotime($thn . "-" . $bln . "-01")) ?></option>
                                                <?
                                            }
                                            ?>
                                        </select>
                                        <!-- </div> -->
                                        <? } ?>
                                        <span style="margin-left:100px;font-size:14px;"><b><?=strtoupper($this->view_name)?></b></span> 

                                </form>
                            </div>
                            <!-- END PERIOD-->		
                            
                            <?php
                            // use saved search parameter if exist
                            if ($_SESSION["search"]!="") {
                                $search = $_SESSION["search"];
                                $page = $_SESSION["page"]; 
                                $order_type = $_SESSION["order_type"]; 
                                $order_field = $_SESSION["order_field"];
                            }
                            ?>
                            
                            <!-- BEGIN: Button -->
                            <?= $this->setButton() ?>
                            <!-- END: Button	-->                        
                            <div class="pagestop" id="divDetail" name="divDetail" style="margin-top:5px;">
                                <?= $this->listData($form,$search,$page, $order_field, $order_type); ?>
                            </div>						
                            <div class="pagesfix" style="margin-bottom:-15px" id="divPage" name="divPage">
                                <?= $this->pageData($form,$search,$page, $order_field, $order_type); ?>
                            </div>	
                            <!-- BEGIN: Button -->
                            <?= $this->setButton() ?>
                            <!-- END: Button	-->					
                        </div>
                        <!-- END row -->	
                    </div>

                    <?php
                }

                /* Ajax & Layout Pencarian (end) */

                function listData($form, $search = "", $page = 0, $order_field = "", $order_type = "") {
                    $limit = LIMIT_PAGE_TRANSACTION;
                    // $limit = "1000";
                    if (empty($page) || $page == 0) {
                        $offset = 0;
                        $page = 1;
                    } else {
                        $offset = (($page * $limit) - $limit);
                    }

                    if ($search == "") {
                        if ($this->view_period) {
                            $search = "WHERE fdtrans_date >= '" . date("Y/m/01") . "' AND fdtrans_date <= '" . date("Y/m/t") . "'";
                        }
                    }
                    if ($this->view_table == "") {
                        $query = "SELECT * FROM ( ";
                        $query .= $this->view_sql;
                        if (empty($order_type) || $order_type == "") {
                            $query .= " ) a " . $search;
                        } else {
                            $query .= " ) a " . $search . " ORDER BY $order_field $order_type ";
                        }
                    } else {
                        $query = "SELECT * FROM ";
                        $query .= $this->view_table;
                        if (empty($order_type) || $order_type == "") {
                            $query .= "  " . $search;
                        } else {
                            $query .= " " . $search . " ORDER BY $order_field $order_type ";
                        }
                    }

                    $query .= " LIMIT $limit OFFSET $offset";

                    if ($_SESSION['username'] == "admin") {
                        echo "<div class='col-md-12' id='query' style='display:none'><div class='well well-lg'><p>" . $query . "</p></div></div>";
                    }

                    $result = mysql_query($query);
                    $fields = mysql_num_fields($result);
                    $num_rows = mysql_num_rows($result);
                    $table = mysql_field_table($result, 0);

                    for ($i = 0; $i < $fields; $i++) {

                        $type[] = mysql_field_type($result, $i);
                        $name[] = mysql_field_name($result, $i);
                        $len[] = mysql_field_len($result, $i);
                        $flags[] = mysql_field_flags($result, $i);
                        $caption[] = $this->view_caption[$i];
                    }

                    $path = $this->url . "?form=" . $form;
                    ?>	

                    <!--** Table detail master vino-->

                    <div class="col-md-12">
                        <form method="post" name="frmMain" id="frmMain"  enctype="multipart/form-data">
                    <?php
                    if ($num_rows != $num_rows) {
                        ?>
                                <table style="font-size:13px;" nama='tis_view' border="0" class="table table-bordered">
                                    <thead>
                                        <tr  >
                                            <td >
                                                No records found
                                            </td>
                                        </tr>
                                    </thead>
                                </table>
                    <?php
                    } else {    
                    ?>
                                <table style="font-size:13px;" class="table table-bordered">
                                    <!-- Table header -->
                                    <!-- <thead style="background-color:#3E8C3E;"> -->
                                    <thead id="table-head-css">    
                                        <tr>
						<?php
							$num_arr = count($name);
							for ($i = 1; $i < $num_arr; $i++) {
								?>
											<th>
									<?php
									if ($order_field == $name[$i]) {
										if ($order_type == "ASC") {?>
											<a href="#"  style="color:#fff" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', 0, '', '<?= $name[$i] ?>', 'DESC');"><?= $caption[$i] ?> <img src="images/sortup.gif" width="10" height="9" border="0"></a><?
										} else {?>
											<a  href="#" style="color:#fff" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', 0, '', '<?= $name[$i] ?>', 'ASC');"><?= $caption[$i] ?> <img src="images/sortdown.gif" width="10" height="9" border="0"></a><?php
										}
									} 
									else {?>
									<a href="#" style="color:#fff" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', 0, '', '<?= $name[$i] ?>', 'ASC');"><?= $caption[$i] ?></a><?
									}
							}
											?>
											</th>
											<!--<th>&nbsp;&nbsp;&nbsp;</th>-->
										</tr>
									</thead>
                                                                        <tbody style="background-color:#F7F7F9;">
                                                                                <!-- Table body -->
                                                                                                <?php
                                                                                                if ($num_rows == 0) {
                                                                                                        $num_arrx = $num_arr - 1;
                                                                                                        echo "<tr  class=\"is_detail_row\"><td class=\"is_view_header_data\" colspan=\"{$num_arrx}\"> No records found</td></tr>";
                                                                                                }

                                                                                                if ($this->GetSecurity($form . "_detail")) {
                                                                                                        $nnn = 1;
                                                                                                } else {
                                                                                                        $nnn = 0;
                                                                                                }
                                                                                                $row_num = 0;
                                                                                                while ($row = mysql_fetch_row($result)) {

                                                                                                        if (strstr($_REQUEST['form'], "laporan_")) {
                                                                                                                if ($this->GetSecurity($form . "_" . RetRstField("select ftreport_code from tlreport where fnid='" . $row[0] . "'"))) {
                                                                                                                    if (_REPORT_TYPE == 'jasper') {
                                                                                                                        $mm="var reportWin = window.open('{$url}?form={$form}&mode=edit&id={$row[0]}','mywindow','";
                                                        								$mm.="top=0,left=0,";
                                                        								$mm.="width='+screen.width+',";
                                                        								$mm.="height='+screen.height+',";
                                                        								//$mm.="'";
                                                                                                                        $mm.="resizable=yes,";
                                                                                                                        $mm.="scrollbars=yes,";
                                                                                                                        $mm.="toolbar=no,";
                                                                                                                        $mm.="location=no,";
                                                                                                                        $mm.="directories=no,";
                                                                                                                        $mm.="status=no,";
                                                                                                                        $mm.="menubar=no,";
                                                        								//$mm.="copyhistory=no,screenX=100,screenY=10')";
                                                                                                                        $mm.="copyhistory=no'); ";
                                                                                                                        $mm.="reportWin.moveTo(0,0); ";
                                                                                                                    }
                                                                                                                    else if (_REPORT_TYPE == 'html') {
                                                                                                                        #$mm = "window.open('{$url}?form={$form}&mode=edit&id={$row[0]}','mywindow',";
                                                                                                                        //css_custom function (klik row tabel laporan)
                                                                                                                        $mm = "window.open('include/report_execute/run.php?execute_mode=PREPARE&project=project_isnet&xmlin={$row[0]}.xml','mywindow',";

                                                                                                                        $mm.="'";
                                                                                                                        $mm.="resizable=yes,";
                                                                                                                        $mm.="scrollbars=yes,";
                                                                                                                        $mm.="toolbar=no,";
                                                                                                                        $mm.="location=no,";
                                                                                                                        $mm.="directories=no,";
                                                                                                                        $mm.="status=no,";
                                                                                                                        $mm.="menubar=no,";
                                                                                                                        //$mm.="copyhistory=no,screenX=100,screenY=10')";
                                                                                                                        $mm.="copyhistory=no')";
                                                                                                                    }
                                                                                                                } else {
                                                                                                                        continue;
                                                                                                                }
                                                                                                        } elseif (($_REQUEST['form'] == "rekapitulasi_barang")) {
                                                                                                                $mm = "";
                                                                                                        } else {
                                                                                                                $mm = "window.location='{$url}?form={$form}&mode=edit&id={$row[0]}'";
                                                                                                        }
                                                                                                        if ($nnn == 0)
                                                                                                                $mm = "";

                                                                                                        if ($row_num % 2)
                                                                                                                $class = " ";
                                                                                                        else
                                                                                                                $class = " ";

                                                                                                        if (isset($this->view_new_window)) {
                                                                                                                $mm = "window.open('{$url}?form={$form}&mode=edit&id={$row[0]}','mywindow',";
                                                                                                                $mm.="'width=900,";
                                                                                                                $mm.="height=800,";
                                                                                                                $mm.="resizable=yes,";
                                                                                                                $mm.="scrollbars=yes,";
                                                                                                                $mm.="toolbar=no,";
                                                                                                                $mm.="location=no,";
                                                                                                                $mm.="directories=no,";
                                                                                                                $mm.="status=no,";
                                                                                                                $mm.="menubar=no,";
                                                                                                                $mm.="copyhistory=no,screenX=100,screenY=2')";
                                                                                                        }
                                                                                                        ?>
                                                                                        <tr class="<?= $class ?>" onClick="<?= $mm ?>" onMouseOver="this.className = 'HighlightRow'" onMouseOut="this.className = '<?= $class ?>'">
                                                                                                <!-- fnID -->
                                                                                        <?
                                                                                        for ($i = 1; $i < $num_arr; $i++) {
                                                                                                switch ($type[$i]) {
                                                                                                        case "date":
                                                                                                                $align = "center";
//
                                                                                                                $strtime = strtotime($row[$i]);
                                                                                                                $value = date("d M Y", $strtime);
                                                                                                                # $value = isset($row[$i])?date("d M Y", mktime(0,0,0,$bln,$tgl,$thn)):date("d M Y");
                                                                                                                break;
                                                                                                        case "real":
                                                                                                                $align = "right";

                                                                                                                if ($len[$i] == 21) {
                                                                                                                        $nn = 2;
                                                                                                                } else {
                                                                                                                        $nn = 2;
                                                                                                                }
                                                                                                                $value = number_format($row[$i], $nn);
                                                                                                                break;
                                                                                                        default:
                                                                                                                $align = "left";
                                                                                                                $value = $row[$i];
                                                                                                                break;
                                                                                                }
                                                                                                if ($i == 0) {
                                                                                                        ?>
                                                                                                                <td align="<?= $align ?>">
                                                                                                                        <div><?= $value ?></div>
                                                                                                                </td>
                                                                                                                <?
                                                                                                        } else {
                                                                                                                ?>
                                                                                                                <td align="<?= $align ?>">
                                                                                                                        <div><?= $value ?></div>
                                                                                                                </td>
                                                                                                                <?
                                                                                                        }
                                                                                                }
                                                                                                ?>
										<!--<td><a href="<?= $url ?>?form=<?= $form ?>&mode=preview&id=<?= $row[0] ?>">Preview</a></td>-->
															</tr>
								<?php
								$row_num = $row_num + 1;
							}
							?>
                                    </tbody>
                                </table>
            <?
        }
        ?>
                        </form>
                    </div>
                    <!--Table detail master vino-->

                                    <?
                                }

                                function pageData($form, $search = "", $page = 0, $order_field = "", $order_type = "") {
                                    if ($this->view_table == "") {
                                        $tbl_name = "SELECT * FROM ( ";
                                        $tbl_name .= $this->view_sql;
                                        if ($search == "") {
                                            if ($this->view_period) {
                                                $search = "WHERE fdtrans_date >= '" . date("Y/m/01") . "' AND fdtrans_date <= '" . date("Y/m/t") . "'";
                                            }
                                        }

                                        if (empty($order_field) || $order_field == "") {
                                            $tbl_name .= " ) a " . $search;
                                        } else {
                                            $tbl_name .= " ) a " . $search . " ORDER BY $order_field $order_type ";
                                        }
                                        $adjacents = 3;
                                        $query = "SELECT COUNT(*) as num FROM ($tbl_name) a";
                                    } else {
                                        //$tbl_name = "SELECT * FROM  ";
                                        $tbl_nameSum = $this->view_table;
                                        //$tbl_name .= $this->view_table;
                                        if ($search == "") {
                                            if ($this->view_period) {
                                                $search = "WHERE fdtrans_date >= '" . date("Y/m/01") . "' AND fdtrans_date <= '" . date("Y/m/t") . "'";
                                            }
                                        }

                                        if (empty($order_field) || $order_field == "") {
                                            $tbl_nameSum .= "  " . $search;
                                        } else {
                                            $tbl_nameSum .= "  " . $search . " ORDER BY $order_field $order_type ";
                                        }
                                        $adjacents = 3;
                                        //$query = "SELECT COUNT(*) as num FROM $this->view_table";
                                        $query = "SELECT COUNT(*) as num FROM $tbl_nameSum";
                                        $tbl_name = "SELECT * FROM  ";
                                        $tbl_name .= $tbl_nameSum;
                                    }
                                    //echo "<script>alert('1  $tbl_name');</script>";
                                    //echo $tbl_name ;
                                    $total_pages = mysql_fetch_array(mysql_query($query));
                                    $total_pages = $total_pages[num];

                                    /* Setup vars for query. */
                                    //$targetpage = "filename.php"; 	//your file name  (the name of this file)
                                    $limit = LIMIT_PAGE_TRANSACTION;         //how many items to show per page
                                    //if ($total_pages < $limit)
                                    //	echo "";
                                    //$page = $_GET['page'];
                                    if ($page)
                                        $start = ($page - 1) * $limit;    //first item to display on this page
                                    else
                                        $start = 0;        //if no page var is given, set start to 0


                                        /* Get data. */
                                    //$sql = "SELECT column_name FROM $tbl_name LIMIT $start, $limit";
                                    $result = mysql_query($tbl_name);
                                    $total_records = mysql_num_rows($result);

                                    /* Setup page vars for display. */
                                    if ($page == 0)
                                        $page = 1;     //if no page var is given, default to 1.
                                    $prev = $page - 1;       //previous page is page - 1
                                    $next = $page + 1;       //next page is page + 1
                                    $lastpage = ceil($total_pages / $limit);  //lastpage is = total pages / items per page, rounded up.
                                    $lpm1 = $lastpage - 1;      //last page minus 1
                                    $path = $this->url . "?form=" . $form;

                                    /*
                                      Now we apply our rules and draw the pagination object.
                                      We're actually saving the code to a variable in case we want to draw it more than once.
                                     */
                                    if ($lastpage > 1) {
                                        ?>
                        <div class="pagination">
                        <?
                        //previous button

                        if ($page > 1) {
                            ?>
                                <a href="#" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', <?= $prev ?>, '', '<?= $order_field ?>', '<?= $order_type ?>');"><< previous</a>
                        <? } else { ?>
                                <span class="disabled"><< previous</span>
                        <?
                        }
                        //pages

                        if ($lastpage < 7 + ($adjacents * 2)) { //not enough pages to bother breaking it up
                            for ($counter = 1; $counter <= $lastpage; $counter++) {
                                if ($counter == $page) {
                                    ?>
                                        <span class="current"><?= $counter ?></span>
                                <? } else { ?>
                                        <a href="#" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', <?= $counter ?>, '', '<?= $order_field ?>', '<?= $order_type ?>');"><?= $counter ?></a>
                                <?
                                }
                            }
                        } elseif ($lastpage > 5 + ($adjacents * 2)) { //enough pages to hide some
                            //close to beginning; only hide later pages
                            if ($page < 1 + ($adjacents * 2)) {
                                for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) {
                                    if ($counter == $page) {
                                        ?>
                                            <span class="current"><?= $counter ?></span>
                                        <? } else { ?>
                                            <a href="#" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', <?= $counter ?>, '', '<?= $order_field ?>', '<?= $order_type ?>');"><?= $counter ?></a>
                                        <?
                                        }
                                    }
                                    ?>
                                    ...
                                    <a href="#" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', <?= $lpm1 ?>, '', '<?= $order_field ?>', '<?= $order_type ?>');"><?= $lpm1 ?></a>
                                    <a href="#" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', <?= $lastpage ?>, '', '<?= $order_field ?>', '<?= $order_type ?>');"><?= $lastpage ?></a>

                                    <?
                                }
                                //in middle; hide some front and some back
                                elseif ($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) {
                                    ?>
                                    <a href="#" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', 1, '', '<?= $order_field ?>', '<?= $order_type ?>');">1</a>
                                    <a href="#" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', 2, '', '<?= $order_field ?>', '<?= $order_type ?>');">2</a>
                                    ...

                                    <?
                                    for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) {
                                        if ($counter == $page) {
                                            ?>
                                            <span class="current"><?= $counter ?></span>
                                        <? } else { ?>
                                            <a href="#" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', <?= $counter ?>, '', '<?= $order_field ?>', '<?= $order_type ?>');"><?= $counter ?></a>
                                        <?
                                        }
                                    }
                                    ?>
                                    ...
                                    <a href="#" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', <?= $lpm1 ?>, '', '<?= $order_field ?>', '<?= $order_type ?>');"><?= $lpm1 ?></a>
                                    <a href="#" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', <?= $lastpage ?>, '', '<?= $order_field ?>', '<?= $order_type ?>');"><?= $lastpage ?></a>
                                    <?
                                }

                                //close to end; only hide early pages
                                else {
                                    ?>
                                    <a href="#" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', 1, '', '<?= $order_field ?>', '<?= $order_type ?>');">1</a>
                                    <a href="#" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', 2, '', '<?= $order_field ?>', '<?= $order_type ?>');">2</a>
                                    ...
                                    <?
                                    for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) {
                                        if ($counter == $page) {
                                            ?>
                                            <span class="current"><?= $counter ?></span>
                        <? } else { ?>
                                            <a href="#" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', <?= $counter ?>, '', '<?= $order_field ?>', '<?= $order_type ?>');"><?= $counter ?></a>
                                        <?
                                        }
                                    }
                                }
                            }

                            //next button
                            if ($page < $counter - 1) {
                                ?>
                                <a href="#" onClick="showList(document.frmSearch, '<?= $path ?>', 'view', <?= $next ?>, '', '<?= $order_field ?>', '<?= $order_type ?>');">next >></a>
                            <? } else { ?>
                                <span class="disabled">next >></span>
                            </div>
            <?
            }
        }

        $start_record = ($page - 1) * $limit + 1;
        if ($page == $lastpage || $last_page == "")
            $end_record = $total_records;
        else
            $end_record = $page * $limit;
        ?>
                    <?= $page ?> Records <?= $start_record ?> of <?= $end_record ?> from <?= $total_records ?>
        <?
    }

    function menuData($strMenuCategory) {
        ?>
            <html>
				<head>
				<!--vino penambahan link css start-->
				<?php include('class/link_css.php'); ?>
				<!-- vino penambahan link css end -->	
		<script>
		$(document).ready(function(){	
		//$("#search").hide();
		$('#search', window.parent.document).hide();
		$('#btn-query', window.parent.document).hide();
		});		
		</script>
                </head>
                <body>
                    <?
                    echo "<link href='css/project1.css' rel='stylesheet' type='text/css' />\n";
                    ?>
                            <div class="wrapper">
                                <div class="container">

                                    <!-- BASIC PILL -->
                                    <h2 class="section-heading">Menu <?= ucwords(str_replace("_", " ", $strMenuCategory)) ?></h2>
                                    <ul class="nav nav-pills tabs-iconized" role="tablist">
                                        <li class="active"><a href="#chapter1" role="tab" data-toggle="tab"><i class="fa fa-folder-open"></i>  </a></li>
                                        <li><a href="#chapter2" role="tab" data-toggle="tab"><i class="fa fa-camera"></i> </a></li>
                                    </ul>
                                    <div class="tab-content">
                                        <div class="tab-pane fade in active" id="chapter1">
                                            <p>
                                            <!-- KNOWLEDGE CONTENT -->
                                            <div class="row">
                                                <!-- LEFT -->
                                                <div class="col-lg-12">

        <?
        $ssqlx = "select * from(select *,case when ftmenu_type = 'master' then '01' when ftmenu_type = 'transaksi' then '02' when ftmenu_type = 'laporan' then '04' else '03' end as sort2 from tlmenu where ifnull(ftmenu_name2,'')='' and fnstatus = 1 ) d order by fnurut, ftmenu_category,sort2,ftmenu_code";
        $result = mysql_query("SELECT DISTINCT ftmenu_type FROM ( $ssqlx ) m WHERE ftmenu_category = '" . $strMenuCategory . "'");
        $rownum = mysql_num_rows($result);
        if ($rownum > 0) {
            while ($row = mysql_fetch_array($result)) {
                ?>
                                                            <div class="col-md-4">
                                                                <div class="knowledge">
                                                                    <h2><a href="#"><i class="fa fa-folder"></i> <?php echo $row["ftmenu_type"] //sub ?><span class="pull-right">#</span></a></h2>

                                    <?
                                    $result2 = mysql_query("SELECT * FROM ( $ssqlx ) m  WHERE ftmenu_category = '" . $strMenuCategory . "' AND ftmenu_type = '" . $row["ftmenu_type"] . "'");
                                    $rownum2 = mysql_num_rows($result2);
                                    if ($rownum2 > 0) {
                                        while ($row2 = mysql_fetch_array($result2)) {
                                            $exp = explode('=', $row2['a_href']);
                                            $exp1 = explode("&", $exp[1]);
                                            if ($this->GetSecurity($exp1[0])) {
                                                ?>
                                                                                <ul class="list-unstyled">


                            <?php
                            if ($row2["ftmenu_name"] == 'ganti password') {
                                $ssql = "SELECT fnid from tluser WHERE ftusername='{$_SESSION['username']}'";
                                $rs = mysql_query($ssql);
                                $r = mysql_fetch_array($rs);
                                ?>
                                                                                        <li><i class="fa fa-file-o pull-left"></i><a href='<?= $row2["a_href"] ?>&mode=edit&id=<?php echo $r[0]; ?>'>
                                                                                                <span ><?= ucwords(str_replace("_", " ", $row2["ftmenu_name"])) ?></span>
                                                                                            </a> </li>
                                                                        <?php } else { ?>
                                                                                        <li><i class="fa fa-file-o pull-left"></i><a href='<?= $row2["a_href"] ?>'>
                                                                                                <span ><?= ucwords(str_replace("_", " ", $row2["ftmenu_name"])) ?></span>
                                                                                            </a>  </li>
                                                                        <?php } ?>


                                                                                </ul>
                                                                                <?
                                                                            }
                                                                        }
                                                                    }
                                                                    mysql_free_result($result2);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                                    <?
                                                                }
                                                            }
                                                            ?>
                                                </div>
                                                <!-- END LEFT -->
                                            </div>
                                            <!-- END KNOWLEDGE CONTENT -->		
                                            </p>
                                        </div>
                                        <div class="tab-pane fade" id="chapter2">
                                            <p>
                                            <table class='adminform' border='1'>
                                                <tr>
        <?
        $ssqlx = "select * from
                            (select *,
                                case when ftmenu_type = 'master'
                                then '01'
                                when ftmenu_type = 'transaksi'
                                then '02'
                                when ftmenu_type = 'laporan'
                                then '04'
                                else '03'
                                end as sort2
                                from tlmenu
                                where ifnull(ftmenu_name2,'')='' and fnstatus = 1
                            ) d order by fnurut, ftmenu_category,sort2,ftmenu_code";

        $result = mysql_query("SELECT DISTINCT ftmenu_type FROM ( $ssqlx ) m WHERE ftmenu_category = '" . $strMenuCategory . "'");
        $rownum = mysql_num_rows($result);
        if ($rownum > 0) {
            while ($row = mysql_fetch_array($result)) {
                ?>
                                                            <td valign="top">
                                                                <div id='cpanel'>
                <?
                $result2 = mysql_query("SELECT * FROM ( $ssqlx ) m  WHERE ftmenu_category = '" . $strMenuCategory . "' AND ftmenu_type = '" . $row["ftmenu_type"] . "'");
                $rownum2 = mysql_num_rows($result2);
                if ($rownum2 > 0) {
                    while ($row2 = mysql_fetch_array($result2)) {
                        $exp = explode('=', $row2['a_href']);
                        $exp1 = explode("&", $exp[1]);
                        if ($this->GetSecurity($exp1[0])) {
                            ?>
                                                                                <div style='float:left;'>
                                                                                    <div class='icon'>

                                                                        <?php
                                                                        if ($row2["ftmenu_name"] == 'ganti password') {
                                                                            $ssql = "SELECT fnid from tluser WHERE ftusername='{$_SESSION['username']}'";
                                                                            $rs = mysql_query($ssql);
                                                                            $r = mysql_fetch_array($rs);
                                                                            ?>
                                                                                            <a href='<?= $row2["a_href"] ?>&mode=edit&id=<?php echo $r[0]; ?>&search=new'>
                                                                                                <img src='<?= $row2["img_src"] ?>' alt='<?= ucwords(str_replace("_", " ", $row2["img_alt"])) ?>' align='middle' border='0' />
                                                                                                <span class='phpmaker'><?= ucwords(str_replace("_", " ", $row2["ftmenu_name"])) ?></span>
                                                                                            </a>
                                                                        <?php } else { ?>
                                                                                            <a href='<?= $row2["a_href"] ?>&search=new'>
                                                                                                <img src='<?= $row2["img_src"] ?>' alt='<?= ucwords(str_replace("_", " ", $row2["img_alt"])) ?>' align='middle' border='0' />
                                                                                                <span class='phpmaker'><?= ucwords(str_replace("_", " ", $row2["ftmenu_name"])) ?></span>
                                                                                            </a><?php } ?>

                                                                                    </div>
                                                                                </div>
                                                                                <?
                                                                            }
                                                                        }
                                                                    }
                                                                    mysql_free_result($result2);
                                                                    ?>
                                                                </div>
                                                            </td>
                <?
            }
        }
        ?>
                                                </tr>
                                            </table>								
                                            </p>
                                        </div>
                                    </div>
                                    <!-- END BASIC PILL -->
                                </div>
                            </div>
                        </body>
                    </html>

                                                            <?
        //mysql_close($link);
        }

        /* Template System Begin */

function headerData() {
?>
    <html>
        <head>
            <title>Insight System</title>
            <meta name="viewport" content="width=device-width, initial-scale=1"> 
            <script type="text/javascript" src="script/JSCookMenu_mini.js"></script>
            <script type="text/javascript" src="script/JSCookMenu_mini_toppanel.js"></script>
            <script type="text/javascript" src="script/theme.js"></script>
            <script type="text/javascript" src="script/iframe.js"></script>
            <link href="css/theme.css" rel="stylesheet" type="text/css" />
            <?php include('class/link_css.php'); ?>
            <script>
                //============ hide and show menu modul ============ //
                $(document).ready(function() {
                    $("#search").hide();
                    $("#btn-query").hide();
                    $(".menhid2").hide();

                    $("#toggle-button").click(function() {
                        if ($("#iframe1").contents().find("#mySidenav").width() != 0 && !$('#search').is(':hidden')) {
                            $(".kiri").show();
                            $(".kanan").toggleClass('kanan-max');
                            $("#iframe1").contents().find("#mySidenav").animate({
                                width: 0
                            }, 'fast');
                            $("#iframe1").contents().find("#pagecont").animate({
                                marginLeft: 0
                            }, 'fast');
                            if ($(".kirihead").find(".menhid").is(':hidden')) {
                                $(".menhid2").hide();
                                $(".menhid").hide();
                                $(".kirihead").toggleClass('kirihead-min');
                                $(".kananhead").toggleClass('kananhead-min');
                                                 $('.sublinksub').collapse('hide');
                            }

                        } else {
                            $('.sublinksub').collapse('hide');
                            $(".menhid").toggle();
                            $(".kiri").toggleClass('kiri-min');
                            $(".kirihead").toggleClass('kirihead-min');
                            $(".kanan").toggleClass('kanan-min');
                            $(".kananhead").toggleClass('kananhead-min');
                        }

                    });

                    $("#search").click(function() {
                        $(".kiri").toggle();
                        $(".kanan").toggleClass('kanan-max');

                        if ($(".kirihead").find(".menhid").is(':hidden')) {
                            $(".menhid2").toggle();
                            $(".menhid").hide();
                            $(".kirihead").toggleClass('kirihead-min');
                            $(".kananhead").toggleClass('kananhead-min');
                        }
                        var toggleWidth = $("#iframe1").contents().find("#mySidenav").width() == 0 ? "224px" : "0%";
                        $("#iframe1").contents().find("#mySidenav").animate({
                            width: toggleWidth
                        }, 'fast');
                        $("#iframe1").contents().find("#pagecont").animate({
                            marginLeft: toggleWidth
                        }, 'fast');
                    });

                     $(".list-group-item").click(function() {
                        $(this).slideDown();
                       $(".sublinks").collapse('hide');

                        $(".menhid").show();
                        $('.kiri').removeClass('kiri-min').addClass('kiri');
                        $('.kirihead').removeClass('kirihead-min').addClass('kirihead');

                        $(".kanan").removeClass('kanan-min').addClass('kanan');
                        $(".kananhead").removeClass('kananhead-min').addClass('kananhead');
                    }); 

                    $("#btn-query").click(function() {
                        $("#iframe1").contents().find("#query").toggle();
                    });


                });					

                // update theme
                function cektheme(){
                    $.ajax({
                        url: 'checktheme.php',
                        method : "GET",
                    }).done(function(data){
                        objek = jQuery.parseJSON(data);
                        var tema_sekarang = $(".tema_sekarang").val();
                        if(objek.theme != tema_sekarang){
                            location.reload();
                        }
                    });
                }

                //auto reload check theme    
                //setInterval(function(){
                //cektheme();
                //},1000);
                            
            </script>	
        </head>

        <body style="overflow:hidden" onload="cektheme()">
        <!-- WRAPPER -->
            <div class="wrapper">
		<!-- NAVBAR 
		<nav class="navbar navbar-default navbar-fixed-top" role="navigation">-->
		<nav class="navbar navbar-default" role="navigation">
			<div class="container">

				<div class="navbar-header" style="margin-top:4px">
					<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-nav">
						<span class="sr-only">Toggle Navigation</span>
						<i class="fa fa-bars"></i>
					</button>
					<a href="index.php">
						
					
					<h3 class="boxed-content-title" style="font-size:20px;"><img src="css_custom/img/default_logo.png?v=<?php echo time(); ?>" height="33px" alt="Company Logo">
					<span><?php echo $_SESSION['nama_aplikasi']; ?></span>
                                        <span><?php if ($_SESSION['strbranch'] != 'PUSAT') { echo " - " . $_SESSION['namebranch']; } ?></span>
					<small>Version 1.0</small>
					</h3>
					</a>
				</div>
                            
				<!-- MAIN NAVIGATION -->
				<div id="main-nav" class="navbar-collapse collapse navbar-mega-menu">
					<ul class="nav navbar-nav navbar-right">
					<div id="myMenuIDtop"></div>
					<!--	<li class="dropdown ">
							<a href="index.php" ><i class="fa fa-home"></i> &nbsp;HOME </a>
						</li>
						<li class="dropdown ">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dokumentasi <i class="fa fa-angle-down"></i></a>
							<ul class="dropdown-menu" role="menu">
								<li><a href="Library_Engine/FORM%20STRUCTURE.docx">Download File Dokumentasi</a></li>
							</ul>
						</li>
						 <li class="dropdown ">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown">Setting <i class="fa fa-angle-down"></i></a>
							<ul class="dropdown-menu" role="menu">
								<li><a href="page-services.html">Service Page</a></li>
								
							</ul>
						</li>-->
					</ul>
				</div>
				<!-- END MAIN NAVIGATION -->
			</div>
		</nav>
		<!-- END NAVBAR -->							


					<div class="container">
						<!-- <div class="row" style="background-color:#F1F1F1"> -->	
                                                <div class="row" id="kananhead">    
							<div class="kirihead" >
								<!-- <div class="testimonial-author pull-left" style="height:45px;background-color:transparent;color:#fff;width:100%;padding:3px;border-bottom:0px solid #002E00;margin-left:10px"> -->
                                                                <div class="testimonial-author pull-left" style="" id="menu-kiri-head-css">    
									<!-- <img src="css_custom/img/user2.png" alt="Author" class="pull-left" style="width:40px;height:40px;"> -->
									<img src="<?php echo $_SESSION["user_profile"]?>" alt="Profile" class="pull-left" style="width:40px;height:40px;">
									<span class="menhid">
										<span class="author-name"><?php echo $_SESSION['username'];?></span><br> 
										<em>CABANG <?php echo strtoupper($_SESSION["strbranch"])?></em>
									</span>
									<!-- <span class="menhid2">
										<span class="author-name">Muhammad Ridwan</span><br> 
										<em>User of TheCompany</em>
									</span> -->
									
								</div>	
							</div>
							
							<!-- <div class="kananhead" style="background-color:#F1F1F1;"> -->
                                                        <div class="kananhead" id="kananhead">    
                                <!-- BREADCRUMBS -->
                                <ol class="breadcrumb link-accent separator-arrow" style="height:25px;margin-left:0px;text-align:right;">

								<button type="button" style="margin-right:2px;" id="toggle-button" class="btn btn-success pull-left" title="Show / Hide Menu"><i class="fa fa-bars"></i> <span class="sr-only">Success</span> </button> &nbsp;&nbsp;&nbsp;					

							
								<button type="button" style="margin-right:2px;"  id="search" class="btn btn-success pull-left" title="Show / Hide Menu"><i class="fa fa-search"></i> <span class="sr-only">Success</span> </button>&nbsp;&nbsp;&nbsp;	

								<button type="button" style="margin-right:2px;"  id="btn-query" class="btn btn-success pull-left" title="Show / Hide Menu"><i class="fa fa-edit"></i> <span class="sr-only">Success</span> </button>&nbsp;&nbsp;&nbsp;
													
                                    <li><i class="fa fa-user"></i> &nbsp <?php echo $_SESSION['username']; ?></li>
                                    <li class="active"><a href="logout.php" title="Home">Log Out</a></li>
                                </ol>
                                <!-- END BREADCRUMBS -->	
							</div>
						</div>
					</div>
												

								<!-- PAGE CONTENT -->
										<div class="page-content">
											<div class="container">
												<div class="row">	
												
														<!-- <div class="kiri col-md-3" style="overflow-y: auto;overflow-x: hidden;height: 85%;padding-top:5px;  padding-right: 0px;padding-left: 0px;background-color:#006600;border-bottom:3px solid #006600;box-shadow: 0 2px 2px 0 #555,0 2px 10px 0 rgba(0,0,0,0.12) !important;"> -->
                                                                                                                <div class="kiri col-md-3" id="menu-kiri-css">
															<div id="menu">
																<div id="myMenuID" class="panel list-group"></div>
															</div>   	
														</div>
													
														<!-- <div class="kanan" style="background-color:#F1F1F1;"> -->
                                                                                                                <div class="kanan" id="kanan-latar-belakang">
															<iframe id="iframe1" style="max-height:80vh;overflow:auto" src="inventory.php?p=1" ></iframe><br><br><br>
														</div>
												</div>
											</div>
										</div>
                                <!-- START myMenuID JAVASCRIPT SUBMENU -->
                                <?php include("class/submenu.php") ?>
                                <!-- END myMenuID JAVASCRIPT SUBMENU -->
								
                                <!-- END PAGE CONTENT -->
                                
                                <!-- check session exist every 1 minute, if not automatic logout -->
                                <script type='text/javascript' >  
                                        setInterval(function() {
                                            val_session();
                                        }, 60000); 

                                        function val_session() {
                                            if (( '<?php echo $_SESSION['username'];?>' == '' ) || ( '<?php echo $_SESSION['strbranch'];?>' == '' )) { 
                                                window.location='logout.php';
                                            }        
                                        }

                                </script>        
                                <?php
                               
    }

    function footerData() {
        ?>

                               
		<!-- FOOTER -->
		<footer style="background-color:#fff;color:#555;border-top:1px solid #CCCCCC">
			<!-- COPYRIGHT -->
			<div class="text-center copyright" >
				&copy; 2018 <?php echo $copyYear . ((date('Y') != '2018') ? '-' . date('Y') : ' '); ?> INSIGHT SYSTEM . All Rights Reserved.
			</div>
			<!-- END COPYRIGHT -->
		</footer>
		<!-- END FOOTER -->

        </div>
        <!--END wrapper-->	

        </body>
        </html><?
    }

    /* Template System END */

    function reportData() {
        ?>
                    <script type="text/javascript" src="script/script.js"></script>
                    <script type="text/javascript" src="script/QxJavaScriptUtils.js"></script>
                    <script type="text/javascript" src="script/ajax.js"></script>
                    <script type="text/javascript" src="script/ajax2.js"></script>
                    <script type="text/javascript" src="script/QxPopup.js"></script>
                    <script type="text/javascript" src="script/iframe.js"></script>
                    <script type="text/javascript" src="script/sack.js"></script>
                    <script type="text/javascript" src="script/ajax-dynamic-list.js"></script>
                    <script type="text/javascript" src="script_custom/ValidasiForm.js?ver=<?php echo $this->script_version;?>"></script>
                
                    <link href="css/project1.css" rel="stylesheet" type="text/css" />
                    <iframe name="gToday:KalenderIndonesia:agenda.js" id="gToday:KalenderIndonesia:agenda.js" src="KalenderIndonesia.htm" style="visibility: visible; z-index: 999; position: absolute; left: -500px; top: 0px;" frameborder="0" height="189" scrolling="no" width="174"></iframe>
                    <link href="css/styles.css" type="text/css" rel="stylesheet">    
                    
                    <!--vino penambahan link css start-->
                    <?php include('class/link_css.php'); ?>
                    <!-- vino penambahan link css end -->
                    <body   >
                        <!-- BEGIN: Form master-Detail -->
                        <form name="frmMain" id="frmMain" enctype="multipart/form-data" method="post" action="<?= $PHP_SELF ?>">
                            <table width="100%" border="0" cellspacing="0" cellpadding="5">
                                <tr>
                                    <td colspan="3" align="center">
                                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                            <tr><td align="center">
                                                    <h3  class="page-title pull-center"><?= strtoupper($this->form_name) ?></h3></td>
                                                <td align="right">
                                                    <button type="button" class="btn btn-success" onClick="if(document.getElementById('formReport').style.display == 'none') { document.getElementById('formReport').style.display=''; show_filter_cap.textContent  = 'Hide'; } else { document.getElementById('formReport').style.display='none'; show_filter_cap.textContent  = 'Show'; }"><div id="show_filter_cap" style="white-space: nowrap;" >Hide</div></button>&nbsp;
                                                </td> 
                                            </tr>
                                        </table>                    
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td width="50%" valign="top">
                                        <!-- BEGIN: Form Header TL (Top Left) -->
                                        <table  width="100%" style="font-size:12px;">
                                                <?php
                                                // --------------------------------------------------
                                                // set TL (Top Left) Position
                                                // --------------------------------------------------
                                                if (isset($this->arrTL)) {
                                                    foreach ($this->arrTL as $val) {
                                                    ?>
                                                        <tr>
                                                            <td align="right" valign="top"><label class="control-label"><?= $val[6] ?></label>&nbsp;&nbsp;</td>
                                                            <td style="padding-bottom:2px"><?= $this->setObject(-1, -1, $val[0], $val[1], $val[2], $val[3], $val[4], $val[5], "", $val[8]); ?></td>
                                                        </tr>
                                                    <?php
                                                    }
                                                }
                                                ?>
                                        </table>
                                        <!-- END: Form Header TL (Top Left) -->
                                    </td>
                                    <td>&nbsp;</td>
                                    <td width="50%" valign="top">
                                        <!-- BEGIN: Form Header TR (Top Right) -->
                                        <table  width="100%" style="font-size:12px;margin-bottom:10px">
                                                <?php
                                                // --------------------------------------------------
                                                // set TR (Top Right) Position
                                                // --------------------------------------------------
                                                if (isset($this->arrTR)) {
                                                    foreach ($this->arrTR as $val) {
                                                    ?>
                                                        <tr >
                                                            <td align="right" valign="top"><label class="control-label"><?= $val[6] ?></label>&nbsp;&nbsp;</td>
                                                            <td style="padding-bottom:2px"><?= $this->setObject(-1, -1, $val[0], $val[1], $val[2], $val[3], $val[4], $val[5], "", $val[8]); ?></td>
                                                        </tr>
                                                    <?php
                                                    }
                                                }
                                                ?>
                                        </table>
                                        <!-- END: Form Header TL (Top Left) -->
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="3">
                                        <!-- BEGIN: Button -->
                                            <?= $this->setButton() ?>
                                        <!-- END: Button	-->
                                    </td>
                                </tr>
                                <tr>
                                    <td   colspan="3" height="100%" valign="top" align=''><div class="pagination" name='page_laporan' id='page_laporan'></div >

                                    </td>
                                </tr>
                                <tr class="is_view">

                                    <td   colspan="3" height="500" valign="top" align=''>
                                            <?php
                                            echo "<iframe  bgcolor=blue src='' name='iframe_laporan' id='iframe_laporan' width='100%' height='500'  ></iframe>";?>

                                        <!-- END: Form Detail GRID -->
                                    </td>
                                </tr>
                                <tr>
                                    <td valign="top">
                                        <!-- BEGIN: Form Header BL (Bottom Left) -->
                                        <table class="is_edit_table" width="100%">
                                            <?php
                                            // --------------------------------------------------
                                            // set BL (Bottom Left) Position
                                            // --------------------------------------------------
                                            if (isset($this->arrBL)) {
                                                foreach ($this->arrBL as $val) {
                                                    ?>
                                                    <tr class="<?= $class ?>">
                                                        <td class="ewTableHeader"><?= $val[6] ?></td>
                                                        <td><?= $this->setObject(-1, -1, $val[0], $val[1], $val[2], $val[3], $val[4], $val[5], "", $val[8]); ?></td>
                                                    </tr>
													<?php
												}
											}
											?>
                                        </table>
                                        <!-- END: Form Header BL (Bottom Left) -->
                                    </td>
                                    <td>&nbsp;</td>
                                    <td valign="top">
                                        <!-- BEGIN: Form Header BR (Bottom Right) -->
                                        <table style="font-size:14px;" width="100%">
                                        <?php
                                        // --------------------------------------------------
                                        // set BR (Bottom Right) Position
                                        // --------------------------------------------------
                                        if (isset($this->arrBR)) {
                                            foreach ($this->arrBR as $val) {
                                                ?>
                                                    <tr class="<?= $class ?>">
                                                        <td class="ewTableHeader"><?= $val[6] ?></td>
                                                        <td><?= $this->setObject(-1, -1, $val[0], $val[1], $val[2], $val[3], $val[4], $val[5], "", $val[8]); ?></td>
                                                    </tr>
												<?php
											}
										}
										?>
                                        </table>
                                        <!-- END: Form Header BR (Bottom Right) -->
                                    </td>
                                </tr>
                            </table>
                            <input type="hidden" name="mode" id="mode" value="<?= $this->mode ?>">
							<?
                            if (isset($this->arrHD)) {
								foreach ($this->arrHD as $val) {?>
                                <?= $this->setObject(-1, -1, $val[0], $val[1], $val[2], $val[3], $val[4], $val[5], "", $val[8]); ?></td><?
								}
							}
							?>

						<?= $this->form_hidden ?>
                        </form>
                        <!-- END: Form master-Detail -->

                        <!-- BEGIN: global startup script -->
                        <script language="JavaScript" type="text/javascript">
                        <!--<?= $this->script_global ?>-->
                        </script>
                        <!-- END: global startup script -->
        <?
        $this->footerData();
        echo "<script>{$this->form_js}</script>";
    }

    function GetSecurity($id) {

//		mysql_connect("localhost", "root", "") or die("Could not connect");
//		mysql_select_db("isdmi") or die("Could not select database");
        $ssql = "SELECT fbaccess FROM tluser_access WHERE fbaccess =1 and  ftusername = '" . $_SESSION['username'] . "' AND ftsecurity_code = '" . $id . "'";

        // --------------------------------------------------
        # /*
        if ((strstr(strtolower($id), "laporan"))) {
            $ssql2 = "select concat('laporan_',ftreport_group,'_',ftreport_code) as ftsecurity_code from tlreport
                            where  concat('laporan_',ftreport_group,'_',ftreport_code)= '" . $id . "'";
        } else {
            $ssql2 = "select ftsecurity_code,ftmodule_code,ftparent_code,ftsecurity_name from tlsecurity
                           where  ftsecurity_code= '" . $id . "'";
        }

        # */
        /*
          $ssql2="select m.ftsecurity_code from
          (
          select ftsecurity_code,ftmodule_code,ftparent_code,ftsecurity_name from tlsecurity
          union all
          select concat('laporan_',ftreport_group,'_',ftreport_code) as ftsecurity_code,ftreport_group as ftmodule_code, concat('Laporan ',ftreport_group) as ftparent_code,ftreport_name from tlreport
          ) m
          where  m.ftsecurity_code= '" . $id . "'";

         */

        if (!RetRstField($ssql2)) {
            return 1;
        } else {
            return RetRstField($ssql);
        }
    }

}


	