Exemplo n.º 1
0
 function launch()
 {
     global $interface;
     $id = $_GET['id'];
     $interface->assign('id', $id);
     $this->eContentRecord = new EContentRecord();
     $this->eContentRecord->id = $_GET['id'];
     $this->eContentRecord->find(true);
     $recordDriver = new EcontentRecordDriver();
     $recordDriver->setDataObject($this->eContentRecord);
     $interface->assign('sourceUrl', $this->eContentRecord->sourceUrl);
     $interface->assign('source', $this->eContentRecord->source);
     $interface->setPageTitle(translate('Copies') . ': ' . $recordDriver->getBreadcrumb());
     $driver = new EContentDriver();
     $holdings = $driver->getHolding($id);
     $showEContentNotes = false;
     foreach ($holdings as $holding) {
         if (strlen($holding->notes) > 0) {
             $showEContentNotes = true;
         }
     }
     $interface->assign('showEContentNotes', $showEContentNotes);
     $interface->assign('holdings', $holdings);
     //Load status summary
     $result = $driver->getStatusSummary($id, $holdings);
     if (PEAR_Singleton::isError($result)) {
         PEAR_Singleton::raiseError($result);
     }
     $holdingData->holdingsSummary = $result;
     $interface->assign('subTemplate', 'view-holdings.tpl');
     $interface->setTemplate('view-alt.tpl');
     // Display Page
     $interface->display('layout.tpl');
 }
Exemplo n.º 2
0
 function launch()
 {
     global $configArray;
     global $interface;
     global $user;
     global $timer;
     // Get My Transactions
     if ($this->catalog->status) {
         if ($user->cat_username) {
             $patron = $this->catalog->patronLogin($user->cat_username, $user->cat_password);
             $timer->logTime("Logged in patron to get checked out items.");
             if (PEAR_Singleton::isError($patron)) {
                 PEAR_Singleton::raiseError($patron);
             }
             $patronResult = $this->catalog->getMyProfile($patron);
             if (!PEAR_Singleton::isError($patronResult)) {
                 $interface->assign('profile', $patronResult);
             }
             $timer->logTime("Got patron profile to get checked out items.");
             // Define sorting options
             $sortOptions = array('title' => 'Title', 'author' => 'Author', 'dueDate' => 'Due Date', 'format' => 'Format');
             $interface->assign('sortOptions', $sortOptions);
             $selectedSortOption = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'dueDate';
             $interface->assign('defaultSortOption', $selectedSortOption);
             $interface->assign('showNotInterested', false);
             require_once ROOT_DIR . '/Drivers/EContentDriver.php';
             $driver = new EContentDriver();
             if (isset($_REQUEST['multiAction']) && $_REQUEST['multiAction'] == 'suspendSelected') {
                 $ids = array();
                 foreach ($_REQUEST['unavailableHold'] as $id => $selected) {
                     $ids[] = $id;
                 }
                 $suspendDate = $_REQUEST['suspendDate'];
                 $dateToReactivate = strtotime($suspendDate);
                 $suspendResult = $driver->suspendHolds($ids, $dateToReactivate);
                 //Redirect back to the EContentHolds page
                 header("Location: " . $configArray['Site']['path'] . "/MyResearch/EContentHolds?section=unavailable");
             }
             $result = $driver->getMyHolds($user);
             $interface->assign('holds', $result['holds']);
             $timer->logTime("Loaded econtent from catalog.");
         }
     }
     $hasSeparateTemplates = $interface->template_exists('MyResearch/eContentAvailableHolds.tpl');
     if ($hasSeparateTemplates) {
         $section = isset($_REQUEST['section']) ? $_REQUEST['section'] : 'available';
         $interface->assign('section', $section);
         if ($section == 'available') {
             $interface->setPageTitle('Available eContent');
             $interface->setTemplate('eContentAvailableHolds.tpl');
         } else {
             $interface->setPageTitle('eContent On Hold');
             $interface->setTemplate('eContentUnavailableHolds.tpl');
         }
     } else {
         $interface->setTemplate('eContentHolds.tpl');
         $interface->setPageTitle('On Hold eContent');
     }
     $interface->display('layout.tpl');
 }
Exemplo n.º 3
0
 function launch()
 {
     global $interface;
     global $configArray;
     $id = strip_tags($_REQUEST['id']);
     $interface->assign('id', $id);
     // Check if user is logged in
     if (!$this->user) {
         $interface->assign('recordId', $id);
         $interface->assign('followupModule', 'EcontentRecord');
         $interface->assign('followupAction', 'AddToWishList');
         $interface->assign('followup', 'AddToWishList');
         if (isset($_GET['lightbox'])) {
             $interface->assign('title', $_GET['message']);
             $interface->assign('message', 'You must be logged in first');
             return $interface->fetch('AJAX/login.tpl');
         } else {
             $interface->setPageTitle('You must be logged in first');
             $interface->assign('subTemplate', '../MyResearch/login.tpl');
             $interface->setTemplate('view-alt.tpl');
             $interface->display('layout.tpl', 'AddToWishList' . $id);
         }
         exit;
     }
     //Add to the wishlist
     //Add to wishlist if not already on the wishlist
     require_once ROOT_DIR . '/Drivers/EContentDriver.php';
     $eContentDriver = new EContentDriver();
     $ret = $eContentDriver->addToWishList($id, $this->user);
     header('Location: ' . $configArray['Site']['path'] . '/EcontentRecord/' . $id . '/Home');
 }
Exemplo n.º 4
0
 /**
  * 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->cancelHold($id);
     echo json_encode($result);
     exit;
 }
Exemplo n.º 5
0
 function launch()
 {
     global $configArray;
     global $interface;
     global $user;
     global $timer;
     // Get My Transactions
     if ($this->catalog->status) {
         if ($user->cat_username) {
             $patron = $this->catalog->patronLogin($user->cat_username, $user->cat_password);
             $timer->logTime("Logged in patron to get checked out items.");
             if (PEAR_Singleton::isError($patron)) {
                 PEAR_Singleton::raiseError($patron);
             }
             $patronResult = $this->catalog->getMyProfile($patron);
             if (!PEAR_Singleton::isError($patronResult)) {
                 $interface->assign('profile', $patronResult);
             }
             $timer->logTime("Got patron profile to get checked out items.");
             // Define sorting options
             $sortOptions = array('title' => 'Title', 'author' => 'Author', 'dueDate' => 'Due Date', 'format' => 'Format');
             $interface->assign('sortOptions', $sortOptions);
             $selectedSortOption = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'dueDate';
             $interface->assign('defaultSortOption', $selectedSortOption);
             $interface->assign('showNotInterested', false);
             //Vars for the IDCLREADER TEMPLATE
             $interface->assign('ButtonBack', true);
             $interface->assign('ButtonHome', true);
             $interface->assign('MobileTitle', 'eContents Checked Out');
             require_once ROOT_DIR . '/Drivers/EContentDriver.php';
             $driver = new EContentDriver();
             $result = $driver->getMyTransactions($user);
             $interface->assign('checkedOut', $result['transactions']);
             $timer->logTime("Loaded econtent from catalog.");
         }
     }
     $interface->setTemplate('eContentCheckedOut.tpl');
     $interface->setPageTitle('Checked Out eContent');
     $interface->display('layout.tpl');
 }
Exemplo n.º 6
0
 function sendSMS()
 {
     global $configArray;
     global $interface;
     // Get Holdings
     $driver = new EContentDriver();
     $id = strip_tags($_REQUEST['id']);
     $eContentRecord = new EContentRecord();
     $eContentRecord->id = $id;
     $eContentRecord->find(true);
     $holdings = $driver->getHolding($id);
     $holdingsSummary = $driver->getStatusSummary($id, $holdings);
     if (PEAR_Singleton::isError($holdingsSummary)) {
         return $holdingsSummary;
     }
     if ($holdingsSummary['status']) {
         $interface->assign('status', $holdingsSummary['status']);
     }
     $interface->assign('title', $eContentRecord->title);
     $interface->assign('author', $eContentRecord->author);
     $interface->assign('recordID', $_GET['id']);
     $message = $interface->fetch('Emails/eContent-sms.tpl');
     return $this->sms->text($_REQUEST['provider'], $_REQUEST['to'], $configArray['Site']['email'], $message);
 }
Exemplo n.º 7
0
 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');
     }
 }
Exemplo n.º 8
0
 function launch()
 {
     global $interface;
     global $configArray;
     global $user;
     $driver = new EContentDriver();
     $id = strip_tags($_REQUEST['id']);
     $interface->assign('id', $id);
     global $logger;
     //Get title information for the record.
     $eContentRecord = new EContentRecord();
     $eContentRecord->id = $id;
     if (!$eContentRecord->find(true)) {
         PEAR_Singleton::raiseError("Unable to find eContent record for id: {$id}");
     }
     if (isset($_REQUEST['autologout'])) {
         $_SESSION['autologout'] = true;
     }
     if (isset($_POST['submit']) || $user) {
         if (isset($_REQUEST['username']) && isset($_REQUEST['password'])) {
             //Log the user in
             $user = UserAccount::login();
         }
         if (!PEAR_Singleton::isError($user) && $user) {
             //The user is already logged in
             $return = $driver->placeHold($id, $user);
             $interface->assign('result', $return['result']);
             $message = $return['message'];
             $interface->assign('message', $message);
             $showMessage = true;
         } else {
             $message = 'Incorrect Patron Information';
             $interface->assign('message', $message);
             $interface->assign('focusElementId', 'username');
             $showMessage = true;
         }
     } else {
         //Get the referrer so we can go back there.
         if (isset($_SERVER['HTTP_REFERER'])) {
             $referer = $_SERVER['HTTP_REFERER'];
             $_SESSION['hold_referrer'] = $referer;
         }
         //Showing place hold form.
         if (!PEAR_Singleton::isError($user) && $user) {
             //set focus to the submit button if the user is logged in since the campus will be correct most of the time.
             $interface->assign('focusElementId', 'submit');
         } else {
             //set focus to the username field by default.
             $interface->assign('focusElementId', 'username');
         }
     }
     if (isset($return) && $showMessage) {
         $hold_message_data = array('successful' => $return['result'] ? 'all' : 'none', 'error' => $return['error'], 'titles' => array($return));
         $_SESSION['hold_message'] = $hold_message_data;
         if (isset($_SESSION['hold_referrer'])) {
             $logger->log('Hold Referrer is set, redirecting to there.  type = ' . $_REQUEST['type'], PEAR_LOG_INFO);
             header("Location: " . $_SESSION['hold_referrer']);
             unset($_SESSION['hold_referrer']);
             if (isset($_SESSION['autologout'])) {
                 unset($_SESSION['autologout']);
                 UserAccount::softLogout();
             }
         } else {
             $logger->log('No referrer set, but there is a message to show, go to the main holds page', PEAR_LOG_INFO);
             header("Location: " . $configArray['Site']['path'] . '/MyResearch/EContentHolds?section=unavailable');
         }
     } else {
         $logger->log('placeHold finished, do not need to show a message', PEAR_LOG_INFO);
         $interface->setPageTitle('Request an Item');
         $interface->assign('subTemplate', 'hold.tpl');
         $interface->setTemplate('hold.tpl');
         $interface->display('layout.tpl', 'RecordHold' . $_GET['id']);
     }
 }
Exemplo n.º 9
0
 /**
  * Get Item Statuses
  *
  * This is responsible for getting holding summary information for a list of
  * records from the database.
  *
  * @access	public
  * @author	Mark Noble <*****@*****.**>
  */
 function GetEContentStatusSummaries()
 {
     global $interface;
     global $timer;
     require_once ROOT_DIR . '/Drivers/EContentDriver.php';
     $driver = new EContentDriver();
     //Load status summaries
     $result = $driver->getStatusSummaries($_GET['id']);
     $timer->logTime("Retrieved status summaries");
     // Loop through all the status information that came back
     foreach ($result as $id => $record) {
         // If we encountered errors, skip those problem records.
         if (PEAR_Singleton::isError($record)) {
             continue;
         }
         $interface->assign('id', $id);
         $interface->assign('holdingsSummary', $record);
         $formattedHoldingsSummary = $interface->fetch('EcontentRecord/holdingsSummary.tpl');
         echo ' <item id="' . htmlspecialchars($record['recordId']) . '">';
         echo '	<status>' . htmlspecialchars($record['status']) . '</status>';
         echo '	<class>' . htmlspecialchars($record['class']) . '</class>';
         echo '	<showplacehold>' . ($record['showPlaceHold'] ? '1' : '0') . '</showplacehold>';
         echo '	<showcheckout>' . ($record['showCheckout'] ? '1' : '0') . '</showcheckout>';
         echo '	<showaccessonline>' . ($record['showAccessOnline'] ? '1' : '0') . '</showaccessonline>';
         if (isset($record['accessOnlineUrl'])) {
             echo '	<accessonlineurl>' . htmlspecialchars($record['accessOnlineUrl']) . '</accessonlineurl>';
             echo '	<accessonlinetext>' . htmlspecialchars($record['accessOnlineText']) . '</accessonlinetext>';
         }
         echo '	<showaddtowishlist>' . ($record['showAddToWishlist'] ? '1' : '0') . '</showaddtowishlist>';
         echo '	<availablecopies>' . htmlspecialchars($record['showAccessOnline']) . '</availablecopies>';
         echo '	<numcopies>' . htmlspecialchars($record['totalCopies']) . '</numcopies>';
         echo '	<holdQueueLength>' . (isset($record['holdQueueLength']) ? htmlspecialchars($record['holdQueueLength']) : '') . '</holdQueueLength>';
         echo '	<isDownloadable>1</isDownloadable>';
         echo '	<formattedHoldingsSummary>' . htmlspecialchars($formattedHoldingsSummary) . '</formattedHoldingsSummary>';
         echo ' </item>';
     }
     $timer->logTime("Formatted results");
 }
