X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=authorities%2Fauthorities.pl;h=3ea36804021100c5397b06a7a67730051da9808c;hb=eed620c773e3c48fdec656ae7b61e09352a94946;hp=23653f6a94fe3904a27e35137e7711f08bc22044;hpb=a642b1c72aa25743796e6e032c8aab1a2a905e14;p=koha.git diff --git a/authorities/authorities.pl b/authorities/authorities.pl index 23653f6a94..3ea3680402 100755 --- a/authorities/authorities.pl +++ b/authorities/authorities.pl @@ -20,10 +20,11 @@ use strict; use warnings; -use CGI; +use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; use C4::AuthoritiesMarc; +use C4::ImportBatch; #GetImportRecordMarc use C4::Context; use C4::Koha; # XXX subfield_is_koha_internal_p use Date::Calc qw(Today); @@ -47,6 +48,21 @@ builds list, depending on authorised value... =cut +sub MARCfindbreeding_auth { + my ( $id ) = @_; + my ($marc, $encoding) = GetImportRecordMarc($id); + if ($marc) { + my $record = MARC::Record->new_from_usmarc($marc); + if ( !defined(ref($record)) ) { + return -1; + } else { + return $record, $encoding; + } + } else { + return -1; + } +} + sub build_authorized_values_list { my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_; @@ -76,7 +92,8 @@ sub build_authorized_values_list { "select itemtype,description from itemtypes order by description"); $sth->execute; push @authorised_values, "" - unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); + unless ( $tagslib->{$tag}->{$subfield}->{mandatory} + && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) ); my $itemtype; @@ -93,25 +110,22 @@ sub build_authorized_values_list { $tagslib->{$tag}->{$subfield}->{authorised_value} ); push @authorised_values, "" - unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); + unless ( $tagslib->{$tag}->{$subfield}->{mandatory} + && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) ); while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) { push @authorised_values, $value; $authorised_lib{$value} = $lib; } } - return CGI::scrolling_list( - -name => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, - -values => \@authorised_values, - -default => $value, - -labels => \%authorised_lib, - -override => 1, - -size => 1, - -multiple => 0, - -tabindex => 1, - -id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, - -class => "input_marceditor", - ); + return { + type => 'select', + id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, + name => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, + values => \@authorised_values, + labels => \%authorised_lib, + default => $value, + }; } @@ -152,9 +166,15 @@ sub create_input { $value =~ s/DD/$day/g; } my $dbh = C4::Context->dbh; + + # map '@' as "subfield" label for fixed fields + # to something that's allowed in a div id. + my $id_subfield = $subfield; + $id_subfield = "00" if $id_subfield eq "@"; + my %subfield_data = ( tag => $tag, - subfield => $subfield, + subfield => $id_subfield, marc_lib => substr( $tagslib->{$tag}->{$subfield}->{lib}, 0, 22 ), marc_lib_plain => $tagslib->{$tag}->{$subfield}->{lib}, tag_mandatory => $tagslib->{$tag}->{mandatory}, @@ -162,14 +182,10 @@ sub create_input { repeatable => $tagslib->{$tag}->{$subfield}->{repeatable}, kohafield => $tagslib->{$tag}->{$subfield}->{kohafield}, index => $index_tag, - id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, + id => "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield, value => $value, + random => CreateKey(), ); - if($subfield eq '@'){ - $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_tag."_".$index_subfield; - } else { - $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield; - } if(exists $mandatory_z3950->{$tag.$subfield}){ $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield}; @@ -189,17 +205,13 @@ sub create_input { # it's a thesaurus / authority field } elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) { - $subfield_data{marc_value} = - " - {$tag}->{$subfield}->{authtypecode}."'); return false;\" tabindex=\"1\" title=\"Tag Editor\">... - "; + $subfield_data{marc_value} = { + type => 'text1', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + authtypecode => $tagslib->{$tag}->{$subfield}->{authtypecode}, + }; # it's a plugin field } elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) { @@ -219,43 +231,35 @@ sub create_input { my ( $function_name, $javascript ) = plugin_javascript( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop ); # my ( $function_name, $javascript,$extended_param ); - $subfield_data{marc_value} = - " - ... - $javascript"; + $subfield_data{marc_value} = { + type => 'text2', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + maxlength => $max_length, + function => $function_name, + index_tag => $index_tag, + javascript => $javascript, + }; # it's an hidden field } elsif ( $tag eq '' ) { - $subfield_data{marc_value} = - " - "; + $subfield_data{marc_value} = { + type => 'hidden', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + maxlength => $max_length, + } } elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) { - $subfield_data{marc_value} = - ""; + $subfield_data{marc_value} = { + type => 'text', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + maxlength => $max_length, + }; # it's a standard field } @@ -270,30 +274,24 @@ sub create_input { && C4::Context->preference("marcflavour") eq "MARC21" ) ) { - $subfield_data{marc_value} = - " - "; + $subfield_data{marc_value} = { + type => 'textarea', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + maxlength => $max_length, + }; + } else { - $subfield_data{marc_value} = - " - "; + $subfield_data{marc_value} = { + type => 'text', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + maxlength => $max_length, + }; + } } $subfield_data{'index_subfield'} = $index_subfield; @@ -325,6 +323,27 @@ sub CreateKey { return int(rand(1000000)); } +=item GetMandatoryFieldZ3950 + + This function return an hashref which containts all mandatory field + to search with z3950 server. + +=cut + +sub GetMandatoryFieldZ3950($){ + my $authtypecode = shift; + + #Tags guessed (see GuessAuthTypeCode from AuthoritiesMarc.pm) + + return { + '100'.'a' => 'authorpersonal', + '110'.'a' => 'authorcorp', + '111'.'a' => 'authormeetingcon', + '130'.'a' => 'uniformtitle', + '150'.'a' => 'topic', + }; +} + sub build_tabs { my ( $template, $record, $dbh, $encoding,$input ) = @_; @@ -519,7 +538,10 @@ sub build_hidden_data { $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib}; $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory}; $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable}; - $subfield_data{marc_value}=""; + $subfield_data{marc_value} = { + type => 'hidden_simple', + name => 'field_value[]', + }; push(@loop_data, \%subfield_data); $i++ } @@ -543,6 +565,7 @@ my $nonav = $input->param('nonav'); my $myindex = $input->param('index'); my $linkid=$input->param('linkid'); my $authtypecode = $input->param('authtypecode'); +my $breedingid = $input->param('breedingid'); my $dbh = C4::Context->dbh; if(!$authtypecode) { @@ -550,18 +573,27 @@ if(!$authtypecode) { } my ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "authorities/authorities.tmpl", + = get_template_and_user({template_name => "authorities/authorities.tt", query => $input, type => "intranet", authnotrequired => 0, flagsrequired => {editauthorities => 1}, debug => 1, }); -$template->param(nonav => $nonav,index=>$myindex,authtypecode=>$authtypecode,); +$template->param(nonav => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,); + $tagslib = GetTagsLabels(1,$authtypecode); +$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode); + my $record=-1; my $encoding=""; -$record = GetAuthority($authid) if ($authid); +if (($authid) && !($breedingid)){ + $record = GetAuthority($authid); +} +if ($breedingid) { + ( $record, $encoding ) = MARCfindbreeding_auth( $breedingid ); +} + my ($oldauthnumtagfield,$oldauthnumtagsubfield); my ($oldauthtypetagfield,$oldauthtypetagsubfield); $is_a_modif=0; @@ -582,17 +614,6 @@ if ($op eq "add") { my @ind_tag = $input->param('ind_tag'); my @indicator = $input->param('indicator'); my $record = TransformHtmlToMarc($input); - if (C4::Context->preference("marcflavour") eq "UNIMARC"){ - unless ($record->field('100')){ - use POSIX qw(strftime); - my $string = strftime( "%Y%m%d", localtime(time) ); - # set 50 to position 26 is biblios, 13 if authorities - my $pos=13; - $string = sprintf( "%-*s", 35, $string ); - substr( $string, $pos , 2, "50" ); - $record->append_fields(MARC::Field->new('100','','',"a"=>$string)); - } - } my ($duplicateauthid,$duplicateauthvalue); ($duplicateauthid,$duplicateauthvalue) = FindDuplicateAuthority($record,$authtypecode) if ($op eq "add") && (!$is_a_modif); @@ -604,7 +625,11 @@ if ($op eq "add") { } else { ($authid) = AddAuthority($record,$authid,$authtypecode); } - print $input->redirect("detail.pl?authid=$authid"); + if ($myindex) { + print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex"); + } else { + print $input->redirect("detail.pl?authid=$authid"); + } exit; } else { # it may be a duplicate, warn the user and do nothing @@ -612,7 +637,7 @@ if ($op eq "add") { build_hidden_data; $template->param(authid =>$authid, duplicateauthid => $duplicateauthid, - duplicateauthvalue => $duplicateauthvalue, + duplicateauthvalue => $duplicateauthvalue->{'authorized'}->[0]->{'heading'}, ); } } elsif ($op eq "delete") {