示例#1
0
 public function getMyProfile($patron, $forceReload = false)
 {
     global $timer;
     global $configArray;
     /** @var Memcache $memCache */
     global $memCache;
     global $serverName;
     $memCacheProfileKey = "patronProfile_{$serverName}_";
     if (is_object($patron)) {
         $patron = get_object_vars($patron);
         $userId = $patron['id'];
         $patronUserName = $patron['username'];
         $memCacheProfileKey .= $patron['username'];
     } else {
         global $user;
         $userId = $user->id;
         $patronUserName = $user->username;
         $memCacheProfileKey .= $user->username;
     }
     if (!$forceReload && !isset($_REQUEST['reload'])) {
         $patronProfile = $memCache->get($memCacheProfileKey);
         if ($patronProfile) {
             $timer->logTime('Retrieved Cached Profile for Patron');
             return $patronProfile;
         }
     }
     global $user;
     if ($configArray['Catalog']['offline'] == true) {
         $fullName = $patron['cat_username'];
         $Address1 = "";
         $City = "";
         $State = "";
         $Zip = "";
         $Email = "";
         $finesVal = 0;
         $expireClose = false;
         $homeBranchCode = '';
         $numHoldsAvailable = '?';
         $numHoldsRequested = '?';
         if (!$user) {
             $user = new User();
             $user->username = $patronUserName;
             if ($user->find(true)) {
                 $location = new Location();
                 $location->locationId = $user->homeLocationId;
                 $location->find(1);
                 $homeBranchCode = $location->code;
             }
         }
     } else {
         //Load the raw information about the patron from web services
         if (isset(HorizonAPI::$sessionIdsForUsers[$userId])) {
             $sessionToken = HorizonAPI::$sessionIdsForUsers[$userId];
             // keys off username
         } else {
             //Log the user in
             $return = $this->loginViaWebService($patron['cat_username'], $patron['cat_password']);
             if (count($return) == 1) {
                 $userValid = $return[0];
             } else {
                 list($userValid, $sessionToken) = $return;
             }
             if (!$userValid) {
                 echo "No session id found for user";
                 return PEAR_Singleton::raiseError("Could not login to web service " . $return);
             }
         }
         $lookupMyAccountInfoResponse = $this->getWebServiceResponse($configArray['Catalog']['webServiceUrl'] . '/standard/lookupMyAccountInfo?clientID=' . $configArray['Catalog']['clientId'] . '&sessionToken=' . $sessionToken . '&includeAddressInfo=true&includeHoldInfo=true&includeBlockInfo=true&includeItemsOutInfo=true');
         if ($lookupMyAccountInfoResponse === false) {
             global $logger;
             $logger->log("Unable to login", PEAR_LOG_WARNING);
             return null;
         }
         if (isset($lookupMyAccountInfoResponse->AddressInfo)) {
             $Address1 = (string) $lookupMyAccountInfoResponse->AddressInfo->line1;
             if (isset($lookupMyAccountInfoResponse->AddressInfo->cityState)) {
                 $cityState = (string) $lookupMyAccountInfoResponse->AddressInfo->cityState;
                 list($City, $State) = explode(', ', $cityState);
             } else {
                 $City = "";
                 $State = "";
             }
             $Zip = (string) $lookupMyAccountInfoResponse->AddressInfo->postalCode;
             if (isset($lookupMyAccountInfoResponse->AddressInfo->email)) {
                 $Email = (string) $lookupMyAccountInfoResponse->AddressInfo->email;
             }
         } else {
             $Address1 = "";
             $City = "";
             $State = "";
             $Zip = "";
             $Email = '';
         }
         $fullName = $lookupMyAccountInfoResponse->name;
         //Get additional information about the patron's home branch for display.
         if (isset($lookupMyAccountInfoResponse->locationID)) {
             $homeBranchCode = trim((string) $lookupMyAccountInfoResponse->locationID);
             //Translate home branch to plain text
             $location = new Location();
             $location->code = $homeBranchCode;
             $location->find(1);
             if ($location->N == 0) {
                 unset($location);
             }
         }
         if ($user) {
             if ($user->homeLocationId == 0 && isset($location)) {
                 $user->homeLocationId = $location->locationId;
                 if ($location->nearbyLocation1 > 0) {
                     $user->myLocation1Id = $location->nearbyLocation1;
                 } else {
                     $user->myLocation1Id = $location->locationId;
                 }
                 if ($location->nearbyLocation2 > 0) {
                     $user->myLocation2Id = $location->nearbyLocation2;
                 } else {
                     $user->myLocation2Id = $location->locationId;
                 }
                 if ($user instanceof User) {
                     //Update the database
                     $user->update();
                     //Update the serialized instance stored in the session
                     $_SESSION['userinfo'] = serialize($user);
                 }
             } else {
                 if (isset($location) && $location->locationId != $user->homeLocationId) {
                     $user->homeLocationId = $location->locationId;
                     //Update the database
                     $user->update();
                     //Update the serialized instance stored in the session
                     $_SESSION['userinfo'] = serialize($user);
                 }
             }
         }
         //TODO: See if we can get information about card expiration date
         $expireClose = 0;
         $finesVal = 0;
         if (isset($lookupMyAccountInfoResponse->BlockInfo)) {
             foreach ($lookupMyAccountInfoResponse->BlockInfo as $block) {
                 // $block is a simplexml object with attribute info about currency, type casting as below seems to work for adding up. plb 3-27-2015
                 $fineAmount = (double) $block->balance;
                 $finesVal += $fineAmount;
             }
         }
         $numHoldsAvailable = 0;
         $numHoldsRequested = 0;
         if (isset($lookupMyAccountInfoResponse->HoldInfo)) {
             foreach ($lookupMyAccountInfoResponse->HoldInfo as $hold) {
                 if ($hold->status == 'FILLED') {
                     $numHoldsAvailable++;
                 } else {
                     $numHoldsRequested++;
                 }
             }
         }
     }
     if ($user) {
         //Get display name for preferred location 1
         $myLocation1 = new Location();
         $myLocation1->whereAdd("locationId = '{$user->myLocation1Id}'");
         $myLocation1->find(1);
         //Get display name for preferred location 1
         $myLocation2 = new Location();
         $myLocation2->whereAdd("locationId = '{$user->myLocation2Id}'");
         $myLocation2->find(1);
     }
     list($fullName, $lastName, $firstName) = $this->splitFullName($fullName);
     $profile = array('lastname' => $lastName, 'firstname' => $firstName, 'fullname' => $fullName, 'address1' => $Address1, 'address2' => $City . ', ' . $State, 'city' => $City, 'state' => $State, 'zip' => $Zip, 'email' => $user && $user->email ? $user->email : $Email, 'overdriveEmail' => $user ? $user->overdriveEmail : $Email, 'promptForOverdriveEmail' => $user ? $user->promptForOverdriveEmail : 1, 'phone' => isset($lookupMyAccountInfoResponse->phone) ? (string) $lookupMyAccountInfoResponse->phone : '', 'workPhone' => '', 'mobileNumber' => '', 'fines' => sprintf('$%01.2f', $finesVal), 'finesval' => $finesVal, 'expires' => '', 'expireclose' => $expireClose, 'homeLocationCode' => isset($homeBranchCode) ? trim($homeBranchCode) : '', 'homeLocationId' => isset($location) ? $location->locationId : 0, 'homeLocation' => isset($location) ? $location->displayName : '', 'myLocation1Id' => $user ? $user->myLocation1Id : -1, 'myLocation1' => isset($myLocation1) ? $myLocation1->displayName : '', 'myLocation2Id' => $user ? $user->myLocation2Id : -1, 'myLocation2' => isset($myLocation2) ? $myLocation2->displayName : '', 'numCheckedOut' => isset($lookupMyAccountInfoResponse->ItemsOutInfo) ? count($lookupMyAccountInfoResponse->ItemsOutInfo) : 0, 'numHolds' => $numHoldsAvailable + $numHoldsRequested, 'numHoldsAvailable' => $numHoldsAvailable, 'numHoldsRequested' => $numHoldsRequested, 'bypassAutoLogout' => $user ? $user->bypassAutoLogout : 0, 'ptype' => 0, 'notices' => '-', 'noticePreferenceLabel' => 'e-mail', 'web_note' => '');
     //Get eContent info as well
     require_once ROOT_DIR . '/Drivers/EContentDriver.php';
     $eContentDriver = new EContentDriver();
     $eContentAccountSummary = $eContentDriver->getAccountSummary();
     $profile = array_merge($profile, $eContentAccountSummary);
     require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
     $overDriveDriver = OverDriveDriverFactory::getDriver();
     if ($overDriveDriver->isUserValidForOverDrive($user)) {
         $overDriveSummary = $overDriveDriver->getOverDriveSummary($user);
         $profile['numOverDriveCheckedOut'] = $overDriveSummary['numCheckedOut'];
         $profile['numOverDriveHoldsAvailable'] = $overDriveSummary['numAvailableHolds'];
         $profile['numOverDriveHoldsRequested'] = $overDriveSummary['numUnavailableHolds'];
         $profile['canUseOverDrive'] = true;
     } else {
         $profile['numOverDriveCheckedOut'] = 0;
         $profile['numOverDriveHoldsAvailable'] = 0;
         $profile['numOverDriveHoldsRequested'] = 0;
         $profile['canUseOverDrive'] = false;
     }
     $profile['numCheckedOutTotal'] = $profile['numCheckedOut'] + $profile['numOverDriveCheckedOut'] + $eContentAccountSummary['numEContentCheckedOut'];
     $profile['numHoldsAvailableTotal'] = $profile['numHoldsAvailable'] + $profile['numOverDriveHoldsAvailable'] + $eContentAccountSummary['numEContentAvailableHolds'];
     $profile['numHoldsRequestedTotal'] = $profile['numHoldsRequested'] + $profile['numOverDriveHoldsRequested'] + $eContentAccountSummary['numEContentUnavailableHolds'];
     $profile['numHoldsTotal'] = $profile['numHoldsAvailableTotal'] + $profile['numHoldsRequestedTotal'];
     //Get a count of the materials requests for the user
     if ($user) {
         $materialsRequest = new MaterialsRequest();
         $materialsRequest->createdBy = $user->id;
         $homeLibrary = Library::getPatronHomeLibrary();
         $statusQuery = new MaterialsRequestStatus();
         $statusQuery->isOpen = 1;
         $statusQuery->libraryId = $homeLibrary->libraryId;
         $materialsRequest->joinAdd($statusQuery);
         $materialsRequest->find();
         $profile['numMaterialsRequests'] = $materialsRequest->N;
     }
     $timer->logTime("Got Patron Profile");
     $memCache->set($memCacheProfileKey, $profile, 0, $configArray['Caching']['patron_profile']);
     return $profile;
 }
