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

(-)a/C4/Biblio.pm (-340 / +6 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 126-132 BEGIN { Link Here
126
      &TransformHtmlToMarc2
122
      &TransformHtmlToMarc2
127
      &TransformHtmlToMarc
123
      &TransformHtmlToMarc
128
      &TransformHtmlToXml
124
      &TransformHtmlToXml
129
      &PrepareItemrecordDisplay
130
      &GetNoZebraIndexes
125
      &GetNoZebraIndexes
131
    );
126
    );
132
}
127
}
Lines 412-420 sub DelBiblio { Link Here
412
    return $error if $error;
407
    return $error if $error;
413
408
414
    # We delete attached subscriptions
409
    # We delete attached subscriptions
415
    my $subscriptions = &C4::Serials::GetFullSubscriptionsFromBiblionumber($biblionumber);
410
    require C4::Serials;
411
    my $subscriptions = C4::Serials::GetFullSubscriptionsFromBiblionumber($biblionumber);
416
    foreach my $subscription (@$subscriptions) {
412
    foreach my $subscription (@$subscriptions) {
417
        &C4::Serials::DelSubscription( $subscription->{subscriptionid} );
413
        C4::Serials::DelSubscription( $subscription->{subscriptionid} );
418
    }
414
    }
419
415
420
    # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
416
    # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
Lines 472-477 MARC record. Link Here
472
=cut
468
=cut
473
469
474
sub LinkBibHeadingsToAuthorities {
470
sub LinkBibHeadingsToAuthorities {
471
    require C4::Heading;
475
    my $bib = shift;
472
    my $bib = shift;
476
473
477
    my $num_headings_changed = 0;
474
    my $num_headings_changed = 0;
Lines 2338-2570 sub TransformMarcToKohaOneField { Link Here
2338
    return $result;
2335
    return $result;
2339
}
2336
}
2340
2337
2341
=head1  OTHER FUNCTIONS
2338
    
2342
2343
2344
=head2 PrepareItemrecordDisplay
2345
2346
  PrepareItemrecordDisplay($itemrecord,$bibnum,$itemumber,$frameworkcode);
2347
2348
Returns a hash with all the fields for Display a given item data in a template
2349
2350
The $frameworkcode returns the item for the given frameworkcode, ONLY if bibnum is not provided
2351
2352
=cut
2353
2354
sub PrepareItemrecordDisplay {
2355
2356
    my ( $bibnum, $itemnum, $defaultvalues, $frameworkcode ) = @_;
2357
2358
    my $dbh = C4::Context->dbh;
2359
    $frameworkcode = &GetFrameworkCode($bibnum) if $bibnum;
2360
    my ( $itemtagfield, $itemtagsubfield ) = &GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2361
    my $tagslib = &GetMarcStructure( 1, $frameworkcode );
2362
2363
    # return nothing if we don't have found an existing framework.
2364
    return q{} unless $tagslib;
2365
    my $itemrecord;
2366
    if ($itemnum) {
2367
        $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum );
2368
    }
2369
    my @loop_data;
2370
    my $authorised_values_sth = $dbh->prepare( "SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib" );
2371
    foreach my $tag ( sort keys %{$tagslib} ) {
2372
        my $previous_tag = '';
2373
        if ( $tag ne '' ) {
2374
2375
            # loop through each subfield
2376
            my $cntsubf;
2377
            foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
2378
                next if ( subfield_is_koha_internal_p($subfield) );
2379
                next if ( $tagslib->{$tag}->{$subfield}->{'tab'} ne "10" );
2380
                my %subfield_data;
2381
                $subfield_data{tag}           = $tag;
2382
                $subfield_data{subfield}      = $subfield;
2383
                $subfield_data{countsubfield} = $cntsubf++;
2384
                $subfield_data{kohafield}     = $tagslib->{$tag}->{$subfield}->{'kohafield'};
2385
2386
                #        $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
2387
                $subfield_data{marc_lib}   = $tagslib->{$tag}->{$subfield}->{lib};
2388
                $subfield_data{mandatory}  = $tagslib->{$tag}->{$subfield}->{mandatory};
2389
                $subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable};
2390
                $subfield_data{hidden}     = "display:none"
2391
                  if $tagslib->{$tag}->{$subfield}->{hidden};
2392
                my ( $x, $defaultvalue );
2393
                if ($itemrecord) {
2394
                    ( $x, $defaultvalue ) = _find_value( $tag, $subfield, $itemrecord );
2395
                }
2396
                $defaultvalue = $tagslib->{$tag}->{$subfield}->{defaultvalue} unless $defaultvalue;
2397
                if ( !defined $defaultvalue ) {
2398
                    $defaultvalue = q||;
2399
                }
2400
                $defaultvalue =~ s/"/"/g;
2401
2402
                # search for itemcallnumber if applicable
2403
                if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber'
2404
                    && C4::Context->preference('itemcallnumber') ) {
2405
                    my $CNtag      = substr( C4::Context->preference('itemcallnumber'), 0, 3 );
2406
                    my $CNsubfield = substr( C4::Context->preference('itemcallnumber'), 3, 1 );
2407
                    if ($itemrecord) {
2408
                        my $temp = $itemrecord->field($CNtag);
2409
                        if ($temp) {
2410
                            $defaultvalue = $temp->subfield($CNsubfield);
2411
                        }
2412
                    }
2413
                }
2414
                if (   $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber'
2415
                    && $defaultvalues
2416
                    && $defaultvalues->{'callnumber'} ) {
2417
                    my $temp;
2418
                    if ($itemrecord) {
2419
                        $temp = $itemrecord->field($subfield);
2420
                    }
2421
                    unless ($temp) {
2422
                        $defaultvalue = $defaultvalues->{'callnumber'} if $defaultvalues;
2423
                    }
2424
                }
2425
                if (   ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.holdingbranch' || $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.homebranch' )
2426
                    && $defaultvalues
2427
                    && $defaultvalues->{'branchcode'} ) {
2428
                    my $temp;
2429
                    if ($itemrecord) {
2430
                        $temp = $itemrecord->field($subfield);
2431
                    }
2432
                    unless ($temp) {
2433
                        $defaultvalue = $defaultvalues->{branchcode} if $defaultvalues;
2434
                    }
2435
                }
2436
                if (   ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.location' )
2437
                    && $defaultvalues
2438
                    && $defaultvalues->{'location'} ) {
2439
                    my $temp = $itemrecord->field($subfield) if ($itemrecord);
2440
                    unless ($temp) {
2441
                        $defaultvalue = $defaultvalues->{location} if $defaultvalues;
2442
                    }
2443
                }
2444
                if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
2445
                    my @authorised_values;
2446
                    my %authorised_lib;
2447
2448
                    # builds list, depending on authorised value...
2449
                    #---- branch
2450
                    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
2451
                        if (   ( C4::Context->preference("IndependantBranches") )
2452
                            && ( C4::Context->userenv->{flags} % 2 != 1 ) ) {
2453
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches WHERE branchcode = ? ORDER BY branchname" );
2454
                            $sth->execute( C4::Context->userenv->{branch} );
2455
                            push @authorised_values, ""
2456
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2457
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
2458
                                push @authorised_values, $branchcode;
2459
                                $authorised_lib{$branchcode} = $branchname;
2460
                            }
2461
                        } else {
2462
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches ORDER BY branchname" );
2463
                            $sth->execute;
2464
                            push @authorised_values, ""
2465
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2466
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
2467
                                push @authorised_values, $branchcode;
2468
                                $authorised_lib{$branchcode} = $branchname;
2469
                            }
