<%
	Response.Buffer = True
	CategoryID = Request.QueryString("category")
	AddSub = (Len(Request.QueryString("addsub"))>0)
%>
<!--#INCLUDE virtual="/forum/Config.asp" -->
<!--#INCLUDE virtual="/forum/inc_top_short.asp" -->
<center>
<%	If Len(Request.Form("Cancel")) > 0 Or (Not(AddSub) And Len(CategoryID)=0) Then %>
<br><br><p align="center"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>"><b>Cancelled!</b></font></p>
<%
Else
	If Len(CategoryID)=0 Then CategoryID = 0
	
set my_Conn = Server.CreateObject("ADODB.Connection")
my_Conn.Open strConnString

Sub RelatedForum%>
<!-- Begin Select Related Forum --> 
    <select name="Forum_ID" size="1">
      <option value="">Select Related Forum</option>
<%
		'##  Build SQL to get forums via category
		'## Forum_SQL
		strSql = "SELECT " & strTablePrefix & "FORUM.FORUM_ID, " & strTablePrefix & "FORUM.F_SUBJECT"
		strSql = strSql & " FROM " & strTablePrefix & "FORUM "
		strSql = strSql & " ORDER BY " & strTablePrefix & "FORUM.F_SUBJECT ASC;"

		set rsForum =  my_Conn.Execute (StrSql)

		if rsForum.eof or rsForum.bof then
			'nothing
		else
			do until rsForum.Eof
						Response.Write "      <option value='" & rsForum("FORUM_ID") &"'"
If Not AddSub Then
					if rsForum("FORUM_ID") = rsCategory("Forum_ID") then 
						Response.Write(" SELECTED") 
					End If
End If
					Response.Write ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & rsForum("F_SUBJECT")& "</option>" & vbCrLf
				rsForum.MoveNext
			loop
		end if
%>
    </select>
