5 # Part of the Collection Workflow Integration System (CWIS) 6 # Copyright 2013 Edward Almasy and Internet Scout Research Group 7 # http://scout.wisc.edu/cwis/ 16 # ---- PUBLIC INTERFACE -------------------------------------------------- 24 static $EmailWrapperSet = FALSE;
25 if (!$EmailWrapperSet)
28 $EmailWrapperSet = TRUE;
31 parent::__construct($UserInfo);
33 if ($this->Result !==
U_OKAY)
36 "Unable to load user information.");
39 # try to fetch the associated resource if the user was found 42 $Resource = $this->FetchAssociatedResource($this->UserId);
44 # the associated resource was successfully found 49 # there was a problem finding the resource 53 "Unable to load corresponding resource for user.");
70 public function Login($UserName, $Password, $IgnorePassword = FALSE)
72 parent::Login($UserName, $Password, $IgnorePassword);
74 if ($this->Result ==
U_OKAY)
76 $Resource = $this->FetchAssociatedResource($this->UserId);
78 # the associated resource was successfully found 83 # there was a problem finding the resource 87 "Unable to load corresponding resource for user.");
112 if ($NewValue !== NULL)
115 "Attempt to set user privileges with CWUser::Privileges(), " 116 .
"which is no longer supported");
154 public function HasPriv($Privilege, $Privileges = NULL)
158 if ($Privileges instanceof
Resource)
160 return $Privilege->MeetsRequirements($this, $Privileges);
164 return $Privilege->MeetsRequirements($this);
169 $Args = func_get_args();
170 if (in_array(PRIV_ISLOGGEDIN, $Args) && $this->
IsLoggedIn())
175 $Args = self::FilterPrivileges($Args);
178 return call_user_func_array(
"parent::HasPriv", $Args);
193 if (self::IsPseudoPrivilege($Privilege))
195 throw new Exception(
"Attempt to grant pseudo-privilege to user");
198 return parent::GrantPriv($Privilege);
209 parent::SetPrivList( self::FilterPrivileges($NewPrivileges) );
222 public static function EmailWrapper($To, $Subject, $Message, $AdditionalHeaders)
224 # extract "From" address from supplied headers if available 225 if (strlen($AdditionalHeaders))
227 $HeaderLines = explode(
"\n", $AdditionalHeaders);
229 foreach ($HeaderLines as $Line)
231 $HeaderLine = trim($Line);
232 if (preg_match(
"/^from:/i", $Line))
234 $From = preg_replace(
"/^from:/i",
"", $Line);
238 $Headers[] = $HeaderLine;
245 if (isset($From)) { $Msg->From($From); }
247 $Msg->Subject($Subject);
248 $Msg->AddHeaders($Headers);
249 $Msg->Body($Message);
252 # report success to caller 262 static $CustomFields;
264 if (!isset($CustomFields))
266 $CustomFields = array();
269 foreach ($Schema->GetFields() as $Field)
271 # they're custom if not owned by CWIS 272 if ($Field->Owner() !=
"CWISCore")
274 $CustomFields[$Field->Id()] = $Field;
279 return $CustomFields;
288 static $DefaultFields;
290 if (!isset($DefaultFields))
292 $DefaultFields = array();
295 foreach ($Schema->GetFields() as $Field)
297 # they're default if owned by CWIS 298 if ($Field->Owner() ==
"CWISCore")
300 $DefaultFields[$Field->Id()] = $Field;
305 return $DefaultFields;
308 # ---- OVERRIDDEN METHODS ------------------------------------------------ 317 # delete the associated user resource if set 324 return parent::Delete();
333 public function Get($FieldName)
335 # all values are NULL for anonymous users 341 if (in_array($FieldName, self::$FieldsOnlyInAPUsers))
343 return parent::Get($FieldName);
357 public function Set($Field, $NewValue)
362 "Attempt to set User field value when " 363 .
"no user is logged in.");
366 # make sure Field is a FieldName 369 $Field = $Field->Name();
372 # if this field is not among those that should only exists in 374 if (!in_array($Field, self::$FieldsOnlyInAPUsers))
376 # set it in our corresponding resource 380 # if the given field exists in the APUsers table, update that too 381 if ($this->DB->FieldExists(
"APUsers", $Field))
383 parent::Set($Field, $NewValue);
387 # indicate success for fields that don't have a column in APUsers 394 # ---- PRIVATE INTERFACE ------------------------------------------------- 402 # list of fields that exist in APUsers that are not mirrored as MetadataFields 403 private static $FieldsOnlyInAPUsers = [
404 # fields necessary to for user identification 405 "UserId",
"UserName",
"EMail",
"EMailNew",
407 # fields necessary for authentication 408 "UserPassword",
"RegistrationConfirmed",
410 # fields that can't be in a schema because they are updated by User 411 "LastLoginDate",
"LastActiveDate",
"LastIPAddress",
"LastLocation",
"LoggedIn",
414 "ActiveUI",
"BrowsingFieldId",
"RecordsPerPage",
"SearchSelections",
423 protected function FetchAssociatedResource(
$UserId)
425 if (self::$UserIdFieldId === NULL)
427 # get the user schema 430 # pull out the UserId field, which should only be one 431 $Field = $Schema->GetField(
"UserId");
433 # and get its FieldId 434 self::$UserIdFieldId = intval($Field->Id());
437 # find the matching Resources (should only be one) 439 "SELECT ResourceId FROM ResourceUserInts WHERE ".
440 "FieldId=".self::$UserIdFieldId.
441 " AND UserId=".intval(
$UserId) );
442 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
443 $ResourceIdCount = count($ResourceIds);
446 if ($ResourceIdCount < 1)
451 # too many resources found 452 if ($ResourceIdCount > 1)
455 "Multiple resources exist for a single user, " 456 .
"which should be impossible");
459 # construct the associated resource and return it 460 return new Resource(array_shift($ResourceIds));
469 public static function IsStandardPrivilege($Priv)
471 return (self::MIN_STANDARD_PRIV <= $Priv &&
472 $Priv <= self::MAX_STANDARD_PRIV) ? TRUE : FALSE;
481 public static function IsPseudoPrivilege($Priv)
483 return (self::MIN_PSEUDO_PRIV <= $Priv &&
484 $Priv <= self::MAX_PSEUDO_PRIV) ? TRUE : FALSE;
493 public static function IsCustomPrivilege($Priv)
495 return (self::MIN_CUSTOM_PRIV <= $Priv &&
496 $Priv <= self::MAX_CUSTOM_PRIV) ? TRUE : FALSE;
504 protected function FilterPrivileges($Privs)
507 foreach ($Privs as $Priv)
509 if (!self::IsPseudoPrivilege($Priv))
518 const MIN_STANDARD_PRIV = 1;
519 const MAX_STANDARD_PRIV = 74;
521 const MIN_PSEUDO_PRIV = 75;
522 const MAX_PSEUDO_PRIV = 99;
524 const MIN_CUSTOM_PRIV = 100;
525 const MAX_CUSTOM_PRIV = PHP_INT_MAX;
527 # ---- MAINTAINED FOR BACKWARD COMPATIBILITY IN INTERFACES (BEGIN) 529 # ---- user interface preference mnemonics 530 # color avoidance flags 531 const UIPREF_AVOID_RED = 1;
532 const UIPREF_AVOID_REDGREEN = 2;
533 const UIPREF_AVOID_BLUEYELLOW = 4;
534 const UIPREF_AVOID_GREENYELLOW = 8;
535 const UIPREF_AVOID_ORANGE = 16;
536 const UIPREF_AVOID_REDBLACK = 32;
537 const UIPREF_AVOID_PURPLEGREY = 64;
538 const UIPREF_AVOID_USEMAXMONOCHR = 128;
540 # content display options 541 const UIPREF_CONTENTDENSITY_NOPREFERENCE = 0;
542 const UIPREF_CONTENTDENSITY_DETAILED = 1;
543 const UIPREF_CONTENTDENSITY_OVERVIEW = 2;
545 # content view options 546 const UIPREF_CONTENTVIEW_NOPREFERENCE = 0;
547 const UIPREF_CONTENTVIEW_TEXTINTENSIVE = 1;
548 const UIPREF_CONTENTVIEW_IMAGEINTENSIVE = 2;
550 # audio description options 551 const UIPREF_AUDIODESCRIPTION_NONE = 0;
552 const UIPREF_AUDIODESCRIPTION_STANDARD = 1;
553 const UIPREF_AUDIODESCRIPTION_EXPANDED = 2;
555 # caption type options 556 const UIPREF_CAPTIONTYPE_NONE = 0;
557 const UIPREF_CAPTIONTYPE_VERBATIM = 1;
558 const UIPREF_CAPTIONTYPE_REDUCEDREADINGLEVEL = 2;
562 # user interface / accessibility preferences 566 function PrefFontTypeFace($NewValue =
DB_NOVALUE)
569 function PrefFontColor($NewValue =
DB_NOVALUE)
572 function PrefBackgroundColor($NewValue =
DB_NOVALUE)
575 function PrefColorAvoidanceFlags($NewValue =
DB_NOVALUE)
578 function PrefContentDensity($NewValue =
DB_NOVALUE)
581 function PrefContentView($NewValue =
DB_NOVALUE)
584 function PrefAudioDescriptionLevel($NewValue =
DB_NOVALUE)
587 function PrefAudioDescriptionLanguage($NewValue =
DB_NOVALUE)
590 function PrefVisualDescriptionLanguage($NewValue =
DB_NOVALUE)
593 function PrefImageDescriptionLanguage($NewValue =
DB_NOVALUE)
596 function PrefUseGraphicAlternatives($NewValue =
DB_NOVALUE)
599 function PrefSignLanguage($NewValue =
DB_NOVALUE)
602 function PrefCaptionType($NewValue =
DB_NOVALUE)
605 function PrefCaptionRate($NewValue =
DB_NOVALUE)
609 # ---- MAINTAINED FOR BACKWARD COMPATIBILITY IN INTERFACES (END) 611 private static $UserIdFieldId = NULL;
IsLoggedIn()
Report whether user is currently logged in.
$Resource
The user resource associated with the user or NULL if the user isn't logged in.
Privileges(PrivilegeSet $NewValue=NULL)
THIS FUNCTION HAS BEEN DEPRECATED This provides compatibility for interfaces written to use a version...
ResourceId()
Get the ID of the user resource associated with the user.
Delete()
Delete the user and its associated user resource.
Id()
Retrieve numerical resource ID.
HasPriv($Privilege, $Privileges=NULL)
Determine if a user has a given privilege, or satisfies the conditions specified by a given privilege...
Get($FieldName)
Get a value from the specified field.
Set($Field, $NewValue)
Set a value for the specified field.
SetPrivList($NewPrivileges)
Clear current user privs and replace them with the specified list.
Set of privileges used to access resource information or other parts of the system.
Login($UserName, $Password, $IgnorePassword=FALSE)
Log the specified user in and associate the underlying Resource with this CWUser. ...
Get($Field, $ReturnObject=FALSE, $IncludeVariants=FALSE)
Retrieve value using field name or field object.
__construct($UserInfo=NULL)
Load user data from the given user info or from the session if available.
IsAnonymous()
Report whether user is anonymous user.
static EmailWrapper($To, $Subject, $Message, $AdditionalHeaders)
Adapter method to bridge between User class and Email class.
static SetEmailFunction($NewValue)
Set email function to use instead of mail().
Compatibility layer allowing interfaces built against the privilege system from CWIS 3...
Represents a "resource" in CWIS.
static GetDefaultUserFields()
Get the default user fields.
static GetCustomUserFields()
Get all custom user fields.
Set($Field, $NewValue, $Reset=FALSE)
Set value using field name or field object.
GetResource()
Get the associated user resource for this user.
CWIS-specific user class.
GrantPriv($Privilege)
Grant privilege to a a user.
Logout()
Log this user out and disassociate their underlying Resource from this CWUser.
Delete()
Remove resource (and accompanying associations) from database and delete any associated files...