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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Jan 21 06:06:23 PST 2016


Author: armin11
Date: 2016-01-21 06:06:22 -0800 (Thu, 21 Jan 2016)
New Revision: 9384

Modified:
   trunk/mapbender/http/php/mod_UsageShow.php
Log:
Enhance little module to also show wfs log entries

Modified: trunk/mapbender/http/php/mod_UsageShow.php
===================================================================
--- trunk/mapbender/http/php/mod_UsageShow.php	2016-01-21 09:32:21 UTC (rev 9383)
+++ trunk/mapbender/http/php/mod_UsageShow.php	2016-01-21 14:06:22 UTC (rev 9384)
@@ -34,14 +34,13 @@
 <body>
 <?php
 $admin = new administration();
-//Test if ID was valid
-if ($_REQUEST['wmsid']) {
+
+if (isset($_REQUEST['wmsid'])) {
 	$wms_id = intval($_GET['wmsid']); 
-}
-else {
-	echo "Invalid WMS ID.";
-	die;
-}
+	$serviceType = "wms";
+	$serviceTypeAbbr = "m";
+	$serviceId = $wms_id;
+} 
 //Test if userid was valid
 if ($_REQUEST['userid']) {
 	$userid = intval($_REQUEST['userid']); 
@@ -52,42 +51,58 @@
 //}
 //Test if User Id exists in db
 
+//Test if ID was valid
+if (isset($_REQUEST['wfsid'])) {
+	$wfs_id = intval($_GET['wfsid']); 
+	$serviceType = "wfs";
+	$serviceTypeAbbr = "f";	
+	$serviceId = $wfs_id;
+}
 
-
-
-
-
-
 //Test if current User is Owner of the service
 //get owners of the wms:
-$wmsOwners = $admin->getOwnerByWms($wms_id);
-echo $wmsOwners;
-if (!(in_array(Mapbender::session()->get("mb_user_id"), $wmsOwners))) {
-	echo "User with ID: ".Mapbender::session()->get("mb_user_id")." - You have no rights to see the requested pages!";
-	//echo "<br> You are: ".$admin->getOwnerByWms($wms_id);
-	die;
+switch ($serviceType) {
+	case 'wms':
+		$owners = $admin->getOwnerByWms($serviceId);
+		if (!(in_array(Mapbender::session()->get("mb_user_id"), $owners))) {
+			echo "User with ID: ".Mapbender::session()->get("mb_user_id")." - You have no rights to see the requested pages!";
+			die;
+		} else {
+			echo "OwnerID: ".Mapbender::session()->get("mb_user_id")."<br>";
+		}
+	break;
+	case 'wfs':
+		$owners = $admin->getOwnerByWfs($serviceId);
+		if (!(Mapbender::session()->get("mb_user_id") == $owners)) {
+			echo "User with ID: ".Mapbender::session()->get("mb_user_id")." - You have no rights to see the requested pages!";
+			die;
+		} else {
+			echo "OwnerID: ".Mapbender::session()->get("mb_user_id")."<br>";
+		}
+	break;
 }
-else {
-	echo "OwnerID: ".Mapbender::session()->get("mb_user_id")."<br>";
-}
 
-
 if (!isset($_REQUEST['userid'])){
 
 //List Users wich have used the service - read the log table
 $sql = "SELECT distinct fkey_mb_user_id, mb_user_name, mb_user_email, mb_user_phone from mb_proxy_log, mb_user ";
-$sql .= " WHERE fkey_wms_id = $1 AND fkey_mb_user_id = mb_user_id";
+$sql .= " WHERE fkey_w".$serviceTypeAbbr."s_id = $1 AND fkey_mb_user_id = mb_user_id";
 
-#$sql = "SELECT upload_id, status, status_comment, timestamp_begin, timestamp_end, upload_url, updated FROM mb_monitor ";
-#$sql .= "WHERE fkey_wms_id = $1 AND NOT status = '-2' ORDER BY upload_id DESC";
-$v = array($wms_id);
+$v = array($serviceId);
 $t = array('i');
 $res = db_prep_query($sql,$v,$t);
 $cnt = 0;
 
-
-$str = "<span style='font-size:30'>Usage for WMS: </span><hr><br>\n";
-$str .= "<b>" . $wms_id . "</b><br>" . $admin->getWmsTitleByWmsId($wms_id) . "<br><br><br>\n";
+$str = "<span style='font-size:30'>Usage for W".strtoupper($serviceTypeAbbr)."S: </span><hr><br>\n";
+switch ($serviceType) {
+	case 'wms':
+		$serviceTitle = $admin->getWmsTitleByWmsId($serviceId);
+	break;
+	case 'wfs':
+		$serviceTitle = $admin->getWfsTitleByWfsId($serviceId);
+	break;
+}
+$str .= "<b>" . $serviceId . "</b><br>" . $serviceTitle . "<br><br><br>\n";
 $str .= "<table cellpadding=10 cellspacing=0 border=0>";
 $str .= "<tr bgcolor='#dddddd'>";
 $str .= "<th align='left'>Index</th><th align='left'>ID</th><th align='left'>User Name</th><th align='left'>User Email</th>";
@@ -113,7 +128,7 @@
 	#else {
 	#	$response_time[$cnt] = "n/a"; 
 	#}
-	$str .= "<td><input type=button value='details' onclick=\"var newWindow = window.open('../php/mod_UsageShow.php?wmsid=".$_REQUEST['wmsid']."&userid=".$UserId[$cnt]."','details','width=500,height=700,scrollbars');newWindow.href.location='Usage of Service: ".$wms_id."'\"></td>";
+	$str .= "<td><input type=button value='details' onclick=\"var newWindow = window.open('../php/mod_UsageShow.php?w".$serviceTypeAbbr."sid=".$serviceId."&userid=".$UserId[$cnt]."','details','width=500,height=700,scrollbars');newWindow.href.location='Usage of Service: ".$serviceId."'\"></td>";
 	$str .= "</tr>";
 	$cnt++;
 }
@@ -123,7 +138,6 @@
 else {
 //UserID was set
 //Get infos about specific user
-
 $sql = "SELECT mb_user_id, mb_user_name, mb_user_email, mb_user_phone from mb_user ";
 $sql .= " WHERE mb_user_id = $1";
 $v = array($_REQUEST['userid']);
@@ -131,21 +145,27 @@
 $res = db_prep_query($sql,$v,$t);
 $row = db_fetch_array($res);
 
+//show usage of this user
+switch ($serviceType) {
+	case 'wms':
+		$sql = "SELECT count(*) as sumrequests, sum(pixel) as sumelements , max(proxy_log_timestamp) as lastaccess FROM mb_proxy_log where fkey_mb_user_id=$2 AND fkey_wms_id=$1";
+	break;
+	case 'wfs':
+		$sql = "SELECT count(*) as sumrequests, sum(features) as sumelements , max(proxy_log_timestamp) as lastaccess FROM mb_proxy_log where fkey_mb_user_id=$2 AND fkey_wfs_id=$1";
+	break;
+}
 
-//show usage of this user
-$sql = "SELECT count(*) as sumrequests, sum(pixel) as sumpixel , max(proxy_log_timestamp) as lastaccess FROM mb_proxy_log where fkey_mb_user_id=$2 AND fkey_wms_id=$1";
-//$sql .= " WHERE fkey_wms_id = $1 AND fkey_mb_user_id = mb_user_id";
-$v = array($wms_id,$_REQUEST['userid']);
+$v = array($serviceId, $_REQUEST['userid']);
 $t = array('i','i');
 $res = db_prep_query($sql,$v,$t);
 $row = db_fetch_array($res);
+
 $sumrequests = $row["sumrequests"];
-$sumpixel = $row["sumpixel"];
+$sumelements = $row["sumelements"];
 $lastAccess = $row["lastaccess"];
 
-//$sumpixel=0;
-$str = "<span style='font-size:30'>Usage of Secured WMS: </span><hr><br>\n";
-$str .= "<b>" . $wms_id . "</b><br>" . $admin->getWmsTitleByWmsId($wms_id) . "<br><br><br>\n";
+$str = "<span style='font-size:30'>Usage of Secured W".strtoupper($serviceTypeAbbr)."S: </span><hr><br>\n";
+$str .= "<b>" . $serviceId . "</b><br>" . $serviceTitle . "<br><br><br>\n";
 $str .= "<hr><b>for User: ".$row['mb_user_name']."</b><br><br>";
 $str .= "UserID: ".$_REQUEST['userid']."<br>UserEmail: ".$row['mb_user_email']."<br>UserPhone: ".$row['mb_user_phone']."<br>Last Access: <b>".$lastAccess."</b><br>";
 
@@ -155,36 +175,58 @@
 //case showSingleRequests
 if (($_REQUEST['requests']) & ($_REQUEST['requests']) == 1 ) {
 	//show usage of this user
-	$sql = "SELECT proxy_log_timestamp, pixel, request FROM mb_proxy_log where fkey_mb_user_id=$2 AND fkey_wms_id=$1 ORDER BY proxy_log_timestamp DESC LIMIT ".$maxRequests;
-	$v = array($wms_id,$_REQUEST['userid']);
+	
+	$sql = "SELECT proxy_log_timestamp, pixel, features, request FROM mb_proxy_log where fkey_mb_user_id=$2 AND fkey_w".$serviceTypeAbbr."s_id=$1 ORDER BY proxy_log_timestamp DESC LIMIT ".$maxRequests;
+	
+	$v = array($serviceId, $_REQUEST['userid']);
 	$t = array('i','i');
 	$res = db_prep_query($sql,$v,$t);
 	$cnt=0;
 	$str .= "<hr><br><b>Last ".$maxRequests." Requests:</b><br>";
 	$str .= "<table cellpadding=10 cellspacing=0 border=0>";
 	$str .= "<tr bgcolor='#dddddd'>";
-	$str .= "<th align='left'>timestamp</th><th align='left'>requested pixels</th><th align='left'>GetMap Request</th></tr>";
+	$str .= "<th align='left'>timestamp</th><th align='left'>requested pixels/features</th><th align='left'>GetMap / GetFeature Request</th></tr>";
 	while ($row = db_fetch_array($res)) {
 		$str .= "\n\t\t<tr bgcolor='#e6e6e6'>";
 		$timestamp[$cnt] = db_result($res,$cnt,"proxy_log_timestamp");
 		$str .= "\n\t\t\t<td>".$timestamp[$cnt]."</td>";
-		$pixels[$cnt] = db_result($res,$cnt,"pixel");
-		//$sumpixel=$sumpixel+$pixels[$cnt];
-		$str .= "\n\t\t\t<td>".$pixels[$cnt]."</td>";
+		switch($serviceType){
+			case 'wms':
+				$elements[$cnt] = db_result($res,$cnt,"pixel");
+			break;
+			case 'wfs':
+				$elements[$cnt] = db_result($res,$cnt,"features");
+			break;
+		}
+		$str .= "\n\t\t\t<td>".$elements[$cnt]."</td>";
 		$request[$cnt] = db_result($res,$cnt,"request");
-		$str .= "\n\t\t\t<td><input type=button value='Show Map' onclick=\"var newWindow = window.open('".$request[$cnt]."','GetMap','width=500,height=700,scrollbars');newWindow.href.location='Get Map from: ".$timestamp[$cnt]."'\"></td>";
+		switch($serviceType){
+			case 'wms':
+				$str .= "\n\t\t\t<td><input type=button value='Show Map' onclick=\"var newWindow = window.open('".$request[$cnt]."','GetMap','width=500,height=700,scrollbars');newWindow.href.location='Get Map from: ".$timestamp[$cnt]."'\"></td>";
+			break;
+			case 'wfs':
+				$str .= "\n\t\t\t<td><input type=button value='Show Features' onclick=\"var newWindow = window.open('".$request[$cnt]."','GetFeature','width=500,height=700,scrollbars');newWindow.href.location='GetFeature from: ".$timestamp[$cnt]."'\"></td>";
+			break;
+		}
 		$str .= "</tr>";
 		$cnt++;
 	}
 }
 
 $str .= "<hr><b>Total Requests: ".$sumrequests."</b><br><br>";
-$sumpixel=$sumpixel/1000000;
-$str .= "<hr><b>Total MegaPixel: ".$sumpixel."</b><br><br>";
+switch($serviceType){
+	case 'wms':
+		$sumelements=$sumelements/1000000;
+		$str .= "<hr><b>Total MegaPixel: ".$sumelements."</b><br><br>";
+	break;
+	case 'wfs':
+		$str .= "<hr><b>Total amount of features: ".$sumelements."</b><br><br>";
+	break;
+}
+
 if (!$_REQUEST['requests']) {
-		$str .= "<input type=button value='Show last ".$maxRequests." Requests' onclick=\"var newWindow = window.open('../php/mod_UsageShow.php?wmsid=".$_REQUEST['wmsid']."&userid=".$_REQUEST["userid"]."&requests=1','details','width=500,height=700,scrollbars');newWindow.href.location='Show Requests: ".$timestamp[$cnt]."'\">";
+		$str .= "<input type=button value='Show last ".$maxRequests." Requests' onclick=\"var newWindow = window.open('../php/mod_UsageShow.php?w".$serviceTypeAbbr."sid=".$serviceId."&userid=".$_REQUEST["userid"]."&requests=1','details','width=500,height=700,scrollbars');newWindow.href.location='Show Requests: ".$timestamp[$cnt]."'\">";
 	}
-
 }
 
 echo $str;



More information about the Mapbender_commits mailing list