[Mapbender-commits] r8258 - trunk/mapbender/http/plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Feb 17 08:37:29 EST 2012


Author: armin11
Date: 2012-02-17 05:37:29 -0800 (Fri, 17 Feb 2012)
New Revision: 8258

Added:
   trunk/mapbender/http/plugins/mb_geodata_edit.js
   trunk/mapbender/http/plugins/mb_geodata_edit.php
   trunk/mapbender/http/plugins/mb_geodata_import.js
   trunk/mapbender/http/plugins/mb_geodata_select.js
   trunk/mapbender/http/plugins/mb_geodata_server.php
Log:
First frame to allow uploading of geodata files (shapes) which are automatically served via wms and as download.

Added: trunk/mapbender/http/plugins/mb_geodata_edit.js
===================================================================
--- trunk/mapbender/http/plugins/mb_geodata_edit.js	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_geodata_edit.js	2012-02-17 13:37:29 UTC (rev 8258)
@@ -0,0 +1,167 @@
+/**
+ * Package: mb_geodata_edit
+ *
+ * Description:
+ *
+ * Files:
+ *
+ * SQL:
+ * 
+ * Help:
+ *
+ * Maintainer:
+ * http://www.mapbender.org/User:Armin_Retterath
+ *
+ * License:
+ * Copyright (c) 2009, Open Source Geospatial Foundation
+ * This program is dual licensed under the GNU General Public License
+ * and Simplified BSD license.
+ * http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+ */
+
+var $geodataEdit = $(this);
+var $geodataForm = $("<form>No dataset selected.</form>").appendTo($geodataEdit);
+
+var GeodataEditApi = function (o) {
+	var that = this;
+	var validator;
+	var formReady = false;
+	var metadataId;
+	
+	this.events = {
+		showOriginalGeodata : new Mapbender.Event(),
+		submit: new Mapbender.Event()
+	};
+
+	this.valid = function () {
+		if (validator && validator.numberOfInvalids() > 0) {
+			$geodataForm.valid();
+			return false;
+		}
+		return true;
+	};
+	
+	this.serialize = function (callback) {
+		$geodataForm.submit();
+		var data = null;
+		if (this.valid()) {
+			data = {
+				metadata: $geodataForm.easyform("serialize")
+			};
+		}
+		if ($.isFunction(callback)) {
+			callback(data);
+		}
+		return data !== null ? data.metadata : data;
+	};
+	
+	// second optional parameter formData
+	var fillForm = function (obj) {
+		if (arguments.length >= 2) {
+			$geodataForm.easyform("reset");
+			$geodataForm.easyform("fill", arguments[1]);
+			that.valid();
+			return;
+		}
+		
+		// get geodata from server
+		var req = new Mapbender.Ajax.Request({
+			url: "../plugins/mb_geodata_server.php",
+			method: "getGeodata",
+			parameters: {
+				"id": obj
+			},
+			callback: function (obj, result, message) {
+				if (!result) {
+					return;
+				}
+				$geodataForm.easyform("reset");
+				$geodataForm.easyform("fill", obj);
+				that.valid();
+			}
+		});
+		req.send();		
+	};
+
+	this.fillMdContact = function(obj) {
+		// get mdContact from server per fkey_mb_group_id
+		var req = new Mapbender.Ajax.Request({
+			url: "../plugins/mb_geodata_server.php",
+			method: "getContactGeodata",
+			parameters: {
+				"id": obj
+			},
+			callback: function (obj, result, message) {
+				if (!result) {
+					return;
+				}
+				//fill form on a not so easy way ;-)
+				for (var key in obj) {
+					if (key == 'mb_group_title' || key == 'mb_group_address' || key == 'mb_group_postcode' || key == 'mb_group_city' || key == 'mb_group_logo_path' || key == 'mb_group_email' || key == 'mb_group_voicetelephone'){
+						document.getElementById(key).value = obj[key];
+					}
+				}
+			}
+		});
+		req.send();
+	}	
+
+	this.fill = function (obj) {
+		$geodataForm.easyform("fill", obj);
+	};
+	
+	var showOriginalGeodata = function () {
+		that.events.showOriginalGeodata.trigger({
+			data : {
+				metadataId : metadataId,
+				metadataData : $geodataForm.easyform("serialize")
+			}
+		});
+	};
+	
+	this.init = function (obj) {
+	
+		metadataId = obj;
+		
+		if (!metadataId) {
+			return;
+		}
+				
+		var formData = arguments.length >= 2 ? arguments[1] : undefined;
+		
+		if (!formReady) {
+			$geodataForm.load("../plugins/mb_geodata_edit.php", function () {
+				$geodataForm.find(".help-dialog").helpDialog();
+				$geodataForm.find(".original-geodata-metadata").bind("click", 					function() {
+					showOriginalGeodata();
+				});				
+				validator = $geodataForm.validate({
+					submitHandler: function () {
+						return false;
+					}
+				});
+				if (formData !== undefined) {
+					fillForm(obj, formData);
+				}
+				else {
+					fillForm(obj);
+				}
+				formReady = true;
+			});
+			return;
+		}
+		fillForm(obj);
+	};
+	
+	Mapbender.events.localize.register(function () {
+		that.valid();
+		var formData = $geodataForm.easyform("serialize");
+		formReady = false;
+		that.init(metadataId, formData);
+	});
+	Mapbender.events.init.register(function () {
+		that.valid();
+	});
+};
+
+$geodataEdit.mapbender(new GeodataEditApi(options));

