コード例 #1
0
ファイル: User.php プロジェクト: bharatm/NDL-VuFind
 /**
  * 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;
 }
コード例 #2
0
ファイル: MyList.php プロジェクト: bryandease/VuFind-Plus
 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');
 }
コード例 #3
0
ファイル: User.php プロジェクト: bryandease/VuFind-Plus
 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;
 }
コード例 #4
0
ファイル: ListAPI.php プロジェクト: bryandease/VuFind-Plus
 /**
  * Get all lists that a particular user has created.
  * includes id, title, description, number of titles, and whether or not the list is public
  */
 function getUserLists()
 {
     $username = $_REQUEST['username'];
     $password = $_REQUEST['password'];
     global $user;
     $user = UserAccount::validateAccount($username, $password);
     if (!isset($_REQUEST['username']) || !isset($_REQUEST['password'])) {
         return array('success' => false, 'message' => 'The username and password must be provided to load lists.');
     }
     $userId = $user->id;
     $list = new User_list();
     $list->user_id = $userId;
     $list->find();
     $results = array();
     if ($list->N > 0) {
         while ($list->fetch()) {
             $query = "SELECT count(resource_id) as numTitles FROM user_resource where list_id = " . $list->id;
             $numTitleResults = mysql_query($query);
             $numTitles = mysql_fetch_assoc($numTitleResults);
             $results[] = array('id' => $list->id, 'title' => $list->title, 'description' => $list->description, 'numTitles' => $numTitles['numTitles'], 'public' => $list->public == 1);
         }
     }
     require_once ROOT_DIR . '/services/MyResearch/lib/Suggestions.php';
     $suggestions = Suggestions::getSuggestions($userId);
     if (count($suggestions) > 0) {
         $results[] = array('id' => 'recommendations', 'title' => 'User Recommendations', 'description' => 'Personalized Recommendations based on ratings.', 'numTitles' => count($suggestions), 'public' => false);
     }
     return array('success' => true, 'lists' => $results);
 }
コード例 #5
0
ファイル: MyResearch.php プロジェクト: bryandease/VuFind-Plus
 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);
     }
 }