b0b46e8c321c0b8907177d75bc6caf8fa431b31d
[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/$mainlevel--//g;
128   my $menu = new Menu "$menufile";
129   $menu = new Menu "custom_$menufile" if (-f "custom_$menufile");
130   $menu = new Menu "$form->{login}_$menufile"
131     if (-f "$form->{login}_$menufile");
132
133   $| = 1;
134
135   print qq|
136 <style>
137 <!--
138
139 .itemBorder {
140   border: 1px solid black
141 }
142
143 .itemText {
144   text-decoration: none;
145   color: #000000;
146   font: 12px Arial, Helvetica
147 }
148
149 .rootItemText {
150   text-decoration: none;
151   color: #ffffff;
152   font: 12px Arial, Helvetica
153 }
154
155 .menu {
156   color:#ffffff;
157   background:url(image/bg_css_menu.png) repeat bottom;
158   border:1px solid;
159   border-color:#ccc #888 #555 #bbb;
160 }
161
162 -->
163 </style>
164
165 <script type="text/javascript">
166 <!--
167 var isDOM = (document.getElementById ? true : false); 
168 var isIE4 = ((document.all && !isDOM) ? true : false);
169 var isNS4 = (document.layers ? true : false);
170 //var KO = (navigator.appName=="Konqueror" \|\| navigator.appName=="Opera") ;
171 var KO = ((navigator.userAgent.indexOf('Opera',0) != -1) \|\| (navigator.userAgent.indexOf('Konqueror',0) != -1));
172 function getRef(id) {
173         if (isDOM) return document.getElementById(id);
174         if (isIE4) return document.all[id];
175         if (isNS4) return document.layers[id];
176 }
177 function getSty(id) {
178         return (isNS4 ? getRef(id) : getRef(id).style);
179
180 var popTimer = 0;
181 var litNow = new Array();
182 function popOver(menuNum, itemNum) {
183         if (KO) document.getElementById("win1").style.visibility = "hidden";
184         clearTimeout(popTimer);
185         hideAllBut(menuNum);
186         litNow = getTree(menuNum, itemNum);
187         changeCol(litNow, true);
188         targetNum = menu[menuNum][itemNum].target;
189         if (targetNum > 0) {
190                 thisX = parseInt(menu[menuNum][0].ref.left) + parseInt(menu[menuNum][itemNum].ref.left);
191                 thisY = parseInt(menu[menuNum][0].ref.top) + parseInt(menu[menuNum][itemNum].ref.top);
192                 with (menu[targetNum][0].ref) {
193                         left = parseInt(thisX + menu[targetNum][0].x);
194                         top = parseInt(thisY + menu[targetNum][0].y);
195                         visibility = 'visible';
196                 }
197         }
198 }
199 function popOut(menuNum, itemNum) {
200         if ((menuNum == 0) && !menu[menuNum][itemNum].target)
201                 hideAllBut(0)
202                 if (KO) document.getElementById("win1").style.visibility = "visible";
203         else
204                 popTimer = setTimeout('hideAllBut(0)', 500);
205 }
206 function getTree(menuNum, itemNum) {
207         itemArray = new Array(menu.length);
208         while(1) {
209                 itemArray[menuNum] = itemNum;
210                 if (menuNum == 0) return itemArray;
211                 itemNum = menu[menuNum][0].parentItem;
212                 menuNum = menu[menuNum][0].parentMenu;
213         }
214 }
215 function changeCol(changeArray, isOver) {
216         for (menuCount = 0; menuCount < changeArray.length; menuCount++) {
217                 if (changeArray[menuCount]) {
218                         newCol = isOver ? menu[menuCount][0].overCol : menu[menuCount][0].backCol;
219                         with (menu[menuCount][changeArray[menuCount]].ref) {
220                                 if (isNS4) bgColor = newCol;
221                                 else backgroundColor = newCol;
222                         }
223                 }
224         }
225 }
226 function hideAllBut(menuNum) {
227         var keepMenus = getTree(menuNum, 1);
228         for (count = 0; count < menu.length; count++)
229                 if (!keepMenus[count])
230                         menu[count][0].ref.visibility = 'hidden';
231         changeCol(litNow, false);
232 }
233
234 function Menu(isVert, popInd, x, y, width, overCol, backCol, borderClass, textClass) {
235         this.isVert = isVert;
236         this.popInd = popInd
237         this.x = x;
238         this.y = y;
239         this.width = width;
240         this.overCol = overCol;
241         this.backCol = backCol;
242         this.borderClass = borderClass;
243         this.textClass = textClass;
244         this.parentMenu = null;
245         this.parentItem = null;
246         this.ref = null;
247 }
248 function Item(text, href, frame, length, spacing, target) {
249         this.text = text;
250         this.href = href;
251         this.frame = frame;
252         this.length = length;
253         this.spacing = spacing;
254         this.target = target;
255         this.ref = null;
256 }
257 function go(link,frame) {
258         tmp=eval("top."+frame);
259         tmp.location=link;
260         //top.main_window.location=link;
261 }
262 function writeMenus() {
263         if (!isDOM && !isIE4 && !isNS4) return;
264         for (currMenu = 0; currMenu < menu.length; currMenu++) with (menu[currMenu][0]) {
265                 var str = '', itemX = 0, itemY = 0;
266                 for (currItem = 1; currItem < menu[currMenu].length; currItem++) with (menu[currMenu][currItem]) {
267                         var itemID = 'menu' + currMenu + 'item' + currItem;
268                         var w = (isVert ? width : length);
269                         var h = (isVert ? length : width);
270                         if (isDOM \|\| isIE4) {
271                                 str += '<div id="' + itemID + '" style="position: absolute; left: ' + itemX + '; top: ' + itemY + '; width: ' + w + '; height: ' + h + '; visibility: inherit; ';
272                                 if (backCol) str += 'background: ' + backCol + '; ';
273                                 str += '" ';
274                         }
275                         if (isNS4) {
276                                 str += '<layer id="' + itemID + '" left="' + itemX + '" top="' + itemY + '" width="' +  w + '" height="' + h + '" visibility="inherit" ';
277                                 if (backCol) str += 'bgcolor="' + backCol + '" ';
278                         }
279                         if (borderClass) str += 'class="' + borderClass + '" "';
280                         str += 'onMouseOver="popOver(' + currMenu + ',' + currItem + ')" onMouseOut="popOut(' + currMenu + ',' + currItem + ')">';
281                         str += '<table width="' + (w - 8) + '" border="0" cellspacing="0" cellpadding="' + (!isNS4 && borderClass ? 3 : 0) + '">';
282                         str +='<tr><td class="' + textClass + '" style="cursor:pointer;" align="left" height="' + (h - 7) + '" onClick=\\'go("' + href + '","' + frame + '")\\'>' + text + '</a></td>';
283                         if (target > 0) {
284                                 menu[target][0].parentMenu = currMenu;
285                                 menu[target][0].parentItem = currItem;
286                                 if (popInd) str += '<td class="' + textClass + '" align="right">' + popInd + '</td>';
287                         }
288                         str += '</tr></table>' + (isNS4 ? '</layer>' : '</div>');
289                         if (isVert) itemY += length + spacing;
290                         else itemX += length + spacing;
291                 }
292                 if (isDOM) {
293                         var newDiv = document.createElement('div');
294                         document.getElementsByTagName('body').item(0).appendChild(newDiv);
295                         newDiv.innerHTML = str;
296                         ref = newDiv.style;
297                         ref.position = 'absolute';
298                         ref.visibility = 'hidden';
299                 }
300                 if (isIE4) {
301                         document.body.insertAdjacentHTML('beforeEnd', '<div id="menu' + currMenu + 'div" ' + 'style="position: absolute; visibility: hidden">' + str + '</div>');
302                         ref = getSty('menu' + currMenu + 'div');
303                 }
304                 if (isNS4) {
305                         ref = new Layer(0);
306                         ref.document.write(str);
307                         ref.document.close();
308                 }
309                 for (currItem = 1; currItem < menu[currMenu].length; currItem++) {
310                         itemName = 'menu' + currMenu + 'item' + currItem;
311                         if (isDOM \|\| isIE4) menu[currMenu][currItem].ref = getSty(itemName);
312                         if (isNS4) menu[currMenu][currItem].ref = ref.document[itemName];
313                 }
314         }
315         with(menu[0][0]) {
316                 ref.left = x;
317                 ref.top = y;
318                 ref.visibility = 'visible';
319    }
320 }
321 var menu = new Array();
322 var defOver = '#cccccc';
323 var defBack = '#dddddd';
324 var defLength = 22;
325 menu[0] = new Array();
326 menu[0][0] = new Menu(false, '', 5, 18, 19, '#cccccc', '', '', 'rootItemText');
327
328 |;
329
330   &section_menu($menu);
331
332   print qq|
333 var popOldWidth = window.innerWidth;
334 nsResizeHandler = new Function('if (popOldWidth != window.innerWidth) location.reload()');
335 if (isNS4) document.captureEvents(Event.CLICK);
336 document.onclick = clickHandle;
337 function clickHandle(evt) {
338         if (isNS4) document.routeEvent(evt);
339         hideAllBut(0);
340         if (KO) document.getElementById("win1").style.visibility = "visible";
341 }
342 function moveRoot() {
343         with(menu[0][0].ref) left = ((parseInt(left) < 100) ? 100 : 5);
344 }
345 //  End -->
346 </script>
347
348 <BODY scrolling="no" topmargin="0" leftmargin="0"  marginwidth="0" marginheight="0" style="margin: 0" onLoad="writeMenus(); clockon();" onResize="if (isNS4) nsResizeHandler()">
349
350
351 <table class="menu" width="100%" border="0" cellpadding="0" cellspacing="0">
352 <tr><td height="21"><font size="1"> </font></td></tr></table>
353
354
355 |;
356
357   print qq|
358   
359 |;
360
361 }
362
363 sub section_menu {
364   my ($menu, $level) = @_;
365
366   # build tiered menus
367   my @menuorder = $menu->access_control(\%myconfig, $level);
368   $main = 0;
369
370   #$pm=0;
371   $shlp=0;
372   while (@menuorder) {
373     $item  = shift @menuorder;
374     $label = $item;
375     $ml    = $item;
376     $label =~ s/$level--//g;
377     $ml    =~ s/--.*//;
378     $label = $locale->text($label);
379     $label =~ s/ /&nbsp;/g;
380     $menu->{$item}{target} = "main_window" unless $menu->{$item}{target};
381
382     if ($menu->{$item}{submenu}) {
383       $menu->{$item}{$item} = !$form->{$item};
384
385       # Untermen
386       if ($mlz{"s$ml"} > 1) { 
387                 $z++; 
388                 $sm = 1; 
389       } else { 
390                 $z = $sm; 
391                 $mlz{"s$ml"}++; 
392       }
393       print
394         qq|menu[$mlz{$ml}][$z] = new Item('$label', '#', '', defLength, 0, |
395         . ++$pm
396         . qq|);\n|;
397       $sm = 1;
398       print qq|menu[$pm] = new Array();\n|;
399       print
400         qq|menu[$pm][0] = new Menu(true, '', 85, 0, 180, defOver, defBack, 'itemBorder', 'itemText');\n|;
401       map { shift @menuorder } grep /^$item/, @menuorder;
402       &section_menu($menu, $item);
403       map { shift @menuorder } grep /^$item/, @menuorder;
404     } else {
405       if ($menu->{$item}{module}) {
406
407         #Untermenüpunkte
408         $target = $menu->{$item}{target};
409         $uri    = $menu->menuitemNew(\%myconfig, \%$form, $item, $level);
410
411         #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|;
412         print
413           qq|menu[$pm][$sm] = new Item('$label', '$uri', '$target', defLength, 0, 0);\n|;
414         $sm++;
415       } else {    # Hauptmenu
416         my $ml_ = $form->escape($ml);
417         $mm++;
418         $pm++;
419         %mlz   = ($ml, $pm, "s$ml", 1);
420         $shlp = $sm;
421         $sm    = 1;
422         $breit = 15 + length($label) * 6;
423         print
424           qq|menu[0][$mm] = new Item('  $label', '#', '', $breit, 10, $pm);     \n|;
425         print qq|menu[$pm] = new Array();\n|;
426         print
427           qq|menu[$pm][0] = new Menu(true, '>', 0, 20, 180, defOver, defBack, 'itemBorder', 'itemText');\n|;
428
429         #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|;
430         &section_menu($menu, $item);
431
432         #print qq|<br>\n|;
433       }
434     }
435   }
436 }