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