mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Settings page for Worldmap widget
This commit is contained in:
@@ -23,19 +23,72 @@
|
||||
*/
|
||||
|
||||
if ($config['map']['engine'] == 'leaflet') {
|
||||
|
||||
$temp_output = '
|
||||
if ((defined('show_settings') || empty($widget_settings)) && $config['front_page'] == "pages/front/tiles.php") {
|
||||
$temp_output = '
|
||||
<form class="form" onsubmit="widget_settings(this); return false;">
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4">
|
||||
<label for="init_lat" class="control-label">Initial Latitude: </label>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<input class="form-control" name="init_lat" id="input_lat_'.$unique_id.'" value="'.$widget_settings['init_lat'].'" placeholder="ie. 51.4800 for Greenwich">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4">
|
||||
<label for="init_lng" class="control-label">Initial Longitude: </label>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<input class="form-control" name="init_lng" id="input_lng_'.$unique_id.'" value="'.$widget_settings['init_lng'].'" placeholder="ie. 0 for Greenwich">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4">
|
||||
<label for="init_zoom" class="control-label">Initial Zoom: </label>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<select class="form-control" name="init_zoom" id="select_zoom'.$unique_id.'">
|
||||
';
|
||||
for ($i=0; $i<19; $i++) {
|
||||
if ($i == $widget_settings['init_zoom']) {
|
||||
$temp_output .= '<option selected value="'.$i.'">'.$i.'</option>';
|
||||
}
|
||||
else {
|
||||
$temp_output .= '<option value="'.$i.'">'.$i.'</option>';
|
||||
}
|
||||
}
|
||||
$temp_output .= '
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-2">
|
||||
<button type="submit" class="btn btn-default">Set</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
';
|
||||
}
|
||||
else {
|
||||
$temp_output = '
|
||||
<script src="js/leaflet.js"></script>
|
||||
<script src="js/leaflet.markercluster-src.js"></script>
|
||||
<script src="js/leaflet.awesome-markers.min.js"></script>
|
||||
<div id="leaflet-map"></div>
|
||||
<script>
|
||||
';
|
||||
|
||||
$map_init = "[" . $config['leaflet']['default_lat'] . ", " . $config['leaflet']['default_lng'] . "], " . sprintf("%01.0f", $config['leaflet']['default_zoom']);
|
||||
|
||||
$temp_output .= 'var map = L.map(\'leaflet-map\').setView('.$map_init.');
|
||||
|
||||
';
|
||||
if (!empty($widget_settings)) {
|
||||
$init_lat = $widget_settings['init_lat'];
|
||||
$init_lng = $widget_settings['init_lng'];
|
||||
$init_zoom = $widget_settings['init_zoom'];
|
||||
}
|
||||
elseif (isset($config['leaflet'])) {
|
||||
$init_lat = $config['leaflet']['default_lat'];
|
||||
$init_lng = $config['leaflet']['default_lng'];
|
||||
$init_zoom = $config['leaflet']['default_zoom'];
|
||||
}
|
||||
$map_init = "[" . $init_lat . ", " . $init_lng . "], " . sprintf("%01.0f", $init_zoom);
|
||||
$temp_output .= 'var map = L.map(\'leaflet-map\').setView('.$map_init.');
|
||||
L.tileLayer(\'//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png\', {
|
||||
attribution: \'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors\'
|
||||
}).addTo(map);
|
||||
@@ -49,39 +102,36 @@ var greenMarker = L.AwesomeMarkers.icon({
|
||||
icon: \'server\',
|
||||
markerColor: \'green\', prefix: \'fa\', iconColor: \'white\'
|
||||
});
|
||||
';
|
||||
|
||||
// Checking user permissions
|
||||
if (is_admin() || is_read()) {
|
||||
// Admin or global read-only - show all devices
|
||||
$sql = "SELECT `device_id`,`hostname`,`os`,`status`,`lat`,`lng` FROM `devices`
|
||||
LEFT JOIN `locations` ON `devices`.`location`=`locations`.`location`
|
||||
WHERE `disabled`=0 AND `ignore`=0 AND `lat` != '' AND `lng` != ''
|
||||
ORDER BY `status` ASC, `hostname`";
|
||||
}
|
||||
else {
|
||||
// Normal user - grab devices that user has permissions to
|
||||
$sql = "SELECT `devices`.`device_id` as `device_id`,`hostname`,`os`,`status`,`lat`,`lng`
|
||||
FROM `devices_perms`, `devices`
|
||||
LEFT JOIN `locations` ON `devices`.`location`=`locations`.`location`
|
||||
WHERE `disabled`=0 AND `ignore`=0 AND `lat` != '' AND `lng` != ''
|
||||
AND `devices`.`device_id` = `devices_perms`.`device_id`
|
||||
AND `devices_perms`.`user_id` = ?
|
||||
ORDER BY `status` ASC, `hostname`";
|
||||
}
|
||||
foreach (dbFetchRows($sql, array($_SESSION['user_id'])) as $map_devices) {
|
||||
$icon = 'greenMarker';
|
||||
if ($map_devices['status'] == 0) {
|
||||
$icon = 'redMarker';
|
||||
}
|
||||
|
||||
$temp_output .= "var title = '<a href=\"" . generate_device_url($map_devices) . "\"><img src=\"".getImageSrc($map_devices)."\" width=\"32\" height=\"32\" alt=\"\">".$map_devices['hostname']."</a>';
|
||||
var marker = L.marker(new L.LatLng(".$map_devices['lat'].", ".$map_devices['lng']."), {title: title, icon: $icon});
|
||||
marker.bindPopup(title);
|
||||
markers.addLayer(marker);\n";
|
||||
}
|
||||
|
||||
$temp_output .= 'map.addLayer(markers);
|
||||
';
|
||||
// Checking user permissions
|
||||
if (is_admin() || is_read()) {
|
||||
// Admin or global read-only - show all devices
|
||||
$sql = "SELECT `device_id`,`hostname`,`os`,`status`,`lat`,`lng` FROM `devices`
|
||||
LEFT JOIN `locations` ON `devices`.`location`=`locations`.`location`
|
||||
WHERE `disabled`=0 AND `ignore`=0 AND `lat` != '' AND `lng` != ''
|
||||
ORDER BY `status` ASC, `hostname`";
|
||||
}
|
||||
else {
|
||||
// Normal user - grab devices that user has permissions to
|
||||
$sql = "SELECT `devices`.`device_id` as `device_id`,`hostname`,`os`,`status`,`lat`,`lng`
|
||||
FROM `devices_perms`, `devices`
|
||||
LEFT JOIN `locations` ON `devices`.`location`=`locations`.`location`
|
||||
WHERE `disabled`=0 AND `ignore`=0 AND `lat` != '' AND `lng` != ''
|
||||
AND `devices`.`device_id` = `devices_perms`.`device_id`
|
||||
AND `devices_perms`.`user_id` = ?
|
||||
ORDER BY `status` ASC, `hostname`";
|
||||
}
|
||||
foreach (dbFetchRows($sql, array($_SESSION['user_id'])) as $map_devices) {
|
||||
$icon = 'greenMarker';
|
||||
if ($map_devices['status'] == 0) {
|
||||
$icon = 'redMarker';
|
||||
}
|
||||
$temp_output .= "var title = '<a href=\"" . generate_device_url($map_devices) . "\"><img src=\"".getImageSrc($map_devices)."\" width=\"32\" height=\"32\" alt=\"\">".$map_devices['hostname']."</a>';
|
||||
var marker = L.marker(new L.LatLng(".$map_devices['lat'].", ".$map_devices['lng']."), {title: title, icon: $icon});
|
||||
marker.bindPopup(title);
|
||||
markers.addLayer(marker);\n";
|
||||
}
|
||||
$temp_output .= 'map.addLayer(markers);
|
||||
map.scrollWheelZoom.disable();
|
||||
$(document).ready(function(){
|
||||
$("#leaflet-map").on("click", function(event) {
|
||||
@@ -92,8 +142,9 @@ $(document).ready(function(){
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
} else {
|
||||
}
|
||||
}
|
||||
else {
|
||||
$temp_output = 'Mapael engine not supported here';
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user