X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FForm.pm;h=951b850613e76deab65a6eb7ab236fe5670141e2;hb=1d1b94ec909a9ab078b78d3299d109818a78b628;hp=98b2a4e4d6e1e5cd2631bb30e7016a5175fe0f57;hpb=ddbe3ea5ec297a58acc9ee3afc17156fb97be7f2;p=kivitendo-erp.git diff --git a/SL/Form.pm b/SL/Form.pm index 98b2a4e4d..951b85061 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -39,13 +39,25 @@ package Form; use Data::Dumper; use Cwd; -use HTML::Template; +use Template; use SL::Template; use CGI::Ajax; use SL::DBUtils; +use SL::Mailer; use SL::Menu; use SL::User; +use SL::Common; use CGI; +use List::Util qw(max min sum); + +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 +80,78 @@ 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; + undef $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 +161,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}) { @@ -148,7 +182,7 @@ sub new { $self->{action} = lc $self->{action}; $self->{action} =~ s/( |-|,|\#)/_/g; - $self->{version} = "2.4.2"; + $self->{version} = "2.4.3"; $main::lxdebug->leave_sub(); @@ -252,6 +286,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; @@ -259,11 +295,7 @@ sub error { } else { - if ($self->{error_function}) { - &{ $self->{error_function} }($msg); - } else { - die "Error: $msg\n"; - } + die "Error: $msg\n"; } $main::lxdebug->leave_sub(); @@ -300,20 +332,17 @@ sub info { $main::lxdebug->leave_sub(); } +# calculates the number of rows in a textarea based on the content and column number +# can be capped with maxrows sub numtextrows { $main::lxdebug->enter_sub(); - my ($self, $str, $cols, $maxrows) = @_; - my $rows = 0; - - map { $rows += int(((length) - 2) / $cols) + 1 } split /\r/, $str; - - $maxrows = $rows unless defined $maxrows; + my $rows = sum map { int((length() - 2) / $cols) + 1 } split /\r/, $str; + $maxrows ||= $rows; $main::lxdebug->leave_sub(); - - return ($rows > $maxrows) ? $maxrows : $rows; + return min $rows, $maxrows; } sub dberror { @@ -347,14 +376,25 @@ sub header { return; } - my ($stylesheet, $favicon, $charset); + my ($stylesheet, $favicon); if ($ENV{HTTP_USER_AGENT}) { + my $doctype; - if ($self->{stylesheet} && (-f "css/$self->{stylesheet}")) { - $stylesheet = - qq| - |; + if ($ENV{'HTTP_USER_AGENT'} =~ m/MSIE\s+\d/) { + # Only set the DOCTYPE for Internet Explorer. Other browsers have problems displaying the menu otherwise. + $doctype = qq|\n|; + } + + my $stylesheets = "$self->{stylesheet} $self->{stylesheets}"; + + $stylesheets =~ s|^\s*||; + $stylesheets =~ s|\s*$||; + foreach my $file (split m/\s+/, $stylesheets) { + $file =~ s|.*/||; + next if (! -f "css/$file"); + + $stylesheet .= qq|\n|; } $self->{favicon} = "favicon.ico" unless $self->{favicon}; @@ -365,11 +405,8 @@ sub header { |; } - if ($self->{charset}) { - $charset = - qq| - |; - } + my $db_charset = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET; + if ($self->{landscape}) { $pagelayout = qq|