[Mapbender-commits] r3417 - in branches/2.5/http: classes javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Jan 8 09:47:47 EST 2009


Author: christoph
Date: 2009-01-08 09:47:47 -0500 (Thu, 08 Jan 2009)
New Revision: 3417

Added:
   branches/2.5/http/classes/class_map.php
   branches/2.5/http/classes/class_wmcToXml.php
   branches/2.5/http/javascripts/mod_loadwmc.js
   branches/2.5/http/javascripts/mod_loadwmc_list.php
   branches/2.5/http/php/mod_loadwmc_server.php
   branches/2.5/http/php/mod_savewmc_server.php
Modified:
   branches/2.5/http/classes/class_administration.php
   branches/2.5/http/classes/class_user.php
   branches/2.5/http/classes/class_wmc.php
   branches/2.5/http/classes/class_wms.php
   branches/2.5/http/javascripts/map.js
   branches/2.5/http/javascripts/mod_initWmc.php
   branches/2.5/http/javascripts/mod_loadwmc.php
   branches/2.5/http/javascripts/mod_savewmc.php
   branches/2.5/http/php/mod_mapOV.php
Log:
http://trac.osgeo.org/mapbender/ticket/364

Modified: branches/2.5/http/classes/class_administration.php
===================================================================
--- branches/2.5/http/classes/class_administration.php	2009-01-08 14:41:46 UTC (rev 3416)
+++ branches/2.5/http/classes/class_administration.php	2009-01-08 14:47:47 UTC (rev 3417)
@@ -106,6 +106,54 @@
 		}
 	}
 
+	/**
+	 * 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)
      *
@@ -633,8 +681,8 @@
 	/**
 	 * @deprecated
 	 */
-	function getGuisByPermission($mb_user_id,$ignorepublic){
-		$e = new mb_notice("administration->getGuisByPermission is deprecated, use user->getApplicationsByPermission instead!"); 
+	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);
 	}
@@ -1085,10 +1133,10 @@
 	 * @param integer 		userid the user-ID of the current user
 	 * @return integer[] 	the IDs of the wfs_conf-table
 	 */
