opac.css - button background fix for input.icon
[koha.git] / circ / circulation.pl
1 #!/usr/bin/perl
2
3 # Please use 8-character tabs for this file (indents are every 4 characters)
4
5 # written 8/5/2002 by Finlay
6 # script to execute issuing of books
7
8 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA  02111-1307 USA
24
25 use strict;
26 use CGI;
27 use C4::Output;
28 use C4::Print;
29 use C4::Auth qw/:DEFAULT get_session/;
30 use C4::Dates qw/format_date/;
31 use C4::Branch; # GetBranches
32 use C4::Koha;   # GetPrinter
33 use C4::Circulation;
34 use C4::Members;
35 use C4::Biblio;
36 use C4::Reserves;
37 use C4::Context;
38 use CGI::Session;
39
40 use Date::Calc qw(
41   Today
42   Today_and_Now
43   Add_Delta_YM
44   Add_Delta_Days
45   Date_to_Days
46 );
47
48
49 #
50 # PARAMETERS READING
51 #
52 my $query = new CGI;
53
54 # new op dev the branch and the printer are now defined by the userenv
55 # but first we have to check if someone has tried to change them
56
57 my $branch = $query->param('branch');
58 if ($branch){
59     # update our session so the userenv is updated
60     my $dbh=C4::Context->dbh;
61     my $sessionID = $query->cookie("CGISESSID") ;
62     my $session = get_session($sessionID);
63     $session->param('branch',$branch);
64     my $branchname = GetBranchName($branch);
65     $session->param('branchname',$branchname);
66 }
67
68 my $printer = $query->param('printer');
69 if ($printer){
70     # update our session so the userenv is updated
71         my $dbh=C4::Context->dbh;
72         my $sessionID = $query->cookie("CGISESSID") ;
73         my $session = get_session($sessionID);
74         $session->param('branchprinter',$printer);
75
76 }
77 if (!C4::Context->userenv && !$branch){
78         my $sessionID = $query->cookie("CGISESSID") ;
79         my $session = get_session($sessionID);
80         if ($session->param('branch') eq 'NO_LIBRARY_SET'){
81                 # no branch set we can't issue
82                 print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
83                 exit;
84         }
85 }
86
87 my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
88     {
89         template_name   => 'circ/circulation.tmpl',
90         query           => $query,
91         type            => "intranet",
92         authnotrequired => 0,
93         flagsrequired   => { circulate => 1 },
94     }
95 );
96 my $branches = GetBranches();
97
98 my $printers = GetPrinters();
99
100 my @failedrenews = $query->param('failedrenew');
101 my @renew_failed;
102 for (@failedrenews) { $renew_failed[$_] = 1; } 
103
104 my $findborrower = $query->param('findborrower');
105 $findborrower =~ s|,| |g;
106 #$findborrower =~ s|'| |g;
107 my $borrowernumber = $query->param('borrowernumber');
108
109 $branch  = C4::Context->userenv->{'branch'};    
110 $printer = C4::Context->userenv->{'branchprinter'};
111
112
113 # If Autolocated is not activated, we show the Circulation Parameters to chage settings of librarian
114     if (C4::Context->preference("AutoLocation") ne 1)
115         {
116             $template->param(
117             ManualLocation => 1,
118             );
119         }
120
121 my $barcode        = $query->param('barcode') || '';
122
123 # strip whitespace
124 $barcode =~ s/\s*//g;
125
126 my $year           = $query->param('year');
127 my $month          = $query->param('month');
128 my $day            = $query->param('day');
129 my $stickyduedate  = $query->param('stickyduedate');
130 my $duedatespec    = $query->param('duedatespec');
131 my $issueconfirmed = $query->param('issueconfirmed');
132 my $cancelreserve  = $query->param('cancelreserve');
133 my $organisation   = $query->param('organisations');
134 my $print          = $query->param('print');
135 my $newexpiry = $query->param('dateexpiry');
136
137 #set up cookie.....
138 # my $branchcookie;
139 # my $printercookie;
140 # if ($query->param('setcookies')) {
141 #     $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
142 #     $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
143 # }
144 #
145
146 my ($datedue,$invalidduedate);
147 if ($duedatespec) {
148         $datedue =  C4::Dates->new($duedatespec);
149         $invalidduedate=1 unless $datedue;
150 }
151
152 #if (defined($year)) {
153 #        $duedatespec = "$year-$month-$day";
154 #} else {
155 #        ($year, $month, $day) = ($duedatespec) ? split /-/, $duedatespec : (0,0,0);
156 #}
157
158 my @datearr = localtime();
159
160 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
161 my $todaysdate =
162     ( 1900 + $datearr[5] )
163   . sprintf( "%0.2d", ( $datearr[4] + 1 ) )
164   . sprintf( "%0.2d", ( $datearr[3] ) );
165
166 # check and see if we should print
167 if ( $barcode eq '' && $print eq 'maybe' ) {
168     $print = 'yes';
169 }
170
171 my $inprocess = ($barcode eq '') ? '' : $query->param('inprocess');
172
173 if ( $barcode eq '' && $query->param('charges') eq 'yes' ) {
174     $template->param(
175         PAYCHARGES     => 'yes',
176         borrowernumber => $borrowernumber
177     );
178 }
179
180 if ( $print eq 'yes' && $borrowernumber ne '' ) {
181     printslip( $borrowernumber );
182     $query->param( 'borrowernumber', '' );
183     $borrowernumber = '';
184 }
185
186 #
187 # STEP 2 : FIND BORROWER
188 # if there is a list of find borrowers....
189 #
190 my $borrowerslist;
191 my $message;
192 if ($findborrower) {
193     my ( $count, $borrowers ) =
194       SearchMember($findborrower, 'cardnumber', 'web' );
195     my @borrowers = @$borrowers;
196     if ( $#borrowers == -1 ) {
197         $query->param( 'findborrower', '' );
198         $message = "'$findborrower'";
199     }
200     elsif ( $#borrowers == 0 ) {
201         $query->param( 'borrowernumber', $borrowers[0]->{'borrowernumber'} );
202         $query->param( 'barcode',           '' );
203         $borrowernumber = $borrowers[0]->{'borrowernumber'};
204     }
205     else {
206         $borrowerslist = \@borrowers;
207     }
208 }
209
210 # get the borrower information.....
211 my $borrower;
212 my @lines;
213 if ($borrowernumber) {
214     $borrower = GetMemberDetails( $borrowernumber, 0 );
215     my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
216
217     # Warningdate is the date that the warning starts appearing
218     my ( $today_year,   $today_month,   $today_day )   = Today();
219     my ( $warning_year, $warning_month, $warning_day ) = split /-/,
220       $borrower->{'dateexpiry'};
221     my ( $enrol_year, $enrol_month, $enrol_day ) = split /-/,
222       $borrower->{'dateenrolled'};
223     # Renew day is calculated by adding the enrolment period to today
224     my ( $renew_year, $renew_month, $renew_day ) =
225       Add_Delta_YM( $enrol_year, $enrol_month, $enrol_day,
226         0 , $borrower->{'enrolmentperiod'}) if ($enrol_year*$enrol_month*$enrol_day>0);
227     # if the expiry date is before today ie they have expired
228     if ( $warning_year*$warning_month*$warning_day==0 
229       || Date_to_Days( $today_year, $today_month, $today_day ) 
230          > Date_to_Days( $warning_year, $warning_month, $warning_day ) )
231     {
232         #borrowercard expired, no issues
233         $template->param(
234                         flagged => "1",
235             noissues       => "1",
236             expired => format_date($borrower->{dateexpiry}),
237             renewaldate   => format_date("$renew_year-$renew_month-$renew_day")
238         );
239     }
240     # check for NotifyBorrowerDeparture
241         elsif ( C4::Context->preference('NotifyBorrowerDeparture') &&
242                 Date_to_Days(Add_Delta_Days($warning_year,$warning_month,$warning_day,- C4::Context->preference('NotifyBorrowerDeparture'))) <
243                 Date_to_Days( $today_year, $today_month, $today_day ) ) 
244         {
245                 # borrower card soon to expire warn librarian
246                 $template->param("warndeparture" => format_date($borrower->{dateexpiry}),
247                         flagged       => "1",);
248                 if ( C4::Context->preference('ReturnBeforeExpiry')){
249                         $template->param("returnbeforeexpiry" => 1);
250                 }
251         }
252     $template->param(
253         overduecount => $od,
254         issuecount   => $issue,
255         finetotal    => $fines
256     );
257 }
258
259 #
260 # STEP 3 : ISSUING
261 #
262 #
263
264 if ($barcode) {
265    # $barcode = cuecatbarcodedecode($barcode);
266         # always check for blockers on issuing
267         my ( $error, $question ) =
268           CanBookBeIssued( $borrower, $barcode, $datedue , $inprocess );
269         my $noerror    = 1;
270         foreach my $impossible ( keys %$error ) {
271             $template->param(
272                 $impossible => $$error{$impossible},
273                 IMPOSSIBLE  => 1
274             );
275             $noerror = 0;
276         }
277     
278         if ($issueconfirmed && $noerror) {
279                 # we have no blockers for issuing and any issues needing confirmation have been resolved
280         AddIssue( $borrower, $barcode, $datedue, $cancelreserve );
281         $inprocess = 1;
282     }
283         elsif ($issueconfirmed){
284         }
285     else {
286         my $noquestion = 1;
287 #         Get the item title for more information
288         my $getmessageiteminfo  = GetBiblioFromItemNumber(undef,$barcode);
289     
290         foreach my $needsconfirmation ( keys %$question ) {
291             $template->param(
292                 $needsconfirmation => $$question{$needsconfirmation},
293                 getTitleMessageIteminfo => $getmessageiteminfo->{'title'},
294                 NEEDSCONFIRMATION  => 1
295             );
296             $noquestion = 0;
297         }
298         $template->param(
299                          itemhomebranch => $getmessageiteminfo->{'homebranch'} ,                     
300                          duedatespec => $duedatespec,
301         );
302         if ( $noerror && ( $noquestion || $issueconfirmed ) ) {
303             AddIssue( $borrower, $barcode, $datedue );
304             $inprocess = 1;
305         }
306     }
307     
308 # FIXME If the issue is confirmed, we launch another time borrdata2, now display the issue count after issue 
309         my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
310         $template->param(
311         issuecount   => $issue,
312         );
313 }
314
315 # reload the borrower info for the sake of reseting the flags.....
316 if ($borrowernumber) {
317     $borrower = GetMemberDetails( $borrowernumber, 0 );
318 }
319
320 ##################################################################################
321 # BUILD HTML
322 # show all reserves of this borrower, and the position of the reservation ....
323 if ($borrowernumber) {
324
325     # new op dev
326     # now we show the status of the borrower's reservations
327     my @borrowerreserv = GetReservesFromBorrowernumber($borrowernumber );
328     my @reservloop;
329     my @WaitingReserveLoop;
330     
331     foreach my $num_res (@borrowerreserv) {
332         my %getreserv;
333         my %getWaitingReserveInfo;
334         my $getiteminfo  = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
335         my $itemtypeinfo = getitemtypeinfo( (C4::Context->preference('item-level_itype')) ? $getiteminfo->{'itype'} : $getiteminfo->{'itemtype'} );
336         my ( $transfertwhen, $transfertfrom, $transfertto ) =
337           GetTransfers( $num_res->{'itemnumber'} );
338
339         $getreserv{waiting}       = 0;
340         $getreserv{transfered}    = 0;
341         $getreserv{nottransfered} = 0;
342
343         $getreserv{reservedate}    = format_date( $num_res->{'reservedate'} );
344         $getreserv{title}          = $getiteminfo->{'title'};
345         $getreserv{itemtype}       = $itemtypeinfo->{'description'};
346         $getreserv{author}         = $getiteminfo->{'author'};
347         $getreserv{barcodereserv}  = $getiteminfo->{'barcode'};
348         $getreserv{itemcallnumber} = $getiteminfo->{'itemcallnumber'};
349                 $getreserv{biblionumber}   = $getiteminfo->{'biblionumber'};
350
351         #         check if we have a waiting status for reservations
352         if ( $num_res->{'found'} eq 'W' ) {
353             $getreserv{color}   = 'reserved';
354             $getreserv{waiting} = 1;
355 #     genarate information displaying only waiting reserves
356         $getWaitingReserveInfo{title}        = $getiteminfo->{'title'};
357         $getWaitingReserveInfo{biblionumber}   = $getiteminfo->{'biblionumber'};
358         $getWaitingReserveInfo{itemtype}    = $itemtypeinfo->{'description'};
359         $getWaitingReserveInfo{author}        = $getiteminfo->{'author'};
360         $getWaitingReserveInfo{reservedate}    = format_date( $num_res->{'reservedate'} );
361         if ($getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} ) {
362         $getWaitingReserveInfo{waitingat}    = GetBranchName( $num_res->{'branchcode'} );
363         }
364     
365         }
366         #         check transfers with the itemnumber foud in th reservation loop
367         if ($transfertwhen) {
368             $getreserv{color}      = 'transfered';
369             $getreserv{transfered} = 1;
370             $getreserv{datesent}   = format_date($transfertwhen);
371             $getreserv{frombranch} = GetBranchName($transfertfrom);
372         }
373
374         if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
375             and not $transfertwhen )
376         {
377             $getreserv{nottransfered}   = 1;
378             $getreserv{nottransferedby} =
379               GetBranchName( $getiteminfo->{'holdingbranch'} );
380         }
381
382 #         if we don't have a reserv on item, we put the biblio infos and the waiting position
383         if ( $getiteminfo->{'title'} eq '' ) {
384             my $getbibinfo = GetBiblioData( $num_res->{'biblionumber'} );
385             my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );  # fixme - we should have item-level reserves here ?
386             $getreserv{color}           = 'inwait';
387             $getreserv{title}           = $getbibinfo->{'title'};
388             $getreserv{waitingposition} = $num_res->{'priority'};
389             $getreserv{nottransfered}   = 0;
390             $getreserv{itemtype}        = $getbibtype->{'description'};
391             $getreserv{author}          = $getbibinfo->{'author'};
392             $getreserv{itemcallnumber}  = '----------';
393                 $getreserv{biblionumber}    = $num_res->{'biblionumber'};
394         }
395         push( @reservloop, \%getreserv );
396
397 #         if we have a reserve waiting, initiate waitingreserveloop
398         if ($getreserv{waiting} eq 1) {
399         push (@WaitingReserveLoop, \%getWaitingReserveInfo)
400         }
401       
402     }
403
404     # return result to the template
405     $template->param( 
406         countreserv => scalar @reservloop,
407         reservloop  => \@reservloop ,
408         WaitingReserveLoop  => \@WaitingReserveLoop,
409     );
410 }
411
412 # make the issued books table.
413 my $todaysissues = '';
414 my $previssues   = '';
415 my @todaysissues;
416 my @previousissues;
417 my $allowborrow;
418 ## ADDED BY JF: new itemtype issuingrules counter stuff
419 my $issued_itemtypes_loop;
420 my $issued_itemtypes_count;
421 my $issued_itemtypes_allowed_count;    # hashref with total allowed by itemtype
422 my $issued_itemtypes_remaining;        # hashref with remaining
423 my $issued_itemtypes_flags;            #hashref that stores flags
424 my @issued_itemtypes_count_loop;
425
426 if ($borrower) {
427
428 # get each issue of the borrower & separate them in todayissues & previous issues
429     my ($countissues,$issueslist) = GetPendingIssues($borrower->{'borrowernumber'});
430
431     # split in 2 arrays for today & previous
432     foreach my $it ( @$issueslist ) {
433         my $issuedate = $it->{'issuedate'};
434         $issuedate =~ s/-//g;
435         $issuedate = substr( $issuedate, 0, 8 );
436                 ($it->{'charge'}, $it->{'itemtype_charge'}) = GetIssuingCharges(
437                                                 $it->{'itemnumber'}, $borrower->{'borrowernumber'}
438                 );
439                 $it->{'charge'} = sprintf("%.2f", $it->{'charge'});
440         ($it->{'can_renew'}, $it->{'can_renew_error'}) = CanBookBeRenewed( 
441                                                 $borrower->{'borrowernumber'},$it->{'itemnumber'}
442                 );
443                 my ($restype, $reserves) = CheckReserves($it->{'itemnumber'});
444                 ($restype) and $it->{'can_renew'} = 0;
445
446                 $it->{'dd'} = format_date($it->{'date_due'});
447         my $datedue = $it->{'date_due'};
448         $datedue =~ s/-//g;
449                 $it->{'od'} = ($datedue < $todaysdate) ? 1 : 0 ;
450         ($it->{'author'} eq '') and $it->{'author'} = ' ';
451         $it->{'renew_failed'} = $renew_failed[$it->{'itemnumber'}];
452         # ADDED BY JF: NEW ITEMTYPE COUNT DISPLAY
453         $issued_itemtypes_count->{ $it->{'itemtype'} }++;
454
455         if ( $todaysdate == $issuedate ) {
456             push @todaysissues, $it;
457         } else {
458             push @previousissues, $it;
459         }
460     }
461         if (C4::Context->preference("todaysIssuesDefaultSortOrder") eq 'asc'){
462                 @todaysissues   = sort { $a->{'timestamp'} cmp $b->{'timestamp'} } @todaysissues;
463         }
464         else {
465                 @todaysissues   = sort { $b->{'timestamp'} cmp $a->{'timestamp'} } @todaysissues;
466         }
467         if (C4::Context->preference("previousIssuesDefaultSortOrder") eq 'asc'){
468                 @previousissues = sort { $a->{'date_due' } cmp $b->{'date_due' } } @previousissues;
469         }
470         else {
471                 @previousissues = sort { $b->{'date_due' } cmp $a->{'date_due' } } @previousissues;
472         }
473     my $i = 1;
474         foreach my $book (@todaysissues) {
475         $book->{'togglecolor'} = (++$i % 2) ? 0 : 1 ;
476     }
477     $i = 1;
478         foreach my $book (@previousissues) {
479         $book->{'togglecolor'} = (++$i % 2) ? 0 : 1 ;
480     }
481 }
482
483 #### ADDED BY JF FOR COUNTS BY ITEMTYPE RULES
484 # FIXME: This should utilize all the issuingrules options rather than just the defaults
485 # and it should be moved to a module
486 my $dbh = C4::Context->dbh;
487
488 # how many of each is allowed?
489 my $issueqty_sth = $dbh->prepare( "
490 SELECT itemtypes.description AS description,issuingrules.itemtype,maxissueqty
491 FROM issuingrules
492   LEFT JOIN itemtypes ON (itemtypes.itemtype=issuingrules.itemtype)
493   WHERE categorycode=?
494 " );
495 #my @issued_itemtypes_count;  # huh?
496 $issueqty_sth->execute("*");
497
498 while ( my $data = $issueqty_sth->fetchrow_hashref() ) {
499
500     # subtract how many of each this borrower has
501     $data->{'count'} = $issued_itemtypes_count->{ $data->{'description'} };  
502     $data->{'left'}  =
503       ( $data->{'maxissueqty'} -
504           $issued_itemtypes_count->{ $data->{'description'} } );
505
506     # can't have a negative number of remaining
507     if ( $data->{'left'} < 0 ) { $data->{'left'} = "0" }
508     $data->{'flag'} = 1 unless ( $data->{'maxissueqty'} > $data->{'count'} );
509     unless ( ( $data->{'maxissueqty'} < 1 )
510         || ( $data->{'itemtype'} eq "*" )
511         || ( $data->{'itemtype'} eq "CIRC" ) )
512     {
513         push @issued_itemtypes_count_loop, $data;
514     }
515 }
516 $issued_itemtypes_loop = \@issued_itemtypes_count_loop;
517
518 #### / JF
519
520 my @values;
521 my %labels;
522 my $CGIselectborrower;
523 if ($borrowerslist) {
524     foreach (
525         sort {
526                 lc $a->{'surname'}
527               . lc $a->{'firstname'} cmp lc $b->{'surname'}
528               . lc $b->{'firstname'}
529         } @$borrowerslist
530       )
531     {
532         push @values, $_->{'borrowernumber'};
533         $labels{ $_->{'borrowernumber'} } =
534 "$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'}) ...  $_->{'address'} ";
535     }
536     $CGIselectborrower = CGI::scrolling_list(
537         -name     => 'borrowernumber',
538                 -class     => 'focus',
539                 -id          => 'borrowernumber',
540         -values   => \@values,
541         -labels   => \%labels,
542         -size     => 7,
543         -tabindex => '',
544         -multiple => 0
545     );
546 }
547
548 #title
549 my $flags = $borrower->{'flags'};
550 my $flag;
551
552 foreach $flag ( sort keys %$flags ) {
553     $template->param( flagged=> 1);
554     $flags->{$flag}->{'message'} =~ s/\n/<br>/g;
555     if ( $flags->{$flag}->{'noissues'} ) {
556         $template->param(
557             flagged  => 1,
558             noissues => 'true',
559         );
560         if ( $flag eq 'GNA' ) {
561             $template->param( gna => 'true' );
562         }
563         if ( $flag eq 'LOST' ) {
564             $template->param( lost => 'true' );
565         }
566         if ( $flag eq 'DBARRED' ) {
567             $template->param( dbarred => 'true' );
568         }
569         if ( $flag eq 'CHARGES' ) {
570             $template->param(
571                 charges    => 'true',
572                 chargesmsg => $flags->{'CHARGES'}->{'message'}
573             );
574         }
575         if ( $flag eq 'CREDITS' ) {
576             $template->param(
577                 credits    => 'true',
578                 creditsmsg => $flags->{'CREDITS'}->{'message'}
579             );
580         }
581     }
582     else {
583         if ( $flag eq 'CHARGES' ) {
584             $template->param(
585                 charges    => 'true',
586                 flagged    => 1,
587                 chargesmsg => $flags->{'CHARGES'}->{'message'}
588             );
589         }
590         if ( $flag eq 'CREDITS' ) {
591             $template->param(
592                 credits    => 'true',
593                 creditsmsg => $flags->{'CREDITS'}->{'message'}
594             );
595         }
596         if ( $flag eq 'ODUES' ) {
597             $template->param(
598                 odues    => 'true',
599                 flagged  => 1,
600                 oduesmsg => $flags->{'ODUES'}->{'message'}
601             );
602
603             my $items = $flags->{$flag}->{'itemlist'};
604 # useless ???
605 #             {
606 #                 my @itemswaiting;
607 #                 foreach my $item (@$items) {
608 #                     my ($iteminformation) =
609 #                         getiteminformation( $item->{'itemnumber'}, 0 );
610 #                     push @itemswaiting, $iteminformation;
611 #                 }
612 #             }
613             if ( $query->param('module') ne 'returns' ) {
614                 $template->param( nonreturns => 'true' );
615             }
616         }
617         if ( $flag eq 'NOTES' ) {
618             $template->param(
619                 notes    => 'true',
620                 flagged  => 1,
621                 notesmsg => $flags->{'NOTES'}->{'message'}
622             );
623         }
624     }
625 }
626
627 my $amountold = $borrower->{flags}->{'CHARGES'}->{'message'} || 0;
628 my @temp = split( /\$/, $amountold );
629
630 my $CGIorganisations;
631 my $member_of_institution;
632 if ( C4::Context->preference("memberofinstitution") ) {
633     my $organisations = get_institutions();
634     my @orgs;
635     my %org_labels;
636     foreach my $organisation ( keys %$organisations ) {
637         push @orgs, $organisation;
638         $org_labels{$organisation} =
639           $organisations->{$organisation}->{'surname'};
640     }
641     $member_of_institution = 1;
642     $CGIorganisations      = CGI::popup_menu(
643         -id     => 'organisations',
644         -name   => 'organisations',
645         -labels => \%org_labels,
646         -values => \@orgs,
647     );
648 }
649
650 $amountold = $temp[1];
651
652 my $borrowercategory = GetBorrowercategory( $borrower->{'categorycode'} );
653 my $category_type = $borrowercategory->{'category_type'};
654 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
655
656 $template->param(
657     issued_itemtypes_count_loop => $issued_itemtypes_loop,
658     findborrower                => $findborrower,
659     borrower                    => $borrower,
660     borrowernumber              => $borrowernumber,
661     branch                      => $branch,
662     printer                     => $printer,
663     printername                 => $printer,
664     firstname                   => $borrower->{'firstname'},
665     surname                     => $borrower->{'surname'},
666         dateexpiry => format_date($newexpiry),
667     expiry                      =>
668       $borrower->{'dateexpiry'},    #format_date($borrower->{'dateexpiry'}),
669     categorycode      => $borrower->{'categorycode'},
670     address     => $borrower->{'address'},
671     address2     => $borrower->{'address2'},
672     email      => $borrower->{'email'},
673         emailpro           => $borrower->{'emailpro'},
674     borrowernotes     => $borrower->{'borrowernotes'},
675     city              => $borrower->{'city'},
676     phone             => $borrower->{'phone'} || $borrower->{'mobile'},
677     cardnumber        => $borrower->{'cardnumber'},
678     amountold         => $amountold,
679     barcode           => $barcode,
680     stickyduedate     => $stickyduedate,
681     message           => $message,
682     CGIselectborrower => $CGIselectborrower,
683     todayissues       => \@todaysissues,
684     previssues        => \@previousissues,
685     inprocess         => $inprocess,
686     memberofinstution => $member_of_institution,
687     CGIorganisations  => $CGIorganisations,
688         circview => 1,
689         
690 );
691
692 # set return date if stickyduedate
693 if ($stickyduedate) {
694     $template->param(
695         duedatespec => $duedatespec,
696     );
697 }
698
699 #if ($branchcookie) {
700 #$cookie=[$cookie, $branchcookie, $printercookie];
701 #}
702
703 # grab patron's image if available
704 my $picture = GetPatronImage($borrower->{'cardnumber'});
705 $template->param( picture => $picture );
706
707 $template->param(
708     SpecifyDueDate           => C4::Context->preference("SpecifyDueDate"),
709     CircAutocompl            => C4::Context->preference("CircAutocompl") ,
710     DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
711 );
712 output_html_with_http_headers $query, $cookie, $template->output;