Projekt

Allgemein

Profil

Herunterladen (7,2 KB) Statistiken
| Zweig: | Markierung: | Revision:
d319704a Moritz Bunkus
#=====================================================================
# LX-Office ERP
# Copyright (C) 2004
# Based on SQL-Ledger Version 2.1.9
# Web http://www.lx-office.org
#
######################################################################
# SQL-Ledger Accounting
# Copyright (c) 1998-2002
#
# Author: Dieter Simader
# Email: dsimader@sql-ledger.org
# Web: http://www.sql-ledger.org
#
# Contributors: Christopher Browne
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#######################################################################
#
08b6539d Sven Donath
# the frame layout with refractured menu
d319704a Moritz Bunkus
#
# CHANGE LOG:
# DS. 2002-03-25 Created
# 2004-12-14 - New Optik - Marco Welter <mawe@linux-studio.de>
da80eb32 Sven Donath
# 2010-08-19 - Icons for sub entries and single click behavior, unlike XUL-Menu
08b6539d Sven Donath
# JS switchable HTML-menu - Sven Donath <lxo@dexo.de>
d319704a Moritz Bunkus
#######################################################################

3289bcb2 Sven Schöling
use strict;

d319704a Moritz Bunkus
use SL::Menu;
54e4131e Moritz Bunkus
use Data::Dumper;
f2078516 Sven Schöling
use URI;
d319704a Moritz Bunkus
25b37b7f Sven Schöling
use List::MoreUtils qw(apply);

3289bcb2 Sven Schöling
my $menufile = "menu.ini";
25b37b7f Sven Schöling
my $nbsp = '&nbsp;';
9f4b866c Sven Schöling
my $mainlevel;

d319704a Moritz Bunkus
# end of main

sub display {
25b37b7f Sven Schöling
$::lxdebug->enter_sub;
d319704a Moritz Bunkus
25b37b7f Sven Schöling
my $callback = $::form->unescape($::form->{callback});
da80eb32 Sven Donath
$callback = URI->new($callback)->rel($callback) if $callback;
$callback = "login.pl?action=company_logo" if $callback =~ /^(\.\/)?$/;
my $framesize = _calc_framesize();
40255f36 Sven Schöling
25b37b7f Sven Schöling
$::form->header;
d319704a Moritz Bunkus
print qq|
54e4131e Moritz Bunkus
<frameset rows="28px,*" cols="*" framespacing="0" frameborder="0">
8c7e4493 Moritz Bunkus
<frame src="kopf.pl" name="kopf" scrolling="NO">
08b6539d Sven Donath
<frameset cols="$framesize,*" framespacing="0" frameborder="0" border="0" id="menuframe" name="menuframe">
25b37b7f Sven Schöling
<frame src="$::form->{script}?action=acc_menu" name="acc_menu" scrolling="auto" noresize marginwidth="0">
f2078516 Sven Schöling
<frame src="$callback" name="main_window" scrolling="auto">
d319704a Moritz Bunkus
</frameset>
<noframes>
You need a browser that can read frames to see this page.
</noframes>
</frameset>
</HTML>
|;

25b37b7f Sven Schöling
$::lxdebug->leave_sub;
d319704a Moritz Bunkus
}

sub acc_menu {
25b37b7f Sven Schöling
$::lxdebug->enter_sub;
d319704a Moritz Bunkus
25b37b7f Sven Schöling
my $framesize = _calc_framesize() - 2;
my $menu = Menu->new($::menufile);
$mainlevel = $::form->{level};
$::form->{title} = $::locale->text('Lx-Office');
$::form->header;
d319704a Moritz Bunkus
print qq|
<body class="menu">

25b37b7f Sven Schöling
<div align="left">\n<table width="$framesize" border="0">\n|;
d319704a Moritz Bunkus
25b37b7f Sven Schöling
section_menu($menu);

print qq|</table></div>
d319704a Moritz Bunkus
</body>
</html>
|;

25b37b7f Sven Schöling
$::lxdebug->leave_sub;
d319704a Moritz Bunkus
}