-	 function getWfsConfByPermission($userid){
+	 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/2.5/http/classes/class_map.php
===================================================================
--- branches/2.5/http/classes/class_map.php	                        (rev 0)
+++ branches/2.5/http/classes/class_map.php	2009-01-08 14:47:47 UTC (rev 3417)
@@ -0,0 +1,458 @@
+<?php
+require_once(dirname(__FILE__)."/../classes/class_bbox.php");
+/**
+ * Representing a map object, identical to the JS object in javascripts/map.js
+ * @class
+ */
+class Map {
+
+	private $width;
+	private $height;
+	private $frameName;
+	private $elementName = "maps";
+	private $extent;
+	private $isOverview = false;
+	private $wmsArray = array();
+	
+	/**
+	 * @destructor
+	 * @param
+	 */
+	function __destruct() {
+	}
+
+	/**
+	 * @constructor
+	 * @param
+	 */
+	function __construct() {
+	}
+	
+	//-------------------------------------------------------------------------
+	// getter and setter
+	//-------------------------------------------------------------------------
+	/**
+	 * @param $value Integer
+	 */
+	public function setWidth ($value) {
+		$this->width = $value;
+	}
+
+	/**
+	 * 
+	 * @return 
+	 */
+	public function getWidth () {
+		return $this->width;
+	}
+
+	/**
+	 * @param $value Integer
+	 */
+	public function setHeight ($value) {
+		$this->height = $value;
+	}
+
+	/**
+	 * 
+	 * @return 
+	 */
+	public function getHeight () {
+		return $this->height;
+	}
+
+	/**
+	 * @param $value String
+	 */
+	public function setFrameName ($value) {
+		$this->frameName = $value;
+	}
+
+	/**
+	 * @param $value String
+	 */
+	public function setElementName ($value) {
+		$this->elementName = $value;
+	}
+
+	/**
+	 * 
+	 * @return String
+	 */
+	public function getFrameName () {
+		return $this->frameName;	
+	}
+	
+	/**
+	 * @param $value String
+	 */
+	public function setExtent ($aMapbenderBbox) {
+		$this->extent = $aMapbenderBbox;
+	}
+
+	/**
+	 * 
+	 * @return Mapbender_bbox 
+	 */
+	public function getExtent () {
+		return $this->extent;	
+	}
+	
+	/**
+	 * 
+	 * @return String EPSG code of the map.
+	 */
+	public function getEpsg () {
+		return $this->extent->epsg;	
+	}
+	
+	/**
+	 * 
+	 * @return 
+	 */
+	public function getWmsArray () {
+		return $this->wmsArray;	
+	}
+	
+	/**
+	 * 
+	 * @return 
+	 * @param $wmsArray Object
+	 */
+	public function setWmsArray ($wmsArray) {
+		$this->wmsArray = $wmsArray;
+	}
+	
+	/**
+	 * 
+	 * @return 
+	 */
+	public function isOverview () {
+		return $this->isOverview;
+	}
+	
+	public function setIsOverview ($bool) {
+		$this->isOverview = $bool;
+	}
+	
+	/**
+	 * @param $value Object
+	 */
+	public function addWms ($value) {
+		array_push($this->wms, $value);
+	}	
+
+
+	// ------------------------------------------------------------------------
+	// map manipulation
+	// ------------------------------------------------------------------------
+
+	/**
+	 * Appends the WMS of another map to this map.
+	 * 
+	 * @param $anotherMap Map
+	 */
+	public function append ($anotherMap) {
+		$this->wmsArray = array_merge($anotherMap->getWmsArray(), $this->wmsArray);
+	}
+		
+	/**
+	 * Merges this map with another map: Copies the map settings from the 
+	 * other map and merges the WMS (keeping the settings of the other
+	 * map if there are duplicates)
+	 * 
+	 * @param $anotherMap Map
+	 */
+	public function merge ($anotherMap) {
+		$this->width = $anotherMap->width;
+		$this->height = $anotherMap->height;
+		$this->frameName = $anotherMap->frameName;
+		$this->elementName = $anotherMap->elementName;
+		$this->extent = $anotherMap->extent;
+		$this->isOverview = $anotherMap->isOverview;
+		$this->wmsArray = wms::merge(array_merge($anotherMap->getWmsArray(), $this->wmsArray));
+	}
+
+	/**
+	 * Adds WMS to this map
+	 * 
+	 * @return 
+	 */
+	public function appendWmsArray ($wmsArray) {
+		$this->wmsArray = array_merge($this->wmsArray, $wmsArray);
+	}
+	
+	/**
+	 * Merge WMS into this map
+	 * 
+	 * @return 
+	 */
+	public function mergeWmsArray ($wmsArray) {
+		$this->wmsArray = wms::merge(array_merge($this->wmsArray, $wmsArray));
+	}
+
+
+	// ------------------------------------------------------------------------
+	// Instantiation
+	// ------------------------------------------------------------------------
+	/**
+	 * 
+	 * @return 
+	 * @param $jsMapObject Object
+	 */
+	public function createFromJs ($jsMapObject) {
+		$arrayBBox = explode(",", $jsMapObject->extent);
+		$minx = floatval($arrayBBox[0]);
+		$miny = floatval($arrayBBox[1]);
+		$maxx = floatval($arrayBBox[2]);
+		$maxy = floatval($arrayBBox[3]);
+		$srs = $jsMapObject->epsg;
+		$bbox = new Mapbender_bbox($minx, $miny, $maxx, $maxy, $srs);
+
+		$this->width = $jsMapObject->width;
+		$this->height = $jsMapObject->height;
+		$this->frameName = $jsMapObject->frameName;
+		$this->extent = $bbox;
+		
+		if (isset($jsMapObject->isOverview) && $jsMapObject->isOverview == "1") {
+			$this->isOverview = true;
+		}
+
+		for ($i=0; $i < count($jsMapObject->wms); $i++){
+	
+			$currentWms = $jsMapObject->wms[$i];
+			$wms = new wms();
+
+			//
+			// set WMS data
+			//
+			$wms->wms_id = $currentWms->wms_id;
+			$wms->wms_version = $currentWms->wms_version;
+			$wms->wms_title = $currentWms->wms_title;
+			$wms->wms_abstract = $currentWms->wms_abstract;
+			$wms->wms_getmap = $currentWms->wms_getmap;
+			$wms->wms_getfeatureinfo = $currentWms->wms_getfeatureinfo;
+			$wms->wms_getlegendurl = $currentWms->wms_getlegendurl;
+			$wms->wms_filter = $currentWms->wms_filter;
+			$wms->gui_epsg = $currentWms->gui_epsg;
+			$wms->gui_minx = $currentWms->gui_minx;
+			$wms->gui_miny = $currentWms->gui_miny;
+			$wms->gui_maxx = $currentWms->gui_maxx;
+			$wms->gui_maxy = $currentWms->gui_maxy;
+			$wms->gui_wms_mapformat = $currentWms->gui_wms_mapformat;
+			$wms->gui_wms_featureinfoformat = $currentWms->gui_wms_featureinfoformat;
+			$wms->gui_wms_exceptionformat = $currentWms->gui_wms_exceptionformat;
+			$wms->gui_wms_opacity = $currentWms->wms_opacity;
+			$wms->gui_wms_sldurl = $currentWms->gui_wms_sldurl;
+			$wms->gui_wms_visible = $currentWms->gui_wms_visible;
+			$wms->gui_wms_epsg = $currentWms->gui_wms_epsg;
+			$wms->data_type = $currentWms->data_type;
+			$wms->data_format = $currentWms->data_format;
+
+			for ($k = 0; $k < count($currentWms->objLayer); $k++){
+				// the current layer of the JSON map object
+				$currentLayer = $currentWms->objLayer[$k];
+
+				// add new layer to WMS
+				$pos = $currentLayer->layer_pos;
+				$parent = $currentLayer->layer_parent;
+				$wms->addLayer($pos, $parent); 
+
+				$newLayerIndex = count($wms->objLayer) - 1;
+				// $newLayer is a short cut to the layer we just added
+				$newLayer = $wms->objLayer[$newLayerIndex];
+				
+				// set layer data
+				$newLayer->layer_uid = $currentLayer->layer_uid;
+				$newLayer->layer_name = $currentLayer->layer_name;
+				$newLayer->layer_title = $currentLayer->layer_title;
+				$newLayer->layer_dataurl_href = $currentLayer->layer_dataurl_href;
+				$newLayer->layer_pos = $currentLayer->layer_pos;
+				$newLayer->layer_queryable = $currentLayer->layer_queryable;
+				$newLayer->layer_minscale = $currentLayer->layer_minscale;
+				$newLayer->layer_maxscale = $currentLayer->layer_maxscale;
+				$newLayer->layer_metadataurl = $currentLayer->metadataurl;
+				$newLayer->gui_layer_wms_id = $currentLayer->gui_layer_wms_id;
+//				$newLayer->gui_layer_wms_id = $wms->objLayer[0]->layer_uid;
+				$newLayer->gui_layer_status = $currentLayer->gui_layer_status;
+				$newLayer->gui_layer_style = $currentLayer->gui_layer_style;
+				$newLayer->gui_layer_selectable = $currentLayer->gui_layer_selectable;
+
+				if ($this->isOverview) {
+					preg_match_all("/LAYERS\=([^&]*)/", $jsMapObject->mapURL[0], $resultMatrix);
+					$layerList = $resultMatrix[1][0];
+					$layerListArray = explode(",", $layerList);
+					$newLayer->gui_layer_visible = (in_array($currentLayer->layer_name, $layerListArray)) ? 1 : 0;
+				}
+				else {
+					$newLayer->gui_layer_visible = $currentLayer->gui_layer_visible;
+				}
+				$newLayer->gui_layer_queryable = $currentLayer->gui_layer_queryable;
+				$newLayer->gui_layer_querylayer = $currentLayer->gui_layer_querylayer;
+				$newLayer->gui_layer_minscale = $currentLayer->gui_layer_minscale;
+				$newLayer->gui_layer_maxscale = $currentLayer->gui_layer_maxscale;
+				$newLayer->gui_layer_wfs_featuretype = $currentLayer->gui_layer_wfs_featuretype;
+
+				// BEWARE THIS IS SUPER UGLY CODE
+				$newLayer->layer_epsg = array();
+				for ($z = 0; $z < count($currentLayer->layer_epsg); $z++) {
+					$newLayer->layer_epsg[$z] = array();
+					$newLayer->layer_epsg[$z]["epsg"] = $currentLayer->layer_epsg[$z]->epsg;
+					$newLayer->layer_epsg[$z]["minx"] = $currentLayer->layer_epsg[$z]->minx;
+					$newLayer->layer_epsg[$z]["miny"] = $currentLayer->layer_epsg[$z]->miny;
+					$newLayer->layer_epsg[$z]["maxx"] = $currentLayer->layer_epsg[$z]->maxx;
+					$newLayer->layer_epsg[$z]["maxy"] = $currentLayer->layer_epsg[$z]->maxy;
+				}
+				
+				// BEWARE THIS IS SUPER UGLY CODE
+				$newLayer->layer_style = array();
+				for ($z = 0; $z < count($currentLayer->layer_style); $z++) {
+					$newLayer->layer_style[$z] = array();
+					$newLayer->layer_style[$z]["name"] = $currentLayer->layer_style[$z]->name ? $currentLayer->layer_style[$z]->name : "default";
+					$newLayer->layer_style[$z]["title"] = $currentLayer->layer_style[$z]->title ? $currentLayer->layer_style[$z]->title : "default";
+					$newLayer->layer_style[$z]["legendurl"] = $currentLayer->layer_style[$z]->legendurl;
+					$newLayer->layer_style[$z]["legendurlformat"] = $currentLayer->layer_style[$z]->legendurlformat;
+				}
+
+			}
+			array_push($this->wmsArray, $wms);
+		}
+		return true;
+	}
+	
+	
+	// ------------------------------------------------------------------------
+	// database functions
+	// ------------------------------------------------------------------------
+	public static function selectMainMapByApplication ($appId) {
+		return map::selectByApplication($appId, "mapframe1");
+	}
+	
+	public static function selectOverviewMapByApplication ($appId) {
+		$currentMap = map::selectByApplication($appId, "overview");
+		if ($currentMap !== null) {
+			$currentMap->setIsOverview(true);
+		}
+		return $currentMap;
+	}
+
+
+	// ------------------------------------------------------------------------
+	// Output
+	// ------------------------------------------------------------------------
+	/**
+	 * Returns an array of string, which are JS statements.
+	 * @return String[]
+	 */
+	public function toJavaScript ($wmsIndex) {
+		$jsCodeArray = array();
+
+		// initialise map object
+		if ($wmsIndex === null) {
+			$wmsIndex = "null";
+		}
+		$registerMapString = "mb_registerMapObj('" . 
+			$this->frameName . "', " . 
+			"'maps', " . 
+			$wmsIndex . ", " . 
+			$this->width . ", " . 
+			$this->height . ");"; 
+		array_push($jsCodeArray, $registerMapString);
+
+//		$e = new mb_notice("Map to JS: ov? " . $this->isOverview);
+
+		// if map is overview...
+		if ($this->isOverview) {
+			// ...set overview flag
+			$setOverviewFlagString = "mb_mapObj[mb_mapObj.length-1].isOverview = true;";
+			array_push($jsCodeArray, $setOverviewFlagString);
+		}
+		
+		// set width
+		$setMapframeWidth = "document.getElementById('" . $this->frameName . "')." . 
+			"style.width = " . $this->width . ";";
+		array_push($jsCodeArray, $setMapframeWidth);
+
+		// set height
+		$setMapframeHeight = "document.getElementById('" . $this->frameName . "')." . 
+			"style.height = " . $this->height . ";";
+		array_push($jsCodeArray, $setMapframeHeight);
+
+		// calculate extent
+		$calcExtentString = "mb_calculateExtent('" . 
+			$this->frameName . "', " .
+			$this->extent->min->x . ", " . 
+			$this->extent->min->y . ", " . 
+			$this->extent->max->x . ", " . 
+			$this->extent->max->y . ");"; 
+		array_push($jsCodeArray, $calcExtentString);
+		return $jsCodeArray;
+	}
+
+
+	// ------------------------------------------------------------------------
+	// PRIVATE FUNCTIONS
+	// ------------------------------------------------------------------------
+	
+	private static function selectByApplication ($appId, $frameName) {
+		// find the mapframe in the application elements...
+		$sql = "SELECT * FROM gui_element WHERE fkey_gui_id = $1 AND " . 
+				"e_id = $2 AND e_public = 1 LIMIT 1";
+		$v = array($appId, $frameName);
+		$t = array('s', 's');
+		$res = db_prep_query($sql,$v,$t);
+		$row = db_fetch_array($res);
+		
+		// if found...
+		if ($row) {
+			$currentMap = new Map();
+
+			// use settings from database
+			$currentMap->setWidth($row["e_width"]);
+			$currentMap->setHeight($row["e_height"]);
+			$currentMap->setFrameName($row["e_id"]);
+			
+			// get the WMS 
+			$wmsArray = wms::selectMyWmsByApplication($appId);
+			
+//			$e = new mb_notice("WMS in this map: " . implode(",", $wmsArray));
+			
+			// if this is the overview, find the WMS index and 
+			// reset the WMS array
+			// BEWARE, SUPER UGLY CODE AHEAD!!
+			// (BUT THERE IS NO OTHER WAY TO DO IT)
+			if (strpos($row["e_src"], "mod_mapOV.php?wms") !== false) {
+//				$e = new mb_exception("guess this is the OV");
+				$pattern = "/[\.\/a-zA-Z_]*\?wms=([0-9]*)[^0-9]*/";
+				$ovIndex = preg_replace($pattern, "\$1", $row["e_src"]);
+//				$e = new mb_exception("OV index: " . $ovIndex);
+				if (!$ovIndex) {
+					$ovIndex = 0;
+				}
+				$wmsArray = array($wmsArray[$ovIndex]);	
+//				$e = new mb_notice("WMS in this map (corrected): " . implode(",", $wmsArray));
+			}
+			else {
+//				$e = new mb_exception("guess this is NOT the OV");
+			}
+
+			$currentMap->wmsArray = $wmsArray;
+			
+			// EXTENT
+			$minx = $wmsArray[0]->objLayer[0]->layer_epsg[0]["minx"];
+			$miny = $wmsArray[0]->objLayer[0]->layer_epsg[0]["miny"];
+			$maxx = $wmsArray[0]->objLayer[0]->layer_epsg[0]["maxx"];
+			$maxy = $wmsArray[0]->objLayer[0]->layer_epsg[0]["maxy"];
+			$epsg = $wmsArray[0]->objLayer[0]->layer_epsg[0]["epsg"];
+			$mapExtent = new Mapbender_bbox($minx, $miny, $maxx, $maxy, $epsg);
+			$currentMap->setExtent($mapExtent);
+			return $currentMap;			
+		}
+		else {
+			return null;
+		}
+	}
+	
+
+}
+?>

Modified: branches/2.5/http/classes/class_user.php
===================================================================
--- branches/2.5/http/classes/class_user.php	2009-01-08 14:41:46 UTC (rev 3416)
+++ branches/2.5/http/classes/class_user.php	2009-01-08 14:47:47 UTC (rev 3417)
@@ -38,6 +38,13 @@
 	}	
 	
 	/**
+	 * @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
@@ -129,5 +136,24 @@
 		}
 		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
+?>

Modified: branches/2.5/http/classes/class_wmc.php
===================================================================
--- branches/2.5/http/classes/class_wmc.php	2009-01-08 14:41:46 UTC (rev 3416)
+++ branches/2.5/http/classes/class_wmc.php	2009-01-08 14:47:47 UTC (rev 3417)
@@ -16,56 +16,87 @@
 # 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__)."/../../core/globalSettings.php");
 
 require_once(dirname(__FILE__) . "/../classes/class_wms.php");
 require_once(dirname(__FILE__) . "/../classes/class_layer_monitor.php");
 require_once(dirname(__FILE__) . "/../classes/class_point.php");
 require_once(dirname(__FILE__) . "/../classes/class_bbox.php");
 require_once(dirname(__FILE__) . "/../classes/class_json.php");
+require_once(dirname(__FILE__) . "/../classes/class_map.php");
+require_once(dirname(__FILE__) . "/../classes/class_administration.php");
+require_once(dirname(__FILE__) . "/../classes/class_wmcToXml.php");
 
-function mb_utf8_encode ($str) {
-	if(CHARSET!="UTF-8") return utf8_encode($str);
-	return $str;
-}
-function mb_utf8_decode ($str) {
-	if(CHARSET!="UTF-8") return utf8_decode($str);
-	return $str;
-}
-function sepNameSpace($s){
-	$c = strpos($s,":"); 
-	if($c>0)return substr($s,$c+1);
-	return $s;
-}
-
 /**
  * Implementation of a Web Map Context Document, WMC 1.1.0
+ * 
+ * Use cases:
+ * 
+ * Instantiation (1) create a WMC object from a WMC XML document
+ * 		$myWmc = new wmc();
+ * 		$myWmc->createFromXml($xml);
+ * 
+ *    If you want to create a WMC object from a WMC in the database
+ *    	$xml = wmc::getDocument($wmcId);
+ * 		$myWmc = new wmc();
+ * 		$myWmc->createFromXml($xml);
+ *    
+ * 
+ * Instantiation (2) create a WMC from the client side
+ * 		$myWmc = new wmc();
+ * 		$myWmc->createFromJs($mapObject, $generalTitle, $extensionData);
+ * 	
+ * 	  	(creates a WMC from the JS data and then creates an object from that WMC)
+ * 
+ * Output (1) (do Instantiation first) Load a WMC into client
+ * 		This will return an array of JS statements
+ *  
+ * 		$myWmc->toJavaScript();
+ * 
+ * Output (2) (do Instantiation first) Merge with another WMC, then load
+ * 	
+ * 		$myWmc->merge($anotherWmcXml);
+ * 		$myWmc->toJavaScript();
+ * 
  */
 class wmc {
+	/**
+	 * Representing the main map in a map application
+	 * @var Map
+	 */
+	var $mainMap;
 
+	/**
+	 * Representing an (optional) overview map in a map application
+	 * @var Map
+	 */
+	var $overviewMap;
+
+	/**
+	 * @var Array
+	 */
+	var $generalExtensionArray = array();
+
+	/**
+	 * The XML representation of this WMC.
+	 * @var String
+	 */
 	var $xml;
 	
+	// constants
+	var $monitoringIsOn = false;
+	var $saveWmcAsFile = false;
+	var $extensionNamespace = "mapbender";
+	var $extensionNamespaceUrl = "http://www.mapbender.org";
+		
+	// set in constructor
 	var $wmc_id;
+	var $userId;
+
+	// set during parsing
 	var $wmc_version;
-	var $wmc_windowWidth;
-	var $wmc_windowHeight;
-	var $wmc_bBox_SRS;
-	var $wmc_bBox_minx;
-	var $wmc_bBox_maxx;
-	var $wmc_bBox_miny;
-	var $wmc_bBox_maxy;
 	var $wmc_name;
 	var $wmc_title;
 	var $wmc_abstract;
-	var $wmc_general_extension = array();
-	var $wmc_logourl;
-	var $wmc_logourl_format;
-	var $wmc_logourl_type;
-	var $wmc_logourl_width;
-	var $wmc_logourl_height;
-	var $wmc_descriptionurl;
-	var $wmc_descriptionurl_format;
-	var $wmc_descriptionurl_type;
 	var $wmc_keyword = array();
 	var $wmc_contactposition;
 	var $wmc_contactvoicetelephone;
@@ -79,1294 +110,995 @@
 	var $wmc_contactstateorprovince;
 	var $wmc_contactpostcode;
 	var $wmc_contactcountry;
-				
-				
-	var $wmc_wms_title = array();
-	var $wmc_layer_queryable = array();
-	var $wmc_layer_hidden = array();
-	var $wmc_wms_id = array();
-	var $wmc_wms_service = array();
-	var $wmc_wms_version = array();
-	var $wmc_wms_layer_id = array();
-	var $wmc_layer_wfs_featuretype = array();
-	var $wmc_layer_id = array();
-	var $wmc_layer_pos = array();
-	var $wmc_layer_parent = array();
-	var $wmc_layer_querylayer = array();
-	var $wmc_layer_title = array();
-	var $wmc_layer_name = array();
-	var $wmc_layer_abstract = array();
-	var $wmc_layer_srs = array();
-	var $wmc_wms_serviceURL = array();
-	var $wmc_layer_format_current = array();
-	var $wmc_layer_dataurl = array();
-	var $wmc_layer_metadataurl = array();
-	var $wmc_layer_minscale = array();
-	var $wmc_layer_maxscale = array();
-	var $wmc_gui_layer_minscale = array();
-	var $wmc_gui_layer_maxscale = array();
-	var $wmc_layer_format = array();
-	var $wmc_layer_style_current = array();
-	var $wmc_layer_style_name = array();
-	var $wmc_layer_style_title = array();
-	var $wmc_layer_style_legendurl = array();
-	var $wmc_layer_style_legendurl_width = array();
-	var $wmc_layer_style_legendurl_height = array();
-	var $wmc_layer_style_legendurl_format = array();
-	var $wmc_layer_style_legendurl_type = array();
-	var $wmc_layer_style_sld_url = array();
-	var $wmc_layer_style_sld_type = array();
-	var $wmc_layer_style_sld_title = array();
-	
-	var $wmc_wms_count = 0;
-			
-	/*	
-	 	var $data_type = array(); 
-		var $data_format = array();
-		
-		var $objLayer = array(); 
-		  
-		var $gui_wms_mapformat;
-		var $gui_wms_featureinfoformat;
-		var $gui_wms_exceptionformat;
-		var $gui_wms_epsg;
-		  
-		var $default_epsg = 0;
-  */
-	var $monitoringIsOn = false;
-  		
-function wmc() {
-} 
+	var $wmc_logourl;
+	var $wmc_logourl_format;
+	var $wmc_logourl_type;
+	var $wmc_logourl_width;
+	var $wmc_logourl_height;
+	var $wmc_descriptionurl;
+	var $wmc_descriptionurl_format;
+	var $wmc_descriptionurl_type;
 
-/**
- * Saves the current WMC in the log folder.
- * 
- * @return string the filename of the WMC document.
- */
-function saveAsFile() {
-	$filename = "wmc_" . date("Y_m_d_H_i_s") . ".log";
-	$logfile = "../../log/" . $filename;
+	public function __construct () {
+		$this->userId = $_SESSION["mb_user_id"];
+		$this->wmc_id = time();
+	} 
 	
-	if($h = fopen($logfile,"a")){
-		$content = $this->xml;
-		if(!fwrite($h,$content)){
-			$e = new mb_exception("class_wmc.php: failed to write wmc.");
+	// ---------------------------------------------------------------------------
+	// INSTANTIATION
+	// ---------------------------------------------------------------------------
+
+	/**
+	 * Parses the XML string and instantiates the WMC object.
+	 * 
+	 * @param $xml String
+	 */
+	public function createFromXml ($xml) {
+		return $this->createObjFromWMC_xml($xml);
+	}
+
+	/**
+	 * Loads a WMC from the database.
+	 * 
+	 * @param integer $wmc_id the ID of the WMC document in the database table "mb_user_wmc"
+	 */
+	function createFromDb($wmcId){
+		$this->monitoringIsOn = true;
+		
+		$doc = wmc::getDocument($wmcId);
+		if ($doc === false) {
 			return false;
 		}
-		fclose($h);
+		$this->createObjFromWMC_xml($doc);
+		return true;
 	}
-	return $filename;
-}
 
-/**
- * @return string the title of the WMC.
- */
-function getTitle() {
-	return $this->wmc_title;
-}
+	public function createFromApplication ($appId) {
+		// get the map objects "overview" and "mapframe1"
+		$this->mainMap = map::selectMainMapByApplication($appId);
+		$this->overviewMap = map::selectOverviewMapByApplication($appId);
+		$this->createXml();
+		$this->saveAsFile();
+	}
 
-/**
- * @return Integer the number of (unique?) WMS contained in this WMC.
- */
-function getNumberOfWms () {
-	return $this->wmc_wms_count;
-}
-
-/**
- * Creates a WMC object from a JS map object {@see map.js}
- * 
- * @param object $mapObject a map object
- * @param integer $user_id the ID of the current user
- * @param string $generalTitle the desired title of the WMC
- * @param object $extensionData data exclusive to Mapbender, which will be 
- * 								mapped into the extension part of the WMC
- */
-function createWMCFromObj($mapObject, $user_id, $generalTitle, $extensionData) {
-	$this->wmc_id = $user_id . '_' . time();
+	/**
+	 * Creates a WMC object from a JS map object {@see map_obj.js}
+	 * 
+	 * @param object $mapObject a map object
+	 * @param integer $user_id the ID of the current user
+	 * @param string $generalTitle the desired title of the WMC
+	 * @param object $extensionData data exclusive to Mapbender, which will be 
+	 * 								mapped into the extension part of the WMC
+	 */
+	public function createFromJs($mapObject, $generalTitle, $extensionData) {
 	
-	$generalWidth = $mapObject->width;
-	$generalHeight = $mapObject->height;
-	$generalBboxSrs = $mapObject->epsg;
-	
-	$arrayBBox = explode(",", $mapObject->extent);
-	$generalBboxMinx = floatval($arrayBBox[0]);
-	$generalBboxMiny = floatval($arrayBBox[1]);
-	$generalBboxMaxx = floatval($arrayBBox[2]);
-	$generalBboxMaxy = floatval($arrayBBox[3]);
-	
-	$generalName = "Mapbender WMC"; // TO do : insert proper data
-	$generalKeywords = array("Mapbender", "WMC"); // TO do : insert proper data
-	$generalAbstract = ""; // TO do : insert proper data
-	$generalLogoUrl = ""; // TO do : insert proper data
-	$generalLogoUrlWidth = ""; // TO do : insert proper data
-	$generalLogoUrlHeight = ""; // TO do : insert proper data
-	$generalLogoUrlFormat = ""; // TO do : insert proper data
-	$generalDescriptionUrl = ""; // TO do : insert proper data
-	$generalContactPerson = "";
-	$generalContactOrganization = "";
-	$generalContactPosition = "";
-	$generalContactAddressType = "";
-	$generalContactAddress = "";
-	$generalContactCity = "";
-	$generalContactStateOrProvince = "";
-	$generalContactPostCode = "";
-	$generalContactCountry = "";
-	$generalContactVoiceTelephone = "";
-	$generalContactFacsimileTelephone = "";
-	$generalContactElectronicMailAddress = "";
-			
-	$extension_namespace = "mapbender";
-	
-	// LayerList variables
-	$layerHidden = "";
-	$layerQueryable = "";
-	$layerAbstract = "";
-	$layerName = "";
-	$layerSrs = "";
-	$layerDataUrl = "";
-	$layerMetadataUrl = "";
-	$layerFormat = "";
-	$layerFormat_current = "";
-	$layerStyle_current = "";
-	$layerStyle_name = "";
-	$layerStyle_title = "";
-	$layerStyle_legendURL = "";
-	$layerStyle_legendURL_width = "";
-	$layerStyle_legendURL_height = "";
-	$layerStyle_legendURL_format = "";		
-	
-	// generate XML
-	$doc = new DOMDocument("1.0", CHARSET);
-	$doc->preserveWhiteSpace = false;
-	
-	// ViewContext
-	$e_view_context = $doc->createElementNS("http://www.opengis.net/context", "ViewContext");
-	
-	
-	$e_view_context->setAttribute("version", "1.0.0");
-	$e_view_context->setAttribute("id", $this->wmc_id);
-	$e_view_context->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-	$e_view_context->setAttribute("xmlns:mapbender", "http://www.mapbender.org");
-	$e_view_context->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
-	$e_view_context->setAttribute("xsi:SchemaLocation", "http://schemas.opengis.net/context/1.0.0/context.xsd");
-	
-		// General
-		$e_general = $doc->createElement("General");
-	
-			$e_window = $doc->createElement("Window");
-			if (!empty($generalWidth) && !empty($generalHeight)) {
-				$e_window->setAttribute("width", $generalWidth);
-				$e_window->setAttribute("height", $generalHeight);
+		if (count($mapObject) > 2) {
+			$e = new mb_exception("Save WMC only works for two concurrent map frames (overview plus main) at the moment.");
+		}
+		
+		// set extension data		
+		$this->generalExtensionArray = $extensionData;
+
+		// set title
+		$this->wmc_title = $generalTitle;
+		
+		// create the map objects
+		for ($i = 0; $i < count($mapObject); $i++) {
+			$currentMap = new Map();
+			$currentMap->createFromJs($mapObject[$i]);
+
+			if (isset($mapObject[$i]->isOverview)) {
+				$this->overviewMap = $currentMap;
 			}
-			$e_general->appendChild($e_window);
-			
-			$e_bbox = $doc->createElement("BoundingBox");
-			$e_bbox->setAttribute("SRS", $generalBboxSrs);
-			$e_bbox->setAttribute("minx", $generalBboxMinx);
-			$e_bbox->setAttribute("miny", $generalBboxMiny);
-			$e_bbox->setAttribute("maxx", $generalBboxMaxx);
-			$e_bbox->setAttribute("maxy", $generalBboxMaxy);
-			$e_general->appendChild($e_bbox);
-			
-			$e_name = $doc->createElement("Name", $generalName);
-			$e_general->appendChild($e_name);
-			
-			$e_title = $doc->createElement("Title", $generalTitle);
-			$e_general->appendChild($e_title);
-			
-			$e_keyword_list = $doc->createElement("KeywordList");
-			for ($i=0; $i < count($generalKeywords); $i++) {
-				$e_keyword = $doc->createElement("Keyword", $generalKeywords[$i]);
-				$e_keyword_list->appendChild($e_keyword);
+			else {
+				$this->mainMap = $currentMap;
 			}
-			$e_general->appendChild($e_keyword_list);
-			
-			if ($generalAbstract){
-				$e_abstract = $doc->createElement("Abstract", $generalAbstract);
-				$e_general->appendChild($e_abstract);
-			}
-			
-			if ($generalLogoUrlWidth && $generalLogoUrlHeight && $generalLogoUrlFormat && $generalLogoUrl){
-				$e_logo_url = $doc->createElement("LogoURL");
-				$e_logo_url->setAttribute("width", $generalLogoUrlWidth);
-				$e_logo_url->setAttribute("height", $generalLogoUrlHeight);
-				$e_logo_url->setAttribute("format", $generalLogoUrlFormat);
-			
-				$e_logo_url_or = $doc->createElement("OnlineResource");
-				$e_logo_url_or->setAttributeNS("http://www.opengis.net/context", "xmlns:xlink", "http://www.w3.org/1999/xlink");
-				$e_logo_url_or->setAttribute("xlink:type", "simple");
-				$e_logo_url_or->setAttribute("xlink:href", $generalLogoUrl);
-				$e_logo_url->appendChild($e_logo_url_or);
+		}
+
+		
+		// create XML
+		$this->createXml();
+
+		$this->saveAsFile();
+		return true;
+	}
 	
-				$e_general->appendChild($e_logo_url);
-			}
-				
-			if ($generalDescriptionUrl){
-				$e_description_url = $doc->createElement("DescriptionURL");
-	
-				$e_description_url_or = $doc->createElement("OnlineResource");
-				$e_description_url_or->setAttributeNS("http://www.opengis.net/context", "xmlns:xlink", "http://www.w3.org/1999/xlink");
-				$e_description_url_or->setAttribute("xlink:type", "simple");
-				$e_description_url_or->setAttribute("xlink:href", $generalDescriptionUrl);
-				$e_description_url->appendChild($e_description_url_or);
-	
-				$e_general->appendChild($e_description_url);
-			}
+	// ---------------------------------------------------------------------------
+	// DATABASE FUNCTIONS
+	// ---------------------------------------------------------------------------
+
+	/**
+	 * Stores this WMC in the database. The WMC has to be instantiated first, see above.
+	 * 
+	 * @return mixed[] an assoc array with attributes "success" (boolean) and "message" (String).
+	 */
+	public function insert () {
+		$result = array();
+		if ($this->userId && $this->xml && $this->wmc_title) {
+			$sql = "INSERT INTO mb_user_wmc VALUES ($1, $2, $3, $4, $5)";
+			$v = array($this->wmc_id, $this->userId, $this->xml, $this->wmc_title, time());
+			$t = array("s", "i", "s", "s", "s");
 			
-			if ($generalContactElectronicMailAddress || $generalContactOrganization ||
-				$generalContactPerson || $generalContactPosition || $generalContactAddressType ||
-				$generalContactAddress || $generalContactCity || $generalContactStateOrProvince ||
-				$generalContactPostCode || $generalContactCountry || $generalContactVoiceTelephone ||
-				$generalContactFacsimileTelephone || $generalContactElectronicMailAddress) {
-			
-				$e_contact = $doc->createElement("ContactInformation");
-			
-				if ($generalContactPerson || $generalContactOrganization){
-					$e_contact_person_primary = $doc->createElement("ContactPersonPrimary");
-			
-					if ($generalContactPerson){
-						$e_contact_person = $doc->createElement("ContactPerson", $generalContactPerson);
-						$e_contact_person_primary->appendChild($e_contact_person);
-					}
-					if ($generalContactOrganization){
-						$e_contact_organization = $doc->createElement("ContactOrganization", $generalContactOrganization);
-						$e_contact_person_primary->appendChild($e_contact_organization);
-					}
-					$e_contact->appendChild($e_contact_person_primary);
-				}
-			
-				if ($generalContactPosition){
-					$e_contact_position = $doc->createElement("ContactPosition", $generalContactPosition);
-					$e_contact->appendChild($e_contact_position);
-				}
-			
-				if ($generalContactAddressType || $generalContactAddress || 
-					$generalContactCity || $generalContactStateOrProvince ||
-					$generalContactPostCode || $generalContactCountry) {
-			
-					$e_contact_address = $doc->createElement("ContactAddress");
-			
-					if ($generalContactAddressType){
-						$e_address_type = $doc->createElement("AddressType", $generalContactAddressType);
-						$e_contact_address->appendChild($e_address_type);
-					}
-					if ($generalContactAddress){
-						$e_address = $doc->createElement("Address", $generalContactAddress);
-						$e_contact_address->appendChild($e_address);
-					}
-					if ($generalContactCity){
-						$e_city = $doc->createElement("City", $generalContactCity);
-						$e_contact_address->appendChild($e_city);
-					}
-					if ($generalContactStateOrProvince){
-						$e_state = $doc->createElement("StateOrProvince", $generalContactStateOrProvince);
-						$e_contact_address->appendChild($e_state);
-					}
-					if ($generalContactPostCode){
-						$e_postcode = $doc->createElement("PostCode", $generalContactPostCode);
-						$e_contact_address->appendChild($e_postcode);
-					}
-					if ($generalContactCountry){
-						$e_country = $doc->createElement("Country", $generalContactCountry);
-						$e_contact_address->appendChild($e_country);
-					}
-					$e_contact->appendChild($e_contact_address);
-				}
-				
-				if ($generalContactVoiceTelephone){
-					$e_voice_telephone = $doc->createElement("ContactVoiceTelephone", $generalContactVoiceTelephone);
-					$e_contact->appendChild($e_voice_telephone);
-				}
-				if ($generalContactFacsimileTelephone){
-					$e_facsimile_telephone = $doc->createElement("ContactFacsimileTelephone", $generalContactFacsimileTelephone);
-					$e_contact->appendChild($e_facsimile_telephone);
-				}
-				if ($generalContactElectronicMailAddress){
-					$e_email = $doc->createElement("ContactElectronicMailAddress", $generalContactElectronicMailAddress);
-					$e_contact->appendChild($e_email);
-				}
-				$e_general->appendChild($e_contact);
+			$res = db_prep_query($sql, $v, $t);
+			if (db_error()) {
+				$errMsg = "Error while saving WMC document '" . $this->wmc_title . "': " . db_error();
+				$result["success"] = false;
+				$result["message"] = $errMsg;
+				$e = new mb_exception("mod_insertWMCIntoDB: " . $errMsg);
 			}
-			
-			
-			if (count($extensionData) > 0) {
-				//$e = new mb_exception("writing wmc...");
-				$e_extensionGeneral = $doc->createElement("Extension");
-				
-				foreach ($extensionData as $keyExtensionData => $valueExtensionData) {
-					$e_currentExtensionTag = $doc->createElement($extension_namespace.":".$keyExtensionData, $valueExtensionData);
-					$e_extensionGeneral->appendChild($e_currentExtensionTag);
-				}
-				$e_general->appendChild($e_extensionGeneral);
+			else {
+				$result["success"] = true;
+				$msg = "WMC document '" . $this->wmc_title . "' has been saved.";
+				$result["message"] = $msg;
+				$e = new mb_notice("mod_insertWMCIntoDB: WMC  '" . $this->wmc_title . "' saved successfully.");
 			}
-		$e_view_context->appendChild($e_general);
+		}
+		else {
+			$result["success"] = false;
+			$errMsg = "missing parameters (user_id: ".$this->userId.", title: " . $this->wmc_title . ")";
+			$result["message"] = $errMsg;
+			$e = new mb_exception("mod_insertWMCIntoDB: " . $errMsg .")");
+		}
+		return $result;
+	}
 	
+	/**
+	 * 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 successful?
+	 */
+	public static function delete ($wmcId, $userId) {
+		if (!isset($userId) || $userId === null) {
+			$userId = $_SESSION["mb_user_id"];
+		}
+		
+		$sql = "DELETE FROM mb_user_wmc ";
+		$sql .= "WHERE fkey_user_id = $1 AND wmc_id = $2";
+		$v = array($userId, $wmcId);
+		$t = array('i', 's');
+		$res = db_prep_query($sql, $v, $t);
+		if ($res) {
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Returns a WMC document
+	 * @return String|boolean The document if it exists; else false
+	 * @param $id String the WMC id
+	 */
+	public static function getDocument ($id) {
+		$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1 AND fkey_user_id = $2";
+		$v = array($id, $_SESSION["mb_user_id"]);
+		$t = array('s', 'i');
+		$res = db_prep_query($sql,$v,$t);
+		$row = db_fetch_array($res);
+		if ($row) {
+			return $row["wmc"];
+		}
+		return false;
+	}
+
+	// ---------------------------------------------------------------------------
+	// GETTER FUNCTIONS
+	// ---------------------------------------------------------------------------
 	
-		// LayerList
-		$e_layer_list = $doc->createElement("LayerList");
+	/**
+	 * @return string the title of the WMC.
+	 */
+	public function getTitle() {
+		return $this->wmc_title;
+	}
+
+	// ---------------------------------------------------------------------------
+	// OUTPUT FUNCTIONS
+	// ---------------------------------------------------------------------------
 	
-		for ($i=0; $i < count($mapObject->wms); $i++){
-			$wmsId = $mapObject->wms[$i]->wms_id;
-			$wms_epsg = array();
-			$wms_epsg[0] = $mapObject->epsg;
-		
-			if ($mapObject->wms[$i]->gui_wms_epsg != $mapObject->epsg){
-				$wms_epsg[1] = $mapObject->wms[$i]->gui_wms_epsg;
+	/**
+	 * Wrapper function, returns XML at the moment
+	 * @return String
+	 */
+	public function __toString() {
+		return $this->toXml();
+	}
+
+	/**
+	 * Returns the XML document if available
+	 * 
+	 * @return String The XML document; if unavailable, null is returned.
+	 */
+	public function toXml () {
+		if (!$this->xml) {
+			$this->createXml();
+		}
+		return $this->xml;
+	}
+
+	/**
+	 * Returns an array of JavaScript statements
+	 * 
+	 * @return String[]
+	 */
+	public function toJavaScript () {
+/*
+		// counts how often a layer has been loaded
+		if ($this->monitoringIsOn) {
+			$monitor = new Layer_load_count();
+			for ($i = 0; $i < count($this->wmc_layer_id); $i++) {
+				$monitor->increment($this->wmc_layer_id[$i]);
 			}
-	
-			for ($q = 0; $q < count($mapObject->wms[$i]->gui_epsg); $q++){
-				$isInArray = false;
-				
-				for ($r=0 ; $r < count($wms_epsg); $r++){
-					if ($wms_epsg[$r] == $mapObject->wms[$i]->gui_epsg[$q]){
-						$isInArray = true;
-					}
-				}
-				if ($isInArray == false){
-					array_push($wms_epsg, $mapObject->wms[$i]->gui_epsg[$q]);
-				}
-			}
-			for ($j = 0; $j < count($mapObject->wms[$i]->objLayer); $j++){
-				if ($mapObject->wms[$i]->objLayer[$j]->layer_parent != ''){
-					if ($mapObject->wms[$i]->objLayer[$j]->gui_layer_visible == "1"){
-						$layerHidden = 0;
-					}
-					else{
-						$layerHidden = 1;
-					}
-					$layerQueryable = $mapObject->wms[$i]->objLayer[$j]->layer_queryable;
-					$layerQuerylayer = $mapObject->wms[$i]->objLayer[$j]->gui_layer_querylayer;
-					$layerId = $mapObject->wms[$i]->objLayer[$j]->layer_uid;
-					$layerName = $mapObject->wms[$i]->objLayer[$j]->layer_name;
-					$layerTitle = $mapObject->wms[$i]->objLayer[$j]->layer_title;
-					$layerAbstract = $mapObject->wms[$i]->wms_abstract; //To Do: insert actual abstract
-					$layerDataUrl = $mapObject->wms[$i]->objLayer[$j]->layer_dataurl_href; 
-					$layerMetadataUrl = $mapObject->wms[$i]->objLayer[$j]->layer_metadataurl;
-					$layerMinscale = $mapObject->wms[$i]->objLayer[$j]->layer_minscale; 
-					$layerMaxscale = $mapObject->wms[$i]->objLayer[$j]->layer_maxscale; 
-					$guiLayerMinscale = $mapObject->wms[$i]->objLayer[$j]->gui_layer_minscale; 
-					$guiLayerMaxscale = $mapObject->wms[$i]->objLayer[$j]->gui_layer_maxscale; 
-					$wmsVersion = $mapObject->wms[$i]->wms_version;
-					$wmsTitle = $mapObject->wms[$i]->wms_title;
-					$wmsLayerId = $mapObject->wms[$i]->objLayer[0]->layer_uid;
-					$wmsOnlineResource = $mapObject->wms[$i]->wms_getmap;
-					$layerPos = $mapObject->wms[$i]->objLayer[$j]->layer_pos;
-					$layerParent = $mapObject->wms[$i]->objLayer[$j]->layer_parent;
-					$queryLayer = $mapObject->wms[$i]->objLayer[$j]->gui_layer_querylayer;
-					$wfsFeatureType = $mapObject->wms[$i]->objLayer[$j]->gui_layer_wfs_featuretype;
-					
-					$e_layer = $doc->createElement("Layer");
-					$e_layer->setAttribute("queryable", $layerQueryable);
-					$e_layer->setAttribute("hidden", $layerHidden);
+		}
+*/		
+		// will contain the JS code to create the maps
+		// representing the state stored in this WMC
+		$wmcJsArray = array();
 		
-						$e_service = $doc->createElement("Server");
-						$e_service->setAttribute("service", "OGC:WMS");
-						$e_service->setAttribute("version", $wmsVersion);
-						$e_service->setAttribute("title", $wmsTitle);
+		// set general extension data
+		if (count($this->generalExtensionArray) > 0) {
+			$json = new Mapbender_JSON();
+			array_push($wmcJsArray, "restoredWmcExtensionData = " . $json->encode($this->generalExtensionArray) . ";"); 
+		}
 		
-						$e_service_or = $doc->createElement("OnlineResource");
-						$e_service_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-						$e_service_or->setAttribute("xlink:type", "simple");
-						$e_service_or->setAttribute("xlink:href", $wmsOnlineResource);
-						
-						$e_service->appendChild($e_service_or);
-						$e_layer->appendChild($e_service);
-		
-						$e_layer_name = $doc->createElement("Name", $layerName);
-						$e_layer->appendChild($e_layer_name);
-		
-						$e_layer_title = $doc->createElement("Title", $layerTitle);
-						$e_layer->appendChild($e_layer_title);
-		
-						if ($layerAbstract){
-							$e_layer_abstract = $doc->createElement("Abstract", $layerAbstract);
-							$e_layer->appendChild($e_layer_abstract);
-						}
-		
-						$e_layer_srs = $doc->createElement("SRS", implode(" ", $wms_epsg));
-						$e_layer->appendChild($e_layer_name);
-		
-						if ($layerDataUrl){
-							$e_layer_data_url = $doc->createElement("DataURL");
-			
-							$e_layer_data_url_or = $doc->createElement("OnlineResource");
-							$e_layer_data_url_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-							$e_layer_data_url_or->setAttribute("xlink:type", "simple");
-							$e_layer_data_url_or->setAttribute("xlink:href", $layerDataUrl);
-							
-							$e_layer_data_url->appendChild($e_layer_data_url_or);
-							$e_layer->appendChild($e_layer_data_url);
-						}
-		
-						if ($layerMetadataUrl){
-							$e_layer_metadata_url = $doc->createElement("MetadataURL");
-			
-							$e_layer_metadata_url_or = $doc->createElement("OnlineResource");
-							$e_layer_metadata_url_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-							$e_layer_metadata_url_or->setAttribute("xlink:type", "simple");
-							$e_layer_metadata_url_or->setAttribute("xlink:href", $layerMetadataUrl);
-							
-							$e_layer_metadata_url->appendChild($e_layer_metadata_url_or);
-							$e_layer->appendChild($e_layer_metadata_url);
-						}
-		
-						$e_extension = $doc->createElement("Extension");
-		
-						$e_scalehint = $doc->createElement($extension_namespace.":ScaleHint");
-						$e_scalehint->setAttribute("min", $layerMinscale);
-						$e_scalehint->setAttribute("max", $layerMaxscale);
-						$e_extension->appendChild($e_scalehint);
-						
-						$e_gui_scalehint = $doc->createElement($extension_namespace.":guiScaleHint");
-						$e_gui_scalehint->setAttribute("min", $guiLayerMinscale);
-						$e_gui_scalehint->setAttribute("max", $guiLayerMaxscale);
-						$e_extension->appendChild($e_gui_scalehint);
-						
-						$e_layer_id = $doc->createElement($extension_namespace.":layer_id", $layerId);
-						$e_extension->appendChild($e_layer_id);
-						
-						$e_wms_layer_id = $doc->createElement($extension_namespace.":wms_layer_id", $wmsLayerId);
-						$e_extension->appendChild($e_wms_layer_id);
-						
-						$e_layer_pos = $doc->createElement($extension_namespace.":layer_pos", $layerPos);
-						$e_extension->appendChild($e_layer_pos);
-		
-						$e_layer_parent = $doc->createElement($extension_namespace.":layer_parent", $layerParent);
-						$e_extension->appendChild($e_layer_parent);
-		
-						$e_wms_id = $doc->createElement($extension_namespace.":wms_id", $wmsId);
-						$e_extension->appendChild($e_wms_id);
-		
-						$e_querylayer = $doc->createElement($extension_namespace.":querylayer", $layerQuerylayer);
-						$e_extension->appendChild($e_querylayer);
-						
-						if ($wfsFeatureType) {
-							$e_wfsFeatureType = $doc->createElement($extension_namespace.":wfsFeatureType", $wfsFeatureType);
-							$e_extension->appendChild($e_wfsFeatureType);
-						}
+		// reset WMS data
+		array_push($wmcJsArray, "wms = [];");
+		array_push($wmcJsArray, "wms_layer_count = 0;");
 
-						$e_layer->appendChild($e_extension);
-		
-						//layerFormat
-						$e_layer_format = $doc->createElement("FormatList");
-		
-						$data_format_current = false;
-		
-						for ($k = 0; $k < count($mapObject->wms[$i]->data_format); $k++){
-		
-							if ($mapObject->wms[$i]->data_type[$k] == "map") {
-								$layerFormat = $mapObject->wms[$i]->data_format[$k];
-				
-								$e_format = $doc->createElement("Format", $layerFormat);
-		
-								if ($data_format_current == false && ( 
-										($mapObject->wms[$i]->data_format[$k] == $mapObject->wms[$i]->gui_wms_mapformat) ||
-										($k == (count($mapObject->wms[$i]->data_format)-1))
-								)){
-		
-									$e_format->setAttribute("current", "1");
-									$data_format_current = true;
-								}
-								$e_layer_format->appendChild($e_format);
-							}
-						}
-						$e_layer->appendChild($e_layer_format);
-		
-		
-						// LayerStyle
-						$e_layer_stylelist = $doc->createElement("StyleList");
-			
-						for ($k = 0; $k < count($mapObject->wms[$i]->objLayer[$j]->layer_style); $k++){
-		
-							if ($k == 0){
-								$layerStyle_current = 1; // To do: insert proper data
-							}
-							else{
-								$layerStyle_current = 0; // To do: insert proper data
-							}
-		
-							$e_layer_style = $doc->createElement("Style");
-		
-							$layerStyleSLD = "";
-		
-							if ($layerStyleSLD){
-								$layerStyleSLDUrl = ""; // To Do: Insert Proper Data
-								
-								$e_layer_style_or = $doc->createElement("OnlineResource");
-								$e_layer_style_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-								$e_layer_style_or->setAttribute("xlink:type", "simple");
-								$e_layer_style_or->setAttribute("xlink:href", $layerStyleSLDUrl);
-								$e_layer_style->appendChild($e_layer_style_or);
-							}
-							else{
-								//TODO: determine correct layer style entries
-								$layerStyle_name = $mapObject->wms[$i]->objLayer[$j]->layer_style[$k]->name;
-								$layerStyle_title = $mapObject->wms[$i]->objLayer[$j]->layer_style[$k]->title;
-								$layerStyle_legendUrl = $mapObject->wms[$i]->objLayer[$j]->layer_style[$k]->legendurl;
-								$layerStyle_legendUrl_width = ""; // To Do: add proper data
-								$layerStyle_legendUrl_height = ""; // To Do: add proper data
-								$layerStyle_legendUrl_format = ""; // To Do: add proper data
-		
-								if ($layerStyle_current == 1){
-									$e_layer_style->setAttribute("current", "1");
-								}
-	
-								$e_layer_style_name = $doc->createElement("Name", $layerStyle_name);
-								$e_layer_style->appendChild($e_layer_style_name);
-	
-								$e_layer_style_title = $doc->createElement("Title", $layerStyle_title);
-								$e_layer_style->appendChild($e_layer_style_title);
-								
-								
-								$e_layer_style_legendurl = $doc->createElement("LegendUrl");
-								$e_layer_style_legendurl->setAttribute("width", $layerStyle_legendUrl_width);
-								$e_layer_style_legendurl->setAttribute("height", $layerStyle_legendUrl_height);
-								$e_layer_style_legendurl->setAttribute("format", $layerStyle_legendUrl_format);
-	
-								$e_layer_style_legendurl_or = $doc->createElement("OnlineResource");
-								$e_layer_style_legendurl_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-								$e_layer_style_legendurl_or->setAttribute("xlink:type", "simple");
-								$e_layer_style_legendurl_or->setAttribute("xlink:href", $layerStyle_legendUrl);
-								$e_layer_style_legendurl->appendChild($e_layer_style_legendurl_or);
-								$e_layer_style->appendChild($e_layer_style_legendurl);
-							}
-							$e_layer_stylelist->appendChild($e_layer_style);
-						}	
-						$e_layer->appendChild($e_layer_stylelist);
-						
-					$e_layer_list->appendChild($e_layer);
+		// add WMS for main map frame
+		$wmsArray = $this->mainMap->getWmsArray();
+
+		// find the WMS in the main map which is equal to the WMS
+		// in the overview map
+		$overviewWmsIndex = null;
+		$ovWmsArray = array();
+		if ($this->overviewMap !== null) {
+			$ovWmsArray = $this->overviewMap->getWmsArray();
+			$overviewWmsIndex = 0;
+			for ($i = 0; $i < count($ovWmsArray); $i++) {
+				for ($j = 0; $j < count($wmsArray); $j++) {
+					if ($ovWmsArray[$i]->equals($wmsArray[$j])) {
+						$overviewWmsIndex = $j;						
+						break;
+					}
 				}
 			}
 		}
-		$e_view_context->appendChild($e_layer_list);
-	
-	
-	$doc->appendChild($e_view_context);
-	$this->xml = $doc->saveXML();
-	
-	// for debugging: saving WMC as file
-	// (comment when no longer needed)
-	$filename = $this->saveAsFile();
-	if ($filename) {
-		$e = new mb_notice("class_wmc: saving WMC as file " . $filename);
-	}
-}
 
-/**
- * Loads a WMC from the database.
- * 
- * @param integer $wmc_id the ID of the WMC document in the database table "mb_user_wmc"
- */
-function createObjFromWMC_id($wmc_id){
-	
-	global $DBSERVER,$DB,$OWNER,$PW;
-	$con = db_connect($DBSERVER,$OWNER,$PW);
-	db_select_db(DB, $con);
-	
-	$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1";
-	$v = array($wmc_id);
-	$t = array("s");
-	$res = db_prep_query($sql, $v, $t);
-	$wmc = db_fetch_row($res);
-	$this->createObjFromWMC_xml($wmc[0]);
-	$this->monitoringIsOn = true;
-}
 
-/**
- * Loads a WMC from an actual WMC XML document.
- * 
- * @param string $data the data from the XML file
- */
-function createObjFromWMC_xml($data){
-#	$data = str_replace("&#38;", "&amp;", $data);
 
-	// store xml 
-	$this->xml = $data;
+		// for all wms...
+		for ($i = 0; $i < count($wmsArray); $i++) {
+			// ..use settings from ov if available
+			if ($overviewWmsIndex !== null && $this->overviewMap !== null && 
+				$overviewWmsIndex == $i && count($ovWmsArray) > $i) {
+				array_push($wmcJsArray, $ovWmsArray[$i]->createJsObjFromWMS_());
+			}
+			else {
+				// ..otherwise use data from mapframe1
+				array_push($wmcJsArray, $wmsArray[$i]->createJsObjFromWMS_());
+			}			
+		}
 
-	// for debugging: saving WMC as file
-	// (comment when no longer needed)
-	$filename = $this->saveAsFile();
-	if ($filename) {
-		$e = new mb_notice("class_wmc: saving WMC as file " . $filename);
-	}
+		// delete existing map objects...
+		array_push($wmcJsArray, "mb_mapObj = [];");
 
+		// .. and add the overview map (if exists) and set map request
+		if ($this->overviewMap !== null) {
+			$wmcJsArray = array_merge($wmcJsArray, $this->overviewMap->toJavaScript($overviewWmsIndex));
+		}
 
+		// .. and add main map ..
+		$wmcJsArray = array_merge($wmcJsArray, $this->mainMap->toJavaScript(null));
 
-	$values = NULL;
-	$tags = NULL;
-	$parser = xml_parser_create(CHARSET);
-	xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
-	xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
-	xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
-	xml_parse_into_struct($parser,$data,$values,$tags);
-	$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);
-		return false;
+		// set visibility of main map WMS (may be different from overview)
+		if ($this->overviewMap !== null) {
+			for ($i = 0; $i < count($wmsArray[$overviewWmsIndex]->objLayer); $i++) {
+				$visStr = "mb_mapObj[1].wms[" .$overviewWmsIndex . "].handleLayer(" . 
+					"'" . $wmsArray[$overviewWmsIndex]->objLayer[$i]->layer_name . "', " . 
+					"'visible', " . 
+					($wmsArray[$overviewWmsIndex]->objLayer[$i]->gui_layer_visible ? 1 : 0) . ");";
+				array_push($wmcJsArray, $visStr);
+			}
+			array_push($wmcJsArray, "mb_mapObj[1].restateLayers(" . $wmsArray[$overviewWmsIndex]->wms_id . ");");
+		}
+		
+
+		// .. request the map
+		array_push($wmcJsArray, "setMapRequest('" . $this->mainMap->getFrameName() . "');");
+		if ($this->overviewMap !== null) {
+			array_push($wmcJsArray, "setMapRequest('" . $this->overviewMap->getFrameName() . "');");
+		}
+
+		array_push($wmcJsArray, "eventAfterLoadWMS.trigger();");
+		return $wmcJsArray;
 	}
-	xml_parser_free($parser);
 	
-	$section = NULL;
-	$format = NULL;
-	$cnt_format = 0;
-	$parent = array();
-	$myParent = array();
-	$cnt_layer = -1;
-	$request = NULL; 
-	$layer_style = array();
-	$extension = false;
-	
-	$general = false;
-	$layerlist = false;
-	$layer = false;
-	$formatlist = false;
-	$dataurl = false;
-	$metadataurl = false; 
-	$stylelist = false;
-	$cnt_style = -1;
-		 
-	foreach ($values as $element) {
-					$verbose .= ".";
-		if(strtoupper($element[tag]) == "VIEWCONTEXT" && $element[type] == "open"){
-				$this->wmc_id = $element[attributes]["id"];
-				$this->wmc_version = $element[attributes]["version"];
+	// ------------------------------------------------------------------------
+	// manipulation
+	// ------------------------------------------------------------------------
+	/**
+	 * Merges this WMC with another WMC.
+	 * The settings of the other WMC overwrite the settings of this WMC.
+	 * 
+	 * @return void
+	 * @param $xml2 Object
+	 */
+	public function merge ($xml2) {
+		$someWmc = new wmc();
+		$someWmc->createFromXml($xml2);
+
+		$this->mainMap->merge($someWmc->mainMap);
+		if (isset($this->overviewMap) && isset($someWmc->overviewMap)) {
+			$this->overviewMap->merge($someWmc->overviewMap);
 		}
-		if(strtoupper($element[tag]) == "GENERAL" && $element[type] == "open"){
-		   $general = true;
+	}
+
+	/**
+	 * Appends the layers of another WMC to this WMC.
+	 * 
+	 * @return void
+	 * @param $xml2 Object
+	 */
+	public function append ($xml2) {
+		$someWmc = new wmc();
+		$someWmc->createFromXml($xml2);
+
+		$this->mainMap->append($someWmc->mainMap);
+		if (isset($this->overviewMap) && isset($someWmc->overviewMap)) {
+			// There is only one WMS in the overview map; merge, not append
+			$this->overviewMap->merge($someWmc->overviewMap);
 		}
-		if(strtoupper($element[tag]) == "LAYERLIST" && $element[type] == "open"){
-		   $layerlist = true;
-		}
-		if ($general) {
-				if(strtoupper($element[tag]) == "WINDOW"){
-						$this->wmc_windowWidth = $element[attributes]["width"];
-						$this->wmc_windowHeight = $element[attributes]["height"];
+	}
+
+	/**
+	 * Adds a WMS to this WMC
+	 * 
+	 * @return 
+	 */
+	public function appendWmsArray ($wmsArray) {
+		return $this->mainMap->appendWmsArray($wmsArray);
+	}
+	
+	/**
+	 * Merges a WMS into this WMC
+	 * 
+	 * @return 
+	 */
+	public function mergeWmsArray ($wmsArray) {
+		$this->mainMap->mergeWmsArray($wmsArray);
+	}
+
+// ---------------------------------------------------------------------------
+// private functions
+// ---------------------------------------------------------------------------
+
+	/**
+	 * Loads a WMC from an actual WMC XML document.
+	 * Uses WMS class.
+	 * 
+	 * @param string $data the data from the XML file
+	 */
+	private function createObjFromWMC_xml($data){
+		// store xml 
+		$this->xml = $data;
+	
+		$values = administration::parseXml($data);
+
+		//
+		// Local variables that indicate which section of the WMC
+		// is currently parsed.
+		//
+		$extension = false;		$general = false;		$layerlist = false;
+		$layer = false;  		$formatlist = false;	$dataurl = false;
+		$metadataurl = false; 	$stylelist = false;
+
+		//
+		// reset WMC data
+		//
+		$this->mainMap = new Map();
+		$this->overviewMap = null;
+		$this->generalExtensionArray = array();
+		
+		$layerlistArray = array();
+		$layerlistArray["main"] = array();
+		$layerlistArray["overview"] = array();
+			 
+		foreach ($values as $element) {
+			$tag = strtoupper(administration::sepNameSpace($element[tag]));
+			$tagLowerCase = administration::sepNameSpace($element[tag]);
+			$type = $element[type];
+			$attributes = $element[attributes];
+			$value = mb_utf8_decode(html_entity_decode($element[value])); // TODO: not sure if utf decoding is necessary
+			
+			if ($tag == "VIEWCONTEXT" && $type == "open") {
+				$this->wmc_id = $attributes["id"];
+				$this->wmc_version = $attributes["version"];
+			}
+			if ($tag == "GENERAL" && $type == "open") {
+				$general = true;
+			}
+			if ($tag == "LAYERLIST" && $type == "open") {
+				$layerlist = true;
+			}
+			if ($general) {
+				if ($tag == "WINDOW") {
+					$this->mainMap->setWidth($attributes["width"]);
+					$this->mainMap->setHeight($attributes["height"]);
 				}
-				if(strtoupper($element[tag]) == "BOUNDINGBOX"){
-						$this->wmc_bBox_SRS = $element[attributes]["SRS"];
-						$this->wmc_bBox_minx = $element[attributes]["minx"];
-						$this->wmc_bBox_miny = $element[attributes]["miny"];
-						$this->wmc_bBox_maxx = $element[attributes]["maxx"];
-						$this->wmc_bBox_maxy = $element[attributes]["maxy"];
+				if ($tag == "BOUNDINGBOX") {
+					$bbox = new Mapbender_bbox($attributes["minx"], $attributes["miny"], $attributes["maxx"], $attributes["maxy"], $attributes["SRS"]);
+					$this->mainMap->setExtent($bbox);
 				}
-				if(strtoupper($element[tag]) == "NAME"){
-						$this->wmc_name = mb_utf8_decode(html_entity_decode($element[value]));
+				if ($tag == "NAME") {
+					$this->wmc_name = $value;
 				}
-				if(strtoupper($element[tag]) == "TITLE"){
-						$this->wmc_title = mb_utf8_decode(html_entity_decode($element[value]));
+				if ($tag == "TITLE") {
+					$this->wmc_title = $value;
 				}
-				if(strtoupper($element[tag]) == "ABSTRACT"){
-						$this->wmc_abstract = mb_utf8_decode(html_entity_decode($element[value]));
+				if ($tag == "ABSTRACT") {
+					$this->wmc_abstract = $value;
 				}
-				if(strtoupper($element[tag]) == "CONTACTINFORMATION" && $element['type'] == "open"){
-						$contactinformation = true;
+				if ($tag == "CONTACTINFORMATION" && $type == "open") {
+					$contactinformation = true;
 				}
 				if ($contactinformation) {
-					if(strtoupper($element[tag]) == "CONTACTPOSITION"){
-							$this->wmc_contactposition = mb_utf8_decode(html_entity_decode($element[value]));
+					if ($tag == "CONTACTPOSITION") {
+						$this->wmc_contactposition = $value;
 					}
-					if(strtoupper($element[tag]) == "CONTACTVOICETELEPHONE"){
-							$this->wmc_contactvoicetelephone = $element[value];
+					if ($tag == "CONTACTVOICETELEPHONE") {
+						$this->wmc_contactvoicetelephone = $value;
 					}
-					if(strtoupper($element[tag]) == "CONTACTFACSIMILETELEPHONE"){
-							$this->wmc_contactfacsimiletelephone = $element[value];
+					if ($tag == "CONTACTFACSIMILETELEPHONE") {
+						$this->wmc_contactfacsimiletelephone = $value;
 					}
-					if(strtoupper($element[tag]) == "CONTACTELECTRONICMAILADDRESS"){
-							$this->wmc_contactemail = mb_utf8_decode(html_entity_decode($element[value]));
+					if ($tag == "CONTACTELECTRONICMAILADDRESS") {
+						$this->wmc_contactemail = $value;
 					}
-					if(strtoupper($element[tag]) == "CONTACTPERSONPRIMARY" && $element['type'] == "open"){
-							$contactpersonprimary = true;
+					if ($tag == "CONTACTPERSONPRIMARY" && $type == "open") {
+						$contactpersonprimary = true;
 					}
 					if ($contactpersonprimary) {
-						if(strtoupper($element[tag]) == "CONTACTPERSON"){
-								$this->wmc_contactperson = mb_utf8_decode(html_entity_decode($element[value]));
+						if ($tag == "CONTACTPERSON") {
+							$this->wmc_contactperson = $value;
 						}
-						if(strtoupper($element[tag]) == "CONTACTORGANIZATION"){
-								$this->wmc_contactorganization = mb_utf8_decode(html_entity_decode($element[value]));
+						if ($tag == "CONTACTORGANIZATION") {
+							$this->wmc_contactorganization = $value;;
 						}
-						if(strtoupper($element[tag]) == "CONTACTPERSONPRIMARY" && $element['type'] == "close"){
-								$contactpersonprimary = false;
+						if ($tag == "CONTACTPERSONPRIMARY" && $type == "close") {
+							$contactpersonprimary = false;
 						}
 					}
-					if(strtoupper($element[tag]) == "CONTACTADDRESS" && $element['type'] == "open"){
-							$contactaddress = true;
+					if ($tag == "CONTACTADDRESS" && $type == "open") {
+						$contactaddress = true;
 					}
 					if ($contactaddress) {
-						if(strtoupper($element[tag]) == "ADDRESSTYPE"){
-								$this->wmc_contactaddresstype = mb_utf8_decode(html_entity_decode($element[value]));
+						if ($tag == "ADDRESSTYPE") {
+							$this->wmc_contactaddresstype = $value;
 						}
-						if(strtoupper($element[tag]) == "ADDRESS"){
-								$this->wmc_contactaddress = mb_utf8_decode(html_entity_decode($element[value]));
+						if ($tag == "ADDRESS") {
+							$this->wmc_contactaddress = $value;
 						}
-						if(strtoupper($element[tag]) == "CITY"){
-								$this->wmc_contactcity = mb_utf8_decode(html_entity_decode($element[value]));
+						if ($tag == "CITY") {
+							$this->wmc_contactcity = $value;
 						}
-						if(strtoupper($element[tag]) == "STATEORPROVINCE"){
-								$this->wmc_contactstateorprovince = mb_utf8_decode(html_entity_decode($element[value]));
+						if ($tag == "STATEORPROVINCE") {
+							$this->wmc_contactstateorprovince = $value;
 						}
-						if(strtoupper($element[tag]) == "POSTCODE"){
-								$this->wmc_contactpostcode = $element[value];
+						if ($tag == "POSTCODE"){
+							$this->wmc_contactpostcode = $value;
 						}
-						if(strtoupper($element[tag]) == "COUNTRY"){
-								$this->wmc_contactcountry = mb_utf8_decode(html_entity_decode($element[value]));
+						if ($tag == "COUNTRY") {
+							$this->wmc_contactcountry = $value;
 						}
-						if(strtoupper($element[tag]) == "CONTACTADDRESS" && $element['type'] == "close"){
-								$contactaddress = false;
+						if ($tag == "CONTACTADDRESS" && $type == "close") {
+							$contactaddress = false;
 						}
 					}
 				}
-				if(strtoupper($element[tag]) == "LOGOURL" && $element['type'] == "open"){
+				if ($tag == "LOGOURL" && $type == "open") {
 						$logourl = true;
-						$this->wmc_logourl_width = $element[attributes]["width"];
-						$this->wmc_logourl_height = $element[attributes]["height"];
-						$this->wmc_logourl_format = $element[attributes]["format"];
+						$this->wmc_logourl_width = $attributes["width"];
+						$this->wmc_logourl_height = $attributes["height"];
+						$this->wmc_logourl_format = $attributes["format"];
 				}
 				if ($logourl) {
-					if(strtoupper($element[tag]) == "LOGOURL" && $element['type'] == "close"){
-							$logourl = false;
+					if ($tag == "LOGOURL" && $type == "close") {
+						$logourl = false;
 					}
-					if(strtoupper($element[tag]) == "ONLINERESOURCE"){
-						$this->wmc_logourl_type = $element[attributes]["xlink:type"];
-						$this->wmc_logourl = $element[attributes]["xlink:href"];
+					if ($tag == "ONLINERESOURCE") {
+						$this->wmc_logourl_type = $attributes["xlink:type"];
+						$this->wmc_logourl = $attributes["xlink:href"];
 					}
 				}
-				if(strtoupper($element[tag]) == "DESCRIPTIONURL" && $element['type'] == "open"){
+				if ($tag == "DESCRIPTIONURL" && $type == "open") {
 						$descriptionurl = true;
-						$this->wmc_descriptionurl_format = $element[attributes]["format"];
+						$this->wmc_descriptionurl_format = $attributes["format"];
 				}
 				if ($descriptionurl) {
-					if(strtoupper($element[tag]) == "DESCRIPTIONURL" && $element['type'] == "close"){
-							$descriptionurl = false;
+					if ($tag == "DESCRIPTIONURL" && $type == "close"){
+						$descriptionurl = false;
 					}
-					if(strtoupper($element[tag]) == "ONLINERESOURCE"){
-						$this->wmc_descriptionurl_type = $element[attributes]["xlink:type"];
-						$this->wmc_descriptionurl = $element[attributes]["xlink:href"];
+					if ($tag == "ONLINERESOURCE") {
+						$this->wmc_descriptionurl_type = $attributes["xlink:type"];
+						$this->wmc_descriptionurl = $attributes["xlink:href"];
 					}
 				}
-				if(strtoupper($element[tag]) == "KEYWORDLIST" && $element['type'] == "open"){
-						$keywordlist = true;
+				if ($tag == "KEYWORDLIST" && $type == "open") {
+					$keywordlist = true;
 				}
 				if ($keywordlist) {
-					if(strtoupper($element[tag]) == "KEYWORDLIST" && $element['type'] == "close"){
-							$keywordlist = false;
-							$cnt_keyword = -1;
+					if ($tag == "KEYWORDLIST" && $type == "close") {
+						$keywordlist = false;
+						$cnt_keyword = -1;
 					}
-					if(strtoupper($element[tag]) == "KEYWORD"){
+					if ($tag == "KEYWORD") {
 						$cnt_keyword++;
-						$this->wmc_keyword[$cnt_keyword] = mb_utf8_decode(html_entity_decode($element[value]));
+						$this->wmc_keyword[$cnt_keyword] = $value;
 					}
 				}
-						
-				if(strtoupper($element[tag]) == "EXTENSION" && $element['type'] == "close"){
+				if ($tag == "EXTENSION" && $type == "close") {
 					$generalExtension = false;
+					//
+					// After the general extension tag is closed,
+					// we have all necessary information to CREATE
+					// the map objects that are contained in this
+					// WMC.
+					//
+					$this->setMapData();
 				}
 				if ($generalExtension) {
-					$this->wmc_general_extension[sepNameSpace($element[tag])] = $element[value];
-//					$e = new mb_exception("WMC: " . $element[tag] . ": " . $element[value]);
+					$this->generalExtensionArray[$tag] = $value;
 				}
-				if(strtoupper($element[tag]) == "EXTENSION" && $element['type'] == "open"){
+				if ($tag == "EXTENSION" && $type == "open") {
 					$generalExtension = true;
 				}
-
-				if(strtoupper($element[tag]) == "GENERAL" && $element['type'] == "close"){
+				if ($tag == "GENERAL" && $type == "close") {
 		   			$general = false;
 			 	}
-		}
-		if ($layerlist) {
-				if(strtoupper($element[tag]) == "LAYERLIST" && $element['type'] == "close"){
+			}
+			if ($layerlist) {
+				if ($tag == "LAYERLIST" && $type == "close") {
 				   $layerlist = false;
 				}
-				if(strtoupper($element[tag]) == "LAYER" && $element[type] == "open"){
-					 $cnt_layer++;
-					 $this->wmc_layer_queryable[$cnt_layer] = $element[attributes]["queryable"];
-					 $this->wmc_layer_hidden[$cnt_layer] = $element[attributes]["hidden"];
-					 $layer = true;
-      		 		 $cnt_epsg = 0;
+				if ($tag == "LAYER" && $type == "open") {
+					//
+					// The associative array currentLayer holds all 
+					// data of the currently processed layer.
+					// The data will be set in the classes' WMS
+					// object when the layer tag is closed.
+					//
+					$currentLayer = array();
+					
+					$currentLayer["queryable"] = $attributes["queryable"];
+					if ($attributes["hidden"] == "1") {
+						$currentLayer["visible"] = 0;
+					}
+					else {
+						$currentLayer["visible"] = 1;
+					}
+					$currentLayer["format"] = array();
+					$currentLayer["style"] = array();
+					$layer = true;
 				}
 				if ($layer) {
-					 if(strtoupper($element[tag]) == "LAYER" && $element[type] == "close"){
-					 		$layer = false;
-					 }
-					 if ($formatlist) {
-						 if(strtoupper($element[tag]) == "FORMAT"){
-						 	$cnt_format++;
-						 	$this->wmc_layer_format_current[$cnt_layer][$cnt_format] = $element[attributes]["current"];
-						 	$this->wmc_layer_format[$cnt_layer][$cnt_format] = $element[value];
+					if ($tag == "LAYER" && $type == "close") {
+
+						//
+						// After a layer tag is closed,
+						// we have all necessary information to CREATE
+						// a layer object and append it to the WMS object
+						//
+						if ($currentLayer["extension"]["ISOVERVIEWLAYER"] == "1") {
+							array_push($layerlistArray["overview"], $currentLayer);		
+						}
+						else {
+							array_push($layerlistArray["main"], $currentLayer);											
+						}
+				 		$layer = false;
+					}
+					if ($formatlist) {
+						if ($tag == "FORMAT") {
+						 	array_push($currentLayer["format"], array("current" => $attributes["current"], "name" => $value));
+							if ($attributes["current"] == "1") {
+								$currentLayer["formatIndex"] = count($currentLayer["format"]) - 1;
+							}
 						 }
-						 if(strtoupper($element[tag]) == "FORMATLIST" && $element[type] == "close"){
+						 if ($tag == "FORMATLIST" && $type == "close") {
 							 $formatlist = false;
 						 }
 					 }
 					 elseif ($metadataurl) {
-						 if(strtoupper($element[tag]) == "ONLINERESOURCE"){
-						 	$this->wmc_layer_metadataurl[$cnt_layer] = $element[attributes]["xlink:href"];
-						 }
-						 if(strtoupper($element[tag]) == "METADATAURL" && $element[type] == "close"){
-							 $metadataurl = false;
-						 }
+						if ($tag == "ONLINERESOURCE") {
+							$currentLayer["metadataurl"] = $attributes["xlink:href"];
+						}
+						if ($tag == "METADATAURL" && $type == "close") {
+							$metadataurl = false;
+						}
 					 }
 					 elseif ($dataurl) {
-						 if(strtoupper($element[tag]) == "ONLINERESOURCE"){
-						 	$this->wmc_layer_dataurl[$cnt_layer] = $element[attributes]["xlink:href"];
+						if ($tag == "ONLINERESOURCE") {
+						 	$currentLayer["dataurl"] = $attributes["xlink:href"];
+						}
+						 if ($tag == "DATAURL" && $type == "close") {
+							$dataurl = false;
 						 }
-						 if(strtoupper($element[tag]) == "DATAURL" && $element[type] == "close"){
-							 $dataurl = false;
-						 }
 					 }
 					 elseif ($stylelist) {
-						 if(strtoupper($element[tag]) == "STYLE" && $element[type] == "open"){
-						 	$cnt_style++;
-						 	$style = true;
-						 	$this->wmc_layer_style_current[$cnt_layer][$cnt_style] = $element[attributes]["current"];
-						 }
-						 if ($style) {
-							 if(strtoupper($element[tag]) == "STYLE" && $element[type] == "close"){
-							 	$style = false;
-							 }
-							 if(strtoupper($element[tag]) == "SLD" && $element[type] == "open"){
-							 	$sld = true;
-							 }
-							 if ($sld) {
-								 if(strtoupper($element[tag]) == "SLD" && $element[type] == "close"){
-								 	$sld = false;
-								 }
-								 if(strtoupper($element[tag]) == "ONLINERESOURCE"){
-								 	$this->wmc_layer_style_sld_type[$cnt_layer][$cnt_style] = $element[attributes]["xlink:type"];
-								 	$this->wmc_layer_style_sld_url[$cnt_layer][$cnt_style] = $element[attributes]["xlink:href"];
-								 }
-								 if(strtoupper($element[tag]) == "TITLE"){
-								 	$this->wmc_layer_style_sld_title[$cnt_layer][$cnt_style] = mb_utf8_decode(html_entity_decode($element[value]));
-								 }
-							 }
-							 else {
-								 if(strtoupper($element[tag]) == "NAME"){
-								 	$this->wmc_layer_style_name[$cnt_layer][$cnt_style] = mb_utf8_decode(html_entity_decode($element[value]));
-								 }
-								 if(strtoupper($element[tag]) == "TITLE"){
-								 	$this->wmc_layer_style_title[$cnt_layer][$cnt_style] = $element[value];
-								 }
-								 if(strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "open"){
+						if ($style) {
+							$index = count($currentLayer["style"]) - 1;
+							if ($tag == "STYLE" && $type == "close") {
+								$style = false;
+							}
+							if ($tag == "SLD" && $type == "open") {
+								$sld = true;
+							}
+							if ($sld) {
+								if ($tag == "SLD" && $type == "close") {
+									$sld = false;
+								}
+								if ($tag == "ONLINERESOURCE") {
+									$currentLayer["style"][$index]["sld_type"] = $attributes["xlink:type"];
+									$currentLayer["style"][$index]["sld_url"] = $attributes["xlink:href"];
+								}
+								if ($tag == "TITLE") {
+									$currentLayer["style"][$index]["sld_title"] = $value;
+								}
+							}
+							else {
+								if ($tag == "NAME"){
+									$currentLayer["style"][$index]["name"] = $value ? $value : "default";
+								}
+								if ($tag == "TITLE") {
+									$currentLayer["style"][$index]["title"] = $value ? $value : "default";
+								}
+								if ($legendurl) {
+									if ($tag == "LEGENDURL" && $type == "close") {
+										$legendurl = false;
+									}
+									if ($tag == "ONLINERESOURCE") {
+									 	$currentLayer["style"][$index]["legendurl_type"] = $attributes["xlink:type"];
+									 	$currentLayer["style"][$index]["legendurl"] = $attributes["xlink:href"];
+									}
+								}
+								if ($tag == "LEGENDURL" && $type == "open") {
 								 	$legendurl = true;
-								 	$this->wmc_layer_style_legendurl_width[$cnt_layer][$cnt_style] = $element[attributes]["width"];
-								 	$this->wmc_layer_style_legendurl_height[$cnt_layer][$cnt_style] = $element[attributes]["height"];
-								 	$this->wmc_layer_style_legendurl_format[$cnt_layer][$cnt_style] = $element[attributes]["format"];
-								 }
-								 if ($legendurl) {
-									 if(strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "close"){
-									 	$legendurl = false;
-									 }
-									 if(strtoupper($element[tag]) == "ONLINERESOURCE"){
-									 	$this->wmc_layer_style_legendurl_type[$cnt_layer][$cnt_style] = $element[attributes]["xlink:type"];
-									 	$this->wmc_layer_style_legendurl[$cnt_layer][$cnt_style] = $element[attributes]["xlink:href"];
-									 }
-								 }
-							 }
-						 }
-						 if(strtoupper($element[tag]) == "STYLELIST" && $element[type] == "close"){
-							 $stylelist = false;
-						 }
-					 }
-					 else {
-						 if(strtoupper($element[tag]) == "SERVER" && $element[type] == "open"){
-						 	 $server = true;
-						 	 $this->wmc_wms_service[$cnt_layer] = $element[attributes]["service"];
-						 	 $this->wmc_wms_version[$cnt_layer] = $element[attributes]["version"];
-						 	 $this->wmc_wms_title[$cnt_layer] = mb_utf8_decode(html_entity_decode($element[attributes]["title"]));
-						 }
-						 if ($server) {
-							 if(strtoupper($element[tag]) == "SERVER" && $element[type] == "close"){
-							 	 $server = false;
-							 }
-							 if(strtoupper($element[tag]) == "ONLINERESOURCE"){
-						 		 $this->wmc_wms_serviceURL[$cnt_layer] = $element[attributes]["xlink:href"];
-							 }
-						 }
-						 if(strtoupper($element[tag]) == "NAME"){
-					 		 $this->wmc_layer_name[$cnt_layer] = mb_utf8_decode(html_entity_decode($element[value]));
-						 }
-						 if(strtoupper($element[tag]) == "TITLE"){
-					 		 $this->wmc_layer_title[$cnt_layer] = mb_utf8_decode(html_entity_decode($element[value]));
-						 }
-						 if(strtoupper($element[tag]) == "ABSTRACT"){
-					 		 $this->wmc_layer_abstract[$cnt_layer] = mb_utf8_decode(html_entity_decode($element[value]));
-						 }
-						 if(strtoupper($element[tag]) == "SRS"){
-							 $epsgArray = explode(" ", $element[value]);						 	
-					 		 
-					 		 for ($c = 0 ; $c < count($epsgArray) ; $c ++) {
-						 		 $this->wmc_layer_srs[$cnt_layer][$cnt_epsg] = $epsgArray[$c];
-								 $cnt_epsg++;
-					 		 }
-						 }
-						 if (strtoupper($element[tag]) == "EXTENSION" && $element[type] == "open") {
-						 	$extension = true;
-						 }
-						 if (strtoupper($element[tag]) == "EXTENSION" && $element[type] == "close") {
-						 	$extension = false;
-						 }
-						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "SCALEHINT"){
-					 		 $this->wmc_layer_minscale[$cnt_layer] = $element[attributes]["min"];
-					 		 $this->wmc_layer_maxscale[$cnt_layer] = $element[attributes]["max"];
-						 }
-						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "GUISCALEHINT"){
-					 		 $this->wmc_gui_layer_minscale[$cnt_layer] = $element[attributes]["min"];
-					 		 $this->wmc_gui_layer_maxscale[$cnt_layer] = $element[attributes]["max"];
-						 }
-						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "LAYER_ID"){
-					 		 $this->wmc_layer_id[$cnt_layer] = $element[value];
-						 }
-						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "WMS_LAYER_ID"){
-					 		 $this->wmc_wms_layer_id[$cnt_layer] = $element[value];
-						 }
-						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "LAYER_POS"){
-					 		 $this->wmc_layer_pos[$cnt_layer] = $element[value];
-						 }
-						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "LAYER_PARENT"){
-					 		 $this->wmc_layer_parent[$cnt_layer] = $element[value];
-						 }
-						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "QUERYLAYER"){
-					 		 $this->wmc_layer_querylayer[$cnt_layer] = $element[value];
-						 }
-						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "WMS_ID"){
-					 		 $this->wmc_wms_id[$cnt_layer] = $element[value];
-						 }
-						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "WFSFEATURETYPE"){
-					 		 $this->wmc_layer_wfs_featuretype[$cnt_layer] = $element[value];
-						 }
-						 if(strtoupper($element[tag]) == "METADATAURL" && $element[type] == "open"){
-							 $metadataurl = true;
-						 }
-						 if(strtoupper($element[tag]) == "DATAURL" && $element[type] == "open"){
-							 $dataurl = true;
-						 }
-						 if(strtoupper($element[tag]) == "FORMATLIST" && $element[type] == "open"){
-							 $formatlist = true;
-							 $cnt_format = -1;
-						 }
-						 if(strtoupper($element[tag]) == "STYLELIST" && $element[type] == "open"){
-							 $stylelist = true;
-							 $cnt_style = -1;
-						 }
-					 }
+								 	$currentLayer["style"][$index]["legendurl_width"] = $attributes["width"];
+								 	$currentLayer["style"][$index]["legendurl_height"] = $attributes["height"];
+								 	$currentLayer["style"][$index]["legendurl_format"] = $attributes["format"];
+								}
+							}
+						}
+						if ($tag == "STYLE" && $type == "open") {
+							$style = true;
+							array_push($currentLayer["style"], array("current" => $attributes["current"]));
+							if ($attributes["current"] == "1") {
+								$currentLayer["styleIndex"] = count($currentLayer["style"]) - 1;
+							}
+						}
+						if ($tag == "STYLELIST" && $type == "close") {
+							$stylelist = false;
+						}
+					}
+					else {
+						if ($tag == "SERVER" && $type == "open") {
+							 $server = true;
+							 $currentLayer["service"] = $attributes["service"];
+							 $currentLayer["version"] = $attributes["version"];
+							 $currentLayer["wms_title"] = $attributes["title"];
+						}
+						if ($server) {
+							if ($tag == "SERVER" && $type == "close") {
+						 		$server = false;
+						 	}
+							if ($tag == "ONLINERESOURCE") {
+						 		$currentLayer["url"] = $attributes["xlink:href"];
+							}
+						}
+						if ($tag == "NAME") {
+					 		$currentLayer["name"] = $value;
+						}
+						if ($tag == "TITLE") {
+					 		$currentLayer["title"] = $value;
+						}
+						if ($tag == "ABSTRACT") {
+					 		$currentLayer["abstract"] = $value;
+						}
+						if ($tag == "SRS") {
+							$currentLayer["epsg"] = explode(" ", $value);						 	
+						}
+						if ($tag == "EXTENSION" && $type == "close") {
+							$extension = false;
+						}
+						if ($extension == true){
+							if ($value !== "") {
+								if (isset($currentLayer["extension"][$tag])) {
+									if (!is_array($currentLayer["extension"][$tag])) {
+										$firstValue = $currentLayer["extension"][$tag];
+										$currentLayer["extension"][$tag] = array();
+										array_push($currentLayer["extension"][$tag], $firstValue);
+									}	
+									array_push($currentLayer["extension"][$tag], $value);
+								}
+								else {
+									$currentLayer["extension"][$tag] = $value;									
+								}
+							}
+						}
+						if ($tag == "EXTENSION" && $type == "open") {
+							$currentLayer["extension"] = array();
+							$extension = true;
+						}
+						if ($tag == "METADATAURL" && $type == "open") {
+							$metadataurl = true;
+						}
+						if ($tag == "DATAURL" && $type == "open") {
+							$dataurl = true;
+						}
+						if ($tag == "FORMATLIST" && $type == "open") {
+							$formatlist = true;
+						}
+						if ($tag == "STYLELIST" && $type == "open") {
+							$stylelist = true;
+						}
+					}
 				}
 			}
 		}
+		
+		// set WMS data
+		
+		$layerlistCompleteArray = array_merge($layerlistArray["main"], $layerlistArray["overview"]);
+
+		for ($i = 0; $i < count($layerlistCompleteArray); $i++) {
+			$this->setLayerData($layerlistCompleteArray[$i]);
+		}
+
 		return true;
-	  //return $verbose;
 	}
 
 	/**
-	 * Creates JS code manipulating the map and wms objects, 
-	 * by this displaying the WMC
+	 * Saves the current WMC in the log folder.
 	 * 
-	 * @param string $target the link to the map object, f.e. "parent." or "window.opener."
-	 * @param string $mapObj the name of the map object, f.e. "mapframe1"
-	 * @param string $action "load", "merge" or "append"
-	 * 
-	 * @return string the JS code
+	 * @return string the filename of the WMC document.
 	 */
-	function createJsObjFromWMC($target, $mapObj, $action){
-		
-		/*
-		 * counts how often a layer has been loaded
-		 */
-		if ($this->monitoringIsOn) {
-			$monitor = new Layer_load_count();
-			for ($i = 0; $i < count($this->wmc_layer_id); $i++) {
-				$monitor->increment($this->wmc_layer_id[$i]);
+	private function saveAsFile() {
+		if ($this->saveWmcAsFile) {
+			$filename = "wmc_" . date("Y_m_d_H_i_s") . ".xml";
+			$logfile = "../tmp/" . $filename;
+			
+			if($h = fopen($logfile,"a")){
+				$content = $this->xml;
+				if(!fwrite($h,$content)){
+					$e = new mb_exception("class_wmc.php: failed to write wmc.");
+					return false;
+				}
+				fclose($h);
 			}
+			$e = new mb_notice("class_wmc: saving WMC as file " . $filename . "; You can turn this behaviour off in class_wmc.php");
+			return $filename;
 		}
-		
-		$wmc_string = "";
-		$validActions = array("load", "merge", "append");
-		if (!in_array($action, $validActions)) {
-			$wmc_string .= "alert('invalid action: ".$action."');";			
+		return null;
+	}
+	
+	/**
+	 * Called during WMC parsing; sets the data of a single layer.
+	 * 
+	 * @return 
+	 * @param $currentLayer Array an associative array with layer data
+	 */
+	private function setLayerData ($currentLayer) {
+		$currentMap = $this->mainMap;
+		$currentMapIsOverview = false;
+
+		if ($currentLayer["extension"]["ISOVERVIEWLAYER"] == "1") {
+			$currentMap = $this->overviewMap;
+			$currentMapIsOverview = true;
 		}
-		else {
-			
-			// general extension
-			if (count($this->wmc_general_extension) > 0) {
-				$json = new Mapbender_JSON();
-				$wmc_string .= $target . "restoredWmcExtensionData = " . $json->encode($this->wmc_general_extension) . ";\n"; 
+
+		$wmsArray = $currentMap->getWmsArray();
+
+		//
+		// check if current layer belongs to an existing WMS.
+		// If yes, store the index of this WMS in $wmsIndex.
+		// If not, set the value to null.
+		//
+		$wmsIndex = null;
+
+		// find last WMS with the same online resource
+		for ($i = count($wmsArray) - 1; $i >= 0; $i--) {
+			if (isset($currentLayer["url"]) && 
+				$currentLayer["url"] == $wmsArray[$i]->wms_getmap) {
+					$wmsIndex = $i;
+					break;
 			}
+		}
+
+		// Even if this WMS has been found before it could still
+		// be a duplicate! We would have to create a new WMS and 
+		// not append this layer to that WMS.
+		// For the overview layer we never add a new wms.
+		// check if this layer is an overview layer. If yes, skip this layer.
+		if ($wmsIndex !== null && !$currentMapIsOverview) {
+
+			// check if this WMS has a layer equal to the current layer.
+			// If yes, this is a new WMS. If not, append this layer
+			// to the existing WMS.
+			$matchingWmsLayerArray = $this->wmsArray[$wmsIndex]->objLayer;
 			
-			$wmc_string .= "var index = " . $target . "getMapObjIndexByName('" . $mapObj . "');\n";
-			if ($action == "load") {
-				// delete all previous wms
-				$wmc_string .= "while(" . $target . "mb_mapObj[index].wms.length > 0){" . $target . "mb_mapObjremoveWMS(index,0);}";
-				$wmc_string .= $target . "deleteWmsObject();\n";
+			for ($i = 0; $i < count($matchingWmsLayerArray); $i++) {
+				if ($matchingWmsLayerArray[$i]->layer_name == $currentLayer["name"]) {
+
+					// by re-setting the index to null, a new WMS will be 
+					// added below.
+					$wmsIndex = null;
+					break;
+				}
 			}
-			if ($action == "merge") {
-				$wmc_string .= "var wms_exists = false;\n";				// true if this wms exists in the mapObj
-				$wmc_string .= "var current_wms_index = null;\n";		// if wms_exists: index of the wms in the map obj; else: null
-				$wmc_string .= "var layer_exists = false;\n";			// true if this layer exists in an existing wms of the mapObj
-				$wmc_string .= "var current_layer_index = null;\n";		// if layer_exists: index of the layer of the wms in the mapObj; else: null
-			}
-			$new_wms = "";
-			$cnt_wms = -1;
-			$added_wms = array();
+		}
+
+		// if yes, create a new WMS ...
+		if ($wmsIndex === null) {
+			$wmsIndex = 0;
+			$wms = new wms();
+
+			//
+			// set WMS data
+			//
+			$wms->wms_id = $currentLayer["extension"]["WMS_ID"]; // TO DO: how about WMS without ID?
+			$wms->wms_version = $currentLayer["version"];
+			$wms->wms_title = $currentLayer["wms_title"];
+			$wms->wms_abstract = $currentLayer["abstract"];
+			$wms->wms_getmap = $currentLayer["url"];
+			$wms->wms_getfeatureinfo = $currentLayer["url"]; // TODO : Add correct data
 			
-			// for all layers in wmc, find individual wms...
-			for ($i = 0; $i < count($this->wmc_layer_title); $i++) {
-				$current_wms = $this->wmc_wms_serviceURL[$i];
-				// ...this is something like 'for every wms'
-				if (!in_array($current_wms , $added_wms)) {
-					$layerlist = "";
-					$querylayerlist = "";
-					$srs_array = array();
-		
-					if ($action == "merge") {
-						$wmc_string .= "wms_exists = false;\n";
-						$wmc_string .= "current_wms_index = null;\n";
-						$wmc_string .= "for (var m=0; m < " . $target . "mb_mapObj[index].wms.length; m++) {\n";
-						$wmc_string .= "\tif ('" . $this->wmc_wms_serviceURL[$i] . "' ==  " . $target . "mb_mapObj[index].wms[m].wms_getmap) {\n";
-						$wmc_string .= "\t\twms_exists = true;\n";
-						$wmc_string .= "\t\tcurrent_wms_index = m;\n";
-						$wmc_string .= "\t}\n";
-						$wmc_string .= "}\n";
-						$wmc_string .= "if (!wms_exists) {\n";
-					}				
-					 
-					$mywms = new wms();
-			
-			  		if(!$this->wmc_layer_title[$i] || $this->wmc_layer_title[$i] == ""){
-						echo "alert('Error: no valid capabilities-document !!');\n";
-						die; exit;
-					}
+			$styleIndex = $currentLayer["styleIndex"];
+			$wms->wms_getlegendurl = $currentLayer["style"][$styleIndex]["legendurl"];
 
-					for($j=0;$j<count($this->wmc_layer_format[$i]);$j++){
-						if ($this->wmc_layer_format_current[$i][$j] == 1) {
-							$wms_data_format = $this->wmc_layer_format[$i][$j];
-						}
-					}
-					// add wms
-					$wmc_string .= "\t" . $target . "add_wms('".
-						$this->wmc_wms_id[$i]."','".
-						$this->wmc_wms_version[$i] ."','".
-						$this->wmc_wms_title[$i] ."','".
-						$this->wmc_layer_abstract[$i] ."','".
-						$this->wmc_wms_serviceURL[$i] ."','" .
-						$this->wmc_wms_serviceURL[$i] ."','" .
-						$this->wmc_layer_style_legendurl[$i][0] ."','','". 
-						$wms_data_format ."','text/html','application/vnd.ogc.se_xml','". 
-						$this->wmc_bBox_SRS ."','1','100','');\n";
-		
-					$added_wms[count($added_wms)] = $current_wms;
-					$cnt_wms++;
-					$cnt_layers = 0;
-					$cnt_query_layers = 0;
-					if ($action == "merge") {
-						$wmc_string .= "}\n";
-					}
-	
-					// add epsg
-					$wmc_string .= $target . "wms_addSRS('". 
-						$this->wmc_bBox_SRS ."','". 
-						$this->wmc_bBox_minx ."','". 
-						$this->wmc_bBox_miny ."','". 
-						$this->wmc_bBox_maxx ."','". 
-						$this->wmc_bBox_maxy ."','". 
-						"');\n";
+			$wms->wms_filter = ""; // TODO : Add correct data
 
-					// for each layer...
-					for ($ii = 0; $ii < count($this->wmc_layer_title); $ii++) {
-						$layer_wms = $this->wmc_wms_serviceURL[$ii];
-						// ... of this wms
-						if ($current_wms == $layer_wms) {
-							
-							// add format (FIXME: is this working?)
-							$z = count($this->wmc_layer_format[$ii]);
-							for($j=0;$j<$z;$j++){
-								$wmc_string .= $target . "wms_add_data_type_format('map','". $this->wmc_layer_format[$ii][$j] ."');\n";
-							}
-							
-							if ($cnt_layers == 0) {
-								if ($action == "merge") {
-									$wmc_string .= "if (!wms_exists) {\n\t";
-								} 
-								// add parent layer
-								$wmc_string .= $target . "wms_add_layer('','".
-									$this->wmc_wms_layer_id[$i]."','','". 
-									$this->wmc_wms_title[$i] ."','','0','0','0','0','','".
-									$this->wmc_wms_id[$i]."','1','', '1','1','0','0','0','0','');\n";
-								if ($action == "merge") {
-									$wmc_string .= "}\n";
-								} 
-							}
-	
-							$cnt_layers++;
-							
-							if ($action == "merge") {
-								$wmc_string .= "if (wms_exists) {\n";
-								
-								// check if this layer already exists in this wms
-								$wmc_string .= "\tlayer_exists = false;\n";
-								$wmc_string .= "\tcurrent_layer_index = null;\n";
-								$wmc_string .= "\tfor (var m=0; m < " . $target . "mb_mapObj[index].wms[current_wms_index].objLayer.length; m++) {\n";
-								$wmc_string .= "\t\tif ('" . $this->wmc_layer_name[$ii] . "' ==  " . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[m].layer_name) {\n";
-								$wmc_string .= "\t\t\tlayer_exists = true;\n";
-								$wmc_string .= "\t\t\tcurrent_layer_index = m;\n";
-								$wmc_string .= "\t\t}\n";
-								$wmc_string .= "\t}\n"; 
+			$formatIndex = $currentLayer["formatIndex"];
+			$wms->gui_wms_mapformat = $currentLayer["format"][$formatIndex]["name"];
 
-								if ($this->wmc_layer_querylayer[$ii]!="") {
-									$querylayer_yn = $this->wmc_layer_querylayer[$ii];
-								}
-								else {
-									$querylayer_yn = $this->wmc_layer_queryable[$ii];
-								}			
-								$wmc_string .= "\tif (layer_exists) {\n";
-								// check if the visibility or the queryability are different to the existing layer
-								$wmc_string .= "\t\tif (" . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_visible != '" . intval(!$this->wmc_layer_hidden[$ii]) . "'";
-								$wmc_string .= " || " . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer != '" . $querylayer_yn . "') {\n";
-		
-								// if yes, update the visibility and queryability
-								$wmc_string .= "\t\t\t" . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_visible = " . intval(!$this->wmc_layer_hidden[$ii]) . ";\n"; 
-								$wmc_string .= "\t\t\t" . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer = " . $querylayer_yn . ";\n"; 
-								$wmc_string .= "\t\t}\n";
-								$wmc_string .= "\t}\n"; 
-								$wmc_string .= "}\n"; 
-								$wmc_string .= "\telse {\n";
-							} 
+			$wms->gui_wms_featureinfoformat = "text/html"; // TODO : Add correct data
+			$wms->gui_wms_exceptionformat = "application/vnd.ogc.se_xml"; // TODO : Add correct data
+			$wms->gui_wms_epsg = $this->mainMap->getEpsg();
+			$wms->gui_wms_visible = 1; // TODO : Add correct data
+			$wms->gui_wms_opacity = 100; // TODO : Add correct data
+			$wms->gui_wms_sldurl = $currentLayer["style"][$styleIndex]["sld_url"];
 
-							// add layer
-							$wmc_string .= "\t" . $target . "wms_add_layer('".
-								($this->wmc_layer_parent[$ii]!=""?$this->wmc_layer_parent[$ii]:"0") . "','". 
-								$this->wmc_layer_id[$ii] . "','". 
-								$this->wmc_layer_name[$ii] . "','". 
-								$this->wmc_layer_title[$ii] ."','". 
-								$this->wmc_layer_dataurl[$ii] . "','". 
-								($this->wmc_layer_pos[$ii]!=""?$this->wmc_layer_pos[$ii]:intval($cnt_layers)) ."','". 
-								$this->wmc_layer_queryable[$ii] ."','".
-								$this->wmc_layer_minscale[$ii]  ."','". 
-								$this->wmc_layer_maxscale[$ii]  ."','". 
-								$this->wmc_layer_metadataurl[$ii] ."','". 
-								$this->wmc_wms_id[$i] ."','1','', '1','". 
-								intval(!$this->wmc_layer_hidden[$ii]) ."','". 
-								$this->wmc_layer_queryable[$ii] ."','". 
-								($this->wmc_layer_querylayer[$ii]!=""?$this->wmc_layer_querylayer[$ii]:$this->wmc_layer_queryable[$ii]) ."','".
-								($this->wmc_gui_layer_minscale[$ii]!=""?$this->wmc_gui_layer_minscale[$ii]:$this->wmc_layer_minscale[$ii]) ."','".
-								($this->wmc_gui_layer_maxscale[$ii]!=""?$this->wmc_gui_layer_maxscale[$ii]:$this->wmc_layer_maxscale[$ii]) ."','".
-								$this->wmc_layer_wfs_featuretype[$ii] . "');\n";
-	
-							if ($action == "merge") {
-								$wmc_string .= "\t}\n";
-							} 
-												
-							// if layer is queryable, add it to querylayerlist
-							if (($this->wmc_layer_querylayer[$ii]!=""?$this->wmc_layer_querylayer[$ii]:$this->wmc_layer_queryable[$ii])) {
-								$cnt_query_layers++;
-								if (!in_array($this->wmc_layer_name[$ii], explode(",",$querylayerlist))) {
-									if ($querylayerlist == "") {$querylayerlist = $this->wmc_layer_name[$ii];} else {$querylayerlist .= "," . $this->wmc_layer_name[$ii];} 
-								}
-							}
-							// if layer is visible, add it to layerlist 
-							if (intval(!$this->wmc_layer_hidden[$ii]) && !in_array($this->wmc_layer_name[$ii], explode(",",$layerlist))) {
-								if ($layerlist == "") {$layerlist = $this->wmc_layer_name[$ii];} else {$layerlist .= "," . $this->wmc_layer_name[$ii];}
-							}
-	
-							// add layer style (FIXME: is this working?)
-							for($j=0; $j<count($this->wmc_layer_style_name[$ii]);$j++){
-								$wmc_string .= $target . "wms_addLayerStyle('".$this->wmc_layer_style_name[$ii][$j] ."','".$this->wmc_layer_style_title[$ii][$j] ."','".$j."','".$cnt_layers."', '" . $this->wmc_layer_style_legendurl[$ii][$j] . "', '" . $this->wmc_layer_style_legendurl_format[$ii][$j] . "');\n";
-							}
-						}
-					}
-					// add wms to mapObj with all layers and querylayers
-					if ($action == "merge") {
-						$wmc_string .= "if (!wms_exists) {\n";
-					} 
-					$wmc_string .= $target. "mb_mapObjaddWMSwithLayers('" . $mapObj . "', '" . $layerlist . "', '" . $querylayerlist . "');\n";
-					if ($action == "merge") {
-						$wmc_string .= "}\n";
-						$wmc_string .= "else {\n";
-						$wmc_string .= $target. "mb_mapObj[index].layers[current_wms_index] = \"" . $layerlist . "\";\n";
-						$wmc_string .= $target. "mb_mapObj[index].querylayers[current_wms_index] = \"" . $querylayerlist . "\";\n";
-						$wmc_string .= "}\n";
-					}
-				}
+			$wms->gui_epsg = $currentLayer["epsg"];
+			//
+			// set data formats
+			//
+			for ($i = 0; $i < count($currentLayer["format"]); $i++) {
+				array_push($wms->data_type, "map");							
+				array_push($wms->data_format, $currentLayer["format"][$i]["name"]);							
 			}
-			$wmc_string .= "var old_mapObj = ".$target."cloneObject(".$target."mb_mapObj);\n";
-			$wmc_string .= $target . "deleteMapObj();\n";
-			$wmc_string .= "for (var i=0; i<old_mapObj.length; i++) {\n";
-			$wmc_string .= "\tif (old_mapObj[i].frameName != 'overview') {\n";
-			$wmc_string .= "\t\t" . $target . "mb_registerMapObj(old_mapObj[i].frameName, old_mapObj[i].elementName, null, " . $this->wmc_windowWidth . ", " . $this->wmc_windowHeight . ");\n"; 
-			$wmc_string .= "\t\t" . $target . "document.getElementById(old_mapObj[i].frameName).style.width = " . $this->wmc_windowWidth . ";\n";
-			$wmc_string .= "\t\t" . $target . "document.getElementById(old_mapObj[i].frameName).style.height = " . $this->wmc_windowHeight . ";\n";
-			$wmc_string .= "\t}\n";
-			$wmc_string .= "\telse {\n";
-			$wmc_string .= "\t\tvar found = false;\n";
-			$wmc_string .= "\t\tfor (var j=0; j < " . $target . "wms.length && found == false; j++) {\n";
-			$wmc_string .= "\t\t\tif (" . $target . "wms[j].wms_getmap == old_mapObj[i].wms[0].wms_getmap) {\n";
-			$wmc_string .= "\t\t\t\t" . $target . "mb_registerMapObj('overview', old_mapObj[i].elementName, j, old_mapObj[i].width,  old_mapObj[i].width);\n"; 
-			$wmc_string .= "\t\t\t\tfound = true;\n"; 
-			$wmc_string .= "\t\t\t}\n";
-			$wmc_string .= "\t\t}\n";
-			$wmc_string .= "\t\tif (!found) {\n";
-			$wmc_string .= "\t\t\t" . $target . "mb_registerMapObj('overview', old_mapObj[i].elementName, 0, old_mapObj[i].width,  old_mapObj[i].width);\n"; 
-			$wmc_string .= "\t\t}\n";
-			$wmc_string .= "\t}\n";
-			$wmc_string .= "}\n";
-			
-			$ov_bbox = array();
-			// compute the union of the overview and the mapframe bbox for the new overview bbox
-			if ($this->wmc_general_extension["ov_minx"] && $this->wmc_general_extension["ov_miny"] && 
-				$this->wmc_general_extension["ov_maxx"] && $this->wmc_general_extension["ov_maxy"]) {
 
-				// box for overview
-				$ov_min = new Mapbender_point($this->wmc_general_extension["ov_minx"], $this->wmc_general_extension["ov_miny"], $this->wmc_bBox_SRS);
-				$ov_max = new Mapbender_point($this->wmc_general_extension["ov_maxx"], $this->wmc_general_extension["ov_maxy"], $this->wmc_bBox_SRS);
-				$ov_box = new Mapbender_bbox($ov_min, $ov_max, $this->wmc_bBox_SRS);
-				
-				// box for mapframe
-				$mf_min = new Mapbender_point($this->wmc_bBox_minx, $this->wmc_bBox_miny, $this->wmc_bBox_SRS);
-				$mf_max = new Mapbender_point($this->wmc_bBox_maxx, $this->wmc_bBox_maxy, $this->wmc_bBox_SRS);
-				$mf_box = new Mapbender_bbox($mf_min, $mf_max, $this->wmc_bBox_SRS);
-				
-				$unionBox = Mapbender_bbox::union(array($ov_box, $mf_box));
-				
-				array_push($ov_bbox, $unionBox->min->x); 				
-				array_push($ov_bbox, $unionBox->min->y); 				
-				array_push($ov_bbox, $unionBox->max->x); 				
-				array_push($ov_bbox, $unionBox->max->y); 				
-			}
-			else {
-/*
-				$sql = "SELECT minx, miny, maxx, maxy FROM layer_epsg WHERE fkey_layer_id = $1 AND epsg = $2 LIMIT 1";
-				$v = array($this->wmc_layer_id[0], $this->wmc_bBox_SRS);
-				$t = array('i', 's');
-				$res = db_prep_query($sql, $v, $t);
-				$row = db_fetch_array($res);
-				if ($row["minx"] && $row["miny"] && $row["maxx"] && $row["maxy"]) {
-					$ov_bbox = array($row["minx"],$row["miny"],$row["maxx"],$row["maxy"]);
+			// set root layer
+			$wms->addLayer(0, "");
+			$wms->objLayer[0]->layer_uid = $currentLayer["extension"]["WMS_LAYER_ID"];
+			$wms->objLayer[0]->layer_name = $currentLayer["extension"]["WMS_NAME"];
+			$wms->objLayer[0]->layer_title = $currentLayer["wms_title"];
+			$wms->objLayer[0]->layer_pos = 0;
+			$wms->objLayer[0]->layer_queryable = 0;
+			$wms->objLayer[0]->layer_minscale = 0;
+			$wms->objLayer[0]->layer_maxscale = 0;
+			$wms->objLayer[0]->gui_layer_wms_id = $currentLayer["extension"]["WMS_ID"];
+			$wms->objLayer[0]->gui_layer_status = 1;
+			$wms->objLayer[0]->gui_layer_selectable = 1; 
+			$wms->objLayer[0]->gui_layer_visible = 1;
+			$wms->objLayer[0]->gui_layer_queryable = 0;
+			$wms->objLayer[0]->gui_layer_querylayer = 0;
+			$wms->objLayer[0]->gui_layer_minscale = 0;
+			$wms->objLayer[0]->gui_layer_maxscale = 0;
+
+			// layer epsg
+			if ($currentLayer["extension"]["EPSG"]) {
+				$layerEpsgArray = array();
+				$layerMinXArray = array();
+				$layerMinYArray = array();
+				$layerMaxXArray = array();
+				$layerMaxYArray = array();
+				if (!is_array($currentLayer["extension"]["EPSG"])) {
+					$layerEpsgArray[0] = $currentLayer["extension"]["EPSG"];
+					$layerMinXArray[0] = $currentLayer["extension"]["MINX"];
+					$layerMinYArray[0] = $currentLayer["extension"]["MINY"];
+					$layerMaxXArray[0] = $currentLayer["extension"]["MAXX"];
+					$layerMaxYArray[0] = $currentLayer["extension"]["MAXY"];
 				}
-				else if ($this->wmc_layer_id[0] && $this->wmc_bBox_SRS){
-					$ov_bbox = array($this->wmc_bBox_minx, $this->wmc_bBox_miny, $this->wmc_bBox_maxx, $this->wmc_bBox_maxy);
-				}
 				else {
-*/
-					$ov_bbox = array(2412139.175257732, 5365000, 2767860.824742268, 5700000);		
-//				}
-			}
+					$layerEpsgArray = $currentLayer["extension"]["EPSG"];
+					$layerMinXArray = $currentLayer["extension"]["MINX"];
+					$layerMinYArray = $currentLayer["extension"]["MINY"];
+					$layerMaxXArray = $currentLayer["extension"]["MAXX"];
+					$layerMaxYArray = $currentLayer["extension"]["MAXY"];
+				}
+	
+				for ($i=0; $i < count($layerEpsgArray); $i++) {
+					$currentLayerEpsg = array();
+					$currentLayerEpsg["epsg"] = $layerEpsgArray[$i];
+					$currentLayerEpsg["minx"] = floatval($layerMinXArray[$i]);
+					$currentLayerEpsg["miny"] = floatval($layerMinYArray[$i]); 
+					$currentLayerEpsg["maxx"] = floatval($layerMaxXArray[$i]);
+					$currentLayerEpsg["maxy"] = floatval($layerMaxYArray[$i]);
+					array_push($wms->objLayer[0]->layer_epsg, $currentLayerEpsg);
+				}
+			}			
+			// add WMS
+			array_push($wmsArray, $wms);
+
+			// the index of the WMS we just added
+			$wmsIndex = count($wmsArray) - 1;
+		}
+
+		// add layer to existing WMS ...
+		$currentWms = $wmsArray[$wmsIndex];
+		$currentWms->newLayer($currentLayer, null);
+		$currentMap->setWmsArray($wmsArray);
+		return true;
+	}
+	
+	/**
+	 * Called during WMC parsing; sets the maps within a WMC.
+	 * 
+	 * @return 
+	 */
+	private function setMapData () {
+		if ($this->generalExtensionArray["OV_WIDTH"] && 
+			$this->generalExtensionArray["OV_HEIGHT"] &&
+			$this->generalExtensionArray["OV_FRAMENAME"] &&
+			$this->generalExtensionArray["OV_MINX"] &&
+			$this->generalExtensionArray["OV_MINY"] &&
+			$this->generalExtensionArray["OV_MAXX"] &&
+			$this->generalExtensionArray["OV_MAXY"] &&
+			$this->generalExtensionArray["OV_SRS"]) {
 			
-			$wmc_string .= "for (var i=0; i<old_mapObj.length; i++) {\n";
-			$wmc_string .= "\tif (old_mapObj[i].frameName != 'overview') {\n";
-			$wmc_string .= "\t\t".$target."mb_calculateExtent(old_mapObj[i].frameName, ";
-			$wmc_string .= $this->wmc_bBox_minx .",".$this->wmc_bBox_miny .",";
-			$wmc_string .= $this->wmc_bBox_maxx .",".$this->wmc_bBox_maxy.");\n";
-			$wmc_string .= "\t}\n";
-			$wmc_string .= "\telse {\n";
-			$wmc_string .= "\t\t".$target."mb_calculateExtent(old_mapObj[i].frameName, ";
-			$wmc_string .= $ov_bbox[0] .",".$ov_bbox[1] .",";
-			$wmc_string .= $ov_bbox[2] .",".$ov_bbox[3] .");\n";
-			$wmc_string .= "\t}\n";
-			$wmc_string .= "\t". $target . "setMapRequest(old_mapObj[i].frameName);\n";
-			$wmc_string .= "}\n";
-			$wmc_string .= $target . "mb_execloadWmsSubFunctions();\n";
+			$this->overviewMap = new Map();
+			$this->overviewMap->setWidth($this->generalExtensionArray["OV_WIDTH"]);
+			$this->overviewMap->setHeight($this->generalExtensionArray["OV_HEIGHT"]);
+			$this->overviewMap->setFrameName($this->generalExtensionArray["OV_FRAMENAME"]);
+			$this->overviewMap->setIsOverview(true);
+
+			$bbox = new Mapbender_bbox($this->generalExtensionArray["OV_MINX"], $this->generalExtensionArray["OV_MINY"], $this->generalExtensionArray["OV_MAXX"], $this->generalExtensionArray["OV_MAXY"], $this->generalExtensionArray["OV_SRS"]);
+			$this->overviewMap->setExtent($bbox);
 		}
-//		$e = new mb_exception("js code: " . $wmc_string);
-		return $wmc_string;
+		if ($this->generalExtensionArray["MAIN_FRAMENAME"]) {
+			$this->mainMap->setFrameName($this->generalExtensionArray["MAIN_FRAMENAME"]);
+		}
+		else {
+			$this->mainMap->setFrameName("mapframe1");
+		}
+		return true;
 	}
+
+	/**
+	 * Creates a WMC document (XML) from the current object
+	 * 
+	 * @return String XML
+	 */
+	private function createXml() {
+		$wmcToXml = new WmcToXml($this);
+		$this->xml = $wmcToXml->getXml();
+	}
 } 
-// end class
+
+/**
+ * @deprecated
+ */
+function mb_utf8_encode ($str) {
+//	if(CHARSET=="UTF-8") return utf8_encode($str);
+	return $str;
+}
+
+/**
+ * @deprecated
+ */
+function mb_utf8_decode ($str) {
+//	if(CHARSET=="UTF-8") return utf8_decode($str);
+	return $str;
+}
 ?>

Added: branches/2.5/http/classes/class_wmcToXml.php
===================================================================
--- branches/2.5/http/classes/class_wmcToXml.php	                        (rev 0)
+++ branches/2.5/http/classes/class_wmcToXml.php	2009-01-08 14:47:47 UTC (rev 3417)
@@ -0,0 +1,560 @@
+<?php
+# $Id: class_wmc.php 2466 2008-05-20 08:55:03Z 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.
+
+/**
+ * The XML representation of a WMC object.
+ * 
+ * Usage:
+ * 
+ * $wmcToXml = new WmcToXml($wmc);
+ * $xml = $wmcToXml->getXml();
+ * 
+ */
+class WmcToXml {
+
+	private $wmc = null;
+	private $doc;
+	private $xml = "";
+	
+	/**
+	 * Constructor. Computes the XML of the WMC object given as parameter.
+	 * 
+	 * @param $someWmc wmc
+	 */
+	public function __construct ($someWmc) {
+		$this->wmc = $someWmc;
+		$this->toXml();
+	} 
+
+	// ---------------------------------------------------------------------
+	// public functions
+	// ---------------------------------------------------------------------
+	
+	public function getXml () {
+		return $this->xml;
+	}
+	
+	// ---------------------------------------------------------------------
+	// private functions
+	// ---------------------------------------------------------------------
+	
+	private function toXml () {
+
+		// add main map and overview (if exists) to $mapArray
+		$mapArray = array($this->wmc->mainMap);
+		if ($this->wmc->overviewMap !== null) {
+			array_push($mapArray, $this->wmc->overviewMap);
+		}
+
+		// generate XML
+		$this->doc = new DOMDocument("1.0", CHARSET);
+		$this->doc->preserveWhiteSpace = false;
+		
+		// ViewContext
+		$e_view_context = $this->doc->createElementNS("http://www.opengis.net/context", "ViewContext");
+		$e_view_context->setAttribute("version", "1.1.0");
+		$e_view_context->setAttribute("id", $this->wmc->wmc_id);
+		$e_view_context->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+		$e_view_context->setAttribute("xmlns:" . $this->wmc->extensionNamespace, $this->wmc->extensionNamespaceUrl);
+		$e_view_context->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+		$e_view_context->setAttribute("xsi:SchemaLocation", "http://schemas.opengis.net/context/1.0.0/context.xsd");
+		
+		// General
+		$e_general = $this->createGeneralNode();	
+		if ($e_general !== null) {
+			$e_view_context->appendChild($e_general);
+		}	
+		
+		// Layerlist
+		$e_layer_list = $this->doc->createElement("LayerList");
+		while (count($mapArray) > 0) {
+			
+			$currentMap = array_pop($mapArray);
+			$currentWmsArray = $currentMap->getWmsArray();
+	
+			for ($i = 0; $i < count($currentWmsArray); $i++) {
+				$currentWms = $currentWmsArray[$i];
+				
+				for ($j = 0; $j < count($currentWms->objLayer); $j++) {
+					$currentLayer = $currentWms->objLayer[$j];
+					
+					$layerNode = $this->createLayerNode($currentMap, $currentWms, $currentLayer);
+					if ($layerNode !== null) {
+						$e_layer_list->appendChild($layerNode);
+					}
+				}
+			}
+		}
+		$e_view_context->appendChild($e_layer_list);
+
+		$this->doc->appendChild($e_view_context);
+		$this->xml = $this->doc->saveXML();
+	}
+
+	private function createGeneralNode () {
+		$extensionData = array();
+		if ($this->wmc->overviewMap !== null) {
+			$ovExtent = $this->wmc->overviewMap->getExtent();
+			$extensionData["ov_minx"] = $ovExtent->min->x;
+			$extensionData["ov_miny"] = $ovExtent->min->y;
+			$extensionData["ov_maxx"] = $ovExtent->max->x;
+			$extensionData["ov_maxy"] = $ovExtent->max->y;
+			$extensionData["ov_srs"] = $ovExtent->epsg;
+			$extensionData["ov_framename"] = $this->wmc->overviewMap->getFrameName();
+			$extensionData["ov_width"] = $this->wmc->overviewMap->getWidth();
+			$extensionData["ov_height"] = $this->wmc->overviewMap->getHeight();
+		}
+		
+		if ($this->wmc->mainMap !== null) {
+			$extensionData["main_framename"] = $this->wmc->mainMap->getFrameName();
+		}
+				
+		// General
+		$e_general = $this->doc->createElement("General");
+		
+		// Window
+		$e_window = $this->doc->createElement("Window");
+		if ($this->wmc->mainMap->getWidth() && $this->wmc->mainMap->getHeight()) {
+			$e_window->setAttribute("width", $this->wmc->mainMap->getWidth());
+			$e_window->setAttribute("height", $this->wmc->mainMap->getHeight());
+		}
+		$e_general->appendChild($e_window);
+		
+		// BoundingBox
+		$mainExtent = $this->wmc->mainMap->getExtent();
+		$e_bbox = $this->doc->createElement("BoundingBox");
+		$e_bbox->setAttribute("SRS", $mainExtent->epsg);
+		$e_bbox->setAttribute("minx", $mainExtent->min->x);
+		$e_bbox->setAttribute("miny", $mainExtent->min->y);
+		$e_bbox->setAttribute("maxx", $mainExtent->max->x);
+		$e_bbox->setAttribute("maxy", $mainExtent->max->y);
+		$e_general->appendChild($e_bbox);
+				
+		// Name
+		$e_name = $this->doc->createElement("Name", $this->wmc->wmc_name);
+		$e_general->appendChild($e_name);
+				
+		// Title
+		$e_title = $this->doc->createElement("Title", $this->wmc->wmc_title);
+		$e_general->appendChild($e_title);
+				
+		// Keywords
+		$e_keyword_list = $this->doc->createElement("KeywordList");
+		for ($i=0; $i < count($this->wmc->wmc_keyword); $i++) {
+			$e_keyword = $this->doc->createElement("Keyword", $this->wmc->wmc_keyword[$i]);
+			$e_keyword_list->appendChild($e_keyword);
+		}
+		$e_general->appendChild($e_keyword_list);
+				
+		// Abstract
+		if ($this->wmc->wmc_abstract) {
+			$e_abstract = $this->doc->createElement("Abstract", $this->wmc->wmc_abstract);
+			$e_general->appendChild($e_abstract);
+		}
+	
+		// Logo URL			
+		if ($this->wmc->wmc_logourl_width && $this->wmc->wmc_logourl_height && 
+			$this->wmc->wmc_logourl_format && $this->wmc->wmc_logourl){
+			
+			$e_logo_url = $this->doc->createElement("LogoURL");
+			$e_logo_url->setAttribute("width", $this->wmc->wmc_logourl_width);
+			$e_logo_url->setAttribute("height", $this->wmc->wmc_logourl_height);
+			$e_logo_url->setAttribute("format", $this->wmc->wmc_logourl_format);
+		
+			$e_logo_url_or = $this->doc->createElement("OnlineResource");
+			$e_logo_url_or->setAttributeNS("http://www.opengis.net/context", "xmlns:xlink", "http://www.w3.org/1999/xlink");
+			$e_logo_url_or->setAttribute("xlink:type", "simple");
+			$e_logo_url_or->setAttribute("xlink:href", $this->wmc->wmc_logourl);
+			$e_logo_url->appendChild($e_logo_url_or);
+
+			$e_general->appendChild($e_logo_url);
+		}
+				
+		// Description URL	
+		if ($this->wmc->wmc_descriptionurl){
+			$e_description_url = $this->doc->createElement("DescriptionURL");
+
+			$e_description_url_or = $this->doc->createElement("OnlineResource");
+			$e_description_url_or->setAttributeNS("http://www.opengis.net/context", "xmlns:xlink", "http://www.w3.org/1999/xlink");
+			$e_description_url_or->setAttribute("xlink:type", "simple");
+			$e_description_url_or->setAttribute("xlink:href", $this->wmc->wmc_descriptionurl);
+			$e_description_url->appendChild($e_description_url_or);
+
+			$e_general->appendChild($e_description_url);
+		}
+				
+		// Contact information
+		$e_contact = $this->createContactInformationNode();
+		if ($e_contact !== null) {
+			$e_general->appendChild($e_contact);
+		}
+
+		// Extension data				
+		if (count($extensionData) > 0) {
+			$e_extensionGeneral = $this->doc->createElement("Extension");
+			
+			foreach ($extensionData as $keyExtensionData => $valueExtensionData) {
+				$e_currentExtensionTag = $this->doc->createElement($this->wmc->extensionNamespace.":".$keyExtensionData, $valueExtensionData);
+				$e_extensionGeneral->appendChild($e_currentExtensionTag);
+			}
+			$e_general->appendChild($e_extensionGeneral);
+		}
+		return $e_general;
+	}
+	
+	private function createLayerNode ($currentMap, $currentWms, $currentLayer) {
+		if ($currentLayer->layer_parent != '') {
+
+			// Layer
+			$e_layer = $this->doc->createElement("Layer");
+			$e_layer->setAttribute("queryable", $currentLayer->layer_queryable);
+			$e_layer->setAttribute("hidden", ($currentLayer->gui_layer_visible ? 0 : 1));
+
+			// Server
+			$e_service = $this->doc->createElement("Server");
+			$e_service->setAttribute("service", "OGC:WMS");
+			$e_service->setAttribute("version", $currentWms->wms_version);
+			$e_service->setAttribute("title", $currentWms->wms_title);
+
+			// Online resource
+			$e_service_or = $this->doc->createElement("OnlineResource");
+			$e_service_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+			$e_service_or->setAttribute("xlink:type", "simple");
+			$e_service_or->setAttribute("xlink:href", $currentWms->wms_getmap);
+			$e_service->appendChild($e_service_or);
+			$e_layer->appendChild($e_service);
+
+			// Name
+			$e_layer_name = $this->doc->createElement("Name", $currentLayer->layer_name);
+			$e_layer->appendChild($e_layer_name);
+
+			// Title
+			$e_layer_title = $this->doc->createElement("Title", $currentLayer->layer_title);
+			$e_layer->appendChild($e_layer_title);
+
+			// Abstract
+			if ($currentWms->wms_abstract){
+				$e_layer_abstract = $this->doc->createElement("Abstract", $currentWms->wms_abstract);
+				$e_layer->appendChild($e_layer_abstract);
+			}
+
+			// SRS		
+			$srsNode = $this->createSrsNode($currentMap, $currentWms);
+			if ($srsNode !== null) {
+				$e_layer->appendChild($srsNode);
+			}
+	
+			// Data URL
+			if ($currentLayer->layer_dataurl_href){
+				$e_layer_data_url = $this->doc->createElement("DataURL");
+	
+				$e_layer_data_url_or = $this->doc->createElement("OnlineResource");
+				$e_layer_data_url_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+				$e_layer_data_url_or->setAttribute("xlink:type", "simple");
+				$e_layer_data_url_or->setAttribute("xlink:href", $currentLayer->layer_dataurl_href);
+				
+				$e_layer_data_url->appendChild($e_layer_data_url_or);
+				$e_layer->appendChild($e_layer_data_url);
+			}
+
+			// Metadata URL
+			if ($currentLayer->layer_metadataurl){
+				$e_layer_metadata_url = $this->doc->createElement("MetadataURL");
+
+				// Metadata URL online resource
+				$e_layer_metadata_url_or = $this->doc->createElement("OnlineResource");
+				$e_layer_metadata_url_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+				$e_layer_metadata_url_or->setAttribute("xlink:type", "simple");
+				$e_layer_metadata_url_or->setAttribute("xlink:href", $currentLayer->layer_metadataurl);
+				$e_layer_metadata_url->appendChild($e_layer_metadata_url_or);
+				$e_layer->appendChild($e_layer_metadata_url);
+			}
+
+			// Layer format
+			$formatListNode = $this->createLayerFormatListNode($currentWms);
+			if ($formatListNode !== null) {
+				$e_layer->appendChild($formatListNode);
+			}
+
+			// Layer style
+			$layerStyleListNode = $this->createLayerStyleNode($currentWms, $currentLayer);
+			if ($layerStyleListNode !== null) {
+				$e_layer->appendChild($layerStyleListNode);
+			}
+
+			// Extension
+			$extensionNode = $this->createLayerExtensionNode($currentMap, $currentWms, $currentLayer);
+			if ($extensionNode !== null) {
+				$e_layer->appendChild($extensionNode);
+			}
+
+			return $e_layer;
+		}
+		return null;	
+	}
+
+	private function createSrsNode ($currentMap, $currentWms) {
+		$wms_epsg = array();
+		$wms_epsg[0] = $currentMap->getEpsg();
+	
+		if ($currentWms->gui_wms_epsg != $currentMap->getEpsg()) {
+			$wms_epsg[1] = $currentWms->gui_wms_epsg;
+		}
+
+		for ($j = 0; $j < count($currentWms->gui_epsg); $j++) {
+			if (!in_array($currentWms->gui_epsg[$j], $wms_epsg)){
+				array_push($wms_epsg, $currentWms->gui_epsg[$j]);
+			}
+		}
+
+		$e_layer_srs = $this->doc->createElement("SRS", implode(" ", $wms_epsg));
+		return $e_layer_srs;
+	}
+
+	private function createLayerFormatListNode ($currentWms) {
+		$e_layer_format = $this->doc->createElement("FormatList");
+
+		$data_format_current = false;
+		
+		for ($k = 0; $k < count($currentWms->data_format); $k++){
+
+			if ($currentWms->data_type[$k] == "map") {
+				$layerFormat = $currentWms->data_format[$k];
+
+				$e_format = $this->doc->createElement("Format", $layerFormat);
+
+				if ($data_format_current === false && ( 
+						$currentWms->data_format[$k] == $currentWms->gui_wms_mapformat ||
+						$k == (count($currentWms->data_format)-1)
+				)){
+
+					$e_format->setAttribute("current", "1");
+					$data_format_current = true;
+				}
+				$e_layer_format->appendChild($e_format);
+			}
+		}
+		return $e_layer_format;
+	}
+
+	private function createLayerExtensionNode ($currentMap, $currentWms, $currentLayer) {
+		$layerExtensionData = array();
+		$layerExtensionData["wms_name"] = $currentWms->objLayer[0]->layer_name;
+		$layerExtensionData["minscale"] = $currentLayer->layer_minscale;
+		$layerExtensionData["maxscale"] = $currentLayer->layer_maxscale;
+		$layerExtensionData["gui_minscale"] = $currentLayer->gui_layer_minscale;
+		$layerExtensionData["gui_maxscale"] = $currentLayer->gui_layer_maxscale;
+		$layerExtensionData["layer_id"] = $currentLayer->layer_uid;
+		$layerExtensionData["wms_layer_id"] = $currentWms->objLayer[0]->layer_uid;
+		$layerExtensionData["layer_pos"] = $currentLayer->layer_pos;
+		$layerExtensionData["layer_parent"] = $currentLayer->layer_parent;
+		$layerExtensionData["wms_id"] = $currentLayer->gui_layer_wms_id;
+		$layerExtensionData["querylayer"] = $currentLayer->gui_layer_querylayer;
+		$layerExtensionData["gui_selectable"] = $currentLayer->gui_layer_selectable;
+		$layerExtensionData["gui_queryable"] = $currentLayer->gui_layer_queryable;
+		$layerExtensionData["gui_status"] = $currentLayer->gui_layer_status;
+		$layerExtensionData["layer_epsg"] = $currentLayer->layer_epsg;
+		
+		if ($currentMap->isOverview()) {
+			$layerExtensionData["isOverviewLayer"] = 1;
+		}
+		if ($currentLayer->gui_layer_wfs_featuretype) {
+			$layerExtensionData["wfsFeatureType"] = $currentLayer->gui_layer_wfs_featuretype;
+		}
+
+		if (count($layerExtensionData) > 0) {
+			$e_extension = $this->doc->createElement("Extension");
+			
+			foreach ($layerExtensionData as $keyExtensionData => $valueExtensionData) {
+				$e_currentExtensionTag = $this->addExtension($keyExtensionData, $valueExtensionData);
+				$e_extension->appendChild($e_currentExtensionTag);
+			}
+			return $e_extension;
+		}
+		return null;
+	}
+	
+	private function addExtension ($key, $value) {
+		if (is_array($value)) {
+			if (is_numeric($key)) {
+				$key = "data" . $key;
+			}
+			$e_currentExtensionTag = $this->doc->createElement($this->wmc->extensionNamespace.":".$key);
+			foreach ($value as $childKey => $childValue) {
+				$newNode = $this->addExtension($childKey, $childValue);
+				$e_currentExtensionTag->appendChild($newNode);
+			}
+		}
+		else {
+			$e_currentExtensionTag = $this->doc->createElement($this->wmc->extensionNamespace.":".$key, $value);
+		}
+		return $e_currentExtensionTag;
+	}
+	
+	private function createLayerStyleNode ($currentWms, $currentLayer) {
+		$e_layer_stylelist = $this->doc->createElement("StyleList");
+		
+		for ($k = 0; $k < count($currentLayer->layer_style); $k++) {
+
+			$currentStyle = $currentLayer->layer_style[$k];
+			
+			$layerStyle_current = 0;
+			if ($k === 0){
+				$layerStyle_current = 1; // To do: insert proper data
+			}
+
+			$e_layer_style = $this->doc->createElement("Style");
+
+			$layerStyleSLD = "";
+
+			if ($layerStyleSLD) {
+				$e_layer_style_or = $this->doc->createElement("OnlineResource");
+				$e_layer_style_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+				$e_layer_style_or->setAttribute("xlink:type", "simple");
+				$e_layer_style_or->setAttribute("xlink:href", $currentWms->gui_wms_sldurl);
+				$e_layer_style->appendChild($e_layer_style_or);
+			}
+			else{
+				
+				if ($layerStyle_current == 1){
+					$e_layer_style->setAttribute("current", "1");
+				}
+
+				$e_layer_style_name = $this->doc->createElement("Name", $currentStyle["name"]);
+				$e_layer_style->appendChild($e_layer_style_name);
+
+				$e_layer_style_title = $this->doc->createElement("Title", $currentStyle["title"]);
+				$e_layer_style->appendChild($e_layer_style_title);
+				
+				
+				$e_layer_style_legendurl = $this->doc->createElement("LegendUrl");
+
+				//TODO: determine correct layer style entries
+				$layerStyle_legendUrl_width = ""; // To Do: add proper data
+				$layerStyle_legendUrl_height = ""; // To Do: add proper data
+				$layerStyle_legendUrl_format = ""; // To Do: add proper data
+				$e_layer_style_legendurl->setAttribute("width", $layerStyle_legendUrl_width);
+				$e_layer_style_legendurl->setAttribute("height", $layerStyle_legendUrl_height);
+				$e_layer_style_legendurl->setAttribute("format", $layerStyle_legendUrl_format);
+
+				$e_layer_style_legendurl_or = $this->doc->createElement("OnlineResource");
+				$e_layer_style_legendurl_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+				$e_layer_style_legendurl_or->setAttribute("xlink:type", "simple");
+				$e_layer_style_legendurl_or->setAttribute("xlink:href", $currentStyle["legendurl"]);
+				$e_layer_style_legendurl->appendChild($e_layer_style_legendurl_or);
+				$e_layer_style->appendChild($e_layer_style_legendurl);
+			}
+			$e_layer_stylelist->appendChild($e_layer_style);
+		}	
+		return $e_layer_stylelist;
+	}
+	
+	/**
+	 * 
+	 * @return 
+	 */
+	private function createContactInformationNode () {
+		
+		if ($this->wmc->wmc_contactemail || $this->wmc->wmc_contactorganization ||
+			$this->wmc->wmc_contactperson || $this->wmc->wmc_contactposition || 
+			$this->wmc->wmc_contactaddresstype || $this->wmc->wmc_contactaddress || 
+			$this->wmc->wmc_contactcity || $this->wmc->wmc_contactstateorprovince ||
+			$this->wmc->wmc_contactpostcode || $this->wmc->wmc_contactcountry || 
+			$this->wmc->wmc_contactvoicetelephone || $this->wmc->wmc_contactfacsimiletelephone) {
+				
+			$e_contact = $this->doc->createElement("ContactInformation");
+			$e_contact_person_primary = $this->wmc->createContactPersonPrimaryNode();
+			if ($e_contact_person_primary !== null) {
+				$e_contact->appendChild($e_contact_person_primary);
+			}
+		
+			if ($this->wmc->wmc_contactposition){
+				$e_contact_position = $this->doc->createElement("ContactPosition", $this->wmc->wmc_contactposition);
+				$e_contact->appendChild($e_contact_position);
+			}
+		
+			if ($this->wmc->wmc_contactaddresstype || $this->wmc->wmc_contactaddress || 
+				$this->wmc->wmc_contactcity || $this->wmc->wmc_contactstateorprovince ||
+				$this->wmc->wmc_contactpostcode || $this->wmc->wmc_contactcountry) {
+		
+				$e_contact_address = $this->doc->createElement("ContactAddress");
+		
+				if ($this->wmc->wmc_contactaddresstype){
+					$e_address_type = $this->doc->createElement("AddressType", $this->wmc->wmc_contactaddresstype);
+					$e_contact_address->appendChild($e_address_type);
+				}
+				if ($this->wmc->wmc_contactaddress){
+					$e_address = $this->doc->createElement("Address", $this->wmc->wmc_contactaddress);
+					$e_contact_address->appendChild($e_address);
+				}
+				if ($this->wmc->wmc_contactcity){
+					$e_city = $this->doc->createElement("City", $this->wmc->wmc_contactcity);
+					$e_contact_address->appendChild($e_city);
+				}
+				if ($this->wmc->wmc_contactstateorprovince){
+					$e_state = $this->doc->createElement("StateOrProvince", $this->wmc->wmc_contactstateorprovince);
+					$e_contact_address->appendChild($e_state);
+				}
+				if ($this->wmc->wmc_contactpostcode){
+					$e_postcode = $this->doc->createElement("PostCode", $this->wmc->wmc_contactpostcode);
+					$e_contact_address->appendChild($e_postcode);
+				}
+				if ($this->wmc->wmc_contactcountry){
+					$e_country = $this->doc->createElement("Country", $this->wmc->wmc_contactcountry);
+					$e_contact_address->appendChild($e_country);
+				}
+				$e_contact->appendChild($e_contact_address);
+			}
+			
+			if ($this->wmc->wmc_contactvoicetelephone){
+				$e_voice_telephone = $this->doc->createElement("ContactVoiceTelephone", $this->wmc->wmc_contactvoicetelephone);
+				$e_contact->appendChild($e_voice_telephone);
+			}
+			if ($this->wmc->wmc_contactfacsimiletelephone){
+				$e_facsimile_telephone = $this->doc->createElement("ContactFacsimileTelephone", $this->wmc->wmc_contactfacsimiletelephone);
+				$e_contact->appendChild($e_facsimile_telephone);
+			}
+			if ($this->wmc->wmc_contactemail){
+				$e_email = $this->doc->createElement("ContactElectronicMailAddress", $this->wmc->wmc_contactemail);
+				$e_contact->appendChild($e_email);
+			}
+			return $e_contact;
+		}		
+		return null;
+	}
+	
+	private function createContactPersonPrimaryNode () {
+		if ($this->wmc->wmc_contactperson || $this->wmc->wmc_contactorganization){
+			$e_contact_person_primary = $this->doc->createElement("ContactPersonPrimary");
+	
+			if ($this->wmc->wmc_contactperson){
+				$e_contact_person = $this->doc->createElement("ContactPerson", $this->wmc->wmc_contactperson);
+				$e_contact_person_primary->appendChild($e_contact_person);
+			}
+			if ($this->wmc->wmc_contactorganization){
+				$e_contact_organization = $this->doc->createElement("ContactOrganization", $this->wmc->wmc_contactorganization);
+				$e_contact_person_primary->appendChild($e_contact_organization);
+			}
+			return $e_contact_person_primary;
+		}
+		return null;		
+	}
+
+}
+?>

Modified: branches/2.5/http/classes/class_wms.php
===================================================================
--- branches/2.5/http/classes/class_wms.php	2009-01-08 14:41:46 UTC (rev 3416)
+++ branches/2.5/http/classes/class_wms.php	2009-01-08 14:47:47 UTC (rev 3417)
@@ -1,7 +1,7 @@
 <?php
 # $Id$
 # http://www.mapbender.org/index.php/class_wms
-# Copyright (C) 2002 CCGIS
+# 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
@@ -19,6 +19,7 @@
 
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__)."/class_connector.php");
+require_once(dirname(__FILE__)."/class_user.php");
 require_once(dirname(__FILE__)."/class_administration.php");
 
 class wms {
@@ -34,7 +35,7 @@
 	var $wms_getfeatureinfo;
 	var $wms_getlegendurl;
 	var $wms_upload_url;
-
+	  
 	var $fees;
 	var $accessconstraints;
 	var $contactperson;
@@ -48,28 +49,28 @@
 	var $contactvoicetelephone;
 	var $contactfacsimiletelephone;
 	var $contactelectronicmailaddress;
-
+	  
 	var $wms_keyword = array();
-	var $data_type = array();
+	var $data_type = array(); 
 	var $data_format = array();
-	var $objLayer = 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() {
-	}
+	} 
 
 	public static function getConjunctionCharacter ($url) {
 		if (mb_strpos($url, "?") !== false) { 
@@ -89,11 +90,151 @@
 		return "";
 	}
 
+	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;
@@ -101,13 +242,13 @@
 		else {
 			$this->wms_status = true;
 		}
-
+			
 		$values = null;
 		$tags = null;
 		$admin = new administration();
 		$this->wms_getcapabilities_doc = $data;
 		$this->wms_upload_url = $url;
-
+		
 		$this->wms_id = "";
 		$parser = xml_parser_create("");
 		xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
@@ -117,22 +258,22 @@
 
 		$code = xml_get_error_code($parser);
 		if ($code) {
-			$line = xml_get_current_line_number($parser);
+			$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;
+		$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];
@@ -185,7 +326,7 @@
 	  		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"){
@@ -340,7 +481,7 @@
 			}
 	      /*legend section*/
 	      if($this->wms_version == "1.0.0"){
-
+	      
 	      }
 	      else{
 	        if(mb_strtoupper($element[tag]) == "GETLEGENDGRAPHIC" && $element[type] == "open"){
@@ -357,17 +498,17 @@
 			}
 			if(mb_strtoupper($element[tag]) == "GETLEGENDGRAPHIC" && $element[type] == "close"){
 				$section = "";
-			}
+			}         
 	      }
-			/* sld 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*/
+	      	      
+			/*layer section*/				
 			if(mb_strtoupper($element[tag]) == "LAYER"){
 				$section = "layer";
 				if ($element[type] == "open") {
@@ -379,7 +520,7 @@
 					$this->objLayer[$cnt_layer]->layer_queryable = $element[attributes][queryable];
 				}
 				if ($element[type] == "close") {
-
+				
 				}
 			}
 			/* attribution */
@@ -423,7 +564,7 @@
 				}
 			    if(mb_strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "close"){
 					$legendurl = false;
-				}
+				}   
 			}
 			/* end of styles */
 			if($section == "layer"){
@@ -447,8 +588,8 @@
 				}
 			    if(mb_strtoupper($element[tag]) == "DATAURL" && $element[type] == "close"){
 					$dataurl = false;
-				}
-
+				}   
+				
 				if(mb_strtoupper($element[tag]) == "METADATAURL" && $element[type] == "open"){
 					$metadataurl = true;
 				}
@@ -457,13 +598,13 @@
 				}
 			    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)));
-				}
+					$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";
@@ -485,12 +626,12 @@
 					}
 				}
 				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];
+					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;
 			}
@@ -498,13 +639,13 @@
 		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;
 		}
 	}
@@ -554,7 +695,7 @@
 		}
 		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;
+				$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;
@@ -563,7 +704,7 @@
 				}
 			}
 			if($this->objLayer[$i]->layer_name == ""){
-				$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;
@@ -585,11 +726,11 @@
 			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++){
@@ -606,7 +747,7 @@
 				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];
 		}
@@ -625,7 +766,7 @@
 		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;
@@ -640,7 +781,7 @@
 				$this->wms_remotewfs = 0;
 		}
 	  }
-
+	
 	function displayWMS(){
 		echo "<br>id: " . $this->wms_id . " <br>";
 		echo "version: " . $this->wms_version . " <br>";
@@ -651,13 +792,13 @@
 		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_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 "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>";
 		}
@@ -684,8 +825,8 @@
 	        echo "<hr>";
 	        echo "<hr>";
 		}
-	}
-	  function addLayer($id,$parent){
+	} 
+	  function addLayer($id,$parent){	
 		$this->objLayer[count($this->objLayer)] = new layer($id,$parent);
 	  }
 	  /**
@@ -694,17 +835,104 @@
 	  function stripEndlineAndCarriageReturn($string) {
 	  	return preg_replace("/\n/", "", preg_replace("/\r/", " ", $string));
 	  }
-	  function createJsObjFromWMS($parent=0){
+		function createJsObjFromWMS($parent=0){
+			echo $this->createJsObjFromWMS_($parent);
+		}
+		
+
+	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_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 ($currentLayer["extension"]["EPSG"]) {
+			$layerEpsgArray = array();
+			$layerMinXArray = array();
+			$layerMinYArray = array();
+			$layerMaxXArray = array();
+			$layerMaxYArray = array();
+			if (!is_array($currentLayer["extension"]["EPSG"])) {
+				$layerEpsgArray[0] = $currentLayer["extension"]["EPSG"];
+				$layerMinXArray[0] = $currentLayer["extension"]["MINX"];
+				$layerMinYArray[0] = $currentLayer["extension"]["MINY"];
+				$layerMaxXArray[0] = $currentLayer["extension"]["MAXX"];
+				$layerMaxYArray[0] = $currentLayer["extension"]["MAXY"];
+			}
+			else {
+				$layerEpsgArray = $currentLayer["extension"]["EPSG"];
+				$layerMinXArray = $currentLayer["extension"]["MINX"];
+				$layerMinYArray = $currentLayer["extension"]["MINY"];
+				$layerMaxXArray = $currentLayer["extension"]["MAXX"];
+				$layerMaxYArray = $currentLayer["extension"]["MAXY"];
+			}
+
+			for ($i=0; $i < count($layerEpsgArray); $i++) {
+				$currentLayerEpsg = array();
+				$currentLayerEpsg["epsg"] = $layerEpsgArray[$i];
+				$currentLayerEpsg["minx"] = floatval($layerMinXArray[$i]);
+				$currentLayerEpsg["miny"] = floatval($layerMinYArray[$i]); 
+				$currentLayerEpsg["maxx"] = floatval($layerMaxXArray[$i]);
+				$currentLayerEpsg["maxy"] = floatval($layerMaxYArray[$i]);
+				array_push($newLayer->layer_epsg, $currentLayerEpsg);
+			}
+		}
+
+
+		//
+		// set layer style
+		//
+		for ($i = 0; $i < count($currentLayer["style"]); $i++) {
+			$layerStyleIndex = count($newLayer->gui_layer_style) - 1;
+			$newLayer->layer_style[$layerStyleIndex] = array();
+			$newLayer->layer_style[$layerStyleIndex]["name"] = $currentLayer["style"][$i]["name"];
+			$newLayer->layer_style[$layerStyleIndex]["title"] = $currentLayer["style"][$i]["title"];	
+			$newLayer->layer_style[$layerStyleIndex]["legendurl"] = $currentLayer["style"][$i]["legendurl"];
+			$newLayer->layer_style[$layerStyleIndex]["legendurl_format"] = $currentLayer["style"][$i]["legendurl_type"];
+		}
+	}
+	
+	  function createJsObjFromWMS_($parent=0){
+	  	$str = "";
 	  	if(!$this->wms_title || $this->wms_title == ""){
-			echo "alert('Error: no valid capabilities-document !!');";
+			$str .= "alert('Error: no valid capabilities-document !!');";
 			die; exit;
 		}
 			if($parent){
-				echo "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 ."'," .
@@ -722,71 +950,77 @@
 					"'" . $this->gui_wms_opacity ."'," .
 					"'" . $this->gui_wms_sldurl ."" .
 					"');";
-			echo $add_wms_string;
-
+			$str .=  $add_wms_string;
+			
 		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";
+				$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){
-				echo "parent.";
+				$str .= "parent.";
 			}
-			print ("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 ."','".
+			$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_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");
-
+				$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.";
+						$str .= "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");
+					$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){
-				echo "parent.";
+					$str .=  "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");
+				$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){
-				echo "parent.";
+				$str .= "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");
+				$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 !!');";
@@ -797,54 +1031,54 @@
 			}
 			// wms_title and abstract have previously been urlencoded
 			// this solution may not yet be the ultimate one
-			print("add_wms('".
+			print("add_wms('". 
 			$this->wms_id ."','".
 			$this->wms_version ."','".
 			preg_replace("/'/", "", $this->wms_title) ."','".
-			preg_replace("/'/", "", $this->wms_abstract) ."','".
+			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_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";
+			}		
+			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 ."','".
+			 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_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++){
@@ -852,21 +1086,21 @@
 					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"] ."','".
+					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"] ."','".
+				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++){
@@ -875,15 +1109,15 @@
 				}
 				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
+	* this function exports the information from the xml to the mapbender database 
 	*/
 	function writeObjInDB($gui_id){
 		global $con;
@@ -891,7 +1125,7 @@
 
 		$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, ";
@@ -912,25 +1146,25 @@
 		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);
-
+		$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');
@@ -938,7 +1172,7 @@
 		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)";
@@ -948,10 +1182,10 @@
 		$t = array('s','i','i','s','s','s','s');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			db_rollback();
+			db_rollback();	
 		}
 		db_commit();
-
+	    
 	    #Changes JW
 	    $this->wms_id = $myWMS;
 	}
@@ -977,19 +1211,19 @@
 		$t = array('i','i','s','s','s','i','i','i','s','s','s');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			db_rollback();
+			db_rollback();	
 		}
 		else {
-			# save the id of each layer: set param2 true
+			# 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);
-
+			$this->insertLayerKeyword($i);	
+		
 		}
 	}
 	function updateLayer($i,$myWMS){
@@ -998,14 +1232,14 @@
 		$t = array('i','s');
 		$res = db_prep_query($sql,$v,$t);
 		if($row = db_fetch_array($res)){
-			$l_id = $row['layer_id'];
+			$l_id = $row['layer_id'];	
 		}
 		else{
 			db_rollback();
 			$e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name);
-			return;
-		}
-
+			return;	
+		}	
+		
 		$sql = "UPDATE layer SET ";
 		$sql .= "layer_pos = $1, ";
 		$sql .= "layer_parent = $2, ";
@@ -1017,7 +1251,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;
 		}
@@ -1031,7 +1265,7 @@
 				$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
+				$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);
@@ -1040,20 +1274,20 @@
 			$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();
+			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){
@@ -1063,7 +1297,7 @@
 	}
 	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) ";
@@ -1080,12 +1314,12 @@
 		$res = db_prep_query($sql,$v,$t);
 		#$e = new mb_exception("name des insert styles und fkey_layer_id: ".$layer_style_name." --- ".$this->objLayer[$i]->db_id);
 		if(!$res){
-			db_rollback();
-		}
+			db_rollback();	
+		}	
 	}
 	function appendGuiLayer($i,$myWMS,$gui_id){
 		# 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) ";
@@ -1101,19 +1335,19 @@
 		$t = array('s','i','i','i','i','i','i','i','i','i','i','s');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			db_rollback();
-		}
+			db_rollback();	
+		}	
 	}
 	function insertSRS($myWMS){
 		for($i=0; $i<count($this->wms_srs);$i++){
-			$sql ="INSERT INTO wms_srs (fkey_wms_id, wms_srs) values($1,$2)";
+			$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');
+			$t = array('i','s');		
 			$res = db_prep_query($sql,$v,$t);
 			if(!$res){
-				db_rollback();
+				db_rollback();	
 			}
-		}
+		}	
 	}
 	function insertFormat($myWMS){
 		for($i=0; $i<count($this->data_type);$i++){
@@ -1123,9 +1357,9 @@
 			$t = array('i','s','s');
 			$res = db_prep_query($sql,$v,$t);
 			if(!$res){
-				db_rollback();
+				db_rollback();	
 			}
-		}
+		}	
 	}
 	function insertLayerEPSG($i){
 		$sql = "DELETE FROM layer_epsg WHERE fkey_layer_id = $1";
@@ -1138,11 +1372,11 @@
 			$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();
+				db_rollback();	
 			}
 		}
 	}
@@ -1156,12 +1390,12 @@
 			$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"]
+					$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();
+				db_rollback();	
 			}
 		}
 	}
@@ -1171,13 +1405,13 @@
 		$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]);
@@ -1186,7 +1420,7 @@
 				$row = db_fetch_array($res);
 			//print_r($row);
 				if ($row) {
-					$keyword_id = $row["keyword_id"];
+					$keyword_id = $row["keyword_id"];	
 				}
 				else {
 					$sql_insertKeyword = "INSERT INTO keyword (keyword)";
@@ -1195,7 +1429,7 @@
 					$t1 = array('s');
 					$res_insertKeyword = db_prep_query($sql_insertKeyword,$v1,$t1);
 					if(!$res_insertKeyword){
-						db_rollback();
+						db_rollback();	
 					}
 				}
 			}
