Fenster und Tabtitle im XUL MenĂ¼ gefixt.
[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 #######################################################################
34
35 use English qw(-no_match_vars);
36 use List::Util qw(max);
37
38 use SL::Menu;
39
40 1;
41
42 # end of main
43
44 sub display {
45   $form->header();
46
47 #   $form->{force_ul_width} = $ENV{HTTP_USER_AGENT} =~ m/MSIE\s+6\./;
48 #   $form->{force_ul_width} = $ENV{HTTP_USER_AGENT} !~ m/Opera/;
49   $form->{force_ul_width} = 1;
50   $form->{date}           = clock_line();
51   $form->{menu_items}     = acc_menu();
52   $form->{callback}       = $form->unescape($form->{callback}) || "login.pl?action=company_logo";
53
54   print $form->parse_html_template("menu/menunew");
55 }
56
57 sub clock_line {
58   my ($Sekunden, $Minuten,   $Stunden,   $Monatstag, $Monat,
59       $Jahr,     $Wochentag, $Jahrestag, $Sommerzeit)
60     = localtime(time);
61   $Monat     += 1;
62   $Jahrestag += 1;
63   $Monat     = $Monat < 10     ? $Monat     = "0" . $Monat     : $Monat;
64   $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag;
65   $Jahr += 1900;
66   my @Wochentage = ("Sonntag",    "Montag",  "Dienstag", "Mittwoch",
67                     "Donnerstag", "Freitag", "Samstag");
68   my @Monatsnamen = ("",       "Januar",    "Februar", "M&auml;rz",
69                      "April",  "Mai",       "Juni",    "Juli",
70                      "August", "September", "Oktober", "November",
71                      "Dezember");
72   return
73       $Wochentage[$Wochentag] . ", der "
74     . $Monatstag . "."
75     . $Monat . "."
76     . $Jahr . " - ";
77 }
78
79 sub acc_menu {
80   $locale = Locale->new($language, "menu");
81
82   my $mainlevel =  $form->{level};
83   $mainlevel    =~ s/\Q$mainlevel\E--//g;
84   my $menu      = Menu->new('menu.ini');
85
86   $AUTOFLUSH    =  1;
87
88   my $all_items = [];
89   create_menu($menu, $all_items);
90
91   my $item = { 'subitems' => $all_items };
92   calculate_width($item);
93
94   return $all_items;
95 }
96
97 sub calculate_width {
98   my $item           = shift;
99
100   $item->{max_width} = max map { length $_->{title} } @{ $item->{subitems} };
101
102   foreach my $subitem (@{ $item->{subitems} }) {
103     calculate_width($subitem) if ($subitem->{subitems});
104   }
105 }
106
107 sub create_menu {
108   my ($menu, $all_items, $parent, $depth) = @_;
109   my $html;
110
111   die if ($depth * 1 > 5);
112
113   my @menuorder  = $menu->access_control(\%myconfig, $parent);
114   $parent       .= "--" if ($parent);
115
116   foreach my $name (@menuorder) {
117     substr($name, 0, length($parent), "");
118     next if (($name eq "") || ($name =~ /--/));
119
120     my $menu_item = $menu->{"${parent}${name}"};
121     my $item      = { 'title' => $locale->text($name) };
122     push @{ $all_items }, $item;
123
124     if ($menu_item->{submenu} || !defined($menu_item->{module}) || ($menu_item->{module} eq "menu.pl")) {
125       $item->{subitems} = [];
126       create_menu($menu, $item->{subitems}, "${parent}${name}", $depth * 1 + 1);
127
128     } else {
129       $menu->menuitem_new("${parent}${name}", $item);
130     }
131   }
132 }