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