[Mapbender-commits] r2406 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Apr 23 11:59:32 EDT 2008


Author: christoph
Date: 2008-04-23 11:59:31 -0400 (Wed, 23 Apr 2008)
New Revision: 2406

Added:
   trunk/mapbender/http/classes/class_json.php
   trunk/mapbender/http/classes/class_user.php
   trunk/mapbender/http/classes/class_weldMaps2Image.php
Removed:
   trunk/mapbender/http/classes/class_kml_parser_2.2.php
Modified:
   trunk/mapbender/http/classes/class_administration.php
   trunk/mapbender/http/classes/class_gml2.php
   trunk/mapbender/http/classes/class_gui.php
   trunk/mapbender/http/classes/class_kml_ows.php
   trunk/mapbender/http/classes/class_kml_parser_ows.php
   trunk/mapbender/http/classes/class_kml_polygon.php
   trunk/mapbender/http/classes/class_locale.php
   trunk/mapbender/http/classes/class_mb_log.php
   trunk/mapbender/http/classes/class_metadata.php
   trunk/mapbender/http/classes/class_stripRequest.php
   trunk/mapbender/http/classes/class_wfs.php
   trunk/mapbender/http/classes/class_wfs_conf.php
   trunk/mapbender/http/classes/class_wmc.php
   trunk/mapbender/http/classes/class_wms.php
Log:
merge w/ 2.5 branch (1)

Modified: trunk/mapbender/http/classes/class_administration.php
===================================================================
--- trunk/mapbender/http/classes/class_administration.php	2008-04-23 13:21:04 UTC (rev 2405)
+++ trunk/mapbender/http/classes/class_administration.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -18,10 +18,11 @@
 
 require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
 require_once(dirname(__FILE__)."/class_mb_exception.php");
+require_once(dirname(__FILE__)."/class_user.php");
 $con = db_connect(DBSERVER,OWNER,PW);
 db_select_db(DB,$con);
 
-require("phpmailer-1.72/class.phpmailer.php");
+require(dirname(__FILE__) . "/phpmailer-1.72/class.phpmailer.php");
 
 /**
  * class to wrap administration methods
@@ -632,51 +633,13 @@
 		return $arrayWmc;
  	}
 
-	function getGuisByPermission($mb_user_id,$ignoreublic){
-		$arrayGuis = array();
-		$mb_user_groups = array();
-		$sql_groups = "SELECT fkey_mb_group_id FROM mb_user_mb_group WHERE fkey_mb_user_id = $1 ";
-		$v = array($mb_user_id);
-		$t = array("i");
-		$res_groups = db_prep_query($sql_groups,$v,$t);
-		$cnt_groups = 0;
-		while($row = db_fetch_array($res_groups)){
-			$mb_user_groups[$cnt_groups] = $row["fkey_mb_group_id"];
-			$cnt_groups++;
-		}
-		if($cnt_groups > 0){
-			$v = array();
-			$t = array();
-			$sql_g = "SELECT gui.gui_id FROM gui JOIN gui_mb_group ";
-			$sql_g .= " ON gui.gui_id = gui_mb_group.fkey_gui_id WHERE gui_mb_group.fkey_mb_group_id IN (";
-			for($i=0; $i<count($mb_user_groups);$i++){
-				if($i > 0){$sql_g .= ",";}
-				$sql_g .= "$".strval($i+1);
-				array_push($v,$mb_user_groups[$i]);
-				array_push($t,"i");
-			}
-			$sql_g .= ") GROUP BY gui.gui_id";
-			$res_g = db_prep_query($sql_g,$v,$t);
-			while($row = db_fetch_array($res_g)){
-				array_push($arrayGuis,$row["gui_id"]);
-			}
-		}
-		$sql_guis = "SELECT gui.gui_id FROM gui JOIN gui_mb_user ON gui.gui_id = gui_mb_user.fkey_gui_id";
-		$sql_guis .= " WHERE (gui_mb_user.fkey_mb_user_id = $1) ";
-		if (!isset($ignore_public) OR $ignore_public== false){
-			$sql_guis .= " AND gui.gui_public = 1 ";
-		}
-		$sql_guis .= " GROUP BY gui.gui_id";
-		$v = array($mb_user_id);
-		$t = array("i");
-		$res_guis = db_prep_query($sql_guis,$v,$t);
-		$guis = array();
-		while($row = db_fetch_array($res_guis)){
-			if(!in_array($row['gui_id'],$arrayGuis)){
-				array_push($arrayGuis,$row["gui_id"]);
-			}
-		}
-		return $arrayGuis;
+	/**
+	 * @deprecated
+	 */
+	function getGuisByPermission($mb_user_id,$ignorepublic){
+		$e = new mb_notice("administration->getGuisByPermission is deprecated, use user->getApplicationsByPermission instead!"); 
+		$user = new User($mb_user_id);
+		return $user->getApplicationsByPermission($ignorepublic);
 	}
 
 	function getWmsByOwnGuis($array_gui_ids){
@@ -793,7 +756,63 @@
    		}
    	}
 
