[Mapbender-commits] r1841 - branches/mapbender_sld/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Nov 23 08:53:03 EST 2007


Author: christoph
Date: 2007-11-23 08:53:03 -0500 (Fri, 23 Nov 2007)
New Revision: 1841

Added:
   branches/mapbender_sld/http/php/mod_digitize_messages.php
   branches/mapbender_sld/http/php/mod_insertWmcIntoDb.php
   branches/mapbender_sld/http/php/mod_wfs_gazetteer_server.php
Log:
new php

Added: branches/mapbender_sld/http/php/mod_digitize_messages.php
===================================================================
--- branches/mapbender_sld/http/php/mod_digitize_messages.php	                        (rev 0)
+++ branches/mapbender_sld/http/php/mod_digitize_messages.php	2007-11-23 13:53:03 UTC (rev 1841)
@@ -0,0 +1,78 @@
+<?php
+#$Id: mod_insertWmcIntoDb.php 507 2006-11-20 10:55:57Z christoph $
+#$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_insertWmcIntoDb.php,v 1.19 2006/03/09 14:02:42 uli_rothstein Exp $
+# 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.
+
+session_start();
+
+require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/../extensions/JSON.php");
+require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+
+$e = new mb_notice("locale: " . $_SESSION["mb_locale"] . "; lang: " . $_SESSION["mb_lang"]);
+$e = new mb_notice(setlocale(LC_ALL, $_SESSION["mb_locale"]));
+
+//
+// Messages
+//
+$msg_obj = array();
+$msg_obj["messageDescriptionPolygon"] = _("polygon");
+$msg_obj["messageDescriptionLine"] = _("line");
+$msg_obj["messageDescriptionPoint"] = _("point");
+$msg_obj["messageErrorNotAnInteger"] = _("Not an integer value.");
+$msg_obj["messageErrorNotAFloat"] = _("Not a double value.");
+$msg_obj["messageErrorFieldIsEmpty"] = _("This field may not be empty.");
+$msg_obj["messageErrorFormEvaluation"] = _("Failure during form evaluation.");
+$msg_obj["messageErrorWfsWrite"] = _("An error occured.");
+$msg_obj["messageSuccessWfsWrite"] = _("Success.");
+$msg_obj["messageConfirmDeleteGeomFromDb"] = _("Delete geometry from database?");
+$msg_obj["messageConfirmDeleteAllGeomFromList"] = _("Clear list of geometries?");
+$msg_obj["messageSelectAnOption"] = _("Please select an entry.");
+$msg_obj["buttonLabelSaveGeometry"] = _("Save");
+$msg_obj["buttonLabelUpdateGeometry"] = _("Update");
+$msg_obj["buttonLabelDeleteGeometry"] = _("Delete");
+$msg_obj["buttonLabelAbort"] = _("Abort");
+$msg_obj["errorMessageEpsgMismatch"] = _("Fatal error: EPSG mismatch. ");
+$msg_obj["errorMessageNoGeometrySelected"] = _("No geometry selected!");
+$msg_obj["buttonLabelPointOff"] = _("add point");
+$msg_obj["buttonLabelPointOn"] = _("cancel editing");
+$msg_obj["buttonLabelLineOff"] = _("add line");
+$msg_obj["buttonLabelLineOn"] = _("finish line");
+$msg_obj["buttonLabelPolygonOff"] = _("add polygon");
+$msg_obj["buttonLabelPolygonOn"] = _("close polygon");
+$msg_obj["buttonLabelMoveBasepointOff"] = _("move basepoint");
+$msg_obj["buttonLabelMoveBasepointOn"] = _("move basepoint");
+$msg_obj["buttonLabelInsertBasepointOff"] = _("Insert basepoint");
+$msg_obj["buttonLabelInsertBasepointOn"] = _("Insert basepoint");
+$msg_obj["buttonLabelDeleteBasepointOff"] = _("Delete basepoint");
+$msg_obj["buttonLabelDeleteBasepointOn"] = _("Delete basepoint");
+$msg_obj["buttonLabelClearListOff"] = _("clear list of geometries");
+$msg_obj["buttonLabelClearListOn"] = _("clear list of geometries");
+$msg_obj["buttonDig_wfs_title"] = _("save / update / delete");
+$msg_obj["buttonDig_remove_title"] = _("remove from workspace");
+$msg_obj["buttonDig_removeDb_title"] = _("remove from database");
+$msg_obj["closePolygon_title"] = _("click the first basepoint to close the polygon");
+$msg_obj["measureTagLabelCurrent"] = _("Current: ");
+$msg_obj["measureTagLabelTotal"] = _("Total: ");
+$msg_obj["digitizeDefaultGeometryName"] = _("new");
+
+$json = new Services_JSON();
+$output = $json->encode($msg_obj);
+
+header("Content-type:text/plain; Charset='UTF-8'");
+echo $output;
+?>
\ No newline at end of file

