Changeset 485 for trunk/phpbms/modules/base/include/users.php
- Timestamp:
- 04/07/09 11:44:18 (3 years ago)
- Files:
-
- 1 modified
-
trunk/phpbms/modules/base/include/users.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpbms/modules/base/include/users.php
r427 r485 39 39 if(class_exists("phpbmsTable")){ 40 40 class users extends phpbmsTable{ 41 42 function updateRecord($variables, $modifiedby = NULL){ 43 41 42 var $usedLoginNames = array(); 43 44 function populateLoginNameArray(){ 45 46 $querystatement=" 47 SELECT 48 `id`, 49 `login` 50 FROM 51 `users`; 52 "; 53 54 $queryresult = $this->db->query($querystatement); 55 56 if($this->db->numRows($queryresult)){ 57 while($therecord = $this->db->fetchArray($queryresult)){ 58 59 $login = $therecord["login"]; 60 $id = $therecord["id"]; 61 $this->usedLoginNames[$login]["id"] = $id; 62 63 }//end while 64 }else{ 65 //if no valid login names, I put in a value that will 66 //give the arrays a count but not actually match any realistic login names 67 $login = "THIS is @ ve|2`/ D|_||\/|B |_0GI|\| and stupid too."; 68 $id = -1; 69 70 $this->usedLoginNames[$login]["id"] = $id; 71 }//end if 72 73 }//end method 74 75 76 function verifyVariables($variables){ 77 //---------[ check login names ]------------------------------ 78 79 if(isset($variables["login"])){ 80 if( $variables["login"] !== "" || $variables["login"] !== NULL ){ 81 82 if(!count($this->usedLoginNames)) 83 $this->populateLoginNameArray(); 84 85 if(!isset($variables["id"])) 86 $variables["id"] = 0; 87 88 if($variables["id"] < 0) 89 $variables["id"] = 0; 90 91 //check to see new login name is taken 92 $templogin = $variables["login"];// using this because it looks ugly to but the brackets within brackets 93 if( array_key_exists($variables["login"], $this->usedLoginNames) ){ 94 95 if( $this->usedLoginNames[$templogin]["id"] !== $variables["id"] ) 96 $this->verifyErrors[] = "The `login` field must give an unique login name."; 97 98 }else{ 99 $this->availableProducts[$templogin]["id"] = -1;// impossible id put in (besides the type will through off the if anyways) 100 }//end if 101 102 }else 103 $this->verifyErrors[] = "The `login` field must not be blank."; 104 }else 105 $this->verifyErrors[] = "The `login` field must be set."; 106 107 //---------[ check email ]--------------------------------- 108 if(isset($variables["email"])) 109 if( $variables["email"] !== NULL && $variables["email"] !== "" && !validateEmail($variables["email"])) 110 $this->verifyErrors[] = "The `email` field must have a valid email or must be left blank."; 111 112 //---------[ check booleans ]--------------------------------- 113 if(isset($variables["revoked"])) 114 if($variables["revoked"] && $variables["revoked"] != 1) 115 $this->verifyErrors[] = "The `revoked` field must be a boolean (equivalent to 0 or exactly 1)."; 116 117 if(isset($variables["portalaccess"])) 118 if($variables["portalaccess"] && $variables["portalaccess"] != 1) 119 $this->verifyErrors[] = "The `portalaccess` field must be a boolean (equivalent to 0 or exactly 1)."; 120 121 if(isset($variables["admin"])) 122 if($variables["admin"] && $variables["admin"] != 1) 123 $this->verifyErrors[] = "The `admin` field must be a boolean (equivalent to 0 or exactly 1)."; 124 125 return parent::verifyVariables($variables); 126 127 }//end method --verifyVariables-- 128 129 130 function updateRecord($variables, $modifiedby = NULL){ 131 44 132 if($variables["password"]) 45 133 $this->fields["password"]["type"] = "password"; … … 48 136 49 137 unset($this->fields["lastlogin"]); 50 138 51 139 parent::updateRecord($variables, $modifiedby); 52 140 53 141 if($variables["roleschanged"]==1) 54 142 $this->assignRoles($variables["id"],$variables["newroles"]); 55 143 56 144 //reset field information 57 145 $this->fields = $this->db->tableInfo($this->maintable); 58 146 } 59 147 60 61 function insertRecord($variables, $createdby = NULL){ 62 148 149 function insertRecord($variables, $createdby = NULL){ 150 63 151 $this->fields["password"]["type"] = "password"; 64 152 unset($this->fields["lastlogin"]); 65 153 66 154 $theid = parent::insertRecord($variables, $createdby); 67 155 68 156 //reset field information 69 157 $this->fields = $this->db->tableInfo($this->maintable); … … 71 159 return $theid; 72 160 } 73 161 74 162 function assignRoles($id,$roles){ 75 163 $querystatement="DELETE FROM rolestousers WHERE userid=".$id; 76 164 $queryresult=$this->db->query($querystatement); 77 165 78 166 $newroles=explode(",",$roles); 79 167 80 168 foreach($newroles as $therole) 81 169 if($therole!=""){ … … 84 172 } 85 173 } 86 87 174 175 88 176 function displayRoles($id,$type){ 89 177 $querystatement="SELECT roles.id,roles.name 90 FROM roles INNER JOIN rolestousers ON rolestousers.roleid=roles.id 178 FROM roles INNER JOIN rolestousers ON rolestousers.roleid=roles.id 91 179 WHERE rolestousers.userid=".((int) $id); 92 180 $assignedquery=$this->db->query($querystatement); 93 181 94 182 $thelist=array(); 95 183 96 184 if($type=="available"){ 97 185 $excludelist=array(); 98 186 while($therecord=$this->db->fetchArray($assignedquery)) 99 187 $excludelist[]=$therecord["id"]; 100 188 101 189 $querystatement="SELECT id,name FROM roles WHERE inactive=0"; 102 190 $availablequery=$this->db->query($querystatement); 103 191 while($therecord=$this->db->fetchArray($availablequery)) 104 192 if(!in_array($therecord["id"],$excludelist)) 105 $thelist[]=$therecord; 106 } else 193 $thelist[]=$therecord; 194 } else 107 195 while($therecord=$this->db->fetchArray($assignedquery)) 108 196 $thelist[]=$therecord; 109 197 110 198 foreach($thelist as $theoption){ 111 199 ?> <option value="<?php echo $theoption["id"]?>"><?php echo htmlQuotes($theoption["name"])?></option> 112 <?php 200 <?php 113 201 } 114 202 }//end function … … 120 208 121 209 function delete_record(){ 122 210 123 211 //passed variable is array of user ids to be revoked 124 212 $whereclause = $this->buildWhereClause(); 125 213 126 214 $querystatement = "UPDATE users SET revoked=1,modifiedby=".$_SESSION["userinfo"]["id"]." WHERE ".$whereclause.";"; 127 215 $queryresult = $this->db->query($querystatement); 128 216 129 217 $message = $this->buildStatusMessage(); 130 218 $message.=" revoked access."; 131 return $message; 132 } 133 134 219 return $message; 220 } 221 222 135 223 }//end class 136 224 }//end if