1 | <?php
|
---|
2 |
|
---|
3 | include_once(dirname(__FILE__).'/MapAPI.php');
|
---|
4 |
|
---|
5 | class PageNetworkMap extends Page
|
---|
6 | {
|
---|
7 | function __construct(System $System)
|
---|
8 | {
|
---|
9 | parent::__construct($System);
|
---|
10 | $this->Title = 'Mapa sítě';
|
---|
11 | $this->ParentClass = 'PagePortal';
|
---|
12 | }
|
---|
13 | //var $Load = 'initialize()';
|
---|
14 | //var $Unload = 'GUnload()';
|
---|
15 |
|
---|
16 | function Show(): string
|
---|
17 | {
|
---|
18 | if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('Map', 'Show'))
|
---|
19 | return 'Nemáte oprávnění';
|
---|
20 |
|
---|
21 | if (count($this->System->PathItems) > 1)
|
---|
22 | {
|
---|
23 | if ($this->System->PathItems[1] == 'show-position') return $this->ShowPosition();
|
---|
24 | else return PAGE_NOT_FOUND;
|
---|
25 | } else return $this->ShowMain();
|
---|
26 | }
|
---|
27 |
|
---|
28 | function ShowPosition(): string
|
---|
29 | {
|
---|
30 | $DbResult = $this->Database->select('MapPosition', '*', '`Id`='.$_GET['i']);
|
---|
31 | if ($DbResult->num_rows > 0)
|
---|
32 | {
|
---|
33 | $DbRow = $DbResult->fetch_assoc();
|
---|
34 | $Pos = explode(';', $DbRow['Pos']);
|
---|
35 | $MapApi = new MapOpenStreetMaps($this->System);
|
---|
36 | $MapApi->Position = array('Lat' => $Pos[0], 'Lng' => $Pos[1]);
|
---|
37 | $MapApi->Zoom = 18;
|
---|
38 | $MapApi->Key = $this->System->Config['Map']['GoogleMapsApiKey'];
|
---|
39 | $MapApi->ShowMarker = true;
|
---|
40 | $Marker = new MapMarker();
|
---|
41 | $Marker->Text = $DbRow['Name'];
|
---|
42 | $Marker->Position = $MapApi->Position;
|
---|
43 | $MapApi->Markers[] = $Marker;
|
---|
44 | $Output = $MapApi->ShowPage($this);
|
---|
45 | return $Output;
|
---|
46 | } else return 'Položka nenalezena';
|
---|
47 | }
|
---|
48 |
|
---|
49 | function ShowMain(): string
|
---|
50 | {
|
---|
51 | $Map = new MapOpenStreetMaps($this->System);
|
---|
52 | $Map->Position = array('Lat' => $this->System->Config['Map']['DefaultLatitude'],
|
---|
53 | 'Lng' => $this->System->Config['Map']['DefaultLongitude']);
|
---|
54 | $Map->Zoom = $this->System->Config['Map']['DefaultZoom'];
|
---|
55 | $Map->Key = $this->System->Config['Map']['GoogleMapsApiKey'];
|
---|
56 | //$Map->OnClickObject = $_GET['r'];
|
---|
57 | //$MapApi->ShowMarker = true;
|
---|
58 |
|
---|
59 | $DbResult = $this->Database->query('SELECT GROUP_CONCAT(`NetworkDevice`.`Name` SEPARATOR ",") AS `Name`, '.
|
---|
60 | '`MapPosition`.`Pos` AS `Pos`, `MapPosition`.`Name` AS `NodeName` '.
|
---|
61 | 'FROM `NetworkDevice` LEFT JOIN `MapPosition` ON `MapPosition`.`Id` = `NetworkDevice`.`MapPosition` '.
|
---|
62 | 'WHERE (`NetworkDevice`.`Used`=1) AND (`NetworkDevice`.`MapPosition` IS NOT NULL) '.
|
---|
63 | 'GROUP BY `NetworkDevice`.`MapPosition`');
|
---|
64 | while ($Device = $DbResult->fetch_assoc())
|
---|
65 | {
|
---|
66 | $Pos = explode(';', $Device['Pos']);
|
---|
67 | $Marker = new MapMarker();
|
---|
68 | $Marker->Position = array('Lat' => $Pos[0], 'Lng' => $Pos[1]);
|
---|
69 | $Marker->Text = $Device['NodeName'].': '.$Device['Name'];
|
---|
70 | $Map->Markers[] = $Marker;
|
---|
71 | }
|
---|
72 |
|
---|
73 | $DbResult = $this->Database->query('SELECT * FROM `NetworkLink` WHERE (`Interface1` <> 0) AND (`Interface2` <> 0)');
|
---|
74 | while ($Link = $DbResult->fetch_assoc())
|
---|
75 | {
|
---|
76 | $DbResult2 = $this->Database->query('SELECT `NetworkDevice`.`Used`, `MapPosition`.`Pos` FROM `NetworkDevice` '.
|
---|
77 | 'JOIN `MapPosition` ON `MapPosition`.`Id` = `NetworkDevice`.`MapPosition` '.
|
---|
78 | 'WHERE `NetworkDevice`.`Id` = (SELECT `NetworkInterface`.`Device` FROM `NetworkInterface` WHERE `NetworkInterface`.`Id` = '.$Link['Interface1'].')');
|
---|
79 | $DbResult3 = $this->Database->query('SELECT `NetworkDevice`.`Used`, `MapPosition`.`Pos` FROM `NetworkDevice` '.
|
---|
80 | 'JOIN `MapPosition` ON `MapPosition`.`Id` = `NetworkDevice`.`MapPosition` '.
|
---|
81 | 'WHERE `NetworkDevice`.`Id` = (SELECT `NetworkInterface`.`Device` FROM `NetworkInterface` WHERE `NetworkInterface`.`Id` = '.$Link['Interface2'].')');
|
---|
82 | if (($DbResult2->num_rows > 0) and ($DbResult3->num_rows > 0))
|
---|
83 | {
|
---|
84 | $Device1 = $DbResult2->fetch_assoc();
|
---|
85 | $Pos1 = explode(';', $Device1['Pos']);
|
---|
86 | $Device2 = $DbResult3->fetch_assoc();
|
---|
87 | $Pos2 = explode(';', $Device2['Pos']);
|
---|
88 | if (($Device1['Used'] == 1) and ($Device2['Used'] == 1))
|
---|
89 | {
|
---|
90 | $PolyLine = new MapPolyLine();
|
---|
91 | $PolyLine->Color = '#4F4FBF';
|
---|
92 | $PolyLine->Points[] = array('Lat' => $Pos1[0], 'Lng' => $Pos1[1]);
|
---|
93 | $PolyLine->Points[] = array('Lat' => $Pos2[0], 'Lng' => $Pos2[1]);
|
---|
94 | $Map->PolyLines[] = $PolyLine;
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | $Output = $Map->ShowPage($this);
|
---|
100 |
|
---|
101 |
|
---|
102 | /*
|
---|
103 | $Output = '<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?key='.
|
---|
104 | $this->System->Config['Map']['GoogleMapsApiKey'].'"></script>';
|
---|
105 | $Output .= '<script type="text/javascript">
|
---|
106 |
|
---|
107 | var map;
|
---|
108 | var tinyIcon;
|
---|
109 |
|
---|
110 | function initialize()
|
---|
111 | {
|
---|
112 |
|
---|
113 | //if (google.maps.BrowserIsCompatible())
|
---|
114 | {
|
---|
115 | map = new google.maps.Map(document.getElementById("map_canvas"));
|
---|
116 | map.setMapTypeId(\'satellite\');
|
---|
117 | map.setCenter(new google.maps.LatLng(49.260422, 18.081179), 15);
|
---|
118 | //map.setUIToDefault();
|
---|
119 | //map.addControl(new google.maps.OverviewMapControl(new google.maps.Size(128, 96)));
|
---|
120 |
|
---|
121 |
|
---|
122 | // Create our "tiny" marker icon
|
---|
123 | //var tinyIcon = new google.maps.Icon();
|
---|
124 | //tinyIcon.image = "point.gif";
|
---|
125 | //tinyIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
|
---|
126 | //tinyIcon.iconSize = new google.maps.Size(10, 10);
|
---|
127 | //tinyIcon.shadowSize = new google.maps.Size(10, 10);
|
---|
128 | //tinyIcon.iconAnchor = new google.maps.Point(5, 5);
|
---|
129 | //tinyIcon.infoWindowAnchor = new google.maps.Point(5, 1);
|
---|
130 |
|
---|
131 | toggleLabel(\'NetworkLinks\');
|
---|
132 | toggleLabel(\'NetworkDevices\');';
|
---|
133 |
|
---|
134 | $Output .= '
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | function toggleLabel(id)
|
---|
139 | {
|
---|
140 | var ele = document.getElementById(id);
|
---|
141 | ele.checked = !ele.checked;
|
---|
142 | ele.onclick( );
|
---|
143 | }
|
---|
144 |
|
---|
145 | function UpdateNetworkLinks()
|
---|
146 | {
|
---|
147 | if ((document.getElementById("NetworkLinks")).checked == true)
|
---|
148 | {
|
---|
149 | NetworkLinks = [';
|
---|
150 | $DbResult = $this->Database->query('SELECT * FROM `NetworkLink` WHERE (`Interface1` <> 0) AND (`Interface2` <> 0)');
|
---|
151 | while ($Link = $DbResult->fetch_assoc())
|
---|
152 | {
|
---|
153 | $DbResult2 = $this->Database->query('SELECT `NetworkDevice`.`Used`, `MapPosition`.`Pos` FROM `NetworkDevice` '.
|
---|
154 | 'JOIN `MapPosition` ON `MapPosition`.`Id` = `NetworkDevice`.`MapPosition` '.
|
---|
155 | 'WHERE `NetworkDevice`.`Id` = (SELECT `NetworkInterface`.`Device` FROM `NetworkInterface` WHERE `NetworkInterface`.`Id` = '.$Link['Interface1'].')');
|
---|
156 | $DbResult3 = $this->Database->query('SELECT `NetworkDevice`.`Used`, `MapPosition`.`Pos` FROM `NetworkDevice` '.
|
---|
157 | 'JOIN `MapPosition` ON `MapPosition`.`Id` = `NetworkDevice`.`MapPosition` '.
|
---|
158 | 'WHERE `NetworkDevice`.`Id` = (SELECT `NetworkInterface`.`Device` FROM `NetworkInterface` WHERE `NetworkInterface`.`Id` = '.$Link['Interface2'].')');
|
---|
159 | if (($DbResult2->num_rows > 0) and ($DbResult3->num_rows > 0))
|
---|
160 | {
|
---|
161 | $Device1 = $DbResult2->fetch_assoc();
|
---|
162 | $Pos1 = explode(';', $Device1['Pos']);
|
---|
163 | $Device2 = $DbResult3->fetch_assoc();
|
---|
164 | $Pos2 = explode(';', $Device2['Pos']);
|
---|
165 | if (($Device1['Used'] == 1) and ($Device2['Used'] == 1))
|
---|
166 | $Output .= 'new google.maps.Polyline([new google.maps.LatLng('.$Pos1[0].', '.
|
---|
167 | $Pos1[1].'),new google.maps.LatLng('.$Pos2[0].', '.$Pos2[1].')], "#4F4FBF", 3, 0.8), ';
|
---|
168 | }
|
---|
169 | }
|
---|
170 | $Output .= '];
|
---|
171 | for (var i in NetworkLinks)
|
---|
172 | {
|
---|
173 | map.addOverlay(NetworkLinks[i]);
|
---|
174 | }
|
---|
175 |
|
---|
176 | } else { //checkbox turned off
|
---|
177 | for (var i in NetworkLinks)
|
---|
178 | {
|
---|
179 | map.removeOverlay(NetworkLinks[i]);
|
---|
180 | NetworkLinks[i] = null;
|
---|
181 | }
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 | function toggleLabel(id)
|
---|
186 | {
|
---|
187 | var ele = document.getElementById(id);
|
---|
188 | ele.checked = !ele.checked;
|
---|
189 | ele.onclick( );
|
---|
190 | }
|
---|
191 |
|
---|
192 | function UpdateNetworkDevices()
|
---|
193 | {
|
---|
194 | if ((document.getElementById("NetworkDevices")).checked == true)
|
---|
195 | {
|
---|
196 | NetworkDevices = [';
|
---|
197 |
|
---|
198 | $DbResult = $this->Database->query('SELECT GROUP_CONCAT(`NetworkDevice`.`Name` SEPARATOR ",") AS `Name`, '.
|
---|
199 | '`MapPosition`.`Pos` AS `Pos`, `MapPosition`.`Name` AS `NodeName` '.
|
---|
200 | 'FROM `NetworkDevice` LEFT JOIN `MapPosition` ON `MapPosition`.`Id` = `NetworkDevice`.`MapPosition` '.
|
---|
201 | 'WHERE (`NetworkDevice`.`Used`=1) AND (`NetworkDevice`.`MapPosition` IS NOT NULL) '.
|
---|
202 | 'GROUP BY `NetworkDevice`.`MapPosition`');
|
---|
203 | while ($Device = $DbResult->fetch_assoc())
|
---|
204 | {
|
---|
205 | $Pos = explode(';', $Device['Pos']);
|
---|
206 | $Output .= 'new google.maps.Marker(new google.maps.LatLng('.$Pos[0].', '.
|
---|
207 | $Pos[1].'), {title: "'.$Device['NodeName'].': '.$Device['Name'].'", icon:\'point.gif\' }), ';
|
---|
208 | }
|
---|
209 | $Output .= '];
|
---|
210 | for (var i in NetworkDevices)
|
---|
211 | {
|
---|
212 | map.addOverlay(NetworkDevices[i]);
|
---|
213 | }
|
---|
214 |
|
---|
215 | } else { //checkbox turned off
|
---|
216 | for (var i in NetworkDevices)
|
---|
217 | {
|
---|
218 | map.removeOverlay(NetworkDevices[i]);
|
---|
219 | NetworkDevices[i] = null;
|
---|
220 | }
|
---|
221 | }
|
---|
222 | }
|
---|
223 |
|
---|
224 | </script>';
|
---|
225 | $Output .= '<table style="margin-left: auto; margin-right: auto; width: 100%; height: 80%;">
|
---|
226 | <tr>
|
---|
227 | <td style="width: 80%; height: 100%;">
|
---|
228 | <div id="map_canvas" style="width: 100%; height: 100%;"></div></td>
|
---|
229 | <td style="width: 20%">
|
---|
230 | <form>
|
---|
231 | <input type="checkbox" id="NetworkLinks" onClick="UpdateNetworkLinks();">
|
---|
232 | <a href="" onClick="toggleLabel(\'NetworkLinks\');return false;">Ukázat spoje</a>
|
---|
233 | </input><br />
|
---|
234 | <input type="checkbox" id="NetworkDevices" onClick="UpdateNetworkDevices();">
|
---|
235 | <a href="" onClick="toggleLabel(\'NetworkDevices\');return false;">Ukázat zařízení</a>
|
---|
236 | </input>
|
---|
237 | </form></td>
|
---|
238 | </tr>
|
---|
239 | </table>';
|
---|
240 | */
|
---|
241 | return $Output;
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | class TypeMapPosition extends TypeString
|
---|
246 | {
|
---|
247 | function OnEdit(array $Item): string
|
---|
248 | {
|
---|
249 | $Output = parent::OnEdit($Item);
|
---|
250 | if ($this->FormManager->ShowRelation)
|
---|
251 | $Output .= '<img src="'.$this->FormManager->Root.'/images/select.png" alf="Vybrat" language="javascript" '.
|
---|
252 | 'onclick="return popupwindow("'.$this->FormManager->Root.'/is/?a=mapselect&r='.
|
---|
253 | $Item['Name'].'","test");" style="cursor:hand;cursor:pointer"/>';
|
---|
254 | return $Output;
|
---|
255 | }
|
---|
256 | }
|
---|
257 |
|
---|
258 | class ModuleMap extends Module
|
---|
259 | {
|
---|
260 | function __construct(System $System)
|
---|
261 | {
|
---|
262 | parent::__construct($System);
|
---|
263 | $this->Name = 'Map';
|
---|
264 | $this->Version = '1.0';
|
---|
265 | $this->Creator = 'Chronos';
|
---|
266 | $this->License = 'GNU/GPLv3';
|
---|
267 | $this->Description = 'Show objects on Google maps';
|
---|
268 | $this->Dependencies = array(ModuleNetwork::GetName(), ModuleUser::GetName());
|
---|
269 | $this->Models = array(MapPosition::GetClassName());
|
---|
270 | }
|
---|
271 |
|
---|
272 | function DoStart(): void
|
---|
273 | {
|
---|
274 | $this->System->Pages['map'] = 'PageNetworkMap';
|
---|
275 | $this->System->FormManager->Type->RegisterType('MapPosition', 'String', array());
|
---|
276 | $this->System->FormManager->RegisterClass('MapPosition', array(
|
---|
277 | 'Title' => 'Pozice na mapě',
|
---|
278 | 'Table' => 'MapPosition',
|
---|
279 | 'Items' => array(
|
---|
280 | 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
|
---|
281 | 'Pos' => array('Type' => 'MapPosition', 'Caption' => 'Poloha', 'Default' => '0;0'),
|
---|
282 | 'Subjects' => array('Type' => 'TSubjectListMapPosition', 'Caption' => 'Subjekty', 'Default' => ''),
|
---|
283 | 'NetworkDevices' => array('Type' => 'TNetworkDeviceListMapPosition', 'Caption' => 'Síťová zařízení', 'Default' => ''),
|
---|
284 | ),
|
---|
285 | 'ItemActions' => array(
|
---|
286 | array('Caption' => 'Ukázat na mapě', 'URL' => '/map/show-position?i=#RowId'),
|
---|
287 | ),
|
---|
288 | 'Actions' => array(
|
---|
289 | array('Caption' => 'Ukázat mapu', 'URL' => '/map/'),
|
---|
290 | ),
|
---|
291 | ));
|
---|
292 | $this->System->FormManager->RegisterFormType('TMapPosition', array(
|
---|
293 | 'Type' => 'Reference',
|
---|
294 | 'Table' => 'MapPosition',
|
---|
295 | 'Id' => 'Id',
|
---|
296 | 'Name' => 'Name',
|
---|
297 | 'Filter' => '1',
|
---|
298 | ));
|
---|
299 | $this->System->FormManager->RegisterFormType('TSubjectListMapPosition', array(
|
---|
300 | 'Type' => 'ManyToOne',
|
---|
301 | 'Table' => 'Subject',
|
---|
302 | 'Id' => 'Id',
|
---|
303 | 'Ref' => 'MapPosition',
|
---|
304 | 'Filter' => '1',
|
---|
305 | ));
|
---|
306 | $this->System->FormManager->RegisterFormType('TNetworkDeviceListMapPosition', array(
|
---|
307 | 'Type' => 'ManyToOne',
|
---|
308 | 'Table' => 'NetworkDevice',
|
---|
309 | 'Id' => 'Id',
|
---|
310 | 'Ref' => 'MapPosition',
|
---|
311 | 'Filter' => '1',
|
---|
312 | ));
|
---|
313 | }
|
---|
314 | }
|
---|
315 |
|
---|
316 | class MapPosition extends Model
|
---|
317 | {
|
---|
318 | static function GetModelDesc(): ModelDesc
|
---|
319 | {
|
---|
320 | $Desc = new ModelDesc(self::GetClassName());
|
---|
321 | $Desc->AddString('Name');
|
---|
322 | $Desc->AddString('Pos');
|
---|
323 | return $Desc;
|
---|
324 | }
|
---|
325 | }
|
---|