Lines 27-32
use C4::Letters;
Link Here
|
27 |
use Koha::ProblemReport; |
27 |
use Koha::ProblemReport; |
28 |
use Koha::DateUtils; |
28 |
use Koha::DateUtils; |
29 |
use Koha::Libraries; |
29 |
use Koha::Libraries; |
|
|
30 |
use Koha::Patrons; |
30 |
|
31 |
|
31 |
my $input = new CGI; |
32 |
my $input = new CGI; |
32 |
|
33 |
|
Lines 35-100
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
Link Here
|
35 |
template_name => "opac-reportproblem.tt", |
36 |
template_name => "opac-reportproblem.tt", |
36 |
type => "opac", |
37 |
type => "opac", |
37 |
query => $input, |
38 |
query => $input, |
38 |
authnotrequired => 0, |
39 |
authnotrequired => 1, |
39 |
} |
40 |
} |
40 |
); |
41 |
); |
41 |
|
42 |
|
42 |
my $problempage = $ENV{HTTP_REFERER}; |
43 |
if ( $borrowernumber ) { # if user is logged in |
43 |
my $member = GetMember( borrowernumber => $borrowernumber ); |
|
|
44 |
my $username = $member->{'userid'}; |
45 |
my $branchcode = $member->{'branchcode'}; |
46 |
my $library = Koha::Libraries->find($branchcode); |
47 |
if ( $library->branchemail eq undef || ! $library->branchemail ) { |
48 |
$template->param( nolibemail => 1 ); |
49 |
} |
50 |
my $koha_admin = C4::Context->preference('KohaAdminEmailAddress'); |
51 |
if ( ! $koha_admin ) { |
52 |
$template->param( noadminemail => 1 ); |
53 |
} |
54 |
my $recipient = $input->param('recipient') || 'library'; |
55 |
$template->param( |
56 |
username => $username, |
57 |
probpage => $problempage, |
58 |
); |
59 |
|
44 |
|
60 |
my $op = $input->param('op') || ''; |
45 |
my $problempage = $ENV{HTTP_REFERER}; |
61 |
if ( $op eq 'addreport' ) { |
46 |
my $member = Koha::Patrons->find( $borrowernumber ); |
62 |
my $subject = $input->param('subject'); |
47 |
my $username = $member->userid; |
63 |
my $message = $input->param('message'); |
48 |
my $branchcode = $member->branchcode; |
64 |
my $place = $input->param('place'); |
49 |
my $library = Koha::Libraries->find($branchcode); |
65 |
my $problem = Koha::ProblemReport->new({ title => $subject, content => $message, borrowernumber => $borrowernumber, branchcode => $branchcode, username => $username, problempage => $place, recipient => $recipient, reportdate => dt_from_string() })->store; |
50 |
if ( ( !defined $library->branchreplyto ) && ( !defined C4::Context->preference('ReplytoDefault') ) && ( !defined $library->branchemail ) ) { |
|
|
51 |
$template->param( nolibemail => 1 ); |
52 |
} |
53 |
my $koha_admin = C4::Context->preference('KohaAdminEmailAddress'); |
54 |
if ( !$koha_admin ) { |
55 |
$template->param( noadminemail => 1 ); |
56 |
} |
57 |
my $recipient = $input->param('recipient') || 'library'; |
66 |
$template->param( |
58 |
$template->param( |
67 |
recipient => $recipient, |
59 |
username => $username, |
68 |
successfuladd => 1, |
60 |
probpage => $problempage, |
69 |
probpage => $place, |
|
|
70 |
); |
61 |
); |
71 |
|
62 |
|
72 |
my $problemreport = $problem->unblessed; |
63 |
my $op = $input->param('op') || ''; |
73 |
$problemreport->{code} = 'PROBLEM_REPORT'; |
64 |
if ( $op eq 'addreport' ) { |
74 |
$problemreport->{content} .= "\nUsername: $username"; |
65 |
# if user does not have JS enabled and the submit button is still enabled, the following lines ensure a report isn't submitted if the required recipient emails don't exist |
75 |
$problemreport->{content} .= "\nProblem page: $place"; |
66 |
if ( $recipient eq 'admin' && !$koha_admin ) { |
76 |
my $transport = 'email'; |
67 |
$template->param( failedadd_admin => 1 ); |
|
|
68 |
} elsif ( ( !defined $library->branchreplyto ) && ( !defined C4::Context->preference('ReplytoDefault') ) && ( !defined $library->branchemail ) ) { |
69 |
$template->param( failedadd_lib => 1 ); |
70 |
} else { |
71 |
|
72 |
my $subject = $input->param('subject'); |
73 |
my $message = $input->param('message'); |
74 |
my $place = $input->param('place'); |
75 |
my $problem = Koha::ProblemReport->new({ title => $subject, content => $message, borrowernumber => $borrowernumber, branchcode => $branchcode, username => $username, problempage => $place, recipient => $recipient, reportdate => dt_from_string() })->store; |
76 |
$template->param( |
77 |
recipient => $recipient, |
78 |
successfuladd => 1, |
79 |
probpage => $place, |
80 |
); |
77 |
|
81 |
|
78 |
my $from_address = $member->{email} || $member->{emailpro} || $member->{B_email} || $koha_admin; |
82 |
my $problemreport = $problem->unblessed; |
|
|
83 |
$problemreport->{code} = 'PROBLEM_REPORT'; |
84 |
$problemreport->{content} .= "\nUsername: $username"; |
85 |
$problemreport->{content} .= "\nProblem page: $place"; |
86 |
my $transport = 'email'; |
79 |
|
87 |
|
80 |
if ( $recipient eq 'admin' ) { |
88 |
my $from_address = $member->email || $member->emailpro || $member->B_email || $koha_admin; |
81 |
C4::Letters::EnqueueLetter({ |
89 |
|
82 |
letter => $problemreport, |
90 |
if ( $recipient eq 'admin' ) { |
83 |
borrowernumber => $borrowernumber, |
91 |
C4::Letters::EnqueueLetter({ |
84 |
message_transport_type => $transport, |
92 |
letter => $problemreport, |
85 |
to_address => $koha_admin, |
93 |
borrowernumber => $borrowernumber, |
86 |
from_address => $from_address, |
94 |
message_transport_type => $transport, |
87 |
}); |
95 |
to_address => $koha_admin, |
88 |
} else { |
96 |
from_address => $from_address, |
89 |
my $to_address = $library->branchemail; |
97 |
}); |
90 |
C4::Letters::EnqueueLetter({ |
98 |
} else { |
91 |
letter => $problemreport, |
99 |
my $to_address = $library->branchreplyto || C4::Context->preference('ReplytoDefault') || $library->branchemail; |
92 |
borrowernumber => $borrowernumber, |
100 |
C4::Letters::EnqueueLetter({ |
93 |
message_transport_type => $transport, |
101 |
letter => $problemreport, |
94 |
to_address => $to_address, |
102 |
borrowernumber => $borrowernumber, |
95 |
from_address => $from_address, |
103 |
message_transport_type => $transport, |
96 |
}); |
104 |
to_address => $to_address, |
|
|
105 |
from_address => $from_address, |
106 |
}); |
107 |
} |
108 |
} |
97 |
} |
109 |
} |
|
|
110 |
|
111 |
} else { # if no user logged in |
112 |
my $problempage = $ENV{HTTP_REFERER}; |
113 |
$template->param( probpage => $problempage ); |
98 |
} |
114 |
} |
99 |
|
115 |
|
100 |
output_html_with_http_headers $input, $cookie, $template->output; |
116 |
output_html_with_http_headers $input, $cookie, $template->output; |
101 |
- |
|
|