map_functions.inc 51.3 KB
Newer Older
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1
2
3
4
5
6
7
8
<?php

/**
 * @name        map_functions.inc
 * @category    MESH MAP
 * @subcategory Display Map routines
 * @package     Active Node List
 * @author      Eric Satterlee, KG6WXC with K6GSE
9
10
 * @copyright   Copyright (c) 2018 as Open Source
 * @license     GPLv3 or later
Eric - kg6wxc's avatar
Eric - kg6wxc committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 * @version     $Id$
 * @abstract    Eric has written a tool called get-map-info which retrieves HAM Mesh network devices,
 *                     their configuration and Linkage information. These details are populated in several SQL tables.
 *
 *
 *             These are the working functions for the meshMap display.
 *             There are three major sections of functions in this file:
 *             MESHMAP Map       - These are used to build the Markers and Links
 *             DATABASE access   - Used for all read-only access to the Database
 *             HTML Page Setup   - Used to build the infrastructure needed for the map display
 *
 *
 ********************************************************************************************************************/

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/******
* 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/>.
******/
Eric - kg6wxc's avatar
Eric - kg6wxc committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

/*
* MESHMAP Map Functions
*
*********************************************************************************************************************/
/**
 * @param $NodeList
 * @param $TopoList
 */
function build_NodesAndLinks($NodeList, $TopoList, $MarkerList = null)
{
    global $STABLE_MESH_VERSION;
    global $useNodes;
    global $useLinks;
    global $useMarkers;
    //icon names: default (green), update firmware (red) and for the different bands

57
    $markerList = '';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
58
59
60
61
62
63
64
65
66
67
68
69

    //then get info from the node info database
    //use it to:
    //1: create markers for the map
    //2: do lots of stuff, like, use the topology data to make the link lines,
    //try to detect the tunnels vs everything else,
    //check what band the device is on,
    //find distance and bearing info of linked nodes. :) yes really!
    //try and tell the dtd links apart from the ones that are not dtd links but appear to be,
    //*real* DTD links will be very close together, if not the same,
    //the others, (like what Ventura Mesh uses) will be far apart and therefore probably not a "real" dtd link.

70
    $display_NodeList = '';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
71
72
73
74
75
76
77
78
79
80
81
    if (is_array($NodeList) && !empty($NodeList))
    {
        foreach ($NodeList as $node_info)
        {
            $node_FirmwareStatus = checkVersion($node_info['firmware_version'], $STABLE_MESH_VERSION);

            if ($node_info['lat'] && $node_info['lon']) // Are there nodes with locations?
            {
                /*
                * find the Linked nodes to list
                *********************/
82
                $node_LinkedList = '';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
83
84
85
86
87
                $node_LinkedList = load_LinkedTO($node_info, $TopoList);

                /*
                * Find the Services for the node
                ********************************/
88
			//	$node_ServiceList = load_ServiceList($node_info['olsrinfo_json']);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
89
90
			//	$node_ServiceList = '';
                $node_ServiceList = load_ServiceList($node_info['services']);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
91
92
93
94
95
96
97
98
99
100
101
102
103

                /*
                * Build the Nodes Marker
                */
                $display_NodeList .= build_Marker($node_info, $node_ServiceList, $node_LinkedList, $node_FirmwareStatus);
            }
        }
        if (!empty($display_NodeList))
        {
            $display_NodeList = rtrim($display_NodeList); // Rtrim off an ending newline
        }
    }

104
    $display_MarkerList = '';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
    if (isset($useMarkers) && $useMarkers)
    {
        foreach ($MarkerList as $Marker)
        {
            if ($Marker['lat'] && $Marker['lon']) //Are there Markers with location?
            {
                $display_MarkerList .= buildStationMarker($Marker); // Build Marker
            }
        }
        if (!empty($display_MarkerList))
        {
            $display_MarkerList = rtrim($display_MarkerList); // Rtrim off an ending newline
        }
    }

    /*
    * Create and Display the Link Lines
    ****************************************/
123
    $display_LinkList = '';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
    if (isset($useLinks) && $useLinks)
    {
        $display_LinkList = load_LinkList($NodeList, $TopoList);
        if (!empty($display_LinkList))
        {
            $display_LinkList = rtrim($display_LinkList); // Rtrim off an ending newline
        }
    }
    $display_MarkersAndLinks = $display_NodeList . $display_MarkerList . $display_LinkList;
    if (!empty($display_MarkersAndLinks))
    {
        $display_MarkersAndLinks = rtrim($display_MarkersAndLinks, ','); // Trim off the very last comma
    }
    $display_MarkersAndLinks .= ";\n\n";

    return $display_MarkersAndLinks;
}

/**
 * loadServiceList
 * This function parses the json data obtained from the node.
 * It looks for all of the plugins/services installed on the node.
 * The Service_line format is:
 *         Link or host value | [TCP | UDP ] | Advertised  service
 *
 * This routine will return the last ( end ) field of the service line, which is the Advertised service
 *
 * @param $json_array
 *
 * @return string List of Services to Display
 */
Eric - kg6wxc's avatar
Eric - kg6wxc committed
155
function load_ServiceList($serviceList)
Eric - kg6wxc's avatar
Eric - kg6wxc committed
156
{
Eric - kg6wxc's avatar
Eric - kg6wxc committed
157
    $localServiceArray =  wxc_listServices($serviceList);
158
    $serviceList = '';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
159

Eric - kg6wxc's avatar
Eric - kg6wxc committed
160
    if (is_array($localServiceArray))
Eric - kg6wxc's avatar
Eric - kg6wxc committed
161
    {
Eric - kg6wxc's avatar
Eric - kg6wxc committed
162
    	foreach ($localServiceArray as $key => $value)
Eric - kg6wxc's avatar
Eric - kg6wxc committed
163
164
165
        {
            //WXC 6-30-2017: removed links for services that have no link
            if ($value == NULL) {
166
167
                //$serviceList .= "<br>". $key;
                $serviceList .= $key;
Eric - kg6wxc's avatar
Eric - kg6wxc committed
168
169
170
            }else {
                //WXC 6-30-2017: Moved <br> from after link to before the link,
                //made the pop up look better.
171
                $serviceList .= "<br><a href=\"" . $value . "\" target=\"service\">" . $key . "</a>";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
            }
        }
    }
    return $serviceList;
}

/**
 * loadLinkList
 * This function iterates through the topology array to build a leaflet package polyline
 * There are four types of links defined, each is represented by a different color.
 * RF Link - Standard Mesh Node link
 * DTD Link - Mesh nodes connected by direct link ( typically via a switch )
 * Tunnel Link -
 * Infinite Link - Links reported by and marked as unusable by olsr
 *
 * @param $NodeList
 * @param $TopoList
 *
 * @return mixed
 */
