View | Details | Raw Unified | Return to bug 24019
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt (-34 / +104 lines)
Lines 36-80 Link Here
36
36
37
                [% IF ( op == 'show_form' ) %]
37
                [% IF ( op == 'show_form' ) %]
38
                <h1>Batch patron modification</h1>
38
                <h1>Batch patron modification</h1>
39
                <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/tools/modborrowers.pl">
39
                <form id="patron_batchmod_form" method="post" enctype="multipart/form-data" action="/cgi-bin/koha/tools/modborrowers.pl">
40
                    <fieldset class="rows">
40
                    <input type="hidden" name="op" value="show" />
41
                        <legend>Use a file</legend>
41
                    <div id="batch_patron_options" class="toptabs">
42
                        <ol>
42
                        <ul>
43
                            <li><label for="uploadfile">File: </label> <input type="file" id="uploadfile" name="uploadfile" /></li>
44
                        </ol>
45
                    </fieldset>
46
47
                    [% IF patron_lists %]
48
                    <fieldset class="rows">
49
                        <legend>Or use a patron list</legend>
50
                        <ol>
51
                            <li>
43
                            <li>
52
                                <label for="patron_list_id">Patron list: </label>
44
                                <a href="#usecardnumber">By card number</a>
53
                                <select id="patron_list_id" name="patron_list_id">
54
                                    <option value=""></option>
55
                                    [% FOREACH pl IN patron_lists %]
56
                                        <option value="[% pl.patron_list_id | html %]">[% pl.name | html %]</option>
57
                                    [% END %]
58
                                </select>
59
                            </li>
45
                            </li>
60
                        </ol>
61
                    </fieldset>
62
                    [% END %]
63
64
                    <fieldset class="rows">
65
                        <legend>Or list cardnumbers one by one</legend>
66
                        <ol>
67
                            <li>
46
                            <li>
68
                              <label for="cardnumberlist">Card number list (one cardnumber per line): </label>
47
                                <a href="#useborrowernumber">By borrowernumber</a>
69
                              <textarea rows="10" cols="30" id="cardnumberlist" name="cardnumberlist">[% cardnumberlist | html %]</textarea>
70
                            </li>
48
                            </li>
71
                        </ol>
49
                            [% IF patron_lists %]
50
                                <li>
51
                                    <a href="#uselist">By patron list</a>
52
                                </li>
53
                            [% END %]
54
                        </ul>
55
                        <div id="usecardnumber">
56
                            <fieldset class="rows">
57
                                <legend>Use a file of card numbers</legend>
58
                                <ol>
59
                                    <li>
60
                                        <label for="cardnumberuploadfile">File: </label> <input type="file" id="cardnumberuploadfile" name="cardnumberuploadfile" />
61
                                        <div class="hint">File must contain one card number per line.</div>
62
                                    </li>
63
                                </ol>
64
                            </fieldset>
65
                            <fieldset class="rows">
66
                                <legend>Or list card numbers one by one</legend>
67
                                <ol>
68
                                    <li>
69
                                    <label for="cardnumberlist">Card number list (one card number per line): </label>
70
                                    <textarea rows="10" cols="30" id="cardnumberlist" name="cardnumberlist">[% cardnumberlist | html %]</textarea>
71
                                    </li>
72
                                </ol>
73
                            </fieldset>
74
                    <fieldset class="action">
75
                        <input type="submit" value="Continue" class="button" />
76
                        <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
72
                    </fieldset>
77
                    </fieldset>
73
                    <input type="hidden" name="op" value="show" />
78
                        </div>
79
                        <div id="useborrowernumber">
80
                            <fieldset class="rows">
81
                                <legend>Use a file of borrowernumbers</legend>
82
                                <ol>
83
                                    <li>
84
                                        <label for="borrowernumberuploadfile">File: </label> <input type="file" id="borrowernumberuploadfile" name="borrowernumberuploadfile" />
85
                                        <div class="hint">File must contain one borrowernumber per line.</div>
86
                                    </li>
