myexperiments.php 3.9 KB
Newer Older
Leigh B Stoller's avatar
Leigh B Stoller committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
<?php
#
# Copyright (c) 2000-2014 University of Utah and the Flux Group.
# 
# {{{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/>.
# 
# }}}
#
chdir("..");
include("defs.php3");
include_once("geni_defs.php");
chdir("apt");
include("quickvm_sup.php");
include("profile_defs.php");
include("instance_defs.php");
$page_title = "My Experiments";
$dblink = GetDBLink("sa");

#
# Verify page arguments.
#
$optargs = OptionalPageArguments("target_user",   PAGEARG_USER,
				 "all",           PAGEARG_BOOLEAN);

#
# Get current user.
#
RedirectSecure();
44 45
$this_user = CheckLoginOrRedirect();

Leigh B Stoller's avatar
Leigh B Stoller committed
46 47 48 49 50 51 52
if (!isset($target_user)) {
    $target_user = $this_user;
}
if (!$this_user->SameUser($target_user)) {
    if (!ISADMIN()) {
	SPITUSERERROR("You do not have permission to view ".
		      "target user's profiles");
53
	exit();
Leigh B Stoller's avatar
Leigh B Stoller committed
54 55 56 57 58 59 60 61
    }
}
$target_idx  = $target_user->uid_idx();
$target_uuid = $target_user->uuid();

SPITHEADER(1);

echo "<link rel='stylesheet'
62
            href='css/tablesorter.css'>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
63 64 65 66 67 68 69

$query_result =
    DBQueryFatal("select * from apt_instances ".
		 (isset($all) && ISADMIN() ?
		  "order by creator" : "where creator_uuid='$target_uuid'"));

if (mysql_num_rows($query_result) == 0) {
70 71 72 73
    $message = "<b>No experiments to show you. Maybe you want to ".
	"<a href='instantiate.php'>start one?</a></b><br><br>";

    if (ISADMIN()) {
74
	$message .= "<img src='images/redball.gif'>".
75 76 77
	    "<a href='myexperiments.php?all=1'>Show all user Experiments</a>";
    }
    SPITUSERERROR($message);
Leigh B Stoller's avatar
Leigh B Stoller committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
    exit();
}
echo "<div class='row'>
       <div class='col-lg-6 col-lg-offset-3
                   col-md-6 col-md-offset-3
                   col-sm-6 col-sm-offset-3
                   col-xs-4 col-xs-offset-4'>\n";

echo "<input class='form-control search' type='search'
             id='experiment_search' placeholder='Search'>\n";

echo "  <table class='tablesorter'>
         <thead>
          <tr>
           <th>Profile</th>\n";
if (isset($all) && ISADMIN()) {
    echo " <th>Creator</th>";
}
echo "     <th>Status</th>
           <th>Created</th>
          </tr>
         </thead>
         <tbody>\n";

while ($row = mysql_fetch_array($query_result)) {
103 104
    $profile_id   = $row["profile_id"];
    $version      = $row["profile_version"];
Leigh B Stoller's avatar
Leigh B Stoller committed
105 106
    $uuid         = $row["uuid"];
    $status       = $row["status"];
107
    $created      = DateStringGMT($row["created"]);
Leigh B Stoller's avatar
Leigh B Stoller committed
108
    $creator_idx  = $row["creator_idx"];
109
    $profile_name = $profile_id;
Leigh B Stoller's avatar
Leigh B Stoller committed
110 111
    $creator_uid  = $row["creator"];

112
    $profile = Profile::Lookup($profile_id, $version);
Leigh B Stoller's avatar
Leigh B Stoller committed
113 114 115 116 117 118 119 120 121 122 123 124
    if ($profile) {
	$profile_name = $profile->name();
    }

    echo " <tr>
            <td>
             <a href='status.php?uuid=$uuid'>$profile_name</a>
            </td>";
    if (isset($all) && ISADMIN()) {
	echo "<td>$creator_uid</td>";
    }
    echo "  <td>$status</td>
125
            <td class='format-date'>$created</td>
Leigh B Stoller's avatar
Leigh B Stoller committed
126 127 128
           </tr>\n";
}
echo "   </tbody>
129 130
        </table>\n";

Leigh B Stoller's avatar
Leigh B Stoller committed
131
if (ISADMIN() && !isset($all)) {
132
    echo "<img src='images/redball.gif'>
133 134 135
          <a href='myexperiments.php?all=1'>Show all user Experiments</a>\n";
}
echo " </div>
Leigh B Stoller's avatar
Leigh B Stoller committed
136 137
      </div>\n";

138
echo "<script src='js/lib/jquery-2.0.3.min.js'></script>\n";
139
echo "<script src='js/lib/bootstrap.js'></script>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
140 141 142 143
echo "<script src='js/lib/require.js' data-main='js/myexperiments'></script>\n";

SPITFOOTER();
?>