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 if (C4::Context->preference('AutoSelfCheckAllowed'))
36 my $AutoSelfCheckID = C4::Context->preference('AutoSelfCheckID');
37 my $AutoSelfCheckPass = C4::Context->preference('AutoSelfCheckPass');
38 $query->param(-name=>'userid',-values=>[$AutoSelfCheckID]),
39 $query->param(-name=>'password',-values=>[$AutoSelfCheckPass]),
41 my ($template, $loggedinuser, $cookie) = get_template_and_user({
42 template_name => "sco/sco-main.tmpl",
44 flagsrequired => { circulate => "circulate_remaining_permissions" },
50 my $issuerid = $loggedinuser;
51 my ($op, $patronid, $barcode, $confirmed, $timedout) = (
52 $query->param("op") || '',
53 $query->param("patronid") || '',
54 $query->param("barcode") || '',
55 $query->param("confirmed") || '',
56 $query->param("timedout") || '', #not actually using this...
59 my %confirmation_strings = ( RENEW_ISSUE => "This item is already checked out to you. Return it?", );
60 my $issuenoconfirm = 1; #don't need to confirm on issue.
61 #warn "issuerid: " . $issuerid;
62 my $issuer = GetMemberDetails($issuerid);
63 my $item = GetItem(undef,$barcode);
64 my $borrower = GetMemberDetails(undef,$patronid);
66 my $branch = $issuer->{branchcode};
67 my $confirm_required = 0;
69 #warn "issuer cardnumber: " . $issuer->{cardnumber};
70 #warn "patron cardnumber: " . $borrower->{cardnumber};
71 if ($op eq "logout") {
72 $query->param( patronid => undef );
74 elsif ( $op eq "returnbook" ) {
75 my ($doreturn) = AddReturn( $barcode, $branch );
76 #warn "returnbook: " . $doreturn;
77 $borrower = GetMemberDetails( undef, $patronid ); # update borrower
79 elsif ( $op eq "checkout" ) {
83 ( $impossible, $needconfirm ) = CanBookBeIssued( $borrower, $barcode );
85 $confirm_required = scalar keys %$needconfirm;
87 #warn "confirm_required: " . $confirm_required ;
88 if (scalar keys %$impossible) {
90 # warn "impossible: numkeys: " . scalar (keys(%$impossible));
91 #warn join " ", keys %$impossible;
92 my $issue_error = (keys %$impossible)[0];
94 # FIXME we assume only one error.
96 impossible => $issue_error,
97 "circ_error_$issue_error" => 1,
98 title => $item->{title},
101 if ($issue_error eq 'DEBT') {
102 $template->param(amount => $impossible->{DEBT});
104 #warn "issue_error: " . $issue_error ;
105 if ( $issue_error eq "NO_MORE_RENEWALS" ) {
112 } elsif ( $needconfirm->{RENEW_ISSUE} ) {
115 AddRenewal( $borrower, $item->{itemnumber} );
117 #warn "renew confirmation";
122 confirm_renew_issue => 1,
126 } elsif ( $confirm_required && !$confirmed ) {
127 #warn "failed confirmation";
128 my $issue_error = (keys %$needconfirm)[0];
130 impossible => (keys %$needconfirm)[0],
131 "circ_error_$issue_error" => 1,
135 if ( $confirmed || $issuenoconfirm ) { # we'll want to call getpatroninfo again to get updated issues.
136 # warn "issuing book?";
137 AddIssue( $borrower, $barcode );
138 # ($borrower, $flags) = getpatroninformation(undef,undef, $patronid);
140 # patronid => $patronid,
144 $confirm_required = 1;
145 #warn "issue confirmation";
147 confirm => "Issuing title: " . $item->{title},
150 inputfocus => 'confirm',
156 if ($borrower->{cardnumber}) {
157 # warn "issuer's branchcode: " . $issuer->{branchcode};
158 # warn "user's branchcode: " . $borrower->{branchcode};
159 my $borrowername = sprintf "%s %s", ($borrower->{firstname} || ''), ($borrower->{surname} || '');
161 my ($issueslist) = GetPendingIssues( $borrower->{'borrowernumber'} );
162 foreach my $it (@$issueslist) {
163 $it->{date_due_display} = format_date($it->{date_due});
164 my ($renewokay, $renewerror) = CanBookBeIssued($borrower, $it->{'barcode'},'','');
165 $it->{'norenew'} = 1 if $renewokay->{'NO_MORE_RENEWALS'};
171 borrowername => $borrowername,
172 issues_count => scalar(@issues),
174 patronid => $patronid,
177 my $inputfocus = ($return_only == 1) ? 'returnbook' :
178 ($confirm_required == 1) ? 'confirm' : 'barcode' ;
180 inputfocus => $inputfocus,
182 "dateformat_" . C4::Context->preference('dateformat') => 1,
184 if (C4::Context->preference('ShowPatronImageInWebBasedSelfCheck')) {
185 my ($image, $dberror) = GetPatronImage($borrower->{cardnumber});
188 display_patron_image => 1,
189 cardnumber => $borrower->{cardnumber},
195 patronid => $patronid,
200 output_html_with_http_headers $query, $cookie, $template->output;