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