0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 18.224.64.51


Current Path : /var/www/oasis/src/
Upload File :
Current File : /var/www/oasis/src/assignUserMenu.php

<?php
   
    function cAssignUserMenu($aobj_context){
        $univcode = $aobj_context->mobj_data["univcode"];
        $usertype = $aobj_context->mobj_data["usertype"];
        $user = $aobj_context->mobj_data["user"];

        if ($user == ""){
            $cnd=" ";
        }else{
            $cnd=$user;
        }
        
       
        // 1) $query="select fmenucode, fmenucode as `key`, fmenuname as title, ifnull(ffunction, '') as url, 
        // fmainmenu from col_masmenu where factive ='T' and fismainmenu='T'
        // and instr(ftype, '{$cnd}') > 0";
        // 2) $query = "select fmenucode, fmenucode as `key`, fmenuname as title, ifnull(ffunction, '') as url, 
        //           fmainmenu from col_masmenu where factive ='T' and fismainmenu='T'";
        $query="SELECT INSTR(ftype,'{$user}')AS ftype, fmenucode, fmenucode AS `key`, fmenuname AS title, IFNULL(ffunction, '') AS url, 
                fmainmenu FROM col_masmenu WHERE factive ='T' AND fismainmenu='T'";
             
 
        $result = $aobj_context->mobj_db->GetAll($query);

        $arr=[];

        foreach($result as $val){
            $menuItems=[];
            if($val['ftype'] != 0){
              $val['ftype']="T";
              $obj['fstatus']=$val['ftype'];
            }else if($val['ftype'] == 0){
                $obj['fstatus']="F";
            }

            $menucode = $val['fmenucode'];
            $obj['title'] = $val['title'];
            $obj['url'] = $val['url'];  
            $obj['key']=$val['key'];
            $submenu = array();

            // $qry = "select fmenucode,fmenucode as `key`, fmenuname as title, ifnull(ffunction, '') as url, factive, fmainmenu from col_masmenu 
            //         where factive ='T' and fissubmenu='T' and fmainmenu='{$menucode}'
            //         and instr(ftype, '{$usertype}') > 0";
                    $qry = "select INSTR(ftype,'{$user}')AS ftype, fmenucode,fmenucode as `key`, fmenuname as title, ifnull(ffunction, '') as url, factive, fmainmenu from col_masmenu 
                    where factive ='T' and fissubmenu='T' and fmainmenu='{$menucode}'";
                

            $res = $aobj_context->mobj_db->GetAll($qry);

            foreach($res as $value){
                $innerSubmenu = array();
                if($menucode == $value['fmainmenu']){
                    if($value['ftype'] != 0){
                        $value['ftype']="T";
                        $sub['fstatus']=$value['ftype'];
                      }else if($value['ftype'] == 0){
                        $sub['fstatus']="F";
                      }
                    $sub['title']=$value['title'];
                    $sub['url']=$value['url'];
                    $sub['key']=$value['key'];
                    
                    // $query1 = "select fmenucode,fmenucode as `key`, fmenuname as title, ifnull(ffunction, '') as url, factive, fmainmenu from col_masmenu 
                    // where factive ='T' and fissubmenu='T' and fmainmenu='{$value['fmenucode']}'
                    // and instr(ftype, '{$usertype}') > 0";

                    $query1 = "select INSTR(ftype,'{$user}')AS ftype, fmenucode,fmenucode as `key`, fmenuname as title, ifnull(ffunction, '') as url, factive, fmainmenu from col_masmenu 
                    where factive ='T' and fissubmenu='T' and fmainmenu='{$value['fmenucode']}'";
                }
             
                $result1 = $aobj_context->mobj_db->GetAll($query1);
             
       
                    foreach($result1 as $v){
                        if($v['fmainmenu'] === $value['fmenucode']){
                            if($v['ftype'] != 0){
                                $v['ftype']="T";
                                $subm['fstatus']=$v['ftype'];
                              }else if($v['ftype'] == 0){
                                $subm['fstatus']="F";
                              }
                            $subm['title']=$v['title'];
                            $subm['url']=$v['url'];
                            $subm['key']=$v['key'];
                            array_push($innerSubmenu, $subm);
                        }  
                    } 
                 
                    $sub['ssubmenu'] = $innerSubmenu;
                    array_push($submenu, $sub);
                  
            }
     
            $obj['submenu'] = $submenu;
            array_push($arr, $obj);
        
        }

        if($result){
            $menu['menu'] = $arr;
            echo $aobj_context->mobj_output->ToJSONEnvelope($menu,0,"success");  
        }else{
            $arr['msg'] = 'Failed to load';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
        }
    }

    function saveassignuserRight($aobj_context){
   
        $collcode =$aobj_context->mobj_data['collcode'];
        $univcode =$aobj_context->mobj_data['univcode'];
        // $fuser =$aobj_context->mobj_data['fuser'];
        $fusertype =$aobj_context->mobj_data['fuser'];

        $_data = $aobj_context->mobj_data["data"];
        $data = json_decode($_data,true);
     
        foreach($data as $key => $val){
            $menucode=$val['key'];
            $fstatus=$val['fstatus'];

            if($fstatus =="F"){
               $removeallmenucode= "SELECT INSTR(ftype,'{$fusertype}') AS ftype FROM col_masmenu WHERE fmenucode='{$menucode}'";
               $removeonemenucode=$aobj_context->mobj_db->GetRow($removeallmenucode);

               if($removeonemenucode['ftype'] == "1"){
                $rmmenucode="UPDATE col_masmenu
                            set ftype=''
                            WHERE fmenucode = '{$menucode}' and ftype='{$fusertype}'";
               }else{
                $rmmenucode="UPDATE col_masmenu
                set ftype=REPLACE(REPLACE(ftype, '*{$fusertype}', ''), '{$fusertype}*', '')
                WHERE fmenucode = '{$menucode}'";
               }
               
                $resrmmenucode=$aobj_context->mobj_db->Execute($rmmenucode);

            }
            else 
            {
                $qrymenucode="SELECT INSTR(ftype,'{$fusertype}') AS ftype FROM col_masmenu WHERE fmenucode='{$menucode}'";
                $resmenucode=$aobj_context->mobj_db->GetRow($qrymenucode);
                if($resmenucode['ftype']==0){
                    $add1menucode="SELECT ftype FROM col_masmenu WHERE fmenucode='{$menucode}' ";
                    $resadd1menucode=$aobj_context->mobj_db->GetRow($add1menucode);
                    if($resadd1menucode['ftype']==""){
                        $qrymenucode1 = "UPDATE col_masmenu
                                        SET ftype = CONCAT(ftype, '{$fusertype}')
                                        WHERE fmenucode = '{$menucode}'";
                    }else{ $qrymenucode1 = "UPDATE col_masmenu
                                            SET ftype = CONCAT(ftype, '*{$fusertype}')
                                            WHERE fmenucode = '{$menucode}'";
                        }
                    
                    
                    $resmenucode1=$aobj_context->mobj_db->Execute($qrymenucode1);          
                 }else{
                    $arr['msg']="Already Have Rights";
                    echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");  
                 }
            }

            
            foreach($val['submenu'] as $sval){
              
                     $smenucode=$sval['key'];
                     $sfstatus=$sval['fstatus'];

                     if($sfstatus =="F"){
                        $removeallsmenucode= "SELECT INSTR(ftype,'{$fusertype}') AS ftype FROM col_masmenu WHERE fmenucode='{$smenucode}'";
                        $removeonesmenucode=$aobj_context->mobj_db->GetRow($removeallsmenucode);

                     
                        
                        if($removeonesmenucode['ftype'] == "1"){
                            $rmsmenucode="UPDATE col_masmenu
                            set ftype=''
                            WHERE fmenucode = '{$smenucode}' and ftype='{$fusertype}'";
                            }else{
                                $rmsmenucode="UPDATE col_masmenu
                                set ftype=REPLACE(REPLACE(ftype, '*{$fusertype}', ''), '{$fusertype}*', '')
                                WHERE fmenucode = '{$smenucode}'";
                        }


                        // $rmsmenucode="UPDATE col_masmenu
                        //              set ftype=REPLACE(REPLACE(ftype, '*{$fusertype}', ''), '{$fusertype}*', '')
                        //              WHERE fmenucode = '{$smenucode}'";
                                   
                        $resrmsmenucode=$aobj_context->mobj_db->Execute($rmsmenucode);
                     }else{
                        $qrysmenucode="SELECT INSTR(ftype,'{$fusertype}') AS ftype FROM col_masmenu WHERE fmenucode='{$smenucode}'";
                        $ressmenucode=$aobj_context->mobj_db->GetRow($qrysmenucode);
                        
                        if($ressmenucode['ftype']==0){
                            $add1smenucode="SELECT ftype FROM col_masmenu WHERE fmenucode='{$smenucode}' ";
                            $resadd1smenucode=$aobj_context->mobj_db->GetRow($add1smenucode);

                            if($resadd1smenucode['ftype']==""){
                                $qrysmenucode1 = "UPDATE col_masmenu
                                                SET ftype = CONCAT(ftype, '{$fusertype}')
                                                WHERE fmenucode = '{$smenucode}'";
                            }else{ $qrysmenucode1 = "UPDATE col_masmenu
                                                    SET ftype = CONCAT(ftype, '*{$fusertype}')
                                                    WHERE fmenucode = '{$smenucode}'";
                                }

                            // $qrysmenucode1 = "UPDATE col_masmenu
                            //                  SET ftype = CONCAT(ftype, '*{$fusertype}')
                            //                  WHERE fmenucode = '{$smenucode}'";
                            $ressmenucode1=$aobj_context->mobj_db->Execute($qrysmenucode1);          
                         }else{
                            $arr['msg']="Already Have Rights";
                            echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");  
                         }
                      
                     }
               
                foreach($sval['ssubmenu'] as $ssval){
               
                   $ssmenucode=$ssval['key'];
                   $ssfstatus=$ssval['fstatus'];
                  
                   if($ssfstatus=="F"){
                    $removeallssmenucode= "SELECT INSTR(ftype,'{$fusertype}') AS ftype FROM col_masmenu WHERE fmenucode='{$ssmenucode}'";
                    $removeonessmenucode=$aobj_context->mobj_db->GetRow($removeallssmenucode);

                    if($removeonessmenucode['ftype'] == "1"){
                        $rmssmenucode="UPDATE col_masmenu
                        set ftype=''
                        WHERE fmenucode = '{$ssmenucode}' and ftype='{$fusertype}'";
                        }else{
                            $rmssmenucode="UPDATE col_masmenu
                            set ftype=REPLACE(REPLACE(ftype, '*{$fusertype}', ''), '{$fusertype}*', '')
                            WHERE fmenucode = '{$ssmenucode}'";
                    }

                   
                        // $rmssmenucode = "UPDATE col_masmenu
                        //                 set ftype=REPLACE(REPLACE(ftype, '*{$fusertype}', ''), '{$fusertype}*', '')
                        //                 WHERE fmenucode = '{$ssmenucode}'";
                                     
                        $resrmssmenucode=$aobj_context->mobj_db->Execute($rmssmenucode);
                   }else{
                  
                        $qryssmenucode = "SELECT INSTR(ftype,'{$fusertype}') AS ftype FROM col_masmenu WHERE fmenucode='{$ssmenucode}'";
                        $resssmenucode = $aobj_context->mobj_db->GetRow($qryssmenucode);
                    
                    if($resssmenucode['ftype'] == 0){

                        $add1ssmenucode="SELECT ftype FROM col_masmenu WHERE fmenucode='{$ssmenucode}' ";
                        $resadd1ssmenucode=$aobj_context->mobj_db->GetRow($add1ssmenucode);

                        if($resadd1ssmenucode['ftype']==""){
                            $qryssmenucode1 = "UPDATE col_masmenu
                                            SET ftype = CONCAT(ftype, '{$fusertype}')
                                            WHERE fmenucode = '{$ssmenucode}'";
                        }else{ $qryssmenucode1 = "UPDATE col_masmenu
                                                SET ftype = CONCAT(ftype, '*{$fusertype}')
                                                WHERE fmenucode = '{$ssmenucode}'";
                            }

                        // $qryssmenucode1 = "UPDATE col_masmenu
                        //                     SET ftype = CONCAT(ftype, '*{$fusertype}')
                        //                     WHERE fmenucode = '{$ssmenucode}'";
                                     
                         $resssmenucode1=$aobj_context->mobj_db->Execute($qryssmenucode1); 
                    }else{
                        $arr['msg']="Already Have Rights";
                        echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");  
                    }
                   }
            }
           }
         
        }

        
      
    }

  
?>