@@ -1214,7 +1448,7 @@
 				$t1 = array('i','i');
 				$res1 = db_prep_query($sql1,$v1,$t1);
 				if(!$res1){
-					db_rollback();
+					db_rollback();	
 				}
 			}
 		}
@@ -1222,7 +1456,7 @@
 	function updateObjInDB($myWMS){
 		$admin = new administration();
 		db_begin();
-
+		
 		$sql = "UPDATE wms SET ";
 		$sql .= "wms_version = $1 ,";
 		$sql .= "wms_getcapabilities  = $2 ,";
@@ -1238,18 +1472,18 @@
 		$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,
 			$admin->char_encode($this->wms_getcapabilities_doc),$this->wms_upload_url,$_SESSION["mb_user_id"],strtotime("now"),
 			$this->wms_supportsld,$this->wms_userlayer,$this->wms_userstyle,$this->wms_remotewfs,$myWMS);
 		$t = array('s','s','s','s','s','s','s','i','i','s','s','s','s','i');
-
+	
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			db_rollback();
+			db_rollback();	
 		}
-
+		
 		if($this->overwrite == true){
 			$sql = "UPDATE wms SET ";
 			$sql .= "wms_title  = $1 ,";
@@ -1268,7 +1502,7 @@
 			$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,
@@ -1276,33 +1510,33 @@
 			$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','i');
 			$res = db_prep_query($sql,$v,$t);
 			if(!$res){
-				db_rollback();
+				db_rollback();	
 			}
 		}
