diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index f8fc79203c..19e6aef27b 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -435,18 +435,7 @@ if ( defined $htmlfilename ) { open $fh, ">:encoding(UTF-8)",File::Spec->catdir ($htmlfilename,"notices-".$today->ymd().".html"); } - print $fh "\n"; - print $fh "\n"; - print $fh "\n"; - print $fh "\n"; - print $fh "\n"; - print $fh "\n"; + print $fh _get_html_start(); } elsif ( defined $text_filename ) { if ( $text_filename eq '' ) { @@ -848,16 +837,19 @@ END_SQL if ( defined $csvfilename ) { my $delimiter = C4::Context->csv_delimiter; $content = join($delimiter, qw(title name surname address1 address2 zipcode city country email itemcount itemsinfo due_date issue_date)) . "\n"; + $content .= join( "\n", @output_chunks ); + } elsif ( defined $htmlfilename ) { + $content = _get_html_start(); + $content .= join( "\n", @output_chunks ); + $content .= _get_html_end(); + } else { + $content = join( "\n", @output_chunks ); } - else { - $content = ""; - } - $content .= join( "\n", @output_chunks ); if ( C4::Context->preference('EmailOverduesNoEmail') ) { my $attachment = { - filename => defined $csvfilename ? 'attachment.csv' : 'attachment.txt', - type => 'text/plain', + filename => defined $csvfilename ? 'attachment.csv' : defined $htmlfilename ? 'attachment.html' : 'attachment.txt', + type => defined $htmlfilename ? 'text/html' : 'text/plain', content => $content, }; @@ -885,8 +877,7 @@ if ($csvfilename) { } if ( defined $htmlfilename ) { - print $fh "\n"; - print $fh "\n"; + print $fh _get_html_end(); close $fh; } elsif ( defined $text_filename ) { close $fh; @@ -946,4 +937,42 @@ sub prepare_letter_for_printing { return $return; } +=head2 _get_html_start + +Return the start of a HTML document, including html, head and the start body +tags. This should be usable both in the HTML file written to disc, and in the +attachment.html sent as email. + +=cut + +sub _get_html_start { + + return " + + + + +"; + +} + +=head2 _get_html_end + +Return the end of an HTML document, namely the closing body and html tags. + +=cut + +sub _get_html_end { + + return " +"; + +} + cronlogaction({ action => 'End', info => "COMPLETED" });