Code Cleaning : AuthoritiesMARC.

This commit is contained in:
hdl 2007-04-06 14:48:45 +00:00
parent 53f665eb94
commit b767f50c8f
10 changed files with 676 additions and 524 deletions

File diff suppressed because it is too large Load Diff

View File

@ -64,7 +64,7 @@ if ($op eq "do_search") {
$resultsperpage= $query->param('resultsperpage');
$resultsperpage = 19 if(!defined $resultsperpage);
my ($results,$total) = authoritysearch(\@marclist,\@and_or,
my ($results,$total) = SearchAuthorities(\@marclist,\@and_or,
\@excluding, \@operator, \@value,
$startfrom*$resultsperpage, $resultsperpage,$authtypecode);# $orderby);

View File

@ -62,7 +62,7 @@ if ($op eq "do_search") {
my $startfrom = $query->param('startfrom') || 1;
my $resultsperpage = $query->param('resultsperpage') || 19;
my ($results,$total) = authoritysearch(
my ($results,$total) = SearchAuthorities(
\@marclist,
\@and_or,
\@excluding,
@ -146,7 +146,7 @@ if ($op eq "do_search") {
} elsif ($op eq "delete") {
&AUTHdelauthority($authid, 1);
&DelAuthority($authid, 1);
($template, $loggedinuser, $cookie)
= get_template_and_user({template_name => "authorities/authorities-home.tmpl",

View File

@ -349,7 +349,7 @@ my $linkid=$input->param('linkid');
my $authtypecode = $input->param('authtypecode');
my $dbh = C4::Context->dbh;
$authtypecode = &AUTHfind_authtypecode($authid) if !$authtypecode;
$authtypecode = &GetAuthTypeCode($authid) if !$authtypecode;
my ($template, $loggedinuser, $cookie)
@ -361,17 +361,17 @@ my ($template, $loggedinuser, $cookie)
debug => 1,
});
$template->param(nonav => $nonav,index=>$myindex,authtypecode=>$authtypecode,);
$tagslib = AUTHgettagslib(1,$authtypecode);
$tagslib = GetTagsLabels(1,$authtypecode);
my $record=-1;
my $encoding="";
$record = AUTHgetauthority($authid) if ($authid);
$record = GetAuthority($authid) if ($authid);
my ($oldauthnumtagfield,$oldauthnumtagsubfield);
my ($oldauthtypetagfield,$oldauthtypetagsubfield);
$is_a_modif=0;
if ($authid) {
$is_a_modif=1;
($oldauthnumtagfield,$oldauthnumtagsubfield) = &AUTHfind_marc_from_kohafield("auth_header.authid",$authtypecode);
($oldauthtypetagfield,$oldauthtypetagsubfield) = &AUTHfind_marc_from_kohafield("auth_header.authtypecode",$authtypecode);
$is_a_modif=1;
($oldauthnumtagfield,$oldauthnumtagsubfield) = &GetAuthMARCFromKohaField("auth_header.authid",$authtypecode);
($oldauthtypetagfield,$oldauthtypetagsubfield) = &GetAuthMARCFromKohaField("auth_header.authtypecode",$authtypecode);
}
#------------------------------------------------------------------------------------------------------------------------------
@ -387,39 +387,32 @@ if ($op eq "add") {
my @indicator = $input->param('indicator');
my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag);
# warn $record->as_formatted;
warn $xml;
# warn $xml;
my $record=MARC::Record->new_from_xml($xml,'UTF-8',(C4::Context->preference("marcflavour") eq "UNIMARC"?"UNIMARCAUTH":C4::Context->preference("marcflavour")));
$record->encoding('UTF-8');
#warn $record->as_formatted;
# check for a duplicate
my ($duplicateauthid,$duplicateauthvalue) = C4::AuthoritiesMarc::FindDuplicate($record,$authtypecode) if ($op eq "add") && (!$is_a_modif);
my ($duplicateauthid,$duplicateauthvalue) = FindDuplicateAuthority($record,$authtypecode) if ($op eq "add") && (!$is_a_modif);
warn "duplicate:$duplicateauthid,$duplicateauthvalue";
my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
# it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
if (!$duplicateauthid or $confirm_not_duplicate) {
# warn "noduplicate";
if ($is_a_modif ) {
$authid=AUTHmodauthority($authid,$record,$authtypecode,1);
} else {
($authid) = AUTHaddauthority($record,$authid,$authtypecode);
}
# now, redirect to detail page
# if ($nonav){
#warn ($myindex,$nonav);
# print $input->redirect("auth_finder.pl?index=$myindex&nonav=$nonav&authtypecode=$authtypecode");
# }else{
print $input->redirect("detail.pl?authid=$authid");
# }
exit;
if ($is_a_modif ) {
$authid=ModAuthority($authid,$record,$authtypecode,1);
} else {
($authid) = AddAuthority($record,$authid,$authtypecode);
}
print $input->redirect("detail.pl?authid=$authid");
exit;
} else {
# it may be a duplicate, warn the user and do nothing
build_tabs ($template, $record, $dbh,$encoding);
build_hidden_data;
$template->param(authid =>$authid,
duplicateauthid => $duplicateauthid,
duplicateauthvalue => $duplicateauthvalue,
);
build_tabs ($template, $record, $dbh,$encoding);
build_hidden_data;
$template->param(authid =>$authid,
duplicateauthid => $duplicateauthid,
duplicateauthvalue => $duplicateauthvalue,
);
}
#------------------------------------------------------------------------------------------------------------------------------
} elsif ($op eq "addfield") {
@ -441,7 +434,7 @@ warn "duplicate:$duplicateauthid,$duplicateauthvalue";
build_tabs ($template, $record, $dbh,$encoding);
build_hidden_data;
$template->param(
authid => $authid,);
authid => $authid,);
} elsif ($op eq "delete") {
#------------------------------------------------------------------------------------------------------------------------------
@ -464,11 +457,6 @@ if ($op eq "duplicate")
authid => $authid , authtypecode=>$authtypecode, );
}
#unless ($op) {
# warn "BUILDING";
# build_tabs ($template, $record, $dbh,$encoding);
# build_hidden_data;
#}
$template->param(
authid => $authid,
authtypecode => $authtypecode,

View File

@ -57,13 +57,13 @@ my $dbh=C4::Context->dbh;
my $authid = $query->param('authid');
my $index = $query->param('index');
my $tagid = $query->param('tagid');
my $authtypecode = &AUTHfind_authtypecode($authid);
my $tagslib = &AUTHgettagslib(1,$authtypecode);
my $authtypecode = &GetAuthTypeCode($authid);
my $tagslib = &GetTagsLabels(1,$authtypecode);
my $auth_type = AUTHgetauth_type($authtypecode);
my $auth_type = GetAuthType($authtypecode);
warn "XX = ".$auth_type->{auth_tag_to_report};
my $record =AUTHgetauthority($authid);
my $record =GetAuthority($authid);
warn "record auth :".$record->as_formatted;
# open template
my ($template, $loggedinuser, $cookie)
@ -80,67 +80,56 @@ my @loop_data =();
my $tag;
my @loop_data =();
if ($authid) {
foreach my $field ($record->field($auth_type->{auth_tag_to_report})) {
my @subfields_data;
my @subf=$field->subfields;
# loop through each subfield
my %result;
for my $i (0..$#subf) {
$subf[$i][0] = "@" unless $subf[$i][0];
$result{$subf[$i][0]}.=$subf[$i][1]."|";
}
foreach (keys %result) {
my %subfield_data;
chop $result{$_};
$subfield_data{marc_value}=$result{$_};
$subfield_data{marc_subfield}=$_;
foreach my $field ($record->field($auth_type->{auth_tag_to_report})) {
my @subfields_data;
my @subf=$field->subfields;
# loop through each subfield
my %result;
for my $i (0..$#subf) {
$subf[$i][0] = "@" unless $subf[$i][0];
$result{$subf[$i][0]}.=$subf[$i][1]."|";
}
foreach (keys %result) {
my %subfield_data;
chop $result{$_};
$subfield_data{marc_value}=$result{$_};
$subfield_data{marc_subfield}=$_;
# $subfield_data{marc_tag}=$field->tag();
push(@subfields_data, \%subfield_data);
}
if ($#subfields_data>=0) {
my %tag_data;
$tag_data{tag}=$field->tag().' -'. $tagslib->{$field->tag()}->{lib};
$tag_data{subfield} = \@subfields_data;
push (@loop_data, \%tag_data);
}
}
push(@subfields_data, \%subfield_data);
}
if ($#subfields_data>=0) {
my %tag_data;
$tag_data{tag}=$field->tag().' -'. $tagslib->{$field->tag()}->{lib};
$tag_data{subfield} = \@subfields_data;
push (@loop_data, \%tag_data);
}
}
} else {
# authid is empty => the user want to empty the entry.
my @subfields_data;
foreach my $subfield ('a'..'z') {
my %subfield_data;
$subfield_data{marc_value}='';
$subfield_data{marc_subfield}=$subfield;
push(@subfields_data, \%subfield_data);
}
my @subfields_data;
foreach my $subfield ('a'..'z') {
my %subfield_data;
$subfield_data{marc_value}='';
$subfield_data{marc_subfield}=$subfield;
push(@subfields_data, \%subfield_data);
}
# if ($#subfields_data>=0) {
my %tag_data;
my %tag_data;
# $tag_data{tag}=$field->tag().' -'. $tagslib->{$field->tag()}->{lib};
$tag_data{subfield} = \@subfields_data;
push (@loop_data, \%tag_data);
$tag_data{subfield} = \@subfields_data;
push (@loop_data, \%tag_data);
# }
}
$template->param("0XX" =>\@loop_data);
# my $authtypes = getauthtypes;
# my @authtypesloop;
# foreach my $thisauthtype (keys %$authtypes) {
# my $selected = 1 if $thisauthtype eq $authtypecode;
# my %row =(value => $thisauthtype,
# selected => $selected,
# authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
# );
# push @authtypesloop, \%row;
# }
$template->param(authid => $authid?$authid:"",
# authtypesloop => \@authtypesloop,
index => $index,
tagid => $tagid,
intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
intranetstylesheet => C4::Context->preference("intranetstylesheet"),
IntranetNav => C4::Context->preference("IntranetNav"),
);
index => $index,
tagid => $tagid,
intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
intranetstylesheet => C4::Context->preference("intranetstylesheet"),
IntranetNav => C4::Context->preference("IntranetNav"),
);
output_html_with_http_headers $query, $cookie, $template->output;

View File

@ -58,10 +58,10 @@ my $dbh=C4::Context->dbh;
my $authid = $query->param('authid');
my $index = $query->param('index');
my $authtypecode = &AUTHfind_authtypecode($dbh,$authid);
my $tagslib = &AUTHgettagslib($dbh,1,$authtypecode);
my $authtypecode = &GetAuthTypeCode($authid);
my $tagslib = &GetTagsLabels(1,$authtypecode);
my $record =AUTHgetauthority($dbh,$authid);
my $record =GetAuthority($authid);
# open template
my ($template, $loggedinuser, $cookie)
= get_template_and_user({template_name => "authorities/detail-biblio-search.tmpl",
@ -119,52 +119,6 @@ my $tag;
}
}
$template->param("0XX" =>\@loop_data);
# }
# now, build item tab !
# the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
# loop through each tag
# warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
# then construct template.
# my @fields = $record->fields();
# my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
# my @big_array;
# foreach my $field (@fields) {
# next if ($field->tag()<10);
# my @subf=$field->subfields;
# my %this_row;
# # loop through each subfield
# for my $i (0..$#subf) {
# next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} ne 10);
# $witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib};
# $this_row{$subf[$i][0]} =$subf[$i][1];
# }
# if (%this_row) {
# push(@big_array, \%this_row);
# }
# }
# #fill big_row with missing datas
# foreach my $subfield_code (keys(%witness)) {
# for (my $i=0;$i<=$#big_array;$i++) {
# $big_array[$i]{$subfield_code}="&nbsp;" unless ($big_array[$i]{$subfield_code});
# }
# }
# # now, construct template !
# my @item_value_loop;
# my @header_value_loop;
# for (my $i=0;$i<=$#big_array; $i++) {
# my $items_data;
# foreach my $subfield_code (keys(%witness)) {
# $items_data .="<td>".$big_array[$i]{$subfield_code}."</td>";
# }
# my %row_data;
# $row_data{item_value} = $items_data;
# push(@item_value_loop,\%row_data);
# }
# foreach my $subfield_code (keys(%witness)) {
# my %header_value;
# $header_value{header_value} = $witness{$subfield_code};
# push(@header_value_loop, \%header_value);
# }
my $authtypes = getauthtypes;
my @authtypesloop;

View File

@ -19,7 +19,7 @@
=head1 NAME
etail.pl : script to show an authority in MARC format
detail.pl : script to show an authority in MARC format
=head1 SYNOPSIS
@ -70,8 +70,8 @@ my $authid = $query->param('authid');
my $authtypecode = &AUTHfind_authtypecode($authid);
my $tagslib = &AUTHgettagslib(1,$authtypecode);
my $authtypecode = &GetAuthTypeCode($authid);
my $tagslib = &GetTagsLabels(1,$authtypecode);
my $record;
if (C4::Context->preference("AuthDisplayHierarchy")){
@ -85,8 +85,8 @@ if (C4::Context->preference("AuthDisplayHierarchy")){
my $cnt=0;
my @loophierarchy;
foreach my $element (@tree){
my %cell;
my $elementdata = AUTHgetauthority($element);
my $cell;
my $elementdata = GetAuthority($element);
$record= $elementdata if ($authid==$element);
push @loophierarchy, BuildUnimarcHierarchy($elementdata,"child".$cnt, $authid);
$cnt++;
@ -98,9 +98,9 @@ if (C4::Context->preference("AuthDisplayHierarchy")){
'loophierarchies' =>\@loophierarchies,
);
} else {
$record=AUTHgetauthority($authid);
$record=GetAuthority($authid);
}
my $count = AUTHcount_usage($authid);
my $count = CountUsage($authid);
# find the marc field/subfield used in biblio by this authority
my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");

View File

@ -67,7 +67,7 @@ if ( $op eq "do_search" ) {
$resultsperpage = 19 if ( !defined $resultsperpage );
my @tags;
my ( $results, $total, @fields ) =
authoritysearch( \@marclist, \@and_or, \@excluding, \@operator,
SearchAuthorities( \@marclist, \@and_or, \@excluding, \@operator,
\@value, $startfrom * $resultsperpage,
$resultsperpage, $authtypecode );
( $template, $loggedinuser, $cookie ) = get_template_and_user(
@ -147,7 +147,7 @@ if ( $op eq "do_search" ) {
}
elsif ( $op eq "delete" ) {
&AUTHdelauthority( $authid, 1 );
&DelAuthority( $authid, 1 );
( $template, $loggedinuser, $cookie ) = get_template_and_user(
{

View File

@ -55,7 +55,7 @@ my $dbh = C4::Context->dbh;
my $authid = $query->param('authid');
my $authtypecode = &AUTHfind_authtypecode( $authid );
my $tagslib = &AUTHgettagslib( 1, $authtypecode );
my $tagslib = &GetTagsLabels( 1, $authtypecode );
# open template
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
@ -88,7 +88,7 @@ if ( C4::Context->preference("AuthDisplayHierarchy") ) {
# warn "tree :$element";
my %cell;
my $elementdata = AUTHgetauthority( $element );
my $elementdata = GetAuthority( $element );
$record = $elementdata if ( $authid == $element );
push @loophierarchy,
BuildUnimarcHierarchy( $elementdata, "child" . $cnt, $authid );
@ -103,9 +103,9 @@ if ( C4::Context->preference("AuthDisplayHierarchy") ) {
}
}
else {
$record = AUTHgetauthority( $authid );
$record = GetAuthority( $authid );
}
my $count = AUTHcount_usage($authid);
my $count = CountUsage($authid);
# find the marc field/subfield used in biblio by this authority
my $sth =

View File

@ -104,5 +104,9 @@ $template->param(
$template->param(
'Disable_Dictionary' => C4::Context->preference("Disable_Dictionary") )
if ( C4::Context->preference("Disable_Dictionary") );
$template->param(
'OpacAuthorities' => 1 );
$template->param(
'OpacCloud' => 1 );
output_html_with_http_headers $input, $cookie, $template->output;