1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 2 of the License, or
20 # (at your option) any later version.
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #=====================================================================
31 # routines for menu items
33 #=====================================================================
42 our @ISA = qw(Inifile);
46 $main::lxdebug->enter_sub();
48 my ($package, @menufiles) = @_;
50 my $self = $package->SUPER::new($menufiles[0]);
52 for (@menufiles[1..$#menufiles]) {
53 my $inifile = Inifile->new($_);
54 push @{ $self->{ORDER} }, @{ delete $inifile->{ORDER} };
55 $self->{$_} = $inifile->{$_} for keys %$inifile;
60 $main::lxdebug->leave_sub();
66 $main::lxdebug->enter_sub(LXDebug::DEBUG2());
68 my ($self, $name, $item) = @_;
70 my $module = $self->{$name}->{module} || $::form->{script};
71 my $action = $self->{$name}->{action};
73 $item->{target} = $self->{$name}->{target} || "main_window";
74 $item->{href} = $self->{$name}->{href} || "${module}?action=" . $::form->escape($action);
76 my @vars = qw(module target href);
77 push @vars, 'action' unless ($self->{$name}->{href});
79 map { delete $self->{$name}{$_} } @vars;
82 foreach my $key (keys %{ $self->{$name} }) {
83 my ($value, $conf) = split(m/=/, $self->{$name}->{$key}, 2);
84 $value = $::myconfig->{$value} . "/$conf" if ($conf);
85 $item->{href} .= "&" . $::form->escape($key) . "=" . $::form->escape($value);
88 $main::lxdebug->leave_sub(LXDebug::DEBUG2());
92 $main::lxdebug->enter_sub(2);
94 my ($self, $myconfig, $menulevel) = @_;
99 @menu = grep { !/--/ } @{ $self->{ORDER} };
101 @menu = grep { /^${menulevel}--/ } @{ $self->{ORDER} };
104 $main::lxdebug->leave_sub(2);
109 sub parse_access_string {
114 my $form = $main::form;
115 my $auth = $main::auth;
116 my $myconfig = \%main::myconfig;
121 push @stack, $cur_ary;
123 while ($access =~ m/^([a-z_]+|\||\&|\(|\)|\s+)/) {
125 substr($access, 0, length($1)) = "";
127 next if ($token =~ /\s/);
130 my $new_cur_ary = [];
131 push @stack, $new_cur_ary;
132 push @{$cur_ary}, $new_cur_ary;
133 $cur_ary = $new_cur_ary;
135 } elsif ($token eq ")") {
138 $form->error("Error in menu.ini for entry ${key}: missing '('");
140 $cur_ary = $stack[-1];
142 } elsif (($token eq "|") || ($token eq "&")) {
143 push @{$cur_ary}, $token;
146 push @{$cur_ary}, $auth->check_right($::myconfig{login}, $token, 1);
151 $form->error("Error in menu.ini for entry ${key}: unrecognized token at the start of '$access'\n");
154 if (1 < scalar @stack) {
155 $main::form->error("Error in menu.ini for entry ${key}: Missing ')'\n");
158 return SL::Auth::evaluate_rights_ary($stack[0]);
161 sub parse_instance_conf_string {
162 my ($self, $setting) = @_;
163 return $::instance_conf->data->{$setting};
171 foreach $key (@{ $self->{ORDER} }) {
172 my $entry = $self->{$key};
174 $entry->{GRANTED} = $entry->{ACCESS} ? $self->parse_access_string($key, $entry->{ACCESS}) : 1;
175 $entry->{GRANTED} &&= $self->parse_instance_conf_string($entry->{INSTANCE_CONF}) if $entry->{INSTANCE_CONF};
176 $entry->{IS_MENU} = $entry->{submenu} || ($key !~ m/--/);
177 $entry->{NUM_VISIBLE_CHILDREN} = 0;
181 substr($parent, rindex($parent, '--')) = '';
182 $entry->{GRANTED} &&= $self->{$parent}->{GRANTED};
185 $entry->{VISIBLE} = $entry->{GRANTED};
188 foreach $key (reverse @{ $self->{ORDER} }) {
189 my $entry = $self->{$key};
191 if ($entry->{IS_MENU}) {
192 $entry->{VISIBLE} &&= $entry->{NUM_VISIBLE_CHILDREN} > 0;
195 next if (($key !~ m/--/) || !$entry->{VISIBLE});
198 substr($parent, rindex($parent, '--')) = '';
199 $self->{$parent}->{NUM_VISIBLE_CHILDREN}++;
202 # $self->dump_visible();
204 $self->{ORDER} = [ grep { $self->{$_}->{VISIBLE} } @{ $self->{ORDER} } ];
207 # ToDO: fix this. nuke and pave algorithm without type checking screams for problems.
208 map { delete @{$self->{$_}}{qw(GRANTED IS_MENU NUM_VISIBLE_CHILDREN VISIBLE ACCESS)} if ($_ ne 'ORDER') } keys %{ $self };
214 foreach my $key (@{ $self->{ORDER} }) {
215 my $entry = $self->{$key};
216 $main::lxdebug->message(0, "$entry->{GRANTED} $entry->{VISIBLE} $entry->{NUM_VISIBLE_CHILDREN} $key");