<%
	response.cachecontrol = "no-cache"
%>
<!--#include file="../library/libraryinc.inc" -->
<%
	timeout(1)
	
	set con = server.createobject("ADODB.Connection")
	con.open Application("CString")
	
	if request.form("Posted") = "Y" then
	
		if request("MakeAssignment") <> empty then
		
			strSQL = "INSERT INTO RelatedNews(ContentID, FileID) VALUES("& request("id") &", "& request("MakeAssignment") &")"
			con.execute(strSQL)	
		
		end if
		
		con.close
		set con = nothing
		
		response.redirect("assign_content.asp?menuID="& request("menuID") &"&id="& request("id"))
	
	elseif request.form("Posted") = "Y2" then
	
		if request("MakeAssignment") <> empty then
		
			strSQL = "INSERT INTO RelatedNews(ContentID, FileID) VALUES("& request("MakeAssignment") &", "& request("id") &")"
			con.execute(strSQL)	
		
		end if
		
		con.close
		set con = nothing
		
		response.redirect("assign_content.asp?menuID="& request("menuID") &"&id="& request("id"))
	
	elseif request("deleteID") <> empty and IsNumeric(request("deleteID")) and request("id") <> empty and IsNumeric(request("id")) then
	
		if request("LinkFrom") = "TO" then
			strSQL = "DELETE FROM RelatedNews WHERE ContentID = "& request("deleteID") &" AND FileID = "& request("id")
		else
			strSQL = "DELETE FROM RelatedNews WHERE ContentID = "& request("id") &" AND FileID = "& request("deleteID")
		end if
			
		con.execute(strSQL)
	
		con.close
		set con = nothing
		
		response.redirect("assign_content.asp?menuID="& request("menuID") &"&id="& request("id"))
	
	end if
%>
<html>
<head>
<title>Website Administration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../StyleSheet.css" type="text/css">
</head>

<body>
<%if request("id") <> empty and IsNumeric(request("id")) and request("menuID") <> empty and IsNumeric(request("menuID")) then

	strSQL = "SELECT m.MenuID, m.MenuName, n.NewsID, n.Heading FROM Menu m, News n WHERE m.MenuID = "& request("menuID") &" AND m.NewsID = n.NewsID AND n.NewsID = "& request("id")
	set rsNews = con.execute(strSQL)
	
	if not rsNews.EOF then
		rsNews.movefirst
		
		intMenuID 		= rsNews("MenuID")
		strMenuName 	= rsNews("MenuName")
		intNewsID 		= rsNews("NewsID")
		strHeading 		= rsNews("Heading")
		%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="table_headings"><%=strMenuName%> / <%=strHeading%></td>
  </tr>
  <tr>
    <td class="table_content">
      <table border="0" cellspacing="0" cellpadding="1" width="100%">
        <form name="assign_frm" method="post" action="assign_content.asp">
          	 
          <tr> 
            <td colspan="2" class="table_subheadings"> <b>Related Pages/Documents  present on this Page.</b></td>
          </tr>
          <%
  strSQL = "SELECT n.NewsID, n.Heading FROM News n, RelatedNews r WHERE n.NewsID = r.FileID AND r.ContentID = "& request("id") &" ORDER BY n.Heading"
  set rsAssigned = con.execute(strSQL)
  
  if not rsAssigned.EOF then%>
          <%counterx=0%>
          <%do while not rsAssigned.EOF%>
          <!--#include file="../library/eyeline.asp" -->
          <tr bgcolor="<%=colorx%>"> 
            <td><b><%=rsAssigned("Heading")%></b></td>
            <td align="right"> 
              <input type="button" onClick="javascript:window.open('assign_content.asp?menuID=<%=request("menuID")%>&id=<%=request("id")%>&deleteID=<%=rsAssigned("NewsID")%>','_self');" name="Button" value=" Remove " class="Button">
      </td>
          </tr>
          <%rsAssigned.movenext%>
          <%loop%>
          <%end if%>
          <%set rsAssigned = nothing%>
          <%
  strSQL = "SELECT NewsID, Heading FROM News WHERE NewsID <> "& request("id") &" AND NewsID NOT IN (SELECT FileID FROM RelatedNews WHERE ContentID = "& request("id") &") ORDER BY Heading"
  set rsUnassigned = con.execute(strSQL)
    %>
          <tr> 
            <td>
		      <select name="MakeAssignment" class="TextBox">
                <option value="" selected>-- Select --</option>
                <%do while not rsUnassigned.EOF%>
                <option value="<%=rsUnassigned("NewsID")%>"><%=rsUnassigned("Heading")%></option>
                <%rsUnassigned.movenext%>
                <%loop%>
                <%set rsUnassigned = nothing%>
              </select>
      </td>
            <td align="right"> 
              <input type="submit" name="Submit2" value="    Add    " class="Button">
      </td>
          </tr>
          <input type="hidden" name="id" value="<%=request("id")%>">
          <input type="hidden" name="menuID" value="<%=request("menuID")%>">
          <input type="hidden" name="Posted" value="Y">
        </form>
      </table>
      <table border="0" cellspacing="0" cellpadding="1" width="100%">
        <form name="assignto_frm" method="post" action="assign_content.asp">
          	 
          <tr> 
            <td colspan="2" class="table_subheadings"> <b>Links to this Page are present on these Pages...</b></td>
          </tr>
          <%
  strSQL = "SELECT n.NewsID, n.Heading FROM News n, RelatedNews r WHERE n.NewsID = r.ContentID AND r.FileID = "& request("id") &" ORDER BY n.Heading"
  set rsAssigned = con.execute(strSQL)
  
  if not rsAssigned.EOF then%><%counterx=0%>
          <%do while not rsAssigned.EOF%>
<!--#include file="../library/eyeline.asp" -->
          <tr bgcolor="<%=colorx%>"> 
            <td><b><%=rsAssigned("Heading")%></b></td>
            <td align="right"> 
              <input type="button" onClick="javascript:window.open('assign_content.asp?menuID=<%=request("menuID")%>&id=<%=request("id")%>&deleteID=<%=rsAssigned("NewsID")%>&LinkFrom=TO','_self');" name="Button" value=" Remove " class="Button">
      </td>
          </tr>
          <%rsAssigned.movenext%>
          <%loop%>
          <%end if%>
          <%set rsAssigned = nothing%>
          <%
	strSQL = "SELECT NewsID, Heading FROM News WHERE NewsID <> "& request("id") &" AND FileName IS NULL AND NewsID NOT IN (SELECT ContentID FROM RelatedNews WHERE FileID = "& request("id") &") ORDER BY Heading"
	set rsUnassigned = con.execute(strSQL)
    %>
          <tr> 
            <td>
		      <select name="MakeAssignment" class="TextBox">
                <option value="" selected>-- Select --</option>
                <%do while not rsUnassigned.EOF%>
                <option value="<%=rsUnassigned("NewsID")%>"><%=rsUnassigned("Heading")%></option>
                <%rsUnassigned.movenext%>
                <%loop%>
                <%set rsUnassigned = nothing%>
              </select>
      </td>
            <td align="right"> 
              <input type="submit" name="Submit2" value="    Add    " class="Button">
      </td>
          </tr>
          <input type="hidden" name="id" value="<%=request("id")%>">
          <input type="hidden" name="menuID" value="<%=request("menuID")%>">
          <input type="hidden" name="Posted" value="Y2">
        </form>
      </table>
		


	</td>
  </tr>
</table>
<%	end if
	
	set rsNews = nothing
	
end if%>

<p align="center"> 
  <input type="button" onClick="javascript:window.close();" name="gotoClose" value=" Close Window " class="Button">
</p>
</body>
</html>
<%
	con.close
	set con = nothing
%>
