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 patron details etc
26 Displays all the details about a patron
35 use C4
::Members
::AttributeTypes
;
36 use C4
::Form
::MessagingPreferences
;
37 use List
::MoreUtils qw
/uniq/;
38 use C4
::Members
::Attributes
qw(GetBorrowerAttributes);
39 use Koha
::Patron
::Debarments
qw(GetDebarments);
40 use Koha
::Patron
::Messages
;
42 use Koha
::CsvProfiles
;
50 $debug = $ENV{DEBUG} || 0;
54 $debug or $debug = $input->param('debug') || 0;
57 my $print = $input->param('print');
61 if (defined $print and $print eq "brief") {
62 $template_name = "members/moremember-brief.tt";
64 $template_name = "members/moremember.tt";
67 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
69 template_name => $template_name,
73 flagsrequired => { borrowers => 'edit_borrowers' },
77 my $borrowernumber = $input->param('borrowernumber');
78 my $error = $input->param('error');
79 $template->param( error => $error ) if ( $error );
81 my $patron = Koha::Patrons->find( $borrowernumber );
82 my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
83 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
85 my $category_type = $patron->category->category_type;
87 for (qw(gonenoaddress lost borrowernotes is_debarred)) {
88 $patron->$_ and $template->param(flagged
=> 1) and last;
91 if ( $patron->is_debarred ) {
93 debarments
=> scalar GetDebarments
({ borrowernumber
=> $borrowernumber }),
95 if ( $patron->debarred ne "9999-12-31" ) {
96 $template->param( 'userdebarreddate' => $patron->debarred );
99 $template->param( flagged
=> 1 ) if $patron->account_locked;
102 my $guarantor_relationships = $patron->guarantor_relationships;
103 my @guarantees = $patron->guarantee_relationships->guarantees;
104 my @guarantors = $guarantor_relationships->guarantors;
106 push( @relatives, $_->id ) for @guarantors;
107 push( @relatives, $_->id ) for $patron->siblings();
110 push( @relatives, $_->id ) for @guarantees;
113 guarantor_relationships
=> $guarantor_relationships,
114 guarantees
=> \
@guarantees,
117 my $relatives_issues_count =
118 Koha
::Checkouts
->count({ borrowernumber
=> \
@relatives });
120 # Calculate and display patron's age
121 if ( !$patron->is_valid_age ) {
122 $template->param( age_limitations
=> 1 );
123 $template->param( age_low
=> $patron->category->dateofbirthrequired );
124 $template->param( age_high
=> $patron->category->upperagelimit );
126 $template->param( age
=> $patron->get_age );
128 # Generate CSRF token for upload and delete image buttons
130 csrf_token
=> Koha
::Token
->new->generate_csrf({ session_id
=> $input->cookie('CGISESSID'),}),
133 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
134 my $attributes = C4
::Members
::Attributes
::GetBorrowerAttributes
($borrowernumber);
135 my @classes = uniq
( map {$_->{class}} @
$attributes );
136 @classes = sort @classes;
139 for my $class (@classes) {
141 for my $attr (@
$attributes) {
142 push @items, $attr if $attr->{class} eq $class
144 my $av = Koha
::AuthorisedValues
->search({ category
=> 'PA_CLASS', authorised_value
=> $class });
145 my $lib = $av->count ?
$av->next->lib : $class;
147 push @attributes_loop, {
155 attributes_loop
=> \
@attributes_loop
158 my @types = C4
::Members
::AttributeTypes
::GetAttributeTypes
();
159 if (scalar(@types) == 0) {
160 $template->param(no_patron_attribute_types
=> 1);
164 if (C4
::Context
->preference('EnhancedMessagingPreferences')) {
165 C4
::Form
::MessagingPreferences
::set_form_values
({ borrowernumber
=> $borrowernumber }, $template);
166 $template->param(messaging_form_inactive
=> 1);
169 if ( C4
::Context
->preference("ExportCircHistory") ) {
170 $template->param(csv_profiles
=> [ Koha
::CsvProfiles
->search({ type
=> 'marc' }) ]);
173 my $patron_messages = Koha
::Patron
::Messages
->search(
175 'me.borrowernumber' => $patron->borrowernumber,
179 '+select' => ['manager.surname', 'manager.firstname' ],
180 '+as' => ['manager_surname', 'manager_firstname'],
184 if( $patron_messages->count > 0 ){
185 $template->param( patron_messages
=> $patron_messages );
188 # Display the language description instead of the code
189 # Note that this is certainly wrong
190 my ( $subtag, $region ) = split '-', $patron->lang;
191 my $translated_language = C4
::Languages
::language_get_description
( $subtag, $subtag, 'language' );
193 # if the expiry date is before today ie they have expired
194 if ( $patron->is_expired || $patron->is_going_to_expire ) {
202 issuecount
=> $patron->checkouts->count,
203 holds_count
=> $patron->holds->count,
204 fines
=> $patron->account->balance,
205 translated_language
=> $translated_language,
207 was_renewed
=> scalar $input->param('was_renewed') ?
1 : 0,
208 $category_type => 1, # [% IF ( I ) %] = institutional/organisation
209 housebound_role
=> scalar $patron->housebound_role,
210 relatives_issues_count
=> $relatives_issues_count,
211 relatives_borrowernumbers
=> \
@relatives,
214 output_html_with_http_headers
$input, $cookie, $template->output;