[Mapbender-commits] r10208 - in trunk/mapbender/http: classes php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Aug 14 07:03:34 PDT 2019


Author: armin11
Date: 2019-08-14 07:03:34 -0700 (Wed, 14 Aug 2019)
New Revision: 10208

Modified:
   trunk/mapbender/http/classes/class_wfs.php
   trunk/mapbender/http/php/mod_linkedDataProxy.php
Log:
New option to allow textfilter (actually one) in combination with bbox filter on wfs 3.0 proxy

Modified: trunk/mapbender/http/classes/class_wfs.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs.php	2019-08-13 10:09:48 UTC (rev 10207)
+++ trunk/mapbender/http/classes/class_wfs.php	2019-08-14 14:03:34 UTC (rev 10208)
@@ -349,7 +349,7 @@
 							$bboxFilter = rawurlencode(utf8_decode($bboxFilter));
 */
 
-				$spatialFilter .= "<fes:Filter xmlns:fes=\"http://www.opengis.net/fes/2.0\">";
+				//$spatialFilter .= "<fes:Filter xmlns:fes=\"http://www.opengis.net/fes/2.0\">";
 				$spatialFilter .= "<fes:BBOX>";
 				$spatialFilter .= "<fes:ValueReference>".$geometryColumn."</fes:ValueReference>";
     				$spatialFilter .= '<gml:Envelope xmlns:gml="http://www.opengis.net/gml/3.2" srsName="'.$targetSrs.'">';                
@@ -357,12 +357,12 @@
                   		$spatialFilter .= '<gml:upperCorner>'.$bboxArray[2]." ".$bboxArray[3].'</gml:upperCorner>';  
 				$spatialFilter .= '</gml:Envelope>';
 				$spatialFilter .= "</fes:BBOX>";
-				$spatialFilter .= "</fes:Filter>";
+				//$spatialFilter .= "</fes:Filter>";
 				
 				break;
 			case "other_test":
 				//gml2
-				$spatialFilter .= "<ogc:Filter>";
+				//$spatialFilter .= "<ogc:Filter>";
 				$spatialFilter .= "<ogc:BBOX>";
 				$spatialFilter .= "<ogc:PropertyName>".$geometryColumn."</ogc:PropertyName>";
     				$spatialFilter .= '<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="'.$targetSrs.'">';
@@ -370,7 +370,7 @@
 				$spatialFilter .= $bboxArray[0].','.$bboxArray[1].' '.$bboxArray[2].','.$bboxArray[3];
 				$spatialFilter .= '</gml:coordinates></gml:Box>';
 				$spatialFilter .= "</ogc:BBOX>";
-				$spatialFilter .= "</ogc:Filter>";
+				//$spatialFilter .= "</ogc:Filter>";
 				break;
 			case "1.1.0":
 				//gml2
@@ -536,8 +536,14 @@
 		return $this->post($this->getFeature, $postData); //from class_ows!
 	}
 
