HTML::Template => HTML::Template::Pro
[koha.git] / opac / sco / sco-circ.pl
1 #!/usr/bin/perl
2 # code modified by Trendsetters (from original circulation.pl)
3 # Please use 8-character tabs for this file (indents are every 4 characters)
4 #
5 #  rychi edit: we're just trying to issue some books. 'Trendsetters' code mostly deleted.
6 #    Note:  This is incomplete; implemented for a library that trusts its users and  has no fines;
7 #    as such, there are some circ functions that are missing and tests that are skipped.
8 #    
9 #    The issuer is a special user
10 #  with borrowerflag 'selfcheck' set.  The borrower has been authenticated.
11 #  We're going to post a barcode with a form, and check that barcode for issuability.
12 #  If it's issuable, we issue it.  If there's an error, we call a popup.
13 #
14
15 # Copyright  2006 
16 # # This file is part of Koha.
17 #
18 # Koha is free software; you can redistribute it and/or modify it under the
19 # terms of the GNU General Public License as published by the Free Software
20 # Foundation; either version 2 of the License, or (at your option) any later
21 # version.
22 #
23 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
24 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
25 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
26 #
27 # You should have received a copy of the GNU General Public License along with
28 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
29 # Suite 330, Boston, MA  02111-1307 USA
30
31 use strict;
32 use CGI;
33 use C4::Circulation;
34 use C4::Search;
35 use DBI;
36 use C4::Auth;
37 use C4::Output;
38 use C4::Koha;
39 use HTML::Template::Pro;
40 use C4::Date;
41
42 my $query=new CGI;
43
44 #my ($loggedinuser, $sessioncookie, $sessionID) = checkauth
45 #       ($query, 0, { circulate => 1 });
46 #  loggedinuser is the 'selfchaeckout user'.
47 my ($template, $loggedinuser, $cookie) = get_template_and_user({
48         template_name   => 'sco/sco-circ.tmpl',
49         query           => $query,
50         type            => "opac",
51         authnotrequired => 0,
52         flagsrequired   => { selfcheckout => 1 },
53     });
54
55 my $issuerid = $loggedinuser;
56 my ( $userid, $op, $barcode, $confirmed )= $query->param("userid", "op", "barcode", "confirmed" );
57 my $env ;
58 my %confirmation_strings = ( RENEW_ISSUE => "This item is already checked out to you.  Renew it?", );
59 my $cnt = 0;
60
61 my ($issuer, $flags) = getpatroninformation(undef,undef, $issuerid);
62 my $item = getiteminformation(undef,undef,$barcode);
63
64 if ($op eq "finish") {
65         $query->param( userid => undef );
66 } elsif ($userid) {  
67
68    my $env = {branchcode =>  $issuer->{'branchcode'} }; 
69    warn "here's the branchcode: ".$issuer->{branchcode};
70    my ($borrower, $flags) = getpatroninformation(undef,undef, $userid);
71    my $bornum = $borrower->{borrowernumber};
72    
73    my $borrowerissues = [];
74    my $issues = currentissues( $env, $borrower);
75    
76    foreach (%$issues) {
77         $borrowerissues->[$cnt]->{issued} = $_ ;
78         $cnt++;
79    }
80    $cnt=0;
81    $template->param( OVERDUES => $borrower->{ODUES} ,
82                         ISSUES => $borrowerissues,
83                         );
84
85    if ($op eq "checkout" ) {
86       my ($impossible,$needconfirm) = canbookbeissued(undef,$borrower,$barcode);
87       if ($impossible) {
88          my ($issue_error) = keys %$impossible ;
89          $template->param( impossible => $issue_error );
90       } elsif ($needconfirm->{RENEW_ISSUE} ) {
91           if ( $confirmed ) {
92             renewbook($env,$bornum,$item->{itemnumber},"");
93           } else {
94            $template->param( confirm => $confirmation_strings{RENEW_ISSUE} );
95           }
96       } elsif ($needconfirm && !$confirmed ) {
97          my ($confirmation) = keys %$needconfirm ;      
98          $template->param( impossible => $confirmation );
99       } else {
100          issuebook($env,$bornum,$barcode,"");
101       }
102
103 #getiteminformation(undef,undef,$item);
104
105    } else {
106
107 }
108                         
109 # reload the borrower info for the sake of reseting the flags.....
110 #       if ($borrowernumber) {
111 #               ($borrower, $flags) = getpatroninformation(\%env,$borrowernumber,0);
112 #       }
113 } else {
114         $template->param( noauth => 1, );
115 }
116
117 output_html_with_http_headers $query, $cookie, $template->output;
118
119
120 #sub patrontable {
121 #    my ($borrower) = @_;
122 #    my $flags = $borrower->{'flags'};
123 #    my $flaginfotable='';
124 #    my $flaginfotext;
125 #    #my $flaginfotext='';
126 #    my $flag;
127 #    my $color='';
128 #    foreach $flag (sort keys %$flags) {
129 #       warn $flag;
130 ##      my @itemswaiting='';
131 #       ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
132 #       $flags->{$flag}->{'message'}=~s/\n/<br>/g;
133 #       if ($flags->{$flag}->{'noissues'}) {
134 #               $template->param(
135 #                       noissues => 'true',
136 #                       color => $color,
137 #                        );
138 #               if ($flag eq 'GNA'){
139 #                       $template->param(
140 #                               gna => 'true'
141 #                               );
142 #                       }
143 #               if ($flag eq 'LOST'){
144 #                       $template->param(
145 #                               lost => 'true'
146 #                       );
147 #                       }
148 #               if ($flag eq 'DBARRED'){
149 #                       $template->param(
150 #                               dbarred => 'true'
151 #                       );
152 #                       }
153 #               if ($flag eq 'CHARGES') {
154 #                       $template->param(
155 #                               charges => 'true',
156 #                               chargesmsg => $flags->{'CHARGES'}->{'message'}
157 #                                );
158 #               }
159 #       } else {
160 #                if ($flag eq 'CHARGES') {
161 #                       $template->param(
162 #                               charges => 'true',
163 #                               chargesmsg => $flags->{'CHARGES'}->{'message'}
164 #                        );
165 #               }
166 #               if ($flag eq 'WAITING') {
167 #                       my $items=$flags->{$flag}->{'itemlist'};
168 #                       my @itemswaiting;
169 #                       foreach my $item (@$items) {
170 #                       my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
171 #                       $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
172 #                       push @itemswaiting, $iteminformation;
173 #                       }
174 #                       $template->param(
175 #                               waiting => 'true',
176 #                               waitingmsg => $flags->{'WAITING'}->{'message'},
177 #                               itemswaiting => \@itemswaiting,
178 #                                );
179 #               }
180 #               if ($flag eq 'ODUES') {
181 #                       $template->param(
182 #                               odues => 'true',
183 #                               oduesmsg => $flags->{'ODUES'}->{'message'}
184 #                                );
185 #
186 #                       my $items=$flags->{$flag}->{'itemlist'};
187 #                       my $currentcolor=$color;
188 #                       {
189 #                       my $color=$currentcolor;
190 #                           my @itemswaiting;
191 #                       foreach my $item (@$items) {
192 #                               ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
193 #                               my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
194 #                               push @itemswaiting, $iteminformation;
195 #                       }
196 #                       }
197 #                       if ($query->param('module') ne 'returns'){
198 #                               $template->param( nonreturns => 'true' );
199 #                       }
200 #               }
201 #               if ($flag eq 'NOTES') {
202 #                       $template->param(
203 #                               notes => 'true',
204 #                               notesmsg => $flags->{'NOTES'}->{'message'}
205 #                                );
206 #               }
207 #       }
208 #    }
209 #    return($patrontable, $flaginfotext);
210 #}
211