2470
                        }
2471
2472
                        #----- itemtypes
2473
                    } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
2474
                        my $sth = $dbh->prepare( "SELECT itemtype,description FROM itemtypes ORDER BY description" );
2475
                        $sth->execute;
2476
                        push @authorised_values, ""
2477
                          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2478
                        while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
2479
                            push @authorised_values, $itemtype;
2480
                            $authorised_lib{$itemtype} = $description;
2481
                        }
2482
                        #---- class_sources
2483
                    } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
2484
                        push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2485
2486
                        my $class_sources = GetClassSources();
2487
                        my $default_source = C4::Context->preference("DefaultClassificationSource");
2488
2489
                        foreach my $class_source (sort keys %$class_sources) {
2490
                            next unless $class_sources->{$class_source}->{'used'} or
2491
                                        ($class_source eq $default_source);
2492
                            push @authorised_values, $class_source;
2493
                            $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
2494
                        }
2495
2496
                        #---- "true" authorised value
2497
                    } else {
2498
                        $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value} );
2499
                        push @authorised_values, ""
2500
                          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2501
                        while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
2502
                            push @authorised_values, $value;
2503
                            $authorised_lib{$value} = $lib;
2504
                        }
2505
                    }
2506
                    $subfield_data{marc_value} = CGI::scrolling_list(
2507
                        -name     => 'field_value',
2508
                        -values   => \@authorised_values,
2509
                        -default  => "$defaultvalue",
2510
                        -labels   => \%authorised_lib,
2511
                        -size     => 1,
2512
                        -tabindex => '',
2513
                        -multiple => 0,
2514
                    );