Added: trunk/mapbender/http/plugins/mb_geodata_edit.php
===================================================================
--- trunk/mapbender/http/plugins/mb_geodata_edit.php	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_geodata_edit.php	2012-02-17 13:37:29 UTC (rev 8258)
@@ -0,0 +1,186 @@
+<?php
+	require_once dirname(__FILE__) . "/../../core/globalSettings.php";
+	require_once dirname(__FILE__) . "/../classes/class_user.php";
+?>
+
+<fieldset>
+	<input name="geodata_id" id="geodata_id" type="hidden"/>
+
+	<legend><?php echo _mb("Service Level Metadata");?>: <img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("Possibility to adapt and add informations in the separate WMS-Layer Metadata. The modified Metadata is stored in the database of the GeoPortal.rlp, outwardly these metadata overwrite the original Service-Metadata.");?>'}" src="../img/questionmark.png" alt="" /></legend>
+	<!--<p>
+		<label for="geodata_title"><?php echo _mb("Show original Service Metadata from last update");?></label>
+		<img class="original-metadata-wms" src="../img/book.png" alt="" />
+		<img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("The original WMS-Metadata from the last update could be recovered or updated, so that the original Service-Metadata will be shown outward again.");?>'}" src="../img/questionmark.png" alt="" />
+	</p>-->
+	<p>
+		<label for="geodata_title"><?php echo _mb("Title of dataset");?>:</label>
+		<input name="geodata_title" id="geodata_title" class="required"/>
+		<img class="metadata_img" title="<?php echo _mb("INSPIRE 1.1: resource title");?>" src="../img/misc/inspire_eu_klein.png" alt="" />
+	</p>
+	<p>
+    	<label for="geodata_abstract"><?php echo _mb("Abstract of dataset");?>:</label>
+    	<input name="geodata_abstract" id="geodata_abstract"/>
+    	<img class="metadata_img" title="<?php echo _mb("INSPIRE 1.2: resource abstract");?>" src="../img/misc/inspire_eu_klein.png" alt="" />
+	<img class="help-dialog" title="<?php echo _mb("Help for INSPIRE Abstract");?>" help="{text:'<?php echo _mb("INSPIRE demands some information about the spatial resolution in the abstract tag of the capabilities document. Please insert some words about it.");?>'}" src="../img/questionmark.png" alt="" />
+	</p>
+<!--	<p>
+		<label for="wms_keywords"><?php echo _mb("WMS Keywords (OWS)");?>:</label>
+    	<input readonly="readonly" name="wms_keywords" id="wms_keywords"/>
+    	<img class="metadata_img" title="<?php echo _mb("INSPIRE 3: keyword");?>" src="../img/misc/inspire_eu_klein.png" alt="" />
+	</p>
+	<p>
+		<label for="fees"><?php echo _mb("WMS Fees (OWS)");?>:</label>
+    	<input name="fees" id="fees"/>
+    	<img class="metadata_img" title="<?php echo _mb("INSPIRE 8.1: conditions applying to access and use");?>" src="../img/misc/inspire_eu_klein.png" alt="" />
+	</p>
+	<p>
+		<label for="accessconstraints"><?php echo _mb("WMS AccessConstraints (OWS)");?>:</label>
+		<input name="accessconstraints" id="accessconstraints"/>
+    	<img class="metadata_img" title="<?php echo _mb("INSPIRE 8.2: limitations on public access");?>" src="../img/misc/inspire_eu_klein.png" alt="" />
+	</p>
+<?php
+	$sql = "SELECT termsofuse_id, name FROM termsofuse";
+	$res = db_query($sql);
+	$termsofuse = array();
+	while ($row = db_fetch_assoc($res)) {
+		$termsofuse[$row["termsofuse_id"]] = $row["name"];
+	}
+?>
+	<p>
+		<label for="wms_termsofuse"><?php echo _mb("WMS Predefined Licence (Registry)");?>:</label>
+    	<select name="wms_termsofuse" id="wms_termsofuse">
+			<option>...</option>
+<?php
+	foreach ($termsofuse as $key => $value) {
+		echo "<option value='" . $key . "'>" . htmlentities($value, ENT_QUOTES, CHARSET) . "</option>";
+	}
+?>
+		</select>
+    	<img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("Auswahl von vordefinierten Lizenzen hinsichtlich Gebühren und Zugriffsbeschränkungen.");?>'}" src="../img/questionmark.png" alt="" />
+	</p>
+	<p>
+		<label for="wms_network_access"><?php echo _mb("Restricted Network Access (Registry)");?>:</label>
+      		<input name="wms_network_access" id="wms_network_access" type="checkbox"/>
+	</p>
+</fieldset>
+<fieldset>
+	<legend><?php echo _mb("WMS Provider Section (OWS)");?></legend>
+	<p>
+		<label for="contactperson"><?php echo _mb("Contact Individual Name (OWS)");?>:</label>
+    	<input name="contactperson" id="contactperson"/>
+	</p>
+	<p>
+		<label for="contactposition"><?php echo _mb("Contact Position Name (OWS)");?>:</label>
+    	<input name="contactposition" id="contactposition"/>
+	</p>
+	<p>
+		<label for="contactvoicetelephone"><?php echo _mb("Contact Phone Voice (OWS)");?>:</label>
+    	<input name="contactvoicetelephone" id="contactvoicetelephone"/>
+	</p>
+	<p>
+		<label for="contactfacsimiletelephone"><?php echo _mb("Contact Phone Fax (OWS)");?>:</label>
+    	<input name="contactfacsimiletelephone" id="contactfacsimiletelephone"/>
+	</p>
+	<p>
+		<label for="contactorganization"><?php echo _mb("Contact Organisation (WMS)");?>:</label>
+    	<input name="contactorganization" id="contactorganization"/>
+    	<img  class="metadata_img" title="<?php echo _mb("INSPIRE 9.1: responsible party name");?>" src="../img/misc/inspire_eu_klein.png" alt="" />
+	</p>
+	<p>
+		<label for="address"><?php echo _mb("Contact Address (WMS)");?>:</label>
+    	<input name="address" id="address"/>
+	</p>
+	<p>
+		<label for="city"><?php echo _mb("Contact City (WMS)");?>:</label>
+     	<input name="city" id="city"/>
+	</p>
+	<p>
+	  	<label for="stateorprovince"><?php echo _mb("Contact State or Province (WMS) - ISO 3166-II");?>:</label>
+      	<input name="stateorprovince" id="stateorprovince"/>
+	</p>
+	<p>
+	  	<label for="postcode"><?php echo _mb("Contact Post Code (WMS)");?>:</label>
+      	<input name="postcode" id="postcode"/>
+	</p>
+	<p>
+	  	<label for="country"><?php echo _mb("Contact Post Country (WMS) - ISO 3166");?>:</label>
+      	<input name="country" id="country"/>
+	</p>
+	<p>
+	  	<label for="contactelectronicmailaddress"><?php echo _mb("Contact Electronic Mail Address (WMS)");?>:</label>
+      	<input name="contactelectronicmailaddress" id="contactelectronicmailaddress" class="required email"/>
+     	<img class="metadata_img" title="<?php echo _mb("INSPIRE 9.1: responsible party email");?>" src="../img/misc/inspire_eu_klein.png" alt="" />
+	</p>
+	<p>
+	  	<label for="wms_timestamp_create"><?php echo _mb("Date of first registration (Registry)");?>:</label>
+      	<input readonly="readonly" name="wms_timestamp_create" id="wms_timestamp_create"/>
+      	<img class="metadata_img" title="<?php echo _mb("INSPIRE 5.2: date of publication");?>" src="../img/misc/inspire_eu_klein.png" alt="" />
+	</p>
+	<p>
+	  	<label for="wms_timestamp"><?php echo _mb("Date of last revision (Registry)");?>:</label>
+      	<td><input readonly="readonly" name="wms_timestamp" id="wms_timestamp"/>
+      	<img class="metadata_img" title="<?php echo _mb("INSPIRE 10.2: metadata date");?>" src="../img/misc/inspire_eu_klein.png" alt="" />
+	</p>
+</fieldset>
+<fieldset>
+	<legend><?php echo _mb("Metadata Point of contact (registry)");?>: <img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("Information about the organization which is responsible for contributing the metadata. The information will be automaticcaly generated from the mapbender database mb_group object. The information came from the primary group of the service owner or from a group which has authorized the owner to publish metadata in their name.");?>'}" src="../img/questionmark.png" alt="" /></legend>
+
+<?php
+//selectbox for organizationswhich allows the publishing of metadatasets for the specific user
+	$sql = "SELECT fkey_mb_group_id, mb_group_name FROM (SELECT fkey_mb_group_id FROM mb_user_mb_group WHERE fkey_mb_user_id = $1 AND (mb_user_mb_group_type = 3 OR mb_user_mb_group_type = 2)) AS a LEFT JOIN mb_group ON a.fkey_mb_group_id = mb_group.mb_group_id";
+	$user = new User();
+	$userId = $user->id;
+	$v = array($userId);
+	$t = array('i');
+	$res = db_prep_query($sql,$v,$t);
+	$metadataGroup = array();
+	while ($row = db_fetch_assoc($res)) {
+		$metadataGroup[$row["fkey_mb_group_id"]] = $row["mb_group_name"];
+	}
+?>
+	<p>
+		<label for="mb_group_name"><?php echo _mb("Organization responsible for metadata");?>:</label>
+    	<select name="fkey_mb_group_id" id="fkey_mb_group_id" onChange="var chosenoption=this.options[this.selectedIndex];$('#mb_md_edit').mapbender().fillMdContact(chosenoption.value);">
+			<option value="0">...</option>
+<?php
+	foreach ($metadataGroup as $key => $value) {
+		echo "<option value='" . $key . "'>" . htmlentities($value, ENT_QUOTES, CHARSET) . "</option>";
+	}
+?>
+		</select>
+    	<img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("Selection of different organizations which authorized you to publish metadata in their name.");?>'}" src="../img/questionmark.png" alt="" />
+	</p> -->
+<!--
+
+	<p>
+		<label for="mb_group_title"><?php echo _mb("Title");?>:</label>
+		<input readonly="readonly" name="mb_group_title" id="mb_group_title"/>
+		<img class="metadata_img" title="<?php echo _mb("INSPIRE 10.1: metadata point of contact name");?>" src="../img/misc/inspire_eu_klein.png" alt="" />
+	</p>
+	<p>
+		<label for="mb_group_address"><?php echo _mb("Address");?>:</label>
+		<input readonly="readonly" name="mb_group_address" id="mb_group_address"/>
+	</p>
+	<p>
+		<label for="mb_group_postcode"><?php echo _mb("Postcode");?>:</label>
+		<input readonly="readonly" name="mb_group_postcode" id="mb_group_postcode"/>
+	</p>
+	<p>
+		<label for="mb_group_city"><?php echo _mb("City");?>:</label>
+		<input readonly="readonly" name="mb_group_city" id="mb_group_city"/>
+	</p>
+	<p>
+		<label for="mb_group_voicetelephone"><?php echo _mb("Telephone");?>:</label>
+		<input readonly="readonly" name="mb_group_voicetelephone" id="mb_group_voicetelephone"/>
+	</p>
+	<p>
+		<label for="mb_group_email"><?php echo _mb("Email");?>:</label>
+		<input readonly="readonly" name="mb_group_email" id="mb_group_email"/>
+		<img class="metadata_img" title="<?php echo _mb("INSPIRE 10.1: metadata point of contact email");?>" src="../img/misc/inspire_eu_klein.png" alt="" />
+	</p>
+	<p>
+		<label for="mb_group_logo_path"><?php echo _mb("Logo url");?>:</label>
+		<input readonly="readonly" name="mb_group_logo_path" id="mb_group_logo_path"/>
+	</p>
+-->
+</fieldset>

