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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue May 20 04:55:03 EDT 2008


Author: christoph
Date: 2008-05-20 04:55:03 -0400 (Tue, 20 May 2008)
New Revision: 2466

Modified:
   branches/beck_dev/mapbender/http/classes/class_wmc.php
   branches/beck_dev/mapbender/http/classes/class_wms.php
   branches/beck_dev/mapbender/http/javascripts/mod_initWmc.php
   branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js
   branches/beck_dev/mapbender/http/php/mod_insertWmcIntoDb.php
   branches/beck_dev/mapbender/http/php/mod_loadwmc_server.php
Log:
refactoring

Modified: branches/beck_dev/mapbender/http/classes/class_wmc.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_wmc.php	2008-05-20 04:53:38 UTC (rev 2465)
+++ branches/beck_dev/mapbender/http/classes/class_wmc.php	2008-05-20 08:55:03 UTC (rev 2466)
@@ -27,21 +27,54 @@
 
 /**
  * Implementation of a Web Map Context Document, WMC 1.1.0
+ * 
+ * Use cases:
+ * 
+ * Instantiation (1) create a WMC object from a WMC XML document
+ * 		$myWmc = new wmc();
+ * 		$myWmc->createFromXml($xml);
+ * 
+ *    If you want to create a WMC object from a WMC in the database
+ *    	$xml = wmc::getDocument($wmcId);
+ * 		$myWmc = new wmc();
+ * 		$myWmc->createFromXml($xml);
+ *    
+ * 
+ * Instantiation (2) create a WMC from the client side
+ * 		$myWmc = new wmc();
+ * 		$myWmc->createWmcFromJs($mapObject, $user_id, $generalTitle, $extensionData);
+ * 	
+ * 	  	(creates a WMC from the JS data and then creates an object from that WMC)
+ * 
+ * Output (1) (do Instantiation first) Load a WMC into client
+ * 		This will return an array of JS statements
+ *  
+ * 		$myWmc->load();
+ * 
+ * Output (2) (do Instantiation first) Merge with another WMC, then load
+ * 	
+ * 		$myWmc->merge($anotherWmcXml);
+ * 		$myWmc->load();
+ * 
  */
 class wmc {
 
-	var $xml;
-	
 	var $mainMap;
 	var $overviewMap;
 	var $wmsArray = array();
 	var $overviewWmsIndex = null;
 	var $generalExtensionArray = array();
+	var $xml;
 	
+	// constants
 	var $monitoringIsOn = false;
 	var $saveWmcAsFile = false;
   		
+	// set in constructor
 	var $wmc_id;
+	var $userId;
+
+	// set during parsing
 	var $wmc_version;
 	var $wmc_name;
 	var $wmc_title;
@@ -69,64 +102,36 @@
 	var $wmc_descriptionurl_type;
 
 	public function __construct () {
+		$this->userId = $_SESSION["mb_user_id"];
+		$this->wmc_id = time();
 	} 
 	
+	// ---------------------------------------------------------------------------
+	// INSTANTIATION
+	// ---------------------------------------------------------------------------
+
 	/**
-	 * 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?
+	 * Parses the XML string and instantiates the WMC object.
+	 * 
+	 * @param $xml String
 	 */
-	public function delete ($wmcId, $userId) {
-		if (!isset($userId) || $userId === null) {
-			$userId = $_SESSION["mb_user_id"];
-		}
-		
-		$sql = "DELETE FROM mb_user_wmc ";
-		$sql .= "WHERE fkey_user_id = $1 AND wmc_id = $2";
-		$v = array($userId, $wmcId);
-		$t = array('i', 's');
-		$res = db_prep_query($sql, $v, $t);
-		if ($res) {
-			return true;
-		}
-		return false;
+	public function createFromXml ($xml) {
+		return $this->createObjFromWMC_xml($xml);
 	}
-	
+
 	/**
-	 * Returns a WMC document
-	 * @return String|boolean The document if it exists; else false
-	 * @param $id String the WMC id
+	 * Loads a WMC from the database.
+	 * 
+	 * @param integer $wmc_id the ID of the WMC document in the database table "mb_user_wmc"
 	 */
-	public 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"];
-		}
-		return false;
+	function createFromDb($wmcId){
+		$this->monitoringIsOn = true;
+		
+		$doc = wmc::getDocument($wmcId);
+		$this->createObjFromWMC_xml($doc);
 	}
 
-	public static function merge ($xml1, $xml2) {
-		$mergedWmc = new wmc();
-		$mergedWmc->createWmcFromXml($xml1);
-		$this->wmsArray = wms::merge($this->wmsArray, $someWmc->wmsArray);
-		return $mergedWmc->load();
-	}
-
 	/**
-	 * @return string the title of the WMC.
-	 */
-	public function getTitle() {
-		return $this->wmc_title;
-	}
-	
-	/**
 	 * Creates a WMC object from a JS map object {@see map_obj.js}
 	 * 
 	 * @param object $mapObject a map object
@@ -135,7 +140,7 @@
 	 * @param object $extensionData data exclusive to Mapbender, which will be 
 	 * 								mapped into the extension part of the WMC
 	 */
-	public function createWmcFromJs($mapObject, $user_id, $generalTitle, $extensionData) {
+	public function createFromJs($mapObject, $generalTitle, $extensionData) {
 	
 		$extension_namespace = "mapbender";
 		$extension_namespace_url = "http://www.mapbender.org";
@@ -144,7 +149,6 @@
 		// STEP 1/2: GENERATE THE GENERAL TAG
 		// 
 	
-		$this->wmc_id = $user_id . '_' . time();
 		$generalWidth = 0; // set below
 		$generalHeight = 0; // set below
 		$generalBboxSrs = 0; // set below
@@ -630,34 +634,511 @@
 		}
 		$e_view_context->appendChild($e_layer_list);
 		$doc->appendChild($e_view_context);
+
 		$this->xml = $doc->saveXML();
+		$this->wmc_title = $generalTitle;
 		
+		$this->createFromXml($this->xml);
+		
 		$filename = $this->saveAsFile();
 	}
 	
+	// ---------------------------------------------------------------------------
+	// DATABASE FUNCTIONS
+	// ---------------------------------------------------------------------------
+
 	/**
-	 * Loads a WMC from the database.
+	 * Stores this WMC in the database. The WMC has to be instantiated first, see above.
 	 * 
-	 * @param integer $wmc_id the ID of the WMC document in the database table "mb_user_wmc"
+	 * @return mixed[] an assoc array with attributes "success" (boolean) and "message" (String).
 	 */
-	function createObjFromWMC_id($wmc_id){
-		$this->monitoringIsOn = true;
+	public function insert () {
+		$result = array();
+		if ($this->userId && $this->xml && $this->wmc_title) {
+			$sql = "INSERT INTO mb_user_wmc VALUES ($1, $2, $3, $4, $5)";
+			$v = array($this->wmc_id, $this->userId, $this->xml, $this->wmc_title, time());
+			$t = array("s", "i", "s", "s", "s");
+			
+			$res = db_prep_query($sql, $v, $t);
+			if (db_error()) {
+				$errMsg = "Error while saving WMC document '" . $this->wmc_title . "': " . db_error();
+				$result["success"] = false;
+				$result["message"] = $errMsg;
+				$e = new mb_exception("mod_insertWMCIntoDB: " . $errMsg);
+			}
+			else {
+				$result["success"] = true;
+				$msg = "WMC document '" . $this->wmc_title . "' has been saved.";
+				$result["message"] = $msg;
+				$e = new mb_notice("mod_insertWMCIntoDB: WMC  '" . $this->wmc_title . "' saved successfully.");
+			}
+		}
+		else {
+			$result["success"] = false;
+			$errMsg = "missing parameters (user_id: ".$this->userId.", title: " . $this->title . ")";
+			$result["message"] = $errMsg;
+			$e = new mb_exception("mod_insertWMCIntoDB: " . $errMsg .")");
+		}
+		return $result;
+	}
+	
+	/**
+	 * deletes a {@link http://www.mapbender.org/index.php/WMC WMC} 
+	 * entry specified by wmc_id and user_id
+	 *
+	 * @param	integer		the user_id
+	 * @param	string		the wmc_id
+	 * @return	boolean		Did the query run successful?
+	 */
+	public static function delete ($wmcId, $userId) {
+		if (!isset($userId) || $userId === null) {
+			$userId = $_SESSION["mb_user_id"];
+		}
 		
-		$doc = $this->getDocument($wmc_id);
-		$this->createObjFromWMC_xml($doc);
+		$sql = "DELETE FROM mb_user_wmc ";
+		$sql .= "WHERE fkey_user_id = $1 AND wmc_id = $2";
+		$v = array($userId, $wmcId);
+		$t = array('i', 's');
+		$res = db_prep_query($sql, $v, $t);
+		if ($res) {
+			return true;
+		}
+		return false;
 	}
+
+	/**
+	 * Returns a WMC document
+	 * @return String|boolean The document if it exists; else false
+	 * @param $id String the WMC id
+	 */
+	public static function getDocument ($id) {
+		$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1";
+		$v = array($id);
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
+		$row = db_fetch_array($res);
+		if ($row) {
+			return $row["wmc"];
+		}
+		return false;
+	}
+
+	// ---------------------------------------------------------------------------
+	// GETTER FUNCTIONS
+	// ---------------------------------------------------------------------------
 	
-	public function createWmcFromXml ($xml) {
-		return $this->createObjFromWMC_xml($xml);
+	/**
+	 * @return string the title of the WMC.
+	 */
+	public function getTitle() {
+		return $this->wmc_title;
 	}
+
+	// ---------------------------------------------------------------------------
+	// OUTPUT FUNCTIONS
+	// ---------------------------------------------------------------------------
 	
 	/**
+	 * Wrapper function, returns XML at the moment
+	 * @return String
+	 */
+	public function __toString() {
+		return $this->toXml();
+	}
+
+	/**
+	 * Returns the XML document if available
+	 * 
+	 * @return String The XML document; if unavailable, null is returned.
+	 */
+	public function toXml () {
+		if ($this->xml) {
+			return $this->xml;
+		}
+		return null;
+	}
+
+	/**
+	 * Returns an array of JavaScript statements
+	 * 
+	 * @return String[]
+	 */
+	public function toJavaScript () {
+/*
+		// counts how often a layer has been loaded
+		if ($this->monitoringIsOn) {
+			$monitor = new Layer_load_count();
+			for ($i = 0; $i < count($this->wmc_layer_id); $i++) {
+				$monitor->increment($this->wmc_layer_id[$i]);
+			}
+		}
+*/		
+		// will contain the JS code to create the maps
+		// representing the state stored in this WMC
+		$wmcJsArray = array();
+		
+		// set general extension data
+		if (count($this->wmc_general_extension) > 0) {
+			$json = new Mapbender_JSON();
+			array_push($wmcJsArray, "restoredWmcExtensionData = " . $json->encode($this->generalExtensionArray) . ";"); 
+		}
+		
+		// reset WMS data
+		array_push($wmcJsArray, "wms = [];");
+
+		// for all wms...
+		for ($i = 0; $i < count($this->wmsArray); $i++) {
+			// ..add wms and set properties
+			array_push($wmcJsArray, $this->wmsArray[$i]->createJsObjFromWMS_());
+		}
+
+		// delete existing map objects...
+		array_push($wmcJsArray, "mb_mapObj = [];");
+
+		// .. and add main map ..
+		$wmcJsArray = array_merge($wmcJsArray, $this->mainMap->createJsObj(null));
+
+		// .. and the overview map (if exists)
+		if ($this->overviewWmsIndex !== null) {
+			$wmcJsArray = array_merge($wmcJsArray, $this->overviewMap->createJsObj($this->overviewWmsIndex));
+		}
+
+		// Finally, request the maps
+		array_push($wmcJsArray, "setMapRequest('" . $this->mainMap->getFrameName() . "');");
+		if ($this->overviewWmsIndex !== null) {
+			array_push($wmcJsArray, "setMapRequest('" . $this->overviewMap->getFrameName() . "');");
+		}
+		return $wmcJsArray;
+	}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+	public function merge ($xml2) {
+		$someWmc = new wmc();
+		$someWmc->createFromXml($xml2);
+
+//		$this->mainMap = $someWmc->mainMap;
+//		$this->overviewMap = $someWmc->overviewMap;
+//		$this->overviewWmsIndex = $someWmc->overviewWmsIndex;
+//		$this->generalExtensionArray = array_merge($this->generalExtensionArray, $someWmc->generalExtensionArray);
+
+		$this->wmsArray = wms::merge(array_merge($someWmc->wmsArray, $this->wmsArray));
+		return $this->toJavaScript();
+	}
+
+	
+	/**
+	 * Creates JS code manipulating the map and wms objects, 
+	 * by this displaying the WMC
+	 * 
+	 * @param string $target the link to the map object, f.e. "parent." or "window.opener."
+	 * @param string $mapObj the name of the map object, f.e. "mapframe1"
+	 * @param string $action "load", "merge" or "append"
+	 * 
+	 * @return string the JS code
+	 * @deprecated
+	 */
+	function createJsObjFromWMC($target, $mapObj, $action){
+		
+		// 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++) {
+				$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) . ";\n"; 
+		}
+		
+/*
+		$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;
+			}
+			
+			// 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_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 .=  "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";
+			}
+			else {
+				$wmc_string .= $wmc_addWMS_string;
+			}
+
+			// 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;
+						}
+					}
+					$cnt_layers++;
+					
+					// add other layers
+					$wmcAddLayerString = $this->getJsCodeAddLayer ($cnt_layers, $i, $ii);
+					
+					if ($action == "merge") {
+						$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"; 
+
+						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 (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 .= ",";
+							} 
+							$querylayerlist .= $this->wmc_layer_name[$ii];
+						}
+					}
+					// 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);
+				}
+
+				// add wms to mapObj with all layers and querylayers
+/*
+				$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 {
+					$wmc_string .= $wmc_addWMSwithLayers_string;
+				}
+*/
+			}
+		}
+		$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);
+			
+			$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 .= "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;
+	}
+
+// ---------------------------------------------------------------------------
+// private functions
+// ---------------------------------------------------------------------------
+
+	/**
 	 * Loads a WMC from an actual WMC XML document.
 	 * Uses WMS class.
 	 * 
 	 * @param string $data the data from the XML file
 	 */
