Example #1
0
 function cancelHold()
 {
     $recordId = $_REQUEST['id'];
     $itemId = $_REQUEST['itemId'];
     require_once ROOT_DIR . '/RecordDrivers/RestrictedEContentDriver.php';
     $recordDriver = new RestrictedEContentDriver($recordId);
     $result = $recordDriver->cancelHold($itemId);
     return json_encode($result);
 }
Example #2
0
 /**
  * @param RestrictedEContentDriver $recordDriver
  */
 function loadCitations($recordDriver)
 {
     global $interface;
     $citationCount = 0;
     $formats = $recordDriver->getCitationFormats();
     foreach ($formats as $current) {
         $interface->assign(strtolower($current), $recordDriver->getCitation($current));
         $citationCount++;
     }
     $interface->assign('citationCount', $citationCount);
 }
Example #3
0
 function launch()
 {
     global $configArray;
     $id = $_REQUEST['id'];
     $file = $_REQUEST['file'];
     //Check the database to see if there is an existing title
     $recordDriver = new PublicEContentDriver($id);
     $restrictedDriver = new RestrictedEContentDriver($id);
     if (!$recordDriver->isValid() && !$restrictedDriver->isValid()) {
         $output = json_encode(array('error' => 'Invalid Record.  The specified title does not exist.'));
     } else {
         $itemId = $_REQUEST['item'];
         if (!$recordDriver->isCheckedOut($itemId) && !$restrictedDriver->isCheckedOut($itemId)) {
             $output = json_encode(array('error' => 'This title is not checked out to you.  Please checkout the title.'));
         } else {
             //TODO: Validate that this file belongs to the checked out record
             $libraryPath = $configArray['EContent']['library'];
             $bookFile = "{$libraryPath}/{$file}";
             if (!file_exists($bookFile)) {
                 $bookFile = null;
                 $epubExists = false;
             } else {
                 $epubExists = true;
             }
             require_once ROOT_DIR . '/sys/eReader/ebook.php';
             $ebook = new ebook($bookFile);
             if ($epubExists) {
                 if ($_GET['method'] == 'getComponentCustom') {
                     //Content type will depend on the type of content created.
                     $output = $this->{$_GET}['method']($ebook, $id, $itemId, $file);
                 } 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, $itemId, $file)));
                     } 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;
 }
Example #4
0
 function launch()
 {
     global $interface;
     global $configArray;
     global $user;
     $id = $_REQUEST['id'];
     $interface->assign('id', $id);
     $itemId = $_REQUEST['itemId'];
     $interface->assign('itemId', $itemId);
     $file = $_REQUEST['file'];
     $interface->assign('file', $file);
     $recordDriver = new RestrictedEContentDriver($id);
     $isAudio = false;
     if (!$recordDriver->isValid()) {
         $interface->setTemplate('../Record/invalidRecord.tpl');
         $interface->display('layout.tpl');
         die;
     } else {
         $interface->assign('recordDriver', $recordDriver);
         $itemId = $_REQUEST['itemId'];
         $errorOccurred = false;
         if ($user == false) {
             $interface->assign('errorMessage', 'Sorry, you must be logged in to view this title.');
             $errorOccurred = true;
             $interface->assign('showLogin', true);
         } else {
             if (!$recordDriver->isCheckedOut($itemId)) {
                 $interface->assign('errorMessage', "You must checkout this title before you view it, please <a href='{$configArray['Site']['path']}/PublicEContent/{$id}/Checkout'>click here</a> to checkout the title.");
                 $errorOccurred = true;
                 $interface->assign('showLogin', false);
             } else {
                 require_once ROOT_DIR . '/sys/eContent/EContentRecord.php';
                 $filename = $_REQUEST['file'];
                 $bookFile = $configArray['EContent']['library'] . '/' . $filename;
                 if (file_exists($bookFile)) {
                     //Check the database to see if there is an existing title
                     $fileExtension = '';
                     if (strpos($bookFile, '.') !== FALSE) {
                         $fileExtension = substr($bookFile, strrpos($bookFile, '.') + 1);
                     }
                     //Record that the title is being viewed.
                     require_once ROOT_DIR . '/sys/eContent/EContentHistoryEntry.php';
                     $entry = new EContentHistoryEntry();
                     $entry->userId = $user->id;
                     $entry->recordId = $id;
                     $entry->itemId = $itemId;
                     $entry->action = 'Read Online';
                     //Open date will be filled out automatically.
                     $entry->insert();
                     if ($fileExtension == 'epub') {
                         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();
                             $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;
                         }
                     } elseif ($fileExtension == 'txt') {
                         header("Content-Type: text/plain;\n");
                         header('Content-Length: ' . filesize($bookFile));
                         readfile($bookFile);
                         exit;
                     } elseif (is_dir($bookFile)) {
                         //A folder of mp3 files?
                         //Display information so patron can listen to the recording.
                         //Table of contents is based on the actual files uploaded.
                         $isAudio = true;
                         $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 that title in our online library.');
                 }
             }
             $interface->assign('errorOccurred', $errorOccurred);
             if ($isAudio) {
                 $interface->display('EcontentRecord/viewer-mp3.tpl');
             } else {
                 $interface->display('EcontentRecord/viewer-custom.tpl');
             }
         }
     }
 }
