Changeset 485 for trunk/phpbms/modules/base/include/menu.php
- Timestamp:
- 04/07/09 11:44:18 (3 years ago)
- Files:
-
- 1 modified
-
trunk/phpbms/modules/base/include/menu.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpbms/modules/base/include/menu.php
r285 r485 39 39 if(class_exists("phpbmsTable")){ 40 40 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){ 43 153 switch($variables["radio"]){ 44 154 case "cat": … … 52 162 default: 53 163 } 54 164 55 165 return $variables; 56 166 } 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 75 169 function displayTableDropDown($selectedlink){ 76 170 77 171 $querystatement="select id, displayname from tabledefs order by displayname"; 78 172 $thequery=$this->db->query($querystatement); 79 173 80 174 echo "<select id=\"linkdropdown\" name=\"linkdropdown\">\n"; 81 175 while($therecord=$this->db->fetchArray($thequery)){ 82 176 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"]) 85 179 echo "selected=\"selected\""; 86 180 87 181 echo " >".$therecord["displayname"]."</option>\n"; 88 182 } 89 183 echo "</select>\n"; 90 184 91 185 }//end method 92 93 186 187 94 188 function displayParentDropDown($selectedpid,$id=0){ 95 189 96 190 if($id=="")$id=0; 97 191 $querystatement="SELECT id, name FROM menu WHERE id!=".$id." and parentid=0 and (link=\"\" or link is null) ORDER BY displayorder"; 98 192 $thequery=$this->db->query($querystatement); 99 193 100 194 echo "<select name=\"parentid\" id=\"parentid\">\n"; 101 195 echo "<option value=\"0\" "; 102 196 103 197 if ($selectedpid=="0") 104 198 echo "selected=\"selected\""; 105 199 106 200 echo " >-- none --</option>\n"; 107 201 while($therecord=$this->db->fetchArray($thequery)){ 108 202 echo "<option value=\"".$therecord["id"]."\" "; 109 if ($selectedpid==$therecord["id"]) 203 if ($selectedpid==$therecord["id"]) 110 204 echo "selected=\"selected\""; 111 205 112 206 echo " >".$therecord["name"]."</option>\n"; 113 207 } 114 208 echo "</select>\n"; 115 209 116 210 }//end method 117 211 118 212 }//end class 119 213 }//end if … … 122 216 if(class_exists("searchFunctions")){ 123 217 class menuSearchFunctions extends searchFunctions{ 124 218 125 219 function delete_record(){ 126 220 127 221 //passed variable is array of user ids to be revoked 128 222 $whereclause = $this->buildWhereClause(); 129 223 $verifywhereclause = $this->buildWhereClause("menu.parentid"); 130 224 131 225 $querystatement = "SELECT id FROM menu WHERE ".$verifywhereclause; 132 226 $queryresult = $this->db->query($querystatement); … … 136 230 $queryresult = $this->db->query($querystatement); 137 231 } 138 232 139 233 $message=$this->buildStatusMessage(); 140 234 $message.=" deleted."; 141 235 return $message; 142 236 } 143 237 144 238 }//end class 145 239 }//end if