source: trunk/src/map/inc/kmlHandler.php

Last change on this file was 7847, checked in by Pieter Naber, 15 years ago

Laatste aanpassingen!

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1<?php
2//$file contains place of the KML file we will be getting our node information from
3function get_node_array($file)
4{
5 //Check if the file exists, if it does we load it. If it doesn't we exit and return an error message
6 try {
7 $xml = simplexml_load_file($file);
8 } catch (Exception $e) {
9 trigger_error(SYSLOG_CRIT, 'Failed to open KML file: ' . $file, __FILE__, __LINE__);
10 }
11
12 //Counter starts at 0. For every foreach done counter will go up by one. Thus resulting in total nodes added(counter starts at 0 so add 1 to the total )
13 $counter = 0;
14
15 //Now we go through the xml files, storing the data in an array called $markers. More data can be stored by adding more rows in the array
16 foreach($xml->Document->Folder->Placemark as $placemark)
17 {
18 /*
19 * Getting all data from the datatags in the KML file.
20 * First we declare variables we will use.
21 * Then we itirate trough all the data and fill the variables
22 */
23 $location = "";
24 $status = "";
25 $interfaces = "";
26 $masterIP = "";
27 $nodeType = "";
28 $type = "";
29 $hostname = "";
30 $hasBeenChecked = "";
31 $checkExecutionTime = "";
32 $currentState = "";
33 $lastCheck = "";
34 $problemHasBeenAcknowledged = "";
35
36 foreach($placemark->ExtendedData->Data as $data)
37 {
38 foreach($data->attributes() as $nameAttribute => $name)
39 {
40 if($name == "location")
41 $location = $data->value;
42
43 if($name == "status")
44 $status = $data->value;
45
46 if($name == "interfaces")
47 $interfaces = $data->value;
48
49 if($name == "masterIP")
50 $masterIP = $data->value;
51
52 if($name == "nodeType")
53 $nodeType = $data->value;
54
55 if($name == "type")
56 $type = $data->value;
57
58 if($name == "hostName")
59 $hostname = $data->value;
60
61 if($name == "hasBeenChecked")
62 $hasBeenChecked = $data->value;
63
64 if($name == "checkExecutionTime")
65 $checkExecutionTime = $data->value;
66
67 if($name == "lastCheck")
68 $lastCheck = $data->value;
69
70 if($name == "currentState")
71 $currentState = $data->value;
72
73 if($name == "problemHasBeenAcknowledged")
74 $problemHasBeenAcknowledged = $data->value;
75 }
76 }
77
78 /*
79 * We now fill up our array with Longitude and Latitude and Name by accessing $placemark
80 * Then we fill the rest of the array with the variables we declared and filled earlier
81 */
82
83 $markers[] = array( "latitude"=>$placemark->LookAt->latitude,
84 "longitude"=>$placemark->LookAt->longitude,
85 "name"=>$placemark->name,
86 "location"=>$location,
87 "status"=>$status,
88 "interfaces"=>$interfaces,
89 "masterIP"=>$masterIP,
90 "nodeType"=>$nodeType,
91 "type"=>$type,
92 "hostname"=>$hostname,
93 "hasBeenChecked"=>$hasBeenChecked,
94 "checkExecutionTime"=>$checkExecutionTime,
95 "currentState"=>$currentState,
96 "lastCheck"=>$lastCheck,
97 "problemHasBeenAcknowledged"=>$problemHasBeenAcknowledged);
98 }
99 return $markers;
100}
Note: See TracBrowser for help on using the repository browser.