Added: branches/mapbender_sld/http/php/mod_insertWmcIntoDb.php
===================================================================
--- branches/mapbender_sld/http/php/mod_insertWmcIntoDb.php	                        (rev 0)
+++ branches/mapbender_sld/http/php/mod_insertWmcIntoDb.php	2007-11-23 13:53:03 UTC (rev 1841)
@@ -0,0 +1,68 @@
+<?php
+#$Id: mod_insertWmcIntoDb.php 1198 2007-10-18 14:37:52Z baudson $
+#$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_insertWmcIntoDb.php,v 1.19 2006/03/09 14:02:42 uli_rothstein Exp $
+# 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__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+require_once(dirname(__FILE__)."/../classes/class_wmc.php");
+require_once(dirname(__FILE__)."/../extensions/JSON.php");
+
+session_start();
+$con = db_connect($DBSERVER,$OWNER,$PW);
+db_select_db(DB,$con);
+
+$json = new Services_JSON();
+$mapObject = $json->decode(stripslashes($_POST["mapObject"]));
+$user_id = $_SESSION["mb_user_id"];
+$save_in_session = $_POST["saveInSession"];
+$generalTitle = $_POST["generalTitle"];
+
+$extensionData = $json->decode(stripslashes($_POST["extensionData"]));
+
+$wmc = new wmc();
+$wmc->createWMCFromObj($mapObject, $user_id, $generalTitle, $extensionData);
+
+if ($save_in_session) {
+	$_SESSION["mb_wmc"] = $wmc->xml;
+	$_SESSION["epsg"] = $mapObject->epsg;
+	$_SESSION["previous_gui"] = $_SESSION["mb_user_gui"];
+	$e = new mb_notice("mod_insertWMCIntoDB: save WMC in session succeeded.");
+}
+else {
+	if ($user_id && $wmc->wmc_id) {
+		$sql = "INSERT INTO mb_user_wmc VALUES ($1, $2, $3, $4, $5)";
+		$v = array($wmc->wmc_id, $user_id, $wmc->xml, $generalTitle, time());
+		$t = array("s", "i", "s", "s", "s");
+		
+		$res = db_prep_query($sql, $v, $t);
+		if (db_error()) {
+			$errMsg = "Error while saving WMC document '" . $generalTitle . "': " . db_error();
+			echo $errMsg;
+			$e = new mb_exception("mod_insertWMCIntoDB: " . $errMsg);
+		}
+		else {
+			echo "WMC document '" . $generalTitle . "' has been saved.";
+			$e = new mb_notice("mod_insertWMCIntoDB: WMC  '" . $generalTitle . "' saved successfully.");
+		}
+	}
+	else {
+		$e = new mb_exception("mod_insertWMCIntoDB: missing parameters (user_id: ".$user_id.", wmc_id: ".$wmc->wmc_id."))");
+	}
+}
+?>
\ No newline at end of file