87
                                </ol>
88
                            </fieldset>
89
                            <fieldset class="rows">
90
                                <legend>List borrowernumbers one by one</legend>
91
                                <ol>
92
                                    <li>
93
                                    <label for="borrowernumberlist">Borrowernumber list (one number per line): </label>
94
                                    <textarea rows="10" cols="30" id="borrowernumberlist" name="borrowernumberlist">[% borrowernumberlist | html %]</textarea>
95
                                    </li>
96
                                </ol>
97
                            </fieldset>
98
                    <fieldset class="action">
99
                        <input type="submit" value="Continue" class="button" />
100
                        <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
101
                    </fieldset>
102
                        </div>
103
                        [% IF patron_lists %]
104
                            <div id="uselist">
105
                                <fieldset class="rows">
106
                                    <legend>Use a patron list</legend>
107
                                    <ol>
108
                                        <li>
109
                                            <label for="patron_list_id">Patron list: </label>
110
                                            <select id="patron_list_id" name="patron_list_id">
111
                                                <option value=""> -- Choose a patron list -- </option>
112
                                                [% FOREACH pl IN patron_lists %]
113
                                                    <option value="[% pl.patron_list_id | html %]">[% pl.name | html %]</option>
114
                                                [% END %]
115
                                            </select>
116
                                        </li>
117
                                    </ol>
118
                                </fieldset>
74
                    <fieldset class="action">
119
                    <fieldset class="action">
75
                        <input type="submit" value="Continue" class="button" />
120
                        <input type="submit" value="Continue" class="button" />
76
                        <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
121
                        <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
77
                    </fieldset>
122
                    </fieldset>
123
                            </div>
124
                        [% END %]
125
                    </div><!-- /#batch_patron_options -->
78
                </form>
126
                </form>
79
                [% END %]
127
                [% END %]
80
128
Lines 82-88 Link Here
82
                    [% op = 'noshow' # Change op to prevent display in code below %]
130
                    [% op = 'noshow' # Change op to prevent display in code below %]
83
                    <h1>Batch patrons modification</h1>
131
                    <h1>Batch patrons modification</h1>
84
                    <div class="dialog alert">
132
                    <div class="dialog alert">
85
                        <p>No patron card numbers given.</p>
133
                        <p>No patron card numbers or borrowernumbers given.</p>
86
                        <form action="/cgi-bin/koha/tools/modborrowers.pl" method="get">
134
                        <form action="/cgi-bin/koha/tools/modborrowers.pl" method="get">
87
                         <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> OK</button>
135
                         <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> OK</button>
88
                        </form>
136
                        </form>
Lines 96-105 Link Here
96
                        <h1>Batch patrons results</h1>
144
                        <h1>Batch patrons results</h1>
97
                    [% END %]
145
                    [% END %]
98
                    [% IF ( notfoundcardnumbers ) %]
146
                    [% IF ( notfoundcardnumbers ) %]
99
                        <div class="dialog alert"><p>Warning, the following cardnumbers were not found:</p></div>
147
                        [% IF ( useborrowernumbers ) -%]
148
                            <div class="dialog alert"><p>Warning, the following borrowernumbers were not found:</p></div>
149
                        [% ELSE -%]
150
                            <div class="dialog alert"><p>Warning, the following card numbers were not found:</p></div>
151
                        [% END %]
152
100
                        <table style="margin:auto;">
153
                        <table style="margin:auto;">
101
                            <thead>
154
                            <thead>
102
                                <tr><th>Cardnumbers not found</th></tr>
155
                                [% IF ( useborrowernumbers ) -%]
156
                                    <tr><th>Borrowernumbers not found</th></tr>
157
                                [% ELSE -%]
158
                                    <tr><th>Card numbers not found</th></tr>
159
                                [% END %]
103
                            </thead>
160
                            </thead>
104
                            <tbody>
161
                            <tbody>
105
                                [% FOREACH notfoundcardnumber IN notfoundcardnumbers %]
162
                                [% FOREACH notfoundcardnumber IN notfoundcardnumbers %]
Lines 117-123 Link Here
117
                            [% FOREACH error IN errors %]
174
                            [% FOREACH error IN errors %]
118
                                [% IF ( error.error == 'can_not_update' ) %]
175
                                [% IF ( error.error == 'can_not_update' ) %]
119
                                    <li>Can not update patron.
176
                                    <li>Can not update patron.
120
                                    [% IF ( error.cardnumber ) %] Cardnumber:  [% error.cardnumber | html %] [% END %]
177
                                    [% IF ( error.cardnumber ) %] Card number:  [% error.cardnumber | html %] [% END %]
121
                                    (Borrowernumber: [% error.borrowernumber | html %])
178
                                    (Borrowernumber: [% error.borrowernumber | html %])
122
                                    </li>
179
                                    </li>
123
                                [% ELSE %]
180
                                [% ELSE %]
Lines 387-392 Link Here
387
                    });
