map_display.php 21.4 KB
Newer Older
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1
2
3
4
<?php
/**
 * @name       MeshMap - a dynamic map for the mesh network
 * @category   Mesh
5
 * @author     Eric Satterlee, KG6WXC with Glen, K6GSE and Mark, N2MH
Eric - kg6wxc's avatar
Eric - kg6wxc committed
6
 * @version    $Id$
7
 * @copyright  Copyright (c) 2018 as Open Source
8
 * @license    GPLv3 or later
Eric - kg6wxc's avatar
Eric - kg6wxc committed
9
 * @abstract   Eric has written a tool called get-map-info which retrieves AREDNmesh network devices,
Eric - kg6wxc's avatar
Eric - kg6wxc committed
10
11
12
13
14
15
16
17
18
 *                     their configuration and Linkage information. These details are populated in several SQL tables.
 *                     The map.php routine extracts the DB details and creates a dynamic map of those nodes and links.
 *
 *             The primary display tools are:
 *             Map Drawing by Leaflet http://leafletjs.com
 *             Map data by OpenStreetMap http://openstreetmap.org
 *                   with contributions from: CC-BY-SA http://creativecommons.org/licenses/by-sa/2.0/
 *             Map tiles by Stamen Design http://stamen.com, under CC BY 3.0
 *             Map style http://viewfinderpanoramas.org
19
 *             Non Mesh Marker Icons from http://www.flaticon.com under CC BY 3.0
Eric - kg6wxc's avatar
Eric - kg6wxc committed
20
21
22
 *             OpenTopoMap https://opentopomap.org
 *
 **************************************************************************/
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/******
* This file is part of the Mesh Mapping System.
* The Mesh Mapping System 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 3 of the License, or
* (at your option) any later version.
*
* The Mesh Mapping System 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 The Mesh Mapping System.  If not, see <http://www.gnu.org/licenses/>.
******/
38

39
40
41
42
43
44
45
//Increase PHP memory limit to 128M (you may need more if you are connected to a "Mega Mesh" :) )
ini_set('memory_limit', '128M');

/******
* You should not need to change much below here
******/

