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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt (-13 / +44 lines)
Lines 107-112 Link Here
107
            $("#"+nodeid).val("");
107
            $("#"+nodeid).val("");
108
        }
108
        }
109
109
110
        function TogglePatronDelete() {
111
            $("#modifications-form").find(":input").not(".prevent-disable").not(":hidden").attr("disabled", $("#delete-checkbox").is(":checked") );
112
        }
110
//]]>
113
//]]>
111
</script>
114
</script>
112
</head>
115
</head>
Lines 191-212 Link Here
191
                    [% IF ( op == 'show_results' ) %]
194
                    [% IF ( op == 'show_results' ) %]
192
                        [% IF ( errors ) %]
195
                        [% IF ( errors ) %]
193
                            <div class="dialog alert">
196
                            <div class="dialog alert">
194
                            <h4>Errors occured:</h4>
197
                                <h4>Errors occured:</h4>
195
                            <ul class="warnings">
198
                                <ul class="warnings">
196
                            [% FOREACH error IN errors %]
199
                                    [% FOREACH error IN errors %]
197
                                [% IF ( error.error == 'can_not_update' ) %]
200
                                        [% IF ( error.error == 'can_not_update' ) %]
198
                                    <li>Can not update patron with borrowernumber [% error.borrowernumber %]</li>
201
                                            <li>Can not update patron with borrowernumber [% error.borrowernumber %]</li>
199
                                [% ELSE %]
202
                                        [% ELSIF error.error == 'current_issues' %]
200
                                    <li>[% error.error %]</li>
203
                                            <li>
201
                                [% END %]
204
                                                Cannot delete patron 
202
                            [% END %]
205
                                                <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% error.borrower.borrowernumber %]">
203
                            </ul>
206
                                                    [% error.borrower.firstname %] [% error.borrower.surname %]
207
                                                </a>.
208
                                                This patron has items checked out.
209
                                            </li>
210
                                        [% ELSIF error.error == 'fees_owed' %]
211
                                            <li>
212
                                                Cannot delete patron 
213
                                                <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% error.borrower.borrowernumber %]">
214
                                                    [% error.borrower.firstname %] [% error.borrower.surname %]
215
                                                </a>.
216
                                                This patron owes fees.
217
                                            </li>
218
                                        [% ELSE %]
219
                                            <li>[% error.error %]</li>
220
                                        [% END %]
221
                                    [% END %]
222
                                </ul>
204
                            </div>
223
                            </div>
205
                        [% END %]
224
                        [% END %]
206
                    [% END %]
225
                    [% END %]
207
226
208
                    [% IF ( op == 'show' ) %]
227
                    [% IF ( op == 'show' ) %]
209
                    <form name="f" action="modborrowers.pl" method="post">
228
                    <form id="modifications-form" name="f" action="modborrowers.pl" method="post">
210
                        <input type="hidden" name="op" value="do" />
229
                        <input type="hidden" name="op" value="do" />
211
                        [% IF ( borrowers ) %]
230
                        [% IF ( borrowers ) %]
212
                            <div id="toolbar"><a id="selectallbutton" href="#">Select All</a> | <a id="clearallbutton" href="#">Clear All</a></div>
231
                            <div id="toolbar"><a id="selectallbutton" href="#">Select All</a> | <a id="clearallbutton" href="#">Clear All</a></div>
Lines 215-220 Link Here
215
                        [% IF borrowers %]
234
                        [% IF borrowers %]
216
                            <div id="cataloguing_additem_itemlist">
235
                            <div id="cataloguing_additem_itemlist">
217
                                <div style="overflow:auto">
236
                                <div style="overflow:auto">
237
                                    [% IF action == 'delete_patrons' %]
238
                                        <h3>Patrons deleted</h3>
239
                                    [% END %]
240
218
                                    <table id="borrowerst">
241
                                    <table id="borrowerst">
219
                                        <thead>
242
                                        <thead>
220
                                            <tr>
243
                                            <tr>
