[Mapbender-commits] r2451 - in branches/beck_dev/mapbender/http: classes javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri May 9 12:00:36 EDT 2008


Author: christoph
Date: 2008-05-09 12:00:35 -0400 (Fri, 09 May 2008)
New Revision: 2451

Added:
   branches/beck_dev/mapbender/http/classes/class_map.php
   branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js
   branches/beck_dev/mapbender/http/javascripts/mod_loadwmc_list.php
   branches/beck_dev/mapbender/http/php/mod_loadwmc_server.php
Modified:
   branches/beck_dev/mapbender/http/classes/class_administration.php
   branches/beck_dev/mapbender/http/classes/class_user.php
   branches/beck_dev/mapbender/http/classes/class_wmc.php
   branches/beck_dev/mapbender/http/javascripts/map.js
   branches/beck_dev/mapbender/http/javascripts/mod_displayWmc.php
   branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.php
   branches/beck_dev/mapbender/http/javascripts/mod_savewmc.php
   branches/beck_dev/mapbender/http/javascripts/popup.js
   branches/beck_dev/mapbender/http/php/mod_map1.php
   branches/beck_dev/mapbender/http/php/mod_mapOV.php
Log:
wmc without iframes and popups

Modified: branches/beck_dev/mapbender/http/classes/class_administration.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_administration.php	2008-05-08 11:19:00 UTC (rev 2450)
+++ branches/beck_dev/mapbender/http/classes/class_administration.php	2008-05-09 16:00:35 UTC (rev 2451)
@@ -346,19 +346,13 @@
      * @param	string		the wmc_id
      * @return	boolean		Did the query run succesfull? This does not necessarily mean that 
      * 						an entry was deleted.
+     * @deprecated
      */
  	function deleteWmc($wmc_id, $user_id){
-		$sql = "DELETE FROM mb_user_wmc ";
-		$sql .= "WHERE fkey_user_id = $1 AND wmc_id = $2";
-		$v = array($user_id,$wmc_id);
-		$t = array('i','s');
-		$res = db_prep_query($sql,$v,$t);
-		if ($res) {
-			return true;
-		}
-		else {
-			return false;
-		}
+		$e = new mb_notice("administration->deleteWmc is deprecated, use wmc->delete instead!"); 
+		
+		$wmc = new wmc();
+		return $wmc->delete($wmc_id, $user_id);
  	}
 
     /**
@@ -517,19 +511,13 @@
      *
      * @param integer			the wms id
      * @return string|boolean	either the wmc as string or false when none exists
+     * @deprecated
      */
 	function getWmcById($id){
-		$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1 ";
-		$v = array($id);
-		$t = array('s');
-		$res = db_prep_query($sql,$v,$t);
-		$row = db_fetch_array($res);
-		if ($row) {
-			return $row["wmc"];
-		}
-		else {
-			return false;
-		}
+		$e = new mb_notice("administration->getWmcById is deprecated, use wmc->getDocument instead!"); 
+
+		$wmc = new wmc();
+		return $wmc->getDocument($id);
 	}
 
     /**
@@ -618,19 +606,14 @@
 		return $arrayGuis;
  	}
 
+	/**
+	 * @deprecated
+	 */
  	function getWmcByOwner($user_id){
-		$sql_wmc = "SELECT wmc_id FROM mb_user_wmc ";
-		$sql_wmc .= "WHERE fkey_user_id = $1 GROUP BY wmc_id";
-		$v = array($user_id);
-		$t = array('i');
-		$res_wmc = db_prep_query($sql_wmc,$v,$t);
-  		$count_g = 0;
-  		$arrayWmc = array();
-		while($row = db_fetch_array($res_wmc)){
-			$arrayWmc[$count_g] = $row["wmc_id"];
-			$count_g++;
-		}
-		return $arrayWmc;
+		$e = new mb_notice("administration->getWmcByOwner is deprecated, use user->getWmcByOwner instead!"); 
+
+		$user = new User($user_id);
+		return $user->getWmcByOwner();
  	}
 
 	/**

Added: branches/beck_dev/mapbender/http/classes/class_map.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_map.php	                        (rev 0)
+++ branches/beck_dev/mapbender/http/classes/class_map.php	2008-05-09 16:00:35 UTC (rev 2451)
@@ -0,0 +1,149 @@
+<?php
+ini_set("display_errors","on");
+
+/**
+ * Representing a map object, identical to the JS object in javascripts/map.js
+ * @class
+ */
+class Map {
+
+	var $width;
+	var $height;
+	var $frameName;
+	var $elementName = "maps";
+	var $layers = array();
+	var $querylayers = array();
+	var $styles = array();
+	var $geom = "";
+	var $gml = "";
+	var $wms = array();
+	var $epsg;
+	var $extent;
+	var $mapURL = array();
+	
+	/**
+	 * @constructor
+	 * @param
+	 */
+	function __construct() {
+	}
+	
+	
+	/**
+	 * @param $value Integer
+	 */
+	public function setWidth ($value) {
+		$this->width = $value;
+	}
+
+	/**
+	 * @param $value Integer
+	 */
+	public function setHeight ($value) {
+		$this->height = $value;
+	}
+
+	/**
+	 * @param $value String
+	 */
+	public function setFrameName ($value) {
+		$this->frameName = $value;
+	}
+
+	/**
+	 * @param $value String
+	 */
+	public function setEpsg ($value) {
+		$this->epsg = $value;
+	}
+
+	/**
+	 * @param $value String
+	 */
+	public function setExtent ($value) {
+		$this->extent = $value;
+	}
+
+	/**
+	 * @param $value Object
+	 */
+	public function pushWms ($value) {
+		array_push($this->wms, $value);
+	}	
+
+	/**
+	 * @param $value Object
+	 */
+	public function pushMapUrl ($value) {
+		array_push($this->mapURL, $value);
+	}	
+
+	/**
+	 * @param $value Object
+	 */
+	public function pushWms ($value) {
+		array_push($this->wms, $value);
+	}	
+
+	/**
+	 * @param $value Object
+	 */
+	public function pushLayer ($value) {
+		array_push($this->layers, $value);
+	}	
+
+	/**
+	 * @param $value Object
+	 */
+	public function pushQueryLayer ($value) {
+		array_push($this->querylayers, $value);
+	}	
+
+	/**
+	 * @param $value Object
+	 */
+	public function pushStyle ($value) {
+		array_push($this->styles, $value);
+	}	
+	/**
+	 * @destructor
+	 * @param
+	 */
+	function __destruct() {
+	}
+
+}
+
+/**
+ * A JSON output class for Map
+ * 
+ * @class
+ */
+class Map2JSON extends Map {
+
+	var $json;
+	
+	/**
+	 * @param
+	 */
+	function __toString() {
+		$this->encodeJSON();
+		
+		return (string)$this->json;
+	}
+	
+	/**
+	 *@param
+	 */
+	function encodeJSON() {
+		$this->json = json_encode(get_object_vars($this));
+	}
+	
+	/**
+	 *@param
+	 */
+	function getJSON() {
+		return $this->json;
+	}
+}
+?>
\ No newline at end of file

