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

(-)a/C4/Biblio.pm (-339 / +5 lines)
Lines 27-33 use Carp; Link Here
27
use MARC::Record;
27
use MARC::Record;
28
use MARC::File::USMARC;
28
use MARC::File::USMARC;
29
use MARC::File::XML;
29
use MARC::File::XML;
30
use ZOOM;
31
use POSIX qw(strftime);
30
use POSIX qw(strftime);
32
31
33
use C4::Koha;
32
use C4::Koha;
Lines 35-43 use C4::Dates qw/format_date/; Link Here
35
use C4::Log;    # logaction
34
use C4::Log;    # logaction
36
use C4::ClassSource;
35
use C4::ClassSource;
37
use C4::Charset;
36
use C4::Charset;
38
require C4::Heading;
39
require C4::Serials;
40
require C4::Items;
41
37
42
use vars qw($VERSION @ISA @EXPORT);
38
use vars qw($VERSION @ISA @EXPORT);
43
39
Lines 131-137 BEGIN { Link Here
131
      &TransformHtmlToMarc2
127
      &TransformHtmlToMarc2
132
      &TransformHtmlToMarc
128
      &TransformHtmlToMarc
133
      &TransformHtmlToXml
129
      &TransformHtmlToXml
134
      &PrepareItemrecordDisplay
135
      &GetNoZebraIndexes
130
      &GetNoZebraIndexes
136
    );
131
    );
