[Mapbender-commits] r3510 - in trunk/mapbender/http: classes javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Feb 3 05:36:02 EST 2009


Author: christoph
Date: 2009-02-03 05:36:01 -0500 (Tue, 03 Feb 2009)
New Revision: 3510

Added:
   trunk/mapbender/http/classes/class_gml.php
   trunk/mapbender/http/classes/class_gml_2.php
   trunk/mapbender/http/classes/class_gml_2_factory.php
   trunk/mapbender/http/classes/class_gml_3.php
   trunk/mapbender/http/classes/class_gml_3_factory.php
   trunk/mapbender/http/classes/class_gml_envelope.php
   trunk/mapbender/http/classes/class_gml_factory.php
   trunk/mapbender/http/classes/class_gml_feature.php
   trunk/mapbender/http/classes/class_gml_feature_collection.php
   trunk/mapbender/http/classes/class_gml_line.php
   trunk/mapbender/http/classes/class_gml_multiline.php
   trunk/mapbender/http/classes/class_gml_multipolygon.php
   trunk/mapbender/http/classes/class_gml_point.php
   trunk/mapbender/http/classes/class_gml_polygon.php
   trunk/mapbender/http/classes/class_ows.php
   trunk/mapbender/http/classes/class_ows_factory.php
   trunk/mapbender/http/classes/class_universal_wfs_factory.php
   trunk/mapbender/http/classes/class_wfsToDb.php
   trunk/mapbender/http/classes/class_wfs_1_0.php
   trunk/mapbender/http/classes/class_wfs_1_0_factory.php
   trunk/mapbender/http/classes/class_wfs_1_1.php
   trunk/mapbender/http/classes/class_wfs_1_1_factory.php
   trunk/mapbender/http/classes/class_wfs_deprecated.php
   trunk/mapbender/http/classes/class_wfs_factory.php
   trunk/mapbender/http/classes/class_wfs_featuretype.php
Modified:
   trunk/mapbender/http/classes/class_gui.php
   trunk/mapbender/http/classes/class_mb_exception.php
   trunk/mapbender/http/classes/class_wfs.php
   trunk/mapbender/http/classes/class_wfs_conf.php
   trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php
   trunk/mapbender/http/javascripts/mod_wfs_gazetteer_client.php
   trunk/mapbender/http/php/mod_loadwfs.php
   trunk/mapbender/http/php/mod_wfs_gazetteer_server.php
   trunk/mapbender/http/php/mod_wfs_result.php
   trunk/mapbender/http/php/mod_wfs_server.php
Log:
WFS redesign

