|
Lines 26-34
use Try::Tiny qw( catch try );
Link Here
|
| 26 |
|
26 |
|
| 27 |
use C4::Auth qw( get_template_and_user ); |
27 |
use C4::Auth qw( get_template_and_user ); |
| 28 |
use C4::Biblio qw( |
28 |
use C4::Biblio qw( |
| 29 |
GetFrameworkCode |
29 |
GetFrameworkCode |
| 30 |
GetMarcISBN |
30 |
GetMarcISBN |
| 31 |
GetMarcSubjects |
31 |
GetMarcSubjects |
| 32 |
); |
32 |
); |
| 33 |
use C4::Output qw( output_html_with_http_headers ); |
33 |
use C4::Output qw( output_html_with_http_headers ); |
| 34 |
use Koha::Biblios; |
34 |
use Koha::Biblios; |
|
Lines 39-141
use Koha::Virtualshelves;
Link Here
|
| 39 |
my $query = CGI->new; |
39 |
my $query = CGI->new; |
| 40 |
|
40 |
|
| 41 |
# if virtualshelves is disabled, leave immediately |
41 |
# if virtualshelves is disabled, leave immediately |
| 42 |
if ( ! C4::Context->preference('virtualshelves') ) { |
42 |
if ( !C4::Context->preference('virtualshelves') ) { |
| 43 |
print $query->redirect("/cgi-bin/koha/errors/404.pl"); |
43 |
print $query->redirect("/cgi-bin/koha/errors/404.pl"); |
| 44 |
exit; |
44 |
exit; |
| 45 |
} |
45 |
} |
| 46 |
|
46 |
|
| 47 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( |
47 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
| 48 |
{ |
48 |
{ |
| 49 |
template_name => "opac-sendshelfform.tt", |
49 |
template_name => "opac-sendshelfform.tt", |
| 50 |
query => $query, |
50 |
query => $query, |
| 51 |
type => "opac", |
51 |
type => "opac", |
| 52 |
} |
52 |
} |
| 53 |
); |
53 |
); |
| 54 |
|
54 |
|
| 55 |
my $shelfid = $query->param('shelfid'); |
55 |
my $shelfid = $query->param('shelfid'); |
| 56 |
my $email = $query->param('email'); |
56 |
my $email = $query->param('email'); |
| 57 |
|
57 |
|
| 58 |
my $shelf = Koha::Virtualshelves->find( $shelfid ); |
58 |
my $shelf = Koha::Virtualshelves->find($shelfid); |
| 59 |
if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { |
59 |
if ( $shelf and $shelf->can_be_viewed($borrowernumber) ) { |
| 60 |
if ( $email ) { |
60 |
if ($email) { |
| 61 |
my $comment = $query->param('comment'); |
61 |
my $comment = $query->param('comment'); |
| 62 |
|
62 |
|
| 63 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
63 |
my $patron = Koha::Patrons->find($borrowernumber); |
| 64 |
my $user_email = $patron->first_valid_email_address; |
64 |
my $user_email = $patron->first_valid_email_address; |
| 65 |
my $shelf = Koha::Virtualshelves->find( $shelfid ); |
65 |
my $shelf = Koha::Virtualshelves->find($shelfid); |
| 66 |
my $contents = $shelf->get_contents; |
66 |
my $contents = $shelf->get_contents; |
| 67 |
my $iso2709; |
67 |
my $iso2709; |
| 68 |
|
68 |
|
| 69 |
my @biblionumbers; |
69 |
my @biblionumbers; |
| 70 |
while ( my $content = $contents->next ) { |
70 |
while ( my $content = $contents->next ) { |
| 71 |
push @biblionumbers, $content->biblionumber; |
71 |
push @biblionumbers, $content->biblionumber; |
| 72 |
my $biblio = Koha::Biblios->find($content->biblionumber); |
72 |
my $biblio = Koha::Biblios->find( $content->biblionumber ); |
| 73 |
$iso2709 .= $biblio->metadata->record->as_usmarc(); |
73 |
$iso2709 .= $biblio->metadata->record->as_usmarc(); |
| 74 |
}; |
74 |
} |
| 75 |
|
75 |
|
| 76 |
if ( !defined $iso2709 ) { |
76 |
if ( !defined $iso2709 ) { |
| 77 |
carp "Error sending mail: empty list"; |
77 |
carp "Error sending mail: empty list"; |
| 78 |
$template->param( error => 1 ); |
78 |
$template->param( error => 1 ); |
| 79 |
} elsif ( !defined $user_email or $user_email eq '' ) { |
79 |
} |
| 80 |
carp "Error sending mail: sender's email address is invalid"; |
80 |
elsif ( !defined $user_email or $user_email eq '' ) { |
| 81 |
$template->param( error => 1 ); |
81 |
carp "Error sending mail: sender's email address is invalid"; |
| 82 |
} else { |
82 |
$template->param( error => 1 ); |
| 83 |
my %loops = ( |
83 |
} |
| 84 |
biblio => \@biblionumbers, |
84 |
else { |
| 85 |
); |
85 |
my %loops = ( biblio => \@biblionumbers, ); |
| 86 |
|
86 |
|
| 87 |
my %substitute = ( |
87 |
my %substitute = ( |
| 88 |
comment => $comment, |
88 |
comment => $comment, |
| 89 |
listname => $shelf->shelfname, |
89 |
listname => $shelf->shelfname, |
| 90 |
); |
90 |
); |
| 91 |
|
91 |
|
| 92 |
my $letter = C4::Letters::GetPreparedLetter( |
92 |
my $letter = C4::Letters::GetPreparedLetter( |
| 93 |
module => 'catalogue', |
93 |
module => 'catalogue', |
| 94 |
letter_code => 'LIST', |
94 |
letter_code => 'LIST', |
| 95 |
lang => $patron->lang, |
95 |
lang => $patron->lang, |
| 96 |
tables => { |
96 |
tables => { |
| 97 |
borrowers => $borrowernumber, |
97 |
borrowers => $borrowernumber, |
| 98 |
}, |
98 |
}, |
| 99 |
message_transport_type => 'email', |
99 |
message_transport_type => 'email', |
| 100 |
loops => \%loops, |
100 |
loops => \%loops, |
| 101 |
substitute => \%substitute, |
101 |
substitute => \%substitute, |
|
|
102 |
); |
| 103 |
|
| 104 |
my $attachment = { |
| 105 |
filename => 'list.iso2709', |
| 106 |
type => 'application/octet-stream', |
| 107 |
content => Encode::encode( "UTF-8", $iso2709 ), |
| 108 |
}; |
| 109 |
|
| 110 |
my $message_id = C4::Letters::EnqueueLetter( |
| 111 |
{ |
| 112 |
letter => $letter, |
| 113 |
message_transport_type => 'email', |
| 114 |
borrowernumber => $patron->borrowernumber, |
| 115 |
to_address => $email, |
| 116 |
reply_address => $user_email, |
| 117 |
attachments => [$attachment], |
| 118 |
} |
| 119 |
); |
| 120 |
|
| 121 |
C4::Letters::SendQueuedMessages( { message_id => $message_id } ); |
| 122 |
|
| 123 |
$template->param( SENT => 1 ); |
| 124 |
} |
| 125 |
|
| 126 |
$template->param( |
| 127 |
shelfid => $shelfid, |
| 128 |
email => $email, |
| 102 |
); |
129 |
); |
|
|
130 |
output_html_with_http_headers $query, $cookie, $template->output, |
| 131 |
undef, { force_no_caching => 1 }; |
| 103 |
|
132 |
|
| 104 |
my $attachment = { |
|
|
| 105 |
filename => 'list.iso2709', |
| 106 |
type => 'application/octet-stream', |
| 107 |
content => Encode::encode("UTF-8", $iso2709), |
| 108 |
}; |
| 109 |
|
| 110 |
my $message_id = C4::Letters::EnqueueLetter({ |
| 111 |
letter => $letter, |
| 112 |
message_transport_type => 'email', |
| 113 |
borrowernumber => $patron->borrowernumber, |
| 114 |
to_address => $email, |
| 115 |
reply_address => $user_email, |
| 116 |
attachments => [$attachment], |
| 117 |
}); |
| 118 |
|
| 119 |
C4::Letters::SendQueuedMessages({ message_id => $message_id }); |
| 120 |
|
| 121 |
$template->param( SENT => 1 ); |
| 122 |
} |
133 |
} |
| 123 |
|
134 |
else { |
|
|
135 |
$template->param( |
| 136 |
shelfid => $shelfid, |
| 137 |
url => "/cgi-bin/koha/opac-sendshelf.pl", |
| 138 |
); |
| 139 |
output_html_with_http_headers $query, $cookie, $template->output, |
| 140 |
undef, { force_no_caching => 1 }; |
| 141 |
} |
| 142 |
} |
| 143 |
else { |
| 124 |
$template->param( |
144 |
$template->param( |
| 125 |
shelfid => $shelfid, |
145 |
invalidlist => 1, |
| 126 |
email => $email, |
146 |
url => "/cgi-bin/koha/opac-sendshelf.pl", |
| 127 |
); |
|
|
| 128 |
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; |
| 129 |
|
| 130 |
} else { |
| 131 |
$template->param( shelfid => $shelfid, |
| 132 |
url => "/cgi-bin/koha/opac-sendshelf.pl", |
| 133 |
); |
| 134 |
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; |
| 135 |
} |
| 136 |
} else { |
| 137 |
$template->param( invalidlist => 1, |
| 138 |
url => "/cgi-bin/koha/opac-sendshelf.pl", |
| 139 |
); |
147 |
); |
| 140 |
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; |
148 |
output_html_with_http_headers $query, $cookie, $template->output, undef, |
|
|
149 |
{ force_no_caching => 1 }; |
| 141 |
} |
150 |
} |