'.$testMatch.' is not valid.
';
die();
}
$searchText = $testMatch;
$testMatch = NULL;
if ($searchText ==='false') {
$searchText ='*';
}
}
if (isset($_REQUEST["registratingDepartments"]) & $_REQUEST["registratingDepartments"] != "") {
//validate to csv integer list
$testMatch = $_REQUEST["registratingDepartments"];
$pattern = '/^[\d,]*$/';
if (!preg_match($pattern,$testMatch)){
echo 'registratingDepartments: '.$testMatch.' is not valid.
';
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: '.$testMatch.' is not valid.
';
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: '.$testMatch.' is not valid.
';
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: '.$testMatch.' is not valid.
';
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: '.$testMatch.' is not valid.
';
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: '.$testMatch.' is not valid.
';
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: '.$testMatch.' is not valid.
';
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: '.$testMatch.' is not valid.
';
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: '.$testMatch.' is not valid.
';
die();
}
$maxResults = $testMatch;
$testMatch = NULL;
}
if (isset($_REQUEST["searchBbox"]) & $_REQUEST["searchBbox"] != "") {
//validate to float/integer
$testMatch = $_REQUEST["searchBbox"];
//$pattern = '/^[-\d,]*$/';
$pattern = '/^[-+]?([0-9]*\.[0-9]+|[0-9]+)*$/';
$testMatchArray = explode(',',$testMatch);
if (count($testMatchArray) != 4) {
echo 'searchBbox: '.$testMatch.' has a wrong amount of entries.
';
die();
}
for($i=0; $i'.$testMatchArray[$i].' is not a valid coordinate value.
';
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' or $testMatch == 'intersects')){
echo 'searchTypeBbox: '.$testMatch.' is not valid.
';
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: '.$testMatch.' is not valid.
';
die();
}
$languageCode = $testMatch;
$testMatch = NULL;
}
if (isset($_REQUEST["outputFormat"]) & $_REQUEST["outputFormat"] != "") {
$testMatch = $_REQUEST["outputFormat"];
if (!($testMatch == 'json' or $testMatch == 'georss')){
echo 'outputFormat: '.$testMatch.' is not valid.
';
die();
}
$outputFormat = $testMatch;
$testMatch = NULL;
}
if (isset($_REQUEST["hostName"]) & $_REQUEST["hostName"] != "") {
$testMatch = $_REQUEST["hostName"];
if (!($testMatch == 'www.geoportal.rlp' or $testMatch == 'www.geoportal.rlp.de' or $testMatch == 'geoportal.rlp' or $testMatch == '10.7.101.151' or $testMatch == 'localhost:16580' or $testMatch == 'localhost' or $testMatch == 'www.gdi-rp-dienste3.rlp.de' )){
echo 'hostName: '.$testMatch.' is not valid.
';
die();
}
$hostName = $testMatch;
$testMatch = NULL;
}
if (isset($_REQUEST["orderBy"]) & $_REQUEST["orderBy"] != "") {
$testMatch = $_REQUEST["orderBy"];
if (!($testMatch == 'rank' or $testMatch == 'title' or $testMatch == 'id' or $testMatch == 'date')){
echo 'orderBy: '.$testMatch.' is not valid.
';
die();
}
$orderBy = $testMatch;
$testMatch = NULL;
}// else {
//$orderBy= 'rank';
//}
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: '.$testMatch.' count of requested resources out of sync.
';
die();
} else {
$testArray = explode(',',$testMatch);
for($i=0; $i'.$testMatch.'at least one of them does not exists!
';
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: '.$testMatch.' is not valid.
';
die();
}
if (count(explode(',',$testMatch)) != count(explode(',',$searchResources))) {
echo 'searchPages: '.$testMatch.' has a wrong amount of entries.
';
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: '.$testMatch.' is not valid.
';
die();
}
$resultTarget = $testMatch;
$testMatch = NULL;
}
if (isset($_REQUEST["userId"]) & $_REQUEST["userId"] != "") {
//validate integer to 100 - not more
$testMatch = $_REQUEST["userId"];
//give max 99 entries - more will be to slow
$pattern = '/^[0-9]*$/';
if (!preg_match($pattern,$testMatch)){
echo 'userId: '.$testMatch.' is not valid.
';
die();
}
$userId = $testMatch;
$testMatch = NULL;
} else {
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
if ($resultTarget == 'debug') {
echo "
DEBUG: searchURL: ".$searchURL."
";
#echo "
DEBUG: languageCode: ".$languageCode."
";
}
if ($resultTarget == 'file') {
if (!isset($searchResources) OR ($searchResources == "")) {
$searchResources = "wms,wfs,wmc";
$searchPages = "1,1,1";
}
}
if ($resultTarget == 'web' or $resultTarget == 'debug') {
if (!isset($searchResources) OR ($searchResources == "")) {
$searchResources = "wms";
$searchPages = "1";
}
}
//convert the respources and the pagenumbers into arrays
$searchResources = explode(",",$searchResources);
$searchPages = explode(",",$searchPages);
//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 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 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 = $countIsoArray + 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 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 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;
//Defining of the different result categories
$resourceCategories = array();
#$resourceCategories[0]['wms'] = 'WMS';
#$resourceCategories[1]['wfs'] = 'WFS';
#$resourceCategories[2]['wmc'] = 'WMC';
#$resourceCategories[3]['georss'] = 'directAccessData';
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:';
$resourceCategories['wms'] = 'Darstellungsdienste';
$resourceCategories['wfs'] = 'Such- und Download- und Erfassungsmodule';
$resourceCategories['wmc'] = 'Kartenzusammenstellungen';
$resourceCategories['georss'] = 'KML/Newsfeeds';
$orderByTitle['header'] = 'Sortierung nach:';
$orderByTitle['id'] = 'ID';
$orderByTitle['title'] = 'Titel';
$orderByTitle['rank'] = 'Relevanz';
$orderByTitle['date'] = 'Letzte Änderung';
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:';
$resourceCategories['wms'] = 'Viewingservices';
$resourceCategories['wfs'] = 'Search- and Downloadservices';
$resourceCategories['wmc'] = 'Combined Maps';
$resourceCategories['georss'] = 'KML/Newsfeeds';
$orderByTitle['header'] = 'Sort by:';
$orderByTitle['id'] = 'ID';
$orderByTitle['title'] = 'title';
$orderByTitle['rank'] = 'relevance';
$orderByTitle['date'] = 'last change';
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:';
$resourceCategories['wms'] = 'Viewingservices';
$resourceCategories['wfs'] = 'Search- and Downloadservices';
$resourceCategories['wmc'] = 'Combined Maps';
$resourceCategories['georss'] = 'KML/Newsfeeds';
$orderByTitle['header'] = 'Sort by:';
$orderByTitle['id'] = 'identification';
$orderByTitle['title'] = 'title';
$orderByTitle['rank'] = 'relevance';
$orderByTitle['date'] = 'last change';
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:';
$resourceCategories['wms'] = 'Darstellungsdienste';
$resourceCategories['wfs'] = 'Such- und Downloaddienste';
$resourceCategories['wmc'] = 'Kartenzusammenstellungen';
$resourceCategories['georss'] = 'KML/Newsfeeds';
$orderByTitle['header'] = 'Sortierung nach:';
$orderByTitle['id'] = 'ID';
$orderByTitle['title'] = 'Titel';
$orderByTitle['rank'] = 'Relevanz';
$orderByTitle['date'] = 'Letzte Änderung';
}
$queryJSON = new stdClass;
$queryJSON->searchFilter = (object) array();
$queryJSON->searchFilter->origURL = $searchURL;
#$queryJSON->searchFilter->classes = (object) array();
for($i=0; $isearchFilter->classes[$i]->title = $resourceCategories[$searchResources[$i]];
$queryJSON->searchFilter->classes[$i]->name = $searchResources[$i];
}
//generate search filter file - if more categories are defined give
#echo "
number of filter elements: ".count($classificationElements)."
";
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);
$queryJSON->searchFilter->{$classificationElements[$i]['name']}->item = array();
if ($classificationElements[$i]['name'] == 'searchBbox') {
$sBboxTitle = $searchTypeBbox." ".${$classificationElements[$i]['name']};
$queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[0]->title = $sBboxTitle;
}
else {
$queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[0]->title = ${$classificationElements[$i]['name']};
}
$queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[0]->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;
}
}
}
}
}
//generate filter for different order possibilities
//$queryJSON->searchFilter = (object) array();
if ($_REQUEST["orderBy"] == '') {
//echo "
orderBy:>".$_REQUEST["orderBy"]."<
";
$queryJSON->searchFilter->orderFilter->title = $orderByTitle['rank'];
$queryJSON->searchFilter->orderFilter->item[0]->title = $orderByTitle['title'];
$queryJSON->searchFilter->orderFilter->item[0]->url = $searchURL."&orderBy=title";
$queryJSON->searchFilter->orderFilter->item[1]->title = $orderByTitle['id'];
$queryJSON->searchFilter->orderFilter->item[1]->url = $searchURL."&orderBy=id";
$queryJSON->searchFilter->orderFilter->item[2]->title = $orderByTitle['date'];
$queryJSON->searchFilter->orderFilter->item[2]->url = $searchURL."&orderBy=date";
} else {
//read out actual order filter
switch ($orderBy) {
case "rank":
$queryJSON->searchFilter->orderFilter->title = $orderByTitle['rank'];
$queryJSON->searchFilter->orderFilter->item[0]->title = $orderByTitle['id'];
$queryJSON->searchFilter->orderFilter->item[0]->url = str_replace("orderBy=rank", "orderBy=id", $searchURL);
$queryJSON->searchFilter->orderFilter->item[1]->title = $orderByTitle['title'];
$queryJSON->searchFilter->orderFilter->item[1]->url = str_replace("orderBy=rank", "orderBy=title", $searchURL);
$queryJSON->searchFilter->orderFilter->item[2]->title = $orderByTitle['date'];
$queryJSON->searchFilter->orderFilter->item[2]->url = str_replace("orderBy=rank", "orderBy=date", $searchURL);
break;
case "id":
$queryJSON->searchFilter->orderFilter->title = $orderByTitle['id'];
$queryJSON->searchFilter->orderFilter->item[0]->title = $orderByTitle['rank'];
$queryJSON->searchFilter->orderFilter->item[0]->url = str_replace("orderBy=id", "orderBy=rank", $searchURL);
$queryJSON->searchFilter->orderFilter->item[1]->title = $orderByTitle['title'];
$queryJSON->searchFilter->orderFilter->item[1]->url = str_replace("orderBy=id", "orderBy=title", $searchURL);
$queryJSON->searchFilter->orderFilter->item[2]->title = $orderByTitle['date'];
$queryJSON->searchFilter->orderFilter->item[2]->url = str_replace("orderBy=id", "orderBy=date", $searchURL);
break;
case "title":
$queryJSON->searchFilter->orderFilter->title = $orderByTitle['title'];
$queryJSON->searchFilter->orderFilter->item[0]->title = $orderByTitle['rank'];
$queryJSON->searchFilter->orderFilter->item[0]->url = str_replace("orderBy=title", "orderBy=rank", $searchURL);
$queryJSON->searchFilter->orderFilter->item[1]->title = $orderByTitle['id'];
$queryJSON->searchFilter->orderFilter->item[1]->url = str_replace("orderBy=title", "orderBy=id", $searchURL);
$queryJSON->searchFilter->orderFilter->item[2]->title = $orderByTitle['date'];
$queryJSON->searchFilter->orderFilter->item[2]->url = str_replace("orderBy=title", "orderBy=date", $searchURL);
break;
case "date":
$queryJSON->searchFilter->orderFilter->title = $orderByTitle['date'];
$queryJSON->searchFilter->orderFilter->item[0]->title = $orderByTitle['rank'];
$queryJSON->searchFilter->orderFilter->item[0]->url = str_replace("orderBy=date", "orderBy=rank", $searchURL);
$queryJSON->searchFilter->orderFilter->item[1]->title = $orderByTitle['id'];
$queryJSON->searchFilter->orderFilter->item[1]->url = str_replace("orderBy=date", "orderBy=id", $searchURL);
$queryJSON->searchFilter->orderFilter->item[2]->title = $orderByTitle['title'];
$queryJSON->searchFilter->orderFilter->item[2]->url = str_replace("orderBy=date", "orderBy=title", $searchURL);
break;
}
}
//write out json to file or web
$queryFilter = $classJSON->encode($queryJSON);
if ($resultTarget == 'debug') {
echo "
DEBUG: filter: ".$queryFilter."
";
#echo "
DEBUG: searchTypeBbox: ".$searchTypeBbox."
";
}
if ($resultTarget == 'file') {
$filename = $tempFolder."/".$searchId."_filter.json";
if (file_exists($filename)) {
$e = new mb_notice("php/callMetdata.php: The file $filename exists - it will not be overwritten!");
} else {
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;
echo "string to search: ".$str2search."
";
$str2exchange = $paramName."=".$objectList;
echo "string to exchange: ".$str2exchange."
";
$queryStringNew = str_replace($str2search, $str2exchange, urldecode($queryString));
}
return $queryStringNew;
}
//function to remove one complete get param out of the query
function delTotalFromQuery($paramName,$queryString) {
//echo $paramName ."
";
$queryString = "&".$queryString;
$queryStringNew = preg_replace('/\b'.$paramName.'\=[^&]*&?/',"",$queryString); //TODO find empty get params
$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";
}
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
?>