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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Sep 25 10:46:18 EDT 2007


Author: christoph
Date: 2007-09-25 10:46:17 -0400 (Tue, 25 Sep 2007)
New Revision: 1680

Modified:
   trunk/mapbender/http/classes/class_wmc.php
   trunk/mapbender/http/javascripts/mod_savewmc.php
   trunk/mapbender/http/php/mod_insertWmcIntoDb.php
Log:
* moved save wmc to server side
* save in session functionality

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2007-09-25 13:41:22 UTC (rev 1679)
+++ trunk/mapbender/http/classes/class_wmc.php	2007-09-25 14:46:17 UTC (rev 1680)
@@ -29,71 +29,73 @@
 }
 class wmc {
 
-		var $wmc_id;
-		var $wmc_version;
-		var $wmc_windowWidth;
-		var $wmc_windowHeight;
-		var $wmc_bBox_SRS;
-		var $wmc_bBox_minx;
-		var $wmc_bBox_maxx;
-		var $wmc_bBox_miny;
-		var $wmc_bBox_maxy;
-		var $wmc_name;
-		var $wmc_title;
-		var $wmc_abstract;
-		var $wmc_logourl;
-		var $wmc_logourl_format;
-		var $wmc_logourl_type;
-		var $wmc_logourl_width;
-		var $wmc_logourl_height;
-		var $wmc_descriptionurl;
-		var $wmc_descriptionurl_format;
-		var $wmc_descriptionurl_type;
-		var $wmc_keyword = array();
-		var $wmc_contactposition;
-		var $wmc_contactvoicetelephone;
-		var $wmc_contactemail;
-		var $wmc_contactfacsimiletelephone;
-		var $wmc_contactperson;
-		var $wmc_contactorganization;
-		var $wmc_contactaddresstype;
-		var $wmc_contactaddress;
-		var $wmc_contactcity;
-		var $wmc_contactstateorprovince;
-		var $wmc_contactpostcode;
-		var $wmc_contactcountry;
-					
-		var $wmc_wms_title = array();
-		var $wmc_layer_queryable = array();
-		var $wmc_layer_querylayer = array();
-		var $wmc_layer_hidden = array();
-		var $wmc_wms_id = array();
-		var $wmc_wms_service = array();
-		var $wmc_wms_version = array();
-		var $wmc_layer_id = array();
-		var $wmc_layer_title = array();
-		var $wmc_layer_name = array();
-		var $wmc_layer_abstract = array();
-		var $wmc_layer_srs = array();
-		var $wmc_wms_serviceURL = array();
-		var $wmc_layer_format_current = array();
-		var $wmc_layer_dataurl = array();
-		var $wmc_layer_metadataurl = array();
-		var $wmc_layer_minscale = array();
-		var $wmc_layer_maxscale = array();
-		var $wmc_layer_format = array();
-		var $wmc_layer_style_current = array();
-		var $wmc_layer_style_name = array();
-		var $wmc_layer_style_title = array();
-		var $wmc_layer_style_legendurl = array();
-		var $wmc_layer_style_legendurl_width = array();
-		var $wmc_layer_style_legendurl_height = array();
-		var $wmc_layer_style_legendurl_format = array();
-		var $wmc_layer_style_legendurl_type = array();
-		var $wmc_layer_style_sld_url = array();
-		var $wmc_layer_style_sld_type = array();
-		var $wmc_layer_style_sld_title = array();
-		var $wmc_wms_count = 0;
+	var $xml;
+
+	var $wmc_id;
+	var $wmc_version;
+	var $wmc_windowWidth;
+	var $wmc_windowHeight;
+	var $wmc_bBox_SRS;
+	var $wmc_bBox_minx;
+	var $wmc_bBox_maxx;
+	var $wmc_bBox_miny;
+	var $wmc_bBox_maxy;
+	var $wmc_name;
+	var $wmc_title;
+	var $wmc_abstract;
+	var $wmc_logourl;
+	var $wmc_logourl_format;
+	var $wmc_logourl_type;
+	var $wmc_logourl_width;
+	var $wmc_logourl_height;
+	var $wmc_descriptionurl;
+	var $wmc_descriptionurl_format;
+	var $wmc_descriptionurl_type;
+	var $wmc_keyword = array();
+	var $wmc_contactposition;
+	var $wmc_contactvoicetelephone;
+	var $wmc_contactemail;
+	var $wmc_contactfacsimiletelephone;
+	var $wmc_contactperson;
+	var $wmc_contactorganization;
+	var $wmc_contactaddresstype;
+	var $wmc_contactaddress;
+	var $wmc_contactcity;
+	var $wmc_contactstateorprovince;
+	var $wmc_contactpostcode;
+	var $wmc_contactcountry;
+				
+	var $wmc_wms_title = array();
+	var $wmc_layer_queryable = array();
+	var $wmc_layer_querylayer = array();
+	var $wmc_layer_hidden = array();
+	var $wmc_wms_id = array();
+	var $wmc_wms_service = array();
+	var $wmc_wms_version = array();
+	var $wmc_layer_id = array();
+	var $wmc_layer_title = array();
+	var $wmc_layer_name = array();
+	var $wmc_layer_abstract = array();
+	var $wmc_layer_srs = array();
+	var $wmc_wms_serviceURL = array();
+	var $wmc_layer_format_current = array();
+	var $wmc_layer_dataurl = array();
+	var $wmc_layer_metadataurl = array();
+	var $wmc_layer_minscale = array();
+	var $wmc_layer_maxscale = array();
+	var $wmc_layer_format = array();
+	var $wmc_layer_style_current = array();
+	var $wmc_layer_style_name = array();
+	var $wmc_layer_style_title = array();
+	var $wmc_layer_style_legendurl = array();
+	var $wmc_layer_style_legendurl_width = array();
+	var $wmc_layer_style_legendurl_height = array();
+	var $wmc_layer_style_legendurl_format = array();
+	var $wmc_layer_style_legendurl_type = array();
+	var $wmc_layer_style_sld_url = array();
+	var $wmc_layer_style_sld_type = array();
+	var $wmc_layer_style_sld_title = array();
+	var $wmc_wms_count = 0;
 			
 	function wmc() {	
 	} 
@@ -106,6 +108,446 @@
 		return $this->wmc_wms_count;
 	}
 
