[Mapbender-commits] r8524 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Dec 11 07:09:27 PST 2012


Author: armin11
Date: 2012-12-11 07:09:27 -0800 (Tue, 11 Dec 2012)
New Revision: 8524

Modified:
   trunk/mapbender/http/php/mb_getWmsData.php
   trunk/mapbender/http/php/mod_monitorCapabilities_read.php
   trunk/mapbender/http/php/mod_updateWMS.php
Log:
New possibility to inform subscribers of wms about update of the service and renaming of layers

Modified: trunk/mapbender/http/php/mb_getWmsData.php
===================================================================
--- trunk/mapbender/http/php/mb_getWmsData.php	2012-12-11 15:06:52 UTC (rev 8523)
+++ trunk/mapbender/http/php/mb_getWmsData.php	2012-12-11 15:09:27 UTC (rev 8524)
@@ -1,11 +1,25 @@
 <?php
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
 require_once(dirname(__FILE__)."/../classes/class_json.php");
 require_once(dirname(__FILE__)."/../classes/class_wms.php");
 require_once(dirname(__FILE__)."/../classes/class_administration.php");
 
+function getRootLayerId ($wms_id) {
+	$sql = "SELECT layer_id FROM layer, wms " . 
+		"WHERE wms.wms_id = layer.fkey_wms_id AND layer_pos='0' " . 
+		"AND wms.wms_id = $1";
+	$v=array($wms_id);
+	$t=array('i');
+	$res=db_prep_query($sql,$v,$t);
+	$row=db_fetch_array($res);
+	return $row ? $row["layer_id"] : null;
+}
+
+//instantiate admin
+$admin = new administration();
+
 $command = $_REQUEST["command"];
