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