
<%
/**
 *	$RCSfile: searchSettings.jsp,v $
 *	$Revision: 1.1.1.1 $
 *	$Date: 2002/09/09 13:50:30 $
 */
%>

<%@ page import="java.util.*,
	             java.text.*,
                 com.jivesoftware.forum.*,
                 com.jivesoftware.forum.util.*"
	errorPage="error.jsp"
%>

<%@	include file="include/global.jsp" %>

<%	// get parameters
	
    boolean searchEnabled = ParamUtils.getBooleanParameter(request,"searchEnabled");
    boolean setSearchEnabled = ParamUtils.getBooleanParameter(request,"setSearchEnabled");
	boolean setAutoIndexEnabled = ParamUtils.getBooleanParameter(request,"setAutoIndexEnabled");
	boolean autoIndexEnabled = ParamUtils.getBooleanParameter(request,"autoIndexEnabled");
    int updateInterval = ParamUtils.getIntParameter(request,"updateInterval",5);
	boolean doUpdateIndex = ParamUtils.getBooleanParameter(request,"doUpdateIndex");
	boolean doRebuildIndex = ParamUtils.getBooleanParameter(request,"doRebuildIndex");
    
    // Get the search manager
	SearchManager searchManager = forumFactory.getSearchManager();
    
    // enable or disable search
    if (setSearchEnabled) {
        searchManager.setSearchEnabled(searchEnabled);
        response.sendRedirect("searchSettings.jsp");
        return;
    }
    
    // enable or disable auto indexing
    if (setAutoIndexEnabled) {
        searchManager.setAutoIndexEnabled(autoIndexEnabled);
        searchManager.setAutoIndexInterval(updateInterval);
        response.sendRedirect("searchSettings.jsp");
        return;
    }
    
    // update index if requested
    if (doUpdateIndex) {
        searchManager.updateIndex();
        response.sendRedirect("searchSettings.jsp");
        return;
    }
    
    // rebuild index if requested
    if (doRebuildIndex) {
        searchManager.rebuildIndex();
        response.sendRedirect("searchSettings.jsp");
        return;
    }
    
	autoIndexEnabled = searchManager.isAutoIndexEnabled();
    searchEnabled = searchManager.isSearchEnabled();
%>

<%@ include file="include/header.jsp" %>

<%  // Title of this page and breadcrumbs
    String title = "Search Settings";
    String[][] breadcrumbs = {
        {"Main", "main.jsp"},
        {"Search Settings", "searchSettings.jsp"}
    };
%>
<%@ include file="include/title.jsp" %>

<font size="-1">
The search indexer periodically adds new messages into the searchable 
message database. You can control how often this update takes place by 
adjusting the refresh interval. Messages will not appear in search results 
until they are indexed, so a relatively frequent refresh interval is 
recommended.
</font>

<p>

<font size="-1"><b>Search Status</b></font><p>
<ul>
    <font size="-1">
    You can enable or disable the search feature in the Jive system by using the form
    below.
    </font>
    <form action="searchSettings.jsp">
    <input type="hidden" name="setSearchEnabled" value="true">
    <table bgcolor="<%= tableBorderColor %>" cellpadding="0" cellspacing="0" border="0" width="300">
    <td>
    <table bgcolor="<%= tableBorderColor %>" cellpadding="3" cellspacing="1" border="0" width="100%">
    <tr bgcolor="#ffffff">
	<td align="center"<%= (searchEnabled)?" bgcolor=\"#99cc99\"":"" %>>
        <font size="-1">
		<input type="radio" name="searchEnabled" value="true" id="rb01"
		 <%= (searchEnabled)?"checked":"" %>>
		<label for="rb01"><%= (searchEnabled)?"<b>On</b>":"On" %></label>
        </font>
	</td>
	<td align="center"<%= (!searchEnabled)?" bgcolor=\"#cc6666\"":"" %>>
        <font size="-1">
		<input type="radio" name="searchEnabled" value="false" id="rb02"
		 <%= (!searchEnabled)?"checked":"" %>>
		<label for="rb02"><%= (!searchEnabled)?"<b>Off</b>":"Off" %></label>
        </font>
	</td>
	<td align="center">
		<input type="submit" value="Update">
	</td>
    </tr>
    </table>
    </td>
    </table>
    </form>