Added: trunk/mapbender/http/classes/class_gml.php
===================================================================
--- trunk/mapbender/http/classes/class_gml.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_gml.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,38 @@
+<?php
+# $Id: class_gml2.php 3099 2008-10-02 15:29:23Z nimix $
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_feature_collection.php");
+
+class Gml {
+	var $featureCollection = null;
+	var $geomFeaturetypeElement;
+	var $doc;
+	
+	public function toGeoJSON () {
+		if ($this->featureCollection === null) {
+			return null;
+		}
+		return $this->featureCollection->toGeoJSON();
+	}	
+}
+
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_gml_2.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_2.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_gml_2.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,27 @@
+<?php
+# $Id: class_gml2.php 3099 2008-10-02 15:29:23Z nimix $
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_gml.php");
+
+class Gml_2 extends Gml {
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_gml_2_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_2_factory.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_gml_2_factory.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,348 @@
+<?php
+# $Id: class_wfs.php 3094 2008-10-01 13:52:35Z christoph $
+# http://www.mapbender.org/index.php/class_wfs.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_factory.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_2.php");
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+
+/**
+ * Creates GML 2 objects from a GML documents.
+ * 
+ * @return Gml_2
+ */
+class Gml_2_Factory extends GmlFactory {
+
+	function findNameSpace($s){
+		list($ns,$FeaturePropertyName) = split(":",$s);
+		$nodeName = array('ns' => $ns, 'value' => $FeaturePropertyName);
+		return $nodeName;
+	}
+
+	private function parsePoint ($domNode, $gmlPoint) {
+		$currentSibling = $domNode->firstChild;
+		while ($currentSibling) {
+			list($x, $y, $z) = explode(",", $currentSibling->nodeValue);
+			$gmlPoint->setPoint($x, $y);
+			$currentSibling = $currentSibling->nextSibling;
+		}
+	}
+
+	private function parseLine ($domNode, $gmlLine) {
+		$currentSibling = $domNode->firstChild;
+		while ($currentSibling) {
+			
+			foreach(explode(' ',$currentSibling->nodeValue) as $cords){
+				list($x,$y,$z) = explode(',',$cords);
+				$gmlLine->addPoint($x, $y);
+			}
+			$currentSibling = $currentSibling->nextSibling;
+		}
+	}
+
+	public function parsePolygon ($domNode, $gmlPolygon) {
+		$simpleXMLNode = simplexml_import_dom($domNode);
+
+		$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+		
+		$allCoords = $simpleXMLNode->xpath("gml:outerBoundaryIs/gml:LinearRing/gml:coordinates");
+			
+		$cnt=0;
+		foreach ($allCoords as $Coords) {
+			$coordsDom = dom_import_simplexml($Coords);
+				
+//			$name = $coordsDom->nodeName;
+//			$value = $coordsDom->nodeValue;				
+//			echo "===> name: ".$name. ", Value: ".$value."<br>";
+			
+			foreach(explode(' ',$coordsDom->nodeValue) as $pointCoords){
+
+				list($x,$y,$z) = explode(',',$pointCoords);
+				$gmlPolygon->addPoint($x, $y);
+				}
+			
+			$cnt++;
+		}
+		
+		$innerRingNodeArray = $simpleXMLNode->xpath("gml:innerBoundaryIs/gml:LinearRing");
+		if ($innerRingNodeArray) {
+			$ringCount = 0;
+			foreach ($innerRingNodeArray as $ringNode) {
+				$coordinates = $ringNode->xpath("gml:coordinates");
+				foreach ($coordinates as $coordinate) {
+					$coordsDom = dom_import_simplexml($coordinate);
+						
+					foreach(explode(' ',$coordsDom->nodeValue) as $pointCoords){
+		
+						list($x,$y,$z) = explode(',',$pointCoords);
+						$gmlPolygon->addPointToRing($ringCount, $x, $y);
+					}
+				}
+				$ringCount++;
+			}
+		}
+	}
+
+	public function parseMultiLine ($domNode, $gmlMultiLine) {
+		$simpleXMLNode = simplexml_import_dom($domNode);
+
+		$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+		
+		$allCoords = $simpleXMLNode->xpath("gml:lineStringMember/gml:LineString/gml:coordinates");
+			
+		$cnt=0;
+		foreach ($allCoords as $Coords) {
+			
+			$gmlMultiLine->lineArray[$cnt] = array();
+			
+			$coordsDom = dom_import_simplexml($Coords);
+				
+//			$name = $coordsDom->nodeName;
+//			$value = $coordsDom->nodeValue;				
+//			echo "===> name: ".$name. ", Value: ".$value."<br>";
+			
+			foreach(explode(' ',$coordsDom->nodeValue) as $pointCoords){
+				list($x,$y,$z) = explode(',',$pointCoords);
+				$gmlMultiLine->addPoint($x, $y, $cnt);
+				}
+			
+			$cnt++;
+		}
+	}		
+	
+	public function parseMultiPolygon ($domNode, $gmlMultiPolygon) {
+//		echo $domNode->nodeName."<br>";
+		$simpleXMLNode = simplexml_import_dom($domNode);
+
+		$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+
+		$allPolygons = $simpleXMLNode->xpath("gml:polygonMember/gml:Polygon");
+		
+		$cnt=0;
+		foreach ($allPolygons as $polygon) {
+			$allCoords = $polygon->xpath("gml:outerBoundaryIs/gml:LinearRing/gml:coordinates");
+				
+			$gmlMultiPolygon->polygonArray[$cnt] = array();
+			foreach ($allCoords as $Coords) {
+				
+				$coordsDom = dom_import_simplexml($Coords);
+					
+				foreach (explode(' ',$coordsDom->nodeValue) as $pointCoords) {
+					list($x,$y,$z) = explode(',',$pointCoords);
+					$gmlMultiPolygon->addPoint($x, $y, $cnt);
+				}
+			}
+			
+			$gmlMultiPolygon->innerRingArray[$cnt] = array();
+			$innerRingNodeArray = $polygon->xpath("gml:innerBoundaryIs");
+			if ($innerRingNodeArray) {
+				$ringCount = 0;
+				foreach ($innerRingNodeArray as $ringNode) {
+					$currentRingNode = $ringNode->xpath("gml:LinearRing");
+					foreach ($currentRingNode as $node) {
+						$coordinates = $node->xpath("gml:coordinates");
+						foreach ($coordinates as $coordinate) {
+							$coordsDom = dom_import_simplexml($coordinate);
+								
+							foreach(explode(' ',$coordsDom->nodeValue) as $pointCoords){
+				
+								list($x,$y,$z) = explode(',',$pointCoords);
+								$gmlMultiPolygon->addPointToRing($cnt, $ringCount, $x, $y);
+							}
+						}
+						$ringCount++;
+						
+					}
+				}
+			}
+			$cnt++;
+//			new mb_exception("create multipolygon " . serialize($gmlMultiPolygon->innerRingArray));
+		}		
+	}
+	
+	/**
+	 * Parses the feature segment of a GML and stores the geometry in the
+	 * $geometry variable of the class.
+	 * 	
+	 * Example of a feature segment of a GML. 
+	 * 	<gml:featureMember>
+	 * 		<ms:ROUTE fid="ROUTE.228168">
+	 * 			<gml:boundedBy>
+	 * 				<gml:Box srsName="EPSG:31466">
+	 * 					<gml:coordinates>2557381.0,5562371.1 2557653.7,5562526.0</gml:coordinates>
+	 * 				</gml:Box>
+	 * 			</gml:boundedBy>
+	 * 			<ms:geometry>
+	 * 				<gml:LineString>
+	 * 					<gml:coordinates>
+	 * 						2557380.97,5562526 2557390.96,
+	 * 						5562523.22 2557404.03,5562518.2 2557422.31,
+	 * 						5562512 2557437.16,5562508.37 2557441.79,
+	 * 						5562507.49 2557454.31,5562505.1 2557464.27,
+	 * 						5562503.97 2557473.24,5562502.97 2557491.67,
+	 * 						5562502.12 2557505.65,5562502.43 2557513.78,
+	 * 						5562501.12 2557520.89,5562498.79 2557528.5,
+	 * 						5562495.07 2557538.9,5562488.91 2557549.5,
+	 * 						5562483.83 2557558.55,5562476.61 2557569.07,
+	 * 						5562469.82 2557576.61,5562462.72 2557582.75,
+	 * 						5562457.92 2557588.57,5562452.56 2557590.38,
+	 * 						5562449.69 2557593.57,5562445.07 2557596.17,
+	 * 						5562441.31 2557601.71,5562433.93 2557612.97,
+	 * 						5562421.03 2557626,5562405.33 2557639.66,
+	 * 						5562389.75 2557653.69,5562371.12 
+	 * 					</gml:coordinates>
+	 * 				</gml:LineString>
+	 * 			</ms:geometry>
+	 * 			<code>354</code>
+	 * 			<Verkehr>0</Verkehr>
+	 * 			<rlp>t</rlp>
+	 * 		</ms:ROUTE>
+	 * 	</gml:featureMember>
+	 * 
+	 * @return void
+	 * @param $domNode DOMNodeObject the feature tag of the GML 
+	 * 								(<gml:featureMember> in the above example)
+	 */
+	private function parseFeature($domNode, $feature) {
+		if (func_num_args() == 3) {
+			$feature->geomFeaturetypeElement = func_get_arg(2);
+		}
+
+		$currentSibling = $domNode->firstChild;
+
+		//
+		// There had been a bug with whitespaces in the XML document.
+		// These whitespace had been interpreted as text nodes
+		//
+		if ($currentSibling instanceof DOMText) {
+			return;
+		}
+		
+		$feature->fid = $currentSibling->getAttribute("fid");
+		
+		$currentSibling = $currentSibling->firstChild;
+		
+		while ($currentSibling) {
+		
+			$name = $currentSibling->nodeName;
+			$value = $currentSibling->nodeValue;
+			
+			$namespace = $this->findNameSpace($name);
+			$ns = $namespace['ns'];
+			$columnName = $namespace['value'];
+			$isGeomColumn = ($feature->geomFeaturetypeElement == null || $columnName == $feature->geomFeaturetypeElement);
+			
+			// check if this node is a geometry node.
+			// however, even if it is a property node, 
+			// it has a child node, the text node!
+			// So we might need to do something more 
+			// sophisticated here...
+			if ($currentSibling->hasChildNodes() && $isGeomColumn){
+				$geomNode = $currentSibling->firstChild; 
+					$geomType = $geomNode->nodeName;
+					switch ($geomType) {
+						case "gml:Polygon" :
+							$feature->geometry = new GMLPolygon();
+							$this->parsePolygon($geomNode, $feature->geometry);
+							break;
+						case "gml:LineString" :
+							$feature->geometry = new GMLLine();
+							$this->parseLine($geomNode, $feature->geometry);
+							break;
+						case "gml:Point" :
+							$feature->geometry = new GMLPoint();
+							$this->parsePoint($geomNode, $feature->geometry);
+							break;
+						case "gml:MultiLineString" :
+							$feature->geometry = new GMLMultiLine();
+							$this->parseMultiLine($geomNode, $feature->geometry);
+							break;
+						case "gml:MultiPolygon" :
+							$feature->geometry = new GMLMultiPolygon();
+							$this->parseMultiPolygon($geomNode, $feature->geometry);
+							break;
+						default:
+							$feature->properties[$columnName] = $value;
+							break;
+					}
+			} 
+			else {
+					$feature->properties[$columnName] = $value;
+			}
+			
+			$currentSibling = $currentSibling->nextSibling;
+		}
+	}
+	
+	
+	/**
+	 * Creates GML 2 objects from GML documents.
+	 * 
+	 * @return Gml_2
+	 * @param $xml String
+	 */
+	public function createFromXml ($xml) {
+		try {
+			$gml2 = new Gml_2();
+			
+			if (func_num_args() == 2) {
+				$gml2->geomFeaturetypeElement = func_get_arg(1);
+			}
+
+			$xml = $this->removeWhiteSpace($xml);
+			$gmlDoc = new SimpleXMLElement($xml);
+			
+			$gmlDoc->registerXPathNamespace('xls', 'http://www.opengis.net/xls');
+			$gmlDoc->registerXPathNamespace('wfs', 'http://www.opengis.net/wfs');
+			$gmlDoc->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+			
+			// build feature collection
+			$gml2->featureCollection = new FeatureCollection();
+			
+			// segments of the featzreCollection
+			$gmlFeatureMembers = $gmlDoc->xpath("//gml:featureMember");
+			
+			if(count($gmlFeatureMembers)>0){
+				$cnt=0;
+				foreach ($gmlFeatureMembers as $gmlFeatureMember) {
+					$featureMember_dom = dom_import_simplexml($gmlFeatureMember);
+					
+					$feature = new Feature();
+					if ($this->geomFeaturetypeElement != null) {
+						$this->parseFeature($featureMember_dom, $feature, $this->geomFeaturetypeElement);
+					}
+					else {
+						$this->parseFeature($featureMember_dom, $feature);
+					}
+					if (isset($feature->geometry)) {
+						$gml2->featureCollection->addFeature($feature);
+					}
+					$cnt++;
+				}
+			}
+			return $gml2;
+		}
+		catch (Exception $e) {
+			$e = new mb_exception($e);
+			return null;
+		}
+	}
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_gml_3.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_3.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_gml_3.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,27 @@
+<?php
+# $Id: class_gml2.php 3099 2008-10-02 15:29:23Z nimix $
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_gml.php");
+
+class Gml_3 extends Gml {
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_gml_3_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_3_factory.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_gml_3_factory.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,57 @@
+<?php
+# $Id: class_wfs.php 3094 2008-10-01 13:52:35Z christoph $
+# http://www.mapbender.org/index.php/class_wfs.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_factory.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_3.php");
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+
+/**
+ * Creates GML 3 objects from a GML documents.
+ * 
+ * @return Gml_3
+ */
+class Gml_3_Factory extends GmlFactory {
+
+	/**
+	 * Creates GML 3 objects from GML documents.
+	 * 
+	 * @return Gml_3
+	 * @param $xml String
+	 */
+	public function createFromXml ($xml) {
+		try {
+			$gml3 = new Gml_3();
+			
+			if (func_num_args() == 2) {
+				$gml3->geomFeaturetypeElement = func_get_arg(1);
+			}
+
+			$xml = $this->removeWhiteSpace($xml);
+			$gmlDoc = new SimpleXMLElement($xml);
+			
+		}
+		catch (Exception $e) {
+			$e = new mb_exception($e);
+			return null;
+		}
+	}
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_gml_envelope.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_envelope.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_gml_envelope.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,50 @@
+<?php
+# $Id: class_gml2.php 3099 2008-10-02 15:29:23Z nimix $
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_polygon.php");
+
+/**
+ * 		Models a GML Envelope.
+ * 
+ *      Example:
+ *      
+ *      <gml:Envelope>
+ *         <gml:lowerCorner>42.943 -71.032</gml:lowerCorner>
+ *         <gml:upperCorner>43.039 -69.856</gml:upperCorner>
+ *      </gml:Envelope>
+ */
+class GMLEnvelope extends GMLPolygon{
+
+	public function parseEnvelope ($domNode) {
+		$corner1 = $domNode->firstChild;
+		$corner2 = $corner1->nextSibling;
+		
+		list($y1,$x1) = explode(' ',$corner1->nodeValue);
+		list($y2,$x2) = explode(' ',$corner2->nodeValue);
+
+		$this->addPoint($x1, $y1);
+		$this->addPoint($x1, $y2);
+		$this->addPoint($x2, $y2);
+		$this->addPoint($x2, $y1);
+		$this->addPoint($x1, $y1);
+	}
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_gml_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_factory.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_gml_factory.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,44 @@
+<?php
+# $Id: class_wfs.php 3094 2008-10-01 13:52:35Z christoph $
+# http://www.mapbender.org/index.php/class_wfs.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+
+/**
+ * Creates GML objects from GML documents.
+ * 
+ * @return Gml
+ */
+class GmlFactory {
+
+	public function removeWhiteSpace ($string) {
+		return preg_replace("/\>(\s)+\</", "><", trim($string));
+	}
+	
+	/**
+	 * Creates GML objects from GML documents.
+	 * 
+	 * @return Gml
+	 * @param $xml String
+	 */
+	public function createFromXml ($xml) {
+	}
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_gml_feature.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_feature.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_gml_feature.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,69 @@
+<?php
+# $Id: class_gml2.php 3099 2008-10-02 15:29:23Z nimix $
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_point.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_line.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_multiline.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_polygon.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_multipolygon.php");
+
+
+class Feature {
+
+	var $type = "Feature";
+	var $fid;
+	var $geometry = false;
+	var $properties = array();
+	var $geomFeaturetypeElement = null;
+	
+	public function __construct() {
+	}
+	
+
+	public function toGeoJSON () {
+		$str = "";
+		$str .= "{\"type\":\"Feature\", \"id\":\"".$this->fid."\", \"geometry\": ";
+		if ($this->geometry) {
+			$str .= $this->geometry->toGeoJSON();
+		}
+		else {
+			$str .= "\"\"";
+		}
+
+		
+		$prop = array();
+		
+		$str .= ", \"properties\": ";
+		$cnt = 0;
+		foreach ($this->properties as $key => $value) {
+				$prop[$key] = $value;
+				$cnt ++;
+		}
+
+		$json = new Mapbender_JSON();
+		$str .= $json->encode($prop); 
+		$str .= "}";
+		
+		return $str;
+	}
+}
+
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_gml_feature_collection.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_feature_collection.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_gml_feature_collection.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,55 @@
+<?php
+# $Id: class_gml2.php 3099 2008-10-02 15:29:23Z nimix $
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_feature.php");
+
+
+class FeatureCollection {
+	var $type = "FeatureCollection";
+	var $featureArray = array();
+	
+	public function __construct() {
+		
+	}
+	
+	public function addFeature ($aFeature) {
+		array_push($this->featureArray, $aFeature);
+	}
+	
+	public function toGeoJSON () {
+		$str = "";
+		$str .= "{\"type\": \"FeatureCollection\", \"features\": [";
+
+		$len = count($this->featureArray); 
+		if ($len > 0) {
+			for ($i=0; $i < $len; $i++) {
+				if ($i > 0) {
+					$str .= ",";
+				}	
+				$str .= $this->featureArray[$i]->toGeoJSON();
+			}
+		}
+
+		$str .= "]}";
+		return $str;
+	}
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_gml_line.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_line.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_gml_line.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,55 @@
+<?php
+# $Id: class_gml2.php 3099 2008-10-02 15:29:23Z nimix $
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+
+
+class GMLLine {
+
+	var $pointArray = array();
+
+	public function __construct() {
+		
+	}
+
+	public function addPoint ($x, $y) {
+		array_push($this->pointArray, array("x" => $x, "y" => $y));
+	}
+	
+	public function toGeoJSON () {
+		$numberOfPoints = count($this->pointArray);
+		$str = "";
+		if ($numberOfPoints > 0) {
+			$str .= "{\"type\": \"LineString\", \"coordinates\":[";
+			for ($i=0; $i < $numberOfPoints; $i++) {
+				if ($i > 0) {
+					$str .= ",";
+				}
+				$str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+			}
+			$str .= "]}";
+		}
+		else {
+			$e = new mb_exception("GMLLine: toGeoJSON: this point is null.");
+		}
+		return $str;
+	}
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_gml_multiline.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_multiline.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_gml_multiline.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,65 @@
+<?php
+# $Id: class_gml2.php 3099 2008-10-02 15:29:23Z nimix $
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+
+
+class GMLMultiLine {
+
+	var $lineArray = array();
+
+	public function __construct() {
+		
+	}
+	
+	public function addPoint ($x, $y, $i) {
+		array_push($this->lineArray[$i], array("x" => $x, "y" => $y));
+	}
+	
+	public function toGeoJSON () {
+		$numberlineArray = count($this->lineArray);
+		$str = "";
+		if ($numberlineArray > 0) {
+			$str .= "{\"type\": \"MultiLineString\", \"coordinates\":[";
+			
+			for ($cnt =0; $cnt < $numberlineArray; $cnt++){
+				if ($cnt > 0) {
+						$str .= ",";
+					}
+					$str .="[";
+			
+				for ($i=0; $i < count($this->lineArray[$cnt]); $i++) {
+					if ($i > 0) {
+						$str .= ",";
+					}
+					$str .= "[".$this->lineArray[$cnt][$i]["x"].",".$this->lineArray[$cnt][$i]["y"]."]";
+				}
+				$str .="]";
+			}
+			$str .= "]}";
+			
+		}
+		else {
+			$e = new mb_exception("GMLMultiLine: toGeoJSON: this multiLine is null.");
+		}
+		return $str;
+	}
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_gml_multipolygon.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_multipolygon.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_gml_multipolygon.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,86 @@
+<?php
+# $Id: class_gml2.php 3099 2008-10-02 15:29:23Z nimix $
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+
+class GMLMultiPolygon {
+
+	var $polygonArray = array();
+	var $innerRingArray = array();
+
+	public function __construct() {
+		
+	}
+
+	public function addPointToRing ($i, $j, $x, $y) {
+		if (count($this->innerRingArray[$i]) <= $j) {
+			array_push($this->innerRingArray[$i], array());
+		}
+		array_push($this->innerRingArray[$i][$j], array("x" => $x, "y" => $y));
+	}
+	
+	public function addPoint ($x, $y, $i) {
+
+		array_push($this->polygonArray[$i], array("x" => $x, "y" => $y));
+	}
+	
+	public function toGeoJSON () {
+		$numberPolygonArray = count($this->polygonArray);
+		$str = "";
+		if ($numberPolygonArray > 0) {
+			$str .= "{\"type\": \"MultiPolygon\", \"coordinates\":[";
+			
+			for ($cnt =0; $cnt < $numberPolygonArray; $cnt++){
+				if ($cnt > 0) {
+					$str .= ",";
+				}
+				$str .= "[";
+
+				$str .= "[";
+				for ($i=0; $i < count($this->polygonArray[$cnt]); $i++) {
+					if ($i > 0) {
+						$str .= ",";
+					}
+					$str .= "[".$this->polygonArray[$cnt][$i]["x"].",".$this->polygonArray[$cnt][$i]["y"]."]";
+				}
+				$str .= "]";
+				
+				for ($i=0; $i < count($this->innerRingArray[$cnt]); $i++) {
+					$str .= ",[";
+					for ($j=0; $j < count($this->innerRingArray[$cnt][$i]); $j++) {
+						if ($j > 0) {
+							$str .= ",";
+						}
+						$str .= "[".$this->innerRingArray[$cnt][$i][$j]["x"].",".$this->innerRingArray[$cnt][$i][$j]["y"]."]";
+					}
+					$str .= "]";
+				}
+				$str .= "]";
+			}
+			$str .= "]}";
+			
+		}
+		else {
+			$e = new mb_exception("GMLMultiPolygon: toGeoJSON: this multiLine is null.");
+		}
+		return $str;
+	}
+}
+?>

Added: trunk/mapbender/http/classes/class_gml_point.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_point.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_gml_point.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,49 @@
+<?php
+# $Id: class_gml2.php 3099 2008-10-02 15:29:23Z nimix $
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+
+class GMLPoint {
+
+	var $point;
+
+	public function __construct() {
+		
+	}
+
+	public function setPoint ($x, $y) {
+#		echo "x: " . $x . " y: " . $y . "\n";
+		$this->point = array("x" => $x, "y" => $y);
+	}
+	
+	public function toGeoJSON () {
+		$str = "";
+		if ($this->point) {
+			$str .= "{\"type\": \"Point\", \"coordinates\":";
+			$str .= "[".$this->point["x"].",".$this->point["y"]."]";
+			$str .= "}";
+		}
+		else {
+			$e = new mb_exception("GMLPoint: toGeoJSON: this point is null.");
+		}
+		return $str;
+	}
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_gml_polygon.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_polygon.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_gml_polygon.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,78 @@
+<?php
+# $Id: class_gml2.php 3099 2008-10-02 15:29:23Z nimix $
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+
+
+class GMLPolygon {
+
+	var $pointArray = array();
+	var $innerRingArray = array();
+
+	public function __construct() {
+		
+	}
+
+	
+	public function addPoint ($x, $y) {
+		array_push($this->pointArray, array("x" => $x, "y" => $y));
+	}
+	
+	public function addPointToRing ($i, $x, $y) {
+		if (count($this->innerRingArray) <= $i) {
+			array_push($this->innerRingArray, array());
+		}
+		$index = count($this->innerRingIndex);
+		$currentIndex = ($i < $index ? $i : $index);
+		array_push($this->innerRingArray[$currentIndex], array("x" => $x, "y" => $y));
+	}
+	
+	public function toGeoJSON () {
+		$numberOfPoints = count($this->pointArray);
+		$str = "";
+		if ($numberOfPoints > 0) {
+			$str .= "{\"type\": \"Polygon\", \"coordinates\":[[";
+			for ($i=0; $i < $numberOfPoints; $i++) {
+				if ($i > 0) {
+					$str .= ",";
+				}
+				$str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+			}
+			$str .= "]";
+			
+			for ($i=0; $i < count($this->innerRingArray); $i++) {
+				$str .= ",[";
+				for ($j=0; $j < count($this->innerRingArray[$i]); $j++) {
+					if ($j > 0) {
+						$str .= ",";
+					}
+					$str .= "[".$this->innerRingArray[$i][$j]["x"].",".$this->innerRingArray[$i][$j]["y"]."]";
+				}
+				$str .= "]";
+			}
+			$str .= "]}";
+		}
+		else {
+			$e = new mb_exception("GMLPolygon: toGeoJSON: this point is null.");
+		}
+		return $str;
+	}
+}
+?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_gui.php
===================================================================
--- trunk/mapbender/http/classes/class_gui.php	2009-01-30 14:01:20 UTC (rev 3509)
+++ trunk/mapbender/http/classes/class_gui.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -28,13 +28,31 @@
 	var $id;
 	var $elementArray = array();
 	
-	public function __construct ($id) {
-		if ($id) {
-			$this->id = $id;
-			$this->elementArray = $this->selectElements();
+	public function __construct () {
+		if (func_num_args() == 1) {
+			$id = func_get_arg(0);
+			if ($this->guiExists($id))	{
+				$this->id = $id;
+				$this->elementArray = $this->selectElements();
+			}
 		}
 	}
 
+	
+	public function addWfs ($aWfs) {
+		$sql ="INSERT INTO gui_wfs (fkey_gui_id, fkey_wfs_id)";
+		$sql .= "VALUES ($1, $2);";
+		$v = array($this->id, $aWfs->id);
+		$t = array("s", "i");
+		$res = db_prep_query($sql, $v, $t);
+
+		if (!$res) {
+			$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+			return false;
+		}
+		return true;
+	}
+	
 	public function selectElements () {
 		$sql = "SELECT e_id FROM gui_element WHERE fkey_gui_id = $1 " . 
 				"ORDER BY e_pos";

Modified: trunk/mapbender/http/classes/class_mb_exception.php
===================================================================
--- trunk/mapbender/http/classes/class_mb_exception.php	2009-01-30 14:01:20 UTC (rev 3509)
+++ trunk/mapbender/http/classes/class_mb_exception.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -31,6 +31,9 @@
 	 * @param	string $message		message that is being logged
 	 */
 	public function __construct ($message) {
+		if ($message == Exception) {
+			return $this->mb_log("ERROR: " . $e->getMessage(), $this->level);
+		}
 		return $this->mb_log("ERROR: " . $message, $this->level);
 	}
 

Added: trunk/mapbender/http/classes/class_ows.php
===================================================================
--- trunk/mapbender/http/classes/class_ows.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_ows.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,75 @@
+<?php
+# $Id: class_wfs.php 3094 2008-10-01 13:52:35Z christoph $
+# http://www.mapbender.org/index.php/class_wfs.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+
+/**
+ * An abstract class modelling an OGC web service (OWS), for example
+ * Web Map Service (WMS) or Web Feature Service (WFS).
+ */
+abstract class Ows {
+	var $id;
+	var $name;
+	var $title;
+	var $summary;
+	var $uploadUrl;
+	var $getCapabilities;
+	var $getCapabilitiesDoc;
+	var $fees;
+	var $accessconstraints;
+	var $individualName;
+	var $positionName;
+	var $providerName;
+	var $city;
+	var $deliveryPoint;
+	var $administrativeArea;
+	var $postalCode;
+	var $voice;
+	var $facsimile;
+	var $electronicMailAddress;
+	var $country;
+	
+	/**
+	 * Returns the conjunction character of an URL
+	 * 
+	 * @param String $url
+	 * @return String the character "&", "?", or ""
+	 */
+	final protected function getConjunctionCharacter ($url) {
+		// does the URL contain "?"
+		$pos = strpos($url, "?");
+
+		// if yes, ...
+		if ($pos > -1) { 
+			// if the last character is "?", return ""
+			if (substr($url, -1) == "?") { 
+				return "";
+			}
+			// if the last character is "&", return ""
+			else if (substr($url, -1) == "&") {
+				return "";
+			}
+			// "?" exists, so the conunction character must be "&"
+			return "&";
+		}
+		// "?" doesn't exist, so the conunction character must be "?"
+		return "?";
+	}
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_ows_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_ows_factory.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_ows_factory.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,121 @@
+<?php
+# $Id: class_wfs.php 3094 2008-10-01 13:52:35Z christoph $
+# http://www.mapbender.org/index.php/class_wfs.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+
+/**
+ * This abstract class is the superclass of all factories
+ * creating OGC Web Services (OWS).
+ */
+abstract class OwsFactory {
+	
+	/**
+	 * Creates an OWS from an XML, presumably a capabilities document.
+	 * 
+	 * @return Ows
+	 * @param $xml String
+	 */
+	abstract public function createFromXml ($xml);
+
+	/**
+	 * Creates an OWS from the Mapbender database.
+	 * 
+	 * @return Ows
+	 * @param $id Integer The index in the database
+	 */
+	abstract public function createFromDb ($id);
+	
+	/**
+	 * Removes endlines and carriage returns from a string.
+	 * 
+	 * @return String
+	 * @param $string String
+	 */
+	final protected function stripEndlineAndCarriageReturn ($string) {
+		return preg_replace("/\n/", "", preg_replace("/\r/", " ", $string));
+	}
+	
+	/**
+	 * Creates a random id. The id contains non-numeric characters in 
+	 * order to distinguish it from a database id.
+	 * 
+	 * @return String
+	 */
+	final protected function createId () {
+		return "id_" . substr(md5(rand()),0,6);
+	}
+	
+	/**
+	 * Removes the namespace from a tag name.
+	 * 
+	 * Example: input is "topp:the_geom" will return "the_geom".
+	 * 
+	 * @return String
+	 * @param $s String
+	 */
+	final protected function sepNameSpace($s) {
+		$c = strpos($s, ":"); 
+		if ($c > 0) {
+			return substr($s, $c + 1);
+		}
+		return $s;
+	}
+
+	/**
+	 * Retrieves a document from a URL, presumably a capabilities document.
+	 * 
+	 * @return String
+	 * @param $url String
+	 */
+	final protected function getFromUrl ($url) {
+		$x = new connector($url);
+		$xml = $x->file;
+		if(!$xml){
+			throw new Exception("Unable to open document: " . $url);
+			return null;
+		}
+		return $xml;		
+	}
+
+	/**
+	 * Creates an OWS from an XML, presumably a capabilities document, 
+	 * which is retrieved from a URL.
+	 * 
+	 * @return Ows
+	 * @param $url String
+	 */
+	final public function createFromUrl ($url) {
+		try {
+			$xml = $this->getFromUrl($url);
+	
+			$myOws = $this->createFromXml($xml);
+			if ($myOws != null) {
+				$myOws->uploadUrl = $url;
+				return $myOws;
+			}		
+			return null;
+		}
+		catch (Exception $e) {
+			new mb_exception($e);
+			return null;
+		}
+		return null;
+	}
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_universal_wfs_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_universal_wfs_factory.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_universal_wfs_factory.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,116 @@
+<?php
+# $Id: class_wfs.php 3094 2008-10-01 13:52:35Z christoph $
+# http://www.mapbender.org/index.php/class_wfs.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+require_once(dirname(__FILE__)."/../classes/class_ows_factory.php");
+require_once(dirname(__FILE__)."/../classes/class_wfs_factory.php");
+require_once(dirname(__FILE__)."/../classes/class_wfs_1_0_factory.php");
+require_once(dirname(__FILE__)."/../classes/class_wfs_1_1_factory.php");
+
+/**
+ * 
+ * @return 
+ * @param $xml String
+ */
+class UniversalWfsFactory extends WfsFactory {
+	
+	/**
+	 * Parses the capabilities document for the WFS 
+	 * version number and returns it.
+	 * 
+	 * @return String
+	 * @param $xml String
+	 */
+	private function getVersionFromXml ($xml) {
+
+		$admin = new administration();
+		$values = $admin->parseXml($xml);
+		
+		foreach ($values as $element) {
+			if($this->sepNameSpace(strtoupper($element[tag])) == "WFS_CAPABILITIES" && $element[type] == "open"){
+				return $element[attributes][version];
+			}
+		}
+		throw new Exception("WFS version could not be determined from XML.");
+	}
+
+	/**
+	 * Creates a WFS object by parsing its capabilities document. 
+	 * 
+	 * The WFS version is determined by parsing 
+	 * the capabilities document up-front.
+	 * 
+	 * @return Wfs
+	 * @param $xml String
+	 */
+	public function createFromXml ($xml) {
+		try {
+			$version = $this->getVersionFromXml($xml);
+
+			switch ($version) {
+				case "1.0.0":
+					$factory = new Wfs_1_0_Factory();
+					break;
+				case "1.1.0":
+					$factory = new Wfs_1_1_Factory();
+					break;
+				default:
+					throw new Exception("Unknown WFS version " . $version);
+					break;
+			}
+			return $factory->createFromXml($xml);
+		}
+		catch (Exception $e) {
+			new mb_exception($e);
+			return null;
+		}
+	}
+	
+	public function createFromDb ($id) {
+		try {
+			$sql = "SELECT wfs_version FROM wfs WHERE wfs_id = $1";
+			$v = array($id);
+			$t = array("i");
+			$res = db_prep_query($sql, $v, $t);
+			$row = db_fetch_array($res);
+			if ($row) {
+				$version = $row["wfs_version"];
+				
+				switch ($version) {
+					case "1.0.0":
+						$factory = new Wfs_1_0_Factory();
+						break;
+					case "1.1.0":
+						$factory = new Wfs_1_1_Factory();
+						break;
+					default:
+						throw new Exception("Unknown WFS version " . $version);
+						break;
+				}
+				return $factory->createFromDb($id);
+			}
+		}
+		catch (Exception $e) {
+			new mb_exception($e);
+			return null;
+		}
+	}
+}
+?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_wfs.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs.php	2009-01-30 14:01:20 UTC (rev 3509)
+++ trunk/mapbender/http/classes/class_wfs.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -17,795 +17,218 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-/**
-* class for wfs-objects
-*/
-
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__)."/class_connector.php");
-require_once(dirname(__FILE__)."/class_administration.php");
+require_once(dirname(__FILE__)."/class_administration.php");
+require_once(dirname(__FILE__)."/class_ows.php");
+require_once(dirname(__FILE__)."/class_wfsToDb.php");
 
-class wfs {
-
-  var $wfs_id;
-  var $wfs_version;
-  var $wfs_name;
-  var $wfs_title;
-  var $wfs_abstract;
-  var $wfs_getcapabilities;
-  var $wfs_getcapabilities_doc; //new SB 2007-08-09
-  var $wfs_describefeaturetype;
-  var $wfs_describefeaturetype_namespace = array();
-  var $wfs_getfeature;
-  var $wfs_transaction;
-  var $wfs_upload_url; //new SB 2007-08-09
-
-  //new WFS 1.0.0 -- SB 2007-08-06
-
-  var $fees;
-  var $accessconstraints;
-  
-  var $wfs_featuretype = array();
- 
- 
-function wfs() {
-
-} 
-function createObjFromXML($url){
+/**
+ * An abstract Web Feature Service (WFS) class, modelling for example
+ * WFS 1.0.0 or WFS 1.1.0
+ */
+abstract class Wfs extends Ows {
+	var $describeFeatureType;
+	var $describeFeatureTypeNamespace;
+	var $getFeature;
+	var $transaction;
+	var $featureTypeArray = array();
 	
-	$x = new connector($url);
-	$data = $x->file;
-	#$data = implode("",file($url));
-	if(!$data){
-		echo "Unable to open document: ".$url;
-		die; 
+	/**
+	 * Returns the version of this WFS. Has to be implemented by the subclass.
+	 * @return String the version, for example "1.0.0"
+	 */
+	public function getVersion () {
+		return "";
 	}
 	
-	$values = null;
-	$tags = null;
-	$admin = new administration();
-	$this->wfs_getcapabilities_doc = $admin->char_encode($data);
-	$this->wfs_upload_url = $url;
-	
-	# for temporary wfs a id has to be created...
-	$this->wfs_id = "id_" . substr(md5(rand()),0,6);
-	$parser = xml_parser_create(CHARSET);
-	xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
-	xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
-	xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
-	xml_parse_into_struct($parser,$this->wfs_getcapabilities_doc,$values,$tags);
-	//xml_parse_into_struct($parser,$data,$values,$tags);
-	
-	xml_parser_free($parser);
-	
-	$section = false;
-	$request = false;
-	$featuretype_name = false;
- 	$featuretype_title = false;
- 	$featuretype_abstract = false;
- 	$featuretype_srs = false;
-	
-	foreach ($values as $element) {
-	
-		if(strtoupper($element[tag]) == "WFS_CAPABILITIES" && $element[type] == "open"){
-			$this->wfs_version = $element[attributes][version];
-		}
-		if(strtoupper($element[tag]) == "NAME"  && $element[level] == '3'){
-			$this->wfs_name = $element[value];
-		}
-		if(strtoupper($element[tag]) == "TITLE"  && $element[level] == '3'){
-			$this->wfs_title = $this->stripEndlineAndCarriageReturn($element[value]);
-		}
-		if(strtoupper($element[tag]) == "ABSTRACT" && $element[level] == '3'){
-			$this->wfs_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
-		}
-		//new WFS 1.0.0 -- SB 2007-08-06
-		if(strtolower($element[tag]) == "fees"){
-			$this->fees = $element[value];
-		}
-		if(strtolower($element[tag]) == "accessconstraints"){
-			$this->accessconstraints = $element[value];
-		}
-		
-		/*capability section*/
-		
-		if($this->wfs_version == "1.0.0"){
-			
-			# getCapabilities
-			if(strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "open"){
-				$section = "getcapabilities";
-			}
-			if($section == "getcapabilities" && strtoupper($element[tag]) == "POST"){
-				$this->wfs_getcapabilities = $element[attributes][onlineResource];
-			}
-			
-			# descriptFeatureType
-			if(strtoupper($element[tag]) == "DESCRIBEFEATURETYPE" && $element[type] == "open"){
-				$section = "describefeaturetype";
-				$this->wfs_describefeaturetype = $element[attributes][onlineResource];
-				
-				
-			}
-			if($section == "describefeaturetype" && strtoupper($element[tag]) == "POST"){
-				$this->wfs_describefeaturetype = $element[attributes][onlineResource];
-			}
-			
-			# getFeature
-			if(strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "open"){
-				$section = "getfeature";
-			}
-			if($section == "getfeature" && strtoupper($element[tag]) == "POST"){
-				$this->wfs_getfeature = $element[attributes][onlineResource];
-			}
-			if(strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "close"){
-				$section = "";
-			}			
-			# transaction
-			if(strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "open"){
-				$section = "transaction";
-			}
-			if($section == "transaction" && strtoupper($element[tag]) == "POST"){
-				$this->wfs_transaction = $element[attributes][onlineResource];
-			}
-			if(strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "close"){
-				$section = "";
-			}
-		} 
-		if(strtoupper($element[tag]) == "FEATURETYPE" && $element[type] == "open"){
-			$section = "featuretype";
-		}
-		if($section == "featuretype" && strtoupper($element[tag]) == "NAME"){
-			$featuretype_name = $element[value];
-		}
-		if($section == "featuretype" && strtoupper($element[tag]) == "TITLE"){
-			$featuretype_title = $this->stripEndlineAndCarriageReturn($element[value]);
-		}
-		if($section == "featuretype" && strtoupper($element[tag]) == "ABSTRACT"){
-			$featuretype_abstract = $this->$element[value];
-		}
-		if($section == "featuretype" && strtoupper($element[tag]) == "SRS"){
-			$featuretype_srs = $element[value];
-			$this->addFeaturetype($featuretype_name,$featuretype_title,$featuretype_abstract,$featuretype_srs,$this->wfs_describefeaturetype,$this->wfs_version);
-		}
+	public function addFeatureType ($aFeatureType) {
+		array_push($this->featureTypeArray, $aFeatureType);
 	}
-}
-function displayWFS(){
-	echo "id: " . $this->wfs_id . " <br>";
-	echo "version: " . $this->wfs_version . " <br>";
-	echo "name: " . $this->wfs_name . " <br>";
-	echo "title: " . $this->wfs_title . " <br>";
-	echo "abstract: " . $this->wfs_abstract . " <br>";
-	echo "capabilitiesrequest: " . $this->wfs_getcapabilities . " <br>";
-	echo "describefeaturetype: " . $this->wfs_describefeaturetype . " <br>";
-	echo "getfeature: " . $this->wfs_getfeature . " <br>";
-	echo "transaction: " . $this->wfs_transaction . " <br>";
-	for($i=0; $i<count($this->wfs_featuretype); $i++){
-		echo "<hr>";
-		echo "name: ". $this->wfs_featuretype[$i]->featuretype_name . "<br>";
-		echo "title: ". $this->wfs_featuretype[$i]->featuretype_title . "<br>";
-		echo "abstract: ". $this->wfs_featuretype[$i]->featuretype_abstract . "<br>";
-		echo "srs: ". $this->wfs_featuretype[$i]->featuretype_srs . "<br>";
-		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
-			echo " element: " . $this->wfs_featuretype[$i]->featuretype_element[$j]["name"] ." - ".$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]."<br>";
-		}
-		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_namespace);$j++){
-			echo " namespace: " . $this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"] ." - ".$this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]."<br>";
-		}
-	}
-} 
-function addFeaturetype($name,$title,$abstract,$srs,$url,$version){
-	$this->wfs_featuretype[count($this->wfs_featuretype)] = new featuretype($name,$title,$abstract,$srs,$url,$version);
-}
- function stripEndlineAndCarriageReturn($string) {
-	  	return preg_replace("/\n/", "", preg_replace("/\r/", " ", $string));
-	  }
-function createJsObjFromWFS($parent){
-	if(!$this->wfs_title || $this->wfs_title == ""){
-		echo "alert('Error: no valid capabilities-document !!');";
-		die; exit;
-	}
-		if($parent){
-			echo "parent.";
-		}
-		print("add_wfs('". 
-		$this->wfs_id ."','".
-		$this->wfs_version ."','".
-		$this->wfs_title ."','".
-		$this->wfs_abstract ."','". 
-		$this->wfs_getcapabilities ."','" .
-		$this->wfs_describefeaturetype ."');");
-		
+	
+	public function getFeature ($featureTypeName, $filter) {
 
-	for($i=0; $i<count($this->wfs_featuretype); $i++){
-		if($parent){
-			echo "parent.";
+		$url = $this->getFeature .
+				$this->getConjunctionCharacter($this->getFeature) . 
+				"service=WFS&request=getFeature&version=" . 
+				$this->getVersion() . "&typename=" . $featureTypeName . 
+				"&filter=" . urlencode($filter);
+
+		$connection = new connector($url);
+		$data = $connection->file;
+		if (!$data) {
+			$e = new mb_exception("WFS request returned no result: " . $url);
+			return null;
 		}
-		print ("wfs_add_featuretype('". 
-			$this->wfs_featuretype[$i]->featuretype_name ."','". 
-			$this->wfs_featuretype[$i]->featuretype_title . "','".
-			$this->wfs_featuretype[$i]->featuretype_abstract . "','".  
-			$this->wfs_featuretype[$i]->featuretype_srs ."','". 
-			$this->wfs_featuretype[$i]->featuretype_geomtype ."');");
-		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
-			if($parent){
-			echo "parent.";
-			}
-			print("wfs_add_featuretype_element('".$this->wfs_featuretype[$i]->featuretype_element[$j]["name"]."', '".$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]."', ".$j.", ".$i.");");
-		}
-		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_namespace);$j++){
-			if($parent){
-			echo "parent.";
-			}
-			print("wfs_add_featuretype_namespace('".$this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"]."', '".$this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]."', ".$j.", ".$i.");");
-		}
+		return $data;
 	}
-}
-
-/**
- * Inserts this WFS in the database
- */
-function insertWfs() {
-	global $DBSERVER,$DB,$OWNER,$PW;
-	$con = db_connect($DBSERVER,$OWNER,$PW);
-	db_select_db($DB,$con);
-
-	$sql = "INSERT INTO wfs (wfs_version, wfs_name, wfs_title, wfs_abstract, ";
-	$sql .= "wfs_getcapabilities, wfs_getcapabilities_doc, wfs_upload_url, ";
-	$sql .= "wfs_describefeaturetype, wfs_getfeature, wfs_transaction, fees, ";
-	$sql .= "accessconstraints, wfs_owner, wfs_timestamp) ";
-	$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)";
-
-	$v = array($this->wfs_version, $this->wfs_name, $this->wfs_title, 
-		$this->wfs_abstract, $this->wfs_getcapabilities, $this->wfs_getcapabilities_doc,
-		$this->wfs_upload_url, $this->wfs_describefeaturetype, $this->wfs_getfeature,
-		$this->wfs_transaction, $this->fees, $this->accessconstraints, 
-		$_SESSION["mb_user_id"], strtotime("now"));
-		
-	$t = array('s', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 'i', 'i');
-
-	$res = db_prep_query($sql,$v,$t);
-
-	if(!$res){
-		db_rollback();
-		$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
-		return false;
-	}
-	$this->wfs_id = db_insert_id($con,'wfs','wfs_id');
-	return true;
-}
-
-function updateWfs() {
-	global $DBSERVER,$DB,$OWNER,$PW;
-	$con = db_connect($DBSERVER,$OWNER,$PW);
-	db_select_db($DB,$con);
-
-	$sql = "UPDATE wfs SET wfs_version = $1, wfs_name = $2, wfs_title = $3, ";
-	$sql .= "wfs_abstract = $4, wfs_getcapabilities = $5, wfs_getcapabilities_doc = $6, ";
-	$sql .= "wfs_upload_url = $7, wfs_describefeaturetype = $8, wfs_getfeature = $9, ";
-	$sql .= "wfs_transaction = $10, fees = $11, accessconstraints = $12, wfs_owner = $13, ";
-	$sql .= "wfs_timestamp = $14 ";
-	$sql .= "WHERE wfs_id = $15";
-	//echo $sql."<br />";
-	$v = array($this->wfs_version, $this->wfs_name, $this->wfs_title, $this->wfs_abstract,
-		$this->wfs_getcapabilities, $this->wfs_getcapabilities_doc, $this->wfs_upload_url,
-		$this->wfs_describefeaturetype, $this->wfs_getfeature, $this->wfs_transaction,
-		$this->fees, $this->accessconstraints, $_SESSION["mb_user_id"],strtotime("now"), 
-		$this->wfs_id);
-		
-	$t = array('s', 's', 's', 's', 's', 's', 's', 's' ,'s' ,'s' ,'s' ,'s' ,'i' ,'i' ,'i');
-	$res = db_prep_query($sql,$v,$t);
-	if(!$res){
-		db_rollback();
-		$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
-		return false;
-	}
-	return true;
-}
-/**
-* wfs2db
-*
-* this function saves the class information to the mapbender database 
-* @return boolean true if sucessful false otherwise
-*/
-function wfs2db($gui_id){
-	global $DBSERVER,$DB,$OWNER,$PW;
-	$con = db_connect($DBSERVER,$OWNER,$PW);
-	db_select_db($DB,$con);
 	
-	db_begin();
 	
-	// check if WFS already might exists (it might exist when wfs_id is numeric)
-	$wfs_exists = is_numeric($this->wfs_id);
+	// -----------------------------------------------------------------------
+	//
+	// Output formats
+	//
+	// -----------------------------------------------------------------------
+	
+	/**
+	 * Compiles a string containing HTML formatted information about the WFS.
+	 * 
+	 * @return String 
+	 */
+	public function toHtml () {
+		$wfsString = "";
+		$wfsString .= "id: " . $this->id . " <br>";
+		$wfsString .= "version: " . $this->getVersion() . " <br>";
+		$wfsString .= "name: " . $this->name . " <br>";
+		$wfsString .= "title: " . $this->title . " <br>";
+		$wfsString .= "abstract: " . $this->summary . " <br>";
+		$wfsString .= "capabilitiesrequest: " . $this->getCapabilities . " <br>";
+		$wfsString .= "describefeaturetype: " . $this->describeFeatureType . " <br>";
+		$wfsString .= "getfeature: " . $this->getFeature . " <br>";
+		$wfsString .= "transaction: " . $this->transaction . " <br>";
 
-	// if it might exist, update it
-	if ($wfs_exists) {
-		// but check first if it really exists in the database
-		$sql = "SELECT * FROM wfs WHERE wfs_id = $1;";
-		$v = array($this->wfs_id);
-		$t = array("i");
-		$res = db_prep_query($sql, $v, $t);	
-		if($res){
-			$this->updateWfs();
+		for ($i = 0; $i < count($this->featureTypeArray); $i++) {
+			$currentFeatureType = $this->featureTypeArray[$i];
+			$wfsString .= $currentFeatureType->toHtml();
 		}
-		// if not, insert as new WFS
-		else {
-			$this->insertWfs();
-		}
+		return $wfsString;
 	}
-	// if it does not exist, insert as new WFS
-	else {
-		$this->insertWfs();
-	}
 
-	# delete featuretypes from DB that does not exist and find the ids
-	$sql = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = $1;";
-	$v = array($this->wfs_id);
-	$t = array("i");
-	$res_ft = db_prep_query($sql, $v, $t);
-	$cnt = 0;
-	while(db_fetch_row($res_ft)){
-		$found = false;
-		for($i=0; $i<count($this->wfs_featuretype); $i++){
-			if($this->wfs_featuretype[$i]->featuretype_name == db_result($res_ft, $cnt, "featuretype_name")){
-				$this->wfs_featuretype[$i]->featuretype_id = db_result($res_ft, $cnt, "featuretype_id");
-				$found = true;
-				break;
-			}
-		}
-		
-		if(!$found){
-			$sql = "DELETE FROM wfs_featuretype WHERE featuretype_id = $1 AND fkey_wfs_id = $2";
-			$v = array(db_result($res_ft, $cnt, "featuretype_id"), $this->wfs_id);
-			$t = array('i','i');
-			//echo $sql."<br />";
-			$res = db_prep_query($sql,$v,$t);
-			if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
-		}
-		$cnt++;
+	/**
+	 * Can be switched to other output format if desired.
+	 * 
+	 * @return String
+	 */
+	public function __toString () {
+		return $this->toHtml();
 	}
-	
-	
-	# TABLE wfs_featuretype
-	
-	for($i=0; $i<count($this->wfs_featuretype); $i++){
-		if(!$this->wfs_featuretype[$i]->featuretype_id){
-			$sql = "INSERT INTO wfs_featuretype(fkey_wfs_id, featuretype_name, featuretype_title, featuretype_abstract, featuretype_srs) ";
-			$sql .= "VALUES($1,$2,$3,$4,$5)";
-			$v = array($this->wfs_id,$this->wfs_featuretype[$i]->featuretype_name,$this->wfs_featuretype[$i]->featuretype_title,$this->wfs_featuretype[$i]->featuretype_abstract,$this->wfs_featuretype[$i]->featuretype_srs);
-			$t = array('i','s','s','s','s');
-			//echo $sql."<br />";
-			$res = db_prep_query($sql,$v,$t);
-			if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
-			
-			# save the id of each featuretype: 
-			$this->wfs_featuretype[$i]->featuretype_id = db_insert_id($con,'wfs_featuretype','featuretype_id');
-		}
-		else{
-			$sql = "UPDATE wfs_featuretype SET ";
-			$sql .= "featuretype_title = $1,";
-			$sql .= "featuretype_abstract = $2,";
-			$sql .= "featuretype_srs = $3 ";
-			$sql .= "WHERE featuretype_id = $4";
-			$v = array($this->wfs_featuretype[$i]->featuretype_title,$this->wfs_featuretype[$i]->featuretype_abstract,$this->wfs_featuretype[$i]->featuretype_srs,$this->wfs_featuretype[$i]->featuretype_id);
-			$t = array('s','s','s','i');
-			//echo $sql."<br />";
-			$res = db_prep_query($sql,$v,$t);
-			if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
-		}
-		
-		//delete featuretype elements from db and find the ids
-		$sql = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = $1;";
-		$v = array($this->wfs_featuretype[$i]->featuretype_id);
-		$t = array("i");
-		$res_el = db_prep_query($sql, $v, $t);
-		$cnt = 0;
-		while(db_fetch_row($res_el)){
-			$found = false;
-			for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element); $j++){
-				if($this->wfs_featuretype[$i]->featuretype_element[$j]["name"] == db_result($res_el, $cnt, "element_name")){
-					$this->wfs_featuretype[$i]->featuretype_element[$j]["id"] = db_result($res_el, $cnt, "element_id");
-					$found = true;
-					break;
-				}
-			}
-			
-			if(!$found){
-				$sql = "DELETE FROM wfs_element WHERE element_id = $1 AND fkey_featuretype_id = $2";
-				$v = array(db_result($res_el, $cnt, "element_id"), $this->wfs_featuretype[$i]->featuretype_id);
-				$t = array('i','i');
-				//echo $sql."<br />";
-				$res = db_prep_query($sql,$v,$t);
-				if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
-			}
-			$cnt++;
-		}
 
+	/**
+	 * Creates a string of JavaScript code. This code will then 
+	 * create a WFS object on the client side.
+	 * 
+	 * @return String
+	 */
+	public function toJavaScript () {
+		$jsString = "";
 
-		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
-			if(!$this->wfs_featuretype[$i]->featuretype_element[$j]["id"]){
-				$sql = "INSERT INTO wfs_element(fkey_featuretype_id, element_name,element_type) ";
-				$sql .= "VALUES($1, $2, $3);";
-				
-				$v = array($this->wfs_featuretype[$i]->featuretype_id, $this->wfs_featuretype[$i]->featuretype_element[$j]["name"], $this->wfs_featuretype[$i]->featuretype_element[$j]["type"]);
-				$t = array("s", "s", "s");
-				$res = db_prep_query($sql, $v, $t);
-				if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
-			}
-			else{
-				$sql = "UPDATE wfs_element SET element_type = $1 ";
-				$sql .= "WHERE element_id = $2 AND ";
-				$sql .= "fkey_featuretype_id = $3;";
-				$v = array($this->wfs_featuretype[$i]->featuretype_element[$j]["type"], $this->wfs_featuretype[$i]->featuretype_element[$j]["id"], $this->wfs_featuretype[$i]->featuretype_id);
-				$t = array("s", "i", "i");
-				$res = db_prep_query($sql, $v, $t);
-				if (!$res) {
-					db_rollback();
-					$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
-					return;
-				}
-			}
+		$parent = "";
+		if (func_num_args() == 1 && func_get_arg(0) == true) {
+			$parent = "parent.";
 		}
-
-		$sql = "DELETE FROM wfs_featuretype_namespace WHERE ";
-		$sql .= "fkey_wfs_id = $1 AND fkey_featuretype_id = $2";
-		$v = array($this->wfs_id, $this->wfs_featuretype[$i]->featuretype_id);
-		$t = array("i", "i");
-		$res = db_prep_query($sql, $v, $t);
-		if (!$res) {
-			db_rollback();
-			$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
-			return;
+		
+		if(!$this->title || $this->title == ""){
+			$e = new mb_exception("Error: no valid capabilities-document !!");
+			return null;
 		}
-				
-		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_namespace);$j++){
-			$sql = "INSERT INTO wfs_featuretype_namespace ";
-			$sql .= "(fkey_wfs_id, fkey_featuretype_id, namespace, namespace_location) ";
-			$sql .= "VALUES ($1, $2, $3, $4);"; 
 
-			$v = array($this->wfs_id, $this->wfs_featuretype[$i]->featuretype_id, $this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"], $this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]);
-			$t = array("s", "s", "s", "s");
-			$res = db_prep_query($sql, $v, $t);
-
-			if (!$res) {
-				db_rollback();
-				$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
-				return;
-			}
-		}
-	}
+		$jsString .= $parent . "add_wfs('". 
+			$this->id ."','".
+			$this->getVersion() ."','".
+			$this->title ."','".
+			$this->summary ."','". 
+			$this->getCapabilities ."','" .
+			$this->describeFeatureType .
+			"');";
+			
 	
-	# TABLE gui_wfs
-	
-	if($gui_id){
-		$sql ="INSERT INTO gui_wfs (fkey_gui_id, fkey_wfs_id)";
-		$sql .= "VALUES($1, $2);";
-		$v = array($gui_id, $this->wfs_id);
-		$t = array("s", "i");
-		$res = db_prep_query($sql, $v, $t);
-
-		if (!$res) {
-			db_rollback();
-			$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
-			return;
-		}
-	}
-	
-	//echo "Successfully saved!<br />";
-	db_commit();
-	
-	return true;
-}
-/**
-* updateObjFromXML
-*
-* this function regets the information from the xml (update)
-* @return boolean true if successful, false otherwise
-*/
-function updateObjFromXML($url){
-	$x = new connector($url);
-	$data = $x->file;
-	#$data = implode("",file($url));
-	if(!$data){
-		$e = new mb_exception("Unable to open document: ".$url);
-		return false; 
-	}
-	
-	$values = null;
-	$tags = null;
-	$admin = new administration();
-	$this->wfs_getcapabilities_doc = $admin->char_encode($data);
-	$this->wfs_featuretype = array();
-	$this->wfs_upload_url = $url;
-	
-	# for temporary wfs a id has to be created...
-	//$this->wfs_id = "id_" . substr(md5(rand()),0,6);
-	$parser = xml_parser_create(CHARSET);
-	xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
-	xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
-	xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
-	xml_parse_into_struct($parser,$this->wfs_getcapabilities_doc,$values,$tags);
-	//xml_parse_into_struct($parser,$data,$values,$tags);
-	
-	xml_parser_free($parser);
-	
-	$section = false;
-	$request = false;
-	$featuretype_name = false;
- 	$featuretype_title = false;
- 	$featuretype_abstract = false;
- 	$featuretype_srs = false;
-	
-	foreach ($values as $element) {
-	
-		if(strtoupper($element[tag]) == "WFS_CAPABILITIES" && $element[type] == "open"){
-			$this->wfs_version = $element[attributes][version];
-		}
-		if(strtoupper($element[tag]) == "NAME"  && $element[level] == '3'){
-			$this->wfs_name = $element[value];
-		}
-/*		if(strtoupper($element[tag]) == "TITLE"  && $element[level] == '3'){
-			$this->wfs_title = $this->stripEndlineAndCarriageReturn($element[value]);
-		}
-		if(strtoupper($element[tag]) == "ABSTRACT" && $element[level] == '3'){
-			$this->wfs_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
-		}
-		//new WFS 1.0.0 -- SB 2007-08-06
-		if(strtolower($element[tag]) == "fees"){
-			$this->fees = $element[value];
-		}
-		if(strtolower($element[tag]) == "accessconstraints"){
-			$this->accessconstraints = $element[value];
-		}
-*/		
-		/*capability section*/
-		
-		if($this->wfs_version == "1.0.0"){
+		for ($i = 0; $i < count($this->featureTypeArray); $i++) {
+			$currentFeatureType = $this->featureTypeArray[$i];
 			
-			# getCapabilities
-			if(strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "open"){
-				$section = "getcapabilities";
-			}
-			if($section == "getcapabilities" && strtoupper($element[tag]) == "POST"){
-				$this->wfs_getcapabilities = $element[attributes][onlineResource];
-			}
-			
-			# descriptFeatureType
-			if(strtoupper($element[tag]) == "DESCRIBEFEATURETYPE" && $element[type] == "open"){
-				$section = "describefeaturetype";
-				$this->wfs_describefeaturetype = $element[attributes][onlineResource];
+			$jsString .= $parent . "wfs_add_featuretype('". 
+				$currentFeatureType->name ."','". 
+				$currentFeatureType->title . "','".
+				$currentFeatureType->summary . "','".  
+				$currentFeatureType->srs ."','". 
+				$currentFeatureType->geomtype .
+				"');";
 				
+			for ($j = 0; $j < count($currentFeatureType->elementArray); $j++) {
+				$currentElement = $currentFeatureType->elementArray[$j];
 				
+				$jsString .= $parent . "wfs_add_featuretype_element('" . 
+					$currentElement->name . "', '" . 
+					$currentElement->type . "', " .
+					$j . ", " . 
+					$i . 
+					");";
 			}
-			if($section == "describefeaturetype" && strtoupper($element[tag]) == "POST"){
-				$this->wfs_describefeaturetype = $element[attributes][onlineResource];
-			}
 			
-			# getFeature
-			if(strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "open"){
-				$section = "getfeature";
+			for ($j = 0; $j < count($currentFeatureType->namespaceArray); $j++) {
+				$currentNamespace = $currentFeatureType->namespaceArray[$j];
+				
+				$jsString .= $parent . "wfs_add_featuretype_namespace('" . 
+					$currentNamespace->name . "', '" . 
+					$currentNamespace->value . "', " . 
+					$j . ", " . 
+					$i . 
+					");";
 			}
-			if($section == "getfeature" && strtoupper($element[tag]) == "POST"){
-				$this->wfs_getfeature = $element[attributes][onlineResource];
-			}
-			if(strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "close"){
-				$section = "";
-			}			
-			# transaction
-			if(strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "open"){
-				$section = "transaction";
-			}
-			if($section == "transaction" && strtoupper($element[tag]) == "POST"){
-				$this->wfs_transaction = $element[attributes][onlineResource];
-			}
-			if(strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "close"){
-				$section = "";
-			}
-		} 
-		if(strtoupper($element[tag]) == "FEATURETYPE" && $element[type] == "open"){
-			$section = "featuretype";
+			
 		}
-		if($section == "featuretype" && strtoupper($element[tag]) == "NAME"){
-			$featuretype_name = $element[value];
-		}
-		if($section == "featuretype" && strtoupper($element[tag]) == "TITLE"){
-			$featuretype_title = $this->stripEndlineAndCarriageReturn($element[value]);
-		}
-		if($section == "featuretype" && strtoupper($element[tag]) == "ABSTRACT"){
-			$featuretype_abstract = $this->$element[value];
-		}
-		if($section == "featuretype" && strtoupper($element[tag]) == "SRS"){
-			$featuretype_srs = $element[value];
-			$this->addFeaturetype($featuretype_name,$featuretype_title,$featuretype_abstract,$featuretype_srs,$this->wfs_describefeaturetype,$this->wfs_version);
-		}
+		return $jsString;
 	}
-	return true;
-}
 
-/**
-* creatObjfromDB
-*
-* this function fills the object with wfs information from db
-* 
-* @param int the id of wfs to get the information from
-*/ 
-function createObjFromDB($wfs_id){
-	global $DBSERVER,$DB,$OWNER,$PW;
-	$con = db_connect($DBSERVER,$OWNER,$PW);
-	db_select_db($DB,$con);
+	/**
+	 * For backwards compatibility only. Echoes a string directly.
+	 * 
+	 * @deprecated
+	 * @return 
+	 * @param $parent Boolean
+	 */
+	public function createJsObjFromWFS($parent){
+		echo $this->toJavaScript($parent);
+	}
 
-	$sql = "SELECT * FROM wfs WHERE wfs_id = $1;";
-	$v = array($wfs_id);
-	$t = array("i");
-	$res = db_prep_query($sql, $v, $t);
-	$cnt = 0;
-	while(db_fetch_row($res)){
-		$this->wfs_id = db_result($res, $cnt, "wfs_id");
-		$this->wfs_version = db_result($res, $cnt, "wfs_version");
-		$this->wfs_name = db_result($res, $cnt, "wfs_name");
-		$this->wfs_title = db_result($res, $cnt, "wfs_title");
-		$this->wfs_abstract = db_result($res, $cnt, "wfs_abstract");
-		$this->wfs_getcapabilities = db_result($res, $cnt, "wfs_getcapabilities");
-		$this->wfs_getcapabilities_doc = db_result($res, $cnt, "wfs_getcapabilities_doc");
-		$this->wfs_upload_url = db_result($res, $cnt, "wfs_upload_url");
-		$this->wfs_describefeaturetype = db_result($res, $cnt, "wfs_describefeaturetype");
-		$this->wfs_getfeature = db_result($res, $cnt, "wfs_getfeature");
-		$this->wfs_transaction = db_result($res, $cnt, "wfs_transaction");
-		$this->fees = db_result($res, $cnt, "fees");
-		$this->accessconstraints = db_result($res, $cnt, "accessconstraints");
-		$this->wfs_owner = db_result($res, $cnt, "wfs_owner");
-		$this->wfs_timestamp = db_result($res, $cnt, "wfs_timestamp");
-		
-		$sql_fe = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = $1 ORDER BY featuretype_id";
-		$v = array($this->wfs_id);
-		$t = array("i");
-		$res_fe = db_prep_query($sql_fe, $v, $t);
-		$cnt_fe = 0;
-		while(db_fetch_row($res_fe)){
-			$c = count($this->wfs_featuretype);
-//			$this->wfs_featuretype[$c]->featuretype_id = db_result($res_fe, $cnt_fe, "featuretype_id");
-			$this->wfs_featuretype[$c]->featuretype_name = db_result($res_fe, $cnt_fe, "featuretype_name");
-			$this->wfs_featuretype[$c]->featuretype_title = db_result($res_fe, $cnt_fe, "featuretype_title");
-			$this->wfs_featuretype[$c]->featuretype_abstract = db_result($res_fe, $cnt_fe, "featuretype_abstract");
-			$this->wfs_featuretype[$c]->featuretype_srs = db_result($res_fe, $cnt_fe, "featuretype_srs");
-			
-			$sql_el = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = $1 ORDER BY element_id";
-			$v = array(db_result($res_fe, $cnt_fe, "featuretype_id"));
-			$t = array("i");
-			$res_el = db_prep_query($sql_el, $v, $t);
-			$cnt_el = 0;
-			while(db_fetch_row($res_el)){
-				$z = count($this->wfs_featuretype[$c]->featuretype_element);
-				$this->wfs_featuretype[$c]->featuretype_element[$z]["name"] = db_result($res_el, $cnt_el, "element_name");
-				$this->wfs_featuretype[$c]->featuretype_element[$z]["type"] = db_result($res_el, $cnt_el, "element_type");
-				$cnt_el++;
-			}
-			$sql_ns = "SELECT * FROM wfs_featuretype_namespace WHERE fkey_featuretype_id = $1 ORDER BY namespace";
-			$v = array(db_result($res_fe, $cnt_fe, "featuretype_id"));
-			$t = array("i");
-			$res_ns = db_prep_query($sql_ns, $v, $t);
-			$cnt_ns = 0;
-			while(db_fetch_row($res_ns)){
-				$z = count($this->wfs_featuretype[$c]->featuretype_namespace);
-				$this->wfs_featuretype[$c]->featuretype_namespace[$z]["name"] = db_result($res_ns, $cnt_ns, "namespace");
-				$this->wfs_featuretype[$c]->featuretype_namespace[$z]["value"] = db_result($res_ns, $cnt_ns, "namespace_location");
-				$cnt_ns++;
-			}
-			$cnt_fe++;
-		}
-		$cnt++;
-    }
-}
-/** end createObjfromDB **/
+	// -----------------------------------------------------------------------
+	//
+	// Database interface
+	//
+	// -----------------------------------------------------------------------
+	
+	/**
+	 * Database wrapper function
+	 * 
+	 * @return Boolean
+	 */
+	public function insertOrUpdate () {
+		return WfsToDb::insertOrUpdate($this);
+	}
 
-	public function getallwfs($userid){
-		$this->wfs_id = array();
-		$this->wfs_name = array();
-		$this->wfs_title = array();
-		$this->wfs_abstract = array();
-		
-		global $DBSERVER,$DB,$OWNER,$PW;
-		$con = db_connect($DBSERVER,$OWNER,$PW);
-		db_select_db($DB,$con);
-		if($userid){
-		 	$sql = "SELECT * FROM wfs WHERE wfs_owner = $1";
-			$v = array($userid);
-			$t = array('i');
-			$res = db_prep_query($sql,$v,$t);
-		}
-		else{
-		 	$sql = "SELECT * FROM wfs";
-			$res = db_query($sql);
-		}
-		
-		$cnt = 0;
-		while ($row = db_fetch_array($res)){
-			$this->wfs_version[$cnt] = $row["wfs_version"];
-			$this->wfs_id[$cnt] = $row["wfs_id"];
-			$this->wfs_name[$cnt] = $row["wfs_name"];
-			$this->wfs_title[$cnt] = $row["wfs_title"];
-			$this->wfs_abstract[$cnt] = $row["wfs_abstract"];
-			$this->wfs_getcapabilities[$cnt] = $row["wfs_getcapabilities"];
-			$this->wfs_describefeaturetype[$cnt] = $row["wfs_describefeaturetype"];
-			$this->wfs_getfeature[$cnt] = $row["wfs_getfeature"];
-			$cnt++;
-		}	
+	/**
+	 * Database wrapper function
+	 * 
+	 * @return Boolean
+	 */
+	public function insert () {
+		return WfsToDb::insert($this);
 	}
-}
 
-
-class featuretype extends wfs{
-	var $featuretype_element = array();	
-	var $featuretype_namespace = array();	
+	/**
+	 * Database wrapper function
+	 * 
+	 * @return Boolean
+	 */
+	public function update () {
+		return WfsToDb::update($this);
+	}
 	
-	function featuretype($name,$title,$abstract,$srs,$url,$version){
+	/**
+	 * Database wrapper function
+	 * 
+	 * @return Boolean
+	 */
+	public function delete () {
+		return WfsToDb::delete($this);
+	}
 
-		$url .= "&SERVICE=WFS&VERSION=".$version."&REQUEST=DescribeFeatureType&TYPENAME=".$name;
-		
-		$this->featuretype_name = $name;
-		$this->featuretype_title = $title;
-		$this->featuretype_abstract = $abstract;
-		$this->featuretype_srs = $srs;
-		
-		$y = new connector($url);
-		$data = $y->file;
-				
-		#$data = implode("",file($url));
-		$parser = xml_parser_create();
-		xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
-		xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
-		xml_parse_into_struct($parser,$data,$values,$tags);
-		xml_parser_free($parser);
-		
-		foreach ($values as $element) {	
-			if($this->sepNameSpace($element[tag]) == "schema" && $element[type] == "open"){
-				$section = "namespace";
-//				echo "namespace<br>";
-			}
-			
-			if($section == "namespace"){		
-				while (list($k, $val) = each ($element[attributes])) {
-   					if (substr($k, 0, 5) == "xmlns") {
-						$cnt = count($this->featuretype_namespace);
-						$match = false;
-						for ($i = 0 ; $i < $cnt && $match == false ; $i++) {
-							if ($this->sepNameSpace($k) == $this->featuretype_namespace[$i]["name"] && $val == $this->featuretype_namespace[$i]["value"]) {
-								$match = true;
-							}
-						}
-						if ($match == false) {
-							$this->featuretype_namespace[$cnt]["name"] = $this->sepNameSpace($k);
-							$this->featuretype_namespace[$cnt]["value"] = $val;
-//							echo "namespace: " . $this->sepNameSpace($k) . " -> " . $val . "<br>";
-						}
-   					}
-				}
-			}
-			if($this->sepNameSpace($element[tag]) == "complexType" && $element[type] == "open"){
-				$section = "";
-			}
-			if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "open"){
-				$section = "complexcontent";
-//				echo "complexcontent<br>";
-			}
-			if($section == "complexcontent" && $this->sepNameSpace($element[tag]) == "element" && $element[attributes][name]){
-				$cnt = count($this->featuretype_element);
-				$this->featuretype_element[$cnt]["name"] = $element[attributes]["name"];
-				$this->featuretype_element[$cnt]["type"] = $this->sepNameSpace($element[attributes]["type"]);
-//				echo "element: ".$this->featuretype_element[$cnt]["name"]."<br>";
-			}
-			if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "close"){
-				$section = "";
-			}
-		}
+	/**
+	 * Database wrapper function
+	 * 
+	 * @return Boolean
+	 */
+	public function exists () {
+		return WfsToDb::exists($this);
 	}
-	function sepNameSpace($s){
-		$c = strpos($s,":"); 
-		if($c>0){
-			return substr($s,$c+1);
-		}
-		else{
-			return $s;
-		}		
-	}
 }
 ?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_wfsToDb.php
===================================================================
--- trunk/mapbender/http/classes/class_wfsToDb.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_wfsToDb.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,485 @@
+<?php
+# $Id: class_wfs.php 3094 2008-10-01 13:52:35Z christoph $
+# http://www.mapbender.org/index.php/class_wfs.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/class_connector.php");
+require_once(dirname(__FILE__)."/class_administration.php");
+require_once(dirname(__FILE__)."/class_wfs.php");
+
+class WfsToDb {
+
+	/**
+	 * Inserts a new or updates an existing WFS. Replaces the old wfs2db function.
+	 * 
+	 * @return Boolean
+	 * @param $aWfs Wfs
+	 */
+	public function insertOrUpdate ($aWfs) {
+		if (WfsToDb::exists($aWfs)) {
+			return WfsToDb::update($aWfs);
+		}
+		return WfsToDb::insert($aWfs);
+	}
+	
+	/**
+	 * Inserts a new WFS into the database.
+	 * 
+	 * @return Boolean
+	 * @param $aWfs Wfs
+	 */
+	public static function insert ($aWfs) {
+		db_begin();
+
+		$sql = "INSERT INTO wfs (wfs_version, wfs_name, wfs_title, wfs_abstract, ";
+		$sql .= "wfs_getcapabilities, wfs_getcapabilities_doc, wfs_upload_url, ";
+		$sql .= "wfs_describefeaturetype, wfs_getfeature, wfs_transaction, fees, ";
+		$sql .= "accessconstraints, wfs_owner, wfs_timestamp) ";
+		$sql .= "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)";
+	
+		$v = array(
+			$aWfs->version, 
+			$aWfs->name, 
+			$aWfs->title, 
+			$aWfs->summary, 
+			$aWfs->getCapabilities, 
+			$aWfs->getCapabilitiesDoc,
+			$aWfs->uploadUrl, 
+			$aWfs->describeFeatureType, 
+			$aWfs->getFeature,
+			$aWfs->transaction, 
+			$aWfs->fees, 
+			$aWfs->accessconstraints, 
+			$_SESSION["mb_user_id"], 
+			strtotime("now")
+		);
+			
+		$t = array('s', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 'i', 'i');
+	
+		$res = db_prep_query($sql, $v, $t);
+	
+		if (!$res) {
+			$e = new mb_exception("Error while inserting WFS into database.");
+			return false;
+		}
+
+		// set the WFS id
+		$aWfs->id = db_insert_id($con, 'wfs', 'wfs_id');
+		
+		// Insert the feature types
+		for ($i = 0; $i < count($aWfs->featureTypeArray); $i++) {
+			$currentFeatureType = $aWfs->featureTypeArray[$i];
+			if (!WfsToDb::insertFeatureType($currentFeatureType)) {
+				db_rollback();
+				return false;
+			}
+		}
+		db_commit();
+		return true;		
+	}
+	
+	/**
+	 * Updates an existing WFS in the database.
+	 * 
+	 * @return Boolean
+	 * @param $aWfs Wfs
+	 */
+	public static function update ($aWfs) {
+		db_begin();
+		
+		// update WFS
+		$sql = "UPDATE wfs SET wfs_version = $1, wfs_name = $2, wfs_title = $3, ";
+		$sql .= "wfs_abstract = $4, wfs_getcapabilities = $5, wfs_getcapabilities_doc = $6, ";
+		$sql .= "wfs_upload_url = $7, wfs_describefeaturetype = $8, wfs_getfeature = $9, ";
+		$sql .= "wfs_transaction = $10, fees = $11, accessconstraints = $12, wfs_owner = $13, ";
+		$sql .= "wfs_timestamp = $14 ";
+		$sql .= "WHERE wfs_id = $15";
+
+		$v = array(
+			$aWfs->version, 
+			$aWfs->name, 
+			$aWfs->title, 
+			$aWfs->summary,
+			$aWfs->getCapabilities, 
+			$aWfs->getCapabilitiesDoc, 
+			$aWfs->uploadUrl,
+			$aWfs->describeFeatureType, 
+			$aWfs->getFeature, 
+			$aWfs->transaction,
+			$aWfs->fees, 
+			$aWfs->accessconstraints, 
+			$_SESSION["mb_user_id"],
+			strtotime("now"), 
+			$aWfs->id
+		);
+			
+		$t = array('s', 's', 's', 's', 's', 's', 's', 's' ,'s' ,'s' ,'s' ,'s' ,'i' ,'i' ,'i');
+		$res = db_prep_query($sql, $v, $t);
+		if (!$res) {
+			$e = new mb_exception("Error while updating WFS in database.");
+			db_rollback();
+			return false;
+		}
+		
+		// update existing WFS feature types
+		$featureTypeNameArray = array();
+		for ($i = 0; $i < count($aWfs->featureTypeArray); $i++) {
+			$currentFeatureType = $aWfs->featureTypeArray[$i];
+			array_push($featureTypeNameArray, $currentFeatureType);
+			if (!WfsToDb::updateFeatureType($currentFeatureType)) {
+				db_rollback();
+				return false;
+			}
+		}		
+		
+		// delete obsolete WFS feature types
+		$v = array($aWfs->id);
+		$t = array("i");
+		$sql = "DELETE FROM wfs_featuretype WHERE wfs_id = $1 AND featuretype_name NOT IN (";
+		for ($i = 0; $i < count($featureTypeNameArray); $i++) {
+			if ($i > 0) {
+				$sql .= ", ";
+			}
+			$sql .= "$" . ($i+1);
+			array_push($v, $featureTypeNameArray);
+			array_push($t, "s");
+		}
+		$res = db_prep_query($sql,$v,$t);
+		if (!$res) {
+			$e = new mb_exception("Error while deleting obsolete WFS feature types in database.");
+			db_rollback();
+			return false;
+		}
+		db_commit();
+		return true;		
+	}
+	
+	
+	/**
+	 * Checks if a WFS exists in the database. 
+	 * 
+	 * @return Boolean
+	 * @param $aWfs Wfs
+	 */
+	public static function exists ($aWfs) {
+		// temporary WFS do not have a numeric ID
+		if (!is_numeric($aWfs->id)) {
+			return false;
+		}
+
+		// if ID is numeric, check if it exists in the database
+		$sql = "SELECT * FROM wfs WHERE wfs_id = $1;";
+		$v = array($aWfs->id);
+		$t = array("i");
+		$res = db_prep_query($sql, $v, $t);	
+		if ($row = db_fetch_array($res)) {
+			return true;
+		}
+		return false;
+	}
+	
+	/**
+	 * Delete a WFS from the database. Also sets the WFS object to null.
+	 * 
+	 * @return Boolean
+	 * @param $aWfs Wfs
+	 */
+	public static function delete ($aWfs) {
+		$sql = "DELETE FROM wfs WHERE wfs_id = $1";
+		$v = array($aWfs->id);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		if ($res) {
+			$aWfs = null;
+			return true;
+		}
+		return false;
+	}
+	
+
+
+	//-----------------------------------------------------------------------	
+	//
+	// PRIVATE
+	//
+	//-----------------------------------------------------------------------	
+	
+	private static function insertFeatureTypeNamespace ($aWfsId, $aWfsFeatureTypeId, $aWfsFeatureTypeNamespace) {
+		$sql = "INSERT INTO wfs_featuretype_namespace (fkey_wfs_id, " . 
+				"fkey_featuretype_id, namespace, namespace_location) " . 
+				"VALUES ($1, $2, $3, $4);"; 
+
+		$v = array(
+			$aWfsId, 
+			$aWfsFeatureTypeId, 
+			$aWfsFeatureTypeNamespace->name, 
+			$aWfsFeatureTypeNamespace->value
+		);
+		$t = array("s", "s", "s", "s");
+		$res = db_prep_query($sql, $v, $t);
+
+		if (!$res) {
+			$e = new mb_exception("Error while inserting WFS feature type namespace into the database.");
+			return false;
+		}
+		return true;
+	}
+	
+	/**
+	 * Inserts a new WFS feature type element into the database.
+	 * 
+	 * @return Boolean
+	 * @param $aWfsFeatureTypeId Integer
+	 * @param $aWfsFeatureTypeElement Object
+	 */
+	private static function insertFeatureTypeElement ($aWfsFeatureTypeId, $aWfsFeatureTypeElement) {
+		$sql = "INSERT INTO wfs_element (fkey_featuretype_id, element_name, " . 
+				"element_type) VALUES ($1, $2, $3)";
+		
+		$v = array(
+			$aWfsFeatureTypeId, 
+			$aWfsFeatureTypeElement->name, 
+			$aWfsFeatureTypeElement->type
+		);
+		$t = array("i", "s", "s");
+		
+		$res = db_prep_query($sql, $v, $t);
+		
+		if (!$res) {
+			$e = new mb_exception("Error while inserting WFS feature type element into the database.");
+			return false;
+		}
+		
+		// set the WFS feature type element ID
+		$aWfsFeatureTypeElement->id = db_insert_id("", "wfs_element", "element_id");
+		
+		return true;
+	}
+
+	/**
+	 * Updates an existing WFS feature type element in the database.
+	 * 
+	 * @return Boolean
+	 * @param $aWfsFeatureTypeId Integer
+	 * @param $aWfsFeatureTypeElement Object
+	 */
+	private static function updateFeatureTypeElement ($aWfsFeatureTypeId, $aWfsFeatureTypeElement) {
+		$sql = "UPDATE wfs_element SET element_type = $1 " . 
+				"WHERE element_id = $2 AND fkey_featuretype_id = $3";
+
+		$v = array(
+			$aWfsFeatureTypeElement->type, 
+			$aWfsFeatureTypeElement->id, 
+			$aWfsFeatureTypeId
+		);
+		$t = array("s", "i", "i");
+
+		$res = db_prep_query($sql, $v, $t);
+
+		if (!$res) {
+			$e = new mb_exception("Error while updating WFS feature type element in the database.");
+			return false;
+		}
+		
+		return true;
+	}
+
+	/**
+	 * Inserts a new WFS feature type into the database.
+	 * 
+	 * @return Boolean
+	 * @param $aWfsFeatureType WfsFeatureType
+	 */
+	private static function insertFeatureType ($aWfsFeatureType) {
+		$sql = "INSERT INTO wfs_featuretype (fkey_wfs_id, featuretype_name, " . 
+				"featuretype_title, featuretype_abstract, featuretype_srs) " . 
+				"VALUES($1, $2, $3, $4, $5)";
+
+		$v = array(
+			$aWfsFeatureType->wfs->id,
+			$aWfsFeatureType->name,
+			$aWfsFeatureType->title,
+			$aWfsFeatureType->summary,
+			$aWfsFeatureType->srs
+		);
+		$t = array('i','s','s','s','s');
+
+		$res = db_prep_query($sql,$v,$t);
+		if (!$res) {
+			$e = new mb_exception("Error while inserting WFS feature type into database.");
+			return false;	
+		}
+
+		// save the id of each featuretype
+		$aWfsFeatureType->id = db_insert_id("", "wfs_featuretype", "featuretype_id");
+
+		// insert feature type elements
+		for ($i = 0; $i < count($aWfsFeatureType->elementArray); $i++) {
+			$element = $aWfsFeatureType->elementArray[$i];
+			if (!WfsToDb::insertFeatureTypeElement($aWfsFeatureType->id, $element)) {
+				return false;	
+			}
+		}
+		
+		// insert feature type namespaces
+		for ($i = 0; $i < count($aWfsFeatureType->namespaceArray); $i++) {
+			$namespace = $aWfsFeatureType->namespaceArray[$i];
+			if (!WfsToDb::insertFeatureTypeNamespace($aWfsFeatureType->wfs->id, $aWfsFeatureType->id, $namespace)) {
+				return false;
+			}
+		}
+		return true;
+	}
+	
+	/**
+	 * Updates an existing WFS feature type in the database.
+	 * 
+	 * @return Boolean
+	 * @param $aWfsFeatureType WfsFeatureType
+	 */
+	private static function updateFeatureType ($aWfsFeatureType) {
+
+		$sql = "UPDATE wfs_featuretype SET ";
+		$sql .= "featuretype_title = $1,";
+		$sql .= "featuretype_abstract = $2,";
+		$sql .= "featuretype_srs = $3 ";
+		$sql .= "WHERE featuretype_id = $4";
+		$v = array(
+			$aWfsFeatureType->title,
+			$aWfsFeatureType->summary,
+			$aWfsFeatureType->srs,
+			$aWfsFeatureType->id
+		);
+		$t = array('s','s','s','i');
+
+		$res = db_prep_query($sql,$v,$t);
+		if (!$res ) {
+			$e = new mb_exception("Error while updating WFS feature type in database.");
+			return false;
+		}
+		
+		// update existing WFS feature type elements
+		$featureTypeElementNameArray = array();
+		for ($i = 0; $i < count($aWfsFeatureType->elementArray); $i++) {
+			$currentElement = $aWfsFeatureType->elementArray[$i];
+			array_push($featureTypeElementNameArray, $currentElement);
+			if (!WfsToDb::updateFeatureTypeElement($currentElement)) {
+				return false;
+			}
+		}		
+		
+		// delete obsolete WFS feature type elements
+		$v = array($aWfs->id);
+		$t = array("i");
+		$sql = "DELETE FROM wfs_element WHERE fkey_featuretype_id = $1 AND element_name NOT IN (";
+		for ($i = 0; $i < count($featureTypeElementNameArray); $i++) {
+			if ($i > 0) {
+				$sql .= ", ";
+			}
+			$sql .= "$" . ($i+1);
+			array_push($v, $featureTypeElementNameArray);
+			array_push($t, "s");
+		}
+		$res = db_prep_query($sql,$v,$t);
+		if (!$res) {
+			$e = new mb_exception("Error while deleting obsolete WFS feature type element in database.");
+			return false;
+		}
+
+		// delete all namespaces of this WFS feature type
+		$sql = "DELETE FROM wfs_featuretype_namespace WHERE ";
+		$sql .= "fkey_wfs_id = $1 AND fkey_featuretype_id = $2";
+		$v = array(
+			$aWfsFeatureType->wfs->id, 
+			$aWfsFeatureType->id
+		);
+		$t = array("i", "i");
+		$res = db_prep_query($sql, $v, $t);
+		if (!$res) {
+			$e = new mb_exception("Error while deleting WFS feature type namespaces from the database.");
+			return false;
+		}		
+		
+		// insert feature type namespaces
+		for ($i = 0; $i < count($aWfsFeatureType->namespaceArray); $i++) {
+			$namespace = $aWfsFeatureType->namespaceArray[$i];
+			if (!WfsToDb::insertFeatureTypeNamespace ($aWfsFeatureType->wfs->id, $aWfsFeatureType->id, $namespace)) {
+				$e = new mb_exception("Error while inserting WFS feature type namespaces into the database.");
+				return false;
+			}
+		}		
+		return true;		
+	}
+	
+	/**
+	 * Deletes an existing WFS feature type from the database.
+	 * 
+	 * @return Boolean
+	 * @param $aWfsFeatureType WfsFeatureType
+	 */
+	private static function deleteFeatureType ($aWfsFeatureType) {
+		$sql = "DELETE FROM wfs_featuretype WHERE featuretype_id = $1 AND fkey_wfs_id = $2";
+		$v = array($aWfsFeatureType->id, $aWfsFeatureType->wfs->id);
+		$t = array('i', 'i');
+
+		$res = db_prep_query($sql, $v, $t);
+		if (!$res) {
+			$e = new mb_exception("Error while deleting WFS feature type from database.");
+			return false;
+		}
+		return true;
+	}
+	
+	/**
+	 * Checks if a featuretype exists in the database. It selects the rows
+	 * that match the WFS id and the featuretype name.
+	 * 
+	 * If the featuretype is found the featuretype id is returned.
+	 * 
+	 * @return Integer
+	 * @param $aWfsFeatureType WfsFeatureType
+	 */
+	private static function getFeatureTypeId ($aWfsFeatureType) {
+		$sql = "SELECT featuretype_id FROM wfs_featuretype WHERE " . 
+			"fkey_wfs_id = $1 AND featuretype_name = $2";
+		$v = array(
+			$aWfsFeatureType->wfs->id,
+			$aWfsFeatureType->name,
+		);
+		$t = array("i", "s");
+		$res = db_prep_query($sql, $v, $t);
+		if ($row = db_fetch_array($res)) {
+			return $row["featuretype_id"];
+		}
+		return null;
+	}
+	
+	/**
+	 * Checks if a featuretype exists in the database. 
+	 * 
+	 * @return Boolean
+	 * @param $aWfsFeatureType WfsFeatureType
+	 */
+	private static function featureTypeExists ($aWfsFeatureType) {
+		if (WfsToDb::getFeatureTypeId($aWfsFeatureType) !== null) {
+			return true;
+		}
+		return false;
+	}
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_wfs_1_0.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_1_0.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_wfs_1_0.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,33 @@
+<?php
+# $Id: class_wfs.php 3094 2008-10-01 13:52:35Z christoph $
+# http://www.mapbender.org/index.php/class_wfs.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/class_connector.php");
+require_once(dirname(__FILE__)."/class_administration.php");
+require_once(dirname(__FILE__)."/class_wfs.php");
+
+class Wfs_1_0 extends Wfs {
+	const VERSION = "1.0.0";
+	
+	public function getVersion () {
+		return "1.0.0";
+	}
+}
+
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_wfs_1_0_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_1_0_factory.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_wfs_1_0_factory.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,198 @@
+<?php
+# $Id: class_wfs.php 3094 2008-10-01 13:52:35Z christoph $
+# http://www.mapbender.org/index.php/class_wfs.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_wfs_factory.php");
+require_once(dirname(__FILE__)."/../classes/class_wfs_1_0.php");
+require_once(dirname(__FILE__)."/../classes/class_wfs_featuretype.php");
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+
+/**
+ * Creates WFS 1.0 objects from a capabilities documents.
+ * 
+ * @return Wfs_1_0
+ */
+class Wfs_1_0_Factory extends WfsFactory {
+
+	private function createFeatureTypeFromXml ($xml, $myWfs) {
+		$newFeatureType = new Wfs_1_0_FeatureType($myWfs);
+
+		$admin = new administration();
+		$values = $admin->parseXml($xml);
+
+		foreach ($values as $element) {	
+			if ($this->sepNameSpace($element[tag]) == "schema" && $element[type] == "open") {
+				$section = "namespace";
+			}
+			
+			if ($section == "namespace" && is_array($element[attributes])) {	
+					
+				while (list($k, $val) = each ($element[attributes])) {
+   					if (substr($k, 0, 5) == "xmlns") {
+   						$key = $this->sepNameSpace($k);
+						$newFeatureType->addNamespace($key, $val);
+   					}
+				}
+			}
+			if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "open"){
+				$section = "complexcontent";
+			}
+			if($section == "complexcontent" && $this->sepNameSpace($element[tag]) == "element" && $element[attributes][name]){
+				$newFeatureType->addElement(
+					$element[attributes]["name"], 
+					$this->sepNameSpace($element[attributes]["type"])
+				);				
+			}
+			if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "close"){
+				$section = "";
+			}
+		}	
+		return $newFeatureType;	
+	}
+
+	private function createFeatureTypeFromUrl ($url, $aWfs) {
+		$xml = $this->getFromUrl($url);
+		return $this->createFeatureTypeFromXml ($xml, $aWfs);
+	}
+
+	/**
+	 * Creates WFS 1.0 objects from a capabilities documents.
+	 * 
+	 * @return Wfs_1_0
+	 * @param $xml String
+	 */
+	public function createFromXml ($xml) {
+		try {
+			
+			$myWfs = new Wfs_1_0();
+		
+			$admin = new administration();
+			$values = $admin->parseXml($xml);
+			
+			$myWfs->getCapabilitiesDoc = $admin->char_encode($xml);
+			$myWfs->id = $this->createId();
+		
+			foreach ($values as $element) {
+				$tag = strtoupper($element[tag]);
+
+				if($tag == "WFS_CAPABILITIES" && $element[type] == "open"){
+					$myWfs->version = $element[attributes][version];
+					if ($myWfs->version !== "1.0.0") {
+						throw new Exception("Not a WFS 1.0.0 capabilities document.");
+					}
+				}
+				if($tag == "NAME"  && $element[level] == '3'){
+					$myWfs->name = $element[value];
+				}
+				if($tag == "TITLE"  && $element[level] == '3'){
+					$myWfs->title = $this->stripEndlineAndCarriageReturn($element[value]);
+				}
+				if($tag == "ABSTRACT" && $element[level] == '3'){
+					$myWfs->summary = $this->stripEndlineAndCarriageReturn($element[value]);
+				}
+				if($tag == "FEES"){
+					$myWfs->fees = $element[value];
+				}
+				if($tag == "ACCESSCONSTRAINTS"){
+					$myWfs->accessconstraints = $element[value];
+				}
+				
+				# getCapabilities
+				if($tag == "GETCAPABILITIES" && $element[type] == "open"){
+					$section = "getcapabilities";
+				}
+				if($section == "getcapabilities" && $tag == "POST"){
+					$myWfs->getCapabilities = $element[attributes][onlineResource];
+				}
+				
+				# descriptFeatureType
+				if($tag == "DESCRIBEFEATURETYPE" && $element[type] == "open"){
+					$section = "describefeaturetype";
+					$myWfs->describeFeatureType = $element[attributes][onlineResource];
+					
+					
+				}
+				if($section == "describefeaturetype" && $tag == "POST"){
+					$myWfs->describeFeatureType = $element[attributes][onlineResource];
+				}
+				
+				# getFeature
+				if($tag == "GETFEATURE" && $element[type] == "open"){
+					$section = "getfeature";
+				}
+				if($section == "getfeature" && $tag == "POST"){
+					$myWfs->getFeature = $element[attributes][onlineResource];
+				}
+				if($tag == "GETFEATURE" && $element[type] == "close"){
+					$section = "";
+				}			
+				# transaction
+				if($tag == "TRANSACTION" && $element[type] == "open"){
+					$section = "transaction";
+				}
+				if($section == "transaction" && $tag == "POST"){
+					$myWfs->transaction = $element[attributes][onlineResource];
+				}
+				if($tag == "TRANSACTION" && $element[type] == "close"){
+					$section = "";
+				}
+				if($tag == "FEATURETYPE" && $element[type] == "open"){
+					$section = "featuretype";
+				}
+				if($section == "featuretype" && $tag == "NAME"){
+					$featuretype_name = $element[value];
+				}
+				if($section == "featuretype" && $tag == "TITLE"){
+					$featuretype_title = $this->stripEndlineAndCarriageReturn($element[value]);
+				}
+				if($section == "featuretype" && $tag == "ABSTRACT"){
+					$featuretype_abstract = $element[value];
+				}
+				if($section == "featuretype" && $tag == "SRS"){
+					$featuretype_srs = $element[value];
+
+					$describeFeatureTypeUrl = $myWfs->describeFeatureType . "&SERVICE=WFS&VERSION=" . 
+							$myWfs->version . "&REQUEST=DescribeFeatureType&TYPENAME=" . $this->sepNameSpace($featuretype_name);
+
+					$currentFeatureType = $this->createFeatureTypeFromUrl($describeFeatureTypeUrl, $myWfs);
+					if ($currentFeatureType !== null) {
+						$currentFeatureType->name = $this->sepNameSpace($featuretype_name);
+						$currentFeatureType->title = $featuretype_title;
+						$currentFeatureType->summary = $featuretype_abstract;
+						$currentFeatureType->srs = $featuretype_srs;
+
+						$myWfs->addFeatureType($currentFeatureType);
+					}
+				}
+			}
+			return $myWfs;
+		}
+		catch (Exception $e) {
+			$e = new mb_exception($e);
+			return null;
+		}
+	}
+	
+	public function createFromDb ($id) {
+		$myWfs = new Wfs_1_0();
+		return parent::createFromDb($id, $myWfs);
+	}
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_wfs_1_1.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_1_1.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_wfs_1_1.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,33 @@
+<?php
+# $Id: class_wfs.php 3094 2008-10-01 13:52:35Z christoph $
+# http://www.mapbender.org/index.php/class_wfs.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/class_connector.php");
+require_once(dirname(__FILE__)."/class_administration.php");
+require_once(dirname(__FILE__)."/class_wfs.php");
+
+class Wfs_1_1 extends Wfs {
+	const VERSION = "1.1.0";
+	
+	public function getVersion () {
+		return "1.1.0";
+	}
+}
+
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_wfs_1_1_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_1_1_factory.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_wfs_1_1_factory.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,199 @@
+<?php
+# $Id: class_wfs.php 3094 2008-10-01 13:52:35Z christoph $
+# http://www.mapbender.org/index.php/class_wfs.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_wfs_factory.php");
+require_once(dirname(__FILE__)."/../classes/class_wfs_1_1.php");
+require_once(dirname(__FILE__)."/../classes/class_wfs_featuretype.php");
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+
+/**
+ * Creates WFS 1.1 objects from a capabilities documents.
+ * 
+ * @return Wfs_1_1
+ */
+class Wfs_1_1_Factory extends WfsFactory {
+
+	private function createFeatureTypeFromXml ($xml, $myWfs) {
+		$newFeatureType = new Wfs_1_1_FeatureType($myWfs);
+
+		$admin = new administration();
+		$values = $admin->parseXml($xml);
+
+		foreach ($values as $element) {	
+			if ($this->sepNameSpace($element[tag]) == "schema" && $element[type] == "open") {
+				$section = "namespace";
+			}
+			
+			if ($section == "namespace" && is_array($element[attributes])) {	
+					
+				while (list($k, $val) = each ($element[attributes])) {
+   					if (substr($k, 0, 5) == "xmlns") {
+   						$key = $this->sepNameSpace($k);
+						$newFeatureType->addNamespace($key, $val);
+   					}
+				}
+			}
+			if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "open"){
+				$section = "complexcontent";
+			}
+			if($section == "complexcontent" && $this->sepNameSpace($element[tag]) == "element" && $element[attributes][name]){
+				$newFeatureType->addElement(
+					$element[attributes]["name"], 
+					$this->sepNameSpace($element[attributes]["type"])
+				);				
+			}
+			if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "close"){
+				$section = "";
+			}
+		}	
+		return $newFeatureType;	
+	}
+
+	private function createFeatureTypeFromUrl ($url, $aWfs) {
+		$xml = $this->getFromUrl($url);
+		return $this->createFeatureTypeFromXml ($xml, $aWfs);
+	}
+
+	/**
+	 * Creates WFS 1.0 objects from a capabilities documents.
+	 * 
+	 * @return Wfs_1_1
+	 * @param $xml String
+	 */
+	public function createFromXml ($xml) {
+		try {
+			
+			$myWfs = new Wfs_1_1();
+		
+			$admin = new administration();
+			$values = $admin->parseXml($xml);
+			
+			$myWfs->getCapabilitiesDoc = $admin->char_encode($xml);
+			$myWfs->id = $this->createId();
+		
+			foreach ($values as $element) {
+				$tag = $this->sepNameSpace(strtoupper($element[tag]));
+			
+				if($tag == "WFS_CAPABILITIES" && $element[type] == "open"){
+					$myWfs->version = $element[attributes][version];
+					if ($myWfs->version !== "1.1.0") {
+						throw new Exception("Not a WFS 1.1.0 capabilities document.");
+					}
+				}
+				if($tag == "NAME"  && $element[level] == '3'){
+					$myWfs->name = $element[value];
+				}
+				if($tag == "TITLE"  && $element[level] == '3'){
+					$myWfs->title = $this->stripEndlineAndCarriageReturn($element[value]);
+				}
+				if($tag == "ABSTRACT" && $element[level] == '3'){
+					$myWfs->summary = $this->stripEndlineAndCarriageReturn($element[value]);
+				}
+				if($tag == "FEES"){
+					$myWfs->fees = $element[value];
+				}
+				if($tag == "ACCESSCONSTRAINTS"){
+					$myWfs->accessconstraints = $element[value];
+				}
+				
+				if($tag == "OPERATION" && $element[type] == "open"){
+					switch ($element[attributes][name]) {
+						case "GetCapabilities" :
+							$section = "getcapabilities";
+							break;
+						case "DescribeFeatureType" :
+							$section = "describefeaturetype";
+							break;
+						case "GetFeature" :
+							$section = "getfeature";
+							break;
+						case "Transaction" :
+							$section = "transaction";
+							break;
+					}
+				}
+				# getCapabilities
+				if($section == "getcapabilities" && $tag == "POST"){
+					$myWfs->getCapabilities = html_entity_decode($element[attributes]["xlink:href"]);
+				}
+			
+				# descriptFeatureType
+				if($section == "describefeaturetype" && $tag == "POST"){
+					$myWfs->describeFeatureType = html_entity_decode($element[attributes]["xlink:href"]);
+				}
+				
+				# getFeature
+				if($section == "getfeature" && $tag == "POST"){
+					$myWfs->getFeature = html_entity_decode($element[attributes]["xlink:href"]);
+				}
+
+				# transaction
+				if($section == "transaction" && $tag == "POST"){
+					$myWfs->transaction = html_entity_decode($element[attributes]["xlink:href"]);
+				}
+
+				if($tag == "OPERATION" && $element[type] == "close"){
+					$section = "";	
+				}
+
+				if($tag == "FEATURETYPE" && $element[type] == "open"){
+					$section = "featuretype";
+				}
+				if($section == "featuretype" && $tag == "NAME"){
+					$featuretype_name = $element[value];
+				}
+				if($section == "featuretype" && $tag == "TITLE"){
+					$featuretype_title = $this->stripEndlineAndCarriageReturn($element[value]);
+				}
+				if($section == "featuretype" && $tag == "ABSTRACT"){
+					$featuretype_abstract = $element[value];
+				}
+				if($section == "featuretype" && $tag == "DEFAULTSRS"){
+					$featuretype_srs = $element[value];
+
+					$describeFeatureTypeUrl = $myWfs->describeFeatureType . "&SERVICE=WFS&VERSION=" . 
+							$myWfs->version . "&REQUEST=DescribeFeatureType&TYPENAME=" . $this->sepNameSpace($featuretype_name);
+
+					$currentFeatureType = $this->createFeatureTypeFromUrl($describeFeatureTypeUrl, $myWfs);
+					if ($currentFeatureType !== null) {
+						$currentFeatureType->name = $this->sepNameSpace($featuretype_name);
+						$currentFeatureType->title = $featuretype_title;
+						$currentFeatureType->summary = $featuretype_abstract;
+						$currentFeatureType->srs = $featuretype_srs;
+
+						$myWfs->addFeatureType($currentFeatureType);
+					}
+				}
+			}
+			return $myWfs;
+		}
+		catch (Exception $e) {
+			$e = new mb_exception($e);
+			return null;
+		}
+	}
+	
+	public function createFromDb ($id) {
+		$myWfs = new Wfs_1_1();
+		return parent::createFromDb($id, $myWfs);
+	}
+}
+?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_wfs_conf.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_conf.php	2009-01-30 14:01:20 UTC (rev 3509)
+++ trunk/mapbender/http/classes/class_wfs_conf.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -69,7 +69,7 @@
 					$idArray = array_intersect($idArray, $user->getWfsConfByPermission());
 				}
 
-				return $this->getWfsConfFromDbByArray($idArray);
+				return $this->getWfsConfFromDb($idArray);
 			}
 			// parameter is invalid
 			else {

Added: trunk/mapbender/http/classes/class_wfs_deprecated.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_deprecated.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_wfs_deprecated.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,830 @@
+<?php
+# $Id: class_wfs.php 3094 2008-10-01 13:52:35Z christoph $
+# http://www.mapbender.org/index.php/class_wfs.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+/**
+* class for wfs-objects
+*/
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/class_connector.php");
+require_once(dirname(__FILE__)."/class_administration.php");
+require_once(dirname(__FILE__)."/class_ows.php");
+
+abstract class Wfs extends Ows {
+}
+
+class wfs {
+
+  var $wfs_id;
+  var $wfs_version;
+  var $wfs_name;
+  var $wfs_title;
+  var $wfs_abstract;
+  var $wfs_getcapabilities;
+  var $wfs_getcapabilities_doc; //new SB 2007-08-09
+  var $wfs_describefeaturetype;
+  var $wfs_describefeaturetype_namespace = array();
+  var $wfs_getfeature;
+  var $wfs_transaction;
+  var $wfs_upload_url; //new SB 2007-08-09
+
+  //new WFS 1.0.0 -- SB 2007-08-06
+
+  var $fees;
+  var $accessconstraints;
+  
+  var $wfs_featuretype = array();
+ 
+ 
+function wfs() {
+
+} 
+/*
+function createObjFromXML($url){
+	
+	$x = new connector($url);
+	$data = $x->file;
+	#$data = implode("",file($url));
+	if(!$data){
+		echo "Unable to open document: ".$url;
+		die; 
+	}
+	
+	$values = null;
+	$tags = null;
+	$admin = new administration();
+	$this->wfs_getcapabilities_doc = $admin->char_encode($data);
+	$this->wfs_upload_url = $url;
+	
+	# for temporary wfs a id has to be created...
+	$this->wfs_id = "id_" . substr(md5(rand()),0,6);
+	$parser = xml_parser_create(CHARSET);
+	xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
+	xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
+	xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
+	xml_parse_into_struct($parser,$this->wfs_getcapabilities_doc,$values,$tags);
+	//xml_parse_into_struct($parser,$data,$values,$tags);
+	
+	xml_parser_free($parser);
+	
+	$section = false;
+	$request = false;
+	$featuretype_name = false;
+ 	$featuretype_title = false;
+ 	$featuretype_abstract = false;
+ 	$featuretype_srs = false;
+	
+	foreach ($values as $element) {
+	
+		if(strtoupper($element[tag]) == "WFS_CAPABILITIES" && $element[type] == "open"){
+			$this->wfs_version = $element[attributes][version];
+		}
+		if(strtoupper($element[tag]) == "NAME"  && $element[level] == '3'){
+			$this->wfs_name = $element[value];
+		}
+		if(strtoupper($element[tag]) == "TITLE"  && $element[level] == '3'){
+			$this->wfs_title = $this->stripEndlineAndCarriageReturn($element[value]);
+		}
+		if(strtoupper($element[tag]) == "ABSTRACT" && $element[level] == '3'){
+			$this->wfs_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
+		}
+		//new WFS 1.0.0 -- SB 2007-08-06
+		if(strtolower($element[tag]) == "fees"){
+			$this->fees = $element[value];
+		}
+		if(strtolower($element[tag]) == "accessconstraints"){
+			$this->accessconstraints = $element[value];
+		}
+		
+		
+		if($this->wfs_version == "1.0.0"){
+			
+			# getCapabilities
+			if(strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "open"){
+				$section = "getcapabilities";
+			}
+			if($section == "getcapabilities" && strtoupper($element[tag]) == "POST"){
+				$this->wfs_getcapabilities = $element[attributes][onlineResource];
+			}
+			
+			# descriptFeatureType
+			if(strtoupper($element[tag]) == "DESCRIBEFEATURETYPE" && $element[type] == "open"){
+				$section = "describefeaturetype";
+				$this->wfs_describefeaturetype = $element[attributes][onlineResource];
+				
+				
+			}
+			if($section == "describefeaturetype" && strtoupper($element[tag]) == "POST"){
+				$this->wfs_describefeaturetype = $element[attributes][onlineResource];
+			}
+			
+			# getFeature
+			if(strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "open"){
+				$section = "getfeature";
+			}
+			if($section == "getfeature" && strtoupper($element[tag]) == "POST"){
+				$this->wfs_getfeature = $element[attributes][onlineResource];
+			}
+			if(strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "close"){
+				$section = "";
+			}			
+			# transaction
+			if(strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "open"){
+				$section = "transaction";
+			}
+			if($section == "transaction" && strtoupper($element[tag]) == "POST"){
+				$this->wfs_transaction = $element[attributes][onlineResource];
+			}
+			if(strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "close"){
+				$section = "";
+			}
+		} 
+		if(strtoupper($element[tag]) == "FEATURETYPE" && $element[type] == "open"){
+			$section = "featuretype";
+		}
+		if($section == "featuretype" && strtoupper($element[tag]) == "NAME"){
+			$featuretype_name = $element[value];
+		}
+		if($section == "featuretype" && strtoupper($element[tag]) == "TITLE"){
+			$featuretype_title = $this->stripEndlineAndCarriageReturn($element[value]);
+		}
+		if($section == "featuretype" && strtoupper($element[tag]) == "ABSTRACT"){
+			$featuretype_abstract = $this->$element[value];
+		}
+		if($section == "featuretype" && strtoupper($element[tag]) == "SRS"){
+			$featuretype_srs = $element[value];
+			$this->addFeaturetype($featuretype_name,$featuretype_title,$featuretype_abstract,$featuretype_srs,$this->wfs_describefeaturetype,$this->wfs_version);
+		}
+	}
+}
+*/
+/*
+
+function displayWFS(){
+	echo "id: " . $this->wfs_id . " <br>";
+	echo "version: " . $this->wfs_version . " <br>";
+	echo "name: " . $this->wfs_name . " <br>";
+	echo "title: " . $this->wfs_title . " <br>";
+	echo "abstract: " . $this->wfs_abstract . " <br>";
+	echo "capabilitiesrequest: " . $this->wfs_getcapabilities . " <br>";
+	echo "describefeaturetype: " . $this->wfs_describefeaturetype . " <br>";
+	echo "getfeature: " . $this->wfs_getfeature . " <br>";
+	echo "transaction: " . $this->wfs_transaction . " <br>";
+	for($i=0; $i<count($this->wfs_featuretype); $i++){
+		echo "<hr>";
+		echo "name: ". $this->wfs_featuretype[$i]->featuretype_name . "<br>";
+		echo "title: ". $this->wfs_featuretype[$i]->featuretype_title . "<br>";
+		echo "abstract: ". $this->wfs_featuretype[$i]->featuretype_abstract . "<br>";
+		echo "srs: ". $this->wfs_featuretype[$i]->featuretype_srs . "<br>";
+		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
+			echo " element: " . $this->wfs_featuretype[$i]->featuretype_element[$j]["name"] ." - ".$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]."<br>";
+		}
+		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_namespace);$j++){
+			echo " namespace: " . $this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"] ." - ".$this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]."<br>";
+		}
+	}
+} 
+*/
+/*
+function addFeaturetype($name,$title,$abstract,$srs,$url,$version){
+	$this->wfs_featuretype[count($this->wfs_featuretype)] = new featuretype($name,$title,$abstract,$srs,$url,$version);
+}
+*/
+/*
+ function stripEndlineAndCarriageReturn($string) {
+	  	return preg_replace("/\n/", "", preg_replace("/\r/", " ", $string));
+	  }
+	 */
+	/*
+function createJsObjFromWFS($parent){
+	if(!$this->wfs_title || $this->wfs_title == ""){
+		echo "alert('Error: no valid capabilities-document !!');";
+		die; exit;
+	}
+		if($parent){
+			echo "parent.";
+		}
+		print("add_wfs('". 
+		$this->wfs_id ."','".
+		$this->wfs_version ."','".
+		$this->wfs_title ."','".
+		$this->wfs_abstract ."','". 
+		$this->wfs_getcapabilities ."','" .
+		$this->wfs_describefeaturetype ."');");
+		
+
+	for($i=0; $i<count($this->wfs_featuretype); $i++){
+		if($parent){
+			echo "parent.";
+		}
+		print ("wfs_add_featuretype('". 
+			$this->wfs_featuretype[$i]->featuretype_name ."','". 
+			$this->wfs_featuretype[$i]->featuretype_title . "','".
+			$this->wfs_featuretype[$i]->featuretype_abstract . "','".  
+			$this->wfs_featuretype[$i]->featuretype_srs ."','". 
+			$this->wfs_featuretype[$i]->featuretype_geomtype ."');");
+		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
+			if($parent){
+			echo "parent.";
+			}
+			print("wfs_add_featuretype_element('".$this->wfs_featuretype[$i]->featuretype_element[$j]["name"]."', '".$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]."', ".$j.", ".$i.");");
+		}
+		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_namespace);$j++){
+			if($parent){
+			echo "parent.";
+			}
+			print("wfs_add_featuretype_namespace('".$this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"]."', '".$this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]."', ".$j.", ".$i.");");
+		}
+	}
+}
+*/
+/**
+ * Inserts this WFS in the database
+ */
+/*
+function insertWfs() {
+	global $DBSERVER,$DB,$OWNER,$PW;
+	$con = db_connect($DBSERVER,$OWNER,$PW);
+	db_select_db($DB,$con);
+
+	$sql = "INSERT INTO wfs (wfs_version, wfs_name, wfs_title, wfs_abstract, ";
+	$sql .= "wfs_getcapabilities, wfs_getcapabilities_doc, wfs_upload_url, ";
+	$sql .= "wfs_describefeaturetype, wfs_getfeature, wfs_transaction, fees, ";
+	$sql .= "accessconstraints, wfs_owner, wfs_timestamp) ";
+	$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)";
+
+	$v = array($this->wfs_version, $this->wfs_name, $this->wfs_title, 
+		$this->wfs_abstract, $this->wfs_getcapabilities, $this->wfs_getcapabilities_doc,
+		$this->wfs_upload_url, $this->wfs_describefeaturetype, $this->wfs_getfeature,
+		$this->wfs_transaction, $this->fees, $this->accessconstraints, 
+		$_SESSION["mb_user_id"], strtotime("now"));
+		
+	$t = array('s', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 'i', 'i');
+
+	$res = db_prep_query($sql,$v,$t);
+
+	if(!$res){
+		db_rollback();
+		$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+		return false;
+	}
+	$this->wfs_id = db_insert_id($con,'wfs','wfs_id');
+	return true;
+}
+*/
+/*
+function updateWfs() {
+	global $DBSERVER,$DB,$OWNER,$PW;
+	$con = db_connect($DBSERVER,$OWNER,$PW);
+	db_select_db($DB,$con);
+
+	$sql = "UPDATE wfs SET wfs_version = $1, wfs_name = $2, wfs_title = $3, ";
+	$sql .= "wfs_abstract = $4, wfs_getcapabilities = $5, wfs_getcapabilities_doc = $6, ";
+	$sql .= "wfs_upload_url = $7, wfs_describefeaturetype = $8, wfs_getfeature = $9, ";
+	$sql .= "wfs_transaction = $10, fees = $11, accessconstraints = $12, wfs_owner = $13, ";
+	$sql .= "wfs_timestamp = $14 ";
+	$sql .= "WHERE wfs_id = $15";
+	//echo $sql."<br />";
+	$v = array($this->wfs_version, $this->wfs_name, $this->wfs_title, $this->wfs_abstract,
+		$this->wfs_getcapabilities, $this->wfs_getcapabilities_doc, $this->wfs_upload_url,
+		$this->wfs_describefeaturetype, $this->wfs_getfeature, $this->wfs_transaction,
+		$this->fees, $this->accessconstraints, $_SESSION["mb_user_id"],strtotime("now"), 
+		$this->wfs_id);
+		
+	$t = array('s', 's', 's', 's', 's', 's', 's', 's' ,'s' ,'s' ,'s' ,'s' ,'i' ,'i' ,'i');
+	$res = db_prep_query($sql,$v,$t);
+	if(!$res){
+		db_rollback();
+		$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+		return false;
+	}
+	return true;
+}
+*/
+/**
+* wfs2db
+*
+* this function saves the class information to the mapbender database 
+* @return boolean true if sucessful false otherwise
+*/
+
+
+/*
+function wfs2db($gui_id){
+	global $DBSERVER,$DB,$OWNER,$PW;
+	$con = db_connect($DBSERVER,$OWNER,$PW);
+	db_select_db($DB,$con);
+	
+	db_begin();
+	
+	// check if WFS already might exists (it might exist when wfs_id is numeric)
+	$wfs_exists = is_numeric($this->wfs_id);
+
+	// if it might exist, update it
+	if ($wfs_exists) {
+		// but check first if it really exists in the database
+		$sql = "SELECT * FROM wfs WHERE wfs_id = $1;";
+		$v = array($this->wfs_id);
+		$t = array("i");
+		$res = db_prep_query($sql, $v, $t);	
+		if($res){
+			$this->updateWfs();
+		}
+		// if not, insert as new WFS
+		else {
+			$this->insertWfs();
+		}
+	}
+	// if it does not exist, insert as new WFS
+	else {
+		$this->insertWfs();
+	}
+
+	# delete featuretypes from DB that does not exist and find the ids
+	$sql = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = $1;";
+	$v = array($this->wfs_id);
+	$t = array("i");
+	$res_ft = db_prep_query($sql, $v, $t);
+	$cnt = 0;
+	while(db_fetch_row($res_ft)){
+		$found = false;
+		for($i=0; $i<count($this->wfs_featuretype); $i++){
+			if($this->wfs_featuretype[$i]->featuretype_name == db_result($res_ft, $cnt, "featuretype_name")){
+				$this->wfs_featuretype[$i]->featuretype_id = db_result($res_ft, $cnt, "featuretype_id");
+				$found = true;
+				break;
+			}
+		}
+		
+		if(!$found){
+			$sql = "DELETE FROM wfs_featuretype WHERE featuretype_id = $1 AND fkey_wfs_id = $2";
+			$v = array(db_result($res_ft, $cnt, "featuretype_id"), $this->wfs_id);
+			$t = array('i','i');
+			//echo $sql."<br />";
+			$res = db_prep_query($sql,$v,$t);
+			if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+		}
+		$cnt++;
+	}
+	# TABLE wfs_featuretype
+	
+	for($i=0; $i<count($this->wfs_featuretype); $i++){
+		if(!$this->wfs_featuretype[$i]->featuretype_id){
+			$sql = "INSERT INTO wfs_featuretype(fkey_wfs_id, featuretype_name, featuretype_title, featuretype_abstract, featuretype_srs) ";
+			$sql .= "VALUES($1,$2,$3,$4,$5)";
+			$v = array($this->wfs_id,$this->wfs_featuretype[$i]->featuretype_name,$this->wfs_featuretype[$i]->featuretype_title,$this->wfs_featuretype[$i]->featuretype_abstract,$this->wfs_featuretype[$i]->featuretype_srs);
+			$t = array('i','s','s','s','s');
+			//echo $sql."<br />";
+			$res = db_prep_query($sql,$v,$t);
+			if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+			
+			# save the id of each featuretype: 
+			$this->wfs_featuretype[$i]->featuretype_id = db_insert_id($con,'wfs_featuretype','featuretype_id');
+		}
+		else{
+			$sql = "UPDATE wfs_featuretype SET ";
+			$sql .= "featuretype_title = $1,";
+			$sql .= "featuretype_abstract = $2,";
+			$sql .= "featuretype_srs = $3 ";
+			$sql .= "WHERE featuretype_id = $4";
+			$v = array($this->wfs_featuretype[$i]->featuretype_title,$this->wfs_featuretype[$i]->featuretype_abstract,$this->wfs_featuretype[$i]->featuretype_srs,$this->wfs_featuretype[$i]->featuretype_id);
+			$t = array('s','s','s','i');
+			//echo $sql."<br />";
+			$res = db_prep_query($sql,$v,$t);
+			if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+		}
+		//delete featuretype elements from db and find the ids
+		$sql = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = $1;";
+		$v = array($this->wfs_featuretype[$i]->featuretype_id);
+		$t = array("i");
+		$res_el = db_prep_query($sql, $v, $t);
+		$cnt = 0;
+		while(db_fetch_row($res_el)){
+			$found = false;
+			for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element); $j++){
+				if($this->wfs_featuretype[$i]->featuretype_element[$j]["name"] == db_result($res_el, $cnt, "element_name")){
+					$this->wfs_featuretype[$i]->featuretype_element[$j]["id"] = db_result($res_el, $cnt, "element_id");
+					$found = true;
+					break;
+				}
+			}
+			
+			if(!$found){
+				$sql = "DELETE FROM wfs_element WHERE element_id = $1 AND fkey_featuretype_id = $2";
+				$v = array(db_result($res_el, $cnt, "element_id"), $this->wfs_featuretype[$i]->featuretype_id);
+				$t = array('i','i');
+				//echo $sql."<br />";
+				$res = db_prep_query($sql,$v,$t);
+				if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+			}
+			$cnt++;
+		}
+
+		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
+			if(!$this->wfs_featuretype[$i]->featuretype_element[$j]["id"]){
+				$sql = "INSERT INTO wfs_element(fkey_featuretype_id, element_name,element_type) ";
+				$sql .= "VALUES($1, $2, $3);";
+				
+				$v = array($this->wfs_featuretype[$i]->featuretype_id, $this->wfs_featuretype[$i]->featuretype_element[$j]["name"], $this->wfs_featuretype[$i]->featuretype_element[$j]["type"]);
+				$t = array("s", "s", "s");
+				$res = db_prep_query($sql, $v, $t);
+				if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+			}
+			else{
+				$sql = "UPDATE wfs_element SET element_type = $1 ";
+				$sql .= "WHERE element_id = $2 AND ";
+				$sql .= "fkey_featuretype_id = $3;";
+				$v = array($this->wfs_featuretype[$i]->featuretype_element[$j]["type"], $this->wfs_featuretype[$i]->featuretype_element[$j]["id"], $this->wfs_featuretype[$i]->featuretype_id);
+				$t = array("s", "i", "i");
+				$res = db_prep_query($sql, $v, $t);
+				if (!$res) {
+					db_rollback();
+					$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+					return;
+				}
+			}
+		}
+
+		$sql = "DELETE FROM wfs_featuretype_namespace WHERE ";
+		$sql .= "fkey_wfs_id = $1 AND fkey_featuretype_id = $2";
+		$v = array($this->wfs_id, $this->wfs_featuretype[$i]->featuretype_id);
+		$t = array("i", "i");
+		$res = db_prep_query($sql, $v, $t);
+		if (!$res) {
+			db_rollback();
+			$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+			return;
+		}
+				
+		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_namespace);$j++){
+			$sql = "INSERT INTO wfs_featuretype_namespace ";
+			$sql .= "(fkey_wfs_id, fkey_featuretype_id, namespace, namespace_location) ";
+			$sql .= "VALUES ($1, $2, $3, $4);"; 
+
+			$v = array($this->wfs_id, $this->wfs_featuretype[$i]->featuretype_id, $this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"], $this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]);
+			$t = array("s", "s", "s", "s");
+			$res = db_prep_query($sql, $v, $t);
+
+			if (!$res) {
+				db_rollback();
+				$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+				return;
+			}
+		}
+	}
+	
+	# TABLE gui_wfs
+	/*
+	if($gui_id){
+		$sql ="INSERT INTO gui_wfs (fkey_gui_id, fkey_wfs_id)";
+		$sql .= "VALUES($1, $2);";
+		$v = array($gui_id, $this->wfs_id);
+		$t = array("s", "i");
+		$res = db_prep_query($sql, $v, $t);
+
+		if (!$res) {
+			db_rollback();
+			$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+			return;
+		}
+	}
+	//echo "Successfully saved!<br />";
+	db_commit();
+	
+	return true;
+}
+*/
+
+/**
+* updateObjFromXML
+*
+* this function regets the information from the xml (update)
+* @return boolean true if successful, false otherwise
+*/
+function updateObjFromXML($url){
+	$x = new connector($url);
+	$data = $x->file;
+	#$data = implode("",file($url));
+	if(!$data){
+		$e = new mb_exception("Unable to open document: ".$url);
+		return false; 
+	}
+	
+	$values = null;
+	$tags = null;
+	$admin = new administration();
+	$this->wfs_getcapabilities_doc = $admin->char_encode($data);
+	$this->wfs_featuretype = array();
+	$this->wfs_upload_url = $url;
+	
+	# for temporary wfs a id has to be created...
+	//$this->wfs_id = "id_" . substr(md5(rand()),0,6);
+	$parser = xml_parser_create(CHARSET);
+	xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
+	xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
+	xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
+	xml_parse_into_struct($parser,$this->wfs_getcapabilities_doc,$values,$tags);
+	//xml_parse_into_struct($parser,$data,$values,$tags);
+	
+	xml_parser_free($parser);
+	
+	$section = false;
+	$request = false;
+	$featuretype_name = false;
+ 	$featuretype_title = false;
+ 	$featuretype_abstract = false;
+ 	$featuretype_srs = false;
+	
+	foreach ($values as $element) {
+	
+		if(strtoupper($element[tag]) == "WFS_CAPABILITIES" && $element[type] == "open"){
+			$this->wfs_version = $element[attributes][version];
+		}
+		if(strtoupper($element[tag]) == "NAME"  && $element[level] == '3'){
+			$this->wfs_name = $element[value];
+		}
+/*		if(strtoupper($element[tag]) == "TITLE"  && $element[level] == '3'){
+			$this->wfs_title = $this->stripEndlineAndCarriageReturn($element[value]);
+		}
+		if(strtoupper($element[tag]) == "ABSTRACT" && $element[level] == '3'){
+			$this->wfs_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
+		}
+		//new WFS 1.0.0 -- SB 2007-08-06
+		if(strtolower($element[tag]) == "fees"){
+			$this->fees = $element[value];
+		}
+		if(strtolower($element[tag]) == "accessconstraints"){
+			$this->accessconstraints = $element[value];
+		}
+*/		
+		/*capability section*/
+		
+		if($this->wfs_version == "1.0.0"){
+			
+			# getCapabilities
+			if(strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "open"){
+				$section = "getcapabilities";
+			}
+			if($section == "getcapabilities" && strtoupper($element[tag]) == "POST"){
+				$this->wfs_getcapabilities = $element[attributes][onlineResource];
+			}
+			
+			# descriptFeatureType
+			if(strtoupper($element[tag]) == "DESCRIBEFEATURETYPE" && $element[type] == "open"){
+				$section = "describefeaturetype";
+				$this->wfs_describefeaturetype = $element[attributes][onlineResource];
+				
+				
+			}
+			if($section == "describefeaturetype" && strtoupper($element[tag]) == "POST"){
+				$this->wfs_describefeaturetype = $element[attributes][onlineResource];
+			}
+			
+			# getFeature
+			if(strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "open"){
+				$section = "getfeature";
+			}
+			if($section == "getfeature" && strtoupper($element[tag]) == "POST"){
+				$this->wfs_getfeature = $element[attributes][onlineResource];
+			}
+			if(strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "close"){
+				$section = "";
+			}			
+			# transaction
+			if(strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "open"){
+				$section = "transaction";
+			}
+			if($section == "transaction" && strtoupper($element[tag]) == "POST"){
+				$this->wfs_transaction = $element[attributes][onlineResource];
+			}
+			if(strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "close"){
+				$section = "";
+			}
+		} 
+		if(strtoupper($element[tag]) == "FEATURETYPE" && $element[type] == "open"){
+			$section = "featuretype";
+		}
+		if($section == "featuretype" && strtoupper($element[tag]) == "NAME"){
+			$featuretype_name = $element[value];
+		}
+		if($section == "featuretype" && strtoupper($element[tag]) == "TITLE"){
+			$featuretype_title = $this->stripEndlineAndCarriageReturn($element[value]);
+		}
+		if($section == "featuretype" && strtoupper($element[tag]) == "ABSTRACT"){
+			$featuretype_abstract = $this->$element[value];
+		}
+		if($section == "featuretype" && strtoupper($element[tag]) == "SRS"){
+			$featuretype_srs = $element[value];
+			$this->addFeaturetype($featuretype_name,$featuretype_title,$featuretype_abstract,$featuretype_srs,$this->wfs_describefeaturetype,$this->wfs_version);
+		}
+	}
+	return true;
+}
+
+/**
+* creatObjfromDB
+*
+* this function fills the object with wfs information from db
+* 
+* @param int the id of wfs to get the information from
+*/ 
+/*
+function createObjFromDB($wfs_id){
+	global $DBSERVER,$DB,$OWNER,$PW;
+	$con = db_connect($DBSERVER,$OWNER,$PW);
+	db_select_db($DB,$con);
+
+	$sql = "SELECT * FROM wfs WHERE wfs_id = $1;";
+	$v = array($wfs_id);
+	$t = array("i");
+	$res = db_prep_query($sql, $v, $t);
+	$cnt = 0;
+	while(db_fetch_row($res)){
+		$this->wfs_id = db_result($res, $cnt, "wfs_id");
+		$this->wfs_version = db_result($res, $cnt, "wfs_version");
+		$this->wfs_name = db_result($res, $cnt, "wfs_name");
+		$this->wfs_title = db_result($res, $cnt, "wfs_title");
+		$this->wfs_abstract = db_result($res, $cnt, "wfs_abstract");
+		$this->wfs_getcapabilities = db_result($res, $cnt, "wfs_getcapabilities");
+		$this->wfs_getcapabilities_doc = db_result($res, $cnt, "wfs_getcapabilities_doc");
+		$this->wfs_upload_url = db_result($res, $cnt, "wfs_upload_url");
+		$this->wfs_describefeaturetype = db_result($res, $cnt, "wfs_describefeaturetype");
+		$this->wfs_getfeature = db_result($res, $cnt, "wfs_getfeature");
+		$this->wfs_transaction = db_result($res, $cnt, "wfs_transaction");
+		$this->fees = db_result($res, $cnt, "fees");
+		$this->accessconstraints = db_result($res, $cnt, "accessconstraints");
+		$this->wfs_owner = db_result($res, $cnt, "wfs_owner");
+		$this->wfs_timestamp = db_result($res, $cnt, "wfs_timestamp");
+		
+		$sql_fe = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = $1 ORDER BY featuretype_id";
+		$v = array($this->wfs_id);
+		$t = array("i");
+		$res_fe = db_prep_query($sql_fe, $v, $t);
+		$cnt_fe = 0;
+		while(db_fetch_row($res_fe)){
+			$c = count($this->wfs_featuretype);
+//			$this->wfs_featuretype[$c]->featuretype_id = db_result($res_fe, $cnt_fe, "featuretype_id");
+			$this->wfs_featuretype[$c]->featuretype_name = db_result($res_fe, $cnt_fe, "featuretype_name");
+			$this->wfs_featuretype[$c]->featuretype_title = db_result($res_fe, $cnt_fe, "featuretype_title");
+			$this->wfs_featuretype[$c]->featuretype_abstract = db_result($res_fe, $cnt_fe, "featuretype_abstract");
+			$this->wfs_featuretype[$c]->featuretype_srs = db_result($res_fe, $cnt_fe, "featuretype_srs");
+			
+			$sql_el = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = $1 ORDER BY element_id";
+			$v = array(db_result($res_fe, $cnt_fe, "featuretype_id"));
+			$t = array("i");
+			$res_el = db_prep_query($sql_el, $v, $t);
+			$cnt_el = 0;
+			while(db_fetch_row($res_el)){
+				$z = count($this->wfs_featuretype[$c]->featuretype_element);
+				$this->wfs_featuretype[$c]->featuretype_element[$z]["name"] = db_result($res_el, $cnt_el, "element_name");
+				$this->wfs_featuretype[$c]->featuretype_element[$z]["type"] = db_result($res_el, $cnt_el, "element_type");
+				$cnt_el++;
+			}
+			$sql_ns = "SELECT * FROM wfs_featuretype_namespace WHERE fkey_featuretype_id = $1 ORDER BY namespace";
+			$v = array(db_result($res_fe, $cnt_fe, "featuretype_id"));
+			$t = array("i");
+			$res_ns = db_prep_query($sql_ns, $v, $t);
+			$cnt_ns = 0;
+			while(db_fetch_row($res_ns)){
+				$z = count($this->wfs_featuretype[$c]->featuretype_namespace);
+				$this->wfs_featuretype[$c]->featuretype_namespace[$z]["name"] = db_result($res_ns, $cnt_ns, "namespace");
+				$this->wfs_featuretype[$c]->featuretype_namespace[$z]["value"] = db_result($res_ns, $cnt_ns, "namespace_location");
+				$cnt_ns++;
+			}
+			$cnt_fe++;
+		}
+		$cnt++;
+    }
+}
+*/
+/** end createObjfromDB **/
+
+	public function getallwfs($userid){
+		$this->wfs_id = array();
+		$this->wfs_name = array();
+		$this->wfs_title = array();
+		$this->wfs_abstract = array();
+		
+		global $DBSERVER,$DB,$OWNER,$PW;
+		$con = db_connect($DBSERVER,$OWNER,$PW);
+		db_select_db($DB,$con);
+		if($userid){
+		 	$sql = "SELECT * FROM wfs WHERE wfs_owner = $1";
+			$v = array($userid);
+			$t = array('i');
+			$res = db_prep_query($sql,$v,$t);
+		}
+		else{
+		 	$sql = "SELECT * FROM wfs";
+			$res = db_query($sql);
+		}
+		
+		$cnt = 0;
+		while ($row = db_fetch_array($res)){
+			$this->wfs_version[$cnt] = $row["wfs_version"];
+			$this->wfs_id[$cnt] = $row["wfs_id"];
+			$this->wfs_name[$cnt] = $row["wfs_name"];
+			$this->wfs_title[$cnt] = $row["wfs_title"];
+			$this->wfs_abstract[$cnt] = $row["wfs_abstract"];
+			$this->wfs_getcapabilities[$cnt] = $row["wfs_getcapabilities"];
+			$this->wfs_describefeaturetype[$cnt] = $row["wfs_describefeaturetype"];
+			$this->wfs_getfeature[$cnt] = $row["wfs_getfeature"];
+			$cnt++;
+		}	
+	}
+}
+
+/*
+class featuretype extends wfs{
+	var $featuretype_element = array();	
+	var $featuretype_namespace = array();	
+	
+	function featuretype($name,$title,$abstract,$srs,$url,$version){
+
+		$url .= "&SERVICE=WFS&VERSION=".$version."&REQUEST=DescribeFeatureType&TYPENAME=".$name;
+		
+		$this->featuretype_name = $name;
+		$this->featuretype_title = $title;
+		$this->featuretype_abstract = $abstract;
+		$this->featuretype_srs = $srs;
+		
+		$y = new connector($url);
+		$data = $y->file;
+				
+		#$data = implode("",file($url));
+		$parser = xml_parser_create();
+		xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
+		xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
+		xml_parse_into_struct($parser,$data,$values,$tags);
+		xml_parser_free($parser);
+		
+		foreach ($values as $element) {	
+			if($this->sepNameSpace($element[tag]) == "schema" && $element[type] == "open"){
+				$section = "namespace";
+//				echo "namespace<br>";
+			}
+			
+			if($section == "namespace"){		
+				while (list($k, $val) = each ($element[attributes])) {
+   					if (substr($k, 0, 5) == "xmlns") {
+						$cnt = count($this->featuretype_namespace);
+						$match = false;
+						for ($i = 0 ; $i < $cnt && $match == false ; $i++) {
+							if ($this->sepNameSpace($k) == $this->featuretype_namespace[$i]["name"] && $val == $this->featuretype_namespace[$i]["value"]) {
+								$match = true;
+							}
+						}
+						if ($match == false) {
+							$this->featuretype_namespace[$cnt]["name"] = $this->sepNameSpace($k);
+							$this->featuretype_namespace[$cnt]["value"] = $val;
+//							echo "namespace: " . $this->sepNameSpace($k) . " -> " . $val . "<br>";
+						}
+   					}
+				}
+			}
+			if($this->sepNameSpace($element[tag]) == "complexType" && $element[type] == "open"){
+				$section = "";
+			}
+			if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "open"){
+				$section = "complexcontent";
+//				echo "complexcontent<br>";
+			}
+			if($section == "complexcontent" && $this->sepNameSpace($element[tag]) == "element" && $element[attributes][name]){
+				$cnt = count($this->featuretype_element);
+				$this->featuretype_element[$cnt]["name"] = $element[attributes]["name"];
+				$this->featuretype_element[$cnt]["type"] = $this->sepNameSpace($element[attributes]["type"]);
+//				echo "element: ".$this->featuretype_element[$cnt]["name"]."<br>";
+			}
+			if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "close"){
+				$section = "";
+			}
+		}
+	}
+	function sepNameSpace($s){
+		$c = strpos($s,":"); 
+		if($c>0){
+			return substr($s,$c+1);
+		}
+		else{
+			return $s;
+		}		
+	}
+}
+*/
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_wfs_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_factory.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_wfs_factory.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,142 @@
+<?php
+# $Id: class_wfs.php 3094 2008-10-01 13:52:35Z christoph $
+# http://www.mapbender.org/index.php/class_wfs.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+require_once(dirname(__FILE__)."/../classes/class_ows_factory.php");
+
+/**
+ * 
+ * @return 
+ * @param $xml String
+ */
+abstract class WfsFactory extends OwsFactory {
+	
+	/**
+	 * Parses the capabilities document for the WFS 
+	 * version number and returns it.
+	 * 
+	 * @return String
+	 * @param $xml String
+	 */
+	private function getVersionFromXml ($xml) {
+
+		$admin = new administration();
+		$values = $admin->parseXml($xml);
+		
+		foreach ($values as $element) {
+			if(strtoupper($element[tag]) == "WFS_CAPABILITIES" && $element[type] == "open"){
+				return $element[attributes][version];
+			}
+		}
+		throw new Exception("WFS version could not be determined from XML.");
+	}
+	
+	/**
+	 * Retrieves the data of a WFS from the database and initiates the object.
+	 * 
+	 * @return 
+	 * @param $id Integer
+	 * @param $aWfs Wfs is being created by the subclass
+	 */
+	public function createFromDb ($id) {
+		if (func_num_args() == 2) {
+			$aWfs = func_get_arg(1);
+		}
+		else {
+			return null;
+		}
+
+		// WFS
+		$sql = "SELECT * FROM wfs WHERE wfs_id = $1;";
+		$v = array($id);
+		$t = array("i");
+		$res = db_prep_query($sql, $v, $t);
+		$cnt = 0;
+		while(db_fetch_row($res)){
+			
+			$aWfs->id = db_result($res, $cnt, "wfs_id");
+			new mb_exception("WFS:".$aWfs->id);
+			$aWfs->name = db_result($res, $cnt, "wfs_name");
+			$aWfs->title = db_result($res, $cnt, "wfs_title");
+			$aWfs->summary = db_result($res, $cnt, "wfs_abstract");
+			$aWfs->getCapabilities = db_result($res, $cnt, "wfs_getcapabilities");
+			$aWfs->getCapabilitiesDoc = db_result($res, $cnt, "wfs_getcapabilities_doc");
+			$aWfs->uploadUrl = db_result($res, $cnt, "wfs_upload_url");
+			$aWfs->describeFeatureType = db_result($res, $cnt, "wfs_describefeaturetype");
+			$aWfs->getFeature = db_result($res, $cnt, "wfs_getfeature");
+			$aWfs->transaction = db_result($res, $cnt, "wfs_transaction");
+			$aWfs->fees = db_result($res, $cnt, "fees");
+			$aWfs->accessconstraints = db_result($res, $cnt, "accessconstraints");
+			$aWfs->owner = db_result($res, $cnt, "wfs_owner");
+			$aWfs->timestamp = db_result($res, $cnt, "wfs_timestamp");
+			
+			// Featuretypes
+			$sql_fe = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = $1 ORDER BY featuretype_id";
+			$v = array($aWfs->id);
+			$t = array("i");
+			$res_fe = db_prep_query($sql_fe, $v, $t);
+			$cnt_fe = 0;
+			
+			while(db_fetch_row($res_fe)){
+
+				$c = count($aWfs->featureTypeArray);
+				$aWfs->featureTypeArray[$c]->id = db_result($res_fe, $cnt_fe, "featuretype_id");
+				new mb_exception("FT:".$aWfs->featureTypeArray[$c]->id);
+				$aWfs->featureTypeArray[$c]->name = db_result($res_fe, $cnt_fe, "featuretype_name");
+				$aWfs->featureTypeArray[$c]->title = db_result($res_fe, $cnt_fe, "featuretype_title");
+				$aWfs->featureTypeArray[$c]->summary = db_result($res_fe, $cnt_fe, "featuretype_abstract");
+				$aWfs->featureTypeArray[$c]->srs = db_result($res_fe, $cnt_fe, "featuretype_srs");
+				
+				// Elements
+				$sql_el = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = $1 ORDER BY element_id";
+				$v = array($aWfs->featureTypeArray[$c]->id);
+				$t = array("i");
+				$res_el = db_prep_query($sql_el, $v, $t);
+				$cnt_el = 0;
+				while(db_fetch_row($res_el)){
+					$z = count($aWfs->featureTypeArray[$c]->elementArray);
+					$aWfs->featureTypeArray[$c]->elementArray[$z] = new stdClass();
+					$aWfs->featureTypeArray[$c]->elementArray[$z]->id = db_result($res_el, $cnt_el, "element_id");
+					$aWfs->featureTypeArray[$c]->elementArray[$z]->name = db_result($res_el, $cnt_el, "element_name");
+					$aWfs->featureTypeArray[$c]->elementArray[$z]->type = db_result($res_el, $cnt_el, "element_type");
+					$cnt_el++;
+				}
+
+				//Namespaces
+				$sql_ns = "SELECT * FROM wfs_featuretype_namespace WHERE fkey_featuretype_id = $1 ORDER BY namespace";
+				$v = array($aWfs->featureTypeArray[$c]->id);
+				$t = array("i");
+				$res_ns = db_prep_query($sql_ns, $v, $t);
+				$cnt_ns = 0;
+				while(db_fetch_row($res_ns)){
+					$z = count($aWfs->featureTypeArray[$c]->namespaceArray);
+					$aWfs->featureTypeArray[$c]->namespaceArray[$z] = new stdClass();
+					$aWfs->featureTypeArray[$c]->namespaceArray[$z]->name = db_result($res_ns, $cnt_ns, "namespace");
+					$aWfs->featureTypeArray[$c]->namespaceArray[$z]->value = db_result($res_ns, $cnt_ns, "namespace_location");
+					$cnt_ns++;
+				}
+				$cnt_fe++;
+			}
+			$cnt++;
+	    }
+		return $aWfs;	
+	}
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_wfs_featuretype.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_featuretype.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_wfs_featuretype.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -0,0 +1,115 @@
+<?php
+# $Id: class_wfs.php 3094 2008-10-01 13:52:35Z christoph $
+# http://www.mapbender.org/index.php/class_wfs.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/class_connector.php");
+require_once(dirname(__FILE__)."/class_administration.php");
+require_once(dirname(__FILE__)."/class_wfs.php");
+
+abstract class WfsFeatureType {
+	var $id;
+	var $name;
+	var $title;
+	var $summary;
+	var $srs;
+	var $wfs;
+	var $namespaceArray = array();
+	var $elementArray = array();
+
+	private function hasNamespace ($key, $value) {
+		for ($i = 0; $i < count($this->namespaceArray); $i++) {
+			if ($this->namespaceArray[$i]->name == $key && 
+				$this->namespaceArray[$i]->value == $value) 
+			{
+				return true;
+			}
+		}
+		return false;
+	}
+
+	public function addNamespace ($key, $value) {
+		if ($this->hasNamespace($key, $value)) {
+			return $this;
+		}
+		
+		$newNamespace = new stdClass();
+		$newNamespace->name = $key;
+		$newNamespace->value = $value;
+
+		array_push($this->namespaceArray, $newNamespace);
+
+		return $this;
+	}
+
+	public function addElement ($name, $type) {
+		$newElement = new stdClass();
+		$newElement->id = null;
+		$newElement->name = $name;
+		$newElement->type = $type;
+
+		array_push($this->elementArray, $newElement);
+
+		return $this;
+	}
+
+	public function toHtml () {
+		
+		$wfsString .= "<hr>";
+		$wfsString .= "name: ". $this->name . "<br>";
+		$wfsString .= "title: ". $this->title . "<br>";
+		$wfsString .= "abstract: ". $this->summary . "<br>";
+		$wfsString .= "srs: ". $this->srs . "<br>";
+
+		for ($j = 0; $j < count($this->elementArray); $j++) {
+			$currentElement = $this->elementArray[$j];
+			$wfsString .= " element: " . $currentElement->name . 
+							" - " . $currentElement->type . "<br>";
+		}
+
+		for ($j = 0; $j < count($this->namespaceArray); $j++) {
+			$currentNamespace = $this->namespaceArray[$j];
+			$wfsString .= " namespace: " . $currentNamespace->name . 
+							" - " . $currentNamespace->value . "<br>";
+		}
+		return $wfsString;
+	}
+
+	public function __toString () {
+		return $this->toHtml();
+	}
+}
+
+/**
+ * This class will be implemented only if needed
+ */
+class Wfs_1_0_FeatureType extends WfsFeatureType {
+	public function __construct ($aWfs) {
+		$this->wfs = $aWfs;
+	}
+}
+
+/**
+ * This class will be implemented only if needed
+ */
+class Wfs_1_1_FeatureType extends WfsFeatureType {
+	public function __construct ($aWfs) {
+		$this->wfs = $aWfs;
+	}
+}
+?>
\ No newline at end of file

Modified: trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php	2009-01-30 14:01:20 UTC (rev 3509)
+++ trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -548,11 +548,6 @@
 	if(queryGeom.geomType==geomType.polygon){
 		for(var i=0; i<js_wfs_conf_id.length; i++){
 			var srs = wfs_config[js_wfs_conf_id[i]]['featuretype_srs'];
-			var url = wfs_config[js_wfs_conf_id[i]]['wfs_getfeature'];
-			url += mb_getConjunctionCharacter(wfs_config[js_wfs_conf_id[i]]['wfs_getfeature']);
-			url += "service=wfs&request=getFeature&version=1.0.0";
-			url += "&typename="+ wfs_config[js_wfs_conf_id[i]]['featuretype_name'];
-			url += "&filter=";
 			var filter = "<ogc:Filter xmlns:ogc=\"http://ogc.org\" xmlns:gml=\"http://www.opengis.net/gml\">";
 
 			if(buttonPolygon.filteroption=='within'){
@@ -589,7 +584,7 @@
 			}
 
 			filter += '</ogc:Filter>';
-			mb_get_geom(url, filter, i, wfs_config[js_wfs_conf_id[i]]['featuretype_name'], js_wfs_conf_id[i], db_wfs_conf_id[i]);
+			mb_get_geom(filter, i, wfs_config[js_wfs_conf_id[i]]['featuretype_name'], js_wfs_conf_id[i], db_wfs_conf_id[i]);
 		}
 	}
 	else if(queryGeom.geomType==geomType.line){
@@ -599,9 +594,6 @@
 		}
 		for(var i=0; i<js_wfs_conf_id.length; i++){
 			var srs = wfs_config[js_wfs_conf_id[i]]['featuretype_srs'];
-			var url = wfs_config[js_wfs_conf_id[i]]['wfs_getfeature'];
-			url += mb_getConjunctionCharacter(wfs_config[js_wfs_conf_id[i]]['wfs_getfeature']);
-			param = "service=wfs&request=getFeature&version=1.0.0&typename="+ wfs_config[js_wfs_conf_id[i]]['featuretype_name']+"&filter=";
 			var filter = "<ogc:Filter xmlns:ogc='http://ogc.org' xmlns:gml='http://www.opengis.net/gml'>";
 
 			if(buttonRectangle.filteroption=='within'){
@@ -648,8 +640,7 @@
 			}
 
 			filter += "</ogc:Filter>";
-			url += param;
-			mb_get_geom(url, filter, i, wfs_config[js_wfs_conf_id[i]]['featuretype_name'], js_wfs_conf_id[i], db_wfs_conf_id[i]);
+			mb_get_geom(filter, i, wfs_config[js_wfs_conf_id[i]]['featuretype_name'], js_wfs_conf_id[i], db_wfs_conf_id[i]);
 		}
 	}
 	else if(queryGeom.geomType == geomType.point){
@@ -666,9 +657,6 @@
 		var realWorld4 = makeClickPos2RealWorldPos("mapframe1",mapPosXRemovePix,mapPosYAddPix);
 		for(var i=0; i<js_wfs_conf_id.length; i++){
 			var srs = wfs_config[js_wfs_conf_id[i]]['featuretype_srs'];
-			var url = wfs_config[js_wfs_conf_id[i]]['wfs_getfeature'];
-			url += mb_getConjunctionCharacter(wfs_config[js_wfs_conf_id[i]]['wfs_getfeature']);
-			param = "service=wfs&request=getFeature&version=1.0.0&typename="+ wfs_config[js_wfs_conf_id[i]]['featuretype_name']+"&filter=";
 			var filter = "<ogc:Filter xmlns:ogc='http://ogc.org' xmlns:gml='http://www.opengis.net/gml'>";
 			filter += "<Intersects><ogc:PropertyName>";
 			for(var j=0; j<wfs_config[js_wfs_conf_id[i]]['element'].length; j++){
@@ -680,25 +668,33 @@
 			filter += realWorld1[0] + "," + realWorld1[1] + " " + realWorld2[0] + "," + realWorld2[1] +  " ";
 			filter += realWorld3[0] + "," + realWorld3[1] + " " + realWorld4[0] + "," + realWorld4[1] + " " + realWorld1[0] + "," + realWorld1[1];
 			filter += "</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></Intersects></ogc:Filter>";
-			url += param;
-			mb_get_geom(url, filter, i, wfs_config[js_wfs_conf_id[i]]['featuretype_name'], js_wfs_conf_id[i], db_wfs_conf_id[i]);
+			mb_get_geom(filter, i, wfs_config[js_wfs_conf_id[i]]['featuretype_name'], js_wfs_conf_id[i], db_wfs_conf_id[i]);
 		}
 	}
 //	highlight = new Highlight(mb_wfs_targets, highlight_tag_id, {"position":"absolute", "top":"0px", "left":"0px", "z-index":generalHighlightZIndex}, generalHighlightLineWidth);
 	return true;
 }
 
-function mb_get_geom(url, filter, index, typename, js_wfs_conf_id, db_wfs_conf_id) {
+function mb_get_geom(filter, index, typename, js_wfs_conf_id, db_wfs_conf_id) {
 
-	mb_ajax_post("../" + wfsResultModulePath + wfsResultModuleFilename,{'url':url,'filter':filter,'typename':typename,'js_wfs_conf_id':js_wfs_conf_id, 'db_wfs_conf_id':db_wfs_conf_id},function(json,status){
-		var geom = new GeometryArray();
-		geom.importGeoJSON(json);
-		for (var i = 0; i < geom.count(); i++) {
-			geom.get(i).wfs_conf = parseInt(js_wfs_conf_id);
+	mb_ajax_post(
+		"../" + wfsResultModulePath + wfsResultModuleFilename,
+		{
+			'filter' : filter,
+			'typename' : typename,
+			'js_wfs_conf_id' : js_wfs_conf_id, 
+			'db_wfs_conf_id' : db_wfs_conf_id
+		},
+		function(json,status){
+			var geom = new GeometryArray();
+			geom.importGeoJSON(json);
+			for (var i = 0; i < geom.count(); i++) {
+				geom.get(i).wfs_conf = parseInt(js_wfs_conf_id);
+			}
+	
+			checkIfAllAjaxCallsFinished(geom);
 		}
-
-		checkIfAllAjaxCallsFinished(geom);
-	});
+	);
 }
 
 function checkIfAllAjaxCallsFinished (geom) {

Modified: trunk/mapbender/http/javascripts/mod_wfs_gazetteer_client.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_wfs_gazetteer_client.php	2009-01-30 14:01:20 UTC (rev 3509)
+++ trunk/mapbender/http/javascripts/mod_wfs_gazetteer_client.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -990,7 +990,15 @@
 			var filter = "<ogc:Filter xmlns:ogc='http://ogc.org' xmlns:gml='http://www.opengis.net/gml'>"+andConditions+"</ogc:Filter>";
 	
 			document.getElementById("res").innerHTML = "<table><tr><td><img src='../img/indicator_wheel.gif'></td><td>Searching...</td></tr></table>";
-			var parameters = {command:"getSearchResults", "wfs_conf_id":global_selectedWfsConfId, "frame":this.name, "url":u, "filter":filter, "backlink":""};
+			var parameters = {
+				"command" : "getSearchResults", 
+				"wfs_conf_id" : global_selectedWfsConfId, 
+				"typename" : global_wfsConfObj[global_selectedWfsConfId].featuretype_name,
+				"frame" : this.name, 
+				"url" : u, 
+				"filter" : filter, 
+				"backlink" : ""
+			};
 			parent.mb_ajax_get("../php/mod_wfs_gazetteer_server.php", parameters, function (jsCode, status) {
 				document.getElementById("res").innerHTML = "<table><tr><td>Arranging search results...</td></tr></table>";
 				

Modified: trunk/mapbender/http/php/mod_loadwfs.php
===================================================================
--- trunk/mapbender/http/php/mod_loadwfs.php	2009-01-30 14:01:20 UTC (rev 3509)
+++ trunk/mapbender/http/php/mod_loadwfs.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -19,15 +19,27 @@
 
 require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
 require_once(dirname(__FILE__)."/mb_validateInput.php");
-require_once(dirname(__FILE__)."/../classes/class_wfs.php"); 
+require_once(dirname(__FILE__)."/../classes/class_universal_wfs_factory.php"); 
+require_once(dirname(__FILE__)."/../classes/class_gui.php"); 
 
 echo "file: ".$_REQUEST["xml_file"];
 echo "<br>-------------------------------<br>";
 
 $guiList = mb_validateInput($_REQUEST["guiList"]);
-$xml = mb_validateInput($_REQUEST["xml_file"]);
-$mywms = new wfs();
-$mywms->createObjFromXML($xml);      
-$mywms->wfs2db($guiList);
-$mywms->displayWFS();
+$url = mb_validateInput($_REQUEST["xml_file"]);
+
+
+$myWfsFactory = new UniversalWfsFactory();
+$myWfs = $myWfsFactory->createFromUrl($url);      
+
+$myWfs->insertOrUpdate();
+
+// link WFS to GUIs in $guiList
+$guiArray = explode(",", $guiList);
+foreach ($guiArray as $appName) {
+	$currentApp = new gui($appName);	
+	$currentApp->addWfs($myWfs);
+}
+
+echo $myWfs;
 ?>
\ No newline at end of file

Modified: trunk/mapbender/http/php/mod_wfs_gazetteer_server.php
===================================================================
--- trunk/mapbender/http/php/mod_wfs_gazetteer_server.php	2009-01-30 14:01:20 UTC (rev 3509)
+++ trunk/mapbender/http/php/mod_wfs_gazetteer_server.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -18,10 +18,11 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
-require_once(dirname(__FILE__)."/../classes/class_gml2.php");
 require_once(dirname(__FILE__)."/../classes/class_json.php");
 require_once(dirname(__FILE__)."/../classes/class_administration.php");
 require_once(dirname(__FILE__)."/../classes/class_wfs_conf.php");
+require_once(dirname(__FILE__)."/../classes/class_universal_wfs_factory.php");
+require_once(dirname(__FILE__)."/../classes/class_universal_gml_factory.php");
 
 $command = $_REQUEST["command"];
 
@@ -104,6 +105,7 @@
 	$frame = $_REQUEST["frame"];
 	$filter = $_REQUEST["filter"];
 	$url = $_REQUEST["url"];
+	$typename = $_REQUEST["typename"];
 
 	/* wfs_conf */
 	$sql = "SELECT * FROM wfs_conf JOIN wfs ON wfs_conf.fkey_wfs_id = wfs.wfs_id ";
@@ -141,14 +143,30 @@
 	
 	$admin = new administration();
 	
-	$req = urldecode($url).urlencode($admin->char_decode(stripslashes($filter)));
-	$mygml = new gml2();
-	$mygml->parseFile($req);
+	$filter = $admin->char_decode(stripslashes($filter));
+
+	$sql = "SELECT fkey_wfs_id FROM wfs_conf WHERE wfs_conf_id = $1";
+	$v = array($wfs_conf_id);
+	$t = array('i');
+	$res = db_prep_query($sql, $v, $t);
+	$row = db_fetch_array($res);
+	$wfsId = $row["fkey_wfs_id"];
+
+	$myWfsFactory = new UniversalWfsFactory();
+	$myWfs = $myWfsFactory->createFromDb($wfsId);
+	$data = $myWfs->getFeature($typename, $filter);
+	if ($data === null) die('{}');
 	
+	$geomColumn = WfsConf::getGeomColumnNameByConfId($wfs_conf_id);
+
+	$gmlFactory = new UniversalGmlFactory();
+	$myGml = $gmlFactory->createFromXml($data);
+	$geoJson = $myGml->toGeoJSON();
+	
 	header("Content-type:application/x-json; charset=utf-8");
-	echo $mygml->toGeoJSON();
+	echo $geoJson;
 }
 else {
 	echo "please enter a valid command.";
 }
-?>
+?>
\ No newline at end of file

Modified: trunk/mapbender/http/php/mod_wfs_result.php
===================================================================
--- trunk/mapbender/http/php/mod_wfs_result.php	2009-01-30 14:01:20 UTC (rev 3509)
+++ trunk/mapbender/http/php/mod_wfs_result.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -20,11 +20,12 @@
 require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
 require_once(dirname(__FILE__) . "/../classes/class_stripRequest.php");
 require_once(dirname(__FILE__) . "/../classes/class_connector.php");
-require_once(dirname(__FILE__) . "/../classes/class_gml2.php");
 require_once(dirname(__FILE__)."/../classes/class_wfs_conf.php");
+require_once(dirname(__FILE__)."/../classes/class_wfs.php");
+require_once(dirname(__FILE__)."/../classes/class_universal_wfs_factory.php");
+require_once(dirname(__FILE__)."/../classes/class_universal_gml_factory.php");
 
 $filter = stripslashes($_REQUEST["filter"]);
-$url = stripslashes($_REQUEST["url"]);
 $db_wfs_conf_id = $_REQUEST["db_wfs_conf_id"];
 $typename = $_REQUEST["typename"];
 
@@ -84,15 +85,25 @@
 
 $filter = checkAccessConstraint($filter, $db_wfs_conf_id);
 
-$wfsRequest = $url . urlencode($filter);
-$connection = new connector($wfsRequest);
-$data = $connection->file;
-if (!$data) die('{}');
+$sql = "SELECT fkey_wfs_id FROM wfs_conf WHERE wfs_conf_id = $1";
+$v = array($db_wfs_conf_id);
+$t = array('i');
+$res = db_prep_query($sql, $v, $t);
+$row = db_fetch_array($res);
+$wfsId = $row["fkey_wfs_id"];
 
+
+$myWfsFactory = new UniversalWfsFactory();
+$myWfs = $myWfsFactory->createFromDb($wfsId);
+$data = $myWfs->getFeature($typename, $filter);
+
+if ($data === null) die('{}');
+
 $geomColumn = WfsConf::getGeomColumnNameByConfId($db_wfs_conf_id);
 
-$wfsResult = new gml2 ();
-$geoJson = $wfsResult->parseXML($data, $geomColumn);
+$gmlFactory = new UniversalGmlFactory();
+$myGml = $gmlFactory->createFromXml($data, geomColumn);
+$geoJson = $myGml->toGeoJSON();
 
 header('Content-type: text/html');
 echo $geoJson;

Modified: trunk/mapbender/http/php/mod_wfs_server.php
===================================================================
--- trunk/mapbender/http/php/mod_wfs_server.php	2009-01-30 14:01:20 UTC (rev 3509)
+++ trunk/mapbender/http/php/mod_wfs_server.php	2009-02-03 10:36:01 UTC (rev 3510)
@@ -3,6 +3,7 @@
 require_once(dirname(__FILE__)."/../classes/class_administration.php");
 require_once(dirname(__FILE__)."/../classes/class_wfs.php");
 require_once(dirname(__FILE__) . "/../classes/class_json.php");
+require_once(dirname(__FILE__) . "/../classes/class_universal_wfs_factory.php");
 
 $json = new Mapbender_JSON();
 $obj = $json->decode(stripslashes($_REQUEST['obj']));
@@ -251,11 +252,17 @@
  */
 function deleteWfs($obj){
 	//$obj->success = false;
-	$sql = "DELETE FROM wfs WHERE wfs_id = $1";
-	$v = array($obj->wfs);
-	$t = array('i');
-	$res = db_prep_query($sql,$v,$t);
-	$obj->success = true;
+	$id = $obj->wfs;
+	
+	$wfsFactory = new UniversalWfsFactory();
+	$myWfs = $wfsFactory->createFromDb($id);
+	if ($myWfs->delete()) {
+		$obj->success = true;
+	}
+	else {
+		$obj->success = false;
+	}
+	
 	return true;
 }
 



More information about the Mapbender_commits mailing list