showexpstats.php3 3.62 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2010 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/>.
# 
# }}}
23 24 25
#
include("defs.php3");

26 27 28 29 30
#
# This page needs more work to make user friendly and flexible.
# Its a hack job at the moment.
# 

31
#
32
# Only known and logged in users.
33
#
34 35
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
36
$uid_idx   = $this_user->uid_idx();
37
$isadmin   = ISADMIN();
38

39 40 41 42 43
#
# Verify page arguments
#
$optargs = OptionalPageArguments("record", PAGEARG_INTEGER);

44 45 46 47 48
#
# Standard Testbed Header
#
PAGEHEADER("Show Experiment Information");

49
#
50 51
# Right now we show just the last N records entered, unless the user
# requested a specific record. 
52
#
53
if (isset($record)) {
54 55
    $wclause = "";
    if (! $isadmin) {
56
	$wclause = "and s.creator_idx='$uid_idx'";
57
    }
58
    $query_result =
59
	DBQueryFatal("select s.*,'foo',r.* from experiment_stats as s ".
60 61 62
		     "left join experiment_resources as r on ".
		     " r.exptidx=s.exptidx ".
		     "where s.exptidx=$record $wclause ".
63
		     "order by r.tstamp desc");
64

65 66 67 68 69
    if (mysql_num_rows($query_result) == 0) {
	USERERROR("No such experiment record $record in the system!", 1);
    }
}
else {
70 71
    $wclause = "";
    if (! $isadmin) {
72
	$wclause = "where s.creator_idx='$uid_idx'";
73
    }
74
    $query_result =
75
	DBQueryFatal("select s.*,'foo',r.* from experiment_stats as s ".
76 77 78 79
		     "left join experiment_resources as r on ".
		     " r.exptidx=s.exptidx ".
		     "$wclause ".
		     "order by s.exptidx desc,r.idx asc limit 200");
80 81 82 83

    if (mysql_num_rows($query_result) == 0) {
	USERERROR("No experiment records in the system!", 1);
    }
84 85 86 87 88 89 90 91 92 93 94
}

#
# Use first row to get the column headers (no pretty printing yet).
# 
$row = mysql_fetch_assoc($query_result);

echo "<table align=center border=1>\n";
echo "<tr>\n";
foreach($row as $key => $value) {
    $key = str_replace("_", " ", $key);
95 96 97

    if ($key == "foo")
	continue;
98 99 100 101 102 103 104
    
    echo "<th><font size=-1>$key</font></th>\n";
}
echo "</tr>\n";

mysql_data_seek($query_result, 0);

105 106 107
$print_header = 0;
$last_exptidx = 0;

108
while ($row = mysql_fetch_assoc($query_result)) {
109 110
    $rsrcidx = $row["idx"];
    $exptidx = $row["exptidx"];
111 112 113 114 115 116 117 118

    $skipping = 1;

    if ($last_exptidx != $exptidx) {
	$print_header  = 1;
	$last_exptidx = $exptidx;
    }

119 120
    echo "<tr>\n";
    foreach($row as $key => $value) {
121 122 123 124 125
	if ($key == "thumbnail") {
	    echo "<td nowrap>
                     <a href='showthumb.php3?idx=$rsrcidx'>Thumbnail</a>
                  </td>\n";
	}
126 127 128 129 130
	elseif ($key == "input_data_idx") {
	    echo "<td nowrap>
                     <a href='spitnsdata.php3?record=$rsrcidx'>$value</a>
                  </td>\n";
	}
131
	else {
132 133 134 135 136 137 138 139 140 141 142
	    if (!$print_header && $skipping) {
		if ($key == "foo") {
		    $skipping = 0;
		    continue;
		}
		echo "<td nowrap>&nbsp</td>\n";		
		continue;
	    }
	    if ($key == "foo")
		continue;
	    
143 144
	    echo "<td nowrap>$value</td>\n";
	}
145
    }
146
    $print_header = 0;
147 148 149 150 151 152 153 154 155
    echo "</tr>\n";
}
echo "</table>\n";

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