3 # Copyright 2009 BibLibre
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use Encode qw( encode );
31 output_html_with_http_headers
35 use Koha::Virtualshelves;
39 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
41 template_name => "virtualshelves/sendshelfform.tt",
44 flagsrequired => { catalogue => 1 },
48 my $shelfid = $query->param('shelfid');
49 my $to_address = $query->param('email');
51 my $shelf = Koha::Virtualshelves->find( $shelfid );
53 output_and_exit( $query, $cookie, $template, 'insufficient_permission' )
54 if $shelf && !$shelf->can_be_viewed( $loggedinuser );
57 my $comment = $query->param('comment');
59 my ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
61 template_name => "virtualshelves/sendshelf.tt",
64 flagsrequired => { catalogue => 1 },
68 my $contents = $shelf->get_contents;
69 my $marcflavour = C4::Context->preference('marcflavour');
73 while ( my $content = $contents->next ) {
74 my $biblionumber = $content->biblionumber;
75 my $dat = GetBiblioData($biblionumber);
76 my $record = GetMarcBiblio({
77 biblionumber => $biblionumber,
79 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
80 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
82 my @items = GetItemsInfo($biblionumber);
84 $dat->{ISBN} = GetMarcISBN($record, $marcflavour);
85 $dat->{MARCSUBJCTS} = $marcsubjctsarray;
86 $dat->{MARCAUTHORS} = $marcauthorsarray;
87 $dat->{'biblionumber'} = $biblionumber;
88 $dat->{ITEM_RESULTS} = \@items;
89 $dat->{HASAUTHORS} = $dat->{'author'} || @$marcauthorsarray;
91 $iso2709 .= $record->as_usmarc();
93 push( @results, $dat );
97 BIBLIO_RESULTS => \@results,
99 shelfname => $shelf->shelfname,
102 # Getting template result
103 my $template_res = $template2->output();
107 # Analysing information and getting mail properties
108 if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
109 $subject = $+{subject};
110 $subject =~ s|\n?(.*)\n?|$1|;
113 $subject = "no subject";
116 my $email_header = "";
117 if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
119 $email_header =~ s|\n?(.*)\n?|$1|;
122 if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
124 $body =~ s|\n?(.*)\n?|$1|;
127 my $THE_body = <<END_OF_BODY;
133 my $email = Koha::Email->create(
139 $email->text_body( $THE_body );
141 Encode::encode("UTF-8", $iso2709),
142 content_type => 'application/octet-stream',
143 name => 'shelf.iso2709',
144 disposition => 'attachment',
147 my $library = Koha::Patrons->find( $borrowernumber )->library;
148 $email->send_or_die({ transport => $library->smtp_server->transport });
149 $template->param( SENT => "1" );
152 carp "Error sending mail: $_";
153 $template->param( error => 1 );
156 $template->param( email => $to_address );
157 output_html_with_http_headers $query, $cookie, $template->output;
163 url => "/cgi-bin/koha/virtualshelves/sendshelf.pl",
165 output_html_with_http_headers $query, $cookie, $template->output;