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