3 # Copyright 2009 SARL 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 );
34 use Koha
::Virtualshelves
;
38 # if virtualshelves is disabled, leave immediately
39 if ( ! C4
::Context
->preference('virtualshelves') ) {
40 print $query->redirect("/cgi-bin/koha/errors/404.pl");
44 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
46 template_name
=> "opac-sendshelfform.tt",
52 my $shelfid = $query->param('shelfid');
53 my $email = $query->param('email');
55 my $dbh = C4
::Context
->dbh;
57 my $shelf = Koha
::Virtualshelves
->find( $shelfid );
58 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) {
61 my $comment = $query->param('comment');
63 my ( $template2, $borrowernumber, $cookie ) = get_template_and_user
(
65 template_name
=> "opac-sendshelf.tt",
72 my $patron = Koha
::Patrons
->find( $borrowernumber );
73 my $borcat = $patron ?
$patron->categorycode : q{};
75 my $shelf = Koha
::Virtualshelves
->find( $shelfid );
76 my $contents = $shelf->get_contents;
77 my $marcflavour = C4
::Context
->preference('marcflavour');
81 while ( my $content = $contents->next ) {
82 my $biblionumber = $content->biblionumber;
83 my $record = GetMarcBiblio
({
84 biblionumber
=> $biblionumber,
89 my $fw = GetFrameworkCode
($biblionumber);
90 my $dat = GetBiblioData
($biblionumber);
92 my $marcauthorsarray = GetMarcAuthors
( $record, $marcflavour );
93 my $marcsubjctsarray = GetMarcSubjects
( $record, $marcflavour );
95 my @items = GetItemsInfo
( $biblionumber );
97 $dat->{ISBN
} = GetMarcISBN
($record, $marcflavour);
98 $dat->{MARCSUBJCTS
} = $marcsubjctsarray;
99 $dat->{MARCAUTHORS
} = $marcauthorsarray;
100 $dat->{'biblionumber'} = $biblionumber;
101 $dat->{ITEM_RESULTS
} = \
@items;
102 $dat->{HASAUTHORS
} = $dat->{'author'} || @
$marcauthorsarray;
104 $iso2709 .= $record->as_usmarc();
106 push( @results, $dat );
110 BIBLIO_RESULTS
=> \
@results,
112 shelfname
=> $shelf->shelfname,
113 firstname
=> $patron->firstname,
114 surname
=> $patron->surname,
117 # Getting template result
118 my $template_res = $template2->output();
122 # Analysing information and getting mail properties
123 if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
124 $subject = $+{subject
};
125 $subject =~ s
|\n?
(.*)\n?
|$1|;
128 $subject = "no subject";
131 my $email = Koha
::Email
->create(
138 my $email_header = "";
139 if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
141 $email_header =~ s
|\n?
(.*)\n?
|$1|;
142 $email_header = Encode
::encode
("UTF-8", $email_header);
145 if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
147 $body =~ s
|\n?
(.*)\n?
|$1|;
148 $body = Encode
::encode
("UTF-8", $body);
151 my $THE_body = <<END_OF_BODY;
156 $email->text_body( $THE_body );
159 content_type => 'application/octet-stream',
160 name => 'list.iso2709',
161 disposition => 'attachment',
165 my $library = Koha::Patrons->find( $borrowernumber )->library;
166 $email->transport( $library->smtp_server->transport );
168 $template->param( SENT => "1" );
171 carp "Error sending mail: $_";
172 $template->param( error => 1 );
179 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
183 $template->param( shelfid => $shelfid,
184 url => "/cgi-bin/koha/opac-sendshelf.pl",
186 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
190 $template->param( invalidlist => 1,
191 url => "/cgi-bin/koha/opac-sendshelf.pl",
193 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };