[Mapbender-commits] r4876 - in trunk/mapbender/http: classes javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Oct 28 13:01:54 EDT 2009


Author: kmq
Date: 2009-10-28 13:01:53 -0400 (Wed, 28 Oct 2009)
New Revision: 4876

Modified:
   trunk/mapbender/http/classes/class_wmc.php
   trunk/mapbender/http/javascripts/mod_savewmc.php
   trunk/mapbender/http/php/mod_savewmc_server.php
Log:
saving WMC now has two behaviours: overwriting existing WMCs with the same name, and just inserting new WMCs alongside. Conrtolled by element_var  'overwrite' 

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2009-10-28 14:08:24 UTC (rev 4875)
+++ trunk/mapbender/http/classes/class_wmc.php	2009-10-28 17:01:53 UTC (rev 4876)
@@ -207,17 +207,58 @@
 	// DATABASE FUNCTIONS
 	// ---------------------------------------------------------------------------
 
+
 	/**
 	 * Stores this WMC in the database. The WMC has to be instantiated first, see above.
 	 * 
 	 * @return mixed[] an assoc array with attributes "success" (boolean) and "message" (String).
 	 */
-	public function insert () {
+	public function insert ($overwrite) {
 		$result = array();
-		if ($this->userId && $this->xml && $this->wmc_title) {
+        if ($this->userId && $this->xml && $this->wmc_title) {
+        
+          db_begin();
+
+          if($overwrite)
+          {
+
+            $findsql = "SELECT fkey_user_id,wmc_title,wmc_timestamp FROM mb_user_wmc WHERE fkey_user_id = $1 AND wmc_title = $2 ORDER BY wmc_timestamp DESC LIMIT 1;";
+            $v = array($this->userId, administration::convertOutgoingString($this->wmc_title));
+            $t = array("i","s");
+        
+            $res = db_prep_query($findsql,$v,$t);
+			if (db_error()) {
+				$errMsg = "Error while saving WMC document '" . $this->wmc_title . "': " . db_error();
+				$result["success"] = false;
+				$result["message"] = $errMsg;
+				$e = new mb_exception("mod_insertWMCIntoDB: " . $errMsg);
+                return $result;
+			}
+
+            if($row = db_fetch_row($res))
+            {
+              $sql = "UPDATE mb_user_wmc SET wmc = $1, wmc_timestamp = $2 WHERE fkey_user_id = $3 AND wmc_title=$4 AND wmc_timestamp = $5";
+              $v = array($this->xml, time(), $this->userId, administration::convertOutgoingString($this->wmc_title),$row[2]);
+              $t = array("s", "s", "i", "s","s");
+
+
+            }else{
+              $sql = "INSERT INTO mb_user_wmc VALUES ($1, $2, $3, $4, $5)";
+              $v = array($this->wmc_id, $this->userId, $this->xml, administration::convertOutgoingString($this->wmc_title), time());
+              $t = array("s", "i", "s", "s", "s");
+            }
+
+
+          }else{
+
 			$sql = "INSERT INTO mb_user_wmc VALUES ($1, $2, $3, $4, $5)";
 			$v = array($this->wmc_id, $this->userId, $this->xml, administration::convertOutgoingString($this->wmc_title), time());
 			$t = array("s", "i", "s", "s", "s");
+          
+          }
+
+
+
 			
 			$res = db_prep_query($sql, $v, $t);
 			if (db_error()) {
@@ -239,6 +280,7 @@
 			$result["message"] = $errMsg;
 			$e = new mb_exception("mod_insertWMCIntoDB: " . $errMsg .")");
 		}
+        db_commit();
 		return $result;
 	}
 	

Modified: trunk/mapbender/http/javascripts/mod_savewmc.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_savewmc.php	2009-10-28 14:08:24 UTC (rev 4875)
+++ trunk/mapbender/http/javascripts/mod_savewmc.php	2009-10-28 17:01:53 UTC (rev 4876)
@@ -22,6 +22,11 @@
 
 echo "mod_savewmc_target = '".$e_target[0]."';";
 ?>
+
+// init element_vars
+
+var overwrite = overwrite || false;
+
 function setOnUnload() {
 	if (ie) {
 		document.getElementsByTagName('body')[0].onunload = function() {
@@ -76,6 +81,7 @@
 	$.post("../php/mod_savewmc_server.php", {
 		"saveInSession":storeInSession, 
 		"generalTitle":generalTitle, 
+        "overwrite": overwrite,
 		"extensionData":extensionDataString, 
 		"mapObject":$.toJSON(mb_mapObj)
 	}, callbackFunction);

Modified: trunk/mapbender/http/php/mod_savewmc_server.php
===================================================================
--- trunk/mapbender/http/php/mod_savewmc_server.php	2009-10-28 14:08:24 UTC (rev 4875)
+++ trunk/mapbender/http/php/mod_savewmc_server.php	2009-10-28 17:01:53 UTC (rev 4876)
@@ -31,6 +31,10 @@
 $generalTitle = $_POST["generalTitle"];
 $extensionData = $json->decode($_POST["extensionData"]);
 
+$overwrite = isset($_POST["overwrite"]) ? $_POST['overwrite'] : "false";
+$overwrite = $overwrite == "true" ? True : False;
+
+
 // create WMC object
 $wmc = new wmc();
 $wmc->createFromJs($mapObject, $generalTitle, $extensionData);
@@ -47,7 +51,7 @@
 }
 else {
 	// insert WMC into database
-	$result = $wmc->insert();
+	$result = $wmc->insert($overwrite);
 	header("Content-Type: text/x-json");
 	echo $result["message"];
 }



More information about the Mapbender_commits mailing list