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 );
32 use Koha
::Virtualshelves
;
36 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
38 template_name
=> "virtualshelves/sendshelfform.tt",
41 flagsrequired
=> { catalogue
=> 1 },
45 my $shelfid = $query->param('shelfid');
46 my $to_address = $query->param('email');
48 my $dbh = C4
::Context
->dbh;
51 my $comment = $query->param('comment');
53 my ( $template2, $borrowernumber, $cookie ) = get_template_and_user
(
55 template_name
=> "virtualshelves/sendshelf.tt",
58 flagsrequired
=> { catalogue
=> 1 },
62 my $shelf = Koha
::Virtualshelves
->find( $shelfid );
63 my $contents = $shelf->get_contents;
64 my $marcflavour = C4
::Context
->preference('marcflavour');
68 while ( my $content = $contents->next ) {
69 my $biblionumber = $content->biblionumber;
70 my $dat = GetBiblioData
($biblionumber);
71 my $record = GetMarcBiblio
({
72 biblionumber
=> $biblionumber,
74 my $marcauthorsarray = GetMarcAuthors
( $record, $marcflavour );
75 my $marcsubjctsarray = GetMarcSubjects
( $record, $marcflavour );
77 my @items = GetItemsInfo
($biblionumber);
79 $dat->{ISBN
} = GetMarcISBN
($record, $marcflavour);
80 $dat->{MARCSUBJCTS
} = $marcsubjctsarray;
81 $dat->{MARCAUTHORS
} = $marcauthorsarray;
82 $dat->{'biblionumber'} = $biblionumber;
83 $dat->{ITEM_RESULTS
} = \
@items;
84 $dat->{HASAUTHORS
} = $dat->{'author'} || @
$marcauthorsarray;
86 $iso2709 .= $record->as_usmarc();
88 push( @results, $dat );
92 BIBLIO_RESULTS
=> \
@results,
94 shelfname
=> $shelf->shelfname,
97 # Getting template result
98 my $template_res = $template2->output();
102 # Analysing information and getting mail properties
103 if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
104 $subject = $+{subject
};
105 $subject =~ s
|\n?
(.*)\n?
|$1|;
108 $subject = "no subject";
111 my $email_header = "";
112 if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
114 $email_header =~ s
|\n?
(.*)\n?
|$1|;
117 if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
119 $body =~ s
|\n?
(.*)\n?
|$1|;
122 my $THE_body = <<END_OF_BODY;
128 my $email = Koha::Email->create(
134 $email->text_body( $THE_body );
136 Encode::encode("UTF-8", $iso2709),
137 content_type => 'application/octet-stream',
138 name => 'shelf.iso2709',
139 disposition => 'attachment',
142 my $library = Koha::Patrons->find( $borrowernumber )->library;
143 $email->send_or_die({ transport => $library->smtp_server->transport });
144 $template->param( SENT => "1" );
147 carp "Error sending mail: $_";
148 $template->param( error => 1 );
151 $template->param( email => $to_address );
152 output_html_with_http_headers $query, $cookie, $template->output;
158 url => "/cgi-bin/koha/virtualshelves/sendshelf.pl",
160 output_html_with_http_headers $query, $cookie, $template->output;