<?php
    class MENUCONFIG_LIST extends MENUCONFIG
    {     
        public function menuconfig_list_javainit()
        {
            echo "<script language=\"javascript\">
              
                  </script>";
        } 
        
        public function fn_list_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_menulist();
                break;
                
                case $task:
                    $task="fn_".$task;
                    if(method_exists($this,$task)){$this->$task();}
                break;
       
                //case "searchmenu":
//                    $this->fn_searchmenu();
//                break;
//                
//                case "paging":
//                    $this->fn_disp_page();
//                break;

//                case "editmenu":
//                    $this->fn_editmenu();
//                break;
//                
//                case "iconlists":
//                    $this->fn_iconlists();
//                break;
//                
//                case "cbomenugroupproject":
//                    $this->fn_cbomenugroupproject();
//                break;
//                
//                case "updatemenu":
//                    $this->fn_updatemenu();
//                break;
//                
//                default:
                    //if($_SESSION["nikx"]!=='9999'){echo $this->under_construction();}
//                    $this->fn_default_menulist();                    
//                break;
            }
        }
                           
        public function fn_default_menulist()
        {
            echo $this->FN_CREATEHEADER();
            //echo "<div><span id=\"pagingArea\"></span>&nbsp;<span id=\"infoArea\"></span></div>";
            echo "<script>  
                        var myForm,dgmenuconfig,dp;
                        function initObject()
                        {";
                            $formdata=array(
                                             array("type"=>"settings","position"=>"label-left","labelWidth"=>"auto","inputWidth"=>"auto"),
                                             array("type"=>"fieldset","width"=>"900","label"=>"Find Menu",
                                                     "list"=>array(
                                                                      array("type"=>"input","name"=>"txtsearch","label"=>"Menu Name","info"=>"true","inputWidth"=>"160",
                                                                            "tooltip"=>"Entry your menu first. Thank you","className"=>"txtleft"),
                                                                      array("type"=>"newcolumn"),
                                                                      array("type"=>"combo","name"=>"cbotipemenu","label"=>"","info"=>"true","readonly"=>"0",
                                                                            "tooltip"=>"Choice your menu type","inputWidth"=>"120","offsetLeft"=>"10","options"=>array(array(value=>"tree",text=>"TreeMenu"),array(value=>"",text=>"Menu"))),
                                                                      array("type"=>"newcolumn"),
                                                                      array("type"=>"combo","name"=>"cbogroupproject","label"=>"","info"=>"true","readonly"=>"0",
                                                                            "tooltip"=>"Choice your menu type","inputWidth"=>"220","offsetLeft"=>"10"),
                                                                      array("type"=>"newcolumn"),
                                                                      array("type"=>"button","name"=>"btnfindmenu","value"=>"Find Menu","className"=>"button_update","offsetLeft"=>"10","offsetTop"=>"5"),
                                                                  )
                                             )
                            );


                            $this->FN_DHTMLXFORMDOCUMENT("myForm","divmyform",$formdata);
                            
                            $eventfindmenu="var url=fn_dhtmlxloadobject('".$this->enc("obj_menuconfig")."','obj=".$this->enc("menuconfig_list")."&task=".$this->enc("searchmenu")."&tipemenu='+myForm.getCombo(\"cbotipemenu\").getSelectedValue()+'&idgroupproject='+myForm.getCombo(\"cbogroupproject\").getSelectedValue()+'&keyword='+myForm.getItemValue(\"txtsearch\"));";
                            $eventfindmenu.="dgmenuconfig.clearAndLoad(url);";
                            $eventfindmenu.="url=fn_dhtmlxloadobject('".$this->enc("obj_menuconfig")."','obj=".$this->enc("menuconfig_list")."&task=".$this->enc("updatemenu")."&tipemenu='+myForm.getCombo(\"cbotipemenu\").getSelectedValue()+'&keyword='+myForm.getItemValue(\"txtsearch\"));";
                            $eventfindmenu.="dp = new dataProcessor(url);";
                            $eventfindmenu.="dp.init(dgmenuconfig);";
                            $arrevent=array(
                                                array("eventname"=>"onButtonClick","eventparam"=>"id",
                                                          "switch"=>array(
                                                                "btnfindmenu"=>"$eventfindmenu"
                                                          )
                                                )
                            );
                            $this->FN_DHTMLXFORMEVENT("myForm",$arrevent);
                            
                            $grdinit=array("gridname"=>"dgmenuconfig","divtarget"=>"divdgmenuconfig","divpaging"=>"divpagingarea","paginglimit"=>PAGE_LIMIT,"skin"=>"modern",
                                           "showloader"=>"true","setcolumnhidden"=>"true,false,false,false,false,false,false,false,false,false,false,false,false,false,true,false",
                                           "attachheader"=>"#rspan,#rspan,#combo_filter,#combo_filter,#rspan,#rspan,#rspan,#rspan,#rspan,#rspan,#rspan,#rspan,#combo_filter,#rspan,#rspan,#rspan",
                                           "enableheadermenu"=>true);
                            $gridproperties=array("id"=>"right,ro,40,right,int,false,true",
                                                  "Menu ID.&nbsp;"=>"left,ro,160,left,str,false",
                                                  "Menu Type"=>"left,ro,110,left,str,false",
                                                  "Menu Header"=>"left,ro,120,left,str,false",
                                                  "Menu Text"=>"left,ed,180,left,str,false",
                                                  "Menu Description"=>"left,ed,200,left,str,false",
                                                  "Menu Image"=>"left,ro,150,left,str,false",
                                                  "Obj Option"=>"left,ed,150,left,str,false",
                                                  "Obj Name"=>"left,ed,150,left,str,false",
                                                  "Obj Task"=>"left,ed,160,left,str,false",
                                                  "Obj Target"=>"left,ro,110,left,str,false",
                                                  "Menu Order"=>"center,ed,110,center,int,false",
                                                  "Menu Group"=>"center,ed,110,center,str,false",
                                                  "Group Project"=>"center,combo,110,center,str,false",
                                                  "idgroupproject"=>"center,ro,80,center,str,false,true",
                                                  "Activated"=>"center,ch,80,center,str,false");
                            $this->FN_DHTMLXGRIDVIEW($grdinit,$gridproperties,"bricks",true,"fn_grid_loaddata()");

                            
            echo "       }
                         
                         function fn_grid_loaddata()
                         {
                            //var keyword=myFormsearch.getItemValue('txtsearch');
                            var url=fn_dhtmlxloadobject('".$this->enc("obj_menuconfig")."','obj=".$this->enc("menuconfig_list")."&task=".$this->enc("searchmenu")."&tipemenu='+myForm.getCombo(\"cbotipemenu\").getSelectedValue()+'&idgroupproject='+myForm.getCombo(\"cbogroupproject\").getSelectedValue()+'&keyword='+myForm.getItemValue(\"txtsearch\"));
                            //alert(url);
                            dgmenuconfig.clearAndLoad(url);
                            url=fn_dhtmlxloadobject('".$this->enc("obj_menuconfig")."','obj=".$this->enc("menuconfig_list")."&task=".$this->enc("updatemenu")."&tipemenu='+myForm.getCombo(\"cbotipemenu\").getSelectedValue()+'&keyword='+myForm.getItemValue(\"txtsearch\"));
                            dp = new dataProcessor(url);
                            dp.init(dgmenuconfig);
                         }  
                  </script>";
            echo $this->FN_CLOSEHEADER();
            
            echo $this->FN_CREATEBODY("e8f1ff");
            echo "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">
                      <tr>
                          <td>
                              <div id=\"divmyform\" style=\"width:100%;\"></div>
                          </td>
                      </tr>
                      <tr>
                          <td>
                              <div id=\"divdgmenuconfig\" style=\"width:898px; height:400px; background-color:white;\"></div>
                          </td>
                      </tr>
                      <tr><td valign=\"top\"><div id=\"loadergrid\" style=\"z-index:100;position:absolute;margin-top:-220px;margin-left:417px;display:visibility;\">".$this->CREATE_IMAGE("loadergrid.gif")."</div></td></tr>
                      <tr>
                          <td>
                            <div id=\"divpagingarea\" style=\"width:888px;margin-top:1px\"></div>
                        </td>
                      </tr>
                  </table>";
            echo $this->FN_CREATEFOOTER();
        }
        
        public function fn_searchmenu()
        {
            $tipemenu=$_REQUEST["tipemenu"];
            $idgrouproject=$_REQUEST["idgroupproject"];$criteriaidgroupproject="";
            if($idgrouproject>=1){$criteriaidgroupproject=" and m.id_menu_groupproject like '%$idgrouproject%'";}
            $keyword=$_REQUEST["keyword"];
            //include XML Header (as response will be in xml format)
            header("Content-type: text/xml");
            //encoding may be different in your case
            echo('<?xml version="1.0" encoding="UTF-8"?>'); 

            //start output of data
            echo "<rows>";

            //output data from DB as XML
            $qry="select m.id,m.menuid,m.menutype,m.menuheader,m.menutext,m.menudesc,m.menuimg,m.objoption,m.id_menu_groupproject,
                         m.objname,m.objtask,m.objtarget,m.menuorder,m.menugroup,gp.groupname,m.menuactivated
                  from ".DB_APORTIL.".tbl_".$tipemenu."menu m left join ".DB_APORTIL.".tbl_menu_groupproject gp on m.id_menu_groupproject=gp.id
                  where (m.menutext like '%$keyword%' or m.menudesc like '%$keyword%') and m.isdeleted=0 $criteriaidgroupproject
                  order by m.id asc limit ".TBL_PAGE_LIMIT;
            $rs=$this->selectquery($qry);                    
            if($rs)
            {
                while($row=$this->data_row_array($rs))
                {
                    //create xml tag for grid's row
                    echo ("<row id=\"".$row["id"]."\">");
                            print("<cell>".$row["id"]."</cell>");
                            print("<cell>".$row["menuid"]."</cell>");
                            print("<cell>".$row["menutype"]."</cell>");
                            print("<cell>".$row["menuheader"]."</cell>");
                            print("<cell>".$row["menutext"]."</cell>");
                            print("<cell>".$row["menudesc"]."</cell>");
                            print("<cell>".$row["menuimg"]."</cell>");
                            print("<cell>".$row["objoption"]."</cell>");
                            print("<cell>".$row["objname"]."</cell>");
                            print("<cell>".$row["objtask"]."</cell>");
                            print("<cell>".$row["objtarget"]."</cell>");
                            print("<cell>".$row["menuorder"]."</cell>");
                            print("<cell>".$row["menugroup"]."</cell>");
                            print("<cell>".$row["groupname"]."</cell>");
                            print("<cell>".$row["id_menu_groupproject"]."</cell>");
                            print("<cell>".$row["menuactivated"]."</cell>");
                    print("</row>");
                }
            }
            else
            {
                //error occurs
                echo mysql_errno().": ".mysql_error()." at ".__LINE__." line in ".__FILE__." file<br>";
            }
            echo "</rows>";
    
        }
        
        public function fn_updatemenuTest()
        {
            //include XML Header (as response will be in xml format)
            header("Content-type: text/xml");
            //encoding may differ in your case
            echo('<?xml version="1.0" encoding="iso-8859-1"?>'); 


            $mode = $_GET["!nativeeditor_status"]; //get request mode
            $rowId = $_GET["gr_id"]; //id or row which was updated 
            $newId = $_GET["gr_id"]; //will be used for insert operation

            switch($mode)
            {
                case "inserted":
                    //row adding request
                    //$action = add_row();
                    $action = "insert";
                break;
                case "deleted":
                    //row deleting request
                    $action = "delete";//delete_row();
                break;
                default:
                    //row updating request
//                    $qry="update ".DB_APORTIL.".tbl_menu 
//                          set menuid='".$_GET["c1"]."',menutype='".$_GET["c2"]."',menuheader='".$_GET["c3"]."',menutext='".$_GET["c4"]."',menudesc='".$_GET["c5"]."', 
//                              menuimg='".$_GET["c6"]."',objoption='".$_GET["c7"]."',objname='".$_GET["c8"]."',objtask='".$_GET["c9"]."',objtarget='".$_GET["c10"]."',
//                              menuorder='".$_GET["c11"]."',menugroup='".$_GET["c12"]."',menuactivated='".$_GET["c13"]."',uby='".$_POST["kduser"]."',udt=now()
//                          where id='".$_GET["gr_id"]."'";
                    $qry="update ".DB_APORTIL.".tbl_menu 
                          set menuid='".$_GET["c1"]."',menutype='".$_GET["c2"]."',menuheader='".$_GET["c3"]."',menutext='".$_GET["c4"]."',menudesc='".$_GET["c5"]."', 
                              menuimg='".$_GET["c6"]."',objoption='".$_GET["c7"]."',objname='".$_GET["c8"]."',objtask='".$_GET["c9"]."',objtarget='".$_GET["c10"]."',
                              menuorder='".$_GET["c11"]."',menugroup='".$_GET["c12"]."',menuactivated='".$_GET["c13"]."',uby='".$_POST["kduser"]."',udt=now()
                          where id='".$_GET["gr_id"]."'";
                    $action = "update";
                break;
            }
            $this->executequery($qry);


            //output update results
            echo "<data>";
            echo "<action type='".$action."' sid='".$rowId."' tid='".$newId."'/>";
            echo "</data>";

        }
        
        public function fn_updatemenu()
        {
            $tipemenu=$_REQUEST["tipemenu"];
            $keyword=$_REQUEST["keyword"];
            $con=mysql_connect(DB_HOST_NAME,DB_USER_NAME,DB_USER_PASS);
                 mysql_select_db(DB_APORTIL);

            require(PATH_THEME."/connector/codebase/grid_connector.php");
            $grid = new GridConnector($con);
            
            //$config = new GridConfiguration();
            //$config->setHeader("id,menutext,menu");
            //$config->setColTypes("ro,ed,ed,ed,ed,ed,ed,ed");
            //$grid->set_config($config);
            
            //$grid->render_table("tbl_menu","id","id,menutext,menudesc,menuactivated");    
            $qry="select * from ".DB_APORTIL.".tbl_".$tipemenu."menu 
                  where (menutext like '%$keyword%' or menudesc like '%$keyword%') and isdeleted=0
                  order by id asc limit ".TBL_PAGE_LIMIT;
                  
            $qry="select m.id,m.menuid,m.menutype,m.menuheader,m.menutext,m.menudesc,m.menuimg,m.objoption,m.id_menu_groupproject,
                         m.objname,m.objtask,m.objtarget,m.menuorder,m.menugroup,gp.id idgroupproject,gp.groupname,m.menuactivated
                  from ".DB_APORTIL.".tbl_".$tipemenu."menu m inner join ".DB_APORTIL.".tbl_menu_groupproject gp on m.id_menu_groupproject=gp.id
                  where (m.menutext like '%$keyword%' or m.menudesc like '%$keyword%') and m.isdeleted=0
                  order by m.id asc limit ".TBL_PAGE_LIMIT;
            //$grid->event->attach("beforeDelete","Function");            
            //$grid->sql->attach("Delete","update ".DB_APORTIL.".tbl_menu set isdeleted=1,dby='".$_SESSION['nik']."',ddt=now() where id={id}");
            $qryupd="update ".DB_APORTIL.".tbl_".$tipemenu."menu 
                     set menuid='{menuid}',menutype='{menutype}',menuheader='{menuheader}',menutext='{menutext}',menudesc='{menudesc}', 
                         menuimg='{menuimg}',objoption='{objoption}',objname='{objname}',objtask='{objtask}',objtarget='{objtarget}',
                         menuorder='{menuorder}',menugroup='{menugroup}',id_menu_groupproject='{id_menu_groupproject}',menuactivated='{menuactivated}',uby='".$_SESSION['nik']."',udt=now()
                     where id={id}";
            $grid->sql->attach("Update",$qryupd);
            $grid->sql->attach("Delete","update ".DB_APORTIL.".tbl_".$tipemenu."menu set isdeleted=1,dby='".$_SESSION['nik']."',ddt=now() where id={id}");
                        
            $grid->render_sql("$qry","id","id,menuid,menutype,menuheader,menutext,menudesc,menuimg,objoption,objname,objtask,objtarget,menuorder,menugroup,groupname,id_menu_groupproject,menuactivated");    
                            
        }   
        
        public function fn_iconlists()
        {
            header("Content-type: text/xml");
            echo("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 
            echo("<complete>"); 
                     echo("<option value=\"\">-</option>"); 
                     $qry="select imgname img,imgname,imgname gif from ".DB_APORTIL.".tbl_menu_img where isdeleted=0 order by id asc";
                     $rsimg=$this->selectquery($qry);
                     if($rsimg)
                     {
                         while($rw=$this->data_row_object($rsimg))
                         {
                             //echo("<option value=\"".$rw->img."\" img_src=\"".$rw->imgname."\">".$rw->imgname."</option>"); 
                             echo("<option value=\"".$rw->img."\">".$rw->imgname."</option>"); 
                         }
                     }
                     $this->clearrecordset($rsimg);
            echo("</complete>"); 
            
        }
        
        public function fn_cbomenugroupproject()
        {
            header("Content-type: text/xml");
            echo("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 
            echo("<complete>"); 
                     echo("<option value=\"\">-</option>"); 
                     $qry="select id,groupname from ".DB_APORTIL.".tbl_menu_groupproject where isdeleted=0 order by id asc";
                     $rs=$this->selectquery($qry);
                     if($rs)
                     {
                         while($rw=$this->data_row_object($rs))
                         {
                             echo("<option value=\"".$rw->id."\">".$rw->groupname."</option>"); 
                         }
                     }
                     $this->clearrecordset($rsimg);
            echo("</complete>"); 
            
        }
                                      

        
    }
?>
