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

(-)a/tools/batchMod.pl (-107 / +131 lines)
Lines 27-33 use C4::Biblio; Link Here
27
use C4::Items;
27
use C4::Items;
28
use C4::Context;
28
use C4::Context;
29
use C4::Koha; # XXX subfield_is_koha_internal_p
29
use C4::Koha; # XXX subfield_is_koha_internal_p
30
use C4::Branch; # XXX subfield_is_koha_internal_p
30
use C4::Branch; 
31
use C4::BackgroundJob;
31
use C4::BackgroundJob;
32
use C4::ClassSource;
32
use C4::ClassSource;
33
use C4::Dates;
33
use C4::Dates;
Lines 73-79 my $nextop=""; Link Here
73
my @errors; # store errors found while checking data BEFORE saving item.
73
my @errors; # store errors found while checking data BEFORE saving item.
74
my $items_display_hashref;
74
my $items_display_hashref;
75
my $frameworkcode="";
75
my $frameworkcode="";
76
my $tagslib = &GetMarcStructure(1,$frameworkcode);
76
my $tagslib = &GetMarcStructure(1,'');
77
77
78
my $deleted_items = 0;     # Numbers of deleted items
78
my $deleted_items = 0;     # Numbers of deleted items
79
my $not_deleted_items = 0; # Numbers of items that could not be deleted
79
my $not_deleted_items = 0; # Numbers of items that could not be deleted
Lines 82-87 my @not_deleted; # List of the itemnumbers that could not be deleted Link Here
82
my %cookies = parse CGI::Cookie($cookie);
82
my %cookies = parse CGI::Cookie($cookie);
83
my $sessionID = $cookies{'CGISESSID'}->value;
83
my $sessionID = $cookies{'CGISESSID'}->value;
84
84
85
my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
85
86
86
#--- ----------------------------------------------------------------------------
87
#--- ----------------------------------------------------------------------------
87
if ($op eq "action") {
88
if ($op eq "action") {
Lines 133-139 if ($op eq "action") { Link Here
133
        }
134
        }
134
135
135
    #initializing values for updates
136
    #initializing values for updates
136
        my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
137
        if ($values_to_modify){
137
        if ($values_to_modify){
138
                    my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
138
                    my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
139
                    $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
139
                    $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
Lines 246-258 unshift (@$branches, $nochange_branch); Link Here
246
246
247
my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
247
my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
248
248
249
250
foreach my $tag (sort keys %{$tagslib}) {
249
foreach my $tag (sort keys %{$tagslib}) {
251
    # loop through each subfield
250
    # loop through each subfield
251
   	next if ($tag ne $itemtagfield);
252
    foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
252
    foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
253
     	next if subfield_is_koha_internal_p($subfield);
253
     	next if subfield_is_koha_internal_p($subfield);
254
    	next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10");
254
        #field disabled
255
        # barcode and stocknumber are not meant to be batch-modified
255
     	next if (!defined ($tagslib->{$tag}->{$subfield}->{'tab'}) || $tagslib->{$tag}->{$subfield}->{'tab'} eq -1);
256
    	next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.barcode';
256
    	next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.barcode';
257
    	next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.stocknumber';
257
    	next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.stocknumber';
258
	my %subfield_data;
258
	my %subfield_data;
Lines 280-400 foreach my $tag (sort keys %{$tagslib}) { Link Here
280
	    $value =~ s/MM/$month/g;
280
	    $value =~ s/MM/$month/g;
281
	    $value =~ s/DD/$day/g;
281
	    $value =~ s/DD/$day/g;
282
	}
282
	}
283
	$subfield_data{visibility} = "display:none;" if (($tagslib->{$tag}->{$subfield}->{hidden} > 4) || ($tagslib->{$tag}->{$subfield}->{hidden} < -4));
283
	#$subfield_data{visibility} = "display:none;" if (($tagslib->{$tag}->{$subfield}->{hidden} > 4) || ($tagslib->{$tag}->{$subfield}->{hidden} < -4));
284
	# testing branch value if IndependantBranches.
284
	# testing branch value if IndependantBranches.
285
285
286
	my $attributes_no_value = qq(tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" );
286
	    my $attributes_no_value;
287
	my $attributes          = qq($attributes_no_value value="$value" );
287
        my $not_editable = 0;
288
289
        my $attributes_no_value;
290
        my $not_editable = 0;
291
        # Disable barcode and stock numbers batch editing
292
        my @not_editable_koha_fields = ( 'items.barcode', 'items.stocknumber' );
293
        foreach (@not_editable_koha_fields) {
294
            my ($bctag, $bcsubfield) = GetMarcFromKohaField($_, $frameworkcode);
295
                if (($bctag eq $subfield_data{tag}) && ($bcsubfield eq $subfield_data{subfield})) {
296
            $not_editable = 1;
297
            }
298
299
        }
300
301
        my $attributes;
302
        # If a field is found to be non-editable,
303
        if ($not_editable) {
304
            # We mark it as disabled, so the user won't be able to edit it
305
                $attributes_no_value = qq(disabled="disabled"); 
306
            $attributes = $attributes_no_value;
307
            # We also remove it's data, so it won't be modified
308
            undef($subfield_data{tag});
309
            undef($subfield_data{subfield});
310
        } else {
311
            $attributes_no_value = qq(tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" );
312
            $attributes          = qq($attributes_no_value value="$value" );
313
        }
288
314
289
	if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
315
	if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
290
	my @authorised_values;
316
	my @authorised_values;
291
	my %authorised_lib;
317
	my %authorised_lib;
292
	# builds list, depending on authorised value...
318
	# builds list, depending on authorised value...
293
  
319
        my @not_editable_koha_fields = ( 'items.barcode', 'items.stocknumber' );
294
	if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
320
        foreach (@not_editable_koha_fields) {
295
	    foreach my $thisbranch (@$branches) {
321
            my ($bctag, $bcsubfield) = GetMarcFromKohaField($_, $frameworkcode);
296
		push @authorised_values, $thisbranch->{value};
322
                if (($bctag eq $subfield_data{tag}) && ($bcsubfield eq $subfield_data{subfield})) {
297
		$authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname};
323
            $not_editable = 1;
298
	    }
299
        $value = "";
300
	}
301
	elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
302
	    push @authorised_values, "";
303
	    my $sth = $dbh->prepare("select itemtype,description from itemtypes order by description");
304
	    $sth->execute;
305
	    while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
306
		push @authorised_values, $itemtype;
307
		$authorised_lib{$itemtype} = $description;
308
	    }
309
        $value = "";
310
311
          #---- class_sources
312
      }
313
      elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
314
          push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
315
            
316
          my $class_sources = GetClassSources();
317
          my $default_source = C4::Context->preference("DefaultClassificationSource");
318
          
319
          foreach my $class_source (sort keys %$class_sources) {
320
              next unless $class_sources->{$class_source}->{'used'} or
321
                          ($value and $class_source eq $value)      or
322
                          ($class_source eq $default_source);
323
              push @authorised_values, $class_source;
324
              $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
325
          }
324
          }
326
		  $value = '';
325
        }
326
        elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
327
            push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
328
            my $sth = $dbh->prepare("select itemtype,description from itemtypes order by description");
329
            $sth->execute;
330
            while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
331
            push @authorised_values, $itemtype;
332
            $authorised_lib{$itemtype} = $description;
333
            }
327
334
328
          #---- "true" authorised value
335
          #---- "true" authorised value
329
      }
