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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Mar 2 04:10:11 EST 2009


Author: christoph
Date: 2009-03-02 04:10:10 -0500 (Mon, 02 Mar 2009)
New Revision: 3614

Modified:
   trunk/mapbender/http/classes/class_gml.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_factory.php
   trunk/mapbender/http/classes/class_gml_feature.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_locale.php
   trunk/mapbender/http/classes/class_ows.php
   trunk/mapbender/http/classes/class_universal_gml_factory.php
   trunk/mapbender/http/classes/class_wfs.php
   trunk/mapbender/http/classes/class_wfsToDb.php
   trunk/mapbender/http/classes/class_wfs_1_0.php
   trunk/mapbender/http/classes/class_wfs_1_1.php
   trunk/mapbender/http/classes/class_wfs_configuration.php
   trunk/mapbender/http/javascripts/geometry.js
   trunk/mapbender/http/javascripts/mod_digitize_tab.php
   trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php
   trunk/mapbender/http/php/mod_wfs_result.php
   trunk/mapbender/http/php/mod_wfs_server.php
   trunk/mapbender/lib/point.js
Log:
WFS 1.1

Modified: trunk/mapbender/http/classes/class_gml.php
===================================================================
--- trunk/mapbender/http/classes/class_gml.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_gml.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -24,7 +24,6 @@
 
 abstract class Gml {
 	var $featureCollection = null;
-	var $geomFeaturetypeElement;
 	var $doc;
 	
 	abstract public function toGml ();

Modified: trunk/mapbender/http/classes/class_gml_2_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_2_factory.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_gml_2_factory.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -69,7 +69,7 @@
 		}
 	}
 
-	public function parsePolygon ($domNode, $gmlPolygon) {
+	private function parsePolygon ($domNode, $gmlPolygon) {
 		$simpleXMLNode = simplexml_import_dom($domNode);
 
 		$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
@@ -80,10 +80,6 @@
 		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);
@@ -112,7 +108,7 @@
 		}
 	}
 
-	public function parseMultiLine ($domNode, $gmlMultiLine) {
+	private function parseMultiLine ($domNode, $gmlMultiLine) {
 		$simpleXMLNode = simplexml_import_dom($domNode);
 
 		$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
@@ -139,7 +135,7 @@
 		}
 	}		
 	
