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 #=====================================================================
45 $main::lxdebug->enter_sub();
47 my ($type, $menufile) = @_;
49 return $instance if $instance;
52 my $inifile = Inifile->new($menufile);
54 map { $self->{$_} = $inifile->{$_} } keys %{ $inifile };
60 $main::lxdebug->leave_sub();
62 return $instance = $self;
66 my ($self, $myconfig, $form, $item) = @_;
68 my $module = $form->{script};
69 my $action = "section_menu";
71 #if ($self->{$item}{module}) {
72 $module = $self->{$item}{module};
75 if ($self->{$item}{action}) {
76 $action = $self->{$item}{action};
79 my $level = $form->escape($item);
80 my $str = qq|$module?action=$action&level=$level|;
81 my @vars = qw(module action target href);
83 if ($self->{$item}{href}) {
84 $str = qq|$self->{$item}{href}|;
85 @vars = qw(module target href);
88 map { delete $self->{$item}{$_} } @vars;
91 foreach my $key (keys %{ $self->{$item} }) {
92 $str .= "&" . $form->escape($key, 1) . "=";
93 my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
94 $value = $myconfig->{$value} . "/$conf" if ($conf);
95 $str .= $form->escape($value, 1);
103 $main::lxdebug->enter_sub();
105 my ($self, $name, $item) = @_;
107 my $form = $main::form;
108 my $myconfig = \%main::myconfig;
110 my $module = $self->{$name}->{module} || $form->{script};
111 my $action = $self->{$name}->{action};
113 $item->{target} = $self->{$name}->{target} || "main_window";
114 $item->{href} = $self->{$name}->{href} || "${module}?action=" . $form->escape($action);
116 my @vars = qw(module target href);
117 push @vars, 'action' unless ($self->{$name}->{href});
119 map { delete $self->{$name}{$_} } @vars;
122 foreach my $key (keys %{ $self->{$name} }) {
123 my ($value, $conf) = split(m/=/, $self->{$name}->{$key}, 2);
124 $value = $myconfig->{$value} . "/$conf" if ($conf);
125 $item->{href} .= "&" . $form->escape($key) . "=" . $form->escape($value);
128 $main::lxdebug->leave_sub();
132 $main::lxdebug->enter_sub();
134 my ($self, $myconfig, $form, $item, $other) = @_;
136 my $module = $form->{script};
137 my $action = "section_menu";
140 if ($self->{$item}{module}) {
141 $module = $self->{$item}{module};
143 if ($self->{$item}{action}) {
144 $action = $self->{$item}{action};
146 if ($self->{$item}{target}) {
147 $target = $self->{$item}{target};
150 my $level = $form->escape($item);
152 my $str = qq|<a href="$module?action=| . $form->escape($action) . qq|&level=| . $form->escape($level);
154 my @vars = qw(module action target href);
156 if ($self->{$item}{href}) {
157 $str = qq|<a href=$self->{$item}{href}|;
158 @vars = qw(module target href);
161 map { delete $self->{$item}{$_} } @vars;
164 foreach my $key (keys %{ $self->{$item} }) {
165 $str .= "&" . $form->escape($key, 1) . "=";
166 my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
167 $value = $myconfig->{$value} . "/$conf" if ($conf);
168 $str .= $form->escape($value, 1);
174 $str .= qq| target="| . $form->quote($target) . qq|"|;
178 foreach my $key (keys(%{$other})) {
179 $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
185 $main::lxdebug->leave_sub();
191 $main::lxdebug->enter_sub();
193 my ($self, $myconfig, $form, $item, $other) = @_;
195 my $module = $form->{script};
196 my $action = "section_menu";
199 if ($self->{$item}{module}) {
200 $module = $self->{$item}{module};
202 if ($self->{$item}{action}) {
203 $action = $self->{$item}{action};
205 if ($self->{$item}{target}) {
206 $target = $self->{$item}{target};
209 my $level = $form->escape($item);
211 my $str = qq| link="$module?action=| . $form->escape($action) .
212 qq|&level=| . $form->escape($level);
214 my @vars = qw(module action target href);
216 if ($self->{$item}{href}) {
217 $str = qq| link=$self->{$item}{href}|;
218 @vars = qw(module target href);
221 map { delete $self->{$item}{$_} } @vars;
224 foreach my $key (keys %{ $self->{$item} }) {
225 $str .= "&" . $form->escape($key, 1) . "=";
226 my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
227 $value = $myconfig->{$value} . "/$conf" if ($conf);
228 $str .= $form->escape($value, 1);
236 foreach my $key (keys(%{$other})) {
237 $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
242 $main::lxdebug->leave_sub();
248 $main::lxdebug->enter_sub(2);
250 my ($self, $myconfig, $menulevel) = @_;
254 if ($menulevel eq "") {
255 @menu = grep { !/--/ } @{ $self->{ORDER} };
257 @menu = grep { /^${menulevel}--/ } @{ $self->{ORDER} };
260 $main::lxdebug->leave_sub(2);
265 sub parse_access_string {
270 my $form = $main::form;
271 my $auth = $main::auth;
272 my $myconfig = \%main::myconfig;
277 push @stack, $cur_ary;
279 while ($access =~ m/^([a-z_]+|\||\&|\(|\)|\s+)/) {
281 substr($access, 0, length($1)) = "";
283 next if ($token =~ /\s/);
286 my $new_cur_ary = [];
287 push @stack, $new_cur_ary;
288 push @{$cur_ary}, $new_cur_ary;
289 $cur_ary = $new_cur_ary;
291 } elsif ($token eq ")") {
294 $form->error("Error in menu.ini for entry ${key}: missing '('");
296 $cur_ary = $stack[-1];
298 } elsif (($token eq "|") || ($token eq "&")) {
299 push @{$cur_ary}, $token;
302 push @{$cur_ary}, $auth->check_right($form->{login}, $token, 1);
307 $form->error("Error in menu.ini for entry ${key}: unrecognized token at the start of '$access'\n");
310 if (1 < scalar @stack) {
311 $main::form->error("Error in menu.ini for entry ${key}: Missing ')'\n");
314 return SL::Auth::evaluate_rights_ary($stack[0]);
322 foreach $key (@{ $self->{ORDER} }) {
323 my $entry = $self->{$key};
325 $entry->{GRANTED} = $entry->{ACCESS} ? $self->parse_access_string($key, $entry->{ACCESS}) : 1;
326 $entry->{IS_MENU} = $entry->{submenu} || ($key !~ m/--/);
327 $entry->{NUM_VISIBLE_CHILDREN} = 0;
331 substr($parent, rindex($parent, '--')) = '';
332 $entry->{GRANTED} &&= $self->{$parent}->{GRANTED};
335 $entry->{VISIBLE} = $entry->{GRANTED};
338 foreach $key (reverse @{ $self->{ORDER} }) {
339 my $entry = $self->{$key};
341 if ($entry->{IS_MENU}) {
342 $entry->{VISIBLE} &&= $entry->{NUM_VISIBLE_CHILDREN} > 0;
345 next if (($key !~ m/--/) || !$entry->{VISIBLE});
348 substr($parent, rindex($parent, '--')) = '';
349 $self->{$parent}->{NUM_VISIBLE_CHILDREN}++;
352 # $self->dump_visible();
354 $self->{ORDER} = [ grep { $self->{$_}->{VISIBLE} } @{ $self->{ORDER} } ];
357 # ToDO: fix this. nuke and pave algorithm without type checking screams for problems.
358 map { delete @{$self->{$_}}{qw(GRANTED IS_MENU NUM_VISIBLE_CHILDREN VISIBLE ACCESS)} if ($_ ne 'ORDER') } keys %{ $self };
364 foreach my $key (@{ $self->{ORDER} }) {
365 my $entry = $self->{$key};
366 $main::lxdebug->message(0, "$entry->{GRANTED} $entry->{VISIBLE} $entry->{NUM_VISIBLE_CHILDREN} $key");