示例#2
0
 public function getMyProfile($patron, $forceReload = false)
 {
     global $timer;
     global $configArray;
     if (is_object($patron)) {
         $patron = get_object_vars($patron);
     }
     if (array_key_exists($patron['username'], $this->patronProfiles) && !$forceReload) {
         $timer->logTime('Retrieved Cached Profile for Patron');
         return $this->patronProfiles[$patron['username']];
     }
     $mysip = new sip2();
     $mysip->hostname = $configArray['SIP2']['host'];
     $mysip->port = $configArray['SIP2']['port'];
     if ($mysip->connect()) {
         //send selfcheck status message
         $in = $mysip->msgSCStatus();
         $msg_result = $mysip->get_message($in);
         // Make sure the response is 98 as expected
         if (preg_match("/^98/", $msg_result)) {
             $result = $mysip->parseACSStatusResponse($msg_result);
             //  Use result to populate SIP2 setings
             $mysip->AO = $result['variable']['AO'][0];
             /* set AO to value returned */
             $mysip->AN = $result['variable']['AN'][0];
             /* set AN to value returned */
             $mysip->patron = $patron['username'];
             $mysip->patronpwd = $patron['cat_password'];
             $in = $mysip->msgPatronInformation('fine');
             $msg_result = $mysip->get_message($in);
             // Make sure the response is 24 as expected
             if (preg_match("/^64/", $msg_result)) {
                 $result = $mysip->parsePatronInfoResponse($msg_result);
                 $address = $result['variable']['BD'][0];
                 $addressParts = explode(',', $address);
                 $expirationDate = $result['variable']['PE'][0];
                 $formattedExpiration = substr($expirationDate, 4, 2) . '/' . substr($expirationDate, 6, 2) . '/' . substr($expirationDate, 0, 4);
                 //$fines = $this->parseSip2Fines($result['variable']['AV']);
                 $location = new Location();
                 $location->code = $result['variable']['AQ'][0];
                 $location->find();
                 if ($location->N > 0) {
                     $location->fetch();
                     $homeLocationId = $location->locationId;
                 }
                 global $user;
                 $profile = array('lastname' => $result['variable']['DJ'][0], 'firstname' => isset($result['variable']['DH'][0]) ? $result['variable']['DH'][0] : '', 'displayName' => $patron['displayName'], 'fullname' => $result['variable']['AE'][0], 'address1' => trim($addressParts[0]), 'city' => trim($addressParts[1]), 'state' => trim($addressParts[2]), 'zip' => isset($addressParts[3]) ? trim($addressParts[3]) : '', 'phone' => isset($result['variable']['BF'][0]) ? $result['variable']['BF'][0] : '', 'email' => isset($result['variable']['BE'][0]) ? $result['variable']['BE'][0] : '', 'homeLocationId' => isset($homeLocationId) ? $homeLocationId : -1, 'homeLocationName' => $this->translateLocation($result['variable']['AQ'][0]), 'expires' => $formattedExpiration, 'fines' => isset($result['variable']['BV']) ? sprintf('$%01.2f', $result['variable']['BV'][0]) : 0, 'finesval' => isset($result['variable']['BV']) ? $result['variable']['BV'][0] : '', 'numHolds' => $result['fixed']['HoldCount'] + $result['fixed']['UnavailableCount'], 'numHoldsAvailable' => $result['fixed']['HoldCount'], 'numHoldsRequested' => $result['fixed']['UnavailableCount'], 'numCheckedOut' => $result['fixed']['ChargedCount'], 'bypassAutoLogout' => $user ? $user->bypassAutoLogout : false);
                 //Get eContent info as well
                 require_once ROOT_DIR . '/Drivers/EContentDriver.php';
                 $eContentDriver = new EContentDriver();
                 $eContentAccountSummary = $eContentDriver->getAccountSummary();
                 $profile = array_merge($profile, $eContentAccountSummary);
                 //Get a count of the materials requests for the user
                 $materialsRequest = new MaterialsRequest();
                 $materialsRequest->createdBy = $user->id;
                 $statusQuery = new MaterialsRequestStatus();
                 $statusQuery->isOpen = 1;
                 $materialsRequest->joinAdd($statusQuery);
                 $materialsRequest->find();
                 $profile['numMaterialsRequests'] = $materialsRequest->N;
             } else {
                 $profile = new PEAR_Error('patron_info_error_technical');
             }
         } else {
             $profile = new PEAR_Error('patron_info_error_technical');
         }
         $mysip->disconnect();
     } else {
         $profile = new PEAR_Error('patron_info_error_technical');
     }
     $this->patronProfiles[$patron['username']] = $profile;
     $timer->logTime('Retrieved Profile for Patron from SIP 2');
     return $profile;
 }
