]> wagnertech.de Git - mfinanz.git/blob - bin/mozilla/menu.pl
eb717077e99f8dffe4877de8269b0c537d352594
[mfinanz.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 URI;
44
45 use List::MoreUtils qw(apply);
46
47 my $nbsp     = '&nbsp;';
48
49 # end of main
50
51 sub display {
52   $::lxdebug->enter_sub;
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(doctype => 'frameset');
60
61   print qq|
62 <frameset rows="28px,*" cols="*" framespacing="0" frameborder="0">
63   <frame  src="controller.pl?action=FrameHeader/header" scrolling="NO">
64   <frameset cols="$framesize,*" framespacing="0" frameborder="0" border="0" id="menuframe" name="menuframe">
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   $::lxdebug->leave_sub;
76 }
77
78 sub acc_menu {
79   $::lxdebug->enter_sub;
80
81   my $framesize    = _calc_framesize() - 2;
82   my $menu         = Menu->new("menu.ini");
83   $::form->{title} = $::locale->text('kivitendo');
84   $::form->header;
85
86   my $sections = section_menu($menu);
87
88   print $::form->parse_html_template('menu/menu', {
89     framesize => $framesize,
90     sections  => $sections,
91   });
92
93   $::lxdebug->leave_sub;
94 }
95
96 sub section_menu {
97   $::lxdebug->enter_sub;
98   my ($menu, $level) = @_;
99   my @menuorder = $menu->access_control(\%::myconfig, $level);
100   my @items;
101
102   for my $item (@menuorder) {
103     my $menuitem   = $menu->{$item};
104     my $label      = apply { s/.*--// } $item;
105     my $ml         = apply { s/--.*// } $item;
106     my $spacer     = $nbsp x (($item =~ s/--/--/g) * 2);
107     my $label_icon = $level . "--" . $label . ".png";
108
109     next if $level && $item ne "$level--$label";
110
111     $label         = $::locale->text($label);
112
113     $menuitem->{module} ||= $::form->{script};
114     $menuitem->{action} ||= "section_menu";
115     $menuitem->{target} ||= "main_window";
116     $menuitem->{href}   ||= "$menuitem->{module}?action=$menuitem->{action}";
117
118     # add other params
119     foreach my $key (keys %$menuitem) {
120       next if $key =~ /target|module|action|href/;
121       $menuitem->{href} .= "&" . $::form->escape($key, 1) . "=";
122       my ($value, $conf) = split(/=/, $menuitem->{$key}, 2);
123       $value = $::myconfig{$value} . "/$conf" if ($conf);
124       $menuitem->{href} .= $::form->escape($value, 1);
125     }
126
127     my $anchor = $menuitem->{href};
128
129     if (!$level) { # toplevel
130       push @items, make_item(
131         img      =>  make_image(icon => $item . '.png', size => 24, label => $label),
132         label    => $label,
133         height   => 24,
134         class    => 'menu',
135         subitems => section_menu($menu, $item)
136       );
137     } elsif ($menuitem->{submenu}) {
138       push @items, make_item(
139         target   => $menuitem->{target},
140         spacer   => $spacer,
141         img      => make_image(submenu => 1),
142         label    => $label,
143         class    => 'submenu',
144         subitems => section_menu($menu, $item),
145       );
146     } elsif ($menuitem->{module}) {
147       push @items, make_item(
148         target => $menuitem->{target},
149         img    => make_image(label => $label, icon => $label_icon),
150         href   => $anchor,
151         spacer => $spacer,
152         label  => $label,
153         class  => 'item',
154       );
155     }
156   }
157   $::lxdebug->leave_sub;
158   return \@items;
159 }
160
161 sub make_item {
162   my %params = @_;
163   $params{spacer} ||= '';
164   $params{height} ||= 16;
165
166   return {
167     %params,
168     chunks => [ multiline($params{label}) ],
169   };
170 }
171
172 # multi line hack, sschoeling jul06
173 # if a label is too long, try to split it at whitespaces, then join it to chunks of less
174 # than 20 chars and store it in an array.
175 # use this array later instead of the &nbsp;-ed label
176 sub multiline {
177   my ($label) = @_;
178   my @chunks;
179   my $l = 20;
180   for (split / /, $label) {
181     $l += length $_;
182     if ($l < 20) {
183       $chunks[-1] .= " $_";
184     } else {
185       $l = length $_;
186       push @chunks, $_;
187     }
188   }
189   return @chunks;
190 }
191
192 sub make_image {
193   my (%params) = @_;
194
195   my $icon   = $params{icon};
196   my $size   = $params{size}   || 16;
197
198   return unless _show_images();
199
200   my $icon_found = $icon && -f _icon_path($icon, $size);
201   my $padding    = $size == 16 && $icon_found ? $nbsp x 2
202                  : $size == 24                ? $nbsp
203                  :                            '';
204
205   return  {
206     src     => $icon_found ? _icon_path($icon, $size) : "image/unterpunkt.png",
207     alt     => $params{label},
208     width   => $icon_found ? $size : 24,
209     height  => $size,
210   }
211 }
212
213 sub _calc_framesize {
214   my $is_lynx_browser   = $ENV{HTTP_USER_AGENT} =~ /links/i;
215   my $is_mobile_browser = $ENV{HTTP_USER_AGENT} =~ /mobile/i;
216   my $is_mobile_style   = $::form->{stylesheet} =~ /mobile/i;
217
218   return  $is_mobile_browser && $is_mobile_style ?  130
219         : $is_lynx_browser                       ?  240
220         :                                           200;
221 }
222
223 sub _show_images {
224   # don't show images in links
225   _calc_framesize() != 240;
226 }
227
228 sub _icon_path {
229   my ($label, $size) = @_;
230
231   $size ||= 16;
232
233   return "image/icons/${size}x${size}/$label";
234 }
235
236 1;
237
238 __END__