use File::Copy;
use IO::File;
use Math::BigInt;
+use POSIX qw(strftime);
use SL::Auth;
use SL::Auth::DB;
use SL::Auth::LDAP;
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));
$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);
}
}
# 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};
# 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);
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)->id;
+ 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"} ) {
$mail->{message} .= $_ while <IN>;
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,
- content => $attfile->get_content };
- }
+
+ 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};
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'),
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();