From 1d059dc06d24e02c858c43d70eaa70453d51cdff Mon Sep 17 00:00:00 2001 From: mensonge Date: Thu, 11 Sep 2008 16:51:00 +0000 Subject: New Feature: add users admin page with delete function git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@146 b3834d28-1941-0410-a4f8-b48e95affb8f --- services/bookmark2tagservice.php | 20 ++++++++++++++++++++ services/bookmarkservice.php | 11 +++++++++++ services/tag2tagservice.php | 14 ++++++++------ services/userservice.php | 29 +++++++++++++++++++++++++++++ templates/toolbar.inc.php | 5 +++++ templates/userlist.tpl.php | 34 ++++++++++++++++++++++++++++++++++ 6 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 templates/userlist.tpl.php diff --git a/services/bookmark2tagservice.php b/services/bookmark2tagservice.php index 121ba8d..31ae4d2 100644 --- a/services/bookmark2tagservice.php +++ b/services/bookmark2tagservice.php @@ -179,6 +179,26 @@ class Bookmark2TagService { return true; } + /* Allow deletion in admin page */ + function deleteTagsForUser($uId) { + $qmask = 'DELETE FROM %s USING %s, %s WHERE %s.bId = %s.bId AND %s.uId = %d'; + $query = sprintf($qmask, + $this->getTableName(), + $this->getTableName(), + $GLOBALS['tableprefix'].'bookmarks', + $this->getTableName(), + $GLOBALS['tableprefix'].'bookmarks', + $GLOBALS['tableprefix'].'bookmarks', + $uId); + + if (!($dbresult =& $this->db->sql_query($query))) { + message_die(GENERAL_ERROR, 'Could not delete tags', '', __LINE__, __FILE__, $query, $this->db); + return false; + } + + return true; + } + function &getTagsForBookmark($bookmarkid) { if (!is_int($bookmarkid)) { message_die(GENERAL_ERROR, 'Could not get tags (invalid bookmarkid)', '', __LINE__, __FILE__, $query); diff --git a/services/bookmarkservice.php b/services/bookmarkservice.php index 2cd42e2..150abc3 100644 --- a/services/bookmarkservice.php +++ b/services/bookmarkservice.php @@ -416,6 +416,17 @@ class BookmarkService { return true; } + function deleteBookmarksForUser($uId) { + $query = 'DELETE FROM '. $GLOBALS['tableprefix'] .'bookmarks WHERE uId = '. intval($uId); + + if (!($dbresult = & $this->db->sql_query($query))) { + message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $query, $this->db); + return false; + } + + return true; + } + function countOthers($address) { if (!$address) { return false; diff --git a/services/tag2tagservice.php b/services/tag2tagservice.php index bf4f866..f24ef79 100644 --- a/services/tag2tagservice.php +++ b/services/tag2tagservice.php @@ -234,15 +234,17 @@ class Tag2TagService { } function removeLinkedTags($tag1, $tag2, $relationType, $uId) { - if($tag1 == $tag2 || strlen($tag1) == 0 || strlen($tag2) == 0 - || ($relationType != ">" && $relationType != "=")) { + if(($tag1 != '' && $tag1 == $tag2) || + ($relationType != ">" && $relationType != "=" && $relationType != "") || + ($tag1 == '' && $tag2 == '' && $relationType == '' && $uId == '')) { return false; } $query = 'DELETE FROM '. $this->getTableName(); - $query.= ' WHERE tag1 = "'. $tag1 .'"'; - $query.= ' AND tag2 = "'. $tag2 .'"'; - $query.= ' AND relationType = "'. $relationType .'"'; - $query.= ' AND uId = "'. $uId .'"'; + $query.= ' WHERE 1=1'; + $query.= strlen($tag1)>0 ? ' AND tag1 = "'. $tag1 .'"' : ''; + $query.= strlen($tag2)>0 ? ' AND tag2 = "'. $tag2 .'"' : ''; + $query.= strlen($relationType)>0 ? ' AND relationType = "'. $relationType .'"' : ''; + $query.= strlen($uId)>0 ? ' AND uId = "'. $uId .'"' : ''; if (!($dbresult =& $this->db->sql_query($query))) { message_die(GENERAL_ERROR, 'Could not remove tag relation', '', __LINE__, __FILE__, $query, $this->db); diff --git a/services/userservice.php b/services/userservice.php index 3d2058f..f620735 100644 --- a/services/userservice.php +++ b/services/userservice.php @@ -336,6 +336,35 @@ class UserService { return true; } + function getAllUsers ( ) { + $query = 'SELECT * FROM '. $this->getTableName(); + + if (! ($dbresult =& $this->db->sql_query($query)) ) { + message_die(GENERAL_ERROR, 'Could not get users', '', __LINE__, __FILE__, $query, $this->db); + return false; + } + + $rows = array(); + + while ( $row = $this->db->sql_fetchrow($dbresult) ) { + $rows[] = $row; + } + + return $rows; + } + + function deleteUser($uId) { + $query = 'DELETE FROM '. $this->getTableName() .' WHERE uId = '. intval($uId); + + if (!($dbresult = & $this->db->sql_query($query))) { + message_die(GENERAL_ERROR, 'Could not delete user', '', __LINE__, __FILE__, $query, $this->db); + return false; + } + + return true; + } + + function sanitisePassword($password) { return sha1(trim($password)); } diff --git a/templates/toolbar.inc.php b/templates/toolbar.inc.php index 593ee0f..92d8d59 100644 --- a/templates/toolbar.inc.php +++ b/templates/toolbar.inc.php @@ -4,6 +4,7 @@ if ($userservice->isLoggedOn()) { $cUser = $userservice->getCurrentUser(); $cUserId = $userservice->getCurrentUserId(); $cUsername = $cUser[$userservice->getFieldName('username')]; + $isAdmin = $userservice->isAdmin($cUser[$userservice->getFieldname('primary')]); ?> getCurrentUser(); +$currentUserID = $userservice->getCurrentUserId(); +$currentUsername = $currentUser[$userservice->getFieldName('username')]; + + +$this->includeTemplate($GLOBALS['top_include']); + +echo '
    '; + +foreach(array_keys($users) as $key) { + + echo '
  1. '."\n"; + + echo ''; + + if($users[$key][$userservice->getFieldName('username')] != $currentUsername) { + echo '
    '; + echo ''.T_('Delete').''; + echo '
    '; + } + + echo '
  2. '."\n"; +} + +$this->includeTemplate('sidebar.tpl'); +$this->includeTemplate($GLOBALS['bottom_include']); + +?> -- cgit v1.2.3