showexp_list.php3 22.3 KB
Newer Older
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.
#
7 8 9 10 11
include("defs.php3");

#
# Standard Testbed Header
#
12
PAGEHEADER("Experiment Information Listing");
13 14

#
15
# Only known and logged in users.
16
#
17 18 19
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
20

21 22
$clause      = 0;
$having      = "";
23 24
$active      = 0;
$idle        = 0;
25

26 27 28 29 30 31 32 33 34 35
function MakeMouseOver($string)
{
    $string = ereg_replace("\n", "<br>", $string);
    $string = ereg_replace("\r", "", $string);
    $string = htmlentities($string);
    $string = preg_replace("/\'/", "\&\#039;", $string);

    return "onmouseover=\"return escape('$string')\"";
}

36 37 38 39 40 41 42 43 44 45 46 47 48 49
#
# Hack for NSDI deadline. Generalize later.
#
$openlist        = TBGetSiteVar("general/open_showexplist");
$openlist_member = 0;
if (!$isadmin && isset($openlist) && $openlist != "") {
    $openlist_member =
	TBMinTrust(TBProjTrust($uid,$openlist), $TBDB_TRUST_USER);
    $openlist_join =
	" left join group_membership as g on ".
	"     g.uid=e.expt_swap_uid and g.pid='$openlist' and g.pid=g.gid ";
    $openlist_clause = " and g.uid is not null ";
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
50 51
if (! isset($showtype))
    $showtype="active";
52 53
if (! isset($sortby))
    $sortby = "normal";
54 55
if (! isset($thumb)) 
    $thumb = 0;
56 57
if (! isset($noignore)) 
    $noignore = 0;
58

59
echo "<b>Show: ";
60

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
if ($showtype != "active") {
    echo "<a class='static' href='showexp_list.php3?showtype=active&sortby=$sortby&thumb=$thumb'>Active</a>, ";
} else {
    echo "Active, ";
}

if ($showtype != "batch") {
    echo "<a class='static' href='showexp_list.php3?showtype=batch&sortby=$sortby&thumb=$thumb'>Batch</a>, ";
} else {
    echo "Batch, ";
}

if ($isadmin) {
    if ($showtype != "idle") {
	echo "<a class='static' href='showexp_list.php3?showtype=idle&sortby=$sortby&thumb=$thumb'>Idle</a>, ";
    } else {
	echo "Idle, ";
    }
}

if ($showtype != "all") {
    echo "<a class='static' href='showexp_list.php3?showtype=all&sortby=$sortby&thumb=$thumb'>All</a>";
} else {
    echo "All";
}

echo "</b><br />\n";

89 90
# Default value for showlastlogin is 1 for admins
$showlastlogin = $isadmin;
91
# Note: setting this to 1 for non-admins still does not make the column
92 93
# show properly... it just shows the header in the table, over the
# wrong column. 
Leigh B. Stoller's avatar
Leigh B. Stoller committed
94

95 96
# How many hours is considered idle...
$idlehours = TBGetSiteVar("idle/threshold");
97

Leigh B. Stoller's avatar
Leigh B. Stoller committed
98 99 100 101 102 103 104
#
# Handle showtype
# 
if (! strcmp($showtype, "all")) {
    $title  = "All";
}
elseif (! strcmp($showtype, "active")) {
105 106
    # Active is now defined as "having nodes reserved" - we just depend on
    # the fact that we skip expts with no nodes further down...
107 108 109
    # But for speed, explicitly exclude expts that say they are "swapped"
    # (leave in activating, swapping, etc.)
    $clause = "e.state !='$TB_EXPTSTATE_SWAPPED'";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
110
    $title  = "Active";
111
    $having = "having (ncount>0)";
112
    $active = 1;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
113 114
}
elseif (! strcmp($showtype, "batch")) {
115 116
    $clause = "(e.batchmode=1 and e.state!='" .
               $TB_EXPTSTATE_SWAPPED . "')";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
117
    $title  = "Batch";
118
}
119
elseif ((!strcmp($showtype, "idle")) && $isadmin ) {
120
    # Do not put active in the clause for same reason as active
121 122
    # However, it takes a long time with so many swapped expts
    $clause = "e.state !='$TB_EXPTSTATE_SWAPPED'";
123
    $title  = "Idle";
124 125
    #$having = "having (lastswap>=1)"; # At least one day since swapin
    $having = "having (lastswap>=0)";
126
    $idle = 1;
127
    $showlastlogin = 0; # do not show a lastlogin column
128
}
129
else {
130
    # See active above
Leigh B. Stoller's avatar
Leigh B. Stoller committed
131
    $title  = "Active";
132
    $having = "having (ncount>0)";
133
    $active = 1;
134
}
135

136 137 138


if (!$idle) {
139 140 141
    echo "<b>View: ";

    if ($thumb != 0) {
142
	echo "<a class='static' href='showexp_list.php3?showtype=$showtype&sortby=$sortby&thumb=0'>";
143 144 145 146 147 148 149 150
	echo "List";
        echo "</a>";
    } else {
        echo "List";
    }
    echo ", ";

    if ($thumb != 1) {
151
	echo "<a class='static' href='showexp_list.php3?showtype=$showtype&sortby=$sortby&thumb=1'>";
152 153
	echo "Detailed Thumbnails";
        echo "</a>";
154
    } else {
155
        echo "Detailed Thumbnails";
156
    }
157 158 159
    echo ", ";

    if ($thumb != 2) {
160
	echo "<a class='static' href='showexp_list.php3?showtype=$showtype&sortby=$sortby&thumb=2'>";
161 162 163 164 165 166
	echo "Brief Thumbnails";
        echo "</a>";
    } else {
        echo "Brief Thumbnails";
    }
    echo "</b><br />\n";
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207

if ($thumb && !$idle) {
    echo "<b>Sort by: ";
    if (isset($sortby) && $sortby != "normal" && $sortby != "pid") {
	echo "<a class='static' href='showexp_list.php3?showtype=$showtype&sortby=pid&thumb=$thumb'>";
	echo "Project";
        echo "</a>, ";
    } else {
        echo "Project, ";
    }	
    if ($sortby != "eid") {
	echo "<a class='static' href='showexp_list.php3?showtype=$showtype&sortby=eid&thumb=$thumb'>";
	echo "Experiment ID";
        echo "</a>, ";
    } else {
        echo "Experiment ID, ";
    }
    if ($sortby != "pcs") {
	echo "<a class='static' href='showexp_list.php3?showtype=$showtype&sortby=pcs&thumb=$thumb'>";
	echo "Node Usage";
        echo "</a>, ";
    } else {
        echo "Node Usage, ";
    }	
    if ($sortby != "name") {
	echo "<a class='static' href='showexp_list.php3?showtype=$showtype&sortby=name&thumb=$thumb'>";
	echo "Experiment Description";
        echo "</a>, ";
    } else {
        echo "Experiment Description, ";
    }	
    if ($sortby != "uid") {
	echo "<a class='static' href='showexp_list.php3?showtype=$showtype&sortby=uid&thumb=$thumb'>";
	echo "Creator";
        echo "</a>";
    } else {
        echo "Creator";
    }

    echo "</b><br />\n";
}
208
}
209
 
210 211
echo "<br />\n";

Leigh B. Stoller's avatar
Leigh B. Stoller committed
212 213 214
#
# Handle sortby.
# 
215 216 217 218 219 220 221 222 223
if (! strcmp($sortby, "normal") ||
    ! strcmp($sortby, "pid"))
    $order = "e.pid,e.eid";
elseif (! strcmp($sortby, "eid"))
    $order = "e.eid,e.expt_head_uid";
elseif (! strcmp($sortby, "uid"))
    $order = "e.expt_head_uid,e.pid,e.eid";
elseif (! strcmp($sortby, "name"))
    $order = "e.expt_name";
224
elseif (! strcmp($sortby, "pcs"))
225
    $order = "ncount DESC,e.pid,e.eid";
226 227
elseif (! strcmp($sortby, "idle"))
    $order = "canbeidle desc,idle_ignore,idlesec DESC,ncount desc,e.pid,e.eid";
228 229 230
else 
    $order = "e.pid,e.eid";

231 232 233 234
#
# Show a menu of all experiments for all projects that this uid
# is a member of. Or, if an admin type person, show them all!
#
235 236 237 238 239
if ($clause) {
    $clause = "and ($clause)";
} else {
    $clause = "";
}
240 241 242

# Notes about the queries below:
# - idle is fudged by 121 seconds so that in the five minutes between 
243
#   slothd reports we do not get active expts showing up as idle for 0.1 hrs
244

245
if ($isadmin || $openlist_member) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
246
    $experiments_result =
247 248 249 250 251 252 253 254
	DBQueryFatal("
select e.*, date_format(expt_swapped,'%Y-%m-%d') as d, 
date_format(expt_swapped,'%c/%e') as dshort, 
(to_days(now())-to_days(expt_swapped)) as lastswap, 
count(r.node_id) as ncount, swap_requests, 
round((unix_timestamp(now())-unix_timestamp(last_swap_req))/3600,1) as lastreq,
(unix_timestamp(now()) - unix_timestamp(max(greatest(
last_tty_act,last_net_act,last_cpu_act,last_ext_act)))) as idlesec,
255
(max(last_report) is not null) as canbeidle, s.rsrcidx
256
from experiments as e 
257 258
left join reserved as r on e.pid=r.pid and e.eid=r.eid
left join experiment_stats as s on e.idx=s.exptidx
259 260
left join nodes as n on r.node_id=n.node_id
left join node_activity as na on r.node_id=na.node_id
261 262
$openlist_join
where (n.type!='dnard' or n.type is null) $clause $openlist_clause
263
group by e.pid,e.eid $having order by $order");
264 265
}
else {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
266
    $experiments_result =
267 268 269 270 271
	DBQueryFatal("
select distinct e.*, date_format(expt_swapped,'%Y-%m-%d') as d, 
date_format(expt_swapped,'%c/%e') as dshort, count(r.node_id) as ncount, 
(unix_timestamp(now()) - unix_timestamp(max(greatest(
last_tty_act,last_net_act,last_cpu_act,last_ext_act)))) as idlesec,
272
(max(last_report) is not null) as canbeidle, s.rsrcidx
273 274
from group_membership as g 
left join experiments as e on g.pid=e.pid and g.pid=g.gid 
275
left join experiment_stats as s on e.idx=s.exptidx
276 277 278 279 280 281
left join reserved as r on e.pid=r.pid and e.eid=r.eid 
left join nodes as n on r.node_id=n.node_id 
left join node_activity as na on r.node_id=na.node_id
where (n.type!='dnard' or n.type is null) and 
 g.uid='$uid' and e.pid is not null and e.eid is not null $clause 
group by e.pid,e.eid $having order by $order");    
282
}
283
if (! mysql_num_rows($experiments_result)) {
284 285
    USERERROR("There are no experiments running in any of the projects ".
              "you are a member of.", 1);
286 287
}

288 289
if (mysql_num_rows($experiments_result)) {
    echo "<center>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
290
           <h2>$title Experiments</h2>
291
          </center>\n";
292

293
    if ($idle) {
294
      echo "<p><center><b>Experiments that have been idle at least 
295 296 297 298 299 300
$idlehours hours</b><br>\n";
      if ($noignore) {
        echo "<a class='static' href='showexp_list.php3?showtype=idle&sortby=$sortby&thumb=$thumb'>\n
Exclude idle-ignore experiments</a></center></p><br />\n";
      } else {
        echo "<a class='static' href='showexp_list.php3?showtype=idle&sortby=$sortby&thumb=$thumb&noignore=1'>\n
301
Include idle-ignore experiments</a></center></p><br />\n";
302
      }
303
    }
304
    
305
    $idlemark = "<b>*</b>";
306 307 308
    $stalemark = "<b>?</b>";
    $parens = 0;
    
309 310 311 312 313 314 315
    #
    # Okay, I decided to do this as one big query instead of a zillion
    # per-exp queries in the loop below. No real reason, except my personal
    # desire not to churn the DB.
    # 
    $total_usage  = array();
    $perexp_usage = array();
316
    $perexp_types = array();
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338

    #
    # Geta all the classes of nodes each experiment is using, and create
    # a two-D array with their counts.
    # 
    $usage_query =
	DBQueryFatal("select r.pid,r.eid,nt.class, ".
		     "  count(nt.class) as ncount ".
		     "from reserved as r ".
		     "left join nodes as n on r.node_id=n.node_id ".
		     "left join node_types as nt on n.type=nt.type ".
		     "where n.type!='dnard' ".
		     "group by r.pid,r.eid,nt.class");

    while ($row = mysql_fetch_array($usage_query)) {
	$pid   = $row[0];
	$eid   = $row[1];
	$class = $row[2];
	$count = $row[3];
	
	$perexp_usage["$pid:$eid"][$class] = $count;
    }
339

340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
    #
    # Geta all the types of nodes each experiment is using, and create
    # a two-D array with their counts.
    # 
    $usage_query =
	DBQueryFatal("select r.pid,r.eid,n.type, ".
		     "  count(n.type) as ncount ".
		     "from reserved as r ".
		     "left join nodes as n on r.node_id=n.node_id ".
		     "group by r.pid,r.eid,n.type");

    while ($row = mysql_fetch_array($usage_query)) {
	$pid   = $row[0];
	$eid   = $row[1];
	$type  = $row[2];
	$count = $row[3];
	
	$perexp_types["$pid:$eid"][$type] = $count;
    }

360 361 362
    #
    # Now shove out the column headers.
    #
363
if ($thumb && !$idle) {
364 365 366 367 368
    if ($thumb == 2) {
	echo "<table border=2 cols=4 cellpadding=2 cellspacing=2 align=center><tr>";
    } else {
	echo "<table border=2 cols=2 cellpadding=2 cellspacing=2 align=center><tr>";
    }
369 370 371 372 373 374 375
    $thumbCount = 0;
 
    while ($row = mysql_fetch_array($experiments_result)) {	
	$pid  = $row["pid"];
	$eid  = $row["eid"]; 
	$huid = $row["expt_head_uid"];
	$name = stripslashes($row["expt_name"]);
376
	$date = $row["dshort"];
377
        $rsrcidx = $row["rsrcidx"];
378 379 380 381 382

	if (! ($head_user = User::Lookup($huid))) {
	    TBERROR("Could not lookup object for user $huid", 1);
	}
	$showuser_url = CreateURL("showuser", $head_user);
383 384
	
	if ($idle && ($str=="&nbsp;" || !$pcs)) { continue; }
385

386 387 388 389
	if ($thumb == 2) {
	    if ($pid != "emulab-ops") {
		echo "<td align=center>".
		     "<a href='shownsfile.php3?pid=$pid&eid=$eid'>".
390
		     "<img border=1 class='stealth' ".
391 392
		     " src='showthumb.php3?idx=$rsrcidx'>".
		     "<br>\n".
393 394 395 396 397
		     "<b>".
		     "<a href='showproject.php3?pid=$pid'>$pid</a>/<br />".
		     "<a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a>".
		     "</b>".
		     "</td>";
398 399 400

		$thumbcount++;
		if (($thumbcount % 4) == 0) { echo "</tr><tr>\n"; }
401 402 403 404 405 406
	    }
	} else {

	    echo "<td>".
		 "<table border=0 cellpadding=4 cellspacing=0>".
		 "<tr>".
407
		 "<td width=160 align=center>".
408
	         "<a href='shownsfile.php3?pid=$pid&eid=$eid'>".
409
		 "<img border=1 class='stealth' ".
410
		 " src='showthumb.php3?idx=$rsrcidx'>".
411 412 413 414 415 416 417 418 419 420
	         "</a>".
                 "</td>".
	         "<td align=left class='paddedcell'>".
	         "<b>".
 	         "<a href='showproject.php3?pid=$pid'>$pid</a>/".
                 "<a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a>".
	         "</b>".
	         "<br />\n".
	         "<b><font size=-1>$name</font></b>".
                 "<br />\n";
421 422


423 424 425 426 427 428 429 430 431
	    if ($isadmin) {
		$swappable= $row["swappable"];
		$swapreq=$row["swap_requests"];
		$lastswapreq=$row["lastreq"];
		$lastlogin = "";
		if ($lastexpnodelogins = TBExpUidLastLogins($pid, $eid)) {
		    $daysidle=$lastexpnodelogins["daysidle"];
		    #if ($idle && $daysidle < 1)
		    #  continue;
432
		    $lastlogin .= $lastexpnodelogins["shortdate"] . " " .
433 434 435
			"(" . $lastexpnodelogins["uid"] . ")";
		} elseif ($state=="active") {
		    $daysidle=$row["lastswap"];
436
		    $lastlogin .= "$date swapin";
437 438 439 440 441 442
		}
		# if ($lastlogin=="") { $lastlogin="<td>&nbsp;</td>\n"; }
		if ($lastlogin != "") {
		    echo "<font size=-2><b>Last Login:</b> $lastlogin</font><br />\n";
		}
	    }	
443

444
	    echo "<font size=-2><b>Created by:</b> ".
445
		 "<a href='$showuser_url'>$huid</a>".
446
		 "</font><br />\n";
447

448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
	    $special = 0;
	    $pcs     = 0;
	    reset($perexp_usage);
	    if (isset($perexp_usage["$pid:$eid"])) {
		while (list ($class, $count) = each($perexp_usage["$pid:$eid"])) {
		    if (strcmp($class, "pc")) {
			$special += $count;
		    } else {
			$pcs += $count;
		    }
		}
	    }

	    if ($pcs) {
		if ($pcs == 1) { $plural = ""; } else { $plural = "s"; }  
		echo "<font size=-1><b>Using <font color=red>$pcs PC</font> Node$plural</b></font><br />\n";
	    }
	    if ($special) {
		if ($special == 1) { $plural = ""; } else { $plural = "s"; }  
		echo "<font size=-1><b>Using <font color=red>$special Special</font> Node$plural</b></font><br />\n";
	    }

470 471
	    echo "</td></tr></table> \n";
	    echo "</td>";
472

473
	    $thumbcount++;
474 475
	    if (($thumbcount % 2) == 0) { echo "</tr><tr>\n"; }
	}
476 477 478 479
    }

    echo "</tr></table>";
} else {
480 481 482

    $ni = ($noignore ? "&noignore=$noignore" : "");
    
483 484 485
    echo "<table border=2 cols=0
                 cellpadding=0 cellspacing=2 align=center>
            <tr>
Chad Barb's avatar
Chad Barb committed
486
              <th width=8%>
487
               <a class='static' href='showexp_list.php3?showtype=$showtype&sortby=pid$ni'>
488
                  PID</a></th>
Chad Barb's avatar
Chad Barb committed
489
              <th width=8%>
490
               <a class='static' href='showexp_list.php3?showtype=$showtype&sortby=eid$ni'>
491
                  EID</a></th>
Chad Barb's avatar
Chad Barb committed
492
              <th align=center width=3%>
493
               <a class='static' href='showexp_list.php3?showtype=$showtype&sortby=pcs$ni'>
494
                  PCs</a> [1]</th>
495
              <th align=center width=3%>
496
               <a class='static' href='showexp_list.php3?showtype=$showtype&sortby=idle$ni'>
497
               Hours Idle</a> [2]</th>\n";
498
    
499
    if ($showlastlogin)
Chad Barb's avatar
Chad Barb committed
500
        echo "<th width=17% align=center>Last Login</th>\n";
501
    if ($idle) {
502 503
	#echo "<th width=4% align=center colspan=2>Swap Requests</th>\n";
	echo "<th width=4% align=center>Swap Requests</th>\n";
504
    }
505

506 507 508 509 510 511 512 513 514
    if (! $openlist_member) {
	echo "<th width=60%>
                  <a class='static' ".
                     "href='showexp_list.php3?showtype=$showtype".
                     "&sortby=name$ni'>Description</a></th>\n";
    }
    echo "  <th width=4%>
               <a class='static' ".
                  "href='showexp_list.php3?showtype=$showtype&sortby=uid$ni'>
515
                  Head UID</a></th>
516 517
            </tr>\n";

518
    while ($row = mysql_fetch_array($experiments_result)) {
519 520 521
	$pid  = $row["pid"];
	$eid  = $row["eid"]; 
	$huid = $row["expt_head_uid"];
Leigh B. Stoller's avatar
Leigh B. Stoller committed
522
	$name = stripslashes($row["expt_name"]);
523
	$date = $row["dshort"];
524
	$state= $row["state"];
525 526 527 528
	$ignore = $row['idle_ignore'];
	$idlesec= $row["idlesec"];
	$swapreqs = $row["swap_requests"];
	$isidle = ($idlesec >= 3600*$idlehours);
529
	$stale = TBGetExptIdleStale($pid,$eid);
530
	$daysidle=0;
531
	$idletime = ($idlesec > 300 ? round($idlesec/3600,1) : 0);
532 533
	# reset pcs
	$pcs=0;
534 535 536 537 538

	if (! ($head_user = User::Lookup($huid))) {
	    TBERROR("Could not lookup object for user $huid", 1);
	}
	$showuser_url = CreateURL("showuser", $head_user);
539 540 541
	
	if ($swapreqs && !$isidle) {
	    $swapreqs = "";
542 543 544 545
	    mysql_query("update experiments set swap_requests='' ".
			"where pid='$pid' and eid='$eid'");
	}

546
	if ($isadmin) {
547 548 549
	    $swappable= $row["swappable"];
	    $swapreq=$row["swap_requests"];
	    $lastswapreq=$row["lastreq"];
550 551 552 553 554 555
	    if ($lastswapreq > $idletime) {
		# My last request was from _before_ it was idle this time
		mysql_query("update experiments set swap_requests='' ".
			    "where pid='$pid' and eid='$eid'");
		$swapreq=0;
	    }
556 557
	    $idlemailinterval = TBGetSiteVar("idle/mailinterval");
	    # Is it toosoon to send another mail?
558
	    $toosoon = ($swapreq>0 && ($lastswapreq < $idlemailinterval));
559
	    $lastlogin = "<td>";
560
	    if ($lastexpnodelogins = TBExpUidLastLogins($pid, $eid)) {
561
	        $daysidle=$lastexpnodelogins["daysidle"];
562 563
	        #if ($idle && $daysidle < 1)
		#  continue;
564
		$lastlogin .= $lastexpnodelogins["shortdate"] . " " .
565
		 "(" . $lastexpnodelogins["uid"] . ")";
566
	    } elseif ($state=="active") {
567
	        $daysidle=$row["lastswap"];
568
	        $lastlogin .= "$date swapin";
569
	    }
570 571
	    $lastlogin.="</td>\n";
	    if ($lastlogin=="<td></td>\n") { $lastlogin="<td>&nbsp;</td>\n"; }
572
	}
573
	
574
	if ($idle) {
575
	    # If it is ignored, skip it now.
576
	    if ($ignore && !$noignore) { continue; }
577
	    #$lastlogin .= "<td align=center>$daysidle</td>\n";
578 579 580
	    if (isset($perexp_usage["$pid:$eid"]) &&
		isset($perexp_usage["$pid:$eid"]["pc"])) {
	      $pcs = $perexp_usage["$pid:$eid"]["pc"];
581
	    }
582 583
	    $foo = "<td align=center valign=center>\n";
	    #$label = "";
584
	    # Probably do not need this when we are using stalemark
585
	    #if ($stale) { $label .= "stale "; }
586
	    # Do not really need this if we are marking ignore with ()
587 588 589 590 591 592 593 594 595 596 597 598
	    #if ($ignore) { $label .= "ignore "; }
	    #if (!$swappable) { $label .= "unswap. "; }
 	    #if ($isidle && !$stale && !$ignore && !$toosoon && $pcs) {
	    #    $fooswap = "<td><a ".
	    #       "href=\"request_swapexp.php3?pid=$pid&eid=$eid\">".
	    #       "<img border=0 src=\"redball.gif\"></a> $label</td>\n" ;
	    #} else {
	    #   if ($label == "") { $label = "&nbsp;"; }
	    #   $fooswap = "<td>$label</td>";
	    #   if (!$pcs) { $foo .= "(no PCs)\n"; }
	    #   else { $foo .="&nbsp;"; }
	    #}
599
	    if ($swapreq > 0) {
600
	      $foo .= "$swapreq&nbsp;sent<br>".
601
	              "<font size=-2>(${lastswapreq}&nbsp;hrs&nbsp;ago)</font>\n";
602
	    }
603 604 605
	    #$foo .= "</td>".$fooswap."\n"; 
	    if (!$swappable) { $foo .= "unswap.\n"; }
	    
606
	}
607

608
	if ($idle && (!$pcs || !$isidle)) { continue; }
609

610 611
	$nodes   = 0;
	$special = 0;
612 613 614 615
	reset($perexp_usage);
	if (isset($perexp_usage["$pid:$eid"])) {
	    while (list ($class, $count) = each($perexp_usage["$pid:$eid"])) {
		$nodes += $count;
616
		if (strcmp($class, "pc")) {
617
		    $special = 1;
618 619 620 621
		} else {
		    $pcs = $count;
		}

622 623 624 625 626 627
		# Summary counts for just the experiments in the projects
		# the user is a member of.
		if (!isset($total_usage[$class]))
		    $total_usage[$class] = 0;
			
		$total_usage[$class] += $count;
628
	    }
629
	}
630

631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
	$onmouseover = "";
	reset($perexp_types);
	if (isset($perexp_types["$pid:$eid"])) {
	    $mouseover  = "<table align=center ";
	    $mouseover .= " cellpadding=2 cellspacing=2 border=2> ";
	    $mouseover .= "<tr><th>Node Type</th><th>Count</th></tr> ";

	    while (list ($type, $count) = each($perexp_types["$pid:$eid"])) {
		$mouseover .= "<tr><td class=pad4>$type</td>";
		$mouseover .= "    <td class=pad4>$count</td></tr> ";

	    }
	    $mouseover .= "</table>";
	    $onmouseover  = "onmouseover=\"this.T_WIDTH=175; ";
	    $onmouseover .= "this.T_FONTSIZE='16px'; this.T_OFFSETX=0; ";
	    $onmouseover .= "return escape('$mouseover')\"";
	}

649 650
	# in idle or active, skip experiments with no nodes.
	if (($idle || $active) && $nodes == 0) { continue; }
651 652
	if ($nodes==0) { $nodes = "&nbsp;"; }
	
653 654
	echo "<tr>
                <td><A href='showproject.php3?pid=$pid'>$pid</A></td>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
655
                <td><A href='showexp.php3?pid=$pid&eid=$eid'>
656
                       $eid</A></td>\n";
657
	
658
	if ($isidle && !$ignore) { $nodes = $nodes.$idlemark; }
659 660
	# If multiple classes, then hightlight the number and show pcs/nodes.
	if ($special) {
661
	    echo "<td nowrap $onmouseover><font color=red>$nodes</font>";
662
	    if ($pcs)
663 664
		echo " ($pcs)";
	    echo "</td>\n";	    
665
	}
666
	else
667
            echo "<td $onmouseover>$nodes</td>\n";
668

Chad Barb's avatar
Chad Barb committed
669
	if ($idletime == -1) {
670
	    $idlestr = "&nbsp;";
Chad Barb's avatar
Chad Barb committed
671
	} else {
672 673 674 675
	    $idlestr = "$idletime";
	    # Order between the next two lines determines if the
	    # stalemark goes inside or outside the parens
	    if ($stale && $pcs > 0) { $idlestr .= $stalemark; }
676
	    if ($ignore && $idletime !=0) {
677 678
		$idlestr = "($idlestr)";
		$parens = 1;
679
	    }
Chad Barb's avatar
Chad Barb committed
680
	}
681
	echo "<td>$idlestr</td>";
682 683
	
	if ($showlastlogin) echo "$lastlogin\n";
684
	if ($idle) echo "$foo\n";
685

686 687 688 689
	if (! $openlist_member) {
	    echo "<td>$name</td>\n";
	}
	
690
        echo "<td><A href='$showuser_url'>$huid</A></td>\n";
691
	echo "</tr>\n";
692 693
    }
    echo "</table>\n";
694

695 696
    
    echo "<font size=-1><ol>
697
             <li><font color=red>Red</font> indicates nodes other than PCs.
698
                 A $idlemark mark by the node count indicates that the
699 700
                 experiment is currently considered idle. The number of
                 local pcs is indicated in the parens. 
701 702 703 704 705 706 707 708 709
             <li>A $stalemark indicates that the data is stale, and
		 at least one node in the experiment has not reported
		 on its proper schedule.\n";
    if ($parens) {
	# don't show this unless we did it... most users shouldn't ever
	# need to know that you can set expts to have their idleness ignored
	echo "Values are in parenthesis for idle-ignore experiments.\n";
    }
    echo "</ol></font>\n";
710 711
    
    echo "<center><b>Node Totals</b></center>\n";
712 713 714
    echo "<table border=0
                 cellpadding=1 cellspacing=1 align=center>\n";
    $total = 0;
715
    ksort($total_usage);
716 717 718 719
    while (list($type, $count) = each($total_usage)) {
	    $total += $count;
	    echo "<tr>
                    <td align=right>${type}:</td>
720
                    <td>&nbsp; &nbsp; &nbsp; &nbsp;</td>
721 722 723 724 725
                    <td align=center>$count</td>
                  </tr>\n";
    }
    echo "<tr>
             <td align=right><hr></td>
726
             <td>&nbsp; &nbsp; &nbsp; &nbsp;</td>
727 728 729 730
             <td align=center><hr></td>
          </tr>\n";
    echo "<tr>
             <td align=right><b>Total</b>:</td>
731
             <td>&nbsp; &nbsp; &nbsp; &nbsp;</td>
732 733 734 735
             <td align=center>$total</td>
          </tr>\n";
    
    echo "</table>\n";
736 737
} # if ($thumb && !$idle)
} # if (mysql_num_rows($experiments_result))
738 739 740 741 742 743

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