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