137
}
132
}
Lines 418-426 sub DelBiblio { Link Here
418
    return $error if $error;
413
    return $error if $error;
419
414
420
    # We delete attached subscriptions
415
    # We delete attached subscriptions
421
    my $subscriptions = &C4::Serials::GetFullSubscriptionsFromBiblionumber($biblionumber);
416
    require C4::Serials;
417
    my $subscriptions = C4::Serials::GetFullSubscriptionsFromBiblionumber($biblionumber);
422
    foreach my $subscription (@$subscriptions) {
418
    foreach my $subscription (@$subscriptions) {
423
        &C4::Serials::DelSubscription( $subscription->{subscriptionid} );
419
        C4::Serials::DelSubscription( $subscription->{subscriptionid} );
424
    }
420
    }
425
421
426
    # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
422
    # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
Lines 478-483 MARC record. Link Here
478
=cut
474
=cut
479
475
480
sub LinkBibHeadingsToAuthorities {
476
sub LinkBibHeadingsToAuthorities {
477
    require C4::Heading;
481
    my $bib = shift;
478
    my $bib = shift;
482
479
483
    my $num_headings_changed = 0;
480
    my $num_headings_changed = 0;
Lines 2450-2681 sub TransformMarcToKohaOneField { Link Here
2450
    return $result;
2447
    return $result;
2451
}
2448
}
2452
2449
2453
=head1  OTHER FUNCTIONS
2454
2455
2456
=head2 PrepareItemrecordDisplay
2457
2458
  PrepareItemrecordDisplay($itemrecord,$bibnum,$itemumber,$frameworkcode);
2459
2460
Returns a hash with all the fields for Display a given item data in a template
2461
2462
The $frameworkcode returns the item for the given frameworkcode, ONLY if bibnum is not provided
2463
2464
=cut
2465
2466
sub PrepareItemrecordDisplay {
2467
2468
    my ( $bibnum, $itemnum, $defaultvalues, $frameworkcode ) = @_;
2469
2470
    my $dbh = C4::Context->dbh;
2471
    $frameworkcode = &GetFrameworkCode($bibnum) if $bibnum;
2472
    my ( $itemtagfield, $itemtagsubfield ) = &GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2473
    my $tagslib = &GetMarcStructure( 1, $frameworkcode );
2474
2475
    # return nothing if we don't have found an existing framework.
2476
    return q{} unless $tagslib;
2477
    my $itemrecord;
2478
    if ($itemnum) {
2479
        $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum );
2480
    }
2481
    my @loop_data;
2482
    my $authorised_values_sth = $dbh->prepare( "SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib" );
2483
    foreach my $tag ( sort keys %{$tagslib} ) {
2484
        my $previous_tag = '';
2485
        if ( $tag ne '' ) {
2486
2487
            # loop through each subfield
2488
            my $cntsubf;
2489
            foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
2490
                next if ( subfield_is_koha_internal_p($subfield) );
2491
                next if ( $tagslib->{$tag}->{$subfield}->{'tab'} ne "10" );
2492
                my %subfield_data;
2493
                $subfield_data{tag}           = $tag;
2494
                $subfield_data{subfield}      = $subfield;
2495
                $subfield_data{countsubfield} = $cntsubf++;
2496
                $subfield_data{kohafield}     = $tagslib->{$tag}->{$subfield}->{'kohafield'};
2497
2498
                #        $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
2499
                $subfield_data{marc_lib}   = $tagslib->{$tag}->{$subfield}->{lib};
2500
                $subfield_data{mandatory}  = $tagslib->{$tag}->{$subfield}->{mandatory};
2501
                $subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable};
2502
                $subfield_data{hidden}     = "display:none"
2503
                  if $tagslib->{$tag}->{$subfield}->{hidden};
2504
                my ( $x, $defaultvalue );
2505
                if ($itemrecord) {
2506
                    ( $x, $defaultvalue ) = _find_value( $tag, $subfield, $itemrecord );
2507
                }
2508
                $defaultvalue = $tagslib->{$tag}->{$subfield}->{defaultvalue} unless $defaultvalue;
2509
                if ( !defined $defaultvalue ) {
2510
                    $defaultvalue = q||;
2511
                }
2512
                $defaultvalue =~ s/"/"/g;
2513
2514
                # search for itemcallnumber if applicable
2515
                if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber'
2516
                    && C4::Context->preference('itemcallnumber') ) {
2517
                    my $CNtag      = substr( C4::Context->preference('itemcallnumber'), 0, 3 );
2518
                    my $CNsubfield = substr( C4::Context->preference('itemcallnumber'), 3, 1 );
2519
                    if ($itemrecord) {
2520
                        my $temp = $itemrecord->field($CNtag);
2521
                        if ($temp) {
2522
                            $defaultvalue = $temp->subfield($CNsubfield);
2523
                        }
2524
                    }
2525
                }
2526
                if (   $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber'
2527
                    && $defaultvalues
2528
                    && $defaultvalues->{'callnumber'} ) {
2529
                    my $temp;
2530
                    if ($itemrecord) {
2531
                        $temp = $itemrecord->field($subfield);
2532
                    }
2533
                    unless ($temp) {
2534
                        $defaultvalue = $defaultvalues->{'callnumber'} if $defaultvalues;
2535
                    }
2536
                }
2537
                if (   ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.holdingbranch' || $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.homebranch' )
2538
                    && $defaultvalues
2539
                    && $defaultvalues->{'branchcode'} ) {
2540
                    my $temp;
2541
                    if ($itemrecord) {
2542
                        $temp = $itemrecord->field($subfield);
2543
                    }
2544
                    unless ($temp) {
2545
                        $defaultvalue = $defaultvalues->{branchcode} if $defaultvalues;
2546
                    }
2547
                }
2548
                if (   ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.location' )
2549
                    && $defaultvalues
2550
                    && $defaultvalues->{'location'} ) {
2551
                    my $temp = $itemrecord->field($subfield) if ($itemrecord);
2552
                    unless ($temp) {
2553
                        $defaultvalue = $defaultvalues->{location} if $defaultvalues;
2554
                    }
2555
                }
2556
                if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
2557
                    my @authorised_values;
2558
                    my %authorised_lib;
2559
2560
                    # builds list, depending on authorised value...
2561
                    #---- branch
2562
                    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
2563
                        if (   ( C4::Context->preference("IndependantBranches") )
2564
                            && ( C4::Context->userenv->{flags} % 2 != 1 ) ) {
2565
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches WHERE branchcode = ? ORDER BY branchname" );
2566
                            $sth->execute( C4::Context->userenv->{branch} );
2567
                            push @authorised_values, ""
2568
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2569
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
2570
                                push @authorised_values, $branchcode;
2571
                                $authorised_lib{$branchcode} = $branchname;
2572
                            }
2573
                        } else {
2574
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches ORDER BY branchname" );
2575
                            $sth->execute;
2576
                            push @authorised_values, ""
2577
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2578
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
2579
                                push @authorised_values, $branchcode;
2580
                                $authorised_lib{$branchcode} = $branchname;
2581
                            }
2582
                        }
2583
2584
                        #----- itemtypes
2585
                    } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