2515
                } elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) {
2516
                        # opening plugin
2517
                        my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
2518
                        if (do $plugin) {
2519
                            my $temp;
2520
                            my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, undef );
2521
                            my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, undef );
2522
                            $subfield_data{random}     = int(rand(1000000));    # why do we need 2 different randoms?
2523
                            my $index_subfield = int(rand(1000000));
2524
                            $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
2525
                            $subfield_data{marc_value} = qq[<input tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255"
2526
                                onfocus="Focus$function_name($subfield_data{random}, '$subfield_data{id}');"
2527
                                 onblur=" Blur$function_name($subfield_data{random}, '$subfield_data{id}');" />
2528
                                <a href="#" class="buttonDot" onclick="Clic$function_name('$subfield_data{id}'); return false;" title="Tag Editor">...</a>
2529
                                $javascript];
2530
                        } else {
2531
                            warn "Plugin Failed: $plugin";
2532
                            $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
2533
                        }
2534
                }
2535
                elsif ( $tag eq '' ) {       # it's an hidden field
2536
                    $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" />);
2537
                }
2538
                elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {   # FIXME: shouldn't input type be "hidden" ?
2539
                    $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" />);
2540
                }
2541
                elsif ( length($defaultvalue) > 100
2542
                            or (C4::Context->preference("marcflavour") eq "UNIMARC" and
2543
                                  300 <= $tag && $tag < 400 && $subfield eq 'a' )
2544
                            or (C4::Context->preference("marcflavour") eq "MARC21"  and
2545
                                  500 <= $tag && $tag < 600                     )
2546
                          ) {
2547
                    # oversize field (textarea)
2548
                    $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");
2549
                } else {
2550
                    $subfield_data{marc_value} = "<input type=\"text\" name=\"field_value\" value=\"$defaultvalue\" size=\"50\" maxlength=\"255\" />";
2551
                }
2552
                push( @loop_data, \%subfield_data );
2553
            }
2554
        }
2555
    }
2556
    my $itemnumber;
2557
    if ( $itemrecord && $itemrecord->field($itemtagfield) ) {
2558
        $itemnumber = $itemrecord->subfield( $itemtagfield, $itemtagsubfield );
2559
    }
2560
    return {
2561
        'itemtagfield'    => $itemtagfield,
2562
        'itemtagsubfield' => $itemtagsubfield,
2563
        'itemnumber'      => $itemnumber,
2564
        'iteminformation' => \@loop_data
2565
    };
2566
}
2567
2568
#"
2339
#"
2569
2340
2570
#
2341
#
Lines 2727-2732 sub EmbedItemsInMarcBiblio { Link Here
2727
    my @item_fields;
2498
    my @item_fields;
2728
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2499
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2729
    while (my ($itemnumber) = $sth->fetchrow_array) {
2500
    while (my ($itemnumber) = $sth->fetchrow_array) {
2501
        require C4::Items;
2730
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2502
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2731
        push @item_fields, $item_marc->field($itemtag);
2503
        push @item_fields, $item_marc->field($itemtag);
2732
    }
2504
    }
Lines 3513-3624 sub ModBiblioMarc { Link Here
3513
    return $biblionumber;
3285
    return $biblionumber;
3514
}
3286
}
3515
3287
3516
=head2 z3950_extended_services
3517
3518
  z3950_extended_services($serviceType,$serviceOptions,$record);
