3 # This code has been modified by Trendsetters (originally from opac-user.pl)
4 # This code has been modified by rch
5 # We're going to authenticate a self-check user. we'll add a flag to borrowers 'selfcheck'
7 # We're in a controlled environment; we trust the user.
8 # So the selfcheck station will accept a patronid and issue items to that borrower.
9 # FIXME: NOT really a controlled environment... We're on the internet!
11 # The checkout permission comes form the CGI cookie/session of a staff user.
12 # The patron is not really logging in here in the same way as they do on the
13 # rest of the OPAC. So don't confuse loggedinuser with the patron user.
15 # FIXME: inputfocus not really used in TMPL
24 use C4::Dates qw/format_date/;
34 my ($template, $loggedinuser, $cookie) = get_template_and_user({
35 template_name => "sco/sco-main.tmpl",
37 flagsrequired => { circulate => "circulate_remaining_permissions" },
43 my $issuerid = $loggedinuser;
44 my ($op, $patronid, $barcode, $confirmed, $timedout) = (
45 $query->param("op") || '',
46 $query->param("patronid") || '',
47 $query->param("barcode") || '',
48 $query->param("confirmed") || '',
49 $query->param("timedout") || '', #not actually using this...
52 my %confirmation_strings = ( RENEW_ISSUE => "This item is already checked out to you. Return it?", );
53 my $issuenoconfirm = 1; #don't need to confirm on issue.
54 #warn "issuerid: " . $issuerid;
55 my $issuer = GetMemberDetails($issuerid);
56 my $item = GetItem(undef,$barcode);
57 my $borrower = GetMemberDetails(undef,$patronid);
59 my $branch = $issuer->{branchcode};
60 my $confirm_required = 0;
62 #warn "issuer cardnumber: " . $issuer->{cardnumber};
63 #warn "patron cardnumber: " . $borrower->{cardnumber};
64 if ($op eq "logout") {
65 $query->param( patronid => undef );
67 elsif ( $op eq "returnbook" ) {
68 my ($doreturn) = AddReturn( $barcode, $branch );
69 #warn "returnbook: " . $doreturn;
70 $borrower = GetMemberDetails( undef, $patronid ); # update borrower
72 elsif ( $op eq "checkout" ) {
76 ( $impossible, $needconfirm ) = CanBookBeIssued( $borrower, $barcode );
78 $confirm_required = scalar keys %$needconfirm;
80 #warn "confirm_required: " . $confirm_required ;
81 if (scalar keys %$impossible) {
83 # warn "impossible: numkeys: " . scalar (keys(%$impossible));
84 #warn join " ", keys %$impossible;
85 my $issue_error = (keys %$impossible)[0];
87 # FIXME we assume only one error.
89 impossible => $issue_error,
90 title => $item->{title},
93 #warn "issue_error: " . $issue_error ;
94 if ( $issue_error eq "NO_MORE_RENEWALS" ) {
101 } elsif ( $needconfirm->{RENEW_ISSUE} ) {
104 AddRenewal( $borrower, $item->{itemnumber} );
106 #warn "renew confirmation";
111 confirm_renew_issue => 1,
115 } elsif ( $confirm_required && !$confirmed ) {
116 #warn "failed confirmation";
118 impossible => (keys %$needconfirm)[0],
122 if ( $confirmed || $issuenoconfirm ) { # we'll want to call getpatroninfo again to get updated issues.
123 # warn "issuing book?";
124 AddIssue( $borrower, $barcode );
125 # ($borrower, $flags) = getpatroninformation(undef,undef, $patronid);
127 # patronid => $patronid,
131 $confirm_required = 1;
132 #warn "issue confirmation";
134 confirm => "Issuing title: " . $item->{title},
137 inputfocus => 'confirm',
143 if ($borrower->{cardnumber}) {
144 # warn "issuer's branchcode: " . $issuer->{branchcode};
145 # warn "user's branchcode: " . $borrower->{branchcode};
146 my $borrowername = sprintf "%s %s", ($borrower->{firstname} || ''), ($borrower->{surname} || '');
148 my ($issueslist) = GetPendingIssues( $borrower->{'borrowernumber'} );
149 foreach my $it (@$issueslist) {
150 $it->{date_due_display} = format_date($it->{date_due});
151 my ($renewokay, $renewerror) = CanBookBeIssued($borrower, $it->{'barcode'},'','');
152 $it->{'norenew'} = 1 if $renewokay->{'NO_MORE_RENEWALS'};
158 borrowername => $borrowername,
159 issues_count => scalar(@issues),
161 patronid => $patronid,
164 my $inputfocus = ($return_only == 1) ? 'returnbook' :
165 ($confirm_required == 1) ? 'confirm' : 'barcode' ;
167 inputfocus => $inputfocus,
169 "dateformat_" . C4::Context->preference('dateformat') => 1,
171 if (C4::Context->preference('ShowPatronImageInWebBasedSelfCheck')) {
172 my ($image, $dberror) = GetPatronImage($borrower->{cardnumber});
175 display_patron_image => 1,
176 cardnumber => $borrower->{cardnumber},
182 patronid => $patronid,
187 output_html_with_http_headers $query, $cookie, $template->output;