<!--#include virtual="/includes/topofpage.asp"-->
<%
'Response.Write "Will be here soon! <A HREF=""javascript:history.back()"">Click here to Return</a>"
'Response.End

'  If Not Request.QueryString("ID") = "" Then Session("Group_ID") = Request.QueryString("ID")

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open Application("conn_string")

Page="64"

User_ID = Request("UID")

If Not User_ID = "" Then
	SQL = "Get_User @User_ID='" & User_ID & "'"
'	Response.Write SQL
	Set Get_User = Conn.Execute(SQL)
	Create_Date = Get_User("User_CreateDate")
	User_Name = Get_User("User_Name")
	Set Get_User = Nothing
End If


If Not User_ID = "" And UCase(Request.ServerVariables("REQUEST_METHOD")) = "POST" And Request("page") = Page Then
	
	SQL = "Delete_User_Key_Ring_Map @User_ID='" & User_ID & "', @Key_Ring_ID = '%', @Realm_ID='%'"
	Conn.Execute(SQL)

	For each Realm_ID in Request("Realms")
		For each Key_Ring_ID in Request("Key_Ring_" & Realm_ID & "")
			If Not Key_Ring_ID = "" Then
				SQL = "Add_User_Key_Ring_Map @User_ID='" & User_ID & "', @Key_Ring_ID = '" & Key_Ring_ID & "', @Realm_ID='" & Realm_ID & "'"
				Conn.Execute(SQL)
			End If
		Next
	Next

	SQL = "Update_User_Key_Chain @User_ID='" & User_ID & "', @Realm_ID='%'"
	Conn.Execute(SQL)

	Response.Redirect("/admin/user_admin.asp?GID=" & Request("GID") & "&CID=" & Request("CID") & "&RID=" & Request("RID") & "")

End If

%>


<html>
<STYLE>
BODY {SCROLLBAR-FACE-COLOR: #5e5ebe; SCROLLBAR-HIGHLIGHT-COLOR: #5e5ebe; SCROLLBAR-SHADOW-COLOR: #5e5ebe; SCROLLBAR-3DLIGHT-COLOR: #5e5ebe; SCROLLBAR-ARROW-COLOR:  #6666CC; SCROLLBAR-TRACK-COLOR: #E3E3E3; SCROLLBAR-DARKSHADOW-COLOR: #666666; }
</STYLE>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">






<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--

function updatechain() {
	var errmsg='';
	if (errmsg) alert(errmsg);
	else {
		form1.action='';
		form1.submit();
	}
}

//-->
</SCRIPT>

<link rel="stylesheet" href="/Style-sheets/standard-input-form.css" type="text/css">
<link rel="stylesheet" href="/Style-sheets/headline.css" type="text/css">
<link rel="stylesheet" href="/Style-sheets/galley-text-indent.css" type="text/css">
<link rel="stylesheet" href="/Style-sheets/Lodging-display.css" type="text/css">
</head>
<body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<FORM action="contact_edit.asp" method=post id=form1 name=form1>
<input type="hidden" name="page" value="<%=Page%>">
<input type="hidden" name="cid" value="<%=Request("cid")%>">
<input type="hidden" name="rid" value="<%=Request("rid")%>">
<input type="hidden" name="gid" value="<%=Request("gid")%>">
<input type="hidden" name="uid" value="<%=Request("uid")%>">
<Br>  
<table border="0" cellspacing="0" cellpadding="0" width="590" style="WIDTH: 290px" align="center">
  <tr>
	<td width="100%"></td>
  </tr>
  <tr> 
    <td colspan="2" valign="top" align="center" bgcolor="#77aadd"><font color="#e7e7e7">Manage User's Key Chain</font></td>
  </tr>
  <tr>
	<td bgcolor="#e7e7e7" colspan="2"><img src="/images/shim.gif" height="1" width="1"></td>
  </tr>
  <tr>
	<td align="right" valign="top" bgcolor="#e7e7e7">
<% If User_ID = "" Then %>
	<div align="center">
	No User Passed. Please report this problem to support@emagineering.com. Thanks!
	</div>
<% Else %>

<br><div class="manage-menu">
User Name: <input type="text" name="user_name" value="<%=User_Name%>" style="{background-color:#e7e7e7;}" readonly>&nbsp;<br>
</div><br><div align="left" class="manage-menu">
<%
	SQL = "Get_User_Realms @User_ID='" & User_ID & "'"
	Set Realm = Conn.Execute(SQL)
	If Not Realm.EOF Then
		Do While Not Realm.EOF
			%>
				&nbsp;<%=Realm("Realm_Name")%><br>
				<select name="Key_Ring_<%=Realm("Realm_ID")%>" style="{width:90%}" align="center" MULTIPLE Size="5">
				<%
				SQL = "Get_Key_Ring @Realm_ID='" & Realm("Realm_ID") & "'"
				Set KR = Conn.Execute(SQL)
				
				SQL = "Get_User_Key_Chain @Realm_ID='" & Realm("Realm_ID") & "', @User_ID='" & User_ID & "'"
				Set UKR = Conn.Execute(SQL)
				
				
				If Not KR.EOF Then
					Do While Not KR.EOF
						Selected = ""
						If Not UKR.EOF Then
							Do While Not UKR.EOF
								If CStr(KR("Key_Ring_ID")) = CStr(UKR("Key_Ring_ID")) Then Selected = " selected"
								Response.Write UKR("Key_Ring_ID") & "-" & KR("Key_Ring_ID") & Chr(13)
								UKR.MoveNext
							Loop
							UKR.MoveFirst
						End If
						%>
							<option value="<%=KR("Key_Ring_ID")%>"<%=Selected%>><%=KR("Key_Ring_Name")%></option>					
						<%
						
						KR.MoveNext
					Loop
				Else
				%>
					<option value="">No Key Rings Available</option>
				<%
				End If
				%>
				</select><input type="hidden" name="Realms" value="<%=Realm("Realm_ID")%>"><br><br>
				<%
			Realm.MoveNext
		Loop
		Realm.MoveFirst
	Else
		%>
		<b>No Realm Assignments Made</b><br><br>
		Cannot assign Keys at this time.
		<%
	End If
%>
<!--<br>
<select name="realms" SIZE="5" MULTIPLE>
<option value="" selected>User is not Active</option>
</select>-->
</div><br>
<% End If %>
	</td>
  </tr>
  <tr>
	<td align="center" valign="top" bgcolor="#cccccc"><div valign="top" align="center">
		<a href="user_admin.asp?CID=<%=Request("CID")%>&GID=<%=Request("GID")%>&RID=<%=Request("RID")%>"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><font color="#000099">Return to Management</font></b></font></a>
		<% If Not User_ID = "" Then %>&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="javascript:updatechain();"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><font color="#000099">Update Key Chain</font></b></font></a>&nbsp;
		<% End If %>
		</div></td>
  </tr>
 </table>

</FORM>
</body>
</html>
