Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 public function authenticate()
 {
     global $configArray;
     global $timer;
     if (isset($_POST['username']) && isset($_POST['password'])) {
         $username = $_POST['username'];
         $password = $_POST['password'];
         //Set this up to use library prefix
         $barcodePrefix = $configArray['Catalog']['barcodePrefix'];
         if (strlen($barcodePrefix) > 0) {
             if (strlen($username) == 9) {
                 $username = substr($barcodePrefix, 0, 5) . $username;
             } elseif (strlen($username) == 8) {
                 $username = substr($barcodePrefix, 0, 6) . $username;
             } elseif (strlen($username) == 7) {
                 $username = $barcodePrefix . $username;
             }
         }
         //Check to see if we have already processed this user
         if (array_key_exists($username, self::$processedUsers)) {
             return self::$processedUsers[$username];
         }
         if ($username != '' && $password != '') {
             // Attempt SIP2 Authentication
             $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 */
                     if (isset($result['variable']['AN'])) {
                         $mysip->AN = $result['variable']['AN'][0];
                         /* set AN to value returned */
                     }
                     $mysip->patron = $username;
                     $mysip->patronpwd = $password;
                     $in = $mysip->msgPatronStatusRequest();
                     $msg_result = $mysip->get_message($in);
                     // Make sure the response is 24 as expected
                     if (preg_match("/^24/", $msg_result)) {
                         $result = $mysip->parsePatronStatusResponse($msg_result);
                         if ($result['variable']['BL'][0] == 'Y' and $result['variable']['CQ'][0] == 'Y') {
                             //Get patron info as well
                             $in = $mysip->msgPatronInformation('none');
                             $msg_result = $mysip->get_message($in);
                             // Make sure the response is 24 as expected
                             if (preg_match("/^64/", $msg_result)) {
                                 $patronInfoResponse = $mysip->parsePatronInfoResponse($msg_result);
                                 //print_r($patronInfoResponse);
                             }
                             // Success!!!
                             $user = $this->processSIP2User($result, $username, $password, $patronInfoResponse);
                             // Set login cookie for 1 hour
                             $user->password = $password;
                             // Need this for Metalib
                         } else {
                             $user = new PEAR_Error('authentication_error_invalid');
                         }
                     } else {
                         $user = new PEAR_Error('authentication_error_technical');
                     }
                 } else {
                     $user = new PEAR_Error('authentication_error_technical');
                 }
                 $mysip->disconnect();
             } else {
                 $user = new PEAR_Error('authentication_error_technical');
                 global $logger;
                 $logger->log("Unable to connect to SIP server", PEAR_LOG_ERR);
             }
         } else {
             $user = new PEAR_Error('authentication_error_blank');
         }
         $timer->logTime("Authenticated user in SIP2Authentication");
         self::$processedUsers[$username] = $user;
     } else {
         $user = new PEAR_Error('authentication_error_blank');
     }
     return $user;
 }