Revision [8695]
This is an old revision of UserAdmin made by JavaWoman on 2005-05-29 12:24:41.
User Administration Module
I've started writing some code for a user administration module. I think this might be interesting for wikka-based projects with a large number of registered users.
This action will enable Wikka administrators (or, in the future, users belonging to an Admin group) to have access to several user management functions from a single page:
- Display a pageable, sortable and searchable list of registered users -- done;
- Perform specific actions on single users, like:
- delete users (forthcoming: see this RemovingUsers discussion);
- add users - in case the registration of a page is turned off, but you want to add a user
- noted, good idea -- DarTar
- send user feedback -- done;
- rename users
- If anyone is interested, running through the seven tables and updating every instance of your old wiki name to your new wiki name will effectively change your name throughout the wiki. copied from comment on the homepage. --NilsLindenberg
- manage user privileges (forthcoming);
- Display user's owned pages -- done;
- Display user's comments -- done.
- Display user's changes -- done;
- other...
The code below (to be saved as actions/useradmin.php and used as {{useradmin}} ) is just a very first draft. Contributions and improvements are welcome (especially to make the code lighter).
-- DarTar
Here's a preview of the interface (email addresses are masked for privacy reasons)
User Administration
[Records (206): 1-10 | 11-20 (sorted by: name, asc )]
Name | Signup Date/Time | Owned | Modified | Comments | Actions | |
---|---|---|---|---|---|---|
AbA | xxxx@xxx.xx | (2004-10-27 15:39:25) | ||||
AdmiN | xxxx@xxx.xx | (2004-12-01 06:45:56) | ||||
AdrianB | xxxx@xxx.xx | (2004-05-19 15:48:37) | ||||
AHerdOfTurtles | xxxx@xxx.xx | (2004-09-18 19:42:39) | ||||
AlekAndreev | xxxx@xxx.xx | (2004-11-01 20:06:31) | ||||
AlessandroRonchi | xxxx@xxx.xx | (2004-10-21 13:12:36) | ||||
AlexM | xxxx@xxx.xx | (2004-11-20 06:02:39) | ||||
AlleyCat | xxxx@xxx.xx | (2004-11-21 18:23:19) | ||||
AndreaRossato | xxxx@xxx.xx | (2004-07-19 11:03:42) | ||||
AndrewEddie | xxxx@xxx.xx | (2004-10-12 22:23:32) |
Current features (2004-11-22):
- users can be sorted by different fields (click on table header to reverse sort order), searched and paged;
- if the current user is not an administrator, then the lastuser.php action is displayed
- feedback can be sent to single users.
- displays pages owned by each user.
- displays pages changed by each user.
- displays pages commented by each user.
Files needed (2004-09-16):
- actions/useradmin.php: see code on this page;
- FeedbackActionUpgrade actions/userfeedback.php (enhanced version of FeedbackAction); 2005-04-18 - action parameter support added
- UserPagesAction actions/userpages.php (enhanced version of mypages.php);2005-04-18 - action parameter support added
- UserChangesAction actions/userchanges.php (enhanced version of mychanges.php); 2005-04-18 - action parameter support added
- UserCommentsAction actions/usercomments.php (new action); 2004-11-23 - RewriteRules bug fixed
actions/useradmin.php
<?php
// USER ADMINISTRATION MODULE
// Last Updated: 2004-11-11
// Version 1.0
// Displays to the Wikka admins a list of registered users
// * Users can be sorted by different fields, searched and paged
// * For each user, full statistics are shown with the number of commented, created and modified pages
// * Specific actions (delete/send feedback) can be performed on single users
// * If the current user is not an administrator, then the lastuser action is displayed instead
// admin only code
if ($this->IsAdmin($this->GetUser())) {
if ($_GET["action"] == "feedback" || $_REQUEST["mail"]) {
echo $this->Action("userfeedback");
} else if ($_GET["action"] == "owned") {
echo $this->Action("userpages");
} else if ($_GET["action"] == "changes") {
echo $this->Action("userchanges");
} else if ($_GET["action"] == "comments") {
echo $this->Action("usercomments");
} else {
// pager defaults
// limit records per page
$l = (!$_POST["l"])? $_GET["l"] : $_POST["l"];
if (!$_POST["l"] && !$_GET["l"]) $l = 10;
// sort field
$sort = (!$_GET["sort"])? "signuptime" : $_GET["sort"];
// sort order
$d = (!$_GET["d"])? "desc" : $_GET["d"];
// start record
$s = (!$_GET["s"])? "0" : $_GET["s"];
// search results
$where = ($_POST["search"])? "WHERE name LIKE \"%".$_POST["search"]."%\"" : "";
echo $this->Format("==== User Administration ==== --- ---");
// 1. Get total number of users
$users = $this->LoadSingle("select count(*) as n FROM ".$this->config["table_prefix"]."users ".$where);
$numusers = $users['n'];
// 2. Display pager form
$form = $this->FormOpen("","","post");
$form .= "Show\n<select name=\"l\" onChange=\"form.submit()\">\n";
for ($rec=10; $rec < ($numusers+10); $rec+=10) {
$selected = ($l == $rec)? "selected" : "";
$form .= "<option value=\"".$rec."\" ".$selected.">".$rec."</option>\n";
}
$form .= "</select> records per page :: \n".
"Search user: <input type =\"text\" name=\"search\" size=\"20\" maxlength=\"50\" value=\"".$_POST["search"]."\"/>\n".
$this->FormClose();
echo $form;
if($s > 0)
$prev = "<a href=\"" .$this->Href("","","l=".$l."&sort=".$sort."&d=".$d."&s=".($s-$l))."\">".($s-$l+1)."-".$s."</a> | ";
if($numusers > ($s + $l))
$next = " | <a href=\"".$this->Href("","","l=".$l."&sort=".$sort."&d=".$d."&s=".($s+$l))."\">".($s+$l+1)."-".($s+2*$l)."</a>";
echo "[Records (".$numusers."): ".$prev."<b>".($s+1)."-".($s+$l)."</b>".$next." (sorted by: <em>".$sort.", ".$d."</em> )]<br /><br />\n";
// get user data
$userdata = $this->LoadAll("SELECT name, email, signuptime FROM ".$this->config["table_prefix"]."users ".
$where." ORDER BY ".$sort." ".$d." limit ".$s.", ".$l);
if ($userdata) {
// print table headers
$htmlout = "<table width=\"100%\" border=\"1px\">\n".
" <tr>\n".
" <th><a href=\"".$this->Href("","", (($sort == "name" && $d == "asc")? "l=".$l."&sort=name&d=desc" :
"l=".$l."&sort=name&d=asc"))."\">Name</a></th>\n".
" <th><a href=\"".$this->Href("","", (($sort == "email" && $d == "asc")? "l=".$l."&sort=email&d=desc" :
"l=".$l."&sort=email&d=asc"))."\">Email</a></th>\n".
" <th><a href=\"".$this->Href("","", (($sort == "signuptime" && $d == "desc")? "l=".$l."&sort=signuptime&d=asc" :
"l=".$l.""))."\">Signup Date/Time</a></th>\n".
" <th>Owned</th>\n".
" <th>Modified</th>\n".
" <th>Comments</th>\n".
" <th>Actions</th>\n".
" </tr>\n";
// print user table
foreach($userdata as $user) {
$htmlout .= " <tr>\n";
$num = $this->LoadSingle("SELECT COUNT(*) AS n FROM ".$this->config["table_prefix"].
"pages WHERE owner='".$user["name"]."' AND latest = 'Y'");
$numchanges = $this->LoadSingle("SELECT COUNT(*) AS m FROM ".$this->config["table_prefix"].
"pages WHERE user='".$user["name"]."'");
$numcomments = $this->LoadSingle("SELECT COUNT(*) AS q FROM ".$this->config["table_prefix"].
"comments WHERE user='".$user["name"]."'");
$htmlout .= " <td>".$this->Link($user["name"])."</td>\n <td>".$user["email"].
"</td>\n<td>(".$user["signuptime"].")</td>\n <td><center />".
"(<a href=\"".$this->Href("","","user=".$user["name"]."&action=owned")."\">".$num["n"]."</a>)"."</td>\n <td><center />".
"(<a href=\"".$this->Href("","","user=".$user["name"]."&action=changes")."\">".$numchanges["m"]."</a>)</td>\n <td><center />".
"(<a href=\"".$this->Href("","","user=".$user["name"]."&action=comments")."\">".$numcomments["q"]."</a>)</td>\n".
"<td><center />delete :: <a href=\"".$this->Href("","","user=".$user["name"]."&action=feedback")."\">feedback</a></td>\n";
$htmlout .= " </tr>\n";
}
$htmlout .= "</table>\n";
print($htmlout);
} else {
echo "<p><span class=\"error\">Sorry, there are no users matching</span> <strong>\"".$_POST["search"]."\"</strong></p>";
}
}
} else {
// user is not admin
echo $this->Action("lastusers");
}
?>
// USER ADMINISTRATION MODULE
// Last Updated: 2004-11-11
// Version 1.0
// Displays to the Wikka admins a list of registered users
// * Users can be sorted by different fields, searched and paged
// * For each user, full statistics are shown with the number of commented, created and modified pages
// * Specific actions (delete/send feedback) can be performed on single users
// * If the current user is not an administrator, then the lastuser action is displayed instead
// admin only code
if ($this->IsAdmin($this->GetUser())) {
if ($_GET["action"] == "feedback" || $_REQUEST["mail"]) {
echo $this->Action("userfeedback");
} else if ($_GET["action"] == "owned") {
echo $this->Action("userpages");
} else if ($_GET["action"] == "changes") {
echo $this->Action("userchanges");
} else if ($_GET["action"] == "comments") {
echo $this->Action("usercomments");
} else {
// pager defaults
// limit records per page
$l = (!$_POST["l"])? $_GET["l"] : $_POST["l"];
if (!$_POST["l"] && !$_GET["l"]) $l = 10;
// sort field
$sort = (!$_GET["sort"])? "signuptime" : $_GET["sort"];
// sort order
$d = (!$_GET["d"])? "desc" : $_GET["d"];
// start record
$s = (!$_GET["s"])? "0" : $_GET["s"];
// search results
$where = ($_POST["search"])? "WHERE name LIKE \"%".$_POST["search"]."%\"" : "";
echo $this->Format("==== User Administration ==== --- ---");
// 1. Get total number of users
$users = $this->LoadSingle("select count(*) as n FROM ".$this->config["table_prefix"]."users ".$where);
$numusers = $users['n'];
// 2. Display pager form
$form = $this->FormOpen("","","post");
$form .= "Show\n<select name=\"l\" onChange=\"form.submit()\">\n";
for ($rec=10; $rec < ($numusers+10); $rec+=10) {
$selected = ($l == $rec)? "selected" : "";
$form .= "<option value=\"".$rec."\" ".$selected.">".$rec."</option>\n";
}
$form .= "</select> records per page :: \n".
"Search user: <input type =\"text\" name=\"search\" size=\"20\" maxlength=\"50\" value=\"".$_POST["search"]."\"/>\n".
$this->FormClose();
echo $form;
if($s > 0)
$prev = "<a href=\"" .$this->Href("","","l=".$l."&sort=".$sort."&d=".$d."&s=".($s-$l))."\">".($s-$l+1)."-".$s."</a> | ";
if($numusers > ($s + $l))
$next = " | <a href=\"".$this->Href("","","l=".$l."&sort=".$sort."&d=".$d."&s=".($s+$l))."\">".($s+$l+1)."-".($s+2*$l)."</a>";
echo "[Records (".$numusers."): ".$prev."<b>".($s+1)."-".($s+$l)."</b>".$next." (sorted by: <em>".$sort.", ".$d."</em> )]<br /><br />\n";
// get user data
$userdata = $this->LoadAll("SELECT name, email, signuptime FROM ".$this->config["table_prefix"]."users ".
$where." ORDER BY ".$sort." ".$d." limit ".$s.", ".$l);
if ($userdata) {
// print table headers
$htmlout = "<table width=\"100%\" border=\"1px\">\n".
" <tr>\n".
" <th><a href=\"".$this->Href("","", (($sort == "name" && $d == "asc")? "l=".$l."&sort=name&d=desc" :
"l=".$l."&sort=name&d=asc"))."\">Name</a></th>\n".
" <th><a href=\"".$this->Href("","", (($sort == "email" && $d == "asc")? "l=".$l."&sort=email&d=desc" :
"l=".$l."&sort=email&d=asc"))."\">Email</a></th>\n".
" <th><a href=\"".$this->Href("","", (($sort == "signuptime" && $d == "desc")? "l=".$l."&sort=signuptime&d=asc" :
"l=".$l.""))."\">Signup Date/Time</a></th>\n".
" <th>Owned</th>\n".
" <th>Modified</th>\n".
" <th>Comments</th>\n".
" <th>Actions</th>\n".
" </tr>\n";
// print user table
foreach($userdata as $user) {
$htmlout .= " <tr>\n";
$num = $this->LoadSingle("SELECT COUNT(*) AS n FROM ".$this->config["table_prefix"].
"pages WHERE owner='".$user["name"]."' AND latest = 'Y'");
$numchanges = $this->LoadSingle("SELECT COUNT(*) AS m FROM ".$this->config["table_prefix"].
"pages WHERE user='".$user["name"]."'");
$numcomments = $this->LoadSingle("SELECT COUNT(*) AS q FROM ".$this->config["table_prefix"].
"comments WHERE user='".$user["name"]."'");
$htmlout .= " <td>".$this->Link($user["name"])."</td>\n <td>".$user["email"].
"</td>\n<td>(".$user["signuptime"].")</td>\n <td><center />".
"(<a href=\"".$this->Href("","","user=".$user["name"]."&action=owned")."\">".$num["n"]."</a>)"."</td>\n <td><center />".
"(<a href=\"".$this->Href("","","user=".$user["name"]."&action=changes")."\">".$numchanges["m"]."</a>)</td>\n <td><center />".
"(<a href=\"".$this->Href("","","user=".$user["name"]."&action=comments")."\">".$numcomments["q"]."</a>)</td>\n".
"<td><center />delete :: <a href=\"".$this->Href("","","user=".$user["name"]."&action=feedback")."\">feedback</a></td>\n";
$htmlout .= " </tr>\n";
}
$htmlout .= "</table>\n";
print($htmlout);
} else {
echo "<p><span class=\"error\">Sorry, there are no users matching</span> <strong>\"".$_POST["search"]."\"</strong></p>";
}
}
} else {
// user is not admin
echo $this->Action("lastusers");
}
?>
CategoryDevelopmentActions CategoryDevelopmentAdmin