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

(-)a/C4/Biblio.pm (-26 / +5 lines)
Lines 2203-2210 sub PrepHostMarcField { Link Here
2203
2203
2204
=head2 TransformHtmlToXml
2204
=head2 TransformHtmlToXml
2205
2205
2206
  $xml = TransformHtmlToXml( $tags, $subfields, $values, $indicator, 
2206
  $xml = TransformHtmlToXml( $tags, $subfields, $values, $indicator, $auth_type )
2207
                             $ind_tag, $auth_type )
2208
2207
2209
$auth_type contains :
2208
$auth_type contains :
2210
2209
Lines 2221-2227 $auth_type contains : Link Here
2221
=cut
2220
=cut
2222
2221
2223
sub TransformHtmlToXml {
2222
sub TransformHtmlToXml {
2224
    my ( $tags, $subfields, $values, $indicator, $ind_tag, $auth_type ) = @_;
2223
    my ( $tags, $subfields, $values, $auth_type ) = @_;
2225
    my $xml = MARC::File::XML::header('UTF-8');
2224
    my $xml = MARC::File::XML::header('UTF-8');
2226
    $xml .= "<record>\n";
2225
    $xml .= "<record>\n";
2227
    $auth_type = C4::Context->preference('marcflavour') unless $auth_type;
2226
    $auth_type = C4::Context->preference('marcflavour') unless $auth_type;
Lines 2260-2280 sub TransformHtmlToXml { Link Here
2260
        #         }
2259
        #         }
2261
        if ( ( @$tags[$i] ne $prevtag ) ) {
2260
        if ( ( @$tags[$i] ne $prevtag ) ) {
2262
            $j++ unless ( @$tags[$i] eq "" );
2261
            $j++ unless ( @$tags[$i] eq "" );
2263
            my $indicator1 = eval { substr( @$indicator[$j], 0, 1 ) };
2264
            my $indicator2 = eval { substr( @$indicator[$j], 1, 1 ) };
2265
            my $ind1       = _default_ind_to_space($indicator1);
2266
            my $ind2;
2267
            if ( @$indicator[$j] ) {
2268
                $ind2 = _default_ind_to_space($indicator2);
2269
            } else {
2270
                warn "Indicator in @$tags[$i] is empty";
2271
                $ind2 = " ";
2272
            }
2273
            if ( !$first ) {
2262
            if ( !$first ) {
2274
                $xml .= "</datafield>\n";
2263
                $xml .= "</datafield>\n";
2275
                if (   ( @$tags[$i] && @$tags[$i] > 10 )
2264
                if (   ( @$tags[$i] && @$tags[$i] > 10 )
2276
                    && ( @$values[$i] ne "" ) ) {
2265
                    && ( @$values[$i] ne "" ) ) {
2277
                    $xml .= "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
2266
                    $xml .= "<datafield tag=\"@$tags[$i]\" ind1=\"\" ind2=\"\">\n";
2278
                    $xml .= "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2267
                    $xml .= "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2279
                    $first = 0;
2268
                    $first = 0;
2280
                } else {
2269
                } else {
Lines 2293-2319 sub TransformHtmlToXml { Link Here
2293
                        $xml .= "<controlfield tag=\"@$tags[$i]\">@$values[$i]</controlfield>\n";
2282
                        $xml .= "<controlfield tag=\"@$tags[$i]\">@$values[$i]</controlfield>\n";
2294
                        $first = 1;
2283
                        $first = 1;
2295
                    } else {
2284
                    } else {
2296
                        $xml .= "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
2285
                        $xml .= "<datafield tag=\"@$tags[$i]\" ind1=\"\" ind2=\"\">\n";
2297
                        $xml .= "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2286
                        $xml .= "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2298
                        $first = 0;
2287
                        $first = 0;
2299
                    }
2288
                    }
2300
                }
2289
                }
2301
            }
2290
            }
2302
        } else {    # @$tags[$i] eq $prevtag
2291
        } else {    # @$tags[$i] eq $prevtag
2303
            my $indicator1 = eval { substr( @$indicator[$j], 0, 1 ) };
2304
            my $indicator2 = eval { substr( @$indicator[$j], 1, 1 ) };
2305
            my $ind1       = _default_ind_to_space($indicator1);
2306
            my $ind2;
2307
            if ( @$indicator[$j] ) {
2308
                $ind2 = _default_ind_to_space($indicator2);
2309
            } else {
2310
                warn "Indicator in @$tags[$i] is empty";
2311
                $ind2 = " ";
2312
            }
2313
            if ( @$values[$i] eq "" ) {
2292
            if ( @$values[$i] eq "" ) {
2314
            } else {
2293
            } else {
2315
                if ($first) {
2294
                if ($first) {
2316
                    $xml .= "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
2295
                    $xml .= "<datafield tag=\"@$tags[$i]\" ind1=\"\" ind2=\"\">\n";
2317
                    $first = 0;
2296
                    $first = 0;
2318
                }
2297
                }
2319
                $xml .= "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2298
                $xml .= "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
(-)a/acqui/addorder.pl (-6 / +1 lines)
Lines 286-293 if ( $orderinfo->{quantity} ne '0' ) { Link Here
286
        my @field_values = $input->param('field_value');
286
        my @field_values = $input->param('field_value');
287
        my @serials      = $input->param('serial');
287
        my @serials      = $input->param('serial');
288
        my @itemid       = $input->param('itemid');
288
        my @itemid       = $input->param('itemid');
289
        my @ind_tag      = $input->param('ind_tag');
290
        my @indicator    = $input->param('indicator');
291
        #Rebuilding ALL the data for items into a hash
289
        #Rebuilding ALL the data for items into a hash
292
        # parting them on $itemid.
290
        # parting them on $itemid.
293
291
Lines 301-316 if ( $orderinfo->{quantity} ne '0' ) { Link Here
301
            push @{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i];
299
            push @{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i];
302
            push @{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i];
300
            push @{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i];
303
            push @{$itemhash{$itemid[$i]}->{'field_values'}},$field_values[$i];
301
            push @{$itemhash{$itemid[$i]}->{'field_values'}},$field_values[$i];
304
            push @{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i];
305
            push @{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i];
306
        }
302
        }
307
        foreach my $item (keys %itemhash){
303
        foreach my $item (keys %itemhash){
308
304
305
            use Data::Dumper; die Dumper($itemhash{$item});
309
            my $xml = TransformHtmlToXml( $itemhash{$item}->{'tags'},
306
            my $xml = TransformHtmlToXml( $itemhash{$item}->{'tags'},
310
                                    $itemhash{$item}->{'subfields'},
307
                                    $itemhash{$item}->{'subfields'},
311
                                    $itemhash{$item}->{'field_values'},
308
                                    $itemhash{$item}->{'field_values'},
312
                                    $itemhash{$item}->{'ind_tag'},
313
                                    $itemhash{$item}->{'indicator'},
314
                                    'ITEM');
309
                                    'ITEM');
315
            my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
310
            my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
316
            my ($biblionumber,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$$orderinfo{biblionumber});
311
            my ($biblionumber,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$$orderinfo{biblionumber});
(-)a/acqui/addorderiso2709.pl (-5 / +1 lines)
Lines 244-258 if ($op eq ""){ Link Here
244
            my @subfields    = $input->param('subfield');
244
            my @subfields    = $input->param('subfield');
245
            my @field_values = $input->param('field_value');
245
            my @field_values = $input->param('field_value');
246
            my @serials      = $input->param('serial');
246
            my @serials      = $input->param('serial');
247
            my @ind_tag   = $input->param('ind_tag');
248
            my @indicator = $input->param('indicator');
249
            my $item;
247
            my $item;
250
            push @{ $item->{tags} },         $tags[0];
248
            push @{ $item->{tags} },         $tags[0];
251
            push @{ $item->{subfields} },    $subfields[0];
249
            push @{ $item->{subfields} },    $subfields[0];
252
            push @{ $item->{field_values} }, $field_values[0];
250
            push @{ $item->{field_values} }, $field_values[0];
253
            push @{ $item->{ind_tag} },      $ind_tag[0];
251
            my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values );
254
            push @{ $item->{indicator} },    $indicator[0];
255
            my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values, \@ind_tag, \@indicator );
256
            my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' );
252
            my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' );
257
            for (my $qtyloop=1;$qtyloop <=$quantity;$qtyloop++) {
253
            for (my $qtyloop=1;$qtyloop <=$quantity;$qtyloop++) {
258
                my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber );
254
                my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber );
(-)a/acqui/finishreceive.pl (-6 / +1 lines)
Lines 123-130 if ($quantityrec > $origquantityrec ) { Link Here
123
        my @field_values = $input->param('field_value');
123
        my @field_values = $input->param('field_value');
124
        my @serials      = $input->param('serial');
124
        my @serials      = $input->param('serial');
125
        my @itemid       = $input->param('itemid');
125
        my @itemid       = $input->param('itemid');
126
        my @ind_tag      = $input->param('ind_tag');
127
        my @indicator    = $input->param('indicator');
128
        #Rebuilding ALL the data for items into a hash
126
        #Rebuilding ALL the data for items into a hash
129
        # parting them on $itemid.
127
        # parting them on $itemid.
130
        my %itemhash;
128
        my %itemhash;
Lines 137-151 if ($quantityrec > $origquantityrec ) { Link Here
137
            push @{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i];
135
            push @{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i];
138
            push @{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i];
136
            push @{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i];
139
            push @{$itemhash{$itemid[$i]}->{'field_values'}},$field_values[$i];
137
            push @{$itemhash{$itemid[$i]}->{'field_values'}},$field_values[$i];
140
            push @{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i];
141
            push @{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i];
142
        }
138
        }
143
        foreach my $item (keys %itemhash){
139
        foreach my $item (keys %itemhash){
144
            my $xml = TransformHtmlToXml( $itemhash{$item}->{'tags'},
140
            my $xml = TransformHtmlToXml( $itemhash{$item}->{'tags'},
145
                                          $itemhash{$item}->{'subfields'},
141
                                          $itemhash{$item}->{'subfields'},
146
                                          $itemhash{$item}->{'field_values'},
142
                                          $itemhash{$item}->{'field_values'},
147
                                          $itemhash{$item}->{'ind_tag'},
143
                                          'ITEM');
148
                                          $itemhash{$item}->{'indicator'},'ITEM');
149
            my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
144
            my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
150
            my (undef,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$biblionumber);
145
            my (undef,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$biblionumber);
151
            NewOrderItem($itemnumber, $new_ordernumber);
146
            NewOrderItem($itemnumber, $new_ordernumber);
(-)a/cataloguing/additem.pl (-24 / +2 lines)
Lines 43-64 use URI::Escape; Link Here
43
43
44
our $dbh = C4::Context->dbh;
44
our $dbh = C4::Context->dbh;
45
45
46
sub find_value {
47
    my ($tagfield,$insubfield,$record) = @_;
48
    my $result;
49
    my $indicator;
50
    foreach my $field ($record->field($tagfield)) {
51
        my @subfields = $field->subfields();
52
        foreach my $subfield (@subfields) {
53
            if (@$subfield[0] eq $insubfield) {
54
                $result .= @$subfield[1];
55
                $indicator = $field->indicator(1).$field->indicator(2);
56
            }
57
        }
58
    }
59
    return($indicator,$result);
60
}
61
62
sub get_item_from_barcode {
46
sub get_item_from_barcode {
63
    my ($barcode)=@_;
47
    my ($barcode)=@_;
64
    my $dbh=C4::Context->dbh;
48
    my $dbh=C4::Context->dbh;
Lines 377-386 if ($op eq "additem") { Link Here
377
    my @tags      = $input->param('tag');
361
    my @tags      = $input->param('tag');
378
    my @subfields = $input->param('subfield');
362
    my @subfields = $input->param('subfield');
379
    my @values    = $input->param('field_value');
363
    my @values    = $input->param('field_value');
380
    # build indicator hash.
364
    my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values, 'ITEM');
381
    my @ind_tag   = $input->param('ind_tag');
382
    my @indicator = $input->param('indicator');
383
    my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
384
    my $record = MARC::Record::new_from_xml($xml, 'UTF-8');
365
    my $record = MARC::Record::new_from_xml($xml, 'UTF-8');
385
366
386
    # type of add
367
    # type of add
Lines 585-595 if ($op eq "additem") { Link Here
585
    my @tags      = $input->param('tag');
566
    my @tags      = $input->param('tag');
586
    my @subfields = $input->param('subfield');
567
    my @subfields = $input->param('subfield');
587
    my @values    = $input->param('field_value');
568
    my @values    = $input->param('field_value');
588
    # build indicator hash.
589
    my @ind_tag   = $input->param('ind_tag');
590
    my @indicator = $input->param('indicator');
591
    # my $itemnumber = $input->param('itemnumber');
569
    # my $itemnumber = $input->param('itemnumber');
592
    my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag,'ITEM');
570
    my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,'ITEM');
593
    my $itemtosave=MARC::Record::new_from_xml($xml, 'UTF-8');
571
    my $itemtosave=MARC::Record::new_from_xml($xml, 'UTF-8');
594
    # MARC::Record builded => now, record in DB
572
    # MARC::Record builded => now, record in DB
595
    # warn "R: ".$record->as_formatted;
573
    # warn "R: ".$record->as_formatted;
(-)a/serials/serials-edit.pl (-6 lines)
Lines 251-258 if ( $op and $op eq 'serialchangestatus' ) { Link Here
251
        my @serials      = $query->param('serial');
251
        my @serials      = $query->param('serial');
252
        my @bibnums      = $query->param('bibnum');
252
        my @bibnums      = $query->param('bibnum');
253
        my @itemid       = $query->param('itemid');
253
        my @itemid       = $query->param('itemid');
254
        my @ind_tag      = $query->param('ind_tag');
255
        my @indicator    = $query->param('indicator');
256
254
257
        #Rebuilding ALL the data for items into a hash
255
        #Rebuilding ALL the data for items into a hash
258
        # parting them on $itemid.
256
        # parting them on $itemid.
Lines 277-284 if ( $op and $op eq 'serialchangestatus' ) { Link Here
277
            push @{ $itemhash{ $itemid[$i] }->{'subfields'} }, $subfields[$i];
275
            push @{ $itemhash{ $itemid[$i] }->{'subfields'} }, $subfields[$i];
278
            push @{ $itemhash{ $itemid[$i] }->{'field_values'} },
276
            push @{ $itemhash{ $itemid[$i] }->{'field_values'} },
279
              $field_values[$i];
277
              $field_values[$i];
280
            push @{ $itemhash{ $itemid[$i] }->{'ind_tag'} },   $ind_tag[$i];
281
            push @{ $itemhash{ $itemid[$i] }->{'indicator'} }, $indicator[$i];
282
        }
278
        }
283
        foreach my $item ( keys %itemhash ) {
279
        foreach my $item ( keys %itemhash ) {
284
280
Lines 298-305 if ( $op and $op eq 'serialchangestatus' ) { Link Here
298
                    $itemhash{$item}->{'tags'},
294
                    $itemhash{$item}->{'tags'},
299
                    $itemhash{$item}->{'subfields'},
295
                    $itemhash{$item}->{'subfields'},
300
                    $itemhash{$item}->{'field_values'},
296
                    $itemhash{$item}->{'field_values'},
301
                    $itemhash{$item}->{'indicator'},
302
                    $itemhash{$item}->{'ind_tag'}
303
                );
297
                );
304
298
305
                #           warn $xml;
299
                #           warn $xml;
(-)a/tools/batchMod.pl (-21 / +1 lines)
Lines 98-106 if ($op eq "action") { Link Here
98
    my @subfields = $input->param('subfield');
98
    my @subfields = $input->param('subfield');
99
    my @values    = $input->param('field_value');
99
    my @values    = $input->param('field_value');
100
    my @disabled  = $input->param('disable_input');
100
    my @disabled  = $input->param('disable_input');
101
    # build indicator hash.
102
    my @ind_tag   = $input->param('ind_tag');
103
    my @indicator = $input->param('indicator');
104
101
105
    # Is there something to modify ?
102
    # Is there something to modify ?
106
    # TODO : We shall use this var to warn the user in case no modification was done to the items
103
    # TODO : We shall use this var to warn the user in case no modification was done to the items
Lines 140-146 if ($op eq "action") { Link Here
140
	#initializing values for updates
137
	#initializing values for updates
141
	my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
138
	my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
142
	if ($values_to_modify){
139
	if ($values_to_modify){
143
	    my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
140
	    my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values, 'ITEM');
144
        utf8::encode($xml);
141
        utf8::encode($xml);
145
	    $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
142
	    $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
146
        }
143
        }
Lines 595-616 sub UpdateMarcWith { Link Here
595
    return $modified;
592
    return $modified;
596
}
593
}
597
594
598
sub find_value {
599
    my ($tagfield,$insubfield,$record) = @_;
600
    my $result;
601
    my $indicator;
602
    foreach my $field ($record->field($tagfield)) {
603
        my @subfields = $field->subfields();
604
        foreach my $subfield (@subfields) {
605
            if (@$subfield[0] eq $insubfield) {
606
                $result .= @$subfield[1];
607
                $indicator = $field->indicator(1).$field->indicator(2);
608
            }
609
        }
610
    }
611
    return($indicator,$result);
612
}
613
614
# ----------------------------
595
# ----------------------------
615
# Background functions
596
# Background functions
616
597
617
- 

Return to bug 11247