[Mapbender-commits] r2514 - in branches/beck_dev/mapbender/http: classes frames

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Jun 19 07:47:30 EDT 2008


Author: christoph
Date: 2008-06-19 07:47:30 -0400 (Thu, 19 Jun 2008)
New Revision: 2514

Added:
   branches/beck_dev/mapbender/http/classes/class_element.php
Modified:
   branches/beck_dev/mapbender/http/classes/class_gui.php
   branches/beck_dev/mapbender/http/frames/index.php
Log:
added class element

Added: branches/beck_dev/mapbender/http/classes/class_element.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_element.php	                        (rev 0)
+++ branches/beck_dev/mapbender/http/classes/class_element.php	2008-06-19 11:47:30 UTC (rev 2514)
@@ -0,0 +1,246 @@
+<?php
+# $Id: class_bbox.php 1965 2008-01-15 08:24:29Z 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.
+
+session_start();
+
+define("ELEMENT_PATTERN", "/sessionID/");
+
+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);
+
+class Element {
+	
+	var $guiId;
+	var $id;
+	var $pos;
+	var $isPublic;
+	var $comment;
+	var $title;
+	var $element;
+	var $src;
+	var $attributes;
+	var $left;
+	var $top;
+	var $width;
+	var $height;
+	var $zIndex;
+	var $moreStyles;
+	var $content;
+	var $closeTag;
+	var $jsFile;
+	var $mbMod;
+	var $target;
+	var $requires;
+	var $helpUrl;
+	
+	public function __contruct() {
+		
+	}
+	
+	public function select ($id, $applicationId) {
+		$sql = "SELECT fkey_gui_id, e_id, e_pos, e_public, e_comment, e_public, ".
+				"gettext($1, e_title) as 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 e_id = $2 AND " .
+				"fkey_gui_id = $3 LIMIT 1";
+		$v = array ($_SESSION["mb_lang"], $id, $applicationId);
+		$t = array ("s", "s", "s");
+		$res = db_prep_query($sql, $v, $t);
+		$row = db_fetch_array($res);
+		if ($row) {
+			$this->guiId = $applicationId;
+			$this->id = $row["e_id"];
+			$this->pos = $row["e_pos"];
+			$this->isPublic = $row["e_public"];
+			$this->comment = $row["e_comment"];
+			$this->title = $row["e_title"];
+			$this->element = $row["e_element"];
+			$this->src = $row["e_src"];
+			$this->attributes = $row["e_attributes"];
+			$this->left = $row["e_left"];
+			$this->top = $row["e_top"];
+			$this->width = $row["e_width"];
+			$this->height = $row["e_height"];
+			$this->zIndex = $row["e_z_index"];
+			$this->moreStyles = $row["e_more_styles"];
+			$this->content = $row["e_content"];
+			$this->closeTag = $row["e_closetag"];
+			$this->jsFile = $row["e_js_file"];
+			$this->mbMod = $row["e_mb_mod"];
+			$this->target = $row["e_target"];
+			$this->requires = $row["e_requires"];
+			$this->helpUrl = $row["e_url"];
+			return true;
+		}
+		return false;		
+	}
+	
+	public function __toString () {
+		return $this->toHtml();
+	}
+	
+	public function getJavaScriptModules () {
+		$jsArray = array();
+		if ($this->mbMod != "") {
+			$moduleArray = explode(",", $this->mbMod);
+			for ($i = 0; $i < count($moduleArray); $i++) {
+				$currentFile = dirname(__FILE__) . "/../javascripts/" . trim($moduleArray[$i]);
+				if (file_exists($currentFile)) {
+					array_push($jsArray, $currentFile);
+				}
+				else {
+					$e = new mb_exception("Javascript module not found: " . $currentFile);
+				}
+			}
+		}
+		return $jsArray;
+	}
+	
+	public function toHtmlArray () {
+		if ($this->isPublic) {
+			return array($this->getHtmlOpenTag(), $this->getHtmlContent(), $this->getHtmlCloseTag());	
+		}
+		return array("", "", "");
+	}
+	
+	public function toHtml () {
+		if ($this->isPublic) {
+			return implode("", $this->toHtmlArray());
+		}
+		return "";
+	}
+
+	private function getHtmlOpenTag () {
+		$openTag = "";
+		
+		if ($this->id) {
+			// tag name
+			$openTag .= "<" . $this->element . " ";
+			
+			// id and name
+			$openTag .= "id='" . $this->id . "' name='" . $this->id . "' ";
+			
+			// attributes
+			if ($this->attributes) {
+				$openTag .= stripslashes($this->replaceSessionStringByUrlParameters($this->attributes)) . " ";
+			}
+			
+			// title
+			if ($this->title) {
+				$openTag .= "title='" . $this->title . "' ";
+			}
+			
+			// src
+			if ($this->src) {
+   				$openTag .= "src = '" . $this->replaceSessionStringByUrlParameters($this->src);
+
+				// for iframes which are not "loadData", 
+				// add additional parameters
+				if ($this->closeTag == "iframe" && $this->id != "loadData") {
+					if(mb_strpos($this->src, "?")) {
+						$openTag .= "&";
+					}
+					else {
+	      				$openTag .= "?";
+      				}
+	      			$openTag .= "e_id_css=" . $this->id . "&" .
+	      					 "e_id= " . $this->id . "&" .
+	      					 "e_target=" . $this->target . "&" .
+	      					 $this->getUrlParameters();
+				}
+   				$openTag .= "' ";
+			}
+			
+			// style
+			$openTag .= " style = '";
+			if ($this->top != "" && $this->left != "") {
+				$openTag .= "position:absolute;" .
+						 "left:" . $this->left . ";" .
+						 "top:" . $this->top . ";";
+			}
+			if ($this->width != "" && $this->height != "") {
+				$openTag .= "width:" . $this->width . ";" .
+						 "height:" . $this->height . ";";
+			}
+			if ($this->zIndex) {
+		    	$openTag .= "z-index:" . $this->zIndex . ";";
+			}
+			if ($this->moreStyles) {
+		    	$openTag .= $this->moreStyles;
+			}
+			$openTag .= "'>";
+
+			if ($this->element == "body" && USE_LOAD_MESSAGE) {
+				$htmlWhileLoading = "<img src='../img/indicator_wheel.gif'>&nbsp;" . 
+					"<b>Ma<font color='#0000CE'>p</font><font color='#C00000'>b</font>ender " . 
+					MB_VERSION_NUMBER . " " . strtolower(MB_VERSION_APPENDIX) . "</b>..." .
+					"loading application '" . $this->guiId . "'";
+	
+				$openTag .= "<div id='loading_mapbender' " .
+								"style='position:absolute;top:100;left:100'>" . 
+								$htmlWhileLoading . "</div>" . 
+								"<div id='complete_mapbender' " .
+								"style='display:none'>";
+			}
+		}
+		return $openTag;
+	}
+	
+	private function getHtmlContent () {
+		$htmlContent = "";
+		if ($this->content != "") {
+			$htmlContent .= stripslashes($this->content);
+		}
+		return $htmlContent;
+	}
+	
+	private function getHtmlCloseTag () {
+		if ($this->element == "body" && USE_LOAD_MESSAGE) {
+			return "</div></body>";
+		}
+		if ($this->closeTag != "") {
+			return "</" . $this->closeTag . ">";
+		}
+		return "";
+	}
+	
+	private function getUrlParameters () {
+		$urlParameters = SID;
+		if (isset($this->guiId)) {
+			$urlParameters .= "&guiID=" . $this->guiId;
+		}
+		if (isset($this->id)) {
+			$urlParameters .= "&elementID=" . $this->id;
+		}
+		return $urlParameters;
+	}
+	
+	private function replaceSessionStringByUrlParameters ($string) {
+		$urlParameters = $this->getUrlParameters();
+		return preg_replace(ELEMENT_PATTERN, $urlParameters, $string);
+	}
+	
+}
+
+
+?>
\ No newline at end of file

