archive_tags.php3 4.56 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2007 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 26 27 28
#
include("defs.php3");

#
# Only known and logged in users can end experiments.
#
29 30 31
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
32

33 34 35
#
# Verify page arguments.
#
36 37 38 39 40 41 42 43 44 45 46 47 48
$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 Stoller's avatar
Leigh Stoller committed
49
	$experiment = $foo;
50 51 52 53 54 55 56 57 58
    else
	$index = $instance->exptidx();
    $template = $instance->GetTemplate();
}
elseif (isset($template)) {
    $experiment = $template->GetExperiment();
}
elseif (isset($index)) {
    $experiment = Experiment::Lookup($index);
Leigh Stoller's avatar
Leigh Stoller committed
59
}
60 61

#
62 63
# If we got a current experiment, great. Otherwise we have to lookup
# data for a historical experiment.
64
#
65
if (isset($experiment) && $experiment) {
66 67 68
    # Need these below.
    $pid = $experiment->pid();
    $eid = $experiment->eid();
Leigh Stoller's avatar
Leigh Stoller committed
69
    $exptidx = $experiment->idx();
70

71 72 73 74 75 76
    $stats = $experiment->GetStats();
    if (!$stats) {
	TBERROR("Could not load stats object for experiment $pid/$eid", 1);
    }
    $archive_idx = $stats->archive_idx();

77 78 79 80 81 82
    # 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);
    }
83
}
84 85
elseif (isset($index)) {
    $stats = ExperimentStats::Lookup($index);
86
    if (!$stats) {
87
	PAGEARGERROR("Invalid experiment index: $index");
88
    }
89

90 91 92
    # Need these below.
    $pid = $stats->pid();
    $eid = $stats->eid();
93 94
    $exptidx = $index;
    $archive_idx = $stats->archive_idx();
95 96 97 98 99 100 101

    # 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);
    }
102 103
}
else {
104 105 106
    PAGEARGERROR("Must provide a current or former experiment index");
}

107 108 109 110 111
#
# Standard Testbed Header
#
PAGEHEADER("Archive Tags");

112 113 114
# Show just the last N records unless request is different.
if (!isset($records)) {
    $records = 100;
115 116
}

117
echo "<center>\n";
Russ Fish's avatar
Russ Fish committed
118
if (isset($instance)) {
119 120 121
    echo $instance->PageHeader();
    $url = CreateURL("archive_view", $instance);
}
Russ Fish's avatar
Russ Fish committed
122
elseif (isset($template)) {
123 124
    echo $template->PageHeader();
    $url = CreateURL("archive_view", $template);
125 126 127
}
else {
    echo $stats->PageHeader();
128
    $url = CreateURL("archive_view", "index", $exptidx);
129 130
}
echo "</center>\n";
131 132 133 134 135 136
echo "<br>\n";

#
# Grab all the (commit/user) tags.
#
$query_result =
137
    DBQueryFatal("select *,FROM_UNIXTIME(date_created) as date_created ".
138 139
		 "  from archive_revisions ".
		 "where archive_idx='$archive_idx' and view='$exptidx' " .
140
		 "order by date_created desc");
141 142 143 144 145 146 147 148

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>";
149
echo "  <th>Tag (Click to visit archive)</th>";
150 151 152 153 154
echo "  <th>Date</th>";
echo "  <th>Description</th>";
echo "</tr>\n";

while ($row = mysql_fetch_assoc($query_result)) {
155 156 157 158
    $archive_tag  = $row["tag"];
    $date_tagged  = $row["date_created"];
    $description  = $row["description"];
    $archive_view = $url . "&tag=$archive_tag";
159 160 161

    echo "<tr>";
    echo "  <td align=center>
162
                <a href=beginexp.php?copyid=$exptidx:$archive_tag>
163 164
                    <img border=0 alt=Run src=greenball.gif></a></td>";
    echo "  <td>".
165
	     "<a href='$archive_view'>$archive_tag</a>".
166 167 168 169 170 171 172 173 174 175 176 177 178
	 "  </td>";
    
    echo "  <td>$date_tagged</td>";
    echo "  <td>$description</td>";
    echo "</tr>\n";
}
echo "</table>\n";

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