3 # This file is part of Koha.
5 # Copyright 2019 Aleisha Amohia <aleisha@catalyst.net.nz>
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>.
22 use C4::Auth; # get_template_and_user
26 use Koha::ProblemReport;
30 use Koha::Util::Navigation;
34 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
36 template_name => "opac-reportproblem.tt",
43 if ( !C4::Context->preference('OPACReportProblem')
44 || !C4::Context->preference('KohaAdminEmailAddress') )
46 print $input->redirect("/cgi-bin/koha/errors/404.pl");
49 my $problempage = C4::Context->preference('OPACBaseURL') . Koha::Util::Navigation::local_referer($input );
51 my $member = Koha::Patrons->find($borrowernumber);
52 my $username = $member->userid;
53 my $branchcode = $member->branchcode;
54 my $library = Koha::Libraries->find($branchcode);
58 ( !defined($library->branchreplyto) || $library->branchreplyto eq '' ) &&
59 ( C4::Context->preference('ReplytoDefault') eq '' ) &&
60 ( !defined($library->branchemail) || $library->branchemail eq '' )
62 $template->param( nolibemail => 1 );
66 my $koha_admin = C4::Context->preference('KohaAdminEmailAddress');
67 if ( $koha_admin eq '' ) {
68 $template->param( noadminemail => 1 );
73 username => $username,
74 probpage => $problempage,
77 my $op = $input->param('op') || '';
78 if ( $op eq 'addreport' ) {
80 if ( $recipients == 0 ){
81 print $input->redirect("/cgi-bin/koha/opac-reportproblem?norecipients=1.pl");
85 my $subject = $input->param('subject');
86 my $message = $input->param('message');
87 my $place = $input->param('place');
88 my $recipient = $input->param('recipient') || 'library';
89 my $problem = Koha::ProblemReport->new(
93 borrowernumber => $borrowernumber,
94 branchcode => $branchcode,
95 username => $username,
96 problempage => $place,
97 recipient => $recipient,
101 recipient => $recipient,
106 # send notice to library
107 my $letter = C4::Letters::GetPreparedLetter(
109 letter_code => 'PROBLEM_REPORT',
110 branchcode => $problem->branchcode,
112 'problem_reports', $problem->reportid
116 my $from_address = C4::Context->preference('KohaAdminEmailAddress');
117 my $transport = 'email';
119 if ( $recipient eq 'admin' ) {
120 C4::Letters::EnqueueLetter({
122 borrowernumber => $borrowernumber,
123 message_transport_type => $transport,
124 to_address => $koha_admin,
125 from_address => $from_address,
128 my $to_address = $library->branchreplyto ||
129 C4::Context->preference('ReplytoDefault') ||
130 $library->branchemail;
131 C4::Letters::EnqueueLetter({
133 borrowernumber => $borrowernumber,
134 message_transport_type => $transport,
135 to_address => $to_address,
136 from_address => $from_address,
141 output_html_with_http_headers $input, $cookie, $template->output;