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