<!-- End Select Related Forum -->
<% End Sub 'Related Forum

				If Not AddSub Then
		        	Set rsCategory = CreateObject("ADODB.Recordset")
					Set rsCategory.ActiveConnection = my_Conn
					rsCategory.LockType = 2				
					rsCategory.Open("SELECT catid,parentid,hits,template,News,Product,Articles,Links,Project,Download,Forum_id,IMG,title,catdesc FROM " & strTablePrefix & "Site_Cats WHERE CatID=" & CategoryID)
					CategoryName = rsCategory("Title")
					Description  = rsCategory("CatDesc")
					IMG  = rsCategory("IMG")

	Set rsCategories = CreateObject("ADODB.Recordset")
	Set rsCategories.ActiveConnection = my_Conn
	rsCategories.LockType = 2
	rsCategories.CursorLocation = 3
	rsCategories.Open(strTablePrefix & "Site_Cats")
	
	Depth = 0
	Function getChildren(Node)
		Depth=Depth+1
		set rsCategories2 = rsCategories.Clone
		rsCategories2.Filter = "ParentID=" & Node

		Do While Not rsCategories2.EOF
			Response.write "<OPTION Value=" & rsCategories2("CatID")
			If rsCategories2("CatID") = rsCategory("ParentID") Then
				Response.Write " selected"
			End If
			Response.write ">"
			Response.write Repeat("- ",Depth) & rsCategories2("Title")
			Response.write "</OPTION>"
			getChildren(rsCategories2("CatID"))
			rsCategories2.MoveNext
		Loop
	Depth=Depth-1
	rsCategories2.Close
	Set rsCategories2 = Nothing
	End Function

	Function Repeat(Str,Times)
		Dim I
		For I=0 To Times
			Repeat = Repeat & Str
		Next
	End Function

	Sub DisplayCategories
		Set ParentRecords = rsCategories.Clone
		ParentRecords.Filter = "ParentID = 0"
		Do While Not ParentRecords.EOF
			Response.write "<OPTION Value=" & ParentRecords("CatID")
			If ParentRecords("CatID") = rsCategory("ParentID") Then
				Response.Write " selected"
			End If
			Response.write ">"
			Response.write ParentRecords("Title")
			Response.write "</OPTION>"
			getChildren(ParentRecords("CatID"))
			ParentRecords.MoveNext
		Loop
		rsCategories.Close
		Set rsCategories = Nothing
		ParentRecords.Close
		Set ParentRecords = Nothing
	End Sub

				End If
	        	If Len(Request.Form("Update")) > 0 Then
			        Set rsCategory= CreateObject("ADODB.Recordset")
				Set rsCategory.ActiveConnection = my_Conn
				rsCategory.LockType = 2				
			If AddSub Then
				rsCategory.Open("SELECT * FROM " & strTablePrefix & "Site_Cats")
				rsCategory.AddNew
				rsCategory("ParentID") = Request.Form("CategoryID")
        			If Len(Request.Form("IMG"))=0 Then
	         			rsCategory("IMG") = Null
        			Else
	        			rsCategory("IMG") = Request.Form("IMG")
	        		End If
	        		'response.write Request.Form("hasProduct")
	        		If Request.Form("hasProduct")="yes" Then
           			  rsCategory("Product") = 1
        			Else
	        		  rsCategory("Product") = 0
	        		End If 
	        		If Request.Form("hasArticle")="yes" Then
           			  rsCategory("Articles") = 1
        			Else
	        		  rsCategory("Articles") = 0
	        		End If
	        		If Request.Form("hasLink")="yes" Then
           			  rsCategory("Links") = 1
        			Else
	        		  rsCategory("Links") = 0
	        		End If
	        		If Request.Form("hasProject")="yes" Then
           			  rsCategory("Project") = 1
        			Else
	        		  rsCategory("Project") = 0
	        		End If
	        		If Request.Form("hasDownload")="yes" Then
           			  rsCategory("Download") = 1
        			Else
	        		  rsCategory("Download") = 0
	        		End If
  		     		rsCategory("Title") = Request.Form("Name")
        			rsCategory("CatDesc") = Request.Form("Description")
        			If Len(Request.Form("Forum_ID"))=0 Then
	         			rsCategory("Forum_ID") = Null
        			Else
	        			rsCategory("Forum_ID") = Request.Form("Forum_ID")
	        		End If
			Else
				rsCategory.Open("SELECT * FROM " & strTablePrefix & "Site_Cats Where CatID=" & CategoryID)
				
   		     		If Request.Form("hasProduct")="yes" Then
           			  rsCategory("Product") = 1
        			Else
	        		  rsCategory("Product") = 0
	        		End If 
	        		If Request.Form("hasArticle")="yes" Then
           			  rsCategory("Articles") = 1
        			Else
	        		  rsCategory("Articles") = 0
	        		End If
	        		If Request.Form("hasLink")="yes" Then
           			  rsCategory("Links") = 1
        			Else
	        		  rsCategory("Links") = 0
	        		End If
	        		If Request.Form("hasProject")="yes" Then
           			  rsCategory("Project") = 1
        			Else
	        		  rsCategory("Project") = 0
	        		End If
	        		If Request.Form("hasDownload")="yes" Then
           			  rsCategory("Download") = 1
        			Else
	        		  rsCategory("Download") = 0
	        		End If
  		     	        rsCategory("Title") = Request.Form("Name")
        			rsCategory("CatDesc") = Request.Form("Description")
        			rsCategory("ParentID") = Request.Form("ParentCat")
        			If Len(Request.Form("IMG"))=0 Then
	         			rsCategory("IMG") = Null
        			Else
	        			rsCategory("IMG") = Request.Form("IMG")
	        		End If
        			If Len(Request.Form("Forum_ID"))=0 Then
	         			rsCategory("Forum_ID") = Null
        			Else
	        			rsCategory("Forum_ID") = Request.Form("Forum_ID")
	        		End If
			End If   
			        'response.write "Request.Form(""hasArticle"") ist : " & Request.Form("hasArticle") & "<br>"
			        'response.write "Artikel ist: " & rsCategory("Articles")
        			rsCategory.Update
		      		rsCategory.Close
      				Set rsCategory= Nothing
				'	my_Conn.Close
      				' Set my_Conn = Nothing %>
<br><br><p align="center"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>"><b>Completed!</b></font></p>
<% Else %>
       <FORM action="editcategory.asp?<% If AddSub Then Response.write "addsub=true&" %>category=<%= CategoryID %>" method="POST">
<br>
<table bgcolor="<%=strTableBorderColor%>" width="95%" border="0" cellpadding="2" cellspacing="1">
<tr><td align="center" bgcolor="<%=strHeadCellColor%>">
<font face="<%=strDefaultFontFace%>" size="<%=strHeaderFontSize%>" color="<%=strHeadFontColor%>"><b>
      <% If AddSub Then %>
      	Add Sub Category
      <% Else %>
	Edit Category
	<% End If %>
		</b></font></td></tr>
<tr><td align="center" bgcolor="<%=strForumCellColor%>">
      <table border="0" cellpadding="2" cellspacing="1" width="100%">
        <tr>
          <td width="40%" bgcolor="<%=strForumCellColor%>"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>"><b>Title</b></font></td>
          <td width="60%"><input type="text" name="Name" size="35" value="<%= CategoryName %>"></td>
	</tr>
        <tr>
          <td width="40%" bgcolor="<%=strForumCellColor%>"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>"><b>Description</b></font></td>
          <td width="60%"><textarea rows="3" name="Description" cols="30"><%= Description %></textarea></td>
        </tr> 
        <tr>
          <td valign="top" width="40%" bgcolor="<%=strForumCellColor%>"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>"><b>Content</b></font></td>
          <td width="60%">
