use SL::Common;
use SL::CVar;
use SL::DB;
+use SL::DBConnect;
use SL::DBUtils;
use SL::DO;
use SL::IC;
use SL::OE;
use SL::Template;
use SL::User;
+use SL::X;
use Template;
use URI;
use List::Util qw(first max min sum);
my $self = shift;
my $input = shift;
+ my $uploads = {};
if (!$ENV{'CONTENT_TYPE'}
|| ($ENV{'CONTENT_TYPE'} !~ /multipart\/form-data\s*;\s*boundary\s*=\s*(.+)$/)) {
$self->_input_to_hash($input);
$main::lxdebug->leave_sub(2);
- return;
+ return $uploads;
}
my ($name, $filename, $headers_done, $content_type, $boundary_found, $need_cr, $previous);
substr $line, $-[0], $+[0] - $-[0], "";
}
- $previous = $self->_store_value($name, '') if ($name);
+ $previous = _store_value($uploads, $name, '') if ($name);
$self->{FILENAME} = $filename if ($filename);
next;
${ $previous } =~ s|\r?\n$|| if $previous;
$main::lxdebug->leave_sub(2);
+
+ return $uploads;
}
sub _recode_recursively {
bless $self, $type;
+ $main::lxdebug->leave_sub();
+
+ return $self;
+}
+
+sub read_cgi_input {
+ $main::lxdebug->enter_sub();
+
+ my ($self) = @_;
+
$self->_input_to_hash($ENV{QUERY_STRING}) if $ENV{QUERY_STRING};
$self->_input_to_hash($ARGV[0]) if @ARGV && $ARGV[0];
+ my $uploads;
if ($ENV{CONTENT_LENGTH}) {
my $content;
read STDIN, $content, $ENV{CONTENT_LENGTH};
- $self->_request_to_hash($content);
+ $uploads = $self->_request_to_hash($content);
+ }
+
+ if ($self->{RESTORE_FORM_FROM_SESSION_ID}) {
+ my %temp_form;
+ $::auth->restore_form_from_session(delete $self->{RESTORE_FORM_FROM_SESSION_ID}, form => \%temp_form);
+ $self->_input_to_hash(join '&', map { $self->escape($_) . '=' . $self->escape($temp_form{$_}) } keys %temp_form);
}
my $db_charset = $::lx_office_conf{system}->{dbcharset};
_recode_recursively(SL::Iconv->new($encoding, $db_charset), $self);
+ map { $self->{$_} = $uploads->{$_} } keys %{ $uploads } if $uploads;
+
#$self->{version} = "2.6.1"; # Old hardcoded but secure style
open VERSION_FILE, "VERSION"; # New but flexible code reads version from VERSION-file
$self->{version} = <VERSION_FILE>;
sub throw_on_error {
my ($self, $code) = @_;
- local $self->{__ERROR_HANDLER} = sub { die({ error => $_[0] }) };
+ local $self->{__ERROR_HANDLER} = sub { die SL::X::FormError->new($_[0]) };
$code->();
}
$cgi_params{'-charset'} = $params{charset} if ($params{charset});
$cgi_params{'-cookie'} = $session_cookie if ($session_cookie);
+ map { $cgi_params{'-' . $_} = $params{$_} if exists $params{$_} } qw(content_disposition content_length);
+
my $output = $cgi->header(%cgi_params);
$main::lxdebug->leave_sub();
return $output;
}
+sub use_stylesheet {
+ my $self = shift;
+
+ $self->{stylesheet} = [ $self->{stylesheet} ] unless ref $self->{stylesheet} eq 'ARRAY';
+ $self->{stylesheet} = [ grep { -f }
+ map { m:^css/: ? $_ : "css/$_" }
+ grep { $_ }
+ (@{ $self->{stylesheet} }, @_)
+ ];
+
+ return @{ $self->{stylesheet} };
+}
sub header {
$::lxdebug->enter_sub;
push @header, "<meta http-equiv='refresh' content='$refresh_time;$refresh_url'>";
}
- push @header, "<link rel='stylesheet' href='css/$_' type='text/css' title='Lx-Office stylesheet'>"
- for grep { -f "css/$_" } apply { s|.*/|| } $self->{stylesheet}, $self->{stylesheets};
+ push @header, map { qq|<link rel="stylesheet" href="$_" type="text/css" title="Lx-Office stylesheet">| } $self->use_stylesheet;
push @header, "<style type='text/css'>\@page { size:landscape; }</style>" if $self->{landscape};
push @header, "<link rel='shortcut icon' href='$self->{favicon}' type='image/x-icon'>" if -f $self->{favicon};
my $base_uri = $self->_get_request_uri;
my $new_uri = URI->new_abs($new_url, $base_uri);
- die "Headers already sent" if $::self->{header};
+ die "Headers already sent" if $self->{header};
$self->{header} = 1;
my $cgi = $main::cgi || CGI->new('');
$language = "de" unless ($language);
if (-f "templates/webpages/${file}.html") {
- if ((-f ".developer") && ((stat("templates/webpages/${file}.html"))[9] > (stat("locale/${language}/all"))[9])) {
- my $info = "Developer information: templates/webpages/${file}.html is newer than the translation file locale/${language}/all.\n" .
- "Please re-run 'locales.pl' in 'locale/${language}'.";
- print(qq|<pre>$info</pre>|);
- ::end_of_request();
- }
-
$file = "templates/webpages/${file}.html";
} else {
}
$additional_params->{"conf_dbcharset"} = $::lx_office_conf{system}->{dbcharset};
- $additional_params->{"conf_webdav"} = $::lx_office_conf{system}->{webdav};
- $additional_params->{"conf_lizenzen"} = $::lx_office_conf{system}->{lizenzen};
+ $additional_params->{"conf_webdav"} = $::lx_office_conf{features}->{webdav};
$additional_params->{"conf_latex_templates"} = $::lx_office_conf{print_templates}->{latex};
$additional_params->{"conf_opendocument_templates"} = $::lx_office_conf{print_templates}->{opendocument};
- $additional_params->{"conf_vertreter"} = $::lx_office_conf{system}->{vertreter};
- $additional_params->{"conf_show_best_before"} = $::lx_office_conf{system}->{show_best_before};
+ $additional_params->{"conf_vertreter"} = $::lx_office_conf{features}->{vertreter};
+ $additional_params->{"conf_show_best_before"} = $::lx_office_conf{features}->{show_best_before};
$additional_params->{"conf_parts_image_css"} = $::lx_office_conf{features}->{parts_image_css};
$additional_params->{"conf_parts_listing_images"} = $::lx_office_conf{features}->{parts_listing_images};
$additional_params->{"conf_parts_show_image"} = $::lx_office_conf{features}->{parts_show_image};
return $jsscript;
} #end sub write_trigger
+sub _store_redirect_info_in_session {
+ my ($self) = @_;
+
+ return unless $self->{callback} =~ m:^ ( [^\?/]+ \.pl ) \? (.+) :x;
+
+ my ($controller, $params) = ($1, $2);
+ my $form = { map { map { $self->unescape($_) } split /=/, $_, 2 } split m/\&/, $params };
+ $self->{callback} = "${controller}?RESTORE_FORM_FROM_SESSION_ID=" . $::auth->save_form_in_session(form => $form);
+}
+
sub redirect {
$main::lxdebug->enter_sub();
my ($self, $msg) = @_;
if (!$self->{callback}) {
-
$self->info($msg);
- ::end_of_request();
- }
-# my ($script, $argv) = split(/\?/, $self->{callback}, 2);
-# $script =~ s|.*/||;
-# $script =~ s|[^a-zA-Z0-9_\.]||g;
-# exec("perl", "$script", $argv);
+ } else {
+ $self->_store_redirect_info_in_session;
+ print $::form->redirect_header($self->{callback});
+ }
- print $::form->redirect_header($self->{callback});
+ ::end_of_request();
$main::lxdebug->leave_sub();
}
if ( ($myconfig->{numberformat} eq '1.000,00')
|| ($myconfig->{numberformat} eq '1000,00')) {
$amount =~ s/\.//g;
- $amount =~ s/,/\./;
+ $amount =~ s/,/\./g;
}
if ($myconfig->{numberformat} eq "1'000.00") {
$main::lxdebug->leave_sub(2);
- return ($amount * 1);
+ # Make sure no code wich is not a math expression ends up in eval().
+ return 0 unless $amount =~ /^ [\s \d \( \) \- \+ \* \/ \. ]* $/x;
+ return scalar(eval($amount)) * 1 ;
}
sub round_amount {
my ($self, $myconfig) = @_;
# connect to database
- my $dbh = DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, $self->_dbconnect_options)
+ my $dbh = SL::DBConnect->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, $self->_dbconnect_options)
or $self->dberror;
# set db options
my ($self, $myconfig) = @_;
# connect to database
- my $dbh = DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, $self->_dbconnect_options(AutoCommit => 0))
+ my $dbh = SL::DBConnect->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, $self->_dbconnect_options(AutoCommit => 0))
or $self->dberror;
# set db options
my $dbh = $self->dbconnect($myconfig);
my $query = "SELECT 1 FROM defaults WHERE ? < closedto";
- my $sth = prepare_execute_query($self, $dbh, $query, $date);
+ my $sth = prepare_execute_query($self, $dbh, $query, conv_date($date));
+
+ # Falls $date = '' - Fehlermeldung aus der Datenbank. Ich denke,
+ # es ist sicher ein conv_date vorher IMMER auszuführen.
+ # Testfälle ohne definiertes closedto:
+ # Leere Datumseingabe i.O.
+ # SELECT 1 FROM defaults WHERE '' < closedto
+ # normale Zahlungsbuchung über Rechnungsmaske i.O.
+ # SELECT 1 FROM defaults WHERE '10.05.2011' < closedto
+ # Testfälle mit definiertem closedto (30.04.2011):
+ # Leere Datumseingabe i.O.
+ # SELECT 1 FROM defaults WHERE '' < closedto
+ # normale Buchung im geschloßenem Zeitraum i.O.
+ # SELECT 1 FROM defaults WHERE '21.04.2011' < closedto
+ # Fehlermeldung: Es können keine Zahlungen für abgeschlossene Bücher gebucht werden!
+ # normale Buchung in aktiver Buchungsperiode i.O.
+ # SELECT 1 FROM defaults WHERE '01.05.2011' < closedto
+
my ($closed) = $sth->fetchrow_array;
$main::lxdebug->leave_sub();
my $dbh = $self->get_standard_dbh($myconfig);
my $query =
- qq|SELECT p.terms_netto, p.terms_skonto, p.percent_skonto, p.description_long | .
+ qq|SELECT p.terms_netto, p.terms_skonto, p.percent_skonto, p.description_long , p.description | .
qq|FROM payment_terms p | .
qq|WHERE p.id = ?|;
($self->{terms_netto}, $self->{terms_skonto}, $self->{percent_skonto},
- $self->{payment_terms}) =
+ $self->{payment_terms}, $self->{payment_description}) =
selectrow_query($self, $dbh, $query, $self->{payment_id});
if ($transdate eq "") {
if ($self->{"language_id"}) {
$query =
- qq|SELECT t.description_long, l.output_numberformat, l.output_dateformat, l.output_longdates | .
- qq|FROM translation_payment_terms t | .
+ qq|SELECT t.translation, l.output_numberformat, l.output_dateformat, l.output_longdates | .
+ qq|FROM generic_translations t | .
qq|LEFT JOIN language l ON t.language_id = l.id | .
- qq|WHERE (t.language_id = ?) AND (t.payment_terms_id = ?)|;
+ qq|WHERE (t.language_id = ?)
+ AND (t.translation_id = ?)
+ AND (t.translation_type = 'SL::DB::PaymentTerm/description_long')|;
my ($description_long, $output_numberformat, $output_dateformat,
$output_longdates) =
selectrow_query($self, $dbh, $query,
$key = "all_payments" unless ($key);
- my $query = qq|SELECT * FROM payment_terms ORDER BY id|;
+ my $query = qq|SELECT * FROM payment_terms ORDER BY sortkey|;
$self->{$key} = selectall_hashref_query($self, $dbh, $query);
$self->{$key} = selectall_hashref_query($self, $dbh, $query);
if ($bins_key) {
- $query = qq|SELECT id, description FROM bin WHERE warehouse_id = ?|;
+ $query = qq|SELECT id, description FROM bin WHERE warehouse_id = ?
+ ORDER BY description|;
my $sth = prepare_query($self, $dbh, $query);
foreach my $warehouse (@{ $self->{$key} }) {
=head2 C<header>
Generates a general purpose http/html header and includes most of the scripts
-ans stylesheets needed.
+and stylesheets needed. Stylesheets can be added with L<use_stylesheet>.
Only one header will be generated. If the method was already called in this
request it will not output anything and return undef. Also if no
=item stylesheet
-=item stylesheets
-
-If these are arrayrefs the contents will be inlined into the header.
+Either a scalar or an array ref. Will be inlined into the header. Add
+stylesheets with the L<use_stylesheet> function.
=item landscape