This commit was generated by cvs2svn to compensate for changes in r2526,
[freeside.git] / sql-ledger / SL / Menu.pm
1 #=====================================================================
2 # SQL-Ledger Accounting
3 # Copyright (C) 2001
4 #
5 #  Author: Dieter Simader
6 #   Email: dsimader@sql-ledger.org
7 #     Web: http://www.sql-ledger.org
8 #
9 #  Contributors:
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #=====================================================================
24 #
25 # routines for menu items
26 #
27 #=====================================================================
28
29 package Menu;
30
31
32 sub new {
33   my ($type, $menufile, $level) = @_;
34
35   use SL::Inifile;
36   my $self = Inifile->new($menufile, $level);
37   
38   bless $self, $type;
39
40 }
41
42
43 sub menuitem {
44   my ($self, $myconfig, $form, $item) = @_;
45
46   my $module = $form->{script};
47   my $action = "section_menu";
48   my $target = "";
49
50   if ($self->{$item}{module}) {
51     $module = $self->{$item}{module};
52   }
53   if ($self->{$item}{action}) {
54     $action = $self->{$item}{action};
55   }
56   if ($self->{$item}{target}) {
57     $target = $self->{$item}{target};
58   }
59
60   my $level = $form->escape($item);
61   my $str = qq|<a href=$module?path=$form->{path}&action=$action&level=$level&login=$form->{login}&password=$form->{password}|;
62   my @vars = qw(module action target href);
63   
64   if ($self->{$item}{href}) {
65     $str = qq|<a href=$self->{$item}{href}|;
66     @vars = qw(module target href);
67   }
68
69   map { delete $self->{$item}{$_} } @vars;
70   
71   
72   # add other params
73   foreach my $key (keys %{ $self->{$item} }) {
74     $str .= "&".$form->escape($key,1)."=";
75     ($value, $conf) = split /=/, $self->{$item}{$key}, 2;
76     $value = $myconfig->{$value}."/$conf" if ($conf);
77     $str .= $form->escape($value, 1);
78   }
79
80   if ($target) {
81     $str .= qq| target=$target|;
82   }
83
84   $str .= ">";
85   
86 }
87
88
89 sub access_control {
90   my ($self, $myconfig, $menulevel) = @_;
91   
92   my @menu = ();
93
94   if ($menulevel eq "") {
95     @menu = grep { !/--/ } @{ $self->{ORDER} };
96   } else {
97     @menu = grep { /^${menulevel}--/ } @{ $self->{ORDER} };
98   }
99
100   my @a = split /;/, $myconfig->{acs};
101   my $excl = ();
102
103   # remove --AR, --AP from array
104   grep { ($a, $b) = split /--/; s/--$a$//; } @a;
105
106   map { $excl{$_} = 1 } @a;
107
108   @a = ();
109   map { push @a, $_ unless $excl{$_} } (@menu);
110
111   @a;
112
113 }
114
115
116 1;
117