<%        if AddSub then %>  
          <table>
          <tr>
            <td colspan="1" width="25%"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>">News</font></td>
	    <td colspan="3" width="75%"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>"><b>Are automatically displayed</b></font></td>
	  </tr>
	  <tr>
            <td align="left" width=10%"><input type="checkbox" name="hasProduct" value="yes"></td>
            <td align="left" width=40%"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>">Product</font></td>
            <td align="left" width=10%"><input type="checkbox" name="hasArticle" value="yes" CHECKED></td>
            <td align="left" width=40%"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>">Article</font></td>
	  </tr>
	  <tr>
            <td align="left" width=10%"><input type="checkbox" name="hasLink" value="yes" CHECKED ></td>
            <td align="left" width=40%"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>">Link</font></td>
	    <td align="left" width=10%"><input type="checkbox" name="hasProject" value="yes"></td>
	    <td align="left" width=40%"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>">Project</font></td>
	    </tr>
	  <tr>
            <td align="left" width=10%"><input type="checkbox" name="hasDownload" value="yes"></td>
	    <td align="left" width=40%"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>">Download</font></td>
	    <td align="left" width=10%"></td>
	  <td align="left" width=40%"></td>
	    </tr>
	  </table>  
<%	  else %>  
          <table>
          <tr>
            <td colspan="1" width="25%"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>">News</font></td>
	    <td colspan="3" width="75%"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>"><b>Are automatically displayed</b></font></td>
	  </tr>
	  <tr>
            <td align="left" width=10%"><input type="checkbox" name="hasProduct" value="yes" <%if rsCategory("Product") = 1 then response.write(" CHECKED")%>></td>
            <td align="left" width=40%"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>">Product</font></td>
            <td align="left" width=10%"><input type="checkbox" name="hasArticle" value="yes"<%if rsCategory("Articles") = 1 then response.write(" CHECKED")%>></td>
            <td align="left" width=40%"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>">Article</font></td>
	  </tr>
	  <tr>
            <td align="left" width=10%"><input type="checkbox" name="hasLink" value="yes"<%if rsCategory("Links") = 1 then response.write(" CHECKED")%>></td>
            <td align="left" width=40%"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>">Link</font></td>
	    <td align="left" width=10%"><input type="checkbox" name="hasProject" value="yes" <%if rsCategory("Project") = 1 then response.write(" CHECKED")%>></td>
	    <td align="left" width=40%"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>">Project</font></td>
	    </tr>
	  <tr>
            <td align="left" width=10%"><input type="checkbox" name="hasDownload" value="yes" <%if rsCategory("Download") = 1 then response.write(" CHECKED")%>></td>
	    <td align="left" width=40%"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>">Download</font></td>
	    <td align="left" width=10%"></td>
	  <td align="left" width=40%"></td>
	    </tr>
	  </table>
<%        end if %>  
          </td>
        </tr>
        <tr>
          <td width="40%" bgcolor="<%=strForumCellColor%>"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>"><b>Image URL</b></font></td>
          <td width="60%"><input type="text" name="IMG" size="25" value="<%= IMG %>"></td>
        </tr>
<%		If Not AddSub Then %>
      <tr>
          <td width="40%" bgcolor="<%=strForumFirstCellColor%>"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>"><b>Parent Category</b></font></td>
          <td width="60%">
		<SELECT NAME="ParentCat">
		<option value="0">Top Level Category</option>
		<% Call DisplayCategories %>
		</select>
	    </td>
	</tr>
<%		End If %>
      <tr>
          <td width="40%" bgcolor="<%=strForumFirstCellColor%>"><font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>"><b>Related Forum</b></font></td>
          <td width="60%">
		<% Call RelatedForum %>
	    </td>
	</tr>
	<input type="hidden" name="CategoryID" value="<%=CategoryID%>">
      </table>

</td></tr>
<tr><td align="center" bgcolor="<%=strForumFirstCellColor%>">
<font face="<%=strDefaultFontFace%>" size="<%=strDefaultFontSize%>" color="<%=strDefaultFontColor%>">Please ensure that all the above information is a-okay before you Update...<%If Not AddSub Then %><br><b>Note:</b> When editing a Top Level category make sure you select "Top Level Category" as the Parent Category!<%End If%></font><br>
      <p><input type="submit" value="Update" name="Update"> &nbsp; <input type="submit" value="Cancel" name="Cancel"></p>
      </form>
</td></tr></table><br>
<%
End If
End If
%>
<!--#INCLUDE virtual="/forum/inc_footer_short.asp" -->
