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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Jun 7 03:25:53 PDT 2016


Author: armin11
Date: 2016-06-07 03:25:53 -0700 (Tue, 07 Jun 2016)
New Revision: 9508

Modified:
   trunk/mapbender/http/plugins/mb_metadata_layer.js
   trunk/mapbender/http/plugins/mb_metadata_server.php
   trunk/mapbender/http/plugins/mb_metadata_showMetadataAddon.js
   trunk/mapbender/http/plugins/mb_metadata_xml_import.js
Log:
Code cleaning and possibility to overwrite uploaded metadata records. Only those elements are keept from the original record, that are ,managed by mapbenders metadata class!

Modified: trunk/mapbender/http/plugins/mb_metadata_layer.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_layer.js	2016-06-06 12:42:43 UTC (rev 9507)
+++ trunk/mapbender/http/plugins/mb_metadata_layer.js	2016-06-07 10:25:53 UTC (rev 9508)
@@ -78,9 +78,10 @@
         // get metadata from server
         var req = new Mapbender.Ajax.Request({
             url: "../plugins/mb_metadata_server.php",
-            method: "getLayerMetadata",
+            method: "getResourceMetadata",
             parameters: {
-                "id": layerId
+                "resourceId": layerId,
+		"resourceType": "layer"
             },
             callback: function(obj, result, message) {
                 if (!result) {
@@ -120,28 +121,28 @@
             }
             if (obj.md_metadata.origin[i] == "external") {
                 if (obj.md_metadata.internal[i] == 1) {
-                    $("<tr class='metadataEntry'><td>" + obj.md_metadata.metadata_id[i] + "</td><td><img src='../img/link-ilink.png' title='link to external 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='deleteInternalMetadataLinkage(" + obj.md_metadata.metadata_id[i] + "," + layerId + ");return false;'/></td></tr>").appendTo($("#metadataTable"));
+                    $("<tr class='metadataEntry'><td>" + obj.md_metadata.metadata_id[i] + "</td><td><img src='../img/link-ilink.png' title='link to external 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 + ",\"layer\",false);return false;'/></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteInternalMetadataLinkage(" + obj.md_metadata.metadata_id[i] + "," + layerId + ",\"layer\");return false;'/></td></tr>").appendTo($("#metadataTable"));
                 } else {
-                    $("<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"));
+                    $("<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 + ",\"layer\",false);return false;'/></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteAddedMetadata(" + obj.md_metadata.metadata_id[i] + "," + layerId + ",\"layer\");return false;'/></td></tr>").appendTo($("#metadataTable"));
                 }
             }
             if (obj.md_metadata.origin[i] == "upload") {
                 if (obj.md_metadata.internal[i] == 1) {
-                    $("<tr class='metadataEntry'><td>" + obj.md_metadata.metadata_id[i] + "</td><td><img src='../img/up-ilink.png' title='link to external 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='deleteInternalMetadataLinkage(" + obj.md_metadata.metadata_id[i] + "," + layerId + ");return false;'/></td></tr>").appendTo($("#metadataTable"));
+                    $("<tr class='metadataEntry'><td>" + obj.md_metadata.metadata_id[i] + "</td><td><img src='../img/up-ilink.png' title='link to external 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='edit' src='../img/pencil.png' onclick='initMetadataAddon(" + obj.md_metadata.metadata_id[i] + "," + layerId + ",\"layer\",false);return false;'/></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteInternalMetadataLinkage(" + obj.md_metadata.metadata_id[i] + "," + layerId + ",\"layer\");return false;'/></td></tr>").appendTo($("#metadataTable"));
                 } else {
-                    $("<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"));
+                    $("<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='edit' src='../img/pencil.png' onclick='initMetadataAddon(" + obj.md_metadata.metadata_id[i] + "," + layerId + ",\"layer\",false);return false;'/></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteAddedMetadata(" + obj.md_metadata.metadata_id[i] + "," + layerId + ",\"layer\");return false;'/></td></tr>").appendTo($("#metadataTable"));
                 }
             }
             if (obj.md_metadata.origin[i] == "metador") {
                 if (obj.md_metadata.internal[i] == 1) {
-                    $("<tr class='metadataEntry'><td>" + obj.md_metadata.metadata_id[i] + "</td><td><img src='../img/edit-select-all-ilink.png' title='link to external edited 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='deleteInternalMetadataLinkage(" + obj.md_metadata.metadata_id[i] + "," + layerId + ");return false;'/></td></tr>").appendTo($("#metadataTable"));
+                    $("<tr class='metadataEntry'><td>" + obj.md_metadata.metadata_id[i] + "</td><td><img src='../img/edit-select-all-ilink.png' title='link to external edited 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 + ",\"layer\",false);return false;'/></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteInternalMetadataLinkage(" + obj.md_metadata.metadata_id[i] + "," + layerId + ",\"layer\");return false;'/></td></tr>").appendTo($("#metadataTable"));
                 } else {
-                    $("<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"));
+                    $("<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 + ",\"layer\",false);return false;'/></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteAddedMetadata(" + obj.md_metadata.metadata_id[i] + "," + layerId + ",\"layer\");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"));
+        $("<img class='metadataEntry' title='new' src='../img/add.png' onclick='initMetadataAddon(" + obj.md_metadata.metadata_id[i] + "," + layerId + ",\"layer\",true);return false;'/>").appendTo($("#metadataTable"));
     }
 
     this.enableResetButton = function() {

Modified: trunk/mapbender/http/plugins/mb_metadata_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_server.php	2016-06-06 12:42:43 UTC (rev 9507)
+++ trunk/mapbender/http/plugins/mb_metadata_server.php	2016-06-07 10:25:53 UTC (rev 9508)
@@ -133,39 +133,6 @@
 	}
 }
 