Modified: branches/beck_dev/mapbender/http/classes/class_user.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_user.php	2008-05-08 11:19:00 UTC (rev 2450)
+++ branches/beck_dev/mapbender/http/classes/class_user.php	2008-05-09 16:00:35 UTC (rev 2451)
@@ -129,5 +129,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/beck_dev/mapbender/http/classes/class_wmc.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_wmc.php	2008-05-08 11:19:00 UTC (rev 2450)
+++ branches/beck_dev/mapbender/http/classes/class_wmc.php	2008-05-09 16:00:35 UTC (rev 2451)
@@ -138,610 +138,680 @@
   */
 	var $monitoringIsOn = false;
   		
-function wmc() {
-} 
-
-/**
- * Saves the current WMC in the log folder.
- * 
- * @return string the filename of the WMC document.
- */
-function saveAsFile() {
-	$filename = "wmc_" . date("Y_m_d_H_i_s") . ".log";
-	$logfile = "../../log/" . $filename;
+	function wmc() {
+	} 
 	
-	if($h = fopen($logfile,"a")){
-		$content = $this->xml;
-		if(!fwrite($h,$content)){
-			$e = new mb_exception("class_wmc.php: failed to write wmc.");
+	/**
+	 * 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?
+	 */
+	function delete ($wmcId, $userId) {
+		if ($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;
+		}
+		else {
 			return false;
 		}
-		fclose($h);
 	}
-	return $filename;
-}
+	
+	/**
+	 * Returns a WMC document
+	 * @return String|boolean The document if it exists; else false
+	 * @param $id String the WMC id
+	 */
+	function getDocument ($id) {
+		$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1 ";
+		$v = array($id);
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
+		$row = db_fetch_array($res);
+		if ($row) {
+			return $row["wmc"];
+		}
+		else {
+			return false;
+		}
+	}
 
-/**
- * @return string the title of the WMC.
- */
-function getTitle() {
-	return $this->wmc_title;
-}
-
-/**
- * @return Integer the number of (unique?) WMS contained in this WMC.
- */
-function getNumberOfWms () {
-	return $this->wmc_wms_count;
-}
-
-/**
- * Creates a WMC object from a JS map object {@see map.js}
- * 
- * @param object $mapObject a map object
- * @param integer $user_id the ID of the current user
- * @param string $generalTitle the desired title of the WMC
- * @param object $extensionData data exclusive to Mapbender, which will be 
- * 								mapped into the extension part of the WMC
- */
-function createWMCFromObj($mapObject, $user_id, $generalTitle, $extensionData) {
-	$this->wmc_id = $user_id . '_' . time();
+	/**
+	 * 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;
+		
+		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);
+		}
+		return $filename;
+	}
 	
-	$generalWidth = $mapObject->width;
-	$generalHeight = $mapObject->height;
-	$generalBboxSrs = $mapObject->epsg;
+	/**
+	 * @return string the title of the WMC.
+	 */
+	function getTitle() {
+		return $this->wmc_title;
+	}
 	
-	$arrayBBox = explode(",", $mapObject->extent);
-	$generalBboxMinx = floatval($arrayBBox[0]);
-	$generalBboxMiny = floatval($arrayBBox[1]);
-	$generalBboxMaxx = floatval($arrayBBox[2]);
-	$generalBboxMaxy = floatval($arrayBBox[3]);
+	/**
+	 * @return Integer the number of (unique?) WMS contained in this WMC.
+	 */
+	function getNumberOfWms () {
+		return $this->wmc_wms_count;
+	}
 	
-	$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";
+	/**
+	 * 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) {
 	
-	// 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 = "";		
+		$extension_namespace = "mapbender";
+		
+		// 
+		// STEP 1/2: GENERATE THE GENERAL TAG
+		// 
 	
-	// generate XML
-	$doc = new DOMDocument("1.0", CHARSET);
-	$doc->preserveWhiteSpace = false;
+		$this->wmc_id = $user_id . '_' . time();
+		$generalWidth = 0; // set below
+		$generalHeight = 0; // set below
+		$generalBboxSrs = 0; // set below
+		$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 = "";
+		
+		if (count($mapObject) > 2) {
+			$e = new mb_exception("Save WMC only works for two concurrent map frames (overview plus main) at the moment.");
+		}
+		
+		// get the width, height, epsg and bbox of the overview and the main map
+		for ($i = 0; $i < count($mapObject); $i++) {
+			if (!isset($mapObject[$i]->isOverview)) {
+				$generalWidth = $mapObject[$i]->width;
+				$generalHeight = $mapObject[$i]->height;
+				$generalBboxSrs = $mapObject[$i]->epsg;
 	
-	// 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);
+				$arrayBBox = explode(",", $mapObject[$i]->extent);
+				$generalBboxMinx = floatval($arrayBBox[0]);
+				$generalBboxMiny = floatval($arrayBBox[1]);
+				$generalBboxMaxx = floatval($arrayBBox[2]);
+				$generalBboxMaxy = floatval($arrayBBox[3]);
 			}
-			$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);
-			}
-			$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);
+			else {
+				$extensionData->ov_width = $mapObject[$i]->width;
+				$extensionData->ov_height = $mapObject[$i]->height;
 	
-				$e_general->appendChild($e_logo_url);
+				$arrayBBox = explode(",", $mapObject[$i]->extent);
+				$extensionData->ov_minx = floatval($arrayBBox[0]);
+				$extensionData->ov_miny = floatval($arrayBBox[1]);
+				$extensionData->ov_maxx = floatval($arrayBBox[2]);
+				$extensionData->ov_maxy = floatval($arrayBBox[3]);
 			}
+		}
 				
-			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);
-			}
-			
-			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);
+		// 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 ($generalContactPosition){
-					$e_contact_position = $doc->createElement("ContactPosition", $generalContactPosition);
-					$e_contact->appendChild($e_contact_position);
+				$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);
 				}
-			
-				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);
+				$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);
+		
+					$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);
+				}
+				
+				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 ($generalContactAddress){
-						$e_address = $doc->createElement("Address", $generalContactAddress);
-						$e_contact_address->appendChild($e_address);
+				
+					if ($generalContactPosition){
+						$e_contact_position = $doc->createElement("ContactPosition", $generalContactPosition);
+						$e_contact->appendChild($e_contact_position);
 					}
-					if ($generalContactCity){
-						$e_city = $doc->createElement("City", $generalContactCity);
-						$e_contact_address->appendChild($e_city);
+				
+					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 ($generalContactStateOrProvince){
-						$e_state = $doc->createElement("StateOrProvince", $generalContactStateOrProvince);
-						$e_contact_address->appendChild($e_state);
+					
+					if ($generalContactVoiceTelephone){
+						$e_voice_telephone = $doc->createElement("ContactVoiceTelephone", $generalContactVoiceTelephone);
+						$e_contact->appendChild($e_voice_telephone);
 					}
-					if ($generalContactPostCode){
-						$e_postcode = $doc->createElement("PostCode", $generalContactPostCode);
-						$e_contact_address->appendChild($e_postcode);
+					if ($generalContactFacsimileTelephone){
+						$e_facsimile_telephone = $doc->createElement("ContactFacsimileTelephone", $generalContactFacsimileTelephone);
+						$e_contact->appendChild($e_facsimile_telephone);
 					}
-					if ($generalContactCountry){
-						$e_country = $doc->createElement("Country", $generalContactCountry);
-						$e_contact_address->appendChild($e_country);
+					if ($generalContactElectronicMailAddress){
+						$e_email = $doc->createElement("ContactElectronicMailAddress", $generalContactElectronicMailAddress);
+						$e_contact->appendChild($e_email);
 					}
-					$e_contact->appendChild($e_contact_address);
+					$e_general->appendChild($e_contact);
 				}
 				
-				if ($generalContactVoiceTelephone){
-					$e_voice_telephone = $doc->createElement("ContactVoiceTelephone", $generalContactVoiceTelephone);
-					$e_contact->appendChild($e_voice_telephone);
+				
+				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);
 				}
-				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);
-			}
+			$e_view_context->appendChild($e_general);
+		
+		
+		// 
+		// STEP 2/2: GENERATE THE LAYERLIST TAG
+		// 
+		$e_layer_list = $doc->createElement("LayerList");
+		for ($h = 0; $h < count($mapObject); $h++) {
+			// 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 = "";		
 			
+		
+			for ($i=0; $i < count($mapObject[$h]->wms); $i++){
+				$wmsId = $mapObject[$h]->wms[$i]->wms_id;
+				$wms_epsg = array();
+				$wms_epsg[0] = $mapObject[$h]->epsg;
 			
-			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);
+				if ($mapObject[$h]->wms[$i]->gui_wms_epsg != $mapObject[$h]->epsg){
+					$wms_epsg[1] = $mapObject[$h]->wms[$i]->gui_wms_epsg;
 				}
-				$e_general->appendChild($e_extensionGeneral);
-			}
-		$e_view_context->appendChild($e_general);
-	
-	
-		// LayerList
-		$e_layer_list = $doc->createElement("LayerList");
-	
-		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;
-			}
-	
-			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;
+				for ($q = 0; $q < count($mapObject[$h]->wms[$i]->gui_epsg); $q++){
+					$isInArray = false;
+					
+					for ($r=0 ; $r < count($wms_epsg); $r++){
+						if ($wms_epsg[$r] == $mapObject[$h]->wms[$i]->gui_epsg[$q]){
+							$isInArray = true;
+						}
 					}
+					if ($isInArray == false){
+						array_push($wms_epsg, $mapObject[$h]->wms[$i]->gui_epsg[$q]);
+					}
 				}
-				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);
-		
-						$e_service = $doc->createElement("Server");
-						$e_service->setAttribute("service", "OGC:WMS");
-						$e_service->setAttribute("version", $wmsVersion);
-						$e_service->setAttribute("title", $wmsTitle);
-		
-						$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);
+				for ($j = 0; $j < count($mapObject[$h]->wms[$i]->objLayer); $j++){
+					if ($mapObject[$h]->wms[$i]->objLayer[$j]->layer_parent != ''){
+						if ($mapObject[$h]->wms[$i]->objLayer[$j]->gui_layer_visible == "1"){
+							$layerHidden = 0;
+						}
+						else{
+							$layerHidden = 1;
+						}
+						$layerQueryable = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_queryable;
+						$layerQuerylayer = $mapObject[$h]->wms[$i]->objLayer[$j]->gui_layer_querylayer;
+						$layerId = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_uid;
+						$layerName = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_name;
+						$layerTitle = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_title;
+						$layerAbstract = $mapObject[$h]->wms[$i]->wms_abstract; //To Do: insert actual abstract
+						$layerDataUrl = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_dataurl_href; 
+						$layerMetadataUrl = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_metadataurl;
+						$layerMinscale = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_minscale; 
+						$layerMaxscale = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_maxscale; 
+						$guiLayerMinscale = $mapObject[$h]->wms[$i]->objLayer[$j]->gui_layer_minscale; 
+						$guiLayerMaxscale = $mapObject[$h]->wms[$i]->objLayer[$j]->gui_layer_maxscale; 
+						$wmsVersion = $mapObject[$h]->wms[$i]->wms_version;
+						$wmsTitle = $mapObject[$h]->wms[$i]->wms_title;
+						$wmsLayerId = $mapObject[$h]->wms[$i]->objLayer[0]->layer_uid;
+						$wmsOnlineResource = $mapObject[$h]->wms[$i]->wms_getmap;
+						$layerPos = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_pos;
+						$layerParent = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_parent;
+						$queryLayer = $mapObject[$h]->wms[$i]->objLayer[$j]->gui_layer_querylayer;
+						$wfsFeatureType = $mapObject[$h]->wms[$i]->objLayer[$j]->gui_layer_wfs_featuretype;
 						
-						$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 = $doc->createElement("Layer");
+						$e_layer->setAttribute("queryable", $layerQueryable);
+						$e_layer->setAttribute("hidden", $layerHidden);
 			
-							$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_service = $doc->createElement("Server");
+							$e_service->setAttribute("service", "OGC:WMS");
+							$e_service->setAttribute("version", $wmsVersion);
+							$e_service->setAttribute("title", $wmsTitle);
+			
+							$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_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_service->appendChild($e_service_or);
+							$e_layer->appendChild($e_service);
 			
-							$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);
-						}
-
-						$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_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_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_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);
 							}
-						}
-						$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
+							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);
 							}
-							else{
-								$layerStyle_current = 0; // To do: insert proper data
+			
+							$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 (isset($mapObject[$h]->isOverview)) {
+								$e_isOverviewLayer = $doc->createElement($extension_namespace.":isOverviewLayer", 1);
+								$e_extension->appendChild($e_isOverviewLayer);
 							}
+							
+							if ($wfsFeatureType) {
+								$e_wfsFeatureType = $doc->createElement($extension_namespace.":wfsFeatureType", $wfsFeatureType);
+								$e_extension->appendChild($e_wfsFeatureType);
+							}
+	
+							$e_layer->appendChild($e_extension);
+			
+							//layerFormat
+							$e_layer_format = $doc->createElement("FormatList");
+			
+							$data_format_current = false;
+			
+							for ($k = 0; $k < count($mapObject[$h]->wms[$i]->data_format); $k++){
+			
+								if ($mapObject[$h]->wms[$i]->data_type[$k] == "map") {
+									$layerFormat = $mapObject[$h]->wms[$i]->data_format[$k];
+					
+									$e_format = $doc->createElement("Format", $layerFormat);
+			
+									if ($data_format_current == false && ( 
+											($mapObject[$h]->wms[$i]->data_format[$k] == $mapObject[$h]->wms[$i]->gui_wms_mapformat) ||
+											($k == (count($mapObject[$h]->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[$h]->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[$h]->wms[$i]->objLayer[$j]->layer_style[$k]->name;
+									$layerStyle_title = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_style[$k]->title;
+									$layerStyle_legendUrl = $mapObject[$h]->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 = $doc->createElement("Style");
+									$e_layer_style_name = $doc->createElement("Name", $layerStyle_name);
+									$e_layer_style->appendChild($e_layer_style_name);
 		
-							$layerStyleSLD = "";
+									$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);
 		
-							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_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_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);
+								$e_layer_stylelist->appendChild($e_layer_style);
+							}	
+							$e_layer->appendChild($e_layer_stylelist);
+							
+						$e_layer_list->appendChild($e_layer);
+					}
 				}
 			}
 		}
 		$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){
+		$this->monitoringIsOn = true;
+		
+		$doc = $this->getDocument($wmc_id);
+		$this->createObjFromWMC_xml($doc);
+	}
 	
-	$doc->appendChild($e_view_context);
-	$this->xml = $doc->saveXML();
+	/**
+	 * 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);
 	
-	// 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){
+		// store xml 
+		$this->xml = $data;
 	
-	global $DBSERVER,$DB,$OWNER,$PW;
-	$con = db_connect($DBSERVER,$OWNER,$PW);
-	db_select_db(DB, $con);
+		// 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);
+		}
 	
-	$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1";
-	$v = array($wmc_id);
-	$t = array("i");
-	$res = db_prep_query($sql, $v, $t);
-	$wmc = db_fetch_row($res);
-	$this->createObjFromWMC_xml($wmc[0]);
-	$this->monitoringIsOn = true;
-}
-
-/**
- * Loads a WMC from an actual WMC XML document.
- * 
- * @param string $data the data from the XML file
- */
-function createObjFromWMC_xml($data){
-#	$data = str_replace("&#38;", "&amp;", $data);
-
-	// store xml 
-	$this->xml = $data;
-
-	// 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);
-	}
-
-
-
-	$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;
-	}
-	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"];
+		$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;
 		}
-		if(strtoupper($element[tag]) == "GENERAL" && $element[type] == "open"){
-		   $general = true;
-		}
-		if(strtoupper($element[tag]) == "LAYERLIST" && $element[type] == "open"){
-		   $layerlist = true;
-		}
-		if ($general) {
+		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"];
+			}
+			if(strtoupper($element[tag]) == "GENERAL" && $element[type] == "open"){
+			   $general = true;
+			}
+			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"];
@@ -1059,6 +1129,241 @@
 	  //return $verbose;
 	}
 
