public function launch()
 {
     global $interface;
     if (isset($_REQUEST['startDate'])) {
         $startDate = new DateTime($_REQUEST['startDate']);
     } else {
         $startDate = new DateTime();
         date_sub($startDate, new DateInterval('P1M'));
     }
     if (isset($_REQUEST['endDate'])) {
         $endDate = new DateTime($_REQUEST['endDate']);
     } else {
         $endDate = new DateTime();
     }
     $interface->assign('startDate', $startDate->getTimestamp());
     $interface->assign('endDate', $endDate->getTimestamp());
     $offlineHolds = array();
     $offlineHoldsObj = new OfflineHold();
     $offlineHoldsObj->whereAdd("timeEntered >= " . $startDate->getTimestamp() . " AND timeEntered <= " . $endDate->getTimestamp());
     $offlineHoldsObj->find();
     while ($offlineHoldsObj->fetch()) {
         $offlineHold = array();
         require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php';
         $recordDriver = new MarcRecord($offlineHoldsObj->bibId);
         if ($recordDriver->isValid()) {
             $offlineHold['title'] = $recordDriver->getTitle();
         }
         $offlineHold['patronBarcode'] = $offlineHoldsObj->patronBarcode;
         $offlineHold['bibId'] = $offlineHoldsObj->bibId;
         $offlineHold['timeEntered'] = $offlineHoldsObj->timeEntered;
         $offlineHold['status'] = $offlineHoldsObj->status;
         $offlineHold['notes'] = $offlineHoldsObj->notes;
         $offlineHolds[] = $offlineHold;
     }
     $interface->setPageTitle('Offline Holds Report');
     $interface->assign('sidebar', 'MyAccount/account-sidebar.tpl');
     $interface->assign('offlineHolds', $offlineHolds);
     $interface->setTemplate('offlineHoldsReport.tpl');
     $interface->display('layout.tpl');
 }
Esempio n. 2
0
 public function placeItemHold($recordId, $itemId, $patronId, $comment, $type)
 {
     global $configArray;
     global $user;
     $userId = $user->id;
     //Get the session token for the user
     if (isset(HorizonAPI::$sessionIdsForUsers[$userId])) {
         $sessionToken = HorizonAPI::$sessionIdsForUsers[$userId];
     } else {
         //Log the user in
         list($userValid, $sessionToken) = $this->loginViaWebService($user->cat_username, $user->cat_password);
         if (!$userValid) {
             return array('result' => false, 'message' => 'Sorry, it does not look like you are logged in currently.  Please login and try again');
         }
     }
     // Retrieve Full Marc Record
     require_once ROOT_DIR . '/RecordDrivers/Factory.php';
     $record = RecordDriverFactory::initRecordDriverById('ils:' . $recordId);
     if (!$record) {
         $title = null;
     } else {
         $title = $record->getTitle();
     }
     if ($configArray['Catalog']['offline']) {
         global $user;
         require_once ROOT_DIR . '/sys/OfflineHold.php';
         $offlineHold = new OfflineHold();
         $offlineHold->bibId = $recordId;
         $offlineHold->patronBarcode = $patronId;
         $offlineHold->patronId = $user->id;
         $offlineHold->timeEntered = time();
         $offlineHold->status = 'Not Processed';
         if ($offlineHold->insert()) {
             return array('title' => $title, 'bib' => $recordId, 'result' => true, 'message' => 'The circulation system is currently offline.  This hold will be entered for you automatically when the circulation system is online.');
         } else {
             return array('title' => $title, 'bib' => $recordId, 'result' => false, 'message' => 'The circulation system is currently offline and we could not place this hold.  Please try again later.');
         }
     } else {
         if ($type == 'cancel' || $type == 'recall' || $type == 'update') {
             $result = $this->updateHold($recordId, $patronId, $type, $title);
             $result['title'] = $title;
             $result['bid'] = $recordId;
             return $result;
         } else {
             if (isset($_REQUEST['campus'])) {
                 $campus = trim($_REQUEST['campus']);
             } else {
                 global $user;
                 $campus = $user->homeLocationId;
             }
             //create the hold using the web service
             $createHoldUrl = $configArray['Catalog']['webServiceUrl'] . '/standard/createMyHold?clientID=' . $configArray['Catalog']['clientId'] . '&sessionToken=' . $sessionToken . '&pickupLocation=' . $campus . '&titleKey=' . $recordId;
             if ($itemId) {
                 $createHoldUrl .= '&itemKey=' . $itemId;
             }
             $createHoldResponse = $this->getWebServiceResponse($createHoldUrl);
             $hold_result = array();
             if ($createHoldResponse == true) {
                 $hold_result['result'] = true;
                 $hold_result['message'] = 'Your hold was placed successfully.';
             } else {
                 $hold_result['result'] = false;
                 $hold_result['message'] = 'Your hold could not be placed. ';
                 if (isset($createHoldResponse->message)) {
                     $hold_result['message'] .= (string) $createHoldResponse->message;
                 } else {
                     if (isset($createHoldResponse->string)) {
                         $hold_result['message'] .= (string) $createHoldResponse->string;
                     }
                 }
             }
             $hold_result['title'] = $title;
             $hold_result['bid'] = $recordId;
             global $analytics;
             if ($analytics) {
                 if ($hold_result['result'] == true) {
                     $analytics->addEvent('ILS Integration', 'Successful Hold', $title);
                 } else {
                     $analytics->addEvent('ILS Integration', 'Failed Hold', $hold_result['message'] . ' - ' . $title);
                 }
             }
             //Clear the patron profile
             $this->clearPatronProfile();
             return $hold_result;
         }
     }
 }