Eric - kg6wxc's avatar
Eric - kg6wxc committed
46
47
48
49
50
header("Cache-Control: no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
header("Expires: 0");


Eric - kg6wxc's avatar
Eric - kg6wxc committed
51
$INCLUDE_DIR = "..";
52
53
54
55

//check for users user-settings.ini file and use it if it exists
//use the default one if it does not
global $USER_SETTINGS;
56
if (file_exists($INCLUDE_DIR . "/scripts/user-settings.ini")) {
57
58
    $USER_SETTINGS = parse_ini_file($INCLUDE_DIR . "/scripts/user-settings.ini");
}else {
Eric - kg6wxc's avatar
Eric - kg6wxc committed
59
    exit("You <strong><em>must</em></strong> copy the user-settings.ini-default file to user-settings.ini and edit it!\n");
60
61
    //$USER_SETTINGS = parse_ini_file($INCLUDE_DIR . "/scripts/user-settings.ini-default");
}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
62
global $MESH_SETTINGS;
63
64
//check for users user-settings.ini file and use it if it exists
//use the default one if it does not
65
if (file_exists($INCLUDE_DIR . "/scripts/meshmap-settings.ini")) {
66
67
68
69
70
    $MESH_SETTINGS = parse_ini_file($INCLUDE_DIR . "/scripts/meshmap-settings.ini");
}else {
    $MESH_SETTINGS = parse_ini_file($INCLUDE_DIR . "/scripts/meshmap-settings.ini-default");
}

Eric - kg6wxc's avatar
Eric - kg6wxc committed
71

72

Eric - kg6wxc's avatar
Eric - kg6wxc committed
73
74
75
require $INCLUDE_DIR . "/scripts/wxc_functions.inc";
require $INCLUDE_DIR . "/scripts/map_functions.inc";

Eric - kg6wxc's avatar
Eric - kg6wxc committed
76
//commented out for timezone fizes -wxc 11-27-2018
Eric - kg6wxc's avatar
Eric - kg6wxc committed
77
78
global $localTimeZone;
$localTimeZone = new DateTimeZone($USER_SETTINGS['localTimeZone']);
79
80
81
82
83
84
85
86
87
88

/*
 * This section will try to tell if the client has internet access or not
 * If we are being called from the mesh, without internet access,
 * we use the offline copies of the add-on scripts and try to load maps locally
 * If there is internet access, set it up so everything is fetched from the internet
 */
global $inetAccess;
global $mesh;

Eric - kg6wxc's avatar
Eric - kg6wxc committed
89
90
91
92
93
94
95
96
97
98
99
100
101
if (isset($_COOKIE['meshmapClientInetAccess'])) {
    $inetAccess = $_COOKIE['meshmapClientInetAccess'];
    if ($inetAccess == "1") {
        $mesh = "0";
    }elseif ($inetAccess == "0") {
        $mesh = "1";
    }
}else {
    $inetAccess = "0";
    $mesh = "1";
}

/*
102
103
if (isset($_POST['inetAccess'])) {
    $inetAccess = $_POST['inetAccess'];
104
105
106
107
108
109
110
111
112
    if ($inetAccess == "1") {
        $mesh = "0";
    }elseif ($inetAccess == "0") {
        $mesh = "1";
    }
}else {
    $inetAccess = "0";
    $mesh = "1";
}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
113
*/
114
@include $INCLUDE_DIR . "/custom.inc";
115

Eric - kg6wxc's avatar
Eric - kg6wxc committed
116
//if (!isset($GLOBALS['internet_only'])) {
117
118
119
120
121
122
function testForInet() {
    $page = <<< EOD
<!DOCTYPE html>
<html>
<head>
<title>meshmap internet check page</title>
Eric's avatar
Eric committed
123
124
125
<meta property="og:sitename" content="KG6WXC MeshMap">
<meta property="og:locale" content="en-US">
<meta property="og:type" content="website">
126
<meta property="og:title" content="Map your local Amateur Radio MESH Network">
Eric's avatar
Eric committed
127
<meta property="og:description" content="The KG6WXC MeshMap is Automated Mapping of AREDN MESH Networks.">
128

Eric's avatar
Eric committed
129
130
EOD;

131
132
133
134
//echo "<meta property='og:url' content='" . $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['CONTEXT_PREFIX'] . "'>\n";
//echo "<meta property='og:image' content='" . $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['CONTEXT_PREFIX'] . "/images/MESHMAP_LOGO.png'>\n";
$page .= "<meta property='og:url' content='" . $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['CONTEXT_PREFIX'] . "'>\n";
$page .= "<meta property='og:image' content='" . $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['CONTEXT_PREFIX'] . "/images/MESHMAP_LOGO.png'>\n";
Eric's avatar
Eric committed
135
136

$page .= <<< EOD
137
138
<script src='javascripts/ping.min.js'></script>
<script>
Eric - kg6wxc's avatar
Eric - kg6wxc committed
139
140
141
142
143
144
145
146
147
var now = new Date();
//expire in 1 day
//var cookieExpireTime = new Date(now.getTime() + 1 * 24 * 3600 * 1000);
//expire in 30 minutes
var cookieExpireTime = new Date(now.getTime() + (30 * 60 * 1000));
function setCookie(name, value) {
        document.cookie = name + "=" + escape(value) + "; expires=" + cookieExpireTime.toGMTString();
}

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
function postData(path, params, method) {
    method = method || "post";
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);
    for (var key in params) {
        if (params.hasOwnProperty(key)) {
            var hiddenField = document.createElement("input");
            hiddenField.setAttribute("type", "hidden");
            hiddenField.setAttribute("name", key);
            hiddenField.setAttribute("value", params[key]);

            form.appendChild(hiddenField);
        }
    }
    document.body.appendChild(form);
    form.submit();
}

var p = new Ping();
var value = "0";
p.ping("//google.com", function(err, data) {
        if (err) {
                value = 0;
        }else {
                value = 1;
        }
        //window.location.replace("map_display.php?inetAccess="+value);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
176
177
178
        //postData('map_display.php', {inetAccess: value});
        setCookie("meshmapClientInetAccess", value);
        window.location.replace("map_display.php");
179
180
181
182
183
184
185
186
187
188
189
190
191
192
});
</script>
</head>
<body>
Just a quick check for internet access so we can load the appropriate maps, etc...
<br>
Please be patient, this should only take a moment.
</body>
</html>
EOD;
    echo $page;
    //return;
    exit("<br><br>reloading...");
}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
193
//}
194
if (!isset($GLOBALS['internet_only'])) {
Eric - kg6wxc's avatar
Eric - kg6wxc committed
195
    if (!isset($_COOKIE['meshmapClientInetAccess'])) {
196
197
198
199
        testForInet();
    }
}

Eric - kg6wxc's avatar
Eric - kg6wxc committed
200
/*
201
202
* SQL Connection
*/
Eric - kg6wxc's avatar
Eric - kg6wxc committed
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
wxc_connectToMySQL();

/*
* Node Table Query
*/
global $useNodes;
global $useMarkers;
global $useLinks;
$NodeList = load_Nodes();
$MarkerList = load_Markers();
$TopoList = load_Topology();

// Get the last time we updated the link info
$filetime = wxc_scriptGetLastDateTime("LINKINFO", "topology");
if ($filetime)
{
    $filetime = date_format($filetime, 'F d Y H:i:s');
}

global $STABLE_MESH_VERSION;
$STABLE_MESH_VERSION = $USER_SETTINGS['current_stable_fw_version'];

Eric - kg6wxc's avatar
Eric - kg6wxc committed
225

Eric - kg6wxc's avatar
Eric - kg6wxc committed
226
227
228
229
230
231
232
233
234
//$page_header = <<< EOD
echo '<!DOCTYPE html>' . "\n";
echo '<!-- AREDNmesh dynamic network map -->' . "\n";
echo '<!-- Created by KG6WXC 2016-2018 with contributions and ideas from N2MH and K6GSE and others. -->' . "\n";
echo '<html lang="en" xmlns="http://www.w3.org/1999/xhtml">' . "\n";
echo '<head>' . "\n";
echo '<meta http-equiv="Pragma" content="no-cache">' . "\n";
echo '<meta http-equiv="Expires" content="-1">' . "\n";
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . "\n";
Eric's avatar
Eric committed
235
236
237
echo '<meta property="og:sitename" content="KG6WXC MeshMap">' . "\n";
echo '<meta property="og:local" content="en-US">' . "\n";
echo '<meta property="og:type" content="website">' . "\n";
238
echo '<meta property="og:title" content="Map your local Amateur Radio MESH Network">' . "\n";
Eric's avatar
Eric committed
239
240
241
242
243
244
245
echo '<meta property="og:description" content="The KG6WXC MeshMap is Automated Mapping of AREDN MESH Networks.">' . "\n";
//echo '<meta property="og:url" content="http://kg6wxc-srv.local.mesh/meshmap">' . "\n";
echo "<meta property='og:url' content='" . $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['CONTEXT_PREFIX'] . "'>\n";
echo "<meta property='og:image' content='" . $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['CONTEXT_PREFIX'] . "/images/MESHMAP_LOGO.png'>\n";
//echo "<meta property='og:image:height' content='1200'>\n";
//echo "<meta property='og:image:width' content='1200'>\n";
//echo '<meta property="og:image" content="images/MESHMAP_LOGO.png">' . "\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
246
//EOD;
Eric - kg6wxc's avatar
Eric - kg6wxc committed
247

Eric - kg6wxc's avatar
Eric - kg6wxc committed
248
//echo $page_header . "\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
249
250
echo "<title>" . $USER_SETTINGS['pageTitle'] . "</title>\n";

251
252
253
254
255
256
257
258
259
260
/*
 * If the client has internet access load everything from there
 * if not, use the local resources.
 */