-   	function getWMSOWSstring($wms_id){
+
+	/**
+	 * Checks if a user is allowed to access a GUI element
+	 * 
+	 * @return boolean 
+	 * @param $arrayGuis Object
+	 * @param $modulePath Object
+	 * @param $elementTag Object
+	 */
+   	function checkModulePermission_new($userId, $modulePath, $elementTag){
+   		if (CHECK) {
+			$arrayGuis = $this->getGuisByPermission($userId, true);
+
+			switch ($elementTag) {
+				case "a" :
+					$column = "e_attributes";
+					$pattern = "/^.*href\s*=\s*(\'|\")\.\.((\/[a-zA-Z0-9_\/\.]+)+)(\?|\'|\").*$/";
+					$replace = "$2";
+					break;
+				case "iframe" :
+					$column = "e_src";
+					$pattern = "/^\.\.((\/[a-zA-Z0-9_\/\.]+)+)(\?|\'|\").*$/";
+					$replace = "$1";
+					break;
+			}
+
+	   		if ($column && count($arrayGuis) > 0) {
+	   			$v = array();
+	   			$t = array();
+		   		$sql = "SELECT DISTINCT ".$column." FROM gui_element WHERE fkey_gui_id IN (";
+		   		for($i=0; $i<count($arrayGuis); $i++){
+		   			if($i > 0){ $sql .= ","; }
+		   			$sql .= "$".($i+1);
+		   			array_push($v,$arrayGuis[$i]);
+		   			array_push($t,'s');
+		   		}
+		   		$sql .= ") ORDER BY " . $column;
+				$res = db_prep_query($sql,$v,$t);
+				while($row = db_fetch_array($res)){
+					if ($row[$column]) {
+						if (preg_match($pattern, stripslashes($row[$column]))) {
+							$dbFilename = preg_replace($pattern, $replace, stripslashes($row[$column]));
+							$e = new mb_notice($dbFilename . " - " . $modulePath);
+
+							if(strpos($modulePath, $dbFilename) !== false){
+								return true;
+							}
+						}
+					}
+				}
+	   		}
+			return false;
+   		}
+		return true;
+   	}
+	
+	function getWMSOWSstring($wms_id){
    		$sql = "SELECT wms_owsproxy FROM wms WHERE wms_id = $1 ";
    		$v = array($wms_id);
    		$t = array("i");
@@ -1055,44 +1074,14 @@
 	 
 	 /** identifies the Conf-FeatureServices where the current user is owner
 	 * 
+	 * @deprecated
 	 * @param integer 		userid the user-ID of the current user
 	 * @return integer[] 	the IDs of the wfs_conf-table
 	 */
-	 function getWfsConfByPermission($userid){
-	 	
-	 	
-	 	$guisByPer = array();
-//	 	1.
-	 	$guisByPer = $this->getGuisByPermission($userid, true);
-	 	
-//	 	2. 
-		if(count($guisByPer)>0){
-			$v = array();
-			$t = array();
-			$sql = "SELECT wfs_conf.wfs_conf_id  FROM gui_wfs_conf, wfs_conf " .
-					"where wfs_conf.wfs_conf_id = gui_wfs_conf.fkey_wfs_conf_id " .
-					"and gui_wfs_conf.fkey_gui_id IN(";
-			for($i=0; $i<count($guisByPer); $i++){
-				if($i>0){ $sql .= ",";}
-				$sql .= "$".strval($i+1);
-				
-				array_push($v, $guisByPer[$i]);
-				array_push($t, "s");
-			}
-			$sql .= ") GROUP BY wfs_conf.wfs_conf_id ORDER BY wfs_conf.wfs_conf_id";
-			
-			
-			$res = db_prep_query($sql,$v,$t);
-			$ownWFSconfs = array();
-			$i=0;
-			while($row = db_fetch_array($res)){
-				
-				$ownWFSconfs[$i] = $row['wfs_conf_id'];
-				$i++;
-			}
-		}
-		return $ownWFSconfs;
-
+	 function getWfsConfByPermission($userid){
+		$e = new mb_notice("administration->getWfsConfByPermission is deprecated, use user->getWfsConfByPermission instead!"); 
+		$user = new User($userid); 	
+		return $user->getWfsConfByPermission();
 	 }
 }
 ?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_gml2.php
===================================================================
--- trunk/mapbender/http/classes/class_gml2.php	2008-04-23 13:21:04 UTC (rev 2405)
+++ trunk/mapbender/http/classes/class_gml2.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -1,5 +1,5 @@
 <?php
-# $Id: class_gml2.php 2058 2008-02-05 14:39:45Z verenadiewald $
+# $Id$
 # http://www.mapbender.org/index.php/class_gml2.php
 # Copyright (C) 2002 CCGIS 
 #
@@ -18,7 +18,7 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 require_once("class_mb_exception.php");
 require_once("class_connector.php");
-require_once("../extensions/JSON.php");
+require_once("../classes/class_json.php");
 require_once("../../conf/mapbender.conf");
 class gml2 {
 	var $geomtype_point = 'Point';					
@@ -500,7 +500,7 @@
 				$cnt ++;
 		}
 
-		$json = new Services_JSON();
+		$json = new Mapbender_JSON();
 		$str .= $json->encode($prop); 
 		$str .= "}";
 		

Modified: trunk/mapbender/http/classes/class_gui.php
===================================================================
--- trunk/mapbender/http/classes/class_gui.php	2008-04-23 13:21:04 UTC (rev 2405)
+++ trunk/mapbender/http/classes/class_gui.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -1,5 +1,4 @@
 <?php
-
 # $Id$
 # http://www.mapbender.org/index.php/class_gui.php
 # Copyright (C) 2002 CCGIS
@@ -19,253 +18,201 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+
 $con = db_connect($DBSERVER,$OWNER,$PW);
 db_select_db(DB,$con);
 
-class gui{
+/**
+ * GUI is a set of GUI elements and services. 
+ */
+class gui {
 
-	function gui() {
+	public function __construct () {
 	}
 
- 	// CB - returns true if a gui '$gui_id' exists
- 	function guiExists($gui_id){
-		$sql = "SELECT * FROM gui ";
-		$sql .= "WHERE gui_id = $1";
+ 	/**
+ 	 * Checks if a GUI with a given ID exists in the database
+ 	 * 
+ 	 * @param integer $gui_id the ID of the GUI that is being checked
+ 	 * @return boolean true if a gui '$gui_id' exists; else false
+ 	 */
+ 	public function guiExists ($gui_id){
+		$sql = "SELECT * FROM gui WHERE gui_id = $1";
 		$v = array($gui_id);
 		$t = array('s');
 		$res = db_prep_query($sql,$v,$t);
 		$row = db_fetch_array($res);
-		if ($row) return true;
-		else return false;
+		if ($row) {
+			return true;	
+		}
+		return false;
  	}
 
-	// CB - deletes a GUI $guiId and all its links to users, layers etc.
-	function deleteGui ($guiId) {
+	
+	/**
+	 * Deletes a GUI $guiId and all its links to users, layers etc.
+	 * 
+	 * @param Integer $guiId the GUI that is going to be deleted
+	 * @return boolean true if the deletion succeded, else false
+	 */
+	public function deleteGui ($guiId) {
 		$guiList = $guiId;
 
-		$sql = "BEGIN";
-		$res = db_query($sql);
-		if (!$res) {
-			$report .=  "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-			$error = true;
-		}
+		$sql = array();
+		$v = array();			
+		$t = array();
 
-		$sql = "DELETE FROM gui WHERE gui_id = $1";
-		$v = array($guiList);
-		$t = array('s');
-		$res = db_prep_query($sql,$v,$t);
-		if (!$res) {
-			$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-			$error = true;
-		}
+		array_push($sql, "BEGIN");
+		array_push($v, array());
+		array_push($t, array());
+		
+		array_push($sql, "DELETE FROM gui WHERE gui_id = $1");
+		array_push($v, array($guiList));
+		array_push($t, array('s'));
 
-		$sql = "DELETE FROM gui_element WHERE fkey_gui_id = $1";
-		$v = array($guiList);
-		$t = array('s');
-		$res = db_prep_query($sql,$v,$t);
-		if (!$res) {
-			$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-			$error = true;
-		}
+		array_push($sql, "DELETE FROM gui_element WHERE fkey_gui_id = $1");
+		array_push($v, array($guiList));
+		array_push($t, array('s'));
 
-		$sql = "DELETE FROM gui_element_vars WHERE fkey_gui_id = $1";
-		$v = array($guiList);
-		$t = array('s');
-		$res = db_prep_query($sql,$v,$t);
-		if (!$res) {
-			$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-			$error = true;
-		}
+		array_push($sql, "DELETE FROM gui_element_vars WHERE fkey_gui_id = $1");
+		array_push($v, array($guiList));
+		array_push($t, array('s'));
 
-		$sql = "DELETE FROM gui_layer WHERE fkey_gui_id = $1";
-		$v = array($guiList);
-		$t = array('s');
-		$res = db_prep_query($sql,$v,$t);
-		if (!$res) {
-			$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-			$error = true;
-		}
+		array_push($sql, "DELETE FROM gui_layer WHERE fkey_gui_id = $1");
+		array_push($v, array($guiList));
+		array_push($t, array('s'));
 
-		$sql = "DELETE FROM gui_mb_group WHERE fkey_gui_id = $1";
-		$v = array($guiList);
-		$t = array('s');
-		$res = db_prep_query($sql,$v,$t);
-		if (!$res) {
-			$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-			$error = true;
-		}
+		array_push($sql, "DELETE FROM gui_mb_group WHERE fkey_gui_id = $1");
+		array_push($v, array($guiList));
+		array_push($t, array('s'));
 
-		$sql = "DELETE FROM gui_mb_user WHERE fkey_gui_id = $1";
-		$v = array($guiList);
-		$t = array('s');
-		$res = db_prep_query($sql,$v,$t);
-		if (!$res) {
-			$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-			$error = true;
-		}
+		array_push($sql, "DELETE FROM gui_mb_user WHERE fkey_gui_id = $1");
+		array_push($v, array($guiList));
+		array_push($t, array('s'));
 
-		$sql = "DELETE FROM gui_treegde WHERE fkey_gui_id = $1";
-		$v = array($guiList);
-		$t = array('s');
-		$res = db_prep_query($sql,$v,$t);
-		if (!$res) {
-			$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-			$error = true;
-		}
+		array_push($sql, "DELETE FROM gui_treegde WHERE fkey_gui_id = $1");
+		array_push($v, array($guiList));
+		array_push($t, array('s'));
 
-		$sql = "DELETE FROM gui_wfs WHERE fkey_gui_id = $1";
-		$v = array($guiList);
-		$t = array('s');
-		$res = db_prep_query($sql,$v,$t);
-		if (!$res) {
-			$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-			$error = true;
-		}
+		array_push($sql, "DELETE FROM gui_wfs WHERE fkey_gui_id = $1");
+		array_push($v, array($guiList));
+		array_push($t, array('s'));
 
-		$sql = "DELETE FROM gui_wms WHERE fkey_gui_id = $1";
-		$v = array($guiList);
-		$t = array('s');
-		$res = db_prep_query($sql,$v,$t);
-		if (!$res) {
-			$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-			$error = true;
-		}
+		array_push($sql, "DELETE FROM gui_wms WHERE fkey_gui_id = $1");
+		array_push($v, array($guiList));
+		array_push($t, array('s'));
 
-		// if $error is true, the transaction is aborted -> rollback
-		if (!$error) {
-			$sql = "COMMIT";
-			$res = db_query($sql);
+		array_push($sql, "COMMIT");
+		array_push($v, array());
+		array_push($t, array());
+
+		// execute all SQLs
+		for ($i = 0; $i < count($sql); $i++) {
+			$res = db_prep_query($sql[$i], $v[$i], $t[$i]);
+			// if an SQL fails, send a ROLLBACK and return false
 			if (!$res) {
-				$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-				$error = true;
+				db_query("ROLLBACK");
+				return false;
 			}
 		}
-		//if $error is false, the transaction is executed -> commit
-		else {
-			$sql = "ROLLBACK";
-			$res = db_query($sql);
-			if (!$res) {
-				$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-				$error = true;
-			}
-		}
-		return !$error;
+		return true;
 	}
 
-	// CB - rename a GUI
-	function renameGui ($guiId, $newGuiName) {
-		$error = false;
+	/** Renames the GUI $guiID to $newGUIName
+	 * 
+	 * @param Integer $guiId ID of the GUI
+	 * @param String $newGuiName the new name of the GUI
+	 * @return boolean true if the renaming succeded, else false
+	 */
+	public function renameGui ($guiId, $newGuiName) {
 		if ($this->copyGui($guiId, $newGuiName, true)) {
 			$this->deleteGui($guiId);
+			return true;
 		}
-		else {
-			$error = true;
-		}
-		return !$error;
+		return false;
 	}
 
-	// CB - copies a GUI $guiId and all its links to users, layers etc. to GUI $newGuiName
- 	function copyGui ($guiId, $newGuiName, $withUsers) {
-		$error = false;
+	/**
+	 * 
+ 	 * Copies a GUI $guiId and all its links to users, layers etc. to GUI $newGuiName
+ 	 * 
+	 * @param Integer $guiId ID of the GUI
+	 * @param String $newGuiName the new name of the GUI
+	 * @param boolean $withUsers true if the users, that may access the GUI $guiId, shall have access to the new GUI; else false.
+	 * 
+	 * @return boolean true if the renaming succeded, else false
+	 */ 
+ 	public function copyGui ($guiId, $newGuiName, $withUsers) {
 		$guiList = $guiId;
 		if (!$this->guiExists($newGuiName)) {
-			$sql = "BEGIN";
-			$res = db_query($sql);
-			if (!$res) {
-				$report .=  "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-				$error = true;
-			}
+			
+			$sql = array();
+			$v = array();			
+			$t = array();
+						
+			array_push($sql, "BEGIN");
+			array_push($v, array());
+			array_push($t, array());
 
-			$sql = "INSERT INTO gui (gui_id, gui_name, gui_description, gui_public) SELECT '" . $newGuiName . "', '" . $newGuiName . "',gui_description, gui_public FROM gui WHERE gui_id = '" . $guiList . "';";
-			$res = db_query($sql);
-			if (!$res) {
-				$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-				$error = true;
-			}
+			array_push($sql, "INSERT INTO gui (gui_id, gui_name, gui_description, gui_public) SELECT $1, $2, gui_description, gui_public FROM gui WHERE gui_id = $3;");
+			array_push($v, array ($newGuiName, $newGuiName, $guiList));
+			array_push($t, array ("s", "s", "s"));;
+			
+			array_push($sql, "INSERT INTO gui_element (fkey_gui_id, e_id, e_pos, e_public, e_comment, e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url) SELECT $1, e_id, e_pos, e_public, e_comment, e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url FROM gui_element WHERE fkey_gui_id = $2;");
+			array_push($v, array($newGuiName, $guiList));
+			array_push($t, array("s", "s"));
 
-			$sql = "INSERT INTO gui_element (fkey_gui_id, e_id, e_pos, e_public, e_comment, e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url) SELECT '" . $newGuiName . "', e_id, e_pos, e_public, e_comment, e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url FROM gui_element WHERE fkey_gui_id = '" . $guiList . "';";
-			$res = db_query($sql);
-			if (!$res) {
-				$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-				$error = true;
-			}
+			array_push($sql, "INSERT INTO gui_element_vars (fkey_gui_id, fkey_e_id, var_name, var_value, context, var_type) SELECT $1, fkey_e_id, var_name, var_value, context, var_type FROM gui_element_vars WHERE fkey_gui_id = $2;");
+			array_push($v, array($newGuiName, $guiList));
+			array_push($t, array("s", "s"));
 
-			$sql = "INSERT INTO gui_element_vars (fkey_gui_id, fkey_e_id, var_name, var_value, context, var_type) SELECT '" . $newGuiName . "', fkey_e_id, var_name, var_value, context, var_type FROM gui_element_vars WHERE fkey_gui_id = '" . $guiList . "';";
-			$res = db_query($sql);
-			if (!$res) {
-				$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-				$error = true;
-			}
+			array_push($sql, "INSERT INTO gui_layer (fkey_gui_id, fkey_layer_id, gui_layer_wms_id, gui_layer_status, gui_layer_selectable, gui_layer_visible, gui_layer_queryable, gui_layer_querylayer, gui_layer_minscale, gui_layer_maxscale, gui_layer_priority, gui_layer_style, gui_layer_wfs_featuretype) SELECT $1, fkey_layer_id, gui_layer_wms_id, gui_layer_status, gui_layer_selectable, gui_layer_visible, gui_layer_queryable, gui_layer_querylayer, gui_layer_minscale, gui_layer_maxscale, gui_layer_priority, gui_layer_style, gui_layer_wfs_featuretype FROM gui_layer WHERE fkey_gui_id = $2;");
+			array_push($v, array($newGuiName, $guiList));
+			array_push($t, array("s", "s"));
 
-			$sql = "INSERT INTO gui_layer (fkey_gui_id, fkey_layer_id, gui_layer_wms_id, gui_layer_status, gui_layer_selectable, gui_layer_visible, gui_layer_queryable, gui_layer_querylayer, gui_layer_minscale, gui_layer_maxscale, gui_layer_priority, gui_layer_style, gui_layer_wfs_featuretype) SELECT '" . $newGuiName . "', fkey_layer_id, gui_layer_wms_id, gui_layer_status, gui_layer_selectable, gui_layer_visible, gui_layer_queryable, gui_layer_querylayer, gui_layer_minscale, gui_layer_maxscale, gui_layer_priority, gui_layer_style, gui_layer_wfs_featuretype FROM gui_layer WHERE fkey_gui_id = '" . $guiList . "';";
-			$res = db_query($sql);
-			if (!$res) {
-				$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-				$error = true;
-			}
-
 			if ($withUsers == true) {
 				/* group of original gui is copied as well */
-				$sql = "INSERT INTO gui_mb_group (fkey_gui_id, fkey_mb_group_id, mb_group_type) SELECT '" . $newGuiName . "', fkey_mb_group_id, mb_group_type FROM gui_mb_group WHERE fkey_gui_id = '" . $guiList . "';";
-				$res = db_query($sql);
-				if (!$res) {
-					$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-					$error = true;
-				}
+				array_push($sql, "INSERT INTO gui_mb_group (fkey_gui_id, fkey_mb_group_id, mb_group_type) SELECT $1, fkey_mb_group_id, mb_group_type FROM gui_mb_group WHERE fkey_gui_id = $2;");
+				array_push($v, array($newGuiName, $guiList));
+				array_push($t, array("s", "s"));
 
 				/* users of original gui are copied as well */
-				$sql = "INSERT INTO gui_mb_user (fkey_gui_id, fkey_mb_user_id, mb_user_type) SELECT '" . $newGuiName . "', fkey_mb_user_id, mb_user_type FROM gui_mb_user WHERE fkey_gui_id = '" . $guiList . "';";
-				$res = db_query($sql);
-				if (!$res) {
-					$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-					$error = true;
-				}
+				array_push($sql, "INSERT INTO gui_mb_user (fkey_gui_id, fkey_mb_user_id, mb_user_type) SELECT $1, fkey_mb_user_id, mb_user_type FROM gui_mb_user WHERE fkey_gui_id = $2;");
+				array_push($v, array($newGuiName, $guiList));
+				array_push($t, array("s", "s"));
 			}
 			else {
 				// users of original gui are not copied, the current user is set as owner 
-				$sql = "INSERT INTO gui_mb_user (fkey_gui_id, fkey_mb_user_id, mb_user_type) VALUES ($1, $2, 'owner')";
-				$v = array($newGuiName, $_SESSION["mb_user_id"]);
-				$t = array('s', 'i');
-				$res = db_prep_query($sql,$v,$t);
-				if (!$res) {
-					$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-					$error = true;
-				}
+				array_push($sql, "INSERT INTO gui_mb_user (fkey_gui_id, fkey_mb_user_id, mb_user_type) VALUES ($1, $2, 'owner')");
+				array_push($v, array($newGuiName, $_SESSION["mb_user_id"]));
+				array_push($t, array('s', 'i'));
 			}
-			$sql = "INSERT INTO gui_treegde (fkey_gui_id, fkey_layer_id, id, lft, rgt, my_layer_title, layer, wms_id) SELECT '" . $newGuiName . "', fkey_layer_id, id, lft, rgt, my_layer_title, layer, wms_id FROM gui_treegde WHERE fkey_gui_id = '" . $guiList . "';";
-			$res = db_query($sql);
-			if (!$res) {
-				$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-				$error = true;
-			}
+			array_push($sql, "INSERT INTO gui_treegde (fkey_gui_id, fkey_layer_id, id, lft, rgt, my_layer_title, layer, wms_id) SELECT $1, fkey_layer_id, id, lft, rgt, my_layer_title, layer, wms_id FROM gui_treegde WHERE fkey_gui_id = $2;");
+			array_push($v, array($newGuiName, $guiList));
+			array_push($t, array("s", "s"));
 
-			$sql = "INSERT INTO gui_wfs (fkey_gui_id, fkey_wfs_id) SELECT '" . $newGuiName . "', fkey_wfs_id FROM gui_wfs WHERE fkey_gui_id = '" . $guiList . "';";
-			$res = db_query($sql);
-			if (!$res) {
-				$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-				$error = true;
-			}
+			array_push($sql, "INSERT INTO gui_wfs (fkey_gui_id, fkey_wfs_id) SELECT $1, fkey_wfs_id FROM gui_wfs WHERE fkey_gui_id = $2;");
+			array_push($v, array($newGuiName, $guiList));
+			array_push($t, array("s", "s"));
 
-			$sql = "INSERT INTO gui_wms (fkey_gui_id, fkey_wms_id, gui_wms_position, gui_wms_mapformat, gui_wms_featureinfoformat, gui_wms_exceptionformat, gui_wms_epsg, gui_wms_visible) SELECT '" . $newGuiName . "', fkey_wms_id, gui_wms_position, gui_wms_mapformat, gui_wms_featureinfoformat, gui_wms_exceptionformat, gui_wms_epsg, gui_wms_visible FROM gui_wms WHERE fkey_gui_id = '" . $guiList . "';";
-			$res = db_query($sql);
-			if (!$res) {
-				$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-				$error = true;
-			}
+			array_push($sql, "INSERT INTO gui_wms (fkey_gui_id, fkey_wms_id, gui_wms_position, gui_wms_mapformat, gui_wms_featureinfoformat, gui_wms_exceptionformat, gui_wms_epsg, gui_wms_visible) SELECT $1, fkey_wms_id, gui_wms_position, gui_wms_mapformat, gui_wms_featureinfoformat, gui_wms_exceptionformat, gui_wms_epsg, gui_wms_visible FROM gui_wms WHERE fkey_gui_id = $2;");
+			array_push($v, array($newGuiName, $guiList));
+			array_push($t, array("s", "s"));
+			
+			array_push($sql, "COMMIT");
+			array_push($v, array());
+			array_push($t, array());
 
-			// if $error is false, the transaction is executed -> commit
-			if (!$error) {
-				$sql = "COMMIT";
-			} 
-			else {
-				$sql = "ROLLBACK";
+			// execute all SQLs
+			for ($i = 0; $i < count($sql); $i++) {
+				$res = db_prep_query($sql[$i], $v[$i], $t[$i]);
+				// if an SQL fails, send a ROLLBACK and return false
+				if (!$res) {
+					db_query("ROLLBACK");
+					return false;
+				}
 			}
-			$res = db_query($sql);
-			if (!$res) {
-				$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
-				$error = true;
-			}
-			return !$error;
+			return true;
 		}
 		else {
 	      echo "<script language='javascript'>";

Copied: trunk/mapbender/http/classes/class_json.php (from rev 2404, branches/2.5/http/classes/class_json.php)
===================================================================
--- trunk/mapbender/http/classes/class_json.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_json.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -0,0 +1,81 @@
+<?php
+# $Id$
+# http://www.mapbender.org/index.php/JSON
+# 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.
+
+mb_internal_encoding("UTF-8");
+
+require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+
+define("JSON_PEAR", "json_pear");
+define("JSON_NATIVE", "json_native");
+
+if (!function_exists("json_encode")) {
+	require_once(dirname(__FILE__)."/../classes/class_json.php");
+}
+
+/**
+ * A wrapper class for PHP JSON encoding/decoding.
+ * Uses native PHP functions if available.
+ * 
+ * @class
+ */
+class Mapbender_JSON {
+	
+	/**
+	 * Either JSON_PEAR or JSON_NATIVE
+	 */
+	private $library = JSON_PEAR;
+
+	/**
+	 * Determines which JSON lib to use.
+	 * @constructor
+	 */
+	public function __construct(){
+		if (function_exists("json_encode")) {
+			$this->library = JSON_NATIVE;
+		}
+	}
+	
+	/**
+	 * Encodes an object to JSON
+	 */
+	public function encode($anObject) {
+		if ($this->library == JSON_PEAR) {
+			$pear = new Mapbender_JSON();
+			$e = new mb_notice("using PEAR JSON");
+			return $pear->encode($anObject);
+		}
+		$e = new mb_notice("using native JSON");
+		return json_encode($anObject);
+	}
+
+	/**
+	 * Decodes a JSON string
+	 */
+	public function decode($aString) {
+		if ($this->library == JSON_PEAR) {
+			$pear = new Mapbender_JSON();
+			$e = new mb_notice("using PEAR JSON");
+			return $pear->decode($aString);
+		}
+		$e = new mb_notice("using native JSON");
+		return json_decode($aString);
+	}
+}
+?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_kml_ows.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_ows.php	2008-04-23 13:21:04 UTC (rev 2405)
+++ trunk/mapbender/http/classes/class_kml_ows.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -21,7 +21,7 @@
 mb_internal_encoding("UTF-8");
 
 require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
-require_once(dirname(__FILE__)."/../extensions/JSON.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
 require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
 require_once(dirname(__FILE__)."/../classes/class_point.php");
 
@@ -108,9 +108,9 @@
 						$coordinates = "";
 						for ($j = 0; $j < count($coordinatesArray); $j++) {
 							if ($j > 0) {
-								$coordinates .= ",";
+								$coordinates .= " ";
 							}
-							$coordinates .= $coordinatesArray[$j]["x"] . "," . $coordinatesArray[$j]["y"];
+							$coordinates .= $coordinatesArray[$j]["x"] . "," . $coordinatesArray[$j]["y"] . ",0";
 							
 						}
 						$e_coordinates = $doc->createElement("coordinates", $coordinates);
@@ -134,6 +134,12 @@
 		return $this->kml;
 	}
 	
+	/**
+	 * @return string the ID of this KML.
+	 */
+	public function getId () {
+		return $this->id;
+	}
 	
 	/**
 	 * parses an incoming KML, creates the object, 
@@ -175,7 +181,7 @@
 		$e = new mb_notice("parsing finished...#placemarks: " . count($this->placemarkArray) . " (" . count($parser->placemarkArray) . ")");
 		$this->placemarkArray = $parser->placemarkArray; 
 
-		print_r($this);
+//		print_r($this);
 		
 //		$this->kml = $this->__toString();
 
@@ -227,7 +233,7 @@
 			$kmlDoc_DOM->loadXML($kmlFromDb); 
 
 			//load the geoJSON
-			$json = new Services_JSON();
+			$json = new Mapbender_JSON();
 			$geoObj = $json->decode($geoJSON);
 
 			// construct an array that holds all metadata of the placemark
@@ -378,7 +384,7 @@
 	}
 	
 	private function updateGeometry ($currentNode, $geometry) {
-		$json = new Services_JSON();
+		$json = new Mapbender_JSON();
 		$currentNode_SimpleXML = simplexml_import_dom($currentNode);
 
 		$currentTypeXml = mb_strtoupper($currentNode->nodeName);

Deleted: trunk/mapbender/http/classes/class_kml_parser_2.2.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_parser_2.2.php	2008-04-23 13:21:04 UTC (rev 2405)
+++ trunk/mapbender/http/classes/class_kml_parser_2.2.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -1,186 +0,0 @@
-<?php
-# $Id$
-# http://www.mapbender.org/index.php/class_wmc.php
-# 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.
-
-require_once("../classes/class_mb_exception.php");
-require_once("../classes/class_kml_polygon.php");
-require_once("../classes/class_kml_linearring.php");
-require_once("../classes/class_kml_line.php");
-require_once("../classes/class_kml_point.php");
-require_once("../classes/class_kml_multigeometry.php");
-require_once("../classes/class_kml_placemark.php");
-
-/**
- * not used in OGC KML Mapbender project, may be buggy
- */
-class Kml22Parser {
-	public function __construct($kml) {
-		$doc = new DOMDocument("1.0");
-		$doc->preserveWhiteSpace = false;
-		$doc->loadXML($kml);
-
-		/*
-		 * Get geometry information only, store it in placemarkArray
-		 */
-		$placemarkTagArray = $doc->getElementsByTagName("Placemark");
-		
-		foreach ($placemarkTagArray as $node) {
-
-			$geometryArray = $this->getGeometryArrayFromPlacemarkOrMultigeometryNode($node);
-			
-			/*
-			 * For a placemark, the geometryArray should only contain 1 geometry!
-			 */
-			for ($i=0; $i < count($geometryArray); $i++) {
-				$currentPlacemark = new KMLPlacemark($geometryArray[$i]);
-				$currentPlacemark->setName($this->getNameFromPlacemarkNode($node));
-				array_push($this->placemarkArray, $currentPlacemark);
-			}		    
-		}
-	}
-
-	/**
-	 * Given a "Point" node, this function returns the geometry (KMLPoint)
-	 * from within the node.
-	 */
-	private function getGeometryFromPointNode ($node) {
-		$coordinatesNode = $this->getCoordinatesNode($node);
-		$geomString = $coordinatesNode->nodeValue;
-		return new KMLPoint($geomString);
-	}
-	
-	/**
-	 * Given a "LineString" node, this function returns the geometry (KMLLine)
-	 * from within the node.
-	 */
-	private function getGeometryFromLinestringNode ($node) {
-		$coordinatesNode = $this->getCoordinatesNode($node);
-		$geomString = $coordinatesNode->nodeValue;
-		return new KMLLine($geomString);
-	}
-	
-	/**
-	 * Given a "Polygon" node, this function returns the geometry (KMLPolygon)
-	 * from within the node.
-	 */
-	private function getGeometryFromPolygonNode ($node) {
-		$polygon = null;
-
-	    $children = $node->childNodes;
-	    
-		// create new KMLPolygon
-		foreach ($children as $child) {
-			if (mb_strtoupper($child->nodeName) == "OUTERBOUNDARYIS") {
-				// create a new Linear Ring
-				$outerBoundary = $this->getGeometryFromLinearRingNode($child);
-				$polygon = new KMLPolygon($outerBoundary);
-			}
-		}
-		
-		if ($polygon !== null) {
-			// append inner boundaries to KMLPolygon
-			foreach ($children as $child) {
-				if (mb_strtoupper($child->nodeName) == "INNERBOUNDARYIS") {
-					// create a new Linear Ring
-					$innerBoundary = $this->getGeometryFromLinearRingNode($child);
-					$polygon->appendInnerBoundary($innerBoundary);
-				}
-			}
-		}
-		return $polygon;
-	}
-	
-	/**
-	 * Given a "OuterBoundaryIs" or "InnerBoundaryIs" node, this function 
-	 * returns the geometry (KMLLinearRing) within the child node named "linearring"
-	 */
-	private function getGeometryFromLinearRingNode ($node) {
-	    $children = $node->childNodes;
-		foreach($children as $child) {
-			if (mb_strtoupper($child->nodeName) == "LINEARRING") {
-				$coordinatesNode = $this->getCoordinatesNode($child);
-				$geomString = $coordinatesNode->nodeValue;
-				return new KMLLinearRing($geomString);
-			}
-		}
-		return null;
-	}
-	
-	/**
-	 * Checks if the child nodes of a given KML node contains any geometries and
-	 * returns an array of geometries (KMLPoint, KMLPolygon, KMLLinestring and KMLMultigeometry)
-	 */
-	private function getGeometryArrayFromPlacemarkOrMultigeometryNode ($node) {
-	    $geometryArray = array();
-	    
-	    $children = $node->childNodes;
-		foreach($children as $child) {
-			if (mb_strtoupper($child->nodeName) == "POINT") {
-				array_push($geometryArray, $this->getGeometryFromPointNode($child));
-			}
-			elseif (mb_strtoupper($child->nodeName) == "POLYGON") {
-				array_push($geometryArray, $this->getGeometryFromPolygonNode($child));
-			}
-			elseif (mb_strtoupper($child->nodeName) == "LINESTRING") {
-				array_push($geometryArray, $this->getGeometryFromLinestringNode($child));
-			}
-			elseif (mb_strtoupper($child->nodeName) == "MULTIGEOMETRY") {
-				$geometryArray = $this->getGeometryArrayFromPlacemarkOrMultigeometryNode($child);
-				$multigeometry = new KMLMultiGeometry();
-				
-				for ($i=0; $i < count($geometryArray); $i++) {
-					$multigeometry->append($geometryArray[$i]);	
-				}
-				array_push($geometryArray, $multigeometry);
-			}
-		}
-		return $geometryArray;
-	}
-	
-	/**
-	 * Returns the name of the placemark from the placemark node
-	 */
-	function getNameFromPlacemarkNode($node) {
-	    $name = "new";
-	    
-	    $children = $node->childNodes;
-		foreach($children as $child) {
-			if (mb_strtoupper($child->nodeName) == "NAME") {
-				$name = $child->nodeValue;
-			}
-		}
-		return $name;
-	}
-	
-	/**
-	 * Returns the child node with node name "coordinates" of a given KML node.
-	 * If no node is found, null is returned.
-	 */
-	private function getCoordinatesNode ($node) {
-	    $children = $node->childNodes;
-		foreach($children as $child) {
-			if (mb_strtoupper($child->nodeName) == "COORDINATES") {
-				return $child;
-			}
-		}
-		return null;
-	}
-}
-
-// end class
-?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_kml_parser_ows.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_parser_ows.php	2008-04-23 13:21:04 UTC (rev 2405)
+++ trunk/mapbender/http/classes/class_kml_parser_ows.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -17,7 +17,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-require_once(dirname(__FILE__)."/../extensions/JSON.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
 require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
 require_once(dirname(__FILE__)."/../classes/class_point.php");
 require_once(dirname(__FILE__)."/../classes/class_kml_polygon.php");
@@ -37,7 +37,9 @@
 	}
 	
 	public function parseGeoJSON ($geoJSON, $kmlId) {
-		$json = new Services_JSON();
+		
+//		$e = new mb_notice("GEOJSON: " . $geoJSON);
+		$json = new Mapbender_JSON();
 		$geometryFromGeoJSON = $json->decode($geoJSON);
 		$id = 0;
 		
@@ -75,17 +77,20 @@
 					if ($currentGeometry) {
 						$currentPlacemark = new KMLPlacemark($currentGeometry);
 
-						foreach ($feature->properties as $key => $value) {
-							$currentPlacemark->setProperty($key, $value);
+						if (gettype($feature->properties) == "object") {
+							
+							foreach ($feature->properties as $key => $value) {
+								$currentPlacemark->setProperty($key, $value);
+							}
+							$currentPlacemark->setProperty("Mapbender:kml", true);
+							$currentPlacemark->setProperty("Mapbender:name", "unknown");
+							$currentPlacemark->setProperty("Mapbender:id", $kmlId);
+							$currentPlacemark->setProperty("Mapbender:placemarkId", $id);
+							$e = new mb_notice("adding to placemarkArray (current length: " . count($this->placemarkArray) . ")");
+							array_push($this->placemarkArray, $currentPlacemark);
+							$e = new mb_notice("added...new length: " . count($this->placemarkArray));
+							$id ++;
 						}
-						$currentPlacemark->setProperty("Mapbender:kml", true);
-						$currentPlacemark->setProperty("Mapbender:name", "unknown");
-						$currentPlacemark->setProperty("Mapbender:id", $kmlId);
-						$currentPlacemark->setProperty("Mapbender:placemarkId", $id);
-						$e = new mb_notice("adding to placemarkArray (current length: " . count($this->placemarkArray) . ")");
-						array_push($this->placemarkArray, $currentPlacemark);
-						$e = new mb_notice("added...new length: " . count($this->placemarkArray));
-						$id ++;
 					}
 				}
 			}

Modified: trunk/mapbender/http/classes/class_kml_polygon.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_polygon.php	2008-04-23 13:21:04 UTC (rev 2405)
+++ trunk/mapbender/http/classes/class_kml_polygon.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -1,6 +1,6 @@
 <?php
 /**
- * $Id$
+ * @version 	$Id$
  * @link 		http://www.mapbender.org/index.php/class_wmc.php
  * @copyright 	2002 CCGIS 
  * @license		http://opensource.org/licenses/gpl-license.php

Modified: trunk/mapbender/http/classes/class_locale.php
===================================================================
--- trunk/mapbender/http/classes/class_locale.php	2008-04-23 13:21:04 UTC (rev 2405)
+++ trunk/mapbender/http/classes/class_locale.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -1,5 +1,5 @@
 <?php
-# $Id:$
+# $Id$
 # http://www.mapbender.org/index.php/class_locale.php
 # Copyright (C) 2002 CCGIS 
 #
@@ -33,13 +33,22 @@
 	var $browserLanguages = null;
 	var $os = null;
 	var $name = null;
-	var $defaultLanguage = "de";
+	var $defaultLanguage = "en";
 	var $status = "No locale set.";
 	
 	function Mb_locale($languageId) {
-		if (!$this->setCurrentLocale($languageId)) {
-			$e = new Mb_exception("Locale could not be set. Language ID: '" . $languageId . "'");
+		if (!$languageId) {
+			$languageId = LANGUAGE;
 		}
+  		$e = new Mb_notice("class_locale: setting locale to " . $languageId);
+		if (USE_I18N) {
+			if (!$this->setCurrentLocale($languageId)) {
+				$e = new Mb_exception("Locale could not be set. Language ID: '" . $languageId . "'");
+			}
+		}
+		else {
+			$this->setCurrentLocale($this->defaultLanguage);
+		}
 	}
 
 	/**
@@ -84,7 +93,7 @@
 			$this->os = $this->guessHostOS();
 		}
 		
-		if ($this->os != null && isset($languageId)) {
+		if (!USE_I18N || ($this->os != null && isset($languageId))) {
 			if ($this->isKnownLanguage($languageId)) {
 				
 				if ($this->systemLocales == null) {
@@ -122,6 +131,8 @@
 	    return 'linux';
 	  else if (strncasecmp(php_uname(), 'OpenBSD', 7) == 0)
 	    return 'bsd';
+	  else if (strncasecmp(php_uname(), 'FreeBSD', 7) == 0)
+	    return 'bsd';  
 	  else {
 	    throw new Mb_exception('unknown platform: could not interpret uname. php_uname() returned '. php_uname().'. Please report to MB developers');
 	    return null;
@@ -174,6 +185,14 @@
                       'en' => 'en_US',
                       'de_DE' => 'de_DE',
                       'de' => 'de_DE',
+                      'bg_BG' => 'bg_BG',
+                      'bg' => 'bg_BG',
+                      'es_ES' => 'es_ES',
+                      'es' => 'es_ES',  
+                      'nl_NL' => 'nl_NL',
+                      'nl' => 'nl_NL',                                                                
+                      'gr_GR' => 'gr_GR',
+                      'gr' => 'gr_GR',
                       'it_IT' => 'it_IT',
                       'it' => 'it_IT');
 	}

Modified: trunk/mapbender/http/classes/class_mb_log.php
===================================================================
--- trunk/mapbender/http/classes/class_mb_log.php	2008-04-23 13:21:04 UTC (rev 2405)
+++ trunk/mapbender/http/classes/class_mb_log.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -133,11 +133,11 @@
 	/**
 	 * @var	bool	true if the logging succeeded; else false.
 	 */
-	protected $result = false;
+	public $result = false;
 
 	/**
 	 * @var	string	if the logging did not succeed, this contains an error message.
 	 */
-	protected $message = "";
+	public $message = "";
 }
 ?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_metadata.php
===================================================================
--- trunk/mapbender/http/classes/class_metadata.php	2008-04-23 13:21:04 UTC (rev 2405)
+++ trunk/mapbender/http/classes/class_metadata.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -178,8 +178,7 @@
 	/* set categories as array */
 		function set_categories(){
 			$sql = "SELECT * FROM md_topic_category ";
-		
-			$sql .= " ORDER BY md_topic_category_id";
+			$sql .= "ORDER BY md_topic_category_id";
 			
 			$res = db_query($sql);
 			$this->cat[0] = array();
@@ -212,10 +211,10 @@
 		}
 
 	/*
-	 * replace german letters (for example ä => ae)
+	 * replace german letters (for example � => ae)
 	 */
 	function replaceChars($text){
-	$search = array( "ä",  "ö",  "ü",  "Ä",  "Ö",  "Ü",  "ß");
+	$search = array( "�",  "�",  "�",  "�",  "�",  "�",  "�");
 	$repwith = array("ae", "oe", "ue", "AE", "OE", "UE", "ss");
 	
 	if(CHARSET=="UTF-8")
@@ -400,7 +399,7 @@
 		$sql .= " ORDER BY load_count DESC";
 		
 		
-		//Beschränkung
+		//Beschr�nkung
 		$lim = $this->limit;
 		$overLimit = $lim+1;
 		$sql .= " LIMIT ".$overLimit;
@@ -599,13 +598,13 @@
 							$tmp_layer_pos = $member -> getAttribute('layer_pos');
 						    	    
 						    /*
-						     * Wiederfinden des Members über die Attribute
+						     * Wiederfinden des Members �ber die Attribute
 						     */   
 							if ($this->cat[$i]['member'][$ii]['wms_id'] == $tmp_wms_id){
 								
 								if ($this->cat[$i]['member'][$ii]['layer_parent'] == $tmp_layer_pos){
 									$sub = "true";
-									$member->appendChild($m);	// dem member $member wird ein weiteres member $m hinzugefügt
+									$member->appendChild($m);	// dem member $member wird ein weiteres member $m hinzugef�gt
 									break;
 									
 								} else {
@@ -665,7 +664,7 @@
 				$epsg_text = $this->doc->createTextNode($equalEPSG);
 				$epsg->appendChild($epsg_text);
 				
-				// Länderkennung
+				// L�nderkennung
 				$state = $this->doc->createElement('federalstate');
 				$m->appendChild($state);
 				
@@ -690,7 +689,7 @@
 				$last_monitoring_text = $this->doc->createTextNode($lastMonitoring);
 				$last_monitoring->appendChild($last_monitoring_text);
 				
-				// Verfügbarkeit - Prozentzahl
+				// Verf�gbarkeit - Prozentzahl
 				$availability = $this->doc->createElement('availability');
 				$m->appendChild($availability);
 				
@@ -930,7 +929,7 @@
 			$epsg_text = $this->doc->createTextNode($equalEPSG);
 			$epsg->appendChild($epsg_text);
 			
-			// Länderkennung
+			// L�nderkennung
 			$state = $this->doc->createElement('federalstate');
 			$m->appendChild($state);
 			
@@ -1082,7 +1081,7 @@
 	
 		$last_date = date("d.m.Y - H:i", $last_timestamp);
 	
-//		Vorrübergehend auskommentiert da keine aktuellen (auf Timestamp basierten) Daten vorliegen
+//		Vorr�bergehend auskommentiert da keine aktuellen (auf Timestamp basierten) Daten vorliegen
 //		$sql = "SELECT upload_id as time, status FROM mb_monitor WHERE fkey_wms_id=$1 AND upload_id > ".$last_timestamp;
 
 		$sql = "SELECT upload_id as time, status FROM mb_monitor WHERE fkey_wms_id=$1";

Modified: trunk/mapbender/http/classes/class_stripRequest.php
===================================================================
--- trunk/mapbender/http/classes/class_stripRequest.php	2008-04-23 13:21:04 UTC (rev 2405)
+++ trunk/mapbender/http/classes/class_stripRequest.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -39,8 +39,8 @@
 			$tmp = explode("=", $patterns[$i]);
 			if(mb_strtoupper($tmp[0]) == mb_strtoupper($key)){
 				$replacement = mb_strtoupper($key) . "=" . $value;
-				$currentPattern = "/" . $patterns[$i] . "/";
-				$this->url = preg_replace($currentPattern, $replacement, $this->url);
+				$currentPattern = $patterns[$i];
+				$this->url = str_replace($currentPattern, $replacement, $this->url);
 				$exists = true;
 			}
 		}

Copied: trunk/mapbender/http/classes/class_user.php (from rev 2404, branches/2.5/http/classes/class_user.php)
===================================================================
--- trunk/mapbender/http/classes/class_user.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_user.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -0,0 +1,133 @@
+<?php
+# $Id: class_kml_geometry.php 1966 2008-01-15 08:25:15Z christoph $
+# http://www.mapbender.org/index.php/class_wmc.php
+# 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.
+
+require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+
+/**
+ * A Mapbender user as described in the table mb_user.
+ */
+class User {
+	/**
+	 * @var Integer The user ID
+	 */
+	var $id;
+	
+	/**
+	 * Constructor
+	 * @param $userId Integer 	the ID of the user that	is represented by 
+	 * 							this object.
+	 */
+	public function __construct ($userId) {
+		$this->id = $userId;
+	}	
+	
+	/**
+	 * Returns an array of application IDs that the user is allowed to access.
+	 * 
+	 * @return Array an array of application IDs
+	 * @param $ignorepublic boolean whether or not to ignore 
+	 * 								public applications (?)
+	 */
+	public function getApplicationsByPermission ($ignorepublic) {
+		$mb_user_id = $this->id;
+		$arrayGuis = array();
+		$mb_user_groups = array();
+		$sql_groups = "SELECT fkey_mb_group_id FROM mb_user_mb_group WHERE fkey_mb_user_id = $1 ";
+		$v = array($mb_user_id);
+		$t = array("i");
+		$res_groups = db_prep_query($sql_groups,$v,$t);
+		$cnt_groups = 0;
+		while($row = db_fetch_array($res_groups)){
+			$mb_user_groups[$cnt_groups] = $row["fkey_mb_group_id"];
+			$cnt_groups++;
+		}
+		if($cnt_groups > 0){
+			$v = array();
+			$t = array();
+			$sql_g = "SELECT gui.gui_id FROM gui JOIN gui_mb_group ";
+			$sql_g .= " ON gui.gui_id = gui_mb_group.fkey_gui_id WHERE gui_mb_group.fkey_mb_group_id IN (";
+			for($i=0; $i<count($mb_user_groups);$i++){
+				if($i > 0){$sql_g .= ",";}
+				$sql_g .= "$".strval($i+1);
+				array_push($v,$mb_user_groups[$i]);
+				array_push($t,"i");
+			}
+			$sql_g .= ") GROUP BY gui.gui_id";
+			$res_g = db_prep_query($sql_g,$v,$t);
+			while($row = db_fetch_array($res_g)){
+				array_push($arrayGuis,$row["gui_id"]);
+			}
+		}
+		$sql_guis = "SELECT gui.gui_id FROM gui JOIN gui_mb_user ON gui.gui_id = gui_mb_user.fkey_gui_id";
+		$sql_guis .= " WHERE (gui_mb_user.fkey_mb_user_id = $1) ";
+		if (!isset($ignore_public) OR $ignore_public== false){
+			$sql_guis .= " AND gui.gui_public = 1 ";
+		}
+		$sql_guis .= " GROUP BY gui.gui_id";
+		$v = array($mb_user_id);
+		$t = array("i");
+		$res_guis = db_prep_query($sql_guis,$v,$t);
+		$guis = array();
+		while($row = db_fetch_array($res_guis)){
+			if(!in_array($row['gui_id'],$arrayGuis)){
+				array_push($arrayGuis,$row["gui_id"]);
+			}
+		}
+		return $arrayGuis;
+	}	
+	
+	/** identifies the IDs of WFS confs where the user is owner
+	 * 
+	 * @param integer userid the user-ID of the current user
+	 * @return integer[] the IDs of the wfs_conf-table
+	 */
+	public function getWfsConfByPermission(){
+		$userid = $this->id;
+	 	$guisByPer = array();
+//	 	1.
+		$adm = new administration();
+	 	$guisByPer = $adm->getGuisByPermission($userid, true);
+//	 	2. 
+		$ownWFSconfs = array();
+		if(count($guisByPer)>0){
+			$v = array();
+			$t = array();
+			$sql = "SELECT wfs_conf.wfs_conf_id  FROM gui_wfs_conf, wfs_conf " .
+					"where wfs_conf.wfs_conf_id = gui_wfs_conf.fkey_wfs_conf_id " .
+					"and gui_wfs_conf.fkey_gui_id IN(";
+			for($i=0; $i<count($guisByPer); $i++){
+				if($i>0){ $sql .= ",";}
+				$sql .= "$".strval($i+1);
+				
+				array_push($v, $guisByPer[$i]);
+				array_push($t, "s");
+			}
+			$sql .= ") GROUP BY wfs_conf.wfs_conf_id ORDER BY wfs_conf.wfs_conf_id";
+			
+			$res = db_prep_query($sql,$v,$t);
+			$i=0;
+			while($row = db_fetch_array($res)){
+				$ownWFSconfs[$i] = $row['wfs_conf_id'];
+				$i++;
+			}
+		}
+		return $ownWFSconfs;
+	}
+}
+?>
\ No newline at end of file

Copied: trunk/mapbender/http/classes/class_weldMaps2Image.php (from rev 2404, branches/2.5/http/classes/class_weldMaps2Image.php)
===================================================================
--- trunk/mapbender/http/classes/class_weldMaps2Image.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_weldMaps2Image.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -0,0 +1,204 @@
+<?php
+# $Id$
+# http://www.mapbender.org/
+# 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.
+
+require_once(dirname(__FILE__)."/class_stripRequest.php");
+require_once(dirname(__FILE__)."/class_mb_exception.php");
+require_once(dirname(__FILE__)."/class_connector.php");
+include_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+ 
+ /*
+  * Class generats Images (jpegs/pngs/geotiff) 
+  * of Image-URL-Array
+  * For geotiff export gdal is necessary
+  * 
+  */
+ class weldMaps2Image{
+ 	
+	var $urls = array();
+	var $filename; 	
+ 	
+ 	function weldMaps2Image($urls, $array_file){
+ 		$this->urls = $urls;
+  		$this->array_file = $array_file;
+ 	}
+ 	
+ 	
+	function getImage($imageTyp_imp, $outputKind=''){
+		
+		$imageTyp="";
+		$imageTyp=$imageTyp_imp;
+		
+		if($imageTyp=='jpg'){
+			$imageTyp='jpeg';
+		}
+				
+		if(!$this->urls || $this->urls == ""){
+			$e = new mb_exception("weldMaps2Image: no maprequests delivered");
+		}
+		$obj1 = new stripRequest($this->urls[0]);
+		$width = $obj1->get("width");
+		$height = $obj1->get("height");
+		$wms_srs = $obj1->get("srs");
+		$wms_bbox = $obj1->get("bbox");
+		$wms_format = $obj1->getFormat();
+		
+		$image = imagecreatetruecolor($width, $height	);
+		$white = ImageColorAllocate($image,255,255,255); 
+		ImageFilledRectangle($image,0,0,$width,$height,$white); 
+	
+		for($i=0; $i<count($this->urls); $i++){
+			$obj = new stripRequest($this->urls[$i]);
+			if($imageTyp=='geotiff'){
+				$this->urls[$i] = $obj->setFormat($wms_format);
+			} else {
+				$this->urls[$i] = $obj->setFormat($imageTyp);	
+			}	
+			
+			$this->urls[$i] = $obj->encodeGET();			
+			$img = $this->loadImage($this->urls[$i]);				
+			if($img != false){
+				imagecopy($image, $img, 0, 0, 0, 0, $width, $height);
+			}
+			else{
+				$e = new mb_exception("weldMaps2Image: unable to load image: " . $this->urls[$i]);
+			}
+		}		
+		
+		$filename = $this->array_file['dir']."/";
+		$timestamp = time();			
+		$filenameOnly =$this->array_file['filename'].md5($timestamp);
+		
+		if($imageTyp=='png'){
+			
+			$filenameOnly .= '.png';
+			$filename .= $filenameOnly;
+
+			imagepng($image, $filename);
+			
+			$this->downloadLink($filenameOnly);
+			
+		} else if($imageTyp=='jpeg'){
+			
+			$filenameOnly .= '.jpeg';
+			$filename .= $filenameOnly;
+			imagejpeg($image, $filename);
+			
+			$this->downloadLink($filenameOnly);
+					
+		} else if($imageTyp=='geotiff'){
+			
+			$filenameOnly .= '.'.$wms_format;
+			$filename .= $filenameOnly;
+			
+			if ($wms_format=='png'){
+				imagepng($image, $filename);	
+			} else if ($wms_format=='jpeg'){
+				imagejpeg($image, $filename);	
+			} else {
+				$e = new mb_exception("weldMaps2Image: unable to generate temp-Image for getiff: " . $filename);
+			}
+			
+			// gdal_translate...
+			$wms_bbox = str_replace(',', ' ', $wms_bbox);
+			$filename_tif = str_replace($wms_format, 'tif', $filenameOnly);
+
+			$tmp_dir = $this->array_file['dir']."/";
+			
+			$array_bbox = explode(" ", $wms_bbox);	
+			$wms_bbox = $array_bbox[0]." ".$array_bbox[3]." ".$array_bbox[2]." ".$array_bbox[1];
+
+			$cmd = "gdal_translate -a_srs ".$wms_srs." -a_ullr ".$wms_bbox." ".$tmp_dir.$filenameOnly." ".$tmp_dir.$filename_tif;
+			exec($cmd);
+			
+			$this->downloadLink($filename_tif);
+					
+		}else {
+			
+		}
+		
+		
+	}
+	
+	function loadImage ($imgurl) {
+
+		$x = new connector($imgurl);		
+		$im = @imagecreatefromstring($x->file);
+		if(!$im){
+			$im = false;
+			$e = new mb_exception("weldMaps2Image: unable to load image: ".$imgurl);
+		}  
+		return $im;
+		
+	}
+ 	
+ 	function downloadLink($downloadFilename){
+ 		
+
+		$dwDir  = $this->array_file['dir']."/";
+		$dwFilename = $downloadFilename;
+		
+		
+		if(!(bool)$dwFilename) {
+			die("No filename given.");
+		}
+		
+		if((int)strpos($dwFilename,"..") !== 0) {
+			die("Illegal filename given.");
+		}
+		
+		$img = $dwDir."/".$dwFilename; 
+		
+		if(!file_exists($img) || !is_readable($img)) {
+			die("An error occured.");
+			
+		}
+		
+		$now_date = date("Ymd_His");
+		
+		switch(substr($dwFilename,-4)) {
+			case ".png":
+				$filename = "map_export__".$now_date.".png";
+				header('Content-Type: image/png');
+				break;
+			case "jpeg":
+				$filename = "map_export__".$now_date.".jpeg";
+				header('Content-Type: image/jpeg');
+				break;
+			case ".tif";
+				$filename = "map_export__".$now_date.".tif";
+				header('Content-Type: image/tif');
+				break;
+			default:
+				die("An error occured.");
+		}
+
+ 		if(file_exists($img) && is_file($img)) {
+				header("Content-Disposition: attachment; filename=\"".$filename."\"");
+
+				readfile($img); 
+		} else {
+			    die('Error: The file '.$img.' does not exist!');
+			}
+
+ 	}
+ 	
+ }
+ 
+
+?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_wfs.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs.php	2008-04-23 13:21:04 UTC (rev 2405)
+++ trunk/mapbender/http/classes/class_wfs.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -22,9 +22,9 @@
 */
 
 include_once(dirname(__FILE__)."/../../conf/mapbender.conf");
-require_once(dirname(__FILE__)."/class_connector.php");
+require_once(dirname(__FILE__)."/class_connector.php");
 require_once(dirname(__FILE__)."/class_mb_exception.php");
-require_once(dirname(__FILE__)."/class_administration.php");
+require_once(dirname(__FILE__)."/class_administration.php");
 
 class wfs {
 
@@ -65,7 +65,7 @@
 	$values = null;
 	$tags = null;
 	$admin = new administration();
-	$this->wfs_getcapabilities_doc = $admin->char_encode($data);
+	$this->wfs_getcapabilities_doc = $admin->char_encode($data);
 	$this->wfs_upload_url = $url;
 	
 	# for temporary wfs a id has to be created...
@@ -76,7 +76,7 @@
 	xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
 	xml_parse_into_struct($parser,$this->wfs_getcapabilities_doc,$values,$tags);
 	//xml_parse_into_struct($parser,$data,$values,$tags);
-	
+	
 	xml_parser_free($parser);
 	
 	$section = false;
@@ -196,7 +196,7 @@
 } 
 function addFeaturetype($name,$title,$abstract,$srs,$url,$version){
 	$this->wfs_featuretype[count($this->wfs_featuretype)] = new featuretype($name,$title,$abstract,$srs,$url,$version);
-}
+}
  function stripEndlineAndCarriageReturn($string) {
 	  	return preg_replace("/\n/", "", preg_replace("/\r/", " ", $string));
 	  }
@@ -321,8 +321,10 @@
 	// if it might exist, update it
 	if ($wfs_exists) {
 		// but check first if it really exists in the database
-		$sql = "SELECT * FROM wfs WHERE wfs_id = ".$this->wfs_id.";";
-		$res = db_query($sql);	
+		$sql = "SELECT * FROM wfs WHERE wfs_id = $1;";
+		$v = array($this->wfs_id);
+		$t = array("i");
+		$res = db_prep_query($sql, $v, $t);	
 		if($res){
 			$this->updateWfs();
 		}
@@ -337,8 +339,10 @@
 	}
 
 	# delete featuretypes from DB that does not exist and find the ids
-	$sql = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = ".$this->wfs_id.";";
-	$res_ft = db_query($sql);
+	$sql = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = $1;";
+	$v = array($this->wfs_id);
+	$t = array("i");
+	$res_ft = db_prep_query($sql, $v, $t);
 	$cnt = 0;
 	while(db_fetch_row($res_ft)){
 		$found = false;
@@ -391,9 +395,10 @@
 		}
 		
 		//delete featuretype elements from db and find the ids
-		$sql = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = ".$this->wfs_featuretype[$i]->featuretype_id.";";
-		//echo $sql."<br />";
-		$res_el = db_query($sql);
+		$sql = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = $1;";
+		$v = array($this->wfs_featuretype[$i]->featuretype_id);
+		$t = array("i");
+		$res_el = db_prep_query($sql, $v, $t);
 		$cnt = 0;
 		while(db_fetch_row($res_el)){
 			$found = false;
@@ -420,57 +425,881 @@
 		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
 			if(!$this->wfs_featuretype[$i]->featuretype_element[$j]["id"]){
 				$sql = "INSERT INTO wfs_element(fkey_featuretype_id, element_name,element_type) ";
-				$sql .= "VALUES("; 
-				$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_id. "', ";
-				$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_element[$j]["name"]. "', ";
-				$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]. "' ";
-				$sql .= ");";
-				//echo $sql."<br />";
-				$res = db_query($sql);
+				$sql .= "VALUES($1, $2, $3);";
+				
+				$v = array($this->wfs_featuretype[$i]->featuretype_id, $this->wfs_featuretype[$i]->featuretype_element[$j]["name"], $this->wfs_featuretype[$i]->featuretype_element[$j]["type"]);
+				$t = array("s", "s", "s");
+				$res = db_prep_query($sql, $v, $t);
 				if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
 			}
 			else{
-				$sql = "UPDATE wfs_element SET element_type = '".$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]."' ";
-				$sql .= "WHERE element_id = ".$this->wfs_featuretype[$i]->featuretype_element[$j]["id"]." AND ";
-				$sql .= "fkey_featuretype_id = ".$this->wfs_featuretype[$i]->featuretype_id.";";
-				//echo $sql."<br />";
-				$res = db_query($sql);
-				if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+				$sql = "UPDATE wfs_element SET element_type = $1 ";
+				$sql .= "WHERE element_id = $2 AND ";
+				$sql .= "fkey_featuretype_id = $3;";
+				$v = array($this->wfs_featuretype[$i]->featuretype_element[$j]["type"], $this->wfs_featuretype[$i]->featuretype_element[$j]["id"], $this->wfs_featuretype[$i]->featuretype_id);
+				$t = array("s", "i", "i");
+				$res = db_prep_query($sql, $v, $t);
+				if (!$res) {
+					db_rollback();
+					$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+					return;
+				}
 			}
 		}
 
 		$sql = "DELETE FROM wfs_featuretype_namespace WHERE ";
-		$sql .= "fkey_wfs_id = ".$this->wfs_id." AND ";
-		$sql .= "fkey_featuretype_id = ".$this->wfs_featuretype[$i]->featuretype_id.";";
-		//echo $sql."<br />";
-		$res = db_query($sql);
-		if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+		$sql .= "fkey_wfs_id = $1 AND fkey_featuretype_id = $2";
+		$v = array($this->wfs_id, $this->wfs_featuretype[$i]->featuretype_id);
+		$t = array("i", "i");
+		$res = db_prep_query($sql, $v, $t);
+		if (!$res) {
+			db_rollback();
+			$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+			return;
+		}
 				
 		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 .= "'" .$this->wfs_id. "',";
-			$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_id. "', ";
-			$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"]. "', ";
-			$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]. "' ";
-			$sql .= ");";
+			$sql = "INSERT INTO wfs_featuretype_namespace ";
+			$sql .= "(fkey_wfs_id, fkey_featuretype_id, namespace, namespace_location) ";
+			$sql .= "VALUES ($1, $2, $3, $4);"; 
+
+			$v = array($this->wfs_id, $this->wfs_featuretype[$i]->featuretype_id, $this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"], $this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]);
+			$t = array("s", "s", "s", "s");
+			$res = db_prep_query($sql, $v, $t);
+
+			if (!$res) {
+				db_rollback();
+				$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+				return;
+			}
+		}
+	}
+	
+	# TABLE gui_wfs
+	
+	if($gui_id){
+		$sql ="INSERT INTO gui_wfs (fkey_gui_id, fkey_wfs_id)";
+		$sql .= "VALUES($1, $2);";
+		$v = array($gui_id, $this->wfs_id);
+		$t = array("s", "i");
+		$res = db_prep_query($sql, $v, $t);
+
+		if (!$res) {
+			db_rollback();
+			$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+			return;
+		}
+	}
+	
+	//echo "Successfully saved!<br />";
+	db_commit();
+	
+	return true;
+}
+/**
+* updateObjFromXML
+*
+* this function regets the information from the xml (update)
+* @return boolean true if successful, false otherwise
+*/
+function updateObjFromXML($url){
+	$x = new connector($url);
+	$data = $x->file;
+	#$data = implode("",file($url));
+	if(!$data){
+		$e = new mb_exception("Unable to open document: ".$url);
+		return false; 
+	}
+	
+	$values = null;
+	$tags = null;
+	$admin = new administration();
+	$this->wfs_getcapabilities_doc = $admin->char_encode($data);
+	$this->wfs_featuretype = array();
+	$this->wfs_upload_url = $url;
+	
+	# for temporary wfs 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,$this->wfs_getcapabilities_doc,$values,$tags);
+	//xml_parse_into_struct($parser,$data,$values,$tags);
+	
+	xml_parser_free($parser);
+	
+	$section = false;
+	$request = false;
+	$featuretype_name = false;
+ 	$featuretype_title = false;
+ 	$featuretype_abstract = 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 = $this->stripEndlineAndCarriageReturn($element[value]);
+		}
+		if(strtoupper($element[tag]) == "ABSTRACT" && $element[level] == '3'){
+			$this->wfs_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
+		}
+		//new WFS 1.0.0 -- SB 2007-08-06
+		if(strtolower($element[tag]) == "fees"){
+			$this->fees = $element[value];
+		}
+		if(strtolower($element[tag]) == "accessconstraints"){
+			$this->accessconstraints = $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 = $this->stripEndlineAndCarriageReturn($element[value]);
+		}
+		if($section == "featuretype" && strtoupper($element[tag]) == "ABSTRACT"){
+			$featuretype_abstract = $this->$element[value];
+		}
+		if($section == "featuretype" && strtoupper($element[tag]) == "SRS"){
+			$featuretype_srs = $element[value];
+			$this->addFeaturetype($featuretype_name,$featuretype_title,$featuretype_abstract,$featuretype_srs,$this->wfs_describefeaturetype,$this->wfs_version);
+		}
+	}
+	return true;
+}
+
+/**
+* creatObjfromDB
+*
+* this function fills the object with wfs information from db
+* 
+* @param int the id of wfs to get the information from
+*/ 
+function createObjFromDB($wfs_id){
+	global $DBSERVER,$DB,$OWNER,$PW;
+	$con = db_connect($DBSERVER,$OWNER,$PW);
+	db_select_db($DB,$con);
+
+	$sql = "SELECT * FROM wfs WHERE wfs_id = $1;";
+	$v = array($wfs_id);
+	$t = array("i");
+	$res = db_prep_query($sql, $v, $t);
+	$cnt = 0;
+	while(db_fetch_row($res)){
+		$this->wfs_id = db_result($res, $cnt, "wfs_id");
+		$this->wfs_version = db_result($res, $cnt, "wfs_version");
+		$this->wfs_name = db_result($res, $cnt, "wfs_name");
+		$this->wfs_title = db_result($res, $cnt, "wfs_title");
+		$this->wfs_abstract = db_result($res, $cnt, "wfs_abstract");
+		$this->wfs_getcapabilities = db_result($res, $cnt, "wfs_getcapabilities");
+		$this->wfs_getcapabilities_doc = db_result($res, $cnt, "wfs_getcapabilities_doc");
+		$this->wfs_upload_url = db_result($res, $cnt, "wfs_upload_url");
+		$this->wfs_describefeaturetype = db_result($res, $cnt, "wfs_describefeaturetype");
+		$this->wfs_getfeature = db_result($res, $cnt, "wfs_getfeature");
+		$this->wfs_transaction = db_result($res, $cnt, "wfs_transaction");
+		$this->fees = db_result($res, $cnt, "fees");
+		$this->accessconstraints = db_result($res, $cnt, "accessconstraints");
+		$this->wfs_owner = db_result($res, $cnt, "wfs_owner");
+		$this->wfs_timestamp = db_result($res, $cnt, "wfs_timestamp");
+		
+		$sql_fe = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = $1 ORDER BY featuretype_id";
+		$v = array($this->wfs_id);
+		$t = array("i");
+		$res_fe = db_prep_query($sql_fe, $v, $t);
+		$cnt_fe = 0;
+		while(db_fetch_row($res_fe)){
+			$c = count($this->wfs_featuretype);
+//			$this->wfs_featuretype[$c]->featuretype_id = db_result($res_fe, $cnt_fe, "featuretype_id");
+			$this->wfs_featuretype[$c]->featuretype_name = db_result($res_fe, $cnt_fe, "featuretype_name");
+			$this->wfs_featuretype[$c]->featuretype_title = db_result($res_fe, $cnt_fe, "featuretype_title");
+			$this->wfs_featuretype[$c]->featuretype_abstract = db_result($res_fe, $cnt_fe, "featuretype_abstract");
+			$this->wfs_featuretype[$c]->featuretype_srs = db_result($res_fe, $cnt_fe, "featuretype_srs");
+			
+			$sql_el = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = $1 ORDER BY element_id";
+			$v = array(db_result($res_fe, $cnt_fe, "featuretype_id"));
+			$t = array("i");
+			$res_el = db_prep_query($sql_el, $v, $t);
+			$cnt_el = 0;
+			while(db_fetch_row($res_el)){
+				$z = count($this->wfs_featuretype[$c]->featuretype_element);
+				$this->wfs_featuretype[$c]->featuretype_element[$z]["name"] = db_result($res_el, $cnt_el, "element_name");
+				$this->wfs_featuretype[$c]->featuretype_element[$z]["type"] = db_result($res_el, $cnt_el, "element_type");
+				$cnt_el++;
+			}
+			$sql_ns = "SELECT * FROM wfs_featuretype_namespace WHERE fkey_featuretype_id = $1 ORDER BY namespace";
+			$v = array(db_result($res_fe, $cnt_fe, "featuretype_id"));
+			$t = array("i");
+			$res_ns = db_prep_query($sql_ns, $v, $t);
+			$cnt_ns = 0;
+			while(db_fetch_row($res_ns)){
+				$z = count($this->wfs_featuretype[$c]->featuretype_namespace);
+				$this->wfs_featuretype[$c]->featuretype_namespace[$z]["name"] = db_result($res_ns, $cnt_ns, "namespace");
+				$this->wfs_featuretype[$c]->featuretype_namespace[$z]["value"] = db_result($res_ns, $cnt_ns, "namespace_location");
+				$cnt_ns++;
+			}
+			$cnt_fe++;
+		}
+		$cnt++;
+    }
+}
+/** end createObjfromDB **/
+
+	public function getallwfs($userid){
+		$this->wfs_id = array();
+		$this->wfs_name = array();
+		$this->wfs_title = array();
+		$this->wfs_abstract = array();
+		
+		global $DBSERVER,$DB,$OWNER,$PW;
+		$con = db_connect($DBSERVER,$OWNER,$PW);
+		db_select_db($DB,$con);
+		if($userid){
+		 	$sql = "SELECT * FROM wfs WHERE wfs_owner = $1";
+			$v = array($userid);
+			$t = array('i');
+			$res = db_prep_query($sql,$v,$t);
+		}
+		else{
+		 	$sql = "SELECT * FROM wfs";
+			$res = db_query($sql);
+		}
+		
+		$cnt = 0;
+		while ($row = db_fetch_array($res)){
+			$this->wfs_version[$cnt] = $row["wfs_version"];
+			$this->wfs_id[$cnt] = $row["wfs_id"];
+			$this->wfs_name[$cnt] = $row["wfs_name"];
+			$this->wfs_title[$cnt] = $row["wfs_title"];
+			$this->wfs_abstract[$cnt] = $row["wfs_abstract"];
+			$this->wfs_getcapabilities[$cnt] = $row["wfs_getcapabilities"];
+			$this->wfs_describefeaturetype[$cnt] = $row["wfs_describefeaturetype"];
+			$this->wfs_getfeature[$cnt] = $row["wfs_getfeature"];
+			$cnt++;
+		}	
+	}
+}
+
+
+class featuretype extends wfs{
+	var $featuretype_element = array();	
+	var $featuretype_namespace = array();	
+	
+	function featuretype($name,$title,$abstract,$srs,$url,$version){
+
+		$url .= "&SERVICE=WFS&VERSION=".$version."&REQUEST=DescribeFeatureType&TYPENAME=".$name;
+		
+		$this->featuretype_name = $name;
+		$this->featuretype_title = $title;
+		$this->featuretype_abstract = $abstract;
+		$this->featuretype_srs = $srs;
+		
+		$y = new connector($url);
+		$data = $y->file;
+				
+		#$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>";
+			}
+			
+			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]) == "complexType" && $element[type] == "open"){
+				$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$
+# http://www.mapbender.org/index.php/class_wfs.php
+# 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(dirname(__FILE__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/class_connector.php");
+require_once(dirname(__FILE__)."/class_mb_exception.php");
+require_once(dirname(__FILE__)."/class_administration.php");
+
+class wfs {
+
+  var $wfs_id;
+  var $wfs_version;
+  var $wfs_name;
+  var $wfs_title;
+  var $wfs_abstract;
+  var $wfs_getcapabilities;
+  var $wfs_getcapabilities_doc; //new SB 2007-08-09
+  var $wfs_describefeaturetype;
+  var $wfs_describefeaturetype_namespace = array();
+  var $wfs_getfeature;
+  var $wfs_transaction;
+  var $wfs_upload_url; //new SB 2007-08-09
+
+  //new WFS 1.0.0 -- SB 2007-08-06
+
+  var $fees;
+  var $accessconstraints;
+  
+  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; 
+	}
+	
+	$values = null;
+	$tags = null;
+	$admin = new administration();
+	$this->wfs_getcapabilities_doc = $admin->char_encode($data);
+	$this->wfs_upload_url = $url;
+	
+	# for temporary wfs 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,$this->wfs_getcapabilities_doc,$values,$tags);
+	//xml_parse_into_struct($parser,$data,$values,$tags);
+	
+	xml_parser_free($parser);
+	
+	$section = false;
+	$request = false;
+	$featuretype_name = false;
+ 	$featuretype_title = false;
+ 	$featuretype_abstract = 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 = $this->stripEndlineAndCarriageReturn($element[value]);
+		}
+		if(strtoupper($element[tag]) == "ABSTRACT" && $element[level] == '3'){
+			$this->wfs_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
+		}
+		//new WFS 1.0.0 -- SB 2007-08-06
+		if(strtolower($element[tag]) == "fees"){
+			$this->fees = $element[value];
+		}
+		if(strtolower($element[tag]) == "accessconstraints"){
+			$this->accessconstraints = $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 = $this->stripEndlineAndCarriageReturn($element[value]);
+		}
+		if($section == "featuretype" && strtoupper($element[tag]) == "ABSTRACT"){
+			$featuretype_abstract = $this->$element[value];
+		}
+		if($section == "featuretype" && strtoupper($element[tag]) == "SRS"){
+			$featuretype_srs = $element[value];
+			$this->addFeaturetype($featuretype_name,$featuretype_title,$featuretype_abstract,$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 "abstract: ". $this->wfs_featuretype[$i]->featuretype_abstract . "<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,$abstract,$srs,$url,$version){
+	$this->wfs_featuretype[count($this->wfs_featuretype)] = new featuretype($name,$title,$abstract,$srs,$url,$version);
+}
+ function stripEndlineAndCarriageReturn($string) {
+	  	return preg_replace("/\n/", "", preg_replace("/\r/", " ", $string));
+	  }
+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_abstract . "','".  
+			$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.");");
+		}
+	}
+}
+
+/**
+ * Inserts this WFS in the database
+ */
+function insertWfs() {
+	global $DBSERVER,$DB,$OWNER,$PW;
+	$con = db_connect($DBSERVER,$OWNER,$PW);
+	db_select_db($DB,$con);
+
+	$sql = "INSERT INTO wfs (wfs_version, wfs_name, wfs_title, wfs_abstract, ";
+	$sql .= "wfs_getcapabilities, wfs_getcapabilities_doc, wfs_upload_url, ";
+	$sql .= "wfs_describefeaturetype, wfs_getfeature, wfs_transaction, fees, ";
+	$sql .= "accessconstraints, wfs_owner, wfs_timestamp) ";
+	$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)";
+
+	$v = array($this->wfs_version, $this->wfs_name, $this->wfs_title, 
+		$this->wfs_abstract, $this->wfs_getcapabilities, $this->wfs_getcapabilities_doc,
+		$this->wfs_upload_url, $this->wfs_describefeaturetype, $this->wfs_getfeature,
+		$this->wfs_transaction, $this->fees, $this->accessconstraints, 
+		$_SESSION["mb_user_id"], strtotime("now"));
+		
+	$t = array('s', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 'i', 'i');
+
+	$res = db_prep_query($sql,$v,$t);
+
+	if(!$res){
+		db_rollback();
+		$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+		return false;
+	}
+	$this->wfs_id = db_insert_id($con,'wfs','wfs_id');
+	return true;
+}
+
+function updateWfs() {
+	global $DBSERVER,$DB,$OWNER,$PW;
+	$con = db_connect($DBSERVER,$OWNER,$PW);
+	db_select_db($DB,$con);
+
+	$sql = "UPDATE wfs SET wfs_version = $1, wfs_name = $2, wfs_title = $3, ";
+	$sql .= "wfs_abstract = $4, wfs_getcapabilities = $5, wfs_getcapabilities_doc = $6, ";
+	$sql .= "wfs_upload_url = $7, wfs_describefeaturetype = $8, wfs_getfeature = $9, ";
+	$sql .= "wfs_transaction = $10, fees = $11, accessconstraints = $12, wfs_owner = $13, ";
+	$sql .= "wfs_timestamp = $14 ";
+	$sql .= "WHERE wfs_id = $15";
+	//echo $sql."<br />";
+	$v = array($this->wfs_version, $this->wfs_name, $this->wfs_title, $this->wfs_abstract,
+		$this->wfs_getcapabilities, $this->wfs_getcapabilities_doc, $this->wfs_upload_url,
+		$this->wfs_describefeaturetype, $this->wfs_getfeature, $this->wfs_transaction,
+		$this->fees, $this->accessconstraints, $_SESSION["mb_user_id"],strtotime("now"), 
+		$this->wfs_id);
+		
+	$t = array('s', 's', 's', 's', 's', 's', 's', 's' ,'s' ,'s' ,'s' ,'s' ,'i' ,'i' ,'i');
+	$res = db_prep_query($sql,$v,$t);
+	if(!$res){
+		db_rollback();
+		$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+		return false;
+	}
+	return true;
+}
+/**
+* wfs2db
+*
+* this function saves the class information to the mapbender database 
+* @return boolean true if sucessful false otherwise
+*/
+function wfs2db($gui_id){
+	global $DBSERVER,$DB,$OWNER,$PW;
+	$con = db_connect($DBSERVER,$OWNER,$PW);
+	db_select_db($DB,$con);
+	
+	db_begin();
+	
+	// check if WFS already might exists (it might exist when wfs_id is numeric)
+	$wfs_exists = is_numeric($this->wfs_id);
+
+	// if it might exist, update it
+	if ($wfs_exists) {
+		// but check first if it really exists in the database
+		$sql = "SELECT * FROM wfs WHERE wfs_id = $1;";
+		$v = array($this->wfs_id);
+		$t = array("i");
+		$res = db_prep_query($sql, $v, $t);	
+		if($res){
+			$this->updateWfs();
+		}
+		// if not, insert as new WFS
+		else {
+			$this->insertWfs();
+		}
+	}
+	// if it does not exist, insert as new WFS
+	else {
+		$this->insertWfs();
+	}
+
+	# delete featuretypes from DB that does not exist and find the ids
+	$sql = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = $1;";
+	$v = array($this->wfs_id);
+	$t = array("i");
+	$res_ft = db_prep_query($sql, $v, $t);
+	$cnt = 0;
+	while(db_fetch_row($res_ft)){
+		$found = false;
+		for($i=0; $i<count($this->wfs_featuretype); $i++){
+			if($this->wfs_featuretype[$i]->featuretype_name == db_result($res_ft, $cnt, "featuretype_name")){
+				$this->wfs_featuretype[$i]->featuretype_id = db_result($res_ft, $cnt, "featuretype_id");
+				$found = true;
+				break;
+			}
+		}
+		
+		if(!$found){
+			$sql = "DELETE FROM wfs_featuretype WHERE featuretype_id = $1 AND fkey_wfs_id = $2";
+			$v = array(db_result($res_ft, $cnt, "featuretype_id"), $this->wfs_id);
+			$t = array('i','i');
 			//echo $sql."<br />";
-			$res = db_query($sql);
+			$res = db_prep_query($sql,$v,$t);
 			if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
 		}
+		$cnt++;
 	}
 	
+	
+	# TABLE wfs_featuretype
+	
+	for($i=0; $i<count($this->wfs_featuretype); $i++){
+		if(!$this->wfs_featuretype[$i]->featuretype_id){
+			$sql = "INSERT INTO wfs_featuretype(fkey_wfs_id, featuretype_name, featuretype_title, featuretype_abstract, featuretype_srs) ";
+			$sql .= "VALUES($1,$2,$3,$4,$5)";
+			$v = array($this->wfs_id,$this->wfs_featuretype[$i]->featuretype_name,$this->wfs_featuretype[$i]->featuretype_title,$this->wfs_featuretype[$i]->featuretype_abstract,$this->wfs_featuretype[$i]->featuretype_srs);
+			$t = array('i','s','s','s','s');
+			//echo $sql."<br />";
+			$res = db_prep_query($sql,$v,$t);
+			if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+			
+			# save the id of each featuretype: 
+			$this->wfs_featuretype[$i]->featuretype_id = db_insert_id($con,'wfs_featuretype','featuretype_id');
+		}
+		else{
+			$sql = "UPDATE wfs_featuretype SET ";
+			$sql .= "featuretype_title = $1,";
+			$sql .= "featuretype_abstract = $2,";
+			$sql .= "featuretype_srs = $3 ";
+			$sql .= "WHERE featuretype_id = $4";
+			$v = array($this->wfs_featuretype[$i]->featuretype_title,$this->wfs_featuretype[$i]->featuretype_abstract,$this->wfs_featuretype[$i]->featuretype_srs,$this->wfs_featuretype[$i]->featuretype_id);
+			$t = array('s','s','s','i');
+			//echo $sql."<br />";
+			$res = db_prep_query($sql,$v,$t);
+			if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+		}
+		
+		//delete featuretype elements from db and find the ids
+		$sql = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = $1;";
+		$v = array($this->wfs_featuretype[$i]->featuretype_id);
+		$t = array("i");
+		$res_el = db_prep_query($sql, $v, $t);
+		$cnt = 0;
+		while(db_fetch_row($res_el)){
+			$found = false;
+			for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element); $j++){
+				if($this->wfs_featuretype[$i]->featuretype_element[$j]["name"] == db_result($res_el, $cnt, "element_name")){
+					$this->wfs_featuretype[$i]->featuretype_element[$j]["id"] = db_result($res_el, $cnt, "element_id");
+					$found = true;
+					break;
+				}
+			}
+			
+			if(!$found){
+				$sql = "DELETE FROM wfs_element WHERE element_id = $1 AND fkey_featuretype_id = $2";
+				$v = array(db_result($res_el, $cnt, "element_id"), $this->wfs_featuretype[$i]->featuretype_id);
+				$t = array('i','i');
+				//echo $sql."<br />";
+				$res = db_prep_query($sql,$v,$t);
+				if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+			}
+			$cnt++;
+		}
+
+
+		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
+			if(!$this->wfs_featuretype[$i]->featuretype_element[$j]["id"]){
+				$sql = "INSERT INTO wfs_element(fkey_featuretype_id, element_name,element_type) ";
+				$sql .= "VALUES($1, $2, $3);";
+				
+				$v = array($this->wfs_featuretype[$i]->featuretype_id, $this->wfs_featuretype[$i]->featuretype_element[$j]["name"], $this->wfs_featuretype[$i]->featuretype_element[$j]["type"]);
+				$t = array("s", "s", "s");
+				$res = db_prep_query($sql, $v, $t);
+				if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+			}
+			else{
+				$sql = "UPDATE wfs_element SET element_type = $1 ";
+				$sql .= "WHERE element_id = $2 AND ";
+				$sql .= "fkey_featuretype_id = $3;";
+				$v = array($this->wfs_featuretype[$i]->featuretype_element[$j]["type"], $this->wfs_featuretype[$i]->featuretype_element[$j]["id"], $this->wfs_featuretype[$i]->featuretype_id);
+				$t = array("s", "i", "i");
+				$res = db_prep_query($sql, $v, $t);
+				if (!$res) {
+					db_rollback();
+					$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+					return;
+				}
+			}
+		}
+
+		$sql = "DELETE FROM wfs_featuretype_namespace WHERE ";
+		$sql .= "fkey_wfs_id = $1 AND fkey_featuretype_id = $2";
+		$v = array($this->wfs_id, $this->wfs_featuretype[$i]->featuretype_id);
+		$t = array("i", "i");
+		$res = db_prep_query($sql, $v, $t);
+		if (!$res) {
+			db_rollback();
+			$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+			return;
+		}
+				
+		for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_namespace);$j++){
+			$sql = "INSERT INTO wfs_featuretype_namespace ";
+			$sql .= "(fkey_wfs_id, fkey_featuretype_id, namespace, namespace_location) ";
+			$sql .= "VALUES ($1, $2, $3, $4);"; 
+
+			$v = array($this->wfs_id, $this->wfs_featuretype[$i]->featuretype_id, $this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"], $this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]);
+			$t = array("s", "s", "s", "s");
+			$res = db_prep_query($sql, $v, $t);
+
+			if (!$res) {
+				db_rollback();
+				$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+				return;
+			}
+		}
+	}
+	
 	# TABLE gui_wfs
 	
 	if($gui_id){
 		$sql ="INSERT INTO gui_wfs (fkey_gui_id, fkey_wfs_id)";
-		$sql .= "VALUES(";
-			$sql .= "'" . $gui_id . "', ";
-			$sql .= $this->wfs_id;
-		$sql .= ");";
-		//echo $sql."<br />";
-		$res = db_query($sql);
-		if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+		$sql .= "VALUES($1, $2);";
+		$v = array($gui_id, $this->wfs_id);
+		$t = array("s", "i");
+		$res = db_prep_query($sql, $v, $t);
+
+		if (!$res) {
+			db_rollback();
+			$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+			return;
+		}
 	}
 	
 	//echo "Successfully saved!<br />";
