showuser_list.php3 6.51 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-2006 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

#
#
# Only known and logged in users allowed.
#
18 19 20
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
21

22 23 24
# For "recent" stuff below.
$dorecent = 0;

Leigh B. Stoller's avatar
Leigh B. Stoller committed
25 26
if (! $isadmin) {
    USERERROR("You do not have permission to view the user list!", 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
27
}
28

29
echo "<b>Show: <a href='showuser_list.php3?showtype=loggedin'>loggedin</a>,
30
               <a href='showuser_list.php3?showtype=recent'>recent</a>,
31
               <a href='showuser_list.php3?showtype=widearea'>widearea</a>,
32 33 34
               <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>,
35
               <a href='showuser_list.php3?showtype=all'>all</a>.</b>\n";
36 37

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

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#
# 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 ".
64
	"u.usr_email like '%${searchfor}%' or u.uid like '%${searchfor}%') ";
65 66 67
    $showtag = "matching";
}
elseif (! strcmp($showtype, "all")) {
68 69 70 71
    $where   = "";
    $clause  = "";
    $showtag = "";
}
72
elseif (! strcmp($showtype, "loggedin")) {
73 74
    $clause  = "left join login as l on u.uid=l.uid ";
    $where   = "where l.timeout>=unix_timestamp()";
75
    $showtag = "logged in";
76
}
77 78 79 80 81
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)";
82
    $dorecent= 1;
83
}
84 85 86 87
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";
88
}
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
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";
}
105
else {
106 107 108
    $clause  = "";
    $where   = "";
    $showtag = "";
109
}
110 111 112 113

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

123
$query_result =
124
    DBQueryFatal("SELECT " . ($dorecent ? "distinct" : "") . " u.*, ".
125 126
		 " IF(ll.weblogin_last, ".
		 "    TO_DAYS(CURDATE()) - TO_DAYS(ll.weblogin_last), ".
127 128 129 130 131 132
		 "    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 ".
133
		 "left join user_stats as ll on u.unix_uid=ll.uid_idx ".
134 135
		 "$where ".
		 "order by $order");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
136

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

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

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

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

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

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

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

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

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

echo "</tr>\n";

while ($row = mysql_fetch_array($query_result)) {
    $thisuid  = $row[uid];
189
    $webid    = $row[uid_idx];
Leigh B. Stoller's avatar
Leigh B. Stoller committed
190
    $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
    $showuser_url = CreateURL("showuser", URLARG_UID, $webid);

198 199
    echo "<tr>\n";

200
    if (strcmp($status, "active") == 0) {
201 202 203 204 205 206
	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";
    }

207
    echo "<td><A href='$showuser_url'>$thisuid</A></td>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
208 209
              <td>$name</td>\n";

210 211 212
    # List of projects.
    reset($projmemb_array);
    if (isset($projmemb_array[$thisuid])) {
213 214
	reset($projmemb_array[$thisuid]);
	
215 216 217
	echo "<td> ";
	while (list ($idx, $pid) = each($projmemb_array[$thisuid])) {
	    echo "<A href='showproject.php3?pid=$pid'>$pid</A>";
218
	    if ($idx != (count($projmemb_array[$thisuid]) - 1))
219 220 221
		echo ", ";
	}
	echo "</td>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
222 223 224 225
    }
    else {
	    echo "<td>--</td>\n";
    }
226
    
227 228 229 230
    if (! strcmp($showtype, "inactive")) {
	echo "<td>$status</td>\n";
    }

231
    echo "<td>$webidle</td>\n";
232

233
    if (! $usersidle)
234
	echo "<td>&nbsp</td>\n";
235 236
    else {
	echo "<td>$usersidle</td>\n";
237 238
    }

Leigh B. Stoller's avatar
Leigh B. Stoller committed
239 240 241 242 243 244 245 246 247
    echo "</tr>\n";
}
echo "</table>\n";

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