function returnRecord($id) { global $user; global $logger; //Get the item information for the record require_once ROOT_DIR . '/sys/eContent/EContentCheckout.php'; $checkout = new EContentCheckout(); $checkout->userId = $user->id; $checkout->recordId = $id; $checkout->status = 'out'; $return = array(); //$trans->whereAdd('timeReturned = null'); if ($checkout->find(true)) { $output = array(); $checkout->dateReturned = time(); $checkout->status = 'returned'; $ret = $checkout->update(); if ($ret != 0) { $this->processHoldQueue($id); $eContentRecord = new EContentRecord(); $eContentRecord->id = $id; $eContentRecord->find(true); //Record that the title was checked in $this->recordEContentAction($id, "Checked In", $eContentRecord->accessType); $eContentRecord->saveToSolr(); $return = array('success' => true, 'message' => "The title was returned successfully."); } else { $return = array('success' => false, 'message' => "Could not return the item"); } $output['database-response'] = $ret; } else { $logger->log("Could not find a checked out item for that title in the database.", PEAR_LOG_INFO); $return = array('success' => false, 'message' => "Could not find a checked out item for that title in the database. It may have already been returned."); } return $return; }
/** * 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); } } }
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.'); } } } }
/** * @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; } }