Lines 238-244 Link Here
238
                                            [% FOREACH borrower IN borrowers %]
261
                                            [% FOREACH borrower IN borrowers %]
239
                                                <tr>
262
                                                <tr>
240
                                                    [% IF ( op == 'show' ) %]
263
                                                    [% IF ( op == 'show' ) %]
241
                                                        <td><input type="checkbox" name="borrowernumber" value="[% borrower.borrowernumber %]" checked="checked" /></td>
264
                                                        <td><input type="checkbox" class="prevent-disable" name="borrowernumber" value="[% borrower.borrowernumber %]" checked="checked" /></td>
242
                                                    [% END %]
265
                                                    [% END %]
243
                                                    <td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]">[% borrower.cardnumber %]</a></td>
266
                                                    <td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]">[% borrower.cardnumber %]</a></td>
244
                                                    <td>[% borrower.surname %]</td>
267
                                                    <td>[% borrower.surname %]</td>
Lines 341-349 Link Here
341
                                            </li>
364
                                            </li>
342
                                        [% END %]
365
                                        [% END %]
343
                                    </ol>
366
                                    </ol>
367
368
                                    <ol>
369
                                        <li>
370
                                            <label for="delete_patrons">Delete patrons:</label>
371
                                            <input type="checkbox" class="prevent-disable" name="delete" id="delete-checkbox" value="1" title="check to delete the selected patrons" onclick="TogglePatronDelete()"/>
372
                                        </li>
373
                                    </ol>
374
                                            
344
                                </fieldset>
375
                                </fieldset>
345
                                <fieldset class="action">
376
                                <fieldset class="action">
346
                                    <input type="submit" name="mainformsubmit" value="Save" />
377
                                    <input type="submit" class="prevent-disable" name="mainformsubmit" id="modications-form-submit" value="Save" />
347
                                    <a href="/cgi-bin/koha/tools/modborrowers.pl" class="cancel">Cancel</a>
378
                                    <a href="/cgi-bin/koha/tools/modborrowers.pl" class="cancel">Cancel</a>
348
                                </fieldset>
379
                                </fieldset>
349
                            </div>
380
                            </div>
