1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 ######################################################################
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
15 # Contributors: Christopher Browne
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.
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 #######################################################################
31 # the frame layout with refractured menu
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 #######################################################################
46 use List::MoreUtils qw(apply);
48 my $menufile = "menu.ini";
55 $::lxdebug->enter_sub;
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 my $framesize = _calc_framesize();
62 $::form->header(doctype => 'frameset');
65 <frameset rows="28px,*" cols="*" framespacing="0" frameborder="0">
66 <frame src="controller.pl?action=FrameHeader/header" scrolling="NO">
67 <frameset cols="$framesize,*" framespacing="0" frameborder="0" border="0" id="menuframe" name="menuframe">
68 <frame src="$::form->{script}?action=acc_menu" name="acc_menu" scrolling="auto" noresize marginwidth="0">
69 <frame src="$callback" name="main_window" scrolling="auto">
72 You need a browser that can read frames to see this page.
78 $::lxdebug->leave_sub;
82 $::lxdebug->enter_sub;
84 my $framesize = _calc_framesize() - 2;
85 my $menu = Menu->new("menu.ini");
86 $mainlevel = $::form->{level};
87 $::form->{title} = $::locale->text('kivitendo');
90 print $::form->parse_html_template('menu/menu', {
91 framesize => $framesize,
92 sections => [ section_menu($menu) ],
95 $::lxdebug->leave_sub;
99 $::lxdebug->enter_sub;
100 my ($menu, $level) = @_;
101 my @menuorder = $menu->access_control(\%::myconfig, $level);
104 for my $item (@menuorder) {
105 my $menuitem = $menu->{$item};
106 my $label = apply { s/.*--// } $item;
107 my $ml = apply { s/--.*// } $item;
108 my $show = $ml eq $mainlevel;
109 my $spacer = $nbsp x (($item =~ s/--/--/g) * 2);
110 my $label_icon = $level . "--" . $label . ".png";
112 next if $level && $item ne "$level--$label";
114 $label = $::locale->text($label);
118 my $anchor = $menuitem->{href};
120 if (!$level) { # toplevel
121 my $ml_ = $::form->escape($ml);
122 my $image = make_image(icon => $item . '.png', size => 24, label => $label);
123 my $anchor = "menu.pl?action=acc_menu&level=$ml_";
125 push @items, make_item(href => $anchor, img => $image, label => $label, height => 24, class => 'menu');
126 push @items, section_menu($menu, $item);
128 } elsif ($menuitem->{submenu}) {
129 my $image = make_image(submenu => 1);
130 if ($mainlevel && $item =~ /^\Q$mainlevel\E/) {
131 push @items, make_item(target => $menuitem->{target}, spacer => $spacer, bold => 1, img => $image, label => $label, class => 'submenu') if $show;
132 push @items, section_menu($menu, $item);
134 push @items, make_item(spacer => $spacer, href => $anchor, img => $image, label => $label . ' ...', class => 'submenu') if $show;
136 } elsif ($menuitem->{module}) {
137 my $image = make_image(label => $label, icon => $label_icon);
138 push @items, make_item(target => $menuitem->{target}, img => $image, href => $anchor, spacer => $spacer, label => $label, class => 'item') if $show;
139 push @items, section_menu($menu, $item) if $show && $::form->{$item} && $::form->{level} eq $item;
142 $::lxdebug->leave_sub;
147 my ($item, $name) = @_;
149 $item->{module} ||= $::form->{script};
150 $item->{action} ||= "section_menu";
151 $item->{target} ||= "main_window";
152 $item->{href} ||= "$item->{module}?action=$item->{action}";
155 foreach my $key (keys %$item) {
156 next if $key =~ /target|module|action|href/;
157 $item->{href} .= "&" . $::form->escape($key, 1) . "=";
158 my ($value, $conf) = split(/=/, $item->{$key}, 2);
159 $value = $::myconfig{$value} . "/$conf" if ($conf);
160 $item->{href} .= $::form->escape($value, 1);
163 # my $str = "<a href='$href' $target_token>";
171 $params{spacer} ||= '';
172 $params{height} ||= 16;
176 chunks => [ multiline($params{label}) ],
180 # multi line hack, sschoeling jul06
181 # if a label is too long, try to split it at whitespaces, then join it to chunks of less
182 # than 20 chars and store it in an array.
183 # use this array later instead of the -ed label
188 for (split / /, $label) {
191 $chunks[-1] .= " $_";
203 my $label = $params{label};
204 my $icon = $params{icon};
205 my $size = $params{size} || 16;
207 return unless _show_images();
209 my $icon_found = $icon && -f _icon_path($icon, $size);
211 my $image_url = $icon_found ? _icon_path($icon, $size) : "image/unterpunkt.png";
212 my $width = $icon_found ? $size : 24;
214 my $padding = $size == 16 && $icon_found ? $nbsp x 2
215 : $size == 24 ? $nbsp
218 return "<img src='$image_url' alt='$label' width='$width' height='$size'>$padding";
221 sub _calc_framesize {
222 my $is_lynx_browser = $ENV{HTTP_USER_AGENT} =~ /links/i;
223 my $is_mobile_browser = $ENV{HTTP_USER_AGENT} =~ /mobile/i;
224 my $is_mobile_style = $::form->{stylesheet} =~ /mobile/i;
226 return $is_mobile_browser && $is_mobile_style ? 130
227 : $is_lynx_browser ? 240
232 # don't show images in links
233 _calc_framesize() != 240;
237 my ($label, $size) = @_;
241 return "image/icons/${size}x${size}/$label";