Commit 159ced78 authored by Leigh Stoller's avatar Leigh Stoller

Add support so that setnodeloc and floormaps can be used on the

new_nodes table. Thought it would be easy, but ended up doing more
damage then I expected; oh well. New nodes show up in "gold" color
(not listed in the legend).

I added a link from the newnode_edit page. Rob will need to arrange
for a location_info entry to be created when a new node is made live
(but only if building/floor are not null).
parent b6341a4e
......@@ -22,6 +22,7 @@ my $optlist = "df:o:e:ta";
my $debug = 0;
my $notitles = 0;
my $showany = 0; # When showing specific floor, showany is turned on.
my $mereuser = 1;
my $building;
my $floor;
my $image;
......@@ -43,6 +44,10 @@ use lib '@prefix@/lib';
use libdb;
use GD;
# Admin people get extra info
$mereuser = 0
if (!TBAdmin($UID));
#
# Gather image data from DB.
#
......@@ -259,20 +264,31 @@ exit(0);
sub dofloor($$)
{
my ($building, $floor) = @_;
my $isnew = 0;
#
# Grab the nodes on this floor in this building. We want to know
# their allocation status so we know what colors to use.
#
#
my $query_result =
DBQueryFatal("select loc.*,r.pid,r.eid,r.vname ".
" from location_info as loc ".
"left join reserved as r on r.node_id=loc.node_id ".
"where loc.floor='$floor' and loc.building='$building'");
if (!$query_result->numrows && !$showany) {
return (undef, undef);
my $newnodes_result =
DBQueryFatal("select * from new_nodes ".
"where floor='$floor' and building='$building'");
if ($mereuser) {
if (!$query_result->numrows && !$showany) {
return (undef, undef);
}
}
else {
if (!$query_result->numrows && !$newnodes_result->numrows && !$showany) {
return (undef, undef);
}
}
#
......@@ -311,38 +327,59 @@ sub dofloor($$)
my $red = $baseimage->colorAllocate(250,0,0);
my $blue = $baseimage->colorAllocate(0,0,250);
my $white = $baseimage->colorAllocate(255,255,255);
my $gold = $baseimage->colorAllocate(255,255,0);
my $CY = 10;
my $CX = 10;
while (my $rowref = $query_result->fetchrow_hashref()) {
my $nodeid = $rowref->{"node_id"};
my $x = $rowref->{"loc_x"};
my $y = $rowref->{"loc_y"};
my $rpid = $rowref->{"pid"};
my $reid = $rowref->{"eid"};
my $label = $nodeid;
my ($x1,$y1,$x2,$y2);
# Without -e option, green means node is free.
# With -e option, green means node belongs to experiment.
if ((!defined($pid) && !(defined($rpid))) ||
(defined($pid) && defined($rpid) && $pid eq $rpid)) {
$baseimage->filledArc($x, $y, $CX, $CY, 0, 360, $green);
}
elsif ($rpid eq NODEDEAD_PID() and $reid eq NODEDEAD_EID()) {
$baseimage->filledArc($x, $y, $CX, $CY, 0, 360, $red);
foreach my $isnew (0, 1) {
my $table;
if ($isnew) {
next
if ($mereuser);
$table = $newnodes_result;
}
else {
$baseimage->filledArc($x, $y, $CX, $CY, 0, 360, $blue);
$table = $query_result;
}
while (my $rowref = $table->fetchrow_hashref()) {
my $nodeid = $rowref->{"node_id"};
my $x = $rowref->{"loc_x"};
my $y = $rowref->{"loc_y"};
my $rpid = $rowref->{"pid"};
my $reid = $rowref->{"eid"};
my $label = $nodeid;
my $newid = ($isnew ? $rowref->{"new_node_id"} : 0);
my ($x1,$y1,$x2,$y2);
if ($isnew) {
$baseimage->filledArc($x, $y, $CX, $CY, 0, 360, $gold)
}
elsif ((!defined($pid) && !(defined($rpid))) ||
(defined($pid) && defined($rpid) && $pid eq $rpid)) {
# Without -e option, green means node is free.
# With -e option, green means node belongs to experiment.
$baseimage->filledArc($x, $y, $CX, $CY, 0, 360, $green);
}
elsif ($rpid eq NODEDEAD_PID() and $reid eq NODEDEAD_EID()) {
$baseimage->filledArc($x, $y, $CX, $CY, 0, 360, $red);
}
else {
$baseimage->filledArc($x, $y, $CX, $CY, 0, 360, $blue);
}
$baseimage->string(gdTinyFont, $x - 7, $y + ($CY / 2),
$label, $black);
my $tmp = {};
$tmp->{"X1"} = $x - ($CX / 2);
$tmp->{"Y1"} = $y - ($CY / 2);
$tmp->{"X2"} = $x + ($CX / 2);
$tmp->{"Y2"} = $y + ($CY / 2);
$tmp->{"ISNEW"} = $newid;
$areamap->{$nodeid} = $tmp;
}
$baseimage->string(gdTinyFont, $x - 7, $y + ($CY / 2), $label, $black);
my $tmp = {};
$tmp->{"X1"} = $x - ($CX / 2);
$tmp->{"Y1"} = $y - ($CY / 2);
$tmp->{"X2"} = $x + ($CX / 2);
$tmp->{"Y2"} = $y + ($CY / 2);
$areamap->{$nodeid} = $tmp;
}
if (!$notitles) {
......@@ -416,9 +453,13 @@ sub writefiles($@)
my $y1 = $map{$nodeid}->{"Y1"};
my $x2 = $map{$nodeid}->{"X2"};
my $y2 = $map{$nodeid}->{"Y2"};
my $isnew = $map{$nodeid}->{"ISNEW"};
my $link = ($isnew ?
"newnode_edit.php3?id=${isnew}" :
"shownode.php3?node_id=${nodeid}");
print MAP "<AREA SHAPE=RECT COORDS=\"$x1,$y1,$x2,$y2\" ".
"HREF=\"shownode.php3?node_id=${nodeid}\">\n\n";
"HREF=\"${link}\">\n\n";
}
}
print MAP "</MAP>\n";
......
<?PHP
#
# EMULAB-COPYRIGHT
# Copyright (c) 2003 University of Utah and the Flux Group.
# Copyright (c) 2003, 2004 University of Utah and the Flux Group.
# All rights reserved.
#
require("defs.php3");
......@@ -181,9 +181,10 @@ while ($row = mysql_fetch_array($query_result)) {
<center>
<input type="submit" name="submit" value="Update node">
</center>
<?
echo "<a href=setnodeloc.php3?node_id=$id&isnewid=1>Set Node Location</a>\n";
#
# Standard Testbed Footer
#
......
......@@ -38,9 +38,20 @@ if (!$isadmin) {
#
# Check page args. Must always supply a nodeid.
#
if (!isset($node_id) || $node_id == "" || !TBvalid_node_id($node_id)) {
PAGEARGERROR("Invalid node_id");
#
if (!isset($node_id) || $node_id == "") {
PAGEARGERROR("Must supply node_id");
}
elseif (isset($isnewid) && $isnewid == 1) {
if (!TBvalid_integer($node_id)) {
PAGEARGERROR("Must supply new node identifier in node_id");
}
}
elseif (!TBvalid_node_id($node_id)) {
PAGEARGERROR("Invalid characters in node_id");
}
elseif (!TBValidNodeName($node_id)) {
PAGEARGERROR("Invalid node_id $node_id");
}
#
......@@ -48,7 +59,7 @@ if (!isset($node_id) || $node_id == "" || !TBvalid_node_id($node_id)) {
# contact info. We use a form and an input type=image, which acts as a submit
# button; the browser sends x,y coords when the user clicks in the image.
#
function SPITFORM($errors, $node_id, $building, $floor,
function SPITFORM($errors, $node_id, $isnewid, $building, $floor,
$room, $contact, $phone, $old_x, $old_y,
$delete = 0)
{
......@@ -136,7 +147,7 @@ function SPITFORM($errors, $node_id, $building, $floor,
size=30>
</td>
</tr>\n";
if (isset($old_x) and isset($old_y)) {
if (isset($old_x) && isset($old_y) && $old_x && $old_y) {
echo "<tr>
<td colspan=2 align=center>
<b><input type=submit name=submit
......@@ -152,6 +163,9 @@ function SPITFORM($errors, $node_id, $building, $floor,
</td>
</tr>\n";
}
if (isset($isnewid) && $isnewid == 1) {
echo "<input type=hidden name=isnewid value=1>\n";
}
echo "</table>
<input type=hidden name=node_id value=$node_id>
<input type=hidden name=building value=$building>
......@@ -163,11 +177,18 @@ function SPITFORM($errors, $node_id, $building, $floor,
}
#
# Get default values from location info.
# Get default values from location info or from the new_nodes table.
#
$query_result =
DBQueryFatal("select * from location_info ".
"where node_id='$node_id'");
if (isset($isnewid) && $isnewid == 1) {
$query_result =
DBQueryFatal("select * from new_nodes ".
"where new_node_id='$node_id'");
}
else {
$query_result =
DBQueryFatal("select * from location_info ".
"where node_id='$node_id'");
}
if (mysql_num_rows($query_result)) {
$row = mysql_fetch_array($query_result);
......@@ -203,18 +224,26 @@ if (isset($delete) && $delete == 1) {
if (! isset($old_building)) {
USERERROR("There is no location info for node $node_id!", 1);
}
SPITFORM(0, $node_id, $old_building, $old_floor, $room, $contact, $phone,
$old_x, $old_y);
SPITFORM(0, $node_id, $isnewid, $old_building, $old_floor, $room, $contact,
$phone, $old_x, $old_y);
PAGEFOOTER();
exit(0);
}
elseif (isset($dodelete) && $dodelete != "") {
#
# Delete the entry and zap to shownode page.
#
DBQueryFatal("delete from location_info where node_id='$node_id'");
#
if (isset($isnewid) && $isnewid == 1) {
DBQueryFatal("update new_nodes set " .
" building=NULL,floor=NULL,loc_x=0,loc_y=0 ".
"where new_node_id='$node_id'");
header("Location: newnode_edit.php3?id=$node_id");
}
else {
DBQueryFatal("delete from location_info where node_id='$node_id'");
header("Location: shownode.php3?node_id=$node_id");
}
header("Location: shownode.php3?node_id=$node_id");
exit(0);
}
......@@ -250,7 +279,8 @@ if (!isset($building) || $building == "" || !isset($floor) || $floor == "") {
echo "<center>\n";
if (isset($old_building)) {
echo "<a href='setnodeloc.php3?node_id=$node_id&delete=1'>
echo "<a href='setnodeloc.php3?node_id=$node_id&delete=1".
"&isnewid=$isnewid'>
Delete</a> location info or<br>\n";
}
......@@ -289,7 +319,7 @@ if (!isset($building) || $building == "" || !isset($floor) || $floor == "") {
echo "<td>
<a href='setnodeloc.php3?node_id=$node_id".
"&building=$building&floor=$floor'>
"&building=$building&floor=$floor&isnewid=$isnewid'>
<img src=$thumb></a>
</td>\n";
$titles[$i] = "$title - " . $floortags[$floor];
......@@ -334,7 +364,7 @@ if (!preg_match("/^[-\w]+$/", $floor)) {
if (!isset($submit) && (!isset($x) || $x == "" || !isset($y) || $y == "")) {
PAGEHEADER("Set Node Location");
SPITFORM(0, $node_id, $building, $floor, $room, $contact, $phone,
SPITFORM(0, $node_id, $isnewid, $building, $floor, $room, $contact, $phone,
$old_x, $old_y);
PAGEFOOTER();
exit(0);
......@@ -427,22 +457,29 @@ else {
#
if (count($errors)) {
PAGEHEADER("Set Node Location");
SPITFORM($errors, $node_id, $building, $floor, $room, $contact,
SPITFORM($errors, $node_id, $isnewid, $building, $floor, $room, $contact,
$phone, $old_x, $old_y);
PAGEFOOTER();
return;
}
#
# Otherwise, do the inserts.
# Otherwise, do the inserts or updates
#
$inserts["node_id"] = $node_id;
$insert_data = array();
foreach ($inserts as $name => $value) {
$insert_data[] = "$name='$value'";
}
DBQueryFatal("replace into location_info set " . implode(",", $insert_data));
if (isset($isnewid) && $isnewid == 1) {
DBQueryFatal("update new_nodes set " . implode(",", $insert_data) . " ".
"where new_node_id='$node_id'");
}
else {
$insert_data[] = "node_id='$node_id'";
DBQueryFatal("replace into location_info set " . implode(",", $insert_data));
}
#
# Zap back to floormap for this building/floor.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment