[Mapbender-commits] r7969 - branches/2.7/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Jul 19 09:02:47 EDT 2011


Author: astrid_emde
Date: 2011-07-19 06:02:47 -0700 (Tue, 19 Jul 2011)
New Revision: 7969

Modified:
   branches/2.7/http/classes/class_SaveLegend.php
   branches/2.7/http/classes/class_connector.php
   branches/2.7/http/classes/class_gui.php
   branches/2.7/http/classes/class_metadata_new.php
   branches/2.7/http/classes/class_wfs.php
   branches/2.7/http/classes/class_wmc.php
   branches/2.7/http/classes/class_wms.php
Log:
merged with trunk

Modified: branches/2.7/http/classes/class_SaveLegend.php
===================================================================
--- branches/2.7/http/classes/class_SaveLegend.php	2011-07-19 13:01:26 UTC (rev 7968)
+++ branches/2.7/http/classes/class_SaveLegend.php	2011-07-19 13:02:47 UTC (rev 7969)
@@ -33,27 +33,40 @@
 		if(!$url || $url == ""){
 			$e = new mb_exception("SaveLegend: no legendurl delivered");
 		}
-		#$obj1 = new stripRequest($url);
-		$size = getimagesize($url);
+		$x = new connector($url);
+		//save file in tmp folder to extract right size - sometimes the size could not be detected by url!
+		if($legendFileHandle = fopen($legend_filename, "w")){
+			fwrite($legendFileHandle,$x->file);
+			fclose($legendFileHandle);
+			$e = new mb_notice("SaveLegend: new legend file created: ".$legend_filename);
+		} else {
+			$e = new mb_exception("SaveLegend: legend file ".$legend_filename." could not be created!");
+		}
+		//get size of image
+		$size = getimagesize($legend_filename);
 		$width = $size[0];
 		$height = $size[1];
-		
 		$image = imagecreatetruecolor($width, $height);
 		$white = ImageColorAllocate($image,255,255,255); 