function load_LinkList($NodeList, $TopoList)
{
    global $MESH_SETTINGS;
195
    $linkList = "\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
196
197
198
199
    if (isset($TopoList))
    {
        foreach ($TopoList as $value)
        {
Eric's avatar
Eric committed
200
            if ((isset($value['nodelat'])) && (isset($value['linklon'])))
Eric - kg6wxc's avatar
Eric - kg6wxc committed
201
202
203
204
205
206
                //if there's no location info ignore the entry
            {
                $node_lat = $value['nodelat'];
                $node_lon = $value['nodelon'];
                $link_lat = $value['linklat'];
                $link_lon = $value['linklon'];
207
                $display_color = 'red';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
208
209
210
                $display_weight = 2;
                $display_opacity = 1;
                $display_offset = 2;
211
                $map_LayerAssigned = '';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
                $tunnel = 0;
                $dtd = 0;
                $moreThanTen = 0;
                $infinite = 0;
                $nodeHasTunnel = 0;
                $linkHasTunnel = 0;
                $nodeName = $value['node'];
                $linkName = $value['linkto'];
                if ($value['cost'] == 1.0 && !($tunnel)) //find the tunnels
                {
                    foreach ($NodeList as $searching_for_tunnels)
                    {
                        if ($searching_for_tunnels['node'] == $nodeName)
                        {
                            if ($searching_for_tunnels['active_tunnel_count'] >= 1)
                            {
                                $nodeHasTunnel = 1;
                            }
                        }
                        if ($searching_for_tunnels['node'] == $linkName)
                        {
                            if ($searching_for_tunnels['active_tunnel_count'] >= 1)
                            {
                                $linkHasTunnel = 1;
                            }
                        }
                        if (($linkHasTunnel) && ($nodeHasTunnel))
                        {
                            $tunnel = 1;
                            $nodeHasTunnel = 0;
                            $linkHasTunnel = 0;
                            $display_color = $MESH_SETTINGS['Link_Tunnel'];
                            $dtd = 1;
                            $display_opacity = 0.5;
246
                            $map_LayerAssigned = 'tunnelLinks';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
247
248
249
250
251
252
253
254
255
256
257
258
259
                        }
                    }
                }
                if ($value['cost'] == 0.1 && $value['distance'] <= 0.7)
                    //find DTD links (always a cost of 0.1)
                {
                    $display_color = $MESH_SETTINGS['DTD_Link_Minus'];
                    $dtd = 1;
                    $display_opacity = 0.2;
                    $map_LayerAssigned = 'dtdLinks';
                }
                //this is for the "other" DTD links
                //using other wireless tech to create links that are seen as "DTD" by the AREDN software
260
261
262
                //
                // this is also some (all) tunnels now after 3.20.3 changes
                // TODO: check this!
Eric - kg6wxc's avatar
Eric - kg6wxc committed
263
264
265
266
                if ($value['cost'] == 0.1 && $value['distance'] > 0.7)
                {
                    $display_color = $MESH_SETTINGS['DTD_Link_Plus'];
                    $dtd = 1;
267
268
269
270
                    //$display_opacity = 0.3;
                    $display_opacity = 1.0;
                    //$display_weight = 0.3;
                    $display_weight = 1.0;
Eric - kg6wxc's avatar
Eric - kg6wxc committed
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
                    $map_LayerAssigned = 'dtdLinks';
                }
                //find the "infinite cost" links (they show as "INFINITE" in the olsr files the other script changes that to 99.99)
                if ($value['cost'] == 99.99)
                {
                    $display_color = $MESH_SETTINGS['Link_Infinite'];
                    $infinite = 1;
                    $display_opacity = 0.2;
                    $map_LayerAssigned = 'infiniteLinks';
                }
                //links with a cost of less than 1.0 but NOT tunnels or DTD links
                //tunnels are always 1.0 and DTD is always 0.1
                if (($value['cost'] <= 1.000) && ($value['cost'] != 0.1) && !($tunnel))
                {
                    //these will always be a solid green
                    $display_color = $MESH_SETTINGS['Link_GOOD'];
                    $display_opacity = 0.5;
                    $map_LayerAssigned = 'rfLinks';
                }
                //links of greater than 10.000 ETX, but not "INFINITE" (these links are always red)
291
                if ($value['cost'] > 14.000 && $value['cost'] != 99.99)
Eric - kg6wxc's avatar
Eric - kg6wxc committed
292
293
294
295
296
297
298
299
                {
                    $display_color = $MESH_SETTINGS['Link_BAD'];
                    $moreThanTen = 1;
                    $display_opacity = 0.3;
                    $map_LayerAssigned = 'rfLinks';
                }
                //now for the more normal links
                //less than ETX 5.0 links
300
                if ($value['cost'] < 7 && !($dtd) && !($tunnel))
Eric - kg6wxc's avatar
Eric - kg6wxc committed
301
302
303
304
305
                {
                    $display_color = sprintf("#%02XFF00", ($value['cost'] - 1) * (255 / (5 - 1)));
                    $map_LayerAssigned = 'rfLinks';
                }
                //more than ETX 5.0 links
306
                if ($value['cost'] > 7 && !($moreThanTen) && !($infinite))
Eric - kg6wxc's avatar
Eric - kg6wxc committed
307
308
309
310
311
312
313
314
                {
                    $display_color = sprintf("#FF%02X00", ($value['cost'] - 1) * (255 / (5 - 1)) -
                        255);
                    $display_opacity = 0.5;
                    $map_LayerAssigned = 'rfLinks';
                }
                if ($map_LayerAssigned)
                {
315
316
317
                    $linkList .= 'L.polyline([[' . $node_lat . ',' . $node_lon . '],[' . $link_lat .
                        ',' . $link_lon . ']], {color: "' . $display_color . '", opacity: ' . $display_opacity .
                        ', weight: ' . $display_weight . ', offset: ' . $display_offset . '})
318
319
						.bindPopup("<div class=\"linkPopupContent\"><strong>' .  $nodeName . '</strong> to <strong>' . $linkName . '</strong><br><strong>Cost</strong>: ' .
                        $value['cost'] . '</div>")
320
						.addTo(' . $map_LayerAssigned . '),' . "\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341

                }
            }
        }
    }

    return $linkList;
}

/**
 * loadLinkedTO
 * This routine create a HTML formatted text list of link details.
 * The information gathered here is display as part of the node popup detail.
 *
 * @param $node_info
 * @param $TopoList
 *
 * @return string
 */
function load_LinkedTO($node_info, $TopoList)
{
342
    $linkedToList = '';
343
344
345
346
347
    $linkInfoForStationPopups = array($node_info['node'] => array());
    
    //don't init what is going to be an array as a string!!
    //$linkInfoForStationPopups = array($node_info['node'] => "");
    
Eric - kg6wxc's avatar
Eric - kg6wxc committed
348
    $node = $node_info['node'];
349
    
Eric - kg6wxc's avatar
Eric - kg6wxc committed
350
351
352
353
354
355
356
357
358
359
360
361
362
    //and build a big 3D array of it all
    //like  this:
    //array
    //	"NodeName"
    //		"1stLinkedNodesName"
    //			"CostFrom"
    //			"CostTo"
    //			"distance"
    //			"bearing"
    //		"2ndLinkedNodesName"
    //			"CostFrom"
    //			"CostTo"
    //etc..etc..
363
    
Eric - kg6wxc's avatar
Eric - kg6wxc committed
364
365
366
367
368
    if (isset($TopoList))
    {
        foreach ($TopoList as $value)
        {
            //if there's no location info (at each end of the link) ignore the entry
Eric's avatar
Eric committed
369
        	if ((isset($value['nodelat'])) && (isset($value['linklon'])))
Eric - kg6wxc's avatar
Eric - kg6wxc committed
370
            {
371
372
                
                //this is the section that is exploding in php7.2.3
Eric - kg6wxc's avatar
Eric - kg6wxc committed
373
                if ($value['linkto'] == $node)
374
                {              
Eric - kg6wxc's avatar
Eric - kg6wxc committed
375
                    //this will be the cost FROM each linked station back TO the node we are currently looking at in the while loop
376
                    //had to create the array correctly! fixed 3-28-2018 - wxc
377
                    if (isset($linkInfoForStationPopups[$node_info['node']][$value['node']]) && is_array($linkInfoForStationPopups[$node_info['node']][$value['node']])) {
378
                        $linkInfoForStationPopups[$node_info['node']][$value['node']]['costFrom'] = $value['cost'];
379
380
381
                    }else {
                        $linkInfoForStationPopups[$node_info['node']][$value['node']] = array('costFrom' => $value['cost']);
                    }
Eric - kg6wxc's avatar
Eric - kg6wxc committed
382
383
384
                }
                if ($value['node'] == $node)
                {
385
                    //$linkedNodesKeyNameArray = array("costTo", "distance", "bearing");
Eric - kg6wxc's avatar
Eric - kg6wxc committed
386
                    //this will be the cost TO each linked station FROM the node we are currently looking at in the while loop
387
388
                    //distance and bearing added too for goo measure! :)
                    //$linkInfoForStationPopups[$node_info['node']][$value['linkto']] = array_fill_keys($linkedNodesKeyNameArray, "");
389
                    $linkInfoForStationPopups[$node_info['node']][$value['linkto']]['costTo'] = $value['cost'];
Eric - kg6wxc's avatar
Eric - kg6wxc committed
390
                    //add in the distance to that linked node
391
                    $linkInfoForStationPopups[$node_info['node']][$value['linkto']]['distance'] = $value['distance'];
Eric - kg6wxc's avatar
Eric - kg6wxc committed
392
                    //add in the bearing to that linked node
393
                    $linkInfoForStationPopups[$node_info['node']][$value['linkto']]['bearing'] = $value['bearing'];
Eric - kg6wxc's avatar
Eric - kg6wxc committed
394
395
396
397
                }
            }
        }
    }
Eric - kg6wxc's avatar
Eric - kg6wxc committed
398
399
    //now take all that info back out and put into a properly formatted string variable that we'll use later
    //this part of the function reformatted by kg6wxc.
400
401
402
403
    //the "kilometers" setting will default to "0"
    if (!isset($GLOBALS['USER_SETTINGS']['kilometers'])) {
    	$GLOBALS['USER_SETTINGS']['kilometers'] = "0";
    }
Eric - kg6wxc's avatar
Eric - kg6wxc committed
404
405
406
407
408
409
410
411
412
413
414
    foreach ($linkInfoForStationPopups as $nodeNameLinkArray => $linktoArray) {
        if (!empty($linktoArray)) {
            foreach ($linktoArray as $linkedNodeName => $costArray) {
            	if (!empty($costArray)) {
            		if (!empty($costArray['costTo']) && !empty($costArray['costFrom'])) {
		                //if ((isset($costArray['costTo']) == 0.1) && (isset($costArray['costFrom']) == 0.1)) {
            			if ($costArray['costTo'] == "0.1" && $costArray['costFrom'] == "0.1") {
		                    $display_cost = ' <Link_DTD>(DTD)</Link_DTD> ';
		                }else {
		                    $display_cost = ' (' . $costArray['costTo'] . '/' . $costArray['costFrom'] . ') ';
		                }
415
		                if ($GLOBALS['USER_SETTINGS']['kilometers']) {
Eric - kg6wxc's avatar
Eric - kg6wxc committed
416
		                	$linkedToList .= $linkedNodeName . $display_cost . $costArray['distance'] . 'km (' . round($costArray['distance'] * 0.62137, 2) . 'mi) ' . $costArray['bearing'] . '&deg;<br>';
417
		                }else {
Eric - kg6wxc's avatar
Eric - kg6wxc committed
418
		                	$linkedToList .= $linkedNodeName . $display_cost . round($costArray['distance'] * 0.62137, 2) . 'mi (' . $costArray['distance'] . 'km) ' . $costArray['bearing'] . '&deg;<br>';
419
		                }
Eric - kg6wxc's avatar
Eric - kg6wxc committed
420
421
            		}
            	}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
            }
        }
    }

    return $linkedToList;
}


/**
 * buildMarker
 * This routine builds Mesh Markers.
 * These mesh markers are added to various map layer depending upon the type of node
 * The currently defined Mesh Markers are categorized by frequency
 *          2Ghz, 3Ghz, 5Ghz, 900Mhz, Linux systems
 *
 * Mesh Markers are stored in the node_info table, which is updated by the get-map-info.php routine
 *
 * @param $node_info
 * @param $node_ServiceList
 * @param $node_LinkedList
 * @param $node_FirmwareStatus
 *
 * @return string AssignedLayer
 */
function build_Marker($node_info, $node_ServiceList, $node_LinkedList, $node_FirmwareStatus)
{
448
	
Eric - kg6wxc's avatar
Eric - kg6wxc committed
449
	//timezone fixes - wxc 11-27-2018
450
	$nodeLastSeen = new DateTime($node_info['last_seen'], $GLOBALS['localTimeZone']);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
451
	date_timezone_set($nodeLastSeen, $GLOBALS['localTimeZone']);
452
453
454
	
    
	$markerList = '';
455
    $nodeUrl = "<NodeTitle><a href=\"http://" . $node_info['node'] . ".local.mesh:8080\" target=\"node\">" . $node_info['node'] .
Eric - kg6wxc's avatar
Eric - kg6wxc committed
456
457
458
459
460
461
        "</a></NodeTitle>";

    //Now we look at the 'channel' value, for each node, from the node_info database.
    //Then compare it to what we know about each bands channels
    //if we find a match, we assume we're in that band...

462
    if ($node_info['firmware_version'] == 'Linux' || $node_info['firmware_version'] == 'linux')
Eric - kg6wxc's avatar
Eric - kg6wxc committed
463
    { // Linux Devices ( Special for SNOOPY )
464
465
        $icon = 'linuxCircle';
        $band = '<Device_Linux>Linux</Device_Linux>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
466
467
468
469
        $AssignedLayer = 'otherStations';
    }
    else
    {
470
        switch ((wxc_checkBand($node_info['channel'], $node_info['board_id'])))
Eric - kg6wxc's avatar
Eric - kg6wxc committed
471
        {
472
473
474
            case '2GHz': // 2.4GHz devices
                $icon = 'twoRadioCircle';
                $band = '<Device_24GHz>2.4GHz</Device_24GHz>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
475
476
                $AssignedLayer = 'twoGHzStations';
                break;
477
478
479
            case '3GHz': // 3GHz devices
                $icon = 'threeRadioCircle';
                $band = '<Device_3GHz>3.4GHz</Device_3GHz>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
480
481
                $AssignedLayer = 'threeGHzStations';
                break;
482
483
484
            case '5GHz': // 5GHz devices
                $icon = 'fiveRadioCircle';
                $band = '<Device_5GHz>5.8GHz</Device_5GHz>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
485
486
                $AssignedLayer = 'fiveGHzStations';
                break;
487
488
489
            case '900MHz': // Note: Channel values borked for 900Mhz
                $icon = 'nineRadioCircle';
                $band = '<Device_900MHz>900MHz</Device_900MHz>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
490
491
492
                $AssignedLayer = 'nineHundredMHzStations';
                break;
            default: // unknown
493
494
                $icon = 'unknownRadioCircle';
                $band = '<unknown>?</unknown>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
495
496
497
498
499
500
501
502
503
504
505
                $AssignedLayer = 'otherStations';
        }
    }


    /*
    * check for Out of Date Firmware
    */
    switch ($node_FirmwareStatus)
    {
        case 1:
506
            $firmware = '<OutOfDate>Firmware: ' . $node_info['firmware_version'] . '</OutOfDate>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
507
508
            break;
        case 2:
509
510
            $firmware = '<Experimental>Firmware: ' . $node_info['firmware_version'] .
                '</Experimental>';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
511
512
513
514
515
516
517
518
519
            break;
        default:
            $firmware = $node_info['firmware_version'];
    }


    /*
    * Now build the marker
    */
520
    
Eric - kg6wxc's avatar
Eric - kg6wxc committed
521
522
    if ($node_LinkedList)
    {
523
    	$node_LinkedList = '<Strong>Node Name (cost to/from) distance bearing</Strong><br>' . $node_LinkedList;
Eric - kg6wxc's avatar
Eric - kg6wxc committed
524
    }
525
526
527
528
529
530
531
532
533
534
535
536
537
538
    
    //add java variable to hold the "main tab" info
    //*** node names used in these variables must have all dashes converted to underscores!! ***
    //*** they also must be outside of the $markerList, just echo them out for now since it'll just work! ***
    // TODO: remove these echos and do it properly
    echo "<script>\n";
    echo "var popupTabs_" . str_replace("-", "_", $node_info['node']) . " = '<div class=\"popupTabs\"><div class=\"popupTab\" id=\"popupTab-Main\">" .
        "<div class=\"popupTabContent\">" . $nodeUrl . " (" . $band . ")<br>" .
    	$node_info['lat'] . ", " . $node_info['lon'] . "<br>SSID: " . $node_info['ssid'] . "<br>Channel: " . $node_info['channel'] .
    	", Bandwidth: " . $node_info['chanbw'] . "<br>" . $node_info['model'] . "<br>" . $firmware .
    	"<br>Last Polled: ". date_format($nodeLastSeen, 'Y-m-d H:i:s T') . "<br>" . "Uptime: " . $node_info['uptime'] . "<br>";
    	if ($node_info['loadavg'] !== "Not Available") {
    		$loadavgs = unserialize($node_info['loadavg']);
    		//var_dump($loadavgs);
Eric's avatar
Eric committed
539
540
541
542
543
    		if (is_array($loadavgs)) {
    			echo 'LoadAvg: 1 min ' . $loadavgs[0] . ', 5 min ' . $loadavgs[1] . ', 15 min ' . $loadavgs[2] . "<br></div></div>';" . "\n";
    		}else {
    			echo "</div></div>';" . "\n";
    		}
544
545
546
547
548
549
550
551
552
    	}else {
    		echo "</div></div>';" . "\n";
    	}
    
    //add the "services tab" info to the java variable if it is available
    if ($node_ServiceList) {
    	echo "popupTabs_" . str_replace("-", "_", $node_info['node']) .
	   		" += '<div class=\"popupTab\" id=\"popupTab-Services\"><div class=\"popupTabContent\">" .
    		$node_ServiceList . "</div></div>';" . "\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
553
    }
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585

    //add the "links tab" info to the java variable if it is available
    if ($node_LinkedList) {
    	echo "popupTabs_" . str_replace("-", "_", $node_info['node']) .
    		" += '<div class=\"popupTab\" id=\"popupTab-Links\"><div class=\"popupTabContent\">" .
    		$node_LinkedList . "</div></div>';" . "\n";
    }else {
    	echo "popupTabs_" . str_replace("-", "_", $node_info['node']) .
    	" += '<div class=\"popupTab\" id=\"popupTab-Links\"><div class=\"popupTabContent\">" .
    	"This node has no links, it may be powered off, old data, no longer linked to the network or otherwise having problems" .
    	"</div></div>';" . "\n";
    }
    
    //complete the popup div stuff
    echo "popupTabs_" . str_replace("-", "_", $node_info['node']) . " += '<ul class=\"popupTabs-link\">" .
    	"<li class=\"popupTab-link\"><a href=\"#popupTab-Main\"><span>Main</span></a></li>";
    if ($node_ServiceList) {
    	echo "<li class=\"popupTab-link\"><a href=\"#popupTab-Services\"><span>Services</span></a></li>";
    }
    echo "<li class=\"popupTab-link\"><a href=\"#popupTab-Links\"><span>Links</span></a></li></ul></div>';\n";
    
    //*** close the additional <script> tag! ***
    echo "</script>\n";
    
    //*now* create the marker
    $markerList .= "L.marker([" . $node_info['lat'] . "," . $node_info['lon'] . "], {title: '" . $node_info['node'] .
    	"', icon: " . $icon . "}).bindPopup(popupTabs_" . str_replace("-", "_", $node_info['node']) .
    	", { maxWidth: 500 } ).addTo(" . $AssignedLayer . ") ,\n";

    //
    // If Upgrade Suggested add Node to that layer and change the popup
    //
Eric - kg6wxc's avatar
Eric - kg6wxc committed
586
587
588
589
    if ($node_FirmwareStatus > 0)
    {
        $markerList .= "L.marker([" . $node_info['lat'] . "," . $node_info['lon'] . "], {title: '" .
            $node_info['node'] . "', icon: " . (($node_FirmwareStatus == 1) ? "redCircle" :
590
591
592
593
            "orangeCircle") . "}).bindPopup('<div class=\"popupTabs-fw\">" . 
            (($node_FirmwareStatus == 1) ? "**** FIRMWARE UPDATE NEEDED ****" : "**** EXPERIMENTAL FIRMWARE ****") .
            "<div class=\"popupTab\"><div class=\"popupTabContent-fw\"> " .
            $nodeUrl . " (" . $band . ")<br>" . $node_info['model'] .
Eric - kg6wxc's avatar
Eric - kg6wxc committed
594
            "<br>" . $firmware . "<br>" . (($node_FirmwareStatus == 1) ?
595
596
597
598
599
600
601
            "<br><strong>Software upgrade is <em>highly</em> recommended!</strong><br>" .
            "<br>Current Stable AREDN version is: " . $GLOBALS['USER_SETTINGS']['current_stable_fw_version'] . "<br>" .
            "<br>Please visit: <a href=\"http://downloads.arednmesh.org/firmware/html/stable.html\">" .
            "arednmesh.org</a> to find the proper firmware." : "Experimental Firmware<br><br>" .
            "The most recent nightly build can be found at:<br><a href=\"http://downloads.arednmesh.org/snapshots/trunk/\">" .
            "http://downloads.arednmesh.org/snapshots/trunk/</a>") .
        	"</div></div></div>').addTo(upgradeStations) ,\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
602
603
    }

604

Eric - kg6wxc's avatar
Eric - kg6wxc committed
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
    return $markerList;
}

/**
 * buildStationMarker
 * This routine builds Station Markers. Station Markers are auxiliary (non-mesh) details to be displayed on the map.
 * These markers are added to the "Other Stations" layer.
 * The currently defined Station Markers are:
 *          Operator, Police Station, Fire Station, EOC, Hospital, Other
 *
 * Station Markers are stored in the station_info table. Station Markers are manually created.
 *
 * @param $station_info
 *
 * @return string AssignedLayer
 */
function buildStationMarker($Marker)
{

    //Now we look at the 'channel' value, for each node, from the node_info database.
    //Then compare it to what we know about each bands channels
    //if we find a match, we assume we're in that band...

    switch ($Marker['type'])
    {
        case "operator":
            // Operator Home Station
            $icon = "operatorIcon";
            $AssignedLayer = 'operatorsElements';
            break;
        case "police":
            $icon = "policeIcon";
            $AssignedLayer = 'policeElements';
            break;
        case "eoc":
            $icon = "eocIcon";
            $AssignedLayer = 'racesElements';
            break;
        case "firedepartment":
            $icon = "fireIcon";
            $AssignedLayer = 'fireElements';
            break;
        case "hospital":
            $icon = "hospitalIcon";
            $AssignedLayer = 'hospitalElements';
            break;
        default:
            // unknown
            $icon = "Red_Marker";
            $AssignedLayer = 'otherElements';
    }

    /*
    * Now build the marker
    */
    $markerList = "L.marker([" . $Marker['lat'] . "," . $Marker['lon'] . "], {title: '" . $Marker['name'] .
661
662
663
664
        "', icon: " . $icon . "}).bindPopup('<div class=\"popupTabs-nonmesh\">" . $Marker['name'] .
        "<div class=\"popupTab\"><div class=\"popupTabContent-fw\">" .
        $Marker['name'] . "<br>" . $Marker['description'] .
        "<br>" . $Marker['lat'] . ", " . $Marker['lon'] . "<br>TYPE: " . $Marker['type'] . "</div></div></div>').addTo(" . $AssignedLayer . ") ,\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780

    return $markerList;
}


/*
* DATABASE access routines
**********************************************************************************************************************/
/**
 * load the Node data into an array.
 *
 * Where Clause and Orderby are optional
 * @param null $whereClause
 * @param null $orderBy
 *
 * @return array
 */
function load_Nodes($whereClause = null, $orderBy = null)
{
    /*
    * Node Table Query
    */
    global $USER_SETTINGS;
    global $useNodes;
    $NodeList = array();
    if (isset($USER_SETTINGS['sql_db_tbl_node']))
    {
        // Setup the Query ( replace WHERE and ORDER By as needed )
        $query = "SELECT * FROM " . $USER_SETTINGS['sql_db_tbl_node'] . " " .
            ($whereClause ? $whereClause : " WHERE 1=1 ") . " " .
            ($orderBy ? $orderBy : " ORDER BY node");
        // Retrieve the data
        $node_info_db = mysqli_query($GLOBALS['sql_connection'], $query)
        or die('Could not Select Items from Node Table: ' . mysqli_error());
        // Load the data into an array for ease of handling
        while ($node_info = mysqli_fetch_array($node_info_db, MYSQLI_ASSOC))
        {
            $NodeList[] = $node_info;
        }
        $useNodes = true;
    }
    else
    {
        $useNodes = false;
    }
    return $NodeList;
}


/**
 * load the Marker data into an array.
 *
 * Where Clause and Orderby are optional
 * @param null $whereClause
 * @param null $orderBy
 *
 * @return array
 */
function load_Markers($whereClause = null, $orderBy = null)
{
    /*
    * marker Table Query
    */
    global $USER_SETTINGS;
    global $useMarkers;
    $MarkerList = array();
    if (isset($USER_SETTINGS['sql_db_tbl_marker']))
    {
        // Setup the Query ( replace WHERE and ORDER By as needed )
        $query = "SELECT * FROM " . $USER_SETTINGS['sql_db_tbl_marker'] . " " .
            ($whereClause ? $whereClause : " WHERE 1=1 ") . " " .
            ($orderBy ? $orderBy : " ORDER BY name");
        // Retrieve the data
        $marker_info_db = mysqli_query($GLOBALS['sql_connection'], $query)
        or die('Could not Select Items from marker Table: ' . mysqli_error());
        // Load the data into an array for ease of handling
        while ($marker_info = mysqli_fetch_array($marker_info_db, MYSQLI_ASSOC))
        {
            $MarkerList[] = $marker_info;
        }
        $useMarkers = true;
    }
    else
    {
        $useMarkers = false;
    }
    return $MarkerList;
}


/**
 * load the Topology (or Link) Data into an array.
 *
 * Where Clause and Orderby are optional
 * @param null $whereClause
 * @param null $orderBy
 *
 * @return array
 */
function load_Topology($whereClause = null, $orderBy = null)
{
    /*
    * Topology Table Query
    */
    global $USER_SETTINGS;
    global $useLinks;
    $TopoList = array();
    if (isset($USER_SETTINGS['sql_db_tbl_topo']))
    {
        // Setup the Query ( replace WHERE and ORDER By as needed )
        $query = "SELECT * FROM " . $USER_SETTINGS['sql_db_tbl_topo'] . " " .
            ($whereClause ? $whereClause : " WHERE 1=1 ") . " " .
            ($orderBy ? $orderBy : " ORDER BY distance, cost");
        // Retrieve the data
        $topology_info_db = mysqli_query($GLOBALS['sql_connection'], $query)
        or die('Could not Select Items from Topology Table: ' . mysqli_error());
781
        $num = mysqli_num_rows($topology_info_db);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
782
        // Load the data into an array for ease of handling
783
784
        for ($i = 0; $i <= $num; ++$i)
        //while ($topology_info = mysqli_fetch_array($topology_info_db, MYSQLI_ASSOC))
Eric - kg6wxc's avatar
Eric - kg6wxc committed
785
        {
786
787
            $TopoList[] = mysqli_fetch_array($topology_info_db, MYSQLI_ASSOC);
            //$TopoList[] = $topology_info;
Eric - kg6wxc's avatar
Eric - kg6wxc committed
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
        }
        $useLinks = true;
    }
    else
    {
        $useLinks = false;
    }
    return $TopoList;
}

/*
* HTML Page Setup routines
**********************************************************************************************************************/
/**
 * add_MapLayers
 *
 * This routine adds the MapLayers needed
 * the (navigator.online) controls the display for online or offline browsers
806
 * No it doesn't, it doesn't tell you crap really... being on a LAN makes navigator.online true!!! DO NOT USE IT.
Eric - kg6wxc's avatar
Eric - kg6wxc committed
807
808
809
810
811
812
813
814
815
816
 * It has no bearing whatsoever if internet access is available or not
 *
 *
 * @return string - This string will need to be outputed to the browser
 */
function add_MapLayers()
{
if($GLOBALS['mesh']) {
	$offline_map_tiles = $GLOBALS['USER_SETTINGS']['offlineMapTileDir'];
	$Content = <<< EOD
817
            var offlineMapTiles = "$offline_map_tiles";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
818
819
820
821
822
823
824
            var defaultMap = new L.tileLayer(offlineMapTiles);

            var baseLayers = {"Offline Map": defaultMap};

        \n\n
EOD;
}else {
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
    $Content = "\n";
    $baseLayersString = "var baseLayers = {";
    $map_num = 0;
    foreach ($GLOBALS['USER_SETTINGS']['inetTileServer'] as $map_name => $map_url) {
        if(@strpos($map_name, "-Default")) {
            $map_name = preg_replace('/-Default/', '', $map_name);
            $Content .= "var defaultMap = new L.tileLayer('" . $map_url . "');\n";
            $baseLayersString .= "\"" . $map_name . "\": defaultMap,";
        }else {
            $map_num++;
            $Content .= "var map" . $map_num . " = new L.tileLayer('" . $map_url . "');\n";
            $baseLayersString .= "\"" . $map_name . "\": map" . $map_num . ",";
        }
    }
    $baseLayersString .= "};\n";
    $Content .= $baseLayersString;
/*
Eric - kg6wxc's avatar
Eric - kg6wxc committed
842
843
844
845
846
847
848
849
850
851
852
853
854
    $Content = <<< EOD
            var OSMMapURL = '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
            var terrainMapURL = '//stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}.jpg';
            var topoMapURL = '//{s}.tile.opentopomap.org/{z}/{x}/{y}.png';
            
            var OSMmap = new L.tileLayer(OSMMapURL);
            var defaultMap = new L.tileLayer(terrainMapURL);
            var topologyMap = new L.tileLayer(topoMapURL);
            
            var baseLayers = {"Topographic": topologyMap, "Street": OSMmap, "Terrain": defaultMap};

		\n\n
EOD;
855
*/
Eric - kg6wxc's avatar
Eric - kg6wxc committed
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
}
    return $Content;
}


/**
 * @param $numNodes
 * @param $numLinks
 * @param $numMarkers
 *
 * @return string
 */
function add_MapImages($numNodes, $numLinks, $numMarkers)
{
    global $MESH_SETTINGS;
    $Content = "
    // Node and Link Icons
        var greenRadioCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_Default'] . "',
            iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        // Out of Date node software
        var redCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_OOD'] . "',
            iconSize: [22, 22], iconAnchor: [11, 11], popupAnchor: [0, -9]
        });
        // Experiment node software
        var orangeCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_Experimental'] . "',
            iconSize: [22, 22], iconAnchor: [11, 11], popupAnchor: [0, -9]
        });
        // 900 Mhz
        var nineRadioCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_900MHz'] . "',
            iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        //2.4GHz
        var twoRadioCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_24GHz'] . "',
            iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        //3GHz
        var threeRadioCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_3GHz'] . "',
            iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        //5GHz
        var fiveRadioCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_5GHz'] . "',
            iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        //Unknown
        var unknownRadioCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_Unknown'] . "',
            iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        
        //a special one
        var linuxCircle = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Device_Linux'] . "',
            iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });\n";

    if ($numMarkers > 0)
    {
        $Content .= "
        // Marker Icons
        var policeIcon = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Marker_Police'] . "',
            iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        var fireIcon = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Marker_Fire'] . "',
            iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        var operatorIcon = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Marker_Operator'] . "',
            iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        var hospitalIcon = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Marker_Hospital'] . "',
            iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        var eocIcon = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Marker_EOC'] . "',
            iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });
        var Red_Marker = L.icon({
            iconUrl: '" . $MESH_SETTINGS['Marker_Future'] . "',
            iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
        });\n\n";
    }
    return $Content;
}


/**
 * @param $numNodes
 * @param $numLinks
 * @param $numMarkers
 *
 * @return string
 */
function create_MapLayers($numNodes, $numLinks, $numMarkers)
{
    //overlay groups to help superposition order
    $Content = "
    // Node Groups
    var nineHundredMHzStations = new L.LayerGroup();
    var twoGHzStations = new L.LayerGroup();
    var threeGHzStations = new L.LayerGroup();
    var fiveGHzStations = new L.LayerGroup();
    var otherStations = new L.LayerGroup();
    var upgradeStations = new L.LayerGroup();\n
970
971
972
973
974
975
976

	var allStations = L.layerGroup([
		nineHundredMHzStations,
		twoGHzStations,
		threeGHzStations,
		fiveGHzStations,
		otherStations]);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
";

    if ($numLinks > 0)
    {
        $Content .= "
        // Link Groups
        var rfLinks = new L . LayerGroup();
        var tunnelLinks = new L . LayerGroup();
        var dtdLinks = new L . LayerGroup();
        var infiniteLinks = new L . LayerGroup();
        var stations = new L . LayerGroup();
        var linkLines = new L . LayerGroup();
        var legendLayer = new L . layerGroup();\n
";
    }
    if ($numMarkers > 0)
    {
        $Content .= "
        // Marker Groups
        var otherElements = new L . LayerGroup();
        var policeElements = new L . LayerGroup();
        var fireElements = new L . LayerGroup();
        var hospitalElements = new L . LayerGroup();
        var racesElements = new L . LayerGroup();
        var operatorsElements = new L . LayerGroup();
        var otherElements = new L . LayerGroup();
        \n\n
";
    }

    return $Content;
}


