[Mapbender-commits] r4911 - in trunk/mapbender/http: javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Nov 3 11:20:38 EST 2009


Author: christoph
Date: 2009-11-03 11:20:38 -0500 (Tue, 03 Nov 2009)
New Revision: 4911

Modified:
   trunk/mapbender/http/javascripts/mod_loadwmc.js
   trunk/mapbender/http/php/mod_loadwmc_server.php
Log:
refactored

Modified: trunk/mapbender/http/javascripts/mod_loadwmc.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_loadwmc.js	2009-11-03 16:20:03 UTC (rev 4910)
+++ trunk/mapbender/http/javascripts/mod_loadwmc.js	2009-11-03 16:20:38 UTC (rev 4911)
@@ -1,19 +1,18 @@
 // checks if element var loadFromSession exists
-try {
-	if (loadFromSession) {
-	}
+if (typeof options.loadFromSession === undefined) {
+	var loadFromSession = 0;
 }
-catch(e) {
-	loadFromSession = 0;
-}
 
 if (loadFromSession) {
 	// function load_wmc_session() is generated by mod_loadwmc.php
-	mb_registerInitFunctions('load_wmc_session()');
+	Mapbender.events.init.register(function () {
+		load_wmc_session();
+	});
 }
 var wmcPopup = null;
 var wmcDisplayPopup = null;
 var wmcOpenlayersPopup = null;
+var wmcTable;
 
 var serverSideFileName = "../php/mod_loadwmc_server.php";
 
@@ -21,19 +20,35 @@
 	alert(id);
 }
 
