[%# This Source Code Form is subject to the terms of the Mozilla Public
  # License, v. 2.0. If a copy of the MPL was not distributed with this
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  #
  # This Source Code Form is "Incompatible With Secondary Licenses", as
  # defined by the Mozilla Public License, v. 2.0.
  #%]

[% INCLUDE global/header.html.tmpl
  title = "Group Members Report"
  style_urls = [ "extensions/BMO/web/styles/reports.css" ]
%]

<form method="GET" action="[% basepath FILTER none %]page.cgi">
  <input type="hidden" name="id" value="group_members.html">

  <table id="parameters">
  <tr>
    <th>Group</th>
    <td>
      <select name="group">
        [% FOREACH group_name = groups %]
          <option value="[% group_name FILTER html %]"
                  [% "selected" IF group_name == group.name %]>
            [% group_name FILTER html %]</option>
        [% END %]
      </select>
      <input type="checkbox" name="include_disabled" id="include_disabled"
             value="1" [% "checked" IF include_disabled %]>
      <label for="include_disabled">
        Include disabled users
      </label>
      <input type="submit" value="Generate">
    </td>
  </tr>
  </table>
</form>

[% IF group != '' %]

  <p>
    [% count FILTER none %] member[% count == 1 ? '' : 's' %] of the <b>[% group.name FILTER html %]</b> group:
  </p>

  [% IF types.size > 0 %]
    <table id="report" class="standard">
    <thead>
      <tr>
        <th>Type</th>
        <th>Count</th>
        <th>Members</th>
        [% IF privileged %]
          <th class="right">2FA, Last Seen (days ago)</th>
        [% END %]
      </tr>
    </thead>
    <tbody>
      [% FOREACH type = types %]
        [% count = loop.count() %]
        <tr class="report_item [% count % 2 == 1 ? "report_row_odd" : "report_row_even" %]">
          <td valign="top" nowrap>
            [% IF type.name == 'direct' %]
              direct
            [% ELSE %]
              via
              [% IF privileged %]
                <a href="[% basepath FILTER none %]page.cgi?id=group_members.html&group=[% type.name FILTER uri %]">
                  [% type.name FILTER html %]
                </a>
              [% ELSE %]
                another group
              [% END %]
            [% END %]
          </td>
          <td valign="top" align="right">
            [% type.members.size FILTER html %]
          </td>
          <td valign="top" width="100%" colspan="2">
            <table cellspacing="0" class="hoverrow">
              [% FOREACH member = type.members %]
                <tr>
                  <td width="100%">
                    [% IF privileged %]
                      <a href="[% basepath FILTER none %]editusers.cgi?action=edit&amp;userid=[% member.id FILTER none %]"
                        target="_blank">
                    [% ELSE %]
                      <a href="[% basepath FILTER none %]user_profile?user_id=[% member.id FILTER none %]"
                        target="_blank">
                    [% END %]
                      <span [% 'class="bz_inactive"' UNLESS member.is_enabled %]>
                        [% member.name FILTER html %] &lt;[% member.email FILTER email FILTER html %]&gt;
                      </span>
                    </a>
                  </td>
                  [% IF privileged %]
                    <td nowrap>
                      [% IF member.mfa %]
                        [% member.mfa FILTER html %]
                        [% " (weakened)" IF member.settings.api_key_only.value == "off" %]
                      [% ELSE %]
                        -
                      [% END %]
                    </td>
                    <td align="right" nowrap>
                      [% member.last_seen_days > 30 ? ">30" : member.last_seen_days FILTER html %]
                    </td>
                  [% END %]
                </tr>
              [% END %]
            </table>
          </td>
        </tr>
      [% END %]
    </tbody>
    </table>

    <a href="[% basepath FILTER none %]page.cgi?id=group_members.json&amp;group=[% group.name FILTER uri %]
       [% IF include_disabled %]&amp;include_disabled=1[% END %]">JSON</a>
  [% ELSE %]
    <p>
      <i>This group is empty.</i>
    </p>
  [% END %]

[% END %]

[% INCLUDE global/footer.html.tmpl %]