2586
                        my $sth = $dbh->prepare( "SELECT itemtype,description FROM itemtypes ORDER BY description" );
2587
                        $sth->execute;
2588
                        push @authorised_values, ""
2589
                          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2590
                        while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
2591
                            push @authorised_values, $itemtype;
2592
                            $authorised_lib{$itemtype} = $description;
2593
                        }
2594
                        #---- class_sources
2595
                    } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
2596
                        push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2597
2598
                        my $class_sources = GetClassSources();
2599
                        my $default_source = C4::Context->preference("DefaultClassificationSource");
2600
2601
                        foreach my $class_source (sort keys %$class_sources) {
2602
                            next unless $class_sources->{$class_source}->{'used'} or
2603
                                        ($class_source eq $default_source);
2604
                            push @authorised_values, $class_source;
2605
                            $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
2606
                        }
2607
2608
                        #---- "true" authorised value
2609
                    } else {
2610
                        $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value} );
2611
                        push @authorised_values, ""
2612
                          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2613
                        while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
2614
                            push @authorised_values, $value;
2615
                            $authorised_lib{$value} = $lib;
2616
                        }
2617
                    }
2618
                    $subfield_data{marc_value} = CGI::scrolling_list(
2619
                        -name     => 'field_value',
2620
                        -values   => \@authorised_values,
2621
                        -default  => "$defaultvalue",
2622
                        -labels   => \%authorised_lib,
2623
                        -size     => 1,
2624
                        -tabindex => '',
2625
                        -multiple => 0,
2626
                    );
2627
                } elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) {
2628
                        # opening plugin
2629
                        my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
2630
                        if (do $plugin) {
2631
                            my $temp;
2632
                            my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, undef );
2633
                            my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, undef );
2634
                            $subfield_data{random}     = int(rand(1000000));    # why do we need 2 different randoms?
2635
                            my $index_subfield = int(rand(1000000));
2636
                            $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
2637
                            $subfield_data{marc_value} = qq[<input tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255"
2638
                                onfocus="Focus$function_name($subfield_data{random}, '$subfield_data{id}');"
2639
                                 onblur=" Blur$function_name($subfield_data{random}, '$subfield_data{id}');" />
2640
                                <a href="#" class="buttonDot" onclick="Clic$function_name('$subfield_data{id}'); return false;" title="Tag Editor">...</a>
2641
                                $javascript];
2642
                        } else {
2643
                            warn "Plugin Failed: $plugin";
2644
                            $subfield_data{marc_value} = qq(<input tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" />); # supply default input form
2645
                        }
2646
                }
2647
                elsif ( $tag eq '' ) {       # it's an hidden field
2648
                    $subfield_data{marc_value} = qq(<input type="hidden" tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" value="$defaultvalue" />);
2649
                }
2650
                elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {   # FIXME: shouldn't input type be "hidden" ?
2651
                    $subfield_data{marc_value} = qq(<input type="text" tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" value="$defaultvalue" />);
2652
                }
2653
                elsif ( length($defaultvalue) > 100
2654
                            or (C4::Context->preference("marcflavour") eq "UNIMARC" and
2655
                                  300 <= $tag && $tag < 400 && $subfield eq 'a' )
2656
                            or (C4::Context->preference("marcflavour") eq "MARC21"  and
2657
                                  500 <= $tag && $tag < 600                     )
2658
                          ) {
2659
                    # oversize field (textarea)
2660
                    $subfield_data{marc_value} = qq(<textarea tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255">$defaultvalue</textarea>\n");
2661
                } else {
2662
                    $subfield_data{marc_value} = "<input type=\"text\" name=\"field_value\" value=\"$defaultvalue\" size=\"50\" maxlength=\"255\" />";
2663
                }
2664
                push( @loop_data, \%subfield_data );
2665
            }
2666
        }
2667
    }
2668
    my $itemnumber;
2669
    if ( $itemrecord && $itemrecord->field($itemtagfield) ) {
2670
        $itemnumber = $itemrecord->subfield( $itemtagfield, $itemtagsubfield );
2671
    }
2672
    return {
2673
        'itemtagfield'    => $itemtagfield,
2674
        'itemtagsubfield' => $itemtagsubfield,
2675
        'itemnumber'      => $itemnumber,
2676
        'iteminformation' => \@loop_data
2677
    };