/**
 * @param $numNodes
 * @param $numLinks
 * @param $numMarkers
 *
 * @return string
 */
function create_MapOverlays($numNodes, $numLinks, $numMarkers)
{
    global $MESH_SETTINGS;
    $Content = "// Node Overlays
    var groupedOverlays = {
        \"Stations\": {
                \"<img src='" . $MESH_SETTINGS['Device_24GHz'] . "' height='20'>2.4GHz\": twoGHzStations,
                \"<img src='" . $MESH_SETTINGS['Device_3GHz'] . "' height='20'>3.4GHz\": threeGHzStations,
                \"<img src='" . $MESH_SETTINGS['Device_5GHz'] . "' height='20'>5.8GHz\": fiveGHzStations,
                \"<img src='" . $MESH_SETTINGS['Device_900MHz'] . "' height='20'>900MHz\": nineHundredMHzStations,
                \"<img src='" . $MESH_SETTINGS['Device_Linux'] . "' height='20'>Additional Mesh\": otherStations,
                \"<img src='" . $MESH_SETTINGS['Device_OOD'] . "' height='20'>Check Versions\": upgradeStations
        }";

    if ($numLinks > 0)
    {
        $Content .= "
                ,\n
        // Link Overlays
    \"Links\": {
    \"<Link_RF_Only>RF Only</Link_RF_Only>\": rfLinks,
            \"<Link_DTD>DTD</Link_DTD>\": dtdLinks,
            \"<Link_Tunnel>Tunnels</Link_Tunnel>\": tunnelLinks,
            \"<Link_Infinite>Infinite</Link_Infinite>\": infiniteLinks
        }\n";
    }

    if ($numMarkers > 0)
    {
        $Content .= "
        ,\n
        // Marker Layers
        \"Additional\": {
            \"<img src='" . $MESH_SETTINGS['Marker_Police'] . "' height='20'>Police\": policeElements,
            \"<img src='" . $MESH_SETTINGS['Marker_Fire'] . "' height='20'>Fire Dept\": fireElements,
            \"<img src='" . $MESH_SETTINGS['Marker_Hospital'] . "' height='20'>Hospital\": hospitalElements,
            \"<img src='" . $MESH_SETTINGS['Marker_EOC'] . "' height='20'>EOC\": racesElements,
            \"<img src='" . $MESH_SETTINGS['Marker_Operator'] . "' height='20'>Operators\": operatorsElements,
            \"<img src='" . $MESH_SETTINGS['Marker_Future'] . "' height='20'>Future Mesh\": otherElements
        }\n";
    }
    $Content .= "};\n\n";

    return $Content;
}


