[Mapbender-commits] r10296 - in trunk/mapbender/http: classes php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Oct 21 08:57:49 PDT 2019


Author: armin11
Date: 2019-10-21 08:57:49 -0700 (Mon, 21 Oct 2019)
New Revision: 10296

Added:
   trunk/mapbender/http/php/mod_invokeApplicationFromMetadata.php
Modified:
   trunk/mapbender/http/classes/class_metadata.php
Log:
Option to count invocation of application from catalogue search interface

Modified: trunk/mapbender/http/classes/class_metadata.php
===================================================================
--- trunk/mapbender/http/classes/class_metadata.php	2019-10-21 13:24:44 UTC (rev 10295)
+++ trunk/mapbender/http/classes/class_metadata.php	2019-10-21 15:57:49 UTC (rev 10296)
@@ -854,6 +854,9 @@
 			$this->applicationJSON->application->srv[$i]->mdLink = $this->protocol."://".$this->hostName."/mapbender/php/mod_iso19139ToHtml.php?url=".urlencode($this->protocol."://".$this->hostName."/mapbender/php/mod_dataISOMetadata.php?outputFormat=iso19139&id=").$applicationMatrix[$i]['fileidentifier'];
 			//TODO: preview?
 			//TODO: preview and access url should be generated by class_administration.php
+			//
+			$accessUrl = $this->protocol."://".$this->hostName."/mapbender/php/mod_invokeApplicationFromMetadata.php?id=".$applicationMatrix[$i]['metadata_id'];
+			
 			$admin = new administration();
 			$notNullElements = array('fkey_gui_id', 'fkey_mapviewer_id', 'fkey_wmc_serial_id');
                         foreach($notNullElements as $notNullElement) {
@@ -861,11 +864,11 @@
 				$applicationMatrix[$i][$notNullElement] = false;
 			    }
 			}
-if (($applicationMatrix[$i]['fkey_gui_id'] != false && $applicationMatrix[$i]['fkey_mapviewer_id'] != false) || ($applicationMatrix[$i]['fkey_wmc_serial_id'] != false && $applicationMatrix[$i]['fkey_mapviewer_id'] != false)) {
+/*if (($applicationMatrix[$i]['fkey_gui_id'] != false && $applicationMatrix[$i]['fkey_mapviewer_id'] != false) || ($applicationMatrix[$i]['fkey_wmc_serial_id'] != false && $applicationMatrix[$i]['fkey_mapviewer_id'] != false)) {
 $accessUrl = $admin->getMapviewerInvokeUrl($applicationMatrix[$i]['fkey_mapviewer_id'], $applicationMatrix[$i]['fkey_gui_id'], $applicationMatrix[$i]['fkey_wmc_serial_id']);
 } else {
 $accessUrl = $applicationMatrix[$i]['link'];
-}
+}*/
 $previewUrl = $admin->getMetadataPreviewUrl($applicationMatrix[$i]['metadata_id']);
 $this->applicationJSON->application->srv[$i]->accessURL = $accessUrl;
 			$this->applicationJSON->application->srv[$i]->previewURL = $previewUrl;

Added: trunk/mapbender/http/php/mod_invokeApplicationFromMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_invokeApplicationFromMetadata.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_invokeApplicationFromMetadata.php	2019-10-21 15:57:49 UTC (rev 10296)
@@ -0,0 +1,66 @@
+<?php
+require_once dirname(__FILE__) . "/../../core/globalSettings.php";  
+require_once dirname(__FILE__) . "/../classes/class_administration.php"; 
+//parse id from application (metadata_id)
+if (isset($_REQUEST["id"]) & $_REQUEST["id"] != "") {
+	//validate to integer
+	$testMatch = $_REQUEST["id"];
+	$pattern = '/^[\d]*$/';		
+ 	if (!preg_match($pattern,$testMatch)){ 
+		//echo 'id: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		echo 'Parameter <b>id</b> is not valid integer.<br/>'; 
+		die(); 		
+ 	}
+	$id = $testMatch;
+	$testMatch = NULL;
+}
+
+//select application from mb_metadata by id
+$sql = "SELECT metadata_id, link, fkey_wmc_serial_id, fkey_gui_id, fkey_mapviewer_id FROM mb_metadata WHERE metadata_id = $1 AND type = 'application'";
+$v = array($id);
+$t = array('i');
+$res = db_prep_query($sql, $v, $t);
+if ($res) {
+    $row = db_fetch_array($res);
+    if (isset($row['metadata_id'])) {
+        $admin = new administration();
+        $notNullElements = array('fkey_gui_id', 'fkey_mapviewer_id', 'fkey_wmc_serial_id');
+        foreach($notNullElements as $notNullElement) {
+            if ($row[$notNullElement] == '' || $row[$notNullElement] == null) {
+                $row[$notNullElement] = false;
+            }
+        }
+        if (($row['fkey_gui_id'] != false && $row['fkey_mapviewer_id'] != false) || ($row['fkey_wmc_serial_id'] != false && $row['fkey_mapviewer_id'] != false)) {
+            $accessUrl = $admin->getMapviewerInvokeUrl($row['fkey_mapviewer_id'], $row['fkey_gui_id'], $row['fkey_wmc_serial_id']);
+        } else {
+            $accessUrl = $row['link'];
+        }
+	
+        //before redirect to the url - increment load count
+        $sql = "SELECT fkey_metadata_id FROM metadata_load_count WHERE fkey_metadata_id = $1";
+        $v = array($id);
+        $t = array('i');
+        $res = db_prep_query($sql, $v, $t);
+        if ($res) {
+            $row = db_fetch_array($res);
+	    if (isset($row['fkey_metadata_id'])) {
+	        $sql = "UPDATE metadata_load_count SET load_count = (load_count + 1) WHERE fkey_metadata_id = $1"; 
+                $v = array($id);
+                $t = array('i');
+	        $res = db_prep_query($sql, $v, $t);
+	    } else {
+                $sql = "INSERT INTO metadata_load_count (fkey_metadata_id, load_count) VALUES ($1, 1)";
+                $v = array($id);
+                $t = array('i');
+	        $res = db_prep_query($sql, $v, $t);
+            }
+	}
+//echo $accessUrl;
+        header("Location: ".$accessUrl);
+    } else {
+        echo "no metadata found with id = ".$id;
+    }
+} else {
+    echo "No accessUrl for the requested application found in database!";
+}
+?>



More information about the Mapbender_commits mailing list