/**
  * @param String $acsId
  * @param EContentCheckout $eContentCheckout
  * @return null|string
  */
 static function mintDownloadLink($acsId, $eContentCheckout)
 {
     global $configArray;
     global $user;
     if ($user == false) {
         return null;
     }
     if (is_null($acsId) || strlen($acsId) == 0) {
         return null;
     }
     //First check to see if we have already minted a download link for this resource
     //And this user that hasn't been returned.
     if ($eContentCheckout->acsTransactionId == null || $eContentCheckout->acsDownloadLink == null) {
         $transactionId = self::getUniqueID();
         $eContentCheckout->acsTransactionId = $transactionId;
         $dateval = time();
         $gbauthdate = gmdate('r', $dateval);
         $rights = "";
         $acsId = trim($acsId);
         if (strpos($acsId, "urn:uuid:") === FALSE) {
             $acsId = "urn:uuid:" . $acsId;
         }
         $bookDownloadURL = "action=enterloan" . "&ordersource=" . urlencode($configArray['EContent']['orderSource']) . "&orderid=" . urlencode($transactionId) . "&resid=" . urlencode($acsId) . $rights . "&gbauthdate=" . urlencode($gbauthdate) . "&dateval=" . urlencode($dateval) . "&gblver=4";
         $linkURL = $configArray['EContent']['linkURL'];
         if (isset($configArray['EContent']['linkURL']) && strlen($configArray['EContent']['linkURL']) > 0) {
             $sharedSecret = $configArray['EContent']['distributorSecret'];
             $sharedSecret = base64_decode($sharedSecret);
             $bookDownloadURL = $linkURL . "?" . $bookDownloadURL . "&auth=" . hash_hmac("sha1", $bookDownloadURL, $sharedSecret);
             $eContentCheckout->acsDownloadLink = $bookDownloadURL;
             $eContentCheckout->update();
             return $bookDownloadURL;
         } else {
             return null;
         }
     } else {
         return $eContentCheckout->acsDownloadLink;
     }
 }
 function getAvailability()
 {
     global $configArray;
     if ($this->availability == null) {
         $this->availability = array();
         require_once ROOT_DIR . '/sys/eContent/EContentAvailability.php';
         $eContentAvailability = new EContentAvailability();
         $eContentAvailability->recordId = $this->id;
         $eContentAvailability->find();
         while ($eContentAvailability->fetch()) {
             $this->availability[] = clone $eContentAvailability;
         }
         if (strcasecmp($this->source, "OverDrive") == 0) {
             require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
             $driver = OverDriveDriverFactory::getDriver();
             //echo("Loading availability from overdrive, part of " . count($this->availability) . " collections");
             foreach ($this->availability as $key => $tmpAvailability) {
                 //echo("\r\n{$tmpAvailability->libraryId}");
                 //Get updated availability for each library from overdrive
                 $productKey = $configArray['OverDrive']['productsKey'];
                 if ($tmpAvailability->libraryId != -1) {
                     $library = new Library();
                     $library->libraryId = $tmpAvailability->libraryId;
                     $library->find(true);
                     $productKey = $library->overdriveAdvantageProductsKey;
                 }
                 $realtimeAvailability = $driver->getProductAvailability($this->externalId, $productKey);
                 $tmpAvailability->copiesOwned = $realtimeAvailability->copiesOwned;
                 $tmpAvailability->availableCopies = $realtimeAvailability->copiesAvailable;
                 $tmpAvailability->numberOfHolds = $realtimeAvailability->numberOfHolds;
                 $this->availability[$key] = $tmpAvailability;
             }
         }
         if (count($this->availability) == 0) {
             //Did not get availability from the Availability table
             if ($this->itemLevelOwnership) {
                 //Ownership is determined at the item level based on library ids set for the item.  Assume unlimited availability
                 $items = $this->getItems();
                 foreach ($items as $item) {
                     $eContentAvailability = new EContentAvailability();
                     $eContentAvailability->recordId = $this->id;
                     $eContentAvailability->copiesOwned = 1;
                     $eContentAvailability->availableCopies = 1;
                     $eContentAvailability->numberOfHolds = 0;
                     $eContentAvailability->libraryId = $item->libraryId;
                     $this->availability[] = $eContentAvailability;
                 }
             } else {
                 //Ownership is shared, based on information at record level
                 $eContentAvailability = new EContentAvailability();
                 $eContentAvailability->recordId = $this->id;
                 $eContentAvailability->copiesOwned = $this->availableCopies;
                 $checkouts = new EContentCheckout();
                 $checkouts->status = 'out';
                 $checkouts->recordId = $this->id;
                 $checkouts->find();
                 $curCheckouts = $checkouts->N;
                 if ($this->accessType == 'free') {
                     $this->availableCopies = 999999;
                 }
                 $eContentAvailability->availableCopies = $this->availableCopies - $curCheckouts;
                 $eContentAvailability->copiesOwned = $this->availableCopies;
                 $holds = new EContentHold();
                 $holds->whereAdd("status in ('active', 'suspended', 'available')");
                 $holds->recordId = $this->id;
                 $holds->find();
                 $eContentAvailability->numberOfHolds = $holds->N;
                 $eContentAvailability->onOrderCopies = $this->onOrderCopies;
                 $eContentAvailability->libraryId = -1;
             }
         }
     }
     return $this->availability;
 }
 public function getAccountSummary()
 {
     global $user;
     $accountSummary = array();
     if ($user) {
         //Get a count of checked out items
         $eContentCheckout = new EContentCheckout();
         $eContentCheckout->status = 'out';
         $eContentCheckout->userId = $user->id;
         $eContentCheckout->find();
         $accountSummary['numEContentCheckedOut'] = $eContentCheckout->N;
         //Get a count of available holds
         $eContentHolds = new EContentHold();
         $eContentHolds->status = 'available';
         $eContentHolds->userId = $user->id;
         $eContentHolds->find();
         $accountSummary['numEContentAvailableHolds'] = $eContentHolds->N;
         //Get a count of unavailable holds
         $eContentHolds = new EContentHold();
         $eContentHolds->whereAdd("status IN ('active', 'suspended')");
         $eContentHolds->userId = $user->id;
         $eContentHolds->find();
         $accountSummary['numEContentUnavailableHolds'] = $eContentHolds->N;
         //Get a count of items on the wishlist
         $eContentWishList = new EContentWishList();
         $eContentWishList->status = 'active';
         $eContentWishList->userId = $user->id;
         $eContentWishList->find();
         $accountSummary['numEContentWishList'] = $eContentWishList->N;
     }
     return $accountSummary;
 }
 public function returnTitle($itemId)
 {
     global $user;
     if (!$user) {
         return array('result' => false, 'message' => 'You must be logged in to return a title');
     } else {
         require_once ROOT_DIR . '/sys/eContent/EContentCheckout.php';
         $eContentCheckout = new EContentCheckout();
         $eContentCheckout->userId = $user->id;
         $eContentCheckout->recordId = $this->getUniqueID();
         $eContentCheckout->itemId = $itemId;
         $eContentCheckout->status = 'out';
         $eContentCheckout->protectionType = 'free';
         if (!$eContentCheckout->find(true)) {
             return array('result' => true, 'message' => 'This title is not checked out to you.');
         } else {
             global $configArray;
             $eContentCheckout->dateReturned = time();
             $eContentCheckout->status = 'returned';
             if ($eContentCheckout->update()) {
                 return array('result' => true, 'message' => 'The title was returned successfully.');
             } else {
                 return array('result' => false, 'message' => 'Unexpected error returning out the title.');
             }
         }
     }
 }
