svn commit: r330 - trunk/mapbender/http/classes/class_wms.php

uli at osgeo.org uli at osgeo.org
Tue May 23 10:45:52 EDT 2006


Author: uli
Date: 2006-05-23 14:45:52+0000
New Revision: 330

Modified:
   trunk/mapbender/http/classes/class_wms.php

Log:
update wms in process

Modified: trunk/mapbender/http/classes/class_wms.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/classes/class_wms.php?view=diff&rev=330&p1=trunk/mapbender/http/classes/class_wms.php&p2=trunk/mapbender/http/classes/class_wms.php&r1=329&r2=330
==============================================================================
--- trunk/mapbender/http/classes/class_wms.php	(original)
+++ trunk/mapbender/http/classes/class_wms.php	2006-05-23 14:45:52+0000
@@ -21,6 +21,7 @@
 require_once("class_connector.php");
   
 class wms {
+  var $lastURL;
   var $wms_id;
   var $wms_status;
   var $wms_version;
@@ -31,6 +32,7 @@
   var $wms_getmap;
   var $wms_getfeatureinfo;
   var $wms_getlegendurl;
+  var $wms_upload_url;
 
   var $data_type = array(); 
   var $data_format = array();
@@ -62,7 +64,7 @@
 	}
 	
 	$this->wms_getcapabilities_doc = $data;
-	
+	$this->wms_upload_url = $url;
 	if(!$data){
 		$this->wms_status = false;
 	}