/**
 * @return string
 */
function create_MapLegend()
{
    //legend overlay
    $Content = <<< EOD
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1072
1073
1074
1075
1076
1077
	var legendHidden = L.control({position: 'topright'});
	legendHidden.onAdd = function(map) {
		var div = L.DomUtil.create('div', 'info legendHidden', L.DomUtil.get('map'));
		div.innerHTML += '<button id="legendLinkButtonHidden" onclick="hideLegend()">Map Legend</button>';
		return div;
	};
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1078
1079
1080
1081
    var legend = L.control({position: 'topright'});
    legend.onAdd = function (map) {
        var div = L.DomUtil.create('div', 'info legend', L.DomUtil.get('map'));
        div.innerHTML +=
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1082
1083
1084
1085
1086
1087
1088
        '<div id="legend">' +
                '<div id="legendGradientRectangle">1.000&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Link Cost&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10.000</div>' +
                '<div id="legendDTDLink">DTD</div>' +
                '<div id="legendOtherWireless">RF DTD</div>' +
                '<div id="legendTunnelLink">Tunnel</div>' +
                '<div id="legendInfinite">Infinite</div>' +
				'<div id="legendUnknownOther">' +
1089
						'<img class="legendBandIcon" src="images/mapMarkers/greyRadioCircle-icon.png">Other' +
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
				'</div>' +
                '<div id="legend900MHz">' +
                        '<img class="legendBandIcon" src="images/mapMarkers/magentaRadioCircle-icon.png">900MHz' +
                '</div>' +
                '<div id="legend2GHz">' +
                        '<img class="legendBandIcon" src="images/mapMarkers/purpleRadioCircle-icon.png">2GHz' +
                '</div>' +
                '<div id="legend3GHz">' +
                        '<img class="legendBandIcon" src="images/mapMarkers/blueRadioCircle-icon.png">3GHz' +
                '</div>' +
                '<div id="legend5GHz">' +
                        '<img class="legendBandIcon" src="images/mapMarkers/goldRadioCircle-icon.png">5GHz' +
                '</div>' +
				'<div id="legendHide"><button id="legendLinkButton" onclick="hideLegend()">Hide</button></div>' +
        '</div>';
//            '<img src="images/mapLegend/LinkCostLegend.jpg" alt="legend" width="175" height="25"><br>' +
//            '<img src="images/mapLegend/DTDLinkLegend.jpg" alt="legend" width="75" height="60" align="right">';
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
        return div;
    };\n\n
EOD;

    return $Content;
}


