/** * Process notifications from the ACS server when an item is checked out * or returned. **/ function launch() { $id = $_REQUEST['id']; //Setup JSON response header('Content-type: text/plain'); header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past require_once ROOT_DIR . '/Drivers/EContentDriver.php'; $driver = new EContentDriver(); $result = $driver->returnRecord($id); echo json_encode($result); exit; }
/** * Returns an eContent record * * Parameters: * <ul> * <li>username - The barcode of the user. Can be truncated to the last 7 or 9 digits.</li> * <li>password - The pin number for the user. </li> * <li>id - The id of the record to return.</li> * </ul> * * Returns: * <ul> * <li>success � true if the account is valid and the hold could be frozen, false if the username or password were incorrect or the hold could not be frozen.</li> * <li>freezeResults � a list of results for each id that was frozen.</li> * </ul> * * Sample Call: * <code> * http://catalog.douglascountylibraries.org/API/UserAPI?method=returnEContentRecord&username=23025003575917&password=1234&id=531 * </code> * * Sample Response: * <code> * {"result":{ * "success":true, * "message":"The title was returned successfully." * }} * </code> * * @author Mark Noble <*****@*****.**> */ function returnEContentRecord() { $username = $_REQUEST['username']; $password = $_REQUEST['password']; global $user; $user = UserAccount::validateAccount($username, $password); if ($user && !PEAR_Singleton::isError($user)) { require_once ROOT_DIR . '/Drivers/EContentDriver.php'; $eContentDriver = new EContentDriver(); $id = $_REQUEST['id']; $returnResults = $eContentDriver->returnRecord($id); return $returnResults; } else { return array('success' => false, 'message' => 'Login unsuccessful'); } }
/** * 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); } } }