Exemplo n.º 10
0
 function launch()
 {
     global $configArray;
     global $interface;
     global $user;
     global $timer;
     $allCheckedOut = array();
     if ($configArray['Catalog']['offline']) {
         $interface->assign('offline', true);
     } else {
         $interface->assign('offline', false);
         //Determine which columns to show
         $ils = $configArray['Catalog']['ils'];
         $showOut = $ils == 'Horizon';
         $showRenewed = $ils == 'Horizon' || $ils == 'Millennium' || $ils == 'Sierra' || $ils == 'Koha';
         $showWaitList = $ils == 'Horizon';
         $interface->assign('showOut', $showOut);
         $interface->assign('showRenewed', $showRenewed);
         $interface->assign('showWaitList', $showWaitList);
         // Define sorting options
         $sortOptions = array('title' => 'Title', 'author' => 'Author', 'dueDate' => 'Due Date', 'format' => 'Format');
         if ($showWaitList) {
             $sortOptions['holdQueueLength'] = 'Wait List';
         }
         if ($showRenewed) {
             $sortOptions['renewed'] = 'Times Renewed';
         }
         $interface->assign('sortOptions', $sortOptions);
         $selectedSortOption = isset($_REQUEST['accountSort']) ? $_REQUEST['accountSort'] : 'dueDate';
         $interface->assign('defaultSortOption', $selectedSortOption);
         $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
         $recordsPerPage = isset($_REQUEST['pagesize']) && is_numeric($_REQUEST['pagesize']) ? $_REQUEST['pagesize'] : 25;
         $interface->assign('recordsPerPage', $recordsPerPage);
         if (isset($_GET['exportToExcel'])) {
             $recordsPerPage = -1;
             $page = 1;
         }
         // Get My Transactions
         if ($this->catalog->status) {
             if ($user->cat_username) {
                 $patron = $this->catalog->patronLogin($user->cat_username, $user->cat_password);
                 $timer->logTime("Logged in patron to get checked out items.");
                 if (PEAR_Singleton::isError($patron)) {
                     PEAR_Singleton::raiseError($patron);
                 }
                 $patronResult = $this->catalog->getMyProfile($patron);
                 if (!PEAR_Singleton::isError($patronResult)) {
                     $interface->assign('profile', $patronResult);
                 }
                 $timer->logTime("Got patron profile to get checked out items.");
                 $libraryHoursMessage = Location::getLibraryHoursMessage($patronResult['homeLocationId']);
                 $interface->assign('libraryHoursMessage', $libraryHoursMessage);
                 //Get checked out titles from the ILS
                 $catalogTransactions = $this->catalog->getMyTransactions(1, -1, $selectedSortOption);
                 $timer->logTime("Loaded transactions from catalog.");
                 //Get checked out titles from OverDrive
                 require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
                 $overDriveDriver = OverDriveDriverFactory::getDriver();
                 $overDriveCheckedOutItems = $overDriveDriver->getOverDriveCheckedOutItems($user);
                 //Get a list of eContent that has been checked out
                 require_once ROOT_DIR . '/Drivers/EContentDriver.php';
                 $driver = new EContentDriver();
                 $eContentCheckedOut = $driver->getMyTransactions($user);
                 $allCheckedOut = array_merge($catalogTransactions['transactions'], $overDriveCheckedOutItems['items'], $eContentCheckedOut['transactions']);
                 if (!PEAR_Singleton::isError($catalogTransactions)) {
                     $interface->assign('showNotInterested', false);
                     foreach ($allCheckedOut as $i => $curTitle) {
                         $sortTitle = isset($curTitle['title_sort']) ? $curTitle['title_sort'] : $curTitle['title'];
                         $sortKey = $sortTitle;
                         if ($selectedSortOption == 'title') {
                             $sortKey = $sortTitle;
                         } elseif ($selectedSortOption == 'author') {
                             $sortKey = (isset($curTitle['author']) ? $curTitle['author'] : "Unknown") . '-' . $sortTitle;
                         } elseif ($selectedSortOption == 'dueDate') {
                             if (isset($curTitle['duedate'])) {
                                 if (preg_match('/.*?(\\d{1,2})[-\\/](\\d{1,2})[-\\/](\\d{2,4}).*/', $curTitle['duedate'], $matches)) {
                                     $sortKey = $matches[3] . '-' . $matches[1] . '-' . $matches[2] . '-' . $sortTitle;
                                 } else {
                                     $sortKey = $curTitle['duedate'] . '-' . $sortTitle;
                                 }
                             }
                         } elseif ($selectedSortOption == 'format') {
                             $sortKey = (isset($curTitle['format']) ? $curTitle['format'] : "Unknown") . '-' . $sortTitle;
                         } elseif ($selectedSortOption == 'renewed') {
                             $sortKey = str_pad(isset($curTitle['renewCount']) ? $curTitle['renewCount'] : 0, 3, '0', STR_PAD_LEFT) . '-' . $sortTitle;
                         } elseif ($selectedSortOption == 'holdQueueLength') {
                             $sortKey = str_pad(isset($curTitle['holdQueueLength']) ? $curTitle['holdQueueLength'] : 0, 3, '0', STR_PAD_LEFT) . '-' . $sortTitle;
                         }
                         $itemBarcode = isset($curTitle['barcode']) ? $curTitle['barcode'] : null;
                         $itemId = isset($curTitle['itemid']) ? $curTitle['itemid'] : null;
                         if ($itemBarcode != null && isset($_SESSION['renew_message'][$itemBarcode])) {
                             $renewMessage = $_SESSION['renew_message'][$itemBarcode]['message'];
                             $renewResult = $_SESSION['renew_message'][$itemBarcode]['result'];
                             $curTitle['renewMessage'] = $renewMessage;
                             $curTitle['renewResult'] = $renewResult;
                             $allCheckedOut[$sortKey] = $curTitle;
                             unset($_SESSION['renew_message'][$itemBarcode]);
                             //$logger->log("Found renewal message in session for $itemBarcode", PEAR_LOG_INFO);
                         } else {
                             if ($itemId != null && isset($_SESSION['renew_message'][$itemId])) {
                                 $renewMessage = $_SESSION['renew_message'][$itemId]['message'];
                                 $renewResult = $_SESSION['renew_message'][$itemId]['result'];
                                 $curTitle['renewMessage'] = $renewMessage;
                                 $curTitle['renewResult'] = $renewResult;
                                 $allCheckedOut[$sortKey] = $curTitle;
                                 unset($_SESSION['renew_message'][$itemId]);
                                 //$logger->log("Found renewal message in session for $itemBarcode", PEAR_LOG_INFO);
                             } else {
                                 $allCheckedOut[$sortKey] = $curTitle;
                                 $renewMessage = null;
                                 $renewResult = null;
                             }
                         }
                         unset($allCheckedOut[$i]);
                     }
                     //Now that we have all the transactions we can sort them
                     if ($selectedSortOption == 'renewed' || $selectedSortOption == 'holdQueueLength') {
                         krsort($allCheckedOut);
                     } else {
                         ksort($allCheckedOut);
                     }
                     $interface->assign('transList', $allCheckedOut);
                     unset($_SESSION['renew_message']);
                 }
             }
         }
     }
     if (isset($_GET['exportToExcel']) && isset($allCheckedOut)) {
         $this->exportToExcel($allCheckedOut, $showOut, $showRenewed, $showWaitList);
     }
     $interface->assign('sidebar', 'MyAccount/account-sidebar.tpl');
     $interface->setTemplate('checkedout.tpl');
     $interface->setPageTitle('Checked Out Items');
     $interface->display('layout.tpl');
 }
Exemplo n.º 11
0
 function getItemAvailability()
 {
     global $timer;
     global $configArray;
     $itemData = array();
     //Load basic information
     $this->id = $_GET['id'];
     $itemData['id'] = $this->id;
     // Setup Search Engine Connection
     $class = $configArray['Index']['engine'];
     $url = $configArray['Index']['url'];
     $this->db = new $class($url);
     if ($configArray['System']['debugSolr']) {
         $this->db->debug = true;
     }
     // Retrieve Full Marc Record
     if (!($record = $this->db->getRecord($this->id))) {
         PEAR_Singleton::raiseError(new PEAR_Error('Record Does Not Exist'));
     }
     $this->record = $record;
     if ($record['recordtype'] == 'econtentRecord') {
         require_once ROOT_DIR . '/sys/eContent/EContentRecord.php';
         $eContentRecord = new EContentRecord();
         $eContentRecord->id = substr($record['id'], strlen('econtentRecord'));
         if (!$eContentRecord->find(true)) {
             $itemData['error'] = 'Cannot load eContent Record for id ' . $record['id'];
         } else {
             require_once ROOT_DIR . '/Drivers/EContentDriver.php';
             $driver = new EContentDriver();
             $itemData['holdings'] = $driver->getHolding($eContentRecord->id);
         }
     } else {
         $this->recordDriver = RecordDriverFactory::initRecordDriver($record);
         $timer->logTime('Initialized the Record Driver');
         //Load Holdings
         $itemData['holdings'] = Record_Holdings::loadHoldings($this->id);
         $timer->logTime('Loaded Holdings');
     }
     return $itemData;
 }