336
      }
330
      else {
337
          elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
331
          push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
338
              push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
332
          $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value} );
339
                
333
          while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
340
              my $class_sources = GetClassSources();
334
              push @authorised_values, $value;
341
              my $default_source = C4::Context->preference("DefaultClassificationSource");
335
              $authorised_lib{$value} = $lib;
342
              
343
              foreach my $class_source (sort keys %$class_sources) {
344
                  next unless $class_sources->{$class_source}->{'used'} or
345
                              ($value and $class_source eq $value)      or
346
                              ($class_source eq $default_source);
347
                  push @authorised_values, $class_source;
348
                  $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
349
              }
350
              $value = $default_source unless ($value);
351
352
              #---- "true" authorised value
336
          }
353
          }
337
      }
354
          else {
338
      $subfield_data{marc_value} =CGI::scrolling_list(      # FIXME: factor out scrolling_list
355
              push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
339
          -name     => "field_value",
356
              $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value} );
340
          -values   => \@authorised_values,
357
              while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
341
          -default  => $value,
358
                  push @authorised_values, $value;
342
          -labels   => \%authorised_lib,
359
                  $authorised_lib{$value} = $lib;
343
          -override => 1,
360
              }
344
          -size     => 1,
361
          }
345
          -multiple => 0,
362
          $subfield_data{marc_value} =CGI::scrolling_list(      # FIXME: factor out scrolling_list
346
          -tabindex => 1,
363
              -name     => "field_value",
347
          -id       => "tag_".$tag."_subfield_".$subfield."_".$index_subfield,
364
              -values   => \@authorised_values,
348
          -class    => "input_marceditor",
365
              -default  => $value,
349
      );
366
              -labels   => \%authorised_lib,
350
    # it's a thesaurus / authority field
367
              -override => 1,
351
    }
368
              -size     => 1,
352
    elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
369
              -multiple => 0,
