#!%PERL% -w
# Copyright (c) vhffs project and its contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without 
# modification, are permitted provided that the following conditions 
# are met:
#
# 1. Redistributions of source code must retain the above copyright 
#   notice, this list of conditions and the following disclaimer.
#2. Redistributions in binary form must reproduce the above copyright
#   notice, this list of conditions and the following disclaimer in 
#   the documentation and/or other materials provided with the 
#   distribution.
#3. Neither the name of vhffs nor the names of its contributors 
#   may be used to endorse or promote products derived from this 
#   software without specific prior written permission.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
# POSSIBILITY OF SUCH DAMAGE.

use strict;
use utf8;

package Vhffs::Panel::Menu;

use POSIX qw(locale_h);
use HTML::Template;
use locale;
use Locale::gettext;


=pod

=head1 NAME

Vhffs::Panel::Menu - Handle top menu in VHFFS panel.

=head1 METHODS

=head2 generate_project_ctxmenu

    print Vhffs::Panel::Main::generate_project_ctxmenu($vhffs->get_config);

Generates and returns the contextual menu for a project.

=cut

sub generate_project_ctxmenu($$) {
    my $config = shift;
    my $group = shift;
    my $context_tmpl = new HTML::Template( filename => $config->get_templatedir.'/panel/menu/context-group.tmpl' , global_vars => 1 );

    $context_tmpl->param( GROUPNAME => $group->get_groupname );

    my $items = [];
    push @$items, {path => 'web', label => gettext('Web') } if( $config->get_service_availability('web') );
    push @$items, {path => 'mysql', label => gettext('MySQL') } if( $config->get_service_availability('mysql') );
    push @$items, {path => 'pgsql', label => gettext('PgSQL') } if( $config->get_service_availability('pgsql') );
    push @$items, {path => 'cvs', label => gettext('CVS') } if( $config->get_service_availability('cvs') );
    push @$items, {path => 'svn', label => gettext('SVN') } if( $config->get_service_availability('svn') );
    push @$items, {path => 'git', label => gettext('GIT') } if( $config->get_service_availability('git') );
    push @$items, {path => 'mercurial', label => gettext('Mercurial') } if( $config->get_service_availability('mercurial') );
    push @$items, {path => 'bazaar', label => gettext('Bazaar') } if( $config->get_service_availability('bazaar') );
    push @$items, {path => 'dns', label => gettext('Domain names') } if( $config->get_service_availability('dns') );
    push @$items, {path => 'repository', label => gettext('Dl repos') } if( $config->get_service_availability('repository') );
    push @$items, {path => 'mail', label => gettext('Mail') } if( $config->get_service_availability('mail') );
    push @$items, {path => 'mailinglist', label => gettext('ML') } if( $config->get_service_availability('mailinglist') );
    push @$items, {path => 'cron', label => gettext('Crons') } if( $config->get_service_availability('cron') );
    $context_tmpl->param( MENU_ITEMS => $items );
    return $context_tmpl->output();
}

=head2 generate_moderator_ctxmenu

    print Vhffs::Panel::Main::generate_moderator_ctxmenu($vhffs->get_config);

Generates and returns the contextual menu for moderation part.

=cut

sub generate_moderator_ctxmenu {
    my $config = shift;
    my $context_tmpl = new HTML::Template( filename => $config->get_templatedir.'/panel/menu/context-modo.tmpl' );

    my $items = [];
    push @$items, {path => 'admin/stats.pl', label => gettext('Get Statistics') };
    push @$items, {path => 'admin/moderation.pl', label => gettext('Moderation') };
    $context_tmpl->param( MENU_ITEMS => $items );
    return $context_tmpl->output();
}

=head2 generate_admin_ctxmenu

    print Vhffs::Panel::Main::generate_admin_ctxmenu($vhffs->get_config);

Generates and returns the contextual menu for platform administration.

=cut

sub generate_admin_ctxmenu($) {
    my $config = shift;
    my $context_tmpl = new HTML::Template( filename => $config->get_templatedir.'/panel/menu/context.tmpl' );

    my $items = [];
    push @$items, {path => 'admin', label => gettext('General') };
    push @$items, {path => 'admin/user', label => gettext('Users') };
    push @$items, {path => 'admin/group', label => gettext('Groups') };
    push @$items, {path => 'admin/web', label => gettext('Web') } if( $config->get_service_availability('web') );
    push @$items, {path => 'admin/mysql', label => gettext('MySQL') } if( $config->get_service_availability('mysql') );
    push @$items, {path => 'admin/pgsql', label => gettext('PgSQL') } if( $config->get_service_availability('pgsql') );
    push @$items, {path => 'admin/cvs', label => gettext('CVS') } if( $config->get_service_availability('cvs') );
    push @$items, {path => 'admin/svn', label => gettext('SVN') } if( $config->get_service_availability('svn') );
    push @$items, {path => 'admin/git', label => gettext('GIT') } if( $config->get_service_availability('git') );
    push @$items, {path => 'admin/mercurial', label => gettext('Mercurial') } if( $config->get_service_availability('mercurial') );
    push @$items, {path => 'admin/bazaar', label => gettext('Bazaar') } if( $config->get_service_availability('bazaar') );
    push @$items, {path => 'admin/dns', label => gettext('Domain names') } if( $config->get_service_availability('dns') );
    push @$items, {path => 'admin/repository', label => gettext('Dl repos') } if( $config->get_service_availability('repository') );
    push @$items, {path => 'admin/mail', label => gettext('Mail') } if( $config->get_service_availability('mail') );
    push @$items, {path => 'admin/mailinglist', label => gettext('ML') } if( $config->get_service_availability('mailinglist') );
    push @$items, {path => 'admin/cron', label => gettext('Crons') } if( $config->get_service_availability('cron') );
    $context_tmpl->param( MENU_ITEMS => $items );
    return $context_tmpl->output();

}

1;
