<%--
  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@ricochet.com>,
  for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
  Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.

  Contributor(s): 
--%>
<%@ page import = "java.util.Iterator" %>
<%@ page import = "java.util.List" %>
<%@ page import = "com.silverwrist.util.*" %>
<%@ page import = "com.silverwrist.venice.core.*" %>
<%@ page import = "com.silverwrist.venice.ui.view.MembersView" %>
<%@ taglib uri="/tlds/util" prefix="util" %>
<%@ taglib uri="/tlds/community" prefix="comm" %>
<%
  MembersView view = MembersView.get(request);
%>
<util:comment>Members view for community <comm:name/></util:comment>
<util:header title="Members of Community:">
  <util:subtitle><util:escape><comm:name/></util:escape></util:subtitle>
</util:header>
<% if (view.canExportMembers()) { %>
  <util:font color="content.fg" size="content">[
    <util:xlink>
      <util:href type="servlet">comm/member_export.js.vs?cc=<comm:ID/></util:href>
      <util:text>Export Member List</util:text>
    </util:xlink>
  ]</util:font><p>
<% } // end if %>
<util:font color="content.fg" size="subhead"><b>Find members of community "<comm:name/>":</b></util:font><p />
<util:form action="comm/members.js.vs" type="servlet"><div class="content">
  <input type="hidden" name="cc" value="<comm:ID/>" />
  <input type="hidden" name="sl" value="0" />
  <input type="hidden" name="ofs" value="0" />
  <util:font color="content.fg" size="content">
    Display all community members whose&nbsp;&nbsp;
    <select name="field" size="1">
      <option value="<%= SearchMode.FIELD_USER_NAME %>"
      <% if (view.testField(SearchMode.FIELD_USER_NAME)) { %>selected="selected"<% } %> >user name</option>
      <option value="<%= SearchMode.FIELD_USER_DESCRIPTION %>"
      <% if (view.testField(SearchMode.FIELD_USER_DESCRIPTION)) { %>selected="selected"<% } %> >description</option>
      <option value="<%= SearchMode.FIELD_USER_GIVEN_NAME %>"
      <% if (view.testField(SearchMode.FIELD_USER_GIVEN_NAME)) { %>selected="selected"<% } %> >first name</option>
      <option value="<%= SearchMode.FIELD_USER_FAMILY_NAME %>"
      <% if (view.testField(SearchMode.FIELD_USER_FAMILY_NAME)) { %>selected="selected"<% } %> >last name</option>
    </select><br />

    <select name="mode" size="1">
      <option value="<%= SearchMode.SEARCH_PREFIX %>"
      <% if (view.testMode(SearchMode.SEARCH_PREFIX)) { %>selected="selected"<% } %> >starts with the string</option>
      <option value="<%= SearchMode.SEARCH_SUBSTRING %>"
      <% if (view.testMode(SearchMode.SEARCH_SUBSTRING)) { %>selected="selected"<% } %> >contains the string</option>
      <option value="<%= SearchMode.SEARCH_REGEXP %>"
      <% if (view.testMode(SearchMode.SEARCH_REGEXP)) { %>selected="selected"<% } %> >matches the regular
      expression</option>
    </select>

    <span class="cinput"><input type="text" class="cinput" name="term" size="32" maxlength="255"
                                value="<%= view.getTerm() %>" /></span><br />
    <util:button id="search" type="input"/>
  </util:font>
</div></util:form>

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

    } // end if
  %>
  <table width="100%" border="0" align="center"><tr valign="middle">
    <td width="50%" align="left" class="content"><util:font color="content.fg" size="content">
      <%-- The community members/search results header --%>
      <font size="+1"><b>
        <% if (view.getSimple()) { %>Community Members:<% } else { %>Search Results:<% } %>
      </b></font>
      (Displaying <%= view.getOffset() + 1 %>-<%= view.getOffset() + dcount %> of
      <%= view.getFindCount() %>)
    </util:font></td>

    <td width="50%" align="right" class="content">
      <% if (go_next || (view.getOffset()>0)) { %>
        <%-- The navigational form that allows us to page through the results --%>
        <util:comment>Navigational Form</util:comment>
        <util:form action="comm/members.js.vs" type="servlet"><div class="content">
          <input type="hidden" name="cc" value="<comm:ID/>" />
          <input type="hidden" name="sl" value="<%= view.getSimple() ? 1 : 0 %>" />
          <input type="hidden" name="ofs" value="<%= view.getOffset() %>" />
          <input type="hidden" name="field" value="<%= view.getField() %>" />
          <input type="hidden" name="mode" value="<%= view.getMode() %>" />
          <input type="hidden" name="term" value="<%= view.getTerm() %>" />
          <input type="hidden" name="fcount" value="<%= view.getFindCount() %>" />
          <% if (view.getOffset()>0) { %>
            <util:button id="previous" type="input"/>
          <% } else { %>
            <util:button id="_null_"/>
          <% } // end if %>
          &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));
            String fullname = uf.getGivenName() + " " + uf.getFamilyName();
            fullname = fullname.trim();
            if (StringUtil.isStringEmpty(fullname))
              fullname = uf.getName();
            String whence = "";
            if (!(StringUtil.isStringEmpty(uf.getLocality())))
            { // figure out the right locality
              if (!(StringUtil.isStringEmpty(uf.getRegion())))
                whence = uf.getLocality() + ", " + uf.getRegion();
              else
                whence = uf.getLocality();

            } // end if
            else if (!(StringUtil.isStringEmpty(uf.getRegion())))
              whence = uf.getRegion();
          %>
          <util:xlink>
            <util:href type="servlet">user/<%= uf.getName() %></util:href>
            <util:text><%= uf.getName() %></util:text>
          </util:xlink><br />
          <util:escape><%= fullname %></util:escape>, from <util:escape><%= whence %></util:escape>
          <% if (!(uf.getCountry().equals("XX"))) { %><%= uf.getCountry() %><% } %>
          <% if (view.isCommunityAdmin(uf)) { %>
            &nbsp;<util:image src="tag_host.gif" fixup="true" alt="Host!" width="40" height="20"/>
          <% } // end if %>
          <% if (uf.getDescription()!=null) { %>
            <br /><i><util:escape><%= uf.getDescription() %></util:escape></i>
          <% } // end if %>
        </util:font></td>
      </tr>
    <% } // end for %>
  </table><br clear="left" />
<% } // end if %>
<%-- EOF --%>
