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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jul 18 10:54:52 EDT 2007


Author: christoph
Date: 2007-07-18 10:54:52 -0400 (Wed, 18 Jul 2007)
New Revision: 1507

Added:
   trunk/mapbender/http/php/mod_insertWmcIntoDb.php
Modified:
   trunk/mapbender/http/classes/class_wmc.php
Log:
saving a wmc via ajax

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2007-07-18 14:13:56 UTC (rev 1506)
+++ trunk/mapbender/http/classes/class_wmc.php	2007-07-18 14:54:52 UTC (rev 1507)
@@ -20,15 +20,8 @@
 require_once("../../conf/mapbender.conf");
 require_once("../classes/class_wms.php");
 require_once("../classes/class_mb_exception.php");
+require_once("../classes/class_administration.php");
 
-function mb_utf8_encode ($str) {
-	if(CHARSET=="UTF-8") return utf8_encode($str);
-	return $str;
-}
-function mb_utf8_decode ($str) {
-	if(CHARSET=="UTF-8") return utf8_decode($str);
-	return $str;
-}
 function sepNameSpace($s){
 	$c = strpos($s,":"); 
 	if($c>0)return substr($s,$c+1);
@@ -128,7 +121,6 @@
 	}
 
 	function createObjFromWMC_xml($data){
-		$data = str_replace("&", "&", $data);
 		$values = NULL;
 		$tags = NULL;
 		$parser = xml_parser_create(CHARSET);
@@ -187,20 +179,20 @@
 					$this->wmc_bBox_maxy = $element[attributes]["maxy"];
 				}
 				if(strtoupper($element[tag]) == "NAME"){
-					$this->wmc_name = mb_utf8_decode(html_entity_decode($element[value]));
+					$this->wmc_name = $element[value];
 				}
 				if(strtoupper($element[tag]) == "TITLE"){
-					$this->wmc_title = mb_utf8_decode(html_entity_decode($element[value]));
+					$this->wmc_title = $element[value];
 				}
 				if(strtoupper($element[tag]) == "ABSTRACT"){
-					$this->wmc_abstract = mb_utf8_decode(html_entity_decode($element[value]));
+					$this->wmc_abstract = $element[value];
 				}
 				if(strtoupper($element[tag]) == "CONTACTINFORMATION" && $element['type'] == "open"){
 					$contactinformation = true;
 				}
 				if ($contactinformation) {
 					if(strtoupper($element[tag]) == "CONTACTPOSITION"){
-						$this->wmc_contactposition = mb_utf8_decode(html_entity_decode($element[value]));
+						$this->wmc_contactposition = $element[value];
 					}
 					if(strtoupper($element[tag]) == "CONTACTVOICETELEPHONE"){
 						$this->wmc_contactvoicetelephone = $element[value];
@@ -209,17 +201,17 @@
 						$this->wmc_contactfacsimiletelephone = $element[value];
 					}
 					if(strtoupper($element[tag]) == "CONTACTELECTRONICMAILADDRESS"){
-						$this->wmc_contactemail = mb_utf8_decode(html_entity_decode($element[value]));
+						$this->wmc_contactemail = $element[value];
 					}
 					if(strtoupper($element[tag]) == "CONTACTPERSONPRIMARY" && $element['type'] == "open"){
 						$contactpersonprimary = true;
 					}
 					if ($contactpersonprimary) {
 						if(strtoupper($element[tag]) == "CONTACTPERSON"){
-							$this->wmc_contactperson = mb_utf8_decode(html_entity_decode($element[value]));
+							$this->wmc_contactperson = $element[value];
 						}
 						if(strtoupper($element[tag]) == "CONTACTORGANIZATION"){
-							$this->wmc_contactorganization = mb_utf8_decode(html_entity_decode($element[value]));
+							$this->wmc_contactorganization = $element[value];
 						}
 						if(strtoupper($element[tag]) == "CONTACTPERSONPRIMARY" && $element['type'] == "close"){
 							$contactpersonprimary = false;
@@ -230,22 +222,22 @@
 					}
 					if ($contactaddress) {
 						if(strtoupper($element[tag]) == "ADDRESSTYPE"){
-							$this->wmc_contactaddresstype = mb_utf8_decode(html_entity_decode($element[value]));
+							$this->wmc_contactaddresstype = $element[value];
 						}
 						if(strtoupper($element[tag]) == "ADDRESS"){
-							$this->wmc_contactaddress = mb_utf8_decode(html_entity_decode($element[value]));
+							$this->wmc_contactaddress = $element[value];
 						}
 						if(strtoupper($element[tag]) == "CITY"){
-							$this->wmc_contactcity = mb_utf8_decode(html_entity_decode($element[value]));
+							$this->wmc_contactcity = $element[value];
 						}
 						if(strtoupper($element[tag]) == "STATEORPROVINCE"){
-							$this->wmc_contactstateorprovince = mb_utf8_decode(html_entity_decode($element[value]));
+							$this->wmc_contactstateorprovince = $element[value];
 						}
 						if(strtoupper($element[tag]) == "POSTCODE"){
 							$this->wmc_contactpostcode = $element[value];
 						}
 						if(strtoupper($element[tag]) == "COUNTRY"){
-							$this->wmc_contactcountry = mb_utf8_decode(html_entity_decode($element[value]));
+							$this->wmc_contactcountry = $element[value];
 						}
 						if(strtoupper($element[tag]) == "CONTACTADDRESS" && $element['type'] == "close"){
 							$contactaddress = false;
@@ -290,7 +282,7 @@
 					}
 					if(strtoupper($element[tag]) == "KEYWORD"){
 						$cnt_keyword++;
-						$this->wmc_keyword[$cnt_keyword] = mb_utf8_decode(html_entity_decode($element[value]));
+						$this->wmc_keyword[$cnt_keyword] = $element[value];
 					}
 				}
 						
@@ -361,12 +353,12 @@
 								 	$this->wmc_layer_style_sld_url[$cnt_layer][$cnt_style] = $element[attributes]["xlink:href"];
 								 }
 								 if(strtoupper($element[tag]) == "TITLE"){
-								 	$this->wmc_layer_style_sld_title[$cnt_layer][$cnt_style] = mb_utf8_decode(html_entity_decode($element[value]));
+								 	$this->wmc_layer_style_sld_title[$cnt_layer][$cnt_style] = $element[value];
 								 }
 							 }
 							 else {
 								 if(strtoupper($element[tag]) == "NAME"){
-								 	$this->wmc_layer_style_name[$cnt_layer][$cnt_style] = mb_utf8_decode(html_entity_decode($element[value]));
+								 	$this->wmc_layer_style_name[$cnt_layer][$cnt_style] = $element[value];
 								 }
 								 if(strtoupper($element[tag]) == "TITLE"){
 								 	$this->wmc_layer_style_title[$cnt_layer][$cnt_style] = $element[value];
@@ -397,7 +389,7 @@
 						 	 $server = true;
 						 	 $this->wmc_wms_service[$cnt_layer] = $element[attributes]["service"];
 						 	 $this->wmc_wms_version[$cnt_layer] = $element[attributes]["version"];
-						 	 $this->wmc_wms_title[$cnt_layer] = mb_utf8_decode(html_entity_decode($element[attributes]["title"]));
+						 	 $this->wmc_wms_title[$cnt_layer] = $element[attributes]["title"];
 						 }
 						 if ($server) {
 							 if(strtoupper($element[tag]) == "SERVER" && $element[type] == "close"){
@@ -408,13 +400,13 @@
 							 }
 						 }
 						 if(strtoupper($element[tag]) == "NAME"){
-					 		 $this->wmc_layer_name[$cnt_layer] = mb_utf8_decode(html_entity_decode($element[value]));
+					 		 $this->wmc_layer_name[$cnt_layer] = $element[value];
 						 }
 						 if(strtoupper($element[tag]) == "TITLE"){
-					 		 $this->wmc_layer_title[$cnt_layer] = mb_utf8_decode(html_entity_decode($element[value]));
+					 		 $this->wmc_layer_title[$cnt_layer] = $element[value];
 						 }
 						 if(strtoupper($element[tag]) == "ABSTRACT"){
-					 		 $this->wmc_layer_abstract[$cnt_layer] = mb_utf8_decode(html_entity_decode($element[value]));
+					 		 $this->wmc_layer_abstract[$cnt_layer] = $element[value];
 						 }
 						 if(strtoupper($element[tag]) == "SRS"){
 							 $epsgArray = explode(" ", $element[value]);						 	
@@ -443,17 +435,17 @@
 						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "QUERYLAYER"){
 					 		 $this->wmc_layer_querylayer[$cnt_layer] = $element[value];
 						 }
-						 if(strtoupper($element[tag]) == "METADATAURL" && $element[type] == "open"){
+						 if(strtoupper(sepNameSpace($element[tag])) == "METADATAURL" && $element[type] == "open"){
 							 $metadataurl = true;
 						 }
-						 if(strtoupper($element[tag]) == "DATAURL" && $element[type] == "open"){
+						 if(strtoupper(sepNameSpace($element[tag])) == "DATAURL" && $element[type] == "open"){
 							 $dataurl = true;
 						 }
-						 if(strtoupper($element[tag]) == "FORMATLIST" && $element[type] == "open"){
+						 if(strtoupper(sepNameSpace($element[tag])) == "FORMATLIST" && $element[type] == "open"){
 							 $formatlist = true;
 							 $cnt_format = -1;
 						 }
-						 if(strtoupper($element[tag]) == "STYLELIST" && $element[type] == "open"){
+						 if(strtoupper(sepNameSpace($element[tag])) == "STYLELIST" && $element[type] == "open"){
 							 $stylelist = true;
 							 $cnt_style = -1;
 						 }

Copied: trunk/mapbender/http/php/mod_insertWmcIntoDb.php (from rev 1356, trunk/mapbender/http/javascripts/mod_insertWmcIntoDb.php)
===================================================================
--- trunk/mapbender/http/php/mod_insertWmcIntoDb.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_insertWmcIntoDb.php	2007-07-18 14:54:52 UTC (rev 1507)
@@ -0,0 +1,482 @@
+<?php
+#$Id: mod_insertWmcIntoDb.php 507 2006-11-20 10:55:57Z christoph $
+#$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_insertWmcIntoDb.php,v 1.19 2006/03/09 14:02:42 uli_rothstein Exp $
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+require_once(dirname(__FILE__)."/../classes/class_administration.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']);
+$user_id = $_SESSION['mb_user_id'];
+$save_in_session = $_POST['saveInSession'];
+$generalTitle = $_POST["generalTitle"];
+
+$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', $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");
+		
+					echo "ct:" . count($mapObject->wms[$i]->objLayer[$j]->layer_style);
+					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;
+	}
+}
+else {
+	if ($user_id && $wmc_id) {
+		$sql = "INSERT INTO mb_user_wmc VALUES ($1, $2, $3, $4, $5)";
+		$v = array($wmc_id, $user_id, $xml, $generalTitle, time());
+		$z = array("s", "i", "s", "s", "s");
+		
+		$res = db_prep_query($sql, $v, $t);
+		if (db_error()) {
+			 echo "Error while saving WMC document '" . $generalTitle . "'.";
+		}
+		else {
+			 echo "WMC document '" . $generalTitle . "' has been saved.";
+		}
+	}
+}
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list