[Mapbender-commits] r8491 - in branches/2.7/http: classes javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Sep 18 08:11:06 PDT 2012


Author: verenadiewald
Date: 2012-09-18 08:11:04 -0700 (Tue, 18 Sep 2012)
New Revision: 8491

Modified:
   branches/2.7/http/classes/class_administration.php
   branches/2.7/http/javascripts/initWmcObj.php
   branches/2.7/http/php/mod_deleteWMS.php
   branches/2.7/http/php/mod_editGuiWms.php
   branches/2.7/http/php/mod_loadCapabilitiesList.php
   branches/2.7/http/php/mod_loadwms.php
   branches/2.7/http/php/mod_updateWMS.php
Log:
included a caching mechanism as a workarounf for performance problems in applications with lots of WMS included

Modified: branches/2.7/http/classes/class_administration.php
===================================================================
--- branches/2.7/http/classes/class_administration.php	2012-09-18 15:09:37 UTC (rev 8490)
+++ branches/2.7/http/classes/class_administration.php	2012-09-18 15:11:04 UTC (rev 8491)
@@ -1529,5 +1529,13 @@
 			": saveAsFile(): saving RSS at " . $fullFilename);
 		return true;		
 	} 
+	
+	function clearJsCacheFile($selectedGui){
+	    $fileName = md5($selectedGui);
+        $applicationLoadFile = "../../cache/".$fileName.".app.cache.js";
+        if(file_exists($applicationLoadFile)) {
+	        unlink($applicationLoadFile);        	
+        }
+	}
 }
 ?>

Modified: branches/2.7/http/javascripts/initWmcObj.php
===================================================================
--- branches/2.7/http/javascripts/initWmcObj.php	2012-09-18 15:09:37 UTC (rev 8490)
+++ branches/2.7/http/javascripts/initWmcObj.php	2012-09-18 15:11:04 UTC (rev 8491)
@@ -56,488 +56,570 @@
 $wmc = new wmc();
 
 $app = Mapbender::session()->get("mb_user_gui");
-//$wmcDocSession = Mapbender::session()->get("mb_wmc");
 
-$wmcDocSession = false;
-if(Mapbender::session()->get("mb_wmc")) {
-    $wmc_filename = Mapbender::session()->get("mb_wmc");
-    $wmcDocSession = file_get_contents($wmc_filename);
-}
+//check for caching element var for mapframe1
+$sql = "SELECT * from gui_element_vars WHERE fkey_gui_id = $1 AND fkey_e_id = 'mapframe1' AND var_name = 'loadFromCache'; ";
+$v = array($app);
+$t = array("s", "s");
+$res = db_prep_query($sql, $v, $t);
 