@@ -512,7 +514,7 @@
 	}
   }
 function displayWMS(){
-	echo "id: " . $this->wms_id . " <br>";
+	echo "<br>id: " . $this->wms_id . " <br>";
 	echo "version: " . $this->wms_version . " <br>";
 	echo "title: " . $this->wms_title . " <br>";
 	echo "abstract: " . $this->wms_abstract . " <br>";
@@ -638,284 +640,327 @@
 * this function exports the information from the xml to the mapbender database 
 */
 function writeObjInDB($gui_id){
-	global $DBSERVER,$DB,$OWNER,$PW;
-	$con = db_connect($DBSERVER,$OWNER,$PW);
-	db_select_db($DB,$con);
-	if(SYS_DBTYPE=="pgsql") {
-		$sql = "SET AUTOCOMMIT=1;";
-	}
-	else {
-		$sql = "SET AUTOCOMMIT=1";	
-	}
-	$res = db_query($sql);
-	$sql = "BEGIN";
-	$res = db_query($sql);
-
+	$this->checkObj();
+	db_begin();
 
 	# TABLE wms
-	//echo "<pre>" . $this->wms_getcapabilities_doc . "</pre>";
-	$sql = "INSERT INTO wms (wms_version, wms_title, wms_abstract, wms_getcapabilities, wms_getmap, wms_getfeatureinfo, wms_getlegendurl, wms_getcapabilities_doc) ";
-	$sql .= "VALUES(";
-		$sql .= "'" . $this->wms_version ."', ";
-		$sql .= "'" . db_escape_string(str_replace("'","",$this->wms_title)) ."', ";
-		$sql .= "'" . db_escape_string(str_replace("'","",$this->wms_abstract)) .  "', ";
-		$sql .= "'" . $this->wms_getcapabilities ."', ";
-		$sql .= "'" . $this->wms_getmap . "', ";
-		$sql .= "'". $this->wms_getfeatureinfo . "', ";
-		$sql .= "'". $this->wms_getlegendurl . "', ";
-		
-		#$newgetcapdoc=str_replace("'", "\"", $this->wms_getcapabilities_doc);
-		#$newgetcapdoc=str_replace("\"", "\\\"", $newgetcapdoc);
-		#echo "<br><br>".$newgetcapdoc."<br><br>";
-		$sql .= "'". addslashes($this->wms_getcapabilities_doc) . "'";
-		#$sql .= "''";
-		$sql .= ");";
-		#echo "<br>". $sql."<br>";
-	$this->transaction($sql);
+	$sql = "INSERT INTO wms (wms_version, wms_title, wms_abstract, wms_getcapabilities, wms_getmap, ";
+	$sql.= "wms_getfeatureinfo, wms_getlegendurl, wms_getcapabilities_doc,wms_upload_url) ";
+	$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9)";
+	$v = array($this->wms_version,$this->wms_title,$this->wms_abstract,$this->wms_getcapabilities,
+		$this->wms_getmap,$this->wms_getfeatureinfo,$this->wms_getlegendurl,$this->wms_getcapabilities_doc,
+		$this->wms_upload_url);
+	$t = array('s','s','s','s','s','s','s','s','s');
+	$res = db_prep_query($sql,$v,$t);
+	if(!$res){
+		db_rollback();
+	}
+	
 	$myWMS = db_insert_id($con,'wms', 'wms_id');
 	
-	# TABLE layer
+	# TABLE layer and gui_layer
 	
 	for($i=0; $i<count($this->objLayer); $i++){
-		$sql = "INSERT INTO layer(fkey_wms_id, layer_pos, layer_parent, layer_name, layer_title, layer_dataurl, layer_queryable, layer_minscale, layer_maxscale,layer_metadataurl) ";
-		$sql .= "VALUES(";
-			$sql .= $myWMS . ",";
-			if($this->objLayer[$i]->layer_id != null){
-				$sql .= $this->objLayer[$i]->layer_id . ",";
-			}
-			else {
-				$sql .= "'0',";
-			}
-			$sql .= "'".$this->objLayer[$i]->layer_parent."',";
-			$sql .= "'".$this->objLayer[$i]->layer_name."',";
-			$sql .= "'".$this->objLayer[$i]->layer_title."',";
-			$sql .= "'".$this->objLayer[$i]->layer_dataurl_href."',";
-			$sql .= $this->objLayer[$i]->layer_queryable . ",";
-			$sql .= $this->objLayer[$i]->layer_minscale . ",";
-			$sql .= $this->objLayer[$i]->layer_maxscale. ",";
-			$sql .= "'".$this->objLayer[$i]->layer_metadataurl."'";
-		$sql .= ")";
-		# save the id of each layer: set param2 true
-		$this->transaction($sql);
-		$this->objLayer[$i]->db_id = db_insert_id($con, 'layer','layer_id');
+		$this->insertLayer($i,$myWMS,$gui_id);
+		$this->insertGuiLayer($i,$myWMS,$gui_id);
+	}	
 		
-		for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
-			$sql = "INSERT INTO layer_epsg (fkey_layer_id, epsg, minx, miny, maxx, maxy) ";
-			$sql .= "VALUES("; 
-			$sql .= $this->objLayer[$i]->db_id . ", "; 
-			$sql .= "'" .$this->objLayer[$i]->layer_epsg[$j][epsg]. "', ";
-			$sql .= $this->objLayer[$i]->layer_epsg[$j][minx] . ", ";
-			$sql .= $this->objLayer[$i]->layer_epsg[$j][miny] . ", ";
-			$sql .= $this->objLayer[$i]->layer_epsg[$j][maxx]. ", ";
-			$sql .= $this->objLayer[$i]->layer_epsg[$j][maxy];
-			$sql .= ")";
-			$this->transaction($sql);
-		}
-		# TABLE layer_style for each layer
-		for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
-			$sql = "INSERT INTO layer_style (fkey_layer_id, name, title, legendurl, legendurlformat) ";
-			$sql .= "VALUES(";
-			$sql .= $this->objLayer[$i]->db_id .", ";
-			$sql .= "'".$this->objLayer[$i]->layer_style[$j]["name"]."', ";
-			$sql .= "'".$this->objLayer[$i]->layer_style[$j]["title"]."', ";
-			$sql .= "'".$this->objLayer[$i]->layer_style[$j]["legendurl"]."', ";
-			$sql .= "'".$this->objLayer[$i]->layer_style[$j]["legendurlformat"]."'";
-			$sql .= ");";
-			$this->transaction($sql);
-		}
-	}
-	
 	
-	for($i=0; $i<count($this->wms_srs);$i++){
-		$sql ="INSERT INTO wms_srs (fkey_wms_id, wms_srs) ";		
-		$sql .= " VALUES(".$myWMS.",'".strtoupper($this->wms_srs[$i])."');";		
-		$this->transaction($sql);
-	}	
+	#TABLE wms_srs
+	$this->insertSRS($myWMS);	
 	
-	# TABLE wms_format
+	# TABLE wms_format	
+	$this->insertFormat($myWMS);	
 		
-	for($i=0; $i<count($this->data_type);$i++){
-		$sql ="INSERT INTO wms_format (fkey_wms_id, data_type, data_format) ";
-		$sql .= " VALUES(".$myWMS.",'".$this->data_type[$i]."','".$this->data_format[$i]."');";
-		$this->transaction($sql);
-	}
-	
 	# TABLE gui_wms
 	
