modnodeattributes_form.php3 4.14 KB
Newer Older
Kirk Webb's avatar
Kirk Webb committed
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/>.
# 
# }}}
Kirk Webb's avatar
Kirk Webb committed
23 24
#
include("defs.php3");
25
include_once("node_defs.php");
Kirk Webb's avatar
Kirk Webb committed
26 27 28 29

#
# Only known and logged in users can do this.
#
30 31 32
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
Kirk Webb's avatar
Kirk Webb committed
33 34 35 36 37

#
# Only admin users can modify node attributes.
#
if (! $isadmin) {
38
    USERERROR("You do not have permission to modify node attributes!", 1);
Kirk Webb's avatar
Kirk Webb committed
39 40 41
}

#
42
# Verify form arguments.
Kirk Webb's avatar
Kirk Webb committed
43
#
44 45 46 47 48 49 50 51 52 53 54 55 56
$reqargs = RequiredPageArguments("node",         PAGEARG_NODE);
$optargs = OptionalPageArguments("refer",        PAGEARG_STRING,
				 "add_numattrs", PAGEARG_INTEGER);

# Need these below ...
$node_id = $node->node_id();
$type    = $node->type();
$url     = CreateURL("modnodeattributes", $node);
# Note that $refer is set by the caller so we know how we got to
# the webmodnodeattributes page. 
if (isset($refer)) {
    $url .= "&refer=$refer";
}
Kirk Webb's avatar
Kirk Webb committed
57

58 59 60 61 62
#
# Standard Testbed Header
#
PAGEHEADER("Modify Node Attributes Form");

Kirk Webb's avatar
Kirk Webb committed
63 64 65 66 67 68 69 70
#
# Get any node attributes that might exist
#
$node_attrs = array();
$attr_result =
    DBQueryFatal("select attrkey,attrvalue from node_attributes ".
		 "where node_id='$node_id'");
while($row = mysql_fetch_array($attr_result)) {
71
    $node_attrs[$row["attrkey"]] = $row["attrvalue"];
Kirk Webb's avatar
Kirk Webb committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
}

#
# Print out node id and type
#

echo "<table border=0 cellpadding=0 cellspacing=2
       align='center'>\n";

echo "<tr>
          <td align=\"center\"><b>Node ID: $node_id</b></td>
      </tr>\n";

echo "<tr>
          <td align=\"center\"><b>Node Type: $type</b></td>
      </tr>\n";
echo "</table><br><br><br><br>\n";

#
91
# Generate the form. 
Kirk Webb's avatar
Kirk Webb committed
92 93 94
# 
echo "<table border=2 cellpadding=0 cellspacing=2
       align='center'>\n";
95
echo "<form action='$url' method=\"post\">\n";
Kirk Webb's avatar
Kirk Webb committed
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
#
# Print out any node attributes already set
#
if ($node_attrs) {
  echo "<tr><td><table border=2 cellpadding=0 cellspacing=2
                 align='left'>\n";
  echo "<tr>
            <td align=\"center\" colspan=\"0\">
                <b>Current Node Attributes</b></td>
        </tr>
        <tr>
            <td>Del?</td><td>Attribute</td><td>Value</td>
        </tr>\n";
  foreach ($node_attrs as $attrkey => $attrval) {
    echo "<tr>
              <td><input type=\"checkbox\" name=\"_delattrs[$attrkey]\">
              <td>$attrkey</td>
              <td class=\"left\">
                  <input type=\"text\" name=\"_modattrs[$attrkey]\" size=\"60\"
                         value=\"$attrval\"></td>
          </tr>\n";
  }
  echo "</table></td></tr>\n";
}

#
# Print out fields for adding new attributes.
# The number of attributes defaults to 1, but this can be changed
# by specifying the number to add in the "add_numattrs" CGI variable.
#

echo "<tr><td><table border=2 cellpadding=0 cellspacing=2
       align='left'>\n";
echo "<tr>
          <td align=\"center\" colspan=\"0\"><b>Add Node Attribute</b></td>
      </tr>\n";

133 134
if (!isset($add_numattrs)) {
    $add_numattrs = 1;
Kirk Webb's avatar
Kirk Webb committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
}

for ($i = 0; $i < $add_numattrs; $i++) {
  echo "<tr>
            <td class=\"left\">
                <input type=\"text\" name=\"_newattrs[$i]\" size=\"32\"></td>
            <td class=\"left\">
                <input type=\"text\" name=\"_newvals[$i]\" size=\"60\"></td>
            </td>
        </tr>\n";
}

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

echo "</table>\n";

#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>