2678
}
2679
2450
2680
#"
2451
#"
2681
2452
Lines 2839-2844 sub EmbedItemsInMarcBiblio { Link Here
2839
    my @item_fields;
2610
    my @item_fields;
2840
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2611
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2841
    while (my ($itemnumber) = $sth->fetchrow_array) {
2612
    while (my ($itemnumber) = $sth->fetchrow_array) {
2613
        require C4::Items;
2842
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2614
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2843
        push @item_fields, $item_marc->field($itemtag);
2615
        push @item_fields, $item_marc->field($itemtag);
2844
    }
2616
    }
Lines 3632-3743 sub ModBiblioMarc { Link Here
3632
    return $biblionumber;
3404
    return $biblionumber;
3633
}
3405
}
3634
3406
3635
=head2 z3950_extended_services
3636
3637
  z3950_extended_services($serviceType,$serviceOptions,$record);
3638
3639
z3950_extended_services is used to handle all interactions with Zebra's extended serices package, which is employed to perform all management of the MARC data stored in Zebra.
3640
3641
C<$serviceType> one of: itemorder,create,drop,commit,update,xmlupdate
3642
3643
C<$serviceOptions> a has of key/value pairs. For instance, if service_type is 'update', $service_options should contain:
3644
3645
 action => update action, one of specialUpdate, recordInsert, recordReplace, recordDelete, elementUpdate.
3646
3647
and maybe
3648
3649
  recordidOpaque => Opaque Record ID (user supplied) or recordidNumber => Record ID number (system number).
3650
  syntax => the record syntax (transfer syntax)
3651
  databaseName = Database from connection object
3652
3653
To set serviceOptions, call set_service_options($serviceType)
3654
3655
C<$record> the record, if one is needed for the service type
3656
3657
A record should be in XML. You can convert it to XML from MARC by running it through marc2xml().
3658
3659
=cut
3660
3661
sub z3950_extended_services {
3662
    my ( $server, $serviceType, $action, $serviceOptions ) = @_;
3663
3664
    # get our connection object
3665
    my $Zconn = C4::Context->Zconn( $server, 0, 1 );
3666
3667
    # create a new package object
3668
    my $Zpackage = $Zconn->package();
3669
3670
    # set our options
3671
    $Zpackage->option( action => $action );
3672
3673
    if ( $serviceOptions->{'databaseName'} ) {
3674
        $Zpackage->option( databaseName => $serviceOptions->{'databaseName'} );
3675
    }
3676
    if ( $serviceOptions->{'recordIdNumber'} ) {
3677
        $Zpackage->option( recordIdNumber => $serviceOptions->{'recordIdNumber'} );
3678
    }
3679
    if ( $serviceOptions->{'recordIdOpaque'} ) {
3680
        $Zpackage->option( recordIdOpaque => $serviceOptions->{'recordIdOpaque'} );
3681
    }
3682
3683
    # this is an ILL request (Zebra doesn't support it, but Koha could eventually)
3684
    #if ($serviceType eq 'itemorder') {
3685
    #   $Zpackage->option('contact-name' => $serviceOptions->{'contact-name'});
3686
    #   $Zpackage->option('contact-phone' => $serviceOptions->{'contact-phone'});
3687
    #   $Zpackage->option('contact-email' => $serviceOptions->{'contact-email'});
3688
    #   $Zpackage->option('itemorder-item' => $serviceOptions->{'itemorder-item'});
3689
    #}
3690
3691
    if ( $serviceOptions->{record} ) {
3692
        $Zpackage->option( record => $serviceOptions->{record} );
3693
3694
        # can be xml or marc
3695
        if ( $serviceOptions->{'syntax'} ) {
3696
            $Zpackage->option( syntax => $serviceOptions->{'syntax'} );
3697
        }
3698
    }
3699
3700
    # send the request, handle any exception encountered
3701
    eval { $Zpackage->send($serviceType) };
3702
    if ( $@ && $@->isa("ZOOM::Exception") ) {
3703
        return "error:  " . $@->code() . " " . $@->message() . "\n";
3704
    }
3705
3706
    # free up package resources
3707
    $Zpackage->destroy();
3708
}
3709
3710
=head2 set_service_options
3711
3712
  my $serviceOptions = set_service_options($serviceType);