@@ -616,8 +1445,10 @@
 	$con = db_connect($DBSERVER,$OWNER,$PW);
 	db_select_db($DB,$con);
 
-	$sql = "SELECT * FROM wfs WHERE wfs_id = ".$wfs_id.";";
-	$res = db_query($sql);
+	$sql = "SELECT * FROM wfs WHERE wfs_id = $1;";
+	$v = array($wfs_id);
+	$t = array("i");
+	$res = db_prep_query($sql, $v, $t);
 	$cnt = 0;
 	while(db_fetch_row($res)){
 		$this->wfs_id = db_result($res, $cnt, "wfs_id");
@@ -636,8 +1467,10 @@
 		$this->wfs_owner = db_result($res, $cnt, "wfs_owner");
 		$this->wfs_timestamp = db_result($res, $cnt, "wfs_timestamp");
 		
-		$sql_fe = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = '" . $this->wfs_id . "' ORDER BY featuretype_id";
-		$res_fe = db_query($sql_fe);
+		$sql_fe = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = $1 ORDER BY featuretype_id";
+		$v = array($this->wfs_id);
+		$t = array("i");
+		$res_fe = db_prep_query($sql_fe, $v, $t);
 		$cnt_fe = 0;
 		while(db_fetch_row($res_fe)){
 			$c = count($this->wfs_featuretype);
@@ -647,8 +1480,10 @@
 			$this->wfs_featuretype[$c]->featuretype_abstract = db_result($res_fe, $cnt_fe, "featuretype_abstract");
 			$this->wfs_featuretype[$c]->featuretype_srs = db_result($res_fe, $cnt_fe, "featuretype_srs");
 			
-			$sql_el = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = ". db_result($res_fe, $cnt_fe, "featuretype_id")." ORDER BY element_id";
-			$res_el = db_query($sql_el);
+			$sql_el = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = $1 ORDER BY element_id";
+			$v = array(db_result($res_fe, $cnt_fe, "featuretype_id"));
+			$t = array("i");
+			$res_el = db_prep_query($sql_el, $v, $t);
 			$cnt_el = 0;
 			while(db_fetch_row($res_el)){
 				$z = count($this->wfs_featuretype[$c]->featuretype_element);
@@ -656,8 +1491,10 @@
 				$this->wfs_featuretype[$c]->featuretype_element[$z]["type"] = db_result($res_el, $cnt_el, "element_type");
 				$cnt_el++;
 			}
-			$sql_ns = "SELECT * FROM wfs_featuretype_namespace WHERE fkey_featuretype_id = ". db_result($res_fe, $cnt_fe, "featuretype_id")." ORDER BY namespace";
-			$res_ns = db_query($sql_ns);
+			$sql_ns = "SELECT * FROM wfs_featuretype_namespace WHERE fkey_featuretype_id = $1 ORDER BY namespace";
+			$v = array(db_result($res_fe, $cnt_fe, "featuretype_id"));
+			$t = array("i");
+			$res_ns = db_prep_query($sql_ns, $v, $t);
 			$cnt_ns = 0;
 			while(db_fetch_row($res_ns)){
 				$z = count($this->wfs_featuretype[$c]->featuretype_namespace);
@@ -724,7 +1561,7 @@
 		$y = new connector($url);
 		$data = $y->file;
 				
-		//$data = implode("",file($url));		
+		#$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);

Modified: trunk/mapbender/http/classes/class_wfs_conf.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_conf.php	2008-04-23 13:21:04 UTC (rev 2405)
+++ trunk/mapbender/http/classes/class_wfs_conf.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -18,8 +18,9 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 require_once(dirname(__FILE__)."/class_mb_exception.php");
+require_once(dirname(__FILE__)."/class_user.php");
 require_once(dirname(__FILE__)."/class_administration.php");
-require_once(dirname(__FILE__)."/../extensions/JSON.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
 
 class WfsConf {
 	var $confArray = array();
@@ -31,185 +32,204 @@
 
 	}
 	
+	function __toString () {
+		$json = new Mapbender_JSON();
+		return $json->encode($this->confArray);
+	}
+	
+	/**
+	 * Loads WFS conf data from the database
+	 * 
+	 * @return Object WFS conf data.
+	 * @param $idOrIdArray Object May be an integer or an array of integers representing WFS conf IDs.
+	 */
 	public function load ($idOrIdArray) {
-		/*
-		 * Check parameter and set idArray
-		 */
+		// Check parameter and set idArray
 		if (isset($idOrIdArray)){
 			
 			// parameter is a number	
 			if (!is_array($idOrIdArray) && is_numeric($idOrIdArray)) {
-				$this->getWfsConfFromDB(array(intval($idOrIdArray)), $_SESSION["mb_user_id"]);
+				$idArray = array(intval($idOrIdArray));
 			}
+
 			// parameter is an array of numbers
-			else if (is_array($idOrIdArray)) {
+			if (is_array($idOrIdArray)) {
 				$idArray = array();
 				for ($i=0; $i < count($idOrIdArray); $i++) {
 					if (!is_numeric($idOrIdArray[$i])) {
 						$e = new mb_exception("Wfs_conf: constructor: wrong parameter: ".$idOrIdArray[$i]." is not a number.");
-						return null;
+						return array();
 					}
 					array_push($idArray, intval($idOrIdArray[$i]));
 				}
-				$this->getWfsConfFromDB($idArray, $_SESSION["mb_user_id"]);
+
+				// If a user ID is given, remove the ones the user has no access to
+				if ($_SESSION["mb_user_id"]) {
+					$user = new User($_SESSION["mb_user_id"]);
+					$idArray = array_intersect($idArray, $user->getWfsConfByPermission());
+				}
+
+				return $this->getWfsConfFromDB($idArray);
 			}
 			// parameter is invalid
 			else {
 				$e = new mb_exception("Wfs_conf: constructor: parameter must be number or an array of numbers.");
-				return null;
+				return array();
 			}
 		}
 		else {
 			$e = new mb_exception("Wfs_conf: constructor: parameter is not valid");
+			return null;
 		}
 	}
 	
+
+	// --------------------------- private -----------------------------------
+
 	/**
-	 * get WFS conf data from database
+	 * Gets the database content for a number of WFS configurations given by their IDs.
+	 * 
+	 * @return Array
+	 * @param $idArray Array an array of integer values representing WFS conf IDs.
 	 */
-	private function getWfsConfFromDB ($idArray, $userId) {
-		/*
-		 * If a user ID is given, remove the ones the user has no access to
-		 */
-		if ($userId) {
-			$idArray = array_intersect($idArray, WfsConf::getWfsConfByPermission($userId));
+	private static function getWfsConfFromDbByArray ($idArray) {
+		$sql = "SELECT * FROM wfs_conf ";
+		$sql .= "JOIN wfs ON wfs_conf.fkey_wfs_id = wfs.wfs_id ";
+		$sql .= "WHERE wfs_conf.wfs_conf_id IN (";
+		
+		$v = array();
+		$t = array();
+		for ($i = 0; $i < count($idArray); $i++) {
+			if ($i > 0) {$sql .= ", ";}
+			$sql .= "$" . ($i+1);
+			array_push($v, $idArray[$i]);
+			array_push($t, 'i');
 		}
+		$sql .= ")";
 		
-		if (count($idArray) > 0) {
-			/*
-			 * Get WFS configurations
-			 */
-			$sql = "SELECT * FROM wfs_conf ";
-			$sql .= "JOIN wfs ON wfs_conf.fkey_wfs_id = wfs.wfs_id ";
-			$sql .= "WHERE wfs_conf.wfs_conf_id IN (";
-			
-			$v = array();
-			$t = array();
-			for ($i = 0; $i < count($idArray); $i++) {
-				if ($i > 0) {$sql .= ", ";}
-				$sql .= "$" . ($i+1);
-				array_push($v, $idArray[$i]);
-				array_push($t, 'i');
-			}
-			$sql .= ")";
-			
-			$res = db_prep_query($sql, $v, $t);
-			
-			while ($row = db_fetch_array($res)) {
+		$res = db_prep_query($sql, $v, $t);
+		
+		$rowArray = array();
+		while ($row = db_fetch_array($res)) {
+			array_push($rowArray, $row);
+		}
+		return $rowArray;
+	}
 	
-				
-				/*
-				 * Get WFS conf elements
-				 */
-				$id = $row["wfs_conf_id"];
+	/**
+	 * Gets the database content of a WFS conf element given by a WFS conf ID.
+	 * 
+	 * @return Array
+	 * @param $id Integer the WFS conf ID.
+	 */
+	private static function getWfsConfElementFromDb ($id) {
+		$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 ";
+		#filtered on client side
+		#$sql .= "AND wfs_conf_element.f_search = 1 ";
+		$sql .= "ORDER BY wfs_conf_element.f_pos";
+		$v = array($id);
+		$t = array('i');
+		$res = db_prep_query($sql, $v, $t);
 	
-				$sql_conf_element = "SELECT * FROM wfs_conf_element ";
-				$sql_conf_element .= "JOIN wfs_element ON wfs_conf_element.f_id = wfs_element.element_id ";
-				$sql_conf_element .= "WHERE wfs_conf_element.fkey_wfs_conf_id = $1 ";
-#filtered on client side
-#				$sql_conf_element .= "AND wfs_conf_element.f_search = 1 ";
-				$sql_conf_element .= "ORDER BY wfs_conf_element.f_pos";
-				$v_conf_element = array($id);
-				$t_conf_element = array('i');
-				$res_conf_element = db_prep_query($sql_conf_element, $v_conf_element, $t_conf_element);
-			
-				$elementArray = array();
-				while ($row_conf_element = db_fetch_array($res_conf_element)) {
+		$elementArray = array();
+		while ($row = db_fetch_array($res)) {
+			$currentElement = array("element_name" => $row["element_name"],
+									"element_type" => $row["element_type"],
+									"f_search" => $row["f_search"],
+									"f_style_id" => $row["f_style_id"],
+									"f_toupper" => $row["f_toupper"],
+									"f_label" => $row["f_label"],
+									"f_label_id" => $row["f_label_id"],
+									"f_geom" => $row["f_geom"],
+									"f_show" => $row["f_show"],
+									"f_respos" => $row["f_respos"],
+									"f_form_element_html" => $row["f_form_element_html"],
+									"f_show_detail" => $row["f_show_detail"]
+									);
+			array_push($elementArray, $currentElement);
+		}
+		return $elementArray;
+	}
+
+	/**
+	 * Gets the database content of a WFS feature type given by a WFS ID and a featuretype ID.
+	 * 
+	 * @return Array
+	 * @param $wfsId Integer the WFS ID.
+	 * @param $featuretypeId Integer the WFS featuretype ID.
+	 */
+	private static function getWfsFeatureTypeFromDb($wfsId, $featuretypeId) {
+		$sql = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = $1 AND featuretype_id = $2";
+		$v = array($wfsId, $featuretypeId);
+		$t = array("i", "i");
 	
+		$res = db_prep_query($sql, $v, $t);
+
+		$currentRow = array();
+		
+		if($row = db_fetch_array($res)){
+			$currentRow["featuretype_name"] = $row["featuretype_name"];
+			$currentRow["featuretype_srs"] = $row["featuretype_srs"];
+		}
 	
-					$currentElement = array("f_search" => $row_conf_element["f_search"],
-											"f_style_id" => $row_conf_element["f_style_id"],
-											"f_toupper" => $row_conf_element["f_toupper"],
-											"f_label" => $row_conf_element["f_label"],
-											"f_label_id" => $row_conf_element["f_label_id"],
-											"f_geom" => $row_conf_element["f_geom"],
-											"f_show" => $row_conf_element["f_show"],
-											"f_respos" => $row_conf_element["f_respos"],
-											"f_show_detail" => $row_conf_element["f_show_detail"],
-											"element_name" => $row_conf_element["element_name"],
-											"element_type" => $row_conf_element["element_type"]
-											);
-					array_push($elementArray, $currentElement);
-				}
-				
-				/*
-				 * Get WFS featuretype
-				 */
-				$sql_feature_type = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = $1 AND featuretype_id = $2";
-				$v_feature_type = array($row["fkey_wfs_id"], $row["fkey_featuretype_id"]);
-				$t_feature_type = array("i", "i");
+		return $currentRow;
+	}
+	
+	/**
+	 * get WFS conf data from database
+	 */
+	private function getWfsConfFromDB ($idArray) {
+		
+		// if a user has access to some WFS confs...
+		if (count($idArray) > 0) {
+
+			// get WFS conf data from DB
+			$rowArray = self::getWfsConfFromDbByArray($idArray);
 			
-				$res_feature_type = db_prep_query($sql_feature_type, $v_feature_type, $t_feature_type);
-				if($row_feature_type = db_fetch_array($res_feature_type)){
-					$featuretype_name  = $row_feature_type["featuretype_name"];
-					$featuretype_srs  = $row_feature_type["featuretype_srs"];
-				}
-			
-				$currentRow = array("g_label" => $row["g_label"], 
-			                        "g_label_id" => $row["g_label_id"],
-									"g_style" => $row["g_style"],
-									"g_button" => $row["g_button"],
-									"g_button_id" => $row["g_button_id"],
-									"g_buffer" => $row["g_buffer"],
-									"g_res_style" => $row["g_res_style"],
-									"g_use_wzgraphics" => $row["g_use_wzgraphics"],
-									"wfs_id" => $row["fkey_wfs_id"],
-									"featuretype_id" => $row["fkey_featuretype_id"],
-									"featuretype_name" => $featuretype_name,
-									"featuretype_id" => $featuretype_srs,
-									"wfs_getfeature" => $row["wfs_getfeature"],
-									"wfs_describefeaturetype" => $row["wfs_describefeaturetype"],
-									"element" => $elementArray
+			for ($i=0; $i < count($rowArray); $i++) {
+	
+				// WFS conf data				
+				$currentRow = array("g_label" => $rowArray[$i]["g_label"], 
+			                        "g_label_id" => $rowArray[$i]["g_label_id"],
+									"g_style" => $rowArray[$i]["g_style"],
+									"g_button" => $rowArray[$i]["g_button"],
+									"g_button_id" => $rowArray[$i]["g_button_id"],
+									"g_buffer" => $rowArray[$i]["g_buffer"],
+									"g_res_style" => $rowArray[$i]["g_res_style"],
+									"g_use_wzgraphics" => $rowArray[$i]["g_use_wzgraphics"],
+									"wfs_id" => $rowArray[$i]["fkey_wfs_id"],
+									"featuretype_id" => $rowArray[$i]["fkey_featuretype_id"],
+									"wfs_getfeature" => $rowArray[$i]["wfs_getfeature"],
+									"wfs_describefeaturetype" => $rowArray[$i]["wfs_describefeaturetype"],
+									"wfs_transaction" => $rowArray[$i]["wfs_transaction"]
 									);
-			
+
+				// get WFS conf element data of current WFS conf
+				$id = $rowArray[$i]["wfs_conf_id"];
+				$currentRow["element"] = self::getWfsConfElementFromDb($id);
+
+				// get WFS featuretype data of current WFS conf
+				$wfsId = $rowArray[$i]["fkey_wfs_id"];
+				$featuretypeId = $rowArray[$i]["fkey_featuretype_id"];
+				$currentRow = array_merge($currentRow , self::getWfsFeatureTypeFromDb($wfsId, $featuretypeId));
+
 				$this->confArray[$id] = $currentRow;
 			}
+			return $this->confArray;
 		}
 		else {
 			$e = new mb_warning("class_wfs_conf.php: getWfsConfFromDB: You don't have access to any WFS confs. Check EDIT WFS.");
+			return array();
 		}
 	}
 	
-	/** identifies the Conf-FeatureServices where the current user is owner
-	 * 
-	 * @param integer userid the user-ID of the current user
-	 * @return integer[] the IDs of the wfs_conf-table
-	 */
-	public static function getWfsConfByPermission($userid){
-	 	$guisByPer = array();
-//	 	1.
-		$adm = new administration();
-	 	$guisByPer = $adm->getGuisByPermission($userid, true);
-//	 	2. 
-		if(count($guisByPer)>0){
-			$v = array();
-			$t = array();
-			$sql = "SELECT wfs_conf.wfs_conf_id  FROM gui_wfs_conf, wfs_conf " .
-					"where wfs_conf.wfs_conf_id = gui_wfs_conf.fkey_wfs_conf_id " .
-					"and gui_wfs_conf.fkey_gui_id IN(";
-			for($i=0; $i<count($guisByPer); $i++){
-				if($i>0){ $sql .= ",";}
-				$sql .= "$".strval($i+1);
-				
-				array_push($v, $guisByPer[$i]);
-				array_push($t, "s");
-			}
-			$sql .= ") GROUP BY wfs_conf.wfs_conf_id ORDER BY wfs_conf.wfs_conf_id";
-			
-			$res = db_prep_query($sql,$v,$t);
-			$ownWFSconfs = array();
-			$i=0;
-			while($row = db_fetch_array($res)){
-				
-				$ownWFSconfs[$i] = $row['wfs_conf_id'];
-				$i++;
-			}
-		}
-		return $ownWFSconfs;
-	}
 }
 
-
+/**
+ * @deprecated
+ */
 class wfs_conf{
 	
 	var $wfs_id;
@@ -285,8 +305,10 @@
 		global $DBSERVER,$DB,$OWNER,$PW;
 		$con = db_connect($DBSERVER,$OWNER,$PW);
 		db_select_db($DB,$con);
-		$sql = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = ".$id;
-		$res = db_query($sql);
+		$sql = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = $1";
+		$v = array($id);
+		$t = array("i");
+		$res = db_prep_query($sql, $v, $t);
 		$cnt = 0;
 		while ($row = db_fetch_array($res)){
 			$this->featuretype_id[$cnt] = $row["featuretype_id"];
@@ -312,8 +334,10 @@
 		global $DBSERVER,$DB,$OWNER,$PW;
 		$con = db_connect($DBSERVER,$OWNER,$PW);
 		db_select_db($DB,$con);
-		$sql = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = ".$fid;
-		$res = db_query($sql);
+		$sql = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = $1";
+		$v = array($fid);
+		$t = array("s");
+		$res = db_prep_query($sql, $v, $t);
 		$cnt = 0;
 		while ($row = db_fetch_array($res)){
 			$this->element_id[$cnt] = $row["element_id"];
@@ -336,8 +360,10 @@
 		global $DBSERVER,$DB,$OWNER,$PW;
 		$con = db_connect($DBSERVER,$OWNER,$PW);
 		db_select_db($DB,$con);
-		$sql = "SELECT * FROM wfs_featuretype_namespace WHERE fkey_featuretype_id = ".$fid;
-		$res = db_query($sql);
+		$sql = "SELECT * FROM wfs_featuretype_namespace WHERE fkey_featuretype_id = $1";
+		$v = array($fid);
+		$t = array("s");
+		$res = db_prep_query($sql, $v, $t);
 		$cnt = 0;
 		while ($row = db_fetch_array($res)){
 			$this->namespace_name[$cnt] = $row["namespace"];

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2008-04-23 13:21:04 UTC (rev 2405)
+++ trunk/mapbender/http/classes/class_wmc.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -16,12 +16,13 @@
 # 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.
-require_once("../../conf/mapbender.conf");
-require_once("../classes/class_wms.php");
-require_once("../classes/class_mb_exception.php");
-require_once("../classes/class_layer_monitor.php");
-require_once("../classes/class_bbox.php");
-require_once("../extensions/JSON.php");
+require_once(dirname(__FILE__) . "/../../conf/mapbender.conf");
+require_once(dirname(__FILE__) . "/../classes/class_wms.php");
+require_once(dirname(__FILE__) . "/../classes/class_mb_exception.php");
+require_once(dirname(__FILE__) . "/../classes/class_layer_monitor.php");
+require_once(dirname(__FILE__) . "/../classes/class_point.php");
+require_once(dirname(__FILE__) . "/../classes/class_bbox.php");
+require_once(dirname(__FILE__) . "/../classes/class_json.php");
 
 $con = db_connect(DBSERVER,OWNER,PW);
 db_select_db(DB,$con);
@@ -39,6 +40,10 @@
 	if($c>0)return substr($s,$c+1);
 	return $s;
 }
+
+/**
+ * Implementation of a Web Map Context Document, WMC 1.1.0
+ */
 class wmc {
 
 	var $xml;
@@ -136,6 +141,11 @@
 function wmc() {
 } 
 
+/**
+ * Saves the current WMC in the log folder.
+ * 
+ * @return string the filename of the WMC document.
+ */
 function saveAsFile() {
 	$filename = "wmc_" . date("Y_m_d_H_i_s") . ".log";
 	$logfile = "../../log/" . $filename;
@@ -151,14 +161,29 @@
 	return $filename;
 }
 
+/**
+ * @return string the title of the WMC.
+ */
 function getTitle() {
 	return $this->wmc_title;
 }
 
+/**
+ * @return Integer the number of (unique?) WMS contained in this WMC.
+ */
 function getNumberOfWms () {
 	return $this->wmc_wms_count;
 }
 
+/**
+ * Creates a WMC object from a JS map object {@see map.js}
+ * 
+ * @param object $mapObject a map object
+ * @param integer $user_id the ID of the current user
+ * @param string $generalTitle the desired title of the WMC
+ * @param object $extensionData data exclusive to Mapbender, which will be 
+ * 								mapped into the extension part of the WMC
+ */
 function createWMCFromObj($mapObject, $user_id, $generalTitle, $extensionData) {
 	$this->wmc_id = $user_id . '_' . time();
 	
@@ -630,19 +655,31 @@
 	}
 }
 
+/**
+ * Loads a WMC from the database.
+ * 
+ * @param integer $wmc_id the ID of the WMC document in the database table "mb_user_wmc"
+ */
 function createObjFromWMC_id($wmc_id){
 	
 	global $DBSERVER,$DB,$OWNER,$PW;
 	$con = db_connect($DBSERVER,$OWNER,$PW);
 	db_select_db(DB, $con);
 	
-	$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = '" . $wmc_id . "'";
-	$res = db_query($sql);
+	$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1";
+	$v = array($wmc_id);
+	$t = array("i");
+	$res = db_prep_query($sql, $v, $t);
 	$wmc = db_fetch_row($res);
 	$this->createObjFromWMC_xml($wmc[0]);
 	$this->monitoringIsOn = true;
+}
 
-}
+/**
+ * Loads a WMC from an actual WMC XML document.
+ * 
+ * @param string $data the data from the XML file
+ */
 function createObjFromWMC_xml($data){
 #	$data = str_replace("&#38;", "&amp;", $data);
 
@@ -1022,6 +1059,16 @@
 	  //return $verbose;
 	}
 
+	/**
+	 * Creates JS code manipulating the map and wms objects, 
+	 * by this displaying the WMC
+	 * 
+	 * @param string $target the link to the map object, f.e. "parent." or "window.opener."
+	 * @param string $mapObj the name of the map object, f.e. "mapframe1"
+	 * @param string $action "load", "merge" or "append"
+	 * 
+	 * @return string the JS code
+	 */
 	function createJsObjFromWMC($target, $mapObj, $action){
 		
 		/*
@@ -1043,7 +1090,7 @@
 			
 			// general extension
 			if (count($this->wmc_general_extension) > 0) {
-				$json = new Services_JSON();
+				$json = new Mapbender_JSON();
 				$wmc_string .= $target . "restoredWmcExtensionData = " . $json->encode($this->wmc_general_extension) . ";\n"; 
 			}
 			
@@ -1106,7 +1153,7 @@
 						$this->wmc_wms_serviceURL[$i] ."','" .
 						$this->wmc_layer_style_legendurl[$i][0] ."','','". 
 						$wms_data_format ."','text/html','application/vnd.ogc.se_xml','". 
-						$this->wmc_bBox_SRS ."','1','100');\n";
+						$this->wmc_bBox_SRS ."','1','100','');\n";
 		
 					$added_wms[count($added_wms)] = $current_wms;
 					$cnt_wms++;
@@ -1319,7 +1366,6 @@
 			$wmc_string .= "\t". $target . "setMapRequest(old_mapObj[i].frameName);\n";
 			$wmc_string .= "}\n";
 			$wmc_string .= $target . "mb_execloadWmsSubFunctions();\n";
-			$wmc_string .= $target . "mb_execloadWmcSubFunctions();\n";
 		}
 //		$e = new mb_exception("js code: " . $wmc_string);
 		return $wmc_string;

Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php	2008-04-23 13:21:04 UTC (rev 2405)
+++ trunk/mapbender/http/classes/class_wms.php	2008-04-23 15:59:31 UTC (rev 2406)
@@ -59,10 +59,16 @@
 	var $data_format = array();
 	var $objLayer = array(); 
 	  
+	var $wms_supportsld;
+	var $wms_userlayer;
+	var $wms_userstyle;
+	var $wms_remotewfs;
+		
 	var $gui_wms_mapformat;
 	var $gui_wms_featureinfoformat;
 	var $gui_wms_exceptionformat;
 	var $gui_wms_epsg;
+	var $gui_wms_sldurl;
 	  
 	var $default_epsg = 0;
 	var $overwrite = true;
@@ -94,8 +100,7 @@
 		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,$this->wms_getcapabilities_doc,$values,$tags);
-		xml_parse_into_struct($parser,$data,$values,$tags);
+		xml_parse_into_struct($parser,$this->wms_getcapabilities_doc,$values,$tags);
 
 		$code = xml_get_error_code($parser);
 		if ($code) {
@@ -341,7 +346,14 @@
 				$section = "";
 			}         
 	      }
-	      
+			/* sld section */	      
+			if(mb_strtoupper($element[tag]) == "USERDEFINEDSYMBOLIZATION" && $element[type] == "complete"){
+				$this->wms_supportsld = $element[attributes]["SupportSLD"];
+				$this->wms_userlayer = $element[attributes]["UserLayer"];
+				$this->wms_userstyle = $element[attributes]["UserStyle"];
+				$this->wms_remotewfs = $element[attributes]["RemoteWFS"];
+			}
+	      	      
 			/*layer section*/				
 			if(mb_strtoupper($element[tag]) == "LAYER"){
 				$section = "layer";
@@ -600,7 +612,22 @@
 		for($i=0; $i<count($this->objLayer); $i++){
 				$this->objLayer[$i]->layer_pos=$i;
 		}
+		
+		/* fill sld variables when empty */
+		if($this->wms_supportsld == ""){
+				$this->wms_supportsld = 0;
+		}
+		if($this->wms_userlayer == ""){
+				$this->wms_userlayer = 0;
+		}
+		if($this->wms_userstyle == ""){
+				$this->wms_userstyle = 0;
+		}
+		if($this->wms_remotewfs == ""){
+				$this->wms_remotewfs = 0;
+		}
 	  }
+	
 	function displayWMS(){
 		echo "<br>id: " . $this->wms_id . " <br>";
 		echo "version: " . $this->wms_version . " <br>";
@@ -616,6 +643,7 @@
 		echo "wms_srs: " . $this->objLayer[0]->wms_srs1 . " <br>";		
 		echo "gui_wms_visible: " . $this->gui_wms_visible . " <br>";
 		echo "gui_wms_opacity: " . $this->gui_wms_opacity . " <br>";
+		echo "support_sld: " . $this->wms_supportsld . " <br>";
 		
 		for($i=0; $i<count($this->data_type);$i++){
 			echo $this->data_type[$i]. " -> ".$this->data_format[$i]. "<br>";
@@ -678,7 +706,8 @@
 					"'" . $this->gui_wms_exceptionformat . "'," .
 					"'" . $this->gui_wms_epsg ."'," .
 					"'" . $this->gui_wms_visible ."'," .
-					"'" . $this->gui_wms_opacity ."" .
+					"'" . $this->gui_wms_opacity ."'," .
+					"'" . $this->gui_wms_sldurl ."" .
 					"');";
 			echo $add_wms_string;
 			
@@ -769,7 +798,8 @@
 			$this->gui_wms_exceptionformat . "','". 
 			$this->gui_wms_epsg ."','". 
 			$this->gui_wms_visible ."','".
-			$this->gui_wms_opacity ."');\n");
+			$this->gui_wms_opacity ."','".
+			$this->gui_wms_sldurl ."');\n");
 			
 		for($i=0;$i<count($this->data_format);$i++){
 			if($parent){
@@ -846,25 +876,27 @@
 		global $con;
 		
 		$this->checkObj();
-		//db_begin();
+		db_begin();
 	
 		# TABLE wms
 		$sql = "INSERT INTO wms (wms_version, wms_title, wms_abstract, wms_getcapabilities, wms_getmap, ";
 		$sql.= "wms_getfeatureinfo, wms_getlegendurl, wms_getcapabilities_doc, wms_upload_url, fees, ";
 		$sql .= "accessconstraints, contactperson, contactposition, contactorganization, address, city, ";
 		$sql .= "stateorprovince, postcode, country, contactvoicetelephone, contactfacsimiletelephone, contactelectronicmailaddress, ";
-		$sql .= "wms_owner,wms_timestamp) ";
-		$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24)";
+		$sql .= "wms_owner,wms_timestamp, ";
+		$sql .= "wms_supportsld, wms_userlayer, wms_userstyle, wms_remotewfs) ";
+		$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28)";
 		$v = array($this->wms_version,$this->wms_title,$this->wms_abstract,$this->wms_getcapabilities,
-			$this->wms_getmap,$this->wms_getfeatureinfo,$this->wms_getlegendurl,"",
+			$this->wms_getmap,$this->wms_getfeatureinfo,$this->wms_getlegendurl,$this->wms_getcapabilities_doc,
 			$this->wms_upload_url,$this->fees,$this->accessconstraints,$this->contactperson,$this->contactposition,
 			$this->contactorganization,$this->address,$this->city,$this->stateorprovince,$this->postcode,$this->country,
 			$this->contactvoicetelephone,$this->contactfacsimiletelephone,$this->contactelectronicmailaddress,
-			$_SESSION['mb_user_id'],strtotime("now"));
-		$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','i','i');
+			$_SESSION['mb_user_id'],strtotime("now"),
+			$this->wms_supportsld,$this->wms_userlayer,$this->wms_userstyle,$this->wms_remotewfs );
+		$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','i','i','s','s','s','s');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			////db_rollback();
+			db_rollback();
 		}
 		
 		$myWMS = db_insert_id($con,'wms', 'wms_id');
@@ -902,9 +934,9 @@
 		$t = array('s','i','i','s','s','s','s');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			////db_rollback();	
+			db_rollback();	
 		}
-		//db_commit();
+		db_commit();
 	    
 	    #Changes JW
 	    $this->wms_id = $myWMS;
@@ -931,7 +963,7 @@
 		$t = array('i','i','s','s','s','i','i','i','s','s','s');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			////db_rollback();	
+			db_rollback();	
 		}
 		else {
 			# save the id of each layer: set param2 true		
@@ -955,7 +987,7 @@
 			$l_id = $row['layer_id'];	
 		}
 		else{
-			////db_rollback();
+			db_rollback();
 			$e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name);
 			return;	
 		}	
@@ -1000,7 +1032,7 @@
 			$res = db_prep_query($sql,$v,$t);
 		}
 		if(!$res){
-			////db_rollback();	
+			db_rollback();	
 		}
 		else {
 			
@@ -1034,7 +1066,7 @@
 		$res = db_prep_query($sql,$v,$t);
 		#$e = new mb_exception("name des insert styles und fkey_layer_id: ".$layer_style_name." --- ".$this->objLayer[$i]->db_id);
 		if(!$res){
-			////db_rollback();	
+			db_rollback();	
 		}	
 	}
 	function appendGuiLayer($i,$myWMS,$gui_id){
@@ -1055,7 +1087,7 @@
 		$t = array('s','i','i','i','i','i','i','i','i','i','i','s');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			////db_rollback();	
+			db_rollback();	
 		}	
 	}
 	function insertSRS($myWMS){
@@ -1065,7 +1097,7 @@
 			$t = array('i','s');		
 			$res = db_prep_query($sql,$v,$t);
 			if(!$res){
-				//db_rollback();	
+				db_rollback();	
 			}
 		}	
 	}
@@ -1077,7 +1109,7 @@
 			$t = array('i','s','s');
 			$res = db_prep_query($sql,$v,$t);
 			if(!$res){
-				////db_rollback();	
+				db_rollback();	
 			}
 		}	
 	}
@@ -1096,7 +1128,7 @@
 			$t = array('i','s','d','d','d','d');
 			$res = db_prep_query($sql,$v,$t);
 			if(!$res){
-				////db_rollback();	
+				db_rollback();	
 			}
 		}
 	}