-	public function countFeatures($featureTypeName, $filter=null) {
-		switch ($this->getVersion()) {
+	public function countFeatures($featureTypeName, $filter=null, $version=false) {
+//$e = new mb_exception("testwfs");
+		if ($version == false) {
+			$version = $this->getVersion();
+		} else {
+			$e = new mb_notice("classes/class_wfs.php: wfs version forced to ".$version."!");
+		}
+		switch ($version) {
 			case "2.0.2":
 				$typeNameParameterName = "typeNames";
 				$maxFeaturesParameterName = "COUNT";
@@ -551,7 +557,7 @@
 				$maxFeaturesParameterName = "MAXFEATURES";
 				break;
 		}
-		if ($this->getVersion() == "1.0.0") {
+		if ($version == "1.0.0") {
 			$e = new mb_exception("Counting features not possible in wfs <= 1.0.0!");
 			return false;
 		}
@@ -558,11 +564,11 @@
 		$url = $this->getFeature .
 		$this->getConjunctionCharacter($this->getFeature) . 
 		"service=WFS&request=GetFeature&version=" . 
-		$this->getVersion() . "&".strtolower($typeNameParameterName)."=" . $featureTypeName."&resultType=hits";
+		$version . "&".strtolower($typeNameParameterName)."=" . $featureTypeName."&resultType=hits";
 		if ($filter != null) {
 			$url .= "&FILTER=".urlencode($filter);
 		}
-                //$e = new mb_exception("class_wfs.php: getFeatureGet: ".$url);
+//$e = new mb_exception("class_wfs.php: getFeatureGet: ".$url);
 		//auth is already integrated in ows class
 		//do request
 		$resultOfCount = $this->get($url); //from class_ows!
@@ -576,7 +582,7 @@
 		catch (Exception $e) {
     			$e = new mb_exception($e->getMessage());
 		}
-		switch ($this->getVersion()) {
+		switch ($version) {
 			case "2.0.0":
 				$hits = $featureTypeHits->xpath('/wfs:FeatureCollection/@numberMatched');
 				break;

Modified: trunk/mapbender/http/php/mod_linkedDataProxy.php
===================================================================
--- trunk/mapbender/http/php/mod_linkedDataProxy.php	2019-08-13 10:09:48 UTC (rev 10207)
+++ trunk/mapbender/http/php/mod_linkedDataProxy.php	2019-08-14 14:03:34 UTC (rev 10208)
@@ -7,7 +7,7 @@
 require_once(dirname(__FILE__)."/../classes/class_connector.php");//for resolving external @context content
 //http://localhost/mapbender/devel_tests/wfsClientTest.php?wfsid=16&ft=vermkv:fluren_rlp&bbox=7.9,50.8,8.0,52
 //initialize some parameter
-$limit = 10;
+$limit = 20;
 //objects per page
 //$maxObjectsPerPage = 10;
 //default page
@@ -343,6 +343,7 @@
             $ftNameInWfs = false;
 	    foreach ($wfs->featureTypeArray as $featureType) {
 		if ($featureType->name == $collection) {
+		    //requested ft found!
 		    $ftNameInWfs = true;
 		    $ftTitle = $featureType->title;
 		    $ftName = $featureType->name;
@@ -350,6 +351,17 @@
 		    //output formats
 		    $ftOutputFormats = implode(',', array_unique($featureType->featuretypeOutputFormatArray));
 		    //get other relevant ft information
+		    //extract schema - get all elements that are strings and integers
+		    $ftElementArray = $featureType->elementArray; //consists of name and type
+		    //get allowed attributes for filtering
+		    $ftAllowedAttributesArray = array();
+
+		    foreach ($ftElementArray as $ftElement) {
+                        //$e = new mb_exception($ftElement->name ." - " .$ftElement->type);
+			if ($ftElement->type == "string") {
+			    $ftAllowedAttributesArray[] = $ftElement->name;
+			}
+		    }
 		    break;
 		} 
 	    }
@@ -356,6 +368,29 @@
 	    if ($ftNameInWfs) {
 		$myFeatureType = $wfs->findFeatureTypeByName($ftName);			
 		$geomColumnName = $wfs->findGeomColumnNameByFeaturetypeId($myFeatureType->id);
+		//check all allowed attributes to may be set by GET param
+		$stringFilterArray = array();
+		$stringFilterActive = array();
+		$stringFilterIndex = 0;
+//$e = new mb_exception("test: count: ".count($ftAllowedAttributesArray));
+		foreach ($ftAllowedAttributesArray as $ftAllowedAttribute) {
+//$e = new mb_exception("search for: ".$ftAllowedAttribute);
+		    if (isset($_REQUEST[$ftAllowedAttribute]) && $_REQUEST[$ftAllowedAttribute] != "") {
+//$e = new mb_exception("found param:".$ftAllowedAttribute.": ".$_REQUEST[$ftAllowedAttribute]);
+			$testMatch = $_REQUEST[$ftAllowedAttribute];
+			$pattern = '/^[0-9a-zA-Z\.\-_:*]*$/';		
+ 			if (!preg_match($pattern,$testMatch)){ 
+		            echo 'Parameter <b>'.$ftAllowedAttribute.'</b> is not valid (allowed string).<br/>'; 
+		            die(); 		
+ 	                }
+			$stringFilterActive[] = $ftAllowedAttribute;
+	                $stringFilterArray[$stringFilterIndex]->elementName = $ftAllowedAttribute;
+			$stringFilterArray[$stringFilterIndex]->elementFilter = $testMatch;
+			$stringFilterIndex++;
+	                $testMatch = NULL;
+		    }
+		}
+		//first test - only use string filter from index 0!
 	        if (!isset($item) || $item == "") {
 		    //generate description of collection in json
 		    $returnObject->name = $myFeatureType->name;
@@ -391,20 +426,89 @@
 		        } else { 
 		            $filter = null;
 		        }
+			//add string filter if some one was given
+			if(isset($stringFilterArray) && count($stringFilterArray) > 0) {
+//foreach - generate own filter - TODO
+				 /*<And>
+    					<PropertyIsEqualTo><ValueReference>dog:gemarkung</ValueReference><Literal>0401</Literal></PropertyIsEqualTo>
+    					<PropertyIsEqualTo><ValueReference>dog:flur</ValueReference><Literal>109</Literal></PropertyIsEqualTo>
+    					<PropertyIsEqualTo><ValueReference>dog:flurstuecksnummer</ValueReference><Literal>00212</Literal></PropertyIsEqualTo>
+    					<PropertyIsEqualTo><ValueReference>dog:flurstuecksnummernenner</ValueReference><Literal>0007</Literal></PropertyIsEqualTo>
+  				</And>*/
+/*
+<fes:PropertyIsLike wildCard="*" singleChar="." escapeChar="\">
+        <fes:ValueReference>st:stationName</fes:ValueReference>
+        <fes:Literal>Rov*</fes:Literal>
+      </fes:PropertyIsLike>
+*/
+//TODO allow combination of different text filters!!!! - Not all wfs support this ?
+			    if (true) {
+				if (strpos($stringFilterArray[0]->elementFilter, "*") !== false) {
+				    $textFilter .= '<fes:PropertyIsLike wildCard="*" singleChar="." escapeChar="\">';
+				    $textFilter .= '<fes:ValueReference>'.$stringFilterArray[0]->elementName.'</fes:ValueReference>';
+				    $textFilter .= '<fes:Literal>'.$stringFilterArray[0]->elementFilter.'</fes:Literal>';
+      				    $textFilter .= '</fes:PropertyIsLike>';
+				} else {
+				    $textFilter .= '<fes:PropertyIsEqualTo>';
+				    $textFilter .= '<fes:ValueReference>'.$stringFilterArray[0]->elementName.'</fes:ValueReference>';
+				    $textFilter .= '<fes:Literal>'.$stringFilterArray[0]->elementFilter.'</fes:Literal>';
+      				    $textFilter .= '</fes:PropertyIsEqualTo>';
+				}
+                            } else {
+				    $textFilterArray = array();
+				    $textFilterIndex = 0;
+				    $textFilterArray[$textFilterIndex] = "";
+				    foreach ($stringFilterArray as $stringFilter) {
+					if (strpos($stringFilter->elementFilter, "*") !== false) {
+					    $textFilterArray[$textFilterIndex] .= '<fes:PropertyIsLike wildCard="*" singleChar="." escapeChar="\">';
+					    $textFilterArray[$textFilterIndex] .= '<fes:ValueReference>'.$stringFilter->elementName.'</fes:ValueReference>';
+					    $textFilterArray[$textFilterIndex] .= '<fes:Literal>'.$stringFilter->elementFilter.'</fes:Literal>';
+	      				    $textFilterArray[$textFilterIndex] .= '</fes:PropertyIsLike>';
+					} else {
+					    $textFilterArray[$textFilterIndex] .= '<fes:PropertyIsEqualTo>';
+					    $textFilterArray[$textFilterIndex] .= '<fes:ValueReference>'.$stringFilter->elementName.'</fes:ValueReference>';
+					    $textFilterArray[$textFilterIndex] .= '<fes:Literal>'.$stringFilter->elementFilter.'</fes:Literal>';
+	      				    $textFilterArray[$textFilterIndex] .= '</fes:PropertyIsEqualTo>';
+					}
+					$textFilterIndex++;
+				    }
+				    if (count($textFilterArray) > 1) { //bbox is set
+					$textFilter = '<fes:And>'.implode('', $textFilterArray).'<fes:/And>';
+				    } else {
+					$textFilter = implode('', $textFilterArray);
+				    }
+                            }
+			} else {
+                            $textFilter = null;
+			}
+			//build new filter
+			if ($filter != null && $textFilter != null) {
+				$filter = '<fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0"><fes:And>'.$filter.$textFilter.'</fes:And></fes:Filter>';
+			} else {
+				if ($filter == null && $textFilter == null) {
+				    $filter = null;
+				} else {
+				    $filter = '<fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0">'.(string)$filter.(string)$textFilter.'</fes:Filter>';
+				}
+			}
+//test
+//$e = new mb_exception("filter: ".$filter);
 		        //write number of features to ram cache:
-		        if ($cache->isActive) {
-		            if ($cache->cachedVariableExists(md5("count_".$wfsid."_".$collection."_".(string)$filter)) == false) {
+		        //if ($cache->isActive) {
+		        if (false) {
+		            if ($cache->cachedVariableExists(md5("count_".$wfsid."_".$collection."_".md5($filter))) == false) {
 		                $numberOfObjects = $wfs->countFeatures($collection, $filter);
-		                $cache->cachedVariableAdd(md5("count_".$wfsid."_".$collection."_".(string)$filter), $numberOfObjects);
+		                $cache->cachedVariableAdd(md5("count_".$wfsid."_".$collection."_".md5($filter)), $numberOfObjects);
 		            } else {
 //$e = new mb_exception("read count from cache!");
-		                $numberOfObjects = $cache->cachedVariableFetch(md5("count_".$wfsid."_".$collection."_".(string)$filter));
+		                $numberOfObjects = $cache->cachedVariableFetch(md5("count_".$wfsid."_".$collection."_".md5($filter)));
 		            }
 		            //$e = new mb_notice("http/classes/class_crs.php - store crs info to cache!");
 		            //return true;
 		        } else {
-		            $numberOfObjects = $wfs->countFeatures($collection, $filter);
+		            $numberOfObjects = $wfs->countFeatures($collection, $filter, "2.0.0");
 		        }
+//$e = new mb_exception("counted features: ".$numberOfObjects);
 			//$e = new mb_exception("number of objects: ".$numberOfObjects);
 		        //request first object and metadata
 		        //count objects
@@ -833,6 +937,14 @@
     case "html":
 	$js1 = '<script>'.$newline;
 	//https://stackoverflow.com/questions/5997450/append-to-url-and-refresh-page
+	$js1 .= "	function checkActivation() {";
+	$js1 .= "	    alert('test');";
+	$js1 .= "	    var button = document.getElementById(\"filterAdd\");";
+	$js1 .= "	    //activate button if that text is filled out";
+
+	$js1 .= "	    ";//function myFunction(item) { var element = document.getElementById(item);element.classList.toggle(\'show\');";
+	$js1 .= "	}";
+
 	$js1 .= "	function URL_add_parameter(url, param, value){"."\n";
 	$js1 .= "	    var hash       = {};";
 	$js1 .= "	    var parser     = document.createElement('a');";
@@ -935,14 +1047,14 @@
                 $html .= '</ol>';
 	    } else {
 		if (!isset($item) || $items == 'all') {
-		    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array("f","wfsid","collection","collections","item","items","limit","offset","bbox"), $_SERVER['REQUEST_URI']),'?').'">Datasets</a></li>'.$newline; //TODO - use base uri
-                    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array("f","collection","collections","item","items","limit","offset","bbox"), $_SERVER['REQUEST_URI']),'?').'">'.$returnObject->serviceTitle.'</a></li>'.$newline;
+		    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array_merge(array("f","wfsid","collection","collections","item","items","limit","offset","bbox"), $stringFilterActive), $_SERVER['REQUEST_URI']),'?').'">Datasets</a></li>'.$newline; //TODO - use base uri
+                    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array_merge(array("f","collection","collections","item","items","limit","offset","bbox"), $stringFilterActive), $_SERVER['REQUEST_URI']),'?').'">'.$returnObject->serviceTitle.'</a></li>'.$newline;
                     $html .= '<li class="breadcrumb-item active">'.$returnObject->collectionTitle.'</li>'.$newline;
                     $html .= '</ol>';
 		} else {
-		    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array("f","wfsid","collection","collections","item","items","limit","offset","bbox"), $_SERVER['REQUEST_URI']),'?').'">Datasets</a></li>'.$newline; //TODO - use base uri
-                    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array("f","collection","collections","item","items","limit","offset","bbox"), $_SERVER['REQUEST_URI']),'?').'">'.$returnObject->serviceTitle.'</a></li>'.$newline;
-		    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array("f","item","limit","offset","bbox"), $_SERVER['REQUEST_URI']),'?').'&items=all'.'">'.$returnObject->collectionTitle.'</a></li>'.$newline;
+		    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array_merge(array("f","wfsid","collection","collections","item","items","limit","offset","bbox"), $stringFilterActive), $_SERVER['REQUEST_URI']),'?').'">Datasets</a></li>'.$newline; //TODO - use base uri
+                    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array_merge(array("f","collection","collections","item","items","limit","offset","bbox"), $stringFilterActive), $_SERVER['REQUEST_URI']),'?').'">'.$returnObject->serviceTitle.'</a></li>'.$newline;
+		    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array_merge(array("f","item","limit","offset","bbox"), $stringFilterActive), $_SERVER['REQUEST_URI']),'?').'&items=all'.'">'.$returnObject->collectionTitle.'</a></li>'.$newline;
                     $html .= '<li class="breadcrumb-item active">'.$returnObject->id.'</li>'.$newline;
                     $html .= '</ol>';
 		}
