function launch()
 {
     global $configArray;
     global $interface;
     global $user;
     global $timer;
     require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
     $overDriveDriver = OverDriveDriverFactory::getDriver();
     $overDriveCheckedOutItems = $overDriveDriver->getOverDriveCheckedOutItems($user);
     //Load the full record for each item in the wishlist
     foreach ($overDriveCheckedOutItems['items'] as $key => $item) {
         if ($item['recordId'] != -1) {
             $econtentRecord = new EContentRecord();
             $econtentRecord->id = $item['recordId'];
             $econtentRecord->find(true);
             $item['record'] = clone $econtentRecord;
         } else {
             $item['record'] = null;
         }
         $overDriveCheckedOutItems['items'][$key] = $item;
     }
     $interface->assign('overDriveCheckedOutItems', $overDriveCheckedOutItems['items']);
     $interface->assign('ButtonBack', true);
     $interface->assign('ButtonHome', true);
     $interface->assign('MobileTitle', 'OverDrive Checked Out Items');
     $interface->assign('showNotInterested', false);
     global $configArray;
     if (!isset($configArray['OverDrive']['interfaceVersion']) || $configArray['OverDrive']['interfaceVersion'] == 1) {
         $interface->setTemplate('overDriveCheckedOut.tpl');
     } else {
         $interface->setTemplate('overDriveCheckedOut2.tpl');
     }
     $interface->setPageTitle('OverDrive Checked Out Items');
     $interface->display('layout.tpl');
 }
예제 #2
0
 function launch()
 {
     global $configArray;
     global $interface;
     global $user;
     global $timer;
     require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
     $overDriveDriver = OverDriveDriverFactory::getDriver();
     $overDriveWishList = $overDriveDriver->getOverDriveWishList($user);
     //Load the full record for each item in the wishlist
     foreach ($overDriveWishList['items'] as $key => $item) {
         if ($item['recordId'] != -1) {
             $econtentRecord = new EContentRecord();
             $econtentRecord->id = $item['recordId'];
             $econtentRecord->find(true);
             $item['record'] = clone $econtentRecord;
         } else {
             $item['record'] = null;
         }
         $item['numRows'] = count($item['formats']) + 1;
         $overDriveWishList['items'][$key] = $item;
     }
     $interface->assign('overDriveWishList', $overDriveWishList['items']);
     if (isset($overDriveWishList['error'])) {
         $interface->assign('error', $overDriveWishList['error']);
     }
     $interface->setTemplate('overDriveWishList.tpl');
     $interface->setPageTitle('OverDrive Wish List');
     $interface->display('layout.tpl');
 }
예제 #3
0
 function launch()
 {
     global $interface;
     global $configArray;
     if (isset($_REQUEST['searchId'])) {
         $_SESSION['searchId'] = $_REQUEST['searchId'];
         $interface->assign('searchId', $_SESSION['searchId']);
     } else {
         if (isset($_SESSION['searchId'])) {
             $interface->assign('searchId', $_SESSION['searchId']);
         }
     }
     $interface->assign('overDriveVersion', isset($configArray['OverDrive']['interfaceVersion']) ? $configArray['OverDrive']['interfaceVersion'] : 1);
     $this->id = strip_tags($_REQUEST['id']);
     $interface->assign('id', $this->id);
     $recordDriver = new OverDriveRecordDriver($this->id);
     if (!$recordDriver->isValid()) {
         $interface->setTemplate('../Record/invalidRecord.tpl');
         $interface->display('layout.tpl');
         die;
     } else {
         $interface->assign('recordDriver', $recordDriver);
         //Load status summary
         require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
         $driver = OverDriveDriverFactory::getDriver();
         $holdings = $driver->getHoldings($recordDriver);
         $scopedAvailability = $driver->getScopedAvailability($recordDriver);
         $holdingsSummary = $driver->getStatusSummary($this->id, $scopedAvailability, $holdings);
         if (PEAR_Singleton::isError($holdingsSummary)) {
             PEAR_Singleton::raiseError($holdingsSummary);
         }
         $interface->assign('holdingsSummary', $holdingsSummary);
         //Load the citations
         $this->loadCitations($recordDriver);
         // Retrieve User Search History
         $interface->assign('lastsearch', isset($_SESSION['lastSearchURL']) ? $_SESSION['lastSearchURL'] : false);
         //Get Next/Previous Links
         $searchSource = isset($_REQUEST['searchSource']) ? $_REQUEST['searchSource'] : 'local';
         $searchObject = SearchObjectFactory::initSearchObject();
         $searchObject->init($searchSource);
         $searchObject->getNextPrevLinks();
         // Set Show in Main Details Section options for templates
         // (needs to be set before moreDetailsOptions)
         global $library;
         foreach ($library->showInMainDetails as $detailoption) {
             $interface->assign($detailoption, true);
         }
         $interface->setPageTitle($recordDriver->getTitle());
         $interface->assign('moreDetailsOptions', $recordDriver->getMoreDetailsOptions());
         // Display Page
         $interface->assign('sidebar', 'OverDrive/full-record-sidebar.tpl');
         $interface->assign('moreDetailsTemplate', 'GroupedWork/moredetails-accordion.tpl');
         $interface->setTemplate('view.tpl');
         $interface->display('layout.tpl');
     }
 }