@@ -1115,7 +1147,7 @@
 			$t = array('i','s','s','s','s');
 			$res = db_prep_query($sql,$v,$t);
 			if(!$res){
-				////db_rollback();	
+				db_rollback();	
 			}
 		}
 	}
@@ -1147,10 +1179,9 @@
 					$sql_insertKeyword .= "VALUES ($1)";
 					$v1 = array($k[$j]);
 					$t1 = array('s');
-					echo $k[$j];
 					$res_insertKeyword = db_prep_query($sql_insertKeyword,$v1,$t1);
 					if(!$res_insertKeyword){
-						//db_rollback();	
+						db_rollback();	
 					}
 				}
 			}
@@ -1169,13 +1200,13 @@
 				$t1 = array('i','i');
 				$res1 = db_prep_query($sql1,$v1,$t1);
 				if(!$res1){
-					////db_rollback();	
+					db_rollback();	
 				}
 			}
 		}
 	}
 	function updateObjInDB($myWMS){
-		//db_begin();
+		db_begin();
 		
 		$sql = "UPDATE wms SET ";
 		$sql .= "wms_version = $1 ,";
@@ -1186,17 +1217,22 @@
 		$sql .= "wms_getcapabilities_doc = $6 ,";
 		$sql .= "wms_upload_url = $7,  ";
 		$sql .= "wms_owner = $8, ";
-		$sql .= "wms_timestamp = $9 ";
-		$sql .= " WHERE wms_id = $10";
+		$sql .= "wms_timestamp = $9, ";
+		$sql .= "wms_supportsld = $10, ";
+		$sql .= "wms_userlayer = $11, ";
+		$sql .= "wms_userstyle = $12, ";
+		$sql .= "wms_remotewfs = $13 ";
+		$sql .= " WHERE wms_id = $14";
 	
 		$v = array($this->wms_version,$this->wms_getcapabilities,
 			$this->wms_getmap,$this->wms_getfeatureinfo,$this->wms_getlegendurl,
-			$this->wms_getcapabilities_doc,$this->wms_upload_url,$_SESSION["mb_user_id"],strtotime("now"),$myWMS);
-		$t = array('s','s','s','s','s','s','s','i','i','i');
+			$this->wms_getcapabilities_doc,$this->wms_upload_url,$_SESSION["mb_user_id"],strtotime("now"),
+			$this->wms_supportsld,$this->wms_userlayer,$this->wms_userstyle,$this->wms_remotewfs,$myWMS);
+		$t = array('s','s','s','s','s','s','s','i','i','s','s','s','s','i');
 	
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			//db_rollback();	
+			db_rollback();	
 		}
 		
 		if($this->overwrite == true){
@@ -1225,7 +1261,7 @@
 			$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','i');
 			$res = db_prep_query($sql,$v,$t);
 			if(!$res){
-				//db_rollback();	
+				db_rollback();	
 			}
 		}
 		
