121f8b4a468ff20deb514a96a661fd10dd0ac273
[kivitendo-erp.git] / bin / mozilla / menu.pl
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) 1998-2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #  Contributors: Christopher Browne
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 # thre frame layout with refractured menu
32 #
33 # CHANGE LOG:
34 #   DS. 2002-03-25  Created
35 #  2004-12-14 - New Optik - Marco Welter <mawe@linux-studio.de>
36 #######################################################################
37
38 $menufile = "menu.ini";
39 use SL::Menu;
40 use Data::Dumper;
41
42 1;
43
44 # end of main
45
46 $framesize = ($ENV{HTTP_USER_AGENT} =~ /links/i) ? "240" : "190";
47
48 sub display {
49   $lxdebug->enter_sub();
50
51   $form->header;
52
53   print qq|
54 <frameset rows="28px,*" cols="*" framespacing="0" frameborder="0">
55   <frame  src="kopf.pl?login=$form->{login}&password=$form->{password}" name="kopf"  scrolling="NO">
56   <frameset cols="$framesize,*" framespacing="0" frameborder="0" border="0" >
57     <frame src="$form->{script}?login=$form->{login}&password=$form->{password}&action=acc_menu" name="acc_menu"  scrolling="auto" noresize marginwidth="0">
58     <frame src="login.pl?login=$form->{login}&password=$form->{password}&action=company_logo" name="main_window" scrolling="auto">
59   </frameset>
60   <noframes>
61   You need a browser that can read frames to see this page.
62   </noframes>
63 </frameset>
64 </HTML>
65 |;
66
67   $lxdebug->leave_sub();
68 }
69
70 sub acc_menu {
71   $lxdebug->enter_sub();
72   $mainlevel = $form->{level};
73   $mainlevel =~ s/\Q$mainlevel\E--//g;
74   my $menu = new Menu "$menufile";
75
76   $form->{title} = $locale->text('Accounting Menu');
77
78   $form->header;
79
80   print qq|
81 <body class="menu">
82
83 |;
84   print qq|<div align="left">\n<table width="|
85     . $framesize
86     . qq|" border=0>\n|;
87
88   &section_menu($menu);
89
90   print qq|</table></div>|;
91   print qq|
92 </body>
93 </html>
94 |;
95
96   $lxdebug->leave_sub();
97 }
98
99 sub section_menu {
100   $lxdebug->enter_sub();
101   my ($menu, $level) = @_;
102
103   # build tiered menus
104   my @menuorder = $menu->access_control(\%myconfig, $level);
105   while (@menuorder) {
106     $item  = shift @menuorder;
107     $label = $item;
108     $ml    = $item;
109     $label =~ s/\Q$level\E--//g;
110     $ml    =~ s/--.*//;
111     if ($ml eq $mainlevel) { $zeige = 1; }
112     else { $zeige = 0; }
113     my $spacer = "&nbsp;" x (($item =~ s/--/--/g) * 1);
114     $label =~ s/.*--//g;
115     $label_icon = $label . ".gif";
116     $mlab       = $label;
117     $label      = $locale->text($label);
118  
119     # multi line hack, sschoeling jul06
120     # if a label is too long, try to split it at whitespaces, then join it to chunks of less 
121     # than 20 chars and store it in an array.
122     # use this array later instead of the &nbsp;-ed label
123     @chunks = ();
124     my ($i,$l) = (-1, 20);
125     map {
126       if (($l += length $_) < 20) {
127         $chunks[$i] .= " $_";
128       } else { 
129         $l = length $_; 
130         $chunks[++$i] = $_; 
131       }
132     } split / /, $label;
133     map { s/ /&nbsp;/ } @chunks;
134     # end multi line
135
136     $label =~ s/ /&nbsp;/g;
137     $menu->{$item}{target} = "main_window" unless $menu->{$item}{target};
138
139     if ($menu->{$item}{submenu}) {
140       $menu->{$item}{$item} = !$form->{$item};
141       if ($form->{level} && $item =~ /^\Q$form->{level}\E/) {
142
143         # expand menu
144         if ($zeige) {
145           print
146             qq|<tr><td valign=bottom><b>$spacer<img src="image/unterpunkt.png">$label</b></td></tr>\n|;
147         }
148
149         # remove same level items
150         map { shift @menuorder } grep /^$item/, @menuorder;
151         &section_menu($menu, $item);
152       } else {
153         if ($zeige) {
154           print qq|<tr><td>|
155             . $menu->menuitem(\%myconfig, \%$form, $item, $level)
156             . qq|$label&nbsp;...</a></td></tr>\n|;
157         }
158
159         # remove same level items
160         map { shift @menuorder } grep /^$item/, @menuorder;
161       }
162     } else {
163       if ($menu->{$item}{module}) {
164         if ($form->{$item} && $form->{level} eq $item) {
165           $menu->{$item}{$item} = !$form->{$item};
166           if ($zeige) {
167             print
168               qq|<tr><td valign=bottom>$spacer<img src="image/unterpunkt.png">|
169               . $menu->menuitem(\%myconfig, \%$form, $item, $level)
170               . qq|$label</a></td></tr>\n|;
171           }
172
173           # remove same level items
174           map { shift @menuorder } grep /^$item/, @menuorder;
175           &section_menu($menu, $item);
176         } else {
177           if ($zeige) {
178             if (scalar @chunks <= 1) {
179               print
180                 qq|<tr><td class="hover" height="13" >$spacer<img src="image/unterpunkt.png"  style="vertical-align:text-top">|
181                 . $menu->menuitem(\%myconfig, \%$form, $item, $level)
182                 . qq|$label</a></td></tr>\n|;
183             } else {
184               my $tmpitem = $menu->menuitem(\%myconfig, \%$form, $item, $level);
185               print
186                 qq|<tr><td class="hover" height="13" >$spacer<img src="image/unterpunkt.png"  style="vertical-align:text-top">|
187                 . $tmpitem
188                 . qq|$chunks[0]</a></td></tr>\n|;
189               map {
190                 print
191                   qq|<tr style="vertical-align:top""><td class="hover">$spacer<img src="image/unterpunkt.png" style="visibility:hidden; width:23; height=2;">|
192                   . $tmpitem
193                   . qq|$chunks[$_]</a></td></tr>\n|;
194               } 1..$#chunks;
195             }
196           }
197         }
198       } else {
199         my $ml_ = $form->escape($ml);
200         print
201           qq|<tr><td class="bg" height="22" align="left" valign="middle" ><img src="image/$item.png" style="vertical-align:middle">&nbsp;<a href="menu.pl?action=acc_menu&level=$ml_&login=$form->{login}&password=$form->{password}" class="nohover">$label</a>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>\n|;
202         &section_menu($menu, $item);
203
204         #print qq|<br>\n|;
205       }
206     }
207   }
208   $lxdebug->leave_sub();
209 }