[Mapbender-commits] r10030 - trunk/mapbender/http/php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Jan 17 08:47:07 PST 2019
Author: armin11
Date: 2019-01-17 08:47:07 -0800 (Thu, 17 Jan 2019)
New Revision: 10030
Added:
trunk/mapbender/http/php/mod_exportWmc.php
Log:
First draft of a script to export mapbender wmc docs as ows context documents
Added: trunk/mapbender/http/php/mod_exportWmc.php
===================================================================
--- trunk/mapbender/http/php/mod_exportWmc.php (rev 0)
+++ trunk/mapbender/http/php/mod_exportWmc.php 2019-01-17 16:47:07 UTC (rev 10030)
@@ -0,0 +1,62 @@
+<?php
+require_once dirname(__FILE__) . "/../../core/globalSettings.php";
+require_once(dirname(__FILE__)."/../classes/class_owsContext.php");
+
+//set default request parameters
+$wmcId = null;
+$outputModel = "OWC";
+$outputEncoding = "atom";
+
+$sessionUserId = Mapbender::session()->get("mb_user_id");
+if ($sessionUserId !== false) {
+ $userId = $sessionUserId;
+} else {
+ if (DEFINED("PUBLIC_USER") && PUBLIC_USER !== false && PUBLIC_USER !== "") {
+ $userId = PUBLIC_USER;
+ }
+}
+//parse request parameters
+if (isset($_REQUEST["wmcId"]) & $_REQUEST["wmcId"] != "") {
+ //validate to csv integer list
+ $testMatch = $_REQUEST["wmcId"];
+ $pattern = '/^[\d,]*$/';
+ if (!preg_match($pattern,$testMatch)){
+ echo 'Parameter <b>wmcId</b> is not a valid integer.<br/>';
+ die();
+ }
+ $wmcId = $testMatch;
+ $testMatch = NULL;
+}
+$wmcExists = false;
+if ($wmcId !== null) {
+ //try to test if given wmcId is either owned by the current user or public
+ $sql = "SELECT wmc_serial_id FROM mb_user_wmc WHERE (wmc_serial_id = $1 AND fkey_user_id = $2) OR (wmc_serial_id = $3 AND wmc_public = 1)";
+ $t = array('i', 'i', 'i');
+ $v = array($wmcId, $userId, $wmcId);
+ $res = db_prep_query($sql,$v,$t);
+ if (!$res) {
+ echo "Error while trying to find wmc in database!";
+ die();
+ } else {
+ while($row = db_fetch_array($res)){
+ //echo "WMC found with id <b>".$row["wmc_serial_id"]."</b> found in DB<br>";
+ $wmcExists = true;
+ $existingWmcId = $row["wmc_serial_id"];
+ }
+ }
+} else {
+ echo 'Mandatory parameter <b>wmcId</b> not given.<br/>';
+ die();
+}
+if ($wmcExists) {
+ //echo "WMC with id ".$existingWmcId." found and will be exported!";
+ $owsContext = new OwsContext();
+ //$owsContextResource = new OwsContextResource();
+ //$owsContext->addResource($owsContextResource);
+ $owsContext->readFromInternalWmc($existingWmcId);
+ echo $owsContext->export("atom");
+} else {
+ echo "WMC with id ".$wmcId." not found!";
+}
+
+?>
More information about the Mapbender_commits
mailing list