Revision [7347]

This is an old revision of UserAdmin made by DarTar on 2005-04-18 08:45:03.

 

User Administration Module

Last edited by DarTar:
Updating links and changelog
Mon, 18 Apr 2005 08:45 UTC [diff]


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:


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


Show records per page :: Search user:
[Records (206): 1-10 | 11-20 (sorted by: name, asc )]

Name Email Signup Date/Time Owned Modified Comments Actions
AbA xxxx@xxx.xx (2004-10-27 15:39:25)
(1)
(1)
(3)
delete :: feedback
AdmiN xxxx@xxx.xx (2004-12-01 06:45:56)
(0)
(0)
(0)
delete :: feedback
AdrianB xxxx@xxx.xx (2004-05-19 15:48:37)
(1)
(4)
(0)
delete :: feedback
AHerdOfTurtles xxxx@xxx.xx (2004-09-18 19:42:39)
(1)
(9)
(4)
delete :: feedback
AlekAndreev xxxx@xxx.xx (2004-11-01 20:06:31)
(0)
(0)
(0)
delete :: feedback
AlessandroRonchi xxxx@xxx.xx (2004-10-21 13:12:36)
(0)
(0)
(0)
delete :: feedback
AlexM xxxx@xxx.xx (2004-11-20 06:02:39)
(0)
(0)
(0)
delete :: feedback
AlleyCat xxxx@xxx.xx (2004-11-21 18:23:19)
(0)
(0)
(0)
delete :: feedback
AndreaRossato xxxx@xxx.xx (2004-07-19 11:03:42)
(4)
(25)
(7)
delete :: feedback
AndrewEddie xxxx@xxx.xx (2004-10-12 22:23:32)
(1)
(3)
(0)
delete :: feedback



Current features (2004-11-22):

Files needed (2004-09-16):



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");
}
?>



CategoryUserContributions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki