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();
62 $main::lxdebug->enter_sub();
64 my ($self, $myconfig, $form, $item) = @_;
66 my $module = $self->{$item}{module} || $form->{script};
67 my $action = $self->{$item}{action} || "section_menu";
68 my $target = $self->{$item}{target} || "";
70 my $level = $form->escape($item);
72 my $style = 'style="vertical-align:top"';
73 my $target_token = ($target)
74 ? "target='$target'" : '';
76 my $href = ($self->{$item}{href})
77 ? $form->escape($self->{$item}{href})
78 : "$module?action=$action&level=$level";
80 my @vars = ($self->{$item}{href})
81 ? qw(module target href)
82 : qw(module action target href);
84 # map { delete $self->{$item}{$_} } @vars;
87 foreach my $key (keys %{ $self->{$item} }) {
88 $href .= "&" . $form->escape($key, 1) . "=";
89 my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
90 $value = $myconfig->{$value} . "/$conf" if ($conf);
91 $href .= $form->escape($value, 1);
94 my $str = "<a href='$href' $target_token $style>";
96 $main::lxdebug->leave_sub();
102 my ($self, $myconfig, $form, $item) = @_;
104 my $module = $form->{script};
105 my $action = "section_menu";
107 #if ($self->{$item}{module}) {
108 $module = $self->{$item}{module};
111 if ($self->{$item}{action}) {
112 $action = $self->{$item}{action};
115 my $level = $form->escape($item);
116 my $str = qq|$module?action=$action&level=$level|;
117 my @vars = qw(module action target href);
119 if ($self->{$item}{href}) {
120 $str = qq|$self->{$item}{href}|;
121 @vars = qw(module target href);
124 map { delete $self->{$item}{$_} } @vars;
127 foreach my $key (keys %{ $self->{$item} }) {
128 $str .= "&" . $form->escape($key, 1) . "=";
129 my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
130 $value = $myconfig->{$value} . "/$conf" if ($conf);
131 $str .= $form->escape($value, 1);
139 $main::lxdebug->enter_sub();
141 my ($self, $name, $item) = @_;
143 my $form = $main::form;
144 my $myconfig = \%main::myconfig;
146 my $module = $self->{$name}->{module} || $form->{script};
147 my $action = $self->{$name}->{action};
149 $item->{target} = $self->{$name}->{target} || "main_window";
150 $item->{href} = $self->{$name}->{href} || "${module}?action=" . $form->escape($action);
152 my @vars = qw(module target href);
153 push @vars, 'action' unless ($self->{$name}->{href});
155 map { delete $self->{$name}{$_} } @vars;
158 foreach my $key (keys %{ $self->{$name} }) {
159 my ($value, $conf) = split(m/=/, $self->{$name}->{$key}, 2);
160 $value = $myconfig->{$value} . "/$conf" if ($conf);
161 $item->{href} .= "&" . $form->escape($key) . "=" . $form->escape($value);
164 $main::lxdebug->leave_sub();
168 $main::lxdebug->enter_sub();
170 my ($self, $myconfig, $form, $item, $other) = @_;
172 my $module = $form->{script};
173 my $action = "section_menu";
176 if ($self->{$item}{module}) {
177 $module = $self->{$item}{module};
179 if ($self->{$item}{action}) {
180 $action = $self->{$item}{action};
182 if ($self->{$item}{target}) {
183 $target = $self->{$item}{target};
186 my $level = $form->escape($item);
188 my $str = qq|<a href="$module?action=| . $form->escape($action) . qq|&level=| . $form->escape($level);
190 my @vars = qw(module action target href);
192 if ($self->{$item}{href}) {
193 $str = qq|<a href=$self->{$item}{href}|;
194 @vars = qw(module target href);
197 map { delete $self->{$item}{$_} } @vars;
200 foreach my $key (keys %{ $self->{$item} }) {
201 $str .= "&" . $form->escape($key, 1) . "=";
202 my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
203 $value = $myconfig->{$value} . "/$conf" if ($conf);
204 $str .= $form->escape($value, 1);
210 $str .= qq| target="| . $form->quote($target) . qq|"|;
214 foreach my $key (keys(%{$other})) {
215 $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
221 $main::lxdebug->leave_sub();
227 $main::lxdebug->enter_sub();
229 my ($self, $myconfig, $form, $item, $other) = @_;
231 my $module = $form->{script};
232 my $action = "section_menu";
235 if ($self->{$item}{module}) {
236 $module = $self->{$item}{module};
238 if ($self->{$item}{action}) {
239 $action = $self->{$item}{action};
241 if ($self->{$item}{target}) {
242 $target = $self->{$item}{target};
245 my $level = $form->escape($item);
247 my $str = qq| link="$module?action=| . $form->escape($action) .
248 qq|&level=| . $form->escape($level);
250 my @vars = qw(module action target href);
252 if ($self->{$item}{href}) {
253 $str = qq| link=$self->{$item}{href}|;
254 @vars = qw(module target href);
257 map { delete $self->{$item}{$_} } @vars;
260 foreach my $key (keys %{ $self->{$item} }) {
261 $str .= "&" . $form->escape($key, 1) . "=";
262 my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
263 $value = $myconfig->{$value} . "/$conf" if ($conf);
264 $str .= $form->escape($value, 1);
272 foreach my $key (keys(%{$other})) {
273 $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
278 $main::lxdebug->leave_sub();
284 $main::lxdebug->enter_sub(2);
286 my ($self, $myconfig, $menulevel) = @_;
290 if ($menulevel eq "") {
291 @menu = grep { !/--/ } @{ $self->{ORDER} };
293 @menu = grep { /^${menulevel}--/ } @{ $self->{ORDER} };
296 $main::lxdebug->leave_sub(2);
301 sub parse_access_string {
306 my $form = $main::form;
307 my $auth = $main::auth;
308 my $myconfig = \%main::myconfig;
313 push @stack, $cur_ary;
315 while ($access =~ m/^([a-z_]+|\||\&|\(|\)|\s+)/) {
317 substr($access, 0, length($1)) = "";
319 next if ($token =~ /\s/);
322 my $new_cur_ary = [];
323 push @stack, $new_cur_ary;
324 push @{$cur_ary}, $new_cur_ary;
325 $cur_ary = $new_cur_ary;
327 } elsif ($token eq ")") {
330 $form->error("Error in menu.ini for entry ${key}: missing '('");
332 $cur_ary = $stack[-1];
334 } elsif (($token eq "|") || ($token eq "&")) {
335 push @{$cur_ary}, $token;
338 push @{$cur_ary}, $auth->check_right($form->{login}, $token, 1);
343 $form->error("Error in menu.ini for entry ${key}: unrecognized token at the start of '$access'\n");
346 if (1 < scalar @stack) {
347 $main::form->error("Error in menu.ini for entry ${key}: Missing ')'\n");
350 return SL::Auth::evaluate_rights_ary($stack[0]);
358 foreach $key (@{ $self->{ORDER} }) {
359 my $entry = $self->{$key};
361 $entry->{GRANTED} = $entry->{ACCESS} ? $self->parse_access_string($key, $entry->{ACCESS}) : 1;
362 $entry->{IS_MENU} = $entry->{submenu} || ($key !~ m/--/);
363 $entry->{NUM_VISIBLE_CHILDREN} = 0;
367 substr($parent, rindex($parent, '--')) = '';
368 $entry->{GRANTED} &&= $self->{$parent}->{GRANTED};
371 $entry->{VISIBLE} = $entry->{GRANTED};
374 foreach $key (reverse @{ $self->{ORDER} }) {
375 my $entry = $self->{$key};
377 if ($entry->{IS_MENU}) {
378 $entry->{VISIBLE} &&= $entry->{NUM_VISIBLE_CHILDREN} > 0;
381 next if (($key !~ m/--/) || !$entry->{VISIBLE});
384 substr($parent, rindex($parent, '--')) = '';
385 $self->{$parent}->{NUM_VISIBLE_CHILDREN}++;
388 # $self->dump_visible();
390 $self->{ORDER} = [ grep { $self->{$_}->{VISIBLE} } @{ $self->{ORDER} } ];
393 # ToDO: fix this. nuke and pave algorithm without type checking screams for problems.
394 map { delete @{$self->{$_}}{qw(GRANTED IS_MENU NUM_VISIBLE_CHILDREN VISIBLE ACCESS)} if ($_ ne 'ORDER') } keys %{ $self };
400 foreach my $key (@{ $self->{ORDER} }) {
401 my $entry = $self->{$key};
402 $main::lxdebug->message(0, "$entry->{GRANTED} $entry->{VISIBLE} $entry->{NUM_VISIBLE_CHILDREN} $key");