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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Feb 1 07:53:20 PST 2018


Author: armin11
Date: 2018-02-01 07:53:20 -0800 (Thu, 01 Feb 2018)
New Revision: 9857

Modified:
   trunk/mapbender/http/php/mod_monitorCapabilities_read.php
Log:
Fix for wms monitoring table - further things needed for wfs monitoring table

Modified: trunk/mapbender/http/php/mod_monitorCapabilities_read.php
===================================================================
--- trunk/mapbender/http/php/mod_monitorCapabilities_read.php	2018-02-01 11:46:54 UTC (rev 9856)
+++ trunk/mapbender/http/php/mod_monitorCapabilities_read.php	2018-02-01 15:53:20 UTC (rev 9857)
@@ -18,7 +18,9 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 $e_id = "monitor_results";
-//$gui_id = $_REQUEST["guiID"];
+$gui_id = $_REQUEST["guiID"];
+$serviceType = $_REQUEST["serviceType"];
+
 //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");
@@ -38,91 +40,85 @@
 $admin = new administration();
 $user = new User();
 
-// update selected wms
-$checkboxes = intval($_POST['cbs']);
 
-for ($i=0; $i < $checkboxes; $i++) {
-	echo $i;
-	if (!isset($_POST['cb'.$i]) || 
-		!isset($_POST['upl_id'.$i])
-	) {
-		continue;
-	}	
-	$upd_wmsid = intval($_POST['cb'.$i]);
-	$upload_id = intval($_POST['upl_id'.$i]);
-	
-	if ($upd_wmsid) {
-		
-		// get upload URL
-		$sql = "SELECT wms_upload_url, wms_owner FROM wms WHERE wms_id = $1";
-		$v = array($upd_wmsid);
-		$t = array("i");
-		$res = db_prep_query($sql, $v, $t);
-		$row = db_fetch_array($res);
-		$uploadUrl = $row["wms_upload_url"];
-		$wmsOwner = $row["wms_owner"];
-		
-		if ($wmsOwner !== $user->id) {
-			echo "<br>Skipped: " . $upd_wmsid . "<br>";
-			continue;
-		}
-		
-		// update WMS from upload URL
-		$mywms = new wms();
-		$result = $mywms->createObjFromXML($uploadUrl);
-
-		if (!$result['success']) {
-	    		//echo $result['message']; //do nothing first - TODO give negative result!
-	    		//die();
-		} else {
-			$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;
+switch ($serviceType) {
+	case "WMS":
+		$checkboxes = intval($_POST['cbs']);
+		for ($i=0; $i < $checkboxes; $i++) {
+			echo $i;
+			if (!isset($_POST['cb'.$i]) || 
+				!isset($_POST['upl_id'.$i])
+			) {
+				continue;
 			}	
-			$mywms->updateObjInDB($upd_wmsid);
-			echo "<br>Updated: " . $upd_wmsid . "<br>";
-		}
-	/*
-			// start new monitoring for this WMS
-			$now = time();
-			$sql = "UPDATE mb_monitor SET status = '-2', status_comment = 'Monitoring is still in progress...', " . 
-			"timestamp_begin = $1, timestamp_end = $2 WHERE upload_id = $3 AND fkey_wms_id = $4";
-			$v = array($now, $now, $upload_id, $upd_wmsid);
-			$t = array('s', 's', 's', 'i');
-			$res = db_prep_query($sql,$v,$t);
+			$upd_wmsid = intval($_POST['cb'.$i]);
+			$upload_id = intval($_POST['upl_id'.$i]);
+			if ($upd_wmsid) {
+				// get upload URL
+				$sql = "SELECT wms_upload_url, wms_owner FROM wms WHERE wms_id = $1";
+				$v = array($upd_wmsid);
+						$t = array("i");
+				$res = db_prep_query($sql, $v, $t);
+				$row = db_fetch_array($res);
+				$uploadUrl = $row["wms_upload_url"];
+				$wmsOwner = $row["wms_owner"];
+				if ($wmsOwner !== $user->id) {
+					echo "<br>Skipped: " . $upd_wmsid . "<br>";
+					continue;
+				}
+						// update WMS from upload URL
+						$mywms = new wms();
+				$result = $mywms->createObjFromXML($uploadUrl);
+						if (!$result['success']) {
+			    		//echo $result['message']; //do nothing first - TODO give negative result!
+					    		//die();
+				} else {
+					$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>";
+				}
+				/*
+				// start new monitoring for this WMS
+				$now = time();
+				$sql = "UPDATE mb_monitor SET status = '-2', status_comment = 'Monitoring is still in progress...', " . 
+				"timestamp_begin = $1, timestamp_end = $2 WHERE upload_id = $3 AND fkey_wms_id = $4";
+				$v = array($now, $now, $upload_id, $upd_wmsid);
+				$t = array('s', 's', 's', 'i');
+				$res = db_prep_query($sql,$v,$t);
 
-			$currentFilename = "wms_monitor_report_" . $upload_id . "_" . 
-			$upd_wmsid . "_" . $wmsOwner . ".xml";		
-			$exec = PHP_PATH . "php5 ../../tools/mod_monitorCapabilities_write.php " . 
+				$currentFilename = "wms_monitor_report_" . $upload_id . "_" . 
+				$upd_wmsid . "_" . $wmsOwner . ".xml";		
+				$exec = PHP_PATH . "php5 ../../tools/mod_monitorCapabilities_write.php " . 
 				$currentFilename. " 0";
-			echo exec(escapeshellcmd($exec));
-	*/
-	}
-	echo "<br>Please note: The updated services need to be monitored again in order to update the database.<br><br>";
+				echo exec(escapeshellcmd($exec));
+				*/
+			}
+			echo "<br>Please note: The updated services need to be monitored again in order to update the database.<br><br>";
+		}
+		break;
+	case "WFS":
+		break;
 }
