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(LXDebug::DEBUG2());
 
  64   my ($self, $name, $item) = @_;
 
  66   my $form        =  $main::form;
 
  67   my $myconfig    = \%main::myconfig;
 
  69   my $module      = $self->{$name}->{module} || $form->{script};
 
  70   my $action      = $self->{$name}->{action};
 
  72   $item->{target} = $self->{$name}->{target} || "main_window";
 
  73   $item->{href}   = $self->{$name}->{href}   || "${module}?action=" . $form->escape($action);
 
  75   my @vars = qw(module target href);
 
  76   push @vars, 'action' unless ($self->{$name}->{href});
 
  78   map { delete $self->{$name}{$_} } @vars;
 
  81   foreach my $key (keys %{ $self->{$name} }) {
 
  82     my ($value, $conf)  = split(m/=/, $self->{$name}->{$key}, 2);
 
  83     $value              = $myconfig->{$value} . "/$conf" if ($conf);
 
  84     $item->{href}      .= "&" . $form->escape($key) . "=" . $form->escape($value);
 
  87   $main::lxdebug->leave_sub(LXDebug::DEBUG2());
 
  91   $main::lxdebug->enter_sub(2);
 
  93   my ($self, $myconfig, $menulevel) = @_;
 
  98     @menu = grep { !/--/ } @{ $self->{ORDER} };
 
 100     @menu = grep { /^${menulevel}--/ } @{ $self->{ORDER} };
 
 103   $main::lxdebug->leave_sub(2);
 
 108 sub parse_access_string {
 
 113   my $form        =  $main::form;
 
 114   my $auth        =  $main::auth;
 
 115   my $myconfig    = \%main::myconfig;
 
 120   push @stack, $cur_ary;
 
 122   while ($access =~ m/^([a-z_]+|\||\&|\(|\)|\s+)/) {
 
 124     substr($access, 0, length($1)) = "";
 
 126     next if ($token =~ /\s/);
 
 129       my $new_cur_ary = [];
 
 130       push @stack, $new_cur_ary;
 
 131       push @{$cur_ary}, $new_cur_ary;
 
 132       $cur_ary = $new_cur_ary;
 
 134     } elsif ($token eq ")") {
 
 137         $form->error("Error in menu.ini for entry ${key}: missing '('");
 
 139       $cur_ary = $stack[-1];
 
 141     } elsif (($token eq "|") || ($token eq "&")) {
 
 142       push @{$cur_ary}, $token;
 
 145       push @{$cur_ary}, $auth->check_right($form->{login}, $token, 1);
 
 150     $form->error("Error in menu.ini for entry ${key}: unrecognized token at the start of '$access'\n");
 
 153   if (1 < scalar @stack) {
 
 154     $main::form->error("Error in menu.ini for entry ${key}: Missing ')'\n");
 
 157   return SL::Auth::evaluate_rights_ary($stack[0]);
 
 165   foreach $key (@{ $self->{ORDER} }) {
 
 166     my $entry = $self->{$key};
 
 168     $entry->{GRANTED}              = $entry->{ACCESS} ? $self->parse_access_string($key, $entry->{ACCESS}) : 1;
 
 169     $entry->{IS_MENU}              = $entry->{submenu} || ($key !~ m/--/);
 
 170     $entry->{NUM_VISIBLE_CHILDREN} = 0;
 
 174       substr($parent, rindex($parent, '--')) = '';
 
 175       $entry->{GRANTED} &&= $self->{$parent}->{GRANTED};
 
 178     $entry->{VISIBLE} = $entry->{GRANTED};
 
 181   foreach $key (reverse @{ $self->{ORDER} }) {
 
 182     my $entry = $self->{$key};
 
 184     if ($entry->{IS_MENU}) {
 
 185       $entry->{VISIBLE} &&= $entry->{NUM_VISIBLE_CHILDREN} > 0;
 
 188     next if (($key !~ m/--/) || !$entry->{VISIBLE});
 
 191     substr($parent, rindex($parent, '--')) = '';
 
 192     $self->{$parent}->{NUM_VISIBLE_CHILDREN}++;
 
 195 #   $self->dump_visible();
 
 197   $self->{ORDER} = [ grep { $self->{$_}->{VISIBLE} } @{ $self->{ORDER} } ];
 
 200   # ToDO: fix this. nuke and pave algorithm without type checking screams for problems.
 
 201   map { delete @{$self->{$_}}{qw(GRANTED IS_MENU NUM_VISIBLE_CHILDREN VISIBLE ACCESS)} if ($_ ne 'ORDER') } keys %{ $self };
 
 207   foreach my $key (@{ $self->{ORDER} }) {
 
 208     my $entry = $self->{$key};
 
 209     $main::lxdebug->message(0, "$entry->{GRANTED} $entry->{VISIBLE} $entry->{NUM_VISIBLE_CHILDREN} $key");