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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Oct 29 08:50:44 EDT 2007


Author: christoph
Date: 2007-10-29 08:50:43 -0400 (Mon, 29 Oct 2007)
New Revision: 1770

Modified:
   trunk/mapbender/http/php/mod_wfs_result.php
Log:
imported from Geoportal

Modified: trunk/mapbender/http/php/mod_wfs_result.php
===================================================================
--- trunk/mapbender/http/php/mod_wfs_result.php	2007-10-29 12:43:58 UTC (rev 1769)
+++ trunk/mapbender/http/php/mod_wfs_result.php	2007-10-29 12:50:43 UTC (rev 1770)
@@ -1,186 +1,194 @@
-<?php
-# $Id$
-# http://www.mapbender.org/index.php/Administration
-# Copyright (C) 2002 CCGIS 
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-$filter = stripslashes($_REQUEST["filter"]);
-$url = stripslashes($_REQUEST["url"]);
-$js_wfs_conf_id = $_REQUEST["js_wfs_conf_id"];
-$db_wfs_conf_id = $_REQUEST["db_wfs_conf_id"];
-$typename = $_REQUEST["typename"];
-
-session_start();
-require_once("../../conf/mapbender.conf");
-require_once("../classes/class_stripRequest.php");
-require_once("../classes/class_connector.php");
-
-$con = db_connect(DBSERVER,OWNER,PW);
-db_select_db(DB,$con);
-
-function sepNameSpace($s){
-	$c = mb_strpos($s,":"); 
-	if ($c > 0){
-		return mb_substr($s,$c+1);
-	}
-	else{
-		return $s;
-	}		
-}
-
-function isValidVarName ($varname) {
-	if (preg_match("/[\$]{1}_[a-z]+\[\"[a-z_]+\"\]/i", $varname) != 0) {
-		return true;
-	}
-	return false;
-}
-
-function checkAccessConstraint($filter, $wfs_conf_id) {
-	/* wfs_conf_element */
-	$sql = "SELECT * FROM wfs_conf_element ";
-	$sql .= "JOIN wfs_element ON wfs_conf_element.f_id = wfs_element.element_id ";
-	$sql .= "WHERE wfs_conf_element.fkey_wfs_conf_id = $1 ";
-	$sql .= "ORDER BY wfs_conf_element.f_respos";
-			
-	$v = array($wfs_conf_id);
-	$t = array('i');
-	$res = db_prep_query($sql,$v,$t);
-	while($row = db_fetch_array($res)){
-
-		if (!empty($row["f_auth_varname"])) {
-			$auth_varname = $row["f_auth_varname"];
-			$element_name = $row["element_name"];
-		}
-	}
-	if (!empty($auth_varname)) {
-
-		if (isValidVarName($auth_varname)) {
-			$user = eval("return " . $auth_varname . ";");
-			$pattern = "(<ogc:Filter[^>]*>)(.*)(</ogc:Filter>)";
-			$replacement = "\\1<And>\\2<ogc:PropertyIsEqualTo><ogc:PropertyName>" . $element_name . "</ogc:PropertyName><ogc:Literal>" . $user . "</ogc:Literal></ogc:PropertyIsEqualTo></And>\\3"; 
-			$filter = eregi_replace($pattern, $replacement, $filter);
-		}
-	}
-	return $filter;
-}
-
-$filter = checkAccessConstraint($filter, $db_wfs_conf_id);
-
-$wfsRequest = $url . urlencode($filter);
-$connection = new connector($wfsRequest);
-$data = $connection->file;
-if (!$data) die('wfs not available');
-
-$geometries = array('Point', 'Polygon', 'LineString', 'MultiPolygon', 'MultiLineString');
-
-
-//TODO: 
-// parsing via class_gml
-// add method toJSON to classGML
-$parser = xml_parser_create();
-xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
-xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
-xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
-xml_parse_into_struct($parser,$data,$values,$tags);
-xml_parser_free($parser);
-$member = -1;
-$section = false;
-$geom = false;
-$memberHasBeenCreated = false;
-$str = array();
-$geomtype = array();
-$el = -1;
-$fid = -1;
-
-$element_str = "";
-$geom_str = "";
-foreach ($values as $element) {
-	if(mb_strtoupper($element[tag]) == mb_strtoupper("gml:featureMember") && $element[type] == "open"){
-		$member++;
-		$section = true;
-		$cnt_geom = 0;
-	}
-	else if(mb_strtoupper($element[tag]) == mb_strtoupper($typename) && $element[type] == "open") {
-		$fid = $element[attributes][fid];
-	}
-	else if(in_array(sepNameSpace($element[tag]),$geometries) && $element[type] == "open" && $section == true){
-		$geom = true;
-		if (sepNameSpace($element[tag]) == "MultiLineString") {
-			$geom_str .= "geom.addMember(geomType.line);\n";
-			$memberHasBeenCreated = true;
-		}
-		else if (sepNameSpace($element[tag]) == "MultiPolygon" ) {
-			$geom_str .= "geom.addMember(geomType.polygon);\n";
-			$memberHasBeenCreated = true;
-		}
-		elseif (sepNameSpace($element[tag]) == "Point") {
-			$geom_str .= "geom.addMember(geomType.point);\n";
-			$memberHasBeenCreated = true;
-			$geom_str .= "geom.get(-1).addGeometry();\n";
-		}
-		elseif (sepNameSpace($element[tag]) == "LineString") {
-			if (!$memberHasBeenCreated) {
-				$geom_str .= "geom.addMember(geomType.line);\n";
-				$memberHasBeenCreated = true;
-			}
-			$geom_str .= "geom.get(-1).addGeometry();\n";
-		}
-		else if (sepNameSpace($element[tag]) == "Polygon" ) {
-			if (!$memberHasBeenCreated) {
-				$geom_str .= "geom.addMember(geomType.polygon);\n";
-				$memberHasBeenCreated = true;
-			}
-			$geom_str .= "geom.get(-1).addGeometry();\n";
-		}
-		else {
-			$geom_str .= "alert('unknown geomtype ".sepNameSpace($element[tag])."');";
-		}
-		// TO DO: the following is added twice! Once suffices.
-		$element_str .= "geom.get(" . $member . ").e.setElement('fid', '".$fid."');\n";
-		$element_str .= "geom.get(" . $member . ").wfs_conf = ".$js_wfs_conf_id.";\n";
-	}
-	else if(mb_strtoupper($element[tag]) == mb_strtoupper("gml:coordinates") && $geom == true){
-		$tmp =  preg_replace("/,,/","",preg_replace("/ /",",",trim($element[value])));
-		$geom_str .= "var tmp1 = '".$tmp."';\n";
-		$geom_str .= "var tmp = tmp1.split(',');\n";
-		$geom_str .= "for (var i = 0 ; i < tmp.length ; i+=2) {\n";
-		$geom_str .= "\tgeom.getGeometry(-1,-1).addPointByCoordinates(parseFloat(tmp[i]), parseFloat(tmp[i+1]));\n";
-		$geom_str .= "}\n";
-		$geom_str .= "geom.close();\n";
-        $cnt_geom++;
-        
-	}
-	else if(in_array(sepNameSpace($element[tag]),$geometries) && $element[type] == "close"){			
-		$geom = false;
-		$memberHasBeenCreated = false;
-	}
-	else if($section == true && $geom == false && $element[value]){
-		$el++;
-		$str = $element[value];
-		$element_str .= "geom.get(" . $member . ").e.setElement('".sepNameSpace($element[tag])."', '".addslashes($str)."');\n";
-	}
-	else if(mb_strtoupper($element[tag]) == mb_strtoupper("gml:featureMember") && $element[type] == "close"){
-		$section = false;	
-		$el = -1;			
-	}
-}
-if ($geom_str != "") {
-	$geom_str = "var geom = new GeometryArray();\n" . $geom_str;
-}
-header('Content-type: text/html');
-echo $geom_str;
-echo $element_str;
+<?php
+# $Id$
+# http://www.mapbender.org/index.php/Administration
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+$filter = stripslashes($_REQUEST["filter"]);
+$url = stripslashes($_REQUEST["url"]);
+$js_wfs_conf_id = $_REQUEST["js_wfs_conf_id"];
+$db_wfs_conf_id = $_REQUEST["db_wfs_conf_id"];
+$typename = $_REQUEST["typename"];
+
+session_start();
+require_once("../../conf/mapbender.conf");
+require_once("../classes/class_stripRequest.php");
+require_once("../classes/class_connector.php");
+
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
+
+function sepNameSpace($s){
+	$c = mb_strpos($s,":"); 
+	if ($c > 0){
+		return mb_substr($s,$c+1);
+	}
+	else{
+		return $s;
+	}		
+}
+
+/**
+ * checks if a variable name is valid.
+ * Currently a valid name would be sth. like $_SESSION["mb_user_id"]
+ * TODO: this function is also in mod_wfs_result!! Maybe merge someday.
+ */
+function isValidVarName ($varname) {
+	if (preg_match("/[\$]{1}_[a-z]+\[\"[a-z_]+\"\]/i", $varname) != 0) {
+		return true;
+	}
+	return false;
+}
+/**
+ * If access to the WFS conf is restricted, modify the filter.
+ * TODO: this function is also in mod_wfs_result!! Maybe merge someday.
+ */
+function checkAccessConstraint($filter, $wfs_conf_id) {
+	/* wfs_conf_element */
+	$sql = "SELECT * FROM wfs_conf_element ";
+	$sql .= "JOIN wfs_element ON wfs_conf_element.f_id = wfs_element.element_id ";
+	$sql .= "WHERE wfs_conf_element.fkey_wfs_conf_id = $1 ";
+	$sql .= "ORDER BY wfs_conf_element.f_respos";
+			
+	$v = array($wfs_conf_id);
+	$t = array('i');
+	$res = db_prep_query($sql,$v,$t);
+	while($row = db_fetch_array($res)){
+
+		if (!empty($row["f_auth_varname"])) {
+			$auth_varname = $row["f_auth_varname"];
+			$element_name = $row["element_name"];
+		}
+	}
+	if (!empty($auth_varname)) {
+
+		if (isValidVarName($auth_varname)) {
+			$user = eval("return " . $auth_varname . ";");
+			$pattern = "(<ogc:Filter[^>]*>)(.*)(</ogc:Filter>)";
+			$replacement = "\\1<And>\\2<ogc:PropertyIsEqualTo><ogc:PropertyName>" . $element_name . "</ogc:PropertyName><ogc:Literal>" . $user . "</ogc:Literal></ogc:PropertyIsEqualTo></And>\\3"; 
+			$filter = eregi_replace($pattern, $replacement, $filter);
+		}
+	}
+	return $filter;
+}
+
+$filter = checkAccessConstraint($filter, $db_wfs_conf_id);
+
+$wfsRequest = $url . urlencode($filter);
+$connection = new connector($wfsRequest);
+$data = $connection->file;
+if (!$data) die('wfs not available');
+
+$geometries = array('Point', 'Polygon', 'LineString', 'MultiPolygon', 'MultiLineString');
+
+
+//TODO: 
+// parsing via class_gml
+// add method toJSON to classGML
+$parser = xml_parser_create();
+xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
+xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
+xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
+xml_parse_into_struct($parser,$data,$values,$tags);
+xml_parser_free($parser);
+$member = -1;
+$section = false;
+$geom = false;
+$memberHasBeenCreated = false;
+$str = array();
+$geomtype = array();
+$el = -1;
+$fid = -1;
+
+$element_str = "";
+$geom_str = "";
+foreach ($values as $element) {
+	if(mb_strtoupper($element[tag]) == mb_strtoupper("gml:featureMember") && $element[type] == "open"){
+		$member++;
+		$section = true;
+		$cnt_geom = 0;
+	}
+	else if(mb_strtoupper($element[tag]) == mb_strtoupper($typename) && $element[type] == "open") {
+		$fid = $element[attributes][fid];
+	}
+	else if(in_array(sepNameSpace($element[tag]),$geometries) && $element[type] == "open" && $section == true){
+		$geom = true;
+		if (sepNameSpace($element[tag]) == "MultiLineString") {
+			$geom_str .= "geom.addMember(geomType.line);\n";
+			$memberHasBeenCreated = true;
+		}
+		else if (sepNameSpace($element[tag]) == "MultiPolygon" ) {
+			$geom_str .= "geom.addMember(geomType.polygon);\n";
+			$memberHasBeenCreated = true;
+		}
+		elseif (sepNameSpace($element[tag]) == "Point") {
+			$geom_str .= "geom.addMember(geomType.point);\n";
+			$memberHasBeenCreated = true;
+			$geom_str .= "geom.get(-1).addGeometry();\n";
+		}
+		elseif (sepNameSpace($element[tag]) == "LineString") {
+			if (!$memberHasBeenCreated) {
+				$geom_str .= "geom.addMember(geomType.line);\n";
+				$memberHasBeenCreated = true;
+			}
+			$geom_str .= "geom.get(-1).addGeometry();\n";
+		}
+		else if (sepNameSpace($element[tag]) == "Polygon" ) {
+			if (!$memberHasBeenCreated) {
+				$geom_str .= "geom.addMember(geomType.polygon);\n";
+				$memberHasBeenCreated = true;
+			}
+			$geom_str .= "geom.get(-1).addGeometry();\n";
+		}
+		else {
+			$geom_str .= "alert('unknown geomtype ".sepNameSpace($element[tag])."');";
+		}
+		// TO DO: the following is added twice! Once suffices.
+		$element_str .= "geom.get(" . $member . ").e.setElement('fid', '".$fid."');\n";
+		$element_str .= "geom.get(" . $member . ").wfs_conf = ".$js_wfs_conf_id.";\n";
+	}
+	else if(mb_strtoupper($element[tag]) == mb_strtoupper("gml:coordinates") && $geom == true){
+		$tmp =  preg_replace("/,,/","",preg_replace("/ /",",",trim($element[value])));
+		$geom_str .= "var tmp1 = '".$tmp."';\n";
+		$geom_str .= "var tmp = tmp1.split(',');\n";
+		$geom_str .= "for (var i = 0 ; i < tmp.length ; i+=2) {\n";
+		$geom_str .= "\tgeom.getGeometry(-1,-1).addPointByCoordinates(parseFloat(tmp[i]), parseFloat(tmp[i+1]));\n";
+		$geom_str .= "}\n";
+		$geom_str .= "geom.close();\n";
+        $cnt_geom++;
+        
+	}
+	else if(in_array(sepNameSpace($element[tag]),$geometries) && $element[type] == "close"){			
+		$geom = false;
+		$memberHasBeenCreated = false;
+	}
+	else if($section == true && $geom == false && $element[value]){
+		$el++;
+		$str = $element[value];
+		$element_str .= "geom.get(" . $member . ").e.setElement('".sepNameSpace($element[tag])."', '".addslashes($str)."');\n";
+	}
+	else if(mb_strtoupper($element[tag]) == mb_strtoupper("gml:featureMember") && $element[type] == "close"){
+		$section = false;	
+		$el = -1;			
+	}
+}
+if ($geom_str != "") {
+	$geom_str = "var geom = new GeometryArray();\n" . $geom_str;
+}
+header('Content-type: text/html');
+echo $geom_str;
+echo $element_str;
 ?> 
\ No newline at end of file



More information about the Mapbender_commits mailing list