-
-try {
-	$loadFromSession = new ElementVar($app, "loadwmc", "loadFromSession");
-	if ($wmcDocSession && $loadFromSession->value === "1") {
-	//check if session contains a wmc,
-	//otherwise create a new wmc from application
-		$e = new mb_notice("trying to load session WMC...");
-		if (!$wmc->createFromXml($wmcDocSession)) {
-			$e = new mb_notice("loading session WMC failed.");
-			$e = new mb_notice("creating wmc from app: " . $app);
-			$wmc->createFromApplication($app);
-		}
+if ($row = db_fetch_array($res)) {
+	if($row["var_value"] == 1) {
+	    $activateCache = true;
 	}
 	else {
-		$e = new mb_notice("loading from session WMC disabled in loadwmc or no session WMC set.");
-		$e = new mb_notice("creating wmc from app: " . $app);
-		$wmc->createFromApplication($app);
+	    $activateCache = false;
 	}
 }
-catch (Exception $e) {
-	$e = new mb_notice("creating wmc from app: " . $app);
-	$wmc->createFromApplication($app);
+else {
+	 $activateCache = false;
 }
 
-//
-// create new WMC with services from GET API
-//
-$wmcGetApi = WmcFactory::createFromXml($wmc->toXml());
+$fileName = md5($app);
+$applicationLoadFile = "../../cache/".$fileName.".app.cache.js";
 
-$options = array();
-if (Mapbender::session()->exists("addwms_showWMS")) {
-	$options["show"] = intval(Mapbender::session()->get("addwms_showWMS"));
+//if there is no GET param from outside and the cache file for gui loading exists, load outputstring from file
+if($activateCache && !Mapbender::session()->get("mb_wmc") &&
+     !getConfiguration("WMC") && 
+     !getConfiguration("WMS") &&
+     !getConfiguration("LAYER") &&
+     !getConfiguration("FEATURETYPE") &&
+     !getConfiguration("GEORSS") && 
+     file_exists($applicationLoadFile)
+     ) {
+    $outputString = file_get_contents($applicationLoadFile);
 }
-if (Mapbender::session()->exists("addwms_zoomToExtent")) {
-	$options["zoom"] = !!Mapbender::session()->get("addwms_zoomToExtent");
-}
+else {
+    $wmcDocSession = false;
+    if(Mapbender::session()->get("mb_wmc")) {
+        $wmc_filename = Mapbender::session()->get("mb_wmc");
+        $wmcDocSession = file_get_contents($wmc_filename);
+    }
 
-$getParams = array(
-	"WMC" => getConfiguration("WMC"),
-	"WMS" => getConfiguration("WMS"),
-	"LAYER" => getConfiguration("LAYER"),
-	"FEATURETYPE" => getConfiguration("FEATURETYPE"),
-	"GEORSS"=>getConfiguration("GEORSS")
-);
-$getApi = new GetApi($getParams);
 
-//
-// WMC
-//
-$inputWmcArray = $getApi->getWmc();
+    try {
+    	$loadFromSession = new ElementVar($app, "loadwmc", "loadFromSession");
+    	if ($wmcDocSession && $loadFromSession->value === "1") {
+    	//check if session contains a wmc,
+    	//otherwise create a new wmc from application
+    		$e = new mb_notice("trying to load session WMC...");
+    		if (!$wmc->createFromXml($wmcDocSession)) {
+    			$e = new mb_notice("loading session WMC failed.");
+    			$e = new mb_notice("creating wmc from app: " . $app);
+    			$wmc->createFromApplication($app);
+    		}
+    	}
+    	else {
+    		$e = new mb_notice("loading from session WMC disabled in loadwmc or no session WMC set.");
+    		$e = new mb_notice("creating wmc from app: " . $app);
+    		$wmc->createFromApplication($app);
+    	}
+    }
+    catch (Exception $e) {
+    	$e = new mb_notice("creating wmc from app: " . $app);
+    	$wmc->createFromApplication($app);
+    }
 
-if ($inputWmcArray) {
-	foreach ($inputWmcArray as $input) {
-	// just make it work for a single Wmc
-		try {
-			$wmcGetApi = WmcFactory::createFromDb($input["id"]);
-			//update urls from wmc with urls from database if id is given 
-			$updatedWMC = $wmcGetApi->updateUrlsFromDb();
-	        	$wmcGetApi->createFromXml($updatedWMC);
-			//increment load count
-			$wmcGetApi->incrementWmcLoadCount();
-		}
-		catch (Exception $e) {
-			new mb_exception("Failed to load WMC from DB. Keeping original WMC.");
-		}
-	}
-}
+    //
+    // create new WMC with services from GET API
+    //
+    $wmcGetApi = WmcFactory::createFromXml($wmc->toXml());
+    
+    $options = array();
+    if (Mapbender::session()->exists("addwms_showWMS")) {
+    	$options["show"] = intval(Mapbender::session()->get("addwms_showWMS"));
+    }
+    if (Mapbender::session()->exists("addwms_zoomToExtent")) {
+    	$options["zoom"] = !!Mapbender::session()->get("addwms_zoomToExtent");
+    }
+    
+    $getParams = array(
+    	"WMC" => getConfiguration("WMC"),
+    	"WMS" => getConfiguration("WMS"),
+    	"LAYER" => getConfiguration("LAYER"),
+    	"FEATURETYPE" => getConfiguration("FEATURETYPE"),
+    	"GEORSS"=>getConfiguration("GEORSS")
+    );
+    $getApi = new GetApi($getParams);
 
-//
-// WMS
-//
-if ($getParams['WMS']) {
-// WMS param given as array
-	if (is_array($getParams['WMS'])) {
-		$inputWmsArray = $getParams['WMS'];
-	}
-	// WMS param given as comma separated list
-	else {
-		$inputWmsArray = split(",",$getParams['WMS']);
-	}
+    //
+    // WMC
+    //
+    $inputWmcArray = $getApi->getWmc();
+    
+    if ($inputWmcArray) {
+    	foreach ($inputWmcArray as $input) {
+    	// just make it work for a single Wmc
+    		try {
+    			$wmcGetApi = WmcFactory::createFromDb($input["id"]);
+    			//update urls from wmc with urls from database if id is given 
+    			$updatedWMC = $wmcGetApi->updateUrlsFromDb();
+    	        	$wmcGetApi->createFromXml($updatedWMC);
+    			//increment load count
+    			$wmcGetApi->incrementWmcLoadCount();
+    		}
+    		catch (Exception $e) {
+    			new mb_exception("Failed to load WMC from DB. Keeping original WMC.");
+    		}
+    	}
+    }
 
-	$wmsArray = array();
-	$singleAssocArray = array();
-	$multipleAssocArray = array();
+    //
+    // WMS
+    //
+    if ($getParams['WMS']) {
+    // WMS param given as array
+    	if (is_array($getParams['WMS'])) {
+    		$inputWmsArray = $getParams['WMS'];
+    	}
+    	// WMS param given as comma separated list
+    	else {
+    		$inputWmsArray = split(",",$getParams['WMS']);
+    	}
+    
+    	$wmsArray = array();
+    	$singleAssocArray = array();
+    	$multipleAssocArray = array();
+    
+    	foreach ($inputWmsArray as $key=>$val) {
+    		if (is_array($val)) {
+    			foreach ($val as $attr=>$value) {
+    				$multipleAssocArray[$attr] = $value;
+    			}
+    			//get WMS by ID with settings of given application
+    			if (array_key_exists('application', $multipleAssocArray) &&
+    				array_key_exists('id', $multipleAssocArray)) {
+    				$currentWms = new wms();
+    				$currentWms->createObjFromDB(
+    					$multipleAssocArray['application'],
+    					$multipleAssocArray['id']
+    				);
+    			}
+    			//get WMS by URL
+    			elseif (array_key_exists('url', $multipleAssocArray)) {
+    				$currentWms = new wms();
+    				$currentWms->createObjFromXML($multipleAssocArray['url']);
+    			}
+    			else {
+    				continue;
+    			}
+    			array_push($wmsArray, $currentWms);
+    
+    			$options['visible'] = $multipleAssocArray['visible'] === "1" ?
+    				true : false;
+    
+    			$options['zoom'] = $multipleAssocArray['zoom'] === "1" ?
+    				true : false;
+    
+    			$wmcGetApi->mergeWmsArray($wmsArray, $options);
+    			$wmsArray = array();
+    			$multipleAssocArray = array();
+    		}
+    		else {
+    			$currentWms = new wms();
+    			if(is_numeric($key)) {
+    				//get WMS by ID
+    				if (is_numeric($val)) {
+    					$currentWms->createObjFromDBNoGui($val);
+    				}
+    				//get WMS by URL
+    				else if (is_string($val)) {
+    					$currentWms->createObjFromXML($val);
+    				}
+    				array_push($wmsArray, $currentWms);
+    				$wmcGetApi->mergeWmsArray($wmsArray);
+    				$wmsArray = array();
+    			}
+    			else {
+    				$singleAssocArray[$key] = $val;
+    			}
+    		}
+    	}
+    
+    	//get WMS by ID with settings of given application
+    	if (array_key_exists('application', $singleAssocArray) &&
+    		array_key_exists('id', $singleAssocArray)) {
+    		$currentWms = new wms();
+    		$currentWms->createObjFromDB(
+    			$singleAssocArray['application'],
+    			$singleAssocArray['id']
+    		);
+    		array_push($wmsArray, $currentWms);
+    		$options['visible'] = $singleAssocArray['visible'] === "1" ?
+    			true : false;
+    
+    		$options['zoom'] = $singleAssocArray['zoom'] === "1" ? true : false;
+    
+    		$wmcGetApi->mergeWmsArray($wmsArray, $options);
+    		$wmsArray = array();
+    		$singleAssocArray = array();
+    	}
+    	//get WMS by URL
+    	elseif (array_key_exists('url', $singleAssocArray)) {
+    		$currentWms = new wms();
+    		$currentWms->createObjFromXML($singleAssocArray['url']);
+    		array_push($wmsArray, $currentWms);
+    		if($singleAssocArray['visible']) {
+    			$options['visible'] = $singleAssocArray['visible'] === "1" ?
+    				true : false;
+    		}
+    		if($singleAssocArray['zoom']) {
+    			$options['zoom'] = $singleAssocArray['zoom'] === "1" ?
+    				true : false;
+    		}
+    		$wmcGetApi->mergeWmsArray($wmsArray, $options);
+    		$wmsArray = array();
+    		$singleAssocArray = array();
+    	}
+    }
 
-	foreach ($inputWmsArray as $key=>$val) {
-		if (is_array($val)) {
-			foreach ($val as $attr=>$value) {
-				$multipleAssocArray[$attr] = $value;
-			}
-			//get WMS by ID with settings of given application
-			if (array_key_exists('application', $multipleAssocArray) &&
-				array_key_exists('id', $multipleAssocArray)) {
-				$currentWms = new wms();
-				$currentWms->createObjFromDB(
-					$multipleAssocArray['application'],
-					$multipleAssocArray['id']
-				);
-			}
-			//get WMS by URL
-			elseif (array_key_exists('url', $multipleAssocArray)) {
-				$currentWms = new wms();
-				$currentWms->createObjFromXML($multipleAssocArray['url']);
-			}
-			else {
-				continue;
-			}
-			array_push($wmsArray, $currentWms);
+    //
+    // LAYER
+    //
+    
+    $inputLayerArray = $getApi->getLayers();
+    if ($inputLayerArray) {
+    	foreach ($inputLayerArray as $input) {
+    	// just make it work for a single layer id
+    		$wmsFactory = new UniversalWmsFactory();
+    		try {
+    			if (isset($input["application"])) {
+    				$wms = $wmsFactory->createLayerFromDb(
+    					$input["id"], $input["application"]
+    				);
+    			}
+    			else {
+    				$wms = $wmsFactory->createLayerFromDb($input["id"]);
+    			}
+    		}
+    		catch (AccessDeniedException $e) {
+    			$resultObj["noPermission"]["wms"][] = array(
+    				"title" => $admin->getLayerTitleByLayerId($input["id"]),
+    				"id" => $input["id"]
+    			);
+    		}
+    
+    		if (is_a($wms, "wms")) {
+    			$options = array();
+    			if ($input["visible"]) {
+    			// this is a hack for the time being:
+    			// make WMS visible if it has less than 100000 layers
+    				$options["show"] = 100000;
+    			}
+    			if (isset($input["querylayer"])) {
+    				$options["querylayer"] = $input["querylayer"];
+    			}
+    			$wmcGetApi->mergeWmsArray(array($wms), $options);
+    
+    			// do not use "zoom" attribute of mergeWmsArray,
+    			// as this would zoom to the entre WMS.
+    			// Here we set extent to the layer extent only.
+    			if ($input["zoom"]) {
+    				$bboxArray = array();
+    				try {
+    					$layer = $wms->getLayerById(intval($input["id"]));
+    					for ($i = 0; $i < count($layer->layer_epsg); $i++) {
+    						$bboxArray[]= Mapbender_bbox::createFromLayerEpsg(
+    							$layer->layer_epsg[$i]
+    						);
+    					}
+    					$wmcGetApi->mainMap->mergeExtent($bboxArray);
+    				}
+    				catch (Exception $e) {
+    
+    				}
+    			}
+    
+    		}
+    	}
+    }
 
-			$options['visible'] = $multipleAssocArray['visible'] === "1" ?
-				true : false;
+    //
+    // FEATURETYPE
+    //
+    $inputFeaturetypeArray = $getApi->getFeaturetypes();
+    if ($inputFeaturetypeArray) {
+    	$wfsConfIds = array();
+    	foreach ($inputFeaturetypeArray as $input) {
+    		array_push($wfsConfIds, $input["id"]);
+    	}
+    
+    	$wmcGetApi->generalExtensionArray['WFSCONFIDSTRING'] = implode(",", array_unique(array_merge(
+    		$wmcGetApi->generalExtensionArray['WFSCONFIDSTRING'] ?
+    		explode(",", $wmcGetApi->generalExtensionArray['WFSCONFIDSTRING']) :
+    		array(),
+    		$wfsConfIds
+    	)));
+    }
+    
+    $inputGeoRSSArray = $getApi->getGeoRSSFeeds();
+    if($inputGeoRSSArray){
+    	$wmc->generalExtensionArray['GEORSS'] = $inputGeoRSSArray; 
+    }
+    
+    //workaround to have a fully merged WMC for loading
+    
+    $xml = $wmcGetApi->toXml();
+    
+    $wmcGetApi = new wmc();
+    //new Object with merged layers and other features
+    $wmcGetApi->createFromXml($xml);
+    
+    
+    
+    //
+    // CONSTRAINTS
+    //
+    $currentUser = new User();
+    
+    // remove all WMS with no permission
+    $deniedIdsArray = $wmcGetApi->getWmsWithoutPermission($currentUser);
+    $deniedIdsTitles = array();
+    $deniedIdsIndices = array();
+    foreach ($deniedIdsArray as $i) {
+    	$deniedIdsTitles[]= array(
+    		"id" => $i["id"],
+    		"index" => $i["index"],
+    		"title" => $i["title"]
+    	);
+    	$deniedIdsIndices[]= $i["index"];
+    }
+    $resultObj["noPermission"]["wms"] = array_merge(
+    	$resultObj["noPermission"]["wms"],
+    	$deniedIdsTitles
+    );
+    $wmcGetApi->removeWms($deniedIdsIndices);
 
-			$options['zoom'] = $multipleAssocArray['zoom'] === "1" ?
-				true : false;
+    // find WMS without ID
+    $withoutIdsArray = $wmcGetApi->getWmsWithoutId();
+    $withoutIdsTitles = array();
+    foreach ($withoutIdsArray as $i) {
+    	$withoutIdsTitles[]= array(
+    		"id" => $i["id"],
+    		"index" => $i["index"],
+    		"title" => $i["title"]
+    	);
+    }
+    $resultObj["withoutId"]["wms"] = array_merge(
+    	$resultObj["withoutId"]["wms"],
+    	$withoutIdsTitles
+    );
+    
+    // find orphaned WMS
+    $invalidIdsArray = $wmcGetApi->getInvalidWms();
+    $invalidIdsTitles = array();
+    foreach ($invalidIdsArray as $i) {
+    	$invalidIdsTitles[]= array(
+    		"id" => $i["id"],
+    		"index" => $i["index"],
+    		"title" => $i["title"]
+    	);
+    }
+    $resultObj["invalidId"]["wms"] = array_merge(
+    	$resultObj["invalidId"]["wms"],
+    	$invalidIdsTitles
+    );
+    
+    // find potentially unavailable WMS
+    $unavailableIdsArray = $wmcGetApi->getUnavailableWms($currentUser);
+    $unavailableIdsTitles = array();
+    foreach ($unavailableIdsArray as $i) {
+    	$unavailableIdsTitles[]= array(
+    		"id" => $i["id"],
+    		"index" => $i["index"],
+    		"title" => $i["title"]
+    	);
+    }
+    $resultObj["unavailable"]["wms"] = array_merge(
+    	$resultObj["unavailable"]["wms"],
+    	$unavailableIdsTitles
+    );
+    
+    //get terms of use from wms objects which are in the remaining wmc and are not already accepted for this session
+    
+    $validWMS = $wmcGetApi->getValidWms();
+    $translation['wms'] = _mb("MapService");
+    $resourceSymbol = "<img src='../img/osgeo_graphics/geosilk/server_map.png' alt='".$translation['wms']." - picture' title='".$translation['wms']."'>";
+    $languageCode = 'de';
+    $hostName = $_SERVER['HTTP_HOST'];
+    $tou = "";
+    $classTou = new tou();
+    foreach($validWMS as $WMS) {
+    	//check if tou has already been read - if not show them in the message
+    	$resultOfCheck = $classTou->check('wms',$WMS['id']);
+    	if ($resultOfCheck['accepted'] == 0) {
+    		$touHeader = $resourceSymbol." <a href='../php/mod_showMetadata.php?resource=wms&layout=tabs&id=".$WMS['id']."&languageCode=".$languageCode."' target='_blank'>".$WMS['title']."</a><br>";
+    
+    		if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
+    			$mapbenderProtocol = "https://";
+    			$mapbenderBaseUrl = "https://".$hostName;
+    		}
+    		else {
+    			$mapbenderProtocol = "http://";
+    			$mapbenderBaseUrl = "http://".$hostName;
+    		}
+    		$touServiceConnector = new connector($mapbenderProtocol."localhost".$_SERVER['SCRIPT_NAME']."/../../php/mod_getServiceDisclaimer.php?resource=wms&id=".$WMS['id']."&languageCode=".$languageCode."&asTable=true");
+    		$touForWMS = $touServiceConnector->file;
+    		//add only those who have no special tou defined - 
+    		if ($touForWMS != ''){
+    			$tou .= $touHeader.$touForWMS;
+    		}
+    		//set the tou to be accepted - TODO maybe do this after the button which deletes the message window - from a ajax request.
+    
+    		$classTou->set('wms',$WMS['id']);
+    	} 
+    }
+    	
+    if ($tou != "") {
+    	$tou = _mb("The configuration, which should be loaded, consists of different services which have the following terms of use:")."<br>".$tou;
+    }
+    $resultObj["wmcTou"]["message"] = $tou;
+    
+    
+    #$resultObj["wmcTou"]["message"] = "Terms of Use";
 
-			$wmcGetApi->mergeWmsArray($wmsArray, $options);
-			$wmsArray = array();
-			$multipleAssocArray = array();
-		}
-		else {
-			$currentWms = new wms();
-			if(is_numeric($key)) {
-				//get WMS by ID
-				if (is_numeric($val)) {
-					$currentWms->createObjFromDBNoGui($val);
-				}
-				//get WMS by URL
-				else if (is_string($val)) {
-					$currentWms->createObjFromXML($val);
-				}
-				array_push($wmsArray, $currentWms);
-				$wmcGetApi->mergeWmsArray($wmsArray);
-				$wmsArray = array();
-			}
-			else {
-				$singleAssocArray[$key] = $val;
-			}
-		}
-	}
-
-	//get WMS by ID with settings of given application
-	if (array_key_exists('application', $singleAssocArray) &&
-		array_key_exists('id', $singleAssocArray)) {
-		$currentWms = new wms();
-		$currentWms->createObjFromDB(
-			$singleAssocArray['application'],
-			$singleAssocArray['id']
-		);
-		array_push($wmsArray, $currentWms);
-		$options['visible'] = $singleAssocArray['visible'] === "1" ?
-			true : false;
-
-		$options['zoom'] = $singleAssocArray['zoom'] === "1" ? true : false;
-
-		$wmcGetApi->mergeWmsArray($wmsArray, $options);
-		$wmsArray = array();
-		$singleAssocArray = array();
-	}
-	//get WMS by URL
-	elseif (array_key_exists('url', $singleAssocArray)) {
-		$currentWms = new wms();
-		$currentWms->createObjFromXML($singleAssocArray['url']);
-		array_push($wmsArray, $currentWms);
-		if($singleAssocArray['visible']) {
-			$options['visible'] = $singleAssocArray['visible'] === "1" ?
-				true : false;
-		}
-		if($singleAssocArray['zoom']) {
-			$options['zoom'] = $singleAssocArray['zoom'] === "1" ?
-				true : false;
-		}
-		$wmcGetApi->mergeWmsArray($wmsArray, $options);
-		$wmsArray = array();
-		$singleAssocArray = array();
-	}
-}
-
-//
-// LAYER
-//
-
-$inputLayerArray = $getApi->getLayers();
-if ($inputLayerArray) {
-	foreach ($inputLayerArray as $input) {
-	// just make it work for a single layer id
-		$wmsFactory = new UniversalWmsFactory();
-		try {
-			if (isset($input["application"])) {
-				$wms = $wmsFactory->createLayerFromDb(
-					$input["id"], $input["application"]
-				);
-			}
-			else {
-				$wms = $wmsFactory->createLayerFromDb($input["id"]);
-			}
-		}
-		catch (AccessDeniedException $e) {
-			$resultObj["noPermission"]["wms"][] = array(
-				"title" => $admin->getLayerTitleByLayerId($input["id"]),
-				"id" => $input["id"]
-			);
-		}
-
-		if (is_a($wms, "wms")) {
-			$options = array();
-			if ($input["visible"]) {
-			// this is a hack for the time being:
-			// make WMS visible if it has less than 100000 layers
-				$options["show"] = 100000;
-			}
-			if (isset($input["querylayer"])) {
-				$options["querylayer"] = $input["querylayer"];
-			}
-			$wmcGetApi->mergeWmsArray(array($wms), $options);
-
-			// do not use "zoom" attribute of mergeWmsArray,
-			// as this would zoom to the entre WMS.
-			// Here we set extent to the layer extent only.
-			if ($input["zoom"]) {
-				$bboxArray = array();
-				try {
-					$layer = $wms->getLayerById(intval($input["id"]));
-					for ($i = 0; $i < count($layer->layer_epsg); $i++) {
-						$bboxArray[]= Mapbender_bbox::createFromLayerEpsg(
-							$layer->layer_epsg[$i]
-						);
-					}
-					$wmcGetApi->mainMap->mergeExtent($bboxArray);
-				}
-				catch (Exception $e) {
-
-				}
-			}
-
-		}
-	}
-}
-
-//
-// FEATURETYPE
-//
-$inputFeaturetypeArray = $getApi->getFeaturetypes();
-if ($inputFeaturetypeArray) {
-	$wfsConfIds = array();
-	foreach ($inputFeaturetypeArray as $input) {
-		array_push($wfsConfIds, $input["id"]);
-	}
-
-	$wmcGetApi->generalExtensionArray['WFSCONFIDSTRING'] = implode(",", array_unique(array_merge(
-		$wmcGetApi->generalExtensionArray['WFSCONFIDSTRING'] ?
-		explode(",", $wmcGetApi->generalExtensionArray['WFSCONFIDSTRING']) :
-		array(),
-		$wfsConfIds
-	)));
-}
-
-$inputGeoRSSArray = $getApi->getGeoRSSFeeds();
-if($inputGeoRSSArray){
-	$wmc->generalExtensionArray['GEORSS'] = $inputGeoRSSArray; 
-}
-
-//workaround to have a fully merged WMC for loading
-
-$xml = $wmcGetApi->toXml();
-
-$wmcGetApi = new wmc();
-//new Object with merged layers and other features
-$wmcGetApi->createFromXml($xml);
-
-
-
-//
-// CONSTRAINTS
-//
-$currentUser = new User();
-
-// remove all WMS with no permission
-$deniedIdsArray = $wmcGetApi->getWmsWithoutPermission($currentUser);
-$deniedIdsTitles = array();
-$deniedIdsIndices = array();
-foreach ($deniedIdsArray as $i) {
-	$deniedIdsTitles[]= array(
-		"id" => $i["id"],
-		"index" => $i["index"],
-		"title" => $i["title"]
-	);
-	$deniedIdsIndices[]= $i["index"];
-}
-$resultObj["noPermission"]["wms"] = array_merge(
-	$resultObj["noPermission"]["wms"],
-	$deniedIdsTitles
-);
-$wmcGetApi->removeWms($deniedIdsIndices);
-
-// find WMS without ID
-$withoutIdsArray = $wmcGetApi->getWmsWithoutId();
-$withoutIdsTitles = array();
-foreach ($withoutIdsArray as $i) {
-	$withoutIdsTitles[]= array(
-		"id" => $i["id"],
-		"index" => $i["index"],
-		"title" => $i["title"]
-	);
-}
-$resultObj["withoutId"]["wms"] = array_merge(
-	$resultObj["withoutId"]["wms"],
-	$withoutIdsTitles
-);
-
-// find orphaned WMS
-$invalidIdsArray = $wmcGetApi->getInvalidWms();
-$invalidIdsTitles = array();
-foreach ($invalidIdsArray as $i) {
-	$invalidIdsTitles[]= array(
-		"id" => $i["id"],
-		"index" => $i["index"],
-		"title" => $i["title"]
-	);
-}
-$resultObj["invalidId"]["wms"] = array_merge(
-	$resultObj["invalidId"]["wms"],
-	$invalidIdsTitles
-);
-
-// find potentially unavailable WMS
-$unavailableIdsArray = $wmcGetApi->getUnavailableWms($currentUser);
-$unavailableIdsTitles = array();
-foreach ($unavailableIdsArray as $i) {
-	$unavailableIdsTitles[]= array(
-		"id" => $i["id"],
-		"index" => $i["index"],
-		"title" => $i["title"]
-	);
-}
-$resultObj["unavailable"]["wms"] = array_merge(
-	$resultObj["unavailable"]["wms"],
-	$unavailableIdsTitles
-);
-
-//get terms of use from wms objects which are in the remaining wmc and are not already accepted for this session
-
-$validWMS = $wmcGetApi->getValidWms();
-$translation['wms'] = _mb("MapService");
-$resourceSymbol = "<img src='../img/osgeo_graphics/geosilk/server_map.png' alt='".$translation['wms']." - picture' title='".$translation['wms']."'>";
-$languageCode = 'de';
-$hostName = $_SERVER['HTTP_HOST'];
-$tou = "";
-$classTou = new tou();
-foreach($validWMS as $WMS) {
-	//check if tou has already been read - if not show them in the message
-	$resultOfCheck = $classTou->check('wms',$WMS['id']);
-	if ($resultOfCheck['accepted'] == 0) {
-		$touHeader = $resourceSymbol." <a href='../php/mod_showMetadata.php?resource=wms&layout=tabs&id=".$WMS['id']."&languageCode=".$languageCode."' target='_blank'>".$WMS['title']."</a><br>";
-
-		if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
-			$mapbenderProtocol = "https://";
-			$mapbenderBaseUrl = "https://".$hostName;
-		}
-		else {
-			$mapbenderProtocol = "http://";
-			$mapbenderBaseUrl = "http://".$hostName;
-		}
-		$touServiceConnector = new connector($mapbenderProtocol."localhost".$_SERVER['SCRIPT_NAME']."/../../php/mod_getServiceDisclaimer.php?resource=wms&id=".$WMS['id']."&languageCode=".$languageCode."&asTable=true");
-		$touForWMS = $touServiceConnector->file;
-		//add only those who have no special tou defined - 
-		if ($touForWMS != ''){
-			$tou .= $touHeader.$touForWMS;
-		}
-		//set the tou to be accepted - TODO maybe do this after the button which deletes the message window - from a ajax request.
-
-		$classTou->set('wms',$WMS['id']);
-	} 
-}
-	
-if ($tou != "") {
-	$tou = _mb("The configuration, which should be loaded, consists of different services which have the following terms of use:")."<br>".$tou;
-}
-$resultObj["wmcTou"]["message"] = $tou;
-
-
-#$resultObj["wmcTou"]["message"] = "Terms of Use";
-
-//
-// Output
-//
-// Check if session WMC module is loaded
-$sql = "SELECT COUNT(e_id) AS i FROM gui_element WHERE fkey_gui_id = $1 AND e_id = $2";
-$v = array(Mapbender::session()->get("mb_user_gui"), "sessionWmc");
-$t = array("s", "s");
-$res = db_prep_query($sql, $v, $t);
-$row = db_fetch_assoc($res);
-$isSessionWmcModuleLoaded = intval($row["i"]);
-
-// check if Session contains a GML, and then zoom to it
-$gml_string = Mapbender::session()->get("GML");
-if($gml_string){
-	$gml = new gml2();
-	$gml->parse_xml($gml_string);
-	$bbox = new Mapbender_bbox(
-	$gml->bbox[0],
-	$gml->bbox[1],
-	$gml->bbox[2],
-	$gml->bbox[3],
-	$epsg = "EPSG:".$gml->epsg);
-	$wmcGetApi->mainMap->setExtent($bbox);
-}
-if (
-	count($resultObj["withoutId"]["wms"]) === 0 &&
-	count($resultObj["invalidId"]["wms"]) === 0 &&
-	count($resultObj["unavailable"]["wms"]) === 0 ||
-	!$isSessionWmcModuleLoaded
-) {
-	
-	Mapbender::session()->set("wmcConstraints", $resultObj);
-	$output = $wmcGetApi->wmsToJavaScript();
-	$wmcJs = $wmcGetApi->toJavaScript(array());
-	$wmcJs = implode(";\n",$wmcJs);
-	$extentJs = $wmcGetApi->extentToJavaScript();
-	$output[] = <<<JS
-		Mapbender.events.afterInit.register(function () {
-			$wmcJs;
-		});
-		Mapbender.events.beforeInit.register(function () {
-			$extentJs
-		});
+    //
+    // Output
+    //
+    // Check if session WMC module is loaded
+    $sql = "SELECT COUNT(e_id) AS i FROM gui_element WHERE fkey_gui_id = $1 AND e_id = $2";
+    $v = array(Mapbender::session()->get("mb_user_gui"), "sessionWmc");
+    $t = array("s", "s");
+    $res = db_prep_query($sql, $v, $t);
+    $row = db_fetch_assoc($res);
+    $isSessionWmcModuleLoaded = intval($row["i"]);
+    
+    // check if Session contains a GML, and then zoom to it
+    $gml_string = Mapbender::session()->get("GML");
+    if($gml_string){
+    	$gml = new gml2();
+    	$gml->parse_xml($gml_string);
+    	$bbox = new Mapbender_bbox(
+    	$gml->bbox[0],
+    	$gml->bbox[1],
+    	$gml->bbox[2],
+    	$gml->bbox[3],
+    	$epsg = "EPSG:".$gml->epsg);
+    	$wmcGetApi->mainMap->setExtent($bbox);
+    }
+    if (
+    	count($resultObj["withoutId"]["wms"]) === 0 &&
+    	count($resultObj["invalidId"]["wms"]) === 0 &&
+    	count($resultObj["unavailable"]["wms"]) === 0 ||
+    	!$isSessionWmcModuleLoaded
+    ) {
+    	
+    	Mapbender::session()->set("wmcConstraints", $resultObj);
+    	$output = $wmcGetApi->wmsToJavaScript();
+    	$wmcJs = $wmcGetApi->toJavaScript(array());
+    	$wmcJs = implode(";\n",$wmcJs);
+    	$extentJs = $wmcGetApi->extentToJavaScript();
+    	$output[] = <<<JS
+    		Mapbender.events.afterInit.register(function () {
+    			$wmcJs;
+    		});
+    		Mapbender.events.beforeInit.register(function () {
+    			$extentJs
+    		});
 JS;
 	Mapbender::session()->delete("wmcGetApi", $wmcGetApi);
-}
-else {
-	Mapbender::session()->set("wmcConstraints", $resultObj);
-	$output = $wmc->wmsToJavaScript();
-	$wmcJs = $wmc->toJavaScript(array());
-	$wmcJs = implode(";\n",$wmcJs);
-	$extentJs = $wmc->extentToJavaScript();
-	$output[] = <<<JS
-		Mapbender.events.afterInit.register(function () {
-			$wmcJs;
-		});
-		Mapbender.events.beforeInit.register(function () {
-			$extentJs
-		});
+    }
+    else {
+    	Mapbender::session()->set("wmcConstraints", $resultObj);
+    	$output = $wmc->wmsToJavaScript();
+    	$wmcJs = $wmc->toJavaScript(array());
+    	$wmcJs = implode(";\n",$wmcJs);
+    	$extentJs = $wmc->extentToJavaScript();
+	    $output[] = <<<JS
+    		Mapbender.events.afterInit.register(function () {
+    			$wmcJs;
+    		});
+    		Mapbender.events.beforeInit.register(function () {
+    			$extentJs
+    		});
 JS;
-	Mapbender::session()->set("wmcGetApi", $wmcGetApi);
-}
+	    Mapbender::session()->set("wmcGetApi", $wmcGetApi);
+    }
 
 
-$outputString = "";
-for ($i = 0; $i < count($output); $i++) {
-	$outputString .= administration::convertOutgoingString($output[$i]);
-}
+    $outputString = "";
+    for ($i = 0; $i < count($output); $i++) {
+    	$outputString .= administration::convertOutgoingString($output[$i]);
+    }
 
-$wmcFeaturetypeJson = $wmc->featuretypeConfToJavaScript();
-$wfsConfIdString = $wmcGetApi->generalExtensionArray['WFSCONFIDSTRING'];
-if($wfsConfIdString != ""){
-	$wmcFeaturetypeStr = <<<JS
-		Mapbender.events.afterInit.register(function () {
-			$('#body').trigger('addFeaturetypeConfs', [
-				{ featuretypeConfObj : $wmcFeaturetypeJson,
-					wfsConfIdString: "$wfsConfIdString"}
-			]);
-		});
+    $wmcFeaturetypeJson = $wmc->featuretypeConfToJavaScript();
+    $wfsConfIdString = $wmcGetApi->generalExtensionArray['WFSCONFIDSTRING'];
+    if($wfsConfIdString != ""){
+	    $wmcFeaturetypeStr = <<<JS
+    		Mapbender.events.afterInit.register(function () {
+    			$('#body').trigger('addFeaturetypeConfs', [
+    				{ featuretypeConfObj : $wmcFeaturetypeJson,
+    					wfsConfIdString: "$wfsConfIdString"}
+    			]);
+    		});
 JS;
-}
-$outputString .= $wmcFeaturetypeStr;
+    }
+    $outputString .= $wmcFeaturetypeStr;
 
-$GeoRSSStr = " Mapbender.events.afterInit.register(function () {";
-foreach($inputGeoRSSArray as $inputGeoRSSUrl){
-	$GeoRSSStr .= 'try {$("#mapframe1").georss({url: "'.$inputGeoRSSUrl .'"})} catch(e) {new Mb_warning("GeoRSS module not loaded")}';
+    $GeoRSSStr = " Mapbender.events.afterInit.register(function () {";
+    foreach($inputGeoRSSArray as $inputGeoRSSUrl){
+    	$GeoRSSStr .= 'try {$("#mapframe1").georss({url: "'.$inputGeoRSSUrl .'"})} catch(e) {new Mb_warning("GeoRSS module not loaded")}';
+    }
+    $GeoRSSStr .="}); ";
+    
+    $outputString .= $GeoRSSStr;
+    
+    if($activateCache) {
+        //save outputString for caching in cache directory and log difference
+        if(file_exists($applicationLoadFile)) {
+            $oldOutputString = file_get_contents($applicationLoadFile);
+            if($oldOutputString == $outputString) {
+                $diff = "No differences between old outputstring and new outputstring for cache file ".$applicationLoadFile;
+            }
+            else {
+                $diff = "Differences between old outputstring and new outputstring for cache file ".$applicationLoadFile." found.";
+            }
+            
+            
+            $cacheLogFile = "../../cache/mb_cache_" . date("Y_m_d") . ".log";
+        	if($h = @fopen($cacheLogFile,"a")){
+        	    $content = strtotime("now")." ";
+        		$content .= "[".date("d/M/Y:H:i:s O")."]";
+        		$content .= " " . Mapbender::session()->get("mb_user_ip");
+        		$content .= ' "';
+    			$content .= Mapbender::session()->get("mb_user_name");
+        		$content .= '"';
+        		$content .= " " . Mapbender::session()->get("mb_user_id");
+        		$content .= $diff;
+        		$content .= chr(13).chr(10);
+        		if(!fwrite($h,$content)){
+        			#exit;
+        		}
+        		fclose($h);    
+        	}
+        }
+        else {
+            $cacheLogFile = "../../cache/mb_cache_" . date("Y_m_d") . ".log";
+        	if($h = @fopen($cacheLogFile,"a")){
+        	    $content = strtotime("now")." ";
+        		$content .= "[".date("d/M/Y:H:i:s O")."]";
+        		$content .= " " . Mapbender::session()->get("mb_user_ip");
+        		$content .= ' "';
+    			$content .= Mapbender::session()->get("mb_user_name");
+        		$content .= '"';
+        		$content .= " " . Mapbender::session()->get("mb_user_id");
+        		$content .= ' "Cache file '.$applicationLoadFile.' does not yet exist, is generated now."';
+        		$content .= chr(13).chr(10);
+        		if(!fwrite($h,$content)){
+        			#exit;
+        		}
+        		fclose($h);    
+        	}
+        }
+        $saveApplicationLoadFile = file_put_contents($applicationLoadFile, $outputString);
+    }
 }
-$GeoRSSStr .="}); ";
 
-$outputString .= $GeoRSSStr;
-
-
 echo $outputString;
 
 Mapbender::session()->delete("addwms_showWMS");

Modified: branches/2.7/http/php/mod_deleteWMS.php
===================================================================
--- branches/2.7/http/php/mod_deleteWMS.php	2012-09-18 15:09:37 UTC (rev 8490)
+++ branches/2.7/http/php/mod_deleteWMS.php	2012-09-18 15:11:04 UTC (rev 8491)
@@ -176,6 +176,15 @@
 else {	
 	// delete WMS
 	if($del){
+	    //on delete wms: unlink the application cache file in cache directory
+    	$sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = $1";
+    	$v = array($wmsList);
+    	$t = array('i');
+    	$res = db_prep_query($sql,$v,$t);
+    	while($row = db_fetch_array($res)){
+    		$admin->clearJsCacheFile($row["fkey_gui_id"]);
+    	}
+        	
 		$sql = "select * from gui_wms where fkey_wms_id = $1 ";
 		$v = array($wmsList);
 		$t = array('i');

Modified: branches/2.7/http/php/mod_editGuiWms.php
===================================================================
--- branches/2.7/http/php/mod_editGuiWms.php	2012-09-18 15:09:37 UTC (rev 8490)
+++ branches/2.7/http/php/mod_editGuiWms.php	2012-09-18 15:11:04 UTC (rev 8491)
@@ -20,6 +20,8 @@
 
 $e_id = "editGUI_WMS";
 require_once (dirname(__FILE__) . "/../php/mb_validatePermission.php");
+require_once (dirname(__FILE__) . "/../classes/class_administration.php");
+$admin = new administration();
 
 /*  
  * @security_patch irv done 
@@ -184,12 +186,21 @@
 <body>
 <?php
 
-
 require_once (dirname(__FILE__) . "/../../conf/mapbender.conf");
 $con = db_connect($DBSERVER, $OWNER, $PW);
 db_select_db(DB, $con);
 
 $mb_user_id = Mapbender :: session()->get("mb_user_id");
+
+//if changes are made here for gui wms selection, unlink the application cache file in cache directory
+if ((isset ($update_content) && $update_content == "1") ||
+    ($del && $del == 'true') ||
+    ($up && $up == 'true') ||
+    ($down && $down == 'true')
+) {
+    $admin->clearJsCacheFile($guiList);
+}
+   
 #delete gui_wms from gui
 if ($del && $del == 'true') {
 	$sql = "SELECT DISTINCT gui_wms_position from gui_wms WHERE fkey_gui_id = $1 and fkey_wms_id = $2";
@@ -461,8 +472,6 @@
 
 echo "<td>";
 
-require_once (dirname(__FILE__) . "/../classes/class_administration.php");
-$admin = new administration();
 $ownguis = $admin->getGuisByOwner(Mapbender :: session()->get("mb_user_id"), true);
 
 $gui_id = array ();

Modified: branches/2.7/http/php/mod_loadCapabilitiesList.php
===================================================================
--- branches/2.7/http/php/mod_loadCapabilitiesList.php	2012-09-18 15:09:37 UTC (rev 8490)
+++ branches/2.7/http/php/mod_loadCapabilitiesList.php	2012-09-18 15:11:04 UTC (rev 8491)
@@ -144,6 +144,11 @@
 
 ###INSERT
 if(isset($wmsID) && isset($guiID_)){
+    
+    //add wms: unlink the application cache file in cache directory
+	$admin->clearJsCacheFile($guiList);
+	
+	
 	$sql_pos = "SELECT MAX(gui_wms_position) AS my_gui_wms_position FROM gui_wms WHERE fkey_gui_id = $1";
 	$v = array($guiList);
 	$t = array('s');

Modified: branches/2.7/http/php/mod_loadwms.php
===================================================================
--- branches/2.7/http/php/mod_loadwms.php	2012-09-18 15:09:37 UTC (rev 8490)
+++ branches/2.7/http/php/mod_loadwms.php	2012-09-18 15:11:04 UTC (rev 8491)
@@ -34,6 +34,7 @@
     	$auth['auth_type'] = $_REQUEST["auth_type"];
     }
     $mywms = new wms();
+    
 	if (isset($auth)) {
 		$mywms->createObjFromXML($xml, $auth);
 	    $mywms->writeObjInDB($gui_id, $auth);  
@@ -45,6 +46,11 @@
         
    	$mywms->displayWMS();
 	$wms_id = $mywms->wms_id;
+	
+	//onload wms: unlink the application cache file in cache directory
+	require_once (dirname(__FILE__) . "/../classes/class_administration.php");
+    $admin = new administration();
+	$admin->clearJsCacheFile($gui_id);
 }
 else {
 	$wms_id = $_REQUEST["wms_id"];

Modified: branches/2.7/http/php/mod_updateWMS.php
===================================================================
--- branches/2.7/http/php/mod_updateWMS.php	2012-09-18 15:09:37 UTC (rev 8490)
+++ branches/2.7/http/php/mod_updateWMS.php	2012-09-18 15:11:04 UTC (rev 8491)
@@ -134,6 +134,16 @@
 	} 
 	$mywms->updateObjInDB($myWMS);
 	$mywms->displayWMS();
+	
+	//if changes are made here for wms, unlink the application cache file in cache directory
+	$sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = $1";
+	$v = array($myWMS);
+	$t = array('i');
+	$res = db_prep_query($sql,$v,$t);
+	while($row = db_fetch_array($res)){
+		$admin->clearJsCacheFile($row["fkey_gui_id"]);
+	}
+	
 
 	// start (owners of the updated wms will be notified by email)
 	if ($use_php_mailing) {



More information about the Mapbender_commits mailing list