[%# 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.
  #%]

[% PROCESS global/variables.none.tmpl %]

[% IF user.id %]
  [% filtered_identity = target.identity FILTER html %]
[% ELSE %]
  [% filtered_identity = target.name || target.address.user FILTER html %]
[% END %]
[% PROCESS global/header.html.tmpl
   title = "User Profile: $filtered_identity"
   generate_api_token = 1
   style_urls = [ "extensions/UserProfile/web/styles/user_profile.css" ]
   javascript_urls = [ "js/field.js" ]
%]

<table id="user_profile_table">

[% IF user.id %]
  <tr>
    <td>&nbsp;</td>
    <th>Search</th>
    <td colspan="2">
      <form action="[% basepath FILTER html %]user_profile">
        [% INCLUDE global/userselect.html.tmpl
          id => "login"
          name => "login"
          value => login
          size => 40
          emptyok => 0
        %]
        &nbsp;&nbsp;<input type="submit" value="Show">
      </form>
    </td>
  </tr>

  <tr>
    <td colspan="4" class="separator"><hr></td>
  </tr>
[% END %]

<tr>
  [% permissions_offset = target.in_group("canconfirm") == 1 ? 1 : 0 %]
  [% creation_offset = target.can('creation_ts') == 1 ? 1 : 0 %]
  [% edit_preferences_offset = user.id ? 1 : 0 %]
   <td rowspan="[% 3 + edit_preferences_offset + permissions_offset + creation_offset FILTER html %]" id="gravatar-container">
    [% IF user.gravatar %]
      <img id="gravatar" src="[% target.gravatar(256) FILTER none %]" width="128" height="128"><br>
      [% IF target.id == user.id %]
        <a href="https://gravatar.com/">Change my image</a>
      [% END %]
    [% ELSE %]
      &nbsp;
    [% END %]
  </td>
  <th>User</th>
  <td colspan="2">
    [% INCLUDE bug_modal/user.html.tmpl u = target hide_profile = 1 %]
    [% " (disabled)" UNLESS target.is_enabled %]
  </td>
</tr>

[%# user.creation_ts is added by the TagNewUsers extension %]
[% IF target.can('creation_ts') %]
  <tr>
    <th>Created</th>
    <td colspan="2">
      [% target.creation_ts FILTER time %] ([% target.creation_ts FILTER timeago FILTER html %])
    </td>
  </tr>
[% END %]

<tr>
  <th>Last activity</th>
  <td colspan="2">
    [% IF user.id %]
      <a href="[% basepath FILTER none %]page.cgi?id=user_activity.html&amp;action=run&amp;who=[% target.login FILTER uri %]">
    [% END %]
    [% target.last_activity_ts FILTER time %]
    [% "</a>" IF user.id %]
  </td>
</tr>

[% IF target.in_group("canconfirm") %]
  <tr>
    <th>Permissions</th>
    <td colspan="2">
      Can confirm [% terms.bugs %]
      [% IF target.in_group("editbugs") ~%]
        , can edit any [% terms.bug %]
      [% END %]
    </td>
  </tr>
[% END %]

<tr>
  <td>&nbsp;</td>
</tr>

[% IF user.id %]
<tr>
    <th></th>
    <td colspan="2">
      [% IF target.id == user.id %]
        <a href="[% basepath FILTER none %]userprefs.cgi?tab=account"><input type="button" value = "Edit Profile & Preferences"></a>
      [% END %]
    </td>
  </tr>
[% END %]

[%# request counters provided by the Review extension %]
[% IF target.can("review_count")
      && (
        stats.reviews
        || (
          target.review_request_count
          || target.feedback_request_count
          || target.needinfo_request_count
        )
      )
%]
  <tr>
    <td colspan="4" class="separator"><hr></td>
  </tr>
  <tr>
    <td>Review Queue</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <th>Review requests</th>
    <td class="numeric">
      [% IF user.id %]
        <a href="[% basepath FILTER none %]request.cgi?action=queue&amp;type=review&amp;requestee=[% target.login FILTER uri %]&amp;group=type"
          target="_blank">
      [% END %]
      [% target.review_request_count FILTER html %]
      [% "</a>" IF user.id %]
    </td>
    [% IF user.id %]
      <td>
        (<a href="[% basepath FILTER none %]page.cgi?id=review_history.html&amp;requestee=[% target.login FILTER uri %]">Review History</a>)
      </td>
    [% END %]
  </tr>
  <tr>
    <td>&nbsp;</td>
    <th>Feedback requests</th>
    <td class="numeric">
      [% IF user.id %]
        <a href="[% basepath FILTER none %]request.cgi?action=queue&amp;type=feedback&amp;requestee=[% target.login FILTER uri %]&amp;group=type"
          target="_blank">
      [% END %]
      [% target.feedback_request_count FILTER html %]
      [% "</a>" IF user.id %]
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <th>Needinfo requests</th>
    <td class="numeric">
      [% IF user.id %]
        <a href="[% basepath FILTER none %]request.cgi?action=queue&amp;type=needinfo&amp;requestee=[% target.login FILTER uri %]&amp;group=type"
          target="_blank">
      [% END %]
      [% target.needinfo_request_count FILTER html %]
      [% "</a>" IF user.id %]
    </td>
  </tr>
[% END %]

<tr>
  <td colspan="4" class="separator"><hr></td>
</tr>
<tr>
  <td>User Statistics</td>
</tr>

<tr>
  <td>&nbsp;</td>
  <th>[% terms.Bugs %] filed</th>
  <td class="numeric">
    [% IF user.id %]
      <a href="[% basepath FILTER none %]buglist.cgi?query_format=advanced&amp;emailtype1=exact&amp;emailreporter1=1&amp;email1=[% target.login FILTER uri %]"
        target="_blank">
    [% END %]
    [% stats.bugs_filed || 0 FILTER html %]
    [% "</a>" IF user.id %]
  </td>
</tr>
<tr>
  <td>&nbsp;</td>
  <th>Comments made</th>
  <td class="numeric">[% stats.comments || 0 FILTER html %]</td>
</tr>
<tr>
  <td>&nbsp;</td>
  <th>Assigned to</th>
  <td class="numeric">
    [% IF user.id %]
      <a href="[% basepath FILTER none %]buglist.cgi?query_format=advanced&amp;emailtype1=exact&amp;emailassigned_to1=1&amp;email1=[% target.login FILTER uri %]"
        target="_blank">
    [% END %]
    [% stats.assigned || 0 FILTER html %]
    [% "</a>" IF user.id %]
  </td>
</tr>
<tr>
  <td>&nbsp;</td>
  <th>Commented on</th>
  <td class="numeric">
    [% IF user.id %]
      <a href="[% basepath FILTER none %]buglist.cgi?query_format=advanced&amp;emailtype1=exact&amp;emaillongdesc1=1&amp;email1=[% target.login FILTER uri %]"
        target="_blank">
    [% END %]
    [% stats.commented_on || 0 FILTER html %]
    [% "</a>" IF user.id %]
  </td>
</tr>
<tr>
  <td>&nbsp;</td>
  <th>QA-Contact</th>
  <td class="numeric">
    [% IF user.id %]
      <a href="[% basepath FILTER none %]buglist.cgi?query_format=advanced&amp;emailtype1=exact&amp;emailqa_contact1=1&amp;email1=[% target.login FILTER uri %]"
        target="_blank">
    [% END %]
    [% stats.qa_contact || 0 FILTER html %]
    [% "</a>" IF user.id %]
  </td>
</tr>
<tr>
  <td>&nbsp;</td>
  <th>Patches submitted</th>
  <td class="numeric">[% stats.patches || 0 FILTER html %]</td>
</tr>
<tr>
  <td>&nbsp;</td>
  <th>Patches reviewed</th>
  <td class="numeric">[% stats.reviews || 0 FILTER html %]</td>
</tr>
<tr>
  <td>&nbsp;</td>
  <th>[% terms.Bugs %] poked</th>
  <td class="numeric">[% stats.touched || 0 FILTER html %]</td>
</tr>

<tr>
  <td>&nbsp;</td>
</tr>

<tr>
  <td>&nbsp;</td>
  <th>[% terms.Bugs %] resolved as</th>
  <td colspan="2">
    RESOLVED ([% statuses.item('RESOLVED') || 0 FILTER html %]),
    FIXED ([% statuses.item('RESOLVED/FIXED') || 0 FILTER html %]),
    VERIFIED ([% statuses.item('VERIFIED') || 0 FILTER html %]),
    INVALID ([% statuses.item('RESOLVED/INVALID') || 0 FILTER html %])
  </td>
</tr>

<tr>
  <td>&nbsp;</td>
  <th>Activity by product</th>
  <td colspan="2">
    [% FOREACH p = products %]
      <span class="product_span">
        [% IF p.product.id %]
          <a href="[% basepath FILTER none %]describecomponents.cgi?product=[% p.product.name FILTER uri %]"
            target="_blank">
        [% END %]
        [% p.product.name FILTER html %] ([% p.count || 0 FILTER html %])
        [% "</a>" IF p.product.id %]
        [% "," UNLESS loop.last ~%]
      </span>
    [%+ END %]
  </td>
</tr>

<tr>
  <td colspan="3">
    <div id="what">
      <a href="https://wiki.mozilla.org/BMO/User_profile_fields" target="_blank">
        What do these fields mean?
      </a>
    </div>

    <div id="updated">
      This information is updated daily
    </div>
  </td>
</tr>

<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td width="100%">&nbsp;</td>
</tr>

</table>

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