3713
3714
C<$serviceType> itemorder,create,drop,commit,update,xmlupdate
3715
3716
Currently, we only support 'create', 'commit', and 'update'. 'drop' support will be added as soon as Zebra supports it.
3717
3718
=cut
3719
3720
sub set_service_options {
3721
    my ($serviceType) = @_;
3722
    my $serviceOptions;
3723
3724
    # FIXME: This needs to be an OID ... if we ever need 'syntax' this sub will need to change
3725
    #   $serviceOptions->{ 'syntax' } = ''; #zebra doesn't support syntaxes other than xml
3726
3727
    if ( $serviceType eq 'commit' ) {
3728
3729
        # nothing to do
3730
    }
3731
    if ( $serviceType eq 'create' ) {
3732
3733
        # nothing to do
3734
    }
3735
    if ( $serviceType eq 'drop' ) {
3736
        die "ERROR: 'drop' not currently supported (by Zebra)";
3737
    }
3738
    return $serviceOptions;
3739
}
3740
3741
=head2 get_biblio_authorised_values
3407
=head2 get_biblio_authorised_values
3742
3408
3743
find the types and values for all authorised values assigned to this biblio.
3409
find the types and values for all authorised values assigned to this biblio.
(-)a/C4/Items.pm (+231 lines)
Lines 82-87 BEGIN { Link Here
82
82
83
	GetAnalyticsCount
83
	GetAnalyticsCount
84
        GetItemHolds
84
        GetItemHolds
85
86
87
        PrepareItemrecordDisplay
88
85
    );
89
    );
86
}
90
}
87
91
Lines 2497-2500 sub GetItemHolds { Link Here
2497
    $holds = $sth->fetchrow;
2501
    $holds = $sth->fetchrow;
2498
    return $holds;
2502
    return $holds;
2499
}
2503
}
2504
=head1  OTHER FUNCTIONS
2505
2506
2507
=head2 PrepareItemrecordDisplay
2508
2509
  PrepareItemrecordDisplay($itemrecord,$bibnum,$itemumber,$frameworkcode);
2510
2511
Returns a hash with all the fields for Display a given item data in a template
2512
2513
The $frameworkcode returns the item for the given frameworkcode, ONLY if bibnum is not provided
2514
2515
=cut
2516
2517
sub PrepareItemrecordDisplay {
2518
2519
    my ( $bibnum, $itemnum, $defaultvalues, $frameworkcode ) = @_;
2520
2521
    my $dbh = C4::Context->dbh;
2522
    $frameworkcode = &GetFrameworkCode($bibnum) if $bibnum;
2523
    my ( $itemtagfield, $itemtagsubfield ) = &GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2524
    my $tagslib = &GetMarcStructure( 1, $frameworkcode );
2525
2526
    # return nothing if we don't have found an existing framework.
2527
    return q{} unless $tagslib;
2528
    my $itemrecord;
2529
    if ($itemnum) {
2530
        $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum );
2531
    }
2532
    my @loop_data;
2533
    my $authorised_values_sth = $dbh->prepare( "SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib" );
2534
    foreach my $tag ( sort keys %{$tagslib} ) {
2535
        my $previous_tag = '';
2536
        if ( $tag ne '' ) {
2537
2538
            # loop through each subfield
2539
            my $cntsubf;
2540
            foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
2541
                next if ( subfield_is_koha_internal_p($subfield) );
2542
                next if ( $tagslib->{$tag}->{$subfield}->{'tab'} ne "10" );
2543
                my %subfield_data;
2544
                $subfield_data{tag}           = $tag;
2545
                $subfield_data{subfield}      = $subfield;
2546
                $subfield_data{countsubfield} = $cntsubf++;
2547
                $subfield_data{kohafield}     = $tagslib->{$tag}->{$subfield}->{'kohafield'};
2548
2549
                #        $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
2550
                $subfield_data{marc_lib}   = $tagslib->{$tag}->{$subfield}->{lib};
2551
                $subfield_data{mandatory}  = $tagslib->{$tag}->{$subfield}->{mandatory};
2552
                $subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable};
2553
                $subfield_data{hidden}     = "display:none"
2554
                  if $tagslib->{$tag}->{$subfield}->{hidden};
2555
                my ( $x, $defaultvalue );
2556
                if ($itemrecord) {
2557
                    ( $x, $defaultvalue ) = _find_value( $tag, $subfield, $itemrecord );
2558
                }
2559
                $defaultvalue = $tagslib->{$tag}->{$subfield}->{defaultvalue} unless $defaultvalue;
2560
                if ( !defined $defaultvalue ) {
2561
                    $defaultvalue = q||;
2562
                }
2563
                $defaultvalue =~ s/"/&quot;/g;
2564
2565
                # search for itemcallnumber if applicable
2566
                if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber'
2567
                    && C4::Context->preference('itemcallnumber') ) {
2568
                    my $CNtag      = substr( C4::Context->preference('itemcallnumber'), 0, 3 );
2569
                    my $CNsubfield = substr( C4::Context->preference('itemcallnumber'), 3, 1 );
2570
                    if ($itemrecord) {
2571
                        my $temp = $itemrecord->field($CNtag);
2572
                        if ($temp) {
2573
                            $defaultvalue = $temp->subfield($CNsubfield);
2574
                        }
2575
                    }
2576
                }
