X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FForm.pm;h=172da36c77f5568e56dcda93e7754abdce0f5821;hb=cae6316e718234083b892b042e61714ceb13b0ca;hp=252c4c159dcd7016346ccc34ee81d6a0c09569dc;hpb=13787dab589901763bd1b2f63cec22add35e0c65;p=kivitendo-erp.git
diff --git a/SL/Form.pm b/SL/Form.pm
index 252c4c159..172da36c7 100644
--- a/SL/Form.pm
+++ b/SL/Form.pm
@@ -43,10 +43,21 @@ use HTML::Template;
use SL::Template;
use CGI::Ajax;
use SL::DBUtils;
+use SL::Mailer;
use SL::Menu;
use SL::User;
+use SL::Common;
use CGI;
+my $standard_dbh;
+
+sub DESTROY {
+ if ($standard_dbh) {
+ $standard_dbh->disconnect();
+ undef $standard_dbh;
+ }
+}
+
sub _input_to_hash {
$main::lxdebug->enter_sub(2);
@@ -68,61 +79,77 @@ sub _request_to_hash {
$main::lxdebug->enter_sub(2);
my ($input) = @_;
- my ($i, $loc, $key, $val);
- my (%ATTACH, $f, $header, $header_body, $len, $buf);
- my ($boundary, @list, $size, $body, $x, $blah, $name);
-
- if ($ENV{'CONTENT_TYPE'}
- && ($ENV{'CONTENT_TYPE'} =~ /multipart\/form-data; boundary=(.+)$/)) {
- $boundary = quotemeta('--' . $1);
- @list = split(/$boundary/, $input);
-
- # For some reason there are always 2 extra, that are empty
- $size = @list - 2;
-
- for ($x = 1; $x <= $size; $x++) {
- $header_body = $list[$x];
- $header_body =~ /\r\n\r\n|\n\n/;
-
- # Here we split the header and body
- $header = $`;
- $body = $'; #'
- $body =~ s/\r\n$//;
-
- # Now we try to get the file name
- $name = $header;
- $name =~ /name=\"(.+)\"/;
- ($name, $blah) = split(/\"/, $1);
-
- # If the form name is not attach, then we need to parse this like
- # regular form data
- if ($name ne "attach") {
- $body =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
- $ATTACH{$name} = $body;
-
- # Otherwise it is an attachment and we need to finish it up
- } elsif ($name eq "attach") {
- $header =~ /filename=\"(.+)\"/;
- $ATTACH{'FILE_NAME'} = $1;
- $ATTACH{'FILE_NAME'} =~ s/\"//g;
- $ATTACH{'FILE_NAME'} =~ s/\s//g;
- $ATTACH{'FILE_CONTENT'} = $body;
-
- for ($i = $x; $list[$i]; $i++) {
- $list[$i] =~ s/^.+name=$//;
- $list[$i] =~ /\"(\w+)\"/;
- $ATTACH{$1} = $'; #'
+
+ if (!$ENV{'CONTENT_TYPE'}
+ || ($ENV{'CONTENT_TYPE'} !~ /multipart\/form-data\s*;\s*boundary\s*=\s*(.+)$/)) {
+ $main::lxdebug->leave_sub(2);
+ return _input_to_hash($input);
+ }
+
+ my ($name, $filename, $headers_done, $content_type, $boundary_found, $need_cr);
+ my %params;
+
+ my $boundary = '--' . $1;
+
+ foreach my $line (split m/\n/, $input) {
+ last if (($line eq "${boundary}--") || ($line eq "${boundary}--\r"));
+
+ if (($line eq $boundary) || ($line eq "$boundary\r")) {
+ $params{$name} =~ s|\r?\n$|| if $name;
+
+ undef $name, $filename;
+
+ $headers_done = 0;
+ $content_type = "text/plain";
+ $boundary_found = 1;
+ $need_cr = 0;
+
+ next;
+ }
+
+ next unless $boundary_found;
+
+ if (!$headers_done) {
+ $line =~ s/[\r\n]*$//;
+
+ if (!$line) {
+ $headers_done = 1;
+ next;
+ }
+
+ if ($line =~ m|^content-disposition\s*:.*?form-data\s*;|i) {
+ if ($line =~ m|filename\s*=\s*"(.*?)"|i) {
+ $filename = $1;
+ substr $line, $-[0], $+[0] - $-[0], "";
+ }
+
+ if ($line =~ m|name\s*=\s*"(.*?)"|i) {
+ $name = $1;
+ substr $line, $-[0], $+[0] - $-[0], "";
}
+
+ $params{$name} = "";
+ $params{FILENAME} = $filename if ($filename);
+
+ next;
+ }
+
+ if ($line =~ m|^content-type\s*:\s*(.*?)$|i) {
+ $content_type = $1;
}
+
+ next;
}
- $main::lxdebug->leave_sub(2);
- return %ATTACH;
+ next unless $name;
- } else {
- $main::lxdebug->leave_sub(2);
- return _input_to_hash($input);
+ $params{$name} .= "${line}\n";
}
+
+ $params{$name} =~ s|\r?\n$|| if $name;
+
+ $main::lxdebug->leave_sub(2);
+ return %params;
}
sub new {
@@ -132,6 +159,11 @@ sub new {
my $self = {};
+ if ($LXDebug::watch_form) {
+ require SL::Watchdog;
+ tie %{ $self }, 'SL::Watchdog';
+ }
+
read(STDIN, $_, $ENV{CONTENT_LENGTH});
if ($ENV{QUERY_STRING}) {
@@ -252,6 +284,8 @@ sub hide_form {
sub error {
$main::lxdebug->enter_sub();
+ $main::lxdebug->show_backtrace();
+
my ($self, $msg) = @_;
if ($ENV{HTTP_USER_AGENT}) {
$msg =~ s/\n/
/g;
@@ -347,7 +381,7 @@ sub header {
return;
}
- my ($stylesheet, $favicon, $charset);
+ my ($stylesheet, $favicon);
if ($ENV{HTTP_USER_AGENT}) {
@@ -365,11 +399,8 @@ sub header {
|;
}
- if ($self->{charset}) {
- $charset =
- qq|
- |;
- }
+ my $db_charset = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
+
if ($self->{landscape}) {
$pagelayout = qq|