Ejemplo n.º 1
0
 public function getMyTransactions($page = 1, $recordsPerPage = -1, $sortOption = 'dueDate')
 {
     global $configArray;
     global $user;
     $userId = $user->id;
     $checkedOutTitles = array();
     //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) {
             echo "No session id found for user";
             return $checkedOutTitles;
         }
     }
     //Now that we have the session token, get checkouts information
     $lookupMyAccountInfoResponse = $this->getWebServiceResponse($configArray['Catalog']['webServiceUrl'] . '/standard/lookupMyAccountInfo?clientID=' . $configArray['Catalog']['clientId'] . '&sessionToken=' . $sessionToken . '&includeItemsOutInfo=true');
     if (isset($lookupMyAccountInfoResponse->ItemsOutInfo)) {
         $sCount = 0;
         foreach ($lookupMyAccountInfoResponse->ItemsOutInfo as $itemOut) {
             $sCount++;
             $bibId = (string) $itemOut->titleKey;
             $curTitle['checkoutSource'] = 'ILS';
             $curTitle['recordId'] = $bibId;
             $curTitle['shortId'] = $bibId;
             $curTitle['id'] = $bibId;
             $curTitle['title'] = (string) $itemOut->title;
             $curTitle['author'] = (string) $itemOut->author;
             $curTitle['duedate'] = (string) $itemOut->dueDate;
             $curTitle['checkoutdate'] = (string) $itemOut->ckoDate;
             $dueTime = strtotime($curTitle['duedate']);
             $daysUntilDue = ceil(($dueTime - time()) / (24 * 60 * 60));
             $overdue = $daysUntilDue < 0;
             $curTitle['overdue'] = $overdue;
             $curTitle['daysUntilDue'] = $daysUntilDue;
             $curTitle['renewCount'] = (string) $itemOut->renewals;
             $curTitle['canrenew'] = true;
             //TODO: Figure out if the user can renew the title or not
             $curTitle['renewIndicator'] = (string) $itemOut->itemBarcode;
             $curTitle['barcode'] = (string) $itemOut->itemBarcode;
             $curTitle['holdQueueLength'] = $this->getNumHolds($bibId);
             $curTitle['format'] = 'Unknown';
             if ($curTitle['id'] && strlen($curTitle['id']) > 0) {
                 require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php';
                 $recordDriver = new MarcRecord($curTitle['id']);
                 if ($recordDriver->isValid()) {
                     $curTitle['coverUrl'] = $recordDriver->getBookcoverUrl('medium');
                     $curTitle['groupedWorkId'] = $recordDriver->getGroupedWorkId();
                     $formats = $recordDriver->getFormats();
                     $curTitle['format'] = reset($formats);
                 } else {
                     $curTitle['coverUrl'] = "";
                 }
             }
             $sortTitle = isset($curTitle['title_sort']) ? $curTitle['title_sort'] : $curTitle['title'];
             $sortKey = $sortTitle;
             if ($sortOption == 'title') {
                 $sortKey = $sortTitle;
             } elseif ($sortOption == 'author') {
                 $sortKey = (isset($curTitle['author']) ? $curTitle['author'] : "Unknown") . '-' . $sortTitle;
             } elseif ($sortOption == '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 ($sortOption == 'format') {
                 $sortKey = (isset($curTitle['format']) ? $curTitle['format'] : "Unknown") . '-' . $sortTitle;
             } elseif ($sortOption == 'renewed') {
                 $sortKey = (isset($curTitle['renewCount']) ? $curTitle['renewCount'] : 0) . '-' . $sortTitle;
             } elseif ($sortOption == 'holdQueueLength') {
                 $sortKey = (isset($curTitle['holdQueueLength']) ? $curTitle['holdQueueLength'] : 0) . '-' . $sortTitle;
             }
             $sortKey .= "_{$sCount}";
             $checkedOutTitles[$sortKey] = $curTitle;
         }
     }
     return array('transactions' => $checkedOutTitles, 'numTransactions' => count($checkedOutTitles));
 }