</ul>

<%  // only show the following section if the search feature is enabled
    if (searchEnabled) {
%>

<font size="-1"><b>Search Indexing Settings</b></font><p>
<ul>
    <font size="-1">
    If you choose, auto-indexing can be turned off.
    However, in that case, messages will not be indexed unless you do so manually.
    </font>
    <p>
    <form action="searchSettings.jsp">
    <input type="hidden" name="setAutoIndexEnabled" value="true">
    
    <table cellpadding="2" cellspacing="0" border="0">
    <tr>
    	<td><input type="radio" name="autoIndexEnabled" value="true" id="rb03"<%= (autoIndexEnabled)?"checked":"" %>></td>
    	<td><font size="-1"><label for="rb03">Auto Indexing On</label></font></td>
    </tr>
    <tr>
    	<td><input type="radio" name="autoIndexEnabled" value="false" id="rb04"<%= (!autoIndexEnabled)?"checked":"" %>></td>
    	<td><font size="-1"><label for="rb04">Auto Indexing Off</label></font></td>
    </tr>
    <%  if (!autoIndexEnabled) { %>
    <tr>
    	<td colspan="2"><input type="submit" value="Save Settings"></td>
    </tr>
    <%  } %>
    </table>
    <%  if (autoIndexEnabled) { %>
    <p>
    <table>
    <tr>
    	<td>
        <font size="-1">
        You can choose how often you would like to index your forum content.
        <br><br>
        </font> 
        </td>
    </tr>
    <tr>
    	<td>
        <font size="-1">
        Search index last updated on
        <%= JiveGlobals.formatDateTime(searchManager.getLastIndexedDate()) %>
        </font> 
        </td>
    </tr>
    <tr>
    	<td>
        <font size="-1">
        Refresh every
		<select size="1" name="updateInterval">
<%      for (int i=0; i<=60;) {
            String selected = "";
            if (updateInterval == i) {
                selected = " selected";
            }
%>
        <option value="<%= i %>"<%= selected %>><%= i %>
<%          if (i >= 10) {
                i+=5;
            } else {
                i++;
            }
        }
%>
		</select>
		minutes.
        </font>
        </td>
    </tr>
    <tr>
    	<td><br><input type="submit" value="Save Settings"></td>
    </tr>
    </table>
    <%  } %>
    </form>
</ul>

<%  } // end if searchEnabled %>

<%  if (!searchManager.isBusy()) { %>

<font size="-1"><b>Update Index</b></font><p>
<ul>
    <form action="searchSettings.jsp">
    <font size="-1">
    This will index any messages added since the last indexer was run.
    <br>
    </font>
    <input type="hidden" name="doUpdateIndex" value="true">
    <input type="submit" value="Update Index">
    </form>
</ul>

<font size="-1"><b>Rebuild Index</b></font><p>
<ul>
    <form action="searchSettings.jsp">
    <font size="-1">
    This will reindex all messages. (May take a few moments if you have a lot of messages)
    <br>
    </font>
    <input type="hidden" name="doRebuildIndex" value="true">
    <input type="submit" value="Rebuild Index">
    </form>
</ul>

<%  } else { // is running task %>

<script language="JavaScript" type="text/javascript">
<!--
function reloadPage() {
    location.href='searchSettings.jsp';
}
setTimeout(reloadPage,5000);
//-->
</script>

<font size="-1"><b>Indexing...</b></font><p>
<ul>
    <font size="-1">
    <b><%= searchManager.getPercentComplete() %>% complete</b>
    <br>
    Jive is currently updating or rebuilding the search index. This may take
    a few moments.
    </font>
</ul>

<%  } %>

<%@ include file="include/footer.jsp" %>
