af860fd155b0fdf08ad3ddeb1650192dd38fb2f4
[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 URI;
44
45 use List::MoreUtils qw(apply);
46
47 # end of main
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   my $framesize = _calc_framesize();
56
57   $::form->header(doctype => 'frameset');
58
59   print qq|
60 <frameset rows="28px,*" cols="*" framespacing="0" frameborder="0">
61   <frame  src="controller.pl?action=FrameHeader/header" scrolling="NO">
62   <frameset cols="$framesize,*" framespacing="0" frameborder="0" border="0" id="menuframe" name="menuframe">
63     <frame src="$::form->{script}?action=acc_menu" name="acc_menu"  scrolling="auto" noresize marginwidth="0">
64     <frame src="$callback" name="main_window" scrolling="auto">
65   </frameset>
66   <noframes>
67   You need a browser that can read frames to see this page.
68   </noframes>
69 </frameset>
70 </HTML>
71 |;
72
73   $::lxdebug->leave_sub;
74 }
75
76 sub acc_menu {
77   $::lxdebug->enter_sub;
78
79   $::form->{stylesheet} = [ qw(css/icons16.css css/icons24.css ) ];
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, $id_prefix) = @_;
99   my @menuorder = $menu->access_control(\%::myconfig, $level);
100   my @items;
101
102   my $id = 0;
103
104   for my $item (@menuorder) {
105     my $menuitem   = $menu->{$item};
106     my $olabel     = apply { s/.*--// } $item;
107     my $ml         = apply { s/--.*// } $item;
108     my $icon_class = apply { y/ /-/   } $item;
109     my $spacer     = "s" . (0 + $item =~ s/--/--/g);
110
111     next if $level && $item ne "$level--$olabel";
112
113     my $label         = $::locale->text($olabel);
114
115     $menuitem->{module} ||= $::form->{script};
116     $menuitem->{action} ||= "section_menu";
117     $menuitem->{target} ||= "main_window";
118     $menuitem->{href}   ||= "$menuitem->{module}?action=$menuitem->{action}";
119
120     # add other params
121     foreach my $key (keys %$menuitem) {
122       next if $key =~ /target|module|action|href/;
123       $menuitem->{href} .= "&" . $::form->escape($key, 1) . "=";
124       my ($value, $conf) = split(/=/, $menuitem->{$key}, 2);
125       $value = $::myconfig{$value} . "/$conf" if ($conf);
126       $menuitem->{href} .= $::form->escape($value, 1);
127     }
128
129     my $anchor = $menuitem->{href};
130
131     my %common_args = (
132         l   => $label,
133         s  => $spacer,
134         t  => $menuitem->{target},
135         id => "$id_prefix\_$id",
136         height  => 16,
137     );
138
139     if (!$level) { # toplevel
140       push @items, { %common_args,
141         i      => "icon24 $icon_class",   #  make_image(size => 24, label => $item),
142         c    => 'm',
143       };
144       push @items, section_menu($menu, $item, "$id_prefix\_$id");
145     } elsif ($menuitem->{submenu}) {
146       push @items, { %common_args,
147         i      => "icon16 submenu",   #make_image(label => 'submenu'),
148         c    => 'sm',
149       };
150       push @items, section_menu($menu, $item, "$id_prefix\_$id");
151     } elsif ($menuitem->{module}) {
152       push @items, { %common_args,
153         i     => "icon16 $icon_class",  #make_image(size => 16, label => $item),
154         h    => $anchor,
155         c   => 'i',
156       };
157     }
158   } continue {
159     $id++;
160   }
161
162   $::lxdebug->leave_sub;
163   return @items;
164 }
165
166 sub _calc_framesize {
167   my $is_lynx_browser   = $ENV{HTTP_USER_AGENT} =~ /links/i;
168   my $is_mobile_browser = $ENV{HTTP_USER_AGENT} =~ /mobile/i;
169   my $is_mobile_style   = $::form->{stylesheet} =~ /mobile/i;
170
171   return  $is_mobile_browser && $is_mobile_style ?  130
172         : $is_lynx_browser                       ?  240
173         :                                           200;
174 }
175
176 sub _show_images {
177   # don't show images in links
178   _calc_framesize() != 240;
179 }
180
181 1;
182
183 __END__