archive_tags.php3 3.88 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
5 6 7 8 9 10 11
# All rights reserved.
#
include("defs.php3");

#
# Only known and logged in users can end experiments.
#
12 13 14
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
15

16 17 18
#
# Verify page arguments.
#
19 20 21 22 23 24 25 26 27 28 29 30 31
$optargs = OptionalPageArguments("index",      PAGEARG_INTEGER,
				 "experiment", PAGEARG_EXPERIMENT,
				 "template",   PAGEARG_TEMPLATE,
				 "instance",   PAGEARG_INSTANCE,
				 "records",    PAGEARG_INTEGER,
				 "tag",        PAGEARG_STRING);

#
# An instance might be a current or historical. If its a template, use
# the underlying experiment of the template.
#
if (isset($instance)) {
    if (($foo = $instance->GetExperiment()))
Leigh B. Stoller's avatar
Leigh B. Stoller committed
32
	$experiment = $foo;
33 34 35 36 37 38 39 40 41
    else
	$index = $instance->exptidx();
    $template = $instance->GetTemplate();
}
elseif (isset($template)) {
    $experiment = $template->GetExperiment();
}
elseif (isset($index)) {
    $experiment = Experiment::Lookup($index);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
42
}
43 44

#
45 46
# If we got a current experiment, great. Otherwise we have to lookup
# data for a historical experiment.
47
#
48
if (isset($experiment) && $experiment) {
49 50 51
    # Need these below.
    $pid = $experiment->pid();
    $eid = $experiment->eid();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
52
    $exptidx = $experiment->idx();
53

54 55 56 57 58 59
    $stats = $experiment->GetStats();
    if (!$stats) {
	TBERROR("Could not load stats object for experiment $pid/$eid", 1);
    }
    $archive_idx = $stats->archive_idx();

60 61 62 63 64 65
    # Permission
    if (!$isadmin &&
	!$experiment->AccessCheck($this_user, $TB_EXPT_READINFO)) {
	USERERROR("You do not have permission to view tags for ".
		  "archive in $pid/$eid!", 1);
    }
66
}
67 68
elseif (isset($index)) {
    $stats = ExperimentStats::Lookup($index);
69
    if (!$stats) {
70
	PAGEARGERROR("Invalid experiment index: $index");
71
    }
72

73 74 75
    # Need these below.
    $pid = $stats->pid();
    $eid = $stats->eid();
76 77
    $exptidx = $index;
    $archive_idx = $stats->archive_idx();
78 79 80 81 82 83 84

    # Permission
    if (!$isadmin &&
	!$stats->AccessCheck($this_user, $TB_PROJECT_READINFO)) {
	USERERROR("You do not have permission to view tags for ".
		  "archive in $pid/$eid!", 1);
    }
85 86
}
else {
87 88 89
    PAGEARGERROR("Must provide a current or former experiment index");
}

90 91 92 93 94
#
# Standard Testbed Header
#
PAGEHEADER("Archive Tags");

95 96 97
# Show just the last N records unless request is different.
if (!isset($records)) {
    $records = 100;
98 99
}

100
echo "<center>\n";
Russ Fish's avatar
Russ Fish committed
101
if (isset($instance)) {
102 103 104
    echo $instance->PageHeader();
    $url = CreateURL("archive_view", $instance);
}
Russ Fish's avatar
Russ Fish committed
105
elseif (isset($template)) {
106 107
    echo $template->PageHeader();
    $url = CreateURL("archive_view", $template);
108 109 110
}
else {
    echo $stats->PageHeader();
111
    $url = CreateURL("archive_view", "index", $exptidx);
112 113
}
echo "</center>\n";
114 115 116 117 118 119
echo "<br>\n";

#
# Grab all the (commit/user) tags.
#
$query_result =
120
    DBQueryFatal("select *,FROM_UNIXTIME(date_created) as date_created ".
121 122
		 "  from archive_revisions ".
		 "where archive_idx='$archive_idx' and view='$exptidx' " .
123
		 "order by date_created desc");
124 125 126 127 128 129 130 131

if (mysql_num_rows($query_result) == 0) {
    USERERROR("No tags for experiment $pid/$eid", 1);
}

echo "<table align=center border=1>
      <tr>";
echo "  <th>Run</th>";
132
echo "  <th>Tag (Click to visit archive)</th>";
133 134 135 136 137
echo "  <th>Date</th>";
echo "  <th>Description</th>";
echo "</tr>\n";

while ($row = mysql_fetch_assoc($query_result)) {
138 139 140 141
    $archive_tag  = $row["tag"];
    $date_tagged  = $row["date_created"];
    $description  = $row["description"];
    $archive_view = $url . "&tag=$archive_tag";
142 143 144

    echo "<tr>";
    echo "  <td align=center>
145
                <a href=beginexp_html.php3?copyid=$exptidx:$archive_tag>
146 147
                    <img border=0 alt=Run src=greenball.gif></a></td>";
    echo "  <td>".
148
	     "<a href='$archive_view'>$archive_tag</a>".
149 150 151 152 153 154 155 156 157 158 159 160 161
	 "  </td>";
    
    echo "  <td>$date_tagged</td>";
    echo "  <td>$description</td>";
    echo "</tr>\n";
}
echo "</table>\n";

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