function launch() { global $interface; global $configArray; $rating = $_REQUEST['rating']; $interface->assign('rating', $rating); $id = $_REQUEST['id']; // Check if user is logged in if (!$this->user) { // Needed for "back to record" link in view-alt.tpl: $interface->assign('id', $id); //Display the login form $login = $interface->fetch('Record/ajax-rate-login.tpl'); header('Content-type: text/plain'); header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); echo json_encode(array('result' => 'true', 'loginForm' => $login)); exit; } if (isset($_GET['submit'])) { global $user; //Save the rating $resource = new Resource(); $resource->record_id = $id; $resource->source = 'VuFind'; if (!$resource->find(true)) { $resource->insert(); } $resource->addRating($rating, $user); return json_encode(array('result' => 'true', 'rating' => $rating)); } }
function SaveTag() { $user = UserAccount::isLoggedIn(); if ($user === false) { return json_encode(array('result' => 'Unauthorized')); } // Create a resource entry for the current ID if necessary (or find the // existing one): $resource = new Resource(); $resource->record_id = $_GET['id']; $resource->source = $_REQUEST['source']; if (!$resource->find(true)) { $resource->insert(); } // Parse apart the tags and save them in association with the resource: preg_match_all('/"[^"]*"|[^,]+/', $_REQUEST['tag'], $words); foreach ($words[0] as $tag) { $tag = trim(strtolower(str_replace('"', '', $tag))); $resource->addTag($tag, $user); } return json_encode(array('result' => 'Done')); }
public function addRecordToReadingHistory($eContentRecord, $user) { //Get the resource for the record require_once ROOT_DIR . '/services/MyResearch/lib/Resource.php'; $resource = new Resource(); $resource->record_id = $eContentRecord->id; $resource->source = 'eContent'; if (!$resource->find(true)) { $resource->title = $eContentRecord->title; $resource->author = $eContentRecord->author; $resource->format = 'EMedia'; $resource->format_category = $eContentRecord->format_category(); $ret = $resource->insert(); } //Check to see if there is an existing entry require_once ROOT_DIR . '/sys/ReadingHistoryEntry.php'; $readingHistoryEntry = new ReadingHistoryEntry(); $readingHistoryEntry->userId = $user->id; $readingHistoryEntry->resourceId = $resource->id; if (!$readingHistoryEntry->find(true)) { $readingHistoryEntry->firstCheckoutDate = date('Y-m-d'); $readingHistoryEntry->lastCheckoutDate = date('Y-m-d'); $readingHistoryEntry->daysCheckedOut = 1; $ret = $readingHistoryEntry->insert(); } else { $readingHistoryEntry->lastCheckoutDate = date('Y-m-d'); $ret = $readingHistoryEntry->update(); } }
/** * 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'] : ''); }
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; } }
/** * 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'); } }
function SaveComment() { require_once ROOT_DIR . '/services/MyResearch/lib/Resource.php'; $user = UserAccount::isLoggedIn(); if ($user === false) { return json_encode(array('result' => 'Unauthorized')); } $resource = new Resource(); $resource->record_id = $_GET['id']; $resource->source = 'eContent'; if (!$resource->find(true)) { $resource->insert(); } $resource->addComment($_REQUEST['comment'], $user, 'eContent'); return json_encode(array('result' => 'true')); }
/** * Export record to RefWorks or EndNote. * * @param array $record Record * @param string $format Export format (refworks or endnote). * @param boolean $render Return rendered template output or the template name? * * @return void|string * @access public */ public function export($record, $format, $render = false) { global $configArray; global $interface; if ($record['author']) { $record['author2'] = array_slice($record['author'], 1); } $formats = null; $tpl = null; if ($format == 'refworks') { // Save record to the database, so that also // restricted records can be retrieved by RefWorks. $resource = new Resource(); $resource->record_id = $record['id']; $resource->source = 'PCI'; if (!$resource->find(true)) { $resource->data = serialize($record); $resource->insert(); } else { $resource->data = serialize($record); $resource->update(); } $exportUrl = $configArray['Site']['url'] . '/PCI/Record?id=' . urlencode($record['id']) . '&export=refworks_data'; $url = $configArray['RefWorks']['url'] . '/express/expressimport.asp'; $url .= '?vendor=' . urlencode($configArray['RefWorks']['vendor']); $url .= '&filter=RefWorks%20Tagged%20Format&url=' . urlencode($exportUrl); header("Location: {$url}"); die; } else { if ($format == 'refworks_data') { header('Content-type: text/plain; charset=utf-8'); if ($record['format']) { $formats = array('article' => 'Journal Article', 'audio' => 'Sound Recording', 'video' => 'Video/ DVD', 'book' => 'Book, Whole', 'book_chapter' => 'Book Section', 'journal' => 'Journal, Electronic'); } $record['format'] = array_key_exists($record['format'], $formats) ? $formats[$record['format']] : 'General'; $tpl = 'PCI/export-refworks.tpl'; } else { if ($format == 'endnote') { header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header('Content-type: application/x-endnote-refer'); header("Content-Disposition: attachment; filename=\"vufind.enw\";"); if ($record['format']) { $formats = array('article' => 'Journal Article', 'audio' => 'Audiovisual Material', 'audio_video' => 'Audiovisual Material', 'video' => 'Audiovisual Material', 'book' => 'Book', 'book_chapter' => 'Book Section', 'conference_proceeding' => 'Conference Proceedings', 'database' => 'Online Database', 'journal' => 'Journal'); } $record['format'] = array_key_exists($record['format'], $formats) ? $formats[$record['format']] : 'Generic'; $tpl = 'PCI/export-endnote.tpl'; } } } if ($tpl) { $interface->assign('record', $record); if ($render) { echo $interface->fetch($tpl); exit; } else { return $tpl; } } return false; }
function save($source = 'eContent') { global $user; // Fail if we don't know what record we're working with: if (!isset($_GET['id'])) { return false; } // Create a resource entry for the current ID if necessary (or find the // existing one): $resource = new Resource(); $resource->record_id = $_GET['id']; $resource->source = $source; if (!$resource->find(true)) { $resource->insert(); } // Parse apart the tags and save them in association with the resource: preg_match_all('/"[^"]*"|[^,]+/', $_REQUEST['tag'], $words); foreach ($words[0] as $tag) { $tag = trim(strtolower(str_replace('"', '', $tag))); $resource->addTag($tag, $user); } // Done -- report success: return true; }
function saveComment() { global $user; // What record are we operating on? if (!isset($_GET['id'])) { return false; } // record already saved as resource? $resource = new Resource(); $resource->record_id = $_GET['id']; $resource->source = 'VuFind'; if (!$resource->find(true)) { $resource->insert(); } $resource->addComment($_REQUEST['comment'], $user); return true; }
/** * 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; }
/** * Save the tag information based on GET parameters. * * @param object $user User that is adding the tag. * * @return bool True on success, false on failure. * @access public */ public static function save($user) { // Fail if we don't know what record we're working with: if (!isset($_GET['id'])) { return false; } $db = ConnectionManager::connectToIndex(); if (!($record = $db->getRecord($_GET['id']))) { return false; } // Create a resource entry for the current ID if necessary (or find the // existing one): $resource = new Resource(); $resource->record_id = $_GET['id']; if (!$resource->find(true)) { $resource->insert(); } // Parse apart the tags and save them in association with the resource: preg_match_all('/"[^"]*"|[^ ]+/', $_REQUEST['tag'], $words); foreach ($words[0] as $tag) { $tag = str_replace('"', '', $tag); $resource->addTag($tag, $user); } // Done -- report success: return true; }
function RateTitle() { require_once ROOT_DIR . '/services/MyResearch/lib/Resource.php'; require_once ROOT_DIR . '/Drivers/marmot_inc/UserRating.php'; global $user; global $analytics; if (!isset($user) || $user == false) { header('HTTP/1.0 500 Internal server error'); return 'Please login to rate this title.'; } $rating = $_REQUEST['rating']; //Save the rating $resource = new Resource(); $resource->record_id = $_GET['id']; $resource->source = 'VuFind'; if (!$resource->find(true)) { $resource->insert(); } $resource->addRating($rating, $user); $analytics->addEvent('User Enrichment', 'Rate Title', $resource->title); /** @var Memcache $memCache */ global $memCache; $memCache->delete('rating_' . $_GET['id']); return $rating; }
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'); }