<?php
    if (preg_match("/libdhtmlx.php/i", $_SERVER['PHP_SELF'])){header("location: index.php");die;}
    class MY_DHTMLX extends MY_HTML
    {
        var $my_form;
        public function FN_DHTMLXNEWCOMBO($myForm,$comboname,$url)
        {
            if(!$url){$url="''";}
            echo "var $comboname=$myForm.getCombo(\"$comboname\");
                      url=$url;
                      //alert(url);
                      $comboname.enableFilteringMode(true);
                      if(url)
                      {
                          $comboname.load(url);
                      }\n";    
        }
        
        public function FN_DHTMLXNEWCOMBOIMAGE($myForm,$comboname,$url,$setdefaultImagePath)
        {
            if(!$url){$url="''";}
            echo "var $comboname=$myForm.getCombo(\"$comboname\");
                      $comboname.setImagePath(\"".$setdefaultImagePath."\");
                      url=$url;
                      //alert(url);
                      $comboname.enableFilteringMode(true);
                      if(url)
                      {
                          $comboname.load(url);
                      }\n";    
        }        
        
        public function FN_DHTMLXNEWCOMBOWITHARRAY($myForm,$comboname,$arr)
        {
            $valarr="''";
            if(is_array($arr)){$valarr="'".json_encode($arr)."'";}
            echo "var $comboname=$myForm.getCombo(\"$comboname\");
                      url=$valarr;
                      //alert(url);
                      $comboname.enableFilteringMode(true);
                      if(url)
                      {
                          $comboname.load(url);
                      }\n";    
        }
        
        public function FN_DHTMLXNEWCOMBOGRID($gridname,$getColumnCombo,$comboname,$url)
        {
            echo "var $comboname=$gridname.getColumnCombo($getColumnCombo);
                      $comboname.enableFilteringMode(false);
                      $comboname.readonly(true);
                      url=$url;
                      //if($getColumnCombo==14){alert(url);}
                      $comboname.load(url);";
//            var cbousergroup2=dguser.getColumnCombo(7);
//              cbousergroup2.enableFilteringMode(false);
//              cbousergroup2.readonly(true);
//              url=fn_dhtmlxloadobject('".$this->enc("obj_user")."','obj=".$this->enc("-")."&task=".$this->enc("addcombo")."&tableobj=tbl_usergroup|groupuser,groupuser');
//              cbousergroup2.load(url);
        }
        
        public function FN_COMBOVALIDATIONVALUE($comboname,$tablename,$otherevent=null)
        {
            echo "$comboname.attachEvent(\"onChange\",function(val){
                        if(val!=='')
                        {
                            var result=ajaxuridhtmlx('".$this->enc("obj_controller")."','&task=".$this->enc("getvalidcombo")."&tablename=$tablename&id='+val+'&validationvalue='+$comboname.getComboText());
                            var spresult=result.split('|');
                            if(trim(spresult[0])!='ok'){fn_dhtmlxmessage('error','Error Found : '+spresult[1]);$comboname.setComboText('');$comboname.setComboValue('');return false;}
                            $otherevent
                        }
                   });";
        }
        
        public function FN_COMBODHMTLXFORM_GETJSON($myquery,$withoutindex0=null,$withimg=null)
        {
            $img="";
//            if($withimg){$img="img:\"\"";}
            $rsqry=$this->selectquery($myquery);
            if($rsqry)
            {    
                $rtn="{options:[";
                if(!$withoutindex0)
                {
                    //$rtn.="options:[{value:\"\",text:\"\"}";    
                    $rtn.="{value:\"\",text:\"\"},";    
                }
                $rtnval="";
                if($this->REC_ROWS_COUNT($rsqry)>0)
                {
                    while($rw=$this->data_row_array($rsqry))
                    {                                  
                        if($withimg){$img=",img:\"".$rw[2]."\"";}
                        $rtnval.="{value:\"".$rw[0]."\",text:\"".$rw[1]."\"$img},";
                    }
                    //$rtn.=substr($rtnval,0,strlen($rtnval)-1);                    
                    $rtnval=substr($rtnval,0,strlen($rtnval)-1);                    
                    $rtn.=$rtnval;
                }
                $rtn.="]}";
            }
            $this->clearrecordset($rsqry);
            return $rtn;
        }
        
        public function FN_COMBOVALIDATIONVALUE2($myForm,$comboname,$tablename,$url,$otherevent=null,$resulttovariable=null)
        {
            $rtn="var $comboname=$myForm.getCombo(\"".$comboname."\");
                      $comboname.enableFilteringMode(true);";
                      //if($url){$rtn.="alert($url);";}
                      if($url){$rtn.="$comboname.load($url);";}
            $rtn.="    $comboname.attachEvent(\"onChange\",function(val){
                            if($comboname.getComboText())
                            {
                                if(val!=='')
                                {";
                                    if($tablename)
                                    {
                                        $rtn.="var result=ajaxuridhtmlx('".$this->enc("obj_controller")."','&task=".$this->enc("getvalidcombo")."&tablename=$tablename&id='+val+'&validationvalue='+$comboname.getComboText());
                                               var spresult=result.split('|');
                                               if(trim(spresult[0])!='ok'){fn_dhtmlxmessage('error','Error Found : '+spresult[1]);$comboname.setComboText('');$comboname.setComboValue('');return false;}";                                    
                                    }
            $rtn.="                 $otherevent
                                }
                                if(val==null){fn_dhtmlxmessage('error','Error Found : Mohon Maaf, Pilihan <b>'+$comboname.getComboText()+' tidak terdaftar</b>');$comboname.setComboText('');$comboname.setComboValue('');return false;}
                                else if(val==''){fn_dhtmlxmessage('error','Error Found : Silahkan Pilih pilihan anda!');$comboname.setComboText('');$comboname.setComboValue('');return false;}
                            }
                       });";
            if($resulttovariable){return $rtn;}else{echo $rtn;}
        }
        
        public function FN_COMBOVALIDATIONVALUEARRAY($myForm,$comboname,$arrvalue,$otherevent=null,$checkvalidation=true)
        {
            echo "var $comboname=$myForm.getCombo(\"".$comboname."\");
                      $comboname.enableFilteringMode(true);";
                      //if($url){echo "$comboname.load($url);";}
            echo "    $comboname.addOption(".json_encode($arrvalue).");";
            if($checkvalidation)
            {
                echo "    $comboname.attachEvent(\"onChange\",function(val){
                                if(val==null){fn_dhtmlxmessage('error','Error Found : Mohon Maaf Pilihan <b>'+$comboname.getComboText()+' tidak terdaftar</b>, Silahkan pilih sesuai yang ada pada Daftar Combo<br/>TERIMA KASIH.');$comboname.setComboText('');$comboname.setComboValue('');return false;}
                                if(val!=='')
                                {";
                echo "              $otherevent
                                }
                           });";
            }
        }
        
        public function FN_COMBOVALIDATIONVALUENEW($myForm,$comboname,$tablename,$url,$otherevent=null,$resulttovariable=null,$checkvalidation=true){
            $rtn="var $comboname=$myForm.getCombo(\"".$comboname."\");
                      $comboname.clearAll();
                      $comboname.setComboValue('');
                      $comboname.setComboText('');";
            
            //if($url){$rtn.="alert($url);";}
            if($url){$rtn.="$comboname.enableFilteringMode(true,".$url.",true);";}
            $rtn.="$comboname.attachEvent(\"onChange\",function(val,text){";
            $rtn.="   if(val==null&&text){";
            $rtn.="       fn_dhtmlxmessage('error','Error Found : Mohon Maaf, Pilihan <b>'+$comboname.getComboText()+' tidak terdaftar</b>');
                          $comboname.setComboText('');$comboname.setComboValue('');return false;
                      }
                      else if(val!==''){                        
                        $otherevent
                      };";
            $rtn.="});";
           // if($checkvalidation)
//            {
//                $rtn.="$comboname.enableFilteringMode(true,\"dummy\"); 
//                       $comboname.attachEvent(\"onDynXLS\", myComboFilter);
//                       
//                       function myComboFilter(text){
//                          $comboname.clearAll();
//                          dhtmlxAjax.get(\"data.php?mask=\"+text, function(xml){
//                              myCombo.load(xml.xmlDoc.responseText);
//                          })
//                       };";    

