<%@ Page Language="vb" AutoEventWireup="false" Codebehind="DiscussionMessage.aspx.vb" Inherits="DiscussionSampleVB.DiscussionMessage" %>
<form id="selectForm" method="post" runat="server">
	<table cellpadding="1" cellspacing="1" border="1" width="100%">
		<tr>
			<td colspan="6"><b>Discussion Details</b>
			</td>
		</tr>
		<tr>
			<td>Name</td>
			<td>Description</td>
			<td>ID</td>
			<td>Created Date</td>
			<td>Last Modified Date</td>
			<td>Owner User ID</td>
		</tr>
		<tr>
			<td><%=discussion.Name%></td>
			<td><%=discussion.Description%></td>
			<td><%=discussion.ID%></td>
			<td><%=discussion.CreatedDate%></td>
			<td><%=discussion.LastModifiedDate%></td>
			<td><%=discussion.OwnerUserID%></td>
		</tr>
	<tr>
		<td colspan="6">
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<!--select for create, remove, search-->
			<asp:DropDownList id="DiscussionMessageMethodDropDownList" runat="server">
				<asp:ListItem value="createMessage">create Message</asp:ListItem>
				<asp:ListItem value="removeMessage">remove Message</asp:ListItem>
				<asp:ListItem value="searchMessages">search Messages</asp:ListItem>
			</asp:DropDownList>
		</td>
		<td colspan="4">
			<asp:Button id="SelectGoButton" text="go" runat="server" ptrender="true" />
		</td>
	</tr>
	<!--show a search box for search, and a box to box to enter the discussion id if remove-->
	<% 
if createDiscussionMessage then
  'if no subject or body, show text boxes for subject and body, and a submit button
  if  subject is Nothing or  body is nothing
    %>
	<tr>
		<td colspan="2">
			Discussion Message Subject:
		</td>
		<td colspan="4">
			<asp:TextBox id="SubjectBox" runat="server" />
		</td>
	</tr>
	<tr>
		<td colspan="2">
			Discussion Message Body:
		</td>
		<td colspan="4">
			<asp:TextBox id="BodyBox" runat="server" />
		</td>
	</tr>
	<tr>
		<td colspan="6">
			<asp:Button id="CreateSubmitButton" text="Submit" runat="server" ptrender="true" />
		</td>
	</tr>
	<%
  else
  'create a discussion message and print out the discussion message id
    if subject is nothing then
			subject = "ExampleDiscussionMessage"
		end if
		if body is nothing then
			body = "Example Discussion Body" 
	  end if
		
		'create the discussion	message		
		dim discussionMessage as Plumtree.Remote.PRC.Collaboration.Discussion.IDiscussionMessage  = discussion.CreateDiscussionMessage(subject, body) 
		'if you want to set additional properties, make sure that store() is called or the changes will not be persisted.
		'for example:
'		discussionMessage.Description = "Sample Description" 
		'call store before asking for the id. 
		discussionMessage.Store() 
		dim id as Integer = discussionMessage.ID 
		dim url as String  = discussionMessage.DetailsURL 

		%>
	<tr>
		<td colspan="6">
			<%
				Response.Write("<a href=""" &	 url & """>Link to collab message " & Cstr(id) & "</a>") 
			%>
		</td>
	</tr>
	<%
  end if
end if
if removeDiscussionMessage then
	'if no discussion Message ID, add a text box for discussionMessageID, and a submit button
	if discussionMessageID = -1 then
		%>
	<tr>
		<td colspan="2">
			Discussion Message ID:
		</td>
		<td colspan="4">
			<asp:TextBox id="DiscussionMessageIDBox" runat="server" />
		</td>
	</tr>
	<tr>
		<td colspan="6">
			<asp:Button id="RemoveSubmitButton" runat="server"  text="Submit" ptrender="true" />
		</td>
	</tr>
	<%
		else
		'remove the discussion Message 
        'then get the discussion manager to retrieve the discussion message
        	dim discussionManager as Plumtree.Remote.PRC.Collaboration.Discussion.IDiscussionManager  = GetDiscussionManager(Request, Response) 
        'then get the discussion message from the manager    	
        dim discussionMessage as Plumtree.Remote.PRC.Collaboration.Discussion.IDiscussionMessage  = discussionManager.GetDiscussionMessage(discussionMessageID) 
        
		'squawk if the discussion could not be retrieved
		if  discussionMessage is nothing then
			%>
	<tr>
		<td colspan="6">
			<%Response.Write("Unable to retrieve discussion  Message with ID of " & Cstr(discussionMessageID)) %>
		</td>
	</tr>
	<%
		else
			'remove
			discussion.RemoveDiscussionMessage(discussionMessage) 
			%>
	<tr>
		<td colspan="6">
			<%Response.Write("Discussion Message with id of " & Cstr(discussionMessageID ) & " removed.") %>
		</td>
	</tr>
	<%
		end if
	end if	
end if

if searchDiscussionMessages then
       	'get the project ID out of session- this should never be null as it is added in the page load event
		dim project as Plumtree.Remote.PRC.Collaboration.Project.IProject  = CType(Session.Item(SESSION_PROJECT_KEY),Plumtree.Remote.PRC.Collaboration.Project.IProject) 
		
		'perform the search
    	dim discussionManager as Plumtree.Remote.PRC.Collaboration.Discussion.IDiscussionManager  = GetDiscussionManager(Request, Response) 
		dim discussionMessageFilter as Plumtree.Remote.PRC.Collaboration.Discussion.IDiscussionMessageFilter  = discussionManager.CreateDiscussionMessageFilter() 

		'hard-code the max results to 10
		discussionMessageFilter.MaximumResults = 10 

		'optionally, set the query orders

		'execute the search and print out the results
		dim discussionMessages() as Plumtree.Remote.PRC.Collaboration.Discussion.IDiscussionMessage  = discussionManager.QueryDiscussionMessages(project, discussionMessageFilter) 
		if discussionMessages.Length > 0 then
			%>
	<tr>
		<td colspan="6">
			Search Results
		</td>
	</tr>
	<tr>
		<td colspan="2">
			Discussion Message Name- Link to Discussion Message
		</td>
		<td colspan="4">
			Discussion ID
		</td>
	</tr>
	<%
      dim i as Integer
			for i = 0 to  discussionMessages.Length -1 
				dim discussionMessage as Plumtree.Remote.PRC.Collaboration.Discussion.IDiscussionMessage  = discussionMessages(i)
				dim id as Integer = discussionMessage.ID 
				dim name as String  = discussionMessage.Subject 
				dim url as String  = discussionMessage.DetailsURL 
				%>
	<tr>
		<td colspan="2">
			<%Response.Write("<a href=""" & url & """>" & name & "</a>") %>
		</td>
		<td colspan="4">
			<%Response.Write(CStr(id)) %>
		</td>
	</tr>
	<%	
			next
		else
			Response.Write("No discussion messages found.") 
     end if
end if

%>

</table>
</form>