Exemplo n.º 12
0
 public function getMyProfile($patron, $forceReload = false)
 {
     global $timer;
     global $configArray;
     /** @var Memcache $memCache */
     global $memCache;
     global $serverName;
     $memCacheProfileKey = "patronProfile_{$serverName}_";
     if (is_object($patron)) {
         $patron = get_object_vars($patron);
         $userId = $patron['id'];
         $patronUserName = $patron['username'];
         $memCacheProfileKey .= $patron['username'];
     } else {
         global $user;
         $userId = $user->id;
         $patronUserName = $user->username;
         $memCacheProfileKey .= $user->username;
     }
     if (!$forceReload && !isset($_REQUEST['reload'])) {
         $patronProfile = $memCache->get($memCacheProfileKey);
         if ($patronProfile) {
             $timer->logTime('Retrieved Cached Profile for Patron');
             return $patronProfile;
         }
     }
     global $user;
     if ($configArray['Catalog']['offline'] == true) {
         $fullName = $patron['cat_username'];
         $Address1 = "";
         $City = "";
         $State = "";
         $Zip = "";
         $Email = "";
         $finesVal = 0;
         $expireClose = false;
         $homeBranchCode = '';
         $numHoldsAvailable = '?';
         $numHoldsRequested = '?';
         if (!$user) {
             $user = new User();
             $user->username = $patronUserName;
             if ($user->find(true)) {
                 $location = new Location();
                 $location->locationId = $user->homeLocationId;
                 $location->find(1);
                 $homeBranchCode = $location->code;
             }
         }
     } else {
         //Load the raw information about the patron from web services
         if (isset(HorizonAPI::$sessionIdsForUsers[$userId])) {
             $sessionToken = HorizonAPI::$sessionIdsForUsers[$userId];
             // keys off username
         } else {
             //Log the user in
             $return = $this->loginViaWebService($patron['cat_username'], $patron['cat_password']);
             if (count($return) == 1) {
                 $userValid = $return[0];
             } else {
                 list($userValid, $sessionToken) = $return;
             }
             if (!$userValid) {
                 echo "No session id found for user";
                 return PEAR_Singleton::raiseError("Could not login to web service " . $return);
             }
         }
         $lookupMyAccountInfoResponse = $this->getWebServiceResponse($configArray['Catalog']['webServiceUrl'] . '/standard/lookupMyAccountInfo?clientID=' . $configArray['Catalog']['clientId'] . '&sessionToken=' . $sessionToken . '&includeAddressInfo=true&includeHoldInfo=true&includeBlockInfo=true&includeItemsOutInfo=true');
         if ($lookupMyAccountInfoResponse === false) {
             global $logger;
             $logger->log("Unable to login", PEAR_LOG_WARNING);
             return null;
         }
         if (isset($lookupMyAccountInfoResponse->AddressInfo)) {
             $Address1 = (string) $lookupMyAccountInfoResponse->AddressInfo->line1;
             if (isset($lookupMyAccountInfoResponse->AddressInfo->cityState)) {
                 $cityState = (string) $lookupMyAccountInfoResponse->AddressInfo->cityState;
                 list($City, $State) = explode(', ', $cityState);
             } else {
                 $City = "";
                 $State = "";
             }
             $Zip = (string) $lookupMyAccountInfoResponse->AddressInfo->postalCode;
             if (isset($lookupMyAccountInfoResponse->AddressInfo->email)) {
                 $Email = (string) $lookupMyAccountInfoResponse->AddressInfo->email;
             }
         } else {
             $Address1 = "";
             $City = "";
             $State = "";
             $Zip = "";
             $Email = '';
         }
         $fullName = $lookupMyAccountInfoResponse->name;
         //Get additional information about the patron's home branch for display.
         if (isset($lookupMyAccountInfoResponse->locationID)) {
             $homeBranchCode = trim((string) $lookupMyAccountInfoResponse->locationID);
             //Translate home branch to plain text
             $location = new Location();
             $location->code = $homeBranchCode;
             $location->find(1);
             if ($location->N == 0) {
                 unset($location);
             }
         }
         if ($user) {
             if ($user->homeLocationId == 0 && isset($location)) {
                 $user->homeLocationId = $location->locationId;
                 if ($location->nearbyLocation1 > 0) {
                     $user->myLocation1Id = $location->nearbyLocation1;
                 } else {
                     $user->myLocation1Id = $location->locationId;
                 }
                 if ($location->nearbyLocation2 > 0) {
                     $user->myLocation2Id = $location->nearbyLocation2;
                 } else {
                     $user->myLocation2Id = $location->locationId;
                 }
                 if ($user instanceof User) {
                     //Update the database
                     $user->update();
                     //Update the serialized instance stored in the session
                     $_SESSION['userinfo'] = serialize($user);
                 }
             } else {
                 if (isset($location) && $location->locationId != $user->homeLocationId) {
                     $user->homeLocationId = $location->locationId;
                     //Update the database
                     $user->update();
                     //Update the serialized instance stored in the session
                     $_SESSION['userinfo'] = serialize($user);
                 }
             }
         }
         //TODO: See if we can get information about card expiration date
         $expireClose = 0;
         $finesVal = 0;
         if (isset($lookupMyAccountInfoResponse->BlockInfo)) {
             foreach ($lookupMyAccountInfoResponse->BlockInfo as $block) {
                 // $block is a simplexml object with attribute info about currency, type casting as below seems to work for adding up. plb 3-27-2015
                 $fineAmount = (double) $block->balance;
                 $finesVal += $fineAmount;
             }
         }
         $numHoldsAvailable = 0;
         $numHoldsRequested = 0;
         if (isset($lookupMyAccountInfoResponse->HoldInfo)) {
             foreach ($lookupMyAccountInfoResponse->HoldInfo as $hold) {
                 if ($hold->status == 'FILLED') {
                     $numHoldsAvailable++;
                 } else {
                     $numHoldsRequested++;
                 }
             }
         }
     }
     if ($user) {
         //Get display name for preferred location 1
         $myLocation1 = new Location();
         $myLocation1->whereAdd("locationId = '{$user->myLocation1Id}'");
         $myLocation1->find(1);
         //Get display name for preferred location 1
         $myLocation2 = new Location();
         $myLocation2->whereAdd("locationId = '{$user->myLocation2Id}'");
         $myLocation2->find(1);
     }
     list($fullName, $lastName, $firstName) = $this->splitFullName($fullName);
     $profile = array('lastname' => $lastName, 'firstname' => $firstName, 'fullname' => $fullName, 'address1' => $Address1, 'address2' => $City . ', ' . $State, 'city' => $City, 'state' => $State, 'zip' => $Zip, 'email' => $user && $user->email ? $user->email : $Email, 'overdriveEmail' => $user ? $user->overdriveEmail : $Email, 'promptForOverdriveEmail' => $user ? $user->promptForOverdriveEmail : 1, 'phone' => isset($lookupMyAccountInfoResponse->phone) ? (string) $lookupMyAccountInfoResponse->phone : '', 'workPhone' => '', 'mobileNumber' => '', 'fines' => sprintf('$%01.2f', $finesVal), 'finesval' => $finesVal, 'expires' => '', 'expireclose' => $expireClose, 'homeLocationCode' => isset($homeBranchCode) ? trim($homeBranchCode) : '', 'homeLocationId' => isset($location) ? $location->locationId : 0, 'homeLocation' => isset($location) ? $location->displayName : '', 'myLocation1Id' => $user ? $user->myLocation1Id : -1, 'myLocation1' => isset($myLocation1) ? $myLocation1->displayName : '', 'myLocation2Id' => $user ? $user->myLocation2Id : -1, 'myLocation2' => isset($myLocation2) ? $myLocation2->displayName : '', 'numCheckedOut' => isset($lookupMyAccountInfoResponse->ItemsOutInfo) ? count($lookupMyAccountInfoResponse->ItemsOutInfo) : 0, 'numHolds' => $numHoldsAvailable + $numHoldsRequested, 'numHoldsAvailable' => $numHoldsAvailable, 'numHoldsRequested' => $numHoldsRequested, 'bypassAutoLogout' => $user ? $user->bypassAutoLogout : 0, 'ptype' => 0, 'notices' => '-', 'noticePreferenceLabel' => 'e-mail', 'web_note' => '');
     //Get eContent info as well
     require_once ROOT_DIR . '/Drivers/EContentDriver.php';
     $eContentDriver = new EContentDriver();
     $eContentAccountSummary = $eContentDriver->getAccountSummary();
     $profile = array_merge($profile, $eContentAccountSummary);
     require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
     $overDriveDriver = OverDriveDriverFactory::getDriver();
     if ($overDriveDriver->isUserValidForOverDrive($user)) {
         $overDriveSummary = $overDriveDriver->getOverDriveSummary($user);
         $profile['numOverDriveCheckedOut'] = $overDriveSummary['numCheckedOut'];
         $profile['numOverDriveHoldsAvailable'] = $overDriveSummary['numAvailableHolds'];
         $profile['numOverDriveHoldsRequested'] = $overDriveSummary['numUnavailableHolds'];
         $profile['canUseOverDrive'] = true;
     } else {
         $profile['numOverDriveCheckedOut'] = 0;
         $profile['numOverDriveHoldsAvailable'] = 0;
         $profile['numOverDriveHoldsRequested'] = 0;
         $profile['canUseOverDrive'] = false;
     }
     $profile['numCheckedOutTotal'] = $profile['numCheckedOut'] + $profile['numOverDriveCheckedOut'] + $eContentAccountSummary['numEContentCheckedOut'];
     $profile['numHoldsAvailableTotal'] = $profile['numHoldsAvailable'] + $profile['numOverDriveHoldsAvailable'] + $eContentAccountSummary['numEContentAvailableHolds'];
     $profile['numHoldsRequestedTotal'] = $profile['numHoldsRequested'] + $profile['numOverDriveHoldsRequested'] + $eContentAccountSummary['numEContentUnavailableHolds'];
     $profile['numHoldsTotal'] = $profile['numHoldsAvailableTotal'] + $profile['numHoldsRequestedTotal'];
     //Get a count of the materials requests for the user
     if ($user) {
         $materialsRequest = new MaterialsRequest();
         $materialsRequest->createdBy = $user->id;
         $homeLibrary = Library::getPatronHomeLibrary();
         $statusQuery = new MaterialsRequestStatus();
         $statusQuery->isOpen = 1;
         $statusQuery->libraryId = $homeLibrary->libraryId;
         $materialsRequest->joinAdd($statusQuery);
         $materialsRequest->find();
         $profile['numMaterialsRequests'] = $materialsRequest->N;
     }
     $timer->logTime("Got Patron Profile");
     $memCache->set($memCacheProfileKey, $profile, 0, $configArray['Caching']['patron_profile']);
     return $profile;
 }
Exemplo n.º 13
0
 /**
  * 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);
         }
     }
 }
Exemplo n.º 14
0
 /**
  *
  * Add an item to the cart in overdrive and then process the cart so it is checked out.
  *
  * @param string $overDriveId
  * @param int $format
  * @param int $lendingPeriod  the number of days that the user would like to have the title chacked out. or -1 to use the default
  * @param User $user
  */
 public function checkoutOverDriveItem($overDriveId, $format, $lendingPeriod, $user)
 {
     global $logger;
     $ch = curl_init();
     $overDriveInfo = $this->_loginToOverDrive($ch, $user);
     $closeSession = true;
     $addCartResult = $this->addItemToOverDriveCart($overDriveId, $format, $user, $overDriveInfo);
     if ($addCartResult['result'] == true) {
         $processCartResult = $this->processOverDriveCart($user, $lendingPeriod, $overDriveInfo);
         if ($processCartResult['result'] == true) {
             //Delete the cache for the record
             global $memCache;
             $memCache->delete('overdrive_record_' . $overDriveId);
             $memCache->delete('overdrive_items_' . $overDriveId);
             //Record that the entry was checked out in strands
             global $configArray;
             $eContentRecord = new EContentRecord();
             $eContentRecord->whereAdd("sourceUrl like '%{$overDriveId}'");
             if ($eContentRecord->find(true)) {
                 if (isset($configArray['Strands']['APID']) && $user->disableRecommendations == 0) {
                     //Get the record for the item
                     $orderId = $user->id . '_' . time();
                     $strandsUrl = "http://bizsolutions.strands.com/api2/event/purchased.sbs?needresult=true&apid={$configArray['Strands']['APID']}&item=econtentRecord{$eContentRecord->id}::0.00::1&user={$user->id}&orderid={$orderId}";
                     $ret = file_get_contents($strandsUrl);
                     /*global $logger;
                     		$logger->log("Strands Checkout\r\n$ret", PEAR_LOG_INFO);*/
                 }
                 //Add the record to the reading history
                 require_once ROOT_DIR . '/Drivers/EContentDriver.php';
                 $eContentDriver = new EContentDriver();
                 $eContentDriver->addRecordToReadingHistory($eContentRecord, $user);
             }
         }
         curl_close($ch);
         return $processCartResult;
     } else {
         curl_close($ch);
         return $addCartResult;
     }
 }
