Zweiter Anlauf: Das (linksseitige) HTML-MenĂ¼ komaptibel zum Textbrowser Links gemacht.
[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 # the 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 #  2010-08-19 - Icons for sub entries and single click behavior, unlike XUL-Menu
37 #               JS switchable HTML-menu - Sven Donath <lxo@dexo.de>
38 #######################################################################
39
40 use strict;
41
42 use SL::Menu;
43 use Data::Dumper;
44 use URI;
45
46 my $menufile = "menu.ini";
47 my $mainlevel;
48
49 # end of main
50
51 sub display {
52   $main::lxdebug->enter_sub();
53
54   my $form      = $main::form;
55
56   my $callback  = $form->unescape($form->{callback});
57   $callback     = URI->new($callback)->rel($callback) if $callback;
58   $callback     = "login.pl?action=company_logo"      if $callback =~ /^(\.\/)?$/;
59   my $framesize = _calc_framesize();
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" id="menuframe" name="menuframe">
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   my $framesize = _calc_framesize();
86
87   $mainlevel = $form->{level};
88   $mainlevel =~ s/\Q$mainlevel\E--//g;
89   my $menu = Menu->new($::menufile);
90
91   $form->{title} = $locale->text('Lx-Office');
92
93   $form->header;
94
95   print qq|
96 <body class="menu">
97  
98 |; 
99   print qq|<div align="left">\n<table width="|
100     . ($framesize-2)
101     . qq|" border="0">\n|;
102
103   &section_menu($menu);
104
105   print qq|</table></div>|;
106   print qq|
107 </body>
108 </html>
109 |;
110
111   $main::lxdebug->leave_sub();
112 }
113
114 sub section_menu {
115   $main::lxdebug->enter_sub();
116   my ($menu, $level) = @_;
117
118   my $form      = $main::form;
119   my %myconfig  = %main::myconfig;
120   my $locale    = $main::locale;
121   my $is_links_browser = 1;
122   if ( _calc_framesize() eq 240) { $is_links_browser = 0; }
123
124   my $zeige;
125
126   # build tiered menus
127   my @menuorder = $menu->access_control(\%myconfig, $level);
128   while (@menuorder) {
129     my $item  = shift @menuorder;
130     my $label = $item;
131     my $ml    = $item;
132     $label =~ s/\Q$level\E--//g;
133     $ml    =~ s/--.*//;
134     if ($ml eq $mainlevel) { $zeige = 1; }
135     else { $zeige = 0; }
136     my $spacer = "&nbsp;" x (($item =~ s/--/--/g) * 2);
137     $label =~ s/.*--//g;
138     my $label_icon = $level . "--" . $label . ".png";
139     my $mlab       = $label;
140     $label      = $locale->text($label);
141
142     # multi line hack, sschoeling jul06
143     # if a label is too long, try to split it at whitespaces, then join it to chunks of less
144     # than 20 chars and store it in an array.
145     # use this array later instead of the &nbsp;-ed label
146     my @chunks = ();
147     my ($i,$l) = (-1, 20);
148     map {
149       if (($l += length $_) < 20) {
150         $chunks[$i] .= " $_";
151       } else {
152         $l = length $_;
153         $chunks[++$i] = $_;
154
155       }
156     } split / /, $label;
157     map { s/ /&nbsp;/ } @chunks;
158     # end multi line
159
160     $label =~ s/ /&nbsp;/g;
161     $menu->{$item}{target} = "main_window" unless $menu->{$item}{target};
162
163     if ($menu->{$item}{submenu}) {
164       $menu->{$item}{$item} = !$form->{$item};
165       if ($form->{level} && $item =~ /^\Q$form->{level}\E/) {
166
167         # expand menu
168         if ($zeige) {
169           print
170             qq|<tr><td style='vertical-align:bottom'><b>$spacer<img src="image/unterpunkt.png">$label</b></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           print qq|<tr><td>|
179             . $menu->menuitem(\%myconfig, \%$form, $item, $level)
180             . qq|$label&nbsp;...</a></td></tr>\n|;
181         }
182
183         # remove same level items
184         map { shift @menuorder } grep /^$item/, @menuorder;
185       }
186     } else {
187       if ($menu->{$item}{module}) {
188         if ($form->{$item} && $form->{level} eq $item) {
189           $menu->{$item}{$item} = !$form->{$item};
190           if ($zeige) {
191             print
192               qq|<tr><td valign=bottom>$spacer<img src="image/unterpunkt.png">|
193               . $menu->menuitem(\%myconfig, \%$form, $item, $level)
194               . qq|$label</a></td></tr>\n|;
195           }
196
197           # remove same level items
198           map { shift @menuorder } grep /^$item/, @menuorder;
199           &section_menu($menu, $item);
200         } else {
201           if ($zeige) {
202             if (scalar @chunks <= 1) {
203               print
204                 qq|<tr><td class="hover" height="16" >$spacer|
205                 . $menu->menuitem(\%myconfig, \%$form, $item, $level) ;
206
207             if (-f "image/icons/16x16/$label_icon" && ($is_links_browser))
208              { print
209                 qq|<img src="image/icons/16x16/$label_icon" border="0" style="vertical-align:text-top" title="|
210                 . $label
211                 . qq|">&nbsp;&nbsp;| }
212             else {
213                    if ($is_links_browser) {
214                     print qq|<img src="image/unterpunkt.png" border="0" style="vertical-align:text-top">|;
215                    }
216                 }
217
218                print
219                  qq|$label</a></td></tr>\n|;
220             } else {
221               my $tmpitem = $menu->menuitem(\%myconfig, \%$form, $item, $level);
222               print
223                 qq|<tr><td class="hover" height="16" >$spacer<img src="image/unterpunkt.png"  style="vertical-align:text-top">|
224                 . $tmpitem
225                 . qq|$chunks[0]</a></td></tr>\n|;
226               map {
227                 print
228                   qq|<tr style="vertical-align:top""><td class="hover">$spacer<img src="image/unterpunkt.png" style="visibility:hidden; width:24; height=2;">|
229                   . $tmpitem
230                   . qq|$chunks[$_]</a></td></tr>\n|;
231               } 1..$#chunks;
232             }
233           }
234         }
235       } else {
236         my $ml_ = $form->escape($ml);
237         print
238           qq|<tr><td class="bg" height="24" align="left" valign="middle">
239           <a href="menu.pl?action=acc_menu&level=$ml_" class="nohover" title="$label">|;
240               if ($is_links_browser) {
241                   print qq|<img src="image/icons/24x24/$item.png" border="0" style="vertical-align:middle" title="$label">|;
242               }
243           print qq|&nbsp;$label</a>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>\n|;
244         &section_menu($menu, $item);
245
246         print qq|\n|;
247       }
248     }
249   }
250   $main::lxdebug->leave_sub();
251 }
252
253 sub _calc_framesize {
254   my $is_lynx_browser   = $ENV{HTTP_USER_AGENT} =~ /links/i;
255   my $is_mobile_browser = $ENV{HTTP_USER_AGENT} =~ /mobile/i;
256   my $is_mobile_style   = $::form->{stylesheet} =~ /mobile/i;
257
258   return  $is_mobile_browser && $is_mobile_style ?  130
259         : $is_lynx_browser                       ?  240
260         :                                           200;
261 }
262
263 1;
264
265 __END__