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