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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue May 27 09:37:12 EDT 2008


Author: christoph
Date: 2008-05-27 09:37:12 -0400 (Tue, 27 May 2008)
New Revision: 2473

Added:
   branches/beck_dev/mapbender/http/php/mod_savewmc_server.php
   branches/beck_dev/mapbender/lib/core.js
   branches/beck_dev/mapbender/lib/event.js
Removed:
   branches/beck_dev/mapbender/http/javascripts/core.js
   branches/beck_dev/mapbender/http/javascripts/event.js
   branches/beck_dev/mapbender/http/php/mod_insertWmcIntoDb.php
Modified:
   branches/beck_dev/mapbender/http/classes/class_map.php
   branches/beck_dev/mapbender/http/classes/class_wmc.php
   branches/beck_dev/mapbender/http/classes/class_wmcToXml.php
   branches/beck_dev/mapbender/http/classes/class_wms.php
   branches/beck_dev/mapbender/http/javascripts/core.php
   branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js
   branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.php
   branches/beck_dev/mapbender/http/javascripts/mod_savewmc.php
   branches/beck_dev/mapbender/http/php/mod_loadwmc_server.php
Log:
debugging

Modified: branches/beck_dev/mapbender/http/classes/class_map.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_map.php	2008-05-27 07:03:07 UTC (rev 2472)
+++ branches/beck_dev/mapbender/http/classes/class_map.php	2008-05-27 13:37:12 UTC (rev 2473)
@@ -121,6 +121,14 @@
 		return $this->isOverview;
 	}
 	
+	public function setIsOverview ($bool) {
+		$this->isOverview = $bool;
+	}
+	
+	public function append ($anotherMap) {
+		$this->wmsArray = array_merge($anotherMap->getWmsArray(), $this->wmsArray);
+	}
+		
 	public function merge ($anotherMap) {
 		$this->width = $anotherMap->width;
 		$this->height = $anotherMap->height;
@@ -152,6 +160,7 @@
 		
 		if (isset($jsMapObject->isOverview) && $jsMapObject->isOverview == "1") {
 			$this->isOverview = true;
+			$e = new mb_notice("ov: " . $this->isOverview);
 		}
 
 		for ($i=0; $i < count($jsMapObject->wms); $i++){
@@ -252,23 +261,39 @@
 	 */
 	public function createJsObj ($wmsIndex) {
 		$jsCodeArray = array();
+
+		// initialise map object
+		if ($wmsIndex === null) {
+			$wmsIndex = "null";
+		}
 		$registerMapString = "mb_registerMapObj('" . 
 			$this->frameName . "', " . 
 			"'maps', " . 
-			(($wmsIndex !== null)?$wmsIndex:"null") . ", " . 
+			$wmsIndex . ", " . 
 			$this->width . ", " . 
 			$this->height . ");"; 
 		array_push($jsCodeArray, $registerMapString);
 
+		$e = new mb_notice("Map to JS: ov? " . $this->isOverview);
+
+		// if map is overview...
+		if ($this->isOverview) {
+			// ...set overview flag
+			$setOverviewFlagString = "mb_mapObj[mb_mapObj.length-1].isOverview = true;";
+			array_push($jsCodeArray, $setOverviewFlagString);
+		}
+		
+		// set width
 		$setMapframeWidth = "document.getElementById('" . $this->frameName . "')." . 
 			"style.width = " . $this->width . ";";
 		array_push($jsCodeArray, $setMapframeWidth);
 
+		// set height
 		$setMapframeHeight = "document.getElementById('" . $this->frameName . "')." . 
 			"style.height = " . $this->height . ";";
 		array_push($jsCodeArray, $setMapframeHeight);
 
-
+		// calculate extent
 		$calcExtentString = "mb_calculateExtent('" . 
 			$this->frameName . "', " .
 			$this->extent->min->x . ", " . 

Modified: branches/beck_dev/mapbender/http/classes/class_wmc.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_wmc.php	2008-05-27 07:03:07 UTC (rev 2472)
+++ branches/beck_dev/mapbender/http/classes/class_wmc.php	2008-05-27 13:37:12 UTC (rev 2473)
@@ -43,7 +43,7 @@
  * 
  * Instantiation (2) create a WMC from the client side
  * 		$myWmc = new wmc();
- * 		$myWmc->createWmcFromJs($mapObject, $user_id, $generalTitle, $extensionData);
+ * 		$myWmc->createFromJs($mapObject, $generalTitle, $extensionData);
  * 	
  * 	  	(creates a WMC from the JS data and then creates an object from that WMC)
  * 
@@ -84,11 +84,10 @@
 	
 	// constants
 	var $monitoringIsOn = false;
-	var $saveWmcAsFile = false;
+	var $saveWmcAsFile = true;
 	var $extensionNamespace = "mapbender";
 	var $extensionNamespaceUrl = "http://www.mapbender.org";
 		
-  		
 	// set in constructor
 	var $wmc_id;
 	var $userId;
@@ -188,6 +187,7 @@
 		// create XML
 		$this->createXml();
 
+		$this->saveAsFile();
 		return true;
 	}
 	
@@ -343,7 +343,6 @@
 			array_push($wmcJsArray, $wmsArray[$i]->createJsObjFromWMS_());
 		}
 
-		array_push($wmcJsArray, "console.log('wms object: %s', $.toJSON(wms));");
 		// delete existing map objects...
 		array_push($wmcJsArray, "mb_mapObj = [];");
 
@@ -373,6 +372,8 @@
 		if ($this->overviewMap !== null) {
 			array_push($wmcJsArray, "setMapRequest('" . $this->overviewMap->getFrameName() . "');");
 		}
+
+		array_push($wmcJsArray, "eventAfterLoadWMS.trigger()");
 		return $wmcJsArray;
 	}
 
@@ -393,7 +394,24 @@
 		}
 	}
 
