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} || "";
69 my $level = $form->escape($item);
70 my $target_token = ($target) ? "target='$target'" : '';
72 my $href = ($self->{$item}{href})
73 ? $form->escape($self->{$item}{href})
74 : "$module?action=$action";
77 foreach my $key (keys %{ $self->{$item} }) {
78 next if $key =~ /target|module|action/;
79 $href .= "&" . $form->escape($key, 1) . "=";
80 my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
81 $value = $myconfig->{$value} . "/$conf" if ($conf);
82 $href .= $form->escape($value, 1);
85 my $str = "<a href='$href' $target_token>";
87 $main::lxdebug->leave_sub();
93 my ($self, $myconfig, $form, $item) = @_;
95 my $module = $form->{script};
96 my $action = "section_menu";
98 #if ($self->{$item}{module}) {
99 $module = $self->{$item}{module};
102 if ($self->{$item}{action}) {
103 $action = $self->{$item}{action};
106 my $level = $form->escape($item);
107 my $str = qq|$module?action=$action&level=$level|;
108 my @vars = qw(module action target href);
110 if ($self->{$item}{href}) {
111 $str = qq|$self->{$item}{href}|;
112 @vars = qw(module target href);
115 map { delete $self->{$item}{$_} } @vars;
118 foreach my $key (keys %{ $self->{$item} }) {
119 $str .= "&" . $form->escape($key, 1) . "=";
120 my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
121 $value = $myconfig->{$value} . "/$conf" if ($conf);
122 $str .= $form->escape($value, 1);
130 $main::lxdebug->enter_sub();
132 my ($self, $name, $item) = @_;
134 my $form = $main::form;
135 my $myconfig = \%main::myconfig;
137 my $module = $self->{$name}->{module} || $form->{script};
138 my $action = $self->{$name}->{action};
140 $item->{target} = $self->{$name}->{target} || "main_window";
141 $item->{href} = $self->{$name}->{href} || "${module}?action=" . $form->escape($action);
143 my @vars = qw(module target href);
144 push @vars, 'action' unless ($self->{$name}->{href});
146 map { delete $self->{$name}{$_} } @vars;
149 foreach my $key (keys %{ $self->{$name} }) {
150 my ($value, $conf) = split(m/=/, $self->{$name}->{$key}, 2);
151 $value = $myconfig->{$value} . "/$conf" if ($conf);
152 $item->{href} .= "&" . $form->escape($key) . "=" . $form->escape($value);
155 $main::lxdebug->leave_sub();
159 $main::lxdebug->enter_sub();
161 my ($self, $myconfig, $form, $item, $other) = @_;
163 my $module = $form->{script};
164 my $action = "section_menu";
167 if ($self->{$item}{module}) {
168 $module = $self->{$item}{module};
170 if ($self->{$item}{action}) {
171 $action = $self->{$item}{action};
173 if ($self->{$item}{target}) {
174 $target = $self->{$item}{target};
177 my $level = $form->escape($item);
179 my $str = qq|<a href="$module?action=| . $form->escape($action) . qq|&level=| . $form->escape($level);
181 my @vars = qw(module action target href);
183 if ($self->{$item}{href}) {
184 $str = qq|<a href=$self->{$item}{href}|;
185 @vars = qw(module target href);
188 map { delete $self->{$item}{$_} } @vars;
191 foreach my $key (keys %{ $self->{$item} }) {
192 $str .= "&" . $form->escape($key, 1) . "=";
193 my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
194 $value = $myconfig->{$value} . "/$conf" if ($conf);
195 $str .= $form->escape($value, 1);
201 $str .= qq| target="| . $form->quote($target) . qq|"|;
205 foreach my $key (keys(%{$other})) {
206 $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
212 $main::lxdebug->leave_sub();
218 $main::lxdebug->enter_sub();
220 my ($self, $myconfig, $form, $item, $other) = @_;
222 my $module = $form->{script};
223 my $action = "section_menu";
226 if ($self->{$item}{module}) {
227 $module = $self->{$item}{module};
229 if ($self->{$item}{action}) {
230 $action = $self->{$item}{action};
232 if ($self->{$item}{target}) {
233 $target = $self->{$item}{target};
236 my $level = $form->escape($item);
238 my $str = qq| link="$module?action=| . $form->escape($action) .
239 qq|&level=| . $form->escape($level);
241 my @vars = qw(module action target href);
243 if ($self->{$item}{href}) {
244 $str = qq| link=$self->{$item}{href}|;
245 @vars = qw(module target href);
248 map { delete $self->{$item}{$_} } @vars;
251 foreach my $key (keys %{ $self->{$item} }) {
252 $str .= "&" . $form->escape($key, 1) . "=";
253 my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
254 $value = $myconfig->{$value} . "/$conf" if ($conf);
255 $str .= $form->escape($value, 1);
263 foreach my $key (keys(%{$other})) {
264 $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
269 $main::lxdebug->leave_sub();
275 $main::lxdebug->enter_sub(2);
277 my ($self, $myconfig, $menulevel) = @_;
281 if ($menulevel eq "") {
282 @menu = grep { !/--/ } @{ $self->{ORDER} };
284 @menu = grep { /^${menulevel}--/ } @{ $self->{ORDER} };
287 $main::lxdebug->leave_sub(2);
292 sub parse_access_string {
297 my $form = $main::form;
298 my $auth = $main::auth;
299 my $myconfig = \%main::myconfig;
304 push @stack, $cur_ary;
306 while ($access =~ m/^([a-z_]+|\||\&|\(|\)|\s+)/) {
308 substr($access, 0, length($1)) = "";
310 next if ($token =~ /\s/);
313 my $new_cur_ary = [];
314 push @stack, $new_cur_ary;
315 push @{$cur_ary}, $new_cur_ary;
316 $cur_ary = $new_cur_ary;
318 } elsif ($token eq ")") {
321 $form->error("Error in menu.ini for entry ${key}: missing '('");
323 $cur_ary = $stack[-1];
325 } elsif (($token eq "|") || ($token eq "&")) {
326 push @{$cur_ary}, $token;
329 push @{$cur_ary}, $auth->check_right($form->{login}, $token, 1);
334 $form->error("Error in menu.ini for entry ${key}: unrecognized token at the start of '$access'\n");
337 if (1 < scalar @stack) {
338 $main::form->error("Error in menu.ini for entry ${key}: Missing ')'\n");
341 return SL::Auth::evaluate_rights_ary($stack[0]);
349 foreach $key (@{ $self->{ORDER} }) {
350 my $entry = $self->{$key};
352 $entry->{GRANTED} = $entry->{ACCESS} ? $self->parse_access_string($key, $entry->{ACCESS}) : 1;
353 $entry->{IS_MENU} = $entry->{submenu} || ($key !~ m/--/);
354 $entry->{NUM_VISIBLE_CHILDREN} = 0;
358 substr($parent, rindex($parent, '--')) = '';
359 $entry->{GRANTED} &&= $self->{$parent}->{GRANTED};
362 $entry->{VISIBLE} = $entry->{GRANTED};
365 foreach $key (reverse @{ $self->{ORDER} }) {
366 my $entry = $self->{$key};
368 if ($entry->{IS_MENU}) {
369 $entry->{VISIBLE} &&= $entry->{NUM_VISIBLE_CHILDREN} > 0;
372 next if (($key !~ m/--/) || !$entry->{VISIBLE});
375 substr($parent, rindex($parent, '--')) = '';
376 $self->{$parent}->{NUM_VISIBLE_CHILDREN}++;
379 # $self->dump_visible();
381 $self->{ORDER} = [ grep { $self->{$_}->{VISIBLE} } @{ $self->{ORDER} } ];
384 # ToDO: fix this. nuke and pave algorithm without type checking screams for problems.
385 map { delete @{$self->{$_}}{qw(GRANTED IS_MENU NUM_VISIBLE_CHILDREN VISIBLE ACCESS)} if ($_ ne 'ORDER') } keys %{ $self };
391 foreach my $key (@{ $self->{ORDER} }) {
392 my $entry = $self->{$key};
393 $main::lxdebug->message(0, "$entry->{GRANTED} $entry->{VISIBLE} $entry->{NUM_VISIBLE_CHILDREN} $key");