Ejemplo n.º 2
0
 public function getMyTransactions($page = 1, $recordsPerPage = -1, $sortOption = 'dueDate')
 {
     global $timer;
     $patronDump = $this->driver->_getPatronDump($this->driver->_getBarcode());
     $timer->logTime("Ready to load checked out titles from Millennium");
     //Load the information from millennium using CURL
     $sResult = $this->driver->_fetchPatronInfoPage($patronDump, 'items');
     $timer->logTime("Loaded checked out titles from Millennium");
     $sResult = preg_replace("/<[^<]+?>\\W<[^<]+?>\\W\\d* ITEM.? CHECKED OUT<[^<]+?>\\W<[^<]+?>/i", "", $sResult);
     $s = substr($sResult, stripos($sResult, 'patFunc'));
     $s = substr($s, strpos($s, ">") + 1);
     $s = substr($s, 0, stripos($s, "</table"));
     $s = preg_replace("/<br \\/>/", "", $s);
     $sRows = preg_split("/<tr([^>]*)>/", $s);
     $sCount = 0;
     $sKeys = array_pad(array(), 10, "");
     $checkedOutTitles = array();
     //Get patron's location to determine if renewals are allowed.
     global $locationSingleton;
     /** @var Location $patronLocation */
     $patronLocation = $locationSingleton->getUserHomeLocation();
     if (isset($patronLocation)) {
         $patronPType = $this->driver->getPType();
         $patronCanRenew = false;
         if ($patronLocation->ptypesToAllowRenewals == '*') {
             $patronCanRenew = true;
         } else {
             if (preg_match("/^({$patronLocation->ptypesToAllowRenewals})\$/", $patronPType)) {
                 $patronCanRenew = true;
             }
         }
     } else {
         $patronCanRenew = true;
     }
     $timer->logTime("Determined if patron can renew");
     foreach ($sRows as $srow) {
         $scols = preg_split("/<t(h|d)([^>]*)>/", $srow);
         $curTitle = array();
         for ($i = 0; $i < sizeof($scols); $i++) {
             $scols[$i] = str_replace("&nbsp;", " ", $scols[$i]);
             $scols[$i] = preg_replace("/<br+?>/", " ", $scols[$i]);
             $scols[$i] = html_entity_decode(trim(substr($scols[$i], 0, stripos($scols[$i], "</t"))));
             //print_r($scols[$i]);
             if ($sCount == 1) {
                 $sKeys[$i] = $scols[$i];
             } else {
                 if ($sCount > 1) {
                     if (stripos($sKeys[$i], "TITLE") > -1) {
                         if (preg_match('/.*?<a href=\\"\\/record=(.*?)(?:~S\\d{1,2})\\">(.*?)<\\/a>.*/', $scols[$i], $matches)) {
                             //Standard Millennium WebPAC
                             $shortId = $matches[1];
                             $bibid = '.' . $matches[1];
                             //Technically, this isn't correct since the check digit is missing
                             $title = strip_tags($matches[2]);
                         } elseif (preg_match('/.*<a href=".*?\\/record\\/C__R(.*?)\\?.*?">(.*?)<\\/a>.*/si', $scols[$i], $matches)) {
                             //Encore
                             $shortId = $matches[1];
                             $bibid = '.' . $matches[1];
                             //Technically, this isn't correct since the check digit is missing
                             $title = strip_tags($matches[2]);
                         } else {
                             $title = strip_tags($scols[$i]);
                             $shortId = '';
                             $bibid = '';
                         }
                         $curTitle['checkoutSource'] = 'ILS';
                         $curTitle['shortId'] = $shortId;
                         $curTitle['id'] = $bibid;
                         $curTitle['title'] = utf8_encode($title);
                     }
                     if (stripos($sKeys[$i], "STATUS") > -1) {
                         // $sret[$scount-2]['duedate'] = strip_tags($scols[$i]);
                         $due = trim(str_replace("DUE", "", strip_tags($scols[$i])));
                         $renewCount = 0;
                         if (preg_match('/FINE\\(up to now\\) (\\$\\d+\\.\\d+)/i', $due, $matches)) {
                             $curTitle['fine'] = trim($matches[1]);
                         }
                         if (preg_match('/(.*)Renewed (\\d+) time(?:s)?/i', $due, $matches)) {
                             $due = trim($matches[1]);
                             $renewCount = $matches[2];
                         } else {
                             if (preg_match('/(.*)\\+\\d+ HOLD.*/i', $due, $matches)) {
                                 $due = trim($matches[1]);
                             }
                         }
                         if (preg_match('/(\\d{2}-\\d{2}-\\d{2})/', $due, $dueMatches)) {
                             $dateDue = DateTime::createFromFormat('m-d-y', $dueMatches[1]);
                             if ($dateDue) {
                                 $dueTime = $dateDue->getTimestamp();
                             } else {
                                 $dueTime = null;
                             }
                         } else {
                             $dueTime = strtotime($due);
                         }
                         if ($dueTime != null) {
                             $daysUntilDue = ceil(($dueTime - time()) / (24 * 60 * 60));
                             $overdue = $daysUntilDue < 0;
                             $curTitle['duedate'] = $dueTime;
                             $curTitle['overdue'] = $overdue;
                             $curTitle['daysUntilDue'] = $daysUntilDue;
                         }
                         $curTitle['renewCount'] = $renewCount;
                     }
                     if (stripos($sKeys[$i], "BARCODE") > -1) {
                         $curTitle['barcode'] = strip_tags($scols[$i]);
                     }
                     if (stripos($sKeys[$i], "RENEW") > -1) {
                         $matches = array();
                         if (preg_match('/<input\\s*type="checkbox"\\s*name="renew(\\d+)"\\s*id="renew(\\d+)"\\s*value="(.*?)"\\s*\\/>/', $scols[$i], $matches)) {
                             $curTitle['canrenew'] = $patronCanRenew;
                             $curTitle['itemindex'] = $matches[1];
                             $curTitle['itemid'] = $matches[3];
                             $curTitle['renewIndicator'] = $curTitle['itemid'] . '|' . $curTitle['itemindex'];
                             $curTitle['renewMessage'] = '';
                         } else {
                             $curTitle['canrenew'] = false;
                         }
                     }
                     if (stripos($sKeys[$i], "CALL NUMBER") > -1) {
                         $curTitle['request'] = "null";
                     }
                 }
             }
         }
         if ($sCount > 1) {
             //Get additional information from resources table
             if ($curTitle['shortId'] && strlen($curTitle['shortId']) > 0) {
                 $checkDigit = $this->driver->getCheckDigit($curTitle['shortId']);
                 $curTitle['recordId'] = '.' . $curTitle['shortId'] . $checkDigit;
                 $curTitle['id'] = '.' . $curTitle['shortId'] . $checkDigit;
                 require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php';
                 $recordDriver = new MarcRecord($curTitle['recordId']);
                 if ($recordDriver->isValid()) {
                     $curTitle['coverUrl'] = $recordDriver->getBookcoverUrl('medium');
                     $curTitle['groupedWorkId'] = $recordDriver->getGroupedWorkId();
                     $formats = $recordDriver->getFormats();
                     $curTitle['format'] = reset($formats);
                     $curTitle['author'] = $recordDriver->getPrimaryAuthor();
                     if (!isset($curTitle['title']) || empty($curTitle['title'])) {
                         $curTitle['title'] = $recordDriver->getTitle();
                     }
                 } else {
                     $curTitle['coverUrl'] = "";
                     $curTitle['groupedWorkId'] = "";
                     $curTitle['format'] = "Unknown";
                     $curTitle['author'] = "";
                 }
             }
             $sortTitle = isset($curTitle['title_sort']) ? $curTitle['title_sort'] : $curTitle['title'];
             $sortKey = $sortTitle;
             if ($sortOption == 'title') {
                 $sortKey = $sortTitle;
             } elseif ($sortOption == 'author') {
                 $sortKey = (isset($curTitle['author']) ? $curTitle['author'] : "Unknown") . '-' . $sortTitle;
             } elseif ($sortOption == '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 ($sortOption == 'format') {
                 $sortKey = (isset($curTitle['format']) ? $curTitle['format'] : "Unknown") . '-' . $sortTitle;
             } elseif ($sortOption == 'renewed') {
                 $sortKey = (isset($curTitle['renewCount']) ? $curTitle['renewCount'] : 0) . '-' . $sortTitle;
             } elseif ($sortOption == 'holdQueueLength') {
                 $sortKey = (isset($curTitle['holdQueueLength']) ? $curTitle['holdQueueLength'] : 0) . '-' . $sortTitle;
             }
             $sortKey .= "_{$sCount}";
             $checkedOutTitles[utf8_encode($sortKey)] = $curTitle;
         }
         $sCount++;
     }
     ksort($checkedOutTitles);
     $timer->logTime("Parsed checkout information");
     $numTransactions = count($checkedOutTitles);
     //Process pagination
     if ($recordsPerPage != -1) {
         $startRecord = ($page - 1) * $recordsPerPage;
         if ($startRecord > $numTransactions) {
             $startRecord = 0;
         }
         $checkedOutTitles = array_slice($checkedOutTitles, $startRecord, $recordsPerPage);
     }
     return array('transactions' => $checkedOutTitles, 'numTransactions' => $numTransactions);
 }
