[Mapbender-commits] r2580 - branches/testbaudson_dev/lib

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jul 2 08:24:58 EDT 2008


Author: christoph
Date: 2008-07-02 08:24:58 -0400 (Wed, 02 Jul 2008)
New Revision: 2580

Added:
   branches/testbaudson_dev/lib/administration.php
   branches/testbaudson_dev/lib/checkInput.php
   branches/testbaudson_dev/lib/connector.php
   branches/testbaudson_dev/lib/exception.php
   branches/testbaudson_dev/lib/json.php
   branches/testbaudson_dev/lib/log.php
   branches/testbaudson_dev/lib/notice.php
   branches/testbaudson_dev/lib/user.php
   branches/testbaudson_dev/lib/warning.php
   branches/testbaudson_dev/lib/wms.php
Log:
copied from /http/classes

Added: branches/testbaudson_dev/lib/administration.php
===================================================================
--- branches/testbaudson_dev/lib/administration.php	                        (rev 0)
+++ branches/testbaudson_dev/lib/administration.php	2008-07-02 12:24:58 UTC (rev 2580)
@@ -0,0 +1,1119 @@
+<?php
+# $Id: class_administration.php 2453 2008-05-15 09:06:04Z christoph $
+# http://www.mapbender.org/index.php/class_administration
+# Copyright (C) 2002 CCGIS
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/exception.php");
+require_once(dirname(__FILE__)."/user.php");
+require_once(dirname(__FILE__)."/../ext/phpmailer-1.72/class.phpmailer.php");
+
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
+
+
+/**
+ * class to wrap administration methods
+ *
+ * @uses phpmailer
+ */ 
+class administration {
+    /**
+     * checks whether the passed email-address is valid / following a pattern
+     * @todo is this an exact representation of the RFC 2822?
+     * @todo this should be checked: what about umlaut-domains and tld like '.museum'?
+     * @see http://tools.ietf.org/html/rfc2822
+     *
+     * @param <string> a all lowercase email adress to test
+     * @return <boolean> answer to "is the passed over email valid?""
+     */
+	function isValidEmail($email) {
+        if(mb_eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
+            return true;
+		}
+		return false;
+	}
+
+    /**
+     * sends an email via php mailer
+     *
+     * @param string an email address for the "From"-field
+     * @param string the displayed name for the "From"-field
+     * @param string an email address for the "To"-field
+     * @param string the displayed name for the "From"-field
+     * @param string the text to be set as "Subject"
+     * @param string the text of the emails body
+     * @param string a reference to an error string
+     */
+	function sendEmail($fromAddr, $fromName, $toAddr, $toName, $subject, $body, &$error_msg ){
+
+		global $mailHost, $mailUsername, $mailPassword;
+		if($fromAddr == ''){
+			$fromAddr = MAILADMIN;
+		}
+
+		if($fromName == ''){
+			$fromName = MAILADMINNAME;
+		}
+
+		if ($this->isValidEmail($fromAddr) && $this->isValidEmail($toAddr)) {
+			$mail = new PHPMailer();
+
+			if ($fromName != "" ) {
+				$mail->FromName = $fromName;
+			}
+
+			$mail->IsSMTP();                  // set mailer to use SMTP
+			$mail->Host = $mailHost;          // specify main and backup server
+			$mail->SMTPAuth = true;           // turn on SMTP authentication
+			$mail->Username = $mailUsername;  // SMTP username
+			$mail->Password = $mailPassword;  // SMTP password
+
+			$mail->From = $fromAddr;
+			$mail->AddAddress($toAddr, $toName);
+			#$mail->AddReplyTo("info at ccgis.de", "Information");
+
+			$mail->WordWrap = 50;                                 // set word wrap to 50 characters
+			#$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
+			#$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
+			$mail->IsHTML(false);                                  // set email format to HTML
+
+			$mail->Subject = "[".$fromName."] ".$subject;
+			$mail->Body    = $body;
+			#$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
+
+			$error_msg='';
+
+			if(!$mail->Send())
+			{
+			   $error_msg .= "Mailer Error: " . $mail->ErrorInfo;
+			   return false;
+			}
+
+			return true;
+		}
+		else {
+			return false;
+		}
+	}
+
+	/**
+	 * Removes the namespace from a tag name
+	 * @return String like "gml"
+	 * @param $s String like "ogc:gml"
+	 */
+	public static function sepNameSpace($s) {
+		$c = strpos($s,":"); 
+		if ($c > 0) {
+			return substr($s,$c+1);	
+		}
+		return $s;
+	}
+
+	/**
+	 * Parses an XML with PHP XML parser, see 
+	 * http://de2.php.net/manual/de/book.xml.php
+	 * 
+	 * @return Array an associative array of tags, values, attributes and types
+	 * @param $someXml String The actual XML as string.
+	 */
+	public static function parseXml ($someXml) {
+		$values = null;
+		$tags = null;
+		
+		$parser = xml_parser_create(CHARSET);
+
+		// set parsing options
+		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);
+
+		// this is the actual parsing process
+		xml_parse_into_struct($parser, $someXml, $values, $tags);
+
+		// check if an error occured
+		$code = xml_get_error_code ($parser);
+		if ($code) {
+			// report error
+			$line = xml_get_current_line_number($parser); 
+			$errorMessage = xml_error_string($code) . " in line " . $line;
+			$mb_exception = new mb_exception($errorMessage);
+			return false;
+		}
+		xml_parser_free($parser);
+	
+		return $values;	
+	}
+
+    /**
+     * returns a random password with numbers and chars both lowercase and uppercase (0-9a-zA-Z)
+     *
+     * @return string the new password
+     */
+ 	function getRandomPassword() {
+
+		// password length
+		$max = 16;
+
+		//new password
+		$newpass = "";
+
+		for ($i=0;$i <= $max;$i++) {
+			//die ASCII-Zeichen 48 - 57 sind die zahlen 0-9
+			//die ASCII-Zeichen 65 - 90 sind die buchstaben A-Z (Gro�)
+			//die ASCII-Zeichen 97 - 122 sind die buchstaben a-z (Klein)
+			$ascii = 0;
+			do {
+				$ascii=rand(48,122);
+			} while ( ($ascii > 57 && $ascii < 65) || ($ascii > 90 && $ascii < 97));
+			$newpass .= chr($ascii);
+		}
+		return $newpass;
+ 	}
+
+    /**
+     * returns the name of a mapbender user which owns the GUI identified by the passed over gui_id.
+     *
+     * @param string the gui_id
+     * @return integer the user id of the owner
+     */
+ 	function getOwnerByGui($gui_id){
+		$sql = "(SELECT mb_user.mb_user_id";
+		$sql .= "FROM mb_user ";
+		$sql .= "JOIN gui_mb_user ON mb_user.mb_user_id = gui_mb_user.fkey_mb_user_id ";
+		$sql .= "WHERE gui_mb_user.mb_user_type = 'owner' ";
+		$sql .= "AND gui_mb_user.fkey_gui_id = $1 ";
+		$sql .= "GROUP BY mb_user.mb_user_id ";
+		$sql .= ") ";
+		$sql .= "UNION ( ";
+		$sql .= "SELECT mb_user.mb_user_id ";
+		$sql .= "FROM gui_mb_group ";
+		$sql .= "JOIN mb_user_mb_group ON mb_user_mb_group.fkey_mb_group_id = gui_mb_group.fkey_mb_group_id ";
+		$sql .= "JOIN mb_user ON mb_user.mb_user_id = mb_user_mb_group.fkey_mb_user_id ";
+		$sql .= "JOIN gui_mb_user ON mb_user.mb_user_id = gui_mb_user.fkey_mb_user_id ";
+		$sql .= "WHERE gui_mb_group.mb_group_type = 'owner' ";
+		$sql .= "AND gui_mb_group.fkey_gui_id = $2 ";
+		$sql .= "GROUP BY mb_user.mb_user_id)";
+		$owner = array();
+		$v = array($gui_id,$gui_id);
+		$t = array('s','s');
+		$res = db_prep_query($sql,$v,$t);
+		$cnt = 0;
+		while($row = db_fetch_array($res)){
+			$owner[$cnt] = $row["mb_user_id"];
+			$cnt++;
+		}
+		return $owner;
+ 	}
+
+    /**
+     * returns the content of the field mb_user_email for the given userid.
+     *
+     * @param integer userid the id of the current user
+     * @return string the email if one row is found or false if none is found
+     */
+	function getEmailByUserId($userid){
+		$sql = "SELECT mb_user_email FROM mb_user ";
+		$sql .= "WHERE mb_user_id = $1 GROUP by mb_user_email";
+        // TODO why do we group, when userid is a primary key?
+		$v = array($userid);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		// TODO shall the next two lines be removed?
+        $count_g = 0;
+		$array = array();
+		$row = db_fetch_array($res);
+		if ($row) {
+			return $row["mb_user_email"];
+		}
+		else {
+			return false;
+		}
+	}
+
+    /**
+     * returns the name of the user for the given userid.
+     *
+     * @param	integer		the userid
+     * @return 	string		the name if one row is found or false if none is foundd
+     */
+	function getUserNameByUserId($userid){
+		$sql = "SELECT mb_user_name FROM mb_user ";
+		$sql .= "WHERE mb_user_id = $1 GROUP BY mb_user_name";
+        // TODO why do we group, when userid is a primary key?
+		$v = array($userid);
+		$t = array("i");
+		$res = db_prep_query($sql,$v,$t);
+        // TODO shall the next two lines be removed?
+		$count_g = 0;
+		$array = array();
+		$row = db_fetch_array($res);
+		if ($row) {
+			return $row["mb_user_name"];
+		}
+		else {
+			return false;
+		}
+	}
+
+    /**
+     * returns one or more userids from the given email or false,
+     * if there is no record in the database matching the given email
+     *
+     * @param	string	the email
+     * @return	mixed	an array of userids or false when no records matches
+     */
+ 	function getUserIdByEmail($email){
+		$sql = "SELECT  mb_user_id FROM mb_user ";
+		$sql .= "WHERE mb_user_email = $1 GROUP BY mb_user_id";
+		$v = array($email);
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
+  		$count_g = 0;
+  		$array = array();
+		while($row = db_fetch_array($res)){
+			$array[$count_g] = $row["mb_user_id"];
+			$count_g++;
+		}
+		if ($count_g >0)	{
+			return $array;
+		}
+		else {
+			return false;
+		}
+ 	}
+
+    /**
+     * returns one or more owners for the given wm_id. First all guis deploying
+     * this wms are selected. Afterwards for each of the guis the owners are
+     * selected and stored within an array.
+     *
+     * @param	integer		the wms_id
+     * @return	mixed		an array of user ids which use the wms in their guis 
+     * 						(both for persona or group ownership)
+     */
+	function getOwnerByWms($wms_id){
+		// first get guis which deploy this wms.
+        $sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = $1 GROUP BY fkey_gui_id";
+		$v = array($wms_id);
+		$t = array('i');
+		$count=0;
+		$res = db_prep_query($sql,$v,$t);
+		while($row = db_fetch_array($res)){
+			$gui[$count] = $row["fkey_gui_id"];
+			$count++;
+		}
+
+		if ($count > 0) {
+			// this is not needed! count($gui) is always equal to $count
+            if(count($gui)>0) {
+				$v = array();
+				$t = array();
+				$c = 1;
+				$sql = "(SELECT mb_user.mb_user_id FROM mb_user JOIN gui_mb_user ";
+				$sql .= "ON mb_user.mb_user_id = gui_mb_user.fkey_mb_user_id ";
+				$sql .= " WHERE gui_mb_user.mb_user_type = 'owner'";
+				$sql .= " AND gui_mb_user.fkey_gui_id IN (";
+				for($i=0; $i<count($gui); $i++){
+					if($i>0){ $sql .= ",";}
+					$sql .= "$".$c;
+					$c++;
+					array_push($v, $gui[$i]);
+					array_push($t, 's');
+				}
+				$sql .= ") GROUP BY mb_user.mb_user_id";
+				$sql .= ") UNION (";
+				$sql .= "SELECT mb_user.mb_user_id FROM gui_mb_group JOIN mb_user_mb_group ON  mb_user_mb_group.fkey_mb_group_id = gui_mb_group.fkey_mb_group_id  JOIN mb_user ";
+				$sql .= "ON mb_user.mb_user_id = mb_user_mb_group.fkey_mb_user_id ";
+				$sql .= " WHERE gui_mb_group.mb_group_type = 'owner'";
+				$sql .= " AND gui_mb_group.fkey_gui_id IN (";
+
+				for($j=0; $j<count($gui); $j++){
+					if($j>0){ $sql .= ",";}
+					$sql .= "$".$c;
+					$c++;
+					array_push($v, $gui[$i]);
+					array_push($t, 's');
+				}
+				$sql .= ") GROUP BY mb_user.mb_user_id)";
+
+				$user = array();
+				$res = db_prep_query($sql,$v,$t);
+			}
+			$cnt = 0;
+
+			while($row = db_fetch_array($res)){
+				$user[$cnt] = $row["mb_user_id"];
+				$cnt++;
+			}
+			if ($cnt>0)	{
+                return $user;
+            } else {
+                return false;
+            }
+		} else {
+          return false;
+        }
+	}
+    /**
+     * tests whether a gui with the passed gui_id exits and returns true or false.
+     *
+     * @param	string		the gui_id to test
+     * @return	boolean		Does a Gui with the passed over gui_id exist?
+     */
+	function guiExists($id){
+		$sql = "SELECT * FROM gui WHERE gui_id = $1 ";
+		$v = array($id);
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
+		$row = db_fetch_array($res);
+		if ($row) {
+			return true;
+		}
+		else {
+			return false;
+		}
+	}
+
+    /**
+     * deletes a {@link http://www.mapbender.org/index.php/WMC WMC} entry specified by wmc_id and user_id
+     *
+     * @param	integer		the user_id
+     * @param	string		the wmc_id
+     * @return	boolean		Did the query run succesfull? This does not necessarily mean that 
+     * 						an entry was deleted.
+     * @deprecated
+     */
+ 	function deleteWmc($wmc_id, $user_id){
+		$e = new mb_notice("administration->deleteWmc is deprecated, use wmc->delete instead!"); 
+		
+		$wmc = new wmc();
+		return $wmc->delete($wmc_id, $user_id);
+ 	}
+
+    /**
+     * inserts a gui with the specified gui_id, after checking the uniqueness of teh gui id.
+     *
+     * @uses administration::guiExists()
+     * @param 	string $guiId	the name and id of the gui to insert.
+     * @return 	boolean			could the gui be inserted?
+     */
+	function insertGui($guiId) {
+		if (!$this->guiExists($guiId)) {
+			$sql = "INSERT INTO gui VALUES ($1, $2, '', '1')";
+			$v = array($guiId,$guiId);
+			$t = array('s','s');
+			$res = db_prep_query($sql,$v,$t);
+			if ($res) {
+				return true;
+			}
+		}
+		return false;
+	}
+
+    /**
+     * deletes links between user and guis in gui_mb_user for a certain gui.
+     *
+     * @param string 	the gui name
+     * @return boolean 	could the sql be executed without errors. This does not 
+     * 					necessarily mean, that entries were deleted
+     */
+	function delAllUsersOfGui($guiId) {
+		$sql = "DELETE FROM gui_mb_user WHERE fkey_gui_id = $1 ";
+		$v = array($guiId);
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
+		if (!$res) {
+			return false;
+		}
+		else {
+			return true;
+		}
+	}
+
+    /**
+     * returns an array of WMS for a given user id
+     * @uses getGuisByOwner
+     * @param integer $user_id		the user id
+     * @return integer[] 			wms ids for the user
+     */
+	function getWmsByOwner($user_id){
+		$gui_list = $this->getGuisByOwner($user_id,true);
+		return $this->getWmsByOwnGuis($gui_list);
+	}
+
+    /**
+     * returns an array of WMS where the owner is the user with the passed user_id
+     * @param integer	the user id
+     * @return array 	wms ids for the user
+     */
+	function getWmsByWmsOwner($user_id){
+		$sql = "SELECT wms_id FROM wms WHERE wms_owner = $1";
+		$v = array($user_id);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$r = array();
+		while($row = db_fetch_array($res)){
+			array_push($r,$row["wms_id"]);
+		}
+		return $r;
+	}
+
+    /**
+     * returns an array of user which are associated with a wms
+     *
+     * @param integer	the wms id
+     * @return array	user_ids for the wms
+     */
+	function getUserByWms($wms_id){
+		$sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = $1 GROUP BY fkey_gui_id";
+		$v = array($wms_id);
+		$t = array('i');
+		$count=0;
+		$res = db_prep_query($sql,$v,$t);
+		while($row = db_fetch_array($res)){
+			$gui[$count] = $row["fkey_gui_id"];
+			$count++;
+		}
+		$c = 1;
+		$v = array();
+		$t = array();
+		if(count($gui)>0){
+			$sql = "(SELECT mb_user.mb_user_id FROM mb_user JOIN gui_mb_user ";
+			$sql .= "ON mb_user.mb_user_id = gui_mb_user.fkey_mb_user_id ";
+			$sql .= " WHERE gui_mb_user.fkey_gui_id IN (";
+			for($i=0; $i<count($gui); $i++){
+				if($i>0){ $sql .= ",";}
+				$sql .= "$".$c;
+				array_push($v,$gui[$i]);
+				array_push($t, 's');
+				$c++;
+			}
+			$sql .= ") GROUP BY mb_user.mb_user_id) UNION";
+			$sql .= "(SELECT mb_user.mb_user_id FROM gui_mb_group JOIN mb_user_mb_group ON   mb_user_mb_group.fkey_mb_group_id = gui_mb_group.fkey_mb_group_id     JOIN mb_user ";
+			$sql .= "ON mb_user.mb_user_id = mb_user_mb_group.fkey_mb_user_id ";
+			$sql .= " WHERE gui_mb_group.fkey_gui_id IN (";
+			for($i=0; $i<count($gui); $i++){
+				if($i>0){ $sql .= ",";}
+				$sql .= "$".$c;
+				array_push($v,$gui[$i]);
+				array_push($t, 's');
+				$c++;
+			}
+			$sql .= ") GROUP BY mb_user.mb_user_id )";
+			$user = array();
+			$res = db_prep_query($sql,$v,$t);
+			$cnt = 0;
+			while($row = db_fetch_array($res)){
+				$user[$cnt] = $row["mb_user_id"];
+				$cnt++;
+			}
+		}
+		return $user;
+	}
+
+    /**
+     * selects the WMS-title for a given wms id.
+     *
+     * @param integer 			the wms id
+     * @return string|boolean 	either the title of the wms as string or false when none exists
+     */
+	function getWmsTitleByWmsId($id){
+		$sql = "SELECT wms_title FROM wms WHERE wms_id = $1 GROUP BY wms_title";
+		$v = array($id);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$row = db_fetch_array($res);
+		if ($row) return $row["wms_title"]; else return false;
+	}
+
+    /**
+     * selects the Layer-title for a given layer id.
+     *
+     * @param integer			the wms id
+     * @return string|boolean	either the title of the wms as string or false when none exists
+     */
+	function getLayerTitleByLayerId($id){
+		$sql = "SELECT layer_title FROM layer WHERE layer_id = $1 GROUP BY layer_title";
+		$v = array($id);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$row = db_fetch_array($res);
+		if ($row) return $row["layer_title"]; else return false;
+	}
+
+    /**
+     * selects the WMC for a given wmc_id.
+     *
+     * @param integer			the wms id
+     * @return string|boolean	either the wmc as string or false when none exists
+     * @deprecated
+     */
+	function getWmcById($id){
+		$e = new mb_notice("administration->getWmcById is deprecated, use wmc->getDocument instead!"); 
+
+		$wmc = new wmc();
+		return $wmc->getDocument($id);
+	}
+
+    /**
+     * resets the login count of a given user to 0
+     * @param integer	the user id
+     * @return boolean 	could the login count be reseted?
+     */
+	function resetLoginCount($userId) {
+		// TODO: isn't mb_user_login_count a integer?
+        $sql = "UPDATE mb_user SET mb_user_login_count = '0' ";
+		$sql .= "WHERE mb_user_id = $1 ";
+		$v = array($userId);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		if (!$res) {
+			return false;
+		}
+		else {
+			return true;
+		}
+	}
+
+	function getUserIdByUserName($username){
+		$sql = "SELECT mb_user_id FROM mb_user ";
+		$sql .= "WHERE mb_user_name = $1 GROUP BY mb_user_id";
+		$v = array($username);
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
+		$row = db_fetch_array($res);
+		if ($row) return $row["mb_user_id"]; else return false;
+	}
+
+	function setUserAsGuiOwner($guiId, $userId) {
+		$sql = "UPDATE gui_mb_user SET mb_user_type = 'owner' ";
+		$sql .= "WHERE fkey_gui_id = $1 AND fkey_mb_user_id = $2 ";
+		$v = array($guiId,$userId);
+		$t = array('s','i');
+		$res = db_prep_query($sql,$v,$t);
+
+		if (!$res) {
+			return false;
+		}
+		else {
+			return true;
+		}
+ 	}
+
+	function getGuiIdByGuiName($guiTitle){
+		$sql = "SELECT gui_id FROM gui ";
+		$sql .= "WHERE gui_name = $1 GROUP BY gui_id";
+		$v = array($guiTitle);
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
+  		$count_g = 0;
+  		$array = array();
+		while($row = db_fetch_array($res)){
+			$array[$count_g] = $row["gui_id"];
+			$count_g++;
+		}
+		if ($count_g >0)	{
+			return $array;
+		}
+		else {
+			return false;
+		}
+ 	}
+
+	function getGuisByOwner($user_id,$ignore_public)
+	{
+		$sql_guis = "SELECT gui.gui_id FROM gui,gui_mb_user ";
+		$sql_guis .= "WHERE (gui.gui_id = gui_mb_user.fkey_gui_id AND 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 .= " AND gui_mb_user.mb_user_type = 'owner' GROUP BY gui.gui_id";
+		$sql_guis .= " ORDER by gui.gui_id";
+		$v = array($user_id);
+		$t = array('i');
+		$res_guis = db_prep_query($sql_guis,$v,$t);
+  		$count_g = 0;
+  		$arrayGuis = array();
+		while($row = db_fetch_array($res_guis)){
+			$arrayGuis[$count_g] = $row["gui_id"];
+			$count_g++;
+		}
+		return $arrayGuis;
+ 	}
+
+	/**
+	 * @deprecated
+	 */
+ 	function getWmcByOwner($user_id){
+		$e = new mb_notice("administration->getWmcByOwner is deprecated, use user->getWmcByOwner instead!"); 
+
+		$user = new User($user_id);
+		return $user->getWmcByOwner();
+ 	}
+
+	/**
+	 * @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){
+		if(count($array_gui_ids)>0){
+			$v = array();
+			$t = array();
+			$sql = "SELECT fkey_wms_id from gui_wms WHERE gui_wms.fkey_gui_id IN(";
+			for($i=0; $i<count($array_gui_ids); $i++){
+				if($i>0){ $sql .= ",";}
+				$sql .= "$".strval($i+1);
+				array_push($v, $array_gui_ids[$i]);
+				array_push($t, "s");
+			}
+			$sql .= ") GROUP BY fkey_wms_id ORDER BY fkey_wms_id";
+			$res = db_prep_query($sql,$v,$t);
+			$ownguis = array();
+			$i=0;
+			while($row = db_fetch_array($res)){
+				$ownguis[$i] = $row['fkey_wms_id'];
+				$i++;
+			}
+		}
+		return $ownguis;
+	}
+	
+	function getLayerByWms($wms_id){
+		$sql = "SELECT layer_id from layer WHERE fkey_wms_id = $1 AND layer_pos NOT IN ('0') GROUP BY layer_id, layer_title ORDER BY layer_title";
+		$v = array($wms_id);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$layer_id_array = array();
+		while($row = db_fetch_array($res)){
+			$layer_id_array[count($layer_id_array)] = $row['layer_id'];
+		}
+		return $layer_id_array;
+	}
+
+	function getWmsOwner($wms_id){
+		$sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = $1 GROUP BY fkey_gui_id";
+		$v = array($wms_id);
+		$t = array('i');
+		$count=0;
+		$res = db_prep_query($sql,$v,$t);
+		while($row = db_fetch_array($res)){
+			$gui[$count] = $row["fkey_gui_id"];
+			$count++;
+		}
+		$v = array();
+		$t = array();
+		if(count($gui)>0){
+			$sql = "SELECT mb_user.mb_user_id FROM mb_user JOIN gui_mb_user ";
+			$sql .= "ON mb_user.mb_user_id = gui_mb_user.fkey_mb_user_id WHERE";
+			$sql .= " gui_mb_user.fkey_gui_id IN (";
+			for($i=0; $i<count($gui); $i++){
+				if($i>0){ $sql .= ",";}
+				$sql .= "$".($i+1);
+				array_push($v,$gui[$i]);
+				array_push($t,'s');
+			}
+			$sql .= ")";
+			$sql .= " AND gui_mb_user.mb_user_type = 'owner' GROUP BY mb_user.mb_user_id";
+			$res = db_prep_query($sql,$v,$t);
+			$i=0;
+			$wmsowner = array();
+			while($row = db_fetch_array($res)){
+				$wmsowner[$i]=$row['mb_user_id'];
+				$i++;
+			}
+		}
+		return $wmsowner;
+	}
+
+	function insertUserAsGuiOwner($guiId, $userId){
+		$sql = "INSERT INTO gui_mb_user VALUES ($1, $2, 'owner')";
+		$v = array($guiId,$userId);
+		$t = array('s','i');
+		$res = db_prep_query($sql,$v,$t);
+		if (!$res) {
+			return false;
+		}
+		else {
+			return true;
+		}
+ 	}
+
+   	function checkModulePermission($arrayGuis, $modulePath, $column){
+   		$check = true;
+   		if($check == true){
+	   		$perm = false;
+	   		if(count($arrayGuis)>0){
+	   			$v = array();
+	   			$t = array();
+		   		$sql = "SELECT ".$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 .= ")";
+				$res = db_prep_query($sql,$v,$t);
+				$cnt = 0;
+				while($row = db_fetch_array($res)){
+					if(mb_strpos(stripslashes($row[$column]),$modulePath) !== false){
+						$perm = true;
+					}
+					$cnt++;
+				}
+	   		}
+			return $perm;
+   		}
+   		else{
+   			return true;
+   		}
+   	}
+
+
+	/**
+	 * 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");
+   		$res = db_prep_query($sql,$v,$t);
+   		if($row = db_fetch_array($res)){
+   			return $row["wms_owsproxy"];
+   		}
+   		else{
+   			return false;
+   		}
+   	}
+
+   	function setWMSOWSstring($wms_id, $status){
+   		$sql = "UPDATE wms SET wms_owsproxy = $1 WHERE wms_id = $2 ";
+   		$t = array("s","i");
+   		if($status == 'on'){
+   			$time = md5(microtime(1));
+			$v = array($time,$wms_id);
+   		}
+   		else{
+   			$v = array("",$wms_id);
+   		}
+   		$res = db_prep_query($sql,$v,$t);
+   	}
+	
+	/*
+	 * get the owsproxy-string of the current wfs
+	 * 
+	 * @param integer the wfs-id of the current wfs
+	 * @return mixed the owsproxy-string or false
+	 */
+	   	
+   	function getWfsOwsproxyString($wfs_id){
+   		$sql = "SELECT wfs_owsproxy FROM wfs WHERE wfs_id = $1 ";
+   		$v = array($wfs_id);
+   		$t = array("i");
+   		$res = db_prep_query($sql,$v,$t);
+   		if($row = db_fetch_array($res)){
+   			return $row["wfs_owsproxy"];
+   		}
+   		else{
+   			return false;
+   		}
+   	}
+   	
+	/*
+	 * sets or removes the owsproxy string of the current wfs
+	 * 
+	 * @param integer the wfs-id
+	 * @param boolean set (true) or remove (false) the owsproxy-string
+	 * 
+	 */
+   	function setWfsOwsproxyString($wfs_id, $status){
+   		$sql = "UPDATE wfs SET wfs_owsproxy = $1 WHERE wfs_id = $2 ";
+   		$t = array("s","i");
+   		if($status == true){
+   			$time = md5(microtime(1));
+			$v = array($time,$wfs_id);
+   		}
+   		else{
+   			$n = new mb_notice("removed owsproxy for wfs:".$wfs_id);
+   			$v = array("",$wfs_id);
+   		}
+   		
+   		$res = db_prep_query($sql,$v,$t);
+   		$newOwsString = $this->getWfsOwsproxyString($wfs_id);
+   		$n = new mb_notice("Class administration - setOWSString for wfs (".$wfs_id.") to: ". $this->getWfsOwsproxyString($wfs_id));
+   		return $newOwsString;
+   	}
+
+   	function checkURL($url){
+		$pos_qm = strpos($url,"?");
+		if($pos_qm > 0 && $pos_qm < (mb_strlen($url)-1) && mb_substr($url,(mb_strlen($url)-1)) != "&"){
+			$url = $url."&";
+			return $url;
+		}
+		else if($pos_qm === false){
+			return $url."?";
+		}
+		else{
+			return $url;
+		}
+	}
+	
+	function getModulPermission($userID,$guiID,$elementID){
+		$g = $this->getGuisByPermission($userID,true);
+		if(in_array($guiID,$g)){
+			$sql = "SELECT * FROM gui_element WHERE fkey_gui_id = $1 AND e_id = $2 ";
+			$v = array($guiID,$elementID);
+			$t = array('s','s');
+			$res = db_prep_query($sql,$v,$t);
+			if($row = db_fetch_array($res)){
+				return true;
+			}
+			else{
+				return false;
+			}
+		}
+		else{
+			return false;
+		}
+	}
+	
+	function getLayerPermission($wms_id, $layer_name, $user_id){
+		$layer_id = $this->getLayerIdByLayerName($wms_id,$layer_name);
+		$array_guis = $this->getGuisByPermission($user_id,true);
+		$v = array();
+		$t = array();
+		$sql = "SELECT * FROM gui_layer WHERE fkey_gui_id IN (";
+		$c = 1;
+		for($i=0; $i<count($array_guis); $i++){
+			if($i>0){ $sql .= ",";}
+			$sql .= "$".$c;
+			$c++;
+			array_push($v, $array_guis[$i]);
+			array_push($t, 's');
+		}
+		$sql .= ") AND fkey_layer_id = $".$c." AND gui_layer_status = 1";
+		array_push($v,$layer_id);
+		array_push($t,'i');
+		$res = db_prep_query($sql,$v,$t);
+		if($row = db_fetch_array($res)){
+			return true;
+		}
+		else{
+			return false;
+		}
+	}
+	
+	function getWmsPermission($wms_id, $user_id) {
+		$array_guis = $this->getGuisByPermission($user_id,true);
+		$v = array();
+		$t = array();
+		$sql = "SELECT * FROM gui_wms WHERE fkey_gui_id IN (";
+		$c = 1;
+		for($i=0; $i<count($array_guis); $i++){
+			if($i>0){ $sql .= ",";}
+			$sql .= "$".$c;
+			$c++;
+			array_push($v, $array_guis[$i]);
+			array_push($t, 's');
+		}
+		$sql .= ") AND fkey_wms_id = $".$c;
+		array_push($v,$wms_id);
+		array_push($t,'i');
+		$res = db_prep_query($sql,$v,$t);
+		if($row = db_fetch_array($res)){
+			return true;
+		}
+		else{
+			return false;
+		}
+	}
+	
+	function getLayerIdByLayerName($wms_id, $layer_name){
+		$sql = "SELECT layer_id FROM layer WHERE ";
+		$sql .= "fkey_wms_id = $1 AND layer_name = $2";
+		$v = array($wms_id,$layer_name);
+		$t = array('i','s');
+		$res = db_prep_query($sql,$v,$t);
+		if($row = db_fetch_array($res)){
+			return $row['layer_id'];
+		}
+		else{
+			return false;
+		}
+	}
+	
+	function getWmsIdByWmsGetmap($getmap) {
+		$sql = "SELECT wms_id FROM wms WHERE ";
+		$sql .= "wms_getmap LIKE $1 LIMIT 1";
+		$v = array($getmap."%");
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
+		if($row = db_fetch_array($res)){
+			return $row['wms_id'];
+		}
+		else{
+			return false;
+		}
+	}
+
+	function is_utf8_string($string) {
+	    if (is_array($string))
+	    {
+	        $enc = implode('', $string);
+	        return @!((ord($enc[0]) != 239) && (ord($enc[1]) != 187) && (ord($enc[2]) != 191));
+	    }
+	    else
+	    {
+	        return (utf8_encode(utf8_decode($string)) == $string);
+	    }  
+    /*
+    		return preg_match('%(?:
+		[\xC2-\xDF][\x80-\xBF]        # non-overlong 2-byte
+		|\xE0[\xA0-\xBF][\x80-\xBF]               # excluding overlongs
+		|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}      # straight 3-byte
+		|\xED[\x80-\x9F][\x80-\xBF]               # excluding surrogates
+		|\xF0[\x90-\xBF][\x80-\xBF]{2}    # planes 1-3
+		|[\xF1-\xF3][\x80-\xBF]{3}                  # planes 4-15
+		|\xF4[\x80-\x8F][\x80-\xBF]{2}    # plane 16
+		)+%xs', $string);
+	*/
+	}
+	
+	function is_utf8_xml($xml) {
+		return preg_match('/<\?xml[^>]+encoding="utf-8"[^>]*\?>/is', $xml);
+	}
+	
+	function is_utf8 ($data) {
+		return ($this->is_utf8_xml($data) || $this->is_utf8_string($data));
+	}
+	
+	function char_encode($data) {
+		if (CHARSET == "UTF-8") {
+			if (!$this->is_utf8($data)) {
+				$e = new mb_notice("Conversion: ISO-8859-1 to UTF-8");
+				return utf8_encode($data);
+			}
+		}
+		else {
+			if ($this->is_utf8($data)) {
+				$e = new mb_notice("Conversion: UTF-8 to ISO-8859-1");
+				return utf8_decode($data);
+			}
+		}
+		$e = new mb_notice("No conversion: is " . CHARSET);
+		return $data;
+	}
+
+	function char_decode($data) {
+		if (CHARSET == "UTF-8") {
+			if ($this->is_utf8($data)) {
+				$e = new mb_notice("Conversion: UTF-8 to ISO-8859-1");
+				return utf8_decode($data);
+			}
+		}
+		$e = new mb_notice("no conversion: is " . CHARSET);
+		return $data;
+	}
+	
+	/**
+	 * identifies the Featureservices where the current user is owner
+	 * 
+	 * @param integer 		userid the user-ID of the current user
+	 * @return integer[] 	the IDs of the featureservices
+	 */
+	 function getWfsByOwner($userid){
+	 	$sql = "SELECT wfs_id FROM wfs WHERE wfs_owner = $1";
+		$v = array($userid);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$r = array();
+		while($row = db_fetch_array($res)){
+			array_push($r,$row["wfs_id"]);
+		}
+		return $r;
+	 }
+	 
+	 /** 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){
+		$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

Added: branches/testbaudson_dev/lib/checkInput.php
===================================================================
--- branches/testbaudson_dev/lib/checkInput.php	                        (rev 0)
+++ branches/testbaudson_dev/lib/checkInput.php	2008-07-02 12:24:58 UTC (rev 2580)
@@ -0,0 +1,54 @@
+<?php
+# $Id: class_checkInput.php 1742 2007-10-26 10:16:07Z christoph $
+# http://www.mapbender.org/index.php/class_checkInput
+# 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 checkInput{
+	var $v;
+	function checkInput($q,$v,$t){
+		if(is_array($v) == false){
+			$v = array($v);
+		}
+		if(is_array($t) == false){
+			$t = array($t);
+		}
+		if(count($v) != count($t)){
+			$e = new mb_exception("array params and array types have a different count  in ".$_SERVER['SCRIPT_FILENAME'].": Sql: ".$q);
+		}
+		if(PREPAREDSTATEMENTS == true && SYS_DBTYPE == "pgsql"){
+			$this->v = $v;
+		}
+		else{
+			for($i=0; $i<count($v); $i++){
+				if($t[$i] == 's'){
+					$v[$i] = db_escape_string($v[$i]);
+				}
+				else if($t[$i] == 'i'){
+					if(preg_match("/w/",$v[$i])){
+						$e = new mb_exception($_SERVER['SCRIPT_FILENAME'].": Unable to parse integer in: ".$q." with: param ".$i.",".$v[i]);
+						die("wrong data type in sql:".$q);
+					}					
+				}
+				else if($t[$i] == 'd'){
+					
+				}	
+			}
+			$this->v = $v;
+		}		
+	}	
+}
+?>
\ No newline at end of file

Added: branches/testbaudson_dev/lib/connector.php
===================================================================
--- branches/testbaudson_dev/lib/connector.php	                        (rev 0)
+++ branches/testbaudson_dev/lib/connector.php	2008-07-02 12:24:58 UTC (rev 2580)
@@ -0,0 +1,213 @@
+<?php
+# $Id: class_connector.php 2073 2008-02-08 12:55:06Z verenadiewald $
+# http://www.mapbender.org/index.php/class_connector
+# 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__)."/../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/exception.php");
+
+mb_internal_encoding("UTF-8");
+
+/**
+ * Establishes a connection to a given URL (and loads the content).
+ * Supports HTTP (GET and POST), cURL and socket connections.
+ * 
+ * @class
+ */
+class connector {
+
+	var $file;	
+	private $connectionType;
+	private $httpType = "get";
+	private $httpVersion = "1.0";
+	private $httpPostData;
+	private $httpContentType;
+		
+	/**
+	 * @constructor
+	 * @param String url the URL that will be loaded (optional)
+	 */
+	public function __construct($url){
+		$this->set("connectionType", CONNECTION);
+		if ($url) {
+			$this->load($url);
+		}
+	}
+	
+	/**
+	 * Loads content from the given URL.
+	 */
+	public function load($url) {
+		switch ($this->connectionType) {
+			case "curl":
+				$this->file = $this->getCURL($url);
+				break;
+			case "http":
+				$this->file = $this->getHTTP($url);
+				break;
+			case "socket":
+				$this->file = $this->getSOCKET($url);
+				break;
+		}
+		if(!$this->file){
+			$e = new mb_exception("connector: unable to load: ".$url);
+			return false;
+		}
+		return $this->file;		
+	}
+	
+	/**
+	 * Sets the environment variables. The following can be set:
+	 * - connectionType ("http", "curl", "socket")
+	 * - httpType ("get", "post")
+	 * - etc.
+	 */
+	public function set ($key, $value) {
+		switch ($key) {
+			case "connectionType":
+				if ($this->isValidConnectionType($value)) {
+					$this->connectionType = $value;
+				}
+				break;
+				
+			case "httpVersion":
+				if (in_array($value, array("1.0", "1.1"))) {
+					$this->httpVersion = $value;
+				}
+				else {
+					$e = new mb_exception("class_connector.php: invalid http type '" . $value . "'");
+				}
+				break;
+							
+			case "httpType":
+				if (in_array(mb_strtoupper($value), array("POST", "GET"))) {
+					$this->httpType = $value;
+				}
+				else {
+					$e = new mb_exception("class_connector.php: invalid http type '" . $value . "'");
+				}
+				break;
+			
+			case "httpPostData":
+				$this->httpPostData = $value;
+				break;
+				
+			case "httpContentType":
+				if ($this->isValidHttpContentType($value)) {
+					$this->httpContentType = $value;
+				}
+				break;
+		}
+	}	
+	
+	private function isValidConnectionType ($value) {
+		if (in_array(mb_strtoupper($value), array("HTTP", "CURL", "SOCKET"))) {
+			return true;
+		}
+		else {
+			$e = new mb_exception("class_connector.php: invalid connection type '" . $value . "'");
+			return false;
+		}
+	}
+	
+	private function isValidHttpContentType ($value) {
+		$validHttpContentTypeArray = array("XML");
+		if (in_array(mb_strtoupper($value), $validHttpContentTypeArray)) {
+			switch ($value) {
+				case "XML":
+					$this->httpContentType = "application/xml";
+					break;
+			}
+			return true;
+		}
+		else {
+			$e = new mb_exception("class_connector.php: invalid HTTP content type '" . $value . "'");
+			return false;
+		}
+	}
+	
+	private function getCURL($url){
+		$ch = curl_init ($url);
+//		curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
+		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+		if(CONNECTION_PROXY != ""){
+			curl_setopt($ch, CURLOPT_PROXY,CONNECTION_PROXY.":".CONNECTION_PORT);	
+		}		
+		if(CONNECTION_PASSWORD != ""){
+			curl_setopt ($ch, CURLOPT_PROXYUSERPWD, CONNECTION_USER.':'.CONNECTION_PASSWORD);	
+		}
+		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
+		$file = curl_exec ($ch);
+		curl_close ($ch);
+
+		return $file;	
+	}
+
+	private function getHTTP($url){
+		if ($this->httpType == "get") {
+			return @file_get_contents($url);
+	 	}
+		else {
+			$urlComponentArray = parse_url($url);
+			$host = $urlComponentArray["host"];
+			$port = $urlComponentArray["port"]; 
+			if ($port == "") {
+				$port = 80;		
+			}	
+			$path = $urlComponentArray["path"];
+			$buf = '';
+		    $fp = fsockopen($host, $port);
+		    fputs($fp, "POST $path HTTP/".$this->httpVersion . "\r\n");
+		    fputs($fp, "Host: $host\r\n");
+		    if ($this->isValidHttpContentType($this->httpContentType)) {
+		    	fputs($fp,"Content-type: " . $this->httpContentType . "\r\n");
+		    }
+		    fputs($fp, "Content-length: " . strlen($this->httpPostData) . "\r\n");
+		    fputs($fp, "Connection: close\r\n\r\n");
+		    fputs($fp, $this->httpPostData);
+		    $xmlstr = false;
+		    while (!feof($fp)) {
+		    	$content = fgets($fp,4096);
+		    	if( strpos($content, '<?xml') === 0){
+		    		$xmlstr = true;
+		    	}
+		    	if($xmlstr == true){
+		    		$buf .= $content;
+		    	}
+			}
+		    fclose($fp);
+		    return $buf;			
+		}
+	}
+
+	private function getSOCKET($url){
+		$r = "";
+		$fp = fsockopen (CONNECTION_PROXY, CONNECTION_PORT, $errno, $errstr, 30);
+		if (!$fp) {
+			echo "$errstr ($errno)<br />\n";
+		} 
+		else {
+			fputs ($fp, "GET ".$url." HTTP/1.0\r\n\r\n");
+			while (!feof($fp)) {
+				$r .= fgets($fp,4096);
+			}
+			fclose($fp);
+			return $r;
+		}
+	}
+}
+?>
\ No newline at end of file