示例#3
0
 /**
  * Get Patron Profile
  *
  * This is responsible for retrieving the profile for a specific patron.
  * Interface defined in CatalogConnection.php
  *
  * @param   array   $patron     The patron array
  * @return  array               Array of the patron's profile data
  *                              If an error occures, return a PEAR_Error
  * @access  public
  */
 public function getMyProfile($patron)
 {
     global $timer;
     global $configArray;
     if (is_object($patron)) {
         $patron = get_object_vars($patron);
         $id2 = $this->_getBarcode();
     } else {
         $id2 = $patron['id'];
     }
     if (array_key_exists($patron['id'], $this->patronProfiles)) {
         $timer->logTime('Retrieved Cached Profile for Patron');
         return $this->patronProfiles[$patron['id']];
     }
     //Load the raw information about the patron
     $patronDump = $this->_getPatronDump($id2);
     if (isset($patronDump['ADDRESS'])) {
         $Fulladdress = $patronDump['ADDRESS'];
         $addressParts = explode('$', $Fulladdress);
         $Address1 = $addressParts[0];
         $City = isset($addressParts[1]) ? $addressParts[1] : '';
         $State = isset($addressParts[2]) ? $addressParts[2] : '';
         $Zip = isset($addressParts[3]) ? $addressParts[3] : '';
         if (preg_match('/(.*?),\\s+(.*)\\s+(\\d*(?:-\\d*)?)/', $City, $matches)) {
             $City = $matches[1];
             $State = $matches[2];
             $Zip = $matches[3];
         }
     } else {
         $Address1 = "";
         $City = "";
         $State = "";
         $Zip = "";
     }
     $fullName = $patronDump['PATRN_NAME'];
     $nameParts = explode(', ', $fullName);
     $lastName = $nameParts[0];
     $secondName = isset($nameParts[1]) ? $nameParts[1] : '';
     if (strpos($secondName, ' ')) {
         $nameParts2 = explode(' ', $secondName);
         $firstName = $nameParts2[0];
     } else {
         $firstName = $secondName;
     }
     //Get additional information about the patron's home branch for display.
     $homeBranchCode = $patronDump['HOME_LIBR'];
     //Translate home branch to plain text
     global $user;
     $location = new Location();
     $location->whereAdd("code = '{$homeBranchCode}'");
     $location->find(1);
     if ($user) {
         if ($user->homeLocationId == 0) {
             $user->homeLocationId = $location->locationId;
             if ($location->nearbyLocation1 > 0) {
                 $user->myLocation1Id = $location->nearbyLocation1;
             } else {
                 $user->myLocation1Id = $location->locationId;
             }
             if ($location->nearbyLocation2 > 0) {
                 $user->myLocation2Id = $location->nearbyLocation2;
             } else {
                 $user->myLocation2Id = $location->locationId;
             }
             if ($user instanceof User) {
                 //Update the database
                 $user->update();
                 //Update the serialized instance stored in the session
                 $_SESSION['userinfo'] = serialize($user);
             }
         }
         //Get display name for preferred location 1
         $myLocation1 = new Location();
         $myLocation1->whereAdd("locationId = '{$user->myLocation1Id}'");
         $myLocation1->find(1);
         //Get display name for preferred location 1
         $myLocation2 = new Location();
         $myLocation2->whereAdd("locationId = '{$user->myLocation2Id}'");
         $myLocation2->find(1);
     }
     //see if expiration date is close
     list($monthExp, $dayExp, $yearExp) = explode("-", $patronDump['EXP_DATE']);
     $timeExpire = strtotime($monthExp . "/" . $dayExp . "/" . $yearExp);
     $timeNow = time();
     $timeToExpire = $timeExpire - $timeNow;
     if ($timeToExpire <= 30 * 24 * 60 * 60) {
         $expireClose = 1;
     } else {
         $expireClose = 0;
     }
     $finesVal = floatval(preg_replace('/[^\\d.]/', '', $patronDump['MONEY_OWED']));
     $numHoldsAvailable = 0;
     $numHoldsRequested = 0;
     $availableStatusRegex = isset($configArray['Catalog']['patronApiAvailableHoldsRegex']) ? $configArray['Catalog']['patronApiAvailableHoldsRegex'] : "/ST=(105|98),/";
     if (isset($patronDump['HOLD']) && count($patronDump['HOLD']) > 0) {
         foreach ($patronDump['HOLD'] as $hold) {
             if (preg_match("{$availableStatusRegex}", $hold)) {
                 $numHoldsAvailable++;
             } else {
                 $numHoldsRequested++;
             }
         }
     }
     $profile = array('lastname' => $lastName, 'firstname' => $firstName, 'fullname' => $fullName, 'address1' => $Address1, 'address2' => $City . ', ' . $State, 'city' => $City, 'state' => $State, 'zip' => $Zip, 'email' => isset($patronDump['EMAIL_ADDR']) ? $patronDump['EMAIL_ADDR'] : '', 'overdriveEmail' => $user ? $user->overdriveEmail : (isset($patronDump['EMAIL_ADDR']) ? $patronDump['EMAIL_ADDR'] : ''), 'promptForOverdriveEmail' => $user ? $user->promptForOverdriveEmail : 1, 'phone' => isset($patronDump['TELEPHONE']) ? $patronDump['TELEPHONE'] : '', 'fines' => $patronDump['MONEY_OWED'], 'finesval' => $finesVal, 'expires' => $patronDump['EXP_DATE'], 'expireclose' => $expireClose, 'homeLocationCode' => trim($homeBranchCode), 'homeLocationId' => $location->locationId, 'homeLocation' => $location->displayName, 'myLocation1Id' => $user ? $user->myLocation1Id : -1, 'myLocation1' => isset($myLocation1) ? $myLocation1->displayName : '', 'myLocation2Id' => $user ? $user->myLocation2Id : -1, 'myLocation2' => isset($myLocation2) ? $myLocation2->displayName : '', 'numCheckedOut' => $patronDump['CUR_CHKOUT'], 'numHolds' => isset($patronDump['HOLD']) ? count($patronDump['HOLD']) : 0, 'numHoldsAvailable' => $numHoldsAvailable, 'numHoldsRequested' => $numHoldsRequested, 'bypassAutoLogout' => $user ? $user->bypassAutoLogout : 0, 'ptype' => $patronDump['P_TYPE'], 'notices' => $patronDump['NOTICE_PREF'], 'web_note' => isset($patronDump['WEB_NOTE']) ? $patronDump['WEB_NOTE'] : '');
     //Get eContent info as well
     require_once ROOT_DIR . '/Drivers/EContentDriver.php';
     $eContentDriver = new EContentDriver();
     $eContentAccountSummary = $eContentDriver->getAccountSummary();
     $profile = array_merge($profile, $eContentAccountSummary);
     //Get a count of the materials requests for the user
     if ($user) {
         $materialsRequest = new MaterialsRequest();
         $materialsRequest->createdBy = $user->id;
         $homeLibrary = Library::getPatronHomeLibrary();
         $statusQuery = new MaterialsRequestStatus();
         $statusQuery->isOpen = 1;
         $statusQuery->libraryId = $homeLibrary->libraryId;
         $materialsRequest->joinAdd($statusQuery);
         $materialsRequest->find();
         $profile['numMaterialsRequests'] = $materialsRequest->N;
     }
     $timer->logTime("Got Patron Profile");
     $this->patronProfiles[$patron['id']] = $profile;
     return $profile;
 }