3519
3520
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.
3521
3522
C<$serviceType> one of: itemorder,create,drop,commit,update,xmlupdate
3523
3524
C<$serviceOptions> a has of key/value pairs. For instance, if service_type is 'update', $service_options should contain:
3525
3526
 action => update action, one of specialUpdate, recordInsert, recordReplace, recordDelete, elementUpdate.
3527
3528
and maybe
3529
3530
  recordidOpaque => Opaque Record ID (user supplied) or recordidNumber => Record ID number (system number).
3531
  syntax => the record syntax (transfer syntax)
3532
  databaseName = Database from connection object
3533
3534
To set serviceOptions, call set_service_options($serviceType)
3535
3536
C<$record> the record, if one is needed for the service type
3537
3538
A record should be in XML. You can convert it to XML from MARC by running it through marc2xml().
3539
3540
=cut
3541
3542
sub z3950_extended_services {
3543
    my ( $server, $serviceType, $action, $serviceOptions ) = @_;
3544
3545
    # get our connection object
3546
    my $Zconn = C4::Context->Zconn( $server, 0, 1 );
3547
3548
    # create a new package object
3549
    my $Zpackage = $Zconn->package();
3550
3551
    # set our options
3552
    $Zpackage->option( action => $action );
3553
3554
    if ( $serviceOptions->{'databaseName'} ) {
3555
        $Zpackage->option( databaseName => $serviceOptions->{'databaseName'} );
3556
    }
3557
    if ( $serviceOptions->{'recordIdNumber'} ) {
3558
        $Zpackage->option( recordIdNumber => $serviceOptions->{'recordIdNumber'} );
3559
    }
3560
    if ( $serviceOptions->{'recordIdOpaque'} ) {
3561
        $Zpackage->option( recordIdOpaque => $serviceOptions->{'recordIdOpaque'} );
3562
    }
3563
3564
    # this is an ILL request (Zebra doesn't support it, but Koha could eventually)
3565
    #if ($serviceType eq 'itemorder') {
3566
    #   $Zpackage->option('contact-name' => $serviceOptions->{'contact-name'});
3567
    #   $Zpackage->option('contact-phone' => $serviceOptions->{'contact-phone'});
3568
    #   $Zpackage->option('contact-email' => $serviceOptions->{'contact-email'});
3569
    #   $Zpackage->option('itemorder-item' => $serviceOptions->{'itemorder-item'});
3570
    #}
3571
3572
    if ( $serviceOptions->{record} ) {
3573
        $Zpackage->option( record => $serviceOptions->{record} );
3574
3575
        # can be xml or marc
3576
        if ( $serviceOptions->{'syntax'} ) {
3577
            $Zpackage->option( syntax => $serviceOptions->{'syntax'} );
3578
        }
3579
    }
3580
3581
    # send the request, handle any exception encountered
3582
    eval { $Zpackage->send($serviceType) };
3583
    if ( $@ && $@->isa("ZOOM::Exception") ) {
3584
        return "error:  " . $@->code() . " " . $@->message() . "\n";
3585
    }
3586
3587
    # free up package resources
3588
    $Zpackage->destroy();
3589
}
3590
3591
=head2 set_service_options
3592
3593
  my $serviceOptions = set_service_options($serviceType);
