[Mapbender-commits] r1751 - trunk/mapbender/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Oct 26 07:33:58 EDT 2007


Author: christoph
Date: 2007-10-26 07:33:57 -0400 (Fri, 26 Oct 2007)
New Revision: 1751

Modified:
   trunk/mapbender/http/javascripts/mod_insertLayerPreviewIntoDb.php
Log:
latest version, let's see if it's usable at all

Modified: trunk/mapbender/http/javascripts/mod_insertLayerPreviewIntoDb.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_insertLayerPreviewIntoDb.php	2007-10-26 11:28:39 UTC (rev 1750)
+++ trunk/mapbender/http/javascripts/mod_insertLayerPreviewIntoDb.php	2007-10-26 11:33:57 UTC (rev 1751)
@@ -1,5 +1,5 @@
 <?php
-#$Id: mod_insertWmcIntoDb.php 359 2006-10-09 16:41:18Z christoph $
+#$Id: mod_insertLayerPreviewIntoDb.php 915 2007-09-19 13:57:27Z baudson $
 #$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_insertWmcIntoDb.php,v 1.19 2006/03/09 14:02:42 uli_rothstein Exp $
 # Copyright (C) 2002 CCGIS 
 #
@@ -18,41 +18,48 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 session_start();
-include("../../conf/mapbender.conf");
+include(dirname(__FILE__)."/../../conf/mapbender.conf");
+include(dirname(__FILE__)."/../../conf/geoportal.conf");
 require_once(dirname(__FILE__)."/../classes/class_administration.php");
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+
+function savePreview($fileName, $fileContent) {
+	if (strlen($fileContent) > 0) {
+		$fileMapImg = fopen("..".LAYER_PREVIEW_URL."/".$fileName, 'w+');
+		if ($fileMapImg) {
+			rewind($fileMapImg);
+			$bytesWritten = fwrite($fileMapImg, $fileContent);
+			if ($bytesWritten) {
+				fflush($fileMapImg);
+				ftruncate($fileMapImg, ftell($fileMapImg));
+				fclose($fileMapImg);
+				return true;
+			}
+			$e = new mb_exception("..".LAYER_PREVIEW_URL."/".$fileName.": 0 bytes written.");
+			return false;
+		}
+		$e = new mb_exception("..".LAYER_PREVIEW_URL."/".$fileName.": could not open.");
+		return false;
+	}
+	$e = new mb_exception($fileName.": no file content.");
+	return false;
+}
+
+
 $gui_id = $_REQUEST["gui_id"];
 
 $con = db_connect($DBSERVER,$OWNER,$PW);
 db_select_db(DB,$con);
 
-
-function escByteA($binData) {
-   $search = array();
-   $replace = array();
-   array_push($search, chr(92)); 
-   array_push($replace, '\\134'); 
-   array_push($search, chr(0)); 
-   array_push($replace, '\\000'); 
-   array_push($search, chr(39)); 
-   array_push($replace, '\\047'); 
-   array_push($search, chr(13)); 
-   array_push($replace, '\\015'); 
-   array_push($search, chr(10)); 
-   array_push($replace, '\\012'); 
-
-  $binData = preg_replace($search, $replace, $binData);
-  return $binData;
-}
-
-
 if ($_POST["data"]) {
 	$d = explode("____", $_POST["data"]);	
 
 	$mapurl = $d[0];
 	$legendurl = $d[1];
 	
-	$mapurl = mb_eregi_replace("(&width=)[0-9]+($|[^0-9])", "\\1200\\2", $mapurl);
-	$mapurl = mb_eregi_replace("(&height=)[0-9]+($|[^0-9])", "\\1200\\2", $mapurl);
+	$mapurl = eregi_replace("(&width=)[0-9]+($|[^0-9])", "\\1".LAYER_PREVIEW_WIDTH."\\2", $mapurl);
+	$mapurl = eregi_replace("(&height=)[0-9]+($|[^0-9])", "\\1".LAYER_PREVIEW_HEIGHT."\\2", $mapurl);
 		
 	$adm = new administration();
 	$layer_id = $_SESSION['layer_preview'];
@@ -60,9 +67,19 @@
 		 echo "<script>alert('Could not find wms: ".$wms_getmap."');</script>";
 	}
 	else {
-		$map_img = file_get_contents($mapurl);	
-		$legend_img = file_get_contents($legendurl);	
-
+		session_write_close();
+		$con1 = new connector($mapurl);
+		$fileNameMap = $layer_id."_layer_map_preview.png";
+		$fileContentMap = $con1->file;
+		$success = savePreview($fileNameMap, $fileContentMap);
+		if (!$success) $fileNameMap = "";
+		
+		$con2 = new	connector($legendurl);
+		$fileNameLegend = $layer_id."_layer_legend_preview.png";
+		$fileContentLegend = $con2->file;
+		$success = savePreview($fileNameLegend, $fileContentLegend);
+		if (!$success) $fileNameLegend = "";
+ 		
 //		$rlp_4326_box = array(6.10988942079081,48.987785376052,8.58790010810365,50.9273496139233);
 		$rlp_4326_box = array(6.05,48.9,8.6,50.96);
 		
@@ -118,8 +135,11 @@
 			if ($new_miny < -90) $rlp_4326_box[1] = -90; else $rlp_4326_box[1] = $new_miny;
 			if ($new_maxy > 90) $rlp_4326_box[3] = 90; else $rlp_4326_box[3] = $new_maxy;
 		}
