|
Lines 50-237
my ( $template, $patronnumber, $cookie ) = get_template_and_user( {
Link Here
|
| 50 |
flagsrequired => { ill => '*' }, |
50 |
flagsrequired => { ill => '*' }, |
| 51 |
} ); |
51 |
} ); |
| 52 |
|
52 |
|
| 53 |
if ( $op eq 'illview' ) { |
53 |
# Are we able to actually work? |
| 54 |
# View the details of an ILL |
54 |
my $backends = Koha::Illrequest::Config->new->available_backends; |
| 55 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
55 |
my $backends_available = ( scalar @{$backends} > 0 ); |
| 56 |
|
56 |
$template->param( backends_available => $backends_available ); |
| 57 |
$template->param( |
57 |
|
| 58 |
request => $request |
58 |
if ( $backends_available ) { |
| 59 |
); |
59 |
if ( $op eq 'illview' ) { |
| 60 |
|
60 |
# View the details of an ILL |
| 61 |
} elsif ( $op eq 'create' ) { |
61 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
| 62 |
# We're in the process of creating a request |
62 |
|
| 63 |
my $request = Koha::Illrequest->new |
63 |
$template->param( |
| 64 |
->load_backend($params->{backend}); |
64 |
request => $request |
| 65 |
my $backend_result = $request->backend_create($params); |
65 |
); |
| 66 |
$template->param( |
66 |
|
| 67 |
whole => $backend_result, |
67 |
} elsif ( $op eq 'create' ) { |
| 68 |
request => $request |
68 |
# We're in the process of creating a request |
| 69 |
); |
69 |
my $request = Koha::Illrequest->new->load_backend( $params->{backend} ); |
| 70 |
handle_commit_maybe($backend_result, $request); |
70 |
my $backend_result = $request->backend_create($params); |
| 71 |
|
|
|
| 72 |
} elsif ( $op eq 'confirm' ) { |
| 73 |
# Backend 'confirm' method |
| 74 |
# confirm requires a specific request, so first, find it. |
| 75 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
| 76 |
my $backend_result = $request->backend_confirm($params); |
| 77 |
$template->param( |
| 78 |
whole => $backend_result, |
| 79 |
request => $request, |
| 80 |
); |
| 81 |
|
| 82 |
# handle special commit rules & update type |
| 83 |
handle_commit_maybe($backend_result, $request); |
| 84 |
|
| 85 |
} elsif ( $op eq 'cancel' ) { |
| 86 |
# Backend 'cancel' method |
| 87 |
# cancel requires a specific request, so first, find it. |
| 88 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
| 89 |
my $backend_result = $request->backend_cancel($params); |
| 90 |
$template->param( |
| 91 |
whole => $backend_result, |
| 92 |
request => $request, |
| 93 |
); |
| 94 |
|
| 95 |
# handle special commit rules & update type |
| 96 |
handle_commit_maybe($backend_result, $request); |
| 97 |
|
| 98 |
} elsif ( $op eq 'edit_action' ) { |
| 99 |
# Handle edits to the Illrequest object. |
| 100 |
# (not the Illrequestattributes) |
| 101 |
# We simulate the API for backend requests for uniformity. |
| 102 |
# So, init: |
| 103 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
| 104 |
if ( !$params->{stage} ) { |
| 105 |
my $backend_result = { |
| 106 |
error => 0, |
| 107 |
status => '', |
| 108 |
message => '', |
| 109 |
method => 'edit_action', |
| 110 |
stage => 'init', |
| 111 |
next => '', |
| 112 |
value => {} |
| 113 |
}; |
| 114 |
$template->param( |
71 |
$template->param( |
| 115 |
whole => $backend_result, |
72 |
whole => $backend_result, |
| 116 |
request => $request |
73 |
request => $request |
| 117 |
); |
74 |
); |
| 118 |
} else { |
|
|
| 119 |
# Commit: |
| 120 |
# Save the changes |
| 121 |
$request->borrowernumber($params->{borrowernumber}); |
| 122 |
$request->biblio_id($params->{biblio_id}); |
| 123 |
$request->branchcode($params->{branchcode}); |
| 124 |
$request->notesopac($params->{notesopac}); |
| 125 |
$request->notesstaff($params->{notesstaff}); |
| 126 |
$request->store; |
| 127 |
my $backend_result = { |
| 128 |
error => 0, |
| 129 |
status => '', |
| 130 |
message => '', |
| 131 |
method => 'edit_action', |
| 132 |
stage => 'commit', |
| 133 |
next => 'illlist', |
| 134 |
value => {} |
| 135 |
}; |
| 136 |
handle_commit_maybe($backend_result, $request); |
75 |
handle_commit_maybe($backend_result, $request); |
| 137 |
} |
|
|
| 138 |
|
76 |
|
| 139 |
} elsif ( $op eq 'moderate_action' ) { |
77 |
} elsif ( $op eq 'confirm' ) { |
| 140 |
# Moderate action is required for an ILL submodule / syspref. |
78 |
# Backend 'confirm' method |
| 141 |
# Currently still needs to be implemented. |
79 |
# confirm requires a specific request, so first, find it. |
| 142 |
redirect_to_list(); |
80 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
|
|
81 |
my $backend_result = $request->backend_confirm($params); |
| 82 |
$template->param( |
| 83 |
whole => $backend_result, |
| 84 |
request => $request, |
| 85 |
); |
| 143 |
|
86 |
|
| 144 |
} elsif ( $op eq 'delete_confirm') { |
87 |
# handle special commit rules & update type |
| 145 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
88 |
handle_commit_maybe($backend_result, $request); |
|
|
89 |
|
| 90 |
} elsif ( $op eq 'cancel' ) { |
| 91 |
# Backend 'cancel' method |
| 92 |
# cancel requires a specific request, so first, find it. |
| 93 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
| 94 |
my $backend_result = $request->backend_cancel($params); |
| 95 |
$template->param( |
| 96 |
whole => $backend_result, |
| 97 |
request => $request, |
| 98 |
); |
| 146 |
|
99 |
|
| 147 |
$template->param( |
100 |
# handle special commit rules & update type |
| 148 |
request => $request |
101 |
handle_commit_maybe($backend_result, $request); |
| 149 |
); |
|
|
| 150 |
|
102 |
|
| 151 |
} elsif ( $op eq 'delete' ) { |
103 |
} elsif ( $op eq 'edit_action' ) { |
|
|
104 |
# Handle edits to the Illrequest object. |
| 105 |
# (not the Illrequestattributes) |
| 106 |
# We simulate the API for backend requests for uniformity. |
| 107 |
# So, init: |
| 108 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
| 109 |
if ( !$params->{stage} ) { |
| 110 |
my $backend_result = { |
| 111 |
error => 0, |
| 112 |
status => '', |
| 113 |
message => '', |
| 114 |
method => 'edit_action', |
| 115 |
stage => 'init', |
| 116 |
next => '', |
| 117 |
value => {} |
| 118 |
}; |
| 119 |
$template->param( |
| 120 |
whole => $backend_result, |
| 121 |
request => $request |
| 122 |
); |
| 123 |
} else { |
| 124 |
# Commit: |
| 125 |
# Save the changes |
| 126 |
$request->borrowernumber($params->{borrowernumber}); |
| 127 |
$request->biblio_id($params->{biblio_id}); |
| 128 |
$request->branchcode($params->{branchcode}); |
| 129 |
$request->notesopac($params->{notesopac}); |
| 130 |
$request->notesstaff($params->{notesstaff}); |
| 131 |
$request->store; |
| 132 |
my $backend_result = { |
| 133 |
error => 0, |
| 134 |
status => '', |
| 135 |
message => '', |
| 136 |
method => 'edit_action', |
| 137 |
stage => 'commit', |
| 138 |
next => 'illlist', |
| 139 |
value => {} |
| 140 |
}; |
| 141 |
handle_commit_maybe($backend_result, $request); |
| 142 |
} |
| 152 |
|
143 |
|
| 153 |
# Check if the request is confirmed, if not, redirect |
144 |
} elsif ( $op eq 'moderate_action' ) { |
| 154 |
# to the confirmation view |
145 |
# Moderate action is required for an ILL submodule / syspref. |
| 155 |
if ($params->{confirmed} == 1) { |
146 |
# Currently still needs to be implemented. |
| 156 |
# We simply delete the request... |
|
|
| 157 |
my $request = Koha::Illrequests->find( |
| 158 |
$params->{illrequest_id} |
| 159 |
)->delete; |
| 160 |
# ... then return to list view. |
| 161 |
redirect_to_list(); |
147 |
redirect_to_list(); |
| 162 |
} else { |
|
|
| 163 |
print $cgi->redirect( |
| 164 |
"/cgi-bin/koha/ill/ill-requests.pl?" . |
| 165 |
"method=delete_confirm&illrequest_id=" . |
| 166 |
$params->{illrequest_id}); |
| 167 |
} |
| 168 |
|
148 |
|
| 169 |
} elsif ( $op eq 'mark_completed' ) { |
149 |
} elsif ( $op eq 'delete_confirm') { |
| 170 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
150 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
| 171 |
my $backend_result = $request->mark_completed($params); |
151 |
|
| 172 |
$template->param( |
152 |
$template->param( |
| 173 |
whole => $backend_result, |
153 |
request => $request |
| 174 |
request => $request, |
154 |
); |
| 175 |
); |
155 |
|
| 176 |
|
156 |
} elsif ( $op eq 'delete' ) { |
| 177 |
# handle special commit rules & update type |
157 |
|
| 178 |
handle_commit_maybe($backend_result, $request); |
158 |
# Check if the request is confirmed, if not, redirect |
| 179 |
|
159 |
# to the confirmation view |
| 180 |
} elsif ( $op eq 'generic_confirm' ) { |
160 |
if ($params->{confirmed}) { |
| 181 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
161 |
# We simply delete the request... |
| 182 |
$params->{current_branchcode} = C4::Context->mybranch; |
162 |
Koha::Illrequests->find( $params->{illrequest_id} )->delete; |
| 183 |
my $backend_result = $request->generic_confirm($params); |
163 |
# ... then return to list view. |
| 184 |
$template->param( |
164 |
redirect_to_list(); |
| 185 |
whole => $backend_result, |
165 |
} else { |
| 186 |
request => $request, |
166 |
print $cgi->redirect( |
| 187 |
); |
167 |
"/cgi-bin/koha/ill/ill-requests.pl?" . |
| 188 |
|
168 |
"method=delete_confirm&illrequest_id=" . |
| 189 |
# handle special commit rules & update type |
169 |
$params->{illrequest_id}); |
| 190 |
handle_commit_maybe($backend_result, $request); |
170 |
exit; |
| 191 |
|
|
|
| 192 |
} elsif ( $op eq 'illlist') { |
| 193 |
# Display all current ILLs |
| 194 |
my $requests = $illRequests->search(); |
| 195 |
|
| 196 |
$template->param( |
| 197 |
requests => $requests |
| 198 |
); |
| 199 |
|
| 200 |
# If we receive a pre-filter, make it available to the template |
| 201 |
my $possible_filters = ['borrowernumber']; |
| 202 |
my $active_filters = []; |
| 203 |
foreach my $filter(@{$possible_filters}) { |
| 204 |
if ($params->{$filter}) { |
| 205 |
push @{$active_filters}, |
| 206 |
{ name => $filter, value => $params->{$filter}}; |
| 207 |
} |
171 |
} |
| 208 |
} |
172 |
|
| 209 |
if (scalar @{$active_filters} > 0) { |
173 |
} elsif ( $op eq 'mark_completed' ) { |
|
|
174 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
| 175 |
my $backend_result = $request->mark_completed($params); |
| 176 |
$template->param( |
| 177 |
whole => $backend_result, |
| 178 |
request => $request, |
| 179 |
); |
| 180 |
|
| 181 |
# handle special commit rules & update type |
| 182 |
handle_commit_maybe($backend_result, $request); |
| 183 |
|
| 184 |
} elsif ( $op eq 'generic_confirm' ) { |
| 185 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
| 186 |
$params->{current_branchcode} = C4::Context->mybranch; |
| 187 |
my $backend_result = $request->generic_confirm($params); |
| 210 |
$template->param( |
188 |
$template->param( |
| 211 |
prefilters => $active_filters |
189 |
whole => $backend_result, |
|
|
190 |
request => $request, |
| 212 |
); |
191 |
); |
|
|
192 |
|
| 193 |
# handle special commit rules & update type |
| 194 |
handle_commit_maybe($backend_result, $request); |
| 195 |
|
| 196 |
} elsif ( $op eq 'illlist') { |
| 197 |
# Display all current ILLs |
| 198 |
my $requests = $illRequests->search(); |
| 199 |
|
| 200 |
$template->param( |
| 201 |
requests => $requests |
| 202 |
); |
| 203 |
|
| 204 |
# If we receive a pre-filter, make it available to the template |
| 205 |
my $possible_filters = ['borrowernumber']; |
| 206 |
my $active_filters = []; |
| 207 |
foreach my $filter(@{$possible_filters}) { |
| 208 |
if ($params->{$filter}) { |
| 209 |
push @{$active_filters}, |
| 210 |
{ name => $filter, value => $params->{$filter}}; |
| 211 |
} |
| 212 |
} |
| 213 |
if (scalar @{$active_filters} > 0) { |
| 214 |
$template->param( |
| 215 |
prefilters => $active_filters |
| 216 |
); |
| 217 |
} |
| 218 |
} else { |
| 219 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
| 220 |
my $backend_result = $request->custom_capability($op, $params); |
| 221 |
$template->param( |
| 222 |
whole => $backend_result, |
| 223 |
request => $request, |
| 224 |
); |
| 225 |
|
| 226 |
# handle special commit rules & update type |
| 227 |
handle_commit_maybe($backend_result, $request); |
| 213 |
} |
228 |
} |
| 214 |
} else { |
|
|
| 215 |
my $request = Koha::Illrequests->find($params->{illrequest_id}); |
| 216 |
my $backend_result = $request->custom_capability($op, $params); |
| 217 |
$template->param( |
| 218 |
whole => $backend_result, |
| 219 |
request => $request, |
| 220 |
); |
| 221 |
|
| 222 |
# handle special commit rules & update type |
| 223 |
handle_commit_maybe($backend_result, $request); |
| 224 |
} |
229 |
} |
| 225 |
|
230 |
|
| 226 |
# Get a list of backends |
|
|
| 227 |
my $ir = Koha::Illrequest->new; |
| 228 |
|
| 229 |
$template->param( |
231 |
$template->param( |
| 230 |
backends => $ir->available_backends, |
232 |
backends => $backends, |
| 231 |
media => [ "Book", "Article", "Journal" ], |
233 |
media => [ "Book", "Article", "Journal" ], |
| 232 |
query_type => $op, |
234 |
query_type => $op, |
| 233 |
branches => Koha::Libraries->search->unblessed, |
235 |
branches => Koha::Libraries->search, |
| 234 |
here_link => "/cgi-bin/koha/ill/ill-requests.pl" |
236 |
here_link => "/cgi-bin/koha/ill/ill-requests.pl" |
| 235 |
); |
237 |
); |
| 236 |
|
238 |
|
| 237 |
output_html_with_http_headers( $cgi, $cookie, $template->output ); |
239 |
output_html_with_http_headers( $cgi, $cookie, $template->output ); |
|
Lines 255-258
sub handle_commit_maybe {
Link Here
|
| 255 |
|
257 |
|
| 256 |
sub redirect_to_list { |
258 |
sub redirect_to_list { |
| 257 |
print $cgi->redirect('/cgi-bin/koha/ill/ill-requests.pl'); |
259 |
print $cgi->redirect('/cgi-bin/koha/ill/ill-requests.pl'); |
|
|
260 |
exit; |
| 258 |
} |
261 |
} |