showuser_list.php3 7.47 KB
Newer Older
Leigh Stoller's avatar
Leigh Stoller committed
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23
#
Leigh Stoller's avatar
Leigh Stoller committed
24 25 26 27 28 29
include("defs.php3");

#
#
# Only known and logged in users allowed.
#
30 31 32
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
Leigh Stoller's avatar
Leigh Stoller committed
33

34 35 36
# For "recent" stuff below.
$dorecent = 0;

Leigh Stoller's avatar
Leigh Stoller committed
37 38
if (! $isadmin) {
    USERERROR("You do not have permission to view the user list!", 1);
Leigh Stoller's avatar
Leigh Stoller committed
39
}
40

41 42 43 44 45
#
# Verify Page Arguments.
#
$optargs = OptionalPageArguments("showtype",   PAGEARG_STRING,
				 "searchfor",  PAGEARG_STRING);
46 47

if (!isset($showtype)) {
48
    $showtype='loggedin';
49
}
50 51 52
if (!isset($searchfor)) {
    $searchfor = "";
}
53

54 55 56 57 58 59
#
# Standard Testbed Header
#
PAGEHEADER("User List");


60 61 62 63 64 65 66 67 68
echo "<b>Show: <a href='showuser_list.php3?showtype=loggedin'>loggedin</a>,
               <a href='showuser_list.php3?showtype=recent'>recent</a>,
               <a href='showuser_list.php3?showtype=widearea'>widearea</a>,
               <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>,
               <a href='showuser_list.php3?showtype=archived'>archived</a>,
               <a href='showuser_list.php3?showtype=all'>all</a>.</b>\n";

69
#
70
# Spit out a search form.
71
#
72 73
$clean_showtype  = CleanString($showtype);
$clean_searchfor = CleanString($searchfor);
74 75 76
echo "<form action=showuser_list.php3 method=post>
      <input type=text
             name=searchfor
77
             value=\"$clean_searchfor\"
78 79
             size=20
   	     maxlength=50>
80
      <input type=hidden name=showtype value=\"$clean_showtype\">
81 82 83 84 85
      <b><input type=submit name=search value=Search></b>\n";
echo "<br><br>\n";

if (isset($searchfor) && strcmp($searchfor, "")) {
    $clause  = "";
86 87 88
    $search  = addslashes("%${searchfor}%");
    $where   = "where (u.usr_name like '$search' or ".
	"u.usr_email like '$search' or u.uid like '$search') ";
89 90 91
    $showtag = "matching";
}
elseif (! strcmp($showtype, "all")) {
92 93 94 95
    $where   = "";
    $clause  = "";
    $showtag = "";
}
96
elseif (! strcmp($showtype, "loggedin")) {
97
    $clause  = "left join login as l on u.uid_idx=l.uid_idx ";
98
    $where   = "where l.timeout>=unix_timestamp()";
99
    $showtag = "logged in";
100
}
101
elseif (! strcmp($showtype, "recent")) {
102
    $clause  = "left join login as l on u.uid_idx=l.uid_idx ";
103 104 105
    $where   = "where l.timeout is null or l.timeout<unix_timestamp() ".
	       "having webidle=1 ";
    $showtag = "recently logged in (yesterday)";
106
    $dorecent= 1;
107
}
108
elseif (! strcmp($showtype, "widearea")) {
109
    $clause  = "left join widearea_accounts as w on u.uid_idx=w.uid_idx ";
110 111
    $where   = "where w.node_id is not NULL";
    $showtag = "widearea";
112
}
113
elseif (! strcmp($showtype, "homeless")) {
114
    $clause  = "left join group_membership as m on u.uid_idx=m.uid_idx ";
115
    $clause .= "left join widearea_accounts as w on u.uid_idx=w.uid_idx ";
116 117 118 119 120 121 122 123 124 125 126 127 128
    $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";
}
129 130 131 132 133
elseif (! strcmp($showtype, "archived")) {
    $clause  = "";
    $where   = "where u.status='archived' ";
    $showtag = "archived";
}
134
else {
135 136 137
    $clause  = "";
    $where   = "";
    $showtag = "";
138
}
139

140
$query_result =
141
    DBQueryFatal("SELECT " . ($dorecent ? "distinct" : "") . " u.*, ".
142 143
		 " IF(ll.weblogin_last, ".
		 "    TO_DAYS(CURDATE()) - TO_DAYS(ll.weblogin_last), ".
144 145 146 147 148
		 "    TO_DAYS(CURDATE()) - TO_DAYS(u.usr_created)) ".
		 "   as webidle, ".
		 " TO_DAYS(CURDATE()) - TO_DAYS(ull.date) as usersidle ".
		 "FROM users as u ".
		 "$clause ".
149
		 "left join userslastlogin as ull on u.uid_idx=ull.uid_idx ".
150
		 "left join user_stats as ll on u.uid_idx=ll.uid_idx ".
151
		 "$where ".
152
		 "order by u.uid");
