Uebernahme der kompletten Version, so wie sie Philip als "Demo-Version" gezeigt hat...
[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 sub new {
38   $main::lxdebug->enter_sub();
39
40   my ($type, $menufile, $level) = @_;
41
42   use SL::Inifile;
43   my $self = Inifile->new($menufile, $level);
44
45   $main::lxdebug->leave_sub();
46
47   bless $self, $type;
48 }
49
50 sub menuitem {
51   $main::lxdebug->enter_sub();
52
53   my ($self, $myconfig, $form, $item) = @_;
54
55   my $module = $form->{script};
56   my $action = "section_menu";
57   my $target = "";
58
59   if ($self->{$item}{module}) {
60     $module = $self->{$item}{module};
61   }
62   if ($self->{$item}{action}) {
63     $action = $self->{$item}{action};
64   }
65   if ($self->{$item}{target}) {
66     $target = $self->{$item}{target};
67   }
68
69   my $level = $form->escape($item);
70
71   my $str =
72     qq|<a style="vertical-align:top" href=$module?path=$form->{path}&action=$action&level=$level&login=$form->{login}&password=$form->{password}|;
73
74   my @vars = qw(module action target href);
75
76   if ($self->{$item}{href}) {
77     $str  = qq|<a href=$self->{$item}{href}|;
78     @vars = qw(module target href);
79   }
80
81   map { delete $self->{$item}{$_} } @vars;
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 sub menuitemNew {
103   my ($self, $myconfig, $form, $item) = @_;
104
105   my $module = $form->{script};
106   my $action = "section_menu";
107
108   #if ($self->{$item}{module}) {
109   $module = $self->{$item}{module};
110
111   #}
112   if ($self->{$item}{action}) {
113     $action = $self->{$item}{action};
114   }
115
116   my $level = $form->escape($item);
117   my $str   =
118     qq|$module?path=$form->{path}&action=$action&level=$level&login=$form->{login}&password=$form->{password}|;
119   my @vars = qw(module action target href);
120
121   if ($self->{$item}{href}) {
122     $str  = qq|$self->{$item}{href}|;
123     @vars = qw(module target href);
124   }
125
126   map { delete $self->{$item}{$_} } @vars;
127
128   # add other params
129   foreach my $key (keys %{ $self->{$item} }) {
130     $str .= "&" . $form->escape($key, 1) . "=";
131     ($value, $conf) = split /=/, $self->{$item}{$key}, 2;
132     $value = $myconfig->{$value} . "/$conf" if ($conf);
133     $str .= $form->escape($value, 1);
134   }
135
136   $str .= " ";
137
138 }
139
140 sub access_control {
141   $main::lxdebug->enter_sub(2);
142
143   my ($self, $myconfig, $menulevel) = @_;
144
145   my @menu = ();
146
147   if ($menulevel eq "") {
148     @menu = grep { !/--/ } @{ $self->{ORDER} };
149   } else {
150     @menu = grep { /^${menulevel}--/ } @{ $self->{ORDER} };
151   }
152
153   my @a    = split /;/, $myconfig->{acs};
154   my $excl = ();
155
156   # remove --AR, --AP from array
157   grep { ($a, $b) = split /--/; s/--$a$//; } @a;
158
159   map { $excl{$_} = 1 } @a;
160
161   @a = ();
162   map { push @a, $_ unless $excl{$_} } (@menu);
163
164   $main::lxdebug->leave_sub(2);
165
166   return @a;
167 }
168
169 sub generate_acl {
170   my ($self, $menulevel, $hash) = @_;
171
172   my @items = $self->access_control(\%main::myconfig, $menulevel);
173
174   $menulevel =~ s/[^A-Za-z_\/\.\+\-]/_/g;
175   $hash->{"access_" . lc($menulevel)} = 1 if ($menulevel);
176
177   foreach my $item (@items) {
178     $self->generate_acl($item, $hash); #unless ($menulevel);
179   }
180 }
181
182 1;
183