[Mapbender-commits] r1197 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Mar 7 05:04:37 EST 2007


Author: christoph
Date: 2007-03-07 05:04:37 -0500 (Wed, 07 Mar 2007)
New Revision: 1197

Modified:
   trunk/mapbender/http/classes/class_wms.php
Log:
some refactoring

Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php	2007-03-07 10:01:38 UTC (rev 1196)
+++ trunk/mapbender/http/classes/class_wms.php	2007-03-07 10:04:37 UTC (rev 1197)
@@ -21,1556 +21,1559 @@
 require_once(dirname(__FILE__)."/class_connector.php");
   
 class wms {
-  var $lastURL;
-  var $wms_id;
-  var $wms_status;
-  var $wms_version;
-  var $wms_title;
-  var $wms_abstract;
-  var $wms_getcapabilities;
-  var $wms_getcapabilities_doc;
-  var $wms_getmap;
-  var $wms_getfeatureinfo;
-  var $wms_getlegendurl;
-  var $wms_upload_url;
-  
-  var $fees;
-  var $accessconstraints;
-  var $contactperson;
-  var $contactposition;
-  var $contactorganization;
-  var $address;
-  var $city;
-  var $stateorprovince;
-  var $postcode;
-  var $country;
-  var $contactvoicetelephone;
-  var $contactfacsimiletelephone;
-  var $contactelectronicmailaddress;
-  
-  var $wms_keyword = array();
-  var $data_type = array(); 
-  var $data_format = array();
-
-  var $objLayer = array(); 
-  
-  var $gui_wms_mapformat;
-  var $gui_wms_featureinfoformat;
-  var $gui_wms_exceptionformat;
-  var $gui_wms_epsg;
-  
-  var $default_epsg = 0;
-  var $overwrite = true;
-  
-  function wms() {
+	var $lastURL;
+	var $wms_id;
+	var $wms_status;
+	var $wms_version;
+	var $wms_title;
+	var $wms_abstract;
+	var $wms_getcapabilities;
+	var $wms_getcapabilities_doc;
+	var $wms_getmap;
+	var $wms_getfeatureinfo;
+	var $wms_getlegendurl;
+	var $wms_upload_url;
+	  
+	var $fees;
+	var $accessconstraints;
+	var $contactperson;
+	var $contactposition;
+	var $contactorganization;
+	var $address;
+	var $city;
+	var $stateorprovince;
+	var $postcode;
+	var $country;
+	var $contactvoicetelephone;
+	var $contactfacsimiletelephone;
+	var $contactelectronicmailaddress;
+	  
+	var $wms_keyword = array();
+	var $data_type = array(); 
+	var $data_format = array();
+	var $objLayer = array(); 
+	  
+	var $gui_wms_mapformat;
+	var $gui_wms_featureinfoformat;
+	var $gui_wms_exceptionformat;
+	var $gui_wms_epsg;
+	  
+	var $default_epsg = 0;
+	var $overwrite = true;
+	  
+	function wms() {
+	} 
+	  
+	function createObjFromXML($url){
 	
-  } 
-  
-function createObjFromXML($url){
-
-	$x = new connector($url);
-	$data = $x->file;
-	if(!$data){
-		//echo "Unable to open document: ".$url;
-		return false;
-		//die; 
-	}
-	
-	$this->wms_getcapabilities_doc = $this->char_encode($data);
-	$this->wms_upload_url = $url;
-	if(!$data){
-		$this->wms_status = false;
-	}
-	else{
-		$this->wms_status = true;
-	}
-	
-//	$time = explode(" ", microtime(1));
-//	$this->wms_id = substr(md5(substr($time[0], 2)), 0, 5);
-	$this->wms_id = ""; 
-	$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,$data,$values,$tags);
-	xml_parser_free($parser);
-	
-	$section;
-	$format;
-	$cnt_format = 0;
-	$parent = array();
-	$myParent = array();
-	$cnt_layer = -1;
-	$request; 
-	$layer_style = array();
-	$cnt_styles = -1;
-	
-	foreach ($values as $element) {
-		if(strtoupper($element[tag]) == "WMT_MS_CAPABILITIES" && $element[type] == "open"){
-			$this->wms_version = $element[attributes][version];
+		$x = new connector($url);
+		$data = $x->file;
+		if(!$data){
+			$this->wms_status = false;
+			return false;
 		}
-		if(strtoupper($element[tag]) == "TITLE" && $element[level] == '3'){
-			$this->wms_title = $this->stripEndlineAndCarriageReturn($element[value]);
+		else {
+			$this->wms_status = true;
 		}
-		if(strtoupper($element[tag]) == "ABSTRACT" && $element[level] == '3'){
-			$this->wms_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
-		}
-		if(strtolower($element[tag]) == "fees"){
-			$this->fees = $element[value];
-		}
-		if(strtolower($element[tag]) == "accessconstraints"){
-			$this->accessconstraints = $element[value];
-		}
-		if(strtolower($element[tag]) == "contactperson"){
-			$this->contactperson = $element[value];
-		}
-		if(strtolower($element[tag]) == "contactposition"){
-			$this->contactposition = $element[value];
-		}
-		if(strtolower($element[tag]) == "contactorganization"){
-			$this->contactorganization = $element[value];
-		}
-		if(strtolower($element[tag]) == "address"){
-			$this->address = $element[value];
-		}
-		if(strtolower($element[tag]) == "city"){
-			$this->city = $element[value];
-		}
-		if(strtolower($element[tag]) == "stateorprovince"){
-			$this->stateorprovince = $element[value];
-		}
-		if(strtolower($element[tag]) == "postcode"){
-			$this->postcode = $element[value];
-		}
-		if(strtolower($element[tag]) == "country"){
-			$this->country = $element[value];
-		}
-		if(strtolower($element[tag]) == "contactvoicetelephone"){
-			$this->contactvoicetelephone = $element[value];
-		}
-		if(strtolower($element[tag]) == "contactfacsimiletelephone"){
-			$this->contactfacsimiletelephone = $element[value];
-		}
-		if(strtolower($element[tag]) == "contactelectronicmailaddress"){
-			$this->contactelectronicmailaddress = $element[value];
-		}
-  		if(strtolower($element[tag]) == "keyword" && $section != 'layer'){
-			$this->wms_keyword[count($this->wms_keyword)] = $element[value];
-		}
+			
 		
-		/*map section*/
-		if($this->wms_version == "1.0.0"){
-	 		if(strtoupper($element[tag]) == "MAP" && $element[type] == "open"){
-				$section = "map";
+		$this->wms_getcapabilities_doc = $this->char_encode($data);
+		$this->wms_upload_url = $url;
+		
+		$this->wms_id = ""; 
+		$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,$data,$values,$tags);
+		xml_parser_free($parser);
+		
+		$section;
+		$format;
+		$cnt_format = 0;
+		$parent = array();
+		$myParent = array();
+		$cnt_layer = -1;
+		$request; 
+		$layer_style = array();
+		$cnt_styles = -1;
+		
+		foreach ($values as $element) {
+			if(strtoupper($element[tag]) == "WMT_MS_CAPABILITIES" && $element[type] == "open"){
+				$this->wms_version = $element[attributes][version];
 			}
-			if($section == "map" && strtoupper($element[tag]) == "GET"){
-				$this->wms_getmap = $element[attributes][onlineResource];
+			if(strtoupper($element[tag]) == "TITLE" && $element[level] == '3'){
+				$this->wms_title = $this->stripEndlineAndCarriageReturn($element[value]);
 			}
-			if($section == "map" && strtoupper($element[tag]) == "FORMAT" && $element[type] == "open"){
-				$format = "map";
+			if(strtoupper($element[tag]) == "ABSTRACT" && $element[level] == '3'){
+				$this->wms_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
 			}
-			if(strtoupper($element[tag]) != "FORMAT" && $section == "map" && $format == "map"){
-				$this->data_type[$cnt_format] = "map";
-				$this->data_format[$cnt_format] = trim($element[tag]);
-				$cnt_format++;
+			if(strtolower($element[tag]) == "fees"){
+				$this->fees = $element[value];
 			}
-			if(strtoupper($element[tag]) == "FORMAT" && $element[type] == "close"){
-				$format = "";
+			if(strtolower($element[tag]) == "accessconstraints"){
+				$this->accessconstraints = $element[value];
 			}
-			if(strtoupper($element[tag]) == "MAP" && $element[type] == "close"){
-				$section = "";
+			if(strtolower($element[tag]) == "contactperson"){
+				$this->contactperson = $element[value];
 			}
-		}
-		else{
-			if(strtoupper($element[tag]) == "GETMAP" && $element[type] == "open"){
-				$section = "map";
+			if(strtolower($element[tag]) == "contactposition"){
+				$this->contactposition = $element[value];
 			}
-			if($section == "map" && strtoupper($element[tag]) == "GET" && $element[type] == "open"){
-				$request = "get";
+			if(strtolower($element[tag]) == "contactorganization"){
+				$this->contactorganization = $element[value];
 			}
-			if($section == "map" && $request == "get" && strtoupper($element[tag]) == "ONLINERESOURCE"){
-				$this->wms_getmap = $element[attributes]["xlink:href"];
+			if(strtolower($element[tag]) == "address"){
+				$this->address = $element[value];
 			}
-			if($section == "map" && strtoupper($element[tag]) == "FORMAT"){
-				$this->data_type[$cnt_format] = "map";
-				$this->data_format[$cnt_format] = trim($element[value]);
-				$cnt_format++;
+			if(strtolower($element[tag]) == "city"){
+				$this->city = $element[value];
 			}
-			if($section == "map" && strtoupper($element[tag]) == "GET" && $element[type] == "close"){
-				$request = "";
+			if(strtolower($element[tag]) == "stateorprovince"){
+				$this->stateorprovince = $element[value];
 			}
-			if(strtoupper($element[tag]) == "GETMAP" && $element[type] == "close"){
-				$section = "";
+			if(strtolower($element[tag]) == "postcode"){
+				$this->postcode = $element[value];
 			}
-		}
-		/*capabilities section*/
-		if($this->wms_version == "1.0.0"){
-			if(strtoupper($element[tag]) == "CAPABILITIES" && $element[type] == "open"){
-				$section = "capabilities";
+			if(strtolower($element[tag]) == "country"){
+				$this->country = $element[value];
 			}
-			if($section == "capabilities" && strtoupper($element[tag]) == "GET"){
-				$this->wms_getcapabilities = $element[attributes][onlineResource];
+			if(strtolower($element[tag]) == "contactvoicetelephone"){
+				$this->contactvoicetelephone = $element[value];
 			}
-			if(strtoupper($element[tag]) == "CAPABILITIES" && $element[type] == "close"){
-				$section = "";
+			if(strtolower($element[tag]) == "contactfacsimiletelephone"){
+				$this->contactfacsimiletelephone = $element[value];
 			}
-		}
-		else{
-			if(strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "open"){
-				$section = "capabilities";
+			if(strtolower($element[tag]) == "contactelectronicmailaddress"){
+				$this->contactelectronicmailaddress = $element[value];
 			}
-			if($section == "capabilities" && strtoupper($element[tag]) == "GET" && $element[type] == "open"){
-				$request = "get";
+	  		if(strtolower($element[tag]) == "keyword" && $section != 'layer'){
+				$this->wms_keyword[count($this->wms_keyword)] = $element[value];
 			}
-			if($section == "capabilities" && $request == "get" && strtoupper($element[tag]) == "ONLINERESOURCE"){
-				$this->wms_getcapabilities = $element[attributes]["xlink:href"];
+			
+			/*map section*/
+			if($this->wms_version == "1.0.0"){
+		 		if(strtoupper($element[tag]) == "MAP" && $element[type] == "open"){
+					$section = "map";
+				}
+				if($section == "map" && strtoupper($element[tag]) == "GET"){
+					$this->wms_getmap = $element[attributes][onlineResource];
+				}
+				if($section == "map" && strtoupper($element[tag]) == "FORMAT" && $element[type] == "open"){
+					$format = "map";
+				}
+				if(strtoupper($element[tag]) != "FORMAT" && $section == "map" && $format == "map"){
+					$this->data_type[$cnt_format] = "map";
+					$this->data_format[$cnt_format] = trim($element[tag]);
+					$cnt_format++;
+				}
+				if(strtoupper($element[tag]) == "FORMAT" && $element[type] == "close"){
+					$format = "";
+				}
+				if(strtoupper($element[tag]) == "MAP" && $element[type] == "close"){
+					$section = "";
+				}
 			}
-			if($section == "capabilities" && strtoupper($element[tag]) == "GET" && $element[type] == "close"){
-				$request = "";
+			else{
+				if(strtoupper($element[tag]) == "GETMAP" && $element[type] == "open"){
+					$section = "map";
+				}
+				if($section == "map" && strtoupper($element[tag]) == "GET" && $element[type] == "open"){
+					$request = "get";
+				}
+				if($section == "map" && $request == "get" && strtoupper($element[tag]) == "ONLINERESOURCE"){
+					$this->wms_getmap = $element[attributes]["xlink:href"];
+				}
+				if($section == "map" && strtoupper($element[tag]) == "FORMAT"){
+					$this->data_type[$cnt_format] = "map";
+					$this->data_format[$cnt_format] = trim($element[value]);
+					$cnt_format++;
+				}
+				if($section == "map" && strtoupper($element[tag]) == "GET" && $element[type] == "close"){
+					$request = "";
+				}
+				if(strtoupper($element[tag]) == "GETMAP" && $element[type] == "close"){
+					$section = "";
+				}
 			}
-			if(strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "close"){
-				$section = "";
+			/*capabilities section*/
+			if($this->wms_version == "1.0.0"){
+				if(strtoupper($element[tag]) == "CAPABILITIES" && $element[type] == "open"){
+					$section = "capabilities";
+				}
+				if($section == "capabilities" && strtoupper($element[tag]) == "GET"){
+					$this->wms_getcapabilities = $element[attributes][onlineResource];
+				}
+				if(strtoupper($element[tag]) == "CAPABILITIES" && $element[type] == "close"){
+					$section = "";
+				}
 			}
-		}
-		/*featureInfo section*/
-		if($this->wms_version == "1.0.0"){
-			if(strtoupper($element[tag]) == "FEATUREINFO" && $element[type] == "open"){
-				$section = "featureinfo";
+			else{
+				if(strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "open"){
+					$section = "capabilities";
+				}
+				if($section == "capabilities" && strtoupper($element[tag]) == "GET" && $element[type] == "open"){
+					$request = "get";
+				}
+				if($section == "capabilities" && $request == "get" && strtoupper($element[tag]) == "ONLINERESOURCE"){
+					$this->wms_getcapabilities = $element[attributes]["xlink:href"];
+				}
+				if($section == "capabilities" && strtoupper($element[tag]) == "GET" && $element[type] == "close"){
+					$request = "";
+				}
+				if(strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "close"){
+					$section = "";
+				}
 			}
-			if($section == "featureinfo" && strtoupper($element[tag]) == "GET"){
-				$this->wms_getfeatureinfo = $element[attributes][onlineResource];
+			/*featureInfo section*/
+			if($this->wms_version == "1.0.0"){
+				if(strtoupper($element[tag]) == "FEATUREINFO" && $element[type] == "open"){
+					$section = "featureinfo";
+				}
+				if($section == "featureinfo" && strtoupper($element[tag]) == "GET"){
+					$this->wms_getfeatureinfo = $element[attributes][onlineResource];
+				}
+				if($section == "featureinfo" && strtoupper($element[tag]) == "FORMAT" && $element[type] == "open"){
+					$format = "featureinfo";
+				}
+				if(strtoupper($element[tag]) != "FORMAT" && $section == "featureinfo" && $format == "featureinfo"){
+					$this->data_type[$cnt_format] = "featureinfo";
+					$this->data_format[$cnt_format] = trim($element[tag]);
+					$cnt_format++;
+				}
+				if(strtoupper($element[tag]) == "FORMAT" && $element[type] == "close"){
+					$format = "";
+				}
+				if(strtoupper($element[tag]) == "FEATUREINFO" && $element[type] == "close"){
+					$section = "";
+				}
 			}
-			if($section == "featureinfo" && strtoupper($element[tag]) == "FORMAT" && $element[type] == "open"){
-				$format = "featureinfo";
+			else{
+				if(strtoupper($element[tag]) == "GETFEATUREINFO" && $element[type] == "open"){
+					$section = "featureinfo";
+				}
+				if($section == "featureinfo" && strtoupper($element[tag]) == "GET" && $element[type] == "open"){
+					$request = "get";
+				}
+				if($section == "featureinfo" && $request == "get" && strtoupper($element[tag]) == "ONLINERESOURCE"){
+					$this->wms_getfeatureinfo = $element[attributes]["xlink:href"];
+				}
+				if($section == "featureinfo" && strtoupper($element[tag]) == "FORMAT"){
+					$this->data_type[$cnt_format] = "featureinfo";
+					$this->data_format[$cnt_format] = trim($element[value]);
+					$cnt_format++;
+				}
+				if($section == "featureinfo" && strtoupper($element[tag]) == "GET" && $element[type] == "close"){
+					$request = "";
+				}
+				if(strtoupper($element[tag]) == "GETFEATUREINFO" && $element[type] == "close"){
+					$section = "";
+				}
 			}
-			if(strtoupper($element[tag]) != "FORMAT" && $section == "featureinfo" && $format == "featureinfo"){
-				$this->data_type[$cnt_format] = "featureinfo";
-				$this->data_format[$cnt_format] = trim($element[tag]);
-				$cnt_format++;
+			/*exception section*/
+			if($this->wms_version == "1.0.0"){
+				if(strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "open"){
+					$section = "exception";
+				}
+				if($section == "exception" && strtoupper($element[tag]) == "FORMAT" && $element[type] == "open"){
+					$format = "exception";
+				}
+				if(strtoupper($element[tag]) != "FORMAT" && $section == "exception" && $format == "exception"){
+					$this->data_type[$cnt_format] = "exception";
+					$this->data_format[$cnt_format] = trim($element[tag]);
+					$cnt_format++;
+				}
+				if($section == "exception" && strtoupper($element[tag]) == "FORMAT" && $element[type] == "close"){
+					$format = "";
+				}
+				if(strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "close"){
+					$section = "";
+				}
 			}
-			if(strtoupper($element[tag]) == "FORMAT" && $element[type] == "close"){
-				$format = "";
+			else{
+				if(strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "open"){
+					$section = "exception";
+				}
+				if($section == "exception" && strtoupper($element[tag]) == "FORMAT"){
+					$this->data_type[$cnt_format] = "exception";
+					$this->data_format[$cnt_format] = trim($element[value]);
+					$cnt_format++;
+				}
+				if(strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "close"){
+					$section = "";
+				}
 			}
-			if(strtoupper($element[tag]) == "FEATUREINFO" && $element[type] == "close"){
-				$section = "";
+	      /*legend section*/
+	      if($this->wms_version == "1.0.0"){
+	      
+	      }
+	      else{
+	        if(strtoupper($element[tag]) == "GETLEGENDGRAPHIC" && $element[type] == "open"){
+				$section = "legend";
 			}
-		}
-		else{
-			if(strtoupper($element[tag]) == "GETFEATUREINFO" && $element[type] == "open"){
-				$section = "featureinfo";
-			}
-			if($section == "featureinfo" && strtoupper($element[tag]) == "GET" && $element[type] == "open"){
+	        if($section == "legend" && strtoupper($element[tag]) == "GET" && $element[type] == "open"){
 				$request = "get";
 			}
-			if($section == "featureinfo" && $request == "get" && strtoupper($element[tag]) == "ONLINERESOURCE"){
-				$this->wms_getfeatureinfo = $element[attributes]["xlink:href"];
+			if($section == "legend" && $request == "get" && strtoupper($element[tag]) == "ONLINERESOURCE"){
+				$this->wms_getlegendurl = $element[attributes]["xlink:href"];
 			}
-			if($section == "featureinfo" && strtoupper($element[tag]) == "FORMAT"){
-				$this->data_type[$cnt_format] = "featureinfo";
-				$this->data_format[$cnt_format] = trim($element[value]);
-				$cnt_format++;
-			}
-			if($section == "featureinfo" && strtoupper($element[tag]) == "GET" && $element[type] == "close"){
+	        if($section == "legend" && strtoupper($element[tag]) == "GET" && $element[type] == "close"){
 				$request = "";
 			}
-			if(strtoupper($element[tag]) == "GETFEATUREINFO" && $element[type] == "close"){
+			if(strtoupper($element[tag]) == "GETLEGENDGRAPHIC" && $element[type] == "close"){
 				$section = "";
+			}         
+	      }
+	      
+			/*layer section*/				
+			if(strtoupper($element[tag]) == "LAYER"){
+				$section = "layer";
+				if ($element[type] == "open") {
+					$cnt_epsg = -1;
+					$cnt_layer++;
+					$parent[$element[level]+1] = $cnt_layer;
+					$myParent[$cnt_layer]= $parent[$element[level]];
+					$this->addLayer($cnt_layer,$myParent[$cnt_layer]);
+					$this->objLayer[$cnt_layer]->layer_queryable = $element[attributes][queryable];
+				}
+				if ($element[type] == "close") {
+				
+				}
 			}
-		}
-		/*exception section*/
-		if($this->wms_version == "1.0.0"){
-			if(strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "open"){
-				$section = "exception";
+			/* styles */
+			if(strtoupper($element[tag]) == "STYLE"){
+				$section = "style";
+				if($cnt_layer != $layer_style){
+					$layer_style = $cnt_layer;
+					$cnt_styles = -1;
+				}
+				if ($element[type] == "open") {
+					$cnt_styles++;
+				}
+				if ($element[type] == "close") {
+					$section = "layer";
+				}
 			}
-			if($section == "exception" && strtoupper($element[tag]) == "FORMAT" && $element[type] == "open"){
-				$format = "exception";
+			if($section == "style"){
+				if(strtoupper($element[tag]) == "NAME"){
+					$this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["name"] = $element[value];
+				}
+				if(strtoupper($element[tag]) == "TITLE"){
+					$this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["title"] = $element[value];
+				}
+	      		if(strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "open"){
+					$legendurl = true;
+				}
+				if($legendurl && strtoupper($element[tag]) == "FORMAT"){
+					$this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["legendurlformat"] = $element[value];
+				}
+				if($legendurl && strtoupper($element[tag]) == "ONLINERESOURCE"){
+					$this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["legendurl"] = $element[attributes]["xlink:href"];
+				}
+			    if(strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "close"){
+					$legendurl = false;
+				}   
 			}
-			if(strtoupper($element[tag]) != "FORMAT" && $section == "exception" && $format == "exception"){
-				$this->data_type[$cnt_format] = "exception";
-				$this->data_format[$cnt_format] = trim($element[tag]);
-				$cnt_format++;
+			/* end of styles */
+			if($section == "layer"){
+				if(strtoupper($element[tag]) == "NAME"){
+					$this->objLayer[$cnt_layer]->layer_name = $element[value];
+				}
+				if(strtoupper($element[tag]) == "TITLE"){
+					$this->objLayer[$cnt_layer]->layer_title = $this->stripEndlineAndCarriageReturn($element[value]);
+				}
+				if(strtoupper($element[tag]) == "ABSTRACT"){
+					$this->objLayer[$cnt_layer]->layer_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
+				}
+				if(strtoupper($element[tag]) == "KEYWORD"){
+					$this->objLayer[$cnt_layer]->layer_keyword[count($this->objLayer[$cnt_layer]->layer_keyword)] = $element[value];
+				}
+	      		if(strtoupper($element[tag]) == "DATAURL" && $element[type] == "open"){
+					$dataurl = true;
+				}
+				if($dataurl && strtoupper($element[tag]) == "ONLINERESOURCE"){
+					$this->objLayer[$cnt_layer]->layer_dataurl_href = $element[attributes]["xlink:href"];
+				}
+			    if(strtoupper($element[tag]) == "DATAURL" && $element[type] == "close"){
+					$dataurl = false;
+				}   
+				
+				if(strtoupper($element[tag]) == "METADATAURL" && $element[type] == "open"){
+					$metadataurl = true;
+				}
+				if($metadataurl && strtoupper($element[tag]) == "ONLINERESOURCE"){
+					$this->objLayer[$cnt_layer]->layer_metadataurl = $element[attributes]["xlink:href"];
+				}
+			    if(strtoupper($element[tag]) == "METADATAURL" && $element[type] == "close"){
+					$metadataurl = false;
+				}   
+				
+				if(strtoupper($element[tag]) == "SRS"){
+	  				$this->objLayer[$cnt_layer]->wms_srs1 = $element[value];
+					$this->wms_srs = explode (" ", $this->objLayer[0]->wms_srs1);  				
+				}						      
+				if(strtoupper($element[tag]) == "LATLONBOUNDINGBOX"){
+					$cnt_epsg++;
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["epsg"] = "EPSG:4326";
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["minx"] = $element[attributes][minx];
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["miny"] = $element[attributes][miny];
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxx"] = $element[attributes][maxx];
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxy"] = $element[attributes][maxy];
+				}
+				if(strtoupper($element[tag]) == "BOUNDINGBOX" && $element[attributes][SRS] != "EPSG:4326"){
+					$cnt_epsg++;
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["epsg"] = $element[attributes][SRS];
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["minx"] = $element[attributes][minx];
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["miny"] = $element[attributes][miny];
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxx"] = $element[attributes][maxx];
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxy"] = $element[attributes][maxy];
+					// a default epsg for mapbender
+					if($cnt_layer == 0 && $this->default_epsg == 0 && strlen(trim($element[attributes][SRS]))>= 10){
+						$this->default_epsg = $cnt_epsg;
+					}
+				}
+				if(strtoupper($element[tag]) == "SCALEHINT"){
+					if($element[attributes][max]>1000) $max = 0; else $max = $element[attributes][max]; 	
+					if($element[attributes][min]>1000) $min = 0; else $min = $element[attributes][min]; 	
+					$this->objLayer[$cnt_layer]->layer_minscale = round(($min * 2004.3976484406788493955738891127));
+					$this->objLayer[$cnt_layer]->layer_maxscale = round(($max * 2004.3976484406788493955738891127));
+				}
+			} 
+			else {
+				continue;
 			}
-			if($section == "exception" && strtoupper($element[tag]) == "FORMAT" && $element[type] == "close"){
-				$format = "";
-			}
-			if(strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "close"){
-				$section = "";
-			}
 		}
+		if(!$this->wms_title || $this->wms_title == "" || !$this->wms_getmap || $this->wms_getmap == ""){
+			$this->wms_status = false;
+			$this->optimizeWMS();
+			return false;
+		}
 		else{
-			if(strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "open"){
-				$section = "exception";
-			}
-			if($section == "exception" && strtoupper($element[tag]) == "FORMAT"){
-				$this->data_type[$cnt_format] = "exception";
-				$this->data_format[$cnt_format] = trim($element[value]);
-				$cnt_format++;
-			}
-			if(strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "close"){
-				$section = "";
-			}
+			$this->wms_status = true;
+			$this->optimizeWMS();
+			return true;
 		}
-      /*legend section*/
-      if($this->wms_version == "1.0.0"){
-      
-      }
-      else{
-        if(strtoupper($element[tag]) == "GETLEGENDGRAPHIC" && $element[type] == "open"){
-			$section = "legend";
+	}
+	/**
+	 * private function
+	 */
+	function optimizeWMS() {
+		/*define defaults for wms-version 1.0.0*/
+		$map_default_ok = false;
+		$featureinfo_default_ok = false;
+		$exception_default_ok = false;
+		if($this->wms_version == "1.0.0"){
+			$map_default = "PNG";
+			$featureinfo_default = "MIME";
+			$exception_default = "INIMAGE";
 		}
-        if($section == "legend" && strtoupper($element[tag]) == "GET" && $element[type] == "open"){
-			$request = "get";
+		/*define defaults for wms-version 1.1.0 and 1.1.1*/
+		else{
+			$map_default = "image/png";
+			$featureinfo_default = "text/html";
+			$exception_default = "application/vnd.ogc.se_inimage";
 		}
-		if($section == "legend" && $request == "get" && strtoupper($element[tag]) == "ONLINERESOURCE"){
-			$this->wms_getlegendurl = $element[attributes]["xlink:href"];
-		}
-        if($section == "legend" && strtoupper($element[tag]) == "GET" && $element[type] == "close"){
-			$request = "";
-		}
-		if(strtoupper($element[tag]) == "GETLEGENDGRAPHIC" && $element[type] == "close"){
-			$section = "";
-		}         
-      }
-      
-		/*layer section*/				
-		if(strtoupper($element[tag]) == "LAYER"){
-			$section = "layer";
-			if ($element[type] == "open") {
-				$cnt_epsg = -1;
-				$cnt_layer++;
-				$parent[$element[level]+1] = $cnt_layer;
-				$myParent[$cnt_layer]= $parent[$element[level]];
-				$this->addLayer($cnt_layer,$myParent[$cnt_layer]);
-				$this->objLayer[$cnt_layer]->layer_queryable = $element[attributes][queryable];
+		#some default
+		$this->gui_wms_visible = 1;
+		/*if the rootlayer has no epsg...*/
+		if($this->objLayer[0]->layer_epsg[0]["epsg"] == ""){
+			$this->objLayer[0]->layer_epsg = $this->objLayer[1]->layer_epsg;
+			for($i=0;$i<count($this->objLayer[0]->layer_epsg);$i++){
+				for($j=1; $j<count($this->objLayer); $j++){
+					if($this->objLayer[0]->layer_epsg[$i]["epsg"] == $this->objLayer[$j]->layer_epsg[$i]["epsg"]){
+						if($this->objLayer[$j]->layer_epsg[$i]["minx"]<$this->objLayer[0]->layer_epsg[$i]["minx"]){
+							$this->objLayer[0]->layer_epsg[$i]["minx"] = $this->objLayer[$j]->layer_epsg[$i]["minx"];
+						}
+						if($this->objLayer[$j]->layer_epsg[$i]["miny"]<$this->objLayer[0]->layer_epsg[$i]["miny"]){
+							$this->objLayer[0]->layer_epsg[$i]["miny"] = $this->objLayer[$j]->layer_epsg[$i]["miny"];
+						}
+						if($this->objLayer[$j]->layer_epsg[$i]["maxx"]>$this->objLayer[0]->layer_epsg[$i]["maxx"]){
+							$this->objLayer[0]->layer_epsg[$i]["maxx"] = $this->objLayer[$j]->layer_epsg[$i]["maxx"];
+						}
+						if($this->objLayer[$j]->layer_epsg[$i]["maxy"]>$this->objLayer[0]->layer_epsg[$i]["maxy"]){
+							$this->objLayer[0]->layer_epsg[$i]["maxy"] = $this->objLayer[$j]->layer_epsg[$i]["maxy"];
+						}
+					}
+				}
 			}
-			if ($element[type] == "close") {
-			
-			}
 		}
-		/* styles */
-		if(strtoupper($element[tag]) == "STYLE"){
-			$section = "style";
-			if($cnt_layer != $layer_style){
-				$layer_style = $cnt_layer;
-				$cnt_styles = -1;
+		for($i=0;$i<count($this->objLayer);$i++){
+			if(count($this->objLayer[$i]->layer_epsg) == 0 && count($this->objLayer[0]->layer_epsg) > 0){
+				$this->objLayer[$i]->layer_epsg = $this->objLayer[0]->layer_epsg; 
 			}
-			if ($element[type] == "open") {
-				$cnt_styles++;
+			if(!is_int($this->objLayer[$i]->layer_parent)){
+				$this->objLayer[$i]->layer_abstract = $this->wms_abstract;
+				$this->objLayer[$i]->layer_keyword = $this->wms_keyword;
 			}
-			if ($element[type] == "close") {
-				$section = "layer";
+			if($this->objLayer[$i]->layer_name == ""){
+				$this->objLayer[$i]->layer_name = $this->objLayer[$i]->layer_title;
 			}
-		}
-		if($section == "style"){
-			if(strtoupper($element[tag]) == "NAME"){
-				$this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["name"] = $element[value];
+			if($this->objLayer[$i]->layer_minscale == ""){
+				$this->objLayer[$i]->layer_minscale = 0;
 			}
-			if(strtoupper($element[tag]) == "TITLE"){
-				$this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["title"] = $element[value];
+			if($this->objLayer[$i]->layer_maxscale == ""){
+				$this->objLayer[$i]->layer_maxscale = 0;
 			}
-      		if(strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "open"){
-				$legendurl = true;
+			if($this->objLayer[$i]->layer_queryable == ""){
+				$this->objLayer[$i]->layer_queryable = 0;
 			}
-			if($legendurl && strtoupper($element[tag]) == "FORMAT"){
-				$this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["legendurlformat"] = $element[value];
+			$this->objLayer[$i]->gui_layer_minscale = $this->objLayer[$i]->layer_minscale;
+			$this->objLayer[$i]->gui_layer_maxscale = $this->objLayer[$i]->layer_maxscale;
+		}
+		for($i=0;$i<count($this->data_format);$i++){
+			if(strtolower($this->data_type[$i]) == 'map' && strtoupper($this->data_format[$i]) == strtoupper($map_default)){
+				$this->gui_wms_mapformat = strtolower($map_default);
+				$map_default_ok = true;
 			}
-			if($legendurl && strtoupper($element[tag]) == "ONLINERESOURCE"){
-				$this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["legendurl"] = $element[attributes]["xlink:href"];
+			if(strtolower($this->data_type[$i]) == 'featureinfo' && strtoupper($this->data_format[$i]) == strtoupper($featureinfo_default)){
+				$this->gui_wms_featureinfoformat = strtolower($featureinfo_default);
+				$featureinfo_default_ok = true;
+			}		
+			if(strtolower($this->data_type[$i]) == 'exception' && strtolower($this->data_format[$i]) == strtolower($exception_default)){
+				$this->gui_wms_exceptionformat = strtolower($exception_default);
+				$exception_default_ok = true;
+			}		
+		}
+		if($map_default_ok == false){
+			for($i=0;$i<count($this->data_format);$i++){
+				if(strtolower($this->data_type[$i]) == "map" ){$this->gui_wms_mapformat = $this->data_format[$i]; break;}
 			}
-		    if(strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "close"){
-				$legendurl = false;
-			}   
 		}
-		/* end of styles */
-		if($section == "layer"){
-			if(strtoupper($element[tag]) == "NAME"){
-				$this->objLayer[$cnt_layer]->layer_name = $element[value];
+		if($featureinfo_default_ok == false){
+			for($i=0;$i<count($this->data_format);$i++){
+				if(strtolower($this->data_type[$i]) == "featureinfo" ){$this->gui_wms_featureinfoformat = $this->data_format[$i]; break;}
 			}
-			if(strtoupper($element[tag]) == "TITLE"){
-				$this->objLayer[$cnt_layer]->layer_title = $this->stripEndlineAndCarriageReturn($element[value]);
-			}
-			if(strtoupper($element[tag]) == "ABSTRACT"){
-				$this->objLayer[$cnt_layer]->layer_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
-			}
-			if(strtoupper($element[tag]) == "KEYWORD"){
-				$this->objLayer[$cnt_layer]->layer_keyword[count($this->objLayer[$cnt_layer]->layer_keyword)] = $element[value];
-			}
-      		if(strtoupper($element[tag]) == "DATAURL" && $element[type] == "open"){
-				$dataurl = true;
-			}
-			if($dataurl && strtoupper($element[tag]) == "ONLINERESOURCE"){
-				$this->objLayer[$cnt_layer]->layer_dataurl_href = $element[attributes]["xlink:href"];
-			}
-		    if(strtoupper($element[tag]) == "DATAURL" && $element[type] == "close"){
-				$dataurl = false;
-			}   
-			
-			if(strtoupper($element[tag]) == "METADATAURL" && $element[type] == "open"){
-				$metadataurl = true;
-			}
-			if($metadataurl && strtoupper($element[tag]) == "ONLINERESOURCE"){
-				$this->objLayer[$cnt_layer]->layer_metadataurl = $element[attributes]["xlink:href"];
-			}
-		    if(strtoupper($element[tag]) == "METADATAURL" && $element[type] == "close"){
-				$metadataurl = false;
-			}   
-			
-			if(strtoupper($element[tag]) == "SRS"){
-  				$this->objLayer[$cnt_layer]->wms_srs1 = $element[value];
-				$this->wms_srs = explode (" ", $this->objLayer[0]->wms_srs1);  				
-			}						      
-			if(strtoupper($element[tag]) == "LATLONBOUNDINGBOX"){
-				$cnt_epsg++;
-				$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["epsg"] = "EPSG:4326";
-				$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["minx"] = $element[attributes][minx];
-				$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["miny"] = $element[attributes][miny];
-				$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxx"] = $element[attributes][maxx];
-				$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxy"] = $element[attributes][maxy];
-			}
-			if(strtoupper($element[tag]) == "BOUNDINGBOX" && $element[attributes][SRS] != "EPSG:4326"){
-				$cnt_epsg++;
-				$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["epsg"] = $element[attributes][SRS];
-				$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["minx"] = $element[attributes][minx];
-				$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["miny"] = $element[attributes][miny];
-				$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxx"] = $element[attributes][maxx];
-				$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxy"] = $element[attributes][maxy];
-				// a default epsg for mapbender
-				if($cnt_layer == 0 && $this->default_epsg == 0 && strlen(trim($element[attributes][SRS]))>= 10){
-					$this->default_epsg = $cnt_epsg;
-				}
-			}
-			if(strtoupper($element[tag]) == "SCALEHINT"){
-				if($element[attributes][max]>1000) $max = 0; else $max = $element[attributes][max]; 	
-				if($element[attributes][min]>1000) $min = 0; else $min = $element[attributes][min]; 	
-				$this->objLayer[$cnt_layer]->layer_minscale = round(($min * 2004.3976484406788493955738891127));
-				$this->objLayer[$cnt_layer]->layer_maxscale = round(($max * 2004.3976484406788493955738891127));
-			}
-		} 
-		else {
-			continue;
 		}
-	}
-	if(!$this->wms_title || $this->wms_title == "" || !$this->wms_getmap || $this->wms_getmap == ""){
-		$this->wms_status = false;
-		$this->optimizeWMS();
-		return false;
-	}
-	else{
-		$this->wms_status = true;
-		$this->optimizeWMS();
-		return true;
-	}
-}
-function optimizeWMS(){
-	/*define defaults for wms-version 1.0.0*/
-	$map_default_ok = false;
-	$featureinfo_default_ok = false;
-	$exception_default_ok = false;
-	if($this->wms_version == "1.0.0"){
-		$map_default = "PNG";
-		$featureinfo_default = "MIME";
-		$exception_default = "INIMAGE";
-	}
-	/*define defaults for wms-version 1.1.0 and 1.1.1*/
-	else{
-		$map_default = "image/png";
-		$featureinfo_default = "text/html";
-		$exception_default = "application/vnd.ogc.se_inimage";
-	}
-	#some default
-	$this->gui_wms_visible = 1;
-	/*if the rootlayer has no epsg...*/
-	if($this->objLayer[0]->layer_epsg[0]["epsg"] == ""){
-		$this->objLayer[0]->layer_epsg = $this->objLayer[1]->layer_epsg;
-		for($i=0;$i<count($this->objLayer[0]->layer_epsg);$i++){
-			for($j=1; $j<count($this->objLayer); $j++){
-				if($this->objLayer[0]->layer_epsg[$i]["epsg"] == $this->objLayer[$j]->layer_epsg[$i]["epsg"]){
-					if($this->objLayer[$j]->layer_epsg[$i]["minx"]<$this->objLayer[0]->layer_epsg[$i]["minx"]){
-						$this->objLayer[0]->layer_epsg[$i]["minx"] = $this->objLayer[$j]->layer_epsg[$i]["minx"];
-					}
-					if($this->objLayer[$j]->layer_epsg[$i]["miny"]<$this->objLayer[0]->layer_epsg[$i]["miny"]){
-						$this->objLayer[0]->layer_epsg[$i]["miny"] = $this->objLayer[$j]->layer_epsg[$i]["miny"];
-					}
-					if($this->objLayer[$j]->layer_epsg[$i]["maxx"]>$this->objLayer[0]->layer_epsg[$i]["maxx"]){
-						$this->objLayer[0]->layer_epsg[$i]["maxx"] = $this->objLayer[$j]->layer_epsg[$i]["maxx"];
-					}
-					if($this->objLayer[$j]->layer_epsg[$i]["maxy"]>$this->objLayer[0]->layer_epsg[$i]["maxy"]){
-						$this->objLayer[0]->layer_epsg[$i]["maxy"] = $this->objLayer[$j]->layer_epsg[$i]["maxy"];
-					}
-				}
+		if($exception_default_ok == false){
+			for($i=0;$i<count($this->data_format);$i++){
+				if(strtolower($this->data_type[$i]) == "exception" ){$this->gui_wms_exceptionformat = $this->data_format[$i]; break;}
 			}
 		}
-	}
-	for($i=0;$i<count($this->objLayer);$i++){
-		if(count($this->objLayer[$i]->layer_epsg) == 0 && count($this->objLayer[0]->layer_epsg) > 0){
-			$this->objLayer[$i]->layer_epsg = $this->objLayer[0]->layer_epsg; 
+		
+		if(count($this->objLayer[0]->layer_epsg)>1){
+			$this->gui_wms_epsg = $this->objLayer[0]->layer_epsg[$this->default_epsg][epsg];
 		}
-		if(!is_int($this->objLayer[$i]->layer_parent)){
-			$this->objLayer[$i]->layer_abstract = $this->wms_abstract;
-			$this->objLayer[$i]->layer_keyword = $this->wms_keyword;
+		else{
+			$this->gui_wms_epsg = $this->objLayer[0]->layer_epsg[0][epsg];
 		}
-		if($this->objLayer[$i]->layer_name == ""){
-			$this->objLayer[$i]->layer_name = $this->objLayer[$i]->layer_title;
+		/*the queryable layers*/
+		for($i=0; $i<count($this->objLayer); $i++){
+			if($this->objLayer[$i]->layer_queryable == 1){
+				$this->objLayer[$i]->gui_layer_queryable = 1;
+			}
+			else{
+				$this->objLayer[$i]->gui_layer_queryable = 0;
+			}
 		}
-		if($this->objLayer[$i]->layer_minscale == ""){
-			$this->objLayer[$i]->layer_minscale = 0;
+		for($i=0; $i<count($this->objLayer); $i++){
+				$this->objLayer[$i]->layer_pos=$i;
 		}
-		if($this->objLayer[$i]->layer_maxscale == ""){
-			$this->objLayer[$i]->layer_maxscale = 0;
+	  }
+	function displayWMS(){
+		echo "<br>id: " . $this->wms_id . " <br>";
+		echo "version: " . $this->wms_version . " <br>";
+		echo "title: " . $this->wms_title . " <br>";
+		echo "abstract: " . $this->wms_abstract . " <br>";
+		echo "maprequest: " . $this->wms_getmap . " <br>";
+		echo "capabilitiesrequest: " . $this->wms_getcapabilities . " <br>";
+		echo "featureinforequest: " . $this->wms_getfeatureinfo . " <br>";
+		echo "gui_wms_mapformat: " . $this->gui_wms_mapformat . " <br>";
+		echo "gui_wms_featureinfoformat: " . $this->gui_wms_featureinfoformat . " <br>";
+		echo "gui_wms_exceptionformat: " . $this->gui_wms_exceptionformat . " <br>";	
+		echo "gui_wms_epsg: " . $this->gui_wms_epsg . " <br>";
+		echo "wms_srs: " . $this->objLayer[0]->wms_srs1 . " <br>";		
+		echo "gui_wms_visible: " . $this->gui_wms_visible . " <br>";
+		
+		for($i=0; $i<count($this->data_type);$i++){
+			echo $this->data_type[$i]. " -> ".$this->data_format[$i]. "<br>";
 		}
-		if($this->objLayer[$i]->layer_queryable == ""){
-			$this->objLayer[$i]->layer_queryable = 0;
+		for($i=0; $i<count($this->objLayer); $i++){
+			echo "<hr>";
+			echo "id: <b>".$this->objLayer[$i]->layer_id ."</b> parent: <b>".$this->objLayer[$i]->layer_parent."</b> name: <b>".$this->objLayer[$i]->layer_name;
+			echo "</b> title: <b>".$this->objLayer[$i]->layer_title. "</b> queryable: <b>".$this->objLayer[$i]->layer_queryable."</b> minScale: <b>". $this->objLayer[$i]->layer_minscale."</b> maxScale: <b>".$this->objLayer[$i]->layer_maxscale."</b>";
+			echo "<br>dataurl: <b>".$this->objLayer[$i]->layer_dataurl_href. "</b>";
+			echo "<br>metadataurl: <b>".$this->objLayer[$i]->layer_metadataurl. "</b>";
+			echo "<table border='1'>";
+			for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
+				echo "<tr><td>".$this->objLayer[$i]->layer_epsg[$j][epsg]."</td><td>".$this->objLayer[$i]->layer_epsg[$j][minx]."</td>";
+				echo "<td>".$this->objLayer[$i]->layer_epsg[$j][miny]."</td><td>".$this->objLayer[$i]->layer_epsg[$j][maxx]."</td>";
+				echo "<td>".$this->objLayer[$i]->layer_epsg[$j][maxy]."</td></tr>";
+			}
+			echo "</table>";
+			echo "layerstyle:";
+			echo "<table border='1'>";
+			echo "<tr><td>name</td><td>title</td><td>legendurl</td><td>legendurlformat</td></tr>";
+			for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
+				echo "<tr><td>".$this->objLayer[$i]->layer_style[$j][name]."</td><td>".$this->objLayer[$i]->layer_style[$j][title]."</td><td>".$this->objLayer[$i]->layer_style[$j][legendurl]."</td><td>".$this->objLayer[$i]->layer_style[$j][legendurlformat]."</td></tr>";
+			}
+			echo "</table>";
+	        echo "<hr>";
+	        echo "<hr>";
 		}
-		$this->objLayer[$i]->gui_layer_minscale = $this->objLayer[$i]->layer_minscale;
-		$this->objLayer[$i]->gui_layer_maxscale = $this->objLayer[$i]->layer_maxscale;
-	}
-	for($i=0;$i<count($this->data_format);$i++){
-		if(strtolower($this->data_type[$i]) == 'map' && strtoupper($this->data_format[$i]) == strtoupper($map_default)){
-			$this->gui_wms_mapformat = strtolower($map_default);
-			$map_default_ok = true;
+	} 
+	  function addLayer($id,$parent){	
+		$this->objLayer[count($this->objLayer)] = new layer($id,$parent);
+	  }
+	  /**
+	   * private function
+	   */
+	  function stripEndlineAndCarriageReturn($string) {
+	  	return str_replace(chr(13), "", str_replace(chr(10), " ", $string));
+	  }
+	  function createJsObjFromWMS($parent=0){
+	  	if(!$this->wms_title || $this->wms_title == ""){
+			echo "alert('Error: no valid capabilities-document !!');";
+			die; exit;
 		}
-		if(strtolower($this->data_type[$i]) == 'featureinfo' && strtoupper($this->data_format[$i]) == strtoupper($featureinfo_default)){
-			$this->gui_wms_featureinfoformat = strtolower($featureinfo_default);
-			$featureinfo_default_ok = true;
-		}		
-		if(strtolower($this->data_type[$i]) == 'exception' && strtolower($this->data_format[$i]) == strtolower($exception_default)){
-			$this->gui_wms_exceptionformat = strtolower($exception_default);
-			$exception_default_ok = true;
-		}		
-	}
-	if($map_default_ok == false){
+			if($parent){
+				echo "parent.";
+			}
+			// wms_title and abstract have previously been urlencoded
+			// this solution may not yet be the ultimate one
+			
+			$add_wms_string = "add_wms(" .
+					"'" . $this->wms_id ."'," .
+					"'" . $this->wms_version ."'," .
+					"'" . addslashes($this->wms_title) . "'," .
+					"'" . addslashes($this->wms_abstract) ."'," .
+					"'" . $this->wms_getmap ."'," .
+					"'" . $this->wms_getfeatureinfo ."'," .
+					"'" . $this->wms_getlegendurl ."'," .
+					"'" . $this->wms_filter ."'," .
+					"'" . $this->gui_wms_mapformat . "'," .
+					"'" . $this->gui_wms_featureinfoformat . "'," .
+					"'" . $this->gui_wms_exceptionformat . "'," .
+					"'" . $this->gui_wms_epsg ."'," .
+					"'" . $this->gui_wms_visible ."" .
+					"');";
+			echo $add_wms_string;
+			
 		for($i=0;$i<count($this->data_format);$i++){
-			if(strtolower($this->data_type[$i]) == "map" ){$this->gui_wms_mapformat = $this->data_format[$i]; break;}
+			if($parent){
+				echo "parent.";
+			}		
+			echo "wms_add_data_type_format('". $this->data_type[$i] ."','". $this->data_format[$i] ."');\n";		
 		}
-	}
-	if($featureinfo_default_ok == false){
-		for($i=0;$i<count($this->data_format);$i++){
-			if(strtolower($this->data_type[$i]) == "featureinfo" ){$this->gui_wms_featureinfoformat = $this->data_format[$i]; break;}
-		}
-	}
-	if($exception_default_ok == false){
-		for($i=0;$i<count($this->data_format);$i++){
-			if(strtolower($this->data_type[$i]) == "exception" ){$this->gui_wms_exceptionformat = $this->data_format[$i]; break;}
-		}
-	}
-	
-	if(count($this->objLayer[0]->layer_epsg)>1){
-		$this->gui_wms_epsg = $this->objLayer[0]->layer_epsg[$this->default_epsg][epsg];
-	}
-	else{
-		$this->gui_wms_epsg = $this->objLayer[0]->layer_epsg[0][epsg];
-	}
-	/*the queryable layers*/
-	for($i=0; $i<count($this->objLayer); $i++){
-		if($this->objLayer[$i]->layer_queryable == 1){
-			$this->objLayer[$i]->gui_layer_queryable = 1;
-		}
-		else{
-			$this->objLayer[$i]->gui_layer_queryable = 0;
-		}
-	}
-	for($i=0; $i<count($this->objLayer); $i++){
-			$this->objLayer[$i]->layer_pos=$i;
-	}
-  }
-function displayWMS(){
-	echo "<br>id: " . $this->wms_id . " <br>";
-	echo "version: " . $this->wms_version . " <br>";
-	echo "title: " . $this->wms_title . " <br>";
-	echo "abstract: " . $this->wms_abstract . " <br>";
-	echo "maprequest: " . $this->wms_getmap . " <br>";
-	echo "capabilitiesrequest: " . $this->wms_getcapabilities . " <br>";
-	echo "featureinforequest: " . $this->wms_getfeatureinfo . " <br>";
-	echo "gui_wms_mapformat: " . $this->gui_wms_mapformat . " <br>";
-	echo "gui_wms_featureinfoformat: " . $this->gui_wms_featureinfoformat . " <br>";
-	echo "gui_wms_exceptionformat: " . $this->gui_wms_exceptionformat . " <br>";	
-	echo "gui_wms_epsg: " . $this->gui_wms_epsg . " <br>";
-	echo "wms_srs: " . $this->objLayer[0]->wms_srs1 . " <br>";		
-	echo "gui_wms_visible: " . $this->gui_wms_visible . " <br>";
-	
-	for($i=0; $i<count($this->data_type);$i++){
-		echo $this->data_type[$i]. " -> ".$this->data_format[$i]. "<br>";
-	}
-	for($i=0; $i<count($this->objLayer); $i++){
-		echo "<hr>";
-		echo "id: <b>".$this->objLayer[$i]->layer_id ."</b> parent: <b>".$this->objLayer[$i]->layer_parent."</b> name: <b>".$this->objLayer[$i]->layer_name;
-		echo "</b> title: <b>".$this->objLayer[$i]->layer_title. "</b> queryable: <b>".$this->objLayer[$i]->layer_queryable."</b> minScale: <b>". $this->objLayer[$i]->layer_minscale."</b> maxScale: <b>".$this->objLayer[$i]->layer_maxscale."</b>";
-		echo "<br>dataurl: <b>".$this->objLayer[$i]->layer_dataurl_href. "</b>";
-		echo "<br>metadataurl: <b>".$this->objLayer[$i]->layer_metadataurl. "</b>";
-		echo "<table border='1'>";
-		for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
-			echo "<tr><td>".$this->objLayer[$i]->layer_epsg[$j][epsg]."</td><td>".$this->objLayer[$i]->layer_epsg[$j][minx]."</td>";
-			echo "<td>".$this->objLayer[$i]->layer_epsg[$j][miny]."</td><td>".$this->objLayer[$i]->layer_epsg[$j][maxx]."</td>";
-			echo "<td>".$this->objLayer[$i]->layer_epsg[$j][maxy]."</td></tr>";
-		}
-		echo "</table>";
-		echo "layerstyle:";
-		echo "<table border='1'>";
-		echo "<tr><td>name</td><td>title</td><td>legendurl</td><td>legendurlformat</td></tr>";
-		for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
-			echo "<tr><td>".$this->objLayer[$i]->layer_style[$j][name]."</td><td>".$this->objLayer[$i]->layer_style[$j][title]."</td><td>".$this->objLayer[$i]->layer_style[$j][legendurl]."</td><td>".$this->objLayer[$i]->layer_style[$j][legendurlformat]."</td></tr>";
-		}
-		echo "</table>";
-        echo "<hr>";
-        echo "<hr>";
-	}
-} 
-  function addLayer($id,$parent){	
-	$this->objLayer[count($this->objLayer)] = new layer($id,$parent);
-  }
-  function stripEndlineAndCarriageReturn($string) {
-  	return str_replace(chr(13), "", str_replace(chr(10), " ", $string));
-  }
-  function createJsObjFromWMS($parent=0){
-  	if(!$this->wms_title || $this->wms_title == ""){
-		echo "alert('Error: no valid capabilities-document !!');";
-		die; exit;
-	}
-		if($parent){
-			echo "parent.";
-		}
-		// wms_title and abstract have previously been urlencoded
-		// this solution may not yet be the ultimate one
-		print("add_wms('". 
-		$this->wms_id ."','".
-		$this->wms_version ."','".
-		str_replace("'", "", $this->wms_title) ."','".
-		str_replace("'", "", $this->wms_abstract) ."','". 
-		$this->wms_getmap ."','" .
-		$this->wms_getfeatureinfo ."','".
-		$this->wms_getlegendurl ."','".
-		$this->wms_filter ."','".
-		$this->gui_wms_mapformat ."','". 
-		$this->gui_wms_featureinfoformat ."','". 
-		$this->gui_wms_exceptionformat . "','". 
-		$this->gui_wms_epsg ."','". 
-		$this->gui_wms_visible ."');\n");
-		
-	for($i=0;$i<count($this->data_format);$i++){
-		if($parent){
-			echo "parent.";
-		}		
-		echo "wms_add_data_type_format('". $this->data_type[$i] ."','". $this->data_format[$i] ."');\n";		
-	}
-	for($i=0; $i<count($this->objLayer); $i++){
-		if($parent){
-			echo "parent.";
-		}
-		print ("wms_add_layer('". 
-			$this->objLayer[$i]->layer_parent ."','". 
-			$this->objLayer[$i]->layer_uid ."','". 
-			$this->objLayer[$i]->layer_name . "','". 
-			addslashes($this->objLayer[$i]->layer_title) ."','". 
-			$this->objLayer[$i]->layer_dataurl_href ."','". 
-			$this->objLayer[$i]->layer_pos ."','". 
-			$this->objLayer[$i]->layer_queryable ."','". 
-			$this->objLayer[$i]->layer_minscale . "','". 
-			$this->objLayer[$i]->layer_maxscale ."','". 
-			$this->objLayer[$i]->layer_metadataurl ."','". 
-			$this->objLayer[$i]->gui_layer_wms_id ."','". 
-			$this->objLayer[$i]->gui_layer_status ."','". 
-			$this->objLayer[$i]->gui_layer_selectable ."','". 
-			$this->objLayer[$i]->gui_layer_visible ."','". 
-			$this->objLayer[$i]->gui_layer_queryable ."','". 
-			$this->objLayer[$i]->gui_layer_querylayer ."','". 
-			$this->objLayer[$i]->gui_layer_minscale ."','". 
-			$this->objLayer[$i]->gui_layer_maxscale ."','".
-			$this->objLayer[$i]->gui_layer_wfs_featuretype ."');\n");
-		for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
-			if($i==0){
+		for($i=0; $i<count($this->objLayer); $i++){
+			if($parent){
+				echo "parent.";
+			}
+			print ("wms_add_layer('". 
+				$this->objLayer[$i]->layer_parent ."','". 
+				$this->objLayer[$i]->layer_uid ."','". 
+				addslashes($this->objLayer[$i]->layer_name) . "','". 
+				addslashes($this->objLayer[$i]->layer_title) ."','". 
+				$this->objLayer[$i]->layer_dataurl_href ."','". 
+				$this->objLayer[$i]->layer_pos ."','". 
+				$this->objLayer[$i]->layer_queryable ."','". 
+				$this->objLayer[$i]->layer_minscale . "','". 
+				$this->objLayer[$i]->layer_maxscale ."','". 
+				$this->objLayer[$i]->layer_metadataurl ."','". 
+				$this->objLayer[$i]->gui_layer_wms_id ."','". 
+				$this->objLayer[$i]->gui_layer_status ."','". 
+				$this->objLayer[$i]->gui_layer_selectable ."','". 
+				$this->objLayer[$i]->gui_layer_visible ."','". 
+				$this->objLayer[$i]->gui_layer_queryable ."','". 
+				$this->objLayer[$i]->gui_layer_querylayer ."','". 
+				$this->objLayer[$i]->gui_layer_minscale ."','". 
+				$this->objLayer[$i]->gui_layer_maxscale ."','".
+				$this->objLayer[$i]->gui_layer_wfs_featuretype ."');\n");
+				
+			for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
+				if($i==0){
+					if($parent){
+					echo "parent.";
+					}
+					print("wms_addSRS('". 
+						$this->objLayer[$i]->layer_epsg[$j]["epsg"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["minx"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["miny"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["maxx"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');\n");
+				}
 				if($parent){
 				echo "parent.";
 				}
-				print("wms_addSRS('". 
+				print("layer_addEpsg('". 
 					$this->objLayer[$i]->layer_epsg[$j]["epsg"] ."','". 
 					$this->objLayer[$i]->layer_epsg[$j]["minx"] ."','". 
 					$this->objLayer[$i]->layer_epsg[$j]["miny"] ."','". 
 					$this->objLayer[$i]->layer_epsg[$j]["maxx"] ."','". 
 					$this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');\n");
 			}
-			if($parent){
-			echo "parent.";
+			for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
+				if($parent){
+				echo "parent.";
+				}
+				print("wms_addLayerStyle('".$this->objLayer[$i]->layer_style[$j]["name"]."', '".$this->objLayer[$i]->layer_style[$j]["title"]."', ".$j.",".$i.",'".$this->objLayer[$i]->layer_style[$j]["legendurl"]."', '".$this->objLayer[$i]->layer_style[$j]["legendformat"]."');\n");
 			}
-			print("layer_addEpsg('". 
-				$this->objLayer[$i]->layer_epsg[$j]["epsg"] ."','". 
-				$this->objLayer[$i]->layer_epsg[$j]["minx"] ."','". 
-				$this->objLayer[$i]->layer_epsg[$j]["miny"] ."','". 
-				$this->objLayer[$i]->layer_epsg[$j]["maxx"] ."','". 
-				$this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');\n");
 		}
-		for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
+	  }
+	  
+	  function createJsLayerObjFromWMS($parent=0, $layer_name){
+	  	if(!$this->wms_title || $this->wms_title == ""){
+			echo " alert('Error: no valid capabilities-document !!');";
+			die; exit;
+		}
 			if($parent){
-			echo "parent.";
+				echo "parent.";
 			}
-			print("wms_addLayerStyle('".$this->objLayer[$i]->layer_style[$j]["name"]."', '".$this->objLayer[$i]->layer_style[$j]["title"]."', ".$j.",".$i.",'".$this->objLayer[$i]->layer_style[$j]["legendurl"]."', '".$this->objLayer[$i]->layer_style[$j]["legendformat"]."');\n");
-		}
-	}
-  }
-  
-  function createJsLayerObjFromWMS($parent=0, $layer_name){
-  	if(!$this->wms_title || $this->wms_title == ""){
-		echo " alert('Error: no valid capabilities-document !!');";
-		die; exit;
-	}
-		if($parent){
-			echo "parent.";
-		}
-		// wms_title and abstract have previously been urlencoded
-		// this solution may not yet be the ultimate one
-		print("add_wms('". 
-		$this->wms_id ."','".
-		$this->wms_version ."','".
-		str_replace("'", "", $this->wms_title) ."','".
-		str_replace("'", "", $this->wms_abstract) ."','". 
-		$this->wms_getmap ."','" .
-		$this->wms_getfeatureinfo ."','".
-		$this->wms_getlegendurl ."','".
-		$this->wms_filter ."','".
-		$this->gui_wms_mapformat ."','". 
-		$this->gui_wms_featureinfoformat ."','". 
-		$this->gui_wms_exceptionformat . "','". 
-		$this->gui_wms_epsg ."','". 
-		$this->gui_wms_visible ."');\n");
-		
-	for($i=0;$i<count($this->data_format);$i++){
-		if($parent){
-			echo "parent.";
-		}		
-		echo "wms_add_data_type_format('". $this->data_type[$i] ."','". $this->data_format[$i] ."');\n";		
-	}
-	for($i=0; $i<count($this->objLayer); $i++){
-		if($this->objLayer[$i]->layer_name == $layer_name|| $this->objLayer[$i]->layer_pos == 0){
-		
+			// wms_title and abstract have previously been urlencoded
+			// this solution may not yet be the ultimate one
+			print("add_wms('". 
+			$this->wms_id ."','".
+			$this->wms_version ."','".
+			str_replace("'", "", $this->wms_title) ."','".
+			str_replace("'", "", $this->wms_abstract) ."','". 
+			$this->wms_getmap ."','" .
+			$this->wms_getfeatureinfo ."','".
+			$this->wms_getlegendurl ."','".
+			$this->wms_filter ."','".
+			$this->gui_wms_mapformat ."','". 
+			$this->gui_wms_featureinfoformat ."','". 
+			$this->gui_wms_exceptionformat . "','". 
+			$this->gui_wms_epsg ."','". 
+			$this->gui_wms_visible ."');\n");
+			
+		for($i=0;$i<count($this->data_format);$i++){
 			if($parent){
 				echo "parent.";
-			}
-		 print ("wms_add_layer('". 
-			$this->objLayer[$i]->layer_parent ."','". 
-			$this->objLayer[$i]->layer_uid ."','". 
-			$this->objLayer[$i]->layer_name . "','". 
-			addslashes($this->objLayer[$i]->layer_title) ."','". 
-			$this->objLayer[$i]->layer_dataurl_href ."','". 
-			$this->objLayer[$i]->layer_pos ."','". 
-			$this->objLayer[$i]->layer_queryable ."','". 
-			$this->objLayer[$i]->layer_minscale . "','". 
-			$this->objLayer[$i]->layer_maxscale ."','". 
-			$this->objLayer[$i]->layer_metadataurl ."','". 
-			$this->objLayer[$i]->gui_layer_wms_id ."','". 
-			$this->objLayer[$i]->gui_layer_status ."','". 
-			$this->objLayer[$i]->gui_layer_selectable ."','". 
-			$this->objLayer[$i]->gui_layer_visible ."','". 
-			$this->objLayer[$i]->gui_layer_queryable ."','". 
-			$this->objLayer[$i]->gui_layer_querylayer ."','". 
-			$this->objLayer[$i]->gui_layer_minscale ."','". 
-			$this->objLayer[$i]->gui_layer_maxscale ."','".
-			$this->objLayer[$i]->gui_layer_wfs_featuretype ."');\n");
-		for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
-			if($i==0){
+			}		
+			echo "wms_add_data_type_format('". $this->data_type[$i] ."','". $this->data_format[$i] ."');\n";		
+		}
+		for($i=0; $i<count($this->objLayer); $i++){
+			if($this->objLayer[$i]->layer_name == $layer_name|| $this->objLayer[$i]->layer_pos == 0){
+			
 				if($parent){
+					echo "parent.";
+				}
+			 print ("wms_add_layer('". 
+				$this->objLayer[$i]->layer_parent ."','". 
+				$this->objLayer[$i]->layer_uid ."','". 
+				$this->objLayer[$i]->layer_name . "','". 
+				addslashes($this->objLayer[$i]->layer_title) ."','". 
+				$this->objLayer[$i]->layer_dataurl_href ."','". 
+				$this->objLayer[$i]->layer_pos ."','". 
+				$this->objLayer[$i]->layer_queryable ."','". 
+				$this->objLayer[$i]->layer_minscale . "','". 
+				$this->objLayer[$i]->layer_maxscale ."','". 
+				$this->objLayer[$i]->layer_metadataurl ."','". 
+				$this->objLayer[$i]->gui_layer_wms_id ."','". 
+				$this->objLayer[$i]->gui_layer_status ."','". 
+				$this->objLayer[$i]->gui_layer_selectable ."','". 
+				$this->objLayer[$i]->gui_layer_visible ."','". 
+				$this->objLayer[$i]->gui_layer_queryable ."','". 
+				$this->objLayer[$i]->gui_layer_querylayer ."','". 
+				$this->objLayer[$i]->gui_layer_minscale ."','". 
+				$this->objLayer[$i]->gui_layer_maxscale ."','".
+				$this->objLayer[$i]->gui_layer_wfs_featuretype ."');\n");
+			for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
+				if($i==0){
+					if($parent){
+					echo "parent.";
+					}
+					print("wms_addSRS('". 
+						$this->objLayer[$i]->layer_epsg[$j]["epsg"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["minx"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["miny"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["maxx"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');\n");
+				}
+				if($parent){
 				echo "parent.";
 				}
-				print("wms_addSRS('". 
+				print("layer_addEpsg('". 
 					$this->objLayer[$i]->layer_epsg[$j]["epsg"] ."','". 
 					$this->objLayer[$i]->layer_epsg[$j]["minx"] ."','". 
 					$this->objLayer[$i]->layer_epsg[$j]["miny"] ."','". 
 					$this->objLayer[$i]->layer_epsg[$j]["maxx"] ."','". 
 					$this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');\n");
 			}
-			if($parent){
-			echo "parent.";
+			for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
+				if($parent){
+				echo "parent.";
+				}
+				print("wms_addLayerStyle('".$this->objLayer[$i]->layer_style[$j]["name"]."', '".$this->objLayer[$i]->layer_style[$j]["title"]."', ".$j.",".$i.",'".$this->objLayer[$i]->layer_style[$j]["legendurl"]."', '".$this->objLayer[$i]->layer_style[$j]["legendformat"]."');\n");
 			}
-			print("layer_addEpsg('". 
-				$this->objLayer[$i]->layer_epsg[$j]["epsg"] ."','". 
-				$this->objLayer[$i]->layer_epsg[$j]["minx"] ."','". 
-				$this->objLayer[$i]->layer_epsg[$j]["miny"] ."','". 
-				$this->objLayer[$i]->layer_epsg[$j]["maxx"] ."','". 
-				$this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');\n");
+		   }	
 		}
-		for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
-			if($parent){
-			echo "parent.";
-			}
-			print("wms_addLayerStyle('".$this->objLayer[$i]->layer_style[$j]["name"]."', '".$this->objLayer[$i]->layer_style[$j]["title"]."', ".$j.",".$i.",'".$this->objLayer[$i]->layer_style[$j]["legendurl"]."', '".$this->objLayer[$i]->layer_style[$j]["legendformat"]."');\n");
+	  }
+	  
+	  
+	/**
+	* writeObjInDB
+	*
+	* this function exports the information from the xml to the mapbender database 
+	*/
+	function writeObjInDB($gui_id){
+		$this->checkObj();
+		db_begin();
+	
+		# TABLE wms
+		$sql = "INSERT INTO wms (wms_version, wms_title, wms_abstract, wms_getcapabilities, wms_getmap, ";
+		$sql.= "wms_getfeatureinfo, wms_getlegendurl, wms_getcapabilities_doc, wms_upload_url, fees, ";
+		$sql .= "accessconstraints, contactperson, contactposition, contactorganization, address, city, ";
+		$sql .= "stateorprovince, postcode, country, contactvoicetelephone, contactfacsimiletelephone, contactelectronicmailaddress, ";
+		$sql .= "wms_owner,wms_timestamp) ";
+		$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24)";
+		$v = array($this->wms_version,$this->wms_title,$this->wms_abstract,$this->wms_getcapabilities,
+			$this->wms_getmap,$this->wms_getfeatureinfo,$this->wms_getlegendurl,$this->wms_getcapabilities_doc,
+			$this->wms_upload_url,$this->fees,$this->accessconstraints,$this->contactperson,$this->contactposition,
+			$this->contactorganization,$this->address,$this->city,$this->stateorprovince,$this->postcode,$this->country,
+			$this->contactvoicetelephone,$this->contactfacsimiletelephone,$this->contactelectronicmailaddress,
+			$_SESSION['mb_user_id'],strtotime("now"));
+		$t = array('s','s','s','s','s','s','s','s','s','s','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();
 		}
-	   }	
-	}
-  }
-  
-  
-/**
-* writeObjInDB
-*
-* this function exports the information from the xml to the mapbender database 
-*/
-function writeObjInDB($gui_id){
-	$this->checkObj();
-	db_begin();
-
-	# TABLE wms
-	$sql = "INSERT INTO wms (wms_version, wms_title, wms_abstract, wms_getcapabilities, wms_getmap, ";
-	$sql.= "wms_getfeatureinfo, wms_getlegendurl, wms_getcapabilities_doc, wms_upload_url, fees, ";
-	$sql .= "accessconstraints, contactperson, contactposition, contactorganization, address, city, ";
-	$sql .= "stateorprovince, postcode, country, contactvoicetelephone, contactfacsimiletelephone, contactelectronicmailaddress, ";
-	$sql .= "wms_owner,wms_timestamp) ";
-	$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24)";
-	$v = array($this->wms_version,$this->wms_title,$this->wms_abstract,$this->wms_getcapabilities,
-		$this->wms_getmap,$this->wms_getfeatureinfo,$this->wms_getlegendurl,$this->wms_getcapabilities_doc,
-		$this->wms_upload_url,$this->fees,$this->accessconstraints,$this->contactperson,$this->contactposition,
-		$this->contactorganization,$this->address,$this->city,$this->stateorprovince,$this->postcode,$this->country,
-		$this->contactvoicetelephone,$this->contactfacsimiletelephone,$this->contactelectronicmailaddress,
-		$_SESSION['mb_user_id'],strtotime("now"));
-	$t = array('s','s','s','s','s','s','s','s','s','s','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();
-	}
-	
-	$myWMS = db_insert_id($con,'wms', 'wms_id');
-	
-	# TABLE layer and gui_layer
-	
-	for($i=0; $i<count($this->objLayer); $i++){
-		$this->insertLayer($i,$myWMS,$gui_id);
-		$this->insertGuiLayer($i,$myWMS,$gui_id);
-	}	
 		
-	
-	#TABLE wms_srs
-	$this->insertSRS($myWMS);	
-	
-	# TABLE wms_format	
-	$this->insertFormat($myWMS);	
+		$myWMS = db_insert_id($con,'wms', 'wms_id');
 		
-	# TABLE gui_wms
-	
-	$sql ="SELECT MAX(gui_wms_position) AS pos FROM gui_wms WHERE fkey_gui_id = $1";
-	$v = array($gui_id);
-	$t = array('s');
-	$res = db_prep_query($sql,$v,$t);
-	if(db_result($res, 0,"pos") > -1){
-		$position = db_result($res, 0,"pos") + 1;
-	} else{ $position = 0; }
-	
-	$sql ="INSERT INTO gui_wms (fkey_gui_id, fkey_wms_id, gui_wms_position, gui_wms_mapformat, ";
-	$sql .= "gui_wms_featureinfoformat, gui_wms_exceptionformat, gui_wms_epsg)";
-	$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7)";
-	$v = array($gui_id,$myWMS,$position,$this->gui_wms_mapformat,$this->gui_wms_featureinfoformat,
-			$this->gui_wms_exceptionformat,$this->gui_wms_epsg
-			);
-	$t = array('s','i','i','s','s','s','s');
-	$res = db_prep_query($sql,$v,$t);
-	if(!$res){
-		db_rollback();	
-	}
-	db_commit();
-    
-    #Changes JW
-    $this->wms_id = $myWMS;
-}
-function insertLayer($i,$myWMS){
-	$sql = "INSERT INTO layer(fkey_wms_id, layer_pos, layer_parent, layer_name, layer_title, ";
-	$sql .= " layer_queryable, layer_minscale, layer_maxscale,layer_dataurl,layer_metadataurl,layer_abstract) ";
-	$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)";
-	if($this->objLayer[$i]->layer_id != null){
-		$tmpPos =  $this->objLayer[$i]->layer_id;
-	}
-	else {
-		$tmpPos .= 0;
-	}
-	if($this->objLayer[$i]->layer_parent == '' && $this->objLayer[$i]->layer_parent != '0'){
-		$this->objLayer[$i]->layer_parent = '';
-	}
-	$v = array($myWMS,$tmpPos,$this->objLayer[$i]->layer_parent,$this->objLayer[$i]->layer_name,
-			$this->objLayer[$i]->layer_title,
-			$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,
-			$this->objLayer[$i]->layer_maxscale,$this->objLayer[$i]->layer_dataurl_href,
-			$this->objLayer[$i]->layer_metadataurl,$this->objLayer[$i]->layer_abstract);
-	$t = array('i','i','s','s','s','i','i','i','s','s','s');
-	$res = db_prep_query($sql,$v,$t);
-	if(!$res){
-		db_rollback();	
-	}
-	
-	# save the id of each layer: set param2 true		
-	$this->objLayer[$i]->db_id = db_insert_id($con, 'layer','layer_id');
-	$this->insertLayerEPSG($i);
-	
-	# TABLE layer_style for each layer
-	$this->insertLayerStyle($i);
-	
-	# insert Keywords
-	$this->insertLayerKeyword($i);	
-}
-function updateLayer($i,$myWMS){
-	$sql = "SELECT layer_id FROM layer WHERE fkey_wms_id = $1 AND layer_name = $2";
-	$v = array($myWMS,$this->objLayer[$i]->layer_name);
-	$t = array('i','s');
-	$res = db_prep_query($sql,$v,$t);
-	if($row = db_fetch_array($res)){
-		$l_id = $row['layer_id'];	
-	}
-	else{
-		db_rollback();
-		$e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name);
-		return;	
-	}	
-	
-	$sql = "UPDATE layer SET ";
-	$sql .= "layer_pos = $1, ";
-	$sql .= "layer_parent = $2, ";
-	$sql .= "layer_title = $3, ";
-	$sql .= "layer_queryable = $4, ";
-	$sql .= "layer_minscale = $5, ";
-	$sql .= "layer_maxscale = $6, ";
-	$sql .= "layer_dataurl = $7, ";
-	$sql .= "layer_metadataurl = $8, ";
-	$sql .= "layer_abstract = $9 ";
-	$sql .= "WHERE layer_id = $10";
-	
-	if($this->objLayer[$i]->layer_id != null){
-		$tmpPos =  $this->objLayer[$i]->layer_id;
-	}
-	else {
-		$tmpPos .= 0;
-	}
-	if($this->objLayer[$i]->layer_parent == '' && $this->objLayer[$i]->layer_parent != '0'){
-		$this->objLayer[$i]->layer_parent = '';
-	}
-	$v = array($tmpPos,$this->objLayer[$i]->layer_parent,
-			$this->objLayer[$i]->layer_title,
-			$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,
-			$this->objLayer[$i]->layer_maxscale,$this->objLayer[$i]->layer_dataurl_href,
-			$this->objLayer[$i]->layer_metadataurl,$this->objLayer[$i]->layer_abstract, $l_id		
-		);
-	$t = array('i','s','s','i','i','i','s','s','s','i');
-	$res = db_prep_query($sql,$v,$t);
-	if($this->overwrite == true){
-		$sql = "UPDATE layer SET ";
-		$sql .= "layer_title = $1, ";
-		$sql .= "layer_abstract = $2 ";
-		$sql .= "WHERE layer_id = $3";
+		# TABLE layer and gui_layer
 		
-		$v = array($this->objLayer[$i]->layer_title,$this->objLayer[$i]->layer_abstract, $l_id);
-		$t = array('s','s','i');
+		for($i=0; $i<count($this->objLayer); $i++){
+			$this->insertLayer($i,$myWMS,$gui_id);
+			$this->insertGuiLayer($i,$myWMS,$gui_id);
+		}	
+			
+		
+		#TABLE wms_srs
+		$this->insertSRS($myWMS);	
+		
+		# TABLE wms_format	
+		$this->insertFormat($myWMS);	
+			
+		# TABLE gui_wms
+		
+		$sql ="SELECT MAX(gui_wms_position) AS pos FROM gui_wms WHERE fkey_gui_id = $1";
+		$v = array($gui_id);
+		$t = array('s');
 		$res = db_prep_query($sql,$v,$t);
-	}
-	if(!$res){
-		db_rollback();	
-	}
-	
-	# save the id of each layer: set param2 true
-	$this->objLayer[$i]->db_id = $l_id;
-	$this->insertLayerEPSG($i);
-	
-	# TABLE layer_style for each layer
-	$this->insertLayerStyle($i);
-	if($this->overwrite == true){
-		$this->insertLayerKeyword($i);
-	}
-}
-function insertGuiLayer($i,$myWMS,$gui_id){
-	# table gui_layer
-	
-	$sql = "INSERT INTO gui_layer (fkey_gui_id, fkey_layer_id, gui_layer_wms_id, ";
-	$sql .= "gui_layer_status, gui_layer_selectable, gui_layer_visible, gui_layer_queryable, ";
-	$sql .= "gui_layer_querylayer,gui_layer_minscale,gui_layer_maxscale, gui_layer_priority) ";
-	$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)";
-	$v = array($gui_id,$this->objLayer[$i]->db_id,$myWMS,1,1,1,$this->objLayer[$i]->layer_queryable,
-		$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,$this->objLayer[$i]->layer_maxscale,$i);
-	$t = array('s','i','i','i','i','i','i','i','i','i','i');
-	$res = db_prep_query($sql,$v,$t);
-	if(!$res){
-		db_rollback();	
-	}	
-}
-function appendGuiLayer($i,$myWMS,$gui_id){
-	# table gui_layer
-	
-	$sql = "INSERT INTO gui_layer (fkey_gui_id, fkey_layer_id, gui_layer_wms_id, ";
-	$sql .= "gui_layer_status, gui_layer_selectable, gui_layer_visible, gui_layer_queryable, ";
-	$sql .= "gui_layer_querylayer,gui_layer_minscale,gui_layer_maxscale, gui_layer_priority) ";
-	$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)";
-	$v = array($gui_id,$this->objLayer[$i]->db_id,$myWMS,0,0,0,$this->objLayer[$i]->layer_queryable,
-		$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,$this->objLayer[$i]->layer_maxscale,$i);
-	$t = array('s','i','i','i','i','i','i','i','i','i','i');
-	$res = db_prep_query($sql,$v,$t);
-	if(!$res){
-		db_rollback();	
-	}	
-}
-function insertSRS($myWMS){
-	for($i=0; $i<count($this->wms_srs);$i++){
-		$sql ="INSERT INTO wms_srs (fkey_wms_id, wms_srs) values($1,$2)";		
-		$v = array($myWMS,strtoupper($this->wms_srs[$i]));
-		$t = array('i','s');		
+		if(db_result($res, 0,"pos") > -1){
+			$position = db_result($res, 0,"pos") + 1;
+		} else{ $position = 0; }
+		
+		$sql ="INSERT INTO gui_wms (fkey_gui_id, fkey_wms_id, gui_wms_position, gui_wms_mapformat, ";
+		$sql .= "gui_wms_featureinfoformat, gui_wms_exceptionformat, gui_wms_epsg)";
+		$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7)";
+		$v = array($gui_id,$myWMS,$position,$this->gui_wms_mapformat,$this->gui_wms_featureinfoformat,
+				$this->gui_wms_exceptionformat,$this->gui_wms_epsg
+				);
+		$t = array('s','i','i','s','s','s','s');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
 			db_rollback();	
 		}
-	}	
-}
-function insertFormat($myWMS){
-	for($i=0; $i<count($this->data_type);$i++){
-		$sql ="INSERT INTO wms_format (fkey_wms_id, data_type, data_format) ";
-		$sql .= " VALUES($1,$2,$3)";
-		$v = array($myWMS,$this->data_type[$i],$this->data_format[$i]);
-		$t = array('i','s','s');
+		db_commit();
+	    
+	    #Changes JW
+	    $this->wms_id = $myWMS;
+	}
+	function insertLayer($i,$myWMS){
+		$sql = "INSERT INTO layer(fkey_wms_id, layer_pos, layer_parent, layer_name, layer_title, ";
+		$sql .= " layer_queryable, layer_minscale, layer_maxscale,layer_dataurl,layer_metadataurl,layer_abstract) ";
+		$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)";
+		if($this->objLayer[$i]->layer_id != null){
+			$tmpPos =  $this->objLayer[$i]->layer_id;
+		}
+		else {
+			$tmpPos .= 0;
+		}
+		if($this->objLayer[$i]->layer_parent == '' && $this->objLayer[$i]->layer_parent != '0'){
+			$this->objLayer[$i]->layer_parent = '';
+		}
+		$v = array($myWMS,$tmpPos,$this->objLayer[$i]->layer_parent,$this->objLayer[$i]->layer_name,
+				$this->objLayer[$i]->layer_title,
+				$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,
+				$this->objLayer[$i]->layer_maxscale,$this->objLayer[$i]->layer_dataurl_href,
+				$this->objLayer[$i]->layer_metadataurl,$this->objLayer[$i]->layer_abstract);
+		$t = array('i','i','s','s','s','i','i','i','s','s','s');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
 			db_rollback();	
 		}
-	}	
-}
-function insertLayerEPSG($i){
-	$sql = "DELETE FROM layer_epsg WHERE fkey_layer_id = $1";
-	$v = array($this->objLayer[$i]->db_id);
-	$t = array('i');
-	$res = db_prep_query($sql,$v,$t);
-	for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
-		$sql = "INSERT INTO layer_epsg (fkey_layer_id, epsg, minx, miny, maxx, maxy) ";
-		$sql .= "VALUES($1,$2,$3,$4,$5,$6)";
-		$v = array($this->objLayer[$i]->db_id,$this->objLayer[$i]->layer_epsg[$j][epsg],
-			$this->objLayer[$i]->layer_epsg[$j][minx],$this->objLayer[$i]->layer_epsg[$j][miny],
-			$this->objLayer[$i]->layer_epsg[$j][maxx],$this->objLayer[$i]->layer_epsg[$j][maxy]
-			); 
-		$t = array('i','s','d','d','d','d');
+		
+		# save the id of each layer: set param2 true		
+		$this->objLayer[$i]->db_id = db_insert_id($con, 'layer','layer_id');
+		$this->insertLayerEPSG($i);
+		
+		# TABLE layer_style for each layer
+		$this->insertLayerStyle($i);
+		
+		# insert Keywords
+		$this->insertLayerKeyword($i);	
+	}
+	function updateLayer($i,$myWMS){
+		$sql = "SELECT layer_id FROM layer WHERE fkey_wms_id = $1 AND layer_name = $2";
+		$v = array($myWMS,$this->objLayer[$i]->layer_name);
+		$t = array('i','s');
 		$res = db_prep_query($sql,$v,$t);
+		if($row = db_fetch_array($res)){
+			$l_id = $row['layer_id'];	
+		}
+		else{
+			db_rollback();
+			$e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name);
+			return;	
+		}	
+		
+		$sql = "UPDATE layer SET ";
+		$sql .= "layer_pos = $1, ";
+		$sql .= "layer_parent = $2, ";
+		$sql .= "layer_title = $3, ";
+		$sql .= "layer_queryable = $4, ";
+		$sql .= "layer_minscale = $5, ";
+		$sql .= "layer_maxscale = $6, ";
+		$sql .= "layer_dataurl = $7, ";
+		$sql .= "layer_metadataurl = $8, ";
+		$sql .= "layer_abstract = $9 ";
+		$sql .= "WHERE layer_id = $10";
+		
+		if($this->objLayer[$i]->layer_id != null){
+			$tmpPos =  $this->objLayer[$i]->layer_id;
+		}
+		else {
+			$tmpPos .= 0;
+		}
+		if($this->objLayer[$i]->layer_parent == '' && $this->objLayer[$i]->layer_parent != '0'){
+			$this->objLayer[$i]->layer_parent = '';
+		}
+		$v = array($tmpPos,$this->objLayer[$i]->layer_parent,
+				$this->objLayer[$i]->layer_title,
+				$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,
+				$this->objLayer[$i]->layer_maxscale,$this->objLayer[$i]->layer_dataurl_href,
+				$this->objLayer[$i]->layer_metadataurl,$this->objLayer[$i]->layer_abstract, $l_id		
+			);
+		$t = array('i','s','s','i','i','i','s','s','s','i');
+		$res = db_prep_query($sql,$v,$t);
+		if($this->overwrite == true){
+			$sql = "UPDATE layer SET ";
+			$sql .= "layer_title = $1, ";
+			$sql .= "layer_abstract = $2 ";
+			$sql .= "WHERE layer_id = $3";
+			
+			$v = array($this->objLayer[$i]->layer_title,$this->objLayer[$i]->layer_abstract, $l_id);
+			$t = array('s','s','i');
+			$res = db_prep_query($sql,$v,$t);
+		}
 		if(!$res){
 			db_rollback();	
 		}
+		
+		# save the id of each layer: set param2 true
+		$this->objLayer[$i]->db_id = $l_id;
+		$this->insertLayerEPSG($i);
+		
+		# TABLE layer_style for each layer
+		$this->insertLayerStyle($i);
+		if($this->overwrite == true){
+			$this->insertLayerKeyword($i);
+		}
 	}
-}
-function insertLayerStyle($i){
-	$sql = "DELETE FROM layer_style WHERE fkey_layer_id = $1";
-	$v = array($this->objLayer[$i]->db_id);
-	$t = array('i');
-	$res = db_prep_query($sql,$v,$t);
-	for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
-		$sql = "INSERT INTO layer_style (fkey_layer_id, name, title, legendurl, legendurlformat) ";
-		$sql .= "VALUES($1,$2,$3,$4,$5)";
-		$v = array($this->objLayer[$i]->db_id,$this->objLayer[$i]->layer_style[$j]["name"],
-				$this->objLayer[$i]->layer_style[$j]["title"],$this->objLayer[$i]->layer_style[$j]["legendurl"],
-				$this->objLayer[$i]->layer_style[$j]["legendurlformat"]				
-			);
-		$t = array('i','s','s','s','s');
+	function insertGuiLayer($i,$myWMS,$gui_id){
+		# table gui_layer
+		
+		$sql = "INSERT INTO gui_layer (fkey_gui_id, fkey_layer_id, gui_layer_wms_id, ";
+		$sql .= "gui_layer_status, gui_layer_selectable, gui_layer_visible, gui_layer_queryable, ";
+		$sql .= "gui_layer_querylayer,gui_layer_minscale,gui_layer_maxscale, gui_layer_priority) ";
+		$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)";
+		$v = array($gui_id,$this->objLayer[$i]->db_id,$myWMS,1,1,1,$this->objLayer[$i]->layer_queryable,
+			$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,$this->objLayer[$i]->layer_maxscale,$i);
+		$t = array('s','i','i','i','i','i','i','i','i','i','i');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
 			db_rollback();	
-		}
+		}	
 	}
-}
-function insertLayerKeyword($i){
-	$sql = "DELETE FROM layer_keyword WHERE fkey_layer_id = $1";
-	$v = array($this->objLayer[$i]->db_id);
-	$t = array('i');
-	$res = db_prep_query($sql,$v,$t);
+	function appendGuiLayer($i,$myWMS,$gui_id){
+		# table gui_layer
 		
-	$k = $this->objLayer[$i]->layer_keyword;
-	for($j=0; $j<count($k); $j++){
-		$sql = "SELECT keyword_id FROM keyword WHERE keyword = $1";
-		$v = array($this->objLayer[$i]->layer_keyword[$j]);
-		$t = array('s');
+		$sql = "INSERT INTO gui_layer (fkey_gui_id, fkey_layer_id, gui_layer_wms_id, ";
+		$sql .= "gui_layer_status, gui_layer_selectable, gui_layer_visible, gui_layer_queryable, ";
+		$sql .= "gui_layer_querylayer,gui_layer_minscale,gui_layer_maxscale, gui_layer_priority) ";
+		$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)";
+		$v = array($gui_id,$this->objLayer[$i]->db_id,$myWMS,0,0,0,$this->objLayer[$i]->layer_queryable,
+			$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,$this->objLayer[$i]->layer_maxscale,$i);
+		$t = array('s','i','i','i','i','i','i','i','i','i','i');
 		$res = db_prep_query($sql,$v,$t);
-		if($row = db_fetch_array($res)){
-			$t_layer_id = $row["keyword_id"];	
+		if(!$res){
+			db_rollback();	
+		}	
+	}
+	function insertSRS($myWMS){
+		for($i=0; $i<count($this->wms_srs);$i++){
+			$sql ="INSERT INTO wms_srs (fkey_wms_id, wms_srs) values($1,$2)";		
+			$v = array($myWMS,strtoupper($this->wms_srs[$i]));
+			$t = array('i','s');		
+			$res = db_prep_query($sql,$v,$t);
+			if(!$res){
+				db_rollback();	
+			}
+		}	
+	}
+	function insertFormat($myWMS){
+		for($i=0; $i<count($this->data_type);$i++){
+			$sql ="INSERT INTO wms_format (fkey_wms_id, data_type, data_format) ";
+			$sql .= " VALUES($1,$2,$3)";
+			$v = array($myWMS,$this->data_type[$i],$this->data_format[$i]);
+			$t = array('i','s','s');
+			$res = db_prep_query($sql,$v,$t);
+			if(!$res){
+				db_rollback();	
+			}
+		}	
+	}
+	function insertLayerEPSG($i){
+		$sql = "DELETE FROM layer_epsg WHERE fkey_layer_id = $1";
+		$v = array($this->objLayer[$i]->db_id);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
+			$sql = "INSERT INTO layer_epsg (fkey_layer_id, epsg, minx, miny, maxx, maxy) ";
+			$sql .= "VALUES($1,$2,$3,$4,$5,$6)";
+			$v = array($this->objLayer[$i]->db_id,$this->objLayer[$i]->layer_epsg[$j][epsg],
+				$this->objLayer[$i]->layer_epsg[$j][minx],$this->objLayer[$i]->layer_epsg[$j][miny],
+				$this->objLayer[$i]->layer_epsg[$j][maxx],$this->objLayer[$i]->layer_epsg[$j][maxy]
+				); 
+			$t = array('i','s','d','d','d','d');
+			$res = db_prep_query($sql,$v,$t);
+			if(!$res){
+				db_rollback();	
+			}
 		}
-		else if(!$row = db_fetch_array($res)){
-			$sql1 = "INSERT INTO keyword (keyword)";
-			$sql1 .= "VALUES ($1)";
-			$v1 = array($k[$j]);
-			$t1 = array('s');
+	}
+	function insertLayerStyle($i){
+		$sql = "DELETE FROM layer_style WHERE fkey_layer_id = $1";
+		$v = array($this->objLayer[$i]->db_id);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
+			$sql = "INSERT INTO layer_style (fkey_layer_id, name, title, legendurl, legendurlformat) ";
+			$sql .= "VALUES($1,$2,$3,$4,$5)";
+			$v = array($this->objLayer[$i]->db_id,$this->objLayer[$i]->layer_style[$j]["name"],
+					$this->objLayer[$i]->layer_style[$j]["title"],$this->objLayer[$i]->layer_style[$j]["legendurl"],
+					$this->objLayer[$i]->layer_style[$j]["legendurlformat"]				
+				);
+			$t = array('i','s','s','s','s');
+			$res = db_prep_query($sql,$v,$t);
+			if(!$res){
+				db_rollback();	
+			}
+		}
+	}
+	function insertLayerKeyword($i){
+		$sql = "DELETE FROM layer_keyword WHERE fkey_layer_id = $1";
+		$v = array($this->objLayer[$i]->db_id);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+			
+		$k = $this->objLayer[$i]->layer_keyword;
+		for($j=0; $j<count($k); $j++){
+			$sql = "SELECT keyword_id FROM keyword WHERE keyword = $1";
+			$v = array($this->objLayer[$i]->layer_keyword[$j]);
+			$t = array('s');
+			$res = db_prep_query($sql,$v,$t);
+			if($row = db_fetch_array($res)){
+				$t_layer_id = $row["keyword_id"];	
+			}
+			else if(!$row = db_fetch_array($res)){
+				$sql1 = "INSERT INTO keyword (keyword)";
+				$sql1 .= "VALUES ($1)";
+				$v1 = array($k[$j]);
+				$t1 = array('s');
+				$res1 = db_prep_query($sql1,$v1,$t1);
+				$t_layer_id = db_insert_id($con,'keyword', 'keyword_id');
+				if(!$res1){
+					db_rollback();	
+				}
+			}
+			$sql1 = "INSERT INTO layer_keyword (fkey_keyword_id,fkey_layer_id)";
+			$sql1 .= "VALUES ($1,$2)";
+			$v1 = array($t_layer_id,$this->objLayer[$i]->db_id);
+			$t1 = array('i','i');
 			$res1 = db_prep_query($sql1,$v1,$t1);
-			$t_layer_id = db_insert_id($con,'keyword', 'keyword_id');
 			if(!$res1){
 				db_rollback();	
 			}
 		}
-		$sql1 = "INSERT INTO layer_keyword (fkey_keyword_id,fkey_layer_id)";
-		$sql1 .= "VALUES ($1,$2)";
-		$v1 = array($t_layer_id,$this->objLayer[$i]->db_id);
-		$t1 = array('i','i');
-		$res1 = db_prep_query($sql1,$v1,$t1);
-		if(!$res1){
-			db_rollback();	
-		}
 	}
-}
-function updateObjInDB($myWMS){
-	db_begin();
+	function updateObjInDB($myWMS){
+		db_begin();
+		
+		$sql = "UPDATE wms SET ";
+		$sql .= "wms_version = $1 ,";
+		$sql .= "wms_getcapabilities  = $2 ,";
+		$sql .= "wms_getmap  = $3 ,";
+		$sql .= "wms_getfeatureinfo  = $4 ,";
+		$sql .= "wms_getlegendurl  = $5 ,";
+		$sql .= "wms_getcapabilities_doc = $6 ,";
+		$sql .= "wms_upload_url = $7,  ";
+		$sql .= "wms_owner = $8, ";
+		$sql .= "wms_timestamp = $9 ";
+		$sql .= " WHERE wms_id = $10";
 	
-	$sql = "UPDATE wms SET ";
-	$sql .= "wms_version = $1 ,";
-	$sql .= "wms_getcapabilities  = $2 ,";
-	$sql .= "wms_getmap  = $3 ,";
-	$sql .= "wms_getfeatureinfo  = $4 ,";
-	$sql .= "wms_getlegendurl  = $5 ,";
-	$sql .= "wms_getcapabilities_doc = $6 ,";
-	$sql .= "wms_upload_url = $7,  ";
-	$sql .= "wms_owner = $8, ";
-	$sql .= "wms_timestamp = $9 ";
-	$sql .= " WHERE wms_id = $10";
-
-	$v = array($this->wms_version,$this->wms_getcapabilities,
-		$this->wms_getmap,$this->wms_getfeatureinfo,$this->wms_getlegendurl,
-		$this->wms_getcapabilities_doc,$this->wms_upload_url,$_SESSION["mb_user_id"],strtotime("now"),$myWMS);
-	$t = array('s','s','s','s','s','s','s','i','i','i');
-
-	$res = db_prep_query($sql,$v,$t);
-	if(!$res){
-		db_rollback();	
-	}
+		$v = array($this->wms_version,$this->wms_getcapabilities,
+			$this->wms_getmap,$this->wms_getfeatureinfo,$this->wms_getlegendurl,
+			$this->wms_getcapabilities_doc,$this->wms_upload_url,$_SESSION["mb_user_id"],strtotime("now"),$myWMS);
+		$t = array('s','s','s','s','s','s','s','i','i','i');
 	
-	if($this->overwrite == true){
-		$sql = "UPDATE wms SET ";
-		$sql .= "wms_title  = $1 ,";
-		$sql .= "wms_abstract  = $2 ,";
-		$sql .= "fees = $3, ";
-		$sql .= "accessconstraints = $4, ";
-		$sql .= "contactperson = $5, ";
-		$sql .= "contactposition = $6, ";
-		$sql .= "contactorganization = $7, ";
-		$sql .= "address = $8, ";
-		$sql .= "city = $9, ";
-		$sql .= "stateorprovince = $10, ";
-		$sql .= "postcode = $11, ";
-		$sql .= "country = $12, ";
-		$sql .= "contactvoicetelephone = $13, ";
-		$sql .= "contactfacsimiletelephone = $14, ";
-		$sql .= "contactelectronicmailaddress = $15 ";
-		$sql .= " WHERE wms_id = $16";
-	
-		$v = array($this->wms_title,$this->wms_abstract,$this->fees,$this->accessconstraints,
-			$this->contactperson,$this->contactposition,$this->contactorganization,$this->address,
-			$this->city,$this->stateorprovince,$this->postcode,$this->country,$this->contactvoicetelephone,
-			$this->contactfacsimiletelephone,$this->contactelectronicmailaddress,$myWMS);
-		$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','i');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
 			db_rollback();	
 		}
-	}
-	
-	# delete and refill srs and formats
-	$sql = "DELETE FROM wms_srs WHERE fkey_wms_id = $1 ";
-	$v = array($myWMS);
-	$t = array('i');
-	$res = db_prep_query($sql,$v,$t);
-	if(!$res){
-		db_rollback();	
-	}
-	$this->insertSRS($myWMS);
-	
-	$sql = "DELETE FROM wms_format WHERE fkey_wms_id = $1 ";
-	$v = array($myWMS);
-	$t = array('i');
-	$res = db_prep_query($sql,$v,$t);
-	if(!$res){
-		db_rollback();	
-	}
-	$this->insertFormat($myWMS);
-	
-	# update gui_wms
-	$this->update_gui_wms($myWMS);
-	
-	# update TABLE layer	
-	# delete all layer which are outdated
-	$v = array($myWMS);
-	$t = array('i');
-	$c = 2;
-	$sql = "DELETE FROM layer WHERE fkey_wms_id = $1 AND NOT layer_name IN(";
-	for($i=0; $i<count($this->objLayer); $i++){
-		if($i>0){$sql .= ',';}
-		$sql .= "$".$c;
-		array_push($v,$this->objLayer[$i]->layer_name);
-		array_push($t,'s');		
-		$c++;
-	}
-	$sql .= ")";
-	
-	$res = db_prep_query($sql,$v,$t);
-	if(!$res){
-		db_rollback();	
-	}
 		
-	# update or insert?
-	$sql = "SELECT layer_name FROM layer WHERE fkey_wms_id = $1";
-	$v = array($myWMS);
-	$t = array('i');
-	$res = db_prep_query($sql,$v,$t);
-	$exLayer = array();
-	while($row = db_fetch_array($res)){
-		array_push($exLayer,$row["layer_name"]);
-	}
-	
-	$sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = $1";
-	$v = array($myWMS);
-	$t = array('i');
-	$res = db_prep_query($sql,$v,$t);
-	$exGui = array();
-	while($row = db_fetch_array($res)){
-		array_push($exGui,$row["fkey_gui_id"]);
-	}
-	
-	for($i=0; $i<count($this->objLayer); $i++){
-		if(in_array($this->objLayer[$i]->layer_name,$exLayer)){
-			//echo "<br>update: ".$this->objLayer[$i]->layer_name;
-			$this->updateLayer($i,$myWMS);
-			for($j=0; $j<count($exGui); $j++){
-				$this->updateGuiLayer($i,$myWMS,$exGui[$j]);
+		if($this->overwrite == true){
+			$sql = "UPDATE wms SET ";
+			$sql .= "wms_title  = $1 ,";
+			$sql .= "wms_abstract  = $2 ,";
+			$sql .= "fees = $3, ";
+			$sql .= "accessconstraints = $4, ";
+			$sql .= "contactperson = $5, ";
+			$sql .= "contactposition = $6, ";
+			$sql .= "contactorganization = $7, ";
+			$sql .= "address = $8, ";
+			$sql .= "city = $9, ";
+			$sql .= "stateorprovince = $10, ";
+			$sql .= "postcode = $11, ";
+			$sql .= "country = $12, ";
+			$sql .= "contactvoicetelephone = $13, ";
+			$sql .= "contactfacsimiletelephone = $14, ";
+			$sql .= "contactelectronicmailaddress = $15 ";
+			$sql .= " WHERE wms_id = $16";
+		
+			$v = array($this->wms_title,$this->wms_abstract,$this->fees,$this->accessconstraints,
+				$this->contactperson,$this->contactposition,$this->contactorganization,$this->address,
+				$this->city,$this->stateorprovince,$this->postcode,$this->country,$this->contactvoicetelephone,
+				$this->contactfacsimiletelephone,$this->contactelectronicmailaddress,$myWMS);
+			$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','i');
+			$res = db_prep_query($sql,$v,$t);
+			if(!$res){
+				db_rollback();	
 			}
 		}
-		else{
-			//echo "<br>append: ".$this->objLayer[$i]->layer_name;
-			$this->insertLayer($i,$myWMS);
-			for($j=0; $j<count($exGui); $j++){
-				$this->appendGuiLayer($i,$myWMS,$exGui[$j]);
+		
+		# delete and refill srs and formats
+		$sql = "DELETE FROM wms_srs WHERE fkey_wms_id = $1 ";
+		$v = array($myWMS);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			db_rollback();	
+		}
+		$this->insertSRS($myWMS);
+		
+		$sql = "DELETE FROM wms_format WHERE fkey_wms_id = $1 ";
+		$v = array($myWMS);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			db_rollback();	
+		}
+		$this->insertFormat($myWMS);
+		
+		# update gui_wms
+		$this->update_gui_wms($myWMS);
+		
+		# update TABLE layer	
+		# delete all layer which are outdated
+		$v = array($myWMS);
+		$t = array('i');
+		$c = 2;
+		$sql = "DELETE FROM layer WHERE fkey_wms_id = $1 AND NOT layer_name IN(";
+		for($i=0; $i<count($this->objLayer); $i++){
+			if($i>0){$sql .= ',';}
+			$sql .= "$".$c;
+			array_push($v,$this->objLayer[$i]->layer_name);
+			array_push($t,'s');		
+			$c++;
+		}
+		$sql .= ")";
+		
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			db_rollback();	
+		}
+			
+		# update or insert?
+		$sql = "SELECT layer_name FROM layer WHERE fkey_wms_id = $1";
+		$v = array($myWMS);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$exLayer = array();
+		while($row = db_fetch_array($res)){
+			array_push($exLayer,$row["layer_name"]);
+		}
+		
+		$sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = $1";
+		$v = array($myWMS);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$exGui = array();
+		while($row = db_fetch_array($res)){
+			array_push($exGui,$row["fkey_gui_id"]);
+		}
+		
+		for($i=0; $i<count($this->objLayer); $i++){
+			if(in_array($this->objLayer[$i]->layer_name,$exLayer)){
+				//echo "<br>update: ".$this->objLayer[$i]->layer_name;
+				$this->updateLayer($i,$myWMS);
+				for($j=0; $j<count($exGui); $j++){
+					$this->updateGuiLayer($i,$myWMS,$exGui[$j]);
+				}
 			}
+			else{
+				//echo "<br>append: ".$this->objLayer[$i]->layer_name;
+				$this->insertLayer($i,$myWMS);
+				for($j=0; $j<count($exGui); $j++){
+					$this->appendGuiLayer($i,$myWMS,$exGui[$j]);
+				}
+			}
 		}
-	}
-	db_commit();
-	return;	
-}
-function updateGuiLayer($i,$myWMS,$gui_id){
-	$sql = "SELECT layer_id FROM layer WHERE fkey_wms_id = $1 AND layer_name = $2";
-	$v = array($myWMS,$this->objLayer[$i]->layer_name);
-	$t = array('i','s');
-	$res = db_prep_query($sql,$v,$t);
-	if($row = db_fetch_array($res)){
-		$l_id = $row['layer_id'];	
-	}
-	else{
-		db_rollback();
-		$e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name. " in gui: ".$gui_id);
+		db_commit();
 		return;	
 	}
-	
-	$sql = "SELECT * FROM gui_layer WHERE fkey_layer_id = $1 and fkey_gui_id = $2";
-	$v = array($l_id,$gui_id);
-	$t = array('i','s');
-	$res = db_prep_query($sql,$v,$t);		
-	while($row = db_fetch_array($res)){
-		if($this->objLayer[$i]->layer_queryable == 0){
-			$sql1 = "UPDATE gui_layer set gui_layer_queryable = 0, gui_layer_querylayer = 0 ";
-			$sql1 .= "WHERE fkey_layer_id = $1 and fkey_gui_id = $2";
-			$v = array($l_id,$gui_id);
-			$t = array('i','s');
-			$res1 = db_prep_query($sql1,$v,$t);
-			if(!$res1){db_rollback();}
+	function updateGuiLayer($i,$myWMS,$gui_id){
+		$sql = "SELECT layer_id FROM layer WHERE fkey_wms_id = $1 AND layer_name = $2";
+		$v = array($myWMS,$this->objLayer[$i]->layer_name);
+		$t = array('i','s');
+		$res = db_prep_query($sql,$v,$t);
+		if($row = db_fetch_array($res)){
+			$l_id = $row['layer_id'];	
 		}
-		if($this->objLayer[$i]->layer_queryable == 1){
-			$sql1 = "UPDATE gui_layer set gui_layer_queryable = 1 ";
-			$sql1 .= "WHERE fkey_layer_id = $1 and fkey_gui_id = $2";
-			$v = array($l_id,$gui_id);
-			$t = array('i','s');
-			$res1 = db_prep_query($sql1,$v,$t);
-			if(!$res1){db_rollback();}
+		else{
+			db_rollback();
+			$e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name. " in gui: ".$gui_id);
+			return;	
 		}
-		if($row["gui_layer_minscale"] < $this->objLayer[$i]->layer_minscale){
-			$sql1 = "UPDATE gui_layer set gui_layer_minscale = $1 ";
-			$sql1 .= "WHERE fkey_layer_id = $2 and fkey_gui_id = $3";
-			$v = array($this->objLayer[$i]->layer_minscale,$l_id,$gui_id);
-			$t = array('i','i','s');
-			$res1 = db_prep_query($sql1,$v,$t);
-			if(!$res1){db_rollback();}
+		
+		$sql = "SELECT * FROM gui_layer WHERE fkey_layer_id = $1 and fkey_gui_id = $2";
+		$v = array($l_id,$gui_id);
+		$t = array('i','s');
+		$res = db_prep_query($sql,$v,$t);		
+		while($row = db_fetch_array($res)){
+			if($this->objLayer[$i]->layer_queryable == 0){
+				$sql1 = "UPDATE gui_layer set gui_layer_queryable = 0, gui_layer_querylayer = 0 ";
+				$sql1 .= "WHERE fkey_layer_id = $1 and fkey_gui_id = $2";
+				$v = array($l_id,$gui_id);
+				$t = array('i','s');
+				$res1 = db_prep_query($sql1,$v,$t);
+				if(!$res1){db_rollback();}
+			}
+			if($this->objLayer[$i]->layer_queryable == 1){
+				$sql1 = "UPDATE gui_layer set gui_layer_queryable = 1 ";
+				$sql1 .= "WHERE fkey_layer_id = $1 and fkey_gui_id = $2";
+				$v = array($l_id,$gui_id);
+				$t = array('i','s');
+				$res1 = db_prep_query($sql1,$v,$t);
+				if(!$res1){db_rollback();}
+			}
+			if($row["gui_layer_minscale"] < $this->objLayer[$i]->layer_minscale){
+				$sql1 = "UPDATE gui_layer set gui_layer_minscale = $1 ";
+				$sql1 .= "WHERE fkey_layer_id = $2 and fkey_gui_id = $3";
+				$v = array($this->objLayer[$i]->layer_minscale,$l_id,$gui_id);
+				$t = array('i','i','s');
+				$res1 = db_prep_query($sql1,$v,$t);
+				if(!$res1){db_rollback();}
+			}
+			if($row["gui_layer_maxscale"] > $this->objLayer[$i]->layer_maxscale){
+				$sql1 = "UPDATE gui_layer set gui_layer_maxscale = $1 ";
+				$sql1 .= "WHERE fkey_layer_id = $2 and fkey_gui_id = $3";
+				$v = array($this->objLayer[$i]->layer_maxscale,$l_id,$gui_id);
+				$t = array('i','i','s');
+				$res1 = db_prep_query($sql1,$v,$t);
+				if(!$res1){db_rollback();}
+			}		
 		}
-		if($row["gui_layer_maxscale"] > $this->objLayer[$i]->layer_maxscale){
-			$sql1 = "UPDATE gui_layer set gui_layer_maxscale = $1 ";
-			$sql1 .= "WHERE fkey_layer_id = $2 and fkey_gui_id = $3";
-			$v = array($this->objLayer[$i]->layer_maxscale,$l_id,$gui_id);
-			$t = array('i','i','s');
-			$res1 = db_prep_query($sql1,$v,$t);
-			if(!$res1){db_rollback();}
-		}		
 	}
-}
-function update_gui_wms($myWMS){
-	$sql = "SELECT * FROM gui_wms where fkey_wms_id = $1";
-	$v = array($myWMS);
-	$t = array('i');
-	$res = db_prep_query($sql,$v,$t);
-	$cnt = 0;
-	while($row = db_fetch_array($res)){	
-		unset($mySubmit);
-		$myGUI[$cnt] = $row["fkey_gui_id"];
-		$sql = "UPDATE gui_wms SET ";		
-		for($i=0; $i<count($this->data_type); $i++){
-			# gui_wms_mapformat
-			if(strtolower($this->data_type[$i]) == "map" && strtolower($this->data_format[$i]) == strtolower($row["gui_wms_mapformat"])){
-				$myMapFormat = true;
+	function update_gui_wms($myWMS){
+		$sql = "SELECT * FROM gui_wms where fkey_wms_id = $1";
+		$v = array($myWMS);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$cnt = 0;
+		while($row = db_fetch_array($res)){	
+			unset($mySubmit);
+			$myGUI[$cnt] = $row["fkey_gui_id"];
+			$sql = "UPDATE gui_wms SET ";		
+			for($i=0; $i<count($this->data_type); $i++){
+				# gui_wms_mapformat
+				if(strtolower($this->data_type[$i]) == "map" && strtolower($this->data_format[$i]) == strtolower($row["gui_wms_mapformat"])){
+					$myMapFormat = true;
+				}
+				# gui_wms_featureinfoformat
+				if(strtolower($this->data_type[$i]) == "featureinfo" && strtolower($this->data_format[$i]) == strtolower($row["gui_wms_featureinfoformat"])){
+					$myFeatureInfoFormat = true;
+				}
+				# gui_wms_exceptionformat
+				if(strtolower($this->data_type[$i]) == "exception" && strtolower($this->data_format[$i]) == strtolower($row["gui_wms_exceptionformat"])){
+					$myExceptionFormat = true;
+				}
 			}
-			# gui_wms_featureinfoformat
-			if(strtolower($this->data_type[$i]) == "featureinfo" && strtolower($this->data_format[$i]) == strtolower($row["gui_wms_featureinfoformat"])){
-				$myFeatureInfoFormat = true;
+			if(!$myMapFormat){
+				$sql .= "gui_wms_mapformat = '".$this->gui_wms_mapformat."' ";
+				$mySubmit = true;
 			}
-			# gui_wms_exceptionformat
-			if(strtolower($this->data_type[$i]) == "exception" && strtolower($this->data_format[$i]) == strtolower($row["gui_wms_exceptionformat"])){
-				$myExceptionFormat = true;
+			if(!$myFeatureInfoFormat){
+				if($mySubmit){ $sql .= ",";}
+				$sql .= "gui_wms_featureinfoformat = '".$this->gui_wms_featureinfoformat."' ";
+				$mySubmit = true;
 			}
-		}
-		if(!$myMapFormat){
-			$sql .= "gui_wms_mapformat = '".$this->gui_wms_mapformat."' ";
-			$mySubmit = true;
-		}
-		if(!$myFeatureInfoFormat){
-			if($mySubmit){ $sql .= ",";}
-			$sql .= "gui_wms_featureinfoformat = '".$this->gui_wms_featureinfoformat."' ";
-			$mySubmit = true;
-		}
-		if(!$myExceptionFormat){
-			if($mySubmit){ $sql .= ",";}
-			$sql .= "gui_wms_exceptionformat = '".$this->gui_wms_exceptionformat."' ";
-			$mySubmit = true;
-		}
-			
-		# gui_wms_epsg
-		for($j=0; $j<count($this->objLayer[0]->layer_epsg);$j++){
-			if($this->objLayer[0]->layer_epsg[$j][epsg] == strtoupper($row["gui_wms_epsg"])){
-				$myGUI_EPSG = true;
+			if(!$myExceptionFormat){
+				if($mySubmit){ $sql .= ",";}
+				$sql .= "gui_wms_exceptionformat = '".$this->gui_wms_exceptionformat."' ";
+				$mySubmit = true;
 			}
-		}
-		if(!$myGUI_EPSG){
-			if($mySubmit){ $sql .= ",";}
-			$sql .= "gui_wms_epsg = '".$this->gui_wms_epsg."' ";
-			$mySubmit = true;
-		}
-		$sql .= " WHERE fkey_gui_id = '".$row["fkey_gui_id"]."' AND fkey_wms_id = " . $myWMS;
-		if($mySubmit){
-			$this->transaction($sql);
-		}
-		$cnt++;
-	}	
-}
-function getVersion() {
-	return $this->wms_version;
-}
-
-function getCapabilities() {
-	return $this->wms_getcapabilities;
-}
-
-function getCapabilitiesDoc() {
-	return $this->wms_getcapabilities_doc;
-}
-function transaction($sql){
-	#echo "<hr>". $sql;
-	$ok = db_query($sql);
-	if(!$ok){
-		echo "<pre>".$sql."</pre><br> <br><p>";
-		$error = db_error();
-		$sql = "ROLLBACK";
-		$res = db_query($sql);
-		if($SYS_DBTYPE=="pgsql")
-			{
-				$sql = "SET AUTOCOMMIT=0";
+				
+			# gui_wms_epsg
+			for($j=0; $j<count($this->objLayer[0]->layer_epsg);$j++){
+				if($this->objLayer[0]->layer_epsg[$j][epsg] == strtoupper($row["gui_wms_epsg"])){
+					$myGUI_EPSG = true;
+				}
 			}
-			else
-			{
-			 	$sql = "SET AUTOCOMMIT=1";
+			if(!$myGUI_EPSG){
+				if($mySubmit){ $sql .= ",";}
+				$sql .= "gui_wms_epsg = '".$this->gui_wms_epsg."' ";
+				$mySubmit = true;
 			}
-	 	echo $error; 
-	 	echo "<br /> UPDATE ERROR -> KILL PROCESS AND ROLLBACK....................no update<br><br>";
-		}
-}
-/**
-* creatObjfromDB
-*
-*/ 
-  function createObjFromDB($gui_id,$wms_id){
-
-	$sql = "Select * from gui_wms where fkey_wms_id = $1 AND fkey_gui_id = $2";
-	$v = array($wms_id,$gui_id);
-	$t = array('i','s');
-	$res = db_prep_query($sql,$v,$t);
+			$sql .= " WHERE fkey_gui_id = '".$row["fkey_gui_id"]."' AND fkey_wms_id = " . $myWMS;
+			if($mySubmit){
+				$this->transaction($sql);
+			}
+			$cnt++;
+		}	
+	}
+	function getVersion() {
+		return $this->wms_version;
+	}
 	
-	$count=0;
-	#$res_count=db_num_rows($res);
-    
-
-	while($row = db_fetch_array($res)){
-		$this->gui_wms_mapformat=$row["gui_wms_mapformat"];
-		$this->gui_wms_featureinfoformat=$row["gui_wms_featureinfoformat"];
-		$this->gui_wms_exceptionformat=$row["gui_wms_exceptionformat"];
-		$this->gui_wms_epsg=$row["gui_wms_epsg"];
-		$this->gui_wms_visible = $row["gui_wms_visible"];
-  
-		$sql = "Select * from wms where wms_id = $1 ";
-		$v = array($wms_id);
-		$t = array('i');
-		$res_wms = db_prep_query($sql,$v,$t);
-		$count_wms=0;
-		while($row2 = db_fetch_array($res_wms)){
-			$this->wms_id = $row2["wms_id"];
-			$this->wms_version = $row2["wms_version"];
-			$this->wms_title = $this->stripEndlineAndCarriageReturn($row2["wms_title"]);
-			$this->wms_abstract = $this->stripEndlineAndCarriageReturn($row2["wms_abstract"]);
-			if($row2["wms_owsproxy"] != ""){
-				$t = OWSPROXY."/".session_id()."/".$row2["wms_owsproxy"]."?";
-				$this->wms_getmap = $t;
-				$this->wms_getcapabilities =  $t;
-				$this->wms_getfeatureinfo = $t;
+	function getCapabilities() {
+		return $this->wms_getcapabilities;
+	}
+	
+	function getCapabilitiesDoc() {
+		return $this->wms_getcapabilities_doc;
+	}
+	function transaction($sql){
+		#echo "<hr>". $sql;
+		$ok = db_query($sql);
+		if(!$ok){
+			echo "<pre>".$sql."</pre><br> <br><p>";
+			$error = db_error();
+			$sql = "ROLLBACK";
+			$res = db_query($sql);
+			if($SYS_DBTYPE=="pgsql")
+				{
+					$sql = "SET AUTOCOMMIT=0";
+				}
+				else
+				{
+				 	$sql = "SET AUTOCOMMIT=1";
+				}
+		 	echo $error; 
+		 	echo "<br /> UPDATE ERROR -> KILL PROCESS AND ROLLBACK....................no update<br><br>";
 			}
-			else{
-				$this->wms_getmap =  $row2["wms_getmap"];
-				$this->wms_getcapabilities =  $row2["wms_getcapabilities"];
-				$this->wms_getfeatureinfo = $row2["wms_getfeatureinfo"];
-			}			
-			$this->wms_getcapabilities_doc = $row2["wms_getcapabilities_doc"];
-			$this->wms_getlegendurl = $row2["wms_getlegendurl"];
-			$this->wms_filter = $row2["wms_filter"];
-			$count_wms++;
-		}
-
-		### formats
-		$sql = "SELECT * FROM wms_format WHERE fkey_wms_id = $1 ";
-		$v = array($wms_id);
-		$t = array('i'); 
-		$res_wms = db_prep_query($sql,$v,$t);
-		$count_format=0;		
-		while($row3 = db_fetch_array($res_wms)){		
-			$this->data_type[$count_format] = $row3["data_type"];
-			$this->data_format[$count_format] = $row3["data_format"];
-			$count_format++;
-		}
-		$count++;
 	}
+	/**
+	* creatObjfromDB
+	*
+	*/ 
+	  function createObjFromDB($gui_id,$wms_id){
 	
-	#layer
-	$sql = "Select * from gui_layer where gui_layer_wms_id = $1 AND fkey_gui_id = $2 ";
-	$sql .= " AND gui_layer_status = 1 ORDER BY gui_layer_priority;";
-	$v = array($wms_id,$gui_id);
-	$t = array('i','s');
-	$res = db_prep_query($sql,$v,$t);
-	$count=0;
+		$sql = "Select * from gui_wms where fkey_wms_id = $1 AND fkey_gui_id = $2";
+		$v = array($wms_id,$gui_id);
+		$t = array('i','s');
+		$res = db_prep_query($sql,$v,$t);
+		
+		$count=0;
+		#$res_count=db_num_rows($res);
+	    
 	
-	while($row = db_fetch_array($res)){
-		$layer_id = $row["fkey_layer_id"];		
-		$sql = "Select * from layer where layer_id = $1";
-		$v = array($layer_id);
-		$t = array('i');
-		$res_layer = db_prep_query($sql,$v,$t);
-		$count_layer=0;
-		while($row2 = db_fetch_array($res_layer)){
-			$this->addLayer($row2["layer_pos"],$row2["layer_parent"]);
-			$layer_cnt=count($this->objLayer)-1;
-			$this->objLayer[$layer_cnt]->layer_uid = $layer_id;
-			$this->objLayer[$layer_cnt]->layer_name =$row2["layer_name"];
-			$this->objLayer[$layer_cnt]->layer_title =$row2["layer_title"];			
-			$this->objLayer[$layer_cnt]->layer_dataurl_href =$row2["layer_dataurl"];
-			$this->objLayer[$layer_cnt]->layer_metadataurl =$row2["layer_metadataurl"];
-			$this->objLayer[$layer_cnt]->layer_pos =$row2["layer_pos"];						
-			$this->objLayer[$layer_cnt]->layer_queryable =$row2["layer_pos"];
-			$this->objLayer[$layer_cnt]->layer_queryable =$row2["layer_queryable"];
-			$this->objLayer[$layer_cnt]->layer_minscale =$row2["layer_minscale"];
-			$this->objLayer[$layer_cnt]->layer_maxscale = $row2["layer_maxscale"];
-			$count_layer++;
+		while($row = db_fetch_array($res)){
+			$this->gui_wms_mapformat=$row["gui_wms_mapformat"];
+			$this->gui_wms_featureinfoformat=$row["gui_wms_featureinfoformat"];
+			$this->gui_wms_exceptionformat=$row["gui_wms_exceptionformat"];
+			$this->gui_wms_epsg=$row["gui_wms_epsg"];
+			$this->gui_wms_visible = $row["gui_wms_visible"];
+	  
+			$sql = "Select * from wms where wms_id = $1 ";
+			$v = array($wms_id);
+			$t = array('i');
+			$res_wms = db_prep_query($sql,$v,$t);
+			$count_wms=0;
+			while($row2 = db_fetch_array($res_wms)){
+				$this->wms_id = $row2["wms_id"];
+				$this->wms_version = $row2["wms_version"];
+				$this->wms_title = $this->stripEndlineAndCarriageReturn($row2["wms_title"]);
+				$this->wms_abstract = $this->stripEndlineAndCarriageReturn($row2["wms_abstract"]);
+				if($row2["wms_owsproxy"] != ""){
+					$t = OWSPROXY."/".session_id()."/".$row2["wms_owsproxy"]."?";
+					$this->wms_getmap = $t;
+					$this->wms_getcapabilities =  $t;
+					$this->wms_getfeatureinfo = $t;
+				}
+				else{
+					$this->wms_getmap =  $row2["wms_getmap"];
+					$this->wms_getcapabilities =  $row2["wms_getcapabilities"];
+					$this->wms_getfeatureinfo = $row2["wms_getfeatureinfo"];
+				}			
+				$this->wms_getcapabilities_doc = $row2["wms_getcapabilities_doc"];
+				$this->wms_getlegendurl = $row2["wms_getlegendurl"];
+				$this->wms_filter = $row2["wms_filter"];
+				$count_wms++;
+			}
+	
+			### formats
+			$sql = "SELECT * FROM wms_format WHERE fkey_wms_id = $1 ";
+			$v = array($wms_id);
+			$t = array('i'); 
+			$res_wms = db_prep_query($sql,$v,$t);
+			$count_format=0;		
+			while($row3 = db_fetch_array($res_wms)){		
+				$this->data_type[$count_format] = $row3["data_type"];
+				$this->data_format[$count_format] = $row3["data_format"];
+				$count_format++;
+			}
+			$count++;
 		}
-		$this->objLayer[$layer_cnt]->layer_uid = $layer_id;
-		$this->objLayer[$layer_cnt]->gui_layer_wms_id = $row["gui_layer_wms_id"];
-		$this->objLayer[$layer_cnt]->gui_layer_selectable = $row["gui_layer_selectable"];
-		$this->objLayer[$layer_cnt]->gui_layer_visible = $row["gui_layer_visible"];
-		$this->objLayer[$layer_cnt]->gui_layer_queryable = $row["gui_layer_queryable"];
-		$this->objLayer[$layer_cnt]->gui_layer_querylayer = $row["gui_layer_querylayer"];
-		$this->objLayer[$layer_cnt]->gui_layer_minscale = $row["gui_layer_minscale"];
-		$this->objLayer[$layer_cnt]->gui_layer_maxscale = $row["gui_layer_maxscale"];
-		$this->objLayer[$layer_cnt]->gui_layer_wfs_featuretype = $row["gui_layer_wfs_featuretype"];
 		
-		$sql = "Select * from layer_epsg where fkey_layer_id = $1 ORDER BY fkey_layer_id";
-		$v = array($layer_id);
-		$t = array('i');
-		$res_layer_epsg = db_prep_query($sql,$v,$t);
+		#layer
+		$sql = "Select * from gui_layer where gui_layer_wms_id = $1 AND fkey_gui_id = $2 ";
+		$sql .= " AND gui_layer_status = 1 ORDER BY gui_layer_priority;";
+		$v = array($wms_id,$gui_id);
+		$t = array('i','s');
+		$res = db_prep_query($sql,$v,$t);
+		$count=0;
 		
-		$count_layer_epsg=0;
-		while($row2 = db_fetch_array($res_layer_epsg)){
-			$this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["epsg"]=$row2["epsg"];
-			$this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["minx"]=$row2["minx"];
-			$this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["miny"]=$row2["miny"];
-			$this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["maxx"]=$row2["maxx"];
-			$this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["maxy"]=$row2["maxy"];
-			$j++;
-			$count_layer_epsg++;
+		while($row = db_fetch_array($res)){
+			$layer_id = $row["fkey_layer_id"];		
+			$sql = "Select * from layer where layer_id = $1";
+			$v = array($layer_id);
+			$t = array('i');
+			$res_layer = db_prep_query($sql,$v,$t);
+			$count_layer=0;
+			while($row2 = db_fetch_array($res_layer)){
+				$this->addLayer($row2["layer_pos"],$row2["layer_parent"]);
+				$layer_cnt=count($this->objLayer)-1;
+				$this->objLayer[$layer_cnt]->layer_uid = $layer_id;
+				$this->objLayer[$layer_cnt]->layer_name =$row2["layer_name"];
+				$this->objLayer[$layer_cnt]->layer_title =$row2["layer_title"];			
+				$this->objLayer[$layer_cnt]->layer_dataurl_href =$row2["layer_dataurl"];
+				$this->objLayer[$layer_cnt]->layer_metadataurl =$row2["layer_metadataurl"];
+				$this->objLayer[$layer_cnt]->layer_pos =$row2["layer_pos"];						
+				$this->objLayer[$layer_cnt]->layer_queryable =$row2["layer_pos"];
+				$this->objLayer[$layer_cnt]->layer_queryable =$row2["layer_queryable"];
+				$this->objLayer[$layer_cnt]->layer_minscale =$row2["layer_minscale"];
+				$this->objLayer[$layer_cnt]->layer_maxscale = $row2["layer_maxscale"];
+				$count_layer++;
+			}
+			$this->objLayer[$layer_cnt]->layer_uid = $layer_id;
+			$this->objLayer[$layer_cnt]->gui_layer_wms_id = $row["gui_layer_wms_id"];
+			$this->objLayer[$layer_cnt]->gui_layer_selectable = $row["gui_layer_selectable"];
+			$this->objLayer[$layer_cnt]->gui_layer_visible = $row["gui_layer_visible"];
+			$this->objLayer[$layer_cnt]->gui_layer_queryable = $row["gui_layer_queryable"];
+			$this->objLayer[$layer_cnt]->gui_layer_querylayer = $row["gui_layer_querylayer"];
+			$this->objLayer[$layer_cnt]->gui_layer_minscale = $row["gui_layer_minscale"];
+			$this->objLayer[$layer_cnt]->gui_layer_maxscale = $row["gui_layer_maxscale"];
+			$this->objLayer[$layer_cnt]->gui_layer_wfs_featuretype = $row["gui_layer_wfs_featuretype"];
+			
+			$sql = "Select * from layer_epsg where fkey_layer_id = $1 ORDER BY fkey_layer_id";
+			$v = array($layer_id);
+			$t = array('i');
+			$res_layer_epsg = db_prep_query($sql,$v,$t);
+			
+			$count_layer_epsg=0;
+			while($row2 = db_fetch_array($res_layer_epsg)){
+				$this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["epsg"]=$row2["epsg"];
+				$this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["minx"]=$row2["minx"];
+				$this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["miny"]=$row2["miny"];
+				$this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["maxx"]=$row2["maxx"];
+				$this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["maxy"]=$row2["maxy"];
+				$j++;
+				$count_layer_epsg++;
+			}
+			
+			### handle styles
+			$sql = "SELECT * FROM layer_style WHERE fkey_layer_id = $1 ";
+			$v = array($layer_id);
+			$t = array('i');
+			$res_style = db_prep_query($sql,$v,$t);
+			$count_layer_style = 0;
+			while($row2 = db_fetch_array($res_style)){
+				$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["name"]=$row2["name"];
+				$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["title"]=$row2["title"];
+				$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"]=$row2["legendurl"];
+				$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurlformat"]=$row2["legendurlformat"];
+				$count_layer_style++;
+			}
+			
+			$count++;
 		}
-		
-		### handle styles
-		$sql = "SELECT * FROM layer_style WHERE fkey_layer_id = $1 ";
-		$v = array($layer_id);
-		$t = array('i');
-		$res_style = db_prep_query($sql,$v,$t);
-		$count_layer_style = 0;
-		while($row2 = db_fetch_array($res_style)){
-			$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["name"]=$row2["name"];
-			$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["title"]=$row2["title"];
-			$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"]=$row2["legendurl"];
-			$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurlformat"]=$row2["legendurlformat"];
-			$count_layer_style++;
+	   }
+	/** end createObjfromDB **/
+	
+	  /**
+	* function checkObjExistsInDB()
+	*
+	* this function checks wether the onlineresource already exists in the database.
+	*/ 
+	function checkObjExistsInDB(){
+	
+		$sql = "Select * from wms where wms_getcapabilities = $1";
+		$v = array($this->wms_getcapabilities);
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
+		$res_count= db_num_rows($res);	  
+		$wms_id=0;
+		if($res_count>0){
+			$count=0;
+			while($row = db_fetch_array($res)){
+				$wms_id=$row["wms_id"];
+				$count++;
+			}
 		}
-		
-		$count++;
+		return $wms_id;
 	}
-   }
-/** end createObjfromDB **/
-
-  /**
-* function checkObjExistsInDB()
-*
-* this function checks wether the onlineresource already exists in the database.
-*/ 
-function checkObjExistsInDB(){
-
-	$sql = "Select * from wms where wms_getcapabilities = $1";
-	$v = array($this->wms_getcapabilities);
-	$t = array('s');
-	$res = db_prep_query($sql,$v,$t);
-	$res_count= db_num_rows($res);	  
-	$wms_id=0;
-	if($res_count>0){
+	
+	function displayDBInformation(){
+		echo $this->wms_getcapabilities;
+		$sql="Select * from wms where wms_getcapabilities = $1";
+		$v = array($this->wms_getcapabilities);
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
 		$count=0;
 		while($row = db_fetch_array($res)){
+		echo "count: ".$count."<br>";
 			$wms_id=$row["wms_id"];
+			echo "version: " .$wms_id." <br>";
+			echo "title: " .$row["wms_version"]. " <br>";
+			echo "abstract: " . $row["wms_title"] . " <br>";
+			echo "maprequest: " .$row["wms_abstract"] . " <br>";
+			echo "capabilitiesrequest: " . $row["wms_getcapabilities"] . " <br>";
+			echo "featureinforequest: " . $row["wms_getmap"]. " <br>";
+			echo "gui_wms_mapformat: " . $row["wms_getfeatureinfo"] . " <br>---------<br>";
 			$count++;
 		}
+	   echo "----<br> wms_id: ".$wms_id."<br>";
+	   
+	   $sql = "Select * from gui_wms where fkey_wms_id = $1";
+	   $v = array($wms_id);
+	   $t = array('i');
+	   echo "sql: ".$sql." <br>---------<br>";
+	   $res = db_prep_query($sql,$v,$t);
+	   $res_count= db_num_rows($res); 
+	   echo "result count: ".$res_count." <br>---------<br>";
+	   
+	   $count=0;
+	   while($row = db_fetch_array($res)){
+	    	echo "gui_wms_featureinfoformat: " . $row["gui_wms_featureinfoformat"]." <br>";
+	    	echo "gui_wms_exceptionformat: " .  $row["gui_wms_exceptionformat"]. " <br>";
+	    	echo "gui_wms_epsg: " .  $row["gui_wms_epsg"]. " <br>";
+	      $count++;
+	   }
+		
+	   #db_close($connect);
 	}
-	return $wms_id;
-}
-
-function displayDBInformation(){
-	echo $this->wms_getcapabilities;
-	$sql="Select * from wms where wms_getcapabilities = $1";
-	$v = array($this->wms_getcapabilities);
-	$t = array('s');
-	$res = db_prep_query($sql,$v,$t);
-	$count=0;
-	while($row = db_fetch_array($res)){
-	echo "count: ".$count."<br>";
-		$wms_id=$row["wms_id"];
-		echo "version: " .$wms_id." <br>";
-		echo "title: " .$row["wms_version"]. " <br>";
-		echo "abstract: " . $row["wms_title"] . " <br>";
-		echo "maprequest: " .$row["wms_abstract"] . " <br>";
-		echo "capabilitiesrequest: " . $row["wms_getcapabilities"] . " <br>";
-		echo "featureinforequest: " . $row["wms_getmap"]. " <br>";
-		echo "gui_wms_mapformat: " . $row["wms_getfeatureinfo"] . " <br>---------<br>";
-		$count++;
-	}
-   echo "----<br> wms_id: ".$wms_id."<br>";
-   
-   $sql = "Select * from gui_wms where fkey_wms_id = $1";
-   $v = array($wms_id);
-   $t = array('i');
-   echo "sql: ".$sql." <br>---------<br>";
-   $res = db_prep_query($sql,$v,$t);
-   $res_count= db_num_rows($res); 
-   echo "result count: ".$res_count." <br>---------<br>";
-   
-   $count=0;
-   while($row = db_fetch_array($res)){
-    	echo "gui_wms_featureinfoformat: " . $row["gui_wms_featureinfoformat"]." <br>";
-    	echo "gui_wms_exceptionformat: " .  $row["gui_wms_exceptionformat"]. " <br>";
-    	echo "gui_wms_epsg: " .  $row["gui_wms_epsg"]. " <br>";
-      $count++;
-   }
-	
-   #db_close($connect);
-  }
   	function char_encode($s){
 		if(CHARSET == 'UTF-8'){
 			$s = utf8_encode($s);
@@ -1586,7 +1589,7 @@
 		}
 	}
 }
-class layer extends wms{	
+class layer extends wms {	
 	var $layer_id;
 	var $layer_parent;
 	var $layer_name;
@@ -1606,7 +1609,7 @@
 	var $gui_layer_status = 1;
 	var $gui_layer_selectable = 1;
 	var $gui_layer_visible = 0;
-	var $gui_layer_queryable;
+	var $gui_layer_queryable = 0;
 	var $gui_layer_querylayer = 0;	
 	
 	function layer($id,$parent){



More information about the Mapbender_commits mailing list