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   my ($self, $myconfig, $form, $item) = @_;
 
  64   my $module = $form->{script};
 
  65   my $action = "section_menu";
 
  67   #if ($self->{$item}{module}) {
 
  68   $module = $self->{$item}{module};
 
  71   if ($self->{$item}{action}) {
 
  72     $action = $self->{$item}{action};
 
  75   my $level = $form->escape($item);
 
  76   my $str   = qq|$module?action=$action&level=$level|;
 
  77   my @vars  = qw(module action target href);
 
  79   if ($self->{$item}{href}) {
 
  80     $str  = qq|$self->{$item}{href}|;
 
  81     @vars = qw(module target href);
 
  84   map { delete $self->{$item}{$_} } @vars;
 
  87   foreach my $key (keys %{ $self->{$item} }) {
 
  88     $str .= "&" . $form->escape($key, 1) . "=";
 
  89     my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
 
  90     $value = $myconfig->{$value} . "/$conf" if ($conf);
 
  91     $str .= $form->escape($value, 1);
 
  99   $main::lxdebug->enter_sub();
 
 101   my ($self, $name, $item) = @_;
 
 103   my $form        =  $main::form;
 
 104   my $myconfig    = \%main::myconfig;
 
 106   my $module      = $self->{$name}->{module} || $form->{script};
 
 107   my $action      = $self->{$name}->{action};
 
 109   $item->{target} = $self->{$name}->{target} || "main_window";
 
 110   $item->{href}   = $self->{$name}->{href}   || "${module}?action=" . $form->escape($action);
 
 112   my @vars = qw(module target href);
 
 113   push @vars, 'action' unless ($self->{$name}->{href});
 
 115   map { delete $self->{$name}{$_} } @vars;
 
 118   foreach my $key (keys %{ $self->{$name} }) {
 
 119     my ($value, $conf)  = split(m/=/, $self->{$name}->{$key}, 2);
 
 120     $value              = $myconfig->{$value} . "/$conf" if ($conf);
 
 121     $item->{href}      .= "&" . $form->escape($key) . "=" . $form->escape($value);
 
 124   $main::lxdebug->leave_sub();
 
 128   $main::lxdebug->enter_sub();
 
 130   my ($self, $myconfig, $form, $item, $other) = @_;
 
 132   my $module = $form->{script};
 
 133   my $action = "section_menu";
 
 136   if ($self->{$item}{module}) {
 
 137     $module = $self->{$item}{module};
 
 139   if ($self->{$item}{action}) {
 
 140     $action = $self->{$item}{action};
 
 142   if ($self->{$item}{target}) {
 
 143     $target = $self->{$item}{target};
 
 146   my $level = $form->escape($item);
 
 148   my $str = qq|<a href="$module?action=| . $form->escape($action) . qq|&level=| . $form->escape($level);
 
 150   my @vars = qw(module action target href);
 
 152   if ($self->{$item}{href}) {
 
 153     $str  = qq|<a href=$self->{$item}{href}|;
 
 154     @vars = qw(module target href);
 
 157   map { delete $self->{$item}{$_} } @vars;
 
 160   foreach my $key (keys %{ $self->{$item} }) {
 
 161     $str .= "&" . $form->escape($key, 1) . "=";
 
 162     my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
 
 163     $value = $myconfig->{$value} . "/$conf" if ($conf);
 
 164     $str .= $form->escape($value, 1);
 
 170     $str .= qq| target="| . $form->quote($target) . qq|"|;
 
 174     foreach my $key (keys(%{$other})) {
 
 175       $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
 
 181   $main::lxdebug->leave_sub();
 
 187   $main::lxdebug->enter_sub();
 
 189   my ($self, $myconfig, $form, $item, $other) = @_;
 
 191   my $module = $form->{script};
 
 192   my $action = "section_menu";
 
 195   if ($self->{$item}{module}) {
 
 196     $module = $self->{$item}{module};
 
 198   if ($self->{$item}{action}) {
 
 199     $action = $self->{$item}{action};
 
 201   if ($self->{$item}{target}) {
 
 202     $target = $self->{$item}{target};
 
 205   my $level = $form->escape($item);
 
 207   my $str = qq| link="$module?action=| . $form->escape($action) .
 
 208     qq|&level=| . $form->escape($level);
 
 210   my @vars = qw(module action target href);
 
 212   if ($self->{$item}{href}) {
 
 213     $str  = qq| link=$self->{$item}{href}|;
 
 214     @vars = qw(module target href);
 
 217   map { delete $self->{$item}{$_} } @vars;
 
 220   foreach my $key (keys %{ $self->{$item} }) {
 
 221     $str .= "&" . $form->escape($key, 1) . "=";
 
 222     my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
 
 223     $value = $myconfig->{$value} . "/$conf" if ($conf);
 
 224     $str .= $form->escape($value, 1);
 
 232     foreach my $key (keys(%{$other})) {
 
 233       $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
 
 238   $main::lxdebug->leave_sub();
 
 244   $main::lxdebug->enter_sub(2);
 
 246   my ($self, $myconfig, $menulevel) = @_;
 
 250   if ($menulevel eq "") {
 
 251     @menu = grep { !/--/ } @{ $self->{ORDER} };
 
 253     @menu = grep { /^${menulevel}--/ } @{ $self->{ORDER} };
 
 256   $main::lxdebug->leave_sub(2);
 
 261 sub parse_access_string {
 
 266   my $form        =  $main::form;
 
 267   my $auth        =  $main::auth;
 
 268   my $myconfig    = \%main::myconfig;
 
 273   push @stack, $cur_ary;
 
 275   while ($access =~ m/^([a-z_]+|\||\&|\(|\)|\s+)/) {
 
 277     substr($access, 0, length($1)) = "";
 
 279     next if ($token =~ /\s/);
 
 282       my $new_cur_ary = [];
 
 283       push @stack, $new_cur_ary;
 
 284       push @{$cur_ary}, $new_cur_ary;
 
 285       $cur_ary = $new_cur_ary;
 
 287     } elsif ($token eq ")") {
 
 290         $form->error("Error in menu.ini for entry ${key}: missing '('");
 
 292       $cur_ary = $stack[-1];
 
 294     } elsif (($token eq "|") || ($token eq "&")) {
 
 295       push @{$cur_ary}, $token;
 
 298       push @{$cur_ary}, $auth->check_right($form->{login}, $token, 1);
 
 303     $form->error("Error in menu.ini for entry ${key}: unrecognized token at the start of '$access'\n");
 
 306   if (1 < scalar @stack) {
 
 307     $main::form->error("Error in menu.ini for entry ${key}: Missing ')'\n");
 
 310   return SL::Auth::evaluate_rights_ary($stack[0]);
 
 318   foreach $key (@{ $self->{ORDER} }) {
 
 319     my $entry = $self->{$key};
 
 321     $entry->{GRANTED}              = $entry->{ACCESS} ? $self->parse_access_string($key, $entry->{ACCESS}) : 1;
 
 322     $entry->{IS_MENU}              = $entry->{submenu} || ($key !~ m/--/);
 
 323     $entry->{NUM_VISIBLE_CHILDREN} = 0;
 
 327       substr($parent, rindex($parent, '--')) = '';
 
 328       $entry->{GRANTED} &&= $self->{$parent}->{GRANTED};
 
 331     $entry->{VISIBLE} = $entry->{GRANTED};
 
 334   foreach $key (reverse @{ $self->{ORDER} }) {
 
 335     my $entry = $self->{$key};
 
 337     if ($entry->{IS_MENU}) {
 
 338       $entry->{VISIBLE} &&= $entry->{NUM_VISIBLE_CHILDREN} > 0;
 
 341     next if (($key !~ m/--/) || !$entry->{VISIBLE});
 
 344     substr($parent, rindex($parent, '--')) = '';
 
 345     $self->{$parent}->{NUM_VISIBLE_CHILDREN}++;
 
 348 #   $self->dump_visible();
 
 350   $self->{ORDER} = [ grep { $self->{$_}->{VISIBLE} } @{ $self->{ORDER} } ];
 
 353   # ToDO: fix this. nuke and pave algorithm without type checking screams for problems.
 
 354   map { delete @{$self->{$_}}{qw(GRANTED IS_MENU NUM_VISIBLE_CHILDREN VISIBLE ACCESS)} if ($_ ne 'ORDER') } keys %{ $self };
 
 360   foreach my $key (@{ $self->{ORDER} }) {
 
 361     my $entry = $self->{$key};
 
 362     $main::lxdebug->message(0, "$entry->{GRANTED} $entry->{VISIBLE} $entry->{NUM_VISIBLE_CHILDREN} $key");