Exemplo n.º 15
0
 function launch()
 {
     global $interface;
     global $configArray;
     global $user;
     $driver = new EContentDriver();
     $id = strip_tags($_REQUEST['id']);
     $interface->assign('id', $id);
     global $logger;
     //Get title information for the record.
     $eContentRecord = new EContentRecord();
     $eContentRecord->id = $id;
     if (!$eContentRecord->find(true)) {
         PEAR_Singleton::raiseError("Unable to find eContent record for id: {$id}");
     }
     if (isset($_POST['submit']) || $user) {
         if (isset($_REQUEST['username']) && isset($_REQUEST['password'])) {
             //Log the user in
             $user = UserAccount::login();
         }
         if (!PEAR_Singleton::isError($user) && $user) {
             //The user is already logged in
             $return = $driver->checkoutRecord($id, $user);
             $interface->assign('result', $return['result']);
             $message = $return['message'];
             $interface->assign('message', $message);
             global $logger;
             $logger->log("Result of checkout " . print_r($return, true), PEAR_LOG_DEBUG);
             $showMessage = true;
         } else {
             $message = 'Incorrect Patron Information';
             $interface->assign('message', $message);
             $interface->assign('focusElementId', 'username');
             $showMessage = true;
         }
     } else {
         //Get the referrer so we can go back there.
         if (isset($_SERVER['HTTP_REFERER'])) {
             $referer = $_SERVER['HTTP_REFERER'];
             $_SESSION['checkout_referrer'] = $referer;
         }
         //Showing checkout form.
         if (!PEAR_Singleton::isError($user) && $user) {
             //set focus to the submit button if the user is logged in since the campus will be correct most of the time.
             $interface->assign('focusElementId', 'submit');
         } else {
             //set focus to the username field by default.
             $interface->assign('focusElementId', 'username');
         }
     }
     if (isset($return) && $showMessage) {
         $hold_message_data = array('successful' => $return['result'] ? 'all' : 'none', 'error' => isset($return['error']) ? $return['error'] : null, 'titles' => array($return));
         $_SESSION['checkout_message'] = $hold_message_data;
         if (isset($_SESSION['checkout_referrer'])) {
             $logger->log('Checkout Referrer is set, redirecting to there.  referrer = ' . $_SESSION['checkout_referrer'], PEAR_LOG_INFO);
             header("Location: " . $_SESSION['checkout_referrer']);
             unset($_SESSION['checkout_referrer']);
             if (isset($_SESSION['autologout'])) {
                 unset($_SESSION['autologout']);
                 UserAccount::softLogout();
             }
         } else {
             $logger->log('No referrer set, but there is a message to show, go to the main eContent page', PEAR_LOG_INFO);
             header("Location: /MyResearch/EContentCheckedOut");
         }
     } else {
         //Var for the IDCLREADER TEMPLATE
         $interface->assign('ButtonBack', true);
         $interface->assign('ButtonHome', true);
         $interface->assign('MobileTitle', 'Login to your account');
         $logger->log('eContent checkout finished, do not need to show a message', PEAR_LOG_INFO);
         $interface->setPageTitle('Checkout Item');
         $interface->assign('subTemplate', 'checkout.tpl');
         $interface->setTemplate('checkout.tpl');
         $interface->display('layout.tpl', 'RecordHold' . $_GET['id']);
     }
 }
Exemplo n.º 16
0
 /**
  * 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');
 }
Exemplo n.º 17
0
 function launch()
 {
     global $configArray;
     global $interface;
     global $user;
     //these actions are being moved to MyAccount/AJAX.php
     if (isset($_REQUEST['multiAction'])) {
         $multiAction = $_REQUEST['multiAction'];
         $locationId = isset($_REQUEST['location']) ? $_REQUEST['location'] : null;
         $cancelId = array();
         $type = 'update';
         $freeze = '';
         if ($multiAction == 'cancelSelected') {
             $type = 'cancel';
             //				$freeze = ''; // same as default setting.
         } elseif ($multiAction == 'freezeSelected') {
             //				$type = 'update'; // same as default setting.
             $freeze = 'on';
         } elseif ($multiAction == 'thawSelected') {
             //				$type = 'update'; // same as default setting.
             $freeze = 'off';
         }
         //			elseif ($multiAction == 'updateSelected'){ // same as default settings.
         //				$type = 'update';
         //				$freeze = '';
         //			}
         $result = $this->catalog->driver->updateHoldDetailed($user->password, $type, '', null, $cancelId, $locationId, $freeze);
         //			$interface->assign('holdResult', $result);
         //Redirect back here without the extra parameters.
         $redirectUrl = $configArray['Site']['path'] . '/MyAccount/Holds?accountSort=' . ($selectedSortOption = isset($_REQUEST['accountSort']) ? $_REQUEST['accountSort'] : 'title');
         header("Location: " . $redirectUrl);
         die;
     }
     $interface->assign('allowFreezeHolds', true);
     $ils = $configArray['Catalog']['ils'];
     $showPosition = $ils == 'Horizon' || ($ils = 'Koha');
     $showExpireTime = $ils == 'Horizon';
     $suspendRequiresReactivationDate = $ils == 'Horizon';
     $interface->assign('suspendRequiresReactivationDate', $suspendRequiresReactivationDate);
     $canChangePickupLocation = $ils != 'Koha';
     $interface->assign('canChangePickupLocation', $canChangePickupLocation);
     // Define sorting options
     $sortOptions = array('title' => 'Title', 'author' => 'Author', 'format' => 'Format', 'placed' => 'Date Placed', 'location' => 'Pickup Location', 'status' => 'Status');
     if ($showPosition) {
         $sortOptions['position'] = 'Position';
     }
     $interface->assign('sortOptions', $sortOptions);
     $selectedSortOption = isset($_REQUEST['accountSort']) ? $_REQUEST['accountSort'] : 'title';
     $interface->assign('defaultSortOption', $selectedSortOption);
     $profile = $this->catalog->getMyProfile($user);
     // TODO: getMyProfile called for second time. First time on index.php
     $libraryHoursMessage = Location::getLibraryHoursMessage($profile['homeLocationId']);
     $interface->assign('libraryHoursMessage', $libraryHoursMessage);
     $allowChangeLocation = $ils == 'Millennium' || $ils == 'Sierra';
     $interface->assign('allowChangeLocation', $allowChangeLocation);
     //$showPlacedColumn = ($ils == 'Horizon');
     //Horizon Web Services does not include data placed anymore
     $showPlacedColumn = false;
     $interface->assign('showPlacedColumn', $showPlacedColumn);
     $showDateWhenSuspending = $ils == 'Horizon';
     $interface->assign('showDateWhenSuspending', $showDateWhenSuspending);
     $interface->assign('showPosition', $showPosition);
     $interface->assign('showNotInterested', false);
     // Get My Transactions
     if ($configArray['Catalog']['offline']) {
         $interface->assign('offline', true);
     } else {
         $patron = null;
         if ($this->catalog->status) {
             if ($user->cat_username) {
                 $patron = $this->catalog->patronLogin($user->cat_username, $user->cat_password);
                 $patronResult = $this->catalog->getMyProfile($patron);
                 // TODO: getMyProfile called above already. Is this call necessary?
                 if (!PEAR_Singleton::isError($patronResult)) {
                     $interface->assign('profile', $patronResult);
                 }
                 $interface->assign('sortOptions', $sortOptions);
                 $selectedSortOption = isset($_REQUEST['accountSort']) ? $_REQUEST['accountSort'] : 'dueDate';
                 $interface->assign('defaultSortOption', $selectedSortOption);
                 $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
                 $recordsPerPage = isset($_REQUEST['pagesize']) && is_numeric($_REQUEST['pagesize']) ? $_REQUEST['pagesize'] : 25;
                 $interface->assign('recordsPerPage', $recordsPerPage);
                 if (isset($_GET['exportToExcel'])) {
                     $recordsPerPage = -1;
                     $page = 1;
                 }
                 //Get Holds from the ILS
                 $ilsHolds = $this->catalog->getMyHolds($patron, 1, -1, $selectedSortOption);
                 if (PEAR_Singleton::isError($ilsHolds)) {
                     $ilsHolds = array();
                 }
                 //Get holds from OverDrive
                 require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
                 $overDriveDriver = OverDriveDriverFactory::getDriver();
                 $overDriveHolds = $overDriveDriver->getOverDriveHolds($user);
                 //Get a list of eContent that has been checked out
                 require_once ROOT_DIR . '/Drivers/EContentDriver.php';
                 $driver = new EContentDriver();
                 $eContentHolds = $driver->getMyHolds($user);
                 $allHolds = array_merge_recursive($ilsHolds, $overDriveHolds, $eContentHolds);
                 /* pickUpLocations doesn't seem to be used by the Holds summary page. plb 1-26-2015
                 			$location = new Location();
                 			$pickupBranches = $location->getPickupBranches($patronResult, null);
                 			$locationList = array();
                 			foreach ($pickupBranches as $curLocation) {
                 				$locationList[$curLocation->locationId] = $curLocation->displayName;
                 			}
                 			$interface->assign('pickupLocations', $locationList); */
                 //Make sure available holds come before unavailable
                 $interface->assign('recordList', $allHolds['holds']);
                 //make call to export function
                 if (isset($_GET['exportToExcelAvailable']) || isset($_GET['exportToExcelUnavailable'])) {
                     if (isset($_GET['exportToExcelAvailable'])) {
                         $exportType = "available";
                     } else {
                         $exportType = "unavailable";
                     }
                     $this->exportToExcel($allHolds['holds'], $exportType, $showDateWhenSuspending, $showPosition, $showExpireTime);
                 }
             }
         }
         $interface->assign('patron', $patron);
     }
     //Load holds that have been entered offline
     if ($user) {
         require_once ROOT_DIR . '/sys/OfflineHold.php';
         $twoDaysAgo = time() - 48 * 60 * 60;
         $twoWeeksAgo = time() - 14 * 24 * 60 * 60;
         $offlineHoldsObj = new OfflineHold();
         $offlineHoldsObj->patronId = $user->id;
         $offlineHoldsObj->whereAdd("status = 'Not Processed' OR (status = 'Hold Placed' AND timeEntered >= {$twoDaysAgo}) OR (status = 'Hold Failed' AND timeEntered >= {$twoWeeksAgo})");
         // mysql has these functions as well: "status = 'Not Processed' OR (status = 'Hold Placed' AND timeEntered >= DATE_SUB(NOW(), INTERVAL 2 DAYS)) OR (status = 'Hold Failed' AND timeEntered >= DATE_SUB(NOW(), INTERVAL 2 WEEKS))");
         $offlineHolds = array();
         if ($offlineHoldsObj->find()) {
             while ($offlineHoldsObj->fetch()) {
                 //Load the title
                 $offlineHold = array();
                 require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php';
                 $recordDriver = new MarcRecord($offlineHoldsObj->bibId);
                 if ($recordDriver->isValid()) {
                     $offlineHold['title'] = $recordDriver->getTitle();
                 }
                 $offlineHold['bibId'] = $offlineHoldsObj->bibId;
                 $offlineHold['timeEntered'] = $offlineHoldsObj->timeEntered;
                 $offlineHold['status'] = $offlineHoldsObj->status;
                 $offlineHold['notes'] = $offlineHoldsObj->notes;
                 $offlineHolds[] = $offlineHold;
             }
         }
         $interface->assign('offlineHolds', $offlineHolds);
     }
     $interface->setPageTitle('My Holds');
     $interface->assign('sidebar', 'MyAccount/account-sidebar.tpl');
     global $library;
     if (!$library->showDetailedHoldNoticeInformation) {
         $notification_method = '';
     } else {
         $notification_method = $profile['noticePreferenceLabel'] != 'Unknown' ? $profile['noticePreferenceLabel'] : '';
         if ($notification_method == 'Mail' && $library->treatPrintNoticesAsPhoneNotices) {
             $notification_method = 'Telephone';
         }
     }
     $interface->assign('notification_method', strtolower($notification_method));
     $interface->setTemplate('holds.tpl');
     //print_r($patron);
     $interface->display('layout.tpl');
 }
