3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
24 use MARC::File::USMARC;
25 # Force MARC::File::XML to use LibXML SAX Parser
26 $XML::SAX::ParserPackage = "XML::LibXML::SAX";
27 require MARC::File::XML;
31 use C4::Dates qw/format_date/;
32 use C4::Log; # logaction
36 use vars qw($VERSION @ISA @EXPORT);
42 @ISA = qw( Exporter );
56 &GetBiblioItemByBiblioNumber
57 &GetBiblioFromItemNumber
68 &GetAuthorisedValueDesc
72 &GetPublisherNameFromIsbn
87 # To link headings in a bib record
88 # to authority records.
90 &LinkBibHeadingsToAuthorities
94 # those functions are exported but should not be used
95 # they are usefull is few circumstances, so are exported.
96 # but don't use them unless you're a core developer ;-)
103 &TransformHtmlToMarc2
106 &PrepareItemrecordDisplay
113 C4::Biblio - cataloging management functions
117 Biblio.pm contains functions for managing storage and editing of bibliographic data within Koha. Most of the functions in this module are used for cataloging records: adding, editing, or removing biblios, biblioitems, or items. Koha's stores bibliographic information in three places:
121 =item 1. in the biblio,biblioitems,items, etc tables, which are limited to a one-to-one mapping to underlying MARC data
123 =item 2. as raw MARC in the Zebra index and storage engine
125 =item 3. as raw MARC the biblioitems.marc and biblioitems.marcxml
129 In the 3.0 version of Koha, the authoritative record-level information is in biblioitems.marcxml
131 Because the data isn't completely normalized there's a chance for information to get out of sync. The design choice to go with a un-normalized schema was driven by performance and stability concerns. However, if this occur, it can be considered as a bug : The API is (or should be) complete & the only entry point for all biblio/items managements.
135 =item 1. Compared with MySQL, Zebra is slow to update an index for small data changes -- especially for proc-intensive operations like circulation
137 =item 2. Zebra's index has been known to crash and a backup of the data is necessary to rebuild it in such cases
141 Because of this design choice, the process of managing storage and editing is a bit convoluted. Historically, Biblio.pm's grown to an unmanagable size and as a result we have several types of functions currently:
145 =item 1. Add*/Mod*/Del*/ - high-level external functions suitable for being called from external scripts to manage the collection
147 =item 2. _koha_* - low-level internal functions for managing the koha tables
149 =item 3. Marc management function : as the MARC record is stored in biblioitems.marc(xml), some subs dedicated to it's management are in this package. They should be used only internally by Biblio.pm, the only official entry points being AddBiblio, AddItem, ModBiblio, ModItem.
151 =item 4. Zebra functions used to update the Zebra index
153 =item 5. internal helper functions such as char_decode, checkitems, etc. Some of these probably belong in Koha.pm
157 The MARC record (in biblioitems.marcxml) contains the complete marc record, including items. It also contains the biblionumber. That is the reason why it is not stored directly by AddBiblio, with all other fields . To save a biblio, we need to :
161 =item 1. save datas in biblio and biblioitems table, that gives us a biblionumber and a biblioitemnumber
163 =item 2. add the biblionumber and biblioitemnumber into the MARC records
165 =item 3. save the marc record
169 When dealing with items, we must :
173 =item 1. save the item in items table, that gives us an itemnumber
175 =item 2. add the itemnumber to the item MARC field
177 =item 3. overwrite the MARC record (with the added item) into biblioitems.marc(xml)
179 When modifying a biblio or an item, the behaviour is quite similar.
183 =head1 EXPORTED FUNCTIONS
189 ($biblionumber,$biblioitemnumber) = AddBiblio($record,$frameworkcode);
193 Exported function (core API) for adding a new biblio to koha.
195 The first argument is a C<MARC::Record> object containing the
196 bib to add, while the second argument is the desired MARC
199 This function also accepts a third, optional argument: a hashref
200 to additional options. The only defined option is C<defer_marc_save>,
201 which if present and mapped to a true value, causes C<AddBiblio>
202 to omit the call to save the MARC in C<bibilioitems.marc>
203 and C<biblioitems.marcxml> This option is provided B<only>
204 for the use of scripts such as C<bulkmarcimport.pl> that may need
205 to do some manipulation of the MARC record for item parsing before
206 saving it and which cannot afford the performance hit of saving
207 the MARC record twice. Consequently, do not use that option
208 unless you can guarantee that C<ModBiblioMarc> will be called.
214 my $frameworkcode = shift;
215 my $options = @_ ? shift : undef;
216 my $defer_marc_save = 0;
217 if (defined $options and exists $options->{'defer_marc_save'} and $options->{'defer_marc_save'}) {
218 $defer_marc_save = 1;
221 my ($biblionumber,$biblioitemnumber,$error);
222 my $dbh = C4::Context->dbh;
223 # transform the data into koha-table style data
224 my $olddata = TransformMarcToKoha( $dbh, $record, $frameworkcode );
225 ($biblionumber,$error) = _koha_add_biblio( $dbh, $olddata, $frameworkcode );
226 $olddata->{'biblionumber'} = $biblionumber;
227 ($biblioitemnumber,$error) = _koha_add_biblioitem( $dbh, $olddata );
229 _koha_marc_update_bib_ids($record, $frameworkcode, $biblionumber, $biblioitemnumber);
231 # update MARC subfield that stores biblioitems.cn_sort
232 _koha_marc_update_biblioitem_cn_sort($record, $olddata, $frameworkcode);
235 $biblionumber = ModBiblioMarc( $record, $biblionumber, $frameworkcode ) unless $defer_marc_save;
237 logaction("CATALOGUING", "ADD", $biblionumber, "biblio") if C4::Context->preference("CataloguingLog");
239 return ( $biblionumber, $biblioitemnumber );
246 ModBiblio( $record,$biblionumber,$frameworkcode);
250 Replace an existing bib record identified by C<$biblionumber>
251 with one supplied by the MARC::Record object C<$record>. The embedded
252 item, biblioitem, and biblionumber fields from the previous
253 version of the bib record replace any such fields of those tags that
254 are present in C<$record>. Consequently, ModBiblio() is not
255 to be used to try to modify item records.
257 C<$frameworkcode> specifies the MARC framework to use
258 when storing the modified bib record; among other things,
259 this controls how MARC fields get mapped to display columns
260 in the C<biblio> and C<biblioitems> tables, as well as
261 which fields are used to store embedded item, biblioitem,
262 and biblionumber data for indexing.
267 my ( $record, $biblionumber, $frameworkcode ) = @_;
268 if (C4::Context->preference("CataloguingLog")) {
269 my $newrecord = GetMarcBiblio($biblionumber);
270 logaction("CATALOGUING", "MODIFY", $biblionumber, "BEFORE=>".$newrecord->as_formatted);
273 my $dbh = C4::Context->dbh;
275 $frameworkcode = "" unless $frameworkcode;
277 # get the items before and append them to the biblio before updating the record, atm we just have the biblio
278 my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",$frameworkcode);
279 my $oldRecord = GetMarcBiblio( $biblionumber );
281 # delete any item fields from incoming record to avoid
282 # duplication or incorrect data - use AddItem() or ModItem()
284 foreach my $field ($record->field($itemtag)) {
285 $record->delete_field($field);
288 # parse each item, and, for an unknown reason, re-encode each subfield
289 # if you don't do that, the record will have encoding mixed
290 # and the biblio will be re-encoded.
291 # strange, I (Paul P.) searched more than 1 day to understand what happends
292 # but could only solve the problem this way...
293 my @fields = $oldRecord->field( $itemtag );
294 foreach my $fielditem ( @fields ){
296 foreach ($fielditem->subfields()) {
298 $field->add_subfields(Encode::encode('utf-8',$_->[0]) => Encode::encode('utf-8',$_->[1]));
300 $field = MARC::Field->new("$itemtag",'','',Encode::encode('utf-8',$_->[0]) => Encode::encode('utf-8',$_->[1]));
303 $record->append_fields($field);
306 # update biblionumber and biblioitemnumber in MARC
307 # FIXME - this is assuming a 1 to 1 relationship between
308 # biblios and biblioitems
309 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
310 $sth->execute($biblionumber);
311 my ($biblioitemnumber) = $sth->fetchrow;
313 _koha_marc_update_bib_ids($record, $frameworkcode, $biblionumber, $biblioitemnumber);
315 # load the koha-table data object
316 my $oldbiblio = TransformMarcToKoha( $dbh, $record, $frameworkcode );
318 # update MARC subfield that stores biblioitems.cn_sort
319 _koha_marc_update_biblioitem_cn_sort($record, $oldbiblio, $frameworkcode);
321 # update the MARC record (that now contains biblio and items) with the new record data
322 &ModBiblioMarc( $record, $biblionumber, $frameworkcode );
324 # modify the other koha tables
325 _koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode );
326 _koha_modify_biblioitem_nonmarc( $dbh, $oldbiblio );
330 =head2 ModBiblioframework
332 ModBiblioframework($biblionumber,$frameworkcode);
333 Exported function to modify a biblio framework
337 sub ModBiblioframework {
338 my ( $biblionumber, $frameworkcode ) = @_;
339 my $dbh = C4::Context->dbh;
340 my $sth = $dbh->prepare(
341 "UPDATE biblio SET frameworkcode=? WHERE biblionumber=?"
343 $sth->execute($frameworkcode, $biblionumber);
351 my $error = &DelBiblio($dbh,$biblionumber);
352 Exported function (core API) for deleting a biblio in koha.
353 Deletes biblio record from Zebra and Koha tables (biblio,biblioitems,items)
354 Also backs it up to deleted* tables
355 Checks to make sure there are not issues on any of the items
357 C<$error> : undef unless an error occurs
364 my ( $biblionumber ) = @_;
365 my $dbh = C4::Context->dbh;
366 my $error; # for error handling
368 # First make sure this biblio has no items attached
369 my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber=?");
370 $sth->execute($biblionumber);
371 if (my $itemnumber = $sth->fetchrow){
372 # Fix this to use a status the template can understand
373 $error .= "This Biblio has items attached, please delete them first before deleting this biblio ";
376 return $error if $error;
378 # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
379 # for at least 2 reasons :
380 # - we need to read the biblio if NoZebra is set (to remove it from the indexes
381 # - if something goes wrong, the biblio may be deleted from Koha but not from zebra
382 # and we would have no way to remove it (except manually in zebra, but I bet it would be very hard to handle the problem)
384 if (C4::Context->preference("NoZebra")) {
385 # only NoZebra indexing needs to have
386 # the previous version of the record
387 $oldRecord = GetMarcBiblio($biblionumber);
389 ModZebra($biblionumber, "recordDelete", "biblioserver", $oldRecord, undef);
391 # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
394 "SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
395 $sth->execute($biblionumber);
396 while ( my $biblioitemnumber = $sth->fetchrow ) {
398 # delete this biblioitem
399 $error = _koha_delete_biblioitems( $dbh, $biblioitemnumber );
400 return $error if $error;
403 # delete biblio from Koha tables and save in deletedbiblio
404 # must do this *after* _koha_delete_biblioitems, otherwise
405 # delete cascade will prevent deletedbiblioitems rows
406 # from being generated by _koha_delete_biblioitems
407 $error = _koha_delete_biblio( $dbh, $biblionumber );
409 logaction("CATALOGUING", "DELETE", $biblionumber, "") if C4::Context->preference("CataloguingLog");
414 =head2 LinkBibHeadingsToAuthorities
418 my $headings_linked = LinkBibHeadingsToAuthorities($marc);
422 Links bib headings to authority records by checking
423 each authority-controlled field in the C<MARC::Record>
424 object C<$marc>, looking for a matching authority record,
425 and setting the linking subfield $9 to the ID of that
428 If no matching authority exists, or if multiple
429 authorities match, no $9 will be added, and any
430 existing one inthe field will be deleted.
432 Returns the number of heading links changed in the
437 sub LinkBibHeadingsToAuthorities {
440 my $num_headings_changed = 0;
441 foreach my $field ($bib->fields()) {
442 my $heading = C4::Heading->new_from_bib_field($field);
443 next unless defined $heading;
446 my $current_link = $field->subfield('9');
448 # look for matching authorities
449 my $authorities = $heading->authorities();
451 # want only one exact match
452 if ($#{ $authorities } == 0) {
453 my $authority = MARC::Record->new_from_usmarc($authorities->[0]);
454 my $authid = $authority->field('001')->data();
455 next if defined $current_link and $current_link eq $authid;
457 $field->delete_subfield(code => '9') if defined $current_link;
458 $field->add_subfields('9', $authid);
459 $num_headings_changed++;
461 if (defined $current_link) {
462 $field->delete_subfield(code => '9');
463 $num_headings_changed++;
468 return $num_headings_changed;
475 $data = &GetBiblioData($biblionumber);
476 Returns information about the book with the given biblionumber.
477 C<&GetBiblioData> returns a reference-to-hash. The keys are the fields in
478 the C<biblio> and C<biblioitems> tables in the
480 In addition, C<$data-E<gt>{subject}> is the list of the book's
481 subjects, separated by C<" , "> (space, comma, space).
482 If there are multiple biblioitems with the given biblionumber, only
483 the first one is considered.
491 my $dbh = C4::Context->dbh;
493 # my $query = C4::Context->preference('item-level_itypes') ?
494 # " SELECT * , biblioitems.notes AS bnotes, biblio.notes
496 # LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
497 # WHERE biblio.biblionumber = ?
498 # AND biblioitems.biblionumber = biblio.biblionumber
501 my $query = " SELECT * , biblioitems.notes AS bnotes, itemtypes.notforloan as bi_notforloan, biblio.notes
503 LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
504 LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype
505 WHERE biblio.biblionumber = ?
506 AND biblioitems.biblionumber = biblio.biblionumber ";
508 my $sth = $dbh->prepare($query);
509 $sth->execute($bibnum);
511 $data = $sth->fetchrow_hashref;
515 } # sub GetBiblioData
517 =head2 &GetBiblioItemData
521 $itemdata = &GetBiblioItemData($biblioitemnumber);
523 Looks up the biblioitem with the given biblioitemnumber. Returns a
524 reference-to-hash. The keys are the fields from the C<biblio>,
525 C<biblioitems>, and C<itemtypes> tables in the Koha database, except
526 that C<biblioitems.notes> is given as C<$itemdata-E<gt>{bnotes}>.
533 sub GetBiblioItemData {
534 my ($biblioitemnumber) = @_;
535 my $dbh = C4::Context->dbh;
536 my $query = "SELECT *,biblioitems.notes AS bnotes
537 FROM biblio LEFT JOIN biblioitems on biblio.biblionumber=biblioitems.biblionumber ";
538 unless(C4::Context->preference('item-level_itypes')) {
539 $query .= "LEFT JOIN itemtypes on biblioitems.itemtype=itemtypes.itemtype ";
541 $query .= " WHERE biblioitemnumber = ? ";
542 my $sth = $dbh->prepare($query);
544 $sth->execute($biblioitemnumber);
545 $data = $sth->fetchrow_hashref;
548 } # sub &GetBiblioItemData
550 =head2 GetBiblioItemByBiblioNumber
554 NOTE : This function has been copy/paste from C4/Biblio.pm from head before zebra integration.
560 sub GetBiblioItemByBiblioNumber {
561 my ($biblionumber) = @_;
562 my $dbh = C4::Context->dbh;
563 my $sth = $dbh->prepare("Select * FROM biblioitems WHERE biblionumber = ?");
567 $sth->execute($biblionumber);
569 while ( my $data = $sth->fetchrow_hashref ) {
570 push @results, $data;
577 =head2 GetBiblioFromItemNumber
581 $item = &GetBiblioFromItemNumber($itemnumber,$barcode);
583 Looks up the item with the given itemnumber. if undef, try the barcode.
585 C<&itemnodata> returns a reference-to-hash whose keys are the fields
586 from the C<biblio>, C<biblioitems>, and C<items> tables in the Koha
594 sub GetBiblioFromItemNumber {
595 my ( $itemnumber, $barcode ) = @_;
596 my $dbh = C4::Context->dbh;
599 $sth=$dbh->prepare( "SELECT * FROM items
600 LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
601 LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
602 WHERE items.itemnumber = ?") ;
603 $sth->execute($itemnumber);
605 $sth=$dbh->prepare( "SELECT * FROM items
606 LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
607 LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
608 WHERE items.barcode = ?") ;
609 $sth->execute($barcode);
611 my $data = $sth->fetchrow_hashref;
620 ( $count, @results ) = &GetBiblio($biblionumber);
627 my ($biblionumber) = @_;
628 my $dbh = C4::Context->dbh;
629 my $sth = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber = ?");
632 $sth->execute($biblionumber);
633 while ( my $data = $sth->fetchrow_hashref ) {
634 $results[$count] = $data;
638 return ( $count, @results );
641 =head2 GetBiblioItemInfosOf
645 GetBiblioItemInfosOf(@biblioitemnumbers);
651 sub GetBiblioItemInfosOf {
652 my @biblioitemnumbers = @_;
655 SELECT biblioitemnumber,
659 WHERE biblioitemnumber IN (' . join( ',', @biblioitemnumbers ) . ')
661 return get_infos_of( $query, 'biblioitemnumber' );
664 =head1 FUNCTIONS FOR HANDLING MARC MANAGEMENT
666 =head2 GetMarcStructure
670 $res = GetMarcStructure($forlibrarian,$frameworkcode);
672 Returns a reference to a big hash of hash, with the Marc structure for the given frameworkcode
673 $forlibrarian :if set to 1, the MARC descriptions are the librarians ones, otherwise it's the public (OPAC) ones
674 $frameworkcode : the framework code to read
680 # cache for results of GetMarcStructure -- needed
682 our $marc_structure_cache;
684 sub GetMarcStructure {
685 my ( $forlibrarian, $frameworkcode ) = @_;
686 my $dbh=C4::Context->dbh;
687 $frameworkcode = "" unless $frameworkcode;
689 if (defined $marc_structure_cache and exists $marc_structure_cache->{$forlibrarian}->{$frameworkcode}) {
690 return $marc_structure_cache->{$forlibrarian}->{$frameworkcode};
694 my $libfield = ( $forlibrarian eq 1 ) ? 'liblibrarian' : 'libopac';
696 # check that framework exists
699 "SELECT COUNT(*) FROM marc_tag_structure WHERE frameworkcode=?");
700 $sth->execute($frameworkcode);
701 my ($total) = $sth->fetchrow;
702 $frameworkcode = "" unless ( $total > 0 );
705 "SELECT tagfield,liblibrarian,libopac,mandatory,repeatable
706 FROM marc_tag_structure
707 WHERE frameworkcode=?
710 $sth->execute($frameworkcode);
711 my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable );
713 while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable ) =
716 $res->{$tag}->{lib} =
717 ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac;
718 $res->{$tag}->{tab} = "";
719 $res->{$tag}->{mandatory} = $mandatory;
720 $res->{$tag}->{repeatable} = $repeatable;
725 "SELECT tagfield,tagsubfield,liblibrarian,libopac,tab,mandatory,repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link,defaultvalue
726 FROM marc_subfield_structure
727 WHERE frameworkcode=?
728 ORDER BY tagfield,tagsubfield
732 $sth->execute($frameworkcode);
735 my $authorised_value;
747 $tag, $subfield, $liblibrarian,
749 $mandatory, $repeatable, $authorised_value,
750 $authtypecode, $value_builder, $kohafield,
751 $seealso, $hidden, $isurl,
757 $res->{$tag}->{$subfield}->{lib} =
758 ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac;
759 $res->{$tag}->{$subfield}->{tab} = $tab;
760 $res->{$tag}->{$subfield}->{mandatory} = $mandatory;
761 $res->{$tag}->{$subfield}->{repeatable} = $repeatable;
762 $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
763 $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode;
764 $res->{$tag}->{$subfield}->{value_builder} = $value_builder;
765 $res->{$tag}->{$subfield}->{kohafield} = $kohafield;
766 $res->{$tag}->{$subfield}->{seealso} = $seealso;
767 $res->{$tag}->{$subfield}->{hidden} = $hidden;
768 $res->{$tag}->{$subfield}->{isurl} = $isurl;
769 $res->{$tag}->{$subfield}->{'link'} = $link;
770 $res->{$tag}->{$subfield}->{defaultvalue} = $defaultvalue;
773 $marc_structure_cache->{$forlibrarian}->{$frameworkcode} = $res;
778 =head2 GetUsedMarcStructure
780 the same function as GetMarcStructure expcet it just take field
781 in tab 0-9. (used field)
783 my $results = GetUsedMarcStructure($frameworkcode);
785 L<$results> is a ref to an array which each case containts a ref
786 to a hash which each keys is the columns from marc_subfield_structure
788 L<$frameworkcode> is the framework code.
792 sub GetUsedMarcStructure($){
793 my $frameworkcode = shift || '';
794 my $dbh = C4::Context->dbh;
797 FROM marc_subfield_structure
799 AND frameworkcode = ?
802 my $sth = $dbh->prepare($query);
803 $sth->execute($frameworkcode);
804 while (my $row = $sth->fetchrow_hashref){
810 =head2 GetMarcFromKohaField
814 ($MARCfield,$MARCsubfield)=GetMarcFromKohaField($kohafield,$frameworkcode);
815 Returns the MARC fields & subfields mapped to the koha field
816 for the given frameworkcode
822 sub GetMarcFromKohaField {
823 my ( $kohafield, $frameworkcode ) = @_;
824 return 0, 0 unless $kohafield;
825 my $relations = C4::Context->marcfromkohafield;
827 $relations->{$frameworkcode}->{$kohafield}->[0],
828 $relations->{$frameworkcode}->{$kohafield}->[1]
836 my $record = GetMarcBiblio($biblionumber);
840 Returns MARC::Record representing bib identified by
841 C<$biblionumber>. If no bib exists, returns undef.
842 The MARC record contains both biblio & item data.
847 my $biblionumber = shift;
848 my $dbh = C4::Context->dbh;
850 $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? ");
851 $sth->execute($biblionumber);
852 my $row = $sth->fetchrow_hashref;
853 my $marcxml = StripNonXmlChars($row->{'marcxml'});
854 MARC::File::XML->default_record_format(C4::Context->preference('marcflavour'));
855 my $record = MARC::Record->new();
857 $record = eval {MARC::Record::new_from_xml( $marcxml, "utf8", C4::Context->preference('marcflavour'))};
858 if ($@) {warn " problem with :$biblionumber : $@ \n$marcxml";}
859 # $record = MARC::Record::new_from_usmarc( $marc) if $marc;
870 my $marcxml = GetXmlBiblio($biblionumber);
872 Returns biblioitems.marcxml of the biblionumber passed in parameter.
873 The XML contains both biblio & item datas
880 my ( $biblionumber ) = @_;
881 my $dbh = C4::Context->dbh;
883 $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? ");
884 $sth->execute($biblionumber);
885 my ($marcxml) = $sth->fetchrow;
889 =head2 GetAuthorisedValueDesc
893 my $subfieldvalue =get_authorised_value_desc(
894 $tag, $subf[$i][0],$subf[$i][1], '', $taglib, $category);
895 Retrieve the complete description for a given authorised value.
897 Now takes $category and $value pair too.
898 my $auth_value_desc =GetAuthorisedValueDesc(
899 '','', 'DVD' ,'','','CCODE');
905 sub GetAuthorisedValueDesc {
906 my ( $tag, $subfield, $value, $framework, $tagslib, $category ) = @_;
907 my $dbh = C4::Context->dbh;
911 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
912 return C4::Branch::GetBranchName($value);
916 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
917 return getitemtypeinfo($value)->{description};
920 #---- "true" authorized value
921 $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'}
924 if ( $category ne "" ) {
927 "SELECT lib FROM authorised_values WHERE category = ? AND authorised_value = ?"
929 $sth->execute( $category, $value );
930 my $data = $sth->fetchrow_hashref;
931 return $data->{'lib'};
934 return $value; # if nothing is found return the original value
942 $marcnotesarray = GetMarcNotes( $record, $marcflavour );
943 Get all notes from the MARC record and returns them in an array.
944 The note are stored in differents places depending on MARC flavour
951 my ( $record, $marcflavour ) = @_;
953 if ( $marcflavour eq "MARC21" ) {
956 else { # assume unimarc if not marc21
963 foreach my $field ( $record->field($scope) ) {
964 my $value = $field->as_string();
966 $marcnote = { marcnote => $note, };
967 push @marcnotes, $marcnote;
970 if ( $note ne $value ) {
971 $note = $note . " " . $value;
976 $marcnote = { marcnote => $note };
977 push @marcnotes, $marcnote; #load last tag into array
982 =head2 GetMarcSubjects
986 $marcsubjcts = GetMarcSubjects($record,$marcflavour);
987 Get all subjects from the MARC record and returns them in an array.
988 The subjects are stored in differents places depending on MARC flavour
994 sub GetMarcSubjects {
995 my ( $record, $marcflavour ) = @_;
996 my ( $mintag, $maxtag );
997 if ( $marcflavour eq "MARC21" ) {
1001 else { # assume unimarc if not marc21
1011 foreach my $field ( $record->field('6..' )) {
1012 next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1014 my @subfields = $field->subfields();
1017 # if there is an authority link, build the link with an= subfield9
1018 my $subfield9 = $field->subfield('9');
1019 for my $subject_subfield (@subfields ) {
1020 # don't load unimarc subfields 3,4,5
1021 next if (($marcflavour eq "UNIMARC") and ($subject_subfield->[0] =~ /3|4|5/ ) );
1022 my $code = $subject_subfield->[0];
1023 my $value = $subject_subfield->[1];
1024 my $linkvalue = $value;
1025 $linkvalue =~ s/(\(|\))//g;
1026 my $operator = " and " unless $counter==0;
1028 @link_loop = ({'limit' => 'an' ,link => "$subfield9" });
1030 push @link_loop, {'limit' => 'su', link => $linkvalue, operator => $operator };
1032 my $separator = C4::Context->preference("authoritysep") unless $counter==0;
1034 my @this_link_loop = @link_loop;
1035 push @subfields_loop, {code => $code, value => $value, link_loop => \@this_link_loop, separator => $separator} unless ($subject_subfield->[0] eq 9 );
1039 push @marcsubjects, { MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop };
1042 return \@marcsubjects;
1043 } #end getMARCsubjects
1045 =head2 GetMarcAuthors
1049 authors = GetMarcAuthors($record,$marcflavour);
1050 Get all authors from the MARC record and returns them in an array.
1051 The authors are stored in differents places depending on MARC flavour
1057 sub GetMarcAuthors {
1058 my ( $record, $marcflavour ) = @_;
1059 my ( $mintag, $maxtag );
1060 # tagslib useful for UNIMARC author reponsabilities
1061 my $tagslib = &GetMarcStructure( 1, '' ); # FIXME : we don't have the framework available, we take the default framework. May be bugguy on some setups, will be usually correct.
1062 if ( $marcflavour eq "MARC21" ) {
1066 elsif ( $marcflavour eq "UNIMARC" ) { # assume unimarc if not marc21
1075 foreach my $field ( $record->fields ) {
1076 next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1079 my @subfields = $field->subfields();
1081 # if there is an authority link, build the link with Koha-Auth-Number: subfield9
1082 my $subfield9 = $field->subfield('9');
1083 for my $authors_subfield (@subfields) {
1084 # don't load unimarc subfields 3, 5
1085 next if ($marcflavour eq 'UNIMARC' and ($authors_subfield->[0] =~ /3|5/ ) );
1086 my $subfieldcode = $authors_subfield->[0];
1087 my $value = $authors_subfield->[1];
1088 my $linkvalue = $value;
1089 $linkvalue =~ s/(\(|\))//g;
1090 my $operator = " and " unless $count_auth==0;
1091 # if we have an authority link, use that as the link, otherwise use standard searching
1093 @link_loop = ({'limit' => 'an' ,link => "$subfield9" });
1096 # reset $linkvalue if UNIMARC author responsibility
1097 if ( $marcflavour eq 'UNIMARC' and ($authors_subfield->[0] eq "4")) {
1098 $linkvalue = "(".GetAuthorisedValueDesc( $field->tag(), $authors_subfield->[0], $authors_subfield->[1], '', $tagslib ).")";
1100 push @link_loop, {'limit' => 'au', link => $linkvalue, operator => $operator };
1102 $value = GetAuthorisedValueDesc( $field->tag(), $authors_subfield->[0], $authors_subfield->[1], '', $tagslib ) if ( $marcflavour eq 'UNIMARC' and ($authors_subfield->[0] =~/4/));
1103 my @this_link_loop = @link_loop;
1104 my $separator = C4::Context->preference("authoritysep") unless $count_auth==0;
1105 push @subfields_loop, {code => $subfieldcode, value => $value, link_loop => \@this_link_loop, separator => $separator} unless ($authors_subfield->[0] == 9 );
1108 push @marcauthors, { MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop };
1110 return \@marcauthors;
1117 $marcurls = GetMarcUrls($record,$marcflavour);
1118 Returns arrayref of URLs from MARC data, suitable to pass to tmpl loop.
1119 Assumes web resources (not uncommon in MARC21 to omit resource type ind)
1126 my ($record, $marcflavour) = @_;
1129 for my $field ($record->field('856')) {
1130 my $url = $field->subfield('u');
1132 for my $note ( $field->subfield('z')) {
1133 push @notes , {note => $note};
1135 if($marcflavour eq 'MARC21') {
1136 my $s3 = $field->subfield('3');
1137 my $link = $field->subfield('y');
1138 unless($url =~ /^\w+:/) {
1139 if($field->indicator(1) eq '7') {
1140 $url = $field->subfield('2') . "://" . $url;
1141 } elsif ($field->indicator(1) eq '1') {
1142 $url = 'ftp://' . $url;
1144 # properly, this should be if ind1=4,
1145 # however we will assume http protocol since we're building a link.
1146 $url = 'http://' . $url;
1149 # TODO handle ind 2 (relationship)
1150 $marcurl = { MARCURL => $url,
1153 $marcurl->{'linktext'} = $link || $s3 || C4::Context->preference('URLLinkText') || $url ;;
1154 $marcurl->{'part'} = $s3 if($link);
1155 $marcurl->{'toc'} = 1 if($s3 =~ /^[Tt]able/) ;
1157 $marcurl->{'linktext'} = $url || C4::Context->preference('URLLinkText') ;
1159 push @marcurls, $marcurl;
1164 =head2 GetMarcSeries
1168 $marcseriesarray = GetMarcSeries($record,$marcflavour);
1169 Get all series from the MARC record and returns them in an array.
1170 The series are stored in differents places depending on MARC flavour
1177 my ($record, $marcflavour) = @_;
1178 my ($mintag, $maxtag);
1179 if ($marcflavour eq "MARC21") {
1182 } else { # assume unimarc if not marc21
1192 foreach my $field ($record->field('440'), $record->field('490')) {
1194 #my $value = $field->subfield('a');
1195 #$marcsubjct = {MARCSUBJCT => $value,};
1196 my @subfields = $field->subfields();
1197 #warn "subfields:".join " ", @$subfields;
1200 for my $series_subfield (@subfields) {
1202 undef $volume_number;
1203 # see if this is an instance of a volume
1204 if ($series_subfield->[0] eq 'v') {
1208 my $code = $series_subfield->[0];
1209 my $value = $series_subfield->[1];
1210 my $linkvalue = $value;
1211 $linkvalue =~ s/(\(|\))//g;
1212 my $operator = " and " unless $counter==0;
1213 push @link_loop, {link => $linkvalue, operator => $operator };
1214 my $separator = C4::Context->preference("authoritysep") unless $counter==0;
1215 if ($volume_number) {
1216 push @subfields_loop, {volumenum => $value};
1219 push @subfields_loop, {code => $code, value => $value, link_loop => \@link_loop, separator => $separator, volumenum => $volume_number};
1223 push @marcseries, { MARCSERIES_SUBFIELDS_LOOP => \@subfields_loop };
1224 #$marcsubjct = {MARCSUBJCT => $field->as_string(),};
1225 #push @marcsubjcts, $marcsubjct;
1229 my $marcseriessarray=\@marcseries;
1230 return $marcseriessarray;
1231 } #end getMARCseriess
1233 =head2 GetFrameworkCode
1237 $frameworkcode = GetFrameworkCode( $biblionumber )
1243 sub GetFrameworkCode {
1244 my ( $biblionumber ) = @_;
1245 my $dbh = C4::Context->dbh;
1246 my $sth = $dbh->prepare("SELECT frameworkcode FROM biblio WHERE biblionumber=?");
1247 $sth->execute($biblionumber);
1248 my ($frameworkcode) = $sth->fetchrow;
1249 return $frameworkcode;
1252 =head2 GetPublisherNameFromIsbn
1254 $name = GetPublishercodeFromIsbn($isbn);
1261 sub GetPublisherNameFromIsbn($){
1263 $isbn =~ s/[- _]//g;
1265 my @codes = (split '-', DisplayISBN($isbn));
1266 my $code = $codes[0].$codes[1].$codes[2];
1267 my $dbh = C4::Context->dbh;
1269 SELECT distinct publishercode
1272 AND publishercode IS NOT NULL
1275 my $sth = $dbh->prepare($query);
1276 $sth->execute("$code%");
1277 my $name = $sth->fetchrow;
1278 return $name if length $name;
1282 =head2 TransformKohaToMarc
1286 $record = TransformKohaToMarc( $hash )
1287 This function builds partial MARC::Record from a hash
1288 Hash entries can be from biblio or biblioitems.
1289 This function is called in acquisition module, to create a basic catalogue entry from user entry
1295 sub TransformKohaToMarc {
1298 my $dbh = C4::Context->dbh;
1301 "SELECT tagfield,tagsubfield FROM marc_subfield_structure WHERE frameworkcode=? AND kohafield=?"
1303 my $record = MARC::Record->new();
1304 foreach (keys %{$hash}) {
1305 &TransformKohaToMarcOneField( $sth, $record, $_,
1311 =head2 TransformKohaToMarcOneField
1315 $record = TransformKohaToMarcOneField( $sth, $record, $kohafieldname, $value, $frameworkcode );
1321 sub TransformKohaToMarcOneField {
1322 my ( $sth, $record, $kohafieldname, $value, $frameworkcode ) = @_;
1323 $frameworkcode='' unless $frameworkcode;
1327 if ( !defined $sth ) {
1328 my $dbh = C4::Context->dbh;
1329 $sth = $dbh->prepare(
1330 "SELECT tagfield,tagsubfield FROM marc_subfield_structure WHERE frameworkcode=? AND kohafield=?"
1333 $sth->execute( $frameworkcode, $kohafieldname );
1334 if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
1335 my $tag = $record->field($tagfield);
1337 $tag->update( $tagsubfield => $value );
1338 $record->delete_field($tag);
1339 $record->insert_fields_ordered($tag);
1342 $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
1348 =head2 TransformHtmlToXml
1352 $xml = TransformHtmlToXml( $tags, $subfields, $values, $indicator, $ind_tag, $auth_type )
1354 $auth_type contains :
1355 - nothing : rebuild a biblio, un UNIMARC the encoding is in 100$a pos 26/27
1356 - UNIMARCAUTH : rebuild an authority. In UNIMARC, the encoding is in 100$a pos 13/14
1357 - ITEM : rebuild an item : in UNIMARC, 100$a, it's in the biblio ! (otherwise, we would get 2 100 fields !)
1363 sub TransformHtmlToXml {
1364 my ( $tags, $subfields, $values, $indicator, $ind_tag, $auth_type ) = @_;
1365 my $xml = MARC::File::XML::header('UTF-8');
1366 $auth_type = C4::Context->preference('marcflavour') unless $auth_type;
1367 MARC::File::XML->default_record_format($auth_type);
1368 # in UNIMARC, field 100 contains the encoding
1369 # check that there is one, otherwise the
1370 # MARC::Record->new_from_xml will fail (and Koha will die)
1371 my $unimarc_and_100_exist=0;
1372 $unimarc_and_100_exist=1 if $auth_type eq 'ITEM'; # if we rebuild an item, no need of a 100 field
1377 for ( my $i = 0 ; $i <= @$tags ; $i++ ) {
1378 if (C4::Context->preference('marcflavour') eq 'UNIMARC' and @$tags[$i] eq "100" and @$subfields[$i] eq "a") {
1379 # if we have a 100 field and it's values are not correct, skip them.
1380 # if we don't have any valid 100 field, we will create a default one at the end
1381 my $enc = substr( @$values[$i], 26, 2 );
1382 if ($enc eq '01' or $enc eq '50' or $enc eq '03') {
1383 $unimarc_and_100_exist=1;
1388 @$values[$i] =~ s/&/&/g;
1389 @$values[$i] =~ s/</</g;
1390 @$values[$i] =~ s/>/>/g;
1391 @$values[$i] =~ s/"/"/g;
1392 @$values[$i] =~ s/'/'/g;
1393 # if ( !utf8::is_utf8( @$values[$i] ) ) {
1394 # utf8::decode( @$values[$i] );
1396 if ( ( @$tags[$i] ne $prevtag ) ) {
1397 $j++ unless ( @$tags[$i] eq "" );
1399 $xml .= "</datafield>\n";
1400 if ( ( @$tags[$i] && @$tags[$i] > 10 )
1401 && ( @$values[$i] ne "" ) )
1403 my $ind1 = substr( @$indicator[$j], 0, 1 );
1405 if ( @$indicator[$j] ) {
1406 $ind2 = substr( @$indicator[$j], 1, 1 );
1409 warn "Indicator in @$tags[$i] is empty";
1413 "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
1415 "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
1423 if ( @$values[$i] ne "" ) {
1426 if ( @$tags[$i] eq "000" ) {
1427 $xml .= "<leader>@$values[$i]</leader>\n";
1430 # rest of the fixed fields
1432 elsif ( @$tags[$i] < 10 ) {
1434 "<controlfield tag=\"@$tags[$i]\">@$values[$i]</controlfield>\n";
1438 my $ind1 = substr( @$indicator[$j], 0, 1 );
1439 my $ind2 = substr( @$indicator[$j], 1, 1 );
1441 "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
1443 "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
1449 else { # @$tags[$i] eq $prevtag
1450 if ( @$values[$i] eq "" ) {
1454 my $ind1 = substr( @$indicator[$j], 0, 1 );
1455 my $ind2 = substr( @$indicator[$j], 1, 1 );
1457 "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
1461 "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
1464 $prevtag = @$tags[$i];
1466 if (C4::Context->preference('marcflavour') eq 'UNIMARC' and !$unimarc_and_100_exist) {
1467 # warn "SETTING 100 for $auth_type";
1468 use POSIX qw(strftime);
1469 my $string = strftime( "%Y%m%d", localtime(time) );
1470 # set 50 to position 26 is biblios, 13 if authorities
1472 $pos=13 if $auth_type eq 'UNIMARCAUTH';
1473 $string = sprintf( "%-*s", 35, $string );
1474 substr( $string, $pos , 6, "50" );
1475 $xml .= "<datafield tag=\"100\" ind1=\"\" ind2=\"\">\n";
1476 $xml .= "<subfield code=\"a\">$string</subfield>\n";
1477 $xml .= "</datafield>\n";
1479 $xml .= MARC::File::XML::footer();
1483 =head2 TransformHtmlToMarc
1485 L<$record> = TransformHtmlToMarc(L<$params>,L<$cgi>)
1486 L<$params> is a ref to an array as below:
1488 'tag_010_indicator1_531951' ,
1489 'tag_010_indicator2_531951' ,
1490 'tag_010_code_a_531951_145735' ,
1491 'tag_010_subfield_a_531951_145735' ,
1492 'tag_200_indicator1_873510' ,
1493 'tag_200_indicator2_873510' ,
1494 'tag_200_code_a_873510_673465' ,
1495 'tag_200_subfield_a_873510_673465' ,
1496 'tag_200_code_b_873510_704318' ,
1497 'tag_200_subfield_b_873510_704318' ,
1498 'tag_200_code_e_873510_280822' ,
1499 'tag_200_subfield_e_873510_280822' ,
1500 'tag_200_code_f_873510_110730' ,
1501 'tag_200_subfield_f_873510_110730' ,
1503 L<$cgi> is the CGI object which containts the value.
1504 L<$record> is the MARC::Record object.
1508 sub TransformHtmlToMarc {
1512 # explicitly turn on the UTF-8 flag for all
1513 # 'tag_' parameters to avoid incorrect character
1514 # conversion later on
1515 my $cgi_params = $cgi->Vars;
1516 foreach my $param_name (keys %$cgi_params) {
1517 if ($param_name =~ /^tag_/) {
1518 my $param_value = $cgi_params->{$param_name};
1519 if (utf8::decode($param_value)) {
1520 $cgi_params->{$param_name} = $param_value;
1522 # FIXME - need to do something if string is not valid UTF-8
1526 # creating a new record
1527 my $record = MARC::Record->new();
1530 while ($params->[$i]){ # browse all CGI params
1531 my $param = $params->[$i];
1533 # if we are on biblionumber, store it in the MARC::Record (it may not be in the edited fields)
1534 if ($param eq 'biblionumber') {
1535 my ( $biblionumbertagfield, $biblionumbertagsubfield ) =
1536 &GetMarcFromKohaField( "biblio.biblionumber", '' );
1537 if ($biblionumbertagfield < 10) {
1538 $newfield = MARC::Field->new(
1539 $biblionumbertagfield,
1540 $cgi->param($param),
1543 $newfield = MARC::Field->new(
1544 $biblionumbertagfield,
1547 "$biblionumbertagsubfield" => $cgi->param($param),
1550 push @fields,$newfield if($newfield);
1552 elsif ($param =~ /^tag_(\d*)_indicator1_/){ # new field start when having 'input name="..._indicator1_..."
1555 my $ind1 = substr($cgi->param($param),0,1);
1556 my $ind2 = substr($cgi->param($params->[$i+1]),0,1);
1560 if($tag < 10){ # no code for theses fields
1561 # in MARC editor, 000 contains the leader.
1562 if ($tag eq '000' ) {
1563 $record->leader($cgi->param($params->[$j+1])) if length($cgi->param($params->[$j+1]))==24;
1564 # between 001 and 009 (included)
1565 } elsif ($cgi->param($params->[$j+1]) ne '') {
1566 $newfield = MARC::Field->new(
1568 $cgi->param($params->[$j+1]),
1571 # > 009, deal with subfields
1573 while($params->[$j] =~ /_code_/){ # browse all it's subfield
1574 my $inner_param = $params->[$j];
1576 if($cgi->param($params->[$j+1]) ne ''){ # only if there is a value (code => value)
1577 $newfield->add_subfields(
1578 $cgi->param($inner_param) => $cgi->param($params->[$j+1])
1582 if ( $cgi->param($params->[$j+1]) ne '' ) { # creating only if there is a value (code => value)
1583 $newfield = MARC::Field->new(
1587 $cgi->param($inner_param) => $cgi->param($params->[$j+1]),
1594 push @fields,$newfield if($newfield);
1599 $record->append_fields(@fields);
1603 # cache inverted MARC field map
1604 our $inverted_field_map;
1606 =head2 TransformMarcToKoha
1610 $result = TransformMarcToKoha( $dbh, $record, $frameworkcode )
1614 Extract data from a MARC bib record into a hashref representing
1615 Koha biblio, biblioitems, and items fields.
1618 sub TransformMarcToKoha {
1619 my ( $dbh, $record, $frameworkcode, $limit_table ) = @_;
1622 $limit_table=$limit_table||0;
1624 unless (defined $inverted_field_map) {
1625 $inverted_field_map = _get_inverted_marc_field_map();
1629 if ( defined $limit_table && $limit_table eq 'items') {
1630 $tables{'items'} = 1;
1632 $tables{'items'} = 1;
1633 $tables{'biblio'} = 1;
1634 $tables{'biblioitems'} = 1;
1637 # traverse through record
1638 MARCFIELD: foreach my $field ($record->fields()) {
1639 my $tag = $field->tag();
1640 next MARCFIELD unless exists $inverted_field_map->{$frameworkcode}->{$tag};
1641 if ($field->is_control_field()) {
1642 my $kohafields = $inverted_field_map->{$frameworkcode}->{$tag}->{list};
1643 ENTRY: foreach my $entry (@{ $kohafields }) {
1644 my ($subfield, $table, $column) = @{ $entry };
1645 next ENTRY unless exists $tables{$table};
1646 my $key = _disambiguate($table, $column);
1647 if ($result->{$key}) {
1648 unless (($key eq "biblionumber" or $key eq "biblioitemnumber") and ($field->data() eq "")) {
1649 $result->{$key} .= " | " . $field->data();
1652 $result->{$key} = $field->data();
1656 # deal with subfields
1657 MARCSUBFIELD: foreach my $sf ($field->subfields()) {
1658 my $code = $sf->[0];
1659 next MARCSUBFIELD unless exists $inverted_field_map->{$frameworkcode}->{$tag}->{sfs}->{$code};
1660 my $value = $sf->[1];
1661 SFENTRY: foreach my $entry (@{ $inverted_field_map->{$frameworkcode}->{$tag}->{sfs}->{$code} }) {
1662 my ($table, $column) = @{ $entry };
1663 next SFENTRY unless exists $tables{$table};
1664 my $key = _disambiguate($table, $column);
1665 if ($result->{$key}) {
1666 unless (($key eq "biblionumber" or $key eq "biblioitemnumber") and ($value eq "")) {
1667 $result->{$key} .= " | " . $value;
1670 $result->{$key} = $value;
1677 # modify copyrightdate to keep only the 1st year found
1678 if (exists $result->{'copyrightdate'}) {
1679 my $temp = $result->{'copyrightdate'};
1680 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1682 $result->{'copyrightdate'} = $1;
1684 else { # if no cYYYY, get the 1st date.
1685 $temp =~ m/(\d\d\d\d)/;
1686 $result->{'copyrightdate'} = $1;
1690 # modify publicationyear to keep only the 1st year found
1691 if (exists $result->{'publicationyear'}) {
1692 my $temp = $result->{'publicationyear'};
1693 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1695 $result->{'publicationyear'} = $1;
1697 else { # if no cYYYY, get the 1st date.
1698 $temp =~ m/(\d\d\d\d)/;
1699 $result->{'publicationyear'} = $1;
1706 sub _get_inverted_marc_field_map {
1708 my $relations = C4::Context->marcfromkohafield;
1710 foreach my $frameworkcode (keys %{ $relations }) {
1711 foreach my $kohafield (keys %{ $relations->{$frameworkcode} }) {
1712 my $tag = $relations->{$frameworkcode}->{$kohafield}->[0];
1713 my $subfield = $relations->{$frameworkcode}->{$kohafield}->[1];
1714 my ($table, $column) = split /[.]/, $kohafield, 2;
1715 push @{ $field_map->{$frameworkcode}->{$tag}->{list} }, [ $subfield, $table, $column ];
1716 push @{ $field_map->{$frameworkcode}->{$tag}->{sfs}->{$subfield} }, [ $table, $column ];
1722 =head2 _disambiguate
1726 $newkey = _disambiguate($table, $field);
1728 This is a temporary hack to distinguish between the
1729 following sets of columns when using TransformMarcToKoha.
1731 items.cn_source & biblioitems.cn_source
1732 items.cn_sort & biblioitems.cn_sort
1734 Columns that are currently NOT distinguished (FIXME
1735 due to lack of time to fully test) are:
1737 biblio.notes and biblioitems.notes
1742 FIXME - this is necessary because prefixing each column
1743 name with the table name would require changing lots
1744 of code and templates, and exposing more of the DB
1745 structure than is good to the UI templates, particularly
1746 since biblio and bibloitems may well merge in a future
1747 version. In the future, it would also be good to
1748 separate DB access and UI presentation field names
1756 my ($table, $column) = @_;
1757 if ($column eq "cn_sort" or $column eq "cn_source") {
1758 return $table . '.' . $column;
1765 =head2 get_koha_field_from_marc
1769 $result->{_disambiguate($table, $field)} = get_koha_field_from_marc($table,$field,$record,$frameworkcode);
1771 Internal function to map data from the MARC record to a specific non-MARC field.
1772 FIXME: this is meant to replace TransformMarcToKohaOneField after more testing.
1778 sub get_koha_field_from_marc {
1779 my ($koha_table,$koha_column,$record,$frameworkcode) = @_;
1780 my ( $tagfield, $subfield ) = GetMarcFromKohaField( $koha_table.'.'.$koha_column, $frameworkcode );
1782 foreach my $field ( $record->field($tagfield) ) {
1783 if ( $field->tag() < 10 ) {
1785 $kohafield .= " | " . $field->data();
1788 $kohafield = $field->data();
1792 if ( $field->subfields ) {
1793 my @subfields = $field->subfields();
1794 foreach my $subfieldcount ( 0 .. $#subfields ) {
1795 if ( $subfields[$subfieldcount][0] eq $subfield ) {
1798 " | " . $subfields[$subfieldcount][1];
1802 $subfields[$subfieldcount][1];
1813 =head2 TransformMarcToKohaOneField
1817 $result = TransformMarcToKohaOneField( $kohatable, $kohafield, $record, $result, $frameworkcode )
1823 sub TransformMarcToKohaOneField {
1825 # FIXME ? if a field has a repeatable subfield that is used in old-db,
1826 # only the 1st will be retrieved...
1827 my ( $kohatable, $kohafield, $record, $result, $frameworkcode ) = @_;
1829 my ( $tagfield, $subfield ) =
1830 GetMarcFromKohaField( $kohatable . "." . $kohafield,
1832 foreach my $field ( $record->field($tagfield) ) {
1833 if ( $field->tag() < 10 ) {
1834 if ( $result->{$kohafield} ) {
1835 $result->{$kohafield} .= " | " . $field->data();
1838 $result->{$kohafield} = $field->data();
1842 if ( $field->subfields ) {
1843 my @subfields = $field->subfields();
1844 foreach my $subfieldcount ( 0 .. $#subfields ) {
1845 if ( $subfields[$subfieldcount][0] eq $subfield ) {
1846 if ( $result->{$kohafield} ) {
1847 $result->{$kohafield} .=
1848 " | " . $subfields[$subfieldcount][1];
1851 $result->{$kohafield} =
1852 $subfields[$subfieldcount][1];
1862 =head1 OTHER FUNCTIONS
1865 =head2 PrepareItemrecordDisplay
1869 PrepareItemrecordDisplay($itemrecord,$bibnum,$itemumber);
1871 Returns a hash with all the fields for Display a given item data in a template
1877 sub PrepareItemrecordDisplay {
1879 my ( $bibnum, $itemnum, $defaultvalues ) = @_;
1881 my $dbh = C4::Context->dbh;
1882 my $frameworkcode = &GetFrameworkCode( $bibnum );
1883 my ( $itemtagfield, $itemtagsubfield ) =
1884 &GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
1885 my $tagslib = &GetMarcStructure( 1, $frameworkcode );
1886 my $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum) if ($itemnum);
1888 my $authorised_values_sth =
1890 "SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib"
1892 foreach my $tag ( sort keys %{$tagslib} ) {
1893 my $previous_tag = '';
1895 # loop through each subfield
1897 foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
1898 next if ( subfield_is_koha_internal_p($subfield) );
1899 next if ( $tagslib->{$tag}->{$subfield}->{'tab'} ne "10" );
1901 $subfield_data{tag} = $tag;
1902 $subfield_data{subfield} = $subfield;
1903 $subfield_data{countsubfield} = $cntsubf++;
1904 $subfield_data{kohafield} =
1905 $tagslib->{$tag}->{$subfield}->{'kohafield'};
1907 # $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
1908 $subfield_data{marc_lib} = $tagslib->{$tag}->{$subfield}->{lib};
1909 $subfield_data{mandatory} =
1910 $tagslib->{$tag}->{$subfield}->{mandatory};
1911 $subfield_data{repeatable} =
1912 $tagslib->{$tag}->{$subfield}->{repeatable};
1913 $subfield_data{hidden} = "display:none"
1914 if $tagslib->{$tag}->{$subfield}->{hidden};
1916 ( $x, $value ) = _find_value( $tag, $subfield, $itemrecord )
1918 $value =~ s/"/"/g;
1920 # search for itemcallnumber if applicable
1921 if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
1922 'items.itemcallnumber'
1923 && C4::Context->preference('itemcallnumber') )
1926 substr( C4::Context->preference('itemcallnumber'), 0, 3 );
1928 substr( C4::Context->preference('itemcallnumber'), 3, 1 );
1929 my $temp = $itemrecord->field($CNtag) if ($itemrecord);
1931 $value = $temp->subfield($CNsubfield);
1934 if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
1935 'items.itemcallnumber'
1936 && $defaultvalues->{'callnumber'} )
1938 my $temp = $itemrecord->field($subfield) if ($itemrecord);
1940 $value = $defaultvalues->{'callnumber'};
1943 if ( ($tagslib->{$tag}->{$subfield}->{kohafield} eq
1944 'items.holdingbranch' ||
1945 $tagslib->{$tag}->{$subfield}->{kohafield} eq
1947 && $defaultvalues->{'branchcode'} )
1949 my $temp = $itemrecord->field($subfield) if ($itemrecord);
1951 $value = $defaultvalues->{branchcode};
1954 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
1955 my @authorised_values;
1958 # builds list, depending on authorised value...
1960 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq
1963 if ( ( C4::Context->preference("IndependantBranches") )
1964 && ( C4::Context->userenv->{flags} != 1 ) )
1968 "SELECT branchcode,branchname FROM branches WHERE branchcode = ? ORDER BY branchname"
1970 $sth->execute( C4::Context->userenv->{branch} );
1971 push @authorised_values, ""
1973 $tagslib->{$tag}->{$subfield}->{mandatory} );
1974 while ( my ( $branchcode, $branchname ) =
1975 $sth->fetchrow_array )
1977 push @authorised_values, $branchcode;
1978 $authorised_lib{$branchcode} = $branchname;
1984 "SELECT branchcode,branchname FROM branches ORDER BY branchname"
1987 push @authorised_values, ""
1989 $tagslib->{$tag}->{$subfield}->{mandatory} );
1990 while ( my ( $branchcode, $branchname ) =
1991 $sth->fetchrow_array )
1993 push @authorised_values, $branchcode;
1994 $authorised_lib{$branchcode} = $branchname;
2000 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq
2005 "SELECT itemtype,description FROM itemtypes ORDER BY description"
2008 push @authorised_values, ""
2009 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2010 while ( my ( $itemtype, $description ) =
2011 $sth->fetchrow_array )
2013 push @authorised_values, $itemtype;
2014 $authorised_lib{$itemtype} = $description;
2017 #---- "true" authorised value
2020 $authorised_values_sth->execute(
2021 $tagslib->{$tag}->{$subfield}->{authorised_value} );
2022 push @authorised_values, ""
2023 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2024 while ( my ( $value, $lib ) =
2025 $authorised_values_sth->fetchrow_array )
2027 push @authorised_values, $value;
2028 $authorised_lib{$value} = $lib;
2031 $subfield_data{marc_value} = CGI::scrolling_list(
2032 -name => 'field_value',
2033 -values => \@authorised_values,
2034 -default => "$value",
2035 -labels => \%authorised_lib,
2041 elsif ( $tagslib->{$tag}->{$subfield}->{thesaurus_category} ) {
2042 $subfield_data{marc_value} =
2043 "<input type=\"text\" name=\"field_value\" size=\"47\" maxlength=\"255\" /> <a href=\"javascript:Dopop('cataloguing/thesaurus_popup.pl?category=$tagslib->{$tag}->{$subfield}->{thesaurus_category}&index=',)\">...</a>";
2046 # COMMENTED OUT because No $i is provided with this API.
2047 # And thus, no value_builder can be activated.
2048 # BUT could be thought over.
2049 # } elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
2050 # my $plugin="value_builder/".$tagslib->{$tag}->{$subfield}->{'value_builder'};
2052 # my $extended_param = plugin_parameters($dbh,$itemrecord,$tagslib,$i,0);
2053 # my ($function_name,$javascript) = plugin_javascript($dbh,$record,$tagslib,$i,0);
2054 # $subfield_data{marc_value}="<input type=\"text\" value=\"$value\" name=\"field_value\" size=47 maxlength=255 DISABLE READONLY OnFocus=\"javascript:Focus$function_name()\" OnBlur=\"javascript:Blur$function_name()\"> <a href=\"javascript:Clic$function_name()\">...</a> $javascript";
2057 $subfield_data{marc_value} =
2058 "<input type=\"text\" name=\"field_value\" value=\"$value\" size=\"50\" maxlength=\"255\" />";
2060 push( @loop_data, \%subfield_data );
2064 my $itemnumber = $itemrecord->subfield( $itemtagfield, $itemtagsubfield )
2065 if ( $itemrecord && $itemrecord->field($itemtagfield) );
2067 'itemtagfield' => $itemtagfield,
2068 'itemtagsubfield' => $itemtagsubfield,
2069 'itemnumber' => $itemnumber,
2070 'iteminformation' => \@loop_data
2076 # true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates
2078 # replaced by a zebraqueue table, that is filled with ModZebra to run.
2079 # the table is emptied by misc/cronjobs/zebraqueue_start.pl script
2080 # =head2 ModZebrafiles
2082 # &ModZebrafiles( $dbh, $biblionumber, $record, $folder, $server );
2086 # sub ModZebrafiles {
2088 # my ( $dbh, $biblionumber, $record, $folder, $server ) = @_;
2092 # C4::Context->zebraconfig($server)->{directory} . "/" . $folder . "/";
2093 # unless ( opendir( DIR, "$zebradir" ) ) {
2094 # warn "$zebradir not found";
2098 # my $filename = $zebradir . $biblionumber;
2101 # open( OUTPUT, ">", $filename . ".xml" );
2102 # print OUTPUT $record;
2111 ModZebra( $biblionumber, $op, $server, $oldRecord, $newRecord );
2113 $biblionumber is the biblionumber we want to index
2114 $op is specialUpdate or delete, and is used to know what we want to do
2115 $server is the server that we want to update
2116 $oldRecord is the MARC::Record containing the previous version of the record. This is used only when
2117 NoZebra=1, as NoZebra indexing needs to know the previous version of a record in order to
2119 $newRecord is the MARC::Record containing the new record. It is usefull only when NoZebra=1, and is used to know what to add to the nozebra database. (the record in mySQL being, if it exist, the previous record, the one just before the modif. We need both : the previous and the new one.
2126 ###Accepts a $server variable thus we can use it for biblios authorities or other zebra dbs
2127 my ( $biblionumber, $op, $server, $oldRecord, $newRecord ) = @_;
2128 my $dbh=C4::Context->dbh;
2130 # true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates
2132 # replaced by a zebraqueue table, that is filled with ModZebra to run.
2133 # the table is emptied by misc/cronjobs/zebraqueue_start.pl script
2135 if (C4::Context->preference("NoZebra")) {
2136 # lock the nozebra table : we will read index lines, update them in Perl process
2137 # and write everything in 1 transaction.
2138 # lock the table to avoid someone else overwriting what we are doing
2139 $dbh->do('LOCK TABLES nozebra WRITE,biblio WRITE,biblioitems WRITE, systempreferences WRITE, auth_types WRITE, auth_header WRITE, auth_subfield_structure READ');
2140 my %result; # the result hash that will be built by deletion / add, and written on mySQL at the end, to improve speed
2141 if ($op eq 'specialUpdate') {
2142 # OK, we have to add or update the record
2143 # 1st delete (virtually, in indexes), if record actually exists
2145 %result = _DelBiblioNoZebra($biblionumber,$oldRecord,$server);
2147 # ... add the record
2148 %result=_AddBiblioNoZebra($biblionumber,$newRecord, $server, %result);
2150 # it's a deletion, delete the record...
2151 # warn "DELETE the record $biblionumber on $server".$record->as_formatted;
2152 %result=_DelBiblioNoZebra($biblionumber,$oldRecord,$server);
2154 # ok, now update the database...
2155 my $sth = $dbh->prepare("UPDATE nozebra SET biblionumbers=? WHERE server=? AND indexname=? AND value=?");
2156 foreach my $key (keys %result) {
2157 foreach my $index (keys %{$result{$key}}) {
2158 $sth->execute($result{$key}->{$index}, $server, $key, $index);
2161 $dbh->do('UNLOCK TABLES');
2164 # we use zebra, just fill zebraqueue table
2166 my $check_sql = "SELECT COUNT(*) FROM zebraqueue
2168 AND biblio_auth_number = ?
2171 my $check_sth = $dbh->prepare_cached($check_sql);
2172 $check_sth->execute($server, $biblionumber, $op);
2173 my ($count) = $check_sth->fetchrow_array;
2174 $check_sth->finish();
2176 my $sth=$dbh->prepare("INSERT INTO zebraqueue (biblio_auth_number,server,operation) VALUES(?,?,?)");
2177 $sth->execute($biblionumber,$server,$op);
2183 =head2 GetNoZebraIndexes
2185 %indexes = GetNoZebraIndexes;
2187 return the data from NoZebraIndexes syspref.
2191 sub GetNoZebraIndexes {
2192 my $no_zebra_indexes = C4::Context->preference('NoZebraIndexes');
2194 INDEX: foreach my $line (split /['"],[\n\r]*/,$no_zebra_indexes) {
2195 $line =~ /(.*)=>(.*)/;
2196 my $index = $1; # initial ' or " is removed afterwards
2198 $index =~ s/'|"|\s//g;
2199 $fields =~ s/'|"|\s//g;
2200 $indexes{$index}=$fields;
2205 =head1 INTERNAL FUNCTIONS
2207 =head2 _DelBiblioNoZebra($biblionumber,$record,$server);
2209 function to delete a biblio in NoZebra indexes
2210 This function does NOT delete anything in database : it reads all the indexes entries
2211 that have to be deleted & delete them in the hash
2212 The SQL part is done either :
2213 - after the Add if we are modifying a biblio (delete + add again)
2214 - immediatly after this sub if we are doing a true deletion.
2215 $server can be 'biblioserver' or 'authorityserver' : it indexes biblios or authorities (in the same table, $server being part of the table itself
2220 sub _DelBiblioNoZebra {
2221 my ($biblionumber, $record, $server)=@_;
2224 my $dbh = C4::Context->dbh;
2228 if ($server eq 'biblioserver') {
2229 %index=GetNoZebraIndexes;
2230 # get title of the record (to store the 10 first letters with the index)
2231 my ($titletag,$titlesubfield) = GetMarcFromKohaField('biblio.title');
2232 $title = lc($record->subfield($titletag,$titlesubfield));
2234 # for authorities, the "title" is the $a mainentry
2235 my ($auth_type_tag, $auth_type_sf) = C4::AuthoritiesMarc::get_auth_type_location();
2236 my $authref = C4::AuthoritiesMarc::GetAuthType($record->subfield($auth_type_tag, $auth_type_sf));
2237 warn "ERROR : authtype undefined for ".$record->as_formatted unless $authref;
2238 $title = $record->subfield($authref->{auth_tag_to_report},'a');
2239 $index{'mainmainentry'}= $authref->{'auth_tag_to_report'}.'a';
2240 $index{'mainentry'} = $authref->{'auth_tag_to_report'}.'*';
2241 $index{'auth_type'} = "${auth_type_tag}${auth_type_sf}";
2245 # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
2246 $title =~ s/ |,|;|\[|\]|\(|\)|\*|-|'|=//g;
2247 # limit to 10 char, should be enough, and limit the DB size
2248 $title = substr($title,0,10);
2250 my $sth2=$dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
2251 foreach my $field ($record->fields()) {
2252 #parse each subfield
2253 next if $field->tag <10;
2254 foreach my $subfield ($field->subfields()) {
2255 my $tag = $field->tag();
2256 my $subfieldcode = $subfield->[0];
2258 # check each index to see if the subfield is stored somewhere
2259 # otherwise, store it in __RAW__ index
2260 foreach my $key (keys %index) {
2261 # warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
2262 if ($index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/) {
2264 my $line= lc $subfield->[1];
2265 # remove meaningless value in the field...
2266 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
2267 # ... and split in words
2268 foreach (split / /,$line) {
2269 next unless $_; # skip empty values (multiple spaces)
2270 # if the entry is already here, do nothing, the biblionumber has already be removed
2271 unless ( defined( $result{$key}->{$_} ) && ( $result{$key}->{$_} =~ /$biblionumber,$title\-(\d);/) ) {
2272 # get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
2273 $sth2->execute($server,$key,$_);
2274 my $existing_biblionumbers = $sth2->fetchrow;
2276 if ($existing_biblionumbers) {
2277 # warn " existing for $key $_: $existing_biblionumbers";
2278 $result{$key}->{$_} =$existing_biblionumbers;
2279 $result{$key}->{$_} =~ s/$biblionumber,$title\-(\d);//;
2285 # the subfield is not indexed, store it in __RAW__ index anyway
2287 my $line= lc $subfield->[1];
2288 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
2289 # ... and split in words
2290 foreach (split / /,$line) {
2291 next unless $_; # skip empty values (multiple spaces)
2292 # if the entry is already here, do nothing, the biblionumber has already be removed
2293 unless ($result{'__RAW__'}->{$_} =~ /$biblionumber,$title\-(\d);/) {
2294 # get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
2295 $sth2->execute($server,'__RAW__',$_);
2296 my $existing_biblionumbers = $sth2->fetchrow;
2298 if ($existing_biblionumbers) {
2299 $result{'__RAW__'}->{$_} =$existing_biblionumbers;
2300 $result{'__RAW__'}->{$_} =~ s/$biblionumber,$title\-(\d);//;
2310 =head2 _AddBiblioNoZebra($biblionumber, $record, $server, %result);
2312 function to add a biblio in NoZebra indexes
2316 sub _AddBiblioNoZebra {
2317 my ($biblionumber, $record, $server, %result)=@_;
2318 my $dbh = C4::Context->dbh;
2322 if ($server eq 'biblioserver') {
2323 %index=GetNoZebraIndexes;
2324 # get title of the record (to store the 10 first letters with the index)
2325 my ($titletag,$titlesubfield) = GetMarcFromKohaField('biblio.title');
2326 $title = lc($record->subfield($titletag,$titlesubfield));
2328 # warn "server : $server";
2329 # for authorities, the "title" is the $a mainentry
2330 my ($auth_type_tag, $auth_type_sf) = C4::AuthoritiesMarc::get_auth_type_location();
2331 my $authref = C4::AuthoritiesMarc::GetAuthType($record->subfield($auth_type_tag, $auth_type_sf));
2332 warn "ERROR : authtype undefined for ".$record->as_formatted unless $authref;
2333 $title = $record->subfield($authref->{auth_tag_to_report},'a');
2334 $index{'mainmainentry'} = $authref->{auth_tag_to_report}.'a';
2335 $index{'mainentry'} = $authref->{auth_tag_to_report}.'*';
2336 $index{'auth_type'} = "${auth_type_tag}${auth_type_sf}";
2339 # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
2340 $title =~ s/ |\.|,|;|\[|\]|\(|\)|\*|-|'|:|=|\r|\n//g;
2341 # limit to 10 char, should be enough, and limit the DB size
2342 $title = substr($title,0,10);
2344 my $sth2=$dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
2345 foreach my $field ($record->fields()) {
2346 #parse each subfield
2347 ###FIXME: impossible to index a 001-009 value with NoZebra
2348 next if $field->tag <10;
2349 foreach my $subfield ($field->subfields()) {
2350 my $tag = $field->tag();
2351 my $subfieldcode = $subfield->[0];
2353 # warn "INDEXING :".$subfield->[1];
2354 # check each index to see if the subfield is stored somewhere
2355 # otherwise, store it in __RAW__ index
2356 foreach my $key (keys %index) {
2357 # warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
2358 if ($index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/) {
2360 my $line= lc $subfield->[1];
2361 # remove meaningless value in the field...
2362 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:|\r|\n/ /g;
2363 # ... and split in words
2364 foreach (split / /,$line) {
2365 next unless $_; # skip empty values (multiple spaces)
2366 # if the entry is already here, improve weight
2367 # warn "managing $_";
2368 if ( exists $result{$key}->{$_} && $result{$key}->{"$_"} =~ /$biblionumber,\Q$title\E\-(\d+);/) {
2369 my $weight = $1 + 1;
2370 $result{$key}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//g;
2371 $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
2373 # get the value if it exist in the nozebra table, otherwise, create it
2374 $sth2->execute($server,$key,$_);
2375 my $existing_biblionumbers = $sth2->fetchrow;
2377 if ($existing_biblionumbers) {
2378 $result{$key}->{"$_"} =$existing_biblionumbers;
2379 my $weight = defined $1 ? $1 + 1 : 1;
2380 $result{$key}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//g;
2381 $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
2382 # create a new ligne for this entry
2384 # warn "INSERT : $server / $key / $_";
2385 $dbh->do('INSERT INTO nozebra SET server='.$dbh->quote($server).', indexname='.$dbh->quote($key).',value='.$dbh->quote($_));
2386 $result{$key}->{"$_"}.="$biblionumber,$title-1;";
2392 # the subfield is not indexed, store it in __RAW__ index anyway
2394 my $line= lc $subfield->[1];
2395 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:|\r|\n/ /g;
2396 # ... and split in words
2397 foreach (split / /,$line) {
2398 next unless $_; # skip empty values (multiple spaces)
2399 # if the entry is already here, improve weight
2400 if ($result{'__RAW__'}->{"$_"} =~ /$biblionumber,\Q$title\E\-(\d+);/) {
2402 $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//;
2403 $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
2405 # get the value if it exist in the nozebra table, otherwise, create it
2406 $sth2->execute($server,'__RAW__',$_);
2407 my $existing_biblionumbers = $sth2->fetchrow;
2409 if ($existing_biblionumbers) {
2410 $result{'__RAW__'}->{"$_"} =$existing_biblionumbers;
2412 $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//;
2413 $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
2414 # create a new ligne for this entry
2416 $dbh->do('INSERT INTO nozebra SET server='.$dbh->quote($server).', indexname="__RAW__",value='.$dbh->quote($_));
2417 $result{'__RAW__'}->{"$_"}.="$biblionumber,$title-1;";
2432 ($indicators, $value) = _find_value($tag, $subfield, $record,$encoding);
2434 Find the given $subfield in the given $tag in the given
2435 MARC::Record $record. If the subfield is found, returns
2436 the (indicators, value) pair; otherwise, (undef, undef) is
2440 Such a function is used in addbiblio AND additem and serial-edit and maybe could be used in Authorities.
2441 I suggest we export it from this module.
2448 my ( $tagfield, $insubfield, $record, $encoding ) = @_;
2451 if ( $tagfield < 10 ) {
2452 if ( $record->field($tagfield) ) {
2453 push @result, $record->field($tagfield)->data();
2460 foreach my $field ( $record->field($tagfield) ) {
2461 my @subfields = $field->subfields();
2462 foreach my $subfield (@subfields) {
2463 if ( @$subfield[0] eq $insubfield ) {
2464 push @result, @$subfield[1];
2465 $indicator = $field->indicator(1) . $field->indicator(2);
2470 return ( $indicator, @result );
2473 =head2 _koha_marc_update_bib_ids
2477 _koha_marc_update_bib_ids($record, $frameworkcode, $biblionumber, $biblioitemnumber);
2479 Internal function to add or update biblionumber and biblioitemnumber to
2486 sub _koha_marc_update_bib_ids {
2487 my ($record, $frameworkcode, $biblionumber, $biblioitemnumber) = @_;
2489 # we must add bibnum and bibitemnum in MARC::Record...
2490 # we build the new field with biblionumber and biblioitemnumber
2491 # we drop the original field
2492 # we add the new builded field.
2493 my ($biblio_tag, $biblio_subfield ) = GetMarcFromKohaField("biblio.biblionumber",$frameworkcode);
2494 my ($biblioitem_tag, $biblioitem_subfield ) = GetMarcFromKohaField("biblioitems.biblioitemnumber",$frameworkcode);
2496 if ($biblio_tag != $biblioitem_tag) {
2497 # biblionumber & biblioitemnumber are in different fields
2499 # deal with biblionumber
2500 my ($new_field, $old_field);
2501 if ($biblio_tag < 10) {
2502 $new_field = MARC::Field->new( $biblio_tag, $biblionumber );
2505 MARC::Field->new( $biblio_tag, '', '',
2506 "$biblio_subfield" => $biblionumber );
2509 # drop old field and create new one...
2510 $old_field = $record->field($biblio_tag);
2511 $record->delete_field($old_field) if $old_field;
2512 $record->append_fields($new_field);
2514 # deal with biblioitemnumber
2515 if ($biblioitem_tag < 10) {
2516 $new_field = MARC::Field->new( $biblioitem_tag, $biblioitemnumber, );
2519 MARC::Field->new( $biblioitem_tag, '', '',
2520 "$biblioitem_subfield" => $biblioitemnumber, );
2522 # drop old field and create new one...
2523 $old_field = $record->field($biblioitem_tag);
2524 $record->delete_field($old_field) if $old_field;
2525 $record->insert_fields_ordered($new_field);
2528 # biblionumber & biblioitemnumber are in the same field (can't be <10 as fields <10 have only 1 value)
2529 my $new_field = MARC::Field->new(
2530 $biblio_tag, '', '',
2531 "$biblio_subfield" => $biblionumber,
2532 "$biblioitem_subfield" => $biblioitemnumber
2535 # drop old field and create new one...
2536 my $old_field = $record->field($biblio_tag);
2537 $record->delete_field($old_field) if $old_field;
2538 $record->insert_fields_ordered($new_field);
2542 =head2 _koha_marc_update_biblioitem_cn_sort
2546 _koha_marc_update_biblioitem_cn_sort($marc, $biblioitem, $frameworkcode);
2550 Given a MARC bib record and the biblioitem hash, update the
2551 subfield that contains a copy of the value of biblioitems.cn_sort.
2555 sub _koha_marc_update_biblioitem_cn_sort {
2557 my $biblioitem = shift;
2558 my $frameworkcode= shift;
2560 my ($biblioitem_tag, $biblioitem_subfield ) = GetMarcFromKohaField("biblioitems.cn_sort",$frameworkcode);
2561 return unless $biblioitem_tag;
2563 my ($cn_sort) = GetClassSort($biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'}, $biblioitem->{'cn_item'} );
2565 if (my $field = $marc->field($biblioitem_tag)) {
2566 $field->delete_subfield(code => $biblioitem_subfield);
2567 if ($cn_sort ne '') {
2568 $field->add_subfields($biblioitem_subfield => $cn_sort);
2571 # if we get here, no biblioitem tag is present in the MARC record, so
2572 # we'll create it if $cn_sort is not empty -- this would be
2573 # an odd combination of events, however
2575 $marc->insert_grouped_field(MARC::Field->new($biblioitem_tag, ' ', ' ', $biblioitem_subfield => $cn_sort));
2580 =head2 _koha_add_biblio
2584 my ($biblionumber,$error) = _koha_add_biblio($dbh,$biblioitem);
2586 Internal function to add a biblio ($biblio is a hash with the values)
2592 sub _koha_add_biblio {
2593 my ( $dbh, $biblio, $frameworkcode ) = @_;
2597 # set the series flag
2599 if ( $biblio->{'seriestitle'} ) { $serial = 1 };
2603 SET frameworkcode = ?,
2614 my $sth = $dbh->prepare($query);
2617 $biblio->{'author'},
2619 $biblio->{'unititle'},
2622 $biblio->{'seriestitle'},
2623 $biblio->{'copyrightdate'},
2624 $biblio->{'abstract'}
2627 my $biblionumber = $dbh->{'mysql_insertid'};
2628 if ( $dbh->errstr ) {
2629 $error.="ERROR in _koha_add_biblio $query".$dbh->errstr;
2634 #warn "LEAVING _koha_add_biblio: ".$biblionumber."\n";
2635 return ($biblionumber,$error);
2638 =head2 _koha_modify_biblio
2642 my ($biblionumber,$error) == _koha_modify_biblio($dbh,$biblio,$frameworkcode);
2644 Internal function for updating the biblio table
2650 sub _koha_modify_biblio {
2651 my ( $dbh, $biblio, $frameworkcode ) = @_;
2656 SET frameworkcode = ?,
2665 WHERE biblionumber = ?
2668 my $sth = $dbh->prepare($query);
2672 $biblio->{'author'},
2674 $biblio->{'unititle'},
2676 $biblio->{'serial'},
2677 $biblio->{'seriestitle'},
2678 $biblio->{'copyrightdate'},
2679 $biblio->{'abstract'},
2680 $biblio->{'biblionumber'}
2681 ) if $biblio->{'biblionumber'};
2683 if ( $dbh->errstr || !$biblio->{'biblionumber'} ) {
2684 $error.="ERROR in _koha_modify_biblio $query".$dbh->errstr;
2687 return ( $biblio->{'biblionumber'},$error );
2690 =head2 _koha_modify_biblioitem_nonmarc
2694 my ($biblioitemnumber,$error) = _koha_modify_biblioitem_nonmarc( $dbh, $biblioitem );
2696 Updates biblioitems row except for marc and marcxml, which should be changed
2703 sub _koha_modify_biblioitem_nonmarc {
2704 my ( $dbh, $biblioitem ) = @_;
2707 # re-calculate the cn_sort, it may have changed
2708 my ($cn_sort) = GetClassSort($biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'}, $biblioitem->{'cn_item'} );
2712 SET biblionumber = ?,
2718 publicationyear = ?,
2722 collectiontitle = ?,
2724 collectionvolume= ?,
2725 editionstatement= ?,
2726 editionresponsibility = ?,
2740 where biblioitemnumber = ?
2742 my $sth = $dbh->prepare($query);
2744 $biblioitem->{'biblionumber'},
2745 $biblioitem->{'volume'},
2746 $biblioitem->{'number'},
2747 $biblioitem->{'itemtype'},
2748 $biblioitem->{'isbn'},
2749 $biblioitem->{'issn'},
2750 $biblioitem->{'publicationyear'},
2751 $biblioitem->{'publishercode'},
2752 $biblioitem->{'volumedate'},
2753 $biblioitem->{'volumedesc'},
2754 $biblioitem->{'collectiontitle'},
2755 $biblioitem->{'collectionissn'},
2756 $biblioitem->{'collectionvolume'},
2757 $biblioitem->{'editionstatement'},
2758 $biblioitem->{'editionresponsibility'},
2759 $biblioitem->{'illus'},
2760 $biblioitem->{'pages'},
2761 $biblioitem->{'bnotes'},
2762 $biblioitem->{'size'},
2763 $biblioitem->{'place'},
2764 $biblioitem->{'lccn'},
2765 $biblioitem->{'url'},
2766 $biblioitem->{'biblioitems.cn_source'},
2767 $biblioitem->{'cn_class'},
2768 $biblioitem->{'cn_item'},
2769 $biblioitem->{'cn_suffix'},
2771 $biblioitem->{'totalissues'},
2772 $biblioitem->{'biblioitemnumber'}
2774 if ( $dbh->errstr ) {
2775 $error.="ERROR in _koha_modify_biblioitem_nonmarc $query".$dbh->errstr;
2778 return ($biblioitem->{'biblioitemnumber'},$error);
2781 =head2 _koha_add_biblioitem
2785 my ($biblioitemnumber,$error) = _koha_add_biblioitem( $dbh, $biblioitem );
2787 Internal function to add a biblioitem
2793 sub _koha_add_biblioitem {
2794 my ( $dbh, $biblioitem ) = @_;
2797 my ($cn_sort) = GetClassSort($biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'}, $biblioitem->{'cn_item'} );
2799 "INSERT INTO biblioitems SET
2806 publicationyear = ?,
2810 collectiontitle = ?,
2812 collectionvolume= ?,
2813 editionstatement= ?,
2814 editionresponsibility = ?,
2830 my $sth = $dbh->prepare($query);
2832 $biblioitem->{'biblionumber'},
2833 $biblioitem->{'volume'},
2834 $biblioitem->{'number'},
2835 $biblioitem->{'itemtype'},
2836 $biblioitem->{'isbn'},
2837 $biblioitem->{'issn'},
2838 $biblioitem->{'publicationyear'},
2839 $biblioitem->{'publishercode'},
2840 $biblioitem->{'volumedate'},
2841 $biblioitem->{'volumedesc'},
2842 $biblioitem->{'collectiontitle'},
2843 $biblioitem->{'collectionissn'},
2844 $biblioitem->{'collectionvolume'},
2845 $biblioitem->{'editionstatement'},
2846 $biblioitem->{'editionresponsibility'},
2847 $biblioitem->{'illus'},
2848 $biblioitem->{'pages'},
2849 $biblioitem->{'bnotes'},
2850 $biblioitem->{'size'},
2851 $biblioitem->{'place'},
2852 $biblioitem->{'lccn'},
2853 $biblioitem->{'marc'},
2854 $biblioitem->{'url'},
2855 $biblioitem->{'biblioitems.cn_source'},
2856 $biblioitem->{'cn_class'},
2857 $biblioitem->{'cn_item'},
2858 $biblioitem->{'cn_suffix'},
2860 $biblioitem->{'totalissues'}
2862 my $bibitemnum = $dbh->{'mysql_insertid'};
2863 if ( $dbh->errstr ) {
2864 $error.="ERROR in _koha_add_biblioitem $query".$dbh->errstr;
2868 return ($bibitemnum,$error);
2871 =head2 _koha_delete_biblio
2875 $error = _koha_delete_biblio($dbh,$biblionumber);
2877 Internal sub for deleting from biblio table -- also saves to deletedbiblio
2879 C<$dbh> - the database handle
2880 C<$biblionumber> - the biblionumber of the biblio to be deleted
2886 # FIXME: add error handling
2888 sub _koha_delete_biblio {
2889 my ( $dbh, $biblionumber ) = @_;
2891 # get all the data for this biblio
2892 my $sth = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber=?");
2893 $sth->execute($biblionumber);
2895 if ( my $data = $sth->fetchrow_hashref ) {
2897 # save the record in deletedbiblio
2898 # find the fields to save
2899 my $query = "INSERT INTO deletedbiblio SET ";
2901 foreach my $temp ( keys %$data ) {
2902 $query .= "$temp = ?,";
2903 push( @bind, $data->{$temp} );
2906 # replace the last , by ",?)"
2908 my $bkup_sth = $dbh->prepare($query);
2909 $bkup_sth->execute(@bind);
2913 my $del_sth = $dbh->prepare("DELETE FROM biblio WHERE biblionumber=?");
2914 $del_sth->execute($biblionumber);
2921 =head2 _koha_delete_biblioitems
2925 $error = _koha_delete_biblioitems($dbh,$biblioitemnumber);
2927 Internal sub for deleting from biblioitems table -- also saves to deletedbiblioitems
2929 C<$dbh> - the database handle
2930 C<$biblionumber> - the biblioitemnumber of the biblioitem to be deleted
2936 # FIXME: add error handling
2938 sub _koha_delete_biblioitems {
2939 my ( $dbh, $biblioitemnumber ) = @_;
2941 # get all the data for this biblioitem
2943 $dbh->prepare("SELECT * FROM biblioitems WHERE biblioitemnumber=?");
2944 $sth->execute($biblioitemnumber);
2946 if ( my $data = $sth->fetchrow_hashref ) {
2948 # save the record in deletedbiblioitems
2949 # find the fields to save
2950 my $query = "INSERT INTO deletedbiblioitems SET ";
2952 foreach my $temp ( keys %$data ) {
2953 $query .= "$temp = ?,";
2954 push( @bind, $data->{$temp} );
2957 # replace the last , by ",?)"
2959 my $bkup_sth = $dbh->prepare($query);
2960 $bkup_sth->execute(@bind);
2963 # delete the biblioitem
2965 $dbh->prepare("DELETE FROM biblioitems WHERE biblioitemnumber=?");
2966 $del_sth->execute($biblioitemnumber);
2973 =head1 UNEXPORTED FUNCTIONS
2975 =head2 ModBiblioMarc
2977 &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
2979 Add MARC data for a biblio to koha
2981 Function exported, but should NOT be used, unless you really know what you're doing
2987 # pass the MARC::Record to this function, and it will create the records in the marc field
2988 my ( $record, $biblionumber, $frameworkcode ) = @_;
2989 my $dbh = C4::Context->dbh;
2990 my @fields = $record->fields();
2991 if ( !$frameworkcode ) {
2992 $frameworkcode = "";
2995 $dbh->prepare("UPDATE biblio SET frameworkcode=? WHERE biblionumber=?");
2996 $sth->execute( $frameworkcode, $biblionumber );
2998 my $encoding = C4::Context->preference("marcflavour");
3000 # deal with UNIMARC field 100 (encoding) : create it if needed & set encoding to unicode
3001 if ( $encoding eq "UNIMARC" ) {
3003 if ( length($record->subfield( 100, "a" )) == 35 ) {
3004 $string = $record->subfield( 100, "a" );
3005 my $f100 = $record->field(100);
3006 $record->delete_field($f100);
3009 $string = POSIX::strftime( "%Y%m%d", localtime );
3011 $string = sprintf( "%-*s", 35, $string );
3013 substr( $string, 22, 6, "frey50" );
3014 unless ( $record->subfield( 100, "a" ) ) {
3015 $record->insert_grouped_field(
3016 MARC::Field->new( 100, "", "", "a" => $string ) );
3020 if (C4::Context->preference("NoZebra")) {
3021 # only NoZebra indexing needs to have
3022 # the previous version of the record
3023 $oldRecord = GetMarcBiblio($biblionumber);
3027 "UPDATE biblioitems SET marc=?,marcxml=? WHERE biblionumber=?");
3028 $sth->execute( $record->as_usmarc(), $record->as_xml_record($encoding),
3031 ModZebra($biblionumber,"specialUpdate","biblioserver",$oldRecord,$record);
3032 return $biblionumber;
3035 =head2 z3950_extended_services
3037 z3950_extended_services($serviceType,$serviceOptions,$record);
3039 z3950_extended_services is used to handle all interactions with Zebra's extended serices package, which is employed to perform all management of the MARC data stored in Zebra.
3041 C<$serviceType> one of: itemorder,create,drop,commit,update,xmlupdate
3043 C<$serviceOptions> a has of key/value pairs. For instance, if service_type is 'update', $service_options should contain:
3045 action => update action, one of specialUpdate, recordInsert, recordReplace, recordDelete, elementUpdate.
3049 recordidOpaque => Opaque Record ID (user supplied) or recordidNumber => Record ID number (system number).
3050 syntax => the record syntax (transfer syntax)
3051 databaseName = Database from connection object
3053 To set serviceOptions, call set_service_options($serviceType)
3055 C<$record> the record, if one is needed for the service type
3057 A record should be in XML. You can convert it to XML from MARC by running it through marc2xml().
3061 sub z3950_extended_services {
3062 my ( $server, $serviceType, $action, $serviceOptions ) = @_;
3064 # get our connection object
3065 my $Zconn = C4::Context->Zconn( $server, 0, 1 );
3067 # create a new package object
3068 my $Zpackage = $Zconn->package();
3071 $Zpackage->option( action => $action );
3073 if ( $serviceOptions->{'databaseName'} ) {
3074 $Zpackage->option( databaseName => $serviceOptions->{'databaseName'} );
3076 if ( $serviceOptions->{'recordIdNumber'} ) {
3078 recordIdNumber => $serviceOptions->{'recordIdNumber'} );
3080 if ( $serviceOptions->{'recordIdOpaque'} ) {
3082 recordIdOpaque => $serviceOptions->{'recordIdOpaque'} );
3085 # this is an ILL request (Zebra doesn't support it, but Koha could eventually)
3086 #if ($serviceType eq 'itemorder') {
3087 # $Zpackage->option('contact-name' => $serviceOptions->{'contact-name'});
3088 # $Zpackage->option('contact-phone' => $serviceOptions->{'contact-phone'});
3089 # $Zpackage->option('contact-email' => $serviceOptions->{'contact-email'});
3090 # $Zpackage->option('itemorder-item' => $serviceOptions->{'itemorder-item'});
3093 if ( $serviceOptions->{record} ) {
3094 $Zpackage->option( record => $serviceOptions->{record} );
3096 # can be xml or marc
3097 if ( $serviceOptions->{'syntax'} ) {
3098 $Zpackage->option( syntax => $serviceOptions->{'syntax'} );
3102 # send the request, handle any exception encountered
3103 eval { $Zpackage->send($serviceType) };
3104 if ( $@ && $@->isa("ZOOM::Exception") ) {
3105 return "error: " . $@->code() . " " . $@->message() . "\n";
3108 # free up package resources
3109 $Zpackage->destroy();
3112 =head2 set_service_options
3114 my $serviceOptions = set_service_options($serviceType);
3116 C<$serviceType> itemorder,create,drop,commit,update,xmlupdate
3118 Currently, we only support 'create', 'commit', and 'update'. 'drop' support will be added as soon as Zebra supports it.
3122 sub set_service_options {
3123 my ($serviceType) = @_;
3126 # FIXME: This needs to be an OID ... if we ever need 'syntax' this sub will need to change
3127 # $serviceOptions->{ 'syntax' } = ''; #zebra doesn't support syntaxes other than xml
3129 if ( $serviceType eq 'commit' ) {
3133 if ( $serviceType eq 'create' ) {
3137 if ( $serviceType eq 'drop' ) {
3138 die "ERROR: 'drop' not currently supported (by Zebra)";
3140 return $serviceOptions;
3143 =head3 get_biblio_authorised_values
3145 find the types and values for all authorised values assigned to this biblio.
3150 returns: a hashref malling the authorised value to the value set for this biblionumber
3152 $authorised_values = {
3153 'Scent' => 'flowery',
3154 'Audience' => 'Young Adult',
3155 'itemtypes' => 'SER',
3158 Notes: forlibrarian should probably be passed in, and called something different.
3163 sub get_biblio_authorised_values {
3164 my $biblionumber = shift;
3166 my $forlibrarian = 1; # are we in staff or opac?
3167 my $frameworkcode = GetFrameworkCode( $biblionumber );
3169 my $authorised_values;
3171 my $record = GetMarcBiblio( $biblionumber )
3172 or return $authorised_values;
3173 my $tagslib = GetMarcStructure( $forlibrarian, $frameworkcode )
3174 or return $authorised_values;
3176 # assume that these entries in the authorised_value table are bibliolevel.
3177 # ones that start with 'item%' are item level.
3178 my $query = q(SELECT distinct authorised_value, kohafield
3179 FROM marc_subfield_structure
3180 WHERE authorised_value !=''
3181 AND (kohafield like 'biblio%'
3182 OR kohafield like '') );
3183 my $bibliolevel_authorised_values = C4::Context->dbh->selectall_hashref( $query, 'authorised_value' );
3185 foreach my $tag ( keys( %$tagslib ) ) {
3186 foreach my $subfield ( keys( %{$tagslib->{ $tag }} ) ) {
3187 # warn "checking $subfield. type is: " . ref $tagslib->{ $tag }{ $subfield };
3188 if ( 'HASH' eq ref $tagslib->{ $tag }{ $subfield } ) {
3189 if ( defined $tagslib->{ $tag }{ $subfield }{'authorised_value'} && exists $bibliolevel_authorised_values->{ $tagslib->{ $tag }{ $subfield }{'authorised_value'} } ) {
3190 if ( defined $record->field( $tag ) ) {
3191 my $this_subfield_value = $record->field( $tag )->subfield( $subfield );
3192 if ( defined $this_subfield_value ) {
3193 $authorised_values->{ $tagslib->{ $tag }{ $subfield }{'authorised_value'} } = $this_subfield_value;
3200 # warn ( Data::Dumper->Dump( [ $authorised_values ], [ 'authorised_values' ] ) );
3201 return $authorised_values;
3211 Koha Developement team <info@koha.org>
3213 Paul POULAIN paul.poulain@free.fr
3215 Joshua Ferraro jmf@liblime.com