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