<%--
  The contents of this file are subject to the Mozilla Public License Version 1.1
  (the "License"); you may not use this file except in compliance with the License.
  You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.

  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
  WARRANTY OF ANY KIND, either express or implied. See the License for the specific
  language governing rights and limitations under the License.
  
  The Original Code is the Venice Web Communities System.
  
  The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
  for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
  Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.

  Contributor(s): 
--%>
<%@ page import = "java.util.*" %>
<%@ page import = "com.silverwrist.util.StringUtil" %>
<%@ page import = "com.silverwrist.venice.core.*" %>
<%@ page import = "com.silverwrist.venice.ui.view.AdminFindUserView" %>
<%@ taglib uri="/tlds/util" prefix="util" %>
<%
  AdminFindUserView data = AdminFindUserView.get(request);
%>
<util:comment>Admin Find Users Menu</util:comment>
<util:header title="User Account Management"/>
<util:font color="content.fg" size="content"><util:link href="sysadmin/menu.js.vs" type="servlet">Return to
System Administration Menu</util:link></util:font><P>

<%-- Display the search form --%>
<util:comment>User Search Form</util:comment>
<util:form action="sysadmin/find_user.js.vs" type="servlet"><DIV CLASS="content">
  <INPUT TYPE=HIDDEN NAME="ofs" VALUE="0">
  <util:font color="content.fg" size="content-heading"><B>Find Users:</B></util:font><BR>
  <util:font color="content.fg" size="content">
    Display all users whose&nbsp;&nbsp;
    <SELECT NAME="field" SIZE=1>
      <OPTION VALUE="<%= SearchMode.FIELD_USER_NAME %>"
        <% if (data.testField(SearchMode.FIELD_USER_NAME)) { %>SELECTED<% } %> >user name</OPTION>
      <OPTION VALUE="<%= SearchMode.FIELD_USER_DESCRIPTION %>"
        <% if (data.testField(SearchMode.FIELD_USER_DESCRIPTION)) { %>SELECTED<% } %> >description</OPTION>
      <OPTION VALUE="<%= SearchMode.FIELD_USER_GIVEN_NAME %>"
        <% if (data.testField(SearchMode.FIELD_USER_GIVEN_NAME)) { %>SELECTED<% } %> >first name</OPTION>
      <OPTION VALUE="<%= SearchMode.FIELD_USER_FAMILY_NAME %>"
        <% if (data.testField(SearchMode.FIELD_USER_FAMILY_NAME)) { %>SELECTED<% } %> >last name</OPTION>
    </SELECT><BR>
    <SELECT NAME="mode" SIZE=1>
      <OPTION VALUE="<%= SearchMode.SEARCH_PREFIX %>"
        <% if (data.testMode(SearchMode.SEARCH_PREFIX)) { %>SELECTED<% } %> >starts with the string</OPTION>
      <OPTION VALUE="<%= SearchMode.SEARCH_SUBSTRING %>"
        <% if (data.testMode(SearchMode.SEARCH_SUBSTRING)) { %>SELECTED<% } %> >contains the string</OPTION>
      <OPTION VALUE="<%= SearchMode.SEARCH_REGEXP %>"
        <% if (data.testMode(SearchMode.SEARCH_REGEXP)) { %>SELECTED<% } %> >matches the regular
        expression</OPTION>
    </SELECT>
    &nbsp;&nbsp;
    <SPAN CLASS="cinput"><INPUT TYPE=TEXT CLASS="cinput" NAME="term" SIZE=32 MAXLENGTH=255
                                VALUE="<%= data.getTerm() %>"></SPAN><BR>
    <util:button id="search" type="input"/><BR>
  </util:font>
</DIV></util:form>

<% List results = data.getResults(); %>
<% if (results!=null) { %>
  <util:comment>Display Search Results</util:comment>
  <%
    // Determine the number of results to display and whether to display a "next" button
    int dcount = results.size();
    boolean go_next = false;
    if (dcount>data.getMaxResults())
    { // there's a "next"
      dcount = data.getMaxResults();
      go_next = true;

    } // end if
  %>
  <HR>
  <TABLE WIDTH="100%" BORDER=0 ALIGN=CENTER><TR VALIGN=MIDDLE>
    <TD WIDTH="50%" ALIGN=LEFT CLASS="content"><util:font color="content.fg" size="subhead">
      <%-- The initial search results --%>
      <B>Search Results</B>
      <% if (data.getFindCount()>0) { %>
        (Displaying <%= data.getOffset() + 1 %>-<%= data.getOffset() + dcount %> of
        <%= data.getFindCount() %>)
      <% } else { %>(None)<% } %>
    </util:font></TD>
    <TD WIDTH="50%" ALIGN=RIGHT CLASS="content">
      <% if (go_next || (data.getOffset()>0)) { %>
        <%-- The navigational form that allows us to page through the results --%>
        <util:comment>Navigational Form</util:comment>
        <util:form action="sysadmin/find_user.js.vs" type="servlet"><DIV CLASS="content">
          <INPUT TYPE=HIDDEN NAME="ofs" VALUE="<%= data.getOffset() %>">
          <INPUT TYPE=HIDDEN NAME="field" VALUE="<%= data.getField() %>">
          <INPUT TYPE=HIDDEN NAME="mode" VALUE="<%= data.getMode() %>">
          <INPUT TYPE=HIDDEN NAME="term" VALUE="<%= data.getTerm() %>">
          <INPUT TYPE=HIDDEN NAME="fcount" VALUE="<%= data.getFindCount() %>">
          <% if (data.getOffset()>0) { %>
            <util:button id="previous" type="input"/>
          <% } else { %>
            <util:button id="_null_"/>
          <% } // end if %>
          &nbsp;&nbsp;
          <% if (go_next) { %>
            <util:button id="next" type="input"/>
          <% } else { %>
            <util:button id="_null_"/>
          <% } // end if %>
        </DIV></util:form>
      <% } else { %>&nbsp;<% } %>
    </TD>
  </TR></TABLE><BR>

  <%-- Display the results of the search --%>
  <TABLE BORDER=0 ALIGN=LEFT CELLPADDING=0 CELLSPACING=4>
    <% for (int i=0; i<dcount; i++) { %>
      <TR VALIGN=TOP>
        <TD ALIGN=CENTER WIDTH=14><util:stdbullet/></TD>
        <TD ALIGN=LEFT CLASS="content"><util:font color="content.fg" size="content">
	  <% UserFound uf = (UserFound)(results.get(i)); %>
          <util:xlink>
            <util:href type="servlet">user/<%= uf.getName() %></util:href>
            <util:text><%= uf.getName() %></util:text>
          </util:xlink><BR>
          <util:escape><%= uf.getGivenName() %> <%= uf.getFamilyName() %></util:escape>,
          from <util:escape><%= uf.getLocality() %>, <%= uf.getRegion() %></util:escape> <%= uf.getCountry() %>
          <% if (!StringUtil.isStringEmpty(uf.getDescription())) { %>
            <BR><EM><util:escape><%= uf.getDescription() %></util:escape></EM>
          <% } // end if %>
	  <BR><util:xlink>
            <util:href type="servlet">sysadmin/modify_user.js.vs?uid=<%= uf.getUID() %></util:href>
            <util:text>[Modify User]</util:text>
          </util:xlink>
        </util:font></TD>
      </TR>
    <% } // end for %>
  </TABLE><BR CLEAR=LEFT>
<% } // end if (results found) %>