-
+		
 		# 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();
+			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();
+			db_rollback();	
 		}
 		$this->insertFormat($myWMS);
-
+		
 		# update gui_wms
 		$this->update_gui_wms($myWMS);
-
-		# update TABLE layer
+		
+		# update TABLE layer	
 		# delete all layer which are outdated
 		$v = array($myWMS);
 		$t = array('i');
@@ -1312,16 +1546,16 @@
 			if($i>0){$sql .= ',';}
 			$sql .= "$".$c;
 			array_push($v,$this->objLayer[$i]->layer_name);
-			array_push($t,'s');
+			array_push($t,'s');		
 			$c++;
 		}
 		$sql .= ")";
-
+		
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			db_rollback();
+			db_rollback();	
 		}
-
+			
 		# update or insert?
 		$sql = "SELECT layer_name FROM layer WHERE fkey_wms_id = $1";
 		$v = array($myWMS);
@@ -1331,7 +1565,7 @@
 		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');
@@ -1340,7 +1574,7 @@
 		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;
@@ -1358,7 +1592,7 @@
 			}
 		}
 		db_commit();
-		return;
+		return;	
 	}
 	function updateGuiLayer($i,$myWMS,$gui_id){
 		$sql = "SELECT layer_id FROM layer WHERE fkey_wms_id = $1 AND layer_name = $2";
@@ -1366,18 +1600,18 @@
 		$t = array('i','s');
 		$res = db_prep_query($sql,$v,$t);
 		if($row = db_fetch_array($res)){
-			$l_id = $row['layer_id'];
+			$l_id = $row['layer_id'];	
 		}
 		else{
 			db_rollback();
 			$e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name. " in gui: ".$gui_id);
-			return;
+			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);
+		$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 ";
@@ -1386,7 +1620,7 @@
 				$t = array('i','s');
 				$res1 = db_prep_query($sql1,$v,$t);
 				if(!$res1){
-
+					
 				db_rollback();
 				}
 			}
