prereserve_node.php3 3.03 KB
Newer Older
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 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 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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");

#
# Only admin people!
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);

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

#
# Verify page arguments.
# 
if (!isset($node_id) ||
    strcmp($node_id, "") == 0) {
    USERERROR("You must provide a node ID.", 1);
}
if (!TBvalid_node_id($node_id)) {
    PAGEARGERROR("Illegal characters in node_id");
}

#
# Check to make sure that this is a valid nodeid
#
if (! TBValidNodeName($node_id)) {
    USERERROR("$node_id is not a valid node name!", 1);
}

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

    header("Location: $TBBASE/shownode.php3?node_id=$node_id");
    return;
}

#
# Spit the form out using the array of data. 
# 
function SPITFORM($node_id, $reserved_pid, $error)
{
    #
    # Standard Testbed Header
    #
    PAGEHEADER("Pre Reserve a node to a project");

    #
    # Get list of projects.
    #
    $query_result =
	DBQueryFatal("select pid from projects where approved!=0");

    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";
    }

    echo "<br>
          <table align=center border=1> 
          <form action='prereserve_node.php3?node_id=$node_id' method=post>\n";

    #
    # Select Project
    #
    echo "<tr>
              <td>Select Project:</td>
              <td><select name=\"reserved_pid\">
                      <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.
#
if (! $submit) {
    SPITFORM($node_id, $TBOPSPID, False);
    PAGEFOOTER();
    return;
}

#
# Otherwise, must validate and redisplay if errors.
#
$error = False;

#
# Project:
#
if (!isset($reserved_pid) || $reserved_pid == "") {
    $error = "Must supply a project name";
}
elseif (!TBvalid_pid($reserved_pid)) {
    $error = "Illegal characters in project name";
}
elseif (!TBValidProject($reserved_pid)) {
    $error = "Invalid project name";
}
if ($error) {
    SPITFORM($node_id, $TBOPSPID, $error);
    PAGEFOOTER();
    return;
}

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

header("Location: $TBBASE/shownode.php3?node_id=$node_id");