|
Lines 275-283
sub create {
Link Here
|
| 275 |
} |
275 |
} |
| 276 |
|
276 |
|
| 277 |
# Received completed details of form. Validate and create request. |
277 |
# Received completed details of form. Validate and create request. |
| 278 |
## Validate |
|
|
| 279 |
my ( $brw_count, $brw ) = |
| 280 |
_validate_borrower( $other->{'cardnumber'} ); |
| 281 |
my $result = { |
278 |
my $result = { |
| 282 |
cwd => dirname(__FILE__), |
279 |
cwd => dirname(__FILE__), |
| 283 |
status => "", |
280 |
status => "", |
|
Lines 289-319
sub create {
Link Here
|
| 289 |
core => $core_fields |
286 |
core => $core_fields |
| 290 |
}; |
287 |
}; |
| 291 |
my $failed = 0; |
288 |
my $failed = 0; |
| 292 |
if ( !$other->{'type'} ) { |
289 |
|
| 293 |
$result->{status} = "missing_type"; |
290 |
my $unauthenticated_request = |
| 294 |
$result->{value} = $params; |
291 |
C4::Context->preference("ILLOpacUnauthenticatedRequest") && !$other->{'cardnumber'}; |
| 295 |
$failed = 1; |
292 |
if($unauthenticated_request){ |
| 296 |
} elsif ( !$other->{'branchcode'} ) { |
293 |
( $failed, $result ) = _validate_form_params( $other, $result, $params); |
| 297 |
$result->{status} = "missing_branch"; |
294 |
if ( !_unauth_request_data_check($other) ) { |
| 298 |
$result->{value} = $params; |
295 |
$result->{status} = "missing_unauth_data"; |
| 299 |
$failed = 1; |
296 |
$result->{value} = $params; |
| 300 |
} elsif ( !Koha::Libraries->find( $other->{'branchcode'} ) ) { |
297 |
$failed = 1; |
| 301 |
$result->{status} = "invalid_branch"; |
298 |
} |
| 302 |
$result->{value} = $params; |
299 |
}else{ |
| 303 |
$failed = 1; |
300 |
( $failed, $result ) = _validate_form_params( $other, $result, $params ); |
| 304 |
} elsif ( $brw_count == 0 ) { |
301 |
|
| 305 |
$result->{status} = "invalid_borrower"; |
302 |
my ( $brw_count, $brw ) = |
| 306 |
$result->{value} = $params; |
303 |
_validate_borrower( $other->{'cardnumber'} ); |
| 307 |
$failed = 1; |
304 |
|
| 308 |
} elsif ( $brw_count > 1 ) { |
305 |
if ( $brw_count == 0 ) { |
| 309 |
|
306 |
$result->{status} = "invalid_borrower"; |
| 310 |
# We must select a specific borrower out of our options. |
307 |
$result->{value} = $params; |
| 311 |
$params->{brw} = $brw; |
308 |
$failed = 1; |
| 312 |
$result->{value} = $params; |
309 |
} elsif ( $brw_count > 1 ) { |
| 313 |
$result->{stage} = "borrowers"; |
310 |
# We must select a specific borrower out of our options. |
| 314 |
$result->{error} = 0; |
311 |
$params->{brw} = $brw; |
| 315 |
$failed = 1; |
312 |
$result->{value} = $params; |
|
|
313 |
$result->{stage} = "borrowers"; |
| 314 |
$result->{error} = 0; |
| 315 |
$failed = 1; |
| 316 |
} |
| 316 |
} |
317 |
} |
|
|
318 |
|
| 317 |
return $result if $failed; |
319 |
return $result if $failed; |
| 318 |
|
320 |
|
| 319 |
$self->add_request( { request => $params->{request}, other => $other } ); |
321 |
$self->add_request( { request => $params->{request}, other => $other } ); |
|
Lines 1215-1220
sub _set_suppression {
Link Here
|
| 1215 |
return 1; |
1217 |
return 1; |
| 1216 |
} |
1218 |
} |
| 1217 |
|
1219 |
|
|
|
1220 |
=head3 _unauth_request_data_check |
| 1221 |
|
| 1222 |
_unauth_request_data_check($other); |
| 1223 |
|
| 1224 |
Checks if unauthenticated request data is present |
| 1225 |
|
| 1226 |
=cut |
| 1227 |
|
| 1228 |
sub _unauth_request_data_check { |
| 1229 |
my ($other) = @_; |
| 1230 |
|
| 1231 |
return 1 unless C4::Context->preference("ILLOpacUnauthenticatedRequest"); |
| 1232 |
|
| 1233 |
return |
| 1234 |
$other->{unauthenticated_first_name} |
| 1235 |
&& $other->{unauthenticated_last_name} |
| 1236 |
&& $other->{unauthenticated_email}; |
| 1237 |
} |
| 1238 |
|
| 1239 |
=head3 _validate_form_params |
| 1240 |
|
| 1241 |
_validate_form_params( $other, $result, $params ); |
| 1242 |
|
| 1243 |
Validate form parameters and return the validation result |
| 1244 |
|
| 1245 |
=cut |
| 1246 |
|
| 1247 |
sub _validate_form_params { |
| 1248 |
my ( $other, $result, $params ) = @_; |
| 1249 |
|
| 1250 |
my $failed = 0; |
| 1251 |
if ( !$other->{'type'} ) { |
| 1252 |
$result->{status} = "missing_type"; |
| 1253 |
$result->{value} = $params; |
| 1254 |
$failed = 1; |
| 1255 |
} elsif ( !$other->{'branchcode'} ) { |
| 1256 |
$result->{status} = "missing_branch"; |
| 1257 |
$result->{value} = $params; |
| 1258 |
$failed = 1; |
| 1259 |
} elsif ( !Koha::Libraries->find( $other->{'branchcode'} ) ) { |
| 1260 |
$result->{status} = "invalid_branch"; |
| 1261 |
$result->{value} = $params; |
| 1262 |
$failed = 1; |
| 1263 |
} |
| 1264 |
|
| 1265 |
return ( $failed, $result ); |
| 1266 |
} |
| 1267 |
|
| 1218 |
=head1 AUTHORS |
1268 |
=head1 AUTHORS |
| 1219 |
|
1269 |
|
| 1220 |
Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com> |
1270 |
Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com> |