Added: branches/mapbender_sld/http/php/mod_wfs_gazetteer_server.php
===================================================================
--- branches/mapbender_sld/http/php/mod_wfs_gazetteer_server.php	                        (rev 0)
+++ branches/mapbender_sld/http/php/mod_wfs_gazetteer_server.php	2007-11-23 13:53:03 UTC (rev 1841)
@@ -0,0 +1,171 @@
+<?php
+# $Id: mod_wfs_gazetteer_server.php 1190 2007-10-18 10:38:38Z baudson $
+# http://www.mapbender.org/index.php/Administration
+# 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.
+
+session_start();
+
+require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+include(dirname(__FILE__)."/../classes/class_gml2.php");
+require_once(dirname(__FILE__)."/../extensions/JSON.php");
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+require_once(dirname(__FILE__)."/../classes/class_wfs_conf.php");
+
+$con = db_connect($DBSERVER,$OWNER,$PW);
+db_select_db($DB,$con);
+
+$command = $_REQUEST["command"];
+
+/**
+ * checks if a variable name is valid.
+ * Currently a valid name would be sth. like $_SESSION["mb_user_id"]
+ * TODO: this function is also in mod_wfs_result!! Maybe merge someday.
+ */
+function isValidVarName ($varname) {
+	if (preg_match("/[\$]{1}_[a-z]+\[\"[a-z_]+\"\]/i", $varname) != 0) {
+		return true;
+	}
+	return false;
+}
+
+/**
+ * If access to the WFS conf is restricted, modify the filter.
+ * TODO: this function is also in mod_wfs_result!! Maybe merge someday.
+ */
+ function checkAccessConstraint($filter, $wfs_conf_id) {
+	/* wfs_conf_element */
+	$sql = "SELECT * FROM wfs_conf_element ";
+	$sql .= "JOIN wfs_element ON wfs_conf_element.f_id = wfs_element.element_id ";
+	$sql .= "WHERE wfs_conf_element.fkey_wfs_conf_id = $1 ";
+	$sql .= "ORDER BY wfs_conf_element.f_respos";
+			
+	$v = array($wfs_conf_id);
+	$t = array('i');
+	$res = db_prep_query($sql,$v,$t);
+	while($row = db_fetch_array($res)){
+
+		if (!empty($row["f_auth_varname"])) {
+			$auth_varname = $row["f_auth_varname"];
+			$element_name = $row["element_name"];
+		}
+	}
+	if (!empty($auth_varname)) {
+
+		if (isValidVarName($auth_varname)) {
+			$user = eval("return " . $auth_varname . ";");
+			if ($user) {
+				$pattern = "(<ogc:Filter[^>]*>)(.*)(</ogc:Filter>)";
+				$replacement = "\\1<And>\\2<ogc:PropertyIsEqualTo><ogc:PropertyName>" . $element_name . "</ogc:PropertyName><ogc:Literal>" . $user . "</ogc:Literal></ogc:PropertyIsEqualTo></And>\\3"; 
+				$filter = mb_eregi_replace($pattern, $replacement, $filter);
+			}
+			else {
+				$e = new mb_exception("mod_wfs_gazetteer_server: checkAccessConstraint: invalid value of variable containing user information!");
+			}
+		}
+		else {
+			$e = new mb_exception("mod_wfs_gazetteer_server: checkAccessConstraint: var name is not valid! (" . $auth_varname . ")");
+		}
+	}
+	return $filter;
+}
+
+
+if ($command == "getWfsConf") {
+	
+	$wfsConfIdString = $_GET["wfsConfIdString"];
+	
+	if ($wfsConfIdString != "") {
+		//array_keys(array_flip()) produces an array with unique entries
+		$wfsConfIdArray = array_keys(array_flip(mb_split(",", $wfsConfIdString)));
+	}
+	else {
+		echo "please specify wfs conf id.";
+		die();
+	}
+	
+	$obj = new WfsConf($wfsConfIdArray);
+
+	$json = new Services_JSON();
+	$output = $json->encode($obj->confArray);
+	echo $output;
+}
+else if ($command == "getSearchResults") {
+	$wfs_conf_id = $_REQUEST["wfs_conf_id"];
+	$backlink = $_REQUEST["backlink"];
+	$frame = $_REQUEST["frame"];
+	$filter = $_REQUEST["filter"];
+	$url = $_REQUEST["url"];
+
+	/* wfs_conf */
+	$sql = "SELECT * FROM wfs_conf JOIN wfs ON wfs_conf.fkey_wfs_id = wfs.wfs_id ";
+	$sql .= "WHERE wfs_conf.wfs_conf_id = $1";
+	$v = array($wfs_conf_id);
+	$t = array('i');
+	
+	$res = db_prep_query($sql,$v,$t);
+	if ($row = db_fetch_array($res)) {
+		$g_res_style  = $row["g_res_style"];
+	}
+	else {
+		die("wfs_conf " . $wfs_conf_id . "data not available");
+	}
+	
+	/* wfs_conf_element */
+	$sql = "SELECT * FROM wfs_conf_element ";
+	$sql .= "JOIN wfs_element ON wfs_conf_element.f_id = wfs_element.element_id ";
+	$sql .= "WHERE wfs_conf_element.fkey_wfs_conf_id = $1 ";
+	$sql .= "AND wfs_conf_element.f_show = 1 ORDER BY wfs_conf_element.f_respos;";
+	$v = array($wfs_conf_id);
+	$t = array('i');
+	
+	$res = db_prep_query($sql,$v,$t);
+	$col = array();
+	while ($row = db_fetch_array($res)) {
+		array_push($col, $row["element_name"]);
+	}
+	if (count($col) == 0) {
+		die("wfs_conf_element data not available");
+	}
+	
+	// append authorisation condition to filter
+	$filter = checkAccessConstraint($filter, $wfs_conf_id);
+	
+	$admin = new administration();
+	
+	$req = urldecode($url).urlencode($admin->char_decode(stripslashes($filter)));
+	$mygml = new gml2();
+	$mygml->parsegml($req);
+	
+	// generates JavaScript code that will add a geometry array containing
+	// all the result geometries and their attributes (wfs_conf_elements)
+	
+	$js = "";
+	if ($mygml->getMemberCount() > 0) { 
+		$js .= $mygml->exportGeometriesToJS(true);
+	
+		for ($i = 0; $i < $mygml->getMemberCount(); $i++) {
+			for ($j = 0; $j < count($col); $j++){
+				$js .= "geom.get(".$i.").e.setElement('".$j."', '".$mygml->getValueBySeparatedKey($i, $col[$j]) . "');\n";
+			}
+		}
+	}
+	echo $js;
+}
+else {
+	echo "please enter a valid command.";
+}
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list