Added: branches/testbaudson_dev/lib/exception.php
===================================================================
--- branches/testbaudson_dev/lib/exception.php	                        (rev 0)
+++ branches/testbaudson_dev/lib/exception.php	2008-07-02 12:24:58 UTC (rev 2580)
@@ -0,0 +1,42 @@
+<?php
+
+# $Id: class_mb_exception.php 1950 2008-01-04 16:33:40Z christoph $
+# http://www.mapbender.org/index.php/class_mb_exception.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__)."/log.php");
+
+/**
+ * Logs messages to a specified file, for example "../log/mb_error_log_<date>.log"
+ * 
+ * @package exceptionHandling
+ */
+class mb_exception extends mb_log {
+
+	/**
+	 * @param	string $message		message that is being logged
+	 */
+	public function __construct ($message) {
+		return $this->mb_log("ERROR: " . $message, $this->level);
+	}
+
+	/**
+	 * @var string a description of the log level
+	 */
+	private $level = "error";
+}
+?>
\ No newline at end of file

Added: branches/testbaudson_dev/lib/json.php
===================================================================
--- branches/testbaudson_dev/lib/json.php	                        (rev 0)
+++ branches/testbaudson_dev/lib/json.php	2008-07-02 12:24:58 UTC (rev 2580)
@@ -0,0 +1,81 @@
+<?php
+# $Id:class_json.php 2406 2008-04-23 15:59:31Z christoph $
+# 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__)."/exception.php");
+
+define("JSON_PEAR", "json_pear");
+define("JSON_NATIVE", "json_native");
+
+if (!function_exists("json_encode")) {
+	require_once(dirname(__FILE__)."/../ext/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 Services_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 Services_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

Added: branches/testbaudson_dev/lib/log.php
===================================================================
--- branches/testbaudson_dev/lib/log.php	                        (rev 0)
+++ branches/testbaudson_dev/lib/log.php	2008-07-02 12:24:58 UTC (rev 2580)
@@ -0,0 +1,143 @@
+<?php
+
+# $Id: class_mb_log.php 2406 2008-04-23 15:59:31Z christoph $
+# http://www.mapbender.org/index.php/class_mb_exception.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__)."/../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/notice.php");
+require_once(dirname(__FILE__)."/warning.php");
+require_once(dirname(__FILE__)."/exception.php");
+
+/**
+ * @package exceptionHandling
+ */
+abstract class mb_log {
+	
+	/**
+	 * Appends a message to a given log file.
+	 * 
+	 * @param	string $n		the message that is being logged.
+	 * @param	string $level	the log level of the message.
+	 * @return	bool			true if the logging succeded; else false.
+	 */
+	protected function mb_log ($n, $level) {
+		if (!isset($this->mb_log_level)) {
+			$n = "class_mb_exception: please set LOG_LEVEL in mapbender.conf" . $n;
+		}
+		if ($this->isValidLevel($level)) {
+			if (is_dir($this->dir)) {
+				$logfile = $this->dir . $this->filename_prefix . date("Y_m_d") . ".log";
+				if ($h = fopen($logfile,"a")) {
+					$content = date("Y.m.d, H:i:s") . "," . $n .chr(13).chr(10);
+					if(!fwrite($h,$content)){
+						$this->result = false;
+						$this->message = "Unable to write " . $logfile;
+						return false;
+					}
+					fclose($h);
+					$this->result = true;
+					$this->message = "Successful.";
+					return true;
+				}
+				else {
+					$this->result = false;
+					$this->message = "Unable to open or generate " . $logfile;
+					return false;
+				}
+			}
+			else {
+				$this->result = false;
+				$this->message = "Directory " . $this->dir . " is not valid.";
+				return false;
+			}
+		}
+		else {
+			$this->result = false;
+			$this->message = "Log level '" . $level . "' is not valid or logging is disabled in mapbender.conf.";
+			return false; 
+		}
+	}
+
+	/**
+	 * Retrieves the index of the level in the array of available levels.
+	 * By this, we can find out if the message is eligable for logging.
+	 * 
+	 * @param	string $level			the log level of the message
+	 * @param	string[] $levelArray	an array of available levels
+	 * @return	mixed					false, if the level is not available; else 
+	 * 									the index of the level in the log level array
+	 */
+	protected function indexOf ($level, $levelArray) {
+		$index = false;
+		for ($i=0; $i < count($levelArray); $i++) {
+			if ($levelArray[$i] == $level) {
+				$index = $i;
+			}
+		}
+		return $index;
+	}
+
+	/**
+	 * Checks if the message will be logged. Example: Log level of the message is "warning",
+	 * but the log level set in 
+	 * {@link http://www.mapbender.org/index.php/Mapbender.conf#Mapbender_error_logging mapbender.conf}
+	 * is "off", then the message will not be logged.
+	 * 
+	 * @param	string $level	the log level of the message that is being logged.
+	 * @return	bool			true if the message will be logged; else false.
+	 */
+	protected function isValidLevel ($level) {
+		$log_level_array = explode(",", $this->log_levels);
+		$isValid = in_array($level, $log_level_array);
+		$isAppropriate = ($this->indexOf($level, $log_level_array) <= $this->indexOf($this->mb_log_level, $log_level_array));
+		return $isValid && $isAppropriate;
+	}
+	
+	/**
+	 * @var	string	a comma-separated list of available log levels, see 
+	 * 				{@link http://www.mapbender.org/index.php/Mapbender.conf#Mapbender_error_logging mapbender.conf}.
+	 */
+	protected $log_levels = LOG_LEVEL_LIST;
+
+	/**
+	 * @var	string	the selected log level, see 
+	 * 				{@link http://www.mapbender.org/index.php/Mapbender.conf#Mapbender_error_logging mapbender.conf}.
+	 */
+	protected $mb_log_level = LOG_LEVEL;	
+
+	/**
+	 * @var	string	the path to the log directory
+	 */
+	protected $dir = "../../log/";
+
+	/**
+	 * @var	string	the prefix of the logs' file name
+	 */
+	protected $filename_prefix = "mb_error_";
+
+	/**
+	 * @var	bool	true if the logging succeeded; else false.
+	 */
+	public $result = false;
+
+	/**
+	 * @var	string	if the logging did not succeed, this contains an error message.
+	 */
+	public $message = "";
+}
+?>
\ No newline at end of file

Added: branches/testbaudson_dev/lib/notice.php
===================================================================
--- branches/testbaudson_dev/lib/notice.php	                        (rev 0)
+++ branches/testbaudson_dev/lib/notice.php	2008-07-02 12:24:58 UTC (rev 2580)
@@ -0,0 +1,40 @@
+<?php
+
+# $Id: class_mb_notice.php 1950 2008-01-04 16:33:40Z christoph $
+# http://www.mapbender.org/index.php/class_mb_exception.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__)."/log.php");
+
+/**
+ * @package exceptionHandling
+ */
+class mb_notice extends mb_log {
+
+	/**
+	 * @param	string $message		message that is being logged
+	 */
+	public function __construct ($message) {
+		return $this->mb_log("Notice: " . $message, $this->level);
+	}
+
+	/**
+	 * @var string a description of the log level
+	 */
+	private $level = "notice";
+}
+?>
\ No newline at end of file

Added: branches/testbaudson_dev/lib/user.php
===================================================================
--- branches/testbaudson_dev/lib/user.php	                        (rev 0)
+++ branches/testbaudson_dev/lib/user.php	2008-07-02 12:24:58 UTC (rev 2580)
@@ -0,0 +1,159 @@
+<?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__)."/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;
+	}	
+	
+	/**
+	 * @return String the ID of this user
+	 */
+	public function __toString () {
+		return (string) $this->id;	
+	}
+	
+	/**
+	 * 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;
+	}
+	
+	/**
+	 * Returns all WMCs that this user owns
+	 * 
+	 * @return integer[] an array of WMC ids; ids from table mb_user_wmc
+	 */
+	public function getWmcByOwner () {
+		$sql = "SELECT wmc_id FROM mb_user_wmc ";
+		$sql .= "WHERE fkey_user_id = $1 GROUP BY wmc_id";
+		$v = array($this->id);
+		$t = array("i");
+		$res_wmc = db_prep_query($sql, $v, $t);
+
+  		$wmcArray = array();
+		while($row = db_fetch_array($res_wmc)){
+			array_push($wmcArray, $row["wmc_id"]);
+		}
+		return $wmcArray;
+	}
+}
+?>
\ No newline at end of file

