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 = $form->{script};
 
  67   my $action = "section_menu";
 
  70   if ($self->{$item}{module}) {
 
  71     $module = $self->{$item}{module};
 
  73   if ($self->{$item}{action}) {
 
  74     $action = $self->{$item}{action};
 
  76   if ($self->{$item}{target}) {
 
  77     $target = $self->{$item}{target};
 
  80   my $level = $form->escape($item);
 
  82   my $str = qq|<a style="vertical-align:top" href=$module?action=$action&level=$level|;
 
  84   my @vars = qw(module action target href);
 
  86   if ($self->{$item}{href}) {
 
  87     $str  = qq|<a href=$self->{$item}{href}|;
 
  88     @vars = qw(module target href);
 
  91   map { delete $self->{$item}{$_} } @vars;
 
  94   foreach my $key (keys %{ $self->{$item} }) {
 
  95     $str .= "&" . $form->escape($key, 1) . "=";
 
  96     my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
 
  97     $value = $myconfig->{$value} . "/$conf" if ($conf);
 
  98     $str .= $form->escape($value, 1);
 
 102     $str .= qq| target=$target|;
 
 107   $main::lxdebug->leave_sub();
 
 113   my ($self, $myconfig, $form, $item) = @_;
 
 115   my $module = $form->{script};
 
 116   my $action = "section_menu";
 
 118   #if ($self->{$item}{module}) {
 
 119   $module = $self->{$item}{module};
 
 122   if ($self->{$item}{action}) {
 
 123     $action = $self->{$item}{action};
 
 126   my $level = $form->escape($item);
 
 127   my $str   = qq|$module?action=$action&level=$level|;
 
 128   my @vars  = qw(module action target href);
 
 130   if ($self->{$item}{href}) {
 
 131     $str  = qq|$self->{$item}{href}|;
 
 132     @vars = qw(module target href);
 
 135   map { delete $self->{$item}{$_} } @vars;
 
 138   foreach my $key (keys %{ $self->{$item} }) {
 
 139     $str .= "&" . $form->escape($key, 1) . "=";
 
 140     my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
 
 141     $value = $myconfig->{$value} . "/$conf" if ($conf);
 
 142     $str .= $form->escape($value, 1);
 
 150   $main::lxdebug->enter_sub();
 
 152   my ($self, $name, $item) = @_;
 
 154   my $form        =  $main::form;
 
 155   my $myconfig    = \%main::myconfig;
 
 157   my $module      = $self->{$name}->{module} || $form->{script};
 
 158   my $action      = $self->{$name}->{action};
 
 160   $item->{target} = $self->{$name}->{target} || "main_window";
 
 161   $item->{href}   = $self->{$name}->{href}   || "${module}?action=" . $form->escape($action);
 
 163   my @vars = qw(module target href);
 
 164   push @vars, 'action' unless ($self->{$name}->{href});
 
 166   map { delete $self->{$name}{$_} } @vars;
 
 169   foreach my $key (keys %{ $self->{$name} }) {
 
 170     my ($value, $conf)  = split(m/=/, $self->{$name}->{$key}, 2);
 
 171     $value              = $myconfig->{$value} . "/$conf" if ($conf);
 
 172     $item->{href}      .= "&" . $form->escape($key) . "=" . $form->escape($value);
 
 175   $main::lxdebug->leave_sub();
 
 179   $main::lxdebug->enter_sub();
 
 181   my ($self, $myconfig, $form, $item, $other) = @_;
 
 183   my $module = $form->{script};
 
 184   my $action = "section_menu";
 
 187   if ($self->{$item}{module}) {
 
 188     $module = $self->{$item}{module};
 
 190   if ($self->{$item}{action}) {
 
 191     $action = $self->{$item}{action};
 
 193   if ($self->{$item}{target}) {
 
 194     $target = $self->{$item}{target};
 
 197   my $level = $form->escape($item);
 
 199   my $str = qq|<a href="$module?action=| . $form->escape($action) . qq|&level=| . $form->escape($level);
 
 201   my @vars = qw(module action target href);
 
 203   if ($self->{$item}{href}) {
 
 204     $str  = qq|<a href=$self->{$item}{href}|;
 
 205     @vars = qw(module target href);
 
 208   map { delete $self->{$item}{$_} } @vars;
 
 211   foreach my $key (keys %{ $self->{$item} }) {
 
 212     $str .= "&" . $form->escape($key, 1) . "=";
 
 213     my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
 
 214     $value = $myconfig->{$value} . "/$conf" if ($conf);
 
 215     $str .= $form->escape($value, 1);
 
 221     $str .= qq| target="| . $form->quote($target) . qq|"|;
 
 225     foreach my $key (keys(%{$other})) {
 
 226       $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
 
 232   $main::lxdebug->leave_sub();
 
 238   $main::lxdebug->enter_sub();
 
 240   my ($self, $myconfig, $form, $item, $other) = @_;
 
 242   my $module = $form->{script};
 
 243   my $action = "section_menu";
 
 246   if ($self->{$item}{module}) {
 
 247     $module = $self->{$item}{module};
 
 249   if ($self->{$item}{action}) {
 
 250     $action = $self->{$item}{action};
 
 252   if ($self->{$item}{target}) {
 
 253     $target = $self->{$item}{target};
 
 256   my $level = $form->escape($item);
 
 258   my $str = qq| link="$module?action=| . $form->escape($action) .
 
 259     qq|&level=| . $form->escape($level);
 
 261   my @vars = qw(module action target href);
 
 263   if ($self->{$item}{href}) {
 
 264     $str  = qq| link=$self->{$item}{href}|;
 
 265     @vars = qw(module target href);
 
 268   map { delete $self->{$item}{$_} } @vars;
 
 271   foreach my $key (keys %{ $self->{$item} }) {
 
 272     $str .= "&" . $form->escape($key, 1) . "=";
 
 273     my ($value, $conf) = split(/=/, $self->{$item}{$key}, 2);
 
 274     $value = $myconfig->{$value} . "/$conf" if ($conf);
 
 275     $str .= $form->escape($value, 1);
 
 283     foreach my $key (keys(%{$other})) {
 
 284       $str .= qq| ${key}="| . $form->quote($other->{$key}) . qq|"|;
 
 289   $main::lxdebug->leave_sub();
 
 295   $main::lxdebug->enter_sub(2);
 
 297   my ($self, $myconfig, $menulevel) = @_;
 
 301   if ($menulevel eq "") {
 
 302     @menu = grep { !/--/ } @{ $self->{ORDER} };
 
 304     @menu = grep { /^${menulevel}--/ } @{ $self->{ORDER} };
 
 307   $main::lxdebug->leave_sub(2);
 
 312 sub parse_access_string {
 
 317   my $form        =  $main::form;
 
 318   my $auth        =  $main::auth;
 
 319   my $myconfig    = \%main::myconfig;
 
 324   push @stack, $cur_ary;
 
 326   while ($access =~ m/^([a-z_]+|\||\&|\(|\)|\s+)/) {
 
 328     substr($access, 0, length($1)) = "";
 
 330     next if ($token =~ /\s/);
 
 333       my $new_cur_ary = [];
 
 334       push @stack, $new_cur_ary;
 
 335       push @{$cur_ary}, $new_cur_ary;
 
 336       $cur_ary = $new_cur_ary;
 
 338     } elsif ($token eq ")") {
 
 341         $form->error("Error in menu.ini for entry ${key}: missing '('");
 
 343       $cur_ary = $stack[-1];
 
 345     } elsif (($token eq "|") || ($token eq "&")) {
 
 346       push @{$cur_ary}, $token;
 
 349       push @{$cur_ary}, $auth->check_right($form->{login}, $token, 1);
 
 354     $form->error("Error in menu.ini for entry ${key}: unrecognized token at the start of '$access'\n");
 
 357   if (1 < scalar @stack) {
 
 358     $main::form->error("Error in menu.ini for entry ${key}: Missing ')'\n");
 
 361   return SL::Auth::evaluate_rights_ary($stack[0]);
 
 369   foreach $key (@{ $self->{ORDER} }) {
 
 370     my $entry = $self->{$key};
 
 372     $entry->{GRANTED}              = $entry->{ACCESS} ? $self->parse_access_string($key, $entry->{ACCESS}) : 1;
 
 373     $entry->{IS_MENU}              = $entry->{submenu} || ($key !~ m/--/);
 
 374     $entry->{NUM_VISIBLE_CHILDREN} = 0;
 
 378       substr($parent, rindex($parent, '--')) = '';
 
 379       $entry->{GRANTED} &&= $self->{$parent}->{GRANTED};
 
 382     $entry->{VISIBLE} = $entry->{GRANTED};
 
 385   foreach $key (reverse @{ $self->{ORDER} }) {
 
 386     my $entry = $self->{$key};
 
 388     if ($entry->{IS_MENU}) {
 
 389       $entry->{VISIBLE} &&= $entry->{NUM_VISIBLE_CHILDREN} > 0;
 
 392     next if (($key !~ m/--/) || !$entry->{VISIBLE});
 
 395     substr($parent, rindex($parent, '--')) = '';
 
 396     $self->{$parent}->{NUM_VISIBLE_CHILDREN}++;
 
 399 #   $self->dump_visible();
 
 401   $self->{ORDER} = [ grep { $self->{$_}->{VISIBLE} } @{ $self->{ORDER} } ];
 
 404   # ToDO: fix this. nuke and pave algorithm without type checking screams for problems.
 
 405   map { delete @{$self->{$_}}{qw(GRANTED IS_MENU NUM_VISIBLE_CHILDREN VISIBLE ACCESS)} if ($_ ne 'ORDER') } keys %{ $self };
 
 411   foreach my $key (@{ $self->{ORDER} }) {
 
 412     my $entry = $self->{$key};
 
 413     $main::lxdebug->message(0, "$entry->{GRANTED} $entry->{VISIBLE} $entry->{NUM_VISIBLE_CHILDREN} $key");