-$e = new mb_exception("mod_monitorCapabilities_read.php: userId: ".$_SESSION["mb_user_id"]);
-$sql = "SELECT DISTINCT mb_monitor.fkey_wms_id FROM mb_monitor, wms " . 
-	"WHERE mb_monitor.fkey_wms_id = wms.wms_id AND wms.wms_owner = $1";
 
+//$e = new mb_exception("mod_monitorCapabilities_read.php: userId: ".$_SESSION["mb_user_id"]);
+$sql = "SELECT mb_wms_availability.* FROM mb_wms_availability, wms " . 
+	"WHERE mb_wms_availability.fkey_wms_id = wms.wms_id AND wms.wms_owner = $1";
 $res = db_prep_query($sql, array($_SESSION["mb_user_id"]), array("i"));
 
 $wms = array();
-
-while($row = db_fetch_array($res)){
-	$wms[] = $row["fkey_wms_id"];
-	$e = new mb_exception("mod_monitorCapabilities_read.php: wmsId: ".$row["fkey_wms_id"]);
-}
 $wms_id = array();
-$status = array();
+
 $upload_id = array();
 $avg_response_time = array();
 $comment = array();
@@ -132,72 +128,23 @@
 $updated = array();
 $mapurl = array();
 $image = array();
+$status = array();
 
