| 41 | | |
| | 41 | |
| | 42 | var $availableUserIDs = array(); |
| | 43 | var $availableTabledefIDs = array(); |
| | 44 | var $availableRoleIDs = array(); |
| | 45 | |
| | 46 | |
| | 47 | function populateUserArray(){ |
| | 48 | |
| | 49 | $this->availableUserIDs = array(); |
| | 50 | |
| | 51 | $querystatement = " |
| | 52 | SELECT |
| | 53 | `id` |
| | 54 | FROM |
| | 55 | `users`; |
| | 56 | "; |
| | 57 | |
| | 58 | $queryresult = $this->db->query($querystatement); |
| | 59 | |
| | 60 | $this->availableUserIDs[] = 0;//for global |
| | 61 | |
| | 62 | while($therecord = $this->db->fetchArray($queryresult)) |
| | 63 | $this->availableUserIDs[] = $therecord["id"]; |
| | 64 | |
| | 65 | }//end method --populateUserArray-- |
| | 66 | |
| | 67 | |
| | 68 | function populateRoleArray(){ |
| | 69 | |
| | 70 | $this->availableRoleIDs = array(); |
| | 71 | |
| | 72 | $querystatement = " |
| | 73 | SELECT |
| | 74 | `id` |
| | 75 | FROM |
| | 76 | `roles`; |
| | 77 | "; |
| | 78 | |
| | 79 | $queryresult = $this->db->query($querystatement); |
| | 80 | |
| | 81 | $this->availableRoleIDs[] = 0;//for global |
| | 82 | $this->availableRoleIDs[] = -100;//for admin |
| | 83 | |
| | 84 | while($therecord = $this->db->fetchArray($queryresult)) |
| | 85 | $this->availableRoleIDs[] = $therecord["id"]; |
| | 86 | |
| | 87 | |
| | 88 | }//end method --populateRoleArray-- |
| | 89 | |
| | 90 | |
| | 91 | function populateTabledefArray(){ |
| | 92 | |
| | 93 | $this->availableTabledefIDs = array(); |
| | 94 | |
| | 95 | $querystatement = " |
| | 96 | SELECT |
| | 97 | `id` |
| | 98 | FROM |
| | 99 | `tabledefs`; |
| | 100 | "; |
| | 101 | |
| | 102 | $queryresult = $this->db->query($querystatement); |
| | 103 | |
| | 104 | if($this->db->numRows($queryresult)){ |
| | 105 | while($therecord = $this->db->fetchArray($queryresult)) |
| | 106 | $this->availableTabledefIDs[] = $therecord["id"]; |
| | 107 | }else |
| | 108 | $this->availableTabledefIDs[] = "none";// so the function doesn't keep |
| | 109 | //getting called |
| | 110 | |
| | 111 | |
| | 112 | }//end method --populateRoleArray-- |
| | 113 | |
| | 114 | |
| | 115 | function verifyVariables($variables){ |
| | 116 | |
| | 117 | //table default (SCH) is sufficient |
| | 118 | if(isset($variables["type"])){ |
| | 119 | |
| | 120 | switch($variables["type"]){ |
| | 121 | |
| | 122 | case "SRT": |
| | 123 | case "SCH": |
| | 124 | break; |
| | 125 | |
| | 126 | default: |
| | 127 | $this->verifyErrors[] = "The value of `type` field is invalid. Its value must be |
| | 128 | 'SRT' or 'SCH'."; |
| | 129 | break; |
| | 130 | |
| | 131 | }//end switch |
| | 132 | |
| | 133 | }//end if |
| | 134 | |
| | 135 | //table default (0) is sufficient |
| | 136 | if(isset($variables["userid"])){ |
| | 137 | |
| | 138 | if( !$variables["userid"] || ((int) $variables["userid"] > 0) ){ |
| | 139 | |
| | 140 | if(!count($this->availableUserIDs)) |
| | 141 | $this->populateUserArray(); |
| | 142 | |
| | 143 | if(!in_array(((int)$variables["userid"]), $this->availableUserIDs)) |
| | 144 | $this->verifyErrors[] = "The `userid` field does not give an existing/acceptable user id number."; |
| | 145 | |
| | 146 | }else |
| | 147 | $this->verifyErrors[] = "The `userid` field must be a non-negative number or equivalent to 0."; |
| | 148 | |
| | 149 | }//end if |
| | 150 | |
| | 151 | //The table default is not enough, so it must be set |
| | 152 | if(isset($variables["tabledefid"])){ |
| | 153 | |
| | 154 | if(is_numeric($variables["tabledefid"]) || !$variables["tabledefid"]){ |
| | 155 | |
| | 156 | if(!count($this->availableTabledefIDs)) |
| | 157 | $this->populateTabledefArray(); |
| | 158 | |
| | 159 | if(!in_array(((int)$variables["tabledefid"]), $this->availableTabledefIDs)) |
| | 160 | $this->verifyErrors[] = "The `tabledefid` field does not give an existing/acceptable table definition id number."; |
| | 161 | }else |
| | 162 | $this->verifyErrors[] = "The `tabledefid` field must be numeric or equivalent to 0."; |
| | 163 | }else |
| | 164 | $this->verifyErrors[] = "The `tabledefid` field must be set."; |
| | 165 | |
| | 166 | //table default (0) is sufficient |
| | 167 | if(isset($variables["roleid"])){ |
| | 168 | |
| | 169 | if(is_numeric($variables["roleid"]) || !$variables["roleid"]){ |
| | 170 | |
| | 171 | if(!count($this->availableRoleIDs)) |
| | 172 | $this->populateRoleArray(); |
| | 173 | |
| | 174 | if(!in_array(((int)$variables["roleid"]), $this->availableRoleIDs)) |
| | 175 | $this->verifyErrors[] = "The `roleid` field does not give an existing/acceptable role id number."; |
| | 176 | }else |
| | 177 | $this->verifyErrors[] = "The `roleid` field must be numeric or equivalent to 0."; |
| | 178 | |
| | 179 | }//end if |
| | 180 | |
| | 181 | return parent::verifyVariables($variables); |
| | 182 | |
| | 183 | }//end method |
| | 184 | |
| | 185 | |