+	function load ($wmcId) {
+		$this->createObjFromWMC_id($wmcId);
+		
+		// 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]);
+			}
+		}
+		
+		// will contain the JS code to create the maps
+		// representing the state stored in this WMC
+		$wmc_string = "";
+
+		// general extension
+		if (count($this->wmc_general_extension) > 0) {
+			$json = new Mapbender_JSON();
+			$wmc_string .= "restoredWmcExtensionData = " . $json->encode($this->wmc_general_extension) . ";"; 
+		}
+		
+		$foundWmsArray = array();
+		
+		// for all layers in wmc, find individual wms...
+		for ($i = 0; $i < count($this->wmc_layer_title); $i++) {
+			$currentWms = $this->wmc_wms_serviceURL[$i];
+
+			// skip this WMS if it has been found before
+			if (in_array($currentWms , $foundWmsArray)) {
+				continue;
+			}
+			
+			// mark this WMS as found
+			array_push($foundWmsArray, $currentWms);
+
+			// add wms
+			$wmc_string .= $this->getJsCodeAddWms($i);
+
+			// add epsg
+			$wmc_string .= $this->createJsCodeAddWmsSrs();
+
+			$layerlist = "";
+			$querylayerlist = "";
+			$numberOfLayers = 0;
+			
+			// find other layers belonging to this layer
+			for ($ii = $i; $ii < count($this->wmc_layer_title); $ii++) {
+				if ($currentWms != $this->wmc_wms_serviceURL[$ii]) {
+					continue;
+				}
+					
+				// add root layer
+				if ($numberOfLayers == 0) {
+					$wmc_string .= $this->getJsCodeAddRootLayer($i);
+				}
+				$numberOfLayers++;
+				
+				// add other layers
+				$wmc_string .= $this->getJsCodeAddLayer ($numberOfLayers, $i, $ii);
+
+				// add layer style
+				$wmc_string .= $this->getJsCodeAddLayerStyle ($numberOfLayers, $ii);
+
+				// add layer format (FIXME: is this working?)
+				$wmc_string .= $this->getJsCodeAddLayerDataFormat($ii);
+				
+
+			}
+		}
+		$wmc_string = "mb_mapObj = null;";
+		$wmc_string = "wms = null;";
+		$wmc_string .= "mb_registerMapObj('mapframe1', 'maps', null, " . $this->wmc_windowWidth . ", " . $this->wmc_windowHeight . ");"; 
+		$wmc_string .= "mb_calculateExtent('mapframe1', " . 
+							$this->wmc_bBox_minx .",".$this->wmc_bBox_miny ."," . 
+							$this->wmc_bBox_maxx .",".$this->wmc_bBox_maxy.");";
+		$wmc_string .= "setMapRequest('mapframe1');";
+
+		$ov_bbox = array();
+
+		// 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);
+
+		// 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);
+			
+			$unionBox = Mapbender_bbox::union(array($ov_box, $mf_box));
+			
+		}
+		else {
+			$unionBox = $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); 				
+		
+
+		$wmc_string .= "mb_registerMapObj('overview', 'maps', 0, " . $this->wmc_windowWidth . ", " . $this->wmc_windowHeight . ");"; 
+	
+		$wmc_string .= "mb_calculateExtent('overview', " .
+						$ov_bbox[0] .",".$ov_bbox[1] ."," .
+						$ov_bbox[2] .",".$ov_bbox[3] .");";
+
+		$wmc_string .= "setMapRequest('overview');\n";
+//		$wmc_string .= $target . "mb_execloadWmsSubFunctions();";
+		return $wmc_string;
+	}
+
+	function append ($wmcId) {
+		$this->createObjFromWMC_id($wmcId);
+		$this->createJsObjFromWMC("", "", "append");
+	}
+
+	function merge ($wmcId) {
+		$this->createObjFromWMC_id($wmcId);
+		$this->createJsObjFromWMC("", "", "merge");
+	}
+	
+	private function getJsCodeAddWms ($i) {
+		// get the last data format of this WMS
+		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_addWMS_string = "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'," .
+			"'');";
+		return $wmc_addWMS_string;
+	}
+	
+	private function createJsCodeAddWmsSrs () {
+		return "wms_addSRS(" . 
+			"'" . $this->wmc_bBox_SRS . "'," . 
+			"'" . $this->wmc_bBox_minx . "'," . 
+			"'" . $this->wmc_bBox_miny . "'," . 
+			"'" . $this->wmc_bBox_maxx . "'," . 
+			"'" . $this->wmc_bBox_maxy . "');";
+	}
+	
+	private function getJsCodeAddLayerDataFormat($ii) {
+		$z = count($this->wmc_layer_format[$ii]);
+		for($j=0; $j < $z; $j++){
+			$wmc_string .= "wms_add_data_type_format(" . 
+						"'map'," . 
+						"'" . $this->wmc_layer_format[$ii][$j] ."');";
+		}
+	}
+	
+	private function getJsCodeAddRootLayer ($i) {
+		return "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'," . 
+				"'');";
+	}
+
+	private function getJsCodeAddLayerStyle ($cnt_layers, $ii) {
+		$str = "";
+		for ($j = 0; $j < count($this->wmc_layer_style_name[$ii]); $j++){
+			$str .= "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] . "');";
+		}
+		return $str;
+	}
+	
+	private function getJsCodeAddLayer ($cnt_layers, $i, $ii) {
+		return "\twms_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] . "'" . 
+			");";
+		
+	}
+
 	/**
 	 * Creates JS code manipulating the map and wms objects, 
 	 * by this displaying the WMC
@@ -1071,9 +1376,13 @@
 	 */
 	function createJsObjFromWMC($target, $mapObj, $action){
 		
-		/*
-		 * counts how often a layer has been loaded
-		 */
+		// abort if action is not valid
+		$validActions = array("load", "merge", "append");
+		if (!in_array($action, $validActions)) {
+			return "alert('invalid action: ".$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++) {
@@ -1081,293 +1390,264 @@
 			}
 		}
 		
