Bug 7924 - Fix handling of command line arguments in koha-remove
[koha.git] / members / readingrec.pl
blob2645edac75109ab889b507576e4aafd578b9a8b5
1 #!/usr/bin/perl
3 # written 27/01/2000
4 # script to display borrowers reading record
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use strict;
24 use warnings;
26 use CGI;
28 use C4::Auth;
29 use C4::Output;
30 use C4::Members;
31 use C4::Branch;
32 use List::MoreUtils qw/any uniq/;
33 use Koha::DateUtils;
35 use C4::Dates qw/format_date/;
36 use C4::Members::Attributes qw(GetBorrowerAttributes);
38 my $input = CGI->new;
40 #get borrower details
41 my $data = undef;
42 my $borrowernumber = undef;
43 my $cardnumber = undef;
45 my ($template, $loggedinuser, $cookie)= get_template_and_user({template_name => "members/readingrec.tmpl",
46 query => $input,
47 type => "intranet",
48 authnotrequired => 0,
49 flagsrequired => {borrowers => 1},
50 debug => 1,
51 });
53 if ($input->param('cardnumber')) {
54 $cardnumber = $input->param('cardnumber');
55 $data = GetMember(cardnumber => $cardnumber);
56 $borrowernumber = $data->{'borrowernumber'}; # we must define this as it is used to retrieve other data about the patron
58 if ($input->param('borrowernumber')) {
59 $borrowernumber = $input->param('borrowernumber');
60 $data = GetMember(borrowernumber => $borrowernumber);
63 my $order = 'date_due desc';
64 my $limit = 0;
65 my ( $issues ) = GetAllIssues($borrowernumber,$order,$limit);
67 my @loop_reading;
68 my @barcodes;
69 my $today = C4::Dates->new();
70 $today = $today->output("iso");
72 foreach my $issue (@{$issues}){
73 my %line;
74 $line{issuestimestamp} = format_date($issue->{'issuestimestamp'});
75 $line{biblionumber} = $issue->{'biblionumber'};
76 $line{title} = $issue->{'title'};
77 $line{author} = $issue->{'author'};
78 $line{classification} = $issue->{'classification'} || $issue->{'itemcallnumber'};
79 $line{date_due} = format_sqldatetime($issue->{date_due});
80 $line{returndate} = format_sqldatetime($issue->{returndate});
81 $line{issuedate} = format_sqldatetime($issue->{issuedate});
82 $line{issuingbranch} = GetBranchName($issue->{'branchcode'});
83 $line{renewals} = $issue->{'renewals'};
84 $line{barcode} = $issue->{'barcode'};
85 $line{volumeddesc} = $issue->{'volumeddesc'};
86 push(@loop_reading,\%line);
87 if (($input->param('op') eq 'export_barcodes') and ($today eq $issue->{'returndate'})) {
88 push( @barcodes, $issue->{'barcode'} );
92 if ($input->param('op') eq 'export_barcodes') {
93 my $borrowercardnumber = GetMember( borrowernumber => $borrowernumber )->{'cardnumber'} ;
94 my $delimiter = "\n";
95 binmode( STDOUT, ":encoding(UTF-8)");
96 print $input->header(
97 -type => 'application/octet-stream',
98 -charset => 'utf-8',
99 -attachment => "$today-$borrowercardnumber-checkinexport.txt"
101 my $content = join($delimiter, uniq(@barcodes));
102 print $content;
103 exit;
106 if ( $data->{'category_type'} eq 'C') {
107 my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
108 my $cnt = scalar(@$catcodes);
109 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
110 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
113 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
114 if (! $limit){
115 $limit = 'full';
118 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
119 $template->param( picture => 1 ) if $picture;
121 if (C4::Context->preference('ExtendedPatronAttributes')) {
122 my $attributes = GetBorrowerAttributes($borrowernumber);
123 $template->param(
124 ExtendedPatronAttributes => 1,
125 extendedattributes => $attributes
129 $template->param(
130 readingrecordview => 1,
131 biblionumber => $data->{'biblionumber'},
132 title => $data->{'title'},
133 initials => $data->{'initials'},
134 surname => $data->{'surname'},
135 othernames => $data->{'othernames'},
136 borrowernumber => $borrowernumber,
137 limit => $limit,
138 firstname => $data->{'firstname'},
139 cardnumber => $data->{'cardnumber'},
140 categorycode => $data->{'categorycode'},
141 category_type => $data->{'category_type'},
142 # category_description => $data->{'description'},
143 categoryname => $data->{'description'},
144 address => $data->{'address'},
145 address2 => $data->{'address2'},
146 city => $data->{'city'},
147 state => $data->{'state'},
148 zipcode => $data->{'zipcode'},
149 country => $data->{'country'},
150 phone => $data->{'phone'},
151 email => $data->{'email'},
152 branchcode => $data->{'branchcode'},
153 is_child => ($data->{'category_type'} eq 'C'),
154 branchname => GetBranchName($data->{'branchcode'}),
155 showfulllink => (scalar @loop_reading > 50),
156 loop_reading => \@loop_reading,
157 activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
159 output_html_with_http_headers $input, $cookie, $template->output;