function launch() { global $configArray; $id = $_REQUEST['id']; $item = $_REQUEST['item']; //Check the database to see if there is an existing title require_once ROOT_DIR . '/sys/eContent/EContentItem.php'; $epubFile = new EContentItem(); $epubFile->id = $_REQUEST['item']; $epubFile->find(); $bookFile = null; if ($epubFile->find(true)) { if (preg_match("/{$epubFile->recordId}/", $id)) { $libraryPath = $configArray['EContent']['library']; $bookFile = "{$libraryPath}/{$epubFile->filename}"; if (!file_exists($bookFile)) { $bookFile = null; } } } if (file_exists($bookFile)) { require_once ROOT_DIR . '/sys/eReader/ebook.php'; $ebook = new ebook($bookFile); $epubExists = true; } else { $epubExists = false; } if ($epubExists) { if ($_GET['method'] == 'getComponent' || $_GET['method'] == 'getComponentCustom') { //Content type will depend on the type of content created. $output = $this->{$_GET}['method']($ebook, $id, $item); } else { 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 if (is_callable(array($this, $_GET['method']))) { $output = json_encode(array('result' => $this->{$_GET}['method']($ebook, $id))); } else { $output = json_encode(array('error' => 'invalid_method ' . $_GET['method'])); } } } else { 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 $output = json_encode(array('error' => 'e-pub file does not exist')); } echo $output; }
function launch() { global $interface; global $configArray; $epubFile = new EContentItem(); $epubFile->id = $_REQUEST['id']; $epubFile->find(); if ($epubFile->N > 0) { $epubFile->fetch(); $epubFile->delete(); } //Redirect back to the PMDA home page header('Location:' . $configArray['Site']['path'] . "/EContent/Search"); exit; }
function processExternalLinks($source) { $eContentAttachmentLogEntry = new EContentAttachmentLogEntry(); $eContentAttachmentLogEntry->dateStarted = time(); $eContentAttachmentLogEntry->sourcePath = 'Attaching External links to ' . $source; $eContentAttachmentLogEntry->recordsProcessed = 0; $eContentAttachmentLogEntry->insert(); //Get a list of all records that do not have items for the source $econtentRecord = new EContentRecord(); $econtentRecord->source = $source; $econtentRecord->find(); while ($econtentRecord->fetch()) { if ($econtentRecord->getNumItems() == 0 && $econtentRecord->sourceUrl != null && strlen($econtentRecord->sourceUrl) > 0) { $sourceUrl = $econtentRecord->sourceUrl; $econtentItem = new EContentItem(); $econtentItem->recordId = $econtentRecord->id; $econtentItem->item_type = 'externalLink'; $econtentItem->addedBy = 1; $econtentItem->date_added = time(); $econtentItem->date_updated = time(); $econtentItem->link = $sourceUrl; $econtentItem->insert(); $eContentAttachmentLogEntry->recordsProcessed++; //Increase processing time since this can take awhile set_time_limit(30); } } $eContentAttachmentLogEntry->dateFinished = time(); $eContentAttachmentLogEntry->status = 'finished'; $eContentAttachmentLogEntry->update(); }
function launch() { global $configArray; global $interface; //Grab the tracking data $recordId = $_REQUEST['id']; $ipAddress = $_SERVER['REMOTE_ADDR']; $itemId = $_REQUEST['itemId']; // Retrieve Full Marc Record $eContentRecord = new EContentRecord(); $eContentRecord->id = $recordId; if (!$eContentRecord->find(true)) { PEAR_Singleton::raiseError(new PEAR_Error('Record Does Not Exist')); } $eContentItem = new EContentItem(); $eContentItem->id = $itemId; if (!$eContentItem->find(true)) { PEAR_Singleton::raiseError(new PEAR_Error('Item Does Not Exist')); } $linkUrl = $eContentItem->link; $linkParts = parse_url($linkUrl); $title = str_replace("/", "", $eContentRecord->title); //Insert into the externalLinkTracking table require_once ROOT_DIR . '/sys/BotChecker.php'; if (!BotChecker::isRequestFromBot()) { require_once ROOT_DIR . '/sys/ExternalLinkTracking.php'; $externalLinkTracking = new ExternalLinkTracking(); $externalLinkTracking->ipAddress = $ipAddress; $externalLinkTracking->recordId = "econtentRecord" . $recordId; $externalLinkTracking->linkUrl = $linkUrl; $externalLinkTracking->linkHost = $linkParts['host']; $result = $externalLinkTracking->insert(); } //redirects them to the link they clicked if ($linkUrl != "") { header("Location:" . $linkUrl); } else { PEAR_Singleton::raiseError(new PEAR_Error("Failed to load link for this title.")); } }
function launch() { global $interface; global $configArray; $interface->assign('id', $_REQUEST['id']); $epubFile = new EContentItem(); $epubFile->id = $_REQUEST['id']; $epubFile->find(); if ($epubFile->N > 0) { $epubFile->fetch(); $interface->assign('epubFile', $epubFile); } //Load the pillar to display $structure = EContentItem::getObjectStructure(); $interface->setTemplate('view.tpl'); $interface->display('layout.tpl'); }
function launch() { global $interface; global $timer; global $configArray; global $user; $id = $_REQUEST['id']; $structure = EContentItem::getObjectStructure(); $ret = DataObjectUtil::saveObject($structure, 'EContentItem'); if (!$ret['validatedOk']) { echo "Item failed validation."; } elseif (!$ret['saveOk']) { echo "Could not save the new item"; } else { $object = $ret['object']; header("Location: " . $configArray['Site']['path'] . "/EcontentRecord/{$object->recordId}/Home"); } }
function launch() { global $interface; global $configArray; $isNew = true; if (isset($_REQUEST['id']) && strlen($_REQUEST['id']) > 0) { $epubFile = new EContentItem(); $epubFile->id = $_REQUEST['id']; $epubFile->find(); if ($epubFile->N > 0) { $epubFile->fetch(); $interface->assign('object', $epubFile); $interface->setPageTitle('Edit EPUB File'); $isNew = false; } } $structure = EContentItem::getObjectStructure(); if (isset($_REQUEST['submit'])) { //Save the object $results = DataObjectUtil::saveObject($structure, 'EContentItem'); $epubFile = $results['object']; //redirect to the view of the competency if we saved ok. if (!$results['validatedOk'] || !$results['saveOk']) { //Display the errors for the user. $interface->assign('errors', $results['errors']); $interface->assign('object', $epubFile); $_REQUEST['id'] = $epubFile->id; } else { //Show the new tip that was created header('Location:' . $configArray['Site']['path'] . "/EContent/{$epubFile->id}/View"); exit; } } //Manipulate the structure as needed if ($isNew) { } else { } $interface->assign('isNew', $isNew); $interface->assign('submitUrl', $configArray['Site']['path'] . '/EContent/Edit'); $interface->assign('editForm', DataObjectUtil::getEditForm($structure)); $interface->setTemplate('edit.tpl'); $interface->display('layout.tpl'); }
function launch() { global $interface; global $configArray; $interface->setPageTitle('eContent Help'); $defaultFormat = ""; require_once ROOT_DIR . '/sys/eContent/EContentRecord.php'; if (isset($_REQUEST['id'])) { $id = $_REQUEST['id']; $interface->assign('id', $id); $eContentRecord = new EContentRecord(); $eContentRecord->id = $id; if ($eContentRecord->find(true)) { require_once ROOT_DIR . '/sys/eContent/EContentItem.php'; $eContentItem = new EContentItem(); $eContentItem->id = $_REQUEST['itemId']; if ($eContentItem->find(true)) { $displayFormat = $eContentItem->getDisplayFormat(); $popupContent = "Sorry, there is not detailed help available for this format yet."; if ($eContentItem->item_type == 'mp3') { $defaultFormat = 'mp3'; } else { if ($eContentItem->item_type == 'epub') { $defaultFormat = 'ebook'; } else { if ($eContentItem->item_type == 'kindle') { $defaultFormat = 'kindle'; } else { if ($eContentItem->item_type == 'plucker') { $defaultFormat = 'other'; } else { if ($eContentItem->item_type == 'pdf') { $defaultFormat = 'other'; } else { if ($eContentItem->item_type == 'externalMP3') { $defaultFormat = 'mp3'; } else { if ($eContentItem->item_type == 'external_ebook') { if ($eContentItem->getSource() == 'SpringerLink') { $defaultFormat = 'springerlink'; } elseif (preg_match('/ebsco/i', $eContentItem->getSource())) { $defaultFormat = 'ebsco'; } else { $defaultFormat = 'other'; } } else { if ($eContentItem->item_type == 'externalLink') { $defaultFormat = 'other'; } else { if ($eContentItem->item_type == 'overdrive') { if ($eContentItem->externalFormatId == 'audiobook-mp3') { $defaultFormat = 'mp3'; } else { if ($eContentItem->externalFormatId == 'audiobook-wma') { $defaultFormat = 'wma'; } else { if ($eContentItem->externalFormatId == 'video-wmv') { $defaultFormat = 'eVideo'; } else { if ($eContentItem->externalFormatId == 'music-wma') { $defaultFormat = 'eMusic'; } else { if ($eContentItem->externalFormatId == 'ebook-kindle') { $defaultFormat = 'kindle'; } else { if ($eContentItem->externalFormatId == 'ebook-epub-adobe') { $defaultFormat = 'ebook'; } else { if ($eContentItem->externalFormatId == 'ebook-pdf-adobe') { $defaultFormat = 'other'; } else { if ($eContentItem->externalFormatId == 'ebook-epub-open') { $defaultFormat = 'ebook'; } else { if ($eContentItem->externalFormatId == 'ebook-pdf-open') { $defaultFormat = 'other'; } else { $defaultFormat = 'other'; } } } } } } } } } } else { if ($eContentItem->item_type == 'external_eaudio') { $defaultFormat = 'other'; } else { if ($eContentItem->item_type == 'external_emusic') { $defaultFormat = 'eMusic'; } else { if ($eContentItem->item_type == 'text') { $defaultFormat = 'other'; } else { if ($eContentItem->item_type == 'itunes') { $defaultFormat = 'other'; } else { if ($eContentItem->item_type == 'gifs') { $defaultFormat = 'other'; } else { $defaultFormat = 'other'; } } } } } } } } } } } } } } } } } $interface->assign('defaultFormat', $defaultFormat); $device = get_device_name(); $defaultDevice = ''; if ($device == 'Kindle') { $defaultDevice = 'kindle'; } elseif ($device == 'Kindle Fire') { $defaultDevice = 'kindle_fire'; } elseif ($device == 'iPad' || $device == 'iPhone') { $defaultDevice = 'ios'; } elseif ($device == 'Android Phone' || $device == 'Android Tablet') { $defaultDevice = 'android'; } elseif ($device == 'Android Phone' || $device == 'Android Tablet' || $device == 'Google TV') { $defaultDevice = 'android'; } elseif ($device == 'BlackBerry') { $defaultDevice = 'other'; } elseif ($device == 'Mac') { $defaultDevice = 'mac'; } elseif ($device == 'PC') { $defaultDevice = 'pc'; } $interface->assign('defaultDevice', $defaultDevice); if (isset($_REQUEST['lightbox'])) { $interface->assign('popupTitle', 'Step by Step Instructions for using eContent'); $popupContent = $interface->fetch('Help/eContentHelp.tpl'); $interface->assign('popupContent', $popupContent); $interface->display('popup-wrapper.tpl'); } else { $interface->setTemplate('eContentHelp.tpl'); $interface->display('layout.tpl'); } }
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'); } }
function DeleteItem() { global $user; require_once ROOT_DIR . '/sys/eContent/EContentItem.php'; if ($user->hasRole('epubAdmin')) { $recordId = strip_tags($_REQUEST['id']); $itemId = strip_tags($_REQUEST['itemId']); $econtentItem = new EContentItem(); $econtentItem->id = $itemId; if ($econtentItem->find(true)) { $ret = $econtentItem->delete(); if ($ret) { $return = array('result' => true, 'message' => 'The item was deleted.'); } else { $return = array('result' => false, 'message' => 'The item could not be deleted from the database and index.'); } } else { $return = array('result' => false, 'message' => 'The specified item does not exist.'); } } else { $return = array('result' => false, 'message' => 'You do not have permissions to delete this item.'); } return json_encode($return); }
function isExternalItem() { return array_key_exists($this->item_type, EContentItem::getExternalItemTypes()); }
/** * 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'); }
/** * 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); }
function getObjectStructure() { return EContentItem::getObjectStructure(); }
/** * Get Holding * * This is responsible for retrieving the holding information of a certain * record. * * @param string $recordId The record id to retrieve the holdings for * @return mixed An associative array with the following keys: * availability (boolean), status, location, * reserve, callnumber, duedate, number, * holding summary, holding notes * If an error occurs, return a PEAR_Error * @access public */ public function getHolding($id, $allowReindex = true) { if (array_key_exists($id, EContentDriver::$holdings)) { return EContentDriver::$holdings[$id]; } global $user; global $configArray; $libaryScopeId = $this->getLibraryScopingId(); //Get any items that are stored for the record $eContentRecord = new EContentRecord(); $eContentRecord->id = $id; $eContentRecord->find(true); if ($eContentRecord->accessType != 'external') { //Check to see if the record is checked out or on hold within VuFind $checkedOutToUser = false; $onHoldForUser = false; $holdPosition = 0; if ($user) { $eContentCheckout = new EContentCheckout(); $eContentCheckout->userId = $user->id; $eContentCheckout->status = 'out'; $eContentCheckout->recordId = $id; $eContentCheckout->find(); if ($eContentCheckout->N > 0) { //The item is checked out to the current user $eContentCheckout->fetch(); $checkedOutToUser = true; } else { $eContentHold = new EContentHold(); $eContentHold->userId = $user->id; $eContentHold->whereAdd("status in ('active', 'suspended', 'available')"); $eContentHold->recordId = $id; $eContentHold->find(); if ($eContentHold->N > 0) { $onHoldForUser = true; $eContentHold->fetch(); $holdPosition = $this->_getHoldPosition($eContentHold); } } } $eContentItem = new EContentItem(); $eContentItem->recordId = $id; if ($libaryScopeId != -1) { $eContentItem->whereAdd("libraryId = -1 or libraryId = {$libaryScopeId}"); } $items = array(); $eContentItem->find(); while ($eContentItem->fetch()) { $item = clone $eContentItem; $item->source = $eContentRecord->source; //Generate links for the items $links = array(); if ($checkedOutToUser) { $links = $this->_getCheckedOutEContentLinks($eContentRecord, $item, $eContentCheckout); } else { if ($eContentRecord->accessType == 'free' && $item->isExternalItem()) { $links = $this->_getFreeExternalLinks($eContentRecord, $item); } else { if ($onHoldForUser) { $links = $this->getOnHoldEContentLinks($eContentHold); } } } $item->checkedOut = $checkedOutToUser; $item->onHold = $onHoldForUser; $item->holdPosition = $holdPosition; $item->links = $links; $items[] = $item; } } else { $items = $eContentRecord->getItems(); //We have econtent stored on an external server. Check to see if it is available there (if possible) if (strcasecmp($eContentRecord->source, 'OverDrive') == 0) { //Add links as needed $availability = $eContentRecord->getAvailability(); $addCheckoutLink = false; $addPlaceHoldLink = false; foreach ($availability as $availableFrom) { if ($availableFrom->libraryId == -1) { if ($availableFrom->availableCopies > 0) { $addCheckoutLink = true; } else { $addPlaceHoldLink = true; } } else { //Non shared item, check to see if we are in the correct scope to show it if ($libaryScopeId == -1 || $availableFrom->libraryId == $libaryScopeId) { if ($availableFrom->availableCopies > 0) { $addCheckoutLink = true; } else { $addPlaceHoldLink = true; } } } } foreach ($items as $key => $item) { $item->links = array(); if ($addCheckoutLink) { if ($configArray['OverDrive']['interfaceVersion'] == 1) { $checkoutLink = "return checkoutOverDriveItem('{$eContentRecord->externalId}', '{$item->externalFormatNumeric}');"; } else { $checkoutLink = "return checkoutOverDriveItemOneClick('{$eContentRecord->externalId}', '{$item->externalFormatNumeric}');"; } $item->links[] = array('onclick' => $checkoutLink, 'text' => 'Check Out', 'overDriveId' => $eContentRecord->externalId, 'formatId' => $item->externalFormatNumeric, 'action' => 'CheckOut'); } else { if ($addPlaceHoldLink) { $item->links[] = array('onclick' => "return placeOverDriveHold('{$eContentRecord->externalId}', '{$item->externalFormatNumeric}');", 'text' => 'Place Hold', 'overDriveId' => $eContentRecord->externalId, 'formatId' => $item->externalFormatNumeric, 'action' => 'Hold'); } } $items[$key] = $item; } } else { foreach ($items as $key => $item) { $item->links = $this->_getFreeExternalLinks($eContentRecord, $item); $items[$key] = $item; } } if ($libaryScopeId != -1) { foreach ($items as $key => $item) { if ($item->libraryId != -1 && $item->libraryId != $libaryScopeId) { unset($items[$key]); } } } } EContentDriver::$holdings[$id] = $items; return $items; }
function getNumItems() { if ($this->items == null) { $this->items = array(); if (strcasecmp($this->source, 'OverDrive') == 0) { return -1; } else { require_once ROOT_DIR . '/sys/eContent/EContentItem.php'; $eContentItem = new EContentItem(); $eContentItem->recordId = $this->id; $eContentItem->find(); return $eContentItem->N; } } return count($this->items); }
/** * 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'); } }