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

Last change on this file since 7815 was 7815, checked in by janveeden, 15 years ago
  • Property svn:eol-style set to native
File size: 2.8 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 if (file_exists($file))
7 {
8 $xml = simplexml_load_file($file);
9 }
10 else
11 {
12 exit('Failed to open'.$file);
13 }
14
15 //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 )
16 $counter = 0;
17
18 //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
19 foreach($xml->Document->Folder->Placemark as $placemark)
20 {
21 /*
22 * Getting all data from the datatags in the KML file.
23 * First we declare variables we will use.
24 * Then we itirate trough all the data and fill the variables
25 */
26 $location = "";
27 $status = "";
28 $interfaces = "";
29 $masterIP = "";
30 $nodeType = "";
31 $type = "";
32 $hostname = "";
33 $hasBeenChecked = "";
34 $checkExecutionTime = "";
35 $currentState = "";
36 $lastCheck = "";
37 $problemHasBeenAcknowledged = "";
38
39 foreach($placemark->ExtendedData->Data as $data)
40 {
41 foreach($data->attributes() as $nameAttribute => $name)
42 {
43 if($name == "location")
44 $location = $data->value;
45
46 if($name == "status")
47 $status = $data->value;
48
49 if($name == "interfaces")
50 $interfaces = $data->value;
51
52 if($name == "masterIP")
53 $masterIP = $data->value;
54
55 if($name == "nodeType")
56 $nodeType = $data->value;
57
58 if($name == "type")
59 $type = $data->value;
60
61 if($name == "hostname")
62 $hostname = $data->value;
63
64 if($name == "hasBeenChecked")
65 $hasBeenChecked = $data->value;
66
67 if($name == "checkExecutionTime")
68 $checkExecutionTime = $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.