Added: trunk/mapbender/http/plugins/mb_geodata_import.js
===================================================================
--- trunk/mapbender/http/plugins/mb_geodata_import.js	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_geodata_import.js	2012-02-17 13:37:29 UTC (rev 8258)
@@ -0,0 +1,84 @@
+var $geodataImport = $(this);
+var importGeodataId;
+
+var GeodataImportApi = function () {
+	var that = this;
+	var type;
+	
+	this.events = {
+		"uploadComplete" : new Mapbender.Event()
+	};
+	
+	this.events.uploadComplete.register(function () {
+		$geodataImport.dialog("close");
+	});
+	
+	var importUploadedFile = function(filename, Id, callback){
+		var req = new Mapbender.Ajax.Request({
+			url: "../plugins/mb_geodata_server.php",
+			method: "store",
+			parameters: {
+				filename: filename,
+				layerId: Id
+			},
+			callback: function (obj, result, message, errorCode) {				
+				if (!result) {
+					switch (errorCode) {
+						case -1002:
+							alert("file: "+filename+"has problems: "+message);
+							break;
+						default:
+							alert(message);
+							return;
+					}
+				}
+				alert(message);
+				$geodataImport.dialog("close");
+				if ($.isFunction(callback)) {
+					callback(obj.id);
+				}
+			}
+		});
+		req.send();
+	};
+
+	$geodataImport.upload({
+		size: 10,
+		timeout: 20000,
+		url: "../plugins/jq_upload.php",
+		callback: function(result,stat,msg){
+			if(!result){ 
+				alert(msg);
+				return;
+			}
+	        	var uploadResultName = result.filename;
+	        	var uploadResultOrigName = result.origFilename;
+	        
+	        	importUploadedFile(result.filename, that.importGeodataId, function (id) {
+		        	that.events.uploadComplete.trigger({
+						"type": type,
+						"id": id
+				});
+			}); 
+    		}
+		}).dialog({
+			title: 'Geodata Import',
+			autoOpen: false,
+			modal: true,
+			width: 580
+		});
+
+	this.init = function (obj) {
+		type = obj.type;
+		$geodataImport.dialog("open");
+		alert('test');
+	};
+
+	initGeodataImport = function (Id) {
+		that.importGeodataId = Id;
+		$geodataImport.dialog("open");
+		return true;
+	};	
+};
+
+$geodataImport.mapbender(new GeodataImportApi());

Added: trunk/mapbender/http/plugins/mb_geodata_select.js
===================================================================
--- trunk/mapbender/http/plugins/mb_geodata_select.js	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_geodata_select.js	2012-02-17 13:37:29 UTC (rev 8258)
@@ -0,0 +1,103 @@
+/**
+ * Package: mb_geodata_select
+ *
+ * Description:
+ *
+ * Files:
+ *
+ * SQL:
+ * 
+ * Help:
+ *
+ * Maintainer:
+ * http://www.mapbender.org/User:Armin_Retterath
+ *
+ * License:
+ * Copyright (c) 2009, Open Source Geospatial Foundation
+ * This program is dual licensed under the GNU General Public License
+ * and Simplified BSD license.
+ * http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+ */
+
+var $geodataSelect = $(this);
+$geodataSelect.prepend("<img src='../img/indicator_wheel.gif'>");
+
+var GeodataSelectApi = function (o) {
+	var table = null;
+	var that = this;
+
+	var fnGetSelected = function (oTableLocal){
+		var aReturn = [];
+		var aTrs = oTableLocal.fnGetNodes();
+		
+		for ( var i=0 ; i<aTrs.length ; i++ ){
+			if ( $(aTrs[i]).hasClass('row_selected') ){
+				aReturn.push( aTrs[i] );
+			}
+		}
+		return aReturn;
+	};
+	
+	this.getData = function () {
+		var req = new Mapbender.Ajax.Request({
+			url: "../plugins/mb_geodata_server.php",
+			method: "getGeodata",
+			parameters: {
+			},
+			callback: function (obj, result, message) {
+				if (!result) {
+					return;
+				}
+				$geodataSelect.find("img").remove();
+				
+				var aoColumns = [];
+				for (var i in obj.header) {
+					if (obj.header[i] === "Geodata ID") {
+						continue;
+					}
+					aoColumns.push({"sTitle": obj.header[i]});
+				}
+
+				// initialize datatables
+				table = $geodataSelect.find("table").dataTable({
+					"aoColumns": aoColumns,
+					"bJQueryUI": true
+				});
+				
+				// add rows
+				for (var j in obj.data) {
+					var data = obj.data[j];
+					var wmsId = data[0];
+					data.shift();
+					var index = table.fnAddData(data);
+					var rowNode = table.fnGetNodes(index[0]);
+					$(rowNode).data("wmsId", wmsId);
+				}
+				
+				// make rows selectable
+				$geodataSelect.find("tbody").click(function (e) {
+					$(table.fnSettings().aoData).each(function (){
+						$(this.nTr).removeClass('row_selected');
+					});
+					$(e.target.parentNode).addClass('row_selected');
+					var selectedRow = fnGetSelected(table);
+					$geodataSelect.fadeOut(function () {
+						that.events.selected.trigger({
+							wmsId: $(selectedRow).data("wmsId")
+						});
+						$geodataSelect.show();
+					});
+				});
+			}
+		});
+		req.send();
+	};
+	
+	this.events = {
+		selected: new Mapbender.Event()
+	};
+};
+
+$geodataSelect.mapbender(new GeodataSelectApi(options));
+
+$geodataSelect.mapbender("getData");

