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::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
71 &GetItemsByBiblioitemnumber
72 &GetItemnumberFromBarcode
76 &GetAuthorisedValueDesc
80 &GetPublisherNameFromIsbn
92 &ModItemInMarconefield
103 # those functions are exported but should not be used
104 # they are usefull is few circumstances, so are exported.
105 # but don't use them unless you're a core developer ;-)
116 &TransformHtmlToMarc2
119 &PrepareItemrecordDisplay
126 C4::Biblio - cataloging management functions
130 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:
134 =item 1. in the biblio,biblioitems,items, etc tables, which are limited to a one-to-one mapping to underlying MARC data
136 =item 2. as raw MARC in the Zebra index and storage engine
138 =item 3. as raw MARC the biblioitems.marc and biblioitems.marcxml
142 In the 3.0 version of Koha, the authoritative record-level information is in biblioitems.marcxml
144 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.
148 =item 1. Compared with MySQL, Zebra is slow to update an index for small data changes -- especially for proc-intensive operations like circulation
150 =item 2. Zebra's index has been known to crash and a backup of the data is necessary to rebuild it in such cases
154 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:
158 =item 1. Add*/Mod*/Del*/ - high-level external functions suitable for being called from external scripts to manage the collection
160 =item 2. _koha_* - low-level internal functions for managing the koha tables
162 =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.
164 =item 4. Zebra functions used to update the Zebra index
166 =item 5. internal helper functions such as char_decode, checkitems, etc. Some of these probably belong in Koha.pm
170 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 :
174 =item 1. save datas in biblio and biblioitems table, that gives us a biblionumber and a biblioitemnumber
176 =item 2. add the biblionumber and biblioitemnumber into the MARC records
178 =item 3. save the marc record
182 When dealing with items, we must :
186 =item 1. save the item in items table, that gives us an itemnumber
188 =item 2. add the itemnumber to the item MARC field
190 =item 3. overwrite the MARC record (with the added item) into biblioitems.marc(xml)
192 When modifying a biblio or an item, the behaviour is quite similar.
196 =head1 EXPORTED FUNCTIONS
202 ($biblionumber,$biblioitemnumber) = AddBiblio($record,$frameworkcode);
203 Exported function (core API) for adding a new biblio to koha.
210 my ( $record, $frameworkcode ) = @_;
212 my $biblioitemnumber;
213 my $dbh = C4::Context->dbh;
214 # transform the data into koha-table style data
215 my $olddata = TransformMarcToKoha( $dbh, $record, $frameworkcode );
216 $biblionumber = _koha_add_biblio( $dbh, $olddata, $frameworkcode );
217 $olddata->{'biblionumber'} = $biblionumber;
218 $biblioitemnumber = _koha_add_biblioitem( $dbh, $olddata );
220 # we must add bibnum and bibitemnum in MARC::Record...
221 # we build the new field with biblionumber and biblioitemnumber
222 # we drop the original field
223 # we add the new builded field.
224 ( my $biblio_tag, my $biblio_subfield ) = GetMarcFromKohaField("biblio.biblionumber",$frameworkcode);
225 ( my $biblioitem_tag, my $biblioitem_subfield ) = GetMarcFromKohaField("biblioitems.biblioitemnumber",$frameworkcode);
229 # biblionumber & biblioitemnumber are in different fields
230 if ( $biblio_tag != $biblioitem_tag ) {
232 # deal with biblionumber
233 if ( $biblio_tag < 10 ) {
234 $newfield = MARC::Field->new( $biblio_tag, $biblionumber );
238 MARC::Field->new( $biblio_tag, '', '',
239 "$biblio_subfield" => $biblionumber );
242 # drop old field and create new one...
243 my $old_field = $record->field($biblio_tag);
244 $record->delete_field($old_field);
245 $record->append_fields($newfield);
247 # deal with biblioitemnumber
248 if ( $biblioitem_tag < 10 ) {
249 $newfield = MARC::Field->new( $biblioitem_tag, $biblioitemnumber, );
253 MARC::Field->new( $biblioitem_tag, '', '',
254 "$biblioitem_subfield" => $biblioitemnumber, );
256 # drop old field and create new one...
257 $old_field = $record->field($biblioitem_tag);
258 $record->delete_field($old_field);
259 $record->insert_fields_ordered($newfield);
261 # biblionumber & biblioitemnumber are in the same field (can't be <10 as fields <10 have only 1 value)
264 my $newfield = MARC::Field->new(
266 "$biblio_subfield" => $biblionumber,
267 "$biblioitem_subfield" => $biblioitemnumber
270 # drop old field and create new one...
271 my $old_field = $record->field($biblio_tag);
272 $record->delete_field($old_field);
273 $record->insert_fields_ordered($newfield);
277 $biblionumber = ModBiblioMarc( $record, $biblionumber, $frameworkcode );
279 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","ADD",$biblionumber,"biblio")
280 if C4::Context->preference("CataloguingLog");
282 return ( $biblionumber, $biblioitemnumber );
289 $biblionumber = AddItem( $record, $biblionumber)
290 Exported function (core API) for adding a new item to Koha
297 my ( $record, $biblionumber ) = @_;
298 my $dbh = C4::Context->dbh;
301 my $frameworkcode = GetFrameworkCode( $biblionumber );
302 my $item = &TransformMarcToKoha( $dbh, $record, $frameworkcode );
304 # needs old biblionumber and biblioitemnumber
305 $item->{'biblionumber'} = $biblionumber;
308 "select biblioitemnumber,itemtype from biblioitems where biblionumber=?"
310 $sth->execute( $item->{'biblionumber'} );
312 ( $item->{'biblioitemnumber'}, $itemtype ) = $sth->fetchrow;
315 "select notforloan from itemtypes where itemtype='$itemtype'");
317 my $notforloan = $sth->fetchrow;
318 ##Change the notforloan field if $notforloan found
319 if ( $notforloan > 0 ) {
320 $item->{'notforloan'} = $notforloan;
321 &MARCitemchange( $record, "items.notforloan", $notforloan );
323 if ( !$item->{'dateaccessioned'} || $item->{'dateaccessioned'} eq '' ) {
326 my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
331 "$year-" . sprintf( "%0.2d", $mon ) . "-" . sprintf( "%0.2d", $mday );
332 $item->{'dateaccessioned'} = $date;
333 &MARCitemchange( $record, "items.dateaccessioned", $date );
335 my ( $itemnumber, $error ) =
336 &_koha_new_items( $dbh, $item, $item->{barcode} );
338 # add itemnumber to MARC::Record before adding the item.
339 $sth = $dbh->prepare(
340 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
342 &TransformKohaToMarcOneField( $sth, $record, "items.itemnumber", $itemnumber,
346 &AddItemInMarc( $record, $item->{'biblionumber'},$frameworkcode );
348 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","ADD",$itemnumber,"item")
349 if C4::Context->preference("CataloguingLog");
351 return ($item->{biblionumber}, $item->{biblioitemnumber},$itemnumber);
356 ModBiblio( $record,$biblionumber,$frameworkcode);
357 Exported function (core API) to modify a biblio
362 my ( $record, $biblionumber, $frameworkcode ) = @_;
363 if (C4::Context->preference("CataloguingLog")) {
364 my $newrecord = GetMarcBiblio($biblionumber);
365 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","MODIFY",$biblionumber,"BEFORE=>".$newrecord->as_formatted);
368 my $dbh = C4::Context->dbh;
370 $frameworkcode = "" unless $frameworkcode;
372 # get the items before and append them to the biblio before updating the record, atm we just have the biblio
373 my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",$frameworkcode);
374 my $oldRecord = GetMarcBiblio( $biblionumber );
376 # parse each item, and, for an unknown reason, re-encode each subfield
377 # if you don't do that, the record will have encoding mixed
378 # and the biblio will be re-encoded.
379 # strange, I (Paul P.) searched more than 1 day to understand what happends
380 # but could only solve the problem this way...
381 my @fields = $oldRecord->field( $itemtag );
382 foreach my $fielditem ( @fields ){
384 foreach ($fielditem->subfields()) {
386 $field->add_subfields(Encode::encode('utf-8',$_->[0]) => Encode::encode('utf-8',$_->[1]));
388 $field = MARC::Field->new("$itemtag",'','',Encode::encode('utf-8',$_->[0]) => Encode::encode('utf-8',$_->[1]));
391 $record->append_fields($field);
394 # adding biblionumber
395 my ($tag_biblionumber, $subfield_biblionumber) = GetMarcFromKohaField('biblio.biblionumber',$frameworkcode);
396 $record->append_fields(
398 $tag_biblionumber,'','',$subfield_biblionumber => $biblionumber
400 ) unless ($record->subfield($tag_biblionumber,$subfield_biblionumber));
402 # update the MARC record (that now contains biblio and items) with the new record data
403 &ModBiblioMarc( $record, $biblionumber, $frameworkcode );
405 # load the koha-table data object
406 my $oldbiblio = TransformMarcToKoha( $dbh, $record, $frameworkcode );
408 # modify the other koha tables
409 _koha_modify_biblio( $dbh, $oldbiblio );
410 _koha_modify_biblioitem( $dbh, $oldbiblio );
418 Exported function (core API) for modifying an item in Koha.
425 my ( $record, $biblionumber, $itemnumber, $delete, $new_item_hashref )
429 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","MODIFY",$itemnumber,$record->as_formatted)
430 if C4::Context->preference("CataloguingLog");
432 my $dbh = C4::Context->dbh;
434 # if we have a MARC record, we're coming from cataloging and so
435 # we do the whole routine: update the MARC and zebra, then update the koha
438 my $frameworkcode = GetFrameworkCode( $biblionumber );
439 ModItemInMarc( $record, $biblionumber, $itemnumber, $frameworkcode );
440 my $olditem = TransformMarcToKoha( $dbh, $record, $frameworkcode );
441 _koha_modify_item( $dbh, $olditem );
442 return $biblionumber;
445 # otherwise, we're just looking to modify something quickly
446 # (like a status) so we just update the koha tables
447 elsif ($new_item_hashref) {
448 _koha_modify_item( $dbh, $new_item_hashref );
452 sub ModItemTransfer {
453 my ( $itemnumber, $frombranch, $tobranch ) = @_;
455 my $dbh = C4::Context->dbh;
457 #new entry in branchtransfers....
458 my $sth = $dbh->prepare(
459 "INSERT INTO branchtransfers (itemnumber, frombranch, datesent, tobranch)
460 VALUES (?, ?, now(), ?)");
461 $sth->execute($itemnumber, $frombranch, $tobranch);
462 #update holdingbranch in items .....
464 "UPDATE items set holdingbranch = ? WHERE items.itemnumber = ?");
465 $sth->execute($tobranch,$itemnumber);
466 &ModDateLastSeen($itemnumber);
467 $sth = $dbh->prepare(
468 "SELECT biblionumber FROM items WHERE itemnumber=?"
470 $sth->execute($itemnumber);
471 while ( my ( $biblionumber ) = $sth->fetchrow ) {
472 &ModItemInMarconefield( $biblionumber, $itemnumber,
473 'items.holdingbranch', $tobranch );
478 =head2 ModBiblioframework
480 ModBiblioframework($biblionumber,$frameworkcode);
481 Exported function to modify a biblio framework
485 sub ModBiblioframework {
486 my ( $biblionumber, $frameworkcode ) = @_;
487 my $dbh = C4::Context->dbh;
488 my $sth = $dbh->prepare(
489 "UPDATE biblio SET frameworkcode=? WHERE biblionumber=$biblionumber"
491 $sth->execute($frameworkcode);
495 =head2 ModItemInMarconefield
499 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)
500 &ModItemInMarconefield( $biblionumber, $itemnumber, $itemfield, $newvalue )
506 sub ModItemInMarconefield {
507 my ( $biblionumber, $itemnumber, $itemfield, $newvalue ) = @_;
508 my $dbh = C4::Context->dbh;
509 if ( !defined $newvalue ) {
513 my $record = GetMarcItem( $biblionumber, $itemnumber );
514 my ($tagfield, $tagsubfield) = GetMarcFromKohaField( $itemfield,'');
515 if ($tagfield && $tagsubfield) {
516 my $tag = $record->field($tagfield);
518 # my $tagsubs = $record->field($tagfield)->subfield($tagsubfield);
519 $tag->update( $tagsubfield => $newvalue );
520 $record->delete_field($tag);
521 $record->insert_fields_ordered($tag);
522 &ModItemInMarc( $record, $biblionumber, $itemnumber, 0 );
531 &ModItemInMarc( $record, $biblionumber, $itemnumber )
538 my ( $ItemRecord, $biblionumber, $itemnumber, $frameworkcode) = @_;
539 my $dbh = C4::Context->dbh;
541 # get complete MARC record & replace the item field by the new one
542 my $completeRecord = GetMarcBiblio($biblionumber);
543 my ($itemtag,$itemsubfield) = GetMarcFromKohaField("items.itemnumber",$frameworkcode);
544 my $itemField = $ItemRecord->field($itemtag);
545 my @items = $completeRecord->field($itemtag);
547 if ($_->subfield($itemsubfield) eq $itemnumber) {
548 # $completeRecord->delete_field($_);
549 $_->replace_with($itemField);
553 my $sth = $dbh->prepare("update biblioitems set marc=?,marcxml=? where biblionumber=?");
554 $sth->execute( $completeRecord->as_usmarc(), $completeRecord->as_xml_record(),$biblionumber );
556 ModZebra($biblionumber,"specialUpdate","biblioserver",$completeRecord);
559 =head2 ModDateLastSeen
561 &ModDateLastSeen($itemnum)
562 Mark item as seen. Is called when an item is issued, returned or manually marked during inventory/stocktaking
563 C<$itemnum> is the item number
567 sub ModDateLastSeen {
569 my $dbh = C4::Context->dbh;
572 "update items set itemlost=0, datelastseen = now() where items.itemnumber = ?"
574 $sth->execute($itemnum);
581 my $error = &DelBiblio($dbh,$biblionumber);
582 Exported function (core API) for deleting a biblio in koha.
583 Deletes biblio record from Zebra and Koha tables (biblio,biblioitems,items)
584 Also backs it up to deleted* tables
585 Checks to make sure there are not issues on any of the items
587 C<$error> : undef unless an error occurs
594 my ( $biblionumber ) = @_;
595 my $dbh = C4::Context->dbh;
596 my $error; # for error handling
598 # First make sure there are no items with issues are still attached
601 "SELECT itemnumber FROM items WHERE biblionumber=?");
602 $sth->execute($biblionumber);
603 while ( my $itemnumber = $sth->fetchrow ) {
604 my $issues = GetItemIssues($itemnumber);
605 foreach my $issue (@$issues) {
606 if ( ( $issue->{date_due} )
607 && ( $issue->{date_due} ne "Available" ) )
610 #FIXME: we need a status system in Biblio like in Circ to return standard codes and messages
611 # instead of hard-coded strings
613 "Item is checked out to a patron -- you must return it before deleting the Biblio";
617 return $error if $error;
619 # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
620 # for at least 2 reasons :
621 # - we need to read the biblio if NoZebra is set (to remove it from the indexes
622 # - if something goes wrong, the biblio may be deleted from Koha but not from zebra
623 # 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)
624 ModZebra($biblionumber, "delete_record", "biblioserver", undef);
626 # delete biblio from Koha tables and save in deletedbiblio
627 $error = &_koha_delete_biblio( $dbh, $biblionumber );
629 # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
632 "SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
633 $sth->execute($biblionumber);
634 while ( my $biblioitemnumber = $sth->fetchrow ) {
636 # delete this biblioitem
637 $error = &_koha_delete_biblioitems( $dbh, $biblioitemnumber );
638 return $error if $error;
643 "SELECT itemnumber FROM items WHERE biblioitemnumber=?");
644 $items_sth->execute($biblioitemnumber);
645 while ( my $itemnumber = $items_sth->fetchrow ) {
646 $error = &_koha_delete_item( $dbh, $itemnumber );
647 return $error if $error;
650 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","DELETE",$biblionumber,"")
651 if C4::Context->preference("CataloguingLog");
659 DelItem( $biblionumber, $itemnumber );
660 Exported function (core API) for deleting an item record in Koha.
667 my ( $biblionumber, $itemnumber ) = @_;
668 my $dbh = C4::Context->dbh;
669 &_koha_delete_item( $dbh, $itemnumber );
670 # get the MARC record
671 my $record = GetMarcBiblio($biblionumber);
672 my $frameworkcode = GetFrameworkCode($biblionumber);
676 $dbh->prepare("UPDATE deleteditems SET marc=? WHERE itemnumber=?");
677 $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
679 #search item field code
680 my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",$frameworkcode);
681 my @fields = $record->field($itemtag);
682 # delete the item specified
683 foreach my $field (@fields) {
684 if ( $field->subfield($itemsubfield) eq $itemnumber ) {
685 $record->delete_field($field);
688 &ModBiblioMarc( $record, $biblionumber, $frameworkcode );
689 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","DELETE",$itemnumber,"item")
690 if C4::Context->preference("CataloguingLog");
697 $data = &GetBiblioData($biblionumber);
698 Returns information about the book with the given biblionumber.
699 C<&GetBiblioData> returns a reference-to-hash. The keys are the fields in
700 the C<biblio> and C<biblioitems> tables in the
702 In addition, C<$data-E<gt>{subject}> is the list of the book's
703 subjects, separated by C<" , "> (space, comma, space).
704 If there are multiple biblioitems with the given biblionumber, only
705 the first one is considered.
713 my $dbh = C4::Context->dbh;
716 SELECT * , biblioitems.notes AS bnotes, biblio.notes
718 LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
719 LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype
720 WHERE biblio.biblionumber = ?
721 AND biblioitems.biblionumber = biblio.biblionumber
723 my $sth = $dbh->prepare($query);
724 $sth->execute($bibnum);
726 $data = $sth->fetchrow_hashref;
730 } # sub GetBiblioData
737 @results = &GetItemsInfo($biblionumber, $type);
739 Returns information about books with the given biblionumber.
741 C<$type> may be either C<intra> or anything else. If it is not set to
742 C<intra>, then the search will exclude lost, very overdue, and
745 C<&GetItemsInfo> returns a list of references-to-hash. Each element
746 contains a number of keys. Most of them are table items from the
747 C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
748 Koha database. Other keys include:
752 =item C<$data-E<gt>{branchname}>
754 The name (not the code) of the branch to which the book belongs.
756 =item C<$data-E<gt>{datelastseen}>
758 This is simply C<items.datelastseen>, except that while the date is
759 stored in YYYY-MM-DD format in the database, here it is converted to
760 DD/MM/YYYY format. A NULL date is returned as C<//>.
762 =item C<$data-E<gt>{datedue}>
764 =item C<$data-E<gt>{class}>
766 This is the concatenation of C<biblioitems.classification>, the book's
767 Dewey code, and C<biblioitems.subclass>.
769 =item C<$data-E<gt>{ocount}>
771 I think this is the number of copies of the book available.
773 =item C<$data-E<gt>{order}>
775 If this is set, it is set to C<One Order>.
784 my ( $biblionumber, $type ) = @_;
785 my $dbh = C4::Context->dbh;
786 my $query = "SELECT *,items.notforloan as itemnotforloan
787 FROM items, biblio, biblioitems
788 LEFT JOIN itemtypes on biblioitems.itemtype = itemtypes.itemtype
789 WHERE items.biblionumber = ?
790 AND biblioitems.biblioitemnumber = items.biblioitemnumber
791 AND biblio.biblionumber = items.biblionumber
792 ORDER BY items.dateaccessioned desc
794 my $sth = $dbh->prepare($query);
795 $sth->execute($biblionumber);
798 my ( $date_due, $count_reserves );
800 while ( my $data = $sth->fetchrow_hashref ) {
802 my $isth = $dbh->prepare(
803 "SELECT issues.*,borrowers.cardnumber,borrowers.surname,borrowers.firstname
804 FROM issues, borrowers
806 AND returndate IS NULL
807 AND issues.borrowernumber=borrowers.borrowernumber"
809 $isth->execute( $data->{'itemnumber'} );
810 if ( my $idata = $isth->fetchrow_hashref ) {
811 $data->{borrowernumber} = $idata->{borrowernumber};
812 $data->{cardnumber} = $idata->{cardnumber};
813 $data->{surname} = $idata->{surname};
814 $data->{firstname} = $idata->{firstname};
815 $datedue = format_date( $idata->{'date_due'} );
817 if ( $datedue eq '' ) {
818 #$datedue="Available";
819 my ( $restype, $reserves ) =
820 C4::Reserves::CheckReserves( $data->{'itemnumber'} );
824 $count_reserves = $restype;
829 #get branch information.....
830 my $bsth = $dbh->prepare(
831 "SELECT * FROM branches WHERE branchcode = ?
834 $bsth->execute( $data->{'holdingbranch'} );
835 if ( my $bdata = $bsth->fetchrow_hashref ) {
836 $data->{'branchname'} = $bdata->{'branchname'};
838 my $date = format_date( $data->{'datelastseen'} );
839 $data->{'datelastseen'} = $date;
840 $data->{'datedue'} = $datedue;
841 $data->{'count_reserves'} = $count_reserves;
843 # get notforloan complete status if applicable
844 my $sthnflstatus = $dbh->prepare(
845 'SELECT authorised_value
846 FROM marc_subfield_structure
847 WHERE kohafield="items.notforloan"
851 $sthnflstatus->execute;
852 my ($authorised_valuecode) = $sthnflstatus->fetchrow;
853 if ($authorised_valuecode) {
854 $sthnflstatus = $dbh->prepare(
855 "SELECT lib FROM authorised_values
857 AND authorised_value=?"
859 $sthnflstatus->execute( $authorised_valuecode,
860 $data->{itemnotforloan} );
861 my ($lib) = $sthnflstatus->fetchrow;
862 $data->{notforloan} = $lib;
865 # my stack procedures
866 my $stackstatus = $dbh->prepare(
867 'SELECT authorised_value
868 FROM marc_subfield_structure
869 WHERE kohafield="items.stack"
872 $stackstatus->execute;
874 ($authorised_valuecode) = $stackstatus->fetchrow;
875 if ($authorised_valuecode) {
876 $stackstatus = $dbh->prepare(
878 FROM authorised_values
880 AND authorised_value=?
883 $stackstatus->execute( $authorised_valuecode, $data->{stack} );
884 my ($lib) = $stackstatus->fetchrow;
885 $data->{stack} = $lib;
887 $results[$i] = $data;
899 $itemstatushash = &getitemstatus($fwkcode);
900 returns information about status.
901 Can be MARC dependant.
903 But basically could be can be loan or not
904 Create a status selector with the following code
906 =head3 in PERL SCRIPT
908 my $itemstatushash = getitemstatus;
910 foreach my $thisstatus (keys %$itemstatushash) {
911 my %row =(value => $thisstatus,
912 statusname => $itemstatushash->{$thisstatus}->{'statusname'},
914 push @itemstatusloop, \%row;
916 $template->param(statusloop=>\@itemstatusloop);
921 <select name="statusloop">
922 <option value="">Default</option>
923 <!-- TMPL_LOOP name="statusloop" -->
924 <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="statusname" --></option>
932 # returns a reference to a hash of references to status...
935 my $dbh = C4::Context->dbh;
937 $fwk = '' unless ($fwk);
938 my ( $tag, $subfield ) =
939 GetMarcFromKohaField( "items.notforloan", $fwk );
940 if ( $tag and $subfield ) {
943 "select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?"
945 $sth->execute( $tag, $subfield, $fwk );
946 if ( my ($authorisedvaluecat) = $sth->fetchrow ) {
949 "select authorised_value, lib from authorised_values where category=? order by lib"
951 $authvalsth->execute($authorisedvaluecat);
952 while ( my ( $authorisedvalue, $lib ) = $authvalsth->fetchrow ) {
953 $itemstatus{$authorisedvalue} = $lib;
969 $itemstatus{"1"} = "Not For Loan";
973 =head2 getitemlocation
977 $itemlochash = &getitemlocation($fwk);
978 returns informations about location.
979 where fwk stands for an optional framework code.
980 Create a location selector with the following code
982 =head3 in PERL SCRIPT
984 my $itemlochash = getitemlocation;
986 foreach my $thisloc (keys %$itemlochash) {
987 my $selected = 1 if $thisbranch eq $branch;
988 my %row =(locval => $thisloc,
989 selected => $selected,
990 locname => $itemlochash->{$thisloc},
992 push @itemlocloop, \%row;
994 $template->param(itemlocationloop => \@itemlocloop);
998 <select name="location">
999 <option value="">Default</option>
1000 <!-- TMPL_LOOP name="itemlocationloop" -->
1001 <option value="<!-- TMPL_VAR name="locval" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="locname" --></option>
1009 sub GetItemLocation {
1011 # returns a reference to a hash of references to location...
1014 my $dbh = C4::Context->dbh;
1016 $fwk = '' unless ($fwk);
1017 my ( $tag, $subfield ) =
1018 GetMarcFromKohaField( "items.location", $fwk );
1019 if ( $tag and $subfield ) {
1022 "select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?"
1024 $sth->execute( $tag, $subfield, $fwk );
1025 if ( my ($authorisedvaluecat) = $sth->fetchrow ) {
1028 "select authorised_value, lib from authorised_values where category=? order by lib"
1030 $authvalsth->execute($authorisedvaluecat);
1031 while ( my ( $authorisedvalue, $lib ) = $authvalsth->fetchrow ) {
1032 $itemlocation{$authorisedvalue} = $lib;
1034 $authvalsth->finish;
1035 return \%itemlocation;
1048 $itemlocation{"1"} = "Not For Loan";
1049 return \%itemlocation;
1054 $items = GetLostItems($where,$orderby);
1056 This function get the items lost into C<$items>.
1061 C<$where> is a hashref. it containts a field of the items table as key
1062 and the value to match as value.
1063 C<$orderby> is a field of the items table.
1066 C<$items> is a reference to an array full of hasref which keys are items' table column.
1068 =item usage in the perl script:
1071 $where{barcode} = 0001548;
1072 my $items = GetLostItems( \%where, "homebranch" );
1073 $template->param(itemsloop => $items);
1080 # Getting input args.
1082 my $orderby = shift;
1083 my $dbh = C4::Context->dbh;
1088 WHERE itemlost IS NOT NULL
1091 foreach my $key (keys %$where) {
1092 $query .= " AND " . $key . " LIKE '%" . $where->{$key} . "%'";
1094 $query .= " ORDER BY ".$orderby if defined $orderby;
1096 my $sth = $dbh->prepare($query);
1099 while ( my $row = $sth->fetchrow_hashref ){
1105 =head2 GetItemsForInventory
1107 $itemlist = GetItemsForInventory($minlocation,$maxlocation,$datelastseen,$offset,$size)
1109 Retrieve a list of title/authors/barcode/callnumber, for biblio inventory.
1111 The sub returns a list of hashes, containing itemnumber, author, title, barcode & item callnumber.
1112 It is ordered by callnumber,title.
1114 The minlocation & maxlocation parameters are used to specify a range of item callnumbers
1115 the datelastseen can be used to specify that you want to see items not seen since a past date only.
1116 offset & size can be used to retrieve only a part of the whole listing (defaut behaviour)
1120 sub GetItemsForInventory {
1121 my ( $minlocation, $maxlocation,$location, $datelastseen, $branch, $offset, $size ) = @_;
1122 my $dbh = C4::Context->dbh;
1124 if ($datelastseen) {
1125 $datelastseen=format_date_in_iso($datelastseen);
1127 "SELECT itemnumber,barcode,itemcallnumber,title,author,biblio.biblionumber,datelastseen
1129 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1130 WHERE itemcallnumber>= ?
1131 AND itemcallnumber <=?
1132 AND (datelastseen< ? OR datelastseen IS NULL)";
1133 $query.= " AND items.location=".$dbh->quote($location) if $location;
1134 $query.= " AND items.homebranch=".$dbh->quote($branch) if $branch;
1135 $query .= " ORDER BY itemcallnumber,title";
1136 $sth = $dbh->prepare($query);
1137 $sth->execute( $minlocation, $maxlocation, $datelastseen );
1141 SELECT itemnumber,barcode,itemcallnumber,biblio.biblionumber,title,author,datelastseen
1143 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1144 WHERE itemcallnumber>= ?
1145 AND itemcallnumber <=?";
1146 $query.= " AND items.location=".$dbh->quote($location) if $location;
1147 $query.= " AND items.homebranch=".$dbh->quote($branch) if $branch;
1148 $query .= " ORDER BY itemcallnumber,title";
1149 $sth = $dbh->prepare($query);
1150 $sth->execute( $minlocation, $maxlocation );
1153 while ( my $row = $sth->fetchrow_hashref ) {
1154 $offset-- if ($offset);
1155 $row->{datelastseen}=format_date($row->{datelastseen});
1156 if ( ( !$offset ) && $size ) {
1157 push @results, $row;
1164 =head2 &GetBiblioItemData
1168 $itemdata = &GetBiblioItemData($biblioitemnumber);
1170 Looks up the biblioitem with the given biblioitemnumber. Returns a
1171 reference-to-hash. The keys are the fields from the C<biblio>,
1172 C<biblioitems>, and C<itemtypes> tables in the Koha database, except
1173 that C<biblioitems.notes> is given as C<$itemdata-E<gt>{bnotes}>.
1180 sub GetBiblioItemData {
1182 my $dbh = C4::Context->dbh;
1185 "Select *,biblioitems.notes as bnotes from biblioitems, biblio,itemtypes where biblio.biblionumber = biblioitems.biblionumber and biblioitemnumber = ? and biblioitems.itemtype = itemtypes.itemtype"
1189 $sth->execute($bibitem);
1191 $data = $sth->fetchrow_hashref;
1195 } # sub &GetBiblioItemData
1197 =head2 GetItemnumberFromBarcode
1201 $result = GetItemnumberFromBarcode($barcode);
1207 sub GetItemnumberFromBarcode {
1209 my $dbh = C4::Context->dbh;
1212 $dbh->prepare("SELECT itemnumber from items where items.barcode=?");
1213 $rq->execute($barcode);
1214 my ($result) = $rq->fetchrow;
1218 =head2 GetBiblioItemByBiblioNumber
1222 NOTE : This function has been copy/paste from C4/Biblio.pm from head before zebra integration.
1228 sub GetBiblioItemByBiblioNumber {
1229 my ($biblionumber) = @_;
1230 my $dbh = C4::Context->dbh;
1231 my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?");
1235 $sth->execute($biblionumber);
1237 while ( my $data = $sth->fetchrow_hashref ) {
1238 push @results, $data;
1245 =head2 GetBiblioFromItemNumber
1249 $item = &GetBiblioFromItemNumber($itemnumber);
1251 Looks up the item with the given itemnumber.
1253 C<&itemnodata> returns a reference-to-hash whose keys are the fields
1254 from the C<biblio>, C<biblioitems>, and C<items> tables in the Koha
1262 sub GetBiblioFromItemNumber {
1263 my ( $itemnumber ) = @_;
1264 my $dbh = C4::Context->dbh;
1265 my $sth = $dbh->prepare(
1266 "SELECT * FROM biblio,items,biblioitems
1267 WHERE items.itemnumber = ?
1268 AND biblio.biblionumber = items.biblionumber
1269 AND biblioitems.biblioitemnumber = items.biblioitemnumber"
1272 $sth->execute($itemnumber);
1273 my $data = $sth->fetchrow_hashref;
1282 ( $count, @results ) = &GetBiblio($biblionumber);
1289 my ($biblionumber) = @_;
1290 my $dbh = C4::Context->dbh;
1291 my $sth = $dbh->prepare("Select * from biblio where biblionumber = ?");
1294 $sth->execute($biblionumber);
1295 while ( my $data = $sth->fetchrow_hashref ) {
1296 $results[$count] = $data;
1300 return ( $count, @results );
1307 $data = &GetItem($itemnumber,$barcode);
1309 return Item information, for a given itemnumber or barcode
1316 my ($itemnumber,$barcode) = @_;
1317 my $dbh = C4::Context->dbh;
1319 my $sth = $dbh->prepare("
1321 WHERE itemnumber = ?");
1322 $sth->execute($itemnumber);
1323 my $data = $sth->fetchrow_hashref;
1326 my $sth = $dbh->prepare("
1330 $sth->execute($barcode);
1331 my $data = $sth->fetchrow_hashref;
1336 =head2 get_itemnumbers_of
1340 my @itemnumbers_of = get_itemnumbers_of(@biblionumbers);
1342 Given a list of biblionumbers, return the list of corresponding itemnumbers
1343 for each biblionumber.
1345 Return a reference on a hash where keys are biblionumbers and values are
1346 references on array of itemnumbers.
1352 sub get_itemnumbers_of {
1353 my @biblionumbers = @_;
1355 my $dbh = C4::Context->dbh;
1361 WHERE biblionumber IN (?' . ( ',?' x scalar @biblionumbers - 1 ) . ')
1363 my $sth = $dbh->prepare($query);
1364 $sth->execute(@biblionumbers);
1368 while ( my ( $itemnumber, $biblionumber ) = $sth->fetchrow_array ) {
1369 push @{ $itemnumbers_of{$biblionumber} }, $itemnumber;
1372 return \%itemnumbers_of;
1375 =head2 GetItemInfosOf
1379 GetItemInfosOf(@itemnumbers);
1385 sub GetItemInfosOf {
1386 my @itemnumbers = @_;
1391 WHERE itemnumber IN (' . join( ',', @itemnumbers ) . ')
1393 return get_infos_of( $query, 'itemnumber' );
1396 =head2 GetItemsByBiblioitemnumber
1400 GetItemsByBiblioitemnumber($biblioitemnumber);
1402 Returns an arrayref of hashrefs suitable for use in a TMPL_LOOP
1403 Called by moredetail.pl
1409 sub GetItemsByBiblioitemnumber {
1410 my ( $bibitem ) = @_;
1411 my $dbh = C4::Context->dbh;
1412 my $sth = $dbh->prepare("SELECT * FROM items WHERE items.biblioitemnumber = ?") || die $dbh->errstr;
1413 # Get all items attached to a biblioitem
1416 $sth->execute($bibitem) || die $sth->errstr;
1417 while ( my $data = $sth->fetchrow_hashref ) {
1418 # Foreach item, get circulation information
1419 my $sth2 = $dbh->prepare( "SELECT * FROM issues,borrowers
1420 WHERE itemnumber = ?
1421 AND returndate is NULL
1422 AND issues.borrowernumber = borrowers.borrowernumber"
1424 $sth2->execute( $data->{'itemnumber'} );
1425 if ( my $data2 = $sth2->fetchrow_hashref ) {
1426 # if item is out, set the due date and who it is out too
1427 $data->{'date_due'} = $data2->{'date_due'};
1428 $data->{'cardnumber'} = $data2->{'cardnumber'};
1429 $data->{'borrowernumber'} = $data2->{'borrowernumber'};
1432 # set date_due to blank, so in the template we check itemlost, and wthdrawn
1433 $data->{'date_due'} = '';
1436 # Find the last 3 people who borrowed this item.
1437 my $query2 = "SELECT * FROM issues, borrowers WHERE itemnumber = ?
1438 AND issues.borrowernumber = borrowers.borrowernumber
1439 AND returndate is not NULL
1440 ORDER BY returndate desc,timestamp desc LIMIT 3";
1441 $sth2 = $dbh->prepare($query2) || die $dbh->errstr;
1442 $sth2->execute( $data->{'itemnumber'} ) || die $sth2->errstr;
1444 while ( my $data2 = $sth2->fetchrow_hashref ) {
1445 $data->{"timestamp$i2"} = $data2->{'timestamp'};
1446 $data->{"card$i2"} = $data2->{'cardnumber'};
1447 $data->{"borrower$i2"} = $data2->{'borrowernumber'};
1451 push(@results,$data);
1458 =head2 GetBiblioItemInfosOf
1462 GetBiblioItemInfosOf(@biblioitemnumbers);
1468 sub GetBiblioItemInfosOf {
1469 my @biblioitemnumbers = @_;
1472 SELECT biblioitemnumber,
1476 WHERE biblioitemnumber IN (' . join( ',', @biblioitemnumbers ) . ')
1478 return get_infos_of( $query, 'biblioitemnumber' );
1481 =head1 FUNCTIONS FOR HANDLING MARC MANAGEMENT
1483 =head2 GetMarcStructure
1487 $res = GetMarcStructure($forlibrarian,$frameworkcode);
1489 Returns a reference to a big hash of hash, with the Marc structure for the given frameworkcode
1490 $forlibrarian :if set to 1, the MARC descriptions are the librarians ones, otherwise it's the public (OPAC) ones
1491 $frameworkcode : the framework code to read
1497 sub GetMarcStructure {
1498 my ( $forlibrarian, $frameworkcode ) = @_;
1499 my $dbh=C4::Context->dbh;
1500 $frameworkcode = "" unless $frameworkcode;
1502 my $libfield = ( $forlibrarian eq 1 ) ? 'liblibrarian' : 'libopac';
1504 # check that framework exists
1507 "select count(*) from marc_tag_structure where frameworkcode=?");
1508 $sth->execute($frameworkcode);
1509 my ($total) = $sth->fetchrow;
1510 $frameworkcode = "" unless ( $total > 0 );
1513 "select tagfield,liblibrarian,libopac,mandatory,repeatable from marc_tag_structure where frameworkcode=? order by tagfield"
1515 $sth->execute($frameworkcode);
1516 my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable );
1518 while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable ) =
1521 $res->{$tag}->{lib} =
1522 ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac;
1523 # why the hell do we need to explicitly decode utf8 ?
1524 # that's a good question, but we must do it...
1525 $res->{$tab}->{tab} = ""; # XXX
1526 $res->{$tag}->{mandatory} = $mandatory;
1527 $res->{$tag}->{repeatable} = $repeatable;
1532 "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"
1535 $sth->execute($frameworkcode);
1538 my $authorised_value;
1550 $tag, $subfield, $liblibrarian,
1552 $mandatory, $repeatable, $authorised_value,
1553 $authtypecode, $value_builder, $kohafield,
1554 $seealso, $hidden, $isurl,
1560 $res->{$tag}->{$subfield}->{lib} =
1561 ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac;
1562 $res->{$tag}->{$subfield}->{tab} = $tab;
1563 $res->{$tag}->{$subfield}->{mandatory} = $mandatory;
1564 $res->{$tag}->{$subfield}->{repeatable} = $repeatable;
1565 $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
1566 $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode;
1567 $res->{$tag}->{$subfield}->{value_builder} = $value_builder;
1568 $res->{$tag}->{$subfield}->{kohafield} = $kohafield;
1569 $res->{$tag}->{$subfield}->{seealso} = $seealso;
1570 $res->{$tag}->{$subfield}->{hidden} = $hidden;
1571 $res->{$tag}->{$subfield}->{isurl} = $isurl;
1572 $res->{$tag}->{$subfield}->{'link'} = $link;
1573 $res->{$tag}->{$subfield}->{defaultvalue} = $defaultvalue;
1578 =head2 GetUsedMarcStructure
1580 the same function as GetMarcStructure expcet it just take field
1581 in tab 0-9. (used field)
1583 my $results = GetUsedMarcStructure($frameworkcode);
1585 L<$results> is a ref to an array which each case containts a ref
1586 to a hash which each keys is the columns from marc_subfield_structure
1588 L<$frameworkcode> is the framework code.
1592 sub GetUsedMarcStructure($){
1593 my $frameworkcode = shift || '';
1594 my $dbh = C4::Context->dbh;
1597 FROM marc_subfield_structure
1599 AND frameworkcode = ?
1602 my $sth = $dbh->prepare($query);
1603 $sth->execute($frameworkcode);
1604 while (my $row = $sth->fetchrow_hashref){
1610 =head2 GetMarcFromKohaField
1614 ($MARCfield,$MARCsubfield)=GetMarcFromKohaField($kohafield,$frameworkcode);
1615 Returns the MARC fields & subfields mapped to the koha field
1616 for the given frameworkcode
1622 sub GetMarcFromKohaField {
1623 my ( $kohafield, $frameworkcode ) = @_;
1624 return 0, 0 unless $kohafield;
1625 my $relations = C4::Context->marcfromkohafield;
1627 $relations->{$frameworkcode}->{$kohafield}->[0],
1628 $relations->{$frameworkcode}->{$kohafield}->[1]
1632 =head2 GetMarcBiblio
1636 Returns MARC::Record of the biblionumber passed in parameter.
1637 the marc record contains both biblio & item datas
1644 my $biblionumber = shift;
1645 my $dbh = C4::Context->dbh;
1647 $dbh->prepare("select marcxml from biblioitems where biblionumber=? ");
1648 $sth->execute($biblionumber);
1649 my ($marcxml) = $sth->fetchrow;
1650 MARC::File::XML->default_record_format(C4::Context->preference('marcflavour'));
1651 $marcxml =~ s/\x1e//g;
1652 $marcxml =~ s/\x1f//g;
1653 $marcxml =~ s/\x1d//g;
1654 $marcxml =~ s/\x0f//g;
1655 $marcxml =~ s/\x0c//g;
1657 my $record = MARC::Record->new();
1658 $record = MARC::Record::new_from_xml( $marcxml, "utf8",C4::Context->preference('marcflavour')) if $marcxml;
1659 # $record = MARC::Record::new_from_usmarc( $marc) if $marc;
1667 my $marcxml = GetXmlBiblio($biblionumber);
1669 Returns biblioitems.marcxml of the biblionumber passed in parameter.
1670 The XML contains both biblio & item datas
1677 my ( $biblionumber ) = @_;
1678 my $dbh = C4::Context->dbh;
1680 $dbh->prepare("select marcxml from biblioitems where biblionumber=? ");
1681 $sth->execute($biblionumber);
1682 my ($marcxml) = $sth->fetchrow;
1686 =head2 GetAuthorisedValueDesc
1690 my $subfieldvalue =get_authorised_value_desc(
1691 $tag, $subf[$i][0],$subf[$i][1], '', $taglib);
1692 Retrieve the complete description for a given authorised value.
1698 sub GetAuthorisedValueDesc {
1699 my ( $tag, $subfield, $value, $framework, $tagslib ) = @_;
1700 my $dbh = C4::Context->dbh;
1703 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
1704 return C4::Branch::GetBranchName($value);
1708 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
1709 return getitemtypeinfo($value)->{description};
1712 #---- "true" authorized value
1713 my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
1714 if ( $category ne "" ) {
1717 "select lib from authorised_values where category = ? and authorised_value = ?"
1719 $sth->execute( $category, $value );
1720 my $data = $sth->fetchrow_hashref;
1721 return $data->{'lib'};
1724 return $value; # if nothing is found return the original value
1732 Returns MARC::Record of the item passed in parameter.
1739 my ( $biblionumber, $itemnumber ) = @_;
1740 my $dbh = C4::Context->dbh;
1741 my $newrecord = MARC::Record->new();
1742 my $marcflavour = C4::Context->preference('marcflavour');
1744 my $marcxml = GetXmlBiblio($biblionumber);
1745 my $record = MARC::Record->new();
1746 $record = MARC::Record::new_from_xml( $marcxml, "utf8", $marcflavour );
1747 # now, find where the itemnumber is stored & extract only the item
1748 my ( $itemnumberfield, $itemnumbersubfield ) =
1749 GetMarcFromKohaField( 'items.itemnumber', '' );
1750 my @fields = $record->field($itemnumberfield);
1751 foreach my $field (@fields) {
1752 if ( $field->subfield($itemnumbersubfield) eq $itemnumber ) {
1753 $newrecord->insert_fields_ordered($field);
1765 $marcnotesarray = GetMarcNotes( $record, $marcflavour );
1766 Get all notes from the MARC record and returns them in an array.
1767 The note are stored in differents places depending on MARC flavour
1774 my ( $record, $marcflavour ) = @_;
1776 if ( $marcflavour eq "MARC21" ) {
1779 else { # assume unimarc if not marc21
1786 foreach my $field ( $record->field($scope) ) {
1787 my $value = $field->as_string();
1788 if ( $note ne "" ) {
1789 $marcnote = { marcnote => $note, };
1790 push @marcnotes, $marcnote;
1793 if ( $note ne $value ) {
1794 $note = $note . " " . $value;
1799 $marcnote = { marcnote => $note };
1800 push @marcnotes, $marcnote; #load last tag into array
1803 } # end GetMarcNotes
1805 =head2 GetMarcSubjects
1809 $marcsubjcts = GetMarcSubjects($record,$marcflavour);
1810 Get all subjects from the MARC record and returns them in an array.
1811 The subjects are stored in differents places depending on MARC flavour
1817 sub GetMarcSubjects {
1818 my ( $record, $marcflavour ) = @_;
1819 my ( $mintag, $maxtag );
1820 if ( $marcflavour eq "MARC21" ) {
1824 else { # assume unimarc if not marc21
1831 foreach my $field ( $record->fields ) {
1832 next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1833 my @subfields = $field->subfields();
1837 my $authoritysep=C4::Context->preference("authoritysep");
1838 for my $subject_subfield ( @subfields ) {
1840 $marcflavour ne 'MARC21'
1842 ($subject_subfield->[0] eq '3') or
1843 ($subject_subfield->[0] eq '4') or
1844 ($subject_subfield->[0] eq '5')
1850 my $code = $subject_subfield->[0];
1851 $label .= $subject_subfield->[1].$authoritysep unless ( $code == 9 );
1852 $link .= " and su-to:".$subject_subfield->[1] unless ( $code == 9 );
1854 $link = "an:".$subject_subfield->[1];
1858 $link =~ s/ and\ssu-to:$//;
1861 $label =~ s/$authoritysep$//;
1868 return \@marcsubjcts;
1869 } #end GetMarcSubjects
1871 =head2 GetMarcAuthors
1875 authors = GetMarcAuthors($record,$marcflavour);
1876 Get all authors from the MARC record and returns them in an array.
1877 The authors are stored in differents places depending on MARC flavour
1883 sub GetMarcAuthors {
1884 my ( $record, $marcflavour ) = @_;
1885 my ( $mintag, $maxtag );
1886 # tagslib useful for UNIMARC author reponsabilities
1887 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.
1888 if ( $marcflavour eq "MARC21" ) {
1892 else { # assume unimarc if not marc21
1899 foreach my $field ( $record->fields ) {
1900 next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1902 my @subfields = $field->subfields();
1905 for my $authors_subfield (@subfields) {
1907 $marcflavour ne 'MARC21'
1909 ($authors_subfield->[0] eq '3') or
1910 ($authors_subfield->[0] eq '5')
1916 if ($count_auth ne '0'){
1920 my $subfieldcode = $authors_subfield->[0];
1922 # deal with UNIMARC author responsibility
1924 $marcflavour ne 'MARC21'
1925 and ($authors_subfield->[0] eq '4')
1928 $value = "(".GetAuthorisedValueDesc( $field->tag(), $authors_subfield->[0], $authors_subfield->[1], '', $tagslib ).")";
1930 $value = $authors_subfield->[1];
1932 $hash{tag} = $field->tag;
1933 $hash{value} .= $value . " " if ($subfieldcode != 9) ;
1934 $hash{link} .= $value if ($subfieldcode eq 9);
1936 push @marcauthors, \%hash;
1938 return \@marcauthors;
1941 =head2 GetMarcSeries
1945 $marcseriessarray = GetMarcSeries($record,$marcflavour);
1946 Get all series from the MARC record and returns them in an array.
1947 The series are stored in differents places depending on MARC flavour
1954 my ($record, $marcflavour) = @_;
1955 my ($mintag, $maxtag);
1956 if ($marcflavour eq "MARC21") {
1959 } else { # assume unimarc if not marc21
1969 foreach my $field ($record->field('440'), $record->field('490')) {
1971 #my $value = $field->subfield('a');
1972 #$marcsubjct = {MARCSUBJCT => $value,};
1973 my @subfields = $field->subfields();
1974 #warn "subfields:".join " ", @$subfields;
1977 for my $series_subfield (@subfields) {
1979 undef $volume_number;
1980 # see if this is an instance of a volume
1981 if ($series_subfield->[0] eq 'v') {
1985 my $code = $series_subfield->[0];
1986 my $value = $series_subfield->[1];
1987 my $linkvalue = $value;
1988 $linkvalue =~ s/(\(|\))//g;
1989 my $operator = " and " unless $counter==0;
1990 push @link_loop, {link => $linkvalue, operator => $operator };
1991 my $separator = C4::Context->preference("authoritysep") unless $counter==0;
1992 if ($volume_number) {
1993 push @subfields_loop, {volumenum => $value};
1996 push @subfields_loop, {code => $code, value => $value, link_loop => \@link_loop, separator => $separator, volumenum => $volume_number};
2000 push @marcseries, { MARCSERIES_SUBFIELDS_LOOP => \@subfields_loop };
2001 #$marcsubjct = {MARCSUBJCT => $field->as_string(),};
2002 #push @marcsubjcts, $marcsubjct;
2006 my $marcseriessarray=\@marcseries;
2007 return $marcseriessarray;
2008 } #end getMARCseriess
2010 =head2 GetFrameworkCode
2014 $frameworkcode = GetFrameworkCode( $biblionumber )
2020 sub GetFrameworkCode {
2021 my ( $biblionumber ) = @_;
2022 my $dbh = C4::Context->dbh;
2023 my $sth = $dbh->prepare("select frameworkcode from biblio where biblionumber=?");
2024 $sth->execute($biblionumber);
2025 my ($frameworkcode) = $sth->fetchrow;
2026 return $frameworkcode;
2029 =head2 GetPublisherNameFromIsbn
2031 $name = GetPublishercodeFromIsbn($isbn);
2038 sub GetPublisherNameFromIsbn($){
2040 $isbn =~ s/[- _]//g;
2042 my @codes = (split '-', DisplayISBN($isbn));
2043 my $code = $codes[0].$codes[1].$codes[2];
2044 my $dbh = C4::Context->dbh;
2046 SELECT distinct publishercode
2049 AND publishercode IS NOT NULL
2052 my $sth = $dbh->prepare($query);
2053 $sth->execute("$code%");
2054 my $name = $sth->fetchrow;
2055 return $name if length $name;
2059 =head2 TransformKohaToMarc
2063 $record = TransformKohaToMarc( $hash )
2064 This function builds partial MARC::Record from a hash
2065 Hash entries can be from biblio or biblioitems.
2066 This function is called in acquisition module, to create a basic catalogue entry from user entry
2072 sub TransformKohaToMarc {
2075 my $dbh = C4::Context->dbh;
2078 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
2080 my $record = MARC::Record->new();
2081 foreach (keys %{$hash}) {
2082 &TransformKohaToMarcOneField( $sth, $record, $_,
2088 =head2 TransformKohaToMarcOneField
2092 $record = TransformKohaToMarcOneField( $sth, $record, $kohafieldname, $value, $frameworkcode );
2098 sub TransformKohaToMarcOneField {
2099 my ( $sth, $record, $kohafieldname, $value, $frameworkcode ) = @_;
2100 $frameworkcode='' unless $frameworkcode;
2104 if ( !defined $sth ) {
2105 my $dbh = C4::Context->dbh;
2106 $sth = $dbh->prepare(
2107 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
2110 $sth->execute( $frameworkcode, $kohafieldname );
2111 if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
2112 my $tag = $record->field($tagfield);
2114 $tag->update( $tagsubfield => $value );
2115 $record->delete_field($tag);
2116 $record->insert_fields_ordered($tag);
2119 $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
2125 =head2 TransformHtmlToXml
2129 $xml = TransformHtmlToXml( $tags, $subfields, $values, $indicator, $ind_tag, $auth_type )
2131 $auth_type contains :
2132 - nothing : rebuild a biblio, un UNIMARC the encoding is in 100$a pos 26/27
2133 - UNIMARCAUTH : rebuild an authority. In UNIMARC, the encoding is in 100$a pos 13/14
2134 - ITEM : rebuild an item : in UNIMARC, 100$a, it's in the biblio ! (otherwise, we would get 2 100 fields !)
2140 sub TransformHtmlToXml {
2141 my ( $tags, $subfields, $values, $indicator, $ind_tag, $auth_type ) = @_;
2142 my $xml = MARC::File::XML::header('UTF-8');
2143 $auth_type = C4::Context->preference('marcflavour') unless $auth_type;
2144 MARC::File::XML->default_record_format($auth_type);
2145 # in UNIMARC, field 100 contains the encoding
2146 # check that there is one, otherwise the
2147 # MARC::Record->new_from_xml will fail (and Koha will die)
2148 my $unimarc_and_100_exist=0;
2149 $unimarc_and_100_exist=1 if $auth_type eq 'ITEM'; # if we rebuild an item, no need of a 100 field
2154 for ( my $i = 0 ; $i <= @$tags ; $i++ ) {
2155 if (C4::Context->preference('marcflavour') eq 'UNIMARC' and @$tags[$i] eq "100" and @$subfields[$i] eq "a") {
2156 # if we have a 100 field and it's values are not correct, skip them.
2157 # if we don't have any valid 100 field, we will create a default one at the end
2158 my $enc = substr( @$values[$i], 26, 2 );
2159 if ($enc eq '01' or $enc eq '50' or $enc eq '03') {
2160 $unimarc_and_100_exist=1;
2165 @$values[$i] =~ s/&/&/g;
2166 @$values[$i] =~ s/</</g;
2167 @$values[$i] =~ s/>/>/g;
2168 @$values[$i] =~ s/"/"/g;
2169 @$values[$i] =~ s/'/'/g;
2170 # if ( !utf8::is_utf8( @$values[$i] ) ) {
2171 # utf8::decode( @$values[$i] );
2173 if ( ( @$tags[$i] ne $prevtag ) ) {
2174 $j++ unless ( @$tags[$i] eq "" );
2176 $xml .= "</datafield>\n";
2177 if ( ( @$tags[$i] && @$tags[$i] > 10 )
2178 && ( @$values[$i] ne "" ) )
2180 my $ind1 = substr( @$indicator[$j], 0, 1 );
2182 if ( @$indicator[$j] ) {
2183 $ind2 = substr( @$indicator[$j], 1, 1 );
2186 warn "Indicator in @$tags[$i] is empty";
2190 "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
2192 "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2200 if ( @$values[$i] ne "" ) {
2203 if ( @$tags[$i] eq "000" ) {
2204 $xml .= "<leader>@$values[$i]</leader>\n";
2207 # rest of the fixed fields
2209 elsif ( @$tags[$i] < 10 ) {
2211 "<controlfield tag=\"@$tags[$i]\">@$values[$i]</controlfield>\n";
2215 my $ind1 = substr( @$indicator[$j], 0, 1 );
2216 my $ind2 = substr( @$indicator[$j], 1, 1 );
2218 "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
2220 "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2226 else { # @$tags[$i] eq $prevtag
2227 if ( @$values[$i] eq "" ) {
2231 my $ind1 = substr( @$indicator[$j], 0, 1 );
2232 my $ind2 = substr( @$indicator[$j], 1, 1 );
2234 "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
2238 "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2241 $prevtag = @$tags[$i];
2243 if (C4::Context->preference('marcflavour') and !$unimarc_and_100_exist) {
2244 # warn "SETTING 100 for $auth_type";
2245 use POSIX qw(strftime);
2246 my $string = strftime( "%Y%m%d", localtime(time) );
2247 # set 50 to position 26 is biblios, 13 if authorities
2249 $pos=13 if $auth_type eq 'UNIMARCAUTH';
2250 $string = sprintf( "%-*s", 35, $string );
2251 substr( $string, $pos , 6, "50" );
2252 $xml .= "<datafield tag=\"100\" ind1=\"\" ind2=\"\">\n";
2253 $xml .= "<subfield code=\"a\">$string</subfield>\n";
2254 $xml .= "</datafield>\n";
2256 $xml .= MARC::File::XML::footer();
2260 =head2 TransformHtmlToMarc
2262 L<$record> = TransformHtmlToMarc(L<$params>,L<$cgi>)
2263 L<$params> is a ref to an array as below:
2265 'tag_010_indicator_531951' ,
2266 'tag_010_code_a_531951_145735' ,
2267 'tag_010_subfield_a_531951_145735' ,
2268 'tag_200_indicator_873510' ,
2269 'tag_200_code_a_873510_673465' ,
2270 'tag_200_subfield_a_873510_673465' ,
2271 'tag_200_code_b_873510_704318' ,
2272 'tag_200_subfield_b_873510_704318' ,
2273 'tag_200_code_e_873510_280822' ,
2274 'tag_200_subfield_e_873510_280822' ,
2275 'tag_200_code_f_873510_110730' ,
2276 'tag_200_subfield_f_873510_110730' ,
2278 L<$cgi> is the CGI object which containts the value.
2279 L<$record> is the MARC::Record object.
2283 sub TransformHtmlToMarc {
2287 # creating a new record
2288 my $record = MARC::Record->new();
2291 while ($params->[$i]){ # browse all CGI params
2292 my $param = $params->[$i];
2294 # if we are on biblionumber, store it in the MARC::Record (it may not be in the edited fields)
2295 if ($param eq 'biblionumber') {
2296 my ( $biblionumbertagfield, $biblionumbertagsubfield ) =
2297 &GetMarcFromKohaField( "biblio.biblionumber", '' );
2298 if ($biblionumbertagfield < 10) {
2299 $newfield = MARC::Field->new(
2300 $biblionumbertagfield,
2301 $cgi->param($param),
2304 $newfield = MARC::Field->new(
2305 $biblionumbertagfield,
2308 "$biblionumbertagsubfield" => $cgi->param($param),
2311 push @fields,$newfield if($newfield);
2313 elsif ($param =~ /^tag_(\d*)_indicator_/){ # new field start when having 'input name="..._indicator_..."
2316 my $ind1 = substr($cgi->param($param),0,1);
2317 my $ind2 = substr($cgi->param($param),1,1);
2321 if($tag < 10){ # no code for theses fields
2322 # in MARC editor, 000 contains the leader.
2323 if ($tag eq '000' ) {
2324 $record->leader($cgi->param($params->[$j+1])) if length($cgi->param($params->[$j+1]))==24;
2325 # between 001 and 009 (included)
2327 $newfield = MARC::Field->new(
2329 $cgi->param($params->[$j+1]),
2332 # > 009, deal with subfields
2334 while($params->[$j] =~ /_code_/){ # browse all it's subfield
2335 my $inner_param = $params->[$j];
2337 if($cgi->param($params->[$j+1])){ # only if there is a value (code => value)
2338 $newfield->add_subfields(
2339 $cgi->param($inner_param) => $cgi->param($params->[$j+1])
2343 if ( $cgi->param($params->[$j+1]) ) { # creating only if there is a value (code => value)
2344 $newfield = MARC::Field->new(
2348 $cgi->param($inner_param) => $cgi->param($params->[$j+1]),
2355 push @fields,$newfield if($newfield);
2360 $record->append_fields(@fields);
2364 =head2 TransformMarcToKoha
2368 $result = TransformMarcToKoha( $dbh, $record, $frameworkcode )
2374 sub TransformMarcToKoha {
2375 my ( $dbh, $record, $frameworkcode ) = @_;
2377 # FIXME :: This query is unused..
2380 #"select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
2384 my $sth2 = $dbh->prepare("SHOW COLUMNS from biblio");
2387 while ( ($field) = $sth2->fetchrow ) {
2389 &TransformMarcToKohaOneField( "biblio", $field, $record, $result,
2392 my $sth2 = $dbh->prepare("SHOW COLUMNS from biblioitems");
2394 while ( ($field) = $sth2->fetchrow ) {
2395 if ( $field eq 'notes' ) { $field = 'bnotes'; }
2397 &TransformMarcToKohaOneField( "biblioitems", $field, $record, $result,
2400 $sth2 = $dbh->prepare("SHOW COLUMNS from items");
2402 while ( ($field) = $sth2->fetchrow ) {
2404 &TransformMarcToKohaOneField( "items", $field, $record, $result,
2409 # modify copyrightdate to keep only the 1st year found
2410 my $temp = $result->{'copyrightdate'};
2411 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
2413 $result->{'copyrightdate'} = $1;
2415 else { # if no cYYYY, get the 1st date.
2416 $temp =~ m/(\d\d\d\d)/;
2417 $result->{'copyrightdate'} = $1;
2420 # modify publicationyear to keep only the 1st year found
2421 $temp = $result->{'publicationyear'};
2422 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
2424 $result->{'publicationyear'} = $1;
2426 else { # if no cYYYY, get the 1st date.
2427 $temp =~ m/(\d\d\d\d)/;
2428 $result->{'publicationyear'} = $1;
2433 =head2 TransformMarcToKohaOneField
2437 $result = TransformMarcToKohaOneField( $kohatable, $kohafield, $record, $result, $frameworkcode )
2443 sub TransformMarcToKohaOneField {
2445 # FIXME ? if a field has a repeatable subfield that is used in old-db,
2446 # only the 1st will be retrieved...
2447 my ( $kohatable, $kohafield, $record, $result, $frameworkcode ) = @_;
2449 my ( $tagfield, $subfield ) =
2450 GetMarcFromKohaField( $kohatable . "." . $kohafield,
2452 foreach my $field ( $record->field($tagfield) ) {
2453 if ( $field->tag() < 10 ) {
2454 if ( $result->{$kohafield} ) {
2455 $result->{$kohafield} .= " | " . $field->data();
2458 $result->{$kohafield} = $field->data();
2462 if ( $field->subfields ) {
2463 my @subfields = $field->subfields();
2464 foreach my $subfieldcount ( 0 .. $#subfields ) {
2465 if ( $subfields[$subfieldcount][0] eq $subfield ) {
2466 if ( $result->{$kohafield} ) {
2467 $result->{$kohafield} .=
2468 " | " . $subfields[$subfieldcount][1];
2471 $result->{$kohafield} =
2472 $subfields[$subfieldcount][1];
2482 =head1 OTHER FUNCTIONS
2488 my $string = char_decode( $string, $encoding );
2490 converts ISO 5426 coded string to UTF-8
2491 sloppy code : should be improved in next issue
2498 my ( $string, $encoding ) = @_;
2501 $encoding = C4::Context->preference("marcflavour") unless $encoding;
2502 if ( $encoding eq "UNIMARC" ) {
2572 # this handles non-sorting blocks (if implementation requires this)
2573 $string = nsb_clean($_);
2575 elsif ( $encoding eq "USMARC" || $encoding eq "MARC21" ) {
2634 #Additional Turkish characters
2637 s/(\xf0)s/\xc5\x9f/gm;
2638 s/(\xf0)S/\xc5\x9e/gm;
2641 s/\xe7\x49/\\xc4\xb0/gm;
2642 s/(\xe6)G/\xc4\x9e/gm;
2643 s/(\xe6)g/ğ\xc4\x9f/gm;
2646 s/(\xe8|\xc8)o/ö/gm;
2647 s/(\xe8|\xc8)O/Ö/gm;
2648 s/(\xe8|\xc8)u/ü/gm;
2649 s/(\xe8|\xc8)U/Ü/gm;
2650 s/\xc2\xb8/\xc4\xb1/gm;
2653 # this handles non-sorting blocks (if implementation requires this)
2654 $string = nsb_clean($_);
2663 my $string = nsb_clean( $string, $encoding );
2670 my $NSB = '\x88'; # NSB : begin Non Sorting Block
2671 my $NSE = '\x89'; # NSE : Non Sorting Block end
2672 # handles non sorting blocks
2676 s/[ ]{0,1}$NSE/) /gm;
2681 =head2 PrepareItemrecordDisplay
2685 PrepareItemrecordDisplay($itemrecord,$bibnum,$itemumber);
2687 Returns a hash with all the fields for Display a given item data in a template
2693 sub PrepareItemrecordDisplay {
2695 my ( $bibnum, $itemnum ) = @_;
2697 my $dbh = C4::Context->dbh;
2698 my $frameworkcode = &GetFrameworkCode( $bibnum );
2699 my ( $itemtagfield, $itemtagsubfield ) =
2700 &GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2701 my $tagslib = &GetMarcStructure( 1, $frameworkcode );
2702 my $itemrecord = GetMarcItem( $bibnum, $itemnum) if ($itemnum);
2704 my $authorised_values_sth =
2706 "select authorised_value,lib from authorised_values where category=? order by lib"
2708 foreach my $tag ( sort keys %{$tagslib} ) {
2709 my $previous_tag = '';
2711 # loop through each subfield
2713 foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
2714 next if ( subfield_is_koha_internal_p($subfield) );
2715 next if ( $tagslib->{$tag}->{$subfield}->{'tab'} ne "10" );
2717 $subfield_data{tag} = $tag;
2718 $subfield_data{subfield} = $subfield;
2719 $subfield_data{countsubfield} = $cntsubf++;
2720 $subfield_data{kohafield} =
2721 $tagslib->{$tag}->{$subfield}->{'kohafield'};
2723 # $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
2724 $subfield_data{marc_lib} =
2725 "<span id=\"error\" title=\""
2726 . $tagslib->{$tag}->{$subfield}->{lib} . "\">"
2727 . substr( $tagslib->{$tag}->{$subfield}->{lib}, 0, 12 )
2729 $subfield_data{mandatory} =
2730 $tagslib->{$tag}->{$subfield}->{mandatory};
2731 $subfield_data{repeatable} =
2732 $tagslib->{$tag}->{$subfield}->{repeatable};
2733 $subfield_data{hidden} = "display:none"
2734 if $tagslib->{$tag}->{$subfield}->{hidden};
2736 ( $x, $value ) = _find_value( $tag, $subfield, $itemrecord )
2738 $value =~ s/"/"/g;
2740 # search for itemcallnumber if applicable
2741 if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
2742 'items.itemcallnumber'
2743 && C4::Context->preference('itemcallnumber') )
2746 substr( C4::Context->preference('itemcallnumber'), 0, 3 );
2748 substr( C4::Context->preference('itemcallnumber'), 3, 1 );
2749 my $temp = $itemrecord->field($CNtag) if ($itemrecord);
2751 $value = $temp->subfield($CNsubfield);
2754 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
2755 my @authorised_values;
2758 # builds list, depending on authorised value...
2760 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq
2763 if ( ( C4::Context->preference("IndependantBranches") )
2764 && ( C4::Context->userenv->{flags} != 1 ) )
2768 "select branchcode,branchname from branches where branchcode = ? order by branchname"
2770 $sth->execute( C4::Context->userenv->{branch} );
2771 push @authorised_values, ""
2773 $tagslib->{$tag}->{$subfield}->{mandatory} );
2774 while ( my ( $branchcode, $branchname ) =
2775 $sth->fetchrow_array )
2777 push @authorised_values, $branchcode;
2778 $authorised_lib{$branchcode} = $branchname;
2784 "select branchcode,branchname from branches order by branchname"
2787 push @authorised_values, ""
2789 $tagslib->{$tag}->{$subfield}->{mandatory} );
2790 while ( my ( $branchcode, $branchname ) =
2791 $sth->fetchrow_array )
2793 push @authorised_values, $branchcode;
2794 $authorised_lib{$branchcode} = $branchname;
2800 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq
2805 "select itemtype,description from itemtypes order by description"
2808 push @authorised_values, ""
2809 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2810 while ( my ( $itemtype, $description ) =
2811 $sth->fetchrow_array )
2813 push @authorised_values, $itemtype;
2814 $authorised_lib{$itemtype} = $description;
2817 #---- "true" authorised value
2820 $authorised_values_sth->execute(
2821 $tagslib->{$tag}->{$subfield}->{authorised_value} );
2822 push @authorised_values, ""
2823 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2824 while ( my ( $value, $lib ) =
2825 $authorised_values_sth->fetchrow_array )
2827 push @authorised_values, $value;
2828 $authorised_lib{$value} = $lib;
2831 $subfield_data{marc_value} = CGI::scrolling_list(
2832 -name => 'field_value',
2833 -values => \@authorised_values,
2834 -default => "$value",
2835 -labels => \%authorised_lib,
2841 elsif ( $tagslib->{$tag}->{$subfield}->{thesaurus_category} ) {
2842 $subfield_data{marc_value} =
2843 "<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>";
2846 # COMMENTED OUT because No $i is provided with this API.
2847 # And thus, no value_builder can be activated.
2848 # BUT could be thought over.
2849 # } elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
2850 # my $plugin="value_builder/".$tagslib->{$tag}->{$subfield}->{'value_builder'};
2852 # my $extended_param = plugin_parameters($dbh,$itemrecord,$tagslib,$i,0);
2853 # my ($function_name,$javascript) = plugin_javascript($dbh,$record,$tagslib,$i,0);
2854 # $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";
2857 $subfield_data{marc_value} =
2858 "<input type=\"text\" name=\"field_value\" value=\"$value\" size=50 maxlength=255>";
2860 push( @loop_data, \%subfield_data );
2864 my $itemnumber = $itemrecord->subfield( $itemtagfield, $itemtagsubfield )
2865 if ( $itemrecord && $itemrecord->field($itemtagfield) );
2867 'itemtagfield' => $itemtagfield,
2868 'itemtagsubfield' => $itemtagsubfield,
2869 'itemnumber' => $itemnumber,
2870 'iteminformation' => \@loop_data
2876 # true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates
2878 # replaced by a zebraqueue table, that is filled with ModZebra to run.
2879 # the table is emptied by misc/cronjobs/zebraqueue_start.pl script
2880 # =head2 ModZebrafiles
2882 # &ModZebrafiles( $dbh, $biblionumber, $record, $folder, $server );
2886 # sub ModZebrafiles {
2888 # my ( $dbh, $biblionumber, $record, $folder, $server ) = @_;
2892 # C4::Context->zebraconfig($server)->{directory} . "/" . $folder . "/";
2893 # unless ( opendir( DIR, "$zebradir" ) ) {
2894 # warn "$zebradir not found";
2898 # my $filename = $zebradir . $biblionumber;
2901 # open( OUTPUT, ">", $filename . ".xml" );
2902 # print OUTPUT $record;
2911 ModZebra( $biblionumber, $op, $server, $newRecord );
2913 $biblionumber is the biblionumber we want to index
2914 $op is specialUpdate or delete, and is used to know what we want to do
2915 $server is the server that we want to update
2916 $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.
2923 ###Accepts a $server variable thus we can use it for biblios authorities or other zebra dbs
2924 my ( $biblionumber, $op, $server, $newRecord ) = @_;
2925 my $dbh=C4::Context->dbh;
2927 # true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates
2929 # replaced by a zebraqueue table, that is filled with ModZebra to run.
2930 # the table is emptied by misc/cronjobs/zebraqueue_start.pl script
2932 if (C4::Context->preference("NoZebra")) {
2933 # lock the nozebra table : we will read index lines, update them in Perl process
2934 # and write everything in 1 transaction.
2935 # lock the table to avoid someone else overwriting what we are doing
2936 $dbh->do('LOCK TABLES nozebra WRITE,biblio WRITE,biblioitems WRITE, systempreferences WRITE, auth_types WRITE, auth_header WRITE');
2937 my %result; # the result hash that will be builded by deletion / add, and written on mySQL at the end, to improve speed
2939 if ($server eq 'biblioserver') {
2940 $record= GetMarcBiblio($biblionumber);
2942 $record= C4::AuthoritiesMarc::GetAuthority($biblionumber);
2944 if ($op eq 'specialUpdate') {
2945 # OK, we have to add or update the record
2946 # 1st delete (virtually, in indexes) ...
2947 %result = _DelBiblioNoZebra($biblionumber,$record,$server);
2948 # ... add the record
2949 %result=_AddBiblioNoZebra($biblionumber,$newRecord, $server, %result);
2951 # it's a deletion, delete the record...
2952 # warn "DELETE the record $biblionumber on $server".$record->as_formatted;
2953 %result=_DelBiblioNoZebra($biblionumber,$record,$server);
2955 # ok, now update the database...
2956 my $sth = $dbh->prepare("UPDATE nozebra SET biblionumbers=? WHERE server=? AND indexname=? AND value=?");
2957 foreach my $key (keys %result) {
2958 foreach my $index (keys %{$result{$key}}) {
2959 $sth->execute($result{$key}->{$index}, $server, $key, $index);
2962 $dbh->do('UNLOCK TABLES');
2966 # we use zebra, just fill zebraqueue table
2968 my $sth=$dbh->prepare("insert into zebraqueue (biblio_auth_number ,server,operation) values(?,?,?)");
2969 $sth->execute($biblionumber,$server,$op);
2974 =head2 GetNoZebraIndexes
2976 %indexes = GetNoZebraIndexes;
2978 return the data from NoZebraIndexes syspref.
2982 sub GetNoZebraIndexes {
2983 my $index = C4::Context->preference('NoZebraIndexes');
2985 foreach my $line (split /('|"),/,$index) {
2986 $line =~ /(.*)=>(.*)/;
2987 my $index = substr($1,1); # get the index, don't forget to remove initial ' or "
2989 $index =~ s/'|"| //g;
2990 $fields =~ s/'|"| //g;
2991 $indexes{$index}=$fields;
2996 =head1 INTERNAL FUNCTIONS
2998 =head2 _DelBiblioNoZebra($biblionumber,$record,$server);
3000 function to delete a biblio in NoZebra indexes
3001 This function does NOT delete anything in database : it reads all the indexes entries
3002 that have to be deleted & delete them in the hash
3003 The SQL part is done either :
3004 - after the Add if we are modifying a biblio (delete + add again)
3005 - immediatly after this sub if we are doing a true deletion.
3006 $server can be 'biblioserver' or 'authorityserver' : it indexes biblios or authorities (in the same table, $server being part of the table itself
3011 sub _DelBiblioNoZebra {
3012 my ($biblionumber, $record, $server)=@_;
3015 my $dbh = C4::Context->dbh;
3019 if ($server eq 'biblioserver') {
3020 %index=GetNoZebraIndexes;
3021 # get title of the record (to store the 10 first letters with the index)
3022 my ($titletag,$titlesubfield) = GetMarcFromKohaField('biblio.title');
3023 $title = lc($record->subfield($titletag,$titlesubfield));
3025 # for authorities, the "title" is the $a mainentry
3026 my $authref = C4::AuthoritiesMarc::GetAuthType($record->subfield(152,'b'));
3027 warn "ERROR : authtype undefined for ".$record->as_formatted unless $authref;
3028 $title = $record->subfield($authref->{auth_tag_to_report},'a');
3029 $index{'mainmainentry'}= $authref->{'auth_tag_to_report'}.'a';
3030 $index{'mainentry'} = $authref->{'auth_tag_to_report'}.'*';
3031 $index{'auth_type'} = '152b';
3035 # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
3036 $title =~ s/ |,|;|\[|\]|\(|\)|\*|-|'|=//g;
3037 # limit to 10 char, should be enough, and limit the DB size
3038 $title = substr($title,0,10);
3040 my $sth2=$dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
3041 foreach my $field ($record->fields()) {
3042 #parse each subfield
3043 next if $field->tag <10;
3044 foreach my $subfield ($field->subfields()) {
3045 my $tag = $field->tag();
3046 my $subfieldcode = $subfield->[0];
3048 # check each index to see if the subfield is stored somewhere
3049 # otherwise, store it in __RAW__ index
3050 foreach my $key (keys %index) {
3051 # warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
3052 if ($index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/) {
3054 my $line= lc $subfield->[1];
3055 # remove meaningless value in the field...
3056 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
3057 # ... and split in words
3058 foreach (split / /,$line) {
3059 next unless $_; # skip empty values (multiple spaces)
3060 # if the entry is already here, do nothing, the biblionumber has already be removed
3061 unless ($result{$key}->{$_} =~ /$biblionumber,$title\-(\d);/) {
3062 # get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
3063 $sth2->execute($server,$key,$_);
3064 my $existing_biblionumbers = $sth2->fetchrow;
3066 if ($existing_biblionumbers) {
3067 # warn " existing for $key $_: $existing_biblionumbers";
3068 $result{$key}->{$_} =$existing_biblionumbers;
3069 $result{$key}->{$_} =~ s/$biblionumber,$title\-(\d);//;
3075 # the subfield is not indexed, store it in __RAW__ index anyway
3077 my $line= lc $subfield->[1];
3078 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
3079 # ... and split in words
3080 foreach (split / /,$line) {
3081 next unless $_; # skip empty values (multiple spaces)
3082 # if the entry is already here, do nothing, the biblionumber has already be removed
3083 unless ($result{'__RAW__'}->{$_} =~ /$biblionumber,$title\-(\d);/) {
3084 # get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
3085 $sth2->execute($server,'__RAW__',$_);
3086 my $existing_biblionumbers = $sth2->fetchrow;
3088 if ($existing_biblionumbers) {
3089 $result{'__RAW__'}->{$_} =$existing_biblionumbers;
3090 $result{'__RAW__'}->{$_} =~ s/$biblionumber,$title\-(\d);//;
3100 =head2 _AddBiblioNoZebra($biblionumber, $record, $server, %result);
3102 function to add a biblio in NoZebra indexes
3106 sub _AddBiblioNoZebra {
3107 my ($biblionumber, $record, $server, %result)=@_;
3108 my $dbh = C4::Context->dbh;
3112 if ($server eq 'biblioserver') {
3113 %index=GetNoZebraIndexes;
3114 # get title of the record (to store the 10 first letters with the index)
3115 my ($titletag,$titlesubfield) = GetMarcFromKohaField('biblio.title');
3116 $title = lc($record->subfield($titletag,$titlesubfield));
3118 # warn "server : $server";
3119 # for authorities, the "title" is the $a mainentry
3120 my $authref = C4::AuthoritiesMarc::GetAuthType($record->subfield(152,'b'));
3121 warn "ERROR : authtype undefined for ".$record->as_formatted unless $authref;
3122 $title = $record->subfield($authref->{auth_tag_to_report},'a');
3123 $index{'mainmainentry'} = $authref->{auth_tag_to_report}.'a';
3124 $index{'mainentry'} = $authref->{auth_tag_to_report}.'*';
3125 $index{'auth_type'} = '152b';
3128 # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
3129 $title =~ s/ |,|;|\[|\]|\(|\)|\*|-|'|=//g;
3130 # limit to 10 char, should be enough, and limit the DB size
3131 $title = substr($title,0,10);
3133 my $sth2=$dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
3134 foreach my $field ($record->fields()) {
3135 #parse each subfield
3136 next if $field->tag <10;
3137 foreach my $subfield ($field->subfields()) {
3138 my $tag = $field->tag();
3139 my $subfieldcode = $subfield->[0];
3141 # check each index to see if the subfield is stored somewhere
3142 # otherwise, store it in __RAW__ index
3143 foreach my $key (keys %index) {
3144 # warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
3145 if ($index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/) {
3147 my $line= lc $subfield->[1];
3148 # remove meaningless value in the field...
3149 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
3150 # ... and split in words
3151 foreach (split / /,$line) {
3152 next unless $_; # skip empty values (multiple spaces)
3153 # if the entry is already here, improve weight
3154 # warn "managing $_";
3155 if ($result{$key}->{"$_"} =~ /$biblionumber,$title\-(\d);/) {
3157 $result{$key}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
3158 $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
3160 # get the value if it exist in the nozebra table, otherwise, create it
3161 $sth2->execute($server,$key,$_);
3162 my $existing_biblionumbers = $sth2->fetchrow;
3164 if ($existing_biblionumbers) {
3165 $result{$key}->{"$_"} =$existing_biblionumbers;
3167 $result{$key}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
3168 $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
3169 # create a new ligne for this entry
3171 # warn "INSERT : $server / $key / $_";
3172 $dbh->do('INSERT INTO nozebra SET server='.$dbh->quote($server).', indexname='.$dbh->quote($key).',value='.$dbh->quote($_));
3173 $result{$key}->{"$_"}.="$biblionumber,$title-1;";
3179 # the subfield is not indexed, store it in __RAW__ index anyway
3181 my $line= lc $subfield->[1];
3182 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
3183 # ... and split in words
3184 foreach (split / /,$line) {
3185 next unless $_; # skip empty values (multiple spaces)
3186 # if the entry is already here, improve weight
3187 if ($result{'__RAW__'}->{"$_"} =~ /$biblionumber,$title\-(\d);/) {
3189 $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
3190 $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
3192 # get the value if it exist in the nozebra table, otherwise, create it
3193 $sth2->execute($server,'__RAW__',$_);
3194 my $existing_biblionumbers = $sth2->fetchrow;
3196 if ($existing_biblionumbers) {
3197 $result{'__RAW__'}->{"$_"} =$existing_biblionumbers;
3199 $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
3200 $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
3201 # create a new ligne for this entry
3203 $dbh->do('INSERT INTO nozebra SET server='.$dbh->quote($server).', indexname="__RAW__",value='.$dbh->quote($_));
3204 $result{'__RAW__'}->{"$_"}.="$biblionumber,$title-1;";
3215 =head2 MARCitemchange
3219 &MARCitemchange( $record, $itemfield, $newvalue )
3221 Function to update a single value in an item field.
3222 Used twice, could probably be replaced by something else, but works well...
3230 sub MARCitemchange {
3231 my ( $record, $itemfield, $newvalue ) = @_;
3232 my $dbh = C4::Context->dbh;
3234 my ( $tagfield, $tagsubfield ) =
3235 GetMarcFromKohaField( $itemfield, "" );
3236 if ( ($tagfield) && ($tagsubfield) ) {
3237 my $tag = $record->field($tagfield);
3239 $tag->update( $tagsubfield => $newvalue );
3240 $record->delete_field($tag);
3241 $record->insert_fields_ordered($tag);
3246 =head2 _koha_add_biblio
3250 _koha_add_biblio($dbh,$biblioitem);
3252 Internal function to add a biblio ($biblio is a hash with the values)
3258 sub _koha_add_biblio {
3259 my ( $dbh, $biblio, $frameworkcode ) = @_;
3260 my $sth = $dbh->prepare("Select max(biblionumber) from biblio");
3262 my $data = $sth->fetchrow_arrayref;
3263 my $biblionumber = $$data[0] + 1;
3266 if ( $biblio->{'seriestitle'} ) { $series = 1 }
3268 $sth = $dbh->prepare(
3270 SET biblionumber = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?, unititle = ?, frameworkcode = ? "
3273 $biblionumber, $biblio->{'title'},
3274 $biblio->{'author'}, $biblio->{'copyrightdate'},
3275 $biblio->{'serial'}, $biblio->{'seriestitle'},
3276 $biblio->{'notes'}, $biblio->{'abstract'},
3277 $biblio->{'unititle'}, $frameworkcode
3281 return ($biblionumber);
3288 ($indicators, $value) = _find_value($tag, $subfield, $record,$encoding);
3290 Find the given $subfield in the given $tag in the given
3291 MARC::Record $record. If the subfield is found, returns
3292 the (indicators, value) pair; otherwise, (undef, undef) is
3296 Such a function is used in addbiblio AND additem and serial-edit and maybe could be used in Authorities.
3297 I suggest we export it from this module.
3304 my ( $tagfield, $insubfield, $record, $encoding ) = @_;
3307 if ( $tagfield < 10 ) {
3308 if ( $record->field($tagfield) ) {
3309 push @result, $record->field($tagfield)->data();
3316 foreach my $field ( $record->field($tagfield) ) {
3317 my @subfields = $field->subfields();
3318 foreach my $subfield (@subfields) {
3319 if ( @$subfield[0] eq $insubfield ) {
3320 push @result, @$subfield[1];
3321 $indicator = $field->indicator(1) . $field->indicator(2);
3326 return ( $indicator, @result );
3329 =head2 _koha_modify_biblio
3333 $biblionumber = _koha_modify_biblio($dbh,$biblio);
3334 Internal function for updating the biblio table
3340 sub _koha_modify_biblio {
3341 my ( $dbh, $biblio ) = @_;
3342 # FIXME: this code could be made more portable by not hard-coding
3343 # the values that are supposed to be in biblio table
3354 WHERE biblionumber = ?
3356 my $sth = $dbh->prepare($query);
3360 $biblio->{'author'},
3361 $biblio->{'abstract'},
3362 $biblio->{'copyrightdate'},
3363 $biblio->{'seriestitle'},
3364 $biblio->{'serial'},
3365 $biblio->{'unititle'},
3367 $biblio->{'biblionumber'}
3368 ) if $biblio->{'biblionumber'};
3370 warn $sth->err if $sth->err;
3371 warn "BIG ERROR :: No biblionumber for $biblio->{title}" if $biblio->{biblionumber} !~ /\d+/; # if it is not a number
3372 return ( $biblio->{'biblionumber'} );
3375 =head2 _koha_modify_biblioitem
3379 _koha_modify_biblioitem( $dbh, $biblioitem );
3385 sub _koha_modify_biblioitem {
3386 my ( $dbh, $biblioitem ) = @_;
3388 ##Recalculate LC in case it changed --TG
3390 $biblioitem->{'itemtype'} = $dbh->quote( $biblioitem->{'itemtype'} );
3391 $biblioitem->{'url'} = $dbh->quote( $biblioitem->{'url'} );
3392 $biblioitem->{'isbn'} = $dbh->quote( $biblioitem->{'isbn'} );
3393 $biblioitem->{'issn'} = $dbh->quote( $biblioitem->{'issn'} );
3394 $biblioitem->{'publishercode'} =
3395 $dbh->quote( $biblioitem->{'publishercode'} );
3396 $biblioitem->{'publicationyear'} =
3397 $dbh->quote( $biblioitem->{'publicationyear'} );
3398 $biblioitem->{'classification'} =
3399 $dbh->quote( $biblioitem->{'classification'} );
3400 $biblioitem->{'dewey'} = $dbh->quote( $biblioitem->{'dewey'} );
3401 $biblioitem->{'subclass'} = $dbh->quote( $biblioitem->{'subclass'} );
3402 $biblioitem->{'illus'} = $dbh->quote( $biblioitem->{'illus'} );
3403 $biblioitem->{'pages'} = $dbh->quote( $biblioitem->{'pages'} );
3404 $biblioitem->{'volumeddesc'} = $dbh->quote( $biblioitem->{'volumeddesc'} );
3405 $biblioitem->{'bnotes'} = $dbh->quote( $biblioitem->{'bnotes'} );
3406 $biblioitem->{'size'} = $dbh->quote( $biblioitem->{'size'} );
3407 $biblioitem->{'place'} = $dbh->quote( $biblioitem->{'place'} );
3408 $biblioitem->{'collectiontitle'} = $dbh->quote( $biblioitem->{'collectiontitle'} );
3409 $biblioitem->{'collectionissn'} = $dbh->quote( $biblioitem->{'collectionissn'} );
3410 $biblioitem->{'collectionvolume'} = $dbh->quote( $biblioitem->{'collectionvolume'} );
3411 $biblioitem->{'editionstatement'} = $dbh->quote( $biblioitem->{'editionstatement'} );
3412 $biblioitem->{'editionresponsibility'} = $dbh->quote( $biblioitem->{'editionresponsibility'} );
3413 $biblioitem->{'ccode'} = $dbh->quote( $biblioitem->{'ccode'} );
3414 $biblioitem->{'biblionumber'} =
3415 $dbh->quote( $biblioitem->{'biblionumber'} );
3417 $query = "UPDATE biblioitems SET
3418 itemtype = $biblioitem->{'itemtype'},
3419 url = $biblioitem->{'url'},
3420 isbn = $biblioitem->{'isbn'},
3421 issn = $biblioitem->{'issn'},
3422 publishercode = $biblioitem->{'publishercode'},
3423 publicationyear = $biblioitem->{'publicationyear'},
3424 classification = $biblioitem->{'classification'},
3425 dewey = $biblioitem->{'dewey'},
3426 subclass = $biblioitem->{'subclass'},
3427 illus = $biblioitem->{'illus'},
3428 pages = $biblioitem->{'pages'},
3429 volumeddesc = $biblioitem->{'volumeddesc'},
3430 notes = $biblioitem->{'bnotes'},
3431 size = $biblioitem->{'size'},
3432 place = $biblioitem->{'place'},
3433 collectiontitle = $biblioitem->{'collectiontitle'},
3434 collectionissn = $biblioitem->{'collectionissn'},
3435 collectionvolume= $biblioitem->{'collectionvolume'},
3436 editionstatement= $biblioitem->{'editionstatement'},
3437 editionresponsibility= $biblioitem->{'editionresponsibility'},
3438 ccode = $biblioitem->{'ccode'}
3439 where biblionumber = $biblioitem->{'biblionumber'}";
3442 if ( $dbh->errstr ) {
3443 warn "ERROR in _koha_modify_biblioitem $query";
3447 =head2 _koha_add_biblioitem
3451 _koha_add_biblioitem( $dbh, $biblioitem );
3453 Internal function to add a biblioitem
3459 sub _koha_add_biblioitem {
3460 my ( $dbh, $biblioitem ) = @_;
3462 # my $dbh = C4Connect;
3463 my $sth = $dbh->prepare("SELECT max(biblioitemnumber) FROM biblioitems");
3468 $data = $sth->fetchrow_arrayref;
3469 $bibitemnum = $$data[0] + 1;
3473 $sth = $dbh->prepare(
3474 "INSERT INTO biblioitems SET
3475 biblioitemnumber = ?, biblionumber = ?,
3476 volume = ?, number = ?,
3477 classification = ?, itemtype = ?,
3479 issn = ?, dewey = ?,
3480 subclass = ?, publicationyear = ?,
3481 publishercode = ?, volumedate = ?,
3482 volumeddesc = ?, illus = ?,
3483 pages = ?, notes = ?,
3485 marc = ?, lcsort = ?,
3486 place = ?, ccode = ?,
3487 collectiontitle = ?, collectionissn = ?,
3488 collectionvolume = ?, editionstatement= ?,
3489 editionresponsibility= ?
3493 calculatelc( $biblioitem->{'classification'} )
3494 . $biblioitem->{'subclass'};
3496 $bibitemnum, $biblioitem->{'biblionumber'},
3497 $biblioitem->{'volume'}, $biblioitem->{'number'},
3498 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
3499 $biblioitem->{'url'}, $biblioitem->{'isbn'},
3500 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
3501 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
3502 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
3503 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
3504 $biblioitem->{'pages'}, $biblioitem->{'bnotes'},
3505 $biblioitem->{'size'}, $biblioitem->{'lccn'},
3506 $biblioitem->{'marc'}, $biblioitem->{'place'},
3507 $lcsort, $biblioitem->{'ccode'},
3508 $biblioitem->{'collectiontitle'},$biblioitem->{'collectionissn'},
3509 $biblioitem->{'collectionvolume'},$biblioitem->{'editionstatement'},
3510 $biblioitem->{'editionresponsibility'}
3513 return ($bibitemnum);
3516 =head2 _koha_new_items
3520 _koha_new_items( $dbh, $item, $barcode );
3526 sub _koha_new_items {
3527 my ( $dbh, $item, $barcode ) = @_;
3529 # my $dbh = C4Connect;
3530 my $sth = $dbh->prepare("Select max(itemnumber) from items");
3536 $data = $sth->fetchrow_hashref;
3537 $itemnumber = $data->{'max(itemnumber)'} + 1;
3539 ## Now calculate lccalnumber
3540 my ($cutterextra) = itemcalculator(
3542 $item->{'biblioitemnumber'},
3543 $item->{'itemcallnumber'}
3546 # FIXME the "notforloan" field seems to be named "loan" in some places. workaround bugfix.
3547 if ( $item->{'loan'} ) {
3548 $item->{'notforloan'} = $item->{'loan'};
3551 # if dateaccessioned is provided, use it. Otherwise, set to NOW()
3552 if ( $item->{'dateaccessioned'} eq '' || !$item->{'dateaccessioned'} ) {
3554 $sth = $dbh->prepare(
3555 "Insert into items set
3556 itemnumber = ?, biblionumber = ?,
3557 multivolumepart = ?,
3558 biblioitemnumber = ?, barcode = ?,
3559 booksellerid = ?, dateaccessioned = NOW(),
3560 homebranch = ?, holdingbranch = ?,
3561 price = ?, replacementprice = ?,
3562 replacementpricedate = NOW(), datelastseen = NOW(),
3563 multivolume = ?, stack = ?,
3564 itemlost = ?, wthdrawn = ?,
3565 paidfor = ?, itemnotes = ?,
3566 itemcallnumber =?, notforloan = ?,
3567 location = ?, Cutterextra = ?
3571 $itemnumber, $item->{'biblionumber'},
3572 $item->{'multivolumepart'}, $item->{'biblioitemnumber'},
3573 $barcode, $item->{'booksellerid'},
3574 $item->{'homebranch'}, $item->{'holdingbranch'},
3575 $item->{'price'}, $item->{'replacementprice'},
3576 $item->{multivolume}, $item->{stack},
3577 $item->{itemlost}, $item->{wthdrawn},
3578 $item->{paidfor}, $item->{'itemnotes'},
3579 $item->{'itemcallnumber'}, $item->{'notforloan'},
3580 $item->{'location'}, $cutterextra
3584 $sth = $dbh->prepare(
3585 "INSERT INTO items SET
3586 itemnumber = ?, biblionumber = ?,
3587 multivolumepart = ?,
3588 biblioitemnumber = ?, barcode = ?,
3589 booksellerid = ?, dateaccessioned = ?,
3590 homebranch = ?, holdingbranch = ?,
3591 price = ?, replacementprice = ?,
3592 replacementpricedate = NOW(), datelastseen = NOW(),
3593 multivolume = ?, stack = ?,
3594 itemlost = ?, wthdrawn = ?,
3595 paidfor = ?, itemnotes = ?,
3596 itemcallnumber = ?, notforloan = ?,
3602 $itemnumber, $item->{'biblionumber'},
3603 $item->{'multivolumepart'}, $item->{'biblioitemnumber'},
3604 $barcode, $item->{'booksellerid'},
3605 $item->{'dateaccessioned'}, $item->{'homebranch'},
3606 $item->{'holdingbranch'}, $item->{'price'},
3607 $item->{'replacementprice'}, $item->{multivolume},
3608 $item->{stack}, $item->{itemlost},
3609 $item->{wthdrawn}, $item->{paidfor},
3610 $item->{'itemnotes'}, $item->{'itemcallnumber'},
3611 $item->{'notforloan'}, $item->{'location'},
3615 if ( defined $sth->errstr ) {
3616 $error .= $sth->errstr;
3618 return ( $itemnumber, $error );
3621 =head2 _koha_modify_item
3625 _koha_modify_item( $dbh, $item, $op );
3631 sub _koha_modify_item {
3632 my ( $dbh, $item, $op ) = @_;
3633 $item->{'itemnum'} = $item->{'itemnumber'} unless $item->{'itemnum'};
3635 # if all we're doing is setting statuses, just update those and get out
3636 if ( $op eq "setstatus" ) {
3638 "UPDATE items SET itemlost=?,wthdrawn=?,binding=? WHERE itemnumber=?";
3640 $item->{'itemlost'}, $item->{'wthdrawn'},
3641 $item->{'binding'}, $item->{'itemnumber'}
3643 my $sth = $dbh->prepare($query);
3644 $sth->execute(@bind);
3648 ## Now calculate lccalnumber
3650 itemcalculator( $dbh, $item->{'bibitemnum'}, $item->{'itemcallnumber'} );
3652 my $query = "UPDATE items SET
3653 barcode=?,itemnotes=?,itemcallnumber=?,notforloan=?,location=?,multivolumepart=?,multivolume=?,stack=?,wthdrawn=?,holdingbranch=?,homebranch=?,cutterextra=?, onloan=?, binding=?";
3656 $item->{'barcode'}, $item->{'notes'},
3657 $item->{'itemcallnumber'}, $item->{'notforloan'},
3658 $item->{'location'}, $item->{multivolumepart},
3659 $item->{multivolume}, $item->{stack},
3660 $item->{wthdrawn}, $item->{holdingbranch},
3661 $item->{homebranch}, $cutterextra,
3662 $item->{onloan}, $item->{binding}
3664 if ( $item->{'lost'} ne '' ) {
3666 "update items set biblioitemnumber=?,barcode=?,itemnotes=?,homebranch=?,
3667 itemlost=?,wthdrawn=?,itemcallnumber=?,notforloan=?,
3668 location=?,multivolumepart=?,multivolume=?,stack=?,wthdrawn=?,holdingbranch=?,cutterextra=?,onloan=?, binding=?";
3670 $item->{'bibitemnum'}, $item->{'barcode'},
3671 $item->{'notes'}, $item->{'homebranch'},
3672 $item->{'lost'}, $item->{'wthdrawn'},
3673 $item->{'itemcallnumber'}, $item->{'notforloan'},
3674 $item->{'location'}, $item->{multivolumepart},
3675 $item->{multivolume}, $item->{stack},
3676 $item->{wthdrawn}, $item->{holdingbranch},
3677 $cutterextra, $item->{onloan},
3680 if ( $item->{homebranch} ) {
3681 $query .= ",homebranch=?";
3682 push @bind, $item->{homebranch};
3684 if ( $item->{holdingbranch} ) {
3685 $query .= ",holdingbranch=?";
3686 push @bind, $item->{holdingbranch};
3689 $query .= " where itemnumber=?";
3690 push @bind, $item->{'itemnum'};
3691 if ( $item->{'replacement'} ne '' ) {
3692 $query =~ s/ where/,replacementprice='$item->{'replacement'}' where/;
3694 my $sth = $dbh->prepare($query);
3695 $sth->execute(@bind);
3699 =head2 _koha_delete_biblio
3703 $error = _koha_delete_biblio($dbh,$biblionumber);
3705 Internal sub for deleting from biblio table -- also saves to deletedbiblio
3707 C<$dbh> - the database handle
3708 C<$biblionumber> - the biblionumber of the biblio to be deleted
3714 # FIXME: add error handling
3716 sub _koha_delete_biblio {
3717 my ( $dbh, $biblionumber ) = @_;
3719 # get all the data for this biblio
3720 my $sth = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber=?");
3721 $sth->execute($biblionumber);
3723 if ( my $data = $sth->fetchrow_hashref ) {
3725 # save the record in deletedbiblio
3726 # find the fields to save
3727 my $query = "INSERT INTO deletedbiblio SET ";
3729 foreach my $temp ( keys %$data ) {
3730 $query .= "$temp = ?,";
3731 push( @bind, $data->{$temp} );
3734 # replace the last , by ",?)"
3736 my $bkup_sth = $dbh->prepare($query);
3737 $bkup_sth->execute(@bind);
3741 my $del_sth = $dbh->prepare("DELETE FROM biblio WHERE biblionumber=?");
3742 $del_sth->execute($biblionumber);
3749 =head2 _koha_delete_biblioitems
3753 $error = _koha_delete_biblioitems($dbh,$biblioitemnumber);
3755 Internal sub for deleting from biblioitems table -- also saves to deletedbiblioitems
3757 C<$dbh> - the database handle
3758 C<$biblionumber> - the biblioitemnumber of the biblioitem to be deleted
3764 # FIXME: add error handling
3766 sub _koha_delete_biblioitems {
3767 my ( $dbh, $biblioitemnumber ) = @_;
3769 # get all the data for this biblioitem
3771 $dbh->prepare("SELECT * FROM biblioitems WHERE biblioitemnumber=?");
3772 $sth->execute($biblioitemnumber);
3774 if ( my $data = $sth->fetchrow_hashref ) {
3776 # save the record in deletedbiblioitems
3777 # find the fields to save
3778 my $query = "INSERT INTO deletedbiblioitems SET ";
3780 foreach my $temp ( keys %$data ) {
3781 $query .= "$temp = ?,";
3782 push( @bind, $data->{$temp} );
3785 # replace the last , by ",?)"
3787 my $bkup_sth = $dbh->prepare($query);
3788 $bkup_sth->execute(@bind);
3791 # delete the biblioitem
3793 $dbh->prepare("DELETE FROM biblioitems WHERE biblioitemnumber=?");
3794 $del_sth->execute($biblioitemnumber);
3801 =head2 _koha_delete_item
3805 _koha_delete_item( $dbh, $itemnum );
3807 Internal function to delete an item record from the koha tables
3813 sub _koha_delete_item {
3814 my ( $dbh, $itemnum ) = @_;
3816 my $sth = $dbh->prepare("select * from items where itemnumber=?");
3817 $sth->execute($itemnum);
3818 my $data = $sth->fetchrow_hashref;
3820 my $query = "Insert into deleteditems set ";
3822 foreach my $temp ( keys %$data ) {
3823 $query .= "$temp = ?,";
3824 push( @bind, $data->{$temp} );
3829 $sth = $dbh->prepare($query);
3830 $sth->execute(@bind);
3832 $sth = $dbh->prepare("Delete from items where itemnumber=?");
3833 $sth->execute($itemnum);
3837 =head1 UNEXPORTED FUNCTIONS
3843 $lc = calculatelc($classification);
3850 my ($classification) = @_;
3851 $classification =~ s/^\s+|\s+$//g;
3856 for ( $i = 0 ; $i < length($classification) ; $i++ ) {
3857 my $c = ( substr( $classification, $i, 1 ) );
3858 if ( $c ge '0' && $c le '9' ) {
3860 $lc2 = substr( $classification, $i );
3864 $lc1 .= substr( $classification, $i, 1 );
3869 my $other = length($lc1);
3876 for ( 1 .. ( 4 - $other ) ) {
3885 ##Find the decimal part of $lc2
3886 my $pos = index( $lc2, "." );
3887 if ( $pos < 0 ) { $pos = length($lc2); }
3888 if ( $pos >= 0 && $pos < 5 ) {
3889 ##Pad lc2 with zeros to create a 5digit decimal needed in marc record to sort as numeric
3891 for ( 1 .. ( 5 - $pos ) ) {
3895 $lc2 = $extras . $lc2;
3896 return ( $lc1 . $lc2 );
3899 =head2 itemcalculator
3903 $cutterextra = itemcalculator( $dbh, $biblioitem, $callnumber );
3909 sub itemcalculator {
3910 my ( $dbh, $biblioitem, $callnumber ) = @_;
3913 "select classification, subclass from biblioitems where biblioitemnumber=?"
3916 $sth->execute($biblioitem);
3917 my ( $classification, $subclass ) = $sth->fetchrow;
3918 my $all = $classification . " " . $subclass;
3919 my $total = length($all);
3920 my $cutterextra = substr( $callnumber, $total - 1 );
3922 return $cutterextra;
3925 =head2 ModBiblioMarc
3927 &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
3929 Add MARC data for a biblio to koha
3931 Function exported, but should NOT be used, unless you really know what you're doing
3937 # pass the MARC::Record to this function, and it will create the records in the marc field
3938 my ( $record, $biblionumber, $frameworkcode ) = @_;
3939 my $dbh = C4::Context->dbh;
3940 my @fields = $record->fields();
3941 if ( !$frameworkcode ) {
3942 $frameworkcode = "";
3945 $dbh->prepare("UPDATE biblio SET frameworkcode=? WHERE biblionumber=?");
3946 $sth->execute( $frameworkcode, $biblionumber );
3948 my $encoding = C4::Context->preference("marcflavour");
3950 # deal with UNIMARC field 100 (encoding) : create it if needed & set encoding to unicode
3951 if ( $encoding eq "UNIMARC" ) {
3953 if ( length($record->subfield( 100, "a" )) == 35 ) {
3954 $string = $record->subfield( 100, "a" );
3955 my $f100 = $record->field(100);
3956 $record->delete_field($f100);
3959 $string = POSIX::strftime( "%Y%m%d", localtime );
3961 $string = sprintf( "%-*s", 35, $string );
3963 substr( $string, 22, 6, "frey50" );
3964 unless ( $record->subfield( 100, "a" ) ) {
3965 $record->insert_grouped_field(
3966 MARC::Field->new( 100, "", "", "a" => $string ) );
3969 ModZebra($biblionumber,"specialUpdate","biblioserver",$record);
3972 "update biblioitems set marc=?,marcxml=? where biblionumber=?");
3973 $sth->execute( $record->as_usmarc(), $record->as_xml_record($encoding),
3976 return $biblionumber;
3979 =head2 AddItemInMarc
3983 $newbiblionumber = AddItemInMarc( $record, $biblionumber, $frameworkcode );
3985 Add an item in a MARC record and save the MARC record
3987 Function exported, but should NOT be used, unless you really know what you're doing
3995 # pass the MARC::Record to this function, and it will create the records in the marc tables
3996 my ( $record, $biblionumber, $frameworkcode ) = @_;
3997 my $newrec = &GetMarcBiblio($biblionumber);
4000 my @fields = $record->fields();
4001 foreach my $field (@fields) {
4002 $newrec->append_fields($field);
4005 # FIXME: should we be making sure the biblionumbers are the same?
4006 my $newbiblionumber =
4007 &ModBiblioMarc( $newrec, $biblionumber, $frameworkcode );
4008 return $newbiblionumber;
4011 =head2 z3950_extended_services
4013 z3950_extended_services($serviceType,$serviceOptions,$record);
4015 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.
4017 C<$serviceType> one of: itemorder,create,drop,commit,update,xmlupdate
4019 C<$serviceOptions> a has of key/value pairs. For instance, if service_type is 'update', $service_options should contain:
4021 action => update action, one of specialUpdate, recordInsert, recordReplace, recordDelete, elementUpdate.
4025 recordidOpaque => Opaque Record ID (user supplied) or recordidNumber => Record ID number (system number).
4026 syntax => the record syntax (transfer syntax)
4027 databaseName = Database from connection object
4029 To set serviceOptions, call set_service_options($serviceType)
4031 C<$record> the record, if one is needed for the service type
4033 A record should be in XML. You can convert it to XML from MARC by running it through marc2xml().
4037 sub z3950_extended_services {
4038 my ( $server, $serviceType, $action, $serviceOptions ) = @_;
4040 # get our connection object
4041 my $Zconn = C4::Context->Zconn( $server, 0, 1 );
4043 # create a new package object
4044 my $Zpackage = $Zconn->package();
4047 $Zpackage->option( action => $action );
4049 if ( $serviceOptions->{'databaseName'} ) {
4050 $Zpackage->option( databaseName => $serviceOptions->{'databaseName'} );
4052 if ( $serviceOptions->{'recordIdNumber'} ) {
4054 recordIdNumber => $serviceOptions->{'recordIdNumber'} );
4056 if ( $serviceOptions->{'recordIdOpaque'} ) {
4058 recordIdOpaque => $serviceOptions->{'recordIdOpaque'} );
4061 # this is an ILL request (Zebra doesn't support it, but Koha could eventually)
4062 #if ($serviceType eq 'itemorder') {
4063 # $Zpackage->option('contact-name' => $serviceOptions->{'contact-name'});
4064 # $Zpackage->option('contact-phone' => $serviceOptions->{'contact-phone'});
4065 # $Zpackage->option('contact-email' => $serviceOptions->{'contact-email'});
4066 # $Zpackage->option('itemorder-item' => $serviceOptions->{'itemorder-item'});
4069 if ( $serviceOptions->{record} ) {
4070 $Zpackage->option( record => $serviceOptions->{record} );
4072 # can be xml or marc
4073 if ( $serviceOptions->{'syntax'} ) {
4074 $Zpackage->option( syntax => $serviceOptions->{'syntax'} );
4078 # send the request, handle any exception encountered
4079 eval { $Zpackage->send($serviceType) };
4080 if ( $@ && $@->isa("ZOOM::Exception") ) {
4081 return "error: " . $@->code() . " " . $@->message() . "\n";
4084 # free up package resources
4085 $Zpackage->destroy();
4088 =head2 set_service_options
4090 my $serviceOptions = set_service_options($serviceType);
4092 C<$serviceType> itemorder,create,drop,commit,update,xmlupdate
4094 Currently, we only support 'create', 'commit', and 'update'. 'drop' support will be added as soon as Zebra supports it.
4098 sub set_service_options {
4099 my ($serviceType) = @_;
4102 # FIXME: This needs to be an OID ... if we ever need 'syntax' this sub will need to change
4103 # $serviceOptions->{ 'syntax' } = ''; #zebra doesn't support syntaxes other than xml
4105 if ( $serviceType eq 'commit' ) {
4109 if ( $serviceType eq 'create' ) {
4113 if ( $serviceType eq 'drop' ) {
4114 die "ERROR: 'drop' not currently supported (by Zebra)";
4116 return $serviceOptions;
4119 =head2 GetItemsCount
4121 $count = &GetItemsCount( $biblionumber);
4122 this function return count of item with $biblionumber
4126 my ( $biblionumber ) = @_;
4127 my $dbh = C4::Context->dbh;
4128 my $query = qq|SELECT count(*)
4130 WHERE biblionumber=?|;
4131 my $sth = $dbh->prepare($query);
4132 $sth->execute($biblionumber);
4133 my $count = $sth->fetchrow;
4138 END { } # module clean-up code here (global destructor)
4146 Koha Developement team <info@koha.org>
4148 Paul POULAIN paul.poulain@free.fr
4150 Joshua Ferraro jmf@liblime.com
4156 # Revision 1.221 2007/07/31 16:01:11 toins
4157 # Some new functions.
4158 # TransformHTMLtoMarc rewrited.
4160 # Revision 1.220 2007/07/20 15:43:16 hdl
4161 # Bug Fixing GetMarcSubjects.
4162 # Links parameters were mixed.
4164 # Revision 1.218 2007/07/19 07:40:08 hdl
4165 # Adding selection by location for inventory
4167 # Revision 1.217 2007/07/03 13:47:44 tipaul
4168 # fixing some display bugs (itemtype not properly returned and a html table bug that makes items appear strangely
4170 # Revision 1.216 2007/07/03 09:40:58 tipaul
4171 # return itemtype description properly
4173 # Revision 1.215 2007/07/03 09:33:05 tipaul
4174 # if you just replace su by a space in subjects, you'll replace jesus by je s, which is strange for users. this fix solves the problem and introduces authoritysep systempref as separator of subfields, for a better identification of where the authority starts and end
4176 # Revision 1.214 2007/07/02 09:13:22 tipaul
4177 # unimarc bugfix : the encoding is in field 100 in UNIMARC. when TransformHTMLtoXML on an item, you must not automatically add a 100 field in items, otherwise there will be 2 100 fields in the biblio, which is wrong
4179 # Revision 1.213 2007/06/25 15:01:45 tipaul
4180 # bugfixes on unimarc 100 handling (the field used for encoding)
4182 # Revision 1.212 2007/06/15 13:44:44 tipaul
4183 # some fixes (and only fixes)
4185 # Revision 1.211 2007/06/15 09:40:06 toins
4186 # do not get $3 $4 and $5 on GetMarcSubjects GetMarcAuthors on unimarc flavour.
4188 # Revision 1.210 2007/06/13 13:03:34 toins
4189 # removing warn compilation.
4191 # Revision 1.209 2007/05/23 16:19:40 tipaul
4192 # various bugfixes (minor) and french translation updated
4194 # Revision 1.208 2007/05/22 09:13:54 tipaul
4195 # Bugfixes & improvements (various and minor) :
4196 # - updating templates to have tmpl_process3.pl running without any errors
4197 # - adding a drupal-like css for prog templates (with 3 small images)
4198 # - fixing some bugs in circulation & other scripts
4199 # - updating french translation
4200 # - fixing some typos in templates
4202 # Revision 1.207 2007/05/22 08:51:19 hdl
4203 # Changing GetMarcStructure signature.
4204 # Deleting first parameter $dbh
4206 # Revision 1.206 2007/05/21 08:44:17 btoumi
4207 # add security when u delete biblio :
4208 # u must delete linked items before delete biblio
4210 # Revision 1.205 2007/05/11 16:04:03 btoumi
4212 # problem in displayed label link with subject in detail.tmpl
4213 # ex: label random => rdom
4215 # Revision 1.204 2007/05/10 14:45:15 tipaul
4217 # - support for authorities
4218 # - some bugfixes in ordering and "CCL" parsing
4219 # - support for authorities <=> biblios walking
4221 # Seems I can do what I want now, so I consider its done, except for bugfixes that will be needed i m sure !
4223 # Revision 1.203 2007/05/03 15:16:02 tipaul
4224 # BUGFIX for : NoZebra
4225 # - NoZebra features : seems they work fine now (adding, modifying, deleting)
4226 # - Biblio edition major bugfix : before this commit editing a biblio resulted in an item removal in marcxml field
4228 # Revision 1.202 2007/05/02 16:44:31 tipaul
4229 # NoZebra SQL index management :
4230 # * adding 3 subs in Biblio.pm
4231 # - GetNoZebraIndexes, that get the index structure in a new systempreference (added with this commit)
4232 # - _DelBiblioNoZebra, that retrieve all index entries for a biblio and remove in a variable the biblio reference
4233 # - _AddBiblioNoZebra, that add index entries for a biblio.
4234 # Note that the 2 _Add and _Del subs work only in a hash variable, to speed up things in case of a modif (ie : delete+add). The effective SQL update is done in the ModZebra sub (that existed before, and dealed with zebra index).
4235 # I think the code has to be more deeply tested, but it works at least partially.
4237 # Revision 1.201 2007/04/27 14:00:49 hdl
4238 # Removing $dbh from GetMarcFromKohaField (dbh is not used in this function.)
4240 # Revision 1.200 2007/04/25 16:26:42 tipaul
4241 # 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 :
4242 # - add nozebra table management on biblio editing
4243 # - the index table content is hardcoded. I still have to add some specific systempref to let the library update it
4244 # - manage pagination (next/previous)
4247 # - NZgetRecords : has exactly the same API & returns as zebra getQuery, except that some parameters are unused
4248 # - search & sort works quite good
4249 # - CQL parser is better that what I thought I could do : title="harry and sally" and publicationyear>2000 not itemtype=LIVR should work fine
4251 # Revision 1.199 2007/04/24 09:07:53 tipaul
4252 # moving dotransfer to Biblio.pm::ModItemTransfer + some CheckReserves fixes
4254 # Revision 1.198 2007/04/23 15:21:17 tipaul
4255 # renaming currenttransfers to transferstoreceive
4257 # Revision 1.197 2007/04/18 17:00:14 tipaul
4258 # removing all useless %env / $env
4260 # Revision 1.196 2007/04/17 08:48:00 tipaul
4261 # circulation cleaning continued: bufixing
4263 # Revision 1.195 2007/04/04 16:46:22 tipaul
4264 # HUGE COMMIT : code cleaning circulation.
4266 # some stuff to do, i'll write a mail on koha-devel NOW !
4268 # Revision 1.194 2007/03/30 12:00:42 tipaul
4269 # 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...
4271 # Revision 1.193 2007/03/29 16:45:53 tipaul
4272 # Code cleaning of Biblio.pm (continued)
4274 # All subs have be cleaned :
4277 # - reordering Biblio.pm completly
4278 # - using only naming conventions
4280 # Seems to have broken nothing, but it still has to be heavily tested.
4281 # Note that Biblio.pm is now much more efficient than previously & probably more reliable as well.
4283 # Revision 1.192 2007/03/29 13:30:31 tipaul
4285 # == Biblio.pm cleaning (useless) ==
4286 # * some sub declaration dropped
4287 # * removed modbiblio sub
4288 # * removed moditem sub
4289 # * removed newitems. It was used only in finishrecieve. Replaced by a TransformKohaToMarc+AddItem, that is better.
4290 # * removed MARCkoha2marcItem
4291 # * removed MARCdelsubfield declaration
4292 # * removed MARCkoha2marcBiblio
4294 # == Biblio.pm cleaning (naming conventions) ==
4295 # * MARCgettagslib renamed to GetMarcStructure
4296 # * MARCgetitems renamed to GetMarcItem
4297 # * MARCfind_frameworkcode renamed to GetFrameworkCode
4298 # * MARCmarc2koha renamed to TransformMarcToKoha
4299 # * MARChtml2marc renamed to TransformHtmlToMarc
4300 # * MARChtml2xml renamed to TranformeHtmlToXml
4301 # * zebraop renamed to ModZebra
4304 # * removing MARC=OFF related scripts (in cataloguing directory)
4305 # * removed checkitems (function related to MARC=off feature, that is completly broken in head. If someone want to reintroduce it, hard work coming...)
4306 # * removed getitemsbybiblioitem (used only by MARC=OFF scripts, that is removed as well)
4308 # Revision 1.191 2007/03/29 09:42:13 tipaul
4309 # adding default value new feature into cataloguing. The system (definition) part has already been added by toins
4311 # Revision 1.190 2007/03/29 08:45:19 hdl
4312 # Deleting ignore_errors(1) pour MARC::Charset
4314 # Revision 1.189 2007/03/28 10:39:16 hdl
4315 # removing $dbh as a parameter in AuthoritiesMarc functions
4316 # And reporting all differences into the scripts taht relies on those functions.