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