Index: trunk/src/inc/KMLFile.class.php
===================================================================
--- trunk/src/inc/KMLFile.class.php	(revision 7768)
+++ trunk/src/inc/KMLFile.class.php	(revision 7773)
@@ -76,5 +76,6 @@
 	private $KMLNodes;
 	private $KMLLines;
-	
+	private $NetworkList;
+
 	/*
 	 * Function: __construct (constructor)
@@ -86,4 +87,5 @@
 		$this->KMLNodes = array();
 		$this->KMLLines = array();
+		$this->NetworkList = new NetworkList();
 	}
 
@@ -119,4 +121,5 @@
 		$toString = $this->template;
 
+		// Add all nodes to the string
 		$nodeString = '';
 		$nodeCount = count($this->KMLNodes);
@@ -125,8 +128,13 @@
 		}
 
+		// Add all connected lines to the string
 		$lineString = '';
 		$lineCount = count($this->KMLLines);
 		for ($i = 0; $i < $lineCount; $i++) {
-			$lineString .= $this->KMLLines[$i]->toString();
+			// If longitude2 and latitude2 aren't set, ignore the lines
+			// This happens with all the connections that don't connect 2 nodes
+			if ($this->KMLLines[$i]->isConnected()) {
+				$lineString .= $this->KMLLines[$i]->toString();
+			}
 		}
 
@@ -137,26 +145,6 @@
 		$toString = str_replace('%NODESCONTENT%', $nodeString, $toString);
 		$toString = str_replace('%LINESCONTENT%', $lineString, $toString);
-		
+
 		return $toString;
-	}
-
-	/*
-	 * Function: write
-	 * Description: Write KMLFile to a KML file
-	 * Parameters: string $filename
-	 * Returns: true if we can write to the file, otherwise false
-	 */
-	public function write($filename) {
-		// TODO: David: Needs to be placed in FileHandler.class.php. Here we just want to call our file handler.
-
-		trigger_log(SYSLOG_DEBUG, 'Opening the file "' . $filename . '"', __FILE__, __LINE__);
-		$file = new FileHandler($filename, 'w')
-			or trigger_log(SYSLOG_ERR, 'Opening the file "' . $filename . '"', __FILE__, __LINE__);
-
-		trigger_log(SYSLOG_DEBUG, 'Writing file "' . $filename . '"', __FILE__, __LINE__);
-		$file->write($file,$this->toString());
-
-		trigger_log(SYSLOG_DEBUG, 'Closing file "' . $filename . '"', __FILE__, __LINE__);
-		fclose($file);
 	}
 
