[Mapbender-commits] r1831 - branches/mapbender_sld/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Nov 23 08:22:46 EST 2007
Author: christoph
Date: 2007-11-23 08:22:46 -0500 (Fri, 23 Nov 2007)
New Revision: 1831
Added:
branches/mapbender_sld/http/classes/class_bbox.php
branches/mapbender_sld/http/classes/class_keyword.php
branches/mapbender_sld/http/classes/class_layer_monitor.php
branches/mapbender_sld/http/classes/class_locale.php
branches/mapbender_sld/http/classes/class_metadata.php
branches/mapbender_sld/http/classes/class_monitor.php
Modified:
branches/mapbender_sld/http/classes/class_administration.php
branches/mapbender_sld/http/classes/class_checkInput.php
branches/mapbender_sld/http/classes/class_gml2.php
branches/mapbender_sld/http/classes/class_gui.php
branches/mapbender_sld/http/classes/class_kml.php
branches/mapbender_sld/http/classes/class_mb_exception.php
branches/mapbender_sld/http/classes/class_stripRequest.php
branches/mapbender_sld/http/classes/class_weldLegend2PNG.php
branches/mapbender_sld/http/classes/class_weldOverview2PNG.php
branches/mapbender_sld/http/classes/class_wfs.php
branches/mapbender_sld/http/classes/class_wfs_conf.php
branches/mapbender_sld/http/classes/class_wmc.php
Log:
new and updated classes
Modified: branches/mapbender_sld/http/classes/class_administration.php
===================================================================
--- branches/mapbender_sld/http/classes/class_administration.php 2007-11-23 13:20:10 UTC (rev 1830)
+++ branches/mapbender_sld/http/classes/class_administration.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -17,6 +17,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/class_mb_exception.php");
$con = db_connect(DBSERVER,OWNER,PW);
db_select_db(DB,$con);
@@ -38,7 +39,7 @@
* @return <boolean> answer to "is the passed over email valid?""
*/
function isValidEmail($email) {
- if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
+ if(mb_eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
return true;
}
return false;
@@ -122,7 +123,7 @@
for ($i=0;$i <= $max;$i++) {
//die ASCII-Zeichen 48 - 57 sind die zahlen 0-9
- //die ASCII-Zeichen 65 - 90 sind die buchstaben A-Z (Groß)
+ //die ASCII-Zeichen 65 - 90 sind die buchstaben A-Z (Gro�)
//die ASCII-Zeichen 97 - 122 sind die buchstaben a-z (Klein)
$ascii = 0;
do {
@@ -132,10 +133,10 @@
}
return $newpass;
}
-
+
/**
* returns the name of a mapbender user which owns the GUI identified by the passed over gui_id.
- *
+ *
* @param <string> the gui_id
* @return <string> the name of the owner
*/
@@ -167,10 +168,10 @@
}
return $owner;
}
-
+
/**
* returns the content of the field mb_user_email for the given userid.
- *
+ *
* @param <integer> the userid
* @return <mixed> the email if one row is found or false if none is foundd
*/
@@ -181,7 +182,7 @@
$v = array($userid);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
- // TODO shall the next two lines be removed?
+ // TODO shall the next two lines be removed?
$count_g = 0;
$array = array();
$row = db_fetch_array($res);
@@ -192,10 +193,10 @@
return false;
}
}
-
+
/**
* returns the name of the user for the given userid.
- *
+ *
* @param <integer> the userid
* @return the name if one row is found or false if none is foundd
*/
@@ -221,7 +222,7 @@
/**
* returns one or more userids from the given email or false,
* if there is no record in the database matching the given email
- *
+ *
* @param <string> the email
* @return <mixed> returns an array of userids or false when no records matches
*/
@@ -249,9 +250,9 @@
* returns one or more owners for the given wm_id. First all guis deploying
* this wms are selected. Afterwards for each of the guis the owners are
* selected and stored within an array.
- *
+ *
* @param <integer> the wms_id
- * @return <mixed> an array of usernames which use thw wms in their guis (both for persona or group ownership)
+ * @return <mixed> an array of usernames which use thw wms in their guis (both for persona or group ownership)
*/
function getOwnerByWms($wms_id){
// first get guis which deploy this wms.
@@ -318,7 +319,7 @@
}
/**
* tests whether a gui with the passed gui_id exits and returns true or false.
- *
+ *
* @param <string> the gui_id to test
* @return <boolean> Does a Gui with the passed over gui_id exist?
*/
@@ -335,10 +336,10 @@
return false;
}
}
-
+
/**
* deletes a WMC entry specified by wmc_id and user_id
- *
+ *
* @param <integer> the user_id
* @param <string> the wmc_id
* @return <boolean> Did the query run succesfull? This does not necessarily mean that an entry was deleted.
@@ -356,10 +357,10 @@
return false;
}
}
-
+
/**
* inserts a gui with the specified gui_id, after checking the uniqueness of teh gui id.
- *
+ *
* @uses guiExists
* @param <string> the name and id of the gui to insert.
* @return <boolean> could the gui be inserted?
@@ -376,10 +377,10 @@
}
return false;
}
-
+
/**
* deletes links between user and guis in gui_mb_user for a certain gui.
- *
+ *
* @param <string> the gui name
* @return <boolean> could the sql be executed without errors. This does not necessarily mean, that entries were deleted
*/
@@ -395,16 +396,23 @@
return true;
}
}
-
+
/**
- *
+ * returns an array of WMS for a given user id
* @uses getGuisByOwner
+ * @param <integer> the user id
+ * @return <array> wms ids for the user
*/
function getWmsByOwner($user_id){
$gui_list = $this->getGuisByOwner($user_id,true);
return $this->getWmsByOwnGuis($gui_list);
}
+ /**
+ * returns an array of WMS where the owner is the user with the passed user_id
+ * @param <integer> the user id
+ * @return <array> wms ids for the user
+ */
function getWmsByWmsOwner($user_id){
$sql = "SELECT wms_id FROM wms WHERE wms_owner = $1";
$v = array($user_id);
@@ -417,6 +425,12 @@
return $r;
}
+ /**
+ * returns an array of user which are associated with a wms
+ *
+ * @param <integer> the wms id
+ * @return <array> user_ids for the wms
+ */
function getUserByWms($wms_id){
$sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = $1 GROUP BY fkey_gui_id";
$v = array($wms_id);
@@ -464,8 +478,14 @@
return $user;
}
+ /**
+ * selects the WMS-title for a given wms id.
+ *
+ * @param <integer> the wms id
+ * @return <string|boolean> either the title of the wms as string or false when none exists
+ */
function getWmsTitleByWmsId($id){
- $sql = "SELECT wms_title from wms WHERE wms_id = $1 GROUP BY wms_title";
+ $sql = "SELECT wms_title FROM wms WHERE wms_id = $1 GROUP BY wms_title";
$v = array($id);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
@@ -473,8 +493,14 @@
if ($row) return $row["wms_title"]; else return false;
}
+ /**
+ * selects the Layer-title for a given layer id.
+ *
+ * @param <integer> the wms id
+ * @return <string|boolean> either the title of the wms as string or false when none exists
+ */
function getLayerTitleByLayerId($id){
- $sql = "SELECT layer_title from layer WHERE layer_id = $1 GROUP BY layer_title";
+ $sql = "SELECT layer_title FROM layer WHERE layer_id = $1 GROUP BY layer_title";
$v = array($id);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
@@ -482,6 +508,12 @@
if ($row) return $row["layer_title"]; else return false;
}
+ /**
+ * selects the WMC for a given wmc_id.
+ *
+ * @param <integer> the wms id
+ * @return <string|boolean> either the wmc as string or false when none exists
+ */
function getWmcById($id){
$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1 ";
$v = array($id);
@@ -496,13 +528,18 @@
}
}
+ /**
+ * resets the login count of a given user to 0
+ * @param <integer> the user id
+ * @return <boolean> could the login count be reseted?
+ */
function resetLoginCount($userId) {
- $sql = "UPDATE mb_user SET mb_user_login_count = '0' ";
+ // TODO: isn't mb_user_login_count a integer?
+ $sql = "UPDATE mb_user SET mb_user_login_count = '0' ";
$sql .= "WHERE mb_user_id = $1 ";
$v = array($userId);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
-
if (!$res) {
return false;
}
@@ -511,6 +548,12 @@
}
}
+ /**
+ * returns the user id for a given username
+ *
+ * @param <string> the username of which the id shall be returned
+ * @return <string|boolean> the userid or false if the operation fails
+ */
function getUserIdByUserName($username){
$sql = "SELECT mb_user_id FROM mb_user ";
$sql .= "WHERE mb_user_name = $1 GROUP BY mb_user_id";
@@ -518,9 +561,21 @@
$t = array('s');
$res = db_prep_query($sql,$v,$t);
$row = db_fetch_array($res);
- if ($row) return $row["mb_user_id"]; else return false;
+ if ($row) {
+ return $row["mb_user_id"];
+ }
+ else {
+ return false;
+ }
}
+ /**
+ * sets the given user_id as owner for the passed gui_id
+ *
+ * @param <string> the gui_id to change ownership of
+ * @param <integer> the user_id of the intended new owner
+ * @return <boolean> Could the owner be updated?
+ */
function setUserAsGuiOwner($guiId, $userId) {
$sql = "UPDATE gui_mb_user SET mb_user_type = 'owner' ";
$sql .= "WHERE fkey_gui_id = $1 AND fkey_mb_user_id = $2 ";
@@ -536,8 +591,16 @@
}
}
+ /**
+ * gets and returns gui_ids identified by the passed over gui_name
+ *
+ * @param <string> name of the gui
+ * @return <array|boolean> an array of gui_ids or false when something went wrong
+ */
function getGuiIdByGuiName($guiTitle){
- $sql = "SELECT gui_id FROM gui ";
+ //TODO: check whether the passed variable should be renamed, guiTitle is misleading
+ //TODO: check whether the function should be renamed to "getGuiIdsByGuiName" since it usually returns an array
+ $sql = "SELECT gui_id FROM gui ";
$sql .= "WHERE gui_name = $1 GROUP BY gui_id";
$v = array($guiTitle);
$t = array('s');
@@ -556,15 +619,23 @@
}
}
- function getGuisByOwner($user_id,$ignore_public)
- {
- $sql_guis = "SELECT gui.gui_id FROM gui,gui_mb_user ";
+ /**
+ * returns gui_ids owned by the user with the passed user_id
+ *
+ * @param <integer> user_id of the owner
+ * @param <boolean> shall only public guis be returned? sort of optional... see todo
+ * @return <array> array of gui_ids owned by the user
+ */
+ function getGuisByOwner($user_id,$ignore_public) {
+ //TODO: isn't the name of the second parameter misleading?
+ $sql_guis = "SELECT gui.gui_id FROM gui,gui_mb_user ";
$sql_guis .= "WHERE (gui.gui_id = gui_mb_user.fkey_gui_id AND gui_mb_user.fkey_mb_user_id = $1) ";
- if (!isset($ignore_public) OR $ignore_public == false){
+ //TODO: when using !isset() below should IMO be replaced with a true otional second parameter via a default value
+ if (!isset($ignore_public) OR $ignore_public == false){
$sql_guis .= " AND gui.gui_public = 1 ";
}
$sql_guis .= " AND gui_mb_user.mb_user_type = 'owner' GROUP BY gui.gui_id";
- $sql_guis .= " ORDER by gui.gui_id";
+ $sql_guis .= " ORDER BY gui.gui_id";
$v = array($user_id);
$t = array('i');
$res_guis = db_prep_query($sql_guis,$v,$t);
@@ -574,9 +645,16 @@
$arrayGuis[$count_g] = $row["gui_id"];
$count_g++;
}
+ //TODO: check: why do we always return an array, when most other comparable functions would return false? This is IMO at least inconsistent.
return $arrayGuis;
}
+ /**
+ * returns wmc_ids owned by the user with the passed user_id
+ *
+ * @param <integer> user_id of the owner
+ * @return <array> array of wmc_ids owned by the user
+ */
function getWmcByOwner($user_id){
$sql_wmc = "SELECT wmc_id FROM mb_user_wmc ";
$sql_wmc .= "WHERE fkey_user_id = $1 GROUP BY wmc_id";
@@ -589,6 +667,7 @@
$arrayWmc[$count_g] = $row["wmc_id"];
$count_g++;
}
+ //TODO: check: why do we always return an array, when most other comparable functions would return false? This is IMO at least inconsistent.
return $arrayWmc;
}
@@ -643,7 +722,7 @@
if(count($array_gui_ids)>0){
$v = array();
$t = array();
- $sql = "SELECT fkey_wms_id from gui_wms WHERE gui_wms.fkey_gui_id IN(";
+ $sql = "SELECT fkey_wms_id FROM gui_wms WHERE gui_wms.fkey_gui_id IN(";
for($i=0; $i<count($array_gui_ids); $i++){
if($i>0){ $sql .= ",";}
$sql .= "$".strval($i+1);
@@ -740,7 +819,7 @@
$res = db_prep_query($sql,$v,$t);
$cnt = 0;
while($row = db_fetch_array($res)){
- if(strpos(stripslashes($row[$column]),$modulePath) !== false){
+ if(mb_strpos(stripslashes($row[$column]),$modulePath) !== false){
$perm = true;
}
$cnt++;
@@ -778,10 +857,55 @@
}
$res = db_prep_query($sql,$v,$t);
}
+
+ /*
+ * get the owsproxy-string of the current wfs
+ *
+ * @param integer the wfs-id of the current wfs
+ * @return mixed the owsproxy-string or false
+ */
+
+ function getWfsOwsproxyString($wfs_id){
+ $sql = "SELECT wfs_owsproxy FROM wfs WHERE wfs_id = $1 ";
+ $v = array($wfs_id);
+ $t = array("i");
+ $res = db_prep_query($sql,$v,$t);
+ if($row = db_fetch_array($res)){
+ return $row["wfs_owsproxy"];
+ }
+ else{
+ return false;
+ }
+ }
+
+ /*
+ * sets or removes the owsproxy string of the current wfs
+ *
+ * @param integer the wfs-id
+ * @param boolean set (true) or remove (false) the owsproxy-string
+ *
+ */
+ function setWfsOwsproxyString($wfs_id, $status){
+ $sql = "UPDATE wfs SET wfs_owsproxy = $1 WHERE wfs_id = $2 ";
+ $t = array("s","i");
+ if($status == true){
+ $time = md5(microtime(1));
+ $v = array($time,$wfs_id);
+ }
+ else{
+ $n = new mb_notice("removed owsproxy for wfs:".$wfs_id);
+ $v = array("",$wfs_id);
+ }
+
+ $res = db_prep_query($sql,$v,$t);
+ $newOwsString = $this->getWfsOwsproxyString($wfs_id);
+ $n = new mb_notice("Class administration - setOWSString for wfs (".$wfs_id.") to: ". $this->getWfsOwsproxyString($wfs_id));
+ return $newOwsString;
+ }
function checkURL($url){
$pos_qm = strpos($url,"?");
- if($pos_qm > 0 && $pos_qm < (strlen($url)-1) && substr($url,(strlen($url)-1)) != "&"){
+ if($pos_qm > 0 && $pos_qm < (mb_strlen($url)-1) && mb_substr($url,(mb_strlen($url)-1)) != "&"){
$url = $url."&";
return $url;
}
@@ -802,6 +926,7 @@
if($row = db_fetch_array($res)){
return true;
}
+ //TODO: next three lines should be removable...
else{
return false;
}
@@ -885,5 +1010,113 @@
return false;
}
}
+
+ function is_utf8_string($string) {
+ return preg_match('%(?:
+ [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
+ |\xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
+ |[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
+ |\xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
+ |\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
+ |[\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
+ |\xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
+ )+%xs', $string);
+ }
+
+ function is_utf8_xml($xml) {
+ return preg_match('/<\?xml[^>]+encoding="utf-8"[^>]*\?>/is', $xml);
+ }
+
+ function is_utf8 ($data) {
+ return ($this->is_utf8_xml($data) || $this->is_utf8_string($data));
+ }
+
+ function char_encode($data) {
+ if (CHARSET == "UTF-8") {
+ if (!$this->is_utf8($data)) {
+ $e = new mb_notice("Conversion: ISO-8859-1 to UTF-8");
+ return utf8_encode($data);
+ }
+ }
+ else {
+ if ($this->is_utf8($data)) {
+ $e = new mb_notice("Conversion: UTF-8 to ISO-8859-1");
+ return utf8_decode($data);
+ }
+ }
+ $e = new mb_notice("No conversion: is " . CHARSET);
+ return $data;
+ }
+
+ function char_decode($data) {
+ if (CHARSET == "UTF-8") {
+ if ($this->is_utf8($data)) {
+ $e = new mb_notice("Conversion: UTF-8 to ISO-8859-1");
+ return utf8_decode($data);
+ }
+ }
+ $e = new mb_notice("no conversion: is " . CHARSET);
+ return $data;
+ }
+
+ /**
+ * identifies the Featureservices where the current user is owner
+ *
+ * @param integer userid the user-ID of the current user
+ * @return array an array of the IDs as integers of the featureservices
+ */
+ function getWfsByOwner($userid){
+ $sql = "SELECT wfs_id FROM wfs WHERE wfs_owner = $1";
+ $v = array($userid);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ $r = array();
+ while($row = db_fetch_array($res)){
+ array_push($r,$row["wfs_id"]);
+ }
+ return $r;
+ }
+
+ /* identifies the Conf-FeatureServices where the current user is owner
+ *
+ * @param integer userid the user-ID of the current user
+ * @returen integer[] the IDs of the wfs_conf-table
+ */
+ function getWfsConfByPermission($userid){
+
+
+ $guisByPer = array();
+// 1.
+ $guisByPer = $this->getGuisByPermission($userid, true);
+
+// 2.
+ if(count($guisByPer)>0){
+ $v = array();
+ $t = array();
+ $sql = "SELECT wfs_conf.wfs_conf_id FROM gui_wfs_conf, wfs_conf " .
+ "where wfs_conf.wfs_conf_id = gui_wfs_conf.fkey_wfs_conf_id " .
+ "and gui_wfs_conf.fkey_gui_id IN(";
+ for($i=0; $i<count($guisByPer); $i++){
+ if($i>0){ $sql .= ",";}
+ $sql .= "$".strval($i+1);
+
+ array_push($v, $guisByPer[$i]);
+ array_push($t, "s");
+ }
+ $sql .= ") GROUP BY wfs_conf.wfs_conf_id ORDER BY wfs_conf.wfs_conf_id";
+
+
+ $res = db_prep_query($sql,$v,$t);
+ $ownWFSconfs = array();
+ $i=0;
+ while($row = db_fetch_array($res)){
+
+ $ownWFSconfs[$i] = $row['wfs_conf_id'];
+ $i++;
+ }
+ }
+ return $ownWFSconfs;
+
+ }
}
-?>
+?>
\ No newline at end of file
Added: branches/mapbender_sld/http/classes/class_bbox.php
===================================================================
--- branches/mapbender_sld/http/classes/class_bbox.php (rev 0)
+++ branches/mapbender_sld/http/classes/class_bbox.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -0,0 +1,285 @@
+<?php
+# $Id: class_bbox.php 1740 2007-10-26 10:12:53Z christoph $
+# http://www.mapbender.org/index.php/
+# 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");
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
+
+/**
+ * A Mapbender_point is a 2-dimensional point with an EPSG.
+ */
+class Mapbender_point {
+ var $x;
+ var $y;
+ var $epsg;
+
+ /**
+ * @constructor
+ */
+ function __construct($x, $y, $epsg) {
+ if (!$x || !$y || !$epsg) {
+ $e = new mb_exception("Mapbender_point: constructor: some parameters are not set (set (x: ".$x.", y: ".$y.", epsg:".$epsg.")!");
+ }
+ $this->x = $x;
+ $this->y = $y;
+ $this->epsg = $epsg;
+ }
+
+ /**
+ * computes a new point with the minimal coordinates of this point and $point
+ */
+ static function min ($point1, $point2) {
+ if ($point1->epsg == $point2->epsg) {
+ if ($point1->isWestOf($point2)) {
+ $minx = $point1->x;
+ }
+ else {
+ $minx = $point2->x;
+ }
+ if ($point1->isSouthOf($point2)) {
+ $miny = $point1->y;
+ }
+ else {
+ $miny = $point2->y;
+ }
+ return new Mapbender_point($minx, $miny, $point1->epsg);
+ }
+ else {
+ $e = new mb_exception("Mapbender_point: cannot process min with different EPSG codes");
+ }
+ }
+
+ /**
+ * computes a new point with the maximal coordinates of this point and $point
+ */
+ static function max ($point1, $point2) {
+ if ($point1->epsg == $point2->epsg) {
+ if ($point1->isWestOf($point2)) {
+ $maxx = $point2->x;
+ }
+ else {
+ $maxx = $point1->x;
+ }
+ if ($point1->isSouthOf($point2)) {
+ $maxy = $point2->y;
+ }
+ else {
+ $maxy = $point1->y;
+ }
+ return new Mapbender_point($maxx, $maxy, $point1->epsg);
+ }
+ else {
+ $e = new mb_exception("Mapbender_point: cannot process min with different EPSG codes");
+ }
+ }
+
+ function isWestOf($point) {
+ if ($this->x < $point->x) {
+ return true;
+ }
+ }
+
+ function isSouthOf($point) {
+ if ($this->y < $point->y) {
+ return true;
+ }
+ }
+
+ /**
+ * Addition
+ *
+ * @param anotherPoint another Mapbender_point
+ */
+ function plus ($anotherPoint) {
+ return new Mapbender_point($this->x + $anotherPoint->x, $this->y + $anotherPoint->y, $this->epsg);
+ }
+
+ /**
+ * Subtraction
+ *
+ * @param anotherPoint another Mapbender_point
+ */
+ function minus ($anotherPoint) {
+ return $this->plus($anotherPoint->times(-1));
+ }
+
+ /**
+ * Scalar multiplication
+ *
+ * @param aFloat a floating point number
+ */
+ function times ($aFloat) {
+ return new Mapbender_point($this->x * $aFloat, $this->y * $aFloat, $this->epsg);
+ }
+
+ /**
+ * transforms this point to another EPSG
+ */
+ function transform($toEpsg) {
+ if(SYS_DBTYPE=='pgsql'){
+ $currentEpsg = preg_replace("/EPSG:/", "", $this->epsg);
+ $targetEpsg = preg_replace("/EPSG:/", "", $toEpsg);
+ $sql = "SELECT X(transform(GeometryFromText('POINT(".$this->x." ".$this->y.")',".$currentEpsg."),".$targetEpsg.")) as x, ";
+ $sql .= "Y(transform(GeometryFromText('POINT(".$this->x." ".$this->y.")',".$currentEpsg."),".$targetEpsg.")) as y";
+ $res = db_query($sql);
+ $point = new Mapbender_point(db_result($res,0,"x"), db_result($res,0,"y"), $toEpsg);
+ $this->x = $point->x;
+ $this->y = $point->y;
+ $this->epsg = $point->epsg;
+ }
+ else {
+ $e = new mb_exception("transformCoordinates needs PostgreSQL");
+ }
+ }
+
+ function __toString() {
+ return (string) "(" . $this->x . "," . $this->y . "," . $this->epsg . ")";
+ }
+}
+
+/**
+ * A bounding box consisting of an lower left and an upper right point, and an EPSG.
+ */
+class Mapbender_bbox {
+ var $min;
+ var $max;
+ var $epsg;
+
+ /**
+ * @constructor
+ */
+ function __construct($param0, $param1, $param2, $param3, $param4) {
+ // params are point, point, epsg
+ if (is_a($param0, "Mapbender_point") && is_a($param1, "Mapbender_point") && !$param3 && !$param4) {
+ $e = new mb_notice("Mapbender_bbox: constructor: point1, point2, epsg");
+ $min = $param0; // is a Mapbender_point
+ $max = $param1; // is a Mapbender_point
+ $epsg = $param2; // is an EPSG code like "EPSG:4326"
+
+ if ($min->isWestOf($max) && $min->isSouthOf($max)) {
+ if ($min->epsg == $max->epsg && $min->epsg == $epsg) {
+ $this->min = $min;
+ $this->max = $max;
+ $this->epsg = $epsg;
+ }
+ else {
+ $e = new mb_exception("Mapbender_bbox: constructor: EPSG mismatch!");
+ }
+ }
+ else {
+ $e = new mb_exception("Mapbender_bbox: constructor: min (".$this->min.") is not southwest of max (".$this->max.")!");
+ }
+ }
+ // params are x1, y1, x2, xy, epsg
+ else {
+ $e = new mb_notice("Mapbender_bbox: constructor: x1, y1, x2, y2, epsg");
+ $min = new Mapbender_point($param0, $param1, $param4);
+ $max = new Mapbender_point($param2, $param3, $param4);
+ $epsg = $param4; // is an EPSG code like "EPSG:4326"
+
+ if ($min->isWestOf($max) && $min->isSouthOf($max)) {
+ if ($min->epsg == $max->epsg && $min->epsg == $epsg) {
+ $this->min = $min;
+ $this->max = $max;
+ $this->epsg = $epsg;
+ }
+ else {
+ $e = new mb_exception("Mapbender_bbox: constructor: EPSG mismatch!");
+ }
+ }
+ else {
+ $e = new mb_exception("Mapbender_bbox: constructor: min (".$this->min.") is not southwest of max (".$this->max.")!");
+ }
+
+ }
+ }
+
+ /**
+ * Computes a new bounding box, bbox1 UNION bbox2
+ */
+ static function union ($bboxArray) {
+ if (count($bboxArray) == 1) {
+ return array_pop($bboxArray);
+ }
+ elseif (count($bboxArray) >= 2) {
+
+ $bbox1 = array_pop($bboxArray);
+ $bbox2 = Mapbender_bbox::union($bboxArray);
+
+ if (!($bbox1 != null && $bbox1->isValid()) && !($bbox2 != null && $bbox2->isValid())) {
+ $e = new mb_exception("Mapbender_bbox: union: both parameters invalid!");
+ return null;
+ }
+ elseif (!($bbox1 != null && $bbox1->isValid()) && ($bbox2 != null && $bbox2->isValid())) {
+ $e = new mb_exception("Mapbender_bbox: union: first parameter invalid!");
+ return $bbox2;
+ }
+ elseif (($bbox1 != null && $bbox1->isValid()) && !($bbox2 != null && $bbox2->isValid())) {
+ $e = new mb_exception("Mapbender_bbox: union: second parameter invalid!");
+ return $bbox1;
+ }
+ else {
+ if ($bbox1->epsg == $bbox2->epsg) {
+ $e = new mb_notice("Mapbender_bbox: union: bbox1 is: " . $bbox1);
+ $e = new mb_notice("Mapbender_bbox: union: bbox2 is: " . $bbox2);
+ $e = new mb_notice("Mapbender_bbox: union: merging bbox1 and bbox2...");
+ return new Mapbender_bbox(Mapbender_point::min($bbox1->min, $bbox2->min), Mapbender_point::max($bbox1->max, $bbox2->max), $bbox1->epsg);
+ }
+ else {
+ $e = new mb_exception("Mapbender_bbox: cannot process union with different EPSG codes");
+ }
+ }
+ }
+ else {
+ $e = new mb_exception("Mapbender_bbox: Invalid parameter (Not an array)!");
+ }
+ return null;
+ }
+
+ /**
+ * transforms this bbox in another EPSG
+ * @param toEpsg transform the bbox to this EPSG code, example: "EPSG:4326"
+ */
+ function transform($toEpsg) {
+ if ($this->isValid()) {
+ $this->epsg = $toEpsg;
+ $this->min->transform($toEpsg);
+ $this->max->transform($toEpsg);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * checks if lower left and upper right coordinate are set, as well as EPSG
+ */
+ function isValid() {
+ if ($this->min != null && $this->max != null && $this->epsg != null) {
+ return true;
+ }
+ $e = new mb_exception("Mapbender_bbox: this is not a valid bbox!");
+ return false;
+ }
+
+ function __toString() {
+ return (string) "[" . $this->min . $this->max . " " . $this->epsg . "]";
+ }
+}
+?>
\ No newline at end of file
Modified: branches/mapbender_sld/http/classes/class_checkInput.php
===================================================================
--- branches/mapbender_sld/http/classes/class_checkInput.php 2007-11-23 13:20:10 UTC (rev 1830)
+++ branches/mapbender_sld/http/classes/class_checkInput.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -29,7 +29,7 @@
if(count($v) != count($t)){
$e = new mb_exception("array params and array types have a different count in ".$_SERVER['SCRIPT_FILENAME'].": Sql: ".$q);
}
- if(PREPAREDSTATEMENTS == true){
+ if(PREPAREDSTATEMENTS == true && SYS_DBTYPE == "pgsql"){
$this->v = $v;
}
else{
Modified: branches/mapbender_sld/http/classes/class_gml2.php
===================================================================
--- branches/mapbender_sld/http/classes/class_gml2.php 2007-11-23 13:20:10 UTC (rev 1830)
+++ branches/mapbender_sld/http/classes/class_gml2.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -1,237 +1,234 @@
-<?php
-# $Id$
-# http://www.mapbender.org/index.php/class_gml2.php
-# 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("class_mb_exception.php");
-require_once("class_connector.php");
-require_once("../../conf/mapbender.conf");
-class gml2{
- var $geomtype_point = 'Point';
- var $geomtype_polygon = 'Polygon';
- var $geomtype_line = 'LineString';
- var $geomtype_multipolygon = 'MultiPolygon';
- var $geomtype_multiline = 'MultiLine';
- var $geometries = array();
- var $member = -1;
- var $geomtype = array();
- var $keys = array();
- var $values = array();
- var $geometry = array();
- var $bbox = array();
-
-
- function gml2(){
- $this->geometries = array($this->geomtype_point, $this->geomtype_polygon, $this->geomtype_line, $this->geomtype_multipolygon, $this->geomtype_multiline);
- }
- function getGml($req){
- $x = new connector($req);
- return $x->file;
- }
- function parsegml($req){
- #$data = implode("",file($req));
- $x = new connector($req);
- $data = $this->char_encode($x->file);
- $this->parse_xml($data);
- }
- function parsestring($data){
- $this->parse_xml($data);
- }
- function parse_xml($data){
- $section = false;
- $geom = false;
- $boundedBy = false;
- $coordinates = false;
- $el = -1;
- $parser = xml_parser_create(CHARSET);
- xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
- xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
- xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
- xml_parse_into_struct($parser,$data,$values,$tags);
- $code = xml_get_error_code ($parser);
- if ($code) {
- $line = xml_get_current_line_number($parser);
- $mb_exception = new mb_exception(xml_error_string($code) . " in line " . $line);
- }
- xml_parser_free($parser);
-
- foreach ($values as $element) {
- if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("boundedBy") && $element[type] == "open"){
- $boundedBy = true;
- }
- if ($boundedBy) {
- if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("coordinates")){
- $this->bbox = explode(",", str_replace(",,","",str_replace(" ",",",trim($element[value]))));
- $boundedBy=false;
- }
- }
- if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("featureMember") && $element[type] == "open"){
- $this->member++;
- $this->keys[$this->member] = array();
- $this->value[$this->member] = array();
- $this->geometry[$this->member] = array();
- $section = true;
- $cnt_geom = 0;
- }
- if($section == true){
- if( in_array($this->sepNameSpace($element[tag]),$this->geometries) && $element[type] == "open"){
- $geom = true;
- $this->geomtype[$this->member] = $this->sepNameSpace($element[tag]);
- }
- else if(in_array($this->sepNameSpace($element[tag]),$this->geometries) && $element[type] == "close"){
- $cnt_geom++;
- $geom = false;
- }
- if($geom == true){
- if (strtoupper($this->sepNameSpace($element[tag])) == strtoupper("coordinates")) {
- $this->geometry[$this->member][$cnt_geom] = str_replace(",,","",str_replace(" ",",",trim($element[value])));
- $coordinates = true;
- }
- else if (!$coordinates && trim($element[value])) {
- $coords = str_replace(",,","",str_replace(" ",",",trim($element[value])));
- $tmp_array = explode(",", $coords);
- if (count($tmp_array > 1)) {
- $this->geometry[$this->member][$cnt_geom] = $coords;
- $coordinates = true;
- }
- }
- }
- else if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("featureMember") && $element[type] == "close"){
- $section = false;
- $el = -1;
- }
- else{
- $el++;
- $this->values[$this->member][$el] = $element[value];
- $this->keys[$this->member][$el] = $element[tag];
- }
- }
- }
- }
-
- function sepNameSpace($s){
- $c = strpos($s,":");
- if($c>0){
- return substr($s,$c+1);
- }
- else{
- return $s;
- }
- }
-
- function getMemberCount(){
- return ($this->member+1);
- }
-
- function getValueBySeparatedKey($memberCount,$keyName){
- for($i=0; $i<count($this->keys[$memberCount]); $i++){
- if($this->sepNameSpace($this->keys[$memberCount][$i]) == $keyName){
- return $this->values[$memberCount][$i];
- }
- }
- }
-
- function getValueByKey($memberCount,$keyName){
- for($i=0; $i<count($this->keys[$memberCount]); $i++){
- if($this->keys[$memberCount][$i] == $keyName){
- return $this->values[$memberCount][$i];
- }
- }
- }
-
- function getXfromMemberAsString($memberCount,$geomCount){
- $t = explode(",",$this->geometry[$memberCount][$geomCount]);
- $x = array();
- for($i=0; $i<(count($t)-1); $i=$i+2){
- array_push($x,$t[$i]);
- }
- return implode(",",$x);
- }
-
- function getYfromMemberAsString($memberCount,$geomCount){
- $t = explode(",",$this->geometry[$memberCount][$geomCount]);
- $y = array();
- for($i=1; $i<=(count($t)-1); $i=$i+2){
- array_push($y,$t[$i]);
- }
- return implode(",",$y);
- }
-
- function getGeometriesFromMember($memberCount){
- return $this->geometry[$memberCount];
- }
-
- function getGeometryTypeFromMember($memberCount){
- return $this->geomtype[$memberCount];
- }
-
- function char_encode($s){
- if(CHARSET == 'UTF-8'){
- $s = utf8_encode($s);
- }
- return $s;
- }
-
- function exportGeometriesToJS ($isInFrame) {
- $prefix = "";
- if ($isInFrame == true) {
- $prefix = "parent.";
- }
- $js = "";
- $js .= "var geom = new ".$prefix."GeometryArray();\n";
- for ($i=0; $i<count($this->geometry); $i++) {
- $js .= $this->exportMemberToJS($i, $isInFrame);
- $js .= "geom.addCopy(q);\n";
- }
- return $js;
- }
-
- function exportMemberToJS ($i, $isInFrame) {
- $prefix = "";
- if ($isInFrame == true) {
- $prefix = "parent.";
- }
- $js = "";
- if ($this->getGeometryTypeFromMember($i) == $this->geomtype_point) {
- $js .= "var current_geomtype = ".$prefix."geomType.point;\n";
- }
- elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_line || $this->getGeometryTypeFromMember($i) == $this->geomtype_multiline) {
- $js .= "var current_geomtype = ".$prefix."geomType.line;\n";
- }
- elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_polygon || $this->getGeometryTypeFromMember($i) == $this->geomtype_multipolygon) {
- $js .= "var current_geomtype = ".$prefix."geomType.polygon;\n";
- }
- else die("unknown geometry type: '".$this->getGeometryTypeFromMember($i)."'");
-
- $js .= "var q = new ".$prefix."MultiGeometry(current_geomtype);\n";
-
- for ($j=0; $j<count($this->geometry[$i]); $j++) {
- $js .= "q.addGeometry(current_geomtype);\n";
-
- $x_array = explode(",", $this->getXfromMemberAsString($i, $j));
- $y_array = explode(",", $this->getYfromMemberAsString($i, $j));
-
- for ($k=0; $k<count($x_array); $k++) {
- $js .= "q.get(-1).addPointByCoordinates(parseFloat(".$x_array[$k]."), parseFloat(".$y_array[$k]."));\n";
- //$js .= "alert(parseFloat(".$x_array[$k]."), parseFloat(".$y_array[$k]."));";
- }
- $js .= "q.get(-1).close();\n";
- }
-// $js .= "alert(q);\n";
- return $js;
- }
-}
+<?php
+# $Id$
+# http://www.mapbender.org/index.php/class_gml2.php
+# 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("class_mb_exception.php");
+require_once("class_connector.php");
+require_once("../../conf/mapbender.conf");
+class gml2{
+ var $geomtype_point = 'Point';
+ var $geomtype_polygon = 'Polygon';
+ var $geomtype_line = 'LineString';
+ var $geomtype_multipolygon = 'MultiPolygon';
+ var $geomtype_multiline = 'MultiLine';
+ var $geometries = array();
+ var $member = -1;
+ var $geomtype = array();
+ var $keys = array();
+ var $values = array();
+ var $geometry = array();
+ var $bbox = array();
+
+
+ function gml2(){
+ $this->geometries = array($this->geomtype_point, $this->geomtype_polygon, $this->geomtype_line, $this->geomtype_multipolygon, $this->geomtype_multiline);
+ }
+ function getGml($req){
+ $x = new connector($req);
+ return $x->file;
+ }
+ function parsegml($req){
+ #$data = implode("",file($req));
+ $x = new connector($req);
+ $data = $x->file;
+ $this->parse_xml($data);
+ }
+ function parse_xml($data){
+ $section = false;
+ $geom = false;
+ $boundedBy = false;
+ $coordinates = false;
+ $values = null;
+ $tags = null;
+ $el = -1;
+ $parser = xml_parser_create(CHARSET);
+ xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
+ xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
+ xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
+ xml_parse_into_struct($parser,$data,$values,$tags);
+ $code = xml_get_error_code ($parser);
+ if ($code) {
+ $line = xml_get_current_line_number($parser);
+ $mb_exception = new mb_exception(xml_error_string($code) . " in line " . $line);
+ }
+ xml_parser_free($parser);
+
+ foreach ($values as $element) {
+ if(mb_strtoupper($this->sepNameSpace($element[tag])) == mb_strtoupper("boundedBy") && $element[type] == "open"){
+ $boundedBy = true;
+ }
+ if ($boundedBy) {
+ if(mb_strtoupper($this->sepNameSpace($element[tag])) == mb_strtoupper("coordinates")){
+ $this->bbox = explode(",", preg_replace("/,,/","",preg_replace("/ /",",",trim($element[value]))));
+ $boundedBy=false;
+ }
+ }
+ if(mb_strtoupper($this->sepNameSpace($element[tag])) == mb_strtoupper("featureMember") && $element[type] == "open"){
+ $this->member++;
+ $this->keys[$this->member] = array();
+ $this->value[$this->member] = array();
+ $this->geometry[$this->member] = array();
+ $section = true;
+ $cnt_geom = 0;
+ }
+ if($section == true){
+ if( in_array($this->sepNameSpace($element[tag]),$this->geometries) && $element[type] == "open"){
+ $geom = true;
+ $this->geomtype[$this->member] = $this->sepNameSpace($element[tag]);
+ }
+ else if(in_array($this->sepNameSpace($element[tag]),$this->geometries) && $element[type] == "close"){
+ $cnt_geom++;
+ $geom = false;
+ }
+ if($geom == true){
+ if (mb_strtoupper($this->sepNameSpace($element[tag])) == mb_strtoupper("coordinates")) {
+ $this->geometry[$this->member][$cnt_geom] = preg_replace("/,,/","",preg_replace("/ /",",",trim($element[value])));
+ $coordinates = true;
+ // XXX: Increment counter to get all geometries of a feature member,
+ // comment it out to only show first geometry of featuremember
+ $cnt_geom++;
+ }
+ else if (!$coordinates && trim($element[value])) {
+ $coords = preg_replace("/,,/","",preg_replace("/ /",",",trim($element[value])));
+ $tmp_array = explode(",", $coords);
+ if (count($tmp_array > 1)) {
+ $this->geometry[$this->member][$cnt_geom] = $coords;
+ $coordinates = true;
+ // XXX: Increment counter to get all geometries of a feature member,
+ // comment it out to only show first geometry of featuremember
+ $cnt_geom++;
+ }
+ }
+ }
+ else if(mb_strtoupper($this->sepNameSpace($element[tag])) == mb_strtoupper("featureMember") && $element[type] == "close"){
+ $section = false;
+ $el = -1;
+ }
+ else{
+ $el++;
+ $this->values[$this->member][$el] = $element[value];
+ $this->keys[$this->member][$el] = $element[tag];
+ }
+ }
+ }
+ }
+
+ function sepNameSpace($s){
+ $c = mb_strpos($s,":");
+ if($c>0){
+ return mb_substr($s,$c+1);
+ }
+ else{
+ return $s;
+ }
+ }
+
+ function getMemberCount(){
+ return ($this->member+1);
+ }
+
+ function getValueBySeparatedKey($memberCount,$keyName){
+ for($i=0; $i<count($this->keys[$memberCount]); $i++){
+ if($this->sepNameSpace($this->keys[$memberCount][$i]) == $keyName){
+ return $this->values[$memberCount][$i];
+ }
+ }
+ }
+
+ function getValueByKey($memberCount,$keyName){
+ for($i=0; $i<count($this->keys[$memberCount]); $i++){
+ if($this->keys[$memberCount][$i] == $keyName){
+ return $this->values[$memberCount][$i];
+ }
+ }
+ }
+
+ function getXfromMemberAsString($memberCount,$geomCount){
+ $t = explode(",",$this->geometry[$memberCount][$geomCount]);
+ $x = array();
+ for($i=0; $i<(count($t)-1); $i=$i+2){
+ array_push($x,$t[$i]);
+ }
+ return implode(",",$x);
+ }
+
+ function getYfromMemberAsString($memberCount,$geomCount){
+ $t = explode(",",$this->geometry[$memberCount][$geomCount]);
+ $y = array();
+ for($i=1; $i<=(count($t)-1); $i=$i+2){
+ array_push($y,$t[$i]);
+ }
+ return implode(",",$y);
+ }
+
+ function getGeometriesFromMember($memberCount){
+ return $this->geometry[$memberCount];
+ }
+
+ function getGeometryTypeFromMember($memberCount){
+ return $this->geomtype[$memberCount];
+ }
+ function exportGeometriesToJS ($isInFrame) {
+ $prefix = "";
+ if ($isInFrame == true) {
+ $prefix = "parent.";
+ }
+ $js = "";
+ $js .= "var geom = new ".$prefix."GeometryArray();\n";
+ for ($i=0; $i<count($this->geometry); $i++) {
+ $js .= $this->exportMemberToJS($i, $isInFrame);
+ $js .= "geom.addCopy(q);\n";
+ }
+ return $js;
+ }
+
+ function exportMemberToJS ($i, $isInFrame) {
+ $prefix = "";
+ if ($isInFrame == true) {
+ $prefix = "parent.";
+ }
+ $js = "";
+ if ($this->getGeometryTypeFromMember($i) == $this->geomtype_point) {
+ $js .= "var current_geomtype = ".$prefix."geomType.point;\n";
+ }
+ elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_line || $this->getGeometryTypeFromMember($i) == $this->geomtype_multiline) {
+ $js .= "var current_geomtype = ".$prefix."geomType.line;\n";
+ }
+ elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_polygon || $this->getGeometryTypeFromMember($i) == $this->geomtype_multipolygon) {
+ $js .= "var current_geomtype = ".$prefix."geomType.polygon;\n";
+ }
+ else die("unknown geometry type: '".$this->getGeometryTypeFromMember($i)."'");
+
+ $js .= "var q = new ".$prefix."MultiGeometry(current_geomtype);\n";
+
+ for ($j=0; $j<count($this->geometry[$i]); $j++) {
+ $js .= "q.addGeometry(current_geomtype);\n";
+
+ $x_array = explode(",", $this->getXfromMemberAsString($i, $j));
+ $y_array = explode(",", $this->getYfromMemberAsString($i, $j));
+
+ for ($k=0; $k<count($x_array); $k++) {
+ $js .= "q.get(-1).addPointByCoordinates(parseFloat(".$x_array[$k]."), parseFloat(".$y_array[$k]."));\n";
+ //$js .= "alert(parseFloat(".$x_array[$k]."), parseFloat(".$y_array[$k]."));";
+ }
+ $js .= "q.get(-1).close();\n";
+ }
+// $js .= "alert(q);\n";
+ return $js;
+ }
+}
?>
\ No newline at end of file
Modified: branches/mapbender_sld/http/classes/class_gui.php
===================================================================
--- branches/mapbender_sld/http/classes/class_gui.php 2007-11-23 13:20:10 UTC (rev 1830)
+++ branches/mapbender_sld/http/classes/class_gui.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -183,7 +183,7 @@
$error = true;
}
- $sql = "INSERT INTO gui_element (fkey_gui_id, e_id, e_pos, e_public, e_comment, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url) SELECT '" . $newGuiName . "', e_id, e_pos, e_public, e_comment, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url FROM gui_element WHERE fkey_gui_id = '" . $guiList . "';";
+ $sql = "INSERT INTO gui_element (fkey_gui_id, e_id, e_pos, e_public, e_comment, e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url) SELECT '" . $newGuiName . "', e_id, e_pos, e_public, e_comment, e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url FROM gui_element WHERE fkey_gui_id = '" . $guiList . "';";
$res = db_query($sql);
if (!$res) {
$report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
@@ -204,14 +204,15 @@
$error = true;
}
- $sql = "INSERT INTO gui_mb_group (fkey_gui_id, fkey_mb_group_id, mb_group_type) SELECT '" . $newGuiName . "', fkey_mb_group_id, mb_group_type FROM gui_mb_group WHERE fkey_gui_id = '" . $guiList . "';";
- $res = db_query($sql);
- if (!$res) {
- $report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
- $error = true;
- }
+ if ($withUsers == true) {
+ /* group of original gui is copied as well */
+ $sql = "INSERT INTO gui_mb_group (fkey_gui_id, fkey_mb_group_id, mb_group_type) SELECT '" . $newGuiName . "', fkey_mb_group_id, mb_group_type FROM gui_mb_group WHERE fkey_gui_id = '" . $guiList . "';";
+ $res = db_query($sql);
+ if (!$res) {
+ $report .= "<br><br>" . $sql . "<br><br>" . db_error() . "<br>";
+ $error = true;
+ }
- if ($withUsers == true) {
/* users of original gui are copied as well */
$sql = "INSERT INTO gui_mb_user (fkey_gui_id, fkey_mb_user_id, mb_user_type) SELECT '" . $newGuiName . "', fkey_mb_user_id, mb_user_type FROM gui_mb_user WHERE fkey_gui_id = '" . $guiList . "';";
$res = db_query($sql);
Added: branches/mapbender_sld/http/classes/class_keyword.php
===================================================================
--- branches/mapbender_sld/http/classes/class_keyword.php (rev 0)
+++ branches/mapbender_sld/http/classes/class_keyword.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -0,0 +1,371 @@
+<?php
+# $Id$
+# http://www.mapbender.org/index.php/class_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.
+
+include_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
+
+/**
+ * class to handle keywords for services
+ */
+
+class Mapbender_keyword{
+
+ private $service;
+ private $serviceId;
+
+ /*
+ * Constructor of the keyword-class
+ * set the service to: wms, layer, wfs, featuretype
+ *
+ * @param string service
+ * @param integer id the id of the service
+ *
+ */
+ function __construct($service,$serviceId){
+ $this->service = $service;
+ $this->serviceId = $serviceId;
+
+ if ($this->service == "layer"){
+
+ $this->table = 'layer_keyword';
+ $this->serviceIdColumn = 'fkey_layer_id';
+
+ }
+ //example for wms
+ else if ($this->service == "wms"){
+
+ $this->table = 'wms_keyword';
+ $this->serviceIdColumn = 'fkey_wms_id';
+
+ }
+ //example for featuretype
+ else if ($this->service == "featuretype"){
+
+ $this->table = 'wfs_featuretype_keyword';
+ $this->serviceIdColumn = 'fkey_featuretype_id';
+
+ }
+ }
+
+ /*
+ * selects a keyword
+ *
+ * @param integer the keyword_id
+ * @return string the name of the selected keyword
+ */
+ function get($keywordId){
+ global $con;
+ $sql = "SELECT keyword FROM keyword WHERE keyword_id = $1";
+ $v = array($keywordId);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ if($row = db_fetch_array($res)){
+ return $row['keyword'];
+ }
+ else{
+ return false;
+ }
+ }
+
+ /* selects keywords of layer
+ *
+ * @param integer the layer_id
+ * @return array keywords
+ */
+ function getLayerKeywords(){
+ global $con;
+ $sql = "SELECT keyword FROM keyword, layer_keyword, layer " .
+ "WHERE keyword.keyword_id = layer_keyword.fkey_keyword_id " .
+ "AND layer_keyword.fkey_layer_id = layer.layer_id " .
+ "AND layer.layer_id = $1";
+ $v = array($this->serviceId);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ $keywordList = "";
+ $separator = "";
+ while($row = db_fetch_array($res)){
+ if($keywordList != ""){
+ $separator = ",";
+ }
+ $keywordList .= $separator.$row["keyword"];
+ }
+ return $keywordList;
+ }
+
+ /* selects keywords of featuretype
+ *
+ * @param integer the featuretype_id
+ * @return array keywords
+ */
+ function getFeaturetypeKeywords(){
+ global $con;
+ $sql = "SELECT keyword FROM keyword, wfs_featuretype_keyword, wfs_featuretype " .
+ "WHERE keyword.keyword_id = wfs_featuretype_keyword.fkey_keyword_id " .
+ "AND wfs_featuretype_keyword.fkey_featuretype_id = wfs_featuretype.featuretype_id " .
+ "AND wfs_featuretype.featuretype_id = $1";
+ $v = array($this->serviceId);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ $keywordList = "";
+ $separator = "";
+ while($row = db_fetch_array($res)){
+ if($keywordList != ""){
+ $separator = ",";
+ }
+ $keywordList .= $separator.$row["keyword"];
+ }
+ return $keywordList;
+ }
+
+ /*
+ * Checks whether the keyword exist in the table keywords
+ *
+ * @param string the keyword
+ * @return integer the ID of the keyword
+ */
+ function exists($keyword){
+ global $con;
+ $sql = "SELECT keyword_id FROM keyword WHERE keyword = $1";
+ $v = array($keyword);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+ if($row = db_fetch_array($res)){
+ return $row['keyword_id'];
+ }
+ else{
+ return false;
+ }
+ }
+
+ /*
+ * Inserts a new keyword in the parent table keyword
+ * Check first, if the keyword exists
+ *
+ * @param string the keyword
+ * @return integer the id of the new keyword
+ */
+ function insert($keyword){
+ global $con;
+ if ($this->exists($keyword)){
+ return false;
+ }
+ else{
+ $sql = "INSERT INTO keyword (keyword) VALUES ($1)";
+ $v = array($keyword);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+ $id_sql = "SELECT keyword_id FROM keyword WHERE keyword = $1";
+ $id_v = array($keyword);
+ $id_t = array('s');
+ $id_res = db_prep_query($id_sql,$id_v,$id_t);
+ if($row = db_fetch_array($id_res)){
+ return $row['keyword_id'];
+ }
+ else{
+ return false;
+ }
+ }
+ }
+
+ /*
+ * Deletes the entry in the parent table keyword
+ *
+ * @param integer the keyword_id
+ * @return integer the ID of the keyword
+ */
+ function delete($keywordId){
+ global $con;
+ $sql = "DELETE FROM keyword WHERE keyword_id = $1";
+ $v = array($keywordId);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ if($row = db_fetch_array($res)){
+ return $row['keyword_id'];
+ }
+ else{
+ return false;
+ }
+ }
+
+ /*
+ * Inserts a new keyword-constraint in the crosstabulation
+ *
+ * @param integer the keyword_id
+ * @return integer the id of the new keyword-constraint
+ */
+ function allocate($keywordId){
+ global $con;
+ $sql = "INSERT INTO ".$this->table." (".$this->serviceIdColumn.", fkey_keyword_id) VALUES ($1,$2)";
+ $v = array($this->serviceId, $keywordId);
+ $t = array('i','i');
+ $res = db_prep_query($sql,$v,$t);
+ if($row = db_fetch_array($res)){
+ return $row['fkey_keyword_id'];
+ }
+ else{
+ return false;
+ }
+ }
+
+ /*
+ * Checks whether the keyword exist in the crosstabulation layer_keywords
+ *
+ * @param integer the keyword_id
+ * @return true or false
+ */
+ function isAllocated($keywordId){
+ global $con;
+ $sql = "SELECT ".$this->serviceIdColumn." FROM ".$this->table." WHERE fkey_keyword_id = $1";
+ $v = array($keywordId);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ if($row = db_fetch_array($res)){
+ return true;
+ }
+ else{
+ return false;
+ }
+ }
+
+ /*
+ * Deletes the entry in the crosstabulation (relation)
+ *
+ * @param integer the keyword_id
+ * @return integer the id of the keyword
+ */
+ function remove($keywordId){
+ global $con;
+ $sql = "DELETE FROM ".$this->table." WHERE ".$this->serviceIdColumn." = $1 AND fkey_keyword_id = $2";
+ $v = array($this->serviceId, $keywordId);
+ $t = array('i','i');
+ $res = db_prep_query($sql,$v,$t);
+ if($res!=FALSE){
+ return true;
+ }
+ else{
+ return false;
+ }
+ }
+
+ /*
+ * Deletes all entries of service in the crosstabulation (relation)
+ *
+ * @param
+ * @return
+ */
+ function removeAll(){
+ global $con;
+ $sql = "DELETE FROM ".$this->table." WHERE ".$this->serviceIdColumn." = $1";
+ $v = array($this->serviceId);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ if($res!=FALSE){
+ return true;
+ }
+ else{
+ return false;
+ }
+ }
+
+ /*
+ * Deletes the keyword if it has no entry in one of the crosstabs
+ *
+ * @TODO check if the keyword exists in every crosstab (wms, layer, wfs, feturetype) !!!
+ * @return integer the ID of the keyword
+ */
+ function orphaned(){
+ global $con;
+ $sql = "DELETE FROM keyword WHERE NOT EXISTS (SELECT fkey_keyword_id FROM layer_keyword WHERE keyword.keyword_id = layer_keyword.fkey_keyword_id);";
+ //$sql .= " AND NOT EXISTS (SELECT fkey_keyword_id FROM wms_keyword WHERE keyword.keyword_id = wms_keyword.fkey_keyword_id);";
+ $res = db_prep_query($sql);
+ if($res!=FALSE){
+ return true;
+ }
+ else{
+ return false;
+ }
+ }
+
+ /*
+ * add a new keyword.
+ *
+ * @param string the new keyword
+ */
+ function add($keyword){
+ // if the keyword exists add a new entry in the crosstab
+ if ($keywordId = $this->exists($keyword)){
+ $this->allocate($keywordId);
+ }
+ // if it doesn´t exist create a new entry in the keyword table and add a new entry in the crosstab
+ else{
+ $keywordId = $this->insert($keyword);
+ $this->allocate($keywordId);
+ }
+ }
+
+ /*
+ * add list of keywords to a service
+ *
+ * @param string[] keywords an array of keywords
+ */
+ function addList($keywords){
+ foreach ($keywords as $keyword){
+ // if the keyword exists add a new entry in the crosstab
+ if ($keywordId = $this->exists($keyword)){
+ $this->allocate($keywordId);
+ }
+ // if it doesn´t exist create a new entry in the keyword table and add a new entry in the crosstab
+ else{
+ $keywordId = $this->insert($keyword);
+ $this->allocate($keywordId);
+ }
+ }
+ }
+
+ /*
+ * replaces the keywords of a service
+ *
+ * @param string keywords an array of keywords
+ */
+ function replaceList($keywords){
+ // remove all entries in the crosstable for the current service
+ $this->removeAll();
+ // check for each keyword of the array if it exists
+ foreach ($keywords as $keyword){
+ // if the keyword exists add a new entry in the crosstab
+ if ($keywordId = $this->exists($keyword)){
+ // check if the keyword is allocated
+ $this->allocate($keywordId);
+ }
+ // if it doesn´t exist create a new entry in the keyword table and add a new entry in the crosstab
+ else{
+ $keywordIdNew = $this->insert($keyword);
+ $this->allocate($keywordIdNew);
+ }
+ }
+ // if a keyword exists, that has no constraint delete it
+ $this->orphaned();
+ }
+
+}
+
+
+//$x = new Mapbender_keyword("layer",20840);
+//echo $x->replaceList(array(test1,test2));
+?>
Modified: branches/mapbender_sld/http/classes/class_kml.php
===================================================================
--- branches/mapbender_sld/http/classes/class_kml.php 2007-11-23 13:20:10 UTC (rev 1830)
+++ branches/mapbender_sld/http/classes/class_kml.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -46,6 +46,10 @@
}
function createObjFromKML($kml_doc) {
+ $section = null;
+ $values = null;
+ $tags = null;
+
$data = $kml_doc;
if(!$data){
@@ -53,7 +57,7 @@
return false;
}
- $this->kml = $this->char_encode($data);
+ $this->kml = $data;
$parser = xml_parser_create(CHARSET);
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
@@ -62,7 +66,6 @@
xml_parse_into_struct($parser,$data,$values,$tags);
xml_parser_free($parser);
- $section;
$cnt_format = 0;
$parent = array();
$myParent = array();
@@ -71,49 +74,49 @@
$cnt_styles = -1;
foreach ($values as $element) {
- if(strtoupper($element[tag]) == "KML" && $element[type] == "open"){
+ if(mb_strtoupper($element[tag]) == "KML" && $element[type] == "open"){
$section = "kml";
}
- if ($section == "kml" && strtoupper($element[tag]) == "PLACEMARK" && $element[type] == "open") {
+ if ($section == "kml" && mb_strtoupper($element[tag]) == "PLACEMARK" && $element[type] == "open") {
$section = "placemark";
}
- if ($section == "placemark" && strtoupper($element[tag]) == "DESCRIPTION" && $element[type] == "complete") {
+ if ($section == "placemark" && mb_strtoupper($element[tag]) == "DESCRIPTION" && $element[type] == "complete") {
$this->description = $element[value];
}
- if ($section == "placemark" && strtoupper($element[tag]) == "NAME" && $element[type] == "complete") {
+ if ($section == "placemark" && mb_strtoupper($element[tag]) == "NAME" && $element[type] == "complete") {
$this->title = $element[value];
}
- if ($section == "placemark" && strtoupper($element[tag]) == "LOOKAT" && $element[type] == "open") {
+ if ($section == "placemark" && mb_strtoupper($element[tag]) == "LOOKAT" && $element[type] == "open") {
$section = "lookat";
}
if ($section == "lookat") {
- if (strtoupper($element[tag]) == "RANGE" && $element[type] == "complete") {
+ if (mb_strtoupper($element[tag]) == "RANGE" && $element[type] == "complete") {
$this->lookAt_range = $element[value];
}
- if (strtoupper($element[tag]) == "HEADING" && $element[type] == "complete") {
+ if (mb_strtoupper($element[tag]) == "HEADING" && $element[type] == "complete") {
$this->lookAt_heading = $element[value];
}
- if (strtoupper($element[tag]) == "TILT" && $element[type] == "complete") {
+ if (mb_strtoupper($element[tag]) == "TILT" && $element[type] == "complete") {
$this->lookAt_tilt = $element[value];
}
}
- if (strtoupper($element[tag]) == "STYLE" && $element[type] == "open") {
+ if (mb_strtoupper($element[tag]) == "STYLE" && $element[type] == "open") {
$section = "style";
}
- if ($section == "style" && strtoupper($element[tag]) == "ICONSTYLE" && $element[type] == "open") {
+ if ($section == "style" && mb_strtoupper($element[tag]) == "ICONSTYLE" && $element[type] == "open") {
$section = "iconstyle";
}
- if ($section == "iconstyle" && strtoupper($element[tag]) == "ICON" && $element[type] == "open") {
+ if ($section == "iconstyle" && mb_strtoupper($element[tag]) == "ICON" && $element[type] == "open") {
$section = "icon";
}
- if ($section == "icon" && strtoupper($element[tag]) == "HREF" && $element[type] == "complete") {
+ if ($section == "icon" && mb_strtoupper($element[tag]) == "HREF" && $element[type] == "complete") {
$this->icon = $element[value];
}
- if (strtoupper($element[tag]) == "POINT" && $element[type] == "open") {
+ if (mb_strtoupper($element[tag]) == "POINT" && $element[type] == "open") {
$section = "point";
}
- if ($section == "point" && strtoupper($element[tag]) == "COORDINATES" && $element[type] == "complete") {
+ if ($section == "point" && mb_strtoupper($element[tag]) == "COORDINATES" && $element[type] == "complete") {
$array = explode(",", $element[value]);
$this->x = $array[0];
$this->y = $array[1];
@@ -167,12 +170,6 @@
return $kml;
}
- function char_encode($s){
- if(CHARSET == 'UTF-8'){
- $s = utf8_encode($s);
- }
- return $s;
- }
}
// end class
?>
\ No newline at end of file
Added: branches/mapbender_sld/http/classes/class_layer_monitor.php
===================================================================
--- branches/mapbender_sld/http/classes/class_layer_monitor.php (rev 0)
+++ branches/mapbender_sld/http/classes/class_layer_monitor.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -0,0 +1,55 @@
+<?php
+# $Id: class_layer_monitor.php 791 2007-08-10 10:36:04Z baudson $
+# http://www.mapbender.org/index.php/
+# 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.
+
+class Layer_load_count {
+
+ function __construct () {
+ }
+
+ /**
+ * increments the load count in table "layer_load_count" for
+ * each layer in the WMC document by one.
+ */
+ function increment($layer_id) {
+
+ //check if an entry exists for the current layer id
+ $sql = "SELECT load_count FROM layer_load_count WHERE fkey_layer_id = $1";
+ $v = array($layer_id);
+ $t = array('i');
+ $res = db_prep_query($sql, $v, $t);
+ $row = db_fetch_array($res);
+
+ //if yes, increment the load counter
+ if ($row) {
+ $currentCount = $row["load_count"];
+ $sql = "UPDATE layer_load_count SET load_count = $1 WHERE fkey_layer_id = $2";
+ $v = array(intval($currentCount + 1), $layer_id);
+ $t = array('i', 'i');
+ $res = db_prep_query($sql, $v, $t);
+ }
+ //if no, insert a new row with current layer id and load_count = 1
+ else {
+ $sql = "INSERT INTO layer_load_count (fkey_layer_id, load_count) VALUES ($1, 1)";
+ $v = array($layer_id);
+ $t = array('i');
+ $res = db_prep_query($sql, $v, $t);
+ }
+ }
+}
+?>
\ No newline at end of file
Added: branches/mapbender_sld/http/classes/class_locale.php
===================================================================
--- branches/mapbender_sld/http/classes/class_locale.php (rev 0)
+++ branches/mapbender_sld/http/classes/class_locale.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -0,0 +1,196 @@
+<?php
+# $Id:$
+# http://www.mapbender.org/index.php/class_locale.php
+# 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
+
+include_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+
+/**
+ * sets the locale, depending on various settings:
+ * 1) a language ID passed to the constructor
+ * 2) the browser settings $_SERVER["HTTP_ACCEPT_LANGUAGE"]
+ * 3) a default language ID
+ *
+ */
+class Mb_locale {
+ var $knownLanguages = null;
+ var $systemLocales = null;
+ var $browserLanguages = null;
+ var $os = null;
+ var $name = null;
+ var $defaultLanguage = "de";
+ var $status = "No locale set.";
+
+ function Mb_locale($languageId) {
+ if (!$this->setCurrentLocale($languageId)) {
+ $e = new Mb_exception("Locale could not be set. Language ID: '" . $languageId . "'");
+ }
+ }
+
+ /**
+ * Get the current locale, evaluating GET/POST variables, browser languages
+ * and a default locale (in that preference)
+ *
+ * @returns current locale
+ */
+ function setCurrentLocale($languageId) {
+
+ // try to set the locale to $languageId
+ if ($this->checkAndSetLocale($languageId)) {
+ return true;
+ }
+ else {
+ $e = new Mb_notice("class_locale: no input parameter specified.");
+ }
+
+ // determine the browser setting and try to set locale according to that
+ if ($this->browserLanguage == null) {
+ $this->setBrowserLanguages();
+ }
+ foreach ($this->browserLanguages as $lang) {
+ $e = new Mb_notice("trying browser setting " . $lang);
+ if ($this->checkAndSetLocale($lang)) {
+ return true;
+ }
+ }
+
+ // set to default language
+ $e = new Mb_notice("trying default language " . $this->defaultLanguage);
+ return $this->checkAndSetLocale($this->defaultLanguage);
+ }
+
+ /**
+ * checks if a locale is available; if yes, it is set via setlocale
+ *
+ * @returns true if the the locale is set successfully; otherwise false
+ */
+ function checkAndSetLocale($languageId) {
+ if ($this->os == null) {
+ $this->os = $this->guessHostOS();
+ }
+
+ if ($this->os != null && isset($languageId)) {
+ if ($this->isKnownLanguage($languageId)) {
+
+ if ($this->systemLocales == null) {
+ $this->setSystemLocales();
+ }
+
+ $locale = $this->systemLocales[$this->knownLanguages[$languageId]][$this->os];
+ bindtextdomain(LOCALE_DOMAIN, LOCALE_DIR);
+ textdomain(LOCALE_DOMAIN);
+ if (setlocale(LC_ALL, $locale)) {
+ $this->name = $locale;
+ $_SESSION["mb_lang"] = $languageId;
+ $_SESSION["mb_locale"] = $this->name;
+ $e = new Mb_notice("locale " . $this->name . " ok on " . $this->os);
+ return true;
+ }
+ $e = new Mb_notice("locale " . $locale . " not found.");
+
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Guess the operating system which on which this code is running
+ * multiple methods are tested for reliably guessing the os
+ *
+ * @private
+ * @returns string with os name
+ */
+ function guessHostOS(){
+ if (strncasecmp(php_uname(), 'Windows', 7) == 0)
+ return 'windows';
+ else if (strncasecmp(php_uname(), 'Linux', 5) == 0)
+ return 'linux';
+ else if (strncasecmp(php_uname(), 'OpenBSD', 7) == 0)
+ return 'bsd';
+ else {
+ throw new Mb_exception('unknown platform: could not interpret uname. php_uname() returned '. php_uname().'. Please report to MB developers');
+ return null;
+ }
+ }
+
+ /**
+ * checks if a language is supported
+ *
+ * @returns true if the language is supported; otherwise false
+ */
+ function isKnownLanguage($languageId) {
+ if ($this->knownLocales == null) {
+ $this->setKnownLanguages();
+ }
+ if (array_key_exists($languageId, $this->knownLanguages)) {
+ return true;
+ }
+ else {
+ $e = new Mb_notice("language " . $languageId . " not supported.");
+ }
+ return false;
+ }
+
+
+
+ /**
+ * determines the available Locales on this system
+ */
+ function setSystemLocales() {
+ $this->systemLocales['it_IT'] = array('linux' => 'it_IT.utf8',
+ 'windows' => 'Italian_Italy.1252',
+ 'bsd' => 'it_IT',
+ 'posix' => 'it_IT');
+ $this->systemLocales['de_DE'] = array('linux' => 'de_DE.utf8',
+ 'windows' => 'German_Germany.1252',
+ 'bsd' => 'de_DE',
+ 'posix' => 'it_IT');
+ $this->systemLocales['en_US'] = array('linux' => 'en_US.utf8',
+ 'windows' => 'English_United States.1252',
+ 'bsd' => 'en_US',
+ 'posix' => 'it_IT');
+ }
+
+ /**
+ * set the known languages
+ */
+ function setKnownLanguages() {
+ $this->knownLanguages = array('en_US' => 'en_US',
+ 'en' => 'en_US',
+ 'de_DE' => 'de_DE',
+ 'de' => 'de_DE',
+ 'it_IT' => 'it_IT',
+ 'it' => 'it_IT');
+ }
+
+ /**
+ * sets the languages accepted by the client browser
+ */
+ function setBrowserLanguages () {
+ $this->browserLanguages = array();
+
+ $bLangs = split(',', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
+ foreach ($bLangs as $lang) {
+ if (strpos($lang, ';') === false)
+ array_push($this->browserLanguages, $lang);
+ else
+ array_push($this->browserLanguages, substr($lang, 0, strpos($lang, ';')));
+ }
+ }
+}
+?>
\ No newline at end of file
Modified: branches/mapbender_sld/http/classes/class_mb_exception.php
===================================================================
--- branches/mapbender_sld/http/classes/class_mb_exception.php 2007-11-23 13:20:10 UTC (rev 1830)
+++ branches/mapbender_sld/http/classes/class_mb_exception.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -29,6 +29,8 @@
var $mb_log_level = LOG_LEVEL;
var $dir = "../../log/";
var $filename_prefix = "mb_error_";
+ var $result = false;
+ var $message = "";
function indexOf($level, $levelArray) {
$index = false;
@@ -57,20 +59,48 @@
if($h = fopen($logfile,"a")){
$content = date("Y.m.d, H:i:s") . "," . $n .chr(13).chr(10);
if(!fwrite($h,$content)){
- #exit;
+ $this->result = false;
+ $this->message = "Unable to write " . $logfile;
+ return false;
}
fclose($h);
+ $this->result = true;
+ $this->message = "Successful.";
+ return true;
}
+ else {
+ $this->result = false;
+ $this->message = "Unable to open or generate " . $logfile;
+ return false;
+ }
}
+ else {
+ $this->result = false;
+ $this->message = "Directory " . $this->dir . " is not valid.";
+ return false;
+ }
}
+ else {
+ $this->result = false;
+ $this->message = "Log level '" . $level . "' is not valid or logging is disabled in mapbender.conf.";
+ return false;
+ }
}
}
+class mb_notice extends mb_log {
+ var $level = "notice";
+
+ function mb_notice($message) {
+ return $this->mb_log("Notice: " . $message, $this->level);
+ }
+}
+
class mb_warning extends mb_log {
var $level = "warning";
function mb_warning($message) {
- $this->mb_log($message, $this->level);
+ return $this->mb_log("Warning: " . $message, $this->level);
}
}
@@ -78,7 +108,7 @@
var $level = "error";
function mb_exception($message) {
- $this->mb_log($message, $this->level);
+ return $this->mb_log("ERROR: " . $message, $this->level);
}
}
?>
\ No newline at end of file
Added: branches/mapbender_sld/http/classes/class_metadata.php
===================================================================
--- branches/mapbender_sld/http/classes/class_metadata.php (rev 0)
+++ branches/mapbender_sld/http/classes/class_metadata.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -0,0 +1,1465 @@
+<?php
+# $Id$
+# http://www.mapbender.org/index.php/class_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.
+
+#require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/class_administration.php");
+require_once(dirname(__FILE__)."/class_mb_exception.php");
+
+include_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
+
+/**
+ * class to handle keywords for services
+ */
+
+class class_metadata{
+
+ private $user_id;
+
+ private $departments = array();
+ private $categories = array();
+ private $searchtext;
+ private $timestamp_beg;
+ private $timestamp_end;
+ private $limit;
+ private $search_bbox = array();
+ private $search_epsg;
+
+ private $obj_members = array();
+
+ private $availabilityTime;
+
+ private $doc;
+
+ /*
+ * Constructor of the class_metadata-class
+ *
+ * @$user_id integer users ID
+ * @$departments array departments
+ * @$categories array categories
+ * @$searchtext string searchtext (with blanks => more searchwords)
+ * @$timestamp_beg integer Timebegin of the Search in TIMESTAMP-Format
+ * @$timestamp_end integer Timeend of the Search in TIMESTAMP-Format
+ * @$limit integer Limit of the whole Result of the Metadata Search
+ * @$search_bbox array BoundingBox
+ * @$search_epsg string EPSG like: "EPSG:4326"
+ */
+ function logit($text){
+ if($h = fopen("/data/mapbender/http/tmp/gregor.txt","a")){
+ $content = $text .chr(13).chr(10);
+ if(!fwrite($h,$content)){
+ #exit;
+ }
+ fclose($h);
+ }
+
+ }
+
+ function __construct($user_id, $departments, $categories, $searchtext, $timestamp_beg, $timestamp_end, $limit, $search_bbox, $search_epsg){
+ $this->user_id = $user_id;
+
+ $this->departments = $departments;
+ $this->categories = $categories;
+ $this->searchtext = $searchtext;
+ $this->timestamp_beg = $timestamp_beg;
+ $this->timestamp_end = $timestamp_end;
+ $this->limit = $limit;
+ $this->search_bbox = $search_bbox;
+ $this->search_epsg = $search_epsg;
+
+ $this->availabilityTime = 60*60*24*90; // sec*min*hour*days
+
+// $e = new mb_notice("Search extended => user_id: ".$this->user_id."");
+// $e = new mb_notice("Search extended => searchtext: ".$this->searchtext."");
+// $e = new mb_notice("Search extended => timestamp_beg: ".$this->timestamp_beg."");
+// $e = new mb_notice("Search extended => timestamp_end: ".$this->timestamp_end."");
+// $e = new mb_notice("Search extended => limit: ".$this->limit."");
+// $e = new mb_notice("Search extended => search_epsg: ".$this->search_epsg."");
+//
+// $e = new mb_notice("Search extended => count departments: ".count($this->departments)."");
+// $e = new mb_notice("Search extended => count categories: ".count($this->categories)."");
+// $e = new mb_notice("Search extended => count search_bbox: ".count($this->search_bbox)."");
+
+// echo "Search extended => user_id: ".$this->user_id."<br>";
+// echo "Search extended => searchtext: ".$this->searchtext."<br>";
+// echo "Search extended => timestamp_beg: ".$this->timestamp_beg."<br>";
+// echo "Search extended => timestamp_end: ".$this->timestamp_end."<br>";
+// echo "Search extended => limit: ".$this->limit."<br>";
+// echo "Search extended => search_epsg: ".$this->search_epsg."<br>";
+// echo "Search extended => count search_bbox: ".count($this->search_bbox)."<br>";
+//
+// echo "Search extended => count departments: ".count($this->departments)."<br>";
+// echo "Search extended => count categories: ".count($this->categories)."<br>";
+// echo "Search extended => count search_bbox: ".count($this->search_bbox)."<br>";
+//
+// echo "Search extended => count departments: ".$this->departments[0]."<br>";
+// echo "Search extended => count categories: ".$this->categories[0]."<br>";
+// echo "Search extended => count search_bbox: ".$this->search_bbox[0]."<br>";
+
+
+ $this->logit("searchtext: ".$this->searchtext);
+ $this->logit("count categories: ".count($this->categories));
+ $this->logit("count departments: ".count($this->departments));
+ $this->logit("count search_bbox: ".count($this->search_bbox));
+
+ $cat_id="";
+ for ($index = 0; $index < sizeof($this->categories); $index++) {
+ $array_element = $this->categories[$index];
+
+ $cat_id .= $array_element.", ";
+ }
+
+ $this->isOverLimit;
+
+ $this->anz_wms=0;
+ $this->anz_wfs=0;
+
+ $cat = array();
+ $this->cat = $cat;
+
+ $this->user_authorization();
+
+ $this->set_categories();
+
+ $this->doc = new DOMDocument('1.0');
+
+ $this->generate_xml_output();
+
+ }
+
+ /*
+ * user authorization
+ */
+ function user_authorization(){
+
+ $n = new administration();
+ $this->n = $n;
+ $myguis = $this->n->getGuisByPermission($this->user_id,true);
+ $mywms = $this->n->getWmsByOwnGuis($myguis);
+
+ $myWFSconfs = $this->n->getWfsConfByPermission($this->user_id);
+
+
+
+ $this->myWFSConfs = $myWFSconfs;
+
+
+ for ($index = 0; $index < sizeof($this->myWFSConfs); $index++) {
+ $array_element = $this->myWFSConfs[$index];
+// echo $index."wfs_conf_id: ".$array_element."<br>";
+ }
+
+
+ $mylayer = array();
+
+ $this->mylayer = $mylayer;
+ if($mywms == false){
+ $mywms = array();
+ }
+
+ }
+
+ /* set categories as array */
+ function set_categories(){
+ $sql = "SELECT * FROM md_topic_category ";
+
+ $sql .= " ORDER BY md_topic_category_id";
+
+ $res = db_query($sql);
+ $this->cat[0] = array();
+ $this->cat[0]['md_topic_category_code_de'] = '';
+ $this->cat[0]['member'] = array();
+ $cnt = 1;
+ while($row = db_fetch_array($res)){
+ $this->cat[$cnt] = array();
+ $this->cat[$cnt]['md_topic_category_code_de'] = $row['md_topic_category_code_de'];
+ $this->cat[$cnt]['member'] = array();
+ $cnt++;
+// echo " => ".$row['md_topic_category_code_de'];
+// echo " => ".$row['md_topic_category_id']."<br>";
+
+ }
+
+
+ $cat_de="";
+
+ for ($index = 0; $index < sizeof($this->cat); $index++) {
+ $array_element = $this->cat[$index];
+
+ $cat_de .= "'".$this->cat[$index]['md_topic_category_code_de']."', ";
+
+ }
+
+// $this->logit("set cat => count categories in [][]: ".count($this->cat));
+// $this->logit("set cat => categories: ".$cat_de);
+
+ }
+
+ /*
+ * replace german letters (for example ä => ae)
+ */
+ function replaceChars($text){
+ $search = array( "ä", "ö", "ü", "Ä", "Ö", "Ü", "ß");
+ $repwith = array("ae", "oe", "ue", "AE", "OE", "UE", "ss");
+
+ if(CHARSET=="UTF-8")
+ $text = utf8_decode($text);
+
+ $ret = str_replace($search, $repwith, $text);
+
+ if(CHARSET=="UTF-8")
+ $ret = utf8_encode($ret);
+
+ return $ret;
+ }
+
+
+ function replaceString($string , $replaceString, $newString){
+
+ $newstr = str_replace($string, $replaceString, $newString);
+
+ return $newstr;
+
+ }
+
+
+ function generate_xml_output(){
+ $this->writeXmlhead();
+ $this->writeXmlWMSPart();
+ $this->writeXmlWFSPart();
+ $this->writeXmlEnd();
+ }
+
+ function writeXmlhead(){
+
+ $this->doc->encoding = CHARSET;
+ $result = $this->doc->createElement("result");
+ $this->doc->appendChild($result);
+
+ //Trefferanzahl
+ $overLimit = $this->doc->createElement('overLimit');
+ $result->appendChild($overLimit);
+ $tr_text = $this->doc->createTextNode($this->isOverLimit);
+ $overLimit->appendChild($tr_text);
+
+ $rd = $this->doc->createElement("redirect");
+ $result->appendChild($rd);
+ $trd = $this->doc->createTextNode("muss noch...");
+ $rd->appendChild($trd);
+
+ }
+
+ function writeXmlEnd(){
+
+ $overLimitText = $this->doc->createTextNode($this->isOverLimit);
+ $overLimits = $this->doc->getElementsByTagName("overLimit");
+ foreach ($overLimits as $overLimit) {
+
+ $overLimit->appendChild($overLimitText);
+ }
+
+
+ $ready = $this->doc->createElement('ready');
+ $tready = $this->doc->createTextNode("true");
+ $ready->appendChild($tready);
+
+ $results = $this->doc->getElementsByTagName("result");
+ foreach ($results as $result) {
+
+ $result->appendChild($ready);
+
+ }
+
+ echo $this->doc->saveXML(); // Ausgabe
+
+ $e = new mb_notice("Wrote the XML-File");
+ }
+
+
+ /*
+ * generats categories with members in the xml-File
+ */
+
+ function writeXmlWMSPart(){
+
+ $asstr = array();
+
+ if ($this->searchtext!="false"){
+ $asstr = split(" ",$this->searchtext);
+ }
+
+
+ $isTextSearch = "false";
+
+
+ for ($index = 0; $index < count($asstr); $index++) {
+ $array_element = $asstr[$index];
+ $e = new mb_notice("Search-Text: ".$index.". ".$array_element."");
+ }
+
+ $v = array();
+ $t = array();
+
+ $sql = "SELECT DISTINCT * from service_metadata where ";
+
+
+
+
+
+ for($i=0; $i<count($asstr); $i++){
+ $isTextSearch = "true";
+ if($i>0){$sql .= " AND ";}
+ $sql .= "searchtext LIKE $".($i+1);
+ $va = "%".trim(strtoupper($this->replaceChars($asstr[$i])))."%";
+ array_push($v,$va);
+ array_push($t,"s");
+ }
+
+
+ $whereBedArray = array();
+ //layer_searchable condition
+ array_push($whereBedArray, "(layer_searchable = 1)");
+
+
+ //date condition
+ if ($this->timestamp_beg!="false" && $this->timestamp_end!="false"){
+
+ $time ="(wms_timestamp BETWEEN ".$this->timestamp_beg." AND ".$this->timestamp_end.")";
+ array_push($whereBedArray, $time);
+
+ } else if ($this->timestamp_beg!="false" && $this->timestamp_end=="false"){
+
+ $time ="(wms_timestamp > ".$this->timestamp_beg.")";
+ array_push($whereBedArray, $time);
+
+ } else if ($this->timestamp_beg=="false" && $this->timestamp_end!="false"){
+
+ $time ="(wms_timestamp < ".$this->timestamp_end.")";
+ array_push($whereBedArray, $time);
+ }
+
+
+ //department condition
+ if(count($this->departments)>0){
+
+ $txt = $this->getDepartmentBed("wms_owner", "mb_user_department", $this->departments, "OR");
+ $dep = " (". $txt . ") ";
+ array_push($whereBedArray, $dep);
+
+ }
+
+
+
+// //Testausgabe
+// for ($index = 0; $index < sizeof($this->whereBedArray); $index++) {
+// $array_element = $this->whereBedArray[$index];
+// echo $index." el: ".$array_element."<br>";
+//
+// }
+
+ //Creating the Where Clausel, based on a Array
+ if(count($whereBedArray)>0){
+ $txt_whereBed="";
+
+ for ($index = 0; $index < sizeof($whereBedArray); $index++) {
+ $array_element = $whereBedArray[$index];
+
+
+ if($isTextSearch=="true") {
+ $txt_whereBed .=" AND ".$array_element;
+ } else {
+ if($index>0){
+ $txt_whereBed .=" AND ".$array_element;
+ } else {
+ $txt_whereBed .=" ".$array_element;
+ }
+ }
+
+ }
+
+ $sql .= $txt_whereBed;
+ }
+
+ //order by
+ $sql .= " ORDER BY load_count DESC";
+
+
+ //Beschränkung
+ $lim = $this->limit;
+ $overLimit = $lim+1;
+ $sql .= " LIMIT ".$overLimit;
+
+
+ for ($index = 0; $index < sizeof($asstr); $index++) {
+ $array_element = $asstr[$index];
+
+ $this->logit($index.".Suchwort : ".$array_element);
+ }
+
+ $this->logit("SQL_WMS: ".$sql);
+
+ $e = new mb_notice("Search extended => SQL-Request of view service_metadata: ".$sql."");
+ $res = db_prep_query($sql, $v, $t);
+
+ // spatial search
+
+
+
+// for ($index = 0; $index < sizeof($this->cat); $index++) {
+// $array_element = $this->cat[$index];
+//
+// $this->logit("0. vor Kategorieeinordnung => Kategorie: ".$this->cat[$index]['md_topic_category_code_de'].", Anzahl Member: ".count($this->cat[$index]['member']));
+// }
+
+
+ if(count($this->search_bbox)>0){
+ $anz = 0;
+ $resultColumns = array();
+ $resultColumns = $this->generateNewReaArray($res);
+
+ $e = new mb_notice("count service_metadata: ".count($resultColumns)."");
+
+ for ($index = 0; $index < count($resultColumns); $index++) {
+ $row = $resultColumns[$index];
+
+ if ($this->n->getLayerPermission($row['wms_id'], $row['layer_name'], $this->user_id)) {
+ array_push($this->mylayer,$row['layer_id']);
+ }
+ //accessconstraints -> email subadmin
+// $sql_ac = "SELECT mb_user_email FROM mb_user WHERE mb_user_id = $1";
+// $v = array($row["wms_owner"]);
+// $t = array('i');
+// $res_ac = db_prep_query($sql_ac, $v, $t);
+// if($row_ac = db_fetch_array($res_ac)){
+// $row["accessconstraints"] = $row_ac["mb_user_email"];
+// }
+ $ns = $this->make_members($row);
+ $anz++;
+ }
+ $e = new mb_notice("count service_metadata(spatial-search): ".$anz."");
+ $this->logit("ANZ_WMS mit bbox: ".$anz);
+ } else {
+ $anz = 0;
+
+ while($row = db_fetch_array($res)){
+
+ if ($this->n->getLayerPermission($row['wms_id'], $row['layer_name'], $this->user_id)) {
+ array_push($this->mylayer,$row['layer_id']);
+ }
+ //accessconstraints -> email subadmin
+// $sql_ac = "SELECT mb_user_email FROM mb_user WHERE mb_user_id = $1";
+// $v = array($row["wms_owner"]);
+// $t = array('i');
+// $res_ac = db_prep_query($sql_ac, $v, $t);
+//
+// if ($row_ac = db_fetch_array($res_ac)){
+// $row["accessconstraints"] = $row_ac["mb_user_email"];
+// }
+
+ $ns = $this->make_members($row);
+ $anz++;
+ }
+
+ $e = new mb_notice("count service_metadata(no spatial-search): ".$anz."");
+ $this->logit("ANZ_WMS ohne bbox: ".$anz);
+ }
+
+
+
+// for ($index = 0; $index < sizeof($this->cat); $index++) {
+// $array_element = $this->cat[$index];
+//
+// $this->logit("1.nach Kategorieeinordnung => Kategorie: ".$this->cat[$index]['md_topic_category_code_de'].", Anzahl Member: ".count($this->cat[$index]['member']));
+// }
+
+ if ($this->limit < $anz ){
+ $this->isOverLimit="true";
+ } else {
+ $this->isOverLimit="false";
+ }
+
+ $ns = $this->make_xml();
+ }
+
+ /*
+ * fills an array[][] with members based on categories
+ */
+ function make_members($r){
+
+// $sql = "SELECT fkey_md_topic_category_id FROM layer_md_topic_category WHERE fkey_layer_id = $1";
+
+ $sql = "SELECT fkey_md_topic_category_id, md_topic_category_code_de, fkey_layer_id " .
+ "FROM layer_md_topic_category, md_topic_category " .
+ "WHERE layer_md_topic_category.fkey_md_topic_category_id = md_topic_category.md_topic_category_id " .
+ "AND fkey_layer_id = $1";
+
+ $sql .= " ORDER BY fkey_md_topic_category_id";
+
+ $v = array($r['layer_id']);
+ $t = array('i');
+ $res = db_prep_query($sql, $v, $t);
+ $c = 0;
+
+ //layer with category
+ while($row = db_fetch_array($res)){
+
+ if (count($this->categories)>0){
+ if (in_array($row['fkey_md_topic_category_id'], $this->categories) ){
+ $this->cat[$row['fkey_md_topic_category_id']]['member'][count($this->cat[$row['fkey_md_topic_category_id']]['member'])] = $r;
+ }
+ } else {
+ $this->cat[$row['fkey_md_topic_category_id']]['member'][count($this->cat[$row['fkey_md_topic_category_id']]['member'])] = $r;
+ }
+
+// $this->cat[$row['fkey_md_topic_category_id']]['member'][count($this->cat[$row['fkey_md_topic_category_id']]['member'])] = $r;
+// $catID = $row['fkey_md_topic_category_id'];
+// array_push($this->cat[$catID]['member'],$r);
+ $c++;
+ }
+
+ // no category for this layer
+ if($c == 0){
+ array_push($this->cat[0]['member'],$r);
+ }
+ return true;
+ }
+
+
+
+ /*
+ * generats the xml-document
+ */
+ function make_xml(){
+
+// for ($index = 0; $index < sizeof($this->cat); $index++) {
+// $array_element = $this->cat[$index];
+//
+// echo "Kategorie: ".$this->cat[$index]['md_topic_category_code_de'].", Anzahl Member: ".count($this->cat[$index]['member'])."<br>";
+// }
+
+
+ $i=0;
+ if (count($this->categories) == 0){ // Wenn eine Kategorieauswahl werde WMSe/Layer die keiner Kategorie zugeordnet sind nicht angezeigt
+ $i=0;
+ } else {
+ $i=1;
+ }
+
+ for($i; $i<count($this->cat); $i++){
+ if(count($this->cat[$i]['member'])>0){
+
+
+
+ $c = $this->doc->createElement("category");
+ $results = $this->doc->getElementsByTagName("result");
+
+ foreach ($results as $result) {
+
+ $result->appendChild($c);
+
+ $c->setAttribute('name',$this->cat[$i]['md_topic_category_code_de']);
+ $c->setAttribute('count',count($this->cat[$i]['member']));
+ }
+
+ $this->logit("IM XML-Aufbau: category: ".$this->cat[$i]['md_topic_category_code_de'].", Anzahl: ".count($this->cat[$i]['member']));
+
+ for($ii=0; $ii<count($this->cat[$i]['member']); $ii++){
+
+// ###################
+// Schachtelung Start
+ $m = $this->doc->createElement('member');
+ $m->setAttribute('wms_id',$this->cat[$i]['member'][$ii]['wms_id']); // Attribut muss gesetzt werden um es wieder zu finden
+ $m->setAttribute('layer_pos',$this->cat[$i]['member'][$ii]['layer_pos']); // Attribut muss gesetzt werden um es wieder zu finden
+// $m->setAttribute('layer_parent',$this->cat[$i]['member'][$ii]['layer_parent']);
+
+ if ($ii != 0){
+
+ $members = $c->getElementsByTagName('member');
+ $sub = "false";
+ $mem = null;
+
+ foreach ($members as $member) {
+ $tmp_wms_id = $member -> getAttribute('wms_id');
+ $tmp_layer_pos = $member -> getAttribute('layer_pos');
+
+ /*
+ * Wiederfinden des Members über die Attribute
+ */
+ if ($this->cat[$i]['member'][$ii]['wms_id'] == $tmp_wms_id){
+
+ if ($this->cat[$i]['member'][$ii]['layer_parent'] == $tmp_layer_pos){
+ $sub = "true";
+ $member->appendChild($m); // dem member $member wird ein weiteres member $m hinzugefügt
+ break;
+
+ } else {
+ $sub = "false";
+ }
+ }
+ }
+
+ if ($sub == "true"){
+ // member konnte schon in der foreach-schleife eingefuegt werden
+ } else {
+ $c->appendChild($m); // member kategorie 1 (anderer WMS)
+ }
+ } else {
+
+ $c->appendChild($m); // member kategorie 1 (erstes member)
+
+ }
+
+// Schachtelung Ende
+// ###################
+
+ // LayerName
+ $state = $this->doc->createElement('layername');
+ $m->appendChild($state);
+
+ $name = "";
+ $layname = $this->cat[$i]['member'][$ii]['layer_name'];
+ if ($layname == "NULL" || $layname == "") {
+ $name = "";
+ } else {
+ $name = $layname;
+ }
+ $lay_name_text = $this->doc->createTextNode($name);
+ $state->appendChild($lay_name_text);
+
+
+ //Abfragbarkeit
+ $queryable = $this->doc->createElement('queryable');
+ $m->appendChild($queryable);
+
+ if ($this->cat[$i]['member'][$ii]['layer_queryable']==1){
+ $lay_queryable = "true";
+ } else {
+ $lay_queryable = "false";
+ }
+
+ $abf_text = $this->doc->createTextNode($lay_queryable);
+ $queryable->appendChild($abf_text);
+
+ // Epsg
+ $epsg = $this->doc->createElement('epsg');
+ $m->appendChild($epsg);
+
+ $equalEPSG = $this->checkEPSG($this->cat[$i]['member'][$ii]['wms_id']);
+
+ $epsg_text = $this->doc->createTextNode($equalEPSG);
+ $epsg->appendChild($epsg_text);
+
+ // Länderkennung
+ $state = $this->doc->createElement('federalstate');
+ $m->appendChild($state);
+
+ $spatialSource = "";
+ $stateorprovince = $this->cat[$i]['member'][$ii]['stateorprovince'];
+ if ($stateorprovince == "NULL" || $stateorprovince == "") {
+
+ $spatialSource = $this->cat[$i]['member'][$ii]['country'];
+ } else {
+ $spatialSource = $this->cat[$i]['member'][$ii]['stateorprovince'];
+ }
+
+ $countr_code_text = $this->doc->createTextNode($spatialSource);
+ $state->appendChild($countr_code_text);
+
+ // Satus des letzten Monitorings
+ $last_monitoring = $this->doc->createElement('last_monitoring');
+ $m->appendChild($last_monitoring);
+
+ $lastMonitoring = $this->getLastMonitoringDate($this->cat[$i]['member'][$ii]['wms_id']);
+
+ $last_monitoring_text = $this->doc->createTextNode($lastMonitoring);
+ $last_monitoring->appendChild($last_monitoring_text);
+
+ // Verfügbarkeit - Prozentzahl
+ $availability = $this->doc->createElement('availability');
+ $m->appendChild($availability);
+
+ $availabilityPercent = $this->getWMSavailability($this->cat[$i]['member'][$ii]['wms_id'], $this->availabilityTime);
+
+ $availability_text = $this->doc->createTextNode($availabilityPercent);
+
+
+
+ $availability->appendChild($availability_text);
+
+ // Relevanz / Count
+ $relevance = $this->doc->createElement('relevance');
+ $m->appendChild($relevance);
+
+ $lay_count=0;
+ if($this->cat[$i]['member'][$ii]['load_count'] != null){
+ $lay_count=$this->cat[$i]['member'][$ii]['load_count'];
+ }
+ $relevance_text = $this->doc->createTextNode($lay_count);
+ $relevance->appendChild($relevance_text);
+
+
+ //type
+ $type = $this->doc->createElement('type');
+ $m->appendChild($type);
+ if($this->cat[$i]['member'][$ii]['layer_pos'] > 0){
+ $ttype = $this->doc->createTextNode("layer");
+ }
+ else{
+ $ttype = $this->doc->createTextNode("wms");
+ }
+ $type->appendChild($ttype);
+
+ //wms_id
+ $wms__id = $this->doc->createElement('wms_id');
+ $m->appendChild($wms__id);
+ $id_text = $this->doc->createTextNode($this->cat[$i]['member'][$ii]['wms_id']);
+ $wms__id->appendChild($id_text);
+ //layer_id
+ $id = $this->doc->createElement('id');
+ $m->appendChild($id);
+ $tid = $this->doc->createTextNode($this->cat[$i]['member'][$ii]['layer_id']);
+ $id->appendChild($tid);
+ //title
+ $title = $this->doc->createElement('title');
+ $m->appendChild($title);
+ $ttitle = $this->doc->createTextNode($this->cat[$i]['member'][$ii]['layer_title']);
+ $title->appendChild($ttitle);
+ //abstract
+ $abst = $this->doc->createElement('abstract');
+ $m->appendChild($abst);
+ $tabst = $this->doc->createTextNode($this->cat[$i]['member'][$ii]['layer_abstract']);
+ $abst->appendChild($tabst);
+
+ // accesscontraints
+ $ac = $this->doc->createElement('accessconstraints');
+ $m->appendChild($ac);
+ $myac = $this->doc->createTextNode($this->cat[$i]['member'][$ii]['accessconstraints']);
+ $ac->appendChild($myac);
+
+ //data
+ $date = $this->doc->createElement('date');
+ $m->appendChild($date);
+ $tdate = $this->doc->createTextNode(date("d.m.Y",$this->cat[$i]['member'][$ii]['wms_timestamp']));
+ $date->appendChild($tdate);
+ //department
+ $dm = $this->doc->createElement('department');
+ $m->appendChild($dm);
+ $tdm = $this->doc->createTextNode($this->cat[$i]['member'][$ii]['mb_group_name']);
+ $dm->appendChild($tdm);
+
+ //permission // Leseberechtigung des Benutzers(true), sonst Email zur Beantragung(email)
+ $per = $this->doc->createElement('permission');
+ $m->appendChild($per);
+ $per_text = $this->getPermissionValue( $this->cat[$i]['member'][$ii]['wms_id'], $this->cat[$i]['member'][$ii]['layer_id']);
+ $pe = $this->doc->createTextNode($per_text);
+ $per->appendChild($pe);
+
+
+ // termsofuse
+ $ter = $this->doc->createElement('termsofuse');
+ $m->appendChild($ter);
+ $myter_text = $this->getTermOfUse($this->cat[$i]['member'][$ii]['wms_id']);
+ $myter = $this->doc->createTextNode($myter_text);
+ $ter->appendChild($myter);
+
+
+
+// $this->logit("Ende member: ".$ii);
+// echo "ende member: ".$ii."<br>";
+ }
+ }
+ }
+
+ }
+
+
+ function writeXmlWFSPart(){
+
+// $asstr = split(" ",$this->searchtext);
+
+ $asstr = array();
+
+ if ($this->searchtext!="false"){
+ $asstr = split(" ",$this->searchtext);
+ }
+
+ for ($index = 0; $index < count($asstr); $index++) {
+ $array_element = $asstr[$index];
+ $e = new mb_notice("Search-Text: ".$index.". ".$array_element."");
+ }
+
+ $v = array();
+ $t = array();
+
+ $sql = "SELECT DISTINCT * from wfs_service_metadata where ";
+ $whereBedArray = array();
+
+
+ $isTextSearch="false";
+ //textsearch
+ for($i=0; $i<count($asstr); $i++){
+ $isTextSearch="true";
+ if($i>0){$sql .= " AND ";}
+ $sql .= "searchtext LIKE $".($i+1);
+ $va = "%".trim(strtoupper($this->replaceChars($asstr[$i])))."%";
+ array_push($v,$va);
+ array_push($t,"s");
+
+ }
+
+ //date condition
+ if ($this->timestamp_beg!="false" && $this->timestamp_end!="false"){
+ $time ="(wfs_timestamp BETWEEN ".$this->timestamp_beg." AND ".$this->timestamp_end.")";
+ array_push($whereBedArray, $time);
+
+ } else if ($this->timestamp_beg!="false" && $this->timestamp_end=="false"){
+
+ $time ="(wfs_timestamp > ".$this->timestamp_beg.")";
+ array_push($whereBedArray, $time);
+
+ } else if ($this->timestamp_beg=="false" && $this->timestamp_end!="false"){
+
+ $time ="(wfs_timestamp < ".$this->timestamp_end.")";
+ array_push($whereBedArray, $time);
+ }
+
+
+ //department condition
+ if(count($this->departments)>0){
+
+ $txt = $this->getDepartmentBed("wfs_owner", "mb_user_department", $this->departments, "OR");
+ $dep = " (". $txt . ") ";
+ array_push($whereBedArray, $dep);
+
+ }
+
+ //featuretype_searchable condition
+ array_push($whereBedArray, "(featuretype_searchable = 1)");
+
+
+
+ // Creating the Where Clausel, based on a Array
+ if(count($whereBedArray)>0){
+ $txt_whereBed="";
+ for ($index = 0; $index < sizeof($whereBedArray); $index++) {
+ $array_element = $whereBedArray[$index];
+
+ if($isTextSearch=="true") {
+ $txt_whereBed .=" AND ".$array_element;
+ } else {
+ if($index>0){
+ $txt_whereBed .=" AND ".$array_element;
+ } else {
+ $txt_whereBed .=" ".$array_element;
+ }
+ }
+
+// $txt_whereBed .=" AND ".$array_element;
+ }
+ $sql .= $txt_whereBed;
+ }
+
+
+ //order by
+ $sql .= " ORDER BY featuretype_id ";
+
+// echo "WFS-SQL:<br>".$sql."<br>";
+
+ $this->logit("WFS_SQL: ".$sql);
+
+ $e = new mb_notice("Search extended => SQL-Request of view service_metadata: ".$sql."");
+
+ $res = db_prep_query($sql, $v, $t);
+ $c = $this->doc->createElement("category");
+ $results = $this->doc->getElementsByTagName("result");
+
+ foreach ($results as $result) {
+
+ $result->appendChild($c);
+
+ $c->setAttribute('name', "Geometriedienste");
+ $c->setAttribute('count', "0");
+ }
+
+ $i = 0;
+
+ while($row = db_fetch_array($res)){
+
+ $m = $this->doc->createElement('member');
+ $m->setAttribute('wfs_id', $row['wfs_id']);
+ $m->setAttribute('layer_pos', "");
+
+ $c->appendChild($m); // member kategorie 1 (erstes member)
+
+ //Abfragbarkeit
+ $queryable = $this->doc->createElement('queryable');
+ $m->appendChild($queryable);
+
+
+ if ($row['featuretype_searchable'] == "1"){
+ $lay_queryable = "true";
+ } else {
+ $lay_queryable = "false";
+ }
+
+ $search_text = $this->doc->createTextNode($lay_queryable);
+ $queryable->appendChild($search_text);
+
+ // Epsg
+ $epsg = $this->doc->createElement('epsg');
+ $m->appendChild($epsg);
+
+ $equalEPSG = $row['featuretype_srs'];
+
+ $epsg_text = $this->doc->createTextNode($equalEPSG);
+ $epsg->appendChild($epsg_text);
+
+ // Länderkennung
+ $state = $this->doc->createElement('federalstate');
+ $m->appendChild($state);
+
+ $spatialSource = "";
+ $stateorprovince = $row['administrativearea'];
+ if ($stateorprovince == "NULL" || $stateorprovince == "") {
+
+ $spatialSource = $row['country'];
+ } else {
+ $spatialSource = $row['administrativearea'];
+ }
+
+ $countr_code_text = $this->doc->createTextNode($spatialSource);
+ $state->appendChild($countr_code_text);
+
+
+ //type
+ $type = $this->doc->createElement('type');
+ $m->appendChild($type);
+ $ttype = $this->doc->createTextNode("wfs");
+ $type->appendChild($ttype);
+
+// // FeaturetypeName
+// $state = $this->doc->createElement('name');
+// $m->appendChild($state);
+//
+// $name = "";
+// $stateorprovince = $row['featuretype_name'];
+// if ($stateorprovince == "NULL" || $stateorprovince == "") {
+//
+//// $name = $row[''];
+// } else {
+// $name = $row['featuretype_name'];
+// }
+//
+// $countr_code_text = $this->doc->createTextNode($name);
+// $state->appendChild($countr_code_text);
+
+ //id
+ $id = $this->doc->createElement('featuretype_id');
+ $m->appendChild($id);
+ $tid = $this->doc->createTextNode($row['featuretype_id']);
+ $id->appendChild($tid);
+
+ //wfs_conf_id
+ $conf_id = $this->doc->createElement('wfs_conf_id');
+ $m->appendChild($conf_id);
+ $c_id = $this->doc->createTextNode($row['wfs_conf_id']);
+ $conf_id->appendChild($c_id);
+
+ //title
+ $title = $this->doc->createElement('title');
+ $m->appendChild($title);
+ $ttitle = $this->doc->createTextNode($row['wfs_conf_abstract']);
+
+ //title
+ $title = $this->doc->createElement('title');
+ $m->appendChild($title);
+ $ttitle = $this->doc->createTextNode($row['wfs_conf_abstract']);
+
+ $title->appendChild($ttitle);
+ //abstract
+ $abst = $this->doc->createElement('abstract');
+ $m->appendChild($abst);
+ $tabst = $this->doc->createTextNode($row['wfs_conf_description']);
+ $abst->appendChild($tabst);
+
+
+ // Geomtype
+ $geo = $this->doc->createElement('geomtype');
+ $m->appendChild($geo);
+ $geo_text = $this->getGeoType($row['wfs_id'], $row['featuretype_id']);
+ $ge = $this->doc->createTextNode($geo_text);
+ $geo->appendChild($ge);
+
+
+ // accesscontraints
+ $ac = $this->doc->createElement('accessconstraints');
+ $m->appendChild($ac);
+// $myac = $this->getAccessConstraints($this->cat[$i]['member'][$ii]['wms_id'], $this->cat[$i]['member'][$ii]['accessconstraints'], $this->cat[$i]['member'][$ii]['layer_id']);
+ $myac = $this->doc->createTextNode($row['accessconstraints']);
+ $ac->appendChild($myac);
+
+ //data
+ $date = $this->doc->createElement('date');
+ $m->appendChild($date);
+ $tdate = $this->doc->createTextNode(date("d.m.Y",$row['wfs_timestamp']));
+ $date->appendChild($tdate);
+ //department
+ $dm = $this->doc->createElement('department');
+ $m->appendChild($dm);
+ $tdm = $this->doc->createTextNode($row['mb_group_name']);
+ $dm->appendChild($tdm);
+
+ //permission Leseberechtigung des Benutzers(true), sonst Email zur Beantragung(email)
+ $per = $this->doc->createElement('permission');
+ $m->appendChild($per);
+ $per_text = $this->getPermissionValueForWFS($row['wfs_id'], $row['wfs_conf_id']);
+ $pe = $this->doc->createTextNode($per_text);
+ $per->appendChild($pe);
+
+// // termsofuse
+// $ter = $this->doc->createElement('termsofuse');
+// $m->appendChild($ter);
+//// $myter = $this->getAccessConstraints($this->cat[$i]['member'][$ii]['wms_id'], $this->cat[$i]['member'][$ii]['accessconstraints'], $this->cat[$i]['member'][$ii]['layer_id']);
+// $myter_text = "";
+// $myter = $this->doc->createTextNode($myter_text);
+// $ter->appendChild($myter);
+
+ $i++;
+ }
+
+ $c->setAttribute('count', $i);
+
+ $this->anz_wfs = $i;
+ }
+
+
+
+ function getLastMonitoringDate($wms_id){
+
+ $sql = "SELECT max(upload_id) as last_time, status FROM mb_monitor WHERE fkey_wms_id=$1 GROUP BY (status)";
+ $v = array($wms_id);
+ $t = array('i');
+ $res = db_prep_query($sql, $v, $t);
+ $c = 0;
+
+ $status = "";
+ while($row = db_fetch_array($res)){
+
+ $status = $row['status'];
+ $c++;
+
+ }
+
+ return $status;
+ }
+
+ /*
+ * Returns the availability of a WMS/Layer during a period of time
+ * in percent
+ */
+ function getWMSavailability ($wms_id, $time_period){
+
+ $timestamp = time();
+ $datum = date("d.m.Y - H:i", $timestamp);
+
+ $last_timestamp = $timestamp - $time_period;
+
+ $last_date = date("d.m.Y - H:i", $last_timestamp);
+
+// Vorrübergehend auskommentiert da keine aktuellen (auf Timestamp basierten) Daten vorliegen
+// $sql = "SELECT upload_id as time, status FROM mb_monitor WHERE fkey_wms_id=$1 AND upload_id > ".$last_timestamp;
+
+ $sql = "SELECT upload_id as time, status FROM mb_monitor WHERE fkey_wms_id=$1";
+
+ $v = array($wms_id);
+ $t = array('i');
+ $res = db_prep_query($sql, $v, $t);
+ $c = 0;
+ $positivStatus=0;
+
+ while($row = db_fetch_array($res)){
+
+ if ($row['status'] == "1" || $row['status'] == "0"){
+ $positivStatus++;
+ }
+ $c++;
+
+ }
+
+ $percent=0;
+
+ if ($c!=0){
+ $percent = ($positivStatus*100) / $c;
+ } else {
+ $percent = 0;
+ }
+
+ return number_format($percent,0, ",", ".") ;
+
+ }
+
+ function checkEPSG ($wms_id){
+
+ $sql = "SELECT wms.wms_id, wms_srs.wms_srs FROM wms, wms_srs where wms.wms_id=fkey_wms_id and wms.wms_id=$1";
+ $v = array($wms_id);
+ $t = array('i');
+ $res = db_prep_query($sql, $v, $t);
+ $c = 0;
+
+ $isequal = "false";
+ while($row = db_fetch_array($res)){
+
+ $wms_epsg = $row['wms_srs.wms_srs'];
+ $c++;
+
+ }
+
+ if ($wms_epsg==$this->epsg){
+ $isequal="true";
+ }
+ return $isequal;
+ }
+
+
+ function isPermissioned() {
+
+
+
+ }
+
+ function getPermissionValue($wms_id, $lay_id){
+ $return_permission="";
+ // get permission
+ if (in_array($lay_id, $this->mylayer)){
+ $return_permission = "true";
+ } else {
+
+ $sql = "SELECT wms.wms_id, mb_user.mb_user_email as email FROM wms, mb_user where wms.wms_owner=mb_user.mb_user_id " .
+ "and wms.wms_id=$1";
+
+ $v = array($wms_id);
+ $t = array('i');
+ $res = db_prep_query($sql, $v, $t);
+
+ // get email
+ $mail="";
+ while($row = db_fetch_array($res)){
+ $mail = $row['email'];
+ $return_permission = $mail;
+ }
+ }
+ return $return_permission;
+ }
+
+ function getPermissionValueForWFS($wfs_id, $wfs_conf_id){
+ $return_permission="";
+ // get permission
+ if (in_array($wfs_conf_id, $this->myWFSConfs)){
+ $return_permission = "true";
+ } else {
+ $sql = "SELECT wfs.wfs_id, mb_user.mb_user_email as email FROM wfs, mb_user where wfs.wfs_owner=mb_user.mb_user_id " .
+ "and wfs.wfs_id=$1";
+
+ $v = array($wfs_id);
+ $t = array('i');
+ $res = db_prep_query($sql, $v, $t);
+
+ // get email
+ $mail="";
+ while($row = db_fetch_array($res)){
+ $mail = $row['email'];
+ $return_permission = $mail;
+ }
+ }
+ return $return_permission;
+ }
+
+
+ function getTermOfUse($wms_id){
+
+ $return_tou_id="";
+
+ $sql = "SELECT wms.wms_id, wms_termsofuse.fkey_wms_id, wms_termsofuse.fkey_termsofuse_id, termsofuse.termsofuse_id as tid " .
+ "FROM wms, wms_termsofuse, termsofuse " .
+ "where wms.wms_id=wms_termsofuse.fkey_wms_id " .
+ "and wms_termsofuse.fkey_termsofuse_id=termsofuse.termsofuse_id " .
+ "and wms.wms_id=$1";
+
+ $v = array($wms_id);
+ $t = array('i');
+ $res = db_prep_query($sql, $v, $t);
+
+ // get termsofuse_id
+ $termsofuse_id="";
+ while($row = db_fetch_array($res)){
+ $termsofuse_id = $row['tid'];
+// $return_tou_id = "mapbender/php/mod_termsofuse_service.php?id=".$termsofuse_id;
+ $return_tou_id = $termsofuse_id;
+
+ }
+
+ return $return_tou_id;
+
+ }
+
+ function generateNewReaArray($result){
+ global $con;
+// echo "func generateNewReaArray<br>";
+
+// $this->search_bbox;
+// $this->search_epsg;
+
+ $delColumns = array();
+
+ $columnsResult = array();
+
+ $db_epsg="";
+ $db_minx="";
+ $db_miny="";
+ $db_maxx="";
+ $db_maxy="";
+
+ $isIntersecting = "";
+
+ $anz = 0;
+
+ while($row = db_fetch_array($result)){
+
+
+ $status="";
+// echo $anz.". layer_id: ".$row['layer_id'];
+
+ //EPSG Vergleich
+ $sql_ac = "SELECT * FROM layer_epsg WHERE fkey_layer_id = $1";
+ $v = array($row["layer_id"]);
+ $t = array('i');
+ $res_ac = db_prep_query($sql_ac, $v, $t);
+
+ $tra_epsg="";
+ $tra_minx="";
+ $tra_miny="";
+ $tra_maxx="";
+ $tra_maxy="";
+
+
+
+ $i=0;
+ while($row_ac = db_fetch_array($res_ac)){
+
+ if ($row_ac["epsg"]=="EPSG:4326"){ // maybe for transformation needed
+ $db_epsg=$row_ac["epsg"];
+ $db_minx=$row_ac["minx"];
+ $db_miny=$row_ac["miny"];
+ $db_maxx=$row_ac["maxx"];
+ $db_maxy=$row_ac["maxy"];
+ }
+
+ if ($row_ac["epsg"]==$this->search_epsg){
+// if ($row_ac["epsg"]=="EPSG:31467"){
+
+ $db_epsg=$row_ac["epsg"];
+ $db_minx=$row_ac["minx"];
+ $db_miny=$row_ac["miny"];
+ $db_maxx=$row_ac["maxx"];
+ $db_maxy=$row_ac["maxy"];
+
+
+ $status="match";
+ break;
+
+ } else {
+
+
+ }
+ $i++;
+ }
+
+ if ($status=="match"){
+
+// echo "match<br>";
+
+ $temp = $this->search_bbox;
+
+ $isIntersecting = $this->intersect($temp[0], $temp[1], $temp[2], $temp[3], $db_minx, $db_miny, $db_maxx, $db_maxy, $this->search_epsg);
+
+
+ } else if ($status != "match" && $i>0){
+
+// echo "Transformation<br>";
+// Transformation
+
+ $temp = $this->search_bbox;
+
+ $sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$temp[0]." ".$temp[1].")',".str_replace("EPSG:","",$this->search_epsg)."), 4326)) as minx";
+
+ $resMinx = @pg_query($con,$sqlMinx);
+ $s_minx = pg_result($resMinx,0,"minx");
+
+ $sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$temp[0]." ".$temp[1].")',".str_replace("EPSG:","",$this->search_epsg)."), 4326)) as miny";
+ $resMiny = @pg_query($con,$sqlMiny);
+ $s_miny = pg_result($resMiny,0,"miny");
+
+ $sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$temp[2]." ".$temp[3].")',".str_replace("EPSG:","",$this->search_epsg)."), 4326)) as maxx";
+ $resMaxx = @pg_query($con,$sqlMaxx);
+ $s_maxx = pg_result($resMaxx,0,"maxx");
+
+ $sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$temp[2]." ".$temp[3].")',".str_replace("EPSG:","",$this->search_epsg)."), 4326)) as maxy";
+ $resMaxy = @pg_query($con,$sqlMaxy);
+ $s_maxy = pg_result($resMaxy,0,"maxy");
+
+ $isIntersecting = $this->intersect($s_minx, $s_miny, $s_maxx, $s_maxy, $db_minx, $db_miny, $db_maxx, $db_maxy, "EPSG:4326");
+
+ } else {
+// "no intersection possible()<br>";
+ $isIntersecting="f";
+ }
+
+ if ($isIntersecting=="t"){
+
+// Datensatz loeschen
+ array_push($columnsResult, $row);
+
+ }
+
+ $anz++;
+
+ }
+ return $columnsResult;
+
+ }
+
+ function intersect($s_minx, $s_miny, $s_maxx, $s_maxy, $db_minx, $db_miny, $db_maxx, $db_maxy, $epsg){
+ global $con;
+
+ $result="";
+
+ $sqlint = "SELECT intersects(envelope(geometryFROMtext('LINESTRING(".$s_minx." ".$s_miny.", ".$s_maxx." ".$s_maxy.")',".str_replace("EPSG:","",$epsg).")) " .
+ ",envelope(geometryFROMtext('LINESTRING(".$db_minx." ".$db_miny.", ".$db_maxx." ".$db_maxy.")',".str_replace("EPSG:","",$epsg).")))";
+
+ $resInt = @pg_query($con,$sqlint);
+ $result = pg_result($resInt,0,"intersects");
+
+ return $result;
+
+ }
+
+
+
+ /*
+ * Checks whether the keyword exist in the table keywords
+ *
+ * @todo is UPPER() working with mysql
+ * @param string the keyword
+ * @return integer the ID of the keyword
+ */
+ function exists($keyword){
+ global $con;
+ $sql = "SELECT keyword_id FROM keyword WHERE UPPER(keyword) = UPPER($1)";
+ $v = array($keyword);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+ if($row = db_fetch_array($res)){
+ return $row['keyword_id'];
+ }
+ else{
+ return false;
+ }
+ }
+
+
+ function getSQLBedfromArray($culumnName, $columnValues, $additionalChar){
+
+
+ $a = array();
+ $a = $columnValues;
+
+ $a_char = $additionalChar;
+ $colName=$culumnName;
+
+
+
+ $resultSql="";
+
+ for ($index = 0; $index < sizeof($a); $index++) {
+ $array_element = $a[$index];
+
+ if ($index<1){
+ $resultSql .= $colName."='".$a[$index]."'";
+ }else{
+
+ $resultSql .= " ".$a_char." " .$colName."='".$a[$index]."'";
+
+ }
+ }
+
+ return $resultSql;
+ }
+
+ function getDepartmentBed ($columnFkey, $culumnName, $columnValues, $additionalChar){
+
+ $a = array();
+ $a = $columnValues;
+
+ $colName=$culumnName;
+ $a_char = $additionalChar;
+
+ $resultSql = $columnFkey." in (SELECT mb_user_id FROM mb_user WHERE ";
+
+ for ($index = 0; $index < count($a); $index++) {
+ $array_element = $a[$index];
+
+ if ($index<1){
+ $resultSql .= $colName."='".$a[$index]."'";
+ }else{
+
+ $resultSql .= " ".$a_char." " .$colName."='".$a[$index]."'";
+
+ }
+ }
+ $resultSql .=")";
+
+ return $resultSql;
+ }
+
+ function getGeoType($wfs_id, $featureType_id){
+
+ $return_geoType="";
+
+ $sql = "SELECT element_type FROM wfs_element, wfs_featuretype " .
+ "where wfs_featuretype.featuretype_id=wfs_element.fkey_featuretype_id " .
+ "and element_name='the_geom'" .
+ "and wfs_featuretype.fkey_wfs_id = $1" .
+ "and wfs_element.fkey_featuretype_id=$2";
+
+ $v = array($wfs_id, $featureType_id);
+ $t = array('i', 'i');
+ $res = db_prep_query($sql, $v, $t);
+
+ // get element_type
+ while($row = db_fetch_array($res)){
+ $return_geoType = $row['element_type'];;
+ }
+
+ return $return_geoType;
+
+ }
+
+}
+
+?>
Added: branches/mapbender_sld/http/classes/class_monitor.php
===================================================================
--- branches/mapbender_sld/http/classes/class_monitor.php (rev 0)
+++ branches/mapbender_sld/http/classes/class_monitor.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -0,0 +1,478 @@
+<?php
+# $Id: class_layer_monitor.php 791 2007-08-10 10:36:04Z baudson $
+# http://www.mapbender.org/index.php/
+# 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__)."/../classes/class_wms.php");
+require_once(dirname(__FILE__)."/../classes/class_bbox.php");
+require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+
+define("MONITOR_DEFAULT_SCALE", 500000);
+define("MONITOR_IMG_WIDTH", 20);
+define("MONITOR_IMG_HEIGHT", 20);
+define("MB_RESOLUTION", 28.35);
+
+class Monitor {
+ /**
+ * 1 = reachable and in sync with db
+ * 0 = reachable and out of sync with db
+ * -1 = unreachable
+ * -2 = monitoring in progress
+ *
+ */
+ var $result = -1;
+
+ /**
+ * 1 = the get map request DEFINITELY returns a valid map image
+ * 0 = the WMS doesn't support XML error format. Who knows if the image is really a map?
+ * -1 = the get map request doesn't return an image
+ */
+ var $returnsImage;
+
+ var $comment = "";
+ var $updated = "0";
+ var $supportsXMLException = false;
+
+ var $timestamp;
+ var $capabilitiesURL;
+ var $mapURL;
+
+ var $remoteXML;
+ var $localXML;
+
+ function __construct($wmsId, $uploadId, $autoUpdate) {
+ $this->wmsId = $wmsId;
+ $this->uploadId = $uploadId;
+ $this->autoUpdate = $autoUpdate;
+
+ $this->capabilitiesURL = $this->getUploadURL($this->wmsId, $this->uploadId);
+
+ set_time_limit(TIME_LIMIT);
+
+
+ $this->timestamp = time();
+
+ if ($this->capabilitiesURL) {
+
+ $remoteWms = new wms();
+ $remoteWms->createObjFromXML($this->capabilitiesURL);
+ $this->remoteXML = $remoteWms->wms_getcapabilities_doc;
+ $this->localXML = $this->getCapabilitiesDocByWMS($this->wmsId);
+
+ // service unreachable
+ if (!$this->remoteXML) {
+ $this->result = -1;
+ $this->comment = "Connection failed.";
+ }
+ /*
+ * service available;
+ * no local copy of capabilities file,
+ * so it has to be updated anyway
+ */
+ elseif (!$this->localXML) {
+ $this->result = 0;
+ }
+ /*
+ * service available;
+ * check if local copy is different
+ * to remote capabilties document
+ */
+ else {
+ /*
+ * compare to local capabilities document
+ */
+ // capabilities files match
+ if ($this->localXML == $this->remoteXML) {
+ $this->result = 1;
+ $this->comment = "WMS is stable.";
+ }
+ // capabilities files don't match
+ else {
+ $this->result = 0;
+ }
+ }
+ /*
+ * if the WMS is available,
+ * 1) get a map image
+ * 2) update the local backup of the capabilities doc if necessary
+ */
+ if ($this->result != -1) {
+
+ $this->mapURL = $this->getMapRequest($this->wmsId);
+
+ if ($this->isImage($this->mapURL)) {
+ $this->returnsImage = 1;
+ }
+ else {
+ $this->returnsImage = -1;
+ }
+
+ /*
+ * if the local backup of the capabilities document
+ * is deprecated, update the local backup
+ */
+ if ($this->result == 0) {
+ $mywms = new wms();
+
+ /*
+ * if the capabilities document is valid,
+ * update it OR mark it as "not up to date"
+ */
+ if ($mywms->createObjFromXML($this->capabilitiesURL)) {
+ if ($this->autoUpdate) {
+ $mywms->updateObjInDB($this->wmsId);
+ $this->updated = "1";
+ $this->comment = "WMS has been updated.";
+ }
+ else {
+ $this->comment = "WMS is not up to date.";
+ }
+ }
+ // capabilities document is invalid
+ else {
+ $this->result = -1;
+ $this->comment = "Invalid getCapabilities request/document or service exception.";
+ }
+ }
+ }
+ }
+ else {
+ $this->result = -1;
+ $this->comment = "Invalid upload URL.";
+ }
+ $e = new mb_notice("class_monitor: constructor: result = " . $this->result);
+ $e = new mb_notice("class_monitor: constructor: comment = " . $this->comment);
+ $e = new mb_notice("class_monitor: constructor: returnsImage = " . $this->returnsImage);
+ }
+
+ /**
+ *
+ */
+ public function __toString() {
+ $str = "";
+ $str .= "wmsid: " . $this->wmsId . "\nupload_id: " . $this->uploadId . "\n";
+ $str .= "autoupdate: " . $this->autoUpdate . "\n";
+ $str .= "result: " . $this->result . "\ncomment: " . $this->comment . "\n";
+ $str .= "timestamp: " . $this->timestamp . " (".date("F j, Y, G:i:s", $this->timestamp).")\n";
+ $str .= "getCapabilities URL: " . $this->capabilitiesURL . "\nupdated: " . $this->updated . "\n\n";
+ $str .= "getMap URL: " . $this->mapURL . "\nis image: " . $this->returnsImage . "\n\n";
+ $str .= "-------------------------------------------------------------------\n";
+ $str .= "remote XML:\n\n" . $this->remoteXML . "\n\n";
+ $str .= "-------------------------------------------------------------------\n";
+ $str .= "local XML:\n\n" . $this->localXML . "\n\n";
+ $str .= "-------------------------------------------------------------------\n";
+ return (string) $str;
+ }
+
+ /**
+ * Update database
+ */
+ function updateInDB() {
+ $sql = "UPDATE mb_monitor SET updated = $1, status = $2, image = $3, status_comment = $4, upload_url = $5, timestamp_end = $6, map_url = $7 WHERE upload_id = $8 AND fkey_wms_id = $9";
+ $v = array($this->updated, $this->result, $this->returnsImage, $this->comment, $this->capabilitiesURL, $this->timestamp, $this->mapURL, $this->uploadId, $this->wmsId);
+ $t = array('s', 'i', 'i', 's', 's', 's', 's', 's', 'i');
+ $res = db_prep_query($sql,$v,$t);
+ }
+
+ /*
+ * Checks if the mapUrl returns an image or an exception
+ */
+ private function isImage($url) {
+ $headers = get_headers($url, 1);
+ $e = new mb_notice("class_monitor: isImage: map URL is " . $url);
+ $e = new mb_notice("class_monitor: isImage: Content-Type is " . $headers["Content-Type"]);
+ if (preg_match("/xml/", $headers["Content-Type"])) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Returns the upload url of some WMS
+ */
+ private function getUploadURL($wmsId, $upload_id) {
+ $e = new mb_notice("class_monitor: getUploadURL: wms = " . $wmsId);
+ $e = new mb_notice("class_monitor: getUploadURL: upload_id = " . $upload_id);
+ $sql = "SELECT upload_url FROM mb_monitor WHERE fkey_wms_id = $1 AND upload_id = $2";
+ $v = array($wmsId, $upload_id);
+ $t = array('i', 'i');
+ $res = db_prep_query($sql,$v,$t);
+ $someArray = db_fetch_array($res);
+ $e = new mb_notice("class_monitor: getUploadURL: url = " . $someArray["upload_url"]);
+ return $someArray["upload_url"];
+ }
+
+ /**
+ * Returns the character that needs to be appended to
+ * a given online resource, in order to append other GET
+ * parameters.
+ *
+ * Possible characters: "?", "&", ""
+ */
+ private function mb_getConjunctionCharacter($onlineresource){
+ // index of character ? in online resource
+ $indexOfChar = mb_strpos($onlineresource,"?");
+
+ if($indexOfChar) {
+ // no conjunction character needed
+ if($indexOfChar == mb_strlen($onlineresource)-1){
+ return "";
+ }
+ // no conjunction character needed
+ else if (mb_substr($onlineresource, mb_strlen($onlineresource)-1) == "&") {
+ return "";
+ }
+ else{
+ return "&";
+ }
+ }
+ return "?";
+ }
+
+ /**
+ * retrieves all information necessary to build a map request,
+ * concatenates them and returns a valid get map request
+ */
+ private function getMapRequest($wmsId) {
+
+ // get map (wms_getmap)
+ // version (wms_version)
+ $sql = "SELECT wms_getmap, wms_version FROM wms WHERE wms_id = $1";
+ $res = db_prep_query($sql, array($wmsId), array('i'));
+ $row = db_fetch_array($res);
+ $getmap = $row["wms_getmap"];
+ $version = $row["wms_version"];
+
+ //map format
+ $sql = "SELECT * FROM wms_format WHERE data_type = 'map' AND fkey_wms_id = $1";
+ $res = db_prep_query($sql, array($wmsId), array('i'));
+ $row = db_fetch_array($res);
+ $mapFormat = "";
+ while ($row = db_fetch_array($res)) {
+ $mapFormat = urlencode($row["data_format"]);
+ if (preg_match("/png/", $mapFormat) || preg_match("/gif/", $mapFormat) || preg_match("/jp.{1}g/", $mapFormat)) {
+ break;
+ }
+ }
+
+ // layers (all layers)
+ $sql = "SELECT layer_name FROM layer WHERE fkey_wms_id = $1 AND layer_parent <> '' AND layer_pos > 0";
+ $res = db_prep_query($sql, array($wmsId), array('i'));
+ $layerArray = array();
+ while ($row = db_fetch_array($res)) {
+ array_push($layerArray, urlencode($row["layer_name"]));
+ }
+ $layerList = implode(",", $layerArray);
+
+ // srs (layer_epsg: epsg)
+ // bbox (layer_epsg: minx, miny, maxx, maxy)
+ $sql = "SELECT epsg, minx, miny, maxx, maxy ";
+ $sql .= "FROM layer_epsg, (SELECT fkey_wms_id, layer_id FROM layer WHERE fkey_wms_id = $1 AND layer_parent = '' AND layer_pos = 0) AS l ";
+ $sql .= "WHERE l.layer_id = layer_epsg.fkey_layer_id AND l.fkey_wms_id = $1";
+ $res = db_prep_query($sql, array($wmsId), array('i'));
+ $bboxArray = array();
+ while ($row = db_fetch_array($res)) {
+ array_push($bboxArray, new Mapbender_bbox($row["minx"], $row["miny"], $row["maxx"], $row["maxy"], $row["epsg"]));
+ }
+
+ // get a bbox in a preferably non WGS84 epsg to use the scalehints
+ for ($i=0; $i < count($bboxArray); $i++) {
+ $bbox = $bboxArray[$i];
+ if ($bboxArray[$i]->epsg != "EPSG:4326") {
+ break;
+ }
+ }
+
+ /*
+ * transform to 31466 if is 4326
+ * TODO: extend to other EPSG apart from 31466
+ */
+ if ($bbox->epsg == "EPSG:4326") {
+ $bbox->transform("EPSG:31466");
+ }
+
+ /*
+ * get map and check if result is image
+ */
+ // check if this WMS supports exception type XML
+ $sql = "SELECT data_format FROM wms_format WHERE fkey_wms_id = $1 AND data_type = 'exception'";
+ $v = array($wmsId);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ while ($row = db_fetch_array($res)) {
+ $exceptionFormat = $row["data_format"];
+ // set the exception type to xml (if possible)
+ if (preg_match('/xml/', $exceptionFormat)) {
+ $this->supportsXMLException = true;
+ break;
+ }
+ }
+
+ // correct bbox according to scale
+ $scale = $this->getScaleForWMS($wmsId);
+ $bbox = $this->getBBoxInScale($bbox, $scale);
+
+ return $this->concatenateMapRequest($getmap, $version, $mapFormat, $layerList, $bbox, MONITOR_IMG_WIDTH, MONITOR_IMG_HEIGHT, $exceptionFormat);
+ }
+
+ /**
+ * updates a given BBox according to a given scale
+ *
+ * @param bbox
+ * @param scale
+ */
+ private function getBBoxInScale($bbox, $scale) {
+ $e = new mb_notice("class_monitor: getMapRequest: old bbox = " . $bbox);
+ $e = new mb_notice("class_monitor: getMapRequest: old bbox = " . $bbox->min->x . "," . $bbox->min->y . "," . $bbox->max->x . "," . $bbox->max->y);
+ $e = new mb_notice("class_monitor: getMapRequest: scale = " . $scale);
+ if ($scale) {
+ $center = $bbox->min->plus($bbox->max)->times(0.5);
+ $e = new mb_notice("class_monitor: getMapRequest: center = " . $center);
+
+ /*
+ * TODO: this formula should have documentation
+ */
+ $offset = MONITOR_IMG_WIDTH / (MB_RESOLUTION * 100 * 2) * $scale;
+ $offsetPoint = new Mapbender_point($offset, $offset, $bbox->epsg);
+ $min = $center->minus($offsetPoint);
+ $max = $center->plus($offsetPoint);
+ $bbox->min = $min;
+ $bbox->max = $max;
+ $e = new mb_notice("class_monitor: getMapRequest: new bbox = " . $bbox);
+ $e = new mb_notice("class_monitor: getMapRequest: new bbox = " . $bbox->min->x . "," . $bbox->min->y . "," . $bbox->max->x . "," . $bbox->max->y);
+ }
+ return $bbox;
+ }
+
+
+ /**
+ * Returns an online resource representing a get map request
+ */
+ private function concatenateMapRequest( $getmap, $wmsVersion, $mapFormat, $layerList,
+ $bbox, $width, $height, $exceptionFormat) {
+ /*
+ * getMap URL
+ */
+ $mapRequest = $getmap;
+ $mapRequest .= $this->mb_getConjunctionCharacter($getmap);
+
+ /*
+ * WMS version
+ */
+ if ($wmsVersion == "1.0.0") {
+ $mapRequest .= "WMTVER=" . $wmsVersion . "&REQUEST=map&";
+ }
+ else {
+ $mapRequest .= "VERSION=" . $wmsVersion . "&REQUEST=GetMap&SERVICE=WMS&";
+ }
+
+ /*
+ * Layer list
+ */
+ $mapRequest .= "LAYERS=" . $layerList . "&";
+
+ /*
+ * Format
+ */
+ $mapRequest .= "FORMAT=" . $mapFormat . "&";
+
+ /*
+ * SRS and BBox
+ */
+ $mapRequest .= "SRS=" . $bbox->epsg . "&";
+ $mapRequest .= "BBOX=" . $bbox->min->x . "," . $bbox->min->y . "," . $bbox->max->x . "," . $bbox->max->y . "&";
+
+ /*
+ * Width and height
+ */
+ $mapRequest .= "WIDTH=" . $width . "&";
+ $mapRequest .= "HEIGHT=" . $height . "&";
+
+ /*
+ * BGColor
+ */
+ $mapRequest .= "BGCOLOR=0xffffff&";
+
+ /*
+ * Transparency
+ */
+ if (preg_match("/png/", $mapFormat) || preg_match("/gif/", $mapFormat)) {
+ $mapRequest .= "TRANSPARENT=TRUE&";
+ }
+
+ /*
+ * Exception format
+ */
+ $mapRequest .= "EXCEPTIONS=" . $exceptionFormat . "&";
+
+// return urlencode($mapRequest);
+ return $mapRequest;
+ }
+
+ /**
+ * Checks if the given WMS has ScaleHints. If yes, a scale is selected and returned.
+ */
+ private function getScaleForWMS($wmsId) {
+ // get the scalehints
+ $sql = "SELECT layer_minscale, layer_maxscale FROM layer WHERE fkey_wms_id = $1 AND layer_pos = 0 AND layer_parent = '' AND layer_minscale <> layer_maxscale LIMIT 1";
+ $v = array($wmsId);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ $scaleHintArray = db_fetch_array($res);
+
+ /*
+ * determine the scalehint
+ */
+ // if a scalehint exists
+ if ($scaleHintArray) {
+ // if upper boundary
+ if ($scaleHintArray["layer_minscale"] < $scaleHintArray["layer_maxscale"]) {
+ // TODO: find a better algorithm with a less obscure scale
+ $scaleHint = round($scaleHintArray["layer_maxscale"] - $scaleHintArray["layer_minscale"]) / 2;
+ }
+ // if lower boundary
+ else {
+ if ($scaleHintArray["layer_minscale"] < MONITOR_DEFAULT_SCALE) {
+ $scaleHint = MONITOR_DEFAULT_SCALE;
+ }
+ else {
+ // TODO: find a better algorithm with a less obscure scale
+ $scaleHint = $scaleHintArray["layer_minscale"] + 1000;
+ }
+ }
+ }
+ // otherwise, use a default value
+ else {
+ $scaleHint = MONITOR_DEFAULT_SCALE;
+ }
+ return $scaleHint;
+ }
+
+ /**
+ * Returns the local backup of the given WMS' capabilities document
+ */
+ private function getCapabilitiesDocByWMS($wmsId) {
+ $sql = "SELECT wms_getcapabilities_doc FROM wms WHERE wms_id = $1";
+ $v = array($wmsId);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ $someArray = db_fetch_array($res);
+ return $someArray["wms_getcapabilities_doc"];
+ }
+
+}
+?>
\ No newline at end of file
Modified: branches/mapbender_sld/http/classes/class_stripRequest.php
===================================================================
--- branches/mapbender_sld/http/classes/class_stripRequest.php 2007-11-23 13:20:10 UTC (rev 1830)
+++ branches/mapbender_sld/http/classes/class_stripRequest.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -37,9 +37,10 @@
$patterns = explode("&", $a[1]);
for($i=0; $i<count($patterns); $i++){
$tmp = explode("=", $patterns[$i]);
- if(strtoupper($tmp[0]) == strtoupper($key)){
- $replacement = strtoupper($key) . "=" . $value;
- $this->url = str_replace($patterns[$i],$replacement, $this->url);
+ if(mb_strtoupper($tmp[0]) == mb_strtoupper($key)){
+ $replacement = mb_strtoupper($key) . "=" . $value;
+ $currentPattern = "/" . $patterns[$i] . "/";
+ $this->url = preg_replace($currentPattern, $replacement, $this->url);
$exists = true;
}
}
@@ -58,7 +59,7 @@
$patterns = explode("&", $a[1]);
for($i=0; $i<count($patterns); $i++){
$tmp = explode("=", $patterns[$i]);
- if(strtoupper($tmp[0]) == strtoupper($key)){
+ if(mb_strtoupper($tmp[0]) == mb_strtoupper($key)){
$exists = true;
return $tmp[1];
}
@@ -90,9 +91,10 @@
$patterns = explode("&", $a[1]);
for($i=0; $i<count($patterns); $i++){
$tmp = explode("=", $patterns[$i]);
- if(strtoupper($tmp[0]) == strtoupper($key)){
+ if(mb_strtoupper($tmp[0]) == mb_strtoupper($key)){
$replacement = "";
- $this->url = str_replace($patterns[$i],$replacement, $this->url);
+ $currentPattern = "/" . $patterns[$i] . "/";
+ $this->url = preg_replace($currentPattern, $replacement, $this->url);
}
}
$this->encodeGET();
@@ -104,7 +106,7 @@
$a[0].= "?";
for($i=0; $i<count($patterns); $i++){
$tmp = explode("=", $patterns[$i]);
- if(in_array(strtoupper($tmp[0]),$this->encodeParams)){
+ if(in_array(mb_strtoupper($tmp[0]),$this->encodeParams)){
$val = explode(",", $tmp[1]);
$a[0] .= $tmp[0]."=";
for($ii=0; $ii<count($val); $ii++){
@@ -127,7 +129,7 @@
}
function encodeLegGET(){
- $this->url = str_replace("&", "\&", $this->url);
+ $this->url = preg_replace("/&/", "\&", $this->url);
return $this->url;
}
}
Modified: branches/mapbender_sld/http/classes/class_weldLegend2PNG.php
===================================================================
--- branches/mapbender_sld/http/classes/class_weldLegend2PNG.php 2007-11-23 13:20:10 UTC (rev 1830)
+++ branches/mapbender_sld/http/classes/class_weldLegend2PNG.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -95,13 +95,13 @@
* @todo handle as reg-exp?
* @todo instanciate $im as false or null?
*/
- if(strtolower($f) == 'image/png' || strtolower($f) == 'png'){
+ if(mb_strtolower($f) == 'image/png' || mb_strtolower($f) == 'png'){
$im = @ImageCreateFromPNG($imgurl);
}
- if(strtolower($f) == 'image/jpeg' || strtolower($f) == 'jpeg'){
+ if(mb_strtolower($f) == 'image/jpeg' || mb_strtolower($f) == 'jpeg'){
$im = @ImageCreateFromJPEG($imgurl);
}
- if(strtolower($f) == 'image/gif' || strtolower($f) == 'gif'){
+ if(mb_strtolower($f) == 'image/gif' || mb_strtolower($f) == 'gif'){
$im = @ImageCreateFromGIF($imgurl);
}
if(!$im){
Modified: branches/mapbender_sld/http/classes/class_weldOverview2PNG.php
===================================================================
--- branches/mapbender_sld/http/classes/class_weldOverview2PNG.php 2007-11-23 13:20:10 UTC (rev 1830)
+++ branches/mapbender_sld/http/classes/class_weldOverview2PNG.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -107,8 +107,6 @@
function loadpng ($imgurl) {
- #ereg_replace(' ', "\%90", $imgurl);
-
$obj = new stripRequest($imgurl);
$x = new connector($imgurl);
Modified: branches/mapbender_sld/http/classes/class_wfs.php
===================================================================
--- branches/mapbender_sld/http/classes/class_wfs.php 2007-11-23 13:20:10 UTC (rev 1830)
+++ branches/mapbender_sld/http/classes/class_wfs.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -22,7 +22,10 @@
*/
include_once(dirname(__FILE__)."/../../conf/mapbender.conf");
-require_once(dirname(__FILE__)."/class_connector.php");
+require_once(dirname(__FILE__)."/class_connector.php");
+require_once(dirname(__FILE__)."/class_mb_exception.php");
+require_once(dirname(__FILE__)."/class_administration.php");
+
class wfs {
var $wfs_id;
@@ -31,17 +34,21 @@
var $wfs_title;
var $wfs_abstract;
var $wfs_getcapabilities;
+ var $wfs_getcapabilities_doc; //new SB 2007-08-09
var $wfs_describefeaturetype;
var $wfs_describefeaturetype_namespace = array();
var $wfs_getfeature;
- //neu
var $wfs_transaction;
+ var $wfs_upload_url; //new SB 2007-08-09
+ //new WFS 1.0.0 -- SB 2007-08-06
+ var $fees;
+ var $accessconstraints;
+
var $wfs_featuretype = array();
-
function wfs() {
}
@@ -55,19 +62,28 @@
die;
}
- # for temporary wms a id has to be created...
+ $values = null;
+ $tags = null;
+ $admin = new administration();
+ $this->wfs_getcapabilities_doc = $admin->char_encode($data);
+ $this->wfs_upload_url = $url;
+
+ # for temporary wfs a id has to be created...
$this->wfs_id = "id_" . substr(md5(rand()),0,6);
$parser = xml_parser_create(CHARSET);
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
- xml_parse_into_struct($parser,$data,$values,$tags);
+ xml_parse_into_struct($parser,$this->wfs_getcapabilities_doc,$values,$tags);
+ //xml_parse_into_struct($parser,$data,$values,$tags);
+
xml_parser_free($parser);
$section = false;
$request = false;
$featuretype_name = false;
$featuretype_title = false;
+ $featuretype_abstract = false;
$featuretype_srs = false;
foreach ($values as $element) {
@@ -79,13 +95,19 @@
$this->wfs_name = $element[value];
}
if(strtoupper($element[tag]) == "TITLE" && $element[level] == '3'){
- $this->wfs_title = $element[value];
+ $this->wfs_title = $this->stripEndlineAndCarriageReturn($element[value]);
}
if(strtoupper($element[tag]) == "ABSTRACT" && $element[level] == '3'){
- $this->wfs_abstract = $element[value];
+ $this->wfs_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
}
+ //new WFS 1.0.0 -- SB 2007-08-06
+ if(strtolower($element[tag]) == "fees"){
+ $this->fees = $element[value];
+ }
+ if(strtolower($element[tag]) == "accessconstraints"){
+ $this->accessconstraints = $element[value];
+ }
-
/*capability section*/
if($this->wfs_version == "1.0.0"){
@@ -137,11 +159,14 @@
$featuretype_name = $element[value];
}
if($section == "featuretype" && strtoupper($element[tag]) == "TITLE"){
- $featuretype_title = $element[value];
+ $featuretype_title = $this->stripEndlineAndCarriageReturn($element[value]);
}
+ if($section == "featuretype" && strtoupper($element[tag]) == "ABSTRACT"){
+ $featuretype_abstract = $this->$element[value];
+ }
if($section == "featuretype" && strtoupper($element[tag]) == "SRS"){
$featuretype_srs = $element[value];
- $this->addFeaturetype($featuretype_name,$featuretype_title,$featuretype_srs,$this->wfs_describefeaturetype,$this->wfs_version);
+ $this->addFeaturetype($featuretype_name,$featuretype_title,$featuretype_abstract,$featuretype_srs,$this->wfs_describefeaturetype,$this->wfs_version);
}
}
}
@@ -159,6 +184,7 @@
echo "<hr>";
echo "name: ". $this->wfs_featuretype[$i]->featuretype_name . "<br>";
echo "title: ". $this->wfs_featuretype[$i]->featuretype_title . "<br>";
+ echo "abstract: ". $this->wfs_featuretype[$i]->featuretype_abstract . "<br>";
echo "srs: ". $this->wfs_featuretype[$i]->featuretype_srs . "<br>";
for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
echo " element: " . $this->wfs_featuretype[$i]->featuretype_element[$j]["name"] ." - ".$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]."<br>";
@@ -168,9 +194,12 @@
}
}
}
-function addFeaturetype($name,$title,$srs,$url,$version){
- $this->wfs_featuretype[count($this->wfs_featuretype)] = new featuretype($name,$title,$srs,$url,$version);
-}
+function addFeaturetype($name,$title,$abstract,$srs,$url,$version){
+ $this->wfs_featuretype[count($this->wfs_featuretype)] = new featuretype($name,$title,$abstract,$srs,$url,$version);
+}
+ function stripEndlineAndCarriageReturn($string) {
+ return preg_replace("/\n/", "", preg_replace("/\r/", " ", $string));
+ }
function createJsObjFromWFS($parent){
if(!$this->wfs_title || $this->wfs_title == ""){
echo "alert('Error: no valid capabilities-document !!');";
@@ -194,7 +223,8 @@
}
print ("wfs_add_featuretype('".
$this->wfs_featuretype[$i]->featuretype_name ."','".
- $this->wfs_featuretype[$i]->featuretype_title . "','".
+ $this->wfs_featuretype[$i]->featuretype_title . "','".
+ $this->wfs_featuretype[$i]->featuretype_abstract . "','".
$this->wfs_featuretype[$i]->featuretype_srs ."','".
$this->wfs_featuretype[$i]->featuretype_geomtype ."');");
for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
@@ -210,169 +240,485 @@
print("wfs_add_featuretype_namespace('".$this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"]."', '".$this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]."', ".$j.", ".$i.");");
}
}
- }
+}
+
/**
+ * Inserts this WFS in the database
+ */
+function insertWfs() {
+ global $DBSERVER,$DB,$OWNER,$PW;
+ $con = db_connect($DBSERVER,$OWNER,$PW);
+ db_select_db($DB,$con);
+
+ $sql = "INSERT INTO wfs (wfs_version, wfs_name, wfs_title, wfs_abstract, ";
+ $sql .= "wfs_getcapabilities, wfs_getcapabilities_doc, wfs_upload_url, ";
+ $sql .= "wfs_describefeaturetype, wfs_getfeature, wfs_transaction, fees, ";
+ $sql .= "accessconstraints, wfs_owner, wfs_timestamp) ";
+ $sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)";
+
+ $v = array($this->wfs_version, $this->wfs_name, $this->wfs_title,
+ $this->wfs_abstract, $this->wfs_getcapabilities, $this->wfs_getcapabilities_doc,
+ $this->wfs_upload_url, $this->wfs_describefeaturetype, $this->wfs_getfeature,
+ $this->wfs_transaction, $this->fees, $this->accessconstraints,
+ $_SESSION["mb_user_id"], strtotime("now"));
+
+ $t = array('s', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 'i', 'i');
+
+ $res = db_prep_query($sql,$v,$t);
+
+ if(!$res){
+ db_rollback();
+ $e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+ return false;
+ }
+ $this->wfs_id = db_insert_id($con,'wfs','wfs_id');
+ return true;
+}
+
+function updateWfs() {
+ global $DBSERVER,$DB,$OWNER,$PW;
+ $con = db_connect($DBSERVER,$OWNER,$PW);
+ db_select_db($DB,$con);
+
+ $sql = "UPDATE wfs SET wfs_version = $1, wfs_name = $2, wfs_title = $3, ";
+ $sql .= "wfs_abstract = $4, wfs_getcapabilities = $5, wfs_getcapabilities_doc = $6, ";
+ $sql .= "wfs_upload_url = $7, wfs_describefeaturetype = $8, wfs_getfeature = $9, ";
+ $sql .= "wfs_transaction = $10, fees = $11, accessconstraints = $12, wfs_owner = $13, ";
+ $sql .= "wfs_timestamp = $14 ";
+ $sql .= "WHERE wfs_id = $15";
+ //echo $sql."<br />";
+ $v = array($this->wfs_version, $this->wfs_name, $this->wfs_title, $this->wfs_abstract,
+ $this->wfs_getcapabilities, $this->wfs_getcapabilities_doc, $this->wfs_upload_url,
+ $this->wfs_describefeaturetype, $this->wfs_getfeature, $this->wfs_transaction,
+ $this->fees, $this->accessconstraints, $_SESSION["mb_user_id"],strtotime("now"),
+ $this->wfs_id);
+
+ $t = array('s', 's', 's', 's', 's', 's', 's', 's' ,'s' ,'s' ,'s' ,'s' ,'i' ,'i' ,'i');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ $e = new mb_exception("Error while saving WFS to DB. Rollback performed.");
+ return false;
+ }
+ return true;
+}
+/**
* wfs2db
*
-* this function exports the information from the xml to the mapbender database
+* this function saves the class information to the mapbender database
+* @return boolean true if sucessful false otherwise
*/
function wfs2db($gui_id){
global $DBSERVER,$DB,$OWNER,$PW;
$con = db_connect($DBSERVER,$OWNER,$PW);
db_select_db($DB,$con);
-
- # TABLE wfs
- $sql = "INSERT INTO wfs (wfs_version, wfs_name, wfs_title, wfs_abstract, wfs_getcapabilities, wfs_describefeaturetype, wfs_getfeature, wfs_transaction) ";
- $sql .= "VALUES(";
- $sql .= "'" . $this->wfs_version ."', ";
- $sql .= "'" . db_escape_string(str_replace("'","",$this->wfs_name)) ."', ";
- $sql .= "'" . db_escape_string(str_replace("'","",$this->wfs_title)) ."', ";
- $sql .= "'" . db_escape_string(str_replace("'","",$this->wfs_abstract)) . "', ";
- $sql .= "'" . $this->wfs_getcapabilities ."', ";
- $sql .= "'" . $this->wfs_describefeaturetype . "', ";
- $sql .= "'". $this->wfs_getfeature . "', ";
- $sql .= "'". $this->wfs_transaction . "'";
- $sql .= ");";
- #echo "sql wfs: <br>".$sql;
+ db_begin();
- $res = db_query($sql)or die(db_error());
+ // check if WFS already might exists (it might exist when wfs_id is numeric)
+ $wfs_exists = is_numeric($this->wfs_id);
+
+ // if it might exist, update it
+ if ($wfs_exists) {
+ // but check first if it really exists in the database
+ $sql = "SELECT * FROM wfs WHERE wfs_id = ".$this->wfs_id.";";
+ $res = db_query($sql);
+ if($res){
+ $this->updateWfs();
+ }
+ // if not, insert as new WFS
+ else {
+ $this->insertWfs();
+ }
+ }
+ // if it does not exist, insert as new WFS
+ else {
+ $this->insertWfs();
+ }
+
+ # delete featuretypes from DB that does not exist and find the ids
+ $sql = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = ".$this->wfs_id.";";
+ $res_ft = db_query($sql);
+ $cnt = 0;
+ while(db_fetch_row($res_ft)){
+ $found = false;
+ for($i=0; $i<count($this->wfs_featuretype); $i++){
+ if($this->wfs_featuretype[$i]->featuretype_name == db_result($res_ft, $cnt, "featuretype_name")){
+ $this->wfs_featuretype[$i]->featuretype_id = db_result($res_ft, $cnt, "featuretype_id");
+ $found = true;
+ break;
+ }
+ }
+
+ if(!$found){
+ $sql = "DELETE FROM wfs_featuretype WHERE featuretype_id = $1 AND fkey_wfs_id = $2";
+ $v = array(db_result($res_ft, $cnt, "featuretype_id"), $this->wfs_id);
+ $t = array('i','i');
+ //echo $sql."<br />";
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+ }
+ $cnt++;
+ }
- $myWFS = db_insert_id($con,'wfs','wfs_id');
- #echo "<br> myWFS: ".$myWFS;
# TABLE wfs_featuretype
for($i=0; $i<count($this->wfs_featuretype); $i++){
- $sql = "INSERT INTO wfs_featuretype(fkey_wfs_id, featuretype_name, featuretype_title, featuretype_srs) ";
- $sql .= "VALUES(";
- $sql .= $myWFS . ",";
- $sql .= "'".$this->wfs_featuretype[$i]->featuretype_name . "',";
- $sql .= "'".$this->wfs_featuretype[$i]->featuretype_title."',";
- $sql .= "'".$this->wfs_featuretype[$i]->featuretype_srs."'";
- $sql .= ")";
+ if(!$this->wfs_featuretype[$i]->featuretype_id){
+ $sql = "INSERT INTO wfs_featuretype(fkey_wfs_id, featuretype_name, featuretype_title, featuretype_abstract, featuretype_srs) ";
+ $sql .= "VALUES($1,$2,$3,$4,$5)";
+ $v = array($this->wfs_id,$this->wfs_featuretype[$i]->featuretype_name,$this->wfs_featuretype[$i]->featuretype_title,$this->wfs_featuretype[$i]->featuretype_abstract,$this->wfs_featuretype[$i]->featuretype_srs);
+ $t = array('i','s','s','s','s');
+ //echo $sql."<br />";
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+
+ # save the id of each featuretype:
+ $this->wfs_featuretype[$i]->featuretype_id = db_insert_id($con,'wfs_featuretype','featuretype_id');
+ }
+ else{
+ $sql = "UPDATE wfs_featuretype SET ";
+ $sql .= "featuretype_title = $1,";
+ $sql .= "featuretype_abstract = $2,";
+ $sql .= "featuretype_srs = $3 ";
+ $sql .= "WHERE featuretype_id = $4";
+ $v = array($this->wfs_featuretype[$i]->featuretype_title,$this->wfs_featuretype[$i]->featuretype_abstract,$this->wfs_featuretype[$i]->featuretype_srs,$this->wfs_featuretype[$i]->featuretype_id);
+ $t = array('s','s','s','i');
+ //echo $sql."<br />";
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+ }
- #$res = mysql_query($sql) or $this->cleanDB($myWFS,$sql);
-
- $res = db_query($sql) or $this->cleanDB($myWFS,$sql);
+ //delete featuretype elements from db and find the ids
+ $sql = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = ".$this->wfs_featuretype[$i]->featuretype_id.";";
+ //echo $sql."<br />";
+ $res_el = db_query($sql);
+ $cnt = 0;
+ while(db_fetch_row($res_el)){
+ $found = false;
+ for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element); $j++){
+ if($this->wfs_featuretype[$i]->featuretype_element[$j]["name"] == db_result($res_el, $cnt, "element_name")){
+ $this->wfs_featuretype[$i]->featuretype_element[$j]["id"] = db_result($res_el, $cnt, "element_id");
+ $found = true;
+ break;
+ }
+ }
+
+ if(!$found){
+ $sql = "DELETE FROM wfs_element WHERE element_id = $1 AND fkey_featuretype_id = $2";
+ $v = array(mysql_result($res_el, $cnt, "element_id"), $this->wfs_featuretype[$i]->featuretype_id);
+ $t = array('i','i');
+ //echo $sql."<br />";
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+ }
+ $cnt++;
+ }
-
- # save the id of each featuretype:
- $this->wfs_featuretype[$i]->mysql_id = db_insert_id($con,'wfs_featuretype','featuretype_id');
-
+
for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_element);$j++){
- $sql = "INSERT INTO wfs_element(fkey_featuretype_id, element_name,element_type) ";
- $sql .= "VALUES(";
- $sql .= "'" .$this->wfs_featuretype[$i]->mysql_id. "', ";
- $sql .= "'" .$this->wfs_featuretype[$i]->featuretype_element[$j]["name"]. "', ";
- $sql .= "'" .$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]. "' ";
- $sql .= ")";
-
- $res = db_query($sql) or $this->cleanDB($myWFS,$sql);
+ if(!$this->wfs_featuretype[$i]->featuretype_element[$j]["id"]){
+ $sql = "INSERT INTO wfs_element(fkey_featuretype_id, element_name,element_type) ";
+ $sql .= "VALUES(";
+ $sql .= "'" .$this->wfs_featuretype[$i]->featuretype_id. "', ";
+ $sql .= "'" .$this->wfs_featuretype[$i]->featuretype_element[$j]["name"]. "', ";
+ $sql .= "'" .$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]. "' ";
+ $sql .= ");";
+ //echo $sql."<br />";
+ $res = db_query($sql);
+ if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+ }
+ else{
+ $sql = "UPDATE wfs_element SET element_type = '".$this->wfs_featuretype[$i]->featuretype_element[$j]["type"]."' ";
+ $sql .= "WHERE element_id = ".$this->wfs_featuretype[$i]->featuretype_element[$j]["id"]." AND ";
+ $sql .= "fkey_featuretype_id = ".$this->wfs_featuretype[$i]->featuretype_id.";";
+ //echo $sql."<br />";
+ $res = db_query($sql);
+ if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+ }
}
+ $sql = "DELETE FROM wfs_featuretype_namespace WHERE ";
+ $sql .= "fkey_wfs_id = ".$this->wfs_id." AND ";
+ $sql .= "fkey_featuretype_id = ".$this->wfs_featuretype[$i]->featuretype_id.";";
+ //echo $sql."<br />";
+ $res = db_query($sql);
+ if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+
for($j=0; $j<count($this->wfs_featuretype[$i]->featuretype_namespace);$j++){
$sql = "INSERT INTO wfs_featuretype_namespace(fkey_wfs_id, fkey_featuretype_id, namespace, namespace_location) ";
$sql .= "VALUES(";
- $sql .= "'" .$myWFS. "',";
- $sql .= "'" .$this->wfs_featuretype[$i]->mysql_id. "', ";
+ $sql .= "'" .$this->wfs_id. "',";
+ $sql .= "'" .$this->wfs_featuretype[$i]->featuretype_id. "', ";
$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_namespace[$j]["name"]. "', ";
$sql .= "'" .$this->wfs_featuretype[$i]->featuretype_namespace[$j]["value"]. "' ";
- $sql .= ")";
-
- $res = db_query($sql) or $this->cleanDB($myWFS,$sql);
+ $sql .= ");";
+ //echo $sql."<br />";
+ $res = db_query($sql);
+ if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
}
}
# TABLE gui_wfs
- $sql ="INSERT INTO gui_wfs (fkey_gui_id, fkey_wfs_id)";
- $sql .= "VALUES(";
- $sql .= "'" . $gui_id . "', ";
- $sql .= $myWFS;
- $sql .= ");";
+ if($gui_id){
+ $sql ="INSERT INTO gui_wfs (fkey_gui_id, fkey_wfs_id)";
+ $sql .= "VALUES(";
+ $sql .= "'" . $gui_id . "', ";
+ $sql .= $this->wfs_id;
+ $sql .= ");";
+ //echo $sql."<br />";
+ $res = db_query($sql);
+ if(!$res){db_rollback();$e = new mb_exception("Error while saving WFS to DB. Rollback performed.");return;}
+ }
- $res = db_query($sql) or $this->cleanDB($myWFS,$sql);
+ //echo "Successfully saved!<br />";
+ db_commit();
+
+ return true;
}
-function cleanDB($wfsid,$sql){
- global $DBSERVER,$DB,$OWNER,$PW;
- $con = db_connect($DBSERVER,$OWNER,$PW);
- db_select_db($DB,$con);
- $s = "DELETE FROM wfs WHERE wfs_id = ".$wfsid;
- $res = db_query($s);
- echo "<br>Error in :".$sql."<br>";
- echo "<br>Db cleaned.<br>";
- die;
+/**
+* updateObjFromXML
+*
+* this function regets the information from the xml (update)
+* @return boolean true if successful, false otherwise
+*/
+function updateObjFromXML($url){
+ $x = new connector($url);
+ $data = $x->file;
+ #$data = implode("",file($url));
+ if(!$data){
+ $e = new mb_exception("Unable to open document: ".$url);
+ return false;
+ }
+
+ $values = null;
+ $tags = null;
+ $admin = new administration();
+ $this->wfs_getcapabilities_doc = $admin->char_encode($data);
+ $this->wfs_featuretype = array();
+ $this->wfs_upload_url = $url;
+
+ # for temporary wfs a id has to be created...
+ //$this->wfs_id = "id_" . substr(md5(rand()),0,6);
+ $parser = xml_parser_create(CHARSET);
+ xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
+ xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
+ xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
+ xml_parse_into_struct($parser,$this->wfs_getcapabilities_doc,$values,$tags);
+ //xml_parse_into_struct($parser,$data,$values,$tags);
+
+ xml_parser_free($parser);
+
+ $section = false;
+ $request = false;
+ $featuretype_name = false;
+ $featuretype_title = false;
+ $featuretype_abstract = false;
+ $featuretype_srs = false;
+
+ foreach ($values as $element) {
+
+ if(strtoupper($element[tag]) == "WFS_CAPABILITIES" && $element[type] == "open"){
+ $this->wfs_version = $element[attributes][version];
+ }
+ if(strtoupper($element[tag]) == "NAME" && $element[level] == '3'){
+ $this->wfs_name = $element[value];
+ }
+/* if(strtoupper($element[tag]) == "TITLE" && $element[level] == '3'){
+ $this->wfs_title = $this->stripEndlineAndCarriageReturn($element[value]);
+ }
+ if(strtoupper($element[tag]) == "ABSTRACT" && $element[level] == '3'){
+ $this->wfs_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
+ }
+ //new WFS 1.0.0 -- SB 2007-08-06
+ if(strtolower($element[tag]) == "fees"){
+ $this->fees = $element[value];
+ }
+ if(strtolower($element[tag]) == "accessconstraints"){
+ $this->accessconstraints = $element[value];
+ }
+*/
+ /*capability section*/
+
+ if($this->wfs_version == "1.0.0"){
+
+ # getCapabilities
+ if(strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "open"){
+ $section = "getcapabilities";
+ }
+ if($section == "getcapabilities" && strtoupper($element[tag]) == "GET"){
+ $this->wfs_getcapabilities = $element[attributes][onlineResource];
+ }
+
+ # descriptFeatureType
+ if(strtoupper($element[tag]) == "DESCRIBEFEATURETYPE" && $element[type] == "open"){
+ $section = "describefeaturetype";
+ $this->wfs_describefeaturetype = $element[attributes][onlineResource];
+
+
+ }
+ if($section == "describefeaturetype" && strtoupper($element[tag]) == "GET"){
+ $this->wfs_describefeaturetype = $element[attributes][onlineResource];
+ }
+
+ # getFeature
+ if(strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "open"){
+ $section = "getfeature";
+ }
+ if($section == "getfeature" && strtoupper($element[tag]) == "GET"){
+ $this->wfs_getfeature = $element[attributes][onlineResource];
+ }
+ if(strtoupper($element[tag]) == "GETFEATURE" && $element[type] == "close"){
+ $section = "";
+ }
+ # transaction
+ if(strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "open"){
+ $section = "transaction";
+ }
+ if($section == "transaction" && strtoupper($element[tag]) == "GET"){
+ $this->wfs_transaction = $element[attributes][onlineResource];
+ }
+ if(strtoupper($element[tag]) == "TRANSACTION" && $element[type] == "close"){
+ $section = "";
+ }
+ }
+ if(strtoupper($element[tag]) == "FEATURETYPE" && $element[type] == "open"){
+ $section = "featuretype";
+ }
+ if($section == "featuretype" && strtoupper($element[tag]) == "NAME"){
+ $featuretype_name = $element[value];
+ }
+ if($section == "featuretype" && strtoupper($element[tag]) == "TITLE"){
+ $featuretype_title = $this->stripEndlineAndCarriageReturn($element[value]);
+ }
+ if($section == "featuretype" && strtoupper($element[tag]) == "ABSTRACT"){
+ $featuretype_abstract = $this->$element[value];
+ }
+ if($section == "featuretype" && strtoupper($element[tag]) == "SRS"){
+ $featuretype_srs = $element[value];
+ $this->addFeaturetype($featuretype_name,$featuretype_title,$featuretype_abstract,$featuretype_srs,$this->wfs_describefeaturetype,$this->wfs_version);
+ }
+ }
+ return true;
}
-
- /**
+/**
* creatObjfromDB
*
+* this function fills the object with wfs information from db
+*
+* @param int the id of wfs to get the information from
*/
-function createObjFromDB________($wfs_id){
- global $server,$db,$owner,$pw;
- $con = mysql_connect($server,$owner,$pw);
- mysql_select_db($db, $con);
+function createObjFromDB($wfs_id){
+ global $DBSERVER,$DB,$OWNER,$PW;
+ $con = db_connect($DBSERVER,$OWNER,$PW);
+ db_select_db($DB,$con);
$sql = "SELECT * FROM wfs WHERE wfs_id = ".$wfs_id.";";
- $res = mysql_query($sql);
+ $res = db_query($sql);
$cnt = 0;
- while(mysql_fetch_row($res)){
- $this->wfs_id = mysql_result($res, $cnt, "wfs_id");
- $this->wfs_version = mysql_result($res, $cnt, "wfs_version");
- $this->wfs_title = mysql_result($res, $cnt, "wfs_title");
- $this->wfs_abstract = mysql_result($res, $cnt, "wfs_abstract");
- $this->wfs_getcapabilities = mysql_result($res, $cnt, "wfs_getcapabilities");
- $this->wfs_describefeaturetype = mysql_result($res, $cnt, "wfs_describefeaturetype");
+ while(db_fetch_row($res)){
+ $this->wfs_id = db_result($res, $cnt, "wfs_id");
+ $this->wfs_version = db_result($res, $cnt, "wfs_version");
+ $this->wfs_name = db_result($res, $cnt, "wfs_name");
+ $this->wfs_title = db_result($res, $cnt, "wfs_title");
+ $this->wfs_abstract = db_result($res, $cnt, "wfs_abstract");
+ $this->wfs_getcapabilities = db_result($res, $cnt, "wfs_getcapabilities");
+ $this->wfs_getcapabilities_doc = db_result($res, $cnt, "wfs_getcapabilities_doc");
+ $this->wfs_upload_url = db_result($res, $cnt, "wfs_upload_url");
+ $this->wfs_describefeaturetype = db_result($res, $cnt, "wfs_describefeaturetype");
+ $this->wfs_getfeature = db_result($res, $cnt, "wfs_getfeature");
+ $this->wfs_transaction = db_result($res, $cnt, "wfs_transaction");
+ $this->fees = db_result($res, $cnt, "fees");
+ $this->accessconstraints = db_result($res, $cnt, "accessconstraints");
+ $this->wfs_owner = db_result($res, $cnt, "wfs_owner");
+ $this->wfs_timestamp = db_result($res, $cnt, "wfs_timestamp");
- $sql_fe = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = " . $this->wfs_id . " ORDER BY featuretype_id";
- $res_fe = mysql_query($sql_fe);
+ $sql_fe = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = '" . $this->wfs_id . "' ORDER BY featuretype_id";
+ $res_fe = db_query($sql_fe);
$cnt_fe = 0;
- while(mysql_fetch_row($res_fe)){
+ while(db_fetch_row($res_fe)){
$c = count($this->wfs_featuretype);
- $this->wfs_featuretype[$c]->featuretype_name = mysql_result($res_fe, $cnt_fe, "featuretype_name");
- $this->wfs_featuretype[$c]->featuretype_title = mysql_result($res_fe, $cnt_fe, "featuretype_title");
- $this->wfs_featuretype[$c]->featuretype_srs = mysql_result($res_fe, $cnt_fe, "featuretype_srs");
- $this->wfs_featuretype[$c]->featuretype_geomtype = mysql_result($res_fe, $cnt_fe, "featuretype_geomtype");
+// $this->wfs_featuretype[$c]->featuretype_id = db_result($res_fe, $cnt_fe, "featuretype_id");
+ $this->wfs_featuretype[$c]->featuretype_name = db_result($res_fe, $cnt_fe, "featuretype_name");
+ $this->wfs_featuretype[$c]->featuretype_title = db_result($res_fe, $cnt_fe, "featuretype_title");
+ $this->wfs_featuretype[$c]->featuretype_abstract = db_result($res_fe, $cnt_fe, "featuretype_abstract");
+ $this->wfs_featuretype[$c]->featuretype_srs = db_result($res_fe, $cnt_fe, "featuretype_srs");
- $sql_el = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = ". mysql_result($res_fe, $cnt_fe, "featuretype_id")." ORDER BY element_id";
- $res_el = mysql_query($sql_el);
+ $sql_el = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = ". db_result($res_fe, $cnt_fe, "featuretype_id")." ORDER BY element_id";
+ $res_el = db_query($sql_el);
$cnt_el = 0;
- while(mysql_fetch_row($res_el)){
+ while(db_fetch_row($res_el)){
$z = count($this->wfs_featuretype[$c]->featuretype_element);
- $this->wfs_featuretype[$c]->featuretype_element[$z]["name"] = mysql_result($res_el, $cnt_el, "element_name");
- $this->wfs_featuretype[$c]->featuretype_element[$z]["type"] = mysql_result($res_el, $cnt_el, "element_type");
+ $this->wfs_featuretype[$c]->featuretype_element[$z]["name"] = db_result($res_el, $cnt_el, "element_name");
+ $this->wfs_featuretype[$c]->featuretype_element[$z]["type"] = db_result($res_el, $cnt_el, "element_type");
$cnt_el++;
}
- $sql_el = "SELECT * FROM wfs_featuretype_namespace WHERE fkey_featuretype_id = ". mysql_result($res_fe, $cnt_fe, "featuretype_id")." ORDER BY namespace";
- $res_el = mysql_query($sql_el);
- $cnt_el = 0;
- while(mysql_fetch_row($res_el)){
+ $sql_ns = "SELECT * FROM wfs_featuretype_namespace WHERE fkey_featuretype_id = ". db_result($res_fe, $cnt_fe, "featuretype_id")." ORDER BY namespace";
+ $res_ns = db_query($sql_ns);
+ $cnt_ns = 0;
+ while(db_fetch_row($res_ns)){
$z = count($this->wfs_featuretype[$c]->featuretype_namespace);
- $this->wfs_featuretype[$c]->featuretype_namespace[$z]["name"] = mysql_result($res_el, $cnt_el, "namespace");
- $this->wfs_featuretype[$c]->featuretype_namespace[$z]["value"] = mysql_result($res_el, $cnt_el, "namespace_location");
- $cnt_el++;
+ $this->wfs_featuretype[$c]->featuretype_namespace[$z]["name"] = db_result($res_ns, $cnt_ns, "namespace");
+ $this->wfs_featuretype[$c]->featuretype_namespace[$z]["value"] = db_result($res_ns, $cnt_ns, "namespace_location");
+ $cnt_ns++;
}
$cnt_fe++;
}
$cnt++;
- }
- }
+ }
}
/** end createObjfromDB **/
+ public function getallwfs($userid){
+ $this->wfs_id = array();
+ $this->wfs_name = array();
+ $this->wfs_title = array();
+ $this->wfs_abstract = array();
+
+ global $DBSERVER,$DB,$OWNER,$PW;
+ $con = db_connect($DBSERVER,$OWNER,$PW);
+ db_select_db($DB,$con);
+ if($userid){
+ $sql = "SELECT * FROM wfs WHERE wfs_owner = $1";
+ $v = array($userid);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ }
+ else{
+ $sql = "SELECT * FROM wfs";
+ $res = db_query($sql);
+ }
+
+ $cnt = 0;
+ while ($row = db_fetch_array($res)){
+ $this->wfs_version[$cnt] = $row["wfs_version"];
+ $this->wfs_id[$cnt] = $row["wfs_id"];
+ $this->wfs_name[$cnt] = $row["wfs_name"];
+ $this->wfs_title[$cnt] = $row["wfs_title"];
+ $this->wfs_abstract[$cnt] = $row["wfs_abstract"];
+ $this->wfs_getcapabilities[$cnt] = $row["wfs_getcapabilities"];
+ $this->wfs_describefeaturetype[$cnt] = $row["wfs_describefeaturetype"];
+ $this->wfs_getfeature[$cnt] = $row["wfs_getfeature"];
+ $cnt++;
+ }
+ }
+}
+
class featuretype extends wfs{
var $featuretype_element = array();
var $featuretype_namespace = array();
- function featuretype($name,$title,$srs,$url,$version){
+ function featuretype($name,$title,$abstract,$srs,$url,$version){
$url .= "&SERVICE=WFS&VERSION=".$version."&REQUEST=DescribeFeatureType&TYPENAME=".$name;
$this->featuretype_name = $name;
$this->featuretype_title = $title;
+ $this->featuretype_abstract = $abstract;
$this->featuretype_srs = $srs;
$data = implode("",file($url));
@@ -385,7 +731,7 @@
foreach ($values as $element) {
if($this->sepNameSpace($element[tag]) == "schema" && $element[type] == "open"){
$section = "namespace";
- echo "namespace<br>";
+// echo "namespace<br>";
}
if($section == "namespace"){
@@ -401,7 +747,7 @@
if ($match == false) {
$this->featuretype_namespace[$cnt]["name"] = $this->sepNameSpace($k);
$this->featuretype_namespace[$cnt]["value"] = $val;
- echo "namespace: " . $this->sepNameSpace($k) . " -> " . $val . "<br>";
+// echo "namespace: " . $this->sepNameSpace($k) . " -> " . $val . "<br>";
}
}
}
@@ -411,20 +757,14 @@
}
if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "open"){
$section = "complexcontent";
- echo "complexcontent<br>";
+// echo "complexcontent<br>";
}
if($section == "complexcontent" && $this->sepNameSpace($element[tag]) == "element" && $element[attributes][name]){
$cnt = count($this->featuretype_element);
$this->featuretype_element[$cnt]["name"] = $element[attributes]["name"];
-
- if (array_key_exists("type", $element[attributes])) {
- $this->featuretype_element[$cnt]["type"] = $this->sepNameSpace($element[attributes]["type"]);
- }
- echo "element: ".$this->featuretype_element[$cnt]["name"]."<br>";
+ $this->featuretype_element[$cnt]["type"] = $this->sepNameSpace($element[attributes]["type"]);
+// echo "element: ".$this->featuretype_element[$cnt]["name"]."<br>";
}
- if($section == "complexcontent" && $this->sepNameSpace($element[tag]) == "restriction" && $element[attributes][base]){
- $this->featuretype_element[$cnt]["type"] = $this->sepNameSpace($element[attributes]["base"]);
- }
if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "close"){
$section = "";
}
Modified: branches/mapbender_sld/http/classes/class_wfs_conf.php
===================================================================
--- branches/mapbender_sld/http/classes/class_wfs_conf.php 2007-11-23 13:20:10 UTC (rev 1830)
+++ branches/mapbender_sld/http/classes/class_wfs_conf.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -17,6 +17,195 @@
# 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__)."/class_mb_exception.php");
+require_once(dirname(__FILE__)."/class_administration.php");
+require_once(dirname(__FILE__)."/../extensions/JSON.php");
+
+class WfsConf {
+ var $confArray = array();
+
+ /**
+ * Gets the configuration from the database
+ */
+ function __construct () {
+
+ }
+
+ public function load ($idOrIdArray) {
+ /*
+ * Check parameter and set idArray
+ */
+ if (isset($idOrIdArray)){
+
+ // parameter is a number
+ if (!is_array($idOrIdArray) && is_numeric($idOrIdArray)) {
+ $this->getWfsConfFromDB(array(intval($idOrIdArray)), $_SESSION["mb_user_id"]);
+ }
+ // parameter is an array of numbers
+ else if (is_array($idOrIdArray)) {
+ $idArray = array();
+ for ($i=0; $i < count($idOrIdArray); $i++) {
+ if (!is_numeric($idOrIdArray[$i])) {
+ $e = new mb_exception("Wfs_conf: constructor: wrong parameter: ".$idOrIdArray[$i]." is not a number.");
+ return null;
+ }
+ array_push($idArray, intval($idOrIdArray[$i]));
+ }
+ $this->getWfsConfFromDB($idArray, $_SESSION["mb_user_id"]);
+ }
+ // parameter is invalid
+ else {
+ $e = new mb_exception("Wfs_conf: constructor: parameter must be number or an array of numbers.");
+ return null;
+ }
+ }
+ else {
+ $e = new mb_exception("Wfs_conf: constructor: parameter is not valid");
+ }
+ }
+
+ /**
+ * get WFS conf data from database
+ */
+ private function getWfsConfFromDB ($idArray, $userId) {
+ /*
+ * If a user ID is given, remove the ones the user has no access to
+ */
+ if ($userId) {
+ $idArray = array_intersect($idArray, WfsConf::getWfsConfByPermission($userId));
+ }
+
+ if (count($idArray) > 0) {
+ /*
+ * Get WFS configurations
+ */
+ $sql = "SELECT * FROM wfs_conf ";
+ $sql .= "JOIN wfs ON wfs_conf.fkey_wfs_id = wfs.wfs_id ";
+ $sql .= "WHERE wfs_conf.wfs_conf_id IN (";
+
+ $v = array();
+ $t = array();
+ for ($i = 0; $i < count($idArray); $i++) {
+ if ($i > 0) {$sql .= ", ";}
+ $sql .= "$" . ($i+1);
+ array_push($v, $idArray[$i]);
+ array_push($t, 'i');
+ }
+ $sql .= ")";
+
+ $res = db_prep_query($sql, $v, $t);
+
+ while ($row = db_fetch_array($res)) {
+
+
+ /*
+ * Get WFS conf elements
+ */
+ $id = $row["wfs_conf_id"];
+
+ $sql_conf_element = "SELECT * FROM wfs_conf_element ";
+ $sql_conf_element .= "JOIN wfs_element ON wfs_conf_element.f_id = wfs_element.element_id ";
+ $sql_conf_element .= "WHERE wfs_conf_element.fkey_wfs_conf_id = $1 ";
+#filtered on client side
+# $sql_conf_element .= "AND wfs_conf_element.f_search = 1 ";
+ $sql_conf_element .= "ORDER BY wfs_conf_element.f_pos";
+ $v_conf_element = array($id);
+ $t_conf_element = array('i');
+ $res_conf_element = db_prep_query($sql_conf_element, $v_conf_element, $t_conf_element);
+
+ $elementArray = array();
+ while ($row_conf_element = db_fetch_array($res_conf_element)) {
+
+
+ $currentElement = array("f_search" => $row_conf_element["f_search"],
+ "f_style_id" => $row_conf_element["f_style_id"],
+ "f_toupper" => $row_conf_element["f_toupper"],
+ "f_label" => $row_conf_element["f_label"],
+ "f_label_id" => $row_conf_element["f_label_id"],
+ "f_geom" => $row_conf_element["f_geom"],
+ "element_name" => $row_conf_element["element_name"],
+ "element_type" => $row_conf_element["element_type"]
+ );
+ array_push($elementArray, $currentElement);
+ }
+
+ /*
+ * Get WFS featuretype
+ */
+ $sql_feature_type = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = $1 AND featuretype_id = $2";
+ $v_feature_type = array($row["fkey_wfs_id"], $row["fkey_featuretype_id"]);
+ $t_feature_type = array("i", "i");
+
+ $res_feature_type = db_prep_query($sql_feature_type, $v_feature_type, $t_feature_type);
+ if($row_feature_type = db_fetch_array($res_feature_type)){
+ $featuretype_name = $row_feature_type["featuretype_name"];
+ $featuretype_srs = $row_feature_type["featuretype_srs"];
+ }
+
+ $currentRow = array("g_label" => $row["g_label"],
+ "g_label_id" => $row["g_label_id"],
+ "g_style" => $row["g_style"],
+ "g_button" => $row["g_button"],
+ "g_button_id" => $row["g_button_id"],
+ "g_buffer" => $row["g_buffer"],
+ "g_res_style" => $row["g_res_style"],
+ "g_use_wzgraphics" => $row["g_use_wzgraphics"],
+ "wfs_id" => $row["fkey_wfs_id"],
+ "featuretype_id" => $row["fkey_featuretype_id"],
+ "featuretype_name" => $featuretype_name,
+ "featuretype_id" => $featuretype_srs,
+ "wfs_getfeature" => $row["wfs_getfeature"],
+ "element" => $elementArray
+ );
+
+ $this->confArray[$id] = $currentRow;
+ }
+ }
+ else {
+ $e = new mb_warning("class_wfs_conf.php: getWfsConfFromDB: You don't have access to any WFS confs. Check EDIT WFS.");
+ }
+ }
+
+ /** identifies the Conf-FeatureServices where the current user is owner
+ *
+ * @param integer userid the user-ID of the current user
+ * @return integer[] the IDs of the wfs_conf-table
+ */
+ public static function getWfsConfByPermission($userid){
+ $guisByPer = array();
+// 1.
+ $adm = new administration();
+ $guisByPer = $adm->getGuisByPermission($userid, true);
+// 2.
+ if(count($guisByPer)>0){
+ $v = array();
+ $t = array();
+ $sql = "SELECT wfs_conf.wfs_conf_id FROM gui_wfs_conf, wfs_conf " .
+ "where wfs_conf.wfs_conf_id = gui_wfs_conf.fkey_wfs_conf_id " .
+ "and gui_wfs_conf.fkey_gui_id IN(";
+ for($i=0; $i<count($guisByPer); $i++){
+ if($i>0){ $sql .= ",";}
+ $sql .= "$".strval($i+1);
+
+ array_push($v, $guisByPer[$i]);
+ array_push($t, "s");
+ }
+ $sql .= ") GROUP BY wfs_conf.wfs_conf_id ORDER BY wfs_conf.wfs_conf_id";
+
+ $res = db_prep_query($sql,$v,$t);
+ $ownWFSconfs = array();
+ $i=0;
+ while($row = db_fetch_array($res)){
+
+ $ownWFSconfs[$i] = $row['wfs_conf_id'];
+ $i++;
+ }
+ }
+ return $ownWFSconfs;
+ }
+}
+
+
class wfs_conf{
var $wfs_id;
@@ -31,30 +220,7 @@
var $elements;
var $namespaces;
- function getallwfs(){
- $this->wfs_id = array();
- $this->wfs_name = array();
- $this->wfs_title = array();
- $this->wfs_abstract = array();
-
- global $DBSERVER,$DB,$OWNER,$PW;
- $con = db_connect($DBSERVER,$OWNER,$PW);
- db_select_db($DB,$con);
- $sql = "SELECT * FROM wfs"; // include permission handling
- $res = db_query($sql);
- $cnt = 0;
- while ($row = db_fetch_array($res)){
- $this->wfs_version[$cnt] = $row["wfs_version"];
- $this->wfs_id[$cnt] = $row["wfs_id"];
- $this->wfs_name[$cnt] = $row["wfs_name"];
- $this->wfs_title[$cnt] = $row["wfs_title"];
- $this->wfs_abstract[$cnt] = $row["wfs_abstract"];
- $this->wfs_getcapabilities[$cnt] = $row["wfs_getcapabilities"];
- $this->wfs_describefeaturetype[$cnt] = $row["wfs_describefeaturetype"];
- $this->wfs_getfeature[$cnt] = $row["wfs_getfeature"];
- $cnt++;
- }
- }
+
function getfeatures($wfsid){
$this->features = new features($wfsid);
}
Modified: branches/mapbender_sld/http/classes/class_wmc.php
===================================================================
--- branches/mapbender_sld/http/classes/class_wmc.php 2007-11-23 13:20:10 UTC (rev 1830)
+++ branches/mapbender_sld/http/classes/class_wmc.php 2007-11-23 13:22:46 UTC (rev 1831)
@@ -1,5 +1,5 @@
<?php
-# $Id: class_wmc.php 645 2006-12-08 12:58:39Z christoph $
+# $Id: class_wmc.php 1233 2007-10-19 14:28:21Z baudson $
# http://www.mapbender.org/index.php/class_wmc.php
# Copyright (C) 2002 CCGIS
#
@@ -16,11 +16,16 @@
# 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("../../conf/mapbender.conf");
require_once("../classes/class_wms.php");
require_once("../classes/class_mb_exception.php");
+require_once("../classes/class_layer_monitor.php");
+require_once("../classes/class_bbox.php");
+require_once("../extensions/JSON.php");
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
+
function mb_utf8_encode ($str) {
if(CHARSET=="UTF-8") return utf8_encode($str);
return $str;
@@ -36,231 +41,756 @@
}
class wmc {
- var $wmc_id;
- var $wmc_version;
- var $wmc_windowWidth;
- var $wmc_windowHeight;
- var $wmc_bBox_SRS;
- var $wmc_bBox_minx;
- var $wmc_bBox_maxx;
- var $wmc_bBox_miny;
- var $wmc_bBox_maxy;
- var $wmc_name;
- var $wmc_title;
- var $wmc_abstract;
- var $wmc_logourl;
- var $wmc_logourl_format;
- var $wmc_logourl_type;
- var $wmc_logourl_width;
- var $wmc_logourl_height;
- var $wmc_descriptionurl;
- var $wmc_descriptionurl_format;
- var $wmc_descriptionurl_type;
- var $wmc_keyword = array();
- var $wmc_contactposition;
- var $wmc_contactvoicetelephone;
- var $wmc_contactemail;
- var $wmc_contactfacsimiletelephone;
- var $wmc_contactperson;
- var $wmc_contactorganization;
- var $wmc_contactaddresstype;
- var $wmc_contactaddress;
- var $wmc_contactcity;
- var $wmc_contactstateorprovince;
- var $wmc_contactpostcode;
- var $wmc_contactcountry;
-
- var $wmc_wms_title = array();
- var $wmc_layer_queryable = array();
- var $wmc_layer_querylayer = array();
- var $wmc_layer_hidden = array();
- var $wmc_wms_id = array();
- var $wmc_wms_service = array();
- var $wmc_wms_version = array();
- var $wmc_layer_id = array();
- var $wmc_layer_title = array();
- var $wmc_layer_name = array();
- var $wmc_layer_abstract = array();
- var $wmc_layer_srs = array();
- var $wmc_wms_serviceURL = array();
- var $wmc_layer_format_current = array();
- var $wmc_layer_dataurl = array();
- var $wmc_layer_metadataurl = array();
- var $wmc_layer_minscale = array();
- var $wmc_layer_maxscale = array();
- var $wmc_layer_format = array();
- var $wmc_layer_style_current = array();
- var $wmc_layer_style_name = array();
- var $wmc_layer_style_title = array();
- var $wmc_layer_style_legendurl = array();
- var $wmc_layer_style_legendurl_width = array();
- var $wmc_layer_style_legendurl_height = array();
- var $wmc_layer_style_legendurl_format = array();
- var $wmc_layer_style_legendurl_type = array();
- var $wmc_layer_style_sld_url = array();
- var $wmc_layer_style_sld_type = array();
- var $wmc_layer_style_sld_title = array();
- var $wmc_wms_count = 0;
+ var $xml;
+
+ var $wmc_id;
+ var $wmc_version;
+ var $wmc_windowWidth;
+ var $wmc_windowHeight;
+ var $wmc_bBox_SRS;
+ var $wmc_bBox_minx;
+ var $wmc_bBox_maxx;
+ var $wmc_bBox_miny;
+ var $wmc_bBox_maxy;
+ var $wmc_name;
+ var $wmc_title;
+ var $wmc_abstract;
+ var $wmc_general_extension = array();
+ var $wmc_logourl;
+ var $wmc_logourl_format;
+ var $wmc_logourl_type;
+ var $wmc_logourl_width;
+ var $wmc_logourl_height;
+ var $wmc_descriptionurl;
+ var $wmc_descriptionurl_format;
+ var $wmc_descriptionurl_type;
+ var $wmc_keyword = array();
+ var $wmc_contactposition;
+ var $wmc_contactvoicetelephone;
+ var $wmc_contactemail;
+ var $wmc_contactfacsimiletelephone;
+ var $wmc_contactperson;
+ var $wmc_contactorganization;
+ var $wmc_contactaddresstype;
+ var $wmc_contactaddress;
+ var $wmc_contactcity;
+ var $wmc_contactstateorprovince;
+ var $wmc_contactpostcode;
+ var $wmc_contactcountry;
+
+
+ var $wmc_wms_title = array();
+ var $wmc_layer_queryable = array();
+ var $wmc_layer_hidden = array();
+ var $wmc_wms_id = array();
+ var $wmc_wms_service = array();
+ var $wmc_wms_version = array();
+ var $wmc_wms_layer_id = array();
+ var $wmc_layer_wfs_featuretype = array();
+ var $wmc_layer_id = array();
+ var $wmc_layer_pos = array();
+ var $wmc_layer_parent = array();
+ var $wmc_layer_querylayer = array();
+ var $wmc_layer_title = array();
+ var $wmc_layer_name = array();
+ var $wmc_layer_abstract = array();
+ var $wmc_layer_srs = array();
+ var $wmc_wms_serviceURL = array();
+ var $wmc_layer_format_current = array();
+ var $wmc_layer_dataurl = array();
+ var $wmc_layer_metadataurl = array();
+ var $wmc_layer_minscale = array();
+ var $wmc_layer_maxscale = array();
+ var $wmc_gui_layer_minscale = array();
+ var $wmc_gui_layer_maxscale = array();
+ var $wmc_layer_format = array();
+ var $wmc_layer_style_current = array();
+ var $wmc_layer_style_name = array();
+ var $wmc_layer_style_title = array();
+ var $wmc_layer_style_legendurl = array();
+ var $wmc_layer_style_legendurl_width = array();
+ var $wmc_layer_style_legendurl_height = array();
+ var $wmc_layer_style_legendurl_format = array();
+ var $wmc_layer_style_legendurl_type = array();
+ var $wmc_layer_style_sld_url = array();
+ var $wmc_layer_style_sld_type = array();
+ var $wmc_layer_style_sld_title = array();
+
+ var $wmc_wms_count = 0;
- function wmc() {
- }
+ /*
+ var $data_type = array();
+ var $data_format = array();
+
+ var $objLayer = array();
+
+ var $gui_wms_mapformat;
+ var $gui_wms_featureinfoformat;
+ var $gui_wms_exceptionformat;
+ var $gui_wms_epsg;
+
+ var $default_epsg = 0;
+ */
+ var $monitoringIsOn = false;
+
+function wmc() {
+}
+
+function saveAsFile() {
+ $filename = "wmc_" . date("Y_m_d_H_i_s") . ".log";
+ $logfile = "../../log/" . $filename;
- function getTitle() {
- return $this->wmc_title;
+ if($h = fopen($logfile,"a")){
+ $content = $this->xml;
+ if(!fwrite($h,$content)){
+ $e = new mb_exception("class_wmc.php: failed to write wmc.");
+ return false;
+ }
+ fclose($h);
}
+ return $filename;
+}
+
+function getTitle() {
+ return $this->wmc_title;
+}
+
+function getNumberOfWms () {
+ return $this->wmc_wms_count;
+}
+
+function createWMCFromObj($mapObject, $user_id, $generalTitle, $extensionData) {
+ $this->wmc_id = $user_id . '_' . time();
- function getNumberOfWms () {
- return $this->wmc_wms_count;
- }
+ $generalWidth = $mapObject->width;
+ $generalHeight = $mapObject->height;
+ $generalBboxSrs = $mapObject->epsg;
+
+ $arrayBBox = explode(",", $mapObject->extent);
+ $generalBboxMinx = floatval($arrayBBox[0]);
+ $generalBboxMiny = floatval($arrayBBox[1]);
+ $generalBboxMaxx = floatval($arrayBBox[2]);
+ $generalBboxMaxy = floatval($arrayBBox[3]);
+
+ $generalName = "Mapbender WMC"; // TO do : insert proper data
+ $generalKeywords = array("Mapbender", "WMC"); // TO do : insert proper data
+ $generalAbstract = ""; // TO do : insert proper data
+ $generalLogoUrl = ""; // TO do : insert proper data
+ $generalLogoUrlWidth = ""; // TO do : insert proper data
+ $generalLogoUrlHeight = ""; // TO do : insert proper data
+ $generalLogoUrlFormat = ""; // TO do : insert proper data
+ $generalDescriptionUrl = ""; // TO do : insert proper data
+ $generalContactPerson = "";
+ $generalContactOrganization = "";
+ $generalContactPosition = "";
+ $generalContactAddressType = "";
+ $generalContactAddress = "";
+ $generalContactCity = "";
+ $generalContactStateOrProvince = "";
+ $generalContactPostCode = "";
+ $generalContactCountry = "";
+ $generalContactVoiceTelephone = "";
+ $generalContactFacsimileTelephone = "";
+ $generalContactElectronicMailAddress = "";
+
+ $extension_namespace = "mapbender";
+
+ // LayerList variables
+ $layerHidden = "";
+ $layerQueryable = "";
+ $layerAbstract = "";
+ $layerName = "";
+ $layerSrs = "";
+ $layerDataUrl = "";
+ $layerMetadataUrl = "";
+ $layerFormat = "";
+ $layerFormat_current = "";
+ $layerStyle_current = "";
+ $layerStyle_name = "";
+ $layerStyle_title = "";
+ $layerStyle_legendURL = "";
+ $layerStyle_legendURL_width = "";
+ $layerStyle_legendURL_height = "";
+ $layerStyle_legendURL_format = "";
+
+ // generate XML
+ $doc = new DOMDocument("1.0", CHARSET);
+ $doc->preserveWhiteSpace = false;
+
+ // ViewContext
+ $e_view_context = $doc->createElementNS("http://www.opengis.net/context", "ViewContext");
+
+
+ $e_view_context->setAttribute("version", "1.0.0");
+ $e_view_context->setAttribute("id", $this->wmc_id);
+ $e_view_context->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+ $e_view_context->setAttribute("xmlns:mapbender", "http://www.mapbender.org");
+ $e_view_context->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ $e_view_context->setAttribute("xsi:SchemaLocation", "http://schemas.opengis.net/context/1.0.0/context.xsd");
+
+ // General
+ $e_general = $doc->createElement("General");
+
+ $e_window = $doc->createElement("Window");
+ if (!empty($generalWidth) && !empty($generalHeight)) {
+ $e_window->setAttribute("width", $generalWidth);
+ $e_window->setAttribute("height", $generalHeight);
+ }
+ $e_general->appendChild($e_window);
+
+ $e_bbox = $doc->createElement("BoundingBox");
+ $e_bbox->setAttribute("SRS", $generalBboxSrs);
+ $e_bbox->setAttribute("minx", $generalBboxMinx);
+ $e_bbox->setAttribute("miny", $generalBboxMiny);
+ $e_bbox->setAttribute("maxx", $generalBboxMaxx);
+ $e_bbox->setAttribute("maxy", $generalBboxMaxy);
+ $e_general->appendChild($e_bbox);
+
+ $e_name = $doc->createElement("Name", $generalName);
+ $e_general->appendChild($e_name);
+
+ $e_title = $doc->createElement("Title", $generalTitle);
+ $e_general->appendChild($e_title);
+
+ $e_keyword_list = $doc->createElement("KeywordList");
+ for ($i=0; $i < count($generalKeywords); $i++) {
+ $e_keyword = $doc->createElement("Keyword", $generalKeywords[$i]);
+ $e_keyword_list->appendChild($e_keyword);
+ }
+ $e_general->appendChild($e_keyword_list);
+
+ if ($generalAbstract){
+ $e_abstract = $doc->createElement("Abstract", $generalAbstract);
+ $e_general->appendChild($e_abstract);
+ }
+
+ if ($generalLogoUrlWidth && $generalLogoUrlHeight && $generalLogoUrlFormat && $generalLogoUrl){
+ $e_logo_url = $doc->createElement("LogoURL");
+ $e_logo_url->setAttribute("width", $generalLogoUrlWidth);
+ $e_logo_url->setAttribute("height", $generalLogoUrlHeight);
+ $e_logo_url->setAttribute("format", $generalLogoUrlFormat);
+
+ $e_logo_url_or = $doc->createElement("OnlineResource");
+ $e_logo_url_or->setAttributeNS("http://www.opengis.net/context", "xmlns:xlink", "http://www.w3.org/1999/xlink");
+ $e_logo_url_or->setAttribute("xlink:type", "simple");
+ $e_logo_url_or->setAttribute("xlink:href", $generalLogoUrl);
+ $e_logo_url->appendChild($e_logo_url_or);
+
+ $e_general->appendChild($e_logo_url);
+ }
+
+ if ($generalDescriptionUrl){
+ $e_description_url = $doc->createElement("DescriptionURL");
+
+ $e_description_url_or = $doc->createElement("OnlineResource");
+ $e_description_url_or->setAttributeNS("http://www.opengis.net/context", "xmlns:xlink", "http://www.w3.org/1999/xlink");
+ $e_description_url_or->setAttribute("xlink:type", "simple");
+ $e_description_url_or->setAttribute("xlink:href", $generalDescriptionUrl);
+ $e_description_url->appendChild($e_description_url_or);
+
+ $e_general->appendChild($e_description_url);
+ }
+
+ if ($generalContactElectronicMailAddress || $generalContactOrganization ||
+ $generalContactPerson || $generalContactPosition || $generalContactAddressType ||
+ $generalContactAddress || $generalContactCity || $generalContactStateOrProvince ||
+ $generalContactPostCode || $generalContactCountry || $generalContactVoiceTelephone ||
+ $generalContactFacsimileTelephone || $generalContactElectronicMailAddress) {
+
+ $e_contact = $doc->createElement("ContactInformation");
+
+ if ($generalContactPerson || $generalContactOrganization){
+ $e_contact_person_primary = $doc->createElement("ContactPersonPrimary");
+
+ if ($generalContactPerson){
+ $e_contact_person = $doc->createElement("ContactPerson", $generalContactPerson);
+ $e_contact_person_primary->appendChild($e_contact_person);
+ }
+ if ($generalContactOrganization){
+ $e_contact_organization = $doc->createElement("ContactOrganization", $generalContactOrganization);
+ $e_contact_person_primary->appendChild($e_contact_organization);
+ }
+ $e_contact->appendChild($e_contact_person_primary);
+ }
+
+ if ($generalContactPosition){
+ $e_contact_position = $doc->createElement("ContactPosition", $generalContactPosition);
+ $e_contact->appendChild($e_contact_position);
+ }
+
+ if ($generalContactAddressType || $generalContactAddress ||
+ $generalContactCity || $generalContactStateOrProvince ||
+ $generalContactPostCode || $generalContactCountry) {
+
+ $e_contact_address = $doc->createElement("ContactAddress");
+
+ if ($generalContactAddressType){
+ $e_address_type = $doc->createElement("AddressType", $generalContactAddressType);
+ $e_contact_address->appendChild($e_address_type);
+ }
+ if ($generalContactAddress){
+ $e_address = $doc->createElement("Address", $generalContactAddress);
+ $e_contact_address->appendChild($e_address);
+ }
+ if ($generalContactCity){
+ $e_city = $doc->createElement("City", $generalContactCity);
+ $e_contact_address->appendChild($e_city);
+ }
+ if ($generalContactStateOrProvince){
+ $e_state = $doc->createElement("StateOrProvince", $generalContactStateOrProvince);
+ $e_contact_address->appendChild($e_state);
+ }
+ if ($generalContactPostCode){
+ $e_postcode = $doc->createElement("PostCode", $generalContactPostCode);
+ $e_contact_address->appendChild($e_postcode);
+ }
+ if ($generalContactCountry){
+ $e_country = $doc->createElement("Country", $generalContactCountry);
+ $e_contact_address->appendChild($e_country);
+ }
+ $e_contact->appendChild($e_contact_address);
+ }
+
+ if ($generalContactVoiceTelephone){
+ $e_voice_telephone = $doc->createElement("ContactVoiceTelephone", $generalContactVoiceTelephone);
+ $e_contact->appendChild($e_voice_telephone);
+ }
+ if ($generalContactFacsimileTelephone){
+ $e_facsimile_telephone = $doc->createElement("ContactFacsimileTelephone", $generalContactFacsimileTelephone);
+ $e_contact->appendChild($e_facsimile_telephone);
+ }
+ if ($generalContactElectronicMailAddress){
+ $e_email = $doc->createElement("ContactElectronicMailAddress", $generalContactElectronicMailAddress);
+ $e_contact->appendChild($e_email);
+ }
+ $e_general->appendChild($e_contact);
+ }
+
+
+ if (count($extensionData) > 0) {
+ //$e = new mb_exception("writing wmc...");
+ $e_extensionGeneral = $doc->createElement("Extension");
+
+ foreach ($extensionData as $keyExtensionData => $valueExtensionData) {
+ $e_currentExtensionTag = $doc->createElement($extension_namespace.":".$keyExtensionData, $valueExtensionData);
+ $e_extensionGeneral->appendChild($e_currentExtensionTag);
+ }
+ $e_general->appendChild($e_extensionGeneral);
+ }
+ $e_view_context->appendChild($e_general);
+
+
+ // LayerList
+ $e_layer_list = $doc->createElement("LayerList");
+
+ for ($i=0; $i < count($mapObject->wms); $i++){
+ $wmsId = $mapObject->wms[$i]->wms_id;
+ $wms_epsg = array();
+ $wms_epsg[0] = $mapObject->epsg;
+
+ if ($mapObject->wms[$i]->gui_wms_epsg != $mapObject->epsg){
+ $wms_epsg[1] = $mapObject->wms[$i]->gui_wms_epsg;
+ }
+
+ for ($q = 0; $q < count($mapObject->wms[$i]->gui_epsg); $q++){
+ $isInArray = false;
+
+ for ($r=0 ; $r < count($wms_epsg); $r++){
+ if ($wms_epsg[$r] == $mapObject->wms[$i]->gui_epsg[$q]){
+ $isInArray = true;
+ }
+ }
+ if ($isInArray == false){
+ array_push($wms_epsg, $mapObject->wms[$i]->gui_epsg[$q]);
+ }
+ }
+ for ($j = 0; $j < count($mapObject->wms[$i]->objLayer); $j++){
+ if ($mapObject->wms[$i]->objLayer[$j]->layer_parent != ''){
+ if ($mapObject->wms[$i]->objLayer[$j]->gui_layer_visible == "1"){
+ $layerHidden = 0;
+ }
+ else{
+ $layerHidden = 1;
+ }
+ $layerQueryable = $mapObject->wms[$i]->objLayer[$j]->layer_queryable;
+ $layerQuerylayer = $mapObject->wms[$i]->objLayer[$j]->gui_layer_querylayer;
+ $layerId = $mapObject->wms[$i]->objLayer[$j]->layer_uid;
+ $layerName = $mapObject->wms[$i]->objLayer[$j]->layer_name;
+ $layerTitle = $mapObject->wms[$i]->objLayer[$j]->layer_title;
+ $layerAbstract = $mapObject->wms[$i]->wms_abstract; //To Do: insert actual abstract
+ $layerDataUrl = $mapObject->wms[$i]->objLayer[$j]->layer_dataurl_href;
+ $layerMetadataUrl = $mapObject->wms[$i]->objLayer[$j]->layer_metadataurl;
+ $layerMinscale = $mapObject->wms[$i]->objLayer[$j]->layer_minscale;
+ $layerMaxscale = $mapObject->wms[$i]->objLayer[$j]->layer_maxscale;
+ $guiLayerMinscale = $mapObject->wms[$i]->objLayer[$j]->gui_layer_minscale;
+ $guiLayerMaxscale = $mapObject->wms[$i]->objLayer[$j]->gui_layer_maxscale;
+ $wmsVersion = $mapObject->wms[$i]->wms_version;
+ $wmsTitle = $mapObject->wms[$i]->wms_title;
+ $wmsLayerId = $mapObject->wms[$i]->objLayer[0]->layer_uid;
+ $wmsOnlineResource = $mapObject->wms[$i]->wms_getmap;
+ $layerPos = $mapObject->wms[$i]->objLayer[$j]->layer_pos;
+ $layerParent = $mapObject->wms[$i]->objLayer[$j]->layer_parent;
+ $queryLayer = $mapObject->wms[$i]->objLayer[$j]->gui_layer_querylayer;
+ $wfsFeatureType = $mapObject->wms[$i]->objLayer[$j]->gui_layer_wfs_featuretype;
+
+ $e_layer = $doc->createElement("Layer");
+ $e_layer->setAttribute("queryable", $layerQueryable);
+ $e_layer->setAttribute("hidden", $layerHidden);
+
+ $e_service = $doc->createElement("Server");
+ $e_service->setAttribute("service", "OGC:WMS");
+ $e_service->setAttribute("version", $wmsVersion);
+ $e_service->setAttribute("title", $wmsTitle);
+
+ $e_service_or = $doc->createElement("OnlineResource");
+ $e_service_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+ $e_service_or->setAttribute("xlink:type", "simple");
+ $e_service_or->setAttribute("xlink:href", $wmsOnlineResource);
+
+ $e_service->appendChild($e_service_or);
+ $e_layer->appendChild($e_service);
+
+ $e_layer_name = $doc->createElement("Name", $layerName);
+ $e_layer->appendChild($e_layer_name);
+
+ $e_layer_title = $doc->createElement("Title", $layerTitle);
+ $e_layer->appendChild($e_layer_title);
+
+ if ($layerAbstract){
+ $e_layer_abstract = $doc->createElement("Abstract", $layerAbstract);
+ $e_layer->appendChild($e_layer_abstract);
+ }
+
+ $e_layer_srs = $doc->createElement("SRS", implode(" ", $wms_epsg));
+ $e_layer->appendChild($e_layer_name);
+
+ if ($layerDataUrl){
+ $e_layer_data_url = $doc->createElement("DataURL");
+
+ $e_layer_data_url_or = $doc->createElement("OnlineResource");
+ $e_layer_data_url_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+ $e_layer_data_url_or->setAttribute("xlink:type", "simple");
+ $e_layer_data_url_or->setAttribute("xlink:href", $layerDataUrl);
+
+ $e_layer_data_url->appendChild($e_layer_data_url_or);
+ $e_layer->appendChild($e_layer_data_url);
+ }
+
+ if ($layerMetadataUrl){
+ $e_layer_metadata_url = $doc->createElement("MetadataURL");
+
+ $e_layer_metadata_url_or = $doc->createElement("OnlineResource");
+ $e_layer_metadata_url_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+ $e_layer_metadata_url_or->setAttribute("xlink:type", "simple");
+ $e_layer_metadata_url_or->setAttribute("xlink:href", $layerMetadataUrl);
+
+ $e_layer_metadata_url->appendChild($e_layer_metadata_url_or);
+ $e_layer->appendChild($e_layer_metadata_url);
+ }
+
+ $e_extension = $doc->createElement("Extension");
+
+ $e_scalehint = $doc->createElement($extension_namespace.":ScaleHint");
+ $e_scalehint->setAttribute("min", $layerMinscale);
+ $e_scalehint->setAttribute("max", $layerMaxscale);
+ $e_extension->appendChild($e_scalehint);
+
+ $e_gui_scalehint = $doc->createElement($extension_namespace.":guiScaleHint");
+ $e_gui_scalehint->setAttribute("min", $guiLayerMinscale);
+ $e_gui_scalehint->setAttribute("max", $guiLayerMaxscale);
+ $e_extension->appendChild($e_gui_scalehint);
+
+ $e_layer_id = $doc->createElement($extension_namespace.":layer_id", $layerId);
+ $e_extension->appendChild($e_layer_id);
+
+ $e_wms_layer_id = $doc->createElement($extension_namespace.":wms_layer_id", $wmsLayerId);
+ $e_extension->appendChild($e_wms_layer_id);
+
+ $e_layer_pos = $doc->createElement($extension_namespace.":layer_pos", $layerPos);
+ $e_extension->appendChild($e_layer_pos);
+
+ $e_layer_parent = $doc->createElement($extension_namespace.":layer_parent", $layerParent);
+ $e_extension->appendChild($e_layer_parent);
+
+ $e_wms_id = $doc->createElement($extension_namespace.":wms_id", $wmsId);
+ $e_extension->appendChild($e_wms_id);
+
+ $e_querylayer = $doc->createElement($extension_namespace.":querylayer", $layerQuerylayer);
+ $e_extension->appendChild($e_querylayer);
+
+ if ($wfsFeatureType) {
+ $e_wfsFeatureType = $doc->createElement($extension_namespace.":wfsFeatureType", $wfsFeatureType);
+ $e_extension->appendChild($e_wfsFeatureType);
+ }
- function createObjFromWMC_id($wmc_id){
+ $e_layer->appendChild($e_extension);
- $con = db_connect(DBSERVER,OWNER,PW);
- db_select_db(DB, $con);
+ //layerFormat
+ $e_layer_format = $doc->createElement("FormatList");
- $sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1";
- $v = array($wmc_id);
- $t = array("s");
- $res = db_prep_query($sql, $v, $t);
- $wmc = db_fetch_array($res);
- $this->createObjFromWMC_xml($wmc[0]);
+ $data_format_current = false;
+
+ for ($k = 0; $k < count($mapObject->wms[$i]->data_format); $k++){
+
+ if ($mapObject->wms[$i]->data_type[$k] == "map") {
+ $layerFormat = $mapObject->wms[$i]->data_format[$k];
+
+ $e_format = $doc->createElement("Format", $layerFormat);
+
+ if ($data_format_current == false && (
+ ($mapObject->wms[$i]->data_format[$k] == $mapObject->wms[$i]->gui_wms_mapformat) ||
+ ($k == (count($mapObject->wms[$i]->data_format)-1))
+ )){
+
+ $e_format->setAttribute("current", "1");
+ $data_format_current = true;
+ }
+ $e_layer_format->appendChild($e_format);
+ }
+ }
+ $e_layer->appendChild($e_layer_format);
+
+
+ // LayerStyle
+ $e_layer_stylelist = $doc->createElement("StyleList");
+
+ for ($k = 0; $k < count($mapObject->wms[$i]->objLayer[$j]->layer_style); $k++){
+
+ if ($k == 0){
+ $layerStyle_current = 1; // To do: insert proper data
+ }
+ else{
+ $layerStyle_current = 0; // To do: insert proper data
+ }
+
+ $e_layer_style = $doc->createElement("Style");
+
+ $layerStyleSLD = "";
+
+ if ($layerStyleSLD){
+ $layerStyleSLDUrl = ""; // To Do: Insert Proper Data
+
+ $e_layer_style_or = $doc->createElement("OnlineResource");
+ $e_layer_style_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+ $e_layer_style_or->setAttribute("xlink:type", "simple");
+ $e_layer_style_or->setAttribute("xlink:href", $layerStyleSLDUrl);
+ $e_layer_style->appendChild($e_layer_style_or);
+ }
+ else{
+ //TODO: determine correct layer style entries
+ $layerStyle_name = $mapObject->wms[$i]->objLayer[$j]->layer_style[$k]->name;
+ $layerStyle_title = $mapObject->wms[$i]->objLayer[$j]->layer_style[$k]->title;
+ $layerStyle_legendUrl = $mapObject->wms[$i]->objLayer[$j]->layer_style[$k]->legendurl;
+ $layerStyle_legendUrl_width = ""; // To Do: add proper data
+ $layerStyle_legendUrl_height = ""; // To Do: add proper data
+ $layerStyle_legendUrl_format = ""; // To Do: add proper data
+
+ if ($layerStyle_current == 1){
+ $e_layer_style->setAttribute("current", "1");
+ }
+ $e_layer_style_name = $doc->createElement("Name", $layerStyle_name);
+ $e_layer_style->appendChild($e_layer_style_name);
+
+ $e_layer_style_title = $doc->createElement("Title", $layerStyle_title);
+ $e_layer_style->appendChild($e_layer_style_title);
+
+
+ $e_layer_style_legendurl = $doc->createElement("LegendUrl");
+ $e_layer_style_legendurl->setAttribute("width", $layerStyle_legendUrl_width);
+ $e_layer_style_legendurl->setAttribute("height", $layerStyle_legendUrl_height);
+ $e_layer_style_legendurl->setAttribute("format", $layerStyle_legendUrl_format);
+
+ $e_layer_style_legendurl_or = $doc->createElement("OnlineResource");
+ $e_layer_style_legendurl_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+ $e_layer_style_legendurl_or->setAttribute("xlink:type", "simple");
+ $e_layer_style_legendurl_or->setAttribute("xlink:href", $layerStyle_legendUrl);
+ $e_layer_style_legendurl->appendChild($e_layer_style_legendurl_or);
+ $e_layer_style->appendChild($e_layer_style_legendurl);
+ }
+ $e_layer_stylelist->appendChild($e_layer_style);
+ }
+ $e_layer->appendChild($e_layer_stylelist);
+
+ $e_layer_list->appendChild($e_layer);
+ }
+ }
+ }
+ $e_view_context->appendChild($e_layer_list);
+
+
+ $doc->appendChild($e_view_context);
+ $this->xml = $doc->saveXML();
+
+ // for debugging: saving WMC as file
+ // (comment when no longer needed)
+ $filename = $this->saveAsFile();
+ if ($filename) {
+ $e = new mb_notice("class_wmc: saving WMC as file " . $filename);
}
+}
- function createObjFromWMC_xml($data){
- $data = str_replace("&", "&", $data);
- $values = NULL;
- $tags = NULL;
- $parser = xml_parser_create(CHARSET);
- xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
- xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
- xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
- xml_parse_into_struct($parser,$data,$values,$tags);
- $code = xml_get_error_code ($parser);
- if ($code) {
- $line = xml_get_current_line_number($parser);
- $mb_exception = new mb_exception(xml_error_string($code) . " in line " . $line);
- return false;
+function createObjFromWMC_id($wmc_id){
+
+ global $DBSERVER,$DB,$OWNER,$PW;
+ $con = db_connect($DBSERVER,$OWNER,$PW);
+ db_select_db(DB, $con);
+
+ $sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = '" . $wmc_id . "'";
+ $res = db_query($sql);
+ $wmc = db_fetch_row($res);
+ $this->createObjFromWMC_xml($wmc[0]);
+ $this->monitoringIsOn = true;
+
+}
+function createObjFromWMC_xml($data){
+# $data = str_replace("&", "&", $data);
+
+ // store xml
+ $this->xml = $data;
+
+ // for debugging: saving WMC as file
+ // (comment when no longer needed)
+ $filename = $this->saveAsFile();
+ if ($filename) {
+ $e = new mb_notice("class_wmc: saving WMC as file " . $filename);
+ }
+
+
+
+ $values = NULL;
+ $tags = NULL;
+ $parser = xml_parser_create(CHARSET);
+ xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
+ xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
+ xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
+ xml_parse_into_struct($parser,$data,$values,$tags);
+ $code = xml_get_error_code ($parser);
+ if ($code) {
+ $line = xml_get_current_line_number($parser);
+ $mb_exception = new mb_exception(xml_error_string($code) . " in line " . $line);
+ return false;
+ }
+ xml_parser_free($parser);
+
+ $section = NULL;
+ $format = NULL;
+ $cnt_format = 0;
+ $parent = array();
+ $myParent = array();
+ $cnt_layer = -1;
+ $request = NULL;
+ $layer_style = array();
+ $extension = false;
+
+ $general = false;
+ $layerlist = false;
+ $layer = false;
+ $formatlist = false;
+ $dataurl = false;
+ $metadataurl = false;
+ $stylelist = false;
+ $cnt_style = -1;
+
+ foreach ($values as $element) {
+ $verbose .= ".";
+ if(strtoupper($element[tag]) == "VIEWCONTEXT" && $element[type] == "open"){
+ $this->wmc_id = $element[attributes]["id"];
+ $this->wmc_version = $element[attributes]["version"];
}
- xml_parser_free($parser);
-
- $section = NULL;
- $format = NULL;
- $cnt_format = 0;
- $parent = array();
- $myParent = array();
- $cnt_layer = -1;
- $request = NULL;
- $layer_style = array();
- $cnt_style = -1;
- $extension = false;
-
- $general = false;
- $layerlist = false;
- $layer = false;
- $formatlist = false;
- $metadataurl = false;
- $dataurl = false;
- $stylelist = false;
-
- foreach ($values as $element) {
- if(strtoupper($element[tag]) == "VIEWCONTEXT" && $element[type] == "open"){
- $this->wmc_id = $element[attributes]["id"];
- $this->wmc_version = $element[attributes]["version"];
- }
- if(strtoupper($element[tag]) == "GENERAL" && $element[type] == "open"){
- $general = true;
- }
- if(strtoupper($element[tag]) == "LAYERLIST" && $element[type] == "open"){
- $layerlist = true;
- }
- if ($general) {
+ if(strtoupper($element[tag]) == "GENERAL" && $element[type] == "open"){
+ $general = true;
+ }
+ if(strtoupper($element[tag]) == "LAYERLIST" && $element[type] == "open"){
+ $layerlist = true;
+ }
+ if ($general) {
if(strtoupper($element[tag]) == "WINDOW"){
- $this->wmc_windowWidth = $element[attributes]["width"];
- $this->wmc_windowHeight = $element[attributes]["height"];
+ $this->wmc_windowWidth = $element[attributes]["width"];
+ $this->wmc_windowHeight = $element[attributes]["height"];
}
if(strtoupper($element[tag]) == "BOUNDINGBOX"){
- $this->wmc_bBox_SRS = $element[attributes]["SRS"];
- $this->wmc_bBox_minx = $element[attributes]["minx"];
- $this->wmc_bBox_miny = $element[attributes]["miny"];
- $this->wmc_bBox_maxx = $element[attributes]["maxx"];
- $this->wmc_bBox_maxy = $element[attributes]["maxy"];
+ $this->wmc_bBox_SRS = $element[attributes]["SRS"];
+ $this->wmc_bBox_minx = $element[attributes]["minx"];
+ $this->wmc_bBox_miny = $element[attributes]["miny"];
+ $this->wmc_bBox_maxx = $element[attributes]["maxx"];
+ $this->wmc_bBox_maxy = $element[attributes]["maxy"];
}
if(strtoupper($element[tag]) == "NAME"){
- $this->wmc_name = mb_utf8_decode(html_entity_decode($element[value]));
+ $this->wmc_name = mb_utf8_decode(html_entity_decode($element[value]));
}
if(strtoupper($element[tag]) == "TITLE"){
- $this->wmc_title = mb_utf8_decode(html_entity_decode($element[value]));
+ $this->wmc_title = mb_utf8_decode(html_entity_decode($element[value]));
}
if(strtoupper($element[tag]) == "ABSTRACT"){
- $this->wmc_abstract = mb_utf8_decode(html_entity_decode($element[value]));
+ $this->wmc_abstract = mb_utf8_decode(html_entity_decode($element[value]));
}
if(strtoupper($element[tag]) == "CONTACTINFORMATION" && $element['type'] == "open"){
- $contactinformation = true;
+ $contactinformation = true;
}
if ($contactinformation) {
if(strtoupper($element[tag]) == "CONTACTPOSITION"){
- $this->wmc_contactposition = mb_utf8_decode(html_entity_decode($element[value]));
+ $this->wmc_contactposition = mb_utf8_decode(html_entity_decode($element[value]));
}
if(strtoupper($element[tag]) == "CONTACTVOICETELEPHONE"){
- $this->wmc_contactvoicetelephone = $element[value];
+ $this->wmc_contactvoicetelephone = $element[value];
}
if(strtoupper($element[tag]) == "CONTACTFACSIMILETELEPHONE"){
- $this->wmc_contactfacsimiletelephone = $element[value];
+ $this->wmc_contactfacsimiletelephone = $element[value];
}
if(strtoupper($element[tag]) == "CONTACTELECTRONICMAILADDRESS"){
- $this->wmc_contactemail = mb_utf8_decode(html_entity_decode($element[value]));
+ $this->wmc_contactemail = mb_utf8_decode(html_entity_decode($element[value]));
}
if(strtoupper($element[tag]) == "CONTACTPERSONPRIMARY" && $element['type'] == "open"){
- $contactpersonprimary = true;
+ $contactpersonprimary = true;
}
if ($contactpersonprimary) {
if(strtoupper($element[tag]) == "CONTACTPERSON"){
- $this->wmc_contactperson = mb_utf8_decode(html_entity_decode($element[value]));
+ $this->wmc_contactperson = mb_utf8_decode(html_entity_decode($element[value]));
}
if(strtoupper($element[tag]) == "CONTACTORGANIZATION"){
- $this->wmc_contactorganization = mb_utf8_decode(html_entity_decode($element[value]));
+ $this->wmc_contactorganization = mb_utf8_decode(html_entity_decode($element[value]));
}
if(strtoupper($element[tag]) == "CONTACTPERSONPRIMARY" && $element['type'] == "close"){
- $contactpersonprimary = false;
+ $contactpersonprimary = false;
}
}
if(strtoupper($element[tag]) == "CONTACTADDRESS" && $element['type'] == "open"){
- $contactaddress = true;
+ $contactaddress = true;
}
if ($contactaddress) {
if(strtoupper($element[tag]) == "ADDRESSTYPE"){
- $this->wmc_contactaddresstype = mb_utf8_decode(html_entity_decode($element[value]));
+ $this->wmc_contactaddresstype = mb_utf8_decode(html_entity_decode($element[value]));
}
if(strtoupper($element[tag]) == "ADDRESS"){
- $this->wmc_contactaddress = mb_utf8_decode(html_entity_decode($element[value]));
+ $this->wmc_contactaddress = mb_utf8_decode(html_entity_decode($element[value]));
}
if(strtoupper($element[tag]) == "CITY"){
- $this->wmc_contactcity = mb_utf8_decode(html_entity_decode($element[value]));
+ $this->wmc_contactcity = mb_utf8_decode(html_entity_decode($element[value]));
}
if(strtoupper($element[tag]) == "STATEORPROVINCE"){
- $this->wmc_contactstateorprovince = mb_utf8_decode(html_entity_decode($element[value]));
+ $this->wmc_contactstateorprovince = mb_utf8_decode(html_entity_decode($element[value]));
}
if(strtoupper($element[tag]) == "POSTCODE"){
- $this->wmc_contactpostcode = $element[value];
+ $this->wmc_contactpostcode = $element[value];
}
if(strtoupper($element[tag]) == "COUNTRY"){
- $this->wmc_contactcountry = mb_utf8_decode(html_entity_decode($element[value]));
+ $this->wmc_contactcountry = mb_utf8_decode(html_entity_decode($element[value]));
}
if(strtoupper($element[tag]) == "CONTACTADDRESS" && $element['type'] == "close"){
- $contactaddress = false;
+ $contactaddress = false;
}
}
}
if(strtoupper($element[tag]) == "LOGOURL" && $element['type'] == "open"){
- $logourl = true;
- $this->wmc_logourl_width = $element[attributes]["width"];
- $this->wmc_logourl_height = $element[attributes]["height"];
- $this->wmc_logourl_format = $element[attributes]["format"];
+ $logourl = true;
+ $this->wmc_logourl_width = $element[attributes]["width"];
+ $this->wmc_logourl_height = $element[attributes]["height"];
+ $this->wmc_logourl_format = $element[attributes]["format"];
}
if ($logourl) {
if(strtoupper($element[tag]) == "LOGOURL" && $element['type'] == "close"){
- $logourl = false;
+ $logourl = false;
}
if(strtoupper($element[tag]) == "ONLINERESOURCE"){
$this->wmc_logourl_type = $element[attributes]["xlink:type"];
@@ -268,12 +798,12 @@
}
}
if(strtoupper($element[tag]) == "DESCRIPTIONURL" && $element['type'] == "open"){
- $descriptionurl = true;
- $this->wmc_descriptionurl_format = $element[attributes]["format"];
+ $descriptionurl = true;
+ $this->wmc_descriptionurl_format = $element[attributes]["format"];
}
if ($descriptionurl) {
if(strtoupper($element[tag]) == "DESCRIPTIONURL" && $element['type'] == "close"){
- $descriptionurl = false;
+ $descriptionurl = false;
}
if(strtoupper($element[tag]) == "ONLINERESOURCE"){
$this->wmc_descriptionurl_type = $element[attributes]["xlink:type"];
@@ -281,12 +811,12 @@
}
}
if(strtoupper($element[tag]) == "KEYWORDLIST" && $element['type'] == "open"){
- $keywordlist = true;
+ $keywordlist = true;
}
if ($keywordlist) {
if(strtoupper($element[tag]) == "KEYWORDLIST" && $element['type'] == "close"){
- $keywordlist = false;
- $cnt_keyword = -1;
+ $keywordlist = false;
+ $cnt_keyword = -1;
}
if(strtoupper($element[tag]) == "KEYWORD"){
$cnt_keyword++;
@@ -294,11 +824,22 @@
}
}
+ if(strtoupper($element[tag]) == "EXTENSION" && $element['type'] == "close"){
+ $generalExtension = false;
+ }
+ if ($generalExtension) {
+ $this->wmc_general_extension[sepNameSpace($element[tag])] = $element[value];
+// $e = new mb_exception("WMC: " . $element[tag] . ": " . $element[value]);
+ }
+ if(strtoupper($element[tag]) == "EXTENSION" && $element['type'] == "open"){
+ $generalExtension = true;
+ }
+
if(strtoupper($element[tag]) == "GENERAL" && $element['type'] == "close"){
$general = false;
}
- }
- if ($layerlist) {
+ }
+ if ($layerlist) {
if(strtoupper($element[tag]) == "LAYERLIST" && $element['type'] == "close"){
$layerlist = false;
}
@@ -310,9 +851,9 @@
$cnt_epsg = 0;
}
if ($layer) {
- if(strtoupper($element[tag]) == "LAYER" && $element[type] == "close"){
- $layer = false;
- }
+ if(strtoupper($element[tag]) == "LAYER" && $element[type] == "close"){
+ $layer = false;
+ }
if ($formatlist) {
if(strtoupper($element[tag]) == "FORMAT"){
$cnt_format++;
@@ -325,10 +866,10 @@
}
elseif ($metadataurl) {
if(strtoupper($element[tag]) == "ONLINERESOURCE"){
- $this->wmc_layer_metadataurl[$cnt_layer] = $element[attributes]["xlink:href"];
+ $this->wmc_layer_metadataurl[$cnt_layer] = $element[attributes]["xlink:href"];
}
if(strtoupper($element[tag]) == "METADATAURL" && $element[type] == "close"){
- $metadataurl = false;
+ $metadataurl = false;
}
}
elseif ($dataurl) {
@@ -434,15 +975,31 @@
$this->wmc_layer_minscale[$cnt_layer] = $element[attributes]["min"];
$this->wmc_layer_maxscale[$cnt_layer] = $element[attributes]["max"];
}
+ if($extension == true && strtoupper(sepNameSpace($element[tag])) == "GUISCALEHINT"){
+ $this->wmc_gui_layer_minscale[$cnt_layer] = $element[attributes]["min"];
+ $this->wmc_gui_layer_maxscale[$cnt_layer] = $element[attributes]["max"];
+ }
if($extension == true && strtoupper(sepNameSpace($element[tag])) == "LAYER_ID"){
$this->wmc_layer_id[$cnt_layer] = $element[value];
}
- if($extension == true && strtoupper(sepNameSpace($element[tag])) == "WMS_ID"){
- $this->wmc_wms_id[$cnt_layer] = $element[value];
+ if($extension == true && strtoupper(sepNameSpace($element[tag])) == "WMS_LAYER_ID"){
+ $this->wmc_wms_layer_id[$cnt_layer] = $element[value];
}
+ if($extension == true && strtoupper(sepNameSpace($element[tag])) == "LAYER_POS"){
+ $this->wmc_layer_pos[$cnt_layer] = $element[value];
+ }
+ if($extension == true && strtoupper(sepNameSpace($element[tag])) == "LAYER_PARENT"){
+ $this->wmc_layer_parent[$cnt_layer] = $element[value];
+ }
if($extension == true && strtoupper(sepNameSpace($element[tag])) == "QUERYLAYER"){
$this->wmc_layer_querylayer[$cnt_layer] = $element[value];
}
+ if($extension == true && strtoupper(sepNameSpace($element[tag])) == "WMS_ID"){
+ $this->wmc_wms_id[$cnt_layer] = $element[value];
+ }
+ if($extension == true && strtoupper(sepNameSpace($element[tag])) == "WFSFEATURETYPE"){
+ $this->wmc_layer_wfs_featuretype[$cnt_layer] = $element[value];
+ }
if(strtoupper($element[tag]) == "METADATAURL" && $element[type] == "open"){
$metadataurl = true;
}
@@ -462,15 +1019,34 @@
}
}
return true;
+ //return $verbose;
}
function createJsObjFromWMC($target, $mapObj, $action){
+
+ /*
+ * counts how often a layer has been loaded
+ */
+ if ($this->monitoringIsOn) {
+ $monitor = new Layer_load_count();
+ for ($i = 0; $i < count($this->wmc_layer_id); $i++) {
+ $monitor->increment($this->wmc_layer_id[$i]);
+ }
+ }
+
$wmc_string = "";
$validActions = array("load", "merge", "append");
if (!in_array($action, $validActions)) {
$wmc_string .= "alert('invalid action: ".$action."');";
}
else {
+
+ // general extension
+ if (count($this->wmc_general_extension) > 0) {
+ $json = new Services_JSON();
+ $wmc_string .= $target . "restoredWmcExtensionData = " . $json->encode($this->wmc_general_extension) . ";\n";
+ }
+
$wmc_string .= "var index = " . $target . "getMapObjIndexByName('" . $mapObj . "');\n";
if ($action == "load") {
// delete all previous wms
@@ -521,7 +1097,8 @@
}
}
// add wms
- $wmc_string .= "\t" . $target . "add_wms('','".
+ $wmc_string .= "\t" . $target . "add_wms('".
+ $this->wmc_wms_id[$i]."','".
$this->wmc_wms_version[$i] ."','".
$this->wmc_wms_title[$i] ."','".
$this->wmc_layer_abstract[$i] ."','".
@@ -565,7 +1142,10 @@
$wmc_string .= "if (!wms_exists) {\n\t";
}
// add parent layer
- $wmc_string .= $target . "wms_add_layer('','".$this->wmc_layer_id[$i]."','','". $this->wmc_wms_title[$i] ."','','0','0','0','0','','".$this->wmc_wms_id[$i]."','1','1','1','0','0','0','0');\n";
+ $wmc_string .= $target . "wms_add_layer('','".
+ $this->wmc_wms_layer_id[$i]."','','".
+ $this->wmc_wms_title[$i] ."','','0','0','0','0','','".
+ $this->wmc_wms_id[$i]."','1','', '1','1','0','0','0','0','');\n";
if ($action == "merge") {
$wmc_string .= "}\n";
}
@@ -585,15 +1165,21 @@
$wmc_string .= "\t\t\tcurrent_layer_index = m;\n";
$wmc_string .= "\t\t}\n";
$wmc_string .= "\t}\n";
-
+
+ if ($this->wmc_layer_querylayer[$ii]!="") {
+ $querylayer_yn = $this->wmc_layer_querylayer[$ii];
+ }
+ else {
+ $querylayer_yn = $this->wmc_layer_queryable[$ii];
+ }
$wmc_string .= "\tif (layer_exists) {\n";
// check if the visibility or the queryability are different to the existing layer
$wmc_string .= "\t\tif (" . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_visible != '" . intval(!$this->wmc_layer_hidden[$ii]) . "'";
- $wmc_string .= " || " . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer != '" . $this->wmc_layer_queryable[$ii] . "') {\n";
+ $wmc_string .= " || " . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer != '" . $querylayer_yn . "') {\n";
// if yes, update the visibility and queryability
$wmc_string .= "\t\t\t" . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_visible = " . intval(!$this->wmc_layer_hidden[$ii]) . ";\n";
- $wmc_string .= "\t\t\t" . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer = " . $this->wmc_layer_queryable[$ii] . ";\n";
+ $wmc_string .= "\t\t\t" . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer = " . $querylayer_yn . ";\n";
$wmc_string .= "\t\t}\n";
$wmc_string .= "\t}\n";
$wmc_string .= "}\n";
@@ -601,29 +1187,31 @@
}
// add layer
- $wmc_string .= "\t" . $target . "wms_add_layer('0','".
+ $wmc_string .= "\t" . $target . "wms_add_layer('".
+ ($this->wmc_layer_parent[$ii]!=""?$this->wmc_layer_parent[$ii]:"0") . "','".
$this->wmc_layer_id[$ii] . "','".
$this->wmc_layer_name[$ii] . "','".
$this->wmc_layer_title[$ii] ."','".
$this->wmc_layer_dataurl[$ii] . "','".
- intval($cnt_layers) ."','".
+ ($this->wmc_layer_pos[$ii]!=""?$this->wmc_layer_pos[$ii]:intval($cnt_layers)) ."','".
$this->wmc_layer_queryable[$ii] ."','".
$this->wmc_layer_minscale[$ii] ."','".
$this->wmc_layer_maxscale[$ii] ."','".
$this->wmc_layer_metadataurl[$ii] ."','".
- $this->wmc_wms_id[$ii] ."','1','1','".
+ $this->wmc_wms_id[$i] ."','1','', '1','".
intval(!$this->wmc_layer_hidden[$ii]) ."','".
$this->wmc_layer_queryable[$ii] ."','".
- $this->wmc_layer_querylayer[$ii] ."','".
- $this->wmc_layer_minscale[$ii] ."','".
- $this->wmc_layer_maxscale[$ii] ."');\n";
+ ($this->wmc_layer_querylayer[$ii]!=""?$this->wmc_layer_querylayer[$ii]:$this->wmc_layer_queryable[$ii]) ."','".
+ ($this->wmc_gui_layer_minscale[$ii]!=""?$this->wmc_gui_layer_minscale[$ii]:$this->wmc_layer_minscale[$ii]) ."','".
+ ($this->wmc_gui_layer_maxscale[$ii]!=""?$this->wmc_gui_layer_maxscale[$ii]:$this->wmc_layer_maxscale[$ii]) ."','".
+ $this->wmc_layer_wfs_featuretype[$ii] . "');\n";
if ($action == "merge") {
$wmc_string .= "\t}\n";
}
// if layer is queryable, add it to querylayerlist
- if ($this->wmc_layer_queryable[$ii]) {
+ if (($this->wmc_layer_querylayer[$ii]!=""?$this->wmc_layer_querylayer[$ii]:$this->wmc_layer_queryable[$ii])) {
$cnt_query_layers++;
if (!in_array($this->wmc_layer_name[$ii], explode(",",$querylayerlist))) {
if ($querylayerlist == "") {$querylayerlist = $this->wmc_layer_name[$ii];} else {$querylayerlist .= "," . $this->wmc_layer_name[$ii];}
@@ -666,30 +1254,57 @@
$wmc_string .= "\t\tvar found = false;\n";
$wmc_string .= "\t\tfor (var j=0; j < " . $target . "wms.length && found == false; j++) {\n";
$wmc_string .= "\t\t\tif (" . $target . "wms[j].wms_getmap == old_mapObj[i].wms[0].wms_getmap) {\n";
- $wmc_string .= "\t\t\t\t" . $target . "mb_registerMapObj('overview', old_mapObj[i].elementName, j, old_mapObj[i].width, old_mapObj[i].height);\n";
+ $wmc_string .= "\t\t\t\t" . $target . "mb_registerMapObj('overview', old_mapObj[i].elementName, j, old_mapObj[i].width, old_mapObj[i].width);\n";
$wmc_string .= "\t\t\t\tfound = true;\n";
$wmc_string .= "\t\t\t}\n";
$wmc_string .= "\t\t}\n";
$wmc_string .= "\t\tif (!found) {\n";
- $wmc_string .= "\t\t\t" . $target . "mb_registerMapObj('overview', old_mapObj[i].elementName, 0, old_mapObj[i].width, old_mapObj[i].height);\n";
+ $wmc_string .= "\t\t\t" . $target . "mb_registerMapObj('overview', old_mapObj[i].elementName, 0, old_mapObj[i].width, old_mapObj[i].width);\n";
$wmc_string .= "\t\t}\n";
$wmc_string .= "\t}\n";
$wmc_string .= "}\n";
- $sql = "SELECT minx, miny, maxx, maxy FROM layer_epsg WHERE fkey_layer_id = $1 AND epsg = $2 LIMIT 1";
- $v = array($this->wmc_layer_id[0], $this->wmc_bBox_SRS);
- $t = array('i', 's');
- $res = db_prep_query($sql, $v, $t);
- $row = db_fetch_array($res);
- if ($row["minx"] && $row["miny"] && $row["maxx"] && $row["maxy"]) {
- $ov_bbox = array($row["minx"],$row["miny"],$row["maxx"],$row["maxy"]);
+ $ov_bbox = array();
+ // compute the union of the overview and the mapframe bbox for the new overview bbox
+ if ($this->wmc_general_extension["ov_minx"] && $this->wmc_general_extension["ov_miny"] &&
+ $this->wmc_general_extension["ov_maxx"] && $this->wmc_general_extension["ov_maxy"]) {
+
+ // box for overview
+ $ov_min = new Mapbender_point($this->wmc_general_extension["ov_minx"], $this->wmc_general_extension["ov_miny"], $this->wmc_bBox_SRS);
+ $ov_max = new Mapbender_point($this->wmc_general_extension["ov_maxx"], $this->wmc_general_extension["ov_maxy"], $this->wmc_bBox_SRS);
+ $ov_box = new Mapbender_bbox($ov_min, $ov_max, $this->wmc_bBox_SRS);
+
+ // box for mapframe
+ $mf_min = new Mapbender_point($this->wmc_bBox_minx, $this->wmc_bBox_miny, $this->wmc_bBox_SRS);
+ $mf_max = new Mapbender_point($this->wmc_bBox_maxx, $this->wmc_bBox_maxy, $this->wmc_bBox_SRS);
+ $mf_box = new Mapbender_bbox($mf_min, $mf_max, $this->wmc_bBox_SRS);
+
+ $unionBox = Mapbender_bbox::union(array($ov_box, $mf_box));
+
+ array_push($ov_bbox, $unionBox->min->x);
+ array_push($ov_bbox, $unionBox->min->y);
+ array_push($ov_bbox, $unionBox->max->x);
+ array_push($ov_bbox, $unionBox->max->y);
}
- else if ($this->wmc_layer_id[0] && $this->wmc_bBox_SRS){
- $ov_bbox = array($this->wmc_bBox_minx, $this->wmc_bBox_miny, $this->wmc_bBox_maxx, $this->wmc_bBox_maxy);
- }
else {
- $ov_bbox = array();
+/*
+ $sql = "SELECT minx, miny, maxx, maxy FROM layer_epsg WHERE fkey_layer_id = $1 AND epsg = $2 LIMIT 1";
+ $v = array($this->wmc_layer_id[0], $this->wmc_bBox_SRS);
+ $t = array('i', 's');
+ $res = db_prep_query($sql, $v, $t);
+ $row = db_fetch_array($res);
+ if ($row["minx"] && $row["miny"] && $row["maxx"] && $row["maxy"]) {
+ $ov_bbox = array($row["minx"],$row["miny"],$row["maxx"],$row["maxy"]);
+ }
+ else if ($this->wmc_layer_id[0] && $this->wmc_bBox_SRS){
+ $ov_bbox = array($this->wmc_bBox_minx, $this->wmc_bBox_miny, $this->wmc_bBox_maxx, $this->wmc_bBox_maxy);
+ }
+ else {
+*/
+ $ov_bbox = array(2412139.175257732, 5365000, 2767860.824742268, 5700000);
+// }
}
+
$wmc_string .= "for (var i=0; i<old_mapObj.length; i++) {\n";
$wmc_string .= "\tif (old_mapObj[i].frameName != 'overview') {\n";
$wmc_string .= "\t\t".$target."mb_calculateExtent(old_mapObj[i].frameName, ";
@@ -697,25 +1312,16 @@
$wmc_string .= $this->wmc_bBox_maxx .",".$this->wmc_bBox_maxy.");\n";
$wmc_string .= "\t}\n";
$wmc_string .= "\telse {\n";
- if (count($ov_bbox)>0) {
-// $wmc_string .= "alert('found bbox for ov: ".implode(',',$ov_bbox)."');";
- $wmc_string .= "\t\t".$target."mb_calculateExtent(old_mapObj[i].frameName, ";
- $wmc_string .= $ov_bbox[0] .",".$ov_bbox[1] .",";
- $wmc_string .= $ov_bbox[2] .",".$ov_bbox[3] .");\n";
- }
- else {
-// $wmc_string .= "alert('no bbox found for ov: old bbox ".$this->wmc_bBox_minx." etc');";
- $wmc_string .= "\t\t".$target."mb_calculateExtent(old_mapObj[i].frameName, ";
- $wmc_string .= $this->wmc_bBox_minx .",".$this->wmc_bBox_miny .",";
- $wmc_string .= $this->wmc_bBox_maxx .",".$this->wmc_bBox_maxy.");\n";
-// $wmc_string .= "\t\tvar ov_index = " . $target . "getMapObjIndexByName('overview');\n";
-// $wmc_string .= "\t\t" . $target . "mb_mapObj[ov_index].extent = old_mapObj[i].extent;\n";
- }
+ $wmc_string .= "\t\t".$target."mb_calculateExtent(old_mapObj[i].frameName, ";
+ $wmc_string .= $ov_bbox[0] .",".$ov_bbox[1] .",";
+ $wmc_string .= $ov_bbox[2] .",".$ov_bbox[3] .");\n";
$wmc_string .= "\t}\n";
$wmc_string .= "\t". $target . "setMapRequest(old_mapObj[i].frameName);\n";
$wmc_string .= "}\n";
$wmc_string .= $target . "mb_execloadWmsSubFunctions();\n";
+ $wmc_string .= $target . "mb_execloadWmcSubFunctions();\n";
}
+// $e = new mb_exception("js code: " . $wmc_string);
return $wmc_string;
}
}
More information about the Mapbender_commits
mailing list