-	$sql ="SELECT MAX(gui_wms_position) AS pos FROM gui_wms WHERE fkey_gui_id='".$gui_id."';";
-	$res = db_query($sql);
+	$sql ="SELECT MAX(gui_wms_position) AS pos FROM gui_wms WHERE fkey_gui_id = $1";
+	$v = array($gui_id);
+	$t = array('s');
+	$res = db_prep_query($sql,$v,$t);
 	if(db_result($res, 0,"pos") > -1){
 		$position = db_result($res, 0,"pos") + 1;
 	} else{ $position = 0; }
 	
 	$sql ="INSERT INTO gui_wms (fkey_gui_id, fkey_wms_id, gui_wms_position, gui_wms_mapformat, ";
 	$sql .= "gui_wms_featureinfoformat, gui_wms_exceptionformat, gui_wms_epsg)";
-	$sql .= "VALUES(";
-		$sql .= "'" . $gui_id . "', ";
-		$sql .= $myWMS . ", ";
-		$sql .= $position .", ";
-		$sql .= "'" . $this->gui_wms_mapformat ."', ";
-		$sql .= "'" . $this->gui_wms_featureinfoformat ."', ";
-		$sql .= "'". $this->gui_wms_exceptionformat ."', ";
-		$sql .= "'" . $this->gui_wms_epsg ."'";
-	$sql .= ");";
-	$this->transaction($sql);
-		
-
+	$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7)";
+	$v = array($gui_id,$myWMS,$position,$this->gui_wms_mapformat,$this->gui_wms_featureinfoformat,
+			$this->gui_wms_exceptionformat,$this->gui_wms_epsg
+			);
+	$t = array('s','i','i','s','s','s','s');
+	$res = db_prep_query($sql,$v,$t);
+	if(!$res){
+		db_rollback();	
+	}
+	db_commit();
+}
+function insertLayer($i,$myWMS){
+	$sql = "INSERT INTO layer(fkey_wms_id, layer_pos, layer_parent, layer_name, layer_title, ";
+	$sql .= " layer_queryable, layer_minscale, layer_maxscale,layer_dataurl,layer_metadataurl) ";
+	$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)";
+	if($this->objLayer[$i]->layer_id != null){
+		$tmpPos =  $this->objLayer[$i]->layer_id;
+	}
+	else {
+		$tmpPos .= 0;
+	}
+	if(empty($this->objLayer[$i]->layer_parent)){
+		$this->objLayer[$i]->layer_parent = '""';
+	}
+	$v = array($myWMS,$tmpPos,$this->objLayer[$i]->layer_parent,$this->objLayer[$i]->layer_name,
+			$this->objLayer[$i]->layer_title,
+			$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,
+			$this->objLayer[$i]->layer_maxscale,$this->objLayer[$i]->layer_dataurl_href,$this->objLayer[$i]->layer_metadataurl		
+		);
+	$t = array('i','i','s','s','s','i','i','i','s','s');
+	$res = db_prep_query($sql,$v,$t);
+	if(!$res){
+		db_rollback();	
+	}		
+	
+	# save the id of each layer: set param2 true		
+	$this->objLayer[$i]->db_id = db_insert_id($con, 'layer','layer_id');
+	$this->insertLayerEPSG($i);
+	
+	# TABLE layer_style for each layer
+	$this->insertLayerStyle($i);
+	
+}
+function insertGuiLayer($i,$myWMS,$gui_id){
 	# table gui_layer
-	$sql="Select * from layer where fkey_wms_id=".$myWMS.";";
-	$res_layer= db_query($sql);
-	$count=0;
-	while($row = db_fetch_array($res_layer)){
-		$sql = "INSERT INTO gui_layer (fkey_gui_id, fkey_layer_id, gui_layer_wms_id, ";
-		$sql .= "gui_layer_status, gui_layer_selectable, gui_layer_visible, gui_layer_queryable, ";
-		$sql .= "gui_layer_querylayer,gui_layer_minscale,gui_layer_maxscale, gui_layer_priority) ";
-		$sql .= "VALUES(";
-		$sql .= "'".$gui_id."', "; 
-		$sql .= $row['layer_id'].", ";
-		$sql .= $myWMS . ", ";
-		$sql .= "1, ";
-		$sql .= "1, ";
-		$sql .= "1, ";
-		$sql .= $row['layer_queryable'] . ", ";
-		$sql .= $row['layer_queryable'] . ", ";
-		$sql .= $row['layer_minscale'] . ", ";
-		$sql .= $row['layer_maxscale'].", ";
-		$sql .= $count;
-		$sql .= ");";
-		$this->transaction($sql);
-		$count++;
+	
+	$sql = "INSERT INTO gui_layer (fkey_gui_id, fkey_layer_id, gui_layer_wms_id, ";
+	$sql .= "gui_layer_status, gui_layer_selectable, gui_layer_visible, gui_layer_queryable, ";
+	$sql .= "gui_layer_querylayer,gui_layer_minscale,gui_layer_maxscale, gui_layer_priority) ";
+	$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)";
+	$v = array($gui_id,$this->objLayer[$i]->db_id,$myWMS,1,1,1,$this->objLayer[$i]->layer_queryable,
+		$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,$this->objLayer[$i]->layer_maxscale,$i);
+	$t = array('s','i','i','i','i','i','i','i','i','i','i');
+	$res = db_prep_query($sql,$v,$t);
+	if(!$res){
+		db_rollback();	
+	}	
+}
+function appendGuiLayer($i,$myWMS,$gui_id){
+	# table gui_layer
+	
+	$sql = "INSERT INTO gui_layer (fkey_gui_id, fkey_layer_id, gui_layer_wms_id, ";
+	$sql .= "gui_layer_status, gui_layer_selectable, gui_layer_visible, gui_layer_queryable, ";
+	$sql .= "gui_layer_querylayer,gui_layer_minscale,gui_layer_maxscale, gui_layer_priority) ";
+	$sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)";
+	$v = array($gui_id,$this->objLayer[$i]->db_id,$myWMS,0,0,0,$this->objLayer[$i]->layer_queryable,
+		$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,$this->objLayer[$i]->layer_maxscale,$i);
+	$t = array('s','i','i','i','i','i','i','i','i','i','i');
+	$res = db_prep_query($sql,$v,$t);
+	if(!$res){
+		db_rollback();	
+	}	
+}
+function insertSRS($myWMS){
+	for($i=0; $i<count($this->wms_srs);$i++){
+		$sql ="INSERT INTO wms_srs (fkey_wms_id, wms_srs) values($1,$2)";		
+		$v = array($myWMS,strtoupper($this->wms_srs[$i]));
+		$t = array('i','s');		
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			db_rollback();	
+		}
+	}	
+}
+function insertFormat($myWMS){
+	for($i=0; $i<count($this->data_type);$i++){
+		$sql ="INSERT INTO wms_format (fkey_wms_id, data_type, data_format) ";
+		$sql .= " VALUES($1,$2,$3)";
+		$v = array($myWMS,$this->data_type[$i],$this->data_format[$i]);
+		$t = array('i','s','s');
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			db_rollback();	
+		}
+	}	
+}
+function insertLayerEPSG($i){
+	for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
+		$sql = "INSERT INTO layer_epsg (fkey_layer_id, epsg, minx, miny, maxx, maxy) ";
+		$sql .= "VALUES($1,$2,$3,$4,$5,$6)";
+		$v = array($this->objLayer[$i]->db_id,$this->objLayer[$i]->layer_epsg[$j][epsg],
+			$this->objLayer[$i]->layer_epsg[$j][minx],$this->objLayer[$i]->layer_epsg[$j][miny],
+			$this->objLayer[$i]->layer_epsg[$j][maxx],$this->objLayer[$i]->layer_epsg[$j][maxy]
+			); 
+		$t = array('i','s','d','d','d','d');
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			db_rollback();	
+		}
 	}
