Revision 829f6742
Von Sven Schöling vor fast 14 Jahren hinzugefügt
bin/mozilla/menu.pl | ||
---|---|---|
43 | 43 |
use Data::Dumper; |
44 | 44 |
use URI; |
45 | 45 |
|
46 |
use List::MoreUtils qw(apply); |
|
47 |
|
|
46 | 48 |
my $menufile = "menu.ini"; |
49 |
my $nbsp = ' '; |
|
47 | 50 |
my $mainlevel; |
48 | 51 |
|
49 | 52 |
# end of main |
50 | 53 |
|
51 | 54 |
sub display { |
52 |
$main::lxdebug->enter_sub(); |
|
53 |
|
|
54 |
my $form = $main::form; |
|
55 |
$::lxdebug->enter_sub; |
|
55 | 56 |
|
56 |
my $callback = $form->unescape($form->{callback});
|
|
57 |
my $callback = $::form->unescape($::form->{callback});
|
|
57 | 58 |
$callback = URI->new($callback)->rel($callback) if $callback; |
58 | 59 |
$callback = "login.pl?action=company_logo" if $callback =~ /^(\.\/)?$/; |
59 | 60 |
my $framesize = _calc_framesize(); |
60 | 61 |
|
61 |
$form->header; |
|
62 |
$::form->header;
|
|
62 | 63 |
|
63 | 64 |
print qq| |
64 | 65 |
<frameset rows="28px,*" cols="*" framespacing="0" frameborder="0"> |
65 | 66 |
<frame src="kopf.pl" name="kopf" scrolling="NO"> |
66 | 67 |
<frameset cols="$framesize,*" framespacing="0" frameborder="0" border="0" id="menuframe" name="menuframe"> |
67 |
<frame src="$form->{script}?action=acc_menu" name="acc_menu" scrolling="auto" noresize marginwidth="0"> |
|
68 |
<frame src="$::form->{script}?action=acc_menu" name="acc_menu" scrolling="auto" noresize marginwidth="0">
|
|
68 | 69 |
<frame src="$callback" name="main_window" scrolling="auto"> |
69 | 70 |
</frameset> |
70 | 71 |
<noframes> |
... | ... | |
74 | 75 |
</HTML> |
75 | 76 |
|; |
76 | 77 |
|
77 |
$main::lxdebug->leave_sub();
|
|
78 |
$::lxdebug->leave_sub;
|
|
78 | 79 |
} |
79 | 80 |
|
80 | 81 |
sub acc_menu { |
81 |
$main::lxdebug->enter_sub(); |
|
82 |
|
|
83 |
my $form = $main::form; |
|
84 |
my $locale = $main::locale; |
|
85 |
my $framesize = _calc_framesize(); |
|
86 |
|
|
87 |
$mainlevel = $form->{level}; |
|
88 |
$mainlevel =~ s/\Q$mainlevel\E--//g; |
|
89 |
my $menu = Menu->new($::menufile); |
|
82 |
$::lxdebug->enter_sub; |
|
90 | 83 |
|
91 |
$form->{title} = $locale->text('Lx-Office'); |
|
92 |
|
|
93 |
$form->header; |
|
84 |
my $framesize = _calc_framesize() - 2; |
|
85 |
my $menu = Menu->new($::menufile); |
|
86 |
$mainlevel = $::form->{level}; |
|
87 |
$::form->{title} = $::locale->text('Lx-Office'); |
|
88 |
$::form->header; |
|
94 | 89 |
|
95 | 90 |
print qq| |
96 | 91 |
<body class="menu"> |
97 |
|
|
98 |
|; |
|
99 |
print qq|<div align="left">\n<table width="| |
|
100 |
. ($framesize-2) |
|
101 |
. qq|" border="0">\n|; |
|
102 | 92 |
|
103 |
§ion_menu($menu);
|
|
93 |
<div align="left">\n<table width="$framesize" border="0">\n|;
|
|
104 | 94 |
|
105 |
print qq|</table></div>|; |
|
106 |
print qq| |
|
95 |
section_menu($menu); |
|
96 |
|
|
97 |
print qq|</table></div> |
|
107 | 98 |
</body> |
108 | 99 |
</html> |
109 | 100 |
|; |
110 | 101 |
|
111 |
$main::lxdebug->leave_sub();
|
|
102 |
$::lxdebug->leave_sub;
|
|
112 | 103 |
} |
113 | 104 |
|
114 | 105 |
sub section_menu { |
115 |
$main::lxdebug->enter_sub();
|
|
106 |
$::lxdebug->enter_sub;
|
|
116 | 107 |
my ($menu, $level) = @_; |
117 |
|
|
118 |
my $form = $main::form; |
|
119 |
my %myconfig = %main::myconfig; |
|
120 |
my $locale = $main::locale; |
|
121 |
my $is_not_links_browser = $ENV{HTTP_USER_AGENT} =~ /links/i ? 0 : 1; |
|
122 |
|
|
123 |
my $zeige; |
|
124 |
|
|
125 |
# build tiered menus |
|
126 |
my @menuorder = $menu->access_control(\%myconfig, $level); |
|
127 |
while (@menuorder) { |
|
128 |
my $item = shift @menuorder; |
|
129 |
my $label = $item; |
|
130 |
my $ml = $item; |
|
131 |
$label =~ s/\Q$level\E--//g; |
|
132 |
$ml =~ s/--.*//; |
|
133 |
if ($ml eq $mainlevel) { $zeige = 1; } |
|
134 |
else { $zeige = 0; } |
|
135 |
my $spacer = " " x (($item =~ s/--/--/g) * 2); |
|
136 |
$label =~ s/.*--//g; |
|
108 |
my @menuorder = $menu->access_control(\%::myconfig, $level); |
|
109 |
|
|
110 |
for my $item (@menuorder) { |
|
111 |
my $menuitem = $menu->{$item}; |
|
112 |
my $label = apply { s/.*--// } $item; |
|
113 |
my $ml = apply { s/--.*// } $item; |
|
114 |
my $show = $ml eq $mainlevel; |
|
115 |
my $spacer = $nbsp x (($item =~ s/--/--/g) * 2); |
|
137 | 116 |
my $label_icon = $level . "--" . $label . ".png"; |
138 |
my $mlab = $label; |
|
139 |
$label = $locale->text($label); |
|
140 |
|
|
141 |
# multi line hack, sschoeling jul06 |
|
142 |
# if a label is too long, try to split it at whitespaces, then join it to chunks of less |
|
143 |
# than 20 chars and store it in an array. |
|
144 |
# use this array later instead of the -ed label |
|
145 |
my @chunks = (); |
|
146 |
my ($i,$l) = (-1, 20); |
|
147 |
map { |
|
148 |
if (($l += length $_) < 20) { |
|
149 |
$chunks[$i] .= " $_"; |
|
150 |
} else { |
|
151 |
$l = length $_; |
|
152 |
$chunks[++$i] = $_; |
|
153 | 117 |
|
154 |
}
|
|
155 |
} split / /, $label; |
|
156 |
map { s/ / / } @chunks;
|
|
157 |
# end multi line |
|
158 |
|
|
159 |
$label =~ s/ / /g; |
|
160 |
$menu->{$item}{target} = "main_window" unless $menu->{$item}{target};
|
|
161 |
|
|
162 |
if ($menu->{$item}{submenu}) {
|
|
163 |
$menu->{$item}{$item} = !$form->{$item};
|
|
164 |
if ($form->{level} && $item =~ /^\Q$form->{level}\E/) {
|
|
165 |
|
|
166 |
# expand menu |
|
167 |
if ($zeige) {
|
|
168 |
print
|
|
169 |
qq|<tr><td style='vertical-align:bottom'><b>$spacer<img src="image/unterpunkt.png">$label</b></td></tr>\n|; |
|
170 |
}
|
|
171 |
|
|
172 |
# remove same level items
|
|
173 |
map { shift @menuorder } grep /^$item/, @menuorder;
|
|
174 |
§ion_menu($menu, $item);
|
|
118 |
next if $level && $item ne "$level--$label";
|
|
119 |
|
|
120 |
$label = $::locale->text($label);
|
|
121 |
|
|
122 |
$menuitem->{target} ||= "main_window"; |
|
123 |
|
|
124 |
my $anchor = $menu->menuitem(\%::myconfig, $::form, $item, $level);
|
|
125 |
|
|
126 |
if (!$level) { # toplevel
|
|
127 |
my $ml_ = $::form->escape($ml);
|
|
128 |
my $image = make_image(icon => $item . '.png', size => 24, label => $label, valign => 'middle');
|
|
129 |
my $anchor = "<a href='menu.pl?action=acc_menu&level=$ml_' class='nohover' title='$label'>"; |
|
130 |
|
|
131 |
print make_item(a => $anchor, img => $image, label => $label, height => 24);
|
|
132 |
section_menu($menu, $item);
|
|
133 |
|
|
134 |
} elsif ($menuitem->{submenu}) {
|
|
135 |
my $image = make_image(submenu => 1); |
|
136 |
if ($mainlevel && $item =~ /^\Q$mainlevel\E/) {
|
|
137 |
print make_item(spacer => $spacer, bold => 1, img => $image, label => $label) if $show;
|
|
138 |
section_menu($menu, $item); |
|
175 | 139 |
} else { |
176 |
if ($zeige) { |
|
177 |
print qq|<tr><td>| |
|
178 |
. $menu->menuitem(\%myconfig, \%$form, $item, $level) |
|
179 |
. qq|$label ...</a></td></tr>\n|; |
|
180 |
} |
|
181 |
|
|
182 |
# remove same level items |
|
183 |
map { shift @menuorder } grep /^$item/, @menuorder; |
|
140 |
print make_item(spacer => $spacer, a => $anchor, img => $image, label => $label . ' ...') if $show; |
|
184 | 141 |
} |
142 |
} elsif ($menuitem->{module}) { |
|
143 |
my $image = make_image(label => $label, icon => $label_icon); |
|
144 |
print make_item(img => $image, a => $anchor, spacer => $spacer, label => $label) if $show; |
|
145 |
section_menu($menu, $item) if $show && $::form->{$item} && $::form->{level} eq $item; |
|
146 |
} |
|
147 |
} |
|
148 |
$::lxdebug->leave_sub; |
|
149 |
} |
|
150 |
|
|
151 |
sub make_item { |
|
152 |
my %params = @_; |
|
153 |
my $anchor = $params{a} || ''; |
|
154 |
my @chunks = multiline($params{label}); |
|
155 |
my $spacer = $params{spacer} || ''; |
|
156 |
my $image = $params{img}; |
|
157 |
my $height = $params{height} || 16; |
|
158 |
my $a_end = $anchor ? '</a>' : ''; |
|
159 |
my $bold = $params{bold} ? '<b>' : ''; |
|
160 |
my $b_end = $bold ? '</b>' : ''; |
|
161 |
my $hidden_image = make_image(hidden => 1); |
|
162 |
return join "\n", |
|
163 |
"<tr><td class='hover' height='$height'>$bold$spacer$anchor$image$chunks[0]$a_end$b_end</td></tr>\n", |
|
164 |
map "<tr style='vertical-align:top'><td class='hover'>$bold$spacer$hidden_image$anchor$chunks[$_]$a_end$b_end</td></tr>\n", |
|
165 |
1..$#chunks; |
|
166 |
} |
|
167 |
|
|
168 |
# multi line hack, sschoeling jul06 |
|
169 |
# if a label is too long, try to split it at whitespaces, then join it to chunks of less |
|
170 |
# than 20 chars and store it in an array. |
|
171 |
# use this array later instead of the -ed label |
|
172 |
sub multiline { |
|
173 |
my ($label) = @_; |
|
174 |
my @chunks; |
|
175 |
my $l = 20; |
|
176 |
for (split / /, $label) { |
|
177 |
$l += length $_; |
|
178 |
if ($l < 20) { |
|
179 |
$chunks[-1] .= " $_"; |
|
185 | 180 |
} else { |
186 |
if ($menu->{$item}{module}) { |
|
187 |
if ($form->{$item} && $form->{level} eq $item) { |
|
188 |
$menu->{$item}{$item} = !$form->{$item}; |
|
189 |
if ($zeige) { |
|
190 |
|
|
191 |
qq|<tr><td valign=bottom>$spacer<img src="image/unterpunkt.png">| |
|
192 |
. $menu->menuitem(\%myconfig, \%$form, $item, $level) |
|
193 |
. qq|$label</a></td></tr>\n|; |
|
194 |
} |
|
195 |
|
|
196 |
# remove same level items |
|
197 |
map { shift @menuorder } grep /^$item/, @menuorder; |
|
198 |
§ion_menu($menu, $item); |
|
199 |
} else { |
|
200 |
if ($zeige) { |
|
201 |
if (scalar @chunks <= 1) { |
|
202 |
|
|
203 |
qq|<tr><td class="hover" height="16" >$spacer| |
|
204 |
. $menu->menuitem(\%myconfig, \%$form, $item, $level) ; |
|
205 |
|
|
206 |
if (-f "image/icons/16x16/$label_icon" && ($is_not_links_browser)) |
|
207 |
|
|
208 |
qq|<img src="image/icons/16x16/$label_icon" border="0" style="vertical-align:text-top" title="| |
|
209 |
. $label |
|
210 |
. qq|"> | } |
|
211 |
else { |
|
212 |
if ($is_not_links_browser) { |
|
213 |
print qq|<img src="image/unterpunkt.png" border="0" style="vertical-align:text-top">|; |
|
214 |
} |
|
215 |
} |
|
216 |
|
|
217 |
|
|
218 |
qq|$label</a></td></tr>\n|; |
|
219 |
} else { |
|
220 |
my $tmpitem = $menu->menuitem(\%myconfig, \%$form, $item, $level); |
|
221 |
|
|
222 |
qq|<tr><td class="hover" height="16" >$spacer<img src="image/unterpunkt.png" style="vertical-align:text-top">| |
|
223 |
. $tmpitem |
|
224 |
. qq|$chunks[0]</a></td></tr>\n|; |
|
225 |
map { |
|
226 |
|
|
227 |
qq|<tr style="vertical-align:top""><td class="hover">$spacer<img src="image/unterpunkt.png" style="visibility:hidden; width:24; height=2;">| |
|
228 |
. $tmpitem |
|
229 |
. qq|$chunks[$_]</a></td></tr>\n|; |
|
230 |
} 1..$#chunks; |
|
231 |
} |
|
232 |
} |
|
233 |
} |
|
234 |
} else { |
|
235 |
my $ml_ = $form->escape($ml); |
|
236 |
|
|
237 |
qq|<tr><td class="bg" height="24" align="left" valign="middle"> |
|
238 |
<a href="menu.pl?action=acc_menu&level=$ml_" class="nohover" title="$label">|; |
|
239 |
if ($is_not_links_browser) { |
|
240 |
print qq|<img src="image/icons/24x24/$item.png" border="0" style="vertical-align:middle" title="$label">|; |
|
241 |
} |
|
242 |
print qq| $label</a> </td></tr>\n|; |
|
243 |
§ion_menu($menu, $item); |
|
244 |
|
|
245 |
print qq|\n|; |
|
246 |
} |
|
181 |
$l = length $_; |
|
182 |
push @chunks, $_; |
|
247 | 183 |
} |
248 | 184 |
} |
249 |
$main::lxdebug->leave_sub(); |
|
185 |
return @chunks; |
|
186 |
} |
|
187 |
|
|
188 |
sub make_image { |
|
189 |
my (%params) = @_; |
|
190 |
|
|
191 |
my $label = $params{label}; |
|
192 |
my $icon = $params{icon}; |
|
193 |
my $hidden = $params{hidden}; |
|
194 |
my $size = $params{size} || 16; |
|
195 |
my $valign = $params{valign} || 'text-top'; |
|
196 |
|
|
197 |
return unless _show_images(); |
|
198 |
|
|
199 |
my $icon_found = $icon && -f _icon_path($icon, $size); |
|
200 |
|
|
201 |
my $image_url = $icon_found ? _icon_path($icon, $size) : "image/unterpunkt.png"; |
|
202 |
my $style = $hidden ? "visibility:hidden" : "vertical-align:$valign"; |
|
203 |
my $width = $hidden ? "width='$size'" : ''; |
|
204 |
|
|
205 |
my $padding = $size == 16 && $icon_found || $hidden ? $nbsp x 2 |
|
206 |
: $size == 24 ? $nbsp |
|
207 |
: ''; |
|
208 |
|
|
209 |
return "<img src='$image_url' border='0' style='$style' title='$label' $width>$padding"; |
|
250 | 210 |
} |
251 | 211 |
|
252 | 212 |
sub _calc_framesize { |
... | ... | |
259 | 219 |
: 200; |
260 | 220 |
} |
261 | 221 |
|
222 |
sub _show_images { |
|
223 |
# don't show images in links |
|
224 |
_calc_framesize() != 240; |
|
225 |
} |
|
226 |
|
|
227 |
sub _icon_path { |
|
228 |
my ($label, $size) = @_; |
|
229 |
|
|
230 |
$size ||= 16; |
|
231 |
|
|
232 |
return "image/icons/${size}x${size}/$label"; |
|
233 |
} |
|
234 |
|
|
262 | 235 |
1; |
263 | 236 |
|
264 | 237 |
__END__ |
Auch abrufbar als: Unified diff
Menü refactored damit keine Icons verloren gehen.
Fix für Bug 1519.