Exemplo n.º 18
0
 /**
  * @param User $patron
  * @param bool $forceReload
  * @return array
  */
 public function getMyProfile($patron, $forceReload = false)
 {
     //Update to not use SIP, just screen scrape for performance (sigh)
     global $timer;
     /** @var Memcache $memCache */
     global $memCache;
     if (!is_object($patron)) {
         $tmpPatron = new User();
         $tmpPatron->username = $patron['username'];
         $tmpPatron->cat_username = $patron['cat_username'];
         $tmpPatron->cat_password = $patron['cat_password'];
         $tmpPatron->firstname = $patron['firstname'];
         $tmpPatron->lastname = $patron['lastname'];
         $tmpPatron->email = $patron['email'];
         $tmpPatron->patronType = $patron['patronType'];
         $patron = $tmpPatron;
     }
     if (!$forceReload && !isset($_REQUEST['reload'])) {
         // Check the Object for profile
         if (array_key_exists($patron->username, $this->patronProfiles)) {
             $timer->logTime('Retrieved Cached Profile for Patron');
             return $this->patronProfiles[$patron->username];
         }
     }
     // Determine memcache key
     global $serverName;
     $memCacheProfileKey = "patronProfile_{$serverName}_";
     if (is_object($patron) && !isset($tmpPatron)) {
         // exclude the new patron object $tmpPatron created above. It won't have an id or be stored in memcache
         //				$patron         = get_object_vars($patron);
         //			$memCacheProfileKey = $patron['username'];
         // $patron needs to remain an object for initial loading below
         $memCacheProfileKey .= $patron->username;
     } else {
         global $user;
         //				$memCacheProfileKey = $user->id;
         $memCacheProfileKey .= $user->username;
     }
     // Check MemCache for profile
     if (!$forceReload && !isset($_REQUEST['reload'])) {
         $patronProfile = $memCache->get($memCacheProfileKey);
         if ($patronProfile) {
             //echo("Using cached profile for patron " . $userId);
             $timer->logTime('Retrieved Cached Profile for Patron');
             return $patronProfile;
         }
     }
     $this->initDatabaseConnection();
     $this->getUserInfoStmt->bind_param('ss', $patron->cat_username, $patron->cat_username);
     if ($this->getUserInfoStmt->execute()) {
         if ($userFromDbResultSet = $this->getUserInfoStmt->get_result()) {
             $userFromDb = $userFromDbResultSet->fetch_assoc();
             $userFromDbResultSet->close();
             //				$city = $userFromDb['city'];
             //				$state = "";
             //				$commaPos = strpos($city, ',');
             //				if ($commaPos !== false){ // fix this
             //					$cityState = $city;
             //					$city = substr($cityState, 0, $commaPos);
             //					$state = substr($cityState, $commaPos);
             //				}
             $city = strtok($userFromDb['city'], ',');
             $state = strtok(',');
             $city = trim($city);
             $state = trim($state);
             //Get fines
             //Load fines from database
             $outstandingFines = $this->getOutstandingFineTotal();
             //Get number of items checked out
             $checkedOutItemsRS = mysqli_query($this->dbConnection, 'SELECT count(*) as numCheckouts FROM issues WHERE borrowernumber = ' . $patron->username);
             $numCheckouts = 0;
             if ($checkedOutItemsRS) {
                 $checkedOutItems = $checkedOutItemsRS->fetch_assoc();
                 $numCheckouts = $checkedOutItems['numCheckouts'];
                 $checkedOutItemsRS->close();
             }
             //Get number of available holds
             $availableHoldsRS = mysqli_query($this->dbConnection, 'SELECT count(*) as numHolds FROM reserves WHERE waitingdate is not null and borrowernumber = ' . $patron->username);
             $numAvailableHolds = 0;
             if ($availableHoldsRS) {
                 $availableHolds = $availableHoldsRS->fetch_assoc();
                 $numAvailableHolds = $availableHolds['numHolds'];
                 $availableHoldsRS->close();
             }
             //Get number of unavailable
             $waitingHoldsRS = mysqli_query($this->dbConnection, 'SELECT count(*) as numHolds FROM reserves WHERE waitingdate is null and borrowernumber = ' . $patron->username);
             $numWaitingHolds = 0;
             if ($waitingHoldsRS) {
                 $waitingHolds = $waitingHoldsRS->fetch_assoc();
                 $numWaitingHolds = $waitingHolds['numHolds'];
                 $waitingHoldsRS->close();
             }
             $homeBranchCode = $userFromDb['branchcode'];
             $location = new Location();
             $location->code = $homeBranchCode;
             $location->find(1);
             if ($location->N == 0) {
                 unset($location);
             }
             global $user;
             $profile = array('lastname' => $patron->lastname, 'firstname' => $patron->firstname, 'displayName' => isset($patron->displayName) ? $patron->displayName : '', 'fullname' => $user->lastname . ', ' . $user->firstname, 'address1' => trim($userFromDb['streetnumber'] . ' ' . $userFromDb['address'] . ' ' . $userFromDb['address2']), 'city' => $city, 'state' => $state, 'zip' => $userFromDb['zipcode'], 'phone' => $userFromDb['phone'], 'email' => $userFromDb['email'], 'homeLocationId' => isset($location) ? $location->locationId : -1, 'homeLocationName' => '', 'expires' => $userFromDb['dateexpiry'], 'fines' => sprintf('$%0.2f', $outstandingFines), 'finesval' => floatval($outstandingFines), 'numHolds' => $numWaitingHolds + $numAvailableHolds, 'numHoldsAvailable' => $numAvailableHolds, 'numHoldsRequested' => $numWaitingHolds, 'numCheckedOut' => $numCheckouts, 'bypassAutoLogout' => $user ? $user->bypassAutoLogout : false);
             $profile['noticePreferenceLabel'] = 'Unknown';
             //Get eContent info as well
             require_once ROOT_DIR . '/Drivers/EContentDriver.php';
             $eContentDriver = new EContentDriver();
             $eContentAccountSummary = $eContentDriver->getAccountSummary();
             $profile = array_merge($profile, $eContentAccountSummary);
             require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
             $overDriveDriver = OverDriveDriverFactory::getDriver();
             if ($overDriveDriver->isUserValidForOverDrive($user)) {
                 $overDriveSummary = $overDriveDriver->getOverDriveSummary($user);
                 $profile['numOverDriveCheckedOut'] = $overDriveSummary['numCheckedOut'];
                 $profile['numOverDriveHoldsAvailable'] = $overDriveSummary['numAvailableHolds'];
                 $profile['numOverDriveHoldsRequested'] = $overDriveSummary['numUnavailableHolds'];
                 $profile['canUseOverDrive'] = true;
             } else {
                 $profile['numOverDriveCheckedOut'] = 0;
                 $profile['numOverDriveHoldsAvailable'] = 0;
                 $profile['numOverDriveHoldsRequested'] = 0;
                 $profile['canUseOverDrive'] = false;
             }
             $profile['numCheckedOutTotal'] = $profile['numCheckedOut'] + $profile['numOverDriveCheckedOut'] + $eContentAccountSummary['numEContentCheckedOut'];
             $profile['numHoldsAvailableTotal'] = $profile['numHoldsAvailable'] + $profile['numOverDriveHoldsAvailable'] + $eContentAccountSummary['numEContentAvailableHolds'];
             $profile['numHoldsRequestedTotal'] = $profile['numHoldsRequested'] + $profile['numOverDriveHoldsRequested'] + $eContentAccountSummary['numEContentUnavailableHolds'];
             $profile['numHoldsTotal'] = $profile['numHoldsAvailableTotal'] + $profile['numHoldsRequestedTotal'];
             //Get a count of the materials requests for the user
             if ($user) {
                 $homeLibrary = Library::getPatronHomeLibrary();
                 if ($homeLibrary) {
                     $materialsRequest = new MaterialsRequest();
                     $materialsRequest->createdBy = $user->id;
                     $statusQuery = new MaterialsRequestStatus();
                     $statusQuery->isOpen = 1;
                     $statusQuery->libraryId = $homeLibrary->libraryId;
                     $materialsRequest->joinAdd($statusQuery);
                     $materialsRequest->find();
                     $profile['numMaterialsRequests'] = $materialsRequest->N;
                 } else {
                     $profile['numMaterialsRequests'] = 0;
                 }
                 if ($user->homeLocationId == 0 && isset($location)) {
                     $user->homeLocationId = $location->locationId;
                     if ($location->nearbyLocation1 > 0) {
                         $user->myLocation1Id = $location->nearbyLocation1;
                     } else {
                         $user->myLocation1Id = $location->locationId;
                     }
                     if ($location->nearbyLocation2 > 0) {
                         $user->myLocation2Id = $location->nearbyLocation2;
                     } else {
                         $user->myLocation2Id = $location->locationId;
                     }
                     if ($user instanceof User) {
                         //Update the database
                         $user->update();
                         //Update the serialized instance stored in the session
                         $_SESSION['userinfo'] = serialize($user);
                     }
                 } else {
                     if (isset($location) && $location->locationId != $user->homeLocationId) {
                         $user->homeLocationId = $location->locationId;
                         //Update the database
                         $user->update();
                         //Update the serialized instance stored in the session
                         $_SESSION['userinfo'] = serialize($user);
                     }
                 }
             }
         } else {
             $profile = PEAR_Singleton::raiseError('patron_info_error_technical - could not load from database');
         }
     } else {
         $profile = PEAR_Singleton::raiseError('patron_info_error_technical - could not execute user info statement');
     }
     $this->patronProfiles[$patron->username] = $profile;
     $timer->logTime('Retrieved Profile for Patron from Database');
     global $configArray, $serverName;
     $memCache->set($memCacheProfileKey, $profile, 0, $configArray['Caching']['patron_profile']);
     // Looks like all drivers but aspencat use id rather than username.
     // plb 4-16-2014
     return $profile;
 }
Exemplo n.º 19
0
 /**
  * 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);
 }
Exemplo n.º 20
0
 /**
  * Get Patron Profile
  *
  * This is responsible for retrieving the profile for a specific patron.
  * Interface defined in CatalogConnection.php
  *
  * @param   array   $patron     The patron array
  * @return  array               Array of the patron's profile data
  *                              If an error occures, return a PEAR_Error
  * @access  public
  */
 public function getMyProfile($patron)
 {
     global $timer;
     global $configArray;
     if (is_object($patron)) {
         $patron = get_object_vars($patron);
         $id2 = $this->_getBarcode();
     } else {
         $id2 = $patron['id'];
     }
     if (array_key_exists($patron['id'], $this->patronProfiles)) {
         $timer->logTime('Retrieved Cached Profile for Patron');
         return $this->patronProfiles[$patron['id']];
     }
     //Load the raw information about the patron
     $patronDump = $this->_getPatronDump($id2);
     if (isset($patronDump['ADDRESS'])) {
         $Fulladdress = $patronDump['ADDRESS'];
         $addressParts = explode('$', $Fulladdress);
         $Address1 = $addressParts[0];
         $City = isset($addressParts[1]) ? $addressParts[1] : '';
         $State = isset($addressParts[2]) ? $addressParts[2] : '';
         $Zip = isset($addressParts[3]) ? $addressParts[3] : '';
         if (preg_match('/(.*?),\\s+(.*)\\s+(\\d*(?:-\\d*)?)/', $City, $matches)) {
             $City = $matches[1];
             $State = $matches[2];
             $Zip = $matches[3];
         }
     } else {
         $Address1 = "";
         $City = "";
         $State = "";
         $Zip = "";
     }
     $fullName = $patronDump['PATRN_NAME'];
     $nameParts = explode(', ', $fullName);
     $lastName = $nameParts[0];
     $secondName = isset($nameParts[1]) ? $nameParts[1] : '';
     if (strpos($secondName, ' ')) {
         $nameParts2 = explode(' ', $secondName);
         $firstName = $nameParts2[0];
     } else {
         $firstName = $secondName;
     }
     //Get additional information about the patron's home branch for display.
     $homeBranchCode = $patronDump['HOME_LIBR'];
     //Translate home branch to plain text
     global $user;
     $location = new Location();
     $location->whereAdd("code = '{$homeBranchCode}'");
     $location->find(1);
     if ($user) {
         if ($user->homeLocationId == 0) {
             $user->homeLocationId = $location->locationId;
             if ($location->nearbyLocation1 > 0) {
                 $user->myLocation1Id = $location->nearbyLocation1;
             } else {
                 $user->myLocation1Id = $location->locationId;
             }
             if ($location->nearbyLocation2 > 0) {
                 $user->myLocation2Id = $location->nearbyLocation2;
             } else {
                 $user->myLocation2Id = $location->locationId;
             }
             if ($user instanceof User) {
                 //Update the database
                 $user->update();
                 //Update the serialized instance stored in the session
                 $_SESSION['userinfo'] = serialize($user);
             }
         }
         //Get display name for preferred location 1
         $myLocation1 = new Location();
         $myLocation1->whereAdd("locationId = '{$user->myLocation1Id}'");
         $myLocation1->find(1);
         //Get display name for preferred location 1
         $myLocation2 = new Location();
         $myLocation2->whereAdd("locationId = '{$user->myLocation2Id}'");
         $myLocation2->find(1);
     }
     //see if expiration date is close
     list($monthExp, $dayExp, $yearExp) = explode("-", $patronDump['EXP_DATE']);
     $timeExpire = strtotime($monthExp . "/" . $dayExp . "/" . $yearExp);
     $timeNow = time();
     $timeToExpire = $timeExpire - $timeNow;
     if ($timeToExpire <= 30 * 24 * 60 * 60) {
         $expireClose = 1;
     } else {
         $expireClose = 0;
     }
     $finesVal = floatval(preg_replace('/[^\\d.]/', '', $patronDump['MONEY_OWED']));
     $numHoldsAvailable = 0;
     $numHoldsRequested = 0;
     $availableStatusRegex = isset($configArray['Catalog']['patronApiAvailableHoldsRegex']) ? $configArray['Catalog']['patronApiAvailableHoldsRegex'] : "/ST=(105|98),/";
     if (isset($patronDump['HOLD']) && count($patronDump['HOLD']) > 0) {
         foreach ($patronDump['HOLD'] as $hold) {
             if (preg_match("{$availableStatusRegex}", $hold)) {
                 $numHoldsAvailable++;
             } else {
                 $numHoldsRequested++;
             }
         }
     }
     $profile = array('lastname' => $lastName, 'firstname' => $firstName, 'fullname' => $fullName, 'address1' => $Address1, 'address2' => $City . ', ' . $State, 'city' => $City, 'state' => $State, 'zip' => $Zip, 'email' => isset($patronDump['EMAIL_ADDR']) ? $patronDump['EMAIL_ADDR'] : '', 'overdriveEmail' => $user ? $user->overdriveEmail : (isset($patronDump['EMAIL_ADDR']) ? $patronDump['EMAIL_ADDR'] : ''), 'promptForOverdriveEmail' => $user ? $user->promptForOverdriveEmail : 1, 'phone' => isset($patronDump['TELEPHONE']) ? $patronDump['TELEPHONE'] : '', 'fines' => $patronDump['MONEY_OWED'], 'finesval' => $finesVal, 'expires' => $patronDump['EXP_DATE'], 'expireclose' => $expireClose, 'homeLocationCode' => trim($homeBranchCode), 'homeLocationId' => $location->locationId, 'homeLocation' => $location->displayName, 'myLocation1Id' => $user ? $user->myLocation1Id : -1, 'myLocation1' => isset($myLocation1) ? $myLocation1->displayName : '', 'myLocation2Id' => $user ? $user->myLocation2Id : -1, 'myLocation2' => isset($myLocation2) ? $myLocation2->displayName : '', 'numCheckedOut' => $patronDump['CUR_CHKOUT'], 'numHolds' => isset($patronDump['HOLD']) ? count($patronDump['HOLD']) : 0, 'numHoldsAvailable' => $numHoldsAvailable, 'numHoldsRequested' => $numHoldsRequested, 'bypassAutoLogout' => $user ? $user->bypassAutoLogout : 0, 'ptype' => $patronDump['P_TYPE'], 'notices' => $patronDump['NOTICE_PREF'], 'web_note' => isset($patronDump['WEB_NOTE']) ? $patronDump['WEB_NOTE'] : '');
     //Get eContent info as well
     require_once ROOT_DIR . '/Drivers/EContentDriver.php';
     $eContentDriver = new EContentDriver();
     $eContentAccountSummary = $eContentDriver->getAccountSummary();
     $profile = array_merge($profile, $eContentAccountSummary);
     //Get a count of the materials requests for the user
     if ($user) {
         $materialsRequest = new MaterialsRequest();
         $materialsRequest->createdBy = $user->id;
         $homeLibrary = Library::getPatronHomeLibrary();
         $statusQuery = new MaterialsRequestStatus();
         $statusQuery->isOpen = 1;
         $statusQuery->libraryId = $homeLibrary->libraryId;
         $materialsRequest->joinAdd($statusQuery);
         $materialsRequest->find();
         $profile['numMaterialsRequests'] = $materialsRequest->N;
     }
     $timer->logTime("Got Patron Profile");
     $this->patronProfiles[$patron['id']] = $profile;
     return $profile;
 }
