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;
97 my $todaysdate =get_today();
100 # check and see if we should print
101 if ($barcode eq '' && $print eq 'maybe'){
104 if ($print eq 'yes' && $borrowernumber ne ''){
105 printslip(\%env,$borrowernumber);
106 $query->param('borrnumber','');
111 # STEP 2 : FIND BORROWER
112 # if there is a list of find borrowers....
117 my ($count,$borrowers)=BornameSearch(\%env,$findborrower,'cardnumber','web');
118 my @borrowers=@$borrowers;
119 if ($#borrowers == -1) {
120 $query->param('findborrower', '');
121 $message = "'$findborrower'";
122 } elsif ($#borrowers == 0) {
123 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
124 $query->param('barcode','');
125 $borrowernumber=$borrowers[0]->{'borrowernumber'};
127 $borrowerslist = \@borrowers;
131 # get the borrower information.....
133 my $bornum=$query->param('bornum');
135 $borrowernumber=$bornum;
138 if ($borrowernumber) {
139 $borrower = getpatroninformation(\%env,$borrowernumber,0);
140 my ($od,$issue,$fines)=borrdata2(\%env,$borrowernumber);
143 $template->param(overduecount => $od,
144 issuecount => $issue.$warning,
145 finetotal => $fines);
148 my $htdocs = C4::Context->config('opacdir');
150 $picture =$htdocs. "/htdocs/uploaded-files/users-photo/".$borrower->{'cardnumber'}.".jpg";
153 $template->param(borrowerphoto => "http://library.neu.edu.tr/uploaded-files/users-photo/".$borrower->{'cardnumber'}.".jpg");
155 $picture = "http://cc.neu.edu.tr/stdpictures/".$borrower->{'cardnumber'}.".jpg";
156 $template->param(borrowerphoto => $picture);
168 $barcode = cuecatbarcodedecode($barcode);
169 my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
170 if ($issueconfirmed) {
171 issuebook(\%env, $borrower, $barcode, $datedue,$cancelreserve);
172 my ($od,$issue,$fines)=borrdata2(\%env,$borrowernumber);
175 $template->param(overduecount => $od,
176 issuecount => $issue.$warning,
177 finetotal => $fines);
180 my ($error, $question) = canbookbeissued(\%env, $borrower, $barcode, $year, $month, $day) unless %error;
181 $error=\%error if %error;
185 foreach my $impossible (keys %$error) {
186 $template->param($impossible => $$error{$impossible},
187 IMPOSSIBLE => 1) unless ($impossible eq 'SUCCESFULL_RENEW');
190 foreach my $needsconfirmation (keys %$question) {
191 $template->param($needsconfirmation => $$question{$needsconfirmation},
192 NEEDSCONFIRMATION => 1);
195 $template->param(day => $day,
198 if ($noerror && ($noquestion || $issueconfirmed)) {
200 issuebook(\%env, $borrower, $barcode, $datedue);
201 my ($od,$issue,$fines)=borrdata2(\%env,$borrowernumber);
204 $template->param(overduecount => $od,
205 issuecount => $issue.$warning,
206 finetotal => $fines);
215 ##################################################################################
218 # make the issued books table.....
227 # get each issue of the borrower & separate them in todayissues & previous issues
230 my $issueslist = getissues($borrower);
231 # split in 2 arrays for today & previous
232 foreach my $it (keys %$issueslist) {
233 my $issuedate = $issueslist->{$it}->{'issue_date'};
234 # $issuedate = substr($issuedate, 0, 10);
236 if ($todaysdate eq $issuedate) {
237 push @todaysissues, $issueslist->{$it};
239 push @previousissues, $issueslist->{$it};
247 # parses today & build Template array
248 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
249 my $dd = $book->{'date_due'};
250 my $datedue = $book->{'date_due'};
252 $dd=format_date($dd);
254 if ($datedue lt $todaysdate) {
267 $book->{'tcolor'}=$togglecolor;
268 if ($book->{'author'} eq ''){
269 $book->{'author'}=' ';
271 push @realtodayissues,$book;
277 # parses previous & build Template array
279 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
280 my $dd = $book->{'date_due'};
281 my $datedue = $book->{'date_due'};
282 $dd=format_date($dd);
286 if ($datedue lt $todaysdate) {
298 $book->{'tcolor'}=$togglecolor;
301 #$book->{'tcolor'}=$pcolor;
302 if ($book->{'author'} eq ''){
303 $book->{'author'}=' ';
306 push @realprevissues,$book;
315 my $CGIselectborrower;
316 if ($borrowerslist) {
317 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
318 push @values,$_->{'borrowernumber'};
319 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'}) ... $_->{'streetaddress'} ";
321 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
329 my ($patrontable, $flaginfotable) = patrontable($borrower);
330 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
331 my @temp=split(/\$/,$amountold);
333 $template->param( today=>format_date($todaysdate),
334 findborrower => $findborrower,
335 borrower => $borrower,
336 borrowernumber => $borrowernumber,
339 branchname => $branches->{$branch}->{'branchname'},
340 printername => $printers->{$printer}->{'printername'},
341 firstname => $borrower->{'firstname'},
342 surname => $borrower->{'surname'},
343 categorycode => getborrowercategory($borrower->{'categorycode'}),
344 streetaddress => $borrower->{'streetaddress'},
345 emailaddress => $borrower->{'emailaddress'},
346 borrowernotes => $borrower->{'borrowernotes'},
347 city => $borrower->{'city'},
348 phone => $borrower->{'phone'},
349 cardnumber => $borrower->{'cardnumber'},
350 amountold => $amountold,
352 stickyduedate => $stickyduedate,
354 CGIselectborrower => $CGIselectborrower,
355 todayissues => \@realtodayissues,
356 previssues => \@realprevissues,
359 # set return date if stickyduedate
360 if ($stickyduedate) {
361 my $t_year = "year".$year;
362 my $t_month = "month".$month;
363 my $t_day = "day".$day;
373 $cookie=[$cookie, $branchcookie, $printercookie];
376 output_html_with_http_headers $query, $cookie, $template->output;
378 ####################################################################
379 # Extra subroutines,,,
383 my $flags = $borrower->{'flags'};
384 my $flaginfotable='';
386 #my $flaginfotext='';
389 foreach $flag (sort keys %$flags) {
390 # my @itemswaiting='';
391 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
392 if ($flags->{$flag}->{'noissues'}) {
402 if ($flag eq 'LOST'){
407 if ($flag eq 'DBARRED'){
412 if ($flag eq 'CHARGES') {
415 chargesmsg => $flags->{'CHARGES'}->{'message'}
419 if ($flag eq 'CHARGES') {
423 chargesmsg => $flags->{'CHARGES'}->{'message'}
426 if ($flag eq 'WAITING') {
427 my $items=$flags->{$flag}->{'itemlist'};
429 foreach my $item (@$items) {
430 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
431 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
432 push @itemswaiting, $iteminformation;
437 waitingmsg => $flags->{'WAITING'}->{'message'},
438 itemswaiting => \@itemswaiting,
441 if ($flag eq 'ODUES') {
445 oduesmsg => $flags->{'ODUES'}->{'message'}
448 my $items=$flags->{$flag}->{'itemlist'};
451 foreach my $item (@$items) {
452 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
453 push @itemswaiting, $iteminformation;
456 if ($query->param('module') ne 'returns'){
457 $template->param( nonreturns => 'true' );
460 if ($flag eq 'NOTES') {
464 notesmsg => $flags->{'NOTES'}->{'message'}
469 return($patrontable, $flaginfotext);
472 sub cuecatbarcodedecode {
475 my @fields = split(/\./,$barcode);
476 my @results = map(decode($_), @fields[1..$#fields]);