2008-12-26 20:18:23 +01:00
|
|
|
##@file
|
2010-09-17 12:23:49 +02:00
|
|
|
# menu for lemonldap::ng portal
|
2008-12-26 20:18:23 +01:00
|
|
|
|
|
|
|
##@class
|
2010-09-17 12:23:49 +02:00
|
|
|
# menu class for lemonldap::ng portal
|
2008-09-18 10:34:17 +02:00
|
|
|
package Lemonldap::NG::Portal::Menu;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2010-09-16 17:10:00 +02:00
|
|
|
use Lemonldap::NG::Portal::Simple;
|
2010-09-17 12:23:49 +02:00
|
|
|
use Lemonldap::NG::Portal::_LibAccess;
|
2010-10-02 17:45:10 +02:00
|
|
|
use base qw(Lemonldap::NG::Portal::_LibAccess);
|
2011-04-14 10:52:41 +02:00
|
|
|
use Clone qw(clone);
|
2009-02-12 20:48:53 +01:00
|
|
|
|
2011-06-01 17:24:27 +02:00
|
|
|
our $VERSION = '1.1.0';
|
2010-09-17 12:23:49 +02:00
|
|
|
our $catlevel = 0;
|
2008-09-18 10:34:17 +02:00
|
|
|
|
2010-09-16 17:10:00 +02:00
|
|
|
## @method void menuInit()
|
|
|
|
# Prepare menu template elements
|
|
|
|
# @return nothing
|
|
|
|
sub menuInit {
|
2008-11-14 08:16:26 +01:00
|
|
|
my $self = shift;
|
2010-02-11 13:39:42 +01:00
|
|
|
$self->{apps}->{imgpath} ||= '/apps/';
|
2008-09-18 10:34:17 +02:00
|
|
|
|
2010-09-16 17:10:00 +02:00
|
|
|
# Modules to display
|
2012-01-10 20:54:30 +01:00
|
|
|
$self->{menuModules} ||= "Appslist ChangePassword LoginHistory Logout";
|
2010-09-16 17:10:00 +02:00
|
|
|
$self->{menuDisplayModules} = $self->displayModules();
|
2008-09-18 10:34:17 +02:00
|
|
|
|
2010-09-16 17:10:00 +02:00
|
|
|
# Extract password from POST data
|
|
|
|
$self->{oldpassword} = $self->param('oldpassword');
|
|
|
|
$self->{newpassword} = $self->param('newpassword');
|
|
|
|
$self->{confirmpassword} = $self->param('confirmpassword');
|
|
|
|
$self->{dn} = $self->{sessionInfo}->{dn};
|
|
|
|
$self->{user} = $self->{sessionInfo}->{_user};
|
2008-09-26 09:36:30 +02:00
|
|
|
|
2010-09-16 17:10:00 +02:00
|
|
|
# Try to change password
|
2011-11-07 17:59:54 +01:00
|
|
|
$self->{menuError} =
|
|
|
|
$self->_subProcess(qw(passwordDBInit modifyPassword sendPasswordMail))
|
2011-06-29 14:47:25 +02:00
|
|
|
unless $self->{ignorePasswordChange};
|
2008-09-18 10:34:17 +02:00
|
|
|
|
2010-09-16 17:10:00 +02:00
|
|
|
# Default menu error code
|
|
|
|
$self->{menuError} ||= $self->{error};
|
2008-10-07 22:15:48 +02:00
|
|
|
|
2010-09-16 17:10:00 +02:00
|
|
|
# Tab to display
|
2011-07-01 15:02:45 +02:00
|
|
|
# Get the tab URL parameter
|
|
|
|
$self->{menuDisplayTab} = $self->param("tab") || "none";
|
|
|
|
|
|
|
|
# Default to appslist if invalid tab URL parameter
|
|
|
|
$self->{menuDisplayTab} = "appslist"
|
|
|
|
unless ( $self->{menuDisplayTab} =~ /^(password|logout)$/ );
|
|
|
|
|
|
|
|
# Force password tab in case of password error
|
2010-09-16 17:10:00 +02:00
|
|
|
$self->{menuDisplayTab} = "password"
|
2008-10-07 22:15:48 +02:00
|
|
|
if (
|
|
|
|
(
|
|
|
|
scalar(
|
2010-09-16 17:10:00 +02:00
|
|
|
grep { $_ == $self->{menuError} } (
|
2008-10-07 22:15:48 +02:00
|
|
|
25, #PE_PP_CHANGE_AFTER_RESET
|
|
|
|
27, #PE_PP_MUST_SUPPLY_OLD_PASSWORD
|
|
|
|
28, #PE_PP_INSUFFICIENT_PASSWORD_QUALITY
|
|
|
|
29, #PE_PP_PASSWORD_TOO_SHORT
|
|
|
|
30, #PE_PP_PASSWORD_TOO_YOUNG
|
|
|
|
31, #PE_PP_PASSWORD_IN_HISTORY
|
|
|
|
32, #PE_PP_GRACE
|
|
|
|
33, #PE_PP_EXP_WARNING
|
|
|
|
34, #PE_PASSWORD_MISMATCH
|
2009-12-10 12:30:43 +01:00
|
|
|
39, #PE_BADOLDPASSWORD
|
2008-10-07 22:15:48 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2008-09-19 17:28:00 +02:00
|
|
|
|
2011-03-03 23:34:09 +01:00
|
|
|
# Application list for old templates
|
2011-06-01 17:24:27 +02:00
|
|
|
if ( $self->{useOldMenuItems} ) {
|
|
|
|
$self->{menuAppslistMenu} = $self->appslistMenu();
|
|
|
|
$self->{menuAppslistDesc} = $self->appslistDescription();
|
|
|
|
}
|
2010-09-16 17:10:00 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
## @method arrayref displayModules()
|
|
|
|
# List modules that can be displayed in Menu
|
|
|
|
# @return modules list
|
|
|
|
sub displayModules {
|
|
|
|
my $self = shift;
|
|
|
|
my $displayModules = [];
|
|
|
|
|
|
|
|
# Modules list
|
|
|
|
my @modules = split( /\s/, $self->{menuModules} );
|
|
|
|
|
|
|
|
# Foreach module, eval condition
|
|
|
|
# Store module in result if condition is valid
|
|
|
|
foreach my $module (@modules) {
|
|
|
|
my $cond = $self->{ 'portalDisplay' . $module };
|
|
|
|
$cond = 1 unless defined $cond;
|
|
|
|
|
|
|
|
$self->lmLog( "Evaluate condition $cond for module $module", 'debug' );
|
|
|
|
|
|
|
|
if ( $self->safe->reval($cond) ) {
|
2010-09-20 12:39:23 +02:00
|
|
|
my $moduleHash = { $module => 1 };
|
|
|
|
$moduleHash->{'APPSLIST_LOOP'} = $self->appslist()
|
|
|
|
if ( $module eq 'Appslist' );
|
2012-01-10 20:54:30 +01:00
|
|
|
if ( $module eq 'LoginHistory' ) {
|
|
|
|
$moduleHash->{'SUCCESS_LOGIN'}
|
|
|
|
= $self->mkSessionArray(
|
|
|
|
$self->{sessionInfo}->{loginHistory}->{successLogin},
|
|
|
|
"", 0, 0
|
|
|
|
);
|
|
|
|
$moduleHash->{'FAILED_LOGIN'}
|
|
|
|
= $self->mkSessionArray(
|
|
|
|
$self->{sessionInfo}->{loginHistory}->{failedLogin},
|
|
|
|
"", 0, 1
|
|
|
|
);
|
|
|
|
}
|
2010-09-20 12:39:23 +02:00
|
|
|
push @$displayModules, $moduleHash;
|
2010-09-16 17:10:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $displayModules;
|
2008-09-19 17:28:00 +02:00
|
|
|
}
|
|
|
|
|
2010-09-20 10:31:09 +02:00
|
|
|
## @method arrayref appslist()
|
2010-09-20 12:39:23 +02:00
|
|
|
# Returns categories and applications list as HTML::Template loop
|
2010-09-20 10:31:09 +02:00
|
|
|
# @return categories and applications list
|
|
|
|
sub appslist {
|
|
|
|
my ($self) = splice @_;
|
|
|
|
my $appslist = [];
|
|
|
|
|
|
|
|
return $appslist unless defined $self->{applicationList};
|
|
|
|
|
|
|
|
# Reset level
|
|
|
|
$catlevel = 0;
|
|
|
|
|
2011-04-14 10:52:41 +02:00
|
|
|
my $applicationList = clone( $self->{applicationList} );
|
2010-09-20 10:31:09 +02:00
|
|
|
my $filteredList = $self->_filter($applicationList);
|
2011-03-03 23:34:09 +01:00
|
|
|
push @$appslist, $self->_buildCategoryHash( "", $filteredList, $catlevel );
|
2010-09-20 10:31:09 +02:00
|
|
|
|
2011-03-03 23:34:09 +01:00
|
|
|
# We must return an ARRAY ref
|
|
|
|
return ( ref $appslist->[0]->{categories} eq "ARRAY" )
|
|
|
|
? $appslist->[0]->{categories}
|
|
|
|
: [];
|
2010-09-20 10:31:09 +02:00
|
|
|
}
|
|
|
|
|
2010-10-03 12:26:50 +02:00
|
|
|
## @method private hashref _buildCategoryHash(string catname,hashref cathash, int catlevel)
|
2010-09-20 10:31:09 +02:00
|
|
|
# Build hash for a category
|
|
|
|
# @param catname Category name
|
|
|
|
# @param cathash Hash of category elements
|
|
|
|
# @param catlevel Category level
|
|
|
|
# @return Category Hash
|
|
|
|
sub _buildCategoryHash {
|
2010-09-20 16:04:33 +02:00
|
|
|
my ( $self, $catid, $cathash, $catlevel ) = splice @_;
|
|
|
|
my $catname = $cathash->{catname} || $catid;
|
2010-09-20 10:31:09 +02:00
|
|
|
my $applications;
|
|
|
|
my $categories;
|
|
|
|
|
|
|
|
# Extract applications from hash
|
|
|
|
my $apphash;
|
2010-09-20 16:04:33 +02:00
|
|
|
foreach my $catkey ( sort keys %$cathash ) {
|
|
|
|
next if $catkey =~ /(type|options|catname)/;
|
2010-09-20 10:31:09 +02:00
|
|
|
if ( $cathash->{$catkey}->{type} eq "application" ) {
|
|
|
|
$apphash->{$catkey} = $cathash->{$catkey};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Display applications first
|
|
|
|
if ( scalar keys %$apphash > 0 ) {
|
2010-09-20 16:04:33 +02:00
|
|
|
foreach my $appkey ( sort keys %$apphash ) {
|
2010-09-20 10:31:09 +02:00
|
|
|
push @$applications,
|
|
|
|
$self->_buildApplicationHash( $appkey, $apphash->{$appkey} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Display subcategories
|
2010-09-20 16:04:33 +02:00
|
|
|
foreach my $catkey ( sort keys %$cathash ) {
|
|
|
|
next if $catkey =~ /(type|options|catname)/;
|
2010-09-20 10:31:09 +02:00
|
|
|
if ( $cathash->{$catkey}->{type} eq "category" ) {
|
|
|
|
push @$categories,
|
|
|
|
$self->_buildCategoryHash( $catkey, $cathash->{$catkey},
|
|
|
|
$catlevel + 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-20 16:04:33 +02:00
|
|
|
my $categoryHash = {
|
|
|
|
category => 1,
|
|
|
|
catname => $catname,
|
|
|
|
catid => $catid,
|
|
|
|
catlevel => $catlevel
|
|
|
|
};
|
2010-09-20 12:39:23 +02:00
|
|
|
$categoryHash->{applications} = $applications if $applications;
|
2010-09-23 18:41:39 +02:00
|
|
|
$categoryHash->{categories} = $categories if $categories;
|
2010-09-20 10:31:09 +02:00
|
|
|
return $categoryHash;
|
|
|
|
}
|
|
|
|
|
2010-10-03 12:26:50 +02:00
|
|
|
## @method private hashref _buildApplicationHash(string appid, hashref apphash)
|
2010-09-20 10:31:09 +02:00
|
|
|
# Build hash for an application
|
|
|
|
# @param $appid Application ID
|
|
|
|
# @param $apphash Hash of application elements
|
|
|
|
# @return Application Hash
|
|
|
|
sub _buildApplicationHash {
|
|
|
|
my ( $self, $appid, $apphash ) = splice @_;
|
|
|
|
my $applications;
|
|
|
|
|
|
|
|
# Get application items
|
|
|
|
my $appname = $apphash->{options}->{name} || $appid;
|
|
|
|
my $appuri = $apphash->{options}->{uri} || "";
|
|
|
|
my $appdesc = $apphash->{options}->{description};
|
|
|
|
my $applogo = $apphash->{options}->{logo};
|
|
|
|
|
|
|
|
# Detect sub applications
|
|
|
|
my $subapphash;
|
2010-09-20 16:04:33 +02:00
|
|
|
foreach my $key ( sort keys %$apphash ) {
|
|
|
|
next if $key =~ /(type|options|catname)/;
|
2010-09-20 10:31:09 +02:00
|
|
|
if ( $apphash->{$key}->{type} eq "application" ) {
|
|
|
|
$subapphash->{$key} = $apphash->{$key};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Display sub applications
|
|
|
|
if ( scalar keys %$subapphash > 0 ) {
|
2010-09-20 16:04:33 +02:00
|
|
|
foreach my $appkey ( sort keys %$subapphash ) {
|
2010-09-20 10:31:09 +02:00
|
|
|
push @$applications,
|
|
|
|
$self->_buildApplicationHash( $appkey, $subapphash->{$appkey} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my $applicationHash = {
|
|
|
|
application => 1,
|
|
|
|
appname => $appname,
|
|
|
|
appuri => $appuri,
|
|
|
|
appdesc => $appdesc,
|
2010-09-20 15:07:28 +02:00
|
|
|
applogo => $applogo,
|
|
|
|
appid => $appid,
|
2010-09-20 10:31:09 +02:00
|
|
|
};
|
|
|
|
$applicationHash->{applications} = $applications if $applications;
|
|
|
|
return $applicationHash;
|
|
|
|
}
|
|
|
|
|
2008-12-28 09:36:52 +01:00
|
|
|
## @method string appslistMenu()
|
2008-12-26 20:18:23 +01:00
|
|
|
# Returns HTML code for application list menu.
|
2008-12-28 09:36:52 +01:00
|
|
|
# @return HTML string
|
2008-09-19 17:28:00 +02:00
|
|
|
sub appslistMenu {
|
|
|
|
my $self = shift;
|
|
|
|
|
2010-01-20 18:17:21 +01:00
|
|
|
# We no more use XML file for menu configuration
|
2010-09-16 17:10:00 +02:00
|
|
|
unless ( defined $self->{applicationList} ) {
|
|
|
|
$self->abort(
|
2010-02-11 09:44:57 +01:00
|
|
|
"XML menu configuration is deprecated",
|
|
|
|
"Please use lmMigrateConfFiles2ini to migrate your menu configuration"
|
2010-01-20 18:17:21 +01:00
|
|
|
);
|
2010-01-08 12:51:04 +01:00
|
|
|
}
|
|
|
|
|
2010-01-20 18:17:21 +01:00
|
|
|
# Use configuration to get menu parameters
|
2011-04-14 10:52:41 +02:00
|
|
|
my $applicationList = clone( $self->{applicationList} );
|
2010-01-15 23:01:04 +01:00
|
|
|
my $filteredList = $self->_filter($applicationList);
|
2011-03-03 23:34:09 +01:00
|
|
|
|
|
|
|
return $self->_displayConfCategory( "", $filteredList, $catlevel );
|
2008-09-19 17:28:00 +02:00
|
|
|
}
|
|
|
|
|
2008-12-28 09:36:52 +01:00
|
|
|
## @method string appslistDescription()
|
2008-12-26 20:18:23 +01:00
|
|
|
# Returns HTML code for application description.
|
2008-12-28 09:36:52 +01:00
|
|
|
# @return HTML string
|
2008-09-19 17:28:00 +02:00
|
|
|
sub appslistDescription {
|
|
|
|
my $self = shift;
|
|
|
|
|
2010-01-20 18:17:21 +01:00
|
|
|
# We no more use XML file for menu configuration
|
2010-09-16 17:10:00 +02:00
|
|
|
unless ( defined $self->{applicationList} ) {
|
|
|
|
$self->lmLog(
|
2010-01-20 18:17:21 +01:00
|
|
|
"XML menu configuration is deprecated. Please use lmMigrateConfFiles2ini to migrate your menu configuration",
|
|
|
|
'error'
|
|
|
|
);
|
|
|
|
return " ";
|
2010-01-08 12:51:04 +01:00
|
|
|
}
|
|
|
|
|
2010-01-20 18:17:21 +01:00
|
|
|
# Use configuration to get menu parameters
|
2011-04-14 10:52:41 +02:00
|
|
|
my $applicationList = clone( $self->{applicationList} );
|
2010-01-08 12:51:04 +01:00
|
|
|
return $self->_displayConfDescription( "", $applicationList );
|
2008-09-19 17:28:00 +02:00
|
|
|
}
|
|
|
|
|
2010-10-03 12:26:50 +02:00
|
|
|
## @method string _displayConfCategory(string catname, hashref cathash, int catlevel)
|
2010-01-08 12:51:04 +01:00
|
|
|
# Creates and returns HTML code for a category.
|
|
|
|
# @param catname Category name
|
|
|
|
# @param cathash Hash of category elements
|
|
|
|
# @param catlevel Category level
|
|
|
|
# @return HTML string
|
|
|
|
sub _displayConfCategory {
|
2010-01-31 09:25:05 +01:00
|
|
|
my ( $self, $catname, $cathash, $catlevel ) = splice @_;
|
2010-01-08 12:51:04 +01:00
|
|
|
my $html;
|
|
|
|
my $key;
|
|
|
|
|
|
|
|
# Init HTML list
|
|
|
|
$html .= "<ul class=\"category cat-level-$catlevel\">\n";
|
|
|
|
$html .= "<li class=\"catname\">\n";
|
|
|
|
$html .= "<span>$catname</span>\n" if $catname;
|
|
|
|
|
|
|
|
# Increase category level
|
|
|
|
$catlevel++;
|
|
|
|
|
|
|
|
# Extract applications from hash
|
|
|
|
my $apphash;
|
2010-01-15 23:01:04 +01:00
|
|
|
foreach $key ( keys %$cathash ) {
|
2010-09-20 16:04:33 +02:00
|
|
|
next if $key =~ /(type|options|catname)/;
|
2011-03-03 23:34:09 +01:00
|
|
|
if ( $cathash->{$key}->{type}
|
|
|
|
and $cathash->{$key}->{type} eq "application" )
|
|
|
|
{
|
2010-01-08 12:51:04 +01:00
|
|
|
$apphash->{$key} = $cathash->{$key};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# display applications first
|
2010-01-15 23:01:04 +01:00
|
|
|
if ( scalar keys %$apphash > 0 ) {
|
2010-01-08 12:51:04 +01:00
|
|
|
$html .= "<ul>";
|
2010-01-15 23:01:04 +01:00
|
|
|
foreach $key ( keys %$apphash ) {
|
|
|
|
$html .= $self->_displayConfApplication( $key, $apphash->{$key} );
|
2010-01-08 12:51:04 +01:00
|
|
|
}
|
|
|
|
$html .= "</ul>";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Display subcategories
|
2010-01-15 23:01:04 +01:00
|
|
|
foreach $key ( keys %$cathash ) {
|
2010-09-20 16:04:33 +02:00
|
|
|
next if $key =~ /(type|options|catname)/;
|
2011-03-03 23:34:09 +01:00
|
|
|
if ( $cathash->{$key}->{type}
|
|
|
|
and $cathash->{$key}->{type} eq "category" )
|
|
|
|
{
|
2010-01-15 23:01:04 +01:00
|
|
|
$html .=
|
|
|
|
$self->_displayConfCategory( $key, $cathash->{$key}, $catlevel );
|
2010-01-08 12:51:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Close HTML list
|
|
|
|
$html .= "</li>\n";
|
|
|
|
$html .= "</ul>\n";
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
2010-10-03 12:26:50 +02:00
|
|
|
## @method private string _displayConfApplication(string appid, hashref apphash)
|
2010-01-08 12:51:04 +01:00
|
|
|
# Creates HTML code for an application.
|
|
|
|
# @param $appid Application ID
|
|
|
|
# @param $apphash Hash of application elements
|
|
|
|
# @return HTML string
|
|
|
|
sub _displayConfApplication {
|
|
|
|
my $self = shift;
|
2010-01-15 23:01:04 +01:00
|
|
|
my ( $appid, $apphash ) = @_;
|
2010-01-08 12:51:04 +01:00
|
|
|
my $html;
|
|
|
|
my $key;
|
|
|
|
|
|
|
|
# Get application items
|
|
|
|
my $appname = $apphash->{options}->{name} || $appid;
|
2010-01-15 23:01:04 +01:00
|
|
|
my $appuri = $apphash->{options}->{uri} || "";
|
2010-01-08 12:51:04 +01:00
|
|
|
|
|
|
|
# Display application
|
|
|
|
$html .=
|
|
|
|
"<li title=\"$appid\" class=\"appname $appid\"><span>"
|
|
|
|
. ( $appuri ? "<a href=\"$appuri\">$appname</a>" : "<a>$appname</a>" )
|
|
|
|
. "</span>\n";
|
|
|
|
|
|
|
|
# Detect sub applications
|
|
|
|
my $subapphash;
|
2010-01-15 23:01:04 +01:00
|
|
|
foreach $key ( keys %$apphash ) {
|
2010-09-20 16:04:33 +02:00
|
|
|
next if $key =~ /(type|options|catname)/;
|
2010-01-15 23:01:04 +01:00
|
|
|
if ( $apphash->{$key}->{type} eq "application" ) {
|
2010-01-08 12:51:04 +01:00
|
|
|
$subapphash->{$key} = $apphash->{$key};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Display sub applications
|
2010-01-15 23:01:04 +01:00
|
|
|
if ( scalar keys %$subapphash > 0 ) {
|
2010-01-08 12:51:04 +01:00
|
|
|
$html .= "<ul>";
|
2010-01-15 23:01:04 +01:00
|
|
|
foreach $key ( keys %$subapphash ) {
|
|
|
|
$html .=
|
|
|
|
$self->_displayConfApplication( $key, $subapphash->{$key} );
|
2010-01-08 12:51:04 +01:00
|
|
|
}
|
|
|
|
$html .= "</ul>";
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= "</li>";
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
2010-10-03 12:26:50 +02:00
|
|
|
## @method private string _displayConfDescription(string appid, hashref apphash)
|
2010-01-08 12:51:04 +01:00
|
|
|
# Create HTML code for application description.
|
|
|
|
# @param $appid Application ID
|
|
|
|
# @param $apphash Hash
|
2010-01-20 18:17:21 +01:00
|
|
|
# @return HTML string
|
2010-01-08 12:51:04 +01:00
|
|
|
sub _displayConfDescription {
|
|
|
|
my $self = shift;
|
2010-01-15 23:01:04 +01:00
|
|
|
my ( $appid, $apphash ) = @_;
|
2011-03-03 23:34:09 +01:00
|
|
|
my $html = "";
|
2010-01-08 12:51:04 +01:00
|
|
|
my $key;
|
|
|
|
|
|
|
|
if ( defined $apphash->{type} and $apphash->{type} eq "application" ) {
|
2010-01-15 23:01:04 +01:00
|
|
|
|
2010-01-08 12:51:04 +01:00
|
|
|
# Get application items
|
|
|
|
my $appname = $apphash->{options}->{name} || $appid;
|
|
|
|
my $appuri = $apphash->{options}->{uri} || "";
|
|
|
|
my $appdesc = $apphash->{options}->{description};
|
|
|
|
my $applogofile = $apphash->{options}->{logo};
|
2010-01-25 15:32:22 +01:00
|
|
|
my $applogo = $self->{apps}->{imgpath} . $applogofile
|
|
|
|
if $applogofile;
|
2010-01-08 12:51:04 +01:00
|
|
|
|
|
|
|
# Display application description
|
|
|
|
$html .= "<div id=\"$appid\" class=\"appsdesc\">\n";
|
|
|
|
$html .=
|
|
|
|
"<a href=\"$appuri\"><img src=\"$applogo\" alt=\"$appid logo\" /></a>\n"
|
|
|
|
if $applogofile;
|
|
|
|
$html .= "<p class=\"appname\">$appname</p>\n" if defined $appname;
|
|
|
|
$html .= "<p class=\"appdesc\">$appdesc</p>\n" if defined $appdesc;
|
|
|
|
$html .= "</div>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Sublevels
|
2010-01-15 23:01:04 +01:00
|
|
|
foreach $key ( keys %$apphash ) {
|
2010-09-20 16:04:33 +02:00
|
|
|
next if $key =~ /(type|options|catname)/;
|
2010-01-15 23:01:04 +01:00
|
|
|
$html .= $self->_displayConfDescription( $key, $apphash->{$key} );
|
2010-01-08 12:51:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
2009-08-20 16:19:40 +02:00
|
|
|
|
2010-10-03 12:26:50 +02:00
|
|
|
## @method private string _filter(hashref apphash)
|
2010-01-20 18:17:21 +01:00
|
|
|
# Duplicate hash reference
|
|
|
|
# Remove unauthorized menu elements
|
|
|
|
# Hide empty categories
|
|
|
|
# @param $apphash Menu elements
|
|
|
|
# @return filtered hash
|
2010-01-08 12:51:04 +01:00
|
|
|
sub _filter {
|
2010-01-31 09:25:05 +01:00
|
|
|
my ( $self, $apphash ) = splice @_;
|
2010-01-08 12:51:04 +01:00
|
|
|
my $filteredHash;
|
|
|
|
my $key;
|
|
|
|
|
2010-01-20 18:17:21 +01:00
|
|
|
# Copy hash reference into a new hash
|
2010-01-15 23:01:04 +01:00
|
|
|
foreach $key ( keys %$apphash ) {
|
2010-01-08 12:51:04 +01:00
|
|
|
$filteredHash->{$key} = $apphash->{$key};
|
|
|
|
}
|
|
|
|
|
2010-01-20 18:17:21 +01:00
|
|
|
# Filter hash
|
|
|
|
$self->_filterHash($filteredHash);
|
|
|
|
|
2010-01-08 12:51:04 +01:00
|
|
|
# Hide empty categories
|
2010-01-20 18:17:21 +01:00
|
|
|
$self->_isCategoryEmpty($filteredHash);
|
|
|
|
|
2010-01-08 12:51:04 +01:00
|
|
|
return $filteredHash;
|
|
|
|
}
|
|
|
|
|
2010-10-03 12:26:50 +02:00
|
|
|
## @method private string _filterHash(hashref apphash)
|
2010-01-20 18:17:21 +01:00
|
|
|
# Remove unauthorized menu elements
|
|
|
|
# @param $apphash Menu elements
|
|
|
|
# @return filtered hash
|
2010-01-08 12:51:04 +01:00
|
|
|
sub _filterHash {
|
|
|
|
my $self = shift;
|
2010-01-20 18:17:21 +01:00
|
|
|
my ($apphash) = @_;
|
2010-01-08 12:51:04 +01:00
|
|
|
my $key;
|
2010-01-20 18:17:21 +01:00
|
|
|
my $appkey;
|
2010-01-08 12:51:04 +01:00
|
|
|
|
|
|
|
foreach $key ( keys %$apphash ) {
|
2010-09-20 16:04:33 +02:00
|
|
|
next if $key =~ /(type|options|catname)/;
|
2011-03-03 23:34:09 +01:00
|
|
|
if ( $apphash->{$key}->{type}
|
|
|
|
and $apphash->{$key}->{type} eq "category" )
|
|
|
|
{
|
2010-01-15 23:01:04 +01:00
|
|
|
|
2010-01-08 12:51:04 +01:00
|
|
|
# Filter the category
|
2010-01-20 18:17:21 +01:00
|
|
|
$self->_filterHash( $apphash->{$key} );
|
2010-01-08 12:51:04 +01:00
|
|
|
}
|
2011-03-03 23:34:09 +01:00
|
|
|
if ( $apphash->{$key}->{type}
|
|
|
|
and $apphash->{$key}->{type} eq "application" )
|
|
|
|
{
|
2010-01-15 23:01:04 +01:00
|
|
|
|
2010-01-20 18:17:21 +01:00
|
|
|
# Find sub applications and filter them
|
|
|
|
foreach $appkey ( keys %{ $apphash->{$key} } ) {
|
2010-09-20 16:04:33 +02:00
|
|
|
next if $appkey =~ /(type|options|catname)/;
|
2010-01-20 18:17:21 +01:00
|
|
|
|
|
|
|
# We have sub elements, so we filter them
|
|
|
|
$self->_filterHash( $apphash->{$key} );
|
|
|
|
}
|
|
|
|
|
2010-01-08 12:51:04 +01:00
|
|
|
# Check rights
|
2010-01-25 15:32:22 +01:00
|
|
|
my $appdisplay = $apphash->{$key}->{options}->{display}
|
|
|
|
|| "auto";
|
2010-01-15 23:01:04 +01:00
|
|
|
my $appuri = $apphash->{$key}->{options}->{uri};
|
2010-01-08 12:51:04 +01:00
|
|
|
|
2010-09-22 16:26:28 +02:00
|
|
|
# Remove if display is "no" or "off"
|
|
|
|
delete $apphash->{$key} and next if ( $appdisplay =~ /^(no|off)$/ );
|
2010-01-08 12:51:04 +01:00
|
|
|
|
2010-09-22 16:26:28 +02:00
|
|
|
# Keep node if display is "yes" or "on"
|
|
|
|
next if ( $appdisplay =~ /^(yes|on)$/ );
|
2010-01-08 12:51:04 +01:00
|
|
|
|
|
|
|
# Check grant function if display is "auto" (this is the default)
|
|
|
|
delete $apphash->{$key} unless ( $self->_grant($appuri) );
|
2010-01-15 23:01:04 +01:00
|
|
|
next;
|
2010-01-08 12:51:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-10-03 12:26:50 +02:00
|
|
|
## @method private void _isCategoryEmpty(hashref apphash)
|
2010-01-20 18:17:21 +01:00
|
|
|
# Check if a category is empty
|
|
|
|
# @param $apphash Menu elements
|
|
|
|
# @return boolean
|
|
|
|
sub _isCategoryEmpty {
|
|
|
|
my $self = shift;
|
|
|
|
my ($apphash) = @_;
|
|
|
|
my $key;
|
2008-09-26 09:36:30 +02:00
|
|
|
|
2010-01-20 18:17:21 +01:00
|
|
|
# Test sub categories
|
|
|
|
foreach $key ( keys %$apphash ) {
|
2010-09-20 16:04:33 +02:00
|
|
|
next if $key =~ /(type|options|catname)/;
|
2011-03-03 23:34:09 +01:00
|
|
|
if ( $apphash->{$key}->{type}
|
|
|
|
and $apphash->{$key}->{type} eq "category" )
|
|
|
|
{
|
2010-01-20 18:17:21 +01:00
|
|
|
delete $apphash->{$key}
|
|
|
|
if $self->_isCategoryEmpty( $apphash->{$key} );
|
2009-08-20 16:19:40 +02:00
|
|
|
}
|
2008-09-18 10:34:17 +02:00
|
|
|
}
|
|
|
|
|
2010-01-20 18:17:21 +01:00
|
|
|
# Test this category
|
2010-01-22 12:25:37 +01:00
|
|
|
if ( $apphash->{type} and $apphash->{type} eq "category" ) {
|
2008-09-18 10:34:17 +02:00
|
|
|
|
2010-01-20 18:17:21 +01:00
|
|
|
# Temporary store 'options'
|
|
|
|
my $tmp_options = $apphash->{options};
|
2011-02-10 11:29:08 +01:00
|
|
|
my $tmp_catname = $apphash->{catname};
|
2008-09-18 10:34:17 +02:00
|
|
|
|
2010-01-20 18:17:21 +01:00
|
|
|
delete $apphash->{type};
|
|
|
|
delete $apphash->{options};
|
2011-02-10 11:29:08 +01:00
|
|
|
delete $apphash->{catname};
|
2010-01-20 18:17:21 +01:00
|
|
|
|
|
|
|
if ( scalar( keys %$apphash ) ) {
|
2008-09-18 10:34:17 +02:00
|
|
|
|
2010-01-20 18:17:21 +01:00
|
|
|
# There are sub categories or sub applications
|
|
|
|
# Restore type and options
|
|
|
|
$apphash->{type} = "category";
|
|
|
|
$apphash->{options} = $tmp_options;
|
2011-02-10 11:29:08 +01:00
|
|
|
$apphash->{catname} = $tmp_catname;
|
2008-09-18 10:34:17 +02:00
|
|
|
|
2010-01-20 18:17:21 +01:00
|
|
|
# Return false
|
|
|
|
return 0;
|
2010-03-01 21:32:28 +01:00
|
|
|
}
|
2010-01-20 18:17:21 +01:00
|
|
|
else {
|
2008-09-18 10:34:17 +02:00
|
|
|
|
2010-01-20 18:17:21 +01:00
|
|
|
# Return true
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2008-09-18 10:34:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
|
|
|
|
__END__
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2010-01-03 09:09:59 +01:00
|
|
|
=encoding utf8
|
|
|
|
|
2010-09-16 17:10:00 +02:00
|
|
|
Lemonldap::NG::Portal::Menu - Portal menu functions
|
2008-09-18 10:34:17 +02:00
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
2010-09-16 17:10:00 +02:00
|
|
|
use Lemonldap::NG::Portal::Simple;
|
|
|
|
my $portal = Lemonldap::NG::Portal::Simple->new(
|
2008-09-18 10:34:17 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2010-09-16 17:10:00 +02:00
|
|
|
# Init portal menu
|
|
|
|
$portal->menuInit();
|
2008-09-18 10:34:17 +02:00
|
|
|
|
|
|
|
|
2010-09-16 17:10:00 +02:00
|
|
|
=head1 DESCRIPTION
|
2008-09-18 10:34:17 +02:00
|
|
|
|
2010-09-16 17:10:00 +02:00
|
|
|
Lemonldap::NG::Portal::Menu is used to build menu.
|
2008-09-18 10:34:17 +02:00
|
|
|
|
|
|
|
=head1 SEE ALSO
|
|
|
|
|
2010-10-26 08:08:16 +02:00
|
|
|
L<Lemonldap::NG::Portal>, L<http://lemonldap-ng.org/>
|
2008-09-18 10:34:17 +02:00
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
2008-09-19 17:28:00 +02:00
|
|
|
Clement OUDOT E<lt>clement@oodo.netE<gt> E<lt>coudot@linagora.comE<gt>
|
2008-09-18 10:34:17 +02:00
|
|
|
|
|
|
|
=head1 BUG REPORT
|
|
|
|
|
|
|
|
Use OW2 system to report bug or ask for features:
|
2010-10-26 08:08:16 +02:00
|
|
|
L<http://jira.ow2.org>
|
2008-09-18 10:34:17 +02:00
|
|
|
|
|
|
|
=head1 DOWNLOAD
|
|
|
|
|
|
|
|
Lemonldap::NG is available at
|
|
|
|
L<http://forge.objectweb.org/project/showfiles.php?group_id=274>
|
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE
|
|
|
|
|
2010-10-23 10:35:38 +02:00
|
|
|
Copyright (C) 2005, 2007, 2010 by Clement OUDOT E<lt>clement@oodo.netE<gt>
|
2009-01-28 18:37:10 +01:00
|
|
|
E<lt>coudot@linagora.comE<gt>
|
2008-09-18 10:34:17 +02:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify
|
2010-10-24 09:25:44 +02:00
|
|
|
it under the same terms as Perl itself, either Perl version 5.10.0 or,
|
2008-09-18 10:34:17 +02:00
|
|
|
at your option, any later version of Perl 5 you may have available.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|