{#
# GNU MediaGoblin -- federated, autonomous media hosting
# Copyright (C) 2011, 2012 MediaGoblin contributors.  See AUTHORS.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#}
{% extends "mediagoblin/base.html" %}
{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %}

{% block title -%}
  {% trans %}Report panel{% endtrans %} &mdash; {{ super() }}
{%- endblock %}

{% block mediagoblin_content %}

<h1>{% trans %}Report panel{% endtrans %}</h1>

<p>
  {% trans %}
    Here you can look up open reports that have been filed by users.
  {% endtrans %}
</p>

<h2>{% trans %}Active Reports Filed{% endtrans %}</h2>
{% if report_list.count() %}
  {% if not active_settings.last_page == 1 %}
  {% if 'active_p='~active_settings.current_page in request.query_string %}
    {% set query_string = request.query_string %}{% else %}
    {% set query_string =
'active_p='~active_settings.current_page~"&"+request.query_string %}
  {% endif %}
  <div class="right_align">
    {% set first_vis = active_settings.current_page-3  %}
    {% set last_vis = active_settings.current_page+3 %}
    {% set curr_page = active_settings.current_page %}
    {% if 1 == curr_page %}<b>1</b>{% else %}
    <a href ="?{{ query_string.replace(
                    'active_p='~active_settings.current_page,
                    'active_p='~1) }}">
        1</a>{% endif %}
    {% if first_vis > 1 %}...{% endif %}
    {% for p in range(first_vis,last_vis+1) %}
      {% if p > 1 and p < active_settings.last_page and
curr_page !=p %}
        <a href="?{{ query_string.replace(
                    'active_p='~active_settings.current_page,
                    'active_p='~p) }}">
          {{ p }}</a>
      {% elif p > 1 and p < active_settings.last_page %}
        <b>{{ p }}</b>
      {% endif  %}
    {% endfor %}
    {% if last_vis < active_settings.last_page %}...{% endif %}
    {% if active_settings.last_page != curr_page %}
    <a href ="?{{ query_string.replace(
                    'active_p='~active_settings.current_page,
                    'active_p='~active_settings.last_page) }}">
      {{ active_settings.last_page }}</a>
    {% else %}<b>{{ active_settings.last_page }}</b>
    {% endif %}
  </div>
  {% endif %}
  <table class="admin_panel processing">
    <tr>
      <th></th>
      <th>{% trans %}Offender{% endtrans %}</th>
      <th>{% trans %}When Reported{% endtrans %}</th>
      <th>{% trans %}Reported By{% endtrans %}</th>
      <th>{% trans %}Reason{% endtrans %}</th>
    </tr>
    {% for report in report_list %}
      <tr>
        {% if report.is_comment_report %}
          <td>
            <img
              src="{{ request.staticdirect(
                '/images/icon_clipboard_alert.png') }}"
              alt=""
              title="Under a GNU LGPL v.3 or Creative Commons BY-SA 3.0 license.
                   Distributed by the GNOME project http://www.gnome.org" />
            <a href="{{ request.urlgen(
                    'mediagoblin.moderation.reports_detail',
                     report_id=report.id) }}">
              {% trans report_id=report.id %}
                Comment Report #{{ report_id }}
              {% endtrans %}
            </a>
          </td>
        {% elif report.is_media_entry_report %}
          <td>
            <img
              src="{{ request.staticdirect(
                '/images/icon_clipboard_alert.png') }}"
              alt=""
              title="Under a GNU LGPL v.3 or Creative Commons BY-SA 3.0 license.
                   Distributed by the GNOME project http://www.gnome.org" />
            <a href="{{ request.urlgen(
                    'mediagoblin.moderation.reports_detail',
                    report_id=report.id) }}">
              {% trans report_id=report.id %}
                Media Report #{{ report_id }}
              {% endtrans %}
            </a>
          </td>
        {% endif %}
          <td>{{ report.reported_user.username }}</td>
          <td>{{ report.created.strftime("%F %R") }}</td>
          <td>{{ report.reporter.username }}</td>
          <td>{{ report.report_content[0:20] }}...</td>
      </tr>
    {% endfor %}
  </table>
{% else %}
  <p><em>{% trans %}No open reports found.{% endtrans %}</em></p>
{% endif %}
<h2>{% trans %}Closed Reports{% endtrans %}</h2>
{% if closed_report_list.count() %}
  {% if not closed_settings.last_page == 1 %}
  {% if 'closed_p='~closed_settings.current_page in request.query_string %}
    {% set query_string = request.query_string %}{% else %}
    {% set query_string =
'closed_p='~closed_settings.current_page~"&"+request.query_string %}
  {% endif %}
  <div class="right_align">
    {% set first_vis = closed_settings.current_page-3  %}
    {% set last_vis = closed_settings.current_page+3 %}
    {% set curr_page = closed_settings.current_page %}
    {% if not curr_page==1 %}
    <a href ="?{{ query_string.replace(
                    'closed_p='~closed_settings.current_page,
                    'closed_p='~1) }}">1</a>
    {% else %}
      <b>1 </b>
    {% endif %}
    {% if first_vis > 1 %}...{% endif %}
    {% for p in range(first_vis,last_vis+1) %}
      {% if p > 1 and p < closed_settings.last_page and
curr_page !=p %}
        <a href="?{{ query_string.replace(
                    'closed_p='~closed_settings.current_page,
                    'closed_p='~p) }}">
          {{ p }}</a>

      {% elif p > 1 and p < closed_settings.last_page %}
        <b>{{ p }}</b>
      {% endif  %}
    {% endfor %}
    {% if last_vis < closed_settings.last_page %}...{% endif %}
    {% if curr_page != closed_settings.last_page %}
      <a href ="?{{ query_string.replace(
                    'closed_p='~closed_settings.current_page,
                    'closed_p='~closed_settings.last_page) }}">
        {{ closed_settings.last_page }}</a>
    {% else  %}<b>{{ closed_settings.last_page }}</b>
    {% endif %}
  </div>
  {% endif %}
  <table class="media_panel processing">
    <tr>
      <th></th>
      <th>{% trans %}Resolved{% endtrans %}</th>
      <th>{% trans %}Offender{% endtrans %}</th>
      <th>{% trans %}Action Taken{% endtrans %}</th>
      <th>{% trans %}Reported By{% endtrans %}</th>
      <th>{% trans %}Reason{% endtrans %}</th>
    </tr>
    {% for report in closed_report_list %}
      <tr>
        <td>
          <img
            src="{{ request.staticdirect('/images/icon_clipboard.png') }}"
            alt=""
            title="Under a GNU LGPL v.3 or Creative Commons BY-SA 3.0 license.
                 Distributed by the GNOME project http://www.gnome.org" />
          <a href="{{ request.urlgen('mediagoblin.moderation.reports_detail',
                          report_id=report.id) }}">
            {% trans report_id=report.id %}
              Closed Report #{{ report_id }}
            {% endtrans %}
          </a>
        </td>
        <td>{{ report.resolved.strftime("%F %R") }}</td>
        <td>{{ report.reported_user.username }}</td>
        <td>{{ report.created.strftime("%F %R") }}</td>
        <td>{{ report.reporter.username }}</td>
        <td>{{ report.report_content[:15] }}...</td>
      </tr>
    {% endfor %}
  </table>
{% else %}
  <p><em>{% trans %}No closed reports found.{% endtrans %}</em></p>
{% endif %}

{% endblock %}
