Example #1
0
 /**
  * Import Lists from the ILS
  *
  * @return array - an array of results including the names of the lists that were imported as well as number of titles.
  */
 function importListsFromIls()
 {
     require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php';
     global $user;
     $results = array('totalTitles' => 0, 'totalLists' => 0);
     $patronDump = $this->_getPatronDump($this->_getBarcode());
     //Get the page which contains a table with all lists in them.
     $listsPage = $this->_fetchPatronInfoPage($patronDump, 'mylists');
     //Get the actual table
     if (preg_match('/<table[^>]*?class="patFunc"[^>]*?>(.*?)<\\/table>/si', $listsPage, $listsPageMatches)) {
         $allListTable = $listsPageMatches[1];
         //Now that we have the table, get the actual list names and ids
         preg_match_all('/<tr[^>]*?class="patFuncEntry"[^>]*?>.*?<input type="checkbox" id ="(\\d+)".*?<a.*?>(.*?)<\\/a>.*?<td[^>]*class="patFuncDetails">(.*?)<\\/td>.*?<\\/tr>/si', $allListTable, $listDetails, PREG_SET_ORDER);
         for ($listIndex = 0; $listIndex < count($listDetails); $listIndex++) {
             $listId = $listDetails[$listIndex][1];
             $title = $listDetails[$listIndex][2];
             $description = str_replace('&nbsp;', '', $listDetails[$listIndex][3]);
             //Create the list (or find one that already exists)
             $newList = new UserList();
             $newList->user_id = $user->id;
             $newList->title = $title;
             if (!$newList->find(true)) {
                 $newList->description = $description;
                 $newList->insert();
             }
             $currentListTitles = $newList->getListTitles();
             //Get a list of all titles within the list to be imported
             $listDetailsPage = $this->_fetchPatronInfoPage($patronDump, 'mylists?listNum=' . $listId);
             //Get the table for the details
             if (preg_match('/<table[^>]*?class="patFunc"[^>]*?>(.*?)<\\/table>/si', $listDetailsPage, $listsDetailsMatches)) {
                 $listTitlesTable = $listsDetailsMatches[1];
                 //Get the bib numbers for the title
                 preg_match_all('/<input type="checkbox" name="(b\\d{1,7})".*?<span[^>]*class="patFuncTitle(?:Main)?">(.*?)<\\/span>/si', $listTitlesTable, $bibNumberMatches, PREG_SET_ORDER);
                 for ($bibCtr = 0; $bibCtr < count($bibNumberMatches); $bibCtr++) {
                     $bibNumber = $bibNumberMatches[$bibCtr][1];
                     $bibTitle = strip_tags($bibNumberMatches[$bibCtr][2]);
                     //Get the grouped work for the resource
                     require_once ROOT_DIR . '/sys/Grouping/GroupedWorkPrimaryIdentifier.php';
                     require_once ROOT_DIR . '/sys/Grouping/GroupedWork.php';
                     $primaryIdentifier = new GroupedWorkPrimaryIdentifier();
                     $groupedWork = new GroupedWork();
                     $primaryIdentifier->identifier = '.' . $bibNumber . $this->getCheckDigit($bibNumber);
                     $primaryIdentifier->type = 'ils';
                     $primaryIdentifier->joinAdd($groupedWork);
                     if ($primaryIdentifier->find(true)) {
                         //Check to see if this title is already on the list.
                         $resourceOnList = false;
                         foreach ($currentListTitles as $currentTitle) {
                             if ($currentTitle->groupedWorkPermanentId == $primaryIdentifier->permanent_id) {
                                 $resourceOnList = true;
                                 break;
                             }
                         }
                         if (!$resourceOnList) {
                             $listEntry = new UserListEntry();
                             $listEntry->groupedWorkPermanentId = $primaryIdentifier->permanent_id;
                             $listEntry->listId = $newList->id;
                             $listEntry->notes = '';
                             $listEntry->dateAdded = time();
                             $listEntry->insert();
                         }
                     } else {
                         //The title is not in the resources, add an error to the results
                         if (!isset($results['errors'])) {
                             $results['errors'] = array();
                         }
                         $results['errors'][] = "\"{$bibTitle}\" on list {$title} could not be found in the catalog and was not imported.";
                     }
                     $results['totalTitles']++;
                 }
             }
             $results['totalLists'] += 1;
         }
     }
     return $results;
 }