-	public function parseMultiPolygon ($domNode, $gmlMultiPolygon) {
+	private function parseMultiPolygon ($domNode, $gmlMultiPolygon) {
 //		echo $domNode->nodeName."<br>";
 		$simpleXMLNode = simplexml_import_dom($domNode);
 
@@ -232,13 +228,11 @@
 	 * @param $domNode DOMNodeObject the feature tag of the GML 
 	 * 								(<gml:featureMember> in the above example)
 	 */
-	protected function parseFeature($domNode, $feature) {
-		if (func_num_args() == 3) {
-			$feature->geomFeaturetypeElement = func_get_arg(2);
-		}
+	protected function parseFeature($domNode, $feature, $wfsConf) {
+		$geomFeaturetypeElement = $wfsConf->getGeometryColumnName();
 
-		$currentSibling = $domNode->firstChild;
-
+		$currentSibling = $domNode;
+		
 		$feature->fid = $currentSibling->getAttribute("fid");
 		
 		$currentSibling = $currentSibling->firstChild;
@@ -251,7 +245,7 @@
 			$namespace = $this->findNameSpace($name);
 			$ns = $namespace['ns'];
 			$columnName = $namespace['value'];
-			$isGeomColumn = ($feature->geomFeaturetypeElement == null || $columnName == $feature->geomFeaturetypeElement);
+			$isGeomColumn = ($geomFeaturetypeElement == null || $columnName == $geomFeaturetypeElement);
 			
 			// check if this node is a geometry node.
 			// however, even if it is a property node, 
@@ -260,35 +254,45 @@
 			// 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;
-					}
+				if ($geomNode->hasAttribute("srsName")) {
+					$srs = $geomNode->getAttribute("srsName");
+				}
+				$geomType = $geomNode->nodeName;
+				switch ($geomType) {
+					case "gml:Polygon" :
+						$feature->geometry = new GMLPolygon();
+						$feature->geometry->srs = $srs;
+						$this->parsePolygon($geomNode, $feature->geometry);
+						break;
+					case "gml:LineString" :
+						$feature->geometry = new GMLLine();
+						$feature->geometry->srs = $srs;
+						$this->parseLine($geomNode, $feature->geometry);
+						break;
+					case "gml:Point" :
+						$feature->geometry = new GMLPoint();
+						$feature->geometry->srs = $srs;
+						$this->parsePoint($geomNode, $feature->geometry);
+						break;
+					case "gml:MultiLineString" :
+						$feature->geometry = new GMLMultiLine();
+						$feature->geometry->srs = $srs;
+						$this->parseMultiLine($geomNode, $feature->geometry);
+						break;
+					case "gml:MultiPolygon" :
+						$feature->geometry = new GMLMultiPolygon();
+						$feature->geometry->srs = $srs;
+						$this->parseMultiPolygon($geomNode, $feature->geometry);
+						break;
+					default:
+						$feature->properties[$columnName] = $value;
+						break;
+				}
 			} 
 			else {
+				if ($currentSibling->hasChildNodes() && $currentSibling->firstChild instanceof DOMText) {
 					$feature->properties[$columnName] = $value;
+				}
 			}
 			
 			$currentSibling = $currentSibling->nextSibling;
@@ -302,13 +306,9 @@
 	 * @return Gml_2
 	 * @param $xml String
 	 */
-	public function createFromXml ($xml) {
+	public function createFromXml ($xml, $wfsConf) {
 		$gml2 = new Gml_2();
-		
-		if (func_num_args() == 2) {
-			$gml2->geomFeaturetypeElement = func_get_arg(1);
-		}
-		return parent::createFromXml($xml, $gml2);
+		return parent::createFromXml($xml, $wfsConf, $gml2);
 	}	
 }
 ?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_gml_3.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_3.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_gml_3.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -26,6 +26,16 @@
 
 	public function toGml () {
 		
+		$str = "";
+		foreach ($this->featureCollection->featureArray as $feature) {
+			if (!$feature->geometry) {
+				$e = new mb_exception("Feature doesn't have a geometry.");
+				return null;
+			}
+			$geometry = $feature->geometry;
+			$str .= $geometry->toGml3();
+		}
+		return $str;
 	}
 
 }

Modified: trunk/mapbender/http/classes/class_gml_3_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_3_factory.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_gml_3_factory.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -48,13 +48,9 @@
 	 * @return Gml_3
 	 * @param $xml String
 	 */
-	public function createFromXml ($xml) {
+	public function createFromXml ($xml, $wfsConf) {
 		$gml3 = new Gml_3();
-		
-		if (func_num_args() == 2) {
-			$gml3->geomFeaturetypeElement = func_get_arg(1);
-		}
-		return parent::createFromXml($xml, $gml3);
+		return parent::createFromXml($xml, $wfsConf, $gml3);
 	}	
 
 	protected function getDimensionFromNode ($domNode) {
@@ -98,7 +94,7 @@
 		}
 	}
 
-	public function parsePolygon ($domNode, $gmlPolygon) {
+	private function parsePolygon ($domNode, $gmlPolygon) {
 		$simpleXMLNode = simplexml_import_dom($domNode);
 
 		$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
@@ -140,12 +136,12 @@
 		}
 	}
 
-	public function parseMultiLine ($domNode, $gmlMultiLine) {
+	private function parseMultiLine ($domNode, $gmlMultiLine) {
 		$simpleXMLNode = simplexml_import_dom($domNode);
 
 		$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
 		
-		$allCoords = $simpleXMLNode->xpath("gml:curveMembers/gml:LineString/gml:posList");
+		$allCoords = $simpleXMLNode->xpath("gml:curveMember/gml:LineString/gml:posList");
 			
 		$cnt=0;
 		foreach ($allCoords as $Coords) {
@@ -165,13 +161,12 @@
 		}
 	}		
 	
-	public function parseMultiPolygon ($domNode, $gmlMultiPolygon) {
-//		echo $domNode->nodeName."<br>";
+	private function parseMultiPolygon ($domNode, $gmlMultiPolygon) {
 		$simpleXMLNode = simplexml_import_dom($domNode);
 
 		$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
 
-		$allPolygons = $simpleXMLNode->xpath("gml:surfaceMembers/gml:Polygon");
+		$allPolygons = $simpleXMLNode->xpath("gml:surfaceMember/gml:Polygon");
 		
 		$cnt=0;
 		foreach ($allPolygons as $polygon) {
@@ -268,17 +263,13 @@
 	 * @param $domNode DOMNodeObject the feature tag of the GML 
 	 * 								(<gml:featureMember> in the above example)
 	 */
-	protected function parseFeature($domNode, $feature) {
-		if (func_num_args() == 3) {
-			$feature->geomFeaturetypeElement = func_get_arg(2);
-		}
+	protected function parseFeature($domNode, $feature, $wfsConf) {
+		$geomFeaturetypeElement = $wfsConf->getGeometryColumnName();
 
+		$feature->fid = $domNode->getAttribute("gml:id");
+		
 		$currentSibling = $domNode->firstChild;
-
-		$feature->fid = $currentSibling->getAttribute("gml:id");
 		
-		$currentSibling = $currentSibling->firstChild;
-		
 		while ($currentSibling) {
 		
 			$name = $currentSibling->nodeName;
@@ -287,7 +278,7 @@
 			$namespace = $this->findNameSpace($name);
 			$ns = $namespace['ns'];
 			$columnName = $namespace['value'];
-			$isGeomColumn = ($feature->geomFeaturetypeElement == null || $columnName == $feature->geomFeaturetypeElement);
+			$isGeomColumn = ($geomFeaturetypeElement == null || $columnName == $geomFeaturetypeElement);
 			
 			// check if this node is a geometry node.
 			// however, even if it is a property node, 
@@ -296,35 +287,45 @@
 			// sophisticated here...
 			if ($currentSibling->hasChildNodes() && $isGeomColumn){
 				$geomNode = $currentSibling->firstChild; 
-					$geomType = $geomNode->nodeName;
-					switch ($geomType) {
-						case "gml:Polygon" :// untested!
-							$feature->geometry = new GMLPolygon();
-							$this->parsePolygon($geomNode, $feature->geometry);
-							break;
-						case "gml:LineString" :// untested!
-							$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:MultiCurve" :
-							$feature->geometry = new GMLMultiLine();
-							$this->parseMultiLine($geomNode, $feature->geometry);
-							break;
-						case "gml:MultiSurface" : 
-							$feature->geometry = new GMLMultiPolygon();
-							$this->parseMultiPolygon($geomNode, $feature->geometry);
-							break;
-						default:
-							$feature->properties[$columnName] = $value;
-							break;
-					}
+				$geomType = $geomNode->nodeName;
+				if ($geomNode->hasAttribute("srsName")) {
+					$srs = $geomNode->getAttribute("srsName");
+				}
+				switch ($geomType) {
+					case "gml:Polygon" :// untested!
+						$feature->geometry = new GMLPolygon();
+						$feature->geometry->srs = $srs;
+						$this->parsePolygon($geomNode, $feature->geometry);
+						break;
+					case "gml:LineString" :// untested!
+						$feature->geometry = new GMLLine();
+						$feature->geometry->srs = $srs;
+						$this->parseLine($geomNode, $feature->geometry);
+						break;
+					case "gml:Point" :
+						$feature->geometry = new GMLPoint();
+						$feature->geometry->srs = $srs;
+						$this->parsePoint($geomNode, $feature->geometry);
+						break;
+					case "gml:MultiCurve" :
+						$feature->geometry = new GMLMultiLine();
+						$feature->geometry->srs = $srs;
+						$this->parseMultiLine($geomNode, $feature->geometry);
+						break;
+					case "gml:MultiSurface" : 
+						$feature->geometry = new GMLMultiPolygon();
+						$feature->geometry->srs = $srs;
+						$this->parseMultiPolygon($geomNode, $feature->geometry);
+						break;
+					default:
+						$feature->properties[$columnName] = $value;
+						break;
+				}
 			} 
 			else {
+				if ($currentSibling->hasChildNodes() && $currentSibling->firstChild instanceof DOMText) {
 					$feature->properties[$columnName] = $value;
+				}
 			}
 			
 			$currentSibling = $currentSibling->nextSibling;

Modified: trunk/mapbender/http/classes/class_gml_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_factory.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_gml_factory.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -175,11 +175,25 @@
 	 * @return Gml
 	 * @param $xml String
 	 */
-	public function createFromXml ($xml, $gml) {
+	public function createFromXml ($xml, $wfsConf, $gml) {
 		try {
 			$xml = $this->removeWhiteSpace($xml);
 			$gmlDoc = new SimpleXMLElement($xml);
 			
+			// we need to find the name and namespaces of the featuretype 
+			// used in this WFS configuration
+			$wfsFactory = new UniversalWfsFactory();
+			$myWfs = $wfsFactory->createFromDb($wfsConf->wfsId);
+			$featureType = $myWfs->findFeatureTypeById($wfsConf->featureTypeId);
+			
+			// register namespace of feature type
+			$pos = strpos($featureType->name, ":");
+			if ($pos !== false) {
+				$ns = substr($featureType->name, 0, $pos);
+				$url = $featureType->getNamespace($ns);
+				$gmlDoc->registerXPathNamespace($ns, $url);
+			}
+			
 			$gmlDoc->registerXPathNamespace('xls', 'http://www.opengis.net/xls');
 			$gmlDoc->registerXPathNamespace('wfs', 'http://www.opengis.net/wfs');
 			$gmlDoc->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
@@ -188,24 +202,19 @@
 			$gml->featureCollection = new FeatureCollection();
 			
 			// segments of the featureCollection
-			$gmlFeatureMembers = $gmlDoc->xpath("//gml:featureMember");
+			$gmlFeatureMembers = $gmlDoc->xpath("//" . $featureType->name);
 			
-			if(count($gmlFeatureMembers)>0){
-				$cnt=0;
+			if (count($gmlFeatureMembers) > 0) {
 				foreach ($gmlFeatureMembers as $gmlFeatureMember) {
+					
+//					$e = new mb_exception($gmlFeatureMember->asXML());
 					$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);
-					}
+					$this->parseFeature($featureMember_dom, $feature, $wfsConf);
 					if (isset($feature->geometry)) {
 						$gml->featureCollection->addFeature($feature);
 					}
-					$cnt++;
 				}
 			}
 			return $gml;

Modified: trunk/mapbender/http/classes/class_gml_feature.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_feature.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_gml_feature.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -32,7 +32,6 @@
 	var $fid;
 	var $geometry = false;
 	var $properties = array();
-	var $geomFeaturetypeElement = null;
 	
 	public function __construct() {
 	}
@@ -40,7 +39,16 @@
 
 	public function toGeoJSON () {
 		$str = "";
-		$str .= "{\"type\":\"Feature\", \"id\":\"".$this->fid."\", \"geometry\": ";
+		$str .= "{\"type\":\"Feature\", \"id\":\"".$this->fid."\", \"crs\":";
+		
+		if (!$this->geometry || !$this->geometry->srs) {
+			$str .= "null, ";
+		}
+		else {
+			$str .= "{\"type\":\"name\", \"properties\":{\"name\":\"" . $this->geometry->srs . "\"}}, ";
+		}
+		
+		$str .= "\"geometry\": ";
 		if ($this->geometry) {
 			$str .= $this->geometry->toGeoJSON();
 		}

Modified: trunk/mapbender/http/classes/class_gml_line.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_line.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_gml_line.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -50,7 +50,18 @@
 	}
 	
 	public function toGml3 () {
-		
+		$str = "<gml:MultiCurve srsName=\"$this->srs\">" . 
+			"<gml:curveMember><gml:LineString>";
+
+		$ptArray = array();
+		foreach ($this->pointArray as $point) {
+			$ptArray[] = "<gml:pos>" . $point["x"] . " " . $point["y"] . "</gml:pos>";
+		}
+		$str .= implode("", $ptArray);
+
+		$str .= "</gml:LineString></gml:curveMember>";
+		$str .= "</gml:MultiCurve>";		
+		return $str;
 	}
 
 	public function toGeoJSON () {

Modified: trunk/mapbender/http/classes/class_gml_multiline.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_multiline.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_gml_multiline.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -50,6 +50,18 @@
 	}
 	
 	public function toGml3 () {
+		$str = "<gml:MultiCurve srsName='$srsName'>";
+		foreach ($this->lineArray as $line) {
+			$str .=	"<gml:curveMember><gml:LineString>";
+			$ptArray = array();
+			foreach ($line as $point) {
+				$ptArray[] = "<gml:pos>" . $point["x"] . " " . $point["y"] . "</gml:pos>";
+			}
+			$str .= implode("", $ptArray);
+			$str .= "</gml:LineString><gml:curveMember>";
+		}
+		$str .=	"<gml:MultiCurve>";
+		return $str;		
 		
 	}
 

Modified: trunk/mapbender/http/classes/class_gml_multipolygon.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_multipolygon.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_gml_multipolygon.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -48,7 +48,7 @@
 	}
 
 	public function toGml2 () {
-		$str .= "<gml:MultiPolygon srsName='$srsName'>";
+		$str = "<gml:MultiPolygon srsName='$this->srs'>";
 		for ($i = 0; $i < count($this->polygonArray); $i++) {
 			$str .= "<gml:polygonMember><gml:Polygon>" . 
 				"<gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";
@@ -87,6 +87,42 @@
 	}
 	
 	public function toGml3 () {
+		$str = "<gml:MultiSurface srsName='$this->srs'>";
+		for ($i = 0; $i < count($this->polygonArray); $i++) {
+			$str .= "<gml:surfaceMember><gml:Polygon>" . 
+				"<gml:exterior><gml:LinearRing>";
+
+			$currentExteriorRing = $this->polygonArray[$i];
+			
+			$ptArray = array();
+			for ($j = 0; $j < count($currentExteriorRing); $j++) {
+				$point = $currentExteriorRing[$j];
+				$ptArray[] = "<gml:pos>" . $point["x"] . " " . $point["y"] . "</gml:pos>";
+			}
+			$str .= implode("", $ptArray);
+			$str .= "</gml:LinearRing></gml:exterior>";
+			
+			// interior rings exist
+			if (count($this->innerRingArray) > $i && count($this->innerRingArray[$i]) > 0) {
+
+				for ($j = 0; $j < count($this->innerRingArray[$i]); $j++) {
+					$currentInteriorRing = $this->innerRingArray[$i][$j];
+					$str .= "<gml:interior><gml:LinearRing>";
+					$ptArray = array();
+					for ($k = 0; $k < count($currentInteriorRing); $k++) {
+						$point = $currentInteriorRing[$k];
+						$ptArray[] = "<gml:pos>" . $point["x"] . " " . $point["y"] . "</gml:pos>";
+					}
+					$str .= implode("", $ptArray);
+					$str .= "</gml:LinearRing></gml:interior>";
+				}
+
+			}
+			$str .= "</gml:Polygon></gml:surfaceMember>";
+		}
+		$str .= "</gml:MultiSurface>";
+
+		return $str;		
 		
 	}
 	

Modified: trunk/mapbender/http/classes/class_gml_point.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_point.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_gml_point.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -42,7 +42,10 @@
 	}
 	
 	public function toGml3 () {
-		
+		$str = "<gml:Point srsName='$this->srs'><gml:pos>";
+		$str .= $this->point["x"] . " " . $this->point["y"];
+		$str .= "</gml:pos></gml:Point>";
+		return $str;		
 	}
 
 	public function toGeoJSON () {

Modified: trunk/mapbender/http/classes/class_gml_polygon.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_polygon.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_gml_polygon.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -73,7 +73,30 @@
 	}
 	
 	public function toGml3 () {
-		
+		$str = "<gml:MultiSurface srsName=\"$this->srs\">" . 
+			"<gml:surfaceMember><gml:Polygon><gml:exterior>" . 
+			"<gml:LinearRing>";
+
+		$ptArray = array();
+		foreach ($this->pointArray as $point) {
+			$ptArray[] = "<gml:pos>" . $point["x"] . " " . $point["y"] . "</gml:pos>";
+		}
+		$str .= implode(" ", $ptArray);
+
+		$str .= '</gml:LinearRing></gml:exterior>';
+				
+		foreach ($this->innerRingArray as $ring) {
+			$str .= "<gml:interior><gml:LinearRing>";
+			$ptArray = array();
+			foreach ($ring as $point) {
+				$ptArray[] = "<gml:pos>" . $point["x"] . " " . $point["y"] . "</gml:pos>";
+			}
+			$str .= implode("", $ptArray);
+			
+			$str .= "</gml:LinearRing></gml:interior>";
+		}
+		$str .= "</gml:Polygon></gml:surfaceMember></gml:MultiSurface>";
+		return $str;
 	}
 	
 	public function toGeoJSON () {

Modified: trunk/mapbender/http/classes/class_locale.php
===================================================================
--- trunk/mapbender/http/classes/class_locale.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_locale.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -37,12 +37,12 @@
 
 	function Mb_locale($languageId) {
 		if (!$languageId) {
-		        $languageId = LANGUAGE;
+			$languageId = LANGUAGE;
 		}
 		$e = new Mb_notice("class_locale: setting locale to " . $languageId);
 		if (USE_I18N) {
 			if (!$this->setCurrentLocale($languageId)) {
-	    	    $e = new Mb_exception("Locale could not be set. Language ID: '" . $languageId . "'");
+				$e = new Mb_exception("Locale could not be set. Language ID: '" . $languageId . "'");
 			}
 		}
 		else {
@@ -51,12 +51,12 @@
 	}
 
     /**
-     * Get the current locale, evaluating GET/POST variables, browser languages
+	 * Get the current locale, evaluating GET/POST variables, browser languages
      * and a default locale (in that preference)
-     *
-     * @returns current locale
-     */
-    function setCurrentLocale($languageId) {
+	 *
+	 * @returns current locale
+	 */
+	function setCurrentLocale($languageId) {
 
 		// try to set the locale to $languageId
 		if ($this->checkAndSetLocale($languageId)) {
@@ -65,28 +65,28 @@
 		else {
 			$e = new Mb_notice("class_locale: no input parameter specified.");
 		}
-		
+
 		// determine the browser setting and try to set locale according to that
 		if ($this->browserLanguage == null) {
-	        $this->setBrowserLanguages();
+			$this->setBrowserLanguages();
 		}
 		foreach ($this->browserLanguages as $lang) {
-	        $e = new Mb_notice("trying browser setting " . $lang);
-	        if ($this->checkAndSetLocale($lang)) {
-                return true;
-	        }
+			$e = new Mb_notice("trying browser setting " . $lang);
+			if ($this->checkAndSetLocale($lang)) {
+				return true;
+			}
 		}
-		
+
 		// set to default language
 		$e = new Mb_notice("trying default language " . $this->defaultLanguage);
 		return $this->checkAndSetLocale($this->defaultLanguage);
 	}
 
 	/**
-	* checks if a locale is available; if yes, it is set via setlocale
-	*
-	* @returns true if the the locale is set successfully; otherwise false
-	*/
+	 * checks if a locale is available; if yes, it is set via setlocale
+	 *
+	 * @returns true if the the locale is set successfully; otherwise false
+	 */
 	function checkAndSetLocale($languageId) {
 		if ($this->os == null) {
 			$this->os = $this->guessHostOS();
@@ -168,43 +168,54 @@
          * determines the available Locales on this system
          */
         function setSystemLocales() {
-                $this->systemLocales['pt_PT'] = array('linux' => 'pt_PT.utf8',
-                                        'windows' => 'Portuguese_Portugal.1252',
-                                        'bsd' => 'pt_PT',
-                                        'posix' => 'pt_PT');
-                $this->systemLocales['fr_FR'] = array('linux' => 'fr_FR.utf8',
-                                        'windows' => 'French_France.1252',
-                                        'bsd' => 'fr_FR',
-                                        'posix' => 'fr_FR');
-                $this->systemLocales['es_ES'] = array('linux' => 'es_ES.utf8',
-                                        'windows' => 'Spanish_Spain.1252',
-                                        'bsd' => 'es_ES',
-                                        'posix' => 'es_ES');
-                $this->systemLocales['it_IT'] = array(
-										'linux' => 'it_IT.utf8',
-                                        'windows' => 'Italian_Italy.1252',
-                                        'bsd' => 'it_IT',
-                                        'posix' => 'it_IT');
-                $this->systemLocales['de_DE'] = array(
-										'linux' => 'de_DE.utf8',
-                                        'windows' => 'German_Germany.1252',
-                                        'bsd' => 'de_DE',
-                                        'posix' => 'de_DE');
-                $this->systemLocales['en_US'] = array(
-										'linux' => 'en_US.utf8',
-                                        'windows' => 'English_United States.1252',
-                                        'bsd' => 'en_US',
-                                        'posix' => 'en_US');
-                $this->systemLocales['bg_BG'] = array(
-										'linux' => 'bg_BG.utf8',
-                                        'windows' => 'Bulgarian_Bulgaria.1251',
-                                        'bsd' => 'bg_BG',
-                                        'posix' => 'bg_BG');
-                $this->systemLocales['el_GR'] = array(
-										'linux' => 'el_GR.utf8',
-                                        'windows' => 'Greek_Greece.1253',
-                                        'bsd' => 'el_GR',
-                                        'posix' => 'el_GR');
+			$this->systemLocales['pt_PT'] = array(
+				'linux' => 'pt_PT.utf8',
+				'windows' => 'Portuguese_Portugal.1252',
+				'bsd' => 'pt_PT',
+				'posix' => 'pt_PT'
+			);
+			$this->systemLocales['fr_FR'] = array(
+				'linux' => 'fr_FR.utf8',
+				'windows' => 'French_France.1252',
+				'bsd' => 'fr_FR',
+				'posix' => 'fr_FR'
+			);
+			$this->systemLocales['es_ES'] = array(
+				'linux' => 'es_ES.utf8',
+				'windows' => 'Spanish_Spain.1252',
+				'bsd' => 'es_ES',
+				'posix' => 'es_ES'
+			);
+			$this->systemLocales['it_IT'] = array(
+				'linux' => 'it_IT.utf8',
+				'windows' => 'Italian_Italy.1252',
+				'bsd' => 'it_IT',
+				'posix' => 'it_IT'
+			);
+			$this->systemLocales['de_DE'] = array(
+				'linux' => 'de_DE.utf8',
+				'windows' => 'German_Germany.1252',
+				'bsd' => 'de_DE',
+				'posix' => 'de_DE'
+			);
+			$this->systemLocales['en_US'] = array(
+				'linux' => 'en_US.utf8',
+				'windows' => 'English_United States.1252',
+				'bsd' => 'en_US',
+				'posix' => 'en_US'
+			);
+			$this->systemLocales['bg_BG'] = array(
+				'linux' => 'bg_BG.utf8',
+				'windows' => 'Bulgarian_Bulgaria.1251',
+				'bsd' => 'bg_BG',
+				'posix' => 'bg_BG'
+			);
+			$this->systemLocales['el_GR'] = array(
+				'linux' => 'el_GR.utf8',
+				'windows' => 'Greek_Greece.1253',
+				'bsd' => 'el_GR',
+				'posix' => 'el_GR'
+			);
         }
 
         /**

Modified: trunk/mapbender/http/classes/class_ows.php
===================================================================
--- trunk/mapbender/http/classes/class_ows.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_ows.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -47,6 +47,22 @@
 	
 	
 	/**
+	 * 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;
+	}
+	
+	/**
 	 * Get namespace from a tag name.
 	 * 
 	 * Example: input is "topp:the_geom" will return "topp".
@@ -88,5 +104,33 @@
 		// "?" doesn't exist, so the conunction character must be "?"
 		return "?";
 	}
+	
+	final protected function get ($url) {
+		$connection = new connector($url);
+		$e = new mb_notice("OWS REQUEST: " . $url);
+		$data = $connection->file;
+		if (!$data) {
+			$e = new mb_exception("OWS request returned no result: " . $url);
+			return null;
+		}
+		return $data;
+	}
+	
+	final protected function post ($url, $postData) {
+		$connection = new connector();
+		$connection->set("httpType", "post");
+		$connection->set("httpContentType", "xml");
+		$connection->set("httpPostData", $postData);
+		
+		$e = new mb_notice("OWS REQUEST: " . $url . "\n\n" . $postData);
+		$data = $connection->load($url);
+		if (!$data) {
+			$e = new mb_exception("OWS request returned no result: " . $url . "\n" . $postData);
+			return null;
+		}
+		return $data;
+	}
+	
+	
 }
 ?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_universal_gml_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_universal_gml_factory.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_universal_gml_factory.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -41,12 +41,12 @@
 		$simpleXml = simplexml_load_string($xml);
 		$simpleXml->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
 		
-		$nodeArray = $simpleXml->xpath("gml:featureMember//gml:posList");
+		$nodeArray = $simpleXml->xpath("//gml:posList");
 		if (count($nodeArray) > 0 ) {
 			return "3";
 		}
 
-		$nodeArray = $simpleXml->xpath("gml:featureMember//gml:pos");
+		$nodeArray = $simpleXml->xpath("//gml:pos");
 		if (count($nodeArray) > 0 ) {
 			return "3";
 		}
@@ -75,22 +75,24 @@
 	 * @return Wfs
 	 * @param $xml String
 	 */
-	public function createFromXml ($xml) {
+	public function createFromXml ($xml, $wfsConf) {
 		try {
 			$version = $this->getVersionFromXml($xml);
 
 			switch ($version) {
 				case "2":
+					$e = new mb_warning("Using GML2 Factory...");
 					$factory = new Gml_2_Factory();
 					break;
 				case "3":
+					$e = new mb_warning("Using GML3 Factory...");
 					$factory = new Gml_3_Factory();
 					break;
 				default:
 					throw new Exception("Unknown GML version " . $version);
 					break;
 			}
-			return $factory->createFromXml($xml);
+			return $factory->createFromXml($xml, $wfsConf);
 		}
 		catch (Exception $e) {
 			new mb_exception($e);

Modified: trunk/mapbender/http/classes/class_wfs.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_wfs.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -58,7 +58,7 @@
 		return null;
 	}
 	
-	protected function findFeatureTypeById ($id) {
+	public function findFeatureTypeById ($id) {
 		foreach ($this->featureTypeArray as $ft) {
 			if ($ft->id == $id) {
 				return $ft;
@@ -75,30 +75,9 @@
 				$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;
-		}
-		new mb_exception("Reply from WFS: " . $url . "\n\n" . $data);
-		return $data;
+		return $this->get($url);
 	}
 	
-	protected function post ($url, $postData) {
-		$connection = new connector();
-		$connection->set("httpType", "post");
-		$connection->set("httpContentType", "xml");
-		$connection->set("httpPostData", $postData);
-		
-		$data = $connection->load($url);
-		if (!$data) {
-			$e = new mb_exception("WFS request returned no result: " . $url . "\n" . $postData);
-			return null;
-		}
-		return $data;
-	}
-	
 	protected function getFeaturePost ($featureTypeName, $filter) {
 		$postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . 
 			"<wfs:GetFeature version=\"" . $this->getVersion() . "\" " . 
@@ -146,6 +125,7 @@
 		$featureType = $this->findFeatureTypeById($wfsConf->featureTypeId);
 		$featureTypeName = $featureType->name;
 		$geomColumnName = $wfsConf->getGeometryColumnName();
+		$authWfsConfElement = $wfsConf->getAuthElement();
 
 		//
 		// GML string
@@ -164,16 +144,15 @@
 		// so I just take the first from the collection.
 		$feature = $gmlObj->featureCollection->featureArray[0];
 
-
-		switch ($method) {
+		switch (strtolower($method)) {
 			case "delete":
-				$requestData = $this->transactionDelete($feature, $featureTypeName);
+				$requestData = $this->transactionDelete($feature, $featureTypeName, $authWfsConfElement);
 				break;
 			case "update":
-				$requestData = $this->transactionUpdate($feature, $featureTypeName, $gml, $geomColumnName);
+				$requestData = $this->transactionUpdate($feature, $featureTypeName, $authWfsConfElement, $gml, $geomColumnName);
 				break;
 			case "insert":
-				$requestData = $this->transactionInsert($feature, $featureTypeName, $gml, $geomColumnName);
+				$requestData = $this->transactionInsert($feature, $featureTypeName, $authWfsConfElement, $gml, $geomColumnName);
 				break;
 			default:
 				$e = new mb_exception("Invalid transaction method: " . $method);
@@ -184,7 +163,14 @@
 		return $this->post($this->transaction, $postData);
 	}
 	
-	protected function transactionInsert ($feature, $featureTypeName, $gml, $geomColumnName) {
+	protected function transactionInsert ($feature, $featureTypeName, $authWfsConfElement, $gml, $geomColumnName) {
+		// authentication
+		$authSegment = "";
+		if (!is_null($authWfsConfElement)) {
+			$user = eval("return " . $authWfsConfElement->authVarname . ";");
+			$authSegment = "<$authWfsConfElement->name>$user</$authWfsConfElement->name>";
+		}
+
 		// add properties
 		$propertiesSegment = "";
 		foreach ($feature->properties as $key => $value) {
@@ -196,11 +182,22 @@
 		// add spatial data
 		$geomSegment = "<$geomColumnName>" . $gml . "</$geomColumnName>";
 
-		return "<wfs:Insert><$featureTypeName>" . $propertiesSegment . 
-					$geomSegment . "</$featureTypeName></wfs:Insert>";
+		return "<wfs:Insert><$featureTypeName>" . $authSegment . 
+				$propertiesSegment . $geomSegment . 
+				"</$featureTypeName></wfs:Insert>";
 	}
 	
-	protected function transactionUpdate ($feature, $featureTypeName, $gml, $geomColumnName) {
+	protected function transactionUpdate ($feature, $featureTypeName, $authWfsConfElement, $gml, $geomColumnName) {
+		// authentication
+		$authSegment = "";
+		if (!is_null($authWfsConfElement)) {
+			$user = eval("return " . $authWfsConfElement->authVarname . ";");
+			$authSegment = "<ogc:PropertyIsEqualTo><ogc:PropertyName>" . 
+				$authWfsConfElement->name . "</ogc:PropertyName><ogc:Literal>" . 
+				$user . "</ogc:Literal></ogc:PropertyIsEqualTo>";
+
+		}
+
 		// add properties
 		$propertiesSegment = "";
 		foreach ($feature->properties as $key => $value) {
@@ -215,7 +212,11 @@
 			$e = new mb_exception("Feature ID not set.");
 			return null;
 		}
-		$filterSegment = "<ogc:Filter><ogc:FeatureId fid=\"$feature->fid\"/></ogc:Filter>";
+		$condition = $this->getFeatureIdFilter($feature->fid);
+		if ($authSegment !== "") {
+			$condition = "<And>" . $condition . $authSegment . "</And>";
+		}
+		$filterSegment = "<ogc:Filter>" . $condition . "</ogc:Filter>";
 
 		// add geometry
 		$geomSegment = "<wfs:Property><wfs:Name>$geomColumnName</wfs:Name>" . 
@@ -229,91 +230,80 @@
 				"</wfs:Update>";
 	}
 	
-	protected function transactionDelete ($feature, $featureTypeName) {
+	protected function getFeatureIdFilter ($fid) {
+	}
+	
+	protected function transactionDelete ($feature, $featureTypeName, $authWfsConfElement) {
+		// authentication
+		$authSegment = "";
+		if (!is_null($authWfsConfElement)) {
+			$user = eval("return " . $authWfsConfElement->authVarname . ";");
+			$authSegment = "<ogc:PropertyIsEqualTo><ogc:PropertyName>" . 
+				$authWfsConfElement->name . "</ogc:PropertyName><ogc:Literal>" . 
+				$user . "</ogc:Literal></ogc:PropertyIsEqualTo>";
+
+		}
+
 		// filter
 		if (!isset($feature->fid)) {
 			$e = new mb_exception("Feature ID not set.");
 			return null;
 		}
+		$condition = $this->getFeatureIdFilter($feature->fid);
+		if ($authSegment !== "") {
+			$condition = "<And>" . $condition . $authSegment . "</And>";
+		}
 
 		return "<wfs:Delete typeName=\"$featureTypeName\">" . 
-			"<ogc:Filter><ogc:FeatureId fid=\"$feature->fid\"/></ogc:Filter>" . 
+			"<ogc:Filter>" . $condition . "</ogc:Filter>" . 
 			"</wfs:Delete>";
 	}
 	
 	protected function wrapTransaction ($featureType, $wfsRequest) {
 		$featureNS = $this->getNameSpace($featureType->name);
 		
-		$str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . 
-			"<wfs:Transaction version=\"" . $this->getVersion() . 
-			"\" service=\"WFS\" ";
-
-		$ns_gml = false;
-		$ns_ogc = false;
-		$ns_xsi = false;
-		$ns_wfs = false;
-		$ns_featureNS = false;
-
+		$ns_gml = 'xmlns:gml="http://www.opengis.net/gml" ';	
+		$ns_ogc = 'xmlns:ogc="http://www.opengis.net/ogc" ';	
+		$ns_xsi = 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
+		$ns_featureNS = "xmlns:$featureNS=\"http://www.someserver.com/$featureNS\" ";	
+		$ns_wfs = "xmlns:wfs=\"http://www.opengis.net/wfs\" ";	
+		$strForSchemaLocation = "";
+		
 		foreach ($featureType->namespaceArray as $namespace) {
+			$n = $namespace->name;
+			$v = $namespace->value;
 
-			if ($namespace->name == "gml"){
-				 $ns_gml = true;
-				 $str .= "xmlns:" . $namespace->name . 
-				 	"=\"" . $namespace->value . "\" ";
+			if ($n === "gml") {
+				 $ns_gml = "xmlns:$n=\"$v\" ";
 			} 
-			else if ($namespace->name == "ogc") {
-				$ns_ogc = true;
-				$str .= "xmlns:" . $namespace->name . 
-					"=\"" . $namespace->value . "\" ";
+			else if ($n === "ogc") {
+				$ns_ogc = "xmlns:$n=\"$v\" ";
 			} 
-			else if ($namespace->name == "xsi") {
-				$ns_xsi = true;
-				$str .= "xmlns:" . $namespace->name . 
-					"=\"" . $namespace->value . "\" ";
+			else if ($n === "xsi") {
+				$ns_xsi = "xmlns:$n=\"$v\" ";
 			} 
-			else if ($namespace->name == "wfs") {
-				$ns_wfs = true;
-				$str .= "xmlns:" . $namespace->name . 
-					"=\"" . $namespace->value . "\" ";
+			else if ($n === "wfs") {
+				$ns_wfs = "xmlns:$n=\"$v\" ";
 			} 
-			else if ($namespace->name == $featureNS) {
-				$ns_featureNS = true;
-				$str .= "xmlns:" . $namespace->name .
-					"=\"" . $namespace->value . "\" ";
-				$strForSchemaLocation = $namespace->value;
+			else if ($n === $featureNS) {
+				$ns_featureNS = "xmlns:$n=\"$v\" ";
+				$strForSchemaLocation = $v;
 			}
 		}
 
-		if (!$ns_gml) {
-			$str .= 'xmlns:gml="http://www.opengis.net/gml" ';	
-		}
-		if (!$ns_ogc) {
-			$str .= 'xmlns:ogc="http://www.opengis.net/ogc" ';	
-		}
-		if (!$ns_xsi) {
-			$str .= 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
-		} 
-		if (!ns_featureNS) {
-			$str .= "xmlns:" . $featureNS . "=\"http://www.someserver.com/" . $featureNS . "\" ";	
-		}
-		if (!$ns_wfs) {
-			$str .= "xmlns:wfs=\"http://www.opengis.net/wfs\" ";	
-		}
-
-		$str .= "xsi:schemaLocation=\"http://www.opengis.net/wfs";
-		$str .= " http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd";
-		$str .= " " . $strForSchemaLocation;
-		$str .= " " . $this->describeFeatureType;
-		//$str .= mb_getConjunctionCharacter(myconf['wfs_describefeaturetype']);
-		//$str .= 'typename=' + myconf['featuretype_name'];
-		$str .= "\">";		
-		
-		$str .= $wfsRequest;
-		
-		$str .= "</wfs:Transaction>";
-		return $str;
+		return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . 
+			"<wfs:Transaction version=\"" . $this->getVersion() . 
+			"\" service=\"WFS\" " . $ns_gml . $ns_ogc . $ns_xsi . 
+			$ns_featureNS . $ns_wfs . 
+			"xsi:schemaLocation=\"http://www.opengis.net/wfs" . 
+			" http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd " . 
+			$strForSchemaLocation . " " . $this->describeFeatureType . 
+			$this->getConjunctionCharacter($this->describeFeatureType) . 
+			"typename=" . $featureType->name . 
+			"\">" .	$wfsRequest . "</wfs:Transaction>";
 	}
 	
+	
 	// -----------------------------------------------------------------------
 	//
 	// Output formats

Modified: trunk/mapbender/http/classes/class_wfsToDb.php
===================================================================
--- trunk/mapbender/http/classes/class_wfsToDb.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_wfsToDb.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -53,7 +53,7 @@
 		$sql .= "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)";
 	
 		$v = array(
-			$aWfs->version, 
+			$aWfs->getVersion(), 
 			$aWfs->name, 
 			$aWfs->title, 
 			$aWfs->summary, 
@@ -106,12 +106,12 @@
 		$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";
+		$sql .= "wfs_transaction = $10, fees = $11, accessconstraints = $12, ";
+		$sql .= "wfs_timestamp = $13 ";
+		$sql .= "WHERE wfs_id = $14";
 
 		$v = array(
-			$aWfs->version, 
+			$aWfs->getVersion(), 
 			$aWfs->name, 
 			$aWfs->title, 
 			$aWfs->summary,
@@ -123,12 +123,12 @@
 			$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');
+		$t = array('s', 's', 's', 's', 's', 's', 's', 's' ,'s' ,'s' ,'s' ,'s', 'i' ,'i');
+		$e = new mb_exception($sql . " " . print_r($v, true));
 		$res = db_prep_query($sql, $v, $t);
 		if (!$res) {
 			$e = new mb_exception("Error while updating WFS in database.");
@@ -150,15 +150,21 @@
 		// 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 (";
+		$sql = "DELETE FROM wfs_featuretype WHERE fkey_wfs_id = $1";
+		$sql_in = "";
 		for ($i = 0; $i < count($featureTypeNameArray); $i++) {
 			if ($i > 0) {
-				$sql .= ", ";
+				$sql_in .= ", ";
 			}
-			$sql .= "$" . ($i+1);
-			array_push($v, $featureTypeNameArray);
+			$sql_in .= "$" . ($i+2);
+			array_push($v, $featureTypeNameArray[$i]->name);
 			array_push($t, "s");
 		}
+		if ($sql_in !== "") {
+			$sql .=  " AND featuretype_name NOT IN (" . $sql_in . ")";
+		}
+		
+		$e = new mb_exception($sql . " " . print_r($v, true));
 		$res = db_prep_query($sql,$v,$t);
 		if (!$res) {
 			$e = new mb_exception("Error while deleting obsolete WFS feature types in database.");
@@ -231,6 +237,7 @@
 			$aWfsFeatureTypeNamespace->value
 		);
 		$t = array("s", "s", "s", "s");
+		$e = new mb_exception($sql . " " . print_r($v, true));
 		$res = db_prep_query($sql, $v, $t);
 
 		if (!$res) {
@@ -289,6 +296,7 @@
 		);
 		$t = array("s", "i", "i");
 
+		$e = new mb_exception($sql . " " . print_r($v, true));
 		$res = db_prep_query($sql, $v, $t);
 
 		if (!$res) {
@@ -367,8 +375,10 @@
 		);
 		$t = array('s','s','s','i');
 
+		$e = new mb_exception($sql . " " . print_r($v, true));
+
 		$res = db_prep_query($sql,$v,$t);
-		if (!$res ) {
+		if (!$res) {
 			$e = new mb_exception("Error while updating WFS feature type in database.");
 			return false;
 		}
@@ -378,23 +388,29 @@
 		for ($i = 0; $i < count($aWfsFeatureType->elementArray); $i++) {
 			$currentElement = $aWfsFeatureType->elementArray[$i];
 			array_push($featureTypeElementNameArray, $currentElement);
-			if (!WfsToDb::updateFeatureTypeElement($currentElement)) {
+			if (!WfsToDb::updateFeatureTypeElement($aWfsFeatureType->id, $currentElement)) {
 				return false;
 			}
 		}		
 		
 		// delete obsolete WFS feature type elements
-		$v = array($aWfs->id);
+		$v = array($aWfsFeatureType->id);
 		$t = array("i");
-		$sql = "DELETE FROM wfs_element WHERE fkey_featuretype_id = $1 AND element_name NOT IN (";
+		$sql = "DELETE FROM wfs_element WHERE fkey_featuretype_id = $1";
+
+		$sql_in = "";
 		for ($i = 0; $i < count($featureTypeElementNameArray); $i++) {
 			if ($i > 0) {
-				$sql .= ", ";
+				$sql_in .= ", ";
 			}
-			$sql .= "$" . ($i+1);
-			array_push($v, $featureTypeElementNameArray);
+			$sql_in .= "$" . ($i+2);
+			array_push($v, $featureTypeElementNameArray[$i]->name);
 			array_push($t, "s");
 		}
+		if ($sql_in !== "")
+		$sql .= " AND element_name NOT IN (" . $sql_in . ")";
+
+		$e = new mb_exception($sql . " " . print_r($v, true));
 		$res = db_prep_query($sql,$v,$t);
 		if (!$res) {
 			$e = new mb_exception("Error while deleting obsolete WFS feature type element in database.");
@@ -409,6 +425,7 @@
 			$aWfsFeatureType->id
 		);
 		$t = array("i", "i");
+		$e = new mb_exception($sql . " " . print_r($v, true));
 		$res = db_prep_query($sql, $v, $t);
 		if (!$res) {
 			$e = new mb_exception("Error while deleting WFS feature type namespaces from the database.");

Modified: trunk/mapbender/http/classes/class_wfs_1_0.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_1_0.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_wfs_1_0.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -28,6 +28,42 @@
 	public function getVersion () {
 		return "1.0.0";
 	}
+	
+	public function transaction ($method, $wfsConf, $geoJson) {
+		$gmlFactory = new Gml_2_Factory();
+		$gmlObj = $gmlFactory->createFromGeoJson($geoJson);
+	
+		return parent::transaction ($method, $wfsConf, $gmlObj);
+	}
+	
+	public function parseTransactionResponse ($xml) {
+		$result = new stdClass();
+		$result->success = false;
+		$result->message = "";
+		$result->xml = $xml;
+
+		$data = mb_eregi_replace("^[^<]*", "", $xml);
+		$data = mb_eregi_replace("[^>]*$", "", $data);
+		$resObj = array();
+		if (mb_strpos(mb_strtoupper($data), "SUCCESS") !== false) {
+			$result->success = true;
+			if (mb_ereg("^.*ogc:FeatureId fid=\"(.+)\"/>.*$", $data)) {
+				$fid = mb_ereg_replace("^.*ogc:FeatureId fid=\"(.+)\"/>.*$", "\\1", $data);
+				$result->fid = $fid;
+			}
+			$result->message = "Success.";
+		}
+		else {
+			$result->message = "An unknown error occured.";
+		}
+		return $result;
+	}
+
+	protected function getFeatureIdFilter ($fid) {
+		return "<ogc:FeatureId fid=\"$fid\"/>";
+	}
+	
+	
 }
 
 ?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_wfs_1_1.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_1_1.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_wfs_1_1.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -28,6 +28,76 @@
 	public function getVersion () {
 		return "1.1.0";
 	}
+
+	public function transaction ($method, $wfsConf, $geoJson) {
+		$gmlFactory = new Gml_3_Factory();
+		$gmlObj = $gmlFactory->createFromGeoJson($geoJson);
+	
+		return parent::transaction ($method, $wfsConf, $gmlObj);
+	}
+	
+	public function parseTransactionResponse ($xml) {
+		$result = new stdClass();
+		$result->success = false;
+		$result->message = "";
+		$result->xml = $xml;
+		
+		$simpleXml = simplexml_load_string($xml);
+		$simpleXml->registerXPathNamespace('wfs', 'http://www.opengis.net/wfs');
+		$simpleXml->registerXPathNamespace('ogc', 'http://www.opengis.net/ogc');
+		
+		//
+		// get error messages
+		//
+		$nodeArray = $simpleXml->xpath("//wfs:TransactionResults/wfs:Action/wfs:Message");
+		$messageArray = array();
+		foreach ($nodeArray as $node) {
+			$domNode = dom_import_simplexml($node);
+			
+			$result->success = false;
+			$messageArray[] = $domNode->nodeValue;
+		}
+		if (count($messageArray) > 0) {
+			$result->message = implode(". ", $messageArray);
+			return $result;		
+		}
+
+		//
+		// Get transaction results
+		//
+		$nodeArray = $simpleXml->xpath("//wfs:TransactionSummary/*");
+		$messageArray = array();
+		foreach ($nodeArray as $node) {
+			$domNode = dom_import_simplexml($node);
+			$tagName = $this->sepNameSpace($domNode->nodeName);
+			$result->success = true;
+			$messageArray[] = $tagName . ": " . $domNode->nodeValue;
+		}		
+		if (count($messageArray) > 0) {
+			$result->message = implode(". ", $messageArray);
+
+			// get fid
+			$nodeArray = $simpleXml->xpath("//wfs:InsertResults/wfs:Feature/ogc:FeatureId");
+			$e = new mb_exception(print_r($nodeArray, true));
+			foreach ($nodeArray as $node) {
+				$domNode = dom_import_simplexml($node);
+				if ($domNode->hasAttribute("fid")) {
+					$result->fid = $domNode->getAttribute("fid");
+				}
+			}
+			return $result;		
+		}
+		
+		//
+		// Unknown error
+		//
+		$result->message = "An unknown error has occured.";
+		return $result;
+	}
+
+	protected function getFeatureIdFilter ($fid) {
+		return "<ogc:GmlObjectId gml:id=\"$fid\"/>";
+	}
+	
 }
-
 ?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_wfs_configuration.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_configuration.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/classes/class_wfs_configuration.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -71,6 +71,27 @@
 	}
 	
 	/**
+	 * Finds the featuretype element which stores the authentication data.
+	 * 
+	 * @return String 
+	 */
+	public function getAuthElement () {
+		foreach ($this->elementArray as $element) {
+			if (!empty($element->authVarname)) {
+				$validname = preg_match('/^\$_[a-zA-z]+(\[\"[a-zA-Z_]+\"\])?$/', $element->authVarname);
+
+				if ($validname === 1) {
+					return $element;
+				}
+				else {
+					$e = new mb_exception("Found auth element, but variable name is not valid: " . $element->authVarname);
+				}
+			}
+		}
+		return null;
+	}
+
+	/**
 	 * Checks if the user currently logged in is allowed to access
 	 * the WFS configuration
 	 * 
@@ -156,7 +177,7 @@
 			$element->respos = $row["f_respos"];
 			$element->minInput = $row["f_min_input"];
 			$element->formElementHtml = $row["f_form_element_html"];
-			$element->authVarname = $row["f_auth_varname"];
+			$element->authVarname = stripslashes($row["f_auth_varname"]);
 			$element->detailpos = $row["f_detailpos"];
 			$element->operator = $row["f_operator"];
 			$element->showDetail = $row["f_show_detail"];

Modified: trunk/mapbender/http/javascripts/geometry.js
===================================================================
--- trunk/mapbender/http/javascripts/geometry.js	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/javascripts/geometry.js	2009-03-02 09:10:10 UTC (rev 3614)
@@ -316,9 +316,6 @@
 		var geoJSON = eval('(' + geoJSON + ')');
 	}
 
-	var featureCollectionEpsg = (geoJSON.crs && geoJSON.crs.type == "EPSG") ? geoJSON.crs.properties.code : 4326;
-	var featureEpsg = (geoJSON.crs && geoJSON.crs.type == "EPSG") ? geoJSON.crs.properties.code : 4326;
-
 	//
 	// FEATURE COLLECTION
 	//
@@ -329,12 +326,19 @@
 		//
 		var featureArray = geoJSON.features;
 		for (var j = 0; j < featureArray.length; j++) {
-			featureEpsg = featureCollectionEpsg;
 			var currentFeature = featureArray[j];
 			var isFeature = (currentFeature.type == "Feature") ? true : false;
 	
 			// add geometry ...
 			if (currentFeature.geometry && isFeature) {
+				var featureEpsg = "EPSG:4326";
+				if (!currentFeature.crs || currentFeature.crs.type !== "name" || !currentFeature.crs.properties.name) {
+					var e = new Mb_warning("SRS not set or unknown in GeoJSON. Using 'EPSG:4326'.");
+				}
+				else {
+					featureEpsg = currentFeature.crs.properties.name;
+				}
+
 				//
 				// GEOMETRY
 				//
@@ -451,14 +455,9 @@
 					this.get(-1).e.setElement("fid", currentFeature.id);
 				}
 			}
-			if (currentFeature.crs) {
-				if (currentFeature.crs.type == "EPSG") {
-					featureEpsg = currentFeature.crs.properties.code;
-				}
-				
-			}	
 		}
 	}
+	return true;
 }
 
 GeometryArray.prototype.featureToString = function (i) {

Modified: trunk/mapbender/http/javascripts/mod_digitize_tab.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_digitize_tab.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/javascripts/mod_digitize_tab.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -346,8 +346,9 @@
 	
 	var currentPos = getMousePosition(e);
 
-	var pos = parent.makeClickPos2RealWorldPos(mod_digitize_target,currentPos.x, currentPos.y);
-	var p = new parent.Point(pos[0], pos[1]);
+	var ind = parent.getMapObjIndexByName(mod_digitize_target);
+	var p = parent.mb_mapObj[ind].convertPixelToReal(new Point(currentPos.x, currentPos.y));
+
 	if (k == undefined) {
 		d.getGeometry(i,j).addPointAtIndex(p, l);
 	}
@@ -425,7 +426,8 @@
 	var currentPos = getMousePosition(e);
 	var basepointDragEnd = currentPos;
 	basepointObject.onmousedown = null;
-	var p = parent.makeClickPos2RealWorldPos(mod_digitize_target, basepointDragEnd.x, basepointDragEnd.y);
+	var ind = parent.getMapObjIndexByName(mod_digitize_target);
+	var p = parent.mb_mapObj[ind].convertPixelToReal(new Point(basepointDragEnd.x, basepointDragEnd.y));
 
 	var oldPoint;
 	if (k == undefined) {
@@ -445,12 +447,11 @@
 		s.clean();
 	}
 	else {
-		var newPoint = new parent.Point(p[0],p[1]);
 		if (!nonTransactionalEditable) {
-			updateAllPointsOfNonTransactionalLike(oldPoint, newPoint);
+			updateAllPointsOfNonTransactionalLike(oldPoint, p);
 		}
 		else {
-			d.updateAllPointsLike(oldPoint, newPoint);
+			d.updateAllPointsLike(oldPoint, p);
 		}
 	}
 	basepointMemberIndex = null;
@@ -1418,10 +1419,36 @@
 			for (var elementIndex = 0; elementIndex < wfsConf[attr]['element'].length ; elementIndex++) {
 				var isGeomColumn = (parseInt(wfsConf[attr]['element'][elementIndex]['f_geom']) == 1); 
 				if (isGeomColumn) {
-					var isMultiPolygon = (geom.geomType == parent.geomType.polygon && wfsConf[attr]['element'][elementIndex]['element_type'] == 'MultiPolygonPropertyType');
-					var isPolygon = (geom.geomType == parent.geomType.polygon && geom.count() == 1 && wfsConf[attr]['element'][elementIndex]['element_type'] == 'PolygonPropertyType');
-					var isMultiLine = (geom.geomType == parent.geomType.line && wfsConf[attr]['element'][elementIndex]['element_type'] == 'MultiLineStringPropertyType');
-					var isLine = (geom.geomType == parent.geomType.line && geom.count() == 1 && wfsConf[attr]['element'][elementIndex]['element_type'] == 'LineStringPropertyType');
+					var isMultiPolygon = (
+						geom.geomType == parent.geomType.polygon && 
+						(
+						wfsConf[attr]['element'][elementIndex]['element_type'] == 'MultiPolygonPropertyType' ||
+						wfsConf[attr]['element'][elementIndex]['element_type'] == 'MultiSurfacePropertyType'
+						)
+					);
+					var isPolygon = (
+						geom.geomType == parent.geomType.polygon && 
+						geom.count() == 1 && 
+						(
+						wfsConf[attr]['element'][elementIndex]['element_type'] == 'PolygonPropertyType' ||
+						wfsConf[attr]['element'][elementIndex]['element_type'] == 'SurfacePropertyType'
+						)
+					);
+					var isMultiLine = (
+						geom.geomType == parent.geomType.line && 
+						(
+						wfsConf[attr]['element'][elementIndex]['element_type'] == 'MultiLineStringPropertyType' ||
+						wfsConf[attr]['element'][elementIndex]['element_type'] == 'MultiCurvePropertyType'
+						)
+					);
+					var isLine = (
+						geom.geomType == parent.geomType.line && 
+						geom.count() == 1 && 
+						(
+						wfsConf[attr]['element'][elementIndex]['element_type'] == 'LineStringPropertyType' ||
+						wfsConf[attr]['element'][elementIndex]['element_type'] == 'CurvePropertyType'
+						)
+					);
 					var isPoint = (geom.geomType == parent.geomType.point && wfsConf[attr]['element'][elementIndex]['element_type'] == 'PointPropertyType');
 //					alert(isMultiPolygon + " " + isPolygon + " " + isMultiLine + " " + isLine + " " + isPoint);
 					if (isMultiPolygon || isPolygon || isMultiLine || isLine || isPoint || wfsConf[attr]['element'][elementIndex]['element_type'] == 'GeometryAssociationType') {
@@ -1685,10 +1712,11 @@
 	
 	var mapObjInd = parent.getMapObjIndexByName(mod_digitize_target);
 
+	var proceed = true;
 	if (myconf['featuretype_srs'] != parent.mb_mapObj[mapObjInd].epsg) {
-		alert(msgObj.errorMessageEpsgMismatch + parent.mb_mapObj[mapObjInd].epsg + " / "+ myconf['featuretype_srs']);
+		proceed = confirm(msgObj.errorMessageEpsgMismatch + parent.mb_mapObj[mapObjInd].epsg + " / "+ myconf['featuretype_srs'] + ". Proceed?");
 	}
-	else {
+	if (proceed) {
 		var fid = false;
 		var errorMessage = "";
 		if (typeof(wfsWindow) != 'undefined' && !wfsWindow.closed) {
@@ -1741,16 +1769,16 @@
 			}, 
 			function(json,status){
 				var result = eval('('+json+')');
-				var response = result.response;
+				var success = result.success;
 				var fid = result.fid;
-				wfsSubWrite(m, type, status, response, fid);
+				wfsSubWrite(m, type, status, success, fid);
 			}
 		);
 	}
 }
 
-function wfsSubWrite(m, type, status, response, fid) {
-	if (status == "success" && response == "success") {
+function wfsSubWrite(m, type, status, success, fid) {
+	if (status == "success" && success) {
 		if (type == 'insert' && fid) {
 			d.get(m).e.setElement("fid", fid);
 		}

Modified: trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -16,7 +16,7 @@
 # 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__)."/../php/mb_validatePermission.php");
 $wfs_conf_filename = "wfs_default.conf";
 include '../include/dyn_php.php';
@@ -374,134 +374,138 @@
 
 	numberOfAjaxCalls =  js_wfs_conf_id.length;
 
-	if(requestGeom!=null){
-		if(requestGeom.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 filter = "<ogc:Filter xmlns:ogc=\"http://ogc.org\" xmlns:gml=\"http://www.opengis.net/gml\">";
-	
-				if(buttonPolygon.filteroption=='within'){
-					filter += "<Within><ogc:PropertyName>";
-					for(var j=0; j<wfs_config[js_wfs_conf_id[i]]['element'].length; j++){
-						if(wfs_config[js_wfs_conf_id[i]]['element'][j]['f_geom'] == 1){
-							filter += wfs_config[js_wfs_conf_id[i]]['element'][j]['element_name'];
-						}
+	if(requestGeom.geomType==geomType.polygon){
+		for(var i=0; i<js_wfs_conf_id.length; i++){
+// I guess we should use the SRS of the map client, not the WFS? 
+// The coordinates come from the current client (?)
+//			var srs = wfs_config[js_wfs_conf_id[i]]['featuretype_srs'];
+			var srs = mod_wfs_spatialRequest_epsg;
+			var filter = "<ogc:Filter xmlns:ogc=\"http://ogc.org\" xmlns:gml=\"http://www.opengis.net/gml\">";
+
+			if(buttonPolygon.filteroption=='within'){
+				filter += "<Within><ogc:PropertyName>";
+				for(var j=0; j<wfs_config[js_wfs_conf_id[i]]['element'].length; j++){
+					if(wfs_config[js_wfs_conf_id[i]]['element'][j]['f_geom'] == 1){
+						filter += wfs_config[js_wfs_conf_id[i]]['element'][j]['element_name'];
 					}
-					filter += "</ogc:PropertyName><gml:Polygon srsName=\""+srs+"\">";
-					filter += "<gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";
-					for(var k=0; k<requestGeom.count(); k++){
-						if(k>0)	filter += " ";
-						filter += requestGeom.get(k).x+","+requestGeom.get(k).y;
-					}
-					filter += "</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>";
-					filter += "</gml:Polygon></Within>";
 				}
-				else if(buttonPolygon.filteroption=='intersects'){
-					filter += "<Intersects><ogc:PropertyName>";
-					for(var j=0; j<wfs_config[js_wfs_conf_id[i]]['element'].length; j++){
-						if(wfs_config[js_wfs_conf_id[i]]['element'][j]['f_geom'] == 1){
-							filter += wfs_config[js_wfs_conf_id[i]]['element'][j]['element_name'];
-						}
+				filter += "</ogc:PropertyName><gml:Polygon srsName=\""+srs+"\">";
+				filter += "<gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";
+				for(var k=0; k<requestGeom.count(); k++){
+					if(k>0)	filter += " ";
+					filter += requestGeom.get(k).x+","+requestGeom.get(k).y;
+				}
+				filter += "</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>";
+				filter += "</gml:Polygon></Within>";
+			}
+			else if(buttonPolygon.filteroption=='intersects'){
+				filter += "<Intersects><ogc:PropertyName>";
+				for(var j=0; j<wfs_config[js_wfs_conf_id[i]]['element'].length; j++){
+					if(wfs_config[js_wfs_conf_id[i]]['element'][j]['f_geom'] == 1){
+						filter += wfs_config[js_wfs_conf_id[i]]['element'][j]['element_name'];
 					}
-					filter += "</ogc:PropertyName><gml:Polygon srsName='"+srs+"'>";
-					filter += "<gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";
-					for(var k=0; k<requestGeom.count(); k++){
-						if(k>0)	filter += " ";
-						filter += requestGeom.get(k).x+","+requestGeom.get(k).y;
-					}
-					filter += "</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>";
-					filter += "</gml:Polygon></Intersects>";
 				}
-	
-				filter += '</ogc:Filter>';
-				mb_get_geom(filter, i, wfs_config[js_wfs_conf_id[i]]['featuretype_name'], js_wfs_conf_id[i], db_wfs_conf_id[i]);
+				filter += "</ogc:PropertyName><gml:Polygon srsName='"+srs+"'>";
+				filter += "<gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";
+				for(var k=0; k<requestGeom.count(); k++){
+					if(k>0)	filter += " ";
+					filter += requestGeom.get(k).x+","+requestGeom.get(k).y;
+				}
+				filter += "</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>";
+				filter += "</gml:Polygon></Intersects>";
 			}
+
+			filter += '</ogc:Filter>';
+			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(requestGeom.geomType==geomType.line){
-			var rectangle = [];
-			if(requestGeom.geomType == geomType.line){
-				var rectangle = requestGeom.getBBox();
-			}
-			for(var i=0; i<js_wfs_conf_id.length; i++){
-				var srs = wfs_config[js_wfs_conf_id[i]]['featuretype_srs'];
-				var filter = "<ogc:Filter xmlns:ogc='http://ogc.org' xmlns:gml='http://www.opengis.net/gml'>";
-	
-				if(buttonRectangle.filteroption=='within'){
-					filter += "<Within><ogc:PropertyName>";
-					for(var j=0; j<wfs_config[js_wfs_conf_id[i]]['element'].length; j++){
-						if(wfs_config[js_wfs_conf_id[i]]['element'][j]['f_geom'] == 1){
-							filter += wfs_config[js_wfs_conf_id[i]]['element'][j]['element_name'];
-						}
+	}
+	else if(requestGeom.geomType==geomType.line){
+		var rectangle = requestGeom.getBBox();
+		for(var i=0; i<js_wfs_conf_id.length; i++){
+// I guess we should use the SRS of the map client, not the WFS? 
+// The coordinates come from the current client (?)
+//			var srs = wfs_config[js_wfs_conf_id[i]]['featuretype_srs'];
+			var srs = mod_wfs_spatialRequest_epsg;
+			var filter = "<ogc:Filter xmlns:ogc='http://ogc.org' xmlns:gml='http://www.opengis.net/gml'>";
+
+			if(buttonRectangle.filteroption=='within'){
+				filter += "<Within><ogc:PropertyName>";
+				for(var j=0; j<wfs_config[js_wfs_conf_id[i]]['element'].length; j++){
+					if(wfs_config[js_wfs_conf_id[i]]['element'][j]['f_geom'] == 1){
+						filter += wfs_config[js_wfs_conf_id[i]]['element'][j]['element_name'];
 					}
-					filter += "</ogc:PropertyName><gml:Polygon srsName='"+srs+"'>";
-					filter += "<gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";
-					filter += rectangle[0].x+","+rectangle[0].y;
-					filter += " ";
-					filter += rectangle[0].x+","+rectangle[1].y;
-					filter += " ";
-					filter += rectangle[1].x+","+rectangle[1].y;
-					filter += " ";
-					filter += rectangle[1].x+","+rectangle[0].y;
-					filter += " ";
-					filter += rectangle[0].x+","+rectangle[0].y;
-					filter += "</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>";
-					filter += "</gml:Polygon></Within>";
 				}
-				else if(buttonRectangle.filteroption=='intersects'){
-					filter += "<Intersects><ogc:PropertyName>";
-					for(var j=0; j<wfs_config[js_wfs_conf_id[i]]['element'].length; j++){
-						if(wfs_config[js_wfs_conf_id[i]]['element'][j]['f_geom'] == 1){
-							filter += wfs_config[js_wfs_conf_id[i]]['element'][j]['element_name'];
-						}
-					}
-					filter += "</ogc:PropertyName><gml:Polygon srsName='"+srs+"'>";
-					filter += "<gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";
-					filter += rectangle[0].x+","+rectangle[0].y;
-					filter += " ";
-					filter += rectangle[0].x+","+rectangle[1].y;
-					filter += " ";
-					filter += rectangle[1].x+","+rectangle[1].y;
-					filter += " ";
-					filter += rectangle[1].x+","+rectangle[0].y;
-					filter += " ";
-					filter += rectangle[0].x+","+rectangle[0].y;
-					filter += "</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>";
-					filter += "</gml:Polygon></Intersects>";
-				}
-	
-				filter += "</ogc:Filter>";
-				mb_get_geom(filter, i, wfs_config[js_wfs_conf_id[i]]['featuretype_name'], js_wfs_conf_id[i], db_wfs_conf_id[i]);
+				filter += "</ogc:PropertyName><gml:Polygon srsName='"+srs+"'>";
+				filter += "<gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";
+				filter += rectangle[0].x+","+rectangle[0].y;
+				filter += " ";
+				filter += rectangle[0].x+","+rectangle[1].y;
+				filter += " ";
+				filter += rectangle[1].x+","+rectangle[1].y;
+				filter += " ";
+				filter += rectangle[1].x+","+rectangle[0].y;
+				filter += " ";
+				filter += rectangle[0].x+","+rectangle[0].y;
+				filter += "</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>";
+				filter += "</gml:Polygon></Within>";
 			}
-		}
-		else if(requestGeom.geomType == geomType.point){
-			var tmp = requestGeom.get(0);
-			var mapPos = makeRealWorld2mapPos("mapframe1",tmp.x, tmp.y);
-			var buffer = mb_wfs_tolerance/2;
-			var mapPosXAddPix = mapPos[0] + buffer;
-			var mapPosYAddPix = mapPos[1] +buffer;
-			var mapPosXRemovePix = mapPos[0] - buffer;
-			var mapPosYRemovePix = mapPos[1] - buffer;
-			var realWorld1 = makeClickPos2RealWorldPos("mapframe1",mapPosXRemovePix,mapPosYRemovePix);
-			var realWorld2 = makeClickPos2RealWorldPos("mapframe1",mapPosXAddPix,mapPosYRemovePix);
-			var realWorld3 = makeClickPos2RealWorldPos("mapframe1",mapPosXAddPix,mapPosYRemovePix);
-			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 filter = "<ogc:Filter xmlns:ogc='http://ogc.org' xmlns:gml='http://www.opengis.net/gml'>";
+			else if(buttonRectangle.filteroption=='intersects'){
 				filter += "<Intersects><ogc:PropertyName>";
 				for(var j=0; j<wfs_config[js_wfs_conf_id[i]]['element'].length; j++){
 					if(wfs_config[js_wfs_conf_id[i]]['element'][j]['f_geom'] == 1){
 						filter += wfs_config[js_wfs_conf_id[i]]['element'][j]['element_name'];
 					}
 				}
-				filter += "</ogc:PropertyName><gml:Polygon srsName='"+srs+"'><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";
-				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>";
-				mb_get_geom(filter, i, wfs_config[js_wfs_conf_id[i]]['featuretype_name'], js_wfs_conf_id[i], db_wfs_conf_id[i]);
+				filter += "</ogc:PropertyName><gml:Polygon srsName='"+srs+"'>";
+				filter += "<gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";
+				filter += rectangle[0].x+","+rectangle[0].y;
+				filter += " ";
+				filter += rectangle[0].x+","+rectangle[1].y;
+				filter += " ";
+				filter += rectangle[1].x+","+rectangle[1].y;
+				filter += " ";
+				filter += rectangle[1].x+","+rectangle[0].y;
+				filter += " ";
+				filter += rectangle[0].x+","+rectangle[0].y;
+				filter += "</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>";
+				filter += "</gml:Polygon></Intersects>";
 			}
+
+			filter += "</ogc:Filter>";
+			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(requestGeom.geomType == geomType.point){
+		var tmp = requestGeom.get(0);
+		var mapPos = makeRealWorld2mapPos("mapframe1",tmp.x, tmp.y);
+		var buffer = mb_wfs_tolerance/2;
+		var mapPosXAddPix = mapPos[0] + buffer;
+		var mapPosYAddPix = mapPos[1] +buffer;
+		var mapPosXRemovePix = mapPos[0] - buffer;
+		var mapPosYRemovePix = mapPos[1] - buffer;
+		var realWorld1 = makeClickPos2RealWorldPos("mapframe1",mapPosXRemovePix,mapPosYRemovePix);
+		var realWorld2 = makeClickPos2RealWorldPos("mapframe1",mapPosXAddPix,mapPosYRemovePix);
+		var realWorld3 = makeClickPos2RealWorldPos("mapframe1",mapPosXAddPix,mapPosYRemovePix);
+		var realWorld4 = makeClickPos2RealWorldPos("mapframe1",mapPosXRemovePix,mapPosYAddPix);
+		for(var i=0; i<js_wfs_conf_id.length; i++){
+// I guess we should use the SRS of the map client, not the WFS? 
+// The coordinates come from the current client (?)
+//			var srs = wfs_config[js_wfs_conf_id[i]]['featuretype_srs'];
+			var srs = mod_wfs_spatialRequest_epsg;
+			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++){
+				if(wfs_config[js_wfs_conf_id[i]]['element'][j]['f_geom'] == 1){
+					filter += wfs_config[js_wfs_conf_id[i]]['element'][j]['element_name'];
+				}
+			}
+			filter += "</ogc:PropertyName><gml:Polygon srsName='"+srs+"'><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";
+			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>";
+			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;
 }
@@ -518,9 +522,10 @@
 		},
 		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);
+			if (geom.importGeoJSON(json)) {
+				for (var i = 0; i < geom.count(); i++) {
+					geom.get(i).wfs_conf = parseInt(js_wfs_conf_id);
+				}
 			}
 	
 			checkIfAllAjaxCallsFinished(geom);
@@ -531,6 +536,14 @@
 function checkIfAllAjaxCallsFinished (geom) {
 	numberOfFinishedAjaxCalls++;
 	if (typeof(geom) == 'object'){
+		var mapIndex = getMapObjIndexByName(mod_wfs_spatialRequest_target);
+		if (geom.count() === 0) {
+			var e = new Mb_exception("Result set is empty.");
+			return;
+		}
+		if (geom.get(0).getEpsg() !== mb_mapObj[mapIndex].epsg) {
+			var e = new Mb_warning("SRS mismatch. Geometry is in " + geom.get(0).getEpsg() + ", map is in " + mb_mapObj[mapIndex].epsg + ".");
+		}
 		geomArray.union(geom);
 	}
 	if (numberOfFinishedAjaxCalls == numberOfAjaxCalls) {
@@ -582,15 +595,38 @@
 }
 
 function appendGeometryArrayToDigitize(geom){
-	parent.window.frames[mod_digitize_elName].appendGeometryArray(geom);
-	parent.tab_open(mod_digitize_elName);
+	var mapIndex = getMapObjIndexByName(mod_wfs_spatialRequest_target);
+
+	if (geom.get(0).getEpsg() !== mb_mapObj[mapIndex].epsg) {
+		var e = new Mb_exception("SRS mismatch. Geometry is in " + geom.get(0).getEpsg() + ", map is in " + mb_mapObj[mapIndex].epsg + ". Geometry discarded.");
+		return;
+	}
+	try {
+		window.frames[mod_digitize_elName].appendGeometryArray(geom);
+		tab_open(mod_digitize_elName);
+	}
+	catch (e) {
+		var e = new Mb_exception("The application element 'digitize' is missing.");
+	}
 }
 
 function appendGeometryToDigitize(i){
+	var mapIndex = getMapObjIndexByName(mod_wfs_spatialRequest_target);
+
+	if (geomArray.get(i).getEpsg() !== mb_mapObj[mapIndex].epsg) {
+		var e = new Mb_exception("SRS mismatch. Geometry is in " + geom.get(0).getEpsg() + ", map is in " + mb_mapObj[mapIndex].epsg + ". Geometry discarded.");
+		return;
+	}
+
 	var digitizeArray = new GeometryArray();
 	digitizeArray.addCopy(geomArray.get(i));
-	parent.window.frames[mod_digitize_elName].appendGeometryArray(digitizeArray);
-	parent.tab_open(mod_digitize_elName);
+	try {
+		window.frames[mod_digitize_elName].appendGeometryArray(digitizeArray);
+		tab_open(mod_digitize_elName);
+	}
+	catch (e) {
+		var e = new Mb_exception("The application element 'digitize' is missing.");
+	}
 }
 
 function createListOfGeometries(){

Modified: trunk/mapbender/http/php/mod_wfs_result.php
===================================================================
--- trunk/mapbender/http/php/mod_wfs_result.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/php/mod_wfs_result.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -20,7 +20,7 @@
 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_wfs_conf.php");
+require_once(dirname(__FILE__)."/../classes/class_wfs_configuration.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");
@@ -61,6 +61,7 @@
 			$element_name = $row["element_name"];
 		}
 	}
+	$e = new mb_exception($auth_varname . " " . $element_name);
 	if (!empty($auth_varname)) {
 
 		if (isValidVarName($auth_varname)) {
@@ -89,12 +90,14 @@
 
 if ($data === null) die('{}');
 
-//echo $data; die;
+$myWfsConf = WfsConfiguration::createFromDb($db_wfs_conf_id);
+if (is_null($myWfsConf)) {
+	die("{}");
+}
 
-$geomColumn = WfsConf::getGeomColumnNameByConfId($db_wfs_conf_id);
+$gmlFactory = new UniversalGmlFactory();
+$myGml = $gmlFactory->createFromXml($data, $myWfsConf);
 
-$gmlFactory = new UniversalGmlFactory();
-$myGml = $gmlFactory->createFromXml($data, geomColumn);
 $geoJson = $myGml->toGeoJSON();
 
 header('Content-type: text/html');

Modified: trunk/mapbender/http/php/mod_wfs_server.php
===================================================================
--- trunk/mapbender/http/php/mod_wfs_server.php	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/http/php/mod_wfs_server.php	2009-03-02 09:10:10 UTC (rev 3614)
@@ -232,16 +232,17 @@
  * @return boolean success
  */
 function updateWfs($obj){
-	$obj->success = false;
-	$mywfs = new wfs();
-	$mywfs->createObjFromDB($obj->wfs);
-	if(!$mywfs->updateObjFromXML($obj->url)){
-		return false;
+	$id = $obj->wfs;
+
+	$wfsFactory = new UniversalWfsFactory();
+	$myWfs = $wfsFactory->createFromDb($id);
+
+	if(is_null($myWfs) || !$myWfs->update()){
+		$obj->success = false;
 	}
-	if(!$mywfs->wfs2db("")){
-		return false;
+	else {
+		$obj->success = true;
 	}
-	$obj->success = true;
 	return true;
 }
 /*
@@ -251,18 +252,16 @@
  * @return boolean success
  */
 function deleteWfs($obj){
-	//$obj->success = false;
 	$id = $obj->wfs;
 	
 	$wfsFactory = new UniversalWfsFactory();
 	$myWfs = $wfsFactory->createFromDb($id);
-	if ($myWfs->delete()) {
-		$obj->success = true;
+	if (is_null($myWfs) || !$myWfs->delete()) {
+		$obj->success = false;
 	}
 	else {
-		$obj->success = false;
+		$obj->success = true;
 	}
-	
 	return true;
 }
 

Modified: trunk/mapbender/lib/point.js
===================================================================
--- trunk/mapbender/lib/point.js	2009-03-02 08:36:23 UTC (rev 3613)
+++ trunk/mapbender/lib/point.js	2009-03-02 09:10:10 UTC (rev 3614)
@@ -119,36 +119,16 @@
 /**
  * @ignore
  */
-function mapToReal(frameName, aPoint){
-	var v;
-	if (typeof(mb_mapObj) == 'object') {
-		v = makeClickPos2RealWorldPos(frameName, aPoint.x, aPoint.y);
-	}
-	else {
-		if (typeof(parent.mb_mapObj) == 'object') {
-			v = parent.makeClickPos2RealWorldPos(frameName, aPoint.x, aPoint.y);
-		}
-		else {
-			alert('where am i?');
-		}
-	}
-	return new Point(v[0], v[1]);
+function mapToReal(frameName, aPoint) {
+	var ind = getMapObjIndexByName(frameName);
+	return mb_mapObj[ind].convertPixelToReal(aPoint);
 }
 /**
  * @ignore
  */
 function realToMap(frameName, aPoint) {
-	var v;
-	if (typeof(mb_mapObj) == 'object') {
-		v = makeRealWorld2mapPos(frameName, aPoint.x, aPoint.y);
-	}
-	else if (typeof(parent.mb_mapObj) == 'object') {
-		v = parent.makeRealWorld2mapPos(frameName, aPoint.x, aPoint.y);
-	}
-	else {
-		var e = new Mb_exception('Point.realToMap:where am i?');
-	}
-	return new Point(v[0], v[1]);
+	var ind = getMapObjIndexByName(frameName);
+	return mb_mapObj[ind].convertRealToPixel(aPoint);
 }
 /**
  * @ignore



More information about the Mapbender_commits mailing list