Revision 3675add4
Von Moritz Bunkus vor mehr als 8 Jahren hinzugefügt
SL/Controller/Letter.pm | ||
---|---|---|
16 | 16 |
use SL::Helper::CreatePDF; |
17 | 17 |
use SL::Helper::PrintOptions; |
18 | 18 |
use SL::Locale::String qw(t8); |
19 |
use SL::Mailer; |
|
19 | 20 |
use SL::IS; |
20 | 21 |
use SL::ReportGenerator; |
21 | 22 |
use SL::Webdav; |
... | ... | |
172 | 173 |
} |
173 | 174 |
|
174 | 175 |
sub action_print_letter { |
175 |
my ($self, $old_form) = @_;
|
|
176 |
my ($self, %params) = @_;
|
|
176 | 177 |
|
177 | 178 |
my $display_form = $::form->{display_form} || "display_form"; |
178 | 179 |
my $letter = $self->_update; |
... | ... | |
231 | 232 |
|
232 | 233 |
my $pdf_file_name; |
233 | 234 |
eval { |
234 |
$pdf_file_name = SL::Helper::CreatePDF->create_pdf(%create_params); |
|
235 |
$pdf_file_name = SL::Helper::CreatePDF->create_pdf(%create_params); |
|
236 |
|
|
237 |
$::form->{letternumber} = $self->letter->letternumber; |
|
238 |
my $attachment_name = $::form->generate_attachment_filename; |
|
239 |
|
|
240 |
if ($::instance_conf->get_webdav_documents) { |
|
241 |
my $webdav_file = SL::Webdav::File->new( |
|
242 |
filename => $attachment_name, |
|
243 |
webdav => SL::Webdav->new( |
|
244 |
type => 'letter', |
|
245 |
number => $self->letter->letternumber, |
|
246 |
), |
|
247 |
); |
|
248 |
|
|
249 |
$webdav_file->store(file => $pdf_file_name); |
|
250 |
} |
|
235 | 251 |
|
236 | 252 |
# set some form defaults for printing webdav copy variables |
237 | 253 |
if ( $::form->{media} eq 'email') { |
238 | 254 |
my $mail = Mailer->new; |
239 | 255 |
my $signature = $::myconfig{signature}; |
240 |
$mail->{$_} = $::form->{$_} for qw(cc subject message bcc to);
|
|
256 |
$mail->{$_} = $params{email}->{$_} for qw(to cc subject message bcc);
|
|
241 | 257 |
$mail->{from} = qq|"$::myconfig{name}" <$::myconfig{email}>|; |
242 |
$mail->{fileid} = time() . '.' . $$ . '.'; |
|
243 |
$mail->{attachments} = [{ "filename" => $pdf_file_name, |
|
244 |
"name" => $::form->{attachment_name} }]; |
|
258 |
$mail->{attachments} = [{ filename => $pdf_file_name, |
|
259 |
name => $params{email}->{attachment_filename} }]; |
|
245 | 260 |
$mail->{message} .= "\n-- \n$signature"; |
246 | 261 |
$mail->{message} =~ s/\r//g; |
247 | 262 |
|
248 |
# copy_file_to_webdav was already done via io.pl -> edit_e_mail |
|
249 |
my $err = $mail->send; |
|
250 |
return !$err; |
|
251 |
} |
|
263 |
$mail->send; |
|
264 |
unlink $pdf_file_name; |
|
252 | 265 |
|
253 |
$::form->{letternumber} = $self->letter->letternumber; |
|
254 |
my $attachment_name = $::form->generate_attachment_filename; |
|
255 |
my $webdav_file = SL::Webdav::File->new( |
|
256 |
filename => $attachment_name, |
|
257 |
webdav => SL::Webdav->new( |
|
258 |
type => 'letter', |
|
259 |
number => $self->letter->letternumber, |
|
260 |
), |
|
261 |
); |
|
266 |
flash_later('info', t8('The email has been sent.')); |
|
267 |
$self->redirect_to(action => 'edit', 'letter.id' => $self->letter->id); |
|
268 |
|
|
269 |
return 1; |
|
270 |
} |
|
262 | 271 |
|
263 | 272 |
if (!$::form->{printer_id} || $::form->{media} eq 'screen') { |
264 | 273 |
$self->send_file($pdf_file_name, name => $attachment_name); |
265 |
$webdav_file->store(file => $pdf_file_name) if $::instance_conf->get_webdav_documents; |
|
266 | 274 |
unlink $pdf_file_name; |
267 | 275 |
|
268 | 276 |
return 1; |
... | ... | |
274 | 282 |
file_name => $pdf_file_name, |
275 | 283 |
); |
276 | 284 |
|
277 |
$webdav_file->store(file => $pdf_file_name) if $::instance_conf->get_webdav_documents; |
|
278 | 285 |
unlink $pdf_file_name; |
279 | 286 |
|
280 | 287 |
flash_later('info', t8('The documents have been sent to the printer \'#1\'.', $printer->printer_description)); |
281 | 288 |
$self->redirect_to(action => 'edit', 'letter.id' => $self->letter->id, media => 'printer', printer_id => $::form->{printer_id}); |
282 | 289 |
1; |
283 | 290 |
} or do { |
284 |
unlink $pdf_file_name; |
|
291 |
unlink $pdf_file_name if $pdf_file_name;
|
|
285 | 292 |
$::form->error(t8("Creating the PDF failed:") . " " . $@); |
286 | 293 |
}; |
287 |
|
|
288 | 294 |
} |
289 | 295 |
|
290 | 296 |
sub action_update { |
... | ... | |
306 | 312 |
$self->action_add(skip_drafts => 1); |
307 | 313 |
} |
308 | 314 |
|
315 |
sub action_edit_email { |
|
316 |
my ($self) = @_; |
|
317 |
|
|
318 |
my $letter = $self->_update; |
|
319 |
$self->export_letter_to_form($letter); |
|
320 |
|
|
321 |
$::form->{formname} = "letter"; |
|
322 |
$::form->{type} = "letter"; |
|
323 |
$::form->{letternumber} = $self->letter->letternumber; |
|
324 |
|
|
325 |
my @hiddens = map { |
|
326 |
my $value = $letter->$_; |
|
327 |
$value = $value->to_kivitendo if ref($_) =~ m{Date}; |
|
328 |
|
|
329 |
{ name => "letter.$_", value => $value } |
|
330 |
} ($letter->meta->columns); |
|
331 |
|
|
332 |
my %vars = ( |
|
333 |
script => 'controller.pl', |
|
334 |
title => t8('Send letter via e-mail'), |
|
335 |
email => $letter->contact ? $letter->contact->cp_email : '', |
|
336 |
subject => $::form->generate_email_subject, |
|
337 |
a_filename => $::form->generate_attachment_filename, |
|
338 |
action => 'Letter/send_email', |
|
339 |
HIDDEN => \@hiddens, |
|
340 |
SHOW_BCC => $::auth->assert('email_bcc', 'may fail'), |
|
341 |
); |
|
342 |
|
|
343 |
$self->render('generic/edit_email', %vars); |
|
344 |
} |
|
345 |
|
|
346 |
sub action_send_email { |
|
347 |
my ($self) = @_; |
|
348 |
|
|
349 |
$::form->{media} = 'email'; |
|
350 |
$self->action_print_letter( |
|
351 |
email => { |
|
352 |
to => $::form->{email}, |
|
353 |
map { ($_ => $::form->{$_}) } qw(cc bcc subject attachment_filename message) |
|
354 |
} |
|
355 |
); |
|
356 |
} |
|
357 |
|
|
309 | 358 |
sub _display { |
310 | 359 |
my ($self, %params) = @_; |
311 | 360 |
|
... | ... | |
430 | 479 |
$self->{filter_summary} = join ', ', @filter_strings; |
431 | 480 |
} |
432 | 481 |
|
433 |
sub e_mail { |
|
434 |
my $letter = _update(); |
|
435 |
|
|
436 |
$letter->check_number; |
|
437 |
$letter->save; |
|
438 |
|
|
439 |
$::form->{formname} = "letter"; |
|
440 |
$letter->export_to($::form); |
|
441 |
|
|
442 |
$::form->{id} = $letter->{id}; |
|
443 |
edit_e_mail(); |
|
444 |
} |
|
445 |
|
|
446 | 482 |
sub load_letter_draft { |
447 | 483 |
my ($self, %params) = @_; |
448 | 484 |
|
Auch abrufbar als: Unified diff
Brieffunktion: Versand per E-Mail implementiert