2577
                if (   $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber'
2578
                    && $defaultvalues
2579
                    && $defaultvalues->{'callnumber'} ) {
2580
                    my $temp;
2581
                    if ($itemrecord) {
2582
                        $temp = $itemrecord->field($subfield);
2583
                    }
2584
                    unless ($temp) {
2585
                        $defaultvalue = $defaultvalues->{'callnumber'} if $defaultvalues;
2586
                    }
2587
                }
2588
                if (   ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.holdingbranch' || $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.homebranch' )
2589
                    && $defaultvalues
2590
                    && $defaultvalues->{'branchcode'} ) {
2591
                    my $temp;
2592
                    if ($itemrecord) {
2593
                        $temp = $itemrecord->field($subfield);
2594
                    }
2595
                    unless ($temp) {
2596
                        $defaultvalue = $defaultvalues->{branchcode} if $defaultvalues;
2597
                    }
2598
                }
2599
                if (   ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.location' )
2600
                    && $defaultvalues
2601
                    && $defaultvalues->{'location'} ) {
2602
                    my $temp = $itemrecord->field($subfield) if ($itemrecord);
2603
                    unless ($temp) {
2604
                        $defaultvalue = $defaultvalues->{location} if $defaultvalues;
2605
                    }
2606
                }
2607
                if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
2608
                    my @authorised_values;
2609
                    my %authorised_lib;
2610
2611
                    # builds list, depending on authorised value...
2612
                    #---- branch
2613
                    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
2614
                        if (   ( C4::Context->preference("IndependantBranches") )
2615
                            && ( C4::Context->userenv->{flags} % 2 != 1 ) ) {
2616
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches WHERE branchcode = ? ORDER BY branchname" );
2617
                            $sth->execute( C4::Context->userenv->{branch} );
2618
                            push @authorised_values, ""
2619
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2620
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
2621
                                push @authorised_values, $branchcode;
2622
                                $authorised_lib{$branchcode} = $branchname;
2623
                            }
2624
                        } else {
2625
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches ORDER BY branchname" );
2626
                            $sth->execute;
2627
                            push @authorised_values, ""
2628
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2629
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
2630
                                push @authorised_values, $branchcode;
2631
                                $authorised_lib{$branchcode} = $branchname;
2632
                            }
2633
                        }
2634
2635
                        #----- itemtypes
2636
                    } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
2637
                        my $sth = $dbh->prepare( "SELECT itemtype,description FROM itemtypes ORDER BY description" );
2638
                        $sth->execute;
2639
                        push @authorised_values, ""
2640
                          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2641
                        while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
2642
                            push @authorised_values, $itemtype;
2643
                            $authorised_lib{$itemtype} = $description;
2644
                        }
2645
                        #---- class_sources
2646
                    } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
2647
                        push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2648
2649
                        my $class_sources = GetClassSources();
2650
                        my $default_source = C4::Context->preference("DefaultClassificationSource");
2651
2652
                        foreach my $class_source (sort keys %$class_sources) {
2653
                            next unless $class_sources->{$class_source}->{'used'} or
2654
                                        ($class_source eq $default_source);
2655
                            push @authorised_values, $class_source;
2656
                            $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
2657
                        }
2658
2659
                        #---- "true" authorised value
2660
                    } else {
2661
                        $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value} );
2662
                        push @authorised_values, ""
2663
                          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2664
                        while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
2665
                            push @authorised_values, $value;
2666
                            $authorised_lib{$value} = $lib;
2667
                        }
2668
                    }
