private function saveChanges($user) { global $interface; $resource = new Resource(); $resource->id = $_REQUEST['resourceId']; if ($resource->find(true)) { $interface->assign('resource', $resource); } else { PEAR_Singleton::raiseError(new PEAR_Error("Could not find resource {$_REQUEST['resourceId']}")); } // Loop through the list of lists on the edit screen: foreach ($_POST['lists'] as $listId) { // Create a list object for the current list: $list = new User_list(); if ($listId != '') { $list->id = $listId; $list->find(true); } else { PEAR_Singleton::raiseError(new PEAR_Error('List ID Missing')); } // Extract tags from the user input: preg_match_all('/"[^"]*"|[^ ]+/', $_POST['tags' . $listId], $tagArray); // Save extracted tags and notes: $user->addResource($resource, $list, $tagArray[0], $_POST['notes' . $listId]); } }
function sendEmail($to, $from, $message) { global $interface; global $user; //Load the list $list = new User_list(); $list->id = $_REQUEST['listId']; if ($list->find(true)) { // Build Favorites List $titles = $list->getResources(null); // Load the User object for the owner of the list (if necessary): if ($user && $user->id == $list->user_id || $list->public == 1) { //The user can access the list $favoriteHandler = new FavoriteHandler($titles, $user); $titleDetails = $favoriteHandler->getTitles(); $interface->assign('titles', $titleDetails); $interface->assign('list', $list); } else { $interface->assign('error', 'You do not have access to this list.'); } } else { $interface->assign('error', 'Unable to read list'); } $interface->assign('from', $from); $interface->assign('message', $message); $body = $interface->fetch('Emails/my-list.tpl'); $mail = new VuFindMailer(); $subject = $list->title; return $mail->send($to, $from, $subject, $body); }
/** * Process incoming parameters and display the page. * * @return void * @access public */ public function launch() { global $configArray; global $interface; global $user; // Fetch List object $list = User_list::staticGet($_GET['id']); if (!$list->public && $list->user_id != $user->id) { PEAR::raiseError(new PEAR_Error(translate('list_access_denied'))); } $interface->assign('list', $list); $interface->assign('publicList', true); $interface->assign('ownList', $list->user_id == $user->id); $date = new VuFindDate(); if (strtotime($list->modified) !== false && strtotime($list->modified) > 0) { $interface->assign('listModified', $date->convertToDisplayDate('Y-m-d H:i:s', $list->modified)); } // Load the User object for the owner of the list (if necessary): if ($user && $user->id == $list->user_id) { $listUser = $user; } else { $listUser = User::staticGet($list->user_id); } $listOwner = null; if ($listUser->email && ($pos = strpos($listUser->email, '@')) !== false) { $listOwner = substr($listUser->email, 0, $pos); } else { if ($listUser->firstname && $listUser->lastname) { $listOwner = "{$listUser->firstname} {$listUser->lastname}"; } } if ($listOwner) { $interface->assign('listUsername', $listOwner); } $searchObject = SearchObjectFactory::initSearchObject(); $searchObject->init(); $interface->assign('viewList', $searchObject->getViewList()); // Build Favorites List $favorites = $list->getResources(isset($_GET['tag']) ? $_GET['tag'] : null); // Create a handler for displaying favorites and use it to assign // appropriate template variables: $favList = new FavoriteHandler($favorites, $listUser, $list->id, false); $favList->initPublicListView($searchObject->getView(), $listOwner); $favList->assign(); $interface->assign('recordSet', $interface->get_template_vars('resourceList')); $interface->assign('openUrlAutoCheck', true); $currentView = $searchObject->getView(); $interface->assign('subpage', 'Search/list-' . $currentView . '.tpl'); $interface->setTemplate('home.tpl'); $interface->setPageTitle($list->title); $interface->display('layout.tpl'); }
function saveToMyList() { require_once ROOT_DIR . '/services/MyResearch/lib/Resource.php'; require_once ROOT_DIR . '/services/MyResearch/lib/User.php'; $listId = $_REQUEST['list']; $tags = $_REQUEST['mytags']; $notes = $_REQUEST['notes']; $ids = $_REQUEST['id']; global $user; $list = new User_list(); if ($_GET['list'] != '') { $list->id = $listId; $list->find(true); } else { $list->user_id = $user->id; $list->title = "My Favorites"; $list->insert(); } $ctr = 0; foreach ($ids as $id) { $source = 'VuFind'; $recordId = $id; if (strpos($recordId, 'econtentRecord') === 0) { $source = 'eContent'; $recordId = str_ireplace("econtentrecord", "", $recordId); } $ctr++; $resource = new Resource(); $resource->record_id = $recordId; $resource->source = $source; if (!$resource->find(true)) { $resource->insert(); } preg_match_all('/"[^"]*"|[^,]+/', $tags, $tagArray); //Make sure that Solr is only updated once for performance reasons. $user->addResource($resource, $list, $tagArray[0], $notes, $ctr == count($ids)); } return array('status' => 'OK'); }
function addList() { if ($this->user) { if (strlen(trim($_REQUEST['title'])) == 0) { return new PEAR_Error('list_edit_name_required'); } $list = new User_list(); $list->title = $_REQUEST['title']; $list->description = $_REQUEST['desc']; $list->public = $_REQUEST['public']; $list->user_id = $this->user->id; $list->insert(); $list->find(); return $list->id; } }
/** * Perform a bulk operation. * * @param array $ids IDs to process * @param int $listID Target list * limit). * * @return void */ protected function processRecords($ids, $listID) { global $user; // First copy the records if (!parent::processRecords($ids, $listID)) { return false; } // Copy successful, now delete $list = User_list::staticGet($_REQUEST['listID']); if ($user->id != $list->user_id) { $this->errorMsg = 'list_access_denied'; return false; } $list->removeResourcesById($ids); $this->infoMsg = 'records_moved'; return true; }
function launch() { global $interface; global $configArray; global $user; //Get all lists for the user // Fetch List object if (isset($_REQUEST['id'])) { $list = User_list::staticGet($_GET['listId']); } $interface->assign('favList', $list); // Get all titles on the list $favorites = $list->getResources(null); $favList = new FavoriteHandler($favorites, null, $list->id, false); $citationFormat = $_REQUEST['citationFormat']; $citationFormats = CitationBuilder::getCitationFormats(); $interface->assign('citationFormat', $citationFormats[$citationFormat]); $citations = $favList->getCitations($citationFormat); $interface->assign('citations', $citations); // Display Page $interface->assign('listId', strip_tags($_REQUEST['id'])); $interface->setTemplate('listCitations.tpl'); $interface->display('layout.tpl'); }
/** * Process parameters and display the page. * * @return void * @access public */ public function launch() { global $interface; global $configArray; if (!($user = UserAccount::isLoggedIn())) { include_once 'Login.php'; Login::launch(); exit; } // Fetch List object $list = User_list::staticGet($_GET['id']); // Ensure user have privs to view the list if ($list->user_id != $user->id) { PEAR::raiseError(new PEAR_Error(translate('list_access_denied'))); } // Save Data if (isset($_POST['submit'])) { if (empty($_POST['title'])) { $interface->assign('errorMsg', 'list_edit_name_required'); } else { if ($this->_saveChanges($user, $list)) { // After changes are saved, send the user back to an appropriate page $nextAction = 'MyList/' . $list->id; header('Location: ' . $configArray['Site']['url'] . '/MyResearch/' . $nextAction); exit; } else { // List was not edited $interface->assign('errorMsg', 'edit_list_fail'); } } } // Send list to template so title/description can be displayed: $interface->assign('list', $list); $interface->setTemplate('editList.tpl'); $interface->display('layout.tpl'); }
/** * Create a new list based on the current user and $_REQUEST parameters. * * @return mixed New list ID on success, PEAR_Error on failure. * @access public */ public function addList() { if ($this->_user) { if (strlen(trim($_REQUEST['title'])) == 0) { return new PEAR_Error('list_edit_name_required'); } $list = new User_list(); $list->title = $_REQUEST['title']; $list->description = $_REQUEST['desc']; $list->public = $_REQUEST['public']; $list->user_id = $this->_user->id; $list->insert(); $list->find(); // Remember that the list was used so it can be the default in future // dialog boxes: $list->rememberLastUsed(); return $list->id; } }
/** * Save the record specified by GET parameters. * * @param object $user User who is saving the record. * * @return bool True on success, false on failure. * @access public */ public static function saveRecord($user) { // Fail if the user is not logged in: if (!$user) { return false; } $list = new User_list(); if (isset($_GET['list']) && $_GET['list'] != '') { $list->id = $_GET['list']; } else { if (isset($_POST['list']) && $_POST['list'] != '') { $list->id = $_POST['list']; } else { $list->user_id = $user->id; $list->title = "My Favorites"; if (!$list->find(true)) { $list->insert(); } } } // Remember that the list was used so it can be the default in future // dialog boxes: $list->rememberLastUsed(); // Setup Search Engine Connection $db = ConnectionManager::connectToIndex('MetaLib'); // Get Record Information $record = $db->getRecord($_GET['id']); if (!$record) { return false; } $resource = new Resource(); $resource->record_id = $_GET['id']; $resource->source = 'MetaLib'; if (!$resource->find(true)) { $resource->data = serialize($record); $resource->insert(); } else { $resource->data = serialize($record); $resource->update(); } preg_match_all('/"[^"]*"|[^ ]+/', isset($_GET['mytags']) ? $_GET['mytags'] : '', $tagArray); return $user->addResource($resource, $list, $tagArray[0], isset($_GET['notes']) ? $_GET['notes'] : ''); }
/** * Process parameters and display the page. * * @return void * @access public */ public function launch() { global $configArray; global $interface; global $user; // Delete List and All Resources (but only if list owner is logged in!) if (isset($_POST['deleteList'])) { $listID = $_POST['listID']; $list = User_list::staticGet($listID); if ($user->id == $list->user_id) { // Remove the List $result = $list->emptyList(); if ($result) { $followupUrl = $configArray['Site']['url'] . "/MyResearch/Favorites"; header("Location: " . $followupUrl . "?infoMsg=fav_list_delete"); exit; } } // If we get this far, there's an error $this->errorMsg = "fav_list_delete_fail"; } // Fetch List object $list = User_list::staticGet($_GET['id']); // Ensure user have privs to view the list if (!$list->public && !UserAccount::isLoggedIn()) { include_once 'Login.php'; Login::launch(); exit; } if (!$list->public && $list->user_id != $user->id) { PEAR::raiseError(new PEAR_Error(translate('list_access_denied'))); } // Redirect anonymous users to public list URL if ($list->public && (!UserAccount::isLoggedIn() || $list->user_id != $user->id)) { header("Location: " . $configArray['Site']['url'] . "/List/" . $list->id); } $this->infoMsg = isset($_GET['infoMsg']) ? $_GET['infoMsg'] : false; $this->errorMsg = isset($_GET['errorMsg']) ? $_GET['errorMsg'] : false; $this->showExport = isset($_GET['showExport']) ? $_GET['showExport'] : false; // Delete Resource (but only if list owner is logged in!) if (isset($_GET['delete']) && $user->id == $list->user_id) { $resource = new Resource(); $resource->record_id = $_GET['delete']; unset($resource->source); if ($resource->find(true)) { $list->removeResource($resource); } } // Send list to template so title/description can be displayed: $interface->assign('list', $list); // Build Favorites List $favorites = $list->getResources(isset($_GET['tag']) ? $_GET['tag'] : null); // Load the User object for the owner of the list (if necessary): if ($user && $user->id == $list->user_id) { $listUser = $user; } else { $listUser = User::staticGet($list->user_id); } // Create a handler for displaying favorites and use it to assign // appropriate template variables: $allowEdit = $user && $user->id == $list->user_id; $favList = new FavoriteHandler($favorites, $listUser, $list->id, $allowEdit); $favList->assign(); if (!$this->infoMsg) { $this->infoMsg = $favList->getInfoMsg(); } // Narrow by Tag if (isset($_GET['tag'])) { $interface->assign('tags', $_GET['tag']); } // Get My Lists $listList = $user ? $user->getLists() : array(); $interface->assign('listList', $listList); // Get My Tags $tagList = $list->getTags(); $interface->assign('tagList', $tagList); // Assign Error & Info Messages $interface->assign('infoMsg', $this->infoMsg); $interface->assign('errorMsg', $this->errorMsg); $interface->assign('showExport', $this->showExport); // Assign Exporter Options $exportOptions = array(); if ($configArray['BulkExport']['enabled']) { $options = explode(':', $configArray['BulkExport']['options']); foreach ($options as $option) { if ($configArray['Export'][$option] == true) { $exportOptions[] = $option; } } $interface->assign('exportOptions', $exportOptions); } $interface->setTemplate('list.tpl'); $interface->setPageTitle($list->title); $interface->display('layout.tpl'); }
function saveRecord() { if ($this->user) { $list = new User_list(); if ($_GET['list'] != '') { $list->id = $_GET['list']; } else { $list->user_id = $this->user->id; $list->title = "My Favorites"; $list->insert(); } $resource = new Resource(); $resource->record_id = $_GET['id']; $resource->service = $_GET['service']; if (!$resource->find(true)) { $resource->insert(); } preg_match_all('/"[^"]*"|[^,]+/', $_GET['mytags'], $tagArray); $this->user->addResource($resource, $list, $tagArray[0], $_GET['notes']); } else { return false; } }
function getLists() { require_once 'User_list.php'; $lists = array(); $sql = "SELECT user_list.*, COUNT(user_resource.id) AS cnt FROM user_list " . "LEFT JOIN user_resource ON user_list.id = user_resource.list_id " . "WHERE user_list.user_id = '{$this->id}' " . "GROUP BY user_list.id, user_list.user_id, user_list.title, " . "user_list.description, user_list.created, user_list.public " . "ORDER BY user_list.title"; $list = new User_list(); $list->query($sql); if ($list->N) { while ($list->fetch()) { $lists[] = clone $list; } } return $lists; }
function launch() { global $configArray; global $interface; global $user; //Get all lists for the user if ($user) { $tmpList = new User_list(); $tmpList->user_id = $user->id; $tmpList->orderBy("title ASC"); $tmpList->find(); $allLists = array(); if ($tmpList->N > 0) { while ($tmpList->fetch()) { $allLists[$tmpList->id] = $tmpList->title; } } else { $allList["-1"] = "My Favorites"; } $interface->assign('allLists', $allLists); } //Figure out if we should show a link to classic opac to pay holds. $ecommerceLink = $configArray['Site']['ecommerceLink']; if ($user) { $homeLibrary = Library::getLibraryForLocation($user->homeLocationId); } if (strlen($ecommerceLink) > 0 && isset($homeLibrary) && $homeLibrary->showEcommerceLink == 1) { $interface->assign('showEcommerceLink', true); $interface->assign('minimumFineAmount', $homeLibrary->minimumFineAmount); if ($homeLibrary->payFinesLink == 'default' || strlen($homeLibrary->payFinesLink) == 0) { $interface->assign('ecommerceLink', $ecommerceLink); } else { $interface->assign('ecommerceLink', $homeLibrary->payFinesLink); } $interface->assign('payFinesLinkText', $homeLibrary->payFinesLinkText); } else { $interface->assign('showEcommerceLink', false); $interface->assign('minimumFineAmount', 0); } // Fetch List object if (isset($_GET['id'])) { $list = User_list::staticGet($_GET['id']); } else { //Use the first list. if (isset($allLists)) { $firstListId = reset(array_keys($allLists)); if ($firstListId == false || $firstListId == -1) { $list = new User_list(); $list->user_id = $user->id; $list->public = false; $list->title = "My Favorites"; } else { $list = User_list::staticGet($firstListId); } } } // Ensure user have privs to view the list if (!isset($list) || !$list->public && !UserAccount::isLoggedIn()) { require_once 'Login.php'; Login::launch(); exit; } if (!$list->public && $list->user_id != $user->id) { PEAR_Singleton::raiseError(new PEAR_Error(translate('list_access_denied'))); } //Reindex can happen by anyone since it needs to be called by cron if (isset($_REQUEST['myListActionHead']) && strlen($_REQUEST['myListActionHead']) > 0) { $actionToPerform = $_REQUEST['myListActionHead']; if ($actionToPerform == 'reindex') { $list->updateDetailed(true); } } if (isset($_SESSION['listNotes'])) { $interface->assign('notes', $_SESSION['listNotes']); unset($_SESSION['listNotes']); } //Perform an action on the list, but verify that the user has permission to do so. $userCanEdit = false; if ($user != false) { if ($user->id == $list->user_id) { $userCanEdit = true; } elseif ($user->hasRole('opacAdmin')) { $userCanEdit = true; } elseif ($user->hasRole('libraryAdmin') || $user->hasRole('contentEditor')) { $listUser = new User(); $listUser->id = $list->user_id; $listUser->find(true); $listLibrary = Library::getLibraryForLocation($listUser->homeLocationId); $userLibrary = Library::getLibraryForLocation($user->homeLocationId); if ($userLibrary->libraryId == $listLibrary->libraryId) { $userCanEdit = true; } } } if ($userCanEdit && (isset($_REQUEST['myListActionHead']) || isset($_REQUEST['myListActionItem']) || isset($_GET['delete']))) { if (isset($_REQUEST['myListActionHead']) && strlen($_REQUEST['myListActionHead']) > 0) { $actionToPerform = $_REQUEST['myListActionHead']; if ($actionToPerform == 'makePublic') { $list->public = 1; $list->update(); } elseif ($actionToPerform == 'makePrivate') { $list->public = 0; $list->updateDetailed(false); $list->removeFromSolr(); } elseif ($actionToPerform == 'saveList') { $list->title = $_REQUEST['newTitle']; $list->description = $_REQUEST['newDescription']; $list->update(); } elseif ($actionToPerform == 'deleteList') { $list->delete(); header("Location: {$configArray['Site']['path']}/MyResearch/Home"); die; } elseif ($actionToPerform == 'bulkAddTitles') { $notes = $this->bulkAddTitles($list); $_SESSION['listNotes'] = $notes; } } elseif (isset($_REQUEST['myListActionItem']) && strlen($_REQUEST['myListActionItem']) > 0) { $actionToPerform = $_REQUEST['myListActionItem']; if ($actionToPerform == 'deleteMarked') { //get a list of all titles that were selected $itemsToRemove = $_REQUEST['selected']; foreach ($itemsToRemove as $id => $selected) { //add back the leading . to get the full bib record $resource = Resource::staticGet('record_id', "{$id}"); $list->removeResource($resource); } } elseif ($actionToPerform == 'deleteAll') { $list->removeAllResources(isset($_GET['tag']) ? $_GET['tag'] : null); } $list->update(); } elseif (isset($_GET['delete'])) { $resource = Resource::staticGet('record_id', $_GET['delete']); $list->removeResource($resource); $list->update(); } //Redirect back to avoid having the parameters stay in the URL. header("Location: {$configArray['Site']['path']}/MyResearch/MyList/{$list->id}"); die; } // Send list to template so title/description can be displayed: $interface->assign('favList', $list); $interface->assign('listSelected', $list->id); // Build Favorites List $favorites = $list->getResources(isset($_GET['tag']) ? $_GET['tag'] : null); // Load the User object for the owner of the list (if necessary): if ($user && $user->id == $list->user_id) { $listUser = $user; } else { if ($list->user_id != 0) { $listUser = new User(); $listUser->id = $list->user_id; if (!$listUser->fetch(true)) { $listUser = false; } } else { $listUser = false; } } // Create a handler for displaying favorites and use it to assign // appropriate template variables: $interface->assign('allowEdit', $userCanEdit); $favList = new FavoriteHandler($favorites, $listUser, $list->id, $userCanEdit); $favList->assign(); //Need to add profile information from MyResearch to show profile data. if ($user !== false) { global $configArray; $this->catalog = new CatalogConnection($configArray['Catalog']['driver']); // Get My Profile if ($this->catalog->status) { if ($user->cat_username) { $patron = $this->catalog->patronLogin($user->cat_username, $user->cat_password); if (PEAR_Singleton::isError($patron)) { PEAR_Singleton::raiseError($patron); } $result = $this->catalog->getMyProfile($patron); if (!PEAR_Singleton::isError($result)) { $interface->assign('profile', $result); } } } //Figure out if we should show a link to classic opac to pay holds. $homeLibrary = Library::getLibraryForLocation($user->homeLocationId); if (isset($homeLibrary) && $homeLibrary->showEcommerceLink == 1) { $interface->assign('showEcommerceLink', true); $interface->assign('minimumFineAmount', $homeLibrary->minimumFineAmount); } else { $interface->assign('showEcommerceLink', false); $interface->assign('minimumFineAmount', 0); } } $interface->setTemplate('list.tpl'); $interface->display('layout.tpl'); }
/** * Add titles to a user list. * * 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>listId - The id of the list to add items to.</li> * <li>recordIds - The id of the record(s) to add to the list.</li> * <li>tags - A comma separated string of tags to apply to the titles within the list. (optional)</li> * <li>notes - descriptive text to apply to the titles. Can be viewed while on the list. (optional)</li> * </ul> * * Note: You may also provide the parameters to addTitlesToList and titles will be added to the list * after the list is created. * * Returns: * <ul> * <li>success - true if the account is valid and the titles could be added to the list, false if the username or password were incorrect or the list could not be created.</li> * <li>listId - the id of the list that titles were added to.</li> * <li>numAdded - the number of titles that were added to the list.</li> * </ul> * * Sample Call: * <code> * http://catalog.douglascountylibraries.org/API/ListAPI?method=createList&username=23025003575917&password=1234&title=Test+List&description=Test&public=0 * </code> * * Sample Response: * <code> * {"result":{"success":true,"listId":"1688"}} * </code> */ function addTitlesToList() { $username = $_REQUEST['username']; $password = $_REQUEST['password']; if (!isset($_REQUEST['listId'])) { return array('success' => false, 'message' => 'You must provide the listId to add titles to.'); } $recordIds = array(); if (!isset($_REQUEST['recordIds'])) { return array('success' => false, 'message' => 'You must provide one or more records to add tot he list.'); } else { if (!is_array($_REQUEST['recordIds'])) { $recordIds[] = $_REQUEST['recordIds']; } else { $recordIds = $_REQUEST['recordIds']; } } global $user; $user = UserAccount::validateAccount($username, $password); if ($user && !PEAR_Singleton::isError($user)) { $list = new User_list(); $list->id = $_REQUEST['listId']; $list->user_id = $user->id; if (!$list->find(true)) { return array('success' => false, 'message' => 'Unable to find the list to add titles to.'); } else { $recordIds = $_REQUEST['recordIds']; $numAdded = 0; foreach ($recordIds as $id) { $source = 'VuFind'; if (preg_match('/econtentRecord\\d+/i', $id)) { $id = substr($id, 14); $source = 'eContent'; } $resource = new Resource(); $resource->record_id = $id; $resource->source = $source; if (!$resource->find(true)) { $resource->insert(); } if (isset($_REQUEST['tags'])) { preg_match_all('/"[^"]*"|[^,]+/', $_REQUEST['tags'], $tagArray); $tags = $tagArray[0]; } else { $tags = array(); } if (isset($_REQUEST['notes'])) { $notes = $_REQUEST['notes']; } else { $notes = ''; } if ($user->addResource($resource, $list, $tags, $notes)) { $numAdded++; } } return array('success' => true, 'listId' => $list->id, 'numAdded' => $numAdded); } } else { return array('success' => false, 'message' => 'Login unsuccessful'); } }
/** * Perform a bulk operation. * * @param array $ids IDs to process * @param int $listID Target list * limit). * * @return boolean Success */ protected function processRecords($ids, $listID) { global $user; if (empty($ids)) { $this->errorMsg = 'bulk_noitems_advice'; return false; } if (!$user) { $this->errorMsg = 'You must be logged in first'; return false; } $list = User_list::staticGet($listID); if ($user->id != $list->user_id) { $this->errorMsg = 'list_access_denied'; return false; } $resources = $user->getResources(); foreach ($resources as $resource) { if (in_array($resource->record_id, $ids)) { $notes = ''; $userResource = new User_resource(); $userResource->user_id = $user->id; $userResource->list_id = $_REQUEST['listID']; $userResource->resource_id = $resource->id; if ($userResource->find(true)) { $notes = $userResource->notes; } $tags = array(); foreach ($user->getTags($resource->record_id) as $tag) { $tags[] = $tag->tag; } $user->addResource($resource, $list, $tags, $notes); } } $this->infoMsg = 'records_copied'; return true; }
/** * Perform a bulk delete operation. * * @param array $ids IDs to delete * @param int $listID List to limit the delete operation to (false for no * limit). * * @return array Status details. * @access public */ public function deleteFavorites($ids, $listID = false) { global $configArray; global $interface; global $user; if ($listID && $listID != "") { $list = User_list::staticGet($listID); if ($user->id == $list->user_id) { $result = $list->removeResourcesById($ids); } } else { $result = $user->removeResourcesById($ids); } if ($result) { $this->infoMsg = 'fav_delete_success'; } $results = array('deleteDetails' => $this->infoMsg); return $results; }
function __construct() { global $interface; global $configArray; global $user; $interface->assign('page_body_style', 'sidebar_left'); $interface->assign('ils', $configArray['Catalog']['ils']); if ($this->requireLogin && !UserAccount::isLoggedIn()) { require_once 'Login.php'; Login::launch(); exit; } //$interface->assign('userNoticeFile', 'MyResearch/listNotice.tpl'); // Setup Search Engine Connection $class = $configArray['Index']['engine']; $this->db = new $class($configArray['Index']['url']); if ($configArray['System']['debugSolr']) { $this->db->debug = true; } // Connect to Database $this->catalog = new CatalogConnection($configArray['Catalog']['driver']); // Register Library Catalog Account if (isset($_POST['submit']) && !empty($_POST['submit'])) { if ($this->catalog && isset($_POST['cat_username']) && isset($_POST['cat_password'])) { $result = $this->catalog->patronLogin($_POST['cat_username'], $_POST['cat_password']); if ($result && !PEAR_Singleton::isError($result)) { $user->cat_username = $_POST['cat_username']; $user->cat_password = $_POST['cat_password']; $user->update(); UserAccount::updateSession($user); $interface->assign('user', $user); } else { $interface->assign('loginError', 'Invalid Patron Login'); } } } //Determine whether or not materials request functionality should be enabled $interface->assign('enableMaterialsRequest', MaterialsRequest::enableMaterialsRequest()); //Check to see if we have any acs or single use eContent in the catalog //to enable the holds and wishlist appropriately if (isset($configArray['EContent']['hasProtectedEContent'])) { $interface->assign('hasProtectedEContent', $configArray['EContent']['hasProtectedEContent']); } else { $interface->assign('hasProtectedEContent', false); } global $library; if (isset($library)) { $interface->assign('showFavorites', $library->showFavorites); $interface->assign('showRatings', $library->showRatings); $interface->assign('showComments', $library->showComments); } else { $interface->assign('showFavorites', 1); $interface->assign('showRatings', 1); $interface->assign('showComments', 1); } //This code is also in Search/History since that page displays in the My Account menu as well. //It is also in MyList.php and Admin.php if ($user !== false) { $interface->assign('user', $user); // Get My Profile if ($this->catalog->status) { if ($user->cat_username) { $patron = $this->catalog->patronLogin($user->cat_username, $user->cat_password); if (PEAR_Singleton::isError($patron)) { PEAR_Singleton::raiseError($patron); } $profile = $this->catalog->getMyProfile($patron); //global $logger; //$logger->log("Patron profile phone number in MyResearch = " . $profile['phone'], PEAR_LOG_INFO); if (!PEAR_Singleton::isError($profile)) { $interface->assign('profile', $profile); } } } //Figure out if we should show a link to classic opac to pay holds. $ecommerceLink = $configArray['Site']['ecommerceLink']; $homeLibrary = Library::getLibraryForLocation($user->homeLocationId); if (strlen($ecommerceLink) > 0 && isset($homeLibrary) && $homeLibrary->showEcommerceLink == 1) { $interface->assign('showEcommerceLink', true); $interface->assign('minimumFineAmount', $homeLibrary->minimumFineAmount); if ($homeLibrary->payFinesLink == 'default') { $interface->assign('ecommerceLink', $ecommerceLink); } else { $interface->assign('ecommerceLink', $homeLibrary->payFinesLink); } $interface->assign('payFinesLinkText', $homeLibrary->payFinesLinkText); } else { $interface->assign('showEcommerceLink', false); $interface->assign('minimumFineAmount', 0); } //Load a list of lists $lists = array(); if ($user->disableRecommendations == 0) { $lists[] = array('name' => 'Recommended For You', 'url' => '/MyResearch/SuggestedTitles', 'id' => 'suggestions'); } $tmpList = new User_list(); $tmpList->user_id = $user->id; $tmpList->orderBy("title ASC"); $tmpList->find(); if ($tmpList->N > 0) { while ($tmpList->fetch()) { $lists[$tmpList->id] = array('name' => $tmpList->title, 'url' => '/MyResearch/MyList/' . $tmpList->id, 'id' => $tmpList->id); } } else { $lists[-1] = array('name' => "My Favorites", 'url' => '/MyResearch/MyList/-1', 'id' => -1); } $interface->assign('lists', $lists); // Get My Tags $tagList = $user->getTags(); $interface->assign('tagList', $tagList); } }
/** * Get Save Statuses * * This is responsible for printing the save status for a collection of * records in XML format. * * @access public * @author Chris Delis <*****@*****.**> */ function GetSaveStatuses() { require_once ROOT_DIR . '/services/MyResearch/lib/User.php'; require_once ROOT_DIR . '/services/MyResearch/lib/Resource.php'; global $configArray; // check if user is logged in if (!($user = UserAccount::isLoggedIn())) { echo "<result>Unauthorized</result>"; return; } for ($i = 0;; $i++) { if (!isset($_GET['id' . $i])) { break; } $id = $_GET['id' . $i]; echo '<item id="' . htmlspecialchars($id) . '">'; // Check if resource is saved to favorites $resource = new Resource(); $resource->record_id = $id; if ($resource->find(true)) { $data = $user->getSavedData($id, $resource->source); if ($data) { echo '<result>'; // Convert the resource list into JSON so it's easily readable // by the calling Javascript code. Note that we have to entity // encode it so it can embed cleanly inside our XML response. $json = array(); foreach ($data as $list) { $listData = new User_list(); $listData->id = $list->list_id; $link = ''; if ($listData->find(true)) { if ($listData->user_id == $user->id || $listData->public) { $link = $configArray['Site']['path'] . '/MyResearch/MyList/' . $listData->id; } } $json[] = array('id' => $list->id, 'title' => $list->list_title, 'link' => $link); } echo htmlspecialchars(json_encode($json)); echo '</result>'; } else { echo '<result>False</result>'; } } else { echo '<result>False</result>'; } echo '</item>'; } }
/** * Get data and output in JSON * * @return void * @access public */ public function saveListData() { global $user; if (!($user = UserAccount::isLoggedIn())) { $this->output("", JSON::STATUS_NEED_AUTH); return; } // Fetch List object $list = User_list::staticGet($_REQUEST['listId']); // Ensure user has permissions to edit the list if ($list->user_id != $user->id) { $this->output("", JSON::STATUS_NEED_AUTH); return; } // Save data and return status to AJAX script // Title if (isset($_REQUEST['title_change'])) { if (!$list->updateListTitle($_REQUEST['title_change'])) { $error = true; } // List Description } else { if (isset($_REQUEST['description_change'])) { if (!$list->updateListDescription($_REQUEST['description_change'])) { $error = true; } // Visibility } else { if (isset($_REQUEST['publicity_change'])) { if (!$list->updateListPublicity($_REQUEST['publicity_change'])) { $error = true; } // Add list } else { if (isset($_REQUEST['list_add'])) { $value = $_REQUEST['list_add']; $list = new User_list(); $list->title = $value; $list->user_id = $user->id; if ($list->insert() && $list->find()) { $this->output("{$list->id}", JSON::STATUS_OK); return; } else { $error = true; } // Entry description } else { if (isset($_REQUEST['entry_description_change'])) { $resource = new Resource(); unset($resource->source); $resource->record_id = $_REQUEST['recordId']; $resource->find(true); // Save resource if (!$user->addResource($resource, $list, '', $_REQUEST['entry_description_change'])) { $error = true; } } } } } } if ($error) { $this->output("An error has occurred", JSON::STATUS_ERROR); } else { $this->output("", JSON::STATUS_OK); } }
/** * Save the records * * @return array A list of successfully saved record ids and the list id * @access public */ public function saveRecord() { // Fail if the user is not logged in: if (!$this->user || !isset($_POST['ids'])) { return false; } $list = new User_list(); if ($_REQUEST['list'] != '') { $list->id = $_REQUEST['list']; } else { $list->user_id = $this->user->id; $list->title = "My Favorites"; $list->insert(); } // Remember that the list was used so it can be the default in future // dialog boxes: $list->rememberLastUsed(); foreach ($_POST['ids'] as $id) { $resource = new Resource(); $resource->record_id = $id; $resource->source = $_REQUEST['service']; if (!$resource->find(true)) { $resource->insert(); } preg_match_all('/"[^"]*"|[^ ]+/', $_REQUEST['mytags'], $tagArray); $result['details'][$id] = $this->user->addResource($resource, $list, $tagArray[0], false, false); } $result['list'] = $list->id; return $result; }
/** * Anonymize user account by updating username to a random string * and setting other user object fields (besides id) to their default values. * User comments are preserved. Catalog accounts, due date reminders, * saved searches and lists are deleted. * * @return boolean True on success */ public function anonymizeAccount() { $conn = $this->getDatabaseConnection(); $res = $conn->query("START TRANSACTION"); try { // Delete catalog accounts $account = new User_account(); $account->user_id = $this->id; if ($account->find(false)) { while ($account->fetch()) { $account->delete(); } } // Delete due date reminders $reminder = new Due_date_reminder(); $reminder->user_id = $this->id; if ($reminder->find(false)) { while ($reminder->fetch()) { $reminder->delete(); } } // Delete lists (linked user_resource objects cascade) $list = new User_list(); $list->user_id = $this->id; if ($list->find(false)) { while ($list->fetch()) { $list->delete(); } } // Delete saved searches $search = new SearchEntry(); $search->user_id = $this->id; if ($search->find(false)) { while ($search->fetch()) { $search->delete(); } } // Anonymize user object $this->username = '******' . uniqid(); $this->password = ''; $this->firstname = ''; $this->lastname = ''; $this->email = ''; $this->cat_username = '******'; $this->cat_password = '******'; $this->college = ''; $this->major = ''; $this->home_library = ''; $this->language = ''; $this->due_date_notification = 0; $this->due_date_reminder = 0; $this->authMethod = 'null'; $this->update(); } catch (Exception $e) { $conn->query("ROLLBACK"); throw $e; return false; } $conn->query("COMMIT"); return true; }
function saveRecord() { if ($this->user) { $list = new User_list(); if ($_GET['list'] != '') { $list->id = $_GET['list']; $list->find(true); } else { $list->user_id = $this->user->id; $list->title = "My Favorites"; $list->insert(); } $resource = new Resource(); $resource->record_id = $_GET['id']; if (isset($_GET['service'])) { $resource->source = $_GET['service']; } else { $resource->source = $_GET['source']; } if (!$resource->find(true)) { PEAR_Singleton::raiseError(new PEAR_Error('Unable find a resource for that title.')); } preg_match_all('/"[^"]*"|[^,]+/', $_GET['mytags'], $tagArray); $this->user->addResource($resource, $list, $tagArray[0], $_GET['notes']); } else { return false; } }