-function getExtentGraphic($layer_4326_box) {
-	$area_4326_box = explode(',',EXTENTSERVICEBBOX);
-	if ($layer_4326_box[0] <= $area_4326_box[0] || $layer_4326_box[2] >= $area_4326_box[2] || $layer_4326_box[1] <= $area_4326_box[1] || $layer_4326_box[3] >= $area_4326_box[3]) {
-		if ($layer_4326_box[0] < $area_4326_box[0]) {
-			$area_4326_box[0] = $layer_4326_box[0];
-		}
-		if ($layer_4326_box[2] > $area_4326_box[2]) {
-			$area_4326_box[2] = $layer_4326_box[2];
-		}
-		if ($layer_4326_box[1] < $area_4326_box[1]) {
-			$area_4326_box[1] = $layer_4326_box[1];
-		}
-		if ($layer_4326_box[3] > $area_4326_box[3]) {
-			$area_4326_box[3] = $layer_4326_box[3];
-		}
-
-		$d_x = $area_4326_box[2] - $area_4326_box[0];
-		$d_y = $area_4326_box[3] - $area_4326_box[1];
-
-		$new_minx = $area_4326_box[0] - 0.05*($d_x);
-		$new_maxx = $area_4326_box[2] + 0.05*($d_x);
-		$new_miny = $area_4326_box[1] - 0.05*($d_y);
-		$new_maxy = $area_4326_box[3] + 0.05*($d_y);
-
-		if ($new_minx < -180) $area_4326_box[0] = -180; else $area_4326_box[0] = $new_minx;
-		if ($new_maxx > 180) $area_4326_box[2] = 180; else $area_4326_box[2] = $new_maxx;
-		if ($new_miny < -90) $area_4326_box[1] = -90; else $area_4326_box[1] = $new_miny;
-		if ($new_maxy > 90) $area_4326_box[3] = 90; else $area_4326_box[3] = $new_maxy;
-	}
-	$getMapUrl = EXTENTSERVICEURL."VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=".EXTENTSERVICELAYER."&STYLES=&SRS=EPSG:4326&BBOX=".$area_4326_box[0].",".$area_4326_box[1].",".$area_4326_box[2].",".$area_4326_box[3]."&WIDTH=120&HEIGHT=120&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_inimage&minx=".$layer_4326_box[0]."&miny=".$layer_4326_box[1]."&maxx=".$layer_4326_box[2]."&maxy=".$layer_4326_box[3];
-	return $getMapUrl;
-}
-
 switch ($ajaxResponse->getMethod()) {
 	case "getWms" :
 		$wmsIdArray = getWms();
@@ -348,20 +315,28 @@
 		$ajaxResponse->setResult($resultObj);
 		$ajaxResponse->setSuccess(true);
 
-		break;
+	break;
+//*****************************
+	case "getResourceMetadata" :
+		$resourceId = $ajaxResponse->getParameter("resourceId");
+		$resourceType = $ajaxResponse->getParameter("resourceType");
+		switch ($resourceType) {
+			case "layer":
+				getLayer($resourceId);
+				//new - only layers with latlonbboxes are supported!
+				$sql = <<<SQL
 
-	case "getLayerMetadata" :
-		$layerId = $ajaxResponse->getParameter("id");
-		getLayer($layerId);
-		//new - only layers with latlonbboxes are supported!
-		$sql = <<<SQL
-
 SELECT layer_id, layer_name, layer_title, layer_abstract, layer_searchable, inspire_download, fkey_wms_id as wms_id
-FROM layer WHERE layer_id = $layerId;
+FROM layer WHERE layer_id = $resourceId;
 
 SQL;
+				$tablename = "layer";
+			break;
+			case "featuretype":
+				$tablename = "wfs_featuretype";
+			break;
+		}
 		$res = db_query($sql);
-
 		$resultObj = array();
 		while ($row = db_fetch_assoc($res)) {
 			foreach ($row as $key => $value) {
@@ -369,64 +344,39 @@
 				$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 AND fkey_metadata_id ISNULL
-SQL;
+		$sql = "SELECT fkey_md_topic_category_id FROM ".$tablename."_md_topic_category WHERE fkey_".$tablename."_id = ".$resourceId." AND fkey_metadata_id ISNULL";
 		$res = db_query($sql);
 		while ($row = db_fetch_assoc($res)) {
-			$resultObj["layer_md_topic_category_id"][]= $row["fkey_md_topic_category_id"];
+			$resultObj[$tablename."_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 AND fkey_metadata_id ISNULL
-SQL;
+		$sql = "SELECT fkey_inspire_category_id FROM ".$tablename."_inspire_category WHERE fkey_layer_id = ".$resourceId." AND fkey_metadata_id ISNULL";
 		$res = db_query($sql);
 		while ($row = db_fetch_assoc($res)) {
-			$resultObj["layer_inspire_category_id"][]= $row["fkey_inspire_category_id"];
+			$resultObj[$tablename."_inspire_category_id"][]= $row["fkey_inspire_category_id"];
 		}
-
-		$sql = <<<SQL
-SELECT fkey_custom_category_id
-FROM layer_custom_category
-WHERE fkey_layer_id = $layerId AND fkey_metadata_id ISNULL
-SQL;
+		$sql = "SELECT fkey_custom_category_id FROM ".$tablename."_custom_category WHERE fkey_layer_id = ".$resourceId." AND fkey_metadata_id ISNULL";
 		$res = db_query($sql);
 		while ($row = db_fetch_assoc($res)) {
-			$resultObj["layer_custom_category_id"][]= $row["fkey_custom_category_id"];
+			$resultObj[$tablename."_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;
+		$sql = "SELECT keyword FROM keyword, ".$tablename."_keyword WHERE keyword_id = fkey_keyword_id AND fkey_layer_id = ".$resourceId;
 		$res = db_query($sql);
-
-		$resultObj["layer_keyword"] = array();
+		$resultObj[$tablename."_keyword"] = array();
 		while ($row = db_fetch_assoc($res)) {
-			$resultObj["layer_keyword"][]= $row["keyword"];
+			$resultObj[$tablename."_keyword"][]= $row["keyword"];
 		}
-
 		$resultObj['inspire_download'] = $resultObj['inspire_download'] == 1 ? true : false;
 		//get wgs84Bbox for relevant layer - to be bequeathed to the metadata
 		/*$sql = <<<SQL
 SELECT minx, miny, maxx, maxy from layer_epsg WHERE fkey_layer_id = $1 AND epsg = 'EPSG:4326'
 SQL;
 		$res = db_query($sql);*/
-
 		//read out values
-
 		//get coupled MetadataURLs from md_metadata and ows_relation_metadata table
-		$sql = <<<SQL
-SELECT metadata_id, uuid, link, linktype, md_format, relation.relation_type, 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 relation.relation_type IN ('capabilities','external','metador','upload', 'internal') ORDER BY metadata_id DESC
-SQL;
+		$sql = "SELECT metadata_id, uuid, link, linktype, md_format, relation.relation_type, origin FROM mb_metadata";
+		$sql .= " INNER JOIN (SELECT * from ows_relation_metadata WHERE fkey_".$resourceType."_id = ".$resourceId." ) as relation ON";
+		$sql .= " mb_metadata.metadata_id = relation.fkey_metadata_id WHERE relation.relation_type IN"; 
+		$sql .= " ('capabilities','external','metador','upload', 'internal') ORDER BY metadata_id DESC";
 		$res = db_query($sql);
 		$resultObj["md_metadata"]->metadata_id = array();
 		$resultObj["md_metadata"]->uuid = array();
@@ -448,18 +398,20 @@
 			}
 			$i++;
 		}
-        // check for preview image
-        if (file_exists(PREVIEW_DIR."/".$layerId."_layer_map_preview.jpg") || file_exists(PREVIEW_DIR."/".$layerId."_layer_map_preview.png")) {
-            $resultObj['hasPreview']= true;
-        } else {
-            $resultObj['hasPreview']= false;
-        }
+		if ($resourceType == "layer") {
+        		// check for preview image
+        		if (file_exists(PREVIEW_DIR."/".$layerId."_layer_map_preview.jpg") || file_exists(PREVIEW_DIR."/".$layerId."_layer_map_preview.png")) {
+            			$resultObj['hasPreview']= true;
+        		} else {
+            			$resultObj['hasPreview']= false;
+        		}
+		}
 		$ajaxResponse->setResult($resultObj);
 		$ajaxResponse->setSuccess(true);
-		break;
+	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, inspire_download
@@ -895,7 +847,50 @@
 			$ajaxResponse->setSuccess(false);
 			break;
 		}
-	case "getInitialLayerMetadata" :
+	case "getInitialResourceMetadata" :
+		$resourceId = $ajaxResponse->getParameter("resourceId");
+		$metadataId = $ajaxResponse->getParameter("metadataId");
+		$resourceType = $ajaxResponse->getParameter("resourceType");
+		switch ($resourceType) {
+			case "layer":
+				$sql = <<<SQL
+SELECT layerpart.*, wms.accessconstraints, wms.fees FROM (SELECT layer_title, fkey_wms_id, layer_abstract, minx as west, miny as south, maxx as east, maxy as north FROM layer INNER JOIN layer_epsg ON layer.layer_id = layer_epsg.fkey_layer_id WHERE layer_id = $1 AND epsg = 'EPSG:4326') as layerpart INNER JOIN wms ON layerpart.fkey_wms_id = wms.wms_id
+SQL;
+				$v = array($resourceId);
+				$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
+					$resultObj["west"]= $row['west']; //double
+					$resultObj["south"] = $row["south"]; //double
+					$resultObj["east"]= $row['east']; //double
+					$resultObj["north"] = $row["north"]; //double
+					$resultObj["accessconstraints_md"] = $row["accessconstraints"]; //
+					$resultObj["fees_md"] = $row["fees"]; //
+				}
+				$sql = <<<SQL
+SELECT fkey_termsofuse_id FROM wms_termsofuse WHERE fkey_wms_id = $1;
+SQL;
+				$v = array($row['fkey_wms_id']);
+				$t = array('i');
+				$res = db_prep_query($sql,$v,$t);
+				$row = array();
+				if ($res) {
+					$row = db_fetch_assoc($res);
+					$resultObj["md_termsofuse"]= $row['fkey_termsofuse_id']; //serial
+				}
+				$ajaxResponse->setResult($resultObj);
+				$ajaxResponse->setSuccess(true);
+			break;
+			case "featuretype":
+				//TODO
+			break;
+		}
+		break;
+/*	case "getInitialLayerMetadata" :
 		$layerId = $ajaxResponse->getParameter("layerId");
 		$metadataId = $ajaxResponse->getParameter("metadataId");
 		$sql = <<<SQL
@@ -930,6 +925,7 @@
 		$ajaxResponse->setResult($resultObj);
 		$ajaxResponse->setSuccess(true);
 		break;
+*/
 	case "updateMetadataAddon" :
 		$metadataId = $ajaxResponse->getParameter("metadataId");
 		$resourceId = $ajaxResponse->getParameter("resourceId");
@@ -964,6 +960,8 @@
 			$mbMetadata->tmpExtentBegin = $data->tmp_reference_1;
 			$mbMetadata->tmpExtentEnd = $data->tmp_reference_2;
 			$mbMetadata->lineage = $data->lineage;
+			//set origin always to metador - even if it was an uploaded record before!
+			$mbMetadata->origin = 'metador';
 			$mbMetadata->spatialResType = $data->spatial_res_type;
 			$mbMetadata->spatialResValue = $data->spatial_res_value;
 			$mbMetadata->inspireCharset = $data->inspire_charset;

Modified: trunk/mapbender/http/plugins/mb_metadata_showMetadataAddon.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_showMetadataAddon.js	2016-06-06 12:42:43 UTC (rev 9507)
+++ trunk/mapbender/http/plugins/mb_metadata_showMetadataAddon.js	2016-06-07 10:25:53 UTC (rev 9508)
@@ -1,15 +1,14 @@
 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;
-	var layerId;
+	var resourceId;
+	var resourceType;
 	var metadataId;
-        //var wmsId;
+   
 	//Function, which pulls the metadata out off the mapbender registry and give a possibility to edit the record or link
 	this.valid = function () {
 		if (validator && validator.numberOfInvalids() > 0) {
@@ -18,14 +17,16 @@
 		}
 		return true;
 	};
-	this.getInitialLayerMetadata = function(metadataId, layerId){
+
+	this.getInitialResourceMetadata = function(metadataId, resourceId, resourceType){
 		// get metadata from server
 		var req = new Mapbender.Ajax.Request({
 			url: "../plugins/mb_metadata_server.php",
-			method: "getInitialLayerMetadata",
+			method: "getInitialResourceMetadata",
 			parameters: {
-				"layerId": layerId,
-				"metadataId": metadataId
+				"resourceId": resourceId,
+				"metadataId": metadataId,
+				"resourceType": resourceType,
 			},
 			callback: function (obj, result, message) {
 				if (!result) {
@@ -38,28 +39,6 @@
 					//alert(JSON.stringify(obj));
 					that.fillLicence(obj.md_termsofuse);
 				}
-				//that.showForm(metadataId, layerId);
-				/*
-				//enable link element to edit link!
-				$("#link").removeAttr("disabled");
-
-				switch (obj.origin) {
-					case "external":
-						$("#metadataUrlEditor").css("display","block");
-						$("#link_editor").css("display","block");
-    						break;
-  					case "metador":
-						$("#metadataUrlEditor").css("display","block");
-						$("#simple_metadata_editor").css("display","block");
-    						break;
-  					case "capabilities":
-						$("#metadataUrlEditor").css("display","block");
-    						$("#simple_metadata_editor").css("display","block");
-    						break;			
-					default:
-    						break;
-				}
-				*/
 			}
 		});
 		req.send();	
@@ -123,7 +102,12 @@
   					case "capabilities":
 						$("#metadataUrlEditor").css("display","block");
     						$("#simple_metadata_editor").css("display","block");
-    						break;			
+    						break;
+					//new - uploaded metadata maybe edited - but some information will be lost :-(
+					case "upload":
+						$("#metadataUrlEditor").css("display","block");
+						$("#simple_metadata_editor").css("display","block");
+    						break;		
 					default:
     						break;
 				}
@@ -201,37 +185,43 @@
 		req.send();
 	}	
 
-	this.insertAddedMetadata = function(layerId, data){
+	this.insertAddedMetadata = function(resourceId, resourceType, data){
 		// push metadata from server
 		var req = new Mapbender.Ajax.Request({
 			url: "../plugins/mb_metadata_server.php",
 			method: "insertMetadataAddon",
 			parameters: {
-				"resourceId": layerId,
-				"resourceType": "layer",
+				"resourceId": resourceId,
+				"resourceType": resourceType,
 				"data": data
 			},
 			callback: function (obj, result, message) {
 				$("<div></div>").text(message).dialog({
 					modal: true
 				});
-				//update layer form to show edited data
-				that.fillLayerForm(layerId);
+				//update resource form to show edited data
+				switch (resourceType) {
+					case "layer":
+						that.fillResourceForm(resourceId, resourceType);
+					break;
+					case "featuretype":
+						//TODO
+					break;
+				}
 			}
 		});
 		req.send();	
 	}
 
-
-	this.updateAddedMetadata = function(metadataId, layerId, data){
-		// push metadata from server
+	this.updateAddedMetadata = function(metadataId, resourceId, resourceType, data){
+		// push metadata to server
 		var req = new Mapbender.Ajax.Request({
 			url: "../plugins/mb_metadata_server.php",
 			method: "updateMetadataAddon",
 			parameters: {
 				"metadataId": metadataId,
-				"resourceId": layerId,
-				"resourceType": "layer",
+				"resourceId": resourceId,
+				"resourceType": resourceType,
 				"data": data
 			},
 			callback: function (obj, result, message) {
@@ -242,45 +232,60 @@
 					modal: true
 				});
 				//update layer form to show edited data
-				that.fillLayerForm(layerId);
+				switch (resourceType) {
+					case "layer":
+						that.fillResourceForm(resourceId, resourceType);
+					break;
+					case "featuretype":
+						//TODO
+					break;
+				}
 			}
 		});
 		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) {
+
+	//function to fill resource 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.fillResourceForm = function (resourceId, resourceType) {
 		// get metadata from server
 		var req = new Mapbender.Ajax.Request({
 			url: "../plugins/mb_metadata_server.php",
-			method: "getLayerMetadata",
+			method: "getResourceMetadata",
 			parameters: {
-				"id": layerId
+				"resourceId": resourceId,
+				"resourceType": resourceType
 			},
 			callback: function (obj, result, message) {
 				if (!result) {
 					return;
 				}
-				//this.wmsId = obj.wms_id;
 				//delete metadataURL entries
 				$('.metadataEntry').remove();
 				//fill MetadataURLs into metadata_selectbox_id - notice: the name of the module is fix!
-				Mapbender.modules.mb_md_layer.fillMetadataURLs(obj);
-				//reload layer tree for showing symbols
-				Mapbender.modules.mb_md_layer_tree.init(Mapbender.modules.mb_md_layer.getWmsId());
+				switch (resourceType) {
+					case "layer":
+						Mapbender.modules.mb_md_layer.fillMetadataURLs(obj);
+						//reload layer tree for showing symbols
+						Mapbender.modules.mb_md_layer_tree.init(Mapbender.modules.mb_md_layer.getWmsId());
+					break;
+					case "featuretype":
+						//TODO
+					break;
+				}
 			}
 		});
 		req.send();		
 	};
 	
-	deleteAddedMetadata = function(metadataId, layerId){
+	deleteAddedMetadata = function(metadataId, resourceId, resourceType){
 		// push metadata from server
 		var req = new Mapbender.Ajax.Request({
 			url: "../plugins/mb_metadata_server.php",
 			method: "deleteMetadataAddon",
 			parameters: {
 				"metadataId": metadataId,
-				"resourceId": layerId,
-				"resourceType": "layer"
+				"resourceId": resourceId,
+				"resourceType": resourceType
 			},
 			callback: function (obj, result, message) {
 				if (!result) {
@@ -289,9 +294,8 @@
 				//delete metadataURL entries
 				$('.metadataEntry').remove();
 				//fill MetadataURLs into metadata_selectbox_id
-				//update layer form to show edited data
-				that.fillLayerForm(layerId);
-				
+				//update resource form to show edited data
+				that.fillResourceForm(resourceId, resourceType);
 				$("<div></div>").text(message).dialog({
 					modal: true
 				});
@@ -300,15 +304,15 @@
 		req.send();	
 	}		
 	
-	deleteInternalMetadataLinkage = function(metadataId, layerId){
+	deleteInternalMetadataLinkage = function(metadataId, resourceId, resourceType){
 		// push metadata from server
 		var req = new Mapbender.Ajax.Request({
 			url: "../plugins/mb_metadata_server.php",
 			method: "deleteInternalMetadataLinkage",
 			parameters: {
 				"metadataId": metadataId,
-				"resourceType": "layer",
-				"resourceId": layerId
+				"resourceType": resourceType,
+				"resourceId": resourceId
 			},
 			callback: function (obj, result, message) {
 				if (!result) {
@@ -317,8 +321,8 @@
 				//delete metadataURL entries
 				$('.metadataEntry').remove();
 				//fill MetadataURLs into metadata_selectbox_id
-				//update layer form to show edited data
-				that.fillLayerForm(layerId);
+				//update resource form to show edited data
+				that.fillResourceForm(resourceId, resourceType);
 				$("<div></div>").text(message).dialog({
 					modal: true
 				});
@@ -327,7 +331,7 @@
 		req.send();	
 	}			
 
-	this.showForm = function (metadataId, layerId, isNew) {
+	this.showForm = function (metadataId, resourceId, resourceType, isNew) {
 		$metadataAddonPopup.append($metadataAddonForm);
 		$metadataAddonPopup.dialog({
 			title : "Metadata Addon Editor", 
@@ -361,10 +365,9 @@
 					}
 					var formData = $metadataAddonForm.easyform("serialize");
 					if (!isNew) {
-						that.updateAddedMetadata(metadataId, layerId, formData);
+						that.updateAddedMetadata(metadataId, resourceId, resourceType, formData);
 					} else {
-						that.insertAddedMetadata(layerId, formData);
-						
+						that.insertAddedMetadata(resourceId, resourceType, formData);	
 					}
 					//$('#mb_md_layer_tree').refresh;
 					$(this).dialog('close');
@@ -372,16 +375,16 @@
 			},
 			close: function() {
 				//what to do when the dialog is closed
-				
 			}
 		});
 		$metadataAddonPopup.dialog("open");
 	};
 	
-	initUploadForm = function (layerId) {
+	initUploadForm = function (resourceId, resourceType) {
 		$metadataAddonPopup.dialog("close");
-		initXmlImport(layerId);
-		that.fillLayerForm(layerId);
+		//TODO: problem - when invoking it first - mb_metadata_addon.php - there is no information about the resourceType and its id. Some error occurs - but hidden ;-)
+		initXmlImport(resourceId, resourceType);
+		that.fillResourceForm(resourceId, resourceType);
 	}
 
  	enableResetButtonMd = function() {
@@ -400,7 +403,6 @@
 		//$metadataAddonPopup.dialog("close");
 		//don't show possibility if metadata was not created before - only afterwards!
 		initGmlImport(metadataId);
-		//that.fillLayerForm(layerId);
 	}
 
 	deleteGmlPolygon = function (metadataId) {
@@ -428,7 +430,7 @@
 		req.send();	
 	}			
 
-	this.init = function (metadataId, layerId, isNew) {
+	this.init = function (metadataId, resourceId, resourceType, isNew) {
 		$metadataAddonPopup.dialog("close");
 		$metadataAddonForm.load("../plugins/mb_metadata_addon.php", function () {
 			//push infos to help dialogs
@@ -439,19 +441,17 @@
 			//first get json
 			if (!isNew) {
 				that.getAddedMetadata(metadataId);
-			
 			} else {
 				//show chooser
 				$("#metadataUrlEditor").css("display","block"); 
 				$("#addonChooser").css("display","block");
 				//get initial values (title/abstract)
-				that.getInitialLayerMetadata(metadataId, layerId);
+				that.getInitialResourceMetadata(metadataId, resourceId, resourceType);
 			}
-			//c
-			that.showForm(metadataId, layerId, isNew);
-			
+			that.showForm(metadataId, resourceId, resourceType, isNew);
 			$("#uploadImage").click(function () {
-				initUploadForm(layerId);
+				initUploadForm(resourceId, resourceType);
+				//initUploadForm(layerId);
 			});
 			$("#uploadgmlimage").click(function () {
 				initUploadGmlForm(metadataId);
@@ -483,10 +483,9 @@
 			//$( "#abstract" ).resizable({ minWidth: 75 });
 		});
 	}
-	initMetadataAddon = function(metadataId, layerId, isNew) {
-		//close old window and load form
-		that.init(metadataId, layerId, isNew);	
-		//fill form
+	initMetadataAddon = function(metadataId, resourceId, resourceType, isNew) {
+		//close old window and load form	
+		that.init(metadataId, resourceId, resourceType, isNew);
 	}
 };
 

Modified: trunk/mapbender/http/plugins/mb_metadata_xml_import.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_xml_import.js	2016-06-06 12:42:43 UTC (rev 9507)
+++ trunk/mapbender/http/plugins/mb_metadata_xml_import.js	2016-06-07 10:25:53 UTC (rev 9508)
@@ -1,6 +1,6 @@
 var $xmlImport = $(this);
-var importXmlLayerId;
-
+var importXmlResourceId;
+var importXmlResourceType;
 var XmlImportApi = function () {
 	var that = this;
 	var type;
@@ -13,14 +13,15 @@
 		$xmlImport.dialog("close");
 	});
 	
-	var importUploadedFile = function(filename, layerId, callback){
+	//var importUploadedFile = function(filename, layerId, callback){
+	var importUploadedFile = function(filename, resourceId, resourceType, callback){
 		var req = new Mapbender.Ajax.Request({
 			url: "../plugins/mb_metadata_server.php",
 			method: "importXmlAddon",
 			parameters: {
 				filename: filename,
-				"resourceId": layerId,
-				"resourceType": "layer"
+				"resourceId": resourceId,
+				"resourceType": resourceType
 			},
 			callback: function (obj, result, message, errorCode) {				
 				if (!result) {
@@ -36,8 +37,7 @@
 				alert(message);
 				$xmlImport.dialog("close");
 				//invoke external script from mb_metadata_showMetadataAddon.js
-				//that.fillLayerForm(layerId);
-				Mapbender.modules.mb_md_showMetadataAddon.fillLayerForm(layerId);
+				Mapbender.modules.mb_md_showMetadataAddon.fillResourceForm(resourceId, resourceType);
 				if ($.isFunction(callback)) {
 					callback(obj.id);
 				}
@@ -58,7 +58,7 @@
 	        var uploadResultName = result.filename;
 	        var uploadResultOrigName = result.origFilename;
 	        
-	        importUploadedFile(result.filename, that.importXmlLayerId, function (id) {
+	        importUploadedFile(result.filename, that.importXmlResourceId, that.importXmlResourceType, function (id) {
 		        that.events.uploadComplete.trigger({
 					"type": type,
 					"id": id
@@ -72,14 +72,14 @@
 		width: 580
 	});
 
-
 	this.init = function (obj) {
 		type = obj.type;
 		$xmlImport.dialog("open");
 	};
 
-	initXmlImport = function (layerId) {
-		that.importXmlLayerId = layerId;
+	initXmlImport = function (resourceId, resourceType) {
+		that.importXmlResourceId = resourceId;
+		that.importXmlResourceType = resourceType;
 		$xmlImport.dialog("open");
 		return true;
 	};



More information about the Mapbender_commits mailing list