if (!$mesh) {
    echo "<link rel='stylesheet' href='//unpkg.com/leaflet@1.3.1/dist/leaflet.css'>\n";
    echo "<script src='//unpkg.com/leaflet@1.3.1/dist/leaflet.js'></script>\n";
    echo "<script src='//bbecquet.github.io/Leaflet.PolylineOffset/leaflet.polylineoffset.js'></script>\n";
    echo "<script src='//api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/Leaflet.fullscreen.min.js'></script>\n";
    echo "<link href='https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/leaflet.fullscreen.css' rel='stylesheet'>\n";
261
    echo "<link rel='stylesheet' href='https://use.fontawesome.com/releases/v5.0.10/css/all.css' integrity='sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg' crossorigin='anonymous'>\n";
262

263

264
265
266
267
268
269
}else {
    echo "<link href='css/leaflet.css' rel='stylesheet'>\n";
    echo "<script src='javascripts/leaflet.js'></script>\n";
    echo "<script src='javascripts/leaflet.polylineoffset.js'></script>\n";
    echo "<script src='javascripts/Leaflet.fullscreen.min.js'></script>\n";
    echo "<link href='css/leaflet.fullscreen.css' rel='stylesheet'>\n";
270
    echo "<link href='javascripts/fontawesome-all.css' rel='stylesheet'>\n";
271
}
272
273
echo "<script src='javascripts/leaflet.groupedlayercontrol.js'></script>\n";
echo "<link rel='stylesheet' href='css/leaflet.groupedlayercontrol.css'>\n";
274
echo "<script src='javascripts/leaflet-hash.js'></script>\n";
275
276
echo "<script src='javascripts/L.Control.SlideMenu.js'></script>\n";
echo "<link href='css/L.Control.SlideMenu.css' rel='stylesheet'>\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
277
278
echo "<script src='javascripts/leaflet-ruler.js'></script>\n";
echo "<link rel='stylesheet' type='text/css' href='css/leaflet-ruler.css'>\n";
279
280
echo "<link rel='stylesheet' href='css/leaflet-search.css'>\n";
echo "<script src='javascripts/leaflet-search.src.js'></script>\n";
281
282
echo "<!-- SPIDERFY ( https://github.com/robertleeplummerjr/OverlappingMarkerSpiderfier-Leaflet ) -->\n";
echo "<script src='javascripts/spiderfy.js'></script>\n";
283

Eric - kg6wxc's avatar
Eric - kg6wxc committed
284

Eric's avatar
Eric committed
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/*
 * check for the users custom.css files and use them if exists...
 * load the "-default" files first (meshmap-default.css)
 * and the user files second, that way changes in the users file(s)
 * will override the default ones (if I understand CSS correctly)
 * These can also be used to override CSS values from anything above!
 */
echo "<link href='css/meshmap-default.css' rel='stylesheet'>\n";
if (file_exists ("./css/meshmap.css")) {
	echo "<link href='css/meshmap.css' rel='stylesheet'>\n";
}

//same thing but for legend.css (which controls the map legend)
echo "<link href='css/map-legend-default.css' rel='stylesheet'>\n";
if (file_exists ("./css/map-legend.css")) {
	echo "<link href='css/map-legend.css' rel='stylesheet'>\n";
}

//same thing, but for some custom controls
//these can be used to move the main buttons (on the left) around on the map
echo "<link href='css/leaflet-custom-control-vertical-center-default.css' rel='stylesheet'>\n";
if (file_exists ("./css/leaflet-custom-control-vertical-center.css")) {
	echo "<link href='css/leaflet-custom-control-vertical-center.css' rel='stylesheet'>\n";
}

Eric - kg6wxc's avatar
Eric - kg6wxc committed
310
311
312
313
314
315
316
317
318
319
320
321
echo "\n";
echo "</head>\n";
echo "<body>\n";

// If this page *is* called from an Internet enabled site:
// Remove the top logo and make the map a bit smaller
// so that it fits in the nice little iFrame page
// Otherwise render a normal map page.