示例#4
0
 /**
  * @param User $patron
  * @param bool $forceReload
  * @return array
  */
 public function getMyProfile($patron, $forceReload = false)
 {
     //Update to not use SIP, just screen scrape for performance (sigh)
     global $timer;
     /** @var Memcache $memCache */
     global $memCache;
     if (!is_object($patron)) {
         $tmpPatron = new User();
         $tmpPatron->username = $patron['username'];
         $tmpPatron->cat_username = $patron['cat_username'];
         $tmpPatron->cat_password = $patron['cat_password'];
         $tmpPatron->firstname = $patron['firstname'];
         $tmpPatron->lastname = $patron['lastname'];
         $tmpPatron->email = $patron['email'];
         $tmpPatron->patronType = $patron['patronType'];
         $patron = $tmpPatron;
     }
     if (!$forceReload && !isset($_REQUEST['reload'])) {
         // Check the Object for profile
         if (array_key_exists($patron->username, $this->patronProfiles)) {
             $timer->logTime('Retrieved Cached Profile for Patron');
             return $this->patronProfiles[$patron->username];
         }
     }
     // Determine memcache key
     global $serverName;
     $memCacheProfileKey = "patronProfile_{$serverName}_";
     if (is_object($patron) && !isset($tmpPatron)) {
         // exclude the new patron object $tmpPatron created above. It won't have an id or be stored in memcache
         //				$patron         = get_object_vars($patron);
         //			$memCacheProfileKey = $patron['username'];
         // $patron needs to remain an object for initial loading below
         $memCacheProfileKey .= $patron->username;
     } else {
         global $user;
         //				$memCacheProfileKey = $user->id;
         $memCacheProfileKey .= $user->username;
     }
     // Check MemCache for profile
     if (!$forceReload && !isset($_REQUEST['reload'])) {
         $patronProfile = $memCache->get($memCacheProfileKey);
         if ($patronProfile) {
             //echo("Using cached profile for patron " . $userId);
             $timer->logTime('Retrieved Cached Profile for Patron');
             return $patronProfile;
         }
     }
     $this->initDatabaseConnection();
     $this->getUserInfoStmt->bind_param('ss', $patron->cat_username, $patron->cat_username);
     if ($this->getUserInfoStmt->execute()) {
         if ($userFromDbResultSet = $this->getUserInfoStmt->get_result()) {
             $userFromDb = $userFromDbResultSet->fetch_assoc();
             $userFromDbResultSet->close();
             //				$city = $userFromDb['city'];
             //				$state = "";
             //				$commaPos = strpos($city, ',');
             //				if ($commaPos !== false){ // fix this
             //					$cityState = $city;
             //					$city = substr($cityState, 0, $commaPos);
             //					$state = substr($cityState, $commaPos);
             //				}
             $city = strtok($userFromDb['city'], ',');
             $state = strtok(',');
             $city = trim($city);
             $state = trim($state);
             //Get fines
             //Load fines from database
             $outstandingFines = $this->getOutstandingFineTotal();
             //Get number of items checked out
             $checkedOutItemsRS = mysqli_query($this->dbConnection, 'SELECT count(*) as numCheckouts FROM issues WHERE borrowernumber = ' . $patron->username);
             $numCheckouts = 0;
             if ($checkedOutItemsRS) {
                 $checkedOutItems = $checkedOutItemsRS->fetch_assoc();
                 $numCheckouts = $checkedOutItems['numCheckouts'];
                 $checkedOutItemsRS->close();
             }
             //Get number of available holds
             $availableHoldsRS = mysqli_query($this->dbConnection, 'SELECT count(*) as numHolds FROM reserves WHERE waitingdate is not null and borrowernumber = ' . $patron->username);
             $numAvailableHolds = 0;
             if ($availableHoldsRS) {
                 $availableHolds = $availableHoldsRS->fetch_assoc();
                 $numAvailableHolds = $availableHolds['numHolds'];
                 $availableHoldsRS->close();
             }
             //Get number of unavailable
             $waitingHoldsRS = mysqli_query($this->dbConnection, 'SELECT count(*) as numHolds FROM reserves WHERE waitingdate is null and borrowernumber = ' . $patron->username);
             $numWaitingHolds = 0;
             if ($waitingHoldsRS) {
                 $waitingHolds = $waitingHoldsRS->fetch_assoc();
                 $numWaitingHolds = $waitingHolds['numHolds'];
                 $waitingHoldsRS->close();
             }
             $homeBranchCode = $userFromDb['branchcode'];
             $location = new Location();
             $location->code = $homeBranchCode;
             $location->find(1);
             if ($location->N == 0) {
                 unset($location);
             }
             global $user;
             $profile = array('lastname' => $patron->lastname, 'firstname' => $patron->firstname, 'displayName' => isset($patron->displayName) ? $patron->displayName : '', 'fullname' => $user->lastname . ', ' . $user->firstname, 'address1' => trim($userFromDb['streetnumber'] . ' ' . $userFromDb['address'] . ' ' . $userFromDb['address2']), 'city' => $city, 'state' => $state, 'zip' => $userFromDb['zipcode'], 'phone' => $userFromDb['phone'], 'email' => $userFromDb['email'], 'homeLocationId' => isset($location) ? $location->locationId : -1, 'homeLocationName' => '', 'expires' => $userFromDb['dateexpiry'], 'fines' => sprintf('$%0.2f', $outstandingFines), 'finesval' => floatval($outstandingFines), 'numHolds' => $numWaitingHolds + $numAvailableHolds, 'numHoldsAvailable' => $numAvailableHolds, 'numHoldsRequested' => $numWaitingHolds, 'numCheckedOut' => $numCheckouts, 'bypassAutoLogout' => $user ? $user->bypassAutoLogout : false);
             $profile['noticePreferenceLabel'] = 'Unknown';
             //Get eContent info as well
             require_once ROOT_DIR . '/Drivers/EContentDriver.php';
             $eContentDriver = new EContentDriver();
             $eContentAccountSummary = $eContentDriver->getAccountSummary();
             $profile = array_merge($profile, $eContentAccountSummary);
             require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
             $overDriveDriver = OverDriveDriverFactory::getDriver();
             if ($overDriveDriver->isUserValidForOverDrive($user)) {
                 $overDriveSummary = $overDriveDriver->getOverDriveSummary($user);
                 $profile['numOverDriveCheckedOut'] = $overDriveSummary['numCheckedOut'];
                 $profile['numOverDriveHoldsAvailable'] = $overDriveSummary['numAvailableHolds'];
                 $profile['numOverDriveHoldsRequested'] = $overDriveSummary['numUnavailableHolds'];
                 $profile['canUseOverDrive'] = true;
             } else {
                 $profile['numOverDriveCheckedOut'] = 0;
                 $profile['numOverDriveHoldsAvailable'] = 0;
                 $profile['numOverDriveHoldsRequested'] = 0;
                 $profile['canUseOverDrive'] = false;
             }
             $profile['numCheckedOutTotal'] = $profile['numCheckedOut'] + $profile['numOverDriveCheckedOut'] + $eContentAccountSummary['numEContentCheckedOut'];
             $profile['numHoldsAvailableTotal'] = $profile['numHoldsAvailable'] + $profile['numOverDriveHoldsAvailable'] + $eContentAccountSummary['numEContentAvailableHolds'];
             $profile['numHoldsRequestedTotal'] = $profile['numHoldsRequested'] + $profile['numOverDriveHoldsRequested'] + $eContentAccountSummary['numEContentUnavailableHolds'];
             $profile['numHoldsTotal'] = $profile['numHoldsAvailableTotal'] + $profile['numHoldsRequestedTotal'];
             //Get a count of the materials requests for the user
             if ($user) {
                 $homeLibrary = Library::getPatronHomeLibrary();
                 if ($homeLibrary) {
                     $materialsRequest = new MaterialsRequest();
                     $materialsRequest->createdBy = $user->id;
                     $statusQuery = new MaterialsRequestStatus();
                     $statusQuery->isOpen = 1;
                     $statusQuery->libraryId = $homeLibrary->libraryId;
                     $materialsRequest->joinAdd($statusQuery);
                     $materialsRequest->find();
                     $profile['numMaterialsRequests'] = $materialsRequest->N;
                 } else {
                     $profile['numMaterialsRequests'] = 0;
                 }
                 if ($user->homeLocationId == 0 && isset($location)) {
                     $user->homeLocationId = $location->locationId;
                     if ($location->nearbyLocation1 > 0) {
                         $user->myLocation1Id = $location->nearbyLocation1;
                     } else {
                         $user->myLocation1Id = $location->locationId;
                     }
                     if ($location->nearbyLocation2 > 0) {
                         $user->myLocation2Id = $location->nearbyLocation2;
                     } else {
                         $user->myLocation2Id = $location->locationId;
                     }
                     if ($user instanceof User) {
                         //Update the database
                         $user->update();
                         //Update the serialized instance stored in the session
                         $_SESSION['userinfo'] = serialize($user);
                     }
                 } else {
                     if (isset($location) && $location->locationId != $user->homeLocationId) {
                         $user->homeLocationId = $location->locationId;
                         //Update the database
                         $user->update();
                         //Update the serialized instance stored in the session
                         $_SESSION['userinfo'] = serialize($user);
                     }
                 }
             }
         } else {
             $profile = PEAR_Singleton::raiseError('patron_info_error_technical - could not load from database');
         }
     } else {
         $profile = PEAR_Singleton::raiseError('patron_info_error_technical - could not execute user info statement');
     }
     $this->patronProfiles[$patron->username] = $profile;
     $timer->logTime('Retrieved Profile for Patron from Database');
     global $configArray, $serverName;
     $memCache->set($memCacheProfileKey, $profile, 0, $configArray['Caching']['patron_profile']);
     // Looks like all drivers but aspencat use id rather than username.
     // plb 4-16-2014
     return $profile;
 }