Leigh Stoller's avatar
Leigh Stoller committed
153

154
if (($count = mysql_num_rows($query_result)) == 0) {
Leigh Stoller's avatar
Leigh Stoller committed
155
    USERERROR("There are no users!", 1);
Leigh Stoller's avatar
Leigh Stoller committed
156 157
}

158 159 160
echo "<center>
       There are $count $showtag users.
      </center><br>\n";
161 162 163 164 165

#
# Grab the project lists and create a hash of lists, per user.
# One query instead of hundreds.
#
166
$projmemb_array  = array();
167
$projmemb_result =
Leigh Stoller's avatar
Leigh Stoller committed
168
   DBQueryFatal("select distinct uid,pid,trust from group_membership ".
169
		"order by uid");
170 171 172 173

while ($row = mysql_fetch_array($projmemb_result)) {
    $uid   = $row[0];
    $pid   = $row[1];
Leigh Stoller's avatar
Leigh Stoller committed
174
    $trust = $row[2];
175

Leigh Stoller's avatar
Leigh Stoller committed
176 177 178 179 180
    $foo   = array();
    $foo["pid"]   = $pid;
    $foo["trust"] = $trust;

    $projmemb_array[$uid][] = $foo;
181 182
}

183 184
echo "<table width=\"100%\" border=2 cellpadding=1 cellspacing=2 
       id='userlist' align='center'>\n";
Leigh Stoller's avatar
Leigh Stoller committed
185

186
echo "<thead class='sort'>";
Leigh Stoller's avatar
Leigh Stoller committed
187
echo "<tr>
Chad Barb's avatar
Chad Barb committed
188
          <th>&nbsp</th>
189 190
          <th>UID</th>
          <th>Name</th>
191
          <th>Affiliation</th>
192 193 194 195 196 197
          <th>Projects</th>\n";

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

198 199
echo "    <th>Web<br>Idle</th>
          <th>Users<br>Idle</th>\n";
Leigh Stoller's avatar
Leigh Stoller committed
200 201

echo "</tr>\n";
202
echo "</thead>\n";
Leigh Stoller's avatar
Leigh Stoller committed
203 204

while ($row = mysql_fetch_array($query_result)) {
205 206 207
    $thisuid  = $row["uid"];
    $webid    = $row["uid_idx"];
    $name     = $row["usr_name"];
208
    $affil    = $row["usr_affil_abbrev"];
209 210 211 212
    $status   = $row["status"];
    $unix_uid = $row["unix_uid"];
    $webidle  = $row["webidle"];
    $usersidle= $row["usersidle"];
Leigh Stoller's avatar
Leigh Stoller committed
213

214 215
    $showuser_url = CreateURL("showuser", URLARG_UID, $webid);

216 217
    echo "<tr>\n";

218
    if (strcmp($status, "active") == 0) {
219 220 221 222 223 224
	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";
    }

225
    echo "<td><A href='$showuser_url'>$thisuid</A></td>
226 227
              <td>$name</td>
	      <td>$affil</td>\n";
Leigh Stoller's avatar
Leigh Stoller committed
228

229 230 231
    # List of projects.
    reset($projmemb_array);
    if (isset($projmemb_array[$thisuid])) {
232 233
	reset($projmemb_array[$thisuid]);
	
234
	echo "<td> ";
Leigh Stoller's avatar
Leigh Stoller committed
235 236 237 238 239 240 241 242 243 244 245 246 247
	while (list ($idx, $foo) = each($projmemb_array[$thisuid])) {
	    $pid   = $foo["pid"];
	    $trust = $foo["trust"];
	    
	    echo "<A href='showproject.php3?pid=$pid'>";
	    if ($trust == TBDB_TRUSTSTRING_NONE) {
		echo "<font color=red>";
	    }
	    echo $pid;
	    if ($trust == TBDB_TRUSTSTRING_NONE) {
		echo "</font>";
	    }
	    echo "</A>";
248
	    if ($idx != (count($projmemb_array[$thisuid]) - 1))
249 250 251
		echo ", ";
	}
	echo "</td>\n";
Leigh Stoller's avatar
Leigh Stoller committed
252 253 254 255
    }
    else {
	    echo "<td>--</td>\n";
    }
256
    
257 258 259 260
    if (! strcmp($showtype, "inactive")) {
	echo "<td>$status</td>\n";
    }

261
    echo "<td>$webidle</td>\n";
262

263
    if (! $usersidle)
264
	echo "<td>&nbsp</td>\n";
265 266
    else {
	echo "<td>$usersidle</td>\n";
267 268
    }

Leigh Stoller's avatar
Leigh Stoller committed
269 270 271 272
    echo "</tr>\n";
}
echo "</table>\n";

273 274 275 276
echo "<script type='text/javascript' language='javascript'>
	  sorttable.makeSortable(getObjbyName('userlist'));
       </script>\n";

Leigh Stoller's avatar
Leigh Stoller committed
277 278 279 280 281
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>