+$(this).click(function () {
+	mod_loadwmc();
+}).mouseover(function () {
+	if (options.src) {
+		this.src = options.src.replace(/_off/, "_over");
+	}
+}).mouseout(function () {
+	if (options.src) {
+		this.src = options.src;
+	}
+});
+
 /**
  * is called when the load WMC button is pressed
  */
 function mod_loadwmc(){
 
-	var initialHtml = "<div>" +
-					"<h2 style='font-family: Arial, Helvetica, sans-serif; color: #808080;'><font align='left' color='#000000'>load WMC from list</font></h2>" +
-					"<table id='loadwmc_list' width='90%' style='font-family: Arial, Helvetica, sans-serif;font-size : 12px;color: #808080;' border='1' cellpadding='3' rules='rows'>" +
-						"<tr style='background-color:#F0F0F0;' width='80px'>" +
-							"<td><b>WMC name</b></td>" +
-							"<td><b>last update</b></td>" +
-							"<td colspan=5></td>" +
-						"</tr>" +
+	var initialHtml = "<div id='" + options.id + "_wmclist' >" +
+					"<table id='" + options.id + "_wmclist_table' style='margin:10px 10px 10px 10px' border='1' rules='rows'>" +
+						"<thead><tr>" +
+							"<th>WMC name</td>" +
+							"<th>last update</td>" +
+							"<th>load</td>" +
+							"<th>merge</td>" +
+							"<th>append</td>" +
+							"<th>show</td>" +
+							"<th>OpenLayers</td>" +
+							"<th>delete</td>" +
+						"</thead></tr>" +
 					"</table>" +
 				"</div>";
 
@@ -42,9 +57,9 @@
 	// display and delete WMC documents
 	if (wmcPopup === null) {
 		wmcPopup = new mb_popup({
-			title:"Load WMC",
-			width:500,
-			height:600,
+			title:options.currentTitle,
+			width:700,
+			height:500,
 			top:100,
 			left:100,
 			html:initialHtml
@@ -57,258 +72,216 @@
 		wmcPopup.show();
 		
 	}
+/*
+	$(initialHtml).appendTo("body");
+	Mapbender.modules.ui_widget.create({
+		target: options.id + "_wmclist",
+		title: "load WMC from list"
+	});
+*/
 
+
 	// 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);
+	var req = new Mapbender.Ajax.Request({
+		url: serverSideFileName,
+		method: "getWmc",
+		callback: function(obj, result, message){
+			if (!result) {
+				new Mb_exception(obj.message);
+				return;
+			}
+			displayWmcList(obj, status);
 		}
-		if (loadWmcDataError) {
-			alert("An error has occured. WMC list could not be loaded.");
-		}
 	});
+	req.send();
 }
 
 /**
  * Displays available WMC documents
  */
-function displayWmcList (json, status) {
-	var wmcObj = eval("(" + json + ")");
-
+function displayWmcList (wmcObj, status) {
 	//
 	// for each wmc, add a row to the table
 	//
 	for (var i=0; i < wmcObj.wmc.length; i++) {
 		(function () {
 			var currentId = wmcObj.wmc[i].id;
-			var $tr = $("<tr onmouseover='this.style.backgroundColor = \"#F08080\"' onmouseout='this.style.backgroundColor = \"#ffffff\"'></tr>").appendTo($("#loadwmc_list"));
-			$tr.hide();
+			var $tr = $("<tr></tr>").appendTo($("#" + options.id + "_wmclist_table"));
 			var $td;
-			
 			$tr.append($("<td>" + wmcObj.wmc[i].title + "</td>"));
 			$tr.append($("<td>" + wmcObj.wmc[i].timestamp + "</td>"));
 
-			// 
 			// Load WMC
-			//
-			var $loadWmc = $("<img src='../img/button_gray/wmc_load.png' style='cursor:pointer' title='load this WMC'>");
-			$loadWmc.click(function() {
-				var queryObj = {command:"loadWmc", parameters:{id:currentId}};
-				$.post(serverSideFileName, {queryObj: $.toJSON(queryObj)}, function (json, status) {
-					var loadWmcError = false;
-					if (json && status == "success") {
-						var resultObj = eval("(" + json + ")");
-						try {
-							if (resultObj.javascript && typeof(resultObj.javascript) == "object") {
-								for (var j=0; j < resultObj.javascript.length; j++) {
-//									var e = new Mb_notice("Statement: " + resultObj.javascript[j]);
-									eval(resultObj.javascript[j]);
-								}
-							}	
-						}
-						catch (e) {
-							alert(e);
-							loadWmcError = true;
-						}
-					}
-					if (loadWmcError) {
-						alert("An error has occured while loading this WMC.");
-					}
-					else {
-						// close the Pop up
-						if (wmcDisplayPopup !== null && wmcDisplayPopup.isVisible()) {
-							wmcDisplayPopup.hide();
-						}
-						wmcPopup.hide();
-						alert("WMC has been loaded successfully.");
-					}
-				});
+			var $loadTd = appendTableCell({
+				src: "../img/button_gray/wmc_load.png",
+				title: "load this WMC",
+				method: "loadWmc",
+				message: "WMC has been loaded successfully.",
+				parameters: {
+					id:currentId
+				},
+				callback: executeJavaScript
 			});
-			$td = $("<td></td>").append($loadWmc);
-			$tr.append($td);				
+			$tr.append($loadTd);				
 
-			// 
 			// Merge WMC
-			//
-			var $mergeWmc = $("<img src='../img/button_gray/wmc_merge.png' style='cursor:pointer' 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.");
-					}
-				});
+			var $mergeTd = appendTableCell({
+				src: "../img/button_gray/wmc_merge.png",
+				title: "merge WMC",
+				method: "mergeWmc",
+				message: "WMC has been merged successfully.",
+				parameters:{
+					id:currentId, 
+					extensionData:currentWmcExtensionData !== null ?
+						currentWmcExtensionData : null, 
+					mapObject:mb_mapObj,
+					generalTitle:"currentState"
+				},
+				callback: executeJavaScript
 			});
-			$td = $("<td></td>").append($mergeWmc);
-			$tr.append($td);				
+			$tr.append($mergeTd);				
 
-			// 
 			// Append WMC
-			//
-			var $appendWmc = $("<img src='../img/button_gray/wmc_append.png' style='cursor:pointer' 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"
+			var $appendTd = appendTableCell({
+				src: "../img/button_gray/wmc_append.png",
+				title: "append WMC",
+				method: "appendWmc",
+				message: "WMC has been appended successfully.",
+				parameters:{
+					id:currentId, 
+					extensionData:currentWmcExtensionData !== null ?
+						currentWmcExtensionData : null,
+					mapObject:mb_mapObj,
+					generalTitle:"currentState"
+				},
+				callback: executeJavaScript
+			});
+			$tr.append($appendTd);				
+
+			// Display WMC
+			var $displayTd = appendTableCell({
+				src: "../img/button_gray/wmc_xml.png",
+				title: "display WMC XML",
+				callback: function() {
+					// create Popup
+					if (wmcDisplayPopup === null) {
+						wmcDisplayPopup = new mb_popup({
+							title:"WMC Document",
+							width:600,
+							height:500,
+							top:100,
+							left:300,
+							url:"../javascripts/mod_displayWmc.php?wmc_id=" + currentId
+						});
 					}
-				};
-				$.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;
-						}
+					// set correct URL
+					if (wmcDisplayPopup.isVisible()) {
+						wmcDisplayPopup.setUrl("../javascripts/mod_displayWmc.php?wmc_id=" + currentId + "&" + mb_session_name + "=" + mb_nr);
 					}
-					if (loadWmcError) {
-						alert("An error has occured while loading this WMC.");
+					// display the pop up
+					wmcDisplayPopup.show();
+				}
+			});
+			$tr.append($displayTd);	
+			
+			// OpenLayers Export
+			var $openLayersTd = appendTableCell({
+				src: "../img/OpenLayers.trac.png",
+				title: "export to OpenLayers",
+				callback: function () {
+					// create Popup
+					if (wmcOpenlayersPopup === null) {
+						wmcOpenlayersPopup = new mb_popup({
+							title: "WMC Document",
+							width: 600,
+							height: 500,
+							top: 100,
+							left: 300,
+							url: "../php/mod_wmc2ol.php?wmc_id=" + currentId + 
+								"&" + mb_session_name + "=" + mb_nr
+						});
 					}
-					else {
-						// close the Pop up
-						if (wmcDisplayPopup !== null && wmcDisplayPopup.isVisible()) {
-							wmcDisplayPopup.hide();
-						}
-						wmcPopup.hide();
-						alert("WMC has been loaded successfully.");
+					// set correct URL
+					if (wmcOpenlayersPopup.isVisible()) {
+						wmcOpenlayersPopup.setUrl("../php/mod_wmc2ol.php?wmc_id=" + currentId + "&" + mb_session_name + "=" + mb_nr);
 					}
-				});
-			});
-			$td = $("<td></td>").append($appendWmc);
-			$tr.append($td);				
-
-			// 
-			// Display WMC
-			//
-			var $displayWmc = $("<img src='../img/button_gray/wmc_xml.png' style='cursor:pointer' title='display WMC XML'>");
-			$displayWmc.click(function() {
-				// create Popup
-				if (wmcDisplayPopup === null) {
-					wmcDisplayPopup = new mb_popup({
-						title:"WMC Document",
-						width:600,
-						height:500,
-						top:100,
-						left:300,
-						url:"../javascripts/mod_displayWmc.php?wmc_id=" + currentId
-					});
+					// display the pop up
+					wmcOpenlayersPopup.show();
 				}
-				// set correct URL
-				if (wmcDisplayPopup.isVisible()) {
-					wmcDisplayPopup.setUrl("../javascripts/mod_displayWmc.php?wmc_id=" + currentId + "&" + mb_session_name + "=" + mb_nr);
-				}
-				// display the pop up
-				wmcDisplayPopup.show();
 			});
-			$td = $("<td></td>").append($displayWmc);
-			$tr.append($td);				
+			$tr.append($openLayersTd);	
 
-			//
-			// OpenLayers Export
-			//
-			var imgHtml = "<img src='../img/OpenLayers.trac.png' style='cursor:pointer' " + 
-				"title='export to OpenLayers' border=0>";
-			var $openlayersWmc = $(imgHtml);
-			$openlayersWmc.click(function () {
-				// create Popup
-				if (wmcOpenlayersPopup === null) {
-					wmcOpenlayersPopup = new mb_popup({
-						title:"WMC Document",
-						width:600,
-						height:500,
-						top:100,
-						left:300,
-						url:"../php/mod_wmc2ol.php?wmc_id=" + currentId + 
-							"&" + mb_session_name + "=" + mb_nr
-					});
+			// delete WMC
+			var $deleteTd = appendTableCell({
+				src: "../img/button_gray/del.png",
+				title: "delete this WMC",
+				method: "deleteWmc",
+				callback: executeJavaScript,
+				parameters:{
+					id:currentId
 				}
-				// set correct URL
-				if (wmcOpenlayersPopup.isVisible()) {
-					wmcOpenlayersPopup.setUrl("../php/mod_wmc2ol.php?wmc_id=" + currentId + "&" + mb_session_name + "=" + mb_nr);
-				}
-				// display the pop up
-				wmcOpenlayersPopup.show();
 			});
-			$td = $("<td></td>").append($openlayersWmc);
-			$tr.append($td);
+			$tr.append($deleteTd);	
+		}());
+	}
 
-			var $deleteWmc = $("<img src='../img/button_gray/del.png' style='cursor:pointer' 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();
-							}	
+	wmcTable = $("#" + options.id + "_wmclist_table").dataTable({
+		"bPaginate": true,
+		"bLengthChange": false,
+		"bFilter": false,
+		"bSort": false,
+		"bInfo": false,
+		"bAutoWidth": false
+	});
+
+}
+
+function executeJavaScript (args) {
+	var req = new Mapbender.Ajax.Request({
+		url: serverSideFileName,
+		method: args.method, // loadWmc
+		parameters: args.parameters,
+		callback: function (obj, result, message) {
+			if (!result) {
+				new Mb_warning(message);
+				return;
+			}
+			try {
+				if (args.method === "deleteWmc") {
+					
+				}
+				else {
+					if (obj.javascript && typeof(obj.javascript) == "object") {
+						for (var j = 0; j < obj.javascript.length; j++) {
+//							var e = new Mb_notice("Statement: " + obj.javascript[j]);
+							eval(obj.javascript[j]);
 						}
-						catch (e) {
-							deleteWmcError = true;
-						}
+					}	
+					// close the Pop ups
+					if (wmcDisplayPopup !== null && wmcDisplayPopup.isVisible()) {
+						wmcDisplayPopup.hide();
 					}
-					if (deleteWmcError) {
-						alert("An error has occured while deleting this WMC.");
-					}
-				});
-			});
-			$td = $("<td></td>").append($deleteWmc);
-			$tr.append($td);
+					wmcPopup.hide();
+					new Mb_notice(args.message);
+					
+				}
+				
+			}
+			catch (e) {
+				new Mb_exception(e.message);
+			}
+		}
+	});
+	req.send();
+	
+}
 
-			$tr.fadeIn("slow");
-		}());
-	}
+function appendTableCell (args) {
+	var $img = $("<img src='" + args.src + "' style='cursor:pointer' " + 
+		"class='ui-icon' title='" + args.title + "'>");
+	$img.click(function() {
+		args.callback(args);
+	});
+	return $("<td></td>").append($img);
+	
 }