Example #2
0
 private function _getUserListTitles($listId)
 {
     global $user;
     //The list is a patron generated list
     $list = new UserList();
     $list->id = $listId;
     if ($list->find(true)) {
         //Make sure the user has acess to the list
         if ($list->public == 0) {
             if (!$user) {
                 return array('success' => false, 'message' => 'The user was invalid.  A valid user must be provided for private lists.');
             } elseif ($list->user_id != $user->id) {
                 return array('success' => false, 'message' => 'The user does not have access to this list.');
             }
         }
         //Load the titles for the list.
         $listTitles = $list->getListTitles();
         $ids = array();
         $datesSaved = array();
         foreach ($listTitles as $listEntry) {
             $ids[] = $listEntry->groupedWorkPermanentId;
             $datesSaved[$listEntry->groupedWorkPermanentId] = $listEntry->dateAdded;
         }
         $titles = $this->loadTitleInformationForIds($ids, array(), $datesSaved);
         return array('success' => true, 'listName' => $list->title, 'listDescription' => $list->description, 'titles' => $titles, 'cacheLength' => 24);
     } else {
         return array('success' => false, 'message' => 'The specified list could not be found.');
     }
 }
Example #3
0
 function sendMyListEmail()
 {
     // TODO: Implements sending emails of list
     global $interface, $user;
     // Get data from AJAX request
     if (isset($_REQUEST['listId']) && ctype_digit($_REQUEST['listId'])) {
         $listId = $_REQUEST['listId'];
     } else {
         // Invalid listId
         // TODO
     }
     $to = $_REQUEST['to'];
     $from = $_REQUEST['from'];
     $message = $_REQUEST['message'];
     //Load the list
     require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php';
     $list = new UserList();
     $list->id = $listId;
     if ($list->find(true)) {
         // Build Favorites List
         $titles = $list->getListTitles();
         $interface->assign('listEntries', $titles);
         // TODO: if not used, i would like to remove
         // Load the User object for the owner of the list (if necessary):
         if ($list->public == true || $user && $user->id == $list->user_id) {
             //The user can access the list
             require_once ROOT_DIR . '/services/MyResearch/lib/FavoriteHandler.php';
             //				$favoriteHandler = new FavoriteHandler($titles, $user, $list->id, false);
             $favoriteHandler = new FavoriteHandler($list, $user, false);
             $titleDetails = $favoriteHandler->getTitles(count($titles));
             // get all titles for email list, not just a page's worth
             $interface->assign('titles', $titleDetails);
             $interface->assign('list', $list);
             if (strpos($message, 'http') === false && strpos($message, 'mailto') === false && $message == strip_tags($message)) {
                 $interface->assign('message', $message);
                 $body = $interface->fetch('Emails/my-list.tpl');
                 require_once ROOT_DIR . '/sys/Mailer.php';
                 $mail = new VuFindMailer();
                 $subject = $list->title;
                 $emailResult = $mail->send($to, $from, $subject, $body);
                 if ($emailResult === true) {
                     $result = array('result' => true, 'message' => 'Your e-mail was sent successfully.');
                 } elseif (PEAR_Singleton::isError($emailResult)) {
                     $result = array('result' => false, 'message' => "Your e-mail message could not be sent: {$emailResult->message}.");
                 } else {
                     $result = array('result' => false, 'message' => 'Your e-mail message could not be sent due to an unknown error.');
                 }
             } else {
                 $result = array('result' => false, 'message' => 'Sorry, we can&apos;t send e-mails with html or other data in it.');
             }
         } else {
             $result = array('result' => false, 'message' => 'You do not have access to this list.');
         }
     } else {
         $result = array('result' => false, 'message' => 'Unable to read list.');
     }
     return $result;
 }