@@ -1096,13 +1208,21 @@
 		    if (isset($bbox) && $bbox != "") {
 		        $html .= '<div class="mr-1 my-1 btn-group"><button disabled="" style="opacity: 1;" class="py-0 btn btn-primary btn-sm disabled">bbox≈'.$bbox.'</button><button type="button" aria-haspopup="true" aria-expanded="false" class="py-0 btn btn-danger btn-sm" onclick="location.href = URL_remove_parameter(URL_remove_parameter(location.href, \'bbox\'), \'offset\');return false;">×</button></div>'.$newline;
 		    }
+		    //for each other set parameter show***********************************************
+		    //variable with parameters:
+		    foreach($stringFilterArray as $stringFilter) {
+			 $html .= '<div class="mr-1 my-1 btn-group"><button disabled="" style="opacity: 1;" class="py-0 btn btn-primary btn-sm disabled">'.$stringFilter->elementName.'='.$stringFilter->elementFilter.'</button><button type="button" aria-haspopup="true" aria-expanded="false" class="py-0 btn btn-danger btn-sm" onclick="location.href = URL_remove_parameter(URL_remove_parameter(location.href, \''.$stringFilter->elementName.'\'), \'offset\');return false;">×</button></div>'.$newline;
+		    }
+		    //$stringFilterArray[$stringFilterIndex]->elementName = $ftAllowedAttribute;
+		    //$stringFilterArray[$stringFilterIndex]->elementFilter = $testMatch;
+		    //********************************************************************************
 		    $html .= '<button type="button" id="edit_filter_button" class="py-0 btn btn-outline-secondary btn-sm collapse show" onclick="var elements = [\'edit_filter_button\',  \'cancel_filter_button\', \'filter_div\']; elements.forEach(myFunction); function myFunction(item) { var element = document.getElementById(item);element.classList.toggle(\'show\'); };">Edit</button>';
 		    //$html .= '<button type="button" id="apply_filter_button" class="py-0 btn btn-outline-secondary btn-sm collapse" onclick="">Apply</button>';
 		    $html .= '<button type="button" id="cancel_filter_button" class="py-0 btn btn-outline-secondary btn-sm collapse" onclick="var elements = [\'edit_filter_button\', \'cancel_filter_button\', \'filter_div\']; elements.forEach(myFunction); function myFunction(item) { var element = document.getElementById(item);element.classList.toggle(\'show\'); };">Cancel</button>'.$newline;
 		    //bbox filter part from ldproxy
 		    $html .= '<div id="filter_div" class="collapse">'.$newline;