@@ -1235,7 +1271,7 @@
 		$t = array('i');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			//db_rollback();	
+			db_rollback();	
 		}
 		$this->insertSRS($myWMS);
 		
@@ -1244,7 +1280,7 @@
 		$t = array('i');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			//db_rollback();	
+			db_rollback();	
 		}
 		$this->insertFormat($myWMS);
 		
@@ -1268,7 +1304,7 @@
 		
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			//db_rollback();	
+			db_rollback();	
 		}
 			
 		# update or insert?
@@ -1306,7 +1342,7 @@
 				}
 			}
 		}
-		//db_commit();
+		db_commit();
 		return;	
 	}
 	function updateGuiLayer($i,$myWMS,$gui_id){
@@ -1318,7 +1354,7 @@
 			$l_id = $row['layer_id'];	
 		}
 		else{
-			//db_rollback();
+			db_rollback();
 			$e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name. " in gui: ".$gui_id);
 			return;	
 		}
@@ -1336,7 +1372,7 @@
 				$res1 = db_prep_query($sql1,$v,$t);
 				if(!$res1){
 					
-				//db_rollback();
+				db_rollback();
 				}
 			}
 			if($this->objLayer[$i]->layer_queryable == 1){
@@ -1347,7 +1383,7 @@
 				$res1 = db_prep_query($sql1,$v,$t);
 				if(!$res1){
 					
-				//db_rollback();
+					db_rollback();
 				}
 			}
 			if($row["gui_layer_minscale"] < $this->objLayer[$i]->layer_minscale){
@@ -1356,7 +1392,7 @@
 				$v = array($this->objLayer[$i]->layer_minscale,$l_id,$gui_id);
 				$t = array('i','i','s');
 				$res1 = db_prep_query($sql1,$v,$t);
-				if(!$res1){//db_rollback();
+				if(!$res1){db_rollback();
 				}
 			}
 			if($row["gui_layer_maxscale"] > $this->objLayer[$i]->layer_maxscale){
@@ -1365,7 +1401,7 @@
 				$v = array($this->objLayer[$i]->layer_maxscale,$l_id,$gui_id);
 				$t = array('i','i','s');
 				$res1 = db_prep_query($sql1,$v,$t);
-				if(!$res1){//db_rollback();
+				if(!$res1){db_rollback();
 				}
 			}		
 		}
@@ -1380,7 +1416,12 @@
 		while($row = db_fetch_array($res)){	
 			unset($mySubmit);
 			$myGUI[$cnt] = $row["fkey_gui_id"];
-			$sql = "UPDATE gui_wms SET ";		
+
+			$sql = "UPDATE gui_wms SET ";
+			$v = array();
+			$t = array();
+			$paramCount = 0;		
+
 			for($i=0; $i<count($this->data_type); $i++){
 				# gui_wms_mapformat
 				if(mb_strtolower($this->data_type[$i]) == "map" && mb_strtolower($this->data_format[$i]) == mb_strtolower($row["gui_wms_mapformat"])){
@@ -1396,17 +1437,26 @@
 				}
 			}
 			if(!$myMapFormat){
-				$sql .= "gui_wms_mapformat = '".$this->gui_wms_mapformat."' ";
+				$paramCount++;
+				$sql .= "gui_wms_mapformat = $" . $paramCount . " ";
 				$mySubmit = true;
+				array_push($v, $this->gui_wms_mapformat);
+				array_push($t, "s");
 			}
 			if(!$myFeatureInfoFormat){
 				if($mySubmit){ $sql .= ",";}
-				$sql .= "gui_wms_featureinfoformat = '".$this->gui_wms_featureinfoformat."' ";
+				$paramCount++;
+				$sql .= "gui_wms_featureinfoformat = $" . $paramCount . " ";
+				array_push($v, $this->gui_wms_featureinfoformat);
+				array_push($t, "s");
 				$mySubmit = true;
 			}
 			if(!$myExceptionFormat){
 				if($mySubmit){ $sql .= ",";}
-				$sql .= "gui_wms_exceptionformat = '".$this->gui_wms_exceptionformat."' ";
+				$paramCount++;
+				$sql .= "gui_wms_exceptionformat = $" . $paramCount ." ";
+				array_push($v, $this->gui_wms_exceptionformat);
+				array_push($t, "s");
 				$mySubmit = true;
 			}
 				
@@ -1418,12 +1468,30 @@
 			}
 			if(!$myGUI_EPSG){
 				if($mySubmit){ $sql .= ",";}
-				$sql .= "gui_wms_epsg = '".$this->gui_wms_epsg."' ";
+				$paramCount++;
+				$sql .= "gui_wms_epsg = $" . $paramCount . " ";
+				array_push($v, $this->gui_wms_epsg);
+				array_push($t, "s");
 				$mySubmit = true;
 			}
-			$sql .= " WHERE fkey_gui_id = '".$row["fkey_gui_id"]."' AND fkey_wms_id = " . $myWMS;
+			$paramCount++;
+			$sql .= " WHERE fkey_gui_id = $" . $paramCount . " ";
+			array_push($v, $row["fkey_gui_id"]);
+			array_push($t, "s");
+
+			$paramCount++;
+			$sql .= "AND fkey_wms_id = $" . $paramCount;
+			array_push($v, $myWMS);
+			array_push($t, "i");
 			if($mySubmit){
-				$this->transaction($sql);
+				$res = db_prep_query($sql,$v,$t);
+				if(!$res){
+					db_rollback();	
+					echo "<pre>".$sql."</pre><br> <br><p>";
+				 	echo db_error(); 
+				 	echo "<br /> UPDATE ERROR -> KILL PROCESS AND ROLLBACK....................no update<br><br>";
+					$e = new mb_exception("class_wms.php: transaction: Transaction aborted, rollback.");
+				}
 			}
 			$cnt++;
 		}	
