%# BEGIN BPS TAGGED BLOCK {{{
%# 
%# COPYRIGHT:
%#  
%# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC 
%#                                          <jesse@bestpractical.com>
%# 
%# (Except where explicitly superseded by other copyright notices)
%# 
%# 
%# LICENSE:
%# 
%# This work is made available to you under the terms of Version 2 of
%# the GNU General Public License. A copy of that license should have
%# been provided with this software, but in any event can be snarfed
%# from www.gnu.org.
%# 
%# This work 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
%# General Public License for more details.
%# 
%# You should have received a copy of the GNU General Public License
%# along with this program; if not, write to the Free Software
%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
%# 02110-1301 or visit their web page on the internet at
%# http://www.gnu.org/copyleft/gpl.html.
%# 
%# 
%# CONTRIBUTION SUBMISSION POLICY:
%# 
%# (The following paragraph is not intended to limit the rights granted
%# to you to modify and distribute this software under the terms of
%# the GNU General Public License and is only of importance to you if
%# you choose to contribute your changes and enhancements to the
%# community by submitting them to Best Practical Solutions, LLC.)
%# 
%# By intentionally submitting any modifications, corrections or
%# derivatives to this work, or any other work intended for use with
%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
%# you are the copyright holder for those contributions and you grant
%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
%# royalty-free, perpetual, license to use, copy, create derivative
%# works based on those contributions, and sublicense and distribute
%# those contributions and any derivatives thereof.
%# 
%# END BPS TAGGED BLOCK }}}
<& /Elements/Tabs,
    actions => $actions,
    current_toptab => $current_toptab,
    current_tab => $current_tab,
    tabs => $tabs,
    Title => $Title,
&>

<%INIT>
my $current_toptab = "Dist/ByMaintainer.html?Name=" . $session{'CurrentUser'}->UserObj->Name;

my $tabs = {
    A => {
        title => loc('My Distributions'),
        path => 'Dist/ByMaintainer.html?Name=' . $session{'CurrentUser'}->UserObj->Name,
    },
    B => {
        title => loc('Search'),
        path => 'Dist/Search.html',
    },
    C => {
        title => loc('Browse'),
        path => 'Dist/Browse.html',
    },
};

my $queue_obj;
if ( $Queue ) {
    if (ref($Queue)) {
        $Queue = $Queue->Name;
    }
    else {
        my $tmp = RT::Queue->new( $session{'CurrentUser'} );
        $tmp->Load( $Queue );
        unless ( $tmp->id ) {
            $RT::Logger->warning( "Couldn't load queue '$Queue'");
        } else {
            $queue_obj = $tmp;
        }
        $Queue = $queue_obj->Name;
    }
}

my $escaped_queue = $m->interp->apply_escapes( $Queue, 'u' );

if ($Queue) {
    my $queue_display_path = 'Dist/Display.html?Queue='. $escaped_queue;
    $tabs->{'H'} = {
        title => $Queue,
        path => $queue_display_path,
    };
}

my $dist_subtabs = {
    A => {
        title   => loc("Active bugs"),
        path    => "Dist/Display.html?Status=Active&Queue=". $escaped_queue,
    },
    Ab => {
        title   => loc("Resolved bugs"),
        path    => "Dist/Display.html?Status=Resolved&Queue=". $escaped_queue,
    },
    Ac => {
        title   => loc("Rejected bugs"),
        path    => "Dist/Display.html?Status=Rejected&Queue=". $escaped_queue,
    },
};

if ( $queue_obj && !$queue_obj->Disabled ) {
    $dist_subtabs->{'G'} = {
        title   => loc("Report a new bug"),
        path    => 'Ticket/Create.html?Queue='. $escaped_queue,
    };
}

if ( $queue_obj
    && (
       $queue_obj->IsAdminCc( $session{'CurrentUser'}->id )
    || $queue_obj->CurrentUserHasRight('AdminQueue') ) )
{
    $dist_subtabs->{'J'} = {
        title   => loc("Manage"),
        path    => 'Dist/Manage.html?Queue='. $escaped_queue,
    };
}

# if we're looking at a page with a submenu, add it to the hash and set the
# current tab
if ($current_subtab =~ m!^(Dist/Display|Ticket/Create)\.html!) {
    $tabs->{'H'}->{'subtabs'} = $dist_subtabs;
    $tabs->{'H'}->{'current_subtab'} = $current_subtab;
    $current_tab = 'Dist/Display.html?Queue='. $escaped_queue;
}

</%INIT>

<%ARGS>
$Queue => undef
$actions => undef
$subtabs => undef
$current_tab => ''
$current_subtab => ''
$Title => undef
</%ARGS>
