[Mapbender-commits] r7151 - in trunk/mapbender/http: classes plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Nov 24 07:11:35 EST 2010


Author: verenadiewald
Date: 2010-11-24 04:11:35 -0800 (Wed, 24 Nov 2010)
New Revision: 7151

Added:
   trunk/mapbender/http/plugins/mb_metadata_wmc_edit.js
   trunk/mapbender/http/plugins/mb_metadata_wmc_edit.php
   trunk/mapbender/http/plugins/mb_metadata_wmc_select.js
   trunk/mapbender/http/plugins/mb_metadata_wmc_showOriginal.html
   trunk/mapbender/http/plugins/mb_metadata_wmc_showOriginal.js
   trunk/mapbender/http/plugins/mb_metadata_wmc_submit.js
   trunk/mapbender/http/plugins/mb_original_metadata_wmc_server.php
Modified:
   trunk/mapbender/http/classes/class_wmc.php
   trunk/mapbender/http/plugins/mb_metadata_wmc_server.php
Log:
metadata editor wmc

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2010-11-24 11:07:13 UTC (rev 7150)
+++ trunk/mapbender/http/classes/class_wmc.php	2010-11-24 12:11:35 UTC (rev 7151)
@@ -125,6 +125,8 @@
 	var $wmc_descriptionurl_type;
 
 	var $inspireCats;
+	var $isoTopicCats;
+	var $customCats;
 
 	public function __construct () {
 		$this->userId = Mapbender::session()->get("mb_user_id");
@@ -155,7 +157,7 @@
 			return false;
 		}
 		$this->createObjFromWMC_xml($doc);
-		$sql = "SELECT wmc_timestamp, wmc_title, wmc_public " .
+		$sql = "SELECT wmc_timestamp, wmc_title, wmc_public, srs, minx, miny, maxx, maxy " .
 			"FROM mb_user_wmc WHERE wmc_serial_id = $1 AND (fkey_user_id = $2 OR wmc_public = 1)";
 		$v = array($wmcId, Mapbender::session()->get("mb_user_id"));
 		$t = array("i", "i");
@@ -167,6 +169,11 @@
 			$this->timestamp = $row[0];
 			$this->title = $row[1];
 			$this->public = $row[2];
+			$this->wmc_srs = $row[3];
+			$this->wmc_extent->minx = $row[4];
+			$this->wmc_extent->miny = $row[5];
+			$this->wmc_extent->maxx = $row[6];
+			$this->wmc_extent->maxy = $row[7];
 			return true;
 		}
 		return false;
@@ -253,8 +260,6 @@
 		return array_keys( array_flip(array_merge($wmcOwnerArray, $publicWmcIdArray)));
 	}
 
-
-
 	public function selectByUser ($user) {
 		$wmcArray = array();
 
@@ -323,6 +328,7 @@
 		while ($row = db_fetch_array($res)) {
 			$keywordArray[]= $row["keyword"];
 		}
+		
 		return $keywordArray;
 	}
 
@@ -332,19 +338,19 @@
 			return array();
 		}
 
-		$keywordArray = array();
+		$categoryArray = array();
 
 		$sql = "SELECT DISTINCT t.md_topic_category_id FROM " .
 			"md_topic_category AS t, wmc_md_topic_category AS w " .
 			"WHERE w.fkey_md_topic_category_id = t.md_topic_category_id " .
 			"AND w.fkey_wmc_serial_id = $1";
 		$v = array($id);
-		$t = array("s");
+		$t = array("i");
 		$res = db_prep_query($sql, $v, $t);
 		while ($row = db_fetch_array($res)) {
-			$keywordArray[]= $row["md_topic_category_id"];
+			$categoryArray[]= $row["md_topic_category_id"];
 		}
-		return $keywordArray;
+		return $categoryArray;
 	}
 
 	private function compareWms ($a, $b) {
@@ -568,8 +574,6 @@
 				new mb_exception("WMC XML is broken.");
 			}
 
-			$NewDoc = new DOMDocument();
-
 			$xpath = new DOMXPath($WMCDoc);
 			$xpath->registerNamespace("wmc","http://www.opengis.net/context");
 			$xpath->registerNamespace("mapbender","http://www.mapbender.org/context");
@@ -580,21 +584,24 @@
 			$DocKeywordLists = $xpath->query($query_KeywordList);
 			// we just use a single <general> element
 
