/** * Track that an e-pub file was opened in the user's reading history. */ public function recordEContentAction($id, $action, $accessType) { global $user; require_once ROOT_DIR . '/sys/eContent/EContentHistoryEntry.php'; global $configArray; if (isset($configArray['Strands']['APID']) && $user->disableRecommendations == 0 && $action == "Checked Out") { //Check to see if this is the first time the user has read the title and if so record the entry in strands $entry = new EContentHistoryEntry(); $entry->userId = $user->id; $entry->recordId = $id; $entry->find(); if ($entry->N == 0) { $orderId = $user->id . '_' . time(); $strandsUrl = "http://bizsolutions.strands.com/api2/event/purchased.sbs?needresult=true&apid={$configArray['Strands']['APID']}&item=econtentRecord{$id}::0.00::1&user={$user->id}&orderid={$orderId}"; $ret = file_get_contents($strandsUrl); } } $entry = new EContentHistoryEntry(); $entry->userId = $user->id; $entry->recordId = $id; $entry->action = $action; $entry->accessType = $accessType; //Open date will be filled out automatically. $entry->insert(); }
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'); } } } }
/** * Download a file from the server so a user can use it locally. **/ function launch() { global $interface; global $configArray; global $user; $id = $_REQUEST['id']; $interface->assign('id', $id); $recordDriver = new PublicEContentDriver($id); if (!$recordDriver->isValid()) { $interface->setTemplate('../Record/invalidRecord.tpl'); $interface->display('layout.tpl'); die; } else { $interface->assign('recordDriver', $recordDriver); $itemId = $_REQUEST['itemId']; if ($user == false) { $interface->assign('errorMessage', 'Sorry, you must be logged in to download this title.'); $errorOccurred = true; $interface->assign('showLogin', true); } else { if (!$recordDriver->isCheckedOut($itemId)) { $interface->assign('errorMessage', "You must checkout this title before you download it, please <a href='{$configArray['Site']['path']}/PublicEContent/{$id}/Checkout'>click here</a> to checkout the title."); $errorOccurred = true; $interface->assign('showLogin', false); } else { $errorOccurred = false; $filename = $_REQUEST['file']; $bookFile = $configArray['EContent']['library'] . '/' . $filename; if (file_exists($bookFile)) { global $user; //Record that the e-pub file is being downloaded. require_once ROOT_DIR . '/sys/eContent/EContentHistoryEntry.php'; $entry = new EContentHistoryEntry(); $entry->userId = $user->id; $entry->recordId = $id; $entry->itemId = $itemId; $entry->action = 'Download'; //Open date will be filled out automatically. $entry->insert(); $fileExtension = ''; if (strpos($bookFile, '.') !== FALSE) { $fileExtension = substr($bookFile, strrpos($bookFile, '.') + 1); } if (strcasecmp($fileExtension, '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($fileExtension, '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($fileExtension, 'mobi') == 0) { header('Content-Length: ' . filesize($bookFile)); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); readfile($bookFile); exit; } else { if (strcasecmp($fileExtension, 'pdb') == 0) { header('Content-Length: ' . filesize($bookFile)); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); readfile($bookFile); exit; } else { if (strcasecmp($fileExtension, 'txt') == 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($fileExtension, '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 title in our online library.'); } } } } $interface->assign('errorOccurred', $errorOccurred); // Display Page $interface->assign('sidebar', 'PublicEContent/full-record-sidebar.tpl'); $interface->setTemplate('download-error.tpl'); $interface->display('layout.tpl'); }
function loadUsageSummary($selectedDateStart, $selectedDateEnd, $selectedSourceFilter, $selectedAccessTypeFilter, $minFilter, $maxFilter, $interface) { $usageSummary = array(); $columns = array('title' => 'Title', 'source' => 'Source', 'readOnline' => 'Read Online', 'download' => 'Downloaded', 'numViews' => 'Total Usage', 'placeHold' => 'Hold Placed', 'checkedOut' => 'Checked Out', 'checkedIn' => 'Returned Early', 'numUsers' => 'Total Users'); $usageSummary['columns'] = $columns; $epubHistory = new EContentHistoryEntry(); //Setup paging for use in the query $currentPage = 1; $startRecord = 1; $itemsPerPage = isset($_REQUEST['itemsPerPage']) && is_numeric($_REQUEST['itemsPerPage']) ? $_REQUEST['itemsPerPage'] : 50; if (isset($_GET['page']) && is_numeric($_GET['page'])) { $currentPage = $_GET['page']; // 1st record is easy, work out the start of this page $startRecord = ($currentPage - 1) * $itemsPerPage + 1; } $startDateSqlFormatted = date('Y-m-d', strtotime($selectedDateStart)); $endDateSqlFormatted = date('Y-m-d', strtotime($selectedDateEnd)); //Create the base query $baseQuery = "SELECT econtent_record.id, " . "econtent_record.title, " . "econtent_record.source, " . "COUNT(DISTINCT userId) as numUsers, " . "COUNT(DISTINCT IF (action = 'Checked Out', userid, NULL)) as checkedOut, " . "COUNT(DISTINCT IF (action = 'Checked In', userid, NULL)) as checkedIn, " . "COUNT(DISTINCT IF (action = 'Read Online', userid, NULL)) as readOnline, " . "COUNT(DISTINCT IF (action = 'Place Hold', userid, NULL)) as placeHold, " . "COUNT(DISTINCT IF (action = 'Download', userid, NULL)) as download, " . "COUNT(DISTINCT IF (action = 'Read Online' OR action = 'Download', userid, NULL)) as numViews " . "FROM `econtent_history` " . "INNER join econtent_record on econtent_record.id = econtent_history.recordId "; $baseQuery .= "WHERE (DATE_FORMAT(econtent_history.openDate, '%Y-%m-%d')) BETWEEN '" . $startDateSqlFormatted . "' AND '" . $endDateSqlFormatted . "' "; if (count($selectedSourceFilter) > 0) { $sourceEntries = ""; foreach ($selectedSourceFilter as $curSource) { if (strlen($sourceEntries) > 0) { $sourceEntries .= ', '; } $sourceEntries .= "'" . mysql_escape_string($curSource) . "'"; } $baseQuery .= "AND econtent_record.source IN (" . $sourceEntries . ") "; } if (count($selectedAccessTypeFilter) > 0) { $accessTypes = join("','", $selectedAccessTypeFilter); $accessTypes = ""; foreach ($selectedAccessTypeFilter as $curAccessType) { if (strlen($accessTypes) > 0) { $accessTypes .= ', '; } $accessTypes .= "'" . mysql_escape_string($curAccessType) . "'"; } $baseQuery .= "AND econtent_record.accessType IN (" . $accessTypes . ") "; } $baseQuery .= "GROUP BY econtent_record.id " . "ORDER BY title, econtent_record.id ASC "; $countQuery = "SELECT COUNT(id) as totalResults FROM (" . $baseQuery . ") baseQuery "; $usageQuery = "SELECT * FROM (" . $baseQuery . ") baseQuery "; //Add max / min filters as needed since they depend on the base query if ($minFilter != "" && $maxFilter != "") { $countQuery .= "WHERE numViews >= " . $minFilter . " AND numViews <= " . $maxFilter . " "; $usageQuery .= "WHERE numViews >= " . $minFilter . " AND numViews <= " . $maxFilter . " "; } elseif ($minFilter != "") { $countQuery .= "WHERE numViews >= " . $minFilter . " "; $usageQuery .= "WHERE numViews >= " . $minFilter . " "; } elseif ($maxFilter != "") { $countQuery .= "WHERE numViews <= " . $maxFilter . " "; $usageQuery .= "WHERE numViews <= " . $maxFilter . " "; } if (!isset($_REQUEST['exportToExcel'])) { $usageQuery .= "LIMIT " . ($startRecord - 1) . ", " . $itemsPerPage . " "; } $epubHistory->query($usageQuery); $usageSummary['data'] = array(); while ($epubHistory->fetch()) { $resourceInfo = array(); $resourceInfo['title'] = $epubHistory->title; $resourceInfo['source'] = $epubHistory->source; $resourceInfo['record_id'] = $epubHistory->recordId; $resourceInfo['checkedOut'] = $epubHistory->checkedOut; $resourceInfo['checkedIn'] = $epubHistory->checkedIn; $resourceInfo['readOnline'] = $epubHistory->readOnline; $resourceInfo['placeHold'] = $epubHistory->placeHold; $resourceInfo['download'] = $epubHistory->download; $resourceInfo['numViews'] = $epubHistory->numViews; $resourceInfo['numUsers'] = $epubHistory->numUsers; $usageSummary['data'][] = $resourceInfo; } //Load total number of results $epubHistory->query($countQuery); if ($epubHistory->fetch()) { $totalResultCount = $epubHistory->totalResults; } else { $totalResultCount = 0; } //////////Paging Array $summary = array('page' => $currentPage, 'perPage' => $itemsPerPage, 'resultTotal' => $totalResultCount, 'startRecord' => $startRecord, 'endRecord' => $startRecord + count($usageSummary['data']) - 1); $interface->assign('recordCount', $summary['resultTotal']); $interface->assign('recordStart', $summary['startRecord']); $interface->assign('recordEnd', $summary['endRecord']); // Process Paging using VuFind Pager object if (strrpos($_SERVER["REQUEST_URI"], "page=")) { //replace the page variable with a new one $link = str_replace("page=" . $currentPage, "page=%d", $_SERVER["REQUEST_URI"]); } else { if (strrpos($_SERVER["REQUEST_URI"], "?")) { $link = $_SERVER["REQUEST_URI"] . "&page=%d"; } else { $link = $_SERVER["REQUEST_URI"] . "?page=%d"; } } $options = array('totalItems' => $summary['resultTotal'], 'fileName' => $link, 'perPage' => $summary['perPage']); $pager = new VuFindPager($options); $interface->assign('pageLinks', $pager->getLinks()); return $usageSummary; }
/** * Track that an e-pub file was opened in the user's reading history. */ public function recordEContentAction($id, $action, $accessType) { global $user; require_once ROOT_DIR . '/sys/eContent/EContentHistoryEntry.php'; $entry = new EContentHistoryEntry(); $entry->userId = $user->id; $entry->recordId = $id; $entry->action = $action; $entry->accessType = $accessType; //Open date will be filled out automatically. $entry->insert(); }