예제 #4
0
 function launch()
 {
     global $configArray;
     global $interface;
     global $user;
     global $timer;
     require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
     $overDriveDriver = OverDriveDriverFactory::getDriver();
     $overDriveHolds = $overDriveDriver->getOverDriveHolds($user);
     //Load the full record for each item in the wishlist
     foreach ($overDriveHolds['holds'] as $sectionKey => $sectionData) {
         foreach ($sectionData as $key => $item) {
             if ($item['recordId'] != -1) {
                 $econtentRecord = new EContentRecord();
                 $econtentRecord->id = $item['recordId'];
                 $econtentRecord->find(true);
                 $item['record'] = clone $econtentRecord;
             } else {
                 $item['record'] = null;
             }
             if ($sectionKey == 'available') {
                 if (isset($item['formats'])) {
                     $item['numRows'] = count($item['formats']) + 1;
                 }
             }
             $overDriveHolds['holds'][$sectionKey][$key] = $item;
         }
     }
     $interface->assign('overDriveHolds', $overDriveHolds['holds']);
     $interface->assign('ButtonBack', true);
     $interface->assign('ButtonHome', true);
     $interface->assign('MobileTitle', 'OverDrive Holds');
     $hasSeparateTemplates = $interface->template_exists('MyResearch/overDriveAvailableHolds.tpl');
     if ($hasSeparateTemplates) {
         $section = isset($_REQUEST['section']) ? $_REQUEST['section'] : 'available';
         if ($section == 'available') {
             $interface->setPageTitle('Available Holds from OverDrive');
             if (!isset($configArray['OverDrive']['interfaceVersion']) || $configArray['OverDrive']['interfaceVersion'] == 1) {
                 $interface->setTemplate('overDriveAvailableHolds.tpl');
             } else {
                 $interface->setTemplate('overDriveAvailableHolds2.tpl');
             }
         } else {
             $interface->setPageTitle('On Hold in OverDrive');
             $interface->setTemplate('overDriveUnavailableHolds.tpl');
         }
     } else {
         $interface->setTemplate('overDriveHolds.tpl');
         $interface->setPageTitle('OverDrive Holds');
     }
     $interface->display('layout.tpl');
 }
