## @file # Notification explorer ## @class # Notification explorer. # Synopsis: # * build a new Lemonldap::NG::Manager::Notifications object # * insert tree() result in HTML # # tree() loads on of the tree methods. # new() manage ajax requests (inserted in HTML tree) package Lemonldap::NG::Manager::Notifications; use strict; use Lemonldap::NG::Handler::CGI qw(:globalStorage :locationRules); use Lemonldap::NG::Common::Notification; use Lemonldap::NG::Common::Conf; #link protected conf Configuration use Lemonldap::NG::Common::Conf::Constants; #inherits require Lemonldap::NG::Manager::_i18n; #inherits use utf8; our $whatToTrace; *whatToTrace = \$Lemonldap::NG::Handler::_CGI::whatToTrace; our $VERSION = '2.00'; our @ISA = qw( Lemonldap::NG::Handler::CGI Lemonldap::NG::Manager::_i18n ); ## @cmethod Lemonldap::NG::Manager::Notifications new(hashRef args) # Constructor. # @param $args Arguments for Lemonldap::NG::Handler::CGI::new() # @return New Lemonldap::NG::Manager::Notifications object sub new { my ( $class, $args ) = @_; # Output UTF-8 binmode( STDOUT, ':utf8' ); # Try to get configuration values from global configuration my $conf = Lemonldap::NG::Common::Conf->new( $args->{configStorage} ) or Lemonldap::NG::Handler::CGI->abort( 'Unable to get configuration', $Lemonldap::NG::Common::Conf::msg ); # Load global configuration if ( my $globalconf = $conf->getConf() ) { $args->{$_} ||= $globalconf->{$_} foreach ( qw/portal notification notificationStorage notificationStorageOptions/ ); } # Configuration from MANAGER section if ( my $localconf = $conf->getLocalConf(MANAGERSECTION) ) { $args->{$_} ||= $localconf->{$_} foreach ( keys %$localconf ); } my $self = $class->SUPER::new($args) or $class->abort( 'Unable to start ' . __PACKAGE__, 'See Apache logs for more' ); # Local args prepends global args $self->{$_} = $args->{$_} foreach ( keys %$args ); # Load default skin if no other specified $self->{managerSkin} ||= 'default'; # Verify if Notification is enabled $class->abort("Notifications not enabled, please update configuration") unless $self->{notification}; # Now try to load Notification module my $tmp; # Use configuration options if ( $self->{notificationStorage} ) { $tmp->{type} = $self->{notificationStorage}; foreach ( keys %{ $self->{notificationStorageOptions} } ) { $tmp->{$_} = $self->{notificationStorageOptions}->{$_}; } } # Else use the configuration backend else { (%$tmp) = (%$conf); $class->abort( "notificationStorage not defined", "This parameter is required to use notification system" ) unless ( ref($tmp) ); # Get the type $tmp->{type} =~ s/.*:://; $tmp->{type} =~ s/(CBDI|RDBI)/DBI/; # CDBI/RDBI are DBI # If type not File or DBI, abort $class->abort("Only File, DBI or LDAP supported for Notifications") unless $tmp->{type} =~ /^(File|DBI|LDAP)$/; # Force table name $tmp->{table} = 'notifications'; } $tmp->{p} = $self; $self->{notifObject} = Lemonldap::NG::Common::Notification->new($tmp); $class->abort($Lemonldap::NG::Common::Notification::msg) unless ( $self->{notifObject} ); # Multi values separator $self->{multiValuesSeparator} ||= '; '; # Now we're ready to display sessions. Choose display type foreach my $k ( $self->param() ) { # Case ajax request: execute corresponding sub and quit if ( grep { $_ eq $k } qw(delete purge notification notificationDone uid uidDone letter letterDone) ) { print $self->header( -type => 'text/html;charset=utf-8' ); print $self->$k( $self->param($k) ); $self->quit(); } # Case ajax request with complex date type (JSON) if ( $k =~ /^(\w+)\[\w+\]$/ ) { print $self->header( -type => 'text/html;charset=utf-8' ); print $self->$1(); $self->quit(); } # Case else: store tree type choosen to use it later in tree() elsif ( grep { $_ eq $k } qw(listDone) ) { $self->{_tree} = $k; last; } } # default display : list by uid $self->{_tree} ||= 'list'; return $self; } ## @method string tree() # Launch required tree builder. It can be one of : # * listDone() # * list() (default) # @return string XML tree sub tree { my $self = shift; my $sub = $self->{_tree}; $self->lmLog( "Building chosen tree: $sub", 'debug' ); my ( $r, $legend ) = $self->$sub( $self->param($sub) ); return qq{
' . $self->translate('internalReference') . ': ' . $id . '
'; # Purge button $res .= '