(-)a/tools/modborrowers.pl (-75 / +131 lines)
Lines 239-336 if ( $op eq 'show' ) { Link Here
239
239
240
# Process modifications
240
# Process modifications
241
if ( $op eq 'do' ) {
241
if ( $op eq 'do' ) {
242
    my @borrowernumbers = $input->param('borrowernumber');
243
    my @errors;
242
244
243
    my @disabled = $input->param('disable_input');
245
    if ( $input->param("delete") ) {
244
    my $infos;
246
        my @deleted_borrowers;
245
    for my $field ( qw/surname firstname branchcode categorycode sort1 sort2 dateenrolled dateexpiry debarred debarredcomment borrowernotes/ ) {
246
        my $value = $input->param($field);
247
        $infos->{$field} = $value if $value;
248
        $infos->{$field} = "" if grep { /^$field$/ } @disabled;
249
    }
250
251
    my @attributes = $input->param('patron_attributes');
252
    my @attr_values = $input->param('patron_attributes_value');
253
247
254
    my @errors;
248
        for my $borrowernumber (@borrowernumbers) {
255
    my @borrowernumbers = $input->param('borrowernumber');
249
            my $borrower = GetMember( borrowernumber => $borrowernumber );
256
    # For each borrower selected
250
            my ( $overdue_count, $issue_count, $total_fines ) =
257
    for my $borrowernumber ( @borrowernumbers ) {
251
              GetMemberIssuesAndFines($borrowernumber);
258
        # If at least one field are filled, we want to modify the borrower
259
        if ( defined $infos ) {
260
            $infos->{borrowernumber} = $borrowernumber;
261
            my $success = ModMember(%$infos);
262
            push @errors, { error => "can_not_update", borrowernumber => $infos->{borrowernumber} } if not $success;
263
        }
264
252
265
        #
253
            if ($issue_count) {
266
        my $borrower_categorycode = GetBorrowerCategorycode $borrowernumber;
254
                push( @errors,
267
        my $i=0;
255
                    { error => "current_issues", borrower => $borrower } );
268
        for ( @attributes ) {
256
            }
269
            my $attribute;
257
            elsif ($total_fines) {
270
            $attribute->{code} = $_;
258
                push( @errors,
271
            $attribute->{attribute} = $attr_values[$i];
259
                    { error => "fees_owed", borrower => $borrower } );
272
            my $attr_type = C4::Members::AttributeTypes->fetch( $_ );
260
            }
273
            # If this borrower is not in the category of this attribute, we don't want to modify this attribute
261
            else {
274
            ++$i and next if $attr_type->{category_code} and $attr_type->{category_code} ne $borrower_categorycode;
262
                MoveMemberToDeleted($borrowernumber);
275
            my $valuename = "attr" . $i . "_value";
263
                DelMember($borrowernumber);
276
            if ( grep { /^$valuename$/ } @disabled ) {
264
                push( @deleted_borrowers, $borrower );
277
                # The attribute is disabled, we remove it for this borrower !
278
                eval {
279
                    C4::Members::Attributes::DeleteBorrowerAttribute( $borrowernumber, $attribute );
280
                };
281
                push @errors, { error => $@ } if $@;
282
            } else {
283
                # Attribute's value is empty, we don't want to modify it
284
                ++$i and next if not $attribute->{attribute};
285
286
                eval {
287
                    C4::Members::Attributes::UpdateBorrowerAttribute( $borrowernumber, $attribute );
288
                };
289
                push @errors, { error => $@ } if $@;
290
            }
265
            }
291
            $i++;
292
        }
266
        }
267
268
        $template->param(
269
            borrowers => \@deleted_borrowers,
270
            action    => 'delete_patrons',
271
        );
293
    }
272
    }
294
    $op = "show_results"; # We have process modifications, the user want to view its
273
    else {
274
        my @disabled = $input->param('disable_input');
275
        my $infos;
295
276
296
    # Construct the results list
277
        for my $field (
297
    my @borrowers;
278
            qw/surname firstname branchcode categorycode sort1 sort2 dateenrolled dateexpiry debarred debarredcomment borrowernotes/
298
    my $max_nb_attr = 0;
279
          )
299
    for my $borrowernumber ( @borrowernumbers ) {
280
        {
300
        my $borrower = GetBorrowerInfos( borrowernumber => $borrowernumber );
281
            my $value = $input->param($field);
301
        if ( $borrower ) {
282
            $infos->{$field} = $value if $value;
302
            $max_nb_attr = scalar( @{ $borrower->{patron_attributes} } )
283
            $infos->{$field} = "" if grep { /^$field$/ } @disabled;
303
                if scalar( @{ $borrower->{patron_attributes} } ) > $max_nb_attr;
304
            push @borrowers, $borrower;
305
        }
284
        }
306
    }
307
    my @patron_attributes_option;
308
    for my $borrower ( @borrowers ) {
309
        push @patron_attributes_option, { value => "$_->{code}", lib => $_->{code} } for @{ $borrower->{patron_attributes} };
310
        my $length = scalar( @{ $borrower->{patron_attributes} } );
311
        push @{ $borrower->{patron_attributes} }, {} for ( $length .. $max_nb_attr - 1);
312
    }
313
285
314
    my @attributes_header = ();
286
        my @attributes  = $input->param('patron_attributes');
315
    for ( 1 .. scalar( $max_nb_attr ) ) {
287
        my @attr_values = $input->param('patron_attributes_value');
316
        push @attributes_header, { attribute => "Attributes $_" };
288
317
    }
289
        # For each borrower selected
290
        for my $borrowernumber (@borrowernumbers) {
291
292
            # If at least one field are filled, we want to modify the borrower
293
            if ( defined $infos ) {
294
                $infos->{borrowernumber} = $borrowernumber;
295
                my $success = ModMember(%$infos);
296
                push @errors,
297
                  {
298
                    error          => "can_not_update",
299
                    borrowernumber => $infos->{borrowernumber}
300
                  }
301
                  if not $success;
302
            }
318
303
319
    $template->param( borrowers => \@borrowers );
304
            my $borrower_categorycode = GetBorrowerCategorycode $borrowernumber;
320
    $template->param( attributes_header => \@attributes_header );
305
            my $i                     = 0;
306
            for (@attributes) {
307
                my $attribute;
308
                $attribute->{code}      = $_;
309
                $attribute->{attribute} = $attr_values[$i];
310
                my $attr_type = C4::Members::AttributeTypes->fetch($_);
311
312
                # If this borrower is not in the category of this attribute, we don't want to modify this attribute
313
                ++$i and next
314
                  if $attr_type->{category_code}
315
                      and $attr_type->{category_code} ne $borrower_categorycode;
316
317
                my $valuename = "attr" . $i . "_value";
318
                if ( grep { /^$valuename$/ } @disabled ) {
319
320
                   # The attribute is disabled, we remove it for this borrower !
321
                    eval {
322
                        C4::Members::Attributes::DeleteBorrowerAttribute(
323
                            $borrowernumber, $attribute );
324
                    };
325
                    push @errors, { error => $@ } if $@;
326
                }
327
                else {
328
329
                    # Attribute's value is empty, we don't want to modify it
330
                    ++$i and next if not $attribute->{attribute};
331
332
                    eval {
333
                        C4::Members::Attributes::UpdateBorrowerAttribute(
334
                            $borrowernumber, $attribute );
335
                    };
336
                    push @errors, { error => $@ } if $@;
337
                }
338
                $i++;
339
            }
340
341
            # Construct the results list
342
            my @borrowers;
343
            my $max_nb_attr = 0;
344
            for my $borrowernumber (@borrowernumbers) {
345
                my $borrower =
346
                  GetBorrowerInfos( borrowernumber => $borrowernumber );
347
                if ($borrower) {
348
                    $max_nb_attr = scalar( @{ $borrower->{patron_attributes} } )
349
                      if scalar( @{ $borrower->{patron_attributes} } ) >
350
                          $max_nb_attr;
351
                    push @borrowers, $borrower;
352
                }
353
            }
354
            my @patron_attributes_option;
355
            for my $borrower (@borrowers) {
356
                push @patron_attributes_option,
357
                  { value => "$_->{code}", lib => $_->{code} }
358
                  for @{ $borrower->{patron_attributes} };
359
360
                my $length = scalar( @{ $borrower->{patron_attributes} } );
361
362
                push @{ $borrower->{patron_attributes} }, {}
363
                  for ( $length .. $max_nb_attr - 1 );
364
            }
365
366
            my @attributes_header = ();
367
            for ( 1 .. scalar($max_nb_attr) ) {
368
                push @attributes_header, { attribute => "Attributes $_" };
369
            }
370
371
            $template->param(
372
                borrowers         => \@borrowers,
373
                attributes_header => \@attributes_header
374
            );
375
        }
376
377
    }
321
378
322
    $template->param( borrowers => \@borrowers );
323
    $template->param( errors => \@errors );
379
    $template->param( errors => \@errors );
380
381
    $op = "show_results";
382
324
} else {
383
} else {
325
384
326
    $template->param( patron_lists => [ GetPatronLists() ] );
385
    $template->param( patron_lists => [ GetPatronLists() ] );
327
}
386
}
328
387
329
$template->param(
388
$template->param( op => $op );
330
    op => $op,
389
331
);
332
output_html_with_http_headers $input, $cookie, $template->output;
390
output_html_with_http_headers $input, $cookie, $template->output;
333
exit;
334
391
335
sub GetBorrowerInfos {
392
sub GetBorrowerInfos {
336
    my ( %info ) = @_;
393
    my ( %info ) = @_;
337
- 

Return to bug 10612