<%@ Page language="c#" Codebehind="ProjectSample.aspx.cs" AutoEventWireup="false" Inherits="WebProjectSample.ProjectSample" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
	<head>
		<title>WebForm1</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
	</head>
	<body MS_POSITIONING="GridLayout">
<table>
<form name="selectForm" method="POST" action="ProjectSample.aspx">
<tr>
<td>
<!--select for create, remove, search-->
<select name="projectMethod">
<option value="create" <% if(create)Response.Write(" SELECTED ");%>>create</option>
<option value="remove" <% if(remove)Response.Write(" SELECTED ");%>>remove</option>
<option value="search" <% if(search)Response.Write(" SELECTED ");%>>search</option>
</select>
<input type="submit" name="selectGo" value="go"/>

</td>
</tr>


<!--show a search box for search, and a box to box to enter the project id if remove-->
<% 
if (create)
{
  //if no name or description, show text boxes for name and description, and a submit button
  if (null == name || null == description)
  {
    %>
	<tr>
	 <td>
	   Project Name:
	 </td>
	 <td>
	   <input type="text" name="name" value="<%=(null==name)?"":name%>"/>
	 </td>
	</tr>
	<tr>
	 <td>
	   Project Description:
	 </td>
	 <td>
	   <input type="text" name="description" value="<%=(null==description)?"":description%>"/>
	 </td>
	</tr>	
	<tr>
	 <td>
	   <input type="submit" name="createSubmit" value="submit"/>
	 </td>
	</tr>		
   <%
  }
  else
  //create a project and print out the project id
  {
		name = (null == name) ? "ExampleProject" : name;
		description = (null == description) ? "ExampleProjectDescription" : description;
			//create the project
		Plumtree.Remote.PRC.Collaboration.Project.IProjectManager projectManager = GetProjectManager(Request, Response);
		Plumtree.Remote.PRC.Collaboration.Project.IProject project =
						projectManager.CreateProject(name, description);

		//if you want to set additional properties, make sure that store() is called or the changes will not be persisted.
		//for example:
		/*
		project.setStatus(ProjectStatus.NOT_STARTED);
		project.setStartDate(new Date());
		*/
		//call store before asking for the id. 
		project.Store();

		%>
		<tr>
			<td>
			<%
				Response.Write("ID of newly created project is " + project.ID);
			%>
			</td>
		</tr>
        
  <%
  }
}
if (remove)
{
	//if no project ID, add a text box for projectID, and a submit button
	if (projectID == -1)
	{
		%>
		<tr>
			<td>
				Project ID:
			</td>
			<td>
				<input type="text" name="projectID" value="<%=(null==strProjectID)?"":strProjectID%>"/>
			</td>
		</tr>	
		<tr>
			<td>
				<input type="submit" name="removeSubmit" value="submit"/>
			</td>
		</tr>
		<%
		} 
		else
		{
		//remove the project
		Plumtree.Remote.PRC.Collaboration.Project.IProjectManager projectManager = GetProjectManager(Request, Response);
		Plumtree.Remote.PRC.Collaboration.Project.IProject project = projectManager.GetProject(projectID);
		//squawk if the project could not be retrieved
		if (null == project)
		{
			%>
			<tr>
				<td>
					<%Response.Write("Unable to retrieve project with ID of " + projectID);%>
				</td>
			</tr>

			<%
		}
		else
		{
			//remove
			projectManager.RemoveProject(project);
			%>
			<tr>
				<td>
					<%Response.Write("Project with id of " + projectID + " removed.");%>
				</td>
			</tr>

		<%
		}
	}
}

if (search)
{
	//if no search text, add a text box for search text, and a submit button
	if (null == searchText)
	{
		%>
		<tr>
			<td>
				Search Text:
			</td>
			<td>
				<input type="text" name="searchText" value="<%=(null==searchText)?"":searchText%>"/>
			</td>
		</tr>	
		<tr>
			<td>
				<input type="submit" name="searchSubmit" value="submit"/>
			</td>
		</tr>
		<%
	} 
	else
	{
		//perform the search
		Plumtree.Remote.PRC.Collaboration.Project.IProjectManager projectManager = GetProjectManager(Request, Response);
		Plumtree.Remote.PRC.Collaboration.Project.IProjectFilter projectFilter = projectManager.CreateProjectFilter();

		//hard-code the max results to 10
		projectFilter.MaximumResults = 10;

		//set the query
		projectFilter.NameSearchText = searchText;

		//execute the search and print out the results
		Plumtree.Remote.PRC.Collaboration.Project.IProject[] projects = projectManager.QueryProjects(projectFilter);
		if (projects.Length > 0)
		{
			%>
			<tr>
				<td>
					Search Results
				</td>

			</tr>
			<tr>
				<td>
					Project Name
				</td>
				<td>
					Project ID
				</td>
			</tr>
			<%
			for (int i = 0; i < projects.Length; i++)
			{
				Plumtree.Remote.PRC.Collaboration.Project.IProject project = projects[i];
				%>
				<tr>
				<td>
			  	<%Response.Write(project.Name);%>
				</td>
				<td>
					<%Response.Write(project.ID);%>
				</td>
				</tr>
			<%	
			}
		}
		else
		{
			Response.Write("No projects found using search query of " + searchText);
		}

	}

}
%>
</form>
</table>
	</body>
</html>