+		// will contain the JS code to create the maps
+		// representing the state stored in this WMC
 		$wmc_string = "";
-		$validActions = array("load", "merge", "append");
-		if (!in_array($action, $validActions)) {
-			$wmc_string .= "alert('invalid action: ".$action."');";			
+
+		// general extension
+		if (count($this->wmc_general_extension) > 0) {
+			$json = new Mapbender_JSON();
+			$wmc_string .= "restoredWmcExtensionData = " . $json->encode($this->wmc_general_extension) . ";\n"; 
 		}
-		else {
+		
+/*
+		$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";
+		}
+		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();
+*/		
+
+		$foundWmsArray = array();
+		
+		// for all layers in wmc, find individual wms...
+		for ($i = 0; $i < count($this->wmc_layer_title); $i++) {
+			$currentWms = $this->wmc_wms_serviceURL[$i];
+
+			// skip this WMS if it has been found before
+			if (in_array($currentWms , $foundWmsArray)) {
+				continue;
+			}
 			
-			// general extension
-			if (count($this->wmc_general_extension) > 0) {
-				$json = new Mapbender_JSON();
-				$wmc_string .= $target . "restoredWmcExtensionData = " . $json->encode($this->wmc_general_extension) . ";\n"; 
+			// mark this WMS as found
+			array_push($foundWmsArray, $currentWms);
+
+			$layerlist = "";
+			$querylayerlist = "";
+			$srs_array = array();
+
+			$mywms = new wms();
+/*	
+	  		if(!$this->wmc_layer_title[$i] || $this->wmc_layer_title[$i] == ""){
+				echo "alert('Error: no valid capabilities-document !!');\n";
+				die; exit;
 			}
+*/
 			
-			$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";
-			}
+			$wmc_addWMS_string = $this->getJsCodeAddWms($i);
+
+/*
+			$cnt_wms++;
+			$cnt_layers = 0;
+			$cnt_query_layers = 0;
+*/
+
+			// When merging, add this WMS only if it is not already loaded in the application
 			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
+				$wmc_string .=  "wms_exists = false;\n" . 
+								"current_wms_index = null;\n" . 
+								"for (var m=0; m < " . $target . "mb_mapObj[index].wms.length; m++) {\n" . 
+									"\tif ('" . $this->wmc_wms_serviceURL[$i] . "' ==  " . $target . "mb_mapObj[index].wms[m].wms_getmap) {\n" . 
+										"\t\twms_exists = true;\n" . 
+										"\t\tcurrent_wms_index = m;\n" . 
+									"\t}\n" . 
+								"}\n" . 
+								"if (!wms_exists) {\n" . 
+									$wmc_addWMS_string . 
+								"}\n";
 			}
-			$new_wms = "";
-			$cnt_wms = -1;
-			$added_wms = array();
-			
-			// 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;
-					}
+			else {
+				$wmc_string .= $wmc_addWMS_string;
+			}
 
-					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 epsg
+			$wmc_string .= $this->createJsCodeAddWmsSrs();
+
+			// 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?)
+					$wmc_string .= $this->getJsCodeAddLayerDataFormat($ii);
+					
+					// add root layer
+					if ($cnt_layers == 0) {
+						$wmc_addLayer_string = $this->getJsCodeAddRootLayer($i);
+
+						if ($action == "merge") {
+							$wmc_string .=  "if (!wms_exists) {\n\t" . 
+												$wmc_addLayer_string . 
+											"}\n";
+						} 
+						else {
+							$wmc_string .= $wmc_addLayer_string;
 						}
 					}
-					// 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;
+					$cnt_layers++;
+					
+					// add other layers
+					$wmcAddLayerString = $this->getJsCodeAddLayer ($cnt_layers, $i, $ii);
+					
 					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";
+						$wmc_string .= "if (wms_exists) {\n";
+						
+						// check if this layer already exists in this wms
+						$wmc_string .=  "\tlayer_exists = false;\n" . 
+										"\tcurrent_layer_index = null;\n" . 
+										"\tfor (var m=0; m < mb_mapObj[index].wms[current_wms_index].objLayer.length; m++) {\n" . 
+											"\t\tif ('" . $this->wmc_layer_name[$ii] . "' == mb_mapObj[index].wms[current_wms_index].objLayer[m].layer_name) {\n" . 
+												"\t\t\tlayer_exists = true;\n" . 
+												"\t\t\tcurrent_layer_index = m;\n" . 
+											"\t\t}\n" . 
+										"\t}\n"; 
 
-					// 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"; 
+						if ($this->wmc_layer_querylayer[$ii] != "") {
+							$querylayer_yn = $this->wmc_layer_querylayer[$ii];
+						}
+						else {
+							$querylayer_yn = $this->wmc_layer_queryable[$ii];
+						}			
 
-								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";
-							} 
+						$wmc_string .= "\tif (layer_exists) {\n";
 
