[Mapbender-commits] r10260 - in trunk/mapbender: conf http/classes http/php lib resources/db/pgsql/UTF-8/update

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Sep 17 07:39:24 PDT 2019


Author: armin11
Date: 2019-09-17 07:39:24 -0700 (Tue, 17 Sep 2019)
New Revision: 10260

Modified:
   trunk/mapbender/conf/mapbender.conf-dist
   trunk/mapbender/http/classes/class_user.php
   trunk/mapbender/http/php/mod_editFilteredUser.php
   trunk/mapbender/http/php/mod_editUser.php
   trunk/mapbender/lib/editUser.php
   trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.8_pgsql_UTF-8.sql
Log:
Some enhancement to define a preferred_gui for a user - they may choose from a list of available and accessable guis

Modified: trunk/mapbender/conf/mapbender.conf-dist
===================================================================
--- trunk/mapbender/conf/mapbender.conf-dist	2019-09-17 14:02:32 UTC (rev 10259)
+++ trunk/mapbender/conf/mapbender.conf-dist	2019-09-17 14:39:24 UTC (rev 10260)
@@ -284,6 +284,11 @@
 #define("PUBLIC_USER_DEFAULT_GUI", "Geoportal-RLP");
 
 # --------------------------------------------
+# define category for applications (guis) that are choosable by users as preferred gui
+# --------------------------------------------
+#define("PREFERRED_GUI_CATEGORY", 2);
+
+# --------------------------------------------
 # set the default srs for the PUBLIC_USER in the SESSION
 # --------------------------------------------
 #define("PUBLIC_USER_DEFAULT_SRS", "EPSG:25832");

Modified: trunk/mapbender/http/classes/class_user.php
===================================================================
--- trunk/mapbender/http/classes/class_user.php	2019-09-17 14:02:32 UTC (rev 10259)
+++ trunk/mapbender/http/classes/class_user.php	2019-09-17 14:39:24 UTC (rev 10260)
@@ -51,6 +51,7 @@
 
 var $isActive = 'f';
 var $createDigest = 'f';
+var $preferredGui = '';
   
     static $displayName = "User";
     static $internalName = "user";
@@ -152,7 +153,8 @@
 			"academicTitle" => $this->academicTitle,
 			"activationKey" => $this->activationKey,
 			"isActive" => $this->isActive,
-			"createDigest" => $this->createDigest
+			"createDigest" => $this->createDigest,		
+			"preferredGui" => $this->preferredGui
         );
 		return $result;
 	}
@@ -254,6 +256,7 @@
 		$this->activationKey = isset($changes->activationKey) ? $changes->activationKey : $this->activationKey;
 		$this->isActive = isset($changes->isActive) ? $changes->isActive : $this->isActive;
 		$this->createDigest = isset($changes->createDigest) ? $changes->createDigest : $this->createDigest;
+		$this->preferredGui = isset($changes->preferredGui) ? $changes->preferredGui : $this->preferredGui;
         return true;
 	}
 
@@ -290,8 +293,9 @@
 			"mb_user_login_count = $28, " .	
 			"activation_key = $29, " .
 			"is_active = $30, " .
-			"create_digest = $31 " .	
-			"WHERE mb_user_id = $32;";
+			"create_digest = $31, " .
+			"fkey_preferred_gui_id = $32 " .
+			"WHERE mb_user_id = $33;";
 
 		if ($this->isActive !== 't') {$this->isActive = 'f';}
 		if ($this->createDigest !== 't') {$this->createDigest = 'f';}
@@ -328,6 +332,7 @@
 			$this->activationKey !== "" ? $this->activationKey : null,
 			$this->isActive,
 			$this->createDigest,
+			$this->preferredGui,
 			is_numeric($this->id) ? intval($this->id) : null,
 		);
 
@@ -337,7 +342,7 @@
 			"s", "s", "s", "i", "s", 
 			"s", "s", "s", "s", "s", 
 			"s", "s", "s", "s", "s",
-			"s", "s", "i", "s", "b", "b", "i"
+			"s", "s", "i", "s", "b", "b", "s", "i"
 		);
 
 		$update_result = db_prep_query($sql_update,$v,$t);
@@ -418,6 +423,7 @@
 			$this->firstName = $row["mb_user_firstname"];
 			$this->lastName = $row["mb_user_lastname"];
 			$this->academicTitle = $row["mb_user_academictitle"];
