%# MyQueues 2.0 -- Andy Moran 10/05/2005

<&|/Elements/TitleBox, 
        title => loc("[_1] newest unowned tickets in the queues I watch", $rows),
	title_href => "Search/Results.html".$QueryString &>
<& /Elements/TicketList, 
        Format => "'<a href=\"$RT::WebPath/Ticket/Display.html?id=__id__\">__id__</a>/TITLE:#', '<a href=\"$RT::WebPath/Ticket/Display.html?id=__id__\">__Subject__</a>/TITLE:Subject', QueueName, ExtendedStatus, CreatedRelative, '<A HREF=\"$RT::WebPath/Ticket/Display.html?Action=Take&id=__id__\">".loc('Take')."</a>/TITLE:&nbsp;' ",
        Query => $Query,
        OrderBy => 'Created',
        Order => 'DESC',
        ShowNavigation => 0,
        Rows => $rows

        &>
</&>

<%init>

my $rows = $RT::MyRequestsLength;

my $Queues = RT::Queues->new($session{'CurrentUser'}); 
my $userEmail = $session{'CurrentUser'}->EmailAddress;
$Queues->UnLimit();
my @QueueList = ();
while (my $queue = $Queues->Next) {
    my $watcherEmails = $queue->AdminCcAddresses();
    next if $watcherEmails !~ /\b$userEmail/;
    next unless ($queue->CurrentUserHasRight('ShowTicket'));
    push(@QueueList, $queue->Name);
}

my $Query = "";

if (scalar(@QueueList) == 0) {
    $Query = "Queue = 'None'";
} else {
    $Query = "Owner = 'Nobody' AND ( Status = 'new' OR Status = 'open') AND ( Queue = '". join("' OR Queue = '", @QueueList) . "')";

}

my $QueryString = "";
$QueryString = '?' . $m->comp('/Elements/QueryString', 
                              Query => $Query,
                              Order => 'DESC',
                              OrderBy => 'Priority') if ($Query);

</%init>

