X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FForm.pm;h=4c8cebfb1c5bcc8ccee01546aed25dbe69b113cb;hb=826d79929635c726f7459296fafa7e630c00e72d;hp=5424a7c923cbd2e6812b59471d953208c058ddeb;hpb=05e0e8ca1544e1ca706a99e51f9caf9a2f56f6af;p=kivitendo-erp.git diff --git a/SL/Form.pm b/SL/Form.pm index 5424a7c92..4c8cebfb1 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -49,6 +49,7 @@ use Encode; use File::Copy; use IO::File; use Math::BigInt; +use POSIX qw(strftime); use SL::Auth; use SL::Auth::DB; use SL::Auth::LDAP; @@ -376,7 +377,7 @@ sub _get_request_uri { return URI->new($ENV{HTTP_REFERER})->canonical() if $ENV{HTTP_X_FORWARDED_FOR}; return URI->new if !$ENV{REQUEST_URI}; # for testing - my $scheme = $ENV{HTTPS} && (lc $ENV{HTTPS} eq 'on') ? 'https' : 'http'; + my $scheme = $::request->is_https ? 'https' : 'http'; my $port = $ENV{SERVER_PORT}; $port = undef if (($scheme eq 'http' ) && ($port == 80)) || (($scheme eq 'https') && ($port == 443)); @@ -426,7 +427,7 @@ sub create_http_response { $session_cookie = $cgi->cookie('-name' => $main::auth->get_session_cookie_name(), '-value' => $session_cookie_value, '-path' => $uri->path, - '-secure' => $ENV{HTTPS}); + '-secure' => $::request->is_https); } } @@ -621,7 +622,7 @@ sub parse_html_template { $additional_params ||= { }; my $real_file = $self->_prepare_html_template($file, $additional_params); - my $template = $self->template || $self->init_template; + my $template = $self->template; map { $additional_params->{$_} ||= $self->{$_} } keys %{ $self }; @@ -633,32 +634,7 @@ sub parse_html_template { return $output; } -sub init_template { - my $self = shift; - - return $self->template if $self->template; - - # Force scripts/locales.pl to pick up the exception handling template. - # parse_html_template('generic/exception') - return $self->template(Template->new({ - 'INTERPOLATE' => 0, - 'EVAL_PERL' => 0, - 'ABSOLUTE' => 1, - 'CACHE_SIZE' => 0, - 'PLUGIN_BASE' => 'SL::Template::Plugin', - 'INCLUDE_PATH' => '.:templates/webpages', - 'COMPILE_EXT' => '.tcc', - 'COMPILE_DIR' => $::lx_office_conf{paths}->{userspath} . '/templates-cache', - 'ERROR' => 'templates/webpages/generic/exception.html', - 'ENCODING' => 'utf8', - })) || die; -} - -sub template { - my $self = shift; - $self->{template_object} = shift if @_; - return $self->{template_object}; -} +sub template { $::request->presenter->get_template } sub show_generic_error { $main::lxdebug->enter_sub(); @@ -685,6 +661,16 @@ sub show_generic_error { $self->{title} = $params{title} if $params{title}; + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Back'), + call => [ 'kivi.history_back' ], + accesskey => 'enter', + ], + ); + } + $self->header(); print $self->parse_html_template("generic/error", $add_params); @@ -1037,16 +1023,19 @@ sub parse_template { # OUT is used for the media, screen, printer, email # for postscript we store a copy in a temporary file + my $keep_temp_files = $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files}; + my ($temp_fh, $suffix); $suffix = $self->{IN}; $suffix =~ s/.*\.//; ($temp_fh, $self->{tmpfile}) = File::Temp::tempfile( - 'kivitendo-printXXXXXX', + strftime('kivitendo-print-%Y%m%d%H%M%S-XXXXXX', localtime()), SUFFIX => '.' . ($suffix || 'tex'), DIR => $userspath, - UNLINK => ($::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files})? 0 : 1, + UNLINK => $keep_temp_files ? 0 : 1, ); close $temp_fh; + chmod 0644, $self->{tmpfile} if $keep_temp_files; (undef, undef, $self->{template_meta}{tmpfile}) = File::Spec->splitpath( $self->{tmpfile} ); $out = $self->{OUT}; @@ -1078,14 +1067,14 @@ sub parse_template { # therefore copy to webdav, even if we do not have the webdav feature enabled (just archive) my $copy_to_webdav = $::instance_conf->get_webdav_documents && !$self->{preview} && $self->{tmpdir} && $self->{tmpfile} && $self->{type}; - if ( $ext_for_format eq 'pdf' && $::instance_conf->get_doc_storage ) { + if ( $ext_for_format eq 'pdf' && $self->doc_storage_enabled ) { $self->append_general_pdf_attachments(filepath => $self->{tmpdir}."/".$self->{tmpfile}, type => $self->{type}); } if ($self->{media} eq 'file') { copy(join('/', $self->{cwd}, $userspath, $self->{tmpfile}), $out =~ m|^/| ? $out : join('/', $self->{cwd}, $out)) if $template->uses_temp_file; Common::copy_file_to_webdav_folder($self) if $copy_to_webdav; - if (!$self->{preview} && $::instance_conf->get_doc_storage) + if (!$self->{preview} && $self->doc_storage_enabled) { $self->{attachment_filename} ||= $self->generate_attachment_filename; $self->store_pdf($self); @@ -1100,9 +1089,10 @@ sub parse_template { Common::copy_file_to_webdav_folder($self) if $copy_to_webdav; - if ( !$self->{preview} && $ext_for_format eq 'pdf' && $::instance_conf->get_doc_storage) { + if ( !$self->{preview} && $ext_for_format eq 'pdf' && $self->doc_storage_enabled) { $self->{attachment_filename} ||= $self->generate_attachment_filename; - $self->{print_file_id} = $self->store_pdf($self); + my $file_obj = $self->store_pdf($self); + $self->{print_file_id} = $file_obj->id if $file_obj; } if ($self->{media} eq 'email') { if ( getcwd() eq $self->{"tmpdir"} ) { @@ -1169,59 +1159,52 @@ sub send_email { $mail->{message} .= $_ while ; close(IN); - } else { - $main::lxdebug->message(LXDebug->DEBUG2(),"action_oldfile=" . $self->{action_oldfile}." action_nofile=".$self->{action_nofile}); - if (!$self->{"do_not_attach"} && !$self->{action_nofile}) { - my $attachment_name = $self->{attachment_filename} || $self->{tmpfile}; - $attachment_name =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format); - if ( $self->{action_oldfile} ) { - $main::lxdebug->message(LXDebug->DEBUG2(),"object_id =>". $self->{id}." object_type =>". $self->{formname}); - my ( $attfile ) = SL::File->get_all(object_id => $self->{id}, - object_type => $self->{formname}, - file_type => 'document'); - $main::lxdebug->message(LXDebug->DEBUG2(), "old file obj=".$attfile); - push @attfiles, $attfile if $attfile; - } else { - push @{ $mail->{attachments} }, { path => $self->{tmpfile}, - id => $self->{print_file_id}, - type => "application/pdf", - name => $attachment_name }; + } elsif (($self->{attachment_policy} // '') ne 'no_file') { + my $attachment_name = $self->{attachment_filename} || $self->{tmpfile}; + $attachment_name =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format); + + if (($self->{attachment_policy} // '') eq 'old_file') { + my ( $attfile ) = SL::File->get_all(object_id => $self->{id}, + object_type => $self->{formname}, + file_type => 'document'); + + if ($attfile) { + $attfile->{override_file_name} = $attachment_name if $attachment_name; + push @attfiles, $attfile; } + + } else { + push @{ $mail->{attachments} }, { path => $self->{tmpfile}, + id => $self->{print_file_id}, + type => "application/pdf", + name => $attachment_name }; } } - if (!$self->{"do_not_attach"}) { - for my $i (1 .. $self->{attfile_count}) { - if ( $self->{"attsel_$i"} ) { - my $attfile = SL::File->get(id => $self->{"attfile_$i"}); - $main::lxdebug->message(LXDebug->DEBUG2(), "att file=".$self->{"attfile_$i"}." obj=".$attfile); - push @attfiles, $attfile if $attfile; - } - } - for my $i (1 .. $self->{attfile_cv_count}) { - if ( $self->{"attsel_cv_$i"} ) { - my $attfile = SL::File->get(id => $self->{"attfile_cv_$i"}); - $main::lxdebug->message(LXDebug->DEBUG2(), "att file=".$self->{"attfile_$i"}." obj=".$attfile); - push @attfiles, $attfile if $attfile; - } - } - for my $i (1 .. $self->{attfile_part_count}) { - if ( $self->{"attsel_part_$i"} ) { - my $attfile = SL::File->get(id => $self->{"attfile_part_$i"}); - $main::lxdebug->message(LXDebug->DEBUG2(), "att file=".$self->{"attfile_$i"}." obj=".$attfile); - push @attfiles, $attfile if $attfile; - } - } - foreach my $attfile ( @attfiles ) { - push @{ $mail->{attachments} }, { path => $attfile->get_file, - id => $attfile->id, - type => $attfile->mime_type, - name => $attfile->file_name }; - } + + push @attfiles, + grep { $_ } + map { SL::File->get(id => $_) } + @{ $self->{attach_file_ids} // [] }; + + foreach my $attfile ( @attfiles ) { + push @{ $mail->{attachments} }, { + path => $attfile->get_file, + id => $attfile->id, + type => $attfile->mime_type, + name => $attfile->{override_file_name} // $attfile->file_name, + content => $attfile->get_content ? ${ $attfile->get_content } : undef, + }; } + $mail->{message} =~ s/\r//g; $mail->{message} .= $full_signature; $self->{emailerr} = $mail->send(); - # $self->error($self->cleanup . "$err") if $self->{emailerr}; + + if ($self->{emailerr}) { + $self->cleanup; + $self->error($::locale->text('The email was not sent due to the following error: #1.', $self->{emailerr})); + } + $self->{email_journal_id} = $mail->{journalentry}; $self->{snumbers} = "emailjournal" . "_" . $self->{email_journal_id}; $self->{what_done} = $::form->{type}; @@ -1305,8 +1288,13 @@ sub get_formname_translation { sales_delivery_order => $main::locale->text('Delivery Order'), purchase_delivery_order => $main::locale->text('Delivery Order'), dunning => $main::locale->text('Dunning'), + dunning1 => $main::locale->text('Payment Reminder'), + dunning2 => $main::locale->text('Dunning'), + dunning3 => $main::locale->text('Last Dunning'), + dunning_invoice => $main::locale->text('Dunning Invoice'), letter => $main::locale->text('Letter'), ic_supply => $main::locale->text('Intra-Community supply'), + statement => $main::locale->text('Statement'), ); $main::lxdebug->leave_sub(); @@ -1392,6 +1380,38 @@ sub generate_email_subject { return $subject; } +sub generate_email_body { + $main::lxdebug->enter_sub(); + my ($self) = @_; + # simple german and english will work grammatically (most european languages as well) + # Dear Mr Alan Greenspan: + # Sehr geehrte Frau Meyer, + # A l’attention de Mme Villeroy, + # Gentile Signora Ferrari, + my $body = ''; + + if ($self->{cp_id}) { + my $givenname = SL::DB::Contact->load_cached($self->{cp_id})->cp_givenname; # for qw(gender givename name); + my $name = SL::DB::Contact->load_cached($self->{cp_id})->cp_name; # for qw(gender givename name); + my $gender = SL::DB::Contact->load_cached($self->{cp_id})->cp_gender; # for qw(gender givename name); + my $mf = $gender eq 'f' ? 'female' : 'male'; + $body = GenericTranslations->get(translation_type => "salutation_$mf", language_id => $self->{language_id}); + $body .= ' ' . $givenname . ' ' . $name if $body; + } else { + $body = GenericTranslations->get(translation_type => "salutation_general", language_id => $self->{language_id}); + } + + return undef unless $body; + + $body .= GenericTranslations->get(translation_type =>"salutation_punctuation_mark", language_id => $self->{language_id}) . "\n"; + $body .= GenericTranslations->get(translation_type =>"preset_text_$self->{formname}", language_id => $self->{language_id}); + + $body = $main::locale->unquote_special_chars('HTML', $body); + + $main::lxdebug->leave_sub(); + return $body; +} + sub cleanup { $main::lxdebug->enter_sub();