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
RevLine 
[7725]1<?php
[7769]2//$file contains place of the KML file we will be getting our node information from
3function get_node_array($file)
[7725]4{
[7767]5 //Check if the file exists, if it does we load it. If it doesn't we exit and return an error message
[7842]6 try {
[7847]7 $xml = simplexml_load_file($file);
[7842]8 } catch (Exception $e) {
9 trigger_error(SYSLOG_CRIT, 'Failed to open KML file: ' . $file, __FILE__, __LINE__);
[7767]10 }
[7725]11
[7767]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 {
[7784]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 */
[7785]23 $location = "";
24 $status = "";
25 $interfaces = "";
26 $masterIP = "";
27 $nodeType = "";
28 $type = "";
29 $hostname = "";
30 $hasBeenChecked = "";
31 $checkExecutionTime = "";
32 $currentState = "";
33 $lastCheck = "";
34 $problemHasBeenAcknowledged = "";
[7767]35
[7784]36 foreach($placemark->ExtendedData->Data as $data)
37 {
38 foreach($data->attributes() as $nameAttribute => $name)
39 {
40 if($name == "location")
41 $location = $data->value;
[7785]42
43 if($name == "status")
[7784]44 $status = $data->value;
[7785]45
46 if($name == "interfaces")
[7784]47 $interfaces = $data->value;
[7785]48
49 if($name == "masterIP")
[7784]50 $masterIP = $data->value;
[7785]51
52 if($name == "nodeType")
[7784]53 $nodeType = $data->value;
[7785]54
55 if($name == "type")
[7784]56 $type = $data->value;
[7785]57
[7827]58 if($name == "hostName")
[7784]59 $hostname = $data->value;
[7785]60
61 if($name == "hasBeenChecked")
[7784]62 $hasBeenChecked = $data->value;
[7785]63
64 if($name == "checkExecutionTime")
[7784]65 $checkExecutionTime = $data->value;
[7785]66
[7827]67 if($name == "lastCheck")
68 $lastCheck = $data->value;
69
[7785]70 if($name == "currentState")
[7784]71 $currentState = $data->value;
[7785]72
73 if($name == "problemHasBeenAcknowledged")
[7784]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
[7769]83 $markers[] = array( "latitude"=>$placemark->LookAt->latitude,
[7767]84 "longitude"=>$placemark->LookAt->longitude,
85 "name"=>$placemark->name,
[7784]86 "location"=>$location,
[7785]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);
[7767]98 }
99 return $markers;
[7722]100}
Note: See TracBrowser for help on using the repository browser.