Ejemplo n.º 3
0
 public function getMyTransactionsFromDB($page = 1, $recordsPerPage = -1, $sortOption = 'dueDate')
 {
     global $user;
     if (isset($this->transactions[$user->id])) {
         return $this->transactions[$user->id];
     }
     //Get transactions by screen scraping
     $transactions = array();
     $this->initDatabaseConnection();
     $sql = "SELECT issues.*, items.biblionumber, title, author from issues left join items on items.itemnumber = issues.itemnumber left join biblio ON items.biblionumber = biblio.biblionumber where borrowernumber = ?";
     $checkoutsStmt = mysqli_prepare($this->dbConnection, $sql);
     $checkoutsStmt->bind_param('i', $user->username);
     $checkoutsStmt->execute();
     $results = $checkoutsStmt->get_result();
     while ($curRow = $results->fetch_assoc()) {
         $transaction = array();
         $transaction['checkoutSource'] = 'ILS';
         $transaction['id'] = $curRow['biblionumber'];
         $transaction['recordId'] = $curRow['biblionumber'];
         $transaction['shortId'] = $curRow['biblionumber'];
         $transaction['title'] = $curRow['title'];
         $transaction['author'] = $curRow['author'];
         $dateDue = DateTime::createFromFormat('Y-m-d', $curRow['date_due']);
         if ($dateDue) {
             $dueTime = $dateDue->getTimestamp();
         } else {
             $dueTime = null;
         }
         $transaction['duedate'] = $dueTime;
         if ($dueTime != null) {
             $daysUntilDue = ceil(($dueTime - time()) / (24 * 60 * 60));
             $overdue = $daysUntilDue < 0;
             $transaction['duedate'] = $dueTime;
             $transaction['overdue'] = $overdue;
             $transaction['daysUntilDue'] = $daysUntilDue;
         }
         $transaction['itemid'] = $curRow['id'];
         $transaction['renewIndicator'] = $curRow['id'];
         $transaction['renewCount'] = $curRow['renewals'];
         if ($transaction['id'] && strlen($transaction['id']) > 0) {
             $transaction['recordId'] = $transaction['id'];
             require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php';
             $recordDriver = new MarcRecord($transaction['recordId']);
             if ($recordDriver->isValid()) {
                 $transaction['coverUrl'] = $recordDriver->getBookcoverUrl('medium');
                 $transaction['groupedWorkId'] = $recordDriver->getGroupedWorkId();
                 $formats = $recordDriver->getFormats();
                 $transaction['format'] = reset($formats);
                 $transaction['author'] = $recordDriver->getPrimaryAuthor();
                 if (!isset($transaction['title']) || empty($transaction['title'])) {
                     $transaction['title'] = $recordDriver->getTitle();
                 }
             } else {
                 $transaction['coverUrl'] = "";
                 $transaction['groupedWorkId'] = "";
                 $transaction['format'] = "Unknown";
                 $transaction['author'] = "";
             }
         }
         $transactions[] = $transaction;
     }
     //Process sorting
     $sortKeys = array();
     $i = 0;
     foreach ($transactions as $key => $transaction) {
         $sortTitle = isset($transaction['sortTitle']) ? $transaction['sortTitle'] : "Unknown";
         if ($sortOption == 'title') {
             $sortKeys[$key] = $sortTitle;
         } elseif ($sortOption == 'author') {
             $sortKeys[$key] = (isset($transaction['author']) ? $transaction['author'] : "Unknown") . '-' . $sortTitle;
         } elseif ($sortOption == 'dueDate') {
             if (preg_match('/.*?(\\d{1,2})[-\\/](\\d{1,2})[-\\/](\\d{2,4}).*/', $transaction['duedate'], $matches)) {
                 $sortKeys[$key] = $matches[3] . '-' . $matches[1] . '-' . $matches[2] . '-' . $sortTitle;
             } else {
                 $sortKeys[$key] = $transaction['duedate'] . '-' . $sortTitle;
             }
         } elseif ($sortOption == 'format') {
             $sortKeys[$key] = (isset($transaction['format']) ? $transaction['format'] : "Unknown") . '-' . $sortTitle;
         } elseif ($sortOption == 'renewed') {
             $sortKeys[$key] = (isset($transaction['renewCount']) ? $transaction['renewCount'] : 0) . '-' . $sortTitle;
         } elseif ($sortOption == 'holdQueueLength') {
             $sortKeys[$key] = (isset($transaction['holdQueueLength']) ? $transaction['holdQueueLength'] : 0) . '-' . $sortTitle;
         }
         $sortKeys[$key] = $sortKeys[$key] . '-' . $i++;
     }
     array_multisort($sortKeys, $transactions);
     //Limit to a specific number of records
     $totalTransactions = count($transactions);
     if ($recordsPerPage != -1) {
         $startRecord = ($page - 1) * $recordsPerPage;
         $transactions = array_slice($transactions, $startRecord, $recordsPerPage);
     }
     $this->transactions[$user->id] = $transactions;
     return array('transactions' => $transactions, 'numTransactions' => $totalTransactions);
 }