/**
 * @return string
 */
function create_MapImage()
{
    global $USER_SETTINGS;
    //init the map with size, zoom level, center co-ords, etc...
    //http://leafletjs.com/reference-1.0.3.html#control-zoom
    $Content = "
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
	if (typeof rfLinks === 'undefined' || rfLinks === null) {
		var map = L.map('mapid', {
			//attributionControl: false,
	        center: [" . $USER_SETTINGS['map_center_coordinates'] . "],
	        zoom: [" . $USER_SETTINGS['map_initial_zoom_level'] . "],            
	        minZoom: 0,
			maxZoom: 18,
			//zoomSnap: 0,
			zoomSnap: 1,
			//zoomDelta: 0.25,
			zoomDelta: 1,
	        //layers: [defaultMap, twoGHzStations, threeGHzStations, fiveGHzStations, nineHundredMHzStations, otherStations, rfLinks, tunnelLinks, dtdLinks, infiniteLinks],
	        layers: [defaultMap, twoGHzStations, threeGHzStations, fiveGHzStations, nineHundredMHzStations, otherStations],
			//layers: [defaultMap],
			fullscreenControl: true
    	});\n\n
	}else {
	    var map = L.map('mapid', {
			//attributionControl: false,
	        center: [" . $USER_SETTINGS['map_center_coordinates'] . "],
	        zoom: [" . $USER_SETTINGS['map_initial_zoom_level'] . "],            
	        minZoom: 0,
			maxZoom: 18,
			//zoomSnap: 0,
			zoomSnap: 1,
			//zoomDelta: 0.25,
			zoomDelta: 1,
	        layers: [defaultMap, twoGHzStations, threeGHzStations, fiveGHzStations, nineHundredMHzStations, otherStations, rfLinks, tunnelLinks, dtdLinks, infiniteLinks],
	        //layers: [defaultMap, twoGHzStations, threeGHzStations, fiveGHzStations, nineHundredMHzStations, otherStations],
			//layers: [defaultMap],
			fullscreenControl: true
	    });\n\n
	}
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
";

    return $Content;
}