2669
                    $subfield_data{marc_value} = CGI::scrolling_list(
2670
                        -name     => 'field_value',
2671
                        -values   => \@authorised_values,
2672
                        -default  => "$defaultvalue",
2673
                        -labels   => \%authorised_lib,
2674
                        -size     => 1,
2675
                        -tabindex => '',
2676
                        -multiple => 0,
2677
                    );
2678
                } elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) {
2679
                        # opening plugin
2680
                        my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
2681
                        if (do $plugin) {
2682
                            my $temp;
2683
                            my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, undef );
2684
                            my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, undef );
2685
                            $subfield_data{random}     = int(rand(1000000));    # why do we need 2 different randoms?
2686
                            my $index_subfield = int(rand(1000000));
2687
                            $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
2688
                            $subfield_data{marc_value} = qq[<input tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255"
2689
                                onfocus="Focus$function_name($subfield_data{random}, '$subfield_data{id}');"
2690
                                 onblur=" Blur$function_name($subfield_data{random}, '$subfield_data{id}');" />
2691
                                <a href="#" class="buttonDot" onclick="Clic$function_name('$subfield_data{id}'); return false;" title="Tag Editor">...</a>
2692
                                $javascript];
2693
                        } else {
2694
                            warn "Plugin Failed: $plugin";
2695
                            $subfield_data{marc_value} = qq(<input tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" />); # supply default input form
2696
                        }
2697
                }
2698
                elsif ( $tag eq '' ) {       # it's an hidden field
2699
                    $subfield_data{marc_value} = qq(<input type="hidden" tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" value="$defaultvalue" />);
2700
                }
2701
                elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {   # FIXME: shouldn't input type be "hidden" ?
2702
                    $subfield_data{marc_value} = qq(<input type="text" tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" value="$defaultvalue" />);
2703
                }
2704
                elsif ( length($defaultvalue) > 100
2705
                            or (C4::Context->preference("marcflavour") eq "UNIMARC" and
2706
                                  300 <= $tag && $tag < 400 && $subfield eq 'a' )
2707
                            or (C4::Context->preference("marcflavour") eq "MARC21"  and
2708
                                  500 <= $tag && $tag < 600                     )
2709
                          ) {
2710
                    # oversize field (textarea)
2711
                    $subfield_data{marc_value} = qq(<textarea tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255">$defaultvalue</textarea>\n");
2712
                } else {
2713
                    $subfield_data{marc_value} = "<input type=\"text\" name=\"field_value\" value=\"$defaultvalue\" size=\"50\" maxlength=\"255\" />";
2714
                }
2715
                push( @loop_data, \%subfield_data );
2716
            }
2717
        }
2718
    }
2719
    my $itemnumber;
2720
    if ( $itemrecord && $itemrecord->field($itemtagfield) ) {
2721
        $itemnumber = $itemrecord->subfield( $itemtagfield, $itemtagsubfield );
2722
    }
2723
    return {
2724
        'itemtagfield'    => $itemtagfield,
2725
        'itemtagsubfield' => $itemtagsubfield,
2726
        'itemnumber'      => $itemnumber,
2727
        'iteminformation' => \@loop_data
2728
    };
