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.223.159.143


Current Path : /var/www/html/collportal/custom_src/
Upload File :
Current File : //var/www/html/collportal/custom_src/assignUserMenu.php

<?php
    function qpAssignUserMenu($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;
        }
       
        $query="select instr(ftype, '{$usertype}')as ftype, fmenucode, 
                fmenuname as title, ifnull(fpath, '') as url, 
                fmainmenu from qp_masmenu where ifnull(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['menucode'] = $val['fmenucode'];
            $submenu = array();

            $qry = "select instr(ftype, '{$usertype}')as ftype, fmenucode, fmenuname as title, 
                    ifnull(fpath, '') as url, factive, fmainmenu from qp_masmenu 
                    where ifnull(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['menucode'] = $value['fmenucode'];
                    $query1 = "select instr(ftype, '{$usertype}')as ftype, fmenucode, 
                               fmenuname as title, ifnull(fpath, '') as url, factive, 
                               fmainmenu from qp_masmenu 
                               where ifnull(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['menucode'] = $v['fmenucode'];
                        array_push($innerSubmenu, $subm);
                    }  
                } 
                 
                $sub['ssubmenu'] = $innerSubmenu;
                array_push($submenu, $sub);
                  
            }
     
            $obj['submenu'] = $submenu;
            array_push($arr, $obj);
        
        }

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

    function saveQpAssignUserRight($aobj_context){
        $fusertype = $aobj_context->mobj_data["fuser"];
        $data = json_decode($aobj_context->mobj_data["data"], true);

        foreach($data as $key => $val){
            $menucode = $val['menucode'];
            $fstatus = $val['fstatus'];

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

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

            }
            else 
            {
                $qrymenucode="SELECT INSTR(ifnull(ftype, ''),'{$fusertype}') AS ftype FROM qp_masmenu WHERE fmenucode='{$menucode}'";
                $resmenucode=$aobj_context->mobj_db->GetRow($qrymenucode);
                if($resmenucode['ftype']==0){
                    $add1menucode="SELECT ifnull(ftype, '')as ftype FROM qp_masmenu WHERE fmenucode='{$menucode}' ";
                    $resadd1menucode=$aobj_context->mobj_db->GetRow($add1menucode);
                    if($resadd1menucode['ftype']==""){
                        $qrymenucode1 = "UPDATE qp_masmenu
                                        SET ftype = CONCAT(ifnull(ftype, ''), '{$fusertype}')
                                        WHERE fmenucode = '{$menucode}'";
                    }else{ $qrymenucode1 = "UPDATE qp_masmenu
                                            SET ftype = CONCAT(ifnull(ftype, ''), '*{$fusertype}')
                                            WHERE fmenucode = '{$menucode}'";
                        }
                    
                    
                    $resmenucode1=$aobj_context->mobj_db->Execute($qrymenucode1);
                    
                 }
            }

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

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

                     
                        
                        // if($removeonesmenucode['ftype'] == "1"){
                        //     $rmsmenucode="UPDATE qp_masmenu
                        //     set ftype=''
                        //     WHERE fmenucode = '{$smenucode}' and ftype='{$fusertype}'";
                        //     }else{
                                $rmsmenucode="UPDATE qp_masmenu
                                set ftype=TRIM(BOTH '*' FROM REPLACE(REPLACE(REPLACE(ftype, '*{$fusertype}', ''), '{$fusertype}*', ''), '{$fusertype}', ''))
                                WHERE fmenucode = '{$smenucode}' and fmainmenu='{$val['menucode']}'";

                        // }



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

                            if($resadd1smenucode['ftype'] == ""){
                                $qrysmenucode1 = "UPDATE qp_masmenu
                                                SET ftype = CONCAT(ifnull(ftype, ''), '{$fusertype}')
                                                WHERE fmenucode = '{$smenucode}'  and fmainmenu='{$val['menucode']}'";

                            }else{ $qrysmenucode1 = "UPDATE qp_masmenu
                                                    SET ftype = CONCAT(ifnull(ftype, ''), '*{$fusertype}')
                                                    WHERE fmenucode = '{$smenucode}'  and fmainmenu='{$val['menucode']}'";
                                }

                            // $qrysmenucode1 = "UPDATE qp_masmenu
                            //                  SET ftype = CONCAT(ftype, '*{$fusertype}')
                            //                  WHERE fmenucode = '{$smenucode}'";
                            $ressmenucode1=$aobj_context->mobj_db->Execute($qrysmenucode1);          
                         }
                      
                     }
               
                foreach($sval['ssubmenu'] as $ssval){
               
                   $ssmenucode=$ssval['menucode'];
                   $ssfstatus=$ssval['fstatus'];
                  
                   if($ssfstatus=="F"){
                    // $removeallssmenucode= "SELECT INSTR(ftype,'{$fusertype}') AS ftype FROM qp_masmenu WHERE fmenucode='{$ssmenucode}'";
                    // $removeonessmenucode=$aobj_context->mobj_db->GetRow($removeallssmenucode);

                    // if($removeonessmenucode['ftype'] == "1"){
                    //     $rmssmenucode="UPDATE qp_masmenu
                    //     set ftype=''
                    //     WHERE fmenucode = '{$ssmenucode}' and ftype='{$fusertype}'";
                    //     }else{
                            $rmssmenucode="UPDATE qp_masmenu
                            set ftype=TRIM(BOTH '*' FROM REPLACE(REPLACE(REPLACE(ftype, '*{$fusertype}', ''), '{$fusertype}*', ''), '{$fusertype}', ''))
                            WHERE fmenucode = '{$ssmenucode}' and fmainmenu='{$val['menucode']}'";
                    // }

                   
                        // $rmssmenucode = "UPDATE qp_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 qp_masmenu WHERE fmenucode='{$ssmenucode}' and fmainmenu='{$val['menucode']}'";
                        $resssmenucode = $aobj_context->mobj_db->GetRow($qryssmenucode);
                    
                    if($resssmenucode['ftype'] == 0){

                        $add1ssmenucode="SELECT ftype FROM qp_masmenu WHERE fmenucode='{$ssmenucode}' and fmainmenu='{$val['menucode']}'";
                        $resadd1ssmenucode=$aobj_context->mobj_db->GetRow($add1ssmenucode);

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

                        // $qryssmenucode1 = "UPDATE qp_masmenu
                        //                     SET ftype = CONCAT(ftype, '*{$fusertype}')
                        //                     WHERE fmenucode = '{$ssmenucode}'";
                                     
                         $resssmenucode1=$aobj_context->mobj_db->Execute($qryssmenucode1); 
                    }
                   }
            }
           }
         
        }

        if(count($data) > 0){
            $arr['msg'] = "Succefully updated";
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "success");  
        }else{
            $arr['msg'] = "Failed to update";
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure"); 
            return;
        }
      
    }


  
?>