+ } else {
+ push @{$cur_ary}, $auth->check_right($form->{login}, $token, 1);
+ }
+ }
+
+ if ($access) {
+ $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 ${key}: Missing ')'\n");
+ }
+
+ return SL::Auth::evaluate_rights_ary($stack[0]);
+}
+
+sub set_access {
+ my $self = shift;
+
+ my $key;
+
+ foreach $key (@{ $self->{ORDER} }) {
+ my $entry = $self->{$key};
+
+ $entry->{GRANTED} = $entry->{ACCESS} ? $self->parse_access_string($key, $entry->{ACCESS}) : 1;
+ $entry->{IS_MENU} = $entry->{submenu} || ($key !~ m/--/);
+ $entry->{NUM_VISIBLE_CHILDREN} = 0;
+
+ if ($key =~ m/--/) {
+ my $parent = $key;
+ substr($parent, rindex($parent, '--')) = '';
+ $entry->{GRANTED} &&= $self->{$parent}->{GRANTED};
+ }
+
+ $entry->{VISIBLE} = $entry->{GRANTED};
+ }
+
+ foreach $key (reverse @{ $self->{ORDER} }) {
+ my $entry = $self->{$key};
+
+ if ($entry->{IS_MENU}) {
+ $entry->{VISIBLE} &&= $entry->{NUM_VISIBLE_CHILDREN} > 0;
+ }
+
+ next if (($key !~ m/--/) || !$entry->{VISIBLE});
+
+ my $parent = $key;
+ substr($parent, rindex($parent, '--')) = '';
+ $self->{$parent}->{NUM_VISIBLE_CHILDREN}++;
+ }
+
+# $self->dump_visible();
+
+ $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 {
+ my $self = shift;
+ foreach my $key (@{ $self->{ORDER} }) {
+ my $entry = $self->{$key};
+ $main::lxdebug->message(0, "$entry->{GRANTED} $entry->{VISIBLE} $entry->{NUM_VISIBLE_CHILDREN} $key");
+ }