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
26 use MARC::File::USMARC;
31 use C4::Dates qw/format_date/;
32 use C4::Log; # logaction
34 use vars qw($VERSION @ISA @EXPORT);
39 @ISA = qw( Exporter );
43 # to add biblios or items
44 push @EXPORT, qw( &AddBiblio &AddBiblioAndItems );
52 &GetBiblioItemByBiblioNumber
53 &GetBiblioFromItemNumber
73 &GetItemsByBiblioitemnumber
74 &GetItemnumberFromBarcode
78 &GetAuthorisedValueDesc
82 &GetPublisherNameFromIsbn
101 # those functions are exported but should not be used
102 # they are usefull is few circumstances, so are exported.
103 # but don't use them unless you're a core developer ;-)
111 &TransformHtmlToMarc2
114 &PrepareItemrecordDisplay
121 C4::Biblio - cataloging management functions
125 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:
129 =item 1. in the biblio,biblioitems,items, etc tables, which are limited to a one-to-one mapping to underlying MARC data
131 =item 2. as raw MARC in the Zebra index and storage engine
133 =item 3. as raw MARC the biblioitems.marc and biblioitems.marcxml
137 In the 3.0 version of Koha, the authoritative record-level information is in biblioitems.marcxml
139 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.
143 =item 1. Compared with MySQL, Zebra is slow to update an index for small data changes -- especially for proc-intensive operations like circulation
145 =item 2. Zebra's index has been known to crash and a backup of the data is necessary to rebuild it in such cases
149 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:
153 =item 1. Add*/Mod*/Del*/ - high-level external functions suitable for being called from external scripts to manage the collection
155 =item 2. _koha_* - low-level internal functions for managing the koha tables
157 =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.
159 =item 4. Zebra functions used to update the Zebra index
161 =item 5. internal helper functions such as char_decode, checkitems, etc. Some of these probably belong in Koha.pm
165 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 :
169 =item 1. save datas in biblio and biblioitems table, that gives us a biblionumber and a biblioitemnumber
171 =item 2. add the biblionumber and biblioitemnumber into the MARC records
173 =item 3. save the marc record
177 When dealing with items, we must :
181 =item 1. save the item in items table, that gives us an itemnumber
183 =item 2. add the itemnumber to the item MARC field
185 =item 3. overwrite the MARC record (with the added item) into biblioitems.marc(xml)
187 When modifying a biblio or an item, the behaviour is quite similar.
191 =head1 EXPORTED FUNCTIONS
197 ($biblionumber,$biblioitemnumber) = AddBiblio($record,$frameworkcode);
198 Exported function (core API) for adding a new biblio to koha.
205 my ( $record, $frameworkcode ) = @_;
206 my ($biblionumber,$biblioitemnumber,$error);
207 my $dbh = C4::Context->dbh;
208 # transform the data into koha-table style data
209 my $olddata = TransformMarcToKoha( $dbh, $record, $frameworkcode );
210 ($biblionumber,$error) = _koha_add_biblio( $dbh, $olddata, $frameworkcode );
211 $olddata->{'biblionumber'} = $biblionumber;
212 ($biblioitemnumber,$error) = _koha_add_biblioitem( $dbh, $olddata );
214 _koha_marc_update_bib_ids($record, $frameworkcode, $biblionumber, $biblioitemnumber);
217 $biblionumber = ModBiblioMarc( $record, $biblionumber, $frameworkcode );
219 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","ADD",$biblionumber,"biblio")
220 if C4::Context->preference("CataloguingLog");
222 return ( $biblionumber, $biblioitemnumber );
225 =head2 AddBiblioAndItems
229 ($biblionumber,$biblioitemnumber, $itemnumber_ref, $error_ref) = AddBiblioAndItems($record, $frameworkcode);
233 Efficiently add a biblio record and create item records from its
234 embedded item fields. This routine is suitable for batch jobs.
236 The goal of this API is to have a similar effect to using AddBiblio
237 and AddItems in succession, but without inefficient repeated
238 parsing of the MARC XML bib record.
240 One functional difference is that the duplicate item barcode
241 check is implemented in this API, instead of relying on
242 the caller to do it, like AddItem does.
244 This function returns the biblionumber and biblioitemnumber of the
245 new bib, an arrayref of new itemsnumbers, and an arrayref of item
246 errors encountered during the processing. Each entry in the errors
247 list is a hashref containing the following keys:
253 Sequence number of original item tag in the MARC record.
257 Item barcode, provide to assist in the construction of
258 useful error messages.
260 =item error_condition
262 Code representing the error condition. Can be 'duplicate_barcode',
263 'invalid_homebranch', or 'invalid_holdingbranch'.
265 =item error_information
267 Additional information appropriate to the error condition.
273 sub AddBiblioAndItems {
274 my ( $record, $frameworkcode ) = @_;
275 my ($biblionumber,$biblioitemnumber,$error);
276 my @itemnumbers = ();
278 my $dbh = C4::Context->dbh;
280 # transform the data into koha-table style data
281 # FIXME - this paragraph copied from AddBiblio
282 my $olddata = TransformMarcToKoha( $dbh, $record, $frameworkcode );
283 ($biblionumber,$error) = _koha_add_biblio( $dbh, $olddata, $frameworkcode );
284 $olddata->{'biblionumber'} = $biblionumber;
285 ($biblioitemnumber,$error) = _koha_add_biblioitem( $dbh, $olddata );
287 # FIXME - this paragraph copied from AddBiblio
288 _koha_marc_update_bib_ids($record, $frameworkcode, $biblionumber, $biblioitemnumber);
290 # now we loop through the item tags and start creating items
291 my @bad_item_fields = ();
292 my ($itemtag, $itemsubfield) = &GetMarcFromKohaField("items.itemnumber",'');
293 my $item_sequence_num = 0;
294 ITEMFIELD: foreach my $item_field ($record->field($itemtag)) {
295 $item_sequence_num++;
296 # we take the item field and stick it into a new
297 # MARC record -- this is required so far because (FIXME)
298 # TransformMarcToKoha requires a MARC::Record, not a MARC::Field
299 # and there is no TransformMarcFieldToKoha
300 my $temp_item_marc = MARC::Record->new();
301 $temp_item_marc->append_fields($item_field);
303 # add biblionumber and biblioitemnumber
304 my $item = TransformMarcToKoha( $dbh, $temp_item_marc, $frameworkcode, 'items' );
305 $item->{'biblionumber'} = $biblionumber;
306 $item->{'biblioitemnumber'} = $biblioitemnumber;
308 # check for duplicate barcode
309 my %item_errors = CheckItemPreSave($item);
311 push @errors, _repack_item_errors($item_sequence_num, $item, \%item_errors);
312 push @bad_item_fields, $item_field;
315 my $duplicate_barcode = exists($item->{'barcode'}) && GetItemnumberFromBarcode($item->{'barcode'});
316 if ($duplicate_barcode) {
317 warn "ERROR: cannot add item $item->{'barcode'} for biblio $biblionumber: duplicate barcode\n";
320 # Make sure item statuses are set to 0 if empty or NULL in both the item and the MARC
321 for ('notforloan', 'damaged','itemlost','wthdrawn') {
322 if (!$item->{$_} or $item->{$_} eq "") {
324 &MARCitemchange( $temp_item_marc, "items.$_", 0 );
328 # FIXME - dateaccessioned stuff copied from AddItem
329 if ( !$item->{'dateaccessioned'} || $item->{'dateaccessioned'} eq '' ) {
332 my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
337 "$year-" . sprintf( "%0.2d", $mon ) . "-" . sprintf( "%0.2d", $mday );
338 $item->{'dateaccessioned'} = $date;
339 &MARCitemchange( $temp_item_marc, "items.dateaccessioned", $date );
342 my ( $itemnumber, $error ) = &_koha_new_items( $dbh, $item, $item->{barcode} );
343 warn $error if $error;
344 push @itemnumbers, $itemnumber; # FIXME not checking error
346 # FIXME - not copied from AddItem
347 # FIXME - AddItems equiv code about passing $sth to TransformKohaToMarcOneField is stupid
348 &MARCitemchange( $temp_item_marc, "items.itemnumber", $itemnumber );
350 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","ADD",$itemnumber,"item")
351 if C4::Context->preference("CataloguingLog");
353 $item_field->replace_with($temp_item_marc->field($itemtag));
356 # remove any MARC item fields for rejected items
357 foreach my $item_field (@bad_item_fields) {
358 $record->delete_field($item_field);
362 # FIXME - this paragraph copied from AddBiblio -- however, moved since
363 # since we need to create the items row and plug in the itemnumbers in the
365 $biblionumber = ModBiblioMarc( $record, $biblionumber, $frameworkcode );
367 # FIXME - when using this API, do we log both bib and item add, or just
369 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","ADD",$biblionumber,"biblio")
370 if C4::Context->preference("CataloguingLog");
372 return ( $biblionumber, $biblioitemnumber, \@itemnumbers, \@errors);
376 sub _repack_item_errors {
377 my $item_sequence_num = shift;
378 my $item_ref = shift;
379 my $error_ref = shift;
381 my @repacked_errors = ();
383 foreach my $error_code (sort keys %{ $error_ref }) {
384 my $repacked_error = {};
385 $repacked_error->{'item_sequence'} = $item_sequence_num;
386 $repacked_error->{'item_barcode'} = exists($item_ref->{'barcode'}) ? $item_ref->{'barcode'} : '';
387 $repacked_error->{'error_code'} = $error_code;
388 $repacked_error->{'error_information'} = $error_ref->{$error_code};
389 push @repacked_errors, $repacked_error;
392 return @repacked_errors;
397 ModBiblio( $record,$biblionumber,$frameworkcode);
398 Exported function (core API) to modify a biblio
403 my ( $record, $biblionumber, $frameworkcode ) = @_;
404 if (C4::Context->preference("CataloguingLog")) {
405 my $newrecord = GetMarcBiblio($biblionumber);
406 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","MODIFY",$biblionumber,"BEFORE=>".$newrecord->as_formatted);
409 my $dbh = C4::Context->dbh;
411 $frameworkcode = "" unless $frameworkcode;
413 # get the items before and append them to the biblio before updating the record, atm we just have the biblio
414 my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",$frameworkcode);
415 my $oldRecord = GetMarcBiblio( $biblionumber );
417 # parse each item, and, for an unknown reason, re-encode each subfield
418 # if you don't do that, the record will have encoding mixed
419 # and the biblio will be re-encoded.
420 # strange, I (Paul P.) searched more than 1 day to understand what happends
421 # but could only solve the problem this way...
422 my @fields = $oldRecord->field( $itemtag );
423 foreach my $fielditem ( @fields ){
425 foreach ($fielditem->subfields()) {
427 $field->add_subfields(Encode::encode('utf-8',$_->[0]) => Encode::encode('utf-8',$_->[1]));
429 $field = MARC::Field->new("$itemtag",'','',Encode::encode('utf-8',$_->[0]) => Encode::encode('utf-8',$_->[1]));
432 $record->append_fields($field);
435 # update biblionumber and biblioitemnumber in MARC
436 # FIXME - this is assuming a 1 to 1 relationship between
437 # biblios and biblioitems
438 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
439 $sth->execute($biblionumber);
440 my ($biblioitemnumber) = $sth->fetchrow;
442 _koha_marc_update_bib_ids($record, $frameworkcode, $biblionumber, $biblioitemnumber);
444 # update the MARC record (that now contains biblio and items) with the new record data
445 &ModBiblioMarc( $record, $biblionumber, $frameworkcode );
447 # load the koha-table data object
448 my $oldbiblio = TransformMarcToKoha( $dbh, $record, $frameworkcode );
450 # modify the other koha tables
451 _koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode );
452 _koha_modify_biblioitem_nonmarc( $dbh, $oldbiblio );
456 =head2 ModBiblioframework
458 ModBiblioframework($biblionumber,$frameworkcode);
459 Exported function to modify a biblio framework
463 sub ModBiblioframework {
464 my ( $biblionumber, $frameworkcode ) = @_;
465 my $dbh = C4::Context->dbh;
466 my $sth = $dbh->prepare(
467 "UPDATE biblio SET frameworkcode=? WHERE biblionumber=?"
469 $sth->execute($frameworkcode, $biblionumber);
477 &ModItemInMarc( $record, $biblionumber, $itemnumber, $frameworkcode )
484 my ( $ItemRecord, $biblionumber, $itemnumber, $frameworkcode) = @_;
485 my $dbh = C4::Context->dbh;
487 # get complete MARC record & replace the item field by the new one
488 my $completeRecord = GetMarcBiblio($biblionumber);
489 my ($itemtag,$itemsubfield) = GetMarcFromKohaField("items.itemnumber",$frameworkcode);
490 my $itemField = $ItemRecord->field($itemtag);
491 my @items = $completeRecord->field($itemtag);
493 if ($_->subfield($itemsubfield) eq $itemnumber) {
494 # $completeRecord->delete_field($_);
495 $_->replace_with($itemField);
499 my $sth = $dbh->prepare("UPDATE biblioitems SET marc=?,marcxml=? WHERE biblionumber=?");
500 $sth->execute( $completeRecord->as_usmarc(), $completeRecord->as_xml_record(),$biblionumber );
502 ModZebra($biblionumber,"specialUpdate","biblioserver",$completeRecord);
509 my $error = &DelBiblio($dbh,$biblionumber);
510 Exported function (core API) for deleting a biblio in koha.
511 Deletes biblio record from Zebra and Koha tables (biblio,biblioitems,items)
512 Also backs it up to deleted* tables
513 Checks to make sure there are not issues on any of the items
515 C<$error> : undef unless an error occurs
522 my ( $biblionumber ) = @_;
523 my $dbh = C4::Context->dbh;
524 my $error; # for error handling
526 # First make sure this biblio has no items attached
527 my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber=?");
528 $sth->execute($biblionumber);
529 if (my $itemnumber = $sth->fetchrow){
530 # Fix this to use a status the template can understand
531 $error .= "This Biblio has items attached, please delete them first before deleting this biblio ";
534 return $error if $error;
536 # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
537 # for at least 2 reasons :
538 # - we need to read the biblio if NoZebra is set (to remove it from the indexes
539 # - if something goes wrong, the biblio may be deleted from Koha but not from zebra
540 # 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)
541 ModZebra($biblionumber, "recordDelete", "biblioserver", undef);
543 # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
546 "SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
547 $sth->execute($biblionumber);
548 while ( my $biblioitemnumber = $sth->fetchrow ) {
550 # delete this biblioitem
551 $error = _koha_delete_biblioitems( $dbh, $biblioitemnumber );
552 return $error if $error;
555 # delete biblio from Koha tables and save in deletedbiblio
556 # must do this *after* _koha_delete_biblioitems, otherwise
557 # delete cascade will prevent deletedbiblioitems rows
558 # from being generated by _koha_delete_biblioitems
559 $error = _koha_delete_biblio( $dbh, $biblionumber );
561 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","DELETE",$biblionumber,"")
562 if C4::Context->preference("CataloguingLog");
570 DelItem( $biblionumber, $itemnumber );
571 Exported function (core API) for deleting an item record in Koha.
578 my ( $dbh, $biblionumber, $itemnumber ) = @_;
580 # check the item has no current issues
583 &_koha_delete_item( $dbh, $itemnumber );
585 # get the MARC record
586 my $record = GetMarcBiblio($biblionumber);
587 my $frameworkcode = GetFrameworkCode($biblionumber);
590 my $copy2deleted = $dbh->prepare("UPDATE deleteditems SET marc=? WHERE itemnumber=?");
591 $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
593 #search item field code
594 my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",$frameworkcode);
595 my @fields = $record->field($itemtag);
597 # delete the item specified
598 foreach my $field (@fields) {
599 if ( $field->subfield($itemsubfield) eq $itemnumber ) {
600 $record->delete_field($field);
603 &ModBiblioMarc( $record, $biblionumber, $frameworkcode );
604 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","DELETE",$itemnumber,"item")
605 if C4::Context->preference("CataloguingLog");
608 =head2 CheckItemPreSave
612 my $item_ref = TransformMarcToKoha($marc, 'items');
614 my %errors = CheckItemPreSave($item_ref);
615 if (exists $errors{'duplicate_barcode'}) {
616 print "item has duplicate barcode: ", $errors{'duplicate_barcode'}, "\n";
617 } elsif (exists $errors{'invalid_homebranch'}) {
618 print "item has invalid home branch: ", $errors{'invalid_homebranch'}, "\n";
619 } elsif (exists $errors{'invalid_holdingbranch'}) {
620 print "item has invalid holding branch: ", $errors{'invalid_holdingbranch'}, "\n";
627 Given a hashref containing item fields, determine if it can be
628 inserted or updated in the database. Specifically, checks for
629 database integrity issues, and returns a hash containing any
630 of the following keys, if applicable.
634 =item duplicate_barcode
636 Barcode, if it duplicates one already found in the database.
638 =item invalid_homebranch
640 Home branch, if not defined in branches table.
642 =item invalid_holdingbranch
644 Holding branch, if not defined in branches table.
648 This function does NOT implement any policy-related checks,
649 e.g., whether current operator is allowed to save an
650 item that has a given branch code.
654 sub CheckItemPreSave {
655 my $item_ref = shift;
659 # check for duplicate barcode
660 if (exists $item_ref->{'barcode'} and defined $item_ref->{'barcode'}) {
661 my $existing_itemnumber = GetItemnumberFromBarcode($item_ref->{'barcode'});
662 if ($existing_itemnumber) {
663 if (!exists $item_ref->{'itemnumber'} # new item
664 or $item_ref->{'itemnumber'} != $existing_itemnumber) { # existing item
665 $errors{'duplicate_barcode'} = $item_ref->{'barcode'};
670 # check for valid home branch
671 if (exists $item_ref->{'homebranch'} and defined $item_ref->{'homebranch'}) {
672 my $branch_name = GetBranchName($item_ref->{'homebranch'});
673 unless (defined $branch_name) {
674 # relies on fact that branches.branchname is a non-NULL column,
675 # so GetBranchName returns undef only if branch does not exist
676 $errors{'invalid_homebranch'} = $item_ref->{'homebranch'};
680 # check for valid holding branch
681 if (exists $item_ref->{'holdingbranch'} and defined $item_ref->{'holdingbranch'}) {
682 my $branch_name = GetBranchName($item_ref->{'holdingbranch'});
683 unless (defined $branch_name) {
684 # relies on fact that branches.branchname is a non-NULL column,
685 # so GetBranchName returns undef only if branch does not exist
686 $errors{'invalid_holdingbranch'} = $item_ref->{'holdingbranch'};
698 $data = &GetBiblioData($biblionumber);
699 Returns information about the book with the given biblionumber.
700 C<&GetBiblioData> returns a reference-to-hash. The keys are the fields in
701 the C<biblio> and C<biblioitems> tables in the
703 In addition, C<$data-E<gt>{subject}> is the list of the book's
704 subjects, separated by C<" , "> (space, comma, space).
705 If there are multiple biblioitems with the given biblionumber, only
706 the first one is considered.
714 my $dbh = C4::Context->dbh;
716 # my $query = C4::Context->preference('item-level_itypes') ?
717 # " SELECT * , biblioitems.notes AS bnotes, biblio.notes
719 # LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
720 # WHERE biblio.biblionumber = ?
721 # AND biblioitems.biblionumber = biblio.biblionumber
724 my $query = " SELECT * , biblioitems.notes AS bnotes, itemtypes.notforloan as bi_notforloan, biblio.notes
726 LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
727 LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype
728 WHERE biblio.biblionumber = ?
729 AND biblioitems.biblionumber = biblio.biblionumber ";
731 my $sth = $dbh->prepare($query);
732 $sth->execute($bibnum);
734 $data = $sth->fetchrow_hashref;
738 } # sub GetBiblioData
745 @results = &GetItemsInfo($biblionumber, $type);
747 Returns information about books with the given biblionumber.
749 C<$type> may be either C<intra> or anything else. If it is not set to
750 C<intra>, then the search will exclude lost, very overdue, and
753 C<&GetItemsInfo> returns a list of references-to-hash. Each element
754 contains a number of keys. Most of them are table items from the
755 C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
756 Koha database. Other keys include:
760 =item C<$data-E<gt>{branchname}>
762 The name (not the code) of the branch to which the book belongs.
764 =item C<$data-E<gt>{datelastseen}>
766 This is simply C<items.datelastseen>, except that while the date is
767 stored in YYYY-MM-DD format in the database, here it is converted to
768 DD/MM/YYYY format. A NULL date is returned as C<//>.
770 =item C<$data-E<gt>{datedue}>
772 =item C<$data-E<gt>{class}>
774 This is the concatenation of C<biblioitems.classification>, the book's
775 Dewey code, and C<biblioitems.subclass>.
777 =item C<$data-E<gt>{ocount}>
779 I think this is the number of copies of the book available.
781 =item C<$data-E<gt>{order}>
783 If this is set, it is set to C<One Order>.
792 my ( $biblionumber, $type ) = @_;
793 my $dbh = C4::Context->dbh;
794 my $query = "SELECT *,items.notforloan as itemnotforloan
796 LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
797 LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber";
798 $query .= (C4::Context->preference('item-level_itypes')) ?
799 " LEFT JOIN itemtypes on items.itype = itemtypes.itemtype "
800 : " LEFT JOIN itemtypes on biblioitems.itemtype = itemtypes.itemtype ";
801 $query .= "WHERE items.biblionumber = ? ORDER BY items.dateaccessioned desc" ;
802 my $sth = $dbh->prepare($query);
803 $sth->execute($biblionumber);
806 my ( $date_due, $count_reserves );
808 my $isth = $dbh->prepare(
809 "SELECT issues.*,borrowers.cardnumber,borrowers.surname,borrowers.firstname,borrowers.branchcode as bcode
810 FROM issues LEFT JOIN borrowers ON issues.borrowernumber=borrowers.borrowernumber
812 AND returndate IS NULL"
814 while ( my $data = $sth->fetchrow_hashref ) {
816 $isth->execute( $data->{'itemnumber'} );
817 if ( my $idata = $isth->fetchrow_hashref ) {
818 $data->{borrowernumber} = $idata->{borrowernumber};
819 $data->{cardnumber} = $idata->{cardnumber};
820 $data->{surname} = $idata->{surname};
821 $data->{firstname} = $idata->{firstname};
822 $datedue = $idata->{'date_due'};
823 if (C4::Context->preference("IndependantBranches")){
824 my $userenv = C4::Context->userenv;
825 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
826 $data->{'NOTSAMEBRANCH'} = 1 if ($idata->{'bcode'} ne $userenv->{branch});
830 if ( $datedue eq '' ) {
831 my ( $restype, $reserves ) =
832 C4::Reserves::CheckReserves( $data->{'itemnumber'} );
834 $count_reserves = $restype;
839 #get branch information.....
840 my $bsth = $dbh->prepare(
841 "SELECT * FROM branches WHERE branchcode = ?
844 $bsth->execute( $data->{'holdingbranch'} );
845 if ( my $bdata = $bsth->fetchrow_hashref ) {
846 $data->{'branchname'} = $bdata->{'branchname'};
848 $data->{'datedue'} = $datedue;
849 $data->{'count_reserves'} = $count_reserves;
851 # get notforloan complete status if applicable
852 my $sthnflstatus = $dbh->prepare(
853 'SELECT authorised_value
854 FROM marc_subfield_structure
855 WHERE kohafield="items.notforloan"
859 $sthnflstatus->execute;
860 my ($authorised_valuecode) = $sthnflstatus->fetchrow;
861 if ($authorised_valuecode) {
862 $sthnflstatus = $dbh->prepare(
863 "SELECT lib FROM authorised_values
865 AND authorised_value=?"
867 $sthnflstatus->execute( $authorised_valuecode,
868 $data->{itemnotforloan} );
869 my ($lib) = $sthnflstatus->fetchrow;
870 $data->{notforloan} = $lib;
873 # my stack procedures
874 my $stackstatus = $dbh->prepare(
875 'SELECT authorised_value
876 FROM marc_subfield_structure
877 WHERE kohafield="items.stack"
880 $stackstatus->execute;
882 ($authorised_valuecode) = $stackstatus->fetchrow;
883 if ($authorised_valuecode) {
884 $stackstatus = $dbh->prepare(
886 FROM authorised_values
888 AND authorised_value=?
891 $stackstatus->execute( $authorised_valuecode, $data->{stack} );
892 my ($lib) = $stackstatus->fetchrow;
893 $data->{stack} = $lib;
895 # Find the last 3 people who borrowed this item.
896 my $sth2 = $dbh->prepare("SELECT * FROM issues,borrowers
898 AND issues.borrowernumber = borrowers.borrowernumber
899 AND returndate IS NOT NULL LIMIT 3");
900 $sth2->execute($data->{'itemnumber'});
902 while (my $data2 = $sth2->fetchrow_hashref()) {
903 $data->{"timestamp$ii"} = $data2->{'timestamp'} if $data2->{'timestamp'};
904 $data->{"card$ii"} = $data2->{'cardnumber'} if $data2->{'cardnumber'};
905 $data->{"borrower$ii"} = $data2->{'borrowernumber'} if $data2->{'borrowernumber'};
909 $results[$i] = $data;
921 $itemstatushash = &getitemstatus($fwkcode);
922 returns information about status.
923 Can be MARC dependant.
925 But basically could be can be loan or not
926 Create a status selector with the following code
928 =head3 in PERL SCRIPT
930 my $itemstatushash = getitemstatus;
932 foreach my $thisstatus (keys %$itemstatushash) {
933 my %row =(value => $thisstatus,
934 statusname => $itemstatushash->{$thisstatus}->{'statusname'},
936 push @itemstatusloop, \%row;
938 $template->param(statusloop=>\@itemstatusloop);
943 <select name="statusloop">
944 <option value="">Default</option>
945 <!-- TMPL_LOOP name="statusloop" -->
946 <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="statusname" --></option>
954 # returns a reference to a hash of references to status...
957 my $dbh = C4::Context->dbh;
959 $fwk = '' unless ($fwk);
960 my ( $tag, $subfield ) =
961 GetMarcFromKohaField( "items.notforloan", $fwk );
962 if ( $tag and $subfield ) {
965 "SELECT authorised_value
966 FROM marc_subfield_structure
972 $sth->execute( $tag, $subfield, $fwk );
973 if ( my ($authorisedvaluecat) = $sth->fetchrow ) {
976 "SELECT authorised_value,lib
977 FROM authorised_values
982 $authvalsth->execute($authorisedvaluecat);
983 while ( my ( $authorisedvalue, $lib ) = $authvalsth->fetchrow ) {
984 $itemstatus{$authorisedvalue} = $lib;
1000 $itemstatus{"1"} = "Not For Loan";
1001 return \%itemstatus;
1004 =head2 getitemlocation
1008 $itemlochash = &getitemlocation($fwk);
1009 returns informations about location.
1010 where fwk stands for an optional framework code.
1011 Create a location selector with the following code
1013 =head3 in PERL SCRIPT
1015 my $itemlochash = getitemlocation;
1017 foreach my $thisloc (keys %$itemlochash) {
1018 my $selected = 1 if $thisbranch eq $branch;
1019 my %row =(locval => $thisloc,
1020 selected => $selected,
1021 locname => $itemlochash->{$thisloc},
1023 push @itemlocloop, \%row;
1025 $template->param(itemlocationloop => \@itemlocloop);
1029 <select name="location">
1030 <option value="">Default</option>
1031 <!-- TMPL_LOOP name="itemlocationloop" -->
1032 <option value="<!-- TMPL_VAR name="locval" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="locname" --></option>
1040 sub GetItemLocation {
1042 # returns a reference to a hash of references to location...
1045 my $dbh = C4::Context->dbh;
1047 $fwk = '' unless ($fwk);
1048 my ( $tag, $subfield ) =
1049 GetMarcFromKohaField( "items.location", $fwk );
1050 if ( $tag and $subfield ) {
1053 "SELECT authorised_value
1054 FROM marc_subfield_structure
1057 AND frameworkcode=?"
1059 $sth->execute( $tag, $subfield, $fwk );
1060 if ( my ($authorisedvaluecat) = $sth->fetchrow ) {
1063 "SELECT authorised_value,lib
1064 FROM authorised_values
1068 $authvalsth->execute($authorisedvaluecat);
1069 while ( my ( $authorisedvalue, $lib ) = $authvalsth->fetchrow ) {
1070 $itemlocation{$authorisedvalue} = $lib;
1072 $authvalsth->finish;
1073 return \%itemlocation;
1086 $itemlocation{"1"} = "Not For Loan";
1087 return \%itemlocation;
1092 $items = GetLostItems($where,$orderby);
1094 This function get the items lost into C<$items>.
1099 C<$where> is a hashref. it containts a field of the items table as key
1100 and the value to match as value.
1101 C<$orderby> is a field of the items table.
1104 C<$items> is a reference to an array full of hasref which keys are items' table column.
1106 =item usage in the perl script:
1109 $where{barcode} = 0001548;
1110 my $items = GetLostItems( \%where, "homebranch" );
1111 $template->param(itemsloop => $items);
1118 # Getting input args.
1120 my $orderby = shift;
1121 my $dbh = C4::Context->dbh;
1126 WHERE itemlost IS NOT NULL
1129 foreach my $key (keys %$where) {
1130 $query .= " AND " . $key . " LIKE '%" . $where->{$key} . "%'";
1132 $query .= " ORDER BY ".$orderby if defined $orderby;
1134 my $sth = $dbh->prepare($query);
1137 while ( my $row = $sth->fetchrow_hashref ){
1143 =head2 GetItemsForInventory
1145 $itemlist = GetItemsForInventory($minlocation,$maxlocation,$datelastseen,$offset,$size)
1147 Retrieve a list of title/authors/barcode/callnumber, for biblio inventory.
1149 The sub returns a list of hashes, containing itemnumber, author, title, barcode & item callnumber.
1150 It is ordered by callnumber,title.
1152 The minlocation & maxlocation parameters are used to specify a range of item callnumbers
1153 the datelastseen can be used to specify that you want to see items not seen since a past date only.
1154 offset & size can be used to retrieve only a part of the whole listing (defaut behaviour)
1158 sub GetItemsForInventory {
1159 my ( $minlocation, $maxlocation,$location, $datelastseen, $branch, $offset, $size ) = @_;
1160 my $dbh = C4::Context->dbh;
1162 if ($datelastseen) {
1163 $datelastseen=format_date_in_iso($datelastseen);
1165 "SELECT itemnumber,barcode,itemcallnumber,title,author,biblio.biblionumber,datelastseen
1167 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1168 WHERE itemcallnumber>= ?
1169 AND itemcallnumber <=?
1170 AND (datelastseen< ? OR datelastseen IS NULL)";
1171 $query.= " AND items.location=".$dbh->quote($location) if $location;
1172 $query.= " AND items.homebranch=".$dbh->quote($branch) if $branch;
1173 $query .= " ORDER BY itemcallnumber,title";
1174 $sth = $dbh->prepare($query);
1175 $sth->execute( $minlocation, $maxlocation, $datelastseen );
1179 SELECT itemnumber,barcode,itemcallnumber,biblio.biblionumber,title,author,datelastseen
1181 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1182 WHERE itemcallnumber>= ?
1183 AND itemcallnumber <=?";
1184 $query.= " AND items.location=".$dbh->quote($location) if $location;
1185 $query.= " AND items.homebranch=".$dbh->quote($branch) if $branch;
1186 $query .= " ORDER BY itemcallnumber,title";
1187 $sth = $dbh->prepare($query);
1188 $sth->execute( $minlocation, $maxlocation );
1191 while ( my $row = $sth->fetchrow_hashref ) {
1192 $offset-- if ($offset);
1193 $row->{datelastseen}=format_date($row->{datelastseen});
1194 if ( ( !$offset ) && $size ) {
1195 push @results, $row;
1202 =head2 &GetBiblioItemData
1206 $itemdata = &GetBiblioItemData($biblioitemnumber);
1208 Looks up the biblioitem with the given biblioitemnumber. Returns a
1209 reference-to-hash. The keys are the fields from the C<biblio>,
1210 C<biblioitems>, and C<itemtypes> tables in the Koha database, except
1211 that C<biblioitems.notes> is given as C<$itemdata-E<gt>{bnotes}>.
1218 sub GetBiblioItemData {
1219 my ($biblioitemnumber) = @_;
1220 my $dbh = C4::Context->dbh;
1221 my $query = "SELECT *,biblioitems.notes AS bnotes
1222 FROM biblio, biblioitems ";
1223 unless(C4::Context->preference('item-level_itypes')) {
1224 $query .= "LEFT JOIN itemtypes on biblioitems.itemtype=itemtypes.itemtype ";
1226 $query .= " WHERE biblio.biblionumber = biblioitems.biblionumber
1227 AND biblioitemnumber = ? ";
1228 my $sth = $dbh->prepare($query);
1230 $sth->execute($biblioitemnumber);
1231 $data = $sth->fetchrow_hashref;
1234 } # sub &GetBiblioItemData
1236 =head2 GetItemnumberFromBarcode
1240 $result = GetItemnumberFromBarcode($barcode);
1246 sub GetItemnumberFromBarcode {
1248 my $dbh = C4::Context->dbh;
1251 $dbh->prepare("SELECT itemnumber FROM items WHERE items.barcode=?");
1252 $rq->execute($barcode);
1253 my ($result) = $rq->fetchrow;
1257 =head2 GetBiblioItemByBiblioNumber
1261 NOTE : This function has been copy/paste from C4/Biblio.pm from head before zebra integration.
1267 sub GetBiblioItemByBiblioNumber {
1268 my ($biblionumber) = @_;
1269 my $dbh = C4::Context->dbh;
1270 my $sth = $dbh->prepare("Select * FROM biblioitems WHERE biblionumber = ?");
1274 $sth->execute($biblionumber);
1276 while ( my $data = $sth->fetchrow_hashref ) {
1277 push @results, $data;
1284 =head2 GetBiblioFromItemNumber
1288 $item = &GetBiblioFromItemNumber($itemnumber,$barcode);
1290 Looks up the item with the given itemnumber. if undef, try the barcode.
1292 C<&itemnodata> returns a reference-to-hash whose keys are the fields
1293 from the C<biblio>, C<biblioitems>, and C<items> tables in the Koha
1301 sub GetBiblioFromItemNumber {
1302 my ( $itemnumber, $barcode ) = @_;
1303 my $dbh = C4::Context->dbh;
1306 $sth=$dbh->prepare( "SELECT * FROM items
1307 LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
1308 LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
1309 WHERE items.itemnumber = ?") ;
1310 $sth->execute($itemnumber);
1312 $sth=$dbh->prepare( "SELECT * FROM items
1313 LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
1314 LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
1315 WHERE items.barcode = ?") ;
1316 $sth->execute($barcode);
1318 my $data = $sth->fetchrow_hashref;
1327 ( $count, @results ) = &GetBiblio($biblionumber);
1334 my ($biblionumber) = @_;
1335 my $dbh = C4::Context->dbh;
1336 my $sth = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber = ?");
1339 $sth->execute($biblionumber);
1340 while ( my $data = $sth->fetchrow_hashref ) {
1341 $results[$count] = $data;
1345 return ( $count, @results );
1352 $data = &GetItem($itemnumber,$barcode);
1354 return Item information, for a given itemnumber or barcode
1361 my ($itemnumber,$barcode) = @_;
1362 my $dbh = C4::Context->dbh;
1364 my $sth = $dbh->prepare("
1366 WHERE itemnumber = ?");
1367 $sth->execute($itemnumber);
1368 my $data = $sth->fetchrow_hashref;
1371 my $sth = $dbh->prepare("
1375 $sth->execute($barcode);
1376 my $data = $sth->fetchrow_hashref;
1381 =head2 get_itemnumbers_of
1385 my @itemnumbers_of = get_itemnumbers_of(@biblionumbers);
1387 Given a list of biblionumbers, return the list of corresponding itemnumbers
1388 for each biblionumber.
1390 Return a reference on a hash where keys are biblionumbers and values are
1391 references on array of itemnumbers.
1397 sub get_itemnumbers_of {
1398 my @biblionumbers = @_;
1400 my $dbh = C4::Context->dbh;
1406 WHERE biblionumber IN (?' . ( ',?' x scalar @biblionumbers - 1 ) . ')
1408 my $sth = $dbh->prepare($query);
1409 $sth->execute(@biblionumbers);
1413 while ( my ( $itemnumber, $biblionumber ) = $sth->fetchrow_array ) {
1414 push @{ $itemnumbers_of{$biblionumber} }, $itemnumber;
1417 return \%itemnumbers_of;
1420 =head2 GetItemInfosOf
1424 GetItemInfosOf(@itemnumbers);
1430 sub GetItemInfosOf {
1431 my @itemnumbers = @_;
1436 WHERE itemnumber IN (' . join( ',', @itemnumbers ) . ')
1438 return get_infos_of( $query, 'itemnumber' );
1441 =head2 GetItemsByBiblioitemnumber
1445 GetItemsByBiblioitemnumber($biblioitemnumber);
1447 Returns an arrayref of hashrefs suitable for use in a TMPL_LOOP
1448 Called by moredetail.pl
1454 sub GetItemsByBiblioitemnumber {
1455 my ( $bibitem ) = @_;
1456 my $dbh = C4::Context->dbh;
1457 my $sth = $dbh->prepare("SELECT * FROM items WHERE items.biblioitemnumber = ?") || die $dbh->errstr;
1458 # Get all items attached to a biblioitem
1461 $sth->execute($bibitem) || die $sth->errstr;
1462 while ( my $data = $sth->fetchrow_hashref ) {
1463 # Foreach item, get circulation information
1464 my $sth2 = $dbh->prepare( "SELECT * FROM issues,borrowers
1465 WHERE itemnumber = ?
1466 AND returndate is NULL
1467 AND issues.borrowernumber = borrowers.borrowernumber"
1469 $sth2->execute( $data->{'itemnumber'} );
1470 if ( my $data2 = $sth2->fetchrow_hashref ) {
1471 # if item is out, set the due date and who it is out too
1472 $data->{'date_due'} = $data2->{'date_due'};
1473 $data->{'cardnumber'} = $data2->{'cardnumber'};
1474 $data->{'borrowernumber'} = $data2->{'borrowernumber'};
1477 # set date_due to blank, so in the template we check itemlost, and wthdrawn
1478 $data->{'date_due'} = '';
1481 # Find the last 3 people who borrowed this item.
1482 my $query2 = "SELECT * FROM issues, borrowers WHERE itemnumber = ?
1483 AND issues.borrowernumber = borrowers.borrowernumber
1484 AND returndate is not NULL
1485 ORDER BY returndate desc,timestamp desc LIMIT 3";
1486 $sth2 = $dbh->prepare($query2) || die $dbh->errstr;
1487 $sth2->execute( $data->{'itemnumber'} ) || die $sth2->errstr;
1489 while ( my $data2 = $sth2->fetchrow_hashref ) {
1490 $data->{"timestamp$i2"} = $data2->{'timestamp'};
1491 $data->{"card$i2"} = $data2->{'cardnumber'};
1492 $data->{"borrower$i2"} = $data2->{'borrowernumber'};
1496 push(@results,$data);
1503 =head2 GetBiblioItemInfosOf
1507 GetBiblioItemInfosOf(@biblioitemnumbers);
1513 sub GetBiblioItemInfosOf {
1514 my @biblioitemnumbers = @_;
1517 SELECT biblioitemnumber,
1521 WHERE biblioitemnumber IN (' . join( ',', @biblioitemnumbers ) . ')
1523 return get_infos_of( $query, 'biblioitemnumber' );
1526 =head1 FUNCTIONS FOR HANDLING MARC MANAGEMENT
1528 =head2 GetMarcStructure
1532 $res = GetMarcStructure($forlibrarian,$frameworkcode);
1534 Returns a reference to a big hash of hash, with the Marc structure for the given frameworkcode
1535 $forlibrarian :if set to 1, the MARC descriptions are the librarians ones, otherwise it's the public (OPAC) ones
1536 $frameworkcode : the framework code to read
1542 sub GetMarcStructure {
1543 my ( $forlibrarian, $frameworkcode ) = @_;
1544 my $dbh=C4::Context->dbh;
1545 $frameworkcode = "" unless $frameworkcode;
1547 my $libfield = ( $forlibrarian eq 1 ) ? 'liblibrarian' : 'libopac';
1549 # check that framework exists
1552 "SELECT COUNT(*) FROM marc_tag_structure WHERE frameworkcode=?");
1553 $sth->execute($frameworkcode);
1554 my ($total) = $sth->fetchrow;
1555 $frameworkcode = "" unless ( $total > 0 );
1558 "SELECT tagfield,liblibrarian,libopac,mandatory,repeatable
1559 FROM marc_tag_structure
1560 WHERE frameworkcode=?
1563 $sth->execute($frameworkcode);
1564 my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable );
1566 while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable ) =
1569 $res->{$tag}->{lib} =
1570 ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac;
1571 $res->{$tab}->{tab} = "";
1572 $res->{$tag}->{mandatory} = $mandatory;
1573 $res->{$tag}->{repeatable} = $repeatable;
1578 "SELECT tagfield,tagsubfield,liblibrarian,libopac,tab,mandatory,repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link,defaultvalue
1579 FROM marc_subfield_structure
1580 WHERE frameworkcode=?
1581 ORDER BY tagfield,tagsubfield
1585 $sth->execute($frameworkcode);
1588 my $authorised_value;
1600 $tag, $subfield, $liblibrarian,
1602 $mandatory, $repeatable, $authorised_value,
1603 $authtypecode, $value_builder, $kohafield,
1604 $seealso, $hidden, $isurl,
1610 $res->{$tag}->{$subfield}->{lib} =
1611 ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac;
1612 $res->{$tag}->{$subfield}->{tab} = $tab;
1613 $res->{$tag}->{$subfield}->{mandatory} = $mandatory;
1614 $res->{$tag}->{$subfield}->{repeatable} = $repeatable;
1615 $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
1616 $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode;
1617 $res->{$tag}->{$subfield}->{value_builder} = $value_builder;
1618 $res->{$tag}->{$subfield}->{kohafield} = $kohafield;
1619 $res->{$tag}->{$subfield}->{seealso} = $seealso;
1620 $res->{$tag}->{$subfield}->{hidden} = $hidden;
1621 $res->{$tag}->{$subfield}->{isurl} = $isurl;
1622 $res->{$tag}->{$subfield}->{'link'} = $link;
1623 $res->{$tag}->{$subfield}->{defaultvalue} = $defaultvalue;
1628 =head2 GetUsedMarcStructure
1630 the same function as GetMarcStructure expcet it just take field
1631 in tab 0-9. (used field)
1633 my $results = GetUsedMarcStructure($frameworkcode);
1635 L<$results> is a ref to an array which each case containts a ref
1636 to a hash which each keys is the columns from marc_subfield_structure
1638 L<$frameworkcode> is the framework code.
1642 sub GetUsedMarcStructure($){
1643 my $frameworkcode = shift || '';
1644 my $dbh = C4::Context->dbh;
1647 FROM marc_subfield_structure
1649 AND frameworkcode = ?
1652 my $sth = $dbh->prepare($query);
1653 $sth->execute($frameworkcode);
1654 while (my $row = $sth->fetchrow_hashref){
1660 =head2 GetMarcFromKohaField
1664 ($MARCfield,$MARCsubfield)=GetMarcFromKohaField($kohafield,$frameworkcode);
1665 Returns the MARC fields & subfields mapped to the koha field
1666 for the given frameworkcode
1672 sub GetMarcFromKohaField {
1673 my ( $kohafield, $frameworkcode ) = @_;
1674 return 0, 0 unless $kohafield;
1675 my $relations = C4::Context->marcfromkohafield;
1677 $relations->{$frameworkcode}->{$kohafield}->[0],
1678 $relations->{$frameworkcode}->{$kohafield}->[1]
1682 =head2 GetMarcBiblio
1686 Returns MARC::Record of the biblionumber passed in parameter.
1687 the marc record contains both biblio & item datas
1694 my $biblionumber = shift;
1695 my $dbh = C4::Context->dbh;
1697 $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? ");
1698 $sth->execute($biblionumber);
1699 my ($marcxml) = $sth->fetchrow;
1700 MARC::File::XML->default_record_format(C4::Context->preference('marcflavour'));
1701 $marcxml =~ s/\x1e//g;
1702 $marcxml =~ s/\x1f//g;
1703 $marcxml =~ s/\x1d//g;
1704 $marcxml =~ s/\x0f//g;
1705 $marcxml =~ s/\x0c//g;
1707 my $record = MARC::Record->new();
1709 $record = eval {MARC::Record::new_from_xml( $marcxml, "utf8", C4::Context->preference('marcflavour'))};
1711 # $record = MARC::Record::new_from_usmarc( $marc) if $marc;
1722 my $marcxml = GetXmlBiblio($biblionumber);
1724 Returns biblioitems.marcxml of the biblionumber passed in parameter.
1725 The XML contains both biblio & item datas
1732 my ( $biblionumber ) = @_;
1733 my $dbh = C4::Context->dbh;
1735 $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? ");
1736 $sth->execute($biblionumber);
1737 my ($marcxml) = $sth->fetchrow;
1741 =head2 GetAuthorisedValueDesc
1745 my $subfieldvalue =get_authorised_value_desc(
1746 $tag, $subf[$i][0],$subf[$i][1], '', $taglib, $category);
1747 Retrieve the complete description for a given authorised value.
1749 Now takes $category and $value pair too.
1750 my $auth_value_desc =GetAuthorisedValueDesc(
1751 '','', 'DVD' ,'','','CCODE');
1757 sub GetAuthorisedValueDesc {
1758 my ( $tag, $subfield, $value, $framework, $tagslib, $category ) = @_;
1759 my $dbh = C4::Context->dbh;
1763 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
1764 return C4::Branch::GetBranchName($value);
1768 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
1769 return getitemtypeinfo($value)->{description};
1772 #---- "true" authorized value
1773 $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'}
1776 if ( $category ne "" ) {
1779 "SELECT lib FROM authorised_values WHERE category = ? AND authorised_value = ?"
1781 $sth->execute( $category, $value );
1782 my $data = $sth->fetchrow_hashref;
1783 return $data->{'lib'};
1786 return $value; # if nothing is found return the original value
1794 Returns MARC::Record of the item passed in parameter.
1801 my ( $biblionumber, $itemnumber ) = @_;
1803 # GetMarcItem has been revised so that it does the following:
1804 # 1. Gets the item information from the items table.
1805 # 2. Converts it to a MARC field for storage in the bib record.
1807 # The previous behavior was:
1808 # 1. Get the bib record.
1809 # 2. Return the MARC tag corresponding to the item record.
1811 # The difference is that one treats the items row as authoritative,
1812 # while the other treats the MARC representation as authoritative
1813 # under certain circumstances.
1817 # As of 2007-11-27, this change hopefully does not introduce
1818 # any bugs. However, it does mean that for code that uses
1819 # ModItemInMarconefield to update one subfield (corresponding to
1820 # an items column) is now less efficient.
1822 # The API needs to be shifted to the following:
1823 # 1. User updates items record.
1824 # 2. Linked bib is sent for indexing.
1826 # The missing step 1.5 is updating the item tag in the bib MARC record
1827 # so that the indexes are updated. Depending on performance considerations,
1828 # this may ultimately mean of of the following:
1829 # a. MARC field for item is updated right away.
1830 # b. MARC field for item is updated only as part of indexing.
1831 # c. MARC field for item is never actually stored in bib record; instead
1832 # it is generated only when needed for indexing, item export, and
1833 # (maybe) OPAC display.
1836 my $itemrecord = GetItem($itemnumber);
1838 # Tack on 'items.' prefix to column names so that TransformKohaToMarc will work.
1839 # Also, don't emit a subfield if the underlying field is blank.
1840 my $mungeditem = { map { $itemrecord->{$_} ne '' ? ("items.$_" => $itemrecord->{$_}) : () } keys %{ $itemrecord } };
1842 my $itemmarc = TransformKohaToMarc($mungeditem);
1853 $marcnotesarray = GetMarcNotes( $record, $marcflavour );
1854 Get all notes from the MARC record and returns them in an array.
1855 The note are stored in differents places depending on MARC flavour
1862 my ( $record, $marcflavour ) = @_;
1864 if ( $marcflavour eq "MARC21" ) {
1867 else { # assume unimarc if not marc21
1874 foreach my $field ( $record->field($scope) ) {
1875 my $value = $field->as_string();
1876 if ( $note ne "" ) {
1877 $marcnote = { marcnote => $note, };
1878 push @marcnotes, $marcnote;
1881 if ( $note ne $value ) {
1882 $note = $note . " " . $value;
1887 $marcnote = { marcnote => $note };
1888 push @marcnotes, $marcnote; #load last tag into array
1891 } # end GetMarcNotes
1893 =head2 GetMarcSubjects
1897 $marcsubjcts = GetMarcSubjects($record,$marcflavour);
1898 Get all subjects from the MARC record and returns them in an array.
1899 The subjects are stored in differents places depending on MARC flavour
1905 sub GetMarcSubjects {
1906 my ( $record, $marcflavour ) = @_;
1907 my ( $mintag, $maxtag );
1908 if ( $marcflavour eq "MARC21" ) {
1912 else { # assume unimarc if not marc21
1922 foreach my $field ( $record->field('6..' )) {
1923 next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1925 my @subfields = $field->subfields();
1928 # if there is an authority link, build the link with an= subfield9
1929 my $subfield9 = $field->subfield('9');
1930 for my $subject_subfield (@subfields ) {
1931 # don't load unimarc subfields 3,4,5
1932 next if (($marcflavour eq "UNIMARC") and ($subject_subfield->[0] =~ (3|4|5) ) );
1933 my $code = $subject_subfield->[0];
1934 my $value = $subject_subfield->[1];
1935 my $linkvalue = $value;
1936 $linkvalue =~ s/(\(|\))//g;
1937 my $operator = " and " unless $counter==0;
1939 @link_loop = ({'limit' => 'an' ,link => "$subfield9" });
1941 push @link_loop, {'limit' => 'su', link => $linkvalue, operator => $operator };
1943 my $separator = C4::Context->preference("authoritysep") unless $counter==0;
1945 my @this_link_loop = @link_loop;
1946 push @subfields_loop, {code => $code, value => $value, link_loop => \@this_link_loop, separator => $separator} unless ($subject_subfield->[0] == 9 );
1950 push @marcsubjects, { MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop };
1953 return \@marcsubjects;
1954 } #end getMARCsubjects
1956 =head2 GetMarcAuthors
1960 authors = GetMarcAuthors($record,$marcflavour);
1961 Get all authors from the MARC record and returns them in an array.
1962 The authors are stored in differents places depending on MARC flavour
1968 sub GetMarcAuthors {
1969 my ( $record, $marcflavour ) = @_;
1970 my ( $mintag, $maxtag );
1971 # tagslib useful for UNIMARC author reponsabilities
1972 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.
1973 if ( $marcflavour eq "MARC21" ) {
1977 elsif ( $marcflavour eq "UNIMARC" ) { # assume unimarc if not marc21
1986 foreach my $field ( $record->fields ) {
1987 next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1990 my @subfields = $field->subfields();
1992 # if there is an authority link, build the link with Koha-Auth-Number: subfield9
1993 my $subfield9 = $field->subfield('9');
1994 for my $authors_subfield (@subfields) {
1995 # don't load unimarc subfields 3, 5
1996 next if ($marcflavour eq 'UNIMARC' and ($authors_subfield->[0] =~ (3|5) ) );
1997 my $subfieldcode = $authors_subfield->[0];
1998 my $value = $authors_subfield->[1];
1999 my $linkvalue = $value;
2000 $linkvalue =~ s/(\(|\))//g;
2001 my $operator = " and " unless $count_auth==0;
2002 # if we have an authority link, use that as the link, otherwise use standard searching
2004 @link_loop = ({'limit' => 'Koha-Auth-Number' ,link => "$subfield9" });
2007 # reset $linkvalue if UNIMARC author responsibility
2008 if ( $marcflavour eq 'UNIMARC' and ($authors_subfield->[0] eq '4')) {
2009 $linkvalue = "(".GetAuthorisedValueDesc( $field->tag(), $authors_subfield->[0], $authors_subfield->[1], '', $tagslib ).")";
2011 push @link_loop, {'limit' => 'au', link => $linkvalue, operator => $operator };
2013 my @this_link_loop = @link_loop;
2014 my $separator = C4::Context->preference("authoritysep") unless $count_auth==0;
2015 push @subfields_loop, {code => $subfieldcode, value => $value, link_loop => \@this_link_loop, separator => $separator} unless ($authors_subfield->[0] == 9 );
2018 push @marcauthors, { MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop };
2020 return \@marcauthors;
2027 $marcurls = GetMarcUrls($record,$marcflavour);
2028 Returns arrayref of URLs from MARC data, suitable to pass to tmpl loop.
2029 Assumes web resources (not uncommon in MARC21 to omit resource type ind)
2036 my ($record, $marcflavour) = @_;
2039 for my $field ($record->field('856')) {
2040 my $url = $field->subfield('u');
2042 for my $note ( $field->subfield('z')) {
2043 push @notes , {note => $note};
2045 $marcurl = { MARCURL => $url,
2048 if($marcflavour eq 'MARC21') {
2049 my $s3 = $field->subfield('3');
2050 my $link = $field->subfield('y');
2051 $marcurl->{'linktext'} = $link || $s3 || $url ;;
2052 $marcurl->{'part'} = $s3 if($link);
2053 $marcurl->{'toc'} = 1 if($s3 =~ /^[Tt]able/) ;
2055 $marcurl->{'linktext'} = $url;
2057 push @marcurls, $marcurl;
2062 =head2 GetMarcSeries
2066 $marcseriesarray = GetMarcSeries($record,$marcflavour);
2067 Get all series from the MARC record and returns them in an array.
2068 The series are stored in differents places depending on MARC flavour
2075 my ($record, $marcflavour) = @_;
2076 my ($mintag, $maxtag);
2077 if ($marcflavour eq "MARC21") {
2080 } else { # assume unimarc if not marc21
2090 foreach my $field ($record->field('440'), $record->field('490')) {
2092 #my $value = $field->subfield('a');
2093 #$marcsubjct = {MARCSUBJCT => $value,};
2094 my @subfields = $field->subfields();
2095 #warn "subfields:".join " ", @$subfields;
2098 for my $series_subfield (@subfields) {
2100 undef $volume_number;
2101 # see if this is an instance of a volume
2102 if ($series_subfield->[0] eq 'v') {
2106 my $code = $series_subfield->[0];
2107 my $value = $series_subfield->[1];
2108 my $linkvalue = $value;
2109 $linkvalue =~ s/(\(|\))//g;
2110 my $operator = " and " unless $counter==0;
2111 push @link_loop, {link => $linkvalue, operator => $operator };
2112 my $separator = C4::Context->preference("authoritysep") unless $counter==0;
2113 if ($volume_number) {
2114 push @subfields_loop, {volumenum => $value};
2117 push @subfields_loop, {code => $code, value => $value, link_loop => \@link_loop, separator => $separator, volumenum => $volume_number};
2121 push @marcseries, { MARCSERIES_SUBFIELDS_LOOP => \@subfields_loop };
2122 #$marcsubjct = {MARCSUBJCT => $field->as_string(),};
2123 #push @marcsubjcts, $marcsubjct;
2127 my $marcseriessarray=\@marcseries;
2128 return $marcseriessarray;
2129 } #end getMARCseriess
2131 =head2 GetFrameworkCode
2135 $frameworkcode = GetFrameworkCode( $biblionumber )
2141 sub GetFrameworkCode {
2142 my ( $biblionumber ) = @_;
2143 my $dbh = C4::Context->dbh;
2144 my $sth = $dbh->prepare("SELECT frameworkcode FROM biblio WHERE biblionumber=?");
2145 $sth->execute($biblionumber);
2146 my ($frameworkcode) = $sth->fetchrow;
2147 return $frameworkcode;
2150 =head2 GetPublisherNameFromIsbn
2152 $name = GetPublishercodeFromIsbn($isbn);
2159 sub GetPublisherNameFromIsbn($){
2161 $isbn =~ s/[- _]//g;
2163 my @codes = (split '-', DisplayISBN($isbn));
2164 my $code = $codes[0].$codes[1].$codes[2];
2165 my $dbh = C4::Context->dbh;
2167 SELECT distinct publishercode
2170 AND publishercode IS NOT NULL
2173 my $sth = $dbh->prepare($query);
2174 $sth->execute("$code%");
2175 my $name = $sth->fetchrow;
2176 return $name if length $name;
2180 =head2 TransformKohaToMarc
2184 $record = TransformKohaToMarc( $hash )
2185 This function builds partial MARC::Record from a hash
2186 Hash entries can be from biblio or biblioitems.
2187 This function is called in acquisition module, to create a basic catalogue entry from user entry
2193 sub TransformKohaToMarc {
2196 my $dbh = C4::Context->dbh;
2199 "SELECT tagfield,tagsubfield FROM marc_subfield_structure WHERE frameworkcode=? AND kohafield=?"
2201 my $record = MARC::Record->new();
2202 foreach (keys %{$hash}) {
2203 &TransformKohaToMarcOneField( $sth, $record, $_,
2209 =head2 TransformKohaToMarcOneField
2213 $record = TransformKohaToMarcOneField( $sth, $record, $kohafieldname, $value, $frameworkcode );
2219 sub TransformKohaToMarcOneField {
2220 my ( $sth, $record, $kohafieldname, $value, $frameworkcode ) = @_;
2221 $frameworkcode='' unless $frameworkcode;
2225 if ( !defined $sth ) {
2226 my $dbh = C4::Context->dbh;
2227 $sth = $dbh->prepare(
2228 "SELECT tagfield,tagsubfield FROM marc_subfield_structure WHERE frameworkcode=? AND kohafield=?"
2231 $sth->execute( $frameworkcode, $kohafieldname );
2232 if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
2233 my $tag = $record->field($tagfield);
2235 $tag->update( $tagsubfield => $value );
2236 $record->delete_field($tag);
2237 $record->insert_fields_ordered($tag);
2240 $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
2246 =head2 TransformHtmlToXml
2250 $xml = TransformHtmlToXml( $tags, $subfields, $values, $indicator, $ind_tag, $auth_type )
2252 $auth_type contains :
2253 - nothing : rebuild a biblio, un UNIMARC the encoding is in 100$a pos 26/27
2254 - UNIMARCAUTH : rebuild an authority. In UNIMARC, the encoding is in 100$a pos 13/14
2255 - ITEM : rebuild an item : in UNIMARC, 100$a, it's in the biblio ! (otherwise, we would get 2 100 fields !)
2261 sub TransformHtmlToXml {
2262 my ( $tags, $subfields, $values, $indicator, $ind_tag, $auth_type ) = @_;
2263 my $xml = MARC::File::XML::header('UTF-8');
2264 $auth_type = C4::Context->preference('marcflavour') unless $auth_type;
2265 MARC::File::XML->default_record_format($auth_type);
2266 # in UNIMARC, field 100 contains the encoding
2267 # check that there is one, otherwise the
2268 # MARC::Record->new_from_xml will fail (and Koha will die)
2269 my $unimarc_and_100_exist=0;
2270 $unimarc_and_100_exist=1 if $auth_type eq 'ITEM'; # if we rebuild an item, no need of a 100 field
2275 for ( my $i = 0 ; $i <= @$tags ; $i++ ) {
2276 if (C4::Context->preference('marcflavour') eq 'UNIMARC' and @$tags[$i] eq "100" and @$subfields[$i] eq "a") {
2277 # if we have a 100 field and it's values are not correct, skip them.
2278 # if we don't have any valid 100 field, we will create a default one at the end
2279 my $enc = substr( @$values[$i], 26, 2 );
2280 if ($enc eq '01' or $enc eq '50' or $enc eq '03') {
2281 $unimarc_and_100_exist=1;
2286 @$values[$i] =~ s/&/&/g;
2287 @$values[$i] =~ s/</</g;
2288 @$values[$i] =~ s/>/>/g;
2289 @$values[$i] =~ s/"/"/g;
2290 @$values[$i] =~ s/'/'/g;
2291 # if ( !utf8::is_utf8( @$values[$i] ) ) {
2292 # utf8::decode( @$values[$i] );
2294 if ( ( @$tags[$i] ne $prevtag ) ) {
2295 $j++ unless ( @$tags[$i] eq "" );
2297 $xml .= "</datafield>\n";
2298 if ( ( @$tags[$i] && @$tags[$i] > 10 )
2299 && ( @$values[$i] ne "" ) )
2301 my $ind1 = substr( @$indicator[$j], 0, 1 );
2303 if ( @$indicator[$j] ) {
2304 $ind2 = substr( @$indicator[$j], 1, 1 );
2307 warn "Indicator in @$tags[$i] is empty";
2311 "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
2313 "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2321 if ( @$values[$i] ne "" ) {
2324 if ( @$tags[$i] eq "000" ) {
2325 $xml .= "<leader>@$values[$i]</leader>\n";
2328 # rest of the fixed fields
2330 elsif ( @$tags[$i] < 10 ) {
2332 "<controlfield tag=\"@$tags[$i]\">@$values[$i]</controlfield>\n";
2336 my $ind1 = substr( @$indicator[$j], 0, 1 );
2337 my $ind2 = substr( @$indicator[$j], 1, 1 );
2339 "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
2341 "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2347 else { # @$tags[$i] eq $prevtag
2348 if ( @$values[$i] eq "" ) {
2352 my $ind1 = substr( @$indicator[$j], 0, 1 );
2353 my $ind2 = substr( @$indicator[$j], 1, 1 );
2355 "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
2359 "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2362 $prevtag = @$tags[$i];
2364 if (C4::Context->preference('marcflavour') eq 'UNIMARC' and !$unimarc_and_100_exist) {
2365 # warn "SETTING 100 for $auth_type";
2366 use POSIX qw(strftime);
2367 my $string = strftime( "%Y%m%d", localtime(time) );
2368 # set 50 to position 26 is biblios, 13 if authorities
2370 $pos=13 if $auth_type eq 'UNIMARCAUTH';
2371 $string = sprintf( "%-*s", 35, $string );
2372 substr( $string, $pos , 6, "50" );
2373 $xml .= "<datafield tag=\"100\" ind1=\"\" ind2=\"\">\n";
2374 $xml .= "<subfield code=\"a\">$string</subfield>\n";
2375 $xml .= "</datafield>\n";
2377 $xml .= MARC::File::XML::footer();
2381 =head2 TransformHtmlToMarc
2383 L<$record> = TransformHtmlToMarc(L<$params>,L<$cgi>)
2384 L<$params> is a ref to an array as below:
2386 'tag_010_indicator_531951' ,
2387 'tag_010_code_a_531951_145735' ,
2388 'tag_010_subfield_a_531951_145735' ,
2389 'tag_200_indicator_873510' ,
2390 'tag_200_code_a_873510_673465' ,
2391 'tag_200_subfield_a_873510_673465' ,
2392 'tag_200_code_b_873510_704318' ,
2393 'tag_200_subfield_b_873510_704318' ,
2394 'tag_200_code_e_873510_280822' ,
2395 'tag_200_subfield_e_873510_280822' ,
2396 'tag_200_code_f_873510_110730' ,
2397 'tag_200_subfield_f_873510_110730' ,
2399 L<$cgi> is the CGI object which containts the value.
2400 L<$record> is the MARC::Record object.
2404 sub TransformHtmlToMarc {
2408 # creating a new record
2409 my $record = MARC::Record->new();
2412 while ($params->[$i]){ # browse all CGI params
2413 my $param = $params->[$i];
2415 # if we are on biblionumber, store it in the MARC::Record (it may not be in the edited fields)
2416 if ($param eq 'biblionumber') {
2417 my ( $biblionumbertagfield, $biblionumbertagsubfield ) =
2418 &GetMarcFromKohaField( "biblio.biblionumber", '' );
2419 if ($biblionumbertagfield < 10) {
2420 $newfield = MARC::Field->new(
2421 $biblionumbertagfield,
2422 $cgi->param($param),
2425 $newfield = MARC::Field->new(
2426 $biblionumbertagfield,
2429 "$biblionumbertagsubfield" => $cgi->param($param),
2432 push @fields,$newfield if($newfield);
2434 elsif ($param =~ /^tag_(\d*)_indicator_/){ # new field start when having 'input name="..._indicator_..."
2437 my $ind1 = substr($cgi->param($param),0,1);
2438 my $ind2 = substr($cgi->param($param),1,1);
2442 if($tag < 10){ # no code for theses fields
2443 # in MARC editor, 000 contains the leader.
2444 if ($tag eq '000' ) {
2445 $record->leader($cgi->param($params->[$j+1])) if length($cgi->param($params->[$j+1]))==24;
2446 # between 001 and 009 (included)
2448 $newfield = MARC::Field->new(
2450 $cgi->param($params->[$j+1]),
2453 # > 009, deal with subfields
2455 while($params->[$j] =~ /_code_/){ # browse all it's subfield
2456 my $inner_param = $params->[$j];
2458 if($cgi->param($params->[$j+1])){ # only if there is a value (code => value)
2459 $newfield->add_subfields(
2460 $cgi->param($inner_param) => $cgi->param($params->[$j+1])
2464 if ( $cgi->param($params->[$j+1]) ) { # creating only if there is a value (code => value)
2465 $newfield = MARC::Field->new(
2469 $cgi->param($inner_param) => $cgi->param($params->[$j+1]),
2476 push @fields,$newfield if($newfield);
2481 $record->append_fields(@fields);
2485 # cache inverted MARC field map
2486 our $inverted_field_map;
2488 =head2 TransformMarcToKoha
2492 $result = TransformMarcToKoha( $dbh, $record, $frameworkcode )
2496 Extract data from a MARC bib record into a hashref representing
2497 Koha biblio, biblioitems, and items fields.
2500 sub TransformMarcToKoha {
2501 my ( $dbh, $record, $frameworkcode, $limit_table ) = @_;
2505 unless (defined $inverted_field_map) {
2506 $inverted_field_map = _get_inverted_marc_field_map();
2510 if ($limit_table eq 'items') {
2511 $tables{'items'} = 1;
2513 $tables{'items'} = 1;
2514 $tables{'biblio'} = 1;
2515 $tables{'biblioitems'} = 1;
2518 # traverse through record
2519 MARCFIELD: foreach my $field ($record->fields()) {
2520 my $tag = $field->tag();
2521 next MARCFIELD unless exists $inverted_field_map->{$frameworkcode}->{$tag};
2522 if ($field->is_control_field()) {
2523 my $kohafields = $inverted_field_map->{$frameworkcode}->{$tag}->{list};
2524 ENTRY: foreach my $entry (@{ $kohafields }) {
2525 my ($subfield, $table, $column) = @{ $entry };
2526 next ENTRY unless exists $tables{$table};
2527 my $key = _disambiguate($table, $column);
2528 if ($result->{$key}) {
2529 unless (($key eq "biblionumber" or $key eq "biblioitemnumber") and ($field->data() eq "")) {
2530 $result->{$key} .= " | " . $field->data();
2533 $result->{$key} = $field->data();
2537 # deal with subfields
2538 MARCSUBFIELD: foreach my $sf ($field->subfields()) {
2539 my $code = $sf->[0];
2540 next MARCSUBFIELD unless exists $inverted_field_map->{$frameworkcode}->{$tag}->{sfs}->{$code};
2541 my $value = $sf->[1];
2542 SFENTRY: foreach my $entry (@{ $inverted_field_map->{$frameworkcode}->{$tag}->{sfs}->{$code} }) {
2543 my ($table, $column) = @{ $entry };
2544 next SFENTRY unless exists $tables{$table};
2545 my $key = _disambiguate($table, $column);
2546 if ($result->{$key}) {
2547 unless (($key eq "biblionumber" or $key eq "biblioitemnumber") and ($value eq "")) {
2548 $result->{$key} .= " | " . $value;
2551 $result->{$key} = $value;
2558 # modify copyrightdate to keep only the 1st year found
2559 if (exists $result->{'copyrightdate'}) {
2560 my $temp = $result->{'copyrightdate'};
2561 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
2563 $result->{'copyrightdate'} = $1;
2565 else { # if no cYYYY, get the 1st date.
2566 $temp =~ m/(\d\d\d\d)/;
2567 $result->{'copyrightdate'} = $1;
2571 # modify publicationyear to keep only the 1st year found
2572 if (exists $result->{'publicationyear'}) {
2573 my $temp = $result->{'publicationyear'};
2574 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
2576 $result->{'publicationyear'} = $1;
2578 else { # if no cYYYY, get the 1st date.
2579 $temp =~ m/(\d\d\d\d)/;
2580 $result->{'publicationyear'} = $1;
2587 sub _get_inverted_marc_field_map {
2588 my $relations = C4::Context->marcfromkohafield;
2591 my $relations = C4::Context->marcfromkohafield;
2593 foreach my $frameworkcode (keys %{ $relations }) {
2594 foreach my $kohafield (keys %{ $relations->{$frameworkcode} }) {
2595 my $tag = $relations->{$frameworkcode}->{$kohafield}->[0];
2596 my $subfield = $relations->{$frameworkcode}->{$kohafield}->[1];
2597 my ($table, $column) = split /[.]/, $kohafield, 2;
2598 push @{ $field_map->{$frameworkcode}->{$tag}->{list} }, [ $subfield, $table, $column ];
2599 push @{ $field_map->{$frameworkcode}->{$tag}->{sfs}->{$subfield} }, [ $table, $column ];
2605 =head2 _disambiguate
2609 $newkey = _disambiguate($table, $field);
2611 This is a temporary hack to distinguish between the
2612 following sets of columns when using TransformMarcToKoha.
2614 items.cn_source & biblioitems.cn_source
2615 items.cn_sort & biblioitems.cn_sort
2617 Columns that are currently NOT distinguished (FIXME
2618 due to lack of time to fully test) are:
2620 biblio.notes and biblioitems.notes
2625 FIXME - this is necessary because prefixing each column
2626 name with the table name would require changing lots
2627 of code and templates, and exposing more of the DB
2628 structure than is good to the UI templates, particularly
2629 since biblio and bibloitems may well merge in a future
2630 version. In the future, it would also be good to
2631 separate DB access and UI presentation field names
2639 my ($table, $column) = @_;
2640 if ($column eq "cn_sort" or $column eq "cn_source") {
2641 return $table . '.' . $column;
2648 =head2 get_koha_field_from_marc
2652 $result->{_disambiguate($table, $field)} = get_koha_field_from_marc($table,$field,$record,$frameworkcode);
2654 Internal function to map data from the MARC record to a specific non-MARC field.
2655 FIXME: this is meant to replace TransformMarcToKohaOneField after more testing.
2661 sub get_koha_field_from_marc {
2662 my ($koha_table,$koha_column,$record,$frameworkcode) = @_;
2663 my ( $tagfield, $subfield ) = GetMarcFromKohaField( $koha_table.'.'.$koha_column, $frameworkcode );
2665 foreach my $field ( $record->field($tagfield) ) {
2666 if ( $field->tag() < 10 ) {
2668 $kohafield .= " | " . $field->data();
2671 $kohafield = $field->data();
2675 if ( $field->subfields ) {
2676 my @subfields = $field->subfields();
2677 foreach my $subfieldcount ( 0 .. $#subfields ) {
2678 if ( $subfields[$subfieldcount][0] eq $subfield ) {
2681 " | " . $subfields[$subfieldcount][1];
2685 $subfields[$subfieldcount][1];
2696 =head2 TransformMarcToKohaOneField
2700 $result = TransformMarcToKohaOneField( $kohatable, $kohafield, $record, $result, $frameworkcode )
2706 sub TransformMarcToKohaOneField {
2708 # FIXME ? if a field has a repeatable subfield that is used in old-db,
2709 # only the 1st will be retrieved...
2710 my ( $kohatable, $kohafield, $record, $result, $frameworkcode ) = @_;
2712 my ( $tagfield, $subfield ) =
2713 GetMarcFromKohaField( $kohatable . "." . $kohafield,
2715 foreach my $field ( $record->field($tagfield) ) {
2716 if ( $field->tag() < 10 ) {
2717 if ( $result->{$kohafield} ) {
2718 $result->{$kohafield} .= " | " . $field->data();
2721 $result->{$kohafield} = $field->data();
2725 if ( $field->subfields ) {
2726 my @subfields = $field->subfields();
2727 foreach my $subfieldcount ( 0 .. $#subfields ) {
2728 if ( $subfields[$subfieldcount][0] eq $subfield ) {
2729 if ( $result->{$kohafield} ) {
2730 $result->{$kohafield} .=
2731 " | " . $subfields[$subfieldcount][1];
2734 $result->{$kohafield} =
2735 $subfields[$subfieldcount][1];
2745 =head1 OTHER FUNCTIONS
2751 my $string = char_decode( $string, $encoding );
2753 converts ISO 5426 coded string to UTF-8
2754 sloppy code : should be improved in next issue
2761 my ( $string, $encoding ) = @_;
2764 $encoding = C4::Context->preference("marcflavour") unless $encoding;
2765 if ( $encoding eq "UNIMARC" ) {
2835 # this handles non-sorting blocks (if implementation requires this)
2836 $string = nsb_clean($_);
2838 elsif ( $encoding eq "USMARC" || $encoding eq "MARC21" ) {
2897 #Additional Turkish characters
2900 s/(\xf0)s/\xc5\x9f/gm;
2901 s/(\xf0)S/\xc5\x9e/gm;
2904 s/\xe7\x49/\\xc4\xb0/gm;
2905 s/(\xe6)G/\xc4\x9e/gm;
2906 s/(\xe6)g/ğ\xc4\x9f/gm;
2909 s/(\xe8|\xc8)o/ö/gm;
2910 s/(\xe8|\xc8)O/Ö/gm;
2911 s/(\xe8|\xc8)u/ü/gm;
2912 s/(\xe8|\xc8)U/Ü/gm;
2913 s/\xc2\xb8/\xc4\xb1/gm;
2916 # this handles non-sorting blocks (if implementation requires this)
2917 $string = nsb_clean($_);
2926 my $string = nsb_clean( $string, $encoding );
2933 my $NSB = '\x88'; # NSB : begin Non Sorting Block
2934 my $NSE = '\x89'; # NSE : Non Sorting Block end
2935 # handles non sorting blocks
2939 s/[ ]{0,1}$NSE/) /gm;
2944 =head2 PrepareItemrecordDisplay
2948 PrepareItemrecordDisplay($itemrecord,$bibnum,$itemumber);
2950 Returns a hash with all the fields for Display a given item data in a template
2956 sub PrepareItemrecordDisplay {
2958 my ( $bibnum, $itemnum ) = @_;
2960 my $dbh = C4::Context->dbh;
2961 my $frameworkcode = &GetFrameworkCode( $bibnum );
2962 my ( $itemtagfield, $itemtagsubfield ) =
2963 &GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2964 my $tagslib = &GetMarcStructure( 1, $frameworkcode );
2965 my $itemrecord = GetMarcItem( $bibnum, $itemnum) if ($itemnum);
2967 my $authorised_values_sth =
2969 "SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib"
2971 foreach my $tag ( sort keys %{$tagslib} ) {
2972 my $previous_tag = '';
2974 # loop through each subfield
2976 foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
2977 next if ( subfield_is_koha_internal_p($subfield) );
2978 next if ( $tagslib->{$tag}->{$subfield}->{'tab'} ne "10" );
2980 $subfield_data{tag} = $tag;
2981 $subfield_data{subfield} = $subfield;
2982 $subfield_data{countsubfield} = $cntsubf++;
2983 $subfield_data{kohafield} =
2984 $tagslib->{$tag}->{$subfield}->{'kohafield'};
2986 # $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
2987 $subfield_data{marc_lib} =
2988 "<span id=\"error\" title=\""
2989 . $tagslib->{$tag}->{$subfield}->{lib} . "\">"
2990 . substr( $tagslib->{$tag}->{$subfield}->{lib}, 0, 12 )
2992 $subfield_data{mandatory} =
2993 $tagslib->{$tag}->{$subfield}->{mandatory};
2994 $subfield_data{repeatable} =
2995 $tagslib->{$tag}->{$subfield}->{repeatable};
2996 $subfield_data{hidden} = "display:none"
2997 if $tagslib->{$tag}->{$subfield}->{hidden};
2999 ( $x, $value ) = _find_value( $tag, $subfield, $itemrecord )
3001 $value =~ s/"/"/g;
3003 # search for itemcallnumber if applicable
3004 if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
3005 'items.itemcallnumber'
3006 && C4::Context->preference('itemcallnumber') )
3009 substr( C4::Context->preference('itemcallnumber'), 0, 3 );
3011 substr( C4::Context->preference('itemcallnumber'), 3, 1 );
3012 my $temp = $itemrecord->field($CNtag) if ($itemrecord);
3014 $value = $temp->subfield($CNsubfield);
3017 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
3018 my @authorised_values;
3021 # builds list, depending on authorised value...
3023 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq
3026 if ( ( C4::Context->preference("IndependantBranches") )
3027 && ( C4::Context->userenv->{flags} != 1 ) )
3031 "SELECT branchcode,branchname FROM branches WHERE branchcode = ? ORDER BY branchname"
3033 $sth->execute( C4::Context->userenv->{branch} );
3034 push @authorised_values, ""
3036 $tagslib->{$tag}->{$subfield}->{mandatory} );
3037 while ( my ( $branchcode, $branchname ) =
3038 $sth->fetchrow_array )
3040 push @authorised_values, $branchcode;
3041 $authorised_lib{$branchcode} = $branchname;
3047 "SELECT branchcode,branchname FROM branches ORDER BY branchname"
3050 push @authorised_values, ""
3052 $tagslib->{$tag}->{$subfield}->{mandatory} );
3053 while ( my ( $branchcode, $branchname ) =
3054 $sth->fetchrow_array )
3056 push @authorised_values, $branchcode;
3057 $authorised_lib{$branchcode} = $branchname;
3063 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq
3068 "SELECT itemtype,description FROM itemtypes ORDER BY description"
3071 push @authorised_values, ""
3072 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
3073 while ( my ( $itemtype, $description ) =
3074 $sth->fetchrow_array )
3076 push @authorised_values, $itemtype;
3077 $authorised_lib{$itemtype} = $description;
3080 #---- "true" authorised value
3083 $authorised_values_sth->execute(
3084 $tagslib->{$tag}->{$subfield}->{authorised_value} );
3085 push @authorised_values, ""
3086 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
3087 while ( my ( $value, $lib ) =
3088 $authorised_values_sth->fetchrow_array )
3090 push @authorised_values, $value;
3091 $authorised_lib{$value} = $lib;
3094 $subfield_data{marc_value} = CGI::scrolling_list(
3095 -name => 'field_value',
3096 -values => \@authorised_values,
3097 -default => "$value",
3098 -labels => \%authorised_lib,
3104 elsif ( $tagslib->{$tag}->{$subfield}->{thesaurus_category} ) {
3105 $subfield_data{marc_value} =
3106 "<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>";
3109 # COMMENTED OUT because No $i is provided with this API.
3110 # And thus, no value_builder can be activated.
3111 # BUT could be thought over.
3112 # } elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
3113 # my $plugin="value_builder/".$tagslib->{$tag}->{$subfield}->{'value_builder'};
3115 # my $extended_param = plugin_parameters($dbh,$itemrecord,$tagslib,$i,0);
3116 # my ($function_name,$javascript) = plugin_javascript($dbh,$record,$tagslib,$i,0);
3117 # $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";
3120 $subfield_data{marc_value} =
3121 "<input type=\"text\" name=\"field_value\" value=\"$value\" size=50 maxlength=255>";
3123 push( @loop_data, \%subfield_data );
3127 my $itemnumber = $itemrecord->subfield( $itemtagfield, $itemtagsubfield )
3128 if ( $itemrecord && $itemrecord->field($itemtagfield) );
3130 'itemtagfield' => $itemtagfield,
3131 'itemtagsubfield' => $itemtagsubfield,
3132 'itemnumber' => $itemnumber,
3133 'iteminformation' => \@loop_data
3139 # true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates
3141 # replaced by a zebraqueue table, that is filled with ModZebra to run.
3142 # the table is emptied by misc/cronjobs/zebraqueue_start.pl script
3143 # =head2 ModZebrafiles
3145 # &ModZebrafiles( $dbh, $biblionumber, $record, $folder, $server );
3149 # sub ModZebrafiles {
3151 # my ( $dbh, $biblionumber, $record, $folder, $server ) = @_;
3155 # C4::Context->zebraconfig($server)->{directory} . "/" . $folder . "/";
3156 # unless ( opendir( DIR, "$zebradir" ) ) {
3157 # warn "$zebradir not found";
3161 # my $filename = $zebradir . $biblionumber;
3164 # open( OUTPUT, ">", $filename . ".xml" );
3165 # print OUTPUT $record;
3174 ModZebra( $biblionumber, $op, $server, $newRecord );
3176 $biblionumber is the biblionumber we want to index
3177 $op is specialUpdate or delete, and is used to know what we want to do
3178 $server is the server that we want to update
3179 $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.
3186 ###Accepts a $server variable thus we can use it for biblios authorities or other zebra dbs
3187 my ( $biblionumber, $op, $server, $newRecord ) = @_;
3188 my $dbh=C4::Context->dbh;
3190 # true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates
3192 # replaced by a zebraqueue table, that is filled with ModZebra to run.
3193 # the table is emptied by misc/cronjobs/zebraqueue_start.pl script
3195 if (C4::Context->preference("NoZebra")) {
3196 # lock the nozebra table : we will read index lines, update them in Perl process
3197 # and write everything in 1 transaction.
3198 # lock the table to avoid someone else overwriting what we are doing
3199 $dbh->do('LOCK TABLES nozebra WRITE,biblio WRITE,biblioitems WRITE, systempreferences WRITE, auth_types WRITE, auth_header WRITE');
3200 my %result; # the result hash that will be builded by deletion / add, and written on mySQL at the end, to improve speed
3202 if ($server eq 'biblioserver') {
3203 $record= GetMarcBiblio($biblionumber);
3205 $record= C4::AuthoritiesMarc::GetAuthority($biblionumber);
3207 if ($op eq 'specialUpdate') {
3208 # OK, we have to add or update the record
3209 # 1st delete (virtually, in indexes), if record actually exists
3211 %result = _DelBiblioNoZebra($biblionumber,$record,$server);
3213 # ... add the record
3214 %result=_AddBiblioNoZebra($biblionumber,$newRecord, $server, %result);
3216 # it's a deletion, delete the record...
3217 # warn "DELETE the record $biblionumber on $server".$record->as_formatted;
3218 %result=_DelBiblioNoZebra($biblionumber,$record,$server);
3220 # ok, now update the database...
3221 my $sth = $dbh->prepare("UPDATE nozebra SET biblionumbers=? WHERE server=? AND indexname=? AND value=?");
3222 foreach my $key (keys %result) {
3223 foreach my $index (keys %{$result{$key}}) {
3224 $sth->execute($result{$key}->{$index}, $server, $key, $index);
3227 $dbh->do('UNLOCK TABLES');
3231 # we use zebra, just fill zebraqueue table
3233 my $sth=$dbh->prepare("INSERT INTO zebraqueue (biblio_auth_number,server,operation) VALUES(?,?,?)");
3234 $sth->execute($biblionumber,$server,$op);
3239 =head2 GetNoZebraIndexes
3241 %indexes = GetNoZebraIndexes;
3243 return the data from NoZebraIndexes syspref.
3247 sub GetNoZebraIndexes {
3248 my $index = C4::Context->preference('NoZebraIndexes');
3250 foreach my $line (split /('|"),/,$index) {
3251 $line =~ /(.*)=>(.*)/;
3252 my $index = substr($1,1); # get the index, don't forget to remove initial ' or "
3254 $index =~ s/'|"|\s//g;
3257 $fields =~ s/'|"|\s//g;
3258 $indexes{$index}=$fields;
3263 =head1 INTERNAL FUNCTIONS
3265 =head2 _DelBiblioNoZebra($biblionumber,$record,$server);
3267 function to delete a biblio in NoZebra indexes
3268 This function does NOT delete anything in database : it reads all the indexes entries
3269 that have to be deleted & delete them in the hash
3270 The SQL part is done either :
3271 - after the Add if we are modifying a biblio (delete + add again)
3272 - immediatly after this sub if we are doing a true deletion.
3273 $server can be 'biblioserver' or 'authorityserver' : it indexes biblios or authorities (in the same table, $server being part of the table itself
3278 sub _DelBiblioNoZebra {
3279 my ($biblionumber, $record, $server)=@_;
3282 my $dbh = C4::Context->dbh;
3286 if ($server eq 'biblioserver') {
3287 %index=GetNoZebraIndexes;
3288 # get title of the record (to store the 10 first letters with the index)
3289 my ($titletag,$titlesubfield) = GetMarcFromKohaField('biblio.title');
3290 $title = lc($record->subfield($titletag,$titlesubfield));
3292 # for authorities, the "title" is the $a mainentry
3293 my $authref = C4::AuthoritiesMarc::GetAuthType($record->subfield(152,'b'));
3294 warn "ERROR : authtype undefined for ".$record->as_formatted unless $authref;
3295 $title = $record->subfield($authref->{auth_tag_to_report},'a');
3296 $index{'mainmainentry'}= $authref->{'auth_tag_to_report'}.'a';
3297 $index{'mainentry'} = $authref->{'auth_tag_to_report'}.'*';
3298 $index{'auth_type'} = '152b';
3302 # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
3303 $title =~ s/ |,|;|\[|\]|\(|\)|\*|-|'|=//g;
3304 # limit to 10 char, should be enough, and limit the DB size
3305 $title = substr($title,0,10);
3307 my $sth2=$dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
3308 foreach my $field ($record->fields()) {
3309 #parse each subfield
3310 next if $field->tag <10;
3311 foreach my $subfield ($field->subfields()) {
3312 my $tag = $field->tag();
3313 my $subfieldcode = $subfield->[0];
3315 # check each index to see if the subfield is stored somewhere
3316 # otherwise, store it in __RAW__ index
3317 foreach my $key (keys %index) {
3318 # warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
3319 if ($index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/) {
3321 my $line= lc $subfield->[1];
3322 # remove meaningless value in the field...
3323 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
3324 # ... and split in words
3325 foreach (split / /,$line) {
3326 next unless $_; # skip empty values (multiple spaces)
3327 # if the entry is already here, do nothing, the biblionumber has already be removed
3328 unless ($result{$key}->{$_} =~ /$biblionumber,$title\-(\d);/) {
3329 # get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
3330 $sth2->execute($server,$key,$_);
3331 my $existing_biblionumbers = $sth2->fetchrow;
3333 if ($existing_biblionumbers) {
3334 # warn " existing for $key $_: $existing_biblionumbers";
3335 $result{$key}->{$_} =$existing_biblionumbers;
3336 $result{$key}->{$_} =~ s/$biblionumber,$title\-(\d);//;
3342 # the subfield is not indexed, store it in __RAW__ index anyway
3344 my $line= lc $subfield->[1];
3345 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
3346 # ... and split in words
3347 foreach (split / /,$line) {
3348 next unless $_; # skip empty values (multiple spaces)
3349 # if the entry is already here, do nothing, the biblionumber has already be removed
3350 unless ($result{'__RAW__'}->{$_} =~ /$biblionumber,$title\-(\d);/) {
3351 # get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
3352 $sth2->execute($server,'__RAW__',$_);
3353 my $existing_biblionumbers = $sth2->fetchrow;
3355 if ($existing_biblionumbers) {
3356 $result{'__RAW__'}->{$_} =$existing_biblionumbers;
3357 $result{'__RAW__'}->{$_} =~ s/$biblionumber,$title\-(\d);//;
3367 =head2 _AddBiblioNoZebra($biblionumber, $record, $server, %result);
3369 function to add a biblio in NoZebra indexes
3373 sub _AddBiblioNoZebra {
3374 my ($biblionumber, $record, $server, %result)=@_;
3375 my $dbh = C4::Context->dbh;
3379 if ($server eq 'biblioserver') {
3380 %index=GetNoZebraIndexes;
3381 # get title of the record (to store the 10 first letters with the index)
3382 my ($titletag,$titlesubfield) = GetMarcFromKohaField('biblio.title');
3383 $title = lc($record->subfield($titletag,$titlesubfield));
3385 # warn "server : $server";
3386 # for authorities, the "title" is the $a mainentry
3387 my $authref = C4::AuthoritiesMarc::GetAuthType($record->subfield(152,'b'));
3388 warn "ERROR : authtype undefined for ".$record->as_formatted unless $authref;
3389 $title = $record->subfield($authref->{auth_tag_to_report},'a');
3390 $index{'mainmainentry'} = $authref->{auth_tag_to_report}.'a';
3391 $index{'mainentry'} = $authref->{auth_tag_to_report}.'*';
3392 $index{'auth_type'} = '152b';
3395 # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
3396 $title =~ s/ |,|;|\[|\]|\(|\)|\*|-|'|=//g;
3397 # limit to 10 char, should be enough, and limit the DB size
3398 $title = substr($title,0,10);
3400 my $sth2=$dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
3401 foreach my $field ($record->fields()) {
3402 #parse each subfield
3403 next if $field->tag <10;
3404 foreach my $subfield ($field->subfields()) {
3405 my $tag = $field->tag();
3406 my $subfieldcode = $subfield->[0];
3408 # check each index to see if the subfield is stored somewhere
3409 # otherwise, store it in __RAW__ index
3410 foreach my $key (keys %index) {
3411 # warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
3412 if ($index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/) {
3414 my $line= lc $subfield->[1];
3415 # remove meaningless value in the field...
3416 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
3417 # ... and split in words
3418 foreach (split / /,$line) {
3419 next unless $_; # skip empty values (multiple spaces)
3420 # if the entry is already here, improve weight
3421 # warn "managing $_";
3422 if ($result{$key}->{"$_"} =~ /$biblionumber,$title\-(\d);/) {
3424 $result{$key}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
3425 $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
3427 # get the value if it exist in the nozebra table, otherwise, create it
3428 $sth2->execute($server,$key,$_);
3429 my $existing_biblionumbers = $sth2->fetchrow;
3431 if ($existing_biblionumbers) {
3432 $result{$key}->{"$_"} =$existing_biblionumbers;
3434 $result{$key}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
3435 $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
3436 # create a new ligne for this entry
3438 # warn "INSERT : $server / $key / $_";
3439 $dbh->do('INSERT INTO nozebra SET server='.$dbh->quote($server).', indexname='.$dbh->quote($key).',value='.$dbh->quote($_));
3440 $result{$key}->{"$_"}.="$biblionumber,$title-1;";
3446 # the subfield is not indexed, store it in __RAW__ index anyway
3448 my $line= lc $subfield->[1];
3449 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
3450 # ... and split in words
3451 foreach (split / /,$line) {
3452 next unless $_; # skip empty values (multiple spaces)
3453 # if the entry is already here, improve weight
3454 if ($result{'__RAW__'}->{"$_"} =~ /$biblionumber,$title\-(\d);/) {
3456 $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
3457 $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
3459 # get the value if it exist in the nozebra table, otherwise, create it
3460 $sth2->execute($server,'__RAW__',$_);
3461 my $existing_biblionumbers = $sth2->fetchrow;
3463 if ($existing_biblionumbers) {
3464 $result{'__RAW__'}->{"$_"} =$existing_biblionumbers;
3466 $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
3467 $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
3468 # create a new ligne for this entry
3470 $dbh->do('INSERT INTO nozebra SET server='.$dbh->quote($server).', indexname="__RAW__",value='.$dbh->quote($_));
3471 $result{'__RAW__'}->{"$_"}.="$biblionumber,$title-1;";
3482 =head2 MARCitemchange
3486 &MARCitemchange( $record, $itemfield, $newvalue )
3488 Function to update a single value in an item field.
3489 Used twice, could probably be replaced by something else, but works well...
3497 sub MARCitemchange {
3498 my ( $record, $itemfield, $newvalue ) = @_;
3499 my $dbh = C4::Context->dbh;
3501 my ( $tagfield, $tagsubfield ) =
3502 GetMarcFromKohaField( $itemfield, "" );
3503 if ( ($tagfield) && ($tagsubfield) ) {
3504 my $tag = $record->field($tagfield);
3506 $tag->update( $tagsubfield => $newvalue );
3507 $record->delete_field($tag);
3508 $record->insert_fields_ordered($tag);
3516 ($indicators, $value) = _find_value($tag, $subfield, $record,$encoding);
3518 Find the given $subfield in the given $tag in the given
3519 MARC::Record $record. If the subfield is found, returns
3520 the (indicators, value) pair; otherwise, (undef, undef) is
3524 Such a function is used in addbiblio AND additem and serial-edit and maybe could be used in Authorities.
3525 I suggest we export it from this module.
3532 my ( $tagfield, $insubfield, $record, $encoding ) = @_;
3535 if ( $tagfield < 10 ) {
3536 if ( $record->field($tagfield) ) {
3537 push @result, $record->field($tagfield)->data();
3544 foreach my $field ( $record->field($tagfield) ) {
3545 my @subfields = $field->subfields();
3546 foreach my $subfield (@subfields) {
3547 if ( @$subfield[0] eq $insubfield ) {
3548 push @result, @$subfield[1];
3549 $indicator = $field->indicator(1) . $field->indicator(2);
3554 return ( $indicator, @result );
3557 =head2 _koha_marc_update_bib_ids
3561 _koha_marc_update_bib_ids($record, $frameworkcode, $biblionumber, $biblioitemnumber);
3563 Internal function to add or update biblionumber and biblioitemnumber to
3570 sub _koha_marc_update_bib_ids {
3571 my ($record, $frameworkcode, $biblionumber, $biblioitemnumber) = @_;
3573 # we must add bibnum and bibitemnum in MARC::Record...
3574 # we build the new field with biblionumber and biblioitemnumber
3575 # we drop the original field
3576 # we add the new builded field.
3577 my ($biblio_tag, $biblio_subfield ) = GetMarcFromKohaField("biblio.biblionumber",$frameworkcode);
3578 my ($biblioitem_tag, $biblioitem_subfield ) = GetMarcFromKohaField("biblioitems.biblioitemnumber",$frameworkcode);
3580 if ($biblio_tag != $biblioitem_tag) {
3581 # biblionumber & biblioitemnumber are in different fields
3583 # deal with biblionumber
3584 my ($new_field, $old_field);
3585 if ($biblio_tag < 10) {
3586 $new_field = MARC::Field->new( $biblio_tag, $biblionumber );
3589 MARC::Field->new( $biblio_tag, '', '',
3590 "$biblio_subfield" => $biblionumber );
3593 # drop old field and create new one...
3594 $old_field = $record->field($biblio_tag);
3595 $record->delete_field($old_field);
3596 $record->append_fields($new_field);
3598 # deal with biblioitemnumber
3599 if ($biblioitem_tag < 10) {
3600 $new_field = MARC::Field->new( $biblioitem_tag, $biblioitemnumber, );
3603 MARC::Field->new( $biblioitem_tag, '', '',
3604 "$biblioitem_subfield" => $biblioitemnumber, );
3606 # drop old field and create new one...
3607 $old_field = $record->field($biblioitem_tag);
3608 $record->delete_field($old_field);
3609 $record->insert_fields_ordered($new_field);
3612 # biblionumber & biblioitemnumber are in the same field (can't be <10 as fields <10 have only 1 value)
3613 my $new_field = MARC::Field->new(
3614 $biblio_tag, '', '',
3615 "$biblio_subfield" => $biblionumber,
3616 "$biblioitem_subfield" => $biblioitemnumber
3619 # drop old field and create new one...
3620 my $old_field = $record->field($biblio_tag);
3621 $record->delete_field($old_field);
3622 $record->insert_fields_ordered($new_field);
3626 =head2 _koha_add_biblio
3630 my ($biblionumber,$error) = _koha_add_biblio($dbh,$biblioitem);
3632 Internal function to add a biblio ($biblio is a hash with the values)
3638 sub _koha_add_biblio {
3639 my ( $dbh, $biblio, $frameworkcode ) = @_;
3643 # set the series flag
3645 if ( $biblio->{'seriestitle'} ) { $serial = 1 };
3649 SET frameworkcode = ?,
3660 my $sth = $dbh->prepare($query);
3663 $biblio->{'author'},
3665 $biblio->{'unititle'},
3668 $biblio->{'seriestitle'},
3669 $biblio->{'copyrightdate'},
3670 $biblio->{'abstract'}
3673 my $biblionumber = $dbh->{'mysql_insertid'};
3674 if ( $dbh->errstr ) {
3675 $error.="ERROR in _koha_add_biblio $query".$dbh->errstr;
3680 #warn "LEAVING _koha_add_biblio: ".$biblionumber."\n";
3681 return ($biblionumber,$error);
3684 =head2 _koha_modify_biblio
3688 my ($biblionumber,$error) == _koha_modify_biblio($dbh,$biblio,$frameworkcode);
3690 Internal function for updating the biblio table
3696 sub _koha_modify_biblio {
3697 my ( $dbh, $biblio, $frameworkcode ) = @_;
3702 SET frameworkcode = ?,
3711 WHERE biblionumber = ?
3714 my $sth = $dbh->prepare($query);
3718 $biblio->{'author'},
3720 $biblio->{'unititle'},
3722 $biblio->{'serial'},
3723 $biblio->{'seriestitle'},
3724 $biblio->{'copyrightdate'},
3725 $biblio->{'abstract'},
3726 $biblio->{'biblionumber'}
3727 ) if $biblio->{'biblionumber'};
3729 if ( $dbh->errstr || !$biblio->{'biblionumber'} ) {
3730 $error.="ERROR in _koha_modify_biblio $query".$dbh->errstr;
3733 return ( $biblio->{'biblionumber'},$error );
3736 =head2 _koha_modify_biblioitem_nonmarc
3740 my ($biblioitemnumber,$error) = _koha_modify_biblioitem_nonmarc( $dbh, $biblioitem );
3742 Updates biblioitems row except for marc and marcxml, which should be changed
3749 sub _koha_modify_biblioitem_nonmarc {
3750 my ( $dbh, $biblioitem ) = @_;
3753 # re-calculate the cn_sort, it may have changed
3754 my ($cn_sort) = GetClassSort($biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'}, $biblioitem->{'cn_item'} );
3758 SET biblionumber = ?,
3764 publicationyear = ?,
3768 collectiontitle = ?,
3770 collectionvolume= ?,
3771 editionstatement= ?,
3772 editionresponsibility = ?,
3786 where biblioitemnumber = ?
3788 my $sth = $dbh->prepare($query);
3790 $biblioitem->{'biblionumber'},
3791 $biblioitem->{'volume'},
3792 $biblioitem->{'number'},
3793 $biblioitem->{'itemtype'},
3794 $biblioitem->{'isbn'},
3795 $biblioitem->{'issn'},
3796 $biblioitem->{'publicationyear'},
3797 $biblioitem->{'publishercode'},
3798 $biblioitem->{'volumedate'},
3799 $biblioitem->{'volumedesc'},
3800 $biblioitem->{'collectiontitle'},
3801 $biblioitem->{'collectionissn'},
3802 $biblioitem->{'collectionvolume'},
3803 $biblioitem->{'editionstatement'},
3804 $biblioitem->{'editionresponsibility'},
3805 $biblioitem->{'illus'},
3806 $biblioitem->{'pages'},
3807 $biblioitem->{'bnotes'},
3808 $biblioitem->{'size'},
3809 $biblioitem->{'place'},
3810 $biblioitem->{'lccn'},
3811 $biblioitem->{'url'},
3812 $biblioitem->{'biblioitems.cn_source'},
3813 $biblioitem->{'cn_class'},
3814 $biblioitem->{'cn_item'},
3815 $biblioitem->{'cn_suffix'},
3817 $biblioitem->{'totalissues'},
3818 $biblioitem->{'biblioitemnumber'}
3820 if ( $dbh->errstr ) {
3821 $error.="ERROR in _koha_modify_biblioitem_nonmarc $query".$dbh->errstr;
3824 return ($biblioitem->{'biblioitemnumber'},$error);
3827 =head2 _koha_add_biblioitem
3831 my ($biblioitemnumber,$error) = _koha_add_biblioitem( $dbh, $biblioitem );
3833 Internal function to add a biblioitem
3839 sub _koha_add_biblioitem {
3840 my ( $dbh, $biblioitem ) = @_;
3843 my ($cn_sort) = GetClassSort($biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'}, $biblioitem->{'cn_item'} );
3845 "INSERT INTO biblioitems SET
3852 publicationyear = ?,
3856 collectiontitle = ?,
3858 collectionvolume= ?,
3859 editionstatement= ?,
3860 editionresponsibility = ?,
3876 my $sth = $dbh->prepare($query);
3878 $biblioitem->{'biblionumber'},
3879 $biblioitem->{'volume'},
3880 $biblioitem->{'number'},
3881 $biblioitem->{'itemtype'},
3882 $biblioitem->{'isbn'},
3883 $biblioitem->{'issn'},
3884 $biblioitem->{'publicationyear'},
3885 $biblioitem->{'publishercode'},
3886 $biblioitem->{'volumedate'},
3887 $biblioitem->{'volumedesc'},
3888 $biblioitem->{'collectiontitle'},
3889 $biblioitem->{'collectionissn'},
3890 $biblioitem->{'collectionvolume'},
3891 $biblioitem->{'editionstatement'},
3892 $biblioitem->{'editionresponsibility'},
3893 $biblioitem->{'illus'},
3894 $biblioitem->{'pages'},
3895 $biblioitem->{'bnotes'},
3896 $biblioitem->{'size'},
3897 $biblioitem->{'place'},
3898 $biblioitem->{'lccn'},
3899 $biblioitem->{'marc'},
3900 $biblioitem->{'url'},
3901 $biblioitem->{'biblioitems.cn_source'},
3902 $biblioitem->{'cn_class'},
3903 $biblioitem->{'cn_item'},
3904 $biblioitem->{'cn_suffix'},
3906 $biblioitem->{'totalissues'}
3908 my $bibitemnum = $dbh->{'mysql_insertid'};
3909 if ( $dbh->errstr ) {
3910 $error.="ERROR in _koha_add_biblioitem $query".$dbh->errstr;
3914 return ($bibitemnum,$error);
3917 =head2 _koha_new_items
3921 my ($itemnumber,$error) = _koha_new_items( $dbh, $item, $barcode );
3927 sub _koha_new_items {
3928 my ( $dbh, $item, $barcode ) = @_;
3930 my ($items_cn_sort) = GetClassSort($item->{'items.cn_source'}, $item->{'itemcallnumber'}, "");
3932 # if dateaccessioned is provided, use it. Otherwise, set to NOW()
3933 if ( $item->{'dateaccessioned'} eq '' || !$item->{'dateaccessioned'} ) {
3934 my $today = C4::Dates->new();
3935 $item->{'dateaccessioned'} = $today->output("iso"); #TODO: check time issues
3938 "INSERT INTO items SET
3940 biblioitemnumber = ?,
3942 dateaccessioned = ?,
3946 replacementprice = ?,
3947 replacementpricedate = NOW(),
3948 datelastborrowed = ?,
3949 datelastseen = NOW(),
3972 my $sth = $dbh->prepare($query);
3974 $item->{'biblionumber'},
3975 $item->{'biblioitemnumber'},
3977 $item->{'dateaccessioned'},
3978 $item->{'booksellerid'},
3979 $item->{'homebranch'},
3981 $item->{'replacementprice'},
3982 $item->{datelastborrowed},
3984 $item->{'notforloan'},
3986 $item->{'itemlost'},
3987 $item->{'wthdrawn'},
3988 $item->{'itemcallnumber'},
3989 $item->{'restricted'},
3990 $item->{'itemnotes'},
3991 $item->{'holdingbranch'},
3993 $item->{'location'},
3996 $item->{'renewals'},
3997 $item->{'reserves'},
3998 $item->{'items.cn_source'},
4002 $item->{'materials'},
4005 my $itemnumber = $dbh->{'mysql_insertid'};
4006 if ( defined $sth->errstr ) {
4007 $error.="ERROR in _koha_new_items $query".$sth->errstr;
4010 return ( $itemnumber, $error );
4013 =head2 _koha_delete_biblio
4017 $error = _koha_delete_biblio($dbh,$biblionumber);
4019 Internal sub for deleting from biblio table -- also saves to deletedbiblio
4021 C<$dbh> - the database handle
4022 C<$biblionumber> - the biblionumber of the biblio to be deleted
4028 # FIXME: add error handling
4030 sub _koha_delete_biblio {
4031 my ( $dbh, $biblionumber ) = @_;
4033 # get all the data for this biblio
4034 my $sth = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber=?");
4035 $sth->execute($biblionumber);
4037 if ( my $data = $sth->fetchrow_hashref ) {
4039 # save the record in deletedbiblio
4040 # find the fields to save
4041 my $query = "INSERT INTO deletedbiblio SET ";
4043 foreach my $temp ( keys %$data ) {
4044 $query .= "$temp = ?,";
4045 push( @bind, $data->{$temp} );
4048 # replace the last , by ",?)"
4050 my $bkup_sth = $dbh->prepare($query);
4051 $bkup_sth->execute(@bind);
4055 my $del_sth = $dbh->prepare("DELETE FROM biblio WHERE biblionumber=?");
4056 $del_sth->execute($biblionumber);
4063 =head2 _koha_delete_biblioitems
4067 $error = _koha_delete_biblioitems($dbh,$biblioitemnumber);
4069 Internal sub for deleting from biblioitems table -- also saves to deletedbiblioitems
4071 C<$dbh> - the database handle
4072 C<$biblionumber> - the biblioitemnumber of the biblioitem to be deleted
4078 # FIXME: add error handling
4080 sub _koha_delete_biblioitems {
4081 my ( $dbh, $biblioitemnumber ) = @_;
4083 # get all the data for this biblioitem
4085 $dbh->prepare("SELECT * FROM biblioitems WHERE biblioitemnumber=?");
4086 $sth->execute($biblioitemnumber);
4088 if ( my $data = $sth->fetchrow_hashref ) {
4090 # save the record in deletedbiblioitems
4091 # find the fields to save
4092 my $query = "INSERT INTO deletedbiblioitems SET ";
4094 foreach my $temp ( keys %$data ) {
4095 $query .= "$temp = ?,";
4096 push( @bind, $data->{$temp} );
4099 # replace the last , by ",?)"
4101 my $bkup_sth = $dbh->prepare($query);
4102 $bkup_sth->execute(@bind);
4105 # delete the biblioitem
4107 $dbh->prepare("DELETE FROM biblioitems WHERE biblioitemnumber=?");
4108 $del_sth->execute($biblioitemnumber);
4115 =head2 _koha_delete_item
4119 _koha_delete_item( $dbh, $itemnum );
4121 Internal function to delete an item record from the koha tables
4127 sub _koha_delete_item {
4128 my ( $dbh, $itemnum ) = @_;
4130 # save the deleted item to deleteditems table
4131 my $sth = $dbh->prepare("SELECT * FROM items WHERE itemnumber=?");
4132 $sth->execute($itemnum);
4133 my $data = $sth->fetchrow_hashref();
4135 my $query = "INSERT INTO deleteditems SET ";
4137 foreach my $key ( keys %$data ) {
4138 $query .= "$key = ?,";
4139 push( @bind, $data->{$key} );
4142 $sth = $dbh->prepare($query);
4143 $sth->execute(@bind);
4146 # delete from items table
4147 $sth = $dbh->prepare("DELETE FROM items WHERE itemnumber=?");
4148 $sth->execute($itemnum);
4153 =head1 UNEXPORTED FUNCTIONS
4155 =head2 ModBiblioMarc
4157 &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
4159 Add MARC data for a biblio to koha
4161 Function exported, but should NOT be used, unless you really know what you're doing
4167 # pass the MARC::Record to this function, and it will create the records in the marc field
4168 my ( $record, $biblionumber, $frameworkcode ) = @_;
4169 my $dbh = C4::Context->dbh;
4170 my @fields = $record->fields();
4171 if ( !$frameworkcode ) {
4172 $frameworkcode = "";
4175 $dbh->prepare("UPDATE biblio SET frameworkcode=? WHERE biblionumber=?");
4176 $sth->execute( $frameworkcode, $biblionumber );
4178 my $encoding = C4::Context->preference("marcflavour");
4180 # deal with UNIMARC field 100 (encoding) : create it if needed & set encoding to unicode
4181 if ( $encoding eq "UNIMARC" ) {
4183 if ( length($record->subfield( 100, "a" )) == 35 ) {
4184 $string = $record->subfield( 100, "a" );
4185 my $f100 = $record->field(100);
4186 $record->delete_field($f100);
4189 $string = POSIX::strftime( "%Y%m%d", localtime );
4191 $string = sprintf( "%-*s", 35, $string );
4193 substr( $string, 22, 6, "frey50" );
4194 unless ( $record->subfield( 100, "a" ) ) {
4195 $record->insert_grouped_field(
4196 MARC::Field->new( 100, "", "", "a" => $string ) );
4199 ModZebra($biblionumber,"specialUpdate","biblioserver",$record);
4202 "UPDATE biblioitems SET marc=?,marcxml=? WHERE biblionumber=?");
4203 $sth->execute( $record->as_usmarc(), $record->as_xml_record($encoding),
4206 return $biblionumber;
4209 =head2 z3950_extended_services
4211 z3950_extended_services($serviceType,$serviceOptions,$record);
4213 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.
4215 C<$serviceType> one of: itemorder,create,drop,commit,update,xmlupdate
4217 C<$serviceOptions> a has of key/value pairs. For instance, if service_type is 'update', $service_options should contain:
4219 action => update action, one of specialUpdate, recordInsert, recordReplace, recordDelete, elementUpdate.
4223 recordidOpaque => Opaque Record ID (user supplied) or recordidNumber => Record ID number (system number).
4224 syntax => the record syntax (transfer syntax)
4225 databaseName = Database from connection object
4227 To set serviceOptions, call set_service_options($serviceType)
4229 C<$record> the record, if one is needed for the service type
4231 A record should be in XML. You can convert it to XML from MARC by running it through marc2xml().
4235 sub z3950_extended_services {
4236 my ( $server, $serviceType, $action, $serviceOptions ) = @_;
4238 # get our connection object
4239 my $Zconn = C4::Context->Zconn( $server, 0, 1 );
4241 # create a new package object
4242 my $Zpackage = $Zconn->package();
4245 $Zpackage->option( action => $action );
4247 if ( $serviceOptions->{'databaseName'} ) {
4248 $Zpackage->option( databaseName => $serviceOptions->{'databaseName'} );
4250 if ( $serviceOptions->{'recordIdNumber'} ) {
4252 recordIdNumber => $serviceOptions->{'recordIdNumber'} );
4254 if ( $serviceOptions->{'recordIdOpaque'} ) {
4256 recordIdOpaque => $serviceOptions->{'recordIdOpaque'} );
4259 # this is an ILL request (Zebra doesn't support it, but Koha could eventually)
4260 #if ($serviceType eq 'itemorder') {
4261 # $Zpackage->option('contact-name' => $serviceOptions->{'contact-name'});
4262 # $Zpackage->option('contact-phone' => $serviceOptions->{'contact-phone'});
4263 # $Zpackage->option('contact-email' => $serviceOptions->{'contact-email'});
4264 # $Zpackage->option('itemorder-item' => $serviceOptions->{'itemorder-item'});
4267 if ( $serviceOptions->{record} ) {
4268 $Zpackage->option( record => $serviceOptions->{record} );
4270 # can be xml or marc
4271 if ( $serviceOptions->{'syntax'} ) {
4272 $Zpackage->option( syntax => $serviceOptions->{'syntax'} );
4276 # send the request, handle any exception encountered
4277 eval { $Zpackage->send($serviceType) };
4278 if ( $@ && $@->isa("ZOOM::Exception") ) {
4279 return "error: " . $@->code() . " " . $@->message() . "\n";
4282 # free up package resources
4283 $Zpackage->destroy();
4286 =head2 set_service_options
4288 my $serviceOptions = set_service_options($serviceType);
4290 C<$serviceType> itemorder,create,drop,commit,update,xmlupdate
4292 Currently, we only support 'create', 'commit', and 'update'. 'drop' support will be added as soon as Zebra supports it.
4296 sub set_service_options {
4297 my ($serviceType) = @_;
4300 # FIXME: This needs to be an OID ... if we ever need 'syntax' this sub will need to change
4301 # $serviceOptions->{ 'syntax' } = ''; #zebra doesn't support syntaxes other than xml
4303 if ( $serviceType eq 'commit' ) {
4307 if ( $serviceType eq 'create' ) {
4311 if ( $serviceType eq 'drop' ) {
4312 die "ERROR: 'drop' not currently supported (by Zebra)";
4314 return $serviceOptions;
4317 =head2 GetItemsCount
4319 $count = &GetItemsCount( $biblionumber);
4320 this function return count of item with $biblionumber
4324 my ( $biblionumber ) = @_;
4325 my $dbh = C4::Context->dbh;
4326 my $query = "SELECT count(*)
4328 WHERE biblionumber=?";
4329 my $sth = $dbh->prepare($query);
4330 $sth->execute($biblionumber);
4331 my $count = $sth->fetchrow;
4336 END { } # module clean-up code here (global destructor)
4344 Koha Developement team <info@koha.org>
4346 Paul POULAIN paul.poulain@free.fr
4348 Joshua Ferraro jmf@liblime.com