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