+++ /dev/null
-package SL::Controller::Layout;
-
-use strict;
-use parent qw(SL::Controller::Base);
-
-use SL::Menu;
-use SL::Controller::Layout::Admin;
-use SL::Controller::Layout::Login;
-use SL::Controller::Layout::Classic;
-use SL::Controller::Layout::V3;
-use SL::Controller::Layout::V4;
-use SL::Controller::Layout::Javascript;
-
-my %menu_cache;
-
-sub new {
- my ($class, %params) = @_;
-
- return SL::Controller::Layout::Classic->new if $params{style} eq 'old';
- return SL::Controller::Layout::V3->new if $params{style} eq 'v3';
- return SL::Controller::Layout::V4->new if $params{style} eq 'v4';
- return SL::Controller::Layout::Javascript->new if $params{style} eq 'neu';
- return SL::Controller::Layout::Admin->new if $params{style} eq 'admin';
- return SL::Controller::Layout::Login->new if $params{style} eq 'login';
- return SL::Controller::Layout::None->new;
-}
-
-1;
+++ /dev/null
-package SL::Controller::Layout::Admin;
-
-use strict;
-use parent qw(SL::Controller::Layout::Base);
-
-sub new {
- my ($class, @slurp) = @_;
-
- my $self = $class->SUPER::new(@slurp);
-
- $self->add_sub_layouts([
- SL::Controller::Layout::None->new,
- ]);
-
- $self;
-}
-
-sub start_content {
- "<div id='admin' class='admin'>\n";
-}
-
-sub end_content {
- "</div>\n";
-}
-
-1;
+++ /dev/null
-package SL::Controller::Layout::Base;
-
-use strict;
-use parent qw(SL::Controller::Base);
-
-use Rose::Object::MakeMethods::Generic (
- 'scalar --get_set_init' => qw(menu),
- 'scalar' => qw(focus),
- 'array' => [
- 'add_stylesheets_inline' => { interface => 'add', hash_key => 'stylesheets_inline' },
- 'add_javascripts_inline' => { interface => 'add', hash_key => 'javascripts_inline' },
- 'sub_layouts',
- 'add_sub_layouts' => { interface => 'add', hash_key => 'sub_layouts' },
- ],
-);
-
-use SL::Menu;
-
-my %menu_cache;
-
-sub new {
- my ($class, @slurp) = @_;
-
- my $self = $class->SUPER::new(@slurp);
-}
-
-sub init_menu {
- Menu->new('menu.ini');
-}
-
-##########################################
-# inheritable/overridable
-##########################################
-
-sub pre_content {
- join '', map { $_->pre_content } $_[0]->sub_layouts;
-}
-
-sub start_content {
- join '', map { $_->start_content } $_[0]->sub_layouts;
-}
-
-sub end_content {
- join '', map { $_->end_content } $_[0]->sub_layouts;
-}
-
-sub post_content {
- join '', map { $_->post_content } $_[0]->sub_layouts;
-}
-
-sub stylesheets_inline {
- ( map { $_->stylesheets_inline } $_[0]->sub_layouts ),
- @{ $_[0]->{stylesheets_inline} || [] };
-}
-
-sub javascripts_inline {
- ( map { $_->javascripts_inline } $_[0]->sub_layouts ),
- @{ $_[0]->{javascripts_inline} || [] };
-}
-
-
-#########################################
-# Interface
-########################################
-
-sub use_stylesheet {
- my $self = shift;
- push @{ $self->{stylesheets} ||= [] }, @_ if @_;
- @{ $self->{stylesheets} ||= [] };
-}
-
-sub stylesheets {
- my ($self) = @_;
- my $css_path = $self->get_stylesheet_for_user;
-
- return grep { $_ } map { $self->_find_stylesheet($_, $css_path) }
- $self->use_stylesheet, map { $_->stylesheets } $self->sub_layouts;
-}
-
-sub _find_stylesheet {
- my ($self, $stylesheet, $css_path) = @_;
-
- return "$css_path/$stylesheet" if -f "$css_path/$stylesheet";
- return "css/$stylesheet" if -f "css/$stylesheet";
- return $stylesheet if -f $stylesheet;
-}
-
-sub get_stylesheet_for_user {
- my $css_path = 'css';
- if (my $user_style = $::myconfig{stylesheet}) {
- $user_style =~ s/\.css$//; # nuke trailing .css, this is a remnand of pre 2.7.0 stylesheet handling
- if (-d "$css_path/$user_style" &&
- -f "$css_path/$user_style/main.css") {
- $css_path = "$css_path/$user_style";
- } else {
- $css_path = "$css_path/lx-office-erp";
- }
- } else {
- $css_path = "$css_path/lx-office-erp";
- }
- $::myconfig{css_path} = $css_path; # needed for menunew, FIXME: don't do this here
-
- return $css_path;
-}
-
-
-sub use_javascript {
- my $self = shift;
- push @{ $self->{javascripts} ||= [] }, @_ if @_;
- @{ $self->{javascripts} ||= [] };
-}
-
-sub javascripts {
- my ($self) = @_;
-
- return map { $self->_find_javascript($_) }
- $self->use_javascript, map { $_->javascripts } $self->sub_layouts;
-}
-
-sub _find_javascript {
- my ($self, $javascript) = @_;
-
- return "js/$javascript" if -f "js/$javascript";
- return $javascript if -f $javascript;
-}
-
-
-############################################
-# track state of form header
-############################################
-
-sub header_done {
- $_[0]{_header_done} = 1;
-}
-
-sub need_footer {
- $_[0]{_header_done};
-}
-
-1;
+++ /dev/null
-package SL::Controller::Layout::Classic;
-
-use strict;
-use parent qw(SL::Controller::Layout::Base);
-
-use SL::Controller::Layout::Top;
-use SL::Controller::Layout::MenuLeft;
-
-sub new {
- my ($class, @slurp) = @_;
-
- my $self = $class->SUPER::new(@slurp);
-
- $self->add_sub_layouts([
- SL::Controller::Layout::Top->new,
- SL::Controller::Layout::MenuLeft->new,
- SL::Controller::Layout::None->new,
- ]);
-
- $self;
-}
-
-1;
+++ /dev/null
-package SL::Controller::Layout::Css;
-
-use strict;
-
-use List::Util qw(max);
-use Exporter qw(import);
-
-our @EXPORT = qw(clock_line print_menu menuitem_v3);
-
-sub clock_line {
- my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat,
- $Jahr, $Wochentag, $Jahrestag, $Sommerzeit)
- = localtime(time);
- $Monat += 1;
- $Jahrestag += 1;
- $Monat = $Monat < 10 ? $Monat = "0" . $Monat : $Monat;
- $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag;
- $Jahr += 1900;
- my @Wochentage = ("Sonntag", "Montag", "Dienstag", "Mittwoch",
- "Donnerstag", "Freitag", "Samstag");
- my @Monatsnamen = ("", "Januar", "Februar", "März",
- "April", "Mai", "Juni", "Juli",
- "August", "September", "Oktober", "November",
- "Dezember");
- return
- $Wochentage[$Wochentag] . ", der "
- . $Monatstag . "."
- . $Monat . "."
- . $Jahr . " - ";
-}
-
-sub print_menu {
- my ($self, $parent, $depth) = @_;
-
- my $html;
-
- die if ($depth * 1 > 5);
-
- my @menuorder;
- my $menu = $self->menu;
-
- @menuorder = $menu->access_control(\%::myconfig, $parent);
-
- $parent .= "--" if ($parent);
-
- foreach my $item (@menuorder) {
- substr($item, 0, length($parent)) = "";
- next if (($item eq "") || ($item =~ /--/));
-
- my $menu_item = $menu->{"${parent}${item}"};
- my $menu_title = $::locale->text($item);
- my $menu_text = $menu_title;
-
- if ($menu_item->{"submenu"} || !defined($menu_item->{"module"}) ||
- ($menu_item->{"module"} eq "menu.pl")) {
-
- my $h = $self->print_menu("${parent}${item}", $depth * 1 + 1)."\n";
- if (!$parent) {
- $html .= qq|<ul><li><h2>${menu_text}</h2><ul>${h}</ul></li></ul>\n|;
- } else {
- $html .= qq|<li><div class="x">${menu_text}</div><ul>${h}</ul></li>\n|;
- }
- } else {
- if ($self->{sub_class} && $depth > 1) {
- $html .= qq|<li class='sub'>|;
- } else {
- $html .= qq|<li>|;
- }
- $html .= $self->menuitem_v3("${parent}$item", { "title" => $menu_title });
- $html .= qq|${menu_text}</a></li>\n|;
- }
- }
-
- return $html;
-}
-
-sub menuitem_v3 {
- $main::lxdebug->enter_sub();
-
- my ($self, $item, $other) = @_;
- my $menuitem = $self->menu->{$item};
-
- my $action = "section_menu";
- my $module;
-
- if ($menuitem->{module}) {
- $module = $menuitem->{module};
- }
- if ($menuitem->{action}) {
- $action = $menuitem->{action};
- }
-
- my $level = $::form->escape($item);
-
- my $str = qq|<a href="$module?action=| . $::form->escape($action) . qq|&level=| . $::form->escape($level);
-
- my @vars = qw(module action target href);
-
- if ($menuitem->{href}) {
- $str = qq|<a href=$menuitem->{href}|;
- @vars = qw(module target href);
- }
-
- map { delete $menuitem->{$_} } @vars;
-
- # add other params
- foreach my $key (keys %{ $menuitem }) {
- $str .= "&" . $::form->escape($key, 1) . "=";
- my ($value, $conf) = split(/=/, $menuitem->{$key}, 2);
- $value = $::myconfig{$value} . "/$conf" if ($conf);
- $str .= $::form->escape($value, 1);
- }
-
- $str .= '"';
-
- if ($other) {
- foreach my $key (keys(%{$other})) {
- $str .= qq| ${key}="| . $::form->quote($other->{$key}) . qq|"|;
- }
- }
-
- $str .= ">";
-
- $main::lxdebug->leave_sub();
-
- return $str;
-}
-
-1;
+++ /dev/null
-package SL::Controller::Layout::Javascript;
-
-use strict;
-use parent qw(SL::Controller::Layout::Base);
-
-use List::Util qw(max);
-use URI;
-
-sub new {
- my ($class, @slurp) = @_;
-
- my $self = $class->SUPER::new(@slurp);
-
- $self->add_sub_layouts([
- SL::Controller::Layout::None->new,
- ]);
-
- $self;
-}
-
-sub pre_content {
- &display
-}
-
-sub start_content {
- "<div id='content'>\n";
-}
-
-sub end_content {
- "</div>\n";
-}
-
-sub display {
- my ($self) = @_;
- my $form = $main::form;
-
- my $callback = $form->unescape($form->{callback});
- $callback = URI->new($callback)->rel($callback) if $callback;
- $callback = "login.pl?action=company_logo" if $callback =~ /^(\.\/)?$/;
-
- $form->parse_html_template("menu/menunew", {
-# $self->render("menu/menunew", { no_menu => 1, no_output => 1 }, # buggy, no idea why
- force_ul_width => 1,
- date => $self->clock_line,
- menu_items => $self->acc_menu,
- callback => $callback,
- });
-}
-
-sub clock_line {
- my $form = $main::form;
-
- my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat,
- $Jahr, $Wochentag, $Jahrestag, $Sommerzeit)
- = localtime(time);
- $Monat += 1;
- $Jahrestag += 1;
- $Monat = $Monat < 10 ? $Monat = "0" . $Monat : $Monat;
- $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag;
- $Jahr += 1900;
- my @Wochentage = ("Sonntag", "Montag", "Dienstag", "Mittwoch",
- "Donnerstag", "Freitag", "Samstag");
- my @Monatsnamen = ("", "Januar", "Februar", "März",
- "April", "Mai", "Juni", "Juli",
- "August", "September", "Oktober", "November",
- "Dezember");
- return
- $Wochentage[$Wochentag] . ", der "
- . $Monatstag . "."
- . $Monat . "."
- . $Jahr . " - ";
-}
-
-sub acc_menu {
- my ($self) = @_;
-
- my $menu = $self->menu;
-
- my $all_items = [];
- $self->create_menu($menu, $all_items);
-
- my $item = { 'subitems' => $all_items };
- calculate_width($item);
-
- return $all_items;
-}
-
-sub calculate_width {
- my $item = shift;
-
- $item->{max_width} = max map { length $_->{title} } @{ $item->{subitems} };
-
- foreach my $subitem (@{ $item->{subitems} }) {
- calculate_width($subitem) if ($subitem->{subitems});
- }
-}
-
-sub create_menu {
- my ($self, $menu, $all_items, $parent, $depth) = @_;
- my $html;
-
- my $form = $main::form;
- my %myconfig = %main::myconfig;
-
- die if ($depth * 1 > 5);
-
- my @menuorder = $menu->access_control(\%myconfig, $parent);
- $parent .= "--" if ($parent);
-
- foreach my $name (@menuorder) {
- substr($name, 0, length($parent), "");
- next if (($name eq "") || ($name =~ /--/));
-
- my $menu_item = $menu->{"${parent}${name}"};
- my $item = { 'title' => $::locale->text($name) };
- push @{ $all_items }, $item;
-
- if ($menu_item->{submenu} || !defined($menu_item->{module}) || ($menu_item->{module} eq "menu.pl")) {
- $item->{subitems} = [];
- $item->{image} = _icon_path("$name.png");
- $self->create_menu($menu, $item->{subitems}, "${parent}${name}", $depth * 1 + 1);
-
- } else {
- $item->{image} = _icon_path("${parent}${name}.png");
- $menu->menuitem_new("${parent}${name}", $item);
- }
- }
-}
-
-sub _icon_path {
- my ($label, $size) = @_;
-
- $size ||= 16;
-
- my $img = "image/icons/${size}x${size}/$label";
-
- return unless -f $img;
- return $img;
-}
-
-1;
+++ /dev/null
-package SL::Controller::Layout::Login;
-
-use strict;
-use parent qw(SL::Controller::Layout::Base);
-
-sub new {
- my ($class, @slurp) = @_;
-
- my $self = $class->SUPER::new(@slurp);
-
- $self->add_sub_layouts([
- SL::Controller::Layout::None->new,
- ]);
-
- $self;
-}
-
-sub start_content {
- "<div id='login' class='login'>\n";
-}
-
-sub end_content {
- "</div>\n";
-}
-
-1;
+++ /dev/null
-package SL::Controller::Layout::MenuLeft;
-
-use strict;
-use parent qw(SL::Controller::Layout::Base);
-
-use URI;
-
-use List::MoreUtils qw(apply);
-
-sub stylesheets {
- qw(css/icons16.css css/icons24.css)
-}
-
-sub javascripts_inline {
- my $self = shift;
- my $sections = [ section_menu($self->menu) ];
- $self->render('menu/menu', { no_menu => 1, no_output => 1 },
- sections => $sections,
- )
-}
-
-sub pre_content {
- "<div id='html-menu'></div>\n";
-}
-
-sub start_content {
- "<div id='content' class='html-menu'>\n";
-}
-
-sub end_content {
- "</div>\n";
-}
-
-sub section_menu {
- $::lxdebug->enter_sub(2);
- my ($menu, $level, $id_prefix) = @_;
- my @menuorder = $menu->access_control(\%::myconfig, $level);
- my @items;
-
- my $id = 0;
-
- for my $item (@menuorder) {
- my $menuitem = $menu->{$item};
- my $olabel = apply { s/.*--// } $item;
- my $ml = apply { s/--.*// } $item;
- my $icon_class = apply { y/ /-/ } $item;
- my $spacer = "s" . (0 + $item =~ s/--/--/g);
-
- next if $level && $item ne "$level--$olabel";
-
- my $label = $::locale->text($olabel);
-
- $menuitem->{module} ||= $::form->{script};
- $menuitem->{action} ||= "section_menu";
- $menuitem->{href} ||= "$menuitem->{module}?action=$menuitem->{action}";
-
- # add other params
- foreach my $key (keys %$menuitem) {
- next if $key =~ /target|module|action|href/;
- $menuitem->{href} .= "&" . $::form->escape($key, 1) . "=";
- my ($value, $conf) = split(/=/, $menuitem->{$key}, 2);
- $value = $::myconfig{$value} . "/$conf" if ($conf);
- $menuitem->{href} .= $::form->escape($value, 1);
- }
-
- my $anchor = $menuitem->{href};
-
- my @common_args = ($label, $spacer, "$id_prefix\_$id");
-
- if (!$level) { # toplevel
- push @items, [ @common_args, "icon24 $icon_class", 'm' ];
- # make_image(size => 24, label => $item),
- push @items, section_menu($menu, $item, "$id_prefix\_$id");
- } elsif ($menuitem->{submenu}) {
- push @items, [ @common_args, "icon16 submenu", 'sm' ];
- #make_image(label => 'submenu'),
- push @items, section_menu($menu, $item, "$id_prefix\_$id");
- } elsif ($menuitem->{module}) {
- push @items, [ @common_args, "icon16 $icon_class", 'i', $anchor ];
- #make_image(size => 16, label => $item),
- }
- } continue {
- $id++;
- }
-
- $::lxdebug->leave_sub(2);
- return @items;
-}
-
-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
- : 200;
-}
-
-sub _show_images {
- # don't show images in links
- _calc_framesize() != 240;
-}
-
-1;
+++ /dev/null
-package SL::Controller::Layout::None;
-
-use strict;
-use parent qw(SL::Controller::Layout::Base);
-
-sub javascripts_inline {
- _setup_formats(),
- _setup_focus(),
-}
-
-
-sub _setup_formats {
- $::form->parse_html_template('generic/javascript_setup')
-}
-
-sub _setup_focus {
- if ($::request->{layout}->focus || $::form->{fokus}) {
- return $::form->parse_html_template('generic/focus_setup', {
- focus => $::request->{layout}->focus,
- fokus => $::form->{fokus},
- })
- } else {
- return ();
- }
-}
-
-1;
+++ /dev/null
-package SL::Controller::Layout::Top;
-
-use strict;
-use parent qw(SL::Controller::Layout::Base);
-
-sub pre_content {
- my ($self) = @_;
-
- $self->SUPER::render('menu/header', { partial => 1, no_output => 1 },
- now => DateTime->now_local,
- is_fastcgi => scalar($::dispatcher->interface_type =~ /fastcgi/i),
- is_links => scalar($ENV{HTTP_USER_AGENT} =~ /links/i));
-}
-
-sub stylesheets {
-# 'frame_header/header.css';
-}
-
-1;
+++ /dev/null
-package SL::Controller::Layout::V3;
-
-use strict;
-use parent qw(SL::Controller::Layout::Base);
-use SL::Controller::Layout::Css;
-
-use URI;
-
-sub new {
- my ($class, @slurp) = @_;
-
- my $self = $class->SUPER::new(@slurp);
-
- $self->add_sub_layouts([
- SL::Controller::Layout::None->new,
- ]);
-
- $self;
-}
-
-sub pre_content {
- &render;
-}
-
-sub start_content {
- "<div id='content'>\n";
-}
-
-sub end_content {
- "</div>\n";
-}
-
-sub render {
- my ($self) = @_;
-
- my $callback = $::form->unescape($::form->{callback});
- $callback = URI->new($callback)->rel($callback) if $callback;
- $callback = "login.pl?action=company_logo" if $callback =~ /^(\.\/)?$/;
-
- $self->SUPER::render('menu/menuv3', { no_menu => 1, no_output => 1 },
- force_ul_width => 1,
- date => $self->clock_line,
- menu => $self->print_menu,
- callback => $callback,
- );
-}
-
-1;
+++ /dev/null
-package SL::Controller::Layout::V4;
-
-use strict;
-use parent qw(SL::Controller::Layout::Base);
-use SL::Controller::Layout::Css;
-use SL::Controller::Layout::Top;
-
-use URI;
-
-sub new {
- my ($class, @slurp) = @_;
-
- my $self = $class->SUPER::new(@slurp);
- $self->add_sub_layouts(
- SL::Controller::Layout::Top->new,
- SL::Controller::Layout::None->new,
- );
- $self;
-}
-
-sub start_content {
- "<div id='content'>\n";
-}
-
-sub end_content {
- "</div>\n";
-}
-
-sub pre_content {
- my ($self) = @_;
-
- $self->{sub_class} = 1;
-
- my $callback = $::form->unescape($::form->{callback});
- $callback = URI->new($callback)->rel($callback) if $callback;
- $callback = "login.pl?action=company_logo" if $callback =~ /^(\.\/)?$/;
-
- $self->SUPER::pre_content .
-
- $self->SUPER::render('menu/menuv4', { no_menu => 1, no_output => 1 },
- force_ul_width => 1,
- date => $self->clock_line,
- menu => $self->print_menu,
- callback => $callback,
- );
-}
-
-1;
$::form->{login} = $::myconfig{login};
$::locale = Locale->new($::myconfig{countrycode}) if $::myconfig{countrycode};
my $user = User->new(login => $::myconfig{login});
- $::request->{layout} = SL::Controller::Layout->new(style => $user->{menustyle});
+ $::request->{layout} = SL::Layout->new(style => $user->{menustyle});
# if we get an error back, bale out
my $result = $user->login($::form);
}
sub set_layout {
- $::request->{layout} = SL::Controller::Layout->new(style => 'login');
+ $::request->{layout} = SL::Layout::Dispatcher->new(style => 'login');
}
1;
use SL::Helper::DateTime;
use SL::InstanceConfiguration;
use SL::Template::Plugin::HTMLFixes;
-use SL::Controller::Layout::None;
+use SL::Layout::None;
# Trailing new line is added so that Perl will not add the line
# number 'die' was called in.
$::instance_conf = SL::InstanceConfiguration->new;
$::request = {
cgi => CGI->new({}),
- layout => SL::Controller::Layout::None->new,
+ layout => SL::Layout::None->new,
};
my $session_result = $::auth->restore_session;
use strict;
use parent qw(Rose::Object);
-use SL::Controller::Layout;
+use SL::Layout::Dispatcher;
sub handle {
%::myconfig = ();
return if $::form->{'{AUTH}admin_password'} && ($::auth->authenticate_root($::form->{'{AUTH}admin_password'}) == $::auth->OK());
return if !$::form->{'{AUTH}admin_password'} && ($::auth->authenticate_root($::auth->get_session_value('admin_password')) == $::auth->OK());
- $::request->{layout} = SL::Controller::Layout->new(style => 'admin');
+ $::request->{layout} = SL::Layout::Dispatcher->new(style => 'admin');
$::auth->punish_wrong_login;
$::auth->delete_session_value('admin_password');
use strict;
use parent qw(Rose::Object);
-use SL::Controller::Layout;
+use SL::Layout::Dispatcher;
sub handle {
my ($self, %param) = @_;
$self->_error(%param) unless $::myconfig{login};
$::locale = Locale->new($::myconfig{countrycode});
- $::request->{layout} = SL::Controller::Layout->new(style => $::myconfig{menustyle});
+ $::request->{layout} = SL::Layout::Dispatcher->new(style => $::myconfig{menustyle});
my $ok = $::form->{'{AUTH}login'} && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, $::form->{'{AUTH}password'}));
$ok ||= !$::form->{'{AUTH}login'} && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, undef));
use SL::DO;
use SL::IC;
use SL::IS;
+use SL::Layout::Dispatcher;
use SL::Locale;
use SL::Mailer;
use SL::Menu;
$::lxdebug->leave_sub and return if !$ENV{HTTP_USER_AGENT} || $self->{header}++;
if ($params{no_layout}) {
- $::request->{layout} = SL::Controller::Layout->new(style => 'none');
+ $::request->{layout} = SL::Layout::Dispatcher->new(style => 'none');
}
my $layout = $::request->{layout};
--- /dev/null
+package SL::Layout::Admin;
+
+use strict;
+use parent qw(SL::Layout::Base);
+
+sub new {
+ my ($class, @slurp) = @_;
+
+ my $self = $class->SUPER::new(@slurp);
+
+ $self->add_sub_layouts([
+ SL::Layout::None->new,
+ ]);
+
+ $self;
+}
+
+sub start_content {
+ "<div id='admin' class='admin'>\n";
+}
+
+sub end_content {
+ "</div>\n";
+}
+
+1;
--- /dev/null
+package SL::Layout::Base;
+
+use strict;
+use parent qw(SL::Controller::Base);
+
+use Rose::Object::MakeMethods::Generic (
+ 'scalar --get_set_init' => qw(menu),
+ 'scalar' => qw(focus),
+ 'array' => [
+ 'add_stylesheets_inline' => { interface => 'add', hash_key => 'stylesheets_inline' },
+ 'add_javascripts_inline' => { interface => 'add', hash_key => 'javascripts_inline' },
+ 'sub_layouts',
+ 'add_sub_layouts' => { interface => 'add', hash_key => 'sub_layouts' },
+ ],
+);
+
+use SL::Menu;
+
+my %menu_cache;
+
+sub new {
+ my ($class, @slurp) = @_;
+
+ my $self = $class->SUPER::new(@slurp);
+}
+
+sub init_menu {
+ Menu->new('menu.ini');
+}
+
+##########################################
+# inheritable/overridable
+##########################################
+
+sub pre_content {
+ join '', map { $_->pre_content } $_[0]->sub_layouts;
+}
+
+sub start_content {
+ join '', map { $_->start_content } $_[0]->sub_layouts;
+}
+
+sub end_content {
+ join '', map { $_->end_content } $_[0]->sub_layouts;
+}
+
+sub post_content {
+ join '', map { $_->post_content } $_[0]->sub_layouts;
+}
+
+sub stylesheets_inline {
+ ( map { $_->stylesheets_inline } $_[0]->sub_layouts ),
+ @{ $_[0]->{stylesheets_inline} || [] };
+}
+
+sub javascripts_inline {
+ ( map { $_->javascripts_inline } $_[0]->sub_layouts ),
+ @{ $_[0]->{javascripts_inline} || [] };
+}
+
+
+#########################################
+# Interface
+########################################
+
+sub use_stylesheet {
+ my $self = shift;
+ push @{ $self->{stylesheets} ||= [] }, @_ if @_;
+ @{ $self->{stylesheets} ||= [] };
+}
+
+sub stylesheets {
+ my ($self) = @_;
+ my $css_path = $self->get_stylesheet_for_user;
+
+ return grep { $_ } map { $self->_find_stylesheet($_, $css_path) }
+ $self->use_stylesheet, map { $_->stylesheets } $self->sub_layouts;
+}
+
+sub _find_stylesheet {
+ my ($self, $stylesheet, $css_path) = @_;
+
+ return "$css_path/$stylesheet" if -f "$css_path/$stylesheet";
+ return "css/$stylesheet" if -f "css/$stylesheet";
+ return $stylesheet if -f $stylesheet;
+}
+
+sub get_stylesheet_for_user {
+ my $css_path = 'css';
+ if (my $user_style = $::myconfig{stylesheet}) {
+ $user_style =~ s/\.css$//; # nuke trailing .css, this is a remnand of pre 2.7.0 stylesheet handling
+ if (-d "$css_path/$user_style" &&
+ -f "$css_path/$user_style/main.css") {
+ $css_path = "$css_path/$user_style";
+ } else {
+ $css_path = "$css_path/lx-office-erp";
+ }
+ } else {
+ $css_path = "$css_path/lx-office-erp";
+ }
+ $::myconfig{css_path} = $css_path; # needed for menunew, FIXME: don't do this here
+
+ return $css_path;
+}
+
+
+sub use_javascript {
+ my $self = shift;
+ push @{ $self->{javascripts} ||= [] }, @_ if @_;
+ @{ $self->{javascripts} ||= [] };
+}
+
+sub javascripts {
+ my ($self) = @_;
+
+ return map { $self->_find_javascript($_) }
+ $self->use_javascript, map { $_->javascripts } $self->sub_layouts;
+}
+
+sub _find_javascript {
+ my ($self, $javascript) = @_;
+
+ return "js/$javascript" if -f "js/$javascript";
+ return $javascript if -f $javascript;
+}
+
+
+############################################
+# track state of form header
+############################################
+
+sub header_done {
+ $_[0]{_header_done} = 1;
+}
+
+sub need_footer {
+ $_[0]{_header_done};
+}
+
+1;
--- /dev/null
+package SL::Layout::Classic;
+
+use strict;
+use parent qw(SL::Layout::Base);
+
+use SL::Layout::Top;
+use SL::Layout::MenuLeft;
+
+sub new {
+ my ($class, @slurp) = @_;
+
+ my $self = $class->SUPER::new(@slurp);
+
+ $self->add_sub_layouts([
+ SL::Layout::Top->new,
+ SL::Layout::MenuLeft->new,
+ SL::Layout::None->new,
+ ]);
+
+ $self;
+}
+
+1;
--- /dev/null
+package SL::Layout::Css;
+
+use strict;
+
+use List::Util qw(max);
+use Exporter qw(import);
+
+our @EXPORT = qw(clock_line print_menu menuitem_v3);
+
+sub clock_line {
+ my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat,
+ $Jahr, $Wochentag, $Jahrestag, $Sommerzeit)
+ = localtime(time);
+ $Monat += 1;
+ $Jahrestag += 1;
+ $Monat = $Monat < 10 ? $Monat = "0" . $Monat : $Monat;
+ $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag;
+ $Jahr += 1900;
+ my @Wochentage = ("Sonntag", "Montag", "Dienstag", "Mittwoch",
+ "Donnerstag", "Freitag", "Samstag");
+ my @Monatsnamen = ("", "Januar", "Februar", "März",
+ "April", "Mai", "Juni", "Juli",
+ "August", "September", "Oktober", "November",
+ "Dezember");
+ return
+ $Wochentage[$Wochentag] . ", der "
+ . $Monatstag . "."
+ . $Monat . "."
+ . $Jahr . " - ";
+}
+
+sub print_menu {
+ my ($self, $parent, $depth) = @_;
+
+ my $html;
+
+ die if ($depth * 1 > 5);
+
+ my @menuorder;
+ my $menu = $self->menu;
+
+ @menuorder = $menu->access_control(\%::myconfig, $parent);
+
+ $parent .= "--" if ($parent);
+
+ foreach my $item (@menuorder) {
+ substr($item, 0, length($parent)) = "";
+ next if (($item eq "") || ($item =~ /--/));
+
+ my $menu_item = $menu->{"${parent}${item}"};
+ my $menu_title = $::locale->text($item);
+ my $menu_text = $menu_title;
+
+ if ($menu_item->{"submenu"} || !defined($menu_item->{"module"}) ||
+ ($menu_item->{"module"} eq "menu.pl")) {
+
+ my $h = $self->print_menu("${parent}${item}", $depth * 1 + 1)."\n";
+ if (!$parent) {
+ $html .= qq|<ul><li><h2>${menu_text}</h2><ul>${h}</ul></li></ul>\n|;
+ } else {
+ $html .= qq|<li><div class="x">${menu_text}</div><ul>${h}</ul></li>\n|;
+ }
+ } else {
+ if ($self->{sub_class} && $depth > 1) {
+ $html .= qq|<li class='sub'>|;
+ } else {
+ $html .= qq|<li>|;
+ }
+ $html .= $self->menuitem_v3("${parent}$item", { "title" => $menu_title });
+ $html .= qq|${menu_text}</a></li>\n|;
+ }
+ }
+
+ return $html;
+}
+
+sub menuitem_v3 {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $item, $other) = @_;
+ my $menuitem = $self->menu->{$item};
+
+ my $action = "section_menu";
+ my $module;
+
+ if ($menuitem->{module}) {
+ $module = $menuitem->{module};
+ }
+ if ($menuitem->{action}) {
+ $action = $menuitem->{action};
+ }
+
+ my $level = $::form->escape($item);
+
+ my $str = qq|<a href="$module?action=| . $::form->escape($action) . qq|&level=| . $::form->escape($level);
+
+ my @vars = qw(module action target href);
+
+ if ($menuitem->{href}) {
+ $str = qq|<a href=$menuitem->{href}|;
+ @vars = qw(module target href);
+ }
+
+ map { delete $menuitem->{$_} } @vars;
+
+ # add other params
+ foreach my $key (keys %{ $menuitem }) {
+ $str .= "&" . $::form->escape($key, 1) . "=";
+ my ($value, $conf) = split(/=/, $menuitem->{$key}, 2);
+ $value = $::myconfig{$value} . "/$conf" if ($conf);
+ $str .= $::form->escape($value, 1);
+ }
+
+ $str .= '"';
+
+ if ($other) {
+ foreach my $key (keys(%{$other})) {
+ $str .= qq| ${key}="| . $::form->quote($other->{$key}) . qq|"|;
+ }
+ }
+
+ $str .= ">";
+
+ $main::lxdebug->leave_sub();
+
+ return $str;
+}
+
+1;
--- /dev/null
+package SL::Layout::Dispatcher;
+
+use strict;
+
+use SL::Menu;
+use SL::Layout::Admin;
+use SL::Layout::Login;
+use SL::Layout::Classic;
+use SL::Layout::V3;
+use SL::Layout::V4;
+use SL::Layout::Javascript;
+
+my %menu_cache;
+
+sub new {
+ my ($class, %params) = @_;
+
+ return SL::Layout::Classic->new if $params{style} eq 'old';
+ return SL::Layout::V3->new if $params{style} eq 'v3';
+ return SL::Layout::V4->new if $params{style} eq 'v4';
+ return SL::Layout::Javascript->new if $params{style} eq 'neu';
+ return SL::Layout::Admin->new if $params{style} eq 'admin';
+ return SL::Layout::Login->new if $params{style} eq 'login';
+ return SL::Layout::None->new;
+}
+
+1;
--- /dev/null
+package SL::Layout::Javascript;
+
+use strict;
+use parent qw(SL::Layout::Base);
+
+use List::Util qw(max);
+use URI;
+
+sub new {
+ my ($class, @slurp) = @_;
+
+ my $self = $class->SUPER::new(@slurp);
+
+ $self->add_sub_layouts([
+ SL::Layout::None->new,
+ ]);
+
+ $self;
+}
+
+sub pre_content {
+ &display
+}
+
+sub start_content {
+ "<div id='content'>\n";
+}
+
+sub end_content {
+ "</div>\n";
+}
+
+sub display {
+ my ($self) = @_;
+ my $form = $main::form;
+
+ my $callback = $form->unescape($form->{callback});
+ $callback = URI->new($callback)->rel($callback) if $callback;
+ $callback = "login.pl?action=company_logo" if $callback =~ /^(\.\/)?$/;
+
+ $form->parse_html_template("menu/menunew", {
+# $self->render("menu/menunew", { no_menu => 1, no_output => 1 }, # buggy, no idea why
+ force_ul_width => 1,
+ date => $self->clock_line,
+ menu_items => $self->acc_menu,
+ callback => $callback,
+ });
+}
+
+sub clock_line {
+ my $form = $main::form;
+
+ my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat,
+ $Jahr, $Wochentag, $Jahrestag, $Sommerzeit)
+ = localtime(time);
+ $Monat += 1;
+ $Jahrestag += 1;
+ $Monat = $Monat < 10 ? $Monat = "0" . $Monat : $Monat;
+ $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag;
+ $Jahr += 1900;
+ my @Wochentage = ("Sonntag", "Montag", "Dienstag", "Mittwoch",
+ "Donnerstag", "Freitag", "Samstag");
+ my @Monatsnamen = ("", "Januar", "Februar", "März",
+ "April", "Mai", "Juni", "Juli",
+ "August", "September", "Oktober", "November",
+ "Dezember");
+ return
+ $Wochentage[$Wochentag] . ", der "
+ . $Monatstag . "."
+ . $Monat . "."
+ . $Jahr . " - ";
+}
+
+sub acc_menu {
+ my ($self) = @_;
+
+ my $menu = $self->menu;
+
+ my $all_items = [];
+ $self->create_menu($menu, $all_items);
+
+ my $item = { 'subitems' => $all_items };
+ calculate_width($item);
+
+ return $all_items;
+}
+
+sub calculate_width {
+ my $item = shift;
+
+ $item->{max_width} = max map { length $_->{title} } @{ $item->{subitems} };
+
+ foreach my $subitem (@{ $item->{subitems} }) {
+ calculate_width($subitem) if ($subitem->{subitems});
+ }
+}
+
+sub create_menu {
+ my ($self, $menu, $all_items, $parent, $depth) = @_;
+ my $html;
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+
+ die if ($depth * 1 > 5);
+
+ my @menuorder = $menu->access_control(\%myconfig, $parent);
+ $parent .= "--" if ($parent);
+
+ foreach my $name (@menuorder) {
+ substr($name, 0, length($parent), "");
+ next if (($name eq "") || ($name =~ /--/));
+
+ my $menu_item = $menu->{"${parent}${name}"};
+ my $item = { 'title' => $::locale->text($name) };
+ push @{ $all_items }, $item;
+
+ if ($menu_item->{submenu} || !defined($menu_item->{module}) || ($menu_item->{module} eq "menu.pl")) {
+ $item->{subitems} = [];
+ $item->{image} = _icon_path("$name.png");
+ $self->create_menu($menu, $item->{subitems}, "${parent}${name}", $depth * 1 + 1);
+
+ } else {
+ $item->{image} = _icon_path("${parent}${name}.png");
+ $menu->menuitem_new("${parent}${name}", $item);
+ }
+ }
+}
+
+sub _icon_path {
+ my ($label, $size) = @_;
+
+ $size ||= 16;
+
+ my $img = "image/icons/${size}x${size}/$label";
+
+ return unless -f $img;
+ return $img;
+}
+
+1;
--- /dev/null
+package SL::Layout::Login;
+
+use strict;
+use parent qw(SL::Layout::Base);
+
+sub new {
+ my ($class, @slurp) = @_;
+
+ my $self = $class->SUPER::new(@slurp);
+
+ $self->add_sub_layouts([
+ SL::Layout::None->new,
+ ]);
+
+ $self;
+}
+
+sub start_content {
+ "<div id='login' class='login'>\n";
+}
+
+sub end_content {
+ "</div>\n";
+}
+
+1;
--- /dev/null
+package SL::Layout::MenuLeft;
+
+use strict;
+use parent qw(SL::Layout::Base);
+
+use URI;
+
+use List::MoreUtils qw(apply);
+
+sub stylesheets {
+ qw(css/icons16.css css/icons24.css)
+}
+
+sub javascripts_inline {
+ my $self = shift;
+ my $sections = [ section_menu($self->menu) ];
+ $self->render('menu/menu', { no_menu => 1, no_output => 1 },
+ sections => $sections,
+ )
+}
+
+sub pre_content {
+ "<div id='html-menu'></div>\n";
+}
+
+sub start_content {
+ "<div id='content' class='html-menu'>\n";
+}
+
+sub end_content {
+ "</div>\n";
+}
+
+sub section_menu {
+ $::lxdebug->enter_sub(2);
+ my ($menu, $level, $id_prefix) = @_;
+ my @menuorder = $menu->access_control(\%::myconfig, $level);
+ my @items;
+
+ my $id = 0;
+
+ for my $item (@menuorder) {
+ my $menuitem = $menu->{$item};
+ my $olabel = apply { s/.*--// } $item;
+ my $ml = apply { s/--.*// } $item;
+ my $icon_class = apply { y/ /-/ } $item;
+ my $spacer = "s" . (0 + $item =~ s/--/--/g);
+
+ next if $level && $item ne "$level--$olabel";
+
+ my $label = $::locale->text($olabel);
+
+ $menuitem->{module} ||= $::form->{script};
+ $menuitem->{action} ||= "section_menu";
+ $menuitem->{href} ||= "$menuitem->{module}?action=$menuitem->{action}";
+
+ # add other params
+ foreach my $key (keys %$menuitem) {
+ next if $key =~ /target|module|action|href/;
+ $menuitem->{href} .= "&" . $::form->escape($key, 1) . "=";
+ my ($value, $conf) = split(/=/, $menuitem->{$key}, 2);
+ $value = $::myconfig{$value} . "/$conf" if ($conf);
+ $menuitem->{href} .= $::form->escape($value, 1);
+ }
+
+ my $anchor = $menuitem->{href};
+
+ my @common_args = ($label, $spacer, "$id_prefix\_$id");
+
+ if (!$level) { # toplevel
+ push @items, [ @common_args, "icon24 $icon_class", 'm' ];
+ # make_image(size => 24, label => $item),
+ push @items, section_menu($menu, $item, "$id_prefix\_$id");
+ } elsif ($menuitem->{submenu}) {
+ push @items, [ @common_args, "icon16 submenu", 'sm' ];
+ #make_image(label => 'submenu'),
+ push @items, section_menu($menu, $item, "$id_prefix\_$id");
+ } elsif ($menuitem->{module}) {
+ push @items, [ @common_args, "icon16 $icon_class", 'i', $anchor ];
+ #make_image(size => 16, label => $item),
+ }
+ } continue {
+ $id++;
+ }
+
+ $::lxdebug->leave_sub(2);
+ return @items;
+}
+
+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
+ : 200;
+}
+
+sub _show_images {
+ # don't show images in links
+ _calc_framesize() != 240;
+}
+
+1;
--- /dev/null
+package SL::Layout::None;
+
+use strict;
+use parent qw(SL::Layout::Base);
+
+sub javascripts_inline {
+ _setup_formats(),
+ _setup_focus(),
+}
+
+
+sub _setup_formats {
+ $::form->parse_html_template('generic/javascript_setup')
+}
+
+sub _setup_focus {
+ if ($::request->{layout}->focus || $::form->{fokus}) {
+ return $::form->parse_html_template('generic/focus_setup', {
+ focus => $::request->{layout}->focus,
+ fokus => $::form->{fokus},
+ })
+ } else {
+ return ();
+ }
+}
+
+1;
--- /dev/null
+package SL::Layout::Top;
+
+use strict;
+use parent qw(SL::Layout::Base);
+
+sub pre_content {
+ my ($self) = @_;
+
+ $self->SUPER::render('menu/header', { partial => 1, no_output => 1 },
+ now => DateTime->now_local,
+ is_fastcgi => scalar($::dispatcher->interface_type =~ /fastcgi/i),
+ is_links => scalar($ENV{HTTP_USER_AGENT} =~ /links/i));
+}
+
+sub stylesheets {
+# 'frame_header/header.css';
+}
+
+1;
--- /dev/null
+package SL::Layout::V3;
+
+use strict;
+use parent qw(SL::Layout::Base);
+use SL::Layout::Css;
+
+use URI;
+
+sub new {
+ my ($class, @slurp) = @_;
+
+ my $self = $class->SUPER::new(@slurp);
+
+ $self->add_sub_layouts([
+ SL::Layout::None->new,
+ ]);
+
+ $self;
+}
+
+sub pre_content {
+ &render;
+}
+
+sub start_content {
+ "<div id='content'>\n";
+}
+
+sub end_content {
+ "</div>\n";
+}
+
+sub render {
+ my ($self) = @_;
+
+ my $callback = $::form->unescape($::form->{callback});
+ $callback = URI->new($callback)->rel($callback) if $callback;
+ $callback = "login.pl?action=company_logo" if $callback =~ /^(\.\/)?$/;
+
+ $self->SUPER::render('menu/menuv3', { no_menu => 1, no_output => 1 },
+ force_ul_width => 1,
+ date => $self->clock_line,
+ menu => $self->print_menu,
+ callback => $callback,
+ );
+}
+
+1;
--- /dev/null
+package SL::Layout::V4;
+
+use strict;
+use parent qw(SL::Layout::Base);
+use SL::Layout::Css;
+use SL::Layout::Top;
+
+use URI;
+
+sub new {
+ my ($class, @slurp) = @_;
+
+ my $self = $class->SUPER::new(@slurp);
+ $self->add_sub_layouts(
+ SL::Layout::Top->new,
+ SL::Layout::None->new,
+ );
+ $self;
+}
+
+sub start_content {
+ "<div id='content'>\n";
+}
+
+sub end_content {
+ "</div>\n";
+}
+
+sub pre_content {
+ my ($self) = @_;
+
+ $self->{sub_class} = 1;
+
+ my $callback = $::form->unescape($::form->{callback});
+ $callback = URI->new($callback)->rel($callback) if $callback;
+ $callback = "login.pl?action=company_logo" if $callback =~ /^(\.\/)?$/;
+
+ $self->SUPER::pre_content .
+
+ $self->SUPER::render('menu/menuv4', { no_menu => 1, no_output => 1 },
+ force_ul_width => 1,
+ date => $self->clock_line,
+ menu => $self->print_menu,
+ callback => $callback,
+ );
+}
+
+1;