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
;
33 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
35 template_name
=> "opac-reportproblem.tt",
42 my $problempage = $ENV{HTTP_REFERER
};
43 my $member = Koha
::Patrons
->find($borrowernumber);
44 my $username = $member->userid;
45 my $branchcode = $member->branchcode;
46 my $library = Koha
::Libraries
->find($branchcode);
50 ( !defined($library->branchreplyto) || $library->branchreplyto eq '' ) &&
51 ( C4
::Context
->preference('ReplytoDefault') eq '' ) &&
52 ( !defined($library->branchemail) || $library->branchemail eq '' )
54 $template->param( nolibemail
=> 1 );
58 my $koha_admin = C4
::Context
->preference('KohaAdminEmailAddress');
59 if ( $koha_admin eq '' ) {
60 $template->param( noadminemail
=> 1 );
65 username
=> $username,
66 probpage
=> $problempage,
69 my $op = $input->param('op') || '';
70 if ( $op eq 'addreport' ) {
72 if ( $recipients == 0 ){
73 print $input->redirect("/cgi-bin/koha/opac-reportproblem?norecipients=1.pl");
77 my $subject = $input->param('subject');
78 my $message = $input->param('message');
79 my $place = $input->param('place');
80 my $recipient = $input->param('recipient') || 'library';
81 my $problem = Koha
::ProblemReport
->new({ title
=> $subject, content
=> $message, borrowernumber
=> $borrowernumber, branchcode
=> $branchcode, username
=> $username, problempage
=> $place, recipient
=> $recipient, reportdate
=> dt_from_string
() })->store;
83 recipient
=> $recipient,
88 my $problemreport = $problem->unblessed;
89 $problemreport->{code
} = 'PROBLEM_REPORT';
90 $problemreport->{content
} .= "\nUsername: $username";
91 $problemreport->{content
} .= "\nProblem page: $place";
92 my $transport = 'email';
94 my $from_address = $member->email || $member->emailpro || $member->B_email || $koha_admin;
96 if ( $recipient eq 'admin' ) {
97 C4
::Letters
::EnqueueLetter
({
98 letter
=> $problemreport,
99 borrowernumber
=> $borrowernumber,
100 message_transport_type
=> $transport,
101 to_address
=> $koha_admin,
102 from_address
=> $from_address,
105 my $to_address = $library->branchreplyto ||
106 C4
::Context
->preference('ReplytoDefault') ||
107 $library->branchemail;
108 C4
::Letters
::EnqueueLetter
({
109 letter
=> $problemreport,
110 borrowernumber
=> $borrowernumber,
111 message_transport_type
=> $transport,
112 to_address
=> $to_address,
113 from_address
=> $from_address,
118 output_html_with_http_headers
$input, $cookie, $template->output;