X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FMenu.pm;h=06ea6ee43ed44c04b21459694f7e7ebce836b05b;hb=99bbf349b825fc48cdb71288e0979ab687770227;hp=4b470cabc56a0e0df147129fecb4f926ea320e0e;hpb=473686a9a1988e577084eed734e307e3aa97075e;p=kivitendo-erp.git
diff --git a/SL/Menu.pm b/SL/Menu.pm
index 4b470cabc..06ea6ee43 100644
--- a/SL/Menu.pm
+++ b/SL/Menu.pm
@@ -37,120 +37,39 @@ package Menu;
use SL::Auth;
use SL::Inifile;
-sub new {
- $main::lxdebug->enter_sub();
-
- my ($type, $menufile) = @_;
-
- my $self = {};
- my $inifile = Inifile->new($menufile);
-
- map { $self->{$_} = $inifile->{$_} } keys %{ $inifile };
-
- bless $self, $type;
-
- $self->set_access();
-
- $main::lxdebug->leave_sub();
-
- return $self;
-}
+use strict;
-sub menuitem {
+sub new {
$main::lxdebug->enter_sub();
- my ($self, $myconfig, $form, $item) = @_;
-
- my $module = $form->{script};
- my $action = "section_menu";
- my $target = "";
-
- if ($self->{$item}{module}) {
- $module = $self->{$item}{module};
- }
- if ($self->{$item}{action}) {
- $action = $self->{$item}{action};
- }
- if ($self->{$item}{target}) {
- $target = $self->{$item}{target};
- }
-
- my $level = $form->escape($item);
+ my ($type, @menufiles) = @_;
+ my $self = bless {}, $type;
- my $str = qq|new($menufile);
- if ($self->{$item}{href}) {
- $str = qq|{$item}{href}|;
- @vars = qw(module target href);
+ push @order, @{ delete($inifile->{ORDER}) || [] };
+ $self->{$_} = $inifile->{$_} for keys %{ $inifile };
}
- map { delete $self->{$item}{$_} } @vars;
+ $self->{ORDER} = \@order;
- # add other params
- foreach my $key (keys %{ $self->{$item} }) {
- $str .= "&" . $form->escape($key, 1) . "=";
- ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
- $value = $myconfig->{$value} . "/$conf" if ($conf);
- $str .= $form->escape($value, 1);
- }
-
- if ($target) {
- $str .= qq| target=$target|;
- }
-
- $str .= ">";
+ $self->set_access();
$main::lxdebug->leave_sub();
- return $str;
-}
-
-sub menuitem_js {
- my ($self, $myconfig, $form, $item) = @_;
-
- my $module = $form->{script};
- my $action = "section_menu";
-
- #if ($self->{$item}{module}) {
- $module = $self->{$item}{module};
-
- #}
- if ($self->{$item}{action}) {
- $action = $self->{$item}{action};
- }
-
- my $level = $form->escape($item);
- my $str =
- qq|$module?action=$action&level=$level&login=$form->{login}&password=$form->{password}|;
- my @vars = qw(module action target href);
-
- if ($self->{$item}{href}) {
- $str = qq|$self->{$item}{href}|;
- @vars = qw(module target href);
- }
-
- map { delete $self->{$item}{$_} } @vars;
-
- # add other params
- foreach my $key (keys %{ $self->{$item} }) {
- $str .= "&" . $form->escape($key, 1) . "=";
- ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
- $value = $myconfig->{$value} . "/$conf" if ($conf);
- $str .= $form->escape($value, 1);
- }
-
- $str .= " ";
-
+ return $self;
}
sub menuitem_new {
- $main::lxdebug->enter_sub();
+ $main::lxdebug->enter_sub(LXDebug::DEBUG2());
my ($self, $name, $item) = @_;
- my $form = $main::form;
+ my $form = $main::form;
+ my $myconfig = \%main::myconfig;
my $module = $self->{$name}->{module} || $form->{script};
my $action = $self->{$name}->{action};
@@ -170,123 +89,7 @@ sub menuitem_new {
$item->{href} .= "&" . $form->escape($key) . "=" . $form->escape($value);
}
- $main::lxdebug->leave_sub();
-}
-
-sub menuitem_v3 {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form, $item, $other) = @_;
-
- my $module = $form->{script};
- my $action = "section_menu";
- my $target = "";
-
- if ($self->{$item}{module}) {
- $module = $self->{$item}{module};
- }
- if ($self->{$item}{action}) {
- $action = $self->{$item}{action};
- }
- if ($self->{$item}{target}) {
- $target = $self->{$item}{target};
- }
-
- my $level = $form->escape($item);
-
- my $str = qq|escape($key, 1) . "=";
- ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
- $value = $myconfig->{$value} . "/$conf" if ($conf);
- $str .= $form->escape($value, 1);
- }
-
- $str .= '"';
-
- if ($target) {
- $str .= qq| target="| . $form->quote($target) . qq|"|;
- }
-
- if ($other) {
- foreach my $key (keys(%{$other})) {
- $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
- }
- }
-
- $str .= ">";
-
- $main::lxdebug->leave_sub();
-
- return $str;
-}
-
-sub menuitem_XML {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form, $item, $other) = @_;
-
- my $module = $form->{script};
- my $action = "section_menu";
- my $target = "";
-
- if ($self->{$item}{module}) {
- $module = $self->{$item}{module};
- }
- if ($self->{$item}{action}) {
- $action = $self->{$item}{action};
- }
- if ($self->{$item}{target}) {
- $target = $self->{$item}{target};
- }
-
- my $level = $form->escape($item);
-
- my $str = qq| link="$module?action=| . $form->escape($action) .
- qq|&level=| . $form->escape($level);
-
- my @vars = qw(module action target href);
-
- if ($self->{$item}{href}) {
- $str = qq| link=$self->{$item}{href}|;
- @vars = qw(module target href);
- }
-
- map { delete $self->{$item}{$_} } @vars;
-
- # add other params
- foreach my $key (keys %{ $self->{$item} }) {
- $str .= "&" . $form->escape($key, 1) . "=";
- ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
- $value = $myconfig->{$value} . "/$conf" if ($conf);
- $str .= $form->escape($value, 1);
- }
-
- $str .= '"';
-
-
-
- if ($other) {
- foreach my $key (keys(%{$other})) {
- $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
- }
- }
-
-
- $main::lxdebug->leave_sub();
-
- return $str;
+ $main::lxdebug->leave_sub(LXDebug::DEBUG2());
}
sub access_control {
@@ -296,7 +99,7 @@ sub access_control {
my @menu = ();
- if ($menulevel eq "") {
+ if (!$menulevel) {
@menu = grep { !/--/ } @{ $self->{ORDER} };
} else {
@menu = grep { /^${menulevel}--/ } @{ $self->{ORDER} };
@@ -312,6 +115,10 @@ sub parse_access_string {
my $key = shift;
my $access = shift;
+ my $form = $main::form;
+ my $auth = $main::auth;
+ my $myconfig = \%main::myconfig;
+
my @stack;
my $cur_ary = [];
@@ -332,7 +139,7 @@ sub parse_access_string {
} elsif ($token eq ")") {
pop @stack;
if (!@stack) {
- $main::form->error("Error in menu.ini for entry ${key}: missing '('");
+ $form->error("Error in menu.ini for entry ${key}: missing '('");
}
$cur_ary = $stack[-1];
@@ -340,16 +147,16 @@ sub parse_access_string {
push @{$cur_ary}, $token;
} else {
- push @{$cur_ary}, $main::auth->check_right($main::form->{login}, $token, 1);
+ push @{$cur_ary}, $auth->check_right($form->{login}, $token, 1);
}
}
if ($access) {
- $main::form->error("Error in menu.ini for entry ${name}: unrecognized token at the start of '$access'\n");
+ $form->error("Error in menu.ini for entry ${key}: unrecognized token at the start of '$access'\n");
}
if (1 < scalar @stack) {
- $main::form->error("Error in menu.ini for entry ${name}: Missing ')'\n");
+ $main::form->error("Error in menu.ini for entry ${key}: Missing ')'\n");
}
return SL::Auth::evaluate_rights_ary($stack[0]);
@@ -394,7 +201,10 @@ sub set_access {
$self->{ORDER} = [ grep { $self->{$_}->{VISIBLE} } @{ $self->{ORDER} } ];
+ { no strict 'refs';
+ # ToDO: fix this. nuke and pave algorithm without type checking screams for problems.
map { delete @{$self->{$_}}{qw(GRANTED IS_MENU NUM_VISIBLE_CHILDREN VISIBLE ACCESS)} if ($_ ne 'ORDER') } keys %{ $self };
+ }
}
sub dump_visible {