-							// 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";
+						// check if the visibility or the queryability are different to the existing layer
+						$wmc_string .=  	"\t\tif (mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_visible != '" . intval(!$this->wmc_layer_hidden[$ii]) . "'" . 
+											" || 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\tmb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_visible = " . intval(!$this->wmc_layer_hidden[$ii]) . ";\n" .
+												"\t\t\tmb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer = " . $querylayer_yn . ";\n" .
+											"\t\t}\n" .
+										"\t}\n" . 
+									"}\n" . 
+									"\telse {\n" . 
+										$wmcAddLayerString . 
+									"\t}\n";
+					}
+					else {
+						$wmc_string .= $wmcAddLayerString;
+					} 
+
+/*										
+					// 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++;
+						$isAlreadyInList = !in_array($this->wmc_layer_name[$ii], explode(",",$querylayerlist));
+						if (!$isAlreadyInList) {
+							if ($querylayerlist != "") {
+								$querylayerlist .= ",";
 							} 
-												
-							// 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";
-							}
+							$querylayerlist .= $this->wmc_layer_name[$ii];
 						}
 					}
-					// 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";
+					// if layer is visible, add it to layerlist 
+					$isAlreadyInList = in_array($this->wmc_layer_name[$ii], explode(",", $layerlist));
+					$isVisible = intval(!$this->wmc_layer_hidden[$ii]);
+					if (!$isAlreadyInList && $isVisible) {
+						if ($layerlist != "") {
+							$layerlist .= ",";
+						} 
+						$layerlist .= $this->wmc_layer_name[$ii];
 					}
+*/
+					// add layer style (FIXME: is this working?)
+					$wmc_string .= $this->getJsCodeAddLayerStyle($cnt_layers, $ii);
 				}
