function launch() { global $interface; global $configArray; $id = $_REQUEST['id']; $interface->assign('id', $id); $item = $_REQUEST['item']; $interface->assign('item', $item); $viewer = 'custom'; $errorOccurred = false; if ($this->user == false) { $interface->assign('errorMessage', 'User is not logged in.'); $errorOccurred = true; $interface->assign('showLogin', true); } else { require_once ROOT_DIR . '/sys/eContent/EContentRecord.php'; $eContentRecord = new EContentRecord(); $eContentRecord->id = $id; if ($eContentRecord->find(true)) { //Check the database to see if there is an existing title require_once ROOT_DIR . '/sys/eContent/EContentItem.php'; $eContentItem = new EContentItem(); $eContentItem->id = $_REQUEST['item']; if ($eContentItem->find(true)) { $bookFile = null; $libraryPath = $configArray['EContent']['library']; if ($eContentItem->item_type == 'mp3') { $bookFile = "{$libraryPath}/{$eContentItem->folder}"; } else { $bookFile = "{$libraryPath}/{$eContentItem->filename}"; } if (!file_exists($bookFile)) { $bookFile = null; } } } else { $errorOccurred = true; $interface->assign('errorMessage', 'Could not find the selected title.'); } if (file_exists($bookFile) && $errorOccurred == false) { require_once ROOT_DIR . '/Drivers/EContentDriver.php'; $driver = new EContentDriver(); //Check to see if the user has access to the title. $isCheckedOut = $driver->isRecordCheckedOutToUser($id); if (!$isCheckedOut) { $errorOccurred = true; $interface->assign('errorMessage', "Sorry, you do not have access to that title, please <a href='{$configArray['Site']['path']}/Record/{$id}/Hold'>place a hold</a> on the title and you will be notified when it is ready for pickup."); } if (!$errorOccurred) { //Record that the e-pub file is being opened. if (strcasecmp($eContentItem->item_type, 'epub') === 0) { $driver->recordEContentAction($id, "Read Online", $eContentRecord->accessType); require_once ROOT_DIR . '/sys/eReader/ebook.php'; $ebook = new ebook($bookFile); if ($ebook->readErrorOccurred()) { $errorOccurred = true; $interface->assign('errorMessage', $ebook->readError()); } else { $spineInfo = $ebook->getSpine(); $toc = $ebook->getTOC(); if ($viewer == 'monocle') { $spineData = addslashes(json_encode($spineInfo)); $interface->assign('spineData', $spineData); $contents = addslashes(json_encode($toc)); $interface->assign('contents', $contents); $metaData = addslashes(json_encode(array("title" => $ebook->getTitle(), "creator" => $ebook->getDcCreator()))); $interface->assign('metaData', $metaData); } else { $interface->assign('spineData', $spineInfo); $interface->assign('contents', $toc); $interface->assign('bookCreator', $ebook->getDcCreator()); //Load a translation map to translate locations into ids $manifest = array(); for ($i = 0; $i < $ebook->getManifestSize(); $i++) { $manifestId = $ebook->getManifestItem($i, 'id'); $manifestHref = $ebook->getManifestItem($i, 'href'); $manifestType = $ebook->getManifestItem($i, 'type'); $manifest[$manifestHref] = $manifestId; } $interface->assign('manifest', $manifest); } $interface->assign('bookTitle', $ebook->getTitle()); $errorOccurred = false; } } else { if ($eContentItem->item_type == 'mp3') { //Display information so patron can listen to the recording. //Table of contents is based on the actual files uploaded. $viewer = 'mp3'; $dirHnd = opendir($bookFile); $mp3Files = array(); while (false !== ($file = readdir($dirHnd))) { if (preg_match('/^.*?\\.mp3$/i', $file)) { $mp3Files[] = preg_replace('/\\.mp3/i', '', $file); } } $files = readdir($dirHnd); closedir($dirHnd); //Sort the mp3 files by name. sort($mp3Files); $interface->assign('mp3Filenames', $mp3Files); } else { $errorOccurred = true; $interface->assign('errorMessage', "Sorry, we could not find a viewer for that type of item, please contact support."); } } } } else { $errorOccurred = true; $interface->assign('errorMessage', 'Sorry, we could not find that book in our online library.'); } } $interface->assign('errorOccurred', $errorOccurred); if ($viewer == 'mp3') { $interface->display('EcontentRecord/viewer-mp3.tpl'); } else { $interface->display('EcontentRecord/viewer-custom.tpl'); } }
/** * Downloads an eContent file to the user's hard drive for offline usage. * * 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>recordId - The id of the record within the eContent database.</li> * <li>itemId - The id of the item attached to the record that should be downloaded.</li> * </ul> * * Returns: * false if the username or password were incorrect or the item cannot be downloaded * or the contents of the file that can be streamed directly to the client. * * @author Mark Noble <*****@*****.**> */ function downloadEContentFile() { global $configArray; $username = $_REQUEST['username']; $password = $_REQUEST['password']; $recordId = $_REQUEST['recordId']; //Trim off econtentRecord from the front of the id if provided if (preg_match('/econtentRecord\\d+/i', $recordId)) { $recordId = substr($recordId, 14); } $itemId = $_REQUEST['itemId']; global $user; $user = UserAccount::validateAccount($username, $password); if ($user && !PEAR_Singleton::isError($user)) { require_once ROOT_DIR . '/Drivers/EContentDriver.php'; $driver = new EContentDriver(); $eContentRecord = new EContentRecord(); $eContentRecord->id = $recordId; if (!$eContentRecord->find(true)) { return array('success' => false, 'message' => 'Could not find the record in the database.'); } //Check to see if the user has access to the title. if (!$driver->isRecordCheckedOutToUser($recordId)) { return array('success' => false, 'message' => 'The record is not checked out to you.'); } $eContentItem = new EContentItem(); $eContentItem->recordId = $recordId; $eContentItem->id = $itemId; if (!$eContentItem->find(true)) { return array('success' => false, 'message' => 'Could not find the item in the database.'); } $driver->recordEContentAction($recordId, 'Download', $eContentRecord->accessType); $libraryPath = $configArray['EContent']['library']; if (isset($eContentItem->filename) && strlen($eContentItem->filename) > 0) { $bookFile = "{$libraryPath}/{$eContentItem->filename}"; } else { $bookFile = "{$libraryPath}/{$eContentItem->folder}"; } if (strcasecmp($eContentItem->item_type, 'epub') == 0) { require_once ROOT_DIR . '/sys/eReader/ebook.php'; $ebook = new ebook($bookFile); //Return the contents of the epub file header("Content-Type: application/epub+zip;\n"); header('Content-Length: ' . filesize($bookFile)); header('Content-Description: ' . $ebook->getTitle()); header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); echo readfile($bookFile); exit; } else { if (strcasecmp($eContentItem->item_type, 'pdf') == 0) { header("Content-Type: application/pdf;\n"); header('Content-Length: ' . filesize($bookFile)); header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); echo readfile($bookFile); exit; } else { if (strcasecmp($eContentItem->item_type, 'kindle') == 0) { header('Content-Length: ' . filesize($bookFile)); header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); echo readfile($bookFile); exit; } else { if (strcasecmp($eContentItem->item_type, 'plucker') == 0) { header('Content-Length: ' . filesize($bookFile)); header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); echo readfile($bookFile); exit; } } } } } else { return array('success' => false, 'message' => 'Login unsuccessful'); } }
/** * Download an EPUB file from the server so a user can use it locally. **/ function launch() { global $interface; global $configArray; $id = $_REQUEST['id']; $interface->assign('id', $id); $itemId = $_REQUEST['item']; $errorOccurred = false; if ($this->user == false) { $interface->assign('errorMessage', 'User is not logged in.'); $errorOccurred = true; $interface->assign('showLogin', true); } else { //Check the database to see if there is an existing title $econtentItem = new EContentItem(); $econtentItem->id = $itemId; $econtentItem->find(); $bookFile = null; if ($econtentItem->find(true)) { $eContentRecord = new EContentRecord(); $eContentRecord->id = $econtentItem->recordId; $eContentRecord->find(true); $libraryPath = $configArray['EContent']['library']; if ($econtentItem->item_type == 'mp3') { //Load the correct segment $segmentIndex = $_REQUEST['segment']; $dirHnd = opendir("{$libraryPath}/{$econtentItem->folder}"); $mp3Files = array(); while (false !== ($file = readdir($dirHnd))) { if (preg_match('/^.*?\\.mp3$/i', $file)) { $mp3Files[] = $file; } } $files = readdir($dirHnd); sort($mp3Files); closedir($dirHnd); $bookFile = "{$libraryPath}/{$econtentItem->folder}/{$mp3Files[$segmentIndex]}"; } else { $bookFile = "{$libraryPath}/{$econtentItem->filename}"; } if (!file_exists($bookFile)) { $bookFile = null; } } $errorOccurred = false; if (file_exists($bookFile)) { require_once ROOT_DIR . '/Drivers/EContentDriver.php'; $driver = new EContentDriver(); //Check to see if the user has access to the title. if (!$driver->isRecordCheckedOutToUser($id)) { $errorOccurred = true; $interface->assign('errorMessage', "Sorry, you do not have access to that title, please <a href='{$configArray['Site']['path']}/Record/{$id}/Hold'>place a hold</a> on the title and you will be notified when it is ready for pickup."); } if (!$errorOccurred) { //Record that the e-pub file is being opened. $driver->recordEContentAction($id, 'Download', $econtentItem->getAccessType()); if (strcasecmp($econtentItem->item_type, 'mp3') == 0) { header("Content-Type: audio/mpeg3;\n"); header('Content-Length: ' . filesize($bookFile)); if (isset($_REQUEST['download'])) { header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); } echo readfile($bookFile); exit; } } } else { $errorOccurred = true; $interface->assign('errorMessage', 'Sorry, we could not find that book in our online library.'); } } $interface->assign('errorOccurred', $errorOccurred); }
/** * Download an EPUB file from the server so a user can use it locally. **/ function launch() { global $interface; global $configArray; $id = $_REQUEST['id']; $interface->assign('id', $id); $itemId = $_REQUEST['item']; $errorOccurred = false; if ($this->user == false) { $interface->assign('errorMessage', 'User is not logged in.'); $errorOccurred = true; $interface->assign('showLogin', true); } else { //Check the database to see if there is an existing title $epubFile = new EContentItem(); $epubFile->id = $itemId; $bookFile = null; if ($epubFile->find(true)) { $eContentRecord = new EContentRecord(); $eContentRecord->id = $epubFile->recordId; $eContentRecord->find(true); $libraryPath = $configArray['EContent']['library']; if (isset($epubFile->filename) && strlen($epubFile->filename) > 0) { $bookFile = "{$libraryPath}/{$epubFile->filename}"; } else { $bookFile = "{$libraryPath}/{$epubFile->folder}"; } if (!file_exists($bookFile)) { $bookFile = null; } } $errorOccurred = false; if (file_exists($bookFile)) { require_once ROOT_DIR . '/Drivers/EContentDriver.php'; $driver = new EContentDriver(); //Check to see if the user has access to the title. if (!$driver->isRecordCheckedOutToUser($id)) { $errorOccurred = true; $interface->assign('errorMessage', "Sorry, you do not have access to that title, please <a href='{$configArray['Site']['path']}/Record/{$id}/Hold'>place a hold</a> on the title and you will be notified when it is ready for pickup."); } if (!$errorOccurred) { //Record that the e-pub file is being opened. $driver->recordEContentAction($id, 'Download', $eContentRecord->accessType); if (strcasecmp($epubFile->item_type, 'epub') == 0) { require_once ROOT_DIR . '/sys/eReader/ebook.php'; $ebook = new ebook($bookFile); //Return the contents of the epub file header("Content-Type: application/epub+zip;\n"); //header('Content-Length: ' . filesize($bookFile)); header('Content-Description: ' . $ebook->getTitle()); //header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); readfile($bookFile); die; } else { if (strcasecmp($epubFile->item_type, 'pdf') == 0) { header("Content-Type: application/pdf;\n"); header('Content-Length: ' . filesize($bookFile)); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); readfile($bookFile); exit; } else { if (strcasecmp($epubFile->item_type, 'kindle') == 0) { header('Content-Length: ' . filesize($bookFile)); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); readfile($bookFile); exit; } else { if (strcasecmp($epubFile->item_type, 'plucker') == 0) { header('Content-Length: ' . filesize($bookFile)); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); readfile($bookFile); exit; } else { if (strcasecmp($epubFile->item_type, 'text') == 0) { header("Content-Type: text/plain;\n"); header('Content-Length: ' . filesize($bookFile)); //header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); readfile($bookFile); exit; } else { if (strcasecmp($epubFile->item_type, 'mp3') == 0) { $id = $_REQUEST['id']; $interface->assign('id', $id); $item = $_REQUEST['item']; $interface->assign('item', $item); //Get all of the MP3 files that $dirHnd = opendir($bookFile); $mp3Files = array(); while (false !== ($file = readdir($dirHnd))) { if (preg_match('/^.*?\\.mp3$/i', $file)) { $mp3Files[] = array('name' => preg_replace('/\\.mp3/i', '', $file), 'size' => filesize($bookFile . '/' . $file)); } } $files = readdir($dirHnd); closedir($dirHnd); //Sort the mp3 files by name. sort($mp3Files); $interface->assign('mp3Filenames', $mp3Files); $interface->display('EcontentRecord/download-mp3.tpl'); exit; } } } } } } } } else { $errorOccurred = true; $interface->assign('errorMessage', 'Sorry, we could not find that book in our online library.'); } } $interface->assign('errorOccurred', $errorOccurred); $interface->display('EcontentRecord/download.tpl'); }
/** * 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); } } }