Include("physweb.def");
if ($room == "") { $room = "3019"; }
$first_digit = substr($room,0,1);
switch(intval($first_digit)) {
case 0;
$floor = "Basement";
break;
case 1;
$floor = "First Floor";
break;
case 2;
$floor = "Second Floor";
break;
case 3;
$floor = "Third Floor";
break;
case 4;
$floor = "Fourth Floor";
break;
case 5;
$floor = "Fifth Floor";
break;
case 6;
$floor = "Sixth Floor";
break;
case 7;
$floor = "Roof";
break;
default;
$floor = "";
break;
}
$conn = pg_Connect("localhost", "5432", "", "", "physics");
if (!$conn) {
echo "An error occured.\n";
exit;
}
$result = pg_Exec($conn, "select number,coords,use from rooms where ((bldg = 'Broida') and (textregexeq(number,'^$first_digit')))");
if (!$result) {
echo "An error occured\n";
exit;
}
$num_rooms = pg_NumRows($result);
if ($num_rooms < 1) {
echo "No matches\n";
exit;
}
$i = 0;
$max_x_coord = -999999.0;
$max_y_coord = -999999.0;
$min_x_coord = 999999.0;
$min_y_coord = 999999.0;
while ($i < $num_rooms) {
#echo "i: $i
\n";
$djrt1=pg_result($result,$i,"coords");
sql_to_temparray($djrt1);
$temparray=$GLOBALS['temparray2'];
$num_coords = count($temparray);
#echo " nc: $num_coords
\n";
$j = 0;
while ($j < $num_coords) {
$temp_point = doubleval(current($temparray));next($temparray);
if ($j % 2) {
if ($temp_point > $max_x_coord) { $max_x_coord = $temp_point; }
if ($temp_point < $min_x_coord) { $min_x_coord = $temp_point; }
} else {
if ($temp_point > $max_y_coord) { $max_y_coord = $temp_point; }
if ($temp_point < $min_y_coord) { $min_y_coord = $temp_point; }
}
$j++;
}
$i++;
}
$min_x_coord -= 0.1;
$min_y_coord -= 0.8; /* Make space for the legend */
$max_x_coord += 0.1;
$max_y_coord += 0.1;
$x_scale = 100.0;
$y_scale = 100.0;
$max_x = ($max_x_coord - $min_x_coord) * $x_scale;
$max_y = ($max_y_coord - $min_y_coord) * $y_scale;
/*echo "IC: max_x_coord=$max_x_coord
\n";
echo "IC: max_y_coord=$max_y_coord
\n";
echo "IC: min_x_coord=$min_x_coord
\n";
echo "IC: min_y_coord=$min_y_coord
\n";*/
$im = ImageCreate(intval($max_x)+1,intval($max_y)+1);
$trans = ImageColorAllocate($im,255,255,255);
ImageColorTransparent($im,$trans);
ImageInterlace($im,1);
$black = ImageColorAllocate($im,0,0,0);
$red = ImageColorAllocate($im,255,0,0);
$green = ImageColorAllocate($im,0,255,0);
$blue = ImageColorAllocate($im,0,0,255);
$grey = ImageColorAllocate($im,100,100,100);
$pink = ImageColorAllocate($im,127,0,0);
$light_blue = ImageColorAllocate($im,0,0,127);
$yellow = ImageColorAllocate($im,255,255,0);
$turq = ImageColorAllocate($im,0,255,255);
ImageRectangle($im,0,0,350,60,$red);
ImageString($im,5,0,0,"Broida " . $floor,$black);
ImageFilledRectangle($im,15,17,25,27,$grey);
ImageString($im,5,30,15,"- Hallway",$black);
ImageFilledRectangle($im,15,32,25,42,$turq);
ImageString($im,5,30,30,"- Elevator",$black);
ImageFilledRectangle($im,15,47,25,57,$yellow);
ImageString($im,5,30,45,"- Stairs",$black);
ImageFilledRectangle($im,145,17,155,27,$pink);
ImageString($im,5,160,15,"- Women's Restroom",$black);
ImageFilledRectangle($im,145,32,155,42,$light_blue);
ImageString($im,5,160,30,"- Men's Restroom",$black);
ImageFilledRectangle($im,145,47,155,57,$green);
ImageString($im,5,160,45,"- Broida " . $room,$black);
$i = 0;
while ($i < $num_rooms) {
sql_to_temparray(pg_result($result,$i,"coords"));
$temparray=$GLOBALS['temparray2'];
$num_coords = count($temparray);
$j = 0;
$center_x = 0;
$center_y = 0;
unset($points);
while ($j < $num_coords) {
$temp_point = doubleval(current($temparray));next($temparray);
if ($j % 2) {
$temp_point = ($temp_point - $min_x_coord) * $x_scale;
#printf("x: %f\n",$temp_point);
$center_x += $temp_point;
$points[]=intval($temp_point);
$points[]=intval($temp_hold);
} else {
$temp_point = ($temp_point - $min_y_coord) * $y_scale;
#printf("y: %f\n",$temp_point);
$center_y += $temp_point;
$temp_hold = $temp_point;
}
$j++;
}
$center_x = $center_x / ($num_coords / 2);
$center_y = $center_y / ($num_coords / 2);
reset($points);
$this_room = pg_result($result,$i,"number");
$use = pg_result($result,$i,"use");
$show_number = 1;
$bcolor = $black;
$fcolor = $red;
if ($this_room == $room) {
$bcolor = $green;
$fcolor = $blue;
$show_number = 1;
} else {
switch (ord($use)) {
case ord("c"); /* Corridor */
$bcolor = $grey;
$show_number = 0;
break;
case ord("m"); /* Male Bathroom */
$bcolor = $light_blue;
$show_number = 0;
break;
case ord("f"); /* Female Bathroom */
$bcolor = $pink;
$show_number = 0;
break;
case ord("z"); /* Core */
$bcolor = $black;
$show_number = 0;
break;
case ord("e"); /* Elevator */
$bcolor = $turq;
$show_number = 0;
break;
case ord("s"); /* Stairs */
$bcolor = $yellow;
$show_number = 0;
break;
case ord("j"); /* Janitor */
$bcolor = $black;
$show_number = 0;
break;
default;
$bcolor = $black;
$fcolor = $red;
break;
}
}
ImageFilledPolygon($im,$points,$num_coords/2,$bcolor);
reset($points);
if ($show_number) {
ImageString($im,3,$center_x - 15,$center_y - 5,
pg_result($result,$i,"number"),$fcolor);
}
$i++;
}
pg_FreeResult($result);
pg_Close($conn);
#echo "hi
\n";
Header("Content-type: image/png");
ImagePng($im);
?>