unstable-Zweig als Kopie des "alten" trunks erstellt.
[kivitendo-erp.git] / SL / Menu.pm
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (C) 2001
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #  Contributors:
16 #
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.
21
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 #=====================================================================
30 #
31 # routines for menu items
32 #
33 #=====================================================================
34
35 package Menu;
36
37
38 sub new {
39   $main::lxdebug->enter_sub();
40
41   my ($type, $menufile, $level) = @_;
42
43   use SL::Inifile;
44   my $self = Inifile->new($menufile, $level);
45   
46   $main::lxdebug->leave_sub();
47
48   bless $self, $type;
49 }
50
51
52 sub menuitem {
53   $main::lxdebug->enter_sub();
54
55   my ($self, $myconfig, $form, $item) = @_;
56
57   my $module = $form->{script};
58   my $action = "section_menu";
59   my $target = "";
60
61   if ($self->{$item}{module}) {
62     $module = $self->{$item}{module};
63   }
64   if ($self->{$item}{action}) {
65     $action = $self->{$item}{action};
66   }
67   if ($self->{$item}{target}) {
68     $target = $self->{$item}{target};
69   }
70
71   my $level = $form->escape($item);
72   my $str = qq|<a href=$module?path=$form->{path}&action=$action&level=$level&login=$form->{login}&password=$form->{password}|;
73   my @vars = qw(module action target href);
74   
75   if ($self->{$item}{href}) {
76     $str = qq|<a href=$self->{$item}{href}|;
77     @vars = qw(module target href);
78   }
79
80   map { delete $self->{$item}{$_} } @vars;
81   
82   
83   # add other params
84   foreach my $key (keys %{ $self->{$item} }) {
85     $str .= "&".$form->escape($key,1)."=";
86     ($value, $conf) = split /=/, $self->{$item}{$key}, 2;
87     $value = $myconfig->{$value}."/$conf" if ($conf);
88     $str .= $form->escape($value, 1);
89   }
90
91   if ($target) {
92     $str .= qq| target=$target|;
93   }
94
95   $str .= ">";
96
97   $main::lxdebug->leave_sub();
98
99   return $str;
100 }
101
102
103 sub access_control {
104   $main::lxdebug->enter_sub();
105
106   my ($self, $myconfig, $menulevel) = @_;
107   
108   my @menu = ();
109
110   if ($menulevel eq "") {
111     @menu = grep { !/--/ } @{ $self->{ORDER} };
112   } else {
113     @menu = grep { /^${menulevel}--/ } @{ $self->{ORDER} };
114   }
115
116   my @a = split /;/, $myconfig->{acs};
117   my $excl = ();
118
119   # remove --AR, --AP from array
120   grep { ($a, $b) = split /--/; s/--$a$//; } @a;
121
122   map { $excl{$_} = 1 } @a;
123
124   @a = ();
125   map { push @a, $_ unless $excl{$_} } (@menu);
126
127   $main::lxdebug->leave_sub();
128
129   return @a;
130 }
131
132
133 1;
134