|
From: <il...@pr...> - 2004-05-09 01:32:33
|
Update of /cvsroot/meshdb/www/db2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27507 Modified Files: view.php Log Message: Added a list of nearby nodes to the bottom of the page. Factored out common elevation calculations. Added class attributes to existing tables. Index: view.php =================================================================== RCS file: /cvsroot/meshdb/www/db2/view.php,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- view.php 18 Mar 2004 10:07:50 -0000 1.11 +++ view.php 9 May 2004 01:32:25 -0000 1.12 @@ -96,6 +96,59 @@ return ("x".strtolower($s) == "xnan"); } + function elev($loc1, $loc2) { + global $ZONE; + + $e1 = doubleval($loc1["e"]); + $n1 = doubleval($loc1["n"]); + $h1 = doubleval($loc1["h"]); + + $e2 = doubleval($loc2["e"]); + $n2 = doubleval($loc2["n"]); + $h2 = doubleval($loc2["h"]); + + $info = split(" ", + mybacktick("bin/elev -z ${ZONE} -a $e1 $n1 $h1" + ." -b $e2 $n2 $h2")); + + $distance = $info[0]; + $bearing1 = doubleval($info[1]) * 180 / M_PI; + if ($bearing1 < 0) $bearing1 += 360; + $bearing2 = doubleval($info[2]) * 180 / M_PI; + if ($bearing2 < 0) $bearing2 += 360; + $alt1 = doubleval($info[3]); + $alt2 = doubleval($info[4]); + $altmin = doubleval($info[5]); + $altmax = doubleval($info[6]); + $incl1 = $info[7]; + $incl2 = $info[8]; + $isclear = intval($info[9]); + + return array("distance" => $distance, + "bearing1" => $bearing1, + "bearing2" => $bearing2, + "alt1" => $alt1, + "alt2" => $alt2, + "altmin" => $altmin, + "altmax" => $altmax, + "incl1" => $incl1, + "incl2" => $incl2, + "isclear" => $isclear); + } + + function elevurl($loc1, $loc2, $w, $h) { + $e1 = doubleval($loc1["e"]); + $n1 = doubleval($loc1["n"]); + $h1 = doubleval($loc1["h"]); + + $e2 = doubleval($loc2["e"]); + $n2 = doubleval($loc2["n"]); + $h2 = doubleval($loc2["h"]); + + $elevarg = "e1=$e1&n1=$n1&h1=$h1&e2=$e2&n2=$n2&h2=$h2&w=$w&h=$h"; + return "elev.php?" . htmlspecialchars($elevarg); + } + include("lookup.inc.php"); header("Last-Modified: " . gmdate("D, d M Y H:i:s", $maxupdated) . " GMT"); @@ -124,11 +177,11 @@ if ($hasloc && $peerid) { $result = mysql_query("SELECT n,e,h from physloc where nodeid=$peerid", $db) or die(mysql_error($db)); - $row = mysql_fetch_row($result); - if ($row) { - $n2 = doubleval($row[0]); - $e2 = doubleval($row[1]); - $h2 = doubleval($row[2]); + $peerloc = mysql_fetch_assoc($result); + if ($peerloc) { + $n2 = doubleval($peerloc["n"]); + $e2 = doubleval($peerloc["e"]); + $h2 = doubleval($peerloc["h"]); } else { $peermsg = "Nodeid $peerid doesn't exist"; $peerid = false; @@ -164,13 +217,13 @@ <table> <tr valign=top> - <td><table> + <td><table class="node"> <tr><th colspan=3 class="major">Node information (site)</th></tr> <? include("view.inc.php"); ?> </table> <? if ($netloc["ifnames"]) { ?> - <table> + <table class="interfaces"> <tr><th colspan=3 class="major">Network interfaces (cards + antennas)</th></tr> <? include("view-netloc.inc.php"); ?> </table> @@ -182,7 +235,7 @@ $result = mysql_query($q, $db) or die(mysql_error($db)); if (mysql_num_rows($result)) { ?> - <table> + <table class="incoming"> <tr><th colspan=4 class="major">Incoming links</th></tr> <tr><th class="minor">Node</th> <th class="minor">Name</th> @@ -278,7 +331,7 @@ $paramb = htmlspecialchars($paramb); ?> <td> - <table> + <table class="maps"> <tr><th class="major">Maps</th></tr> <? foreach ($maps as $maptype) { @@ -361,8 +414,8 @@ echo "<option value=\"\" selected>(none)</option>\n"; if ($PREF["viewpeersortdist"]) { $sort = "dist"; - if (intval($PREF["indexlimit"]) > 0) - $limit = "LIMIT ".intval($PREF["indexlimit"]); + if (intval($PREF["viewpeermenulimit"]) > 0) + $limit = "LIMIT ".intval($PREF["viewpeermenulimit"]); } else $sort = "admin.nodeid"; $result = mysql_query("SELECT admin.nodeid, nodename, sqrt(pow($n - n, 2) + pow($e - e, 2)) AS dist FROM admin,physloc WHERE admin.nodeid = physloc.nodeid AND n IS NOT NULL AND e IS NOT NULL ORDER BY $sort $limit", $db) @@ -390,23 +443,13 @@ <?=$peermsg?> </td></tr> <? - if ($peerid) { - $n1 = doubleval($physloc["n"]); - $e1 = doubleval($physloc["e"]); - $h1 = doubleval($physloc["h"]); - - $e2 = doubleval($e2); /* paranoia */ - $n2 = doubleval($n2); - $h2 = doubleval($h2); - - $w = $IMGWIDTH; - $hh = $IMGHEIGHT / 2; - $elevarg = "e1=$e1&n1=$n1&h1=$h1&e2=$e2&n2=$n2&h2=$h2&w=$w&h=$hh"; - $elevarg = htmlspecialchars($elevarg); + if ($peerid) { + $w = $IMGWIDTH; + $hh = $IMGHEIGHT / 2; - $info = split(" ", mybacktick("bin/elev -z ${ZONE} -a $e1 $n1 $h1 -b $e2 $n2 $h2")); + $info = elev($physloc, $peerloc); - if (isnan($info[0])) { + if (isnan($info["distance"])) { $distance = "unknown"; $pathloss24 = 0; $pathloss58 = 0; @@ -417,52 +460,44 @@ * = 20*log10(R) + 40.17 @ f=2.431e9 * = 20*log10(R) + 47.72 @ f=5.8e9 */ - $distance = doubleval($info[0]); + $distance = doubleval($info["distance"]); $pathloss24 = 20*log10($distance) + 40.1652687; $pathloss58 = 20*log10($distance) + 47.7163430931; $distance = sprintf("%.2fm", $distance); } - $bearing1 = doubleval($info[1]) * 180 / M_PI; - if ($bearing1 < 0) $bearing1 += 360; - $bearing2 = doubleval($info[2]) * 180 / M_PI; - if ($bearing2 < 0) $bearing2 += 360; - $alt1 = doubleval($info[3]); - $alt2 = doubleval($info[4]); - $altmin = doubleval($info[5]); - $altmax = doubleval($info[6]); - if (isnan($info[7]) || isnan($info[8])) { - $incl1 = $incl2 = "?"; + if (isnan($info["incl1"]) || isnan($info["incl2"])) { + $incl1 = $incl2 = "?"; } else { - $incl1 = sprintf("%.2f",doubleval($info[7]) * 180 / M_PI); - $incl2 = sprintf("%.2f",doubleval($info[8]) * 180 / M_PI); + $incl1 = sprintf("%.2f", doubleval($info["incl1"]) * 180 / M_PI); + $incl2 = sprintf("%.2f", doubleval($info["incl2"]) * 180 / M_PI); } ?> <tr><td><table> - <tr><td valign=top><?printf("%.0f", $altmax)?>m</td> + <tr><td valign=top><?printf("%.0f", $info["altmax"])?>m</td> <td class="figure" colspan=2 rowspan=2><img width="<?=$w?>" height="<?=$hh?>" - src="elev.php?<?=$elevarg?>"></td></tr> - <tr><td valign=bottom> <?printf("%.0f", $altmin)?>m</td></tr> + src="<?=elevurl($physloc, $peerloc, $w, $hh)?>"></td></tr> + <tr><td valign=bottom> <?printf("%.0f", $info["altmin"])?>m</td></tr> <tr><td></td> <td colspan=2 class="caption" align=center><?=$distance?></td></tr> <tr><td></td> <td class="caption"> <strong><?=$nodename?></strong> <br> - Altitude: <? printf("%.2f", $alt1 + $h1); ?>m + Altitude: <? printf("%.2f", $info["alt1"] + $h1); ?>m <br> - Azimuth: <? printf("%.2f", $bearing1); ?>° + Azimuth: <? printf("%.2f", $info["bearing1"]); ?>° <br> Inclination: <?=$incl1?>° </td> <td class="caption"> <strong><a href="view.php?nodeid=<?=$peerid?>&peerid=<?=$nodeid?>"><?=$peername?></a></strong> <br> - Altitude: <? printf("%.2f", $alt2 + $h2); ?>m + Altitude: <? printf("%.2f", $info["alt2"] + $h2); ?>m <br> - Azimuth: <? printf("%.2f", $bearing2); ?>° + Azimuth: <? printf("%.2f", $info["bearing2"]); ?>° <br> Inclination: <?=$incl2?>° </td> @@ -505,6 +540,91 @@ </tr></table> +<? +if ($hasloc) { + if (isset($nodes)) + $peerlimit = intval($nodes); + else + $peerlimit = intval($PREF["viewpeertablelimit"]); + if ($peerlimit == 0 || $peerlimit > 100) + $peerlimit = 100; + $infinite = 100000000; + $result = mysql_query("SELECT" + ." admin.nodeid as nodeid," + ." nodename," + ." suburb," + ." to_days(now())-to_days(admin.updated) as age," + ." e," + ." n," + ." h," + ." ifnull(sqrt(pow(e - ".$physloc["e"].", 2) +" + ." pow(n - ".$physloc["n"].", 2))," + ." $infinite) as distance," + ." admin.status as status" + ." FROM admin, physloc, physaddr" + ." WHERE admin.nodeid = physloc.nodeid" + ." AND admin.nodeid = physaddr.nodeid" + ." AND admin.nodeid != $nodeid" + ." ORDER BY distance" + ." LIMIT $peerlimit") + or die(mysql_error($db)); + +?> + <table class="nearby"> + <tr><th class="major" colspan="8">Nearby nodes</th></tr> + <tr> + <th class="minor">ID</th> + <th class="minor">Name</th> + <th class="minor">Suburb</th> + <th class="minor">Status</th> + <th class="minor">Age</th> + <th class="minor">Distance</th> + <th class="minor">Bearing</th> + <th class="minor">Elevation diagram</th> + </tr> +<? + $w = 100; + $hh = 32; + + while ($row = mysql_fetch_assoc($result)) { + $info = elev($physloc, $row); + + /* Format the distance as a whole number of metres. */ + if (isnan($info["distance"])) { + $distance = "unknown"; + } else { + $distance = sprintf("%.0fm", doubleval($info["distance"])); + } + + if ($info["isclear"] || !$PREF["viewlosonly"]) { +?> + <tr> + <td class="peerid number"><?=$row["nodeid"]?></td> + <td class="peername"><a href="<?=selfurl(array("nodeid"=>$row["nodeid"], "peerid"=>$nodeid))?>"><?=$row["nodename"]?></a></td> + <td class="peersuburb"><?=$row["suburb"]?></td> + <td class="peerstatus <?=$row["status"]?>"><?=$row["status"]?></td> + <? if ($row["age"] > 0) { ?> + <td class="peerage number"><?=$row["age"]?>d</td> + <? } else { ?> + <td class="peerage number"> </td> + <? } ?> + <td class="peerdistance number"><?=$distance?></td> + <td class="peerbearing number"><?=intval($info["bearing1"])?>°</td> + <? + $elevarg = "e1=$e1&n1=$n1&h1=$h1&e2=$e2&n2=$n2&h2=$h2&w=$w&h=$hh"; + $elevarg = htmlspecialchars($elevarg); + ?> + <td class="peerelev"> + <img width="<?=$w?>" height="<?=$hh?>" src="<?=elevurl($physloc, $row, $w, $hh)?>"> + </td> + </tr> +<? + } /* isclear || !viewlosonly */ + } /* while row */ +} /* if $hasloc */ +?> +</table> + <ul> <li><a href="edit.php?nodeid=<?=$nodeid?>">Edit this node entry</a> <li><a href="index.php">Return to index</a> |