showuser_list.php3 4.94 KB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1
2
3
4
5
6
<?php
include("defs.php3");

#
# Standard Testbed Header
#
7
PAGEHEADER("User List");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21

#
#
# Only known and logged in users allowed.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);

#
# Admin users can see all users, while normal users can only see
# users in their projects.
#
$isadmin = ISADMIN($uid);

Leigh B. Stoller's avatar
Leigh B. Stoller committed
22
23
if (! $isadmin) {
    USERERROR("You do not have permission to view the user list!", 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
24
}
25
26
if (!isset($showactive))
    $showactive = 0;
27
28
if (!isset($sortby))
    $sortby = "name";
29
30
    
if (!$showactive) {
31
    echo "<b><a href='showuser_list.php3?showactive=1&sortby=$sortby'>
32
                Show Logged in Users</a>
33
34
35
          </b><br><br>\n";
}
else {
36
    echo "<b><a href='showuser_list.php3?showactive=0&sortby=$sortby'>
37
                Show All Users</a>
38
          </b><br><br>\n";
39
}
40
41
42
43

if (! strcmp($sortby, "name"))
    $order = "u.usr_name";
elseif (! strcmp($sortby, "uid"))
44
    $order = "u.uid";
45
46
47
48
elseif (! strcmp($sortby, "widle"))
    $order = "webidle DESC";
elseif (! strcmp($sortby, "uidle"))
    $order = "usersidle DESC";
49
50
else {
    $order = "u.usr_name";
51
52
}

53
if ($showactive) {
54
    $query_result =
55
56
57
58
59
60
61
62
63
64
65
	DBQueryFatal("SELECT u.*, ".
		     " IF(ll.time, ".
		     "    TO_DAYS(CURDATE()) - TO_DAYS(ll.time), ".
		     "    TO_DAYS(CURDATE()) - TO_DAYS(u.usr_created)) ".
		     "   as webidle, ".
		     " TO_DAYS(CURDATE()) - TO_DAYS(ull.date) as usersidle ".
		     "FROM users as u ".
		     "left join login as l on u.uid=l.uid ".
		     "left join userslastlogin as ull on u.uid=ull.uid ".
		     "left join lastlogin as ll on u.uid=ll.uid ".
		     "where l.timeout>=unix_timestamp() ".
66
		     "order by $order");
67
68
69
}
else {
    $query_result =
70
71
72
73
74
75
76
77
78
79
	DBQueryFatal("SELECT u.*, ".
		     " IF(ll.time, ".
		     "    TO_DAYS(CURDATE()) - TO_DAYS(ll.time), ".
		     "    TO_DAYS(CURDATE()) - TO_DAYS(u.usr_created)) ".
		     "   as webidle, ".
		     " TO_DAYS(CURDATE()) - TO_DAYS(ull.date) as usersidle ".
		     "FROM users as u ".
		     "left join userslastlogin as ull on u.uid=ull.uid ".
		     "left join lastlogin as ll on u.uid=ll.uid ".
		     "order by $order");
80
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
81

82
if (($count = mysql_num_rows($query_result)) == 0) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
83
    USERERROR("There are no users!", 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
84
85
}

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
if ($showactive) {
    echo "<center>
          There are $count users logged in.
          </center><br>\n";
}
else {
    echo "<center>
          There are $count users.
          </center><br>\n";
}

#
# Grab the project lists and create a hash of lists, per user.
# One query instead of hundreds.
#
$projmemb_result =
    DBQueryFatal("select distinct uid,pid from group_membership order by uid");

$projmemb_array = array();

while ($row = mysql_fetch_array($projmemb_result)) {
    $uid   = $row[0];
    $pid   = $row[1];

    $projmemb_array[$uid][] = $pid;
}

113
echo "<table width=\"100%\" border=2 cellpadding=1 cellspacing=0
Leigh B. Stoller's avatar
Leigh B. Stoller committed
114
115
116
       align='center'>\n";

echo "<tr>
117
          <td>&nbsp</td>
118
119
120
121
          <td><a href='showuser_list.php3?showactive=$showactive&sortby=uid'>
                 UID</a></td>
          <td><a href='showuser_list.php3?showactive=$showactive&sortby=name'>
                 Name</a></td>
122
          <td>Projects</td>
123
124
125
126
          <td><a href='showuser_list.php3?showactive=$showactive&sortby=widle'>
                 Web<br>Idle</a></td>
          <td><a href='showuser_list.php3?showactive=$showactive&sortby=uidle'>
                 Users<br>Idle</a></td>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
127
128

#
129
# Admin users get a "delete" and a "modify" option.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
130
131
# 
if ($isadmin) {
132
133
    echo "<td align=center>Modify</td>\n";
    echo "<td align=center>Delete</td>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
134
}
135

Leigh B. Stoller's avatar
Leigh B. Stoller committed
136
137
138
139
140
echo "</tr>\n";

while ($row = mysql_fetch_array($query_result)) {
    $thisuid  = $row[uid];
    $name     = $row[usr_name];
141
    $status   = $row[status];
142
    $unix_uid = $row[unix_uid];
143
144
    $webidle  = $row[webidle];
    $usersidle= $row[usersidle];
Leigh B. Stoller's avatar
Leigh B. Stoller committed
145

146
147
148
149
150
151
152
153
154
155
156
    echo "<tr>\n";

    if (strcmp($status, "active") == 0 ||
	strcmp($status, "unverified") == 0) {
	echo "<td align=center><img alt=\"Y\" src=\"greenball.gif\"></td>\n";
    }
    else {
	echo "<td align=center><img alt=\"N\" src=\"redball.gif\"></td>\n";
    }

    echo "<td><A href='showuser.php3?target_uid=$thisuid'>$thisuid</A></td>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
157
158
              <td>$name</td>\n";

159
160
161
162
163
164
    # List of projects.
    reset($projmemb_array);
    if (isset($projmemb_array[$thisuid])) {
	echo "<td> ";
	while (list ($idx, $pid) = each($projmemb_array[$thisuid])) {
	    echo "<A href='showproject.php3?pid=$pid'>$pid</A>";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
165
	    if ($idx != (count($projmemb_array[$thisuid]) - 1))
166
167
168
		echo ", ";
	}
	echo "</td>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
169
170
171
172
    }
    else {
	    echo "<td>--</td>\n";
    }
173
    
174
    echo "<td>$webidle</td>\n";
175

176
    if (! $usersidle)
177
	echo "<td>&nbsp</td>\n";
178
179
    else {
	echo "<td>$usersidle</td>\n";
180
181
    }

Leigh B. Stoller's avatar
Leigh B. Stoller committed
182
    if ($isadmin) {
183
	echo "<td align=center><A href='moduserinfo.php3?target_uid=$thisuid'>
184
                     <img alt=\"O\" src=\"blueball.gif\"></A></td>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
185
	echo "<td align=center><A href='deleteuser.php3?target_uid=$thisuid'>
186
                     <img alt=\"X\" src=\"redball.gif\"></A></td>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
187
188
189
190
191
192
193
194
195
196
    }
    echo "</tr>\n";
}
echo "</table>\n";

#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>