Esempio n. 3
0
 /**
  * Place Item Hold
  *
  * This is responsible for both placing item level holds.
  *
  * @param   string  $recordId   The id of the bib record
  * @param   string  $itemId     The id of the item to hold
  * @param   string  $patronId   The id of the patron
  * @param   string  $comment    Any comment regarding the hold or recall
  * @param   string  $type       Whether to place a hold or recall
  * @param   string  $type       The date when the hold should be cancelled if any
  * @return  mixed               True if successful, false if unsuccessful
  *                              If an error occurs, return a PEAR_Error
  * @access  public
  */
 public function placeItemHold($recordId, $itemId, $patronId, $comment, $type)
 {
     global $configArray;
     $bib1 = $recordId;
     if (substr($bib1, 0, 1) != '.') {
         $bib1 = '.' . $bib1;
     }
     $bib = substr(str_replace('.b', 'b', $bib1), 0, -1);
     if (strlen($bib) == 0) {
         return array('result' => false, 'message' => 'A valid record id was not provided. Please try again.');
     }
     //Get the title of the book.
     $class = $configArray['Index']['engine'];
     $url = $configArray['Index']['url'];
     $this->driver->db = new $class($url);
     // Retrieve Full Marc Record
     require_once ROOT_DIR . '/RecordDrivers/Factory.php';
     $record = RecordDriverFactory::initRecordDriverById('ils:' . $bib1);
     if (!$record) {
         $title = null;
     } else {
         $title = $record->getTitle();
     }
     if ($configArray['Catalog']['offline']) {
         global $user;
         require_once ROOT_DIR . '/sys/OfflineHold.php';
         $offlineHold = new OfflineHold();
         $offlineHold->bibId = $bib1;
         $offlineHold->patronBarcode = $patronId;
         $offlineHold->patronId = $user->id;
         $offlineHold->timeEntered = time();
         $offlineHold->status = 'Not Processed';
         if ($offlineHold->insert()) {
             return array('title' => $title, 'bib' => $bib1, 'result' => true, 'message' => 'The circulation system is currently offline.  This hold will be entered for you automatically when the circulation system is online.');
         } else {
             return array('title' => $title, 'bib' => $bib1, 'result' => false, 'message' => 'The circulation system is currently offline and we could not place this hold.  Please try again later.');
         }
     } else {
         //Cancel a hold
         if ($type == 'cancel' || $type == 'recall' || $type == 'update') {
             $result = $this->updateHold($recordId, $patronId, $type, $title);
             $result['title'] = $title;
             $result['bid'] = $bib1;
             return $result;
         } else {
             if (isset($_REQUEST['canceldate']) && !is_null($_REQUEST['canceldate']) && $_REQUEST['canceldate'] != '') {
                 $date = $_REQUEST['canceldate'];
             } else {
                 //Default to a date 6 months (half a year) in the future.
                 $sixMonthsFromNow = time() + 182.5 * 24 * 60 * 60;
                 $date = date('m/d/Y', $sixMonthsFromNow);
             }
             if (isset($_REQUEST['campus'])) {
                 $campus = trim($_REQUEST['campus']);
             } else {
                 global $user;
                 $campus = $user->homeLocationId;
             }
             if (is_numeric($campus)) {
                 $location = new Location();
                 $location->locationId = $campus;
                 if ($location->find(true)) {
                     $campus = $location->code;
                 }
             }
             list($Month, $Day, $Year) = explode("/", $date);
             //------------BEGIN CURL-----------------------------------------------------------------
             $header = array();
             $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
             $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
             $header[] = "Cache-Control: max-age=0";
             $header[] = "Connection: keep-alive";
             $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
             $header[] = "Accept-Language: en-us,en;q=0.5";
             $cookie = tempnam("/tmp", "CURLCOOKIE");
             $curl_connection = curl_init();
             curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
             curl_setopt($curl_connection, CURLOPT_HTTPHEADER, $header);
             curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
             curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
             curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, true);
             curl_setopt($curl_connection, CURLOPT_UNRESTRICTED_AUTH, true);
             curl_setopt($curl_connection, CURLOPT_COOKIEJAR, $cookie);
             curl_setopt($curl_connection, CURLOPT_COOKIESESSION, true);
             curl_setopt($curl_connection, CURLOPT_FORBID_REUSE, false);
             curl_setopt($curl_connection, CURLOPT_HEADER, false);
             curl_setopt($curl_connection, CURLOPT_POST, true);
             $lt = null;
             if (isset($configArray['Catalog']['loginPriorToPlacingHolds']) && ($configArray['Catalog']['loginPriorToPlacingHolds'] = true)) {
                 //User must be logged in as a separate step to placing holds
                 $curl_url = $configArray['Catalog']['url'] . "/patroninfo";
                 $post_data = $this->driver->_getLoginFormValues();
                 $post_data['submit.x'] = "35";
                 $post_data['submit.y'] = "21";
                 $post_data['submit'] = "submit";
                 curl_setopt($curl_connection, CURLOPT_REFERER, $curl_url);
                 curl_setopt($curl_connection, CURLOPT_URL, $curl_url);
                 $post_items = array();
                 foreach ($post_data as $key => $value) {
                     $post_items[] = $key . '=' . $value;
                 }
                 $post_string = implode('&', $post_items);
                 curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
                 $loginResult = curl_exec($curl_connection);
                 $curlInfo = curl_getinfo($curl_connection);
                 //When a library uses Encore, the initial login does a redirect and requires additional parameters.
                 if (preg_match('/<input type="hidden" name="lt" value="(.*?)" \\/>/si', $loginResult, $loginMatches)) {
                     //Get the lt value
                     $lt = $loginMatches[1];
                     //Login again
                     $post_data['lt'] = $lt;
                     $post_data['_eventId'] = 'submit';
                     $post_items = array();
                     foreach ($post_data as $key => $value) {
                         $post_items[] = $key . '=' . $value;
                     }
                     $post_string = implode('&', $post_items);
                     curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
                     $loginResult = curl_exec($curl_connection);
                     $curlInfo = curl_getinfo($curl_connection);
                 }
                 $post_data = array();
             } else {
                 $post_data = $this->driver->_getLoginFormValues();
             }
             $scope = $this->driver->getLibraryScope();
             $curl_url = $configArray['Catalog']['url'] . "/search/.{$bib}/.{$bib}/1,1,1,B/request~{$bib}";
             //echo "$curl_url";
             curl_setopt($curl_connection, CURLOPT_URL, $curl_url);
             /** @var Library $librarySingleton */
             global $librarySingleton;
             $patronHomeBranch = $librarySingleton->getPatronHomeLibrary();
             if ($patronHomeBranch->defaultNotNeededAfterDays != -1) {
                 $post_data['needby_Month'] = $Month;
                 $post_data['needby_Day'] = $Day;
                 $post_data['needby_Year'] = $Year;
             }
             $post_data['submit.x'] = "35";
             $post_data['submit.y'] = "21";
             $post_data['submit'] = "submit";
             $post_data['locx00'] = str_pad($campus, 5 - strlen($campus), '+');
             if (!is_null($itemId) && $itemId != -1) {
                 $post_data['radio'] = $itemId;
             }
             $post_data['x'] = "48";
             $post_data['y'] = "15";
             if ($lt != null) {
                 $post_data['lt'] = $lt;
                 $post_data['_eventId'] = 'submit';
             }
             $post_items = array();
             foreach ($post_data as $key => $value) {
                 $post_items[] = $key . '=' . $value;
             }
             $post_string = implode('&', $post_items);
             curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
             $sResult = curl_exec($curl_connection);
             global $logger;
             $logger->log("Placing hold {$curl_url}?{$post_string}", PEAR_LOG_INFO);
             $sResult = preg_replace("/<!--([^(-->)]*)-->/", "", $sResult);
             curl_close($curl_connection);
             //Parse the response to get the status message
             $hold_result = $this->_getHoldResult($sResult);
             $hold_result['title'] = $title;
             $hold_result['bid'] = $bib1;
             global $analytics;
             if ($analytics) {
                 if ($hold_result['result'] == true) {
                     $analytics->addEvent('ILS Integration', 'Successful Hold', $title);
                 } else {
                     $analytics->addEvent('ILS Integration', 'Failed Hold', $hold_result['message'] . ' - ' . $title);
                 }
             }
             //Clear the patron profile
             $this->driver->clearPatronProfile();
             return $hold_result;
         }
     }
 }
Esempio n. 4
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');
 }