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
25 use MARC::File::USMARC;
31 use C4::Log; # logaction
33 use vars qw($VERSION @ISA @EXPORT);
35 # set the version for version checking
36 $VERSION = do { my @v = '$Revision$' =~ /\d+/g; shift(@v).".".join( "_", map { sprintf "%03d", $_ } @v ); };
38 @ISA = qw( Exporter );
42 # to add biblios or items
43 push @EXPORT, qw( &AddBiblio &AddItem );
51 &GetBiblioItemByBiblioNumber
52 &GetBiblioFromItemNumber
69 &GetItemnumberFromBarcode
73 &GetAuthorisedValueDesc
88 &ModItemInMarconefield
99 # those functions are exported but should not be used
100 # they are usefull is few circumstances, so are exported.
101 # but don't use them unless you're a core developer ;-)
114 &PrepareItemrecordDisplay
120 C4::Biblio - cataloging management functions
124 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:
128 =item 1. in the biblio,biblioitems,items, etc tables, which are limited to a one-to-one mapping to underlying MARC data
130 =item 2. as raw MARC in the Zebra index and storage engine
132 =item 3. as raw MARC the biblioitems.marc and biblioitems.marcxml
136 In the 3.0 version of Koha, the authoritative record-level information is in biblioitems.marcxml
138 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.
142 =item 1. Compared with MySQL, Zebra is slow to update an index for small data changes -- especially for proc-intensive operations like circulation
144 =item 2. Zebra's index has been known to crash and a backup of the data is necessary to rebuild it in such cases
148 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:
152 =item 1. Add*/Mod*/Del*/ - high-level external functions suitable for being called from external scripts to manage the collection
154 =item 2. _koha_* - low-level internal functions for managing the koha tables
156 =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.
158 =item 4. Zebra functions used to update the Zebra index
160 =item 5. internal helper functions such as char_decode, checkitems, etc. Some of these probably belong in Koha.pm
164 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 :
168 =item 1. save datas in biblio and biblioitems table, that gives us a biblionumber and a biblioitemnumber
170 =item 2. add the biblionumber and biblioitemnumber into the MARC records
172 =item 3. save the marc record
176 When dealing with items, we must :
180 =item 1. save the item in items table, that gives us an itemnumber
182 =item 2. add the itemnumber to the item MARC field
184 =item 3. overwrite the MARC record (with the added item) into biblioitems.marc(xml)
186 When modifying a biblio or an item, the behaviour is quite similar.
190 =head1 EXPORTED FUNCTIONS
196 ($biblionumber,$biblioitemnumber) = AddBiblio($record,$frameworkcode);
197 Exported function (core API) for adding a new biblio to koha.
204 my ( $record, $frameworkcode ) = @_;
206 my $biblioitemnumber;
207 my $dbh = C4::Context->dbh;
208 # transform the data into koha-table style data
209 my $olddata = TransformMarcToKoha( $dbh, $record, $frameworkcode );
210 $biblionumber = _koha_add_biblio( $dbh, $olddata, $frameworkcode );
211 $olddata->{'biblionumber'} = $biblionumber;
212 $biblioitemnumber = _koha_add_biblioitem( $dbh, $olddata );
214 # we must add bibnum and bibitemnum in MARC::Record...
215 # we build the new field with biblionumber and biblioitemnumber
216 # we drop the original field
217 # we add the new builded field.
218 ( my $biblio_tag, my $biblio_subfield ) = GetMarcFromKohaField("biblio.biblionumber",$frameworkcode);
219 ( my $biblioitem_tag, my $biblioitem_subfield ) = GetMarcFromKohaField("biblioitems.biblioitemnumber",$frameworkcode);
223 # biblionumber & biblioitemnumber are in different fields
224 if ( $biblio_tag != $biblioitem_tag ) {
226 # deal with biblionumber
227 if ( $biblio_tag < 10 ) {
228 $newfield = MARC::Field->new( $biblio_tag, $biblionumber );
232 MARC::Field->new( $biblio_tag, '', '',
233 "$biblio_subfield" => $biblionumber );
236 # drop old field and create new one...
237 my $old_field = $record->field($biblio_tag);
238 $record->delete_field($old_field);
239 $record->append_fields($newfield);
241 # deal with biblioitemnumber
242 if ( $biblioitem_tag < 10 ) {
243 $newfield = MARC::Field->new( $biblioitem_tag, $biblioitemnumber, );
247 MARC::Field->new( $biblioitem_tag, '', '',
248 "$biblioitem_subfield" => $biblioitemnumber, );
250 # drop old field and create new one...
251 $old_field = $record->field($biblioitem_tag);
252 $record->delete_field($old_field);
253 $record->insert_fields_ordered($newfield);
255 # biblionumber & biblioitemnumber are in the same field (can't be <10 as fields <10 have only 1 value)
258 my $newfield = MARC::Field->new(
260 "$biblio_subfield" => $biblionumber,
261 "$biblioitem_subfield" => $biblioitemnumber
264 # drop old field and create new one...
265 my $old_field = $record->field($biblio_tag);
266 $record->delete_field($old_field);
267 $record->insert_fields_ordered($newfield);
272 ModBiblioMarc( $record, $biblionumber, $frameworkcode );
274 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","ADD",$biblionumber,"biblio")
275 if C4::Context->preference("CataloguingLog");
277 return ( $biblionumber, $biblioitemnumber );
284 $biblionumber = AddItem( $record, $biblionumber)
285 Exported function (core API) for adding a new item to Koha
292 my ( $record, $biblionumber ) = @_;
293 my $dbh = C4::Context->dbh;
296 my $frameworkcode = GetFrameworkCode( $biblionumber );
297 my $item = &TransformMarcToKoha( $dbh, $record, $frameworkcode );
299 # needs old biblionumber and biblioitemnumber
300 $item->{'biblionumber'} = $biblionumber;
303 "select biblioitemnumber,itemtype from biblioitems where biblionumber=?"
305 $sth->execute( $item->{'biblionumber'} );
307 ( $item->{'biblioitemnumber'}, $itemtype ) = $sth->fetchrow;
310 "select notforloan from itemtypes where itemtype='$itemtype'");
312 my $notforloan = $sth->fetchrow;
313 ##Change the notforloan field if $notforloan found
314 if ( $notforloan > 0 ) {
315 $item->{'notforloan'} = $notforloan;
316 &MARCitemchange( $record, "items.notforloan", $notforloan );
318 if ( !$item->{'dateaccessioned'} || $item->{'dateaccessioned'} eq '' ) {
321 my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
326 "$year-" . sprintf( "%0.2d", $mon ) . "-" . sprintf( "%0.2d", $mday );
327 $item->{'dateaccessioned'} = $date;
328 &MARCitemchange( $record, "items.dateaccessioned", $date );
330 my ( $itemnumber, $error ) =
331 &_koha_new_items( $dbh, $item, $item->{barcode} );
333 # add itemnumber to MARC::Record before adding the item.
336 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
338 &TransformKohaToMarcOneField( $sth, $record, "items.itemnumber", $itemnumber,
342 &AddItemInMarc( $record, $item->{'biblionumber'},$frameworkcode );
344 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","ADD",$itemnumber,"item")
345 if C4::Context->preference("CataloguingLog");
347 return ($item->{biblionumber}, $item->{biblioitemnumber},$itemnumber);
354 ModBiblio( $record,$biblionumber,$frameworkcode);
355 Exported function (core API) to modify a biblio
362 my ( $record, $biblionumber, $frameworkcode ) = @_;
364 if (C4::Context->preference("CataloguingLog")) {
365 my $newrecord = GetMarcBiblio($biblionumber);
366 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","MODIFY",$biblionumber,$newrecord->as_formatted)
369 my $dbh = C4::Context->dbh;
371 $frameworkcode = "" unless $frameworkcode;
373 # update the MARC record with the new record data
374 &ModBiblioMarc($record, $biblionumber, $frameworkcode );
376 # load the koha-table data object
377 my $oldbiblio = TransformMarcToKoha( $dbh, $record, $frameworkcode );
379 # modify the other koha tables
380 my $biblionumber = _koha_modify_biblio( $dbh, $oldbiblio );
381 _koha_modify_biblioitem( $dbh, $oldbiblio );
390 Exported function (core API) for modifying an item in Koha.
397 my ( $record, $biblionumber, $itemnumber, $delete, $new_item_hashref )
401 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","MODIFY",$itemnumber,$record->as_formatted)
402 if C4::Context->preference("CataloguingLog");
404 my $dbh = C4::Context->dbh;
406 # if we have a MARC record, we're coming from cataloging and so
407 # we do the whole routine: update the MARC and zebra, then update the koha
410 my $frameworkcode = GetFrameworkCode( $biblionumber );
411 ModItemInMarc( $record, $biblionumber, $itemnumber, $frameworkcode );
412 my $olditem = TransformMarcToKoha( $dbh, $record, $frameworkcode );
413 _koha_modify_item( $dbh, $olditem );
414 return $biblionumber;
417 # otherwise, we're just looking to modify something quickly
418 # (like a status) so we just update the koha tables
419 elsif ($new_item_hashref) {
420 _koha_modify_item( $dbh, $new_item_hashref );
424 sub ModItemTransfer {
425 my ( $itemnumber, $frombranch, $tobranch ) = @_;
427 my $dbh = C4::Context->dbh;
429 #new entry in branchtransfers....
430 my $sth = $dbh->prepare(
431 "INSERT INTO branchtransfers (itemnumber, frombranch, datesent, tobranch)
432 VALUES (?, ?, now(), $?)");
433 $sth->execute($itemnumber, $frombranch, $tobranch);
434 #update holdingbranch in items .....
436 "UPDATE items set holdingbranch = ? WHERE items.itemnumber = ?");
437 $sth->execute($tobranch,$itemnumber);
438 &ModDateLastSeen($itemnumber);
439 $sth = $dbh->prepare(
440 "SELECT biblionumber FROM items WHERE itemnumber=?"
442 $sth->execute($itemnumber);
443 while ( my ( $biblionumber ) = $sth->fetchrow ) {
444 &ModItemInMarconefield( $biblionumber, $itemnumber,
445 'items.holdingbranch', $tobranch );
450 ##New sub to dotransfer in marc tables as well. Not exported -TG 10/04/2006
451 # sub domarctransfer {
452 # my ( $dbh, $itemnumber ) = @_;
453 # $itemnumber =~ s /\'//g; ##itemnumber seems to come with quotes-TG
456 # "select biblionumber,holdingbranch from items where itemnumber=$itemnumber"
459 # while ( my ( $biblionumber, $holdingbranch ) = $sth->fetchrow ) {
460 # &ModItemInMarconefield( $biblionumber, $itemnumber,
461 # 'items.holdingbranch', $holdingbranch );
465 =head2 ModBiblioframework
469 ModBiblioframework($biblionumber,$frameworkcode);
470 Exported function to modify a biblio framework
476 sub ModBiblioframework {
477 my ( $biblionumber, $frameworkcode ) = @_;
478 my $dbh = C4::Context->dbh;
481 "UPDATE biblio SET frameworkcode=? WHERE biblionumber=$biblionumber");
482 $sth->execute($frameworkcode);
486 =head2 ModItemInMarconefield
490 modify only 1 field in a MARC item (mainly used for holdingbranch, but could also be used for status modif - moving a book to "lost" on a long overdu for example)
491 &ModItemInMarconefield( $biblionumber, $itemnumber, $itemfield, $newvalue )
497 sub ModItemInMarconefield {
498 my ( $biblionumber, $itemnumber, $itemfield, $newvalue ) = @_;
499 my $dbh = C4::Context->dbh;
500 if ( !defined $newvalue ) {
504 my $record = GetMarcItem( $biblionumber, $itemnumber );
505 my ($tagfield, $tagsubfield) = GetMarcFromKohaField( $itemfield,'');
506 if ($tagfield && $tagsubfield) {
507 my $tag = $record->field($tagfield);
509 # my $tagsubs = $record->field($tagfield)->subfield($tagsubfield);
510 $tag->update( $tagsubfield => $newvalue );
511 $record->delete_field($tag);
512 $record->insert_fields_ordered($tag);
513 &ModItemInMarc( $record, $biblionumber, $itemnumber, 0 );
522 &ModItemInMarc( $record, $biblionumber, $itemnumber )
529 my ( $ItemRecord, $biblionumber, $itemnumber, $frameworkcode) = @_;
530 my $dbh = C4::Context->dbh;
532 # get complete MARC record & replace the item field by the new one
533 my $completeRecord = GetMarcBiblio($biblionumber);
534 my ($itemtag,$itemsubfield) = GetMarcFromKohaField("items.itemnumber",$frameworkcode);
535 my $itemField = $ItemRecord->field($itemtag);
536 my @items = $completeRecord->field($itemtag);
538 if ($_->subfield($itemsubfield) eq $itemnumber) {
539 # $completeRecord->delete_field($_);
540 $_->replace_with($itemField);
544 my $sth = $dbh->prepare("update biblioitems set marc=?,marcxml=? where biblionumber=?");
545 $sth->execute( $completeRecord->as_usmarc(), $completeRecord->as_xml_record(),$biblionumber );
547 ModZebra($biblionumber,"specialUpdate","biblioserver");
550 =head2 ModDateLastSeen
552 &ModDateLastSeen($itemnum)
553 Mark item as seen. Is called when an item is issued, returned or manually marked during inventory/stocktaking
554 C<$itemnum> is the item number
558 sub ModDateLastSeen {
560 my $dbh = C4::Context->dbh;
563 "update items set itemlost=0, datelastseen = now() where items.itemnumber = ?"
565 $sth->execute($itemnum);
572 my $error = &DelBiblio($dbh,$biblionumber);
573 Exported function (core API) for deleting a biblio in koha.
574 Deletes biblio record from Zebra and Koha tables (biblio,biblioitems,items)
575 Also backs it up to deleted* tables
576 Checks to make sure there are not issues on any of the items
578 C<$error> : undef unless an error occurs
585 my ( $biblionumber ) = @_;
586 my $dbh = C4::Context->dbh;
587 my $error; # for error handling
589 # First make sure there are no items with issues are still attached
592 "SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
593 $sth->execute($biblionumber);
594 while ( my $biblioitemnumber = $sth->fetchrow ) {
595 my @issues = C4::Circulation::Circ2::itemissues($biblioitemnumber);
596 foreach my $issue (@issues) {
597 if ( ( $issue->{date_due} )
598 && ( $issue->{date_due} ne "Available" ) )
601 #FIXME: we need a status system in Biblio like in Circ to return standard codes and messages
602 # instead of hard-coded strings
604 "Item is checked out to a patron -- you must return it before deleting the Biblio";
608 return $error if $error;
611 ModZebra($biblionumber,"delete_record","biblioserver");
613 # delete biblio from Koha tables and save in deletedbiblio
614 $error = &_koha_delete_biblio( $dbh, $biblionumber );
616 # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
619 "SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
620 $sth->execute($biblionumber);
621 while ( my $biblioitemnumber = $sth->fetchrow ) {
623 # delete this biblioitem
624 $error = &_koha_delete_biblioitems( $dbh, $biblioitemnumber );
625 return $error if $error;
630 "SELECT itemnumber FROM items WHERE biblioitemnumber=?");
631 $items_sth->execute($biblioitemnumber);
632 while ( my $itemnumber = $items_sth->fetchrow ) {
633 $error = &_koha_delete_item( $dbh, $itemnumber );
634 return $error if $error;
637 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","DELETE",$biblionumber,"")
638 if C4::Context->preference("CataloguingLog");
646 DelItem( $biblionumber, $itemnumber );
647 Exported function (core API) for deleting an item record in Koha.
654 my ( $biblionumber, $itemnumber ) = @_;
655 my $dbh = C4::Context->dbh;
656 &_koha_delete_item( $dbh, $itemnumber );
657 # get the MARC record
658 my $record = GetMarcBiblio($biblionumber);
659 my $frameworkcode = GetFrameworkCode($biblionumber);
663 $dbh->prepare("UPDATE deleteditems SET marc=? WHERE itemnumber=?");
664 $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
666 #search item field code
667 my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",$frameworkcode);
668 my @fields = $record->field($itemtag);
669 # delete the item specified
670 foreach my $field (@fields) {
671 if ( $field->subfield($itemsubfield) eq $itemnumber ) {
672 $record->delete_field($field);
675 &ModBiblioMarc( $record, $biblionumber, $frameworkcode );
676 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","DELETE",$itemnumber,"item")
677 if C4::Context->preference("CataloguingLog");
684 $data = &GetBiblioData($biblionumber);
685 Returns information about the book with the given biblionumber.
686 C<&GetBiblioData> returns a reference-to-hash. The keys are the fields in
687 the C<biblio> and C<biblioitems> tables in the
689 In addition, C<$data-E<gt>{subject}> is the list of the book's
690 subjects, separated by C<" , "> (space, comma, space).
691 If there are multiple biblioitems with the given biblionumber, only
692 the first one is considered.
700 my $dbh = C4::Context->dbh;
703 SELECT * , biblioitems.notes AS bnotes, biblio.notes
705 LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
706 LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype
707 WHERE biblio.biblionumber = ?
708 AND biblioitems.biblionumber = biblio.biblionumber
710 my $sth = $dbh->prepare($query);
711 $sth->execute($bibnum);
713 $data = $sth->fetchrow_hashref;
717 } # sub GetBiblioData
724 @results = &GetItemsInfo($biblionumber, $type);
726 Returns information about books with the given biblionumber.
728 C<$type> may be either C<intra> or anything else. If it is not set to
729 C<intra>, then the search will exclude lost, very overdue, and
732 C<&GetItemsInfo> returns a list of references-to-hash. Each element
733 contains a number of keys. Most of them are table items from the
734 C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
735 Koha database. Other keys include:
739 =item C<$data-E<gt>{branchname}>
741 The name (not the code) of the branch to which the book belongs.
743 =item C<$data-E<gt>{datelastseen}>
745 This is simply C<items.datelastseen>, except that while the date is
746 stored in YYYY-MM-DD format in the database, here it is converted to
747 DD/MM/YYYY format. A NULL date is returned as C<//>.
749 =item C<$data-E<gt>{datedue}>
751 =item C<$data-E<gt>{class}>
753 This is the concatenation of C<biblioitems.classification>, the book's
754 Dewey code, and C<biblioitems.subclass>.
756 =item C<$data-E<gt>{ocount}>
758 I think this is the number of copies of the book available.
760 =item C<$data-E<gt>{order}>
762 If this is set, it is set to C<One Order>.
771 my ( $biblionumber, $type ) = @_;
772 my $dbh = C4::Context->dbh;
773 my $query = "SELECT *,items.notforloan as itemnotforloan
774 FROM items, biblio, biblioitems
775 LEFT JOIN itemtypes on biblioitems.itemtype = itemtypes.itemtype
776 WHERE items.biblionumber = ?
777 AND biblioitems.biblioitemnumber = items.biblioitemnumber
778 AND biblio.biblionumber = items.biblionumber
779 ORDER BY items.dateaccessioned desc
781 my $sth = $dbh->prepare($query);
782 $sth->execute($biblionumber);
785 my ( $date_due, $count_reserves );
787 while ( my $data = $sth->fetchrow_hashref ) {
789 my $isth = $dbh->prepare(
790 "SELECT issues.*,borrowers.cardnumber
791 FROM issues, borrowers
793 AND returndate IS NULL
794 AND issues.borrowernumber=borrowers.borrowernumber"
796 $isth->execute( $data->{'itemnumber'} );
797 if ( my $idata = $isth->fetchrow_hashref ) {
798 $data->{borrowernumber} = $idata->{borrowernumber};
799 $data->{cardnumber} = $idata->{cardnumber};
800 $datedue = format_date( $idata->{'date_due'} );
802 if ( $datedue eq '' ) {
803 #$datedue="Available";
804 my ( $restype, $reserves ) =
805 C4::Reserves::CheckReserves( $data->{'itemnumber'} );
809 $count_reserves = $restype;
814 #get branch information.....
815 my $bsth = $dbh->prepare(
816 "SELECT * FROM branches WHERE branchcode = ?
819 $bsth->execute( $data->{'holdingbranch'} );
820 if ( my $bdata = $bsth->fetchrow_hashref ) {
821 $data->{'branchname'} = $bdata->{'branchname'};
823 my $date = format_date( $data->{'datelastseen'} );
824 $data->{'datelastseen'} = $date;
825 $data->{'datedue'} = $datedue;
826 $data->{'count_reserves'} = $count_reserves;
828 # get notforloan complete status if applicable
829 my $sthnflstatus = $dbh->prepare(
830 'SELECT authorised_value
831 FROM marc_subfield_structure
832 WHERE kohafield="items.notforloan"
836 $sthnflstatus->execute;
837 my ($authorised_valuecode) = $sthnflstatus->fetchrow;
838 if ($authorised_valuecode) {
839 $sthnflstatus = $dbh->prepare(
840 "SELECT lib FROM authorised_values
842 AND authorised_value=?"
844 $sthnflstatus->execute( $authorised_valuecode,
845 $data->{itemnotforloan} );
846 my ($lib) = $sthnflstatus->fetchrow;
847 $data->{notforloan} = $lib;
850 # my stack procedures
851 my $stackstatus = $dbh->prepare(
852 'SELECT authorised_value
853 FROM marc_subfield_structure
854 WHERE kohafield="items.stack"
857 $stackstatus->execute;
859 ($authorised_valuecode) = $stackstatus->fetchrow;
860 if ($authorised_valuecode) {
861 $stackstatus = $dbh->prepare(
863 FROM authorised_values
865 AND authorised_value=?
868 $stackstatus->execute( $authorised_valuecode, $data->{stack} );
869 my ($lib) = $stackstatus->fetchrow;
870 $data->{stack} = $lib;
872 $results[$i] = $data;
884 $itemstatushash = &getitemstatus($fwkcode);
885 returns information about status.
886 Can be MARC dependant.
888 But basically could be can be loan or not
889 Create a status selector with the following code
891 =head3 in PERL SCRIPT
893 my $itemstatushash = getitemstatus;
895 foreach my $thisstatus (keys %$itemstatushash) {
896 my %row =(value => $thisstatus,
897 statusname => $itemstatushash->{$thisstatus}->{'statusname'},
899 push @itemstatusloop, \%row;
901 $template->param(statusloop=>\@itemstatusloop);
906 <select name="statusloop">
907 <option value="">Default</option>
908 <!-- TMPL_LOOP name="statusloop" -->
909 <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="statusname" --></option>
917 # returns a reference to a hash of references to status...
920 my $dbh = C4::Context->dbh;
922 $fwk = '' unless ($fwk);
923 my ( $tag, $subfield ) =
924 GetMarcFromKohaField( "items.notforloan", $fwk );
925 if ( $tag and $subfield ) {
928 "select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?"
930 $sth->execute( $tag, $subfield, $fwk );
931 if ( my ($authorisedvaluecat) = $sth->fetchrow ) {
934 "select authorised_value, lib from authorised_values where category=? order by lib"
936 $authvalsth->execute($authorisedvaluecat);
937 while ( my ( $authorisedvalue, $lib ) = $authvalsth->fetchrow ) {
938 $itemstatus{$authorisedvalue} = $lib;
954 $itemstatus{"1"} = "Not For Loan";
958 =head2 getitemlocation
962 $itemlochash = &getitemlocation($fwk);
963 returns informations about location.
964 where fwk stands for an optional framework code.
965 Create a location selector with the following code
967 =head3 in PERL SCRIPT
969 my $itemlochash = getitemlocation;
971 foreach my $thisloc (keys %$itemlochash) {
972 my $selected = 1 if $thisbranch eq $branch;
973 my %row =(locval => $thisloc,
974 selected => $selected,
975 locname => $itemlochash->{$thisloc},
977 push @itemlocloop, \%row;
979 $template->param(itemlocationloop => \@itemlocloop);
983 <select name="location">
984 <option value="">Default</option>
985 <!-- TMPL_LOOP name="itemlocationloop" -->
986 <option value="<!-- TMPL_VAR name="locval" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="locname" --></option>
994 sub GetItemLocation {
996 # returns a reference to a hash of references to location...
999 my $dbh = C4::Context->dbh;
1001 $fwk = '' unless ($fwk);
1002 my ( $tag, $subfield ) =
1003 GetMarcFromKohaField( "items.location", $fwk );
1004 if ( $tag and $subfield ) {
1007 "select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?"
1009 $sth->execute( $tag, $subfield, $fwk );
1010 if ( my ($authorisedvaluecat) = $sth->fetchrow ) {
1013 "select authorised_value, lib from authorised_values where category=? order by lib"
1015 $authvalsth->execute($authorisedvaluecat);
1016 while ( my ( $authorisedvalue, $lib ) = $authvalsth->fetchrow ) {
1017 $itemlocation{$authorisedvalue} = $lib;
1019 $authvalsth->finish;
1020 return \%itemlocation;
1033 $itemlocation{"1"} = "Not For Loan";
1034 return \%itemlocation;
1039 $items = GetLostItems($where,$orderby);
1041 This function get the items lost into C<$items>.
1046 C<$where> is a hashref. it containts a field of the items table as key
1047 and the value to match as value.
1048 C<$orderby> is a field of the items table.
1051 C<$items> is a reference to an array full of hasref which keys are items' table column.
1053 =item usage in the perl script:
1056 $where{barcode} = 0001548;
1057 my $items = GetLostItems( \%where, "homebranch" );
1058 $template->param(itemsloop => $items);
1065 # Getting input args.
1067 my $orderby = shift;
1068 my $dbh = C4::Context->dbh;
1073 WHERE itemlost IS NOT NULL
1076 foreach my $key (keys %$where) {
1077 $query .= " AND " . $key . " LIKE '%" . $where->{$key} . "%'";
1079 $query .= " ORDER BY ".$orderby if defined $orderby;
1081 my $sth = $dbh->prepare($query);
1084 while ( my $row = $sth->fetchrow_hashref ){
1090 =head2 GetItemsForInventory
1092 $itemlist = GetItemsForInventory($minlocation,$maxlocation,$datelastseen,$offset,$size)
1094 Retrieve a list of title/authors/barcode/callnumber, for biblio inventory.
1096 The sub returns a list of hashes, containing itemnumber, author, title, barcode & item callnumber.
1097 It is ordered by callnumber,title.
1099 The minlocation & maxlocation parameters are used to specify a range of item callnumbers
1100 the datelastseen can be used to specify that you want to see items not seen since a past date only.
1101 offset & size can be used to retrieve only a part of the whole listing (defaut behaviour)
1105 sub GetItemsForInventory {
1106 my ( $minlocation, $maxlocation, $datelastseen, $branch, $offset, $size ) = @_;
1107 my $dbh = C4::Context->dbh;
1109 if ($datelastseen) {
1111 "SELECT itemnumber,barcode,itemcallnumber,title,author,datelastseen
1113 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1114 WHERE itemcallnumber>= ?
1115 AND itemcallnumber <=?
1116 AND (datelastseen< ? OR datelastseen IS NULL)";
1117 $query.= " AND items.homebranch=".$dbh->quote($branch) if $branch;
1118 $query .= " ORDER BY itemcallnumber,title";
1119 $sth = $dbh->prepare($query);
1120 $sth->execute( $minlocation, $maxlocation, $datelastseen );
1124 SELECT itemnumber,barcode,itemcallnumber,title,author,datelastseen
1126 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1127 WHERE itemcallnumber>= ?
1128 AND itemcallnumber <=?";
1129 $query.= " AND items.homebranch=".$dbh->quote($branch) if $branch;
1130 $query .= " ORDER BY itemcallnumber,title";
1131 $sth = $dbh->prepare($query);
1132 $sth->execute( $minlocation, $maxlocation );
1135 while ( my $row = $sth->fetchrow_hashref ) {
1136 $offset-- if ($offset);
1137 if ( ( !$offset ) && $size ) {
1138 push @results, $row;
1145 =head2 &GetBiblioItemData
1149 $itemdata = &GetBiblioItemData($biblioitemnumber);
1151 Looks up the biblioitem with the given biblioitemnumber. Returns a
1152 reference-to-hash. The keys are the fields from the C<biblio>,
1153 C<biblioitems>, and C<itemtypes> tables in the Koha database, except
1154 that C<biblioitems.notes> is given as C<$itemdata-E<gt>{bnotes}>.
1161 sub GetBiblioItemData {
1163 my $dbh = C4::Context->dbh;
1166 "Select *,biblioitems.notes as bnotes from biblioitems, biblio,itemtypes where biblio.biblionumber = biblioitems.biblionumber and biblioitemnumber = ? and biblioitems.itemtype = itemtypes.itemtype"
1170 $sth->execute($bibitem);
1172 $data = $sth->fetchrow_hashref;
1176 } # sub &GetBiblioItemData
1178 =head2 GetItemnumberFromBarcode
1182 $result = GetItemnumberFromBarcode($barcode);
1188 sub GetItemnumberFromBarcode {
1190 my $dbh = C4::Context->dbh;
1193 $dbh->prepare("SELECT itemnumber from items where items.barcode=?");
1194 $rq->execute($barcode);
1195 my ($result) = $rq->fetchrow;
1199 =head2 GetBiblioItemByBiblioNumber
1203 NOTE : This function has been copy/paste from C4/Biblio.pm from head before zebra integration.
1209 sub GetBiblioItemByBiblioNumber {
1210 my ($biblionumber) = @_;
1211 my $dbh = C4::Context->dbh;
1212 my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?");
1216 $sth->execute($biblionumber);
1218 while ( my $data = $sth->fetchrow_hashref ) {
1219 push @results, $data;
1226 =head2 GetBiblioFromItemNumber
1230 $item = &GetBiblioFromItemNumber($itemnumber);
1232 Looks up the item with the given itemnumber.
1234 C<&itemnodata> returns a reference-to-hash whose keys are the fields
1235 from the C<biblio>, C<biblioitems>, and C<items> tables in the Koha
1243 sub GetBiblioFromItemNumber {
1244 my ( $itemnumber ) = @_;
1245 my $dbh = C4::Context->dbh;
1246 my $sth = $dbh->prepare(
1247 "SELECT * FROM biblio,items,biblioitems
1248 WHERE items.itemnumber = ?
1249 AND biblio.biblionumber = items.biblionumber
1250 AND biblioitems.biblioitemnumber = items.biblioitemnumber"
1253 $sth->execute($itemnumber);
1254 my $data = $sth->fetchrow_hashref;
1263 ( $count, @results ) = &GetBiblio($biblionumber);
1270 my ($biblionumber) = @_;
1271 my $dbh = C4::Context->dbh;
1272 my $sth = $dbh->prepare("Select * from biblio where biblionumber = ?");
1275 $sth->execute($biblionumber);
1276 while ( my $data = $sth->fetchrow_hashref ) {
1277 $results[$count] = $data;
1281 return ( $count, @results );
1288 $data = &GetItem($itemnumber,$barcode);
1290 return Item information, for a given itemnumber or barcode
1297 my ($itemnumber,$barcode) = @_;
1298 my $dbh = C4::Context->dbh;
1300 my $sth = $dbh->prepare("
1302 WHERE itemnumber = ?");
1303 $sth->execute($itemnumber);
1304 my $data = $sth->fetchrow_hashref;
1307 my $sth = $dbh->prepare("
1311 $sth->execute($barcode);
1312 my $data = $sth->fetchrow_hashref;
1317 =head2 get_itemnumbers_of
1321 my @itemnumbers_of = get_itemnumbers_of(@biblionumbers);
1323 Given a list of biblionumbers, return the list of corresponding itemnumbers
1324 for each biblionumber.
1326 Return a reference on a hash where keys are biblionumbers and values are
1327 references on array of itemnumbers.
1333 sub get_itemnumbers_of {
1334 my @biblionumbers = @_;
1336 my $dbh = C4::Context->dbh;
1342 WHERE biblionumber IN (?' . ( ',?' x scalar @biblionumbers - 1 ) . ')
1344 my $sth = $dbh->prepare($query);
1345 $sth->execute(@biblionumbers);
1349 while ( my ( $itemnumber, $biblionumber ) = $sth->fetchrow_array ) {
1350 push @{ $itemnumbers_of{$biblionumber} }, $itemnumber;
1353 return \%itemnumbers_of;
1356 =head2 GetItemInfosOf
1360 GetItemInfosOf(@itemnumbers);
1366 sub GetItemInfosOf {
1367 my @itemnumbers = @_;
1372 WHERE itemnumber IN (' . join( ',', @itemnumbers ) . ')
1374 return get_infos_of( $query, 'itemnumber' );
1377 =head2 GetBiblioItemInfosOf
1381 GetBiblioItemInfosOf(@biblioitemnumbers);
1387 sub GetBiblioItemInfosOf {
1388 my @biblioitemnumbers = @_;
1391 SELECT biblioitemnumber,
1395 WHERE biblioitemnumber IN (' . join( ',', @biblioitemnumbers ) . ')
1397 return get_infos_of( $query, 'biblioitemnumber' );
1400 =head1 FUNCTIONS FOR HANDLING MARC MANAGEMENT
1402 =head2 GetMarcStructure
1406 $res = GetMarcStructure($dbh,$forlibrarian,$frameworkcode);
1408 Returns a reference to a big hash of hash, with the Marc structure fro the given frameworkcode
1410 $forlibrarian :if set to 1, the MARC descriptions are the librarians ones, otherwise it's the public (OPAC) ones
1411 $frameworkcode : the framework code to read
1419 sub GetMarcStructure {
1420 my ( $dbh, $forlibrarian, $frameworkcode ) = @_;
1421 $frameworkcode = "" unless $frameworkcode;
1423 my $libfield = ( $forlibrarian eq 1 ) ? 'liblibrarian' : 'libopac';
1425 # check that framework exists
1428 "select count(*) from marc_tag_structure where frameworkcode=?");
1429 $sth->execute($frameworkcode);
1430 my ($total) = $sth->fetchrow;
1431 $frameworkcode = "" unless ( $total > 0 );
1434 "select tagfield,liblibrarian,libopac,mandatory,repeatable from marc_tag_structure where frameworkcode=? order by tagfield"
1436 $sth->execute($frameworkcode);
1437 my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable );
1439 while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable ) =
1442 $res->{$tag}->{lib} =
1443 ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac;
1444 # why the hell do we need to explicitly decode utf8 ?
1445 # that's a good question, but we must do it...
1447 utf8::decode($res->{$tag}->{lib});
1448 # warn "$liblibrarian";
1449 $res->{$tab}->{tab} = ""; # XXX
1450 $res->{$tag}->{mandatory} = $mandatory;
1451 $res->{$tag}->{repeatable} = $repeatable;
1456 "select tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link,defaultvalue from marc_subfield_structure where frameworkcode=? order by tagfield,tagsubfield"
1458 $sth->execute($frameworkcode);
1461 my $authorised_value;
1473 $tag, $subfield, $liblibrarian,
1475 $mandatory, $repeatable, $authorised_value,
1476 $authtypecode, $value_builder, $kohafield,
1477 $seealso, $hidden, $isurl,
1483 $res->{$tag}->{$subfield}->{lib} =
1484 ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac;
1485 $res->{$tag}->{$subfield}->{tab} = $tab;
1486 $res->{$tag}->{$subfield}->{mandatory} = $mandatory;
1487 $res->{$tag}->{$subfield}->{repeatable} = $repeatable;
1488 $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
1489 $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode;
1490 $res->{$tag}->{$subfield}->{value_builder} = $value_builder;
1491 $res->{$tag}->{$subfield}->{kohafield} = $kohafield;
1492 $res->{$tag}->{$subfield}->{seealso} = $seealso;
1493 $res->{$tag}->{$subfield}->{hidden} = $hidden;
1494 $res->{$tag}->{$subfield}->{isurl} = $isurl;
1495 $res->{$tag}->{$subfield}->{link} = $link;
1496 $res->{$tag}->{$subfield}->{defaultvalue} = $defaultvalue;
1501 =head2 GetMarcFromKohaField
1505 ($MARCfield,$MARCsubfield)=GetMarcFromKohaField($kohafield,$frameworkcode);
1506 Returns the MARC fields & subfields mapped to the koha field
1507 for the given frameworkcode
1513 sub GetMarcFromKohaField {
1514 my ( $kohafield, $frameworkcode ) = @_;
1515 return 0, 0 unless $kohafield;
1516 my $relations = C4::Context->marcfromkohafield;
1518 $relations->{$frameworkcode}->{$kohafield}->[0],
1519 $relations->{$frameworkcode}->{$kohafield}->[1]
1523 =head2 GetMarcBiblio
1527 Returns MARC::Record of the biblionumber passed in parameter.
1528 the marc record contains both biblio & item datas
1535 my $biblionumber = shift;
1536 my $dbh = C4::Context->dbh;
1538 $dbh->prepare("select marcxml from biblioitems where biblionumber=? ");
1539 $sth->execute($biblionumber);
1540 my ($marcxml) = $sth->fetchrow;
1541 MARC::File::XML->default_record_format(C4::Context->preference('marcflavour'));
1542 $marcxml =~ s/\x1e//g;
1543 $marcxml =~ s/\x1f//g;
1544 $marcxml =~ s/\x1d//g;
1545 $marcxml =~ s/\x0f//g;
1546 $marcxml =~ s/\x0c//g;
1547 my $record = MARC::Record->new();
1548 $record = MARC::Record::new_from_xml( $marcxml, "utf8",C4::Context->preference('marcflavour')) if $marcxml;
1556 my $marcxml = GetXmlBiblio($biblionumber);
1558 Returns biblioitems.marcxml of the biblionumber passed in parameter.
1559 The XML contains both biblio & item datas
1566 my ( $biblionumber ) = @_;
1567 my $dbh = C4::Context->dbh;
1569 $dbh->prepare("select marcxml from biblioitems where biblionumber=? ");
1570 $sth->execute($biblionumber);
1571 my ($marcxml) = $sth->fetchrow;
1575 =head2 GetAuthorisedValueDesc
1579 my $subfieldvalue =get_authorised_value_desc(
1580 $tag, $subf[$i][0],$subf[$i][1], '', $taglib);
1581 Retrieve the complete description for a given authorised value.
1587 sub GetAuthorisedValueDesc {
1588 my ( $tag, $subfield, $value, $framework, $tagslib ) = @_;
1589 my $dbh = C4::Context->dbh;
1592 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
1593 return C4::Branch::GetBranchName($value);
1597 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
1598 return getitemtypeinfo($value);
1601 #---- "true" authorized value
1602 my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
1604 if ( $category ne "" ) {
1607 "select lib from authorised_values where category = ? and authorised_value = ?"
1609 $sth->execute( $category, $value );
1610 my $data = $sth->fetchrow_hashref;
1611 return $data->{'lib'};
1614 return $value; # if nothing is found return the original value
1622 Returns MARC::Record of the item passed in parameter.
1629 my ( $biblionumber, $itemnumber ) = @_;
1630 my $dbh = C4::Context->dbh;
1631 my $newrecord = MARC::Record->new();
1632 my $marcflavour = C4::Context->preference('marcflavour');
1634 my $marcxml = GetXmlBiblio($biblionumber);
1635 my $record = MARC::Record->new();
1636 $record = MARC::Record::new_from_xml( $marcxml, "utf8", $marcflavour );
1637 # now, find where the itemnumber is stored & extract only the item
1638 my ( $itemnumberfield, $itemnumbersubfield ) =
1639 GetMarcFromKohaField( 'items.itemnumber', '' );
1640 my @fields = $record->field($itemnumberfield);
1641 foreach my $field (@fields) {
1642 if ( $field->subfield($itemnumbersubfield) eq $itemnumber ) {
1643 $newrecord->insert_fields_ordered($field);
1655 $marcnotesarray = GetMarcNotes( $record, $marcflavour );
1656 Get all notes from the MARC record and returns them in an array.
1657 The note are stored in differents places depending on MARC flavour
1664 my ( $record, $marcflavour ) = @_;
1666 if ( $marcflavour eq "MARC21" ) {
1669 else { # assume unimarc if not marc21
1676 foreach my $field ( $record->field($scope) ) {
1677 my $value = $field->as_string();
1678 if ( $note ne "" ) {
1679 $marcnote = { marcnote => $note, };
1680 push @marcnotes, $marcnote;
1683 if ( $note ne $value ) {
1684 $note = $note . " " . $value;
1689 $marcnote = { marcnote => $note };
1690 push @marcnotes, $marcnote; #load last tag into array
1693 } # end GetMarcNotes
1695 =head2 GetMarcSubjects
1699 $marcsubjcts = GetMarcSubjects($record,$marcflavour);
1700 Get all subjects from the MARC record and returns them in an array.
1701 The subjects are stored in differents places depending on MARC flavour
1707 sub GetMarcSubjects {
1708 my ( $record, $marcflavour ) = @_;
1709 my ( $mintag, $maxtag );
1710 if ( $marcflavour eq "MARC21" ) {
1714 else { # assume unimarc if not marc21
1721 foreach my $field ( $record->fields ) {
1722 next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1723 my @subfields = $field->subfields();
1727 for my $subject_subfield ( @subfields ) {
1728 my $code = $subject_subfield->[0];
1729 $label .= $subject_subfield->[1] . " and su-to:" unless ( $code == 9 );
1731 $link = "Koha-Auth-Number:".$subject_subfield->[1];
1736 $link =~ s/ and\ssu-to:$//;
1749 return \@marcsubjcts;
1750 } #end GetMarcSubjects
1752 =head2 GetMarcAuthors
1756 authors = GetMarcAuthors($record,$marcflavour);
1757 Get all authors from the MARC record and returns them in an array.
1758 The authors are stored in differents places depending on MARC flavour
1764 sub GetMarcAuthors {
1765 my ( $record, $marcflavour ) = @_;
1766 my ( $mintag, $maxtag );
1767 if ( $marcflavour eq "MARC21" ) {
1771 else { # assume unimarc if not marc21
1778 foreach my $field ( $record->fields ) {
1779 next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1781 my @subfields = $field->subfields();
1784 for my $authors_subfield (@subfields) {
1785 if ($count_auth ne '0'){
1789 my $subfieldcode = $authors_subfield->[0];
1790 my $value = $authors_subfield->[1];
1791 $hash{'tag'} = $field->tag;
1792 $hash{value} .= $value . " " if ($subfieldcode != 9) ;
1793 $hash{link} .= $value if ($subfieldcode eq 9);
1795 push @marcauthors, \%hash;
1797 return \@marcauthors;
1800 =head2 GetMarcSeries
1804 $marcseriessarray = GetMarcSeries($record,$marcflavour);
1805 Get all series from the MARC record and returns them in an array.
1806 The series are stored in differents places depending on MARC flavour
1813 my ($record, $marcflavour) = @_;
1814 my ($mintag, $maxtag);
1815 if ($marcflavour eq "MARC21") {
1818 } else { # assume unimarc if not marc21
1828 foreach my $field ($record->field('440'), $record->field('490')) {
1830 #my $value = $field->subfield('a');
1831 #$marcsubjct = {MARCSUBJCT => $value,};
1832 my @subfields = $field->subfields();
1833 #warn "subfields:".join " ", @$subfields;
1836 for my $series_subfield (@subfields) {
1838 undef $volume_number;
1839 # see if this is an instance of a volume
1840 if ($series_subfield->[0] eq 'v') {
1844 my $code = $series_subfield->[0];
1845 my $value = $series_subfield->[1];
1846 my $linkvalue = $value;
1847 $linkvalue =~ s/(\(|\))//g;
1848 my $operator = " and " unless $counter==0;
1849 push @link_loop, {link => $linkvalue, operator => $operator };
1850 my $separator = C4::Context->preference("authoritysep") unless $counter==0;
1851 if ($volume_number) {
1852 push @subfields_loop, {volumenum => $value};
1855 push @subfields_loop, {code => $code, value => $value, link_loop => \@link_loop, separator => $separator, volumenum => $volume_number};
1859 push @marcseries, { MARCSERIES_SUBFIELDS_LOOP => \@subfields_loop };
1860 #$marcsubjct = {MARCSUBJCT => $field->as_string(),};
1861 #push @marcsubjcts, $marcsubjct;
1865 my $marcseriessarray=\@marcseries;
1866 return $marcseriessarray;
1867 } #end getMARCseriess
1869 =head2 GetFrameworkCode
1873 $frameworkcode = GetFrameworkCode( $biblionumber )
1879 sub GetFrameworkCode {
1880 my ( $biblionumber ) = @_;
1881 my $dbh = C4::Context->dbh;
1883 $dbh->prepare("select frameworkcode from biblio where biblionumber=?");
1884 $sth->execute($biblionumber);
1885 my ($frameworkcode) = $sth->fetchrow;
1886 return $frameworkcode;
1889 =head2 TransformKohaToMarc
1893 $record = TransformKohaToMarc( $hash )
1894 This function builds partial MARC::Record from a hash
1895 Hash entries can be from biblio or biblioitems.
1896 This function is called in acquisition module, to create a basic catalogue entry from user entry
1902 sub TransformKohaToMarc {
1905 my $dbh = C4::Context->dbh;
1908 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
1910 my $record = MARC::Record->new();
1911 foreach (keys %{$hash}) {
1912 &TransformKohaToMarcOneField( $sth, $record, $_,
1918 =head2 TransformKohaToMarcOneField
1922 $record = TransformKohaToMarcOneField( $sth, $record, $kohafieldname, $value, $frameworkcode );
1928 sub TransformKohaToMarcOneField {
1929 my ( $sth, $record, $kohafieldname, $value, $frameworkcode ) = @_;
1930 $frameworkcode='' unless $frameworkcode;
1934 if ( !defined $sth ) {
1935 my $dbh = C4::Context->dbh;
1938 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
1941 $sth->execute( $frameworkcode, $kohafieldname );
1942 if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
1943 my $tag = $record->field($tagfield);
1945 $tag->update( $tagsubfield => $value );
1946 $record->delete_field($tag);
1947 $record->insert_fields_ordered($tag);
1950 $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
1956 =head2 TransformHtmlToXml
1960 $xml = TransformHtmlToXml( $tags, $subfields, $values, $indicator, $ind_tag )
1966 sub TransformHtmlToXml {
1967 my ( $tags, $subfields, $values, $indicator, $ind_tag ) = @_;
1968 my $xml = MARC::File::XML::header('UTF-8');
1969 if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
1970 MARC::File::XML->default_record_format('UNIMARC');
1971 use POSIX qw(strftime);
1972 my $string = strftime( "%Y%m%d", localtime(time) );
1973 $string = sprintf( "%-*s", 35, $string );
1974 substr( $string, 22, 6, "frey50" );
1975 $xml .= "<datafield tag=\"100\" ind1=\"\" ind2=\"\">\n";
1976 $xml .= "<subfield code=\"a\">$string</subfield>\n";
1977 $xml .= "</datafield>\n";
1983 for ( my $i = 0 ; $i <= @$tags ; $i++ ) {
1984 @$values[$i] =~ s/&/&/g;
1985 @$values[$i] =~ s/</</g;
1986 @$values[$i] =~ s/>/>/g;
1987 @$values[$i] =~ s/"/"/g;
1988 @$values[$i] =~ s/'/'/g;
1989 if ( !utf8::is_utf8( @$values[$i] ) ) {
1990 utf8::decode( @$values[$i] );
1992 if ( ( @$tags[$i] ne $prevtag ) ) {
1993 $j++ unless ( @$tags[$i] eq "" );
1995 $xml .= "</datafield>\n";
1996 if ( ( @$tags[$i] && @$tags[$i] > 10 )
1997 && ( @$values[$i] ne "" ) )
1999 my $ind1 = substr( @$indicator[$j], 0, 1 );
2001 if ( @$indicator[$j] ) {
2002 $ind2 = substr( @$indicator[$j], 1, 1 );
2005 warn "Indicator in @$tags[$i] is empty";
2009 "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
2011 "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2019 if ( @$values[$i] ne "" ) {
2022 if ( @$tags[$i] eq "000" ) {
2023 $xml .= "<leader>@$values[$i]</leader>\n";
2026 # rest of the fixed fields
2028 elsif ( @$tags[$i] < 10 ) {
2030 "<controlfield tag=\"@$tags[$i]\">@$values[$i]</controlfield>\n";
2034 my $ind1 = substr( @$indicator[$j], 0, 1 );
2035 my $ind2 = substr( @$indicator[$j], 1, 1 );
2037 "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
2039 "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2045 else { # @$tags[$i] eq $prevtag
2046 if ( @$values[$i] eq "" ) {
2050 my $ind1 = substr( @$indicator[$j], 0, 1 );
2051 my $ind2 = substr( @$indicator[$j], 1, 1 );
2053 "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
2057 "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2060 $prevtag = @$tags[$i];
2062 $xml .= MARC::File::XML::footer();
2067 =head2 TransformHtmlToMarc
2071 $record = TransformHtmlToMarc( $dbh, $rtags, $rsubfields, $rvalues, %indicators )
2077 sub TransformHtmlToMarc {
2078 my ( $dbh, $rtags, $rsubfields, $rvalues, %indicators ) = @_;
2080 my $record = MARC::Record->new();
2082 # my %subfieldlist=();
2083 my $prevvalue; # if tag <10
2084 my $field; # if tag >=10
2085 for ( my $i = 0 ; $i < @$rtags ; $i++ ) {
2086 next unless @$rvalues[$i];
2088 # rebuild MARC::Record
2089 # warn "0=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ";
2090 if ( @$rtags[$i] ne $prevtag ) {
2091 if ( $prevtag < 10 ) {
2094 if ( $prevtag ne '000' ) {
2095 $record->insert_fields_ordered(
2096 ( sprintf "%03s", $prevtag ), $prevvalue );
2100 $record->leader($prevvalue);
2107 $record->insert_fields_ordered($field);
2110 $indicators{ @$rtags[$i] } .= ' ';
2111 if ( @$rtags[$i] < 10 ) {
2112 $prevvalue = @$rvalues[$i];
2117 $field = MARC::Field->new(
2118 ( sprintf "%03s", @$rtags[$i] ),
2119 substr( $indicators{ @$rtags[$i] }, 0, 1 ),
2120 substr( $indicators{ @$rtags[$i] }, 1, 1 ),
2121 @$rsubfields[$i] => @$rvalues[$i]
2124 $prevtag = @$rtags[$i];
2127 if ( @$rtags[$i] < 10 ) {
2128 $prevvalue = @$rvalues[$i];
2131 if ( length( @$rvalues[$i] ) > 0 ) {
2132 $field->add_subfields( @$rsubfields[$i] => @$rvalues[$i] );
2135 $prevtag = @$rtags[$i];
2139 # the last has not been included inside the loop... do it now !
2140 $record->insert_fields_ordered($field) if $field;
2142 $record->encoding('UTF-8');
2144 # $record->MARC::File::USMARC::update_leader();
2148 =head2 TransformMarcToKoha
2152 $result = TransformMarcToKoha( $dbh, $record, $frameworkcode )
2158 sub TransformMarcToKoha {
2159 my ( $dbh, $record, $frameworkcode ) = @_;
2162 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
2165 my $sth2 = $dbh->prepare("SHOW COLUMNS from biblio");
2168 while ( ($field) = $sth2->fetchrow ) {
2170 &TransformMarcToKohaOneField( "biblio", $field, $record, $result,
2173 $sth2 = $dbh->prepare("SHOW COLUMNS from biblioitems");
2175 while ( ($field) = $sth2->fetchrow ) {
2176 if ( $field eq 'notes' ) { $field = 'bnotes'; }
2178 &TransformMarcToKohaOneField( "biblioitems", $field, $record, $result,
2181 $sth2 = $dbh->prepare("SHOW COLUMNS from items");
2183 while ( ($field) = $sth2->fetchrow ) {
2185 &TransformMarcToKohaOneField( "items", $field, $record, $result,
2190 # modify copyrightdate to keep only the 1st year found
2191 my $temp = $result->{'copyrightdate'};
2192 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
2194 $result->{'copyrightdate'} = $1;
2196 else { # if no cYYYY, get the 1st date.
2197 $temp =~ m/(\d\d\d\d)/;
2198 $result->{'copyrightdate'} = $1;
2201 # modify publicationyear to keep only the 1st year found
2202 $temp = $result->{'publicationyear'};
2203 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
2205 $result->{'publicationyear'} = $1;
2207 else { # if no cYYYY, get the 1st date.
2208 $temp =~ m/(\d\d\d\d)/;
2209 $result->{'publicationyear'} = $1;
2214 =head2 TransformMarcToKohaOneField
2218 $result = TransformMarcToKohaOneField( $kohatable, $kohafield, $record, $result, $frameworkcode )
2224 sub TransformMarcToKohaOneField {
2226 # FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
2227 my ( $kohatable, $kohafield, $record, $result, $frameworkcode ) = @_;
2230 my ( $tagfield, $subfield ) =
2231 GetMarcFromKohaField( $kohatable . "." . $kohafield,
2233 foreach my $field ( $record->field($tagfield) ) {
2234 if ( $field->tag() < 10 ) {
2235 if ( $result->{$kohafield} ) {
2236 $result->{$kohafield} .= " | " . $field->data();
2239 $result->{$kohafield} = $field->data();
2243 if ( $field->subfields ) {
2244 my @subfields = $field->subfields();
2245 foreach my $subfieldcount ( 0 .. $#subfields ) {
2246 if ( $subfields[$subfieldcount][0] eq $subfield ) {
2247 if ( $result->{$kohafield} ) {
2248 $result->{$kohafield} .=
2249 " | " . $subfields[$subfieldcount][1];
2252 $result->{$kohafield} =
2253 $subfields[$subfieldcount][1];
2262 =head1 OTHER FUNCTIONS
2268 my $string = char_decode( $string, $encoding );
2270 converts ISO 5426 coded string to UTF-8
2271 sloppy code : should be improved in next issue
2278 my ( $string, $encoding ) = @_;
2281 $encoding = C4::Context->preference("marcflavour") unless $encoding;
2282 if ( $encoding eq "UNIMARC" ) {
2352 # this handles non-sorting blocks (if implementation requires this)
2353 $string = nsb_clean($_);
2355 elsif ( $encoding eq "USMARC" || $encoding eq "MARC21" ) {
2414 #Additional Turkish characters
2417 s/(\xf0)s/\xc5\x9f/gm;
2418 s/(\xf0)S/\xc5\x9e/gm;
2421 s/\xe7\x49/\\xc4\xb0/gm;
2422 s/(\xe6)G/\xc4\x9e/gm;
2423 s/(\xe6)g/ğ\xc4\x9f/gm;
2426 s/(\xe8|\xc8)o/ö/gm;
2427 s/(\xe8|\xc8)O/Ö/gm;
2428 s/(\xe8|\xc8)u/ü/gm;
2429 s/(\xe8|\xc8)U/Ü/gm;
2430 s/\xc2\xb8/\xc4\xb1/gm;
2433 # this handles non-sorting blocks (if implementation requires this)
2434 $string = nsb_clean($_);
2443 my $string = nsb_clean( $string, $encoding );
2450 my $NSB = '\x88'; # NSB : begin Non Sorting Block
2451 my $NSE = '\x89'; # NSE : Non Sorting Block end
2452 # handles non sorting blocks
2456 s/[ ]{0,1}$NSE/) /gm;
2461 =head2 PrepareItemrecordDisplay
2465 PrepareItemrecordDisplay($itemrecord,$bibnum,$itemumber);
2467 Returns a hash with all the fields for Display a given item data in a template
2473 sub PrepareItemrecordDisplay {
2475 my ( $bibnum, $itemnum ) = @_;
2477 my $dbh = C4::Context->dbh;
2478 my $frameworkcode = &GetFrameworkCode( $bibnum );
2479 my ( $itemtagfield, $itemtagsubfield ) =
2480 &GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2481 my $tagslib = &GetMarcStructure( $dbh, 1, $frameworkcode );
2482 my $itemrecord = GetMarcItem( $bibnum, $itemnum) if ($itemnum);
2484 my $authorised_values_sth =
2486 "select authorised_value,lib from authorised_values where category=? order by lib"
2488 foreach my $tag ( sort keys %{$tagslib} ) {
2489 my $previous_tag = '';
2491 # loop through each subfield
2493 foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
2494 next if ( subfield_is_koha_internal_p($subfield) );
2495 next if ( $tagslib->{$tag}->{$subfield}->{'tab'} ne "10" );
2497 $subfield_data{tag} = $tag;
2498 $subfield_data{subfield} = $subfield;
2499 $subfield_data{countsubfield} = $cntsubf++;
2500 $subfield_data{kohafield} =
2501 $tagslib->{$tag}->{$subfield}->{'kohafield'};
2503 # $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
2504 $subfield_data{marc_lib} =
2505 "<span id=\"error\" title=\""
2506 . $tagslib->{$tag}->{$subfield}->{lib} . "\">"
2507 . substr( $tagslib->{$tag}->{$subfield}->{lib}, 0, 12 )
2509 $subfield_data{mandatory} =
2510 $tagslib->{$tag}->{$subfield}->{mandatory};
2511 $subfield_data{repeatable} =
2512 $tagslib->{$tag}->{$subfield}->{repeatable};
2513 $subfield_data{hidden} = "display:none"
2514 if $tagslib->{$tag}->{$subfield}->{hidden};
2516 ( $x, $value ) = _find_value( $tag, $subfield, $itemrecord )
2518 $value =~ s/"/"/g;
2520 # search for itemcallnumber if applicable
2521 if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
2522 'items.itemcallnumber'
2523 && C4::Context->preference('itemcallnumber') )
2526 substr( C4::Context->preference('itemcallnumber'), 0, 3 );
2528 substr( C4::Context->preference('itemcallnumber'), 3, 1 );
2529 my $temp = $itemrecord->field($CNtag) if ($itemrecord);
2531 $value = $temp->subfield($CNsubfield);
2534 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
2535 my @authorised_values;
2538 # builds list, depending on authorised value...
2540 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq
2543 if ( ( C4::Context->preference("IndependantBranches") )
2544 && ( C4::Context->userenv->{flags} != 1 ) )
2548 "select branchcode,branchname from branches where branchcode = ? order by branchname"
2550 $sth->execute( C4::Context->userenv->{branch} );
2551 push @authorised_values, ""
2553 $tagslib->{$tag}->{$subfield}->{mandatory} );
2554 while ( my ( $branchcode, $branchname ) =
2555 $sth->fetchrow_array )
2557 push @authorised_values, $branchcode;
2558 $authorised_lib{$branchcode} = $branchname;
2564 "select branchcode,branchname from branches order by branchname"
2567 push @authorised_values, ""
2569 $tagslib->{$tag}->{$subfield}->{mandatory} );
2570 while ( my ( $branchcode, $branchname ) =
2571 $sth->fetchrow_array )
2573 push @authorised_values, $branchcode;
2574 $authorised_lib{$branchcode} = $branchname;
2580 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq
2585 "select itemtype,description from itemtypes order by description"
2588 push @authorised_values, ""
2589 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2590 while ( my ( $itemtype, $description ) =
2591 $sth->fetchrow_array )
2593 push @authorised_values, $itemtype;
2594 $authorised_lib{$itemtype} = $description;
2597 #---- "true" authorised value
2600 $authorised_values_sth->execute(
2601 $tagslib->{$tag}->{$subfield}->{authorised_value} );
2602 push @authorised_values, ""
2603 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2604 while ( my ( $value, $lib ) =
2605 $authorised_values_sth->fetchrow_array )
2607 push @authorised_values, $value;
2608 $authorised_lib{$value} = $lib;
2611 $subfield_data{marc_value} = CGI::scrolling_list(
2612 -name => 'field_value',
2613 -values => \@authorised_values,
2614 -default => "$value",
2615 -labels => \%authorised_lib,
2621 elsif ( $tagslib->{$tag}->{$subfield}->{thesaurus_category} ) {
2622 $subfield_data{marc_value} =
2623 "<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>";
2626 # COMMENTED OUT because No $i is provided with this API.
2627 # And thus, no value_builder can be activated.
2628 # BUT could be thought over.
2629 # } elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
2630 # my $plugin="value_builder/".$tagslib->{$tag}->{$subfield}->{'value_builder'};
2632 # my $extended_param = plugin_parameters($dbh,$itemrecord,$tagslib,$i,0);
2633 # my ($function_name,$javascript) = plugin_javascript($dbh,$record,$tagslib,$i,0);
2634 # $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";
2637 $subfield_data{marc_value} =
2638 "<input type=\"text\" name=\"field_value\" value=\"$value\" size=50 maxlength=255>";
2640 push( @loop_data, \%subfield_data );
2644 my $itemnumber = $itemrecord->subfield( $itemtagfield, $itemtagsubfield )
2645 if ( $itemrecord && $itemrecord->field($itemtagfield) );
2647 'itemtagfield' => $itemtagfield,
2648 'itemtagsubfield' => $itemtagsubfield,
2649 'itemnumber' => $itemnumber,
2650 'iteminformation' => \@loop_data
2656 # true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates
2658 # replaced by a zebraqueue table, that is filled with ModZebra to run.
2659 # the table is emptied by misc/cronjobs/zebraqueue_start.pl script
2660 # =head2 ModZebrafiles
2662 # &ModZebrafiles( $dbh, $biblionumber, $record, $folder, $server );
2666 # sub ModZebrafiles {
2668 # my ( $dbh, $biblionumber, $record, $folder, $server ) = @_;
2672 # C4::Context->zebraconfig($server)->{directory} . "/" . $folder . "/";
2673 # unless ( opendir( DIR, "$zebradir" ) ) {
2674 # warn "$zebradir not found";
2678 # my $filename = $zebradir . $biblionumber;
2681 # open( OUTPUT, ">", $filename . ".xml" );
2682 # print OUTPUT $record;
2691 ModZebra( $dbh, $biblionumber, $op, $server );
2698 ###Accepts a $server variable thus we can use it for biblios authorities or other zebra dbs
2699 my ( $biblionumber, $op, $server ) = @_;
2700 my $dbh=C4::Context->dbh;
2701 #warn "SERVER:".$server;
2703 # true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates
2705 # replaced by a zebraqueue table, that is filled with ModZebra to run.
2706 # the table is emptied by misc/cronjobs/zebraqueue_start.pl script
2708 my $sth=$dbh->prepare("insert into zebraqueue (biblio_auth_number ,server,operation) values(?,?,?)");
2709 $sth->execute($biblionumber,$server,$op);
2716 # my $reconnect = 0;
2721 # $Zconnbiblio[0] = C4::Context->Zconn( $server, 0, 1 );
2723 # if ( $server eq "biblioserver" ) {
2725 # # it's unclear to me whether this should be in xml or MARC format
2726 # # but it is clear it should be nabbed from zebra rather than from
2728 # $record = GetMarcBiblio($biblionumber);
2729 # $record = $record->as_xml_record() if $record;
2730 # # warn "RECORD $biblionumber => ".$record;
2731 # $shadow="biblioservershadow";
2733 # # warn "RECORD $biblionumber => ".$record;
2734 # $shadow = "biblioservershadow";
2737 # elsif ( $server eq "authorityserver" ) {
2738 # $record = C4::AuthoritiesMarc::XMLgetauthority( $dbh, $biblionumber );
2739 # $shadow = "authorityservershadow";
2740 # } ## Add other servers as necessary
2742 # my $Zpackage = $Zconnbiblio[0]->package();
2743 # $Zpackage->option( action => $op );
2744 # $Zpackage->option( record => $record );
2747 # $Zpackage->send("update");
2751 # while ( ( $i = ZOOM::event( \@Zconnbiblio ) ) != 0 ) {
2752 # $event = $Zconnbiblio[0]->last_event();
2753 # last if $event == ZOOM::Event::ZEND;
2756 # my ( $error, $errmsg, $addinfo, $diagset ) = $Zconnbiblio[0]->error_x();
2757 # if ( $error == 10000 && $reconnect == 0 )
2758 # { ## This is serious ZEBRA server is not available -reconnect
2759 # warn "problem with zebra server connection";
2761 # my $res = system('sc start "Z39.50 Server" >c:/zebraserver/error.log');
2763 # #warn "Trying to restart ZEBRA Server";
2764 # #goto "reconnect";
2766 # elsif ( $error == 10007 && $tried < 2 )
2767 # { ## timeout --another 30 looonng seconds for this update
2768 # $tried = $tried + 1;
2769 # warn "warn: timeout, trying again";
2772 # elsif ( $error == 10004 && $recon == 0 ) { ##Lost connection -reconnect
2774 # warn "error: reconnecting to zebra";
2777 # # as a last resort, we save the data to the filesystem to be indexed in batch
2781 # "Error-$server $op $biblionumber /errcode:, $error, /MSG:,$errmsg,$addinfo \n";
2782 # $Zpackage->destroy();
2783 # $Zconnbiblio[0]->destroy();
2784 # ModZebrafiles( $dbh, $biblionumber, $record, $op, $server );
2787 # if ( C4::Context->$shadow ) {
2788 # $Zpackage->send('commit');
2789 # while ( ( $i = ZOOM::event( \@Zconnbiblio ) ) != 0 ) {
2791 # #waiting zebra to finish;
2794 # $Zpackage->destroy();
2797 =head1 INTERNAL FUNCTIONS
2799 =head2 MARCitemchange
2803 &MARCitemchange( $record, $itemfield, $newvalue )
2805 Function to update a single value in an item field.
2806 Used twice, could probably be replaced by something else, but works well...
2814 sub MARCitemchange {
2815 my ( $record, $itemfield, $newvalue ) = @_;
2816 my $dbh = C4::Context->dbh;
2818 my ( $tagfield, $tagsubfield ) =
2819 GetMarcFromKohaField( $itemfield, "" );
2820 if ( ($tagfield) && ($tagsubfield) ) {
2821 my $tag = $record->field($tagfield);
2823 $tag->update( $tagsubfield => $newvalue );
2824 $record->delete_field($tag);
2825 $record->insert_fields_ordered($tag);
2830 =head2 _koha_add_biblio
2834 _koha_add_biblio($dbh,$biblioitem);
2836 Internal function to add a biblio ($biblio is a hash with the values)
2842 sub _koha_add_biblio {
2843 my ( $dbh, $biblio, $frameworkcode ) = @_;
2844 my $sth = $dbh->prepare("Select max(biblionumber) from biblio");
2846 my $data = $sth->fetchrow_arrayref;
2847 my $biblionumber = $$data[0] + 1;
2850 if ( $biblio->{'seriestitle'} ) { $series = 1 }
2852 $sth = $dbh->prepare(
2854 SET biblionumber = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?, unititle = ?, frameworkcode = ? "
2857 $biblionumber, $biblio->{'title'},
2858 $biblio->{'author'}, $biblio->{'copyrightdate'},
2859 $biblio->{'serial'}, $biblio->{'seriestitle'},
2860 $biblio->{'notes'}, $biblio->{'abstract'},
2861 $biblio->{'unititle'}, $frameworkcode
2865 return ($biblionumber);
2872 ($indicators, $value) = _find_value($tag, $subfield, $record,$encoding);
2874 Find the given $subfield in the given $tag in the given
2875 MARC::Record $record. If the subfield is found, returns
2876 the (indicators, value) pair; otherwise, (undef, undef) is
2880 Such a function is used in addbiblio AND additem and serial-edit and maybe could be used in Authorities.
2881 I suggest we export it from this module.
2888 my ( $tagfield, $insubfield, $record, $encoding ) = @_;
2891 if ( $tagfield < 10 ) {
2892 if ( $record->field($tagfield) ) {
2893 push @result, $record->field($tagfield)->data();
2900 foreach my $field ( $record->field($tagfield) ) {
2901 my @subfields = $field->subfields();
2902 foreach my $subfield (@subfields) {
2903 if ( @$subfield[0] eq $insubfield ) {
2904 push @result, @$subfield[1];
2905 $indicator = $field->indicator(1) . $field->indicator(2);
2910 return ( $indicator, @result );
2913 =head2 _koha_modify_biblio
2917 Internal function for updating the biblio table
2923 sub _koha_modify_biblio {
2924 my ( $dbh, $biblio ) = @_;
2926 # FIXME: this code could be made more portable by not hard-coding the values that are supposed to be in biblio table
2929 "Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?, seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?"
2932 $biblio->{'title'}, $biblio->{'author'},
2933 $biblio->{'abstract'}, $biblio->{'copyrightdate'},
2934 $biblio->{'seriestitle'}, $biblio->{'serial'},
2935 $biblio->{'unititle'}, $biblio->{'notes'},
2936 $biblio->{'biblionumber'}
2939 return ( $biblio->{'biblionumber'} );
2942 =head2 _koha_modify_biblioitem
2946 _koha_modify_biblioitem( $dbh, $biblioitem );
2952 sub _koha_modify_biblioitem {
2953 my ( $dbh, $biblioitem ) = @_;
2955 ##Recalculate LC in case it changed --TG
2957 $biblioitem->{'itemtype'} = $dbh->quote( $biblioitem->{'itemtype'} );
2958 $biblioitem->{'url'} = $dbh->quote( $biblioitem->{'url'} );
2959 $biblioitem->{'isbn'} = $dbh->quote( $biblioitem->{'isbn'} );
2960 $biblioitem->{'issn'} = $dbh->quote( $biblioitem->{'issn'} );
2961 $biblioitem->{'publishercode'} =
2962 $dbh->quote( $biblioitem->{'publishercode'} );
2963 $biblioitem->{'publicationyear'} =
2964 $dbh->quote( $biblioitem->{'publicationyear'} );
2965 $biblioitem->{'classification'} =
2966 $dbh->quote( $biblioitem->{'classification'} );
2967 $biblioitem->{'dewey'} = $dbh->quote( $biblioitem->{'dewey'} );
2968 $biblioitem->{'subclass'} = $dbh->quote( $biblioitem->{'subclass'} );
2969 $biblioitem->{'illus'} = $dbh->quote( $biblioitem->{'illus'} );
2970 $biblioitem->{'pages'} = $dbh->quote( $biblioitem->{'pages'} );
2971 $biblioitem->{'volumeddesc'} = $dbh->quote( $biblioitem->{'volumeddesc'} );
2972 $biblioitem->{'bnotes'} = $dbh->quote( $biblioitem->{'bnotes'} );
2973 $biblioitem->{'size'} = $dbh->quote( $biblioitem->{'size'} );
2974 $biblioitem->{'place'} = $dbh->quote( $biblioitem->{'place'} );
2975 $biblioitem->{'ccode'} = $dbh->quote( $biblioitem->{'ccode'} );
2976 $biblioitem->{'biblionumber'} =
2977 $dbh->quote( $biblioitem->{'biblionumber'} );
2979 $query = "Update biblioitems set
2980 itemtype = $biblioitem->{'itemtype'},
2981 url = $biblioitem->{'url'},
2982 isbn = $biblioitem->{'isbn'},
2983 issn = $biblioitem->{'issn'},
2984 publishercode = $biblioitem->{'publishercode'},
2985 publicationyear = $biblioitem->{'publicationyear'},
2986 classification = $biblioitem->{'classification'},
2987 dewey = $biblioitem->{'dewey'},
2988 subclass = $biblioitem->{'subclass'},
2989 illus = $biblioitem->{'illus'},
2990 pages = $biblioitem->{'pages'},
2991 volumeddesc = $biblioitem->{'volumeddesc'},
2992 notes = $biblioitem->{'bnotes'},
2993 size = $biblioitem->{'size'},
2994 place = $biblioitem->{'place'},
2995 ccode = $biblioitem->{'ccode'}
2996 where biblionumber = $biblioitem->{'biblionumber'}";
2999 if ( $dbh->errstr ) {
3004 =head2 _koha_add_biblioitem
3008 _koha_add_biblioitem( $dbh, $biblioitem );
3010 Internal function to add a biblioitem
3016 sub _koha_add_biblioitem {
3017 my ( $dbh, $biblioitem ) = @_;
3019 # my $dbh = C4Connect;
3020 my $sth = $dbh->prepare("SELECT max(biblioitemnumber) FROM biblioitems");
3025 $data = $sth->fetchrow_arrayref;
3026 $bibitemnum = $$data[0] + 1;
3030 $sth = $dbh->prepare(
3031 "INSERT INTO biblioitems SET
3032 biblioitemnumber = ?, biblionumber = ?,
3033 volume = ?, number = ?,
3034 classification = ?, itemtype = ?,
3036 issn = ?, dewey = ?,
3037 subclass = ?, publicationyear = ?,
3038 publishercode = ?, volumedate = ?,
3039 volumeddesc = ?, illus = ?,
3040 pages = ?, notes = ?,
3042 marc = ?, lcsort =?,
3043 place = ?, ccode = ?
3047 calculatelc( $biblioitem->{'classification'} )
3048 . $biblioitem->{'subclass'};
3050 $bibitemnum, $biblioitem->{'biblionumber'},
3051 $biblioitem->{'volume'}, $biblioitem->{'number'},
3052 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
3053 $biblioitem->{'url'}, $biblioitem->{'isbn'},
3054 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
3055 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
3056 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
3057 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
3058 $biblioitem->{'pages'}, $biblioitem->{'bnotes'},
3059 $biblioitem->{'size'}, $biblioitem->{'lccn'},
3060 $biblioitem->{'marc'}, $biblioitem->{'place'},
3061 $lcsort, $biblioitem->{'ccode'}
3064 return ($bibitemnum);
3067 =head2 _koha_new_items
3071 _koha_new_items( $dbh, $item, $barcode );
3077 sub _koha_new_items {
3078 my ( $dbh, $item, $barcode ) = @_;
3080 # my $dbh = C4Connect;
3081 my $sth = $dbh->prepare("Select max(itemnumber) from items");
3087 $data = $sth->fetchrow_hashref;
3088 $itemnumber = $data->{'max(itemnumber)'} + 1;
3090 ## Now calculate lccalnumber
3091 my ($cutterextra) = itemcalculator(
3093 $item->{'biblioitemnumber'},
3094 $item->{'itemcallnumber'}
3097 # FIXME the "notforloan" field seems to be named "loan" in some places. workaround bugfix.
3098 if ( $item->{'loan'} ) {
3099 $item->{'notforloan'} = $item->{'loan'};
3102 # if dateaccessioned is provided, use it. Otherwise, set to NOW()
3103 if ( $item->{'dateaccessioned'} eq '' || !$item->{'dateaccessioned'} ) {
3105 $sth = $dbh->prepare(
3106 "Insert into items set
3107 itemnumber = ?, biblionumber = ?,
3108 multivolumepart = ?,
3109 biblioitemnumber = ?, barcode = ?,
3110 booksellerid = ?, dateaccessioned = NOW(),
3111 homebranch = ?, holdingbranch = ?,
3112 price = ?, replacementprice = ?,
3113 replacementpricedate = NOW(), datelastseen = NOW(),
3114 multivolume = ?, stack = ?,
3115 itemlost = ?, wthdrawn = ?,
3116 paidfor = ?, itemnotes = ?,
3117 itemcallnumber =?, notforloan = ?,
3118 location = ?, Cutterextra = ?
3122 $itemnumber, $item->{'biblionumber'},
3123 $item->{'multivolumepart'}, $item->{'biblioitemnumber'},
3124 $barcode, $item->{'booksellerid'},
3125 $item->{'homebranch'}, $item->{'holdingbranch'},
3126 $item->{'price'}, $item->{'replacementprice'},
3127 $item->{multivolume}, $item->{stack},
3128 $item->{itemlost}, $item->{wthdrawn},
3129 $item->{paidfor}, $item->{'itemnotes'},
3130 $item->{'itemcallnumber'}, $item->{'notforloan'},
3131 $item->{'location'}, $cutterextra
3135 $sth = $dbh->prepare(
3136 "INSERT INTO items SET
3137 itemnumber = ?, biblionumber = ?,
3138 multivolumepart = ?,
3139 biblioitemnumber = ?, barcode = ?,
3140 booksellerid = ?, dateaccessioned = ?,
3141 homebranch = ?, holdingbranch = ?,
3142 price = ?, replacementprice = ?,
3143 replacementpricedate = NOW(), datelastseen = NOW(),
3144 multivolume = ?, stack = ?,
3145 itemlost = ?, wthdrawn = ?,
3146 paidfor = ?, itemnotes = ?,
3147 itemcallnumber = ?, notforloan = ?,
3153 $itemnumber, $item->{'biblionumber'},
3154 $item->{'multivolumepart'}, $item->{'biblioitemnumber'},
3155 $barcode, $item->{'booksellerid'},
3156 $item->{'dateaccessioned'}, $item->{'homebranch'},
3157 $item->{'holdingbranch'}, $item->{'price'},
3158 $item->{'replacementprice'}, $item->{multivolume},
3159 $item->{stack}, $item->{itemlost},
3160 $item->{wthdrawn}, $item->{paidfor},
3161 $item->{'itemnotes'}, $item->{'itemcallnumber'},
3162 $item->{'notforloan'}, $item->{'location'},
3166 if ( defined $sth->errstr ) {
3167 $error .= $sth->errstr;
3169 return ( $itemnumber, $error );
3172 =head2 _koha_modify_item
3176 _koha_modify_item( $dbh, $item, $op );
3182 sub _koha_modify_item {
3183 my ( $dbh, $item, $op ) = @_;
3184 $item->{'itemnum'} = $item->{'itemnumber'} unless $item->{'itemnum'};
3186 # if all we're doing is setting statuses, just update those and get out
3187 if ( $op eq "setstatus" ) {
3189 "UPDATE items SET itemlost=?,wthdrawn=?,binding=? WHERE itemnumber=?";
3191 $item->{'itemlost'}, $item->{'wthdrawn'},
3192 $item->{'binding'}, $item->{'itemnumber'}
3194 my $sth = $dbh->prepare($query);
3195 $sth->execute(@bind);
3199 ## Now calculate lccalnumber
3201 itemcalculator( $dbh, $item->{'bibitemnum'}, $item->{'itemcallnumber'} );
3203 my $query = "UPDATE items SET
3204 barcode=?,itemnotes=?,itemcallnumber=?,notforloan=?,location=?,multivolumepart=?,multivolume=?,stack=?,wthdrawn=?,holdingbranch=?,homebranch=?,cutterextra=?, onloan=?, binding=?";
3207 $item->{'barcode'}, $item->{'notes'},
3208 $item->{'itemcallnumber'}, $item->{'notforloan'},
3209 $item->{'location'}, $item->{multivolumepart},
3210 $item->{multivolume}, $item->{stack},
3211 $item->{wthdrawn}, $item->{holdingbranch},
3212 $item->{homebranch}, $cutterextra,
3213 $item->{onloan}, $item->{binding}
3215 if ( $item->{'lost'} ne '' ) {
3217 "update items set biblioitemnumber=?,barcode=?,itemnotes=?,homebranch=?,
3218 itemlost=?,wthdrawn=?,itemcallnumber=?,notforloan=?,
3219 location=?,multivolumepart=?,multivolume=?,stack=?,wthdrawn=?,holdingbranch=?,cutterextra=?,onloan=?, binding=?";
3221 $item->{'bibitemnum'}, $item->{'barcode'},
3222 $item->{'notes'}, $item->{'homebranch'},
3223 $item->{'lost'}, $item->{'wthdrawn'},
3224 $item->{'itemcallnumber'}, $item->{'notforloan'},
3225 $item->{'location'}, $item->{multivolumepart},
3226 $item->{multivolume}, $item->{stack},
3227 $item->{wthdrawn}, $item->{holdingbranch},
3228 $cutterextra, $item->{onloan},
3231 if ( $item->{homebranch} ) {
3232 $query .= ",homebranch=?";
3233 push @bind, $item->{homebranch};
3235 if ( $item->{holdingbranch} ) {
3236 $query .= ",holdingbranch=?";
3237 push @bind, $item->{holdingbranch};
3240 $query .= " where itemnumber=?";
3241 push @bind, $item->{'itemnum'};
3242 if ( $item->{'replacement'} ne '' ) {
3243 $query =~ s/ where/,replacementprice='$item->{'replacement'}' where/;
3245 my $sth = $dbh->prepare($query);
3246 $sth->execute(@bind);
3250 =head2 _koha_delete_biblio
3254 $error = _koha_delete_biblio($dbh,$biblionumber);
3256 Internal sub for deleting from biblio table -- also saves to deletedbiblio
3258 C<$dbh> - the database handle
3259 C<$biblionumber> - the biblionumber of the biblio to be deleted
3265 # FIXME: add error handling
3267 sub _koha_delete_biblio {
3268 my ( $dbh, $biblionumber ) = @_;
3270 # get all the data for this biblio
3271 my $sth = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber=?");
3272 $sth->execute($biblionumber);
3274 if ( my $data = $sth->fetchrow_hashref ) {
3276 # save the record in deletedbiblio
3277 # find the fields to save
3278 my $query = "INSERT INTO deletedbiblio SET ";
3280 foreach my $temp ( keys %$data ) {
3281 $query .= "$temp = ?,";
3282 push( @bind, $data->{$temp} );
3285 # replace the last , by ",?)"
3287 my $bkup_sth = $dbh->prepare($query);
3288 $bkup_sth->execute(@bind);
3292 my $del_sth = $dbh->prepare("DELETE FROM biblio WHERE biblionumber=?");
3293 $del_sth->execute($biblionumber);
3300 =head2 _koha_delete_biblioitems
3304 $error = _koha_delete_biblioitems($dbh,$biblioitemnumber);
3306 Internal sub for deleting from biblioitems table -- also saves to deletedbiblioitems
3308 C<$dbh> - the database handle
3309 C<$biblionumber> - the biblioitemnumber of the biblioitem to be deleted
3315 # FIXME: add error handling
3317 sub _koha_delete_biblioitems {
3318 my ( $dbh, $biblioitemnumber ) = @_;
3320 # get all the data for this biblioitem
3322 $dbh->prepare("SELECT * FROM biblioitems WHERE biblioitemnumber=?");
3323 $sth->execute($biblioitemnumber);
3325 if ( my $data = $sth->fetchrow_hashref ) {
3327 # save the record in deletedbiblioitems
3328 # find the fields to save
3329 my $query = "INSERT INTO deletedbiblioitems SET ";
3331 foreach my $temp ( keys %$data ) {
3332 $query .= "$temp = ?,";
3333 push( @bind, $data->{$temp} );
3336 # replace the last , by ",?)"
3338 my $bkup_sth = $dbh->prepare($query);
3339 $bkup_sth->execute(@bind);
3342 # delete the biblioitem
3344 $dbh->prepare("DELETE FROM biblioitems WHERE biblioitemnumber=?");
3345 $del_sth->execute($biblioitemnumber);
3352 =head2 _koha_delete_item
3356 _koha_delete_item( $dbh, $itemnum );
3358 Internal function to delete an item record from the koha tables
3364 sub _koha_delete_item {
3365 my ( $dbh, $itemnum ) = @_;
3367 my $sth = $dbh->prepare("select * from items where itemnumber=?");
3368 $sth->execute($itemnum);
3369 my $data = $sth->fetchrow_hashref;
3371 my $query = "Insert into deleteditems set ";
3373 foreach my $temp ( keys %$data ) {
3374 $query .= "$temp = ?,";
3375 push( @bind, $data->{$temp} );
3380 $sth = $dbh->prepare($query);
3381 $sth->execute(@bind);
3383 $sth = $dbh->prepare("Delete from items where itemnumber=?");
3384 $sth->execute($itemnum);
3388 =head1 UNEXPORTED FUNCTIONS
3394 $lc = calculatelc($classification);
3401 my ($classification) = @_;
3402 $classification =~ s/^\s+|\s+$//g;
3407 for ( $i = 0 ; $i < length($classification) ; $i++ ) {
3408 my $c = ( substr( $classification, $i, 1 ) );
3409 if ( $c ge '0' && $c le '9' ) {
3411 $lc2 = substr( $classification, $i );
3415 $lc1 .= substr( $classification, $i, 1 );
3420 my $other = length($lc1);
3427 for ( 1 .. ( 4 - $other ) ) {
3436 ##Find the decimal part of $lc2
3437 my $pos = index( $lc2, "." );
3438 if ( $pos < 0 ) { $pos = length($lc2); }
3439 if ( $pos >= 0 && $pos < 5 ) {
3440 ##Pad lc2 with zeros to create a 5digit decimal needed in marc record to sort as numeric
3442 for ( 1 .. ( 5 - $pos ) ) {
3446 $lc2 = $extras . $lc2;
3447 return ( $lc1 . $lc2 );
3450 =head2 itemcalculator
3454 $cutterextra = itemcalculator( $dbh, $biblioitem, $callnumber );
3460 sub itemcalculator {
3461 my ( $dbh, $biblioitem, $callnumber ) = @_;
3464 "select classification, subclass from biblioitems where biblioitemnumber=?"
3467 $sth->execute($biblioitem);
3468 my ( $classification, $subclass ) = $sth->fetchrow;
3469 my $all = $classification . " " . $subclass;
3470 my $total = length($all);
3471 my $cutterextra = substr( $callnumber, $total - 1 );
3473 return $cutterextra;
3476 =head2 ModBiblioMarc
3480 &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
3482 Add MARC data for a biblio to koha
3484 Function exported, but should NOT be used, unless you really know what you're doing
3492 # pass the MARC::Record to this function, and it will create the records in the marc tables
3493 my ( $record, $biblionumber, $frameworkcode ) = @_;
3494 my $dbh = C4::Context->dbh;
3495 my @fields = $record->fields();
3496 if ( !$frameworkcode ) {
3497 $frameworkcode = "";
3500 $dbh->prepare("UPDATE biblio SET frameworkcode=? WHERE biblionumber=?");
3501 $sth->execute( $frameworkcode, $biblionumber );
3503 my $encoding = C4::Context->preference("marcflavour");
3505 # deal with UNIMARC field 100 (encoding) : create it if needed & set encoding to unicode
3506 if ( $encoding eq "UNIMARC" ) {
3508 if ( $record->subfield( 100, "a" ) ) {
3509 $string = $record->subfield( 100, "a" );
3510 my $f100 = $record->field(100);
3511 $record->delete_field($f100);
3514 $string = POSIX::strftime( "%Y%m%d", localtime );
3516 $string = sprintf( "%-*s", 35, $string );
3518 substr( $string, 22, 6, "frey50" );
3519 unless ( $record->subfield( 100, "a" ) ) {
3520 $record->insert_grouped_field(
3521 MARC::Field->new( 100, "", "", "a" => $string ) );
3524 # warn "biblionumber : ".$biblionumber;
3527 "update biblioitems set marc=?,marcxml=? where biblionumber=?");
3528 $sth->execute( $record->as_usmarc(), $record->as_xml_record(),
3530 # warn $record->as_xml_record();
3532 ModZebra($biblionumber,"specialUpdate","biblioserver");
3533 return $biblionumber;
3536 =head2 AddItemInMarc
3540 $newbiblionumber = AddItemInMarc( $record, $biblionumber, $frameworkcode );
3542 Add an item in a MARC record and save the MARC record
3544 Function exported, but should NOT be used, unless you really know what you're doing
3552 # pass the MARC::Record to this function, and it will create the records in the marc tables
3553 my ( $record, $biblionumber, $frameworkcode ) = @_;
3554 my $newrec = &GetMarcBiblio($biblionumber);
3557 my @fields = $record->fields();
3558 foreach my $field (@fields) {
3559 $newrec->append_fields($field);
3562 # FIXME: should we be making sure the biblionumbers are the same?
3563 my $newbiblionumber =
3564 &ModBiblioMarc( $newrec, $biblionumber, $frameworkcode );
3565 return $newbiblionumber;
3568 =head2 z3950_extended_services
3570 z3950_extended_services($serviceType,$serviceOptions,$record);
3572 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.
3574 C<$serviceType> one of: itemorder,create,drop,commit,update,xmlupdate
3576 C<$serviceOptions> a has of key/value pairs. For instance, if service_type is 'update', $service_options should contain:
3578 action => update action, one of specialUpdate, recordInsert, recordReplace, recordDelete, elementUpdate.
3582 recordidOpaque => Opaque Record ID (user supplied) or recordidNumber => Record ID number (system number).
3583 syntax => the record syntax (transfer syntax)
3584 databaseName = Database from connection object
3586 To set serviceOptions, call set_service_options($serviceType)
3588 C<$record> the record, if one is needed for the service type
3590 A record should be in XML. You can convert it to XML from MARC by running it through marc2xml().
3594 sub z3950_extended_services {
3595 my ( $server, $serviceType, $action, $serviceOptions ) = @_;
3597 # get our connection object
3598 my $Zconn = C4::Context->Zconn( $server, 0, 1 );
3600 # create a new package object
3601 my $Zpackage = $Zconn->package();
3604 $Zpackage->option( action => $action );
3606 if ( $serviceOptions->{'databaseName'} ) {
3607 $Zpackage->option( databaseName => $serviceOptions->{'databaseName'} );
3609 if ( $serviceOptions->{'recordIdNumber'} ) {
3611 recordIdNumber => $serviceOptions->{'recordIdNumber'} );
3613 if ( $serviceOptions->{'recordIdOpaque'} ) {
3615 recordIdOpaque => $serviceOptions->{'recordIdOpaque'} );
3618 # this is an ILL request (Zebra doesn't support it, but Koha could eventually)
3619 #if ($serviceType eq 'itemorder') {
3620 # $Zpackage->option('contact-name' => $serviceOptions->{'contact-name'});
3621 # $Zpackage->option('contact-phone' => $serviceOptions->{'contact-phone'});
3622 # $Zpackage->option('contact-email' => $serviceOptions->{'contact-email'});
3623 # $Zpackage->option('itemorder-item' => $serviceOptions->{'itemorder-item'});
3626 if ( $serviceOptions->{record} ) {
3627 $Zpackage->option( record => $serviceOptions->{record} );
3629 # can be xml or marc
3630 if ( $serviceOptions->{'syntax'} ) {
3631 $Zpackage->option( syntax => $serviceOptions->{'syntax'} );
3635 # send the request, handle any exception encountered
3636 eval { $Zpackage->send($serviceType) };
3637 if ( $@ && $@->isa("ZOOM::Exception") ) {
3638 return "error: " . $@->code() . " " . $@->message() . "\n";
3641 # free up package resources
3642 $Zpackage->destroy();
3645 =head2 set_service_options
3647 my $serviceOptions = set_service_options($serviceType);
3649 C<$serviceType> itemorder,create,drop,commit,update,xmlupdate
3651 Currently, we only support 'create', 'commit', and 'update'. 'drop' support will be added as soon as Zebra supports it.
3655 sub set_service_options {
3656 my ($serviceType) = @_;
3659 # FIXME: This needs to be an OID ... if we ever need 'syntax' this sub will need to change
3660 # $serviceOptions->{ 'syntax' } = ''; #zebra doesn't support syntaxes other than xml
3662 if ( $serviceType eq 'commit' ) {
3666 if ( $serviceType eq 'create' ) {
3670 if ( $serviceType eq 'drop' ) {
3671 die "ERROR: 'drop' not currently supported (by Zebra)";
3673 return $serviceOptions;
3676 END { } # module clean-up code here (global destructor)
3684 Koha Developement team <info@koha.org>
3686 Paul POULAIN paul.poulain@free.fr
3688 Joshua Ferraro jmf@liblime.com
3694 # Revision 1.201 2007/04/27 14:00:49 hdl
3695 # Removing $dbh from GetMarcFromKohaField (dbh is not used in this function.)
3697 # Revision 1.200 2007/04/25 16:26:42 tipaul
3698 # Koha 3.0 nozebra 1st commit : the script misc/migration_tools/rebuild_nozebra.pl build the nozebra table, and, if you set NoZebra to Yes, queries will be done through zebra. TODO :
3699 # - add nozebra table management on biblio editing
3700 # - the index table content is hardcoded. I still have to add some specific systempref to let the library update it
3701 # - manage pagination (next/previous)
3704 # - NZgetRecords : has exactly the same API & returns as zebra getQuery, except that some parameters are unused
3705 # - search & sort works quite good
3706 # - CQL parser is better that what I thought I could do : title="harry and sally" and publicationyear>2000 not itemtype=LIVR should work fine
3708 # Revision 1.199 2007/04/24 09:07:53 tipaul
3709 # moving dotransfer to Biblio.pm::ModItemTransfer + some CheckReserves fixes
3711 # Revision 1.198 2007/04/23 15:21:17 tipaul
3712 # renaming currenttransfers to transferstoreceive
3714 # Revision 1.197 2007/04/18 17:00:14 tipaul
3715 # removing all useless %env / $env
3717 # Revision 1.196 2007/04/17 08:48:00 tipaul
3718 # circulation cleaning continued: bufixing
3720 # Revision 1.195 2007/04/04 16:46:22 tipaul
3721 # HUGE COMMIT : code cleaning circulation.
3723 # some stuff to do, i'll write a mail on koha-devel NOW !
3725 # Revision 1.194 2007/03/30 12:00:42 tipaul
3726 # why the hell do we need to explicitly utf8 decode this string ? I really don't know, but it seems it's mandatory, otherwise, tag descriptions are not properly encoded...
3728 # Revision 1.193 2007/03/29 16:45:53 tipaul
3729 # Code cleaning of Biblio.pm (continued)
3731 # All subs have be cleaned :
3734 # - reordering Biblio.pm completly
3735 # - using only naming conventions
3737 # Seems to have broken nothing, but it still has to be heavily tested.
3738 # Note that Biblio.pm is now much more efficient than previously & probably more reliable as well.
3740 # Revision 1.192 2007/03/29 13:30:31 tipaul
3742 # == Biblio.pm cleaning (useless) ==
3743 # * some sub declaration dropped
3744 # * removed modbiblio sub
3745 # * removed moditem sub
3746 # * removed newitems. It was used only in finishrecieve. Replaced by a TransformKohaToMarc+AddItem, that is better.
3747 # * removed MARCkoha2marcItem
3748 # * removed MARCdelsubfield declaration
3749 # * removed MARCkoha2marcBiblio
3751 # == Biblio.pm cleaning (naming conventions) ==
3752 # * MARCgettagslib renamed to GetMarcStructure
3753 # * MARCgetitems renamed to GetMarcItem
3754 # * MARCfind_frameworkcode renamed to GetFrameworkCode
3755 # * MARCmarc2koha renamed to TransformMarcToKoha
3756 # * MARChtml2marc renamed to TransformHtmlToMarc
3757 # * MARChtml2xml renamed to TranformeHtmlToXml
3758 # * zebraop renamed to ModZebra
3761 # * removing MARC=OFF related scripts (in cataloguing directory)
3762 # * removed checkitems (function related to MARC=off feature, that is completly broken in head. If someone want to reintroduce it, hard work coming...)
3763 # * removed getitemsbybiblioitem (used only by MARC=OFF scripts, that is removed as well)
3765 # Revision 1.191 2007/03/29 09:42:13 tipaul
3766 # adding default value new feature into cataloguing. The system (definition) part has already been added by toins
3768 # Revision 1.190 2007/03/29 08:45:19 hdl
3769 # Deleting ignore_errors(1) pour MARC::Charset
3771 # Revision 1.189 2007/03/28 10:39:16 hdl
3772 # removing $dbh as a parameter in AuthoritiesMarc functions
3773 # And reporting all differences into the scripts taht relies on those functions.