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