@@ -1397,7 +1631,7 @@
 				$t = array('i','s');
 				$res1 = db_prep_query($sql1,$v,$t);
 				if(!$res1){
-
+					
 					db_rollback();
 				}
 			}
@@ -1418,7 +1652,7 @@
 				$res1 = db_prep_query($sql1,$v,$t);
 				if(!$res1){db_rollback();
 				}
-			}
+			}		
 		}
 	}
 	function update_gui_wms($myWMS){
@@ -1428,14 +1662,14 @@
 		$t = array('i');
 		$res = db_prep_query($sql,$v,$t);
 		$cnt = 0;
-		while($row = db_fetch_array($res)){
+		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;
+			$paramCount = 0;		
 
 			for($i=0; $i<count($this->data_type); $i++){
 				# gui_wms_mapformat
@@ -1474,7 +1708,7 @@
 				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"])){
@@ -1501,24 +1735,24 @@
 			if($mySubmit){
 				$res = db_prep_query($sql,$v,$t);
 				if(!$res){
-					db_rollback();
+					db_rollback();	
 					echo "<pre>".$sql."</pre><br> <br><p>";
-				 	echo db_error();
+				 	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;
 	}
@@ -1526,18 +1760,18 @@
 	/**
 	* 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"];
@@ -1546,7 +1780,7 @@
 			$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');
@@ -1571,7 +1805,7 @@
 					$this->wms_getcapabilities =  $row2["wms_getcapabilities"];
 					$this->wms_getfeatureinfo = $row2["wms_getfeatureinfo"];
 					$this->wms_getlegendurl = $row2["wms_getlegendurl"];
-				}
+				}			
 				// TO DO: Capabilities document needs to 
 				// be encoded to the original encoding
 				// if different from the database encoding
@@ -1581,24 +1815,24 @@
 				$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');
+			$t = array('i'); 
 			$res_wms = db_prep_query($sql,$v,$t);
-			$count_format=0;
-			while($row3 = db_fetch_array($res_wms)){
+			$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;";
@@ -1606,9 +1840,9 @@
 		$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"];
+			$layer_id = $row["fkey_layer_id"];		
 			$sql = "Select * from layer where layer_id = $1";
 			$v = array($layer_id);
 			$t = array('i');
@@ -1619,10 +1853,10 @@
 				$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_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_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"];
@@ -1639,12 +1873,12 @@
 			$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"];
@@ -1654,7 +1888,7 @@
 				$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);
@@ -1684,7 +1918,7 @@
 		}
 	   }
 	/** end createObjfromDB **/
-
+	
 	  /**
 	* creatObjfromDBNoGui
 	*
@@ -1839,14 +2073,14 @@
 	* 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);
+		$res_count= db_num_rows($res);	  
 		$wms_id=0;
 		if($res_count>0){
 			$count=0;
@@ -1857,7 +2091,7 @@
 		}
 		return $wms_id;
 	}
-
+	
 	function displayDBInformation(){
 		echo $this->wms_getcapabilities;
 		$sql="Select * from wms where wms_getcapabilities = $1";
@@ -1878,15 +2112,15 @@
 			$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);
+	   $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>";
@@ -1894,7 +2128,7 @@
 	    	echo "gui_wms_epsg: " .  $row["gui_wms_epsg"]. " <br>";
 	      $count++;
 	   }
-
+		
 	   #db_close($connect);
 	}
 
@@ -1902,12 +2136,47 @@
 		if($this->wms_getcapabilities == '' || $this->wms_getmap == '' ){
 			echo "<br>Missing parameters: <br>";
 			$this->displayWMS();
-			echo "<br> Data not commited<br>";
+			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 {
+class layer extends wms {	
 	var $layer_id;
 	var $layer_parent;
 	var $layer_name;
@@ -1916,25 +2185,31 @@
 	var $layer_pos;
 	var $layer_queryable;
 	var $layer_minscale;
-	var $layer_maxscale;
+	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;
-
+	var $gui_layer_style = NULL;	
+	
 	function layer($id,$parent){
 		$this->layer_id = $id;
-		$this->layer_parent = $parent;
-		//var_dump($this);
+		$this->layer_parent = $parent;	
+		//var_dump($this);	
 	}
+
+	public function __toString () {
+		$e = new mb_exception("TITLE: " . $this->layer_title);
+		return $this->layer_title;
+	}
+	
 }
 ?>

Modified: branches/2.5/http/javascripts/map.js
===================================================================
--- branches/2.5/http/javascripts/map.js	2009-01-08 14:41:46 UTC (rev 3416)
+++ branches/2.5/http/javascripts/map.js	2009-01-08 14:47:47 UTC (rev 3417)
@@ -465,6 +465,45 @@
 		return true;
 	};
 	
+	/**
+	 * Sets the list of layers, styles and querylayers for a specified WMS
+	 */
+	this.restateLayers = function(wms_id){
+		for (var i = 0; i < this.wms.length; i++) {
+			if (this.wms[i].wms_id == wms_id) {
+				var currentWms = this.wms[i];
+				var cnt_layers = 0;
+				var cnt_querylayers = 0;
+				var layers = "";
+				var styles = "";
+				var querylayers = "";
+				for (var ii = 0; ii < currentWms.objLayer.length; ii++) {
+					var currentLayer = currentWms.objLayer[ii];
+					if (currentLayer.gui_layer_visible == 1 && !currentLayer.has_childs) {
+						if (cnt_layers > 0) {
+							layers += ",";
+							styles += ",";
+						}
+						layers += currentLayer.layer_name;
+						styles += "";
+						cnt_layers++;
+					}
+					if (currentLayer.gui_layer_querylayer == 1 && !currentLayer.has_childs) {
+						if (cnt_querylayers > 0) {
+							querylayers += ",";
+						}
+						querylayers += currentLayer.layer_name;
+						cnt_querylayers++;
+					}
+				}
+				this.layers[i] = layers;
+				this.querylayers[i] = querylayers;
+				this.styles[i] = styles;
+			}
+		}
+//		this.setExtent(ext.minx,ext.miny,ext.maxx,ext.maxy);
+	};
+	
 	eventAfterMapObjectConstruction.trigger();
 }
 

Modified: branches/2.5/http/javascripts/mod_initWmc.php
===================================================================
--- branches/2.5/http/javascripts/mod_initWmc.php	2009-01-08 14:41:46 UTC (rev 3416)
+++ branches/2.5/http/javascripts/mod_initWmc.php	2009-01-08 14:47:47 UTC (rev 3417)
@@ -61,43 +61,36 @@
 	
 //WMC
 if (isset($wmc_id)) {
-	if ($adm->getWmcById($wmc_id) != false) {
+	$myInitWmc = new wmc();
+	$success = $myInitWmc->createFromDb($wmc_id);
+	if ($success) {
 
-		$valid_wmcs = $adm->getWmcByOwner($user);
-		if (in_array($wmc_id, $valid_wmcs)) {
-			echo "var wmc_id = false;";
-			echo "wmc_id = '".$wmc_id."';";
-			$wmc = new wmc();
-			$wmc->createObjFromWMC_id($wmc_id);
-			$js_wmc .= $wmc->createJsObjFromWMC("", $e_target[0], $action);
+		$js_wmc = implode("", $myInitWmc->toJavaScript());
+		new mb_exception("WMC JS: " . $js_wmc);
+		
+		if (!empty($x) && !empty($y) && !empty($icon)) {
 			
-			if (!empty($x) && !empty($y) && !empty($icon)) {
-				
-				$js_kml .= "var myPoint = realToMap('".$e_target[0]."', new Point(".$x.",".$y."));\n";
+			$js_kml .= "var myPoint = realToMap('".$e_target[0]."', new Point(".$x.",".$y."));\n";
 
-				// 7 is half the width of pin.png
-				$js_kml .= "myPoint.x -= 7;";
-				// 20 is the height of pin.png
-				$js_kml .= "myPoint.y -= 20;";
+			// 7 is half the width of pin.png
+			$js_kml .= "myPoint.x -= 7;";
+			// 20 is the height of pin.png
+			$js_kml .= "myPoint.y -= 20;";
 
-				$js_kml .= "var meetingPointLogoStyle = {'position':'absolute', 'top':0, 'left':0, 'z-index':100, 'font-size':'10px'};\n"; 
-				$js_kml .= "meetingPointLogoTag = new DivTag('meeting_logo', '".$e_target[0]."', meetingPointLogoStyle);\n";
-				$js_img .= "<img id='meeting_img' border='0' src='".$icon."' title='".$alt."'>";
-				if ($url) {
-					$js_img = "<a href='".$url."' target='_blank'>" . $js_img . "</a>";
-				}
-				$js_kml .= "var meetingPointLogoText = \"" . $js_img . "\";\n";
-				$js_kml .= "meetingPointLogoTag.write(meetingPointLogoText);\n";
-				$js_kml .= "var meeting_img = window.frames['".$e_target[0]."'].document.getElementById('meeting_img');";
-				$js_kml .= "meeting_img.style.position = 'absolute';";
-				$js_kml .= "meeting_img.style.top = myPoint.y;";
-				$js_kml .= "meeting_img.style.left = myPoint.x;";
-				$js_kml .= "mb_registerPanSubElement('meeting_logo');";
+			$js_kml .= "var meetingPointLogoStyle = {'position':'absolute', 'top':0, 'left':0, 'z-index':100, 'font-size':'10px'};\n"; 
+			$js_kml .= "meetingPointLogoTag = new DivTag('meeting_logo', '".$e_target[0]."', meetingPointLogoStyle);\n";
+			$js_img .= "<img id='meeting_img' border='0' src='".$icon."' title='".$alt."'>";
+			if ($url) {
+				$js_img = "<a href='".$url."' target='_blank'>" . $js_img . "</a>";
 			}
+			$js_kml .= "var meetingPointLogoText = \"" . $js_img . "\";\n";
+			$js_kml .= "meetingPointLogoTag.write(meetingPointLogoText);\n";
+			$js_kml .= "var meeting_img = window.frames['".$e_target[0]."'].document.getElementById('meeting_img');";
+			$js_kml .= "meeting_img.style.position = 'absolute';";
+			$js_kml .= "meeting_img.style.top = myPoint.y;";
+			$js_kml .= "meeting_img.style.left = myPoint.x;";
+			$js_kml .= "mb_registerPanSubElement('meeting_logo');";
 		}
-		else {
-			$js_error .= "alert('".$adm->getUserNameByUserId($user)." is not allowed to access WMC ".$wmc_id.". Default GUI will be loaded instead.');"; 
-		}
 	}
 	else {
 		$js_error .= "alert('WMC id ".$wmc_id." is not valid. Default GUI will be loaded instead.');"; 
@@ -111,7 +104,6 @@
 
 echo "function addFlag() {";
 echo $js_kml;
-echo $js_error;
 echo "}";
 
 

Added: branches/2.5/http/javascripts/mod_loadwmc.js
===================================================================
--- branches/2.5/http/javascripts/mod_loadwmc.js	                        (rev 0)
+++ branches/2.5/http/javascripts/mod_loadwmc.js	2009-01-08 14:47:47 UTC (rev 3417)
@@ -0,0 +1,284 @@
+// checks if element var loadFromSession exists
+try {
+	if (loadFromSession) {
+	}
+}
+catch(e) {
+	loadFromSession = 0;
+}
+
+if (loadFromSession) {
+	// function load_wmc_session() is generated by mod_loadwmc.php
+	mb_registerInitFunctions('load_wmc_session()');
+}
+var wmcPopup = null;
+var wmcDisplayPopup = null;
+
+var serverSideFileName = "../php/mod_loadwmc_server.php";
+
+function mod_importWmc(id){
+	alert(id);
+}
+
+/**
+ * is called when the load WMC button is pressed
+ */
+function mod_loadwmc(){
+
+	var initialHtml = "<div>" +
+					"<h2 style='font-family: Arial, Helvetica, sans-serif; color: #808080;'><font align='left' color='#000000'>load WMC from list</font></h2>" +
+					"<table id='loadwmc_list' width='90%' style='font-family: Arial, Helvetica, sans-serif;font-size : 12px;color: #808080;' border='1' cellpadding='3' rules='rows'>" +
+						"<tr style='background-color:#F0F0F0;' width='80px'>" +
+							"<td><b>WMC name</b></td>" +
+							"<td><b>last update</b></td>" +
+							"<td colspan=5></td>" +
+						"</tr>" +
+					"</table>" +
+				"</div>";
+
+	// creates a new pop up (if it doesn't already exist)
+	// the pop up allows you to load, append, merge, 
+	// display and delete WMC documents
+	if (wmcPopup === null) {
+		wmcPopup = new mb_popup({
+			title:"Load WMC",
+			width:500,
+			height:600,
+			top:100,
+			left:100,
+			html:initialHtml
+		});
+	}
+
+	// display the pop up
+	if (!wmcPopup.isVisible()) {
+		wmcPopup.setHtml(initialHtml);
+		wmcPopup.show();
+		
+	}
+
+	// get WMC data from server
+	var queryObj = {command:"getWmc"};
+	$.post(serverSideFileName, {queryObj:$.toJSON(queryObj)}, function(json, status) {
+		var loadWmcDataError = false;
+		if (json && status == "success") {
+			loadWmcDataError = displayWmcList(json, status);
+		}
+		if (loadWmcDataError) {
+			alert("An error has occured. WMC list could not be loaded.");
+		}
+	});
+}
+
+/**
+ * Displays available WMC documents
+ */
+function displayWmcList (json, status) {
+	var wmcObj = eval("(" + json + ")");
+
+	//
+	// for each wmc, add a row to the table
+	//
+	for (var i=0; i < wmcObj.wmc.length; i++) {
+		(function () {
+			var currentId = wmcObj.wmc[i].id;
+			var $tr = $("<tr onmouseover='this.style.backgroundColor = \"#F08080\"' onmouseout='this.style.backgroundColor = \"#ffffff\"'></tr>").appendTo($("#loadwmc_list"));
+			$tr.hide();
+			var $td;
+			
+			$tr.append($("<td>" + wmcObj.wmc[i].title + "</td>"));
+			$tr.append($("<td>" + wmcObj.wmc[i].timestamp + "</td>"));
+
+			// 
+			// Load WMC
+			//
+			$loadWmc = $("<img src='../img/button_gray/wmc_load.png' title='load this WMC'>");
+			$loadWmc.click(function() {
+				var queryObj = {command:"loadWmc", parameters:{id:currentId}};
+				$.post(serverSideFileName, {queryObj: $.toJSON(queryObj)}, function (json, status) {
+					var loadWmcError = false;
+					if (json && status == "success") {
+						var resultObj = eval("(" + json + ")");
+						try {
+							if (resultObj.javascript && typeof(resultObj.javascript) == "object") {
+								for (var j=0; j < resultObj.javascript.length; j++) {
+//									console.log("Statement: %s", resultObj.javascript[j]);
+									eval(resultObj.javascript[j]);
+								}
+							}	
+						}
+						catch (e) {
+							alert(e);
+							loadWmcError = true;
+						}
+					}
+					if (loadWmcError) {
+						alert("An error has occured while loading this WMC.");
+					}
+					else {
+						// close the Pop up
+						if (wmcDisplayPopup !== null && wmcDisplayPopup.isVisible()) {
+							wmcDisplayPopup.hide();
+						}
+						wmcPopup.hide();
+						alert("WMC has been loaded successfully.");
+					}
+				});
+			});
+			$td = $("<td></td>").append($loadWmc);
+			$tr.append($td);				
+
+			// 
+			// Merge WMC
+			//
+			$mergeWmc = $("<img src='../img/button_gray/wmc_merge.png' title='merge WMC'>");
+			$mergeWmc.click(function() {
+				var	extensionDataString = null;
+				if (currentWmcExtensionData !== null) {
+					extensionDataString = currentWmcExtensionData;
+				}
+				var queryObj = {
+					command:"mergeWmc", 
+					parameters:{
+						id:currentId, 
+						extensionData:extensionDataString, 
+						mapObject:mb_mapObj,
+						generalTitle:"currentState"
+					}
+				};
+				$.post(serverSideFileName, {queryObj: $.toJSON(queryObj)}, function (json, status) {
+					var loadWmcError = false;
+					if (json && status == "success") {
+						var resultObj = eval("(" + json + ")");
+						try {
+							if (resultObj.javascript && typeof(resultObj.javascript) == "object") {
+								for (var j=0; j < resultObj.javascript.length; j++) {
+									eval(resultObj.javascript[j]);
+								}
+							}	
+						}
+						catch (e) {
+							alert(e);
+							loadWmcError = true;
+						}
+					}
+					if (loadWmcError) {
+						alert("An error has occured while loading this WMC.");
+					}
+					else {
+						// close the Pop up
+						if (wmcDisplayPopup !== null && wmcDisplayPopup.isVisible()) {
+							wmcDisplayPopup.hide();
+						}
+						wmcPopup.hide();
+						alert("WMC has been loaded successfully.");
+					}
+				});
+			});
+			$td = $("<td></td>").append($mergeWmc);
+			$tr.append($td);				
+
+			// 
+			// Append WMC
+			//
+			$appendWmc = $("<img src='../img/button_gray/wmc_append.png' title='append WMC'>");
+			$appendWmc.click(function() {
+				var	extensionDataString = null;
+				if (currentWmcExtensionData !== null) {
+					extensionDataString = currentWmcExtensionData;
+				}
+				var queryObj = {
+					command:"appendWmc", 
+					parameters:{
+						id:currentId, 
+						extensionData:extensionDataString, 
+						mapObject:mb_mapObj,
+						generalTitle:"currentState"
+					}
+				};
+				$.post(serverSideFileName, {queryObj: $.toJSON(queryObj)}, function (json, status) {
+					var loadWmcError = false;
+					if (json && status == "success") {
+						var resultObj = eval("(" + json + ")");
+						try {
+							if (resultObj.javascript && typeof(resultObj.javascript) == "object") {
+								for (var j=0; j < resultObj.javascript.length; j++) {
+									eval(resultObj.javascript[j]);
+								}
+							}	
+						}
+						catch (e) {
+							alert(e);
+							loadWmcError = true;
+						}
+					}
+					if (loadWmcError) {
+						alert("An error has occured while loading this WMC.");
+					}
+					else {
+						// close the Pop up
+						if (wmcDisplayPopup !== null && wmcDisplayPopup.isVisible()) {
+							wmcDisplayPopup.hide();
+						}
+						wmcPopup.hide();
+						alert("WMC has been loaded successfully.");
+					}
+				});
+			});
+			$td = $("<td></td>").append($appendWmc);
+			$tr.append($td);				
+
+			// 
+			// Display WMC
+			//
+			$displayWmc = $("<img src='../img/button_gray/wmc_xml.png' title='display WMC XML'>");
+			$displayWmc.click(function() {
+				// create Popup
+				if (wmcDisplayPopup === null) {
+					wmcDisplayPopup = new mb_popup({
+						title:"WMC Document",
+						width:600,
+						height:500,
+						top:100,
+						left:300,
+						url:"../javascripts/mod_displayWmc.php?wmc_id=" + currentId
+					});
+				}
+				// set correct URL
+				if (wmcDisplayPopup.isVisible()) {
+					wmcDisplayPopup.setUrl("../javascripts/mod_displayWmc.php?wmc_id=" + currentId);
+				}
+				// display the pop up
+				wmcDisplayPopup.show();
+			});
+			$td = $("<td></td>").append($displayWmc);
+			$tr.append($td);				
+
+			$deleteWmc = $("<img src='../img/button_gray/del.png' title='delete this WMC'>");
+			$deleteWmc.click(function() {
+				var queryObj = {command:"deleteWmc", parameters:{id:currentId}};
+				$.post(serverSideFileName, {queryObj: $.toJSON(queryObj)}, function (json, status) {
+					var deleteWmcError = false;
+					if (json && status == "success") {
+						var resultObj = eval("(" + json + ")");
+						try {
+							if (resultObj.success) {
+								$tr.remove();
+							}	
+						}
+						catch (e) {
+							deleteWmcError = true;
+						}
+					}
+					if (deleteWmcError) {
+						alert("An error has occured while deleting this WMC.");
+					}
+				});
+			});
+			$td = $("<td></td>").append($deleteWmc);
+			$tr.append($td);
+
+			$tr.fadeIn("slow");
+		}());
+	}
+}

Modified: branches/2.5/http/javascripts/mod_loadwmc.php
===================================================================
--- branches/2.5/http/javascripts/mod_loadwmc.php	2009-01-08 14:41:46 UTC (rev 3416)
+++ branches/2.5/http/javascripts/mod_loadwmc.php	2009-01-08 14:47:47 UTC (rev 3417)
@@ -22,77 +22,77 @@
 
 include(dirname(__FILE__) . "/../include/dyn_js.php");
 
-echo "mod_loadwmc_target = '".$e_target[0]."';";
+function createJs ($mergeWms) {
+	$jsString = "";
+	$wmc = new wmc();
+	if (!isset($_SESSION['mb_wmc'])) {
+		$e = new mb_notice("wmc not set, generating from app: " . $_SESSION["mb_user_gui"]);
+		$wmc->createFromApplication($_SESSION["mb_user_gui"]);		
+		$_SESSION["mb_wmc"] = $wmc->toXml();
+//		$e = new mb_exception("initial WMC: " . $_SESSION["mb_wmc"]);
+	}
 
-/*
-// this may be added at a later stage
-if ($new_wmc == 1) {
-	include(dirname(__FILE__) . "/../generate_defaultWmc.php");
-	$startup = true;
-	$e = new mb_notice("loadwmc: new wmc");
-}
-else {
-	$startup = false;
-	$e = new mb_notice("loadwmc: old wmc");
-}
-if ($gui_changed == 0) {
-	if ($_REQUEST['portal_services']) {
-		$e = new mb_notice("loadwmc: merging layers");
-		include(dirname(__FILE__) . "/../merge_layers.php");
-	}
-	if ($_SESSION['GML']) {
-		$e = new mb_notice("loadwmc: merging bbox");
-		include(dirname(__FILE__) . "/../merge_bbox.php");
-	}
-}
-*/
-?>
-function load_wmc_session() {
-	<?php
-		if (isset($_SESSION['mb_wmc'])) {
-			$wmc = new wmc();
-			if ($wmc->createObjFromWMC_xml($_SESSION['mb_wmc'])) {
-				$js = "";
-				if ($_SESSION['layer_preview']) {
-//					echo "var e = new Mb_notice('mod_loadwmc: load_wmc_session: layer preview');";
-					$js = $wmc->createJsObjFromWMC("", $e_target, "load");
+	if (isset($_SESSION['mb_wmc'])) {
+		$e = new mb_exception("merging with WMC.");
+
+		if ($wmc->createFromXml($_SESSION['mb_wmc'])) {
+	
+			if ($mergeWms) {
+				$wmsArray = array();
+				for ($i = 0; $i < count($_SESSION["wms"]); $i++) {
+					$currentWms = new wms();
+					$currentWms->createObjFromXML($_SESSION["wms"][$i]);
+					array_push($wmsArray, $currentWms);
 				}
-				else if ($startup == true) {
-//					echo "var e = new Mb_notice('mod_loadwmc: load_wmc_session: load new wmc');";
-					$js = $wmc->createJsObjFromWMC("", $e_target, "merge");
-					$startup = false;
-				}		
-				else {
-//					echo "var e = new Mb_notice('mod_loadwmc: load_wmc_session: load old wmc');";
-					$js = $wmc->createJsObjFromWMC("", $e_target, "load");
-				}
-				echo $js;
+				$wmc->mergeWmsArray($wmsArray);
+				$_SESSION["command"] = "";
+				$_SESSION["wms"] = array();
 			}
-			else {
-				echo "var e = new Mb_notice('mod_loadwmc: load_wmc_session: error parsing wmc');";
-			}
+	
+			$javaScriptArray = array();
+			$javaScriptArray = $wmc->toJavaScript();
+
+			$jsString .= implode("", $javaScriptArray);
 		}
 		else {
-			echo "var e = new Mb_warning('mod_loadwmc: load_wmc_session: no wmc set!');";
+			$jsString .= "var e = new Mb_notice('mod_loadwmc: load_wmc_session: error parsing wmc');";
 		}
-	?>
+	}
+	else {
+		$e = new mb_notice("not merging WMC");
+		$jsString .= "var e = new Mb_warning('mod_loadwmc: load_wmc_session: no wmc set!');";
+	}
+	return $jsString;
 }
 
-try {if (loadFromSession) {}}catch(e) {loadFromSession = 0;}
+//
+// Creates the function load_wmc_session.
+// This function loads a WMC from the session, if the element var
+// "loadFromSession" is set to true.
+//
+?>
+function load_wmc_session() {
+<?php
+if ($_SESSION["command"] && $_SESSION["command"] == "ADDWMS") {
+	$e = new mb_notice("merging with WMS in Session...");
+	echo createJs(true);
+}
+else {
+	$e = new mb_notice("NOT merging with WMS in Session...");
+	echo createJs(false);
+}
+?>
+}
 
-if (loadFromSession) {
-	mb_registerInitFunctions('load_wmc_session()');
+<?php 
+if ($e_src) {
+	sprintf("var mod_loadwmc_img = new Image(); 
+			mod_loadwmc_img.src = '%s'", $e_src);
+	
 }
 
-var mod_loadwmc_img = new Image(); mod_loadwmc_img.src = "<?php echo $e_src; ?>";
-//var mod_loadwmc_img_over = new Image(); mod_loadwmc_img_over.src = "<?php  echo preg_replace("/_off/","_over",$e_src);  ?>";
-
-function mod_importWmc(id){
-	alert(id);
-}
-function mod_loadwmc(obj){
-	windowWmc = window.open("../php/mb_listWMCs.php?<?php echo SID;?>","displayWmc","width=500, height=600, scrollbars=yes, dependent=yes");
-}
-function mod_loadwmc_init(obj){
-	//document.getElementById("loadwmc").src = mod_zoom1_img_over.src;
-}
\ No newline at end of file
+//
+// Creates a pop up with a dialogue to load, view or delete WMC documents
+//
+include("mod_loadwmc.js");
+?>
\ No newline at end of file

Added: branches/2.5/http/javascripts/mod_loadwmc_list.php
===================================================================
--- branches/2.5/http/javascripts/mod_loadwmc_list.php	                        (rev 0)
+++ branches/2.5/http/javascripts/mod_loadwmc_list.php	2009-01-08 14:47:47 UTC (rev 3417)
@@ -0,0 +1,3 @@
+<?php
+	echo "fisch";
+?>
\ No newline at end of file

Modified: branches/2.5/http/javascripts/mod_savewmc.php
===================================================================
--- branches/2.5/http/javascripts/mod_savewmc.php	2009-01-08 14:41:46 UTC (rev 3416)
+++ branches/2.5/http/javascripts/mod_savewmc.php	2009-01-08 14:47:47 UTC (rev 3417)
@@ -24,7 +24,9 @@
 ?>
 function setOnUnload() {
 	if (ie) {
-		document.getElementsByTagName('body')[0].onunload = function() {var x = new Function ("", "mod_savewmc_session()"); x(); };
+		document.getElementsByTagName('body')[0].onunload = function() {
+			var x = new Function ("", "mod_savewmc_session()"); x(); 
+		};
 	}
 	else {
 		document.getElementsByTagName('body')[0].setAttribute("onUnload", "mod_savewmc_session();");
@@ -34,11 +36,18 @@
 try {if (saveInSession) {}}catch(e) {saveInSession = 0;}
 
 if (saveInSession == 1) {
-	mb_registerInitFunctions('setOnUnload()');
+	eventAfterMapRequest.register(function () {
+		mod_savewmc_session();
+	});
+//	mb_registerInitFunctions('setOnUnload()');
 }
 
-var mod_savewmc_img = new Image(); 
-mod_savewmc_img.src = "<?php  echo $e_src;  ?>";
+<?php 
+if ($e_src) {
+	sprintf("var mod_savewmc_img = new Image(); 
+			mod_savewmc_img.src = '%s';", $e_src);
+}
+?>
 //var mod_savewmc_img_over = new Image(); mod_savewmc_img_over.src = "<?php  echo preg_replace("/_off/","_over",$e_src);  ?>";
 
 function mod_savewmc_session(){
@@ -62,7 +71,12 @@
 	}
 
 	if (storeInSession) {
-		$.ajaxSetup({async:false}); //TODO: find out why async doesn't work onunload
+		$.ajaxSetup({async:false}); 
 	}
-	$.post("../php/mod_insertWmcIntoDb.php", {"saveInSession":storeInSession, "generalTitle":generalTitle, "extensionData":extensionDataString, "mapObject":$.toJSON(mb_mapObj[ind])}, callbackFunction);
-}
\ No newline at end of file
+	$.post("../php/mod_savewmc_server.php", {
+		"saveInSession":storeInSession, 
+		"generalTitle":generalTitle, 
+		"extensionData":extensionDataString, 
+		"mapObject":$.toJSON(mb_mapObj)
+	}, callbackFunction);
+}

Added: branches/2.5/http/php/mod_loadwmc_server.php
===================================================================
--- branches/2.5/http/php/mod_loadwmc_server.php	                        (rev 0)
+++ branches/2.5/http/php/mod_loadwmc_server.php	2009-01-08 14:47:47 UTC (rev 3417)
@@ -0,0 +1,174 @@
+<?php
+require_once(dirname(__FILE__) . "/../php/mb_validateSession.php");
+require_once(dirname(__FILE__) . "/../classes/class_user.php");
+require_once(dirname(__FILE__) . "/../classes/class_wmc.php");
+require_once(dirname(__FILE__) . "/../classes/class_json.php");
+
+/**
+ * encodes and delivers the data
+ * 
+ * @param object the un-encoded object 
+ */
+function sendOutput($out){
+	global $json;
+	$output = $json->encode($out);
+	header("Content-Type: text/x-json");
+	echo $output;
+}
+
+/**
+ * Get all available WMC documents from the database
+ * 
+ * @return mixed[] an array of wmcs 
+ * 					(wmc = assoc. array of "id", "title", "timestamp")
+ */
+function getWmc(){
+	global $con;
+	global $userId;
+	
+	$wmcArray = array();
+	
+	// get WMC ids 
+	$currentUser = new User($userId);
+	$wmcIdArray = $currentUser->getWmcByOwner();
+	
+	// get WMC data
+	$v = array();
+	$t = array();
+	$wmcIdList = "";
+
+	for ($i = 0; $i < count($wmcIdArray); $i++) {
+		if ($i > 0) { 
+			$wmcIdList .= ",";
+		}
+		$wmcIdList .= "$".($i+1);
+		array_push($v, $wmcIdArray[$i]);
+		array_push($t, 's');
+	}
+
+	$sql = "SELECT DISTINCT wmc_id, wmc_title, wmc_timestamp " . 
+		"FROM mb_user_wmc WHERE wmc_id IN (" . $wmcIdList . ") " .
+		"ORDER BY wmc_timestamp DESC";
+	
+	$res = db_prep_query($sql, $v, $t);
+	while($row = db_fetch_array($res)){
+		$currentResult = array();
+		$currentResult["id"] = $row["wmc_id"];
+		$currentResult["title"] = $row["wmc_title"];
+		$currentResult["timestamp"] = date("M d Y H:i:s", $row["wmc_timestamp"]); 
+		array_push($wmcArray, $currentResult);
+	}
+	return $wmcArray;
+}
+
+$json = new Mapbender_JSON();
+$queryObj = $json->decode(stripslashes($_REQUEST['queryObj']));
+$resultObj = array();
+
+$e = new mb_exception("command: " . $queryObj->command);
+
+$wmc = new wmc();
+$userId = $_SESSION[mb_user_id];
+
+switch($queryObj->command){
+
+	// gets available WMCs
+	case 'getWmc':
+		$resultObj["wmc"] = getWmc();
+	break;
+
+	// gets XML document of a WMC
+	case 'getWmcDocument':
+		$wmcId = $queryObj->parameters->id;
+		$doc = $wmc->getDocument($wmcId);
+		if (!$doc) {
+			$resultObj["error"] = "The WMC document could not be found.";
+		}
+		else {
+			$resultObj["wmc"] = array("document" => $doc);
+		}
+	break;
+
+	// deletes a WMC
+	case 'deleteWmc':
+		$wmcId = $queryObj->parameters->id;
+		if ($wmc->delete($wmcId)) {
+			$resultObj["success"] = "WMC has been deleted from the database.";
+		}
+		else {
+			$resultObj["error"] = "WMC could not be deleted.";
+		}
+	break;
+	
+	// loads a WMC (returns array of JS code)
+	case 'loadWmc':
+		$wmcId = $queryObj->parameters->id;
+		$wmc->createFromDb($wmcId);
+		$jsArray = $wmc->toJavaScript();
+		if ($jsArray) {
+			$resultObj["javascript"] = $jsArray;
+		}
+		else {
+			$resultObj["error"] = "WMC could not be loaded.";
+		}
+	break;
+
+	// merges data with WMC and loads it (returns array of JS code)
+	case 'mergeWmc':
+		$params = $queryObj->parameters;
+		
+		// generate a WMC for the current client state
+		$currentWmc = new wmc();
+		$currentWmc->createFromJs($params->mapObject, $params->generalTitle, $params->extensionData);
+
+		// get the desired WMC from the database
+		$wmcId = $queryObj->parameters->id;
+		$wmcXml = wmc::getDocument($wmcId);
+
+		// merge the two WMCs
+		$currentWmc->merge($wmcXml);
+		
+		// load the merged WMC
+		$jsArray = $currentWmc->toJavaScript();
+
+		if (is_array($jsArray) && count($jsArray) > 0) {
+			$resultObj["javascript"] = $jsArray;
+		}
+		else {
+			$resultObj["error"] = "WMC could not be loaded.";
+		}
+	break;
+	
+	// appends a WMC (returns JS code)
+	case 'appendWmc':
+		$params = $queryObj->parameters;
+		// generate a WMC for the current client state
+		$currentWmc = new wmc();
+		$currentWmc->createFromJs($params->mapObject, $params->generalTitle, $params->extensionData);
+
+		// get the desired WMC from the database
+		$wmcId = $queryObj->parameters->id;
+		$wmcXml = wmc::getDocument($wmcId);
+
+		// merge the two WMCs
+		$currentWmc->append($wmcXml);
+		
+		// load the merged WMC
+		$jsArray = $currentWmc->toJavaScript();
+
+		if (is_array($jsArray) && count($jsArray) > 0) {
+			$resultObj["javascript"] = $jsArray;
+		}
+		else {
+			$resultObj["error"] = "WMC could not be appended.";
+		}
+	break;
+	
+
+	// Invalid command
+	default:
+		$resultObj["error"] = "no action specified...";
+}
+
+sendOutput($resultObj);
+?>
\ No newline at end of file

Modified: branches/2.5/http/php/mod_mapOV.php
===================================================================
--- branches/2.5/http/php/mod_mapOV.php	2009-01-08 14:41:46 UTC (rev 3416)
+++ branches/2.5/http/php/mod_mapOV.php	2009-01-08 14:47:47 UTC (rev 3417)
@@ -73,7 +73,7 @@
 		
 		var ind = parent.getMapObjIndexByName('overview');
 		var ov_extent = parent.mb_mapObj[ind].getExtentInfos();
-		parent.mb_setWmcExtensionData({"ov_minx":ov_extent.minx,"ov_miny":ov_extent.miny,"ov_maxx":ov_extent.maxx,"ov_maxy":ov_extent.maxy});
+		parent.mb_mapObj[ind].isOverview = true;
 	});
 }
 function mod_ov_setHandler(e){

Added: branches/2.5/http/php/mod_savewmc_server.php
===================================================================
--- branches/2.5/http/php/mod_savewmc_server.php	                        (rev 0)
+++ branches/2.5/http/php/mod_savewmc_server.php	2009-01-08 14:47:47 UTC (rev 3417)
@@ -0,0 +1,50 @@
+<?php
+#$Id: mod_insertWmcIntoDb.php 1198 2007-10-18 14:37:52Z baudson $
+#$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_insertWmcIntoDb.php,v 1.19 2006/03/09 14:02:42 uli_rothstein Exp $
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+require_once(dirname(__FILE__)."/../classes/class_wmc.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+
+$json = new Mapbender_JSON();
+
+// get data from POST and SESSION
+$mapObject = $json->decode(stripslashes($_POST["mapObject"]));
+$userId = $_SESSION["mb_user_id"];
+$saveInSession = $_POST["saveInSession"];
+$generalTitle = $_POST["generalTitle"];
+$extensionData = $json->decode(stripslashes($_POST["extensionData"]));
+
+// create WMC object
+$wmc = new wmc();
+$wmc->createFromJs($mapObject, $generalTitle, $extensionData);
+
+if ($saveInSession === 1) {
+	// store XML in session
+	$_SESSION["mb_wmc"] = $wmc->xml;
+	$_SESSION["epsg"] = $mapObject->epsg;
+	$_SESSION["previous_gui"] = $_SESSION["mb_user_gui"];
+	$e = new mb_notice("mod_insertWMCIntoDB: save WMC in session succeeded.");
+}
+else {
+	// insert WMC into database
+	$result = $wmc->insert();
+	echo $result["message"];
+}
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list