[Mapbender-commits] r4513 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Aug 13 09:19:19 EDT 2009


Author: christoph
Date: 2009-08-13 09:19:18 -0400 (Thu, 13 Aug 2009)
New Revision: 4513

Modified:
   trunk/mapbender/http/classes/class_user.php
Log:
added functions for monitoring

Modified: trunk/mapbender/http/classes/class_user.php
===================================================================
--- trunk/mapbender/http/classes/class_user.php	2009-08-11 10:05:11 UTC (rev 4512)
+++ trunk/mapbender/http/classes/class_user.php	2009-08-13 13:19:18 UTC (rev 4513)
@@ -55,13 +55,13 @@
 	 * @param $userId Integer 	the ID of the user that	is represented by 
 	 * 							this object.
 	 */
-	public function __construct ($userId) {
-		
-        if($userId == null){
-          // new user
-          return;
-        }
-        $this->id = $userId;
+	public function __construct () {
+		if (func_num_args() === 1) {
+			$this->id = intval(func_get_arg(0));
+		}
+		else {
+			$this->id = Mapbender::session()->get("mb_user_id");
+		}
 		try{
 			$this->load();
 		}
@@ -69,7 +69,6 @@
 		{	
 			new mb_exception($E->getMessage());
 		}
-
 	}	
 
 	
@@ -109,6 +108,13 @@
 		return $result;
 	}
 
+	public function isPublic () {
+		if ($this->id == PUBLIC_USER) {
+			return true;
+		}
+		return false;
+	}
+
 	public function  create() {
 		if($this->name == ""){ $e = new Exception("Can' t create user without name");}
 		
@@ -324,7 +330,7 @@
 
     }
 	
-		/**
+	/**
 	 * Returns an array of application IDs that the user is allowed to access.
 	 * 
 	 * @return Array an array of application IDs
@@ -487,5 +493,185 @@
 		}
 		return $wmcArray;
 	}
+	
+	public function isLayerAccessible ($layerId) {
+		$array_guis = $this->getApplicationsByPermission();
+		$v = array();
+		$t = array();
+		$sql = "SELECT * FROM gui_layer WHERE fkey_gui_id IN (";
+		$c = 1;
+		for ($i = 0; $i < count($array_guis); $i++) {
+			if ($i > 0) { 
+				$sql .= ",";
+			}
+			$sql .= "$".$c;
+			$c++;
+			array_push($v, $array_guis[$i]);
+			array_push($t, 's');
+		}
+		$sql .= ") AND fkey_layer_id = $".$c." AND gui_layer_status = 1";
+		array_push($v,$layerId);
+		array_push($t,'i');
+		$res = db_prep_query($sql,$v,$t);
+		
+		return ($row = db_fetch_array($res)) ? true : false;
+	}
+	
+	public function isWmsAccessible ($wms_id) {
+		$array_guis = $this->getApplicationsByPermission();
+		$v = array();
+		$t = array();
+		$sql = "SELECT * FROM gui_wms WHERE fkey_gui_id IN (";
+		$c = 1;
+		for ($i = 0; $i < count($array_guis); $i++) {
+			if ($i > 0) { 
+				$sql .= ",";
+			}
+			$sql .= "$".$c;
+			$c++;
+			array_push($v, $array_guis[$i]);
+			array_push($t, 's');
+		}
+		$sql .= ") AND fkey_wms_id = $" . $c;
+		array_push($v, $wms_id);
+		array_push($t, 'i');
+		$res = db_prep_query($sql, $v, $t);
+		return ($row = db_fetch_array($res)) ? true : false;
+	}
+	
+	public function isWmsOwner ($wms_id) {
+		// first get guis which deploy this wms.
+        $sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = $1 GROUP BY fkey_gui_id";
+		$v = array($wms_id);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+
+		$gui = array();
+		while($row = db_fetch_array($res)){
+			$gui[] = $row["fkey_gui_id"];
+		}
+
+        if (count($gui) === 0) {
+        	return false;
+		}
+		$v = array();
+		$t = array();
+		$c = 1;
+		$sql = "(SELECT mb_user.mb_user_id FROM mb_user JOIN gui_mb_user ";
+		$sql .= "ON mb_user.mb_user_id = gui_mb_user.fkey_mb_user_id ";
+		$sql .= " WHERE gui_mb_user.mb_user_type = 'owner'";
+		$sql .= " AND gui_mb_user.fkey_gui_id IN (";
+		for ($i = 0; $i < count($gui); $i++) {
+			if ($i > 0) { 
+				$sql .= ",";
+			}
+			$sql .= "$".$c;
+			$c++;
+			array_push($v, $gui[$i]);
+			array_push($t, 's');
+		}
+		$sql .= ") GROUP BY mb_user.mb_user_id";
+		$sql .= ") UNION (";
+		$sql .= "SELECT mb_user.mb_user_id FROM gui_mb_group JOIN mb_user_mb_group ON  mb_user_mb_group.fkey_mb_group_id = gui_mb_group.fkey_mb_group_id  JOIN mb_user ";
+		$sql .= "ON mb_user.mb_user_id = mb_user_mb_group.fkey_mb_user_id ";
+		$sql .= " WHERE gui_mb_group.mb_group_type = 'owner'";
+		$sql .= " AND gui_mb_group.fkey_gui_id IN (";
+
+		for ($j = 0; $j < count($gui); $j++) {
+			if ($j > 0) { 
+				$sql .= ",";
+			}
+			$sql .= "$".$c;
+			$c++;
+			array_push($v, $gui[$i]);
+			array_push($t, 's');
+		}
+		$sql .= ") GROUP BY mb_user.mb_user_id)";
+
+		$res = db_prep_query($sql,$v,$t);
+
+		$user = array();
+		while($row = db_fetch_array($res)){
+			$user[] = intval($row["mb_user_id"]);
+		}
+		if (in_array($this->id, $user))	{
+            return true;
+        } 
+		return false;
+	}
+	
+	private function addSingleSubscription ($wmsId) {
+		if (!is_numeric($wmsId)) {
+			$e = new mb_exception("class_user.php: addSingleSubscription: WMS Id not a number.");
+			return false;
+		}
+		$id = intval($wmsId);
+		
+		if ($this->cancelSingleSubscription($id)) {
+			$sql = "INSERT INTO mb_user_abo_ows (fkey_mb_user_id, fkey_wms_id) VALUES ($1, $2)";   
+			$v = array($this->id, $id);
+			$t = array('i', 'i');
+			$res = db_prep_query($sql, $v, $t);
+			return ($res) ? true : false;
+		}
+		return false;
+	}
+	
+	private function cancelSingleSubscription ($wmsId) {
+		if (!is_numeric($wmsId)) {
+			$e = new mb_exception("class_user.php: cancelSingleSubscription: WMS Id not a number.");
+			return false;
+		}
+		$id = intval($wmsId);
+
+		$sql = "DELETE FROM mb_user_abo_ows WHERE fkey_wms_id = $1 " . 
+			"AND fkey_mb_user_id = $2";   
+		$v = array($id, $this->id);
+		$t = array('i', 'i');
+		$res = db_prep_query($sql, $v, $t);	
+		return ($res) ? true : false;
+	}
+	
+	public function addSubscription ($wms) {
+		if (is_array($wms)) {
+			foreach ($wms as $wmsId) {
+				$this->addSingleSubscription($wmsId);
+			}
+		}
+		else {
+			$this->addSingleSubscription($wms);
+		}
+	}
+
+	public function cancelSubscription ($wms) {
+		if (is_array($wms)) {
+			foreach ($wms as $wmsId) {
+				$this->cancelSingleSubscription($wmsId);
+			}
+		}
+		else {
+			$this->cancelSingleSubscription($wms);
+		}
+	}
+
+	public function hasSubscription ($wmsId) {
+		if (!is_numeric($wmsId)) {
+			$e = new mb_exception("class_user.php: cancelSingleSubscription: WMS Id not a number.");
+			return false;
+		}
+		$id = intval($wmsId);
+		
+		$sql = "SELECT * FROM mb_user_abo_ows WHERE fkey_wms_id = $1 AND " . 
+			"fkey_mb_user_id = $2 LIMIT 1";
+		$v = array($id, $this->id);
+		$t = array('i', 'i');
+		$res = db_prep_query($sql, $v, $t);
+		$row = db_fetch_array($res);
+		
+		if (!isset($row['fkey_wms_id'])) {
+	        return false;
+		}
+        return true;
+	}
 }
 ?>



More information about the Mapbender_commits mailing list