예제 #5
0
 function launch()
 {
     global $interface;
     global $configArray;
     global $library;
     global $locationSingleton;
     global $timer;
     global $user;
     if ($user) {
         if (isset($_GET['overDriveId']) && isset($_GET['formatId']) || isset($_POST['overDriveId']) && isset($_POST['formatId'])) {
             $catalog = new CatalogConnection($configArray['Catalog']['driver']);
             $patron = $catalog->patronLogin($user->cat_username, $user->cat_password);
             $profile = $catalog->getMyProfile($patron);
             if (!PEAR_Singleton::isError($profile)) {
                 $interface->assign('profile', $profile);
             }
             $overDriveId = isset($_GET['overDriveId']) ? $_GET['overDriveId'] : $_POST['overDriveId'];
             $formatId = isset($_GET['formatId']) ? $_GET['formatId'] : $_POST['formatId'];
             require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
             $driver = OverDriveDriverFactory::getDriver();
             $holdMessage = $driver->placeOverDriveHold($overDriveId, $formatId, $user);
             $interface->assign('message', $holdMessage['message']);
             $interface->assign('MobileTitle', 'OverDrive Place Hold');
             $interface->assign('ButtonBack', false);
             $interface->assign('ButtonHome', true);
             $interface->setTemplate('od-placeHold.tpl');
         }
     } else {
         if (isset($_GET['overDriveId']) && isset($_GET['formatId'])) {
             $interface->assign('overDriveId', $_GET['overDriveId']);
             $interface->assign('formatId', $_GET['formatId']);
             $interface->setTemplate('login.tpl');
         } else {
             header('Location: /');
         }
     }
     $interface->display('layout.tpl', $cacheId);
 }
예제 #6
0
 public function placeHold($id, $user)
 {
     $id = str_ireplace("econtentrecord", "", $id);
     $return = array();
     $eContentRecord = new EContentRecord();
     $eContentRecord->id = $id;
     if (!$eContentRecord->find(true)) {
         $return['result'] = false;
         $return['message'] = "Could not find a record with an id of {$id}";
     } else {
         $return['title'] = $eContentRecord->title;
         //If the source is overdrive, process it as an overdrive title
         if (strcasecmp($eContentRecord->source, 'OverDrive') == 0) {
             require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
             $overDriveDriver = OverDriveDriverFactory::getDriver();
             $overDriveResult = $overDriveDriver->placeOverDriveHold($eContentRecord->externalId, '', $user);
             $return['result'] = $overDriveResult['result'];
             $return['message'] = $overDriveResult['message'];
         } else {
             //Check to see if the user already has a hold placed
             $holds = new EContentHold();
             $holds->userId = $user->id;
             $holds->recordId = $id;
             $holds->whereAdd("(status = 'active' or status = 'suspended' or status ='available')");
             $holds->find();
             if ($holds->N > 0) {
                 $return['result'] = false;
                 $return['message'] = "That record is already on hold for you, unable to place a second hold.";
             } else {
                 //Check to see if the user already has the record checked out
                 $checkouts = new EContentCheckout();
                 $checkouts->userId = $user->id;
                 $checkouts->status = 'out';
                 $checkouts->recordId = $id;
                 $checkouts->find();
                 if ($checkouts->N > 0) {
                     $return['result'] = false;
                     $return['message'] = "That record is already checked out to you, unable to place a hold.";
                 } else {
                     //Check to see if there are any available copies and then checkout the record rather than placing a hold
                     $holdings = $this->getHolding($id);
                     $holdingsSummary = $this->getStatusSummary($id, $holdings);
                     if ($holdingsSummary['availableCopies'] > 0 || $eContentRecord->accessType == 'free') {
                         //The record can be checked out directly
                         $ret = $this->checkoutRecord($id, $user);
                         return $ret;
                     } else {
                         //Place the hold for the user
                         $hold = new EContentHold();
                         $hold->userId = $user->id;
                         $hold->recordId = $id;
                         $hold->status = 'active';
                         $hold->datePlaced = time();
                         $hold->dateUpdated = time();
                         if ($hold->insert()) {
                             $return['result'] = true;
                             $holdPosition = $this->_getHoldPosition($hold);
                             $return['message'] = "Your hold was successfully placed, you are number {$holdPosition} in the queue.";
                             //Record that the record had a hold placed on it
                             $this->recordEContentAction($id, "Place Hold", $eContentRecord->accessType);
                         }
                     }
                 }
             }
         }
     }
     if ($return['result'] == true) {
         //Make a call to strands to update that the item was placed on hold
         global $configArray;
         global $user;
         if (isset($configArray['Strands']['APID']) && $user->disableRecommendations == 0) {
             $strandsUrl = "http://bizsolutions.strands.com/api2/event/addshoppingcart.sbs?needresult=true&apid={$configArray['Strands']['APID']}&item=econtentRecord{$id}&user={$user->id}";
             $ret = file_get_contents($strandsUrl);
         }
     }
     return $return;
 }
