Commit 4cc2036fafd62bc90d237a437346915e44cd692e
1 parent
77834f5f
reformatted
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1127 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
417 additions
and
425 deletions
lib/users/User.inc
| ... | ... | @@ -9,407 +9,402 @@ |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | class User { |
| 12 | - | |
| 13 | - /** object primary key */ | |
| 14 | - var $iId; | |
| 15 | - /** user's login name */ | |
| 16 | - var $sUserName; | |
| 17 | - /** user's name (first and last) */ | |
| 18 | - var $sName; | |
| 19 | - /** user's password */ | |
| 20 | - var $sPassword; | |
| 21 | - /** user's maximum allowed file storage quota in bytes */ | |
| 22 | - var $iQuotaMax; | |
| 23 | - /** user's current file storage quota in bytes */ | |
| 24 | - var $iQuotaCurrent; | |
| 25 | - /** user's email address */ | |
| 26 | - var $sEmail; | |
| 27 | - /** user's mobile phone number */ | |
| 28 | - var $sMobile; | |
| 29 | - /** notify user by mail status */ | |
| 30 | - var $bEmailNotification; | |
| 31 | - /** notify user via sms (mobile phone) status */ | |
| 32 | - var $bSmsNotification; | |
| 33 | - /** user's ldap identification */ | |
| 34 | - var $sLdapDn; | |
| 35 | - /** maxiumum concurrent sessions user may have */ | |
| 36 | - var $iMaxSessions; | |
| 37 | - /** primary key of language preferred by user */ | |
| 38 | - var $iLanguageID; | |
| 39 | - /** internal variable used to determine if the password has changed or not */ | |
| 40 | - var $bPasswordChanged; | |
| 41 | - | |
| 42 | - function User($sNewUserName, $sNewName, $sNewPassword, $iNewQuotaMax, $sNewEmail, $sNewMobile, $bNewEmailNotification, $bNewSmsNotification, $sNewLdapDn, $iNewMaxSessions, $iNewLanguageID) { | |
| 43 | - //object not created in database yet | |
| 44 | - $this->iId = -1; | |
| 45 | - $this->sUserName = $sNewUserName; | |
| 46 | - $this->sName = $sNewName; | |
| 47 | - $this->sPassword = $sNewPassword; | |
| 48 | - $this->iQuotaMax = $iNewQuotaMax; | |
| 49 | - $this->sEmail = $sNewEmail; | |
| 50 | - $this->sMobile = $sNewMobile; | |
| 51 | - $this->bEmailNotification = $bNewEmailNotification; | |
| 52 | - $this->bSmsNotification = $bNewSmsNotification; | |
| 53 | - $this->sLdapDn = $sNewLdapDn; | |
| 54 | - $this->iMaxSessions = $iNewMaxSessions; | |
| 55 | - $this->iLanguageID = $iNewLanguageID; | |
| 56 | - $this->bPasswordChanged = false; | |
| 57 | - } | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * Get the object's primary key | |
| 61 | - * | |
| 62 | - * @return int object's primary key | |
| 63 | - * | |
| 64 | - */ | |
| 65 | - function getID() { | |
| 66 | - return $this->iId; | |
| 67 | - } | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * Get the user's login name | |
| 71 | - * | |
| 72 | - * @return String user's login name | |
| 73 | - * | |
| 74 | - */ | |
| 75 | - function getUserName() { | |
| 76 | - return $this->sUserName; | |
| 77 | - } | |
| 78 | - | |
| 79 | - /** | |
| 80 | - * Set the user's login name | |
| 81 | - * | |
| 82 | - * @param String New user login name | |
| 83 | - * | |
| 84 | - */ | |
| 85 | - function setUserName($sNewValue) { | |
| 86 | - $this->sUserName = $sNewValue; | |
| 87 | - } | |
| 88 | - | |
| 89 | - /** | |
| 90 | - * Set the user's password | |
| 91 | - * | |
| 92 | - * @param String New user password | |
| 93 | - * | |
| 94 | - */ | |
| 95 | - function setPassword($sNewValue) { | |
| 96 | - $this->sPassword = $sNewValue; | |
| 97 | - $this->bPasswordChanged = true; | |
| 98 | - } | |
| 99 | - | |
| 100 | - /** | |
| 101 | - * Get the user's maximum disk quota | |
| 102 | - * | |
| 103 | - * @return int user's maximum disk quota | |
| 104 | - * | |
| 105 | - */ | |
| 106 | - function getQuotaMax() { | |
| 107 | - return $this->iQuotaMax; | |
| 108 | - } | |
| 109 | - | |
| 110 | - /** | |
| 111 | - * Set the user's maximum disk quota | |
| 112 | - * | |
| 113 | - * @param int User's maximum disk quota in bytes | |
| 114 | - * | |
| 115 | - */ | |
| 116 | - function setQuotaMax($iNewValue) { | |
| 117 | - $this->iQuotaMax = $iNewValue; | |
| 118 | - } | |
| 119 | - | |
| 120 | - function getName() { | |
| 121 | - return $this->sName; | |
| 122 | - } | |
| 123 | - | |
| 124 | - /** | |
| 125 | - * Get the user's currrently used quota | |
| 126 | - * | |
| 127 | - * @return int user's currently used quota | |
| 128 | - * | |
| 129 | - */ | |
| 130 | - function getQuotaCurrent() { | |
| 131 | - return $this->iQuotaCurrent; | |
| 132 | - } | |
| 133 | - | |
| 134 | - /** | |
| 135 | - * Get the user's email address | |
| 136 | - * | |
| 137 | - * @return String user's email address | |
| 138 | - * | |
| 139 | - */ | |
| 140 | - function getEmail() { | |
| 141 | - return $this->sEmail; | |
| 142 | - } | |
| 143 | - | |
| 144 | - /** | |
| 145 | - * Set the user's email address | |
| 146 | - * | |
| 147 | - * @param String User's email address | |
| 148 | - * | |
| 149 | - */ | |
| 150 | - function setEmail($sNewValue) { | |
| 151 | - $this->sEmail = $sNewValue; | |
| 152 | - } | |
| 153 | - | |
| 154 | - /** | |
| 155 | - * Get the user's mobile phone number | |
| 156 | - * | |
| 157 | - * @return String user's mobile phone number | |
| 158 | - * | |
| 159 | - */ | |
| 160 | - function getMobile() { | |
| 161 | - return $this->sMobile; | |
| 162 | - } | |
| 163 | - | |
| 164 | - /** | |
| 165 | - * Set the user's mobile phone number | |
| 166 | - * | |
| 167 | - * @param String User's mobile phone number | |
| 168 | - * | |
| 169 | - */ | |
| 170 | - function setMobile($sNewValue) { | |
| 171 | - $this->sMobile = $sNewValue; | |
| 172 | - } | |
| 173 | - | |
| 174 | - /** | |
| 175 | - * Get the user's email notification status | |
| 176 | - * | |
| 177 | - * @return boolean user's email notification status | |
| 178 | - * | |
| 179 | - */ | |
| 180 | - function getEmailNotification() { | |
| 181 | - return $this->bEmailNotification; | |
| 182 | - } | |
| 183 | - | |
| 184 | - /** | |
| 185 | - * Set the user's email notification status | |
| 186 | - * | |
| 187 | - * @param boolean User's email notification status (notify by email) | |
| 188 | - * | |
| 189 | - */ | |
| 190 | - function setEmailNotification($bNewValue) { | |
| 191 | - $this->bEmailNotification = $bNewValue; | |
| 192 | - } | |
| 193 | - | |
| 194 | - /** | |
| 195 | - * Get the user's SMS (mobile phone) notification status | |
| 196 | - * | |
| 197 | - * @return boolean SMS (mobile phone) notification status | |
| 198 | - * | |
| 199 | - */ | |
| 200 | - function getSmsNotification() { | |
| 201 | - return $this->bSmsNotification; | |
| 202 | - } | |
| 203 | - | |
| 204 | - /** | |
| 205 | - * Set the user's SMS (mobile phone) notification status | |
| 206 | - * | |
| 207 | - * @param boolean User's SMS (mobile phone) notification status (notify by mobile phone) | |
| 208 | - * | |
| 209 | - */ | |
| 210 | - function setSmsNotification($bNewValue) { | |
| 211 | - $this->bSmsNotification = $bNewValue; | |
| 212 | - } | |
| 213 | - | |
| 214 | - /** | |
| 215 | - * Get the user's LDAP distinguished name | |
| 216 | - * | |
| 217 | - * @return String user's LDAP distinguished name | |
| 218 | - * | |
| 219 | - */ | |
| 220 | - function getLdapDn() { | |
| 221 | - return $this->sLdapDn; | |
| 222 | - } | |
| 223 | - | |
| 224 | - /** | |
| 225 | - * Set the user's LDAP distinguished name | |
| 226 | - * | |
| 227 | - * @param String User's LDAP distinguished name | |
| 228 | - * | |
| 229 | - */ | |
| 230 | - function setLdapDn($sNewValue) { | |
| 231 | - $this->sLdapDn = $sNewValue; | |
| 232 | - } | |
| 233 | - | |
| 234 | - /** | |
| 235 | - * Get the user's maximum number of concurrent sessions | |
| 236 | - * | |
| 237 | - * @return int user's maximum number of concurrent sessions | |
| 238 | - * | |
| 239 | - */ | |
| 240 | - function getMaxSessions() { | |
| 241 | - return $this->iMaxSessions; | |
| 242 | - } | |
| 243 | - | |
| 244 | - /** | |
| 245 | - * Set the user's maximum number of concurrent sessions | |
| 246 | - * | |
| 247 | - * @param int User's maximum number of concurrent sessions | |
| 248 | - * | |
| 249 | - */ | |
| 250 | - function setMaxSessions($iNewValue) { | |
| 251 | - $this->iMaxSessions = $iNewValue; | |
| 252 | - } | |
| 253 | - | |
| 254 | - /** | |
| 255 | - * Get the primary key for the language preferred by the user | |
| 256 | - * | |
| 257 | - * @return int primary key of language preferred by user | |
| 258 | - * | |
| 259 | - */ | |
| 260 | - function getLanguageID() { | |
| 261 | - return $this->iLanguageIDID; | |
| 262 | - } | |
| 263 | - | |
| 264 | - /** | |
| 265 | - * Set the primary key of the language preferred by the user | |
| 266 | - * | |
| 267 | - * @param int Primary key of language preferred by user | |
| 268 | - * | |
| 269 | - */ | |
| 270 | - function setLanguageID($iNewValue) { | |
| 271 | - $this->iLanguageIDID = $iNewValue; | |
| 272 | - } | |
| 273 | - | |
| 274 | - /** | |
| 275 | - * Create the current object in the database | |
| 276 | - * | |
| 277 | - * @return boolean on successful store, false otherwise and set $_SESSION["errorMessage"] | |
| 278 | - * | |
| 279 | - */ | |
| 280 | - function create() { | |
| 281 | - global $default, $lang_err_database, $lang_err_object_exists; | |
| 282 | - //if the object hasn't been created | |
| 283 | - if ($this->iId < 0) | |
| 284 | - { | |
| 285 | - //check to see if name exsits | |
| 286 | - $sql = $default->db; | |
| 287 | - $query = "SELECT username FROM ". $default->owl_users_table ." WHERE username = '" . $this->sUserName . "'"; | |
| 288 | - $sql->query($query); | |
| 289 | - $rows = $sql->num_rows($sql); | |
| 290 | - | |
| 291 | - if ($rows > 0) | |
| 292 | - { | |
| 293 | - // duplicate username | |
| 294 | - $_SESSION["errorMessage"] = "User::The username " . $this->sUserName . " is already in use!"; | |
| 295 | - return false; | |
| 296 | - } | |
| 297 | - | |
| 298 | - else | |
| 299 | - { | |
| 300 | - $result = $sql->query("INSERT INTO " . $default->owl_users_table . " (username, name, password, quota_max, quota_current, email, mobile, email_notification, sms_notification, ldap_dn, max_sessions, language_id) " . | |
| 301 | - "VALUES ('" . addslashes($this->sUserName) . "', '" . addslashes($this->sName) . "', '" . addslashes(md5($this->sPassword)) . "', $this->iQuotaMax, 0, '" . addslashes($this->sEmail) . "', '" . addslashes($this->sMobile) . "', " . ($this->bEmailNotification ? 1 : 0) . ", " . ($this->bSmsNotification ? 1 : 0) . ", '" . addslashes($this->sLdapDn) . "', $this->iMaxSessions, $this->iLanguageID)"); | |
| 302 | - if ($result) | |
| 303 | - { | |
| 304 | - $this->iId = $sql->insert_id(); | |
| 305 | - return true; | |
| 306 | - } | |
| 307 | - $_SESSION["errorMessage"] = $lang_err_database; | |
| 308 | - return false; | |
| 309 | - } | |
| 310 | - } | |
| 311 | - $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = $default->owl_users_table"; | |
| 312 | - return false; | |
| 313 | - } | |
| 314 | - | |
| 315 | - /** | |
| 316 | - * Update the values in the database table with the object's current values | |
| 317 | - * | |
| 318 | - * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"] | |
| 319 | - * | |
| 320 | - */ | |
| 321 | - function update() { | |
| 322 | - global $default, $lang_err_database, $lang_err_object_key; | |
| 323 | - //only update if the object has been stored | |
| 324 | - if ($this->iId > 0) { | |
| 325 | - $sql = $default->db; | |
| 326 | - $result = $sql->query("UPDATE " . $default->owl_users_table . " SET username = '" . addslashes($this->sUserName) . "', name = '" . addslashes($this->sName) . "', " . ($this->bPasswordChanged ? "password = '" . addslashes(md5($this->sPassword)) . "', " : " ") . " quota_max = $this->iQuotaMax, email = '" . addslashes($this->sEmail) . "', mobile = '" . addslashes($this->sMobile) . "', email_notification = " . ($this->bEmailNotification ? 1 : 0) . ", sms_notification = " . ($this->bSmsNotification ? 1 : 0) . ", ldap_dn = '" . addslashes($this->sLdapDn) . "', max_sessions = $this->iMaxSessions, language_id = $this->iLanguageID WHERE id = $this->iId"); | |
| 327 | - if ($result) { | |
| 328 | - return true; | |
| 329 | - } | |
| 330 | - $_SESSION["errorMessage"] = $lang_err_database; | |
| 331 | - return false; | |
| 332 | - } | |
| 333 | - $_SESSION["errorMessage"] = $lang_err_object_key; | |
| 334 | - return false; | |
| 335 | - } | |
| 336 | - | |
| 337 | - /** | |
| 338 | - * Delete the current object from the database | |
| 339 | - * | |
| 340 | - * @return boolean true on successful deletion, false otherwise and set $_SESSION["errorMessage"] | |
| 341 | - * | |
| 342 | - */ | |
| 343 | - function delete() { | |
| 344 | - global $default, $lang_err_database, $lang_err_object_key; | |
| 345 | - //only delete the object if it exists in the database | |
| 346 | - if ($this->iId >= 0) { | |
| 347 | - $sql = $default->db; | |
| 348 | - $result = $sql->query("DELETE FROM $default->owl_users_table WHERE id = $this->iId"); | |
| 349 | - if ($result) { | |
| 350 | - return true; | |
| 351 | - } | |
| 352 | - $_SESSION["errorMessage"] = $lang_err_database; | |
| 353 | - return false; | |
| 354 | - } | |
| 355 | - $_SESSION["errorMessage"] = $lang_err_object_key; | |
| 356 | - return false; | |
| 357 | - } | |
| 358 | - | |
| 359 | - /** | |
| 360 | - * Static function. | |
| 361 | - * Given a web_documents primary key it will create a | |
| 362 | - * User object and populate it with the | |
| 363 | - * corresponding database values | |
| 364 | - * | |
| 365 | - * @return User populated User object on successful query, false otherwise and set $_SESSION["errorMessage"] | |
| 366 | - */ | |
| 367 | - function & get($iUserID) { | |
| 368 | - global $default; | |
| 369 | - $sql = $default->db; | |
| 370 | - $result = $sql->query("SELECT * FROM $default->owl_users_table WHERE id = $iUserID"); | |
| 371 | - if ($result) { | |
| 372 | - if ($sql->next_record()) { | |
| 373 | - $oUser = & new User(stripslashes($sql->f("username")), stripslashes($sql->f("name")), stripslashes($sql->f("password")), $sql->f("quota_max"), stripslashes($sql->f("email")), stripslashes($sql->f("mobile")), $sql->f("email_notification"), $sql->f("sms_notification"), $sql->f("ldap_dn"), $sql->f("max_sessions"), $sql->f("language_id")); | |
| 374 | - $oUser->iId = $iUserID; | |
| 375 | - return $oUser; | |
| 376 | - } | |
| 377 | - $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iUserID . " table = $default->owl_users_table"; | |
| 378 | - return false; | |
| 379 | - } | |
| 380 | - $_SESSION["errorMessage"] = $lang_err_database; | |
| 381 | - return false; | |
| 382 | - } | |
| 383 | - | |
| 384 | - /** | |
| 385 | - * Static function | |
| 386 | - * Get a list of users | |
| 387 | - * | |
| 388 | - * @param String Where clause (not required) | |
| 389 | - * | |
| 390 | - * @return Array array of User objects, false otherwise and set $_SESSION["errorMessage"] | |
| 391 | - */ | |
| 392 | - function getList($sWhereClause = null) { | |
| 393 | - global $default, $lang_err_database; | |
| 394 | - $aUserArray; | |
| 395 | - settype($aUserArray, "array"); | |
| 396 | - $sql = $default->db; | |
| 397 | - $result = $sql->query("SELECT * FROM " . $default->owl_users_table . (isset($sWhereClause) ? " " . $sWhereClause : "")); | |
| 398 | - if ($result) { | |
| 399 | - $iCount = 0; | |
| 400 | - while ($sql->next_record()) { | |
| 401 | - $oUser = & User::get($sql->f("id")); | |
| 402 | - $oUser->iQuotaCurrent = $sql->f("quota_current"); | |
| 403 | - $aUserArray[$iCount] = $oUser; | |
| 404 | - $iCount++; | |
| 405 | - } | |
| 406 | - return $aUserArray; | |
| 407 | - } | |
| 408 | - $_SESSION["errorMessage"] = $lang_err_database; | |
| 409 | - return false; | |
| 410 | - } | |
| 411 | - | |
| 412 | - | |
| 12 | + | |
| 13 | + /** object primary key */ | |
| 14 | + var $iId; | |
| 15 | + /** user's login name */ | |
| 16 | + var $sUserName; | |
| 17 | + /** user's name (first and last) */ | |
| 18 | + var $sName; | |
| 19 | + /** user's password */ | |
| 20 | + var $sPassword; | |
| 21 | + /** user's maximum allowed file storage quota in bytes */ | |
| 22 | + var $iQuotaMax; | |
| 23 | + /** user's current file storage quota in bytes */ | |
| 24 | + var $iQuotaCurrent; | |
| 25 | + /** user's email address */ | |
| 26 | + var $sEmail; | |
| 27 | + /** user's mobile phone number */ | |
| 28 | + var $sMobile; | |
| 29 | + /** notify user by mail status */ | |
| 30 | + var $bEmailNotification; | |
| 31 | + /** notify user via sms (mobile phone) status */ | |
| 32 | + var $bSmsNotification; | |
| 33 | + /** user's ldap identification */ | |
| 34 | + var $sLdapDn; | |
| 35 | + /** maxiumum concurrent sessions user may have */ | |
| 36 | + var $iMaxSessions; | |
| 37 | + /** primary key of language preferred by user */ | |
| 38 | + var $iLanguageID; | |
| 39 | + /** internal variable used to determine if the password has changed or not */ | |
| 40 | + var $bPasswordChanged; | |
| 41 | + | |
| 42 | + function User($sNewUserName, $sNewName, $sNewPassword, $iNewQuotaMax, $sNewEmail, $sNewMobile, $bNewEmailNotification, $bNewSmsNotification, $sNewLdapDn, $iNewMaxSessions, $iNewLanguageID) { | |
| 43 | + //object not created in database yet | |
| 44 | + $this->iId = -1; | |
| 45 | + $this->sUserName = $sNewUserName; | |
| 46 | + $this->sName = $sNewName; | |
| 47 | + $this->sPassword = $sNewPassword; | |
| 48 | + $this->iQuotaMax = $iNewQuotaMax; | |
| 49 | + $this->sEmail = $sNewEmail; | |
| 50 | + $this->sMobile = $sNewMobile; | |
| 51 | + $this->bEmailNotification = $bNewEmailNotification; | |
| 52 | + $this->bSmsNotification = $bNewSmsNotification; | |
| 53 | + $this->sLdapDn = $sNewLdapDn; | |
| 54 | + $this->iMaxSessions = $iNewMaxSessions; | |
| 55 | + $this->iLanguageID = $iNewLanguageID; | |
| 56 | + $this->bPasswordChanged = false; | |
| 57 | + } | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * Get the object's primary key | |
| 61 | + * | |
| 62 | + * @return int object's primary key | |
| 63 | + * | |
| 64 | + */ | |
| 65 | + function getID() { | |
| 66 | + return $this->iId; | |
| 67 | + } | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * Get the user's login name | |
| 71 | + * | |
| 72 | + * @return String user's login name | |
| 73 | + * | |
| 74 | + */ | |
| 75 | + function getUserName() { | |
| 76 | + return $this->sUserName; | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * Set the user's login name | |
| 81 | + * | |
| 82 | + * @param String New user login name | |
| 83 | + * | |
| 84 | + */ | |
| 85 | + function setUserName($sNewValue) { | |
| 86 | + $this->sUserName = $sNewValue; | |
| 87 | + } | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * Set the user's password | |
| 91 | + * | |
| 92 | + * @param String New user password | |
| 93 | + * | |
| 94 | + */ | |
| 95 | + function setPassword($sNewValue) { | |
| 96 | + $this->sPassword = $sNewValue; | |
| 97 | + $this->bPasswordChanged = true; | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * Get the user's maximum disk quota | |
| 102 | + * | |
| 103 | + * @return int user's maximum disk quota | |
| 104 | + * | |
| 105 | + */ | |
| 106 | + function getQuotaMax() { | |
| 107 | + return $this->iQuotaMax; | |
| 108 | + } | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * Set the user's maximum disk quota | |
| 112 | + * | |
| 113 | + * @param int User's maximum disk quota in bytes | |
| 114 | + * | |
| 115 | + */ | |
| 116 | + function setQuotaMax($iNewValue) { | |
| 117 | + $this->iQuotaMax = $iNewValue; | |
| 118 | + } | |
| 119 | + | |
| 120 | + function getName() { | |
| 121 | + return $this->sName; | |
| 122 | + } | |
| 123 | + | |
| 124 | + /** | |
| 125 | + * Get the user's currrently used quota | |
| 126 | + * | |
| 127 | + * @return int user's currently used quota | |
| 128 | + * | |
| 129 | + */ | |
| 130 | + function getQuotaCurrent() { | |
| 131 | + return $this->iQuotaCurrent; | |
| 132 | + } | |
| 133 | + | |
| 134 | + /** | |
| 135 | + * Get the user's email address | |
| 136 | + * | |
| 137 | + * @return String user's email address | |
| 138 | + * | |
| 139 | + */ | |
| 140 | + function getEmail() { | |
| 141 | + return $this->sEmail; | |
| 142 | + } | |
| 143 | + | |
| 144 | + /** | |
| 145 | + * Set the user's email address | |
| 146 | + * | |
| 147 | + * @param String User's email address | |
| 148 | + * | |
| 149 | + */ | |
| 150 | + function setEmail($sNewValue) { | |
| 151 | + $this->sEmail = $sNewValue; | |
| 152 | + } | |
| 153 | + | |
| 154 | + /** | |
| 155 | + * Get the user's mobile phone number | |
| 156 | + * | |
| 157 | + * @return String user's mobile phone number | |
| 158 | + * | |
| 159 | + */ | |
| 160 | + function getMobile() { | |
| 161 | + return $this->sMobile; | |
| 162 | + } | |
| 163 | + | |
| 164 | + /** | |
| 165 | + * Set the user's mobile phone number | |
| 166 | + * | |
| 167 | + * @param String User's mobile phone number | |
| 168 | + * | |
| 169 | + */ | |
| 170 | + function setMobile($sNewValue) { | |
| 171 | + $this->sMobile = $sNewValue; | |
| 172 | + } | |
| 173 | + | |
| 174 | + /** | |
| 175 | + * Get the user's email notification status | |
| 176 | + * | |
| 177 | + * @return boolean user's email notification status | |
| 178 | + * | |
| 179 | + */ | |
| 180 | + function getEmailNotification() { | |
| 181 | + return $this->bEmailNotification; | |
| 182 | + } | |
| 183 | + | |
| 184 | + /** | |
| 185 | + * Set the user's email notification status | |
| 186 | + * | |
| 187 | + * @param boolean User's email notification status (notify by email) | |
| 188 | + * | |
| 189 | + */ | |
| 190 | + function setEmailNotification($bNewValue) { | |
| 191 | + $this->bEmailNotification = $bNewValue; | |
| 192 | + } | |
| 193 | + | |
| 194 | + /** | |
| 195 | + * Get the user's SMS (mobile phone) notification status | |
| 196 | + * | |
| 197 | + * @return boolean SMS (mobile phone) notification status | |
| 198 | + * | |
| 199 | + */ | |
| 200 | + function getSmsNotification() { | |
| 201 | + return $this->bSmsNotification; | |
| 202 | + } | |
| 203 | + | |
| 204 | + /** | |
| 205 | + * Set the user's SMS (mobile phone) notification status | |
| 206 | + * | |
| 207 | + * @param boolean User's SMS (mobile phone) notification status (notify by mobile phone) | |
| 208 | + * | |
| 209 | + */ | |
| 210 | + function setSmsNotification($bNewValue) { | |
| 211 | + $this->bSmsNotification = $bNewValue; | |
| 212 | + } | |
| 213 | + | |
| 214 | + /** | |
| 215 | + * Get the user's LDAP distinguished name | |
| 216 | + * | |
| 217 | + * @return String user's LDAP distinguished name | |
| 218 | + * | |
| 219 | + */ | |
| 220 | + function getLdapDn() { | |
| 221 | + return $this->sLdapDn; | |
| 222 | + } | |
| 223 | + | |
| 224 | + /** | |
| 225 | + * Set the user's LDAP distinguished name | |
| 226 | + * | |
| 227 | + * @param String User's LDAP distinguished name | |
| 228 | + * | |
| 229 | + */ | |
| 230 | + function setLdapDn($sNewValue) { | |
| 231 | + $this->sLdapDn = $sNewValue; | |
| 232 | + } | |
| 233 | + | |
| 234 | + /** | |
| 235 | + * Get the user's maximum number of concurrent sessions | |
| 236 | + * | |
| 237 | + * @return int user's maximum number of concurrent sessions | |
| 238 | + * | |
| 239 | + */ | |
| 240 | + function getMaxSessions() { | |
| 241 | + return $this->iMaxSessions; | |
| 242 | + } | |
| 243 | + | |
| 244 | + /** | |
| 245 | + * Set the user's maximum number of concurrent sessions | |
| 246 | + * | |
| 247 | + * @param int User's maximum number of concurrent sessions | |
| 248 | + * | |
| 249 | + */ | |
| 250 | + function setMaxSessions($iNewValue) { | |
| 251 | + $this->iMaxSessions = $iNewValue; | |
| 252 | + } | |
| 253 | + | |
| 254 | + /** | |
| 255 | + * Get the primary key for the language preferred by the user | |
| 256 | + * | |
| 257 | + * @return int primary key of language preferred by user | |
| 258 | + * | |
| 259 | + */ | |
| 260 | + function getLanguageID() { | |
| 261 | + return $this->iLanguageIDID; | |
| 262 | + } | |
| 263 | + | |
| 264 | + /** | |
| 265 | + * Set the primary key of the language preferred by the user | |
| 266 | + * | |
| 267 | + * @param int Primary key of language preferred by user | |
| 268 | + * | |
| 269 | + */ | |
| 270 | + function setLanguageID($iNewValue) { | |
| 271 | + $this->iLanguageIDID = $iNewValue; | |
| 272 | + } | |
| 273 | + | |
| 274 | + /** | |
| 275 | + * Create the current object in the database | |
| 276 | + * | |
| 277 | + * @return boolean on successful store, false otherwise and set $_SESSION["errorMessage"] | |
| 278 | + * | |
| 279 | + */ | |
| 280 | + function create() { | |
| 281 | + global $default, $lang_err_database, $lang_err_object_exists; | |
| 282 | + //if the object hasn't been created | |
| 283 | + if ($this->iId < 0) { | |
| 284 | + //check to see if name exsits | |
| 285 | + $sql = $default->db; | |
| 286 | + $query = "SELECT username FROM ". $default->owl_users_table ." WHERE username = '" . $this->sUserName . "'"; | |
| 287 | + $sql->query($query); | |
| 288 | + $rows = $sql->num_rows($sql); | |
| 289 | + | |
| 290 | + if ($rows > 0) { | |
| 291 | + // duplicate username | |
| 292 | + $_SESSION["errorMessage"] = "User::The username " . $this->sUserName . " is already in use!"; | |
| 293 | + return false; | |
| 294 | + } | |
| 295 | + else { | |
| 296 | + $result = $sql->query("INSERT INTO " . $default->owl_users_table . " (username, name, password, quota_max, quota_current, email, mobile, email_notification, sms_notification, ldap_dn, max_sessions, language_id) " . | |
| 297 | + "VALUES ('" . addslashes($this->sUserName) . "', '" . addslashes($this->sName) . "', '" . addslashes(md5($this->sPassword)) . "', $this->iQuotaMax, 0, '" . addslashes($this->sEmail) . "', '" . addslashes($this->sMobile) . "', " . ($this->bEmailNotification ? 1 : 0) . ", " . ($this->bSmsNotification ? 1 : 0) . ", '" . addslashes($this->sLdapDn) . "', $this->iMaxSessions, $this->iLanguageID)"); | |
| 298 | + if ($result) { | |
| 299 | + $this->iId = $sql->insert_id(); | |
| 300 | + return true; | |
| 301 | + } | |
| 302 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 303 | + return false; | |
| 304 | + } | |
| 305 | + } | |
| 306 | + $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = $default->owl_users_table"; | |
| 307 | + return false; | |
| 308 | + } | |
| 309 | + | |
| 310 | + /** | |
| 311 | + * Update the values in the database table with the object's current values | |
| 312 | + * | |
| 313 | + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"] | |
| 314 | + * | |
| 315 | + */ | |
| 316 | + function update() { | |
| 317 | + global $default, $lang_err_database, $lang_err_object_key; | |
| 318 | + //only update if the object has been stored | |
| 319 | + if ($this->iId > 0) { | |
| 320 | + $sql = $default->db; | |
| 321 | + $result = $sql->query("UPDATE " . $default->owl_users_table . " SET username = '" . addslashes($this->sUserName) . "', name = '" . addslashes($this->sName) . "', " . ($this->bPasswordChanged ? "password = '" . addslashes(md5($this->sPassword)) . "', " : " ") . " quota_max = $this->iQuotaMax, email = '" . addslashes($this->sEmail) . "', mobile = '" . addslashes($this->sMobile) . "', email_notification = " . ($this->bEmailNotification ? 1 : 0) . ", sms_notification = " . ($this->bSmsNotification ? 1 : 0) . ", ldap_dn = '" . addslashes($this->sLdapDn) . "', max_sessions = $this->iMaxSessions, language_id = $this->iLanguageID WHERE id = $this->iId"); | |
| 322 | + if ($result) { | |
| 323 | + return true; | |
| 324 | + } | |
| 325 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 326 | + return false; | |
| 327 | + } | |
| 328 | + $_SESSION["errorMessage"] = $lang_err_object_key; | |
| 329 | + return false; | |
| 330 | + } | |
| 331 | + | |
| 332 | + /** | |
| 333 | + * Delete the current object from the database | |
| 334 | + * | |
| 335 | + * @return boolean true on successful deletion, false otherwise and set $_SESSION["errorMessage"] | |
| 336 | + * | |
| 337 | + */ | |
| 338 | + function delete() { | |
| 339 | + global $default, $lang_err_database, $lang_err_object_key; | |
| 340 | + //only delete the object if it exists in the database | |
| 341 | + if ($this->iId >= 0) { | |
| 342 | + $sql = $default->db; | |
| 343 | + $result = $sql->query("DELETE FROM $default->owl_users_table WHERE id = $this->iId"); | |
| 344 | + if ($result) { | |
| 345 | + return true; | |
| 346 | + } | |
| 347 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 348 | + return false; | |
| 349 | + } | |
| 350 | + $_SESSION["errorMessage"] = $lang_err_object_key; | |
| 351 | + return false; | |
| 352 | + } | |
| 353 | + | |
| 354 | + /** | |
| 355 | + * Static function. | |
| 356 | + * Given a web_documents primary key it will create a | |
| 357 | + * User object and populate it with the | |
| 358 | + * corresponding database values | |
| 359 | + * | |
| 360 | + * @return User populated User object on successful query, false otherwise and set $_SESSION["errorMessage"] | |
| 361 | + */ | |
| 362 | + function & get($iUserID) { | |
| 363 | + global $default; | |
| 364 | + $sql = $default->db; | |
| 365 | + $result = $sql->query("SELECT * FROM $default->owl_users_table WHERE id = $iUserID"); | |
| 366 | + if ($result) { | |
| 367 | + if ($sql->next_record()) { | |
| 368 | + $oUser = & new User(stripslashes($sql->f("username")), stripslashes($sql->f("name")), stripslashes($sql->f("password")), $sql->f("quota_max"), stripslashes($sql->f("email")), stripslashes($sql->f("mobile")), $sql->f("email_notification"), $sql->f("sms_notification"), $sql->f("ldap_dn"), $sql->f("max_sessions"), $sql->f("language_id")); | |
| 369 | + $oUser->iId = $iUserID; | |
| 370 | + return $oUser; | |
| 371 | + } | |
| 372 | + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iUserID . " table = $default->owl_users_table"; | |
| 373 | + return false; | |
| 374 | + } | |
| 375 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 376 | + return false; | |
| 377 | + } | |
| 378 | + | |
| 379 | + /** | |
| 380 | + * Static function | |
| 381 | + * Get a list of users | |
| 382 | + * | |
| 383 | + * @param String Where clause (not required) | |
| 384 | + * | |
| 385 | + * @return Array array of User objects, false otherwise and set $_SESSION["errorMessage"] | |
| 386 | + */ | |
| 387 | + function getList($sWhereClause = null) { | |
| 388 | + global $default, $lang_err_database; | |
| 389 | + $aUserArray; | |
| 390 | + settype($aUserArray, "array"); | |
| 391 | + $sql = $default->db; | |
| 392 | + $result = $sql->query("SELECT * FROM " . $default->owl_users_table . (isset($sWhereClause) ? " " . $sWhereClause : "")); | |
| 393 | + if ($result) { | |
| 394 | + $iCount = 0; | |
| 395 | + while ($sql->next_record()) { | |
| 396 | + $oUser = & User::get($sql->f("id")); | |
| 397 | + $oUser->iQuotaCurrent = $sql->f("quota_current"); | |
| 398 | + $aUserArray[$iCount] = $oUser; | |
| 399 | + $iCount++; | |
| 400 | + } | |
| 401 | + return $aUserArray; | |
| 402 | + } | |
| 403 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 404 | + return false; | |
| 405 | + } | |
| 406 | + | |
| 407 | + | |
| 413 | 408 | /** |
| 414 | 409 | * Static function |
| 415 | 410 | * Return the useID for the specified user |
| ... | ... | @@ -419,37 +414,34 @@ class User { |
| 419 | 414 | */ |
| 420 | 415 | function getUnitID($userID) { |
| 421 | 416 | global $default, $lang_err_database; |
| 422 | - | |
| 423 | - $sql = $default->db; | |
| 417 | + | |
| 418 | + $sql = $default->db; | |
| 424 | 419 | $result = $sql->query("SELECT DISTINCT gul.unit_id FROM $default->owl_users_groups_table ugl " . |
| 425 | 420 | "INNER JOIN $default->owl_groups_units_table gul ON ugl.group_id = gul.group_id ". |
| 426 | 421 | "WHERE ugl.user_id=$userID"); |
| 427 | - if ($result) { | |
| 428 | - if ($sql->next_record()) { | |
| 429 | - return $sql->f("unit_id"); | |
| 430 | - } | |
| 431 | - } | |
| 432 | - $_SESSION["errorMessage"] = $lang_err_database; | |
| 433 | - return false; | |
| 422 | + if ($result) { | |
| 423 | + if ($sql->next_record()) { | |
| 424 | + return $sql->f("unit_id"); | |
| 425 | + } | |
| 426 | + } | |
| 427 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 428 | + return false; | |
| 434 | 429 | } |
| 435 | - /* | |
| 430 | + | |
| 431 | + /** | |
| 436 | 432 | * static function |
| 437 | 433 | * |
| 438 | 434 | * gets the id of a user using their username |
| 439 | 435 | * |
| 440 | 436 | * @param string The username for which we want its ID |
| 441 | - * | |
| 442 | - * | |
| 443 | 437 | */ |
| 444 | - | |
| 445 | - function getUserID($username) | |
| 446 | - { | |
| 447 | - global $default; | |
| 448 | - | |
| 449 | - $id = lookupID($default->owl_users_table, "username", $username); | |
| 450 | - | |
| 451 | - $this->iId = $id; | |
| 452 | - } | |
| 438 | + function getUserID($sUsername) { | |
| 439 | + global $default; | |
| 440 | + | |
| 441 | + $id = lookupID($default->owl_users_table, "username", $sUsername); | |
| 442 | + | |
| 443 | + $this->iId = $id; | |
| 444 | + } | |
| 453 | 445 | } |
| 454 | 446 | |
| 455 | 447 | /** |
| ... | ... | @@ -457,13 +449,13 @@ class User { |
| 457 | 449 | * |
| 458 | 450 | * Creates a User object from an array |
| 459 | 451 | * |
| 460 | -* @param Array Array of parameters. Must match order of parameters in constructor | |
| 452 | +* @param Array Array of parameters. Must match order of parameters in constructor | |
| 461 | 453 | * |
| 462 | 454 | * @return User user object |
| 463 | 455 | */ |
| 464 | 456 | function & userCreateFromArray($aParameters) { |
| 465 | - $oUser = & new User($aParameters[0], $aParameters[1], $aParameters[2], $aParameters[3], $aParameters[4], $aParameters[5], $aParameters[6], $aParameters[7], $aParameters[8], $aParameters[9], $aParameters[10]); | |
| 466 | - return $oUser; | |
| 457 | + $oUser = & new User($aParameters[0], $aParameters[1], $aParameters[2], $aParameters[3], $aParameters[4], $aParameters[5], $aParameters[6], $aParameters[7], $aParameters[8], $aParameters[9], $aParameters[10]); | |
| 458 | + return $oUser; | |
| 467 | 459 | } |
| 468 | 460 | |
| 469 | 461 | ?> | ... | ... |