-for ($i = 0; $i < count($wms); $i++) {
-	$wms_id[$wms[$i]] = $wms[$i];
-	// get upload id
-	$sql = "SELECT MAX(upload_id) FROM mb_monitor WHERE fkey_wms_id = $1";
-	$v = array($wms[$i]);
-	$t = array('i');
-	$res = db_prep_query($sql,$v,$t);
-	$upload_id[$wms[$i]] = db_result($res,0,0);
-
-	$sql = "SELECT AVG(timestamp_begin), AVG(timestamp_end) FROM mb_monitor " . 
-		"WHERE fkey_wms_id = $1 AND NOT status = '-1' AND NOT status = '-2'";
-	$v = array($wms[$i]);
-	$t = array('i');
-	$res = db_prep_query($sql,$v,$t);
-	if (db_result($res,0,1) == 0 && db_result($res,0,0) == 0) {
-		$avg_response_time[$wms[$i]] = NULL;	
-	}
-	else {
-		$avg_response_time[$wms[$i]] = round(db_result($res,0,1)-db_result($res,0,0), 1);
-	}
-	
-	$sql = "SELECT status, status_comment, timestamp_begin, timestamp_end, " . 
-		"upload_url, updated, image, map_url, cap_diff FROM mb_monitor, wms " . 
-		"WHERE upload_id = $1 AND fkey_wms_id = $2 AND wms_owner = $3 ORDER BY status, " . 
-		"status_comment, timestamp_end, fkey_wms_id";
-	$v = array($upload_id[$wms[$i]], $wms_id[$wms[$i]], $user->id);
-	$t = array('s', 'i', 'i');
-	$res = db_prep_query($sql,$v,$t);
-
-	$status[$wms[$i]] = intval(db_result($res,0,"status"));
-	$comment[$wms[$i]] = db_result($res,0,"status_comment");
-	$timestamp_begin[$wms[$i]] = db_result($res,0,"timestamp_begin");
-	$timestamp_end[$wms[$i]] = db_result($res,0,"timestamp_end");
-	$upload_url[$wms[$i]] = db_result($res,0,"upload_url");
-	$updated[$wms[$i]] = db_result($res,0,"updated");
-	$mapurl[$wms[$i]] = db_result($res,0,"map_url");
-	$image[$wms[$i]] = db_result($res,0,"image");
-	$cap_diff[$wms[$i]] = db_result($res,0,"cap_diff");
-	
- 	if ($status[$wms[$i]] == -2 && 
-		intval(time())-intval($timestamp_begin[$wms[$i]]) > intval(TIME_LIMIT)) 
-	{
-		$comment[$wms[$i]] = "Monitoring process timed out.";	
-		
-		$new_sql = "UPDATE mb_monitor SET status = '-1', status_comment = 'Monitoring process timed out.', timestamp_end = $1 WHERE fkey_wms_id = $2 AND upload_id = $3";
-		$new_v = array((intval($upload_id[$wms[$i]])+intval(TIME_LIMIT)), $wms_id[$wms[$i]], $upload_id[$wms[$i]]);
-		$new_t = array('s', 'i', 's');
-		$new_res = db_prep_query($new_sql,$new_v,$new_t);
-	}
-
-	$sql = "SELECT COUNT(upload_id) FROM mb_monitor WHERE fkey_wms_id = $1 AND NOT status = '-2'";
-	$v = array($wms[$i]);
-	$t = array('i');
-	$res = db_prep_query($sql, $v, $t);
-	$total[$wms[$i]] = db_result($res, 0, 0);
-
-	$sql = "SELECT COUNT(upload_id) FROM mb_monitor WHERE fkey_wms_id = $1 AND status = '-1'";
-	$v = array($wms[$i]);
-	$t = array('i');
-	$res = db_prep_query($sql, $v, $t);
-	$fail = db_result($res, 0, 0);
-	
-	$percentage[$wms[$i]] = 100 - round(100*floatval($fail)/floatval($total[$wms[$i]]), 1);
+while($row = db_fetch_array($res)){
+	$wms[] = $row["fkey_wms_id"];
+	$wms_id[$row["fkey_wms_id"]] = $row["fkey_wms_id"];
+	$status[$row["fkey_wms_id"]] = $row["last_status"];
+	$comment[$row["fkey_wms_id"]] = $row["status_comment"];
+	$average_resp_time[$row["fkey_wms_id"]] = $row["average_resp_time"];
+	$upload_url[$row["fkey_wms_id"]] = $row["upload_url"];
+	$updated[$row["fkey_wms_id"]] = $row["fkey_upload_id"];
+	$upload_id[$row["fkey_wms_id"]] = $row["fkey_upload_id"];
+	$mapurl[$row["fkey_wms_id"]] = $row["map_url"];
+	$image[$row["fkey_wms_id"]] = $row["image"];
+	$cap_diff[$row["fkey_wms_id"]] = $row["cap_diff"];
+	$percentage[$row["fkey_wms_id"]] = $row["availability"];
+	$total[$row["fkey_wms_id"]] = $row["monitor_count"];
 }
-
 $newArray = $status;
 if ($_GET['sortby']) {
 	if ($_GET['sortby'] == "wms") {
@@ -226,17 +173,18 @@
 	}
 }
 
+$script = $_SERVER["SCRIPT_NAME"]."?guiID=".$gui_id."&";
+
 $str = "<span style='font-size:30'>monitoring results</span><hr><br>\n";
-$str .= "<form name = 'form1' method='post' action='".$_SERVER["SCRIPT_NAME"]."?sortby=".$_GET['sortby']."'>\n\t";
+$str .= "<form name = 'form1' method='post' action='".$script."sortby=".$_GET['sortby']."'>\n\t";
 $str .= "\n\t<input type=submit value='update selected WMS'>\n";
-$str .= "\n\t<input type=button onclick=\"window.location.href='".$_SERVER["SCRIPT_NAME"]."?sortby=".$_GET['sortby']."'\" value='refresh'>\n<br/><br/>\n	";
+$str .= "\n\t<input type=button onclick=\"window.location.href='".$script."sortby=".$_GET['sortby']."'\" value='refresh'>\n<br/><br/>\n	";
 $str .= "<table cellpadding=10 cellspacing=0 border=0>";
-$str .= "<tr bgcolor='#dddddd'><th></th><th align='left'><a href='".$_SERVER["SCRIPT_NAME"]."?sortby=wms'>wms</a></th>";
-$str .= "<th align='left' colspan = 2><a href='".$_SERVER["SCRIPT_NAME"]."?sortby=status'>current status</a></th>";
-$str .= "<th align='left'><a href='".$_SERVER["SCRIPT_NAME"]."?sortby=image'>image</a></th>";
-$str .= "<th align='left'><a href='".$_SERVER["SCRIPT_NAME"]."?sortby=avgresp'>avg. response time</a></th>";
-$str .= "<th align='left'><a href='".$_SERVER["SCRIPT_NAME"]."?sortby=avail'>overall availability</a></th><th></th><th>Diff</th></tr>";
-
+$str .= "<tr bgcolor='#dddddd'><th></th><th align='left'><a href='".$script."sortby=wms'>wms</a></th>";
+$str .= "<th align='left' colspan = 2><a href='".$script."sortby=status'>current status</a></th>";
+$str .= "<th align='left'><a href='".$script."sortby=image'>image</a></th>";
+$str .= "<th align='left'><a href='".$script."sortby=avgresp'>avg. response time</a></th>";
+$str .= "<th align='left'><a href='".$script."sortby=avail'>overall availability</a></th><th></th><th>Diff</th></tr>";
 $cnt = 0;
 foreach ($newArray as $k => $value) {
 	$img = "stop.bmp";
@@ -255,10 +203,9 @@
 	$str .= "\n\t\t\t<td valign='top'><b>" . $wms_id[$k] . "</b><br>" . $admin->getWmsTitleByWmsId($wms_id[$k]) . "</td>";
 	$str .= "\n\t\t\t<td valign='top'><a href='".$upload_url[$k]."' target=_blank><img title='Connect to service' border=0 src = '../img/trafficlights/". $img. "'></a></td>";
 	$str .= "\n\t\t\t<td valign='top'>" . $comment[$k] . "<br><div style='font-size:12'>".date("F j, Y, G:i:s", $upload_id[$k])."</div></td>";
+	//$str .= "\n\t\t\t<td valign='top'>" . $comment[$k] . "<br><div style='font-size:12'>".$upload_id[$k]."</div></td>";
 	$str .= "\n\t\t\t<td valign='top'>";
-
 	$str .= "<table bgcolor='black' border=1 cellspacing=1 cellpadding=0><tr><td height=20 width=20 align=center valign=middle bgcolor='";
-
 	if ($image[$k] == -1) {
 		$str .= "red";
 	}
@@ -304,23 +251,14 @@
 		}
 	}
 	$str .= "</tr></table></td>";
