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;
34 use C4::Interface::CGI::Output;
45 my ($template, $loggedinuser, $cookie) = get_template_and_user
47 template_name => 'circ/rescirculation.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');
78 #if ($query->param('setcookies')) {
79 # $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
80 # $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
83 my %env; # FIXME env is used as an "environment" variable. Could be dropped probably...
85 $env{'branchcode'}=$branch;
86 $env{'printer'}=$printer;
87 $env{'queue'}=$printer;
89 my @datearr = localtime(time());
90 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
91 my $todaysdate = (1900+$datearr[5])."-".sprintf ("%0.2d", ($datearr[4]+1))."-".sprintf ("%0.2d", ($datearr[3]));
94 # check and see if we should print
95 if ($barcode eq '' && $print eq 'maybe'){
98 if ($print eq 'yes' && $borrowernumber ne ''){
99 printslip(\%env,$borrowernumber);
100 $query->param('borrnumber','');
105 # STEP 2 : FIND BORROWER
106 # if there is a list of find borrowers....
111 my ($count,$borrowers)=BornameSearch(\%env,$findborrower,'cardnumber','web');
112 my @borrowers=@$borrowers;
113 if ($#borrowers == -1) {
114 $query->param('findborrower', '');
115 $message = "'$findborrower'";
116 } elsif ($#borrowers == 0) {
117 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
118 $query->param('barcode','');
119 $borrowernumber=$borrowers[0]->{'borrowernumber'};
121 $borrowerslist = \@borrowers;
125 # get the borrower information.....
127 my $bornum=$query->param('bornum');
129 $borrowernumber=$bornum;
132 if ($borrowernumber) {
133 $borrower = C4::Circulation::Circ2::getpatroninformation(\%env,$borrowernumber,0);
134 my ($od,$issue,$fines,$resfine)=borrdata3(\%env,$borrowernumber);
135 if ($resfine >0 || $fines) {
141 $template->param(overduecount => $od,
142 issuecount => $issue,
144 resfine => $resfine);
146 my $htdocs = C4::Context->config('opacdir');
148 $picture =$htdocs. "/htdocs/uploaded-files/users-photo/".$borrower->{'cardnumber'}.".jpg";
152 $template->param(borrowerphoto => "http://library.neu.edu.tr/uploaded-files/users-photo/".$borrower->{'cardnumber'}.".jpg");
154 $picture = "http://cc.neu.edu.tr/stdpictures/".$borrower->{'cardnumber'}.".jpg";
155 $template->param(borrowerphoto => $picture);
158 $renew=$query->param('renew');
167 $barcode = cuecatbarcodedecode($barcode);
168 # my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
169 if ($issueconfirmed) {
170 issuebook(\%env, $borrower, $barcode, $cancelreserve);
171 my ($od,$issue,$fines,$resfine)=borrdata3(\%env,$borrowernumber);
172 $template->param(overduecount => $od,
173 issuecount => $issue,
175 resfine => $resfine);
177 my ($error, $question) = canbookbeissued(\%env, $borrower, $barcode, $year, $month, $day);
180 foreach my $impossible (keys %$error) {
181 $template->param($impossible => $$error{$impossible},
185 foreach my $needsconfirmation (keys %$question) {
186 $template->param($needsconfirmation => $$question{$needsconfirmation},
187 NEEDSCONFIRMATION => 1);
190 $template->param(day => $day,
193 if ($noerror && ($noquestion || $issueconfirmed)) {
194 issuebook(\%env, $borrower, $barcode);
195 my ($od,$issue,$fines,$resfine)=borrdata3(\%env,$borrowernumber);
196 $template->param(overduecount => $od,
197 issuecount => $issue,
199 resfine => $resfine);
208 ##################################################################################
211 # make the issued books table.....
218 # get each issue of the borrower & separate them in todayissues & previous issues
221 my $issueslist = getissues($borrower);
223 # split in 2 arrays for today & previous
224 foreach my $it (keys %$issueslist) {
225 my $issuedate = $issueslist->{$it}->{'timestamp'};
226 $issuedate = substr($issuedate, 0, 10);
227 #warn "$todaysdate,$issuedate";
228 if ($todaysdate == $issuedate) {
229 push @todaysissues, $issueslist->{$it};
231 push @previousissues, $issueslist->{$it};
238 # parses today & build Template array
239 foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
240 my $dd = $book->{'duetime'};
241 my $overdue = $book->{'overdue'};
242 # $dd=format_date($dd);
257 $book->{'tcolor'}=$togglecolor;
258 if ($book->{'author'} eq ''){
259 $book->{'author'}=' ';
261 push @realtodayissues,$book;
264 # parses previous & build Template array
265 foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
266 my $dd = $book->{'duedate'};
267 my $overdue = $book->{'overdue'};
268 # $dd=format_date($dd);
285 $book->{'tcolor'}=$togglecolor;
286 if ($book->{'author'} eq ''){
287 $book->{'author'}=' ';
289 push @realprevissues,$book
296 my $CGIselectborrower;
297 if ($borrowerslist) {
298 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
299 push @values,$_->{'borrowernumber'};
300 $labels{$_->{'borrowernumber'}} ="$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'}) ... $_->{'streetaddress'} ";
302 $CGIselectborrower=CGI::scrolling_list( -name => 'borrnumber',
310 my ($patrontable, $flaginfotable) = patrontable($borrower);
311 my $amountold=$borrower->{flags}->{'CHARGES'}->{'message'};
312 my @temp=split(/\$/,$amountold);
314 $template->param( today=>format_date($todaysdate),
315 findborrower => $findborrower,
316 borrower => $borrower,
317 borrowernumber => $borrowernumber,
320 branchname => $branches->{$branch}->{'branchname'},
321 printername => $printers->{$printer}->{'printername'},
322 firstname => $borrower->{'firstname'},
323 surname => $borrower->{'surname'},
324 categorycode => getborrowercategory($borrower->{'categorycode'}),
325 streetaddress => $borrower->{'streetaddress'},
326 emailaddress => $borrower->{'emailaddress'},
327 borrowernotes => $borrower->{'borrowernotes'},
328 city => $borrower->{'city'},
329 phone => $borrower->{'phone'},
330 cardnumber => $borrower->{'cardnumber'},
331 amountold => $amountold,
334 stickyduedate => $stickyduedate,
336 CGIselectborrower => $CGIselectborrower,
337 todayissues => \@realtodayissues,
338 previssues => \@realprevissues,
340 # set return date if stickyduedate
341 if ($stickyduedate) {
342 my $t_year = "year".$year;
343 my $t_month = "month".$month;
344 my $t_day = "day".$day;
354 $cookie=[$cookie, $branchcookie, $printercookie];
357 output_html_with_http_headers $query, $cookie, $template->output;
359 ####################################################################
360 # Extra subroutines,,,
364 my $flags = $borrower->{'flags'};
365 my $flaginfotable='';
367 #my $flaginfotext='';
370 foreach $flag (sort keys %$flags) {
371 # my @itemswaiting='';
372 $flags->{$flag}->{'message'}=~s/\n/<br>/g;
373 if ($flags->{$flag}->{'noissues'}) {
383 if ($flag eq 'LOST'){
388 if ($flag eq 'DBARRED'){
393 if ($flag eq 'CHARGES') {
396 chargesmsg => $flags->{'CHARGES'}->{'message'}
400 if ($flag eq 'CHARGES') {
404 chargesmsg => $flags->{'CHARGES'}->{'message'}
407 if ($flag eq 'WAITING') {
408 my $items=$flags->{$flag}->{'itemlist'};
410 foreach my $item (@$items) {
411 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
412 $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
413 push @itemswaiting, $iteminformation;
418 waitingmsg => $flags->{'WAITING'}->{'message'},
419 itemswaiting => \@itemswaiting,
422 if ($flag eq 'ODUES') {
426 oduesmsg => $flags->{'ODUES'}->{'message'}
429 my $items=$flags->{$flag}->{'itemlist'};
432 foreach my $item (@$items) {
433 my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
434 push @itemswaiting, $iteminformation;
437 if ($query->param('module') ne 'returns'){
438 $template->param( nonreturns => 'true' );
441 if ($flag eq 'NOTES') {
445 notesmsg => $flags->{'NOTES'}->{'message'}
450 return($patrontable, $flaginfotext);
453 sub cuecatbarcodedecode {
456 my @fields = split(/\./,$barcode);
457 my @results = map(decode($_), @fields[1..$#fields]);