3594
3595
C<$serviceType> itemorder,create,drop,commit,update,xmlupdate
3596
3597
Currently, we only support 'create', 'commit', and 'update'. 'drop' support will be added as soon as Zebra supports it.
3598
3599
=cut
3600
3601
sub set_service_options {
3602
    my ($serviceType) = @_;
3603
    my $serviceOptions;
3604
3605
    # FIXME: This needs to be an OID ... if we ever need 'syntax' this sub will need to change
3606
    #   $serviceOptions->{ 'syntax' } = ''; #zebra doesn't support syntaxes other than xml
3607
3608
    if ( $serviceType eq 'commit' ) {
3609
3610
        # nothing to do
3611
    }
3612
    if ( $serviceType eq 'create' ) {
3613
3614
        # nothing to do
3615
    }
3616
    if ( $serviceType eq 'drop' ) {
3617
        die "ERROR: 'drop' not currently supported (by Zebra)";
3618
    }
3619
    return $serviceOptions;
3620
}
3621
3622
=head2 get_biblio_authorised_values
3288
=head2 get_biblio_authorised_values
3623
3289
3624
find the types and values for all authorised values assigned to this biblio.
3290
find the types and values for all authorised values assigned to this biblio.
(-)a/C4/Items.pm (+229 lines)
Lines 78-83 BEGIN { Link Here
78
		MoveItemFromBiblio 
78
		MoveItemFromBiblio 
79
		GetLatestAcquisitions
79
		GetLatestAcquisitions
80
        CartToShelf
80
        CartToShelf
81
        
82
        PrepareItemrecordDisplay
81
    );
83
    );
82
}
84
}
83
85
Lines 2336-2339 sub _parse_unlinked_item_subfields_from_xml { Link Here
2336
    return $unlinked_subfields;
2338
    return $unlinked_subfields;
2337
}
2339
}
2338
2340
2341
=head1  OTHER FUNCTIONS
2342
2343
2344
=head2 PrepareItemrecordDisplay
2345
2346
  PrepareItemrecordDisplay($itemrecord,$bibnum,$itemumber,$frameworkcode);
2347
2348
Returns a hash with all the fields for Display a given item data in a template
2349
2350
The $frameworkcode returns the item for the given frameworkcode, ONLY if bibnum is not provided
2351
2352
=cut
2353
2354
sub PrepareItemrecordDisplay {
2355
2356
    my ( $bibnum, $itemnum, $defaultvalues, $frameworkcode ) = @_;
2357
2358
    my $dbh = C4::Context->dbh;
2359
    $frameworkcode = &GetFrameworkCode($bibnum) if $bibnum;
2360
    my ( $itemtagfield, $itemtagsubfield ) = &GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2361
    my $tagslib = &GetMarcStructure( 1, $frameworkcode );
2362
2363
    # return nothing if we don't have found an existing framework.
2364
    return q{} unless $tagslib;
2365
    my $itemrecord;
2366
    if ($itemnum) {
2367
        $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum );
2368
    }
2369
    my @loop_data;
2370
    my $authorised_values_sth = $dbh->prepare( "SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib" );
2371
    foreach my $tag ( sort keys %{$tagslib} ) {
2372
        my $previous_tag = '';
2373
        if ( $tag ne '' ) {
2374
2375
            # loop through each subfield
2376
            my $cntsubf;
2377
            foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
2378
                next if ( subfield_is_koha_internal_p($subfield) );
2379
                next if ( $tagslib->{$tag}->{$subfield}->{'tab'} ne "10" );
2380
                my %subfield_data;
2381
                $subfield_data{tag}           = $tag;
2382
                $subfield_data{subfield}      = $subfield;
2383
                $subfield_data{countsubfield} = $cntsubf++;
2384
                $subfield_data{kohafield}     = $tagslib->{$tag}->{$subfield}->{'kohafield'};
2385
2386
                #        $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
2387
                $subfield_data{marc_lib}   = $tagslib->{$tag}->{$subfield}->{lib};
2388
                $subfield_data{mandatory}  = $tagslib->{$tag}->{$subfield}->{mandatory};
2389
                $subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable};
2390
                $subfield_data{hidden}     = "display:none"
2391
                  if $tagslib->{$tag}->{$subfield}->{hidden};
2392
                my ( $x, $defaultvalue );
2393
                if ($itemrecord) {
2394
                    ( $x, $defaultvalue ) = _find_value( $tag, $subfield, $itemrecord );
2395
                }
2396
                $defaultvalue = $tagslib->{$tag}->{$subfield}->{defaultvalue} unless $defaultvalue;
2397
                if ( !defined $defaultvalue ) {
2398
                    $defaultvalue = q||;
2399
                }
2400
                $defaultvalue =~ s/"/&quot;/g;
2401
2402
                # search for itemcallnumber if applicable
2403
                if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber'
2404
                    && C4::Context->preference('itemcallnumber') ) {
2405
                    my $CNtag      = substr( C4::Context->preference('itemcallnumber'), 0, 3 );
2406
                    my $CNsubfield = substr( C4::Context->preference('itemcallnumber'), 3, 1 );
2407
                    if ($itemrecord) {
2408
                        my $temp = $itemrecord->field($CNtag);
2409
                        if ($temp) {
2410
                            $defaultvalue = $temp->subfield($CNsubfield);
2411
                        }
2412
                    }
2413
                }
