Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Copyright 2017 Aleisha Amohia <aleisha@catalyst.net.nz> |
6 |
# |
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. |
11 |
# |
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. |
16 |
# |
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>. |
19 |
|
20 |
|
21 |
use Modern::Perl; |
22 |
use CGI qw ( -utf8 ); |
23 |
use C4::Auth; # get_template_and_user |
24 |
use C4::Output; |
25 |
use C4::Members; |
26 |
use C4::Letters; |
27 |
use Koha::ProblemReport; |
28 |
use Koha::DateUtils; |
29 |
use Koha::Libraries; |
30 |
|
31 |
my $input = new CGI; |
32 |
|
33 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
34 |
{ |
35 |
template_name => "opac-reportproblem.tt", |
36 |
type => "opac", |
37 |
query => $input, |
38 |
authnotrequired => 0, |
39 |
} |
40 |
); |
41 |
|
42 |
my $problempage = $ENV{HTTP_REFERER}; |
43 |
my $member = GetMember( borrowernumber => $borrowernumber ); |
44 |
my $username = $member->{'userid'}; |
45 |
my $branchcode = $member->{'branchcode'}; |
46 |
my $recipient = $input->param('recipient') || 'library'; |
47 |
$template->param( |
48 |
username => $username, |
49 |
probpage => $problempage, |
50 |
); |
51 |
|
52 |
my $op = $input->param('op') || ''; |
53 |
if ( $op eq 'addreport' ) { |
54 |
my $subject = $input->param('subject'); |
55 |
my $message = $input->param('message'); |
56 |
my $place = $input->param('place'); |
57 |
my $problem = Koha::ProblemReport->new({ title => $subject, content => $message, borrowernumber => $borrowernumber, branchcode => $branchcode, username => $username, problempage => $place, recipient => $recipient, reportdate => dt_from_string() })->store; |
58 |
$template->param( |
59 |
recipient => $recipient, |
60 |
successfuladd => 1, |
61 |
probpage => $place, |
62 |
); |
63 |
|
64 |
my $problemreport = $problem->unblessed; |
65 |
$problemreport->{code} = 'PROBLEM_REPORT'; |
66 |
$problemreport->{content} .= "\nUsername: $username"; |
67 |
$problemreport->{content} .= "\nProblem page: $place"; |
68 |
my $transport = 'email'; |
69 |
|
70 |
my $koha_admin = C4::Context->preference('KohaAdminEmailAddress'); |
71 |
my $from_address = $member->{email} || $member->{emailpro} || $member->{B_email} || $koha_admin; |
72 |
|
73 |
if ( $recipient eq 'admin' ) { |
74 |
C4::Letters::EnqueueLetter({ |
75 |
letter => $problemreport, |
76 |
borrowernumber => $borrowernumber, |
77 |
message_transport_type => $transport, |
78 |
to_address => $koha_admin, |
79 |
from_address => $from_address, |
80 |
}); |
81 |
} else { |
82 |
my $library = Koha::Libraries->find($branchcode); |
83 |
my $to_address = $library->branchemail; |
84 |
C4::Letters::EnqueueLetter({ |
85 |
letter => $problemreport, |
86 |
borrowernumber => $borrowernumber, |
87 |
message_transport_type => $transport, |
88 |
to_address => $to_address, |
89 |
from_address => $from_address, |
90 |
}); |
91 |
} |
92 |
} |
93 |
|
94 |
output_html_with_http_headers $input, $cookie, $template->output; |