X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=cataloguing%2Faddbiblio.pl;h=d78d2534fd28167022e52f39a5cb1b39e3548269;hb=0396492c4ea02cf2eecd0b5970daf44e993b49d0;hp=8777e6c3e7dd2bf16e954f235acbe4e8ff2c1fa1;hpb=a85f1004949842c83b80e5b963d59e8c01a67def;p=koha_gimpoz diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 8777e6c3e7..d78d2534fd 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -290,7 +290,9 @@ sub create_input { index => $index_tag, id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, value => $value, + random => CreateKey(), ); + # deal with a <010 tag if($subfield eq '@'){ $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_tag."_".$index_subfield; } else { @@ -300,12 +302,14 @@ sub create_input { if(exists $mandatory_z3950->{$tag.$subfield}){ $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield}; } - + # decide if the subfield must be expanded (visible) by default or not + # if it is mandatory, then expand. If it is hidden explicitly by the hidden flag, hidden anyway $subfield_data{visibility} = "display:none;" if ( ($tagslib->{$tag}->{$subfield}->{hidden} % 2 == 1) and $value ne '' or ($value eq '' and !$tagslib->{$tag}->{$subfield}->{mandatory}) ); - + # always expand all subfields of a mandatory field + $subfield_data{visibility} = "" if $tagslib->{$tag}->{mandatory}; # it's an authorised field if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) { $subfield_data{marc_value} = @@ -316,15 +320,15 @@ sub create_input { } elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) { $subfield_data{marc_value} = - " - {$tag}->{$subfield}->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}')\">... + " + {$tag}->{$subfield}->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}')\">... "; # it's a plugin field } @@ -345,14 +349,13 @@ sub create_input { $subfield_data{marc_value} = " - ... + onfocus=\"Focus$function_name($index_tag)\" + onblur=\"Blur$function_name($index_tag); \" \/> + ... $javascript"; # it's an hidden field } @@ -360,16 +363,16 @@ sub create_input { $subfield_data{marc_value} = " "; } elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) { $subfield_data{marc_value} = "$value @@ -401,8 +404,8 @@ sub create_input { else { $subfield_data{marc_value} = "leader(); # if tag == 000 } + # loop through each field foreach my $field (@fields) { my @subfields_data; @@ -529,12 +533,18 @@ sub build_tabs ($$$$$) { ); } if ( $#subfields_data >= 0 ) { + # build the tag entry. + # note that the random() field is mandatory. Otherwise, on repeated fields, you'll + # have twice the same "name" value, and cgi->param() will return only one, making + # all subfields to be merged in a single field. my %tag_data = ( tag => $tag, index => $index_tag, tag_lib => $tagslib->{$tag}->{lib}, + repeatable => $tagslib->{$tag}->{repeatable}, subfield_loop => \@subfields_data, - fixedfield => ($tag < 10)?(1):(0), + fixedfield => $tag < 10?1:0, + random => CreateKey, ); if ($tag >= 010){ # no indicator for theses tag $tag_data{indicator} = $field->indicator(1).$field->indicator(2); @@ -572,7 +582,7 @@ sub build_tabs ($$$$$) { indicator => $indicator, subfield_loop => \@subfields_data, tagfirstsubfield => $subfields_data[0], - fixedfield => ($tag < 10)?(1):(0) + fixedfield => $tag < 10?1:0, ); push @loop_data, \%tag_data ; @@ -589,6 +599,51 @@ sub build_tabs ($$$$$) { $template->param( BIG_LOOP => \@BIG_LOOP ); } +sub BiblioAddAuthorities{ + my ( $record, $frameworkcode ) = @_; + my $dbh=C4::Context->dbh; + my $query=$dbh->prepare(qq| +SELECT authtypecode,tagfield +FROM marc_subfield_structure +WHERE frameworkcode=? +AND (authtypecode IS NOT NULL AND authtypecode<>\"\")|); +# SELECT authtypecode,tagfield +# FROM marc_subfield_structure +# WHERE frameworkcode=? +# AND (authtypecode IS NOT NULL OR authtypecode<>\"\")|); + $query->execute($frameworkcode); + my ($countcreated,$countlinked); + while (my $data=$query->fetchrow_hashref){ + if ($record->field($data->{tagfield})){ + next if ($record->subfield($data->{tagfield},'3')||$record->subfield($data->{tagfield},'9')); + # No authorities id in the tag. + # Search if there is any authorities to link to. + my $query='at='.$data->{authtypecode}.' '; + map {$query.= " and he=".$_->[1] if ($_->[0]=~/[A-z]/)} $record->field($data->{tagfield})->subfields(); + my ($error,$results)=SimpleSearch($query,"authorityserver"); + # there is at least 1 result => return the 1st one + if (@$results>1) { + my $marcrecord = MARC::File::USMARC::decode($results->[0]); + $record->field($data->{tagfield})->add_subfields('9'=>$marcrecord->field('001')->data); + $countlinked++; + } else { + #There are no results, build authority record, add it to Authorities, get authid and add it to 9 + ###NOTICE : This is only valid if a subfield is linked to one and only one authtypecode + + my $authtypedata=GetAuthType($data->{authtypecode}); + my $marcrecordauth=MARC::Record->new(); + my $field=MARC::Field->new($authtypedata->{auth_tag_to_report},'','',"a"=>"".$record->subfield($data->{tagfield},'a')); + map { $field->add_subfields($_->[0]=>$_->[1]) if ($_->[0]=~/[A-z]/ && $_->[0] ne "a" )} $record->field($data->{tagfield})->subfields(); + $marcrecordauth->insert_fields_ordered($field); + my $authid=AddAuthority($marcrecordauth,'',$data->{authtypecode}); + $countcreated++; + $record->field($data->{tagfield})->add_subfields('9'=>$authid); + } + } + } + return ($countlinked,$countcreated); +} + # ======================== # MAIN #========================= @@ -634,7 +689,7 @@ my $framework = CGI::scrolling_list( -name => 'Frameworks', -id => 'Frameworks', -default => $curfwk, - -OnChange => 'Changefwk(this);', + -onchange => 'Changefwk(this);', -values => \@select_fwk, -labels => \%select_fwk, -size => 1, @@ -651,8 +706,8 @@ $mandatory_z3950 = GetMandatoryFieldZ3950($frameworkcode); my $record = -1; my $encoding = ""; my ( - $biblionumtagfield, - $biblionumtagsubfield, + $biblionumbertagfield, + $biblionumbertagsubfield, $biblioitemnumtagfield, $biblioitemnumtagsubfield, $bibitem, @@ -672,7 +727,7 @@ if ($biblionumber) { $is_a_modif = 1; # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB. - ( $biblionumtagfield, $biblionumtagsubfield ) = + ( $biblionumbertagfield, $biblionumbertagsubfield ) = &GetMarcFromKohaField( "biblio.biblionumber", $frameworkcode ); ( $biblioitemnumtagfield, $biblioitemnumtagsubfield ) = &GetMarcFromKohaField( "biblioitems.biblioitemnumber", $frameworkcode ); @@ -696,6 +751,9 @@ if ( $op eq "addbiblio" ) { if ( !$duplicatebiblionumber or $confirm_not_duplicate ) { my $oldbibnum; my $oldbibitemnum; + if (C4::Context->preference("BiblioAddsAuthorities")){ + my ($countlinked,$countcreated)=BiblioAddAuthorities($record,$frameworkcode); + } if ( $is_a_modif ) { ModBiblioframework( $biblionumber, $frameworkcode ); ModBiblio( $record, $biblionumber, $frameworkcode ); @@ -704,10 +762,6 @@ if ( $op eq "addbiblio" ) { ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode ); } - if (C4::Context->preference("BiblioAddsAuthorities")){ - my ($countlinked,$countcreated)=BiblioAddAuthorities($record,$frameworkcode); - } - if ($mode ne "popup"){ print $input->redirect( "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode" @@ -733,10 +787,6 @@ if ( $op eq "addbiblio" ) { build_tabs ($template, $record, $dbh,$encoding,$input); $template->param( biblionumber => $biblionumber, - biblionumtagfield => $biblionumtagfield, - biblionumtagsubfield => $biblionumtagsubfield, - biblioitemnumtagfield => $biblioitemnumtagfield, - biblioitemnumtagsubfield => $biblioitemnumtagsubfield, biblioitemnumber => $biblioitemnumber, duplicatebiblionumber => $duplicatebiblionumber, duplicatebibid => $duplicatebiblionumber, @@ -775,8 +825,8 @@ elsif ( $op eq "delete" ) { build_tabs( $template, $record, $dbh, $encoding,$input ); $template->param( biblionumber => $biblionumber, - biblionumtagfield => $biblionumtagfield, - biblionumtagsubfield => $biblionumtagsubfield, + biblionumbertagfield => $biblionumbertagfield, + biblionumbertagsubfield => $biblionumbertagsubfield, biblioitemnumtagfield => $biblioitemnumtagfield, biblioitemnumtagsubfield => $biblioitemnumtagsubfield, biblioitemnumber => $biblioitemnumber,