Modified: branches/beck_dev/mapbender/http/classes/class_gui.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_gui.php	2008-06-19 10:23:31 UTC (rev 2513)
+++ branches/beck_dev/mapbender/http/classes/class_gui.php	2008-06-19 11:47:30 UTC (rev 2514)
@@ -18,6 +18,7 @@
 # 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_element.php");
 
 $con = db_connect($DBSERVER,$OWNER,$PW);
 db_select_db(DB,$con);
@@ -27,9 +28,51 @@
  */
 class gui {
 
-	public function __construct () {
+	var $id;
+	var $elementArray = array();
+	
+	public function __construct ($id) {
+		if ($id) {
+			$this->id = $id;
+			$this->elementArray = $this->selectElements();
+		}
 	}
 
+	public function selectElements () {
+		$sql = "SELECT e_id FROM gui_element WHERE fkey_gui_id = $1 " . 
+				"ORDER BY e_pos";
+		$v = array($this->id);
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
+		$elementArray = array();
+		while ($row = db_fetch_array($res)) {
+			array_push($elementArray, $row[0]);
+		}
+
+		$this->elementArray = array();
+		for ($i = 0; $i < count($elementArray); $i++) {
+			$currentElement = new Element();
+			$currentElement->select($elementArray[$i], $this->id);
+			array_push($this->elementArray, $currentElement);
+		}
+		return $this->elementArray;
+	}
+
+	public function toHtml () {
+		$htmlString = "";
+		$htmlString .= $this->elementsToHtml();
+		return $htmlString;
+	}
+
+	public function getJavaScriptModules () {
+		$jsArray = array();
+		for ($i = 0; $i < count($this->elementArray); $i++) {
+			$currentElement = $this->elementArray[$i];
+			array_merge($jsArray, $currentElement->getJavaScriptModules());			
+		}
+		return $jsArray;
+	}
+	
  	/**
  	 * Checks if a GUI with a given ID exists in the database
  	 * 
@@ -221,5 +264,33 @@
 	      return false;
 		}
 	}
+
+	private function elementsToHtml () {
+		$bodyStringArray = array();
+		$elementString = "";
+		for ($i = 0; $i < count($this->elementArray); $i++) {
+			$currentElement = $this->elementArray[$i];
+			if ($currentElement->id != "body") {
+				$elementString .= $currentElement->toHtml();
+			}
+			else {
+				$bodyStringArray = $currentElement->toHtmlArray();
+			}
+		}
+		$elementString .= "<form id='sendData' name='sendData' action='' " .
+						  "method='POST' target='loadData' " .
+						  "style='position:absolute;left:800px'>" .
+						  "<input type='hidden' name='data'></form>";
+
+		if (count($bodyStringArray) == 3) {
+			$elementString = $bodyStringArray[0] . 
+				$bodyStringArray[1] .
+				$elementString . 
+				$bodyStringArray[2];
+			
+		}
+		return $elementString;			
+	}
+	
 }
 ?>
\ No newline at end of file

Modified: branches/beck_dev/mapbender/http/frames/index.php
===================================================================
--- branches/beck_dev/mapbender/http/frames/index.php	2008-06-19 10:23:31 UTC (rev 2513)
+++ branches/beck_dev/mapbender/http/frames/index.php	2008-06-19 11:47:30 UTC (rev 2514)
@@ -21,7 +21,11 @@
 mb_internal_encoding("UTF-8");
 require("../php/mb_validateSession.php");
 require_once(dirname(__FILE__)."/../classes/class_locale.php");
+require_once(dirname(__FILE__)."/../classes/class_gui.php");
 
+$_SESSION["mb_user_gui"] = $gui_id;
+$localeObj = new Mb_locale($_SESSION["mb_lang"]);
+
 //
 // check if user is allowed to access current GUI; 
 // if not, return to login screen
@@ -31,23 +35,6 @@
 	header("Location: ".LOGIN);
 	die();
 }
-
-#$e = new mb_notice("index.php: arguments: GML: " . $_SESSION["GML"]);
-#$e = new mb_notice("index.php: arguments: Zoom to layer: " . $_REQUEST["zoomToLayer"]);
-#$e = new mb_notice("index.php: arguments: portal_services: " . $_REQUEST["portal_services"]);
-#$e = new mb_notice("index.php: arguments: portal_services_wfs: " . $_REQUEST["portal_services_wfs"]);
-#$e = new mb_notice("index.php: arguments: layer_preview: " . $_REQUEST["layer_preview"]);
-
-$pattern = "/sessionID/";
-
-$_SESSION["mb_user_gui"] = $gui_id;
-
-$localeObj = new Mb_locale($_SESSION["mb_lang"]);
-
-$htmlWhileLoading = "<img src='../img/indicator_wheel.gif'>&nbsp;" . 
-	"<b>Ma<font color='#0000CE'>p</font><font color='#C00000'>b</font>ender " . 
-	MB_VERSION_NUMBER . " " . strtolower(MB_VERSION_APPENDIX) . "</b>..." .
-	"loading application '" . $gui_id . "'";
 ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
@@ -61,11 +48,9 @@
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="expires" content="0">
+<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET;?>">
+<title><?php echo  $gui_id;?> - presented by Mapbender</title>
 <?php
-echo '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">';	
-?>
-<title><?php  echo  $gui_id;?> - presented by Mapbender</title>
-<?php
 $sql = "SELECT * FROM gui_element_vars WHERE fkey_e_id = 'body' AND fkey_gui_id = $1 and var_type='file/css'";
 $v = array($gui_id);
 $t = array('s');
@@ -89,89 +74,11 @@
 ?>
 -->
 </style>
-<?php
-/*********************************************/
-$frame = "";
-/*********************************************/
-
-echo "<script type='text/javascript' src='../javascripts/core.php'></script>";
-?>
+<script type='text/javascript' src='../javascripts/core.php'></script>
 </head>
 <?php
-$sql = "SELECT fkey_gui_id,e_id,e_pos,e_public,e_comment,gettext($1, e_title) as e_title, e_element,";
-$sql .= "e_src,e_attributes,e_left,e_top,e_width,e_height,e_z_index,e_more_styles,";
-$sql .= "e_content,e_closetag,e_js_file,e_mb_mod,e_target,e_requires,e_url FROM gui_element WHERE e_public = 1 AND fkey_gui_id = $2 ORDER BY e_pos";
-$v = array($_SESSION["mb_lang"], $gui_id);
-$t = array('s', 's');
-$res = db_prep_query($sql,$v,$t);
-$i = 0;
-while(db_fetch_row($res)){
-	$replacement = $urlParameters."&elementID=".db_result($res,$i,"e_id");
-	echo "<".db_result($res,$i,"e_element")." ";
-	if(db_result($res,$i,"e_id") != ""){
-		echo " id='".db_result($res,$i,"e_id")."'";
-		echo " name='".db_result($res,$i,"e_id")."'";
-	}
-	if(db_result($res,$i,"e_attributes") != ""){
-		echo " ".stripslashes(preg_replace($pattern,$replacement,db_result($res,$i,"e_attributes")));
-	}
-	if(db_result($res,$i,"e_title") != ""){
-		echo " title='".db_result($res,$i,"e_title")."' ";
-	}
-	if(db_result($res,$i,"e_src") != ""){
-		if(db_result($res,$i,"e_closetag") == "iframe" && db_result($res,$i,"e_id") != 'loadData'){
-      		echo " src = '".preg_replace($pattern,$replacement,db_result($res,$i,"e_src"));
-				if(mb_strpos(db_result($res,$i,"e_src"), "?")) {
-					echo "&";
-				}
-				else {
-	      			echo "?";
-      			}
-      			echo "e_id_css=".db_result($res,$i,"e_id")."&e_id=".db_result($res,$i,"e_id") . 
-					"&e_target=".db_result($res,$i,"e_target").
-					"&" . $urlParameters . "'";
-		}
-		else{
-			echo " src = '".preg_replace($pattern,$replacement,db_result($res,$i,"e_src"))."'";
-		}
-	}
-	echo " style = '";
-	if(db_result($res,$i,"e_left") != "" && db_result($res,$i,"e_top") != ""){
-		echo "position:absolute;";
-		echo "left:".db_result($res,$i,"e_left").";";
-		echo "top:".db_result($res,$i,"e_top").";";
-	}
-	if(db_result($res,$i,"e_width") != "" && db_result($res,$i,"e_height") != ""){
-		echo "width:".db_result($res,$i,"e_width").";";
-		echo "height:".db_result($res,$i,"e_height").";";
-	}
-	if(db_result($res,$i,"e_z_index") != ""){
-    	echo "z-index:".db_result($res,$i,"e_z_index").";";
-	}
-	if(db_result($res,$i,"e_more_styles") != ""){
-    	echo db_result($res,$i,"e_more_styles");
-	}
-	echo "' >";
-	if (db_result($res,$i,"e_element") == "body" && USE_LOAD_MESSAGE) {
-		echo "<div id='loading_mapbender' style='position:absolute;top:100;left:100'>" . 
-			$htmlWhileLoading . "</div>" . 
-			"<div id='complete_mapbender' style='display:none'>";
-	}
-	if(db_result($res,$i,"e_content") != ""){
-		echo " ".stripslashes(db_result($res,$i,"e_content"));
-	}
-	if(db_result($res,$i,"e_closetag") != "" && db_result($res,$i,"e_closetag") != "body"){
-		echo "</".db_result($res,$i,"e_closetag").">";
-	}
-	$i++;
-}
-?>
-<form id='sendData' name='sendData' action='' method='POST' target='loadData' style='position:absolute;left:800px'>
-<input type='hidden' name='data'>
-</form>
-<?php
-#echo "<script type='text/javascript' src='../javascripts/map.php?gui_id=".$_REQUEST["gui_id"]."&zoomToLayer=".$_REQUEST["zoomToLayer"]."&portal_services=".$_REQUEST['portal_services']."&portal_services_wfs=".$_REQUEST['portal_services_wfs']."&layer_preview=".$_REQUEST['layer_preview']."&".strip_tags(SID)."&mb_myBBOX=".$_REQUEST["mb_myBBOX"]."'></script>";
+$currentApplication = new gui($gui_id);
+echo $currentApplication->toHtml();
 echo "<script type='text/javascript' src='../javascripts/map.php?".$urlParameters."&mb_myBBOX=".$_REQUEST["mb_myBBOX"]."'></script>";
 ?>
-</div></body>
 </html>
\ No newline at end of file



More information about the Mapbender_commits mailing list