Added: branches/testbaudson_dev/lib/warning.php
===================================================================
--- branches/testbaudson_dev/lib/warning.php	                        (rev 0)
+++ branches/testbaudson_dev/lib/warning.php	2008-07-02 12:24:58 UTC (rev 2580)
@@ -0,0 +1,40 @@
+<?php
+
+# $Id: class_mb_warning.php 1950 2008-01-04 16:33:40Z christoph $
+# http://www.mapbender.org/index.php/class_mb_exception.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__)."/log.php");
+
+/**
+ * @package exceptionHandling
+ */
+class mb_warning extends mb_log {
+	
+	/**
+	 * @param	string $message		message that is being logged
+	 */
+	public function __construct ($message) {
+		return $this->mb_log("Warning: " . $message, $this->level);
+	}
+
+	/**
+	 * @var string a description of the log level
+	 */
+	private $level = "warning";
+}
+?>
\ No newline at end of file

Added: branches/testbaudson_dev/lib/wms.php
===================================================================
--- branches/testbaudson_dev/lib/wms.php	                        (rev 0)
+++ branches/testbaudson_dev/lib/wms.php	2008-07-02 12:24:58 UTC (rev 2580)
@@ -0,0 +1,2027 @@
+<?php
+# $Id: class_wms.php 2541 2008-06-23 15:59:25Z christoph $
+# http://www.mapbender.org/index.php/class_wms
+# 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.
+
+include_once(dirname(__FILE__)."/../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/connector.php");
+require_once(dirname(__FILE__)."/user.php");
+require_once(dirname(__FILE__)."/exception.php");
+require_once(dirname(__FILE__)."/administration.php");
+
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
+  
+class wms {
+	var $lastURL;
+	var $wms_id;
+	var $wms_status;
+	var $wms_version;
+	var $wms_title;
+	var $wms_abstract;
+	var $wms_getcapabilities;
+	var $wms_getcapabilities_doc;
+	var $wms_getmap;
+	var $wms_getfeatureinfo;
+	var $wms_getlegendurl;
+	var $wms_upload_url;
+	  
+	var $fees;
+	var $accessconstraints;
+	var $contactperson;
+	var $contactposition;
+	var $contactorganization;
+	var $address;
+	var $city;
+	var $stateorprovince;
+	var $postcode;
+	var $country;
+	var $contactvoicetelephone;
+	var $contactfacsimiletelephone;
+	var $contactelectronicmailaddress;
+	  
+	var $wms_keyword = array();
+	var $data_type = array(); 
+	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;
+	  
+	function wms() {
+	} 
+
+	function createOlObjFromWMS($base){
+	 	if(!$this->wms_title || $this->wms_title == ""){
+			echo "alert('Error: no valid capabilities-document !!');";
+			die; exit;
+		}
+		// wms_title and abstract have previously been urlencoded
+		// this solution may not yet be the ultimate one
+		
+		$add_wms_string = "var wms_".$this->wms_id." = new OpenLayers.Layer.WMS.Untiled(" .
+				"'" . addslashes($this->wms_title) . "'," .
+				"'" . $this->wms_getmap ."'," ."{layers:'";
+				for($i=1;$i<count($this->objLayer);$i++){
+					$add_wms_string .= addslashes($this->objLayer[$i]->layer_name);
+					if($i!=count($this->objLayer)-1)
+						$add_wms_string .= ",";
+				}
+				$add_wms_string .= "', transparent: 'true'";
+				$add_wms_string .= ",format: '".$this->gui_wms_mapformat."'});\n";
+				if($base)
+					$add_wms_string .= 	"wms_".$this->wms_id.".isBaseLayer=true;\n";
+				$add_wms_string .= 	"wms_".$this->wms_id.".setVisibility(".($this->gui_wms_visible=="1"?"true":"false").");\n";
+				$add_wms_string .= "ol_map.addLayer(wms_".$this->wms_id.");\n";
+		echo $add_wms_string;
+	}	
+	
+	/**
+	 * Compares this WMS to another WMS.
+	 * 
+	 * @return boolean false, if
+	 * 					- the capabilities URLs don't match
+	 * 					- the layer count is different
+	 * 					- the layer names are different
+	 * 
+	 * @param $anotherWms wms this is just another WMS object
+	 */
+	public function equals ($anotherWms) {
+		// If the getMap URLs are not equal, the WMS are not equal.
+		if ($this->wms_getmap != $anotherWms->wms_getmap) {
+//			$e = new mb_notice($this . " != " . $anotherWms . " (getMap URL)");
+			return false;
+		}
+
+		// If the layer count is different, the WMS are not equal.
+		if (count($this->objLayer) != count($anotherWms->objLayer)) {
+//			$e = new mb_notice($this . " != " . $anotherWms . " (layer count: " . count($this->objLayer) . ":" . count($anotherWms->objLayer). ")");
+			return false;
+		}
+		
+		// If the layer names are different, the WMS are not equal.
+		for ($i = 0; $i < count($this->objLayer); $i++) {
+			$name1 = $this->objLayer[$i]->layer_name;
+			$name2 = $anotherWms->objLayer[$i]->layer_name;
+			
+			if ($name1 != $name2) {
+//				$e = new mb_notice($this . " != " . $anotherWms . " (layer names, " . $name1 . " vs. " . $name2 . ")");
+				return false;
+			}
+		}
+//		$e = new mb_notice($this . " == " . $anotherWms);
+		return true;
+	}  
+	
+	/**
+	 * The other WMS must be the same as this WMS, but with different
+	 * application settings. These application settings are copied,
+	 * the local settings are overwritten.
+	 * 
+	 * @return boolean true if the settings could be copied; false 
+	 * 					when an error occured.
+	 * @param $anotherWms wms The same WMS with possibly other settings
+	 */
+/*
+	public function copyConfiguration ($anotherWms) {
+		if (!$this->equals($anotherWms)) {
+			$e = new mb_exception("class_wms.php: copyConfiguration(): parameters cannot be copied, it's a different WMS.");
+			return false;
+		}
+		for ($i = 0; $i < count($this->objLayer); $i++) {
+			$myCurrentLayer = $this->objLayer[$i];
+			$theirCurrentLayer = $anotherWms->objLayer[$i];
+
+			$myCurrentLayer->gui_layer_selectable = $theirCurrentLayer->gui_layer_selectable;
+			$myCurrentLayer->gui_layer_visible    = $theirCurrentLayer->gui_layer_visible;
+			$myCurrentLayer->gui_layer_queryable  = $theirCurrentLayer->gui_layer_queryable;
+			$myCurrentLayer->gui_layer_querylayer = $theirCurrentLayer->gui_layer_querylayer;
+			$myCurrentLayer->gui_layer_style      = $theirCurrentLayer->gui_layer_style;
+		}
+	}
+*/	
+	
+	/**
+	 * Removes duplicate WMS from an array of WMS. To find duplicates,
+	 * two WMS are compared via equals().
+	 * 
+	 * @return wms[]
+	 * @param $wmsArray wms[]
+	 */
+	public static function merge ($wmsArray) {
+		$e = new mb_notice("before: " . implode(", ", $wmsArray));
+		if (!is_array($wmsArray)) {
+			$e = new mb_exception("class_wms.php: merge(): parameter is NOT an array.");
+			return array();
+		}
+		if (count($wmsArray) == 0) {
+			$e = new mb_exception("class_wms.php: merge(): parameter is an EMPTY array.");
+			return array();
+		}
+		
+		$newWmsArray = array();
+		
+		while (count($wmsArray) > 0) {
+			$currentWms = array_pop($wmsArray);
+			
+			$isNewWms = true;
+
+			if (get_class($currentWms) != "wms") {
+				$e = new mb_exception("class_wms.php: merge(): current WMS is not a WMS object, but a " . get_class($currentWms));
+			}
+			else {
+				for ($i = 0; $i < count($newWmsArray) && $isNewWms; $i++) {
+					if ($currentWms->equals($newWmsArray[$i])) {
+						$isNewWms = false;
+					}
+				}
+				if ($isNewWms) {
+//					$e = new mb_notice("adding WMS " . $currentWms);
+					array_push($newWmsArray, $currentWms);
+				}
+			}
+		}
+		// reversal of the array, because the elements were popped 
+		// from another array before.
+//		$e = new mb_notice("after: " . implode(", ", array_reverse($newWmsArray)));
+		return array_reverse($newWmsArray);
+	}
+	
+	public function __toString () {
+		return $this->wms_title;
+	}
+	
+	function createObjFromXML($url){
+	
+		$x = new connector($url);
+		$data = $x->file;
+		
+		if(!$data){
+			$this->wms_status = false;
+			return false;
+		}
+		else {
+			$this->wms_status = true;
+		}
+			
+		$values = null;
+		$tags = null;
+		$admin = new administration();
+		$this->wms_getcapabilities_doc = $admin->char_encode($data);
+		$this->wms_upload_url = $url;
+		
+		$this->wms_id = "";
+		$parser = xml_parser_create("");
+		xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
+		xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
+		xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
+		xml_parse_into_struct($parser,$this->wms_getcapabilities_doc,$values,$tags);
+
+		$code = xml_get_error_code($parser);
+		if ($code) {
+			$line = xml_get_current_line_number($parser); 
+			$mb_exception = new mb_exception(xml_error_string($code) .  " in line " . $line);
+		}
+		
+		xml_parser_free($parser);
+		
+		$section = null;
+		$format = null;
+		$cnt_format = 0;
+		$parent = array();
+		$myParent = array();
+		$cnt_layer = -1;
+		$request = null; 
+		$layer_style = array();
+		$cnt_styles = -1;
+		
+		foreach ($values as $element) {
+			if(mb_strtoupper($element[tag]) == "WMT_MS_CAPABILITIES" && $element[type] == "open"){
+				$this->wms_version = $element[attributes][version];
+			}
+			if(mb_strtoupper($element[tag]) == "TITLE" && $element[level] == '3'){
+				$this->wms_title = $this->stripEndlineAndCarriageReturn($element[value]);
+			}
+			if(mb_strtoupper($element[tag]) == "ABSTRACT" && $element[level] == '3'){
+				$this->wms_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
+			}
+			if(mb_strtolower($element[tag]) == "fees"){
+				$this->fees = $element[value];
+			}
+			if(mb_strtolower($element[tag]) == "accessconstraints"){
+				$this->accessconstraints = $element[value];
+			}
+			if(mb_strtolower($element[tag]) == "contactperson"){
+				$this->contactperson = $element[value];
+			}
+			if(mb_strtolower($element[tag]) == "contactposition"){
+				$this->contactposition = $element[value];
+			}
+			if(mb_strtolower($element[tag]) == "contactorganization"){
+				$this->contactorganization = $element[value];
+			}
+			if(mb_strtolower($element[tag]) == "address"){
+				$this->address = $element[value];
+			}
+			if(mb_strtolower($element[tag]) == "city"){
+				$this->city = $element[value];
+			}
+			if(mb_strtolower($element[tag]) == "stateorprovince"){
+				$this->stateorprovince = $element[value];
+			}
+			if(mb_strtolower($element[tag]) == "postcode"){
+				$this->postcode = $element[value];
+			}
+			if(mb_strtolower($element[tag]) == "country"){
+				$this->country = $element[value];
+			}
+			if(mb_strtolower($element[tag]) == "contactvoicetelephone"){
+				$this->contactvoicetelephone = $element[value];
+			}
+			if(mb_strtolower($element[tag]) == "contactfacsimiletelephone"){
+				$this->contactfacsimiletelephone = $element[value];
+			}
+			if(mb_strtolower($element[tag]) == "contactelectronicmailaddress"){
+				$this->contactelectronicmailaddress = $element[value];
+			}
+	  		if(mb_strtolower($element[tag]) == "keyword" && $section != 'layer'){
+				$this->wms_keyword[count($this->wms_keyword)] = $element[value];
+			}
+			
+			/*map section*/
+			if($this->wms_version == "1.0.0"){
+		 		if(mb_strtoupper($element[tag]) == "MAP" && $element[type] == "open"){
+					$section = "map";
+				}
+				if($section == "map" && mb_strtoupper($element[tag]) == "GET"){
+					$this->wms_getmap = $element[attributes][onlineResource];
+				}
+				if($section == "map" && mb_strtoupper($element[tag]) == "FORMAT" && $element[type] == "open"){
+					$format = "map";
+				}
+				if(mb_strtoupper($element[tag]) != "FORMAT" && $section == "map" && $format == "map"){
+					$this->data_type[$cnt_format] = "map";
+					$this->data_format[$cnt_format] = trim($element[tag]);
+					$cnt_format++;
+				}
+				if(mb_strtoupper($element[tag]) == "FORMAT" && $element[type] == "close"){
+					$format = "";
+				}
+				if(mb_strtoupper($element[tag]) == "MAP" && $element[type] == "close"){
+					$section = "";
+				}
+			}
+			else{
+				if(mb_strtoupper($element[tag]) == "GETMAP" && $element[type] == "open"){
+					$section = "map";
+				}
+				if($section == "map" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "open"){
+					$request = "get";
+				}
+				if($section == "map" && $request == "get" && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+					$this->wms_getmap = $element[attributes]["xlink:href"];
+				}
+				if($section == "map" && mb_strtoupper($element[tag]) == "FORMAT"){
+					$this->data_type[$cnt_format] = "map";
+					$this->data_format[$cnt_format] = trim($element[value]);
+					$cnt_format++;
+				}
+				if($section == "map" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "close"){
+					$request = "";
+				}
+				if(mb_strtoupper($element[tag]) == "GETMAP" && $element[type] == "close"){
+					$section = "";
+				}
+			}
+			/*capabilities section*/
+			if($this->wms_version == "1.0.0"){
+				if(mb_strtoupper($element[tag]) == "CAPABILITIES" && $element[type] == "open"){
+					$section = "capabilities";
+				}
+				if($section == "capabilities" && mb_strtoupper($element[tag]) == "GET"){
+					$this->wms_getcapabilities = $element[attributes][onlineResource];
+				}
+				if(mb_strtoupper($element[tag]) == "CAPABILITIES" && $element[type] == "close"){
+					$section = "";
+				}
+			}
+			else{
+				if(mb_strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "open"){
+					$section = "capabilities";
+				}
+				if($section == "capabilities" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "open"){
+					$request = "get";
+				}
+				if($section == "capabilities" && $request == "get" && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+					$this->wms_getcapabilities = $element[attributes]["xlink:href"];
+				}
+				if($section == "capabilities" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "close"){
+					$request = "";
+				}
+				if(mb_strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "close"){
+					$section = "";
+				}
+			}
+			/*featureInfo section*/
+			if($this->wms_version == "1.0.0"){
+				if(mb_strtoupper($element[tag]) == "FEATUREINFO" && $element[type] == "open"){
+					$section = "featureinfo";
+				}
+				if($section == "featureinfo" && mb_strtoupper($element[tag]) == "GET"){
+					$this->wms_getfeatureinfo = $element[attributes][onlineResource];
+				}
+				if($section == "featureinfo" && mb_strtoupper($element[tag]) == "FORMAT" && $element[type] == "open"){
+					$format = "featureinfo";
+				}
+				if(mb_strtoupper($element[tag]) != "FORMAT" && $section == "featureinfo" && $format == "featureinfo"){
+					$this->data_type[$cnt_format] = "featureinfo";
+					$this->data_format[$cnt_format] = trim($element[tag]);
+					$cnt_format++;
+				}
+				if(mb_strtoupper($element[tag]) == "FORMAT" && $element[type] == "close"){
+					$format = "";
+				}
+				if(mb_strtoupper($element[tag]) == "FEATUREINFO" && $element[type] == "close"){
+					$section = "";
+				}
+			}
+			else{
+				if(mb_strtoupper($element[tag]) == "GETFEATUREINFO" && $element[type] == "open"){
+					$section = "featureinfo";
+				}
+				if($section == "featureinfo" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "open"){
+					$request = "get";
+				}
+				if($section == "featureinfo" && $request == "get" && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+					$this->wms_getfeatureinfo = $element[attributes]["xlink:href"];
+				}
+				if($section == "featureinfo" && mb_strtoupper($element[tag]) == "FORMAT"){
+					$this->data_type[$cnt_format] = "featureinfo";
+					$this->data_format[$cnt_format] = trim($element[value]);
+					$cnt_format++;
+				}
+				if($section == "featureinfo" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "close"){
+					$request = "";
+				}
+				if(mb_strtoupper($element[tag]) == "GETFEATUREINFO" && $element[type] == "close"){
+					$section = "";
+				}
+			}
+			/*exception section*/
+			if($this->wms_version == "1.0.0"){
+				if(mb_strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "open"){
+					$section = "exception";
+				}
+				if($section == "exception" && mb_strtoupper($element[tag]) == "FORMAT" && $element[type] == "open"){
+					$format = "exception";
+				}
+				if(mb_strtoupper($element[tag]) != "FORMAT" && $section == "exception" && $format == "exception"){
+					$this->data_type[$cnt_format] = "exception";
+					$this->data_format[$cnt_format] = trim($element[tag]);
+					$cnt_format++;
+				}
+				if($section == "exception" && mb_strtoupper($element[tag]) == "FORMAT" && $element[type] == "close"){
+					$format = "";
+				}
+				if(mb_strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "close"){
+					$section = "";
+				}
+			}
+			else{
+				if(mb_strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "open"){
+					$section = "exception";
+				}
+				if($section == "exception" && mb_strtoupper($element[tag]) == "FORMAT"){
+					$this->data_type[$cnt_format] = "exception";
+					$this->data_format[$cnt_format] = trim($element[value]);
+					$cnt_format++;
+				}
+				if(mb_strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "close"){
+					$section = "";
+				}
+			}
+	      /*legend section*/
+	      if($this->wms_version == "1.0.0"){
+	      
+	      }
+	      else{
+	        if(mb_strtoupper($element[tag]) == "GETLEGENDGRAPHIC" && $element[type] == "open"){
+				$section = "legend";
+			}
+	        if($section == "legend" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "open"){
+				$request = "get";
+			}
+			if($section == "legend" && $request == "get" && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+				$this->wms_getlegendurl = $element[attributes]["xlink:href"];
+			}
+	        if($section == "legend" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "close"){
+				$request = "";
+			}
+			if(mb_strtoupper($element[tag]) == "GETLEGENDGRAPHIC" && $element[type] == "close"){
+				$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";
+				if ($element[type] == "open") {
+					$cnt_epsg = -1;
+					$cnt_layer++;
+					$parent[$element[level]+1] = $cnt_layer;
+					$myParent[$cnt_layer]= $parent[$element[level]];
+					$this->addLayer($cnt_layer,$myParent[$cnt_layer]);
+					$this->objLayer[$cnt_layer]->layer_queryable = $element[attributes][queryable];
+				}
+				if ($element[type] == "close") {
+				
+				}
+			}
+			/* attribution */
+			if(mb_strtoupper($element[tag]) == "ATTRIBUTION"){
+				if ($element[type] == "open") {
+					$section = "attribution";
+				}
+				if ($element[type] == "close") {
+					$section = "layer";
+				}
+			}
+			/* styles */
+			if(mb_strtoupper($element[tag]) == "STYLE"){
+				$section = "style";
+				if($cnt_layer != $layer_style){
+					$layer_style = $cnt_layer;
+					$cnt_styles = -1;
+				}
+				if ($element[type] == "open") {
+					$cnt_styles++;
+				}
+				if ($element[type] == "close") {
+					$section = "layer";
+				}
+			}
+			if($section == "style"){
+				if(mb_strtoupper($element[tag]) == "NAME"){
+					$this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["name"] = $element[value];
+				}
+				if(mb_strtoupper($element[tag]) == "TITLE"){
+					$this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["title"] = $element[value];
+				}
+	      		if(mb_strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "open"){
+					$legendurl = true;
+				}
+				if($legendurl && mb_strtoupper($element[tag]) == "FORMAT"){
+					$this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["legendurlformat"] = $element[value];
+				}
+				if($legendurl && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+					$this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["legendurl"] = $element[attributes]["xlink:href"];
+				}
+			    if(mb_strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "close"){
+					$legendurl = false;
+				}   
+			}
+			/* end of styles */
+			if($section == "layer"){
+				if(mb_strtoupper($element[tag]) == "NAME"){
+					$this->objLayer[$cnt_layer]->layer_name = $element[value];
+				}
+				if(mb_strtoupper($element[tag]) == "TITLE"){
+					$this->objLayer[$cnt_layer]->layer_title = $this->stripEndlineAndCarriageReturn($element[value]);
+				}
+				if(mb_strtoupper($element[tag]) == "ABSTRACT"){
+					$this->objLayer[$cnt_layer]->layer_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
+				}
+				if(mb_strtoupper($element[tag]) == "KEYWORD"){
+					array_push($this->objLayer[$cnt_layer]->layer_keyword, trim($element[value]));
+				}
+	      		if(mb_strtoupper($element[tag]) == "DATAURL" && $element[type] == "open"){
+					$dataurl = true;
+				}
+				if($dataurl && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+					$this->objLayer[$cnt_layer]->layer_dataurl_href = $element[attributes]["xlink:href"];
+				}
+			    if(mb_strtoupper($element[tag]) == "DATAURL" && $element[type] == "close"){
+					$dataurl = false;
+				}   
+				
+				if(mb_strtoupper($element[tag]) == "METADATAURL" && $element[type] == "open"){
+					$metadataurl = true;
+				}
+				if($metadataurl && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+					$this->objLayer[$cnt_layer]->layer_metadataurl = $element[attributes]["xlink:href"];
+				}
+			    if(mb_strtoupper($element[tag]) == "METADATAURL" && $element[type] == "close"){
+					$metadataurl = false;
+				}   
+				
+				if(mb_strtoupper($element[tag]) == "SRS"){
+	  				$this->objLayer[$cnt_layer]->wms_srs1 = $element[value];
+					// unique srs only, see http://www.mapbender.org/index.php/Arrays_with_unique_entries
+					$this->wms_srs = array_keys(array_flip(explode(" ", $this->objLayer[0]->wms_srs1)));  				
+				}						      
+				if(mb_strtoupper($element[tag]) == "LATLONBOUNDINGBOX"){
+					$cnt_epsg++;
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["epsg"] = "EPSG:4326";
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["minx"] = $element[attributes][minx];
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["miny"] = $element[attributes][miny];
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxx"] = $element[attributes][maxx];
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxy"] = $element[attributes][maxy];
+				}
+				if(mb_strtoupper($element[tag]) == "BOUNDINGBOX" && $element[attributes][SRS] != "EPSG:4326"){
+					$cnt_epsg++;
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["epsg"] = $element[attributes][SRS];
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["minx"] = $element[attributes][minx];
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["miny"] = $element[attributes][miny];
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxx"] = $element[attributes][maxx];
+					$this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxy"] = $element[attributes][maxy];
+					// a default epsg for mapbender
+					if($cnt_layer == 0 && $this->default_epsg == 0 && mb_strlen(trim($element[attributes][SRS]))>= 10){
+						$this->default_epsg = $cnt_epsg;
+					}
+				}
+				if(mb_strtoupper($element[tag]) == "SCALEHINT"){
+					if($element[attributes][max]>1000) $max = 0; else $max = $element[attributes][max]; 	
+					if($element[attributes][min]>1000) $min = 0; else $min = $element[attributes][min]; 	
+					$this->objLayer[$cnt_layer]->layer_minscale = round(($min * 2004.3976484406788493955738891127));
+					$this->objLayer[$cnt_layer]->layer_maxscale = round(($max * 2004.3976484406788493955738891127));
+				}
+			} 
+			else {
+				continue;
+			}
+		}
+		if(!$this->wms_title || $this->wms_title == "" || !$this->wms_getmap || $this->wms_getmap == ""){
+			$this->wms_status = false;
+			$this->optimizeWMS();
+			$e = new mb_exception("class_wms: createObjFromXML: WMS " . $url . " could not be loaded.");
+			return false;
+		}
+		else{
+			$this->wms_status = true;
+			$this->optimizeWMS();
+
+			$e = new mb_notice("class_wms: createObjFromXML: WMS " . $url . " has been loaded successfully.");
+			return true;
+		}
+	}
+	/**
+	 * private function
+	 */
+	function optimizeWMS() {
+		/*define defaults for wms-version 1.0.0*/
+		$map_default_ok = false;
+		$featureinfo_default_ok = false;
+		$exception_default_ok = false;
+		if($this->wms_version == "1.0.0"){
+			$map_default = "PNG";
+			$featureinfo_default = "MIME";
+			$exception_default = "INIMAGE";
+		}
+		/*define defaults for wms-version 1.1.0 and 1.1.1*/
+		else{
+			$map_default = "image/png";
+			$featureinfo_default = "text/html";
+			$exception_default = "application/vnd.ogc.se_inimage";
+		}
+		#some default
+		$this->gui_wms_visible = 1;
+		$this->gui_wms_opacity = 100;
+		/*if the rootlayer has no epsg...*/
+		if($this->objLayer[0]->layer_epsg[0]["epsg"] == ""){
+			$this->objLayer[0]->layer_epsg = $this->objLayer[1]->layer_epsg;
+			for($i=0;$i<count($this->objLayer[0]->layer_epsg);$i++){
+				for($j=1; $j<count($this->objLayer); $j++){
+					if($this->objLayer[0]->layer_epsg[$i]["epsg"] == $this->objLayer[$j]->layer_epsg[$i]["epsg"]){
+						if($this->objLayer[$j]->layer_epsg[$i]["minx"]<$this->objLayer[0]->layer_epsg[$i]["minx"]){
+							$this->objLayer[0]->layer_epsg[$i]["minx"] = $this->objLayer[$j]->layer_epsg[$i]["minx"];
+						}
+						if($this->objLayer[$j]->layer_epsg[$i]["miny"]<$this->objLayer[0]->layer_epsg[$i]["miny"]){
+							$this->objLayer[0]->layer_epsg[$i]["miny"] = $this->objLayer[$j]->layer_epsg[$i]["miny"];
+						}
+						if($this->objLayer[$j]->layer_epsg[$i]["maxx"]>$this->objLayer[0]->layer_epsg[$i]["maxx"]){
+							$this->objLayer[0]->layer_epsg[$i]["maxx"] = $this->objLayer[$j]->layer_epsg[$i]["maxx"];
+						}
+						if($this->objLayer[$j]->layer_epsg[$i]["maxy"]>$this->objLayer[0]->layer_epsg[$i]["maxy"]){
+							$this->objLayer[0]->layer_epsg[$i]["maxy"] = $this->objLayer[$j]->layer_epsg[$i]["maxy"];
+						}
+					}
+				}
+			}
+		}
+		for($i=0;$i<count($this->objLayer);$i++){
+			if(count($this->objLayer[$i]->layer_epsg) == 0 && count($this->objLayer[0]->layer_epsg) > 0){
+				$this->objLayer[$i]->layer_epsg = $this->objLayer[0]->layer_epsg; 
+			}
+			if(!is_int($this->objLayer[$i]->layer_parent)){
+				$this->objLayer[$i]->layer_abstract = $this->wms_abstract;
+				for ($r = 0; $r < count($this->wms_keyword); $r++) {
+					array_push($this->objLayer[$i]->layer_keyword, trim($this->wms_keyword[$r]));
+				}
+			}
+			if($this->objLayer[$i]->layer_name == ""){
+				$this->objLayer[$i]->layer_name = $this->objLayer[$i]->layer_title;
+			}
+			if($this->objLayer[$i]->layer_minscale == ""){
+				$this->objLayer[$i]->layer_minscale = 0;
+			}
+			if($this->objLayer[$i]->layer_maxscale == ""){
+				$this->objLayer[$i]->layer_maxscale = 0;
+			}
+			if($this->objLayer[$i]->layer_queryable == ""){
+				$this->objLayer[$i]->layer_queryable = 0;
+			}
+			$this->objLayer[$i]->gui_layer_minscale = $this->objLayer[$i]->layer_minscale;
+			$this->objLayer[$i]->gui_layer_maxscale = $this->objLayer[$i]->layer_maxscale;
+		}
+		for($i=0;$i<count($this->data_format);$i++){
+			if(mb_strtolower($this->data_type[$i]) == 'map' && mb_strtoupper($this->data_format[$i]) == mb_strtoupper($map_default)){
+				$this->gui_wms_mapformat = mb_strtolower($map_default);
+				$map_default_ok = true;
+			}
+			if(mb_strtolower($this->data_type[$i]) == 'featureinfo' && mb_strtoupper($this->data_format[$i]) == mb_strtoupper($featureinfo_default)){
+				$this->gui_wms_featureinfoformat = mb_strtolower($featureinfo_default);
+				$featureinfo_default_ok = true;
+			}		
+			if(mb_strtolower($this->data_type[$i]) == 'exception' && mb_strtolower($this->data_format[$i]) == mb_strtolower($exception_default)){
+				$this->gui_wms_exceptionformat = mb_strtolower($exception_default);
+				$exception_default_ok = true;
+			}		
+		}
+		if($map_default_ok == false){
+			for($i=0;$i<count($this->data_format);$i++){
+				if(mb_strtolower($this->data_type[$i]) == "map" ){$this->gui_wms_mapformat = $this->data_format[$i]; break;}
+			}
+		}
+		if($featureinfo_default_ok == false){
+			for($i=0;$i<count($this->data_format);$i++){
+				if(mb_strtolower($this->data_type[$i]) == "featureinfo" ){$this->gui_wms_featureinfoformat = $this->data_format[$i]; break;}
+			}
+		}
+		if($exception_default_ok == false){
+			for($i=0;$i<count($this->data_format);$i++){
+				if(mb_strtolower($this->data_type[$i]) == "exception" ){$this->gui_wms_exceptionformat = $this->data_format[$i]; break;}
+			}
+		}
+		
+		if(count($this->objLayer[0]->layer_epsg)>1){
+			$this->gui_wms_epsg = $this->objLayer[0]->layer_epsg[$this->default_epsg][epsg];
+		}
+		else{
+			$this->gui_wms_epsg = $this->objLayer[0]->layer_epsg[0][epsg];
+		}
+		/*the queryable layers*/
+		for($i=0; $i<count($this->objLayer); $i++){
+			if($this->objLayer[$i]->layer_queryable == 1){
+				$this->objLayer[$i]->gui_layer_queryable = 1;
+			}
+			else{
+				$this->objLayer[$i]->gui_layer_queryable = 0;
+			}
+		}
+		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>";
+		echo "title: " . $this->wms_title . " <br>";
+		echo "abstract: " . $this->wms_abstract . " <br>";
+		echo "maprequest: " . $this->wms_getmap . " <br>";
+		echo "capabilitiesrequest: " . $this->wms_getcapabilities . " <br>";
+		echo "featureinforequest: " . $this->wms_getfeatureinfo . " <br>";
+		echo "gui_wms_mapformat: " . $this->gui_wms_mapformat . " <br>";
+		echo "gui_wms_featureinfoformat: " . $this->gui_wms_featureinfoformat . " <br>";
+		echo "gui_wms_exceptionformat: " . $this->gui_wms_exceptionformat . " <br>";	
+		echo "gui_wms_epsg: " . $this->gui_wms_epsg . " <br>";
+		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>";
+		}
+		for($i=0; $i<count($this->objLayer); $i++){
+			echo "<hr>";
+			echo "id: <b>".$this->objLayer[$i]->layer_id ."</b> parent: <b>".$this->objLayer[$i]->layer_parent."</b> name: <b>".$this->objLayer[$i]->layer_name;
+			echo "</b> title: <b>".$this->objLayer[$i]->layer_title. "</b> queryable: <b>".$this->objLayer[$i]->layer_queryable."</b> minScale: <b>". $this->objLayer[$i]->layer_minscale."</b> maxScale: <b>".$this->objLayer[$i]->layer_maxscale."</b>";
+			echo "<br>dataurl: <b>".$this->objLayer[$i]->layer_dataurl_href. "</b>";
+			echo "<br>metadataurl: <b>".$this->objLayer[$i]->layer_metadataurl. "</b>";
+			echo "<table border='1'>";
+			for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
+				echo "<tr><td>".$this->objLayer[$i]->layer_epsg[$j][epsg]."</td><td>".$this->objLayer[$i]->layer_epsg[$j][minx]."</td>";
+				echo "<td>".$this->objLayer[$i]->layer_epsg[$j][miny]."</td><td>".$this->objLayer[$i]->layer_epsg[$j][maxx]."</td>";
+				echo "<td>".$this->objLayer[$i]->layer_epsg[$j][maxy]."</td></tr>";
+			}
+			echo "</table>";
+			echo "layerstyle:";
+			echo "<table border='1'>";
+			echo "<tr><td>name</td><td>title</td><td>legendurl</td><td>legendurlformat</td></tr>";
+			for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
+				echo "<tr><td>".$this->objLayer[$i]->layer_style[$j][name]."</td><td>".$this->objLayer[$i]->layer_style[$j][title]."</td><td>".$this->objLayer[$i]->layer_style[$j][legendurl]."</td><td>".$this->objLayer[$i]->layer_style[$j][legendurlformat]."</td></tr>";
+			}
+			echo "</table>";
+	        echo "<hr>";
+	        echo "<hr>";
+		}
+	} 
+	  function addLayer($id,$parent){	
+		$this->objLayer[count($this->objLayer)] = new layer($id,$parent);
+	  }
+	  /**
+	   * private function
+	   */
+	  function stripEndlineAndCarriageReturn($string) {
+	  	return preg_replace("/\n/", "", preg_replace("/\r/", " ", $string));
+	  }
+		function createJsObjFromWMS($parent=0){
+			echo $this->createJsObjFromWMS_();
+		}
+		
+
+	function newLayer ($currentLayer, $currentExtent) {
+		$pos = $currentLayer["extension"]["LAYER_POS"];
+		$parent = $currentLayer["extension"]["LAYER_PARENT"];
+		$this->addLayer($pos, $parent); 
+
+		// set layer data
+		$layerIndex = count($this->objLayer) - 1;
+		$newLayer = $this->objLayer[$layerIndex];
+		$newLayer->layer_uid = $currentLayer["extension"]["LAYER_ID"];
+		$newLayer->layer_name = $currentLayer["name"];
+		$newLayer->layer_title = $currentLayer["title"];
+		$newLayer->layer_dataurl_href = $currentLayer["dataurl"];
+		$newLayer->layer_pos = $currentLayer["extension"]["LAYER_POS"];
+		$newLayer->layer_queryable = $currentLayer["queryable"];
+		$newLayer->layer_minscale = $currentLayer["extension"]["MINSCALE"];
+		$newLayer->layer_maxscale = $currentLayer["extension"]["MAXSCALE"];
+		$newLayer->layer_metadataurl = $currentLayer["metadataurl"];
+		$newLayer->gui_layer_wms_id = $currentLayer["extension"]["WMS_LAYER_ID"];
+		$newLayer->gui_layer_status = $currentLayer["extension"]["GUI_STATUS"];
+		$newLayer->gui_layer_style = ""; // TODO: Add correct data
+		$newLayer->gui_layer_selectable = $currentLayer["extension"]["GUI_SELECTABLE"];
+		$newLayer->gui_layer_visible = $currentLayer["visible"];
+		$newLayer->gui_layer_queryable = $currentLayer["extension"]["GUI_QUERYABLE"];
+		$newLayer->gui_layer_querylayer = $currentLayer["extension"]["QUERYLAYER"];
+		$newLayer->gui_layer_minscale = $currentLayer["extension"]["GUI_MINSCALE"];
+		$newLayer->gui_layer_maxscale = $currentLayer["extension"]["GUI_MAXSCALE"];
+		if (isset($currentLayer["extension"]["WFSFEATURETYPE"])) {
+			$newLayer->gui_layer_wfs_featuretype = $currentLayer["extension"]["WFSFEATURETYPE"];
+		}
+		$newLayer->layer_abstract = $currentLayer["abstract"];
+
+
+		//
+		// set layer epsg
+		//
+		$newLayer->layer_epsg = array();
+		if ($currentExtent !== null) {
+			$currentLayerEpsg = array();
+			$currentLayerEpsg["epsg"] = $currentExtent->epsg;
+			$currentLayerEpsg["minx"] = $currentExtent->min->x;
+			$currentLayerEpsg["miny"] = $currentExtent->min->y; 
+			$currentLayerEpsg["maxx"] = $currentExtent->max->x;
+			$currentLayerEpsg["maxy"] = $currentExtent->max->y;
+			array_push($newLayer->layer_epsg, $currentLayerEpsg);
+		}
+
+
+		//
+		// set layer style
+		//
+		for ($i = 0; $i < count($currentLayer["format"]); $i++) {
+			$layerStyleIndex = count($newLayer->gui_layer_style) - 1;
+			$newLayer->layer_style[$layerStyleIndex] = array();
+			$currentStyle = $newLayer->layer_style[$layerStyleIndex];
+			$currentStyle["name"] = $currentLayer["style"][$i]["name"];
+			$currentStyle["title"] = $currentLayer["style"][$i]["title"];
+			$currentStyle["legendurl"] = $currentLayer["style"][$i]["legendurl"];
+			$currentStyle["legendurl_format"] = $currentLayer["style"][$i]["legendurl_type"];
+		}
+	}
+	
+	  function createJsObjFromWMS_($parent=0){
+	  	$str = "";
+	  	if(!$this->wms_title || $this->wms_title == ""){
+			$str .= "alert('Error: no valid capabilities-document !!');";
+			die; exit;
+		}
+			if($parent){
+				$str .=  "parent.";
+			}
+			// wms_title and abstract have previously been urlencoded
+			// this solution may not yet be the ultimate one
+			
+			$add_wms_string = "add_wms(" .
+					"'" . $this->wms_id ."'," .
+					"'" . $this->wms_version ."'," .
+					"'" . addslashes($this->wms_title) . "'," .
+					"'" . addslashes($this->wms_abstract) ."'," .
+					"'" . $this->wms_getmap ."'," .
+					"'" . $this->wms_getfeatureinfo ."'," .
+					"'" . $this->wms_getlegendurl ."'," .
+					"'" . $this->wms_filter ."'," .
+					"'" . $this->gui_wms_mapformat . "'," .
+					"'" . $this->gui_wms_featureinfoformat . "'," .
+					"'" . $this->gui_wms_exceptionformat . "'," .
+					"'" . $this->gui_wms_epsg ."'," .
+					"'" . $this->gui_wms_visible ."'," .
+					"'" . $this->gui_wms_opacity ."'," .
+					"'" . $this->gui_wms_sldurl ."" .
+					"');";
+			$str .=  $add_wms_string;
+			
+		for($i=0;$i<count($this->data_format);$i++){
+			if($parent){
+				$str .=  "parent.";
+			}		
+			$str .= "wms_add_data_type_format('". $this->data_type[$i] ."','". $this->data_format[$i] ."');\n";		
+		}
+		for($i=0; $i<count($this->objLayer); $i++){
+			if($parent){
+				$str .= "parent.";
+			}
+			$str .=  "wms_add_layer('". 
+				$this->objLayer[$i]->layer_parent ."','". 
+				$this->objLayer[$i]->layer_uid ."','". 
+				addslashes($this->objLayer[$i]->layer_name) . "','". 
+				addslashes($this->objLayer[$i]->layer_title) ."','". 
+				$this->objLayer[$i]->layer_dataurl_href ."','". 
+				$this->objLayer[$i]->layer_pos ."','". 
+				$this->objLayer[$i]->layer_queryable ."','". 
+				$this->objLayer[$i]->layer_minscale . "','". 
+				$this->objLayer[$i]->layer_maxscale ."','". 
+				$this->objLayer[$i]->layer_metadataurl ."','". 
+				$this->objLayer[$i]->gui_layer_wms_id ."','". 
+				$this->objLayer[$i]->gui_layer_status ."','".
+				$this->objLayer[$i]->gui_layer_style ."','".  
+				$this->objLayer[$i]->gui_layer_selectable ."','". 
+				$this->objLayer[$i]->gui_layer_visible ."','". 
+				$this->objLayer[$i]->gui_layer_queryable ."','". 
+				$this->objLayer[$i]->gui_layer_querylayer ."','". 
+				$this->objLayer[$i]->gui_layer_minscale ."','". 
+				$this->objLayer[$i]->gui_layer_maxscale ."','".
+				$this->objLayer[$i]->gui_layer_wfs_featuretype ."');\n";
+				
+			for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
+				if($i==0){
+					if($parent){
+						$str .= "parent.";
+					}
+					$str .= "wms_addSRS('". 
+						$this->objLayer[$i]->layer_epsg[$j]["epsg"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["minx"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["miny"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["maxx"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');\n";
+				}
+				if($parent){
+					$str .=  "parent.";
+				}
+				$str .= "layer_addEpsg('". 
+					$this->objLayer[$i]->layer_epsg[$j]["epsg"] ."','". 
+					$this->objLayer[$i]->layer_epsg[$j]["minx"] ."','". 
+					$this->objLayer[$i]->layer_epsg[$j]["miny"] ."','". 
+					$this->objLayer[$i]->layer_epsg[$j]["maxx"] ."','". 
+					$this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');\n";
+			}
+			for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
+				if($parent){
+				$str .= "parent.";
+				}
+				$str .= "wms_addLayerStyle('".$this->objLayer[$i]->layer_style[$j]["name"].
+					"', '".$this->objLayer[$i]->layer_style[$j]["title"].
+					"', ".$j.
+					",".$i.
+					",'".$this->objLayer[$i]->layer_style[$j]["legendurl"].
+					"', '".$this->objLayer[$i]->layer_style[$j]["legendformat"]."');\n";
+			}
+		}
+		return $str;
+	  }
+	  
+	  function createJsLayerObjFromWMS($parent=0, $layer_name){
+	  	if(!$this->wms_title || $this->wms_title == ""){
+			echo " alert('Error: no valid capabilities-document !!');";
+			die; exit;
+		}
+			if($parent){
+				echo "parent.";
+			}
+			// wms_title and abstract have previously been urlencoded
+			// this solution may not yet be the ultimate one
+			print("add_wms('". 
+			$this->wms_id ."','".
+			$this->wms_version ."','".
+			preg_replace("/'/", "", $this->wms_title) ."','".
+			preg_replace("/'/", "", $this->wms_abstract) ."','". 
+			$this->wms_getmap ."','" .
+			$this->wms_getfeatureinfo ."','".
+			$this->wms_getlegendurl ."','".
+			$this->wms_filter ."','".
+			$this->gui_wms_mapformat ."','". 
+			$this->gui_wms_featureinfoformat ."','". 
+			$this->gui_wms_exceptionformat . "','". 
+			$this->gui_wms_epsg ."','". 
+			$this->gui_wms_visible ."','".
+			$this->gui_wms_opacity ."','".
+			$this->gui_wms_sldurl ."');\n");
+			
+		for($i=0;$i<count($this->data_format);$i++){
+			if($parent){
+				echo "parent.";
+			}		
+			echo "wms_add_data_type_format('". $this->data_type[$i] ."','". $this->data_format[$i] ."');\n";		
+		}
+		for($i=0; $i<count($this->objLayer); $i++){
+			if($this->objLayer[$i]->layer_name == $layer_name|| $this->objLayer[$i]->layer_pos == 0){
+			
+				if($parent){
+					echo "parent.";
+				}
+			 print ("wms_add_layer('". 
+				$this->objLayer[$i]->layer_parent ."','". 
+				$this->objLayer[$i]->layer_uid ."','". 
+				$this->objLayer[$i]->layer_name . "','". 
+				addslashes($this->objLayer[$i]->layer_title) ."','". 
+				$this->objLayer[$i]->layer_dataurl_href ."','". 
+				$this->objLayer[$i]->layer_pos ."','". 
+				$this->objLayer[$i]->layer_queryable ."','". 
+				$this->objLayer[$i]->layer_minscale . "','". 
+				$this->objLayer[$i]->layer_maxscale ."','". 
+				$this->objLayer[$i]->layer_metadataurl ."','". 
+				$this->objLayer[$i]->gui_layer_wms_id ."','". 
+				$this->objLayer[$i]->gui_layer_status ."','".
+				$this->objLayer[$i]->gui_layer_style ."','". 
+				$this->objLayer[$i]->gui_layer_selectable ."','". 
+				$this->objLayer[$i]->gui_layer_visible ."','". 
+				$this->objLayer[$i]->gui_layer_queryable ."','". 
+				$this->objLayer[$i]->gui_layer_querylayer ."','". 
+				$this->objLayer[$i]->gui_layer_minscale ."','". 
+				$this->objLayer[$i]->gui_layer_maxscale ."','".
+				$this->objLayer[$i]->gui_layer_wfs_featuretype ."');\n");
+			for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
+				if($i==0){
+					if($parent){
+					echo "parent.";
+					}
+					print("wms_addSRS('". 
+						$this->objLayer[$i]->layer_epsg[$j]["epsg"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["minx"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["miny"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["maxx"] ."','". 
+						$this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');\n");
+				}
+				if($parent){
+				echo "parent.";
+				}
+				print("layer_addEpsg('". 
+					$this->objLayer[$i]->layer_epsg[$j]["epsg"] ."','". 
+					$this->objLayer[$i]->layer_epsg[$j]["minx"] ."','". 
+					$this->objLayer[$i]->layer_epsg[$j]["miny"] ."','". 
+					$this->objLayer[$i]->layer_epsg[$j]["maxx"] ."','". 
+					$this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');\n");
+			}
+			for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
+				if($parent){
+				echo "parent.";
+				}
+				print("wms_addLayerStyle('".$this->objLayer[$i]->layer_style[$j]["name"]."', '".$this->objLayer[$i]->layer_style[$j]["title"]."', ".$j.",".$i.",'".$this->objLayer[$i]->layer_style[$j]["legendurl"]."', '".$this->objLayer[$i]->layer_style[$j]["legendformat"]."');\n");
+			}
+		   }	
+		}
+	  }
+	  
+	  
+	/**
+	* writeObjInDB
+	*
+	* this function exports the information from the xml to the mapbender database 
+	*/
+	function writeObjInDB($gui_id){
+		global $con;
+		
+		$this->checkObj();
+		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 .= "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_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"),
+			$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();
+		}
+		
+		$myWMS = db_insert_id($con,'wms', 'wms_id');
+		
+		# TABLE layer and gui_layer
+		
+		for($i=0; $i<count($this->objLayer); $i++){
+			$this->insertLayer($i,$myWMS,$gui_id);
+			$this->insertGuiLayer($i,$myWMS,$gui_id);
+		}	
+			
+		
+		#TABLE wms_srs
+		$this->insertSRS($myWMS);	
+		
+		# TABLE wms_format	
+		$this->insertFormat($myWMS);	
+			
+		# TABLE gui_wms
+		
+		$sql ="SELECT MAX(gui_wms_position) AS pos FROM gui_wms WHERE fkey_gui_id = $1";
+		$v = array($gui_id);
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
+		if(db_result($res, 0,"pos") > -1){
+			$position = db_result($res, 0,"pos") + 1;
+		} else{ $position = 0; }
+		
+		$sql ="INSERT INTO gui_wms (fkey_gui_id, fkey_wms_id, gui_wms_position, gui_wms_mapformat, ";
+		$sql .= "gui_wms_featureinfoformat, gui_wms_exceptionformat, gui_wms_epsg)";
+		$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7)";
+		$v = array($gui_id,$myWMS,$position,$this->gui_wms_mapformat,$this->gui_wms_featureinfoformat,
+				$this->gui_wms_exceptionformat,$this->gui_wms_epsg
+				);
+		$t = array('s','i','i','s','s','s','s');
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			db_rollback();	
+		}
+		db_commit();
+	    
+	    #Changes JW
+	    $this->wms_id = $myWMS;
+	}
+	function insertLayer($i,$myWMS){
+		global $con;
+		$sql = "INSERT INTO layer(fkey_wms_id, layer_pos, layer_parent, layer_name, layer_title, ";
+		$sql .= " layer_queryable, layer_minscale, layer_maxscale,layer_dataurl,layer_metadataurl,layer_abstract) ";
+		$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)";
+		if($this->objLayer[$i]->layer_id != null){
+			$tmpPos =  $this->objLayer[$i]->layer_id;
+		}
+		else {
+			$tmpPos .= 0;
+		}
+		if($this->objLayer[$i]->layer_parent == '' && $this->objLayer[$i]->layer_parent != '0'){
+			$this->objLayer[$i]->layer_parent = '';
+		}
+		$v = array($myWMS,$tmpPos,$this->objLayer[$i]->layer_parent,$this->objLayer[$i]->layer_name,
+				$this->objLayer[$i]->layer_title,
+				$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,
+				$this->objLayer[$i]->layer_maxscale,$this->objLayer[$i]->layer_dataurl_href,
+				$this->objLayer[$i]->layer_metadataurl,$this->objLayer[$i]->layer_abstract);
+		$t = array('i','i','s','s','s','i','i','i','s','s','s');
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			db_rollback();	
+		}
+		else {
+			# save the id of each layer: set param2 true		
+			$this->objLayer[$i]->db_id = db_insert_id($con, 'layer','layer_id');
+			$this->insertLayerEPSG($i);
+			
+			# TABLE layer_style for each layer
+			$this->insertLayerStyle($i);
+			
+			# insert Keywords
+			$this->insertLayerKeyword($i);	
+		
+		}
+	}
+	function updateLayer($i,$myWMS){
+		$sql = "SELECT layer_id FROM layer WHERE fkey_wms_id = $1 AND layer_name = $2";
+		$v = array($myWMS,$this->objLayer[$i]->layer_name);
+		$t = array('i','s');
+		$res = db_prep_query($sql,$v,$t);
+		if($row = db_fetch_array($res)){
+			$l_id = $row['layer_id'];	
+		}
+		else{
+			db_rollback();
+			$e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name);
+			return;	
+		}	
+		
+		$sql = "UPDATE layer SET ";
+		$sql .= "layer_pos = $1, ";
+		$sql .= "layer_parent = $2, ";
+		$sql .= "layer_title = $3, ";
+		$sql .= "layer_queryable = $4, ";
+		$sql .= "layer_minscale = $5, ";
+		$sql .= "layer_maxscale = $6, ";
+		$sql .= "layer_dataurl = $7, ";
+		$sql .= "layer_metadataurl = $8, ";
+		$sql .= "layer_abstract = $9 ";
+		$sql .= "WHERE layer_id = $10";
+		
+		if($this->objLayer[$i]->layer_id != null){
+			$tmpPos =  $this->objLayer[$i]->layer_id;
+		}
+		else {
+			$tmpPos .= 0;
+		}
+		if($this->objLayer[$i]->layer_parent == '' && $this->objLayer[$i]->layer_parent != '0'){
+			$this->objLayer[$i]->layer_parent = '';
+		}
+		$v = array($tmpPos,$this->objLayer[$i]->layer_parent,
+				$this->objLayer[$i]->layer_title,
+				$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,
+				$this->objLayer[$i]->layer_maxscale,$this->objLayer[$i]->layer_dataurl_href,
+				$this->objLayer[$i]->layer_metadataurl,$this->objLayer[$i]->layer_abstract, $l_id		
+			);
+		$t = array('i','s','s','i','i','i','s','s','s','i');
+		$res = db_prep_query($sql,$v,$t);
+		if($this->overwrite == true){
+			$sql = "UPDATE layer SET ";
+			$sql .= "layer_title = $1, ";
+			$sql .= "layer_abstract = $2 ";
+			$sql .= "WHERE layer_id = $3";
+			
+			$v = array($this->objLayer[$i]->layer_title,$this->objLayer[$i]->layer_abstract, $l_id);
+			$t = array('s','s','i');
+			$res = db_prep_query($sql,$v,$t);
+		}
+		if(!$res){
+			db_rollback();	
+		}
+		else {
+			
+			# save the id of each layer: set param2 true
+			$this->objLayer[$i]->db_id = $l_id;
+			$this->insertLayerEPSG($i);
+			
+			# TABLE layer_style for each layer
+			$this->insertLayerStyle($i);
+			if($this->overwrite == true){
+				$this->insertLayerKeyword($i);
+			}
+		}
+	}
+	function insertGuiLayer($i,$myWMS,$gui_id){
+		# table gui_layer
+		
+		$sql = "INSERT INTO gui_layer (fkey_gui_id, fkey_layer_id, gui_layer_wms_id, ";
+		$sql .= "gui_layer_status, gui_layer_selectable, gui_layer_visible, gui_layer_queryable, ";
+		$sql .= "gui_layer_querylayer,gui_layer_minscale,gui_layer_maxscale, gui_layer_priority, gui_layer_style) ";
+		$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)";
+		if(count($this->objLayer[$i]->layer_style)>0){
+			$layer_style_name = $this->objLayer[$i]->layer_style[0]["name"];
+		}
+		else{
+			$layer_style_name = NULL;
+		}
+		$v = array($gui_id,$this->objLayer[$i]->db_id,$myWMS,1,1,1,$this->objLayer[$i]->layer_queryable,
+			$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,$this->objLayer[$i]->layer_maxscale,$i,$layer_style_name);
+		$t = array('s','i','i','i','i','i','i','i','i','i','i','s');
+		$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();	
+		}	
+	}
+	function appendGuiLayer($i,$myWMS,$gui_id){
+		# table gui_layer
+		
+		$sql = "INSERT INTO gui_layer (fkey_gui_id, fkey_layer_id, gui_layer_wms_id, ";
+		$sql .= "gui_layer_status, gui_layer_selectable, gui_layer_visible, gui_layer_queryable, ";
+		$sql .= "gui_layer_querylayer,gui_layer_minscale,gui_layer_maxscale, gui_layer_priority, gui_layer_style) ";
+		$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)";
+		if(count($this->objLayer[$i]->layer_style)>0){
+			$layer_style_name = $this->objLayer[$i]->layer_style[0]["name"];
+		}
+		else{
+			$layer_style_name = NULL;
+		}
+		$v = array($gui_id,$this->objLayer[$i]->db_id,$myWMS,0,0,0,$this->objLayer[$i]->layer_queryable,
+			$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,$this->objLayer[$i]->layer_maxscale,$i,$layer_style_name);
+		$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();	
+		}	
+	}
+	function insertSRS($myWMS){
+		for($i=0; $i<count($this->wms_srs);$i++){
+			$sql ="INSERT INTO wms_srs (fkey_wms_id, wms_srs) values($1,$2)";		
+			$v = array($myWMS,mb_strtoupper($this->wms_srs[$i]));
+			$t = array('i','s');		
+			$res = db_prep_query($sql,$v,$t);
+			if(!$res){
+				db_rollback();	
+			}
+		}	
+	}
+	function insertFormat($myWMS){
+		for($i=0; $i<count($this->data_type);$i++){
+			$sql ="INSERT INTO wms_format (fkey_wms_id, data_type, data_format) ";
+			$sql .= " VALUES($1,$2,$3)";
+			$v = array($myWMS,$this->data_type[$i],$this->data_format[$i]);
+			$t = array('i','s','s');
+			$res = db_prep_query($sql,$v,$t);
+			if(!$res){
+				db_rollback();	
+			}
+		}	
+	}
+	function insertLayerEPSG($i){
+		$sql = "DELETE FROM layer_epsg WHERE fkey_layer_id = $1";
+		$v = array($this->objLayer[$i]->db_id);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
+			$sql = "INSERT INTO layer_epsg (fkey_layer_id, epsg, minx, miny, maxx, maxy) ";
+			$sql .= "VALUES($1,$2,$3,$4,$5,$6)";
+			$v = array($this->objLayer[$i]->db_id,$this->objLayer[$i]->layer_epsg[$j][epsg],
+				$this->objLayer[$i]->layer_epsg[$j][minx],$this->objLayer[$i]->layer_epsg[$j][miny],
+				$this->objLayer[$i]->layer_epsg[$j][maxx],$this->objLayer[$i]->layer_epsg[$j][maxy]
+				); 
+			$t = array('i','s','d','d','d','d');
+			$res = db_prep_query($sql,$v,$t);
+			if(!$res){
+				db_rollback();	
+			}
+		}
+	}
+	function insertLayerStyle($i){
+		$sql = "DELETE FROM layer_style WHERE fkey_layer_id = $1";
+		$v = array($this->objLayer[$i]->db_id);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
+			$sql = "INSERT INTO layer_style (fkey_layer_id, name, title, legendurl, legendurlformat) ";
+			$sql .= "VALUES($1,$2,$3,$4,$5)";
+			$v = array($this->objLayer[$i]->db_id,$this->objLayer[$i]->layer_style[$j]["name"],
+					$this->objLayer[$i]->layer_style[$j]["title"],$this->objLayer[$i]->layer_style[$j]["legendurl"],
+					$this->objLayer[$i]->layer_style[$j]["legendurlformat"]				
+				);
+			$t = array('i','s','s','s','s');
+			$res = db_prep_query($sql,$v,$t);
+			if(!$res){
+				db_rollback();	
+			}
+		}
+	}
+	function insertLayerKeyword($i){
+		global $con;
+		$sql = "DELETE FROM layer_keyword WHERE fkey_layer_id = $1";
+		$v = array($this->objLayer[$i]->db_id);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		
+//		var_dump($this);
+		$k = $this->objLayer[$i]->layer_keyword;
+//		var_dump($k);
+		for($j=0; $j<count($k); $j++){
+			$keyword_id = "";
+			
+			while ($keyword_id == "") {
+				$sql = "SELECT keyword_id FROM keyword WHERE UPPER(keyword) = UPPER($1)";
+				$v = array($k[$j]);
+				$t = array('s');
+				$res = db_prep_query($sql,$v,$t);
+				$row = db_fetch_array($res);
+			//print_r($row);
+				if ($row) {
+					$keyword_id = $row["keyword_id"];	
+				}
+				else {
+					$sql_insertKeyword = "INSERT INTO keyword (keyword)";
+					$sql_insertKeyword .= "VALUES ($1)";
+					$v1 = array($k[$j]);
+					$t1 = array('s');
+					$res_insertKeyword = db_prep_query($sql_insertKeyword,$v1,$t1);
+					if(!$res_insertKeyword){
+						db_rollback();	
+					}
+				}
+			}
+
+			// check if layer/keyword combination already exists
+			$sql_layerKeywordExists = "SELECT * FROM layer_keyword WHERE fkey_layer_id = $1 AND fkey_keyword_id = $2";
+			$v = array($this->objLayer[$i]->db_id, $keyword_id);
+			$t = array('i', 'i');
+			$res_layerKeywordExists = db_prep_query($sql_layerKeywordExists, $v, $t);
+			$row = db_fetch_array($res_layerKeywordExists);
+			//print_r($row);
+			if (!$row) {
+				$sql1 = "INSERT INTO layer_keyword (fkey_keyword_id,fkey_layer_id)";
+				$sql1 .= "VALUES ($1,$2)";
+				$v1 = array($keyword_id,$this->objLayer[$i]->db_id);
+				$t1 = array('i','i');
+				$res1 = db_prep_query($sql1,$v1,$t1);
+				if(!$res1){
+					db_rollback();	
+				}
+			}
+		}
+	}
+	function updateObjInDB($myWMS){
+		db_begin();
+		
+		$sql = "UPDATE wms SET ";
+		$sql .= "wms_version = $1 ,";
+		$sql .= "wms_getcapabilities  = $2 ,";
+		$sql .= "wms_getmap  = $3 ,";
+		$sql .= "wms_getfeatureinfo  = $4 ,";
+		$sql .= "wms_getlegendurl  = $5 ,";
+		$sql .= "wms_getcapabilities_doc = $6 ,";
+		$sql .= "wms_upload_url = $7,  ";
+		$sql .= "wms_owner = $8, ";
+		$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"),
+			$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();	
+		}
+		
+		if($this->overwrite == true){
+			$sql = "UPDATE wms SET ";
+			$sql .= "wms_title  = $1 ,";
+			$sql .= "wms_abstract  = $2 ,";
+			$sql .= "fees = $3, ";
+			$sql .= "accessconstraints = $4, ";
+			$sql .= "contactperson = $5, ";
+			$sql .= "contactposition = $6, ";
+			$sql .= "contactorganization = $7, ";
+			$sql .= "address = $8, ";
+			$sql .= "city = $9, ";
+			$sql .= "stateorprovince = $10, ";
+			$sql .= "postcode = $11, ";
+			$sql .= "country = $12, ";
+			$sql .= "contactvoicetelephone = $13, ";
+			$sql .= "contactfacsimiletelephone = $14, ";
+			$sql .= "contactelectronicmailaddress = $15 ";
+			$sql .= " WHERE wms_id = $16";
+		
+			$v = array($this->wms_title,$this->wms_abstract,$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,$myWMS);
+			$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();	
+			}
+		}
+		
+		# delete and refill srs and formats
+		$sql = "DELETE FROM wms_srs WHERE fkey_wms_id = $1 ";
+		$v = array($myWMS);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			db_rollback();	
+		}
+		$this->insertSRS($myWMS);
+		
+		$sql = "DELETE FROM wms_format WHERE fkey_wms_id = $1 ";
+		$v = array($myWMS);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			db_rollback();	
+		}
+		$this->insertFormat($myWMS);
+		
+		# update gui_wms
+		$this->update_gui_wms($myWMS);
+		
+		# update TABLE layer	
+		# delete all layer which are outdated
+		$v = array($myWMS);
+		$t = array('i');
+		$c = 2;
+		$sql = "DELETE FROM layer WHERE fkey_wms_id = $1 AND NOT layer_name IN(";
+		for($i=0; $i<count($this->objLayer); $i++){
+			if($i>0){$sql .= ',';}
+			$sql .= "$".$c;
+			array_push($v,$this->objLayer[$i]->layer_name);
+			array_push($t,'s');		
+			$c++;
+		}
+		$sql .= ")";
+		
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			db_rollback();	
+		}
+			
+		# update or insert?
+		$sql = "SELECT layer_name FROM layer WHERE fkey_wms_id = $1";
+		$v = array($myWMS);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$exLayer = array();
+		while($row = db_fetch_array($res)){
+			array_push($exLayer,$row["layer_name"]);
+		}
+		
+		$sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = $1";
+		$v = array($myWMS);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$exGui = array();
+		while($row = db_fetch_array($res)){
+			array_push($exGui,$row["fkey_gui_id"]);
+		}
+		
+		for($i=0; $i<count($this->objLayer); $i++){
+			if(in_array($this->objLayer[$i]->layer_name,$exLayer)){
+				//echo "<br>update: ".$this->objLayer[$i]->layer_name;
+				$this->updateLayer($i,$myWMS);
+				for($j=0; $j<count($exGui); $j++){
+					$this->updateGuiLayer($i,$myWMS,$exGui[$j]);
+				}
+			}
+			else{
+				//echo "<br>append: ".$this->objLayer[$i]->layer_name;
+				$this->insertLayer($i,$myWMS);
+				for($j=0; $j<count($exGui); $j++){
+					$this->appendGuiLayer($i,$myWMS,$exGui[$j]);
+				}
+			}
+		}
+		db_commit();
+		return;	
+	}
+	function updateGuiLayer($i,$myWMS,$gui_id){
+		$sql = "SELECT layer_id FROM layer WHERE fkey_wms_id = $1 AND layer_name = $2";
+		$v = array($myWMS,$this->objLayer[$i]->layer_name);
+		$t = array('i','s');
+		$res = db_prep_query($sql,$v,$t);
+		if($row = db_fetch_array($res)){
+			$l_id = $row['layer_id'];	
+		}
+		else{
+			db_rollback();
+			$e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name. " in gui: ".$gui_id);
+			return;	
+		}
+		
+		$sql = "SELECT * FROM gui_layer WHERE fkey_layer_id = $1 and fkey_gui_id = $2";
+		$v = array($l_id,$gui_id);
+		$t = array('i','s');
+		$res = db_prep_query($sql,$v,$t);		
+		while($row = db_fetch_array($res)){
+			if($this->objLayer[$i]->layer_queryable == 0){
+				$sql1 = "UPDATE gui_layer set gui_layer_queryable = 0, gui_layer_querylayer = 0 ";
+				$sql1 .= "WHERE fkey_layer_id = $1 and fkey_gui_id = $2";
+				$v = array($l_id,$gui_id);
+				$t = array('i','s');
+				$res1 = db_prep_query($sql1,$v,$t);
+				if(!$res1){
+					
+				db_rollback();
+				}
+			}
+			if($this->objLayer[$i]->layer_queryable == 1){
+				$sql1 = "UPDATE gui_layer set gui_layer_queryable = 1 ";
+				$sql1 .= "WHERE fkey_layer_id = $1 and fkey_gui_id = $2";
+				$v = array($l_id,$gui_id);
+				$t = array('i','s');
+				$res1 = db_prep_query($sql1,$v,$t);
+				if(!$res1){
+					
+					db_rollback();
+				}
+			}
+			if($row["gui_layer_minscale"] < $this->objLayer[$i]->layer_minscale){
+				$sql1 = "UPDATE gui_layer set gui_layer_minscale = $1 ";
+				$sql1 .= "WHERE fkey_layer_id = $2 and fkey_gui_id = $3";
+				$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($row["gui_layer_maxscale"] > $this->objLayer[$i]->layer_maxscale){
+				$sql1 = "UPDATE gui_layer set gui_layer_maxscale = $1 ";
+				$sql1 .= "WHERE fkey_layer_id = $2 and fkey_gui_id = $3";
+				$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();
+				}
+			}		
+		}
+	}
+	function update_gui_wms($myWMS){
+		$mySubmit = null;
+		$sql = "SELECT * FROM gui_wms where fkey_wms_id = $1";
+		$v = array($myWMS);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$cnt = 0;
+		while($row = db_fetch_array($res)){	
+			unset($mySubmit);
+			$myGUI[$cnt] = $row["fkey_gui_id"];
+
+			$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"])){
+					$myMapFormat = true;
+				}
+				# gui_wms_featureinfoformat
+				if(mb_strtolower($this->data_type[$i]) == "featureinfo" && mb_strtolower($this->data_format[$i]) == mb_strtolower($row["gui_wms_featureinfoformat"])){
+					$myFeatureInfoFormat = true;
+				}
+				# gui_wms_exceptionformat
+				if(mb_strtolower($this->data_type[$i]) == "exception" && mb_strtolower($this->data_format[$i]) == mb_strtolower($row["gui_wms_exceptionformat"])){
+					$myExceptionFormat = true;
+				}
+			}
+			if(!$myMapFormat){
+				$paramCount++;
+				$sql .= "gui_wms_mapformat = $" . $paramCount . " ";
+				$mySubmit = true;
+				array_push($v, $this->gui_wms_mapformat);
+				array_push($t, "s");
+			}
+			if(!$myFeatureInfoFormat){
+				if($mySubmit){ $sql .= ",";}
+				$paramCount++;
+				$sql .= "gui_wms_featureinfoformat = $" . $paramCount . " ";
+				array_push($v, $this->gui_wms_featureinfoformat);
+				array_push($t, "s");
+				$mySubmit = true;
+			}
+			if(!$myExceptionFormat){
+				if($mySubmit){ $sql .= ",";}
+				$paramCount++;
+				$sql .= "gui_wms_exceptionformat = $" . $paramCount ." ";
+				array_push($v, $this->gui_wms_exceptionformat);
+				array_push($t, "s");
+				$mySubmit = true;
+			}
+				
+			# gui_wms_epsg
+			for($j=0; $j<count($this->objLayer[0]->layer_epsg);$j++){
+				if($this->objLayer[0]->layer_epsg[$j][epsg] == mb_strtoupper($row["gui_wms_epsg"])){
+					$myGUI_EPSG = true;
+				}
+			}
+			if(!$myGUI_EPSG){
+				if($mySubmit){ $sql .= ",";}
+				$paramCount++;
+				$sql .= "gui_wms_epsg = $" . $paramCount . " ";
+				array_push($v, $this->gui_wms_epsg);
+				array_push($t, "s");
+				$mySubmit = true;
+			}
+			$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){
+				$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++;
+		}	
+	}
+	function getVersion() {
+		return $this->wms_version;
+	}
+	
+	function getCapabilities() {
+		return $this->wms_getcapabilities;
+	}
+	
+	function getCapabilitiesDoc() {
+		return $this->wms_getcapabilities_doc;
+	}
+
+	/**
+	* creatObjfromDB
+	*
+	*/ 
+	  function createObjFromDB($gui_id,$wms_id){
+	
+		$sql = "Select * from gui_wms where fkey_wms_id = $1 AND fkey_gui_id = $2";
+		$v = array($wms_id,$gui_id);
+		$t = array('i','s');
+		$res = db_prep_query($sql,$v,$t);
+		
+		$count=0;
+		#$res_count=db_num_rows($res);
+	    
+	
+		while($row = db_fetch_array($res)){
+			$this->gui_wms_mapformat=$row["gui_wms_mapformat"];
+			$this->gui_wms_featureinfoformat=$row["gui_wms_featureinfoformat"];
+			$this->gui_wms_exceptionformat=$row["gui_wms_exceptionformat"];
+			$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);
+			$t = array('i');
+			$res_wms = db_prep_query($sql,$v,$t);
+			$count_wms=0;
+			while($row2 = db_fetch_array($res_wms)){
+				$this->wms_id = $row2["wms_id"];
+				$this->wms_version = $row2["wms_version"];
+				$this->wms_title = $this->stripEndlineAndCarriageReturn($row2["wms_title"]);
+				$this->wms_abstract = $this->stripEndlineAndCarriageReturn($row2["wms_abstract"]);
+				$wmsowsproxy = $row2["wms_owsproxy"];
+				#$wmsowsproxy = "test";
+				if($wmsowsproxy != ""){
+					$owsproxyurl = OWSPROXY."/".session_id()."/".$wmsowsproxy."?";
+					$this->wms_getmap = $owsproxyurl;
+					$this->wms_getcapabilities =  $owsproxyurl;
+					$this->wms_getfeatureinfo = $owsproxyurl;
+					$this->wms_getlegendurl = $owsproxyurl;
+				}
+				else{
+					$this->wms_getmap =  $row2["wms_getmap"];
+					$this->wms_getcapabilities =  $row2["wms_getcapabilities"];
+					$this->wms_getfeatureinfo = $row2["wms_getfeatureinfo"];
+					$this->wms_getlegendurl = $row2["wms_getlegendurl"];
+				}			
+				$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++;
+			}
+	
+			### formats
+			$sql = "SELECT * FROM wms_format WHERE fkey_wms_id = $1 ";
+			$v = array($wms_id);
+			$t = array('i'); 
+			$res_wms = db_prep_query($sql,$v,$t);
+			$count_format=0;		
+			while($row3 = db_fetch_array($res_wms)){		
+				$this->data_type[$count_format] = $row3["data_type"];
+				$this->data_format[$count_format] = $row3["data_format"];
+				$count_format++;
+			}
+			$count++;
+		}
+		
+		#layer
+		$sql = "Select * from gui_layer where gui_layer_wms_id = $1 AND fkey_gui_id = $2 ";
+		$sql .= " AND gui_layer_status = 1 ORDER BY gui_layer_priority;";
+		$v = array($wms_id,$gui_id);
+		$t = array('i','s');
+		$res = db_prep_query($sql,$v,$t);
+		$count=0;
+		
+		while($row = db_fetch_array($res)){
+			$layer_id = $row["fkey_layer_id"];		
+			$sql = "Select * from layer where layer_id = $1";
+			$v = array($layer_id);
+			$t = array('i');
+			$res_layer = db_prep_query($sql,$v,$t);
+			$count_layer=0;
+			while($row2 = db_fetch_array($res_layer)){
+				$this->addLayer($row2["layer_pos"],$row2["layer_parent"]);
+				$layer_cnt=count($this->objLayer)-1;
+				$this->objLayer[$layer_cnt]->layer_uid = $layer_id;
+				$this->objLayer[$layer_cnt]->layer_name =$row2["layer_name"];
+				$this->objLayer[$layer_cnt]->layer_title =$row2["layer_title"];			
+				$this->objLayer[$layer_cnt]->layer_dataurl_href =$row2["layer_dataurl"];
+				$this->objLayer[$layer_cnt]->layer_metadataurl =$row2["layer_metadataurl"];
+				$this->objLayer[$layer_cnt]->layer_pos =$row2["layer_pos"];						
+				$this->objLayer[$layer_cnt]->layer_queryable =$row2["layer_pos"];
+				$this->objLayer[$layer_cnt]->layer_queryable =$row2["layer_queryable"];
+				$this->objLayer[$layer_cnt]->layer_minscale =$row2["layer_minscale"];
+				$this->objLayer[$layer_cnt]->layer_maxscale = $row2["layer_maxscale"];
+				$count_layer++;
+			}
+			$this->objLayer[$layer_cnt]->layer_uid = $layer_id;
+			$this->objLayer[$layer_cnt]->gui_layer_wms_id = $row["gui_layer_wms_id"];
+			$this->objLayer[$layer_cnt]->gui_layer_selectable = $row["gui_layer_selectable"];
+			$this->objLayer[$layer_cnt]->gui_layer_visible = $row["gui_layer_visible"];
+			$this->objLayer[$layer_cnt]->gui_layer_queryable = $row["gui_layer_queryable"];
+			$this->objLayer[$layer_cnt]->gui_layer_querylayer = $row["gui_layer_querylayer"];
+			$this->objLayer[$layer_cnt]->gui_layer_minscale = $row["gui_layer_minscale"];
+			$this->objLayer[$layer_cnt]->gui_layer_maxscale = $row["gui_layer_maxscale"];
+			$this->objLayer[$layer_cnt]->gui_layer_style = $row["gui_layer_style"];
+			$this->objLayer[$layer_cnt]->gui_layer_wfs_featuretype = $row["gui_layer_wfs_featuretype"];
+			
+			$sql = "Select * from layer_epsg where fkey_layer_id = $1 ORDER BY fkey_layer_id";
+			$v = array($layer_id);
+			$t = array('i');
+			$res_layer_epsg = db_prep_query($sql,$v,$t);
+			
+			$count_layer_epsg=0;
+			while($row2 = db_fetch_array($res_layer_epsg)){
+				$this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["epsg"]=$row2["epsg"];
+				$this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["minx"]=$row2["minx"];
+				$this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["miny"]=$row2["miny"];
+				$this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["maxx"]=$row2["maxx"];
+				$this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["maxy"]=$row2["maxy"];
+				$count_layer_epsg++;
+			}
+			
+			### handle styles
+			$sql = "SELECT * FROM layer_style WHERE fkey_layer_id = $1 ";
+			$v = array($layer_id);
+			$t = array('i');
+			$res_style = db_prep_query($sql,$v,$t);
+			$count_layer_style = 0;
+			while($row2 = db_fetch_array($res_style)){
+				$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["name"]=$row2["name"];
+				$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["title"]=$row2["title"];
+				if($wmsowsproxy != ""){
+					if($row2["legendurl"]!=''){
+						$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"]=$owsproxyurl.
+						"REQUEST=getlegendgraphic&VERSION=".$this->wms_version."&LAYER=".$this->objLayer[$layer_cnt]->layer_name."&FORMAT=".$row2["legendurlformat"].
+						"&STYLE=".$row2["name"];
+					}
+				}
+				else{
+					if($row2["legendurl"]!=''){
+						$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"]=$row2["legendurl"];
+						#$e = new mb_exception("legendurl = ".$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"]);
+					}
+				}
+				$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurlformat"]=$row2["legendurlformat"];
+				$count_layer_style++;
+			}
+			$count++;
+		}
+	   }
+	/** end createObjfromDB **/
+	
+	  /**
+	* function checkObjExistsInDB()
+	*
+	* this function checks wether the onlineresource already exists in the database.
+	*/ 
+	function checkObjExistsInDB(){
+	
+		$sql = "Select * from wms where wms_getcapabilities = $1";
+		$v = array($this->wms_getcapabilities);
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
+		$res_count= db_num_rows($res);	  
+		$wms_id=0;
+		if($res_count>0){
+			$count=0;
+			while($row = db_fetch_array($res)){
+				$wms_id=$row["wms_id"];
+				$count++;
+			}
+		}
+		return $wms_id;
+	}
+	
+	function displayDBInformation(){
+		echo $this->wms_getcapabilities;
+		$sql="Select * from wms where wms_getcapabilities = $1";
+		$v = array($this->wms_getcapabilities);
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
+		$count=0;
+		while($row = db_fetch_array($res)){
+		echo "count: ".$count."<br>";
+			$wms_id=$row["wms_id"];
+			echo "version: " .$wms_id." <br>";
+			echo "title: " .$row["wms_version"]. " <br>";
+			echo "abstract: " . $row["wms_title"] . " <br>";
+			echo "maprequest: " .$row["wms_abstract"] . " <br>";
+			echo "capabilitiesrequest: " . $row["wms_getcapabilities"] . " <br>";
+			echo "featureinforequest: " . $row["wms_getmap"]. " <br>";
+			echo "gui_wms_mapformat: " . $row["wms_getfeatureinfo"] . " <br>---------<br>";
+			$count++;
+		}
+	   echo "----<br> wms_id: ".$wms_id."<br>";
+	   
+	   $sql = "Select * from gui_wms where fkey_wms_id = $1";
+	   $v = array($wms_id);
+	   $t = array('i');
+	   echo "sql: ".$sql." <br>---------<br>";
+	   $res = db_prep_query($sql,$v,$t);
+	   $res_count= db_num_rows($res); 
+	   echo "result count: ".$res_count." <br>---------<br>";
+	   
+	   $count=0;
+	   while($row = db_fetch_array($res)){
+	    	echo "gui_wms_featureinfoformat: " . $row["gui_wms_featureinfoformat"]." <br>";
+	    	echo "gui_wms_exceptionformat: " .  $row["gui_wms_exceptionformat"]. " <br>";
+	    	echo "gui_wms_epsg: " .  $row["gui_wms_epsg"]. " <br>";
+	      $count++;
+	   }
+		
+	   #db_close($connect);
+	}
+
+	function checkObj(){
+		if($this->wms_getcapabilities == '' || $this->wms_getmap == '' ){
+			echo "<br>Missing parameters: <br>";
+			$this->displayWMS();
+			print_r($this);
+			echo "<br> Data not committed<br>";
+			die();
+		}
+	}
+	
+	/**
+	 * Selects all WMS of the current user from the database.
+	 * Then it creates the corresponding WMS object and returns
+	 * these objects as an array.
+	 * 
+	 * @return wms[]
+	 * @param $appId String
+	 */
+	public static function selectMyWmsByApplication ($appId) {
+		// check if user is permitted to access the application
+		$currentUser = new User($_SESSION["mb_user_id"]);
+		$appArray = $currentUser->getApplicationsByPermission(false);
+		if (!in_array($appId, $appArray)) {
+			$e = new mb_warning("class_wms.php: selectMyWmsByApplication(): User '" . $currentUser . "' is not allowed to acces application '" . $appId . "'.");
+			return array();
+		}
+		
+		// get WMS of this application
+		$sql = "SELECT fkey_wms_id FROM gui_wms WHERE " . 
+				"fkey_gui_id = $1 ORDER BY gui_wms_position";
+		$v = array($appId);
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
+		
+		// instantiate PHP objects and store in array
+		$wmsArray = array();
+		while ($row = db_fetch_array($res)) {
+			$currentWms = new wms();
+			$currentWms->createObjFromDB($appId, $row["fkey_wms_id"]);
+			array_push($wmsArray, $currentWms);
+		}
+		return $wmsArray;
+	}
+}
+class layer extends wms {	
+	var $layer_id;
+	var $layer_parent;
+	var $layer_name;
+	var $layer_title;
+	var $layer_abstract;
+	var $layer_pos;
+	var $layer_queryable;
+	var $layer_minscale;
+	var $layer_maxscale;	
+    var $layer_dataurl_href;
+    var $layer_metadataurl;
+    var $layer_keyword = array();
+	var $layer_epsg = array();
+	var $layer_style = array();
+	
+	var $gui_layer_wms_id;
+	var $gui_layer_status = 1;
+	var $gui_layer_selectable = 1;
+	var $gui_layer_visible = 0;
+	var $gui_layer_queryable = 0;
+	var $gui_layer_querylayer = 0;
+	var $gui_layer_style = NULL;	
+	
+	function layer($id,$parent){
+		$this->layer_id = $id;
+		$this->layer_parent = $parent;	
+		//var_dump($this);	
+	}
+
+	public function __toString () {
+		$e = new mb_exception("TITLE: " . $this->layer_title);
+		return $this->layer_title;
+	}
+	
+}
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list