-	$res = db_query("COMMIT");
-	if($SYS_DBTYPE=="pgsql")
-	{$sql2 = "SET AUTOCOMMIT=0";}
-	else{
-	$sql2 = "SET AUTOCOMMIT=1";
+}
+function insertLayerStyle($i){
+	for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
+		$sql = "INSERT INTO layer_style (fkey_layer_id, name, title, legendurl, legendurlformat) ";
+		$sql .= "VALUES($1,$2,$3,$4,$5)";
+		$v = array($this->objLayer[$i]->db_id,$this->objLayer[$i]->layer_style[$j]["name"],
+				$this->objLayer[$i]->layer_style[$j]["title"],$this->objLayer[$i]->layer_style[$j]["legendurl"],
+				$this->objLayer[$i]->layer_style[$j]["legendurlformat"]				
+			);
+		$t = array('i','s','s','s','s');
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			db_rollback();	
+		}
 	}
-	$res = db_query($sql2);
 }
 function updateObjInDB($myWMS){
-	global $DBSERVER,$DB,$OWNER,$PW;
-	$con = db_connect($DBSERVER,$OWNER,$PW);
-	db_select_db($DB, $con);
-	if(SYS_DBTYPE=="pgsql")
-	{$sql = "SET AUTOCOMMIT=1";}
-	else{
-	$sql = "SET AUTOCOMMIT=1";
-	}
-	$res = db_query($sql);
-	$sql = "BEGIN";
-	$res = db_query($sql);
+	db_begin();
 	
 	# TABLE wms
 	$sql = "UPDATE wms SET ";
-	$sql .= "wms_version = '".$this->wms_version."' ,";
-	$sql .= "wms_title  = '".db_escape_string(str_replace("'","",$this->wms_title))."' ,";
-	$sql .= "wms_abstract  = '".db_escape_string(str_replace("'","",$this->wms_abstract))."' ,";
-	$sql .= "wms_getcapabilities  = '".$this->wms_getcapabilities."' ,";
-	$sql .= "wms_getmap  = '".$this->wms_getmap."' ,";
-	$sql .= "wms_getfeatureinfo  = '".$this->wms_getfeatureinfo."' ,";
-	$sql .= "wms_getlegendurl  = '".$this->wms_getlegendurl."' ,";
-	$sql .= "wms_getcapabilities_doc = '".addslashes($this->wms_getcapabilities_doc) . "'";
-	$sql .= " WHERE wms_id = ". $myWMS;
-	
-	$this->transaction($sql);
-	
-	# TABLE layer
-	
-	# backup layer_params
-	$sql = "SELECT * FROM gui_layer INNER JOIN layer ON layer.layer_id = gui_layer.fkey_layer_id WHERE gui_layer_wms_id = ".$myWMS;
-	$res_backup = db_query($sql);		
-	$cnt = 0;
-	while($row = db_fetch_array($res_backup)){
-#		$my_layer_name[$cnt] = $row["layer.layer_name"];
-#		$fkey_gui_id[$cnt] = $row["gui_layer.fkey_gui_id"];
-#		$fkey_layer_id[$cnt] = $row["gui_layer.fkey_layer_id"];
-		$my_layer_name[$cnt] = $row["layer_name"];
-		$fkey_gui_id[$cnt] = $row["fkey_gui_id"];
-		$fkey_layer_id[$cnt] = $row["fkey_layer_id"];
-		$gui_layer_wms_id[$cnt] = $row["gui_layer_wms_id"];
-		$gui_layer_status[$cnt] = $row["gui_layer_status"];
-		$gui_layer_selectable[$cnt] = $row["gui_layer_selectable"];
-		$gui_layer_visible[$cnt] = $row["gui_layer_visible"];
-		$gui_layer_queryable[$cnt] = $row["gui_layer_queryable"];
-		$gui_layer_querylayer[$cnt] = $row["gui_layer_querylayer"];
-		$gui_layer_minscale[$cnt] = $row["gui_layer_minscale"];
-		$gui_layer_maxscale[$cnt] = $row["gui_layer_maxscale"];
-		$gui_layer_priority[$cnt] = $row["gui_layer_priority"];
-		$gui_layer_style[$cnt] = $row["gui_layer_style"];
-		$cnt++;
-	 }	
+	$sql .= "wms_version = $1 ,";
+	$sql .= "wms_title  = $2 ,";
+	$sql .= "wms_abstract  = $3 ,";
+	$sql .= "wms_getcapabilities  = $4 ,";
+	$sql .= "wms_getmap  = $5 ,";
+	$sql .= "wms_getfeatureinfo  = $6 ,";
+	$sql .= "wms_getlegendurl  = $7 ,";
+	$sql .= "wms_getcapabilities_doc = $8 ,";
+	$sql .= "wms_upload_url = $9 ";
+	$sql .= " WHERE wms_id = $10";
+	
+	
+	$v = array($this->wms_version,$this->wms_title,$this->wms_abstract,$this->wms_getcapabilities,
+		$this->wms_getmap,$this->wms_getfeatureinfo,$this->wms_getlegendurl,
+		$this->wms_getcapabilities_doc,$this->wms_upload_url,$myWMS);
+	$t = array('s','s','s','s','s','s','s','s','s','i');
+	$res = db_prep_query($sql,$v,$t);
+	if(!$res){
+		db_rollback();	
+	}
+	
+	# delete and refill srs and formats
+	$sql = "DELETE FROM wms_srs WHERE fkey_wms_id = $1 ";
+	$v = array($myWMS);
+	$t = array('i');
+	$res = db_prep_query($sql,$v,$t);
+	if(!$res){
+		db_rollback();	
+	}
+	$this->insertSRS($myWMS);
+	
+	$sql = "DELETE FROM wms_format WHERE fkey_wms_id = $1 ";
+	$v = array($myWMS);
+	$t = array('i');
+	$res = db_prep_query($sql,$v,$t);
+	if(!$res){
+		db_rollback();	
+	}
+	$this->insertFormat($myWMS);
+	
+	# update gui_wms
+	$this->update_gui_wms($myWMS);
+	
+	# update TABLE layer	
+	# delete all layer which are outdated
+	$v = array($myWMS);
+	$t = array('i');
+	$c = 2;
+	$sql = "DELETE FROM layer WHERE fkey_wms_id = $1 AND NOT layer_name IN(";
+	for($i=0; $i<count($this->objLayer); $i++){
+		if($i>0){$sql .= ',';}
+		$sql .= "$".$c;
+		array_push($v,$this->objLayer[$i]->layer_name);
+		array_push($t,'s');		
+		$c++;
+	}
+	$sql .= ")";
+	
+	$res = db_prep_query($sql,$v,$t);
+	if(!$res){
+		db_rollback();	
+	}
+		
+	# update or insert?
+	$sql = "SELECT layer_name FROM layer WHERE fkey_wms_id = $1";
+	$v = array($myWMS);
+	$t = array('i');
+	$res = db_prep_query($sql,$v,$t);
+	$exLayer = array();
+	while($row = db_fetch_array($res)){
+		array_push($exLayer,$row["layer_name"]);
+	}
 	
-	$sql = "DELETE FROM layer WHERE fkey_wms_id = ".$myWMS;
-	$this->transaction($sql);
+	$sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = $1";
+	$v = array($myWMS);
+	$t = array('i');
+	$res = db_prep_query($sql,$v,$t);
+	$exGui = array();
+	while($row = db_fetch_array($res)){
+		array_push($exGui,$row["fkey_gui_id"]);
+	}
 	
 	for($i=0; $i<count($this->objLayer); $i++){
-		$sql = "INSERT INTO layer(fkey_wms_id, layer_pos, layer_parent, layer_name, layer_title, layer_dataurl, layer_queryable, layer_minscale, layer_maxscale,layer_metadataurl) ";
-		$sql .= "VALUES(";
-			$sql .= $myWMS . ",";
-			$sql .= $this->objLayer[$i]->layer_id . ",";
-			$sql .= "'".$this->objLayer[$i]->layer_parent."',";
-			$sql .= "'".$this->objLayer[$i]->layer_name."',";
-			$sql .= "'".$this->objLayer[$i]->layer_title."',";
-			$sql .= "'".$this->objLayer[$i]->layer_dataurl_href."',";
-			$sql .= $this->objLayer[$i]->layer_queryable . ",";
-			$sql .= $this->objLayer[$i]->layer_minscale . ",";
-			$sql .= $this->objLayer[$i]->layer_maxscale. ",";
-			$sql .= "'".$this->objLayer[$i]->layer_metadataurl."'";
-		$sql .= ")";
-		# save the id of each layer: set param2 true
-		$this->transaction($sql);
-		$this->objLayer[$i]->db_id = db_insert_id($con,"layer","layer_id");
-		
-		for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
-			$sql = "INSERT INTO layer_epsg (fkey_layer_id, epsg, minx, miny, maxx, maxy) ";
-			$sql .= "VALUES("; 
-			$sql .= $this->objLayer[$i]->db_id . ", "; 
-			$sql .= "'" .$this->objLayer[$i]->layer_epsg[$j][epsg]. "', ";
-			$sql .= $this->objLayer[$i]->layer_epsg[$j][minx] . ", ";
-			$sql .= $this->objLayer[$i]->layer_epsg[$j][miny] . ", ";
-			$sql .= $this->objLayer[$i]->layer_epsg[$j][maxx]. ", ";
-			$sql .= $this->objLayer[$i]->layer_epsg[$j][maxy];
-			$sql .= ")";
-			$this->transaction($sql);
+		if(in_array($this->objLayer[$i]->layer_name,$exLayer)){
+			echo "<br>update: ".$this->objLayer[$i]->layer_name;
+			for($j=0; $j<count($exGui); $j++){
+				$this->updateGuiLayer($i,$myWMS,$exGui[$j]);
+			}
 		}
-		# delete and refill TABLE layer_style for each layer
-		for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
-			$sql = "INSERT INTO layer_style (fkey_layer_id, name, title, legendurl, legendurlformat) ";
-			$sql .= "VALUES(";
-			$sql .= $this->objLayer[$i]->db_id .", ";
-			$sql .= "'".$this->objLayer[$i]->layer_style[$j]["name"]."', ";
-			$sql .= "'".$this->objLayer[$i]->layer_style[$j]["title"]."', ";
-			$sql .= "'".$this->objLayer[$i]->layer_style[$j]["legendurl"]."', ";
-			$sql .= "'".$this->objLayer[$i]->layer_style[$j]["legendurlformat"]."'";
-			$sql .= ");";
-			$this->transaction($sql);
+		else{
+			echo "<br>append: ".$this->objLayer[$i]->layer_name;
+			$this->insertLayer($i,$myWMS);
+			for($j=0; $j<count($exGui); $j++){
+				$this->appendGuiLayer($i,$myWMS,$exGui[$j]);
+			}
 		}
 	}
-		
-	
-	# TABLE wms_srs
-	
-	for($i=0; $i<count($this->wms_srs);$i++){
-		$sql ="INSERT INTO wms_srs (fkey_wms_id, wms_srs) ";		
-		$sql .= " VALUES(".$myWMS.",'".$this->wms_srs[$i]."');";		
-		$this->transaction($sql);
-	}		
-	
-	# TABLE wms_format
-	
-	$sql = "DELETE FROM wms_format WHERE fkey_wms_id = " . $myWMS;
-	$this->transaction($sql);
-	
-	for($i=0; $i<count($this->data_type);$i++){
-		$sql ="INSERT INTO wms_format (fkey_wms_id, data_type, data_format) ";
-		$sql .= " VALUES(".$myWMS.",'".$this->data_type[$i]."','".$this->data_format[$i]."');";
-		$this->transaction($sql);
+	db_commit();
+	return;	
+}
+function updateGuiLayer($i,$myWMS,$gui_id){
+	$sql = "SELECT layer_id FROM layer WHERE fkey_wms_id = $1 AND layer_name = $2";
+	$v = array($myWMS,$this->objLayer[$i]->layer_name);
+	$t = array('i','s');
+	$res = db_prep_query($sql,$v,$t);
+	if($row = db_fetch_array($res)){
+		$l_id = $row['layer_id'];	
+	}
+	else{
+		db_rollback();
+		$e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name. " in gui: ".$gui_id);
+		return;	
 	}
 	
-	# TABLE gui_wms
-	
+	$sql = "SELECT * FROM gui_layer WHERE fkey_layer_id = $1 and fkey_gui_id = $2";
+	$v = array($l_id,$gui_id);
+	$t = array('i','s');
+	$res = db_prep_query($sql,$v,$t);		
+	while($row = db_fetch_array($res)){
+		if($this->objLayer[$i]->layer_queryable == 0){
+			$sql1 = "UPDATE gui_layer set gui_layer_queryable = 0, gui_layer_querylayer = 0 ";
+			$sql1 .= "WHERE fkey_layer_id = $1 and fkey_gui_id = $2";
+			$v = array($l_id,$gui_id);
+			$t = array('i','s');
+			$res1 = db_prep_query($sql1,$v,$t);
+			if(!$res1){db_rollback();}
+		}
+		if($row["gui_layer_minscale"] < $this->objLayer[$i]->layer_minscale){
+			$sql1 = "UPDATE gui_layer set gui_layer_minscale = $1 ";
+			$sql1 .= "WHERE fkey_layer_id = $2 and fkey_gui_id = $3";
+			$v = array($this->objLayer[$i]->layer_minscale,$l_id,$gui_id);
+			$t = array('i','i','s');
+			$res1 = db_prep_query($sql1,$v,$t);
+			if(!$res1){db_rollback();}
+		}
+		if($row["gui_layer_maxscale"] > $this->objLayer[$i]->layer_maxscale){
+			$sql1 = "UPDATE gui_layer set gui_layer_maxscale = $1 ";
+			$sql1 .= "WHERE fkey_layer_id = $2 and fkey_gui_id = $3";
+			$v = array($this->objLayer[$i]->layer_maxscale,$l_id,$gui_id);
+			$t = array('i','i','s');
+			$res1 = db_prep_query($sql1,$v,$t);
+			if(!$res1){db_rollback();}
+		}		
+	}
+}
+function update_gui_wms($myWMS){
 	$sql = "SELECT * FROM gui_wms where fkey_wms_id = " . $myWMS;
 	$res = db_query($sql);
 	$cnt = 0;
@@ -968,96 +1013,8 @@
 			$this->transaction($sql);
 		}
 		$cnt++;