+			$this->preferredGui = $row["fkey_preferred_gui_id"];
 		}
 		else {
 			 throw new Exception("no such User");
@@ -869,10 +875,11 @@
 	 * Returns an array of application IDs that the user is allowed to access.
 	 * 
 	 * @return Array an array of application IDs
-	 * @param $ignorepublic boolean whether or not to ignore 
-	 * 								public applications (?)
+	 * @param $ignorePublic boolean whether or not to ignore 
+	 * public applications (?)
+         * @param $categoryFilter false or id of category to filter guis - only return those guis, that are in that category
 	 */
-	public function getApplicationsByPermission ($ignorepublic = false) {
+	public function getApplicationsByPermission ($ignorePublic = false, $categoryFilter = false) {
 		$mb_user_id = $this->id;
 		$arrayGuis = array();
 		$mb_user_groups = array();
@@ -900,21 +907,34 @@
 				$sql_g .= "$".strval($i+1);
 				array_push($v,$mb_user_groups[$i]);
 				array_push($t,"i");
+				$numberOfGroups = $i;
 			}
 			$sql_g .= ") GROUP BY gui.gui_id";
+
+                	if ($categoryFilter != false) {
+		    	    $sql_g = "SELECT fkey_gui_id as gui_id from gui_gui_category as gui_id WHERE fkey_gui_id IN "."(".$sql_g.") AND fkey_gui_category_id = $".strval($numberOfGroups+2);
+		    	    array_push($v, $categoryFilter);
+		    	    array_push($t, "i");
+			}
 			$res_g = db_prep_query($sql_g,$v,$t);
 			while($row = db_fetch_array($res_g)){
 				array_push($arrayGuis,$row["gui_id"]);
 			}
 		}
+
 		$sql_guis = "SELECT gui.gui_id FROM gui JOIN gui_mb_user ON gui.gui_id = gui_mb_user.fkey_gui_id";
 		$sql_guis .= " WHERE (gui_mb_user.fkey_mb_user_id = $1) ";
-		if (!isset($ignore_public) OR $ignore_public== false){
+		if (!isset($ignorePublic) OR $ignorePublic== false){
 			$sql_guis .= " AND gui.gui_public = 1 ";
 		}
 		$sql_guis .= " GROUP BY gui.gui_id";
-		$v = array($mb_user_id);
+                $v = array($mb_user_id);
 		$t = array("i");
+                if ($categoryFilter != false) {
+		    $sql_guis = "SELECT fkey_gui_id as gui_id from gui_gui_category as gui_id WHERE fkey_gui_id IN "."(".$sql_guis.") AND fkey_gui_category_id = $2";
+		    array_push($v, $categoryFilter);
+		    array_push($t, "i");
+		}
 		$res_guis = db_prep_query($sql_guis,$v,$t);
 		$guis = array();
 		while($row = db_fetch_array($res_guis)){

Modified: trunk/mapbender/http/php/mod_editFilteredUser.php
===================================================================
--- trunk/mapbender/http/php/mod_editFilteredUser.php	2019-09-17 14:02:32 UTC (rev 10259)
+++ trunk/mapbender/http/php/mod_editFilteredUser.php	2019-09-17 14:39:24 UTC (rev 10260)
@@ -52,6 +52,7 @@
 $action = $_POST["action"];
 $is_active = $_POST["is_active"];
 $create_digest = $_POST["create_digest"];
+$fkey_preferred_gui_id = $_POST["fkey_preferred_gui_id"];
 require_once(dirname(__FILE__)."/../classes/class_user.php");
 $myUser = true;
 include "../../lib/editUser.php";

Modified: trunk/mapbender/http/php/mod_editUser.php
===================================================================
--- trunk/mapbender/http/php/mod_editUser.php	2019-09-17 14:02:32 UTC (rev 10259)
+++ trunk/mapbender/http/php/mod_editUser.php	2019-09-17 14:39:24 UTC (rev 10260)
@@ -25,7 +25,7 @@
 //security_patch_log(__FILE__,__LINE__);
 //import_request_variables("PG");
 
-$postvars = explode(",", "selected_user,name,firstname,lastname,academic_title,password,password_plain,v_password,description,email,phone,facsimile,street,housenumber,delivery_point,postal_code,city,organization,department,position,country,owner_name,owner_id,login_count,resolution,action,is_active, create_digest");
+$postvars = explode(",", "selected_user,name,firstname,lastname,academic_title,password,password_plain,v_password,description,email,phone,facsimile,street,housenumber,delivery_point,postal_code,city,organization,department,position,country,owner_name,owner_id,login_count,resolution,action,is_active, create_digest,fkey_preferred_gui_id");
 foreach ($postvars as $value) {
    ${$value} = $_POST[$value];
 }

Modified: trunk/mapbender/lib/editUser.php
===================================================================
--- trunk/mapbender/lib/editUser.php	2019-09-17 14:02:32 UTC (rev 10259)
+++ trunk/mapbender/lib/editUser.php	2019-09-17 14:39:24 UTC (rev 10260)
@@ -141,6 +141,12 @@
 </head>
 <body>
 <?php
+if (defined("PREFERRED_GUI_CATEGORY") && is_int(PREFERRED_GUI_CATEGORY)) {
+    $preferredGuiCategory = PREFERRED_GUI_CATEGORY;
+} else {
+    $preferredGuiCategory = false;
+}
+
 //TODO: important - to extent form mod_editUser.php and mod_editFilteredUser.php have to include the allowed HTTP POST variables!!!!!!!!!!!
 #delete
 if ($action == 'delete' && (!isset($editSelf) || !$editSelf)) {
@@ -197,6 +203,7 @@
 				$user->isActive = 'f';
 				break;
 		}
+		$user->preferredGui = $fkey_preferred_gui_id;
 		$user->create();
 		$user->setNewUserPasswordTicket();
 		//TODO: check function !
@@ -258,10 +265,11 @@
 				$user->isActive = 'f';
 				break;
 		}
+		$user->preferredGui = $fkey_preferred_gui_id;
 		$user->commit();
 
 		$user->setNewUserPasswordTicket();
-		
+
 		if($withPasswordInsertion == 'true' && $password !== '' && $user->validUserPasswordTicket($user->passwordTicket)) {
 			$user->setPassword($password, $user->passwordTicket);
 			echo "<script language='JavaScript'>alert('Password has been updated successfully!');</script>";
@@ -300,6 +308,7 @@
   $country = "";
   $is_active = 'f';
   $create_digest = 'f';
+  $fkey_preferred_gui_id = "";
 }
 
 
@@ -336,7 +345,8 @@
 		*/
 		$user = new User(intval($selected_user));
 		$data = $user->getFields();
-		
+		//$available Guis :
+		//$e = new mb_exception("guis:".json_encode($user->getApplicationsByPermission (false, 2)));
 		if ($selected_user && intval($selected_user) === $user->id) {
 			echo '<option value="'.htmlentities($user->id, ENT_QUOTES, 'UTF-8').'" title="'.htmlentities($user->email, ENT_QUOTES, 'UTF-8').'" selected="selected">'.htmlentities($user->name, ENT_QUOTES, "UTF-8").'</option>';
 		}
@@ -374,7 +384,8 @@
 		$city = $data["city"];
 		$country = $data["country"];
 		$is_active = $data["isActive"];
-		$create_digest = $data["createDigest"];	
+		$create_digest = $data["createDigest"];
+		$fkey_preferred_gui_id = $data["preferredGui"];
 	}
 }
 
@@ -584,6 +595,15 @@
    echo "</td>";
 echo "</tr>";
 
+#preferredGui
+if ($preferredGuiCategory != false && count($user->getApplicationsByPermission(false, $preferredGuiCategory)) > 0) {
+echo "<tr>";
+   echo "<td>"._mb("Preferred GUI")." (".implode(",", $user->getApplicationsByPermission(false, $preferredGuiCategory))."): </td>";
+   echo "<td>";
+      echo "<input type='text' size='30' name='fkey_preferred_gui_id' value='".htmlentities($fkey_preferred_gui_id, ENT_QUOTES, "UTF-8")."'>";
+   echo "</td>";
+echo "</tr>";
+}
 # blank row
 echo "<tr>";
    echo "<td colspan='2'> </td>";

Modified: trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.8_pgsql_UTF-8.sql
===================================================================
--- trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.8_pgsql_UTF-8.sql	2019-09-17 14:02:32 UTC (rev 10259)
+++ trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.8_pgsql_UTF-8.sql	2019-09-17 14:39:24 UTC (rev 10260)
@@ -135,3 +135,19 @@
 -- 2019-09-13 - update css to have a nicer default gui!
 update gui_element set e_width=null, e_height=null where e_id = 'body' AND fkey_gui_id IN ( 'Administration_DE', 'PortalAdmin_DE', 'admin1');
 
+-- 2019-0-17 - add option to have a preferred gui defined for a user account
+-- Column: fkey_preferred_gui_id
+
+-- ALTER TABLE mb_user DROP COLUMN fkey_preferred_gui_id;
+
+ALTER TABLE mb_user ADD COLUMN fkey_preferred_gui_id character varying(50);
+
+-- Foreign Key: fkey_preferred_gui_id_fkey
+
+-- ALTER TABLE mb_user DROP CONSTRAINT fkey_preferred_gui_id_fkey;
+
+ALTER TABLE mb_user
+  ADD CONSTRAINT fkey_preferred_gui_id_fkey FOREIGN KEY (fkey_preferred_gui_id)
+      REFERENCES gui (gui_id) MATCH SIMPLE
+      ON UPDATE CASCADE;
+



More information about the Mapbender_commits mailing list