Location: PHPKode > projects > Wifimap > wifimap/addnode.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="addnode.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($zoom)) $zoom=$row->defaultzoom;
// Make $*orig a multiple of zoom
if(!isset($xorig)) $xorig=$row->xorig; else $xorig-=$xorig%$zoom;
if(!isset($yorig)) $yorig=$row->yorig; else $yorig-=$yorig%$zoom;
if(!isset($mapsizex)) $mapsizex=$row->dispcellsx;
if(!isset($mapsizey))$mapsizey=$row->dispcellsy;

$cellsize=$row->cellsize;

if(isset($clickat_x))
  {
// We need these values below
    $absolutex=($cellsx*$cellsize)+($clickat_x*$zoom);
    $absolutey=($cellsy*$cellsize)+($clickat_y*$zoom);
  }

// 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;

//$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);

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["Add a Node"]."</h2></td>\n");
include("./legend.php");
include("./mapsizes.php");
print("</tr>
</table>\n");
print("".$i18n["addnode-instructions"]."\n");
//print("Displaying $count nodes.\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(" <form name=\"form\" method=\"post\" action=\"$thisfile\">
        <input type=\"image\" src=\"$row->imagesource\" name=\"clickat\" alt=\"Select your location on the map.\">
        <input type=\"hidden\" name=\"cellsx\" value=\"$xvar\">
        <input type=\"hidden\" name=\"cellsy\" value=\"$yvar\">
        <input type=\"hidden\" name=\"mapsizex\" value=\"$mapsizex\">
        <input type=\"hidden\" name=\"mapsizey\" value=\"$mapsizey\">
        <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>");
				}
				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");

//include("drawlinks.php");

// 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());
$result = mysql_query("SELECT * FROM nodes WHERE mapid=$mapid AND absolutex>=$absx_start AND absolutex<=$absx_end AND absolutey>=$absy_start AND absolutey<=$absy_end",$db_link);
while ($node = mysql_fetch_object($result)) 
  {
    $nodex=($node->absolutex-$absx_start)/$zoom;   $nodex-=6;   $nodex+=$mapborder;   $nodexpx=$nodex.px;
    $nodey=($node->absolutey-$absy_start)/$zoom;   $nodey-=6;   $nodey+=$mapborder;   $nodey+=$mapoffset;  $nodeypx=$nodey.px;
    $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.
    print("<div id=\"node\" style=\"position:absolute; left:$nodexpx; top:$nodeypx; width:0px; height:0px; z-index:$layer\"><img src=\"images/$nodeimage\" border=\"0\"></div>\n");
  }

// Display a crosshair
if(isset($absolutex)) 
  {
    $nodex=(($absolutex-$absx_start)/$zoom)-10+$mapborder;              $nodexpx=$nodex.px;
    $nodey=(($absolutey-$absy_start)/$zoom)-10+$mapborder+$mapoffset;   $nodeypx=$nodey.px;
    print("<div id=\"crosshair\" style=\"position:absolute; left:$nodexpx; top:$nodeypx; height:1px; z-index:$layer\"><img src=\"images/crosshair.png\" border=\"0\"></div>\n");
  }



// Extra stuff that goes after the map
$formoffset=($mapsizex*$cellsize)+($mapborder*2)+50;   $formoffsetpx=$formoffset.px;
print("<div id=\"dataform\" style=\"position:absolute; left:$formoffsetpx; top:$mapoffset; height:0px; z-index:2\">\n");
if(isset($absolutex))
  {
    print("<p>
<hr>
<form name=\"form\" method=\"post\" action=\"db_addnode.php\">
<table>
<tr><td>".$i18n["Node Name"]."</td>  <td><input type=\"text\" name=\"nodename\" value=\"\"></td></tr>
<tr><td>".$i18n["Password"]."</td>  <td><input type=\"text\" name=\"password\" value=\"\"></td></tr>
<tr><td>".$i18n["Admin Email"]."</td>  <td><input type=\"text\" name=\"email\" value=\"\"></td></tr>
<tr><td>".$i18n["URL"]."</td>  <td><input type=\"text\" name=\"url\" value=\"\"></td></tr>
<tr><td>".$i18n["Status"]."</td>  <td><select name=\"status\">
	<option value=\"1\">".$i18n["Operational"]."
	<option value=\"2\">".$i18n["Faulty"]."
	<option value=\"3\">".$i18n["Planned"]."
</select></td></tr>
<input type=\"hidden\" name=\"absolutex\" value=\"$absolutex\">
<input type=\"hidden\" name=\"absolutey\" value=\"$absolutey\">
<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\">
<tr><td></td><td><input type=\"submit\" name=\"Submit\" value=\"Submit Information\"></td></tr>
</form>
");
  }
print("</div>\n");

include("debug.php");

// Finish the page
print ("</body>
</html>\n");

?>
Return current item: Wifimap