-	}
-	
-	# TABLE gui_layer
-	for($k=0; $k<count($myGUI); $k++){
-		for($i=0; $i<count($this->objLayer); $i++){
-			unset($lastLayer_index);
-			for($j=0; $j<count($my_layer_name); $j++){
-#				echo "<br>" . $this->objLayer[$i]->layer_name . " vs. " . $my_layer_name[$j] . "<br>"; 
-#				echo "<br>" . $myGUI[$k] . " vs. " . $fkey_gui_id[$j] . "<br>"; 
-				if($this->objLayer[$i]->layer_name == $my_layer_name[$j] && $myGUI[$k] == $fkey_gui_id[$j]){
-					$lastLayer_index = $j; 
-				}
-			}
-			
-			if($lastLayer_index >= 0 && $lastLayer_index != ""){
-				$sql = "INSERT INTO gui_layer(fkey_gui_id, fkey_layer_id, gui_layer_wms_id, gui_layer_status, ";
-				$sql .= "gui_layer_selectable, gui_layer_visible, gui_layer_queryable, gui_layer_querylayer, ";
-				$sql .= "gui_layer_minscale, gui_layer_maxscale, gui_layer_priority, gui_layer_style) VALUES(";
-				$sql .= "'".$myGUI[$k]."', ";
-				$sql .= $this->objLayer[$i]->db_id. ", ";
-				$sql .= $myWMS. ", ";
-				$sql .= $gui_layer_status[$lastLayer_index]. ", ";
-				$sql .= $gui_layer_selectable[$lastLayer_index]. ", ";
-				$sql .= $gui_layer_visible[$lastLayer_index]. ", ";
-				# gui_layer_queryable
-				if($this->objLayer[$i]->layer_queryable == 1 && $gui_layer_queryable[$lastLayer_index] == 1){
-					$sql .= $this->objLayer[$i]->layer_queryable. ", ";
-				} else{$sql .=  "0, ";}
-				# gui_layer_querylayer
-				if($this->objLayer[$i]->layer_queryable == 1 && $gui_layer_querylayer[$lastLayer_index] == 1){
-					$sql .=  "1, ";
-				} else{$sql .=  "0, ";}
-				# gui_layer_minscale
-				if($gui_layer_minscale[$lastLayer_index] >= $this->objLayer[$i]->layer_minscale){
-					$sql .= $gui_layer_minscale[$lastLayer_index] . ", ";
-				} else{ $sql .= $this->objLayer[$i]->layer_minscale . ", ";}
-				# gui_layer_maxscale 
-				if($this->objLayer[$i]->layer_maxscale == 0 || $gui_layer_maxscale[$lastLayer_index] <= $this->objLayer[$i]->layer_maxscale){
-					$sql .= $gui_layer_maxscale[$lastLayer_index] . ", ";
-				} else{ $sql .= $this->objLayer[$i]->layer_maxscale . ", ";}
-				# gui_layer_priority
-				$sql .= $gui_layer_priority[$lastLayer_index] . ", ";
-				# gui_layer_style
-				for($n=0; $n<count($this->objLayer[$i]->layer_style); $n++){
-					if($gui_layer_style[$lastLayer_index] == $this->objLayer[$i]->layer_style[$n]["name"]){
-						$myStyle = true;
-					}
-				}
-				if($myStyle){
-					$sql .= "'".$gui_layer_style[$lastLayer_index]."'";
-				} 
-				else{$sql .= "''";}
-				$sql .= ")";
-			}
-			else{
-				$sql = "INSERT INTO gui_layer(fkey_gui_id, fkey_layer_id, gui_layer_wms_id, gui_layer_status, ";
-				$sql .= "gui_layer_selectable, gui_layer_visible, gui_layer_queryable, gui_layer_querylayer, ";
-				$sql .= "gui_layer_minscale, gui_layer_maxscale, gui_layer_priority, gui_layer_style) VALUES(";
-				$sql .= "'".$myGUI[$k]."', ";
-				$sql .= $this->objLayer[$i]->db_id. ", ";
-				$sql .= $myWMS. ", ";
-				# gui_layer_status
-				$sql .= "0, ";
-				# gui_layer_selectable
-				$sql .= "0, ";
-				# gui_layer_visible
-				$sql .= "0, ";
-				# gui_layer_queryable
-				$sql .=  $this->objLayer[$i]->layer_queryable. ", ";
-				# gui_layer_querylayer
-				$sql .= "0, ";
-				$sql .= $this->objLayer[$i]->layer_minscale . ", ";
-				$sql .= $this->objLayer[$i]->layer_maxscale . ", ";
-				$sql .= $this->objLayer[$i]->layer_id . ", ";
-				$sql .= "''";
-				$sql .= ")";
-			}
-			$this->transaction($sql);
-		}
-	}
-	$sql = "COMMIT";
-	$res = db_query($sql);
-	if($SYS_DBTYPE=="pgsql")
-	{$sql = "SET AUTOCOMMIT=0";}
-	else{
-	$sql = "SET AUTOCOMMIT=1";
-	}
-	$res = db_query($sql);
+	}	
 }
-
 function getVersion() {
 	return $this->wms_version;
 }
@@ -1281,6 +1238,14 @@
 		}
 		return $s;
 	}
+	function checkObj(){
+		if($this->wms_getcapabilities == '' || $this->wms_getmap == '' ){
+			echo "<br>Missing parameters: <br>";
+			$this->displayWMS();
+			echo "<br> Data not commited<br>";
+			die();
+		}
+	}
 }
 class layer extends wms{	
 	var $layer_id;




More information about the Mapbender_commits mailing list