//            }          
            if($resulttovariable){return $rtn;}else{echo $rtn;}
        }
        
        public function FN_COMBOVALIDATIONVALUENEWOLD($myForm,$comboname,$tablename,$url,$otherevent=null,$resulttovariable=null,$checkvalidation=true)
        {
            //$rtn="try";
            //$rtn.="{";
            $rtn="var $comboname=$myForm.getCombo(\"".$comboname."\");
                      $comboname.clearAll();
                      $comboname.setComboValue('');
                      $comboname.setComboText('');";
                      ///if($comboname=='cbo_idjnsbiaya')
                      //{if($url){$rtn.="alert($url);";}}    
                      if($url){$rtn.="$comboname.enableFilteringMode(true,".$url.");";}    
            if($checkvalidation)
            {
                $rtn.="   $comboname.attachEvent(\"onChange\",function(val,text){
                                //fn_dhtmlxmessage('error',val);
                                //alert(value+' '+text);
                                if($comboname.getComboText())
                                {
                                    if(val!=='')
                                    {";
                                        if($tablename)
                                        {
                                            $sp=explode("|",$tablename);$fieldcriteria="id";
                                            if(count($sp)>1){$tablename=$sp[0];$fieldcriteria=$sp[1];}
                                            $rtn.="var result=ajaxuridhtmlx('".$this->enc("obj_controller")."','&task=".$this->enc("getvalidcombo")."&tablename=$tablename&id='+val+'&fieldcriteria=$fieldcriteria&validationvalue='+$comboname.getComboText().trim());
                                                   //alert('$fieldcriteria');
                                                   var spresult=result.split('|');
                                                   if(trim(spresult[0])!='ok'){fn_dhtmlxmessage('error','Error Found : '+spresult[1]);$comboname.setComboText('');$comboname.setComboValue('');return false;}";                                    
                                        }
                $rtn.="                 $otherevent
                                    }
                                    if(val==null){fn_dhtmlxmessage('error','Error Found : Mohon Maaf, Pilihan <b>'+$comboname.getComboText()+' tidak ddd terdaftar</b>');$comboname.setComboText('');$comboname.setComboValue('');return false;}
                                    else if(val==''){fn_dhtmlxmessage('error','Error Found : Silahkan Pilih pilihan anda / Record Not Found!');$comboname.setComboText('ff');$comboname.setComboValue('');return false;}
                                }
                           });";
                
            }
            //$rtn.="}";
            //$rtn.="catch(e)";
            //$rtn.="{fn_dhtmlxmessage('error',e.getMessage());}";
            if($resulttovariable){return $rtn;}else{echo $rtn;}
        }
        
        public function FN_DHTMLXGRIDVIEW($gridinit=array(),$gridcolumnproperties=array(),$gridtypes,$contexmenu=null,$functioninit=null,$resulttovariable=null)
        {
            $dgname=$gridinit['gridname'];
            $divtarget=$gridinit['divtarget'];
            $divpaging=$gridinit['divpaging'];
            $paginglimit=$gridinit['paginglimit'];
            $setcolumnhidden=$gridinit['setcolumnhidden'];
            $attachheader=$gridinit['attachheader'];
            $attachfooter=$gridinit['attachfooter'];
            $attachfooteralign=$gridinit['attachfooteralign'];
            $footer=$gridinit['footer'];
            $footerspan=$gridinit['footerspan'];
            $footeralign=$gridinit['footeralign'];
            $showloader=$gridinit['showloader'];
            $enableheadermenu=$gridinit['enableheadermenu'];
            $enablemultiline=$gridinit['enableMultiline'];
            $divloadername="loadergrid";
            if($gridinit['divloadername']){$divloadername=$gridinit['divloadername'];}
            $resulttovariable=$gridinit['resulttovariable'];
            $split=$gridinit['split'];
            $skin=$gridinit['skin'];if(!$skin){$skin="dhx_skyblue";}
            $columnformat=$gridinit['columnformat'];
            if(!$footeralign){$footeralign="left";}
            if(!$paginglimit){$paginglimit=PAGE_LIMIT;}
            if($contexmenu){$contexmenu="$dgname.enableContextMenu($contexmenu);";}
            $fieldname="";$headeralign="";$coltypes="";$widths="";$contentalign="";$colsort="";
            $enabletooltips="";$setcolhidden="";
            foreach($gridcolumnproperties as $arr=>$arrval)
            {
                $fieldname.=$arr.",";
                $spprop=explode(",",$arrval);
                $headeralign.="\"text-align:".$spprop[0]."\",";$coltypes.=$spprop[1].",";
                $widths.=$spprop[2].",";$contentalign.=$spprop[3].",";$colsort.=$spprop[4].",";
                $enabletooltips.=$spprop[5].",";
                if($spprop[6]){$setcolhidden.=$spprop[6].",";}
                else
                {$setcolhidden.="false,";}
                
            }
            $fieldname=substr($fieldname,0,strlen($fieldname)-1);
            $headeralign=substr($headeralign,0,strlen($headeralign)-1);
            $coltypes=substr($coltypes,0,strlen($coltypes)-1);
            $widths=substr($widths,0,strlen($widths)-1);
            $contentalign=substr($contentalign,0,strlen($contentalign)-1);
            $colsort=substr($colsort,0,strlen($colsort)-1);
            $enabletooltips=substr($enabletooltips,0,strlen($enabletooltips)-1);
            if($setcolhidden){$setcolhidden=substr($setcolhidden,0,strlen($setcolhidden)-1);$setcolumnhidden=$setcolhidden;}
            //echo $fieldname.' '.$headeralign.' '.$coltypes.' '.$contentalign.' '.$colsort;return false;
            $rtn="// === Data Grid Akun Header
                   $dgname=new dhtmlXGridObject(\"$divtarget\");
                   //$dgname.setSkin(\"web\");
                   //$dgname.setImagePath(\"".PATH_THEME."/codebase/imgs/\");
                   $dgname.setImagePath(\"".PATH_THEME."/skins/web/imgs/dhxgrid_web/\");
                   $dgname.setHeader(\"".$fieldname."\",null,[".$headeralign."]);
                   $dgname.setColTypes(\"".$coltypes."\"); // ro => Read Only, ed => Edit
                   $dgname.setInitWidths(\"".$widths."\");
                   $dgname.setColAlign(\"".$contentalign."\");
                   $dgname.setColSorting(\"".$colsort."\");
                   //$dgname.enablePaging(true,".$paginglimit.",5,\"$divpaging\",true,\"recInfoArea\");
                   $dgname.enablePaging(true,".$paginglimit.",5,\"$divpaging\",true,\"pagingArea\");
                   $dgname.setPagingSkin(\"".$gridtypes."\");".$contexmenu."                   
                   $dgname.enableTooltips(\"".$enabletooltips."\");";
                   if($setcolumnhidden){$rtn.="$dgname.setColumnsVisibility('".$setcolumnhidden."');";}
                   if($enablemultiline){$rtn.="$dgname.enableMultiline(true);";}
                   
                   if($attachheader){$rtn.="$dgname.attachHeader(\"$attachheader\");";}
                   if($columnformat)
                   {
                       foreach($columnformat as $arrf1=>$arrvalf1)
                       {
                           foreach($arrvalf1 as $arrf=>$arrfvalue)
                           {
                               //$rtn.="//".$arrf."<";
                               if($arrfvalue=='numberformat')
                               {
                                   $columnnumber=explode(",",$arrvalf1["columnnumber"]);
                                   for($i=0;$i<count($columnnumber);$i++)
                                   {
                                      $rtn.="$dgname.setNumberFormat(\"".$arrvalf1["format"]."\",".$columnnumber[$i].",\".\",\",\");";      
                                   }
                                   
                               }     
                           }
                       }
                   }
                    //<div id='div$dgnamegrandtotal' style='color:blue'>Total</div>,#cspan,#cspan,#cspan,<div id='divdgtranominal' style='text-align:right;'>{#stat_total}</div>,<div id='divdgtrapotongan' style='text-align:right;'>{#stat_total}</div>,<div id='divdgtratotalnominal' style='text-align:right;'>{#stat_total}</div>
                    if($footer)
                    {
                        if($footerspan)
                        {
                            $footerspan=str_repeat("#cspan,", $footerspan);$footerspan=substr($footerspan, 0, strlen($footerspan)-1);
                        } 
                        $rtn.="$dgname.attachFooter(\"".$footer.",".$footerspan."\",[\"text-align:".$footeralign.";\"]);";
                    }
                    if($attachfooter)
                    {
                        $rtn.="$dgname.attachFooter(\"".$attachfooter."\",[\"text-align:".$attachfooteralign.";\"]);";
                    }
            $rtn.=" $dgname.init();";
            //$rtn.=" $dgname.enableLightMouseNavigation(true);";
            if($enableheadermenu){$rtn.=" $dgname.enableHeaderMenu();";}
            if($functioninit){$rtn.="$functioninit;";}
            if($split){$rtn.="$dgname.splitAt($split);";}
            if($showloader)
            {
                $rtn.="$dgname.attachEvent(\"onXLS\",function(){document.getElementById('$divloadername').style.display='block';});";
                $rtn.="$dgname.attachEvent(\"onXLE\",function(){document.getElementById('$divloadername').style.display='none';});";
            }
            if($resulttovariable){return $rtn;}else{echo $rtn;}
        }
        
        public function FN_DHTMLXGRIDVIEWEVENT($gridname,$arrevent,$resulttovariable=null)
        {
            $rtn="";
            foreach($arrevent as $arr=>$arrval1)
            {
                $eventname="";$eventparam="";$withcase="";$arrsyntax=array();$statement="";
                foreach($arrval1 as $arrt1=>$arrvalt1)
                {
                    if($arrt1=='eventname'){$eventname=$arrvalt1;}
                    if($arrt1=='eventparam'){$eventparam=$arrvalt1;}
                    if($arrt1=='switch'){$withcase=$arrvalt1;$arrsyntax=$arrvalt1;}
                    if($arrt1=='statement'){$statement=$arrvalt1;}
                }
                $rtn.="$gridname.attachEvent('$eventname',function($eventparam){";
                          if($withcase)
                          {
                              $rtn.="switch(id)
                                    {";
                                        foreach($arrsyntax as $arrcase=>$arrstatement)
                                        {
                                            $rtn.="case '$arrcase':$arrstatement;break;";
                                        }
                              $rtn.="}";
                          }
                          else{$rtn.=$statement;}    
                $rtn.="});";
            }
            if($resulttovariable){return $rtn;}else{echo $rtn;}

        }
        
        public function FN_DHTMLXGRIDVIEWTOFORMNEW($gridname,$formname,$tablename,$idparameterindex,$fieldsarray,$fielddatetime=null,$otherevent=null,$otherbuttonevent=null,$resulttovariable=null,$expcolumnindexclick=null)
        {
            $rtn="$gridname.attachEvent(\"onRowSelect\",function(rowid,ind){";
            $rtn.="try{";

            if($expcolumnindexclick)
            {
                $sp=explode("|",$expcolumnindexclick);
                if(count($sp)>0)
                {
                    for($i=0;$i<count($sp);$i++)
                    {
                        $rtn.="if(ind==".$sp[$i]."){return false;}";
                    }
                }
                else{$rtn.="if(ind==$expcolumnindexclick){return false;}";}
                //$rtn.="if(ind==$expcolumnindexclick){return false;}";
            }
            $rtn.="id=$gridname.cells(rowid,$idparameterindex).getValue();";
            $i=0;$fieldsid="";$getresult="";$fieldfocus="";
            foreach($fieldsarray as $arr=>$arrvalue)
            {   
                if($i==1){$fieldfocus=$arr;}
                if($i>0)
                {
                    $tfield=$arrvalue;$prefix="";
                    $sparr=explode("_",$arr);
                    $prefix=$sparr[0];
                    if(!$arrvalue)
                    {
                        $tfield=$arr;
                        $spf=explode("_",$tfield);
                        $tfield=$spf[1];
                        if($prefix=='cbo')
                        {
                            $t2field=substr($tfield,2,strlen($tfield)-2);
                            $tfield=$tfield."|".$t2field;
                        }
                    }                          
                    $fieldname.=$tfield.",";
                    //$getresult.="$formname.setItemValue('".$arr."',trim(spres[".$i."]));";
                    //$getresult.="alert('$arr $tfield');";
                    if($prefix=='cbo')
                    {
                        $getresult.="var spcombo=spres[".$i."].trim().split(',');";
                        $getresult.="$formname.getCombo('".$arr."').clearAll();";
                        $getresult.="$formname.getCombo('".$arr."').setComboText('');";
                        $getresult.="$formname.getCombo('".$arr."').setComboValue('');";
                        $getresult.="if(spcombo[0])";
                        $getresult.="{";
                        //$getresult.="$formname.getCombo('".$arr."').addOption([[spcombo[0],spcombo[1]]]);";
                        $getresult.="$formname.getCombo('".$arr."').addOption(spcombo[0],spcombo[1], null, null, true);";
                        //$getresult.="$formname.getCombo('".$arr."').setComboValue(spcombo[0].trim());";
                        //$getresult.="$formname.getCombo('".$arr."').setComboText(spcombo[1].trim());";
                        
                        $getresult.="}";
                    }
                    else
                    {
                        $getresult.="$formname.setItemValue('".$arr."',trim(spres[".$i."]));";    
                    }
                    //$getresult.=";alert('$arr $i');";
                    
                }
                else
                {$getresult.="$formname.setItemValue('".$arr."',id);";}
                $i+=1;
            }
            $fieldname=substr($fieldname,0,strlen($fieldname)-1);
            //if($otherevent){$getresult.=$otherevent;}
            if($otherevent){$getresult=$otherevent.$getresult;}
            $rtn.="   var result=ajaxuridhtmlx('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("getinfotable2")."&tablename=$tablename&fields=$fieldname&fielddatetime=$fielddatetime&id='+id);";
            //$rtn.="   alert(result);";
            $rtn.="   var spres=result.split('|');";
            // === Change 2016-04-03 5:23 Am ==> check validation user edit
            //$rtn.="alert(spres[0]);";
            $rtn.="   if(trim(spres[0])=='failed'){fn_dhtmlxmessage('error',spres[1]);return false;}";
            // ============================================================
            $rtn.=$getresult;
            //$rtn.="";
            //if($otherevent){$rtn.=$otherevent;}
            if($otherbuttonevent)
            {
                $rtn.=$otherbuttonevent;
            }
            else
            {
                $rtn.="   $formname.disableItem(\"btnsave\");";
                $rtn.="   $formname.enableItem(\"btnupdate\");";
                $rtn.="   $formname.enableItem(\"btndelete\");";
                $rtn.="   $formname.setItemFocus(\"$fieldfocus\");";
            }
            $rtn.="}";
            $rtn.="catch(e)";
            $rtn.="{alert(e.getMessage());}";
            $rtn.="});";
            
            if($resulttovariable){return $rtn;}else{echo $rtn;}
        }
        
        public function FN_DHTMLXGRIDVIEWTOFORM($gridname,$formname,$tablename,$idparameterindex,$fieldsarray,$fielddatetime=null,$otherevent=null,$otherbuttonevent=null,$resulttovariable=null,$expcolumnindexclick=null)
        {
            $rtn="$gridname.attachEvent(\"onRowSelect\",function(rowid,ind){";
            if($expcolumnindexclick)
            {
                $sp=explode("|",$expcolumnindexclick);
                if(count($sp)>0)
                {
                    for($i=0;$i<count($sp);$i++)
                    {
                        $rtn.="if(ind==".$sp[$i]."){return false;}";
                    }
                }
                else{$rtn.="if(ind==$expcolumnindexclick){return false;}";}
                //$rtn.="if(ind==$expcolumnindexclick){return false;}";
            }
            $rtn.="id=$gridname.cells(rowid,$idparameterindex).getValue();";
            $i=0;$fieldsid="";$getresult="";$fieldfocus="";
            foreach($fieldsarray as $arr=>$arrvalue)
            {   
                if($i==1){$fieldfocus=$arr;}
                if($i>0)
                {
                    $tfield=$arrvalue;
                    if(!$arrvalue)
                    {
                        $tfield=$arr;
                        $spf=explode("_",$tfield);
                        $tfield=$spf[1];
                    }
                
                    $fieldname.=$tfield.",";
                    //$rtn.="   var ".$fieldname."=spres[".$i."];";
                    $getresult.="$formname.setItemValue('".$arr."',trim(spres[".$i."]));";
                }
                else
                {$getresult.="$formname.setItemValue('".$arr."',id);";}
                $i+=1;
            }
            $fieldname=substr($fieldname,0,strlen($fieldname)-1);
            if($otherevent){$getresult.=$otherevent;}
            $rtn.="   var result=ajaxuridhtmlx('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("getinfotable")."&tablename=$tablename&fields=$fieldname&fielddatetime=$fielddatetime&id='+id);";
            //$rtn.="   alert(result);";
            $rtn.="   var spres=result.split('|');";
            // === Change 2016-04-03 5:23 Am ==> check validation user edit
            $rtn.="   if(trim(spres[0])=='failed'){fn_dhtmlxmessage('error',spres[1]);return false;}";
            // ============================================================
            $rtn.=$getresult;
            if($otherbuttonevent)
            {
                $rtn.=$otherbuttonevent;
            }
            else
            {
                $rtn.="   $formname.disableItem(\"btnsave\");";
                $rtn.="   $formname.enableItem(\"btnupdate\");";
                $rtn.="   $formname.enableItem(\"btndelete\");";
                $rtn.="   $formname.setItemFocus(\"$fieldfocus\");";
            }
            $rtn.="});";
            if($resulttovariable){return $rtn;}else{echo $rtn;}
        }
        
        
        
        public function FN_DHTMLXGRIDVIEWINCONTENT($gridinit=array(),$gridcolumnproperties=array(),$gridtypes,$contexmenu=null,$functioninit=null)
        {
            $rtn="";
            $dgname=$gridinit['gridname'];
            $contenttarget=$gridinit['contenttarget'];
            $divpaging=$gridinit['divpaging'];
            $paginglimit=$gridinit['paginglimit'];
            $setcolumnhidden=$gridinit['setcolumnhidden'];
            $footer=$gridinit['footer'];
            if(!$paginglimit){$paginglimit=PAGE_LIMIT;}
            if($contexmenu){$contexmenu="$dgname.enableContextMenu($contexmenu)";}
            $fieldname="";$headeralign="";$coltypes="";$widths="";$contentalign="";$colsort="";
            $enabletooltips="";
            foreach($gridcolumnproperties as $arr=>$arrval)
            {
                $fieldname.=$arr.",";
                $spprop=explode(",",$arrval);
                $headeralign.="\"text-align:".$spprop[0]."\",";$coltypes.=$spprop[1].",";
                $widths.=$spprop[2].",";$contentalign.=$spprop[3].",";$colsort.=$spprop[4].",";
                $enabletooltips.=$spprop[5].",";
                
            }
            $fieldname=substr($fieldname,0,strlen($fieldname)-1);
            $headeralign=substr($headeralign,0,strlen($headeralign)-1);
            $coltypes=substr($coltypes,0,strlen($coltypes)-1);
            $widths=substr($widths,0,strlen($widths)-1);
            $contentalign=substr($contentalign,0,strlen($contentalign)-1);
            $colsort=substr($colsort,0,strlen($colsort)-1);
            $enabletooltips=substr($enabletooltips,0,strlen($enabletooltips)-1);
            //echo $fieldname.' '.$headeralign.' '.$coltypes.' '.$contentalign.' '.$colsort;return false;
            $rtn="// === Data Grid 
                   $dgname=new dhtmlXGridObject($contenttarget);
                   $dgname.setSkin(\"dhx_skyblue\");
                   $dgname.setImagePath(\"".PATH_THEME."/codebase/imgs/\");
                   $dgname.setHeader(\"".$fieldname."\",null,[".$headeralign."]);
                   $dgname.setColTypes(\"".$coltypes."\"); // ro => Read Only, ed => Edit
                   $dgname.setInitWidths(\"".$widths."\");
                   $dgname.setColAlign(\"".$contentalign."\");
                   $dgname.setColSorting(\"".$colsort."\");
                   $dgname.enablePaging(true,".$paginglimit.",5,\"$divpaging\",true,\"recInfoArea\");
                   $dgname.setPagingSkin(\"".$gridtypes."\");".$contexmenu."                   
                   $dgname.enableTooltips(\"".$enabletooltips."\");";
                   if($setcolumnhidden){$rtn.="$dgname.setColumnsVisibility('".$setcolumnhidden."');";}
                   
                   //<div id='div$dgnamegrandtotal' style='color:blue'>Total</div>,#cspan,#cspan,#cspan,<div id='divdgtranominal' style='text-align:right;'>{#stat_total}</div>,<div id='divdgtrapotongan' style='text-align:right;'>{#stat_total}</div>,<div id='divdgtratotalnominal' style='text-align:right;'>{#stat_total}</div>
                   if($footer){$rtn.="$dgname.attachFooter(\"".$footer."\",[\"text-align:right;\"]);";}
            $rtn.=" $dgname.init();";
            if($functioninit){$rtn.="$functioninit;";}
            return $rtn;
        }
        
        public function FN_DHTMLXWINDOWSURL($dhxwin,$windowsname,$windowstitle,$x,$y,$w,$h,$url,$maximize=false,$modal=false)
        {
            $rtn="$dhxwin.createWindow(\"$windowsname\",$x,$y,$w,$h);";
            $rtn.="$dhxwin.window('$windowsname').denyResize();";
            $rtn.="$dhxwin.window('$windowsname').progressOn();";
            $rtn.="$dhxwin.window(\"$windowsname\").setText(\"$windowstitle\");";
            //$rtn.="var url=fn_dhtmlxloadobject('".$this->enc("obj_nits")."','obj=".$this->enc("nits_sitedown")."&task=".$this->enc("viewmaps")."');";
            $rtn.="$dhxwin.window(\"$windowsname\").attachURL('$url');";
            if($maximize)
            {
                $rtn.="$dhxwin.window(\"$windowsname\").maximize();";    
            }                                                    
            if($modal){$rtn.="$dhxwin.window('$windowsname').setModal($modal);";}
            $rtn.="$dhxwin.window('$windowsname').progressOff();";
            echo $rtn;
        }
        public function FN_DHTMLXWINDOWSURL1($windowsname,$windowproperties=array(),$w,$h,$x,$y,$divport,$url,$arrjson="",$resulttovariable=false)
        {
            $windowtitle="";$skin="dhx_web";$denyresize="";$modalwin="";$closedby="";$eventwhenclosed="";
            $position="";$skinform="dhx_skyblue";
            foreach($windowproperties as $arr=>$arrval)
            {
                if($arr=='title'){$windowtitle=$arrval;}
                if($arr=='skin'){$skin=$arrval;}
                if($arr=='skinform'){$skinform=$arrval;}
                if($arr=='denyresize'){$denyresize=$arrval;}
                if($arr=='modalwin'){$modalwin=$arrval;}
                if($arr=='closedby'){$closedby=$arrval;}
                if($arr=='eventwhenclosed'){$eventwhenclosed=$arrval;}
                if($arr=='position'){$position=trim($arrval);}
            }
            
            $rtn="dhxwin=new dhtmlXWindows();";
            $rtn.="dhxwin.setSkin('$skin');";
            $rtn.="dhxwin.window('$windowsname').progressOn();";
            $rtn.="dhxwin.window('$windowsname').setText('$windowtitle');";
            $rtn.="dhxwin.attachViewportTo('$divport');";
            $rtn.="dhxwin.window('$windowsname').attachURL(\"$url\", true);";
            
            if($denyresize){$rtn.="dhxwin.window('$windowsname').denyResize();";}
            if($modalwin){$rtn.="dhxwin.window('$windowsname').setModal($modalwin);";}
            if(!$closedby){$rtn.="dhxwin.window('$windowsname').button(\"close\").disable();";}
            $rtn.="dhxwin.window('$windowsname').bringToTop();";
            if($position){$rtn.="dhxwin.window('$windowsname').".$position."();";}
            $rtn.="dhxwin.window('$windowsname').progressOff();";
            if($eventwhenclosed){$rtn.="dhxwin.attachEvent('onClose',function(win){".$eventwhenclosed.";return true;})";}
            if($resulttovariable){return $rtn;}
            else{echo $rtn;}
    
        }
        public function FN_DHTMLXWINDOWS($windowsname,$windowproperties=array(),$w,$h,$x,$y,$attachtodiv=null,$myform=null,$formdata=null,$myformjquery=null,$resulttovariable=null)
        {
            //echo json_encode($formdata);return false;
            $windowtitle="";$skin="dhx_web";$denyresize="";$modalwin="";$closedby="";$eventwhenclosed="";
            $position="";$skinform="dhx_skyblue";
            foreach($windowproperties as $arr=>$arrval)
            {
                if($arr=='title'){$windowtitle=$arrval;}
                if($arr=='skin'){$skin=$arrval;}
                if($arr=='skinform'){$skinform=$arrval;}
                if($arr=='denyresize'){$denyresize=$arrval;}
                if($arr=='modalwin'){$modalwin=$arrval;}
                if($arr=='closedby'){$closedby=$arrval;}
                if($arr=='eventwhenclosed'){$eventwhenclosed=$arrval;}
                if($arr=='position'){$position=trim($arrval);}
            }
            //echo "if(typeof dhxwin==='undefined'||dhxwin===null){alert('f');var dhxwin=new dhtmlXWindows();}else{dhxwin=new dhtmlXWindows();}";
            $rtn="dhxwin=new dhtmlXWindows();";
//            $rtn.="dhxwin.setSkin('$skin');";
            
            if($attachtodiv){$rtn.="dhxwin.attachViewportTo('$attachtodiv');";}
            $rtn.="$windowsname=dhxwin.createWindow(\"$windowsname\",$x,$y,$w,$h);";            
            //echo "$windowsname.getView().dhxwin.firstChild.style.backgroundColor ='blue';";
            //echo "$windowsname.firstChild.style.background = \"#c2d5dc\";";
            $rtn.="dhxwin.window('$windowsname').progressOn();";
            $rtn.="$windowsname.setText('$windowtitle');";
            if($denyresize){$rtn.="dhxwin.window('$windowsname').denyResize();";}
            if($modalwin){$rtn.="dhxwin.window('$windowsname').setModal($modalwin);";}
            if(!$closedby){$rtn.="dhxwin.window('$windowsname').button(\"close\").disable();";}
            $rtn.="dhxwin.window('$windowsname').bringToTop();";
            if($position){$rtn.="dhxwin.window('$windowsname').".$position."();";}
            if($myform)
            {
                $formdata=json_encode($formdata);
                $rtn.="$myform=$windowsname.attachForm($formdata, true);";
                $rtn.="$myform.setFocusOnFirstActive();";
                //$rtn.="$myform.setSkin('$skinform');";
                $rtn.="$myform.attachEvent(\"onKeyDown\",function(inp,ev,id,value){";
                          if($closedby)
                          {
                              $rtn.="if(ev.keyCode==27){dhxwin.unload();}"; 
                          }
                $rtn.="});";                
                if($myformjquery){$rtn.=$myformjquery;}
            }
            $rtn.="dhxwin.window('$windowsname').progressOff();";
            if($eventwhenclosed){$rtn.="dhxwin.attachEvent('onClose',function(win){".$eventwhenclosed.";return true;})";}
            if($resulttovariable){return $rtn;}
            else{echo $rtn;}
            
        }
        
        public function FN_DHTMLXWINDOWSHOWPROGESS($event,$dhxwinname="dhxwin")
        {
            $rtn.="$dhxwinname=new dhtmlXWindows();";
            if($dhxwinname!='dhxwin'){$rtn="var $dhxwinname=new dhtmlXWindows();";}
            $rtn.="$dhxwinname.setSkin('material');";            
            
            $rtn.="var winprogress=$dhxwinname.createWindow(\"winprogress\",0,0,190,40);";            
            $rtn.="winprogress.setText('Progress');";
            
            $rtn.="$dhxwinname.window('winprogress').hideHeader();";
            $rtn.="$dhxwinname.window('winprogress').denyResize();";
            $rtn.="$dhxwinname.window('winprogress').setModal(true);";
            $rtn.="$dhxwinname.window('winprogress').button(\"close\").disable();";
            $rtn.="$dhxwinname.window('winprogress').bringToTop();";
            $rtn.="$dhxwinname.window('winprogress').center();";
            $winprogressvalue="<table border=\"0\" style=\"font-family:tahoma;font-size:9pt;margin-top:0px;color:blue\" width=\"100%\">";
            $winprogressvalue.="    <tr>";
            $winprogressvalue.="         <td align=\"center\">Please Wait..<td>";
            $winprogressvalue.="    </tr>";
            $winprogressvalue.="    <tr>";
            $winprogressvalue.="         <td align=\"center\">".$this->CREATE_IMAGE("loaderring.gif","32","32")."<td>";
            $winprogressvalue.="    </tr>";
            $winprogressvalue.="</table>";
            $rtn.="winprogress.attachHTMLString('$winprogressvalue');";
            $rtn.=$event;
            //$rtn.="$dhxwinname.unload();";
            //$rtn.="alert('test');return false;";
            return $rtn;
        }
                
        public function FN_DHTMLXWINDOWSHIDEPROGRESS($dhxwinname="dhxwin")
        {
            return "$dhxwinname.unload();";    
        }
        
        public function FN_DHTMLXFORMCLEAR($myformname,$ArrayControls=array(),$setFocusControl=null)
        {
            $statement="";
            foreach($ArrayControls as $arr=>$arrval)
            {
                $statement="$myformname.setItemValue('$arr','$arrval');";
                //if(substr($arr,0,3)!='cbo'){$statement="$myformname.setItemValue('$arr','$arrval');";}
                if(substr($arr,0,3)=='chk')
                {
                    $statement="$myformname.checkItem('$arr');";
                    if($arrval==false){$statement="$myformname.uncheckItem('$arr');";}
                }
                if(substr($arr,0,3)=='cbo'){$statement.="$myformname.getCombo('$arr').setComboValue('');$myformname.getCombo('$arr').setComboText('$arrval');";}
                $dhtmlxformclear.=$statement;
            }
            $rtn="$dhtmlxformclear";
            if($setFocusControl){$rtn.="$myformname.setItemFocus('$setFocusControl');";}            
            return $rtn;
        }
        
        public function FN_DHTMLXFORMCLEAR2($myformname,$ArrayControls=array(),$setFocusControl=null)
        {
            $statement="";
            foreach($ArrayControls as $arr=>$arrval)
            {
                $statement="$myformname.setItemValue('$arr','$arrval');";
                //if(substr($arr,0,3)!='cbo'){$statement="$myformname.setItemValue('$arr','$arrval');";}
                if(substr($arr,0,3)=='chk')
                {
                    $statement="$myformname.checkItem('$arr');";
                    if($arrval=='false'){$statement="$myformname.uncheckItem('$arr');";}
                }
                if(substr($arr,0,3)=='cbo'){$statement.="$myformname.getCombo('$arr').setComboValue('');$myformname.getCombo('$arr').setComboText('');$myformname.getCombo('$arr').clearAll();";}
                $dhtmlxformclear.=$statement;
            }
            $rtn="$dhtmlxformclear";
            if($setFocusControl){$rtn.="$myformname.setItemFocus('$setFocusControl');";}            
            return $rtn;
        }
        
        public function FN_DHTMLXFORMDISABLEDOBJ($myformname,$ArrayControls=array(),$setFocusControl=null)
        {
            $statement="";
            foreach($ArrayControls as $arr=>$arrval)
            {
                $statement.="$myformname.disableItem('$arr');";
            }
            $rtn=$statement;
            if($setFocusControl){$rtn.="$myformname.setItemFocus('$setFocusControl');";}            
            return $rtn;
        }        
        
        public function FN_DHTMLXFORMENABLEDOBJ($myformname,$ArrayControls=array(),$setFocusControl=null)
        {
            $statement="";
            foreach($ArrayControls as $arr=>$arrval)
            {
                $statement.="$myformname.enableItem('$arr');";
            }
            $rtn=$statement;
            if($setFocusControl){$rtn.="$myformname.setItemFocus('$setFocusControl');";}            
            return $rtn;
        }
         
        public function FN_DHTMLXGETFIELDVALUE($tablename,$getfieldname,$swhere=Array(),$resulttovariable=null)
        {
            $swherecondition="$swhere";
            if(is_array($swhere))
            {
                $swherecondition="";
                foreach($swhere as $a=>$a1)
                {
                    $swherecondition.=$a."|'+".$a1.",";
                }
                $swherecondition=substr($swherecondition,0,strlen($swherecondition)-1);
            }
            $rtn="ajaxuridhtmlx('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("getfieldvalue")."&tableobj=".$tablename."&getfield=".$getfieldname."&swhere=".$swherecondition.");";//sinumber|'+sinumber
            if($resulttovariable){return $rtn;}
            echo $rtn;
            
        }
        
        public function FN_DHTMLXREMARKFORDELETED2($ObjectRoot,$ObjectName,$idrecord,$objtextdeleted,$eventafterdeleted,$deletefunction="delrecord",$titleremove="'Confirmation Delete Record'")
        {
            $rtn="var dhxwindelete=new dhtmlXWindows();";
            //$rtn.="dhxwindelete.setSkin('dhx_terrace');";
            //$rtn.="dhxwindelete.attachViewportTo(\"winVP\");";
            //if($attachtodiv){$rtn.="dhxwindelete.attachViewportTo('$attachtodiv');";}
            $rtn.="var windeleted=dhxwindelete.createWindow(\"windeleted\",0,0,410,190);";            
            //echo "windeleted.getView().dhxwindelete.firstChild.style.backgroundColor ='blue';";
            //echo "windeleted.firstChild.style.background = \"#c2d5dc\";";
            $rtn.="dhxwindelete.window('windeleted').progressOn();";
            $rtn.="windeleted.setText(".$titleremove.");";
            $rtn.="dhxwindelete.window('windeleted').denyResize();";
            $rtn.="dhxwindelete.window('windeleted').setModal(true);";
            //if(!$closedby){$rtn.="dhxwindelete.window('windeleted').button(\"close\").disable();";}
            $rtn.="dhxwindelete.window('windeleted').bringToTop();";
            $rtn.="dhxwindelete.window('windeleted').center();";

            // === FOrm Deleted
            $formdata=array(
                              array("type"=>"settings","position"=>"label-left","labelWidth"=>"160","inputWidth"=>"120"),
                              array("type"=>"fieldset","label"=>"<font color='red'>Insert Remark</font> First","width"=>"255","offsetLeft"=>"5",
                                    "list"=>array(
                                                    array("type"=>"hidden","name"=>"txt_id"),
                                                    array("type"=>"input","name"=>"txtremark","inputWidth"=>"320","className"=>"txtleft","maxLength"=>"90",
                                                                          "note"=>array("text"=>"<span id='spjlhchar' style='color:blue;'>0/90</span> characters.")),
                                                    array("type"=>"button","name"=>"btndeleted","value"=>"Delete","offsetLeft"=>"0","offsetTop"=>"0",
                                                                           "className"=>"button_delete")
                                            )
                              )
                      );
            $formdata=json_encode($formdata);
            $rtn.="var myformdel=windeleted.attachForm($formdata, true);";
            $rtn.="myformdel.setFocusOnFirstActive();";
            //$rtn.="myformdel.setSkin('dhx_skyblue');";
            
            // === FOrm Event
            $ontxtremarkonkeydown="if(ev.keyCode==13){ev.stopPropagation();ev.preventDefault();myformdel.setItemFocus('btndeleted');}";
            $ontxtremarkonkeydown.="if(ev.keyCode==27){dhxwindelete.unload();}";
            $ontxtremarkonkeyup="var remarklength=myformdel.getItemValue('txtremark');";
            $ontxtremarkonkeyup.="document.getElementById('spjlhchar').innerHTML=remarklength.toString().length+'/90';";
            
            
            $onbuttonclickbtndeleted="var lengthremark=myformdel.getItemValue('txtremark').trim().length;";
            $onbuttonclickbtndeleted.="if(lengthremark<=15){fn_dhtmlxmessage('error','Minimal 15 Character for the reason. Thank You!');myformdel.setItemFocus('txtremark');return false;}";
            $onbuttonclickbtndeleted.="if(myformdel.validate())
                                       {
                                           dhtmlx.confirm({
                                                 title:'Confirmation',text:'Are you will be deleted data?',type:'confirm',
                                                 callback:function(result){
                                                      if(result)
                                                      {";
                                                         $params="'obj=".$this->enc($ObjectName)."&task=".$this->enc($deletefunction)."'";
                                                         $onformsenddata="url=fn_dhtmlxsenddata('".$this->enc($ObjectRoot)."',$params);
                                                         myformdel.send(url,\"get\",function(loader, response){";
                                                           $onformsenddata.=$this->FN_DHTMLXWINDOWSHIDEPROGRESS();
                                                           $onformsenddata.="var sp=trim(response).split('|');
                                                           //alert(response);
                                                           if(sp[0]=='ok')
                                                           {
                                                               fn_dhtmlxmessage('','Data <b>'+$objtextdeleted+'</b> has been deleted');";
                                                               $onformsenddata.=$eventafterdeleted;   
                                                               $onformsenddata.="dhxwindelete.unload();
                                                           }
                                                           else if(sp[0]=='failed')
                                                           {fn_dhtmlxmessage('error','Error Found : '+sp[1]);}
                                                           else
                                                           {fn_dhtmlxmessage('error','Error Found : '+response);}
                                                         });";
                                                         $onbuttonclickbtndeleted.=$this->FN_DHTMLXWINDOWSHOWPROGESS($onformsenddata);
            $onbuttonclickbtndeleted.="               }
                                                 }
                                           });
                                       }";
            $arrevent=array(
                                array("eventname"=>"onButtonClick","eventparam"=>"id,val",
                                                                   "switch"=>array("btndeleted"=>"$onbuttonclickbtndeleted")
                                ),
                                array("eventname"=>"onkeyup","eventparam"=>"inp,ev,id,val",
                                                    "switch"=>array("txtremark"=>"$ontxtremarkonkeyup")
                                ),
                                array("eventname"=>"onkeydown","eventparam"=>"inp,ev,id,val",
                                                    "switch"=>array("txtremark"=>"$ontxtremarkonkeydown")
                                )
                      );  
            $rtn.="myformdel.setItemValue('txt_id',$idrecord);";                          
            $rtn.=$this->FN_DHTMLXFORMEVENT("myformdel",$arrevent,true);
            $rtn.="dhxwindelete.window('windeleted').progressOff();";
            $rtn.="dhxwindelete.attachEvent('onClose',function(win){return true;})";
            return $rtn;
        }
        
        public function FN_DHTMLXREMARKFORDELETED($ObjectRoot,$ObjectName,$idrecord,$textdeleted,$eventafterdeleted,$deletefunction="delrecord")
        {
            $rtn="var dhxwindelete=new dhtmlXWindows();";
            $rtn.="dhxwindelete.setSkin('dhx_terrace');";
            
            //if($attachtodiv){$rtn.="dhxwindelete.attachViewportTo('$attachtodiv');";}
            $rtn.="var windeleted=dhxwindelete.createWindow(\"windeleted\",0,0,410,190);";            
            //echo "windeleted.getView().dhxwindelete.firstChild.style.backgroundColor ='blue';";
            //echo "windeleted.firstChild.style.background = \"#c2d5dc\";";
            $rtn.="dhxwindelete.window('windeleted').progressOn();";
            $rtn.="windeleted.setText('Konfirmasi Penghapusan Record');";
            $rtn.="dhxwindelete.window('windeleted').denyResize();";
            $rtn.="dhxwindelete.window('windeleted').setModal(true);";
            //if(!$closedby){$rtn.="dhxwindelete.window('windeleted').button(\"close\").disable();";}
            $rtn.="dhxwindelete.window('windeleted').bringToTop();";
            $rtn.="dhxwindelete.window('windeleted').center();";
            
            // === FOrm Deleted
            $formdata=array(
                              array("type"=>"settings","position"=>"label-left","labelWidth"=>"160","inputWidth"=>"120"),
                              array("type"=>"fieldset","label"=>"<font color='red'>Masukkan Remark</font> Terlebih dahulu","width"=>"255","offsetLeft"=>"5",
                                    "list"=>array(
                                                    array("type"=>"hidden","name"=>"txt_id"),
                                                    array("type"=>"input","name"=>"txtremark","inputWidth"=>"320","className"=>"txtleft","maxLength"=>"90",
                                                                          "note"=>array("text"=>"<span id='spjlhchar' style='color:blue;'>0/90</span> characters.")),
                                                    array("type"=>"button","name"=>"btndeleted","value"=>"Delete","offsetLeft"=>"0","offsetTop"=>"0",
                                                                           "className"=>"button_delete")
                                            )
                              )
                      );
            $formdata=json_encode($formdata);
            $rtn.="var myformdel=windeleted.attachForm($formdata, true);";
            $rtn.="myformdel.setFocusOnFirstActive();";
            $rtn.="myformdel.setSkin('dhx_skyblue');";
            
            // === FOrm Event
            $ontxtremarkonkeydown="if(ev.keyCode==13){ev.stopPropagation();ev.preventDefault();myformdel.setItemFocus('btndeleted');}";
            $ontxtremarkonkeydown.="if(ev.keyCode==27){dhxwindelete.unload();}";
            $ontxtremarkonkeyup="var remarklength=myformdel.getItemValue('txtremark');";
            $ontxtremarkonkeyup.="document.getElementById('spjlhchar').innerHTML=remarklength.toString().length+'/90';";
            
            
            $onbuttonclickbtndeleted="var lengthremark=myformdel.getItemValue('txtremark').length;";
            $onbuttonclickbtndeleted.="if(lengthremark<=15){fn_dhtmlxmessage('error','Masukkan Minimal 15 Character untuk alasan penghapusan. TERIMA KASIH!');myformdel.setItemFocus('txtremark');return false;}";
            $onbuttonclickbtndeleted.="if(myformdel.validate())
                                       {
                                            dhtmlx.confirm({
                                                 title:'Confirmation',text:'Are you will be deleted data?',type:'confirm',
                                                 callback:function(result){
                                                      if(result)
                                                      {";
                                                         $params="'obj=".$this->enc($ObjectName)."&task=".$this->enc($deletefunction)."'";
                                                         $onformsenddata="url=fn_dhtmlxsenddata('".$this->enc($ObjectRoot)."',$params);
                                                         myformdel.send(url,\"get\",function(loader, response){";
                                                           $onformsenddata.=$this->FN_DHTMLXWINDOWSHIDEPROGRESS();
                                                           $onformsenddata.="var sp=trim(response).split('|');
                                                           //alert(response);
                                                           if(sp[0]=='ok')
                                                           {
                                                               fn_dhtmlxmessage('','Data <b>'+myForm.getItemValue('$textdeleted')+'</b> has been deleted');";
                                                               $onformsenddata.=$eventafterdeleted;   
                                                               $onformsenddata.="dhxwindelete.unload();
                                                           }
                                                           else if(sp[0]=='failed')
                                                           {fn_dhtmlxmessage('error','Error Found : '+sp[1]);}
                                                           else
                                                           {fn_dhtmlxmessage('error','Error Found : '+response);}
                                                         });";
                                                         $onbuttonclickbtndeleted.=$this->FN_DHTMLXWINDOWSHOWPROGESS($onformsenddata);
            $onbuttonclickbtndeleted.="               }
                                                  }
                                             });
                                       }";
            $arrevent=array(
                                array("eventname"=>"onButtonClick","eventparam"=>"id,val",
                                                                   "switch"=>array("btndeleted"=>"$onbuttonclickbtndeleted")
                                ),
                                array("eventname"=>"onkeyup","eventparam"=>"inp,ev,id,val",
                                                    "switch"=>array("txtremark"=>"$ontxtremarkonkeyup")
                                ),
                                array("eventname"=>"onkeydown","eventparam"=>"inp,ev,id,val",
                                                    "switch"=>array("txtremark"=>"$ontxtremarkonkeydown")
                                )
                      );  
            $rtn.="myformdel.setItemValue('txt_id',$idrecord);";                          
            $rtn.=$this->FN_DHTMLXFORMEVENT("myformdel",$arrevent,true);
            $rtn.="dhxwindelete.window('windeleted').progressOff();";
            $rtn.="dhxwindelete.attachEvent('onClose',function(win){return true;})";
            return $rtn;
        }
        
        public function FN_DHTMLXFORM($myformname,$elementarget,$formdata,$notsetFocusOnFirstActive=null)
        {
            $formdata=json_encode($formdata);
            
            echo "$myformname=new dhtmlXForm(\"".$elementarget."\", ".$formdata.");";
            echo "$myformname.enableLiveValidation(true);";
            if(is_null($notsetFocusOnFirstActive)){echo "$myformname.setFocusOnFirstActive();";}
            //echo "$myformname.setFocusOnFirstActive();";
        }
        
        public function FN_DHTMLXFORMPOPUP($POPUPvar,$myFormpop,$myformarray,$myFormelement=null,$elementPop=null)
        {
            if($myFormelement&&$elementPop)
            {
                echo "$POPUPvar = new dhtmlXPopup({form: $myFormelement, id: ['$elementPop']});";
                echo "$myFormpop=$POPUPvar.attachForm(".json_encode($myformarray).");";                
            }
            else
            {
                echo "$POPUPvar=new dhtmlXPopup();";
                echo "$myFormpop=$POPUPvar.attachForm(".json_encode($myformarray).");";
                //echo "$POPUPvar.show(10,50,125,0);";
            }
        }
        
        public function FN_DHTMLXFORMDOCUMENT($myformname,$documentbody,$formdata)
        {
            $formdata=json_encode($formdata);
            
            echo "$myformname=new dhtmlXForm(".$documentbody.", ".$formdata.");";
            echo "$myformname.enableLiveValidation(true);";
            echo "$myformname.setFocusOnFirstActive();";
        }
        
        public function FN_DHTMLXFORMEVENT($myformname,$arrevent,$resulttovariable=null)
        {
            $rtn="";
            foreach($arrevent as $arr=>$arrval1)
            {
                $eventname="";$eventparam="";$withcase="";$arrsyntax=array();$statement="";
                //echo json_encode($arrval1);return false;
                foreach($arrval1 as $arrt1=>$arrvalt1)
                {
                    if($arrt1=='eventname'){$eventname=$arrvalt1;}
                    if($arrt1=='eventparam'){$eventparam=$arrvalt1;}
                    if($arrt1=='switch'){$withcase=$arrvalt1;$arrsyntax=$arrvalt1;}
                    if($arrt1=='statement'){$statement=$arrvalt1;}
                }
                $rtn.="$myformname.attachEvent(\"$eventname\",function($eventparam){";
                          if($withcase)
                          {
                              $rtn.="switch(id)
                                    {";
                                        foreach($arrsyntax as $arrcase=>$arrstatement)
                                        {
                                            $rtn.="case \"$arrcase\":$arrstatement;break;";
                                        }
                              $rtn.="}";
                          }
                          else{$rtn.=$statement;}    
                $rtn.="});";
            }
            if($resulttovariable){return $rtn;}else{echo $rtn;}

        }
                                                  
        public function FN_DHTMLXCREATECONTEXTMENUGRID($gridname,$contextmenuname,$arrmenucontext)
        {
            $menuproperties="";
            echo "var $contextmenuname=new dhtmlXMenuObject();
                      $contextmenuname.renderAsContextMenu();
                      $contextmenuname.setIconsPath(\"".PATH_THEME."/icons/\");
                   
                      $contextmenuname.attachEvent(\"onClick\",function(id){
                           switch(id)
                           {";
                               foreach($arrmenucontext as $arr=>$arrvalue)
                               {
                                   $event=$arrvalue["event"];
                                   $gifname=$arrvalue["gifname"];
                                   $menutext=$arrvalue["menutext"];
                                   $menuproperties.=$arr."|".$gifname."|".$menutext.",";
                                   echo "case '$arr':";
                                   if($arr=='contextmenu_deleted')
                                   {
                                        $contextconfirm="Data <b>'+getVal+'</b> ingin <font color=\"red\">dihapus</font>?";
                                        $contextevent="$gridname.deleteRow(data[0]);$event";

                                       //if(!$event)
                                       //{
//                                           echo "var data=$gridname.contextID.split(\"_\");
//                                                 var getValuserText=$gridname.cellById(data[0],1).getValue();
//                                                        dhtmlx.confirm({
//                                                            title:'Confirm',
//                                                            type:'confirm',
//                                                            text:'',
//                                                            callback:function(result){
//                                                                if(result){
//                                                                    $gridname.deleteRow(data[0]);$event;
//                                                                }
//                                                            }
//                                                        });";
                                       //}
                                       //else
                                       //{echo $event;}
                                   }
                                   if($arr=='contextmenu_print')
                                   {
                                       $contextconfirm="Data <b>'+getVal+'</b> ingin <font color=\"blue\">di Print</font>?";
                                       $contextevent=$event;
                                   }
                                   echo "var data=$gridname.contextID.split(\"_\");
                                         var getVal=$gridname.cellById(data[0],1).getValue();
                                                dhtmlx.confirm({
                                                    title:'Confirm',
                                                    type:'confirm',
                                                    text:'$contextconfirm',
                                                    callback:function(result){
                                                        if(result){
                                                            $contextevent;
                                                        }
                                                    }
                                                });";
                                   echo "break;";
                                   $menuproperties=substr($menuproperties,0,strlen($menuproperties)-1);
                               } 
            echo "         }";
            echo "    });
                   url=fn_dhtmlxloadobject('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("contxtmenustruc")."&mnuprop=$menuproperties');
                   //alert(url);
                   $contextmenuname.loadStruct(url);";    
        }
        
        public function FN_DHTMLXCONTEXTMENUSTRUCTURE()
        {
            $mnuprop=$_REQUEST['mnuprop'];
            $spmnuprop=explode(",",$mnuprop);
            
            header("Content-type: text/xml");
            echo("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 
            echo("<menu id=\"0\">");
                for($i=0;$i<count($spmnuprop);$i++)
                {
                    $sp=explode("|",$spmnuprop[$i]);
                    $mnuid=$sp[0];$mnugif=$sp[1];$mnutext=$sp[2];
                    echo("<item text=\"$mnutext\" img=\"$mnugif\"  id=\"$mnuid\" />");
                }
            
            echo("</menu>");
        }
        
        public function p($s) {
        if (!get_magic_quotes_gpc()) return mysql_real_escape_string($s);
            return $s;
        }
        
        public function r($s) {
            return str_replace("'", "\\'", $s);
        }
        
        
        public function FN_DHTMLXCBOFILTER(){
            //echo "dfdf";return false;
            //tableobj=tbl_cargoprice_information|id,cargocategory,cargodescription:id,cargodescription&
            //and=idroutestart|'+myForm.getItemValue('cbo_idroutestart')+',idrouteend|'+myForm.getItemValue('cbo_idrouteend')
            header("Content-Type: text/xml");
            $mask = @$_REQUEST["mask"];
            $tableobj=$_REQUEST['tableobj'];
            
            $sp=explode("|",$tableobj);
            $field=$sp[1];
            $f=explode(":",$sp[1]);
            //echo count($f);return false;
            $ismulticolumn=false;
            if(count($f)>1)
            {
                $ismulticolumn=true;
                $sfield=$f[0];
                $c=explode(",",$f[1]);
                $criteria="";$sortfield="";
                for($i=0;$i<count($c);$i++){
                    $criteria.="lower(".$c[$i].") like lower('%".$this->p($mask)."%') or ";
                    $sortfield=$c[$i];    
                }
                
            }
            else
            {
                $sfield=$field;
                $scol=explode(",",$sp[1]);
                $sortfield=$scol[1];
                $criteria="lower(".$scol[1].") like lower('%".$this->p($mask)."%') or ";
            }
            $criteria=substr($criteria,0,strlen($criteria)-strlen(" or "));                

            //$exp=$_REQUEST['exp'];
//            if($exp){
//                $spexp=explode("|",$exp);
//                
//            }
            
            $and=$_REQUEST['and'];
            if($and){
                $andcondition="";
                $spand=explode(",",$and);
                if(count($spand)>=1){
                    for($i=0;$i<count($spand);$i++){
                        $fand=explode("|",$spand[$i]);                        
                        $andcondition.=$fand[0]."='".$fand[1]."' and ";
                    } 
                    $andcondition=substr($andcondition,0,strlen($andcondition)-strlen(" and "));
                    $criteria="(".$andcondition.")";
                }
            }
            
            
            //tbl_employee|id,nik,fullname:nik,fullname
            $xml = '<?xml version="1.0" encoding="UTF-8"?>'.
                   '<complete add="true">';
            //$qry="SELECT ".$f[0]." FROM tbl_employee WHERE LOWER($sortfield) LIKE LOWER('".$this->p($mask)."%') ORDER BY LOWER($sortfield) ";
            $qry="SELECT ".$sfield." FROM ".$sp[0]." WHERE (".$criteria.") and isdeleted=0 ORDER BY LOWER(".$sortfield.") ";
            //echo $qry;return false;
            $r = $this->selectquery($qry);
            
           
//            $r = $this->selectquery($qry);
            //echo $r;
            //echo $field;return false;
            $spfield=explode(",",$field);
            $spfieldmulticol=array();
            if($ismulticolumn){
                $spfieldmulticol=explode(",",$f[1]);   
            }
            while ($o = $this->data_row_array($r)) {
                if(!$ismulticolumn)
                {
                    $xml.= '<option value="'.str_replace(" ","_",strtolower($o[$spfield[0]])).'"><![CDATA['.$o[$spfield[1]].']]></option>';    
                }
                else
                {
                    $xml.= '<option value="'.str_replace(" ","_",strtolower($o[$spfield[0]])).'"><![CDATA['.$o[$spfieldmulticol[0]].' - '.$o[$spfieldmulticol[1]].']]></option>';    
                }
                
            }
            $this->clearrecordset($r);
            $xml .= '</complete>';
            
            print_r($xml);

        }
        
        public function FN_DHTMLXADDCOMBO($DBNAME=null)
        {
            if(!$DBNAME){$DBNAME=DB_APORTIL;}
            // === param request tablename|col1,col2
            $tableobj=$_REQUEST['tableobj'];
            //echo $tableobj;
            $sp=explode("|",$tableobj);
            
            $table=$sp[0];
            $spcol=explode(",",$sp[1]);
            $col1=$spcol[0];$col2=$spcol[1];

            //echo $table;
            $multicol=false;
            // === Check The MultiColumn  id,subunitname,abbrunit:abbrunit,subunitname
            $spfield=explode(":",$sp[1]);
            if(count($spfield)>1)
            {
                $multicol=true;
                $spcol=explode(",",$spfield[0]);
                $col1=$spcol[0];$col2=$spcol[1];$col3=$spcol[2];
                
                $spview=explode(",",$spfield[1]);
                $view1=$spview[0];$view2=$spview[1];
            }
            //echo $multicol;return false;
            $swhere="";
            if(isset($_REQUEST['exp']))//&&$_SESSION['nik']!=='9999'
            {
                //$spexp=explode("|",$_REQUEST['exp']);
                //$exp="and ".$spexp[0]."<>'".$spexp[1]."'";
                $spexp=explode(",",$_REQUEST['exp']);
                if(count($spexp)>0)
                {
                    for($i=0;$i<count($spexp);$i++)
                    {
                        $spcriteria=explode("|",$spexp[$i]);    
                        $swhere.="and ".$spcriteria[0]."<>'".$spcriteria[1]."' ";
                    }
                }
                else
                {
                    $spcriteria=explode("|",$spexp[$i]);
                    $swhere="and ".$spcriteria[0]."<>'".$spcriteria[1]."'";
                }
                
            }
            
            if(isset($_REQUEST['and']))//&&$_SESSION['nik']!=='9999'
            {
                //$spexp=explode("|",$_REQUEST['exp']);
                //$exp="and ".$spexp[0]."<>'".$spexp[1]."'";
                $spexp=explode(",",$_REQUEST['and']);
                if(count($spexp)>0)
                {
                    for($i=0;$i<count($spexp);$i++)
                    {
                        $spcriteria=explode("|",$spexp[$i]);    
                        $swhere.="and ".$spcriteria[0]."='".$spcriteria[1]."' ";
                    }
                }
                else
                {
                    $spcriteria=explode("|",$spexp[$i]);
                    $swhere="and ".$spcriteria[0]."='".$spcriteria[1]."'";
                }
                
            }
            if(isset($_REQUEST['in']))//&&$_SESSION['nik']!=='9999'
            {
                //$spexp=explode("|",$_REQUEST['exp']);
                //$exp="and ".$spexp[0]."<>'".$spexp[1]."'";
                $spexp=explode("|",$_REQUEST['in']);
                $swhere="and ".$spexp[0]." in (".$spexp[1].")";
                
            }
            
            $captionnulltext="";
            if(isset($_REQUEST['withallcaption'])){$captionnulltext="ALL";}
            $mask=$_REQUEST['mask'];
            header("Content-type: text/xml");
            echo("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 
            echo("<complete>"); 
            echo("<template>");
            
            echo("<input><![CDATA[#$col2#]]></input>");
            if($multicol)
            {echo("<option><![CDATA[<div style='width:490px;'>#$view1# - #$view2#</div>]]></option>");}
            else
            {echo("<option><![CDATA[<div style='width:490px;'>#$col2#</div>]]></option>");}
            
            
            echo("</template>");
                     //echo("<option value=\"\">$captionnulltext</option>");
                     $sort=$col2;
                     if($_REQUEST['sort']){$sort=$_REQUEST['sort'];}
                     $qry="select distinct $col1,$col2 from ".$DBNAME.".$table where isdeleted=0 $swhere and ($col2<>'') order by $sort asc limit 100";
                     if($mask)
                     {
                        //$qry="select distinct $col1,$col2 from ".$DBNAME.".$table where isdeleted=0 $swhere and $col2 like '%$mask%' and ($col2<>'') order by $sort asc limit 20";
                        $qry="select distinct $col1,$col2 from ".$DBNAME.".$table where isdeleted=0 $swhere and ($col2 like '%$mask%' and $col2<>'') order by $sort asc limit 20";
                        if($multicol)
                        {
                            $qry="select distinct $col1,$col2,$col3 from ".$DBNAME.".$table 
                                  where (isdeleted=0 $swhere) and (($col2 like '%$mask%' and ($col2<>'')) or ($col3 like '%$mask%' and ($col3<>''))) order by $sort,$col3 asc limit 20";
                            //echo "FF";
                        }
                     }
                     //echo $qry;
                     if($this->fn_row_isexists($qry))
                     {
                         $rs=$this->selectquery($qry);
                         if($rs)
                         {
                             $option="";
                             while($rw=$this->data_row_array($rs))
                             {
                                 //echo("<option value=\"".$rw->img."\" img_src=\"".$rw->imgname."\">".$rw->imgname."</option>"); 
                                 //echo("<option value=\"".str_replace("&","&amp;",$rw[0])."\">".str_replace("&","&amp;",$rw[1])."</option>"); 
                                 $option="<option value=\"".str_replace("&","&amp;",$rw[0])."\">";
                                 $option.="<text>";
                                    $option.="<$col1>".str_replace("&","&amp;",$rw[0])."</$col1>";
                                    $option.="<$col2>".str_replace("&","&amp;",$rw[1])."</$col2>";
                                    if($multicol)
                                    {
                                        $option.="<$col3>".str_replace("&","&amp;",$rw[2])."</$col3>";    
                                    }
                                 $option.="</text>";
                                 $option.="</option>";
                                 echo($option); 
                             }
                         }
                         $this->clearrecordset($rs);                         
                     }
            echo("</complete>"); 
        }
        
        public function FN_DHTMLXADDCOMBOOLD($DBNAME=null)
        {
            if(!$DBNAME){$DBNAME=DB_APORTIL;}
            // === param request tablename|col1,col2
            $tableobj=$_REQUEST['tableobj'];
            //echo $tableobj;
            $sp=explode("|",$tableobj);
            
            $table=$sp[0];
            //echo $table;
            $spcol=explode(",",$sp[1]);
            $col1=$spcol[0];$col2=$spcol[1];
            
            $swhere="";
            if(isset($_REQUEST['exp']))//&&$_SESSION['nik']!=='9999'
            {
                //$spexp=explode("|",$_REQUEST['exp']);
                //$exp="and ".$spexp[0]."<>'".$spexp[1]."'";
                $spexp=explode(",",$_REQUEST['exp']);
                if(count($spexp)>0)
                {
                    for($i=0;$i<count($spexp);$i++)
                    {
                        $spcriteria=explode("|",$spexp[$i]);    
                        $swhere.="and ".$spcriteria[0]."<>'".$spcriteria[1]."' ";
                    }
                }
                else
                {
                    $spcriteria=explode("|",$spexp[$i]);
                    $swhere="and ".$spcriteria[0]."<>'".$spcriteria[1]."'";
                }
                
            }
            
            if(isset($_REQUEST['and']))//&&$_SESSION['nik']!=='9999'
            {
                //$spexp=explode("|",$_REQUEST['exp']);
                //$exp="and ".$spexp[0]."<>'".$spexp[1]."'";
                $spexp=explode(",",$_REQUEST['and']);
                if(count($spexp)>0)
                {
                    for($i=0;$i<count($spexp);$i++)
                    {
                        $spcriteria=explode("|",$spexp[$i]);    
                        $swhere.="and ".$spcriteria[0]."='".$spcriteria[1]."' ";
                    }
                }
                else
                {
                    $spcriteria=explode("|",$spexp[$i]);
                    $swhere="and ".$spcriteria[0]."='".$spcriteria[1]."'";
                }
                
            }
            if(isset($_REQUEST['in']))//&&$_SESSION['nik']!=='9999'
            {
                //$spexp=explode("|",$_REQUEST['exp']);
                //$exp="and ".$spexp[0]."<>'".$spexp[1]."'";
                $spexp=explode("|",$_REQUEST['in']);
                $swhere="and ".$spexp[0]." in (".$spexp[1].")";
                
            }
            
            $captionnulltext="";
            if(isset($_REQUEST['withallcaption'])){$captionnulltext="ALL";}
            $mask=$_REQUEST['mask'];
            header("Content-type: text/xml");
            echo("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 
            echo("<complete>"); 
                     //echo("<option value=\"\">$captionnulltext</option>");
                     $qry="select $col1,$col2 from ".$DBNAME.".$table where isdeleted=0 $swhere and ($col2<>'') order by $col2 asc limit 100";
                     if($mask)
                     {
                        $qry="select $col1,$col2 from ".$DBNAME.".$table where isdeleted=0 $swhere and $col2 like '%$mask%' and ($col2<>'') order by $col2 asc limit 100";
                     }
                     //echo $qry;
                     if($this->fn_row_isexists($qry))
                     {
                         $rs=$this->selectquery($qry);
                         if($rs)
                         {
                             while($rw=$this->data_row_array($rs))
                             {
                                 //echo("<option value=\"".$rw->img."\" img_src=\"".$rw->imgname."\">".$rw->imgname."</option>"); 
                                 echo("<option value=\"".str_replace("&","&amp;",$rw[0])."\">".str_replace("&","&amp;",$rw[1])."</option>"); 
                             }
                         }
                         $this->clearrecordset($rs);                         
                     }
            echo("</complete>"); 
        }
        
        public function FN_DHTMLXLOADOBJECT($withvariable=null,$objroot,$objname,$task,$params=null)
        {
            $singlequote="'";
            if($params){$params="&$params";if(substr($params,strlen($params)-1,1)!="'"){$singlequote="";};}
            $url="fn_dhtmlxloadobject('".$this->enc($objroot)."','obj=".$this->enc($objname)."&task=".$task."".$params."$singlequote);";
            if($withvariable){$url=$withvariable."=".$url;}
            return $url;
        }
        
        public function FN_DHTMLXLOADOBJECTURL($option,$task){return "?ajax=1&sec=1&option=".$option."&".$task;}
        
    }
?>
