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/;
35 unless (C4::Context->preference('WebBasedSelfCheck')) {
36 # redirect to OPAC home if self-check is not enabled
37 print $query->redirect("/cgi-bin/koha/opac-main.pl");
41 if (C4::Context->preference('AutoSelfCheckAllowed'))
43 my $AutoSelfCheckID = C4::Context->preference('AutoSelfCheckID');
44 my $AutoSelfCheckPass = C4::Context->preference('AutoSelfCheckPass');
45 $query->param(-name=>'userid',-values=>[$AutoSelfCheckID]);
46 $query->param(-name=>'password',-values=>[$AutoSelfCheckPass]);
47 $query->param(-name=>'koha_login_context',-values=>['sco']);
49 my ($template, $loggedinuser, $cookie) = get_template_and_user({
50 template_name => "sco/sco-main.tmpl",
52 flagsrequired => { circulate => "circulate_remaining_permissions" },
58 my $issuerid = $loggedinuser;
59 my ($op, $patronid, $barcode, $confirmed, $timedout) = (
60 $query->param("op") || '',
61 $query->param("patronid") || '',
62 $query->param("barcode") || '',
63 $query->param("confirmed") || '',
64 $query->param("timedout") || '', #not actually using this...
67 my %confirmation_strings = ( RENEW_ISSUE => "This item is already checked out to you. Return it?", );
68 my $issuenoconfirm = 1; #don't need to confirm on issue.
69 #warn "issuerid: " . $issuerid;
70 my $issuer = GetMemberDetails($issuerid);
71 my $item = GetItem(undef,$barcode);
72 my $borrower = GetMemberDetails(undef,$patronid);
74 my $branch = $issuer->{branchcode};
75 my $confirm_required = 0;
77 #warn "issuer cardnumber: " . $issuer->{cardnumber};
78 #warn "patron cardnumber: " . $borrower->{cardnumber};
79 if ($op eq "logout") {
80 $query->param( patronid => undef );
82 elsif ( $op eq "returnbook" ) {
83 my ($doreturn) = AddReturn( $barcode, $branch );
84 #warn "returnbook: " . $doreturn;
85 $borrower = GetMemberDetails( undef, $patronid ); # update borrower
87 elsif ( $op eq "checkout" ) {
91 ( $impossible, $needconfirm ) = CanBookBeIssued( $borrower, $barcode );
93 $confirm_required = scalar keys %$needconfirm;
95 #warn "confirm_required: " . $confirm_required ;
96 if (scalar keys %$impossible) {
98 # warn "impossible: numkeys: " . scalar (keys(%$impossible));
99 #warn join " ", keys %$impossible;
100 my $issue_error = (keys %$impossible)[0];
102 # FIXME we assume only one error.
104 impossible => $issue_error,
105 "circ_error_$issue_error" => 1,
106 title => $item->{title},
109 if ($issue_error eq 'DEBT') {
110 $template->param(amount => $impossible->{DEBT});
112 #warn "issue_error: " . $issue_error ;
113 if ( $issue_error eq "NO_MORE_RENEWALS" ) {
120 } elsif ( $needconfirm->{RENEW_ISSUE} ) {
123 AddRenewal( $borrower, $item->{itemnumber} );
125 #warn "renew confirmation";
130 confirm_renew_issue => 1,
134 } elsif ( $confirm_required && !$confirmed ) {
135 #warn "failed confirmation";
136 my $issue_error = (keys %$needconfirm)[0];
138 impossible => (keys %$needconfirm)[0],
139 "circ_error_$issue_error" => 1,
143 if ( $confirmed || $issuenoconfirm ) { # we'll want to call getpatroninfo again to get updated issues.
144 # warn "issuing book?";
145 AddIssue( $borrower, $barcode );
146 # ($borrower, $flags) = getpatroninformation(undef,undef, $patronid);
148 # patronid => $patronid,
152 $confirm_required = 1;
153 #warn "issue confirmation";
155 confirm => "Issuing title: " . $item->{title},
158 inputfocus => 'confirm',
164 if ($borrower->{cardnumber}) {
165 # warn "issuer's branchcode: " . $issuer->{branchcode};
166 # warn "user's branchcode: " . $borrower->{branchcode};
167 my $borrowername = sprintf "%s %s", ($borrower->{firstname} || ''), ($borrower->{surname} || '');
169 my ($issueslist) = GetPendingIssues( $borrower->{'borrowernumber'} );
170 foreach my $it (@$issueslist) {
171 $it->{date_due_display} = format_date($it->{date_due});
172 my ($renewokay, $renewerror) = CanBookBeIssued($borrower, $it->{'barcode'},'','');
173 $it->{'norenew'} = 1 if $renewokay->{'NO_MORE_RENEWALS'};
179 borrowername => $borrowername,
180 issues_count => scalar(@issues),
182 patronid => $patronid,
185 my $inputfocus = ($return_only == 1) ? 'returnbook' :
186 ($confirm_required == 1) ? 'confirm' : 'barcode' ;
188 inputfocus => $inputfocus,
190 "dateformat_" . C4::Context->preference('dateformat') => 1,
192 if (C4::Context->preference('ShowPatronImageInWebBasedSelfCheck')) {
193 my ($image, $dberror) = GetPatronImage($borrower->{cardnumber});
196 display_patron_image => 1,
197 cardnumber => $borrower->{cardnumber},
203 patronid => $patronid,
208 output_html_with_http_headers $query, $cookie, $template->output;