예제 #7
0
 private function getCoverFromEContent()
 {
     if ($this->configArray['EContent']['library'] && isset($this->id) && is_numeric($this->id)) {
         $this->log("Looking for eContent Cover", PEAR_LOG_INFO);
         $this->initMemcache();
         $this->log("Checking eContent database to see if there is a record for {$this->id}", PEAR_LOG_INFO);
         //Check the database to see if there is an existing title
         require_once ROOT_DIR . '/sys/eContent/EContentRecord.php';
         $epubFile = new EContentRecord();
         $epubFile->id = $this->id;
         if ($epubFile->find(true)) {
             $this->log("Found an eContent record for {$this->id}, source is {$epubFile->source}", PEAR_LOG_INFO);
             //Get the cover for the epub if one exists.
             if (strcasecmp($epubFile->source, 'OverDrive') == 0 && ($epubFile->cover == null || strlen($epubFile->cover) == 0)) {
                 $this->log("Record is an OverDrive record that needs cover information fetched.", PEAR_LOG_INFO);
                 //Get the image from OverDrive
                 require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
                 $overDriveDriver = OverDriveDriverFactory::getDriver();
                 $filename = $overDriveDriver->getCoverUrl($epubFile);
                 $this->log("Got OverDrive cover information for {$epubFile->id} {$epubFile->sourceUrl}", PEAR_LOG_INFO);
                 $this->log("Received filename {$filename}", PEAR_LOG_INFO);
                 if ($filename != null) {
                     $epubFile->cover = $filename;
                     $ret = $epubFile->update();
                     //Don't update solr for performance reasons
                     $this->log("Result of saving cover url is {$ret}", PEAR_LOG_INFO);
                 }
             } elseif (preg_match('/Colorado State Gov\\. Docs/si', $epubFile->source) == 1 || $epubFile->source == 'CO State Gov Docs') {
                 //Cover is colorado state flag
                 $this->log("Record is a gov docs file.", PEAR_LOG_INFO);
                 $themeName = $this->configArray['Site']['theme'];
                 $filename = "interface/themes/{$themeName}/images/state_flag_of_colorado.png";
                 if ($this->processImageURL($filename, true)) {
                     return;
                 }
             }
             if ($epubFile->cover && strlen($epubFile->cover) > 0) {
                 $this->log("Cover for the file is specified as {$epubFile->cover}.", PEAR_LOG_INFO);
                 if (strpos($epubFile->cover, 'http://') === 0) {
                     $filename = $epubFile->cover;
                     if ($this->processImageURL($filename, true)) {
                         $this->timer->writeTimings();
                         exit;
                     }
                 } else {
                     $filename = $this->bookCoverPath . '/original/' . $epubFile->cover;
                     $this->localFile = $this->bookCoverPath . '/' . $this->size . '/' . $this->cacheName . '.png';
                     if (file_exists($filename)) {
                         if ($this->processImageURL($filename, true)) {
                             $this->timer->writeTimings();
                             exit;
                         }
                     } else {
                         $this->log("Did not find econtent cover file {$filename}", PEAR_LOG_ERR);
                     }
                 }
             }
         }
     }
     $this->log("Did not find a cover based on eContent information.", PEAR_LOG_INFO);
 }
