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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue May 17 06:02:55 EDT 2011


Author: armin11
Date: 2011-05-17 03:02:55 -0700 (Tue, 17 May 2011)
New Revision: 7817

Added:
   trunk/mapbender/http/plugins/mb_metadata_xml_import.js
Modified:
   trunk/mapbender/http/plugins/mb_metadata_addon.php
   trunk/mapbender/http/plugins/mb_metadata_layer.js
   trunk/mapbender/http/plugins/mb_metadata_server.php
   trunk/mapbender/http/plugins/mb_metadata_showMetadataAddon.js
Log:
Possibility to upload a metadata record to the mapbender mb_metadata table

Modified: trunk/mapbender/http/plugins/mb_metadata_addon.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_addon.php	2011-05-17 10:02:34 UTC (rev 7816)
+++ trunk/mapbender/http/plugins/mb_metadata_addon.php	2011-05-17 10:02:55 UTC (rev 7817)
@@ -6,8 +6,9 @@
 	<fieldset id="addonChooser" name="addonChooser" style="display: none">
 		<legend><?php echo _mb("Choose kind of coupled metadata");?></legend>
 		<p>
-			<table><tr><td><img src='../img/osgeo_graphics/geosilk/link.png' title='linkage' onclick='$("#addonChooser").css("display","none");$("#link_editor").css("display","block");$("#kindOfMetadataAddOn").attr("value","link");' /></td><td><?php echo _mb("Add URL to existing Metadataset");?></td></tr>
-			<tr><td><img src='../img/gnome/edit-select-all.png' title='metadata'  onclick='$("#addonChooser").css("display","none");$("#simple_metadata_editor").css("display","block");$("#kindOfMetadataAddOn").attr("value","metadataset");' /></td><td><?php echo _mb("Add a simple metadata record which is mostly generated from given layer information");?></td></tr>
+			<table><tr><td><img src='../img/osgeo_graphics/geosilk/link.png' title='linkage' onclick='$("#addonChooser").css("display","none");$("#link_editor").css("display","block");$("#kindOfMetadataAddOn").attr("value","link");' /></td><td><?php echo _mb("Add URL to existing Metadataset");?><img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("Here someone can add a url to an existing metadata record, which is available in www. The record can either be harvested and pushed to the own catalogue service or it is only used as a link. This links are pushed into the service metadata record and the new capabilities document.");?>'}" src="../img/questionmark.png" alt="" /></td></tr>
+			<tr><td><img src='../img/gnome/edit-select-all.png' title='metadata'  onclick='$("#addonChooser").css("display","none");$("#simple_metadata_editor").css("display","block");$("#kindOfMetadataAddOn").attr("value","metadataset");' /></td><td><?php echo _mb("Add a simple metadata record which is mostly generated from given layer information");?><img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("With this option someone can generate a very simple metadata record for the data which is distributed thru the wms layer. The record fulfills only the INSPIRE Metadata Regulation! Most of the needed data is pulled from the service, layer and group information of the owner of the service. The metadate will be created on the fly. It is not stored in the database!");?>'}" src="../img/questionmark.png" alt="" /></td></tr>
+			<tr><td><img src='../img/button_blue_red/up.png' id='uploadImage' title='upload' /></td><td><?php echo _mb("Add a simple metadata record from a local file");?><img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("With this option someone can upload an existing metadata record and couple it to the layer. The uploaded data is pushed to the catalogue and will be available for searching. The uploaded data is not fully controlled and validated. It cannot be edited but must be replace it with a new record if needed!");?>'}" src="../img/questionmark.png" alt="" /></td></tr>
 			</table>
 		</p>
 	</fieldset>
@@ -21,6 +22,11 @@
 		</p>
 		
 	</fieldset>
+	<!--fieldset for upload metadata form-->
+	<fieldset id="metadata_upload" name="metadata_upload" type="hidden" style="display: none">
+		<legend><?php echo _mb("Metadata upload");?></legend>
+		<input name="metadatafile" id="metadatafile" type="file"/>
+	</fieldset>
 	<!--fieldset for metadata form-->
 	<fieldset id="simple_metadata_editor" name="simple_metadata_editor" type="hidden"  style="display: none">
 		<legend><?php echo _mb("Simple metadata editor");?></legend>

