Endlose Rekursionen via call_sub vermeiden.
[kivitendo-erp.git] / bin / mozilla / menujs.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 - Holger Lindemann
36 #######################################################################
37
38 my $menufile = "menu.ini";
39 use SL::Menu;
40 use CGI::Carp qw(fatalsToBrowser);
41
42 use strict;
43
44 my $locale;
45
46 1;
47
48 # end of main
49
50 sub display {
51
52   my $form     = $main::form;
53
54   $form->{callback}   = $form->unescape($form->{callback});
55   $form->{callback} ||= "login.pl?action=company_logo";
56
57   $form->header;
58
59   &clock_line;
60
61   &acc_menu;
62
63   print qq|
64 <iframe id="win1" src="$form->{callback}" width="100%" height="93%" name="main_window" style="position: absolute; border:0px;">
65 <p>Ihr Browser kann leider keine eingebetteten Frames anzeigen.
66 </p>
67 </iframe>
68 </body>
69 </html>
70
71 |;
72
73 }
74
75 sub clock_line {
76
77   my $form     = $main::form;
78
79   my $fensterlink="menujs.pl?action=display";
80   my $fenster = "["."<a href=\"$fensterlink\" target=\"_blank\">neues Fenster</a>]";
81
82   my $login = "[Nutzer "
83     . $form->{login}
84     . " - <a href=\"login.pl?action=logout\" target=\"_top\">"
85     . $locale->text('Logout')
86     . "</a>] ";
87   my ($Sekunden, $Minuten,   $Stunden,   $Monatstag, $Monat,
88       $Jahr,     $Wochentag, $Jahrestag, $Sommerzeit)
89     = localtime(time);
90   my $CTIME_String = localtime(time);
91   $Monat     += 1;
92   $Jahrestag += 1;
93   $Monat     = $Monat < 10     ? $Monat     = "0" . $Monat     : $Monat;
94   $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag;
95   $Jahr += 1900;
96   my @Wochentage = ("Sonntag",    "Montag",  "Dienstag", "Mittwoch",
97                     "Donnerstag", "Freitag", "Samstag");
98   my @Monatsnamen = ("",       "Januar",    "Februar", "M&auml;rz",
99                      "April",  "Mai",       "Juni",    "Juli",
100                      "August", "September", "Oktober", "November",
101                      "Dezember");
102   my $datum =
103       $Wochentage[$Wochentag] . ", der "
104     . $Monatstag . "."
105     . $Monat . "."
106     . $Jahr . " - ";
107
108   #$zeit="<div id='Uhr'>".$Stunden.":".$Minuten.":".$Sekunden."</div>";
109   my $zeit = "<div id='Uhr'>" . $Stunden . ":" . $Minuten . "</div>";
110   print qq|
111 <script type="text/javascript">
112 <!--
113 function clockon() {
114   var now = new Date();
115   var h = now.getHours();
116   var m = now.getMinutes();
117   document.getElementById('clock_id').innerHTML = (h<10?'0'+h:h)+":"+(m<10?'0'+m:m);
118   var timer=setTimeout("clockon()", 10000);
119 }
120 window.onload=clockon
121 //-->
122 </script>
123 <table border="0" width="100%" background="image/bg_titel.gif" cellpadding="0" cellspacing="0">
124   <tr>
125     <td style="color:white; font-family:verdana,arial,sans-serif; font-size: 12px;"> &nbsp; $fenster &nbsp; [<a href="JavaScript:top.main_window.print()">drucken</a>]</td>
126     <td align="right" style="vertical-align:middle; color:white; font-family:verdana,arial,sans-serif; font-size: 12px;" nowrap>
127       $login $datum <span id='clock_id' style='position:relative'></span>&nbsp;
128     </td>
129   </tr>
130 </table>
131 |;
132 }
133
134 sub acc_menu {
135
136   my $form     = $main::form;
137   my %myconfig = %main::myconfig;
138
139   $locale = Locale->new($myconfig{countrycode}, "menu");
140   my $mainlevel = $form->{level};
141   $mainlevel =~ s/$mainlevel--//g;
142   my $menu = new Menu "$menufile";
143
144   $| = 1;
145
146   print qq|
147 <style>
148 <!--
149
150 .itemBorder {
151   border: 1px solid black
152 }
153
154 .itemText {
155   text-decoration: none;
156   color: #000000;
157   font: 12px Arial, Helvetica
158 }
159
160 .rootItemText {
161   text-decoration: none;
162   color: #ffffff;
163   font: 12px Arial, Helvetica
164 }
165
166 .menu {
167   color:#ffffff;
168   background:url(image/bg_css_menu.png) repeat bottom;
169   border:1px solid;
170   border-color:#ccc #888 #555 #bbb;
171 }
172
173 -->
174 </style>
175
176 <script type="text/javascript">
177 <!--
178 var isDOM = (document.getElementById ? true : false);
179 var isIE4 = ((document.all && !isDOM) ? true : false);
180 var isNS4 = (document.layers ? true : false);
181 //var KO = (navigator.appName=="Konqueror" \|\| navigator.appName=="Opera") ;
182 var KO = ((navigator.userAgent.indexOf('Opera',0) != -1) \|\| (navigator.userAgent.indexOf('Konqueror',0) != -1));
183 function getRef(id) {
184   if (isDOM) return document.getElementById(id);
185   if (isIE4) return document.all[id];
186   if (isNS4) return document.layers[id];
187 }
188 function getSty(id) {
189   return (isNS4 ? getRef(id) : getRef(id).style);
190 }
191 var popTimer = 0;
192 var litNow = new Array();
193 function popOver(menuNum, itemNum) {
194   if (KO) document.getElementById("win1").style.visibility = "hidden";
195   clearTimeout(popTimer);
196   hideAllBut(menuNum);
197   litNow = getTree(menuNum, itemNum);
198   changeCol(litNow, true);
199   targetNum = menu[menuNum][itemNum].target;
200   if (targetNum > 0) {
201     thisX = parseInt(menu[menuNum][0].ref.left) + parseInt(menu[menuNum][itemNum].ref.left);
202     thisY = parseInt(menu[menuNum][0].ref.top) + parseInt(menu[menuNum][itemNum].ref.top);
203     with (menu[targetNum][0].ref) {
204       left = parseInt(thisX + menu[targetNum][0].x);
205       top = parseInt(thisY + menu[targetNum][0].y);
206       visibility = 'visible';
207     }
208   }
209 }
210 function popOut(menuNum, itemNum) {
211   if ((menuNum == 0) && !menu[menuNum][itemNum].target)
212     hideAllBut(0)
213     if (KO) document.getElementById("win1").style.visibility = "visible";
214   else
215     popTimer = setTimeout('hideAllBut(0)', 500);
216 }
217 function getTree(menuNum, itemNum) {
218   itemArray = new Array(menu.length);
219   while(1) {
220     itemArray[menuNum] = itemNum;
221     if (menuNum == 0) return itemArray;
222     itemNum = menu[menuNum][0].parentItem;
223     menuNum = menu[menuNum][0].parentMenu;
224   }
225 }
226 function changeCol(changeArray, isOver) {
227   for (menuCount = 0; menuCount < changeArray.length; menuCount++) {
228     if (changeArray[menuCount]) {
229       newCol = isOver ? menu[menuCount][0].overCol : menu[menuCount][0].backCol;
230       with (menu[menuCount][changeArray[menuCount]].ref) {
231         if (isNS4) bgColor = newCol;
232         else backgroundColor = newCol;
233       }
234     }
235   }
236 }
237 function hideAllBut(menuNum) {
238   var keepMenus = getTree(menuNum, 1);
239   for (count = 0; count < menu.length; count++)
240     if (!keepMenus[count])
241       menu[count][0].ref.visibility = 'hidden';
242   changeCol(litNow, false);
243 }
244
245 function Menu(isVert, popInd, x, y, width, overCol, backCol, borderClass, textClass) {
246   this.isVert = isVert;
247   this.popInd = popInd
248   this.x = x;
249   this.y = y;
250   this.width = width;
251   this.overCol = overCol;
252   this.backCol = backCol;
253   this.borderClass = borderClass;
254   this.textClass = textClass;
255   this.parentMenu = null;
256   this.parentItem = null;
257   this.ref = null;
258 }
259 function Item(text, href, frame, length, spacing, target) {
260   this.text = text;
261   this.href = href;
262   this.frame = frame;
263   this.length = length;
264   this.spacing = spacing;
265   this.target = target;
266   this.ref = null;
267 }
268 function go(link,frame) {
269   tmp=eval("top."+frame);
270   tmp.location=link;
271         //top.main_window.location=link;
272 }
273 function writeMenus() {
274   if (!isDOM && !isIE4 && !isNS4) return;
275   for (currMenu = 0; currMenu < menu.length; currMenu++) with (menu[currMenu][0]) {
276     var str = '', itemX = 0, itemY = 0;
277     for (currItem = 1; currItem < menu[currMenu].length; currItem++) with (menu[currMenu][currItem]) {
278       var itemID = 'menu' + currMenu + 'item' + currItem;
279       var w = (isVert ? width : length);
280       var h = (isVert ? length : width);
281       if (isDOM \|\| isIE4) {
282         str += '<div id="' + itemID + '" style="position: absolute; left: ' + itemX + '; top: ' + itemY + '; width: ' + w + '; height: ' + h + '; visibility: inherit; ';
283         if (backCol) str += 'background: ' + backCol + '; ';
284         str += '" ';
285       }
286       if (isNS4) {
287         str += '<layer id="' + itemID + '" left="' + itemX + '" top="' + itemY + '" width="' +  w + '" height="' + h + '" visibility="inherit" ';
288         if (backCol) str += 'bgcolor="' + backCol + '" ';
289       }
290       if (borderClass) str += 'class="' + borderClass + '" "';
291       str += 'onMouseOver="popOver(' + currMenu + ',' + currItem + ')" onMouseOut="popOut(' + currMenu + ',' + currItem + ')">';
292       str += '<table width="' + (w - 8) + '" border="0" cellspacing="0" cellpadding="' + (!isNS4 && borderClass ? 3 : 0) + '">';
293       str +='<tr><td class="' + textClass + '" style="cursor:pointer;" align="left" height="' + (h - 7) + '" onClick=\\'go("' + href + '","' + frame + '")\\'>' + text + '</a></td>';
294       if (target > 0) {
295         menu[target][0].parentMenu = currMenu;
296         menu[target][0].parentItem = currItem;
297         if (popInd) str += '<td class="' + textClass + '" align="right">' + popInd + '</td>';
298       }
299       str += '</tr></table>' + (isNS4 ? '</layer>' : '</div>');
300       if (isVert) itemY += length + spacing;
301       else itemX += length + spacing;
302     }
303     if (isDOM) {
304       var newDiv = document.createElement('div');
305       document.getElementsByTagName('body').item(0).appendChild(newDiv);
306       newDiv.innerHTML = str;
307       ref = newDiv.style;
308       ref.position = 'absolute';
309       ref.visibility = 'hidden';
310     }
311     if (isIE4) {
312       document.body.insertAdjacentHTML('beforeEnd', '<div id="menu' + currMenu + 'div" ' + 'style="position: absolute; visibility: hidden">' + str + '</div>');
313       ref = getSty('menu' + currMenu + 'div');
314     }
315     if (isNS4) {
316       ref = new Layer(0);
317       ref.document.write(str);
318       ref.document.close();
319     }
320     for (currItem = 1; currItem < menu[currMenu].length; currItem++) {
321       itemName = 'menu' + currMenu + 'item' + currItem;
322       if (isDOM \|\| isIE4) menu[currMenu][currItem].ref = getSty(itemName);
323       if (isNS4) menu[currMenu][currItem].ref = ref.document[itemName];
324     }
325   }
326   with(menu[0][0]) {
327     ref.left = x;
328     ref.top = y;
329     ref.visibility = 'visible';
330    }
331 }
332 var menu = new Array();
333 var defOver = '#cccccc';
334 var defBack = '#dddddd';
335 var defLength = 22;
336 menu[0] = new Array();
337 menu[0][0] = new Menu(false, '', 5, 18, 19, '#cccccc', '', '', 'rootItemText');
338
339 |;
340
341   &section_menu($menu);
342
343   print qq|
344 var popOldWidth = window.innerWidth;
345 nsResizeHandler = new Function('if (popOldWidth != window.innerWidth) location.reload()');
346 if (isNS4) document.captureEvents(Event.CLICK);
347 document.onclick = clickHandle;
348 function clickHandle(evt) {
349   if (isNS4) document.routeEvent(evt);
350   hideAllBut(0);
351   if (KO) document.getElementById("win1").style.visibility = "visible";
352 }
353 function moveRoot() {
354   with(menu[0][0].ref) left = ((parseInt(left) < 100) ? 100 : 5);
355 }
356 //  End -->
357 </script>
358
359 <BODY scrolling="no" topmargin="0" leftmargin="0"  marginwidth="0" marginheight="0" style="margin: 0" onLoad="writeMenus(); clockon();" onResize="if (isNS4) nsResizeHandler()">
360
361
362 <table class="menu" width="100%" border="0" cellpadding="0" cellspacing="0">
363 <tr><td height="21"><font size="1"> </font></td></tr></table>
364
365
366 |;
367
368   print qq|
369
370 |;
371
372 }
373
374 sub section_menu {
375   my ($menu, $level) = @_;
376
377   my $form     = $main::form;
378   my %myconfig = %main::myconfig;
379
380   # build tiered menus
381   my @menuorder = $menu->access_control(\%myconfig, $level);
382   my $main = 0;
383
384   #$pm=0;
385   my $shlp=0;
386   my (%mlz, $sm, $z, $pm, $mm);
387   while (@menuorder) {
388     my $item  = shift @menuorder;
389     my $label = $item;
390     my $ml    = $item;
391     $label =~ s/$level--//g;
392     $ml    =~ s/--.*//;
393     $label = $locale->text($label);
394     $label =~ s/ /&nbsp;/g;
395     $menu->{$item}{target} = "main_window" unless $menu->{$item}{target};
396
397     if ($menu->{$item}{submenu}) {
398       $menu->{$item}{$item} = !$form->{$item};
399
400       # Untermen
401       if ($mlz{"s$ml"} > 1) {
402         $z++;
403         $sm = 1;
404       } else {
405         $z = $sm;
406         $mlz{"s$ml"}++;
407       }
408       print
409         qq|menu[$mlz{$ml}][$z] = new Item('$label', '#', '', defLength, 0, |
410         . ++$pm
411         . qq|);\n|;
412       $sm = 1;
413       print qq|menu[$pm] = new Array();\n|;
414       print
415         qq|menu[$pm][0] = new Menu(true, '', 85, 0, 180, defOver, defBack, 'itemBorder', 'itemText');\n|;
416       map { shift @menuorder } grep /^$item/, @menuorder;
417       &section_menu($menu, $item);
418       map { shift @menuorder } grep /^$item/, @menuorder;
419     } else {
420       if ($menu->{$item}{module}) {
421
422         #Untermenüpunkte
423         my $target = $menu->{$item}{target};
424         my $uri    = $menu->menuitem_js(\%myconfig, \%$form, $item, $level);
425
426         print
427           qq|menu[$pm][$sm] = new Item('$label', '$uri', '$target', defLength, 0, 0);\n|;
428         $sm++;
429       } else {    # Hauptmenu
430         my $ml_ = $form->escape($ml);
431         $mm++;
432         $pm++;
433         %mlz   = ($ml, $pm, "s$ml", 1);
434         $shlp = $sm;
435         $sm    = 1;
436         my $breit = 15 + length($label) * 6;
437         print
438           qq|menu[0][$mm] = new Item('  $label', '#', '', $breit, 10, $pm); \n|;
439         print qq|menu[$pm] = new Array();\n|;
440         print
441           qq|menu[$pm][0] = new Menu(true, '>', 0, 20, 180, defOver, defBack, 'itemBorder', 'itemText');\n|;
442
443         &section_menu($menu, $item);
444
445         #print qq|<br>\n|;
446       }
447     }
448   }
449 }