sub section_menu {
25b37b7f Sven Schöling
$::lxdebug->enter_sub;
d319704a Moritz Bunkus
my ($menu, $level) = @_;

# build tiered menus
25b37b7f Sven Schöling
my @menuorder = $menu->access_control(\%::myconfig, $level);
for my $item (@menuorder) {
my $menuitem = $menu->{$item};
my $label = apply { s/.*--// } $item;
my $ml = apply { s/--.*// } $item;
my $show = $ml eq $mainlevel;
my $spacer = $nbsp x (($item =~ s/--/--/g) * 2);
ad27efa6 Sven Donath
my $label_icon = $level . "--" . $label . ".png";
25b37b7f Sven Schöling
$label = $::locale->text($label);

$menuitem->{target} ||= "main_window";

my $anchor = $menu->menuitem(\%::myconfig, $::form, $item, $level);

577a6777 Sven Schöling
next if $menuitem->{HIDDEN};
40255f36 Sven Schöling
54e4131e Moritz Bunkus
# multi line hack, sschoeling jul06
40255f36 Sven Schöling
# if a label is too long, try to split it at whitespaces, then join it to chunks of less
54e4131e Moritz Bunkus
# than 20 chars and store it in an array.
# use this array later instead of the &nbsp;-ed label
25b37b7f Sven Schöling
my @chunks;
my $l = 20;
for (split / /, $label) {
$l += length $_;
if ($l < 20) {
$chunks[-1] .= " $_";
40255f36 Sven Schöling
} else {
$l = length $_;
25b37b7f Sven Schöling
push @chunks, $_;
d0810c42 Sven Schöling
}
25b37b7f Sven Schöling
}
54e4131e Moritz Bunkus
# end multi line

25b37b7f Sven Schöling
if ($menuitem->{submenu}) {
if ($::form->{level} && $item =~ /^\Q$::form->{level}\E/) {
my $image = make_image(submenu => 1);
print "<tr><td style='vertical-align:bottom'><b>$spacer$image$label</b></td></tr>\n" if $show;
d319704a Moritz Bunkus
# remove same level items
25b37b7f Sven Schöling
$menu->{$_}{HIDDEN} = 1 for grep /^$item/, @menuorder;
section_menu($menu, $item);
d319704a Moritz Bunkus
} else {
25b37b7f Sven Schöling
print "<tr><td>$anchor$label&nbsp;...</a></td></tr>\n" if $show;
d319704a Moritz Bunkus
# remove same level items
25b37b7f Sven Schöling
$menu->{$_}{HIDDEN} = 1 for grep /^$item/, @menuorder;
d319704a Moritz Bunkus
}
25b37b7f Sven Schöling
} elsif ($menuitem->{module}) {
if ($::form->{$item} && $::form->{level} eq $item) {
my $image = make_image();
print qq|<tr><td valign=bottom>$spacer$image$anchor$label</a></td></tr>\n| if $show;

# remove same level items
$menu->{$_}{HIDDEN} = 1 for grep /^$item/, @menuorder;
section_menu($menu, $item);
} elsif ($show) {
my $image1 = make_image(label => $label, icon => $label_icon);
my $image2 = make_image(hidden => 1);
print "<tr><td class='hover' height='16'>$spacer$anchor$image1$chunks[0]</a></td></tr>\n";
print "<tr style='vertical-align:top'><td class='hover'>$spacer$image2$anchor$chunks[$_]</a></td></tr>\n"
for 1..$#chunks;
d319704a Moritz Bunkus
}
25b37b7f Sven Schöling
} else {
my $ml_ = $::form->escape($ml);
my $image = make_image(icon => $item . '.png', size => 24, label => $label, valign => 'middle');
my $anchor = "<a href='menu.pl?action=acc_menu&level=$ml_' class='nohover' title='$label'>";
print qq|<tr><td class="bg" height="24" align="left" valign="middle">$anchor$image$label</a></td></tr>\n|;

&section_menu($menu, $item);
d319704a Moritz Bunkus
}
}
25b37b7f Sven Schöling
$::lxdebug->leave_sub;
d319704a Moritz Bunkus
}
3289bcb2 Sven Schöling
sub _calc_framesize {
my $is_lynx_browser = $ENV{HTTP_USER_AGENT} =~ /links/i;
my $is_mobile_browser = $ENV{HTTP_USER_AGENT} =~ /mobile/i;
my $is_mobile_style = $::form->{stylesheet} =~ /mobile/i;

return $is_mobile_browser && $is_mobile_style ? 130
: $is_lynx_browser ? 240
da80eb32 Sven Donath
: 200;
3289bcb2 Sven Schöling
}

25b37b7f Sven Schöling
sub _show_images {
# don't show images in links
_calc_framesize() != 240;
}

sub make_image {
my (%params) = @_;

my $label = $params{label};
my $icon = $params{icon};
my $hidden = $params{hidden};
my $size = $params{size} || 16;
my $valign = $params{valign} || 'text-top';

return unless _show_images();

my $icon_found = $icon && -f _icon_path($icon, $size);

my $image_url = $icon_found ? _icon_path($icon, $size) : "image/unterpunkt.png";
my $style = $hidden ? "visibility:hidden" : "vertical-align:$valign";
my $width = $hidden ? "width='$size'" : '';

my $padding = $size == 16 && $icon_found || $hidden ? $nbsp x 2
: $size == 24 ? $nbsp
: '';

return "<img src='$image_url' border='0' style='$style' title='$label' $width>$padding";
}

sub _icon_path {
my ($label, $size) = @_;

$size ||= 16;

return "image/icons/${size}x${size}/$label";
}

3289bcb2 Sven Schöling
1;

__END__