From 4ff9cae64be993d3e1c196af76fbb054e5c3be52 Mon Sep 17 00:00:00 2001 From: hdl Date: Tue, 5 Apr 2005 09:58:47 +0000 Subject: [PATCH] Adding double authority search before creating a new authority --- C4/AuthoritiesMarc.pm | 44 +++++++++++++++++++ authorities/authorities.pl | 26 +++++++++-- .../default/en/authorities/authorities.tmpl | 10 +++++ 3 files changed, 76 insertions(+), 4 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 00d57b0142..cd68b4afbd 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -51,6 +51,7 @@ $VERSION = 0.01; &AUTHaddword &MARCaddword &MARCdelword &char_decode + &FindDuplicate ); sub authoritysearch { @@ -844,6 +845,46 @@ sub nsb_clean { return($string) ; } +sub FindDuplicate { + my ($record,$authtypecode)=@_; + my $dbh = C4::Context->dbh; + + warn "".$record->as_formatted; + # search duplicate on ISBN, easy and fast... + my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?"); + $sth->execute($authtypecode); + my ($auth_tag_to_report) = $sth->fetchrow; + $sth->finish; + # a more complex search : 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"; + if ($record->fields($auth_tag_to_report)) { + my $sth = $dbh->prepare("select tagfield,tagsubfield from auth_subfield_structure where tagfield=? and authtypecode=? and tab >= 0"); + $sth->execute($auth_tag_to_report,$authtypecode); + warn " Champ $auth_tag_to_report present"; + while (my ($tag,$subfield) = $sth->fetchrow){ + if ($record->field($tag)->subfields($subfield)) { + warn "tag :".$tag." subfield: $subfield value : $record->field($tag)->subfield($subfield)->as_formatted"; + push @tags, "'".$tag.$subfield."'"; + push @and_or, "and"; + push @excluding, ""; + push @operator, "contains"; + 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 "$nbresult => ".@$finalresult[0]->{authid},@$finalresult[0]->{summary}; + return @$finalresult[0]->{authid},@$finalresult[0]->{authid},@$finalresult[0]->{summary}; + } + # no result, returns nothing + return; +} + END { } # module clean-up code here (global destructor) =back @@ -858,6 +899,9 @@ Paul POULAIN paul.poulain@free.fr # $Id$ # $Log$ +# Revision 1.12 2005/04/05 09:58:48 hdl +# Adding double authority search before creating a new authority +# # Revision 1.11 2005/03/07 08:55:29 tipaul # synch'ing with 2.2 # diff --git a/authorities/authorities.pl b/authorities/authorities.pl index 76e008e725..e7209395e0 100755 --- a/authorities/authorities.pl +++ b/authorities/authorities.pl @@ -334,12 +334,30 @@ 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 ($duplicateauthnumber,$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 (!$duplicateauthnumber or $confirm_not_duplicate) { + # MARC::Record built => now, record in DB + if ($is_a_modif) { + AUTHmodauthority($dbh,$authid,$record,$authtypecode); + } else { + ($authid) = AUTHaddauthority($dbh,$record,$authid,$authtypecode); + } + # now, redirect to additem 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( + duplicateauthnumber => $duplicateauthnumber, + duplicateauthid => $duplicateauthid, + duplicateauthvalue => $duplicateauthvalue, + ); } - print $input->redirect("detail.pl?authid=$authid"); #------------------------------------------------------------------------------------------------------------------------------ } elsif ($op eq "addfield") { #------------------------------------------------------------------------------------------------------------------------------ diff --git a/koha-tmpl/intranet-tmpl/default/en/authorities/authorities.tmpl b/koha-tmpl/intranet-tmpl/default/en/authorities/authorities.tmpl index 4f142c3591..072b3849ee 100644 --- a/koha-tmpl/intranet-tmpl/default/en/authorities/authorities.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/authorities/authorities.tmpl @@ -19,6 +19,16 @@










+ +
+

Duplicate suspected with

+

You must either :

+ +
+

-- 2.39.5