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 (renew etc.) 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::Circ2;
34 use C4::Interface::CGI::Output;
45 my ($template, $loggedinuser, $cookie) = get_template_and_user
47 template_name => 'circ/circulation.tmpl',
51 flagsrequired => { circulate => 1 },
53 my $branches = GetBranches();
54 my $printers = getprinters();
55 #my $branch = getbranch($query, $branches);
56 my $branch=C4::Context->preference("defaultBranch");
57 my $printer = getprinter($query, $printers);
59 my $findborrower = $query->param('findborrower');
60 $findborrower =~ s|,| |g;
61 $findborrower =~ s|'| |g;
62 my $borrowernumber = $query->param('borrnumber');
64 my $print=$query->param('print');
65 my $barcode = $query->param('barcode');
66 my $year=$query->param('year');
67 my $month=$query->param('month');
68 my $day=$query->param('day');
69 my $stickyduedate=$query->param('stickyduedate');
70 my $issueconfirmed = $query->param('issueconfirmed');
71 my $cancelreserve = $query->param('cancelreserve');
73 my $errorflag=$query->param('error');
75 if ( $errorflag gt "1"){
76 %error=(TOO_EARLY=>{1},) if ($errorflag eq "2");
77 %error=(NO_MORE_RENEWALS=>{1},) if ($errorflag eq "3");
78 %error=(RESERVE_FOUND=>{1},) if ($errorflag eq "4");
79 }elsif ( $errorflag eq "1"){
80 %error=(SUCCESFULL_RENEW=>{1},)
85 #if ($query->param('setcookies')) {
86 # $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
87 # $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
90 my %env; # FIXME env is used as an "environment" variable. Could be dropped probably...
92 $env{'branchcode'}=$branch;
93 $env{'printer'}=$printer;
94 $env{'queue'}=$printer;
96 my @datearr = localtime(time());
97 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
98 my $todaysdate = (1900+$datearr[5])."-".sprintf ("%0.2d", ($datearr[4]+1))."-".sprintf ("%0.2d", ($datearr[3]));
101 # check and see if we should print
102 if ($barcode eq '' && $print eq 'maybe'){
105 if ($print eq 'yes' && $borrowernumber ne ''){
106 printslip(\%env,$borrowernumber);
107 $query->param('borrnumber','');
112 # STEP 2 : FIND BORROWER
113 # if there is a list of find borrowers....
118 my ($count,$borrowers)=BornameSearch(\%env,$findborrower,'cardnumber','web');
119 my @borrowers=@$borrowers;
120 if ($#borrowers == -1) {
121 $query->param('findborrower', '');
122 $message = "'$findborrower'";
123 } elsif ($#borrowers == 0) {
124 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
125 $query->param('barcode','');
126 $borrowernumber=$borrowers[0]->{'borrowernumber'};
128 $borrowerslist = \@borrowers;
132 # get the borrower information.....
134 my $bornum=$query->param('bornum');
136 $borrowernumber=$bornum;
139 if ($borrowernumber) {
140 $borrower = getpatroninformation(\%env,$borrowernumber,0);
141 my ($od,$issue,$fines)=borrdata2(\%env,$borrowernumber);
144 $template->param(overduecount => $od,
145 issuecount => $issue.$warning,
146 finetotal => $fines);
149 my $htdocs = C4::Context->config('opacdir');
151 $picture =$htdocs. "/htdocs/uploaded-files/users-photo/".$borrower->{'cardnumber'}.".jpg";
154 $template->param(borrowerphoto => "http://library.neu.edu.tr/uploaded-files/users-photo/".$borrower->{'cardnumber'}.".jpg");
156 $picture = "http://cc.neu.edu.tr/stdpictures/".$borrower->{'cardnumber'}.".jpg";
157 $template->param(borrowerphoto => $picture);
169 $barcode = cuecatbarcodedecode($barcode);
170 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
171 if ($issueconfirmed) {
172 issuebook(\%env, $borrower, $barcode, $datedue,$cancelreserve);
173 my ($od,$issue,$fines)=borrdata2(\%env,$borrowernumber);
176 $template->param(overduecount => $od,
177 issuecount => $issue.$warning,
178 finetotal => $fines);
181 my ($error, $question) = canbookbeissued(\%env, $borrower, $barcode, $year, $month, $day) unless %error;
182 $error=\%error if %error;
186 foreach my $impossible (keys %$error) {
187 $template->param($impossible => $$error{$impossible},
188 IMPOSSIBLE => 1) unless ($impossible eq 'SUCCESFULL_RENEW');
191 foreach my $needsconfirmation (keys %$question) {
192 $template->param($needsconfirmation => $$question{$needsconfirmation},
193 NEEDSCONFIRMATION => 1);
196 $template->param(day => $day,
199 if ($noerror && ($noquestion || $issueconfirmed)) {
201 issuebook(\%env, $borrower, $barcode, $datedue);
202 my ($od,$issue,$fines)=borrdata2(\%env,$borrowernumber);
205 $template->param(overduecount => $od,
206 issuecount => $issue.$warning,
207 finetotal => $fines);
216 ##################################################################################
219 # make the issued books table.....
228 # get each issue of the borrower & separate them in todayissues & previous issues
231 my $issueslist = getissues($borrower);
232 # split in 2 arrays for today & previous
233 foreach my $it (keys %$issueslist) {
234 my $issuedate = $issueslist->{$it}->{'issue_date'};
235 # $issuedate = substr($issuedate, 0, 10);
237 if ($todaysdate eq $issuedate) {
238 push @todaysissues, $issueslist->{$it};
240 push @previousissues, $issueslist->{$it};
248 # parses today & build Template array
249 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
250 my $dd = $book->{'date_due'};
251 my $datedue = $book->{'date_due'};
253 $dd=format_date($dd);
255 if ($datedue lt $todaysdate) {
268 $book->{'tcolor'}=$togglecolor;
269 if ($book->{'author'} eq ''){
270 $book->{'author'}=' ';
272 push @realtodayissues,$book;
278 # parses previous & build Template array
280 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
281 my $dd = $book->{'date_due'};
282 my $datedue = $book->{'date_due'};
283 $dd=format_date($dd);
287 if ($datedue lt $todaysdate) {
299 $book->{'tcolor'}=$togglecolor;
302 #$book->{'tcolor'}=$pcolor;
303 if ($book->{'author'} eq ''){
304 $book->{'author'}=' ';
307 push @realprevissues,$book;
316 my $CGIselectborrower;
317 if ($borrowerslist) {
318 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
319 push @values,$_->{'borrowernumber'};
320 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'}) ... $_->{'streetaddress'} ";
322 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
330 my ($patrontable, $flaginfotable) = patrontable($borrower);
331 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
332 my @temp=split(/\$/,$amountold);
334 $template->param( today=>format_date($todaysdate),
335 findborrower => $findborrower,
336 borrower => $borrower,
337 borrowernumber => $borrowernumber,
340 branchname => $branches->{$branch}->{'branchname'},
341 printername => $printers->{$printer}->{'printername'},
342 firstname => $borrower->{'firstname'},
343 surname => $borrower->{'surname'},
344 categorycode => getborrowercategory($borrower->{'categorycode'}),
345 streetaddress => $borrower->{'streetaddress'},
346 emailaddress => $borrower->{'emailaddress'},
347 borrowernotes => $borrower->{'borrowernotes'},
348 city => $borrower->{'city'},
349 phone => $borrower->{'phone'},
350 cardnumber => $borrower->{'cardnumber'},
351 amountold => $amountold,
353 stickyduedate => $stickyduedate,
355 CGIselectborrower => $CGIselectborrower,
356 todayissues => \@realtodayissues,
357 previssues => \@realprevissues,
360 # set return date if stickyduedate
361 if ($stickyduedate) {
362 my $t_year = "year".$year;
363 my $t_month = "month".$month;
364 my $t_day = "day".$day;
374 $cookie=[$cookie, $branchcookie, $printercookie];
377 output_html_with_http_headers $query, $cookie, $template->output;
379 ####################################################################
380 # Extra subroutines,,,
384 my $flags = $borrower->{'flags'};
385 my $flaginfotable='';
387 #my $flaginfotext='';
390 foreach $flag (sort keys %$flags) {
391 # my @itemswaiting='';
392 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
393 if ($flags->{$flag}->{'noissues'}) {
403 if ($flag eq 'LOST'){
408 if ($flag eq 'DBARRED'){
413 if ($flag eq 'CHARGES') {
416 chargesmsg => $flags->{'CHARGES'}->{'message'}
420 if ($flag eq 'CHARGES') {
424 chargesmsg => $flags->{'CHARGES'}->{'message'}
427 if ($flag eq 'WAITING') {
428 my $items=$flags->{$flag}->{'itemlist'};
430 foreach my $item (@$items) {
431 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
432 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
433 push @itemswaiting, $iteminformation;
438 waitingmsg => $flags->{'WAITING'}->{'message'},
439 itemswaiting => \@itemswaiting,
442 if ($flag eq 'ODUES') {
446 oduesmsg => $flags->{'ODUES'}->{'message'}
449 my $items=$flags->{$flag}->{'itemlist'};
452 foreach my $item (@$items) {
453 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
454 push @itemswaiting, $iteminformation;
457 if ($query->param('module') ne 'returns'){
458 $template->param( nonreturns => 'true' );
461 if ($flag eq 'NOTES') {
465 notesmsg => $flags->{'NOTES'}->{'message'}
470 return($patrontable, $flaginfotext);
473 sub cuecatbarcodedecode {
476 my @fields = split(/\./,$barcode);
477 my @results = map(decode($_), @fields[1..$#fields]);