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, $menufile) = @_;
48 my $inifile = Inifile->new($menufile);
50 map { $self->{$_} = $inifile->{$_} } keys %{ $inifile };
56 $main::lxdebug->leave_sub();
70 } $self->access_control;
74 my ($self, $myconfig, $form, $item) = @_;
76 my $module = $form->{script};
77 my $action = "section_menu";
79 #if ($self->{$item}{module}) {
80 $module = $self->{$item}{module};
83 if ($self->{$item}{action}) {
84 $action = $self->{$item}{action};
87 my $level = $form->escape($item);
88 my $str = qq|$module?action=$action&level=$level|;
89 my @vars = qw(module action target href);
91 if ($self->{$item}{href}) {
92 $str = qq|$self->{$item}{href}|;
93 @vars = qw(module target href);
96 map { delete $self->{$item}{$_} } @vars;
99 foreach my $key (keys %{ $self->{$item} }) {
100 $str .= "&" . $form->escape($key, 1) . "=";
101 my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
102 $value = $myconfig->{$value} . "/$conf" if ($conf);
103 $str .= $form->escape($value, 1);
111 $main::lxdebug->enter_sub();
113 my ($self, $name, $item) = @_;
115 my $form = $main::form;
116 my $myconfig = \%main::myconfig;
118 my $module = $self->{$name}->{module} || $form->{script};
119 my $action = $self->{$name}->{action};
121 $item->{target} = $self->{$name}->{target} || "main_window";
122 $item->{href} = $self->{$name}->{href} || "${module}?action=" . $form->escape($action);
124 my @vars = qw(module target href);
125 push @vars, 'action' unless ($self->{$name}->{href});
127 map { delete $self->{$name}{$_} } @vars;
130 foreach my $key (keys %{ $self->{$name} }) {
131 my ($value, $conf) = split(m/=/, $self->{$name}->{$key}, 2);
132 $value = $myconfig->{$value} . "/$conf" if ($conf);
133 $item->{href} .= "&" . $form->escape($key) . "=" . $form->escape($value);
136 $main::lxdebug->leave_sub();
140 $main::lxdebug->enter_sub();
142 my ($self, $myconfig, $form, $item, $other) = @_;
144 my $module = $form->{script};
145 my $action = "section_menu";
148 if ($self->{$item}{module}) {
149 $module = $self->{$item}{module};
151 if ($self->{$item}{action}) {
152 $action = $self->{$item}{action};
154 if ($self->{$item}{target}) {
155 $target = $self->{$item}{target};
158 my $level = $form->escape($item);
160 my $str = qq|<a href="$module?action=| . $form->escape($action) . qq|&level=| . $form->escape($level);
162 my @vars = qw(module action target href);
164 if ($self->{$item}{href}) {
165 $str = qq|<a href=$self->{$item}{href}|;
166 @vars = qw(module target href);
169 map { delete $self->{$item}{$_} } @vars;
172 foreach my $key (keys %{ $self->{$item} }) {
173 $str .= "&" . $form->escape($key, 1) . "=";
174 my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
175 $value = $myconfig->{$value} . "/$conf" if ($conf);
176 $str .= $form->escape($value, 1);
182 $str .= qq| target="| . $form->quote($target) . qq|"|;
186 foreach my $key (keys(%{$other})) {
187 $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
193 $main::lxdebug->leave_sub();
199 $main::lxdebug->enter_sub();
201 my ($self, $myconfig, $form, $item, $other) = @_;
203 my $module = $form->{script};
204 my $action = "section_menu";
207 if ($self->{$item}{module}) {
208 $module = $self->{$item}{module};
210 if ($self->{$item}{action}) {
211 $action = $self->{$item}{action};
213 if ($self->{$item}{target}) {
214 $target = $self->{$item}{target};
217 my $level = $form->escape($item);
219 my $str = qq| link="$module?action=| . $form->escape($action) .
220 qq|&level=| . $form->escape($level);
222 my @vars = qw(module action target href);
224 if ($self->{$item}{href}) {
225 $str = qq| link=$self->{$item}{href}|;
226 @vars = qw(module target href);
229 map { delete $self->{$item}{$_} } @vars;
232 foreach my $key (keys %{ $self->{$item} }) {
233 $str .= "&" . $form->escape($key, 1) . "=";
234 my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
235 $value = $myconfig->{$value} . "/$conf" if ($conf);
236 $str .= $form->escape($value, 1);
244 foreach my $key (keys(%{$other})) {
245 $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
250 $main::lxdebug->leave_sub();
256 $main::lxdebug->enter_sub(2);
258 my ($self, $myconfig, $menulevel) = @_;
262 if ($menulevel eq "") {
263 @menu = grep { !/--/ } @{ $self->{ORDER} };
265 @menu = grep { /^${menulevel}--/ } @{ $self->{ORDER} };
268 $main::lxdebug->leave_sub(2);
273 sub parse_access_string {
278 my $form = $main::form;
279 my $auth = $main::auth;
280 my $myconfig = \%main::myconfig;
285 push @stack, $cur_ary;
287 while ($access =~ m/^([a-z_]+|\||\&|\(|\)|\s+)/) {
289 substr($access, 0, length($1)) = "";
291 next if ($token =~ /\s/);
294 my $new_cur_ary = [];
295 push @stack, $new_cur_ary;
296 push @{$cur_ary}, $new_cur_ary;
297 $cur_ary = $new_cur_ary;
299 } elsif ($token eq ")") {
302 $form->error("Error in menu.ini for entry ${key}: missing '('");
304 $cur_ary = $stack[-1];
306 } elsif (($token eq "|") || ($token eq "&")) {
307 push @{$cur_ary}, $token;
310 push @{$cur_ary}, $auth->check_right($form->{login}, $token, 1);
315 $form->error("Error in menu.ini for entry ${key}: unrecognized token at the start of '$access'\n");
318 if (1 < scalar @stack) {
319 $main::form->error("Error in menu.ini for entry ${key}: Missing ')'\n");
322 return SL::Auth::evaluate_rights_ary($stack[0]);
330 foreach $key (@{ $self->{ORDER} }) {
331 my $entry = $self->{$key};
333 $entry->{GRANTED} = $entry->{ACCESS} ? $self->parse_access_string($key, $entry->{ACCESS}) : 1;
334 $entry->{IS_MENU} = $entry->{submenu} || ($key !~ m/--/);
335 $entry->{NUM_VISIBLE_CHILDREN} = 0;
339 substr($parent, rindex($parent, '--')) = '';
340 $entry->{GRANTED} &&= $self->{$parent}->{GRANTED};
343 $entry->{VISIBLE} = $entry->{GRANTED};
346 foreach $key (reverse @{ $self->{ORDER} }) {
347 my $entry = $self->{$key};
349 if ($entry->{IS_MENU}) {
350 $entry->{VISIBLE} &&= $entry->{NUM_VISIBLE_CHILDREN} > 0;
353 next if (($key !~ m/--/) || !$entry->{VISIBLE});
356 substr($parent, rindex($parent, '--')) = '';
357 $self->{$parent}->{NUM_VISIBLE_CHILDREN}++;
360 # $self->dump_visible();
362 $self->{ORDER} = [ grep { $self->{$_}->{VISIBLE} } @{ $self->{ORDER} } ];
365 # ToDO: fix this. nuke and pave algorithm without type checking screams for problems.
366 map { delete @{$self->{$_}}{qw(GRANTED IS_MENU NUM_VISIBLE_CHILDREN VISIBLE ACCESS)} if ($_ ne 'ORDER') } keys %{ $self };
372 foreach my $key (@{ $self->{ORDER} }) {
373 my $entry = $self->{$key};
374 $main::lxdebug->message(0, "$entry->{GRANTED} $entry->{VISIBLE} $entry->{NUM_VISIBLE_CHILDREN} $key");