@@ -185,43 +173,44 @@
 	 */
 	public function parseLocationFile($file) {
+		// We want to find all the nodes in the location file and store information of the nodes...
 		$nodesCount = preg_match_all('/\[[a-zA-Z0-9]*\]/i', $file, $nodes, PREG_OFFSET_CAPTURE);
 		for ($i = 0; $i < $nodesCount; $i++) {
 			// Looking for "location" of the node
-			if (!$location = $this->findInLocationFile($file, 'location', $nodes[0][$i][1])) {
+			if (!$location = $this->findInLocationFile($file, 'location = ', $nodes[0][$i][1])) {
 				trigger_log(SYSLOG_WARNING, 'Could not find the "location" of node "' . $i . '", skipping to next', __FILE__, __LINE__);
 				continue;
 			}
 			// Looking for "status" of the node
-			if (!$status = $this->findInLocationFile($file, 'status', $nodes[0][$i][1])) {
+			if (!$status = $this->findInLocationFile($file, 'status = ', $nodes[0][$i][1])) {
 				trigger_log(SYSLOG_WARNING, 'Could not find the "status" of node "' . $i . '", skipping to next', __FILE__, __LINE__);
 				continue;
 			}
 			// Looking for "latitude" of the node
-			if (!$latitude = $this->findInLocationFile($file, 'latitude', $nodes[0][$i][1])) {
+			if (!$latitude = $this->findInLocationFile($file, 'latitude = ', $nodes[0][$i][1])) {
 				trigger_log(SYSLOG_WARNING, 'Could not find the "latitude" of node "' . $i . '", skipping to next', __FILE__, __LINE__);
 				continue;
 			}
 			// Looking for "longitude" of the node
-			if (!$longitude = $this->findInLocationFile($file, 'longitude', $nodes[0][$i][1])) {
+			if (!$longitude = $this->findInLocationFile($file, 'longitude = ', $nodes[0][$i][1])) {
 				trigger_log(SYSLOG_WARNING, 'Could not find the "longitude" of node "' . $i . '", skipping to next', __FILE__, __LINE__);
 				continue;
 			}
 			// Looking for "interfaces" of the node
-			if (!$interfaces = $this->findInLocationFile($file, 'interfaces', $nodes[0][$i][1])) {
+			if (!$interfaces = $this->findInLocationFile($file, 'interfaces = ', $nodes[0][$i][1])) {
 				trigger_log(SYSLOG_WARNING, 'Could not find the "interfaces" of node "' . $i . '", skipping to next', __FILE__, __LINE__);
 				continue;
 			}
 			// Looking for "masterip" of the node
-			if (!$masterip = $this->findInLocationFile($file, 'masterip', $nodes[0][$i][1])) {
+			if (!$masterip = $this->findInLocationFile($file, 'masterip = ', $nodes[0][$i][1])) {
 				trigger_log(SYSLOG_WARNING, 'Could not find the "masterip" of node "' . $i . '", skipping to next', __FILE__, __LINE__);
 				continue;
 			}
 			// Looking for "nodetype" of the node
-			if (!$nodetype = $this->findInLocationFile($file, 'nodetype', $nodes[0][$i][1])) {
+			if (!$nodetype = $this->findInLocationFile($file, 'nodetype = ', $nodes[0][$i][1])) {
 				trigger_log(SYSLOG_WARNING, 'Could not find the "nodetype" of node "' . $i . '", skipping to next', __FILE__, __LINE__);
 				continue;
 			}
 			// Looking for "name" of the node
-			if (!$name = $this->findInLocationFile($file, 'name', $nodes[0][$i][1])) {
+			if (!$name = $this->findInLocationFile($file, 'name = ', $nodes[0][$i][1])) {
 				trigger_log(SYSLOG_WARNING, 'Could not find the "name" of node "' . $i . '", skipping to next', __FILE__, __LINE__);
 				continue;
@@ -246,4 +235,37 @@
 				$this->addNode($placemark);
 			}
+
+			// Now let's find all interlinks with this node
+			$position = $nodes[0][$i][1];
+			while (($position = strpos($file, 'ip=', $position + 1)) && (isset($nodes[0][$i + 1][1]) && $position < $nodes[0][$i + 1][1])) {
+				$ipAddress = $this->findInLocationFile($file, 'ip=', $position);
+				$posSlash = strpos($ipAddress, '/');
+				$ip = substr($ipAddress, 0, $posSlash);
+				$netmask = substr($ipAddress, $posSlash + 1);
+
+				$posNetwork = $this->NetworkList->find($ip);
+				if ($posNetwork) {
+					// Network already excists in list, just need to add longitude2 en latitude2 to KMLLine
+					// and add the node name to the name of the line.
+					// Position in network equals position in KMLLine array :-)
+
+					$this->KMLLines[$posNetwork]->setName($this->KMLLines[$posNetwork]->getName() . $name);
+					$this->KMLLines[$posNetwork]->setLongitude2($longitude);
+					$this->KMLLines[$posNetwork]->setLatitude2($latitude);
+				} else {
+					// Network doesn't excist. We create a new network and a new line.
+
+					$network = new Network($ip, $netmask);
+					$this->NetworkList->add($network);
+
+					$line = new KMLLine();
+					$line->setID($network->networkDecimal);
+					$line->setName('Link: Van ' . $name . ' naar ');
+					$line->setDescription($network->toString());
+					$line->setLongitude1($longitude);
+					$line->setLatitude1($latitude);
+					$this->KMLLines[] = $line;
+				}
+			}
 		}
 	}
@@ -256,5 +278,5 @@
 	 */
 	private function findInLocationFile($file, $keyword, $offset) {
-		$start	= strpos($file, $keyword, $offset) + strlen($keyword . ' = ');
+		$start	= strpos($file, $keyword, $offset) + strlen($keyword);
 		$end	= strpos($file, "\n", $start);
 
Index: trunk/src/inc/KMLLine.class.php
===================================================================
--- trunk/src/inc/KMLLine.class.php	(revision 7768)
+++ trunk/src/inc/KMLLine.class.php	(revision 7773)
@@ -19,6 +19,6 @@
 			</description>
 			<LookAt>
-				<longitude>%LONGITUDE%</longitude>
-				<latitude>%LATITUDE%</latitude>
+				<longitude>%LONGITUDE1%</longitude>
+				<latitude>%LATITUDE1%</latitude>
 				<altitude>0</altitude>
 				<heading>0</heading>
@@ -29,6 +29,6 @@
 			<LineString>
 				<coordinates>
-					%X1%, %Y1%, 0. 
-					%X2%, %Y2%, 0.
+					%LONGITUDE1%, %LATITUDE1%, 0. 
+					%LONGITUDE2%, %LATITUDE2%, 0.
 				</coordinates>
 			</LineString>
@@ -38,11 +38,9 @@
 	private $name;					// Name of the line
 	private $description;			// Description of the line
-	private $longitude;				// Longitude of the line
-	private $latitude;				// Latitude of the line
 	private $style;					// Style of the line
-	private $x1;					// Start X of line
-	private $y1;					// Start Y of line
-	private $x2;					// End X of line
-	private $y2;					// End Y of line
+	private $longitude1;			// Start longitude of line
+	private $latitude1;				// Start latitude of line
+	private $longitude2;			// End longitude of line
+	private $latitude2;				// End latitude of line
 
 	/*
@@ -59,8 +57,8 @@
 		$this->latitude = 0;
 		$this->style = LINE_BLACK;
-		$this->x1 = 0;
-		$this->y1 = 0;
-		$this->x2 = 0;
-		$this->y2 = 0;
+		$this->longitude1 = 0;
+		$this->latitude1 = 0;
+		$this->longitude2 = 0;
+		$this->latitude2 = 0;
 	}
 
@@ -106,24 +104,4 @@
 
 	/*
-	 * Function: setLongitude
-	 * Description: Setting the longitude of the placemark
-	 * Parameters: double $newLongitude
-	 * Returns: -
-	 */
-	function setLongitude($newLongitude) {
-		$this->longitude = (double) $newLongitude;
-	}
-
-	/*
-	 * Function: setLatitude
-	 * Description: Setting the latitude of the placemark
-	 * Parameters: double $newLatitude
-	 * Returns: -
-	 */
-	function setLatitude($newLatitude) {
-		$this->latitude = (double) $newLatitude;
-	}
-
-	/*
 	 * Function: setStyle
 	 * Description: Setting the style of the placemark
@@ -136,41 +114,56 @@
 
 	/*
-	 * Function: setX1
-	 * Description: Setting the X1 of the placemark
-	 * Parameters: double $newX1
+	 * Function: setLongitude1
+	 * Description: Setting the longitude1 of the placemark
+	 * Parameters: double $newLongitude
 	 * Returns: -
 	 */
-	function setX1($newX1) {
-		$this->x1 = (double) $newX1;
+	function setLongitude1($newLongitude) {
+		$this->longitude1 = (double) $newLongitude;
+	}
+
+	/*
+	 * Function: setLatitude1
+	 * Description: Setting the latitude1 of the placemark
+	 * Parameters: double $newLatitude
+	 * Returns: -
+	 */
+	function setLatitude1($newLatitude) {
+		$this->latitude1 = (double) $newLatitude;
 	}
 	
 	/*
-	 * Function: setY1
-	 * Description: Setting the Y1 of the placemark
-	 * Parameters: double $newY1
+	 * Function: setLongitude2
+	 * Description: Setting the longitude2 of the placemark
+	 * Parameters: double $newLongitude
 	 * Returns: -
 	 */
-	function setY1($newY1) {
-		$this->y1 = (double) $newY1;
+	function setLongitude2($newLongitude) {
+		$this->longitude2 = (double) $newLongitude;
 	}
-	
+
 	/*
-	 * Function: setX2
-	 * Description: Setting the X2 of the placemark
-	 * Parameters: double $newX2
+	 * Function: setLatitude2
+	 * Description: Setting the latitude2 of the placemark
+	 * Parameters: double $newLatitude
 	 * Returns: -
 	 */
-	function setX2($newX2) {
-		$this->x2 = (double) $newX2;
+	function setLatitude2($newLatitude) {
+		$this->latitude2 = (double) $newLatitude;
 	}
-	
+
 	/*
-	 * Function: setY2
-	 * Description: Setting the Y2 of the placemark
-	 * Parameters: double $newY2
-	 * Returns: -
+	 * Function: isConnected
+	 * Description: Check if it is really a line or just a dot
+	 * Parameters: -
+	 * Returns: true if the line is connected, otherwise false
 	 */
-	function setY2($newY2) {
-		$this->y2 = (double) $newY2;
+	function isConnected() {
+		if (($this->latitude2 == 0) || ($this->longitude2 == 0)) {
+			return false;
+		}
+
+		// This is a line!
+		return true; 
 	}
 
@@ -187,11 +180,9 @@
 		$toString = str_replace('%NAME%', $this->name, $toString);
 		$toString = str_replace('%DESCRIPTION%', $this->description, $toString);
-		$toString = str_replace('%LONGITUDE%', $this->longitude, $toString);
-		$toString = str_replace('%LATITUDE%', $this->latitude, $toString);
 		$toString = str_replace('%STYLE%', $this->style, $toString);
-		$toString = str_replace('%X1%', $this->x1, $toString);
-		$toString = str_replace('%Y1%', $this->y1, $toString);
-		$toString = str_replace('%X2%', $this->x2, $toString);
-		$toString = str_replace('%Y2%', $this->y2, $toString);
+		$toString = str_replace('%LONGITUDE1%', $this->longitude1, $toString);
+		$toString = str_replace('%LATITUDE1%', $this->latitude1, $toString);
+		$toString = str_replace('%LONGITUDE2%', $this->longitude2, $toString);
+		$toString = str_replace('%LATITUDE2%', $this->latitude2, $toString);
 
 		return $toString;
Index: trunk/src/inc/LogHandler.class.php
===================================================================
--- trunk/src/inc/LogHandler.class.php	(revision 7768)
+++ trunk/src/inc/LogHandler.class.php	(revision 7773)
@@ -36,4 +36,6 @@
 
 class LogHandler {
+	private $logString;		// For caching purposes
+
 	/*
 	 * Function: __construct (constructor)
@@ -42,4 +44,5 @@
 	 */
 	public function __construct() {
+		$logString = '';
 	}
 
@@ -82,9 +85,8 @@
 		}
 
-		$time = date( "H:i.s m/d/y" );
-		$errorString .= ' (' . $logno .' | '.$time .' | ): ' . $logstr . "\r\n\t" . 'In file "' . $logfile . '" on line "' . $logline . '"' . "\r\n";
+		$errorString .= ' (' . $logno . ' | ' . date('Y/d/m H:i:s') . '): ' . $logstr . "\r\n\t" . 'In file "' . $logfile . '" on line "' . $logline . '"' . "\r\n";
 
 		if ($logno <= LOG_LEVEL_ECHO) {
-			echo '<!-- ' . $errorString . ' -->';
+			$this->logString .= $errorString;
 		}
 		if ((!defined('IGNORE_LOG_LEVEL_WRITE')) && ($logno <= LOG_LEVEL_WRITE)) {
@@ -118,4 +120,8 @@
 		}
 	}
+
+	function __destruct() {
+		echo '<!-- ' . $this->logString . ' -->';
+	}
 }
 
Index: trunk/src/inc/Network.class.php
===================================================================
--- trunk/src/inc/Network.class.php	(revision 7768)
+++ trunk/src/inc/Network.class.php	(revision 7773)
@@ -146,4 +146,21 @@
 		return $check;
 	}
+
+	/*
+	 * Function: toString
+	 * Description: Converts the data of the network to a string
+	 * Parameters: -
+	 * Returns: string with all data
+	 */
+	function toString() {
+		return '
+			Netmask: ' . $this->netmaskDecimal . ' / ' . $this->netmaskBinary . '<br/>
+			Wildcard: ' . $this->wildcardDecimal . ' / ' . $this->wildcardBinary . '<br/>
+			Network: ' . $this->networkDecimal . ' / ' . $this->networkBinary . '<br/>
+			Broadcast: ' . $this->broadcastDecimal . ' / ' . $this->broadcastBinary . '<br/>
+			HostMin: ' . $this->hostminDecimal . ' / ' . $this->hostminBinary . '<br/>
+			HostMax: ' . $this->hostmaxDecimal . ' / ' . $this->hostmaxBinary . '<br/>
+			Hosts/Net: ' . $this->numberHosts . '<br/>';
+	}
 }
 ?>
Index: trunk/src/inc/NetworkList.class.php
===================================================================
--- trunk/src/inc/NetworkList.class.php	(revision 7773)
+++ trunk/src/inc/NetworkList.class.php	(revision 7773)
@@ -0,0 +1,65 @@
+<?php
+/*
+ * Project: NodeMap2.0
+ * File: NetworkList.class.php
+ * Purpose: Contains a list of Network objects
+ */
+
+class NetworkList {
+	private $networks;		// Array of Network objects
+
+	/*
+	 * Function: __construct (constructor)
+	 * Description: Creating a new NetworkList object
+	 * Parameters: -
+	 * Returns: -
+	 */
+	public function __construct() {
+		// Create an empty network array
+		$this->networks = array();
+	}
+
+	/*
+	 * Function: add
+	 * Description: Adds a network to our list
+	 * Parameters: Network $newNetwork
+	 * Returns: -
+	 */
+	function add(Network $newNetwork) {
+		// Add Network $newNetwork to the array
+		$this->networks[] = $newNetwork;
+	}
+
+	/*
+	 * Function: get
+	 * Description: Gets the network on a specific number
+	 * Parameters: int $i
+	 * Returns: Network if $i is in the range of the array, otherwise false
+	 */
+	function get($i) {
+		if (($i >= 0) && ($i < count($this->networks))) {
+			return $this->networks[$i];
+		} else {
+			return false;
+		}
+	}
+
+	/*
+	 * Function: find
+	 * Description: Find the position of a network using a IP within the range of network
+	 * Parameters: string $ip
+	 * Returns: Position of the network if found, otherwise false
+	 */
+	function find($ipAddress) {
+		$networkCount = count($this->networks);
+		for ($i = 0; $i < $networkCount; $i++) {
+			if ($this->networks[$i]->inNetwork($ipAddress)) {
+				return $i;
+			}
+		}
+
+		// Not found
+		return false;
+	}
+}
+?>
