<?php
    class UAM_ACCESS extends UAM
    {
        public function uam_access_javainit()
        {

        }

        public function fn_access_init()
        {
            if(isset($_REQUEST['task'])){$task=trim(strtolower($_REQUEST['task']));}
            if(isset($_POST['task'])){$task=trim(strtolower($_POST['task']));}
            if($_REQUEST||$_POST){if($_REQUEST['sec']||$_POST['sec']){$task=$this->dec($task);}}

            switch($task)
            {
                case "default":
                    $this->fn_default_access();
                break;

                case $task:
                    $task="fn_".$task;
                    if(method_exists($this,$task)){$this->$task();}
                break;

                default:
                    $this->fn_default_access();
                break;
            }
        }
        public function fn_default_access()
        {
            echo $this->FN_CREATEHEADER();
//            echo "<style>
//                      .besidepassword {margin-left:92px;margin-top:-5px;position:absolute;z-index:0}
//                  </style>";
            echo "<script>  
                       var myFormsearch;var dguserauth;var rwcount;
                       function initObject()
                       {";
                           // =====  FOrm Search
                           $formdata=array(
                                              array("type"=>"settings","position"=>"label-left","labelWidth"=>"160","inputWidth"=>"120"),
                                              array("type"=>"fieldset","width"=>"1028","label"=>"User Access Matrix",
                                                     "list"=>array(
                                                                      array("type"=>"hidden","name"=>"txtmenuid"),
                                                                      array("type"=>"combo","name"=>"cbonik","label"=>"Insert Name / NIk","required"=>"true","info"=>"true","inputWidth"=>"350",
                                                                            "tooltip"=>"Insert Name / Nik first","validate"=>"NotEmpty","maxLength"=>"","className"=>"txtleft"),
                                                                      array("type"=>"newcolumn"),
                                                                      array("type"=>"combo","name"=>"cbotipemenu","required"=>"true","info"=>"true","offsetLeft"=>"10",
                                                                            "tooltip"=>"Pilih Tipe Menu terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"","className"=>"txtleft"),
                                                                      array("type"=>"newcolumn"),
                             //                                         array("type"=>"combo","name"=>"cbogroupproject","info"=>"true","offsetLeft"=>"10","width"=>"190",
//                                                                            "tooltip"=>"Pilih Group Project Menu terlebih dahulu. TERIMA KASIH","maxLength"=>"","className"=>"txtleft"),
//                                                                      array("type"=>"newcolumn"),
                                                                      array("type"=>"button","name"=>"btnloadmenu","value"=>"Load Menu","className"=>"button_load","offsetLeft"=>"10","offsetTop"=>"5","disabled"=>"1"),
                                                                      array("type"=>"newcolumn"),
                                                                      array("type"=>"button","name"=>"btnupdatemenu","value"=>"Update","className"=>"button_update","offsetLeft"=>"10","offsetTop"=>"5","disabled"=>"1")
                                                     )
                                              )
                                       );
                           $this->FN_DHTMLXFORM("myFormsearch","divformsearch",$formdata); 
                           $arrval=array(array(value=>"",text=>""),array(value=>"",text=>"Menu"),array(value=>"tree",text=>"TreeMenu"));
                           $this->FN_COMBOVALIDATIONVALUEARRAY("myFormsearch","cbotipemenu",$arrval);
                           
                           $exp="&exp=nik|82010";
                           if($_SESSION['nik']=='82010'){$exp="&exp=";} 
                                                                        
                           //$urlcbo="fn_dhtmlxloadobject('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("dhtmlxaddcombo")."&tableobj=tbl_employee_accessibility|id,nik,employeename:nik,employeename".$exp."')";
                           //$urlcbo="fn_dhtmlxloadobject('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("dhtmlxaddcombo")."&tableobj=tbl_employee|id,nik,fullname:nik,fullname".$exp."')";
                           $urlcbo="fn_dhtmlxloadobject('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("dhtmlxcbofilter")."&tableobj=tbl_employee|id,nik,employeename:nik,employeename".$exp."')";
                           $this->FN_COMBOVALIDATIONVALUENEW("myFormsearch","cbonik","tbl_employee","$urlcbo","");

                           $urlcbo="fn_dhtmlxloadobject('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("dhtmlxcbofilter")."&tableobj=tbl_employee_accessibility|id,nik,employeename:nik,employeename".$exp."')";
                           $urlother="myFormsearch.getCombo('cbogroupproject').clearAll();myFormsearch.getCombo('cbogroupproject').setComboText('');";
                           $urlother.="var groupproject=ajaxuridhtmlx('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("getfieldvalue")."&tableobj=tbl_employee_accessibility&getfield=menuidgroupproject&swhere=id|'+val);";
                           $urlother.="var url=fn_dhtmlxloadobject('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("dhtmlxaddcombo")."&tableobj=tbl_menu_groupproject|id,groupname,groupdescription:id,groupname&in=id|'+groupproject+'&sort=id');";
                           $urlother.=$this->FN_COMBOVALIDATIONVALUE2("myFormsearch","cbogroupproject","tbl_menu_groupproject","url","",true);
                           //$this->FN_COMBOVALIDATIONVALUENEW("myFormsearch","cbonik","tbl_employee_accessibility","$urlcbo","$urlother");

                           // === Form Event
                           $onchangecbotipemenu="myFormsearch.enableItem('btnloadmenu');";
                           $onchangecbotipemenu.="myFormsearch.setItemFocus('btnloadmenu');";
                           
                           $onclickbtnloadmenu="var menuid=ajaxuridhtmlx('".$this->enc("obj_uam")."','obj=".$this->enc("uam_access")."&task=".$this->enc("getmenuid")."&tipemenu='+myFormsearch.getCombo('cbotipemenu').getSelectedValue()+'&idnik='+myFormsearch.getCombo('cbonik').getSelectedValue());";
                           $onclickbtnloadmenu.="myFormsearch.setItemValue('txtmenuid',menuid);";
                           //$onclickbtnloadmenu.="url=fn_dhtmlxloadobject('".$this->enc("obj_uam")."','obj=".$this->enc("uam_access")."&task=".$this->enc("loadmenu")."&idnik='+myFormsearch.getCombo('cbonik').getSelectedValue()+'&tipemenu='+myFormsearch.getCombo('cbotipemenu').getSelectedValue()+'&idgroupproject='+myFormsearch.getItemValue('cbogroupproject'));";
                           $onclickbtnloadmenu.="url=fn_dhtmlxloadobject('".$this->enc("obj_uam")."','obj=".$this->enc("uam_access")."&task=".$this->enc("loadmenu")."&idnik='+myFormsearch.getCombo('cbonik').getSelectedValue()+'&tipemenu='+myFormsearch.getCombo('cbotipemenu').getSelectedValue());";
                           //$onclickbtnloadmenu.="alert(url);";
                           $onclickbtnloadmenu.="dguserauth.clearAndLoad(url);";
                           $onclickbtnloadmenu.="myFormsearch.enableItem('btnupdatemenu');";
                           
                           $eventupdatemenu="dhtmlx.confirm({";
                           $eventupdatemenu.="    title:'Konfirmasi',text:'Data sudah benar dan ingin diupdate?',type:'confirm',";
                           $eventupdatemenu.="    callback:function(result){";
                           $eventupdatemenu.="        if(result)";
                           $eventupdatemenu.="        {";
                           $eventupdatemenu.="            var res=ajaxuridhtmlx('".$this->enc("obj_uam")."','obj=".$this->enc("uam_access")."&task=".$this->enc("updatemenuid")."&idnik='+myFormsearch.getItemValue('cbonik')+'&menuid='+myFormsearch.getItemValue('txtmenuid')+'&tipemenu='+myFormsearch.getItemValue('cbotipemenu'));";
                           $eventupdatemenu.="            var spres=res.split('|');";
                           $eventupdatemenu.="            if(spres[0]=='ok'){fn_dhtmlxmessage('','Menu sudah berhasil diupdate.TERIMA KASIH');}";
                           $eventupdatemenu.="            else{fn_dhtmlxmessage('error','Error Found : '+spres[1]);}";
                           $eventupdatemenu.="            fn_myform_clear();dguserauth.clearAll();".$this->FN_DHTMLXWINDOWSHIDEPROGRESS();
                           $eventupdatemenu.="        }else{".$this->FN_DHTMLXWINDOWSHIDEPROGRESS()."}";
                           $eventupdatemenu.="    }";
                           $eventupdatemenu.="});";
                           $onclickbtnupdatemenu=$this->FN_DHTMLXWINDOWSHOWPROGESS($eventupdatemenu);
                           
                           $arrevent=array(
                                              array("eventname"=>"onbuttonclick","eventparam"=>"id,val",
                                                                "switch"=>array(
                                                                                    "btnloadmenu"=>"$onclickbtnloadmenu",
                                                                                    "btnupdatemenu"=>"$onclickbtnupdatemenu"
                                                                )
                                              ),
                                              array("eventname"=>"onchange","eventparam"=>"id,val",
                                                                "switch"=>array(
                                                                                    "cbotipemenu"=>"$onchangecbotipemenu",
                                                                                    "cbogroupproject"=>"myFormsearch.setItemFocus('btnloadmenu')"
                                                                )
                                              )  
                                     );
                           
                           $this->FN_DHTMLXFORMEVENT("myFormsearch",$arrevent);

                           // === Form Event
                           
//            echo "         // ==== Attach Event Click
//                           myFormsearch.attachEvent(\"onButtonClick\",function(id){
//                               switch(id)
//                               {
//                                    case 'btnloadmenu':
//                                        var menuid=ajaxuridhtmlx('".$this->enc("obj_uam")."','obj=".$this->enc("uam_access")."&task=getmenuid&tipemenu='+myFormsearch.getCombo(\"cbotipemenu\").getSelectedValue()+'&idnik='+myFormsearch.getCombo(\"cbonik\").getSelectedValue());
                                        //alert(menuid);
//                                        myFormsearch.setItemValue(\"txtmenuid\",menuid);

//                                        url=fn_dhtmlxloadobject('".$this->enc("obj_uam")."','obj=".$this->enc("uam_access")."&task=loadmenu&idnik='+myFormsearch.getCombo(\"cbonik\").getSelectedValue()+'&tipemenu='+myFormsearch.getCombo(\"cbotipemenu\").getSelectedValue());
                                        //alert(url);
                                        //dguserauth.enableSmartRendering(true,50);
//                                        dguserauth.clearAndLoad(url);                                        
//                                        myFormsearch.enableItem(\"btnupdatemenu\");
//                                    break;
//                                    case 'btnupdatemenu':
//                                        dhtmlx.confirm({
//                                            title:'Konfirmasi',text:'Data sudah benar dan ingin diupdate?',type:'confirm',
//                                            callback:function(result){
//                                                if(result)
//                                                {
                                                    //alert(myFormsearch.getItemValue(\"txtmenuid\"));
//                                                    var res=ajaxuridhtmlx('".$this->enc("obj_uam")."','obj=".$this->enc("uam_access")."&task=updatemenuid&nik='+myFormsearch.getCombo(\"cbonik\").getSelectedValue()+'&menuid='+myFormsearch.getItemValue(\"txtmenuid\")+'&tipemenu='+myFormsearch.getCombo(\"cbotipemenu\").getSelectedValue());
//                                                    var spres=res.split('|');
//                                                    if(spres[0]=='ok'){fn_dhtmlxmessage('','Menu sudah berhasil diupdate.TERIMA KASIH');}
//                                                    else{fn_dhtmlxmessage('error','Error Found : '+spres[1]);}
//                                                    fn_myform_clear();
//                                                    dguserauth.clearAll();
//                                                }
//                                            }
//                                        });
//                                        
//                                    break;
//                               } 
//                           });

//                           myFormsearch.attachEvent(\"onChange\",function(id,value){
//                                switch(id)
//                                {                                    
//                                    case 'cbotipemenu':
//                                        myFormsearch.enableItem(\"btnloadmenu\");
//                                        myFormsearch.setItemFocus(\"btnloadmenu\");
//                                    break;
//                                }
//                           });";
                           
                           // === data grid attach 
//                           $footerinfo="<a href='javascript:void(0)' style='color:blue' onClick='fn_checkall(1)'>Check All</a>&nbsp;&nbsp;<a href='javascript:void(0)' style='color:blue' onClick='fn_checkall(0)'>Uncheck all</a>";
//                           $grdinit=array("gridname"=>"dguserauth","divtarget"=>"divdgsearch","divpaging"=>"divdgsearchpaging","paginglimit"=>PAGE_LIMIT,
//                                          "showloader"=>"true","setcolumnhidden"=>"false,false,false,false,false","footer"=>"$footerinfo","footerspan"=>"5",
//                                          "attachheader"=>"#rspan,#rspan,#combo_filter,#rspan,#rspan");
//                           $gridproperties=array("C&nbsp;"=>"center,ch,40,center,int,false",
//                                                 "ID.&nbsp;"=>"left,ro,30,left,int,false",
//                                                 "Tipe"=>"center,ro,80,center,str,false",
//                                                 "Menu Text"=>"left,ro,210,left,str,false",
//                                                 "Keterangan"=>"left,ro,*,left,str,false");
//                           $this->FN_DHTMLXGRIDVIEW($grdinit,$gridproperties,"bricks","","");
//            echo "         dguserauth=new dhtmlXGridObject(\"divdgsearch\");
//                           dguserauth.setSkin(\"dhx_skyblue\");
//                           dguserauth.setImagePath(\"".PATH_THEME."/codebase/imgs/\");
//                           dguserauth.setHeader(\"C,Id,Tipe,Menu Text,Keterangan,Group Project\");
//                           dguserauth.setColTypes(\"ch,ro,ro,ro,ro,ro\"); // ro => Read Only, ed => Edit
//                           dguserauth.attachHeader(\"#rspan,#rspan,#combo_filter,#rspan,#rspan,#combo_filter\");                                  
//                           dguserauth.setInitWidths(\"40,30,80,210,320,*\");
//                           dguserauth.setColAlign(\"center,left,center,left,left,left\");
//                           dguserauth.setColSorting(\"int,int,str,str,str,str\");
//                           
//                           dguserauth.setDateFormat(\"%Y-%m-%d %H:%i:%s\");
//                           dguserauth.enablePaging(true,".PAGE_LIMIT.",null,\"divdgsearchpaging\",true,\"recInfoArea\");
//                           dguserauth.setPagingSkin(\"toolbar\",\"dhx_skyblue\");
//                           dguserauth.setPagingSkin(\"bricks\");
//                           dguserauth.enableTooltips(\"false,false,false,false,false\");                           
//                           dguserauth.attachFooter(\"<a href='javascript:void(0)' style='color:blue' onClick='fn_checkall(1)'>Check All</a>&nbsp;&nbsp;<a href='javascript:void(0)' style='color:blue' onClick='fn_checkall(0)'>Uncheck all</a>,#cspan,#cspan,#cspan,#cspan,#cspan\",[\"text-align:left;\"]);
//                           dguserauth.init();";
                            
                            $footerevent="<a href='javascript:void(0)' style='color:blue' onClick='fn_checkall(1)'>Check All</a>&nbsp;&nbsp;<a href='javascript:void(0)' style='color:blue' onClick='fn_checkall(0)'>Uncheck all</a>";
                            $grdinit=array("gridname"=>"dguserauth","divtarget"=>"divdgsearch","divpaging"=>"divdgsearchpaging","paginglimit"=>PAGE_LIMIT,"skin"=>"modern",
                                           "showloader"=>"true","setcolumnhidden"=>"false,false,false,false,false,false",
                                           "attachheader"=>"#rspan,#rspan,#combo_filter,#rspan,#rspan,#combo_filter","footer"=>"$footerevent","footerspan"=>"6","footeralign"=>"left",
                                           "enableheadermenu"=>true);
                            $gridproperties=array("C"=>"center,ch,40,center,int,false",
                                                  "ID.&nbsp;"=>"left,ro,30,left,str,false",
                                                  "Menu Type"=>"left,ro,110,left,str,false",
                                                  "Menu Text"=>"left,ed,180,left,str,false",
                                                  "Menu Description"=>"left,ro,280,left,str,false",
                                                  "Group Project"=>"center,combo,180,center,str,false");
                            $this->FN_DHTMLXGRIDVIEW($grdinit,$gridproperties,"bricks",true,"");                           
                           // === data grid attach Event
            echo "         dguserauth.attachEvent(\"onXLE\",function(){
                                rwcount=dguserauth.getRowsNum();
                                var menuid=myFormsearch.getItemValue(\"txtmenuid\");
                                if(menuid)
                                {                                    
                                    spmenuid=menuid.split(',');
                                    //dguserauth.cells(40,0).setValue(1);return false;
                                    for(i=1;i<=rwcount;i++)
                                    {
                                        var id=dguserauth.cells(i,1).getValue();
                                        //    id=trim(id);
                                        for(j=0;j<spmenuid.length;j++)
                                        {
                                            if(trim(spmenuid[j])==trim(id))
                                            {
                                                dguserauth.cells(i,0).setValue(1);
                                            }
                                        }
                                        //var id=dguserauth.cells(i,1).getValue();
                                        //var strmatch=spmenuid.indexOf(id);
                                        //if(strmatch>=0){dguserauth.cells(i,0).setValue(1);}
                                    }    
                                }
                           });
                           
                           dguserauth.attachEvent(\"onEditCell\",function(stage,rowid,colid){
                               // stage 2 is edit closed
                               if(colid==0&&stage==1){fn_getmenuid();}
                               //alert(colid);
                               return true;
                           });
                       }
                       
                       function fn_checkall(chkvalue)
                       {
                           //var rwcount=dguserauth.getRowsNum();
                           if(rwcount<=0){fn_dhtmlxmessage('error','Mohon maaf data tidak ada / belum query');return false;}
                           //alert(rwcount);
                           for(i=1;i<=rwcount;i++)
                           {
                               dguserauth.cells(i,0).setValue(chkvalue); 
                               //alert(i+' '+dguserauth.cells(i,0).getValue(chkvalue)); 
                           }
                           if(chkvalue==1){fn_getmenuid();}
                       }
                       
                       function fn_getmenuid()
                       {
                           //var rwcount=dguserauth.getRowsNum();
                           //alert(dguserauth.getSelectedRowId());
                           //alert(rwcount);
                           var varmenuid='';
                           for(i=1;i<=rwcount;i++)
                           {
                               var id=dguserauth.cells(i,0).getValue();
                               
                               if(id==1){varmenuid=varmenuid+dguserauth.cells(i,1).getValue()+',';}
                           }
                           varmenuid=varmenuid.substring(0,varmenuid.length-1);
                           myFormsearch.setItemValue(\"txtmenuid\",varmenuid);
                           //alert(myFormsearch.getItemValue(\"txtmenuid\"));
                       }
                       
                       function fn_myform_clear()
                       {
                           myFormsearch.getCombo(\"cbonik\").setComboValue('');
                           myFormsearch.getCombo(\"cbonik\").setComboText('');
                           myFormsearch.getCombo(\"cbotipemenu\").setComboValue('');
                           myFormsearch.getCombo(\"cbotipemenu\").setComboText('');
                           myFormsearch.disableItem(\"btnloadmenu\");
                           myFormsearch.disableItem(\"btnupdatemenu\");
                           myFormsearch.setItemFocus(\"cbonik\");
                           
                       }
                  </script>";
            echo $this->FN_CLOSEHEADER();
            echo $this->FN_CREATEBODY("e8f1ff");
            echo "  <table width=\"100%\" border=\"0\">
                        <tr>
                            <td valign=\"top\">
                                <div id=\"divformsearch\" style=\"width:100%\"></div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div id=\"divdgsearch\" style=\"height:420px;width:1028px;overflow:hidden\"></div>
                            </td>
                        </tr>
                        <tr><td valign=\"top\"><div id=\"loadergrid\" style=\"z-index:100;position:absolute;margin-top:-220px;margin-left:437px;display:none;\">".$this->CREATE_IMAGE("loadergrid.gif")."</div></td></tr>
                        <tr>
                            <td>
                                <div id=\"divdgsearchpaging\" style=\"width:830px;margin-top:1px\"></div>
                            </td>
                        </tr>
                        
                    </table>";            
            echo $this->FN_CREATEFOOTER();
        }
        
        public function fn_updatemenuid()
        {
            $id=$_REQUEST['idnik'];
            $spemp=$this->fn_get_fieldsvalues("nik,employeename,msisdn","select nik,employeename,msisdn from ".DB_APORTIL.".tbl_employee where id='$id'");
            $nik=$spemp[0];$fullname=$spemp[1];$msisdn=$spemp[2];
            $menuid=$_REQUEST['menuid'];//echo $menutype;return true;
            $tipemenu=$_REQUEST['tipemenu'];//echo $menutype;return true;
            $idgroupproject="";
            
            $qry="select distinct id_menu_groupproject from ".DB_APORTIL.".tbl_treemenu where id in($menuid) order by id_menu_groupproject asc";
            $rs=$this->selectquery($qry);
            if($rs)
            {
                while($rw=$this->data_row_object($rs))
                {
                    $idgroupproject.=$rw->id_menu_groupproject.",";
                }
                $idgroupproject=substr($idgroupproject,0,strlen($idgroupproject)-1);
            }
            $this->clearrecordset($rs);
            
            $qry="insert into ".DB_APORTIL.".tbl_employee_accessibility
                  set nik='$nik',employeename='$fullname',msisdn='$msisdn',pass='".$this->enc("1234")."',maskpass='1234',
                      menuidgroupproject='$idgroupproject',treemenuid='$menuid',idgroupuser='1',groupuser='ALL',isactivated=1,
                      iby='".$_SESSION['nik']."',idt=now()";
            $qrychk="select id from ".DB_APORTIL.".tbl_employee_accessibility where nik='$nik'";
            if($this->fn_row_isexists($qrychk))
            {
                $id=$this->fn_get_fieldvalue("id",$qrychk);
                $qry="update ".DB_APORTIL.".tbl_employee_accessibility
                      set menuidgroupproject='$idgroupproject',".$tipemenu."menuid='$menuid',uby='".$_SESSION['nik']."',udt=now()
                      where id='$id'";    
            }            
            //echo "failed|$qry";return false;
            if($this->executequery($qry))
            {
                echo 'ok|';
                //$msg="Menu baru <b>".strtoupper("$nmuser")."</b> sudah berhasil ditambahkan<br/>";
                //$msg.="Klik ".$this->CREATE_LINK($this->fn_url_home(),"disini","javascript:void(0)","_self","Penambahan Menu Baru");
                //$msg.=" untuk Penambahan Menu Baru. TERIMA KASIH";
                //echo $this->SHOWMESSAGE($msg);    
            }else{echo "failed|".$this->getErrorQuery();}
        }        
        
        public function fn_loadmenu()
        {
            $id=$_REQUEST["idnik"];
            $nik=$this->fn_get_fieldvalue("nik","select nik from ".DB_APORTIL.".tbl_employee where id='$id'");
            $tipemenu=$_REQUEST["tipemenu"];
            //$idgroupproject=$_REQUEST["idgroupproject"];
            $sp=$this->fn_get_fieldsvalues("menuidgroupproject,groupuser","select menuidgroupproject,groupuser from ".DB_APORTIL.".tbl_employee_accessibility where nik='$nik'");
            //echo "select menuidgroupproject,groupuser from ".DB_APORTIL.".tbl_employee_accessibility where nik='$nik'";return false;
            $menuidgroupproject=$sp[0];$groupuser=$sp[1];
            //include XML Header (as response will be in xml format)
            header("Content-type: text/xml");
            //encoding may be different in your case
            echo('<?xml version="1.0" encoding="utf-8"?>'); 
            //start output of data
            echo "<rows id=\"0\">";
            //if(!$menuidgroupproject){$menuidgroupproject=0;}
            $swhere="";
            if($menuidgroupproject)
            {
                $swhere="and t.id_menu_groupproject in($menuidgroupproject)";        
            }
            //if($idgroupproject){$swhere="and t.id_menu_groupproject='$idgroupproject'";}
            //if($nik=='82010'||$groupuser=='SU'&&!$idgroupproject){$swhere="";}

            $qry="select t.id,t.menutype,t.menutext,t.menudesc,0 ischecked,m.groupname 
                  from ".DB_APORTIL.".tbl_".$tipemenu."menu t inner join ".DB_APORTIL.".tbl_menu_groupproject m on m.id=t.id_menu_groupproject
                  where t.isdeleted=0 and t.menuactivated=1 $swhere
                  order by t.id asc limit ".TBL_PAGE_LIMIT;
            echo $qry;
            $rs=$this->selectquery($qry);                    
            if($rs)
            {
                $i=1;
                while($row=$this->data_row_array($rs))
                {
                    //create xml tag for grid's row
                    echo ("<row id='".$i."'>");
                            print("<cell><![CDATA[".$row["ischecked"]."]]></cell>");
                            print("<cell><![CDATA[".$row["id"]."]]></cell>");
                            print("<cell><![CDATA[".$row["menutype"]."]]></cell>");
                            print("<cell><![CDATA[".$row["menutext"]."]]></cell>");
                            print("<cell><![CDATA[".$row["menudesc"]."]]></cell>");
                            print("<cell><![CDATA[".$row["groupname"]."]]></cell>");
                    echo ("</row>");
                    $i+=1;
                }
            }
            else
            {
                //error occurs
                echo mysql_errno().": ".mysql_error()." at ".__LINE__." line in ".__FILE__." file<br>";
            }
            echo "</rows>";
    
        }
        
        public function fn_getnik()
        {
            $nik=$_REQUEST["nik"];
            $getnik=$this->fn_get_fieldvalue("nik","select nik from ".DB_APORTIL.".tbl_employee_accessibility where nik='$nik' and isdeleted=0");
            echo $getnik;
        }

        public function fn_getmenuid()
        {
            $id=$_REQUEST["idnik"];
            $nik=$this->fn_get_fieldvalue("nik","select nik from ".DB_APORTIL.".tbl_employee where id='$id'");
            $tipemenu=$_REQUEST["tipemenu"];
            $menuid=$this->fn_get_fieldvalue($tipemenu."menuid","select ".$tipemenu."menuid from ".DB_APORTIL.".tbl_employee_accessibility where nik='$nik'");
            echo $menuid;
            
        }
    }
?>