示例#5
0
 /**
  * Get Patron Profile
  *
  * This is responsible for retrieving the profile for a specific patron.
  * Interface defined in CatalogConnection.php
  *
  * @param   array   $patron     The patron array
  * @param   boolean $forceReload Whether or not we should force a reload of the data
  * @return  array               Array of the patron's profile data
  *                              If an error occurs, return a PEAR_Error
  * @access  public
  */
 public function getMyProfile($patron, $forceReload = false)
 {
     global $timer;
     global $configArray;
     /** @var Memcache $memCache */
     global $memCache;
     global $serverName;
     $memCacheProfileKey = "patronProfile_{$serverName}_";
     if (is_object($patron)) {
         $patron = get_object_vars($patron);
         $memCacheProfileKey .= $patron['username'];
         $id2 = $this->_getBarcode($patron);
     } else {
         global $user;
         $memCacheProfileKey .= $user->username;
         $id2 = $patron['cat_password'];
     }
     if (!$forceReload && !isset($_REQUEST['reload'])) {
         $patronProfile = $memCache->get($memCacheProfileKey);
         if ($patronProfile) {
             $timer->logTime('Retrieved Cached Profile for Patron');
             return $patronProfile;
         }
     }
     global $user;
     if ($configArray['Catalog']['offline'] == true) {
         $fullName = $patron['cat_username'];
         $Address1 = "";
         $City = "";
         $State = "";
         $Zip = "";
         $finesVal = 0;
         $expireClose = false;
         $homeBranchCode = '';
         $numHoldsAvailable = '?';
         $numHoldsRequested = '?';
         if (!$user) {
             $user = new User();
             $user->cat_password = $id2;
             if ($user->find(true)) {
                 $location = new Location();
                 $location->locationId = $user->homeLocationId;
                 $location->find(1);
                 $homeBranchCode = $location->code;
             }
         }
     } else {
         //Load the raw information about the patron
         $patronDump = $this->_getPatronDump($id2);
         if (isset($patronDump['ADDRESS'])) {
             $fullAddress = $patronDump['ADDRESS'];
             $addressParts = explode('$', $fullAddress);
             $Address1 = $addressParts[0];
             $City = isset($addressParts[1]) ? $addressParts[1] : '';
             $State = isset($addressParts[2]) ? $addressParts[2] : '';
             $Zip = isset($addressParts[3]) ? $addressParts[3] : '';
             if (preg_match('/(.*?),\\s+(.*)\\s+(\\d*(?:-\\d*)?)/', $City, $matches)) {
                 $City = $matches[1];
                 $State = $matches[2];
                 $Zip = $matches[3];
             } else {
                 if (preg_match('/(.*?)\\s+(\\w{2})\\s+(\\d*(?:-\\d*)?)/', $City, $matches)) {
                     $City = $matches[1];
                     $State = $matches[2];
                     $Zip = $matches[3];
                 }
             }
         } else {
             $Address1 = "";
             $City = "";
             $State = "";
             $Zip = "";
         }
         $fullName = $patronDump['PATRN_NAME'];
         //Get additional information about the patron's home branch for display.
         $location = null;
         if (isset($patronDump['HOME_LIBR']) || isset($patronDump['HOLD_LIBR'])) {
             $homeBranchCode = isset($patronDump['HOME_LIBR']) ? $patronDump['HOME_LIBR'] : $patronDump['HOLD_LIBR'];
             $homeBranchCode = str_replace('+', '', $homeBranchCode);
             //Translate home branch to plain text
             $location = new Location();
             $location->whereAdd("code = '{$homeBranchCode}'");
             $location->find(1);
             if ($location->N == 0) {
                 unset($location);
             }
         }
         if ($user) {
             if (isset($location)) {
                 if ($user->homeLocationId == 0) {
                     $user->homeLocationId = $location->locationId;
                     if ($location->nearbyLocation1 > 0) {
                         $user->myLocation1Id = $location->nearbyLocation1;
                     } else {
                         $user->myLocation1Id = $location->locationId;
                     }
                     if ($location->nearbyLocation2 > 0) {
                         $user->myLocation2Id = $location->nearbyLocation2;
                     } else {
                         $user->myLocation2Id = $location->locationId;
                     }
                     if ($user instanceof User) {
                         //Update the database
                         $user->update();
                         //Update the serialized instance stored in the session
                         $_SESSION['userinfo'] = serialize($user);
                     }
                 } else {
                     if ($location->locationId != $user->homeLocationId) {
                         $user->homeLocationId = $location->locationId;
                         //Update the database
                         $user->update();
                         //Update the serialized instance stored in the session
                         $_SESSION['userinfo'] = serialize($user);
                     }
                 }
             }
         }
         //see if expiration date is close
         if (trim($patronDump['EXP_DATE']) != '-  -') {
             list($monthExp, $dayExp, $yearExp) = explode("-", $patronDump['EXP_DATE']);
             $timeExpire = strtotime($monthExp . "/" . $dayExp . "/" . $yearExp);
             $timeNow = time();
             $timeToExpire = $timeExpire - $timeNow;
             $expired = 0;
             if ($timeToExpire <= 30 * 24 * 60 * 60) {
                 if ($timeToExpire <= 0) {
                     $expired = 1;
                 }
                 $expireClose = 1;
             } else {
                 $expireClose = 0;
             }
         } else {
             $expired = 0;
             $expireClose = 0;
         }
         $finesVal = floatval(preg_replace('/[^\\d.]/', '', $patronDump['MONEY_OWED']));
         $numHoldsAvailable = 0;
         $numHoldsRequested = 0;
         $availableStatusRegex = isset($configArray['Catalog']['patronApiAvailableHoldsRegex']) ? $configArray['Catalog']['patronApiAvailableHoldsRegex'] : "/ST=(105|98),/";
         if (isset($patronDump) && isset($patronDump['HOLD']) && count($patronDump['HOLD']) > 0) {
             foreach ($patronDump['HOLD'] as $hold) {
                 if (preg_match("{$availableStatusRegex}", $hold)) {
                     $numHoldsAvailable++;
                 } else {
                     $numHoldsRequested++;
                 }
             }
         }
     }
     $nameParts = explode(', ', $fullName);
     $lastName = $nameParts[0];
     $secondName = isset($nameParts[1]) ? $nameParts[1] : '';
     if (strpos($secondName, ' ')) {
         $nameParts2 = explode(' ', $secondName);
         $firstName = $nameParts2[0];
     } else {
         $firstName = $secondName;
     }
     if ($user) {
         //Get display name for preferred location 1
         $myLocation1 = new Location();
         $myLocation1->whereAdd("locationId = '{$user->myLocation1Id}'");
         $myLocation1->find(1);
         //Get display name for preferred location 1
         $myLocation2 = new Location();
         $myLocation2->whereAdd("locationId = '{$user->myLocation2Id}'");
         $myLocation2->find(1);
     }
     $noticeLabels = array('-' => '', 'a' => 'Mail', 'p' => 'Telephone', 'z' => 'E-mail');
     $profile = array('lastname' => $lastName, 'firstname' => $firstName, 'fullname' => $fullName, 'address1' => $Address1, 'address2' => $City . ', ' . $State, 'city' => $City, 'state' => $State, 'zip' => $Zip, 'email' => $user && $user->email ? $user->email : (isset($patronDump) && isset($patronDump['EMAIL_ADDR']) ? $patronDump['EMAIL_ADDR'] : ''), 'overdriveEmail' => $user ? $user->overdriveEmail : (isset($patronDump) && isset($patronDump['EMAIL_ADDR']) ? $patronDump['EMAIL_ADDR'] : ''), 'promptForOverdriveEmail' => $user ? $user->promptForOverdriveEmail : 1, 'phone' => isset($patronDump) && isset($patronDump['TELEPHONE']) ? $patronDump['TELEPHONE'] : (isset($patronDump['HOME_PHONE']) ? $patronDump['HOME_PHONE'] : ''), 'workPhone' => isset($patronDump) && isset($patronDump['G/WK_PHONE']) ? $patronDump['G/WK_PHONE'] : '', 'mobileNumber' => isset($patronDump) && isset($patronDump['MOBILE_NO']) ? $patronDump['MOBILE_NO'] : '', 'fines' => isset($patronDump) ? $patronDump['MONEY_OWED'] : '0', 'finesval' => $finesVal, 'expires' => isset($patronDump) ? $patronDump['EXP_DATE'] : '', 'expireclose' => $expireClose, 'expired' => $expired, 'homeLocationCode' => isset($homeBranchCode) ? trim($homeBranchCode) : '', 'homeLocationId' => isset($location) ? $location->locationId : 0, 'homeLocation' => isset($location) ? $location->displayName : '', 'myLocation1Id' => $user ? $user->myLocation1Id : -1, 'myLocation1' => isset($myLocation1) ? $myLocation1->displayName : '', 'myLocation2Id' => $user ? $user->myLocation2Id : -1, 'myLocation2' => isset($myLocation2) ? $myLocation2->displayName : '', 'numCheckedOut' => isset($patronDump) ? $patronDump['CUR_CHKOUT'] : '?', 'numHolds' => isset($patronDump) ? isset($patronDump['HOLD']) ? count($patronDump['HOLD']) : 0 : '?', 'numHoldsAvailable' => $numHoldsAvailable, 'numHoldsRequested' => $numHoldsRequested, 'bypassAutoLogout' => $user ? $user->bypassAutoLogout : 0, 'ptype' => $user && $user->patronType ? $user->patronType : (isset($patronDump) ? $patronDump['P_TYPE'] : 0), 'notices' => isset($patronDump) ? $patronDump['NOTICE_PREF'] : '-', 'web_note' => isset($patronDump) ? isset($patronDump['WEB_NOTE']) ? $patronDump['WEB_NOTE'] : '' : '');
     if (array_key_exists($profile['notices'], $noticeLabels)) {
         $profile['noticePreferenceLabel'] = $noticeLabels[$profile['notices']];
     } else {
         $profile['noticePreferenceLabel'] = 'Unknown';
     }
     //Get eContent info as well
     require_once ROOT_DIR . '/Drivers/EContentDriver.php';
     $eContentDriver = new EContentDriver();
     $eContentAccountSummary = $eContentDriver->getAccountSummary();
     $profile = array_merge($profile, $eContentAccountSummary);
     require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
     $overDriveDriver = OverDriveDriverFactory::getDriver();
     if ($overDriveDriver->isUserValidForOverDrive($user)) {
         $overDriveSummary = $overDriveDriver->getOverDriveSummary($user);
         $profile['numOverDriveCheckedOut'] = $overDriveSummary['numCheckedOut'];
         $profile['numOverDriveHoldsAvailable'] = $overDriveSummary['numAvailableHolds'];
         $profile['numOverDriveHoldsRequested'] = $overDriveSummary['numUnavailableHolds'];
         $profile['canUseOverDrive'] = true;
     } else {
         $profile['numOverDriveCheckedOut'] = 0;
         $profile['numOverDriveHoldsAvailable'] = 0;
         $profile['numOverDriveHoldsRequested'] = 0;
         $profile['canUseOverDrive'] = false;
     }
     $profile['numCheckedOutTotal'] = $profile['numCheckedOut'] + $profile['numOverDriveCheckedOut'] + $eContentAccountSummary['numEContentCheckedOut'];
     $profile['numHoldsAvailableTotal'] = $profile['numHoldsAvailable'] + $profile['numOverDriveHoldsAvailable'] + $eContentAccountSummary['numEContentAvailableHolds'];
     $profile['numHoldsRequestedTotal'] = $profile['numHoldsRequested'] + $profile['numOverDriveHoldsRequested'] + $eContentAccountSummary['numEContentUnavailableHolds'];
     $profile['numHoldsTotal'] = $profile['numHoldsAvailableTotal'] + $profile['numHoldsRequestedTotal'];
     //Get a count of the materials requests for the user
     if ($user) {
         $materialsRequest = new MaterialsRequest();
         $materialsRequest->createdBy = $user->id;
         $homeLibrary = Library::getPatronHomeLibrary();
         $statusQuery = new MaterialsRequestStatus();
         $statusQuery->isOpen = 1;
         $statusQuery->libraryId = $homeLibrary->libraryId;
         $materialsRequest->joinAdd($statusQuery);
         $materialsRequest->find();
         $profile['numMaterialsRequests'] = $materialsRequest->N;
     }
     $timer->logTime("Got Patron Profile");
     $memCache->set($memCacheProfileKey, $profile, 0, $configArray['Caching']['patron_profile']);
     return $profile;
 }