activity.php 6.56 KB
Newer Older
1
2
<?php
#
3
# Copyright (c) 2000-2018 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
23
24
25
26
27
28
29
30
# 
# {{{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");
chdir("apt");
include("quickvm_sup.php");
include("profile_defs.php");
$page_title = "My Profiles";

31
32
33
34
35
36
37
#
# Verify page arguments.
#
$optargs = OptionalPageArguments("target_user",    PAGEARG_USER,
				 "target_project", PAGEARG_PROJECT,
                                 "min",            PAGEARG_INTEGER,
                                 "max",            PAGEARG_INTEGER);
38
39
40
41
#
# Get current user.
#
RedirectSecure();
42
$this_user = CheckLoginOrRedirect();
43
44
SPITHEADER(1);

45
if (!(ISADMIN() || ISFOREIGN_ADMIN())) {
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    if (isset($target_user)) {
        if (!$target_user->SameUser($this_user)) {
            SPITUSERERROR("Not enough permission to view this page!");
        }
    }
    elseif (isset($target_project)) {
        $approved = 0;
        
        if (!$target_project->IsMember($this_user, $approved) && $approved) {
            SPITUSERERROR("Not enough permission to view this page!");
        }
    }
    else {
        $target_user = $this_user;
    }
61
62
63
64
}
$instances = array();

#
65
# Allow for targeted searches
66
#
67
68
69
70
71
72
73
74
75
76
$whereclause = "";

if (isset($target_user)) {
    $target_idx  = $target_user->idx();
    $whereclause = "where h.creator_idx='$target_idx'";
}
elseif (isset($target_project)) {
    $target_idx   = $target_project->pid_idx();
    $whereclause = "where h.pid_idx='$target_idx'";
}
77
78
79
80
# Lets default to last three months if neither min or max provided
if (! (isset($min) || isset($max))) {
    $min = time() - (90 * 3600 * 24);
}
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
if (isset($min) || isset($max)) {
    if ($whereclause != "") {
        $whereclause = "$whereclause and ";
    }
    else {
        $whereclause = "where ";
    }
    if (isset($min)) {
        $whereclause .= "UNIX_TIMESTAMP(h.created) > $min ";
        if (isset($max)) {
            $whereclause .= "and ";
        }
    }
    if (isset($max)) {
        $whereclause .= "UNIX_TIMESTAMP(h.created) < $max ";
    }
}

$query_result =
100
    DBQueryFatal("select h.uuid,h.profile_version,h.created,h.destroyed, ".
Leigh B Stoller's avatar
Leigh B Stoller committed
101
		 "    h.creator,p.uuid as profile_uuid,h.pid,u.email, ".
102
103
                 "    h.physnode_count,h.virtnode_count,".
                 "    h.name as instance_name,p.name as profile_name, ".
104
105
106
                 "    truncate(h.physnode_count * ".
                 "      ((UNIX_TIMESTAMP(h.destroyed) - ".
                 "        UNIX_TIMESTAMP(h.created)) / 3600.0),2) as phours ".
107
108
109
110
		 "  from apt_instance_history as h ".
		 "left join apt_profile_versions as p on ".
		 "     p.profileid=h.profile_id and ".
		 "     p.version=h.profile_version ".
111
		 "left join geni.geni_users as u on u.uuid=h.creator_uuid ".
112
                 $whereclause . " " .
113
114
		 "order by h.created desc");

115
if (mysql_num_rows($query_result) == 0) {
116
117
118
119
120
    $message = "<b>Oops, there is no activity to show you.</b><br>";
    SPITUSERERROR($message);
    exit();
}

121
if (1) {
122
    while ($row = mysql_fetch_array($query_result)) {
123
        $uuid      = $row["uuid"];
124
125
	$pname     = $row["profile_name"];
        $iname     = $row["instance_name"];
126
127
	$pproj     = $row["pid"];
	$puuid     = $row["profile_uuid"];
128
129
	$created   = DateStringGMT($row["created"]);
	$destroyed = DateStringGMT($row["destroyed"]);
130
	$creator   = $row["creator"];
131
	$email     = $row["email"];
132
133
134
135
136
137
138
139
140
141
        $pcount    = $row["physnode_count"];
        $vcount    = $row["virtnode_count"];
        $phours    = $row["phours"];
        # Backwards compat.
        if (!isset($pproj)) {
            $pproj = "";
        }
        if (!isset($destroyed)) {
            $destroyed = "";
        }
142
143
144
        if (!isset($iname)) {
            $iname = "&nbsp;";
        }
145
        
146
147
148
149
	# If a guest user, use email instead.
	if (isset($email)) {
	    $creator = $email;
	}
150

151
152
153
        # Save space with array instead of hash.
	$instance =
            array($pname, $pproj, $puuid, $pcount, $vcount,
154
                  $creator, $created, $destroyed, $phours, $iname, $uuid);
155
                          
156
157
158
159
160
161
162
163
164
	$instances[] = $instance;
    }
}

# Place to hang the toplevel template.
echo "<div id='activity-body'></div>\n";

echo "<script type='text/javascript'>\n";
echo "    window.AJAXURL  = 'server-ajax.php';\n";
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
if (isset($min)) {
    echo "    window.MIN  = $min;\n";
}
else {
    echo "    window.MIN  = null;\n";
}
if (isset($max)) {
    echo "    window.MAX  = $max;\n";
}
else {
    echo "    window.MAX  = null;\n";
}
if (isset($target_user)) {
    echo "    window.ARG = 'user=$target_idx';\n";
}
elseif (isset($target_project)) {
    echo "    window.ARG = 'project=$target_idx';\n";
}
else {
    echo "    window.ARG = null;\n";
}
186
187
188
189
echo "</script>\n";
echo "<script type='text/plain' id='instances-json'>\n";
echo json_encode($instances);
echo "</script>\n";
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
echo "<link rel='stylesheet' href='css/tablesorter.css'>\n";
echo "<link rel='stylesheet' href='css/jQRangeSlider.css'>\n";
echo "<script src='js/lib/jquery-ui.js'></script>\n";
echo "<script src='js/lib/jQRangeSlider/jQRangeSliderMouseTouch.js'></script>\n";
echo "<script src='js/lib/jQRangeSlider/jQRangeSliderDraggable.js'></script>\n";
echo "<script src='js/lib/jQRangeSlider/jQRangeSliderHandle.js'></script>\n";
echo "<script src='js/lib/jQRangeSlider/jQRangeSliderBar.js'></script>\n";
echo "<script src='js/lib/jQRangeSlider/jQRangeSliderLabel.js'></script>\n";
echo "<script src='js/lib/jQRangeSlider/jQRangeSlider.js'></script>\n";
echo "<script src='js/lib/jQRangeSlider/jQDateRangeSliderHandle.js'></script>\n";
echo "<script src='js/lib/jQRangeSlider/jQDateRangeSlider.js'></script>\n";
echo "<script src='js/lib/jQRangeSlider/jQRuler.js'></script>\n";
echo "<script src='js/lib/jquery.tablesorter.min.js'></script>\n";
echo "<script src='js/lib/jquery.tablesorter.widgets.min.js'></script>\n";
echo "<script src='js/lib/jquery.tablesorter.widget-math.js'></script>\n";
205
206
207
208
209
210
211

REQUIRE_UNDERSCORE();
REQUIRE_SUP();
REQUIRE_MOMENT();
SPITREQUIRE("js/activity.js");

AddTemplate("activity");
212
213
214

SPITFOOTER();
?>