+function createWMCFromObj($mapObject, $user_id, $generalTitle) {
+	$this->wmc_id = $user_id . '_' . time();
+	
+	$generalWidth = $mapObject->width;
+	$generalHeight = $mapObject->height;
+	$generalBboxSrs = $mapObject->epsg;
+	
+	$arrayBBox = explode(",", $mapObject->extent);
+	$generalBboxMinx = floatval($arrayBBox[0]);
+	$generalBboxMiny = floatval($arrayBBox[1]);
+	$generalBboxMaxx = floatval($arrayBBox[2]);
+	$generalBboxMaxy = floatval($arrayBBox[3]);
+	
+	$generalName = "Mapbender WMC"; // TO do : insert proper data
+	$generalKeywords = array("Mapbender", "WMC"); // TO do : insert proper data
+	$generalAbstract = ""; // TO do : insert proper data
+	$generalLogoUrl = ""; // TO do : insert proper data
+	$generalLogoUrlWidth = ""; // TO do : insert proper data
+	$generalLogoUrlHeight = ""; // TO do : insert proper data
+	$generalLogoUrlFormat = ""; // TO do : insert proper data
+	$generalDescriptionUrl = ""; // TO do : insert proper data
+	$generalContactPerson = "";
+	$generalContactOrganization = "";
+	$generalContactPosition = "";
+	$generalContactAddressType = "";
+	$generalContactAddress = "";
+	$generalContactCity = "";
+	$generalContactStateOrProvince = "";
+	$generalContactPostCode = "";
+	$generalContactCountry = "";
+	$generalContactVoiceTelephone = "";
+	$generalContactFacsimileTelephone = "";
+	$generalContactElectronicMailAddress = "";
+			
+	$extension_namespace = "mapbender";
+	
+	// LayerList variables
+	$layerHidden = "";
+	$layerQueryable = "";
+	$layerAbstract = "";
+	$layerName = "";
+	$layerSrs = "";
+	$layerDataUrl = "";
+	$layerMetadataUrl = "";
+	$layerFormat = "";
+	$layerFormat_current = "";
+	$layerStyle_current = "";
+	$layerStyle_name = "";
+	$layerStyle_title = "";
+	$layerStyle_legendURL = "";
+	$layerStyle_legendURL_width = "";
+	$layerStyle_legendURL_height = "";
+	$layerStyle_legendURL_format = "";		
+	
+	// generate XML
+	$doc = new DOMDocument("1.0", CHARSET);
+	$doc->preserveWhiteSpace = false;
+	
+	// ViewContext
+	$e_view_context = $doc->createElementNS("http://www.opengis.net/context", "ViewContext");
+	
+	
+	$e_view_context->setAttribute("version", "1.0.0");
+	$e_view_context->setAttribute("id", $this->wmc_id);
+	$e_view_context->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+	$e_view_context->setAttribute("xmlns:mapbender", "http://www.mapbender.org");
+	$e_view_context->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+	$e_view_context->setAttribute("xsi:SchemaLocation", "http://schemas.opengis.net/context/1.0.0/context.xsd");
+	
+		// General
+		$e_general = $doc->createElement("General");
+	
+			$e_window = $doc->createElement("Window");
+			if (!empty($generalWidth) && !empty($generalHeight)) {
+				$e_window->setAttribute("width", $generalWidth);
+				$e_window->setAttribute("height", $generalHeight);
+			}
+			$e_general->appendChild($e_window);
+			
+			$e_bbox = $doc->createElement("BoundingBox");
+			$e_bbox->setAttribute("SRS", $generalBboxSrs);
+			$e_bbox->setAttribute("minx", $generalBboxMinx);
+			$e_bbox->setAttribute("miny", $generalBboxMiny);
+			$e_bbox->setAttribute("maxx", $generalBboxMaxx);
+			$e_bbox->setAttribute("maxy", $generalBboxMaxy);
+			$e_general->appendChild($e_bbox);
+			
+			$e_name = $doc->createElement("Name", $generalName);
+			$e_general->appendChild($e_name);
+			
+			$e_title = $doc->createElement("Title", $generalTitle);
+			$e_general->appendChild($e_title);
+			
+			$e_keyword_list = $doc->createElement("KeywordList");
+			for ($i=0; $i < count($generalKeywords); $i++) {
+				$e_keyword = $doc->createElement("Keyword", $generalKeywords[$i]);
+				$e_keyword_list->appendChild($e_keyword);
+			}
+			$e_general->appendChild($e_keyword_list);
+			
+			if ($generalAbstract){
+				$e_abstract = $doc->createElement("Abstract", $generalAbstract);
+				$e_general->appendChild($e_abstract);
+			}
+			
+			if ($generalLogoUrlWidth && $generalLogoUrlHeight && $generalLogoUrlFormat && $generalLogoUrl){
+				$e_logo_url = $doc->createElement("LogoURL");
+				$e_logo_url->setAttribute("width", $generalLogoUrlWidth);
+				$e_logo_url->setAttribute("height", $generalLogoUrlHeight);
+				$e_logo_url->setAttribute("format", $generalLogoUrlFormat);
+			
+				$e_logo_url_or = $doc->createElement("OnlineResource");
+				$e_logo_url_or->setAttributeNS("http://www.opengis.net/context", "xmlns:xlink", "http://www.w3.org/1999/xlink");
+				$e_logo_url_or->setAttribute("xlink:type", "simple");
+				$e_logo_url_or->setAttribute("xlink:href", $generalLogoUrl);
+				$e_logo_url->appendChild($e_logo_url_or);
+	
+				$e_general->appendChild($e_logo_url);
+			}
+				
+			if ($generalDescriptionUrl){
+				$e_description_url = $doc->createElement("DescriptionURL");
+	
+				$e_description_url_or = $doc->createElement("OnlineResource");
+				$e_description_url_or->setAttributeNS("http://www.opengis.net/context", "xmlns:xlink", "http://www.w3.org/1999/xlink");
+				$e_description_url_or->setAttribute("xlink:type", "simple");
+				$e_description_url_or->setAttribute("xlink:href", $generalDescriptionUrl);
+				$e_description_url->appendChild($e_description_url_or);
+	
+				$e_general->appendChild($e_description_url);
+			}
+			
+			if ($generalContactElectronicMailAddress || $generalContactOrganization ||
+				$generalContactPerson || $generalContactPosition || $generalContactAddressType ||
+				$generalContactAddress || $generalContactCity || $generalContactStateOrProvince ||
+				$generalContactPostCode || $generalContactCountry || $generalContactVoiceTelephone ||
+				$generalContactFacsimileTelephone || $generalContactElectronicMailAddress) {
+			
+				$e_contact = $doc->createElement("ContactInformation");
+			
+				if ($generalContactPerson || $generalContactOrganization){
+					$e_contact_person_primary = $doc->createElement("ContactPersonPrimary");
+			
+					if ($generalContactPerson){
+						$e_contact_person = $doc->createElement("ContactPerson", $generalContactPerson);
+						$e_contact_person_primary->appendChild($e_contact_person);
+					}
+					if ($generalContactOrganization){
+						$e_contact_organization = $doc->createElement("ContactOrganization", $generalContactOrganization);
+						$e_contact_person_primary->appendChild($e_contact_organization);
+					}
+					$e_contact->appendChild($e_contact_person_primary);
+				}
+			
+				if ($generalContactPosition){
+					$e_contact_position = $doc->createElement("ContactPosition", $generalContactPosition);
+					$e_contact->appendChild($e_contact_position);
+				}
+			
+				if ($generalContactAddressType || $generalContactAddress || 
+					$generalContactCity || $generalContactStateOrProvince ||
+					$generalContactPostCode || $generalContactCountry) {
+			
+					$e_contact_address = $doc->createElement("ContactAddress");
+			
+					if ($generalContactAddressType){
+						$e_address_type = $doc->createElement("AddressType", $generalContactAddressType);
+						$e_contact_address->appendChild($e_address_type);
+					}
+					if ($generalContactAddress){
+						$e_address = $doc->createElement("Address", $generalContactAddress);
+						$e_contact_address->appendChild($e_address);
+					}
+					if ($generalContactCity){
+						$e_city = $doc->createElement("City", $generalContactCity);
+						$e_contact_address->appendChild($e_city);
+					}
+					if ($generalContactStateOrProvince){
+						$e_state = $doc->createElement("StateOrProvince", $generalContactStateOrProvince);
+						$e_contact_address->appendChild($e_state);
+					}
+					if ($generalContactPostCode){
+						$e_postcode = $doc->createElement("PostCode", $generalContactPostCode);
+						$e_contact_address->appendChild($e_postcode);
+					}
+					if ($generalContactCountry){
+						$e_country = $doc->createElement("Country", $generalContactCountry);
+						$e_contact_address->appendChild($e_country);
+					}
+					$e_contact->appendChild($e_contact_address);
+				}
+				
+				if ($generalContactVoiceTelephone){
+					$e_voice_telephone = $doc->createElement("ContactVoiceTelephone", $generalContactVoiceTelephone);
+					$e_contact->appendChild($e_voice_telephone);
+				}
+				if ($generalContactFacsimileTelephone){
+					$e_facsimile_telephone = $doc->createElement("ContactFacsimileTelephone", $generalContactFacsimileTelephone);
+					$e_contact->appendChild($e_facsimile_telephone);
+				}
+				if ($generalContactElectronicMailAddress){
+					$e_email = $doc->createElement("ContactElectronicMailAddress", $generalContactElectronicMailAddress);
+					$e_contact->appendChild($e_email);
+				}
+				$e_general->appendChild($e_contact);
+			}
+		$e_view_context->appendChild($e_general);
+	
+	
+		// LayerList
+		$e_layer_list = $doc->createElement("LayerList");
+	
+		for ($i=0; $i < count($mapObject->wms); $i++){
+			$wmsId = $mapObject->wms[$i]->wms_id;
+			$wms_epsg = array();
+			$wms_epsg[0] = $mapObject->epsg;
+		
+			if ($mapObject->wms[$i]->gui_wms_epsg != $mapObject->epsg){
+				$wms_epsg[1] = $mapObject->wms[$i]->gui_wms_epsg;
+			}
+	
+			for ($q = 0; $q < count($mapObject->wms[$i]->gui_epsg); $q++){
+				$isInArray = false;
+				
+				for ($r=0 ; $r < count($wms_epsg); $r++){
+					if ($wms_epsg[$r] == $mapObject->wms[$i]->gui_epsg[$q]){
+						$isInArray = true;
+					}
+				}
+				if ($isInArray == false){
+					array_push($wms_epsg, $mapObject->wms[$i]->gui_epsg[$q]);
+				}
+			}
+			for ($j = 0; $j < count($mapObject->wms[$i]->objLayer); $j++){
+				if ($mapObject->wms[$i]->objLayer[$j]->layer_parent != ''){
+					if ($mapObject->wms[$i]->objLayer[$j]->gui_layer_visible == "1"){
+						$layerHidden = 0;
+					}
+					else{
+						$layerHidden = 1;
+					}
+					$layerQueryable = $mapObject->wms[$i]->objLayer[$j]->layer_queryable;
+					$layerQuerylayer = $mapObject->wms[$i]->objLayer[$j]->gui_layer_querylayer;
+					$layerId = $mapObject->wms[$i]->objLayer[$j]->layer_uid;
+					$layerName = $mapObject->wms[$i]->objLayer[$j]->layer_name;
+					$layerTitle = $mapObject->wms[$i]->objLayer[$j]->layer_title;
+					$layerAbstract = $mapObject->wms[$i]->wms_abstract; //To Do: insert actual abstract
+					$layerDataUrl = $mapObject->wms[$i]->objLayer[$j]->layer_dataurl_href; 
+					$layerMetadataUrl = $mapObject->wms[$i]->objLayer[$j]->layer_metadataurl;
+					$layerMinscale = $mapObject->wms[$i]->objLayer[$j]->layer_minscale; 
+					$layerMaxscale = $mapObject->wms[$i]->objLayer[$j]->layer_maxscale; 
+					$wmsVersion = $mapObject->wms[$i]->wms_version;
+					$wmsTitle = $mapObject->wms[$i]->wms_title;
+					$wmsLayerId = $mapObject->wms[$i]->objLayer[0]->layer_uid;
+					$wmsOnlineResource = $mapObject->wms[$i]->wms_getmap;
+					$layerPos = $mapObject->wms[$i]->objLayer[$j]->layer_pos;
+					$layerParent = $mapObject->wms[$i]->objLayer[$j]->layer_parent;
+					$queryLayer = $mapObject->wms[$i]->objLayer[$j]->gui_layer_querylayer;
+		
+					$e_layer = $doc->createElement("Layer");
+					$e_layer->setAttribute("queryable", $layerQueryable);
+					$e_layer->setAttribute("hidden", $layerHidden);
+		
+						$e_service = $doc->createElement("Server");
+						$e_service->setAttribute("service", "OGC:WMS");
+						$e_service->setAttribute("version", $wmsVersion);
+						$e_service->setAttribute("title", $wmsTitle);
+		
+						$e_service_or = $doc->createElement("OnlineResource");
+						$e_service_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+						$e_service_or->setAttribute("xlink:type", "simple");
+						$e_service_or->setAttribute("xlink:href", $wmsOnlineResource);
+						
+						$e_service->appendChild($e_service_or);
+						$e_layer->appendChild($e_service);
+		
+						$e_layer_name = $doc->createElement("Name", $layerName);
+						$e_layer->appendChild($e_layer_name);
+		
+						$e_layer_title = $doc->createElement("Title", $layerTitle);
+						$e_layer->appendChild($e_layer_title);
+		
+						if ($layerAbstract){
+							$e_layer_abstract = $doc->createElement("Abstract", $layerAbstract);
+							$e_layer->appendChild($e_layer_abstract);
+						}
+		
+						$e_layer_srs = $doc->createElement("SRS", implode(" ", $wms_epsg));
+						$e_layer->appendChild($e_layer_name);
+		
+						if ($layerDataUrl){
+							$e_layer_data_url = $doc->createElement("DataURL");
+			
+							$e_layer_data_url_or = $doc->createElement("OnlineResource");
+							$e_layer_data_url_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+							$e_layer_data_url_or->setAttribute("xlink:type", "simple");
+							$e_layer_data_url_or->setAttribute("xlink:href", $layerDataUrl);
+							
+							$e_layer_data_url->appendChild($e_layer_data_url_or);
+							$e_layer->appendChild($e_layer_data_url);
+						}
+		
+						if ($layerMetadataUrl){
+							$e_layer_metadata_url = $doc->createElement("MetadataURL");
+			
+							$e_layer_metadata_url_or = $doc->createElement("OnlineResource");
+							$e_layer_metadata_url_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+							$e_layer_metadata_url_or->setAttribute("xlink:type", "simple");
+							$e_layer_metadata_url_or->setAttribute("xlink:href", $layerMetadataUrl);
+							
+							$e_layer_metadata_url->appendChild($e_layer_metadata_url_or);
+							$e_layer->appendChild($e_layer_metadata_url);
+						}
+		
+						$e_extension = $doc->createElement("Extension");
+		
+						$e_scalehint = $doc->createElement($extension_namespace.":ScaleHint");
+						$e_scalehint->setAttribute("min", $layerMinscale);
+						$e_scalehint->setAttribute("max", $layerMaxscale);
+						$e_extension->appendChild($e_scalehint);
+						
+						$e_layer_id = $doc->createElement($extension_namespace.":layer_id", $layerId);
+						$e_extension->appendChild($e_layer_id);
+						
+						$e_wms_layer_id = $doc->createElement($extension_namespace.":wms_layer_id", $wmsLayerId);
+						$e_extension->appendChild($e_wms_layer_id);
+						
+						$e_layer_pos = $doc->createElement($extension_namespace.":layer_pos", $layerPos);
+						$e_extension->appendChild($e_layer_pos);
+		
+						$e_layer_parent = $doc->createElement($extension_namespace.":layer_parent", $layerParent);
+						$e_extension->appendChild($e_layer_parent);
+		
+						$e_wms_id = $doc->createElement($extension_namespace.":wms_id", $wmsId);
+						$e_extension->appendChild($e_wms_id);
+		
+						$e_querylayer = $doc->createElement($extension_namespace.":querylayer", $layerQuerylayer);
+						$e_extension->appendChild($e_querylayer);
+
+						$e_layer->appendChild($e_extension);
+		
+						//layerFormat
+						$e_layer_format = $doc->createElement("FormatList");
+		
+						$data_format_current = false;
+		
+						for ($k = 0; $k < count($mapObject->wms[$i]->data_format); $k++){
+		
+							if ($mapObject->wms[$i]->data_type[$k] == "map") {
+								$layerFormat = $mapObject->wms[$i]->data_format[$k];
+				
+								$e_format = $doc->createElement("Format", $layerFormat);
+		
+								if ($data_format_current == false && ( 
+										($mapObject->wms[$i]->data_format[$k] == $mapObject->wms[$i]->gui_wms_mapformat) ||
+										($k == (count($mapObject->wms[$i]->data_format)-1))
+								)){
+		
+									$e_format->setAttribute("current", "1");
+									$data_format_current = true;
+								}
+								$e_layer_format->appendChild($e_format);
+							}
+						}
+						$e_layer->appendChild($e_layer_format);
+		
+		
+						// LayerStyle
+						$e_layer_stylelist = $doc->createElement("StyleList");
+			
+						for ($k = 0; $k < count($mapObject->wms[$i]->objLayer[$j]->layer_style); $k++){
+		
+							if ($k == 0){
+								$layerStyle_current = 1; // To do: insert proper data
+							}
+							else{
+								$layerStyle_current = 0; // To do: insert proper data
+							}
+		
+							$e_layer_style = $doc->createElement("Style");
+		
+							$layerStyleSLD = "";
+		
+							if ($layerStyleSLD){
+								$layerStyleSLDUrl = ""; // To Do: Insert Proper Data
+								
+								$e_layer_style_or = $doc->createElement("OnlineResource");
+								$e_layer_style_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+								$e_layer_style_or->setAttribute("xlink:type", "simple");
+								$e_layer_style_or->setAttribute("xlink:href", $layerStyleSLDUrl);
+								$e_layer_style->appendChild($e_layer_style_or);
+							}
+							else{
+								//TODO: determine correct layer style entries
+								$layerStyle_name = $mapObject->wms[$i]->objLayer[$j]->layer_style[$k]->name;
+								$layerStyle_title = $mapObject->wms[$i]->objLayer[$j]->layer_style[$k]->title;
+								$layerStyle_legendUrl = $mapObject->wms[$i]->objLayer[$j]->layer_style[$k]->legendurl;
+								$layerStyle_legendUrl_width = ""; // To Do: add proper data
+								$layerStyle_legendUrl_height = ""; // To Do: add proper data
+								$layerStyle_legendUrl_format = ""; // To Do: add proper data
+		
+								if ($layerStyle_current == 1){
+									$e_layer_style->setAttribute("current", "1");
+								}
+	
+								$e_layer_style_name = $doc->createElement("Name", $layerStyle_name);
+								$e_layer_style->appendChild($e_layer_style_name);
+	
+								$e_layer_style_title = $doc->createElement("Title", $layerStyle_title);
+								$e_layer_style->appendChild($e_layer_style_title);
+								
+								
+								$e_layer_style_legendurl = $doc->createElement("LegendUrl");
+								$e_layer_style_legendurl->setAttribute("width", $layerStyle_legendUrl_width);
+								$e_layer_style_legendurl->setAttribute("height", $layerStyle_legendUrl_height);
+								$e_layer_style_legendurl->setAttribute("format", $layerStyle_legendUrl_format);
+	
+								$e_layer_style_legendurl_or = $doc->createElement("OnlineResource");
+								$e_layer_style_legendurl_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+								$e_layer_style_legendurl_or->setAttribute("xlink:type", "simple");
+								$e_layer_style_legendurl_or->setAttribute("xlink:href", $layerStyle_legendUrl);
+								$e_layer_style_legendurl->appendChild($e_layer_style_legendurl_or);
+								$e_layer_style->appendChild($e_layer_style_legendurl);
+							}
+							$e_layer_stylelist->appendChild($e_layer_style);
+						}	
+						$e_layer->appendChild($e_layer_stylelist);
+						
+					$e_layer_list->appendChild($e_layer);
+				}
+			}
+		}
+		$e_view_context->appendChild($e_layer_list);
+	
+	
+	$doc->appendChild($e_view_context);
+	$this->xml = $doc->saveXML();
+}
+
+
 	function createObjFromWMC_id($wmc_id){
 		
 		$con = db_connect(DBSERVER,OWNER,PW);

Modified: trunk/mapbender/http/javascripts/mod_savewmc.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_savewmc.php	2007-09-25 13:41:22 UTC (rev 1679)
+++ trunk/mapbender/http/javascripts/mod_savewmc.php	2007-09-25 14:46:17 UTC (rev 1680)
@@ -17,43 +17,68 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
+$gui_id = $_REQUEST["gui_id"];
 require_once("../../conf/mapbender.conf");
+$con = db_connect($DBSERVER,$OWNER,$PW);
+db_select_db(DB,$con);
+$sql = "SELECT e_src, e_target FROM gui_element WHERE e_id = 'savewmc' AND fkey_gui_id = $1";
+$v = array($gui_id);
+$t = array('s');
+$res = db_prep_query($sql, $v, $t);
+$cnt = 0;
+while($row = db_fetch_array($res)){
+	$e_src = $row["e_src"];
+	$e_target = $row["e_target"];
+	$cnt++;
+}
+if($cnt > 1){
+	echo "alert('savewmc: ID not unique!');";
+}
 
-$gui_id = $_REQUEST["gui_id"];
-
+$e_id_css = "savewmc";
 include("../include/dyn_js.php");
 
 echo "mod_savewmc_target = '".$e_target."';";
 ?>
 function setOnUnload() {
-	document.getElementsByTagName('body')[0].setAttribute("onUnload", "mod_savewmc('session');");
+	if (ie) {
+		document.getElementsByTagName('body')[0].onunload = function() {var x = new Function ("", "mod_savewmc_session()"); x(); };
+	}
+	else {
+		document.getElementsByTagName('body')[0].setAttribute("onUnload", "mod_savewmc_session();");
+	}
 }
 
 try {if (saveInSession) {}}catch(e) {saveInSession = 0;}
 
-if (saveInSession == '1') {
+if (saveInSession == 1) {
 	mb_registerInitFunctions('setOnUnload()');
 }
 
 var mod_savewmc_img = new Image(); mod_savewmc_img.src = "<?php  echo $e_src;  ?>";
 //var mod_savewmc_img_over = new Image(); mod_savewmc_img_over.src = "<?php  echo preg_replace("/_off/","_over",$e_src);  ?>";
 
+function mod_savewmc_session(){
+	var user = "<?php echo $_SESSION["mb_user_id"]; ?>";
+	var ind = getMapObjIndexByName(mod_savewmc_target);
+	var generalTitle = "session";
+	window.frames['ajax'].$.ajaxSetup({async:false}); //TODO: find out why async doesn't work sometimes
+	window.frames['ajax'].$.post("../php/mod_insertWmcIntoDb.php", {"saveInSession":1, "generalTitle":generalTitle, "mapObject":mb_mapObj[ind].toJSONString()}, function (result, status) {
+	});
+}
 
 function mod_savewmc(title){
-	
+	var user = "<?php echo $_SESSION["mb_user_id"]; ?>";
 	var ind = getMapObjIndexByName(mod_savewmc_target);
-	var session = 0;
-	var generalTitle = title;
-
-	if (generalTitle) {
-		if (generalTitle == 'session') {
-			session = 1;
-		}
+	var generalTitle;
+	if (title) {
+		generalTitle = title;
 	}
 	else {
 		generalTitle = prompt("Save WMC as...");
 	}
-	mb_ajax_post("../php/mod_insertWmcIntoDb.php", {"saveInSession":session, "generalTitle":generalTitle, "mapObject":mb_mapObj[ind].toJSONString()}, function (result, status) {
-		alert(result);
+	window.frames['ajax'].$.ajaxSetup({async:false}); //TODO: find out why async doesn't work onunload
+	window.frames['ajax'].$.post("../php/mod_insertWmcIntoDb.php", {"saveInSession":0, "generalTitle":generalTitle, "mapObject":mb_mapObj[ind].toJSONString()}, function (result, status) {
+		alert(status + ": " + result);
 	});
 }
\ No newline at end of file

Modified: trunk/mapbender/http/php/mod_insertWmcIntoDb.php
===================================================================
--- trunk/mapbender/http/php/mod_insertWmcIntoDb.php	2007-09-25 13:41:22 UTC (rev 1679)
+++ trunk/mapbender/http/php/mod_insertWmcIntoDb.php	2007-09-25 14:46:17 UTC (rev 1680)
@@ -20,462 +20,47 @@
 require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
 require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
 require_once(dirname(__FILE__)."/../classes/class_administration.php");
+require_once(dirname(__FILE__)."/../classes/class_wmc.php");
 require_once(dirname(__FILE__)."/../extensions/JSON.php");
 
 session_start();
-
 $con = db_connect($DBSERVER,$OWNER,$PW);
 db_select_db(DB,$con);
 
-
 $json = new Services_JSON();
-$mapObject = $json->decode($_REQUEST["mapObject"]);
+$mapObject = $json->decode(stripslashes($_POST["mapObject"]));
 $user_id = $_SESSION["mb_user_id"];
 $save_in_session = $_POST["saveInSession"];
 $generalTitle = $_POST["generalTitle"];
 
-$wmc_id = $user_id . '_' . time();
+$wmc = new wmc();
+$wmc->createWMCFromObj($mapObject, $user_id, $generalTitle);
 
-$generalWidth = $mapObject->width;
-$generalHeight = $mapObject->height;
-$generalBboxSrs = $mapObject->epsg;
 
-$arrayBBox = explode(",", $mapObject->extent);
-$generalBboxMinx = floatval($arrayBBox[0]);
-$generalBboxMiny = floatval($arrayBBox[1]);
-$generalBboxMaxx = floatval($arrayBBox[2]);
-$generalBboxMaxy = floatval($arrayBBox[3]);
-
-$generalName = "Mapbender WMC"; // TO do : insert proper data
-$generalKeywords = array("Mapbender", "WMC"); // TO do : insert proper data
-$generalAbstract = ""; // TO do : insert proper data
-$generalLogoUrl = ""; // TO do : insert proper data
-$generalLogoUrlWidth = ""; // TO do : insert proper data
-$generalLogoUrlHeight = ""; // TO do : insert proper data
-$generalLogoUrlFormat = ""; // TO do : insert proper data
-$generalDescriptionUrl = ""; // TO do : insert proper data
-$generalContactPerson = "";
-$generalContactOrganization = "";
-$generalContactPosition = "";
-$generalContactAddressType = "";
-$generalContactAddress = "";
-$generalContactCity = "";
-$generalContactStateOrProvince = "";
-$generalContactPostCode = "";
-$generalContactCountry = "";
-$generalContactVoiceTelephone = "";
-$generalContactFacsimileTelephone = "";
-$generalContactElectronicMailAddress = "";
-		
-$extension_namespace = "mapbender";
-
-// LayerList variables
-$layerHidden = "";
-$layerQueryable = "";
-$layerAbstract = "";
-$layerName = "";
-$layerSrs = "";
-$layerDataUrl = "";
-$layerMetadataUrl = "";
-$layerFormat = "";
-$layerFormat_current = "";
-$layerStyle_current = "";
-$layerStyle_name = "";
-$layerStyle_title = "";
-$layerStyle_legendURL = "";
-$layerStyle_legendURL_width = "";
-$layerStyle_legendURL_height = "";
-$layerStyle_legendURL_format = "";		
-
-// generate XML
-$doc = new DOMDocument("1.0", CHARSET);
-$doc->preserveWhiteSpace = false;
-
-// ViewContext
-$e_view_context = $doc->createElementNS("http://www.opengis.net/context", "ViewContext");
-
-
-$e_view_context->setAttribute("version", "1.0.0");
-$e_view_context->setAttribute("id", $wmc_id);
-$e_view_context->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-$e_view_context->setAttribute("xmlns:mapbender", "http://www.mapbender.org");
-$e_view_context->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
-$e_view_context->setAttribute("xsi:SchemaLocation", "http://schemas.opengis.net/context/1.0.0/context.xsd");
-
-	// General
-	$e_general = $doc->createElement("General");
-
-		$e_window = $doc->createElement("Window");
-		if (!empty($generalWidth) && !empty($generalHeight)) {
-			$e_window->setAttribute("width", $generalWidth);
-			$e_window->setAttribute("height", $generalHeight);
-		}
-		$e_general->appendChild($e_window);
-		
-		$e_bbox = $doc->createElement("BoundingBox");
-		$e_bbox->setAttribute("SRS", $generalBboxSrs);
-		$e_bbox->setAttribute("minx", $generalBboxMinx);
-		$e_bbox->setAttribute("miny", $generalBboxMiny);
-		$e_bbox->setAttribute("maxx", $generalBboxMaxx);
-		$e_bbox->setAttribute("maxy", $generalBboxMaxy);
-		$e_general->appendChild($e_bbox);
-		
-		$e_name = $doc->createElement("Name", $generalName);
-		$e_general->appendChild($e_name);
-		
-		$e_title = $doc->createElement("Title", $generalTitle);
-		$e_general->appendChild($e_title);
-		
-		$e_keyword_list = $doc->createElement("KeywordList");
-		for ($i=0; $i < count($generalKeywords); $i++) {
-			$e_keyword = $doc->createElement("Keyword", $generalKeywords[$i]);
-			$e_keyword_list->appendChild($e_keyword);
-		}
-		$e_general->appendChild($e_keyword_list);
-		
-		if ($generalAbstract){
-			$e_abstract = $doc->createElement("Abstract", $generalAbstract);
-			$e_general->appendChild($e_abstract);
-		}
-		
-		if ($generalLogoUrlWidth && $generalLogoUrlHeight && $generalLogoUrlFormat && $generalLogoUrl){
-			$e_logo_url = $doc->createElement("LogoURL");
-			$e_logo_url->setAttribute("width", $generalLogoUrlWidth);
-			$e_logo_url->setAttribute("height", $generalLogoUrlHeight);
-			$e_logo_url->setAttribute("format", $generalLogoUrlFormat);
-		
-			$e_logo_url_or = $doc->createElement("OnlineResource");
-			$e_logo_url_or->setAttributeNS("http://www.opengis.net/context", "xmlns:xlink", "http://www.w3.org/1999/xlink");
-			$e_logo_url_or->setAttribute("xlink:type", "simple");
-			$e_logo_url_or->setAttribute("xlink:href", $generalLogoUrl);
-			$e_logo_url->appendChild($e_logo_url_or);
-
-			$e_general->appendChild($e_logo_url);
-		}
-			
-		if ($generalDescriptionUrl){
-			$e_description_url = $doc->createElement("DescriptionURL");
-
-			$e_description_url_or = $doc->createElement("OnlineResource");
-			$e_description_url_or->setAttributeNS("http://www.opengis.net/context", "xmlns:xlink", "http://www.w3.org/1999/xlink");
-			$e_description_url_or->setAttribute("xlink:type", "simple");
-			$e_description_url_or->setAttribute("xlink:href", $generalDescriptionUrl);
-			$e_description_url->appendChild($e_description_url_or);
-
-			$e_general->appendChild($e_description_url);
-		}
-		
-		if ($generalContactElectronicMailAddress || $generalContactOrganization ||
-			$generalContactPerson || $generalContactPosition || $generalContactAddressType ||
-			$generalContactAddress || $generalContactCity || $generalContactStateOrProvince ||
-			$generalContactPostCode || $generalContactCountry || $generalContactVoiceTelephone ||
-			$generalContactFacsimileTelephone || $generalContactElectronicMailAddress) {
-		
-			$e_contact = $doc->createElement("ContactInformation");
-		
-			if ($generalContactPerson || $generalContactOrganization){
-				$e_contact_person_primary = $doc->createElement("ContactPersonPrimary");
-		
-				if ($generalContactPerson){
-					$e_contact_person = $doc->createElement("ContactPerson", $generalContactPerson);
-					$e_contact_person_primary->appendChild($e_contact_person);
-				}
-				if ($generalContactOrganization){
-					$e_contact_organization = $doc->createElement("ContactOrganization", $generalContactOrganization);
-					$e_contact_person_primary->appendChild($e_contact_organization);
-				}
-				$e_contact->appendChild($e_contact_person_primary);
-			}
-		
-			if ($generalContactPosition){
-				$e_contact_position = $doc->createElement("ContactPosition", $generalContactPosition);
-				$e_contact->appendChild($e_contact_position);
-			}
-		
-			if ($generalContactAddressType || $arrayBBoxgeneralContactAddress || 
-				$generalContactCity || $generalContactStateOrProvince ||
-				$generalContactPostCode || $generalContactCountry) {
-		
-				$e_contact_address = $doc->createElement("ContactAddress");
-		
-				if ($generalContactAddressType){
-					$e_address_type = $doc->createElement("AddressType", $generalContactAddressType);
-					$e_contact_address->appendChild($e_address_type);
-				}
-				if ($generalContactAddress){
-					$e_address = $doc->createElement("Address", $generalContactAddress);
-					$e_contact_address->appendChild($e_address);
-				}
-				if ($generalContactCity){
-					$e_city = $doc->createElement("City", $generalContactCity);
-					$e_contact_address->appendChild($e_city);
-				}
-				if ($generalContactStateOrProvince){
-					$e_state = $doc->createElement("StateOrProvince", $generalContactStateOrProvince);
-					$e_contact_address->appendChild($e_state);
-				}
-				if ($generalContactPostCode){
-					$e_postcode = $doc->createElement("PostCode", $generalContactPostCode);
-					$e_contact_address->appendChild($e_postcode);
-				}
-				if ($generalContactCountry){
-					$e_country = $doc->createElement("Country", $generalContactCountry);
-					$e_contact_address->appendChild($e_country);
-				}
-				$e_contact->appendChild($e_contact_address);
-			}
-			
-			if ($generalContactVoiceTelephone){
-				$e_voice_telephone = $doc->createElement("ContactVoiceTelephone", $generalContactVoiceTelephone);
-				$e_contact->appendChild($e_voice_telephone);
-			}
-			if ($generalContactFacsimileTelephone){
-				$e_facsimile_telephone = $doc->createElement("ContactFacsimileTelephone", $generalContactFacsimileTelephone);
-				$e_contact->appendChild($e_facsimile_telephone);
-			}
-			if ($generalContactElectronicMailAddress){
-				$e_email = $doc->createElement("ContactElectronicMailAddress", $generalContactElectronicMailAddress);
-				$e_contact->appendChild($e_email);
-			}
-			$e_general->appendChild($e_contact);
-		}
-	$e_view_context->appendChild($e_general);
-
-
-	// LayerList
-	$e_layer_list = $doc->createElement("LayerList");
-
-	for ($i=0; $i < count($mapObject->wms); $i++){
-		$wmsId = $mapObject->wms[$i]->wms_id;
-		$wms_epsg = array();
-		$wms_epsg[0] = $mapObject->epsg;
-	
-		if ($mapObject->wms[$i]->gui_wms_epsg != $mapObject->epsg){
-			$wms_epsg[1] = $mapObject->wms[$i]->gui_wms_epsg;
-		}
-
-		for ($q = 0; $q < count($mapObject->wms[$i]->gui_epsg); $q++){
-			$isInArray = false;
-			
-			for ($r=0 ; $r < count($wms_epsg); $r++){
-				if ($wms_epsg[$r] == $mapObject->wms[$i]->gui_epsg[$q]){
-					$isInArray = true;
-				}
-			}
-			if ($isInArray == false){
-				array_push($wms_epsg, $mapObject->wms[$i]->gui_epsg[$q]);
-			}
-		}
-		for ($j = 0; $j < count($mapObject->wms[$i]->objLayer); $j++){
-			if ($mapObject->wms[$i]->objLayer[$j]->layer_parent != ''){
-				if ($mapObject->wms[$i]->objLayer[$j]->gui_layer_visible == "1"){
-					$layerHidden = 0;
-				}
-				else{
-					$layerHidden = 1;
-				}
-				$layerQueryable = $mapObject->wms[$i]->objLayer[$j]->layer_queryable;
-				$layerQuerylayer = $mapObject->wms[$i]->objLayer[$j]->gui_layer_querylayer;
-				$layerId = $mapObject->wms[$i]->objLayer[$j]->layer_uid;
-				$layerName = $mapObject->wms[$i]->objLayer[$j]->layer_name;
-				$layerTitle = $mapObject->wms[$i]->objLayer[$j]->layer_title;
-				$layerAbstract = $mapObject->wms[$i]->wms_abstract; //To Do: insert actual abstract
-				$layerDataUrl = $mapObject->wms[$i]->objLayer[$j]->layer_dataurl_href; 
-				$layerMetadataUrl = $mapObject->wms[$i]->objLayer[$j]->layer_metadataurl;
-				$layerMinscale = $mapObject->wms[$i]->objLayer[$j]->layer_minscale; 
-				$layerMaxscale = $mapObject->wms[$i]->objLayer[$j]->layer_maxscale; 
-				$wmsVersion = $mapObject->wms[$i]->wms_version;
-				$wmsTitle = $mapObject->wms[$i]->wms_title;
-				$wmsOnlineResource = $mapObject->wms[$i]->wms_getmap;
-	
-				$e_layer = $doc->createElement("Layer");
-				$e_layer->setAttribute("queryable", $layerQueryable);
-				$e_layer->setAttribute("hidden", $layerHidden);
-	
-					$e_service = $doc->createElement("Server");
-					$e_service->setAttribute("service", "OGC:WMS");
-					$e_service->setAttribute("version", $wmsVersion);
-					$e_service->setAttribute("title", $wmsTitle);
-	
-					$e_service_or = $doc->createElement("OnlineResource");
-					$e_service_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-					$e_service_or->setAttribute("xlink:type", "simple");
-					$e_service_or->setAttribute("xlink:href", $wmsOnlineResource);
-					
-					$e_service->appendChild($e_service_or);
-					$e_layer->appendChild($e_service);
-	
-					$e_layer_name = $doc->createElement("Name", $layerName);
-					$e_layer->appendChild($e_layer_name);
-	
-					$e_layer_title = $doc->createElement("Title", $layerTitle);
-					$e_layer->appendChild($e_layer_title);
-	
-					if ($layerAbstract){
-						$e_layer_abstract = $doc->createElement("Abstract", $layerAbstract);
-						$e_layer->appendChild($e_layer_abstract);
-					}
-	
-					$e_layer_srs = $doc->createElement("SRS", implode(" ", $wms_epsg));
-					$e_layer->appendChild($e_layer_name);
-	
-					if ($layerDataUrl){
-						$e_layer_data_url = $doc->createElement("DataURL");
-		
-						$e_layer_data_url_or = $doc->createElement("OnlineResource");
-						$e_layer_data_url_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-						$e_layer_data_url_or->setAttribute("xlink:type", "simple");
-						$e_layer_data_url_or->setAttribute("xlink:href", $layerDataUrl);
-						
-						$e_layer_data_url->appendChild($e_layer_data_url_or);
-						$e_layer->appendChild($e_layer_data_url);
-					}
-	
-					if ($layerMetadataUrl){
-						$e_layer_metadata_url = $doc->createElement("MetadataURL");
-		
-						$e_layer_metadata_url_or = $doc->createElement("OnlineResource");
-						$e_layer_metadata_url_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-						$e_layer_metadata_url_or->setAttribute("xlink:type", "simple");
-						$e_layer_metadata_url_or->setAttribute("xlink:href", $layerMetadataUrl);
-						
-						$e_layer_metadata_url->appendChild($e_layer_metadata_url_or);
-						$e_layer->appendChild($e_layer_metadata_url);
-					}
-	
-					$e_extension = $doc->createElement("Extension");
-	
-					$e_scalehint = $doc->createElement($extension_namespace.":ScaleHint");
-					$e_scalehint->setAttribute("min", $layerMinscale);
-					$e_scalehint->setAttribute("max", $layerMaxscale);
-					$e_extension->appendChild($e_scalehint);
-					
-					$e_layer_id = $doc->createElement($extension_namespace.":layer_id", $layerId);
-					$e_extension->appendChild($e_layer_id);
-	
-					$e_wms_id = $doc->createElement($extension_namespace.":wms_id", $wmsId);
-					$e_extension->appendChild($e_wms_id);
-	
-					$e_querylayer = $doc->createElement($extension_namespace.":querylayer", $layerQuerylayer);
-					$e_extension->appendChild($e_querylayer);
-					
-					$e_layer->appendChild($e_extension);
-	
-					//layerFormat
-					$e_layer_format = $doc->createElement("FormatList");
-	
-					$data_format_current = false;
-	
-					for ($k = 0; $k < count($mapObject->wms[$i]->data_format); $k++){
-	
-						if ($mapObject->wms[$i]->data_type[$k] == "map") {
-							$layerFormat = $mapObject->wms[$i]->data_format[$k];
-			
-							$e_format = $doc->createElement("Format", $layerFormat);
-	
-							if ($data_format_current == false && ( 
-									($mapObject->wms[$i]->data_format[$k] == $mapObject->wms[$i]->gui_wms_mapformat) ||
-									($k == (count($mapObject->wms[$i]->data_format)-1))
-							)){
-	
-								$e_format->setAttribute("current", "1");
-								$data_format_current = true;
-							}
-							$e_layer_format->appendChild($e_format);
-						}
-					}
-					$e_layer->appendChild($e_layer_format);
-	
-	
-					// LayerStyle
-					$e_layer_stylelist = $doc->createElement("StyleList");
-		
-					for ($k = 0; $k < count($mapObject->wms[$i]->objLayer[$j]->layer_style); $k++){
-	
-						if ($k == 0){
-							$layerStyle_current = 1; // To do: insert proper data
-						}
-						else{
-							$layerStyle_current = 0; // To do: insert proper data
-						}
-	
-						$e_layer_style = $doc->createElement("Style");
-	
-						$layerStyleSLD = "";
-	
-						if ($layerStyleSLD){
-							$layerStyleSLDUrl = ""; // To Do: Insert Proper Data
-							
-							$e_layer_style_or = $doc->createElement("OnlineResource");
-							$e_layer_style_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-							$e_layer_style_or->setAttribute("xlink:type", "simple");
-							$e_layer_style_or->setAttribute("xlink:href", $layerStyleSLDUrl);
-							$e_layer_style->appendChild($e_layer_style_or);
-						}
-						else{
-							//TODO: determine correct layer style entries
-							$layerStyle_name = $mapObject->wms[$i]->objLayer[$j]->layer_style[$k]->name;
-							$layerStyle_title = $mapObject->wms[$i]->objLayer[$j]->layer_style[$k]->title;
-							$layerStyle_legendUrl = $mapObject->wms[$i]->objLayer[$j]->layer_style[$k]->legendurl;
-							$layerStyle_legendUrl_width = ""; // To Do: add proper data
-							$layerStyle_legendUrl_height = ""; // To Do: add proper data
-							$layerStyle_legendUrl_format = ""; // To Do: add proper data
-	
-							if ($layerStyle_current == 1){
-								$e_layer_style->setAttribute("current", "1");
-							}
-
-							$e_layer_style_name = $doc->createElement("Name", $layerStyle_name);
-							$e_layer_style->appendChild($e_layer_style_name);
-
-							$e_layer_style_title = $doc->createElement("Title", $layerStyle_title);
-							$e_layer_style->appendChild($e_layer_style_title);
-							
-							
-							$e_layer_style_legendurl = $doc->createElement("LegendUrl");
-							$e_layer_style_legendurl->setAttribute("width", $layerStyle_legendUrl_width);
-							$e_layer_style_legendurl->setAttribute("height", $layerStyle_legendUrl_height);
-							$e_layer_style_legendurl->setAttribute("format", $layerStyle_legendUrl_format);
-
-							$e_layer_style_legendurl_or = $doc->createElement("OnlineResource");
-							$e_layer_style_legendurl_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-							$e_layer_style_legendurl_or->setAttribute("xlink:type", "simple");
-							$e_layer_style_legendurl_or->setAttribute("xlink:href", $layerStyle_legendUrl);
-							$e_layer_style_legendurl->appendChild($e_layer_style_legendurl_or);
-							$e_layer_style->appendChild($e_layer_style_legendurl);
-						}
-						$e_layer_stylelist->appendChild($e_layer_style);
-					}	
-					$e_layer->appendChild($e_layer_stylelist);
-					
-				$e_layer_list->appendChild($e_layer);
-			}
-		}
-	}
-	$e_view_context->appendChild($e_layer_list);
-
-
-$doc->appendChild($e_view_context);
-$xml = $doc->saveXML();
-
 if ($save_in_session) {
-	if (isset($_SESSION["mb_wmc"])) {
-		$_SESSION["mb_wmc"] = $xml;
-	}
+	$_SESSION["mb_wmc"] = $wmc->xml;
+	$_SESSION["epsg"] = $mapObject->epsg;
+	$_SESSION["previous_gui"] = $_SESSION["mb_user_gui"];
+	$e = new mb_notice("mod_insertWMCIntoDB: save WMC in session succeeded.");
 }
 else {
-	if ($user_id && $wmc_id) {
+	if ($user_id && $wmc->wmc_id) {
 		$sql = "INSERT INTO mb_user_wmc VALUES ($1, $2, $3, $4, $5)";
-		$v = array($wmc_id, $user_id, $xml, $generalTitle, time());
+		$v = array($wmc->wmc_id, $user_id, $wmc->xml, $generalTitle, time());
 		$t = array("s", "i", "s", "s", "s");
 		
 		$res = db_prep_query($sql, $v, $t);
 		if (db_error()) {
-			 echo "Error while saving WMC document '" . $generalTitle . "': " . db_error();
+			echo "Error while saving WMC document '" . $generalTitle . "': " . db_error();
+			$e = new mb_exception("mod_insertWMCIntoDB: save WMC in DB failed.");
 		}
 		else {
 			 echo "WMC document '" . $generalTitle . "' has been saved.";
+			$e = new mb_notice("mod_insertWMCIntoDB: save WMC in DB succeeded.");
 		}
 	}
+	else {
+		$e = new mb_exception("mod_insertWMCIntoDB: missing parameters (user_id: ".$user_id.", wmc_id: ".$wmc->wmc_id."))");
+	}
 }
 ?>
\ No newline at end of file



More information about the Mapbender_commits mailing list