@@ -1439,26 +1507,7 @@
 	function getCapabilitiesDoc() {
 		return $this->wms_getcapabilities_doc;
 	}
-	function transaction($sql){
-		#echo "<hr>". $sql;
-		$ok = db_query($sql);
-		if(!$ok){
-			echo "<pre>".$sql."</pre><br> <br><p>";
-			$error = db_error();
-			$sql = "ROLLBACK";
-			$res = db_query($sql);
-			if(SYS_DBTYPE=="pgsql")
-				{
-					$sql = "SET AUTOCOMMIT=0";
-				}
-				else
-				{
-				 	$sql = "SET AUTOCOMMIT=1";
-				}
-		 	echo $error; 
-		 	echo "<br /> UPDATE ERROR -> KILL PROCESS AND ROLLBACK....................no update<br><br>";
-			}
-	}
+
 	/**
 	* creatObjfromDB
 	*
@@ -1481,7 +1530,7 @@
 			$this->gui_wms_epsg=$row["gui_wms_epsg"];
 			$this->gui_wms_visible = $row["gui_wms_visible"];
 			$this->gui_wms_opacity = $row["gui_wms_opacity"];
-			
+			$this->gui_wms_sldurl = $row["gui_wms_sldurl"];
 	  
 			$sql = "Select * from wms where wms_id = $1 ";
 			$v = array($wms_id);
@@ -1510,6 +1559,10 @@
 				}			
 				$this->wms_getcapabilities_doc = $row2["wms_getcapabilities_doc"];
 				$this->wms_filter = $row2["wms_filter"];
+				$this->wms_supportsld = $row2["wms_supportsld"];
+				$this->wms_userlayer = $row2["wms_userlayer"];
+				$this->wms_userstyle = $row2["wms_userstyle"];
+				$this->wms_remotewfs = $row2["wms_remotewfs"];
 				
 				$count_wms++;
 			}



More information about the Mapbender_commits mailing list