/** * Delete a search from the database * * @param SearchEntry $search */ private function deleteSearch($search) { if ($search->saved != 0) { $search->saved = 0; $search->update(); } }
function launch() { global $configArray; global $interface; global $user; $source = $_REQUEST['source']; $sourceId = $_REQUEST['id']; $existingWidget = isset($_REQUEST['widgetId']) ? $_REQUEST['widgetId'] : -1; $widgetName = isset($_REQUEST['widgetName']) ? $_REQUEST['widgetName'] : ''; if ($existingWidget == -1) { $widget = new ListWidget(); $widget->name = $widgetName; if ($user->hasRole('libraryAdmin') || $user->hasRole('contentEditor')) { //Get all widgets for the library $userLibrary = Library::getPatronHomeLibrary(); $widget->libraryId = $userLibrary->libraryId; } else { $widget->libraryId = -1; } $widget->customCss = ''; $widget->autoRotate = 0; $widget->description = ''; $widget->showTitleDescriptions = 1; $widget->onSelectCallback = ''; $widget->fullListLink = ''; $widget->listDisplayType = 'tabs'; $widget->showMultipleTitles = 1; $widget->insert(); } else { $widget = new ListWidget(); $widget->id = $existingWidget; $widget->find(true); } //Make sure to save the search if ($source == 'search') { $searchObject = new SearchEntry(); $searchObject->id = $sourceId; $searchObject->find(true); $searchObject->saved = 1; $searchObject->update(); } //Add the list to the widget $widgetList = new ListWidgetList(); $widgetList->listWidgetId = $widget->id; $widgetList->displayFor = 'all'; $widgetList->source = "{$source}:{$sourceId}"; $widgetList->name = $widgetName; $widgetList->weight = 0; $widgetList->insert(); //Redirect to the widget header("Location: {$path}/Admin/ListWidgets?objectAction=view&id={$widget->id}"); }
/** * Add into the search table (history) * * @access protected */ protected function addToHistory() { global $user; // Get the list of all old searches for this session and/or user $s = new SearchEntry(); /** @var SearchEntry[] $searchHistory */ $searchHistory = $s->getSearches(session_id(), is_object($user) ? $user->id : null); // Duplicate elimination $dupSaved = false; foreach ($searchHistory as $oldSearch) { // Deminify the old search $minSO = unserialize($oldSearch->search_object); $dupSearch = SearchObjectFactory::deminify($minSO); // See if the classes and urls match if (get_class($dupSearch) && get_class($this) && $dupSearch->renderSearchUrl() == $this->renderSearchUrl()) { // Is the older search saved? if ($oldSearch->saved) { // Flag for later $dupSaved = true; // Record the details $this->searchId = $oldSearch->id; $this->savedSearch = true; } else { // Delete this search $oldSearch->delete(); } } } // Save this search unless we found a 'saved' duplicate if (!$dupSaved) { $search = new SearchEntry(); $search->session_id = session_id(); $search->created = date('Y-m-d'); $search->search_object = serialize($this->minify()); $search->insert(); // Record the details $this->searchId = $search->id; $this->savedSearch = false; // Chicken and egg... We didn't know the id before insert $search->search_object = serialize($this->minify()); $search->update(); } }
/** * Process parameters and remove the subscription. * * @return void * @access public */ public function launch() { global $interface; global $configArray; if (!isset($_REQUEST['id']) || !isset($_REQUEST['key']) || !isset($_REQUEST['type'])) { PEAR::raiseError('Can\'t unsubscribe'); return; } $id = $_REQUEST['id']; $key = $_REQUEST['key']; $type = $_REQUEST['type']; // display confirm dialog if (!isset($_REQUEST['confirm']) || !$_REQUEST['confirm']) { $params = array('id' => $id, 'type' => $type, 'key' => $key, 'confirm' => true); $unsubscribeUrl = $configArray['Site']['url'] . '/MyResearch/Unsubscribe?' . http_build_query($params); $interface->assign('unsubscribeUrl', $unsubscribeUrl); $interface->setTemplate('unsubscribe.tpl'); $interface->display('layout.tpl'); } else { $success = false; // scheduled alert if ($type == 'alert') { $search = new SearchEntry(); if ($search->get($id)) { $user = new User(); if ($user->get($search->user_id)) { $secret = $this->_getSecret($user, $id); if ($key === $secret) { $search->schedule = 0; $search->update(); $success = true; } } } } else { if ($type == 'reminder') { // due date reminder $user = new User(); if ($user->get($id)) { $secret = $this->_getSecret($user, $id); if ($key === $secret) { $user->due_date_reminder = 0; $user->update(); $success = true; } } } } if ($success) { $interface->assign('success', true); $interface->setTemplate('unsubscribe.tpl'); $interface->display('layout.tpl'); } else { PEAR::raiseError('Can\'t unsubscribe'); } } }
function deleteSavedSearch() { global $user; $searchId = $_REQUEST['searchId']; $search = new SearchEntry(); $search->id = $searchId; $saveOk = false; if ($search->find(true)) { // Found, make sure this is a search from this user if ($search->session_id == session_id() || $search->user_id == $user->id) { if ($search->saved != 0) { $search->saved = 0; $saveOk = $search->update() !== FALSE; $message = $saveOk ? "Your saved search was deleted successfully." : "Sorry, we could not delete that search for you. It may have already been deleted."; } else { $saveOk = true; $message = "That search is not saved."; } } else { $message = "Sorry, it looks like that search does not belong to you."; } } else { $message = "Sorry, it looks like that search has expired."; } $result = array('result' => $saveOk, 'message' => $message); return $result; }