Exemplo n.º 21
0
 public function getMyProfile($patron, $forceReload = false)
 {
     global $timer;
     global $configArray;
     if (is_object($patron)) {
         $patron = get_object_vars($patron);
     }
     if (array_key_exists($patron['username'], $this->patronProfiles) && !$forceReload) {
         $timer->logTime('Retrieved Cached Profile for Patron');
         return $this->patronProfiles[$patron['username']];
     }
     $mysip = new sip2();
     $mysip->hostname = $configArray['SIP2']['host'];
     $mysip->port = $configArray['SIP2']['port'];
     if ($mysip->connect()) {
         //send selfcheck status message
         $in = $mysip->msgSCStatus();
         $msg_result = $mysip->get_message($in);
         // Make sure the response is 98 as expected
         if (preg_match("/^98/", $msg_result)) {
             $result = $mysip->parseACSStatusResponse($msg_result);
             //  Use result to populate SIP2 setings
             $mysip->AO = $result['variable']['AO'][0];
             /* set AO to value returned */
             $mysip->AN = $result['variable']['AN'][0];
             /* set AN to value returned */
             $mysip->patron = $patron['username'];
             $mysip->patronpwd = $patron['cat_password'];
             $in = $mysip->msgPatronInformation('fine');
             $msg_result = $mysip->get_message($in);
             // Make sure the response is 24 as expected
             if (preg_match("/^64/", $msg_result)) {
                 $result = $mysip->parsePatronInfoResponse($msg_result);
                 $address = $result['variable']['BD'][0];
                 $addressParts = explode(',', $address);
                 $expirationDate = $result['variable']['PE'][0];
                 $formattedExpiration = substr($expirationDate, 4, 2) . '/' . substr($expirationDate, 6, 2) . '/' . substr($expirationDate, 0, 4);
                 //$fines = $this->parseSip2Fines($result['variable']['AV']);
                 $location = new Location();
                 $location->code = $result['variable']['AQ'][0];
                 $location->find();
                 if ($location->N > 0) {
                     $location->fetch();
                     $homeLocationId = $location->locationId;
                 }
                 global $user;
                 $profile = array('lastname' => $result['variable']['DJ'][0], 'firstname' => isset($result['variable']['DH'][0]) ? $result['variable']['DH'][0] : '', 'displayName' => $patron['displayName'], 'fullname' => $result['variable']['AE'][0], 'address1' => trim($addressParts[0]), 'city' => trim($addressParts[1]), 'state' => trim($addressParts[2]), 'zip' => isset($addressParts[3]) ? trim($addressParts[3]) : '', 'phone' => isset($result['variable']['BF'][0]) ? $result['variable']['BF'][0] : '', 'email' => isset($result['variable']['BE'][0]) ? $result['variable']['BE'][0] : '', 'homeLocationId' => isset($homeLocationId) ? $homeLocationId : -1, 'homeLocationName' => $this->translateLocation($result['variable']['AQ'][0]), 'expires' => $formattedExpiration, 'fines' => isset($result['variable']['BV']) ? sprintf('$%01.2f', $result['variable']['BV'][0]) : 0, 'finesval' => isset($result['variable']['BV']) ? $result['variable']['BV'][0] : '', 'numHolds' => $result['fixed']['HoldCount'] + $result['fixed']['UnavailableCount'], 'numHoldsAvailable' => $result['fixed']['HoldCount'], 'numHoldsRequested' => $result['fixed']['UnavailableCount'], 'numCheckedOut' => $result['fixed']['ChargedCount'], 'bypassAutoLogout' => $user ? $user->bypassAutoLogout : false);
                 //Get eContent info as well
                 require_once ROOT_DIR . '/Drivers/EContentDriver.php';
                 $eContentDriver = new EContentDriver();
                 $eContentAccountSummary = $eContentDriver->getAccountSummary();
                 $profile = array_merge($profile, $eContentAccountSummary);
                 //Get a count of the materials requests for the user
                 $materialsRequest = new MaterialsRequest();
                 $materialsRequest->createdBy = $user->id;
                 $statusQuery = new MaterialsRequestStatus();
                 $statusQuery->isOpen = 1;
                 $materialsRequest->joinAdd($statusQuery);
                 $materialsRequest->find();
                 $profile['numMaterialsRequests'] = $materialsRequest->N;
             } else {
                 $profile = new PEAR_Error('patron_info_error_technical');
             }
         } else {
             $profile = new PEAR_Error('patron_info_error_technical');
         }
         $mysip->disconnect();
     } else {
         $profile = new PEAR_Error('patron_info_error_technical');
     }
     $this->patronProfiles[$patron['username']] = $profile;
     $timer->logTime('Retrieved Profile for Patron from SIP 2');
     return $profile;
 }
Exemplo n.º 22
0
 function GetHoldingsInfo()
 {
     global $interface;
     global $configArray;
     $interface->assign('showOtherEditionsPopup', $configArray['Content']['showOtherEditionsPopup']);
     $id = strip_tags($_REQUEST['id']);
     $interface->assign('id', $id);
     //Load holdings information from the driver
     require_once ROOT_DIR . '/Drivers/EContentDriver.php';
     require_once ROOT_DIR . '/sys/eContent/EContentRecord.php';
     $driver = new EContentDriver();
     //Get any items that are stored for the record
     $eContentRecord = new EContentRecord();
     $eContentRecord->id = $id;
     $eContentRecord->find(true);
     /** @var EContentItem[] $holdings */
     $holdings = $driver->getHolding($id);
     $showEContentNotes = false;
     foreach ($holdings as $holding) {
         if (strlen($holding->notes) > 0) {
             $showEContentNotes = true;
         }
     }
     $interface->assign('record', $eContentRecord);
     $availability = $driver->getScopedAvailability($eContentRecord);
     $interface->assign('availability', $availability['mine']);
     $interface->assign('availabilityOther', $availability['other']);
     $showAvailability = true;
     $showAvailabilityOther = true;
     if ($eContentRecord->accessType == 'external' && strcasecmp($eContentRecord->source, 'OverDrive') != 0) {
         $showAvailability = false;
         $showAvailabilityOther = false;
     }
     $interface->assign('showAvailability', $showAvailability);
     $interface->assign('showAvailabilityOther', $showAvailabilityOther);
     $interface->assign('source', $eContentRecord->source);
     $interface->assign('accessType', $eContentRecord->accessType);
     $interface->assign('showEContentNotes', $showEContentNotes);
     if ($eContentRecord->getIsbn() == null || strlen($eContentRecord->getIsbn()) == 0) {
         $interface->assign('showOtherEditionsPopup', false);
     }
     $showOverDriveConsole = false;
     $showAdobeDigitalEditions = false;
     foreach ($holdings as $item) {
         if (strcasecmp($item->getSource(), 'overdrive') == 0) {
             if (in_array($item->externalFormatId, array('ebook-epub-adobe', 'ebook-pdf-adobe'))) {
                 $showAdobeDigitalEditions = true;
             } else {
                 if (in_array($item->externalFormatId, array('video-wmv', 'music-wma', 'music-wma', 'audiobook-wma', 'audiobook-mp3'))) {
                     $showOverDriveConsole = true;
                 }
             }
         } else {
             if (in_array($item->item_type, array('epub', 'pdf'))) {
                 $showAdobeDigitalEditions = true;
             }
         }
     }
     $interface->assign('showOverDriveConsole', $showOverDriveConsole);
     $interface->assign('showAdobeDigitalEditions', $showAdobeDigitalEditions);
     $interface->assign('holdings', $holdings);
     //Load status summary
     $result = $driver->getStatusSummary($id, $holdings);
     if (PEAR_Singleton::isError($result)) {
         PEAR_Singleton::raiseError($result);
     }
     $interface->assign('holdingsSummary', $result);
     return $interface->fetch('EcontentRecord/ajax-holdings.tpl');
 }
Exemplo n.º 23
0
 function getItemAvailability()
 {
     global $timer;
     global $configArray;
     $itemData = array();
     //Load basic information
     $this->id = $_GET['id'];
     $itemData['id'] = $this->id;
     // Setup Search Engine Connection
     $class = $configArray['Index']['engine'];
     $url = $configArray['Index']['url'];
     $this->db = new $class($url);
     // Retrieve Full Marc Record
     disableErrorHandler();
     $record = $this->db->getRecord($this->id);
     enableErrorHandler();
     if ($record == false) {
         $marcRecord = new MarcRecord($this->id);
         if ($marcRecord->isValid()) {
             $itemData['holdings'] = Record_Holdings::loadHoldings($this->id);
             $timer->logTime('Loaded Holdings');
         } else {
             $itemData['error'] = 'Cannot load Record for id ' . $record['id'];
         }
     } else {
         $this->record = $record;
         if ($record['recordtype'] == 'econtentRecord') {
             require_once ROOT_DIR . '/sys/eContent/EContentRecord.php';
             $eContentRecord = new EContentRecord();
             $eContentRecord->id = substr($record['id'], strlen('econtentRecord'));
             if (!$eContentRecord->find(true)) {
                 $itemData['error'] = 'Cannot load eContent Record for id ' . $record['id'];
             } else {
                 require_once ROOT_DIR . '/Drivers/EContentDriver.php';
                 $driver = new EContentDriver();
                 $itemData['holdings'] = $driver->getHolding($eContentRecord->id);
             }
         } else {
             $this->recordDriver = RecordDriverFactory::initRecordDriver($record);
             $timer->logTime('Initialized the Record Driver');
             //Load Holdings
             $itemData['holdings'] = Record_Holdings::loadHoldings($this->id);
             $timer->logTime('Loaded Holdings');
         }
     }
     return $itemData;
 }