-		ImageFilledRectangle($image,0,0,$width,$height,$white); 
-
-			$img = $this->loadpng($url);
-			if($img != false){
-				imagecopy($image, $img, 0, 0, 0, 0, $width, $height);
-			}else{
-				$e = new mb_exception("SaveLegend: unable to load image: " . $url);
-			}
+		ImageFilledRectangle($image,0,0,$width,$height,$white);
+		//load image from url to create new image
+		$img = $this->loadpng($url);
+		if($img != false){
+			imagecopy($image, $img, 0, 0, 0, 0, $width, $height);
+		}else{
+			$e = new mb_exception("SaveLegend: unable to load image: " . $url);
+		}
+		//save image to same filename as before
 		imagepng($image,$legend_filename);
 		imagedestroy($img);
 	}
 	function loadpng ($imgurl) {
 		$x = new connector($imgurl);
-		$im = @imagecreatefromstring($x->file);
+		try {
+			$im = imagecreatefromstring($x->file);
+		}catch(Exception $E){
+			$e = new mb_exception("Can't read image from string: ".$E->getmessage);
+		}
 		if(!$im){
 			$im = false;
 			$e = new mb_exception("SaveLegend: unable to load image: ".$imgurl);

Modified: branches/2.7/http/classes/class_connector.php
===================================================================
--- branches/2.7/http/classes/class_connector.php	2011-07-19 13:01:26 UTC (rev 7968)
+++ branches/2.7/http/classes/class_connector.php	2011-07-19 13:02:47 UTC (rev 7969)
@@ -28,15 +28,15 @@
 
 	var $file;	
 	private $connectionType;
+	private $timeOut = 20;
 	private $httpType = "get";
 	private $httpVersion = "1.0";
 	private $httpPostData;
 	private $httpContentType;
 	private $httpPostFieldsNumber;
 	private $curlSendCustomHeaders = true; //decide to send own headers or not
+	
 		
-
-		
 	/**
 	 * @constructor
 	 * @param String url the URL that will be loaded (optional)
@@ -155,6 +155,10 @@
 	
 			case "curlSendCustomHeaders":
 				$this->curlSendCustomHeaders = $value;
+				break;
+	
+			case "timeOut":
+				$this->timeOut = (integer)$value;
 				break;	
 	
 			case "httpContentType":
@@ -206,6 +210,7 @@
 		//allow https connections and handle certificates quite simply ;-)
 		curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
 		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeOut);
 		//$e = new mb_notice("connector: test1:");
 		//get hostname/ip out of url
 		//$host = parse_url($url,PHP_URL_HOST);
@@ -317,8 +322,8 @@
 		}
 		if ($info['http_code'] == '502') {
 			curl_close ($ch);
-			$e = new mb_exception("class_connector.php: Problem with connectiong Gateway - maybe problem with the configuration of the security proxy (mod_proxy?).");
-			return $info['hhtp_code'];
+			$e = new mb_exception("class_connector.php: Problem with connecting Gateway - maybe problem with the configuration of the security proxy (mod_proxy?).");
+			return $info['http_code'];
 			/*fwrite($handle,"HEADER: \n");
 			fwrite($handle,$error_log);
 			fwrite($handle,"502: ".$file."\n");*/

Modified: branches/2.7/http/classes/class_gui.php
===================================================================
--- branches/2.7/http/classes/class_gui.php	2011-07-19 13:01:26 UTC (rev 7968)
+++ branches/2.7/http/classes/class_gui.php	2011-07-19 13:02:47 UTC (rev 7969)
@@ -437,10 +437,10 @@
 			array_push($v, array($newGuiName, $guiList));
 			array_push($t, array("s", "s"));
 
-			array_push($sql, "INSERT INTO sld_user_layer (fkey_mb_user_id,fkey_layer_id,fkey_gui_id,sld_xml,use_sld) SELECT fkey_mb_user_id,fkey_layer_id, $1,sld_xml,use_sld  FROM sld_user_layer  WHERE fkey_gui_id = $2;");
+			array_push($sql, "INSERT INTO sld_user_layer (fkey_mb_user_id,fkey_layer_id,fkey_gui_id,sld_xml,use_sld) SELECT fkey_mb_user_id,fkey_layer_id, $1,sld_xml,use_sld FROM sld_user_layer  WHERE fkey_gui_id = $2;");
 			array_push($v, array($newGuiName, $guiList));
 			array_push($t, array("s", "s"));
-
+			
 			if ($withUsers == true) {
 				/* group of original gui is copied as well */
 				array_push($sql, "INSERT INTO gui_mb_group (fkey_gui_id, fkey_mb_group_id, mb_group_type) SELECT $1, fkey_mb_group_id, mb_group_type FROM gui_mb_group WHERE fkey_gui_id = $2;");

Modified: branches/2.7/http/classes/class_metadata_new.php
===================================================================
--- branches/2.7/http/classes/class_metadata_new.php	2011-07-19 13:01:26 UTC (rev 7968)
+++ branches/2.7/http/classes/class_metadata_new.php	2011-07-19 13:02:47 UTC (rev 7969)
@@ -125,8 +125,20 @@
 		$this->resourceClassifications[1]['relation_wfs'] = 'featuretype_inspire_category';
 		$this->resourceClassifications[1]['relation_wmc'] = 'wmc_inspire_category';
 //TODO: define this in mapbender
-
-		$this->resourceClassifications[2]['title'] = "Custom"; //TODO: define the translations somewhere? - This is done in call_metadata.php before. Maybe we can get them from there? - It will be shown in the rightside categories table
+		switch($this->languageCode){
+			case "de":
+				$this->resourceClassifications[2]['title'] = "Sonstige"; //TODO: define the translations somewhere? - This is done in call_metadata.php before. Maybe we can get them from there? - It will be shown in the rightside categories table
+			break;
+			case "en":
+				$this->resourceClassifications[2]['title'] = "Custom";
+			break;
+			case "fr":
+				$this->resourceClassifications[2]['title'] = "Custom"; 
+			break;
+			default:
+				$this->resourceClassifications[2]['title'] = "Custom";
+			break;
+		}
 		$this->resourceClassifications[2]['tablename'] = 'custom_category';
 		$this->resourceClassifications[2]['requestName'] = 'customCategories';
 		$this->resourceClassifications[2]['id_wms'] = 'layer_id';
@@ -204,7 +216,7 @@
 				$this->databaseTableName = 'wfs_featuretype';
 				//$this->keywordRelation = 'wfs_featuretype_keyword';
 				$this->searchView = 'search_wfs_view';
-				$this->whereStrCatExtension = "";
+				$this->whereStrCatExtension = " AND custom_category.custom_category_hidden = 0";
 				switch ($this->orderBy) {
 					case "rank":
 						$this->orderBy = " ORDER BY wfs_id,featuretype_id,wfs_conf_id ";
@@ -231,7 +243,7 @@
 				//$this->keywordRelation = 'layer_keyword';
 				$this->searchView = 'wms_search_table';
 				//$this->searchView = 'wms_search_view';
-				$this->whereStrCatExtension = "";
+				$this->whereStrCatExtension = " AND custom_category.custom_category_hidden = 0";
 				switch ($this->orderBy) {
 					case "rank":
 						$this->orderBy = " ORDER BY load_count DESC";
@@ -257,7 +269,7 @@
 				$this->databaseIdColumnName = 'wmc_serial_id';
 				$this->databaseTableName = 'wmc';
 				//the following is needed to give a special filter to the custom cat table!
-				$this->whereStrCatExtension = " AND custom_category.custom_category_hidden != 1";
+				$this->whereStrCatExtension = " AND custom_category.custom_category_hidden = 0";
 
 				switch ($this->orderBy) {
 					case "rank":
@@ -1141,7 +1153,7 @@
 						$sqlCat[$i] .= $this->resourceClassifications[$i]['relation_'.$this->searchResources].".fkey_";
 						$sqlCat[$i] .= $this->resourceClassifications[$i]['tablename']."_id)";
 						//the following is needed to filter the custom cats for those which should not be seen in the classification
-						if ($this->resourceClassifications[$i]['title'] != "Custom"){
+						if ($this->resourceClassifications[$i]['title'] != $this->resourceClassifications[2]['title']){
 							$sqlCat[$i] .= " WHERE ".$whereStr." GROUP BY ";
 						} else {
 							$sqlCat[$i] .= " WHERE ".$whereStr.$this->whereStrCatExtension." GROUP BY ";

Modified: branches/2.7/http/classes/class_wfs.php
===================================================================
--- branches/2.7/http/classes/class_wfs.php	2011-07-19 13:01:26 UTC (rev 7968)
+++ branches/2.7/http/classes/class_wfs.php	2011-07-19 13:02:47 UTC (rev 7969)
@@ -201,7 +201,14 @@
 		$propertiesSegment = "";
 		foreach ($feature->properties as $key => $value) {
 			if (isset($value)) {
-				$propertiesSegment .= "<$ns:$key><![CDATA[$value]]></$ns:$key>";
+				if (is_numeric($value) || $value == "" || $value == "NULL") {
+					$value = $value;
+				} else {
+					$value = "<![CDATA[$value]]>";
+				}
+				if ($value != "NULL") {
+					$propertiesSegment .= "<$ns:$key>$value</$ns:$key>";
+				}
 			}
 		}
 
@@ -232,14 +239,16 @@
 		$propertiesSegment = "";
 		foreach ($feature->properties as $key => $value) {
 			if (isset($value)) {
-				if (is_numeric($value) || $value == "") {
+				if (is_numeric($value) || $value == "" || $value == "NULL") {
 					$value = $value;
 				}
 				else {
 					$value = "<![CDATA[$value]]>";
 				}
-				$propertiesSegment .= "<wfs:Property><wfs:Name>$featureNS:$key</wfs:Name>" . 
-					"<wfs:Value>$value</wfs:Value></wfs:Property>";
+				if ($value != "NULL") {
+					$propertiesSegment .= "<wfs:Property><wfs:Name>$featureNS:$key</wfs:Name>" . 
+						"<wfs:Value>$value</wfs:Value></wfs:Property>";
+				}
 			}
 		}
 

Modified: branches/2.7/http/classes/class_wmc.php
===================================================================
--- branches/2.7/http/classes/class_wmc.php	2011-07-19 13:01:26 UTC (rev 7968)
+++ branches/2.7/http/classes/class_wmc.php	2011-07-19 13:02:47 UTC (rev 7969)
@@ -675,7 +675,7 @@
 				if($row = db_fetch_row($res)) {
 					$sql = "UPDATE mb_user_wmc SET wmc = $1, wmc_timestamp = $2, abstract = $3, srs = $4, minx = $5, miny = $6,".
 						" maxx = $7, maxy = $8, wmc_title = $9 WHERE fkey_user_id = $10 AND wmc_serial_id=$11 AND wmc_timestamp = $12;";
-					$v = array($this->xml, time(), $this->wmc_abstract, $this->wmc_srs, $this->wmc_extent->minx, $this->wmc_extent->minx,
+					$v = array($this->xml, time(), $this->wmc_abstract, $this->wmc_srs, $this->wmc_extent->minx, $this->wmc_extent->miny,
 						$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);

Modified: branches/2.7/http/classes/class_wms.php
===================================================================
--- branches/2.7/http/classes/class_wms.php	2011-07-19 13:01:26 UTC (rev 7968)
+++ branches/2.7/http/classes/class_wms.php	2011-07-19 13:02:47 UTC (rev 7969)
@@ -101,7 +101,7 @@
 		#	"$1php/mod_layerMetadata.php?id=", 
 		#	LOGIN
 		#) . $wmsId;
-		return LOGIN."/../../mapbender/php/mod_showMetadata.php?resource=wms&id=".$wmsId;
+		return LOGIN."/../php/mod_showMetadata.php?resource=wms&id=".$wmsId;
 	}
 	public static function getLayerMetadataUrl ($layerId) {
 		#return preg_replace(
@@ -109,7 +109,7 @@
 		#	"$1php/mod_layerMetadata.php?id=", 
 		#	LOGIN
 		#) . $wmsId;
-		return LOGIN."/../../mapbender/php/mod_showMetadata.php?resource=layer&id=".$layerId;
+		return LOGIN."/../php/mod_showMetadata.php?resource=layer&id=".$layerId;
 	}
 	public static function isOwsProxyUrl ($getmap) {
 //		$e = new mb_notice("isOwsProxyUrl? " . $getmap);
@@ -810,6 +810,9 @@
 				$section = "layer";
 				if ($element[type] == "open") {
 					$cnt_epsg = -1;
+					//new for resolving metadataurls and dataurls
+					$cnt_metadataurl = -1;
+					$cnt_dataurl = -1;
 					$cnt_layer++;
 					$parent[$element[level]+1] = $cnt_layer;
 					$myParent[$cnt_layer]= $parent[$element[level]];
@@ -850,7 +853,7 @@
 				if(mb_strtoupper($element[tag]) == "TITLE"){
 					$this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["title"] = ($element[value] ? $element[value] : '');
 				}
-	      		if(mb_strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "open"){
+	      			if(mb_strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "open"){
 					$legendurl = true;
 				}
 				if($legendurl && mb_strtoupper($element[tag]) == "FORMAT"){
@@ -859,7 +862,7 @@
 				if($legendurl && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
 					$this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["legendurl"] = $element[attributes]["xlink:href"];
 				}
-			    if(mb_strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "close"){
+				if(mb_strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "close"){
 					$legendurl = false;
 				}   
 			}
@@ -877,23 +880,29 @@
 				if(mb_strtoupper($element[tag]) == "KEYWORD"){
 					array_push($this->objLayer[$cnt_layer]->layer_keyword, trim($element[value]));
 				}
-	      		if(mb_strtoupper($element[tag]) == "DATAURL" && $element[type] == "open"){
+	      			if(mb_strtoupper($element[tag]) == "DATAURL" && $element[type] == "open"){
 					$dataurl = true;
+					$cnt_dataurl++;
 				}
 				if($dataurl && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
-					$this->objLayer[$cnt_layer]->layer_dataurl_href = $element[attributes]["xlink:href"];
+					$this->objLayer[$cnt_layer]->layer_dataurl[$cnt_dataurl]->href = $element[attributes]["xlink:href"];
 				}
-			    if(mb_strtoupper($element[tag]) == "DATAURL" && $element[type] == "close"){
+			    	if(mb_strtoupper($element[tag]) == "DATAURL" && $element[type] == "close"){
 					$dataurl = false;
-				}   
+			   	}   
 				
 				if(mb_strtoupper($element[tag]) == "METADATAURL" && $element[type] == "open"){
 					$metadataurl = true;
+					$cnt_metadataurl++;
+					$this->objLayer[$cnt_layer]->layer_metadataurl[$cnt_metadataurl]->type = $element[attributes]["type"];
 				}
+				if($metadataurl && mb_strtoupper($element[tag]) == "FORMAT"){
+					$this->objLayer[$cnt_layer]->layer_metadataurl[$cnt_metadataurl]->format = $element[value];
+				}
 				if($metadataurl && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
-					$this->objLayer[$cnt_layer]->layer_metadataurl = $element[attributes]["xlink:href"];
+					$this->objLayer[$cnt_layer]->layer_metadataurl[$cnt_metadataurl]->href = $element[attributes]["xlink:href"];
 				}
-			    if(mb_strtoupper($element[tag]) == "METADATAURL" && $element[type] == "close"){
+			    	if(mb_strtoupper($element[tag]) == "METADATAURL" && $element[type] == "close"){
 					$metadataurl = false;
 				}   
 				
@@ -1112,9 +1121,16 @@
 			echo "<hr>";
 			echo "id: <b>".$this->objLayer[$i]->layer_id ."</b> parent: <b>".$this->objLayer[$i]->layer_parent."</b> name: <b>".$this->objLayer[$i]->layer_name;
 			echo "</b> title: <b>".$this->objLayer[$i]->layer_title. "</b> queryable: <b>".$this->objLayer[$i]->layer_queryable."</b> minScale: <b>". $this->objLayer[$i]->layer_minscale."</b> maxScale: <b>".$this->objLayer[$i]->layer_maxscale."</b>";
-			echo "<br>dataurl: <b>".$this->objLayer[$i]->layer_dataurl_href. "</b>";
-			echo "<br>metadataurl: <b>".$this->objLayer[$i]->layer_metadataurl. "</b>";
+			echo "<br>dataurl: <b>".$this->objLayer[$i]->layer_dataurl[0]->href. "</b>";
+			echo "<br>MetadataUrls:<br>";
 			echo "<table border='1'>";
+			echo "<tr><td>link</td><td>type</td><td>format</td></tr>";
+			for($j=0; $j<count($this->objLayer[$i]->layer_metadataurl);$j++){
+				echo "<tr><td>".$this->objLayer[$i]->layer_metadataurl[$j]->href."</td><td>".$this->objLayer[$i]->layer_metadataurl[$j]->type."</td><td>".$this->objLayer[$i]->layer_metadataurl[$j]->format."</td></tr>";
+			}
+			echo "</table>";
+			echo "<br>BBOXes:<br>";
+			echo "<table border='1'>";
 			for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
 				echo "<tr><td>".$this->objLayer[$i]->layer_epsg[$j][epsg]."</td><td>".$this->objLayer[$i]->layer_epsg[$j][minx]."</td>";
 				echo "<td>".$this->objLayer[$i]->layer_epsg[$j][miny]."</td><td>".$this->objLayer[$i]->layer_epsg[$j][maxx]."</td>";
@@ -1158,12 +1174,12 @@
 		$newLayer->layer_name = $currentLayer["name"];
 		$newLayer->layer_title = $currentLayer["title"];
 		$newLayer->gui_layer_title = $currentLayer["title"];
-		$newLayer->layer_dataurl_href = $currentLayer["dataurl"];
+		$newLayer->layer_dataurl[0]->href = $currentLayer["dataurl"];
 		$newLayer->layer_pos = $currentLayer["extension"]["LAYER_POS"];
 		$newLayer->layer_queryable = $currentLayer["queryable"];
 		$newLayer->layer_minscale = $currentLayer["extension"]["MINSCALE"];
 		$newLayer->layer_maxscale = $currentLayer["extension"]["MAXSCALE"];
-		$newLayer->layer_metadataurl = $currentLayer["metadataurl"];
+		$newLayer->layer_metadataurl[0]->href = $currentLayer["metadataurl"];
 //		$newLayer->layer_searchable = $currentLayer["searchable"];
 		$newLayer->gui_layer_wms_id = $currentLayer["extension"]["WMS_ID"];
 		$newLayer->gui_layer_status = $currentLayer["extension"]["GUI_STATUS"];
@@ -1311,13 +1327,13 @@
 				$this->objLayer[$i]->layer_uid ."','". 
 				addslashes($this->objLayer[$i]->layer_name) . "','". 
 				addslashes($this->objLayer[$i]->layer_title) ."','". 
-				$this->objLayer[$i]->layer_dataurl_href ."','". 
+				$this->objLayer[$i]->layer_dataurl[0]->href ."','". 
 				$this->objLayer[$i]->layer_pos ."','". 
 				$this->objLayer[$i]->layer_queryable ."','". 
 				$this->objLayer[$i]->layer_minscale . "','". 
 				$this->objLayer[$i]->layer_maxscale ."','". 
-				$this->objLayer[$i]->layer_metadataurl ."','". 
-// will be added later, not needed now
+				$this->objLayer[$i]->layer_metadataurl[0]->href ."','". 
+// will be added later, not needed now TODO check if more than one metadataUrl is usefull here
 //				$this->objLayer[$i]->layer_searchable ."','". 
 				$this->objLayer[$i]->gui_layer_wms_id ."','". 
 				$this->objLayer[$i]->gui_layer_status ."','".
@@ -1433,13 +1449,13 @@
 				$this->objLayer[$i]->layer_uid ."','". 
 				$this->objLayer[$i]->layer_name . "','". 
 				addslashes($this->objLayer[$i]->layer_title) ."','". 
-				$this->objLayer[$i]->layer_dataurl_href ."','". 
+				$this->objLayer[$i]->layer_dataurl[0]->href ."','". 
 				$this->objLayer[$i]->layer_pos ."','". 
 				$this->objLayer[$i]->layer_queryable ."','". 
 				$this->objLayer[$i]->layer_minscale . "','". 
 				$this->objLayer[$i]->layer_maxscale ."','". 
-				$this->objLayer[$i]->layer_metadataurl ."','". 
-// will be added later, not needed now
+				$this->objLayer[$i]->layer_metadataurl[0]->href ."','". 
+// will be added later, not needed now TODO check if more than one metadataUrl is usefull here
 //				$this->objLayer[$i]->layer_searchable ."','". 
 				$this->objLayer[$i]->gui_layer_wms_id ."','". 
 				$this->objLayer[$i]->gui_layer_status ."','".
@@ -1677,8 +1693,8 @@
 		$v = array($myWMS,$tmpPos,$this->objLayer[$i]->layer_parent,$this->objLayer[$i]->layer_name,
 				$this->objLayer[$i]->layer_title,
 				$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,
-				$this->objLayer[$i]->layer_maxscale,$this->objLayer[$i]->layer_dataurl_href,
-				$this->objLayer[$i]->layer_metadataurl, $this->objLayer[$i]->layer_searchable,
+				$this->objLayer[$i]->layer_maxscale,$this->objLayer[$i]->layer_dataurl[0]->href,
+				$this->objLayer[$i]->layer_metadataurl[0]->href, $this->objLayer[$i]->layer_searchable,
 				$this->objLayer[$i]->layer_abstract,
 				$uuid);
 		$t = array('i','i','s','s','s','i','i','i','s','s','i','s','s');
@@ -1696,7 +1712,11 @@
 			
 			# insert Keywords
 			$this->insertLayerKeyword($i);	
-		
+	
+			# insert dataurls
+			#$this->insertLayerDataUrls($i);TODO: in the spec 1.3.0 the schema defines a 1:n relation, but in the table there is only one link possible - maybe we need only this one link
+			# insert metadataurls
+			$this->insertLayerMetadataUrls($i);
 		}
 	}
 	function updateLayer($i,$myWMS){
@@ -1738,8 +1758,8 @@
 		$v = array($tmpPos,$this->objLayer[$i]->layer_parent,
 				$this->objLayer[$i]->layer_title,
 				$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,
-				$this->objLayer[$i]->layer_maxscale,$this->objLayer[$i]->layer_dataurl_href,
-				$this->objLayer[$i]->layer_metadataurl, $this->objLayer[$i]->layer_searchable,
+				$this->objLayer[$i]->layer_maxscale,$this->objLayer[$i]->layer_dataurl[0]->href,
+				$this->objLayer[$i]->layer_metadataurl[0]->href, $this->objLayer[$i]->layer_searchable,
 				$this->objLayer[$i]->layer_abstract, $l_id		
 			);
 		$t = array('i','s','s','i','i','i','s','s','i', 's','i');
@@ -1764,7 +1784,7 @@
 			# save the id of each layer: set param2 true
 			$this->objLayer[$i]->db_id = $l_id;
 			$this->insertLayerEPSG($i);
-			
+			$this->insertLayerMetadataUrls($i);
 			# TABLE layer_style for each layer
 			$this->insertLayerStyle($i);
 			if($this->overwrite == true){
@@ -1872,7 +1892,7 @@
 			return false;
        }
 		
-       //layer name from DB
+		//layer name from DB
 		$layerName=$row['layer_name'];
 		//defining the xpath for getting all Layer-tags
 		$xpathLayerName="//Layer[./Name =\"".$layerName."\"]";
@@ -1888,7 +1908,7 @@
 		if(!isset($layerObject[0])) {
 			$n = new mb_notice("Layer has no name and title, BBOX will not be generated for ".$epsg);
 			return false;	
-		}	
+		}
 		
 		//search for the SRS tag of specified layer		
 		$srsElementArray=$layerObject[0]->xpath("SRS");
@@ -2142,6 +2162,158 @@
 			}
 		}
 	}
+	function insertLayerMetadataUrls($i){
+		//first delete the old ones - but only those who have been harvested thru caps before!
+		global $con;
+		$sql = "DELETE FROM mb_metadata WHERE metadata_id IN (SELECT metadata_id FROM mb_metadata INNER JOIN";
+		$sql .= " (SELECT * from ows_relation_metadata WHERE fkey_layer_id = $1) as relation ON ";
+		$sql .= " mb_metadata.metadata_id = relation.fkey_metadata_id AND mb_metadata.origin = 'capabilities')";
+		$v = array($this->objLayer[$i]->db_id);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		//origin 2 - set by mapbender metadata editor - new record
+		//origin 3 - set by mapbender metadata editor - new linkage
+		//harvest the record if some readable format is given - should this be adoptable?
+		//parse the content if iso19139 is given
+		//TODO: generate temporal uuid for inserting and getting the serial afterwards
+		for($j=0; $j<count($this->objLayer[$i]->layer_metadataurl);$j++){
+
+			//check for returned format?
+			if (($this->objLayer[$i]->layer_metadataurl[$j]->type == 'ISO19115:2003' && $this->objLayer[$i]->layer_metadataurl[$j]->format =='text/xml') || ($this->objLayer[$i]->layer_metadataurl[$j]->type == 'TC211' && $this->objLayer[$i]->layer_metadataurl[$j]->format =='text/xml')) {
+				//load metadata from link
+				$metadataConnector = new connector($this->objLayer[$i]->layer_metadataurl[$j]->href);
+				$metaData = $metadataConnector->file;
+				//parse metadata
+				try {
+					//$iso19139Xml = simplexml_load_string($metaData);
+					$iso19139Xml =  new SimpleXMLElement($metaData);
+					if ($iso19139Xml == false) {
+						throw new Exception('Cannot parse Metadata XML!');
+					}
+				}
+				catch (Exception $e) {
+    					$e = new mb_exception($e->getMessage());
+				}
+				if ($iso19139Xml != false) {
+					//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_exception("class_wms.php: code: ".$code[0]);
+					$e = new mb_exception("class_wms.php: codeSpace: ".$codeSpace[0]);
+					if (isset($codeSpace[0]) && isset($code[0]) && $codeSpace[0] != '' && $code[0] != '') {
+						
+						$datasetid = $codeSpace[0]."#".$code[0];
+						$e = new mb_exception("class_wms.php: datasetid: ".$datasetid);
+					} else {
+						
+						$datasetid = 'undefined';# in sense of INSPIRE TODO control MD_Identifier too!
+						$e = new mb_exception("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 = "INSERT INTO mb_metadata (link, origin, md_format, data, linktype, uuid, title, createdate, changedate, abstract, searchtext, type, tmp_reference_1, tmp_reference_2, export2csw, datasetid) ";
+					$sql .= "VALUES($1, 'capabilities', $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)";
+					$v = array($this->objLayer[$i]->layer_metadataurl[$j]->href,
+						$this->objLayer[$i]->layer_metadataurl[$j]->format,
+						$metaData,
+						$this->objLayer[$i]->layer_metadataurl[$j]->type,
+						$uuid[0],
+						$title[0],
+						$createdate[0],
+						$changedate[0],
+						$abstract[0],
+						$keywords[0],
+						$type[0],
+						$tmp_reference_1[0],
+						$tmp_reference_2[0],
+						't',
+						$datasetid
+					);
+					$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s');
+					$res = db_prep_query($sql,$v,$t);
+					if(!$res){
+						db_rollback();	
+					}
+					//get last inserted serial_id
+					$mdId = db_insert_id($con, 'mb_metadata','metadata_id');
+					//insert into ows_relation_metadata (fkey_layer_id, fkey_metadata_id) values (20131,3);
+					$sql = "INSERT INTO ows_relation_metadata (fkey_layer_id, fkey_metadata_id) values ($1, $2);";
+					$v = array($this->objLayer[$i]->db_id, $mdId);
+					$t = array('i','i');
+					$res = db_prep_query($sql,$v,$t);
+					if(!$res){
+						db_rollback();	
+					} else {
+						$sql = "UPDATE mb_metadata SET harvestresult = 1 where metadata_id = $1";
+						$v = array($mdId);
+						$t = array('i');
+						$res = db_prep_query($sql,$v,$t);
+					}		
+				}
+			} else {//no readable format given - only store the links!
+				//don't push single elements into database
+				$sql = "INSERT INTO mb_metadata (link, origin, md_format, linktype) ";
+				$sql .= "VALUES($1, 'capabilities', $2, $3)";
+				$v = array($this->objLayer[$i]->layer_metadataurl[$j]->href,
+					$this->objLayer[$i]->layer_metadataurl[$j]->format,
+					$this->objLayer[$i]->layer_metadataurl[$j]->type		
+				);
+				$t = array('s','s','s');
+				$res = db_prep_query($sql,$v,$t);
+				if(!$res){
+					db_rollback();	
+				}
+				//get last inserted serial_id
+				$mdId = db_insert_id($con, 'mb_metadata','metadata_id');
+				//insert into ows_relation_metadata (fkey_layer_id, fkey_metadata_id) values (20131,3);
+				$sql = "INSERT INTO ows_relation_metadata (fkey_layer_id, fkey_metadata_id) values ($1, $2);";
+				$v = array($this->objLayer[$i]->db_id, $mdId);
+				$t = array('i','i');
+				$res = db_prep_query($sql,$v,$t);
+				if(!$res){
+					db_rollback();	
+				} else {
+					//set harvest result to 0 cause this metadata format can not to be parsed
+					$sql = "UPDATE mb_metadata SET harvestresult = 0 where metadata_id = $1";
+					$v = array($mdId);
+					$t = array('i');
+					$res = db_prep_query($sql,$v,$t);
+				}
+			}
+		}
+	}
+	
+
+
+
 	function updateObjInDB($myWMS){
 		if (!isset($this->wms_network_access) || ($this->wms_network_access == '')) {
 			$this->wms_network_access = intval('0');
@@ -2271,9 +2443,28 @@
 		}
 		
 		# delete all layer which are outdated
+		//first delete their metadataUrl entries*****
 		$v = array($myWMS);
 		$t = array('i');
 		$c = 2;
+		$sql = "DELETE FROM mb_metadata WHERE metadata_id IN (SELECT metadata_id FROM mb_metadata INNER JOIN (SELECT * from ows_relation_metadata WHERE fkey_layer_id IN " ;
+		$sql .= "(SELECT layer_id FROM layer WHERE fkey_wms_id = $1 AND NOT layer_name IN (";
+		for($i=0; $i<count($this->objLayer); $i++){
+			if($i>0){$sql .= ',';}
+			$sql .= "$".$c;
+			array_push($v,$this->objLayer[$i]->layer_name);
+			array_push($t,'s');		
+			$c++;
+		}
+		$sql .= ") ) )";
+		$sql .= " as relation ON  mb_metadata.metadata_id = relation.fkey_metadata_id AND mb_metadata.origin = 'capabilities')";
+		$res = db_prep_query($sql,$v,$t);		
+		//*******************************************
+		//TODO: is this done for the keywords too? Maybe not, cause they are stored only once! Only the relations have to be deleted!
+		//and then the layer entries
+		$v = array($myWMS);
+		$t = array('i');
+		$c = 2;
 		$sql = "DELETE FROM layer WHERE fkey_wms_id = $1 AND NOT layer_name IN(";
 		for($i=0; $i<count($this->objLayer); $i++){
 			if($i>0){$sql .= ',';}
@@ -2687,8 +2878,22 @@
 				$this->objLayer[$layer_cnt]->layer_uid = $layer_id;
 				$this->objLayer[$layer_cnt]->layer_name = administration::convertIncomingString($row2["layer_name"]);
 				$this->objLayer[$layer_cnt]->layer_title = administration::convertIncomingString($row2["layer_title"]);			
-				$this->objLayer[$layer_cnt]->layer_dataurl_href =$row2["layer_dataurl"];
-				$this->objLayer[$layer_cnt]->layer_metadataurl =$row2["layer_metadataurl"];
+				$this->objLayer[$layer_cnt]->layer_dataurl[0]->href =$row2["layer_dataurl"];
+				//load all metadataUrl elements from mb_metadata
+				$sql = "SELECT metadata_id, link, linktype, md_format FROM mb_metadata INNER JOIN (SELECT * from ows_relation_metadata WHERE fkey_layer_id = $1) as relation ON  mb_metadata.metadata_id = relation.fkey_metadata_id AND mb_metadata.origin = 'capabilities'";
+				$v = array($layer_id);
+				$t = array('i');
+				$res_metadataUrl = db_prep_query($sql,$v,$t);
+				$count_metadataUrl = 0;
+				while($row3 = db_fetch_array($res_metadataUrl)){
+					$this->objLayer[$layer_cnt]->layer_metadataurl[$count_metadataUrl]->href = $row3["link"];
+					$this->objLayer[$layer_cnt]->layer_metadataurl[$count_metadataUrl]->type = $row3["linktype"];
+					$this->objLayer[$layer_cnt]->layer_metadataurl[$count_metadataUrl]->format = $row3["md_format"];
+					
+					$count_metadataUrl++;
+				}
+				//old one:
+				//$this->objLayer[$layer_cnt]->layer_metadataurl[0]->href = $row2["layer_metadataurl"];
 				$this->objLayer[$layer_cnt]->layer_searchable =$row2["layer_searchable"];
 				$this->objLayer[$layer_cnt]->layer_pos =$row2["layer_pos"];						
 				$this->objLayer[$layer_cnt]->layer_queryable =$row2["layer_pos"];
@@ -2758,6 +2963,7 @@
 	* creatObjfromDBNoGui
 	*
 	*/ 
+	//TODO Update while editing metadata of wms will update the metadata - delete entries and read new ones - then they will be visible and cannot be set to inactive!
 	  function createObjFromDBNoGui($wms_id, $withProxyUrls = true){
 	   	$sql = "Select * from wms where wms_id = $1 ";
 		$v = array($wms_id);
@@ -2861,8 +3067,25 @@
 			$this->objLayer[$layer_cnt]->layer_title = administration::convertIncomingString($row2["layer_title"]);
 			$this->objLayer[$layer_cnt]->layer_abstract = administration::convertIncomingString($row2["layer_abstract"]);	
 			$this->objLayer[$layer_cnt]->gui_layer_title = $this->objLayer[$layer_cnt]->layer_title;			
-			$this->objLayer[$layer_cnt]->layer_dataurl_href =$row2["layer_dataurl"];
-			$this->objLayer[$layer_cnt]->layer_metadataurl =$row2["layer_metadataurl"];
+			$this->objLayer[$layer_cnt]->layer_dataurl[0]->href =$row2["layer_dataurl"];
+
+
+			//load all metadataUrl elements from mb_metadata
+			$sql = "SELECT metadata_id, link, linktype, md_format FROM mb_metadata INNER JOIN (SELECT * from ows_relation_metadata WHERE fkey_layer_id = $1) as relation ON  mb_metadata.metadata_id = relation.fkey_metadata_id AND mb_metadata.origin = 'capabilities'";
+			$v = array($this->objLayer[$layer_cnt]->layer_uid);
+			$t = array('i');
+			$res_metadataUrl = db_prep_query($sql,$v,$t);
+			$count_metadataUrl = 0;
+			while($row4 = db_fetch_array($res_metadataUrl)){
+				$this->objLayer[$layer_cnt]->layer_metadataurl[$count_metadataUrl]->href = $row4["link"];
+				$e = new mb_notice("nogui layer_metadataurl: ".$row4["link"]);
+				$this->objLayer[$layer_cnt]->layer_metadataurl[$count_metadataUrl]->type = $row4["linktype"];
+				$this->objLayer[$layer_cnt]->layer_metadataurl[$count_metadataUrl]->format = $row4["md_format"];
+					
+				$count_metadataUrl++;
+			}
+			//old one:
+			//$this->objLayer[$layer_cnt]->layer_metadataurl[0]->href = $row2["layer_metadataurl"];
 			$this->objLayer[$layer_cnt]->layer_searchable =$row2["layer_searchable"];
 			$this->objLayer[$layer_cnt]->layer_pos =$row2["layer_pos"];						
 			$this->objLayer[$layer_cnt]->layer_queryable =$row2["layer_queryable"];
@@ -3098,11 +3321,12 @@
 	var $layer_pos;
 	var $layer_queryable;
 	var $layer_minscale;
-	var $layer_maxscale;	
-    var $layer_dataurl_href;
-    var $layer_metadataurl;
+	var $layer_maxscale;
+	var $layer_dataurl;
+    	var $layer_dataurl_href;
+    	var $layer_metadataurl;
 	var $layer_searchable;
-    var $layer_keyword = array();
+    	var $layer_keyword = array();
 	var $layer_epsg = array();
 	var $layer_style = array();
 	var $layer_md_topic_category_id = array();



More information about the Mapbender_commits mailing list