Ejemplo n.º 4
0
 function reloadCover()
 {
     require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php';
     $id = $_REQUEST['id'];
     $recordDriver = new MarcRecord($id);
     //Reload small cover
     $smallCoverUrl = str_replace('&amp;', '&', $recordDriver->getBookcoverUrl('small')) . '&reload';
     file_get_contents($smallCoverUrl);
     //Reload medium cover
     $mediumCoverUrl = str_replace('&amp;', '&', $recordDriver->getBookcoverUrl('medium')) . '&reload';
     file_get_contents($mediumCoverUrl);
     //Reload large cover
     $largeCoverUrl = str_replace('&amp;', '&', $recordDriver->getBookcoverUrl('large')) . '&reload';
     file_get_contents($largeCoverUrl);
     //Also reload covers for the grouped work
     require_once ROOT_DIR . '/RecordDrivers/GroupedWorkDriver.php';
     $groupedWorkDriver = new GroupedWorkDriver($recordDriver->getGroupedWorkId());
     global $configArray;
     //Reload small cover
     $smallCoverUrl = $configArray['Site']['coverUrl'] . str_replace('&amp;', '&', $groupedWorkDriver->getBookcoverUrl('small')) . '&reload';
     file_get_contents($smallCoverUrl);
     //Reload medium cover
     $mediumCoverUrl = $configArray['Site']['coverUrl'] . str_replace('&amp;', '&', $groupedWorkDriver->getBookcoverUrl('medium')) . '&reload';
     file_get_contents($mediumCoverUrl);
     //Reload large cover
     $largeCoverUrl = $configArray['Site']['coverUrl'] . str_replace('&amp;', '&', $groupedWorkDriver->getBookcoverUrl('large')) . '&reload';
     file_get_contents($largeCoverUrl);
     return $this->json_utf8_encode(array('success' => true, 'message' => 'Covers have been reloaded.  You may need to refresh the page to clear your local cache.'));
 }