svn commit: r104 - trunk/mapbender/http/classes/class_wfs.php

christoph at osgeo.org christoph at osgeo.org
Wed Apr 19 10:30:59 EDT 2006


Author: christoph
Date: 2006-04-19 14:30:59+0000
New Revision: 104

Modified:
   trunk/mapbender/http/classes/class_wfs.php

Log:


Modified: trunk/mapbender/http/classes/class_wfs.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/classes/class_wfs.php?view=diff&rev=104&p1=trunk/mapbender/http/classes/class_wfs.php&p2=trunk/mapbender/http/classes/class_wfs.php&r1=103&r2=104
==============================================================================
--- trunk/mapbender/http/classes/class_wfs.php	(original)
+++ trunk/mapbender/http/classes/class_wfs.php	2006-04-19 14:30:59+0000
@@ -1,437 +1,437 @@
-<?php
-# $Id: class_wfs.php,v 1.15 2006/03/09 13:55:46 uli_rothstein Exp $
-# $Header: /cvsroot/mapbender/mapbender/http/classes/class_wfs.php,v 1.15 2006/03/09 13:55:46 uli_rothstein Exp $
-# 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.
-
-/**
-* class for wfs-objects
-*/
-
-include_once("../../conf/mapbender.conf");
-require_once("class_connector.php");
-class wfs {
-
-  var $wfs_id;
-  var $wfs_version;
-  var $wfs_name;
-  var $wfs_title;
-  var $wfs_abstract;
-  var $wfs_getcapabilities;
-  var $wfs_describefeaturetype;
-  var $wfs_describefeaturetype_namespace = array();
-  var $wfs_getfeature;
-  //neu
-  var $wfs_transaction;
-
-
-  var $wfs_featuretype = array();
- 
- 
-  
-function wfs() {
-
-} 
-function createObjFromXML($url){
-	
-	$x = new connector($url);
-	$data = $x->file;
-	#$data = implode("",file($url));
-	if(!$data){
-		echo "Unable to open document: ".$url;
-		die; 
-	}
-	
-	# for temporary wms a id has to be created...
-	$this->wfs_id = "id_" . substr(md5(rand()),0,6);
-	$parser = xml_parser_create(CHARSET);
-	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);
-	
-	$section = false;
-	$request = false;
-	$featuretype_name = false;
- 	$featuretype_title = false;
- 	$featuretype_srs = false;
-	
-	foreach ($values as $element) {
-	
-		if(strtoupper($element[tag]) == "WFS_CAPABILITIES" && $element[type] == "open"){
-			$this->wfs_version = $element[attributes][version];
-		}
-		if(strtoupper($element[tag]) == "NAME"  && $element[level] == '3'){
-			$this->wfs_name = $element[value];
-		}
-		if(strtoupper($element[tag]) == "TITLE"  && $element[level] == '3'){
-			$this->wfs_title = $element[value];
-		}
-		if(strtoupper($element[tag]) == "ABSTRACT" && $element[level] == '3'){
-			$this->wfs_abstract = $element[value];
-		}
-		
-		
-		/*capability section*/
-		
-		if($this->wfs_version == "1.0.0"){
-			
-			# getCapabilities
-			if(strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "open"){
-				$section = "getcapabilities";
-			}
-			if($section == "getcapabilities" && strtoupper($element[tag]) == "GET"){
-				$this->wfs_getcapabilities = $element[attributes][onlineResource];
-			}
-			
-			# descriptFeatureType
-			if(strtoupper($element[tag]) == "DESCRIBEFEATURETYPE" && $element[type] == "open"){
-				$section = "describefeaturetype";
-				$this->wfs_describefeaturetype = $element[attributes][onlineResource];
-				
-				
-			}
-			if($section == "describefeaturetype" && strtoupper($element[tag]) == "GET"){
-				$this->wfs_describefeaturetype = $element[attributes][onlineResource];
-			}
-			
-			# getFeature
-			if(strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "open"){
-				$section = "getfeature";
-			}
-			if($section == "getfeature" && strtoupper($element[tag]) == "GET"){
-				$this->wfs_getfeature = $element[attributes][onlineResource];
-			}
-			if(strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "close"){
-				$section = "";
-			}			
-			# transaction
-			if(strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "open"){
-				$section = "transaction";
-			}
-			if($section == "transaction" && strtoupper($element[tag]) == "GET"){
-				$this->wfs_transaction = $element[attributes][onlineResource];
-			}
-			if(strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "close"){
-				$section = "";
-			}
-		} 
-		if(strtoupper($element[tag]) == "FEATURETYPE" && $element[type] == "open"){
-			$section = "featuretype";
-		}
-		if($section == "featuretype" && strtoupper($element[tag]) == "NAME"){
-			$featuretype_name = $element[value];
-		}
-		if($section == "featuretype" && strtoupper($element[tag]) == "TITLE"){
-			$featuretype_title = $element[value];
-		}
-		if($section == "featuretype" && strtoupper($element[tag]) == "SRS"){
-			$featuretype_srs = $element[value];
-			$this->addFeaturetype($featuretype_name,$featuretype_title,$featuretype_srs,$this->wfs_describefeaturetype,$this->wfs_version);
-		}
-	}
-}
-function displayWFS(){
-	echo "id: " . $this->wfs_id . " <br>";
-	echo "version: " . $this->wfs_version . " <br>";
-	echo "name: " . $this->wfs_name . " <br>";
-	echo "title: " . $this->wfs_title . " <br>";
-	echo "abstract: " . $this->wfs_abstract . " <br>";
-	echo "capabilitiesrequest: " . $this->wfs_getcapabilities . " <br>";
-	echo "describefeaturetype: " . $this->wfs_describefeaturetype . " <br>";
-	echo "getfeature: " . $this->wfs_getfeature . " <br>";
-	echo "transaction: " . $this->wfs_transaction . " <br>";
-	for($i=0; $i<count($this->wfs_featuretype); $i++){
-		echo "<hr>";
-		echo "name: ". $this->wfs_featuretype[$i]->featuretype_name . "<br>";
-		echo "title: ". $this->wfs_featuretype[$i]->featuretype_title . "<br>";
-		echo "srs: ". $this->wfs_featuretype[$i]->featuretype_srs . "<br>";
-		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
-			echo " element: " . $this->wfs_featuretype[$i]->featuretype_element[$j]["name"] ." - ".$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]."<br>";
-		}
-		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_namespace);$j++){
-			echo " namespace: " . $this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"] ." - ".$this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]."<br>";
-		}
-	}
-} 
-function addFeaturetype($name,$title,$srs,$url,$version){
-	$this->wfs_featuretype[count($this->wfs_featuretype)] = new featuretype($name,$title,$srs,$url,$version);
-}
-function createJsObjFromWFS($parent){
-	if(!$this->wfs_title || $this->wfs_title == ""){
-		echo "alert('Error: no valid capabilities-document !!');";
-		die; exit;
-	}
-		if($parent){
-			echo "parent.";
-		}
-		print("add_wfs('". 
-		$this->wfs_id ."','".
-		$this->wfs_version ."','".
-		$this->wfs_title ."','".
-		$this->wfs_abstract ."','". 
-		$this->wfs_getcapabilities ."','" .
-		$this->wfs_describefeaturetype ."');");
-		
-
-	for($i=0; $i<count($this->wfs_featuretype); $i++){
-		if($parent){
-			echo "parent.";
-		}
-		print ("wfs_add_featuretype('". 
-			$this->wfs_featuretype[$i]->featuretype_name ."','". 
-			$this->wfs_featuretype[$i]->featuretype_title . "','". 
-			$this->wfs_featuretype[$i]->featuretype_srs ."','". 
-			$this->wfs_featuretype[$i]->featuretype_geomtype ."');");
-		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
-			if($parent){
-			echo "parent.";
-			}
-			print("wfs_add_featuretype_element('".$this->wfs_featuretype[$i]->featuretype_element[$j]["name"]."', '".$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]."', ".$j.", ".$i.");");
-		}
-		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_namespace);$j++){
-			if($parent){
-			echo "parent.";
-			}
-			print("wfs_add_featuretype_namespace('".$this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"]."', '".$this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]."', ".$j.", ".$i.");");
-		}
-	}
-  }
-/**
-* wfs2db
-*
-* this function exports the information from the xml to the mapbender database 
-*/
-function wfs2db($gui_id){
-	global $DBSERVER,$DB,$OWNER,$PW;
-	$con = db_connect($DBSERVER,$OWNER,$PW);
-	db_select_db($DB,$con);
-
-	# TABLE wfs
-	
-	$sql = "INSERT INTO wfs (wfs_version, wfs_name, wfs_title, wfs_abstract, wfs_getcapabilities, wfs_describefeaturetype, wfs_getfeature, wfs_transaction) ";
-	$sql .= "VALUES(";
-		$sql .= "'" . $this->wfs_version ."', ";
-		$sql .= "'" . db_escape_string(str_replace("'","",$this->wfs_name)) ."', ";
-		$sql .= "'" . db_escape_string(str_replace("'","",$this->wfs_title)) ."', ";
-		$sql .= "'" . db_escape_string(str_replace("'","",$this->wfs_abstract)) .  "', ";
-		$sql .= "'" . $this->wfs_getcapabilities ."', ";
-		$sql .= "'" . $this->wfs_describefeaturetype . "', ";
-		$sql .= "'". $this->wfs_getfeature . "', ";
-		$sql .= "'". $this->wfs_transaction . "'";
-	$sql .= ");";
-	#echo "sql wfs: <br>".$sql;
-	
-	$res = db_query($sql)or die(db_error());
-	
-	$myWFS = db_insert_id($con,'wfs','wfs_id');
-	#echo "<br> myWFS: ".$myWFS;
-	
-	# TABLE wfs_featuretype
-	
-	for($i=0; $i<count($this->wfs_featuretype); $i++){
-		$sql = "INSERT INTO wfs_featuretype(fkey_wfs_id, featuretype_name, featuretype_title, featuretype_srs) ";
-		$sql .= "VALUES(";
-			$sql .= $myWFS . ",";
-			$sql .= "'".$this->wfs_featuretype[$i]->featuretype_name . "',";
-			$sql .= "'".$this->wfs_featuretype[$i]->featuretype_title."',";
-			$sql .= "'".$this->wfs_featuretype[$i]->featuretype_srs."'";
-		$sql .= ")";
-		
-		#$res = mysql_query($sql) or $this->cleanDB($myWFS,$sql);
-		
-		$res = db_query($sql) or $this->cleanDB($myWFS,$sql);
-
-		
-		# save the id of each featuretype: 
-		$this->wfs_featuretype[$i]->mysql_id = db_insert_id($con,'wfs_featuretype','featuretype_id');
-		
-		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
-			$sql = "INSERT INTO wfs_element(fkey_featuretype_id, element_name,element_type) ";
-			$sql .= "VALUES("; 
-			$sql .= "'" .$this->wfs_featuretype[$i]->mysql_id. "', ";
-			$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_element[$j]["name"]. "', ";
-			$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]. "' ";
-			$sql .= ")";
-			
-			$res = db_query($sql) or $this->cleanDB($myWFS,$sql);
-		}
-
-		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_namespace);$j++){
-			$sql = "INSERT INTO wfs_featuretype_namespace(fkey_wfs_id, fkey_featuretype_id, namespace, namespace_location) ";
-			$sql .= "VALUES("; 
-			$sql .= "'" .$myWFS. "',";
-			$sql .= "'" .$this->wfs_featuretype[$i]->mysql_id. "', ";
-			$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"]. "', ";
-			$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]. "' ";
-			$sql .= ")";
-			
-			$res = db_query($sql) or $this->cleanDB($myWFS,$sql);
-		}
-	}
-	
-	# TABLE gui_wfs
-	
-	$sql ="INSERT INTO gui_wfs (fkey_gui_id, fkey_wfs_id)";
-	$sql .= "VALUES(";
-		$sql .= "'" . $gui_id . "', ";
-		$sql .= $myWFS;
-	$sql .= ");";
-	
-	$res = db_query($sql) or $this->cleanDB($myWFS,$sql);
-}
-function cleanDB($wfsid,$sql){
-	global $DBSERVER,$DB,$OWNER,$PW;
-	$con = db_connect($DBSERVER,$OWNER,$PW);
-	db_select_db($DB,$con);
-	$s = "DELETE FROM wfs WHERE wfs_id = ".$wfsid;
-	$res = db_query($s);
-	echo "<br>Error in :".$sql."<br>";
-	echo "<br>Db cleaned.<br>";
-	die;
-}
-
-
-  /**
-* creatObjfromDB
-*
-*/ 
-function createObjFromDB________($wfs_id){
-	global $server,$db,$owner,$pw;
-	$con = mysql_connect($server,$owner,$pw);
-	mysql_select_db($db, $con);
-
-	$sql = "SELECT * FROM wfs WHERE wfs_id = ".$wfs_id.";";
-	$res = mysql_query($sql);
-	$cnt = 0;
-	while(mysql_fetch_row($res)){
-		$this->wfs_id = mysql_result($res, $cnt, "wfs_id");
-		$this->wfs_version = mysql_result($res, $cnt, "wfs_version");
-		$this->wfs_title = mysql_result($res, $cnt, "wfs_title");
-		$this->wfs_abstract = mysql_result($res, $cnt, "wfs_abstract");
-		$this->wfs_getcapabilities = mysql_result($res, $cnt, "wfs_getcapabilities");
-		$this->wfs_describefeaturetype = mysql_result($res, $cnt, "wfs_describefeaturetype");
-		
-		$sql_fe = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = " . $this->wfs_id . " ORDER BY featuretype_id";
-		$res_fe = mysql_query($sql_fe);
-		$cnt_fe = 0;
-		while(mysql_fetch_row($res_fe)){
-			$c = count($this->wfs_featuretype);
-			$this->wfs_featuretype[$c]->featuretype_name = mysql_result($res_fe, $cnt_fe, "featuretype_name");
-			$this->wfs_featuretype[$c]->featuretype_title = mysql_result($res_fe, $cnt_fe, "featuretype_title");
-			$this->wfs_featuretype[$c]->featuretype_srs = mysql_result($res_fe, $cnt_fe, "featuretype_srs");
-			$this->wfs_featuretype[$c]->featuretype_geomtype = mysql_result($res_fe, $cnt_fe, "featuretype_geomtype");
-			
-			$sql_el = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = ". mysql_result($res_fe, $cnt_fe, "featuretype_id")." ORDER BY element_id";
-			$res_el = mysql_query($sql_el);
-			$cnt_el = 0;
-			while(mysql_fetch_row($res_el)){
-				$z = count($this->wfs_featuretype[$c]->featuretype_element);
-				$this->wfs_featuretype[$c]->featuretype_element[$z]["name"] = mysql_result($res_el, $cnt_el, "element_name");
-				$this->wfs_featuretype[$c]->featuretype_element[$z]["type"] = mysql_result($res_el, $cnt_el, "element_type");
-				$cnt_el++;
-			}
-			$sql_el = "SELECT * FROM wfs_featuretype_namespace WHERE fkey_featuretype_id = ". mysql_result($res_fe, $cnt_fe, "featuretype_id")." ORDER BY namespace";
-			$res_el = mysql_query($sql_el);
-			$cnt_el = 0;
-			while(mysql_fetch_row($res_el)){
-				$z = count($this->wfs_featuretype[$c]->featuretype_namespace);
-				$this->wfs_featuretype[$c]->featuretype_namespace[$z]["name"] = mysql_result($res_el, $cnt_el, "namespace");
-				$this->wfs_featuretype[$c]->featuretype_namespace[$z]["value"] = mysql_result($res_el, $cnt_el, "namespace_location");
-				$cnt_el++;
-			}
-			$cnt_fe++;
-		}
-		$cnt++;
-	}
-   }
-}
-/** end createObjfromDB **/
-
-
-class featuretype extends wfs{
-	var $featuretype_element = array();	
-	var $featuretype_namespace = array();	
-	
-	function featuretype($name,$title,$srs,$url,$version){
-
-		$url .= "&SERVICE=WFS&VERSION=".$version."&REQUEST=DescribeFeatureType&TYPENAME=".$name;
-		
-		$this->featuretype_name = $name;
-		$this->featuretype_title = $title;
-		$this->featuretype_srs = $srs;
-				
-		$data = implode("",file($url));
-		$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_parse_into_struct($parser,$data,$values,$tags);
-		xml_parser_free($parser);
-		
-		foreach ($values as $element) {	
-			if($this->sepNameSpace($element[tag]) == "schema" && $element[type] == "open"){
-				$section = "namespace";
-				echo "namespace<br>";
-			}
-			//echo $element[attributes][name] . "<br/>";
-			if($section == "namespace"){
-				while (list($k, $val) = each ($element[attributes])) {
-   					if (substr($k, 0, 5) == "xmlns") {
-						$cnt = count($this->featuretype_namespace);
-						$match = false;
-						for ($i = 0 ; $i < $cnt && $match == false ; $i++) {
-							if ($this->sepNameSpace($k) == $this->featuretype_namespace[$i]["name"] && $val == $this->featuretype_namespace[$i]["value"]) {
-								$match = true;
-							}
-						}
-						if ($match == false) {
-							$this->featuretype_namespace[$cnt]["name"] = $this->sepNameSpace($k);
-							$this->featuretype_namespace[$cnt]["value"] = $val;
-							echo "namespace: " . $this->sepNameSpace($k) . " -> " . $val . "<br>";
-						}
-   					}
-				}
-			}
-			if($this->sepNameSpace($element[tag]) == "schema" && $element[type] == "close"){
-				$section = "";
-			}
-			if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "open"){
-				$section = "complexcontent";
-				echo "complexcontent<br>";
-			}
-			if($section == "complexcontent" && $this->sepNameSpace($element[tag]) == "element" && $element[attributes][name]){
-				$cnt = count($this->featuretype_element);
-				$this->featuretype_element[$cnt]["name"] = $element[attributes]["name"];
-				$this->featuretype_element[$cnt]["type"] = $this->sepNameSpace($element[attributes]["type"]);
-				echo "element: ".$this->featuretype_element[$cnt]["name"]."<br>";
-			}
-			if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "close"){
-				$section = "";
-			}
-		}
-	}
-	function sepNameSpace($s){
-		$c = strpos($s,":"); 
-		if($c>0){
-			return substr($s,$c+1);
-		}
-		else{
-			return $s;
-		}		
-	}
-}
+<?php
+# $Id: class_wfs.php,v 1.15 2006/03/09 13:55:46 uli_rothstein Exp $
+# $Header: /cvsroot/mapbender/mapbender/http/classes/class_wfs.php,v 1.15 2006/03/09 13:55:46 uli_rothstein Exp $
+# 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.
+
+/**
+* class for wfs-objects
+*/
+
+include_once("../../conf/mapbender.conf");
+require_once("class_connector.php");
+class wfs {
+
+  var $wfs_id;
+  var $wfs_version;
+  var $wfs_name;
+  var $wfs_title;
+  var $wfs_abstract;
+  var $wfs_getcapabilities;
+  var $wfs_describefeaturetype;
+  var $wfs_describefeaturetype_namespace = array();
+  var $wfs_getfeature;
+  //neu
+  var $wfs_transaction;
+
+
+  var $wfs_featuretype = array();
+ 
+ 
+  
+function wfs() {
+
+} 
+function createObjFromXML($url){
+	
+	$x = new connector($url);
+	$data = $x->file;
+	#$data = implode("",file($url));
+	if(!$data){
+		echo "Unable to open document: ".$url;
+		die; 
+	}
+	
+	# for temporary wms a id has to be created...
+	$this->wfs_id = "id_" . substr(md5(rand()),0,6);
+	$parser = xml_parser_create(CHARSET);
+	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);
+	
+	$section = false;
+	$request = false;
+	$featuretype_name = false;
+ 	$featuretype_title = false;
+ 	$featuretype_srs = false;
+	
+	foreach ($values as $element) {
+	
+		if(strtoupper($element[tag]) == "WFS_CAPABILITIES" && $element[type] == "open"){
+			$this->wfs_version = $element[attributes][version];
+		}
+		if(strtoupper($element[tag]) == "NAME"  && $element[level] == '3'){
+			$this->wfs_name = $element[value];
+		}
+		if(strtoupper($element[tag]) == "TITLE"  && $element[level] == '3'){
+			$this->wfs_title = $element[value];
+		}
+		if(strtoupper($element[tag]) == "ABSTRACT" && $element[level] == '3'){
+			$this->wfs_abstract = $element[value];
+		}
+		
+		
+		/*capability section*/
+		
+		if($this->wfs_version == "1.0.0"){
+			
+			# getCapabilities
+			if(strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "open"){
+				$section = "getcapabilities";
+			}
+			if($section == "getcapabilities" && strtoupper($element[tag]) == "GET"){
+				$this->wfs_getcapabilities = $element[attributes][onlineResource];
+			}
+			
+			# descriptFeatureType
+			if(strtoupper($element[tag]) == "DESCRIBEFEATURETYPE" && $element[type] == "open"){
+				$section = "describefeaturetype";
+				$this->wfs_describefeaturetype = $element[attributes][onlineResource];
+				
+				
+			}
+			if($section == "describefeaturetype" && strtoupper($element[tag]) == "GET"){
+				$this->wfs_describefeaturetype = $element[attributes][onlineResource];
+			}
+			
+			# getFeature
+			if(strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "open"){
+				$section = "getfeature";
+			}
+			if($section == "getfeature" && strtoupper($element[tag]) == "GET"){
+				$this->wfs_getfeature = $element[attributes][onlineResource];
+			}
+			if(strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "close"){
+				$section = "";
+			}			
+			# transaction
+			if(strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "open"){
+				$section = "transaction";
+			}
+			if($section == "transaction" && strtoupper($element[tag]) == "GET"){
+				$this->wfs_transaction = $element[attributes][onlineResource];
+			}
+			if(strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "close"){
+				$section = "";
+			}
+		} 
+		if(strtoupper($element[tag]) == "FEATURETYPE" && $element[type] == "open"){
+			$section = "featuretype";
+		}
+		if($section == "featuretype" && strtoupper($element[tag]) == "NAME"){
+			$featuretype_name = $element[value];
+		}
+		if($section == "featuretype" && strtoupper($element[tag]) == "TITLE"){
+			$featuretype_title = $element[value];
+		}
+		if($section == "featuretype" && strtoupper($element[tag]) == "SRS"){
+			$featuretype_srs = $element[value];
+			$this->addFeaturetype($featuretype_name,$featuretype_title,$featuretype_srs,$this->wfs_describefeaturetype,$this->wfs_version);
+		}
+	}
+}
+function displayWFS(){
+	echo "id: " . $this->wfs_id . " <br>";
+	echo "version: " . $this->wfs_version . " <br>";
+	echo "name: " . $this->wfs_name . " <br>";
+	echo "title: " . $this->wfs_title . " <br>";
+	echo "abstract: " . $this->wfs_abstract . " <br>";
+	echo "capabilitiesrequest: " . $this->wfs_getcapabilities . " <br>";
+	echo "describefeaturetype: " . $this->wfs_describefeaturetype . " <br>";
+	echo "getfeature: " . $this->wfs_getfeature . " <br>";
+	echo "transaction: " . $this->wfs_transaction . " <br>";
+	for($i=0; $i<count($this->wfs_featuretype); $i++){
+		echo "<hr>";
+		echo "name: ". $this->wfs_featuretype[$i]->featuretype_name . "<br>";
+		echo "title: ". $this->wfs_featuretype[$i]->featuretype_title . "<br>";
+		echo "srs: ". $this->wfs_featuretype[$i]->featuretype_srs . "<br>";
+		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
+			echo " element: " . $this->wfs_featuretype[$i]->featuretype_element[$j]["name"] ." - ".$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]."<br>";
+		}
+		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_namespace);$j++){
+			echo " namespace: " . $this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"] ." - ".$this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]."<br>";
+		}
+	}
+} 
+function addFeaturetype($name,$title,$srs,$url,$version){
+	$this->wfs_featuretype[count($this->wfs_featuretype)] = new featuretype($name,$title,$srs,$url,$version);
+}
+function createJsObjFromWFS($parent){
+	if(!$this->wfs_title || $this->wfs_title == ""){
+		echo "alert('Error: no valid capabilities-document !!');";
+		die; exit;
+	}
+		if($parent){
+			echo "parent.";
+		}
+		print("add_wfs('". 
+		$this->wfs_id ."','".
+		$this->wfs_version ."','".
+		$this->wfs_title ."','".
+		$this->wfs_abstract ."','". 
+		$this->wfs_getcapabilities ."','" .
+		$this->wfs_describefeaturetype ."');");
+		
+
+	for($i=0; $i<count($this->wfs_featuretype); $i++){
+		if($parent){
+			echo "parent.";
+		}
+		print ("wfs_add_featuretype('". 
+			$this->wfs_featuretype[$i]->featuretype_name ."','". 
+			$this->wfs_featuretype[$i]->featuretype_title . "','". 
+			$this->wfs_featuretype[$i]->featuretype_srs ."','". 
+			$this->wfs_featuretype[$i]->featuretype_geomtype ."');");
+		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
+			if($parent){
+			echo "parent.";
+			}
+			print("wfs_add_featuretype_element('".$this->wfs_featuretype[$i]->featuretype_element[$j]["name"]."', '".$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]."', ".$j.", ".$i.");");
+		}
+		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_namespace);$j++){
+			if($parent){
+			echo "parent.";
+			}
+			print("wfs_add_featuretype_namespace('".$this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"]."', '".$this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]."', ".$j.", ".$i.");");
+		}
+	}
+  }
+/**
+* wfs2db
+*
+* this function exports the information from the xml to the mapbender database 
+*/
+function wfs2db($gui_id){
+	global $DBSERVER,$DB,$OWNER,$PW;
+	$con = db_connect($DBSERVER,$OWNER,$PW);
+	db_select_db($DB,$con);
+
+	# TABLE wfs
+	
+	$sql = "INSERT INTO wfs (wfs_version, wfs_name, wfs_title, wfs_abstract, wfs_getcapabilities, wfs_describefeaturetype, wfs_getfeature, wfs_transaction) ";
+	$sql .= "VALUES(";
+		$sql .= "'" . $this->wfs_version ."', ";
+		$sql .= "'" . db_escape_string(str_replace("'","",$this->wfs_name)) ."', ";
+		$sql .= "'" . db_escape_string(str_replace("'","",$this->wfs_title)) ."', ";
+		$sql .= "'" . db_escape_string(str_replace("'","",$this->wfs_abstract)) .  "', ";
+		$sql .= "'" . $this->wfs_getcapabilities ."', ";
+		$sql .= "'" . $this->wfs_describefeaturetype . "', ";
+		$sql .= "'". $this->wfs_getfeature . "', ";
+		$sql .= "'". $this->wfs_transaction . "'";
+	$sql .= ");";
+	#echo "sql wfs: <br>".$sql;
+	
+	$res = db_query($sql)or die(db_error());
+	
+	$myWFS = db_insert_id($con,'wfs','wfs_id');
+	#echo "<br> myWFS: ".$myWFS;
+	
+	# TABLE wfs_featuretype
+	
+	for($i=0; $i<count($this->wfs_featuretype); $i++){
+		$sql = "INSERT INTO wfs_featuretype(fkey_wfs_id, featuretype_name, featuretype_title, featuretype_srs) ";
+		$sql .= "VALUES(";
+			$sql .= $myWFS . ",";
+			$sql .= "'".$this->wfs_featuretype[$i]->featuretype_name . "',";
+			$sql .= "'".$this->wfs_featuretype[$i]->featuretype_title."',";
+			$sql .= "'".$this->wfs_featuretype[$i]->featuretype_srs."'";
+		$sql .= ")";
+		
+		#$res = mysql_query($sql) or $this->cleanDB($myWFS,$sql);
+		
+		$res = db_query($sql) or $this->cleanDB($myWFS,$sql);
+
+		
+		# save the id of each featuretype: 
+		$this->wfs_featuretype[$i]->mysql_id = db_insert_id($con,'wfs_featuretype','featuretype_id');
+		
+		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
+			$sql = "INSERT INTO wfs_element(fkey_featuretype_id, element_name,element_type) ";
+			$sql .= "VALUES("; 
+			$sql .= "'" .$this->wfs_featuretype[$i]->mysql_id. "', ";
+			$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_element[$j]["name"]. "', ";
+			$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]. "' ";
+			$sql .= ")";
+			
+			$res = db_query($sql) or $this->cleanDB($myWFS,$sql);
+		}
+
+		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_namespace);$j++){
+			$sql = "INSERT INTO wfs_featuretype_namespace(fkey_wfs_id, fkey_featuretype_id, namespace, namespace_location) ";
+			$sql .= "VALUES("; 
+			$sql .= "'" .$myWFS. "',";
+			$sql .= "'" .$this->wfs_featuretype[$i]->mysql_id. "', ";
+			$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"]. "', ";
+			$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]. "' ";
+			$sql .= ")";
+			
+			$res = db_query($sql) or $this->cleanDB($myWFS,$sql);
+		}
+	}
+	
+	# TABLE gui_wfs
+	
+	$sql ="INSERT INTO gui_wfs (fkey_gui_id, fkey_wfs_id)";
+	$sql .= "VALUES(";
+		$sql .= "'" . $gui_id . "', ";
+		$sql .= $myWFS;
+	$sql .= ");";
+	
+	$res = db_query($sql) or $this->cleanDB($myWFS,$sql);
+}
+function cleanDB($wfsid,$sql){
+	global $DBSERVER,$DB,$OWNER,$PW;
+	$con = db_connect($DBSERVER,$OWNER,$PW);
+	db_select_db($DB,$con);
+	$s = "DELETE FROM wfs WHERE wfs_id = ".$wfsid;
+	$res = db_query($s);
+	echo "<br>Error in :".$sql."<br>";
+	echo "<br>Db cleaned.<br>";
+	die;
+}
+
+
+  /**
+* creatObjfromDB
+*
+*/ 
+function createObjFromDB________($wfs_id){
+	global $server,$db,$owner,$pw;
+	$con = mysql_connect($server,$owner,$pw);
+	mysql_select_db($db, $con);
+
+	$sql = "SELECT * FROM wfs WHERE wfs_id = ".$wfs_id.";";
+	$res = mysql_query($sql);
+	$cnt = 0;
+	while(mysql_fetch_row($res)){
+		$this->wfs_id = mysql_result($res, $cnt, "wfs_id");
+		$this->wfs_version = mysql_result($res, $cnt, "wfs_version");
+		$this->wfs_title = mysql_result($res, $cnt, "wfs_title");
+		$this->wfs_abstract = mysql_result($res, $cnt, "wfs_abstract");
+		$this->wfs_getcapabilities = mysql_result($res, $cnt, "wfs_getcapabilities");
+		$this->wfs_describefeaturetype = mysql_result($res, $cnt, "wfs_describefeaturetype");
+		
+		$sql_fe = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = " . $this->wfs_id . " ORDER BY featuretype_id";
+		$res_fe = mysql_query($sql_fe);
+		$cnt_fe = 0;
+		while(mysql_fetch_row($res_fe)){
+			$c = count($this->wfs_featuretype);
+			$this->wfs_featuretype[$c]->featuretype_name = mysql_result($res_fe, $cnt_fe, "featuretype_name");
+			$this->wfs_featuretype[$c]->featuretype_title = mysql_result($res_fe, $cnt_fe, "featuretype_title");
+			$this->wfs_featuretype[$c]->featuretype_srs = mysql_result($res_fe, $cnt_fe, "featuretype_srs");
+			$this->wfs_featuretype[$c]->featuretype_geomtype = mysql_result($res_fe, $cnt_fe, "featuretype_geomtype");
+			
+			$sql_el = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = ". mysql_result($res_fe, $cnt_fe, "featuretype_id")." ORDER BY element_id";
+			$res_el = mysql_query($sql_el);
+			$cnt_el = 0;
+			while(mysql_fetch_row($res_el)){
+				$z = count($this->wfs_featuretype[$c]->featuretype_element);
+				$this->wfs_featuretype[$c]->featuretype_element[$z]["name"] = mysql_result($res_el, $cnt_el, "element_name");
+				$this->wfs_featuretype[$c]->featuretype_element[$z]["type"] = mysql_result($res_el, $cnt_el, "element_type");
+				$cnt_el++;
+			}
+			$sql_el = "SELECT * FROM wfs_featuretype_namespace WHERE fkey_featuretype_id = ". mysql_result($res_fe, $cnt_fe, "featuretype_id")." ORDER BY namespace";
+			$res_el = mysql_query($sql_el);
+			$cnt_el = 0;
+			while(mysql_fetch_row($res_el)){
+				$z = count($this->wfs_featuretype[$c]->featuretype_namespace);
+				$this->wfs_featuretype[$c]->featuretype_namespace[$z]["name"] = mysql_result($res_el, $cnt_el, "namespace");
+				$this->wfs_featuretype[$c]->featuretype_namespace[$z]["value"] = mysql_result($res_el, $cnt_el, "namespace_location");
+				$cnt_el++;
+			}
+			$cnt_fe++;
+		}
+		$cnt++;
+	}
+   }
+}
+/** end createObjfromDB **/
+
+
+class featuretype extends wfs{
+	var $featuretype_element = array();	
+	var $featuretype_namespace = array();	
+	
+	function featuretype($name,$title,$srs,$url,$version){
+
+		$url .= "&SERVICE=WFS&VERSION=".$version."&REQUEST=DescribeFeatureType&TYPENAME=".$name;
+		
+		$this->featuretype_name = $name;
+		$this->featuretype_title = $title;
+		$this->featuretype_srs = $srs;
+				
+		$data = implode("",file($url));
+		$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_parse_into_struct($parser,$data,$values,$tags);
+		xml_parser_free($parser);
+		
+		foreach ($values as $element) {	
+			if($this->sepNameSpace($element[tag]) == "schema" && $element[type] == "open"){
+				$section = "namespace";
+				echo "namespace<br>";
+			}
+			//echo $element[attributes][name] . "<br/>";
+			if($section == "namespace"){
+				while (list($k, $val) = each ($element[attributes])) {
+   					if (substr($k, 0, 5) == "xmlns") {
+						$cnt = count($this->featuretype_namespace);
+						$match = false;
+						for ($i = 0 ; $i < $cnt && $match == false ; $i++) {
+							if ($this->sepNameSpace($k) == $this->featuretype_namespace[$i]["name"] && $val == $this->featuretype_namespace[$i]["value"]) {
+								$match = true;
+							}
+						}
+						if ($match == false) {
+							$this->featuretype_namespace[$cnt]["name"] = $this->sepNameSpace($k);
+							$this->featuretype_namespace[$cnt]["value"] = $val;
+							echo "namespace: " . $this->sepNameSpace($k) . " -> " . $val . "<br>";
+						}
+   					}
+				}
+			}
+			if($this->sepNameSpace($element[tag]) == "schema" && $element[type] == "close"){
+				$section = "";
+			}
+			if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "open"){
+				$section = "complexcontent";
+				echo "complexcontent<br>";
+			}
+			if($section == "complexcontent" && $this->sepNameSpace($element[tag]) == "element" && $element[attributes][name]){
+				$cnt = count($this->featuretype_element);
+				$this->featuretype_element[$cnt]["name"] = $element[attributes]["name"];
+				$this->featuretype_element[$cnt]["type"] = $this->sepNameSpace($element[attributes]["type"]);
+				echo "element: ".$this->featuretype_element[$cnt]["name"]."<br>";
+			}
+			if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "close"){
+				$section = "";
+			}
+		}
+	}
+	function sepNameSpace($s){
+		$c = strpos($s,":"); 
+		if($c>0){
+			return substr($s,$c+1);
+		}
+		else{
+			return $s;
+		}		
+	}
+}
 ?>
\ No newline at end of file




More information about the Mapbender_commits mailing list