obstacles.php3 2.73 KB
Newer Older
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/>.
# 
# }}}
23 24 25 26 27
#
chdir("..");
include("defs.php3");

#
28
# Only known and logged in users.
29
#
30 31 32
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
33 34

#
35 36
# Verify page arguments. Allow user to optionally specify building/floor.
#
37 38 39
$optargs = OptionalPageArguments("building",      PAGEARG_STRING,
				 "floor",         PAGEARG_STRING);

40 41 42 43 44 45 46 47 48 49 50 51 52 53
if (isset($building) && $building != "") {
    # Sanitize for the shell.
    if (!preg_match("/^[-\w]+$/", $building)) {
	PAGEARGERROR("Invalid building argument.");
    }
    # Optional floor argument. Sanitize for the shell.
    if (isset($floor) && !preg_match("/^[-\w]+$/", $floor)) {
	PAGEARGERROR("Invalid floor argument.");
    }
}
else {
    $building = "MEB-ROBOTS";
    $floor    = 4;
}
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

# Initial goo.
header("Content-Type: text/plain");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
flush();

#
# Clean up when the remote user disconnects
#
function SPEWCLEANUP()
{
    exit(0);
}
register_shutdown_function("SPEWCLEANUP");

#
# Get the obstacle information. This stuff is in pixels, but we want to
# always send meters to the applet.
#
$query_result =
    DBQueryFatal("select o.*,f.pixels_per_meter from obstacles as o ".
		 "left join floorimages as f on ".
		 "  o.building=f.building and o.floor=f.floor ".
 		 "where o.building='$building' and o.floor='$floor'");

while ($row = mysql_fetch_array($query_result)) {
    $id    = $row["obstacle_id"];
    $x1    = $row["x1"];
    $y1    = $row["y1"];
    $x2    = $row["x2"];
    $y2    = $row["y2"];
    $desc  = $row["description"];
    $ppm   = $row["pixels_per_meter"];

    if (!isset($desc))
	$desc = "";

    $meters_x1 = sprintf("%.4f", $x1 / $ppm);
    $meters_y1 = sprintf("%.4f", $y1 / $ppm);
    $meters_x2 = sprintf("%.4f", $x2 / $ppm);
    $meters_y2 = sprintf("%.4f", $y2 / $ppm);
    
    echo "$id, $meters_x1, $meters_y1, $meters_x2, $meters_y2, $desc\n";
}

?>