X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=tools%2Fmodborrowers.pl;h=bb35b8e1c03f405e916eec466f6ea455e7059518;hb=2802a4dd91a52c5bcf81c36f169ae65fd3d731a5;hp=5c3b5f7a5b25440edcb7963a7d675acc6a7a4d03;hpb=37e634bb5b99ab4bcdba45062527ad6bfe439f47;p=koha-ffzg.git diff --git a/tools/modborrowers.pl b/tools/modborrowers.pl index 5c3b5f7a5b..bb35b8e1c0 100755 --- a/tools/modborrowers.pl +++ b/tools/modborrowers.pl @@ -27,68 +27,86 @@ use Modern::Perl; use CGI qw ( -utf8 ); -use C4::Auth; -use C4::Koha; +use C4::Auth qw( get_template_and_user ); +use C4::Koha qw( GetAuthorisedValues ); use C4::Members; -use C4::Members::Attributes; -use C4::Output; -use List::MoreUtils qw /any uniq/; +use C4::Output qw( output_html_with_http_headers ); use Koha::DateUtils qw( dt_from_string ); -use Koha::List::Patron; +use Koha::List::Patron qw( GetPatronLists ); use Koha::Libraries; use Koha::Patron::Categories; -use Koha::Patron::Debarments; +use Koha::Patron::Debarments qw( AddDebarment DelDebarment GetDebarments ); use Koha::Patrons; +use List::MoreUtils qw(uniq); -my $input = new CGI; +my $input = CGI->new; my $op = $input->param('op') || 'show_form'; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "tools/modborrowers.tt", query => $input, type => "intranet", - authnotrequired => 0, flagsrequired => { tools => "edit_patrons" }, } ); my $logged_in_user = Koha::Patrons->find( $loggedinuser ); -my %cookies = parse CGI::Cookie($cookie); -my $sessionID = $cookies{'CGISESSID'}->value; +$template->param( CanUpdatePasswordExpiration => 1 ) if $logged_in_user->is_superlibrarian; + my $dbh = C4::Context->dbh; # Show borrower informations if ( $op eq 'show' ) { - my $filefh = $input->upload('uploadfile'); - my $filecontent = $input->param('filecontent'); - my $patron_list_id = $input->param('patron_list_id'); my @borrowers; - my @cardnumbers; - my ( @notfoundcardnumbers, @from_another_group_of_libraries ); + my @patronidnumbers; + my @notfoundcardnumbers; + my $useborrowernumbers = 0; # Get cardnumbers from a file or the input area - my @contentlist; - if ($filefh) { - while ( my $content = <$filefh> ) { - $content =~ s/[\r\n]*$//g; - push @cardnumbers, $content if $content; + if( my $cardnumberlist = $input->param('cardnumberlist') ){ + # User submitted a list of card numbers + push @patronidnumbers, split( /\s\n/, $cardnumberlist ); + } elsif ( my $cardnumberuploadfile = $input->param('cardnumberuploadfile') ){ + # User uploaded a file of card numbers + binmode $cardnumberuploadfile, ':encoding(UTF-8)'; + while ( my $content = <$cardnumberuploadfile> ) { + next unless $content; + $content =~ s/[\r\n]*$//; + push @patronidnumbers, $content if $content; + } + } elsif ( my $borrowernumberlist = $input->param('borrowernumberlist') ){ + # User submitted a list of borrowernumbers + $useborrowernumbers = 1; + push @patronidnumbers, split( /\s\n/, $borrowernumberlist ); + } elsif ( my $borrowernumberuploadfile = $input->param('borrowernumberuploadfile') ){ + # User uploaded a file of borrowernumbers + $useborrowernumbers = 1; + binmode $borrowernumberuploadfile, ':encoding(UTF-8)'; + while ( my $content = <$borrowernumberuploadfile> ) { + next unless $content; + $content =~ s/[\r\n]*$//; + push @patronidnumbers, $content if $content; } - } elsif ( $patron_list_id ) { + } elsif ( my $patron_list_id = $input->param('patron_list_id') ){ + # User selected a patron list my ($list) = GetPatronLists( { patron_list_id => $patron_list_id } ); - - @cardnumbers = + @patronidnumbers = $list->patron_list_patrons()->search_related('borrowernumber') ->get_column('cardnumber')->all(); - - } else { - if ( my $list = $input->param('cardnumberlist') ) { - push @cardnumbers, split( /\s\n/, $list ); - } } my $max_nb_attr = 0; - for my $cardnumber ( @cardnumbers ) { - my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } ); + + # Make sure there is only one of each patron id number + @patronidnumbers = uniq( @patronidnumbers ); + + for my $patronidnumber ( @patronidnumbers ) { + my $patron; + if( $useborrowernumbers == 1 ){ + $patron = Koha::Patrons->find( { borrowernumber => $patronidnumber } ); + } else { + $patron = Koha::Patrons->find( { cardnumber => $patronidnumber } ); + } if ( $patron ) { if ( $logged_in_user->can_see_patron_infos( $patron ) ) { my $borrower = $patron->unblessed; @@ -98,10 +116,10 @@ if ( $op eq 'show' ) { $max_nb_attr = $borrower->{patron_attributes_count} if $borrower->{patron_attributes_count} > $max_nb_attr; push @borrowers, $borrower; } else { - push @notfoundcardnumbers, $cardnumber; + push @notfoundcardnumbers, $patronidnumber; } } else { - push @notfoundcardnumbers, $cardnumber; + push @notfoundcardnumbers, $patronidnumber; } } @@ -114,8 +132,9 @@ if ( $op eq 'show' ) { # Construct the patron attributes list my @patron_attributes_values; my @patron_attributes_codes; - my $patron_attribute_types = Koha::Patron::Attribute::Types->filter_by_branch_limitations; - my @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']}); + my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; + my $patron_attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits({}, {}, $library_id); + my @patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['description']})->as_list; while ( my $attr_type = $patron_attribute_types->next ) { # TODO Repeatable attributes are not correctly managed and can cause data lost. # This should be implemented. @@ -132,7 +151,7 @@ if ( $op eq 'show' ) { my $category_code = $attr_type->category_code; my ( $category_lib ) = map { - ( defined $category_code and $attr_type->categorycode eq $category_code ) ? $attr_type->description : () + ( defined $category_code and $attr_type->category_code eq $category_code ) ? $attr_type->description : () } @patron_categories; push @patron_attributes_codes, { @@ -152,6 +171,7 @@ if ( $op eq 'show' ) { @notfoundcardnumbers = map { { cardnumber => $_ } } @notfoundcardnumbers; $template->param( notfoundcardnumbers => \@notfoundcardnumbers ) if @notfoundcardnumbers; + $template->param( useborrowernumbers => $useborrowernumbers ); # Construct drop-down list values my $branches = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed; @@ -312,6 +332,8 @@ if ( $op eq 'show' ) { }, ); + push @fields, { name => "password_expiration_date", type => "date" } if $logged_in_user->is_superlibrarian; + $template->param('patron_attributes_codes', \@patron_attributes_codes); $template->param('patron_attributes_values', \@patron_attributes_values); @@ -323,16 +345,18 @@ if ( $op eq 'do' ) { my @disabled = $input->multi_param('disable_input'); my $infos; - for my $field ( qw/surname firstname branchcode categorycode streetnumber address address2 city state zipcode country email phone mobile sort1 sort2 dateenrolled dateexpiry borrowernotes opacnote/ ) { + for my $field ( qw/surname firstname branchcode categorycode streetnumber address address2 city state zipcode country email phone mobile sort1 sort2 dateenrolled dateexpiry password_expiration_date borrowernotes opacnote debarred debarredcomment/ ) { my $value = $input->param($field); $infos->{$field} = $value if $value; $infos->{$field} = "" if grep { $_ eq $field } @disabled; } - for my $field ( qw( dateenrolled dateexpiry debarred ) ) { + for my $field ( qw( dateenrolled dateexpiry debarred password_expiration_date ) ) { $infos->{$field} = dt_from_string($infos->{$field}) if $infos->{$field}; } + delete $infos->{password_expiration_date} unless $logged_in_user->is_superlibrarian; + my @attributes = $input->multi_param('patron_attributes'); my @attr_values = $input->multi_param('patron_attributes_value'); @@ -381,7 +405,7 @@ if ( $op eq 'do' ) { $attribute->{attribute} = $attr_values[$i]; my $attr_type = Koha::Patron::Attribute::Types->find($_); # If this borrower is not in the category of this attribute, we don't want to modify this attribute - ++$i and next if $attr_type->category_code and $attr_type->category_code ne $patron->category_code; + ++$i and next if $attr_type->category_code and $attr_type->category_code ne $patron->categorycode; my $valuename = "attr" . $i . "_value"; if ( grep { $_ eq $valuename } @disabled ) { # The attribute is disabled, we remove it for this borrower !