+	/**
+	 * Appends the layers of another WMC to this WMC.
+	 * 
+	 * @return void
+	 * @param $xml2 Object
+	 */
+	public function append ($xml2) {
+		$someWmc = new wmc();
+		$someWmc->createFromXml($xml2);
 
+		$this->mainMap->append($someWmc->mainMap);
+		if (isset($this->overviewMap) && isset($someWmc->overviewMap)) {
+			// There is only one WMS in the overview map; merge, not append
+			$this->overviewMap->merge($someWmc->overviewMap);
+		}
+	}
+
+
 // ---------------------------------------------------------------------------
 // private functions
 // ---------------------------------------------------------------------------
@@ -777,8 +795,8 @@
 	 */
 	private function saveAsFile() {
 		if ($this->saveWmcAsFile) {
-			$filename = "wmc_" . date("Y_m_d_H_i_s") . ".log";
-			$logfile = "../../log/" . $filename;
+			$filename = "wmc_" . date("Y_m_d_H_i_s") . ".xml";
+			$logfile = "../tmp/" . $filename;
 			
 			if($h = fopen($logfile,"a")){
 				$content = $this->xml;
@@ -830,14 +848,10 @@
 		// Even if this WMS has been found before it could still
 		// be a duplicate! We would have to create a new WMS and 
 		// not append this layer to that WMS.
-		if ($wmsIndex !== null) {
+		// For the overview layer we never add a new wms.
+		// check if this layer is an overview layer. If yes, skip this layer.
+		if ($wmsIndex !== null && !$currentMapIsOverview) {
 
-			// for the overview layer we never add a new wms.
-			// check if this layer is an overview layer. If yes, skip this layer.
-			if ($currentMapIsOverview) {
-				return;
-			}
-
 			// check if this WMS has a layer equal to the current layer.
 			// If yes, this is a new WMS. If not, append this layer
 			// to the existing WMS.
@@ -897,7 +911,8 @@
 			// set root layer
 			$wms->addLayer(0, "");
 			$wms->objLayer[0]->layer_uid = $currentLayer["extension"]["WMS_LAYER_ID"];
-			$wms->objLayer[0]->layer_name = $currentLayer["wms_title"];
+			$wms->objLayer[0]->layer_name = $currentLayer["extension"]["WMS_NAME"];
+			$wms->objLayer[0]->layer_title = $currentLayer["wms_title"];
 			$wms->objLayer[0]->layer_pos = 0;
 			$wms->objLayer[0]->layer_queryable = 0;
 			$wms->objLayer[0]->layer_minscale = 0;
@@ -944,6 +959,7 @@
 			$this->overviewMap->setWidth($this->generalExtensionArray["OV_WIDTH"]);
 			$this->overviewMap->setHeight($this->generalExtensionArray["OV_HEIGHT"]);
 			$this->overviewMap->setFrameName($this->generalExtensionArray["OV_FRAMENAME"]);
+			$this->overviewMap->setIsOverview(true);
 
 			$bbox = new Mapbender_bbox($this->generalExtensionArray["OV_MINX"], $this->generalExtensionArray["OV_MINY"], $this->generalExtensionArray["OV_MAXX"], $this->generalExtensionArray["OV_MAXY"], $this->generalExtensionArray["OV_SRS"]);
 			$this->overviewMap->setExtent($bbox);

Modified: branches/beck_dev/mapbender/http/classes/class_wmcToXml.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_wmcToXml.php	2008-05-27 07:03:07 UTC (rev 2472)
+++ branches/beck_dev/mapbender/http/classes/class_wmcToXml.php	2008-05-27 13:37:12 UTC (rev 2473)
@@ -350,6 +350,7 @@
 
 	private function createLayerExtensionNode ($currentMap, $currentWms, $currentLayer) {
 		$layerExtensionData = array();
+		$layerExtensionData["wms_name"] = $currentWms->objLayer[0]->layer_name;
 		$layerExtensionData["minscale"] = $currentLayer->layer_minscale;
 		$layerExtensionData["maxscale"] = $currentLayer->layer_maxscale;
 		$layerExtensionData["gui_minscale"] = $currentLayer->gui_layer_minscale;

Modified: branches/beck_dev/mapbender/http/classes/class_wms.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_wms.php	2008-05-27 07:03:07 UTC (rev 2472)
+++ branches/beck_dev/mapbender/http/classes/class_wms.php	2008-05-27 13:37:12 UTC (rev 2473)
@@ -87,15 +87,15 @@
 	 * @param $anotherWms wms this is just another WMS object
 	 */
 	public function equals ($anotherWms) {
-		// If the capabilities URLs are not equal, the WMS are not equal.
-		if ($this->wms_getcapabilities != $anotherWms->wms_getcapabilities) {
-			$e = new mb_notice($this . " != " . $anotherWms . " (capabilities)");
+		// If the getMap URLs are not equal, the WMS are not equal.
+		if ($this->wms_getmap != $anotherWms->wms_getmap) {
+//			$e = new mb_notice($this . " != " . $anotherWms . " (getMap URL)");
 			return false;
 		}
 
 		// If the layer count is different, the WMS are not equal.
 		if (count($this->objLayer) != count($anotherWms->objLayer)) {
-			$e = new mb_notice($this . " != " . $anotherWms . " (layer count)");
+//			$e = new mb_notice($this . " != " . $anotherWms . " (layer count: " . count($this->objLayer) . ":" . count($anotherWms->objLayer). ")");
 			return false;
 		}
 		
@@ -105,11 +105,11 @@
 			$name2 = $anotherWms->objLayer[$i]->layer_name;
 			
 			if ($name1 != $name2) {
-				$e = new mb_notice($this . " != " . $anotherWms . " (layer names, " . $name1 . " vs. " . $name2 . ")");
+//				$e = new mb_notice($this . " != " . $anotherWms . " (layer names, " . $name1 . " vs. " . $name2 . ")");
 				return false;
 			}
 		}
-		$e = new mb_notice($this . " == " . $anotherWms);
+//		$e = new mb_notice($this . " == " . $anotherWms);
 		return true;
 	}  
 	
@@ -148,6 +148,7 @@
 	 * @param $wmsArray wms[]
 	 */
 	public static function merge ($wmsArray) {
+		$e = new mb_notice("before: " . implode(", ", $wmsArray));
 		if (!is_array($wmsArray)) {
 			$e = new mb_exception("class_wms.php: merge(): parameter is NOT an array.");
 			return array();
@@ -158,6 +159,7 @@
 		}
 		
 		$newWmsArray = array();
+		
 		while (count($wmsArray) > 0) {
 			$currentWms = array_pop($wmsArray);
 			
@@ -173,12 +175,14 @@
 					}
 				}
 				if ($isNewWms) {
-					$e = new mb_exception("adding WMS " . $currentWms);
+//					$e = new mb_notice("adding WMS " . $currentWms);
 					array_push($newWmsArray, $currentWms);
 				}
 			}
-			
 		}
+		// reversal of the array, because the elements were popped 
+		// from another array before.
+//		$e = new mb_notice("after: " . implode(", ", array_reverse($newWmsArray)));
 		return array_reverse($newWmsArray);
 	}
 	
@@ -1951,5 +1955,11 @@
 		$this->layer_parent = $parent;	
 		//var_dump($this);	
 	}
+
+	public function __toString () {
+		$e = new mb_exception("TITLE: " . $this->layer_title);
+		return $this->layer_title;
+	}
+	
 }
 ?>
\ No newline at end of file

Deleted: branches/beck_dev/mapbender/http/javascripts/core.js
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/core.js	2008-05-27 07:03:07 UTC (rev 2472)
+++ branches/beck_dev/mapbender/http/javascripts/core.js	2008-05-27 13:37:12 UTC (rev 2473)
@@ -1,170 +0,0 @@
-var currentWmcExtensionData = {};
-var restoredWmcExtensionData = {};
-
-//var mb_MapRequestSubFunctions = [];
-//var mb_MapRequestPreFunctions = [];
-//var mb_MapObjectSubFunctions = [];
-//var mb_GetScalePreFunctions = [];
-//var mb_FeatureInfoPreFunctions = [];
-//var mb_loadWmsSubFunctions = [];
-//var mb_InitFunctions = [];
-var mb_WfsReadSubFunctions = [];
-var mb_WfsWriteSubFunctions = [];
-var mb_l10nFunctions = [];
-
-/**
- * Triggered after a map is requested.
- */
-var eventAfterMapRequest = new MapbenderEvent();
-
-/**
- * Triggered before a map is requested.
- */
-var eventBeforeMapRequest = new MapbenderEvent();
-
-/**
- * Triggered before the scale is calculated.
- */
-var eventBeforeGetScale = new MapbenderEvent();
-
-/**
- * Triggered before a feature info is requested.
- */
-var eventBeforeFeatureInfo = new MapbenderEvent();
-
-/**
- * Triggered after a WMS has been loaded.
- */
-var eventAfterLoadWMS = new MapbenderEvent();
-
-/**
- * Triggered when Mapbender is loaded and after the map object has been initialised.
- */
-var eventInit = new MapbenderEvent();
-
-/**
- * Initializes the map object. Triggered when Mapbender is loaded. 
- */
-var eventInitMap = new MapbenderEvent();
-
-/**
- * Switches the locale. Triggered by module switch_locale or onload(?) 
- */
-var eventLocalize = new MapbenderEvent();
-
-/**
- * Triggered after the map object has been created. 
- */
-var eventAfterMapObjectConstruction = new MapbenderEvent(); // possibly obsolete!
-
-/**
- * deprecated wrapped function
- * @deprecated
- */
-function mb_registerInitFunctions(stringFunction){
-//	mb_InitFunctions[mb_InitFunctions.length] = stringFunction;
-	eventInit.register(stringFunction);
-}
-
-/**
- * deprecated wrapped function
- * @deprecated
- */
-function mb_registerPreFunctions(stringFunction){
-//	mb_MapRequestPreFunctions[mb_MapRequestPreFunctions.length] = stringFunction;
-	eventBeforeMapRequest.register(stringFunction);
-}
-
-/**
- * deprecated wrapped function
- * @deprecated
- */
-function mb_registerFeatureInfoPreFunctions(stringFunction){
-//	mb_FeatureInfoPreFunctions[mb_FeatureInfoPreFunctions.length] = stringFunction;
-	eventBeforeFeatureInfo.register(stringFunction);
-}
-
-/**
- * deprecated wrapped function
- * @deprecated
- */
-function mb_registerSubFunctions(stringFunction){
-//	mb_MapRequestSubFunctions[mb_MapRequestSubFunctions.length] = stringFunction;
-	eventAfterMapRequest.register(stringFunction);
-}
-
-/**
- * deprecated wrapped function
- * @deprecated
- */
-function mb_registerMapObjectSubFunctions(stringFunction){
-//	mb_MapObjectSubFunctions[mb_MapObjectSubFunctions.length] = stringFunction;
-	eventAfterMapObjectConstruction.register(stringFunction);
-}
-
-/**
- * deprecated wrapped function
- * @deprecated
- */
-function mb_registerGetScalePreFunctions(stringFunction){
-//	mb_GetScalePreFunctions[mb_GetScalePreFunctions.length] = stringFunction;
-	eventBeforeGetScale.register(stringFunction);
-}
-
-/**
- * deprecated wrapped function
- * @deprecated
- */
-function mb_registerloadWmsSubFunctions(stringFunction){
-//	mb_loadWmsSubFunctions[mb_loadWmsSubFunctions.length] = stringFunction;
-	eventAfterLoadWMS.register(stringFunction);
-}
-
-/**
- * deprecated wrapped function
- * @deprecated
- */
-function mb_registerWfsReadSubFunctions(stringFunction){
-	mb_WfsReadSubFunctions[mb_WfsReadSubFunctions.length] = stringFunction;
-}
-
-/**
- * deprecated wrapped function
- * @deprecated
- */
-function mb_registerWfsWriteSubFunctions(stringFunction){
-	mb_WfsWriteSubFunctions[mb_WfsWriteSubFunctions.length] = stringFunction;
-}
-
-/**
- * deprecated wrapped function
- * @deprecated
- */
-function mb_registerL10nFunctions(stringFunction) {
-	eventLocalize.register(stringFunction)
-//	mb_l10nFunctions[mb_l10nFunctions.length] = stringFunction;
-}
-
-var mb_PanSubElements = [];
-function mb_registerPanSubElement(elName){
-	var ind = mb_PanSubElements.length;
-	mb_PanSubElements[ind] = elName;
-}
-
-var mb_vendorSpecific = [];
-function mb_registerVendorSpecific(stringFunction){
-	mb_vendorSpecific[mb_vendorSpecific.length] = stringFunction;
-}
-
-/**
- * deprecated function for writing content within a tag via innerHTML
- * @deprecated
- */
-function writeTag(frameName, elName, tagSource) {
-  if(frameName && frameName !== ""){
-     window.frames[frameName].document.getElementById(elName).innerHTML = tagSource;
-  }
-  else if(!frameName || frameName === ""){
-       document.getElementById(elName).innerHTML = tagSource;
-  }
-}
\ No newline at end of file

Modified: branches/beck_dev/mapbender/http/javascripts/core.php
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/core.php	2008-05-27 07:03:07 UTC (rev 2472)
+++ branches/beck_dev/mapbender/http/javascripts/core.php	2008-05-27 13:37:12 UTC (rev 2473)
@@ -19,7 +19,6 @@
 
 ob_start();
 header('Content-type: application/x-javascript');
-require_once(dirname(__FILE__) . "/../javascripts/event.js");
-require_once(dirname(__FILE__) . "/../javascripts/core.js");
-
+require_once(dirname(__FILE__) . "/../../lib/event.js");
+require_once(dirname(__FILE__) . "/../../lib/core.js");
 ?>
\ No newline at end of file

Deleted: branches/beck_dev/mapbender/http/javascripts/event.js
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/event.js	2008-05-27 07:03:07 UTC (rev 2472)
+++ branches/beck_dev/mapbender/http/javascripts/event.js	2008-05-27 13:37:12 UTC (rev 2473)
@@ -1,193 +0,0 @@
-/**
- * An event. What happens, when the event occurs, depends on which functions have been
- * registered with the event. 
- * 
- * usage:
- * 
- * // create a new Event
- * var eventAfterMapRequest = new MapbenderEvent(); 
- * 
- * // register a function with that event
- * eventAfterMapRequest.register(function () {
- * 	...
- * })
- * 
- * // trigger the event
- * eventAfterMapRequest.trigger();
- * 
- */
-var MapbenderEvent = function () {
-	
-	// public methods
-	/**
-	 * A function that needs to be executed, when the event occurs, has to be 
-	 * registered via this function.
-	 */
-	this.register = function(aFunction) {
-
-		var mpbnFunction = new MapbenderFunction(aFunction);
-		functionArray.push(mpbnFunction);
-	};
-
-	/**
-	 * Exclude a previously registered function from the event
-	 */
-	this.unregister = function(aFunction) {
-		for (var i = 0, len = functionArray.length; i < len; i++) {
-			if (functionArray[i].getFunction() === aFunction) {
-				for (var j = i + 1; j < len; j++) {
-					functionArray[j-1] = functionArray[j];
-				}
-				delete functionArray[len - 1];
-				len = len - 1;
-			}
-		}
-		functionArray.length = len;
-	};
-
-	/**
-	 * Checks if a function is already registered with this event
-	 */
-	this.isRegistered = function (aFunction) {
-		for (var i = 0, len = functionArray.length; i < len; i++) {
-			if (functionArray[i].getFunction() === aFunction) {
-				return true;
-			}
-		}
-		return false;
-	};
-	
-	/**
-	 * This function triggers the event
-	 */
-	this.trigger = function(properties, booleanOperator) {
-		if (!(functionArray.length > 0)) {
-			return true;
-		}
-		//
-		// check arguments
-		//
-		// properties
-		if (typeof(properties) != "object") {
-			// maybe properties is missing, and so 
-			// properties represents booleanOperator
-			if (typeof(booleanOperator) == "undefined") {
-				booleanOperator = properties;
-				properties = undefined;
-			}
-			else {
-//				var e = new Mb_exception("MapbenderEvent.trigger: invalid properties: %s", properties);
-			}
-		}		
-
-		// booleanOperator
-		if (typeof(booleanOperator) == "string") {
-			if (booleanOperator != "AND" && booleanOperator != "OR") {
-//				var e = new Mb_exception("MapbenderEvent.trigger: invalid booleanOperator: %s", booleanOperator);
-			}
-		}		
-		else if (typeof(booleanOperator) != "undefined") {
-//			var e = new Mb_exception("MapbenderEvent.trigger: invalid booleanOperator, must be a string, but is %s", typeof(booleanOperator));
-		}
-		
-		var result;
-
-		// the optional boolean operator allows to combine the return values of the functions
-		// into a single result value.
-		switch (booleanOperator) {
-			case "AND":
-				result = true;
-				break;
-			case "OR":
-				result = false;
-				break;
-			default:
-				result = true;
-				break;
-		}
-
-		if (log) {
-			var e = new Mb_notice("functions (after sort): " + functionArray.join(","));
-		}
-
-		for (var i = 0; i < functionArray.length; i++) {
-			// executes the function at position i
-			// and determines the return value based on the (optional) boolean operator
-			switch (booleanOperator) {
-				case "AND":
-					result = result && functionArray[i].execute(properties);
-					break;
-				case "OR":
-					result = result || functionArray[i].execute(properties);
-					break;
-				default:
-					result = functionArray[i].execute(properties);
-					break;
-			}
-		}
-		return result;
-	};	
-	
-	this.getProperties = function () {
-		return propertiesObj;
-	};
-
-	// private
-	/**
-	 * these functions will be executed once the event is triggered
-	 */
-	var functionArray = [];
-	
-	var propertiesObj;
-	var log = false;
-};
-
-/**
- * A MapbenderFunction is a function with a priority.
- */
-var MapbenderFunction = function (aFunction) {
-	
-	// public
-	/**
-	 * Returns the function itself
-	 */
-	this.getFunction = function () {
-		return func;
-	};
-	
-	/**
-	 * Executes the function
-	 */
-	this.execute = function (argumentObj) {
-		if (typeof(aFunction) == "function") {
-			return func(argumentObj);
-		}
-
-		// this branch is for backwards compatibility with the 
-		// pre-2.5 event system that is based on strings.
-		else {
-			var argumentNames = [];
-			var argumentValues = [];
-			for (var i in argumentObj) {
-				if (typeof(argumentObj[i]) == "number" || typeof(argumentObj[i]) == "boolean") {
-					argumentNames.push(i);
-					argumentValues.push(argumentObj[i]);
-				}
-				else if (typeof(argumentObj[i]) == "string") {
-					argumentNames.push(i);
-					argumentValues.push("'" + argumentObj[i] + "'");
-				}
-			}
-			var str = "";
-			str += "(function (" + argumentNames.join(", ") + ") {";
-			str += "return " + aFunction;
-			str += "}";
-			str += "(" + argumentValues.join(", ") + "));";
-			var returnValue = eval(str);
-			return returnValue;
-		}	
-	};
-	
-	// private
-	var func = aFunction;
-};
\ No newline at end of file

Modified: branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js	2008-05-27 07:03:07 UTC (rev 2472)
+++ branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js	2008-05-27 13:37:12 UTC (rev 2473)
@@ -88,6 +88,9 @@
 			$tr.append($("<td>" + wmcObj.wmc[i].title + "</td>"));
 			$tr.append($("<td>" + wmcObj.wmc[i].timestamp + "</td>"));
 
+			// 
+			// Load WMC
+			//
 			$loadWmc = $("<img src='../img/button_gray/wmc_load.png' title='load this WMC'>");
 			$loadWmc.click(function() {
 				var queryObj = {command:"loadWmc", parameters:{id:currentId}};
@@ -98,6 +101,7 @@
 						try {
 							if (resultObj.javascript && typeof(resultObj.javascript) == "object") {
 								for (var j=0; j < resultObj.javascript.length; j++) {
+//									console.log("Statement: %s", resultObj.javascript[j]);
 									eval(resultObj.javascript[j]);
 								}
 							}	
@@ -123,10 +127,13 @@
 			$td = $("<td></td>").append($loadWmc);
 			$tr.append($td);				
 
+			// 
+			// Merge WMC
+			//
 			$mergeWmc = $("<img src='../img/button_gray/wmc_merge.png' title='merge WMC'>");
 			$mergeWmc.click(function() {
 				var	extensionDataString = null;
-				if (currentWmcExtensionData != null) {
+				if (currentWmcExtensionData !== null) {
 					extensionDataString = currentWmcExtensionData;
 				}
 				var queryObj = {
@@ -145,7 +152,6 @@
 						try {
 							if (resultObj.javascript && typeof(resultObj.javascript) == "object") {
 								for (var j=0; j < resultObj.javascript.length; j++) {
-									console.log("Statement: %s", resultObj.javascript[j]);
 									eval(resultObj.javascript[j]);
 								}
 							}	
@@ -171,10 +177,59 @@
 			$td = $("<td></td>").append($mergeWmc);
 			$tr.append($td);				
 
+			// 
+			// Append WMC
+			//
 			$appendWmc = $("<img src='../img/button_gray/wmc_append.png' title='append WMC'>");
+			$appendWmc.click(function() {
+				var	extensionDataString = null;
+				if (currentWmcExtensionData !== null) {
+					extensionDataString = currentWmcExtensionData;
+				}
+				var queryObj = {
+					command:"appendWmc", 
+					parameters:{
+						id:currentId, 
+						extensionData:extensionDataString, 
+						mapObject:mb_mapObj,
+						generalTitle:"currentState"
+					}
+				};
+				$.post(serverSideFileName, {queryObj: $.toJSON(queryObj)}, function (json, status) {
+					var loadWmcError = false;
+					if (json && status == "success") {
+						var resultObj = eval("(" + json + ")");
+						try {
+							if (resultObj.javascript && typeof(resultObj.javascript) == "object") {
+								for (var j=0; j < resultObj.javascript.length; j++) {
+									eval(resultObj.javascript[j]);
+								}
+							}	
+						}
+						catch (e) {
+							alert(e);
+							loadWmcError = true;
+						}
+					}
+					if (loadWmcError) {
+						alert("An error has occured while loading this WMC.");
+					}
+					else {
+						// close the Pop up
+						if (wmcDisplayPopup !== null && wmcDisplayPopup.isVisible()) {
+							wmcDisplayPopup.hide();
+						}
+						wmcPopup.hide();
+						alert("WMC has been loaded successfully.");
+					}
+				});
+			});
 			$td = $("<td></td>").append($appendWmc);
 			$tr.append($td);				
 
+			// 
+			// Display WMC
+			//
 			$displayWmc = $("<img src='../img/button_gray/wmc_xml.png' title='display WMC XML'>");
 			$displayWmc.click(function() {
 				// create Popup

Modified: branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.php
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.php	2008-05-27 07:03:07 UTC (rev 2472)
+++ branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.php	2008-05-27 13:37:12 UTC (rev 2473)
@@ -53,19 +53,19 @@
 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 {
-			$js = $wmc->createJsObjFromWMC("", $e_target, "load");
-		}
-		echo $js;
+	if ($wmc->createFromXml($_SESSION['mb_wmc'])) {
+		$jsArray = array();
+//		if ($_SESSION['layer_preview']) {
+//			$js = $wmc->createJsObjFromWMC("", $e_target, "load");
+//		}
+//		else if ($startup == true) {
+//			$js = $wmc->createJsObjFromWMC("", $e_target, "merge");
+//			$startup = false;
+//		}		
+//		else {
+			$jsArray = $wmc->toJavaScript();
+//		}
+		echo implode("", $jsArray);
 	}
 	else {
 		echo "var e = new Mb_notice('mod_loadwmc: load_wmc_session: error parsing wmc');";

Modified: branches/beck_dev/mapbender/http/javascripts/mod_savewmc.php
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/mod_savewmc.php	2008-05-27 07:03:07 UTC (rev 2472)
+++ branches/beck_dev/mapbender/http/javascripts/mod_savewmc.php	2008-05-27 13:37:12 UTC (rev 2473)
@@ -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)}, callbackFunction);
+	$.post("../php/mod_savewmc_server.php", {"saveInSession":storeInSession, "generalTitle":generalTitle, "extensionData":extensionDataString, "mapObject":$.toJSON(mb_mapObj)}, callbackFunction);
 }
\ No newline at end of file

Deleted: branches/beck_dev/mapbender/http/php/mod_insertWmcIntoDb.php
===================================================================
--- branches/beck_dev/mapbender/http/php/mod_insertWmcIntoDb.php	2008-05-27 07:03:07 UTC (rev 2472)
+++ branches/beck_dev/mapbender/http/php/mod_insertWmcIntoDb.php	2008-05-27 13:37:12 UTC (rev 2473)
@@ -1,46 +0,0 @@
-<?php
-#$Id: mod_insertWmcIntoDb.php 1198 2007-10-18 14:37:52Z baudson $
-#$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_insertWmcIntoDb.php,v 1.19 2006/03/09 14:02:42 uli_rothstein Exp $
-# Copyright (C) 2002 CCGIS 
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
-require_once(dirname(__FILE__)."/../classes/class_administration.php");
-require_once(dirname(__FILE__)."/../classes/class_wmc.php");
-require_once(dirname(__FILE__)."/../classes/class_json.php");
-
-$json = new Mapbender_JSON();
-$mapObject = $json->decode(stripslashes($_POST["mapObject"]));
-$userId = $_SESSION["mb_user_id"];
-$saveInSession = $_POST["saveInSession"];
-$generalTitle = $_POST["generalTitle"];
-
-$extensionData = $json->decode(stripslashes($_POST["extensionData"]));
-
-$wmc = new wmc();
-$wmc->createFromJs($mapObject, $generalTitle, $extensionData);
-
-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 {
-	$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-27 07:03:07 UTC (rev 2472)
+++ branches/beck_dev/mapbender/http/php/mod_loadwmc_server.php	2008-05-27 13:37:12 UTC (rev 2473)
@@ -117,62 +117,54 @@
 	case 'mergeWmc':
 		$params = $queryObj->parameters;
 		
-		$e = new mb_notice("CREATING WMC1...");
-
 		// generate a WMC for the current client state
 		$currentWmc = new wmc();
 		$currentWmc->createFromJs($params->mapObject, $params->generalTitle, $params->extensionData);
 
-		$e = new mb_notice("CREATED WMC1");
-		$e = new mb_notice("CREATING WMC2...");
-
 		// get the desired WMC from the database
 		$wmcId = $queryObj->parameters->id;
 		$wmcXml = wmc::getDocument($wmcId);
 
-		$e = new mb_notice("CREATED WMC2...");
-
-		$e = new mb_notice("MERGING...");
 		// merge the two WMCs
 		$currentWmc->merge($wmcXml);
 		
-		$e = new mb_notice("MERGED.");
 		// load the merged WMC
-		$e = new mb_notice("EXPORTING TO JS...");
 		$jsArray = $currentWmc->toJavaScript();
-		$e = new mb_notice("JS EXPORT FINISHED.");
-		if ($jsArray) {
+
+		if (is_array($jsArray) && count($jsArray) > 0) {
 			$resultObj["javascript"] = $jsArray;
 		}
 		else {
 			$resultObj["error"] = "WMC could not be loaded.";
 		}
 	break;
-/*	
+	
 	// appends a WMC (returns JS code)
-	case 'loadWmc':
+	case 'appendWmc':
+		$params = $queryObj->parameters;
+		// generate a WMC for the current client state
+		$currentWmc = new wmc();
+		$currentWmc->createFromJs($params->mapObject, $params->generalTitle, $params->extensionData);
+
+		// get the desired WMC from the database
 		$wmcId = $queryObj->parameters->id;
-		$js = $wmc->append($wmcId);
-		if ($js) {
-			$resultObj["javascript"] = $js;
+		$wmcXml = wmc::getDocument($wmcId);
+
+		// merge the two WMCs
+		$currentWmc->append($wmcXml);
+		
+		// load the merged WMC
+		$jsArray = $currentWmc->toJavaScript();
+
+		if (is_array($jsArray) && count($jsArray) > 0) {
+			$resultObj["javascript"] = $jsArray;
 		}
 		else {
 			$resultObj["error"] = "WMC could not be appended.";
 		}
 	break;
 	
-	// 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...";

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

Copied: branches/beck_dev/mapbender/lib/core.js (from rev 2450, branches/beck_dev/mapbender/http/javascripts/core.js)
===================================================================
--- branches/beck_dev/mapbender/lib/core.js	                        (rev 0)
+++ branches/beck_dev/mapbender/lib/core.js	2008-05-27 13:37:12 UTC (rev 2473)
@@ -0,0 +1,170 @@
+var currentWmcExtensionData = {};
+var restoredWmcExtensionData = {};
+
+//var mb_MapRequestSubFunctions = [];
+//var mb_MapRequestPreFunctions = [];
+//var mb_MapObjectSubFunctions = [];
+//var mb_GetScalePreFunctions = [];
+//var mb_FeatureInfoPreFunctions = [];
+//var mb_loadWmsSubFunctions = [];
+//var mb_InitFunctions = [];
+var mb_WfsReadSubFunctions = [];
+var mb_WfsWriteSubFunctions = [];
+var mb_l10nFunctions = [];
+
+/**
+ * Triggered after a map is requested.
+ */
+var eventAfterMapRequest = new MapbenderEvent();
+
+/**
+ * Triggered before a map is requested.
+ */
+var eventBeforeMapRequest = new MapbenderEvent();
+
+/**
+ * Triggered before the scale is calculated.
+ */
+var eventBeforeGetScale = new MapbenderEvent();
+
+/**
+ * Triggered before a feature info is requested.
+ */
+var eventBeforeFeatureInfo = new MapbenderEvent();
+
+/**
+ * Triggered after a WMS has been loaded.
+ */
+var eventAfterLoadWMS = new MapbenderEvent();
+
+/**
+ * Triggered when Mapbender is loaded and after the map object has been initialised.
+ */
+var eventInit = new MapbenderEvent();
+
+/**
+ * Initializes the map object. Triggered when Mapbender is loaded. 
+ */
+var eventInitMap = new MapbenderEvent();
+
+/**
+ * Switches the locale. Triggered by module switch_locale or onload(?) 
+ */
+var eventLocalize = new MapbenderEvent();
+
+/**
+ * Triggered after the map object has been created. 
+ */
+var eventAfterMapObjectConstruction = new MapbenderEvent(); // possibly obsolete!
+
+/**
+ * deprecated wrapped function
+ * @deprecated
+ */
+function mb_registerInitFunctions(stringFunction){
+//	mb_InitFunctions[mb_InitFunctions.length] = stringFunction;
+	eventInit.register(stringFunction);
+}
+
+/**
+ * deprecated wrapped function
+ * @deprecated
+ */
+function mb_registerPreFunctions(stringFunction){
+//	mb_MapRequestPreFunctions[mb_MapRequestPreFunctions.length] = stringFunction;
+	eventBeforeMapRequest.register(stringFunction);
+}
+
+/**
+ * deprecated wrapped function
+ * @deprecated
+ */
+function mb_registerFeatureInfoPreFunctions(stringFunction){
+//	mb_FeatureInfoPreFunctions[mb_FeatureInfoPreFunctions.length] = stringFunction;
+	eventBeforeFeatureInfo.register(stringFunction);
+}
+
+/**
+ * deprecated wrapped function
+ * @deprecated
+ */
+function mb_registerSubFunctions(stringFunction){
+//	mb_MapRequestSubFunctions[mb_MapRequestSubFunctions.length] = stringFunction;
+	eventAfterMapRequest.register(stringFunction);
+}
+
+/**
+ * deprecated wrapped function
+ * @deprecated
+ */
+function mb_registerMapObjectSubFunctions(stringFunction){
+//	mb_MapObjectSubFunctions[mb_MapObjectSubFunctions.length] = stringFunction;
+	eventAfterMapObjectConstruction.register(stringFunction);
+}
+
+/**
+ * deprecated wrapped function
+ * @deprecated
+ */
+function mb_registerGetScalePreFunctions(stringFunction){
+//	mb_GetScalePreFunctions[mb_GetScalePreFunctions.length] = stringFunction;
+	eventBeforeGetScale.register(stringFunction);
+}
+
+/**
+ * deprecated wrapped function
+ * @deprecated
+ */
+function mb_registerloadWmsSubFunctions(stringFunction){
+//	mb_loadWmsSubFunctions[mb_loadWmsSubFunctions.length] = stringFunction;
+	eventAfterLoadWMS.register(stringFunction);
+}
+
+/**
+ * deprecated wrapped function
+ * @deprecated
+ */
+function mb_registerWfsReadSubFunctions(stringFunction){
+	mb_WfsReadSubFunctions[mb_WfsReadSubFunctions.length] = stringFunction;
+}
+
+/**
+ * deprecated wrapped function
+ * @deprecated
+ */
+function mb_registerWfsWriteSubFunctions(stringFunction){
+	mb_WfsWriteSubFunctions[mb_WfsWriteSubFunctions.length] = stringFunction;
+}
+
+/**
+ * deprecated wrapped function
+ * @deprecated
+ */
+function mb_registerL10nFunctions(stringFunction) {
+	eventLocalize.register(stringFunction)
+//	mb_l10nFunctions[mb_l10nFunctions.length] = stringFunction;
+}
+
+var mb_PanSubElements = [];
+function mb_registerPanSubElement(elName){
+	var ind = mb_PanSubElements.length;
+	mb_PanSubElements[ind] = elName;
+}
+
+var mb_vendorSpecific = [];
+function mb_registerVendorSpecific(stringFunction){
+	mb_vendorSpecific[mb_vendorSpecific.length] = stringFunction;
+}
+
+/**
+ * deprecated function for writing content within a tag via innerHTML
+ * @deprecated
+ */
+function writeTag(frameName, elName, tagSource) {
+  if(frameName && frameName !== ""){
+     window.frames[frameName].document.getElementById(elName).innerHTML = tagSource;
+  }
+  else if(!frameName || frameName === ""){
+       document.getElementById(elName).innerHTML = tagSource;
+  }
+}
\ No newline at end of file

Copied: branches/beck_dev/mapbender/lib/event.js (from rev 2450, branches/beck_dev/mapbender/http/javascripts/event.js)
===================================================================
--- branches/beck_dev/mapbender/lib/event.js	                        (rev 0)
+++ branches/beck_dev/mapbender/lib/event.js	2008-05-27 13:37:12 UTC (rev 2473)
@@ -0,0 +1,193 @@
+/**
+ * An event. What happens, when the event occurs, depends on which functions have been
+ * registered with the event. 
+ * 
+ * usage:
+ * 
+ * // create a new Event
+ * var eventAfterMapRequest = new MapbenderEvent(); 
+ * 
+ * // register a function with that event
+ * eventAfterMapRequest.register(function () {
+ * 	...
+ * })
+ * 
+ * // trigger the event
+ * eventAfterMapRequest.trigger();
+ * 
+ */
+var MapbenderEvent = function () {
+	
+	// public methods
+	/**
+	 * A function that needs to be executed, when the event occurs, has to be 
+	 * registered via this function.
+	 */
+	this.register = function(aFunction) {
+
+		var mpbnFunction = new MapbenderFunction(aFunction);
+		functionArray.push(mpbnFunction);
+	};
+
+	/**
+	 * Exclude a previously registered function from the event
+	 */
+	this.unregister = function(aFunction) {
+		for (var i = 0, len = functionArray.length; i < len; i++) {
+			if (functionArray[i].getFunction() === aFunction) {
+				for (var j = i + 1; j < len; j++) {
+					functionArray[j-1] = functionArray[j];
+				}
+				delete functionArray[len - 1];
+				len = len - 1;
+			}
+		}
+		functionArray.length = len;
+	};
+
+	/**
+	 * Checks if a function is already registered with this event
+	 */
+	this.isRegistered = function (aFunction) {
+		for (var i = 0, len = functionArray.length; i < len; i++) {
+			if (functionArray[i].getFunction() === aFunction) {
+				return true;
+			}
+		}
+		return false;
+	};
+	
+	/**
+	 * This function triggers the event
+	 */
+	this.trigger = function(properties, booleanOperator) {
+		if (!(functionArray.length > 0)) {
+			return true;
+		}
+		//
+		// check arguments
+		//
+		// properties
+		if (typeof(properties) != "object") {
+			// maybe properties is missing, and so 
+			// properties represents booleanOperator
+			if (typeof(booleanOperator) == "undefined") {
+				booleanOperator = properties;
+				properties = undefined;
+			}
+			else {
+//				var e = new Mb_exception("MapbenderEvent.trigger: invalid properties: %s", properties);
+			}
+		}		
+
+		// booleanOperator
+		if (typeof(booleanOperator) == "string") {
+			if (booleanOperator != "AND" && booleanOperator != "OR") {
+//				var e = new Mb_exception("MapbenderEvent.trigger: invalid booleanOperator: %s", booleanOperator);
+			}
+		}		
+		else if (typeof(booleanOperator) != "undefined") {
+//			var e = new Mb_exception("MapbenderEvent.trigger: invalid booleanOperator, must be a string, but is %s", typeof(booleanOperator));
+		}
+		
+		var result;
+
+		// the optional boolean operator allows to combine the return values of the functions
+		// into a single result value.
+		switch (booleanOperator) {
+			case "AND":
+				result = true;
+				break;
+			case "OR":
+				result = false;
+				break;
+			default:
+				result = true;
+				break;
+		}
+
+		if (log) {
+			var e = new Mb_notice("functions (after sort): " + functionArray.join(","));
+		}
+
+		for (var i = 0; i < functionArray.length; i++) {
+			// executes the function at position i
+			// and determines the return value based on the (optional) boolean operator
+			switch (booleanOperator) {
+				case "AND":
+					result = result && functionArray[i].execute(properties);
+					break;
+				case "OR":
+					result = result || functionArray[i].execute(properties);
+					break;
+				default:
+					result = functionArray[i].execute(properties);
+					break;
+			}
+		}
+		return result;
+	};	
+	
+	this.getProperties = function () {
+		return propertiesObj;
+	};
+
+	// private
+	/**
+	 * these functions will be executed once the event is triggered
+	 */
+	var functionArray = [];
+	
+	var propertiesObj;
+	var log = false;
+};
+
+/**
+ * A MapbenderFunction is a function with a priority.
+ */
+var MapbenderFunction = function (aFunction) {
+	
+	// public
+	/**
+	 * Returns the function itself
+	 */
+	this.getFunction = function () {
+		return func;
+	};
+	
+	/**
+	 * Executes the function
+	 */
+	this.execute = function (argumentObj) {
+		if (typeof(aFunction) == "function") {
+			return func(argumentObj);
+		}
+
+		// this branch is for backwards compatibility with the 
+		// pre-2.5 event system that is based on strings.
+		else {
+			var argumentNames = [];
+			var argumentValues = [];
+			for (var i in argumentObj) {
+				if (typeof(argumentObj[i]) == "number" || typeof(argumentObj[i]) == "boolean") {
+					argumentNames.push(i);
+					argumentValues.push(argumentObj[i]);
+				}
+				else if (typeof(argumentObj[i]) == "string") {
+					argumentNames.push(i);
+					argumentValues.push("'" + argumentObj[i] + "'");
+				}
+			}
+			var str = "";
+			str += "(function (" + argumentNames.join(", ") + ") {";
+			str += "return " + aFunction;
+			str += "}";
+			str += "(" + argumentValues.join(", ") + "));";
+			var returnValue = eval(str);
+			return returnValue;
+		}	
+	};
+	
+	// private
+	var func = aFunction;
+};
\ No newline at end of file



More information about the Mapbender_commits mailing list