use Modern::Perl;
use CGI qw ( -utf8 );
-use List::MoreUtils qw/uniq/;
-use C4::Auth;
+use C4::Auth qw( get_template_and_user );
use C4::Context;
-use C4::Koha;
-use C4::Acquisition;
-use C4::Output;
-use C4::Reports;
-use C4::Circulation;
-use C4::Members::AttributeTypes;
+use C4::Koha qw( GetAuthorisedValues );
+use C4::Output qw( output_html_with_http_headers );
+use C4::Reports qw( GetDelimiterChoices );
use Koha::AuthorisedValues;
-use Koha::DateUtils;
use Koha::Libraries;
+use Koha::Patron::Attribute::Types;
use Koha::Patron::Categories;
-use Date::Calc qw(
- Today
- Add_Delta_YM
- );
+use Date::Calc qw( Add_Delta_YM Today );
=head1 NAME
=cut
-my $input = new CGI;
+my $input = CGI->new;
my $do_it=$input->param('do_it');
my $fullreportname = "reports/borrowers_stats.tt";
my $line = $input->param("Line");
my $column = $input->param("Column");
my @filters = $input->multi_param("Filter");
-$filters[3] = eval { output_pref( { dt => dt_from_string( $filters[3]), dateonly => 1, dateformat => 'iso' } ); }
- if ( $filters[3] );
-$filters[4] = eval { output_pref ({ dt => dt_from_string( $filters[4]), dateonly => 1, dateformat => 'iso' } ); }
- if ( $filters[4] );
my $digits = $input->param("digits");
our $period = $input->param("period");
my $borstat = $input->param("status");
my $borstat1 = $input->param("activity");
my $output = $input->param("output");
my $basename = $input->param("basename");
-our $sep = $input->param("sep");
-$sep = "\t" if ($sep and $sep eq 'tabulation');
+our $sep = C4::Context->csv_delimiter(scalar $input->param("sep"));
my ($template, $borrowernumber, $cookie)
= get_template_and_user({template_name => $fullreportname,
query => $input,
type => "intranet",
- authnotrequired => 0,
flagsrequired => {reports => '*'},
- debug => 1,
});
$template->param(do_it => $do_it);
if ($do_it) {
CGIsepChoice => $CGIsepChoice,
);
if (C4::Context->preference('ExtendedPatronAttributes')) {
- $template->param(ExtendedPatronAttributes => 1);
patron_attributes_form($template);
}
}
# check parameters
my @valid_names = qw(categorycode zipcode branchcode sex sort1 sort2);
- my @attribute_types = C4::Members::AttributeTypes::GetAttributeTypes;
if ($line =~ /^patron_attr\.(.*)/) {
my $attribute_type = $1;
- return unless (grep {$attribute_type eq $_->{code}} @attribute_types);
+ return unless Koha::Patron::Attribute::Types->find($attribute_type);
} else {
- return unless (grep /^$line$/, @valid_names);
+ return unless (grep { $_ eq $line } @valid_names);
}
if ($column =~ /^patron_attr\.(.*)/) {
my $attribute_type = $1;
- return unless (grep {$attribute_type eq $_->{code}} @attribute_types);
+ return unless Koha::Patron::Attribute::Types->find($attribute_type);
} else {
- return unless (grep /^$column$/, @valid_names);
+ return unless (grep { $_ eq $column } @valid_names);
}
return if ($digits and $digits !~ /^\d+$/);
- return if ($status and (grep /^$status$/, qw(debarred gonenoaddress lost)) == 0);
- return if ($activity and (grep /^$activity$/, qw(active nonactive)) == 0);
+ return if ($status and (grep { $_ eq $status } qw(debarred gonenoaddress lost)) == 0);
+ return if ($activity and (grep { $_ eq $activity } qw(active nonactive)) == 0);
# Filters
my $linefilter;
foreach my $i (0 .. scalar @$filters) {
my %cell;
if ( @$filters[$i] ) {
- if ($i == 3 or $i == 4) {
- $cell{filter} = eval { output_pref( { dt => dt_from_string( @$filters[$i] ), dateonly => 1 }); }
- if ( @$filters[$i] );
- } else {
- $cell{filter} = @$filters[$i];
- }
-
if ( $i == 0) { $cell{crit} = "Cat code"; }
elsif ( $i == 1 ) { $cell{crit} = "ZIP/Postal code"; }
elsif ( $i == 2 ) { $cell{crit} = "Branch code"; }
}
}
- my @branchcodes = map { $_->branchcode } Koha::Libraries->search;
+ my @branchcodes = Koha::Libraries->search->get_column('branchcode');
($status ) and push @loopfilter,{crit=>"Status", filter=>$status };
($activity) and push @loopfilter,{crit=>"Activity",filter=>$activity};
# year of activity
$strcalc .= " AND attribute_$type.attribute LIKE '" . $filter . "' ";
}
}
- $strcalc .= " AND borrowernumber in (select distinct(borrowernumber) from old_issues where issuedate > '" . $newperioddate . "')" if ($activity eq 'active');
- $strcalc .= " AND borrowernumber not in (select distinct(borrowernumber) from old_issues where issuedate > '" . $newperioddate . "' AND borrowernumber IS NOT NULL)" if ($activity eq 'nonactive');
+ $strcalc .= " AND borrowers.borrowernumber in (select distinct(borrowernumber) from old_issues where issuedate > '" . $newperioddate . "')" if ($activity eq 'active');
+ $strcalc .= " AND borrowers.borrowernumber not in (select distinct(borrowernumber) from old_issues where issuedate > '" . $newperioddate . "' AND borrowernumber IS NOT NULL)" if ($activity eq 'nonactive');
$strcalc .= " AND $status='1' " if ($status);
$strcalc .= " GROUP BY ";
sub patron_attributes_form {
my $template = shift;
- my @types = C4::Members::AttributeTypes::GetAttributeTypes();
+ my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
+ my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits({}, {}, $library_id);
my %items_by_class;
- foreach my $type (@types) {
- my $attr_type = C4::Members::AttributeTypes->fetch($type->{code});
+ while ( my $attr_type = $attribute_types->next ) {
+ # TODO The following can be simplified easily
my $entry = {
class => $attr_type->class(),
code => $attr_type->code(),