//GSE: [Removed]  if ($_SERVER['HTTP_HOST'] == $USER_SETTINGS['meshServerHostName'] || $_SERVER['HTTP_HOST'] ==
//    "kg6wxc-host.local.mesh"
//)
322
323
if (isset($USER_SETTINGS['map_iFrame_Enabled']) && ($USER_SETTINGS['map_iFrame_Enabled'])) {
    if(isset($GLOBALS['map_div_embedded'])) {
324
    	echo "<div id='meshmap' style='margin: 0px;'>\n"; // Closing tag at end of primary routine
325
326
    	echo $GLOBALS['map_div_embedded'];
    }else {
327
    	echo "<div id='meshmap'>\n"; // Closing tag at end of primary routine
328
329
330
    	echo "<div id='mapid'></div>\n";
    }
}else {
331
    echo "<div id='meshmap'>\n"; // Closing tag at end of primary routine
332
333
334
    
    echo "<div id='mapHeader'>\n";
    
335
    if (isset($USER_SETTINGS['pageLogo'])) {
Eric - kg6wxc's avatar
Eric - kg6wxc committed
336
337
338
        //echo "<MapTitle>";
        echo "<img class='maptitle' id='pageLogo' src='" . $USER_SETTINGS['pageLogo'] . "' alt='The Logo'>";
        //echo "</MapTitle>\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
339
    }
340
    if (isset($USER_SETTINGS['logoHeaderText'])) {
Eric - kg6wxc's avatar
Eric - kg6wxc committed
341
342
343
        //echo "<MapTitle>";
        echo '<p class="maptitle">' . $USER_SETTINGS['logoHeaderText'] . '</p>';
        //echo "</MapTitle>\n";
344
        echo "<br>";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
345
    }
346
    if (isset($USER_SETTINGS['welcomeMessage'])) {
Eric - kg6wxc's avatar
Eric - kg6wxc committed
347
348
        //echo "<Welcome_MSG>";
        echo '<p class="welcomeMsg">' . $USER_SETTINGS['welcomeMessage'] . '</p>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
349
350
        //echo "<br>";
        echo "&nbsp;&nbsp;";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
351
        //echo "</Welcome_MSG>\n";
352
353
    }
    if (isset($USER_SETTINGS['otherTopOfMapMsg'])) {
Eric - kg6wxc's avatar
Eric - kg6wxc committed
354
355
356
		//echo "<Welcome_MSG2>";
		echo '<p class="welcomeMsg2">' . $USER_SETTINGS['otherTopOfMapMsg'] . '</p>';
		//echo "</Welcome_MSG2>\n";
357
		echo "<br>";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
358
    }
Eric - kg6wxc's avatar
Eric - kg6wxc committed
359
360
361
362
363
    //if (isset($USER_SETTINGS['meshWarning']) && $mesh) {
    if (isset($USER_SETTINGS['meshWarning'])) {
        //echo "<Warning_MSG>";
        echo '<p class="warningMsg">' . $USER_SETTINGS['meshWarning'] . '</p>';
        //echo "</Warning_MSG>";
364
        echo "<br>";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
365
    }
366
367
    
    echo "</div>\n"; // end of mapHeader <div>
Eric - kg6wxc's avatar
Eric - kg6wxc committed
368
369
}

370
371
372
373
374
if (isset($GLOBALS['hide_admin'])) {
    if ($GLOBALS['hide_admin'] == "1") {
        //output nothing!!
    }
}else {
Eric - kg6wxc's avatar
Eric - kg6wxc committed
375
376
	//do not need anymore?
    //echo "<strong><a style=\"float: right;\" href=\"admin/admin.php\">Admin</a></strong>\n";
377
378
}

379
380
381
if (isset($USER_SETTINGS['map_iFrame_Enabled']) && !($USER_SETTINGS['map_iFrame_Enabled'])) {
	echo "<div id='mapid'></div>\n";
}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
382
383
384
385

//$numNodes = count($NodeList);	// WXC change: this was giving the wrong number.
//should not count nodes that have no location info, they are not on the map...
//just using this for now.
Eric - kg6wxc's avatar
Eric - kg6wxc committed
386
387

//it is still giving the wrong number WXC -april 2018
388
389
390
//changing this based on other changes to get-map-info - may 2018
//$numNodes = wxc_getMySql("SELECT COUNT(*) as nodesWithLocations FROM node_info where (lat is not null or 0 or '') and (lon is not null or 0 or '')");
$numNodes = wxc_getMySql("SELECT COUNT(*) as nodesWithLocations FROM node_info where (lat != '0') and (lon != '0')");
Eric - kg6wxc's avatar
Eric - kg6wxc committed
391
392
393
394
395
396
397
398
$numNodes = $numNodes['nodesWithLocations'];
$numNodesTotal = count($NodeList);

