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 #=====================================================================
43 $main::lxdebug->enter_sub();
45 my ($type, @menufiles) = @_;
46 my $self = bless {}, $type;
50 foreach my $menufile (grep { -f } @menufiles) {
51 my $inifile = Inifile->new($menufile);
53 push @order, @{ delete($inifile->{ORDER}) || [] };
54 $self->{$_} = $inifile->{$_} for keys %{ $inifile };
57 $self->{ORDER} = \@order;
61 $main::lxdebug->leave_sub();
67 $main::lxdebug->enter_sub(LXDebug::DEBUG2());
69 my ($self, $name, $item) = @_;
71 my $form = $main::form;
72 my $myconfig = \%main::myconfig;
74 my $module = $self->{$name}->{module} || $form->{script};
75 my $action = $self->{$name}->{action};
77 $item->{target} = $self->{$name}->{target} || "main_window";
78 $item->{href} = $self->{$name}->{href} || "${module}?action=" . $form->escape($action);
80 my @vars = qw(module target href);
81 push @vars, 'action' unless ($self->{$name}->{href});
83 map { delete $self->{$name}{$_} } @vars;
86 foreach my $key (keys %{ $self->{$name} }) {
87 my ($value, $conf) = split(m/=/, $self->{$name}->{$key}, 2);
88 $value = $myconfig->{$value} . "/$conf" if ($conf);
89 $item->{href} .= "&" . $form->escape($key) . "=" . $form->escape($value);
92 $main::lxdebug->leave_sub(LXDebug::DEBUG2());
96 $main::lxdebug->enter_sub(2);
98 my ($self, $myconfig, $menulevel) = @_;
103 @menu = grep { !/--/ } @{ $self->{ORDER} };
105 @menu = grep { /^${menulevel}--/ } @{ $self->{ORDER} };
108 $main::lxdebug->leave_sub(2);
113 sub parse_access_string {
118 my $form = $main::form;
119 my $auth = $main::auth;
120 my $myconfig = \%main::myconfig;
125 push @stack, $cur_ary;
127 while ($access =~ m/^([a-z_]+|\||\&|\(|\)|\s+)/) {
129 substr($access, 0, length($1)) = "";
131 next if ($token =~ /\s/);
134 my $new_cur_ary = [];
135 push @stack, $new_cur_ary;
136 push @{$cur_ary}, $new_cur_ary;
137 $cur_ary = $new_cur_ary;
139 } elsif ($token eq ")") {
142 $form->error("Error in menu.ini for entry ${key}: missing '('");
144 $cur_ary = $stack[-1];
146 } elsif (($token eq "|") || ($token eq "&")) {
147 push @{$cur_ary}, $token;
150 push @{$cur_ary}, $auth->check_right($::myconfig{login}, $token, 1);
155 $form->error("Error in menu.ini for entry ${key}: unrecognized token at the start of '$access'\n");
158 if (1 < scalar @stack) {
159 $main::form->error("Error in menu.ini for entry ${key}: Missing ')'\n");
162 return SL::Auth::evaluate_rights_ary($stack[0]);
165 sub parse_instance_conf_string {
166 my ($self, $setting) = @_;
167 return $::instance_conf->data->{$setting};
175 foreach $key (@{ $self->{ORDER} }) {
176 my $entry = $self->{$key};
178 $entry->{GRANTED} = $entry->{ACCESS} ? $self->parse_access_string($key, $entry->{ACCESS}) : 1;
179 $entry->{GRANTED} &&= $self->parse_instance_conf_string($entry->{INSTANCE_CONF}) if $entry->{INSTANCE_CONF};
180 $entry->{IS_MENU} = $entry->{submenu} || ($key !~ m/--/);
181 $entry->{NUM_VISIBLE_CHILDREN} = 0;
185 substr($parent, rindex($parent, '--')) = '';
186 $entry->{GRANTED} &&= $self->{$parent}->{GRANTED};
189 $entry->{VISIBLE} = $entry->{GRANTED};
192 foreach $key (reverse @{ $self->{ORDER} }) {
193 my $entry = $self->{$key};
195 if ($entry->{IS_MENU}) {
196 $entry->{VISIBLE} &&= $entry->{NUM_VISIBLE_CHILDREN} > 0;
199 next if (($key !~ m/--/) || !$entry->{VISIBLE});
202 substr($parent, rindex($parent, '--')) = '';
203 $self->{$parent}->{NUM_VISIBLE_CHILDREN}++;
206 # $self->dump_visible();
208 $self->{ORDER} = [ grep { $self->{$_}->{VISIBLE} } @{ $self->{ORDER} } ];
211 # ToDO: fix this. nuke and pave algorithm without type checking screams for problems.
212 map { delete @{$self->{$_}}{qw(GRANTED IS_MENU NUM_VISIBLE_CHILDREN VISIBLE ACCESS)} if ($_ ne 'ORDER') } keys %{ $self };
218 foreach my $key (@{ $self->{ORDER} }) {
219 my $entry = $self->{$key};
220 $main::lxdebug->message(0, "$entry->{GRANTED} $entry->{VISIBLE} $entry->{NUM_VISIBLE_CHILDREN} $key");