showuser_list.php3 6.34 KB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5 6
# All rights reserved.
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
7 8 9 10 11
include("defs.php3");

#
# Standard Testbed Header
#
12
PAGEHEADER("User List");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26

#
#
# 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
27 28
if (! $isadmin) {
    USERERROR("You do not have permission to view the user list!", 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
29
}
30

31
echo "<b>Show: <a href='showuser_list.php3?showtype=loggedin'>loggedin</a>,
32
               <a href='showuser_list.php3?showtype=recent'>recent</a>,
33
               <a href='showuser_list.php3?showtype=widearea'>widearea</a>,
34 35 36
               <a href='showuser_list.php3?showtype=homeless'>homeless</a>,
               <a href='showuser_list.php3?showtype=active'>active</a>,
               <a href='showuser_list.php3?showtype=inactive'>inactive</a>,
37
               <a href='showuser_list.php3?showtype=all'>all</a>.</b>\n";
38 39

if (!isset($showtype)) {
40
    $showtype='loggedin';
41
}
42
if (!isset($sortby)) {
43
    $sortby = "uid";
44 45 46 47
}
if (!isset($searchfor)) {
    $searchfor = "";
}
48

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
#
# Spit out a search form!
#
echo "<form action=showuser_list.php3 method=post>
      <input type=text
             name=searchfor
             value=\"$searchfor\"
             size=20
   	     maxlength=50>
      <input type=hidden name=showtype value=\"$showtype\">
      <input type=hidden name=sortby   value=\"$sortby\">
      <b><input type=submit name=search value=Search></b>\n";
echo "<br><br>\n";

if (isset($searchfor) && strcmp($searchfor, "")) {
    $clause  = "";
    $where   = "where (u.usr_name like '%${searchfor}%' or ".
	"u.usr_email like '%${searchfor}%') ";
    $showtag = "matching";
}
elseif (! strcmp($showtype, "all")) {
70 71 72 73
    $where   = "";
    $clause  = "";
    $showtag = "";
}
74
elseif (! strcmp($showtype, "loggedin")) {
75 76
    $clause  = "left join login as l on u.uid=l.uid ";
    $where   = "where l.timeout>=unix_timestamp()";
77
    $showtag = "logged in";
78
}
79 80 81 82 83 84
elseif (! strcmp($showtype, "recent")) {
    $clause  = "left join login as l on u.uid=l.uid ";
    $where   = "where l.timeout is null or l.timeout<unix_timestamp() ".
	       "having webidle=1 ";
    $showtag = "recently logged in (yesterday)";
}
85 86 87 88
elseif (! strcmp($showtype, "widearea")) {
    $clause  = "left join widearea_accounts as w on u.uid=w.uid ";
    $where   = "where w.node_id is not NULL";
    $showtag = "widearea";
89
}
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
elseif (! strcmp($showtype, "homeless")) {
    $clause  = "left join group_membership as m on u.uid=m.uid ";
    $clause .= "left join widearea_accounts as w on u.uid=w.uid ";
    $where   = "where (m.uid is null and w.node_id is NULL) ";
    $showtag = "homeless";
}
elseif (! strcmp($showtype, "inactive")) {
    $clause  = "";
    $where   = "where u.status!='active' ";
    $showtag = "inactive";
}
elseif (! strcmp($showtype, "active")) {
    $clause  = "";
    $where   = "where u.status='active' ";
    $showtag = "active";
}
106
else {
107 108 109
    $clause  = "";
    $where   = "";
    $showtag = "";
110
}
111 112 113 114

if (! strcmp($sortby, "name"))
    $order = "u.usr_name";
elseif (! strcmp($sortby, "uid"))
115
    $order = "u.uid";
116 117 118 119
elseif (! strcmp($sortby, "widle"))
    $order = "webidle DESC";
elseif (! strcmp($sortby, "uidle"))
    $order = "usersidle DESC";
120
else {
121
    $order = "u.uid";
122 123
}

124 125
$query_result =
    DBQueryFatal("SELECT u.*, ".
126 127
		 " IF(ll.weblogin_last, ".
		 "    TO_DAYS(CURDATE()) - TO_DAYS(ll.weblogin_last), ".
128 129 130 131 132 133
		 "    TO_DAYS(CURDATE()) - TO_DAYS(u.usr_created)) ".
		 "   as webidle, ".
		 " TO_DAYS(CURDATE()) - TO_DAYS(ull.date) as usersidle ".
		 "FROM users as u ".
		 "$clause ".
		 "left join userslastlogin as ull on u.uid=ull.uid ".
134
		 "left join user_stats as ll on u.uid=ll.uid ".
135 136
		 "$where ".
		 "order by $order");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
137

138
if (($count = mysql_num_rows($query_result)) == 0) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
139
    USERERROR("There are no users!", 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
140 141
}

142 143 144
echo "<center>
       There are $count $showtag users.
      </center><br>\n";
145 146 147 148 149

#
# Grab the project lists and create a hash of lists, per user.
# One query instead of hundreds.
#
150
$projmemb_array  = array();
151
$projmemb_result =
152 153
   DBQueryFatal("select distinct uid,pid from group_membership ".
		"order by uid");
154 155 156 157 158 159 160 161

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

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

Chad Barb's avatar
Chad Barb committed
162
echo "<table width=\"100%\" border=2 cellpadding=1 cellspacing=2
Leigh B. Stoller's avatar
Leigh B. Stoller committed
163 164 165
       align='center'>\n";

echo "<tr>
Chad Barb's avatar
Chad Barb committed
166
          <th>&nbsp</th>
167 168
          <th><a href='showuser_list.php3?showtype=$showtype&sortby=uid".
                 "&searchfor=$searchfor'> 
Chad Barb's avatar
Chad Barb committed
169
                 UID</a></th>
170 171
          <th><a href='showuser_list.php3?showtype=$showtype&sortby=name".
                 "&searchfor=$searchfor'>
Chad Barb's avatar
Chad Barb committed
172
                 Name</a></th>
173 174 175 176 177 178
          <th>Projects</th>\n";

if (! strcmp($showtype, "inactive")) {
    echo "<th>Status</th>\n";
}

179 180
echo "    <th><a href='showuser_list.php3?showtype=$showtype&sortby=widle".
                 "&searchfor=$searchfor'>
Chad Barb's avatar
Chad Barb committed
181
                 Web<br>Idle</a></th>
182 183
          <th><a href='showuser_list.php3?showtype=$showtype&sortby=uidle".
                 "&searchfor=$searchfor'>
Chad Barb's avatar
Chad Barb committed
184
                 Users<br>Idle</a></th>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
185 186 187 188 189 190

echo "</tr>\n";

while ($row = mysql_fetch_array($query_result)) {
    $thisuid  = $row[uid];
    $name     = $row[usr_name];
191
    $status   = $row[status];
192
    $unix_uid = $row[unix_uid];
193 194
    $webidle  = $row[webidle];
    $usersidle= $row[usersidle];
Leigh B. Stoller's avatar
Leigh B. Stoller committed
195

196 197
    echo "<tr>\n";

198
    if (strcmp($status, "active") == 0) {
199 200 201 202 203 204 205
	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
206 207
              <td>$name</td>\n";

208 209 210 211 212 213
    # 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>";
214
	    if ($idx != (count($projmemb_array[$thisuid]) - 1))
215 216 217
		echo ", ";
	}
	echo "</td>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
218 219 220 221
    }
    else {
	    echo "<td>--</td>\n";
    }
222
    
223 224 225 226
    if (! strcmp($showtype, "inactive")) {
	echo "<td>$status</td>\n";
    }

227
    echo "<td>$webidle</td>\n";
228

229
    if (! $usersidle)
230
	echo "<td>&nbsp</td>\n";
231 232
    else {
	echo "<td>$usersidle</td>\n";
233 234
    }

Leigh B. Stoller's avatar
Leigh B. Stoller committed
235 236 237 238 239 240 241 242 243
    echo "</tr>\n";
}
echo "</table>\n";

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