/**
 * @param $numNodes
 * @param $numLinks
 * @param $numMarkers
 *
 * @return string
 */
function show_MapMarkerDetails($numNodes, $numLinks, $numMarkers, $numNodesTotal, $numLinksTotal)
{
    // Get the last time we updated the link info
    $filetime = wxc_scriptGetLastDateTime("LINKINFO", "topology");
    if ($filetime)
    {
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1176
    	date_timezone_set($filetime, $GLOBALS['localTimeZone']);
1177
        $filetime = date_format($filetime, 'F d Y H:i:s T');
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1178
1179
1180
1181
1182
1183
1184
1185
1186
    }

    //$Content = "MeshMapDetails = '<strong>" . $numNodes . " Nodes shown, with " . $numLinks .
    //    " links " . " &nbsp;&nbsp;&nbsp;Data Last Acquired @ " . $filetime . "</strong>';\n";
    
    $Content = "MeshMapDetails = '<strong><a style=\"color: inherit;text-decoration: none;\" href=\"\" title=\"" .
    	$numNodesTotal . " Total nodes in the database." . '\n' . "Nodes without Location info cannot be shown.\">" .
    	$numNodes . "</a> Nodes shown, with <a style=\"color: inherit;text-decoration: none;\" href=\"\" title=\"" .
    	$numLinksTotal . " Total links in the database." . '\n' . "Nodes without Location info cannot have links shown.\">" . 
1187
    	$numLinks . "</a> links " . "&nbsp;|&nbsp;Data Last Acquired @ " . $filetime . "</strong>';\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1188

1189
1190
1191
1192
1193
    $Content .= "WXCAttribution = '<a href=mailto:kg6wxc@gmail.com title=\'" .
        "MeshMap version 2.5" . '\n\n' .
    	"Map originally created by:" . '\n' .
    	"KG6WXC in Oct 2016" .'\n' .
		"With later contributions from:" . '\n' .
1194
		"N2MH and K6GSE" . '\n' .
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1195
1196
		"Official Testing Guinea Pig:" . '\n' .
		"N7QJK\'>KG6WXC</a>&nbsp;|&nbsp;';\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218

    $Content .= "MapAttribution = '<a href=http://leafletjs.com title=\'" .
        "Map data &copy; by OpenStreetMap (http://openstreetmap.org) with contributions from:" . '\n' .
        "CC-BY-SA (http://creativecommons.org/licenses/by-sa/2.0/" . '\n' .
        "Map tiles (http://maps.stamen.com) by Stamen Design (http://stamen.com), under CC BY 3.0" .
        '\n' . "Map style (http://viewfinderpanoramas.org)" . '\n' . "Icons (www.flaticon.com)" . '\n' .
        "OpenTopoMap (https://opentopomap.org)\'>Leaflet</a>&nbsp;';\n";

    $Content .= "attributionCtrl = map.attributionControl;\n";
    $Content .= "attributionCtrl.setPrefix(WXCAttribution + MapAttribution);\n";
    $Content .= "attributionCtrl.addAttribution(MeshMapDetails);\n";

    return $Content;
}


