Bug 22417: Remove FIXME in the template
[koha.git] / members / moremember.pl
blob8f6e959850cf5a50981e3b30fb3d961e44c2399a
1 #!/usr/bin/perl
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>.
23 =head1 moremember.pl
25 script to do a borrower enquiry/bring up patron details etc
26 Displays all the details about a patron
28 =cut
30 use Modern::Perl;
31 use CGI qw ( -utf8 );
32 use C4::Context;
33 use C4::Auth;
34 use C4::Output;
35 use C4::Form::MessagingPreferences;
36 use List::MoreUtils qw/uniq/;
37 use Koha::Patron::Attribute::Types;
38 use Koha::Patron::Debarments qw(GetDebarments);
39 use Koha::Patron::Messages;
40 use Koha::DateUtils;
41 use Koha::CsvProfiles;
42 use Koha::Patrons;
43 use Koha::Patron::Files;
44 use Koha::Token;
45 use Koha::Checkouts;
47 use vars qw($debug);
49 BEGIN {
50 $debug = $ENV{DEBUG} || 0;
53 my $input = CGI->new;
54 $debug or $debug = $input->param('debug') || 0;
57 my $print = $input->param('print');
59 my $template_name;
61 if (defined $print and $print eq "brief") {
62 $template_name = "members/moremember-brief.tt";
63 } else {
64 $template_name = "members/moremember.tt";
67 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
69 template_name => $template_name,
70 query => $input,
71 type => "intranet",
72 flagsrequired => { borrowers => 'edit_borrowers' },
73 debug => 1,
76 my $borrowernumber = $input->param('borrowernumber');
77 my $error = $input->param('error');
78 $template->param( error => $error ) if ( $error );
80 my $patron = Koha::Patrons->find( $borrowernumber );
81 my $logged_in_user = Koha::Patrons->find( $loggedinuser );
82 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
84 my $category_type = $patron->category->category_type;
86 for (qw(gonenoaddress lost borrowernotes is_debarred)) {
87 $patron->$_ and $template->param(flagged => 1) and last;
90 if ( $patron->is_debarred ) {
91 $template->param(
92 debarments => scalar GetDebarments({ borrowernumber => $borrowernumber }),
94 if ( $patron->debarred ne "9999-12-31" ) {
95 $template->param( 'userdebarreddate' => $patron->debarred );
98 $template->param( flagged => 1 ) if $patron->account_locked;
100 my @relatives;
101 my $guarantor_relationships = $patron->guarantor_relationships;
102 my @guarantees = $patron->guarantee_relationships->guarantees;
103 my @guarantors = $guarantor_relationships->guarantors;
104 if (@guarantors) {
105 push( @relatives, $_->id ) for @guarantors;
106 push( @relatives, $_->id ) for $patron->siblings();
108 else {
109 push( @relatives, $_->id ) for @guarantees;
111 $template->param(
112 guarantor_relationships => $guarantor_relationships,
113 guarantees => \@guarantees,
116 my $relatives_issues_count =
117 Koha::Checkouts->count({ borrowernumber => \@relatives });
119 # Calculate and display patron's age
120 if ( !$patron->is_valid_age ) {
121 $template->param( age_limitations => 1 );
122 $template->param( age_low => $patron->category->dateofbirthrequired );
123 $template->param( age_high => $patron->category->upperagelimit );
126 # Generate CSRF token for upload and delete image buttons
127 $template->param(
128 csrf_token => Koha::Token->new->generate_csrf({ session_id => $input->cookie('CGISESSID'),}),
131 if (C4::Context->preference('ExtendedPatronAttributes')) {
132 my @attributes = $patron->extended_attributes->as_list; # FIXME Must be improved!
133 my @classes = uniq( map {$_->type->class} @attributes );
134 @classes = sort @classes;
136 my @attributes_loop;
137 for my $class (@classes) {
138 my @items;
139 for my $attr (@attributes) {
140 push @items, $attr if $attr->type->class eq $class
142 my $av = Koha::AuthorisedValues->search({ category => 'PA_CLASS', authorised_value => $class });
143 my $lib = $av->count ? $av->next->lib : $class;
145 push @attributes_loop, {
146 class => $class,
147 items => \@items,
148 lib => $lib,
152 $template->param(
153 attributes_loop => \@attributes_loop
156 my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
157 my $nb_of_attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits({}, {}, $library_id)->count;
158 if ( $nb_of_attribute_types == 0 ) {
159 $template->param(no_patron_attribute_types => 1);
163 if (C4::Context->preference('EnhancedMessagingPreferences')) {
164 C4::Form::MessagingPreferences::set_form_values({ borrowernumber => $borrowernumber }, $template);
165 $template->param(messaging_form_inactive => 1);
168 if ( C4::Context->preference("ExportCircHistory") ) {
169 $template->param(csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ]);
172 my $patron_messages = Koha::Patron::Messages->search(
174 'me.borrowernumber' => $patron->borrowernumber,
177 join => 'manager',
178 '+select' => ['manager.surname', 'manager.firstname' ],
179 '+as' => ['manager_surname', 'manager_firstname'],
183 if( $patron_messages->count > 0 ){
184 $template->param( patron_messages => $patron_messages );
187 # Display the language description instead of the code
188 # Note that this is certainly wrong
189 my ( $subtag, $region ) = split '-', $patron->lang;
190 my $translated_language = C4::Languages::language_get_description( $subtag, $subtag, 'language' );
192 # if the expiry date is before today ie they have expired
193 if ( $patron->is_expired || $patron->is_going_to_expire ) {
194 $template->param(
195 flagged => 1
199 $template->param(
200 patron => $patron,
201 issuecount => $patron->checkouts->count,
202 holds_count => $patron->holds->count,
203 fines => $patron->account->balance,
204 translated_language => $translated_language,
205 detailview => 1,
206 was_renewed => scalar $input->param('was_renewed') ? 1 : 0,
207 $category_type => 1, # [% IF ( I ) %] = institutional/organisation
208 housebound_role => scalar $patron->housebound_role,
209 relatives_issues_count => $relatives_issues_count,
210 relatives_borrowernumbers => \@relatives,
211 logged_in_user => $logged_in_user,
212 files => Koha::Patron::Files->new( borrowernumber => $borrowernumber ) ->GetFilesInfo(),
215 output_html_with_http_headers $input, $cookie, $template->output;