Added: trunk/mapbender/http/plugins/mb_geodata_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_geodata_server.php	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_geodata_server.php	2012-02-17 13:37:29 UTC (rev 8258)
@@ -0,0 +1,1172 @@
+<?php
+require_once dirname(__FILE__) . "/../../core/globalSettings.php";
+require_once dirname(__FILE__) . "/../classes/class_user.php";
+require_once dirname(__FILE__) . "/../classes/class_wms.php";
+require_once dirname(__FILE__) . "/../classes/class_Uuid.php";
+
+$ajaxResponse = new AjaxResponse($_POST);
+
+function abort ($message) {
+	global $ajaxResponse;
+	$ajaxResponse->setSuccess(false);
+	$ajaxResponse->setMessage($message);
+	$ajaxResponse->send();
+	die();
+};
+
+function getGeodata ($geodataId = null) {
+	$user = new User(Mapbender::session()->get("mb_user_id"));
+	$e = new mb_exception("plugins/mb_geodata_server.php: mb_user_id: ".$user);
+	$geodataIdArray = $user->getOwnedGeodata();
+
+	if (!is_null($geodataId) && !in_array($geodataId, $geodataIdArray)) {
+		abort(_mb("You are not allowed to access this dataset."));
+	}
+	return $geodataIdArray;
+}
+
+function getLayer ($layerId = null) {
+	$user = new User(Mapbender::session()->get("mb_user_id"));
+	$wmsIdArray = $user->getOwnedWms();
+	if (!is_array($wmsIdArray) || count($wmsIdArray) === 0) {
+		abort(_mb("No metadata sets available."));
+	}
+	$wmsId = wms::getWmsIdByLayerId($layerId);
+	if (is_null($wmsId) || !in_array($wmsId, $wmsIdArray)) {
+		abort(_mb("You are not allowed to access WMS " . $wmsId));
+	}
+	return;
+}
+
+switch ($ajaxResponse->getMethod()) {
+	case "getGeodata" :
+		$geodataIdArray = getGeodata();
+		
+		$geodataList = implode(",", $geodataIdArray);
+		$sql = <<<SQL
+	
+SELECT metadata_id, title, lastchanged, changedate, origin, datasetid, uuid FROM
+mb_metadata WHERE metadata_id IN ($geodataList);
+
+SQL;
+		$res = db_query($sql);
+		$resultObj = array(
+			"header" => array(
+				_mb("Geodata ID"),
+				_mb("title"),
+				_mb("last change"),
+				_mb("change"),
+				_mb("origin"),
+				_mb("datasetid"),
+				_mb("uuid")
+			), 
+			"data" => array()
+		);
+
+		while ($row = db_fetch_row($res)) {
+			// convert NULL to '', NULL values cause datatables to crash
+			$walk = array_walk($row, create_function('&$s', '$s=strval($s);'));
+			$resultObj["data"][]= $row;
+		}
+		$ajaxResponse->setResult($resultObj);
+		$ajaxResponse->setSuccess(true);
+		break;
+
+	case "getWmsMetadata" :
+		$wmsId = $ajaxResponse->getParameter("id");
+		getWms($wmsId);
+
+		$wms = new wms();
+		$wms->createObjFromDBNoGui($wmsId);//here the owsproxyurls will be read out - to make previews with proxy urls
+
+		$fields = array(
+			"wms_id", 
+			"wms_abstract", 
+			"wms_title", 
+			"fees", 
+			"accessconstraints", 
+			"contactperson", 
+			"contactposition", 
+			"contactvoicetelephone", 
+			"contactfacsimiletelephone", 
+			"contactorganization", 
+			"address", 
+			"city", 
+			"stateorprovince", 
+			"postcode", 
+			"country", 
+			"contactelectronicmailaddress",
+			"wms_timestamp", 
+			"wms_timestamp_create",
+			"wms_network_access",
+			"fkey_mb_group_id"
+		);
+
+		$resultObj = array();
+		foreach ($fields as $field) {
+			if ($field == "wms_timestamp" || $field == "wms_timestamp_create") {
+				if ($wms->$field != "") {
+	
+					$resultObj[$field] = date('d.m.Y', $wms->$field);
+					
+				}
+			}
+			else {
+				$resultObj[$field] = $wms->$field;
+				//$e = new mb_exception("mb_metadata_server: resultObject[".$field."]=".$wms->$field);	
+			}
+		}
+		
+		// layer searchable
+		$resultObj["layer_searchable"] = array();
+		foreach ($wms->objLayer as $layer) {
+			if (intval($layer->layer_searchable) === 1) {
+				$resultObj["layer_searchable"][] = intval($layer->layer_uid);
+			}
+		}
+		
+		$keywordSql = <<<SQL
+	
+SELECT DISTINCT keyword FROM keyword, layer_keyword 
+WHERE keyword_id = fkey_keyword_id AND fkey_layer_id IN (
+	SELECT layer_id from layer, wms 
+	WHERE fkey_wms_id = wms_id AND wms_id = $wmsId
+) ORDER BY keyword
+
+SQL;
+
+		$keywordRes = db_query($keywordSql);
+		$keywords = array();
+		while ($keywordRow = db_fetch_assoc($keywordRes)) {
+			$keywords[]= $keywordRow["keyword"];
+		}
+
+		$resultObj["wms_keywords"] = implode(", ", $keywords);
+
+		$termsofuseSql = <<<SQL
+SELECT fkey_termsofuse_id FROM wms_termsofuse WHERE fkey_wms_id = $wmsId
+SQL;
+
+		$termsofuseRes = db_query($termsofuseSql);
+		if ($termsofuseRes) {
+			$termsofuseRow = db_fetch_assoc($termsofuseRes);
+			$resultObj["wms_termsofuse"] = $termsofuseRow["fkey_termsofuse_id"];
+		}
+		else {
+			$resultObj["wms_termsofuse"] = null;
+		}
+		
+		$resultObj['wms_network_access'] = $resultObj['wms_network_access'] == 1 ? true : false;
+		
+		//get contact information from group relation
+		//check if fkey_mb_group_id has been defined before - in service table
+		if ($resultObj["fkey_mb_group_id"] == "" || !isset($resultObj["fkey_mb_group_id"])){
+			$e = new mb_notice("fkey_mb_group_id is null or empty");
+			//check if primary group is set 
+			$user = new User;
+			$userId = $user->id;
+			//$e = new mb_exception("user id:".$userId);
+			$sql = <<<SQL
+	
+SELECT fkey_mb_group_id, mb_group_name, mb_group_title, mb_group_address, mb_group_email, mb_group_postcode, mb_group_city, mb_group_logo_path, mb_group_voicetelephone FROM (SELECT fkey_mb_group_id FROM mb_user_mb_group WHERE fkey_mb_user_id = $1 AND mb_user_mb_group_type = 2) AS a LEFT JOIN mb_group ON a.fkey_mb_group_id = mb_group.mb_group_id
+
+SQL;
+			$v = array($userId);
+			$t = array('i');
+			$res = db_prep_query($sql,$v,$t);
+			$row = array();
+			if ($res) {
+				$row = db_fetch_assoc($res);
+				$resultObj["fkey_mb_group_id"] = $row["fkey_mb_group_id"];
+				$resultObj["mb_group_title"] = $row["mb_group_title"];
+				$resultObj["mb_group_address"] = $row["mb_group_address"];
+				$resultObj["mb_group_email"] = $row["mb_group_email"];
+				$resultObj["mb_group_postcode"] = $row["mb_group_postcode"];
+				$resultObj["mb_group_city"] = $row["mb_group_city"];
+				$resultObj["mb_group_logo_path"] = $row["mb_group_logo_path"];
+				$resultObj["mb_group_voicetelephone"] = $row["mb_group_voicetelephone"];
+			}
+		} else {
+			//get current fkey_mb_group_id and the corresponding data
+			$sql = <<<SQL
+	
+SELECT mb_group_name, mb_group_title, mb_group_address, mb_group_email, mb_group_postcode, mb_group_city, mb_group_logo_path, mb_group_voicetelephone FROM mb_group WHERE mb_group_id = $1
+
+SQL;
+			$v = array($resultObj["fkey_mb_group_id"]);
+			$t = array('i');
+			$res = db_prep_query($sql,$v,$t);
+			$row = array();
+			if ($res) {
+				$row = db_fetch_assoc($res);
+				$resultObj["mb_group_title"] = $row["mb_group_title"];
+				$resultObj["mb_group_address"] = $row["mb_group_address"];
+				$resultObj["mb_group_email"] = $row["mb_group_email"];
+				$resultObj["mb_group_postcode"] = $row["mb_group_postcode"];
+				$resultObj["mb_group_city"] = $row["mb_group_city"];
+				$resultObj["mb_group_logo_path"] = $row["mb_group_logo_path"];
+				$resultObj["mb_group_voicetelephone"] = $row["mb_group_voicetelephone"];
+			}
+			else {
+				$resultObj["fkey_mb_group_id"] = null;
+			}
+		}
+		$ajaxResponse->setResult($resultObj);
+		$ajaxResponse->setSuccess(true);
+
+		break;
+	
+	case "getLayerMetadata" :
+		$layerId = $ajaxResponse->getParameter("id");
+		getLayer($layerId);
+
+		$sql = <<<SQL
+	
+SELECT layer_id, layer_name, layer_title, layer_abstract, layer_searchable, fkey_wms_id as wms_id  
+FROM layer WHERE layer_id = $layerId;
+
+SQL;
+		$res = db_query($sql);
+
+		$resultObj = array();
+		while ($row = db_fetch_assoc($res)) {
+			foreach ($row as $key => $value) {
+				$resultObj[$key] = $value;
+				$e = new mb_notice("plugins/mb_metadata_server.php: get ".$value." for ".$key);
+			}
+		}
+
+		$sql = <<<SQL
+SELECT fkey_md_topic_category_id 
+FROM layer_md_topic_category 
+WHERE fkey_layer_id = $layerId
+SQL;
+		$res = db_query($sql);
+		while ($row = db_fetch_assoc($res)) {
+			$resultObj["layer_md_topic_category_id"][]= $row["fkey_md_topic_category_id"];
+		}
+
+		$sql = <<<SQL
+SELECT fkey_inspire_category_id 
+FROM layer_inspire_category 
+WHERE fkey_layer_id = $layerId
+SQL;
+		$res = db_query($sql);
+		while ($row = db_fetch_assoc($res)) {
+			$resultObj["layer_inspire_category_id"][]= $row["fkey_inspire_category_id"];
+		}
+
+		$sql = <<<SQL
+SELECT fkey_custom_category_id 
+FROM layer_custom_category 
+WHERE fkey_layer_id = $layerId
+SQL;
+		$res = db_query($sql);
+		while ($row = db_fetch_assoc($res)) {
+			$resultObj["layer_custom_category_id"][]= $row["fkey_custom_category_id"];
+		}
+
+		$sql = <<<SQL
+SELECT keyword FROM keyword, layer_keyword 
+WHERE keyword_id = fkey_keyword_id AND fkey_layer_id = $layerId
+SQL;
+		$res = db_query($sql);
+
+		$resultObj["layer_keyword"] = array();
+		while ($row = db_fetch_assoc($res)) {
+			$resultObj["layer_keyword"][]= $row["keyword"];
+		}
+		//get MetadataURLs from md_metadata table
+		$sql = <<<SQL
+SELECT metadata_id, uuid, link, linktype, md_format, origin FROM mb_metadata 
+INNER JOIN (SELECT * from ows_relation_metadata 
+WHERE fkey_layer_id = $layerId ) as relation ON 
+mb_metadata.metadata_id = relation.fkey_metadata_id WHERE mb_metadata.origin IN ('capabilities','external','metador','upload')
+SQL;
+		$res = db_query($sql);
+		$resultObj["md_metadata"]->metadata_id = array();
+		$resultObj["md_metadata"]->uuid = array();
+		$resultObj["md_metadata"]->origin = array();
+		$resultObj["md_metadata"]->linktype = array();
+		$resultObj["md_metadata"]->link = array();
+		$i = 0;
+		while ($row = db_fetch_assoc($res)) {
+			$resultObj["md_metadata"]->metadata_id[$i]= $row["metadata_id"];
+			$resultObj["md_metadata"]->link[$i]= $row["link"];
+			$resultObj["md_metadata"]->uuid[$i]= $row["uuid"];
+			$resultObj["md_metadata"]->origin[$i]= $row["origin"];
+			$resultObj["md_metadata"]->linktype[$i]= $row["linktype"];
+			$i++;
+		}
+		$ajaxResponse->setResult($resultObj);
+		$ajaxResponse->setSuccess(true);
+		break;
+	case "getLayerByWms" :
+		$wmsId = $ajaxResponse->getParameter("id");
+//		getWms($wmsId);
+
+		$sql = <<<SQL
+	
+SELECT layer_id, f_count_layer_couplings(layer_id) as count_coupling, f_collect_inspire_cat_layer(layer_id) AS inspire_cats, layer_pos, layer_parent, layer_name, layer_title, layer_abstract, layer_searchable 
+FROM layer WHERE fkey_wms_id = $wmsId ORDER BY layer_pos;
+
+SQL;
+
+
+
+		$res = db_query($sql);
+
+		$rows = array();
+		while ($row = db_fetch_assoc($res)) {
+			$rows[] = $row;
+		}
+		$left = 1;
+
+		function createNode ($left, $right, $row) {
+			$inspireCatsArray = explode(",",str_replace("}","",str_replace("{","",$row["inspire_cats"])));
+			if (count($inspireCatsArray) >= 0) {
+				$inspireCats = 1;
+			} else {
+				$inspireCats = 0;
+				}
+			return array(
+				"left" => $left,
+				"right" => $right,
+				"parent" => $row["layer_parent"] !== "" ? intval($row["layer_parent"]) : null,
+				"pos" => intval($row["layer_pos"]),
+				"attr" => array (
+					"layer_id" => intval($row["layer_id"]),
+					"layer_name" => $row["layer_name"],
+					"layer_title" => $row["layer_title"],
+					"layer_abstract" => $row["layer_abstract"],
+					"layer_searchable" => intval($row["layer_searchable"]),
+					"layer_coupling" => intval($row["count_coupling"]),
+					"inspire_cats" => intval($inspireCats)
+				)
+			);
+		}
+
+		function addSubTree ($rows, $i, $left) {
+			$nodeArray = array();
+			$addNewNode = true;
+			for ($j = $i; $j < count($rows); $j++) {
+				$row = $rows[$j];
+				$pos = intval($row["layer_pos"]);
+				$parent = $row["layer_parent"] !== "" ? intval($row["layer_parent"]) : null;
+				
+				// first node of subtree
+				if ($addNewNode) {
+					$nodeArray[]= createNode($left, null, $row);
+					$addNewNode = false;
+				}
+				else {
+					// new sub tree
+					if ($parent === $nodeArray[count($nodeArray)-1]["pos"]) {
+						$addedNodeArray = addSubTree($rows, $j, ++$left);
+						
+						$nodeArray[count($nodeArray)-1]["right"] = 
+							$nodeArray[count($nodeArray)-1]["left"] + 
+							2 * count($addedNodeArray) + 1;
+						
+						$left = $nodeArray[count($nodeArray)-1]["right"] + 1;
+
+						$nodeArray = array_merge($nodeArray, $addedNodeArray);
+						$j += count($addedNodeArray) - 1;
+						$addNewNode = true;
+						
+					}
+					// siblings
+					elseif ($parent === $nodeArray[count($nodeArray)-1]["parent"]) {
+						$nodeArray[count($nodeArray)-1]["right"] = ++$left;
+						$nodeArray[]= createNode(++$left, null, $row);
+					}
+				}
+			}
+			if (is_null($nodeArray[count($nodeArray)-1]["right"])) {
+				$nodeArray[count($nodeArray)-1]["right"] = ++$left;
+			}
+			return $nodeArray;
+		}
+		
+
+		$nodeArray = addSubTree($rows, 0, 1);
+		$resultObj = array(
+			"nestedSets" => $nodeArray
+		);
+		
+		$ajaxResponse->setResult($resultObj);
+		$ajaxResponse->setSuccess(true);
+		
+
+		break;
+	case "save":
+		$data = $ajaxResponse->getParameter("data");
+		
+		try {
+			$wmsId = intval($data->wms->wms_id);
+		}
+		catch (Exception $e) {
+			$ajaxResponse->setSuccess(false);
+			$ajaxResponse->setMessage(_mb("Invalid WMS ID."));
+			$ajaxResponse->send();						
+		}
+		getWms($wmsId);
+		
+		$wms = new wms();
+		$wms->createObjFromDBNoGui($wmsId,false);//here the original urls will be used - cause the object will used to update the wms table
+		
+		$columns = array(
+			"wms_abstract", 
+			"wms_title", 
+			"fees", 
+			"accessconstraints", 
+			"contactperson", 
+			"contactposition", 
+			"contactvoicetelephone", 
+			"contactfacsimiletelephone", 
+			"contactorganization", 
+			"address", 
+			"city", 
+			"stateorprovince", 
+			"postcode", 
+			"country", 
+			"contactelectronicmailaddress",
+			"wms_termsofuse",
+			"wms_network_access",
+			"fkey_mb_group_id"
+		);
+		foreach ($columns as $c) {
+			$value = $data->wms->$c;
+			if (!is_null($value)) {
+				$wms->$c = $value;
+			}
+		}
+
+		if (is_array($data->wms->layer_searchable)) {
+			foreach ($wms->objLayer as &$layer) {
+				$layer->layer_searchable = 0;//why
+				$e = new mb_notice("mb_metadata_server.php: Check layer with id ".$layer->layer_uid." to be searchable");
+				for ($i = 0; $i < count($data->wms->layer_searchable); $i++) {
+					//$e = new mb_exception("mb_metadata_server.php: Layer with id ".$id." found to be searchable");
+					$id = $data->wms->layer_searchable[$i];
+					$e = new mb_notice("mb_metadata_server.php: Layer with id ".$id." found to be searchable");
+					if ($id == intval($layer->layer_uid)) {
+						$e = new mb_notice("mb_metadata_server.php: Layer identical - update it in wms object");
+						$layer->layer_searchable = 1;					
+					} else {
+						continue; //with next 
+					}
+					unset($id);
+					//$layer->layer_searchable = 1;
+					//break;
+				}
+			}
+		}
+
+		try {
+			$layerId = intval($data->layer->layer_id);
+		}
+		catch (Exception $e) {
+		  	$ajaxResponse->setSuccess(false);
+			$ajaxResponse->setMessage(_mb("Could not read layer ID ".$data->layer->layer_id));
+			$ajaxResponse->send();						
+		}
+		
+		if ($layerId) {
+			$e = new mb_notice("Got following layer id from wms metadata editor client: ".$layerId);
+			try {
+				$layer = &$wms->getLayerReferenceById($layerId);
+			}
+			catch (Exception $e) {
+				$ajaxResponse->setSuccess(false);
+				$ajaxResponse->setMessage(_mb("Could not get layer with ID ".$layerId));
+				$ajaxResponse->send();						
+			}
+			$columns = array(
+				"layer_abstract",
+				"layer_title",
+				"layer_keyword",
+				"layer_md_topic_category_id",
+				"layer_inspire_category_id",
+				"layer_custom_category_id"
+			);
+
+			foreach ($columns as $c) {
+				$value = $data->layer->$c;
+				$e = new mb_notice("plugins/mb_metadata_server.php: layer entry for ".$c.": ".$data->layer->$c);
+				if ($c === "layer_keyword") {
+					$layer->$c = explode(",", $value);
+					foreach ($layer->$c as &$val) {
+						$val = trim($val);
+					}
+				}
+				elseif ($c === "layer_md_topic_category_id"
+					|| $c === "layer_inspire_category_id"
+					|| $c === "layer_custom_category_id"
+				) {
+					if (!is_array($value)) {
+						$layer->$c = array($value);
+					}
+					else {
+						$layer->$c = $value;
+					}
+				}
+				else {
+					if (!is_null($value)) {
+						$layer->$c = $value;
+					}
+				}
+			}
+		}
+		if ($wms->wms_network_access == "on") {
+			$wms->wms_network_access = intval('1');
+		} else {
+			$wms->wms_network_access = intval('0');
+		}
+		//try {
+			$wms->updateObjInDB($wmsId);
+		//}
+		//catch (Exception $e) {
+		//	$ajaxResponse->setSuccess(false);
+		//	$ajaxResponse->setMessage(_mb("Could not update wms object in database!"));
+		//	$ajaxResponse->send();						
+		//}
+		
+		
+		$ajaxResponse->setMessage("Updated WMS metadata for ID " . $wmsId);
+		$ajaxResponse->setSuccess(true);		
+		
+		break;
+	case "getContactMetadata" :
+		$mbGroupId = $ajaxResponse->getParameter("id");
+		$sql = <<<SQL
+	
+SELECT mb_group_name, mb_group_title, mb_group_address, mb_group_email, mb_group_postcode, mb_group_city, mb_group_logo_path, mb_group_voicetelephone FROM mb_group WHERE mb_group_id = $1
+
+SQL;
+		$v = array($mbGroupId);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$row = array();
+		if ($res) {
+			$row = db_fetch_assoc($res);
+			$resultObj["fkey_mb_group_id"] = $mbGroupId;
+			$resultObj["mb_group_name"] = $row["mb_group_name"];
+			$resultObj["mb_group_title"] = $row["mb_group_title"];
+			$resultObj["mb_group_address"] = $row["mb_group_address"];
+			$resultObj["mb_group_email"] = $row["mb_group_email"];
+			$resultObj["mb_group_postcode"] = $row["mb_group_postcode"];
+			$resultObj["mb_group_city"] = $row["mb_group_city"];
+			$resultObj["mb_group_logo_path"] = $row["mb_group_logo_path"];
+			$resultObj["mb_group_voicetelephone"] = $row["mb_group_voicetelephone"];	
+		}
+		$ajaxResponse->setResult($resultObj);
+		$ajaxResponse->setSuccess(true);
+		break;
+	case "getWmsIdByLayerId" :
+		$layerId = $ajaxResponse->getParameter("layerId");
+		$sql = <<<SQL
+
+SELECT fkey_wms_id from layer where layer_id = $1
+
+SQL;
+		$v = array($layerId);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$row = array();
+		if ($res) {
+			$row = db_fetch_assoc($res);
+			$resultObj["wms_id"]= $row['fkey_wms_id']; 
+		}
+		$ajaxResponse->setResult($resultObj);
+		$ajaxResponse->setSuccess(true);
+		break;
+	case "getLayerMetadataAddon" :
+		$layerId = $ajaxResponse->getParameter("layerId");
+		$metadataId = $ajaxResponse->getParameter("metadataId");
+		$sql = <<<SQL
+
+SELECT * from mb_metadata where metadata_id = $1
+
+SQL;
+		$v = array($metadataId);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$row = array();
+		if ($res) {
+			$row = db_fetch_assoc($res);
+			$resultObj["metadata_id"]= $row['metadata_id']; //serial
+			$resultObj["uuid"] = $row["uuid"]; //char
+			$resultObj["origin"] = $row["origin"]; //char
+			$resultObj["link"] = $row["link"]; //char
+			$resultObj["linktype"] = $row["linktype"]; //char
+			$resultObj["title"] = $row["title"]; //char -- prefill from layer
+			$resultObj["abstract"] = $row["abstract"]; //char - prefill from layer
+			$resultObj["format"] = $row["format"]; //char
+			$resultObj["ref_system"] = $row["ref_system"]; //char
+			$resultObj["spatial_res_type"] = $row["spatial_res_type"]; //integer
+			$resultObj["spatial_res_value"] = $row["spatial_res_value"]; //char
+			$resultObj["inspire_charset"] = $row["inspire_charset"]; //char
+			$resultObj["lineage"] = $row["lineage"]; //text
+			$resultObj["tmp_reference_1"] = $row["tmp_reference_1"]; //text
+			$resultObj["tmp_reference_2"] = $row["tmp_reference_2"]; //text
+			$export2csw = $row["export2csw"]; //boolean
+			$resultObj["update_frequency"] = $row["update_frequency"]; //text
+			switch ($export2csw) {
+				case "t" :
+					$resultObj["export2csw"] = true;
+					break;
+				case "f" :
+					$resultObj["export2csw"] = false;
+					break;
+				default:
+				break;	
+			}
+			$inspire_top_consistence = $row["inspire_top_consistence"]; //boolean
+			switch ($inspire_top_consistence) {
+				case "t" :
+					$resultObj["inspire_top_consistence"] = true;
+					break;
+				case "f" :
+					$resultObj["inspire_top_consistence"] = false;
+					break;
+				default:
+				break;	
+			}					
+			
+		}
+		$ajaxResponse->setResult($resultObj);
+		$ajaxResponse->setSuccess(true);
+		break;
+case "getInitialLayerMetadata" :
+		$layerId = $ajaxResponse->getParameter("layerId");
+		$metadataId = $ajaxResponse->getParameter("metadataId");
+		$sql = <<<SQL
+
+SELECT layer_title, layer_abstract from layer where layer_id = $1
+
+SQL;
+		$v = array($layerId);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$row = array();
+		if ($res) {
+			$row = db_fetch_assoc($res);
+			$resultObj["title"]= $row['layer_title']; //serial
+			$resultObj["abstract"] = $row["layer_abstract"]; //char	
+		}
+		$ajaxResponse->setResult($resultObj);
+		$ajaxResponse->setSuccess(true);
+		break;
+	case "updateLayerMetadataAddon" :
+		$layerId = $ajaxResponse->getParameter("layerId");
+		$metadataId = $ajaxResponse->getParameter("metadataId");
+		$data = $ajaxResponse->getParameter("data");
+		if ($data->export2csw) {
+			$data->export2csw = 't';
+		} else {
+			$data->export2csw = 'f';
+		}
+		if ($data->inspire_top_consistence) {
+			$data->inspire_top_consistence = 't';
+		} else {
+			$data->inspire_top_consistence = 'f';
+		}
+		$sql = <<<SQL
+
+UPDATE mb_metadata SET link = $2, title = $3, abstract = $4, format = $5, ref_system = $6, export2csw = $7, inspire_top_consistence = $8, tmp_reference_1 = $9, tmp_reference_2 = $10, lineage = $11, spatial_res_type = $12, spatial_res_value = $13, inspire_charset = $14, changedate = now(), update_frequency = $15 WHERE metadata_id = $1
+
+SQL;
+		$v = array($metadataId, $data->link, $data->title, $data->abstract, $data->format, $data->ref_system, $data->export2csw, $data->inspire_top_consistence, $data->tmp_reference_1, $data->tmp_reference_2, $data->lineage, $data->spatial_res_type, $data->spatial_res_value, $data->inspire_charset, $data->update_frequency);
+		$t = array('i','s','s','s','s','s','b','b','s','s','s','s','s','s','s');
+		try {
+			$res = db_prep_query($sql,$v,$t);
+		}
+		catch (Exception $e){
+			$ajaxResponse->setSuccess(false);
+			$ajaxResponse->setMessage(_mb("Could not update metadata object in database!"));
+			$ajaxResponse->send();
+			die;	
+		}
+		$ajaxResponse->setMessage("Metadata updated!");
+		$ajaxResponse->setSuccess(true);
+		break;
+	case "insertLayerMetadataAddon" :
+		$layerId = $ajaxResponse->getParameter("layerId");
+		$data = $ajaxResponse->getParameter("data");
+		//normaly the link is only set if a link has been created
+		//if a record has been created, the link element will be empty 
+		//use this to distinguish between the to different inserts!
+		//this insert should also push one entry in the ows_relation_metadata table! - after the insert into md_metadata
+		//origin
+		if ($data->kindOfMetadataAddOn == 'link') {
+			//generate metador entry
+			$origin = 'external';
+		} else {
+			$origin = 'metador';
+		}
+		//export
+		if ($data->export2csw == "on") {
+			$data->export2csw = 't';
+		} else {
+			$data->export2csw = 'f';
+		}
+		//consistance
+		if ($data->inspire_top_consistence == "on") {
+			$data->inspire_top_consistence = 't';
+		} else {
+			$data->inspire_top_consistence = 'f';
+		}
+		//generate a uuid for the record:
+		$uuid = new Uuid();
+		//initialize database objects
+		$link = '';
+		$title = '';
+		$abstract = '';
+		$format = '';	
+		$ref_system = '';
+		$export2csw = 'f';
+		$inspire_top_consistence = 'f';
+		$tmp_reference_1 = '';
+		$tmp_reference_2 = '';
+		$lineage = '';
+		$spatial_res_type = '';
+		$spatial_res_value = '';
+		$inspire_charset = '';
+		$update_frequency = '';
+		//read out json objects 
+		if (isset($data->link)) {
+			$link = $data->link;
+		}
+		if (isset($data->export2csw)) {
+			$export2csw = $data->export2csw;
+		} else {
+			$export2csw = 'f';
+		}
+		if (isset($data->title)) {
+			$title = $data->title;
+		}
+		if (isset($data->abstract)) {
+			$abstract = $data->abstract;
+		}
+		if (isset($data->format)) {
+			$format = $data->format;
+		}
+		if (isset($data->ref_system)) {
+			$ref_system = $data->ref_system;
+		}
+		if (isset($data->inspire_top_consistence)) {
+			$inspire_top_consistence = $data->inspire_top_consistence;
+		}
+		if (isset($data->tmp_reference_1)) {
+			$tmp_reference_1 = $data->tmp_reference_1;
+		}
+		if ($tmp_reference_1 == "") {
+			$tmp_reference_1 = "2000-01-01";
+		}
+		if (isset($data->tmp_reference_2)) {
+			$tmp_reference_2 = $data->tmp_reference_2;
+		}
+		if ($tmp_reference_2 == "") {
+			$tmp_reference_2 = "2000-01-01";
+		}
+		if (isset($data->lineage)) {
+			$lineage = $data->lineage;
+		}
+		if (isset($data->spatial_res_type)) {
+			$spatial_res_type = $data->spatial_res_type;
+		}
+		if (isset($data->spatial_res_value)) {
+			$spatial_res_value = $data->spatial_res_value;
+		}
+		if (isset($data->inspire_charset)) {
+			$inspire_charset = $data->inspire_charset;
+		}
+		if (isset($data->update_frequency)) {
+			$update_frequency = $data->update_frequency;
+		}
+		$randomid = new Uuid();
+		//Check if origin is external and export2csw is activated!
+		if ($origin == 'external' ) {
+			//harvest link from location, parse the content for datasetid and push xml into data column
+			//load metadata from link TODO: function from class_wms - generate a class for metadata management and include it here and in class_wms
+			$metadataConnector = new connector();
+			$metadataConnector->set("timeOut", "5");
+			$metaData = $metadataConnector->load($link);
+			//$e = new mb_exception($metaData);
+			if (!$metaData) {
+    				abort(_mb("Could not load metadata from source url!"));
+			}
+			//delete getRecordByIdResponse from xml if there
+			$regex = "#<csw:GetRecordByIdResponse .*?>#";
+			$output = preg_replace($regex,"",$metaData);
+			$regex = "#</csw:GetRecordByIdResponse>#";
+			$output = preg_replace($regex,"",$output);
+			//$e = new mb_exception($output);
+			$metaData = $output;
+			//***
+			//write metadata to temporary file:
+			$randomFileId = new Uuid();
+				
+			$tmpMetadataFile = fopen(TMPDIR.'/link_metadata_file_'.$randomFileId.'.xml', 'w');
+			fwrite($tmpMetadataFile, $metaData);
+			fclose($tmpMetadataFile);
+			$e = new mb_exception("File which has been written: link_metadata_file_".$randomFileId.".xml");
+			//read out objects from xml structure
+			if (file_exists(TMPDIR.'/link_metadata_file_'.$randomFileId.'.xml')) {
+				$iso19139Xml=simplexml_load_file(TMPDIR.'/link_metadata_file_'.$randomFileId.'.xml');
+				//$metaData = file_get_contents(TMPDIR.'/link_metadata_file_'.$randomFileId.'.xml');
+			} else {
+				abort(_mb("Temporary file could not be parsed!"));
+			}
+			//$metaData = $metadataConnector->file;
+			//parse metadata
+			/*try {
+				$iso19139Xml =  new SimpleXMLElement($metaData);
+			}
+			catch (Exception $e) {
+				abort(_mb("Parsing ISO19139 XML failed!"));
+			}*/
+			if ($iso19139Xml != false) {
+				//get elements for database from xml by using xpath
+				//uuid
+				$uuid = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:fileIdentifier/gco:CharacterString');
+				$e = new mb_exception("plugins/mb_metadata_server.php: File Identifier found: ".$uuid);
+				//createdate
+				$createdate = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:dateStamp/gco:Date');
+				//changedate
+				$changedate = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:dateStamp/gco:Date');
+				//TODO: check if this is set, maybe DateTime must be searched instead?
+				//title
+				$title = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString');
+				//datasetid
+				//next came from class_wms - TODO maybe put it into a special function
+				//dataset identifier - howto model into md_metadata?
+				//check where datasetid is defined - maybe as RS_Identifier or as MD_Identifier see http://inspire.jrc.ec.europa.eu/documents/Metadata/INSPIRE_MD_IR_and_ISO_v1_2_20100616.pdf page 18
+				//First check if MD_Identifier is set, then check if RS_Identifier is used!
+				//Initialize datasetid
+				$datasetid = 'undefined';
+				$code = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:MD_Identifier/gmd:code/gco:CharacterString');
+				if (isset($code[0]) && $code[0] != '') {
+					$e = new mb_exception("plugins/mb_metadata_server.php: code given thru MD_Identifier: ".$code[0]);
+					//check if code is defined by codespace and code
+					$codeSplit = explode("#",$code);
+					if (isset($codeSplit[0]) && $codeSplit[0] != '' && isset($codeSplit[1]) && $codeSplit[1] != '') {
+						$e = new mb_exception("plugins/mb_metadata_server.php: code was constructed via codespace#code !");	
+						$datasetid = $codeSplit[0]."#".$codeSplit[1];
+					} else {
+						$e = new mb_exception("plugins/mb_metadata_server.php: code was not constructed via codespace#code !");	
+						$datasetid = $code[0];
+					}
+				} else { //try to read code from RS_Identifier 		
+					$code = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:RS_Identifier/gmd:code/gco:CharacterString');
+					$codeSpace = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:RS_Identifier/gmd:codeSpace/gco:CharacterString');
+				#$e = new mb_exception("plugins/mb_metadata_server.php: code: ".$code[0]);
+				#$e = new mb_exception("plugins/mb_metadata_server.php: codeSpace: ".$codeSpace[0]);
+					if (isset($codeSpace[0]) && isset($code[0]) && $codeSpace[0] != '' && $code[0] != '') {
+						$datasetid = $codeSpace[0]."#".$code[0];
+						$e = new mb_exception("plugins/mb_metadata_server.php: datasetid: ".$datasetid);
+					} else {
+						//neither MD_Identifier nor RS_Identifier are defined in a right way
+						$e = new mb_exception("plugins/mb_metadata_server.php: the service data coupling has problems, cause the metadata doesnt have defined a datasetid");
+					}
+				}
+				//abstract
+				$abstract = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:abstract/gco:CharacterString');
+				//searchtext -- use keywords!
+				$keywords = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:descriptiveKeywords/gmd:MD_Keywords/gmd:keyword/gco:CharacterString');
+				//type 
+				$type = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:hierarchyLevel/gmd:MD_ScopeCode');
+				//tmp_reference_1
+				$tmp_reference_1 = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition');
+				//tmp_reference_2
+				$tmp_reference_2 = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:endPosition');		//spatial_res_type
+				//spatial_res_value
+				//ref_system
+				//format
+				//inspire_charset
+				//inspire_top_consistence
+				//responsible_party
+				//fees
+				//"constraints"	
+				//fill database with elements:
+
+				$sql = <<<SQL
+
+INSERT INTO mb_metadata (link, uuid, origin, title, abstract, format, ref_system, export2csw, inspire_top_consistence, tmp_reference_1, tmp_reference_2, lineage, spatial_res_type, spatial_res_value, inspire_charset, createdate, datasetid, randomid, data, harvestresult) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, now(), $16, $17, $18, 1)
+
+SQL;
+				$v = array($link, $uuid[0], $origin, $title[0], $abstract[0], $format, $ref_system, $export2csw,$inspire_top_consistence,$tmp_reference_1[0],$tmp_reference_2[0],$lineage,$spatial_res_type,$spatial_res_value,$inspire_charset, $datasetid, $randomid, $metaData);
+				$t = array('s','s','s','s','s','s','s','b','b','s','s','s','s','s','s','s','s','s');
+		
+				try {
+					$res = db_prep_query($sql,$v,$t);
+				}
+				catch (Exception $e){
+					abort(_mb("Insert of harvested metadata into database failed!"));
+				}
+			
+			} else {
+				abort(_mb("Problem with parsing the XML structure with SimpleXML! Record was not inserted into database! Ask your administrator."));
+				//give back error message - cause parsing has problems
+			}
+		} else { //fill only links or the edited information into db 
+			$sql = <<<SQL
+
+INSERT INTO mb_metadata (link, uuid, origin, title, abstract, format, ref_system, export2csw, inspire_top_consistence, tmp_reference_1, tmp_reference_2, lineage, spatial_res_type, spatial_res_value, inspire_charset, createdate, randomid, update_frequency) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, now(), $16, $17)
+
+SQL;
+			$v = array($link, $uuid, $origin, $title, $abstract, $format, $ref_system, $export2csw,$inspire_top_consistence,$tmp_reference_1,$tmp_reference_2,$lineage,$spatial_res_type,$spatial_res_value,$inspire_charset, $randomid, $update_frequency);
+			$t = array('s','s','s','s','s','s','s','b','b','s','s','s','s','s','s','s','s');
+		
+			try {
+				$res = db_prep_query($sql,$v,$t);
+			}
+			catch (Exception $e){
+				abort(_mb("Insert of edited metadata into database failed!"));
+			}
+		}
+		//set relation into relation table
+		//get metadata_id of record which have been inserted before
+		$sql = <<<SQL
+
+SELECT metadata_id FROM mb_metadata WHERE randomid = $1
+
+SQL;
+		//maybe there are more than one results - which should be used??? case of creating new linkage with old metadata TODO TODO
+		$v = array($randomid);
+		$t = array('s');
+		try {
+			$res = db_prep_query($sql,$v,$t);
+		}
+		catch (Exception $e){
+			abort(_mb("Cannot get metadata record with following uuid from database: ".$uuid));
+		}
+		if ($res) {
+			$row = db_fetch_assoc($res);
+			$metadata_id = $row['metadata_id'];
+		}
+		$sql = <<<SQL
+
+		INSERT INTO ows_relation_metadata (fkey_metadata_id, fkey_layer_id) VALUES ($1, $2)
+
+SQL;
+		$v = array($metadata_id, $layerId);
+		$t = array('i','i');
+		try {
+			$res = db_prep_query($sql,$v,$t);
+		}
+		catch (Exception $e){
+				abort(_mb("Cannot write relation between ows and metadata to database!"));
+		}
+		if ($dbInsertFailed != true) {	
+			$ajaxResponse->setMessage("Metadata object inserted into md_metadata!");
+			$ajaxResponse->setSuccess(true);
+		}				
+		break;
+	case "deleteLayerMetadataAddon" :
+		$metadataId = $ajaxResponse->getParameter("metadataId");
+		$sql = <<<SQL
+
+DELETE FROM mb_metadata WHERE metadata_id = $1
+
+SQL;
+		$v = array($metadataId);
+		$t = array('i');
+		try {
+			$res = db_prep_query($sql,$v,$t);
+		}
+		catch (Exception $e){
+			$ajaxResponse->setSuccess(false);
+			$ajaxResponse->setMessage(_mb("Could not delete metadata from database!"));
+			$ajaxResponse->send();
+			die;	
+		}
+		$ajaxResponse->setMessage("Metadata deleted!");
+		$ajaxResponse->setSuccess(true);
+		break;
+	case "importLayerXmlAddon" :
+//this is similar to insert the metadata from external link, but came from internal file from tmp folder which has been updated before
+		$layerId = $ajaxResponse->getParameter("layerId");
+		$filename = $ajaxResponse->getParameter("filename");
+		//normaly the link is only set if a link has been created
+		//if a record has been created, the link element will be empty 
+		//use this to distinguish between the to different inserts!
+		//this insert should also push one entry in the ows_relation_metadata table! - after the insert into md_metadata
+		//origin
+		//generate metador entry
+		$origin = 'upload';
+		//generate a uuid for the record:
+		$uuid = new Uuid();
+		//initialize database objects
+		$link = '';
+		$title = '';
+		$abstract = '';
+		$format = '';	
+		$ref_system = '';
+		$export2csw = 't';
+		$inspire_top_consistence = 'f';
+		$tmp_reference_1 = '';
+		$tmp_reference_2 = '';
+		$lineage = '';
+		$spatial_res_type = '';
+		$spatial_res_value = '';
+		$inspire_charset = '';
+		$randomid = new Uuid();	
+		$e = new mb_exception("File to load: ".$filename);
+		//read out objects from xml structure
+		/*if (file_exists($filename)) {
+			try {	
+				
+				$iso19139Xml = simplexml_load_file($filename);
+			}
+			catch (Exception $e) {
+				abort(_mb("Loading ISO19139 XML failed!"));
+			}
+		}
+		else {
+			abort(_mb("File not found: ".$filename." !"));
+		}*/
+		$metaData = file_get_contents($filename);
+		if (!$metaData){
+			abort(_mb("Reading file ".$filename." failed!"));
+		}
+		//delete getRecordByIdResponse from xml if there
+		$regex = "#<csw:GetRecordByIdResponse .*?>#";
+		$output = preg_replace($regex,"",$metaData);
+		$regex = "#</csw:GetRecordByIdResponse>#";
+		$output = preg_replace($regex,"",$output);
+		//$e = new mb_exception($output);
+		$iso19139Xml = simplexml_load_string($output);
+		$e = new mb_exception('');
+		
+		//get elements for database from xml by using xpath
+		//uuid
+		$uuid = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:fileIdentifier/gco:CharacterString');
+		if (!isset($uuid) || $uuid == "") {
+			abort(_mb(" No fileIdentifier found, parsing ISO19139 XML maybe failed. Check if element /gmd:MD_Metadata/gmd:fileIdentifier/gco:CharacterString is given and not empty!"));
+		}
+		//$e = new mb_exception("plugins/mb_metadata_server.php: File Identifier found: ".$uuid);
+		//createdate
+		$createdate = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:dateStamp/gco:Date');
+		//changedate
+		$changedate = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:dateStamp/gco:Date');
+		//TODO: check if this is set, maybe DateTime must be searched instead?
+		//title
+		$title = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString');
+		//next came from class_wms - TODO maybe put it into a special function
+		//dataset identifier - howto model into md_metadata?
+		//check where datasetid is defined - maybe as RS_Identifier or as MD_Identifier see http://inspire.jrc.ec.europa.eu/documents/Metadata/INSPIRE_MD_IR_and_ISO_v1_2_20100616.pdf page 18
+		//First check if MD_Identifier is set, then check if RS_Identifier is used!
+		//Initialize datasetid
+		$datasetid = 'undefined';
+		$code = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:MD_Identifier/gmd:code/gco:CharacterString');
+		if (isset($code[0]) && $code[0] != '') {
+			$e = new mb_exception("plugins/mb_metadata_server.php: code given thru MD_Identifier: ".$code[0]);
+			//check if code is defined by codespace and code
+			$codeSplit = explode("#",$code);
+			if (isset($codeSplit[0]) && $codeSplit[0] != '' && isset($codeSplit[1]) && $codeSplit[1] != '') {
+				$e = new mb_exception("plugins/mb_metadata_server.php: code was constructed via codespace#code !");	
+				$datasetid = $codeSplit[0]."#".$codeSplit[1];
+			} else {
+				$e = new mb_exception("plugins/mb_metadata_server.php: code was not constructed via codespace#code !");	
+				$datasetid = $code;
+			}
+		} else { //try to read code from RS_Identifier 		
+			$code = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:RS_Identifier/gmd:code/gco:CharacterString');
+			$codeSpace = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:RS_Identifier/gmd:codeSpace/gco:CharacterString');
+		#$e = new mb_exception("plugins/mb_metadata_server.php: code: ".$code[0]);
+		#$e = new mb_exception("plugins/mb_metadata_server.php: codeSpace: ".$codeSpace[0]);
+			if (isset($codeSpace[0]) && isset($code[0]) && $codeSpace[0] != '' && $code[0] != '') {
+				$datasetid = $codeSpace[0]."#".$code[0];
+				$e = new mb_exception("plugins/mb_metadata_server.php: datasetid: ".$datasetid);
+			} else {
+				//neither MD_Identifier nor RS_Identifier are defined in a right way
+				$e = new mb_exception("plugins/mb_metadata_server.php: the service data coupling has problems, cause the metadata doesnt have defined a datasetid");
+			}
+		}
+
+
+		//abstract
+		$abstract = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:abstract/gco:CharacterString');
+		//searchtext -- use keywords!
+		$keywords = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:descriptiveKeywords/gmd:MD_Keywords/gmd:keyword/gco:CharacterString');
+		//type 
+		$type = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:hierarchyLevel/gmd:MD_ScopeCode');
+		//tmp_reference_1
+		$tmp_reference_1 = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition');
+		//tmp_reference_2
+		$tmp_reference_2 = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:endPosition');	//spatial_res_type
+		//spatial_res_value
+		//ref_system
+		//format
+		//inspire_charset
+		//inspire_top_consistence
+		//responsible_party
+		//fees
+		//"constraints"	
+		//fill database with elements:
+		$sql = <<<SQL
+
+INSERT INTO mb_metadata (link, uuid, origin, title, abstract, format, ref_system, export2csw, inspire_top_consistence, tmp_reference_1, tmp_reference_2, lineage, spatial_res_type, spatial_res_value, inspire_charset, createdate, datasetid, randomid, data, harvestresult) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, now(), $16, $17, $18, 1)
+
+			
+SQL;
+			
+		$xml = $iso19139Xml->asXML();
+		$v = array($link, $uuid[0], $origin, $title[0], $abstract[0], $format, $ref_system, $export2csw,$inspire_top_consistence,$tmp_reference_1[0],$tmp_reference_2[0],$lineage,$spatial_res_type,$spatial_res_value,$inspire_charset, $datasetid, $randomid, $xml);
+		$t = array('s','s','s','s','s','s','s','b','b','s','s','s','s','s','s','s','s','s');
+		
+		try {
+				$res = db_prep_query($sql,$v,$t);
+		}
+		catch (Exception $e){
+			abort(_mb("Insert of harvested metadata into database failed!"));
+		}
+	//set relation into relation table
+	//get metadata_id of record which have been inserted before
+	$sql = <<<SQL
+
+SELECT metadata_id FROM mb_metadata WHERE randomid = $1
+
+SQL;
+	//maybe there are more than one results - which should be used??? case of creating new linkage with old metadata TODO TODO
+	$v = array($randomid);
+	$t = array('s');
+	try {
+		$res = db_prep_query($sql,$v,$t);
+	}
+	catch (Exception $e){
+		abort(_mb("Cannot get metadata record with following uuid from database: ".$uuid));
+	}
+	if ($res) {
+		$row = db_fetch_assoc($res);
+		$metadata_id = $row['metadata_id'];
+	}
+	$sql = <<<SQL
+
+	INSERT INTO ows_relation_metadata (fkey_metadata_id, fkey_layer_id) VALUES ($1, $2)
+
+SQL;
+	$v = array($metadata_id, $layerId);
+	$t = array('i','i');
+	try {
+		$res = db_prep_query($sql,$v,$t);
+	}
+	catch (Exception $e){
+			abort(_mb("Cannot write relation between ows and metadata to database!"));
+	}
+	if ($dbInsertFailed != true) {	
+		$ajaxResponse->setMessage("Metadata object inserted into md_metadata!");
+		$ajaxResponse->setSuccess(true);
+	}				
+	break;		
+
+	default: 
+		$ajaxResponse->setSuccess(false);
+		$ajaxResponse->setMessage(_mb("An unknown error occured."));
+		break;
+}
+
+$ajaxResponse->send();
+?>



More information about the Mapbender_commits mailing list