//WXC comment: looks like this was for something else maybe?...
$numMarkers = count($MarkerList);

//$numLinks = count($TopoList);	// WXC change: probably the same thing going on here too
//just using this for now
Eric - kg6wxc's avatar
Eric - kg6wxc committed
399
//same here, probably still giving the wrong number WXC - april 2018
400
//changing this based on other changes to get-map-info - may 2018
Eric - kg6wxc's avatar
Eric - kg6wxc committed
401
402
$numLinks = wxc_getMySql("SELECT COUNT(*) as linksWithLocations FROM topology WHERE (nodelat != '0' or NULL or 0) and (nodelon != '0' or NULL or 0) or (linklat != '0' or NULL or 0) and (linklon != '0' or NULL or 0)");
//$numLinks = wxc_getMySql("SELECT COUNT(*) as linksWithLocations FROM topology WHERE (nodelat != '0' or NULL) and (nodelon != '0' or NULL) or (linklat != '0' or NULL) and (linklon != '0' or NULL)");
Eric - kg6wxc's avatar
Eric - kg6wxc committed
403
404
405
406
407
408
409
410
411
$numLinks = $numLinks['linksWithLocations'];
$numLinksTotal = count($TopoList);

$Content = "";

$filetime = 'Today';

//$Content .= "<div id='mapid' style='width: 100%; height: 95%;'>\n";
//$Content .= "</div>\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
412
$Content .= "<script>";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434

$Content .= add_MapLayers();
$Content .= add_MapImages($numNodes, $numLinks, $numMarkers);
$Content .= create_MapLayers($numNodes, $numLinks, $numMarkers);
$Content .= create_MapOverlays($numNodes, $numLinks, $numMarkers);
$Content .= build_NodesAndLinks($NodeList, $TopoList, $MarkerList);
$Content .= create_MapLegend();
$Content .= create_MapImage();
$Content .= show_MapMarkerDetails($numNodes, $numLinks, $numMarkers, $numNodesTotal, $numLinksTotal);
$Content .= instantiate_Map();
/*
* Mesh messages and notes
*/

//if ($mesh && $USER_SETTINGS['meshServerText'])
//{
//    echo "<Mesh_MSG>";
//    echo sprintf($USER_SETTINGS['meshServerText'], $USER_SETTINGS['meshServerHostName']);
//    echo "<br>";
//    echo "</Mesh_MSG>";
//}

435
$Content .= "</script>\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
436

Eric - kg6wxc's avatar
Eric - kg6wxc committed
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
$Content .= '<script>' . "\n" .
		'var ldgHidden = document.getElementsByClassName("legendHidden");' . "\n" .
		'ldgHidden[0].style.display = "none";' . "\n" .
		'function hideLegend() {' . "\n" .
			'var lgd = document.getElementsByClassName("legend");' . "\n" .
			'var lgdHidden = document.getElementsByClassName("legendHidden");' . "\n" .
			'if (lgd[0].style.display === "" || lgd[0].style.display === "block") {' . "\n" .
				'lgd[0].style.display = "none";' . "\n" .
				'lgdHidden[0].style.display = "block";' . "\n" .
			'}else {' . "\n" .
				'lgd[0].style.display = "block";' . "\n" .
				'lgdHidden[0].style.display = "none";' . "\n" .
			'}' . "\n" .
		'}' . "\n" .
	'</script>' . "\n";