-		    $html .= '            <form class="">'.$newline;
-		    $html .= '		<p class="text-muted text-uppercase">bbox</p>'.$newline;
+		    $html .= '    <form class="">'.$newline;
+		    $html .= '        <p class="text-muted text-uppercase">bbox</p>'.$newline;
 		    $html .= '		<div class="row">'.$newline;
 		    $html .= '		    <div class="col-md-5">'.$newline;
 		    $html .= '		        <div class="form-group">'.$newline;
@@ -1129,8 +1249,82 @@
 		    $html .= '		    <div class="col-md-2">'.$newline;
 		    $html .= '			<button type="button" class="btn btn-primary btn-sm" onclick="location.href = URL_add_parameter(URL_remove_parameter(location.href, \'p\'), \'bbox\', map.getBounds().getWest()+\',\'+map.getBounds().getSouth()+\',\'+map.getBounds().getEast()+\',\'+map.getBounds().getNorth());return false;">Add</button>'.$newline;
 		    $html .= '		    </div>'.$newline;
-		    $html .= '               </div>'.$newline;
+		    $html .= '          </div>'.$newline;
 		    $html .= '	    </form>'.$newline;
+		    if (is_array($ftAllowedAttributesArray) && count($ftAllowedAttributesArray) > 0) {
+$html .= '<form class="">'.$newline;
+$html .= '    <p class="text-muted text-uppercase">field</p>'.$newline;
+$html .= '    <div class="row">'.$newline;
+$html .= '        <div class="col-md-5">'.$newline;
+$html .= '            <div class="form-group">'.$newline;
+$html .= '                <select id="attributeSelection" name="field" type="select" class="mr-2 text-muted form-control-sm form-control" onchange="document.getElementById(\'filterValue\').value = \'\';">'.$newline;
+$html .= '                    <option value="" class="d-none">none</option>'.$newline;
+foreach($ftAllowedAttributesArray as $ftAllowedAttribute) {
+$html .= '                    <option value="'.$ftAllowedAttribute.'">'.$ftAllowedAttribute.'</option>'.$newline;
+}
+$html .= '               </select>'.$newline;
+$html .= '            </div>'.$newline;
+$html .= '        </div>'.$newline;
+$html .= '        <div class="col-md-5">'.$newline;
+$html .= '            <div class="form-group">'.$newline;
+$html .= '                <input id="filterValue" name="filterValue" placeholder="filter pattern" class="mr-2 form-control-sm form-control" value="" type="text">'.$newline;
+$html .= '                    <small class="form-text text-muted">Use * as wildcard</small>'.$newline;
+$html .= '                    <small class="form-text text-muted" id="filterNameErrMsg"></small>'.$newline;
+$html .= '            </div>'.$newline;
+$html .= '        </div>'.$newline;
+$html .= '        <div class="col-md-2">'.$newline;
+$html .= '            <button id="filterValueAddButton" name="filterValueAddButton" type="button" disabled="" class="btn btn-primary btn-sm disabled" onclick="var attributeSelection = document.getElementById(\'attributeSelection\'); var filterValue = document.getElementById(\'filterValue\'); var selectionValue = attributeSelection.options[attributeSelection.selectedIndex].value; location.href = URL_add_parameter(URL_remove_parameter(location.href, \'p\'), selectionValue, filterValue.value );return false;">Add</button>'.$newline;
+$html .= '        </div>'.$newline;
+$html .= '    </div>'.$newline;
+
+//add script
+$html .= '<script>';
+$html .= 'const filterValue = document.getElementById(\'filterValue\');';
+$html .= 'const filterErrMsgHolder = document.getElementById(\'filterNameErrMsg\');';
+$html .= 'const filterValueAddButton = document.getElementById(\'filterValueAddButton\');';
+$html .= 'const attributeSelection = document.getElementById(\'attributeSelection\');';
+$html .= 'function checkFilterValue() {';
+$html .= 'var inputValue = filterValue.value;';
+$html .= '    if (attributeSelection.options[attributeSelection.selectedIndex].value == "") {';
+$html .= '        filterErrMsgHolder.innerHTML =';
+$html .= '            \'Please select an attribute on the left side before setting the filter value\';';
+$html .= '        return false;';
+$html .= '    } else if (inputValue.length < 1) {';
+$html .= '        filterErrMsgHolder.innerHTML =';
+$html .= '            \'Please enter a text with at least 1 letters\';';
+$html .= '        return false;';
+$html .= '    } else if (!(/^\S{1,}$/.test(inputValue))) {';
+$html .= '        filterErrMsgHolder.innerHTML =';
+$html .= '            \'Name cannot contain whitespace\';';
+$html .= '        return false;';
+$html .= '    } else if(!(/^[a-zA-Z*0-9]+$/.test(inputValue)))';
+$html .= '    {';
+$html .= '       filterErrMsgHolder.innerHTML=';
+$html .= '                \'Only alphabets or * are allowed\'';
+$html .= '    }';
+//$html .= '    else if(!(/^(?:(\w)(?!\1\1))+$/.test(inputValue)))';
+//$html .= '    {';
+//$html .= '        filterErrMsgHolder.innerHTML=';
+//$html .= '                \'per 3 alphabets allowed\'';
+//$html .= '   }';
+$html .= '    else {';
+$html .= '        filterErrMsgHolder.innerHTML = \'\';';
+$html .= '        return true;';
+$html .= '    }       ';
+$html .= '}';
+$html .= 'filterValue.addEventListener(\'keyup\', function (event) {';
+$html .= '    isValidFilter = checkFilterValue();';
+$html .= '    if ( isValidFilter && attributeSelection.options[attributeSelection.selectedIndex].value != "") {';
+$html .= '        filterValueAddButton.classList.remove("disabled");';
+$html .= '        filterValueAddButton.disabled = false;';
+$html .= '    } else {';
+//$html .= '        filterValueAddButton.classList.add("disabled");';
+$html .= '        filterValueAddButton.disabled = true;';
+$html .= '   }';
+$html .= '});';
+$html .= '</script>';
+$html .= '</form>'.$newline;
+		    }
 		    $html .= '</div>'.$newline;
 		    $html .= '</div>'.$newline;
 		    $html .= '</div>'.$newline;



More information about the Mapbender_commits mailing list