reserve.php 5.01 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2019 University of Utah and the Flux Group.
4
#
5
# {{{EMULAB-LICENSE
6
#
7
# This file is part of the Emulab network testbed software.
8
#
9 10 11 12
# 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.
13
#
14 15 16 17
# 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.
18
#
19 20
# 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/>.
21
#
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
# }}}
#
chdir("..");
include("defs.php3");
include_once("geni_defs.php");
chdir("apt");
include("quickvm_sup.php");
include_once("instance_defs.php");
include_once("aggregate_defs.php");
$page_title = "Reservations";

#
# Get current user.
#
RedirectSecure();
$this_user = CheckLoginOrRedirect();
38 39 40
if (NOPROJECTMEMBERSHIP()) {
    return NoProjectMembershipError($this_user);
}
41 42 43 44 45 46 47
$isadmin   = (ISADMIN() ? 1 : 0);
$isfadmin  = (ISFOREIGN_ADMIN() ? 1 : 0);

#
# Verify page arguments. Cluster is a domain that we turn into a URN.
#
$optargs = OptionalPageArguments("edit",     PAGEARG_BOOLEAN,
48
                                 "debug",    PAGEARG_BOOLEAN,
49
                                 "cluster",  PAGEARG_STRING,
50
                                 "project",  PAGEARG_PROJECT,
51
                                 "uuid",     PAGEARG_UUID);
52 53

if ($edit) {
54
    if (! (isset($cluster) && isset($uuid))) {
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
        SPITUSERERROR("Missing arguments for edit mode");
        exit();
    }
    $aggregate = Aggregate::LookupByNickname($cluster);
    if (!$aggregate) {
        SPITUSERERROR("No such cluster: $cluster");
        exit();
    }
}

SPITHEADER(1);

echo "<link rel='stylesheet'
            href='css/jquery-ui.min.css'>\n";
echo "<link rel='stylesheet'
            href='css/tablesorter.css'>\n";
71 72
echo "<link rel='stylesheet'
            href='css/nv.d3.css'>\n";
73 74 75 76 77 78

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

# Place to hang the modals for now
echo "<div id='oops_div'></div>
79
      <div id='waitwait_div'></div>\n";
80 81 82 83 84 85 86 87 88 89 90 91

#
# See what projects the user can do this in.
#
$projlist = $this_user->ProjectAccessList($TB_PROJECT_CREATEEXPT);

#
# Pass project list through. Need to convert to list without groups.
# When editing, pass through a single value. The template treats a
# a single value as a read-only field.
#
$plist = array();
92 93 94 95 96
while (list($p) = each($projlist)) {
    $plist[] = $p;
}
if (ISADMIN() && isset($project)) {
    $plist[] = $project->pid();
97 98 99 100 101 102 103 104 105
}
echo "<script type='text/plain' id='projects-json'>\n";
echo htmlentities(json_encode($plist));
echo "</script>\n";

# List of clusters.
if ($edit) {
    $ams = array($aggregate);
}
106 107 108
elseif (isset($debug) && $debug) {
    $ams = array(Aggregate::ThisAggregate());
}
109
else {
110
    $ams = Aggregate::SupportsReservations($this_user);
111
}
112 113 114 115
if (!count($ams)) {
    SPITUSERERROR("No clusters support reservations.");
    exit();
}
116 117 118 119
$amlist  = array();
while (list($index, $aggregate) = each($ams)) {
    $urn = $aggregate->urn();
    $am  = $aggregate->name();
120

121 122 123 124 125 126 127 128 129 130 131 132
    $amlist[$urn] = array("urn"      => $urn,
                          "name"     => $am,
                          "nickname" => $aggregate->nickname(),
                          "typeinfo" => $aggregate->typeinfo);
}
echo "<script type='text/plain' id='amlist-json'>\n";
echo htmlentities(json_encode($amlist));
echo "</script>\n";

$defaults = array();
$defaults["pid"]   = '';
# Default project.
133 134 135
if (ISADMIN() && isset($project)) {
    $defaults["pid"]   = $project->pid();
}
136 137
elseif (count($plist) == 1) {
    $defaults["pid"] = $plist[0];
138 139 140 141 142 143 144 145 146
}
echo "<script type='text/plain' id='form-json'>\n";
echo htmlentities(json_encode($defaults)) . "\n";
echo "</script>\n";

echo "<script type='text/javascript'>\n";
if ($edit) {
    echo "   window.EDITING  = true;\n";
    echo "   window.CLUSTER  = '$cluster';\n";
147
    echo "   window.ISADMIN  = $isadmin;\n";
148
    echo "   window.UUID     = '$uuid';\n";
149 150 151 152 153 154 155 156 157 158
}
else {
    echo "   window.EDITING  = false;\n";
}
echo "</script>\n";

REQUIRE_UNDERSCORE();
REQUIRE_SUP();
REQUIRE_MOMENT();
REQUIRE_APTFORMS();
159 160
AddLibrary("js/resgraphs.js");
AddTemplateList(array("reserve-request", "reserve-faq", "reservation-graph",
161 162
                      "oops-modal", "waitwait-modal", "confirm-modal",
                      "resusage-graph"));
163
SPITREQUIRE("js/reserve.js",
164 165
            "<script src='js/lib/d3.v3.js'></script>\n".
            "<script src='js/lib/nv.d3.js'></script>\n".
166 167 168 169 170 171 172
            "<script src='js/lib/jquery.tablesorter.min.js'></script>\n".
            "<script src='js/lib/jquery.tablesorter.widgets.min.js'></script>".
            "<script src='js/lib/sugar.min.js'></script>".
            "<script src='js/lib/jquery.tablesorter.parser-date.js'></script>".
            "<script src='js/lib/jquery-ui.js'></script>");
SPITFOOTER();
?>