Exemple #5
0
 /**
  * Process notifications from the ACS server when an item is checked out
  * or returned.
  **/
 function launch()
 {
     global $configArray;
     global $logger;
     $post_body = file_get_contents('php://input');
     if (isset($_POST['body'])) {
         $post_body = $_POST['body'];
     }
     $logger->log("POST_BODY {$post_body}", PEAR_LOG_INFO);
     $notificationData = new SimpleXMLElement($post_body);
     //Check to see of the EPUB is being fulfilled or returned
     $isFulfilled = strcasecmp((string) $notificationData->body->fulfilled, 'true') == 0;
     $isReturned = strcasecmp((string) $notificationData->body->returned, 'true') == 0;
     //Get the transactionId
     $transactionId = (string) $notificationData->body->transaction;
     //Get the user acsId
     $userAcsId = (string) $notificationData->body->user;
     if ($isFulfilled) {
         if ($isReturned) {
             $logger->log("Transaction {$transactionId} was returned, returning it in the catalog.", PEAR_LOG_INFO);
         } else {
             $logger->log("Transaction {$transactionId} was fulfilled, checking it out in the catalog.", PEAR_LOG_INFO);
         }
     } else {
         $logger->log("Transaction {$transactionId} was not fulfilled or returned, ignoring it.", PEAR_LOG_INFO);
         exit;
     }
     //Add a log entry for debugging.
     $logger->log("Preparing to insert log entry for transaction", PEAR_LOG_INFO);
     require_once ROOT_DIR . '/sys/eContent/AcsLog.php';
     $acsLog = new AcsLog();
     $acsLog->acsTransactionId = $transactionId;
     $acsLog->fulfilled = $isFulfilled;
     $acsLog->returned = $isReturned;
     $acsLog->userAcsId = $userAcsId;
     $ret = $acsLog->insert();
     $logger->log("Inserted log entry result: {$ret}", PEAR_LOG_INFO);
     //Update the database as appropriate
     //Get the chckd out item for the transaction Id
     require_once ROOT_DIR . '/sys/eContent/EContentCheckout.php';
     $checkout = new EContentCheckout();
     $checkout->acsTransactionId = $transactionId;
     if ($checkout->find(true)) {
         //Update the checkout to show
         if ($isReturned) {
             if ($checkout->status == 'out') {
                 //return the item
                 require_once ROOT_DIR . '/Drivers/EContentDriver.php';
                 $driver = new EContentDriver();
                 $driver->returnRecord($checkout->recordId);
             }
         } else {
             //Update the checked out item with information from acs
             if ($checkout->downloadedToReader == 0) {
                 $checkout->downloadedToReader = 1;
                 $checkout->dateFulfilled = time();
                 $checkout->userAcsId = $userAcsId;
                 $checkout->update();
             }
             //Mark that the record is downloaded
             require_once ROOT_DIR . '/sys/eContent/EContentRecord.php';
             $eContentRecord = new EContentRecord();
             $eContentRecord->id = $checkout->recordId;
             $eContentRecord->find(true);
             require_once ROOT_DIR . '/Drivers/EContentDriver.php';
             $driver = new EContentDriver();
             $driver->recordEContentAction($checkout->recordId, 'Download', $eContentRecord->accessType);
         }
     }
 }