353
        $subfield_data{marc_value} = "<input type=\"text\" $attributes />
370
              -tabindex => 1,
354
            <a href=\"#\" class=\"buttonDot\"
371
              -id       => "tag_".$tag."_subfield_".$subfield."_".$index_subfield,
355
                onclick=\"Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=".$tagslib->{$tag}->{$subfield}->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}'); return false;\" title=\"Tag Editor\">...</a>
372
              -class    => "input_marceditor",
356
    ";
373
          );
357
    # it's a plugin field
374
        # it's a thesaurus / authority field
358
    }
375
        }
359
    elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) {
376
        elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
360
        # opening plugin
377
            $subfield_data{marc_value} = "<input type=\"text\" $attributes />
361
        my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
378
                <a href=\"#\" class=\"buttonDot\"
362
        if (do $plugin) {
379
                    onclick=\"Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=".$tagslib->{$tag}->{$subfield}->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}'); return false;\" title=\"Tag Editor\">...</a>
363
			my $temp;
380
        ";
364
            my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
381
        # it's a plugin field
365
            my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
382
        }
366
            $subfield_data{marc_value} = qq[<input $attributes
383
        elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) {
367
                onfocus="Focus$function_name($subfield_data{random}, '$subfield_data{id}');"
384
            # opening plugin
368
                 onblur=" Blur$function_name($subfield_data{random}, '$subfield_data{id}');" />
385
            my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
369
                <a href="#" class="buttonDot" onclick="Clic$function_name('$subfield_data{id}'); return false;" title="Tag Editor">...</a>
386
            if (do $plugin) {
370
                $javascript];
387
                my $temp;
388
                my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
389
                my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
390
                $subfield_data{marc_value} = qq[<input $attributes
391
                    onfocus="Focus$function_name($subfield_data{random}, '$subfield_data{id}');"
392
                     onblur=" Blur$function_name($subfield_data{random}, '$subfield_data{id}');" />
393
                    <a href="#" class="buttonDot" onclick="Clic$function_name('$subfield_data{id}'); return false;" title="Tag Editor">...</a>
394
                    $javascript];
395
            } else {
396
                warn "Plugin Failed: $plugin";
397
                $subfield_data{marc_value} = "<input $attributes />"; # supply default input form
398
            }
399
        }
400
# Donot hide any field in edit
401
#        elsif ( $tag eq '' ) {       # it's an hidden field
402
#            $subfield_data{marc_value} = qq(<input type="hidden" $attributes />);
403
#        }
404
#        elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {   # FIXME: shouldn't input type be "hidden" ?
405
#            $subfield_data{marc_value} = qq(<input type="hidden" $attributes />);
406
#        }
407
        elsif ( length($value) > 100
408
                or (C4::Context->preference("marcflavour") eq "UNIMARC" and
409
                      300 <= $tag && $tag < 400 && $subfield eq 'a' )
410
                or (C4::Context->preference("marcflavour") eq "MARC21"  and
411
                      500 <= $tag && $tag < 600                     )
412
              ) {
413
            # oversize field (textarea)
414
            $subfield_data{marc_value} = "<textarea $attributes_no_value>$value</textarea>\n";
371
        } else {
415
        } else {
372
            warn "Plugin Failed: $plugin";
416
            # it's a standard field
373
            $subfield_data{marc_value} = "<input $attributes />"; # supply default input form
417
             $subfield_data{marc_value} = "<input $attributes />";
374
        }
418
        }
419
    #   $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
420
        push (@loop_data, \%subfield_data);
421
        $i++
375
    }
422
    }
376
    elsif ( $tag eq '' ) {       # it's an hidden field
377
        $subfield_data{marc_value} = qq(<input type="hidden" $attributes />);
378
    }
379
    elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {   # FIXME: shouldn't input type be "hidden" ?
380
        $subfield_data{marc_value} = qq(<input type="text" $attributes />);
381
    }
382
    elsif ( length($value) > 100
383
            or (C4::Context->preference("marcflavour") eq "UNIMARC" and
384
                  300 <= $tag && $tag < 400 && $subfield eq 'a' )
385
            or (C4::Context->preference("marcflavour") eq "MARC21"  and
386
                  500 <= $tag && $tag < 600                     )
387
          ) {
388
        # oversize field (textarea)
389
        $subfield_data{marc_value} = "<textarea $attributes_no_value>$value</textarea>\n";
390
    } else {
391
        # it's a standard field
392
         $subfield_data{marc_value} = "<input $attributes />";
393
    }
394
#   $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
395
    push (@loop_data, \%subfield_data);
396
    $i++
397
  }
398
} # -- End foreach tag
423
} # -- End foreach tag
399
424
400
425
401
- 

Return to bug 6018