예제 #8
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');
 }
 public function getMoreDetailsOptions()
 {
     global $interface;
     $isbn = $this->getCleanISBN();
     //Load holdings information from the driver
     require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
     $driver = OverDriveDriverFactory::getDriver();
     /** @var OverDriveAPIProductFormats[] $holdings */
     $holdings = $driver->getHoldings($this);
     $scopedAvailability = $driver->getScopedAvailability($this);
     $interface->assign('availability', $scopedAvailability['mine']);
     $interface->assign('availabilityOther', $scopedAvailability['other']);
     $showAvailability = true;
     $showAvailabilityOther = true;
     $interface->assign('showAvailability', $showAvailability);
     $interface->assign('showAvailabilityOther', $showAvailabilityOther);
     $showOverDriveConsole = false;
     $showAdobeDigitalEditions = false;
     foreach ($holdings as $item) {
         if (in_array($item->textId, array('ebook-epub-adobe', 'ebook-pdf-adobe'))) {
             $showAdobeDigitalEditions = true;
         } else {
             if (in_array($item->textId, array('video-wmv', 'music-wma', 'music-wma', 'audiobook-wma', 'audiobook-mp3'))) {
                 $showOverDriveConsole = true;
             }
         }
     }
     $interface->assign('showOverDriveConsole', $showOverDriveConsole);
     $interface->assign('showAdobeDigitalEditions', $showAdobeDigitalEditions);
     $interface->assign('holdings', $holdings);
     //Load more details options
     $moreDetailsOptions = $this->getBaseMoreDetailsOptions($isbn);
     $moreDetailsOptions['formats'] = array('label' => 'Formats', 'body' => $interface->fetch('OverDrive/view-formats.tpl'), 'openByDefault' => true);
     //Other editions if applicable (only if we aren't the only record!)
     $relatedRecords = $this->getGroupedWorkDriver()->getRelatedRecords();
     if (count($relatedRecords) > 1) {
         $interface->assign('relatedManifestations', $this->getGroupedWorkDriver()->getRelatedManifestations());
         $moreDetailsOptions['otherEditions'] = array('label' => 'Other Editions', 'body' => $interface->fetch('GroupedWork/relatedManifestations.tpl'), 'hideByDefault' => false);
     }
     $moreDetailsOptions['moreDetails'] = array('label' => 'More Details', 'body' => $interface->fetch('OverDrive/view-more-details.tpl'));
     $moreDetailsOptions['citations'] = array('label' => 'Citations', 'body' => $interface->fetch('Record/cite.tpl'));
     $moreDetailsOptions['copyDetails'] = array('label' => 'Copy Details', 'body' => $interface->fetch('OverDrive/view-copies.tpl'));
     if ($interface->getVariable('showStaffView')) {
         $moreDetailsOptions['staff'] = array('label' => 'Staff View', 'body' => $interface->fetch($this->getStaffView()));
     }
     return $this->filterAndSortMoreDetailsOptions($moreDetailsOptions);
 }
예제 #10
0
 function launch()
 {
     global $configArray;
     global $interface;
     global $user;
     global $librarySingleton;
     $activeLibrary = $librarySingleton->getActiveLibrary();
     if ($activeLibrary == null || $activeLibrary->allowProfileUpdates) {
         $canUpdateContactInfo = true;
     } else {
         $canUpdateContactInfo = false;
     }
     $interface->assign('canUpdateContactInfo', $canUpdateContactInfo);
     if (isset($_POST['update'])) {
         $result = $this->catalog->updatePatronInfo($canUpdateContactInfo);
         $_SESSION['profileUpdateErrors'] = $result;
         require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
         $overDriveDriver = OverDriveDriverFactory::getDriver();
         $result = $overDriveDriver->updateLendingOptions();
         header("Location: " . $configArray['Site']['path'] . '/MyResearch/Profile');
         exit;
     } elseif (isset($_POST['updatePin'])) {
         $result = $this->catalog->updatePin();
         $_SESSION['profileUpdateErrors'] = $result;
         header("Location: " . $configArray['Site']['path'] . '/MyResearch/Profile');
         exit;
     } else {
         if (isset($_POST['edit'])) {
             $interface->assign('edit', true);
         } else {
             $interface->assign('edit', false);
         }
     }
     require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
     $overDriveDriver = OverDriveDriverFactory::getDriver();
     if ($overDriveDriver->version >= 2) {
         $overDriveSummary = $overDriveDriver->getAccountDetails($user);
         $interface->assign('overDriveLendingOptions', $overDriveSummary['lendingOptions']);
     }
     if (isset($_SESSION['profileUpdateErrors'])) {
         $interface->assign('profileUpdateErrors', $_SESSION['profileUpdateErrors']);
         unset($_SESSION['profileUpdateErrors']);
     }
     //Get the list of locations for display in the user interface.
     global $locationSingleton;
     $locationSingleton->whereAdd("validHoldPickupBranch = 1");
     $locationSingleton->find();
     $locationList = array();
     while ($locationSingleton->fetch()) {
         $locationList[$locationSingleton->locationId] = $locationSingleton->displayName;
     }
     $interface->assign('locationList', $locationList);
     if ($this->catalog->checkFunction('isUserStaff')) {
         $userIsStaff = $this->catalog->isUserStaff();
         $interface->assign('userIsStaff', $userIsStaff);
     } else {
         $interface->assign('userIsStaff', false);
     }
     $interface->setTemplate('profile.tpl');
     $interface->setPageTitle(translate('My Profile'));
     $interface->display('layout.tpl');
 }
