myexperiments.php 5.03 KB
Newer Older
Leigh B Stoller's avatar
Leigh B Stoller committed
1
2
<?php
#
3
# Copyright (c) 2000-2015 University of Utah and the Flux Group.
Leigh B Stoller's avatar
Leigh B Stoller committed
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
# 
# {{{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

$query_result =
Leigh B Stoller's avatar
Leigh B Stoller committed
65
66
67
68
    DBQueryFatal("select a.*,s.expires,s.hrn,u.email, ".
                 " (UNIX_TIMESTAMP(now()) > ".
                 "  UNIX_TIMESTAMP(s.expires)) as expired ".
                 "  from apt_instances as a ".
69
70
                 "left join geni.geni_slices as s on ".
                 "     s.uuid=a.slice_uuid ".
Leigh B Stoller's avatar
Leigh B Stoller committed
71
		 "left join geni.geni_users as u on u.uuid=a.creator_uuid ".
Leigh B Stoller's avatar
Leigh B Stoller committed
72
		 (isset($all) && ISADMIN() ?
73
74
		  "order by a.creator" :
                  "where a.creator_uuid='$target_uuid'"));
Leigh B Stoller's avatar
Leigh B Stoller committed
75
76

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

    if (ISADMIN()) {
81
	$message .= "<img src='images/redball.gif'>".
82
83
84
	    "<a href='myexperiments.php?all=1'>Show all user Experiments</a>";
    }
    SPITUSERERROR($message);
Leigh B Stoller's avatar
Leigh B Stoller committed
85
86
87
    exit();
}
echo "<div class='row'>
88
89
90
       <div class='col-lg-10 col-lg-offset-1
                   col-md-10 col-md-offset-1
                   col-sm-12 col-sm-offset-0
91
                   col-xs-12 col-xs-offset-0'>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
92

Leigh B Stoller's avatar
Leigh B Stoller committed
93
echo "<input class='form-control search' type='search' data-column='all'
Leigh B Stoller's avatar
Leigh B Stoller committed
94
95
96
97
98
99
100
             id='experiment_search' placeholder='Search'>\n";

echo "  <table class='tablesorter'>
         <thead>
          <tr>
           <th>Profile</th>\n";
if (isset($all) && ISADMIN()) {
101
    echo " <th>Slice</th>";
Leigh B Stoller's avatar
Leigh B Stoller committed
102
    echo " <th>Creator</th>";
103
    echo " <th>Project</th>";
Leigh B Stoller's avatar
Leigh B Stoller committed
104
105
106
}
echo "     <th>Status</th>
           <th>Created</th>
107
           <th>Expires</th>
Leigh B Stoller's avatar
Leigh B Stoller committed
108
109
110
111
112
          </tr>
         </thead>
         <tbody>\n";

while ($row = mysql_fetch_array($query_result)) {
113
114
    $profile_id   = $row["profile_id"];
    $version      = $row["profile_version"];
Leigh B Stoller's avatar
Leigh B Stoller committed
115
116
    $uuid         = $row["uuid"];
    $status       = $row["status"];
117
    $created      = DateStringGMT($row["created"]);
118
    $expires      = DateStringGMT($row["expires"]);
Leigh B Stoller's avatar
Leigh B Stoller committed
119
    $creator_idx  = $row["creator_idx"];
120
    $profile_name = $profile_id;
Leigh B Stoller's avatar
Leigh B Stoller committed
121
    $creator_uid  = $row["creator"];
122
    $pid          = $row["pid"];
123
    list($foo,$hrn) = preg_split("/\./", $row["hrn"]);
Leigh B Stoller's avatar
Leigh B Stoller committed
124
125
126
127
128
129
130
131
132
    $email        = $row["email"];
    # If a guest user, use email instead.
    if (isset($email)) {
        $creator = $email;
    }
    else {
        $creator = "<a href='$TBBASE/showuser.php3?user=$creator_idx'>".
            "$creator_uid</a>";
    }
Leigh B Stoller's avatar
Leigh B Stoller committed
133
134
135
    if ($row["expired"]) {
        $status = "expired";
    }
Leigh B Stoller's avatar
Leigh B Stoller committed
136

137
    $profile = Profile::Lookup($profile_id, $version);
Leigh B Stoller's avatar
Leigh B Stoller committed
138
139
140
141
142
143
144
145
146
    if ($profile) {
	$profile_name = $profile->name();
    }

    echo " <tr>
            <td>
             <a href='status.php?uuid=$uuid'>$profile_name</a>
            </td>";
    if (isset($all) && ISADMIN()) {
147
	echo "<td>$hrn</td>";
Leigh B Stoller's avatar
Leigh B Stoller committed
148
	echo "<td>$creator</td>";
149
	echo "<td>$pid</td>";
Leigh B Stoller's avatar
Leigh B Stoller committed
150
151
    }
    echo "  <td>$status</td>
152
            <td class='format-date'>$created</td>
153
            <td class='format-date'>$expires</td>
Leigh B Stoller's avatar
Leigh B Stoller committed
154
155
156
           </tr>\n";
}
echo "   </tbody>
157
158
        </table>\n";

Leigh B Stoller's avatar
Leigh B Stoller committed
159
if (ISADMIN() && !isset($all)) {
160
    echo "<img src='images/redball.gif'>
161
162
163
          <a href='myexperiments.php?all=1'>Show all user Experiments</a>\n";
}
echo " </div>
Leigh B Stoller's avatar
Leigh B Stoller committed
164
165
      </div>\n";

166
echo "<script src='js/lib/jquery-2.0.3.min.js'></script>\n";
167
168
echo "<script src='js/lib/jquery.tablesorter.min.js'></script>\n";
echo "<script src='js/lib/jquery.tablesorter.widgets.min.js'></script>\n";
169
echo "<script src='js/lib/bootstrap.js'></script>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
170
171
172
173
echo "<script src='js/lib/require.js' data-main='js/myexperiments'></script>\n";

SPITFOOTER();
?>