[Mapbender-commits] r5490 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Feb 9 04:15:18 EST 2010


Author: armin11
Date: 2010-02-09 04:15:17 -0500 (Tue, 09 Feb 2010)
New Revision: 5490

Added:
   trunk/mapbender/http/php/mod_callMetadata.php
   trunk/mapbender/http/php/mod_metadataWrite.php
Log:
new files for the http metadata search service, merged from geoportal.rlp 

Added: trunk/mapbender/http/php/mod_callMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_callMetadata.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_callMetadata.php	2010-02-09 09:15:17 UTC (rev 5490)
@@ -0,0 +1,701 @@
+<?php
+#http://www.geoportal.rlp.de/mapbender/php/mod_callMetadata.php?searchText=sozial&outputFormat=json&resultTarget=web&searchResources=wfs
+#http://www.geoportal.rlp.de/mapbender/php/mod_callMetadata.php?searchText=sozial+schwanger&outputFormat=json&resultTarget=web&searchResources=wfs&registratingDepartments=72
+#http://www.geoportal.rlp.de/mapbender/php/mod_callMetadata.php?searchText=sozial&outputFormat=json&resultTarget=web&searchResources=wms&
+#http://www.geoportal.rlp.de/mapbender/php/mod_callMetadata.php?searchText=niedersachsen&outputFormat=json&resultTarget=web&searchResources=wms&maxResults=50
+#http://www.geoportal.rlp.de/mapbender/php/mod_callMetadata.php?searchId=wal&searchText=wald&outputFormat=json&resultTarget=web&searchResources=wms&maxResults=10
+#http://www.geoportal.rlp.de/mapbender/php/mod_callMetadata.php?searchId=test&searchText=e,w&outputFormat=json&registratingDepartments=44,33,29,30,31,35,40,61,101,87&languageCode=en&resultTarget=web&searchResources=wms&maxResults=10
+#http://www.geoportal.rlp.de/mapbender/php/mod_callMetadata.php?searchId=45&searchText=e&outputFormat=json&registratingDepartments=44,33,29,30,31,35,40,61,101,87&languageCode=en&resultTarget=debug&searchResources=wms&maxResults=10&searchPages=1&isoCategories=10
+#http://www.geoportal.rlp.de/mapbender/php/mod_callMetadata.php?searchId=45&searchText=e&outputFormat=json&registratingDepartments=44,33,29,30,31,35,40,61,101,87&languageCode=en&resultTarget=debug&searchResources=wms&maxResults=20&searchPages=1&isoCategories=10,5
+#http://www.geoportal.rlp.de/mapbender/php/mod_callMetadata.php?searchId=wa&searchText=e&outputFormat=json&languageCode=de&resultTarget=debug&searchResources=wms&maxResults=10&isoCategories=10,5&registratingDepartments=44,31
+#http://www.geoportal.rlp.de/mapbender/php/mod_callMetadata.php?searchId=wa&searchText=e&outputFormat=json&languageCode=de&resultTarget=debug&searchResources=wms&maxResults=5&registratingDepartments=44,31&inspireThemes=11&isoCategories=5,10
+#http://www.geoportal.rlp.de/mapbender/php/mod_callMetadata.php?searchId=wa&searchText=e&outputFormat=json&languageCode=de&resultTarget=debug&searchResources=wms&maxResults=5&registratingDepartments=44,31&inspireThemes=11&isoCategories=5,10
+#http://www.geoportal.rlp.de/mapbender/php/mod_callMetadata.php?searchId=wa&searchText=e&outputFormat=json&languageCode=de&resultTarget=debug&searchResources=wms&maxResults=5&registratingDepartments=44,31&inspireThemes=11&isoCategories=5,10&searchBbox=7,48,9,51
+#http://www.geoportal.rlp.de/mapbender/php/mod_callMetadata.php?searchId=wa&searchText=e&outputFormat=json&languageCode=de&resultTarget=debug&searchResources=wms&maxResults=99&registratingDepartments=44,31,52&inspireThemes=11&isoCategories=5,10&searchBbox=7,48,9,51&regTimeBegin=2001-12-24&regTimeEnd=2020-10-10
+#http://www.geoportal.rlp.de/mapbender/php/mod_callMetadata.php?searchId=wa&outputFormat=json&languageCode=de&resultTarget=debug&searchResources=wms&maxResults=99&registratingDepartments=44,31,52&inspireThemes=11&isoCategories=5,10&searchBbox=7,48,9,51&regTimeBegin=2001-12-24&regTimeEnd=2020-10-10
+require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/../classes/class_metadata_new.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+session_start();
+//initialize request parameters:
+$searchId = "dummysearch";
+$searchText = "e";
+#$registratingDepartments = "33,29,30,31,35,40,61,101,87,44";
+$registratingDepartments = NULL;
+#$isoCategories = "1,2,3";
+$isoCategories = NULL;
+$inspireThemes = NULL;
+$customCategories = NULL;
+$timeBegin = NULL;
+$timeEnd = NULL;
+$regTimeBegin = NULL;
+$regTimeEnd = NULL;
+$maxResults = 5;
+#$searchBbox = "-180.0,-90.0,180.0,90.0";
+$searchBbox = NULL;
+$searchTypeBbox = "intersects"; //outside / inside
+$accessRestrictions = "false"; 
+$languageCode = "de";
+$outputFormat = 'json';
+#$searchResources = "wms,wfs,wmc,georss";
+$searchResources = "wms";
+$searchPages = "1,1,1,1";
+$resultTarget = "debug";
+$searchEPSG = "EPSG:31466";
+$classJSON = new Mapbender_JSON;
+$tempFolder = "/tmp";
+
+
+
+//Read out request Parameter:
+if (isset($_REQUEST["searchId"]) & $_REQUEST["searchId"] != "") {
+	//gernerate md5 representation, cause the id is used as a filename later on! - no validation needed
+	$searchId = md5($_REQUEST["searchId"]);
+}
+if (isset($_REQUEST["searchText"]) & $_REQUEST["searchText"] != "") {
+	$test="(SELECT\s[\w\*\)\(\,\s]+\sFROM\s[\w]+)| (UPDATE\s[\w]+\sSET\s[\w\,\'\=]+)| (INSERT\sINTO\s[\d\w]+[\s\w\d\)\(\,]*\sVALUES\s\([\d\w\'\,\)]+)| (DELETE\sFROM\s[\d\w\'\=]+)";
+	//validate to csv integer list
+	$testMatch = $_REQUEST["searchText"];
+	$pattern = '/(\%27)|(\')|(\-\-)|(\")|(\%22)/';		
+ 	if (preg_match($pattern,$testMatch)){ 
+		echo 'searchText: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$searchText = $testMatch;
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["registratingDepartments"]) & $_REQUEST["registratingDepartments"] != "") {
+	//validate to csv integer list
+	$testMatch = $_REQUEST["registratingDepartments"];
+	$pattern = '/^[\d,]*$/';		
+ 	if (!preg_match($pattern,$testMatch)){ 
+		echo 'registratingDepartments: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$registratingDepartments = $testMatch;
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["isoCategories"]) & $_REQUEST["isoCategories"] != "") {
+	//validate to csv integer list
+	$testMatch = $_REQUEST["isoCategories"];
+	$pattern = '/^[\d,]*$/';		
+ 	if (!preg_match($pattern,$testMatch)){ 
+		echo 'isoCategories: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$isoCategories = $testMatch;
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["inspireThemes"]) & $_REQUEST["inspireThemes"] != "") {
+	//validate to csv integer list
+	$testMatch = $_REQUEST["inspireThemes"];
+	$pattern = '/^[\d,]*$/';		
+ 	if (!preg_match($pattern,$testMatch)){ 
+		echo 'inspireThemes: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$inspireThemes = $testMatch;
+	$testMatch = NULL;
+}
+
+if (isset($_REQUEST["customCategories"]) & $_REQUEST["customCategories"] != "") {
+	//validate to csv integer list
+	$testMatch = $_REQUEST["customCategories"];
+	$pattern = '/^[\d,]*$/';		
+ 	if (!preg_match($pattern,$testMatch)){ 
+		echo 'customCategories: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$customCategories = $testMatch;
+	$testMatch = NULL;
+}
+
+if (isset($_REQUEST["timeBegin"]) & $_REQUEST["timeBegin"] != "") {
+	//validate to iso date format YYYY-MM-DD
+	$testMatch = $_REQUEST["timeBegin"];
+	$pattern = '/^(19|20)[0-9]{2}[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/';		
+ 	if (!preg_match($pattern,$testMatch)){ 
+		echo 'timeBegin: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$timeBegin = $testMatch;
+	$testMatch = NULL;	
+}
+if (isset($_REQUEST["timeEnd"]) & $_REQUEST["timeEnd"] != "") {
+	$testMatch = $_REQUEST["timeEnd"];
+	$pattern = '/(19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])/';		
+ 	if (!preg_match($pattern,$testMatch)){ 
+		echo 'timeEnd: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$timeEnd = $testMatch;
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["regTimeBegin"]) & $_REQUEST["regTimeBegin"] != "") {
+	//validate to iso date format YYYY-MM-DD
+	$testMatch = $_REQUEST["regTimeBegin"];
+	$pattern = '/^(19|20)[0-9]{2}[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/';		
+ 	if (!preg_match($pattern,$testMatch)){ 
+		echo 'regTimeBegin: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$regTimeBegin = $testMatch;
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["regTimeEnd"]) & $_REQUEST["regTimeEnd"] != "") {
+	//validate to iso date format YYYY-MM-DD
+	$testMatch = $_REQUEST["regTimeEnd"];
+	$pattern = '/^(19|20)[0-9]{2}[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/';		
+ 	if (!preg_match($pattern,$testMatch)){ 
+		echo 'regTimeEnd: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$regTimeEnd = $testMatch;
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["maxResults"]) & $_REQUEST["maxResults"] != "") {
+	//validate integer to 100 - not more
+	$testMatch = $_REQUEST["maxResults"];
+	//give max 99 entries - more will be to slow
+	$pattern = '/^([0-9]{0,1})([0-9]{1})$/';		
+ 	if (!preg_match($pattern,$testMatch)){ 
+		echo 'maxResults: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$maxResults = $testMatch;
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["searchBbox"]) & $_REQUEST["searchBbox"] != "") {
+	//validate to csv integer list
+	$testMatch = $_REQUEST["searchBbox"];
+	$pattern = '/^[-\d,]*$/';		
+ 	if (!preg_match($pattern,$testMatch)){ 
+		echo 'searchBbox: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	if (count(explode(',',$testMatch)) != 4) {
+		echo 'searchBbox: <b>'.$testMatch.'</b> has a wrong amount of entries.<br/>'; 
+		die(); 
+	}
+	$searchBbox = $testMatch;
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["searchTypeBbox"]) & $_REQUEST["searchTypeBbox"] != "") {
+	//validate to inside / outside - TODO implement other ones than intersects which is default
+	$testMatch = $_REQUEST["searchTypeBbox"];	
+ 	if (!($testMatch == 'inside' or $testMatch == 'outside')){ 
+		echo 'searchTypeBbox: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	#$searchTypeBbox = $testMatch; //TODO activate this
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["accessRestrictions"]) & $_REQUEST["accessRestrictions"] != "") {
+	//validate to ?
+	#TODO implement me //$accessRestrictions = $_REQUEST["accessRestrictions"];
+}
+if (isset($_REQUEST["languageCode"]) & $_REQUEST["languageCode"] != "") {
+	//validate to de, en, fr
+	$testMatch = $_REQUEST["languageCode"];	
+ 	if (!($testMatch == 'de' or $testMatch == 'en' or $testMatch == 'fr')){ 
+		echo 'languageCode: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$languageCode = $testMatch;
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["outputFormat"]) & $_REQUEST["outputFormat"] != "") {
+	$testMatch = $_REQUEST["outputFormat"];	
+ 	if (!($testMatch == 'json' or $testMatch == 'georss')){ 
+		echo 'outputFormat: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$outputFormat = $testMatch;
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["searchResources"]) & $_REQUEST["searchResources"] != "") {
+	//validate to wms,wfs,wmc,georss
+	$testMatch = $_REQUEST["searchResources"];
+	#$pattern = '/^(19|20)[0-9]{2}[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/';
+	$countSR = count(explode(',',$testMatch));
+ 	if (!($countSR >= 1 && $countSR <= 4)){ 
+		echo 'searchResources: <b>'.$testMatch.'</b> count of requested resources out of sync.<br/>'; 
+		die(); 		
+ 	} else {
+		$testArray = explode(',',$testMatch);
+		for($i=0; $i<count($testArray);$i++){
+			if (!($testArray[$i] == 'wms' or $testArray[$i] == 'wfs' or $testArray[$i] == 'wmc' or $testArray[$i] == 'georss')) {
+			echo 'searchResources: <b>'.$testMatch.'</b>at least one of them does not exists!<br/>'; 
+			die();
+			}
+		}
+		unset($i);
+	}
+	$searchResources = $testMatch;
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["searchPages"]) & $_REQUEST["searchPages"] != "") {
+	//validate to csv integer list with dimension of searchResources list
+	$testMatch = $_REQUEST["searchPages"];
+	$pattern = '/^[-\d,]*$/';		
+ 	if (!preg_match($pattern,$testMatch)){ 
+		echo 'searchPages: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	if (count(explode(',',$testMatch)) != count(explode(',',$searchResources))) {
+		echo 'searchPages: <b>'.$testMatch.'</b> has a wrong amount of entries.<br/>'; 
+		die(); 
+	}
+	$searchPages = $testMatch;
+	$testMatch = NULL;
+
+
+
+
+
+
+
+$searchPages = $_REQUEST["searchPages"];
+	#$searchPages = split(',',$searchPages);
+	
+}
+if (isset($_REQUEST["resultTarget"]) & $_REQUEST["resultTarget"] != "") {
+	//validate to web,debug,file
+	$testMatch = $_REQUEST["resultTarget"];	
+ 	if (!($testMatch == 'web' or $testMatch == 'debug' or $testMatch == 'file')){ 
+		echo 'resultTarget: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$resultTarget = $testMatch;
+	$testMatch = NULL;
+}
+//validate request parameters
+if (!isset($_SESSION['mb_user_id'])) {
+	$userId = ANONYMOUS_USER;	
+}
+else
+{
+	$userId = $_SESSION['mb_user_id'];
+}
+
+#$searchResources = array('wms','wfs','wmc','georss');
+#$searchPages = array(1,1,1,1);
+
+//TODO: if class is called directly
+	#$registratingDepartments = explode(",",$registratingDepartments);
+	#$isoCategories = explode(",",$isoCategories);
+	#$inspireThemes = explode(",",$inspireThemes);
+	#$searchBbox = explode(",",$searchBbox);
+	$searchResources = explode(",",$searchResources);
+	$searchPages = explode(",",$searchPages);
+
+//*****************************************************************
+//read the whole query string:
+$searchURL = $_SERVER['QUERY_STRING'];
+if ($resultTarget == 'debug') {
+	echo "<br>DEBUG: searchURL: ".$searchURL."<br>";
+	#echo "<br>DEBUG: languageCode: ".$languageCode."<br>";
+}
+
+
+
+
+//Generate search filter file. This file holds the defined search filter to allow the user to see how he searched 
+//The user should become the possibility to drop the search filters by clicking in some buttons
+//list of options to display:
+//searchText (textfields) - dropping only if more than one text is given
+//registratingDepartments (list) - dropping allowed - maybe give a webservice for mb_group data
+//isoCategories - dropping allowed
+//inspireThemes - dropping allowed
+//customCategories - dropping allowed
+//bbox (show) - dropping allowed
+//regTimeBegin - dropping allowed
+//regTimeEnd -dropping allowed
+//the idea is, to rewrite the searchURL directly and then have another url for the special case!
+//we have to get the searchURL as a parameter for this wrapper cause the class_metadata should give filters for the found categories
+//use regular expressions to do this!
+
+//define internationalization
+//searchText
+//registratingDepartments
+//bbox
+
+//generate query json:
+//some objects like names of categories and other objects have to be pulled of the database. Maybe a webservice is the better way? But now there are no webservices - therefor: pull the names out of the database into arrays - only those who are requested:
+
+//function to get the information about the registrating departments (mb_groups) out of the mapbender database
+function get_registratingDepartmentsArray($departmentIds,$languageCode) {
+			$sql = "SELECT mb_group_id, mb_group_name FROM mb_group WHERE mb_group_id IN (";
+			$v = array();
+			$t = array();
+			$departmentsArray = array();
+			for($i=0; $i<count($departmentIds);$i++){
+				if($i > 0){$sql .= ",";}
+				$sql .= "$".strval($i+1);
+				array_push($v,$departmentIds[$i]);
+				array_push($t,"i");
+			}
+			$sql .= ")";
+			$res = db_prep_query($sql,$v,$t);
+			$countDepArray = 0;
+			while($row = db_fetch_array($res)){
+				$departmentsArray[$countDepArray]["id"] = $row["mb_group_id"];
+				$departmentsArray[$countDepArray]["name"] = $row["mb_group_name"];
+				$departmentsArray[$countDepArray]["showScript"] = "../php/mod_showRegistratingGroup.php?";
+				$countDepArray = $countDepArray + 1; 
+			}
+			return $departmentsArray;
+		}
+
+//get the information about the requested isoCategories
+function get_isoCategoriesArray($isoCategoryIds,$languageCode) {
+			
+			$sql = "SELECT md_topic_category_id, md_topic_category_code_".$languageCode;
+			#$e = new mb_exception("php/mod_callMetadata.php: language code: ".$languageCode);
+			$sql .= " FROM md_topic_category WHERE md_topic_category_id IN (";
+			$v = array();
+			$t = array();
+			$isoCategoryArray = array();
+			for($i=0; $i<count($isoCategoryIds);$i++){
+				if($i > 0){$sql .= ",";}
+				$sql .= "$".strval($i+1);
+				array_push($v,$isoCategoryIds[$i]);
+				array_push($t,"i");
+			}
+			$sql .= ")";
+			#$e = new mb_exception("php/mod_callMetadata.php: sql for getting topic cats: ".$sql);
+			$res = db_prep_query($sql,$v,$t);
+			$countIsoArray = 0;
+			while($row = db_fetch_array($res)){
+				$isoCategoryArray[$countIsoArray]["id"] = $row["md_topic_category_id"];
+				$isoCategoryArray[$countIsoArray]["name"] = $row["md_topic_category_code_".$languageCode];
+				$countIsoArray = $countDepArray + 1; 
+			}
+			return $isoCategoryArray;
+		}
+
+//get the information about the inspireThemes
+function get_inspireThemesArray($inspireThemesIds,$languageCode) {
+			$sql = "SELECT inspire_category_id, inspire_category_code_".$languageCode." FROM inspire_category WHERE inspire_category_id IN (";
+			$v = array();
+			$t = array();
+			$inspireCategoryArray = array();
+			for($i=0; $i<count($inspireThemesIds);$i++){
+				if($i > 0){$sql .= ",";}
+				$sql .= "$".strval($i+1);
+				array_push($v,$inspireThemesIds[$i]);
+				array_push($t,"i");
+			}
+			$sql .= ")";
+			$e = new mb_exception("php/mod_callMetadata.php: sql for getting inspire cats: ".$sql);
+			$res = db_prep_query($sql,$v,$t);
+			$countInspireArray = 0;
+			while($row = db_fetch_array($res)){
+				$inspireCategoryArray[$countInspireArray]["id"] = $row["inspire_category_id"];
+				$inspireCategoryArray[$countInspireArray]["name"] = $row["inspire_category_code_".$languageCode];
+				$countInspireArray = $countInspireArray + 1; 
+			}
+			return $inspireCategoryArray;
+		}
+
+function get_customCategoriesArray($customCategoriesIds,$languageCode) {
+			$sql = "SELECT custom_category_id, custom_category_code_".$languageCode." FROM custom_category WHERE custom_category_id IN (";
+			$v = array();
+			$t = array();
+			$customCategoryArray = array();
+			for($i=0; $i<count($customCategoriesIds);$i++){
+				if($i > 0){$sql .= ",";}
+				$sql .= "$".strval($i+1);
+				array_push($v,$customCategoriesIds[$i]);
+				array_push($t,"i");
+			}
+			$sql .= ")";
+			$e = new mb_exception("php/mod_callMetadata.php: sql for getting custom cats: ".$sql);
+			$res = db_prep_query($sql,$v,$t);
+			$countCustomArray = 0;
+			while($row = db_fetch_array($res)){
+				$customCategoryArray[$countCustomArray]["id"] = $row["custom_category_id"];
+				$customCategoryArray[$countCustomArray]["name"] = $row["custom_category_code_".$languageCode];
+				$countCustomArray = $countCustomArray + 1; 
+			}
+			return $customCategoryArray;
+		}
+
+
+
+
+
+
+
+//define where to become the information from - this is relavant for the information which must be pulled out of the database
+$classificationElements = array();
+
+$classificationElements[0]['name'] = 'searchText';
+$classificationElements[1]['name'] = 'registratingDepartments';
+$classificationElements[2]['name'] = 'isoCategories';
+$classificationElements[3]['name'] = 'inspireThemes';
+$classificationElements[4]['name'] = 'customCategories';
+$classificationElements[5]['name'] = 'searchBbox';
+$classificationElements[6]['name'] = 'regTimeBegin';
+$classificationElements[7]['name'] = 'regTimeEnd';
+
+$classificationElements[0]['source'] = '';
+$classificationElements[1]['source'] = 'database';
+$classificationElements[2]['source'] = 'database';
+$classificationElements[3]['source'] = 'database';
+$classificationElements[4]['source'] = 'database';
+$classificationElements[5]['source'] = '';
+$classificationElements[6]['source'] = '';
+$classificationElements[7]['source'] = '';
+
+$classificationElements[0]['list'] = true;
+$classificationElements[1]['list'] = true;
+$classificationElements[2]['list'] = true;
+$classificationElements[3]['list'] = true;
+$classificationElements[4]['list'] = true;
+$classificationElements[5]['list'] = false;
+$classificationElements[6]['list'] = false;
+$classificationElements[7]['list'] = false;
+
+
+
+switch($languageCode){
+        case 'de':
+        	$classificationElements[0]['name2show'] = 'Suchbegriff(e):';
+		$classificationElements[1]['name2show'] = 'Anbietende Stelle(n):';
+		$classificationElements[3]['name2show'] = 'INSPIRE Themen:';
+		$classificationElements[2]['name2show'] = 'ISO Kategorien:';
+		$classificationElements[4]['name2show'] = 'RP Kategorien:';
+		$classificationElements[5]['name2show'] = 'Räumliche Einschränkung:';
+		$classificationElements[6]['name2show'] = 'Registrierung/Aktualisierung von:';
+		$classificationElements[7]['name2show'] = 'Registrierung/Aktualisierung bis:';
+	
+       	break;
+        case 'en':
+        	$classificationElements[0]['name2show'] = 'Search Term(s):';
+		$classificationElements[1]['name2show'] = 'Department(s):';
+		$classificationElements[3]['name2show'] = 'INSPIRE Themes:';
+		$classificationElements[2]['name2show'] = 'ISO Topic Categories:';
+		$classificationElements[4]['name2show'] = 'RP Categories:';
+		$classificationElements[5]['name2show'] = 'Spatial Filter:';
+		$classificationElements[6]['name2show'] = 'Registration/Update from:';
+		$classificationElements[7]['name2show'] = 'Registration/Update till:';
+
+        break;
+        case 'fr':
+        	$classificationElements[0]['name2show'] = 'Suchbegriff(e):';
+		$classificationElements[1]['name2show'] = 'Anbietende Stelle(n):';
+		$classificationElements[3]['name2show'] = 'INSPIRE Themen:';
+		$classificationElements[2]['name2show'] = 'ISO Kategorien:';
+		$classificationElements[4]['name2show'] = 'RP Kategorien:';
+		$classificationElements[5]['name2show'] = 'Räumliche Einschränkung:';
+		$classificationElements[6]['name2show'] = 'Registrierung/Aktualisierung von:';
+		$classificationElements[7]['name2show'] = 'Registrierung/Aktualisierung bis:';
+
+       	break;
+     	default:
+        	$classificationElements[0]['name2show'] = 'Suchbegriff(e):';
+		$classificationElements[1]['name2show'] = 'Anbietende Stelle(n):';
+		$classificationElements[3]['name2show'] = 'INSPIRE Themen:';
+		$classificationElements[2]['name2show'] = 'ISO Kategorien:';
+		$classificationElements[4]['name2show'] = 'RP Kategorien:';
+		$classificationElements[5]['name2show'] = 'Räumliche Einschränkung:';
+		$classificationElements[6]['name2show'] = 'Registrierung/Aktualisierung von:';
+		$classificationElements[7]['name2show'] = 'Registrierung/Aktualisierung bis:';
+
+}	
+
+$queryJSON = new stdClass;
+$queryJSON->searchFilter = (object) array();
+
+//generate search filter file - if more categories are defined give 
+#echo "<br> number of filter elements: ".count($classificationElements)."<br>";
+for($i=0; $i < count($classificationElements); $i++){
+	if (isset(${$classificationElements[$i]['name']}) & ${$classificationElements[$i]['name']} !='' & ${$classificationElements[$i]['name']} != NULL) {
+		//pull register information out of database in arrays
+		if ($classificationElements[$i]['source'] == 'database') {
+			$funcName = "get_".$classificationElements[$i]['name']."Array";
+			${$classificationElements[$i]['name']."Array"} = $funcName(explode(',',${$classificationElements[$i]['name']}),$languageCode);
+		}
+		$queryJSON->searchFilter->{$classificationElements[$i]['name']}->title = $classificationElements[$i]['name2show'];
+		//check if the filter has subfilters - if not delete the whole filter from query
+		if ($classificationElements[$i]['list'] == false) { //the object has no subsets - like bbox or time filters
+			$queryJSON->searchFilter->{$classificationElements[$i]['name']}->delLink = delTotalFromQuery($classificationElements[$i]['name'],$searchURL);
+		} else {
+
+
+
+			//TODO delete all entries of this main category (not for searchText)
+			if ($classificationElements[$i]['name'] != 'searchText') { 
+				$queryJSON->searchFilter->{$classificationElements[$i]['name']}->delLink = delTotalFromQuery($classificationElements[$i]['name'],$searchURL);
+			} else {
+				$queryJSON->searchFilter->{$classificationElements[$i]['name']}->delLink = NULL;
+			}
+			$queryJSON->searchFilter->{$classificationElements[$i]['name']}->item = array();
+			$queryArray = explode(',',${$classificationElements[$i]['name']});
+			//loop for the subcategories
+			for($j=0; $j < count($queryArray); $j++){
+				if ($classificationElements[$i]['source'] == 'database') {
+					$identArray = ${$classificationElements[$i]['name']."Array"};
+					$identArray = flipDiagonally($identArray);
+					//find searched id in information from database
+					$key = array_search($queryArray[$j], $identArray['id']);
+					if ($key === false) {
+						$queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[$j]->title = "no information found in database";
+					} else {
+						$queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[$j]->title = ${$classificationElements[$i]['name']."Array"}[$key]['name'];
+					}
+				} else {
+					$queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[$j]->title = $queryArray[$j];
+				}
+				//generate links to disable filters on a simple way
+				if ($classificationElements[$i]['name'] === 'searchText' & count(explode(',',${$classificationElements[$i]['name']})) === 1) { 
+					$queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[$j]->delLink = NULL;
+				} else {
+					$newSearchLink = delFromQuery($classificationElements[$i]['name'], $searchURL,$queryArray[$j],$queryArray,${$classificationElements[$i]['name']});
+					$newSearchLink = delTotalFromQuery('searchId',$newSearchLink);
+					$queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[$j]->delLink = $newSearchLink;
+				}
+			}
+		}
+	}	
+}
+
+//write out json to file or web
+
+
+	
+$queryFilter = $classJSON->encode($queryJSON);
+
+if ($resultTarget == 'debug') {
+	echo "<br>DEBUG: filter: ".$queryFilter."<br>";
+	#echo "<br>DEBUG: searchTypeBbox: ".$searchTypeBbox."<br>";
+}
+if ($resultTarget == 'file') {
+	$filename = $tempFolder."/".$searchId."_filter.json";
+	if($catFileHandle = fopen($filename, "w")){
+		fwrite($catFileHandle,$queryFilter);
+		fclose($catFileHandle);
+		$e = new mb_notice("php/callMetdata.php: new filter_file created!");
+	} else {
+		$e = new mb_notice("php/callMetdata.php: cannot create filter_file!");
+	}
+}
+//function to transpose a matrix - sometimes needed to do an array search
+function flipDiagonally($arr) {
+    	$out = array();
+    	foreach ($arr as $key => $subarr) {
+      		foreach ($subarr as $subkey => $subvalue) {
+        		$out[$subkey][$key] = $subvalue;
+       		}
+    	}
+   	return $out;
+}
+
+//function to delete one of the comma separated values from one get request
+function delFromQuery($paramName,$queryString,$string,$queryArray,$queryList) {
+	//check if if count searchArray = 1
+	if (count($queryArray) == 1){
+		//remove request parameter from url by regexpr or replace
+		$str2search = $paramName."=".$queryList;
+		$str2exchange = "";
+		$queryStringNew = str_replace($str2search, $str2exchange, $queryString);
+		$queryStringNew = str_replace("&&", "&", $queryStringNew);
+	} else {
+	//there are more than one filter - reduce the filter  
+		$objectList = "";
+		for($i=0; $i < count($queryArray); $i++){
+			if ($queryArray[$i] != $string){
+				$objectList .= $queryArray[$i].",";		
+			} 
+		}
+		//remove last comma
+		$objectList = rtrim($objectList, ",");
+		$str2search = $paramName."=".$queryList;
+		$str2exchange = $paramName."=".$objectList;
+		$queryStringNew = str_replace($str2search, $str2exchange, $queryString);
+	}
+	return $queryStringNew;
+}
+
+//function to remove one complete get param out of the query
+function delTotalFromQuery($paramName,$queryString) {
+	$queryString = "&".$queryString;
+	$queryStringNew = preg_replace('/\b'.$paramName.'\=[^&]+&?/',"",$queryString);
+	$queryStringNew = ltrim($queryStringNew,'&');
+	$queryStringNew = rtrim($queryStringNew,'&');
+	return $queryStringNew;
+}
+
+
+
+//call class_metadata - in case of file for all requested resources, in case of web only for one resource - cause there are different result files
+if ($resultTarget == 'file') {
+	for($i=0; $i<count($searchResources);$i++){
+		$str = "nohup php5 /data/mapbender/http/php/mod_metadataWrite.php ";
+		$str .= "'".$userId."' ";		
+		$str .= "'".$searchId."' ";		
+		$str .= "'".$searchText."' "; 		
+		$str .= "'".$registratingDepartments."' ";						
+		$str .= "'".$isoCategories."' ";							
+		$str .= "'".$inspireThemes."' ";
+		$str .= "'".$timeBegin."' ";
+		$str .= "'".$timeEnd."' ";
+		$str .= "'".$regTimeBegin."' ";
+		$str .= "'".$regTimeEnd."' ";
+		$str .= "'".$maxResults."' ";
+		$str .= "'".$searchBbox."' ";
+		$str .= "'".$searchTypeBbox."' ";
+		$str .= "'".$accessRestrictions."' ";
+		$str .= "'".$languageCode."' ";
+		$str .= "'".$searchEPSG."' ";
+		$str .= "'".$searchResources[$i]."' ";
+		$str .= "'".$searchPages[$i]."' ";
+		$str .= "'".$outputFormat."' ";
+		$str .= "'".$resultTarget."' ";
+		$str .= "'".$searchURL."' ";
+		$str .= "'".$customCategories."' ";
+		$str .= " & ";
+		$e = new mb_exception($str);
+		exec($str);
+	}
+}
+if ($resultTarget == 'web' or $resultTarget == 'debug') {
+	if (count($searchResources) == 1) {
+		$metadata = new searchMetadata($userId, $searchId, $searchText, $registratingDepartments, $isoCategories, $inspireThemes, $timeBegin, $timeEnd, $regTimeBegin, $regTimeEnd, $maxResults, $searchBbox, $searchTypeBbox, $accessRestrictions, $languageCode, $searchEPSG, $searchResources[0], $searchPages[0], $outputFormat, $resultTarget, $searchURL, $customCategories);
+		#if ($outputFormat == 'xml') {
+		#	header("Content-type: application/xhtml+xml; charset=UTF-8");		
+		#}
+		#echo "class initiated<br>";
+	}
+	else {
+		echo "Result for web can only requested for one type of resource (wms, wfs, wmc, georss)!";
+	}
+}
+/*
+How does the webservice look like?
+First request: Do search for all classes. 
+Next request: Search only in the requested class and the numbered page.
+search.php?q=test&classes=wms,wfs,wmc,georss&pages=1,1,1,1&iso=1,2,3&inspire=1,2,3,4&department=1,2,3,4&bbox=123,123,123,123
+simple other request:
+search.php?q=test&classes=wms&pages=2&iso=1,2,3&inspire=1,2,3,4&department=1,2,3,4&beginDate=2009-10-10&endDate=2010-11-12&searchId=12hjxa31231
+There is a possibility to exchange some classes by other information - the id will be used to update the search result files - but this can only update the class infos. The pagenumber should be updated in the metadata file
+*/
+//
+//Name of searchMetadata file
+//searchid_classes.json
+//Name of searchCategories file
+//Name of searchResult files
+//searchid_wms_1.json
+//searchid_wfs_1.json
+//searchid_wmc_1.json - doesn't exists till now
+//searchid_georss_1.json - doesn't exists till now
+//categories files - will only be generated when the search is started and resultType = 'file'. if the categories files already exists it will not be updated! - Here we can spare a reasonable amount of calculating power. Another approach is to generate a md5 hash of an ordered searchURL. With this we can cache the requests!
+
+//searchid_wms_cat.json
+//searchid_wfs_cat.json
+//searchid_wmc_cat.json - doesn't exists till now
+//searchid_georss_cat.json - doesn't exists till now
+//searchid_filter.json
+
+?>
\ No newline at end of file

Added: trunk/mapbender/http/php/mod_metadataWrite.php
===================================================================
--- trunk/mapbender/http/php/mod_metadataWrite.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_metadataWrite.php	2010-02-09 09:15:17 UTC (rev 5490)
@@ -0,0 +1,26 @@
+<?php
+require_once(dirname(__FILE__)."/../classes/class_metadata_new.php");
+$userId = $_SERVER["argv"][1];
+$searchId = $_SERVER["argv"][2];
+$searchText = $_SERVER["argv"][3];
+$registratingDepartments = $_SERVER["argv"][4];
+$isoCategories = $_SERVER["argv"][5];
+$inspireThemes = $_SERVER["argv"][6];
+$timeBegin = $_SERVER["argv"][7];
+$timeEnd = $_SERVER["argv"][8];
+$regTimeBegin = $_SERVER["argv"][9];
+$regTimeEnd = $_SERVER["argv"][10];
+$maxResults = $_SERVER["argv"][11];
+$searchBbox = $_SERVER["argv"][12];
+$searchTypeBbox = $_SERVER["argv"][13];
+$accessRestrictions = $_SERVER["argv"][14];
+$languageCode = $_SERVER["argv"][15];
+$searchEPSG = $_SERVER["argv"][16];
+$searchResources = $_SERVER["argv"][17];
+$searchPages = $_SERVER["argv"][18];
+$outputFormat = $_SERVER["argv"][19];
+$resultTarget = $_SERVER["argv"][20];
+$searchURL = $_SERVER["argv"][21];
+$customCategories = $_SERVER["argv"][22];
+$metadata = new searchMetadata($userId, $searchId, $searchText, $registratingDepartments, $isoCategories, $inspireThemes, $timeBegin, $timeEnd, $regTimeBegin, $regTimeEnd, $maxResults, $searchBbox, $searchTypeBbox, $accessRestrictions, $languageCode, $searchEPSG, $searchResources, $searchPages, $outputFormat, $resultTarget, $searchURL,$customCategories);
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list