예제 #11
0
 function getOverDriveSummary()
 {
     global $user;
     if ($user) {
         require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
         $overDriveDriver = OverDriveDriverFactory::getDriver();
         $summary = $overDriveDriver->getOverDriveSummary($user);
         return json_encode($summary);
     } else {
         return array('error' => 'There is no user currently logged in.');
     }
 }
예제 #12
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');
 }
예제 #13
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;
 }
예제 #14
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;
 }
예제 #15
0
<?php

ini_set('display_errors', true);
error_reporting(E_ALL & ~E_DEPRECATED);
require_once 'bootstrap.php';
require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
$driver = OverDriveDriverFactory::getDriver();
$libraryInfo = $driver->getLibraryAccountInformation();
print_r($libraryInfo);
echo "<h1>{$libraryInfo->name}</h1>";
echo "<h2>Products</h2>";
echo "Products link {$libraryInfo->links->products->href}<br/>";
//showProductInfo($driver, $libraryInfo->links->products->href);
$productInfo = $driver->getProductsInAccount($libraryInfo->links->products->href);
echo "<h2>First Product Details</h2>";
$firstProduct = reset($productInfo->products);
echo "{$firstProduct->title}: {$firstProduct->subtitle}<br/>";
echo "By {$firstProduct->primaryCreator->name}<br/>";
print_r($firstProduct);
//echo("<h2>Advantage Product Details</h2>");
//$productInfo = $driver->_callUrl("http://api.overdrive.com/v1/libraries/1201/advantageAccounts/50");
//print_r($productInfo);
//echo("<h2>Bud Unique Products</h2>");
//$productInfo = $driver->_callUrl("http://api.overdrive.com/v1/collections/L1BUwYAAA2r/products");
//print_r($productInfo);
echo "<h3>Metadata</h3>";
echo $firstProduct->links->metadata->href;
//$metadata = $driver->getProductMetadata($firstProduct->links->metadata->href);
$metadata = $driver->getProductMetadata("cda4632c-0593-46e7-94a4-1e4c4451da09", "L1BMAEAAA2k");
print_r($metadata);
/*echo("<h3>Availability - MDL</h3>");
예제 #16
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;
 }
예제 #17
0
 /**
  * Process the account to checkout any titles within the OverDrive cart
  *
  * 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>lendingPeriod - The number of days to checkout the title. (optional) </li>
  * </ul>
  *
  * Returns JSON encoded data as follows:
  * <ul>
  * <li>success � true if the cart was processed, false if the username or password were incorrect or the hold could not be removed from the wishlist.</li>
  * <li>message � information about the process for display to the user.</li>
  * </ul>
  *
  * Sample Call:
  * <code>
  * http://catalog.douglascountylibraries.org/API/UserAPI?method=processOverDriveCart&username=23025003575917&password=1234&lendingPeriod=14
  * </code>
  *
  * Sample Response:
  * <code>
  * {"result":{
  *   "success":true,
  *   "message":"Your titles were checked out successfully. You may now download the titles from your Account."
  * }}
  * </code>
  *
  * @author Mark Noble <*****@*****.**>
  *
  */
 function processOverDriveCart()
 {
     $username = $_REQUEST['username'];
     $password = $_REQUEST['password'];
     global $user;
     $user = UserAccount::validateAccount($username, $password);
     if ($user && !PEAR_Singleton::isError($user)) {
         require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
         $driver = OverDriveDriverFactory::getDriver();
         $lendingPeriod = isset($_REQUEST['lendingPeriod']) ? $_REQUEST['lendingPeriod'] : -1;
         $processCartResult = $driver->processOverDriveCart($user, $lendingPeriod);
         return array('success' => $processCartResult['result'], 'message' => $processCartResult['message']);
     } else {
         return array('success' => false, 'message' => 'Login unsuccessful');
     }
 }