-
 if ($command == "getWmsData") {
 	$wms = $_POST["wmsId"];
 	$url = $_POST["wmsUrl"];
@@ -63,7 +77,7 @@
 	
 	#$changedLayerObj = json_encode($changedLayerArray);
 	
-    $mywms = new wms();
+    	$mywms = new wms();
 	$mywms->createObjFromXML($url);    
 	$mywms->optimizeWMS();
 	echo "<br />";  
@@ -80,29 +94,73 @@
 	$mywms->updateObjInDB($myWMS,false, $changedLayerArray);
 	$mywms->displayWMS();
 
-	// start (owners of the updated wms will be notified by email)
+	$subscribers_ids = $admin->getSubscribersByWms($myWMS);
+	$layerChangeInformation = "";
+	for ($i=0; $i<count($subscribers_ids); $i++) {
+		$e = new mb_notice("Subscriber for wms ".$myWMS." - ".$subscribers_ids[$i]);
+		for ($j=0; $j<count($changedLayerArray); $j++) {
+			if ($changedLayerArray[$j]["oldLayerName"] != $changedLayerArray[$j]["newLayerName"]) {
+				$e = new mb_notice("Old layer name: ".$changedLayerArray[$j]["oldLayerName"]." - changed to: ".$changedLayerArray[$j]["newLayerName"]);
+				$layerChangeInformation = _mb("Old layer name: ").$changedLayerArray[$j]["oldLayerName"]._mb(" - changed to: ").$changedLayerArray[$j]["newLayerName"]."\n";
+				
+			}
+		}
+	}
+	// start (owners and subscribers of the updated wms will be notified by email)
 	if ($use_php_mailing) {
+		//collect change information
+		$layerChangeInformation = "";
+		for ($j=0; $j<count($changedLayerArray); $j++) {
+			if ($changedLayerArray[$j]["oldLayerName"] != $changedLayerArray[$j]["newLayerName"]) {
+				$e = new mb_notice("Old layer name: ".$changedLayerArray[$j]["oldLayerName"]." - changed to: ".$changedLayerArray[$j]["newLayerName"]);
+				$layerChangeInformation = _mb("Old layer name: ").$changedLayerArray[$j]["oldLayerName"]._mb(" - changed to: ").$changedLayerArray[$j]["newLayerName"]."\n";	
+			}
+		}
+		//get owner of guis with this wms
 		$owner_ids = $admin->getOwnerByWms($myWMS);
-		
-		if ($owner_ids && count($owner_ids)>0) {
-			$owner_mail_addresses = array();
+		//get information for subscribers
+		$subscribers_ids = $admin->getSubscribersByWms($myWMS);
+		//if some person exists which is interested in changing of wms information ;-)
+		if (($owner_ids && count($owner_ids)>0) || ($subscribers_ids && count($subscribers_ids)>0)) {
+			$notification_mail_addresses = array();
 			$j=0;
 			for ($i=0; $i<count($owner_ids); $i++) {
 				$adr_tmp = $admin->getEmailByUserId($owner_ids[$i]);
-				if (!in_array($adr_tmp, $owner_mail_addresses) && $adr_tmp) {
-					$owner_mail_addresses[$j] = $adr_tmp;
+				if (!in_array($adr_tmp, $notification_mail_addresses) && $adr_tmp) {
+					$notification_mail_addresses[$j] = $adr_tmp;
 					$j++;
 				} 
 			}
-			
+			for ($i=0; $i<count($subscribers_ids); $i++) {
+				$adr_tmp = $admin->getEmailByUserId($subscribers_ids[$i]);
+				if (!in_array($adr_tmp, $notification_mail_addresses) && $adr_tmp) {
+					$notification_mail_addresses[$j] = $adr_tmp;
+					$j++;
+				} 
+			}
+
 			$replyto = $admin->getEmailByUserId(Mapbender::session()->get("mb_user_id"));
 			$from = $replyto;
-			$pathArray = explode("http/php/", $_SERVER["PATH_TRANSLATED"]);
-			$path = $pathArray[0];		
-			$body = "WMS '" . $admin->getWmsTitleByWmsId($myWMS) . "' has been updated. \n\nServer name:  " . $_SERVER["SERVER_NAME"] . "\nInstallation Path: " . $path . "\n\nYou may want to check the changes as you are an owner of this WMS.";
+			$rootLayerId = getRootLayerId($myWMS);
+			if (defined(MAPBENDER_PATH) && MAPBENDER_PATH != '') {
+				$metadataUrl = MAPBENDER_PATH."/php/mod_showMetadata.php?resource=layer&id=".$rootLayerId;
+			} else {
+				$metadataUrl = preg_replace(
+					"/(.*)frames\/login.php/", 
+					"$1php/mod_showMetadata.php?resource=layer&id=".$rootLayerId, 
+					LOGIN
+				);
+			}
+			$path = $pathArray[0];
+			//Build mailbody	
+			$body = _mb("WMS")." '" . $admin->getWmsTitleByWmsId($myWMS) . "' "._mb("has been updated.")."\n\n".$metadataUrl. "\n\n"._mb("You may want to check the changes as you are an owner or subscriber of this WMS. If you have integrated the into a gis client, you have to reconfigure the client!");
+			if (isset($layerChangeInformation) &&  $layerChangeInformation != "") {
+				$body .= "\n\n"._mb("Following layers have been renamed:\n").$layerChangeInformation;
+			}
 			$error_msg = "";
-			for ($i=0; $i<count($owner_mail_addresses); $i++) {
-				if (!$admin->sendEmail($replyto, $from, $owner_mail_addresses[$i], $owner_mail_addresses[$i], "[Mapbender] A user has updated one of your WMS", $body, $error)) {
+
+			for ($i=0; $i<count($notification_mail_addresses); $i++) {
+				if (!$admin->sendEmail($replyto, $from, $notification_mail_addresses[$i], $notification_mail_addresses[$i], _mb("Update of an observed WMS"), $body, $error)) {
 					if ($error){
 						$error_msg .= $error . " ";
 					}
@@ -110,12 +168,12 @@
 			}
 			if (!$error_msg) {
 				echo "<script language='javascript'>";
-				echo "alert('Other owners of this WMS have been informed about the changes!');";
+				echo "alert('"._mb("Other owners of this WMS have been informed about the changes!")."');";
 				echo "</script>";
 			}
 			else {
 				echo "<script language='javascript'>";
-				echo "alert('When notifying the owners of this WMS about your changes, an error occured: ' + '" . $error_msg . "');";
+				echo "alert('"._mb("When notifying the owners of this WMS about your changes, an error occured").": ' + '" . $error_msg . "');";
 				echo "</script>";
 			}
 		}
@@ -123,6 +181,6 @@
 	// end (owners of the updated wms will be notified by email)
 }
 else {
-	echo "please enter a valid command.";
+	echo _mb("please enter a valid command.");
 }
-?>
\ No newline at end of file
+?>

Modified: trunk/mapbender/http/php/mod_monitorCapabilities_read.php
===================================================================
--- trunk/mapbender/http/php/mod_monitorCapabilities_read.php	2012-12-11 15:06:52 UTC (rev 8523)
+++ trunk/mapbender/http/php/mod_monitorCapabilities_read.php	2012-12-11 15:09:27 UTC (rev 8524)
@@ -18,11 +18,10 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 $e_id = "monitor_results";
-#require_once(dirname(__FILE__)."/../php/mb_validatePermission.php");
-require_once(dirname(__FILE__)."/../classes/class_administration.php");
-require_once(dirname(__FILE__)."/../classes/class_user.php");
+//$gui_id = $_REQUEST["guiID"];
+//TODO: Check wether request parameters cannot be found! Since this is not handled, update will not be available!
+require_once(dirname(__FILE__)."/../php/mb_validatePermission.php");
 require_once(dirname(__FILE__)."/../classes/class_wms.php");
-require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
 ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
@@ -74,6 +73,16 @@
 		$mywms->optimizeWMS();
 		
 		echo "<br />";  
+		if (!MD_OVERWRITE) {
+			$mywms->overwrite=false;
+		} 
+		//possibility to see update information in georss and/or twitter channel
+		if(empty($_POST['twitter_news'])) {
+			$mywms->twitterNews = false;
+		}
+		if(empty($_POST['rss_news'])) {
+			$mywms->setGeoRss = false;
+		}	
 		$mywms->updateObjInDB($upd_wmsid);
 		echo "<br>Updated: " . $upd_wmsid . "<br>";
 

Modified: trunk/mapbender/http/php/mod_updateWMS.php
===================================================================
--- trunk/mapbender/http/php/mod_updateWMS.php	2012-12-11 15:06:52 UTC (rev 8523)
+++ trunk/mapbender/http/php/mod_updateWMS.php	2012-12-11 15:09:27 UTC (rev 8524)
@@ -18,6 +18,7 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 $e_id="updateWMSs";
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__)."/mb_validatePermission.php");
 require_once(dirname(__FILE__)."/../classes/class_wms.php"); 
 
@@ -29,6 +30,16 @@
 $secParams = SID."&guiID=".$_REQUEST["guiID"]."&elementID=".$_REQUEST["elementID"];
 $self = $_SERVER["SCRIPT_NAME"]."?".$secParams;
 
+function getRootLayerId ($wms_id) {
+	$sql = "SELECT layer_id FROM layer, wms " . 
+		"WHERE wms.wms_id = layer.fkey_wms_id AND layer_pos='0' " . 
+		"AND wms.wms_id = $1";
+	$v=array($wms_id);
+	$t=array('i');
+	$res=db_prep_query($sql,$v,$t);
+	$row=db_fetch_array($res);
+	return $row ? $row["layer_id"] : null;
+}
 
 
 ?>
@@ -375,31 +386,64 @@
 	
 	echo "<div id='updateResult'>";
 	$mywms->displayWMS();
-    echo "</div>";
-	
-	// start (owners of the updated wms will be notified by email)
-	if ($use_php_mailing) {
+    	echo "</div>";
+
+	// start (owners and subscribers of the updated wms will be notified by email)
+	if (defined("NOTIFY_ON_UPDATE") &&  NOTIFY_ON_UPDATE == true) {
+		//collect change information
+		$layerChangeInformation = "";
+		for ($j=0; $j<count($changedLayerArray); $j++) {
+			if ($changedLayerArray[$j]["oldLayerName"] != $changedLayerArray[$j]["newLayerName"]) {
+				$e = new mb_notice("Old layer name: ".$changedLayerArray[$j]["oldLayerName"]." - changed to: ".$changedLayerArray[$j]["newLayerName"]);
+				$layerChangeInformation = _mb("Old layer name: ").$changedLayerArray[$j]["oldLayerName"]._mb(" - changed to: ").$changedLayerArray[$j]["newLayerName"]."\n";	
+			}
+		}
+		//get owner of guis with this wms
 		$owner_ids = $admin->getOwnerByWms($myWMS);
-		
-		if ($owner_ids && count($owner_ids)>0) {
-			$owner_mail_addresses = array();
+		//get information for subscribers
+		$subscribers_ids = $admin->getSubscribersByWms($myWMS);
+		//if some person exists which is interested in changing of wms information ;-)
+		if (($owner_ids && count($owner_ids)>0) || ($subscribers_ids && count($subscribers_ids)>0)) {
+			$notification_mail_addresses = array();
 			$j=0;
 			for ($i=0; $i<count($owner_ids); $i++) {
 				$adr_tmp = $admin->getEmailByUserId($owner_ids[$i]);
-				if (!in_array($adr_tmp, $owner_mail_addresses) && $adr_tmp) {
-					$owner_mail_addresses[$j] = $adr_tmp;
+				if (!in_array($adr_tmp, $notification_mail_addresses) && $adr_tmp) {
+					$notification_mail_addresses[$j] = $adr_tmp;
 					$j++;
 				} 
 			}
-			
+			for ($i=0; $i<count($subscribers_ids); $i++) {
+				$adr_tmp = $admin->getEmailByUserId($subscribers_ids[$i]);
+				if (!in_array($adr_tmp, $notification_mail_addresses) && $adr_tmp) {
+					$notification_mail_addresses[$j] = $adr_tmp;
+					$j++;
+				} 
+			}
+
 			$replyto = $admin->getEmailByUserId(Mapbender::session()->get("mb_user_id"));
 			$from = $replyto;
-			$pathArray = explode("http/php/", $_SERVER["PATH_TRANSLATED"]);
-			$path = $pathArray[0];		
-			$body = "WMS '" . $admin->getWmsTitleByWmsId($myWMS) . "' has been updated. \n\nServer name:  " . $_SERVER["SERVER_NAME"] . "\nInstallation Path: " . $path . "\n\nYou may want to check the changes as you are an owner of this WMS.";
+			$rootLayerId = getRootLayerId($myWMS);
+			//$e = new mb_exception(MAPBENDER_PATH);
+			if (defined("MAPBENDER_PATH") && MAPBENDER_PATH != '') {
+				$metadataUrl = MAPBENDER_PATH."/php/mod_showMetadata.php?resource=layer&id=".$rootLayerId;
+			} else {
+				$metadataUrl = preg_replace(
+					"/(.*)frames\/login.php/", 
+					"$1php/mod_showMetadata.php?resource=layer&id=".$rootLayerId, 
+					LOGIN
+				);
+			}
+			$path = $pathArray[0];
+			//Build mailbody	
+			$body = _mb("WMS")." '" . $admin->getWmsTitleByWmsId($myWMS) . "' "._mb("has been updated").".\n\n".$metadataUrl. "\n\n"._mb("You may want to check the changes as you are an owner or subscriber of this WMS. If you have integrated the service into a gis client, you have to reconfigure the client!")."\n"._mb("Note: This e-mail has been sent automatically because you subscribed " . "to this service. You can unsubscribe by logging in and clicking the " . "unsubscribe button in the Mapbender metadata dialogue by following the given link.");
+			if (isset($layerChangeInformation) &&  $layerChangeInformation != "") {
+				$body .= "\n\n"._mb("Attention - following layers have been renamed".":\n").$layerChangeInformation;
+			}
 			$error_msg = "";
-			for ($i=0; $i<count($owner_mail_addresses); $i++) {
-				if (!$admin->sendEmail($replyto, $from, $owner_mail_addresses[$i], $owner_mail_addresses[$i], "[Mapbender] A user has updated one of your WMS", $body, $error)) {
+
+			for ($i=0; $i<count($notification_mail_addresses); $i++) {
+				if (!$admin->sendEmail($replyto, $from, $notification_mail_addresses[$i], $notification_mail_addresses[$i], _mb("Update of an observed WMS"), $body, $error)) {
 					if ($error){
 						$error_msg .= $error . " ";
 					}
@@ -407,17 +451,17 @@
 			}
 			if (!$error_msg) {
 				echo "<script language='javascript'>";
-				echo "alert('Other owners of this WMS have been informed about the changes!');";
+				echo "alert('"._mb("Other owners of this WMS have been informed about the changes!")."');";
 				echo "</script>";
 			}
 			else {
 				echo "<script language='javascript'>";
-				echo "alert('When notifying the owners of this WMS about your changes, an error occured: ' + '" . $error_msg . "');";
+				echo "alert('"._mb("When notifying the owners of this WMS about your changes, an error occured").": ' + '" . $error_msg . "');";
 				echo "</script>";
 			}
 		}
 	}
-	// end (owners of the updated wms will be notified by email)
+	// end (owners and subscribers of the updated wms will be notified by email)	
 }
 
 	echo "</form>";



More information about the Mapbender_commits mailing list