%# Natives who beat drums to drive off evil spirits are objects of
%# scorn to smart Americans who blow horns to break up traffic jams.
%# 		-- Mary Ellen Kelly
% if ($DoSearch) {
%    require URI::Escape;
<script><!--
    window.opener.location.href = 'index.html?'
% foreach my $kv (@Args) {
	+ '<% $kv->[0] %>=<% URI::Escape::uri_escape(Encode::encode_utf8($kv->[1])) %>&'
% }
    ;
    window.close();
--></script>
% $m->abort;
% }
<& /Edit/Elements/PopHeader, Title => loc('Query'), Action => 'Search.html' &>

<input type="hidden" name="DoSearch" value="1">
<table width="100%" border="0" cellspacing="6" cellpadding="0" class="poptable">
  <tr> 
    <td><img src="/img/space.png" width="6" height="4" align="absmiddle"> <label>
      <input type="radio" name="Limit" value="0" checked>
<&|/l&>List All Users</&></label></td>
  </tr>
  <tr> 
    <td><fieldset > <legend> <label>
      <input type="radio" name="Limit" value="1"><&|/l&>Enter one or more conditions below to search for users</&>
      </label></legend>
      <table border="0" cellspacing="3" cellpadding="0" align="center">
        <tr> 
          <td>&nbsp;</td>
          <td>&nbsp; </td>
        </tr>
        <tr> 
          <td><&|/l&>User Number</&></td>
          <td> 
            <input type="text" name="IdMin"  style="width:140px">
            <&|/l&>to</&> 
            <input type="text" name="IdMax"  style="width:140px">
            <&|/l&>number</&></td>
        </tr>
        <tr> 
          <td><&|/l&>Name</&></td>
          <td> 
            <input type="text" name="Name"  style="width:300px" value="">
          </td>
        </tr>
        <tr> 
          <td>Email</td>
          <td> 
            <input type="text" name="Email"  style="width:300px">
          </td>
        </tr>
        <tr> 
          <td><&|/l&>Group Name</&></td>
          <td> 
            <select name="GroupId" style="width:300px">
		<option></option>
% while (my $Group = $Groups->Next) {
%     my $name = $Group->Name or next;
<option value="<% $Group->id %>"><% $name %></option>
%}
            </select>
          </td>
        </tr>
        <tr> 
          <td>&nbsp;</td>
          <td>&nbsp; </td>
        </tr>
        <tr> 
          <td>&nbsp;</td>
          <td> 
            <input type="checkbox" name="FindDisabledUsers" value="1">
            <&|/l&>Include disabled users in search.</&></td>
        </tr>
        <tr> 
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
      </table>
      </fieldset></td>
  </tr>
</table>

<& /Edit/Elements/PopFooter &>
<%INIT>
my (@Args, $Groups);

if ($DoSearch) {
    foreach my $key (sort keys %ARGS) {
	next if $key =~ /^(?:user|pass|auth_digest|auth_nonce|auth_created)$/;
	my $val = $ARGS{$key};
	push @Args, [ $key => $_ ] foreach (ref($val) ? @$val : $val);
    }
}
else {
    $Groups = RT::Groups->new($session{'CurrentUser'});
    $Groups->LimitToUserDefinedGroups;
    $Groups->OrderBy( FIELD => 'Name', ORDER => 'DESC' );
}
</%INIT>
<%ARGS>
$DoSearch => undef
</%ARGS>
