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