Lines 19-30
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
use CGI qw ( -utf8 ); |
21 |
use CGI qw ( -utf8 ); |
|
|
22 |
use Try::Tiny; |
23 |
|
22 |
use C4::Auth; # get_template_and_user |
24 |
use C4::Auth; # get_template_and_user |
23 |
use C4::Output; |
25 |
use C4::Output; |
24 |
use C4::Members; |
|
|
25 |
use C4::Letters; |
26 |
use C4::Letters; |
26 |
use Koha::ProblemReport; |
27 |
use Koha::ProblemReport; |
27 |
use Koha::DateUtils; |
|
|
28 |
use Koha::Libraries; |
28 |
use Koha::Libraries; |
29 |
use Koha::Patrons; |
29 |
use Koha::Patrons; |
30 |
use Koha::Util::Navigation; |
30 |
use Koha::Util::Navigation; |
Lines 48-62
if ( !C4::Context->preference('OPACReportProblem')
Link Here
|
48 |
|
48 |
|
49 |
my $problempage = C4::Context->preference('OPACBaseURL') . Koha::Util::Navigation::local_referer($input ); |
49 |
my $problempage = C4::Context->preference('OPACBaseURL') . Koha::Util::Navigation::local_referer($input ); |
50 |
|
50 |
|
51 |
my $member = Koha::Patrons->find($borrowernumber); |
51 |
my $patron = Koha::Patrons->find($borrowernumber); |
52 |
my $username = $member->userid; |
52 |
my $username = $patron->userid; |
53 |
my $branchcode = $member->branchcode; |
53 |
my $branchcode = $patron->branchcode; |
54 |
my $library = Koha::Libraries->find($branchcode); |
54 |
my $library = Koha::Libraries->find($branchcode); |
|
|
55 |
my @messages; |
55 |
|
56 |
|
56 |
$template->param( |
57 |
$template->param( |
57 |
username => $username, |
58 |
username => $username, |
58 |
probpage => $problempage, |
59 |
problempage => $problempage, |
59 |
library => $library, |
60 |
library => $library, |
60 |
); |
61 |
); |
61 |
|
62 |
|
62 |
my $op = $input->param('op') || ''; |
63 |
my $op = $input->param('op') || ''; |
Lines 64-118
if ( $op eq 'addreport' ) {
Link Here
|
64 |
|
65 |
|
65 |
my $subject = $input->param('subject'); |
66 |
my $subject = $input->param('subject'); |
66 |
my $message = $input->param('message'); |
67 |
my $message = $input->param('message'); |
67 |
my $place = $input->param('place'); |
68 |
my $problempage = $input->param('problempage'); |
68 |
my $recipient = $input->param('recipient') || 'admin'; |
69 |
my $recipient = $input->param('recipient') || 'admin'; |
69 |
my $problem = Koha::ProblemReport->new( |
70 |
|
70 |
{ |
71 |
try { |
71 |
title => $subject, |
72 |
my $schema = Koha::Database->new->schema; |
72 |
content => $message, |
73 |
$schema->txn_do( |
73 |
borrowernumber => $borrowernumber, |
74 |
sub { |
74 |
branchcode => $branchcode, |
75 |
my $problem = Koha::ProblemReport->new( |
75 |
username => $username, |
76 |
{ |
76 |
problempage => $place, |
77 |
title => $subject, |
77 |
recipient => $recipient, |
78 |
content => $message, |
78 |
} |
79 |
borrowernumber => $borrowernumber, |
79 |
)->store; |
80 |
branchcode => $branchcode, |
80 |
$template->param( |
81 |
username => $username, |
81 |
recipient => $recipient, |
82 |
problempage => $problempage, |
82 |
successfuladd => 1, |
83 |
recipient => $recipient, |
83 |
probpage => $place, |
84 |
} |
84 |
); |
85 |
)->store; |
85 |
|
86 |
|
86 |
# send notice to library |
87 |
# send notice to library |
87 |
my $letter = C4::Letters::GetPreparedLetter( |
88 |
my $letter = C4::Letters::GetPreparedLetter( |
88 |
module => 'members', |
89 |
module => 'members', |
89 |
letter_code => 'PROBLEM_REPORT', |
90 |
letter_code => 'PROBLEM_REPORT', |
90 |
branchcode => $problem->branchcode, |
91 |
branchcode => $problem->branchcode, |
91 |
tables => { |
92 |
tables => { |
92 |
'problem_reports', $problem->reportid |
93 |
'problem_reports', $problem->reportid |
93 |
} |
94 |
} |
94 |
); |
95 |
); |
95 |
|
96 |
|
96 |
my $from_address = C4::Context->preference('KohaAdminEmailAddress'); |
97 |
my $from_address = C4::Context->preference('KohaAdminEmailAddress'); |
97 |
my $transport = 'email'; |
98 |
my $transport = 'email'; |
98 |
|
99 |
|
99 |
if ( $recipient eq 'admin' ) { |
100 |
if ( $recipient eq 'admin' ) { |
100 |
C4::Letters::EnqueueLetter({ |
101 |
C4::Letters::EnqueueLetter({ |
101 |
letter => $letter, |
102 |
letter => $letter, |
102 |
borrowernumber => $borrowernumber, |
103 |
borrowernumber => $borrowernumber, |
103 |
message_transport_type => $transport, |
104 |
message_transport_type => $transport, |
104 |
to_address => C4::Context->preference('KohaAdminEmailAddress'), |
105 |
to_address => C4::Context->preference('KohaAdminEmailAddress'), |
105 |
from_address => $from_address, |
106 |
from_address => $from_address, |
106 |
}); |
107 |
}); |
107 |
} else { |
108 |
} else { |
108 |
C4::Letters::EnqueueLetter({ |
109 |
C4::Letters::EnqueueLetter({ |
109 |
letter => $letter, |
110 |
letter => $letter, |
110 |
borrowernumber => $borrowernumber, |
111 |
borrowernumber => $borrowernumber, |
111 |
message_transport_type => $transport, |
112 |
message_transport_type => $transport, |
112 |
to_address => $library->branchemail, |
113 |
to_address => $library->branchemail, |
113 |
from_address => $from_address, |
114 |
from_address => $from_address, |
114 |
}); |
115 |
}); |
|
|
116 |
} |
117 |
|
118 |
push @messages, { |
119 |
type => 'info', |
120 |
code => 'success_on_send', |
121 |
}; |
122 |
|
123 |
$template->param( |
124 |
recipient => $recipient, |
125 |
); |
126 |
} |
127 |
); |
128 |
} |
129 |
catch { |
130 |
warn "Something wrong happened when sending the report problem: $_"; |
131 |
push @messages, { |
132 |
type => 'error', |
133 |
code => 'error_on_send', |
134 |
}; |
115 |
} |
135 |
} |
116 |
} |
136 |
} |
117 |
|
137 |
|
|
|
138 |
$template->param( messages => \@messages ); |
139 |
|
118 |
output_html_with_http_headers $input, $cookie, $template->output; |
140 |
output_html_with_http_headers $input, $cookie, $template->output; |
119 |
- |
|
|