[Mapbender-commits] r2708 - in branches/dev_lenkne: http/classes http/php lib

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jul 23 18:28:57 EDT 2008


Author: lenkne
Date: 2008-07-23 18:28:56 -0400 (Wed, 23 Jul 2008)
New Revision: 2708

Modified:
   branches/dev_lenkne/http/classes/class_administration.php
   branches/dev_lenkne/http/php/mod_adminEditFilteredUser.php
   branches/dev_lenkne/http/php/mod_adminFrame.php
   branches/dev_lenkne/lib/mb_admin_functions.js
Log:


Modified: branches/dev_lenkne/http/classes/class_administration.php
===================================================================
--- branches/dev_lenkne/http/classes/class_administration.php	2008-07-23 15:51:55 UTC (rev 2707)
+++ branches/dev_lenkne/http/classes/class_administration.php	2008-07-23 22:28:56 UTC (rev 2708)
@@ -590,13 +590,21 @@
 	}
 
 	function getAllFilteredUsers($owner) {
+		$allUsers = array();
 		$sql = "SELECT mb_user_id,mb_user_name,mb_user_email FROM mb_user ";
 		$sql .= " WHERE mb_user_owner = $1 ORDER BY mb_user_name ";
 		$v = array($owner);
-		$t = array('i');
+		$t = array('i'); 
 		$res = db_prep_query($sql, $v, $t);
-		$allUsers = $res;
-		return $allUsers;
+		while ($row = db_fetch_array($res)) {
+			array_push($allUsers, array("mb_user_id" => $row["mb_user_id"], "mb_user_name" => $row["mb_user_name"], "mb_user_email" => $row["mb_user_email"]));
+		}
+		$json = new Mapbender_JSON();
+		$output = $json->encode($allUsers);
+
+		header("Content-type:text/plain; charset=utf-8");
+		return $output;
+
 	}
 
 	function getAllUserColumns($userId) {
@@ -639,8 +647,7 @@
 			$i++;
 		}
 
-		$sqlArray = array_merge_recursive($columnArray, array_intersect_key($_REQUEST,  $columnArray));
-		return $sqlArray;
+		return $columnArray;
 	}
 
 	function deleteTableRecord($table,$keyField,$keyFieldValue) {

Modified: branches/dev_lenkne/http/php/mod_adminEditFilteredUser.php
===================================================================
--- branches/dev_lenkne/http/php/mod_adminEditFilteredUser.php	2008-07-23 15:51:55 UTC (rev 2707)
+++ branches/dev_lenkne/http/php/mod_adminEditFilteredUser.php	2008-07-23 22:28:56 UTC (rev 2708)
@@ -21,6 +21,12 @@
 require_once(dirname(__FILE__)."/../classes/class_json.php");
 require_once(dirname(__FILE__)."/../classes/class_administration.php");
 
+$admin = new administration();
+$json = new Mapbender_JSON();
+$queryObj = $json->decode(stripslashes($_REQUEST['queryObj']));
+$resultObj = array();
+//$e = new mb_exception("command: " . $queryObj->command);
+
 function sendOutput($out){
     global $json;
     $output = $json->encode($out);
@@ -28,38 +34,32 @@
     echo $output;
 }
 
-function showAllFilteredUsers($owner) {
+switch ($queryObj->command) {
 
-	$admin = new administration();
-	$allUsers = $admin->getAllFilteredUsers($owner);
+case "showUser":
 
-	$i=0;
-	while($row = db_fetch_array($allUsers)){
-		echo "<li onclick='showUser(\"".$_REQUEST["module"]."\",\"".$row["mb_user_id"]."\")'>".$row["mb_user_name"];
-			if ($row["mb_user_email"]) {
-				echo " (".$row["mb_user_email"].")";
-			}
-		echo "</li>";
-	$i++;
+	$userDetail = $admin->getAllUserColumns($queryObj->parameters->mb_user_id);
+
+	if ($userDetail) {
+		$resultObj["success"] = true;
+		$resultObj["data"] = $userDetail;
+		$resultObj["command"] = "refreshUser";
 	}
-	echo "</ul></div>";
+	else {
+		$resultObj["success"] = false;
+		$resultObj["message"] = "User information not found.";
+	}
 
-}
+break;
 
-$admin = new administration();
-$json = new Mapbender_JSON();
-$queryObj = $json->decode(stripslashes($_REQUEST['queryObj']));
-$resultObj = array();
+case "showFilteredUsers":
 
-switch ($_REQUEST["action"]) {
+	$filteredUsers = $admin->getAllFilteredUsers($_SESSION["mb_user_id"]);
 
-case "showUser":
-
-	$userDetail = $admin->getAllUserColumns($_REQUEST["mb_user_id"]);
-	if ($userDetail) {
+	if ($filteredUsers) {
 		$resultObj["success"] = true;
-		$resultObj["data"] = $userDetail;
-		$resultObj["action"] = "refreshUser";
+		$resultObj["data"] = $filteredUsers;
+		$resultObj["command"] = "refreshFilteredUsers";
 	}
 	else {
 		$resultObj["success"] = false;
@@ -68,64 +68,139 @@
 
 break;
 
-case "update":
+case "updateUser":
 
-	$dbUserId = $admin->getUserIdByUserName($_REQUEST["mb_user_name"]);
+	$dbUserId = $admin->getUserIdByUserName($queryObj->parameters->mb_user_name);
 
-	if($dbUserId != $_REQUEST["mb_user_id"]){
+	if($dbUserId != $queryObj->parameters->mb_user_id){
 		$resultObj["success"] = false;
 		$resultObj["message"] = "Username must be unique. Select a different name.";
 	}
-	else{
-		$sqlArray = $admin->getTableColumns(mb_user,mb_user_id,$_REQUEST["mb_user_id"]);
+	else{ 
+		$tableColumns = $admin->getTableColumns(mb_user,mb_user_id,$queryObj->parameters->mb_user_id);
 
+		$parameters = array();
+
+		foreach ($queryObj->parameters as $keyq => $valueq) {
+			$parameters[$keyq] = $valueq;
+		}
+
+		$sqlArray = array_merge_recursive($tableColumns, array_intersect_key($parameters, $tableColumns));
+
 		$res = "";
 		$sql = "UPDATE mb_user SET ";
 		$i = 0;
-		$j = 1;
 		foreach ($sqlArray as $key => $value) {
 			if ($value[1]) {
-				if ($j == 1) {
-					$sql.= $key . "=$" . $j;
+				if (($i+1) == 1) { 
+					$sql.= $key . "=$" . ($i+1);
 				}
 				else {
-					$sql.= "," . $key . "=$" . $j;
+					$sql.= "," . $key . "=$" . ($i+1);
 				}
 			$t[$i] = $value[0];
-			if ($j == 3) { // for password
+			if ($key == "mb_user_password") { // for password
 				$v[$i] = md5($value[1]);
 			}
 			else {
 				$v[$i] = $value[1];
 			}
 			$i++;
-			$j++;
 			}
 		}
 		$sql.= " WHERE mb_user_id = $1";
 		$res = db_prep_query($sql,$v,$t);	
-		
+
 		if ($res) {
 			$resultObj["success"] = true;
-			$resultObj["data"] = $admin->getAllUserColumns($_REQUEST["mb_user_id"]);
-			$resultObj["action"] = "refreshUser";
+			$resultObj["data"] = $admin->getAllUserColumns($queryObj->parameters->mb_user_id);
+			$resultObj["command"] = "refreshUser";
 			$resultObj["message"] = "User updated.";
 		}
 		else {
 			$resultObj["success"] = false;
-			$resultObj["message"] = "Error. User not saved.";
+			$resultObj["message"] = "Error. User not updated.";
 		}
 	}
+break;
 
+case "insertUser":
+
+	$dbUserId = $admin->getUserIdByUserName($queryObj->parameters->mb_user_name);
+
+	if($dbUserId != $queryObj->parameters->mb_user_id){
+		$resultObj["success"] = false;
+		$resultObj["message"] = "Username must be unique. Select a different name.";
+	}
+	else{
+		$tableColumns = $admin->getTableColumns(mb_user,mb_user_id,$queryObj->parameters->mb_user_id);
+
+		$parameters = array();
+
+		foreach ($queryObj->parameters as $keyq => $valueq) {
+			$parameters[$keyq] = $valueq;
+		}
+
+		$sqlArray = array_merge_recursive($tableColumns, array_intersect_key($parameters, $tableColumns));
+
+		$res = "";
+		$sql = "INSERT INTO mb_user (";
+		$i = 0;
+		foreach ($sqlArray as $key => $value) { //Adds the field names, $v & $t
+			if ($value[1]) {
+				if (($i+1) == 1) {
+					$sql.= $key;
+				}
+				else {
+					$sql.= "," . $key;
+				}
+			$t[$i] = $value[0];
+			if ($key == "mb_user_password") { // for password
+				$v[$i] = md5($value[1]);
+			}
+			else {
+				$v[$i] = $value[1];
+			}
+			$i++;
+			}
+		}
+		$sql.=") VALUES (";
+		$i = 0;
+		foreach ($sqlArray as $key => $value) {  //Adds field values from form
+			if ($value[1]) {
+				if (($i+1) == 1) {
+					$sql.= "$" . ($i+1);
+				}
+				else {
+					$sql.= ",$" . ($i+1);
+				}
+			$i++;
+			}
+		}
+		$sql.=")";
+
+		$res = db_prep_query($sql,$v,$t);	
+
+		if ($res) {
+			$resultObj["success"] = true;
+			$resultObj["data"] = $admin->getAllUserColumns($queryObj->parameters->mb_user_id);
+			$resultObj["command"] = "refreshUser";
+			$resultObj["message"] = "User created.";
+		}
+		else {
+			$resultObj["success"] = false;
+			$resultObj["message"] = "Error. User not created.";
+		}
+	}
 break;
 
 case "deleteUser":
 
-	$result = $admin->deleteTableRecord(mb_user,mb_user_id,$_REQUEST["mb_user_id"]);
+	$result = $admin->deleteTableRecord(mb_user,mb_user_id,($queryObj->parameters->mb_user_id));
 	if ($result == true) {
 		$resultObj["success"] = true;
 		$resultObj["data"] = $result;
-		$resultObj["action"] = "refreshUser";
+		$resultObj["command"] = "refreshUser";
 		$resultObj["message"] = "User Deleted.";
 	}
 	else {
@@ -142,12 +217,13 @@
 ?>
 
 <div id="main">
-	<h2>Create and edit user</h2>
+	<h2>Create or edit user</h2>
 	<form id="form" name="form" action="" method="post">
 	<fieldset>
 		<p>
-			<input type="button" id="action" name="action" value="update" onclick="updateUser('mod_adminEditFilteredUser')" /> 
-			<input type="button" id="delete" name="save" value="Delete" onclick="deleteUser('mod_adminEditFilteredUser')" /> 
+			<input type="button" id="insert" name="insert" value="Create" onclick="insertUser('mod_adminEditFilteredUser')" /> 
+			<input type="button" id="update" name="update" value="Update" onclick="updateUser('mod_adminEditFilteredUser')" /> 
+			<input type="button" id="delete" name="delete" value="Delete" onclick="deleteUser('mod_adminEditFilteredUser')" /> 
 			<input type="button" id="cancel" name="cancel" value="Cancel" onclick="loadAction('mod_adminEditFilteredUser',this);" /> 
 		</p>
 	</fieldset>
@@ -172,7 +248,7 @@
 
 	</fieldset>
 
-	<fieldset>
+	<fieldset style="visibility:show">
 		<p>
 			<label for="mb_user_description">Description:</label> 
 			<input type="text" id="mb_user_description" name="mb_user_description" value="" /> 
@@ -238,25 +314,23 @@
 		</p>
 		<p>
 			<label for="mb_user_owner">Owner:</label> 
-			<input type="text" id="mb_user_owner" name="mb_user_owner" value="" /> 
+			<input type="text" id="mb_user_owner" name="mb_user_owner" value="<? $_SESSION["mb_user_id"] ?>" /> 
 		</p>
 	</fieldset>
 	</form>
 </div>
+
 <div id="options">
-	<h2>Current users</h2>
+<h2>Current users</h2>
 
 <h3>Search by name</h3>
 <input type="text" id="searchText" name="searchText" value="" style="width:200" /> 
-<input type="button" id="search" name="search" value="Go" onclick="search();" />
+<input type="button" id="search" name="search" value="Go" onclick="showFilteredUsers('mod_adminEditFilteredUser')" />
 <h3>Current users</h3>
-<ul>
-
+<div id="usersList"></div>
+</div>
 <?php
 
-showAllFilteredUsers($_SESSION["mb_user_id"]);
-//TODO - This works to populate the initial page with users, but cannot be updated with changes, deletion, and addition of new users
-
 break; //for default case
 } // end switch
 

Modified: branches/dev_lenkne/http/php/mod_adminFrame.php
===================================================================
--- branches/dev_lenkne/http/php/mod_adminFrame.php	2008-07-23 15:51:55 UTC (rev 2707)
+++ branches/dev_lenkne/http/php/mod_adminFrame.php	2008-07-23 22:28:56 UTC (rev 2708)
@@ -1,3 +1,5 @@
 <?php
 require_once(dirname(__FILE__)."/../../lib/mb_admin_functions.js");
+// require_once(dirname(__FILE__)."/../extensions/ui.core.js");
+// require_once(dirname(__FILE__)."/../extensions/ui.accordion.js");
 ?>

Modified: branches/dev_lenkne/lib/mb_admin_functions.js
===================================================================
--- branches/dev_lenkne/lib/mb_admin_functions.js	2008-07-23 15:51:55 UTC (rev 2707)
+++ branches/dev_lenkne/lib/mb_admin_functions.js	2008-07-23 22:28:56 UTC (rev 2708)
@@ -1,5 +1,4 @@
-
-    <script type="text/javascript" src="form.js"></script> 
+<script type="text/javascript" src="form.js"></script> 
  
 var fullscreenProgressIndicator;
 var wrapperContainer;
@@ -122,6 +121,7 @@
 	mb_localizeDiv();
 });
 
+//TODO This needs to be replaced with GETTEXT
 function updateDivTitle(obj){
 	showFullscreenProgressIndicator();
 	var locArray= document.getElementsByTagName("li");
@@ -162,8 +162,8 @@
 	var resultObj = eval("(" + result + ")");
 	if (resultObj.success == true) {
 		data = eval(resultObj.data);
-		action = eval(resultObj.action);
-		action(data);
+		command = eval(resultObj.command);
+		command(data);
 		if (resultObj.message) {
 			alert(resultObj.message);
 		}
@@ -177,10 +177,15 @@
 		alert("Error.");
 	}	
 }
-//TODO fix Parameters like Christoph example
 function showUser(module, mb_user_id) {
 	showFullscreenProgressIndicator();
-	mb_ajax_post('../php/' + module + '.php', {module: module, action:"showUser", mb_user_id: mb_user_id}, function(result, status) {
+	var queryObj = {module: module, 
+			command:"showUser", 
+			parameters:{
+				mb_user_id: mb_user_id
+			}
+	};
+	$.post('../php/' + module + '.php',{queryObj: $.toJSON(queryObj)}, function(result, status) {
   		if (result && status == "success") {
 			processAjax(result);
 		}
@@ -191,27 +196,99 @@
 	});
 }
 
-function refreshUser(obj) {
+function refreshUser(resultObj) {
 	showFullscreenProgressIndicator();
 	var userArray= document.getElementsByTagName('input');
 	for(var i=0;i<userArray.length;i++){
-		for(var j=0;j<obj.length;j++){
-			if(userArray[i].id==obj[j].id){
-				document.getElementById(userArray[i].id).value=obj[j].value;
+		for(var j=0;j<resultObj.length;j++){
+			if(userArray[i].id==resultObj[j].id){
+				document.getElementById(userArray[i].id).value=resultObj[j].value;
 			}
 		}
 	}
+	showFilteredUsers('mod_adminEditFilteredUser');
 	hideFullscreenProgressIndicator();
 }
 
+function showFilteredUsers(module) {
+	showFullscreenProgressIndicator();
+	var queryObj = {module: module, 
+			command:"showFilteredUsers", 
+//			parameters:{
+//				mb_user_id: mb_user_id
+//			}
+	};
+	$.post('../php/' + module + '.php',{queryObj: $.toJSON(queryObj)}, function(result, status) {
+  		if (result && status == "success") {
+			processAjax(result);
+		}
+		else {
+			alert("Error.");
+		}
+	hideFullscreenProgressIndicator();
+	});
+}
+
+function refreshFilteredUsers(resultObj) {
+	var user = '';
+	showFullscreenProgressIndicator();
+	for(var i=0;i<resultObj.length;i++){
+		user += "<li onclick=\"showUser('mod_adminEditFilteredUser'," + resultObj[i].mb_user_id + ")\">";
+		user += resultObj[i].mb_user_name;
+		if (resultObj[i].mb_user_email) {
+			user += " (" + resultObj[i].mb_user_email + ")";
+		}
+		user += "</li>";
+	}
+	document.getElementById("usersList").innerHTML=user;
+	hideFullscreenProgressIndicator();
+
+}
+
 function updateUser(module) {
-	var postArray= document.getElementsByTagName('input');
-	var postText = "module=" + module;
+	showFullscreenProgressIndicator();
+	var postArray = document.getElementsByTagName('input');
+	var parameters = new Object();
+
 	for(var i=0;i<postArray.length;i++){
-		postText += "&" + postArray[i].id + "=" + postArray[i].value;
+		if (postArray[i].value.length > 0) { //If input field null, don't send
+			var id = postArray[i].id;
+			parameters[id] = postArray[i].value;
+		}
 	}
+	var queryObj = {module: module,
+			command:"updateUser",
+			parameters: parameters
+	};
+
+	$.post('../php/' + module + '.php',{queryObj: $.toJSON(queryObj)}, function(result, status) {
+  		if (result && status == "success") {
+			processAjax(result);
+		}
+		else {
+			alert("Error.");
+		}
+	hideFullscreenProgressIndicator();
+	});
+}
+
+function insertUser(module) {
 	showFullscreenProgressIndicator();
-	mb_ajax_post('../php/' + module + '.php', postText, function(result, status) {
+	var postArray = document.getElementsByTagName('input');
+	var parameters = new Object();
+	
+	for(var i=0;i<postArray.length;i++){
+		if (postArray[i].value.length > 0) { //If input field null, don't send
+			var id = postArray[i].id;
+			parameters[id] = postArray[i].value;
+		}
+	}
+	var queryObj = {module: module,
+			command:"insertUser",
+			parameters: parameters
+	};
+
+	$.post('../php/' + module + '.php',{queryObj: $.toJSON(queryObj)}, function(result, status) {
   		if (result && status == "success") {
 			processAjax(result);
 		}
@@ -224,11 +301,17 @@
 
 //TODO put YES/NO to make sure they really want to delete user
 function deleteUser(module) {
-	var postText = "module=" + module;
-	postText += "&action=deleteUser&";
-	postText += "mb_user_id=" + document.getElementById('mb_user_id').value;
 	showFullscreenProgressIndicator();
-	mb_ajax_post('../php/' + module + '.php',postText, function(result, status) {
+	var queryObj = {module: module, 
+			command: "deleteUser", 
+			parameters:{
+				mb_user_id: document.getElementById('mb_user_id').value
+			}
+
+//			mb_user_id: document.getElementById('mb_user_id').value
+	};
+
+	$.post('../php/' + module + '.php',{queryObj: $.toJSON(queryObj)}, function(result, status) {
   		if (result && status == "success") {
 			processAjax(result);
 		}



More information about the Mapbender_commits mailing list