phpBMS

Show
Ignore:
Timestamp:
04/07/09 11:44:18 (3 years ago)
Author:
nate
Message:
  • Merged Nathan branch back into trunk.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/modules/base/include/menu.php

    r285 r485  
    3939if(class_exists("phpbmsTable")){ 
    4040        class menus extends phpbmsTable{ 
    41          
    42                 function formatVariables($variables){ 
     41 
     42                var $availableRoleIDs = array(); 
     43 
     44                function checkParentMenuIDs($currentID = 0, $parentID = 0){ 
     45 
     46                        //cannot be own parent 
     47                        $currentID = ((int) $currentID); 
     48                        //current setting of the parentid 
     49                        $parentID = ((int) $parentID); 
     50 
     51                        if(!$parentID) 
     52                                return true; 
     53 
     54                        $querystatement = " 
     55                                SELECT 
     56                                        `id` 
     57                                FROM 
     58                                        `menu` 
     59                                WHERE 
     60                                        `id` = '".$parentID."' 
     61                                        AND 
     62                                        `id`!='".$currentID."' 
     63                                        AND 
     64                                        `parentid` = '0' 
     65                                        AND 
     66                                        ( 
     67                                                `link` = '' 
     68                                                OR 
     69                                                `link` IS NULL 
     70                                        ) 
     71                                        ; 
     72                                "; 
     73 
     74                        $queryresult = $this->db->query($querystatement); 
     75 
     76                        return $this->db->numRows($queryresult); 
     77 
     78                }//end method --getParentMenuIDs-- 
     79 
     80                //pouplate the id roles array 
     81                function populateRoleArray(){ 
     82 
     83                        $this->availableRoleIDs = array(); 
     84 
     85                        $querystatement = " 
     86                                SELECT 
     87                                        `id` 
     88                                FROM 
     89                                        `roles`; 
     90                                "; 
     91 
     92                        $queryresult = $this->db->query($querystatement); 
     93 
     94                        $this->availableRoleIDs[] = 0;//for everyone 
     95                        $this->availableRoleIDs[] = -100;//for admin 
     96 
     97 
     98                        while($therecord = $this->db->fetchArray($queryresult)) 
     99                                $this->availableRoleIDs[] = $therecord["id"]; 
     100 
     101                }//end method --populateRoleArray()-- 
     102 
     103 
     104                function verifyVariables($variables){ 
     105 
     106                        //table default (0) for `roleid` is ok (i.e. doesn't have to be set) 
     107                        if(isset($variables["roleid"])){ 
     108 
     109                                //can either be numeric or equivalent to 0 
     110                                if(is_numeric($variables["roleid"]) || !$variables["roleid"]){ 
     111 
     112                                        //check for populated role id array 
     113                                        if(!count($this->availableRoleIDs)) 
     114                                                $this->populateRoleArray(); 
     115 
     116                                        //check to see if the int typecast role id is in one of the available ones 
     117                                        if(!in_array(((int)$variables["roleid"]), $this->availableRoleIDs)) 
     118                                                $this->verifyErrors[] = "The `roleid` field does not give an existing/acceptable role id number."; 
     119                                }else 
     120                                        $this->verifyErrors[] = "The `roleid` field must be numeric or equivalent to 0."; 
     121 
     122                        }//end if 
     123 
     124                        //check parent ids under certain circumstances 
     125                        //not set is acceptable 
     126                        if(isset($variables["parentid"])){ 
     127 
     128                                //can be either numeric or equivalent to 0 and its int typecast must be non-negative 
     129                                if( !$variables["parentid"] || ((int)$variables["parentid"]) > 0 ){ 
     130 
     131                                        $id = 0; 
     132 
     133                                        //use the current id if it exists (A menu record cannot be its own parent) 
     134                                        if(isset($variables["id"])) 
     135                                                if(is_numeric($variables["id"]) && ((int) $variables["id"]) > 0) 
     136                                                        $id = $variables["id"]; 
     137 
     138                                        //Select run every time because `id` can be different 
     139                                        if( !$this->checkParentMenuIDs($id, ((int) $variables["parentid"])) ) 
     140                                                $this->verifyErrors[] = "The `parentid` field does not give an existing/acceptable parent id number."; 
     141 
     142                                }else 
     143                                        $this->verifyErrors[] = "The `roleid` field must be a non-negative number or equivalent to 0."; 
     144 
     145                        }//end if 
     146 
     147                        return parent::verifyVariables($variables); 
     148 
     149                }//end method --verifyVariables-- 
     150 
     151 
     152                function prepareVariables($variables){ 
    43153                        switch($variables["radio"]){ 
    44154                                case "cat": 
     
    52162                                default: 
    53163                        } 
    54                  
     164 
    55165                        return $variables; 
    56166                } 
    57          
    58                  
    59                 function updateRecord($variables, $modifiedby = NULL){ 
    60                          
    61                         $variables = $this->formatVariables($variables); 
    62                  
    63                         parent::updateRecord($variables, $modifiedby); 
    64                 } 
    65          
    66          
    67                 function insertRecord($variables, $createdby = NULL){ 
    68                          
    69                         $variables = $this->formatVariables($variables); 
    70                  
    71                         return parent::insertRecord($variables, $createdby ); 
    72                 } 
    73          
    74          
     167 
     168 
    75169                function displayTableDropDown($selectedlink){ 
    76          
     170 
    77171                        $querystatement="select id, displayname from tabledefs order by displayname"; 
    78172                        $thequery=$this->db->query($querystatement); 
    79                          
     173 
    80174                        echo "<select id=\"linkdropdown\" name=\"linkdropdown\">\n"; 
    81175                        while($therecord=$this->db->fetchArray($thequery)){ 
    82176                                echo "<option value=\"search.php?id=".$therecord["id"]."\" "; 
    83          
    84                                 if ($selectedlink == "search.php?id=".$therecord["id"])  
     177 
     178                                if ($selectedlink == "search.php?id=".$therecord["id"]) 
    85179                                        echo "selected=\"selected\""; 
    86          
     180 
    87181                                echo " >".$therecord["displayname"]."</option>\n"; 
    88182                        } 
    89183                        echo "</select>\n"; 
    90                  
     184 
    91185                }//end method 
    92                  
    93                  
     186 
     187 
    94188                function displayParentDropDown($selectedpid,$id=0){ 
    95          
     189 
    96190                        if($id=="")$id=0; 
    97191                        $querystatement="SELECT id, name FROM menu WHERE id!=".$id." and parentid=0 and (link=\"\" or link is null) ORDER BY displayorder"; 
    98192                        $thequery=$this->db->query($querystatement); 
    99          
     193 
    100194                        echo "<select name=\"parentid\" id=\"parentid\">\n"; 
    101195                        echo "<option value=\"0\" "; 
    102          
     196 
    103197                        if ($selectedpid=="0") 
    104198                                echo "selected=\"selected\""; 
    105                                  
     199 
    106200                        echo " >-- none --</option>\n"; 
    107201                        while($therecord=$this->db->fetchArray($thequery)){ 
    108202                                echo "<option value=\"".$therecord["id"]."\" "; 
    109                                 if ($selectedpid==$therecord["id"])  
     203                                if ($selectedpid==$therecord["id"]) 
    110204                                        echo "selected=\"selected\""; 
    111          
     205 
    112206                                echo " >".$therecord["name"]."</option>\n"; 
    113207                        } 
    114208                        echo "</select>\n"; 
    115                          
     209 
    116210                }//end method 
    117          
     211 
    118212        }//end class 
    119213}//end if 
     
    122216if(class_exists("searchFunctions")){ 
    123217        class menuSearchFunctions extends searchFunctions{ 
    124          
     218 
    125219                function delete_record(){ 
    126                          
     220 
    127221                        //passed variable is array of user ids to be revoked 
    128222                        $whereclause = $this->buildWhereClause(); 
    129223                        $verifywhereclause = $this->buildWhereClause("menu.parentid"); 
    130                          
     224 
    131225                        $querystatement = "SELECT id FROM menu WHERE ".$verifywhereclause; 
    132226                        $queryresult = $this->db->query($querystatement); 
     
    136230                                $queryresult = $this->db->query($querystatement); 
    137231                        } 
    138                          
     232 
    139233                        $message=$this->buildStatusMessage(); 
    140234                        $message.=" deleted."; 
    141235                        return $message; 
    142236                } 
    143          
     237 
    144238        }//end class 
    145239}//end if 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.