3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2010 BibLibre
5 # Copyright 2014 ByWater Solutions
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 script to do a borrower enquiry/bring up borrower details etc
26 Displays all the details about a borrower
27 written 20/12/99 by chris@katipo.co.nz
28 last modified 21/1/2000 by chris@katipo.co.nz
29 modified 31/1/2001 by chris@katipo.co.nz
30 to not allow items on request to be renewed
32 needs html removed and to use the C4::Output more, but its tricky
37 #use warnings; FIXME - Bug 2505
44 use C4
::Members
::Attributes
;
45 use C4
::Members
::AttributeTypes
;
51 use C4
::Form
::MessagingPreferences
;
52 use List
::MoreUtils qw
/uniq/;
53 use C4
::Members
::Attributes
qw(GetBorrowerAttributes);
54 use Koha
::AuthorisedValues
;
55 use Koha
::CsvProfiles
;
56 use Koha
::Patron
::Debarments
qw(GetDebarments);
57 use Koha
::Patron
::Images
;
59 if ( C4
::Context
->preference('NorwegianPatronDBEnable') && C4
::Context
->preference('NorwegianPatronDBEnable') == 1 ) {
60 load Koha
::NorwegianPatronDB
, qw( NLGetSyncDataFromBorrowernumber );
68 use Koha
::Patron
::Categories
;
74 $debug = $ENV{DEBUG} || 0;
77 my $dbh = C4::Context->dbh;
80 $debug or $debug = $input->param('debug') || 0;
81 my $print = $input->param('print');
87 if (defined $print and $print eq "page") {
88 $template_name = "members/moremember-print.tt";
89 # circ staff who process checkouts but can't edit
90 # patrons still need to be able to access print view
91 $flagsrequired = { circulate => "circulate_remaining_permissions" };
92 } elsif (defined $print and $print eq "slip") {
93 $template_name = "members/moremember-receipt.tt";
94 # circ staff who process checkouts but can't edit
95 # patrons still need to be able to print receipts
96 $flagsrequired = { circulate => "circulate_remaining_permissions" };
97 } elsif (defined $print and $print eq "qslip") {
98 $template_name = "members/moremember-receipt.tt";
100 $flagsrequired = { circulate => "circulate_remaining_permissions" };
101 } elsif (defined $print and $print eq "brief") {
102 $template_name = "members/moremember-brief.tt";
103 $flagsrequired = { borrowers => 1 };
105 $template_name = "members/moremember.tt";
106 $flagsrequired = { borrowers => 1 };
109 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
111 template_name => $template_name,
114 authnotrequired => 0,
115 flagsrequired => $flagsrequired,
119 my $borrowernumber = $input->param('borrowernumber');
120 $borrowernumber = HTML::Entities::encode($borrowernumber);
121 my $error = $input->param('error');
122 $template->param( error => $error ) if ( $error );
124 my $patron = Koha::Patrons->find($borrowernumber);
125 my $issues = $patron->checkouts;
126 my $balance = $patron->account->balance;
128 issuecount => $issues->count,
133 my $data = GetMember( 'borrowernumber' => $borrowernumber );
135 if ( not defined $data ) {
136 $template->param (unknowuser => 1);
137 output_html_with_http_headers $input, $cookie, $template->output;
141 my $category_type = $data->{'category_type'};
143 $debug and printf STDERR "dates (enrolled,expiry,birthdate) raw: (%s, %s, %s)\n", map {$data->{$_}} qw(dateenrolled dateexpiry dateofbirth);
144 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
145 my $userdate = $data->{$_};
147 $debug and warn sprintf "Empty \$data{%12s}", $_;
151 $data->{$_} = dt_from_string
( $userdate );
153 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
155 for (qw(gonenoaddress lost borrowernotes)) {
156 $data->{$_} and $template->param(flagged
=> 1) and last;
159 if ( $patron->is_debarred ) {
163 debarments
=> GetDebarments
({ borrowernumber
=> $borrowernumber }),
165 my $debar = $data->{'debarred'};
166 if ( $debar ne "9999-12-31" ) {
167 $template->param( 'userdebarreddate' => output_pref
( { dt
=> dt_from_string
( $debar ), dateonly
=> 1 } ) );
168 $template->param( 'debarredcomment' => $data->{debarredcomment
} );
172 $data->{ "sex_".$data->{'sex'}."_p" } = 1 if defined $data->{sex
};
174 if ( $category_type eq 'C') {
175 my $patron_categories = Koha
::Patron
::Categories
->search_limited({ category_type
=> 'A' }, {order_by
=> ['categorycode']});
176 $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
177 $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1;
181 if ( my $guarantor = $patron->guarantor ) {
182 $template->param( guarantor
=> $guarantor );
183 push @relatives, $guarantor->borrowernumber;
184 push @relatives, $_->borrowernumber for $patron->siblings;
185 } elsif ( $patron->contactname || $patron->contactfirstname ) {
188 firstname
=> $patron->contactfirstname,
189 surname
=> $patron->contactname,
193 my @guarantees = $patron->guarantees;
194 $template->param( guarantees
=> \
@guarantees );
195 push @relatives, $_->borrowernumber for @guarantees;
198 my $relatives_issues_count =
199 Koha
::Database
->new()->schema()->resultset('Issue')
200 ->count( { borrowernumber
=> \
@relatives } );
202 $template->param( adultborrower
=> 1 ) if ( $category_type eq 'A' || $category_type eq 'I' );
205 $bor{'borrowernumber'} = $borrowernumber;
207 # Converts the branchcode to the branch name
209 if ( C4
::Context
->preference("IndependentBranches") ) {
210 my $userenv = C4
::Context
->userenv;
211 if ( C4
::Context
->IsSuperLibrarian() ) {
215 $samebranch = ( $data->{'branchcode'} eq $userenv->{branch
} );
221 my $library = Koha
::Libraries
->find( $data->{branchcode
})->unblessed;
222 @
{$data}{keys %$library} = values %$library; # merge in all branch columns
224 my ( $total, $accts, $numaccts) = GetMemberAccountRecords
( $borrowernumber );
226 # If printing a page, send the account informations to the template
227 if ($print eq "page") {
228 foreach my $accountline (@
$accts) {
229 $accountline->{amount
} = sprintf '%.2f', $accountline->{amount
};
230 $accountline->{amountoutstanding
} = sprintf '%.2f', $accountline->{amountoutstanding
};
232 if ($accountline->{accounttype
} ne 'F' && $accountline->{accounttype
} ne 'FU'){
233 $accountline->{printtitle
} = 1;
236 $template->param( accounts
=> $accts );
239 # Show OPAC privacy preference is system preference is set
240 if ( C4
::Context
->preference('OPACPrivacy') ) {
241 $template->param( OPACPrivacy
=> 1);
242 $template->param( "privacy".$data->{'privacy'} => 1);
245 my $today = DateTime
->now( time_zone
=> C4
::Context
->tz);
246 $today->truncate(to
=> 'day');
247 my $overdues_exist = 0;
250 # Calculate and display patron's age
251 if ( $data->{dateofbirth
} ) {
252 $template->param( age
=> Koha
::Patron
->new({ dateofbirth
=> $data->{dateofbirth
} })->get_age );
255 ### ###############################################################################
257 # show all reserves of this borrower, and the position of the reservation ....
258 if ($borrowernumber) {
260 holds_count
=> Koha
::Database
->new()->schema()->resultset('Reserve')
261 ->count( { borrowernumber
=> $borrowernumber } ) );
264 # current alert subscriptions
265 my $alerts = getalert
($borrowernumber);
267 $_->{ $_->{type
} } = 1;
268 $_->{relatedto
} = findrelatedto
( $_->{type
}, $_->{externalid
} );
271 # Add sync data to the user data
272 if ( C4
::Context
->preference('NorwegianPatronDBEnable') && C4
::Context
->preference('NorwegianPatronDBEnable') == 1 ) {
273 my $sync = NLGetSyncDataFromBorrowernumber
( $borrowernumber );
275 $data->{'sync'} = $sync->sync;
276 $data->{'syncstatus'} = $sync->syncstatus;
277 $data->{'lastsync'} = $sync->lastsync;
281 # check to see if patron's image exists in the database
282 # basically this gives us a template var to condition the display of
283 # patronimage related interface on
284 my $patron_image = Koha
::Patron
::Images
->find($data->{borrowernumber
});
285 $template->param( picture
=> 1 ) if $patron_image;
286 # Generate CSRF token for upload and delete image buttons
288 csrf_token
=> Koha
::Token
->new->generate_csrf({ session_id
=> $input->cookie('CGISESSID'),}),
292 $template->param(%$data);
294 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
295 my $attributes = C4
::Members
::Attributes
::GetBorrowerAttributes
($borrowernumber);
296 my @classes = uniq
( map {$_->{class}} @
$attributes );
297 @classes = sort @classes;
300 for my $class (@classes) {
302 for my $attr (@
$attributes) {
303 push @items, $attr if $attr->{class} eq $class
305 my $av = Koha
::AuthorisedValues
->search({ category
=> 'PA_CLASS', authorised_value
=> $class });
306 my $lib = $av->count ?
$av->next->lib : $class;
308 push @attributes_loop, {
316 ExtendedPatronAttributes
=> 1,
317 attributes_loop
=> \
@attributes_loop
320 my @types = C4
::Members
::AttributeTypes
::GetAttributeTypes
();
321 if (scalar(@types) == 0) {
322 $template->param(no_patron_attribute_types
=> 1);
326 if (C4
::Context
->preference('EnhancedMessagingPreferences')) {
327 C4
::Form
::MessagingPreferences
::set_form_values
({ borrowernumber
=> $borrowernumber }, $template);
328 $template->param(messaging_form_inactive
=> 1);
329 $template->param(SMSSendDriver
=> C4
::Context
->preference("SMSSendDriver"));
330 $template->param(SMSnumber
=> $data->{'smsalertnumber'});
331 $template->param(TalkingTechItivaPhone
=> C4
::Context
->preference("TalkingTechItivaPhoneNotification"));
334 if ( C4
::Context
->preference("ExportCircHistory") ) {
335 $template->param(csv_profiles
=> [ Koha
::CsvProfiles
->search({ type
=> 'marc' }) ]);
338 # in template <TMPL_IF name="I"> => institutional (A for Adult, C for children)
339 $template->param( $data->{'categorycode'} => 1 );
341 # Display the language description instead of the code
342 # Note that this is certainly wrong
343 my ( $subtag, $region ) = split '-', $patron->lang;
344 my $translated_language = C4
::Languages
::language_get_description
( $subtag, $subtag, 'language' );
348 translated_language
=> $translated_language,
350 borrowernumber
=> $borrowernumber,
351 othernames
=> $data->{'othernames'},
352 categoryname
=> $data->{'description'},
353 was_renewed
=> scalar $input->param('was_renewed') ?
1 : 0,
354 todaysdate
=> output_pref
({ dt
=> dt_from_string
, dateformat
=> 'iso', dateonly
=> 1 }),
355 totalprice
=> sprintf("%.2f", $totalprice),
356 totaldue
=> sprintf("%.2f", $total),
357 totaldue_raw
=> $total,
358 overdues_exist
=> $overdues_exist,
359 StaffMember
=> $category_type eq 'S',
360 is_child
=> $category_type eq 'C',
361 samebranch
=> $samebranch,
362 quickslip
=> $quickslip,
363 housebound_role
=> scalar $patron->housebound_role,
364 privacy_guarantor_checkouts
=> $data->{'privacy_guarantor_checkouts'},
365 AutoResumeSuspendedHolds
=> C4
::Context
->preference('AutoResumeSuspendedHolds'),
366 SuspendHoldsIntranet
=> C4
::Context
->preference('SuspendHoldsIntranet'),
367 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
368 PatronsPerPage
=> C4
::Context
->preference("PatronsPerPage") || 20,
369 relatives_issues_count
=> $relatives_issues_count,
370 relatives_borrowernumbers
=> \
@relatives,
373 output_html_with_http_headers
$input, $cookie, $template->output;