2414
                if (   $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber'
2415
                    && $defaultvalues
2416
                    && $defaultvalues->{'callnumber'} ) {
2417
                    my $temp;
2418
                    if ($itemrecord) {
2419
                        $temp = $itemrecord->field($subfield);
2420
                    }
2421
                    unless ($temp) {
2422
                        $defaultvalue = $defaultvalues->{'callnumber'} if $defaultvalues;
2423
                    }
2424
                }
2425
                if (   ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.holdingbranch' || $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.homebranch' )
2426
                    && $defaultvalues
2427
                    && $defaultvalues->{'branchcode'} ) {
2428
                    my $temp;
2429
                    if ($itemrecord) {
2430
                        $temp = $itemrecord->field($subfield);
2431
                    }
2432
                    unless ($temp) {
2433
                        $defaultvalue = $defaultvalues->{branchcode} if $defaultvalues;
2434
                    }
2435
                }
2436
                if (   ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.location' )
2437
                    && $defaultvalues
2438
                    && $defaultvalues->{'location'} ) {
2439
                    my $temp = $itemrecord->field($subfield) if ($itemrecord);
2440
                    unless ($temp) {
2441
                        $defaultvalue = $defaultvalues->{location} if $defaultvalues;
2442
                    }
2443
                }
2444
                if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
2445
                    my @authorised_values;
2446
                    my %authorised_lib;
2447
2448
                    # builds list, depending on authorised value...
2449
                    #---- branch
2450
                    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
2451
                        if (   ( C4::Context->preference("IndependantBranches") )
2452
                            && ( C4::Context->userenv->{flags} % 2 != 1 ) ) {
2453
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches WHERE branchcode = ? ORDER BY branchname" );
2454
                            $sth->execute( C4::Context->userenv->{branch} );
2455
                            push @authorised_values, ""
2456
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2457
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
2458
                                push @authorised_values, $branchcode;
2459
                                $authorised_lib{$branchcode} = $branchname;
2460
                            }
2461
                        } else {
2462
                            my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches ORDER BY branchname" );
2463
                            $sth->execute;
2464
                            push @authorised_values, ""
2465
                              unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2466
                            while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
2467
                                push @authorised_values, $branchcode;
2468
                                $authorised_lib{$branchcode} = $branchname;
2469
                            }
2470
                        }
2471
2472
                        #----- itemtypes
2473
                    } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
2474
                        my $sth = $dbh->prepare( "SELECT itemtype,description FROM itemtypes ORDER BY description" );
2475
                        $sth->execute;
2476
                        push @authorised_values, ""
2477
                          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2478
                        while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
2479
                            push @authorised_values, $itemtype;
2480
                            $authorised_lib{$itemtype} = $description;
2481
                        }
2482
                        #---- class_sources
2483
                    } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
2484
                        push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2485
2486
                        my $class_sources = GetClassSources();
2487
                        my $default_source = C4::Context->preference("DefaultClassificationSource");
2488
2489
                        foreach my $class_source (sort keys %$class_sources) {
2490
                            next unless $class_sources->{$class_source}->{'used'} or
2491
                                        ($class_source eq $default_source);
2492
                            push @authorised_values, $class_source;
2493
                            $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
2494
                        }
2495
2496
                        #---- "true" authorised value
2497
                    } else {
2498
                        $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value} );
2499
                        push @authorised_values, ""