-			}
-			$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 {
+				// add wms to mapObj with all layers and querylayers
 /*
-				$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"]);
+				$wmc_addWMSwithLayers_string = $target. "mb_mapObjaddWMSwithLayers('" . $mapObj . "', '" . $layerlist . "', '" . $querylayerlist . "');\n";
+				if ($action == "merge") {
+					$wmc_string .=  "if (!wms_exists) {\n" . 
+										$wmc_addWMSwithLayers_string . 
+									"}\n" . 
+									"else {\n" . 
+										"mb_mapObj[index].layers[current_wms_index] = \"" . $layerlist . "\";\n" . 
+										"mb_mapObj[index].querylayers[current_wms_index] = \"" . $querylayerlist . "\";\n" . 
+									"}\n";
 				}
-				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 {
+					$wmc_string .= $wmc_addWMSwithLayers_string;
 				}
-				else {
 */
-					$ov_bbox = array(2412139.175257732, 5365000, 2767860.824742268, 5700000);		
-//				}
 			}
+		}
+		$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, " . $this->wmc_general_extension["ov_width"] . ", " . $this->wmc_general_extension["ov_height"] . ");\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();
+
+		// 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);
+
+		// 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);
 			
-			$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";
+			$unionBox = Mapbender_bbox::union(array($ov_box, $mf_box));
+			
 		}
-//		$e = new mb_exception("js code: " . $wmc_string);
+		else {
+			$unionBox = $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); 				
+		
+
+		$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";
 		return $wmc_string;
 	}
 } 

Modified: branches/beck_dev/mapbender/http/javascripts/map.js
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/map.js	2008-05-08 11:19:00 UTC (rev 2450)
+++ branches/beck_dev/mapbender/http/javascripts/map.js	2008-05-09 16:00:35 UTC (rev 2451)
@@ -30,21 +30,18 @@
 	}
 }
 
+/**
+ * @deprecated
+ */
 function localize() {
 	eventLocalize.trigger();
-/*
-	for(var i=0; i<mb_l10nFunctions.length; i++){
-		eval(mb_l10nFunctions[i]); 	 
-	} 	 
-*/
 }
