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