X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=opac%2Fopac-sendshelf.pl;h=4b33d8ef9720a326e64c982234ef8c4aff01c016;hb=81bdce5c4390e1914ff6cfb2adb469027904f659;hp=1df7a672fd727e0252f08ae2447d7149c485ff7a;hpb=6a0246e24838cfba672baf4aef080588b7d091bf;p=koha-ffzg.git diff --git a/opac/opac-sendshelf.pl b/opac/opac-sendshelf.pl index 1df7a672fd..4b33d8ef97 100755 --- a/opac/opac-sendshelf.pl +++ b/opac/opac-sendshelf.pl @@ -20,22 +20,24 @@ use Modern::Perl; use CGI qw ( -utf8 ); -use Encode qw( encode ); -use Carp; - -use Mail::Sendmail; -use MIME::QuotedPrint; -use MIME::Base64; -use C4::Auth; -use C4::Biblio; -use C4::Items; -use C4::Output; -use C4::Members; +use Encode; +use Carp qw( carp ); +use Try::Tiny qw( catch try ); + +use C4::Auth qw( get_template_and_user ); +use C4::Biblio qw( + GetFrameworkCode + GetMarcBiblio + GetMarcISBN + GetMarcSubjects +); +use C4::Items qw( GetItemsInfo ); +use C4::Output qw( output_html_with_http_headers ); use Koha::Email; use Koha::Patrons; use Koha::Virtualshelves; -my $query = new CGI; +my $query = CGI->new; # if virtualshelves is disabled, leave immediately if ( ! C4::Context->preference('virtualshelves') ) { @@ -48,7 +50,6 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( template_name => "opac-sendshelfform.tt", query => $query, type => "opac", - authnotrequired => 0, } ); @@ -59,17 +60,9 @@ my $dbh = C4::Context->dbh; my $shelf = Koha::Virtualshelves->find( $shelfid ); if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { - -if ( $email ) { - my $message = Koha::Email->new(); + if ( $email ) { my $comment = $query->param('comment'); - my %mail = $message->create_message_headers( - { - to => $email, - } - ); - my ( $template2, $borrowernumber, $cookie ) = get_template_and_user( { template_name => "opac-sendshelf.tt", @@ -90,6 +83,8 @@ if ( $email ) { while ( my $content = $contents->next ) { my $biblionumber = $content->biblionumber; + my $biblio = Koha::Biblios->find( $biblionumber ) or next; + my $dat = $biblio->unblessed; my $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1, @@ -97,11 +92,9 @@ if ( $email ) { borcat => $borcat }); next unless $record; my $fw = GetFrameworkCode($biblionumber); - my $dat = GetBiblioData($biblionumber); - my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); + my $marcauthorsarray = $biblio->get_marc_authors; my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); - my $subtitle = GetRecordValue('subtitle', $record, $fw); my @items = GetItemsInfo( $biblionumber ); @@ -110,7 +103,6 @@ if ( $email ) { $dat->{MARCAUTHORS} = $marcauthorsarray; $dat->{'biblionumber'} = $biblionumber; $dat->{ITEM_RESULTS} = \@items; - $dat->{subtitle} = $subtitle; $dat->{HASAUTHORS} = $dat->{'author'} || @$marcauthorsarray; $iso2709 .= $record->as_usmarc(); @@ -130,83 +122,68 @@ if ( $email ) { my $template_res = $template2->output(); my $body; + my $subject; # Analysing information and getting mail properties - if ( $template_res =~ /(.*)/s ) { - $mail{subject} = $1; - $mail{subject} =~ s|\n?(.*)\n?|$1|; + if ( $template_res =~ /(?.*)/s ) { + $subject = $+{subject}; + $subject =~ s|\n?(.*)\n?|$1|; + } + else { + $subject = "no subject"; } - else { $mail{'subject'} = "no subject"; } - $mail{subject} = encode('MIME-Header', $mail{subject}); my $email_header = ""; if ( $template_res =~ /
(.*)/s ) { $email_header = $1; $email_header =~ s|\n?(.*)\n?|$1|; - $email_header = encode_qp(Encode::encode("UTF-8", $email_header)); - } - - my $email_file = "list.txt"; - if ( $template_res =~ /(.*)/s ) { - $email_file = $1; - $email_file =~ s|\n?(.*)\n?|$1|; } if ( $template_res =~ /(.*)/s ) { $body = $1; $body =~ s|\n?(.*)\n?|$1|; - $body = encode_qp(Encode::encode("UTF-8", $body)); } - my $boundary = "====" . time() . "===="; - - # We set and put the multipart content - $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; - - my $isofile = encode_base64(encode("UTF-8", $iso2709)); - $boundary = '--' . $boundary; - - $mail{body} = <param( SENT => "1" ); + try { + my $email = Koha::Email->create( + { + to => $email, + subject => $subject, + } + ); + $email->text_body( $THE_body ); + $email->attach( + Encode::encode( "UTF-8", $iso2709 ), + content_type => 'application/octet-stream', + name => 'list.iso2709', + disposition => 'attachment', + ); + my $library = Koha::Patrons->find( $borrowernumber )->library; + $email->transport( $library->smtp_server->transport ); + $email->send_or_die; + $template->param( SENT => "1" ); } - else { - # do something if it doesn't work.... - carp "Error sending mail: $Mail::Sendmail::error \n"; + catch { + carp "Error sending mail: $_"; $template->param( error => 1 ); - } + }; $template->param( shelfid => $shelfid, - email => $email, + email => $email, ); output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; - -}else{ + } else { $template->param( shelfid => $shelfid, url => "/cgi-bin/koha/opac-sendshelf.pl", ); output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; -} - + } } else { $template->param( invalidlist => 1, url => "/cgi-bin/koha/opac-sendshelf.pl",