Modified: trunk/mapbender/http/php/mod_loadwmc_server.php
===================================================================
--- trunk/mapbender/http/php/mod_loadwmc_server.php	2009-11-03 16:20:03 UTC (rev 4910)
+++ trunk/mapbender/http/php/mod_loadwmc_server.php	2009-11-03 16:20:38 UTC (rev 4911)
@@ -1,194 +1,90 @@
 <?php
-require_once(dirname(__FILE__) . "/../php/mb_validateSession.php");
+require_once(dirname(__FILE__) . "/../../core/globalSettings.php");
 require_once(dirname(__FILE__) . "/../classes/class_user.php");
 require_once(dirname(__FILE__) . "/../classes/class_wmc.php");
 require_once(dirname(__FILE__) . "/../classes/class_wmcToXml.php");
 require_once(dirname(__FILE__) . "/../classes/class_json.php");
 require_once(dirname(__FILE__) . "/../classes/class_administration.php");
 
-/**
- * encodes and delivers the data
- * 
- * @param object the un-encoded object 
- */
-function sendOutput($out){
-	global $json;
-	$output = $json->encode($out);
-	if (CHARSET == "ISO-8859-1") {
-		$output = utf8_decode($output);
-	}
-	header("Content-Type: text/x-json");
-	echo $output;
-}
+$ajaxResponse = new AjaxResponse($_POST);
 
