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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Nov 5 08:09:12 EST 2009


Author: kmq
Date: 2009-11-05 08:09:11 -0500 (Thu, 05 Nov 2009)
New Revision: 4939

Modified:
   trunk/mapbender/http/classes/class_wmc.php
   trunk/mapbender/http/javascripts/mod_loadwmc.js
   trunk/mapbender/http/php/mod_loadwmc_server.php
Log:
added ability to set WMCs public

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2009-11-05 13:09:11 UTC (rev 4938)
+++ trunk/mapbender/http/classes/class_wmc.php	2009-11-05 13:09:11 UTC (rev 4939)
@@ -93,6 +93,7 @@
 	var $wmc_id;
 	var $userId;
     var $timestamp;
+    var $public;
 
 	// set during parsing
 	var $wmc_version;
@@ -154,19 +155,22 @@
 		}
 		$this->createObjFromWMC_xml($doc);
         // FIXME:too hackisch to be proper
-        $sql = "SELECT wmc_timestamp FROM mb_user_wmc WHERE wmc_id = $1";
+        $sql = "SELECT wmc_timestamp,wmc_title,wmc_public FROM mb_user_wmc WHERE wmc_id = $1";
         $v = array($wmcId);
         $t = array("i");
         
         // FIXME: might as well fetch title too, as long as we ŕe here  
         $res = db_prep_query($sql,$v,$t);
-        if(db_error) { return false; } //FIXME: no really need erromessage when this fails
+        if(db_error()) { return false; } //FIXME: no really need erromessage when this fails
         if($row = db_fetch_row($res))
         {
+          $this->wmc_Id = $wmcId;
           $this->timestamp = $row[0];
+          $this->title = $row[1];
+          $this->public = $row[2];
         
         }
-        
+
 		return true;
 	}
 
@@ -245,7 +249,7 @@
 		}
 	
 		if ($wmcIdList !== "") {
-			$sql = "SELECT DISTINCT wmc_id, wmc_title, wmc_timestamp,wmc_timestamp_create FROM mb_user_wmc ";
+			$sql = "SELECT DISTINCT wmc_id, wmc_title, wmc_timestamp,wmc_timestamp_create,wmc_public FROM mb_user_wmc ";
 			$sql .= "WHERE wmc_id IN (" . $wmcIdList . ") ";
 			$sql .=	"ORDER BY wmc_timestamp DESC";
 		
@@ -256,6 +260,7 @@
 				$currentResult["title"] = administration::convertIncomingString($row["wmc_title"]);
 				$currentResult["timestamp"] = date("M d Y H:i:s", $row["wmc_timestamp"]); 
 				$currentResult["timestamp_create"] = date("M d Y H:i:s", $row["wmc_timestamp_create"]); 
+				$currentResult["public"] = $row["wmc_public"] == 1? true: false;
 				array_push($wmcArray, $currentResult);
 			}
 		}
@@ -468,6 +473,23 @@
 		return false;
 	}
 
+    /*
+    * sets the WMC's publich flag
+    * @param $public boolean wether access should be public
+    */
+    public function setPublic($public)
+    {
+      $wmcId = $this->wmc_Id;
+      $public = $public ? 1 :0;
+      $sql = "UPDATE mb_user_wmc SET wmc_public = $1 WHERE wmc_id = $2;";
+      $v = array($public,$wmcId);
+      $t = array("i","s");
+      $res = db_prep_query($sql,$v,$t);
+      if(db_error()){
+        return false;
+      }
+      return true;
+    }
 	// ---------------------------------------------------------------------------
 	// GETTER FUNCTIONS
 	// ---------------------------------------------------------------------------

Modified: trunk/mapbender/http/javascripts/mod_loadwmc.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_loadwmc.js	2009-11-05 13:09:11 UTC (rev 4938)
+++ trunk/mapbender/http/javascripts/mod_loadwmc.js	2009-11-05 13:09:11 UTC (rev 4939)
@@ -41,6 +41,7 @@
 							"<th>load</td>" +
 							"<th>merge</td>" +
 							"<th>append</td>" +
+							"<th>public</td>" +
 							"<th>show</td>" +
 							"<th>OpenLayers</td>" +
 							"<th>delete</td>" +
@@ -149,6 +150,17 @@
 			});
 			$tr.append($appendTd);				
 
+            //WMC is Public
+			var $appendTd = appendBoolTableCell({
+                public:  wmcObj.wmc[i].public,
+				method: "setWMCPublic",
+				parameters:{
+					id:currentId, 
+				},
+				callback: executeJavaScript
+			});
+			$tr.append($appendTd);				
+
 			// Display WMC
 			var $displayTd = appendTableCell({
 				src: "../img/button_gray/wmc_xml.png",
@@ -252,6 +264,9 @@
 				if (args.method === "deleteWmc") {
 					
 				}
+                else if (args.method == "setWMCPublic"){
+
+                }
 				else {
 					if (obj.javascript && typeof(obj.javascript) == "object") {
 						for (var j = 0; j < obj.javascript.length; j++) {
@@ -285,3 +300,14 @@
 	});
 	return $("<td></td>").append($img);
 }
+
+function appendBoolTableCell (args){
+  var checked = args.public == true ? 'checked="checked"':'' ;
+  var checkbox = $('<input type="checkbox" '+  checked  +' />');
+  checkbox.change(function(){
+    args.parameters.public = $(this).attr('checked') ? 1 : 0;
+    args.callback(args);
+  })
+  return $("<td></td>").append(checkbox);
+
+}

Modified: trunk/mapbender/http/php/mod_loadwmc_server.php
===================================================================
--- trunk/mapbender/http/php/mod_loadwmc_server.php	2009-11-05 13:09:11 UTC (rev 4938)
+++ trunk/mapbender/http/php/mod_loadwmc_server.php	2009-11-05 13:09:11 UTC (rev 4939)
@@ -134,6 +134,21 @@
 			$ajaxResponse->setSuccess(false);		
 		}
 	break;
+
+    case 'setWMCPublic':
+	  $wmcId = $ajaxResponse->getParameter("id");
+	  $public = $ajaxResponse->getParameter("public") == 1  ? true : false;
+      $wmc = new wmc();
+      $wmc->createFromDb($wmcId);
+      if($wmc->setPublic($public)){
+			$ajaxResponse->setMessage(_mb("Updated public flag"));
+			$ajaxResponse->setSuccess(true);		
+      }else {
+			$ajaxResponse->setMessage(_mb("could not update public flag"));
+			$ajaxResponse->setSuccess(false);		
+
+      }
+    break;
 	
 
 	// Invalid command
@@ -143,4 +158,4 @@
 }
 
 $ajaxResponse->send();
-?>
\ No newline at end of file
+?>



More information about the Mapbender_commits mailing list