Modified: trunk/mapbender/http/plugins/mb_metadata_layer.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_layer.js	2011-05-17 10:02:34 UTC (rev 7816)
+++ trunk/mapbender/http/plugins/mb_metadata_layer.js	2011-05-17 10:02:55 UTC (rev 7817)
@@ -97,7 +97,7 @@
 		});
 		req.send();		
 	};
-
+	//function generate updated metadataUrl entries TODO: this function is defined in mb_metadata_layer.js before but it cannot be called - maybe s.th. have to be changed
 	this.fillMetadataURLs = function (obj) {
 		layerId = obj.layer_id;
 		//for size of md_metadata records:
@@ -108,6 +108,9 @@
 			if (obj.md_metadata.origin[i] == "external") {
 				$("<tr class='metadataEntry'><td>"+obj.md_metadata.metadata_id[i]+"</td><td><img src='../img/osgeo_graphics/geosilk/link.png' title='linkage'/><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"' target='_blank'>"+obj.md_metadata.uuid[i]+"</a></td><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"&validate=true' target='_blank'>validate</a></td><td><img  class='' title='edit' src='../img/pencil.png' onclick='initMetadataAddon("+obj.md_metadata.metadata_id[i]+","+layerId+",false);return false;'/></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteAddedMetadata("+obj.md_metadata.metadata_id[i]+","+layerId+");return false;'/></td></tr>").appendTo($("#metadataTable"));
 			}
+			if (obj.md_metadata.origin[i] == "upload") {
+				$("<tr class='metadataEntry'><td>"+obj.md_metadata.metadata_id[i]+"</td><td><img src='../img/button_blue_red/up.png' title='uploaded data'/><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"' target='_blank'>"+obj.md_metadata.uuid[i]+"</a></td><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"&validate=true' target='_blank'>validate</a></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteAddedMetadata("+obj.md_metadata.metadata_id[i]+","+layerId+");return false;'/></td></tr>").appendTo($("#metadataTable"));
+			}
 			if (obj.md_metadata.origin[i] == "metador") {
 				$("<tr class='metadataEntry'><td>"+obj.md_metadata.metadata_id[i]+"</td><td><img src='../img/gnome/edit-select-all.png' title='metadata'/><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"' target='_blank'>"+obj.md_metadata.uuid[i]+"</a></td><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"&validate=true' target='_blank'>validate</a></td><td><img  class='' title='edit' src='../img/pencil.png' onclick='initMetadataAddon("+obj.md_metadata.metadata_id[i]+","+layerId+",false);return false;'/></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteAddedMetadata("+obj.md_metadata.metadata_id[i]+","+layerId+");return false;'/></td></tr>").appendTo($("#metadataTable"));
 			}
@@ -115,7 +118,6 @@
 		$("<img class='metadataEntry' title='new' src='../img/add.png' onclick='initMetadataAddon("+obj.md_metadata.metadata_id[i]+","+layerId+",true);return false;'/>").appendTo($("#metadataTable"));
 	}
 
-
 	this.enableResetButton = function () {
 		$("#resetIsoTopicCats").click(function () {
 			$("#layer_md_topic_category_id option").removeAttr("selected");

Modified: trunk/mapbender/http/plugins/mb_metadata_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_server.php	2011-05-17 10:02:34 UTC (rev 7816)
+++ trunk/mapbender/http/plugins/mb_metadata_server.php	2011-05-17 10:02:55 UTC (rev 7817)
@@ -11,7 +11,7 @@
 	$ajaxResponse->setSuccess(false);
 	$ajaxResponse->setMessage($message);
 	$ajaxResponse->send();
-	die;
+	die();
 };
 
 function getWms ($wmsId = null) {
@@ -282,7 +282,7 @@
 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')
+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();
@@ -691,6 +691,8 @@
 		}
 		if (isset($data->export2csw)) {
 			$export2csw = $data->export2csw;
+		} else {
+			$export2csw = 'f';
 		}
 		if (isset($data->title)) {
 			$title = $data->title;
@@ -733,20 +735,24 @@
 		}
 		$randomid = new Uuid();
 		//Check if origin is external and export2csw is activated!
-		if ($origin == 'external' && $export2csw = 't' ) {
+		if ($origin == 'external' && $export2csw == 't' ) {
 			//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($link);
-			$metaData = $metadataConnector->file;
+			$metadataConnector = new connector();
+			$metadataConnector->set("timeOut", "5");
+			$metaData = $metadataConnector->load($link);
+			if (!$metaData) {
+    				$ajaxResponse->setSuccess(false);
+				$ajaxResponse->setMessage("Could not load data via resolving link location!");
+				break;
+			}
+			//$metaData = $metadataConnector->file;
 			//parse metadata
 			try {
 				$iso19139Xml =  new SimpleXMLElement($metaData);
-				if ($iso19139Xml == false) {
-					throw new Exception('Cannot parse Metadata XML!');
-				}
 			}
 			catch (Exception $e) {
-    				$e = new mb_exception($e->getMessage());
+				abort(_mb("Parsing ISO19139 XML failed!"));
 			}
 			if ($iso19139Xml != false) {
 				//get elements for database from xml by using xpath
@@ -793,7 +799,6 @@
 				//fees
 				//"constraints"	
 				//fill database with elements:
-				$dbInsertFailed = false;
 
 				$sql = <<<SQL
 
@@ -807,18 +812,13 @@
 					$res = db_prep_query($sql,$v,$t);
 				}
 				catch (Exception $e){
-					$ajaxResponse->setSuccess(false);
-					$ajaxResponse->setMessage(_mb("Could not insert metadata object into database!"));	
-					$dbInsertFailed = true;	
-					$e = new mb_exception($dbInsertFailed);
+					abort(_mb("Insert of harvested metadata into database failed!"));
 				}
 			
 			} else {
 				//give back error message - cause parsing has problems
 			}
-		} else {
-
-			$dbInsertFailed = false;
+		} else { //fill only links into db do not ry to load data
 			$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) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, now(), $16)
@@ -831,57 +831,46 @@
 				$res = db_prep_query($sql,$v,$t);
 			}
 			catch (Exception $e){
-				$ajaxResponse->setSuccess(false);
-				$ajaxResponse->setMessage(_mb("Could not insert metadata object into database!"));	
-				$dbInsertFailed = true;	
-				$e = new mb_exception($dbInsertFailed);
+				abort(_mb("Insert of link into database failed!"));
 			}
 		}
 		//set relation into relation table
 		//get metadata_id of record which have been inserted before
-		if ($dbInsertFailed != true) {	
-			$sql = <<<SQL
+		$sql = <<<SQL
 
-	SELECT metadata_id FROM mb_metadata WHERE randomid = $1
+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){
-				$ajaxResponse->setSuccess(false);
-				$ajaxResponse->setMessage(_mb("Cannot get metadata record with following uuid from database: ".$uuid));
-				$dbInsertFailed = true;	
-			}
-			if ($dbInsertFailed != true) {
-				if ($res) {
-					$row = db_fetch_assoc($res);
-					$metadata_id = $row['metadata_id'];
-				}
-				$sql = <<<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)
+		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){
-					$ajaxResponse->setSuccess(false);
-					$ajaxResponse->setMessage(_mb("Cannot write relation between ows and metadata to database!"));
-					$dbInsertFailed = true;
-				}
-				if ($dbInsertFailed != true) {	
-					$ajaxResponse->setMessage("Metadata object inserted into md_metadata!");
-					$ajaxResponse->setSuccess(true);
-				}				
-			}
+		$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");
@@ -904,8 +893,157 @@
 		$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!"));
