Commit 05f7884223ad16d889f750e9fb661191c5f6b3c5
1 parent
c0e1050b
Initial revision. Object that represents users table in database
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@410 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
393 additions
and
0 deletions
lib/users/User.inc
0 → 100644
| 1 | +<?php | |
| 2 | +/** | |
| 3 | +* Class User | |
| 4 | +* Represents a user as per the users table in the database | |
| 5 | +* | |
| 6 | +* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | |
| 7 | +* @date 20 January 2003 | |
| 8 | +* @package lib.user | |
| 9 | +*/ | |
| 10 | + | |
| 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 | + /** | |
| 121 | + * Get the user's currrently used quota | |
| 122 | + * | |
| 123 | + * @return int user's currently used quota | |
| 124 | + * | |
| 125 | + */ | |
| 126 | + function getQuotaCurrent() { | |
| 127 | + return $this->iQuotaCurrent; | |
| 128 | + } | |
| 129 | + | |
| 130 | + /** | |
| 131 | + * Get the user's email address | |
| 132 | + * | |
| 133 | + * @return String user's email address | |
| 134 | + * | |
| 135 | + */ | |
| 136 | + function getEmail() { | |
| 137 | + return $this->sEmail; | |
| 138 | + } | |
| 139 | + | |
| 140 | + /** | |
| 141 | + * Set the user's email address | |
| 142 | + * | |
| 143 | + * @param String User's email address | |
| 144 | + * | |
| 145 | + */ | |
| 146 | + function setEmail($sNewValue) { | |
| 147 | + $this->sEmail = $sNewValue; | |
| 148 | + } | |
| 149 | + | |
| 150 | + /** | |
| 151 | + * Get the user's mobile phone number | |
| 152 | + * | |
| 153 | + * @return String user's mobile phone number | |
| 154 | + * | |
| 155 | + */ | |
| 156 | + function getMobile() { | |
| 157 | + return $this->sMobile; | |
| 158 | + } | |
| 159 | + | |
| 160 | + /** | |
| 161 | + * Set the user's mobile phone number | |
| 162 | + * | |
| 163 | + * @param String User's mobile phone number | |
| 164 | + * | |
| 165 | + */ | |
| 166 | + function setMobile($sNewValue) { | |
| 167 | + $this->sMobile = $sNewValue; | |
| 168 | + } | |
| 169 | + | |
| 170 | + /** | |
| 171 | + * Get the user's email notification status | |
| 172 | + * | |
| 173 | + * @return boolean user's email notification status | |
| 174 | + * | |
| 175 | + */ | |
| 176 | + function getEmailNotification() { | |
| 177 | + return $this->bEmailNotification; | |
| 178 | + } | |
| 179 | + | |
| 180 | + /** | |
| 181 | + * Set the user's email notification status | |
| 182 | + * | |
| 183 | + * @param boolean User's email notification status (notify by email) | |
| 184 | + * | |
| 185 | + */ | |
| 186 | + function setEmailNotification($bNewValue) { | |
| 187 | + $this->bEmailNotification = $bNewValue; | |
| 188 | + } | |
| 189 | + | |
| 190 | + /** | |
| 191 | + * Get the user's SMS (mobile phone) notification status | |
| 192 | + * | |
| 193 | + * @return boolean SMS (mobile phone) notification status | |
| 194 | + * | |
| 195 | + */ | |
| 196 | + function getSmsNotification() { | |
| 197 | + return $this->bSmsNotification; | |
| 198 | + } | |
| 199 | + | |
| 200 | + /** | |
| 201 | + * Set the user's SMS (mobile phone) notification status | |
| 202 | + * | |
| 203 | + * @param boolean User's SMS (mobile phone) notification status (notify by mobile phone) | |
| 204 | + * | |
| 205 | + */ | |
| 206 | + function setSmsNotification($bNewValue) { | |
| 207 | + $this->bSmsNotification = $bNewValue; | |
| 208 | + } | |
| 209 | + | |
| 210 | + /** | |
| 211 | + * Get the user's LDAP distinguished name | |
| 212 | + * | |
| 213 | + * @return String user's LDAP distinguished name | |
| 214 | + * | |
| 215 | + */ | |
| 216 | + function getLdapDn() { | |
| 217 | + return $this->sLdapDn; | |
| 218 | + } | |
| 219 | + | |
| 220 | + /** | |
| 221 | + * Set the user's LDAP distinguished name | |
| 222 | + * | |
| 223 | + * @param String User's LDAP distinguished name | |
| 224 | + * | |
| 225 | + */ | |
| 226 | + function setLdapDn($sNewValue) { | |
| 227 | + $this->sLdapDn = $sNewValue; | |
| 228 | + } | |
| 229 | + | |
| 230 | + /** | |
| 231 | + * Get the user's maximum number of concurrent sessions | |
| 232 | + * | |
| 233 | + * @return int user's maximum number of concurrent sessions | |
| 234 | + * | |
| 235 | + */ | |
| 236 | + function getMaxSessions() { | |
| 237 | + return $this->iMaxSessions; | |
| 238 | + } | |
| 239 | + | |
| 240 | + /** | |
| 241 | + * Set the user's maximum number of concurrent sessions | |
| 242 | + * | |
| 243 | + * @param int User's maximum number of concurrent sessions | |
| 244 | + * | |
| 245 | + */ | |
| 246 | + function setMaxSessions($iNewValue) { | |
| 247 | + $this->iMaxSessions = $iNewValue; | |
| 248 | + } | |
| 249 | + | |
| 250 | + /** | |
| 251 | + * Get the primary key for the language preferred by the user | |
| 252 | + * | |
| 253 | + * @return int primary key of language preferred by user | |
| 254 | + * | |
| 255 | + */ | |
| 256 | + function getLanguageID() { | |
| 257 | + return $this->iLanguageIDID; | |
| 258 | + } | |
| 259 | + | |
| 260 | + /** | |
| 261 | + * Set the primary key of the language preferred by the user | |
| 262 | + * | |
| 263 | + * @param int Primary key of language preferred by user | |
| 264 | + * | |
| 265 | + */ | |
| 266 | + function setLanguageID($iNewValue) { | |
| 267 | + $this->iLanguageIDID = $iNewValue; | |
| 268 | + } | |
| 269 | + | |
| 270 | + /** | |
| 271 | + * Create the current object in the database | |
| 272 | + * | |
| 273 | + * @return boolean on successful store, false otherwise and set $_SESSION["errorMessage"] | |
| 274 | + * | |
| 275 | + */ | |
| 276 | + function create() { | |
| 277 | + global $default, $lang_err_database, $lang_err_object_exists; | |
| 278 | + //if the object hasn't been created | |
| 279 | + if ($this->iId < 0) { | |
| 280 | + $sql = new Owl_DB(); | |
| 281 | + $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) " . | |
| 282 | + "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)"); | |
| 283 | + if ($result) { | |
| 284 | + $this->iId = $sql->insert_id(); | |
| 285 | + return true; | |
| 286 | + } | |
| 287 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 288 | + return false; | |
| 289 | + } | |
| 290 | + $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = $default->owl_users_table"; | |
| 291 | + return false; | |
| 292 | + } | |
| 293 | + | |
| 294 | + /** | |
| 295 | + * Update the values in the database table with the object's current values | |
| 296 | + * | |
| 297 | + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"] | |
| 298 | + * | |
| 299 | + */ | |
| 300 | + function update() { | |
| 301 | + global $default, $lang_err_database, $lang_err_object_key; | |
| 302 | + //only update if the object has been stored | |
| 303 | + if ($this->iId > 0) { | |
| 304 | + $sql = new Owl_DB(); | |
| 305 | + $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 = $this->iLanguageID WHERE id = $this->iId"); | |
| 306 | + if ($result) { | |
| 307 | + return true; | |
| 308 | + } | |
| 309 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 310 | + return false; | |
| 311 | + } | |
| 312 | + $_SESSION["errorMessage"] = $lang_err_object_key; | |
| 313 | + return false; | |
| 314 | + } | |
| 315 | + | |
| 316 | + /** | |
| 317 | + * Delete the current object from the database | |
| 318 | + * | |
| 319 | + * @return boolean true on successful deletion, false otherwise and set $_SESSION["errorMessage"] | |
| 320 | + * | |
| 321 | + */ | |
| 322 | + function delete() { | |
| 323 | + global $default, $lang_err_database, $lang_err_object_key; | |
| 324 | + //only delete the object if it exists in the database | |
| 325 | + if ($this->iId >= 0) { | |
| 326 | + $sql = new Owl_DB(); | |
| 327 | + $result = $sql->query("DELETE FROM $default->owl_users_table WHERE id = $this->iId"); | |
| 328 | + if ($result) { | |
| 329 | + return true; | |
| 330 | + } | |
| 331 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 332 | + return false; | |
| 333 | + } | |
| 334 | + $_SESSION["errorMessage"] = $lang_err_object_key; | |
| 335 | + return false; | |
| 336 | + } | |
| 337 | + | |
| 338 | + /** | |
| 339 | + * Static function. | |
| 340 | + * Given a web_documents primary key it will create a | |
| 341 | + * User object and populate it with the | |
| 342 | + * corresponding database values | |
| 343 | + * | |
| 344 | + * @return User populated User object on successful query, false otherwise and set $_SESSION["errorMessage"] | |
| 345 | + */ | |
| 346 | + function & get($iUserID) { | |
| 347 | + global $default; | |
| 348 | + $sql = new Owl_DB(); | |
| 349 | + $result = $sql->query("SELECT * FROM $default->owl_users_table WHERE id = $iUserID"); | |
| 350 | + if ($result) { | |
| 351 | + if ($sql->next_record()) { | |
| 352 | + $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")); | |
| 353 | + $oUser->iId = $iUserID; | |
| 354 | + return $oUser; | |
| 355 | + } | |
| 356 | + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iUserID . " table = $default->owl_users_table"; | |
| 357 | + return false; | |
| 358 | + } | |
| 359 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 360 | + return false; | |
| 361 | + } | |
| 362 | + | |
| 363 | + /** | |
| 364 | + * Static function | |
| 365 | + * Get a list of users | |
| 366 | + * | |
| 367 | + * @param String Where clause (not required) | |
| 368 | + * | |
| 369 | + * @return Array array of User objects, false otherwise and set $_SESSION["errorMessage"] | |
| 370 | + */ | |
| 371 | + function getList($sWhereClause = null) { | |
| 372 | + global $default, $lang_err_database; | |
| 373 | + $aUserArray; | |
| 374 | + settype($aUserArray, "array"); | |
| 375 | + $sql = new Owl_DB(); | |
| 376 | + $result = $sql->query("SELECT * FROM " . $default->owl_users_table . (isset($sWhereClause) ? " " . $sWhereClause : "")); | |
| 377 | + if ($result) { | |
| 378 | + $iCount = 0; | |
| 379 | + while ($sql->next_record()) { | |
| 380 | + $oUser = & User::get($sql->f("id")); | |
| 381 | + $oUser->iQuotaCurrent = $sql->f("quota_current"); | |
| 382 | + $aUserArray[$iCount] = $oUser; | |
| 383 | + $iCount++; | |
| 384 | + } | |
| 385 | + return $aUserArray; | |
| 386 | + } | |
| 387 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 388 | + return false; | |
| 389 | + } | |
| 390 | + | |
| 391 | + | |
| 392 | +} | |
| 393 | +?> | ... | ... |