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