2729
}
2730
2500
1;
2731
1;
(-)a/C4/Serials.pm (-2 / +3 lines)
Lines 225-237 sub GetSerialInformation { Link Here
225
        my $queryitem = $dbh->prepare("SELECT itemnumber from serialitems where serialid=?");
225
        my $queryitem = $dbh->prepare("SELECT itemnumber from serialitems where serialid=?");
226
        $queryitem->execute($serialid);
226
        $queryitem->execute($serialid);
227
        my $itemnumbers = $queryitem->fetchall_arrayref( [0] );
227
        my $itemnumbers = $queryitem->fetchall_arrayref( [0] );
228
        require C4::Items;
228
        if ( scalar(@$itemnumbers) > 0 ) {
229
        if ( scalar(@$itemnumbers) > 0 ) {
229
            foreach my $itemnum (@$itemnumbers) {
230
            foreach my $itemnum (@$itemnumbers) {
230
231
231
                #It is ASSUMED that GetMarcItem ALWAYS WORK...
232
                #It is ASSUMED that GetMarcItem ALWAYS WORK...
232
                #Maybe GetMarcItem should return values on failure
233
                #Maybe GetMarcItem should return values on failure
233
                $debug and warn "itemnumber :$itemnum->[0], bibnum :" . $data->{'biblionumber'};
234
                $debug and warn "itemnumber :$itemnum->[0], bibnum :" . $data->{'biblionumber'};
234
                my $itemprocessed = PrepareItemrecordDisplay( $data->{'biblionumber'}, $itemnum->[0], $data );
235
                my $itemprocessed = C4::Items::PrepareItemrecordDisplay( $data->{'biblionumber'}, $itemnum->[0], $data );
235
                $itemprocessed->{'itemnumber'}   = $itemnum->[0];
236
                $itemprocessed->{'itemnumber'}   = $itemnum->[0];
236
                $itemprocessed->{'itemid'}       = $itemnum->[0];
237
                $itemprocessed->{'itemid'}       = $itemnum->[0];
237
                $itemprocessed->{'serialid'}     = $serialid;
238
                $itemprocessed->{'serialid'}     = $serialid;
Lines 239-245 sub GetSerialInformation { Link Here
239
                push @{ $data->{'items'} }, $itemprocessed;
240
                push @{ $data->{'items'} }, $itemprocessed;
240
            }
241
            }
241
        } else {
242
        } else {
242
            my $itemprocessed = PrepareItemrecordDisplay( $data->{'biblionumber'}, '', $data );
243
            my $itemprocessed = C4::Items::PrepareItemrecordDisplay( $data->{'biblionumber'}, '', $data );
243
            $itemprocessed->{'itemid'}       = "N$serialid";
244
            $itemprocessed->{'itemid'}       = "N$serialid";
244
            $itemprocessed->{'serialid'}     = $serialid;
245
            $itemprocessed->{'serialid'}     = $serialid;
245
            $itemprocessed->{'biblionumber'} = $data->{'biblionumber'};
246
            $itemprocessed->{'biblionumber'} = $data->{'biblionumber'};
(-)a/acqui/neworderempty.pl (+1 lines)
Lines 81-86 use C4::Bookseller qw/ GetBookSellerFromId /; Link Here
81
use C4::Acquisition;
81
use C4::Acquisition;
82
use C4::Suggestions;	# GetSuggestion
82
use C4::Suggestions;	# GetSuggestion
83
use C4::Biblio;			# GetBiblioData
83
use C4::Biblio;			# GetBiblioData
84
use C4::Items; #PrepareItemRecord
84
use C4::Output;
85
use C4::Output;
85
use C4::Input;
86
use C4::Input;
86
use C4::Koha;
87
use C4::Koha;
(-)a/t/db_dependent/lib/KohaTest/Biblio.pm (-3 lines)
Lines 45-51 sub methods : Test( 1 ) { Link Here
45
                       _disambiguate
45
                       _disambiguate
46
                       get_koha_field_from_marc
46
                       get_koha_field_from_marc
47
                       TransformMarcToKohaOneField
47
                       TransformMarcToKohaOneField
48
                       PrepareItemrecordDisplay
49
                       ModZebra
48
                       ModZebra
50
                       GetNoZebraIndexes
49
                       GetNoZebraIndexes
51
                       _DelBiblioNoZebra
50
                       _DelBiblioNoZebra
Lines 60-67 sub methods : Test( 1 ) { Link Here
60
                       _koha_delete_biblio
59
                       _koha_delete_biblio
61
                       _koha_delete_biblioitems
60
                       _koha_delete_biblioitems
62
                       ModBiblioMarc
61
                       ModBiblioMarc
63
                       z3950_extended_services
64
                       set_service_options
65
                       get_biblio_authorised_values
62
                       get_biblio_authorised_values
66
                );
63
                );
67
    
64
    
(-)a/t/db_dependent/lib/KohaTest/Items.pm (-1 / +1 lines)
Lines 52-57 sub methods : Test( 1 ) { Link Here
52
      _get_unlinked_item_subfields
52
      _get_unlinked_item_subfields
53
      _get_unlinked_subfields_xml
53
      _get_unlinked_subfields_xml
54
      _parse_unlinked_item_subfields_from_xml
54
      _parse_unlinked_item_subfields_from_xml
55
      PrepareItemrecordDisplay
55
    );
56
    );
56
57
57
    can_ok( $self->testing_class, @methods );
58
    can_ok( $self->testing_class, @methods );
58
- 

Return to bug 6875