+		}
+		
+		try {	
+			$iso19139Xml =  new SimpleXMLElement($metaData);
+		}
+		catch (Exception $e) {
+			abort(_mb("Parsing ISO19139 XML failed!"));
+		}
+		//get elements for database from xml by using xpath
+		//uuid
+		$uuid = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:fileIdentifier/gco:CharacterString');
+		//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');
+		//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
+		$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_notice("plugins/mb_metadata_server.php: code: ".$code[0]);
+		$e = new mb_notice("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_notice("class_wms.php: datasetid: ".$datasetid);
+		} else {		
+			$datasetid = 'undefined';# in sense of INSPIRE TODO control MD_Identifier too!
+			$e = new mb_notice("class_wms.php: datasetid: ".$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."));

Modified: trunk/mapbender/http/plugins/mb_metadata_showMetadataAddon.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_showMetadataAddon.js	2011-05-17 10:02:34 UTC (rev 7816)
+++ trunk/mapbender/http/plugins/mb_metadata_showMetadataAddon.js	2011-05-17 10:02:55 UTC (rev 7817)
@@ -1,6 +1,9 @@
 var $showMetadataAddonDiv = $(this);
 var $metadataAddonForm = $("<form></form>").appendTo($showMetadataAddonDiv);
+//var $metadataUploadForm = $("<form></form>").appendTo($showMetadataAddonDiv);
+
 var $metadataAddonPopup = $("<div></div>");
+var $metadataUploadPopup = $("<div></div>");
 
 var ShowMetadataAddonApi = function() {
 	var that = this;
@@ -46,7 +49,7 @@
   					case "capabilities":
 						$("#metadataUrlEditor").css("display","block");
     						$("#simple_metadata_editor").css("display","block");
-    						break;
+    						break;			
 					default:
     						break;
 				}
@@ -69,9 +72,6 @@
 				"data": data
 			},
 			callback: function (obj, result, message) {
-				if (!result) {
-					return;
-				}
 				$("<div></div>").text(message).dialog({
 					modal: true
 				});
@@ -81,6 +81,8 @@
 		});
 		req.send();	
 	}