Exemplo n.º 24
0
 function placeHolds()
 {
     global $interface;
     global $configArray;
     global $user;
     if (!isset($_REQUEST['selected'])) {
         $hold_message_data = array('successful' => 'none', 'error' => 'No titles were selected', 'titles' => array());
         $showMessage = true;
     } else {
         $selectedIds = $_REQUEST['selected'];
         $eContentDriver = null;
         $showMessage = false;
         $holdings = array();
         //Check to see if all items are eContent
         $ids = array();
         $allItemsEContent = true;
         foreach ($selectedIds as $recordId => $onOff) {
             $ids[] = $recordId;
             //Get the title for the item
             $resource = new Resource();
             if (strpos($recordId, 'econtentRecord') !== 0) {
                 $allItemsEContent = false;
                 $resource->record_id = '.' . $recordId;
                 $resource->source = 'VuFind';
                 $resource->deleted = 0;
             } else {
                 $shortId = str_replace('econtentRecord', '', $recordId);
                 $resource->record_id = $shortId;
                 $resource->source = 'eContent';
                 $resource->deleted = 0;
             }
             if ($resource->find(true)) {
                 $holdings[] = $resource->title;
             } else {
                 echo "Could not find resource for record id {$recordId}";
             }
         }
         $interface->assign('ids', $ids);
         $interface->assign('holdings', $holdings);
         $hold_message_data = array('successful' => 'all', 'titles' => array());
         if (isset($_REQUEST['autologout'])) {
             $_SESSION['autologout'] = true;
         }
         //Check to see if we are ready to place the hold.
         $placeHold = false;
         if (isset($_REQUEST['holdType']) && isset($_REQUEST['campus'])) {
             $placeHold = true;
         } else {
             if ($user && $allItemsEContent) {
                 $placeHold = true;
             }
         }
         if ($placeHold) {
             $hold_message_data['campus'] = $_REQUEST['campus'];
             //This is a new login
             if (isset($_REQUEST['username']) && isset($_REQUEST['password'])) {
                 $user = UserAccount::login();
             }
             if ($user == false) {
                 $hold_message_data['error'] = 'Incorrect Patron Information';
                 $showMessage = true;
             } else {
                 $atLeast1Successful = false;
                 foreach ($selectedIds as $recordId => $onOff) {
                     if (strpos($recordId, 'econtentRecord', 0) === 0) {
                         if ($eContentDriver == null) {
                             require_once ROOT_DIR . '/Drivers/EContentDriver.php';
                             $eContentDriver = new EContentDriver();
                         }
                         $return = $eContentDriver->placeHold($recordId, $user);
                     } else {
                         $return = $this->catalog->placeHold($recordId, $user->password, '', $_REQUEST['holdType']);
                     }
                     $hold_message_data['titles'][] = $return;
                     if (!$return['result']) {
                         $hold_message_data['successful'] = 'partial';
                     } else {
                         $atLeast1Successful = true;
                     }
                     //Check to see if there are item level holds that need follow-up by the user
                     if (isset($return['items'])) {
                         $hold_message_data['showItemForm'] = true;
                     }
                     $showMessage = true;
                 }
                 if (!$atLeast1Successful) {
                     $hold_message_data['successful'] = 'none';
                 }
             }
         } else {
             //Get the referrer so we can go back there.
             if (isset($_SERVER['HTTP_REFERER'])) {
                 $referer = $_SERVER['HTTP_REFERER'];
                 $_SESSION['hold_referrer'] = $referer;
             }
             //Showing place hold form.
             if ($user) {
                 $profile = $this->catalog->getMyProfile($user);
                 $interface->assign('profile', $profile);
                 //Get information to show a warning if the user does not have sufficient holds
                 require_once ROOT_DIR . '/Drivers/marmot_inc/PType.php';
                 $maxHolds = -1;
                 //Determine if we should show a warning
                 $ptype = new PType();
                 $ptype->pType = $user->patronType;
                 if ($ptype->find(true)) {
                     $maxHolds = $ptype->maxHolds;
                 }
                 $currentHolds = $profile['numHolds'];
                 if ($maxHolds != -1 && $currentHolds + count($selectedIds) > $maxHolds) {
                     $interface->assign('showOverHoldLimit', true);
                     $interface->assign('maxHolds', $maxHolds);
                     $interface->assign('currentHolds', $currentHolds);
                 }
                 global $locationSingleton;
                 //Get the list of pickup branch locations for display in the user interface.
                 $locations = $locationSingleton->getPickupBranches($profile, $profile['homeLocationId']);
                 $interface->assign('pickupLocations', $locations);
                 //set focus to the submit button if the user is logged in since the campus will be correct most of the time.
                 $interface->assign('focusElementId', 'submit');
             } else {
                 //set focus to the username field by default.
                 $interface->assign('focusElementId', 'username');
             }
             global $librarySingleton;
             $patronHomeBranch = $librarySingleton->getPatronHomeLibrary();
             if ($patronHomeBranch != null) {
                 if ($patronHomeBranch->defaultNotNeededAfterDays > 0) {
                     $interface->assign('defaultNotNeededAfterDays', date('m/d/Y', time() + $patronHomeBranch->defaultNotNeededAfterDays * 60 * 60 * 24));
                 } else {
                     $interface->assign('defaultNotNeededAfterDays', '');
                 }
                 $interface->assign('showHoldCancelDate', $patronHomeBranch->showHoldCancelDate);
             } else {
                 //Show the hold cancellation date for now.  It may be hidden later when the user logs in.
                 $interface->assign('showHoldCancelDate', 1);
                 $interface->assign('defaultNotNeededAfterDays', '');
             }
             $activeLibrary = $librarySingleton->getActiveLibrary();
             if ($activeLibrary != null) {
                 $interface->assign('holdDisclaimer', $activeLibrary->holdDisclaimer);
             } else {
                 //Show the hold cancellation date for now.  It may be hidden later when the user logs in.
                 $interface->assign('holdDisclaimer', '');
             }
         }
     }
     if ($showMessage) {
         $hold_message_data['fromCart'] = isset($_REQUEST['fromCart']);
         $_SESSION['hold_message'] = $hold_message_data;
         if (isset($_SESSION['hold_referrer'])) {
             if ($_REQUEST['type'] != 'recall' && $_REQUEST['type'] != 'cancel' && $_REQUEST['type'] != 'update') {
                 header("Location: " . $_SESSION['hold_referrer']);
             } else {
                 //Redirect for hold cancellation or update
                 header("Location: " . $configArray['Site']['path'] . '/MyResearch/Holds');
             }
             if (!isset($hold_message_data['showItemForm']) || $hold_message_data['showItemForm'] == false) {
                 unset($_SESSION['hold_referrer']);
                 if (isset($_SESSION['autologout'])) {
                     unset($_SESSION['autologout']);
                     UserAccount::softLogout();
                 }
             }
         } else {
             header("Location: " . $configArray['Site']['path'] . '/MyResearch/Holds');
         }
     } else {
         $interface->assign('fromCart', isset($_REQUEST['fromCart']));
         $interface->setPageTitle('Request Items');
         $interface->setTemplate('holdMultiple.tpl');
         $interface->display('layout.tpl', 'RecordHolds');
     }
 }
