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