Commit b5726dcd authored by Leigh Stoller's avatar Leigh Stoller

More sorting sillyness for Jay. Project and User lists get a lot more

sorting options. I have not done anything with the experiment listing
though since I'm hoping to get better info out of the slothd stuff, so
might as well wait.
parent 8e532a2b
......@@ -1018,6 +1018,21 @@ function TBNodeUidLastLogin($node_id)
return $row;
}
#
# Return the last login for the users node.
#
function TBUsersLastLogin($uid)
{
$query_result =
DBQueryFatal("select * from userslastlogin where uid='$uid'");
if (mysql_num_rows($query_result) == 0) {
return 0;
}
$row = mysql_fetch_array($query_result);
return $row;
}
#
# Return number of events in an experiment.
#
......
......@@ -262,74 +262,6 @@ function CHECKPASSWORD($uid, $password, $name, $email, &$error)
"$TBCHKPASS_PATH $password $uid '$name:$email'", 1);
}
#
# Get the last USERS node login for a user (or all users). If this fails,
# the let testbed ops know, but its not a fatal problem.
#
function LASTUSERSLOGIN($uid) {
global $TBLIBEXEC_DIR;
$output = array();
$retval = 0;
#
# Either a specific UID or a list of all UIDs.
#
$uidarg = "";
if ($uid) {
$uidarg = "-u $uid";
}
$cmdandargs = "$TBLIBEXEC_DIR/lastlogin $uidarg";
$result = exec($cmdandargs, $output, $retval);
if ($retval) {
if (0) {
$foo = "";
for ($i = 0; $i < count($output); $i++) {
$foo = "$foo $output[$i]";
}
TBERROR("LASTUSERSLOGIN: ".
"Cmd was \"$cmdandargs\". \n".
"Error output:\n\n $foo\n", 0);
}
return 0;
}
$hashtable = array();
#
# In single user mode, return a hash of date, time, node.
#
if ($uid) {
if (! $output[0])
return 0;
$parts = explode(" ", $output[0]);
$hashtable["date"] = $parts[0];
$hashtable["time"] = $parts[1];
$hashtable["node_id"] = $parts[2];
return $hashtable;
}
#
# In all user mode, return a hash of hashes, indexed by uid.
#
for ($i = 0; $i < count($output); $i++) {
$utable = array();
$parts = explode(" ", $output[$i]);
$utable["date"] = $parts[1];
$utable["time"] = $parts[2];
$utable["node_id"] = $parts[3];
$hashtable["$parts[0]"] = $utable;
}
return $hashtable;
}
function LASTNODELOGIN($node)
{
}
......
......@@ -44,12 +44,20 @@ elseif (! strcmp($sortby, "pid"))
$order = "p.pid";
elseif (! strcmp($sortby, "uid"))
$order = "p.head_uid";
elseif (! strcmp($sortby, "idle"))
$order = "idle";
elseif (! strcmp($sortby, "created"))
$order = "p.expt_count DESC";
elseif (! strcmp($sortby, "running"))
$order = "ecount DESC";
elseif (! strcmp($sortby, "nodes"))
$order = "ncount DESC";
else
$order = "p.name";
if ($isadmin) {
$query_result =
DBQueryFatal("SELECT * FROM projects as p order by $order");
DBQueryFatal("SELECT pid,expt_count FROM projects as p");
#
# Process the query results for active projects so I can generate a
......@@ -90,17 +98,31 @@ function GENPLIST ($query_result)
echo "<table width='100%' border=2
cellpadding=2 cellspacing=0 align=center>
<tr>
<td><a href='showproject_list.php3?splitview=$splitview&sortby=pid'>
PID</td>
<td>(Approved?)
<tr>\n";
echo "<td><a href='showproject_list.php3?splitview=$splitview&sortby=pid'>
PID</a></td>\n";
echo "<td>(Approved?)
<a href='showproject_list.php3?splitview=$splitview&sortby=name'>
Description</td>
<td><a href='showproject_list.php3?splitview=$splitview&sortby=uid'>
Leader</td>
<td align=center>Days<br>Idle</td>
<td align=center colspan=2>Expts<br>Cr, Run</td>
<td align=center>Nodes</td>\n";
Description</a></td>\n";
echo "<td><a href='showproject_list.php3?splitview=$splitview&sortby=uid'>
Leader</a></td>\n";
echo "<td align=center>
<a href='showproject_list.php3?splitview=$splitview&sortby=idle'>
Days<br>Idle</a></td>\n";
echo "<td align=center colspan=2>Expts<br>
<a href='showproject_list.php3?splitview=$splitview&sortby=created'>
Cr</a>,
<a href='showproject_list.php3?splitview=$splitview&sortby=running'>
Run</a></td>\n";
echo "<td align=center>
<a href='showproject_list.php3?splitview=$splitview&sortby=nodes'>
Nodes</a></td>\n";
#
# Admin users get other fields.
......@@ -115,10 +137,11 @@ function GENPLIST ($query_result)
$headuid = $projectrow[head_uid];
$Pname = $projectrow[name];
$approved = $projectrow[approved];
$created = $projectrow[created];
$expt_count = $projectrow[expt_count];
$expt_last = $projectrow[expt_last];
$public = $projectrow[public];
$ecount = $projectrow[ecount];
$ncount = $projectrow[ncount];
$idle = $projectrow[idle];
echo "<tr>
<td><A href='showproject.php3?pid=$pid'>$pid</A></td>
......@@ -133,37 +156,10 @@ function GENPLIST ($query_result)
<td><A href='showuser.php3?target_uid=$headuid'>
$headuid</A></td>\n";
#
# Sleazy! Use mysql query to convert dates to days and subtract!
#
if (isset($expt_last)) {
$idle_query =
DBQueryFatal("select TO_DAYS(CURDATE()) - ".
" TO_DAYS('$expt_last')");
$idle_row = mysql_fetch_row($idle_query);
echo "<td>$idle_row[0]</td>\n";
}
else {
$idle_query =
DBQueryFatal("select TO_DAYS(CURDATE()) - ".
" TO_DAYS('$created')");
$idle_row = mysql_fetch_row($idle_query);
echo "<td>$idle_row[0]</td>\n";
}
# Number of Current Experiments.
$query_cur_expts =
DBQueryFatal("SELECT count(*) FROM experiments where pid='$pid'");
$cur_expts_row = mysql_fetch_array($query_cur_expts);
# Number of nodes reserved.
$query_nodes_reserved =
DBQueryFatal("SELECT count(*) FROM reserved where pid='$pid'");
$nodes_reserved_row = mysql_fetch_array($query_nodes_reserved);
echo "<td>$idle</td>\n";
echo "<td>$expt_count</td>\n";
echo "<td>$cur_expts_row[0]</td>\n";
echo "<td>$nodes_reserved_row[0]</td>\n";
echo "<td>$ecount</td>\n";
echo "<td>$ncount</td>\n";
if ($isadmin) {
if ($public) {
......@@ -183,10 +179,18 @@ function GENPLIST ($query_result)
#
if (! $isadmin) {
$query_result =
DBQueryFatal("SELECT * FROM projects as p ".
DBQueryFatal("SELECT p.pid,count(distinct r.node_id) as ncount, ".
"count(distinct e.eid) as ecount, ".
"IF(p.expt_last, ".
" TO_DAYS(CURDATE()) - TO_DAYS(p.expt_last), ".
" TO_DAYS(CURDATE()) - TO_DAYS(p.created)) as idle ".
"FROM projects as p ".
"left join group_membership as g on ".
" p.pid=g.pid and g.pid=g.gid ".
"where g.uid='$uid' and g.trust!='none' order by $order");
" p.pid=g.pid and g.pid=g.gid ".
"left join experiments as e on e.pid=p.pid ".
"left join reserved as r on r.pid=p.pid ".
"where g.uid='$uid' and g.trust!='none' ".
"group by p.pid order by $order");
if (mysql_num_rows($query_result) == 0) {
USERERROR("You are not a member of any projects!", 1);
......@@ -197,8 +201,16 @@ if (! $isadmin) {
else {
if ($splitview) {
$query_result =
DBQueryFatal("select * FROM projects as p ".
"where expt_count>0 order by $order");
DBQueryFatal("SELECT p.pid,count(distinct r.node_id) as ncount, ".
"count(distinct e.eid) as ecount, ".
"IF(p.expt_last, ".
" TO_DAYS(CURDATE()) - TO_DAYS(p.expt_last), ".
" TO_DAYS(CURDATE()) - TO_DAYS(p.created)) as idle ".
"FROM projects as p ".
"left join experiments as e on e.pid=p.pid ".
"left join reserved as r on r.pid=p.pid ".
"where expt_count>0 ".
"group by p.pid order by $order");
if (mysql_num_rows($query_result)) {
echo "<center>
......@@ -208,8 +220,16 @@ else {
}
$query_result =
DBQueryFatal("select * FROM projects as p ".
"where expt_count=0 order by $order");
DBQueryFatal("SELECT p.pid,count(distinct r.node_id) as ncount, ".
"count(distinct e.eid) as ecount, ".
"IF(p.expt_last, ".
" TO_DAYS(CURDATE()) - TO_DAYS(p.expt_last), ".
" TO_DAYS(CURDATE()) - TO_DAYS(p.created)) as idle ".
"FROM projects as p ".
"left join experiments as e on e.pid=p.pid ".
"left join reserved as r on r.pid=p.pid ".
"where expt_count=0 ".
"group by p.pid order by $order");
if (mysql_num_rows($query_result)) {
echo "<br><center>
......@@ -220,7 +240,20 @@ else {
}
else {
GENPLIST($query_result);
$query_result =
DBQueryFatal("SELECT p.*,count(distinct r.node_id) as ncount, ".
"count(distinct e.eid) as ecount, ".
"IF(p.expt_last, ".
" TO_DAYS(CURDATE()) - TO_DAYS(p.expt_last), ".
" TO_DAYS(CURDATE()) - TO_DAYS(p.created)) as idle ".
" FROM projects as p ".
"left join experiments as e on e.pid=p.pid ".
"left join reserved as r on r.pid=p.pid ".
"group by p.pid order by $order");
if (mysql_num_rows($query_result)) {
GENPLIST($query_result);
}
}
}
......
......@@ -336,12 +336,11 @@ function SHOWUSER($uid) {
#
if (($lastweblogin = LASTWEBLOGIN($uid)) == 0)
$lastweblogin = "&nbsp";
if (($lastuserslogininfo = LASTUSERSLOGIN($uid)) == 0)
if (($lastuserslogininfo = TBUsersLastLogin($uid)) == 0)
$lastuserslogin = "N/A";
else {
$lastuserslogin = $lastuserslogininfo["date"] . " " .
$lastuserslogininfo["time"] . " " .
"(" . $lastuserslogininfo["node_id"] . ")";
$lastuserslogininfo["time"];
}
if (($lastnodelogininfo = TBUidNodeLastLogin($uid)) == 0)
......
......@@ -24,61 +24,79 @@ if (! $isadmin) {
}
if (!isset($showactive))
$showactive = 0;
if (!isset($sortbyname))
$sortbyname = 0;
if (!isset($sortby))
$sortby = "name";
if (!$showactive) {
echo "<b><a href='showuser_list.php3?showactive=1&sortbyname=$sortbyname'>
echo "<b><a href='showuser_list.php3?showactive=1&sortby=$sortby'>
Show Logged in Users</a>
</b><br><br>\n";
}
else {
echo "<b><a href='showuser_list.php3?showactive=0&sortbyname=$sortbyname'>
echo "<b><a href='showuser_list.php3?showactive=0&sortby=$sortby'>
Show All Users</a>
</b><br><br>\n";
}
if (!$sortbyname) {
if (! strcmp($sortby, "name"))
$order = "u.usr_name";
elseif (! strcmp($sortby, "uid"))
$order = "u.uid";
$sortbyname = 0;
}
elseif (! strcmp($sortby, "widle"))
$order = "webidle DESC";
elseif (! strcmp($sortby, "uidle"))
$order = "usersidle DESC";
else {
$order = "u.usr_name";
}
if ($showactive) {
$query_result =
DBQueryFatal("select u.* from login as l ".
"left join users as u on u.uid=l.uid ".
"where timeout>=unix_timestamp() ".
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() ".
"order by $order");
}
else {
$query_result =
DBQueryFatal("SELECT u.* FROM users as u order by $order");
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");
}
if (mysql_num_rows($query_result) == 0) {
USERERROR("There are no users!", 1);
}
#
# Grab the login info. If we cannot get the login info, then just
# proceed without it.
#
$loginarray = LASTUSERSLOGIN(0);
echo "<table width=\"100%\" border=2 cellpadding=1 cellspacing=0
align='center'>\n";
echo "<tr>
<td>&nbsp</td>
<td><a href='showuser_list.php3?showactive=$showactive&sortbyname=0'>
UID</td>
<td><a href='showuser_list.php3?showactive=$showactive&sortbyname=1'>
Name</td>
<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>
<td>Projects</td>
<td>Web<br>Idle</td>
<td>Users<br>Idle</td>\n";
<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";
#
# Admin users get a "delete" and a "modify" option.
......@@ -95,7 +113,8 @@ while ($row = mysql_fetch_array($query_result)) {
$name = $row[usr_name];
$status = $row[status];
$unix_uid = $row[unix_uid];
$lastweblogin = LASTWEBLOGIN($thisuid);
$webidle = $row[webidle];
$usersidle= $row[usersidle];
#
# Suck out a list of projects too.
......@@ -132,30 +151,12 @@ while ($row = mysql_fetch_array($query_result)) {
echo "<td>--</td>\n";
}
#
# Sleazy! Use mysql query to convert dates to days and subtract!
#
if ($lastweblogin) {
$idle_query = mysql_db_query($TBDBNAME,
"SELECT TO_DAYS(CURDATE()) - TO_DAYS(\"$lastweblogin\")");
$idle_row = mysql_fetch_row($idle_query);
echo "<td>$idle_row[0]</td>\n";
}
else {
echo "<td>&nbsp</td>\n";
}
echo "<td>$webidle</td>\n";
if ($loginarray && isset($loginarray["$unix_uid"])) {
$userslogininfo = $loginarray["$unix_uid"];
$lastuserslogin = $userslogininfo["date"];
$idle_query = mysql_db_query($TBDBNAME,
"SELECT TO_DAYS(CURDATE()) - TO_DAYS(\"$lastuserslogin\")");
$idle_row = mysql_fetch_row($idle_query);
echo "<td>$idle_row[0]</td>\n";
}
else {
if (! $usersidle)
echo "<td>&nbsp</td>\n";
else {
echo "<td>$usersidle</td>\n";
}
if ($isadmin) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment