<!--#include virtual="/includes/topofpage.asp"-->
<%

Dim Page 
Page = "45"

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

%>
<%
If UCase(Request.ServerVariables("REQUEST_METHOD")) = "POST" And Request("Page") = Page And (Request("cont") = "1" Or Request("cont") = "2") Then

	If Request("Title_ID") = "" Then
		 Response.Write "Please select a Title"
		 Response.End
	Else
		SQL = "Delete_Key_Ring_Title_Map @Title_ID='" & Replace(Request("Title_ID"), "'", "''") & "', @Key_Ring_ID='%'"
		Conn.Execute(SQL)
		For each Key_Ring_ID In Request("Key_Ring_List")
			SQL = "Add_Key_Ring_Title_Map @Title_ID='" & Replace(Request("Title_ID"), "'", "''") & "', @Key_Ring_ID='" & Replace(Key_Ring_ID, "'", "''") & "'"
			Conn.Execute(SQL)
		Next
	End If

End If


Function Get_Realms_DD (Realm_ID, Sel_ID)
   SQL	=	"Get_Realms @Realm_ID='" & Realm_ID & "'"
   HTML =	""
   Set Realm = Conn.Execute(SQL)
   Do While Not Realm.EOF
		Realm_Desc = Realm("Realm_Description")
		If isNull(Realm_Desc) Or Realm_Desc = "" Then
			Realm_Desc = Realm("Realm_Name")
		End If
		HTML = HTML & "<option value=""" & Realm("Realm_ID") & """"
		ID = Realm("Realm_ID")
		On Error Resume Next
		For each Sel in Request(Sel_ID)
			If ID = Int(Sel) Then HTML = HTML & " selected"
			If ID = Sel Then HTML = HTML & " selected"
		Next
		On Error Goto 0
		HTML = HTML & ">" & Realm_Desc & "</option>"
		Realm.MoveNext
	Loop
   Set Realm = Nothing
   Get_Realms_DD = HTML
End Function

Function Get_Key_Types_DD (Key_Type_ID, Sel_ID)
   SQL	=	"Get_Key_Types @Key_Type_ID='" & Key_Type_ID & "'"
   HTML =	""
   Set Key_Type = Conn.Execute(SQL)
   Do While Not Key_Type.EOF
		Key_Type_Desc = Key_Type("Key_Type_Desc")
		If isNull(Key_Type_Desc) Or Key_Type_Desc = "" Then
			Key_Type_Desc = Key_Type("Key_Type_Name")
		End If
		HTML = HTML & "<option value=""" & Key_Type("Key_Type_ID") & """"
		If Not Request(Sel_ID) = "%" And Not Request(Sel_ID) = "" Then
		ID = Key_Type("Key_Type_ID")
			On Error Resume Next
			For each Sel in Request(Sel_ID)
				If ID = Int(Sel) Then HTML = HTML & " selected"
				If ID = Sel Then HTML = HTML & " selected"
			Next
			On Error Goto 0
		End If
		HTML = HTML & ">" & Key_Type_Desc & "</option>"
		Key_Type.MoveNext
	Loop
   Set Key_Type = Nothing
   Get_Key_Types_DD = HTML
End Function

Function Get_Keys_DD (Key_Type_ID, Realm_ID, Sel_ID)
   SQL	=	"Get_Keys @Key_Type_ID='" & Key_Type_ID & "', @Realm_ID='" & Realm_ID & "'"
   HTML =	""
   Set Keys = Conn.Execute(SQL)
   Do While Not Keys.EOF
		Key = Keys("Name")
		HTML = HTML & "<option value=""" & Keys("Key_ID") & """"
		ID = Keys("Key_ID")
		On Error Resume Next
		For each Sel in Request(Sel_ID)
			If ID = Int(Sel) Then HTML = HTML & " selected"
			If ID = Sel Then HTML = HTML & " selected"
		Next
		On Error Goto 0
		HTML = HTML & ">" & Key & "</option>"
		Keys.MoveNext
	Loop
   Set Keys = Nothing
   Get_Keys_DD = HTML
End Function

Function Get_Titles_DD (Title_ID, Sel_ID)
   SQL	=	"Get_Titles @Title_ID='" & Title_ID & "'"
   HTML =	""
   Set Title = Conn.Execute(SQL)
   Do While Not Title.EOF
		Title_Desc = Title("Title_Description")
		If isNull(Title_Desc) Or Title_Desc = "" Then
			Title_Desc = Title("Title")
		End If
		HTML = HTML & "<option value=""" & Title("Title_ID") & """"
		ID = Title("Title_ID")
		On Error Resume Next
		For each Sel in Request(Sel_ID)
			If Not Sel = "" Then
				If ID = Int(Sel) Then HTML = HTML & " selected"
				If ID = Sel Then HTML = HTML & " selected"
			End If
		Next
		On Error Goto 0
		HTML = HTML & ">" & Title_Desc & "</option>"
		Title.MoveNext
	Loop
   Set Title = Nothing
   Get_Titles_DD = HTML
End Function


Function Get_Realm (Realm_ID)
   SQL	=	"Get_Realms @Realm_ID='" & Realm_ID & "'"
   HTML =	""
   Set Realm = Conn.Execute(SQL)
   Do While Not Realm.EOF
		Realm_Desc = Realm("Realm_Description")
		If isNull(Realm_Desc) Or Realm_Desc = "" Then
			Realm_Desc = Realm("Realm_Name")
		End If
		HTML = HTML & Realm_Desc & "<br>"
		Realm.MoveNext
	Loop
   Set Realm = Nothing
   Get_Realm = HTML
End Function


Function Get_Realms_By_Realm_DD (Realm_ID, Sel_ID)
   SQL = "Get_Realms_By_Realm @Realm_ID='" & Realm_ID & "'"
   HTML =	""

	Set Realms = Conn.Execute(SQL)
	Do While Not Realms.EOF
		ID = Realms("Realm_ID_2")
		HTML = HTML & "<option value=""" & Realms("Realm_ID_2") & """"
		ID = Realms("Realm_ID_2")
		On Error Resume Next
		For each Sel in Request(Sel_ID)
			If ID = Int(Sel) Then HTML = HTML & " selected"
			If ID = Sel Then HTML = HTML & " selected"
		Next
		On Error Goto 0
		HTML = HTML & ">" & Realms("Realm_Name_2") & "</option>" & Chr(13)
		Realms.MoveNext
	Loop			

   Set Realm = Nothing
   Get_Realms_By_Realm_DD = HTML
End Function

Function Get_Key_Ring_DD (Key_Ring_Type_ID, Realm_ID, Sel_ID)
   SQL	=	"Get_Key_Ring @Key_Ring_Type_ID='" & Key_Ring_Type_ID & "', @Realm_ID='" & Realm_ID & "'"
   HTML =	""
   Set Key_Rings = Conn.Execute(SQL)
   Do While Not Key_Rings.EOF
		Key_Ring = Key_Rings("Key_Ring_Name")
		HTML = HTML & "<option value=""" & Key_Rings("Key_Ring_ID") & """"
		ID = Key_Rings("Key_Ring_ID")
		On Error Resume Next
		For each Sel in Request(Sel_ID)
			If ID = Int(Sel) Then HTML = HTML & " selected"
			If ID = Sel Then HTML = HTML & " selected"
		Next
		On Error Goto 0
		HTML = HTML & ">" & Key_Ring & "</option>"
		Key_Rings.MoveNext
	Loop
   Set Key_Rings = Nothing
   Get_Key_Ring_DD = HTML
End Function

Realm_ID = Request("Realm_ID")
Key_Ring_Type_ID = Request("Key_Ring_Type_ID")

If Realm_ID = "" Then Realm_ID="%"
If Key_Ring_Type_ID = "" Then Key_Ring_Type_ID = "%"



If (UCase(Request.ServerVariables("REQUEST_METHOD")) = "POST" And Request.Form("page") = Page) Then
    ' Linking to the next page
    If Request.Form("cont") = "1" Then Response.Redirect(Session("Default_Page"))

End If

If Not Request("From") = "" Then Session("Default_Page") = Request("From")
If Session("Default_Page") = "" Then Session("Default_Page") = "default-entities.asp"

Function Get_Key_Ring_Types_DD (Key_Ring_Type_ID, Sel_ID)
   SQL	=	"Get_Key_Ring_Types @Key_Ring_Type_ID='" & Key_Ring_Type_ID & "'"
   HTML =	""
   Set Key_Ring_Type = Conn.Execute(SQL)
   Do While Not Key_Ring_Type.EOF
		Key_Ring_Type_Desc = Key_Ring_Type("Key_Ring_Type_Desc")
		If isNull(Key_Ring_Type_Desc) Or Key_Ring_Type_Desc = "" Then
			Key_Ring_Type_Desc = Key_Ring_Type("Key_Ring_Type_Name")
		End If
		HTML = HTML & "<option value=""" & Key_Ring_Type("Key_Ring_Type_ID") & """"
		If Not Request(Sel_ID) = "%" And Not Request(Sel_ID) = "" Then
			ID = Key_Ring_Type("Key_Ring_Type_ID")
			On Error Resume Next
			For each Sel in Request(Sel_ID)
				If ID = Int(Sel) Then HTML = HTML & " selected"
				If ID = Sel Then HTML = HTML & " selected"
			Next
			On Error Goto 0
		End If
		HTML = HTML & ">" & Key_Ring_Type_Desc & "</option>"
		Key_Ring_Type.MoveNext
	Loop
   Set Key_Ring_Type = Nothing
   Get_Key_Ring_Types_DD = HTML
End Function

	If Request("cont") = "3" Then 

		Key_Ring_List = ""
		Drop_Down = ""
	
		For each Key_Ring in Request("Key_Ring_List")
			If InStr(1, Key_Ring_List, "|" & Key_Ring & "|") = 0 Then
				SQL	= "Get_Key_Ring @Key_Ring_ID='" & Key_Ring & "'"
				Set Key_Rings = Conn.Execute(SQL)
				Found = False
				For each List_Key_Ring in Request("Add_Key_Rings")
					If Key_Ring = List_Key_Ring Then
						Found = True
					End If
				Next
				If Found = False Then
					Key_Ring_List = Key_Ring_List & "|" & Key_Ring & "|" 
					Add_Key_Rings = Add_Key_Rings & "<input type=""hidden"" name=""Key_Ring_List"" value=""" & Key_Ring & """>" & Chr(13)
					Drop_Down = Drop_Down & "<option value=""" & Key_Ring & """"
					Drop_Down = Drop_Down & ">" & Key_Rings("Key_Ring_Name") & "</option>"
				End If
			End If
		Next

		For each Key_Ring in Request("Key_Rings")

			If InStr(1, Key_Ring_List, "|" & Key_Ring & "|") = 0 Then
				SQL	= "Get_Key_Ring @Key_Ring_ID='" & Key_Ring & "'"
				Set Key_Rings = Conn.Execute(SQL)
				Found = False
				For each List_Key_Ring in Request("Add_Key_Rings")
					If Key_Ring = List_Key_Ring Then
						Found = True
					End If
				Next
				If Found = False Then
					Key_Ring_List = Key_Ring_List & "|" & Key_Ring & "|" 
					Add_Key_Rings = Add_Key_Rings & "<input type=""hidden"" name=""Key_Ring_List"" value=""" & Key_Ring & """>" & Chr(13)
					Drop_Down = Drop_Down & "<option value=""" & Key_Ring & """"
					Drop_Down = Drop_Down & ">" & Key_Rings("Key_Ring_Name") & "</option>"
				End If
			End If
		Next

	ElseIf Request("cont") = "4" Or Request("cont") = "2" Then

		If Not Request("Title_ID") = "" Then
			SQL		=	"Get_Title_Key_Chain @Title_ID='" & Request("Title_ID") & "'"
			Set Title_Key_Rings = Conn.Execute(SQL)
			Do While Not Title_Key_Rings.EOF
				Found = False
				For each List_Key_Ring in Request("Add_Key_Rings")
					If Key_Ring = List_Key_Ring Then
						Found = True
					End If
				Next
				If Found = False Then
					Key_Ring_List = Key_Ring_List & "|" & Title_Key_Rings("Key_Ring_ID") & "|" 
					Add_Key_Rings = Add_Key_Rings & "<input type=""hidden"" name=""Key_Ring_List"" value=""" & Title_Key_Rings("Key_Ring_ID") & """>" & Chr(13)
					Drop_Down = Drop_Down & "<option value=""" & Title_Key_Rings("Key_Ring_ID") & """"
					Drop_Down = Drop_Down & ">" & Title_Key_Rings("Key_Ring_Name") & "</option>"
				End If
				Title_Key_Rings.MoveNext
			Loop
		End If		
	End If

   SQL		=	"Get_Key_Ring @Key_Ring_Type_ID='" & Key_Ring_Type_ID & "'"
   Sel_ID	=	"Key_Rings"
   HTML		=	""
   HTML1	=	""
   Set Key_Rings = Conn.Execute(SQL)
   Do While Not Key_Rings.EOF
		Key_Ring = Key_Rings("Key_Ring_Name")
		HTML1 = "<option value=""" & Key_Rings("Key_Ring_ID") & """"
		ID = Key_Rings("Key_Ring_ID")
		For each Sel in Request(Sel_ID)
			If Int(ID) = Int(Sel) Then HTML1 = HTML1 & " selected"
		Next
		HTML1 = HTML1 & ">" & Key_Ring & "</option>"
		If InStr(1, Key_Ring_List, "|" & ID & "|") = 0 Then 
			HTML = HTML & HTML1
		End If
		Key_Rings.MoveNext
	Loop
   Set Key_Rings = Nothing
   
   Show_Key_Rings = HTML

%>
<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 language="JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function Sub_Form (cont)
{
  form1.cont.value=cont
  form1.submit();
}
function refresher()
{
  form1.action = ""
  form1.cont.value='3'
  form1.submit();
}
function TitleChange()
{
  form1.action = ""
  form1.cont.value='4'
  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">
</head>

<body bgcolor="#ffffff" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('images/icon-return-to-main-2.gif','images/icon-submit-changes-2.gif','images/icon-continue-wizard-2.gif')">
<form name="form1" method="post" action="">
<INPUT type="hidden" id=page name=page value="<%=Page%>">
<INPUT type="hidden" id=cont name=cont >
<INPUT type="hidden" id="from" name="from" value="<%= Request("From")%>">
<%=Add_Key_Rings%>
  <table width="525" border="0" cellspacing="0" cellpadding="2" align="center">
    <tr> 
      <td width="338">&nbsp;</td>
      <td align="right" width="187">&nbsp;</td>
    </tr>
    <tr> 
      <td width="338" bgcolor="#5e5ebe" class="headline-ffffff" align="middle">Title to Permissions Mapping</td>
      <td bgcolor="#5e5ebe" align="right" width="187"><A onmouseover="MM_swapImage('Image1','','images/icon-return-to-main-2.gif',1)" onmouseout=MM_swapImgRestore() href="<%=Session("Default_Page")%>"><IMG height=17 src="images/icon-return-to-main.gif" width=75 useMap=#returntomain border=0 name=Image1></a></td>
    </tr>
		<tr> 
		<td class="galley-text-indent" colspan="2">Title to Permissions Mapping</td>
	    </tr>
	</table>
	<table width="500" border="0" cellspacing="0" cellpadding="2" align="center">
	    <tr> 
			<td>&nbsp;</td>
			<td>&nbsp;</td>
	    </tr>
	    <tr> 
		<td widht="30%">&nbsp;</td>
		<td align="left" class="manage-menu"><font size="1">

  <table width="100%" border="0" cellspacing="0" cellpadding="1" style="LEFT: 0px; TOP: 14px">
<!--  <TR>
    <TD align=right height=24 class="manage-menu">Applies to:</TD>
    <TD colspan="3" height=24 class="manage-menu"><select name="Realm_ID">
        <option value="">Select</option>
        <%=Get_Realms_By_Realm_DD(Session("Admin_Realm"), "Realm_ID")%></select></td>
  </TR>
-->
  <TR>
    <TD align=right height=24 class="manage-menu">Select Title:</TD>
    <TD width=166 height=24 colspan="3"><select name="Title_ID" onChange="TitleChange();">
    <option value="" <% If Request("Title_ID") = "" Then Response.Write " selected"%>>Choose a Title</option>
    <%=Get_Titles_DD("%", "Title_ID")%>
    <TD align=center height=24 class="manage-menu"></TD>
    <TD align=center height=24 class="manage-menu"></TD></TR>
  <TR>
    <TD align=right height=24 class="manage-menu">Key&nbsp;Ring&nbsp;Type:</TD>
    <TD height=24 colspan="3"><select name="Key_Ring_Type_ID" onChange="refresher();">
    <option value="%" <%If Key_Ring_Type_ID = "%" Then Response.Write " selected"%>>All Functionality</option>
    <%=Get_Key_Ring_Types_DD("%", "Key_Ring_Type_ID")%>
    <TD align=center height=24 class="manage-menu"></TD>
    <TD align=center height=24 class="manage-menu"></TD></TR>
  <TR>
    <TD align=right height=24 class="manage-menu">Key Rings:</TD>
    <TD height=24 colspan="3"><select name="Key_Rings" MULTIPLE SIZE="10">
    <%=Show_Key_Rings%>
    </select>&nbsp;<img src="images/dn.gif" onclick="refresher();">
    <!--<%=Get_Key_Ring_DD(Key_Ring_Type_ID, "%", "Key_Rings")%> -->
    <TD align=center height=24 class="manage-menu"></TD>
    <TD align=center height=24 class="manage-menu"></TD></TR>
  <TR>
    <TD align=right height=24 class="manage-menu">Title's Key Rings:</TD>
    <TD height=24 colspan="3"><select name="Add_Key_Rings" MULTIPLE SIZE="5">
    <%=Drop_Down%>
    </select>&nbsp;<img src="images/up.gif" onclick="refresher();">
    <!--<%=Get_Key_Ring_DD(Key_Ring_Type_ID, "%", "Key_Rings")%> -->
    <TD align=center height=24 class="manage-menu"></TD>
    <TD align=center height=24 class="manage-menu"></TD></TR>
    
</TBODY>
</table>


		</font></td>
	    </tr>
	    <tr> 
		<td>&nbsp;</td>
		<td>&nbsp;</td>
  	    </tr>		
	</table>
	<table width="525" border="0" cellspacing="0" cellpadding="0" align="center">
	  <tr bgcolor="#5e5ebe"> 
		<!-- -->
			<td align="right" width="49%" bgcolor="#5e5ebe">
			<a href="javascript:Sub_Form('1');" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('submitchanges','','images/icon-submit-changes-2.gif',1)">
			<img src="images/icon-submit-changes.gif" width="200" height="15" name="submitchanges" border="0">
		</a>
	   </td>
       <td width="51%">
		<a href="javascript:Sub_Form('2');" onmouseover="MM_swapImage('Image2','','images/icon-continue-wizard-2.gif',1)"  onmouseout=MM_swapImgRestore()>
			<img src="images/icon-continue-wizard.gif" width="150" height="15" usemap="#continue" border="0" name="Image2">
		</a>
	   </td>
	  </tr>
	  <tr> 
	    <td width="49%">&nbsp;</td>
	    <td width="51%">&nbsp;</td>
	  </tr>
	</table> 
</form>
</body>
</html>