-	
-#	$str .= "\n\t\t\t<td><a href='output_".$wms_id[$k]."_".$max.".txt' target=_blank>log</a></td>";
-
 	$str .= "\n\t\t<td><input type=button value='details' onclick=\"var newWindow = window.open('../php/mod_monitorCapabilities_read_single.php?wmsid=".$wms_id[$k]."','wms','width=500,height=700,scrollbars');newWindow.focus();\"></td>";
 	$str .= "\n\t\t\t<td>";	
-	if ($cap_diff[$k] != "")
-		#$str .= "<a href='mod_monitorCapabilities_read_single_diff.php?wmsid=".$wms_id[$k]."&upload_id=".$upload_id[$k]."' target=_blank>view</a>";
+	if ($cap_diff[$k] != "" && $status[$k] == 0)
 		$str .= "<input type=button value='show' onclick=\"var newWindow = window.open('../php/mod_showCapDiff.php?wmsid=".$wms_id[$k]."','Caps Diff','width=700,height=300,scrollbars');newWindow.focus();\">";
 	$str .= "</td></tr>";
-
-
 	$cnt++;
 }
-
-
 $str .= "\n\t</table>\n\t<br/><input type=hidden name=cbs value='".$cnt."'>\n</form>";
 echo $str;
-
 ?>
 </body></html>



More information about the Mapbender_commits mailing list