|
Lines 21-33
Link Here
|
| 21 |
|
21 |
|
| 22 |
# We're going to authenticate a self-check user. we'll add a flag to borrowers 'selfcheck' |
22 |
# We're going to authenticate a self-check user. we'll add a flag to borrowers 'selfcheck' |
| 23 |
# |
23 |
# |
| 24 |
# We're in a controlled environment; we trust the user. |
24 |
# We're not in a controlled environment; we never trust the user. |
| 25 |
# So the selfcheck station will accept a patronid and issue items to that borrower. |
|
|
| 26 |
# FIXME: NOT really a controlled environment... We're on the internet! |
| 27 |
# |
25 |
# |
| 28 |
# The checkout permission comes form the CGI cookie/session of a staff user. |
26 |
# The checkout permission comes form the CGI cookie/session of a staff user. |
| 29 |
# The patron is not really logging in here in the same way as they do on the |
27 |
# The patron is not really logging in here in the same way as they do on the |
| 30 |
# rest of the OPAC. So don't confuse loggedinuser with the patron user. |
28 |
# rest of the OPAC. So don't confuse loggedinuser with the patron user. |
|
|
29 |
# The patron id/cardnumber is retrieved from the JWT |
| 31 |
|
30 |
|
| 32 |
use Modern::Perl; |
31 |
use Modern::Perl; |
| 33 |
|
32 |
|
|
Lines 94-102
if (defined C4::Context->preference('SCOAllowCheckin')) {
Link Here
|
| 94 |
} |
93 |
} |
| 95 |
|
94 |
|
| 96 |
my $issuerid = $loggedinuser; |
95 |
my $issuerid = $loggedinuser; |
| 97 |
my ($op, $patronid, $patronlogin, $patronpw, $barcode, $confirmed, $newissues) = ( |
96 |
my ($op, $patronlogin, $patronpw, $barcode, $confirmed, $newissues) = ( |
| 98 |
$query->param("op") || '', |
97 |
$query->param("op") || '', |
| 99 |
$query->param("patronid") || '', |
|
|
| 100 |
$query->param("patronlogin")|| '', |
98 |
$query->param("patronlogin")|| '', |
| 101 |
$query->param("patronpw") || '', |
99 |
$query->param("patronpw") || '', |
| 102 |
$query->param("barcode") || '', |
100 |
$query->param("barcode") || '', |
|
Lines 104-119
my ($op, $patronid, $patronlogin, $patronpw, $barcode, $confirmed, $newissues) =
Link Here
|
| 104 |
$query->param("newissues") || '', |
102 |
$query->param("newissues") || '', |
| 105 |
); |
103 |
); |
| 106 |
|
104 |
|
|
|
105 |
my $jwt = $query->cookie('JWT'); |
| 106 |
if ($op eq "logout") { |
| 107 |
$template->param( loggedout => 1 ); |
| 108 |
$query->param( patronlogin => undef, patronpw => undef ); |
| 109 |
undef $jwt; |
| 110 |
} |
| 111 |
|
| 107 |
$barcode = barcodedecode( $barcode ) if $barcode; |
112 |
$barcode = barcodedecode( $barcode ) if $barcode; |
| 108 |
|
113 |
|
| 109 |
my @newissueslist = split /,/, $newissues; |
114 |
my @newissueslist = split /,/, $newissues; |
| 110 |
my $issuenoconfirm = 1; #don't need to confirm on issue. |
115 |
my $issuenoconfirm = 1; #don't need to confirm on issue. |
| 111 |
my $issuer = Koha::Patrons->find( $issuerid )->unblessed; |
116 |
my $issuer = Koha::Patrons->find( $issuerid )->unblessed; |
| 112 |
my $item = Koha::Items->find({ barcode => $barcode }); |
117 |
|
| 113 |
if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) { |
118 |
my $patronid = $jwt ? Koha::Token->new->decode_jwt({ token => $jwt }) : undef; |
| 114 |
my $dbh = C4::Context->dbh; |
119 |
unless ( $patronid ) { |
| 115 |
my $resval; |
120 |
if ( C4::Context->preference('SelfCheckoutByLogin') ) { |
| 116 |
($resval, $patronid) = checkpw($dbh, $patronlogin, $patronpw); |
121 |
my $dbh = C4::Context->dbh; |
|
|
122 |
( undef, $patronid ) = checkpw( $dbh, $patronlogin, $patronpw ); |
| 123 |
} |
| 124 |
else { # People should not do that unless they know what they are doing! |
| 125 |
# SelfCheckAllowByIPRanges MUST be configured |
| 126 |
$patronid = $query->param('patronid'); |
| 127 |
} |
| 128 |
$jwt = Koha::Token->new->generate_jwt({ id => $patronid }) if $patronid; |
| 117 |
} |
129 |
} |
| 118 |
|
130 |
|
| 119 |
my $patron; |
131 |
my $patron; |
|
Lines 125-139
if ( $patronid ) {
Link Here
|
| 125 |
my $branch = $issuer->{branchcode}; |
137 |
my $branch = $issuer->{branchcode}; |
| 126 |
my $confirm_required = 0; |
138 |
my $confirm_required = 0; |
| 127 |
my $return_only = 0; |
139 |
my $return_only = 0; |
| 128 |
if ($op eq "logout") { |
140 |
|
| 129 |
$template->param( loggedout => 1 ); |
141 |
if ( $patron && $op eq "returnbook" && $allowselfcheckreturns ) { |
| 130 |
$query->param( patronid => undef, patronlogin => undef, patronpw => undef ); |
|
|
| 131 |
} |
| 132 |
elsif ( $op eq "returnbook" && $allowselfcheckreturns ) { |
| 133 |
my $success = 0; |
142 |
my $success = 0; |
| 134 |
my $human_required = 0; |
143 |
my $human_required = 0; |
|
|
144 |
my $item = Koha::Items->find( { barcode => $barcode } ); |
| 135 |
if ( C4::Context->preference("CircConfirmItemParts") ) { |
145 |
if ( C4::Context->preference("CircConfirmItemParts") ) { |
| 136 |
my $item = Koha::Items->find( { barcode => $barcode } ); |
|
|
| 137 |
if ( defined($item) |
146 |
if ( defined($item) |
| 138 |
&& $item->materials ) |
147 |
&& $item->materials ) |
| 139 |
{ |
148 |
{ |
|
Lines 146-151
elsif ( $op eq "returnbook" && $allowselfcheckreturns ) {
Link Here
|
| 146 |
$template->param( returned => $success ); |
155 |
$template->param( returned => $success ); |
| 147 |
} |
156 |
} |
| 148 |
elsif ( $patron && ( $op eq 'checkout' ) ) { |
157 |
elsif ( $patron && ( $op eq 'checkout' ) ) { |
|
|
158 |
|
| 159 |
my $item = Koha::Items->find( { barcode => $barcode } ); |
| 149 |
my $impossible = {}; |
160 |
my $impossible = {}; |
| 150 |
my $needconfirm = {}; |
161 |
my $needconfirm = {}; |
| 151 |
( $impossible, $needconfirm ) = CanBookBeIssued( |
162 |
( $impossible, $needconfirm ) = CanBookBeIssued( |
|
Lines 166-172
elsif ( $patron && ( $op eq 'checkout' ) ) {
Link Here
|
| 166 |
} |
177 |
} |
| 167 |
} |
178 |
} |
| 168 |
|
179 |
|
| 169 |
#warn "confirm_required: " . $confirm_required ; |
|
|
| 170 |
if (scalar keys %$impossible) { |
180 |
if (scalar keys %$impossible) { |
| 171 |
|
181 |
|
| 172 |
my $issue_error = (keys %$impossible)[0]; # FIXME This is wrong, we assume only one error and keys are not ordered |
182 |
my $issue_error = (keys %$impossible)[0]; # FIXME This is wrong, we assume only one error and keys are not ordered |
|
Lines 181-187
elsif ( $patron && ( $op eq 'checkout' ) ) {
Link Here
|
| 181 |
if ($issue_error eq 'DEBT') { |
191 |
if ($issue_error eq 'DEBT') { |
| 182 |
$template->param(DEBT => $impossible->{DEBT}); |
192 |
$template->param(DEBT => $impossible->{DEBT}); |
| 183 |
} |
193 |
} |
| 184 |
#warn "issue_error: " . $issue_error ; |
|
|
| 185 |
if ( $issue_error eq "NO_MORE_RENEWALS" ) { |
194 |
if ( $issue_error eq "NO_MORE_RENEWALS" ) { |
| 186 |
$return_only = 1; |
195 |
$return_only = 1; |
| 187 |
$template->param( |
196 |
$template->param( |
|
Lines 198-204
elsif ( $patron && ( $op eq 'checkout' ) ) {
Link Here
|
| 198 |
hide_main => 1, |
207 |
hide_main => 1, |
| 199 |
); |
208 |
); |
| 200 |
} elsif ( $confirm_required && !$confirmed ) { |
209 |
} elsif ( $confirm_required && !$confirmed ) { |
| 201 |
#warn "failed confirmation"; |
|
|
| 202 |
$template->param( |
210 |
$template->param( |
| 203 |
impossible => 1, |
211 |
impossible => 1, |
| 204 |
"circ_error_$issue_error" => 1, |
212 |
"circ_error_$issue_error" => 1, |
|
Lines 248-254
elsif ( $patron && ( $op eq 'checkout' ) ) {
Link Here
|
| 248 |
} |
256 |
} |
| 249 |
} else { |
257 |
} else { |
| 250 |
$confirm_required = 1; |
258 |
$confirm_required = 1; |
| 251 |
#warn "issue confirmation"; |
|
|
| 252 |
$template->param( |
259 |
$template->param( |
| 253 |
confirm => "Issuing title: " . $item->biblio->title, |
260 |
confirm => "Issuing title: " . $item->biblio->title, |
| 254 |
barcode => $barcode, |
261 |
barcode => $barcode, |
|
Lines 259-274
elsif ( $patron && ( $op eq 'checkout' ) ) {
Link Here
|
| 259 |
} # $op |
266 |
} # $op |
| 260 |
|
267 |
|
| 261 |
if ( $patron && ( $op eq 'renew' ) ) { |
268 |
if ( $patron && ( $op eq 'renew' ) ) { |
|
|
269 |
my $item = Koha::Items->find({ barcode => $barcode }); |
| 262 |
my ($status,$renewerror) = CanBookBeRenewed( $patron->borrowernumber, $item->itemnumber ); |
270 |
my ($status,$renewerror) = CanBookBeRenewed( $patron->borrowernumber, $item->itemnumber ); |
| 263 |
if ($status) { |
271 |
if ($status) { |
| 264 |
#warn "renewing"; |
|
|
| 265 |
AddRenewal( $patron->borrowernumber, $item->itemnumber, undef, undef, undef, undef, 1 ); |
272 |
AddRenewal( $patron->borrowernumber, $item->itemnumber, undef, undef, undef, undef, 1 ); |
| 266 |
push @newissueslist, $barcode; |
273 |
push @newissueslist, $barcode; |
| 267 |
$template->param( renewed => 1 ); |
274 |
$template->param( renewed => 1 ); |
| 268 |
} |
275 |
} |
| 269 |
} |
276 |
} |
| 270 |
|
277 |
|
| 271 |
if ($patron) { |
278 |
if ( $patron) { |
| 272 |
my $borrowername = sprintf "%s %s", ($patron->firstname || ''), ($patron->surname || ''); |
279 |
my $borrowername = sprintf "%s %s", ($patron->firstname || ''), ($patron->surname || ''); |
| 273 |
my $pending_checkouts = $patron->pending_checkouts; |
280 |
my $pending_checkouts = $patron->pending_checkouts; |
| 274 |
my @checkouts; |
281 |
my @checkouts; |
|
Lines 307-313
if ($patron) {
Link Here
|
| 307 |
ISSUES => \@checkouts, |
314 |
ISSUES => \@checkouts, |
| 308 |
HOLDS => $holds, |
315 |
HOLDS => $holds, |
| 309 |
newissues => join(',',@newissueslist), |
316 |
newissues => join(',',@newissueslist), |
| 310 |
patronid => $patronid, |
|
|
| 311 |
patronlogin => $patronlogin, |
317 |
patronlogin => $patronlogin, |
| 312 |
patronpw => $patronpw, |
318 |
patronpw => $patronpw, |
| 313 |
waiting_holds_count => $waiting_holds_count, |
319 |
waiting_holds_count => $waiting_holds_count, |
|
Lines 344-352
if ($patron) {
Link Here
|
| 344 |
} |
350 |
} |
| 345 |
} else { |
351 |
} else { |
| 346 |
$template->param( |
352 |
$template->param( |
| 347 |
patronid => $patronid, |
|
|
| 348 |
nouser => $patronid, |
353 |
nouser => $patronid, |
| 349 |
); |
354 |
); |
| 350 |
} |
355 |
} |
| 351 |
|
356 |
|
|
|
357 |
$cookie = $query->cookie( |
| 358 |
-name => 'JWT', |
| 359 |
-value => $jwt // '', |
| 360 |
-expires => $jwt ? '+1d' : '', |
| 361 |
-HttpOnly => 1, |
| 362 |
-secure => ( C4::Context->https_enabled() ? 1 : 0 ), |
| 363 |
); |
| 364 |
|
| 365 |
$template->param(patronid => $patronid); |
| 366 |
|
| 352 |
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; |
367 |
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; |
| 353 |
- |
|
|