AddAuthority, adding 100 field for UNIMARC if it's not provided
[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     unless ($record->field('001') && $record->field('001')->data() eq $authid){
509         $record->delete_field($record->field('001'));
510         $record->insert_fields_ordered(MARC::Field->new('001',$authid));
511     }
512     if (($format eq "UNIMARCAUTH") && (!$record->subfield('100','a'))){
513         $record->leader("     nx  j22             ");
514         my $date=POSIX::strftime("%Y%m%d",localtime);    
515         if ($record->field('100')){
516             $record->field('100')->update('a'=>$date."afrey50      ba0");
517         } else {      
518             $record->append_fields(
519             MARC::Field->new('100',' ',' '
520                 ,'a'=>$date."afrey50      ba0")
521             );
522         }      
523     }    
524     $record->add_fields('152','','','b'=>$authtypecode) unless $record->field('152');
525 #     warn $record->as_formatted;
526     $dbh->do("lock tables auth_header WRITE");
527     $sth=$dbh->prepare("insert into auth_header (authid,datecreated,authtypecode,marc,marcxml) values (?,now(),?,?,?)");
528     $sth->execute($authid,$authtypecode,$record->as_usmarc,$record->as_xml_record($format));
529     $sth->finish;
530   }else{
531       $record->add_fields('001',$authid) unless ($record->field('001'));
532       if (($format eq "UNIMARCAUTH") && (!$record->subfield('100','a'))){
533             $record->leader("     nx  j22             ");
534             my $date=POSIX::strftime("%Y%m%d",localtime);    
535             if ($record->field('100')){
536               $record->field('100')->update('a'=>$date."afrey50      ba0");
537             } else {      
538               $record->append_fields(
539                 MARC::Field->new('100',' ',' '
540                   ,'a'=>$date."afrey50      ba0")
541               );
542             }      
543       }    
544       $record->add_fields('152','','','b'=>$authtypecode) unless ($record->field('152'));
545       $dbh->do("lock tables auth_header WRITE");
546       my $sth=$dbh->prepare("update auth_header set marc=?,marcxml=? where authid=?");
547       $sth->execute($record->as_usmarc,$record->as_xml_record($format),$authid);
548       $sth->finish;
549   }
550   $dbh->do("unlock tables");
551   ModZebra($authid,'specialUpdate',"authorityserver",$record);
552   return ($authid);
553 }
554
555
556 =head2 DelAuthority
557
558 =over 4
559
560 $authid= &DelAuthority($authid)
561 Deletes $authid
562
563 =back
564
565 =cut
566
567
568 sub DelAuthority {
569     my ($authid) = @_;
570     my $dbh=C4::Context->dbh;
571
572     ModZebra($authid,"recordDelete","authorityserver",GetAuthority($authid));
573     $dbh->do("delete from auth_header where authid=$authid") ;
574
575 }
576
577 sub ModAuthority {
578   my ($authid,$record,$authtypecode,$merge)=@_;
579   my $dbh=C4::Context->dbh;
580 #   my ($oldrecord)=&GetAuthority($authid);
581 #   if ($oldrecord eq $record) {
582 #       return;
583 #   }
584 #   my $sth=$dbh->prepare("update auth_header set marc=?,marcxml=? where authid=?");
585   #Now rewrite the $record to table with an add
586   $authid=AddAuthority($record,$authid,$authtypecode);
587
588 ### 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
589 ### they should have a system preference "dontmerge=1" otherwise by default biblios will be updated
590 ### the $merge flag is now depreceated and will be removed at code cleaning
591   if (C4::Context->preference('dontmerge') ){
592   # save the file in tmp/modified_authorities
593       my $cgidir = C4::Context->intranetdir ."/cgi-bin";
594       unless (opendir(DIR,"$cgidir")) {
595               $cgidir = C4::Context->intranetdir."/";
596       }
597   
598       my $filename = $cgidir."/tmp/modified_authorities/$authid.authid";
599       open AUTH, "> $filename";
600       print AUTH $authid;
601       close AUTH;
602   } else {
603 #        &merge($authid,$record,$authid,$record);
604   }
605   return $authid;
606 }
607
608 =head2 GetAuthorityXML 
609
610 =over 4
611
612 $marcxml= &GetAuthorityXML( $authid)
613 returns xml form of record $authid
614
615 =back
616
617 =cut
618 sub GetAuthorityXML {
619   # Returns MARC::XML of the authority passed in parameter.
620   my ( $authid ) = @_;
621   my $dbh=C4::Context->dbh;
622   my $sth =
623       $dbh->prepare("select marcxml from auth_header where authid=? "  );
624   $sth->execute($authid);
625   my ($marcxml)=$sth->fetchrow;
626   return $marcxml;
627
628 }
629
630 =head2 GetAuthority 
631
632 =over 4
633
634 $record= &GetAuthority( $authid)
635 Returns MARC::Record of the authority passed in parameter.
636
637 =back
638
639 =cut
640 sub GetAuthority {
641     my ($authid)=@_;
642     my $dbh=C4::Context->dbh;
643     my $sth=$dbh->prepare("select marcxml from auth_header where authid=?");
644     $sth->execute($authid);
645     my ($marcxml) = $sth->fetchrow;
646     my $record=MARC::Record->new_from_xml($marcxml,'UTF-8',(C4::Context->preference("marcflavour") eq "UNIMARC"?"UNIMARCAUTH":C4::Context->preference("marcflavour")));
647     $record->encoding('UTF-8');
648     return ($record);
649 }
650
651 =head2 GetAuthType 
652
653 =over 4
654
655 $result= &GetAuthType( $authtypecode)
656 If $authtypecode is not "" then 
657   Returns hashref to authtypecode information
658 else 
659   returns ref to array of hashref information of all Authtypes
660
661 =back
662
663 =cut
664 sub GetAuthType {
665     my ($authtypecode) = @_;
666     my $dbh=C4::Context->dbh;
667     my $sth;
668     if (defined $authtypecode){ # NOTE - in MARC21 framework, '' is a valid authority 
669                                 # type
670       $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
671       $sth->execute($authtypecode);
672     } else {
673       $sth=$dbh->prepare("select * from auth_types");
674       $sth->execute;
675     }
676     my $res=$sth->fetchall_arrayref({});
677     if (scalar(@$res)==1){
678       return $res->[0];
679     } else {
680       return $res;
681     }
682 }
683
684
685 sub AUTHhtml2marc {
686     my ($rtags,$rsubfields,$rvalues,%indicators) = @_;
687     my $dbh=C4::Context->dbh;
688     my $prevtag = -1;
689     my $record = MARC::Record->new();
690 #---- TODO : the leader is missing
691
692 #     my %subfieldlist=();
693     my $prevvalue; # if tag <10
694     my $field; # if tag >=10
695     for (my $i=0; $i< @$rtags; $i++) {
696         # rebuild MARC::Record
697         if (@$rtags[$i] ne $prevtag) {
698             if ($prevtag < 10) {
699                 if ($prevvalue) {
700                     $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
701                 }
702             } else {
703                 if ($field) {
704                     $record->add_fields($field);
705                 }
706             }
707             $indicators{@$rtags[$i]}.='  ';
708             if (@$rtags[$i] <10) {
709                 $prevvalue= @$rvalues[$i];
710                 undef $field;
711             } else {
712                 undef $prevvalue;
713                 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
714             }
715             $prevtag = @$rtags[$i];
716         } else {
717             if (@$rtags[$i] <10) {
718                 $prevvalue=@$rvalues[$i];
719             } else {
720                 if (length(@$rvalues[$i])>0) {
721                     $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
722                 }
723             }
724             $prevtag= @$rtags[$i];
725         }
726     }
727     # the last has not been included inside the loop... do it now !
728     $record->add_fields($field) if $field;
729     return $record;
730 }
731
732 =head2 FindDuplicateAuthority
733
734 =over 4
735
736 $record= &FindDuplicateAuthority( $record, $authtypecode)
737 return $authid,Summary if duplicate is found.
738
739 Comments : an improvement would be to return All the records that match.
740
741 =back
742
743 =cut
744
745 sub FindDuplicateAuthority {
746
747     my ($record,$authtypecode)=@_;
748 #    warn "IN for ".$record->as_formatted;
749     my $dbh = C4::Context->dbh;
750 #    warn "".$record->as_formatted;
751     my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
752     $sth->execute($authtypecode);
753     my ($auth_tag_to_report) = $sth->fetchrow;
754     $sth->finish;
755 #     warn "record :".$record->as_formatted."  auth_tag_to_report :$auth_tag_to_report";
756     # build a request for SearchAuthorities
757     my $query='at='.$authtypecode.' ';
758     map {$query.= " and he=\"".$_->[1]."\"" if ($_->[0]=~/[A-z]/)}  $record->field($auth_tag_to_report)->subfields() if $record->field($auth_tag_to_report);
759     my ($error,$results)=SimpleSearch($query,"authorityserver");
760     # there is at least 1 result => return the 1st one
761     if (@$results>0) {
762       my $marcrecord = MARC::File::USMARC::decode($results->[0]);
763       return $marcrecord->field('001')->data,BuildSummary($marcrecord,$marcrecord->field('001')->data,$authtypecode);
764     }
765     # no result, returns nothing
766     return;
767 }
768
769 =head2 BuildSummary
770
771 =over 4
772
773 $text= &BuildSummary( $record, $authid, $authtypecode)
774 return HTML encoded Summary
775
776 Comment : authtypecode can be infered from both record and authid.
777 Moreover, authid can also be inferred from $record.
778 Would it be interesting to delete those things.
779
780 =back
781
782 =cut
783
784 sub BuildSummary{
785 ## give this a Marc record to return summary
786   my ($record,$authid,$authtypecode)=@_;
787   my $dbh=C4::Context->dbh;
788   my $authref = GetAuthType($authtypecode);
789   my $summary = $authref->{summary};
790   my %language;
791   $language{'fre'}="Français";
792   $language{'eng'}="Anglais";
793   $language{'ger'}="Allemand";
794   $language{'ita'}="Italien";
795   $language{'spa'}="Espagnol";
796   my %thesaurus;
797   $thesaurus{'1'}="Peuples";
798   $thesaurus{'2'}="Anthroponymes";
799   $thesaurus{'3'}="Oeuvres";
800   $thesaurus{'4'}="Chronologie";
801   $thesaurus{'5'}="Lieux";
802   $thesaurus{'6'}="Sujets";
803   #thesaurus a remplir
804   my @fields = $record->fields();
805   my $reported_tag;
806   # if the library has a summary defined, use it. Otherwise, build a standard one
807   # FIXME - it appears that the summary field in the authority frameworks
808   #         can work as a display template.  However, this doesn't
809   #         suit the MARC21 version, so for now the "templating"
810   #         feature will be enabled only for UNIMARC for backwards
811   #         compatibility.
812   if ($summary and C4::Context->preference('marcflavour') eq 'UNIMARC') {
813     my @fields = $record->fields();
814     #             $reported_tag = '$9'.$result[$counter];
815     foreach my $field (@fields) {
816       my $tag = $field->tag();
817       my $tagvalue = $field->as_string();
818       $summary =~ s/\[(.?.?.?.?)$tag\*(.*?)]/$1$tagvalue$2\[$1$tag$2]/g;
819       if ($tag<10) {
820         if ($tag eq '001') {
821           $reported_tag.='$3'.$field->data();
822         }
823       } else {
824         my @subf = $field->subfields;
825         for my $i (0..$#subf) {
826           my $subfieldcode = $subf[$i][0];
827           my $subfieldvalue = $subf[$i][1];
828           my $tagsubf = $tag.$subfieldcode;
829           $summary =~ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
830         }
831       }
832     }
833     $summary =~ s/\[(.*?)]//g;
834     $summary =~ s/\n/<br>/g;
835   } else {
836     my $heading; 
837     my $authid; 
838     my $altheading;
839     my $seealso;
840     my $broaderterms;
841     my $narrowerterms;
842     my $see;
843     my $seeheading;
844         my $notes;
845     my @fields = $record->fields();
846     if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
847     # construct UNIMARC summary, that is quite different from MARC21 one
848       # accepted form
849       foreach my $field ($record->field('2..')) {
850         $heading.= $field->subfield('a');
851                 $authid=$field->subfield('3');
852       }
853       # rejected form(s)
854       foreach my $field ($record->field('3..')) {
855         $notes.= '<span class="note">'.$field->subfield('a')."</span>\n";
856       }
857       foreach my $field ($record->field('4..')) {
858         my $thesaurus = "thes. : ".$thesaurus{"$field->subfield('2')"}." : " if ($field->subfield('2'));
859         $see.= '<span class="UF">'.$thesaurus.$field->subfield('a')."</span> -- \n";
860       }
861       # see :
862       foreach my $field ($record->field('5..')) {
863             
864         if (($field->subfield('5')) && ($field->subfield('a')) && ($field->subfield('5') eq 'g')) {
865           $broaderterms.= '<span class="BT"> <a href="detail.pl?authid='.$field->subfield('3').'">'.$field->subfield('a')."</a></span> -- \n";
866         } elsif (($field->subfield('5')) && ($field->subfield('a')) && ($field->subfield('5') eq 'h')){
867           $narrowerterms.= '<span class="NT"><a href="detail.pl?authid='.$field->subfield('3').'">'.$field->subfield('a')."</a></span> -- \n";
868         } elsif ($field->subfield('a')) {
869           $seealso.= '<span class="RT"><a href="detail.pl?authid='.$field->subfield('3').'">'.$field->subfield('a')."</a></span> -- \n";
870         }
871       }
872       # // form
873       foreach my $field ($record->field('7..')) {
874         my $lang = substr($field->subfield('8'),3,3);
875         $seeheading.= '<span class="langue"> En '.$language{$lang}.' : </span><span class="OT"> '.$field->subfield('a')."</span><br />\n";  
876       }
877             $broaderterms =~s/-- \n$//;
878             $narrowerterms =~s/-- \n$//;
879             $seealso =~s/-- \n$//;
880             $see =~s/-- \n$//;
881       $summary = "<b><a href=\"detail.pl?authid=$authid\">".$heading."</a></b><br />".($notes?"$notes <br />":"");
882       $summary.= '<p><div class="label">TG : '.$broaderterms.'</div></p>' if ($broaderterms);
883       $summary.= '<p><div class="label">TS : '.$narrowerterms.'</div></p>' if ($narrowerterms);
884       $summary.= '<p><div class="label">TA : '.$seealso.'</div></p>' if ($seealso);
885       $summary.= '<p><div class="label">EP : '.$see.'</div></p>' if ($see);
886       $summary.= '<p><div class="label">'.$seeheading.'</div></p>' if ($seeheading);
887       } else {
888       # construct MARC21 summary
889           # FIXME - looping over 1XX is questionable
890           # since MARC21 authority should have only one 1XX
891           foreach my $field ($record->field('1..')) {
892               next if "152" eq $field->tag(); # FIXME - 152 is not a good tag to use
893                                               # in MARC21 -- purely local tags really ought to be
894                                               # 9XX
895               if ($record->field('100')) {
896                   $heading.= $field->as_string('abcdefghjklmnopqrstvxyz68');
897               } elsif ($record->field('110')) {
898                                       $heading.= $field->as_string('abcdefghklmnoprstvxyz68');
899               } elsif ($record->field('111')) {
900                                       $heading.= $field->as_string('acdefghklnpqstvxyz68');
901               } elsif ($record->field('130')) {
902                                       $heading.= $field->as_string('adfghklmnoprstvxyz68');
903               } elsif ($record->field('148')) {
904                                       $heading.= $field->as_string('abvxyz68');
905               } elsif ($record->field('150')) {
906           #    $heading.= $field->as_string('abvxyz68');
907           $heading.= $field->as_formatted();
908               my $tag=$field->tag();
909               $heading=~s /^$tag//g;
910               $heading =~s /\_/\$/g;
911               } elsif ($record->field('151')) {
912                                       $heading.= $field->as_string('avxyz68');
913               } elsif ($record->field('155')) {
914                                       $heading.= $field->as_string('abvxyz68');
915               } elsif ($record->field('180')) {
916                                       $heading.= $field->as_string('vxyz68');
917               } elsif ($record->field('181')) {
918                                       $heading.= $field->as_string('vxyz68');
919               } elsif ($record->field('182')) {
920                                       $heading.= $field->as_string('vxyz68');
921               } elsif ($record->field('185')) {
922                                       $heading.= $field->as_string('vxyz68');
923               } else {
924                   $heading.= $field->as_string();
925               }
926           } #See From
927           foreach my $field ($record->field('4..')) {
928               $seeheading.= "<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>used for/see from:</i> ".$field->as_string();
929           } #See Also
930           foreach my $field ($record->field('5..')) {
931               $altheading.= "<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>see also:</i> ".$field->as_string();
932           }
933           $summary .= ": " if $summary;
934           $summary.=$heading.$seeheading.$altheading;
935       }
936   }
937   return $summary;
938 }
939
940 =head2 BuildUnimarcHierarchies
941
942 =over 4
943
944 $text= &BuildUnimarcHierarchies( $authid, $force)
945 return text containing trees for hierarchies
946 for them to be stored in auth_header
947
948 Example of text:
949 122,1314,2452;1324,2342,3,2452
950
951 =back
952
953 =cut
954 sub BuildUnimarcHierarchies{
955   my $authid = shift @_;
956 #   warn "authid : $authid";
957   my $force = shift @_;
958   my @globalresult;
959   my $dbh=C4::Context->dbh;
960   my $hierarchies;
961   my $data = GetHeaderAuthority($authid);
962   if ($data->{'authtrees'} and not $force){
963     return $data->{'authtrees'};
964   } elsif ($data->{'authtrees'}){
965     $hierarchies=$data->{'authtrees'};
966   } else {
967     my $record = GetAuthority($authid);
968     my $found;
969     foreach my $field ($record->field('550')){
970       if ($field->subfield('5') && $field->subfield('5') eq 'g'){
971         my $parentrecord = GetAuthority($field->subfield('3'));
972         my $localresult=$hierarchies;
973         my $trees;
974         $trees = BuildUnimarcHierarchies($field->subfield('3'));
975         my @trees;
976         if ($trees=~/;/){
977            @trees = split(/;/,$trees);
978         } else {
979            push @trees, $trees;
980         }
981         foreach (@trees){
982           $_.= ",$authid";
983         }
984         @globalresult = (@globalresult,@trees);
985         $found=1;
986       }
987       $hierarchies=join(";",@globalresult);
988     }
989     #Unless there is no ancestor, I am alone.
990     $hierarchies="$authid" unless ($hierarchies);
991   }
992   AddAuthorityTrees($authid,$hierarchies);
993   return $hierarchies;
994 }
995
996 =head2 BuildUnimarcHierarchy
997
998 =over 4
999
1000 $ref= &BuildUnimarcHierarchy( $record, $class,$authid)
1001 return a hashref in order to display hierarchy for record and final Authid $authid
1002
1003 "loopparents"
1004 "loopchildren"
1005 "class"
1006 "loopauthid"
1007 "current_value"
1008 "value"
1009
1010 "ifparents"  
1011 "ifchildren" 
1012 Those two latest ones should disappear soon.
1013
1014 =back
1015
1016 =cut
1017 sub BuildUnimarcHierarchy{
1018   my $record = shift @_;
1019   my $class = shift @_;
1020   my $authid_constructed = shift @_;
1021   my $authid=$record->subfield('250','3');
1022   my %cell;
1023   my $parents=""; my $children="";
1024   my (@loopparents,@loopchildren);
1025   foreach my $field ($record->field('550')){
1026     if ($field->subfield('5') && $field->subfield('a')){
1027       if ($field->subfield('5') eq 'h'){
1028         push @loopchildren, { "childauthid"=>$field->subfield('3'),"childvalue"=>$field->subfield('a')};
1029       }elsif ($field->subfield('5') eq 'g'){
1030         push @loopparents, { "parentauthid"=>$field->subfield('3'),"parentvalue"=>$field->subfield('a')};
1031       }
1032           # brothers could get in there with an else
1033     }
1034   }
1035   $cell{"ifparents"}=1 if (scalar(@loopparents)>0);
1036   $cell{"ifchildren"}=1 if (scalar(@loopchildren)>0);
1037   $cell{"loopparents"}=\@loopparents if (scalar(@loopparents)>0);
1038   $cell{"loopchildren"}=\@loopchildren if (scalar(@loopchildren)>0);
1039   $cell{"class"}=$class;
1040   $cell{"loopauthid"}=$authid;
1041   $cell{"current_value"} =1 if $authid eq $authid_constructed;
1042   $cell{"value"}=$record->subfield('250',"a");
1043   return \%cell;
1044 }
1045
1046 =head2 GetHeaderAuthority
1047
1048 =over 4
1049
1050 $ref= &GetHeaderAuthority( $authid)
1051 return a hashref in order auth_header table data
1052
1053 =back
1054
1055 =cut
1056 sub GetHeaderAuthority{
1057   my $authid = shift @_;
1058   my $sql= "SELECT * from auth_header WHERE authid = ?";
1059   my $dbh=C4::Context->dbh;
1060   my $rq= $dbh->prepare($sql);
1061   $rq->execute($authid);
1062   my $data= $rq->fetchrow_hashref;
1063   return $data;
1064 }
1065
1066 =head2 AddAuthorityTrees
1067
1068 =over 4
1069
1070 $ref= &AddAuthorityTrees( $authid, $trees)
1071 return success or failure
1072
1073 =back
1074
1075 =cut
1076
1077 sub AddAuthorityTrees{
1078   my $authid = shift @_;
1079   my $trees = shift @_;
1080   my $sql= "UPDATE IGNORE auth_header set authtrees=? WHERE authid = ?";
1081   my $dbh=C4::Context->dbh;
1082   my $rq= $dbh->prepare($sql);
1083   return $rq->execute($trees,$authid);
1084 }
1085
1086 =head2 merge
1087
1088 =over 4
1089
1090 $ref= &merge(mergefrom,$MARCfrom,$mergeto,$MARCto)
1091
1092
1093 Could add some feature : Migrating from a typecode to an other for instance.
1094 Then we should add some new parameter : bibliotargettag, authtargettag
1095
1096 =back
1097
1098 =cut
1099 sub merge {
1100     my ($mergefrom,$MARCfrom,$mergeto,$MARCto) = @_;
1101     my $dbh=C4::Context->dbh;
1102     my $authtypecodefrom = GetAuthTypeCode($mergefrom);
1103     my $authtypecodeto = GetAuthTypeCode($mergeto);
1104     # return if authority does not exist
1105     my @X = $MARCfrom->fields();
1106     return if $#X == -1;
1107     @X = $MARCto->fields();
1108     return if $#X == -1;
1109     # search the tag to report
1110     my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
1111     $sth->execute($authtypecodefrom);
1112     my ($auth_tag_to_report) = $sth->fetchrow;
1113     
1114     my @record_to;
1115     @record_to = $MARCto->field($auth_tag_to_report)->subfields() if $MARCto->field($auth_tag_to_report);
1116     my @record_from;
1117     @record_from = $MARCfrom->field($auth_tag_to_report)->subfields() if $MARCfrom->field($auth_tag_to_report);
1118     
1119     # search all biblio tags using this authority.
1120     $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
1121     $sth->execute($authtypecodefrom);
1122     my @tags_using_authtype;
1123     while (my ($tagfield) = $sth->fetchrow) {
1124         push @tags_using_authtype,$tagfield."9" ;
1125     }
1126
1127     if (C4::Context->preference('NoZebra')) {
1128         warn "MERGE TO DO";
1129     } else {
1130         # now, find every biblio using this authority
1131         my $oConnection=C4::Context->Zconn("biblioserver");
1132         my $query;
1133         $query= "an= ".$mergefrom;
1134         my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
1135         my $count=$oResult->size() if  ($oResult);
1136         my @reccache;
1137         my $z=0;
1138         while ( $z<$count ) {
1139         my $rec;
1140                 $rec=$oResult->record($z);
1141             my $marcdata = $rec->raw();
1142         push @reccache, $marcdata;
1143         $z++;
1144         }
1145         $oResult->destroy();
1146         foreach my $marc(@reccache){
1147             my $update;
1148             my $marcrecord;
1149             $marcrecord = MARC::File::USMARC::decode($marc);
1150             foreach my $tagfield (@tags_using_authtype){
1151             $tagfield=substr($tagfield,0,3);
1152             my @tags = $marcrecord->field($tagfield);
1153             foreach my $tag (@tags){
1154                 my $tagsubs=$tag->subfield("9");
1155             #warn "$tagfield:$tagsubs:$mergefrom";
1156                 if ($tagsubs== $mergefrom) {
1157                 $tag->update("9" =>$mergeto);
1158                 foreach my $subfield (@record_to) {
1159             #        warn "$subfield,$subfield->[0],$subfield->[1]";
1160                     $tag->update($subfield->[0] =>$subfield->[1]);
1161                 }#for $subfield
1162                 }
1163                 $marcrecord->delete_field($tag);
1164                 $marcrecord->add_fields($tag);
1165                 $update=1;
1166             }#for each tag
1167             }#foreach tagfield
1168             my $oldbiblio = TransformMarcToKoha($dbh,$marcrecord,"") ;
1169             if ($update==1){
1170             &ModBiblio($marcrecord,$oldbiblio->{'biblionumber'},GetFrameworkCode($oldbiblio->{'biblionumber'})) ;
1171             }
1172             
1173         }#foreach $marc
1174     }
1175   # now, find every other authority linked with this authority
1176 #   my $oConnection=C4::Context->Zconn("authorityserver");
1177 #   my $query;
1178 # # att 9210               Auth-Internal-authtype
1179 # # att 9220               Auth-Internal-LN
1180 # # ccl.properties to add for authorities
1181 #   $query= "= ".$mergefrom;
1182 #   my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
1183 #   my $count=$oResult->size() if  ($oResult);
1184 #   my @reccache;
1185 #   my $z=0;
1186 #   while ( $z<$count ) {
1187 #   my $rec;
1188 #           $rec=$oResult->record($z);
1189 #       my $marcdata = $rec->raw();
1190 #   push @reccache, $marcdata;
1191 #   $z++;
1192 #   }
1193 #   $oResult->destroy();
1194 #   foreach my $marc(@reccache){
1195 #     my $update;
1196 #     my $marcrecord;
1197 #     $marcrecord = MARC::File::USMARC::decode($marc);
1198 #     foreach my $tagfield (@tags_using_authtype){
1199 #       $tagfield=substr($tagfield,0,3);
1200 #       my @tags = $marcrecord->field($tagfield);
1201 #       foreach my $tag (@tags){
1202 #         my $tagsubs=$tag->subfield("9");
1203 #     #warn "$tagfield:$tagsubs:$mergefrom";
1204 #         if ($tagsubs== $mergefrom) {
1205 #           $tag->update("9" =>$mergeto);
1206 #           foreach my $subfield (@record_to) {
1207 #     #        warn "$subfield,$subfield->[0],$subfield->[1]";
1208 #             $tag->update($subfield->[0] =>$subfield->[1]);
1209 #           }#for $subfield
1210 #         }
1211 #         $marcrecord->delete_field($tag);
1212 #         $marcrecord->add_fields($tag);
1213 #         $update=1;
1214 #       }#for each tag
1215 #     }#foreach tagfield
1216 #     my $authoritynumber = TransformMarcToKoha($dbh,$marcrecord,"") ;
1217 #     if ($update==1){
1218 #       &ModAuthority($marcrecord,$authoritynumber,GetAuthTypeCode($authoritynumber)) ;
1219 #     }
1220
1221 #   }#foreach $marc
1222 }#sub
1223 END { }       # module clean-up code here (global destructor)
1224
1225 =back
1226
1227 =head1 AUTHOR
1228
1229 Koha Developement team <info@koha.org>
1230
1231 Paul POULAIN paul.poulain@free.fr
1232
1233 =cut
1234
1235 # Revision 1.50  2007/07/26 15:14:05  toins
1236 # removing warn compilation.
1237 #
1238 # Revision 1.49  2007/07/16 15:45:28  hdl
1239 # Adding Summary for UNIMARC authorities
1240 #
1241 # Revision 1.48  2007/06/25 15:01:45  tipaul
1242 # bugfixes on unimarc 100 handling (the field used for encoding)
1243 #
1244 # Revision 1.47  2007/06/06 13:08:35  tipaul
1245 # 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-
1246 #
1247 # Revision 1.46  2007/05/10 14:45:15  tipaul
1248 # Koha NoZebra :
1249 # - support for authorities
1250 # - some bugfixes in ordering and "CCL" parsing
1251 # - support for authorities <=> biblios walking
1252 #
1253 # Seems I can do what I want now, so I consider its done, except for bugfixes that will be needed i m sure !
1254 #
1255 # Revision 1.45  2007/04/06 14:48:45  hdl
1256 # Code Cleaning : AuthoritiesMARC.
1257 #
1258 # Revision 1.44  2007/04/05 12:17:55  btoumi
1259 # add "sort by" with heading-entity in authorities search
1260 #
1261 # Revision 1.43  2007/03/30 11:59:16  tipaul
1262 # some cleaning (minor, the main one will come later) : removing some unused subs
1263 #
1264 # Revision 1.42  2007/03/29 16:45:53  tipaul
1265 # Code cleaning of Biblio.pm (continued)
1266 #
1267 # All subs have be cleaned :
1268 # - removed useless
1269 # - merged some
1270 # - reordering Biblio.pm completly
1271 # - using only naming conventions
1272 #
1273 # Seems to have broken nothing, but it still has to be heavily tested.
1274 # Note that Biblio.pm is now much more efficient than previously & probably more reliable as well.
1275 #
1276 # Revision 1.41  2007/03/29 13:30:31  tipaul
1277 # Code cleaning :
1278 # == Biblio.pm cleaning (useless) ==
1279 # * some sub declaration dropped
1280 # * removed modbiblio sub
1281 # * removed moditem sub
1282 # * removed newitems. It was used only in finishrecieve. Replaced by a TransformKohaToMarc+AddItem, that is better.
1283 # * removed MARCkoha2marcItem
1284 # * removed MARCdelsubfield declaration
1285 # * removed MARCkoha2marcBiblio
1286 #
1287 # == Biblio.pm cleaning (naming conventions) ==
1288 # * MARCgettagslib renamed to GetMarcStructure
1289 # * MARCgetitems renamed to GetMarcItem
1290 # * MARCfind_frameworkcode renamed to GetFrameworkCode
1291 # * MARCmarc2koha renamed to TransformMarcToKoha
1292 # * MARChtml2marc renamed to TransformHtmlToMarc
1293 # * MARChtml2xml renamed to TranformeHtmlToXml
1294 # * zebraop renamed to ModZebra
1295 #
1296 # == MARC=OFF ==
1297 # * removing MARC=OFF related scripts (in cataloguing directory)
1298 # * removed checkitems (function related to MARC=off feature, that is completly broken in head. If someone want to reintroduce it, hard work coming...)
1299 # * removed getitemsbybiblioitem (used only by MARC=OFF scripts, that is removed as well)
1300 #
1301 # Revision 1.40  2007/03/28 10:39:16  hdl
1302 # removing $dbh as a parameter in AuthoritiesMarc functions
1303 # And reporting all differences into the scripts taht relies on those functions.
1304 #
1305 # Revision 1.39  2007/03/16 01:25:08  kados
1306 # Using my precrash CVS copy I did the following:
1307 #
1308 # cvs -z3 -d:ext:kados@cvs.savannah.nongnu.org:/sources/koha co -P koha
1309 # find koha.precrash -type d -name "CVS" -exec rm -v {} \;
1310 # cp -r koha.precrash/* koha/
1311 # cd koha/
1312 # cvs commit
1313 #
1314 # This should in theory put us right back where we were before the crash
1315 #
1316 # Revision 1.39  2007/03/12 22:16:31  kados
1317 # chcking for field before calling subfields
1318 #
1319 # Revision 1.38  2007/03/09 14:31:47  tipaul
1320 # rel_3_0 moved to HEAD
1321 #
1322 # Revision 1.28.2.17  2007/02/05 13:16:08  hdl
1323 # Removing Link from AuthoritiesMARC summary (caused a problem owed to the API differences between opac and intranet)
1324 # + removing $dbh in SearchAuthorities
1325 # + adding links in templates on summaries to go to full view.
1326 # (no more links in popup authorities. or should we add it ?)
1327 #
1328 # Revision 1.28.2.16  2007/02/02 18:07:42  hdl
1329 # Sorting and searching for exact term now works.
1330 #
1331 # Revision 1.28.2.15  2007/01/24 10:17:47  hdl
1332 # FindDuplicate Now works.
1333 # Be AWARE that it needs a change ccl.properties.
1334 #
1335 # Revision 1.28.2.14  2007/01/10 14:40:11  hdl
1336 # Adding Authorities tree.
1337 #
1338 # Revision 1.28.2.13  2007/01/09 15:18:09  hdl
1339 # Adding an to ccl.properties to allow ccl search for authority-numbers.
1340 # Fixing Some problems with the previous modification to allow pqf search to work for more than one page.
1341 # Using search for an= for an authority-Number.
1342 #
1343 # Revision 1.28.2.12  2007/01/09 13:51:31  hdl
1344 # Bug Fixing : CountUsage used *synchronous* connection where biblio used ****asynchronous**** one.
1345 # First try to get it work.
1346 #
1347 # Revision 1.28.2.11  2007/01/05 14:37:26  btoumi
1348 # bug fix : remove wrong field in sql syntaxe from auth_subfield_structure table
1349 #
1350 # Revision 1.28.2.10  2007/01/04 13:11:08  tipaul
1351 # commenting 2 zconn destroy
1352 #
1353 # Revision 1.28.2.9  2006/12/22 15:09:53  toins
1354 # removing C4::Database;
1355 #
1356 # Revision 1.28.2.8  2006/12/20 17:13:19  hdl
1357 # modifying use of GILS into use of @attr 1=Koha-Auth-Number
1358 #
1359 # Revision 1.28.2.7  2006/12/18 16:45:38  tipaul
1360 # FIXME upcased
1361 #
1362 # Revision 1.28.2.6  2006/12/07 16:45:43  toins
1363 # removing warn compilation. (perl -wc)
1364 #
1365 # Revision 1.28.2.5  2006/12/06 14:19:59  hdl
1366 # ABugFixing : Authority count  Management.
1367 #
1368 # Revision 1.28.2.4  2006/11/17 13:18:58  tipaul
1369 # code cleaning : removing use of "bib", and replacing with "biblionumber"
1370 #
1371 # WARNING : I tried to do carefully, but there are probably some mistakes.
1372 # So if you encounter a problem you didn't have before, look for this change !!!
1373 # anyway, I urge everybody to use only "biblionumber", instead of "bib", "bi", "biblio" or anything else. will be easier to maintain !!!
1374 #
1375 # Revision 1.28.2.3  2006/11/17 11:17:30  tipaul
1376 # code cleaning : removing use of "bib", and replacing with "biblionumber"
1377 #
1378 # WARNING : I tried to do carefully, but there are probably some mistakes.
1379 # So if you encounter a problem you didn't have before, look for this change !!!
1380 # anyway, I urge everybody to use only "biblionumber", instead of "bib", "bi", "biblio" or anything else. will be easier to maintain !!!
1381 #
1382 # Revision 1.28.2.2  2006/10/12 22:04:47  hdl
1383 # Authorities working with zebra.
1384 # zebra Configuration files are comitted next.