Adding KohaAdminEmailAdress
[koha.git] / C4 / AuthoritiesMarc.pm
1 package C4::AuthoritiesMarc;
2 # Copyright 2000-2002 Katipo Communications
3 #
4 # This file is part of Koha.
5 #
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
9 # version.
10 #
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.
14 #
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
18
19 use strict;
20 require Exporter;
21 use C4::Context;
22 use C4::Koha;
23 use MARC::Record;
24 use C4::Biblio;
25 use C4::Search;
26
27 use vars qw($VERSION @ISA @EXPORT);
28
29 # set the version for version checking
30 $VERSION = 0.01;
31
32 @ISA = qw(Exporter);
33 @EXPORT = qw(
34     &GetTagsLabels
35     &GetAuthType
36     &GetAuthTypeCode
37     &GetAuthMARCFromKohaField 
38     &AUTHhtml2marc
39
40     &AddAuthority
41     &ModAuthority
42     &DelAuthority
43     &GetAuthority
44     &GetAuthorityXML
45     
46     &CountUsage
47     &CountUsageChildren
48     &SearchAuthorities
49     
50     &BuildSummary
51     &BuildUnimarcHierarchies
52     &BuildUnimarcHierarchy
53     
54     &merge
55     &FindDuplicateAuthority
56  );
57
58 =head2 GetAuthMARCFromKohaField 
59
60 =over 4
61
62 ( $tag, $subfield ) = &GetAuthMARCFromKohaField ($kohafield,$authtypecode);
63 returns tag and subfield linked to kohafield
64
65 Comment :
66 Suppose Kohafield is only linked to ONE subfield
67 =back
68
69 =cut
70 sub GetAuthMARCFromKohaField {
71 #AUTHfind_marc_from_kohafield
72   my ( $kohafield,$authtypecode ) = @_;
73   my $dbh=C4::Context->dbh;
74   return 0, 0 unless $kohafield;
75   $authtypecode="" unless $authtypecode;
76   my $marcfromkohafield;
77   my $sth = $dbh->prepare("select tagfield,tagsubfield from auth_subfield_structure where kohafield= ? and authtypecode=? ");
78   $sth->execute($kohafield,$authtypecode);
79   my ($tagfield,$tagsubfield) = $sth->fetchrow;
80     
81   return  ($tagfield,$tagsubfield);
82 }
83
84 =head2 SearchAuthorities 
85
86 =over 4
87
88 (\@finalresult, $nbresults)= &SearchAuthorities($tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby)
89 returns ref to array result and count of results returned
90
91 =back
92
93 =cut
94 sub SearchAuthorities {
95     my ($tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby) = @_;
96 #     warn "CALL : $tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby";
97     my $dbh=C4::Context->dbh;
98     if (C4::Context->preference('NoZebra')) {
99     
100         #
101         # build the query
102         #
103         my $query;
104         my @auths=split / /,$authtypecode ;
105         foreach my  $auth (@auths){
106             $query .="AND auth_type= $auth ";
107         }
108         $query =~ s/^AND //;
109         my $dosearch;
110         for(my $i = 0 ; $i <= $#{$value} ; $i++)
111         {
112             if (@$value[$i]){
113                 if (@$tags[$i] eq "mainmainentry") {
114                     $query .=" AND mainmainentry";
115                 }elsif (@$tags[$i] eq "mainentry") {
116                     $query .=" AND mainentry";
117                 } else {
118                     $query .=" AND ";
119                 }
120                 if (@$operator[$i] eq 'is') {
121                     $query.=(@$tags[$i]?"=":""). '"'.@$value[$i].'"';
122                 }elsif (@$operator[$i] eq "="){
123                     $query.=(@$tags[$i]?"=":""). '"'.@$value[$i].'"';
124                 }elsif (@$operator[$i] eq "start"){
125                     $query.=(@$tags[$i]?"=":"").'"'.@$value[$i].'%"';
126                 } else {
127                     $query.=(@$tags[$i]?"=":"").'"'.@$value[$i].'%"';
128                 }
129                 $dosearch=1;
130             }#if value
131         }
132         #
133         # do the query (if we had some search term
134         #
135         if ($dosearch) {
136 #             warn "QUERY : $query";
137             my $result = C4::Search::NZanalyse($query,'authorityserver');
138 #             warn "result : $result";
139             my %result;
140             foreach (split /;/,$result) {
141                 my ($authid,$title) = split /,/,$_;
142                 # hint : the result is sorted by title.biblionumber because we can have X biblios with the same title
143                 # and we don't want to get only 1 result for each of them !!!
144                 # hint & speed improvement : we can order without reading the record
145                 # so order, and read records only for the requested page !
146                 $result{$title.$authid}=$authid;
147             }
148             # sort the hash and return the same structure as GetRecords (Zebra querying)
149             my @finalresult = ();
150             my $numbers=0;
151             if ($sortby eq 'HeadingDsc') { # sort by mainmainentry desc
152                 foreach my $key (sort {$b cmp $a} (keys %result)) {
153                     push @finalresult, $result{$key};
154 #                     warn "push..."$#finalresult;
155                     $numbers++;
156                 }
157             } else { # sort by mainmainentry ASC
158                 foreach my $key (sort (keys %result)) {
159                     push @finalresult, $result{$key};
160 #                     warn "push..."$#finalresult;
161                     $numbers++;
162                 }
163             }
164             # limit the $results_per_page to result size if it's more
165             $length = $numbers-1 if $numbers < $length;
166             # for the requested page, replace authid by the complete record
167             # speed improvement : avoid reading too much things
168             for (my $counter=$offset;$counter<=$offset+$length;$counter++) {
169 #                 $finalresult[$counter] = GetAuthority($finalresult[$counter])->as_usmarc;
170                 my $separator=C4::Context->preference('authoritysep');
171                 my $authrecord = MARC::File::USMARC::decode(GetAuthority($finalresult[$counter])->as_usmarc);
172                 my $authid=$authrecord->field('001')->data(); 
173                 my $summary=BuildSummary($authrecord,$authid,$authtypecode);
174                 my $query_auth_tag = "SELECT auth_tag_to_report FROM auth_types WHERE authtypecode=?";
175                 my $sth = $dbh->prepare($query_auth_tag);
176                 $sth->execute($authtypecode);
177                 my $auth_tag_to_report = $sth->fetchrow;
178                 my %newline;
179                 $newline{used}=CountUsage($authid);
180                 $newline{summary} = $summary;
181                 $newline{authid} = $authid;
182                 $newline{even} = $counter % 2;
183                 $finalresult[$counter]= \%newline;
184             }
185             return (\@finalresult, $numbers);
186         } else {
187             return;
188         }
189     } else {
190         my $query;
191         my $attr;
192             # the marclist may contain "mainentry". In this case, search the tag_to_report, that depends on
193             # the authtypecode. Then, search on $a of this tag_to_report
194             # also store main entry MARC tag, to extract it at end of search
195         my $mainentrytag;
196         ##first set the authtype search and may be multiple authorities
197         my $n=0;
198         my @authtypecode;
199         my @auths=split / /,$authtypecode ;
200         foreach my  $auth (@auths){
201             $query .=" \@attr 1=Authority/format-id \@attr 5=100 ".$auth; ##No truncation on authtype
202             push @authtypecode ,$auth;
203             $n++;
204         }
205         if ($n>1){
206             $query= "\@or ".$query;
207         }
208         
209         my $dosearch;
210         my $and;
211         my $q2;
212         for(my $i = 0 ; $i <= $#{$value} ; $i++)
213         {
214             if (@$value[$i]){
215             ##If mainentry search $a tag
216                 if (@$tags[$i] eq "mainmainentry") {
217                 $attr =" \@attr 1=Heading ";
218                 }elsif (@$tags[$i] eq "mainentry") {
219                 $attr =" \@attr 1=Heading-Entity ";
220                 }else{
221                 $attr =" \@attr 1=Any ";
222                 }
223                 if (@$operator[$i] eq 'is') {
224                     $attr.=" \@attr 4=1  \@attr 5=100 ";##Phrase, No truncation,all of subfield field must match
225                 }elsif (@$operator[$i] eq "="){
226                     $attr.=" \@attr 4=107 ";           #Number Exact match
227                 }elsif (@$operator[$i] eq "start"){
228                     $attr.=" \@attr 4=1 \@attr 5=1 ";#Phrase, Right truncated
229                 } else {
230                     $attr .=" \@attr 5=1 \@attr 4=6 ";## Word list, right truncated, anywhere
231                 }
232                 $and .=" \@and " ;
233                 $attr =$attr."\"".@$value[$i]."\"";
234                 $q2 .=$attr;
235             $dosearch=1;
236             }#if value
237         }
238         ##Add how many queries generated
239         $query= $and.$query.$q2;
240         ## Adding order
241         $query=' @or  @attr 7=1 @attr 1=Heading 0 @or  @attr 7=1 @attr 1=Heading-Entity 1'.$query if ($sortby eq "HeadingAsc");
242         $query=' @or  @attr 7=2 @attr 1=Heading 0 @or  @attr 7=1 @attr 1=Heading-Entity 1'.$query if ($sortby eq "HeadingDsc");
243         
244         $offset=0 unless $offset;
245         my $counter = $offset;
246         $length=10 unless $length;
247         my @oAuth;
248         my $i;
249         $oAuth[0]=C4::Context->Zconn("authorityserver" , 1);
250         my $Anewq= new ZOOM::Query::PQF($query,$oAuth[0]);
251         my $oAResult;
252         $oAResult= $oAuth[0]->search($Anewq) ; 
253         while (($i = ZOOM::event(\@oAuth)) != 0) {
254             my $ev = $oAuth[$i-1]->last_event();
255             last if $ev == ZOOM::Event::ZEND;
256         }
257         my($error, $errmsg, $addinfo, $diagset) = $oAuth[0]->error_x();
258         if ($error) {
259             warn  "oAuth error: $errmsg ($error) $addinfo $diagset\n";
260             goto NOLUCK;
261         }
262         
263         my $nbresults;
264         $nbresults=$oAResult->size();
265         my $nremains=$nbresults;    
266         my @result = ();
267         my @finalresult = ();
268         
269         if ($nbresults>0){
270         
271         ##Find authid and linkid fields
272         ##we may be searching multiple authoritytypes.
273         ## FIXME this assumes that all authid and linkid fields are the same for all authority types
274         # my ($authidfield,$authidsubfield)=GetAuthMARCFromKohaField($dbh,"auth_header.authid",$authtypecode[0]);
275         # my ($linkidfield,$linkidsubfield)=GetAuthMARCFromKohaField($dbh,"auth_header.linkid",$authtypecode[0]);
276             while (($counter < $nbresults) && ($counter < ($offset + $length))) {
277             
278             ##Here we have to extract MARC record and $authid from ZEBRA AUTHORITIES
279             my $rec=$oAResult->record($counter);
280             my $marcdata=$rec->raw();
281             my $authrecord;
282             my $separator=C4::Context->preference('authoritysep');
283             $authrecord = MARC::File::USMARC::decode($marcdata);
284             my $authid=$authrecord->field('001')->data(); 
285             my $summary=BuildSummary($authrecord,$authid,$authtypecode);
286             my $query_auth_tag = "SELECT auth_tag_to_report FROM auth_types WHERE authtypecode=?";
287             my $sth = $dbh->prepare($query_auth_tag);
288             $sth->execute($authtypecode);
289             my $auth_tag_to_report = $sth->fetchrow;
290             my %newline;
291             $newline{summary} = $summary;
292             $newline{authid} = $authid;
293             $newline{even} = $counter % 2;
294             $counter++;
295             push @finalresult, \%newline;
296             }## while counter
297         ###
298         for (my $z=0; $z<@finalresult; $z++){
299                 my  $count=CountUsage($finalresult[$z]{authid});
300                 $finalresult[$z]{used}=$count;
301         }# all $z's
302         
303         }## if nbresult
304         NOLUCK:
305         # $oAResult->destroy();
306         # $oAuth[0]->destroy();
307         
308         return (\@finalresult, $nbresults);
309     }
310 }
311
312 =head2 CountUsage 
313
314 =over 4
315
316 $count= &CountUsage($authid)
317 counts Usage of Authid in bibliorecords. 
318
319 =back
320
321 =cut
322 sub CountUsage {
323     my ($authid) = @_;
324     if (C4::Context->preference('NoZebra')) {
325         # Read the index Koha-Auth-Number for this authid and count the lines
326         my $result = C4::Search::NZanalyse("an=$authid");
327         return scalar split /;/,$result;
328     } else {
329         ### ZOOM search here
330         my $oConnection=C4::Context->Zconn("biblioserver",1);
331         my $query;
332         $query= "an=".$authid;
333         my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
334         my $result;
335         while ((my $i = ZOOM::event([ $oConnection ])) != 0) {
336             my $ev = $oConnection->last_event();
337             if ($ev == ZOOM::Event::ZEND) {
338                 $result = $oResult->size();
339             }
340         }
341         return ($result);
342     }
343 }
344
345 =head2 CountUsageChildren 
346
347 =over 4
348
349 $count= &CountUsageChildren($authid)
350 counts Usage of narrower terms of Authid in bibliorecords.
351
352 =back
353
354 =cut
355 sub CountUsageChildren {
356   my ($authid) = @_;
357 }
358
359 =head2 GetAuthTypeCode
360
361 =over 4
362
363 $authtypecode= &GetAuthTypeCode($authid)
364 returns authtypecode of an authid
365
366 =back
367
368 =cut
369 sub GetAuthTypeCode {
370 #AUTHfind_authtypecode
371   my ($authid) = @_;
372   my $dbh=C4::Context->dbh;
373   my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?");
374   $sth->execute($authid);
375   my ($authtypecode) = $sth->fetchrow;
376   return $authtypecode;
377 }
378  
379 =head2 GetTagsLabels
380
381 =over 4
382
383 $tagslabel= &GetTagsLabels($forlibrarian,$authtypecode)
384 returns a ref to hashref of authorities tag and subfield structure.
385
386 tagslabel usage : 
387 $tagslabel->{$tag}->{$subfield}->{'attribute'}
388 where attribute takes values in :
389   lib
390   tab
391   mandatory
392   repeatable
393   authorised_value
394   authtypecode
395   value_builder
396   kohafield
397   seealso
398   hidden
399   isurl
400   link
401
402 =back
403
404 =cut
405 sub GetTagsLabels {
406   my ($forlibrarian,$authtypecode)= @_;
407   my $dbh=C4::Context->dbh;
408   $authtypecode="" unless $authtypecode;
409   my $sth;
410   my $libfield = ($forlibrarian eq 1)? 'liblibrarian' : 'libopac';
411
412
413   # check that authority exists
414   $sth=$dbh->prepare("select count(*) from auth_tag_structure where authtypecode=?");
415   $sth->execute($authtypecode);
416   my ($total) = $sth->fetchrow;
417   $authtypecode="" unless ($total >0);
418   $sth= $dbh->prepare(
419 "SELECT tagfield,liblibrarian,libopac,mandatory,repeatable 
420  FROM auth_tag_structure 
421  WHERE authtypecode=? 
422  ORDER BY tagfield"
423     );
424
425   $sth->execute($authtypecode);
426   my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable );
427
428   while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable ) = $sth->fetchrow ) {
429         $res->{$tag}->{lib}        = ($forlibrarian or !$libopac)?$liblibrarian:$libopac;
430         $res->{$tag}->{tab}        = " ";            # XXX
431         $res->{$tag}->{mandatory}  = $mandatory;
432         $res->{$tag}->{repeatable} = $repeatable;
433   }
434   $sth=      $dbh->prepare(
435 "SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl 
436 FROM auth_subfield_structure 
437 WHERE authtypecode=? 
438 ORDER BY tagfield,tagsubfield"
439     );
440     $sth->execute($authtypecode);
441
442     my $subfield;
443     my $authorised_value;
444     my $value_builder;
445     my $kohafield;
446     my $seealso;
447     my $hidden;
448     my $isurl;
449     my $link;
450
451     while (
452         ( $tag,         $subfield,   $liblibrarian,   , $libopac,      $tab,
453         $mandatory,     $repeatable, $authorised_value, $authtypecode,
454         $value_builder, $kohafield,  $seealso,          $hidden,
455         $isurl,            $link )
456         = $sth->fetchrow
457       )
458     {
459         $res->{$tag}->{$subfield}->{lib}              = ($forlibrarian or !$libopac)?$liblibrarian:$libopac;
460         $res->{$tag}->{$subfield}->{tab}              = $tab;
461         $res->{$tag}->{$subfield}->{mandatory}        = $mandatory;
462         $res->{$tag}->{$subfield}->{repeatable}       = $repeatable;
463         $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
464         $res->{$tag}->{$subfield}->{authtypecode}     = $authtypecode;
465         $res->{$tag}->{$subfield}->{value_builder}    = $value_builder;
466         $res->{$tag}->{$subfield}->{kohafield}        = $kohafield;
467         $res->{$tag}->{$subfield}->{seealso}          = $seealso;
468         $res->{$tag}->{$subfield}->{hidden}           = $hidden;
469         $res->{$tag}->{$subfield}->{isurl}            = $isurl;
470         $res->{$tag}->{$subfield}->{link}            = $link;
471     }
472     return $res;
473 }
474
475 =head2 AddAuthority
476
477 =over 4
478
479 $authid= &AddAuthority($record, $authid,$authtypecode)
480 returns authid of the newly created authority
481
482 Either Create Or Modify existing authority.
483
484 =back
485
486 =cut
487 sub AddAuthority {
488 # pass the MARC::Record to this function, and it will create the records in the authority table
489   my ($record,$authid,$authtypecode) = @_;
490   my $dbh=C4::Context->dbh;
491   my $leader='         a              ';##Fixme correct leader as this one just adds utf8 to MARC21
492
493 # if authid empty => true add, find a new authid number
494   if (!$authid) {
495     my $sth=$dbh->prepare("select max(authid) from auth_header");
496     $sth->execute;
497     ($authid)=$sth->fetchrow;
498     $authid=$authid+1;
499   ##Insert the recordID in MARC record 
500   ##Both authid and authtypecode is expected to be in the same field. Modify if other requirements arise
501     $record->add_fields('001',$authid) unless $record->field('001');
502     $record->add_fields('152','','','b'=>$authtypecode) unless $record->field('152');
503 #     warn $record->as_formatted;
504     $dbh->do("lock tables auth_header WRITE");
505     $sth=$dbh->prepare("insert into auth_header (authid,datecreated,authtypecode,marc,marcxml) values (?,now(),?,?,?)");
506     $sth->execute($authid,$authtypecode,$record->as_usmarc,$record->as_xml_record);
507     $sth->finish;
508   }else{
509       $record->add_fields('001',$authid) unless ($record->field('001'));
510       $record->add_fields('100',$authid) unless ($record->field('100'));
511       $record->add_fields('152','','','b'=>$authtypecode) unless ($record->field('152'));
512       $dbh->do("lock tables auth_header WRITE");
513       my $sth=$dbh->prepare("update auth_header set marc=?,marcxml=? where authid=?");
514       $sth->execute($record->as_usmarc,$record->as_xml_record,$authid);
515       $sth->finish;
516   }
517   $dbh->do("unlock tables");
518   ModZebra($authid,'specialUpdate',"authorityserver",$record);
519   return ($authid);
520 }
521
522
523 =head2 DelAuthority
524
525 =over 4
526
527 $authid= &DelAuthority($authid)
528 Deletes $authid
529
530 =back
531
532 =cut
533
534
535 sub DelAuthority {
536     my ($authid) = @_;
537     my $dbh=C4::Context->dbh;
538
539     ModZebra($authid,"recordDelete","authorityserver",GetAuthority($authid));
540     $dbh->do("delete from auth_header where authid=$authid") ;
541
542 }
543
544 sub ModAuthority {
545   my ($authid,$record,$authtypecode,$merge)=@_;
546   my $dbh=C4::Context->dbh;
547 #   my ($oldrecord)=&GetAuthority($authid);
548 #   if ($oldrecord eq $record) {
549 #       return;
550 #   }
551 #   my $sth=$dbh->prepare("update auth_header set marc=?,marcxml=? where authid=?");
552   #Now rewrite the $record to table with an add
553   $authid=AddAuthority($record,$authid,$authtypecode);
554
555 ### If a library thinks that updating all biblios is a long process and wishes to leave that to a cron job to use merge_authotities.p
556 ### they should have a system preference "dontmerge=1" otherwise by default biblios will be updated
557 ### the $merge flag is now depreceated and will be removed at code cleaning
558   if (C4::Context->preference('dontmerge') ){
559   # save the file in localfile/modified_authorities
560       my $cgidir = C4::Context->intranetdir ."/cgi-bin";
561       unless (opendir(DIR,"$cgidir")) {
562               $cgidir = C4::Context->intranetdir."/";
563       }
564   
565       my $filename = $cgidir."/localfile/modified_authorities/$authid.authid";
566       open AUTH, "> $filename";
567       print AUTH $authid;
568       close AUTH;
569   } else {
570 #        &merge($authid,$record,$authid,$record);
571   }
572   return $authid;
573 }
574
575 =head2 GetAuthorityXML 
576
577 =over 4
578
579 $marcxml= &GetAuthorityXML( $authid)
580 returns xml form of record $authid
581
582 =back
583
584 =cut
585 sub GetAuthorityXML {
586   # Returns MARC::XML of the authority passed in parameter.
587   my ( $authid ) = @_;
588   my $dbh=C4::Context->dbh;
589   my $sth =
590       $dbh->prepare("select marcxml from auth_header where authid=? "  );
591   $sth->execute($authid);
592   my ($marcxml)=$sth->fetchrow;
593   return $marcxml;
594
595 }
596
597 =head2 GetAuthority 
598
599 =over 4
600
601 $record= &GetAuthority( $authid)
602 Returns MARC::Record of the authority passed in parameter.
603
604 =back
605
606 =cut
607 sub GetAuthority {
608     my ($authid)=@_;
609     my $dbh=C4::Context->dbh;
610     my $sth=$dbh->prepare("select marcxml from auth_header where authid=?");
611     $sth->execute($authid);
612     my ($marcxml) = $sth->fetchrow;
613     my $record=MARC::Record->new_from_xml($marcxml,'UTF-8',(C4::Context->preference("marcflavour") eq "UNIMARC"?"UNIMARCAUTH":C4::Context->preference("marcflavour")));
614     $record->encoding('UTF-8');
615     return ($record);
616 }
617
618 =head2 GetAuthType 
619
620 =over 4
621
622 $result= &GetAuthType( $authtypecode)
623 If $authtypecode is not "" then 
624   Returns hashref to authtypecode information
625 else 
626   returns ref to array of hashref information of all Authtypes
627
628 =back
629
630 =cut
631 sub GetAuthType {
632     my ($authtypecode) = @_;
633     my $dbh=C4::Context->dbh;
634     my $sth;
635     if ($authtypecode){
636       $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
637       $sth->execute($authtypecode);
638     } else {
639       $sth=$dbh->prepare("select * from auth_types");
640       $sth->execute;
641     }
642     my $res=$sth->fetchall_arrayref({});
643     if (scalar(@$res)==1){
644       return $res->[0];
645     } else {
646       return $res;
647     }
648 }
649
650
651 sub AUTHhtml2marc {
652     my ($rtags,$rsubfields,$rvalues,%indicators) = @_;
653     my $dbh=C4::Context->dbh;
654     my $prevtag = -1;
655     my $record = MARC::Record->new();
656 #---- TODO : the leader is missing
657
658 #     my %subfieldlist=();
659     my $prevvalue; # if tag <10
660     my $field; # if tag >=10
661     for (my $i=0; $i< @$rtags; $i++) {
662         # rebuild MARC::Record
663         if (@$rtags[$i] ne $prevtag) {
664             if ($prevtag < 10) {
665                 if ($prevvalue) {
666                     $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
667                 }
668             } else {
669                 if ($field) {
670                     $record->add_fields($field);
671                 }
672             }
673             $indicators{@$rtags[$i]}.='  ';
674             if (@$rtags[$i] <10) {
675                 $prevvalue= @$rvalues[$i];
676                 undef $field;
677             } else {
678                 undef $prevvalue;
679                 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
680             }
681             $prevtag = @$rtags[$i];
682         } else {
683             if (@$rtags[$i] <10) {
684                 $prevvalue=@$rvalues[$i];
685             } else {
686                 if (length(@$rvalues[$i])>0) {
687                     $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
688                 }
689             }
690             $prevtag= @$rtags[$i];
691         }
692     }
693     # the last has not been included inside the loop... do it now !
694     $record->add_fields($field) if $field;
695     return $record;
696 }
697
698 =head2 FindDuplicateAuthority
699
700 =over 4
701
702 $record= &FindDuplicateAuthority( $record, $authtypecode)
703 return $authid,Summary if duplicate is found.
704
705 Comments : an improvement would be to return All the records that match.
706
707 =back
708
709 =cut
710
711 sub FindDuplicateAuthority {
712
713     my ($record,$authtypecode)=@_;
714 #    warn "IN for ".$record->as_formatted;
715     my $dbh = C4::Context->dbh;
716 #    warn "".$record->as_formatted;
717     my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
718     $sth->execute($authtypecode);
719     my ($auth_tag_to_report) = $sth->fetchrow;
720     $sth->finish;
721 #     warn "record :".$record->as_formatted."  auth_tag_to_report :$auth_tag_to_report";
722     # build a request for SearchAuthorities
723     my $query='at='.$authtypecode.' ';
724     map {$query.= " and he=\"".$_->[1]."\"" if ($_->[0]=~/[A-z]/)}  $record->field($auth_tag_to_report)->subfields() if $record->field($auth_tag_to_report);
725     my ($error,$results)=SimpleSearch($query,"authorityserver");
726     # there is at least 1 result => return the 1st one
727     if (@$results>0) {
728       my $marcrecord = MARC::File::USMARC::decode($results->[0]);
729       return $marcrecord->field('001')->data,BuildSummary($marcrecord,$marcrecord->field('001')->data,$authtypecode);
730     }
731     # no result, returns nothing
732     return;
733 }
734
735 =head2 BuildSummary
736
737 =over 4
738
739 $text= &BuildSummary( $record, $authid, $authtypecode)
740 return HTML encoded Summary
741
742 Comment : authtypecode can be infered from both record and authid.
743 Moreover, authid can also be inferred from $record.
744 Would it be interesting to delete those things.
745
746 =back
747
748 =cut
749
750 sub BuildSummary{
751 ## give this a Marc record to return summary
752   my ($record,$authid,$authtypecode)=@_;
753   my $dbh=C4::Context->dbh;
754   my $authref = GetAuthType($authtypecode);
755   my $summary = $authref->{summary};
756   my @fields = $record->fields();
757   my $reported_tag;
758   # if the library has a summary defined, use it. Otherwise, build a standard one
759   if ($summary) {
760     my @fields = $record->fields();
761     #             $reported_tag = '$9'.$result[$counter];
762     foreach my $field (@fields) {
763       my $tag = $field->tag();
764       my $tagvalue = $field->as_string();
765       $summary =~ s/\[(.?.?.?.?)$tag\*(.*?)]/$1$tagvalue$2\[$1$tag$2]/g;
766       if ($tag<10) {
767         if ($tag eq '001') {
768           $reported_tag.='$3'.$field->data();
769         }
770       } else {
771         my @subf = $field->subfields;
772         for my $i (0..$#subf) {
773           my $subfieldcode = $subf[$i][0];
774           my $subfieldvalue = $subf[$i][1];
775           my $tagsubf = $tag.$subfieldcode;
776           $summary =~ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
777         }
778       }
779     }
780     $summary =~ s/\[(.*?)]//g;
781     $summary =~ s/\n/<br>/g;
782     } else {
783       my $heading; # = $authref->{summary};
784       my $altheading;
785       my $seeheading;
786       my $see;
787       my @fields = $record->fields();
788       if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
789       # construct UNIMARC summary, that is quite different from MARC21 one
790           # accepted form
791           foreach my $field ($record->field('2..')) {
792               $heading.= $field->as_string();
793           }
794           # rejected form(s)
795           foreach my $field ($record->field('4..')) {
796               $summary.= "&nbsp;&nbsp;&nbsp;<i>".$field->as_string()."</i><br/>";
797               $summary.= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>see:</i> ".$heading."<br/>";
798           }
799           # see :
800           foreach my $field ($record->field('5..')) {
801               $summary.= "&nbsp;&nbsp;&nbsp;<i>".$field->as_string()."</i><br/>";
802               $summary.= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>see:</i> ".$heading."<br/>";
803           }
804           # // form
805           foreach my $field ($record->field('7..')) {
806               $seeheading.= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>see also:</i> ".$field->as_string()."<br />";
807               $altheading.= "&nbsp;&nbsp;&nbsp;".$field->as_string()."<br />";
808               $altheading.= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>see also:</i> ".$heading."<br />";
809           }
810           $summary = "<b>".$heading."</b><br />".$seeheading.$altheading.$summary;
811       } else {
812       # construct MARC21 summary
813           foreach my $field ($record->field('1..')) {
814               if ($record->field('100')) {
815                   $heading.= $field->as_string('abcdefghjklmnopqrstvxyz68');
816               } elsif ($record->field('110')) {
817                                       $heading.= $field->as_string('abcdefghklmnoprstvxyz68');
818               } elsif ($record->field('111')) {
819                                       $heading.= $field->as_string('acdefghklnpqstvxyz68');
820               } elsif ($record->field('130')) {
821                                       $heading.= $field->as_string('adfghklmnoprstvxyz68');
822               } elsif ($record->field('148')) {
823                                       $heading.= $field->as_string('abvxyz68');
824               } elsif ($record->field('150')) {
825           #    $heading.= $field->as_string('abvxyz68');
826           $heading.= $field->as_formatted();
827               my $tag=$field->tag();
828               $heading=~s /^$tag//g;
829               $heading =~s /\_/\$/g;
830               } elsif ($record->field('151')) {
831                                       $heading.= $field->as_string('avxyz68');
832               } elsif ($record->field('155')) {
833                                       $heading.= $field->as_string('abvxyz68');
834               } elsif ($record->field('180')) {
835                                       $heading.= $field->as_string('vxyz68');
836               } elsif ($record->field('181')) {
837                                       $heading.= $field->as_string('vxyz68');
838               } elsif ($record->field('182')) {
839                                       $heading.= $field->as_string('vxyz68');
840               } elsif ($record->field('185')) {
841                                       $heading.= $field->as_string('vxyz68');
842               } else {
843                   $heading.= $field->as_string();
844               }
845           } #See From
846           foreach my $field ($record->field('4..')) {
847               $seeheading.= "&nbsp;&nbsp;&nbsp;".$field->as_string()."<br />";
848               $seeheading.= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>see:</i> ".$seeheading."<br />";
849           } #See Also
850           foreach my $field ($record->field('5..')) {
851               $altheading.= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>see also:</i> ".$field->as_string()."<br />";
852               $altheading.= "&nbsp;&nbsp;&nbsp;".$field->as_string()."<br />";
853               $altheading.= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>see also:</i> ".$altheading."<br />";
854           }
855           $summary.=$heading.$seeheading.$altheading;
856       }
857     }
858 return $summary;
859 }
860
861 =head2 BuildUnimarcHierarchies
862
863 =over 4
864
865 $text= &BuildUnimarcHierarchies( $authid, $force)
866 return text containing trees for hierarchies
867 for them to be stored in auth_header
868
869 Example of text:
870 122,1314,2452;1324,2342,3,2452
871
872 =back
873
874 =cut
875 sub BuildUnimarcHierarchies{
876   my $authid = shift @_;
877 #   warn "authid : $authid";
878   my $force = shift @_;
879   my @globalresult;
880   my $dbh=C4::Context->dbh;
881   my $hierarchies;
882   my $data = GetHeaderAuthority($authid);
883   if ($data->{'authtrees'} and not $force){
884     return $data->{'authtrees'};
885   } elsif ($data->{'authtrees'}){
886     $hierarchies=$data->{'authtrees'};
887   } else {
888     my $record = GetAuthority($authid);
889     my $found;
890     foreach my $field ($record->field('550')){
891       if ($field->subfield('5') && $field->subfield('5') eq 'g'){
892         my $parentrecord = GetAuthority($field->subfield('3'));
893         my $localresult=$hierarchies;
894         my $trees;
895         $trees = BuildUnimarcHierarchies($field->subfield('3'));
896         my @trees;
897         if ($trees=~/;/){
898            @trees = split(/;/,$trees);
899         } else {
900            push @trees, $trees;
901         }
902         foreach (@trees){
903           $_.= ",$authid";
904         }
905         @globalresult = (@globalresult,@trees);
906         $found=1;
907       }
908       $hierarchies=join(";",@globalresult);
909     }
910     #Unless there is no ancestor, I am alone.
911     $hierarchies="$authid" unless ($hierarchies);
912   }
913   AddAuthorityTrees($authid,$hierarchies);
914   return $hierarchies;
915 }
916
917 =head2 BuildUnimarcHierarchy
918
919 =over 4
920
921 $ref= &BuildUnimarcHierarchy( $record, $class,$authid)
922 return a hashref in order to display hierarchy for record and final Authid $authid
923
924 "loopparents"
925 "loopchildren"
926 "class"
927 "loopauthid"
928 "current_value"
929 "value"
930
931 "ifparents"  
932 "ifchildren" 
933 Those two latest ones should disappear soon.
934
935 =back
936
937 =cut
938 sub BuildUnimarcHierarchy{
939   my $record = shift @_;
940   my $class = shift @_;
941   my $authid_constructed = shift @_;
942   my $authid=$record->subfield('250','3');
943   my %cell;
944   my $parents=""; my $children="";
945   my (@loopparents,@loopchildren);
946   foreach my $field ($record->field('550')){
947     if ($field->subfield('5') && $field->subfield('a')){
948       if ($field->subfield('5') eq 'h'){
949         push @loopchildren, { "childauthid"=>$field->subfield('3'),"childvalue"=>$field->subfield('a')};
950       }elsif ($field->subfield('5') eq 'g'){
951         push @loopparents, { "parentauthid"=>$field->subfield('3'),"parentvalue"=>$field->subfield('a')};
952       }
953           # brothers could get in there with an else
954     }
955   }
956   $cell{"ifparents"}=1 if (scalar(@loopparents)>0);
957   $cell{"ifchildren"}=1 if (scalar(@loopchildren)>0);
958   $cell{"loopparents"}=\@loopparents if (scalar(@loopparents)>0);
959   $cell{"loopchildren"}=\@loopchildren if (scalar(@loopchildren)>0);
960   $cell{"class"}=$class;
961   $cell{"loopauthid"}=$authid;
962   $cell{"current_value"} =1 if $authid eq $authid_constructed;
963   $cell{"value"}=$record->subfield('250',"a");
964   return \%cell;
965 }
966
967 =head2 GetHeaderAuthority
968
969 =over 4
970
971 $ref= &GetHeaderAuthority( $authid)
972 return a hashref in order auth_header table data
973
974 =back
975
976 =cut
977 sub GetHeaderAuthority{
978   my $authid = shift @_;
979   my $sql= "SELECT * from auth_header WHERE authid = ?";
980   my $dbh=C4::Context->dbh;
981   my $rq= $dbh->prepare($sql);
982   $rq->execute($authid);
983   my $data= $rq->fetchrow_hashref;
984   return $data;
985 }
986
987 =head2 AddAuthorityTrees
988
989 =over 4
990
991 $ref= &AddAuthorityTrees( $authid, $trees)
992 return success or failure
993
994 =back
995
996 =cut
997
998 sub AddAuthorityTrees{
999   my $authid = shift @_;
1000   my $trees = shift @_;
1001   my $sql= "UPDATE IGNORE auth_header set authtrees=? WHERE authid = ?";
1002   my $dbh=C4::Context->dbh;
1003   my $rq= $dbh->prepare($sql);
1004   return $rq->execute($trees,$authid);
1005 }
1006
1007 =head2 merge
1008
1009 =over 4
1010
1011 $ref= &merge(mergefrom,$MARCfrom,$mergeto,$MARCto)
1012
1013
1014 Could add some feature : Migrating from a typecode to an other for instance.
1015 Then we should add some new parameter : bibliotargettag, authtargettag
1016
1017 =back
1018
1019 =cut
1020 sub merge {
1021     my ($mergefrom,$MARCfrom,$mergeto,$MARCto) = @_;
1022     my $dbh=C4::Context->dbh;
1023     my $authtypecodefrom = GetAuthTypeCode($mergefrom);
1024     my $authtypecodeto = GetAuthTypeCode($mergeto);
1025     # return if authority does not exist
1026     my @X = $MARCfrom->fields();
1027     return if $#X == -1;
1028     @X = $MARCto->fields();
1029     return if $#X == -1;
1030     # search the tag to report
1031     my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
1032     $sth->execute($authtypecodefrom);
1033     my ($auth_tag_to_report) = $sth->fetchrow;
1034     
1035     my @record_to;
1036     @record_to = $MARCto->field($auth_tag_to_report)->subfields() if $MARCto->field($auth_tag_to_report);
1037     my @record_from;
1038     @record_from = $MARCfrom->field($auth_tag_to_report)->subfields() if $MARCfrom->field($auth_tag_to_report);
1039     
1040     # search all biblio tags using this authority.
1041     $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
1042     $sth->execute($authtypecodefrom);
1043     my @tags_using_authtype;
1044     while (my ($tagfield) = $sth->fetchrow) {
1045         push @tags_using_authtype,$tagfield."9" ;
1046     }
1047
1048     if (C4::Context->preference('NoZebra')) {
1049         warn "MERGE TO DO";
1050     } else {
1051         # now, find every biblio using this authority
1052         my $oConnection=C4::Context->Zconn("biblioserver");
1053         my $query;
1054         $query= "an= ".$mergefrom;
1055         my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
1056         my $count=$oResult->size() if  ($oResult);
1057         my @reccache;
1058         my $z=0;
1059         while ( $z<$count ) {
1060         my $rec;
1061                 $rec=$oResult->record($z);
1062             my $marcdata = $rec->raw();
1063         push @reccache, $marcdata;
1064         $z++;
1065         }
1066         $oResult->destroy();
1067         foreach my $marc(@reccache){
1068             my $update;
1069             my $marcrecord;
1070             $marcrecord = MARC::File::USMARC::decode($marc);
1071             foreach my $tagfield (@tags_using_authtype){
1072             $tagfield=substr($tagfield,0,3);
1073             my @tags = $marcrecord->field($tagfield);
1074             foreach my $tag (@tags){
1075                 my $tagsubs=$tag->subfield("9");
1076             #warn "$tagfield:$tagsubs:$mergefrom";
1077                 if ($tagsubs== $mergefrom) {
1078                 $tag->update("9" =>$mergeto);
1079                 foreach my $subfield (@record_to) {
1080             #        warn "$subfield,$subfield->[0],$subfield->[1]";
1081                     $tag->update($subfield->[0] =>$subfield->[1]);
1082                 }#for $subfield
1083                 }
1084                 $marcrecord->delete_field($tag);
1085                 $marcrecord->add_fields($tag);
1086                 $update=1;
1087             }#for each tag
1088             }#foreach tagfield
1089             my $oldbiblio = TransformMarcToKoha($dbh,$marcrecord,"") ;
1090             if ($update==1){
1091             &ModBiblio($marcrecord,$oldbiblio->{'biblionumber'},GetFrameworkCode($oldbiblio->{'biblionumber'})) ;
1092             }
1093             
1094         }#foreach $marc
1095     }
1096   # now, find every other authority linked with this authority
1097 #   my $oConnection=C4::Context->Zconn("authorityserver");
1098 #   my $query;
1099 # # att 9210               Auth-Internal-authtype
1100 # # att 9220               Auth-Internal-LN
1101 # # ccl.properties to add for authorities
1102 #   $query= "= ".$mergefrom;
1103 #   my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
1104 #   my $count=$oResult->size() if  ($oResult);
1105 #   my @reccache;
1106 #   my $z=0;
1107 #   while ( $z<$count ) {
1108 #   my $rec;
1109 #           $rec=$oResult->record($z);
1110 #       my $marcdata = $rec->raw();
1111 #   push @reccache, $marcdata;
1112 #   $z++;
1113 #   }
1114 #   $oResult->destroy();
1115 #   foreach my $marc(@reccache){
1116 #     my $update;
1117 #     my $marcrecord;
1118 #     $marcrecord = MARC::File::USMARC::decode($marc);
1119 #     foreach my $tagfield (@tags_using_authtype){
1120 #       $tagfield=substr($tagfield,0,3);
1121 #       my @tags = $marcrecord->field($tagfield);
1122 #       foreach my $tag (@tags){
1123 #         my $tagsubs=$tag->subfield("9");
1124 #     #warn "$tagfield:$tagsubs:$mergefrom";
1125 #         if ($tagsubs== $mergefrom) {
1126 #           $tag->update("9" =>$mergeto);
1127 #           foreach my $subfield (@record_to) {
1128 #     #        warn "$subfield,$subfield->[0],$subfield->[1]";
1129 #             $tag->update($subfield->[0] =>$subfield->[1]);
1130 #           }#for $subfield
1131 #         }
1132 #         $marcrecord->delete_field($tag);
1133 #         $marcrecord->add_fields($tag);
1134 #         $update=1;
1135 #       }#for each tag
1136 #     }#foreach tagfield
1137 #     my $authoritynumber = TransformMarcToKoha($dbh,$marcrecord,"") ;
1138 #     if ($update==1){
1139 #       &ModAuthority($marcrecord,$authoritynumber,GetAuthTypeCode($authoritynumber)) ;
1140 #     }
1141
1142 #   }#foreach $marc
1143 }#sub
1144 END { }       # module clean-up code here (global destructor)
1145
1146 =back
1147
1148 =head1 AUTHOR
1149
1150 Koha Developement team <info@koha.org>
1151
1152 Paul POULAIN paul.poulain@free.fr
1153
1154 =cut
1155
1156 # $Id$
1157 # $Log$
1158 # Revision 1.48  2007/06/25 15:01:45  tipaul
1159 # bugfixes on unimarc 100 handling (the field used for encoding)
1160 #
1161 # Revision 1.47  2007/06/06 13:08:35  tipaul
1162 # bugfixes (various), handling utf-8 without guessencoding (as suggested by joshua, fixing some zebra config files -for french but should be interesting for other languages-
1163 #
1164 # Revision 1.46  2007/05/10 14:45:15  tipaul
1165 # Koha NoZebra :
1166 # - support for authorities
1167 # - some bugfixes in ordering and "CCL" parsing
1168 # - support for authorities <=> biblios walking
1169 #
1170 # Seems I can do what I want now, so I consider its done, except for bugfixes that will be needed i m sure !
1171 #
1172 # Revision 1.45  2007/04/06 14:48:45  hdl
1173 # Code Cleaning : AuthoritiesMARC.
1174 #
1175 # Revision 1.44  2007/04/05 12:17:55  btoumi
1176 # add "sort by" with heading-entity in authorities search
1177 #
1178 # Revision 1.43  2007/03/30 11:59:16  tipaul
1179 # some cleaning (minor, the main one will come later) : removing some unused subs
1180 #
1181 # Revision 1.42  2007/03/29 16:45:53  tipaul
1182 # Code cleaning of Biblio.pm (continued)
1183 #
1184 # All subs have be cleaned :
1185 # - removed useless
1186 # - merged some
1187 # - reordering Biblio.pm completly
1188 # - using only naming conventions
1189 #
1190 # Seems to have broken nothing, but it still has to be heavily tested.
1191 # Note that Biblio.pm is now much more efficient than previously & probably more reliable as well.
1192 #
1193 # Revision 1.41  2007/03/29 13:30:31  tipaul
1194 # Code cleaning :
1195 # == Biblio.pm cleaning (useless) ==
1196 # * some sub declaration dropped
1197 # * removed modbiblio sub
1198 # * removed moditem sub
1199 # * removed newitems. It was used only in finishrecieve. Replaced by a TransformKohaToMarc+AddItem, that is better.
1200 # * removed MARCkoha2marcItem
1201 # * removed MARCdelsubfield declaration
1202 # * removed MARCkoha2marcBiblio
1203 #
1204 # == Biblio.pm cleaning (naming conventions) ==
1205 # * MARCgettagslib renamed to GetMarcStructure
1206 # * MARCgetitems renamed to GetMarcItem
1207 # * MARCfind_frameworkcode renamed to GetFrameworkCode
1208 # * MARCmarc2koha renamed to TransformMarcToKoha
1209 # * MARChtml2marc renamed to TransformHtmlToMarc
1210 # * MARChtml2xml renamed to TranformeHtmlToXml
1211 # * zebraop renamed to ModZebra
1212 #
1213 # == MARC=OFF ==
1214 # * removing MARC=OFF related scripts (in cataloguing directory)
1215 # * removed checkitems (function related to MARC=off feature, that is completly broken in head. If someone want to reintroduce it, hard work coming...)
1216 # * removed getitemsbybiblioitem (used only by MARC=OFF scripts, that is removed as well)
1217 #
1218 # Revision 1.40  2007/03/28 10:39:16  hdl
1219 # removing $dbh as a parameter in AuthoritiesMarc functions
1220 # And reporting all differences into the scripts taht relies on those functions.
1221 #
1222 # Revision 1.39  2007/03/16 01:25:08  kados
1223 # Using my precrash CVS copy I did the following:
1224 #
1225 # cvs -z3 -d:ext:kados@cvs.savannah.nongnu.org:/sources/koha co -P koha
1226 # find koha.precrash -type d -name "CVS" -exec rm -v {} \;
1227 # cp -r koha.precrash/* koha/
1228 # cd koha/
1229 # cvs commit
1230 #
1231 # This should in theory put us right back where we were before the crash
1232 #
1233 # Revision 1.39  2007/03/12 22:16:31  kados
1234 # chcking for field before calling subfields
1235 #
1236 # Revision 1.38  2007/03/09 14:31:47  tipaul
1237 # rel_3_0 moved to HEAD
1238 #
1239 # Revision 1.28.2.17  2007/02/05 13:16:08  hdl
1240 # Removing Link from AuthoritiesMARC summary (caused a problem owed to the API differences between opac and intranet)
1241 # + removing $dbh in SearchAuthorities
1242 # + adding links in templates on summaries to go to full view.
1243 # (no more links in popup authorities. or should we add it ?)
1244 #
1245 # Revision 1.28.2.16  2007/02/02 18:07:42  hdl
1246 # Sorting and searching for exact term now works.
1247 #
1248 # Revision 1.28.2.15  2007/01/24 10:17:47  hdl
1249 # FindDuplicate Now works.
1250 # Be AWARE that it needs a change ccl.properties.
1251 #
1252 # Revision 1.28.2.14  2007/01/10 14:40:11  hdl
1253 # Adding Authorities tree.
1254 #
1255 # Revision 1.28.2.13  2007/01/09 15:18:09  hdl
1256 # Adding an to ccl.properties to allow ccl search for authority-numbers.
1257 # Fixing Some problems with the previous modification to allow pqf search to work for more than one page.
1258 # Using search for an= for an authority-Number.
1259 #
1260 # Revision 1.28.2.12  2007/01/09 13:51:31  hdl
1261 # Bug Fixing : CountUsage used *synchronous* connection where biblio used ****asynchronous**** one.
1262 # First try to get it work.
1263 #
1264 # Revision 1.28.2.11  2007/01/05 14:37:26  btoumi
1265 # bug fix : remove wrong field in sql syntaxe from auth_subfield_structure table
1266 #
1267 # Revision 1.28.2.10  2007/01/04 13:11:08  tipaul
1268 # commenting 2 zconn destroy
1269 #
1270 # Revision 1.28.2.9  2006/12/22 15:09:53  toins
1271 # removing C4::Database;
1272 #
1273 # Revision 1.28.2.8  2006/12/20 17:13:19  hdl
1274 # modifying use of GILS into use of @attr 1=Koha-Auth-Number
1275 #
1276 # Revision 1.28.2.7  2006/12/18 16:45:38  tipaul
1277 # FIXME upcased
1278 #
1279 # Revision 1.28.2.6  2006/12/07 16:45:43  toins
1280 # removing warn compilation. (perl -wc)
1281 #
1282 # Revision 1.28.2.5  2006/12/06 14:19:59  hdl
1283 # ABugFixing : Authority count  Management.
1284 #
1285 # Revision 1.28.2.4  2006/11/17 13:18:58  tipaul
1286 # code cleaning : removing use of "bib", and replacing with "biblionumber"
1287 #
1288 # WARNING : I tried to do carefully, but there are probably some mistakes.
1289 # So if you encounter a problem you didn't have before, look for this change !!!
1290 # anyway, I urge everybody to use only "biblionumber", instead of "bib", "bi", "biblio" or anything else. will be easier to maintain !!!
1291 #
1292 # Revision 1.28.2.3  2006/11/17 11:17:30  tipaul
1293 # code cleaning : removing use of "bib", and replacing with "biblionumber"
1294 #
1295 # WARNING : I tried to do carefully, but there are probably some mistakes.
1296 # So if you encounter a problem you didn't have before, look for this change !!!
1297 # anyway, I urge everybody to use only "biblionumber", instead of "bib", "bi", "biblio" or anything else. will be easier to maintain !!!
1298 #
1299 # Revision 1.28.2.2  2006/10/12 22:04:47  hdl
1300 # Authorities working with zebra.
1301 # zebra Configuration files are comitted next.