Location: PHPKode > projects > Wifimap > wifimap/editnode.php
<?
/*****************************
 * 
 * wifimap v 0.3.1
 *
 * copyright 2003 John O'Sullivan <hide@address.com>
 * Based on some code and ideas from phpwirelessmap
 *
 * This file is part of wifimap.
 * wifimap is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * wifimap 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with wifimap; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * Licensed under the GNU General Public License
 * See the file COPYING for details
 *
 *****************************/

require("./config.inc.php");

$thisfile="editnode.php";

// Establish a connection to the database.
$db_link = mysql_connect($sql_server,$sql_user,$sql_passwd) or die('Not connected : ' . mysql_error());
mysql_select_db($sql_dbname,$db_link) or die('Can\'t use $sql_dbname : ' . mysql_error());

// Get mapdata from the database.
$query="SELECT * FROM maps WHERE id='$mapid'";
$result = mysql_query($query,$db_link);
$row = mysql_fetch_object($result);
if(!isset($xorig)) $xorig=$row->xorig; else $xorig-=$xorig%$zoom;
if(!isset($yorig)) $yorig=$row->yorig; else $yorig-=$yorig%$zoom;
if(!isset($zoom)) $zoom=$row->defaultzoom;
if(!isset($mapsizex)) $mapsizex=$row->dispcellsx;
if(!isset($mapsizey)) $mapsizey=$row->dispcellsy;
$cellsize=$row->cellsize;

// Calculate some numbers we need to work with.
$xdest=$xorig+($mapsizex*$zoom);
$ydest=$yorig+($mapsizey*$zoom);
$absx_start=$xorig*$cellsize;
$absy_start=$yorig*$cellsize;
$absx_end=($xdest)*$cellsize;
$absy_end=($ydest)*$cellsize;

// These are for the navigation buttons
$xorige=$xorig+$zoom;
$xorigw=$xorig-$zoom;
$yorigs=$yorig+$zoom;
$yorign=$yorig-$zoom;

$layer=1;

print ("
<html>
<head>
<title>wifimap</title>
</head>
<body> \n");

// Top Menu Bar
include("./topbar.php");

// Page header, instructions and similar info should go here.
print("<table width=100%>
<tr>
<td><h2>".$i18n["Edit a Node"]."</h2></td>\n");
include("./legend.php");
include("./mapsizes.php");
print("</tr>
</table>\n");
print("".$i18n["editnode-instructions"]."\n");
print("<div id=\"map\" style=\"position:absolute; left:0px; top:$mapoffsetpx; width:0px; height:0px; z-index:$layer\">\n");

$tablex=($mapsizex*$cellsize)+($mapborder*2);
$tabley=($mapsizey*$cellsize)+($mapborder*2);
// Make a table to hold the graphical map elements
print("<table cellpadding=0 cellspacing=0 width=$tablex height=$tabley>\n");

$tablex=($mapsizex*$cellsize);
$tabley=($mapsizey*$cellsize);
// Display the first 4 navigation buttons.
include("navbuttons1-4.php");

print("	<td width=$tablex height=$tabley>");

// Start the table which will display the maps
print("<table width=$tablex height=$tabley cellpadding=0 cellspacing=0>\n");

// Begin displaying the map cells
	for ($yvar = $yorig; $yvar < $ydest; $yvar+=$zoom)
		{
// Start a map row
		print("<tr>");
		for ($xvar = $xorig; $xvar < $xdest; $xvar+=$zoom)
			{
// Start a map cell
			print("<td>");

			$query = "SELECT * FROM cells WHERE x=$xvar AND y=$yvar AND zoom=$zoom AND mapid=$mapid";
			$result = mysql_query($query,$db_link);
     			$row = mysql_fetch_object($result);
				if ($row) {
				  print("<img src=\"$row->imagesource\">");
				}
				else {
				print("<img src=\"./cells/nomap.png\">");
				}

// Finish a map cell
			print("</td>");
			}
// Finish a map row
		print("</tr>");
		}
// Finished drawing the map grid
print("</table>\n");

// Draw the final 4 navigation buttons
include("navbuttons5-8.php");

print("</table>\n");
print("</div>\n");

// Next display the links
// links cover some areas of the map making it difficult to add nodes to those areas
include("drawlinks.php");

// Next display the nodes
// Get nodedata from the database.
$db_link = mysql_connect($sql_server,$sql_user,$sql_passwd) or die('Not connected : ' . mysql_error());
mysql_select_db($sql_dbname,$db_link) or die('Can\'t use $sql_dbname : ' . mysql_error());
//	$count = mysql_query("SELECT count(*) FROM nodes WHERE absolutex>='$absx_start' and absolutex<='$absx_end' and absolutey>='$absy_start' and absolutey<='$absy_end'",$db_link);
// Get all the nodes that are in the displayed area
$query="SELECT * FROM nodes WHERE mapid=$mapid AND absolutex>=$absx_start AND absolutex<=$absx_end AND absolutey>=$absy_start AND absolutey<=$absy_end";
$result = mysql_query($query,$db_link);
while ($node = mysql_fetch_object($result)) {
  $nodex=intval(($node->absolutex-$absx_start)/$zoom);   $nodex-=6;  $nodex+=$mapborder; $nodexpx=$nodex.px;
  $nodey=intval(($node->absolutey-$absy_start)/$zoom);   $nodey-=6;  $nodey+=$mapborder;  $nodey+=$mapoffset;  $nodeypx=$nodey.px;
  $nodeid=$node->id;
  $layer++;

  if($node->status==1) $nodeimage="livenode.png";
  if($node->status==2) $nodeimage="deadnode.png";
  if($node->status==3) $nodeimage="plannednode.png";

// Display the nodes as image forms linked to editnodeform.php
  print("<div id=\"node\" style=\"position:absolute; left:$nodexpx; top:$nodeypx; width:0px; height:0px; z-index:$layer\">
<form name=\"form\" method=\"post\" action=\"editnodeform.php\">
	<input type=\"image\" src=\"images/$nodeimage\" name=\"clickat\" title=\"Edit Node: $node->name.\">
	<input type=\"hidden\" name=\"nodeid\" value=\"$nodeid\">
	<input type=\"hidden\" name=\"xorig\" value=\"$xorig\">
	<input type=\"hidden\" name=\"yorig\" value=\"$yorig\">
        <input type=\"hidden\" name=\"zoom\" value=\"$zoom\">
	<input type=\"hidden\" name=\"mapid\" value=\"$mapid\">
	</form>
</div>\n");
}

// Extra stuff that goes below the map
include("debug.php");

// Finish the page
print ("</body>
</html>
");
?>
Return current item: Wifimap