-			$NewKeywordList = new DOMElement('KeywordList','','http://opengis.net/context');
-			$NewDoc->appendChild($NewKeywordList);
-			foreach($this->keyword as $keyword) {
-				$Keyword = new DOMElement('Keyword',$keyword, 'http://opengis.net/context');
+			$NewKeywordList = $WMCDoc->createElementNS('http://opengis.net/context', 'wmc:KeywordList');
+			$WMCDoc->appendChild($NewKeywordList);
+			
+			foreach($this->wmc_keyword as $keyword) {
+				$Keyword = $WMCDoc->createElementNS('http://opengis.net/context', 'wmc:Keyword', $keyword);
 				$NewKeywordList->appendChild($Keyword);
 			}
 
 			$generalList = $xpath->query($query_general);
 			$general = $generalList->item(0);
+			
 			if($DocKeywordLists->item(0)) {
-				$general->replaceChild($NewKeywordList,$DocKeywordList->item(0));
-			}else {
+				$tmpNode = $WMCDoc->importNode($DocKeywordLists->item(0),true);
+				$general->replaceChild($NewKeywordList,$tmpNode);
+			}
+			else {
 				$tmpNode = $WMCDoc->importNode($NewKeywordList,true);
 				$general->appendChild($tmpNode);
-
 			}
 
 			$this->xml  = $WMCDoc->saveXML();
@@ -622,20 +629,28 @@
 					$v = array($this->xml, time(), $this->wmc_abstract, $this->wmc_srs, $this->wmc_extent->minx, $this->wmc_extent->minx,
 						$this->wmc_extent->maxx, $this->wmc_extent->maxy ,administration::convertOutgoingString($this->wmc_title), $this->userId, $this->wmc_id,$row[2]);
 					$t = array("s", "s","s","s","i","i","i","i", "s", "i", "i","s");
+					$res = db_prep_query($sql, $v, $t);
 					// need the database Id
 					$wmc_DB_ID = $row[3];
+					$delsqlCustomTopic = "DELETE FROM wmc_custom_category WHERE fkey_wmc_serial_id = $1;";
+					$delvCustomTopic = array($wmc_DB_ID);
+					$deltCustomTopic = array("s");
+					db_prep_query($delsqlCustomTopic, $delvCustomTopic,$deltCustomTopic);
+
+					$delsqlInspireTopic = "DELETE FROM wmc_inspire_category WHERE fkey_wmc_serial_id = $1;";
+					$delvInspireTopic= array($wmc_DB_ID);
+					$deltInspireTopic = array("s");
+					db_prep_query($delsqlInspireTopic, $delvInspireTopic,$deltInspireTopic);
+					
 					$delsql = "DELETE FROM wmc_md_topic_category WHERE fkey_wmc_serial_id = $1;";
 					$delv = array($wmc_DB_ID);
 					$delt = array("s");
 					db_prep_query($delsql, $delv,$delt);
-
+					
 					$delkwsql = "DELETE FROM wmc_keyword WHERE fkey_wmc_serial_id = $1;";
 					$delkwv = array($wmc_DB_ID);
 					$delkwt = array("s");
 					db_prep_query($delkwsql, $delkwv,$delkwt);
-
-
-
 				}
 				else {
 					$sql = "INSERT INTO mb_user_wmc (" .
@@ -645,10 +660,15 @@
 					$v = array(time(), $this->userId, $this->xml, administration::convertOutgoingString($this->wmc_title), $user->isPublic()?1:0,time(),time(),
 						$this->wmc_abstract, $this->wmc_srs, $this->wmc_extent->minx,  $this->wmc_extent->miny, $this->wmc_extent->maxx, $this->wmc_extent->maxy);
 					$t = array("s", "i", "s", "s", "i", "s","s", "s","s","i","i","i", "i");
+					$res = db_prep_query($sql, $v, $t);
+					
+					$sql = "SELECT max(wmc_serial_id) AS i FROM mb_user_wmc";
+					$res = db_query($sql);
+					$row = db_fetch_assoc($res);
+					$wmc_DB_ID = intval($row["i"]);
 				}
 			}
 			else {
-
 				$sql = "INSERT INTO mb_user_wmc (" .
 					"wmc_id, fkey_user_id, wmc, wmc_title, wmc_public, wmc_timestamp, wmc_timestamp_create, " .
 					"abstract, srs, minx, miny, maxx, maxy ".
@@ -656,11 +676,14 @@
 				$v = array(time(), $this->userId, $this->xml, administration::convertOutgoingString($this->wmc_title), $user->isPublic()?1:0, time(),time(),
 					$this->wmc_abstract, $this->wmc_srs, $this->wmc_extent->minx,  $this->wmc_extent->miny, $this->wmc_extent->maxx, $this->wmc_extent->maxy);
 				$t = array("s", "i", "s", "s", "i", "s","s", "s","s","i","i","i", "i");
-
+				$res = db_prep_query($sql, $v, $t);
+				
+				$sql = "SELECT max(wmc_serial_id) AS i FROM mb_user_wmc";
+				$res = db_query($sql);
+				$row = db_fetch_assoc($res);
+				$wmc_DB_ID = intval($row["i"]);
 			}
 
