{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<!-- $Id$ -->
<H1>{$layout.pagetitle}</H1>

<form method="POST" action="?m=rtqueuelist" id="filter" name="filter">
	<input type="hidden" name="m" value="rtqueuelist">
	<input type="hidden" name="deleted" value="0">
	<input type="hidden" name="deleted_tickets" value="0">
</form>

<TABLE class="lmsbox lms-ui-background-cycle">
	<COLGROUP>
			<COL style="width: 1%;">
			<COL style="width: 25%;">
			<COL style="width: 70%;">
			<COL style="width: 1%;">
			<COL style="width: 1%;">
			<COL style="width: 1%;">
			<COL style="width: 1%;">
			<COL style="width: 1%;">
			<COL style="width: 1%;">
			<COL style="width: 1%;">
	</COLGROUP>
    <THEAD>
	<TR>
		<TD class="bold nobr">
			{icon name="queue"}
		</TD>
		<TD class="bold nobr">
			{trans("Queue")}:
		</TD>
		<TD>
			{icon name="description"}
			{trans("Description")}:
		</TD>
		<TD class="text-right nobr bold">
			{trans("E-mail:")}
		</TD>
		<TD class="text-right">
			{trans("New:")}
		</TD>
		<TD class="text-right">
			{trans("Opened:")}
		</TD>
		<TD class="text-right">
			{trans("Unresolved:")}
		</TD>
		<TD class="text-right">
			{trans("Unread:")}
		</TD>
		<TD class="text-right">
			{trans("Last:")}
		</TD>
		<TD>
			{if ConfigHelper::checkPrivilege('helpdesk_administration')}
				{button label="New Queue" icon="add" href="?m=rtqueueadd"}
			{/if}
		</TD>
	</TR>
	<TR>
		<TD colspan="10">
			<div class="lms-ui-filter-container">
				<div class="lms-ui-filter-definition">
					<strong>{trans("Filter")}</strong>
					<label class="nobr">
						{trans("deleted queues")}
						<input type="checkbox" name="deleted" value="1" form="filter"
							onChange="document.filter.submit();"{if $filter.deleted == 1} checked{/if}>
					</label>
					<label class="nobr">
						{trans("deleted tickets")}
						<input type="checkbox" name="deleted_tickets" value="1" form="filter"
							onChange="document.filter.submit();"{if $filter.deleted_tickets == 1} checked{/if}>
					</label>
				</div>
				{persistent_filter}
			</div>
		</TD>
	</TR>
    </THEAD>
    <TBODY>
	{foreach $queues as $queue}
	<TR class="highlight lms-ui-resource{if $queue.deleted == 1 && $queue.deltime != 0}-deleted{elseif $queue.delcount != 0 && (ConfigHelper::checkPrivilege('helpdesk_advanced_operations'))}-partly-deleted{else}{/if}"
		data-target-url="?m=rtqueueview&id={$queue.id}" data-name="{$queue.name}"
		data-popup-menu-title="{t a=$queue.name}Queue $a{/t}">
		<TD class="nobr bold">
		{if $queue.critical != 0}
			{icon name="critical"}
		{else}
			{if $queue.unread}
				{icon name="unread"}
			{else}
				{icon name="queue"}
			{/if}
		{/if}
		</TD>
		<TD class="bold">
			{$queue.name}
		</TD>
		<TD>
			{if $queue.description}
				{icon name="description" label=$queue.description}
			{/if}
		<TD>
			<A HREF="mailto:{$queue.email}">{$queue.email}</A>
		</TD>
		<TD class="text-center nobr">
			{$queue.new|default:0}
		</TD>
		<TD class="text-center nobr">
			{$queue.open|default:0}
		</TD>
		<TD class="text-center nobr">
			{$queue.unresolved|default:0}
		</TD>
		<TD class="text-center nobr">
			{$queue.unread|default:0}
		</TD>
		<TD class="text-center nobr">
			{if $queue.lastticket}{$queue.lastticket|date_format:"Y-m-d H:i:s"}{else}-{/if}
		</TD>
		<TD class="lms-ui-buttons text-right nobr">
			{buttons}
				{button type="link" icon="add" tip="Add" onclick="window.location.href = '?m=rtticketadd&amp;id={$queue.id}';"}
				{if $queue.unread}
				{button type="link" href="?m=rtqueueedit&id={$queue.id}&unread=0" icon="read" tip="Mark queue as read"}
				{/if}
				{if $queue.deleted == 1 && $queue.deltime != 0 && (ConfigHelper::checkPrivilege('helpdesk_advanced_operations'))}
				{button type="link" href="?m=rtrestore&id={$queue.id}&qaction=restore" icon="reload" tip="Restore<!RT>"}
				{button type="link" href="?m=rtremove&id={$queue.id}&qaction=delperm" icon="delete" tip="Delete permanently" class="remove-rtqueue"}
				{else}
				{button type="link" href="?m=rtqueuedel&id={$queue.id}&amp;qaction=delete" icon="delete" tip="Delete" class="delete-rtqueue"}
				{/if}
				{button type="link" href="?m=rtqueueedit&amp;id={$queue.id}" icon="edit" tip="Edit" class="edit-rtqueue"}
				{button type="link" href="?m=rtqueueinfo&amp;id={$queue.id}" icon="info" tip="Info" class="info-rtqueue"}
			{/buttons}
		</TD>
	</TR>
	{foreachelse}
	<tr>
		<td colspan="10" class="empty-table">
			{trans("There are no queues.")} {trans('Click $a to create.', '<a href="?m=rtqueueadd">'|cat: trans('here')|cat: '</a>')}
		</td>
	</tr>
	{/foreach}
        </TBODY>
        <TFOOT>
	<TR class="lms-ui-button-panel">
		<TD COLSPAN="4" class="text-right bold">
			{icon name="count" label="Total"}
		</TD>
		<TD class="text-center bold">
			{sum array=$queues column=new}
		</TD>
		<TD class="text-center bold">
			{sum array=$queues column=open}
		</TD>
		<TD class="text-center bold">
			{sum array=$queues column=unresolved}
		</TD>
		<TD class="text-center bold">
			{sum array=$queues column=unread}
		</TD>
		<TD COLSPAN="2">
			&nbsp;
		</TD>
	</TR>
        </TFOOT>
</TABLE>
	<script>
		$('.delete-rtqueue').click(function() {
			var name = $(this).closest('tr').attr('data-name');
			confirmDialog($t("Are you sure, you want to remove queue '$a' and all assigned tickets and messages?", name), this).done(function() {
				location.href = $(this).attr('href');
			});
			return false;
		});
		$('.restore-rtqueue').click(function() {
			var name = $(this).closest('tr').attr('data-name');
			confirmDialog($t("Are you sure, you want to restore queue '$a' and all assigned tickets and messages?", name), this).done(function() {
				location.href = $(this).attr('href');
			});
			return false;
		});
		$('.remove-rtqueue').click(function() {
			var name = $(this).closest('tr').attr('data-name');
			confirmDialog($t("Are you sure, you want to permanently remove queue '$a' and all assigned tickets and messages?", name), this).done(function() {
				location.href = $(this).attr('href');
			});
			return false;
		});
	</script>
{/block}
