1 package C4::AuthoritiesMarc;
2 # Copyright 2000-2002 Katipo Communications
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along with
16 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
17 # Suite 330, Boston, MA 02111-1307 USA
27 use vars qw($VERSION @ISA @EXPORT);
29 # set the version for version checking
36 &AUTHfind_authtypecode
51 &MARCaddword &MARCdelword
56 my ($dbh, $tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode) = @_;
57 # build the sql request. She will look like :
59 # from auth_subfield_table as m1, auth_subfield_table as m2
60 # where m1.authid=m2.authid and
61 # (m1.subfieldvalue like "Des%" and m2.subfieldvalue like "27%")
65 my @normal_and_or = ();
66 my @normal_operator = ();
67 my @normal_value = ();
68 # Extracts the NOT statements from the list of statements
69 for(my $i = 0 ; $i <= $#{$value} ; $i++)
71 if(@$operator[$i] eq "contains") # if operator is contains, splits the words in separate requests
73 foreach my $word (split(/ /, @$value[$i]))
75 unless (C4::Context->stopwords->{uc($word)}) { #it's NOT a stopword => use it. Otherwise, ignore
76 my $tag = substr(@$tags[$i],0,3);
77 my $subf = substr(@$tags[$i],3,1);
78 push @normal_tags, @$tags[$i];
79 push @normal_and_or, "and"; # assumes "foo" and "bar" if "foo bar" is entered
80 push @normal_operator, @$operator[$i];
81 push @normal_value, $word;
87 push @normal_tags, @$tags[$i];
88 push @normal_and_or, @$and_or[$i];
89 push @normal_operator, @$operator[$i];
90 push @normal_value, @$value[$i];
94 # Finds the basic results without the NOT requests
95 my ($sql_tables, $sql_where1, $sql_where2) = create_request($dbh,\@normal_tags, \@normal_and_or, \@normal_operator, \@normal_value);
100 $sth = $dbh->prepare("select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where2 and ($sql_where1)");
101 warn "Q2 : select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where2 and ($sql_where1)";
103 $sth = $dbh->prepare("select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where1");
104 warn "Q : select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where1";
106 $sth->execute($authtypecode);
108 while (my ($authid) = $sth->fetchrow) {
109 push @result,$authid;
112 # we have authid list. Now, loads summary from [offset] to [offset]+[length]
113 my $counter = $offset;
114 my @finalresult = ();
116 while (($counter <= $#result) && ($counter <= ($offset + $length))) {
117 # warn " HERE : $counter, $#result, $offset, $length";
118 # get MARC::Record of the authority
119 my $record = AUTHgetauthority($dbh,$result[$counter]);
120 # then build the summary
121 my $authtypecode = AUTHfind_authtypecode($dbh,$result[$counter]);
122 my $authref = getauthtype($authtypecode);
123 my $summary = $authref->{summary};
124 my @fields = $record->fields();
125 foreach my $field (@fields) {
126 my $tag = $field->tag();
129 my @subf = $field->subfields;
130 for my $i (0..$#subf) {
131 my $subfieldcode = $subf[$i][0];
132 my $subfieldvalue = $subf[$i][1];
133 my $tagsubf = $tag.$subfieldcode;
134 $summary =~ s/\[(.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue\[$1$tagsubf$2]$2$3/g;
138 $summary =~ s/\[(.*?)]//g;
139 $summary =~ s/\n/<br>/g;
141 # find biblio MARC field using this authtypecode (to jump to biblio)
142 my $authtypecode = AUTHfind_authtypecode($dbh,$result[$counter]);
143 my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
144 $sth->execute($authtypecode);
145 my $tags_using_authtype;
146 while (my ($tagfield) = $sth->fetchrow) {
147 # warn "TAG : $tagfield";
148 $tags_using_authtype.= $tagfield."9,";
150 chop $tags_using_authtype;
152 # then add a line for the template loop
154 $newline{summary} = $summary;
155 $newline{authid} = $result[$counter];
156 $newline{used} = &AUTHcount_usage($result[$counter]);
157 $newline{biblio_fields} = $tags_using_authtype;
159 push @finalresult, \%newline;
161 my $nbresults = $#result + 1;
162 return (\@finalresult, $nbresults);
165 # Creates the SQL Request
168 my ($dbh,$tags, $and_or, $operator, $value) = @_;
170 my $sql_tables; # will contain marc_subfield_table as m1,...
171 my $sql_where1; # will contain the "true" where
172 my $sql_where2 = "("; # will contain m1.authid=m2.authid
173 my $nb_active=0; # will contain the number of "active" entries. and entry is active is a value is provided.
174 my $nb_table=1; # will contain the number of table. ++ on each entry EXCEPT when an OR is provided.
177 for(my $i=0; $i<=@$value;$i++) {
181 if (@$operator[$i] eq "start") {
182 $sql_tables .= "auth_subfield_table as m$nb_table,";
183 $sql_where1 .= "(m1.subfieldvalue like ".$dbh->quote("@$value[$i]%");
185 $sql_where1 .=" and m1.tag+m1.subfieldcode in (@$tags[$i])";
188 } elsif (@$operator[$i] eq "contains") {
189 $sql_tables .= "auth_word as m$nb_table,";
190 $sql_where1 .= "(m1.word like ".$dbh->quote("@$value[$i]%");
192 $sql_where1 .=" and m1.tagsubfield in (@$tags[$i])";
197 $sql_tables .= "auth_subfield_table as m$nb_table,";
198 $sql_where1 .= "(m1.subfieldvalue @$operator[$i] ".$dbh->quote("@$value[$i]");
200 $sql_where1 .=" and m1.tag+m1.subfieldcode in (@$tags[$i])";
205 if (@$operator[$i] eq "start") {
207 $sql_tables .= "auth_subfield_table as m$nb_table,";
208 $sql_where1 .= "@$and_or[$i] (m$nb_table.subfieldvalue like ".$dbh->quote("@$value[$i]%");
210 $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldcode in (@$tags[$i])";
213 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
214 } elsif (@$operator[$i] eq "contains") {
215 if (@$and_or[$i] eq 'and') {
217 $sql_tables .= "auth_word as m$nb_table,";
218 $sql_where1 .= "@$and_or[$i] (m$nb_table.word like ".$dbh->quote("@$value[$i]%");
220 $sql_where1 .=" and m$nb_table.tagsubfield in(@$tags[$i])";
223 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
225 $sql_where1 .= "@$and_or[$i] (m$nb_table.word like ".$dbh->quote("@$value[$i]%");
227 $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldid in (@$tags[$i])";
230 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
234 $sql_tables .= "auth_subfield_table as m$nb_table,";
235 $sql_where1 .= "@$and_or[$i] (m$nb_table.subfieldvalue @$operator[$i] ".$dbh->quote(@$value[$i]);
237 $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldcode in (@$tags[$i])";
239 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
246 if($sql_where2 ne "(") # some datas added to sql_where2, processing
248 $sql_where2 = substr($sql_where2, 0, (length($sql_where2)-5)); # deletes the trailing ' and '
251 else # no sql_where2 statement, deleting '('
255 chop $sql_tables; # deletes the trailing ','
257 return ($sql_tables, $sql_where1, $sql_where2);
261 sub AUTHcount_usage {
263 my $dbh = C4::Context->dbh;
264 # find MARC fields using this authtype
265 my $authtypecode = AUTHfind_authtypecode($dbh,$authid);
266 my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
267 $sth->execute($authtypecode);
268 my $tags_using_authtype;
269 while (my ($tagfield) = $sth->fetchrow) {
270 # warn "TAG : $tagfield";
271 $tags_using_authtype.= "'".$tagfield."9',";
273 chop $tags_using_authtype;
274 $sth = $dbh->prepare("select count(*) from marc_subfield_table where concat(tag,subfieldcode) in ($tags_using_authtype) and subfieldvalue=?");
275 # warn "Q : select count(*) from marc_subfield_table where concat(tag,subfieldcode) in ($tags_using_authtype) and subfieldvalue=$authid";
276 $sth->execute($authid);
277 my ($result) = $sth->fetchrow;
278 # warn "Authority $authid TOTAL USED : $result";
282 # merging 2 authority entries. After a merge, the "from" can be deleted.
284 # my ($auth_merge_from,$auth_merge_to) = @_;
285 # my $dbh = C4::Context->dbh;
286 # # find MARC fields using this authtype
287 # my $authtypecode = AUTHfind_authtypecode($dbh,$authid);
289 # my $record_from = AUTHgetauthority($dbh,$auth_merge_from);
290 # my $record_to = AUTHgetauthority($dbh,$auth_merge_to);
291 # my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
292 # $sth->execute($authtypecode);
293 # my $tags_using_authtype;
294 # while (my ($tagfield) = $sth->fetchrow) {
295 # warn "TAG : $tagfield";
296 # $tags_using_authtype.= "'".$tagfield."9',";
298 # chop $tags_using_authtype;
299 # # now, find every biblio using this authority
300 # $sth = $dbh->prepare("select bibid,tag,tag_indicator,tagorder from marc_subfield_table where tag+subfieldid in ($tags_using_authtype) and subfieldvalue=?");
301 # $sth->execute($authid);
302 # # and delete entries before recreating them
303 # while (my ($bibid,$tag,$tag_indicator,$tagorder) = $sth->fetchrow) {
304 # &MARCdelsubfield($dbh,$bibid,$tag);
310 sub AUTHfind_authtypecode {
311 my ($dbh,$authid) = @_;
312 my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?");
313 $sth->execute($authid);
314 my ($authtypecode) = $sth->fetchrow;
315 return $authtypecode;
320 my ($dbh,$forlibrarian,$authtypecode)= @_;
321 $authtypecode="" unless $authtypecode;
323 my $libfield = ($forlibrarian eq 1)? 'liblibrarian' : 'libopac';
324 # check that framework exists
325 $sth=$dbh->prepare("select count(*) from auth_tag_structure where authtypecode=?");
326 $sth->execute($authtypecode);
327 my ($total) = $sth->fetchrow;
328 $authtypecode="" unless ($total >0);
329 $sth=$dbh->prepare("select tagfield,$libfield as lib,mandatory,repeatable from auth_tag_structure where authtypecode=? order by tagfield");
330 $sth->execute($authtypecode);
331 my ($lib,$tag,$res,$tab,$mandatory,$repeatable);
332 while ( ($tag,$lib,$mandatory,$repeatable) = $sth->fetchrow) {
333 $res->{$tag}->{lib}=$lib;
334 $res->{$tab}->{tab}=""; # XXX
335 $res->{$tag}->{mandatory}=$mandatory;
336 $res->{$tag}->{repeatable}=$repeatable;
339 $sth=$dbh->prepare("select tagfield,tagsubfield,$libfield as lib,tab, mandatory, repeatable,authorised_value,value_builder,seealso from auth_subfield_structure where authtypecode=? order by tagfield,tagsubfield");
340 $sth->execute($authtypecode);
343 my $authorised_value;
344 my $thesaurus_category;
350 while ( ($tag, $subfield, $lib, $tab, $mandatory, $repeatable,$authorised_value,$value_builder,$seealso) = $sth->fetchrow) {
351 $res->{$tag}->{$subfield}->{lib}=$lib;
352 $res->{$tag}->{$subfield}->{tab}=$tab;
353 $res->{$tag}->{$subfield}->{mandatory}=$mandatory;
354 $res->{$tag}->{$subfield}->{repeatable}=$repeatable;
355 $res->{$tag}->{$subfield}->{authorised_value}=$authorised_value;
356 $res->{$tag}->{$subfield}->{thesaurus_category}=$thesaurus_category;
357 $res->{$tag}->{$subfield}->{value_builder}=$value_builder;
358 $res->{$tag}->{$subfield}->{seealso}=$seealso;
359 $res->{$tag}->{$subfield}->{hidden}=$hidden;
360 $res->{$tag}->{$subfield}->{isurl}=$isurl;
365 sub AUTHaddauthority {
366 # pass the MARC::Record to this function, and it will create the records in the marc tables
367 my ($dbh,$record,$authid,$authtypecode) = @_;
368 my @fields=$record->fields();
369 # warn "IN AUTHaddauthority $authid => ".$record->as_formatted;
370 # adding main table, and retrieving authid
371 # if authid is sent, then it's not a true add, it's only a re-add, after a delete (ie, a mod)
372 # if authid empty => true add, find a new authid number
374 $dbh->do("lock tables auth_header WRITE,auth_subfield_table WRITE, auth_word WRITE, stopwords READ");
375 my $sth=$dbh->prepare("insert into auth_header (datecreated,authtypecode) values (now(),?)");
376 $sth->execute($authtypecode);
377 $sth=$dbh->prepare("select max(authid) from auth_header");
379 ($authid)=$sth->fetchrow;
383 # now, add subfields...
384 foreach my $field (@fields) {
386 if ($field->tag() <10) {
387 &AUTHaddsubfield($dbh,$authid,
396 my @subfields=$field->subfields();
397 foreach my $subfieldcount (0..$#subfields) {
398 &AUTHaddsubfield($dbh,$authid,
400 $field->indicator(1).$field->indicator(2),
402 $subfields[$subfieldcount][0],
404 $subfields[$subfieldcount][1]
409 $dbh->do("unlock tables");
414 sub AUTHaddsubfield {
415 # Add a new subfield to a tag into the DB.
416 my ($dbh,$authid,$tagid,$tag_indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalues) = @_;
417 # if not value, end of job, we do nothing
418 if (length($subfieldvalues) ==0) {
421 if (not($subfieldcode)) {
424 my @subfieldvalues = split /\|/,$subfieldvalues;
425 foreach my $subfieldvalue (@subfieldvalues) {
426 my $sth=$dbh->prepare("insert into auth_subfield_table (authid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)");
427 $sth->execute($authid,(sprintf "%03s",$tagid),$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue);
429 warn "ERROR ==> insert into auth_subfield_table (authid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($authid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
431 &AUTHaddword($dbh,$authid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
435 sub AUTHgetauthority {
436 # Returns MARC::Record of the biblio passed in parameter.
437 my ($dbh,$authid)=@_;
438 my $record = MARC::Record->new();
439 #---- TODO : the leader is missing
440 $record->leader(' ');
441 my $sth=$dbh->prepare("select authid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue
442 from auth_subfield_table
443 where authid=? order by tag,tagorder,subfieldcode
445 $sth->execute($authid);
449 my $field; # for >=10 tags
450 my $prevvalue; # for <10 tags
451 while (my $row=$sth->fetchrow_hashref) {
452 if ($row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag) {
455 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue) unless $prevtag eq "XXX"; # ignore the 1st loop
457 $record->add_fields($field) unless $prevtag eq "XXX";
460 $prevtagorder=$row->{tagorder};
461 $prevtag = $row->{tag};
462 $previndicator=$row->{tag_indicator};
463 if ($row->{tag}<10) {
464 $prevvalue = $row->{subfieldvalue};
466 $field = MARC::Field->new((sprintf "%03s",$prevtag), substr($row->{tag_indicator}.' ',0,1), substr($row->{tag_indicator}.' ',1,1), $row->{'subfieldcode'}, $row->{'subfieldvalue'} );
469 if ($row->{tag} <10) {
470 $record->add_fields((sprintf "%03s",$row->{tag}), $row->{'subfieldvalue'});
472 $field->add_subfields($row->{'subfieldcode'}, $row->{'subfieldvalue'} );
474 $prevtag= $row->{tag};
475 $previndicator=$row->{tag_indicator};
478 # the last has not been included inside the loop... do it now !
479 if ($prevtag ne "XXX") { # check that we have found something. Otherwise, prevtag is still XXX and we
480 # must return an empty record, not make MARC::Record fail because we try to
481 # create a record with XXX as field :-(
483 $record->add_fields($prevtag,$prevvalue);
485 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
486 $record->add_fields($field);
492 sub AUTHgetauth_type {
493 my ($authtypecode) = @_;
494 my $dbh=C4::Context->dbh;
495 my $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
496 $sth->execute($authtypecode);
497 return $sth->fetchrow_hashref;
499 sub AUTHmodauthority {
500 my ($dbh,$authid,$record,$delete)=@_;
501 my $oldrecord=&AUTHgetauthority($dbh,$authid);
502 if ($oldrecord eq $record) {
505 # 1st delete the authority,
507 &AUTHdelauthority($dbh,$authid,1);
508 &AUTHaddauthority($dbh,$record,$authid);
509 # FIXME : modify the authority in biblio too.
512 sub AUTHdelauthority {
513 my ($dbh,$authid,$keep_biblio) = @_;
514 # if the keep_biblio is set to 1, then authority entries in biblio are preserved.
515 # This flag is set when the delauthority is called by modauthority
516 # due to a too complex structure of MARC (repeatable fields and subfields),
517 # the best solution for a modif is to delete / recreate the record.
519 my $record = AUTHgetauthority($dbh,$authid);
520 $dbh->do("delete from auth_header where authid=$authid");
521 $dbh->do("delete from auth_subfield_table where authid=$authid");
522 $dbh->do("delete from auth_word where authid=$authid");
523 # FIXME : delete or not in biblio tables (depending on $keep_biblio flag)
526 sub AUTHmodsubfield {
527 # Subroutine changes a subfield value given a subfieldid.
528 my ($dbh, $subfieldid, $subfieldvalue )=@_;
529 $dbh->do("lock tables auth_subfield_table WRITE");
530 my $sth=$dbh->prepare("update auth_subfield_table set subfieldvalue=? where subfieldid=?");
531 $sth->execute($subfieldvalue, $subfieldid);
532 $dbh->do("unlock tables");
534 $sth=$dbh->prepare("select authid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from auth_subfield_table where subfieldid=?");
535 $sth->execute($subfieldid);
536 my ($authid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
538 &AUTHdelword($dbh,$authid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
539 &AUTHaddword($dbh,$authid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
540 return($subfieldid, $subfieldvalue);
543 sub AUTHfindsubfield {
544 my ($dbh,$authid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
548 my $query="select subfieldid from auth_subfield_table where authid=? and tag=? and subfieldcode=?";
549 my @bind_values = ($authid,$tag, $subfieldcode);
550 if ($subfieldvalue) {
551 $query .= " and subfieldvalue=?";
552 push(@bind_values,$subfieldvalue);
554 if ($subfieldorder<1) {
557 $query .= " and subfieldorder=?";
558 push(@bind_values,$subfieldorder);
560 my $sti=$dbh->prepare($query);
561 $sti->execute(@bind_values);
562 while (($subfieldid) = $sti->fetchrow) {
564 $lastsubfieldid=$subfieldid;
566 if ($resultcounter>1) {
567 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
568 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
571 return $lastsubfieldid;
575 sub AUTHfindsubfieldid {
576 my ($dbh,$authid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
577 my $sth=$dbh->prepare("select subfieldid from auth_subfield_table
578 where authid=? and tag=? and tagorder=?
579 and subfieldcode=? and subfieldorder=?");
580 $sth->execute($authid,$tag,$tagorder,$subfield,$subfieldorder);
581 my ($res) = $sth->fetchrow;
583 $sth=$dbh->prepare("select subfieldid from auth_subfield_table
584 where authid=? and tag=? and tagorder=?
585 and subfieldcode=?");
586 $sth->execute($authid,$tag,$tagorder,$subfield);
587 ($res) = $sth->fetchrow;
592 sub AUTHfind_authtypecode {
593 my ($dbh,$authid) = @_;
594 my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?");
595 $sth->execute($authid);
596 my ($authtypecode) = $sth->fetchrow;
597 return $authtypecode;
600 sub AUTHdelsubfield {
601 # delete a subfield for $authid / tag / tagorder / subfield / subfieldorder
602 my ($dbh,$authid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
603 $dbh->do("delete from auth_subfield_table where authid='$authid' and
604 tag='$tag' and tagorder='$tagorder'
605 and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
610 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
612 my $record = MARC::Record->new();
613 # my %subfieldlist=();
614 my $prevvalue; # if tag <10
615 my $field; # if tag >=10
616 for (my $i=0; $i< @$rtags; $i++) {
617 # rebuild MARC::Record
618 if (@$rtags[$i] ne $prevtag) {
621 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
625 $record->add_fields($field);
628 $indicators{@$rtags[$i]}.=' ';
629 if (@$rtags[$i] <10) {
630 $prevvalue= @$rvalues[$i];
632 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
634 $prevtag = @$rtags[$i];
636 if (@$rtags[$i] <10) {
637 $prevvalue=@$rvalues[$i];
640 $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
643 $prevtag= @$rtags[$i];
646 # the last has not been included inside the loop... do it now !
647 $record->add_fields($field);
648 # warn $record->as_formatted;
653 # split a subfield string and adds it into the word table.
655 my ($dbh,$authid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
656 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\})/ /g;
657 my @words = split / /,$sentence;
658 my $stopwords= C4::Context->stopwords;
659 my $sth=$dbh->prepare("insert into auth_word (authid, tagsubfield, tagorder, subfieldorder, word, sndx_word)
660 values (?,concat(?,?),?,?,?,soundex(?))");
661 foreach my $word (@words) {
662 # we record only words longer than 2 car and not in stopwords hash
663 if (length($word)>2 and !($stopwords->{uc($word)})) {
664 $sth->execute($authid,$tag,$subfieldid,$tagorder,$subfieldorder,$word,$word);
666 warn "ERROR ==> insert into auth_word (authid, tagsubfield, tagorder, subfieldorder, word, sndx_word) values ($authid,concat($tag,$subfieldid),$tagorder,$subfieldorder,$word,soundex($word))\n";
673 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
674 my ($dbh,$authid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
675 my $sth=$dbh->prepare("delete from auth_word where authid=? and tagsubfield=concat(?,?) and tagorder=? and subfieldorder=?");
676 $sth->execute($authid,$tag,$subfield,$tagorder,$subfieldorder);
680 # converts ISO 5426 coded string to ISO 8859-1
681 # sloppy code : should be improved in next issue
682 my ($string,$encoding) = @_ ;
684 # $encoding = C4::Context->preference("marcflavour") unless $encoding;
685 if ($encoding eq "UNIMARC") {
747 # this handles non-sorting blocks (if implementation requires this)
748 $string = nsb_clean($_) ;
749 } elsif ($encoding eq "USMARC" || $encoding eq "MARC21") {
802 # this handles non-sorting blocks (if implementation requires this)
803 $string = nsb_clean($_) ;
810 my $NSB = '\x88' ; # NSB : begin Non Sorting Block
811 my $NSE = '\x89' ; # NSE : Non Sorting Block end
812 # handles non sorting blocks
816 s/[ ]{0,1}$NSE/) /gm ;
821 END { } # module clean-up code here (global destructor)
827 Koha Developement team <info@koha.org>
829 Paul POULAIN paul.poulain@free.fr
835 # Revision 1.6 2004/08/18 16:00:24 tipaul
836 # fixes for authorities management
838 # Revision 1.5 2004/07/05 13:37:22 doxulting
839 # First step for working authorities
841 # Revision 1.4 2004/06/22 11:35:37 tipaul
842 # removing % at the beginning of a string to avoid loooonnnngggg searchs
844 # Revision 1.3 2004/06/17 08:02:13 tipaul
845 # merging tag & subfield in auth_word for better perfs
847 # Revision 1.2 2004/06/10 08:29:01 tipaul
848 # MARC authority management (continued)
850 # Revision 1.1 2004/06/07 07:35:01 tipaul
851 # MARC authority management package