-/**
- * 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 = "";
+$userId = Mapbender::session()->get("mb_user_id");
+$currentUser = new User($userId);
 
-	for ($i = 0; $i < count($wmcIdArray); $i++) {
-		if ($i > 0) { 
-			$wmcIdList .= ",";
-		}
-		$wmcIdList .= "$".($i+1);
-		array_push($v, $wmcIdArray[$i]);
-		array_push($t, 's');
-	}
+$wmc = new wmc();
 
-	if ($wmcIdList !== "") {
-		$sql = "SELECT DISTINCT wmc_id, wmc_title, wmc_timestamp FROM mb_user_wmc ";
-		$sql .= "WHERE wmc_id IN (" . $wmcIdList . ") ";
-		$sql .=	"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"] = administration::convertIncomingString($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($_REQUEST['queryObj']);
 $resultObj = array();
 
-$e = new mb_exception("command: " . $queryObj->command);
+switch ($ajaxResponse->getMethod()) {
 
-$wmc = new wmc();
-$userId = Mapbender::session()->get("mb_user_id");
-
-switch($queryObj->command){
-
 	// gets available WMCs
-	case 'getWmc':
-		$resultObj["wmc"] = getWmc();
+	case "getWmc":
+		$resultObj["wmc"] = $wmc->selectByUser($currentUser);
+		$ajaxResponse->setResult($resultObj);
+		$ajaxResponse->setSuccess(true);		
 	break;
 
 	// gets XML document of a WMC
-	case 'getWmcDocument':
-		$wmcId = $queryObj->parameters->id;
+	case "getWmcDocument":
+		$wmcId = $ajaxResponse->getParameter("id");
 		$doc = $wmc->getDocument($wmcId);
 		if (!$doc) {
-			$resultObj["error"] = "The WMC document could not be found.";
+			$ajaxResponse->setMessage(_mb("The WMC document could not be found."));
+			$ajaxResponse->setSuccess(false);
 		}
 		else {
 			$resultObj["wmc"] = array("document" => $doc);
+			$ajaxResponse->setResult($resultObj);
+			$ajaxResponse->setSuccess(true);		
 		}
 	break;
 
 	// deletes a WMC
-	case 'deleteWmc':
-		$wmcId = $queryObj->parameters->id;
-		if ($wmc->delete($wmcId,$userId)) {
-			$resultObj["success"] = "WMC has been deleted from the database.";
+	case "deleteWmc":
+		$wmcId = $ajaxResponse->getParameter("id");
+		if ($wmc->delete($wmcId, $userId)) {
+			$ajaxResponse->setMessage(_mb("WMC has been deleted from the database."));
+			$ajaxResponse->setSuccess(true);
 		}
 		else {
-			$resultObj["error"] = "WMC could not be deleted.";
+			$ajaxResponse->setMessage(_mb("WMC could not be deleted."));
+			$ajaxResponse->setSuccess(false);
 		}
 	break;
 	
 	// loads a WMC (returns array of JS code)
 	case 'loadWmc':
-		$wmcId = $queryObj->parameters->id;
+		$wmcId = $ajaxResponse->getParameter("id");
         $wmc->createFromDb($wmcId);
-        
-        $query_mbWMSId = "/wmc:ViewContext/wmc:LayerList/wmc:Layer/wmc:Extension/mapbender:wms_id";
-            
-        try{
-          $WMCDoc = DOMDocument::loadXML($wmc->toXml());
-        } catch (Exception $E) {
-          echo "WMC XML is broken";
-        }   
 
-        $xpath = new DOMXPath($WMCDoc);
-        $xpath->registerNamespace("wmc","http://www.opengis.net/context");
-        $xpath->registerNamespace("mapbender","http://www.mapbender.org/context");
-        $xpath->registerNamespace("xlink","http://www.w3.org/1999/xlink");
-
-        $WMSIdList = $xpath->query($query_mbWMSId);
-        foreach($WMSIdList as $WMSId)
-        {
-          $id =  $WMSId->nodeValue;
-          $sql = "SELECT wms_timestamp,wms_getmap,wms_getlegendurl FROM wms WHERE wms_id = $1";
-          $v = array($id);
-          $t = array("t");
-            
-          $res = db_prep_query($sql,$v,$t);
-          if(db_error()){true; } //FIMXE: PROPER ERROR MESSAGE
-          
-          if($row = db_fetch_row($res))
-          {
-            $wms_timestamp = $row[0];
-            if($wmc->timestamp < $wms_timestamp)
-            {
-              // wmc is fresh, life is good
-            }else{
-
-              $MapResources = $xpath->query("../../wmc:Server/wmc:OnlineResource",$WMSId);
-              foreach($MapResources as $MapResource)
-              {
-                $MapResource->setAttribute("xlink:href",$row[1]);
-              }
-
-              $LegendResources = $xpath->query("../../wmc:StyleList/wmc:Style/wmc:LegendURL/wmc:OnlineResource",$WMSId);
-              foreach($LegendResources as $LegendResource)
-              {
-                $base = $row[2];
-                $origurl = explode('&', $LegendResource->getAttribute("xlink:href"),2);
-                $url = $base . $origurl[1]; 
-                $LegendResource->setAttribute("xlink:href",$url);
-              }
-            
-
-            }
-
-
-          }
-      
-        }
-        $updatedWMC = $WMCDoc->saveXML();
-        $wmc->update_exisiting($updatedWMC,$wmsId);
+		// FIXME: maybe wrap in if condition (configurable by element vars)
+		$updatedWMC = $wmc->updateUrlsFromDb();
         $wmc->createFromXml($updatedWMC);
 		
         $jsArray = $wmc->toJavaScript();
 		if ($jsArray) {
 			$resultObj["javascript"] = $jsArray;
+			$ajaxResponse->setResult($resultObj); 
+			$ajaxResponse->setSuccess(true);
 		}
 		else {
-			$resultObj["error"] = "WMC could not be loaded.";
+			$ajaxResponse->setMessage(_mb("WMC could not be loaded."));
+			$ajaxResponse->setSuccess(false);
 		}
 	break;
 
 	// merges data with WMC and loads it (returns array of JS code)
-	case 'mergeWmc':
-		$params = $queryObj->parameters;
-		
+	case "mergeWmc":
 		// generate a WMC for the current client state
 		$currentWmc = new wmc();
-		$currentWmc->createFromJs($params->mapObject, $params->generalTitle, $params->extensionData);
+		$currentWmc->createFromJs(
+			$ajaxResponse->getParameter("mapObject"), 
+			$ajaxResponse->getParameter("generalTitle"), 
+			$ajaxResponse->getParameter("extensionData")
+		);
 
 		// get the desired WMC from the database
-		$wmcId = $queryObj->parameters->id;
+		$wmcId = $ajaxResponse->getParameter("id");
 		$wmcXml = wmc::getDocument($wmcId);
 
 		// merge the two WMCs
@@ -199,21 +95,27 @@
 
 		if (is_array($jsArray) && count($jsArray) > 0) {
 			$resultObj["javascript"] = $jsArray;
+			$ajaxResponse->setResult($resultObj); 
+			$ajaxResponse->setSuccess(true);
 		}
 		else {
-			$resultObj["error"] = "WMC could not be loaded.";
+			$ajaxResponse->setMessage(_mb("WMC could not be merged."));
+			$ajaxResponse->setSuccess(false);
 		}
 	break;
 	
 	// appends a WMC (returns JS code)
 	case 'appendWmc':
-		$params = $queryObj->parameters;
 		// generate a WMC for the current client state
 		$currentWmc = new wmc();
-		$currentWmc->createFromJs($params->mapObject, $params->generalTitle, $params->extensionData);
+		$currentWmc->createFromJs(
+			$ajaxResponse->getParameter("mapObject"), 
+			$ajaxResponse->getParameter("generalTitle"), 
+			$ajaxResponse->getParameter("extensionData")
+		);
 
 		// get the desired WMC from the database
-		$wmcId = $queryObj->parameters->id;
+		$wmcId = $ajaxResponse->getParameter("id");
 		$wmcXml = wmc::getDocument($wmcId);
 
 		// merge the two WMCs
@@ -224,17 +126,21 @@
 
 		if (is_array($jsArray) && count($jsArray) > 0) {
 			$resultObj["javascript"] = $jsArray;
+			$ajaxResponse->setResult($resultObj); 
+			$ajaxResponse->setSuccess(true);
 		}
 		else {
-			$resultObj["error"] = "WMC could not be appended.";
+			$ajaxResponse->setMessage(_mb("WMC could not be appended."));
+			$ajaxResponse->setSuccess(false);		
 		}
 	break;
 	
 
 	// Invalid command
 	default:
-		$resultObj["error"] = "no action specified...";
+		$ajaxResponse->setMessage(_mb("No method specified."));
+		$ajaxResponse->setSuccess(false);		
 }
 
-sendOutput($resultObj);
-?>
+$ajaxResponse->send();
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list