/**
 * @return string
 */
function instantiate_Map()
{
    $Content = <<< EOD
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
// Create additional Control placeholders
function addControlPlaceholders(map) {
    var corners = map._controlCorners,
        l = 'leaflet-',
        container = map._controlContainer;

    function createCorner(vSide, hSide) {
        var className = l + vSide + ' ' + l + hSide;

        corners[vSide + hSide] = L.DomUtil.create('div', className, container);
    }

    createCorner('verticalcenter', 'left');
    createCorner('verticalcenter', 'right');
}
addControlPlaceholders(map);
map.zoomControl.setPosition('verticalcenterleft');
map.fullscreenControl.setPosition('verticalcenterleft');

Eric - kg6wxc's avatar
Eric - kg6wxc committed
1238
1239
1240
EOD;

    $Content .= <<< EOD
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
//********* "VIEW AS LIST" button ***********
	//view as list (node_report.php)
	L.Control.viewAsList = L.Control.extend({
		options: {
			position: 'verticalcenterleft'
		},
		onAdd: function(map) {

			var viewAsListControl = L.DomUtil.create('div', 'leaflet-control-custom leaflet-bar');
			viewAsListControl.style.backgroundColor = 'white';
			viewAsListControl.style.width = '30px';
			viewAsListControl.style.height = '30px';
			viewAsListControl.title = 'View as list (node report)';
			var link = L.DomUtil.create('a', 'leaflet-bar-part leaflet-bar-part-single', viewAsListControl);
			var listIcon = L.DomUtil.create('div', 'viewAsListControl', link);
			listIcon.style.fontSize = '20px';
			listIcon.style.verticalAlign = 'middle';

			viewAsListControl.onclick = function() {
				window.location = "node_report.php"
			}
			return viewAsListControl;
		}
	});
	L.control.viewAsList = function(opts) {
		return new L.Control.viewAsList(opts);
	}
	L.control.viewAsList().addTo(map);
//*********** END "VIEW AS LIST" button *************

1271
1272
1273
1274
1275
1276
1277
1278
1279

//the search button
L.control.search({
	layer: allStations,
	initial: false,
	zoom: 16,
	position: 'verticalcenterleft',
	hideMarkerOnCollapse: true
}).addTo(map);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304

//the watermark logo
L.Control.Watermark = L.Control.extend({
	onAdd: function(map) {
		var img = L.DomUtil.create('img');
		img.src = 'images/MESHMAP_LOGO.svg';
		img.style.width = '75px';
		//img.className += 'watermark';
		img.style.background = 'rgba(0,0,0,0.5)';
		img.style.border = '1px solid black';
		img.style.borderRadius = '5px';
		img.style.opacity = '0.3';
		img.style.filter = 'alpha(opacity=30)';

		return img;
	},
	OnRemove: function(map) {
		//nothing
	}
});
L.control.watermark = function(opts) {
	return new L.Control.Watermark(opts);
}
L.control.watermark({position: 'bottomright'}).addTo(map);

Eric - kg6wxc's avatar
Eric - kg6wxc committed
1305
1306
1307
1308
1309
1310
    var hash = new L.Hash(map);

    /*
     * MeshMap Legend
     */
    legend.addTo(map);
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1311
	legendHidden.addTo(map);
1312

Eric - kg6wxc's avatar
Eric - kg6wxc committed
1313
1314
1315
1316
    /*
     * Scale Control
     */
    L.control.scale().addTo(map);\n
1317
1318
1319
1320
1321
1322
1323
/*
*The "help" button
*/
var contents = "";

EOD;

Eric - kg6wxc's avatar
Eric - kg6wxc committed
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
    if (!isset($GLOBALS['hide_admin']) == "1") {
    	$Content .= <<< EOD
	//admin icon (the gears)
	L.Control.Admin = L.Control.extend({
		options: {
			position: 'verticalcenterleft'
		},
		onAdd: function(map) {
			var adminControl = L.DomUtil.create('div', 'leaflet-control-custom leaflet-bar');
			adminControl.style.backgroundColor = 'white';
			//adminControl.content = "\F013";
			//adminControl.font-family = "FontAwesome";
			//adminControl.style.background = "fa-cog";
			adminControl.style.width = '30px';
			adminControl.style.height = '30px';
			adminControl.title = 'Admin';
			var link = L.DomUtil.create('a', 'leaflet-bar-part leaflet-bar-part-single', adminControl);
			var gear = L.DomUtil.create('span', 'fa fa-cogs', link);
			gear.style.fontSize = '15px';
			adminControl.onclick = function() {
				//alert('you clicked it');
				window.location = "admin/admin.php";
			}
			return adminControl;
		}
	});
	L.control.admin = function(opts) {
		return new L.Control.Admin(opts);
	}
	/*
	*admin control button
	*/
	L.control.admin().addTo(map);
EOD;
    }
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
    
//    $help_msg = file_get_contents('../webpage/help_msg.html');
//    $Content .= "L.Control.slideMenu(\"" . $help_msg . "\").addTo(map);\n";

    $help_msg_file = fopen("help_msg.html", "r");
    if ($help_msg_file) {
        while (($line = fgets($help_msg_file)) != false) {
            $Content .= "contents += \"" . trim(preg_replace('/\s\s+/', ' ', $line)) . "\";\n";
        }
        fclose($help_msg_file);
    }else {
        $Content .= "alert('Could not open help_msg.html');\n";
    }
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1372
    $Content .= "\nL.control.slideMenu(contents, {width: '400px', position: 'verticalcenterleft'}).addTo(map);\n";
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1373
1374
	/* Attribution */
	//attributionCtrl({position: 'bottomleft'}).addTo(map);\n
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1375
    
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
    //the left side controls go in the order they are added.
    //we want the ruler and the layers control to be the last two on the bottom
    $Content .= <<< EOD
	//the ruler
	var rulerOptions = {position: 'verticalcenterleft',
	lengthUnit: {
		factor: 0.621371,
		display: 'Miles',
		decimal: 3}
	};
    L.control.ruler(rulerOptions).addTo(map);
    document.getElementById('ruler').title = 'Ruler\\n(ESC 1x to stop, 2x to remove)';

    //Grouped Layer Control
    var layerControls = L.control.groupedLayers(baseLayers, groupedOverlays, {position: 'verticalcenterleft'}).addTo(map);
	L.DomEvent.disableClickPropagation(layerControls._container);
	L.DomEvent.disableScrollPropagation(layerControls._container);
EOD;
Eric - kg6wxc's avatar
Eric - kg6wxc committed
1394
1395
1396
1397
1398
1399
    return $Content;
}
?>