3 # Please use 8-character tabs for this file (indents are every 4 characters)
5 #written 8/5/2002 by Finlay
6 #script to execute issuing of books
7 # New functions added 07-08-2005 Tumer Garip tgarip@neu.edu.tr
9 # Copyright 2000-2002 Katipo Communications
11 # This file is part of Koha.
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA 02111-1307 USA
28 use C4::Circulation::Circ3;
30 use C4::Interface::CGI::Output;
41 my ($template, $loggedinuser, $cookie) = get_template_and_user
43 template_name => 'circ/rescirculation.tmpl',
47 flagsrequired => { circulate => 1 },
49 my $branches = GetBranches();
50 my $printers = getprinters();
51 my $branch=C4::Context->preference("defaultBranch");
52 my $printer = getprinter($query, $printers);
54 my $findborrower = $query->param('findborrower');
55 $findborrower =~ s|,| |g;
56 $findborrower =~ s|'| |g;
57 my $borrowernumber = $query->param('borrnumber');
59 my $print=$query->param('print');
60 my $barcode = $query->param('barcode');
61 my $year=$query->param('year');
62 my $month=$query->param('month');
63 my $day=$query->param('day');
64 my $stickyduedate=$query->param('stickyduedate');
65 my $issueconfirmed = $query->param('issueconfirmed');
66 my $cancelreserve = $query->param('cancelreserve');
73 #if ($query->param('setcookies')) {
74 # $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
75 # $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
78 my %env; # FIXME env is used as an "environment" variable. Could be dropped probably...
80 $env{'branchcode'}=$branch;
81 $env{'printer'}=$printer;
82 $env{'queue'}=$printer;
84 my @datearr = localtime(time());
85 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
86 my $todaysdate = (1900+$datearr[5])."-".sprintf ("%0.2d", ($datearr[4]+1))."-".sprintf ("%0.2d", ($datearr[3]));
89 # check and see if we should print
90 if ($barcode eq '' && $print eq 'maybe'){
93 if ($print eq 'yes' && $borrowernumber ne ''){
94 printslip(\%env,$borrowernumber);
95 $query->param('borrnumber','');
100 # STEP 2 : FIND BORROWER
101 # if there is a list of find borrowers....
106 my ($count,$borrowers)=BornameSearch(\%env,$findborrower,'cardnumber','web');
107 my @borrowers=@$borrowers;
108 if ($#borrowers == -1) {
109 $query->param('findborrower', '');
110 $message = "'$findborrower'";
111 } elsif ($#borrowers == 0) {
112 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
113 $query->param('barcode','');
114 $borrowernumber=$borrowers[0]->{'borrowernumber'};
116 $borrowerslist = \@borrowers;
120 # get the borrower information.....
122 my $bornum=$query->param('bornum');
124 $borrowernumber=$bornum;
127 if ($borrowernumber) {
128 $borrower = C4::Circulation::Circ2::getpatroninformation(\%env,$borrowernumber,0);
129 my ($od,$issue,$fines,$resfine)=borrdata3(\%env,$borrowernumber);
130 if ($resfine >0 || $fines) {
136 $template->param(overduecount => $od,
137 issuecount => $issue,
139 resfine => $resfine);
141 my $htdocs = C4::Context->config('opacdir');
143 $picture =$htdocs. "/htdocs/uploaded-files/users-photo/".$borrower->{'cardnumber'}.".jpg";
147 $template->param(borrowerphoto => "http://library.neu.edu.tr/uploaded-files/users-photo/".$borrower->{'cardnumber'}.".jpg");
149 $picture = "http://cc.neu.edu.tr/stdpictures/".$borrower->{'cardnumber'}.".jpg";
150 $template->param(borrowerphoto => $picture);
153 $renew=$query->param('renew');
162 $barcode = cuecatbarcodedecode($barcode);
163 # my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
164 if ($issueconfirmed) {
165 issuebook(\%env, $borrower, $barcode, $cancelreserve);
166 my ($od,$issue,$fines,$resfine)=borrdata3(\%env,$borrowernumber);
167 $template->param(overduecount => $od,
168 issuecount => $issue,
170 resfine => $resfine);
172 my ($error, $question) = canbookbeissued(\%env, $borrower, $barcode, $year, $month, $day);
175 foreach my $impossible (keys %$error) {
176 $template->param($impossible => $$error{$impossible},
180 foreach my $needsconfirmation (keys %$question) {
181 $template->param($needsconfirmation => $$question{$needsconfirmation},
182 NEEDSCONFIRMATION => 1);
185 $template->param(day => $day,
188 if ($noerror && ($noquestion || $issueconfirmed)) {
189 issuebook(\%env, $borrower, $barcode);
190 my ($od,$issue,$fines,$resfine)=borrdata3(\%env,$borrowernumber);
191 $template->param(overduecount => $od,
192 issuecount => $issue,
194 resfine => $resfine);
203 ##################################################################################
206 # make the issued books table.....
213 # get each issue of the borrower & separate them in todayissues & previous issues
216 my $issueslist = getissues($borrower);
218 # split in 2 arrays for today & previous
219 foreach my $it (keys %$issueslist) {
220 my $issuedate = $issueslist->{$it}->{'timestamp'};
221 $issuedate = substr($issuedate, 0, 10);
222 #warn "$todaysdate,$issuedate";
223 if ($todaysdate == $issuedate) {
224 push @todaysissues, $issueslist->{$it};
226 push @previousissues, $issueslist->{$it};
233 # parses today & build Template array
234 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
235 my $dd = $book->{'duetime'};
236 my $overdue = $book->{'overdue'};
237 # $dd=format_date($dd);
252 $book->{'tcolor'}=$togglecolor;
253 if ($book->{'author'} eq ''){
254 $book->{'author'}=' ';
256 push @realtodayissues,$book;
259 # parses previous & build Template array
260 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
261 my $dd = $book->{'duedate'};
262 my $overdue = $book->{'overdue'};
263 # $dd=format_date($dd);
280 $book->{'tcolor'}=$togglecolor;
281 if ($book->{'author'} eq ''){
282 $book->{'author'}=' ';
284 push @realprevissues,$book
291 my $CGIselectborrower;
292 if ($borrowerslist) {
293 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
294 push @values,$_->{'borrowernumber'};
295 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'}) ... $_->{'streetaddress'} ";
297 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
305 my ($patrontable, $flaginfotable) = patrontable($borrower);
306 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
307 my @temp=split(/\$/,$amountold);
309 $template->param( today=>format_date($todaysdate),
310 findborrower => $findborrower,
311 borrower => $borrower,
312 borrowernumber => $borrowernumber,
315 branchname => $branches->{$branch}->{'branchname'},
316 printername => $printers->{$printer}->{'printername'},
317 firstname => $borrower->{'firstname'},
318 surname => $borrower->{'surname'},
319 categorycode => getborrowercategory($borrower->{'categorycode'}),
320 streetaddress => $borrower->{'streetaddress'},
321 emailaddress => $borrower->{'emailaddress'},
322 borrowernotes => $borrower->{'borrowernotes'},
323 city => $borrower->{'city'},
324 phone => $borrower->{'phone'},
325 cardnumber => $borrower->{'cardnumber'},
326 amountold => $amountold,
329 stickyduedate => $stickyduedate,
331 CGIselectborrower => $CGIselectborrower,
332 todayissues => \@realtodayissues,
333 previssues => \@realprevissues,
335 # set return date if stickyduedate
336 if ($stickyduedate) {
337 my $t_year = "year".$year;
338 my $t_month = "month".$month;
339 my $t_day = "day".$day;
349 $cookie=[$cookie, $branchcookie, $printercookie];
352 output_html_with_http_headers $query, $cookie, $template->output;
354 ####################################################################
355 # Extra subroutines,,,
359 my $flags = $borrower->{'flags'};
360 my $flaginfotable='';
362 #my $flaginfotext='';
365 foreach $flag (sort keys %$flags) {
366 # my @itemswaiting='';
367 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
368 if ($flags->{$flag}->{'noissues'}) {
378 if ($flag eq 'LOST'){
383 if ($flag eq 'DBARRED'){
388 if ($flag eq 'CHARGES') {
391 chargesmsg => $flags->{'CHARGES'}->{'message'}
395 if ($flag eq 'CHARGES') {
399 chargesmsg => $flags->{'CHARGES'}->{'message'}
402 if ($flag eq 'WAITING') {
403 my $items=$flags->{$flag}->{'itemlist'};
405 foreach my $item (@$items) {
406 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
407 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
408 push @itemswaiting, $iteminformation;
413 waitingmsg => $flags->{'WAITING'}->{'message'},
414 itemswaiting => \@itemswaiting,
417 if ($flag eq 'ODUES') {
421 oduesmsg => $flags->{'ODUES'}->{'message'}
424 my $items=$flags->{$flag}->{'itemlist'};
427 foreach my $item (@$items) {
428 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
429 push @itemswaiting, $iteminformation;
432 if ($query->param('module') ne 'returns'){
433 $template->param( nonreturns => 'true' );
436 if ($flag eq 'NOTES') {
440 notesmsg => $flags->{'NOTES'}->{'message'}
445 return($patrontable, $flaginfotext);
448 sub cuecatbarcodedecode {
451 my @fields = split(/\./,$barcode);
452 my @results = map(decode($_), @fields[1..$#fields]);