Eric - kg6wxc's avatar
Eric - kg6wxc committed
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
//autorefesh mechanism
if (!isset($refresh) || $refresh == 1) {
$Content .= <<< EOD
	<script>
	var autoRefreshCookieValue = 0;
	var now = new Date();
	//expire in 1 day
	var cookieExpireTime = new Date(now.getTime() + 1 * 24 * 3600 * 1000);
	//expire in 30 minutes
	//var cookieExpireTime = new Date(now.getTime() + (30 * 60 * 1000));
	function setCookie(name, value) {
        document.cookie = name + "=" + escape(value) + "; expires=" + cookieExpireTime.toGMTString();
	}
	function getCookie(cname) {
    	var name = cname + "=";
    	var decodedCookie = decodeURIComponent(document.cookie);
    	var ca = decodedCookie.split(';');
    	for(var i = 0; i <ca.length; i++) {
        	var c = ca[i];
        	while (c.charAt(0) == ' ') {
            	c = c.substring(1);
        	}
        	if (c.indexOf(name) == 0) {
            	return c.substring(name.length, c.length);
        	}
    	}
    	return "";
	}
	function checkForAutoRefreshCookie() {
    	var arCookie = getCookie("meshmapAutoRefresh");
    	if (arCookie != "") {
			autoRefreshCookieValue = arCookie;
    	} else {
			setCookie("meshmapAutoRefresh", 0);
        }
	}
	L.Control.autoRefresh = L.Control.extend({
		options: {
			position: 'topleft'
		},
		onAdd: function(map) {
			var refreshControl = L.DomUtil.create('div', 'leaflet-control-custom leaflet-bar');
			refreshControl.style.backgroundColor = 'white';
			refreshControl.style.width = '30px';
			refreshControl.style.height = '30px';
			refreshControl.title = 'Toggle Auto Refresh\\nEvery 10 minutes';
			var link = L.DomUtil.create('a', 'leaflet-bar-part leaflet-bar-part-single', refreshControl);
			var refreshIcon = L.DomUtil.create('span', 'fa fa-sync-alt', link);
			refreshIcon.style.fontSize = '20px';
			refreshIcon.style.verticalAlign = 'middle';
			checkForAutoRefreshCookie();
			if (autoRefreshCookieValue == 1) {
					refreshIcon.style.color = 'green';
					refreshControl.style.background = 'black';
					document.addEventListener("DOMContentLoaded", function(event) {
						if (getCookie("meshmapAutoRefresh")) {
							setTimeout(function() {
								window.location.reload(1);
							}, 600000);
						}});
			}
			if (autoRefreshCookieValue == 0) {
					refreshIcon.style.color = 'grey';
					refreshControl.style.background = 'lightgrey';
			}
			refreshControl.onclick = function() {
				autoRefreshCookieValue = getCookie("meshmapAutoRefresh");
				if (autoRefreshCookieValue == 1) {
					refreshIcon.style.color = 'grey';
					refreshControl.style.background = 'lightgrey';
					setCookie("meshmapAutoRefresh", 0);
					window.location.reload(1);
				}else {
					refreshIcon.style.color = 'green';
					refreshControl.style.background = 'black';
					setCookie("meshmapAutoRefresh", 1);
					window.location.reload(1);
				}
			}
			return refreshControl;
		}
	});
	L.control.autoRefresh = function(opts) {
		return new L.Control.autoRefresh(opts);
	}
	//refresh control button
	L.control.autoRefresh().addTo(map);
			
	</script>
542

Eric - kg6wxc's avatar
Eric - kg6wxc committed
543
EOD;
544

Eric - kg6wxc's avatar
Eric - kg6wxc committed
545
546
}

Eric - kg6wxc's avatar
Eric - kg6wxc committed
547
$Content .= "</div>\n"; // Closing tag
Eric - kg6wxc's avatar
Eric - kg6wxc committed
548
549
550
551

// Display Page
echo $Content;

552
553
554
555
556
557
558
// the final scaling of the map div
// kinda hacky but it works well enough for now.
$scaling = <<<EOD
<script>
	var userAgent = window.navigator.userAgent;
	var map = document.getElementById("mapid");
	var header = document.getElementById("mapHeader");
559
	if(header.offsetHeight != 0 || !header) {
560
561
		var offset = header.offsetHeight;
		var search4FF = /Firefox/;
562
		if(search4FF.test(userAgent)) {
563
564
565
			offset = offset + 14;
		}
		str = "calc(100vh - " + offset + "px)";
566
		map.style.height = str;
567
568
	}
</script>
Eric - kg6wxc's avatar
Eric - kg6wxc committed
569

570
EOD;
Eric - kg6wxc's avatar
Eric - kg6wxc committed
571

572
echo $scaling;
Eric - kg6wxc's avatar
Eric - kg6wxc committed
573

Eric - kg6wxc's avatar
Eric - kg6wxc committed
574
575
echo "</body>\n";
echo "</html>\n";
576
?>