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