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]);
40 $query->param(-name=>'koha_login_context',-values=>['sco']);
42 my ($template, $loggedinuser, $cookie) = get_template_and_user({
43 template_name => "sco/sco-main.tmpl",
45 flagsrequired => { circulate => "circulate_remaining_permissions" },
51 my $issuerid = $loggedinuser;
52 my ($op, $patronid, $barcode, $confirmed, $timedout) = (
53 $query->param("op") || '',
54 $query->param("patronid") || '',
55 $query->param("barcode") || '',
56 $query->param("confirmed") || '',
57 $query->param("timedout") || '', #not actually using this...
60 my %confirmation_strings = ( RENEW_ISSUE => "This item is already checked out to you. Return it?", );
61 my $issuenoconfirm = 1; #don't need to confirm on issue.
62 #warn "issuerid: " . $issuerid;
63 my $issuer = GetMemberDetails($issuerid);
64 my $item = GetItem(undef,$barcode);
65 my $borrower = GetMemberDetails(undef,$patronid);
67 my $branch = $issuer->{branchcode};
68 my $confirm_required = 0;
70 #warn "issuer cardnumber: " . $issuer->{cardnumber};
71 #warn "patron cardnumber: " . $borrower->{cardnumber};
72 if ($op eq "logout") {
73 $query->param( patronid => undef );
75 elsif ( $op eq "returnbook" ) {
76 my ($doreturn) = AddReturn( $barcode, $branch );
77 #warn "returnbook: " . $doreturn;
78 $borrower = GetMemberDetails( undef, $patronid ); # update borrower
80 elsif ( $op eq "checkout" ) {
84 ( $impossible, $needconfirm ) = CanBookBeIssued( $borrower, $barcode );
86 $confirm_required = scalar keys %$needconfirm;
88 #warn "confirm_required: " . $confirm_required ;
89 if (scalar keys %$impossible) {
91 # warn "impossible: numkeys: " . scalar (keys(%$impossible));
92 #warn join " ", keys %$impossible;
93 my $issue_error = (keys %$impossible)[0];
95 # FIXME we assume only one error.
97 impossible => $issue_error,
98 "circ_error_$issue_error" => 1,
99 title => $item->{title},
102 if ($issue_error eq 'DEBT') {
103 $template->param(amount => $impossible->{DEBT});
105 #warn "issue_error: " . $issue_error ;
106 if ( $issue_error eq "NO_MORE_RENEWALS" ) {
113 } elsif ( $needconfirm->{RENEW_ISSUE} ) {
116 AddRenewal( $borrower, $item->{itemnumber} );
118 #warn "renew confirmation";
123 confirm_renew_issue => 1,
127 } elsif ( $confirm_required && !$confirmed ) {
128 #warn "failed confirmation";
129 my $issue_error = (keys %$needconfirm)[0];
131 impossible => (keys %$needconfirm)[0],
132 "circ_error_$issue_error" => 1,
136 if ( $confirmed || $issuenoconfirm ) { # we'll want to call getpatroninfo again to get updated issues.
137 # warn "issuing book?";
138 AddIssue( $borrower, $barcode );
139 # ($borrower, $flags) = getpatroninformation(undef,undef, $patronid);
141 # patronid => $patronid,
145 $confirm_required = 1;
146 #warn "issue confirmation";
148 confirm => "Issuing title: " . $item->{title},
151 inputfocus => 'confirm',
157 if ($borrower->{cardnumber}) {
158 # warn "issuer's branchcode: " . $issuer->{branchcode};
159 # warn "user's branchcode: " . $borrower->{branchcode};
160 my $borrowername = sprintf "%s %s", ($borrower->{firstname} || ''), ($borrower->{surname} || '');
162 my ($issueslist) = GetPendingIssues( $borrower->{'borrowernumber'} );
163 foreach my $it (@$issueslist) {
164 $it->{date_due_display} = format_date($it->{date_due});
165 my ($renewokay, $renewerror) = CanBookBeIssued($borrower, $it->{'barcode'},'','');
166 $it->{'norenew'} = 1 if $renewokay->{'NO_MORE_RENEWALS'};
172 borrowername => $borrowername,
173 issues_count => scalar(@issues),
175 patronid => $patronid,
178 my $inputfocus = ($return_only == 1) ? 'returnbook' :
179 ($confirm_required == 1) ? 'confirm' : 'barcode' ;
181 inputfocus => $inputfocus,
183 "dateformat_" . C4::Context->preference('dateformat') => 1,
185 if (C4::Context->preference('ShowPatronImageInWebBasedSelfCheck')) {
186 my ($image, $dberror) = GetPatronImage($borrower->{cardnumber});
189 display_patron_image => 1,
190 cardnumber => $borrower->{cardnumber},
196 patronid => $patronid,
201 output_html_with_http_headers $query, $cookie, $template->output;