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 #=====================================================================
 
  41   $main::lxdebug->enter_sub();
 
  43   my ($type, $menufile) = @_;
 
  46   my $inifile = Inifile->new($menufile);
 
  48   map { $self->{$_} = $inifile->{$_} } keys %{ $inifile };
 
  54   $main::lxdebug->leave_sub();
 
  60   $main::lxdebug->enter_sub();
 
  62   my ($self, $myconfig, $form, $item) = @_;
 
  64   my $module = $form->{script};
 
  65   my $action = "section_menu";
 
  68   if ($self->{$item}{module}) {
 
  69     $module = $self->{$item}{module};
 
  71   if ($self->{$item}{action}) {
 
  72     $action = $self->{$item}{action};
 
  74   if ($self->{$item}{target}) {
 
  75     $target = $self->{$item}{target};
 
  78   my $level = $form->escape($item);
 
  80   my $str = qq|<a style="vertical-align:top" href=$module?action=$action&level=$level|;
 
  82   my @vars = qw(module action target href);
 
  84   if ($self->{$item}{href}) {
 
  85     $str  = qq|<a href=$self->{$item}{href}|;
 
  86     @vars = qw(module target href);
 
  89   map { delete $self->{$item}{$_} } @vars;
 
  92   foreach my $key (keys %{ $self->{$item} }) {
 
  93     $str .= "&" . $form->escape($key, 1) . "=";
 
  94     ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
 
  95     $value = $myconfig->{$value} . "/$conf" if ($conf);
 
  96     $str .= $form->escape($value, 1);
 
 100     $str .= qq| target=$target|;
 
 105   $main::lxdebug->leave_sub();
 
 111   $main::lxdebug->enter_sub();
 
 113   my ($self, $name, $item) = @_;
 
 115   my $form        = $main::form;
 
 117   my $module      = $self->{$name}->{module} || $form->{script};
 
 118   my $action      = $self->{$name}->{action};
 
 120   $item->{target} = $self->{$name}->{target} || "main_window";
 
 121   $item->{href}   = $self->{$name}->{href}   || "${module}?action=" . $form->escape($action);
 
 123   my @vars = qw(module target href);
 
 124   push @vars, $action unless ($self->{$name}->{href});
 
 126   map { delete $self->{$name}{$_} } @vars;
 
 129   foreach my $key (keys %{ $self->{$name} }) {
 
 130     my ($value, $conf)  = split(m/=/, $self->{$name}->{$key}, 2);
 
 131     $value              = $myconfig->{$value} . "/$conf" if ($conf);
 
 132     $item->{href}      .= "&" . $form->escape($key) . "=" . $form->escape($value);
 
 135   $main::lxdebug->leave_sub();
 
 139   $main::lxdebug->enter_sub();
 
 141   my ($self, $myconfig, $form, $item, $other) = @_;
 
 143   my $module = $form->{script};
 
 144   my $action = "section_menu";
 
 147   if ($self->{$item}{module}) {
 
 148     $module = $self->{$item}{module};
 
 150   if ($self->{$item}{action}) {
 
 151     $action = $self->{$item}{action};
 
 153   if ($self->{$item}{target}) {
 
 154     $target = $self->{$item}{target};
 
 157   my $level = $form->escape($item);
 
 159   my $str = qq|<a href="$module?action=| . $form->escape($action) . qq|&level=| . $form->escape($level);
 
 161   my @vars = qw(module action target href);
 
 163   if ($self->{$item}{href}) {
 
 164     $str  = qq|<a href=$self->{$item}{href}|;
 
 165     @vars = qw(module target href);
 
 168   map { delete $self->{$item}{$_} } @vars;
 
 171   foreach my $key (keys %{ $self->{$item} }) {
 
 172     $str .= "&" . $form->escape($key, 1) . "=";
 
 173     ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
 
 174     $value = $myconfig->{$value} . "/$conf" if ($conf);
 
 175     $str .= $form->escape($value, 1);
 
 181     $str .= qq| target="| . $form->quote($target) . qq|"|;
 
 185     foreach my $key (keys(%{$other})) {
 
 186       $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
 
 192   $main::lxdebug->leave_sub();
 
 198   $main::lxdebug->enter_sub();
 
 200   my ($self, $myconfig, $form, $item, $other) = @_;
 
 202   my $module = $form->{script};
 
 203   my $action = "section_menu";
 
 206   if ($self->{$item}{module}) {
 
 207     $module = $self->{$item}{module};
 
 209   if ($self->{$item}{action}) {
 
 210     $action = $self->{$item}{action};
 
 212   if ($self->{$item}{target}) {
 
 213     $target = $self->{$item}{target};
 
 216   my $level = $form->escape($item);
 
 218   my $str = qq| link="$module?action=| . $form->escape($action) .
 
 219     qq|&level=| . $form->escape($level);
 
 221   my @vars = qw(module action target href);
 
 223   if ($self->{$item}{href}) {
 
 224     $str  = qq| link=$self->{$item}{href}|;
 
 225     @vars = qw(module target href);
 
 228   map { delete $self->{$item}{$_} } @vars;
 
 231   foreach my $key (keys %{ $self->{$item} }) {
 
 232     $str .= "&" . $form->escape($key, 1) . "=";
 
 233     ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
 
 234     $value = $myconfig->{$value} . "/$conf" if ($conf);
 
 235     $str .= $form->escape($value, 1);
 
 243     foreach my $key (keys(%{$other})) {
 
 244       $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
 
 249   $main::lxdebug->leave_sub();
 
 255   $main::lxdebug->enter_sub(2);
 
 257   my ($self, $myconfig, $menulevel) = @_;
 
 261   if ($menulevel eq "") {
 
 262     @menu = grep { !/--/ } @{ $self->{ORDER} };
 
 264     @menu = grep { /^${menulevel}--/ } @{ $self->{ORDER} };
 
 267   my @a    = split(/;/, $myconfig->{acs});
 
 270   # remove --AR, --AP from array
 
 271   grep { ($a, $b) = split(/--/); s/--$a$//; } @a;
 
 273   map { $excl{$_} = 1 } @a;
 
 276   map { push @a, $_ unless $excl{$_} } (@menu);
 
 278   $main::lxdebug->leave_sub(2);
 
 284   my ($self, $menulevel, $hash) = @_;
 
 286   my @items = $self->access_control(\%main::myconfig, $menulevel);
 
 288   $menulevel =~ s/[^A-Za-z_\/\.\+\-]/_/g;
 
 289   $hash->{"access_" . lc($menulevel)} = 1 if ($menulevel);
 
 291   foreach my $item (@items) {
 
 292     $self->generate_acl($item, $hash); #unless ($menulevel);
 
 296 sub parse_access_string {
 
 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         $main::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}, $main::auth->check_right($main::form->{login}, $token, 1);
 
 334     $main::form->error("Error in menu.ini for entry ${name}: unrecognized token at the start of '$access'\n");
 
 337   if (1 < scalar @stack) {
 
 338     $main::form->error("Error in menu.ini for entry ${name}: 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} } ];
 
 383   map { delete @{$self->{$_}}{qw(GRANTED IS_MENU NUM_VISIBLE_CHILDREN VISIBLE ACCESS)} if ($_ ne 'ORDER') } keys %{ $self };
 
 388   foreach my $key (@{ $self->{ORDER} }) {
 
 389     my $entry = $self->{$key};
 
 390     $main::lxdebug->message(0, "$entry->{GRANTED} $entry->{VISIBLE} $entry->{NUM_VISIBLE_CHILDREN} $key");