This commit was generated by cvs2svn to compensate for changes in r4407,
[freeside.git] / sql-ledger / SL / Menu.pm
1 #=====================================================================
2 # SQL-Ledger Accounting
3 # Copyright (C) 2002
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 if $self;
39
40 }
41
42
43 sub menuitem {
44   my ($self, $myconfig, $form, $item, $level) = @_;
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   $level = $form->escape($item);
61   my $str = qq|<a href=$module?path=$form->{path}&action=$action&level=$level&login=$form->{login}&timeout=$form->{timeout}&sessionid=$form->{sessionid}|;
62
63   my @vars = qw(module action target href);
64   
65   if ($self->{$item}{href}) {
66     $str = qq|<a href=$self->{$item}{href}|;
67     @vars = qw(module target href);
68   }
69
70   map { delete $self->{$item}{$_} } @vars;
71   
72   delete $self->{$item}{submenu};
73  
74   # add other params
75   foreach my $key (keys %{ $self->{$item} }) {
76     $str .= "&".$form->escape($key)."=";
77     ($value, $conf) = split /=/, $self->{$item}{$key}, 2;
78     $value = $myconfig->{$value}."/$conf" if ($conf);
79     $str .= $form->escape($value);
80   }
81
82   $str .= qq|#id$form->{tag}| if $target eq 'acc_menu';
83   
84   if ($target) {
85     $str .= qq| target=$target|;
86   }
87   
88   $str .= qq|>|;
89   
90 }
91
92
93 sub access_control {
94   my ($self, $myconfig, $menulevel) = @_;
95   
96   my @menu = ();
97
98   if ($menulevel eq "") {
99     @menu = grep { !/--/ } @{ $self->{ORDER} };
100   } else {
101     @menu = grep { /^${menulevel}--/ } @{ $self->{ORDER} };
102   }
103
104   my @a = split /;/, $myconfig->{acs};
105   my $excl = ();
106
107   # remove --AR, --AP from array
108   grep { ($a, $b) = split /--/; s/--$a$//; } @a;
109
110   map { $excl{$_} = 1 } @a;
111
112   @a = ();
113   map { push @a, $_ unless $excl{$_} } (@menu);
114
115   @a;
116
117 }
118
119
120 1;
121