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