{##
 # The ticket listing showing all a users tickets
 ##}
{% import 'UserBundle::macros.html.twig' as dp %}
{% import 'UserBundle:Tickets:list.html.twig' as ticket_macro %}
{% extends 'UserBundle::layout.html.twig' %}
{% block breadcrumb %}
	<li><span class="dp-divider">{{ language_arrow('right') }}</span> <a href="{{ path('user_tickets') }}">{{ phrase('user.tickets.organization_tickets', {organization: organization.name}) }}</a></li>
{% endblock %}
{% block page_title %}{{ phrase('user.tickets.organization_tickets', {organization: organization.name}) }}{% endblock %}
{% block content %}

{% set sort_form %}
	<form class="dp-ticket-sort" action="{{ path('user_tickets_organization') }}">
		<select name="sort">
			<option value="date_created" {% if sort == 'date_created' %}selected="selected"{% endif %}>{{ phrase('user.tickets.date_created') }}</option>
			<option value="last_reply" {% if sort == 'last_reply' %}selected="selected"{% endif %}>{{ phrase('user.tickets.last_reply') }}</option>
			<option value="creator" {% if sort == 'creator' %}selected="selected"{% endif %}>{{ phrase('user.tickets.creator') }}</option>
			<option value="department" {% if sort == 'department' %}selected="selected"{% endif %}>{{ phrase('user.tickets.fields_department') }}</option>
		</select>
		<input type="submit" class="dp-btn-primary" value="{{ phrase('user.general.btn_sort') }}" />
	</form>
{% endset %}

{% if show_split %}
	{% if active_tickets|length %}
		<section class="dp-ticketlist-section dp-portal-section">
			<header>
				{{ sort_form|raw }}
				<h1>{{ phrase('user.tickets.open_tickets') }}</h1>
			</header>
			<div class="dp-content-block">
				<div class="dp-content-wrapper">
					<ul class="dp-ticket-list">
						{% for ticket in active_tickets %}
							{{ ticket_macro.ticket_row(ticket, last_messages) }}
						{% endfor %}
					</ul>
				</div>
			</div>
		</section>

		<br />
	{% endif %}

	{% if resolved_tickets|length %}
		<section class="dp-ticketlist-section dp-portal-section">
			<header>
				{% if not active_tickets %}{{ sort_form|raw }}{% endif %}
				<h1>{{ phrase('user.tickets.list_resolved') }}</h1>
			</header>
			<div class="dp-content-block">
				<div class="dp-content-wrapper">
					<ul class="dp-ticket-list">
						{% for ticket in resolved_tickets %}
							{{ ticket_macro.ticket_row(ticket, last_messages) }}
						{% endfor %}
					</ul>
				</div>
			</div>
		</section>

		<br />
	{% endif %}
{% else %}
	{% if all_tickets|length %}
		<section class="dp-ticketlist-section dp-portal-section">
			<header>
				{% if all_tickets|length %}{{ sort_form|raw }}{% endif %}
				<h1>{{ phrase('user.tickets.tickets') }}</h1>
			</header>
			<div class="dp-content-block">
				<div class="dp-content-wrapper">
					<ul class="dp-ticket-list">
						{% for ticket in all_tickets %}
							{{ ticket_macro.ticket_row(ticket, last_messages, false, true) }}
						{% endfor %}
					</ul>
				</div>
			</div>
		</section>

		<br />
	{% endif %}
{% endif %}

{% if pageinfo.last != 1 %}
	<br/>
	{% set page_url = path('user_tickets_organization') ~ '?sort=' ~ sort ~ '&p=' %}

	<div class="dp-pagination">
		<ul>
			{% if pageinfo.curpage == 1 %}
				{% if pageinfo.next %}<li><a href="{{ page_url ~ pageinfo.next }}">{{ phrase('user.general.more') }} {{ language_arrow('right') }}</a></li>{% endif %}
			{% else %}
				{% if pageinfo.prev %}<li><a href="{{ page_url ~ pageinfo.prev }}">{{ language_arrow('left') }} {{ phrase('user.general.page_prev') }}</a></li>{% endif %}
				{% for p in pageinfo.pages %}
				<li class="{% if pageinfo.cursor == p %}dp-active{% endif %}"><a href="{{ page_url ~ p }}">{{ p }}</a>
					{% endfor %}
				{% if pageinfo.next %}<li><a href="{{ page_url ~ pageinfo.next }}">{{ phrase('user.general.next') }} {{ language_arrow('right') }}</a></li>{% endif %}
			{% endif	 %}
		</ul>
	</div>
{% endif %}
{% endblock %}
