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 vars qw($VERSION @ISA @EXPORT);
28 # set the version for version checking
34 # don't forget MARCxxx subs are exported only for testing purposes. Should not be used
35 # as the old-style API and the NEW one are the only public functions.
38 &updateBiblio &updateBiblioItem &updateItem
39 &itemcount &newbiblio &newbiblioitem
40 &modnote &newsubject &newsubtitle
41 &modbiblio &checkitems
43 &modsubtitle &modsubject &modaddauthor &moditem &countitems
44 &delitem &deletebiblioitem &delbiblio
46 &getbiblioitembybiblionumber
47 &getbiblioitem &getitemsbybiblioitem
49 &newcompletebiblioitem
51 &MARCfind_oldbiblionumber_from_MARCbibid
52 &MARCfind_MARCbibid_from_oldbiblionumber
53 &MARCfind_marc_from_kohafield
55 &MARCfind_frameworkcode
58 &NEWnewbiblio &NEWnewitem
59 &NEWmodbiblio &NEWmoditem
60 &NEWdelbiblio &NEWdelitem
62 &MARCaddbiblio &MARCadditem
63 &MARCmodsubfield &MARCaddsubfield
64 &MARCmodbiblio &MARCmoditem
65 &MARCkoha2marcBiblio &MARCmarc2koha
66 &MARCkoha2marcItem &MARChtml2marc
67 &MARCgetbiblio &MARCgetitem
68 &MARCaddword &MARCdelword
76 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
79 # all the following subs takes a MARC::Record as parameter and manage
80 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
81 # NEWxxx subs (xxx deals with old-DB parameters, the NEWxxx deals with MARC-DB parameter)
85 C4::Biblio - acquisition, catalog management functions
89 move from 1.2 to 1.4 version :
90 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
91 In the 1.4 version, we want to do 2 differents things :
92 - keep populating the old-DB, that has a LOT less datas than MARC
93 - populate the MARC-DB
94 To populate the DBs we have 2 differents sources :
95 - the standard acquisition system (through book sellers), that does'nt use MARC data
96 - the MARC acquisition system, that uses MARC data.
98 Thus, we have 2 differents cases :
99 - with the standard acquisition system, we have non MARC data and want to populate old-DB and MARC-DB, knowing it's an incomplete MARC-record
100 - with the MARC acquisition system, we have MARC datas, and want to loose nothing in MARC-DB. So, we can't store datas in old-DB, then copy in MARC-DB. we MUST have an API for true MARC data, that populate MARC-DB then old-DB
102 That's why we need 4 subs :
103 all I<subs beginning by MARC> manage only MARC tables. They manage MARC-DB with MARC::Record parameters
104 all I<subs beginning by OLD> manage only OLD-DB tables. They manage old-DB with old-DB parameters
105 all I<subs beginning by NEW> manage both OLD-DB and MARC tables. They use MARC::Record as parameters. it's the API that MUST be used in MARC acquisition system
106 all I<subs beginning by seomething else> are the old-style API. They use old-DB as parameter, then call internally the OLD and MARC subs.
108 - NEW and old-style API should be used in koha to manage biblio
109 - MARCsubs are divided in 2 parts :
110 * some of them manage MARC parameters. They are heavily used in koha.
111 * some of them manage MARC biblio : they are mostly used by NEW and old-style subs.
112 - OLD are used internally only
114 all subs requires/use $dbh as 1st parameter.
116 I<NEWxxx related subs>
118 all subs requires/use $dbh as 1st parameter.
119 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
121 I<OLDxxx related subs>
123 all subs requires/use $dbh as 1st parameter.
124 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
126 They all are the exact copy of 1.0/1.2 version of the sub without the OLD.
127 The OLDxxx is called by the original xxx sub.
128 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
130 WARNING : there is 1 difference between initialxxx and OLDxxx :
131 the db header $dbh is always passed as parameter to avoid over-DB connexion
137 =item @tagslib = &MARCgettagslib($dbh,1|0,$itemtype);
139 last param is 1 for liblibrarian and 0 for libopac
140 $itemtype contains the itemtype framework reference. If empty or does not exist, the default one is used
141 returns a hash with tag/subfield meaning
142 =item ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,$kohafield);
144 finds MARC tag and subfield for a given kohafield
145 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
147 =item $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
149 finds a old-db biblio number for a given MARCbibid number
151 =item $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
153 finds a MARC bibid from a old-db biblionumber
155 =item $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
157 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
159 =item $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
161 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
163 =item $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
165 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
167 =item $olddb = &MARCmarc2koha($dbh,$MARCRecord);
169 builds a hash with old-db datas from a MARC::Record
171 =item &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
173 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
175 =item &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
177 adds a subfield in a biblio (in the MARC tables only).
179 =item $MARCRecord = &MARCgetbiblio($dbh,$bibid);
181 Returns a MARC::Record for the biblio $bibid.
183 =item &MARCmodbiblio($dbh,$bibid,$record,$frameworkcode,$delete);
185 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
186 It 1st delete the biblio, then recreates it.
187 WARNING : the $delete parameter is not used anymore (too much unsolvable cases).
188 =item ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
190 MARCmodsubfield changes the value of a given subfield
192 =item $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
194 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
195 Returns -1 if more than 1 answer
197 =item $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
199 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
201 =item &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
203 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
205 =item &MARCdelbiblio($dbh,$bibid);
207 MARCdelbiblio delete biblio $bibid
209 =item &MARCkoha2marcOnefield
211 used by MARCkoha2marc and should not be useful elsewhere
213 =item &MARCmarc2kohaOnefield
215 used by MARCmarc2koha and should not be useful elsewhere
219 used to manage MARC_word table and should not be useful elsewhere
223 used to manage MARC_word table and should not be useful elsewhere
228 my ( $dbh, $forlibrarian, $frameworkcode ) = @_;
229 $frameworkcode = "" unless $frameworkcode;
231 my $libfield = ( $forlibrarian eq 1 ) ? 'liblibrarian' : 'libopac';
233 # check that framework exists
236 "select count(*) from marc_tag_structure where frameworkcode=?");
237 $sth->execute($frameworkcode);
238 my ($total) = $sth->fetchrow;
239 $frameworkcode = "" unless ( $total > 0 );
242 "select tagfield,$libfield as lib,mandatory,repeatable from marc_tag_structure where frameworkcode=? order by tagfield"
244 $sth->execute($frameworkcode);
245 my ( $lib, $tag, $res, $tab, $mandatory, $repeatable );
247 while ( ( $tag, $lib, $mandatory, $repeatable ) = $sth->fetchrow ) {
248 $res->{$tag}->{lib} = $lib;
249 $res->{$tab}->{tab} = ""; # XXX
250 $res->{$tag}->{mandatory} = $mandatory;
251 $res->{$tag}->{repeatable} = $repeatable;
256 "select tagfield,tagsubfield,$libfield as lib,tab, mandatory, repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link from marc_subfield_structure where frameworkcode=? order by tagfield,tagsubfield"
258 $sth->execute($frameworkcode);
261 my $authorised_value;
271 ( $tag, $subfield, $lib, $tab,
272 $mandatory, $repeatable, $authorised_value, $authtypecode,
273 $value_builder, $kohafield, $seealso, $hidden,
278 $res->{$tag}->{$subfield}->{lib} = $lib;
279 $res->{$tag}->{$subfield}->{tab} = $tab;
280 $res->{$tag}->{$subfield}->{mandatory} = $mandatory;
281 $res->{$tag}->{$subfield}->{repeatable} = $repeatable;
282 $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
283 $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode;
284 $res->{$tag}->{$subfield}->{value_builder} = $value_builder;
285 $res->{$tag}->{$subfield}->{kohafield} = $kohafield;
286 $res->{$tag}->{$subfield}->{seealso} = $seealso;
287 $res->{$tag}->{$subfield}->{hidden} = $hidden;
288 $res->{$tag}->{$subfield}->{isurl} = $isurl;
289 $res->{$tag}->{$subfield}->{link} = $link;
294 sub MARCfind_marc_from_kohafield {
295 my ( $dbh, $kohafield,$frameworkcode ) = @_;
296 return 0, 0 unless $kohafield;
297 my $relations = C4::Context->marcfromkohafield;
298 return ($relations->{$frameworkcode}->{$kohafield}->[0],$relations->{$frameworkcode}->{$kohafield}->[1]);
301 # "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
303 # $sth->execute($frameworkcode,$kohafield);
304 # my ( $tagfield, $tagsubfield ) = $sth->fetchrow;
305 # return ( $tagfield, $tagsubfield );
308 sub MARCfind_oldbiblionumber_from_MARCbibid {
309 my ( $dbh, $MARCbibid ) = @_;
311 $dbh->prepare("select biblionumber from marc_biblio where bibid=?");
312 $sth->execute($MARCbibid);
313 my ($biblionumber) = $sth->fetchrow;
314 return $biblionumber;
317 sub MARCfind_MARCbibid_from_oldbiblionumber {
318 my ( $dbh, $oldbiblionumber ) = @_;
320 $dbh->prepare("select bibid from marc_biblio where biblionumber=?");
321 $sth->execute($oldbiblionumber);
322 my ($bibid) = $sth->fetchrow;
328 # pass the MARC::Record to this function, and it will create the records in the marc tables
329 my ($dbh,$record,$biblionumber,$frameworkcode,$bibid) = @_;
330 my @fields=$record->fields();
332 # adding main table, and retrieving bibid
333 # if bibid is sent, then it's not a true add, it's only a re-add, after a delete (ie, a mod)
334 # if bibid empty => true add, find a new bibid number
337 "lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ"
341 "insert into marc_biblio (datecreated,biblionumber,frameworkcode) values (now(),?,?)"
343 $sth->execute( $biblionumber, $frameworkcode );
344 $sth = $dbh->prepare("select max(bibid) from marc_biblio");
346 ($bibid) = $sth->fetchrow;
351 # now, add subfields...
352 foreach my $field (@fields) {
354 if ( $field->tag() < 10 ) {
355 &MARCaddsubfield( $dbh, $bibid, $field->tag(), '', $fieldcount, '',
359 my @subfields = $field->subfields();
360 foreach my $subfieldcount ( 0 .. $#subfields ) {
365 $field->indicator(1) . $field->indicator(2),
367 $subfields[$subfieldcount][0],
369 $subfields[$subfieldcount][1]
374 $dbh->do("unlock tables");
380 # pass the MARC::Record to this function, and it will create the records in the marc tables
381 my ($dbh,$record,$biblionumber) = @_;
382 # search for MARC biblionumber
383 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
384 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
385 my @fields=$record->fields();
386 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
387 $sth->execute($bibid);
388 my ($fieldcount) = $sth->fetchrow;
390 # now, add subfields...
391 foreach my $field (@fields) {
392 my @subfields = $field->subfields();
394 foreach my $subfieldcount ( 0 .. $#subfields ) {
399 $field->indicator(1) . $field->indicator(2),
401 $subfields[$subfieldcount][0],
403 $subfields[$subfieldcount][1]
407 $dbh->do("unlock tables");
411 sub MARCaddsubfield {
413 # Add a new subfield to a tag into the DB.
415 $dbh, $bibid, $tagid, $tag_indicator,
416 $tagorder, $subfieldcode, $subfieldorder, $subfieldvalues
419 # warn "$tagid / $subfieldcode / $subfieldvalues";
420 # if not value, end of job, we do nothing
421 # if ( length($subfieldvalues) == 0 ) {
424 if ( not($subfieldcode) ) {
427 my @subfieldvalues = split /\||#/, $subfieldvalues;
428 foreach my $subfieldvalue (@subfieldvalues) {
429 if ( length($subfieldvalue) > 255 ) {
431 "lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE"
435 "insert into marc_blob_subfield (subfieldvalue) values (?)");
436 $sth->execute($subfieldvalue);
438 $dbh->prepare("select max(blobidlink)from marc_blob_subfield");
440 my ($res) = $sth->fetchrow;
443 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?,?)"
445 $sth->execute( $bibid, ( sprintf "%03s", $tagid ), $tagorder,
446 $tag_indicator, $subfieldcode, $subfieldorder, $res );
448 if ( $sth->errstr ) {
450 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
452 $dbh->do("unlock tables");
457 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)"
460 $bibid, ( sprintf "%03s", $tagid ),
461 $tagorder, $tag_indicator,
462 $subfieldcode, $subfieldorder,
465 if ( $sth->errstr ) {
467 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
471 $dbh, $bibid, $tagid, $tagorder,
472 $subfieldcode, $subfieldorder, $subfieldvalue
479 # Returns MARC::Record of the biblio passed in parameter.
480 my ( $dbh, $bibid ) = @_;
481 my $record = MARC::Record->new();
483 #---- TODO : the leader is missing
484 $record->leader(' ');
487 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
488 from marc_subfield_table
489 where bibid=? order by tag,tagorder,subfieldcode
494 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
495 $sth->execute($bibid);
496 my $prevtagorder = 1;
499 my $field; # for >=10 tags
500 my $prevvalue; # for <10 tags
501 while ( my $row = $sth->fetchrow_hashref ) {
503 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
504 $sth2->execute( $row->{'valuebloblink'} );
505 my $row2 = $sth2->fetchrow_hashref;
507 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
509 if ( $row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag ) {
510 $previndicator .= " ";
511 if ( $prevtag < 10 ) {
512 $record->add_fields( ( sprintf "%03s", $prevtag ), $prevvalue )
513 unless $prevtag eq "XXX"; # ignore the 1st loop
516 $record->add_fields($field) unless $prevtag eq "XXX";
519 $prevtagorder = $row->{tagorder};
520 $prevtag = $row->{tag};
521 $previndicator = $row->{tag_indicator};
522 if ( $row->{tag} < 10 ) {
523 $prevvalue = $row->{subfieldvalue};
526 $field = MARC::Field->new(
527 ( sprintf "%03s", $prevtag ),
528 substr( $row->{tag_indicator} . ' ', 0, 1 ),
529 substr( $row->{tag_indicator} . ' ', 1, 1 ),
530 $row->{'subfieldcode'},
531 $row->{'subfieldvalue'}
536 if ( $row->{tag} < 10 ) {
537 $record->add_fields( ( sprintf "%03s", $row->{tag} ),
538 $row->{'subfieldvalue'} );
541 $field->add_subfields( $row->{'subfieldcode'},
542 $row->{'subfieldvalue'} );
544 $prevtag = $row->{tag};
545 $previndicator = $row->{tag_indicator};
549 # the last has not been included inside the loop... do it now !
550 if ( $prevtag ne "XXX" )
551 { # check that we have found something. Otherwise, prevtag is still XXX and we
552 # must return an empty record, not make MARC::Record fail because we try to
553 # create a record with XXX as field :-(
554 if ( $prevtag < 10 ) {
555 $record->add_fields( $prevtag, $prevvalue );
559 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
560 $record->add_fields($field);
568 # Returns MARC::Record of the biblio passed in parameter.
569 my ( $dbh, $bibid, $itemnumber ) = @_;
570 my $record = MARC::Record->new();
572 # search MARC tagorder
575 "select tagorder from marc_subfield_table,marc_subfield_structure where marc_subfield_table.tag=marc_subfield_structure.tagfield and marc_subfield_table.subfieldcode=marc_subfield_structure.tagsubfield and bibid=? and kohafield='items.itemnumber' and subfieldvalue=?"
577 $sth2->execute( $bibid, $itemnumber );
578 my ($tagorder) = $sth2->fetchrow_array();
580 #---- TODO : the leader is missing
583 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
584 from marc_subfield_table
585 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
590 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
591 $sth->execute( $bibid, $tagorder );
592 while ( my $row = $sth->fetchrow_hashref ) {
593 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
594 $sth2->execute( $row->{'valuebloblink'} );
595 my $row2 = $sth2->fetchrow_hashref;
597 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
599 if ( $record->field( $row->{'tag'} ) ) {
602 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
603 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
604 if ( length( $row->{'tag'} ) < 3 ) {
605 $row->{'tag'} = "0" . $row->{'tag'};
607 $field = $record->field( $row->{'tag'} );
610 $field->add_subfields( $row->{'subfieldcode'},
611 $row->{'subfieldvalue'} );
612 $record->delete_field($field);
613 $record->add_fields($field);
617 if ( length( $row->{'tag'} ) < 3 ) {
618 $row->{'tag'} = "0" . $row->{'tag'};
621 MARC::Field->new( $row->{'tag'}, " ", " ",
622 $row->{'subfieldcode'} => $row->{'subfieldvalue'} );
623 $record->add_fields($temp);
631 my ($dbh,$bibid,$record,$frameworkcode,$delete)=@_;
632 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
633 if ($oldrecord eq $record) {
636 # 1st delete the biblio,
638 my $biblionumber = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
639 &MARCdelbiblio($dbh,$bibid,1);
640 &MARCaddbiblio($dbh,$record,$biblionumber,$frameworkcode,$bibid);
644 my ( $dbh, $bibid, $keep_items ) = @_;
646 # if the keep_item is set to 1, then all items are preserved.
647 # This flag is set when the delbiblio is called by modbiblio
648 # due to a too complex structure of MARC (repeatable fields and subfields),
649 # the best solution for a modif is to delete / recreate the record.
651 # 1st of all, copy the MARC::Record to deletedbiblio table => if a true deletion, MARC data will be kept.
652 # if deletion called before MARCmodbiblio => won't do anything, as the oldbiblionumber doesn't
653 # exist in deletedbiblio table
654 my $record = MARCgetbiblio( $dbh, $bibid );
655 my $oldbiblionumber =
656 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
658 $dbh->prepare("update deletedbiblio set marc=? where biblionumber=?");
659 $copy2deleted->execute( $record->as_usmarc(), $oldbiblionumber );
661 # now, delete in MARC tables.
662 if ( $keep_items eq 1 ) {
664 #search item field code
667 "select tagfield from marc_subfield_structure where kohafield like 'items.%'"
670 my $itemtag = $sth->fetchrow_hashref->{tagfield};
672 "delete from marc_subfield_table where bibid=$bibid and tag<>$itemtag"
675 "delete from marc_word where bibid=$bibid and not (tagsubfield like \"$itemtag%\")"
679 $dbh->do("delete from marc_biblio where bibid=$bibid");
680 $dbh->do("delete from marc_subfield_table where bibid=$bibid");
681 $dbh->do("delete from marc_word where bibid=$bibid");
687 # delete the item passed in parameter in MARC tables.
688 my ( $dbh, $bibid, $itemnumber ) = @_;
690 # my $record = MARC::Record->new();
691 # search MARC tagorder
692 my $record = MARCgetitem( $dbh, $bibid, $itemnumber );
694 $dbh->prepare("update deleteditems set marc=? where itemnumber=?");
695 $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
699 "select tagorder from marc_subfield_table,marc_subfield_structure where marc_subfield_table.tag=marc_subfield_structure.tagfield and marc_subfield_table.subfieldcode=marc_subfield_structure.tagsubfield and bibid=? and kohafield='items.itemnumber' and subfieldvalue=?"
701 $sth2->execute( $bibid, $itemnumber );
702 my ($tagorder) = $sth2->fetchrow_array();
705 "delete from marc_subfield_table where bibid=? and tagorder=?");
706 $sth->execute( $bibid, $tagorder );
710 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
712 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
713 # if nothing to change, don't waste time...
714 if ($oldrecord eq $record) {
717 # otherwise, skip through each subfield...
718 my @fields = $record->fields();
719 # search old MARC item
720 my $sth2 = $dbh->prepare("select tagorder from marc_subfield_table,marc_subfield_structure where marc_subfield_table.tag=marc_subfield_structure.tagfield and marc_subfield_table.subfieldcode=marc_subfield_structure.tagsubfield and bibid=? and kohafield='items.itemnumber' and subfieldvalue=?");
721 $sth2->execute($bibid,$itemnumber);
722 my ($tagorder) = $sth2->fetchrow_array();
723 foreach my $field (@fields) {
724 my $oldfield = $oldrecord->field($field->tag());
725 my @subfields=$field->subfields();
727 foreach my $subfield (@subfields) {
729 if ($oldfield eq 0 or (length($oldfield->subfield(@$subfield[0])) ==0) ) {
730 # just adding datas...
731 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
732 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
734 # modify he subfield if it's a different string
735 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
736 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
737 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
744 sub MARCmodsubfield {
746 # Subroutine changes a subfield value given a subfieldid.
747 my ( $dbh, $subfieldid, $subfieldvalue ) = @_;
748 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
751 "select valuebloblink from marc_subfield_table where subfieldid=?");
752 $sth1->execute($subfieldid);
753 my ($oldvaluebloblink) = $sth1->fetchrow;
757 # if too long, use a bloblink
758 if ( length($subfieldvalue) > 255 ) {
760 # if already a bloblink, update it, otherwise, insert a new one.
761 if ($oldvaluebloblink) {
764 "update marc_blob_subfield set subfieldvalue=? where blobidlink=?"
766 $sth->execute( $subfieldvalue, $oldvaluebloblink );
771 "insert into marc_blob_subfield (subfieldvalue) values (?)");
772 $sth->execute($subfieldvalue);
774 $dbh->prepare("select max(blobidlink) from marc_blob_subfield");
776 my ($res) = $sth->fetchrow;
779 "update marc_subfield_table set subfieldvalue=null, valuebloblink=? where subfieldid=?"
781 $sth->execute( $res, $subfieldid );
786 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
789 "update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?"
791 $sth->execute( $subfieldvalue, $subfieldid );
793 $dbh->do("unlock tables");
797 "select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?"
799 $sth->execute($subfieldid);
800 my ( $bibid, $tagid, $tagorder, $subfieldcode, $x, $subfieldorder ) =
803 &MARCdelword( $dbh, $bibid, $tagid, $tagorder, $subfieldcode,
806 $dbh, $bibid, $tagid, $tagorder,
807 $subfieldcode, $subfieldorder, $subfieldvalue
809 return ( $subfieldid, $subfieldvalue );
812 sub MARCfindsubfield {
813 my ( $dbh, $bibid, $tag, $subfieldcode, $subfieldorder, $subfieldvalue ) =
815 my $resultcounter = 0;
819 "select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
820 my @bind_values = ( $bibid, $tag, $subfieldcode );
821 if ($subfieldvalue) {
822 $query .= " and subfieldvalue=?";
823 push ( @bind_values, $subfieldvalue );
826 if ( $subfieldorder < 1 ) {
829 $query .= " and subfieldorder=?";
830 push ( @bind_values, $subfieldorder );
832 my $sti = $dbh->prepare($query);
833 $sti->execute(@bind_values);
834 while ( ($subfieldid) = $sti->fetchrow ) {
836 $lastsubfieldid = $subfieldid;
838 if ( $resultcounter > 1 ) {
840 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
841 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
845 return $lastsubfieldid;
849 sub MARCfindsubfieldid {
850 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
851 my $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
852 where bibid=? and tag=? and tagorder=?
853 and subfieldcode=? and subfieldorder=?"
855 $sth->execute( $bibid, $tag, $tagorder, $subfield, $subfieldorder );
856 my ($res) = $sth->fetchrow;
858 $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
859 where bibid=? and tag=? and tagorder=?
862 $sth->execute( $bibid, $tag, $tagorder, $subfield );
863 ($res) = $sth->fetchrow;
868 sub MARCfind_frameworkcode {
869 my ( $dbh, $bibid ) = @_;
871 $dbh->prepare("select frameworkcode from marc_biblio where bibid=?");
872 $sth->execute($bibid);
873 my ($frameworkcode) = $sth->fetchrow;
874 return $frameworkcode;
877 sub MARCdelsubfield {
879 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
880 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
881 $dbh->do( "delete from marc_subfield_table where bibid='$bibid' and
882 tag='$tag' and tagorder='$tagorder'
883 and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
888 sub MARCkoha2marcBiblio {
890 # this function builds partial MARC::Record from the old koha-DB fields
891 my ( $dbh, $biblionumber, $biblioitemnumber ) = @_;
894 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
896 my $record = MARC::Record->new();
898 #--- if bibid, then retrieve old-style koha data
899 if ( $biblionumber > 0 ) {
902 "select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
903 from biblio where biblionumber=?"
905 $sth2->execute($biblionumber);
906 my $row = $sth2->fetchrow_hashref;
908 foreach $code ( keys %$row ) {
909 if ( $row->{$code} ) {
910 &MARCkoha2marcOnefield( $sth, $record, "biblio." . $code,
916 #--- if biblioitem, then retrieve old-style koha data
917 if ( $biblioitemnumber > 0 ) {
920 " SELECT biblioitemnumber,biblionumber,volume,number,classification,
921 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
922 volumedate,volumeddesc,timestamp,illus,pages,notes AS bnotes,size,place
924 WHERE biblioitemnumber=?
927 $sth2->execute($biblioitemnumber);
928 my $row = $sth2->fetchrow_hashref;
930 foreach $code ( keys %$row ) {
931 if ( $row->{$code} ) {
932 &MARCkoha2marcOnefield( $sth, $record, "biblioitems." . $code,
938 # other fields => additional authors, subjects, subtitles
941 " SELECT author FROM additionalauthors WHERE biblionumber=?");
942 $sth2->execute($biblionumber);
943 while ( my $row = $sth2->fetchrow_hashref ) {
944 &MARCkoha2marcOnefield( $sth, $record, "additionalauthors.author",
945 $row->{'author'},'' );
948 $dbh->prepare(" SELECT subject FROM bibliosubject WHERE biblionumber=?");
949 $sth2->execute($biblionumber);
950 while ( my $row = $sth2->fetchrow_hashref ) {
951 &MARCkoha2marcOnefield( $sth, $record, "bibliosubject.subject",
952 $row->{'subject'},'' );
956 " SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?");
957 $sth2->execute($biblionumber);
958 while ( my $row = $sth2->fetchrow_hashref ) {
959 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.title",
960 $row->{'subtitle'},'' );
965 sub MARCkoha2marcItem {
967 # this function builds partial MARC::Record from the old koha-DB fields
968 my ( $dbh, $biblionumber, $itemnumber ) = @_;
970 # my $dbh=&C4Connect;
973 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
975 my $record = MARC::Record->new();
977 #--- if item, then retrieve old-style koha data
978 if ( $itemnumber > 0 ) {
980 # print STDERR "prepare $biblionumber,$itemnumber\n";
983 "SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
984 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
985 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,itemcallnumber,issues,renewals,
986 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
990 $sth2->execute($itemnumber);
991 my $row = $sth2->fetchrow_hashref;
993 foreach $code ( keys %$row ) {
994 if ( $row->{$code} ) {
995 &MARCkoha2marcOnefield( $sth, $record, "items." . $code,
1003 sub MARCkoha2marcSubtitle {
1005 # this function builds partial MARC::Record from the old koha-DB fields
1006 my ( $dbh, $bibnum, $subtitle ) = @_;
1009 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
1011 my $record = MARC::Record->new();
1012 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle",
1017 sub MARCkoha2marcOnefield {
1018 my ( $sth, $record, $kohafieldname, $value,$frameworkcode ) = @_;
1021 $sth->execute($frameworkcode,$kohafieldname);
1022 if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
1023 if ( $record->field($tagfield) ) {
1024 my $tag = $record->field($tagfield);
1026 $tag->add_subfields( $tagsubfield, $value );
1027 $record->delete_field($tag);
1028 $record->add_fields($tag);
1032 $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
1039 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
1041 my $record = MARC::Record->new();
1042 # my %subfieldlist=();
1043 my $prevvalue; # if tag <10
1044 my $field; # if tag >=10
1045 for (my $i=0; $i< @$rtags; $i++) {
1046 # rebuild MARC::Record
1047 # warn "0=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ";
1048 if (@$rtags[$i] ne $prevtag) {
1049 if ($prevtag < 10) {
1051 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
1055 $record->add_fields($field);
1058 $indicators{@$rtags[$i]}.=' ';
1059 if (@$rtags[$i] <10) {
1060 $prevvalue= @$rvalues[$i];
1062 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
1063 # warn "1=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
1065 $prevtag = @$rtags[$i];
1067 if (@$rtags[$i] <10) {
1068 $prevvalue=@$rvalues[$i];
1070 if (length(@$rvalues[$i])>0) {
1071 $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
1072 # warn "2=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
1075 $prevtag= @$rtags[$i];
1078 # the last has not been included inside the loop... do it now !
1079 $record->add_fields($field);
1080 # warn "HTML2MARC=".$record->as_formatted;
1085 my ($dbh,$record,$frameworkcode) = @_;
1086 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?");
1088 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
1091 while (($field)=$sth2->fetchrow) {
1092 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result,$frameworkcode);
1094 $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
1096 while (($field)=$sth2->fetchrow) {
1097 if ($field eq 'notes') { $field = 'bnotes'; }
1098 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result,$frameworkcode);
1100 $sth2=$dbh->prepare("SHOW COLUMNS from items");
1102 while (($field)=$sth2->fetchrow) {
1103 $result=&MARCmarc2kohaOneField($sth,"items",$field,$record,$result,$frameworkcode);
1105 # additional authors : specific
1106 $result = &MARCmarc2kohaOneField($sth,"bibliosubtitle","subtitle",$record,$result,$frameworkcode);
1107 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result,$frameworkcode);
1108 # modify copyrightdate to keep only the 1st year found
1109 my $temp = $result->{'copyrightdate'};
1110 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1112 $result->{'copyrightdate'} = $1;
1113 } else { # if no cYYYY, get the 1st date.
1114 $temp =~ m/(\d\d\d\d)/;
1115 $result->{'copyrightdate'} = $1;
1117 # modify publicationyear to keep only the 1st year found
1118 my $temp = $result->{'publicationyear'};
1119 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1121 $result->{'publicationyear'} = $1;
1122 } else { # if no cYYYY, get the 1st date.
1123 $temp =~ m/(\d\d\d\d)/;
1124 $result->{'publicationyear'} = $1;
1129 sub MARCmarc2kohaOneField {
1131 # FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
1132 my ( $sth, $kohatable, $kohafield, $record, $result,$frameworkcode ) = @_;
1133 # warn "kohatable / $kohafield / $result / ";
1137 ( $tagfield, $subfield ) = MARCfind_marc_from_kohafield("",$kohatable.".".$kohafield,$frameworkcode);
1138 foreach my $field ( $record->field($tagfield) ) {
1139 if ( $field->subfield($subfield) ) {
1140 if ( $result->{$kohafield} ) {
1141 $result->{$kohafield} .= " | " . $field->subfield($subfield);
1144 $result->{$kohafield} = $field->subfield($subfield);
1148 # warn "OneField for $kohatable.$kohafield and $frameworkcode=> $tagfield, $subfield";
1154 # split a subfield string and adds it into the word table.
1157 $dbh, $bibid, $tag, $tagorder,
1158 $subfieldid, $subfieldorder, $sentence
1161 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\})/ /g;
1162 my @words = split / /, $sentence;
1163 my $stopwords = C4::Context->stopwords;
1166 "insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word)
1167 values (?,concat(?,?),?,?,?,soundex(?))"
1169 foreach my $word (@words) {
1170 # we record only words one char long and not in stopwords hash
1171 if (length($word)>=1 and !($stopwords->{uc($word)})) {
1172 $sth->execute($bibid,$tag,$subfieldid,$tagorder,$subfieldorder,$word,$word);
1174 warn "ERROR ==> insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word) values ($bibid,concat($tag,$subfieldid),$tagorder,$subfieldorder,$word,soundex($word))\n";
1182 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
1183 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
1186 "delete from marc_word where bibid=? and tagsubfield=concat(?,?) and tagorder=? and subfieldorder=?"
1188 $sth->execute( $bibid, $tag, $subfield, $tagorder, $subfieldorder );
1193 # NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW
1196 # all the following subs are useful to manage MARC-DB with complete MARC records.
1197 # it's used with marcimport, and marc management tools
1200 =item ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
1202 creates a new biblio from a MARC::Record. The 3rd and 4th parameter are hashes and may be ignored. If only 2 params are passed to the sub, the old-db hashes
1203 are builded from the MARC::Record. If they are passed, they are used.
1205 =item NEWnewitem($dbh, $record,$bibid);
1207 adds an item in the db.
1212 my ( $dbh, $record, $frameworkcode ) = @_;
1215 my $olddata = MARCmarc2koha( $dbh, $record,$frameworkcode );
1216 $oldbibnum = OLDnewbiblio( $dbh, $olddata );
1217 $olddata->{'biblionumber'} = $oldbibnum;
1218 $oldbibitemnum = OLDnewbiblioitem( $dbh, $olddata );
1220 # search subtiles, addiauthors and subjects
1221 my ( $tagfield, $tagsubfield ) =
1222 MARCfind_marc_from_kohafield( $dbh, "additionalauthors.author",$frameworkcode );
1223 my @addiauthfields = $record->field($tagfield);
1224 foreach my $addiauthfield (@addiauthfields) {
1225 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1226 foreach my $subfieldcount ( 0 .. $#addiauthsubfields ) {
1227 OLDmodaddauthor( $dbh, $oldbibnum,
1228 $addiauthsubfields[$subfieldcount] );
1231 ( $tagfield, $tagsubfield ) =
1232 MARCfind_marc_from_kohafield( $dbh, "bibliosubtitle.title",$frameworkcode );
1233 my @subtitlefields = $record->field($tagfield);
1234 foreach my $subtitlefield (@subtitlefields) {
1235 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1236 foreach my $subfieldcount ( 0 .. $#subtitlesubfields ) {
1237 OLDnewsubtitle( $dbh, $oldbibnum,
1238 $subtitlesubfields[$subfieldcount] );
1241 ( $tagfield, $tagsubfield ) =
1242 MARCfind_marc_from_kohafield( $dbh, "bibliosubject.subject",$frameworkcode );
1243 my @subj = $record->field($tagfield);
1245 foreach my $subject (@subj) {
1246 my @subjsubfield = $subject->subfield($tagsubfield);
1247 foreach my $subfieldcount ( 0 .. $#subjsubfield ) {
1248 push @subjects, $subjsubfield[$subfieldcount];
1251 OLDmodsubject( $dbh, $oldbibnum, 1, @subjects );
1253 # we must add bibnum and bibitemnum in MARC::Record...
1254 # we build the new field with biblionumber and biblioitemnumber
1255 # we drop the original field
1256 # we add the new builded field.
1257 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
1258 # (steve and paul : thinks 090 is a good choice)
1261 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
1263 $sth->execute("biblio.biblionumber");
1264 ( my $tagfield1, my $tagsubfield1 ) = $sth->fetchrow;
1265 $sth->execute("biblioitems.biblioitemnumber");
1266 ( my $tagfield2, my $tagsubfield2 ) = $sth->fetchrow;
1267 if ( $tagfield1 != $tagfield2 ) {
1269 "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1271 "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1274 my $newfield = MARC::Field->new(
1275 $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
1276 "$tagsubfield2" => $oldbibitemnum
1279 # drop old field and create new one...
1280 my $old_field = $record->field($tagfield1);
1281 $record->delete_field($old_field);
1282 $record->add_fields($newfield);
1283 my $bibid = MARCaddbiblio( $dbh, $record, $oldbibnum, $frameworkcode );
1284 return ( $bibid, $oldbibnum, $oldbibitemnum );
1288 my ($dbh,$record,$bibid,$frameworkcode) =@_;
1289 $frameworkcode="" unless $frameworkcode;
1290 &MARCmodbiblio($dbh,$bibid,$record,$frameworkcode,0);
1291 my $oldbiblio = MARCmarc2koha($dbh,$record,$frameworkcode);
1292 my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
1293 OLDmodbibitem($dbh,$oldbiblio);
1294 # now, modify addi authors, subject, addititles.
1295 my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"additionalauthors.author",$frameworkcode);
1296 my @addiauthfields = $record->field($tagfield);
1297 foreach my $addiauthfield (@addiauthfields) {
1298 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1299 foreach my $subfieldcount (0..$#addiauthsubfields) {
1300 OLDmodaddauthor($dbh,$oldbiblionumber,$addiauthsubfields[$subfieldcount]);
1303 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubtitle.subtitle",$frameworkcode);
1304 my @subtitlefields = $record->field($tagfield);
1305 foreach my $subtitlefield (@subtitlefields) {
1306 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1307 foreach my $subfieldcount (0..$#subtitlesubfields) {
1308 OLDmodsubtitle($dbh,$oldbiblionumber,$subtitlesubfields[$subfieldcount]);
1311 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject",$frameworkcode);
1312 my @subj = $record->field($tagfield);
1314 foreach my $subject (@subj) {
1315 my @subjsubfield = $subject->subfield($tagsubfield);
1316 foreach my $subfieldcount (0..$#subjsubfield) {
1317 push @subjects,$subjsubfield[$subfieldcount];
1320 OLDmodsubject($dbh,$oldbiblionumber,1,@subjects);
1325 my ( $dbh, $bibid ) = @_;
1326 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1327 &OLDdelbiblio( $dbh, $biblio );
1330 "select biblioitemnumber from biblioitems where biblionumber=?");
1331 $sth->execute($biblio);
1332 while ( my ($biblioitemnumber) = $sth->fetchrow ) {
1333 OLDdeletebiblioitem( $dbh, $biblioitemnumber );
1335 &MARCdelbiblio( $dbh, $bibid, 0 );
1339 my ( $dbh, $record, $bibid ) = @_;
1341 # add item in old-DB
1342 my $frameworkcode=MARCfind_frameworkcode($dbh,$bibid);
1343 my $item = &MARCmarc2koha( $dbh, $record,$frameworkcode );
1344 # needs old biblionumber and biblioitemnumber
1345 $item->{'biblionumber'} =
1346 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1349 "select biblioitemnumber from biblioitems where biblionumber=?");
1350 $sth->execute( $item->{'biblionumber'} );
1351 ( $item->{'biblioitemnumber'} ) = $sth->fetchrow;
1352 my ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, $item->{barcode} );
1354 # add itemnumber to MARC::Record before adding the item.
1357 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
1359 &MARCkoha2marcOnefield( $sth, $record, "items.itemnumber", $itemnumber,$frameworkcode );
1362 my $bib = &MARCadditem( $dbh, $record, $item->{'biblionumber'} );
1366 my ( $dbh, $record, $bibid, $itemnumber, $delete ) = @_;
1368 &MARCmoditem( $dbh, $record, $bibid, $itemnumber, $delete );
1369 my $frameworkcode=MARCfind_frameworkcode($dbh,$bibid);
1370 my $olditem = MARCmarc2koha( $dbh, $record,$frameworkcode );
1371 OLDmoditem( $dbh, $olditem );
1375 my ( $dbh, $bibid, $itemnumber ) = @_;
1376 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1377 &OLDdelitem( $dbh, $itemnumber );
1378 &MARCdelitem( $dbh, $bibid, $itemnumber );
1383 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
1387 =item $biblionumber = OLDnewbiblio($dbh,$biblio);
1389 adds a record in biblio table. Datas are in the hash $biblio.
1391 =item $biblionumber = OLDmodbiblio($dbh,$biblio);
1393 modify a record in biblio table. Datas are in the hash $biblio.
1395 =item OLDmodsubtitle($dbh,$bibnum,$subtitle);
1397 modify subtitles in bibliosubtitle table.
1399 =item OLDmodaddauthor($dbh,$bibnum,$author);
1401 adds or modify additional authors
1402 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1404 =item $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1406 modify/adds subjects
1408 =item OLDmodbibitem($dbh, $biblioitem);
1412 =item OLDmodnote($dbh,$bibitemnum,$note
1414 modify a note for a biblioitem
1416 =item OLDnewbiblioitem($dbh,$biblioitem);
1418 adds a biblioitem ($biblioitem is a hash with the values)
1420 =item OLDnewsubject($dbh,$bibnum);
1424 =item OLDnewsubtitle($dbh,$bibnum,$subtitle);
1426 create a new subtitle
1428 =item ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1430 create a item. $item is a hash and $barcode the barcode.
1432 =item OLDmoditem($dbh,$item);
1436 =item OLDdelitem($dbh,$itemnum);
1440 =item OLDdeletebiblioitem($dbh,$biblioitemnumber);
1442 deletes a biblioitem
1443 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1445 =item OLDdelbiblio($dbh,$biblio);
1452 my ( $dbh, $biblio ) = @_;
1454 # my $dbh = &C4Connect;
1455 my $sth = $dbh->prepare("Select max(biblionumber) from biblio");
1457 my $data = $sth->fetchrow_arrayref;
1458 my $bibnum = $$data[0] + 1;
1461 if ( $biblio->{'seriestitle'} ) { $series = 1 }
1465 "insert into biblio set biblionumber = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?"
1468 $bibnum, $biblio->{'title'},
1469 $biblio->{'author'}, $biblio->{'copyrightdate'},
1470 $biblio->{'serial'}, $biblio->{'seriestitle'},
1471 $biblio->{'notes'}, $biblio->{'abstract'}
1481 my ( $dbh, $biblio ) = @_;
1483 # my $dbh = C4Connect;
1490 "Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?, seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?"
1493 $biblio->{'title'}, $biblio->{'author'},
1494 $biblio->{'abstract'}, $biblio->{'copyrightdate'},
1495 $biblio->{'seriestitle'}, $biblio->{'serial'},
1496 $biblio->{'unititle'}, $biblio->{'notes'},
1497 $biblio->{'biblionumber'}
1501 return ( $biblio->{'biblionumber'} );
1504 sub OLDmodsubtitle {
1505 my ( $dbh, $bibnum, $subtitle ) = @_;
1508 "update bibliosubtitle set subtitle = ? where biblionumber = ?");
1509 $sth->execute( $subtitle, $bibnum );
1513 sub OLDmodaddauthor {
1514 my ( $dbh, $bibnum, @authors ) = @_;
1516 # my $dbh = C4Connect;
1518 $dbh->prepare("Delete from additionalauthors where biblionumber = ?");
1520 $sth->execute($bibnum);
1522 foreach my $author (@authors) {
1523 if ( $author ne '' ) {
1526 "Insert into additionalauthors set author = ?, biblionumber = ?"
1529 $sth->execute( $author, $bibnum );
1534 } # sub modaddauthor
1537 my ( $dbh, $bibnum, $force, @subject ) = @_;
1539 # my $dbh = C4Connect;
1540 my $count = @subject;
1542 for ( my $i = 0 ; $i < $count ; $i++ ) {
1543 $subject[$i] =~ s/^ //g;
1544 $subject[$i] =~ s/ $//g;
1547 "select * from catalogueentry where entrytype = 's' and catalogueentry = ?"
1549 $sth->execute( $subject[$i] );
1551 if ( my $data = $sth->fetchrow_hashref ) {
1554 if ( $force eq $subject[$i] || $force == 1 ) {
1556 # subject not in aut, chosen to force anway
1557 # so insert into cataloguentry so its in auth file
1560 "Insert into catalogueentry (entrytype,catalogueentry) values ('s',?)"
1563 $sth2->execute( $subject[$i] ) if ( $subject[$i] );
1568 "$subject[$i]\n does not exist in the subject authority file";
1571 "Select * from catalogueentry where entrytype = 's' and (catalogueentry like ? or catalogueentry like ? or catalogueentry like ?)"
1573 $sth2->execute( "$subject[$i] %", "% $subject[$i] %",
1575 while ( my $data = $sth2->fetchrow_hashref ) {
1576 $error .= "<br>$data->{'catalogueentry'}";
1583 if ( $error eq '' ) {
1585 $dbh->prepare("Delete from bibliosubject where biblionumber = ?");
1586 $sth->execute($bibnum);
1590 "Insert into bibliosubject (subject,biblionumber) values (?,?)");
1592 foreach $query (@subject) {
1593 $sth->execute( $query, $bibnum ) if ( $query && $bibnum );
1603 my ( $dbh, $biblioitem ) = @_;
1605 # my $dbh = C4Connect;
1608 $biblioitem->{'itemtype'} = $dbh->quote( $biblioitem->{'itemtype'} );
1609 $biblioitem->{'url'} = $dbh->quote( $biblioitem->{'url'} );
1610 $biblioitem->{'isbn'} = $dbh->quote( $biblioitem->{'isbn'} );
1611 $biblioitem->{'publishercode'} =
1612 $dbh->quote( $biblioitem->{'publishercode'} );
1613 $biblioitem->{'publicationyear'} =
1614 $dbh->quote( $biblioitem->{'publicationyear'} );
1615 $biblioitem->{'classification'} =
1616 $dbh->quote( $biblioitem->{'classification'} );
1617 $biblioitem->{'dewey'} = $dbh->quote( $biblioitem->{'dewey'} );
1618 $biblioitem->{'subclass'} = $dbh->quote( $biblioitem->{'subclass'} );
1619 $biblioitem->{'illus'} = $dbh->quote( $biblioitem->{'illus'} );
1620 $biblioitem->{'pages'} = $dbh->quote( $biblioitem->{'pages'} );
1621 $biblioitem->{'volumeddesc'} = $dbh->quote( $biblioitem->{'volumeddesc'} );
1622 $biblioitem->{'bnotes'} = $dbh->quote( $biblioitem->{'bnotes'} );
1623 $biblioitem->{'size'} = $dbh->quote( $biblioitem->{'size'} );
1624 $biblioitem->{'place'} = $dbh->quote( $biblioitem->{'place'} );
1626 $query = "Update biblioitems set
1627 itemtype = $biblioitem->{'itemtype'},
1628 url = $biblioitem->{'url'},
1629 isbn = $biblioitem->{'isbn'},
1630 publishercode = $biblioitem->{'publishercode'},
1631 publicationyear = $biblioitem->{'publicationyear'},
1632 classification = $biblioitem->{'classification'},
1633 dewey = $biblioitem->{'dewey'},
1634 subclass = $biblioitem->{'subclass'},
1635 illus = $biblioitem->{'illus'},
1636 pages = $biblioitem->{'pages'},
1637 volumeddesc = $biblioitem->{'volumeddesc'},
1638 notes = $biblioitem->{'bnotes'},
1639 size = $biblioitem->{'size'},
1640 place = $biblioitem->{'place'}
1641 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1644 if ( $dbh->errstr ) {
1652 my ( $dbh, $bibitemnum, $note ) = @_;
1654 # my $dbh=C4Connect;
1655 my $query = "update biblioitems set notes='$note' where
1656 biblioitemnumber='$bibitemnum'";
1657 my $sth = $dbh->prepare($query);
1664 sub OLDnewbiblioitem {
1665 my ( $dbh, $biblioitem ) = @_;
1667 # my $dbh = C4Connect;
1668 my $sth = $dbh->prepare("Select max(biblioitemnumber) from biblioitems");
1673 $data = $sth->fetchrow_arrayref;
1674 $bibitemnum = $$data[0] + 1;
1678 $sth = $dbh->prepare( "insert into biblioitems set
1679 biblioitemnumber = ?, biblionumber = ?,
1680 volume = ?, number = ?,
1681 classification = ?, itemtype = ?,
1683 issn = ?, dewey = ?,
1684 subclass = ?, publicationyear = ?,
1685 publishercode = ?, volumedate = ?,
1686 volumeddesc = ?, illus = ?,
1687 pages = ?, notes = ?,
1689 marc = ?, place = ?"
1692 $bibitemnum, $biblioitem->{'biblionumber'},
1693 $biblioitem->{'volume'}, $biblioitem->{'number'},
1694 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
1695 $biblioitem->{'url'}, $biblioitem->{'isbn'},
1696 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
1697 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
1698 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
1699 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
1700 $biblioitem->{'pages'}, $biblioitem->{'bnotes'},
1701 $biblioitem->{'size'}, $biblioitem->{'lccn'},
1702 $biblioitem->{'marc'}, $biblioitem->{'place'}
1707 return ($bibitemnum);
1711 my ( $dbh, $bibnum ) = @_;
1713 $dbh->prepare("insert into bibliosubject (biblionumber) values (?)");
1714 $sth->execute($bibnum);
1718 sub OLDnewsubtitle {
1719 my ( $dbh, $bibnum, $subtitle ) = @_;
1722 "insert into bibliosubtitle set biblionumber = ?, subtitle = ?");
1723 $sth->execute( $bibnum, $subtitle );
1728 my ( $dbh, $item, $barcode ) = @_;
1730 # my $dbh = C4Connect;
1731 my $sth = $dbh->prepare("Select max(itemnumber) from items");
1737 $data = $sth->fetchrow_hashref;
1738 $itemnumber = $data->{'max(itemnumber)'} + 1;
1741 # FIXME the "notforloan" field seems to be named "loan" in some places. workaround bugfix.
1742 if ( $item->{'loan'} ) {
1743 $item->{'notforloan'} = $item->{'loan'};
1746 # if dateaccessioned is provided, use it. Otherwise, set to NOW()
1747 if ( $item->{'dateaccessioned'} ) {
1748 $sth = $dbh->prepare( "Insert into items set
1749 itemnumber = ?, biblionumber = ?,
1750 biblioitemnumber = ?, barcode = ?,
1751 booksellerid = ?, dateaccessioned = ?,
1752 homebranch = ?, holdingbranch = ?,
1753 price = ?, replacementprice = ?,
1754 replacementpricedate = NOW(), itemnotes = ?,
1755 itemcallnumber =?, notforloan = ?,
1760 $itemnumber, $item->{'biblionumber'},
1761 $item->{'biblioitemnumber'}, $barcode,
1762 $item->{'booksellerid'}, $item->{'dateaccessioned'},
1763 $item->{'homebranch'}, $item->{'holdingbranch'},
1764 $item->{'price'}, $item->{'replacementprice'},
1765 $item->{'itemnotes'}, $item->{'itemcallnumber'},
1766 $item->{'notforloan'}, $item->{'location'}
1770 $sth = $dbh->prepare( "Insert into items set
1771 itemnumber = ?, biblionumber = ?,
1772 biblioitemnumber = ?, barcode = ?,
1773 booksellerid = ?, dateaccessioned = NOW(),
1774 homebranch = ?, holdingbranch = ?,
1775 price = ?, replacementprice = ?,
1776 replacementpricedate = NOW(), itemnotes = ?,
1777 itemcallnumber = ? , notforloan = ?,
1782 $itemnumber, $item->{'biblionumber'},
1783 $item->{'biblioitemnumber'}, $barcode,
1784 $item->{'booksellerid'}, $item->{'homebranch'},
1785 $item->{'holdingbranch'}, $item->{'price'},
1786 $item->{'replacementprice'}, $item->{'itemnotes'},
1787 $item->{'itemcallnumber'}, $item->{'notforloan'},
1791 if ( defined $sth->errstr ) {
1792 $error .= $sth->errstr;
1795 return ( $itemnumber, $error );
1799 my ( $dbh, $item ) = @_;
1801 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1802 # my $dbh=C4Connect;
1803 $item->{'itemnum'} = $item->{'itemnumber'} unless $item->{'itemnum'};
1804 my $query = "update items set barcode=?,itemnotes=?,itemcallnumber=?,notforloan=?,location=? where itemnumber=?";
1806 $item->{'barcode'}, $item->{'notes'},
1807 $item->{'itemcallnumber'}, $item->{'notforloan'},
1808 $item->{'location'}, $item->{'itemnum'}
1810 if ( $item->{'barcode'} eq '' ) {
1811 $item->{'notforloan'} = 0 unless $item->{'notforloan'};
1812 $query = "update items set notforloan=? where itemnumber=?";
1813 @bind = ( $item->{'notforloan'}, $item->{'itemnum'} );
1815 if ( $item->{'lost'} ne '' ) {
1816 $query = "update items set biblioitemnumber=?,
1826 $item->{'bibitemnum'}, $item->{'barcode'},
1827 $item->{'notes'}, $item->{'homebranch'},
1828 $item->{'lost'}, $item->{'wthdrawn'},
1829 $item->{'itemcallnumber'}, $item->{'notforloan'},
1830 $item->{'location'}, $item->{'itemnum'}
1832 if ($item->{homebranch}) {
1833 $query.=",homebranch=?";
1834 push @bind, $item->{homebranch};
1836 if ($item->{holdingbranch}) {
1837 $query.=",holdingbranch=?";
1838 push @bind, $item->{holdingbranch};
1840 $query.=" where itemnumber=?";
1842 if ( $item->{'replacement'} ne '' ) {
1843 $query =~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1845 my $sth = $dbh->prepare($query);
1846 $sth->execute(@bind);
1853 my ( $dbh, $itemnum ) = @_;
1855 # my $dbh=C4Connect;
1856 my $sth = $dbh->prepare("select * from items where itemnumber=?");
1857 $sth->execute($itemnum);
1858 my $data = $sth->fetchrow_hashref;
1860 my $query = "Insert into deleteditems set ";
1862 foreach my $temp ( keys %$data ) {
1863 $query .= "$temp = ?,";
1864 push ( @bind, $data->{$temp} );
1869 $sth = $dbh->prepare($query);
1870 $sth->execute(@bind);
1872 $sth = $dbh->prepare("Delete from items where itemnumber=?");
1873 $sth->execute($itemnum);
1879 sub OLDdeletebiblioitem {
1880 my ( $dbh, $biblioitemnumber ) = @_;
1882 # my $dbh = C4Connect;
1883 my $sth = $dbh->prepare( "Select * from biblioitems
1884 where biblioitemnumber = ?"
1888 $sth->execute($biblioitemnumber);
1890 if ( $results = $sth->fetchrow_hashref ) {
1894 "Insert into deletedbiblioitems (biblioitemnumber, biblionumber, volume, number, classification, itemtype,
1895 isbn, issn ,dewey ,subclass ,publicationyear ,publishercode ,volumedate ,volumeddesc ,timestamp ,illus ,
1896 pages ,notes ,size ,url ,lccn ) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
1900 $results->{biblioitemnumber}, $results->{biblionumber},
1901 $results->{volume}, $results->{number},
1902 $results->{classification}, $results->{itemtype},
1903 $results->{isbn}, $results->{issn},
1904 $results->{dewey}, $results->{subclass},
1905 $results->{publicationyear}, $results->{publishercode},
1906 $results->{volumedate}, $results->{volumeddesc},
1907 $results->{timestamp}, $results->{illus},
1908 $results->{pages}, $results->{notes},
1909 $results->{size}, $results->{url},
1913 $dbh->prepare("Delete from biblioitems where biblioitemnumber = ?");
1914 $sth2->execute($biblioitemnumber);
1919 # Now delete all the items attached to the biblioitem
1920 $sth = $dbh->prepare("Select * from items where biblioitemnumber = ?");
1921 $sth->execute($biblioitemnumber);
1923 while ( my $data = $sth->fetchrow_hashref ) {
1924 my $query = "Insert into deleteditems set ";
1926 foreach my $temp ( keys %$data ) {
1927 $query .= "$temp = ?,";
1928 push ( @bind, $data->{$temp} );
1931 my $sth2 = $dbh->prepare($query);
1932 $sth2->execute(@bind);
1935 $sth = $dbh->prepare("Delete from items where biblioitemnumber = ?");
1936 $sth->execute($biblioitemnumber);
1940 } # sub deletebiblioitem
1943 my ( $dbh, $biblio ) = @_;
1944 my $sth = $dbh->prepare("select * from biblio where biblionumber=?");
1945 $sth->execute($biblio);
1946 if ( my $data = $sth->fetchrow_hashref ) {
1948 my $query = "Insert into deletedbiblio set ";
1950 foreach my $temp ( keys %$data ) {
1951 $query .= "$temp = ?,";
1952 push ( @bind, $data->{$temp} );
1955 #replacing the last , by ",?)"
1957 $sth = $dbh->prepare($query);
1958 $sth->execute(@bind);
1960 $sth = $dbh->prepare("Delete from biblio where biblionumber=?");
1961 $sth->execute($biblio);
1975 my $dbh = C4::Context->dbh;
1978 my $sth = $dbh->prepare("Select count(*) from items where biblionumber=?");
1979 $sth->execute($biblio);
1980 my $data = $sth->fetchrow_hashref;
1982 return ( $data->{'count(*)'} );
1987 my $dbh = C4::Context->dbh;
1988 my $bibnum = OLDnewbiblio( $dbh, $biblio );
1989 # finds new (MARC bibid
1990 # my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
1991 my $record = &MARCkoha2marcBiblio( $dbh, $bibnum );
1992 MARCaddbiblio( $dbh, $record, $bibnum,'' );
1998 $biblionumber = &modbiblio($biblio);
2000 Update a biblio record.
2002 C<$biblio> is a reference-to-hash whose keys are the fields in the
2003 biblio table in the Koha database. All fields must be present, not
2004 just the ones you wish to change.
2006 C<&modbiblio> updates the record defined by
2007 C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
2009 C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
2016 my $dbh = C4::Context->dbh;
2017 my $biblionumber=OLDmodbiblio($dbh,$biblio);
2018 my $record = MARCkoha2marcBiblio($dbh,$biblionumber,$biblionumber);
2019 # finds new (MARC bibid
2020 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
2021 MARCmodbiblio($dbh,$bibid,$record,"",0);
2022 return($biblionumber);
2027 &modsubtitle($biblionumber, $subtitle);
2029 Sets the subtitle of a book.
2031 C<$biblionumber> is the biblionumber of the book to modify.
2033 C<$subtitle> is the new subtitle.
2038 my ( $bibnum, $subtitle ) = @_;
2039 my $dbh = C4::Context->dbh;
2040 &OLDmodsubtitle( $dbh, $bibnum, $subtitle );
2045 &modaddauthor($biblionumber, $author);
2047 Replaces all additional authors for the book with biblio number
2048 C<$biblionumber> with C<$author>. If C<$author> is the empty string,
2049 C<&modaddauthor> deletes all additional authors.
2054 my ( $bibnum, @authors ) = @_;
2055 my $dbh = C4::Context->dbh;
2056 &OLDmodaddauthor( $dbh, $bibnum, @authors );
2057 } # sub modaddauthor
2061 $error = &modsubject($biblionumber, $force, @subjects);
2063 $force - a subject to force
2065 $error - Error message, or undef if successful.
2070 my ( $bibnum, $force, @subject ) = @_;
2071 my $dbh = C4::Context->dbh;
2072 my $error = &OLDmodsubject( $dbh, $bibnum, $force, @subject );
2077 my ($biblioitem) = @_;
2078 my $dbh = C4::Context->dbh;
2079 &OLDmodbibitem( $dbh, $biblioitem );
2083 my ( $bibitemnum, $note ) = @_;
2084 my $dbh = C4::Context->dbh;
2085 &OLDmodnote( $dbh, $bibitemnum, $note );
2089 my ($biblioitem) = @_;
2090 my $dbh = C4::Context->dbh;
2091 my $bibitemnum = &OLDnewbiblioitem( $dbh, $biblioitem );
2094 MARCkoha2marcBiblio( $dbh, 0, $bibitemnum )
2095 ; # the 0 means "do NOT retrieve biblio, only biblioitem, in the MARC record
2097 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh,
2098 $biblioitem->{biblionumber} );
2099 &MARCaddbiblio( $dbh, $MARCbiblio, $biblioitem->{biblionumber}, '',$bibid );
2100 return ($bibitemnum);
2105 my $dbh = C4::Context->dbh;
2106 &OLDnewsubject( $dbh, $bibnum );
2110 my ( $bibnum, $subtitle ) = @_;
2111 my $dbh = C4::Context->dbh;
2112 &OLDnewsubtitle( $dbh, $bibnum, $subtitle );
2116 my ( $item, @barcodes ) = @_;
2117 my $dbh = C4::Context->dbh;
2121 foreach my $barcode (@barcodes) {
2122 ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, uc($barcode) );
2125 &MARCkoha2marcItem( $dbh, $item->{biblionumber}, $itemnumber );
2126 &MARCadditem( $dbh, $MARCitem, $item->{biblionumber} );
2133 my $dbh = C4::Context->dbh;
2134 &OLDmoditem( $dbh, $item );
2136 &MARCkoha2marcItem( $dbh, $item->{'biblionumber'}, $item->{'itemnum'} );
2138 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $item->{biblionumber} );
2139 &MARCmoditem( $dbh, $MARCitem, $bibid, $item->{itemnum}, 0 );
2143 my ( $count, @barcodes ) = @_;
2144 my $dbh = C4::Context->dbh;
2146 my $sth = $dbh->prepare("Select * from items where barcode=?");
2147 for ( my $i = 0 ; $i < $count ; $i++ ) {
2148 $barcodes[$i] = uc $barcodes[$i];
2149 $sth->execute( $barcodes[$i] );
2150 if ( my $data = $sth->fetchrow_hashref ) {
2151 $error .= " Duplicate Barcode: $barcodes[$i]";
2159 my ($bibitemnum) = @_;
2160 my $dbh = C4::Context->dbh;
2163 $dbh->prepare("Select count(*) from items where biblioitemnumber=?");
2164 $sth->execute($bibitemnum);
2165 my $data = $sth->fetchrow_hashref;
2167 return ( $data->{'count(*)'} );
2172 my $dbh = C4::Context->dbh;
2173 &OLDdelitem( $dbh, $itemnum );
2176 sub deletebiblioitem {
2177 my ($biblioitemnumber) = @_;
2178 my $dbh = C4::Context->dbh;
2179 &OLDdeletebiblioitem( $dbh, $biblioitemnumber );
2180 } # sub deletebiblioitem
2184 my $dbh = C4::Context->dbh;
2185 &OLDdelbiblio( $dbh, $biblio );
2186 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $biblio );
2187 &MARCdelbiblio( $dbh, $bibid, 0 );
2191 my ($biblionumber) = @_;
2192 my $dbh = C4::Context->dbh;
2193 my $sth = $dbh->prepare("Select * from biblio where biblionumber = ?");
2195 # || die "Cannot prepare $query\n" . $dbh->errstr;
2199 $sth->execute($biblionumber);
2201 # || die "Cannot execute $query\n" . $sth->errstr;
2202 while ( my $data = $sth->fetchrow_hashref ) {
2203 $results[$count] = $data;
2208 return ( $count, @results );
2212 my ($biblioitemnum) = @_;
2213 my $dbh = C4::Context->dbh;
2214 my $sth = $dbh->prepare( "Select * from biblioitems where
2215 biblioitemnumber = ?"
2220 $sth->execute($biblioitemnum);
2222 while ( my $data = $sth->fetchrow_hashref ) {
2223 $results[$count] = $data;
2228 return ( $count, @results );
2229 } # sub getbiblioitem
2231 sub getbiblioitembybiblionumber {
2232 my ($biblionumber) = @_;
2233 my $dbh = C4::Context->dbh;
2234 my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?");
2238 $sth->execute($biblionumber);
2240 while ( my $data = $sth->fetchrow_hashref ) {
2241 $results[$count] = $data;
2246 return ( $count, @results );
2250 my $dbh = C4::Context->dbh;
2251 my $query = "select * from itemtypes order by description";
2252 my $sth = $dbh->prepare($query);
2254 # || die "Cannot prepare $query" . $dbh->errstr;
2260 # || die "Cannot execute $query\n" . $sth->errstr;
2261 while ( my $data = $sth->fetchrow_hashref ) {
2262 $results[$count] = $data;
2267 return ( $count, @results );
2268 } # sub getitemtypes
2270 sub getitemsbybiblioitem {
2271 my ($biblioitemnum) = @_;
2272 my $dbh = C4::Context->dbh;
2273 my $sth = $dbh->prepare( "Select * from items, biblio where
2274 biblio.biblionumber = items.biblionumber and biblioitemnumber
2278 # || die "Cannot prepare $query\n" . $dbh->errstr;
2282 $sth->execute($biblioitemnum);
2284 # || die "Cannot execute $query\n" . $sth->errstr;
2285 while ( my $data = $sth->fetchrow_hashref ) {
2286 $results[$count] = $data;
2291 return ( $count, @results );
2292 } # sub getitemsbybiblioitem
2296 # Subroutine to log changes to databases
2297 # Eventually, this subroutine will be used to create a log of all changes made,
2298 # with the possibility of "undo"ing some changes
2299 my $database = shift;
2300 if ( $database eq 'kohadb' ) {
2302 my $section = shift;
2304 my $original = shift;
2307 # print STDERR "KOHA: $type $section $item $original $new\n";
2309 elsif ( $database eq 'marc' ) {
2311 my $Record_ID = shift;
2314 my $subfield_ID = shift;
2315 my $original = shift;
2318 # print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2322 #------------------------------------------------
2324 #---------------------------------------
2325 # Find a biblio entry, or create a new one if it doesn't exist.
2326 # If a "subtitle" entry is in hash, add it to subtitle table
2327 sub getoraddbiblio {
2332 # FIXME - Unused argument
2333 $biblio, # hash ref to fields
2344 $dbh = C4::Context->dbh;
2346 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2347 $sth = $dbh->prepare( "select biblionumber
2349 where title=? and author=?
2350 and copyrightdate=? and seriestitle=?"
2353 $biblio->{title}, $biblio->{author},
2354 $biblio->{copyright}, $biblio->{seriestitle}
2357 ($biblionumber) = $sth->fetchrow;
2358 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2362 # Doesn't exist. Add new one.
2363 print "<PRE>Adding biblio</PRE>\n" if $debug;
2364 ( $biblionumber, $error ) = &newbiblio($biblio);
2365 if ($biblionumber) {
2366 print "<PRE>Added with biblio number=$biblionumber</PRE>\n"
2368 if ( $biblio->{subtitle} ) {
2369 &newsubtitle( $biblionumber, $biblio->{subtitle} );
2373 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2377 return $biblionumber, $error;
2379 } # sub getoraddbiblio
2383 # converts ISO 5426 coded string to ISO 8859-1
2384 # sloppy code : should be improved in next issue
2385 my ( $string, $encoding ) = @_;
2388 # $encoding = C4::Context->preference("marcflavour") unless $encoding;
2389 if ( $encoding eq "UNIMARC" ) {
2452 # this handles non-sorting blocks (if implementation requires this)
2453 $string = nsb_clean($_);
2455 elsif ( $encoding eq "USMARC" || $encoding eq "MARC21" ) {
2456 if (/[\xc1-\xff]/) {
2509 # this handles non-sorting blocks (if implementation requires this)
2510 $string = nsb_clean($_);
2517 my $NSB = '\x88'; # NSB : begin Non Sorting Block
2518 my $NSE = '\x89'; # NSE : Non Sorting Block end
2519 # handles non sorting blocks
2523 s/[ ]{0,1}$NSE/) /gm;
2530 my $dbh = C4::Context->dbh;
2531 my $result = MARCmarc2koha($dbh,$record,'');
2532 # search duplicate on ISBN, easy and fast...
2533 my $sth = $dbh->prepare("select biblio.biblionumber,bibid,title from biblio,biblioitems,marc_biblio where biblio.biblionumber=biblioitems.biblionumber and marc_biblio.biblionumber=biblioitems.biblionumber and isbn=?");
2534 $sth->execute($result->{'isbn'});
2535 my ($biblionumber,$bibid,$title) = $sth->fetchrow;
2536 return $biblionumber,$bibid,$title if ($biblionumber);
2537 # a more complex search : build a request for SearchMarc::catalogsearch()
2538 my (@tags, @and_or, @excluding, @operator, @value, $offset,$length);
2539 # search on biblio.title
2540 my ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblio.title","");
2541 if ($record->field($tag)) {
2542 if ($record->field($tag)->subfields($subfield)) {
2543 push @tags, "'".$tag.$subfield."'";
2544 push @and_or, "and";
2545 push @excluding, "";
2546 push @operator, "contains";
2547 push @value, $record->field($tag)->subfield($subfield);
2548 # warn "for title, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2551 # ... and on biblio.author
2552 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblio.author","");
2553 if ($record->field($tag)) {
2554 if ($record->field($tag)->subfields($subfield)) {
2555 push @tags, "'".$tag.$subfield."'";
2556 push @and_or, "and";
2557 push @excluding, "";
2558 push @operator, "contains";
2559 push @value, $record->field($tag)->subfield($subfield);
2560 # warn "for author, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2563 # ... and on publicationyear.
2564 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.publicationyear","");
2565 if ($record->field($tag)) {
2566 if ($record->field($tag)->subfields($subfield)) {
2567 push @tags, "'".$tag.$subfield."'";
2568 push @and_or, "and";
2569 push @excluding, "";
2570 push @operator, "=";
2571 push @value, $record->field($tag)->subfield($subfield);
2572 # warn "for publicationyear, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2576 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.size","");
2577 if ($record->field($tag)) {
2578 if ($record->field($tag)->subfields($subfield)) {
2579 push @tags, "'".$tag.$subfield."'";
2580 push @and_or, "and";
2581 push @excluding, "";
2582 push @operator, "=";
2583 push @value, $record->field($tag)->subfield($subfield);
2584 # warn "for size, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2587 # ... and on publisher.
2588 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.publishercode","");
2589 if ($record->field($tag)) {
2590 if ($record->field($tag)->subfields($subfield)) {
2591 push @tags, "'".$tag.$subfield."'";
2592 push @and_or, "and";
2593 push @excluding, "";
2594 push @operator, "=";
2595 push @value, $record->field($tag)->subfield($subfield);
2596 # warn "for publishercode, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2599 # ... and on volume.
2600 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.volume","");
2601 if ($record->field($tag)) {
2602 if ($record->field($tag)->subfields($subfield)) {
2603 push @tags, "'".$tag.$subfield."'";
2604 push @and_or, "and";
2605 push @excluding, "";
2606 push @operator, "=";
2607 push @value, $record->field($tag)->subfield($subfield);
2608 # warn "for volume, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2612 my ($finalresult,$nbresult) = C4::SearchMarc::catalogsearch($dbh,\@tags,\@and_or,\@excluding,\@operator,\@value,0,10);
2613 # there is at least 1 result => return the 1st one
2615 # warn "$nbresult => ".@$finalresult[0]->{biblionumber},@$finalresult[0]->{bibid},@$finalresult[0]->{title};
2616 return @$finalresult[0]->{biblionumber},@$finalresult[0]->{bibid},@$finalresult[0]->{title};
2618 # no result, returns nothing
2622 END { } # module clean-up code here (global destructor)
2628 Koha Developement team <info@koha.org>
2630 Paul POULAIN paul.poulain@free.fr
2636 # Revision 1.115 2005/01/06 14:32:17 tipaul
2637 # improvement of speed for bulkmarcimport.
2638 # A sub had been forgotten to use the C4::Context->marcfromkohafield array, that caches DB datas.
2639 # this is only a little improvement for normal DB modif, but almost x2 the speed of bulkmarcimport... from 6records/seconds to more than 10.
2641 # Revision 1.114 2005/01/03 10:48:33 tipaul
2642 # * bugfix for the search on a MARC detail, when you clic on the magnifying glass (caused an internal server error)
2643 # * partial support of the "linkage" MARC feature : if you enter a "link" on a MARC subfield, the magnifying glass won't search on the field, but on the linked field. I agree it's a partial support. Will be improved, but I need to investigate MARC21 & UNIMARC diffs on this topic.
2645 # Revision 1.113 2004/12/10 16:27:53 tipaul
2646 # limiting the number of search term to 8. There was no limit before, but 8 words seems to be the upper limit mySQL can deal with (in less than a second. tested on a DB with 13 000 items)
2647 # In 2.4, a new DB structure will highly speed things and this limit will be removed.
2648 # FindDuplicate is activated again, the perf problems were due to this problem.
2650 # Revision 1.112 2004/12/08 10:14:42 tipaul
2651 # * desactivate FindDuplicate
2654 # Revision 1.111 2004/11/25 17:39:44 tipaul
2655 # removing useless &branches in package declaration
2657 # Revision 1.110 2004/11/24 16:00:01 tipaul
2658 # removing sub branches (commited by chris for MARC=OFF bugfix, but sub branches is already in Acquisition.pm)
2660 # Revision 1.109 2004/11/24 15:58:31 tipaul
2661 # * critical fix for acquisition (see RC3 release notes)
2662 # * critical fix for duplicate finder
2664 # Revision 1.108 2004/11/19 19:41:22 rangi
2665 # Shifting branches() from deprecated C4::Catalogue to C4::Biblio
2666 # Allowing the non marc interface acquisitions to work.
2668 # Revision 1.107 2004/11/05 10:15:27 tipaul
2669 # Improving FindDuplicate to find duplicate records on adding biblio
2671 # Revision 1.106 2004/11/02 16:44:45 tipaul
2672 # new feature : checking for duplicate biblio.
2674 # For instance, it's only done on ISBN only. Will be improved soon.
2676 # When a duplicate is detected, the biblio is not saved, but the user is asked for a confirmations.
2678 # Revision 1.105 2004/09/23 16:15:37 tipaul
2681 # Revision 1.104 2004/09/16 15:06:46 tipaul
2682 # enabling # (| still possible too) for repeatable subfields
2684 # Revision 1.103 2004/09/06 14:17:34 tipaul
2685 # some commented warning added + 1 major bugfix => drop empty fields, NOT fields containing 0
2687 # Revision 1.102 2004/09/06 10:00:19 tipaul
2688 # adding a "location" field to the library.
2689 # This field is useful when the callnumber contains no information on the room where the item is stored.
2690 # With this field, we now have 3 levels of informations to find a book :
2695 # This should be versatile enough to solve any storing method.
2696 # This hack is quite simple, due to the nice Biblio.pm API. The MARC => koha db link is automatically managed. Just add the link in the parameters section.
2698 # Revision 1.101 2004/08/18 16:01:37 tipaul
2699 # modifs to support frameworkcodes
2701 # Revision 1.100 2004/08/13 16:37:25 tipaul
2702 # adding frameworkcode to API in some subs
2704 # Revision 1.99 2004/07/30 13:54:50 doxulting
2705 # Beginning of serial commit
2707 # Revision 1.98 2004/07/15 09:48:10 tipaul
2708 # * removing useless sub
2709 # * minor bugfix in moditem (managing homebranch & holdingbranch)
2711 # Revision 1.97 2004/07/02 15:53:53 tipaul
2712 # bugfix (due to frameworkcode field)
2714 # Revision 1.96 2004/06/29 16:07:10 tipaul
2715 # last sync for 2.1.0 release
2717 # Revision 1.95 2004/06/26 23:19:59 rangi
2718 # Fixing modaddauthor, and adding getitemtypes.
2719 # Also tidying up formatting of code
2721 # Revision 1.94 2004/06/17 08:16:32 tipaul
2722 # merging tag & subfield in marc_word for better perfs
2724 # Revision 1.93 2004/06/11 15:38:06 joshferraro
2725 # Changes MARCaddword to index words >= 1 char ... needed for more accurate
2726 # searches using SearchMarc routines.
2728 # Revision 1.92 2004/06/10 08:29:01 tipaul
2729 # MARC authority management (continued)
2731 # Revision 1.91 2004/06/03 10:03:01 tipaul
2732 # * frameworks and itemtypes are independant
2733 # * in the MARC editor, showing the + to duplicate a tag only if the tag is repeatable
2735 # Revision 1.90 2004/05/28 08:25:53 tipaul
2736 # hidding hidden & isurl constraints into MARC subfield structure
2738 # Revision 1.89 2004/05/27 21:47:21 rangi
2741 # Revision 1.88 2004/05/18 15:23:49 tipaul
2742 # framework management : 1 MARC framework for each itemtype
2744 # Revision 1.87 2004/05/18 11:54:07 tipaul
2745 # getitemtypes moved in Koha.pm
2747 # Revision 1.86 2004/05/03 09:19:22 tipaul
2748 # some fixes for mysql prepare & execute
2750 # Revision 1.85 2004/04/02 14:55:48 tipaul
2751 # renaming items.bulk field to items.itemcallnumber.
2752 # Will be used to store call number for libraries that don't use dewey classification.
2753 # Note it's related to ITEMS, not biblio.
2755 # Revision 1.84 2004/03/24 17:18:30 joshferraro
2756 # Fixes bug 749 by removing the comma on line 1488.
2758 # Revision 1.83 2004/03/15 14:31:50 tipaul
2759 # adding a minor check
2761 # Revision 1.82 2004/03/07 05:47:31 acli
2762 # Various updates/fixes from rel_2_0
2763 # Fixes for bugs 721 (templating), 727, and 734
2765 # Revision 1.81 2004/03/06 20:26:13 tipaul
2766 # adding seealso feature in MARC searches
2768 # Revision 1.80 2004/02/12 13:40:56 tipaul
2769 # deleting subs duplicated by error
2771 # Revision 1.79 2004/02/11 08:40:09 tipaul
2772 # synch'ing 2.0.0 branch and head
2774 # Revision 1.78.2.3 2004/02/10 13:15:46 tipaul
2775 # removing 2 warnings
2777 # Revision 1.78.2.2 2004/01/26 10:38:06 tipaul
2778 # dealing correctly "bulk" field
2780 # Revision 1.78.2.1 2004/01/13 17:29:53 tipaul
2781 # * minor html fixes
2782 # * adding publisher in acquisition process (& ordering basket by publisher)
2784 # Revision 1.78 2003/12/09 15:57:28 tipaul
2785 # rolling back to working char_decode sub
2787 # Revision 1.77 2003/12/03 17:47:14 tipaul
2788 # bugfixes for biblio deletion
2790 # Revision 1.76 2003/12/03 01:43:41 slef
2793 # Revision 1.75 2003/12/03 01:42:03 slef
2794 # bug 662 fixes securing DBI
2796 # Revision 1.74 2003/11/28 09:48:33 tipaul
2797 # bugfix : misusing prepare & execute => now using prepare(?) and execute($var)
2799 # Revision 1.73 2003/11/28 09:45:25 tipaul
2800 # bugfix for iso2709 file import in the "notforloan" field.
2802 # But notforloan field called "loan" somewhere, so in case "loan" is used, copied to "notforloan" to avoid a bug.
2804 # Revision 1.72 2003/11/24 17:40:14 tipaul
2807 # Revision 1.71 2003/11/24 16:28:49 tipaul
2808 # biblio & item deletion now works fine in MARC editor.
2809 # Stores deleted biblio/item in the marc field of the deletedbiblio/deleteditem table.
2811 # Revision 1.70 2003/11/24 13:29:55 tipaul
2812 # moving $id from beginning to end of file (70 commits... huge comments...)
2814 # Revision 1.69 2003/11/24 13:27:17 tipaul
2815 # fix for #380 (bibliosubject)
2817 # Revision 1.68 2003/11/06 17:18:30 tipaul
2820 # 1st draft for MARC biblio deletion.
2821 # Still does not work well, but at least, Biblio.pm compiles & it should'nt break too many things
2822 # (Note the trash in the MARCdetail, but don't use it, please :-) )
2824 # Revision 1.67 2003/10/25 08:46:27 tipaul
2825 # minor fixes for bilbio deletion (still buggy)
2827 # Revision 1.66 2003/10/17 10:02:56 tipaul
2828 # Indexing only words longer than 2 letters. Was >=2 before, & 2 letters words usually means nothing.
2830 # Revision 1.65 2003/10/14 09:45:29 tipaul
2831 # adding rebuildnonmarc.pl script : run this script when you change a link between marc and non MARC DB. It rebuilds the non-MARC DB (long operation)
2833 # Revision 1.64 2003/10/06 15:20:51 tipaul
2834 # fix for 536 (subtitle error)
2836 # Revision 1.63 2003/10/01 13:25:49 tipaul
2837 # seems a char encoding problem modified something in char_decode sub... changing back to something that works...
2839 # Revision 1.62 2003/09/17 14:21:13 tipaul
2840 # fixing bug that makes a MARC biblio disappear when using full acquisition (order => recieve ==> MARC editor).
2841 # Before this 2 lines fix, the MARC biblio was deleted during recieve, and had to be entirely recreated :-(
2843 # Revision 1.61 2003/09/17 10:24:39 tipaul
2844 # notforloan value in itemtype was overwritting notforloan value in a given item.
2845 # I changed this behaviour :
2846 # if notforloan is set for a given item, and NOT for all items from this itemtype, the notforloan is kept.
2847 # If notforloan is set for itemtype, it's used (and impossible to loan a specific item from this itemtype)
2849 # Revision 1.60 2003/09/04 14:11:23 tipaul
2850 # fix for 593 (data duplication in MARC-DB)
2852 # Revision 1.58 2003/08/06 12:54:52 tipaul
2853 # fix for publicationyear : extracting numeric value from MARC string, like for copyrightdate.
2854 # (note that copyrightdate still extracted to get numeric format)
2856 # Revision 1.57 2003/07/15 23:09:18 slef
2857 # change show columns to use biblioitems bnotes too
2859 # Revision 1.56 2003/07/15 11:34:52 slef
2860 # fixes from paul email
2862 # Revision 1.55 2003/07/15 00:02:49 slef
2863 # Work on bug 515... can we do a single-side rename of notes to bnotes?
2865 # Revision 1.54 2003/07/11 11:51:32 tipaul
2866 # *** empty log message ***
2868 # Revision 1.52 2003/07/10 10:37:19 tipaul
2869 # fix for copyrightdate problem, #514
2871 # Revision 1.51 2003/07/02 14:47:17 tipaul
2872 # fix for #519 : items.dateaccessioned imports incorrectly
2874 # Revision 1.49 2003/06/17 11:21:13 tipaul
2875 # improvments/fixes for z3950 support.
2876 # * Works now even on ADD, not only on MODIFY
2877 # * able to search on ISBN, author, title
2879 # Revision 1.48 2003/06/16 09:22:53 rangi
2880 # Just added an order clause to getitemtypes
2882 # Revision 1.47 2003/05/20 16:22:44 tipaul
2883 # fixing typo in Biblio.pm POD
2885 # Revision 1.46 2003/05/19 13:45:18 tipaul
2886 # support for subtitles, additional authors, subject.
2887 # This supports is only for MARC <-> OLD-DB link. It worked previously, but values entered as MARC were not reported to OLD-DB, neither values entered as OLD-DB were reported to MARC.
2888 # Note that some OLD-DB subs are strange (dummy ?) see OLDmodsubject, OLDmodsubtitle, OLDmodaddiauthor in C4/Biblio.pm
2889 # For example it seems impossible to have more that 1 addi author and 1 subtitle. In MARC it's not the case. So, if you enter more than one, I'm afraid only the LAST will be stored.
2891 # Revision 1.45 2003/04/29 16:50:49 tipaul
2892 # really proud of this commit :-)
2893 # z3950 search and import seems to works fine.
2894 # Let me explain how :
2895 # * a "search z3950" button is added in the addbiblio template.
2896 # * when clicked, a popup appears and z3950/search.pl is called
2897 # * z3950/search.pl calls addz3950search in the DB
2898 # * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table.
2899 # * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending.
2900 # * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled
2903 # * character encoding support : (It's a nightmare...) In the z3950servers table, a "encoding" column has been added. You can put "UNIMARC" or "USMARC" in this column. Depending on this, the char_decode in C4::Biblio.pm replaces marc-char-encode by an iso 8859-1 encoding. Note that in the breeding import this value has been added too, for a better support.
2904 # * the marc_breeding and z3950* tables have been modified : they have an encoding column and the random z3950 number is stored too for convenience => it's the key I use to list only requested biblios in the popup.
2906 # Revision 1.44 2003/04/28 13:07:14 tipaul
2907 # Those fixes solves the "internal server error" with MARC::Record 1.12.
2908 # It was due to an illegal contruction in Koha : we tried to retrive subfields from <10 tags.
2909 # That's not possible. MARC::Record accepted this in 0.93 version, but it was fixed after.
2910 # Now, the construct/retrieving is OK !
2912 # Revision 1.43 2003/04/10 13:56:02 tipaul
2914 # * worked in 1.9.0, but not in 1.9.1 :
2915 # - modif of a biblio didn't work
2916 # - empty fields where not shown when modifying a biblio. empty fields managed by the library (ie in tab 0->9 in MARC parameter table) MUST be entered, even if not presented.
2918 # * did not work before :
2919 # - repeatable subfields now works correctly. Enter 2 subfields separated by | and they will be splitted during saving.
2920 # - dropped the last subfield of the MARC form :-(
2922 # Internal changes :
2923 # - MARCmodbiblio now works by deleting and recreating the biblio. It's not perf optimized, but MARC is a "do_something_impossible_to_trace" standard, so, it's the best solution. not a problem for me, as biblio are rarely modified.
2924 # Note the MARCdelbiblio has been rewritted to enable deletion of a biblio WITHOUT deleting items.
2926 # Revision 1.42 2003/04/04 08:41:11 tipaul
2927 # last commits before 1.9.1
2929 # Revision 1.41 2003/04/01 12:26:43 tipaul
2932 # Revision 1.40 2003/03/11 15:14:03 tipaul
2935 # Revision 1.39 2003/03/07 16:35:42 tipaul
2936 # * moving generic functions to Koha.pm
2937 # * improvement of SearchMarc.pm
2941 # Revision 1.38 2003/02/27 16:51:59 tipaul
2942 # * moving prepare / execute to ? form.
2945 # * road to 1.9.2 => acquisition and cataloguing merging
2947 # Revision 1.37 2003/02/12 11:03:03 tipaul
2948 # Support for 000 -> 010 fields.
2949 # Those fields doesn't have subfields.
2950 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
2951 # Note it's only virtual : when rebuilding the MARC::Record, the koha API handle correctly "@" subfields => the resulting MARC record has a 00x field without subfield.
2953 # Revision 1.36 2003/02/12 11:01:01 tipaul
2954 # Support for 000 -> 010 fields.
2955 # Those fields doesn't have subfields.
2956 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
2957 # Note it's only virtual : when rebuilding the MARC::Record, the koha API handle correctly "@" subfields => the resulting MARC record has a 00x field without subfield.
2959 # Revision 1.35 2003/02/03 18:46:00 acli
2960 # Minor factoring in C4/Biblio.pm, plus change to export the per-tag
2961 # 'mandatory' property to a per-subfield 'tag_mandatory' template parameter,
2962 # so that addbiblio.tmpl can distinguish between mandatory subfields in a
2963 # mandatory tag and mandatory subfields in an optional tag
2965 # Not-minor factoring in acqui.simple/addbiblio.pl to make the if-else blocks
2966 # smaller, and to add some POD; need further testing for this
2968 # Added function to check if a MARC subfield name is "koha-internal" (instead
2969 # of checking it for 'lib' and 'tag' everywhere); temporarily added to Koha.pm
2971 # Use above function in acqui.simple/additem.pl and search.marc/search.pl
2973 # Revision 1.34 2003/01/28 14:50:04 tipaul
2974 # fixing MARCmodbiblio API and reindenting code
2976 # Revision 1.33 2003/01/23 12:22:37 tipaul
2977 # adding char_decode to decode MARC21 or UNIMARC extended chars
2979 # Revision 1.32 2002/12/16 15:08:50 tipaul
2980 # small but important bugfix (fixes a problem in export)
2982 # Revision 1.31 2002/12/13 16:22:04 tipaul
2983 # 1st draft of marc export
2985 # Revision 1.30 2002/12/12 21:26:35 tipaul
2986 # YAB ! (Yet Another Bugfix) => related to biblio modif
2987 # (some warning cleaning too)
2989 # Revision 1.29 2002/12/12 16:35:00 tipaul
2990 # adding authentification with Auth.pm and
2991 # MAJOR BUGFIX on marc biblio modification
2993 # Revision 1.28 2002/12/10 13:30:03 tipaul
2994 # fugfixes from Dombes Abbey work
2996 # Revision 1.27 2002/11/19 12:36:16 tipaul
2998 # various bugfixes, improvments, and migration from acquisition.pm to biblio.pm
3000 # Revision 1.26 2002/11/12 15:58:43 tipaul
3003 # * adding value_builder : you can map a subfield in the marc_subfield_structure to a sub stored in "value_builder" directory. In this directory you can create screen used to build values with any method. In this commit is a 1st draft of the builder for 100$a unimarc french subfield, which is composed of 35 digits, with 12 differents values (only the 4th first are provided for instance)
3005 # Revision 1.25 2002/10/25 10:58:26 tipaul
3007 # * bugfixes and improvements
3009 # Revision 1.24 2002/10/24 12:09:01 arensb
3010 # Fixed "no title" warning when generating HTML documentation from POD.
3012 # Revision 1.23 2002/10/16 12:43:08 arensb
3013 # Added some FIXME comments.
3015 # Revision 1.22 2002/10/15 13:39:17 tipaul
3016 # removing Acquisition.pm
3017 # deleting unused code in biblio.pm, rewriting POD and answering most FIXME comments
3019 # Revision 1.21 2002/10/13 11:34:14 arensb
3020 # Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
3021 # Thus, $x = $x+2 becomes $x += 2, and so forth.
3023 # Revision 1.20 2002/10/13 08:28:32 arensb
3024 # Deleted unused variables.
3025 # Removed trailing whitespace.
3027 # Revision 1.19 2002/10/13 05:56:10 arensb
3028 # Added some FIXME comments.
3030 # Revision 1.18 2002/10/11 12:34:53 arensb
3031 # Replaced &requireDBI with C4::Context->dbh
3033 # Revision 1.17 2002/10/10 14:48:25 tipaul
3036 # Revision 1.16 2002/10/07 14:04:26 tipaul
3037 # road to 1.3.1 : viewing MARC biblio
3039 # Revision 1.15 2002/10/05 09:49:25 arensb
3040 # Merged with arensb-context branch: use C4::Context->dbh instead of
3041 # &C4Connect, and generally prefer C4::Context over C4::Database.
3043 # Revision 1.14 2002/10/03 11:28:18 tipaul
3044 # Extending Context.pm to add stopword management and using it in MARC-API.
3045 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
3047 # Revision 1.13 2002/10/02 16:26:44 tipaul
3050 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
3051 # Merged in changes from main branch.
3053 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
3054 # Added a whole mess of FIXME comments.
3056 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
3057 # Added some missing semicolons.
3059 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
3060 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
3063 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
3064 # Added a whole mess of FIXME comments.
3066 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
3067 # Added some missing semicolons.
3069 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
3070 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
3073 # Revision 1.12 2002/10/01 11:48:51 arensb
3074 # Added some FIXME comments, mostly marking duplicate functions.
3076 # Revision 1.11 2002/09/24 13:49:26 tipaul
3077 # long WAS the road to 1.3.0...
3078 # coming VERY SOON NOW...
3079 # modifying installer and buildrelease to update the DB
3081 # Revision 1.10 2002/09/22 16:50:08 arensb
3082 # Added some FIXME comments.
3084 # Revision 1.9 2002/09/20 12:57:46 tipaul
3085 # long is the road to 1.4.0
3086 # * MARCadditem and MARCmoditem now wroks
3087 # * various bugfixes in MARC management
3088 # !!! 1.3.0 should be released very soon now. Be careful !!!
3090 # Revision 1.8 2002/09/10 13:53:52 tipaul
3091 # MARC API continued...
3093 # * multiple item management : MARCadditem and MARCmoditem have been added. They suppose that ALL the MARC field linked to koha-item are in the same MARC tag (on the same line of MARC file)
3095 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
3097 # Revision 1.7 2002/08/14 18:12:51 tonnesen
3098 # Added copyright statement to all .pl and .pm files
3100 # Revision 1.6 2002/07/25 13:40:31 tipaul
3101 # pod documenting the API.
3103 # Revision 1.5 2002/07/24 16:11:37 tipaul
3105 # Database.pm and Output.pm are almost not modified (var test...)
3107 # Biblio.pm is almost completly rewritten.
3109 # WHAT DOES IT ??? ==> END of Hitchcock suspens
3111 # 1st, it does... nothing...
3112 # Every old API should be there. So if MARC-stuff is not done, the behaviour is EXACTLY the same (if there is no added bug, of course). So, if you use normal acquisition, you won't find anything new neither on screen or old-DB tables ...
3114 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
3115 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
3116 # * a "OLDnewbiblio" sub, which is a copy/paste of the previous newbiblio sub. Then, when you want to add the MARC-DB stuff, you can modify the newbiblio sub without modifying the OLDnewbiblio one. If we correct a bug in 1.2 in newbiblio, we can do the same in main branch by correcting OLDnewbiblio.
3117 # * The MARC stuff is usually done through a sub named MARCxxx where xxx is the same as OLDxxx. For example, newbiblio calls MARCnewbiblio. the MARCxxx subs use a MARC::Record as parameter.
3118 # The last thing to solve was to manage biblios through real MARC import : they must populate the old-db, but must populate the MARC-DB too, without loosing information (if we go from MARC::Record to old-data then back to MARC::Record, we loose A LOT OF ROWS). To do this, there are subs beginning by "NEWxxx" : they manage datas with MARC::Record datas. they call OLDxxx sub too (to populate old-DB), but MARCxxx subs too, with a complete MARC::Record ;-)
3120 # In Biblio.pm, there are some subs that permits to build a old-style record from a MARC::Record, and the opposite. There is also a sub finding a MARC-bibid from a old-biblionumber and the opposite too.
3121 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.