From df21bd6c0a3eacf4839ca1889475a0d611949720 Mon Sep 17 00:00:00 2001 From: tipaul Date: Thu, 28 Apr 2005 08:45:33 +0000 Subject: [PATCH] porting FindDuplicate feature for authorities from HEAD to rel_2_2, works correctly now. --- C4/AuthoritiesMarc.pm | 57 ++++++++++++++++++- authorities/authorities.pl | 31 +++++++--- .../default/en/authorities/authorities.tmpl | 10 ++++ 3 files changed, 90 insertions(+), 8 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 7ed3381539..a4fa317fd3 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -51,6 +51,7 @@ $VERSION = 0.01; &AUTHaddword &MARCaddword &MARCdelword &char_decode + &FindDuplicate ); sub authoritysearch { @@ -74,7 +75,7 @@ sub authoritysearch { # "Normal" statements # quote marc fields/subfields - for (my $i=0;$i<$#{$tags};$i++) { + for (my $i=0;$i<=$#{$tags};$i++) { if (@$tags[$i]) { @$tags[$i] = $dbh->quote(@$tags[$i]); } @@ -844,6 +845,57 @@ sub nsb_clean { return($string) ; } +sub FindDuplicate { + my ($record,$authtypecode)=@_; + warn "IN for ".$record->as_formatted; + my $dbh = C4::Context->dbh; + +# warn "".$record->as_formatted; + my $sth = $dbh->prepare("select auth_tag_to_report,summary from auth_types where authtypecode=?"); + $sth->execute($authtypecode); + my ($auth_tag_to_report,$taglist) = $sth->fetchrow; + $sth->finish; + # build a request for authoritysearch + my (@tags, @and_or, @excluding, @operator, @value, $offset, $length); + # search on biblio.title +# warn " tag a reporter : $auth_tag_to_report"; +# warn "taglist ".$taglist; + my @subfield = split /\[/, $taglist; + my $max = @subfield; + for (my $i=1; $i<$max;$i++){ + warn " ".$subfield[$i]; + $subfield[$i]=substr($subfield[$i],3,1); +# warn " ".$subfield[$i]; + } + + if ($record->fields($auth_tag_to_report)) { + my $sth = $dbh->prepare("select tagfield,tagsubfield from auth_subfield_structure where tagfield=? and authtypecode=? "); + $sth->execute($auth_tag_to_report,$authtypecode); +# warn " field $auth_tag_to_report exists"; + while (my ($tag,$subfield) = $sth->fetchrow){ + if ($record->field($tag)->subfield($subfield)) { + warn "tag :".$tag." subfield: $subfield value : ".$record->field($tag)->subfield($subfield); + push @tags, $tag.$subfield; +# warn "'".$tag.$subfield."' value :". $record->field($tag)->subfield($subfield); + push @and_or, "and"; + push @excluding, ""; + push @operator, "="; + push @value, $record->field($tag)->subfield($subfield); + } + } + } + + my ($finalresult,$nbresult) = authoritysearch($dbh,\@tags,\@and_or,\@excluding,\@operator,\@value,0,10,$authtypecode); + # there is at least 1 result => return the 1st one + if ($nbresult) { + warn "XXXXX $nbresult => ".@$finalresult[0]->{authid},@$finalresult[0]->{summary}; + return @$finalresult[0]->{authid},@$finalresult[0]->{summary}; + } + # no result, returns nothing + return; +} + + END { } # module clean-up code here (global destructor) =back @@ -858,6 +910,9 @@ Paul POULAIN paul.poulain@free.fr # $Id$ # $Log$ +# Revision 1.9.2.3 2005/04/28 08:45:33 tipaul +# porting FindDuplicate feature for authorities from HEAD to rel_2_2, works correctly now. +# # Revision 1.9.2.2 2005/02/28 14:03:13 tipaul # * adding search on "main entry" (ie $a subfield) on a given authority (the "search everywhere" field is still here). # * adding a select box to requet "contain" or "begin with" search. diff --git a/authorities/authorities.pl b/authorities/authorities.pl index 76e008e725..12bd3cd3d4 100755 --- a/authorities/authorities.pl +++ b/authorities/authorities.pl @@ -160,7 +160,6 @@ sub create_input () { sub build_tabs ($$$$) { my($template, $record, $dbh,$encoding) = @_; -# "=>".$record->as_formatted; # fill arrays my @loop_data =(); my $tag; @@ -334,12 +333,28 @@ if ($op eq "add") { } my $record = AUTHhtml2marc($dbh,\@tags,\@subfields,\@values,%indicators); # MARC::Record built => now, record in DB - if ($is_a_modif) { - AUTHmodauthority($dbh,$authid,$record,$authtypecode); + # check for a duplicate + my ($duplicateauthid,$duplicateauthvalue) = FindDuplicate($record,$authtypecode) if ($op eq "add") && (!$is_a_modif); + 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) { + if ($is_a_modif) { + AUTHmodauthority($dbh,$authid,$record,$authtypecode); + } else { + ($authid) = AUTHaddauthority($dbh,$record,$authid,$authtypecode); + } + # now, redirect to detail page + print $input->redirect("detail.pl?authid=$authid"); + exit; } else { - ($authid) = AUTHaddauthority($dbh,$record,$authid,$authtypecode); + # it may be a duplicate, warn the user and do nothing + build_tabs ($template, $record, $dbh,$encoding); + build_hidden_data; + $template->param( + duplicateauthid => $duplicateauthid, + duplicateauthvalue => $duplicateauthvalue, + ); } - print $input->redirect("detail.pl?authid=$authid"); #------------------------------------------------------------------------------------------------------------------------------ } elsif ($op eq "addfield") { #------------------------------------------------------------------------------------------------------------------------------ @@ -399,8 +414,10 @@ if ($op eq "add") { &AUTHdelauthority($dbh,$authid); } -build_tabs ($template, $record, $dbh,$encoding); -build_hidden_data; +if ($authid) { + build_tabs ($template, $record, $dbh,$encoding); + build_hidden_data; +} $template->param( authid => $authid, # oldbiblionumtagfield => $oldbiblionumtagfield, diff --git a/koha-tmpl/intranet-tmpl/default/en/authorities/authorities.tmpl b/koha-tmpl/intranet-tmpl/default/en/authorities/authorities.tmpl index 4f142c3591..fd19d677d0 100644 --- a/koha-tmpl/intranet-tmpl/default/en/authorities/authorities.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/authorities/authorities.tmpl @@ -18,6 +18,16 @@










+ +
+

Duplicate suspected with

+

You must either :

+ +
+ -- 2.39.5