+
+/**
+ * @deprecated
+ */
 function mb_execloadWmsSubFunctions(){
 	eventAfterLoadWMS.trigger();
-/*
-	for(var i=0; i<mb_loadWmsSubFunctions.length; i++){
-		eval(mb_loadWmsSubFunctions[i]); 	 
-	} 	 
-*/
 }
 
 function mb_execWfsReadSubFunctions(geom) { 	 
@@ -84,15 +81,17 @@
 /*END OF GLOBALS*/
 
 
+/**
+ * Called in index.php on body onload
+ */
 function init() {
+	// creates the map objects (mapframe1, overview...)
 	eventInitMap.trigger();
+
+	// initialisation
 	eventInit.trigger();
-/*
-	for(var i=0; i<mb_InitFunctions.length; i++){
-		eval(mb_InitFunctions[i]);
-	}
-*/
 	
+	// performs a map request for each map frame
 	for(var i=0; i<mb_mapObj.length; i++){
 		setMapRequest(mb_mapObj[i].frameName);
 	}      	
@@ -121,75 +120,70 @@
 	this.querylayers = [];
 	this.geom = "";
 	this.gml = ""; 
+	this.wms = [];
 
-	if (wms_index !== null){
-		this.wms = [];
-		this.wms[0] = wms[wms_index];
-		this.wms[0].mapURL = false;
-		var cnt_layers = 0;
-		var cnt_querylayers = 0;
-		var styles = "";
-		var layers = "";
-		var querylayers = "";
-		for (var ii=0; ii<this.wms[0].objLayer.length; ii++){
-			if (this.wms[0].objLayer[ii].gui_layer_visible == 1 && ii>0){
-				if (cnt_layers > 0) {
+	// 
+	// Add pointers to WMS objects which are in this map.
+	// If wms_index is set (=map is overview), only this 
+	// WMS is being pointed to.
+	//
+	var index = 0;
+	for(var i=0; i < wms.length; i++){
+		var isValidWms = (wms_index === null) || (wms_index == i);
+		if (isValidWms) {
+			this.wms[index] = wms[i];
+			this.wms[index].mapURL = false;
+			index++;
+		}
+	}
+
+	//
+	// set list of visible layers, active querylayers 
+	// and styles for each WMS in this map
+	//
+	var cnt_layers;
+	var cnt_querylayers;
+	var styles;
+	var layers;
+	var querylayers = "";
+	for(i=0; i< this.wms.length; i++){
+		cnt_layers = 0;
+		cnt_querylayers = 0;
+		styles = "";
+		layers = "";
+		querylayers = "";
+
+		for(var ii=0; ii<this.wms[i].objLayer.length; ii++){
+			// layer is visible and not root layer
+			if(this.wms[i].objLayer[ii].gui_layer_visible == 1 && ii>0){
+				if(cnt_layers > 0){
 					layers += ","; styles += ","; 
 				}
-				layers += this.wms[0].objLayer[ii].layer_name; 
+				layers += wms[i].objLayer[ii].layer_name; 
 				styles += ""; 
 				cnt_layers++;
-			}   
-			if (this.wms[0].objLayer[ii].gui_layer_querylayer == 1 && ii>0) {
-				if (cnt_querylayers > 0) {
+			}            
+			// layer is queryable and not root layer
+			if(this.wms[i].objLayer[ii].gui_layer_querylayer == 1 && ii>0){
+				if(cnt_querylayers > 0){
 					querylayers += ",";
 				}
-				querylayers += this.wms[0].objLayer[ii].layer_name; 
+				querylayers += wms[i].objLayer[ii].layer_name; 
 				cnt_querylayers++;
-			}                      
+			}                          
 		}
-		this.layers[0] = layers;
-		this.styles[0] = styles;
-		this.querylayers[0] = querylayers;   
+		this.layers[i] = layers;
+		this.styles[i] = styles;
+		this.querylayers[i] = querylayers;
 	}
-	else {
-		this.wms = [];
-		for(var i=0; i<wms.length; i++){
-			this.wms[i] = wms[i];
-			this.wms[i].mapURL = false;
-		}
-		for(i=0; i< this.wms.length; i++){
-			var cnt_layers = 0;
-			var cnt_querylayers = 0;
-			var styles = "";
-			var layers = "";
-			var querylayers = "";
-			for(var ii=0; ii<this.wms[i].objLayer.length; ii++){
-				if(this.wms[i].objLayer[ii].gui_layer_visible == 1 && ii>0){
-					if(cnt_layers > 0){
-						layers += ","; styles += ","; 
-					}
-					layers += wms[i].objLayer[ii].layer_name; 
-					styles += ""; 
-					cnt_layers++;
-				}            
-				if(this.wms[i].objLayer[ii].gui_layer_querylayer == 1 && ii>0){
-					if(cnt_querylayers > 0){
-						querylayers += ",";
-					}
-					querylayers += wms[i].objLayer[ii].layer_name; 
-					cnt_querylayers++;
-				}                          
-			}
-			this.layers[i] = layers;
-			this.styles[i] = styles;
-			this.querylayers[i] = querylayers;
-		}
-	}
-   this.epsg = wms[0].gui_wms_epsg;
-   this.extent = setExtent(this.width,this.height,this.epsg);
-   this.mapURL = [];
    
+	this.epsg = wms[0].gui_wms_epsg;
+	this.extent = setExtent(this.width,this.height,this.epsg);
+	this.mapURL = [];
+	var styleTag = window.frames[this.frameName].document.getElementById(this.elementName).style;
+	styleTag.width = this.width;
+	styleTag.height = this.height;   
+   
 	/**
 	 * get the width of the mapObj
 	 *

Modified: branches/beck_dev/mapbender/http/javascripts/mod_displayWmc.php
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/mod_displayWmc.php	2008-05-08 11:19:00 UTC (rev 2450)
+++ branches/beck_dev/mapbender/http/javascripts/mod_displayWmc.php	2008-05-09 16:00:35 UTC (rev 2451)
@@ -22,9 +22,9 @@
 $wmc_id = $_GET["wmc_id"];
 
 if ($wmc_id){
-	require_once(dirname(__FILE__)."/../classes/class_administration.php");
-	$admin = new administration();
-	$wmc_gml = $admin->getWmcById($wmc_id);
+	require_once(dirname(__FILE__)."/../classes/class_wmc.php");
+	$wmc = new wmc();
+	$wmc_gml = $wmc->getDocument($wmc_id);
 
 	if ($wmc_gml){
 		//Display WMC

Added: branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js	                        (rev 0)
+++ branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js	2008-05-09 16:00:35 UTC (rev 2451)
@@ -0,0 +1,169 @@
+// 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(){
+
+	// 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:"<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>"
+		});
+	}
+
+	// display the pop up
+	if (!wmcPopup.isVisible()) {
+		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"));
+			var $td;
+			
+			$tr.append($("<td>" + wmcObj.wmc[i].title + "</td>"));
+			$tr.append($("<td>" + wmcObj.wmc[i].timestamp + "</td>"));
+
+			$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) {
+								eval(resultObj.javascript);
+							}	
+						}
+						catch (e) {
+							alert(e);
+							loadWmcError = true;
+						}
+					}
+					if (loadWmcError) {
+						alert("An error has occured while deleting this WMC.");
+					}
+				});
+			});
+			$td = $("<td></td>").append($loadWmc);
+			$tr.append($td);				
+
+			$mergeWmc = $("<img src='../img/button_gray/wmc_merge.png' title='merge WMC'>");
+			$td = $("<td></td>").append($mergeWmc);
+			$tr.append($td);				
+
+			$appendWmc = $("<img src='../img/button_gray/wmc_append.png' title='append WMC'>");
+			$td = $("<td></td>").append($appendWmc);
+			$tr.append($td);				
+
+			$displayWmc = $("<img src='../img/button_gray/wmc_xml.png' title='display WMC XML'>");
+			$displayWmc.click(function() {
+				// create Popup
+				if (wmcDisplayPopup === null) {
+					console.log("is 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);
+		}());
+	}
+}
\ No newline at end of file

Modified: branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.php
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.php	2008-05-08 11:19:00 UTC (rev 2450)
+++ branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.php	2008-05-09 16:00:35 UTC (rev 2451)
@@ -22,8 +22,6 @@
 
 include(dirname(__FILE__) . "/../include/dyn_js.php");
 
-echo "mod_loadwmc_target = '".$e_target[0]."';";
-
 /*
 // this may be added at a later stage
 if ($new_wmc == 1) {
@@ -46,53 +44,44 @@
 	}
 }
 */
-?>
-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");
-				}
-				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;
-			}
-			else {
-				echo "var e = new Mb_notice('mod_loadwmc: load_wmc_session: error parsing wmc');";
-			}
+
+//
+// Creates the function load_wmc_session.
+// This function loads a WMC from the session, if the element var
+// "loadFromSession" is set to true.
+//
+echo "function load_wmc_session() {";
+if (isset($_SESSION['mb_wmc'])) {
+	$wmc = new wmc();
+	if ($wmc->createObjFromWMC_xml($_SESSION['mb_wmc'])) {
+		$js = "";
+		if ($_SESSION['layer_preview']) {
+			$js = $wmc->createJsObjFromWMC("", $e_target, "load");
 		}
+		else if ($startup == true) {
+			$js = $wmc->createJsObjFromWMC("", $e_target, "merge");
+			$startup = false;
+		}		
 		else {
-			echo "var e = new Mb_warning('mod_loadwmc: load_wmc_session: no wmc set!');";
+			$js = $wmc->createJsObjFromWMC("", $e_target, "load");
 		}
-	?>
+		echo $js;
+	}
+	else {
+		echo "var e = new Mb_notice('mod_loadwmc: load_wmc_session: error parsing wmc');";
+	}
 }
+else {
+	echo "var e = new Mb_warning('mod_loadwmc: load_wmc_session: no wmc set!');";
+}
+echo "}";
 
-try {if (loadFromSession) {}}catch(e) {loadFromSession = 0;}
 
-if (loadFromSession) {
-	mb_registerInitFunctions('load_wmc_session()');
-}
+echo "var mod_loadwmc_img = new Image(); mod_loadwmc_img.src = '" . $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/beck_dev/mapbender/http/javascripts/mod_loadwmc_list.php
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/mod_loadwmc_list.php	                        (rev 0)
+++ branches/beck_dev/mapbender/http/javascripts/mod_loadwmc_list.php	2008-05-09 16:00:35 UTC (rev 2451)
@@ -0,0 +1,3 @@
+<?php
+	echo "fisch";
+?>
\ No newline at end of file

Modified: branches/beck_dev/mapbender/http/javascripts/mod_savewmc.php
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/mod_savewmc.php	2008-05-08 11:19:00 UTC (rev 2450)
+++ branches/beck_dev/mapbender/http/javascripts/mod_savewmc.php	2008-05-09 16:00:35 UTC (rev 2451)
@@ -64,5 +64,5 @@
 	if (storeInSession) {
 		$.ajaxSetup({async:false}); //TODO: find out why async doesn't work onunload
 	}
-	$.post("../php/mod_insertWmcIntoDb.php", {"saveInSession":storeInSession, "generalTitle":generalTitle, "extensionData":extensionDataString, "mapObject":$.toJSON(mb_mapObj[ind])}, callbackFunction);
+	$.post("../php/mod_insertWmcIntoDb.php", {"saveInSession":storeInSession, "generalTitle":generalTitle, "extensionData":extensionDataString, "mapObject":$.toJSON(mb_mapObj)}, callbackFunction);
 }
\ No newline at end of file

Modified: branches/beck_dev/mapbender/http/javascripts/popup.js
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/popup.js	2008-05-08 11:19:00 UTC (rev 2450)
+++ branches/beck_dev/mapbender/http/javascripts/popup.js	2008-05-09 16:00:35 UTC (rev 2451)
@@ -52,7 +52,7 @@
 		}
 
 //	this.id="popup"+String(create_pos);
-	this.id="popup"+String(popup_top);
+	this.id="popup"+String(++popup_top);
 	
 	//Set defaults
 	defaults = {

Added: branches/beck_dev/mapbender/http/php/mod_loadwmc_server.php
===================================================================
--- branches/beck_dev/mapbender/http/php/mod_loadwmc_server.php	                        (rev 0)
+++ branches/beck_dev/mapbender/http/php/mod_loadwmc_server.php	2008-05-09 16:00:35 UTC (rev 2451)
@@ -0,0 +1,143 @@
+<?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();
+
+$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 JS code)
+	case 'loadWmc':
+		$wmcId = $queryObj->parameters->id;
+		$js = $wmc->load($wmcId);
+		if ($js) {
+			$resultObj["javascript"] = $js;
+		}
+		else {
+			$resultObj["error"] = "WMC could not be loaded.";
+		}
+	break;
+	
+	// appends a WMC (returns JS code)
+	case 'loadWmc':
+		$wmcId = $queryObj->parameters->id;
+		$js = $wmc->append($wmcId);
+		if ($js) {
+			$resultObj["javascript"] = $js;
+		}
+		else {
+			$resultObj["error"] = "WMC could not be appended.";
+		}
+	break;
+	
+	// merges a WMC (returns JS code)
+	case 'mergeWmc':
+		$wmcId = $queryObj->parameters->id;
+		$js = $wmc->merge($wmcId);
+		if ($js) {
+			$resultObj["javascript"] = $js;
+		}
+		else {
+			$resultObj["error"] = "WMC could not be merged.";
+		}
+	break;
+
+	// Invalid command
+	default:
+		$resultObj["error"] = "no action specified...";
+}
+
+sendOutput($resultObj);
+?>
\ No newline at end of file

Modified: branches/beck_dev/mapbender/http/php/mod_map1.php
===================================================================
--- branches/beck_dev/mapbender/http/php/mod_map1.php	2008-05-08 11:19:00 UTC (rev 2450)
+++ branches/beck_dev/mapbender/http/php/mod_map1.php	2008-05-09 16:00:35 UTC (rev 2451)
@@ -54,8 +54,6 @@
 function init () {
 	parent.eventInitMap.register(function init_mod_map1(){
 		parent.mb_registerMapObj('mapframe1', 'maps', null,mod_map1_width, mod_map1_height);
-		document.getElementById("maps").style.width = mod_map1_width;
-		document.getElementById("maps").style.height = mod_map1_height;
 	});
 }
 

Modified: branches/beck_dev/mapbender/http/php/mod_mapOV.php
===================================================================
--- branches/beck_dev/mapbender/http/php/mod_mapOV.php	2008-05-08 11:19:00 UTC (rev 2450)
+++ branches/beck_dev/mapbender/http/php/mod_mapOV.php	2008-05-09 16:00:35 UTC (rev 2451)
@@ -68,12 +68,12 @@
 		document.onmousedown = parent.mod_box_start;
 		document.onmouseup = mod_ov_getExtent;
 		document.onmousemove = parent.mod_box_run;
-		document.getElementById("maps").style.width = mod_overview_width;
-		document.getElementById("maps").style.height = mod_overview_height;   
 		
 		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_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){



More information about the Mapbender_commits mailing list