Nur ein globales Locale-Objekt anlegen
[kivitendo-erp.git] / bin / mozilla / menuv4.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 SL::Menu;
36 use URI;
37
38 use strict;
39
40 my $menufile = "menu.ini";
41
42 1;
43
44 # end of main
45
46 sub display {
47   my $form     = $main::form;
48
49   $form->header(qq|<link rel="stylesheet" href="css/menuv4.css?id=" type="text/css">|);
50
51   $form->{date}     = clock_line();
52   $form->{menu}     = 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/menuv4");
59
60 }
61
62 sub clock_line {
63   my $form     = $main::form;
64
65   my ($Sekunden, $Minuten,   $Stunden,   $Monatstag, $Monat,
66       $Jahr,     $Wochentag, $Jahrestag, $Sommerzeit)
67     = localtime(time);
68   $Monat     += 1;
69   $Jahrestag += 1;
70   $Monat     = $Monat < 10     ? $Monat     = "0" . $Monat     : $Monat;
71   $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag;
72   $Jahr += 1900;
73   my @Wochentage = ("Sonntag",    "Montag",  "Dienstag", "Mittwoch",
74                     "Donnerstag", "Freitag", "Samstag");
75   my @Monatsnamen = ("",       "Januar",    "Februar", "M&auml;rz",
76                      "April",  "Mai",       "Juni",    "Juli",
77                      "August", "September", "Oktober", "November",
78                      "Dezember");
79   return
80       $Wochentage[$Wochentag] . ", der "
81     . $Monatstag . "."
82     . $Monat . "."
83     . $Jahr . " - ";
84 }
85
86 sub acc_menu {
87   my $form     = $main::form;
88   my %myconfig = %main::myconfig;
89
90   my $mainlevel = $form->{level};
91   $mainlevel =~ s/\Q$mainlevel\E--//g;
92   my $menu = new Menu "$menufile";
93
94   $| = 1;
95
96   return print_menu($menu);
97 }
98
99 sub print_menu {
100   my ($menu, $parent, $depth) = @_;
101
102   my $form     = $main::form;
103   my %myconfig = %main::myconfig;
104
105   my $html;
106
107   die if ($depth * 1 > 5);
108
109   my @menuorder;
110
111   @menuorder = $menu->access_control(\%myconfig, $parent);
112
113   $parent .= "--" if ($parent);
114
115   foreach my $item (@menuorder) {
116     substr($item, 0, length($parent)) = "";
117     next if (($item eq "") || ($item =~ /--/));
118
119     my $menu_item = $menu->{"${parent}${item}"};
120     my $menu_title = $::locale->text($item);
121     my $menu_text = $menu_title;
122
123     my $target = "main_window";
124     $target = $menu_item->{"target"} if ($menu_item->{"target"});
125
126     if ($menu_item->{"submenu"} || !defined($menu_item->{"module"}) ||
127         ($menu_item->{"module"} eq "menu.pl")) {
128
129       my $h = print_menu($menu, "${parent}${item}", $depth * 1 + 1)."\n";
130       if (!$parent) {
131         $html .= qq|<ul><li><h2>${menu_text}</h2><ul>${h}</ul></li></ul>\n|;
132       } else {
133         $html .= qq|<li><div class="x">${menu_text}</div><ul>${h}</ul></li>\n|;
134       }
135     } else {
136       if ($depth>1) {
137       $html .= qq|<li class='sub'>|;
138       } else {
139       $html .= qq|<li>|;
140       }
141       $html .= $menu->menuitem_v3(\%myconfig, $form, "${parent}$item",
142                                   { "title" => $menu_title,
143                                     "target" => $target });
144       $html .= qq|${menu_text}</a></li>\n|;
145     }
146   }
147
148   return $html;
149 }