prereserve_node.php3 3.45 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
#
include("defs.php3");
25
include_once("node_defs.php");
26 27 28 29

#
# Only admin people!
#
30 31 32
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
33 34 35 36 37 38 39

if (! $isadmin) {
    USERERROR("You do not have permission to pre-reserve nodes!", 1);
}

#
# Verify page arguments.
40 41 42 43 44
#
$reqargs = RequiredPageArguments("node",    PAGEARG_NODE);
$optargs = OptionalPageArguments("clear",   PAGEARG_BOOLEAN,
				 "submit",  PAGEARG_STRING,
				 "project", PAGEARG_PROJECT);
45 46

#
47
# Need these below
48
#
49
$node_id = $node->node_id();
50 51 52 53

#
# Clear and zap back.
#
54
if (isset($clear) && $clear) {
55 56 57
    DBQueryFatal("update nodes set reserved_pid=NULL ".
		 "where node_id='$node_id'");

58
    header("Location: " . CreateURL("shownode", $node));
59 60 61 62 63 64
    return;
}

#
# Spit the form out using the array of data. 
# 
65
function SPITFORM($node, $reserved_pid, $error)
66 67 68 69 70 71 72 73 74 75
{
    #
    # Standard Testbed Header
    #
    PAGEHEADER("Pre Reserve a node to a project");

    #
    # Get list of projects.
    #
    $query_result =
76 77
	DBQueryFatal("select pid from projects where approved!=0 ".
		     "order by pid");
78 79 80 81 82 83 84 85 86 87 88

    if (mysql_num_rows($query_result) == 0) {
	USERERROR("There are no projects!", 1);
    }

    if ($error) {
	echo "<center>
               <font size=+1 color=red>$error</font>
              </center>\n";
    }

89
    $url = CreateURL("prereserve_node", $node);
90 91
    echo "<br>
          <table align=center border=1> 
92
          <form action='$url' method=post>\n";
93 94 95 96 97 98

    #
    # Select Project
    #
    echo "<tr>
              <td>Select Project:</td>
99
              <td><select name=\"pid\">
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
                      <option value=''>Please Select &nbsp</option>\n";

    while ($row = mysql_fetch_array($query_result)) {
	$pid      = $row['pid'];
	$selected = "";

	if ($reserved_pid == $pid)
	    $selected = "selected";
	
	echo "        <option $selected value='$pid'>$pid </option>\n";
    }
    echo "       </select>";
    echo "    </td>
          </tr>\n";

    echo "<tr>
              <td align=center colspan=2>
                  <b><input type=submit name=submit value=Submit></b>
              </td>
          </tr>\n";

    echo "</form>
          </table>\n";
}

#
# On first load, display a virgin form and exit.
#
128 129
if (!isset($submit)) {
    SPITFORM($node, $TBOPSPID, null);
130 131 132 133 134 135 136
    PAGEFOOTER();
    return;
}

#
# Otherwise, must validate and redisplay if errors.
#
137 138
if (!isset($project)) {
    SPITFORM($node, $TBOPSPID, "Must supply a project name");
139 140 141
    PAGEFOOTER();
    return;
}
142
$pid = $project->pid();
143 144 145 146

#
# Set the pid and zap back to shownode page.
#
147
DBQueryFatal("update nodes set reserved_pid='$pid' ".
148 149
	     "where node_id='$node_id'");

150
header("Location: " . CreateURL("shownode", $node));
151 152

?>