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