-
-			$res = db_prep_query($sql, $v, $t);
 			if (db_error()) {
 				$errMsg = "Error while saving WMC document '" . $this->wmc_title . "': " . db_error();
 				$result["success"] = false;
@@ -674,30 +697,25 @@
 				if(!isset($wmc_DB_ID)) { $wmc_DB_ID = $this->wmc_id; }
 
 				// update keywords
-				foreach($this->keyword as $keyword) {
+				foreach($this->wmc_keyword as $keyword) {
 
 				// if a keyword does not yet exist, create it
 					$keywordExistsSql = "SELECT keyword FROM keyword WHERE keyword = $1";
 					$keywordCreateSql = "INSERT INTO keyword (keyword) VALUES($1);";
 					$v = array($keyword);
 					$t = array("s");
-					$res =  db_prep_query($keywordExistsSql,$v,$t);
+					$res = db_prep_query($keywordExistsSql,$v,$t);
 					if(db_num_rows($res) == 0) {
 						$res = db_prep_query($keywordCreateSql,$v,$t);
 						if($a = db_error()) {
 						}
 					}
-
-					$sql = "SELECT max(wmc_serial_id) AS i FROM mb_user_wmc";
-					$res = db_query($sql);
-					$row = db_fetch_assoc($res);
-					$wmc_DB_ID = intval($row["i"]);
-
+					
 					$keywordsql = <<<SQL
 INSERT INTO wmc_keyword (fkey_keyword_id,fkey_wmc_serial_id)
 	SELECT keyword.keyword_id,$1 FROM keyword
-	WHERE keyword = $2 AND NOT EXISTS (
-		SELECT fkey_wmc_serial_id FROM wmc_keyword	WHERE fkey_wmc_serial_id = $3
+	WHERE keyword = $2 AND keyword.keyword_id NOT IN (
+		SELECT fkey_keyword_id FROM wmc_keyword WHERE fkey_wmc_serial_id = $3
 	)
 SQL;
 					$v = array($wmc_DB_ID, $keyword,$wmc_DB_ID);
@@ -705,19 +723,41 @@
 					$res = db_prep_query($keywordsql, $v, $t);
 					if($a = db_error()) {
 					}
+				}
+				
+				// update iso topic categories
+				$this->isoTopicCats = $this->isoTopicCats? $this->isoTopicCats: array();
+				foreach($this->isoTopicCats as $catId) {
 
+					$catSql = "INSERT INTO wmc_md_topic_category (fkey_wmc_serial_id, fkey_md_topic_category_id) VALUES ($1,$2)";
+					$v = array($wmc_DB_ID, $catId);
+					$t = array("s","s");
+					$res = db_prep_query($catSql, $v, $t);
+
 				}
-				// update categories
+				
+				// update inspire categories
 				$this->inspireCats = $this->inspireCats? $this->inspireCats: array();
 				foreach($this->inspireCats as $catId) {
 
-					$catSql = "INSERT INTO wmc_md_topic_category (fkey_wmc_serial_id, fkey_md_topic_category_id) VALUES ($1,$2)";
+					$catSql = "INSERT INTO wmc_inspire_category (fkey_wmc_serial_id, fkey_inspire_category_id) VALUES ($1,$2)";
 					$v = array($wmc_DB_ID, $catId);
 					$t = array("s","s");
 					$res = db_prep_query($catSql, $v, $t);
 
 				}
+				
+				// update custom categories
+				$this->customCats = $this->customCats? $this->customCats: array();
+				foreach($this->customCats as $catId) {
 
+					$catSql = "INSERT INTO wmc_custom_category (fkey_wmc_serial_id, fkey_custom_category_id) VALUES ($1,$2)";
+					$v = array($wmc_DB_ID, $catId);
+					$t = array("s","s");
+					$res = db_prep_query($catSql, $v, $t);
+
+				}
+
 				$result["success"] = true;
 				$msg = "WMC document '" . $this->wmc_title . "' has been saved.";
 				$result["message"] = $msg;
@@ -825,7 +865,7 @@
 		if ($currentUser->isPublic()) {
 			return false;
 		}
-		$wmcId = $this->wmc_Id;
+		$wmcId = $this->wmc_id;
 		$public = $public ? 1 :0;
 		$sql = "UPDATE mb_user_wmc SET wmc_public = $1 WHERE wmc_serial_id = $2 AND fkey_user_id = $3;";
 		$v = array($public,$wmcId, $currentUser->id);

Added: trunk/mapbender/http/plugins/mb_metadata_wmc_edit.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wmc_edit.js	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_metadata_wmc_edit.js	2010-11-24 12:11:35 UTC (rev 7151)
@@ -0,0 +1,143 @@
+/**
+ * Package: mb_metadata_wmc_edit
+ *
+ * Description:
+ *
+ * Files:
+ *
+ * SQL:
+ * 
+ * Help:
+ *
+ * Maintainer:
+ * http://www.mapbender.org/User:Christoph_Baudson
+ *
+ * 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 $metadataEdit = $(this);
+var $metadataForm = $("<form>No WMC selected.</form>").appendTo($metadataEdit);
+
+var MetadataEditApi = function (o) {
+	var that = this;
+	var validator;
+	var formReady = false;
+	var wmcId;
+	
+	this.events = {
+		showOriginalMetadata : new Mapbender.Event(),
+		submit: new Mapbender.Event()
+	};
+
+	this.valid = function () {
+		if (validator && validator.numberOfInvalids() > 0) {
+			$metadataForm.valid();
+			return false;
+		}
+		return true;
+	};
+	
+	this.serialize = function (callback) {
+		$metadataForm.submit();
+		var data = null;
+		if (this.valid()) {
+			data = {
+				wmc: $metadataForm.easyform("serialize")
+			};
+		}
+		if ($.isFunction(callback)) {
+			callback(data);
+		}
+		return data !== null ? data.wmc : data;
+	};
+	
+	// second optional parameter formData
+	var fillForm = function (obj) {
+		
+		if (arguments.length >= 2) {
+			$metadataForm.easyform("reset");
+			$metadataForm.easyform("fill", arguments[1]);
+			that.valid();
+			return;
+		}
+		
+		// get metadata from server
+		var req = new Mapbender.Ajax.Request({
+			url: "../plugins/mb_metadata_wmc_server.php",
+			method: "getWmcMetadata",
+			parameters: {
+				"id": obj
+			},
+			callback: function (obj, result, message) {
+				if (!result) {
+					return;
+				}
+				$metadataForm.easyform("reset");
+				$metadataForm.easyform("fill", obj);
+				that.valid();
+			}
+		});
+		req.send();		
+	};
+
+	this.fill = function (obj) {
+		$metadataForm.easyform("fill", obj);
+	};
+	
+	var showOriginalMetadata = function () {
+		that.events.showOriginalMetadata.trigger({
+			data : {
+				wmcId : wmcId,
+				wmcData : $metadataForm.easyform("serialize")
+			}
+		});
+	};
+	
+	this.init = function (obj) {
+		wmcId = obj;
+		
+		var formData = arguments.length >= 2 ? arguments[1] : undefined;
+		
+		if (!formReady) {
+			$metadataForm.load("../plugins/mb_metadata_wmc_edit.php", function () {
+				$metadataForm.find(".help-dialog").helpDialog();
+				$metadataForm.find(".original-metadata-wmc").bind("click", function() {
+					showOriginalMetadata();
+				});				
+				validator = $metadataForm.validate({
+					submitHandler: function () {
+						return false;
+					}
+				});
+				if (formData !== undefined) {
+					fillForm(obj, formData);
+				}
+				else {
+					fillForm(obj);
+				}
+				formReady = true;
+			});
+			return;
+		}
+		fillForm(obj);
+	};
+	
+	Mapbender.events.localize.register(function () {
+		if (!wmcId) {
+			return;
+		}
+		that.valid();
+		var formData = $metadataForm.easyform("serialize");
+		formReady = false;
+		that.init(wmcId, formData);
+	});
+	Mapbender.events.init.register(function () {
+		that.valid();
+	});
+};
+
+$metadataEdit.mapbender(new MetadataEditApi(options));

Added: trunk/mapbender/http/plugins/mb_metadata_wmc_edit.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wmc_edit.php	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_metadata_wmc_edit.php	2010-11-24 12:11:35 UTC (rev 7151)
@@ -0,0 +1,94 @@
+<?php
+	require_once dirname(__FILE__) . "/../../core/globalSettings.php";
+	
+	function displayCategories ($sql) {
+		if (Mapbender::session()->get("mb_lang") === "de") {
+			$sql = str_replace("category_code_en", "category_code_de", $sql);
+		}
+		
+		$str = "";
+		$res = db_query($sql);
+		while ($row = db_fetch_assoc($res)) {
+			$str .= "<option value='" . $row["id"] . "'>" . 
+				htmlentities($row["name"], ENT_QUOTES, CHARSET) . 
+				"</option>";
+		}
+		return $str;
+	}
+?>
+<div id="wmc">
+<fieldset>
+	<input name="wmc_id" id="wmc_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 WMC-Featuretype 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"></img></legend>
+	<p>
+		<label><?php echo _mb("Show original Service Metadata from last update");?></label>
+		<img class="original-metadata-wmc" src="../img/book.png"></img>
+		<img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("The original WMC-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"></img>
+	</p>
+	<p>
+		<label for="wmc_title"><?php echo _mb("WMC Title (OWS)");?>:</label>
+		<input name="wmc_title" id="wmc_title" class="required"/>
+		<img class="metadata_img" title="<?php echo _mb("Inspire");?>" src="../img/misc/inspire_eu_klein.png"></img>
+	</p>
+	<p>
+    	<label for="wmc_abstract"><?php echo _mb("WMC Abstract (OWS)");?>:</label>
+    	<input name="wmc_abstract" id="wmc_abstract"/>
+    	<img class="metadata_img" title="<?php echo _mb("Inspire");?>" src="../img/misc/inspire_eu_klein.png"></img>
+	</p>
+	<p>
+		<label for="wmc_keyword"><?php echo _mb("WMC Keywords (OWS)");?>:</label>
+    	<input name="wmc_keyword" id="wmc_keyword"/>
+    	<img class="metadata_img" title="<?php echo _mb("Inspire");?>" src="../img/misc/inspire_eu_klein.png"></img>
+	</p>
+	<p>
+		<label for="public"><?php echo _mb("WMC is public");?>:</label>
+    	<input name="public" id="public" type="checkbox"/>
+    </p>
+</fieldset>
+</div>
+
+<div id="preview">
+	<fieldset class="">
+		<legend><?php echo _mb("Preview");?></legend>
+		<div id="map"></div>
+		<div id="toolbar_upper"></div>
+		<div id="toolbar_lower"></div>
+	</fieldset>
+</div>
+
+<div id="classification">
+	<fieldset class="">
+		<legend><?php echo _mb("Classification");?></legend>
+		<p>
+		    <label for="isoTopicCats" class="label_classification"><?php echo _mb("ISO Topic Category");?>:</label>
+			<img class="metadata_img" title="<?php echo _mb("Inspire");?>" src="../img/misc/inspire_eu_klein.png"></img>
+			<select class="metadata_selectbox" id="isoTopicCats" name="isoTopicCats" size="2" multiple="multiple">
+<?php
+	$sql = "SELECT md_topic_category_id AS id, md_topic_category_code_en AS name FROM md_topic_category";
+	echo displayCategories($sql);
+?>
+			</select>
+		</p>
+		<p>
+		    <label for="inspireCats" class="label_classification"><?php echo _mb("INSPIRE Category");?>:</label>
+			<img class="metadata_img" title="<?php echo _mb("Inspire");?>" src="../img/misc/inspire_eu_klein.png"></img>
+			<select class="metadata_selectbox" id="inspireCats" name="inspireCats" size="2" multiple="multiple">
+<?php
+	$sql = "SELECT inspire_category_id AS id, inspire_category_code_en AS name FROM inspire_category";
+	echo displayCategories($sql);
+?>
+			</select>
+		</p>
+		<p>
+		    <label for="customCats" class="label_classification"><?php echo _mb("Custom Category");?>:</label>
+			<span class="metadata_span"></span>
+			<select class="metadata_selectbox" id="customCats" name="customCats" size="2" multiple="multiple">
+<?php
+	$sql = "SELECT custom_category_id AS id, custom_category_code_en AS name FROM custom_category";
+	echo displayCategories($sql);
+?>
+			</select>
+		</p>
+	</fieldset>
+</div>

Added: trunk/mapbender/http/plugins/mb_metadata_wmc_select.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wmc_select.js	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_metadata_wmc_select.js	2010-11-24 12:11:35 UTC (rev 7151)
@@ -0,0 +1,104 @@
+/**
+ * Package: mb_metadata_wmc_select
+ *
+ * Description:
+ *
+ * Files:
+ *
+ * SQL:
+ * 
+ * Help:
+ *
+ * Maintainer:
+ * http://www.mapbender.org/User:Christoph_Baudson
+ *
+ * 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 $metadataSelect = $(this);
+$metadataSelect.prepend("<img src='../img/indicator_wheel.gif'>");
+
+var MetadataSelectApi = 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_metadata_wmc_server.php",
+			method: "getWmc",
+			parameters: {
+			},
+			callback: function (obj, result, message) {
+				if (!result) {
+					return;
+				}
+				$metadataSelect.find("img").remove();
+				
+				var aoColumns = [];
+				for (var i in obj.header) {
+					if (obj.header[i] === "WMC ID") {
+						continue;
+					}
+					aoColumns.push({"sTitle": obj.header[i]});
+				}
+
+				// initialize datatables
+				table = $metadataSelect.find("table").dataTable({
+					"aoColumns": aoColumns,
+					"bJQueryUI": true,
+					"bAutoWidth": false
+				});
+				
+				// add rows
+				for (var j in obj.data) {
+					var data = obj.data[j];
+					var wmcId = data[0];
+					data.shift();
+					var index = table.fnAddData(data);
+					var rowNode = table.fnGetNodes(index[0]);
+					$(rowNode).data("wmcId", wmcId);
+				}
+				
+				// make rows selectable
+				$metadataSelect.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);
+					$metadataSelect.fadeOut(function () {
+						that.events.selected.trigger({
+							wmcId: $(selectedRow).data("wmcId")
+						});
+						$metadataSelect.show();
+					});
+				});
+			}
+		});
+		req.send();
+	};
+	
+	this.events = {
+		selected: new Mapbender.Event()
+	};
+};
+
+$metadataSelect.mapbender(new MetadataSelectApi(options));
+
+$metadataSelect.mapbender("getData");
\ No newline at end of file

Modified: trunk/mapbender/http/plugins/mb_metadata_wmc_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wmc_server.php	2010-11-24 11:07:13 UTC (rev 7150)
+++ trunk/mapbender/http/plugins/mb_metadata_wmc_server.php	2010-11-24 12:11:35 UTC (rev 7151)
@@ -16,7 +16,9 @@
 
 function getWmc ($wmcId = null) {
 	$user = new User(Mapbender::session()->get("mb_user_id"));
-	$wmcIdArray = $user->getOwnedWmc();
+	$wmcIdArray = $user->getWmcByOwner();
+	//getAccessibleWmcs();
+		
 	if (!is_array($wmcIdArray) || count($wmcIdArray) === 0) {
 		abort(_mb("No metadata sets available."));
 	}
@@ -26,28 +28,14 @@
 	return $wmcIdArray;
 }
 
-/*function getFeaturetype ($featuretypeId = null) {
-	$user = new User(Mapbender::session()->get("mb_user_id"));
-	$wfsIdArray = $user->getOwnedWfs();
-	if (!is_array($wfsIdArray) || count($wfsIdArray) === 0) {
-		abort(_mb("No metadata sets available."));
-	}
-	$wfsId = wfs::getWfsIdByFeaturetypeId($featuretypeId);
-	if (is_null($wfsId) || !in_array($wfsId, $wfsIdArray)) {
-		abort(_mb("You are not allowed to access this WFS " . $wfsId));
-	}
-	return;
-}
-*/
 switch ($ajaxResponse->getMethod()) {
 	case "getWmc" :
-		$wmcIdArray = getWfs();
-		
+		$wmcIdArray = getWmc();
 		$wmcList = implode(",", $wmcIdArray);
-		
 		$sql = <<<SQL
 	
-SELECT mb_user_wmc.wmc_serial_id as wmc_id, mb_user_wmc.wmc_title, mb_user_wmc.wmc_timestamp FROM mb_user_wmc WHERE wmc_serial_id IN ($wmcList);
+SELECT mb_user_wmc.wmc_serial_id as wmc_id, mb_user_wmc.wmc_title, mb_user_wmc.wmc_timestamp, wmc_load_count.load_count FROM mb_user_wmc 
+LEFT JOIN wmc_load_count ON wmc_load_count.fkey_wmc_serial_id = mb_user_wmc.wmc_serial_id WHERE wmc_serial_id IN ($wmcList);
 
 SQL;
 		$res = db_query($sql);
@@ -55,7 +43,8 @@
 			"header" => array(
 				"WMC ID",
 				"Titel",
-				"Timestamp"
+				"Timestamp",
+				"Load Count"
 			), 
 			"data" => array()
 		);
@@ -71,33 +60,31 @@
 
 	case "getWmcMetadata" :
 		$wmcId = $ajaxResponse->getParameter("id");
-		getWmcs($wmcId);
-
+		
 		$sql = <<<SQL
 	
-SELECT wmc_serial_id as wmc_id, wmc_abstract, wmc_title 
-individualname, positionname, providername, voice, 
-wmc_timestamp, wmc_timestamp_create 
+SELECT wmc_serial_id as wmc_id, abstract, wmc_title, 
+wmc_timestamp, wmc_timestamp_create, wmc_public 
 FROM mb_user_wmc WHERE wmc_serial_id = $wmcId;
 
 SQL;
 
 		$res = db_query($sql);
-		$resultObj = array();
 		$row = db_fetch_assoc($res);
 		
+		$resultObj = array();
 		$resultObj['wmc_id'] = $row['wmc_id'];
-		$resultObj['summary'] = $row['wmc_abstract'];
-		$resultObj['title'] = $row['wfs_title'];
-		$resultObj['fees'] = $row['fees'];
+		$resultObj['wmc_abstract'] = $row['abstract'];
+		$resultObj['wmc_title'] = $row['wmc_title'];
 		$resultObj['wmc_timestamp'] = $row['wmc_timestamp'] != "" ? date('d.m.Y', $row['wmc_timestamp']) : "";
 		$resultObj['wmc_timestamp_create'] = $row['wmc_timestamp_create'] != "" ? date('d.m.Y', $row['wmc_timestamp_create']) : "";
-		
+		$resultObj['public'] = $row['wmc_public'] == 1 ? true : false;	
+
 		$keywordSql = <<<SQL
 	
 SELECT DISTINCT keyword FROM keyword, wmc_keyword 
 WHERE keyword_id = fkey_keyword_id AND 
-fkey_wmc_id = $wmcId ORDER BY keyword
+fkey_wmc_serial_id = $wmcId ORDER BY keyword
 
 SQL;
 
@@ -107,54 +94,16 @@
 			$keywords[]= $keywordRow["keyword"];
 		}
 
-		$resultObj["wmc_keywords"] = implode(", ", $keywords);
-/*
-		$termsofuseSql = <<<SQL
-SELECT fkey_termsofuse_id FROM wfs_termsofuse WHERE fkey_wfs_id = $wfsId
-SQL;
+		$resultObj["wmc_keyword"] = implode(", ", $keywords);
 
-		$termsofuseRes = db_query($termsofuseSql);
-		if ($termsofuseRes) {
-			$termsofuseRow = db_fetch_assoc($termsofuseRes);
-			$resultObj["wfs_termsofuse"] = $termsofuseRow["fkey_termsofuse_id"];
-		}
-		else {
-			$resultObj["wfs_termsofuse"] = null;
-		}
-		
-
-		$ajaxResponse->setResult($resultObj);
-		$ajaxResponse->setSuccess(true);
-
-		break;
-	
-	case "getFeaturetypeMetadata" :
-		$featuretypeId = $ajaxResponse->getParameter("id");
-		getFeaturetype($featuretypeId);
-
 		$sql = <<<SQL
-	
-SELECT featuretype_id, featuretype_name, featuretype_title, featuretype_abstract, featuretype_searchable 
-FROM wfs_featuretype WHERE featuretype_id = $featuretypeId;
-
-SQL;
-		$res = db_query($sql);
-
-		$resultObj = array();
-		while ($row = db_fetch_assoc($res)) {
-			foreach ($row as $key => $value) {
-				$resultObj[$key] = $value;
-			}
-		}
-*/
-		$sql = <<<SQL
 SELECT fkey_md_topic_category_id
 FROM wmc_md_topic_category 
 WHERE fkey_wmc_serial_id = $wmcId
 SQL;
 		$res = db_query($sql);
 		while ($row = db_fetch_assoc($res)) {
-			$resultObj["wmc_md_topic_category_id"][]= $row["fkey_md_topic_category_id"];
+			$resultObj["isoTopicCats"][]= $row["fkey_md_topic_category_id"];
 		}
 
 		$sql = <<<SQL
@@ -164,7 +113,7 @@
 SQL;
 		$res = db_query($sql);
 		while ($row = db_fetch_assoc($res)) {
-			$resultObj["wmc_inspire_category_id"][]= $row["fkey_inspire_category_id"];
+			$resultObj["inspireCats"][]= $row["fkey_inspire_category_id"];
 		}
 
 		$sql = <<<SQL
@@ -174,90 +123,15 @@
 SQL;
 		$res = db_query($sql);
 		while ($row = db_fetch_assoc($res)) {
-			$resultObj["wmc_custom_category_id"][]= $row["fkey_custom_category_id"];
+			$resultObj["customCats"][]= $row["fkey_custom_category_id"];
 		}
-/*
-		$sql = <<<SQL
-SELECT keyword FROM keyword, wfs_featuretype_keyword 
-WHERE keyword_id = fkey_keyword_id AND fkey_featuretype_id = $featuretypeId
-SQL;
-		$res = db_query($sql);
-
-		$resultObj["featuretype_keyword"] = array();
-		while ($row = db_fetch_assoc($res)) {
-			$resultObj["featuretype_keyword"][]= $row["keyword"];
-		}
-
+		
 		$ajaxResponse->setResult($resultObj);
 		$ajaxResponse->setSuccess(true);
 		break;
-	case "getFeaturetypeByWfs" :
-		$wfsId = $ajaxResponse->getParameter("id");
-//		getWms($wmsId);
-
-		$sql = <<<SQL
-	
-SELECT featuretype_id, featuretype_name, featuretype_title, featuretype_abstract 
-FROM wfs_featuretype WHERE fkey_wfs_id = $wfsId ORDER BY featuretype_id;
-
-SQL;
-		$res = db_query($sql);
-
-		$rows = array();
-		while ($row = db_fetch_assoc($res)) {
-			$rows[] = $row;
-		}
-		$left = 1;
-
-		function createNode ($left, $right, $row) {
-			return array(
-				"left" => $left,
-				"right" => $right,
-				#"parent" => $row["layer_parent"] !== "" ? intval($row["layer_parent"]) : null,
-				#"pos" => intval($row["layer_pos"]),
-				"attr" => array (
-					"featuretype_id" => intval($row["featuretype_id"]),
-					"featuretype_name" => $row["featuretype_name"],
-					"featuretype_title" => $row["featuretype_title"],
-					"featuretype_abstract" => $row["featuretype_abstract"]
-				)
-			);
-		}
-
-		function addSubTree ($rows, $i, $left) {
-			$nodeArray = array();
-			$addNewNode = true;
-			for ($j = $i; $j < count($rows); $j++) {
-				$row = $rows[$j];
-				$pos = $j;
-				
-				// first node of subtree
-				if ($addNewNode) {
-					$nodeArray[]= createNode($left, null, $row);
-					$addNewNode = false;
-				}
-				else {
-					$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":
+		global $firephp;
 		$data = $ajaxResponse->getParameter("data");
 		
 		try {
@@ -268,120 +142,67 @@
 			$ajaxResponse->setMessage(_mb("Invalid WMC ID."));
 			$ajaxResponse->send();						
 		}
-		getWmc($wmcId);
-		//is that true for a wmc? control it
-		$wfsFactory = new UniversalWfsFactory();
-		$wfs = $wfsFactory->createFromDb($wfsId);
-		if (is_null($wfs)) {
+		$wmcFactory = new WmcFactory();
+		$wmc = $wmcFactory->createFromDb($wmcId);
+
+		if (is_null($wmc)) {
 			$ajaxResponse->setSuccess(false);
-			$ajaxResponse->setMessage(_mb("Invalid WFS ID."));
+			$ajaxResponse->setMessage(_mb("Invalid WMC ID."));
 			$ajaxResponse->send();	
 		}
 		
 		$columns = array(
-			"summary", 
-			"title",
+			"wmc_abstract", 
+			"wmc_title",
 			"wmc_keyword",
-			"wmc_md_topic_category_id",
-			"wmc_inspire_category_id",
-			"wmc_custom_category_id"
+			"isoTopicCats",
+			"inspireCats",
+			"customCats",
+			"public"
 		);
+		
 		foreach ($columns as $c) {
 			$value = $data->wmc->$c;
-			//if (!is_null($value)) {
-			//	$wmc->$c = $value;
-			//}
-			if ($c === "summary") {
-				$value = $data->wmc_abstract;
-			}
-			elseif ($c === "title") {
-				$value = $data->wmc_title;
-			}
-			else {
-				$value = $data->$c;
-			}
 			if ($c === "wmc_keyword") {
-						$wmc->$c = explode(",", $value);
-						foreach ($wmc->$c as &$val) {
-							$val = trim($val);
-						}
+				$wmc->$c = explode(",", $value);
+				foreach ($wmc->$c as &$val) {
+					$val = trim($val);
+				}
+				if(!$value) {
+					$wmc->$c = array();
+				}
+			}
+			elseif ($c === "isoTopicCats" 
+				|| $c === "inspireCats"
+				|| $c === "customCats"
+			) {
+				if (!is_array($value)) {
+					if(!$value) {
+						$wmc->$c = array();
 					}
-					elseif ($c === "wmc_md_topic_category_id" 
-						|| $c === "wmc_inspire_category_id"
-						|| $c === "wmc_custom_category_id"
-					) {
-						if (!is_array($value)) {
-							$wmc->$c = array($value);
-						}
-						else {
-							$wmc->$c = $value;
-						}
-					}
 					else {
-						if (!is_null($value)) {
-							$wmc->$c = $value;
-						}
+						$wmc->$c = array($value);
 					}
-		}
-		
-/*		try {
-			$featuretypeId = intval($data->featuretype->featuretype_id);
-		}
-		catch (Exception $e) {
-		}*/
-
-/*		if ($featuretypeId) {
-			$featuretype = $wfs->findFeatureTypeById($featuretypeId);
-			if (!is_null($featuretype)) {
-				
-				$columns = array(
-					"summary", 
-					"title",
-					"featuretype_keyword",
-					"featuretype_md_topic_category_id",
-					"featuretype_inspire_category_id",
-					"featuretype_custom_category_id"
-				);			
-	
-				foreach ($columns as $c) {
-					if ($c === "summary") {
-						$value = $data->featuretype->featuretype_abstract;
-					}
-					elseif ($c === "title") {
-						$value = $data->featuretype->featuretype_title;
-					}
-					else {
-						$value = $data->featuretype->$c;
-					}	
-					if ($c === "featuretype_keyword") {
-						$featuretype->$c = explode(",", $value);
-						foreach ($featuretype->$c as &$val) {
-							$val = trim($val);
-						}
-					}
-					elseif ($c === "featuretype_md_topic_category_id" 
-						|| $c === "featuretype_inspire_category_id"
-						|| $c === "featuretype_custom_category_id"
-					) {
-						if (!is_array($value)) {
-							$featuretype->$c = array($value);
-						}
-						else {
-							$featuretype->$c = $value;
-						}
-					}
-					else {
-						if (!is_null($value)) {
-							$featuretype->$c = $value;
-						}
-					}
 				}
+				else {
+					$wmc->$c = $value;
+				}
 			}
-		}*/
-
-		$wmc->update();
-
+			elseif ($c === "public") {
+				$public = $value == "on"  ? true : false;
+				$wmc->setPublic($public);
+			}
+			else {
+				if (!is_null($value)) {
+					$wmc->$c = $value;
+				}
+			}
+		}
 		
+		//$firephp->log($wmc->public);
+		$overwrite = 1;
+		$wmc->insert($overwrite);
+		
 		$ajaxResponse->setMessage("Updated WMC metadata for ID " . $wmcId);
 		$ajaxResponse->setSuccess(true);		
 		

Added: trunk/mapbender/http/plugins/mb_metadata_wmc_showOriginal.html
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wmc_showOriginal.html	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_metadata_wmc_showOriginal.html	2010-11-24 12:11:35 UTC (rev 7151)
@@ -0,0 +1,16 @@
+<fieldset class="ui-widget">
+
+	<legend>Original Service Level Metadata: </legend>
+	<p>
+		<label for="original_wmc_title">WMC Title (OWS):</label>
+		<input readonly name="original_wmc_title" id="original_wmc_title" class="required"/>
+	</p>
+	<p>
+    	<label for="original_wmc_abstract">WMC Abstract (OWS):</label>
+    	<input readonly name="original_wmc_abstract" id="original_wmc_abstract"/>
+	</p>
+	<p>
+		<label for="original_wmc_keyword">WMC Keywords (OWS):</label>
+    	<input readonly name="original_wmc_keyword" id="original_wmc_keyword"/>
+	</p>
+</fieldset>

Added: trunk/mapbender/http/plugins/mb_metadata_wmc_showOriginal.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wmc_showOriginal.js	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_metadata_wmc_showOriginal.js	2010-11-24 12:11:35 UTC (rev 7151)
@@ -0,0 +1,144 @@
+var $showOriginalDiv = $(this);
+var $originalMetadataForm = $("<form></form>").appendTo($showOriginalDiv);
+var $originalMetadataPopup = $("<div></div>");
+
+var ShowOriginalApi = function() {
+	var that = this;
+	var featuretypeName;
+	
+	this.events = {
+		replaceMetadata : new Mapbender.Event()
+	};
+	
+	var replaceMetadata = function (clickedAttr, attrVal) {
+		var returnObj = {};
+		returnObj[clickedAttr] = attrVal;
+		that.events.replaceMetadata.trigger({
+			data : returnObj
+		});
+		//remove background-color of replaced attr
+		$("#" + clickedAttr).removeClass("differentFromOriginal");
+	};
+	
+	var replaceAllMetadata = function (obj) {
+		var returnObj = {};
+		for(metadataAttr in obj) {
+			var attr = metadataAttr.split("original_");
+			returnObj[attr[1]] = obj[metadataAttr];
+		}	
+		that.events.replaceMetadata.trigger({
+			data : returnObj
+		});
+		//remove background-color of all replaced attr
+		$(".differentFromOriginal").removeClass("differentFromOriginal");
+	};
+	
+	var mergeOriginalWithCurrentMetadata = function (originalObj,currentObj) {
+		var differenceFound = false;
+		for(metadataAttr in currentObj) {
+			var origMetadataAttr = "original_" + metadataAttr;
+			
+			//some attr are excluded from check
+			if(metadataAttr != "wmc_id") {
+				if(!originalObj[origMetadataAttr]) {
+					originalObj[origMetadataAttr] = "";
+				}
+				
+				if(currentObj[metadataAttr] == originalObj[origMetadataAttr]) {
+					$("#" + origMetadataAttr).parent().hide();
+				}
+				else if(currentObj[metadataAttr] == "" && originalObj[origMetadataAttr] == "") {
+					$("#" + origMetadataAttr).parent().hide();
+				}
+				else {
+					//mark all attr in main form which are different
+					$("#" + metadataAttr).addClass("differentFromOriginal");
+					(function () {
+						var clickedAttr = metadataAttr;
+						var attrValue = $("#" + origMetadataAttr).val();
+						$("#" + origMetadataAttr).parent().append("<input type='button' value='Replace' id='replaceRecord_"+origMetadataAttr+"' />");
+						$("#replaceRecord_" +origMetadataAttr).addClass("ui-state-default ui-corner-all");
+						$("#replaceRecord_" +origMetadataAttr).bind("click", function () {
+							replaceMetadata(clickedAttr, attrValue);
+						});
+					})();
+					var differenceFound = true;
+				}
+			}
+		}
+		if(differenceFound === false) {
+			$originalMetadataPopup.dialog("close");
+			var noDifferenceMsg = "No difference found.";
+			$("<div>" + noDifferenceMsg + "</div>").dialog(
+				{
+					title : "Show original metadata", 
+					bgiframe: true,
+					autoOpen: true,
+					modal: false,
+					position : [600, 75],
+					buttons: {
+						"ok": function(){
+							$(this).dialog('close').remove();
+						}
+					}
+				}
+			);
+		}
+	};
+	
+	var getOriginalMetadata = function (currentId, currentData) {
+		// get original metadata from server
+		var req = new Mapbender.Ajax.Request({
+			url: "../plugins/mb_original_metadata_wmc_server.php",
+			method: "getOriginalMetadata",
+			parameters: {
+				"id": currentId
+			},
+			callback: function (obj, result, message) {
+				if (!result) {
+					return;
+				}
+				fillForm(obj);
+				mergeOriginalWithCurrentMetadata(obj,currentData);
+			}
+		});
+		req.send();	
+	};
+	
+	var fillForm = function (obj) {
+		$originalMetadataForm.easyform("reset");
+		$originalMetadataForm.easyform("fill", obj);
+		$originalMetadataPopup.append($originalMetadataForm);
+		$originalMetadataPopup.dialog({
+			title : "Show original metadata", 
+			autoOpen : false, 
+			draggable : true,
+			modal : true,
+			width : 600,
+			position : [600, 75],
+			buttons: {
+				"close": function() {
+					$(this).dialog('close');
+				},
+				"replace all metadata": function() {
+					replaceAllMetadata(obj);
+					$(this).dialog('close');
+				}
+			},
+			close: function() {
+				$(".differentFromOriginal").removeClass("differentFromOriginal");
+			}
+		});
+		$originalMetadataPopup.dialog("open");
+		
+	};
+	
+	this.init = function (obj) {
+		$originalMetadataPopup.dialog("close");
+		$originalMetadataForm.load("../plugins/mb_metadata_wmc_showOriginal.html", function () {
+			getOriginalMetadata(obj.wmcId, obj.wmcData);
+		});
+	}
+};
+
+$showOriginalDiv.mapbender(new ShowOriginalApi());
\ No newline at end of file

Added: trunk/mapbender/http/plugins/mb_metadata_wmc_submit.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wmc_submit.js	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_metadata_wmc_submit.js	2010-11-24 12:11:35 UTC (rev 7151)
@@ -0,0 +1,67 @@
+var $submit = $(this);
+
+var MetadataSubmitApi = function () {
+	var that = this;
+	var formData = {};
+	
+	var serializeCallback = function (data) {
+		if (data === null) {
+			formData = null;
+			return;
+		}
+		if (formData !== null) {
+			formData = $.extend(formData, data);
+		}
+	};
+	
+	this.enable = function () {
+		$submit.find("input[type='submit']").removeAttr("disabled");
+	};
+	
+	this.submit = function () {
+		formData = {};
+		this.events.submit.trigger({
+			callback: serializeCallback
+		});
+
+		if (formData === null) {
+			return;
+		}
+
+		// get metadata from server
+		var req = new Mapbender.Ajax.Request({
+			url: "../plugins/mb_metadata_wmc_server.php",
+			method: "save",
+			parameters: {
+				"data": formData
+			},
+			callback: function (obj, result, message) {
+				if (!result) {
+					$("<div></div>").text(!message ? "An error occured." : message).dialog({
+						modal: true
+					});
+					return;
+				}
+				$("<div></div>").text(message).dialog({
+					modal: true
+				});
+
+			}
+		});
+		req.send();			
+	};
+	
+	this.events = {
+		submit: new Mapbender.Event()
+	};
+	
+	var init = function () {
+		$submit.find("input[type='submit']").bind("click", function () {
+			that.submit();
+		});
+	};
+
+	init();
+};
+
+$submit.mapbender(new MetadataSubmitApi());

Added: trunk/mapbender/http/plugins/mb_original_metadata_wmc_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_original_metadata_wmc_server.php	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_original_metadata_wmc_server.php	2010-11-24 12:11:35 UTC (rev 7151)
@@ -0,0 +1,80 @@
+<?php
+require_once dirname(__FILE__) . "/../../core/globalSettings.php";
+require_once dirname(__FILE__) . "/../classes/class_user.php";
+require_once dirname(__FILE__) . "/../classes/class_wmc.php";
+
+$ajaxResponse = new AjaxResponse($_POST);
+
+function abort ($message) {
+	global $ajaxResponse;
+	$ajaxResponse->setSuccess(false);
+	$ajaxResponse->setMessage($message);
+	$ajaxResponse->send();
+	die;
+};
+
+function getWmcMetadataFromXml($wmcDoc) {
+	$xmlDoc = new DOMDocument();
+	$xmlDoc->encoding = CHARSET;
+	$xmlDoc->preserveWhiteSpace = false;
+	$xmlDoc->loadXML($wmcDoc);
+	
+	//define default resultObj
+	$resultObj = array(
+		"original_wmc_title" => "",
+		"original_wmc_abstract" => "",
+		"original_wmc_keyword" => ""
+	);
+	
+	$general_node = $xmlDoc->getElementsByTagName('General'); 
+	foreach ($general_node as $node) {
+		$children = $node->childNodes;
+		foreach($children as $child) {
+			if (strtoupper($child->nodeName) == "TITLE"){
+				$resultObj["original_wmc_title"] = $child->nodeValue;
+			}
+			if (strtoupper($child->nodeName) == "ABSTRACT"){
+				$resultObj["original_wmc_abstract"] = $child->nodeValue;
+			}
+
+			//childnode KeywordList	
+			if (strtoupper($child->nodeName) == "WMC:KEYWORDLIST"){
+				$keywords_list = $child->childNodes;
+				$keywords = array();
+				foreach ($keywords_list as $keywordlist_child_node) {																		
+					$keyword = $keywordlist_child_node->nodeValue;						
+					array_push($keywords, $keyword);
+				}
+				$resultObj["original_wmc_keyword"] = implode(", ", $keywords); 		
+			}
+		}
+	}
+	return $resultObj;
+}
+
+switch ($ajaxResponse->getMethod()) {
+	case "getOriginalMetadata" :
+		$wmcId = $ajaxResponse->getParameter("id");
+		$sql = <<<SQL
+	
+SELECT wmc FROM mb_user_wmc WHERE wmc_serial_id = $wmcId;
+
+SQL;
+		$res = db_query($sql);
+		$row = db_fetch_array($res);
+		$wmc_doc = $row["wmc"];
+		
+		$resultObj = getWmcMetadataFromXml($wmc_doc);
+		
+		$ajaxResponse->setResult($resultObj);
+		$ajaxResponse->setSuccess(true);
+		
+		break;
+	default: 
+		$ajaxResponse->setSuccess(false);
+		$ajaxResponse->setMessage(_mb("An unknown error occured."));
+		break;
+}
+
+$ajaxResponse->send();
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list