+
+
 	this.updateAddedMetadata = function(metadataId, layerId, data){
 		// push metadata from server
 		var req = new Mapbender.Ajax.Request({
@@ -137,6 +139,9 @@
 			if (obj.md_metadata.origin[i] == "external") {
 				$("<tr class='metadataEntry'><td>"+obj.md_metadata.metadata_id[i]+"</td><td><img src='../img/osgeo_graphics/geosilk/link.png' title='linkage'/><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"' target='_blank'>"+obj.md_metadata.uuid[i]+"</a></td><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"&validate=true' target='_blank'>validate</a></td><td><img  class='' title='edit' src='../img/pencil.png' onclick='initMetadataAddon("+obj.md_metadata.metadata_id[i]+","+layerId+",false);return false;'/></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteAddedMetadata("+obj.md_metadata.metadata_id[i]+","+layerId+");return false;'/></td></tr>").appendTo($("#metadataTable"));
 			}
+			if (obj.md_metadata.origin[i] == "upload") {
+				$("<tr class='metadataEntry'><td>"+obj.md_metadata.metadata_id[i]+"</td><td><img src='../img/button_blue_red/up.png' title='uploaded data'/><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"' target='_blank'>"+obj.md_metadata.uuid[i]+"</a></td><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"&validate=true' target='_blank'>validate</a></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteAddedMetadata("+obj.md_metadata.metadata_id[i]+","+layerId+");return false;'/></td></tr>").appendTo($("#metadataTable"));
+			}
 			if (obj.md_metadata.origin[i] == "metador") {
 				$("<tr class='metadataEntry'><td>"+obj.md_metadata.metadata_id[i]+"</td><td><img src='../img/gnome/edit-select-all.png' title='metadata'/><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"' target='_blank'>"+obj.md_metadata.uuid[i]+"</a></td><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"&validate=true' target='_blank'>validate</a></td><td><img  class='' title='edit' src='../img/pencil.png' onclick='initMetadataAddon("+obj.md_metadata.metadata_id[i]+","+layerId+",false);return false;'/></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteAddedMetadata("+obj.md_metadata.metadata_id[i]+","+layerId+");return false;'/></td></tr>").appendTo($("#metadataTable"));
 			}
@@ -191,6 +196,11 @@
 					//$("#myform").validate({
 					// ignore: ".ignore"
 					//})
+					if ($("#addonChooser").css("display") == "block") {
+						//don't allow saving but do something else
+						return;
+						
+					}
 					if ($("#simple_metadata_editor").css("display") == "block") {
 						//validate form before send it!
 						if ($metadataAddonForm.valid() != true) {
@@ -208,18 +218,27 @@
 				}
 			},
 			close: function() {
+				//what to do when the dialog is closed
+				
 			}
 		});
 		$metadataAddonPopup.dialog("open");
 	};
 	
+	initUploadForm = function (layerId) {
+		$metadataAddonPopup.dialog("close");
+		initXmlImport(layerId);
+		that.fillLayerForm(layerId);
+	}
+
+
 	this.init = function (metadataId, layerId, isNew) {
 		$metadataAddonPopup.dialog("close");
 		$metadataAddonForm.load("../plugins/mb_metadata_addon.php", function () {
 			//push infos to help dialogs
 			$metadataAddonForm.find(".help-dialog").helpDialog();
 			//initialize datepicker
-			$('.hasdatepicker').datepicker({dateFormat:'yy-mm-dd', buttonImageOnly: true, changeYear: true,
+			$('.hasdatepicker').datepicker({dateFormat:'yy-mm-dd', yearRange: '1900:2050', buttonImageOnly: true, changeYear: true,
 constraintInput: true});
 			//first get json
 			if (!isNew) {
@@ -229,9 +248,13 @@
 				//show chooser
 				$("#metadataUrlEditor").css("display","block"); 
 				$("#addonChooser").css("display","block");
+				$("#uploadImage").attr('onclick', 'initUploadForm('+layerId+')');
 			}
 			that.showForm(metadataId, layerId, isNew);
 		});
+		//upload form
+		
+		//$metadataUploadPopup.append($metadataUploadForm);
 	}
 	initMetadataAddon = function(metadataId, layerId, isNew) {
 		//close old window and load form

Added: trunk/mapbender/http/plugins/mb_metadata_xml_import.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_xml_import.js	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_metadata_xml_import.js	2011-05-17 10:02:55 UTC (rev 7817)
@@ -0,0 +1,135 @@
+var $xmlImport = $(this);
+var importXmlLayerId;
+
+var XmlImportApi = function () {
+	var that = this;
+	var type;
+	
+	this.events = {
+		"uploadComplete" : new Mapbender.Event()
+	};
+	
+	this.events.uploadComplete.register(function () {
+		$xmlImport.dialog("close");
+	});
+	
+
+	
+	var importUploadedFile = function(filename, layerId, callback){
+		var req = new Mapbender.Ajax.Request({
+			url: "../plugins/mb_metadata_server.php",
+			method: "importLayerXmlAddon",
+			parameters: {
+				filename: filename,
+				layerId: layerId
+			},
+			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);
+				$xmlImport.dialog("close");
+				that.fillLayerForm(layerId);
+				if ($.isFunction(callback)) {
+					callback(obj.id);
+				}
+			}
+		});
+		req.send();
+	};
+
+	//function to fill layer form with changed metadata entries TODO: this function is defined in mb_metadata_layer.js before but it cannot be called - maybe s.th. have to be changed
+	this.fillLayerForm = function (layerId) {
+		// get metadata from server
+		var req = new Mapbender.Ajax.Request({
+			url: "../plugins/mb_metadata_server.php",
+			method: "getLayerMetadata",
+			parameters: {
+				"id": layerId
+			},
+			callback: function (obj, result, message) {
+				if (!result) {
+					return;
+				}
+				//delete metadataURL entries
+				$('.metadataEntry').remove();
+				//fill MetadataURLs into metadata_selectbox_id
+				that.fillMetadataURLs(obj);
+			}
+		});
+		req.send();		
+	};
+
+	//function generate updated metadataUrl entries TODO: this function is defined in mb_metadata_layer.js before but it cannot be called - maybe s.th. have to be changed
+	this.fillMetadataURLs = function (obj) {
+		layerId = obj.layer_id;
+		//for size of md_metadata records:
+		for (i=0;i<obj.md_metadata.metadata_id.length;i++) {
+			if (obj.md_metadata.origin[i] == "capabilities") {
+				$("<tr class='metadataEntry'><td>"+obj.md_metadata.metadata_id[i]+"</td><td><img src='../img/osgeo_graphics/geosilk/server_map.png' title='capabilities'/></td><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"' target='_blank'>"+obj.md_metadata.uuid[i]+"</a></td><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"&validate=true' target='_blank'>validate</a></td><td></td></tr>").appendTo($("#metadataTable"));
+			}
+			if (obj.md_metadata.origin[i] == "external") {
+				$("<tr class='metadataEntry'><td>"+obj.md_metadata.metadata_id[i]+"</td><td><img src='../img/osgeo_graphics/geosilk/link.png' title='linkage'/><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"' target='_blank'>"+obj.md_metadata.uuid[i]+"</a></td><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"&validate=true' target='_blank'>validate</a></td><td><img  class='' title='edit' src='../img/pencil.png' onclick='initMetadataAddon("+obj.md_metadata.metadata_id[i]+","+layerId+",false);return false;'/></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteAddedMetadata("+obj.md_metadata.metadata_id[i]+","+layerId+");return false;'/></td></tr>").appendTo($("#metadataTable"));
+			}
+			if (obj.md_metadata.origin[i] == "upload") {
+				$("<tr class='metadataEntry'><td>"+obj.md_metadata.metadata_id[i]+"</td><td><img src='../img/button_blue_red/up.png' title='uploaded data'/><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"' target='_blank'>"+obj.md_metadata.uuid[i]+"</a></td><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"&validate=true' target='_blank'>validate</a></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteAddedMetadata("+obj.md_metadata.metadata_id[i]+","+layerId+");return false;'/></td></tr>").appendTo($("#metadataTable"));
+			}
+			if (obj.md_metadata.origin[i] == "metador") {
+				$("<tr class='metadataEntry'><td>"+obj.md_metadata.metadata_id[i]+"</td><td><img src='../img/gnome/edit-select-all.png' title='metadata'/><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"' target='_blank'>"+obj.md_metadata.uuid[i]+"</a></td><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"&validate=true' target='_blank'>validate</a></td><td><img  class='' title='edit' src='../img/pencil.png' onclick='initMetadataAddon("+obj.md_metadata.metadata_id[i]+","+layerId+",false);return false;'/></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteAddedMetadata("+obj.md_metadata.metadata_id[i]+","+layerId+");return false;'/></td></tr>").appendTo($("#metadataTable"));
+			}
+		}
+		$("<img class='metadataEntry' title='new' src='../img/add.png' onclick='initMetadataAddon("+obj.md_metadata.metadata_id[i]+","+layerId+",true);return false;'/>").appendTo($("#metadataTable"));
+	}
+
+	
+	$xmlImport.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.importXmlLayerId, function (id) {
+		        that.events.uploadComplete.trigger({
+					"type": type,
+					"id": id
+				});
+			});
+	        
+    	}
+	}).dialog({
+		title: 'XML Import',
+		autoOpen: false,
+		modal: true,
+		width: 580
+	});
+
+
+	this.init = function (obj) {
+		type = obj.type;
+		$xmlImport.dialog("open");
+	};
+
+	initXmlImport = function (layerId) {
+		that.importXmlLayerId = layerId;
+		$xmlImport.dialog("open");
+		return true;
+	};
+	
+};
+
+$xmlImport.mapbender(new XmlImportApi());



More information about the Mapbender_commits mailing list