prereserve_node.php3 2.75 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
5 6 7
# All rights reserved.
#
include("defs.php3");
8
include_once("node_defs.php");
9 10 11 12

#
# Only admin people!
#
13 14 15
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
16 17 18 19 20 21 22

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

#
# Verify page arguments.
23 24 25 26 27
#
$reqargs = RequiredPageArguments("node",    PAGEARG_NODE);
$optargs = OptionalPageArguments("clear",   PAGEARG_BOOLEAN,
				 "submit",  PAGEARG_STRING,
				 "project", PAGEARG_PROJECT);
28 29

#
30
# Need these below
31
#
32
$node_id = $node->node_id();
33 34 35 36

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

41
    header("Location: " . CreateURL("shownode", $node));
42 43 44 45 46 47
    return;
}

#
# Spit the form out using the array of data. 
# 
48
function SPITFORM($node, $reserved_pid, $error)
49 50 51 52 53 54 55 56 57 58
{
    #
    # Standard Testbed Header
    #
    PAGEHEADER("Pre Reserve a node to a project");

    #
    # Get list of projects.
    #
    $query_result =
59 60
	DBQueryFatal("select pid from projects where approved!=0 ".
		     "order by pid");
61 62 63 64 65 66 67 68 69 70 71

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

72
    $url = CreateURL("prereserve_node", $node);
73 74
    echo "<br>
          <table align=center border=1> 
75
          <form action='$url' method=post>\n";
76 77 78 79 80 81

    #
    # Select Project
    #
    echo "<tr>
              <td>Select Project:</td>
82
              <td><select name=\"pid\">
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
                      <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.
#
111 112
if (!isset($submit)) {
    SPITFORM($node, $TBOPSPID, null);
113 114 115 116 117 118 119
    PAGEFOOTER();
    return;
}

#
# Otherwise, must validate and redisplay if errors.
#
120 121
if (!isset($project)) {
    SPITFORM($node, $TBOPSPID, "Must supply a project name");
122 123 124
    PAGEFOOTER();
    return;
}
125
$pid = $project->pid();
126 127 128 129

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

133
header("Location: " . CreateURL("shownode", $node));