[Mapbender-commits] r4478 - trunk/mapbender/tools

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Aug 4 11:11:24 EDT 2009


Author: christoph
Date: 2009-08-04 11:11:24 -0400 (Tue, 04 Aug 2009)
New Revision: 4478

Added:
   trunk/mapbender/tools/mod_mailAbo.php
Log:


Added: trunk/mapbender/tools/mod_mailAbo.php
===================================================================
--- trunk/mapbender/tools/mod_mailAbo.php	                        (rev 0)
+++ trunk/mapbender/tools/mod_mailAbo.php	2009-08-04 15:11:24 UTC (rev 4478)
@@ -0,0 +1,125 @@
+<?php
+# $Id: mod_monitorCapabilities_main.php 1240 2007-10-24 09:27:00Z baudson $
+# http://www.mapbender.org/index.php/Monitor_Capabilities
+# 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__)."/../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../http/classes/class_administration.php");
+require_once(dirname(__FILE__)."/../http/classes/class_user.php");
+
+$admin = new administration();
+
+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["layer_id"];
+}
+
+//Herauslesen der User die in der Tabelle mb_user_abo_ows eingetragen sind
+$sql = "SELECT DISTINCT fkey_mb_user_id FROM mb_user_abo_ows";
+$res = db_query($sql);
+
+$cnt = 0;
+$user_id_all=array();
+while($row = db_fetch_array($res)){
+	echo $cnt."\n";
+	$user_id_all[] = $row["fkey_mb_user_id"];
+	echo "User_id: ". $row["fkey_mb_user_id"] ."\n";
+	$cnt++;
+}
+
+$cnt=0;
+echo "\nZahl der eingetragenen User IDs: " . count($user_id_all) . "\n";
+
+for ($iz = 0; $iz < count($user_id_all); $iz++) {
+	$userid = $user_id_all[$iz];
+	echo "User: ".$userid."\n";
+	
+	//Herauslesen abonnierten Dienste aus Tabelle mb_user_abo_ows
+	$sql="SELECT fkey_wms_id FROM mb_user_abo_ows WHERE fkey_mb_user_id = $1";
+	$v=array($userid);
+	$t=array('i');
+	$res=db_prep_query($sql,$v,$t);
+	$cnt = 0;
+	//Initialisieren des Arrays
+	$wms_id_all=array();
+
+	echo "Alle abonnierten WMS des Users:\n";
+	//Herauslesen der Ergebnisse
+	while($row = db_fetch_array($res)){
+		$wms_id_all[$cnt] = $row["fkey_wms_id"];
+		$cnt++;
+	}
+	echo "WMS: " . implode(",", $wms_id_all) . "\n";
+	
+	$mailhead="";
+	$body="";
+	//Auslesen der Monitoring Ergebnisse aus mb_monitor
+	for ($iz2=0; $iz2<count($wms_id_all);$iz2++){
+		$wmsid = $wms_id_all[$iz2];
+		#echo "WMS: ".$wmsid."\n";
+		$sql = "SELECT status, status_comment, to_timestamp(timestamp_end) " . 
+			"AS timestamp_end FROM mb_monitor WHERE fkey_wms_id = $1 " . 
+			"ORDER BY timestamp_end DESC LIMIT 1";
+		$v = array($wmsid);
+		$t = array('i');
+		$res=db_prep_query($sql,$v,$t);
+
+		//Herauslesen der Ergebnisse
+		$row = db_fetch_array($res);
+		$wms_monitor_status = $row["status"];
+		$wms_monitor_status_comment = $row["status_comment"];
+		$wms_monitor_timestamp_end = $row["timestamp_end"];
+		
+		echo "WMS mit Problemen:\n";
+		#read wms_title
+		$sql="SELECT wms_title FROM wms WHERE wms_id = $1";
+		$v_wms_t = array($wmsid);
+		$t_wms_t = array('i');
+		$res_wms_t = db_prep_query($sql, $v_wms_t, $t_wms_t);
+		$row_wms_t = db_fetch_array($res_wms_t);
+		
+		if ($wms_monitor_status == '-1') {
+			echo "WMS: ".$wmsid."\n";
+			$body .= "WMS \'" . $row_wms_t["wms_title"] . " \' mit ID: " . 
+				$wmsid . " nicht erreichbar! (" . $wms_monitor_timestamp_end . 
+				")\nMetadaten: http://www.geoportal.rlp.de/mapbender/x_geoportal/mod_layerMetadata.php?id=" . 
+				getRootLayerId ($wmsid)."\n\n";
+		}			
+	}
+	//Absenden der Mail an einzelnen User (falls ein Dienst nicht erreichbar ist)
+	if ($body) {
+		$body .= "\nDas Geoportal.rlp hat Probleme beim Zugriff auf die oben in dieser E-Mail genannten Dienste. Es ist möglich, dass diese kurzfristig nicht verfügbar sind. Weitere Informationen erhalten Sie auf Anfrage beim Dienstebereitsteller, der in den Metadaten des Dienstes angegeben ist. Folgen Sie dazu dem oben in dieser E-Mail aufgeführten Link.\n Hinweis: Diese E-Mail wurde automatisiert erzeugt und der Versand von Ihnen beantragt. Diese E-Mail-Benachrichtigung können Sie jederzeit abbestellen, indem Sie das Abonnement über die Metadatenanzeige im GeoPortal.rlp deaktivieren.\n http://www.geoportal.rlp.de";
+
+		$time = strval(time()-2);
+		$error_msg = "";
+		if ($admin->getEmailByUserId($userid)) {
+		$admin->sendEmail(MAILADMIN, MAILADMINNAME, $admin->getEmailByUserId($userid), $user, "GeoPortal.rlp WMS Abo Mitteilung " . date("F j, Y, G:i:s", $time), utf8_decode($body), &$error_msg);
+		}
+		else {
+			$error_msg = "Email address of user '" . $admin->getUserNameByUserId($userid) . "' unknown!\n";
+		}
+		if ($error_msg) {
+			echo "\n ERROR: " . $error_msg;
+		}
+	}
+}
+		
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list