-//		echo "<script>prompt('link', 'http://212.79.172.107/cgi-bin/mapserv?map=/data/umn/service_layer.map&VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=rlp,ows_layer&STYLES=&SRS=EPSG:4326&BBOX=".$rlp_4326_box[0].",".$rlp_4326_box[1].",".$rlp_4326_box[2].",".$rlp_4326_box[3]."&WIDTH=600&HEIGHT=600&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_inimage&layer_id=".$extent_layer_id."');</script>";
-		$extent_img = file_get_contents("http://212.79.172.107/cgi-bin/mapserv?map=/data/umn/service_layer.map&VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=rlp,ows_layer&STYLES=&SRS=EPSG:4326&BBOX=".$rlp_4326_box[0].",".$rlp_4326_box[1].",".$rlp_4326_box[2].",".$rlp_4326_box[3]."&WIDTH=120&HEIGHT=120&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_inimage&layer_id=".$extent_layer_id);
+		$con3 = new connector(LAYER_EXTENT_URL."VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=rlp,ows_layer&STYLES=&SRS=EPSG:4326&BBOX=".$rlp_4326_box[0].",".$rlp_4326_box[1].",".$rlp_4326_box[2].",".$rlp_4326_box[3]."&WIDTH=120&HEIGHT=120&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_inimage&layer_id=".$extent_layer_id);
+		$fileNameExtent = $layer_id."_layer_extent_preview.png";
+		$fileContentExtent = $con3->file;
+		$success = savePreview($fileNameExtent, $fileContentExtent);
+		if (!$success) $fileNameExtent = "";
 
 		$sql = "SELECT * FROM layer_preview WHERE fkey_layer_id = $1";
 		$v = array($layer_id);
@@ -127,17 +147,16 @@
 		$res = db_prep_query($sql, $v, $t);
 		$row = db_fetch_array($res);
 		if ($row['fkey_layer_id'] == $layer_id) {
-			$sql = "UPDATE layer_preview SET layer_map_preview = $1, layer_extent_preview = $2, layer_legend_preview = $3 WHERE fkey_layer_id = $4";
-			$v = array( escByteA($map_img),  escByteA($extent_img), escByteA($legend_img), $layer_id);
+			$sql = "UPDATE layer_preview SET layer_map_preview_filename = $1, layer_extent_preview_filename = $2, layer_legend_preview_filename = $3 WHERE fkey_layer_id = $4";
+			$v = array($fileNameMap, $fileNameExtent, $fileNameLegend, $layer_id);
 			$t = array('s', 's', 's', 'i');
 		}
 		else {
-			$sql = "INSERT INTO layer_preview (fkey_layer_id, layer_map_preview, layer_extent_preview, layer_legend_preview) VALUES ($1, $2, $3, $4)";
-			$v = array($layer_id, escByteA($map_img), escByteA($extent_img), escByteA($legend_img));
+			$sql = "INSERT INTO layer_preview (fkey_layer_id, layer_map_preview_filename, layer_extent_preview_filename, layer_legend_preview_filename) VALUES ($1, $2, $3, $4)";
+			$v = array($layer_id, $fileNameMap, $fileNameExtent, $fileNameLegend);
 			$t = array('i', 's', 's', 's');
 		}
 			
-			
 		$res = db_prep_query($sql, $v, $t);
 		if (db_error()) {
 			 echo "<script>alert(\"Error while saving layer preview: ".addslashes(db_error())."\");</script>";



More information about the Mapbender_commits mailing list