Example #5
0
 public function getMyTransactions($user)
 {
     $return = array();
     $eContentCheckout = new EContentCheckout();
     $eContentCheckout->userId = $user->id;
     $eContentCheckout->status = 'out';
     $eContentCheckout->find();
     $return['transactions'] = array();
     $return['numTransactions'] = $eContentCheckout->find();
     while ($eContentCheckout->fetch()) {
         if ($eContentCheckout->protectionType == 'free') {
             require_once ROOT_DIR . '/RecordDrivers/PublicEContentDriver.php';
             $recordDriver = new PublicEContentDriver($eContentCheckout->recordId);
         } else {
             require_once ROOT_DIR . '/RecordDrivers/RestrictedEContentDriver.php';
             $recordDriver = new RestrictedEContentDriver($eContentCheckout->recordId);
         }
         if ($recordDriver->isValid()) {
             $daysUntilDue = ceil(($eContentCheckout->dateDue - time()) / (24 * 60 * 60));
             $overdue = $daysUntilDue < 0;
             $items = $recordDriver->getItems();
             if ($eContentCheckout->protectionType == 'free') {
                 $links['return'] = array('text' => 'Return&nbsp;Now', 'onclick' => "if (confirm('Are you sure you want to cancel this hold?')){VuFind.LocalEContent.returnPublicEContent('{$eContentCheckout->recordId}', '{$eContentCheckout->itemId}')};return false;", 'typeReturn' => 0);
             } else {
                 $links['return'] = array('text' => 'Return&nbsp;Now', 'onclick' => "if (confirm('Are you sure you want to cancel this hold?')){VuFind.LocalEContent.returnRestrictedEContent('{$eContentCheckout->recordId}', '{$eContentCheckout->itemId}')};return false;", 'typeReturn' => 0);
             }
             //Get Ratings
             $return['transactions'][] = array('id' => $eContentCheckout->recordId, 'groupedWorkId' => $recordDriver->getGroupedWorkId(), 'recordId' => $recordDriver->getUniqueID(), 'recordType' => $eContentCheckout->protectionType == 'free' ? 'PublicEContent' : 'RestrictedEContent', 'checkoutSource' => 'eContent', 'title' => $recordDriver->getTitle(), 'author' => $recordDriver->getPrimaryAuthor(), 'format' => $recordDriver->getFormatCategory(), 'duedate' => $eContentCheckout->dateDue, 'checkoutdate' => $eContentCheckout->dateCheckedOut, 'daysUntilDue' => $daysUntilDue, 'links' => $links, 'items' => $items, 'ratingData' => $recordDriver->getRatingData(), 'overdue' => $overdue, 'recordUrl' => $recordDriver->getLinkUrl(), 'bookcoverUrl' => $recordDriver->getBookcoverUrl('medium'));
         }
     }
     return $return;
 }
 /**
  * @param ReadingHistoryEntry $readingHistoryDB
  * @return mixed
  */
 public function getHistoryEntryForDatabaseEntry($readingHistoryDB)
 {
     $historyEntry = array();
     $historyEntry['itemindex'] = $readingHistoryDB->id;
     $historyEntry['deletable'] = true;
     $historyEntry['source'] = $readingHistoryDB->source;
     $historyEntry['id'] = $readingHistoryDB->sourceId;
     $historyEntry['recordId'] = $readingHistoryDB->sourceId;
     $historyEntry['shortId'] = $readingHistoryDB->sourceId;
     $historyEntry['title'] = $readingHistoryDB->title;
     $historyEntry['author'] = $readingHistoryDB->author;
     $historyEntry['format'] = array($readingHistoryDB->format);
     $historyEntry['checkout'] = $readingHistoryDB->checkOutDate;
     $historyEntry['checkin'] = $readingHistoryDB->checkInDate;
     $historyEntry['ratingData'] = null;
     $historyEntry['permanentId'] = null;
     $historyEntry['linkUrl'] = null;
     $historyEntry['coverUrl'] = null;
     $recordDriver = null;
     if ($readingHistoryDB->source == 'ILS') {
         require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php';
         $recordDriver = new MarcRecord($historyEntry['id']);
     } elseif ($readingHistoryDB->source == 'OverDrive') {
         require_once ROOT_DIR . '/RecordDrivers/OverDriveRecordDriver.php';
         $recordDriver = new OverDriveRecordDriver($historyEntry['id']);
     } elseif ($readingHistoryDB->source == 'PublicEContent') {
         require_once ROOT_DIR . '/RecordDrivers/PublicEContentDriver.php';
         $recordDriver = new PublicEContentDriver($historyEntry['id']);
     } elseif ($readingHistoryDB->source == 'RestrictedEContent') {
         require_once ROOT_DIR . '/RecordDrivers/RestrictedEContentDriver.php';
         $recordDriver = new RestrictedEContentDriver($historyEntry['id']);
     }
     if ($recordDriver != null && $recordDriver->isValid()) {
         $historyEntry['ratingData'] = $recordDriver->getRatingData();
         $historyEntry['permanentId'] = $recordDriver->getPermanentId();
         $historyEntry['linkUrl'] = $recordDriver->getLinkUrl();
         $historyEntry['coverUrl'] = $recordDriver->getBookcoverUrl('medium');
         $historyEntry['format'] = $recordDriver->getFormats();
     }
     $recordDriver = null;
     return $historyEntry;
 }