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
72 &GetItemsByBiblioitemnumber
73 &GetItemnumberFromBarcode
77 &GetAuthorisedValueDesc
81 &GetPublisherNameFromIsbn
93 &ModItemInMarconefield
104 # those functions are exported but should not be used
105 # they are usefull is few circumstances, so are exported.
106 # but don't use them unless you're a core developer ;-)
117 &TransformHtmlToMarc2
120 &PrepareItemrecordDisplay
127 C4::Biblio - cataloging management functions
131 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:
135 =item 1. in the biblio,biblioitems,items, etc tables, which are limited to a one-to-one mapping to underlying MARC data
137 =item 2. as raw MARC in the Zebra index and storage engine
139 =item 3. as raw MARC the biblioitems.marc and biblioitems.marcxml
143 In the 3.0 version of Koha, the authoritative record-level information is in biblioitems.marcxml
145 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.
149 =item 1. Compared with MySQL, Zebra is slow to update an index for small data changes -- especially for proc-intensive operations like circulation
151 =item 2. Zebra's index has been known to crash and a backup of the data is necessary to rebuild it in such cases
155 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:
159 =item 1. Add*/Mod*/Del*/ - high-level external functions suitable for being called from external scripts to manage the collection
161 =item 2. _koha_* - low-level internal functions for managing the koha tables
163 =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.
165 =item 4. Zebra functions used to update the Zebra index
167 =item 5. internal helper functions such as char_decode, checkitems, etc. Some of these probably belong in Koha.pm
171 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 :
175 =item 1. save datas in biblio and biblioitems table, that gives us a biblionumber and a biblioitemnumber
177 =item 2. add the biblionumber and biblioitemnumber into the MARC records
179 =item 3. save the marc record
183 When dealing with items, we must :
187 =item 1. save the item in items table, that gives us an itemnumber
189 =item 2. add the itemnumber to the item MARC field
191 =item 3. overwrite the MARC record (with the added item) into biblioitems.marc(xml)
193 When modifying a biblio or an item, the behaviour is quite similar.
197 =head1 EXPORTED FUNCTIONS
203 ($biblionumber,$biblioitemnumber) = AddBiblio($record,$frameworkcode);
204 Exported function (core API) for adding a new biblio to koha.
211 my ( $record, $frameworkcode ) = @_;
213 my $biblioitemnumber;
214 my $dbh = C4::Context->dbh;
215 # transform the data into koha-table style data
216 my $olddata = TransformMarcToKoha( $dbh, $record, $frameworkcode );
217 $biblionumber = _koha_add_biblio( $dbh, $olddata, $frameworkcode );
218 $olddata->{'biblionumber'} = $biblionumber;
219 $biblioitemnumber = _koha_add_biblioitem( $dbh, $olddata );
221 # we must add bibnum and bibitemnum in MARC::Record...
222 # we build the new field with biblionumber and biblioitemnumber
223 # we drop the original field
224 # we add the new builded field.
225 ( my $biblio_tag, my $biblio_subfield ) = GetMarcFromKohaField("biblio.biblionumber",$frameworkcode);
226 ( my $biblioitem_tag, my $biblioitem_subfield ) = GetMarcFromKohaField("biblioitems.biblioitemnumber",$frameworkcode);
230 # biblionumber & biblioitemnumber are in different fields
231 if ( $biblio_tag != $biblioitem_tag ) {
233 # deal with biblionumber
234 if ( $biblio_tag < 10 ) {
235 $newfield = MARC::Field->new( $biblio_tag, $biblionumber );
239 MARC::Field->new( $biblio_tag, '', '',
240 "$biblio_subfield" => $biblionumber );
243 # drop old field and create new one...
244 my $old_field = $record->field($biblio_tag);
245 $record->delete_field($old_field);
246 $record->append_fields($newfield);
248 # deal with biblioitemnumber
249 if ( $biblioitem_tag < 10 ) {
250 $newfield = MARC::Field->new( $biblioitem_tag, $biblioitemnumber, );
254 MARC::Field->new( $biblioitem_tag, '', '',
255 "$biblioitem_subfield" => $biblioitemnumber, );
257 # drop old field and create new one...
258 $old_field = $record->field($biblioitem_tag);
259 $record->delete_field($old_field);
260 $record->insert_fields_ordered($newfield);
262 # biblionumber & biblioitemnumber are in the same field (can't be <10 as fields <10 have only 1 value)
265 my $newfield = MARC::Field->new(
267 "$biblio_subfield" => $biblionumber,
268 "$biblioitem_subfield" => $biblioitemnumber
271 # drop old field and create new one...
272 my $old_field = $record->field($biblio_tag);
273 $record->delete_field($old_field);
274 $record->insert_fields_ordered($newfield);
278 $biblionumber = ModBiblioMarc( $record, $biblionumber, $frameworkcode );
280 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","ADD",$biblionumber,"biblio")
281 if C4::Context->preference("CataloguingLog");
283 return ( $biblionumber, $biblioitemnumber );
290 $biblionumber = AddItem( $record, $biblionumber)
291 Exported function (core API) for adding a new item to Koha
298 my ( $record, $biblionumber ) = @_;
299 my $dbh = C4::Context->dbh;
302 my $frameworkcode = GetFrameworkCode( $biblionumber );
303 my $item = &TransformMarcToKoha( $dbh, $record, $frameworkcode );
305 # needs old biblionumber and biblioitemnumber
306 $item->{'biblionumber'} = $biblionumber;
309 "select biblioitemnumber,itemtype from biblioitems where biblionumber=?"
311 $sth->execute( $item->{'biblionumber'} );
313 ( $item->{'biblioitemnumber'}, $itemtype ) = $sth->fetchrow;
316 "select notforloan from itemtypes where itemtype='$itemtype'");
318 my $notforloan = $sth->fetchrow;
319 ##Change the notforloan field if $notforloan found
320 if ( $notforloan > 0 ) {
321 $item->{'notforloan'} = $notforloan;
322 &MARCitemchange( $record, "items.notforloan", $notforloan );
324 if ( !$item->{'dateaccessioned'} || $item->{'dateaccessioned'} eq '' ) {
327 my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
332 "$year-" . sprintf( "%0.2d", $mon ) . "-" . sprintf( "%0.2d", $mday );
333 $item->{'dateaccessioned'} = $date;
334 &MARCitemchange( $record, "items.dateaccessioned", $date );
336 my ( $itemnumber, $error ) =
337 &_koha_new_items( $dbh, $item, $item->{barcode} );
339 # add itemnumber to MARC::Record before adding the item.
340 $sth = $dbh->prepare(
341 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
343 &TransformKohaToMarcOneField( $sth, $record, "items.itemnumber", $itemnumber,
347 &AddItemInMarc( $record, $item->{'biblionumber'},$frameworkcode );
349 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","ADD",$itemnumber,"item")
350 if C4::Context->preference("CataloguingLog");
352 return ($item->{biblionumber}, $item->{biblioitemnumber},$itemnumber);
357 ModBiblio( $record,$biblionumber,$frameworkcode);
358 Exported function (core API) to modify a biblio
363 my ( $record, $biblionumber, $frameworkcode ) = @_;
364 if (C4::Context->preference("CataloguingLog")) {
365 my $newrecord = GetMarcBiblio($biblionumber);
366 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","MODIFY",$biblionumber,"BEFORE=>".$newrecord->as_formatted);
369 my $dbh = C4::Context->dbh;
371 $frameworkcode = "" unless $frameworkcode;
373 # get the items before and append them to the biblio before updating the record, atm we just have the biblio
374 my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",$frameworkcode);
375 my $oldRecord = GetMarcBiblio( $biblionumber );
377 # parse each item, and, for an unknown reason, re-encode each subfield
378 # if you don't do that, the record will have encoding mixed
379 # and the biblio will be re-encoded.
380 # strange, I (Paul P.) searched more than 1 day to understand what happends
381 # but could only solve the problem this way...
382 my @fields = $oldRecord->field( $itemtag );
383 foreach my $fielditem ( @fields ){
385 foreach ($fielditem->subfields()) {
387 $field->add_subfields(Encode::encode('utf-8',$_->[0]) => Encode::encode('utf-8',$_->[1]));
389 $field = MARC::Field->new("$itemtag",'','',Encode::encode('utf-8',$_->[0]) => Encode::encode('utf-8',$_->[1]));
392 $record->append_fields($field);
395 # adding biblionumber
396 my ($tag_biblionumber, $subfield_biblionumber) = GetMarcFromKohaField('biblio.biblionumber',$frameworkcode);
397 $record->append_fields(
399 $tag_biblionumber,'','',$subfield_biblionumber => $biblionumber
401 ) unless ($record->subfield($tag_biblionumber,$subfield_biblionumber));
403 # update the MARC record (that now contains biblio and items) with the new record data
404 &ModBiblioMarc( $record, $biblionumber, $frameworkcode );
406 # load the koha-table data object
407 my $oldbiblio = TransformMarcToKoha( $dbh, $record, $frameworkcode );
409 # modify the other koha tables
410 _koha_modify_biblio( $dbh, $oldbiblio );
411 _koha_modify_biblioitem( $dbh, $oldbiblio );
419 Exported function (core API) for modifying an item in Koha.
426 my ( $record, $biblionumber, $itemnumber, $delete, $new_item_hashref )
430 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","MODIFY",$itemnumber,$record->as_formatted)
431 if C4::Context->preference("CataloguingLog");
433 my $dbh = C4::Context->dbh;
435 # if we have a MARC record, we're coming from cataloging and so
436 # we do the whole routine: update the MARC and zebra, then update the koha
439 my $frameworkcode = GetFrameworkCode( $biblionumber );
440 ModItemInMarc( $record, $biblionumber, $itemnumber, $frameworkcode );
441 my $olditem = TransformMarcToKoha( $dbh, $record, $frameworkcode );
442 _koha_modify_item( $dbh, $olditem );
443 return $biblionumber;
446 # otherwise, we're just looking to modify something quickly
447 # (like a status) so we just update the koha tables
448 elsif ($new_item_hashref) {
449 _koha_modify_item( $dbh, $new_item_hashref );
453 sub ModItemTransfer {
454 my ( $itemnumber, $frombranch, $tobranch ) = @_;
456 my $dbh = C4::Context->dbh;
458 #new entry in branchtransfers....
459 my $sth = $dbh->prepare(
460 "INSERT INTO branchtransfers (itemnumber, frombranch, datesent, tobranch)
461 VALUES (?, ?, now(), ?)");
462 $sth->execute($itemnumber, $frombranch, $tobranch);
463 #update holdingbranch in items .....
465 "UPDATE items set holdingbranch = ? WHERE items.itemnumber = ?");
466 $sth->execute($tobranch,$itemnumber);
467 &ModDateLastSeen($itemnumber);
468 $sth = $dbh->prepare(
469 "SELECT biblionumber FROM items WHERE itemnumber=?"
471 $sth->execute($itemnumber);
472 while ( my ( $biblionumber ) = $sth->fetchrow ) {
473 &ModItemInMarconefield( $biblionumber, $itemnumber,
474 'items.holdingbranch', $tobranch );
479 =head2 ModBiblioframework
481 ModBiblioframework($biblionumber,$frameworkcode);
482 Exported function to modify a biblio framework
486 sub ModBiblioframework {
487 my ( $biblionumber, $frameworkcode ) = @_;
488 my $dbh = C4::Context->dbh;
489 my $sth = $dbh->prepare(
490 "UPDATE biblio SET frameworkcode=? WHERE biblionumber=$biblionumber"
492 $sth->execute($frameworkcode);
496 =head2 ModItemInMarconefield
500 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)
501 &ModItemInMarconefield( $biblionumber, $itemnumber, $itemfield, $newvalue )
507 sub ModItemInMarconefield {
508 my ( $biblionumber, $itemnumber, $itemfield, $newvalue ) = @_;
509 my $dbh = C4::Context->dbh;
510 if ( !defined $newvalue ) {
514 my $record = GetMarcItem( $biblionumber, $itemnumber );
515 my ($tagfield, $tagsubfield) = GetMarcFromKohaField( $itemfield,'');
516 if ($tagfield && $tagsubfield) {
517 my $tag = $record->field($tagfield);
519 # my $tagsubs = $record->field($tagfield)->subfield($tagsubfield);
520 $tag->update( $tagsubfield => $newvalue );
521 $record->delete_field($tag);
522 $record->insert_fields_ordered($tag);
523 &ModItemInMarc( $record, $biblionumber, $itemnumber, 0 );
532 &ModItemInMarc( $record, $biblionumber, $itemnumber )
539 my ( $ItemRecord, $biblionumber, $itemnumber, $frameworkcode) = @_;
540 my $dbh = C4::Context->dbh;
542 # get complete MARC record & replace the item field by the new one
543 my $completeRecord = GetMarcBiblio($biblionumber);
544 my ($itemtag,$itemsubfield) = GetMarcFromKohaField("items.itemnumber",$frameworkcode);
545 my $itemField = $ItemRecord->field($itemtag);
546 my @items = $completeRecord->field($itemtag);
548 if ($_->subfield($itemsubfield) eq $itemnumber) {
549 # $completeRecord->delete_field($_);
550 $_->replace_with($itemField);
554 my $sth = $dbh->prepare("update biblioitems set marc=?,marcxml=? where biblionumber=?");
555 $sth->execute( $completeRecord->as_usmarc(), $completeRecord->as_xml_record(),$biblionumber );
557 ModZebra($biblionumber,"specialUpdate","biblioserver",$completeRecord);
560 =head2 ModDateLastSeen
562 &ModDateLastSeen($itemnum)
563 Mark item as seen. Is called when an item is issued, returned or manually marked during inventory/stocktaking
564 C<$itemnum> is the item number
568 sub ModDateLastSeen {
570 my $dbh = C4::Context->dbh;
573 "update items set itemlost=0, datelastseen = now() where items.itemnumber = ?"
575 $sth->execute($itemnum);
582 my $error = &DelBiblio($dbh,$biblionumber);
583 Exported function (core API) for deleting a biblio in koha.
584 Deletes biblio record from Zebra and Koha tables (biblio,biblioitems,items)
585 Also backs it up to deleted* tables
586 Checks to make sure there are not issues on any of the items
588 C<$error> : undef unless an error occurs
595 my ( $biblionumber ) = @_;
596 my $dbh = C4::Context->dbh;
597 my $error; # for error handling
599 # First make sure this biblio has no items attached
600 my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber=?");
601 $sth->execute($biblionumber);
602 if (my $itemnumber = $sth->fetchrow){
603 # Fix this to use a status the template can understand
604 $error .= "This Biblio has items attached, please delete them first before deleting this biblio ";
607 return $error if $error;
609 # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
610 # for at least 2 reasons :
611 # - we need to read the biblio if NoZebra is set (to remove it from the indexes
612 # - if something goes wrong, the biblio may be deleted from Koha but not from zebra
613 # 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)
614 ModZebra($biblionumber, "delete_record", "biblioserver", undef);
616 # delete biblio from Koha tables and save in deletedbiblio
617 $error = &_koha_delete_biblio( $dbh, $biblionumber );
619 # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
622 "SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
623 $sth->execute($biblionumber);
624 while ( my $biblioitemnumber = $sth->fetchrow ) {
626 # delete this biblioitem
627 $error = &_koha_delete_biblioitems( $dbh, $biblioitemnumber );
628 return $error if $error;
630 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","DELETE",$biblionumber,"")
631 if C4::Context->preference("CataloguingLog");
639 DelItem( $biblionumber, $itemnumber );
640 Exported function (core API) for deleting an item record in Koha.
647 my ( $biblionumber, $itemnumber ) = @_;
648 my $dbh = C4::Context->dbh;
650 # check the item has no current issues
653 &_koha_delete_item( $dbh, $itemnumber );
654 # get the MARC record
655 my $record = GetMarcBiblio($biblionumber);
656 my $frameworkcode = GetFrameworkCode($biblionumber);
660 $dbh->prepare("UPDATE deleteditems SET marc=? WHERE itemnumber=?");
661 $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
663 #search item field code
664 my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",$frameworkcode);
665 my @fields = $record->field($itemtag);
666 # delete the item specified
667 foreach my $field (@fields) {
668 if ( $field->subfield($itemsubfield) eq $itemnumber ) {
669 $record->delete_field($field);
672 &ModBiblioMarc( $record, $biblionumber, $frameworkcode );
673 &logaction(C4::Context->userenv->{'number'},"CATALOGUING","DELETE",$itemnumber,"item")
674 if C4::Context->preference("CataloguingLog");
681 $data = &GetBiblioData($biblionumber);
682 Returns information about the book with the given biblionumber.
683 C<&GetBiblioData> returns a reference-to-hash. The keys are the fields in
684 the C<biblio> and C<biblioitems> tables in the
686 In addition, C<$data-E<gt>{subject}> is the list of the book's
687 subjects, separated by C<" , "> (space, comma, space).
688 If there are multiple biblioitems with the given biblionumber, only
689 the first one is considered.
697 my $dbh = C4::Context->dbh;
700 SELECT * , biblioitems.notes AS bnotes, biblio.notes
702 LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
703 LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype
704 WHERE biblio.biblionumber = ?
705 AND biblioitems.biblionumber = biblio.biblionumber
707 my $sth = $dbh->prepare($query);
708 $sth->execute($bibnum);
710 $data = $sth->fetchrow_hashref;
714 } # sub GetBiblioData
721 @results = &GetItemsInfo($biblionumber, $type);
723 Returns information about books with the given biblionumber.
725 C<$type> may be either C<intra> or anything else. If it is not set to
726 C<intra>, then the search will exclude lost, very overdue, and
729 C<&GetItemsInfo> returns a list of references-to-hash. Each element
730 contains a number of keys. Most of them are table items from the
731 C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
732 Koha database. Other keys include:
736 =item C<$data-E<gt>{branchname}>
738 The name (not the code) of the branch to which the book belongs.
740 =item C<$data-E<gt>{datelastseen}>
742 This is simply C<items.datelastseen>, except that while the date is
743 stored in YYYY-MM-DD format in the database, here it is converted to
744 DD/MM/YYYY format. A NULL date is returned as C<//>.
746 =item C<$data-E<gt>{datedue}>
748 =item C<$data-E<gt>{class}>
750 This is the concatenation of C<biblioitems.classification>, the book's
751 Dewey code, and C<biblioitems.subclass>.
753 =item C<$data-E<gt>{ocount}>
755 I think this is the number of copies of the book available.
757 =item C<$data-E<gt>{order}>
759 If this is set, it is set to C<One Order>.
768 my ( $biblionumber, $type ) = @_;
769 my $dbh = C4::Context->dbh;
770 my $query = "SELECT *,items.notforloan as itemnotforloan
772 LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
773 LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
774 LEFT JOIN itemtypes on biblioitems.itemtype = itemtypes.itemtype
775 WHERE items.biblionumber = ?
776 ORDER BY items.dateaccessioned desc
778 my $sth = $dbh->prepare($query);
779 $sth->execute($biblionumber);
782 my ( $date_due, $count_reserves );
784 while ( my $data = $sth->fetchrow_hashref ) {
786 my $isth = $dbh->prepare(
787 "SELECT issues.*,borrowers.cardnumber,borrowers.surname,borrowers.firstname
788 FROM issues LEFT JOIN borrowers ON issues.borrowernumber=borrowers.borrowernumber
790 AND returndate IS NULL"
792 $isth->execute( $data->{'itemnumber'} );
793 if ( my $idata = $isth->fetchrow_hashref ) {
794 $data->{borrowernumber} = $idata->{borrowernumber};
795 $data->{cardnumber} = $idata->{cardnumber};
796 $data->{surname} = $idata->{surname};
797 $data->{firstname} = $idata->{firstname};
798 $datedue = format_date( $idata->{'date_due'} );
800 if ( $datedue eq '' ) {
801 #$datedue="Available";
802 my ( $restype, $reserves ) =
803 C4::Reserves::CheckReserves( $data->{'itemnumber'} );
807 $count_reserves = $restype;
812 #get branch information.....
813 my $bsth = $dbh->prepare(
814 "SELECT * FROM branches WHERE branchcode = ?
817 $bsth->execute( $data->{'holdingbranch'} );
818 if ( my $bdata = $bsth->fetchrow_hashref ) {
819 $data->{'branchname'} = $bdata->{'branchname'};
821 my $date = format_date( $data->{'datelastseen'} );
822 $data->{'datelastseen'} = $date;
823 $data->{'datedue'} = $datedue;
824 $data->{'count_reserves'} = $count_reserves;
826 # get notforloan complete status if applicable
827 my $sthnflstatus = $dbh->prepare(
828 'SELECT authorised_value
829 FROM marc_subfield_structure
830 WHERE kohafield="items.notforloan"
834 $sthnflstatus->execute;
835 my ($authorised_valuecode) = $sthnflstatus->fetchrow;
836 if ($authorised_valuecode) {
837 $sthnflstatus = $dbh->prepare(
838 "SELECT lib FROM authorised_values
840 AND authorised_value=?"
842 $sthnflstatus->execute( $authorised_valuecode,
843 $data->{itemnotforloan} );
844 my ($lib) = $sthnflstatus->fetchrow;
845 $data->{notforloan} = $lib;
848 # my stack procedures
849 my $stackstatus = $dbh->prepare(
850 'SELECT authorised_value
851 FROM marc_subfield_structure
852 WHERE kohafield="items.stack"
855 $stackstatus->execute;
857 ($authorised_valuecode) = $stackstatus->fetchrow;
858 if ($authorised_valuecode) {
859 $stackstatus = $dbh->prepare(
861 FROM authorised_values
863 AND authorised_value=?
866 $stackstatus->execute( $authorised_valuecode, $data->{stack} );
867 my ($lib) = $stackstatus->fetchrow;
868 $data->{stack} = $lib;
870 $results[$i] = $data;
882 $itemstatushash = &getitemstatus($fwkcode);
883 returns information about status.
884 Can be MARC dependant.
886 But basically could be can be loan or not
887 Create a status selector with the following code
889 =head3 in PERL SCRIPT
891 my $itemstatushash = getitemstatus;
893 foreach my $thisstatus (keys %$itemstatushash) {
894 my %row =(value => $thisstatus,
895 statusname => $itemstatushash->{$thisstatus}->{'statusname'},
897 push @itemstatusloop, \%row;
899 $template->param(statusloop=>\@itemstatusloop);
904 <select name="statusloop">
905 <option value="">Default</option>
906 <!-- TMPL_LOOP name="statusloop" -->
907 <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="statusname" --></option>
915 # returns a reference to a hash of references to status...
918 my $dbh = C4::Context->dbh;
920 $fwk = '' unless ($fwk);
921 my ( $tag, $subfield ) =
922 GetMarcFromKohaField( "items.notforloan", $fwk );
923 if ( $tag and $subfield ) {
926 "select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?"
928 $sth->execute( $tag, $subfield, $fwk );
929 if ( my ($authorisedvaluecat) = $sth->fetchrow ) {
932 "select authorised_value, lib from authorised_values where category=? order by lib"
934 $authvalsth->execute($authorisedvaluecat);
935 while ( my ( $authorisedvalue, $lib ) = $authvalsth->fetchrow ) {
936 $itemstatus{$authorisedvalue} = $lib;
952 $itemstatus{"1"} = "Not For Loan";
956 =head2 getitemlocation
960 $itemlochash = &getitemlocation($fwk);
961 returns informations about location.
962 where fwk stands for an optional framework code.
963 Create a location selector with the following code
965 =head3 in PERL SCRIPT
967 my $itemlochash = getitemlocation;
969 foreach my $thisloc (keys %$itemlochash) {
970 my $selected = 1 if $thisbranch eq $branch;
971 my %row =(locval => $thisloc,
972 selected => $selected,
973 locname => $itemlochash->{$thisloc},
975 push @itemlocloop, \%row;
977 $template->param(itemlocationloop => \@itemlocloop);
981 <select name="location">
982 <option value="">Default</option>
983 <!-- TMPL_LOOP name="itemlocationloop" -->
984 <option value="<!-- TMPL_VAR name="locval" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="locname" --></option>
992 sub GetItemLocation {
994 # returns a reference to a hash of references to location...
997 my $dbh = C4::Context->dbh;
999 $fwk = '' unless ($fwk);
1000 my ( $tag, $subfield ) =
1001 GetMarcFromKohaField( "items.location", $fwk );
1002 if ( $tag and $subfield ) {
1005 "select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?"
1007 $sth->execute( $tag, $subfield, $fwk );
1008 if ( my ($authorisedvaluecat) = $sth->fetchrow ) {
1011 "select authorised_value, lib from authorised_values where category=? order by lib"
1013 $authvalsth->execute($authorisedvaluecat);
1014 while ( my ( $authorisedvalue, $lib ) = $authvalsth->fetchrow ) {
1015 $itemlocation{$authorisedvalue} = $lib;
1017 $authvalsth->finish;
1018 return \%itemlocation;
1031 $itemlocation{"1"} = "Not For Loan";
1032 return \%itemlocation;
1037 $items = GetLostItems($where,$orderby);
1039 This function get the items lost into C<$items>.
1044 C<$where> is a hashref. it containts a field of the items table as key
1045 and the value to match as value.
1046 C<$orderby> is a field of the items table.
1049 C<$items> is a reference to an array full of hasref which keys are items' table column.
1051 =item usage in the perl script:
1054 $where{barcode} = 0001548;
1055 my $items = GetLostItems( \%where, "homebranch" );
1056 $template->param(itemsloop => $items);
1063 # Getting input args.
1065 my $orderby = shift;
1066 my $dbh = C4::Context->dbh;
1071 WHERE itemlost IS NOT NULL
1074 foreach my $key (keys %$where) {
1075 $query .= " AND " . $key . " LIKE '%" . $where->{$key} . "%'";
1077 $query .= " ORDER BY ".$orderby if defined $orderby;
1079 my $sth = $dbh->prepare($query);
1082 while ( my $row = $sth->fetchrow_hashref ){
1088 =head2 GetItemsForInventory
1090 $itemlist = GetItemsForInventory($minlocation,$maxlocation,$datelastseen,$offset,$size)
1092 Retrieve a list of title/authors/barcode/callnumber, for biblio inventory.
1094 The sub returns a list of hashes, containing itemnumber, author, title, barcode & item callnumber.
1095 It is ordered by callnumber,title.
1097 The minlocation & maxlocation parameters are used to specify a range of item callnumbers
1098 the datelastseen can be used to specify that you want to see items not seen since a past date only.
1099 offset & size can be used to retrieve only a part of the whole listing (defaut behaviour)
1103 sub GetItemsForInventory {
1104 my ( $minlocation, $maxlocation,$location, $datelastseen, $branch, $offset, $size ) = @_;
1105 my $dbh = C4::Context->dbh;
1107 if ($datelastseen) {
1108 $datelastseen=format_date_in_iso($datelastseen);
1110 "SELECT itemnumber,barcode,itemcallnumber,title,author,biblio.biblionumber,datelastseen
1112 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1113 WHERE itemcallnumber>= ?
1114 AND itemcallnumber <=?
1115 AND (datelastseen< ? OR datelastseen IS NULL)";
1116 $query.= " AND items.location=".$dbh->quote($location) if $location;
1117 $query.= " AND items.homebranch=".$dbh->quote($branch) if $branch;
1118 $query .= " ORDER BY itemcallnumber,title";
1119 $sth = $dbh->prepare($query);
1120 $sth->execute( $minlocation, $maxlocation, $datelastseen );
1124 SELECT itemnumber,barcode,itemcallnumber,biblio.biblionumber,title,author,datelastseen
1126 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1127 WHERE itemcallnumber>= ?
1128 AND itemcallnumber <=?";
1129 $query.= " AND items.location=".$dbh->quote($location) if $location;
1130 $query.= " AND items.homebranch=".$dbh->quote($branch) if $branch;
1131 $query .= " ORDER BY itemcallnumber,title";
1132 $sth = $dbh->prepare($query);
1133 $sth->execute( $minlocation, $maxlocation );
1136 while ( my $row = $sth->fetchrow_hashref ) {
1137 $offset-- if ($offset);
1138 $row->{datelastseen}=format_date($row->{datelastseen});
1139 if ( ( !$offset ) && $size ) {
1140 push @results, $row;
1147 =head2 &GetBiblioItemData
1151 $itemdata = &GetBiblioItemData($biblioitemnumber);
1153 Looks up the biblioitem with the given biblioitemnumber. Returns a
1154 reference-to-hash. The keys are the fields from the C<biblio>,
1155 C<biblioitems>, and C<itemtypes> tables in the Koha database, except
1156 that C<biblioitems.notes> is given as C<$itemdata-E<gt>{bnotes}>.
1163 sub GetBiblioItemData {
1164 my ($biblioitemnumber) = @_;
1165 my $dbh = C4::Context->dbh;
1168 "SELECT *,biblioitems.notes AS bnotes
1169 FROM biblioitems,biblio,itemtypes
1170 WHERE biblio.biblionumber = biblioitems.biblionumber
1171 AND biblioitemnumber = ? "
1174 $sth->execute($biblioitemnumber);
1175 $data = $sth->fetchrow_hashref;
1178 } # sub &GetBiblioItemData
1180 =head2 GetItemnumberFromBarcode
1184 $result = GetItemnumberFromBarcode($barcode);
1190 sub GetItemnumberFromBarcode {
1192 my $dbh = C4::Context->dbh;
1195 $dbh->prepare("SELECT itemnumber from items where items.barcode=?");
1196 $rq->execute($barcode);
1197 my ($result) = $rq->fetchrow;
1201 =head2 GetBiblioItemByBiblioNumber
1205 NOTE : This function has been copy/paste from C4/Biblio.pm from head before zebra integration.
1211 sub GetBiblioItemByBiblioNumber {
1212 my ($biblionumber) = @_;
1213 my $dbh = C4::Context->dbh;
1214 my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?");
1218 $sth->execute($biblionumber);
1220 while ( my $data = $sth->fetchrow_hashref ) {
1221 push @results, $data;
1228 =head2 GetBiblioFromItemNumber
1232 $item = &GetBiblioFromItemNumber($itemnumber);
1234 Looks up the item with the given itemnumber.
1236 C<&itemnodata> returns a reference-to-hash whose keys are the fields
1237 from the C<biblio>, C<biblioitems>, and C<items> tables in the Koha
1245 sub GetBiblioFromItemNumber {
1246 my ( $itemnumber ) = @_;
1247 my $dbh = C4::Context->dbh;
1248 my $sth = $dbh->prepare(
1249 "SELECT * FROM items
1250 LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
1251 LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
1252 WHERE items.itemnumber = ?"
1255 $sth->execute($itemnumber);
1256 my $data = $sth->fetchrow_hashref;
1265 ( $count, @results ) = &GetBiblio($biblionumber);
1272 my ($biblionumber) = @_;
1273 my $dbh = C4::Context->dbh;
1274 my $sth = $dbh->prepare("Select * from biblio where biblionumber = ?");
1277 $sth->execute($biblionumber);
1278 while ( my $data = $sth->fetchrow_hashref ) {
1279 $results[$count] = $data;
1283 return ( $count, @results );
1290 $data = &GetItem($itemnumber,$barcode);
1292 return Item information, for a given itemnumber or barcode
1299 my ($itemnumber,$barcode) = @_;
1300 my $dbh = C4::Context->dbh;
1302 my $sth = $dbh->prepare("
1304 WHERE itemnumber = ?");
1305 $sth->execute($itemnumber);
1306 my $data = $sth->fetchrow_hashref;
1309 my $sth = $dbh->prepare("
1313 $sth->execute($barcode);
1314 my $data = $sth->fetchrow_hashref;
1319 =head2 get_itemnumbers_of
1323 my @itemnumbers_of = get_itemnumbers_of(@biblionumbers);
1325 Given a list of biblionumbers, return the list of corresponding itemnumbers
1326 for each biblionumber.
1328 Return a reference on a hash where keys are biblionumbers and values are
1329 references on array of itemnumbers.
1335 sub get_itemnumbers_of {
1336 my @biblionumbers = @_;
1338 my $dbh = C4::Context->dbh;
1344 WHERE biblionumber IN (?' . ( ',?' x scalar @biblionumbers - 1 ) . ')
1346 my $sth = $dbh->prepare($query);
1347 $sth->execute(@biblionumbers);
1351 while ( my ( $itemnumber, $biblionumber ) = $sth->fetchrow_array ) {
1352 push @{ $itemnumbers_of{$biblionumber} }, $itemnumber;
1355 return \%itemnumbers_of;
1358 =head2 GetItemInfosOf
1362 GetItemInfosOf(@itemnumbers);
1368 sub GetItemInfosOf {
1369 my @itemnumbers = @_;
1374 WHERE itemnumber IN (' . join( ',', @itemnumbers ) . ')
1376 return get_infos_of( $query, 'itemnumber' );
1379 =head2 GetItemsByBiblioitemnumber
1383 GetItemsByBiblioitemnumber($biblioitemnumber);
1385 Returns an arrayref of hashrefs suitable for use in a TMPL_LOOP
1386 Called by moredetail.pl
1392 sub GetItemsByBiblioitemnumber {
1393 my ( $bibitem ) = @_;
1394 my $dbh = C4::Context->dbh;
1395 my $sth = $dbh->prepare("SELECT * FROM items WHERE items.biblioitemnumber = ?") || die $dbh->errstr;
1396 # Get all items attached to a biblioitem
1399 $sth->execute($bibitem) || die $sth->errstr;
1400 while ( my $data = $sth->fetchrow_hashref ) {
1401 # Foreach item, get circulation information
1402 my $sth2 = $dbh->prepare( "SELECT * FROM issues,borrowers
1403 WHERE itemnumber = ?
1404 AND returndate is NULL
1405 AND issues.borrowernumber = borrowers.borrowernumber"
1407 $sth2->execute( $data->{'itemnumber'} );
1408 if ( my $data2 = $sth2->fetchrow_hashref ) {
1409 # if item is out, set the due date and who it is out too
1410 $data->{'date_due'} = $data2->{'date_due'};
1411 $data->{'cardnumber'} = $data2->{'cardnumber'};
1412 $data->{'borrowernumber'} = $data2->{'borrowernumber'};
1415 # set date_due to blank, so in the template we check itemlost, and wthdrawn
1416 $data->{'date_due'} = '';
1419 # Find the last 3 people who borrowed this item.
1420 my $query2 = "SELECT * FROM issues, borrowers WHERE itemnumber = ?
1421 AND issues.borrowernumber = borrowers.borrowernumber
1422 AND returndate is not NULL
1423 ORDER BY returndate desc,timestamp desc LIMIT 3";
1424 $sth2 = $dbh->prepare($query2) || die $dbh->errstr;
1425 $sth2->execute( $data->{'itemnumber'} ) || die $sth2->errstr;
1427 while ( my $data2 = $sth2->fetchrow_hashref ) {
1428 $data->{"timestamp$i2"} = $data2->{'timestamp'};
1429 $data->{"card$i2"} = $data2->{'cardnumber'};
1430 $data->{"borrower$i2"} = $data2->{'borrowernumber'};
1434 push(@results,$data);
1441 =head2 GetBiblioItemInfosOf
1445 GetBiblioItemInfosOf(@biblioitemnumbers);
1451 sub GetBiblioItemInfosOf {
1452 my @biblioitemnumbers = @_;
1455 SELECT biblioitemnumber,
1459 WHERE biblioitemnumber IN (' . join( ',', @biblioitemnumbers ) . ')
1461 return get_infos_of( $query, 'biblioitemnumber' );
1464 =head1 FUNCTIONS FOR HANDLING MARC MANAGEMENT
1466 =head2 GetMarcStructure
1470 $res = GetMarcStructure($forlibrarian,$frameworkcode);
1472 Returns a reference to a big hash of hash, with the Marc structure for the given frameworkcode
1473 $forlibrarian :if set to 1, the MARC descriptions are the librarians ones, otherwise it's the public (OPAC) ones
1474 $frameworkcode : the framework code to read
1480 sub GetMarcStructure {
1481 my ( $forlibrarian, $frameworkcode ) = @_;
1482 my $dbh=C4::Context->dbh;
1483 $frameworkcode = "" unless $frameworkcode;
1485 my $libfield = ( $forlibrarian eq 1 ) ? 'liblibrarian' : 'libopac';
1487 # check that framework exists
1490 "select count(*) from marc_tag_structure where frameworkcode=?");
1491 $sth->execute($frameworkcode);
1492 my ($total) = $sth->fetchrow;
1493 $frameworkcode = "" unless ( $total > 0 );
1496 "select tagfield,liblibrarian,libopac,mandatory,repeatable from marc_tag_structure where frameworkcode=? order by tagfield"
1498 $sth->execute($frameworkcode);
1499 my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable );
1501 while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable ) =
1504 $res->{$tag}->{lib} =
1505 ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac;
1506 # why the hell do we need to explicitly decode utf8 ?
1507 # that's a good question, but we must do it...
1508 $res->{$tab}->{tab} = ""; # XXX
1509 $res->{$tag}->{mandatory} = $mandatory;
1510 $res->{$tag}->{repeatable} = $repeatable;
1515 "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"
1518 $sth->execute($frameworkcode);
1521 my $authorised_value;
1533 $tag, $subfield, $liblibrarian,
1535 $mandatory, $repeatable, $authorised_value,
1536 $authtypecode, $value_builder, $kohafield,
1537 $seealso, $hidden, $isurl,
1543 $res->{$tag}->{$subfield}->{lib} =
1544 ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac;
1545 $res->{$tag}->{$subfield}->{tab} = $tab;
1546 $res->{$tag}->{$subfield}->{mandatory} = $mandatory;
1547 $res->{$tag}->{$subfield}->{repeatable} = $repeatable;
1548 $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
1549 $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode;
1550 $res->{$tag}->{$subfield}->{value_builder} = $value_builder;
1551 $res->{$tag}->{$subfield}->{kohafield} = $kohafield;
1552 $res->{$tag}->{$subfield}->{seealso} = $seealso;
1553 $res->{$tag}->{$subfield}->{hidden} = $hidden;
1554 $res->{$tag}->{$subfield}->{isurl} = $isurl;
1555 $res->{$tag}->{$subfield}->{'link'} = $link;
1556 $res->{$tag}->{$subfield}->{defaultvalue} = $defaultvalue;
1561 =head2 GetUsedMarcStructure
1563 the same function as GetMarcStructure expcet it just take field
1564 in tab 0-9. (used field)
1566 my $results = GetUsedMarcStructure($frameworkcode);
1568 L<$results> is a ref to an array which each case containts a ref
1569 to a hash which each keys is the columns from marc_subfield_structure
1571 L<$frameworkcode> is the framework code.
1575 sub GetUsedMarcStructure($){
1576 my $frameworkcode = shift || '';
1577 my $dbh = C4::Context->dbh;
1580 FROM marc_subfield_structure
1582 AND frameworkcode = ?
1585 my $sth = $dbh->prepare($query);
1586 $sth->execute($frameworkcode);
1587 while (my $row = $sth->fetchrow_hashref){
1593 =head2 GetMarcFromKohaField
1597 ($MARCfield,$MARCsubfield)=GetMarcFromKohaField($kohafield,$frameworkcode);
1598 Returns the MARC fields & subfields mapped to the koha field
1599 for the given frameworkcode
1605 sub GetMarcFromKohaField {
1606 my ( $kohafield, $frameworkcode ) = @_;
1607 return 0, 0 unless $kohafield;
1608 my $relations = C4::Context->marcfromkohafield;
1610 $relations->{$frameworkcode}->{$kohafield}->[0],
1611 $relations->{$frameworkcode}->{$kohafield}->[1]
1615 =head2 GetMarcBiblio
1619 Returns MARC::Record of the biblionumber passed in parameter.
1620 the marc record contains both biblio & item datas
1627 my $biblionumber = shift;
1628 my $dbh = C4::Context->dbh;
1630 $dbh->prepare("select marcxml from biblioitems where biblionumber=? ");
1631 $sth->execute($biblionumber);
1632 my ($marcxml) = $sth->fetchrow;
1633 MARC::File::XML->default_record_format(C4::Context->preference('marcflavour'));
1634 $marcxml =~ s/\x1e//g;
1635 $marcxml =~ s/\x1f//g;
1636 $marcxml =~ s/\x1d//g;
1637 $marcxml =~ s/\x0f//g;
1638 $marcxml =~ s/\x0c//g;
1640 my $record = MARC::Record->new();
1642 $record = eval {MARC::Record::new_from_xml( $marcxml, "utf8",C4::Context->preference('marcflavour'))} if ($marcxml);
1644 # $record = MARC::Record::new_from_usmarc( $marc) if $marc;
1652 my $marcxml = GetXmlBiblio($biblionumber);
1654 Returns biblioitems.marcxml of the biblionumber passed in parameter.
1655 The XML contains both biblio & item datas
1662 my ( $biblionumber ) = @_;
1663 my $dbh = C4::Context->dbh;
1665 $dbh->prepare("select marcxml from biblioitems where biblionumber=? ");
1666 $sth->execute($biblionumber);
1667 my ($marcxml) = $sth->fetchrow;
1671 =head2 GetAuthorisedValueDesc
1675 my $subfieldvalue =get_authorised_value_desc(
1676 $tag, $subf[$i][0],$subf[$i][1], '', $taglib);
1677 Retrieve the complete description for a given authorised value.
1683 sub GetAuthorisedValueDesc {
1684 my ( $tag, $subfield, $value, $framework, $tagslib ) = @_;
1685 my $dbh = C4::Context->dbh;
1688 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
1689 return C4::Branch::GetBranchName($value);
1693 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
1694 return getitemtypeinfo($value)->{description};
1697 #---- "true" authorized value
1698 my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
1699 if ( $category ne "" ) {
1702 "select lib from authorised_values where category = ? and authorised_value = ?"
1704 $sth->execute( $category, $value );
1705 my $data = $sth->fetchrow_hashref;
1706 return $data->{'lib'};
1709 return $value; # if nothing is found return the original value
1717 Returns MARC::Record of the item passed in parameter.
1724 my ( $biblionumber, $itemnumber ) = @_;
1725 my $dbh = C4::Context->dbh;
1726 my $newrecord = MARC::Record->new();
1727 my $marcflavour = C4::Context->preference('marcflavour');
1729 my $marcxml = GetXmlBiblio($biblionumber);
1730 my $record = MARC::Record->new();
1731 $record = MARC::Record::new_from_xml( $marcxml, "utf8", $marcflavour );
1732 # now, find where the itemnumber is stored & extract only the item
1733 my ( $itemnumberfield, $itemnumbersubfield ) =
1734 GetMarcFromKohaField( 'items.itemnumber', '' );
1735 my @fields = $record->field($itemnumberfield);
1736 foreach my $field (@fields) {
1737 if ( $field->subfield($itemnumbersubfield) eq $itemnumber ) {
1738 $newrecord->insert_fields_ordered($field);
1750 $marcnotesarray = GetMarcNotes( $record, $marcflavour );
1751 Get all notes from the MARC record and returns them in an array.
1752 The note are stored in differents places depending on MARC flavour
1759 my ( $record, $marcflavour ) = @_;
1761 if ( $marcflavour eq "MARC21" ) {
1764 else { # assume unimarc if not marc21
1771 foreach my $field ( $record->field($scope) ) {
1772 my $value = $field->as_string();
1773 if ( $note ne "" ) {
1774 $marcnote = { marcnote => $note, };
1775 push @marcnotes, $marcnote;
1778 if ( $note ne $value ) {
1779 $note = $note . " " . $value;
1784 $marcnote = { marcnote => $note };
1785 push @marcnotes, $marcnote; #load last tag into array
1788 } # end GetMarcNotes
1790 =head2 GetMarcSubjects
1794 $marcsubjcts = GetMarcSubjects($record,$marcflavour);
1795 Get all subjects from the MARC record and returns them in an array.
1796 The subjects are stored in differents places depending on MARC flavour
1802 sub GetMarcSubjects {
1803 my ( $record, $marcflavour ) = @_;
1804 my ( $mintag, $maxtag );
1805 if ( $marcflavour eq "MARC21" ) {
1809 else { # assume unimarc if not marc21
1816 foreach my $field ( $record->fields ) {
1817 next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1818 my @subfields = $field->subfields();
1822 my $authoritysep=C4::Context->preference("authoritysep");
1823 for my $subject_subfield ( @subfields ) {
1825 $marcflavour ne 'MARC21'
1827 ($subject_subfield->[0] eq '3') or
1828 ($subject_subfield->[0] eq '4') or
1829 ($subject_subfield->[0] eq '5')
1835 my $code = $subject_subfield->[0];
1836 $label .= $subject_subfield->[1].$authoritysep unless ( $code == 9 );
1837 $link .= " and su-to:".$subject_subfield->[1] unless ( $code == 9 );
1839 $link = "an:".$subject_subfield->[1];
1843 $link =~ s/ and\ssu-to:$//;
1846 $label =~ s/$authoritysep$//;
1853 return \@marcsubjcts;
1854 } #end GetMarcSubjects
1856 =head2 GetMarcAuthors
1860 authors = GetMarcAuthors($record,$marcflavour);
1861 Get all authors from the MARC record and returns them in an array.
1862 The authors are stored in differents places depending on MARC flavour
1868 sub GetMarcAuthors {
1869 my ( $record, $marcflavour ) = @_;
1870 my ( $mintag, $maxtag );
1871 # tagslib useful for UNIMARC author reponsabilities
1872 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.
1873 if ( $marcflavour eq "MARC21" ) {
1877 else { # assume unimarc if not marc21
1884 foreach my $field ( $record->fields ) {
1885 next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1887 my @subfields = $field->subfields();
1890 for my $authors_subfield (@subfields) {
1892 $marcflavour ne 'MARC21'
1894 ($authors_subfield->[0] eq '3') or
1895 ($authors_subfield->[0] eq '5')
1901 if ($count_auth ne '0'){
1905 my $subfieldcode = $authors_subfield->[0];
1907 # deal with UNIMARC author responsibility
1909 $marcflavour ne 'MARC21'
1910 and ($authors_subfield->[0] eq '4')
1913 $value = "(".GetAuthorisedValueDesc( $field->tag(), $authors_subfield->[0], $authors_subfield->[1], '', $tagslib ).")";
1915 $value = $authors_subfield->[1];
1917 $hash{tag} = $field->tag;
1918 $hash{value} .= $value . " " if ($subfieldcode != 9) ;
1919 $hash{link} .= $value if ($subfieldcode eq 9);
1921 push @marcauthors, \%hash;
1923 return \@marcauthors;
1930 $marcurls = GetMarcUrls($record,$marcflavour);
1931 Returns arrayref of URLs from MARC data, suitable to pass to tmpl loop.
1932 Assumes web resources (not uncommon in MARC21 to omit resource type ind)
1939 my ($record, $marcflavour) = @_;
1942 for my $field ($record->field('856')) {
1943 my $url = $field->subfield('u');
1945 for my $note ( $field->subfield('z')) {
1946 push @notes , {note => $note};
1948 $marcurl = { MARCURL => $url,
1951 if($marcflavour eq 'MARC21') {
1952 my $s3 = $field->subfield('3');
1953 my $link = $field->subfield('y');
1954 $marcurl->{'linktext'} = $link || $s3 || $url ;;
1955 $marcurl->{'part'} = $s3 if($link);
1956 $marcurl->{'toc'} = 1 if($s3 =~ /^[Tt]able/) ;
1958 $marcurl->{'linktext'} = $url;
1960 push @marcurls, $marcurl;
1965 =head2 GetMarcSeries
1969 $marcseriesarray = GetMarcSeries($record,$marcflavour);
1970 Get all series from the MARC record and returns them in an array.
1971 The series are stored in differents places depending on MARC flavour
1978 my ($record, $marcflavour) = @_;
1979 my ($mintag, $maxtag);
1980 if ($marcflavour eq "MARC21") {
1983 } else { # assume unimarc if not marc21
1993 foreach my $field ($record->field('440'), $record->field('490')) {
1995 #my $value = $field->subfield('a');
1996 #$marcsubjct = {MARCSUBJCT => $value,};
1997 my @subfields = $field->subfields();
1998 #warn "subfields:".join " ", @$subfields;
2001 for my $series_subfield (@subfields) {
2003 undef $volume_number;
2004 # see if this is an instance of a volume
2005 if ($series_subfield->[0] eq 'v') {
2009 my $code = $series_subfield->[0];
2010 my $value = $series_subfield->[1];
2011 my $linkvalue = $value;
2012 $linkvalue =~ s/(\(|\))//g;
2013 my $operator = " and " unless $counter==0;
2014 push @link_loop, {link => $linkvalue, operator => $operator };
2015 my $separator = C4::Context->preference("authoritysep") unless $counter==0;
2016 if ($volume_number) {
2017 push @subfields_loop, {volumenum => $value};
2020 push @subfields_loop, {code => $code, value => $value, link_loop => \@link_loop, separator => $separator, volumenum => $volume_number};
2024 push @marcseries, { MARCSERIES_SUBFIELDS_LOOP => \@subfields_loop };
2025 #$marcsubjct = {MARCSUBJCT => $field->as_string(),};
2026 #push @marcsubjcts, $marcsubjct;
2030 my $marcseriessarray=\@marcseries;
2031 return $marcseriessarray;
2032 } #end getMARCseriess
2034 =head2 GetFrameworkCode
2038 $frameworkcode = GetFrameworkCode( $biblionumber )
2044 sub GetFrameworkCode {
2045 my ( $biblionumber ) = @_;
2046 my $dbh = C4::Context->dbh;
2047 my $sth = $dbh->prepare("select frameworkcode from biblio where biblionumber=?");
2048 $sth->execute($biblionumber);
2049 my ($frameworkcode) = $sth->fetchrow;
2050 return $frameworkcode;
2053 =head2 GetPublisherNameFromIsbn
2055 $name = GetPublishercodeFromIsbn($isbn);
2062 sub GetPublisherNameFromIsbn($){
2064 $isbn =~ s/[- _]//g;
2066 my @codes = (split '-', DisplayISBN($isbn));
2067 my $code = $codes[0].$codes[1].$codes[2];
2068 my $dbh = C4::Context->dbh;
2070 SELECT distinct publishercode
2073 AND publishercode IS NOT NULL
2076 my $sth = $dbh->prepare($query);
2077 $sth->execute("$code%");
2078 my $name = $sth->fetchrow;
2079 return $name if length $name;
2083 =head2 TransformKohaToMarc
2087 $record = TransformKohaToMarc( $hash )
2088 This function builds partial MARC::Record from a hash
2089 Hash entries can be from biblio or biblioitems.
2090 This function is called in acquisition module, to create a basic catalogue entry from user entry
2096 sub TransformKohaToMarc {
2099 my $dbh = C4::Context->dbh;
2102 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
2104 my $record = MARC::Record->new();
2105 foreach (keys %{$hash}) {
2106 &TransformKohaToMarcOneField( $sth, $record, $_,
2112 =head2 TransformKohaToMarcOneField
2116 $record = TransformKohaToMarcOneField( $sth, $record, $kohafieldname, $value, $frameworkcode );
2122 sub TransformKohaToMarcOneField {
2123 my ( $sth, $record, $kohafieldname, $value, $frameworkcode ) = @_;
2124 $frameworkcode='' unless $frameworkcode;
2128 if ( !defined $sth ) {
2129 my $dbh = C4::Context->dbh;
2130 $sth = $dbh->prepare(
2131 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
2134 $sth->execute( $frameworkcode, $kohafieldname );
2135 if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
2136 my $tag = $record->field($tagfield);
2138 $tag->update( $tagsubfield => $value );
2139 $record->delete_field($tag);
2140 $record->insert_fields_ordered($tag);
2143 $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
2149 =head2 TransformHtmlToXml
2153 $xml = TransformHtmlToXml( $tags, $subfields, $values, $indicator, $ind_tag, $auth_type )
2155 $auth_type contains :
2156 - nothing : rebuild a biblio, un UNIMARC the encoding is in 100$a pos 26/27
2157 - UNIMARCAUTH : rebuild an authority. In UNIMARC, the encoding is in 100$a pos 13/14
2158 - ITEM : rebuild an item : in UNIMARC, 100$a, it's in the biblio ! (otherwise, we would get 2 100 fields !)
2164 sub TransformHtmlToXml {
2165 my ( $tags, $subfields, $values, $indicator, $ind_tag, $auth_type ) = @_;
2166 my $xml = MARC::File::XML::header('UTF-8');
2167 $auth_type = C4::Context->preference('marcflavour') unless $auth_type;
2168 MARC::File::XML->default_record_format($auth_type);
2169 # in UNIMARC, field 100 contains the encoding
2170 # check that there is one, otherwise the
2171 # MARC::Record->new_from_xml will fail (and Koha will die)
2172 my $unimarc_and_100_exist=0;
2173 $unimarc_and_100_exist=1 if $auth_type eq 'ITEM'; # if we rebuild an item, no need of a 100 field
2178 for ( my $i = 0 ; $i <= @$tags ; $i++ ) {
2179 if (C4::Context->preference('marcflavour') eq 'UNIMARC' and @$tags[$i] eq "100" and @$subfields[$i] eq "a") {
2180 # if we have a 100 field and it's values are not correct, skip them.
2181 # if we don't have any valid 100 field, we will create a default one at the end
2182 my $enc = substr( @$values[$i], 26, 2 );
2183 if ($enc eq '01' or $enc eq '50' or $enc eq '03') {
2184 $unimarc_and_100_exist=1;
2189 @$values[$i] =~ s/&/&/g;
2190 @$values[$i] =~ s/</</g;
2191 @$values[$i] =~ s/>/>/g;
2192 @$values[$i] =~ s/"/"/g;
2193 @$values[$i] =~ s/'/'/g;
2194 # if ( !utf8::is_utf8( @$values[$i] ) ) {
2195 # utf8::decode( @$values[$i] );
2197 if ( ( @$tags[$i] ne $prevtag ) ) {
2198 $j++ unless ( @$tags[$i] eq "" );
2200 $xml .= "</datafield>\n";
2201 if ( ( @$tags[$i] && @$tags[$i] > 10 )
2202 && ( @$values[$i] ne "" ) )
2204 my $ind1 = substr( @$indicator[$j], 0, 1 );
2206 if ( @$indicator[$j] ) {
2207 $ind2 = substr( @$indicator[$j], 1, 1 );
2210 warn "Indicator in @$tags[$i] is empty";
2214 "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
2216 "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2224 if ( @$values[$i] ne "" ) {
2227 if ( @$tags[$i] eq "000" ) {
2228 $xml .= "<leader>@$values[$i]</leader>\n";
2231 # rest of the fixed fields
2233 elsif ( @$tags[$i] < 10 ) {
2235 "<controlfield tag=\"@$tags[$i]\">@$values[$i]</controlfield>\n";
2239 my $ind1 = substr( @$indicator[$j], 0, 1 );
2240 my $ind2 = substr( @$indicator[$j], 1, 1 );
2242 "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
2244 "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2250 else { # @$tags[$i] eq $prevtag
2251 if ( @$values[$i] eq "" ) {
2255 my $ind1 = substr( @$indicator[$j], 0, 1 );
2256 my $ind2 = substr( @$indicator[$j], 1, 1 );
2258 "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
2262 "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
2265 $prevtag = @$tags[$i];
2267 if (C4::Context->preference('marcflavour') and !$unimarc_and_100_exist) {
2268 # warn "SETTING 100 for $auth_type";
2269 use POSIX qw(strftime);
2270 my $string = strftime( "%Y%m%d", localtime(time) );
2271 # set 50 to position 26 is biblios, 13 if authorities
2273 $pos=13 if $auth_type eq 'UNIMARCAUTH';
2274 $string = sprintf( "%-*s", 35, $string );
2275 substr( $string, $pos , 6, "50" );
2276 $xml .= "<datafield tag=\"100\" ind1=\"\" ind2=\"\">\n";
2277 $xml .= "<subfield code=\"a\">$string</subfield>\n";
2278 $xml .= "</datafield>\n";
2280 $xml .= MARC::File::XML::footer();
2284 =head2 TransformHtmlToMarc
2286 L<$record> = TransformHtmlToMarc(L<$params>,L<$cgi>)
2287 L<$params> is a ref to an array as below:
2289 'tag_010_indicator_531951' ,
2290 'tag_010_code_a_531951_145735' ,
2291 'tag_010_subfield_a_531951_145735' ,
2292 'tag_200_indicator_873510' ,
2293 'tag_200_code_a_873510_673465' ,
2294 'tag_200_subfield_a_873510_673465' ,
2295 'tag_200_code_b_873510_704318' ,
2296 'tag_200_subfield_b_873510_704318' ,
2297 'tag_200_code_e_873510_280822' ,
2298 'tag_200_subfield_e_873510_280822' ,
2299 'tag_200_code_f_873510_110730' ,
2300 'tag_200_subfield_f_873510_110730' ,
2302 L<$cgi> is the CGI object which containts the value.
2303 L<$record> is the MARC::Record object.
2307 sub TransformHtmlToMarc {
2311 # creating a new record
2312 my $record = MARC::Record->new();
2315 while ($params->[$i]){ # browse all CGI params
2316 my $param = $params->[$i];
2318 # if we are on biblionumber, store it in the MARC::Record (it may not be in the edited fields)
2319 if ($param eq 'biblionumber') {
2320 my ( $biblionumbertagfield, $biblionumbertagsubfield ) =
2321 &GetMarcFromKohaField( "biblio.biblionumber", '' );
2322 if ($biblionumbertagfield < 10) {
2323 $newfield = MARC::Field->new(
2324 $biblionumbertagfield,
2325 $cgi->param($param),
2328 $newfield = MARC::Field->new(
2329 $biblionumbertagfield,
2332 "$biblionumbertagsubfield" => $cgi->param($param),
2335 push @fields,$newfield if($newfield);
2337 elsif ($param =~ /^tag_(\d*)_indicator_/){ # new field start when having 'input name="..._indicator_..."
2340 my $ind1 = substr($cgi->param($param),0,1);
2341 my $ind2 = substr($cgi->param($param),1,1);
2345 if($tag < 10){ # no code for theses fields
2346 # in MARC editor, 000 contains the leader.
2347 if ($tag eq '000' ) {
2348 $record->leader($cgi->param($params->[$j+1])) if length($cgi->param($params->[$j+1]))==24;
2349 # between 001 and 009 (included)
2351 $newfield = MARC::Field->new(
2353 $cgi->param($params->[$j+1]),
2356 # > 009, deal with subfields
2358 while($params->[$j] =~ /_code_/){ # browse all it's subfield
2359 my $inner_param = $params->[$j];
2361 if($cgi->param($params->[$j+1])){ # only if there is a value (code => value)
2362 $newfield->add_subfields(
2363 $cgi->param($inner_param) => $cgi->param($params->[$j+1])
2367 if ( $cgi->param($params->[$j+1]) ) { # creating only if there is a value (code => value)
2368 $newfield = MARC::Field->new(
2372 $cgi->param($inner_param) => $cgi->param($params->[$j+1]),
2379 push @fields,$newfield if($newfield);
2384 $record->append_fields(@fields);
2388 =head2 TransformMarcToKoha
2392 $result = TransformMarcToKoha( $dbh, $record, $frameworkcode )
2398 sub TransformMarcToKoha {
2399 my ( $dbh, $record, $frameworkcode ) = @_;
2401 # FIXME :: This query is unused..
2404 #"select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
2408 my $sth2 = $dbh->prepare("SHOW COLUMNS from biblio");
2411 while ( ($field) = $sth2->fetchrow ) {
2413 &TransformMarcToKohaOneField( "biblio", $field, $record, $result,
2416 my $sth2 = $dbh->prepare("SHOW COLUMNS from biblioitems");
2418 while ( ($field) = $sth2->fetchrow ) {
2419 if ( $field eq 'notes' ) { $field = 'bnotes'; }
2421 &TransformMarcToKohaOneField( "biblioitems", $field, $record, $result,
2424 $sth2 = $dbh->prepare("SHOW COLUMNS from items");
2426 while ( ($field) = $sth2->fetchrow ) {
2428 &TransformMarcToKohaOneField( "items", $field, $record, $result,
2433 # modify copyrightdate to keep only the 1st year found
2434 my $temp = $result->{'copyrightdate'};
2435 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
2437 $result->{'copyrightdate'} = $1;
2439 else { # if no cYYYY, get the 1st date.
2440 $temp =~ m/(\d\d\d\d)/;
2441 $result->{'copyrightdate'} = $1;
2444 # modify publicationyear to keep only the 1st year found
2445 $temp = $result->{'publicationyear'};
2446 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
2448 $result->{'publicationyear'} = $1;
2450 else { # if no cYYYY, get the 1st date.
2451 $temp =~ m/(\d\d\d\d)/;
2452 $result->{'publicationyear'} = $1;
2457 =head2 TransformMarcToKohaOneField
2461 $result = TransformMarcToKohaOneField( $kohatable, $kohafield, $record, $result, $frameworkcode )
2467 sub TransformMarcToKohaOneField {
2469 # FIXME ? if a field has a repeatable subfield that is used in old-db,
2470 # only the 1st will be retrieved...
2471 my ( $kohatable, $kohafield, $record, $result, $frameworkcode ) = @_;
2473 my ( $tagfield, $subfield ) =
2474 GetMarcFromKohaField( $kohatable . "." . $kohafield,
2476 foreach my $field ( $record->field($tagfield) ) {
2477 if ( $field->tag() < 10 ) {
2478 if ( $result->{$kohafield} ) {
2479 $result->{$kohafield} .= " | " . $field->data();
2482 $result->{$kohafield} = $field->data();
2486 if ( $field->subfields ) {
2487 my @subfields = $field->subfields();
2488 foreach my $subfieldcount ( 0 .. $#subfields ) {
2489 if ( $subfields[$subfieldcount][0] eq $subfield ) {
2490 if ( $result->{$kohafield} ) {
2491 $result->{$kohafield} .=
2492 " | " . $subfields[$subfieldcount][1];
2495 $result->{$kohafield} =
2496 $subfields[$subfieldcount][1];
2506 =head1 OTHER FUNCTIONS
2512 my $string = char_decode( $string, $encoding );
2514 converts ISO 5426 coded string to UTF-8
2515 sloppy code : should be improved in next issue
2522 my ( $string, $encoding ) = @_;
2525 $encoding = C4::Context->preference("marcflavour") unless $encoding;
2526 if ( $encoding eq "UNIMARC" ) {
2596 # this handles non-sorting blocks (if implementation requires this)
2597 $string = nsb_clean($_);
2599 elsif ( $encoding eq "USMARC" || $encoding eq "MARC21" ) {
2658 #Additional Turkish characters
2661 s/(\xf0)s/\xc5\x9f/gm;
2662 s/(\xf0)S/\xc5\x9e/gm;
2665 s/\xe7\x49/\\xc4\xb0/gm;
2666 s/(\xe6)G/\xc4\x9e/gm;
2667 s/(\xe6)g/ğ\xc4\x9f/gm;
2670 s/(\xe8|\xc8)o/ö/gm;
2671 s/(\xe8|\xc8)O/Ö/gm;
2672 s/(\xe8|\xc8)u/ü/gm;
2673 s/(\xe8|\xc8)U/Ü/gm;
2674 s/\xc2\xb8/\xc4\xb1/gm;
2677 # this handles non-sorting blocks (if implementation requires this)
2678 $string = nsb_clean($_);
2687 my $string = nsb_clean( $string, $encoding );
2694 my $NSB = '\x88'; # NSB : begin Non Sorting Block
2695 my $NSE = '\x89'; # NSE : Non Sorting Block end
2696 # handles non sorting blocks
2700 s/[ ]{0,1}$NSE/) /gm;
2705 =head2 PrepareItemrecordDisplay
2709 PrepareItemrecordDisplay($itemrecord,$bibnum,$itemumber);
2711 Returns a hash with all the fields for Display a given item data in a template
2717 sub PrepareItemrecordDisplay {
2719 my ( $bibnum, $itemnum ) = @_;
2721 my $dbh = C4::Context->dbh;
2722 my $frameworkcode = &GetFrameworkCode( $bibnum );
2723 my ( $itemtagfield, $itemtagsubfield ) =
2724 &GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2725 my $tagslib = &GetMarcStructure( 1, $frameworkcode );
2726 my $itemrecord = GetMarcItem( $bibnum, $itemnum) if ($itemnum);
2728 my $authorised_values_sth =
2730 "select authorised_value,lib from authorised_values where category=? order by lib"
2732 foreach my $tag ( sort keys %{$tagslib} ) {
2733 my $previous_tag = '';
2735 # loop through each subfield
2737 foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
2738 next if ( subfield_is_koha_internal_p($subfield) );
2739 next if ( $tagslib->{$tag}->{$subfield}->{'tab'} ne "10" );
2741 $subfield_data{tag} = $tag;
2742 $subfield_data{subfield} = $subfield;
2743 $subfield_data{countsubfield} = $cntsubf++;
2744 $subfield_data{kohafield} =
2745 $tagslib->{$tag}->{$subfield}->{'kohafield'};
2747 # $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
2748 $subfield_data{marc_lib} =
2749 "<span id=\"error\" title=\""
2750 . $tagslib->{$tag}->{$subfield}->{lib} . "\">"
2751 . substr( $tagslib->{$tag}->{$subfield}->{lib}, 0, 12 )
2753 $subfield_data{mandatory} =
2754 $tagslib->{$tag}->{$subfield}->{mandatory};
2755 $subfield_data{repeatable} =
2756 $tagslib->{$tag}->{$subfield}->{repeatable};
2757 $subfield_data{hidden} = "display:none"
2758 if $tagslib->{$tag}->{$subfield}->{hidden};
2760 ( $x, $value ) = _find_value( $tag, $subfield, $itemrecord )
2762 $value =~ s/"/"/g;
2764 # search for itemcallnumber if applicable
2765 if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
2766 'items.itemcallnumber'
2767 && C4::Context->preference('itemcallnumber') )
2770 substr( C4::Context->preference('itemcallnumber'), 0, 3 );
2772 substr( C4::Context->preference('itemcallnumber'), 3, 1 );
2773 my $temp = $itemrecord->field($CNtag) if ($itemrecord);
2775 $value = $temp->subfield($CNsubfield);
2778 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
2779 my @authorised_values;
2782 # builds list, depending on authorised value...
2784 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq
2787 if ( ( C4::Context->preference("IndependantBranches") )
2788 && ( C4::Context->userenv->{flags} != 1 ) )
2792 "select branchcode,branchname from branches where branchcode = ? order by branchname"
2794 $sth->execute( C4::Context->userenv->{branch} );
2795 push @authorised_values, ""
2797 $tagslib->{$tag}->{$subfield}->{mandatory} );
2798 while ( my ( $branchcode, $branchname ) =
2799 $sth->fetchrow_array )
2801 push @authorised_values, $branchcode;
2802 $authorised_lib{$branchcode} = $branchname;
2808 "select branchcode,branchname from branches order by branchname"
2811 push @authorised_values, ""
2813 $tagslib->{$tag}->{$subfield}->{mandatory} );
2814 while ( my ( $branchcode, $branchname ) =
2815 $sth->fetchrow_array )
2817 push @authorised_values, $branchcode;
2818 $authorised_lib{$branchcode} = $branchname;
2824 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq
2829 "select itemtype,description from itemtypes order by description"
2832 push @authorised_values, ""
2833 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2834 while ( my ( $itemtype, $description ) =
2835 $sth->fetchrow_array )
2837 push @authorised_values, $itemtype;
2838 $authorised_lib{$itemtype} = $description;
2841 #---- "true" authorised value
2844 $authorised_values_sth->execute(
2845 $tagslib->{$tag}->{$subfield}->{authorised_value} );
2846 push @authorised_values, ""
2847 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
2848 while ( my ( $value, $lib ) =
2849 $authorised_values_sth->fetchrow_array )
2851 push @authorised_values, $value;
2852 $authorised_lib{$value} = $lib;
2855 $subfield_data{marc_value} = CGI::scrolling_list(
2856 -name => 'field_value',
2857 -values => \@authorised_values,
2858 -default => "$value",
2859 -labels => \%authorised_lib,
2865 elsif ( $tagslib->{$tag}->{$subfield}->{thesaurus_category} ) {
2866 $subfield_data{marc_value} =
2867 "<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>";
2870 # COMMENTED OUT because No $i is provided with this API.
2871 # And thus, no value_builder can be activated.
2872 # BUT could be thought over.
2873 # } elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
2874 # my $plugin="value_builder/".$tagslib->{$tag}->{$subfield}->{'value_builder'};
2876 # my $extended_param = plugin_parameters($dbh,$itemrecord,$tagslib,$i,0);
2877 # my ($function_name,$javascript) = plugin_javascript($dbh,$record,$tagslib,$i,0);
2878 # $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";
2881 $subfield_data{marc_value} =
2882 "<input type=\"text\" name=\"field_value\" value=\"$value\" size=50 maxlength=255>";
2884 push( @loop_data, \%subfield_data );
2888 my $itemnumber = $itemrecord->subfield( $itemtagfield, $itemtagsubfield )
2889 if ( $itemrecord && $itemrecord->field($itemtagfield) );
2891 'itemtagfield' => $itemtagfield,
2892 'itemtagsubfield' => $itemtagsubfield,
2893 'itemnumber' => $itemnumber,
2894 'iteminformation' => \@loop_data
2900 # true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates
2902 # replaced by a zebraqueue table, that is filled with ModZebra to run.
2903 # the table is emptied by misc/cronjobs/zebraqueue_start.pl script
2904 # =head2 ModZebrafiles
2906 # &ModZebrafiles( $dbh, $biblionumber, $record, $folder, $server );
2910 # sub ModZebrafiles {
2912 # my ( $dbh, $biblionumber, $record, $folder, $server ) = @_;
2916 # C4::Context->zebraconfig($server)->{directory} . "/" . $folder . "/";
2917 # unless ( opendir( DIR, "$zebradir" ) ) {
2918 # warn "$zebradir not found";
2922 # my $filename = $zebradir . $biblionumber;
2925 # open( OUTPUT, ">", $filename . ".xml" );
2926 # print OUTPUT $record;
2935 ModZebra( $biblionumber, $op, $server, $newRecord );
2937 $biblionumber is the biblionumber we want to index
2938 $op is specialUpdate or delete, and is used to know what we want to do
2939 $server is the server that we want to update
2940 $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.
2947 ###Accepts a $server variable thus we can use it for biblios authorities or other zebra dbs
2948 my ( $biblionumber, $op, $server, $newRecord ) = @_;
2949 my $dbh=C4::Context->dbh;
2951 # true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates
2953 # replaced by a zebraqueue table, that is filled with ModZebra to run.
2954 # the table is emptied by misc/cronjobs/zebraqueue_start.pl script
2956 if (C4::Context->preference("NoZebra")) {
2957 # lock the nozebra table : we will read index lines, update them in Perl process
2958 # and write everything in 1 transaction.
2959 # lock the table to avoid someone else overwriting what we are doing
2960 $dbh->do('LOCK TABLES nozebra WRITE,biblio WRITE,biblioitems WRITE, systempreferences WRITE, auth_types WRITE, auth_header WRITE');
2961 my %result; # the result hash that will be builded by deletion / add, and written on mySQL at the end, to improve speed
2963 if ($server eq 'biblioserver') {
2964 $record= GetMarcBiblio($biblionumber);
2966 $record= C4::AuthoritiesMarc::GetAuthority($biblionumber);
2968 if ($op eq 'specialUpdate') {
2969 # OK, we have to add or update the record
2970 # 1st delete (virtually, in indexes) ...
2971 %result = _DelBiblioNoZebra($biblionumber,$record,$server);
2972 # ... add the record
2973 %result=_AddBiblioNoZebra($biblionumber,$newRecord, $server, %result);
2975 # it's a deletion, delete the record...
2976 # warn "DELETE the record $biblionumber on $server".$record->as_formatted;
2977 %result=_DelBiblioNoZebra($biblionumber,$record,$server);
2979 # ok, now update the database...
2980 my $sth = $dbh->prepare("UPDATE nozebra SET biblionumbers=? WHERE server=? AND indexname=? AND value=?");
2981 foreach my $key (keys %result) {
2982 foreach my $index (keys %{$result{$key}}) {
2983 $sth->execute($result{$key}->{$index}, $server, $key, $index);
2986 $dbh->do('UNLOCK TABLES');
2990 # we use zebra, just fill zebraqueue table
2992 my $sth=$dbh->prepare("insert into zebraqueue (biblio_auth_number ,server,operation) values(?,?,?)");
2993 $sth->execute($biblionumber,$server,$op);
2998 =head2 GetNoZebraIndexes
3000 %indexes = GetNoZebraIndexes;
3002 return the data from NoZebraIndexes syspref.
3006 sub GetNoZebraIndexes {
3007 my $index = C4::Context->preference('NoZebraIndexes');
3009 foreach my $line (split /('|"),/,$index) {
3010 $line =~ /(.*)=>(.*)/;
3011 my $index = substr($1,1); # get the index, don't forget to remove initial ' or "
3013 $index =~ s/'|"| //g;
3014 $fields =~ s/'|"| //g;
3015 $indexes{$index}=$fields;
3020 =head1 INTERNAL FUNCTIONS
3022 =head2 _DelBiblioNoZebra($biblionumber,$record,$server);
3024 function to delete a biblio in NoZebra indexes
3025 This function does NOT delete anything in database : it reads all the indexes entries
3026 that have to be deleted & delete them in the hash
3027 The SQL part is done either :
3028 - after the Add if we are modifying a biblio (delete + add again)
3029 - immediatly after this sub if we are doing a true deletion.
3030 $server can be 'biblioserver' or 'authorityserver' : it indexes biblios or authorities (in the same table, $server being part of the table itself
3035 sub _DelBiblioNoZebra {
3036 my ($biblionumber, $record, $server)=@_;
3039 my $dbh = C4::Context->dbh;
3043 if ($server eq 'biblioserver') {
3044 %index=GetNoZebraIndexes;
3045 # get title of the record (to store the 10 first letters with the index)
3046 my ($titletag,$titlesubfield) = GetMarcFromKohaField('biblio.title');
3047 $title = lc($record->subfield($titletag,$titlesubfield));
3049 # for authorities, the "title" is the $a mainentry
3050 my $authref = C4::AuthoritiesMarc::GetAuthType($record->subfield(152,'b'));
3051 warn "ERROR : authtype undefined for ".$record->as_formatted unless $authref;
3052 $title = $record->subfield($authref->{auth_tag_to_report},'a');
3053 $index{'mainmainentry'}= $authref->{'auth_tag_to_report'}.'a';
3054 $index{'mainentry'} = $authref->{'auth_tag_to_report'}.'*';
3055 $index{'auth_type'} = '152b';
3059 # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
3060 $title =~ s/ |,|;|\[|\]|\(|\)|\*|-|'|=//g;
3061 # limit to 10 char, should be enough, and limit the DB size
3062 $title = substr($title,0,10);
3064 my $sth2=$dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
3065 foreach my $field ($record->fields()) {
3066 #parse each subfield
3067 next if $field->tag <10;
3068 foreach my $subfield ($field->subfields()) {
3069 my $tag = $field->tag();
3070 my $subfieldcode = $subfield->[0];
3072 # check each index to see if the subfield is stored somewhere
3073 # otherwise, store it in __RAW__ index
3074 foreach my $key (keys %index) {
3075 # warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
3076 if ($index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/) {
3078 my $line= lc $subfield->[1];
3079 # remove meaningless value in the field...
3080 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
3081 # ... and split in words
3082 foreach (split / /,$line) {
3083 next unless $_; # skip empty values (multiple spaces)
3084 # if the entry is already here, do nothing, the biblionumber has already be removed
3085 unless ($result{$key}->{$_} =~ /$biblionumber,$title\-(\d);/) {
3086 # get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
3087 $sth2->execute($server,$key,$_);
3088 my $existing_biblionumbers = $sth2->fetchrow;
3090 if ($existing_biblionumbers) {
3091 # warn " existing for $key $_: $existing_biblionumbers";
3092 $result{$key}->{$_} =$existing_biblionumbers;
3093 $result{$key}->{$_} =~ s/$biblionumber,$title\-(\d);//;
3099 # the subfield is not indexed, store it in __RAW__ index anyway
3101 my $line= lc $subfield->[1];
3102 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
3103 # ... and split in words
3104 foreach (split / /,$line) {
3105 next unless $_; # skip empty values (multiple spaces)
3106 # if the entry is already here, do nothing, the biblionumber has already be removed
3107 unless ($result{'__RAW__'}->{$_} =~ /$biblionumber,$title\-(\d);/) {
3108 # get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
3109 $sth2->execute($server,'__RAW__',$_);
3110 my $existing_biblionumbers = $sth2->fetchrow;
3112 if ($existing_biblionumbers) {
3113 $result{'__RAW__'}->{$_} =$existing_biblionumbers;
3114 $result{'__RAW__'}->{$_} =~ s/$biblionumber,$title\-(\d);//;
3124 =head2 _AddBiblioNoZebra($biblionumber, $record, $server, %result);
3126 function to add a biblio in NoZebra indexes
3130 sub _AddBiblioNoZebra {
3131 my ($biblionumber, $record, $server, %result)=@_;
3132 my $dbh = C4::Context->dbh;
3136 if ($server eq 'biblioserver') {
3137 %index=GetNoZebraIndexes;
3138 # get title of the record (to store the 10 first letters with the index)
3139 my ($titletag,$titlesubfield) = GetMarcFromKohaField('biblio.title');
3140 $title = lc($record->subfield($titletag,$titlesubfield));
3142 # warn "server : $server";
3143 # for authorities, the "title" is the $a mainentry
3144 my $authref = C4::AuthoritiesMarc::GetAuthType($record->subfield(152,'b'));
3145 warn "ERROR : authtype undefined for ".$record->as_formatted unless $authref;
3146 $title = $record->subfield($authref->{auth_tag_to_report},'a');
3147 $index{'mainmainentry'} = $authref->{auth_tag_to_report}.'a';
3148 $index{'mainentry'} = $authref->{auth_tag_to_report}.'*';
3149 $index{'auth_type'} = '152b';
3152 # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
3153 $title =~ s/ |,|;|\[|\]|\(|\)|\*|-|'|=//g;
3154 # limit to 10 char, should be enough, and limit the DB size
3155 $title = substr($title,0,10);
3157 my $sth2=$dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
3158 foreach my $field ($record->fields()) {
3159 #parse each subfield
3160 next if $field->tag <10;
3161 foreach my $subfield ($field->subfields()) {
3162 my $tag = $field->tag();
3163 my $subfieldcode = $subfield->[0];
3165 # check each index to see if the subfield is stored somewhere
3166 # otherwise, store it in __RAW__ index
3167 foreach my $key (keys %index) {
3168 # warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
3169 if ($index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/) {
3171 my $line= lc $subfield->[1];
3172 # remove meaningless value in the field...
3173 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
3174 # ... and split in words
3175 foreach (split / /,$line) {
3176 next unless $_; # skip empty values (multiple spaces)
3177 # if the entry is already here, improve weight
3178 # warn "managing $_";
3179 if ($result{$key}->{"$_"} =~ /$biblionumber,$title\-(\d);/) {
3181 $result{$key}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
3182 $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
3184 # get the value if it exist in the nozebra table, otherwise, create it
3185 $sth2->execute($server,$key,$_);
3186 my $existing_biblionumbers = $sth2->fetchrow;
3188 if ($existing_biblionumbers) {
3189 $result{$key}->{"$_"} =$existing_biblionumbers;
3191 $result{$key}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
3192 $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
3193 # create a new ligne for this entry
3195 # warn "INSERT : $server / $key / $_";
3196 $dbh->do('INSERT INTO nozebra SET server='.$dbh->quote($server).', indexname='.$dbh->quote($key).',value='.$dbh->quote($_));
3197 $result{$key}->{"$_"}.="$biblionumber,$title-1;";
3203 # the subfield is not indexed, store it in __RAW__ index anyway
3205 my $line= lc $subfield->[1];
3206 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
3207 # ... and split in words
3208 foreach (split / /,$line) {
3209 next unless $_; # skip empty values (multiple spaces)
3210 # if the entry is already here, improve weight
3211 if ($result{'__RAW__'}->{"$_"} =~ /$biblionumber,$title\-(\d);/) {
3213 $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
3214 $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
3216 # get the value if it exist in the nozebra table, otherwise, create it
3217 $sth2->execute($server,'__RAW__',$_);
3218 my $existing_biblionumbers = $sth2->fetchrow;
3220 if ($existing_biblionumbers) {
3221 $result{'__RAW__'}->{"$_"} =$existing_biblionumbers;
3223 $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
3224 $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
3225 # create a new ligne for this entry
3227 $dbh->do('INSERT INTO nozebra SET server='.$dbh->quote($server).', indexname="__RAW__",value='.$dbh->quote($_));
3228 $result{'__RAW__'}->{"$_"}.="$biblionumber,$title-1;";
3239 =head2 MARCitemchange
3243 &MARCitemchange( $record, $itemfield, $newvalue )
3245 Function to update a single value in an item field.
3246 Used twice, could probably be replaced by something else, but works well...
3254 sub MARCitemchange {
3255 my ( $record, $itemfield, $newvalue ) = @_;
3256 my $dbh = C4::Context->dbh;
3258 my ( $tagfield, $tagsubfield ) =
3259 GetMarcFromKohaField( $itemfield, "" );
3260 if ( ($tagfield) && ($tagsubfield) ) {
3261 my $tag = $record->field($tagfield);
3263 $tag->update( $tagsubfield => $newvalue );
3264 $record->delete_field($tag);
3265 $record->insert_fields_ordered($tag);
3270 =head2 _koha_add_biblio
3274 _koha_add_biblio($dbh,$biblioitem);
3276 Internal function to add a biblio ($biblio is a hash with the values)
3282 sub _koha_add_biblio {
3283 my ( $dbh, $biblio, $frameworkcode ) = @_;
3284 my $sth = $dbh->prepare("Select max(biblionumber) from biblio");
3286 my $data = $sth->fetchrow_arrayref;
3287 my $biblionumber = $$data[0] + 1;
3290 if ( $biblio->{'seriestitle'} ) { $series = 1 }
3292 $sth = $dbh->prepare(
3294 SET datecreated=NOW(), biblionumber = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?, unititle = ?, frameworkcode = ? "
3297 $biblionumber, $biblio->{'title'},
3298 $biblio->{'author'}, $biblio->{'copyrightdate'},
3299 $biblio->{'serial'}, $biblio->{'seriestitle'},
3300 $biblio->{'notes'}, $biblio->{'abstract'},
3301 $biblio->{'unititle'}, $frameworkcode
3305 return ($biblionumber);
3312 ($indicators, $value) = _find_value($tag, $subfield, $record,$encoding);
3314 Find the given $subfield in the given $tag in the given
3315 MARC::Record $record. If the subfield is found, returns
3316 the (indicators, value) pair; otherwise, (undef, undef) is
3320 Such a function is used in addbiblio AND additem and serial-edit and maybe could be used in Authorities.
3321 I suggest we export it from this module.
3328 my ( $tagfield, $insubfield, $record, $encoding ) = @_;
3331 if ( $tagfield < 10 ) {
3332 if ( $record->field($tagfield) ) {
3333 push @result, $record->field($tagfield)->data();
3340 foreach my $field ( $record->field($tagfield) ) {
3341 my @subfields = $field->subfields();
3342 foreach my $subfield (@subfields) {
3343 if ( @$subfield[0] eq $insubfield ) {
3344 push @result, @$subfield[1];
3345 $indicator = $field->indicator(1) . $field->indicator(2);
3350 return ( $indicator, @result );
3353 =head2 _koha_modify_biblio
3357 $biblionumber = _koha_modify_biblio($dbh,$biblio);
3358 Internal function for updating the biblio table
3364 sub _koha_modify_biblio {
3365 my ( $dbh, $biblio ) = @_;
3366 # FIXME: this code could be made more portable by not hard-coding
3367 # the values that are supposed to be in biblio table
3378 WHERE biblionumber = ?
3380 my $sth = $dbh->prepare($query);
3384 $biblio->{'author'},
3385 $biblio->{'abstract'},
3386 $biblio->{'copyrightdate'},
3387 $biblio->{'seriestitle'},
3388 $biblio->{'serial'},
3389 $biblio->{'unititle'},
3391 $biblio->{'biblionumber'}
3392 ) if $biblio->{'biblionumber'};
3394 warn $sth->err if $sth->err;
3395 warn "BIG ERROR :: No biblionumber for $biblio->{title}" if $biblio->{biblionumber} !~ /\d+/; # if it is not a number
3396 return ( $biblio->{'biblionumber'} );
3399 =head2 _koha_modify_biblioitem
3403 _koha_modify_biblioitem( $dbh, $biblioitem );
3409 sub _koha_modify_biblioitem {
3410 my ( $dbh, $biblioitem ) = @_;
3412 ##Recalculate LC in case it changed --TG
3414 $biblioitem->{'itemtype'} = $dbh->quote( $biblioitem->{'itemtype'} );
3415 $biblioitem->{'url'} = $dbh->quote( $biblioitem->{'url'} );
3416 $biblioitem->{'isbn'} = $dbh->quote( $biblioitem->{'isbn'} );
3417 $biblioitem->{'issn'} = $dbh->quote( $biblioitem->{'issn'} );
3418 $biblioitem->{'publishercode'} =
3419 $dbh->quote( $biblioitem->{'publishercode'} );
3420 $biblioitem->{'publicationyear'} =
3421 $dbh->quote( $biblioitem->{'publicationyear'} );
3422 $biblioitem->{'classification'} =
3423 $dbh->quote( $biblioitem->{'classification'} );
3424 $biblioitem->{'dewey'} = $dbh->quote( $biblioitem->{'dewey'} );
3425 $biblioitem->{'subclass'} = $dbh->quote( $biblioitem->{'subclass'} );
3426 $biblioitem->{'illus'} = $dbh->quote( $biblioitem->{'illus'} );
3427 $biblioitem->{'pages'} = $dbh->quote( $biblioitem->{'pages'} );
3428 $biblioitem->{'volumeddesc'} = $dbh->quote( $biblioitem->{'volumeddesc'} );
3429 $biblioitem->{'bnotes'} = $dbh->quote( $biblioitem->{'bnotes'} );
3430 $biblioitem->{'size'} = $dbh->quote( $biblioitem->{'size'} );
3431 $biblioitem->{'place'} = $dbh->quote( $biblioitem->{'place'} );
3432 $biblioitem->{'collectiontitle'} = $dbh->quote( $biblioitem->{'collectiontitle'} );
3433 $biblioitem->{'collectionissn'} = $dbh->quote( $biblioitem->{'collectionissn'} );
3434 $biblioitem->{'collectionvolume'} = $dbh->quote( $biblioitem->{'collectionvolume'} );
3435 $biblioitem->{'editionstatement'} = $dbh->quote( $biblioitem->{'editionstatement'} );
3436 $biblioitem->{'editionresponsibility'} = $dbh->quote( $biblioitem->{'editionresponsibility'} );
3437 $biblioitem->{'ccode'} = $dbh->quote( $biblioitem->{'ccode'} );
3438 $biblioitem->{'biblionumber'} =
3439 $dbh->quote( $biblioitem->{'biblionumber'} );
3441 $query = "UPDATE biblioitems SET
3442 itemtype = $biblioitem->{'itemtype'},
3443 url = $biblioitem->{'url'},
3444 isbn = $biblioitem->{'isbn'},
3445 issn = $biblioitem->{'issn'},
3446 publishercode = $biblioitem->{'publishercode'},
3447 publicationyear = $biblioitem->{'publicationyear'},
3448 classification = $biblioitem->{'classification'},
3449 dewey = $biblioitem->{'dewey'},
3450 subclass = $biblioitem->{'subclass'},
3451 illus = $biblioitem->{'illus'},
3452 pages = $biblioitem->{'pages'},
3453 volumeddesc = $biblioitem->{'volumeddesc'},
3454 notes = $biblioitem->{'bnotes'},
3455 size = $biblioitem->{'size'},
3456 place = $biblioitem->{'place'},
3457 collectiontitle = $biblioitem->{'collectiontitle'},
3458 collectionissn = $biblioitem->{'collectionissn'},
3459 collectionvolume= $biblioitem->{'collectionvolume'},
3460 editionstatement= $biblioitem->{'editionstatement'},
3461 editionresponsibility= $biblioitem->{'editionresponsibility'},
3462 ccode = $biblioitem->{'ccode'}
3463 where biblionumber = $biblioitem->{'biblionumber'}";
3466 if ( $dbh->errstr ) {
3467 warn "ERROR in _koha_modify_biblioitem $query";
3471 =head2 _koha_add_biblioitem
3475 _koha_add_biblioitem( $dbh, $biblioitem );
3477 Internal function to add a biblioitem
3483 sub _koha_add_biblioitem {
3484 my ( $dbh, $biblioitem ) = @_;
3486 # my $dbh = C4Connect;
3487 my $sth = $dbh->prepare("SELECT max(biblioitemnumber) FROM biblioitems");
3492 $data = $sth->fetchrow_arrayref;
3493 $bibitemnum = $$data[0] + 1;
3497 $sth = $dbh->prepare(
3498 "INSERT INTO biblioitems SET
3499 biblioitemnumber = ?, biblionumber = ?,
3500 volume = ?, number = ?,
3501 classification = ?, itemtype = ?,
3503 issn = ?, dewey = ?,
3504 subclass = ?, publicationyear = ?,
3505 publishercode = ?, volumedate = ?,
3506 volumeddesc = ?, illus = ?,
3507 pages = ?, notes = ?,
3509 marc = ?, lcsort = ?,
3510 place = ?, ccode = ?,
3511 collectiontitle = ?, collectionissn = ?,
3512 collectionvolume = ?, editionstatement= ?,
3513 editionresponsibility= ?
3517 calculatelc( $biblioitem->{'classification'} )
3518 . $biblioitem->{'subclass'};
3520 $bibitemnum, $biblioitem->{'biblionumber'},
3521 $biblioitem->{'volume'}, $biblioitem->{'number'},
3522 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
3523 $biblioitem->{'url'}, $biblioitem->{'isbn'},
3524 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
3525 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
3526 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
3527 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
3528 $biblioitem->{'pages'}, $biblioitem->{'bnotes'},
3529 $biblioitem->{'size'}, $biblioitem->{'lccn'},
3530 $biblioitem->{'marc'}, $biblioitem->{'place'},
3531 $lcsort, $biblioitem->{'ccode'},
3532 $biblioitem->{'collectiontitle'},$biblioitem->{'collectionissn'},
3533 $biblioitem->{'collectionvolume'},$biblioitem->{'editionstatement'},
3534 $biblioitem->{'editionresponsibility'}
3537 return ($bibitemnum);
3540 =head2 _koha_new_items
3544 _koha_new_items( $dbh, $item, $barcode );
3550 sub _koha_new_items {
3551 my ( $dbh, $item, $barcode ) = @_;
3553 # my $dbh = C4Connect;
3554 my $sth = $dbh->prepare("Select max(itemnumber) from items");
3560 $data = $sth->fetchrow_hashref;
3561 $itemnumber = $data->{'max(itemnumber)'} + 1;
3563 ## Now calculate lccalnumber
3564 my ($cutterextra) = itemcalculator(
3566 $item->{'biblioitemnumber'},
3567 $item->{'itemcallnumber'}
3570 # FIXME the "notforloan" field seems to be named "loan" in some places. workaround bugfix.
3571 if ( $item->{'loan'} ) {
3572 $item->{'notforloan'} = $item->{'loan'};
3575 # if dateaccessioned is provided, use it. Otherwise, set to NOW()
3576 if ( $item->{'dateaccessioned'} eq '' || !$item->{'dateaccessioned'} ) {
3578 $sth = $dbh->prepare(
3579 "Insert into items set
3580 itemnumber = ?, biblionumber = ?,
3581 biblioitemnumber = ?, barcode = ?,
3582 booksellerid = ?, dateaccessioned = NOW(),
3583 homebranch = ?, holdingbranch = ?,
3584 price = ?, replacementprice = ?,
3585 replacementpricedate = NOW(), datelastseen = NOW(),
3587 itemlost = ?, wthdrawn = ?,
3588 paidfor = ?, itemnotes = ?,
3589 itemcallnumber =?, notforloan = ?,
3590 location = ?, Cutterextra = ?
3594 $itemnumber, $item->{'biblionumber'},
3595 $item->{'biblioitemnumber'},
3596 $barcode, $item->{'booksellerid'},
3597 $item->{'homebranch'}, $item->{'holdingbranch'},
3598 $item->{'price'}, $item->{'replacementprice'},
3600 $item->{itemlost}, $item->{wthdrawn},
3601 $item->{paidfor}, $item->{'itemnotes'},
3602 $item->{'itemcallnumber'}, $item->{'notforloan'},
3603 $item->{'location'}, $cutterextra
3607 $sth = $dbh->prepare(
3608 "INSERT INTO items SET
3609 itemnumber = ?, biblionumber = ?,
3610 biblioitemnumber = ?, barcode = ?,
3611 booksellerid = ?, dateaccessioned = ?,
3612 homebranch = ?, holdingbranch = ?,
3613 price = ?, replacementprice = ?,
3614 replacementpricedate = NOW(), datelastseen = NOW(),
3616 itemlost = ?, wthdrawn = ?,
3617 paidfor = ?, itemnotes = ?,
3618 itemcallnumber = ?, notforloan = ?,
3624 $itemnumber, $item->{'biblionumber'},
3625 $item->{'biblioitemnumber'},
3626 $barcode, $item->{'booksellerid'},
3627 $item->{'dateaccessioned'}, $item->{'homebranch'},
3628 $item->{'holdingbranch'}, $item->{'price'},
3629 $item->{'replacementprice'},
3630 $item->{stack}, $item->{itemlost},
3631 $item->{wthdrawn}, $item->{paidfor},
3632 $item->{'itemnotes'}, $item->{'itemcallnumber'},
3633 $item->{'notforloan'}, $item->{'location'},
3637 if ( defined $sth->errstr ) {
3638 $error .= $sth->errstr;
3640 return ( $itemnumber, $error );
3643 =head2 _koha_modify_item
3647 _koha_modify_item( $dbh, $item, $op );
3653 sub _koha_modify_item {
3654 my ( $dbh, $item, $op ) = @_;
3655 $item->{'itemnum'} = $item->{'itemnumber'} unless $item->{'itemnum'};
3657 # if all we're doing is setting statuses, just update those and get out
3658 if ( $op eq "setstatus" ) {
3660 "UPDATE items SET itemlost=?,wthdrawn=? WHERE itemnumber=?";
3662 $item->{'itemlost'}, $item->{'wthdrawn'},
3663 $item->{'itemnumber'}
3665 my $sth = $dbh->prepare($query);
3666 $sth->execute(@bind);
3670 ## Now calculate lccalnumber
3672 itemcalculator( $dbh, $item->{'bibitemnum'}, $item->{'itemcallnumber'} );
3674 my $query = "UPDATE items SET
3675 barcode=?,itemnotes=?,itemcallnumber=?,notforloan=?,location=?,stack=?,wthdrawn=?,holdingbranch=?,homebranch=?,cutterextra=?, onloan=?";
3678 $item->{'barcode'}, $item->{'notes'},
3679 $item->{'itemcallnumber'}, $item->{'notforloan'},
3680 $item->{'location'}, $item->{stack},
3681 $item->{wthdrawn}, $item->{holdingbranch},
3682 $item->{homebranch}, $cutterextra,
3685 if ( $item->{'lost'} ne '' ) {
3687 "update items set biblioitemnumber=?,barcode=?,itemnotes=?,homebranch=?,
3688 itemlost=?,wthdrawn=?,itemcallnumber=?,notforloan=?,
3689 location=?,stack=?,wthdrawn=?,holdingbranch=?,cutterextra=?,onloan=?";
3691 $item->{'bibitemnum'}, $item->{'barcode'},
3692 $item->{'notes'}, $item->{'homebranch'},
3693 $item->{'lost'}, $item->{'wthdrawn'},
3694 $item->{'itemcallnumber'}, $item->{'notforloan'},
3695 $item->{'location'}, $item->{stack},
3696 $item->{wthdrawn}, $item->{holdingbranch},
3697 $cutterextra, $item->{onloan}
3699 if ( $item->{homebranch} ) {
3700 $query .= ",homebranch=?";
3701 push @bind, $item->{homebranch};
3703 if ( $item->{holdingbranch} ) {
3704 $query .= ",holdingbranch=?";
3705 push @bind, $item->{holdingbranch};
3708 $query .= " where itemnumber=?";
3709 push @bind, $item->{'itemnum'};
3710 if ( $item->{'replacement'} ne '' ) {
3711 $query =~ s/ where/,replacementprice='$item->{'replacement'}' where/;
3713 my $sth = $dbh->prepare($query);
3714 $sth->execute(@bind);
3718 =head2 _koha_delete_biblio
3722 $error = _koha_delete_biblio($dbh,$biblionumber);
3724 Internal sub for deleting from biblio table -- also saves to deletedbiblio
3726 C<$dbh> - the database handle
3727 C<$biblionumber> - the biblionumber of the biblio to be deleted
3733 # FIXME: add error handling
3735 sub _koha_delete_biblio {
3736 my ( $dbh, $biblionumber ) = @_;
3738 # get all the data for this biblio
3739 my $sth = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber=?");
3740 $sth->execute($biblionumber);
3742 if ( my $data = $sth->fetchrow_hashref ) {
3744 # save the record in deletedbiblio
3745 # find the fields to save
3746 my $query = "INSERT INTO deletedbiblio SET ";
3748 foreach my $temp ( keys %$data ) {
3749 $query .= "$temp = ?,";
3750 push( @bind, $data->{$temp} );
3753 # replace the last , by ",?)"
3755 my $bkup_sth = $dbh->prepare($query);
3756 $bkup_sth->execute(@bind);
3760 my $del_sth = $dbh->prepare("DELETE FROM biblio WHERE biblionumber=?");
3761 $del_sth->execute($biblionumber);
3768 =head2 _koha_delete_biblioitems
3772 $error = _koha_delete_biblioitems($dbh,$biblioitemnumber);
3774 Internal sub for deleting from biblioitems table -- also saves to deletedbiblioitems
3776 C<$dbh> - the database handle
3777 C<$biblionumber> - the biblioitemnumber of the biblioitem to be deleted
3783 # FIXME: add error handling
3785 sub _koha_delete_biblioitems {
3786 my ( $dbh, $biblioitemnumber ) = @_;
3788 # get all the data for this biblioitem
3790 $dbh->prepare("SELECT * FROM biblioitems WHERE biblioitemnumber=?");
3791 $sth->execute($biblioitemnumber);
3793 if ( my $data = $sth->fetchrow_hashref ) {
3795 # save the record in deletedbiblioitems
3796 # find the fields to save
3797 my $query = "INSERT INTO deletedbiblioitems SET ";
3799 foreach my $temp ( keys %$data ) {
3800 $query .= "$temp = ?,";
3801 push( @bind, $data->{$temp} );
3804 # replace the last , by ",?)"
3806 my $bkup_sth = $dbh->prepare($query);
3807 $bkup_sth->execute(@bind);
3810 # delete the biblioitem
3812 $dbh->prepare("DELETE FROM biblioitems WHERE biblioitemnumber=?");
3813 $del_sth->execute($biblioitemnumber);
3820 =head2 _koha_delete_item
3824 _koha_delete_item( $dbh, $itemnum );
3826 Internal function to delete an item record from the koha tables
3832 sub _koha_delete_item {
3833 my ( $dbh, $itemnum ) = @_;
3835 my $sth = $dbh->prepare("select * from items where itemnumber=?");
3836 $sth->execute($itemnum);
3837 my $data = $sth->fetchrow_hashref;
3839 my $query = "Insert into deleteditems set ";
3841 foreach my $temp ( keys %$data ) {
3842 $query .= "$temp = ?,";
3843 push( @bind, $data->{$temp} );
3848 $sth = $dbh->prepare($query);
3849 $sth->execute(@bind);
3851 $sth = $dbh->prepare("Delete from items where itemnumber=?");
3852 $sth->execute($itemnum);
3856 =head1 UNEXPORTED FUNCTIONS
3862 $lc = calculatelc($classification);
3869 my ($classification) = @_;
3870 $classification =~ s/^\s+|\s+$//g;
3875 for ( $i = 0 ; $i < length($classification) ; $i++ ) {
3876 my $c = ( substr( $classification, $i, 1 ) );
3877 if ( $c ge '0' && $c le '9' ) {
3879 $lc2 = substr( $classification, $i );
3883 $lc1 .= substr( $classification, $i, 1 );
3888 my $other = length($lc1);
3895 for ( 1 .. ( 4 - $other ) ) {
3904 ##Find the decimal part of $lc2
3905 my $pos = index( $lc2, "." );
3906 if ( $pos < 0 ) { $pos = length($lc2); }
3907 if ( $pos >= 0 && $pos < 5 ) {
3908 ##Pad lc2 with zeros to create a 5digit decimal needed in marc record to sort as numeric
3910 for ( 1 .. ( 5 - $pos ) ) {
3914 $lc2 = $extras . $lc2;
3915 return ( $lc1 . $lc2 );
3918 =head2 itemcalculator
3922 $cutterextra = itemcalculator( $dbh, $biblioitem, $callnumber );
3928 sub itemcalculator {
3929 my ( $dbh, $biblioitem, $callnumber ) = @_;
3932 "select classification, subclass from biblioitems where biblioitemnumber=?"
3935 $sth->execute($biblioitem);
3936 my ( $classification, $subclass ) = $sth->fetchrow;
3937 my $all = $classification . " " . $subclass;
3938 my $total = length($all);
3939 my $cutterextra = substr( $callnumber, $total - 1 );
3941 return $cutterextra;
3944 =head2 ModBiblioMarc
3946 &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
3948 Add MARC data for a biblio to koha
3950 Function exported, but should NOT be used, unless you really know what you're doing
3956 # pass the MARC::Record to this function, and it will create the records in the marc field
3957 my ( $record, $biblionumber, $frameworkcode ) = @_;
3958 my $dbh = C4::Context->dbh;
3959 my @fields = $record->fields();
3960 if ( !$frameworkcode ) {
3961 $frameworkcode = "";
3964 $dbh->prepare("UPDATE biblio SET frameworkcode=? WHERE biblionumber=?");
3965 $sth->execute( $frameworkcode, $biblionumber );
3967 my $encoding = C4::Context->preference("marcflavour");
3969 # deal with UNIMARC field 100 (encoding) : create it if needed & set encoding to unicode
3970 if ( $encoding eq "UNIMARC" ) {
3972 if ( length($record->subfield( 100, "a" )) == 35 ) {
3973 $string = $record->subfield( 100, "a" );
3974 my $f100 = $record->field(100);
3975 $record->delete_field($f100);
3978 $string = POSIX::strftime( "%Y%m%d", localtime );
3980 $string = sprintf( "%-*s", 35, $string );
3982 substr( $string, 22, 6, "frey50" );
3983 unless ( $record->subfield( 100, "a" ) ) {
3984 $record->insert_grouped_field(
3985 MARC::Field->new( 100, "", "", "a" => $string ) );
3988 ModZebra($biblionumber,"specialUpdate","biblioserver",$record);
3991 "update biblioitems set marc=?,marcxml=? where biblionumber=?");
3992 $sth->execute( $record->as_usmarc(), $record->as_xml_record($encoding),
3995 return $biblionumber;
3998 =head2 AddItemInMarc
4002 $newbiblionumber = AddItemInMarc( $record, $biblionumber, $frameworkcode );
4004 Add an item in a MARC record and save the MARC record
4006 Function exported, but should NOT be used, unless you really know what you're doing
4014 # pass the MARC::Record to this function, and it will create the records in the marc tables
4015 my ( $record, $biblionumber, $frameworkcode ) = @_;
4016 my $newrec = &GetMarcBiblio($biblionumber);
4019 my @fields = $record->fields();
4020 foreach my $field (@fields) {
4021 $newrec->append_fields($field);
4024 # FIXME: should we be making sure the biblionumbers are the same?
4025 my $newbiblionumber =
4026 &ModBiblioMarc( $newrec, $biblionumber, $frameworkcode );
4027 return $newbiblionumber;
4030 =head2 z3950_extended_services
4032 z3950_extended_services($serviceType,$serviceOptions,$record);
4034 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.
4036 C<$serviceType> one of: itemorder,create,drop,commit,update,xmlupdate
4038 C<$serviceOptions> a has of key/value pairs. For instance, if service_type is 'update', $service_options should contain:
4040 action => update action, one of specialUpdate, recordInsert, recordReplace, recordDelete, elementUpdate.
4044 recordidOpaque => Opaque Record ID (user supplied) or recordidNumber => Record ID number (system number).
4045 syntax => the record syntax (transfer syntax)
4046 databaseName = Database from connection object
4048 To set serviceOptions, call set_service_options($serviceType)
4050 C<$record> the record, if one is needed for the service type
4052 A record should be in XML. You can convert it to XML from MARC by running it through marc2xml().
4056 sub z3950_extended_services {
4057 my ( $server, $serviceType, $action, $serviceOptions ) = @_;
4059 # get our connection object
4060 my $Zconn = C4::Context->Zconn( $server, 0, 1 );
4062 # create a new package object
4063 my $Zpackage = $Zconn->package();
4066 $Zpackage->option( action => $action );
4068 if ( $serviceOptions->{'databaseName'} ) {
4069 $Zpackage->option( databaseName => $serviceOptions->{'databaseName'} );
4071 if ( $serviceOptions->{'recordIdNumber'} ) {
4073 recordIdNumber => $serviceOptions->{'recordIdNumber'} );
4075 if ( $serviceOptions->{'recordIdOpaque'} ) {
4077 recordIdOpaque => $serviceOptions->{'recordIdOpaque'} );
4080 # this is an ILL request (Zebra doesn't support it, but Koha could eventually)
4081 #if ($serviceType eq 'itemorder') {
4082 # $Zpackage->option('contact-name' => $serviceOptions->{'contact-name'});
4083 # $Zpackage->option('contact-phone' => $serviceOptions->{'contact-phone'});
4084 # $Zpackage->option('contact-email' => $serviceOptions->{'contact-email'});
4085 # $Zpackage->option('itemorder-item' => $serviceOptions->{'itemorder-item'});
4088 if ( $serviceOptions->{record} ) {
4089 $Zpackage->option( record => $serviceOptions->{record} );
4091 # can be xml or marc
4092 if ( $serviceOptions->{'syntax'} ) {
4093 $Zpackage->option( syntax => $serviceOptions->{'syntax'} );
4097 # send the request, handle any exception encountered
4098 eval { $Zpackage->send($serviceType) };
4099 if ( $@ && $@->isa("ZOOM::Exception") ) {
4100 return "error: " . $@->code() . " " . $@->message() . "\n";
4103 # free up package resources
4104 $Zpackage->destroy();
4107 =head2 set_service_options
4109 my $serviceOptions = set_service_options($serviceType);
4111 C<$serviceType> itemorder,create,drop,commit,update,xmlupdate
4113 Currently, we only support 'create', 'commit', and 'update'. 'drop' support will be added as soon as Zebra supports it.
4117 sub set_service_options {
4118 my ($serviceType) = @_;
4121 # FIXME: This needs to be an OID ... if we ever need 'syntax' this sub will need to change
4122 # $serviceOptions->{ 'syntax' } = ''; #zebra doesn't support syntaxes other than xml
4124 if ( $serviceType eq 'commit' ) {
4128 if ( $serviceType eq 'create' ) {
4132 if ( $serviceType eq 'drop' ) {
4133 die "ERROR: 'drop' not currently supported (by Zebra)";
4135 return $serviceOptions;
4138 =head2 GetItemsCount
4140 $count = &GetItemsCount( $biblionumber);
4141 this function return count of item with $biblionumber
4145 my ( $biblionumber ) = @_;
4146 my $dbh = C4::Context->dbh;
4147 my $query = qq|SELECT count(*)
4149 WHERE biblionumber=?|;
4150 my $sth = $dbh->prepare($query);
4151 $sth->execute($biblionumber);
4152 my $count = $sth->fetchrow;
4157 END { } # module clean-up code here (global destructor)
4165 Koha Developement team <info@koha.org>
4167 Paul POULAIN paul.poulain@free.fr
4169 Joshua Ferraro jmf@liblime.com
4175 # Revision 1.221 2007/07/31 16:01:11 toins
4176 # Some new functions.
4177 # TransformHTMLtoMarc rewrited.
4179 # Revision 1.220 2007/07/20 15:43:16 hdl
4180 # Bug Fixing GetMarcSubjects.
4181 # Links parameters were mixed.
4183 # Revision 1.218 2007/07/19 07:40:08 hdl
4184 # Adding selection by location for inventory
4186 # Revision 1.217 2007/07/03 13:47:44 tipaul
4187 # fixing some display bugs (itemtype not properly returned and a html table bug that makes items appear strangely
4189 # Revision 1.216 2007/07/03 09:40:58 tipaul
4190 # return itemtype description properly
4192 # Revision 1.215 2007/07/03 09:33:05 tipaul
4193 # 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
4195 # Revision 1.214 2007/07/02 09:13:22 tipaul
4196 # 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
4198 # Revision 1.213 2007/06/25 15:01:45 tipaul
4199 # bugfixes on unimarc 100 handling (the field used for encoding)
4201 # Revision 1.212 2007/06/15 13:44:44 tipaul
4202 # some fixes (and only fixes)
4204 # Revision 1.211 2007/06/15 09:40:06 toins
4205 # do not get $3 $4 and $5 on GetMarcSubjects GetMarcAuthors on unimarc flavour.
4207 # Revision 1.210 2007/06/13 13:03:34 toins
4208 # removing warn compilation.
4210 # Revision 1.209 2007/05/23 16:19:40 tipaul
4211 # various bugfixes (minor) and french translation updated
4213 # Revision 1.208 2007/05/22 09:13:54 tipaul
4214 # Bugfixes & improvements (various and minor) :
4215 # - updating templates to have tmpl_process3.pl running without any errors
4216 # - adding a drupal-like css for prog templates (with 3 small images)
4217 # - fixing some bugs in circulation & other scripts
4218 # - updating french translation
4219 # - fixing some typos in templates
4221 # Revision 1.207 2007/05/22 08:51:19 hdl
4222 # Changing GetMarcStructure signature.
4223 # Deleting first parameter $dbh
4225 # Revision 1.206 2007/05/21 08:44:17 btoumi
4226 # add security when u delete biblio :
4227 # u must delete linked items before delete biblio
4229 # Revision 1.205 2007/05/11 16:04:03 btoumi
4231 # problem in displayed label link with subject in detail.tmpl
4232 # ex: label random => rdom
4234 # Revision 1.204 2007/05/10 14:45:15 tipaul
4236 # - support for authorities
4237 # - some bugfixes in ordering and "CCL" parsing
4238 # - support for authorities <=> biblios walking
4240 # Seems I can do what I want now, so I consider its done, except for bugfixes that will be needed i m sure !
4242 # Revision 1.203 2007/05/03 15:16:02 tipaul
4243 # BUGFIX for : NoZebra
4244 # - NoZebra features : seems they work fine now (adding, modifying, deleting)
4245 # - Biblio edition major bugfix : before this commit editing a biblio resulted in an item removal in marcxml field
4247 # Revision 1.202 2007/05/02 16:44:31 tipaul
4248 # NoZebra SQL index management :
4249 # * adding 3 subs in Biblio.pm
4250 # - GetNoZebraIndexes, that get the index structure in a new systempreference (added with this commit)
4251 # - _DelBiblioNoZebra, that retrieve all index entries for a biblio and remove in a variable the biblio reference
4252 # - _AddBiblioNoZebra, that add index entries for a biblio.
4253 # 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).
4254 # I think the code has to be more deeply tested, but it works at least partially.
4256 # Revision 1.201 2007/04/27 14:00:49 hdl
4257 # Removing $dbh from GetMarcFromKohaField (dbh is not used in this function.)
4259 # Revision 1.200 2007/04/25 16:26:42 tipaul
4260 # 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 :
4261 # - add nozebra table management on biblio editing
4262 # - the index table content is hardcoded. I still have to add some specific systempref to let the library update it
4263 # - manage pagination (next/previous)
4266 # - NZgetRecords : has exactly the same API & returns as zebra getQuery, except that some parameters are unused
4267 # - search & sort works quite good
4268 # - CQL parser is better that what I thought I could do : title="harry and sally" and publicationyear>2000 not itemtype=LIVR should work fine
4270 # Revision 1.199 2007/04/24 09:07:53 tipaul
4271 # moving dotransfer to Biblio.pm::ModItemTransfer + some CheckReserves fixes
4273 # Revision 1.198 2007/04/23 15:21:17 tipaul
4274 # renaming currenttransfers to transferstoreceive
4276 # Revision 1.197 2007/04/18 17:00:14 tipaul
4277 # removing all useless %env / $env
4279 # Revision 1.196 2007/04/17 08:48:00 tipaul
4280 # circulation cleaning continued: bufixing
4282 # Revision 1.195 2007/04/04 16:46:22 tipaul
4283 # HUGE COMMIT : code cleaning circulation.
4285 # some stuff to do, i'll write a mail on koha-devel NOW !
4287 # Revision 1.194 2007/03/30 12:00:42 tipaul
4288 # 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...
4290 # Revision 1.193 2007/03/29 16:45:53 tipaul
4291 # Code cleaning of Biblio.pm (continued)
4293 # All subs have be cleaned :
4296 # - reordering Biblio.pm completly
4297 # - using only naming conventions
4299 # Seems to have broken nothing, but it still has to be heavily tested.
4300 # Note that Biblio.pm is now much more efficient than previously & probably more reliable as well.
4302 # Revision 1.192 2007/03/29 13:30:31 tipaul
4304 # == Biblio.pm cleaning (useless) ==
4305 # * some sub declaration dropped
4306 # * removed modbiblio sub
4307 # * removed moditem sub
4308 # * removed newitems. It was used only in finishrecieve. Replaced by a TransformKohaToMarc+AddItem, that is better.
4309 # * removed MARCkoha2marcItem
4310 # * removed MARCdelsubfield declaration
4311 # * removed MARCkoha2marcBiblio
4313 # == Biblio.pm cleaning (naming conventions) ==
4314 # * MARCgettagslib renamed to GetMarcStructure
4315 # * MARCgetitems renamed to GetMarcItem
4316 # * MARCfind_frameworkcode renamed to GetFrameworkCode
4317 # * MARCmarc2koha renamed to TransformMarcToKoha
4318 # * MARChtml2marc renamed to TransformHtmlToMarc
4319 # * MARChtml2xml renamed to TranformeHtmlToXml
4320 # * zebraop renamed to ModZebra
4323 # * removing MARC=OFF related scripts (in cataloguing directory)
4324 # * removed checkitems (function related to MARC=off feature, that is completly broken in head. If someone want to reintroduce it, hard work coming...)
4325 # * removed getitemsbybiblioitem (used only by MARC=OFF scripts, that is removed as well)
4327 # Revision 1.191 2007/03/29 09:42:13 tipaul
4328 # adding default value new feature into cataloguing. The system (definition) part has already been added by toins
4330 # Revision 1.190 2007/03/29 08:45:19 hdl
4331 # Deleting ignore_errors(1) pour MARC::Charset
4333 # Revision 1.189 2007/03/28 10:39:16 hdl
4334 # removing $dbh as a parameter in AuthoritiesMarc functions
4335 # And reporting all differences into the scripts taht relies on those functions.