2500
                          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2501
                        while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
2502
                            push @authorised_values, $value;
2503
                            $authorised_lib{$value} = $lib;
2504
                        }
2505
                    }
2506
                    $subfield_data{marc_value} = CGI::scrolling_list(
2507
                        -name     => 'field_value',
2508
                        -values   => \@authorised_values,
2509
                        -default  => "$defaultvalue",
2510
                        -labels   => \%authorised_lib,
2511
                        -size     => 1,
2512
                        -tabindex => '',
2513
                        -multiple => 0,
2514
                    );
2515
                } elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) {
2516
                        # opening plugin
2517
                        my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
2518
                        if (do $plugin) {
2519
                            my $temp;
2520
                            my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, undef );
2521
                            my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, undef );
2522
                            $subfield_data{random}     = int(rand(1000000));    # why do we need 2 different randoms?
2523
                            my $index_subfield = int(rand(1000000));
2524
                            $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
2525
                            $subfield_data{marc_value} = qq[<input tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255"
2526
                                onfocus="Focus$function_name($subfield_data{random}, '$subfield_data{id}');"
2527
                                 onblur=" Blur$function_name($subfield_data{random}, '$subfield_data{id}');" />
2528
                                <a href="#" class="buttonDot" onclick="Clic$function_name('$subfield_data{id}'); return false;" title="Tag Editor">...</a>
2529
                                $javascript];
2530
                        } else {
2531
                            warn "Plugin Failed: $plugin";
2532
                            $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
2533
                        }
2534
                }
2535
                elsif ( $tag eq '' ) {       # it's an hidden field
2536
                    $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" />);
2537
                }
2538
                elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {   # FIXME: shouldn't input type be "hidden" ?
2539
                    $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" />);
2540
                }
2541
                elsif ( length($defaultvalue) > 100
2542
                            or (C4::Context->preference("marcflavour") eq "UNIMARC" and
2543
                                  300 <= $tag && $tag < 400 && $subfield eq 'a' )
2544
                            or (C4::Context->preference("marcflavour") eq "MARC21"  and
2545
                                  500 <= $tag && $tag < 600                     )
2546
                          ) {
2547
                    # oversize field (textarea)
2548
                    $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");
2549
                } else {
2550
                    $subfield_data{marc_value} = "<input type=\"text\" name=\"field_value\" value=\"$defaultvalue\" size=\"50\" maxlength=\"255\" />";
2551
                }
2552
                push( @loop_data, \%subfield_data );
2553
            }
2554
        }
2555
    }
2556
    my $itemnumber;
2557
    if ( $itemrecord && $itemrecord->field($itemtagfield) ) {
2558
        $itemnumber = $itemrecord->subfield( $itemtagfield, $itemtagsubfield );
2559
    }
2560
    return {
2561
        'itemtagfield'    => $itemtagfield,
2562
        'itemtagsubfield' => $itemtagsubfield,
2563
        'itemnumber'      => $itemnumber,
2564
        'iteminformation' => \@loop_data
2565
    };
2566
}
2567
2339
1;
2568
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 46-52 sub methods : Test( 1 ) { Link Here
46
                       _disambiguate
46
                       _disambiguate
47
                       get_koha_field_from_marc
47
                       get_koha_field_from_marc
48
                       TransformMarcToKohaOneField
48
                       TransformMarcToKohaOneField
49
                       PrepareItemrecordDisplay
50
                       ModZebra
49
                       ModZebra
51
                       GetNoZebraIndexes
50
                       GetNoZebraIndexes
52
                       _DelBiblioNoZebra
51
                       _DelBiblioNoZebra
Lines 61-68 sub methods : Test( 1 ) { Link Here
61
                       _koha_delete_biblio
60
                       _koha_delete_biblio
62
                       _koha_delete_biblioitems
61
                       _koha_delete_biblioitems
63
                       ModBiblioMarc
62
                       ModBiblioMarc
64
                       z3950_extended_services
65
                       set_service_options
66
                       get_biblio_authorised_values
63
                       get_biblio_authorised_values
67
                );
64
                );
68
    
65
    
(-)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