-	function createObjFromWMC_xml($data){
+	private function createObjFromWMC_xml($data){
 		// store xml 
 		$this->xml = $data;
 	
@@ -1021,365 +1502,10 @@
 			$this->setLayerData($layerlistCompleteArray[$i]);
 		}
 
-		$yetAnotherWmsArray = array_merge($this->wmsArray, $this->wmsArray);
-		$otherWmsArray = wms::merge($yetAnotherWmsArray);
-		$e = new mb_exception("old wms: " . implode(", ", $yetAnotherWmsArray)) ;
-		$e = new mb_exception("new wms: " . implode(", ", $otherWmsArray)) ;
-		
 		return true;
 	}
 
-	public 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
-		$wmcJsArray = array();
-		
-		// set general extension data
-		if (count($this->wmc_general_extension) > 0) {
-			$json = new Mapbender_JSON();
-			array_push($wmcJsArray, "restoredWmcExtensionData = " . $json->encode($this->generalExtensionArray) . ";"); 
-		}
-		
-		// reset WMS data
-		array_push($wmcJsArray, "wms = [];");
-
-		// for all wms...
-		for ($i = 0; $i < count($this->wmsArray); $i++) {
-			// ..add wms and set properties
-			array_push($wmcJsArray, $this->wmsArray[$i]->createJsObjFromWMS_());
-		}
-
-		// delete existing map objects...
-		array_push($wmcJsArray, "mb_mapObj = [];");
-
-		// .. and add main map ..
-		$wmcJsArray = array_merge($wmcJsArray, $this->mainMap->createJsObj(null));
-
-		// .. and the overview map (if exists)
-		if ($this->overviewWmsIndex !== null) {
-			$wmcJsArray = array_merge($wmcJsArray, $this->overviewMap->createJsObj($this->overviewWmsIndex));
-		}
-
-		// Finally, request the maps
-		array_push($wmcJsArray, "setMapRequest('" . $this->mainMap->getFrameName() . "');");
-		if ($this->overviewWmsIndex !== null) {
-			array_push($wmcJsArray, "setMapRequest('" . $this->overviewMap->getFrameName() . "');");
-		}
-		return $wmcJsArray;
-	}
-/*
-	function append ($wmcId) {
-		$this->createObjFromWMC_id($wmcId);
-		$this->createJsObjFromWMC("", "", "append");
-	}
-
-	function merge ($wmcId) {
-		$this->createObjFromWMC_id($wmcId);
-		$this->createJsObjFromWMC("", "", "merge");
-	}
-*/	
 	/**
-	 * Creates JS code manipulating the map and wms objects, 
-	 * by this displaying the WMC
-	 * 
-	 * @param string $target the link to the map object, f.e. "parent." or "window.opener."
-	 * @param string $mapObj the name of the map object, f.e. "mapframe1"
-	 * @param string $action "load", "merge" or "append"
-	 * 
-	 * @return string the JS code
-	 */
-	function createJsObjFromWMC($target, $mapObj, $action){
-		
-		// 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++) {
-				$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) . ";\n"; 
-		}
-		
-/*
-		$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;
-			}
-			
-			// 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_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 .=  "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";
-			}
-			else {
-				$wmc_string .= $wmc_addWMS_string;
-			}
-
-			// 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;
-						}
-					}
-					$cnt_layers++;
-					
-					// add other layers
-					$wmcAddLayerString = $this->getJsCodeAddLayer ($cnt_layers, $i, $ii);
-					
-					if ($action == "merge") {
-						$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"; 
-
-						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 (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 .= ",";
-							} 
-							$querylayerlist .= $this->wmc_layer_name[$ii];
-						}
-					}
-					// 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);
-				}
-
-				// add wms to mapObj with all layers and querylayers
-/*
-				$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 {
-					$wmc_string .= $wmc_addWMSwithLayers_string;
-				}
-*/
-			}
-		}
-		$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);
-			
-			$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 .= "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;
-	}
-
-// ---------------------------------------------------------------------------
-// private functions
-// ---------------------------------------------------------------------------
-
-	/**
 	 * Saves the current WMC in the log folder.
 	 * 
 	 * @return string the filename of the WMC document.

Modified: branches/beck_dev/mapbender/http/classes/class_wms.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_wms.php	2008-05-20 04:53:38 UTC (rev 2465)
+++ branches/beck_dev/mapbender/http/classes/class_wms.php	2008-05-20 08:55:03 UTC (rev 2466)
@@ -173,6 +173,7 @@
 					}
 				}
 				if ($isNewWms) {
+					$e = new mb_exception("adding WMS " . $currentWms);
 					array_push($newWmsArray, $currentWms);
 				}
 			}

Modified: branches/beck_dev/mapbender/http/javascripts/mod_initWmc.php
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/mod_initWmc.php	2008-05-20 04:53:38 UTC (rev 2465)
+++ branches/beck_dev/mapbender/http/javascripts/mod_initWmc.php	2008-05-20 08:55:03 UTC (rev 2466)
@@ -68,7 +68,7 @@
 			echo "var wmc_id = false;";
 			echo "wmc_id = '".$wmc_id."';";
 			$wmc = new wmc();
-			$wmc->createObjFromWMC_id($wmc_id);
+			$wmc->createFromDb($wmc_id);
 			$js_wmc .= $wmc->createJsObjFromWMC("", $e_target[0], $action);
 			
 			if (!empty($x) && !empty($y) && !empty($icon)) {

Modified: branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js	2008-05-20 04:53:38 UTC (rev 2465)
+++ branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js	2008-05-20 08:55:03 UTC (rev 2466)
@@ -124,6 +124,49 @@
 			$tr.append($td);				
 
 			$mergeWmc = $("<img src='../img/button_gray/wmc_merge.png' title='merge WMC'>");
+			$mergeWmc.click(function() {
+				var	extensionDataString = null;
+				if (currentWmcExtensionData != null) {
+					extensionDataString = currentWmcExtensionData;
+				}
+				var queryObj = {
+					command:"mergeWmc", 
+					parameters:{
+						id:currentId, 
+						extensionData:extensionDataString, 
+						mapObject:mb_mapObj,
+						generalTitle:"currentState"
+					}
+				};
+				$.post(serverSideFileName, {queryObj: $.toJSON(queryObj)}, function (json, status) {
+					var loadWmcError = false;
+					if (json && status == "success") {
+						var resultObj = eval("(" + json + ")");
+						try {
+							if (resultObj.javascript && typeof(resultObj.javascript) == "object") {
+								for (var j=0; j < resultObj.javascript.length; j++) {
+									eval(resultObj.javascript[j]);
+								}
+							}	
+						}
+						catch (e) {
+							alert(e);
+							loadWmcError = true;
+						}
+					}
+					if (loadWmcError) {
+						alert("An error has occured while loading this WMC.");
+					}
+					else {
+						// close the Pop up
+						if (wmcDisplayPopup !== null && wmcDisplayPopup.isVisible()) {
+							wmcDisplayPopup.hide();
+						}
+						wmcPopup.hide();
+						alert("WMC has been loaded successfully.");
+					}
+				});
+			});
 			$td = $("<td></td>").append($mergeWmc);
 			$tr.append($td);				
 

Modified: branches/beck_dev/mapbender/http/php/mod_insertWmcIntoDb.php
===================================================================
--- branches/beck_dev/mapbender/http/php/mod_insertWmcIntoDb.php	2008-05-20 04:53:38 UTC (rev 2465)
+++ branches/beck_dev/mapbender/http/php/mod_insertWmcIntoDb.php	2008-05-20 08:55:03 UTC (rev 2466)
@@ -24,40 +24,23 @@
 
 $json = new Mapbender_JSON();
 $mapObject = $json->decode(stripslashes($_POST["mapObject"]));
-$user_id = $_SESSION["mb_user_id"];
-$save_in_session = $_POST["saveInSession"];
+$userId = $_SESSION["mb_user_id"];
+$saveInSession = $_POST["saveInSession"];
 $generalTitle = $_POST["generalTitle"];
 
 $extensionData = $json->decode(stripslashes($_POST["extensionData"]));
 
 $wmc = new wmc();
-$wmc->createWmcFromJs($mapObject, $user_id, $generalTitle, $extensionData);
+$wmc->createFromJs($mapObject, $generalTitle, $extensionData);
 
-if ($save_in_session) {
+if ($saveInSession) {
 	$_SESSION["mb_wmc"] = $wmc->xml;
 	$_SESSION["epsg"] = $mapObject->epsg;
 	$_SESSION["previous_gui"] = $_SESSION["mb_user_gui"];
 	$e = new mb_notice("mod_insertWMCIntoDB: save WMC in session succeeded.");
 }
 else {
-	if ($user_id && $wmc->wmc_id) {
-		$sql = "INSERT INTO mb_user_wmc VALUES ($1, $2, $3, $4, $5)";
-		$v = array($wmc->wmc_id, $user_id, $wmc->xml, $generalTitle, time());
-		$t = array("s", "i", "s", "s", "s");
-		
-		$res = db_prep_query($sql, $v, $t);
-		if (db_error()) {
-			$errMsg = "Error while saving WMC document '" . $generalTitle . "': " . db_error();
-			echo $errMsg;
-			$e = new mb_exception("mod_insertWMCIntoDB: " . $errMsg);
-		}
-		else {
-			echo "WMC document '" . $generalTitle . "' has been saved.";
-			$e = new mb_notice("mod_insertWMCIntoDB: WMC  '" . $generalTitle . "' saved successfully.");
-		}
-	}
-	else {
-		$e = new mb_exception("mod_insertWMCIntoDB: missing parameters (user_id: ".$user_id.", wmc_id: ".$wmc->wmc_id."))");
-	}
+	$result = $wmc->insert();
+	echo $result["message"];
 }
 ?>
\ No newline at end of file

Modified: branches/beck_dev/mapbender/http/php/mod_loadwmc_server.php
===================================================================
--- branches/beck_dev/mapbender/http/php/mod_loadwmc_server.php	2008-05-20 04:53:38 UTC (rev 2465)
+++ branches/beck_dev/mapbender/http/php/mod_loadwmc_server.php	2008-05-20 08:55:03 UTC (rev 2466)
@@ -65,6 +65,8 @@
 $queryObj = $json->decode(stripslashes($_REQUEST['queryObj']));
 $resultObj = array();
 
+$e = new mb_exception("command: " . $queryObj->command);
+
 $wmc = new wmc();
 $userId = $_SESSION[mb_user_id];
 
@@ -98,18 +100,44 @@
 		}
 	break;
 	
-	// loads a WMC (returns JS code)
+	// loads a WMC (returns array of JS code)
 	case 'loadWmc':
 		$wmcId = $queryObj->parameters->id;
-		$js = $wmc->load($wmcId);
-		if ($js) {
-			$resultObj["javascript"] = $js;
+		$wmc->createFromDb($wmcId);
+		$jsArray = $wmc->toJavaScript();
+		if ($jsArray) {
+			$resultObj["javascript"] = $jsArray;
 		}
 		else {
 			$resultObj["error"] = "WMC could not be loaded.";
 		}
 	break;
-	
+
+	// merges data with WMC and loads it (returns array of JS code)
+	case 'mergeWmc':
+		$params = $queryObj->parameters;
+		
+		// generate a WMC for the current client state
+		$currentWmc = new wmc();
+		$currentWmc->createFromJs($params->mapObject, $params->generalTitle, $params->extensionData);
+
+		// get the desired WMC from the database
+		$wmcId = $queryObj->parameters->id;
+		$wmcXml = wmc::getDocument($wmcId);
+
+		// merge the two WMCs
+		$currentWmc->merge($wmcXml);
+		
+		// load the merged WMC
+		$jsArray = $currentWmc->toJavaScript();
+		if ($jsArray) {
+			$resultObj["javascript"] = $jsArray;
+		}
+		else {
+			$resultObj["error"] = "WMC could not be loaded.";
+		}
+	break;
+/*	
 	// appends a WMC (returns JS code)
 	case 'loadWmc':
 		$wmcId = $queryObj->parameters->id;
@@ -133,7 +161,7 @@
 			$resultObj["error"] = "WMC could not be merged.";
 		}
 	break;
-
+*/
 	// Invalid command
 	default:
 		$resultObj["error"] = "no action specified...";



More information about the Mapbender_commits mailing list