444
                    });
388
                    return false;
445
                    return false;
389
                });
446
                });
447
            [% ELSE %]
448
                $("#batch_patron_options").tabs();
390
            [% END %]
449
            [% END %]
391
450
392
            var values = new Array();
451
            var values = new Array();
Lines 421-426 Link Here
421
                e.preventDefault();
480
                e.preventDefault();
422
                del_attributes(this);
481
                del_attributes(this);
423
            });
482
            });
483
            $("#patron_batchmod_form").on("submit", function(){
484
                /* Reset form fields on inactive tabs */
485
                var tab = $(this).find('.ui-tabs-active:first a').attr('href');
486
                if ( tab == '#usecardnumber' ) {
487
                    $("#borrowernumberuploadfile, #patron_list_id, #borrowernumberlist").val("");
488
                } else if ( tab == '#useborrowernumber' ) {
489
                    $("#cardnumberuploadfile, #cardnumberlist, #patron_list_id").val("");
490
                } else { // uselist
491
                    $("#borrowernumberuploadfile, #cardnumberuploadfile, #borrowernumberlist, #cardnumberlist").val("");
492
                }
493
            });
424
        });
494
        });
425
495
426
        function updateAttrValues (select_attr) {
496
        function updateAttrValues (select_attr) {
(-)a/tools/modborrowers.pl (-21 / +39 lines)
Lines 57-91 my $dbh = C4::Context->dbh; Link Here
57
57
58
# Show borrower informations
58
# Show borrower informations
59
if ( $op eq 'show' ) {
59
if ( $op eq 'show' ) {
60
    my $filefh         = $input->upload('uploadfile');
61
    my $filecontent    = $input->param('filecontent');
62
    my $patron_list_id = $input->param('patron_list_id');
63
    my @borrowers;
60
    my @borrowers;
64
    my @cardnumbers;
61
    my @patronidnumbers;
65
    my @notfoundcardnumbers;
62
    my @notfoundcardnumbers;
63
    my $useborrowernumbers = 0;
66
64
67
    # Get cardnumbers from a file or the input area
65
    # Get cardnumbers from a file or the input area
68
    if ($filefh) {
66
    if( my $cardnumberlist = $input->param('cardnumberlist') ){
69
        while ( my $content = <$filefh> ) {
67
        # User submitted a list of card numbers
70
            $content =~ s/[\r\n]*$//g;
68
        push @patronidnumbers, split( /\s\n/, $cardnumberlist );
71
            push @cardnumbers, $content if $content;
69
    } elsif ( my $cardnumberuploadfile = $input->param('cardnumberuploadfile') ){
70
        # User uploaded a file of card numbers
71
        binmode $cardnumberuploadfile, ':encoding(UTF-8)';
72
        while ( my $content = <$cardnumberuploadfile> ) {
73
            next unless $content;
74
            $content =~ s/[\r\n]*$//;
75
            push @patronidnumbers, $content if $content;
72
        }
76
        }
73
    } elsif ( $patron_list_id ) {
77
    } elsif ( my $borrowernumberlist = $input->param('borrowernumberlist') ){
78
        # User submitted a list of borrowernumbers
79
        $useborrowernumbers = 1;
80
        push @patronidnumbers, split( /\s\n/, $borrowernumberlist );
81
    } elsif ( my $borrowernumberuploadfile = $input->param('borrowernumberuploadfile') ){
82
        # User uploaded a file of borrowernumbers
83
        $useborrowernumbers = 1;
84
        binmode $borrowernumberuploadfile, ':encoding(UTF-8)';
85
        while ( my $content = <$borrowernumberuploadfile> ) {
86
            next unless $content;
87
            $content =~ s/[\r\n]*$//;
88
            push @patronidnumbers, $content if $content;
89
        }
90
    } elsif ( my $patron_list_id = $input->param('patron_list_id') ){
91
        # User selected a patron list
74
        my ($list) = GetPatronLists( { patron_list_id => $patron_list_id } );
92
        my ($list) = GetPatronLists( { patron_list_id => $patron_list_id } );
75
93
        @patronidnumbers =
76
        @cardnumbers =
77
          $list->patron_list_patrons()->search_related('borrowernumber')
94
          $list->patron_list_patrons()->search_related('borrowernumber')
78
          ->get_column('cardnumber')->all();
95
          ->get_column('cardnumber')->all();
79
80
    } else {
81
        if ( my $list = $input->param('cardnumberlist') ) {
82
            push @cardnumbers, split( /\s\n/, $list );
83
        }
84
    }
96
    }
85
97
86
    my $max_nb_attr = 0;
98
    my $max_nb_attr = 0;
87
    for my $cardnumber ( @cardnumbers ) {
99
88
        my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } );
100
    for my $patronidnumber ( @patronidnumbers ) {
101
        my $patron;
102
        if( $useborrowernumbers == 1 ){
103
            $patron = Koha::Patrons->find( { borrowernumber => $patronidnumber } );
104
        } else {
105
            $patron = Koha::Patrons->find( { cardnumber => $patronidnumber } );
106
        }
89
        if ( $patron ) {
107
        if ( $patron ) {
90
            if ( $logged_in_user->can_see_patron_infos( $patron ) ) {
108
            if ( $logged_in_user->can_see_patron_infos( $patron ) ) {
91
                my $borrower = $patron->unblessed;
109
                my $borrower = $patron->unblessed;
Lines 95-104 if ( $op eq 'show' ) { Link Here
95
                $max_nb_attr = $borrower->{patron_attributes_count} if $borrower->{patron_attributes_count} > $max_nb_attr;
113
                $max_nb_attr = $borrower->{patron_attributes_count} if $borrower->{patron_attributes_count} > $max_nb_attr;
96
                push @borrowers, $borrower;
114
                push @borrowers, $borrower;
97
            } else {
115
            } else {
98
                push @notfoundcardnumbers, $cardnumber;
116
                push @notfoundcardnumbers, $patronidnumber;
99
            }
117
            }
100
        } else {
118
        } else {
101
            push @notfoundcardnumbers, $cardnumber;
119
            push @notfoundcardnumbers, $patronidnumber;
102
        }
120
        }
103
    }
121
    }
104
122
Lines 150-155 if ( $op eq 'show' ) { Link Here
150
    @notfoundcardnumbers = map { { cardnumber => $_ } } @notfoundcardnumbers;
168
    @notfoundcardnumbers = map { { cardnumber => $_ } } @notfoundcardnumbers;
151
    $template->param( notfoundcardnumbers => \@notfoundcardnumbers )
169
    $template->param( notfoundcardnumbers => \@notfoundcardnumbers )
152
        if @notfoundcardnumbers;
170
        if @notfoundcardnumbers;
171
    $template->param( useborrowernumbers => $useborrowernumbers );
153
172
154
    # Construct drop-down list values
173
    # Construct drop-down list values
155
    my $branches = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;
174
    my $branches = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;
156
- 

Return to bug 24019