Commit 315c5d9c authored by Leigh Stoller's avatar Leigh Stoller

Switch everything over to using new buildings and floorimages tables

that I added to the DB. See revision 1.251 of sql/database-create.sql.
I have removed all of the hardwired names of buildings, images, files,
etc. I have also added MEB floors 1 and 2, but they do not show up on
the status page unlesss there are actually nodes assigned to them.
When you go to set a node location, you do see the little thumbs of
all existing buildings/floors, so you can add nodes to floors that do
not currently have any.

Still needs some work to cleanly display multiple buildings, but thats
for another day.
parent a2f84fa2
......@@ -6,6 +6,7 @@
#
use English;
use Getopt::Std;
use File::Basename;
#
# TODO: Deal with multiple buildings? Currently defaults to MEB!
......@@ -17,15 +18,17 @@ sub usage {
print STDERR "[-e <pid,eid>] [<building>]\n";
exit(-1);
}
my $optlist = "df:o:e:t";
my $optlist = "df:o:e:ta";
my $debug = 0;
my $notitles = 0;
my $building = "MEB";
my $showany = 0; # When showing specific floor, showany is turned on.
my $building;
my $floor;
my $image;
my $pid;
my $eid;
my @areamaps = ();
my @areamaps = ();
my %baseimages = ();
my $prefix = "/tmp/floormap";
#
......@@ -41,14 +44,33 @@ use libdb;
use GD;
#
# Hardwire the imagemaps for now. This needs to go into the DB in some format.
# Gather image data from DB.
#
my %baseimages =
("MEB" => { "title" => "Merril Engineering Building",
"floors" => { 3 => "$TB/www/meb3fl.png",
4 => "$TB/www/meb4fl.png"}
}
);
my $query_result =
DBQueryFatal("select b.building,b.title,f.floor,f.image_path ".
" from buildings as b ".
"left join floorimages as f on f.building=b.building");
if (!$query_result->numrows) {
die("*** $0:\n".
" There is no building/floor data in the DB!\n");
}
while (my ($building,$title,$floor,$image) = $query_result->fetchrow_array()) {
if (!exists($baseimages{$building})) {
$baseimages{$building} = {};
$baseimages{$building}->{"title"} = $title;
$baseimages{$building}->{"floors"} = {};
}
$image = "$TB/www/$image"
if (dirname($image) eq ".");
if (! -e $image) {
die("*** $0:\n".
" $image does not exist!\n");
}
$baseimages{$building}->{"floors"}->{$floor} = $image;
}
# Ha.
my @floortags = ();
......@@ -86,6 +108,9 @@ sub adjustmap($$$);
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"a"})) {
$showany = 1;
}
if (defined($options{"d"})) {
$debug = 1;
}
......@@ -93,7 +118,8 @@ if (defined($options{"t"})) {
$notitles = 1;
}
if (defined($options{"f"})) {
$floor = $options{"f"};
$floor = $options{"f"};
$showany = 1;
}
if (defined($options{"o"})) {
$prefix = $options{"o"};
......@@ -130,13 +156,15 @@ if (defined($options{"e"})) {
elsif (@ARGV == 1) {
$building = $ARGV[0];
}
else {
# XXX We default to MEB above. Change later.
;
# Must specify a building with a floor.
if (defined($floor) && !defined($building)) {
die("*** $0:\n".
" Must supply a building name!\n");
}
# Building must exist. Someday deal with multiple buildings.
if (!exists($baseimages{$building})) {
# Building must exist.
if (defined($building) && !exists($baseimages{$building})) {
die("*** $0:\n".
" No such building: $building\n");
}
......@@ -159,10 +187,29 @@ else {
#
my @floors = ();
foreach my $floor (sort(keys(%{ $baseimages{$building}->{"floors"} }))) {
my ($floorimage, $areamap) = dofloor($building, $floor);
if (defined($building)) {
foreach my $floor (sort(keys(%{ $baseimages{$building}->{"floors"} }))) {
my ($floorimage, $areamap) = dofloor($building, $floor);
push(@floors, [ $floorimage, $areamap ]);
push(@floors, [ $floorimage, $areamap ])
if (defined($floorimage));
}
}
else {
#
# XXX We need to be fancier for multiple buildings at some point!
# Not much of a worry right now.
#
foreach my $building (sort(keys(%baseimages))) {
my @floorlist = sort(keys(%{ $baseimages{$building}->{"floors"} }));
foreach my $floor (@floorlist) {
my ($floorimage, $areamap) = dofloor($building, $floor);
push(@floors, [ $floorimage, $areamap ])
if (defined($floorimage));
}
}
}
#
......@@ -213,6 +260,21 @@ sub dofloor($$)
{
my ($building, $floor) = @_;
#
# 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);
}
#
# The area map is indexed by nodeid, and contains a list of the
# x1,y1,x2,y2 (upper left, lower right) coordinates of the "hot"
......@@ -252,16 +314,6 @@ sub dofloor($$)
my $CY = 10;
my $CX = 10;
#
# 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'");
while (my $rowref = $query_result->fetchrow_hashref()) {
my $nodeid = $rowref->{"node_id"};
my $x = $rowref->{"loc_x"};
......
......@@ -45,7 +45,7 @@ else {
echo "<b>Show: <a href='nodecontrol_list.php3?showtype=summary'>summary</a>,
<a href='nodecontrol_list.php3?showtype=pcs'>pcs</a>,
<a href='floormap.php3?building=MEB'>wireless</a>,
<a href='floormap.php3'>wireless</a>,
<a href='nodecontrol_list.php3?showtype=widearea'>widearea</a>";
if ($isadmin) {
......
......@@ -225,6 +225,28 @@ elseif (isset($dodelete) && $dodelete != "") {
if (!isset($building) || $building == "" || !isset($floor) || $floor == "") {
PAGEHEADER("Set Node Location");
$building_result =
DBQueryFatal("select b.building,b.title,f.floor,f.thumb_path ".
" from buildings as b ".
"left join floorimages as f on f.building=b.building " .
"order by b.building,f.floor");
if (! mysql_num_rows($building_result)) {
USERERROR("There is no floormap data in the DB!", 1);
}
# Ha.
$floortags = array();
$floortags[1] = "1st floor";
$floortags[2] = "2nd floor";
$floortags[3] = "3rd floor";
$floortags[4] = "4th floor";
$floortags[5] = "5th floor";
$floortags[6] = "6th floor";
$floortags[7] = "7th floor";
$floortags[8] = "8th floor";
$floortags[9] = "9th floor";
echo "<center>\n";
if (isset($old_building)) {
......@@ -233,24 +255,61 @@ if (!isset($building) || $building == "" || !isset($floor) || $floor == "") {
}
echo "<font size=+2>Pick a floor, any floor</font><br><br>\n";
echo "<table>\n";
echo "<table>
<tr>
<td>
<a href='setnodeloc.php3?node_id=$node_id&building=MEB&floor=3'>
<img src=meb3fl-thumb.png></a>
</td>
<td>
<a href='setnodeloc.php3?node_id=$node_id&building=MEB&floor=4'>
<img src=meb4fl-thumb.png></a>
</td>
</tr>
<tr>
<td align=center>MEB 3rd Floor</td>
<td align=center>MEB 4th Floor</td>
</tr>
</table>\n";
$maxcol = 2;
$i = 0;
$titles = array();
#
# XXX This will need to be generalized to multiple buildings at some
# point; right now just throw up a set of thumb images in a single
# table. Not very pretty.
#
while ($row = mysql_fetch_array($building_result)) {
$building = $row["building"];
$title = $row["title"];
$floor = $row["floor"];
$thumb = $row["thumb_path"];
if ($i == $maxcol) {
#
# Start a new row. Keeps the window reasonably narrow.
# We have to put the titles in for the previous row before
# starting the next row; see below where we have to do this
# when the table is finished.
#
echo "</tr><tr>\n";
for ($i = 0 ; $i < $maxcol; $i++) {
echo "<td align=center>" . $titles[$i] . "</td>\n";
}
echo "</tr><tr>\n";
$i = 0;
}
echo "<td>
<a href='setnodeloc.php3?node_id=$node_id".
"&building=$building&floor=$floor'>
<img src=$thumb></a>
</td>\n";
$titles[$i] = "$title - " . $floortags[$floor];
$i++;
}
# Finish out previous row.
while ($i < $maxcol) {
echo "<td></td>";
$titles[$i] = "";
$i++;
}
echo "</tr>";
# Then stick in the title row.
echo "<tr>";
for ($i = 0 ; $i < $maxcol; $i++) {
echo "<td align=center>" . $titles[$i] . "</td>\n";
}
echo "</tr>\n";
echo "</table>\n";
echo "</center>\n";
PAGEFOOTER();
......
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