<?php
    class USER_NEW extends USER
    {
        public function user_new_javainit()
        {

        }

        public function fn_new_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_new();
                break;

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

                default:
                    $this->fn_default_new();
                break;
            }
        }
        
        public function fn_default_new()
        {
            echo $this->FN_CREATEHEADER();

            echo "<style>
                      .besidebtnsave {margin-left:114px;margin-top:-7px;position:absolute;}
                      .besidebtnupdate {margin-left:220px;margin-top:-7px;position:absolute;}
                      .besidebtndelete {margin-left:322px;margin-top:-7px;position:absolute;}
                      .besidepassword {margin-left:290px;margin-top:-15px;position:absolute;}
                  </style>";
            echo "<script>
                       var myForm,myFormsearch,dgnew;
                       function initObject()
                       {";
                            $formdata=array(
                                              array("type"=>"settings","position"=>"label-left","labelWidth"=>"180","inputWidth"=>"120"),
                                              array("type"=>"block","width"=>"500",
                                                     "list"=>array(
                                                                      array("type"=>"hidden","name"=>"txt_id"),
                                                                      array("type"=>"hidden","name"=>"txt_isactivated"),
                                                                      array("type"=>"hidden","name"=>"txt_passmask"),
                                                                      array("type"=>"input","name"=>"txt_nik","label"=>"NIK / User Login","required"=>"true","info"=>"true","inputWidth"=>"130",
                                                                            "tooltip"=>"Masukkan NIK terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"20","className"=>"txtcenter"),
                                                                      array("type"=>"input","name"=>"txt_namaemployee","label"=>"Nama Employee","required"=>"true","info"=>"true","inputWidth"=>"220",
                                                                            "tooltip"=>"Masukkan Nama Employee terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"80","className"=>"txtleft"),
                                                                      array("type"=>"input","name"=>"txt_hp","label"=>"Nomor HP","required"=>"true","info"=>"true","inputWidth"=>"130",
                                                                            "tooltip"=>"Masukkan Nomor HP terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"20","className"=>"txtcenter"),
                                                                      array("type"=>"input","name"=>"txt_pass","label"=>"Password","required"=>"true","info"=>"true","inputWidth"=>"130",
                                                                            "tooltip"=>"Masukkan Password terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"10","className"=>"txtcenter"),
                                                                      array("type"=>"input","name"=>"txt_menuidgroupproject","label"=>"ID Groupproject","info"=>"true","inputWidth"=>"220",
                                                                            "tooltip"=>"Masukkan ID Groupproject terlebih dahulu. TERIMA KASIH","maxLength"=>"65535","className"=>"txtleft"),
                                                                      array("type"=>"input","name"=>"txt_menuid","label"=>"Menu ID","info"=>"true","inputWidth"=>"220",
                                                                            "tooltip"=>"Masukkan Menu ID terlebih dahulu. TERIMA KASIH","maxLength"=>"65535","className"=>"txtleft"),
                                                                      array("type"=>"input","name"=>"txt_treemenuid","label"=>"Treemenu ID","info"=>"true","inputWidth"=>"220",
                                                                            "tooltip"=>"Masukkan Treemenu ID terlebih dahulu. TERIMA KASIH","maxLength"=>"65535","className"=>"txtleft"),
                                                                      array("type"=>"combo","name"=>"cbo_idgroupuser","label"=>"Group User","required"=>"true","info"=>"true","inputWidth"=>"130",
                                                                            "tooltip"=>"Pilih Group User terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"11","className"=>"txtleft"),
                                                                      array("type"=>"combo","name"=>"cbo_idgroupunit","label"=>"Group Unit","required"=>"true","info"=>"true","inputWidth"=>"130",
                                                                            "tooltip"=>"Pilih Group Unit terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"11","className"=>"txtleft"),
                                                                      array("type"=>"checkbox","name"=>"chk_isactivated","label"=>"Aktifkan"),
                                                                      array("type"=>"combo","name"=>"cbo_idlevel","label"=>"User Level","required"=>"true","info"=>"true","inputWidth"=>"160",
                                                                            "tooltip"=>"Pilih User Level terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"11","className"=>"txtleft"),
                                                                      array("type"=>"button","name"=>"btnsave","value"=>"Save","className"=>"button_update","offsetLeft"=>"20","offsetTop"=>"15"),
                                                                      array("type"=>"button","name"=>"btnupdate","value"=>"Update","className"=>"button_saveas besidebtnsave","offsetLeft"=>"0","disabled"=>"1"),
                                                                      //array("type"=>"button","name"=>"btnsubmit","value"=>"Submit","className"=>"button_submit besidebtnupdate","offsetLeft"=>"0","disabled"=>"1"),
                                                                      array("type"=>"button","name"=>"btndelete","value"=>"Delete","className"=>"button_delete besidebtnupdate","offsetLeft"=>"0","disabled"=>"1"),
                                                                      array("type"=>"button","name"=>"btncancel","value"=>"Cancel","className"=>"button_cancel besidebtndelete","offsetLeft"=>"0","disabled"=>"0")
                                                     )
                                              )
                                       );

                            $this->FN_DHTMLXFORM("myForm","divnewnew",$formdata);

                            $urlcbo="fn_dhtmlxloadobject('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("dhtmlxaddcombo")."&tableobj=tbl_usergroup|id,groupuser')";
                            $this->FN_COMBOVALIDATIONVALUENEW("myForm","cbo_idgroupuser","tbl_usergroup","$urlcbo","");

                            $urlcbo="fn_dhtmlxloadobject('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("dhtmlxaddcombo")."&tableobj=tbl_usergroupunit|id,groupunit')";
                            $this->FN_COMBOVALIDATIONVALUENEW("myForm","cbo_idgroupunit","tbl_usergroupunit","$urlcbo","");

                            $urlcbo="fn_dhtmlxloadobject('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("dhtmlxaddcombo")."&tableobj=tbl_userlevel|id,userlevel')";
                            $this->FN_COMBOVALIDATIONVALUENEW("myForm","cbo_idlevel","tbl_userlevel","$urlcbo","");

                            $arrerror=array("txt_nik"=>"Error Found : Harap Isikan <b>NIK</b> terlebih dahulu.TERIMA KASIH",
                                            "txt_namaemployee"=>"Error Found : Harap Isikan <b>Nama Employee</b> terlebih dahulu.TERIMA KASIH",
                                            "txt_hp"=>"Error Found : Harap Isikan <b>Nomor HP</b> terlebih dahulu.TERIMA KASIH",
                                            "txt_pass"=>"Error Found : Harap Isikan <b>Password</b> terlebih dahulu.TERIMA KASIH",
                                            "txt_menuidgroupproject"=>"Error Found : Harap Isikan <b>ID Groupproject</b> terlebih dahulu.TERIMA KASIH",
                                            "txt_menuid"=>"Error Found : Harap Isikan <b>Menu ID</b> terlebih dahulu.TERIMA KASIH",
                                            "txt_treemenuid"=>"Error Found : Harap Isikan <b>Treemenu ID</b> terlebih dahulu.TERIMA KASIH",
                                            "cbo_idgroupuser"=>"Error Found : Harap Isikan <b>Group User</b> terlebih dahulu.TERIMA KASIH",
                                            "cbo_idgroupunit"=>"Error Found : Harap Isikan <b>Group Unit</b> terlebih dahulu.TERIMA KASIH",
                                            "cbo_idlevel"=>"Error Found : Harap Isikan <b>User Level</b> terlebih dahulu.TERIMA KASIH"
                                      );
                            $this->FN_DHTMLXFORMVALIDATIONERROR("myForm",$arrerror);

                            $arrayControls=array("txt_id"=>"","txt_nik"=>"","txt_namaemployee"=>"","txt_hp"=>"",
                                                 "txt_pass"=>"","txt_menuidgroupproject"=>"","txt_menuid"=>"",
                                                 "txt_treemenuid"=>"","cbo_idgroupuser"=>"","cbo_idgroupunit"=>"",
                                                 "chk_isactivated"=>"","cbo_idlevel"=>""
                                          );

                            // === Form Event
                            $onobjkeydown="if(ev.keyCode==13){ev.stopPropagation();ev.preventDefault();if(myForm.isItemEnabled('btnupdate')){myForm.setItemFocus('btnupdate');dhtmlXclickButton('btnupdate');}else{myForm.setItemFocus('btnsave');}return false;}";
                            $onchangechkisactivated="myForm.setItemValue('txt_isactivated',0);";
                            $onchangechkisactivated.="if(checked){myForm.setItemValue('txt_isactivated',1);}";
                            
                            $onbuttonclickbtnsave="if(myForm.validate())
                                                   {
                                                        dhtmlx.confirm({
                                                              title:'Confirmation',text:'Are you will be saved and data is correctly?',type:'confirm',
                                                              callback:function(result){
                                                                  if(result)
                                                                  {";
                                                                      $params="'obj=".$this->enc("user_new")."&task=".$this->enc("saverecord")."'";
                                                                      $onformsenddata="url=fn_dhtmlxsenddata('".$this->enc("obj_user")."',$params);
                                                                      myForm.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('txt_nik')+'</b> has been saved');";
                                                                              $onformsenddata.=$this->FN_DHTMLXFORMCLEAR2("myForm",$arrayControls,"txt_nik");
                                                                              $onformsenddata.="fn_grid_loaddata();
                                                                          }
                                                                          else if(sp[0]=='failed')
                                                                          {fn_dhtmlxmessage('error','Error Found : '+sp[1]);}
                                                                          else
                                                                          {fn_dhtmlxmessage('error','Error Found : '+response);}
                                                                      });";
                                                                      $onbuttonclickbtnsave.=$this->FN_DHTMLXWINDOWSHOWPROGESS($onformsenddata);
                            $onbuttonclickbtnsave.="              }
                                                              }
                                                        });
                                                    }";

                            $onbuttonclickbtnupdt="if(myForm.validate())
                                                   {
                                                        dhtmlx.confirm({
                                                             title:'Confirmation',text:'Are you will be updated and data is correctly?',type:'confirm',
                                                             callback:function(result){
                                                                if(result)
                                                                {";
                                                                   $params="'obj=".$this->enc("user_new")."&task=".$this->enc("updrecord")."'";
                                                                   $onformsenddata="url=fn_dhtmlxsenddata('".$this->enc("obj_user")."',$params);
                                                                   myForm.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('txt_nik')+'</b> has been update');";
                                                                           $onformsenddata.=$this->FN_DHTMLXFORMCLEAR2("myForm",$arrayControls,"txt_nik");
                                                                           $onformsenddata.="myForm.enableItem('btnsave');";
                                                                           $onformsenddata.="myForm.disableItem('btnupdate');";
                                                                           $onformsenddata.="myForm.disableItem('btndelete');";
                                                                           $onformsenddata.="fn_grid_loaddata();
                                                                      }
                                                                      else if(sp[0]=='failed')
                                                                      {fn_dhtmlxmessage('error','Error Found : '+sp[1]);}
                                                                      else
                                                                      {fn_dhtmlxmessage('error','Error Found : '+response);}
                                                                   });";
                                                                   $onbuttonclickbtnupdt.=$this->FN_DHTMLXWINDOWSHOWPROGESS($onformsenddata);
                            $onbuttonclickbtnupdt.="            }
                                                             }
                                                        });
                                                   }";

                            $eventafterdeleted=$this->FN_DHTMLXFORMCLEAR2("myForm",$arrayControls,"txt_nik");
                            $eventafterdeleted.="myForm.enableItem('btnsave');";
                            $eventafterdeleted.="myForm.disableItem('btnupdate');";
                            $eventafterdeleted.="myForm.disableItem('btndelete');";
                            $eventafterdeleted.="fn_grid_loaddata();";
                            $onbuttonclickbtndeleted=$this->FN_DHTMLXREMARKFORDELETED("obj_user","user_new","myForm.getItemValue('txt_id')","txt_nik",$eventafterdeleted);

                            $onbuttonclickbtncancel=$this->FN_DHTMLXFORMCLEAR2("myForm",$arrayControls);
                            $onbuttonclickbtncancel.="myForm.enableItem('btnsave');";
                            $onbuttonclickbtncancel.="myForm.disableItem('btnupdate');";
                            $onbuttonclickbtncancel.="myForm.disableItem('btndelete');";
                            $onbuttonclickbtncancel.="myForm.setItemFocus('txt_nik');";
                            $onbuttonclickbtncancel.="fn_grid_loaddata();";

                            $arrevent=array(
                                                array("eventname"=>"onbuttonclick","eventparam"=>"id,val",
                                                          "switch"=>array(
                                                                                "btnsave"=>"$onbuttonclickbtnsave",
                                                                                "btnupdate"=>"$onbuttonclickbtnupdt",
                                                                                "btndelete"=>"$onbuttonclickbtndeleted",
                                                                                "btncancel"=>"$onbuttonclickbtncancel"
                                                          )
                                                ),
                                                array("eventname"=>"onkeydown","eventparam"=>"inp,ev,id,val",
                                                          "switch"=>array(
                                                                                "cbo_idlevel"=>"$onobjkeydown"
                                                          )
                                                ),
                                                array("eventname"=>"onChange","eventparam"=>"id,val,checked",
                                                          "switch"=>array(
                                                                                "chk_isactivated"=>"$onchangechkisactivated"
                                                          )
                                                )
                            );


                            $this->FN_DHTMLXFORMEVENT("myForm",$arrevent);

                            // === FORM SEARCH AND GRID
                            $formdata=array(
                                              array("type"=>"settings","position"=>"label-left","labelWidth"=>"180","inputWidth"=>"120"),
                                              array("type"=>"fieldset","width"=>"580","label"=>"Pencarian",
                                                     "list"=>array(
                                                                      array("type"=>"input","name"=>"txtsearch","label"=>"Masukkan Kata Yang Ingin Dicari","info"=>"true","inputWidth"=>"240",
                                                                            "tooltip"=>"Insert Your Keyword","maxLength"=>"","className"=>"txtleft","labelWidth"=>"210"),
                                                                      array("type"=>"newcolumn"),
                                                                      array("type"=>"button","name"=>"btnfind","value"=>"","className"=>"button_find","offsetLeft"=>"10","offsetTop"=>"0")
                                                     )
                                              )
                            );

                            $this->FN_DHTMLXFORM("myFormsearch","divnewsearch",$formdata,true);
                            $ontxtsearchkeydown="if(ev.keyCode==13){ev.stopPropagation();ev.preventDefault();myFormsearch.setItemFocus('btnfind');}";
                            $arrevent=array(
                                                array("eventname"=>"onbuttonclick","eventparam"=>"id,val",
                                                          "switch"=>array(
                                                                                "btnfind"=>"fn_grid_loaddata()"
                                                          )
                                                ),
                                                array("eventname"=>"onkeydown","eventparam"=>"inp,ev,id,val",
                                                          "switch"=>array(
                                                                                "txtsearch"=>"$ontxtsearchkeydown"
                                                          )
                                                )
                            );
                            $this->FN_DHTMLXFORMEVENT("myFormsearch",$arrevent);

                            $grdinit=array("gridname"=>"dgnew","divtarget"=>"div_dgnew","divpaging"=>"div_dgnewpaging","paginglimit"=>PAGE_LIMIT,
                                           "showloader"=>"true","setcolumnhidden"=>"true,false,false,false,false,false,false,false,false,false,false,false,false,false,false");
                            $gridproperties=array("id"=>"right,ro,96,right,int,false,true",
                                                  "No.&nbsp;"=>"right,ro,35,center,int,false",
                                                  "Nik"=>"left,ro,94,left,str,false",
                                                  "Nama Employee"=>"left,ro,234,left,str,false",
                                                  "Nomor HP"=>"left,ro,134,left,str,false",
                                                  "Password"=>"left,ro,126,left,str,false",
                                                  "ID Groupproject"=>"left,ro,250,left,str,false",
                                                  "Menu ID"=>"left,ro,250,left,str,false",
                                                  "Treemenu ID"=>"left,ro,250,left,str,false",
                                                  "Group User"=>"center,ro,110,center,str,false",
                                                  "Group Unit"=>"center,ro,110,center,str,false",
                                                  "Aktifkan"=>"center,ch,110,center,int,false",
                                                  "User Level"=>"center,ro,110,center,str,false");
                            $this->FN_DHTMLXGRIDVIEW($grdinit,$gridproperties,"bricks","","fn_grid_loaddata()");
                            $arrfields=array("txt_id"=>"","txt_nik"=>"","txt_namaemployee"=>"","txt_hp"=>"","txt_passmask"=>"pass",
                                             "txt_menuidgroupproject"=>"","txt_menuid"=>"","txt_treemenuid"=>"","txt_isactivated"=>"",
                                             "cbo_idgroupuser"=>"idgroupuser|groupuser","cbo_idgroupunit"=>"idgroupunit|groupunit","cbo_idlevel"=>"idlevel|userlevel");
                            
                            $otherevent="var pass=ajaxuridhtmlx('".$this->enc("obj_user")."','obj=".$this->enc("user_new")."&task=".$this->enc("getdecrypt")."&pass='+spres[4]);";
                            $otherevent.="myForm.setItemValue('txt_pass',pass);";
                            $otherevent.="myForm.uncheckItem('chk_isactivated');";
                            $otherevent.="if(spres[8]=='1'){myForm.checkItem('chk_isactivated');}";
                            $this->FN_DHTMLXGRIDVIEWTOFORMNEW("dgnew","myForm","tbl_userlogin",0,$arrfields,"",$otherevent);
            echo "    }

                      function fn_grid_loaddata()
                      {
                          var keyword=myFormsearch.getItemValue('txtsearch');
                          url=fn_dhtmlxloadobject('".$this->enc("obj_user")."','obj=".$this->enc("user_new")."&task=".$this->enc("grdrecord")."&keyword='+keyword);
                          //alert(url);
                          dgnew.clearAndLoad(url);";
            echo "    }
                   </script>";
            echo $this->FN_CLOSEHEADER();
            echo $this->FN_CREATEBODY("e8f1ff");

            echo "<table width=\"98%\" border=\"0\">
                      <tr>
                          <td>";
                              $url="location.reload();";
                              $myuri=array("<b>INFORMASI USER LOGIN</b>"=>"$url|id='a_new'");
                              echo $this->MULTIPLE_LINK($myuri);
            echo "       </td>
                      </tr>
                      <tr>
                          <td>
                              <div id=\"divnewcontent\" style=\"margin-left:0px;\">
                                  <table width=\"98%\" border=\"0\">
                                      <tr>
                                          <td width=\"45%\" valign=\"top\">
                                              <div id=\"divnewnew\" style=\"\"></div>
                                          </td>
                                          <td valign=\"top\">
                                              <table width=\"98%\" cellpadding=\"0\" cellspacing=\"0\">
                                                  <tr>
                                                      <td valign=\"top\">
                                                          <div id=\"divnewsearch\" style=\"width:560px;margin-top:-6px;\"></div>
                                                      </td>
                                                  </tr>
                                                  <tr>
                                                      <td>
                                                          <div id=\"div_dgnew\" style=\"height:380px;width:580px;overflow:hidden\"></div>
                                                      </td>
                                                  </tr>
                                                  <tr>
                                                      <td>
                                                          <div id=\"div_dgnewpaging\" style=\"width:598px;margin-top:1px\"></div>
                                                      </td>
                                                  </tr>
                                                  <tr><td valign=\"top\"><div id=\"loadergrid\" style=\"z-index:100;position:absolute;margin-top:-220px;margin-left:287px;display:visibility;\">".$this->CREATE_IMAGE("loadergrid.gif")."</div></td></tr>
                                              </table>
                                          </td>
                                      </tr>
                                  </table>
                              </div>
                          </td>
                      </tr>
                  </table>";
            echo $this->FN_CREATEFOOTER();

        }

        public function fn_getdecrypt()
        {
            $pass=$_REQUEST['pass'];
            echo $this->dec($pass);
        }
        
        public function fn_grdrecord()
        {
            $keyword=$_REQUEST["keyword"];
            header("Content-type: text/xml");
            echo('<?xml version="1.0" encoding="utf-8"?>');
            echo "<rows id='0'>";

            $nikexception="and nik<>'82010'";
            if($_SESSION['nik']=='82010'){$nikexception="";}
            $qry="select id,nik,namaemployee,hp,maskpass,pass,menuidgroupproject,menuid,treemenuid,idgroupuser,
                         groupuser,idgroupunit,groupunit,isactivated,idlevel,userlevel
                  from ".DB_APORTIL.".tbl_userlogin
                  where (nik like '%$keyword%' and isdeleted=0) $nikexception
                  order by id asc limit ".TBL_PAGE_LIMIT;

            $rs=$this->selectquery($qry);
            if($rs)
            {
               $i=1;
               while($row=$this->data_row_array($rs))
               {
                  echo ("<row id='".$row["id"]."'>");
                        print("<cell><![CDATA[".$row["id"]."]]></cell>");
                        print("<cell><![CDATA[".$i."]]></cell>");
                        print("<cell><![CDATA[".$row["nik"]."]]></cell>");
                        print("<cell><![CDATA[".$row["namaemployee"]."]]></cell>");
                        print("<cell><![CDATA[".$row["hp"]."]]></cell>");
                        print("<cell><![CDATA[".$row["maskpass"]."]]></cell>");
                        print("<cell><![CDATA[".$row["menuidgroupproject"]."]]></cell>");
                        print("<cell><![CDATA[".$row["menuid"]."]]></cell>");
                        print("<cell><![CDATA[".$row["treemenuid"]."]]></cell>");
                        print("<cell><![CDATA[".$row["groupuser"]."]]></cell>");
                        print("<cell><![CDATA[".$row["groupunit"]."]]></cell>");
                        print("<cell><![CDATA[".$row["isactivated"]."]]></cell>");
                        print("<cell><![CDATA[".$row["userlevel"]."]]></cell>");
                  echo ("</row>");
                  $i+=1;
               }
            }
            else
            {
                  echo mysql_errno().": ".mysql_error()." at ".__LINE__." line in ".__FILE__." file<br>";
            }
            echo "</rows>";

        }

        public function fn_saverecord($isupdate=null)
        {
            if($isupdate){$id=$_REQUEST['txt_id'];}
            $nik=$_REQUEST['txt_nik'];
            $namaemployee=$_REQUEST['txt_namaemployee'];
            $hp=$_REQUEST['txt_hp'];
            $pass=$this->enc(trim($_REQUEST['txt_pass']));
            $menuidgroupproject=$_REQUEST['txt_menuidgroupproject'];
            $menuid=$_REQUEST['txt_menuid'];
            $treemenuid=$_REQUEST['txt_treemenuid'];
            $idgroupuser=$_REQUEST['cbo_idgroupuser'];
            $groupuser=$this->fn_get_fieldvalue("groupuser","select groupuser from ".DB_APORTIL.".tbl_usergroup where id='".$idgroupuser."'");
            $idgroupunit=$_REQUEST['cbo_idgroupunit'];
            $groupunit=$this->fn_get_fieldvalue("groupunit","select groupunit from ".DB_APORTIL.".tbl_usergroupunit where id='".$idgroupunit."'");
            $isactivated=$_REQUEST['txt_isactivated'];
            $idlevel=$_REQUEST['cbo_idlevel'];
            $userlevel=$this->fn_get_fieldvalue("userlevel","select userlevel from ".DB_APORTIL.".tbl_userlevel where id='$idlevel'");

            $qry="insert into ".DB_APORTIL.".tbl_userlogin 
                  set nik='$nik',namaemployee='$namaemployee',hp='$hp',pass='$pass',menuidgroupproject='$menuidgroupproject',menuid='$menuid',
                      treemenuid='$treemenuid',idgroupuser='$idgroupuser',groupuser='$groupuser',idgroupunit='$idgroupunit',groupunit='$groupunit',isactivated='$isactivated',
                      idlevel='$idlevel',userlevel='$userlevel',iby='".$_SESSION['nik']."',idt=now()";
            if($isupdate)
            {
                $qry="update ".DB_APORTIL.".tbl_userlogin
                      set nik='$nik',namaemployee='$namaemployee',hp='$hp',pass='$pass',menuidgroupproject='$menuidgroupproject',menuid='$menuid',
                          treemenuid='$treemenuid',idgroupuser='$idgroupuser',groupuser='$groupuser',idgroupunit='$idgroupunit',groupunit='$groupunit',
                          isactivated='$isactivated',idlevel='$idlevel',uby='".$_SESSION['nik']."',udt=now()
                      where id='$id'";
            }

            if($this->executequery($qry)){echo "ok|";return true;}
        }
        
        public function fn_updrecord(){$this->fn_saverecord(true);}

        public function fn_delrecord()
        {
            $id=$_REQUEST['txt_id'];
            $remark=$_REQUEST['txtremark'];
            $qry="update ".DB_APORTIL.".tbl_userlogin
                  set isdeleted=1,remark='$remark',dby='".$_SESSION['nik']."',ddt=now()
                  where id='$id'";
            if($this->executequery($qry)){echo "ok|";return true;}
            else
            {
              echo "failed|".$this->getErrorQuery();
            }
        }
    }
?>