예제 #18
0
 function getAvailability()
 {
     global $configArray;
     if ($this->availability == null) {
         $this->availability = array();
         require_once ROOT_DIR . '/sys/eContent/EContentAvailability.php';
         $eContentAvailability = new EContentAvailability();
         $eContentAvailability->recordId = $this->id;
         $eContentAvailability->find();
         while ($eContentAvailability->fetch()) {
             $this->availability[] = clone $eContentAvailability;
         }
         if (strcasecmp($this->source, "OverDrive") == 0) {
             require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
             $driver = OverDriveDriverFactory::getDriver();
             //echo("Loading availability from overdrive, part of " . count($this->availability) . " collections");
             foreach ($this->availability as $key => $tmpAvailability) {
                 //echo("\r\n{$tmpAvailability->libraryId}");
                 //Get updated availability for each library from overdrive
                 $productKey = $configArray['OverDrive']['productsKey'];
                 if ($tmpAvailability->libraryId != -1) {
                     $library = new Library();
                     $library->libraryId = $tmpAvailability->libraryId;
                     $library->find(true);
                     $productKey = $library->overdriveAdvantageProductsKey;
                 }
                 $realtimeAvailability = $driver->getProductAvailability($this->externalId, $productKey);
                 $tmpAvailability->copiesOwned = $realtimeAvailability->copiesOwned;
                 $tmpAvailability->availableCopies = $realtimeAvailability->copiesAvailable;
                 $tmpAvailability->numberOfHolds = $realtimeAvailability->numberOfHolds;
                 $this->availability[$key] = $tmpAvailability;
             }
         }
         if (count($this->availability) == 0) {
             //Did not get availability from the Availability table
             if ($this->itemLevelOwnership) {
                 //Ownership is determined at the item level based on library ids set for the item.  Assume unlimited availability
                 $items = $this->getItems();
                 foreach ($items as $item) {
                     $eContentAvailability = new EContentAvailability();
                     $eContentAvailability->recordId = $this->id;
                     $eContentAvailability->copiesOwned = 1;
                     $eContentAvailability->availableCopies = 1;
                     $eContentAvailability->numberOfHolds = 0;
                     $eContentAvailability->libraryId = $item->libraryId;
                     $this->availability[] = $eContentAvailability;
                 }
             } else {
                 //Ownership is shared, based on information at record level
                 $eContentAvailability = new EContentAvailability();
                 $eContentAvailability->recordId = $this->id;
                 $eContentAvailability->copiesOwned = $this->availableCopies;
                 $checkouts = new EContentCheckout();
                 $checkouts->status = 'out';
                 $checkouts->recordId = $this->id;
                 $checkouts->find();
                 $curCheckouts = $checkouts->N;
                 if ($this->accessType == 'free') {
                     $this->availableCopies = 999999;
                 }
                 $eContentAvailability->availableCopies = $this->availableCopies - $curCheckouts;
                 $eContentAvailability->copiesOwned = $this->availableCopies;
                 $holds = new EContentHold();
                 $holds->whereAdd("status in ('active', 'suspended', 'available')");
                 $holds->recordId = $this->id;
                 $holds->find();
                 $eContentAvailability->numberOfHolds = $holds->N;
                 $eContentAvailability->onOrderCopies = $this->onOrderCopies;
                 $eContentAvailability->libraryId = -1;
             }
         }
     }
     return $this->availability;
 }
예제 #19
0
 function CancelOverDriveHold()
 {
     global $user;
     $overDriveId = $_REQUEST['overDriveId'];
     $format = $_REQUEST['formatId'];
     if ($user && !PEAR_Singleton::isError($user)) {
         require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
         $driver = OverDriveDriverFactory::getDriver();
         $result = $driver->cancelOverDriveHold($overDriveId, $format, $user);
         return json_encode($result);
     } else {
         return json_encode(array('result' => false, 'message' => 'You must be logged in to cancel holds.'));
     }
 }