Exemplo n.º 25
0
 /**
  * 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');
     }
 }
Exemplo n.º 26
0
 /**
  * Get Patron Profile
  *
  * This is responsible for retrieving the profile for a specific patron.
  * Interface defined in CatalogConnection.php
  *
  * @param   array   $patron     The patron array
  * @param   boolean $forceReload Whether or not we should force a reload of the data
  * @return  array               Array of the patron's profile data
  *                              If an error occurs, return a PEAR_Error
  * @access  public
  */
 public function getMyProfile($patron, $forceReload = false)
 {
     global $timer;
     global $configArray;
     /** @var Memcache $memCache */
     global $memCache;
     global $serverName;
     $memCacheProfileKey = "patronProfile_{$serverName}_";
     if (is_object($patron)) {
         $patron = get_object_vars($patron);
         $memCacheProfileKey .= $patron['username'];
         $id2 = $this->_getBarcode($patron);
     } else {
         global $user;
         $memCacheProfileKey .= $user->username;
         $id2 = $patron['cat_password'];
     }
     if (!$forceReload && !isset($_REQUEST['reload'])) {
         $patronProfile = $memCache->get($memCacheProfileKey);
         if ($patronProfile) {
             $timer->logTime('Retrieved Cached Profile for Patron');
             return $patronProfile;
         }
     }
     global $user;
     if ($configArray['Catalog']['offline'] == true) {
         $fullName = $patron['cat_username'];
         $Address1 = "";
         $City = "";
         $State = "";
         $Zip = "";
         $finesVal = 0;
         $expireClose = false;
         $homeBranchCode = '';
         $numHoldsAvailable = '?';
         $numHoldsRequested = '?';
         if (!$user) {
             $user = new User();
             $user->cat_password = $id2;
             if ($user->find(true)) {
                 $location = new Location();
                 $location->locationId = $user->homeLocationId;
                 $location->find(1);
                 $homeBranchCode = $location->code;
             }
         }
     } else {
         //Load the raw information about the patron
         $patronDump = $this->_getPatronDump($id2);
         if (isset($patronDump['ADDRESS'])) {
             $fullAddress = $patronDump['ADDRESS'];
             $addressParts = explode('$', $fullAddress);
             $Address1 = $addressParts[0];
             $City = isset($addressParts[1]) ? $addressParts[1] : '';
             $State = isset($addressParts[2]) ? $addressParts[2] : '';
             $Zip = isset($addressParts[3]) ? $addressParts[3] : '';
             if (preg_match('/(.*?),\\s+(.*)\\s+(\\d*(?:-\\d*)?)/', $City, $matches)) {
                 $City = $matches[1];
                 $State = $matches[2];
                 $Zip = $matches[3];
             } else {
                 if (preg_match('/(.*?)\\s+(\\w{2})\\s+(\\d*(?:-\\d*)?)/', $City, $matches)) {
                     $City = $matches[1];
                     $State = $matches[2];
                     $Zip = $matches[3];
                 }
             }
         } else {
             $Address1 = "";
             $City = "";
             $State = "";
             $Zip = "";
         }
         $fullName = $patronDump['PATRN_NAME'];
         //Get additional information about the patron's home branch for display.
         $location = null;
         if (isset($patronDump['HOME_LIBR']) || isset($patronDump['HOLD_LIBR'])) {
             $homeBranchCode = isset($patronDump['HOME_LIBR']) ? $patronDump['HOME_LIBR'] : $patronDump['HOLD_LIBR'];
             $homeBranchCode = str_replace('+', '', $homeBranchCode);
             //Translate home branch to plain text
             $location = new Location();
             $location->whereAdd("code = '{$homeBranchCode}'");
             $location->find(1);
             if ($location->N == 0) {
                 unset($location);
             }
         }
         if ($user) {
             if (isset($location)) {
                 if ($user->homeLocationId == 0) {
                     $user->homeLocationId = $location->locationId;
                     if ($location->nearbyLocation1 > 0) {
                         $user->myLocation1Id = $location->nearbyLocation1;
                     } else {
                         $user->myLocation1Id = $location->locationId;
                     }
                     if ($location->nearbyLocation2 > 0) {
                         $user->myLocation2Id = $location->nearbyLocation2;
                     } else {
                         $user->myLocation2Id = $location->locationId;
                     }
                     if ($user instanceof User) {
                         //Update the database
                         $user->update();
                         //Update the serialized instance stored in the session
                         $_SESSION['userinfo'] = serialize($user);
                     }
                 } else {
                     if ($location->locationId != $user->homeLocationId) {
                         $user->homeLocationId = $location->locationId;
                         //Update the database
                         $user->update();
                         //Update the serialized instance stored in the session
                         $_SESSION['userinfo'] = serialize($user);
                     }
                 }
             }
         }
         //see if expiration date is close
         if (trim($patronDump['EXP_DATE']) != '-  -') {
             list($monthExp, $dayExp, $yearExp) = explode("-", $patronDump['EXP_DATE']);
             $timeExpire = strtotime($monthExp . "/" . $dayExp . "/" . $yearExp);
             $timeNow = time();
             $timeToExpire = $timeExpire - $timeNow;
             $expired = 0;
             if ($timeToExpire <= 30 * 24 * 60 * 60) {
                 if ($timeToExpire <= 0) {
                     $expired = 1;
                 }
                 $expireClose = 1;
             } else {
                 $expireClose = 0;
             }
         } else {
             $expired = 0;
             $expireClose = 0;
         }
         $finesVal = floatval(preg_replace('/[^\\d.]/', '', $patronDump['MONEY_OWED']));
         $numHoldsAvailable = 0;
         $numHoldsRequested = 0;
         $availableStatusRegex = isset($configArray['Catalog']['patronApiAvailableHoldsRegex']) ? $configArray['Catalog']['patronApiAvailableHoldsRegex'] : "/ST=(105|98),/";
         if (isset($patronDump) && isset($patronDump['HOLD']) && count($patronDump['HOLD']) > 0) {
             foreach ($patronDump['HOLD'] as $hold) {
                 if (preg_match("{$availableStatusRegex}", $hold)) {
                     $numHoldsAvailable++;
                 } else {
                     $numHoldsRequested++;
                 }
             }
         }
     }
     $nameParts = explode(', ', $fullName);
     $lastName = $nameParts[0];
     $secondName = isset($nameParts[1]) ? $nameParts[1] : '';
     if (strpos($secondName, ' ')) {
         $nameParts2 = explode(' ', $secondName);
         $firstName = $nameParts2[0];
     } else {
         $firstName = $secondName;
     }
     if ($user) {
         //Get display name for preferred location 1
         $myLocation1 = new Location();
         $myLocation1->whereAdd("locationId = '{$user->myLocation1Id}'");
         $myLocation1->find(1);
         //Get display name for preferred location 1
         $myLocation2 = new Location();
         $myLocation2->whereAdd("locationId = '{$user->myLocation2Id}'");
         $myLocation2->find(1);
     }
     $noticeLabels = array('-' => '', 'a' => 'Mail', 'p' => 'Telephone', 'z' => 'E-mail');
     $profile = array('lastname' => $lastName, 'firstname' => $firstName, 'fullname' => $fullName, 'address1' => $Address1, 'address2' => $City . ', ' . $State, 'city' => $City, 'state' => $State, 'zip' => $Zip, 'email' => $user && $user->email ? $user->email : (isset($patronDump) && isset($patronDump['EMAIL_ADDR']) ? $patronDump['EMAIL_ADDR'] : ''), 'overdriveEmail' => $user ? $user->overdriveEmail : (isset($patronDump) && isset($patronDump['EMAIL_ADDR']) ? $patronDump['EMAIL_ADDR'] : ''), 'promptForOverdriveEmail' => $user ? $user->promptForOverdriveEmail : 1, 'phone' => isset($patronDump) && isset($patronDump['TELEPHONE']) ? $patronDump['TELEPHONE'] : (isset($patronDump['HOME_PHONE']) ? $patronDump['HOME_PHONE'] : ''), 'workPhone' => isset($patronDump) && isset($patronDump['G/WK_PHONE']) ? $patronDump['G/WK_PHONE'] : '', 'mobileNumber' => isset($patronDump) && isset($patronDump['MOBILE_NO']) ? $patronDump['MOBILE_NO'] : '', 'fines' => isset($patronDump) ? $patronDump['MONEY_OWED'] : '0', 'finesval' => $finesVal, 'expires' => isset($patronDump) ? $patronDump['EXP_DATE'] : '', 'expireclose' => $expireClose, 'expired' => $expired, 'homeLocationCode' => isset($homeBranchCode) ? trim($homeBranchCode) : '', 'homeLocationId' => isset($location) ? $location->locationId : 0, 'homeLocation' => isset($location) ? $location->displayName : '', 'myLocation1Id' => $user ? $user->myLocation1Id : -1, 'myLocation1' => isset($myLocation1) ? $myLocation1->displayName : '', 'myLocation2Id' => $user ? $user->myLocation2Id : -1, 'myLocation2' => isset($myLocation2) ? $myLocation2->displayName : '', 'numCheckedOut' => isset($patronDump) ? $patronDump['CUR_CHKOUT'] : '?', 'numHolds' => isset($patronDump) ? isset($patronDump['HOLD']) ? count($patronDump['HOLD']) : 0 : '?', 'numHoldsAvailable' => $numHoldsAvailable, 'numHoldsRequested' => $numHoldsRequested, 'bypassAutoLogout' => $user ? $user->bypassAutoLogout : 0, 'ptype' => $user && $user->patronType ? $user->patronType : (isset($patronDump) ? $patronDump['P_TYPE'] : 0), 'notices' => isset($patronDump) ? $patronDump['NOTICE_PREF'] : '-', 'web_note' => isset($patronDump) ? isset($patronDump['WEB_NOTE']) ? $patronDump['WEB_NOTE'] : '' : '');
     if (array_key_exists($profile['notices'], $noticeLabels)) {
         $profile['noticePreferenceLabel'] = $noticeLabels[$profile['notices']];
     } else {
         $profile['noticePreferenceLabel'] = 'Unknown';
     }
     //Get eContent info as well
     require_once ROOT_DIR . '/Drivers/EContentDriver.php';
     $eContentDriver = new EContentDriver();
     $eContentAccountSummary = $eContentDriver->getAccountSummary();
     $profile = array_merge($profile, $eContentAccountSummary);
     require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
     $overDriveDriver = OverDriveDriverFactory::getDriver();
     if ($overDriveDriver->isUserValidForOverDrive($user)) {
         $overDriveSummary = $overDriveDriver->getOverDriveSummary($user);
         $profile['numOverDriveCheckedOut'] = $overDriveSummary['numCheckedOut'];
         $profile['numOverDriveHoldsAvailable'] = $overDriveSummary['numAvailableHolds'];
         $profile['numOverDriveHoldsRequested'] = $overDriveSummary['numUnavailableHolds'];
         $profile['canUseOverDrive'] = true;
     } else {
         $profile['numOverDriveCheckedOut'] = 0;
         $profile['numOverDriveHoldsAvailable'] = 0;
         $profile['numOverDriveHoldsRequested'] = 0;
         $profile['canUseOverDrive'] = false;
     }
     $profile['numCheckedOutTotal'] = $profile['numCheckedOut'] + $profile['numOverDriveCheckedOut'] + $eContentAccountSummary['numEContentCheckedOut'];
     $profile['numHoldsAvailableTotal'] = $profile['numHoldsAvailable'] + $profile['numOverDriveHoldsAvailable'] + $eContentAccountSummary['numEContentAvailableHolds'];
     $profile['numHoldsRequestedTotal'] = $profile['numHoldsRequested'] + $profile['numOverDriveHoldsRequested'] + $eContentAccountSummary['numEContentUnavailableHolds'];
     $profile['numHoldsTotal'] = $profile['numHoldsAvailableTotal'] + $profile['numHoldsRequestedTotal'];
     //Get a count of the materials requests for the user
     if ($user) {
         $materialsRequest = new MaterialsRequest();
         $materialsRequest->createdBy = $user->id;
         $homeLibrary = Library::getPatronHomeLibrary();
         $statusQuery = new MaterialsRequestStatus();
         $statusQuery->isOpen = 1;
         $statusQuery->libraryId = $homeLibrary->libraryId;
         $materialsRequest->joinAdd($statusQuery);
         $materialsRequest->find();
         $profile['numMaterialsRequests'] = $materialsRequest->N;
     }
     $timer->logTime("Got Patron Profile");
     $memCache->set($memCacheProfileKey, $profile, 0, $configArray['Caching']['patron_profile']);
     return $profile;
 }
Exemplo n.º 27
0
 function update()
 {
     //Check to see if we are adding copies.
     //If so, we wil need to process the hold queue after
     //The tile is saved
     $currentValue = new EContentRecord();
     $currentValue->id = $this->id;
     $currentValue->find(true);
     //Don't update solr, rely on the nightly reindex
     $ret = parent::update();
     if ($ret) {
         $this->clearCachedCover();
         if ($currentValue->N == 1 && $currentValue->availableCopies != $this->availableCopies) {
             require_once ROOT_DIR . '/Drivers/EContentDriver.php';
             $eContentDriver = new EContentDriver();
             $eContentDriver->processHoldQueue($this->id);
         }
     }
     return $ret;
 }
Exemplo n.º 28
0
 /**
  * Get Item Statuses
  *
  * This is responsible for printing the holdings information for a
  * collection of records in JSON format.
  *
  * @return void
  * @access public
  * @author Chris Delis <*****@*****.**>
  * @author Tuan Nguyen <*****@*****.**>
  */
 public function getItemStatuses()
 {
     global $interface;
     global $configArray;
     $catalog = ConnectionManager::connectToCatalog();
     if (!$catalog || !$catalog->status) {
         $this->output(translate('An error has occurred'), JSON::STATUS_ERROR);
     }
     $printIds = array();
     $econtentIds = array();
     $allIds = array();
     foreach ($_GET['id'] as $id) {
         if (preg_match('/econtentRecord(\\d+)$/i', $id, $matches)) {
             $econtentIds[] = $matches[1];
         } else {
             $printIds[] = $id;
         }
     }
     $allIds = array_merge($printIds, $econtentIds);
     $results = array();
     if (count($printIds) > 0) {
         $results = $catalog->getStatuses($printIds);
         if (PEAR_Singleton::isError($results)) {
             $this->output($results->getMessage(), JSON::STATUS_ERROR);
         } else {
             if (!is_array($results)) {
                 // If getStatuses returned garbage, let's turn it into an empty array
                 // to avoid triggering a notice in the foreach loop below.
                 $results = array();
             }
         }
     }
     // In order to detect IDs missing from the status response, create an
     // array with a key for every requested ID.  We will clear keys as we
     // encounter IDs in the response -- anything left will be problems that
     // need special handling.
     $missingIds = array_flip($printIds);
     // Load messages for response:
     $messages = array('available' => $interface->fetch('AJAX/status-available.tpl'), 'unavailable' => $interface->fetch('AJAX/status-unavailable.tpl'));
     // Load callnumber and location settings:
     $callnumberSetting = isset($configArray['Item_Status']['multiple_call_nos']) ? $configArray['Item_Status']['multiple_call_nos'] : 'msg';
     $locationSetting = isset($configArray['Item_Status']['multiple_locations']) ? $configArray['Item_Status']['multiple_locations'] : 'msg';
     // Loop through all the status information that came back
     $statuses = array();
     foreach ($results as $record) {
         // Skip errors and empty records:
         if (!PEAR_Singleton::isError($record) && count($record)) {
             if ($locationSetting == "group") {
                 $current = $this->_getItemStatusGroup($record, $messages, $callnumberSetting);
             } else {
                 $current = $this->_getItemStatus($record, $messages, $locationSetting, $callnumberSetting);
             }
             $statuses[] = $current;
             // The current ID is not missing -- remove it from the missing list.
             unset($missingIds[$current['id']]);
         }
     }
     // If any IDs were missing, send back appropriate dummy data
     foreach ($missingIds as $missingId => $junk) {
         $statuses[] = array('id' => $missingId, 'availability' => 'false', 'availability_message' => $messages['unavailable'], 'location' => translate('Unknown'), 'locationList' => false, 'reserve' => 'false', 'reserve_message' => translate('Not On Reserve'), 'callnumber' => '');
     }
     if (count($econtentIds) > 0) {
         require_once ROOT_DIR . '/Drivers/EContentDriver.php';
         $econtentDriver = new EContentDriver();
         $econtentResults = $econtentDriver->getStatuses($econtentIds);
         foreach ($econtentResults as $result) {
             $available = $result['available'];
             $interface->assign('status', $result['status']);
             if ($available) {
                 $message = $interface->fetch('AJAX/status-available.tpl');
             } else {
                 $message = $interface->fetch('AJAX/status-unavailable.tpl');
             }
             $statuses[] = array('id' => $result['id'], 'shortId' => $result['id'], 'availability' => $available ? 'true' : 'false', 'availability_message' => $message, 'location' => translate('Unknown'), 'locationList' => false, 'reserve' => 'false', 'reserve_message' => translate('Not On Reserve'), 'callnumber' => '');
         }
     }
     // Done
     $this->output($statuses, JSON::STATUS_OK);
 }