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
74 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
77 # all the following subs takes a MARC::Record as parameter and manage
78 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
79 # NEWxxx subs (xxx deals with old-DB parameters, the NEWxxx deals with MARC-DB parameter)
83 C4::Biblio - acquisition, catalog management functions
87 move from 1.2 to 1.4 version :
88 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
89 In the 1.4 version, we want to do 2 differents things :
90 - keep populating the old-DB, that has a LOT less datas than MARC
91 - populate the MARC-DB
92 To populate the DBs we have 2 differents sources :
93 - the standard acquisition system (through book sellers), that does'nt use MARC data
94 - the MARC acquisition system, that uses MARC data.
96 Thus, we have 2 differents cases :
97 - 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
98 - 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
100 That's why we need 4 subs :
101 all I<subs beginning by MARC> manage only MARC tables. They manage MARC-DB with MARC::Record parameters
102 all I<subs beginning by OLD> manage only OLD-DB tables. They manage old-DB with old-DB parameters
103 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
104 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.
106 - NEW and old-style API should be used in koha to manage biblio
107 - MARCsubs are divided in 2 parts :
108 * some of them manage MARC parameters. They are heavily used in koha.
109 * some of them manage MARC biblio : they are mostly used by NEW and old-style subs.
110 - OLD are used internally only
112 all subs requires/use $dbh as 1st parameter.
114 I<NEWxxx related subs>
116 all subs requires/use $dbh as 1st parameter.
117 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
119 I<OLDxxx related subs>
121 all subs requires/use $dbh as 1st parameter.
122 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
124 They all are the exact copy of 1.0/1.2 version of the sub without the OLD.
125 The OLDxxx is called by the original xxx sub.
126 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
128 WARNING : there is 1 difference between initialxxx and OLDxxx :
129 the db header $dbh is always passed as parameter to avoid over-DB connexion
135 =item @tagslib = &MARCgettagslib($dbh,1|0,$itemtype);
137 last param is 1 for liblibrarian and 0 for libopac
138 $itemtype contains the itemtype framework reference. If empty or does not exist, the default one is used
139 returns a hash with tag/subfield meaning
140 =item ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,$kohafield);
142 finds MARC tag and subfield for a given kohafield
143 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
145 =item $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
147 finds a old-db biblio number for a given MARCbibid number
149 =item $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
151 finds a MARC bibid from a old-db biblionumber
153 =item $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
155 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
157 =item $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
159 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
161 =item $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
163 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
165 =item $olddb = &MARCmarc2koha($dbh,$MARCRecord);
167 builds a hash with old-db datas from a MARC::Record
169 =item &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
171 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
173 =item &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
175 adds a subfield in a biblio (in the MARC tables only).
177 =item $MARCRecord = &MARCgetbiblio($dbh,$bibid);
179 Returns a MARC::Record for the biblio $bibid.
181 =item &MARCmodbiblio($dbh,$bibid,$record,$delete);
183 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
184 It 1st delete the biblio, then recreates it.
185 WARNING : the $delete parameter is not used anymore (too much unsolvable cases).
186 =item ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
188 MARCmodsubfield changes the value of a given subfield
190 =item $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
192 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
193 Returns -1 if more than 1 answer
195 =item $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
197 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
199 =item &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
201 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
203 =item &MARCdelbiblio($dbh,$bibid);
205 MARCdelbiblio delete biblio $bibid
207 =item &MARCkoha2marcOnefield
209 used by MARCkoha2marc and should not be useful elsewhere
211 =item &MARCmarc2kohaOnefield
213 used by MARCmarc2koha and should not be useful elsewhere
217 used to manage MARC_word table and should not be useful elsewhere
221 used to manage MARC_word table and should not be useful elsewhere
226 my ( $dbh, $forlibrarian, $frameworkcode ) = @_;
227 $frameworkcode = "" unless $frameworkcode;
229 my $libfield = ( $forlibrarian eq 1 ) ? 'liblibrarian' : 'libopac';
231 # check that framework exists
234 "select count(*) from marc_tag_structure where frameworkcode=?");
235 $sth->execute($frameworkcode);
236 my ($total) = $sth->fetchrow;
237 $frameworkcode = "" unless ( $total > 0 );
240 "select tagfield,$libfield as lib,mandatory,repeatable from marc_tag_structure where frameworkcode=? order by tagfield"
242 $sth->execute($frameworkcode);
243 my ( $lib, $tag, $res, $tab, $mandatory, $repeatable );
245 while ( ( $tag, $lib, $mandatory, $repeatable ) = $sth->fetchrow ) {
246 $res->{$tag}->{lib} = $lib;
247 $res->{$tab}->{tab} = ""; # XXX
248 $res->{$tag}->{mandatory} = $mandatory;
249 $res->{$tag}->{repeatable} = $repeatable;
254 "select tagfield,tagsubfield,$libfield as lib,tab, mandatory, repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl from marc_subfield_structure where frameworkcode=? order by tagfield,tagsubfield"
256 $sth->execute($frameworkcode);
259 my $authorised_value;
268 ( $tag, $subfield, $lib, $tab,
269 $mandatory, $repeatable, $authorised_value, $authtypecode,
270 $value_builder, $kohafield, $seealso, $hidden,
275 $res->{$tag}->{$subfield}->{lib} = $lib;
276 $res->{$tag}->{$subfield}->{tab} = $tab;
277 $res->{$tag}->{$subfield}->{mandatory} = $mandatory;
278 $res->{$tag}->{$subfield}->{repeatable} = $repeatable;
279 $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
280 $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode;
281 $res->{$tag}->{$subfield}->{value_builder} = $value_builder;
282 $res->{$tag}->{$subfield}->{kohafield} = $kohafield;
283 $res->{$tag}->{$subfield}->{seealso} = $seealso;
284 $res->{$tag}->{$subfield}->{hidden} = $hidden;
285 $res->{$tag}->{$subfield}->{isurl} = $isurl;
290 sub MARCfind_marc_from_kohafield {
291 my ( $dbh, $kohafield ) = @_;
292 return 0, 0 unless $kohafield;
295 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
297 $sth->execute($kohafield);
298 my ( $tagfield, $tagsubfield ) = $sth->fetchrow;
299 return ( $tagfield, $tagsubfield );
302 sub MARCfind_oldbiblionumber_from_MARCbibid {
303 my ( $dbh, $MARCbibid ) = @_;
305 $dbh->prepare("select biblionumber from marc_biblio where bibid=?");
306 $sth->execute($MARCbibid);
307 my ($biblionumber) = $sth->fetchrow;
308 return $biblionumber;
311 sub MARCfind_MARCbibid_from_oldbiblionumber {
312 my ( $dbh, $oldbiblionumber ) = @_;
314 $dbh->prepare("select bibid from marc_biblio where biblionumber=?");
315 $sth->execute($oldbiblionumber);
316 my ($bibid) = $sth->fetchrow;
322 # pass the MARC::Record to this function, and it will create the records in the marc tables
323 my ( $dbh, $record, $biblionumber, $frameworkcode, $bibid ) = @_;
324 my @fields = $record->fields();
326 # warn "IN MARCaddbiblio $bibid => ".$record->as_formatted;
328 # adding main table, and retrieving bibid
329 # if bibid is sent, then it's not a true add, it's only a re-add, after a delete (ie, a mod)
330 # if bibid empty => true add, find a new bibid number
333 "lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ"
337 "insert into marc_biblio (datecreated,biblionumber,frameworkcode) values (now(),?,?)"
339 $sth->execute( $biblionumber, $frameworkcode );
340 $sth = $dbh->prepare("select max(bibid) from marc_biblio");
342 ($bibid) = $sth->fetchrow;
347 # now, add subfields...
348 foreach my $field (@fields) {
350 if ( $field->tag() < 10 ) {
351 &MARCaddsubfield( $dbh, $bibid, $field->tag(), '', $fieldcount, '',
355 my @subfields = $field->subfields();
356 foreach my $subfieldcount ( 0 .. $#subfields ) {
361 $field->indicator(1) . $field->indicator(2),
363 $subfields[$subfieldcount][0],
365 $subfields[$subfieldcount][1]
370 $dbh->do("unlock tables");
376 # pass the MARC::Record to this function, and it will create the records in the marc tables
377 my ( $dbh, $record, $biblionumber ) = @_;
379 # warn "adding : ".$record->as_formatted();
380 # search for MARC biblionumber
382 "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();
388 "select max(tagorder) from marc_subfield_table where bibid=?");
389 $sth->execute($bibid);
390 my ($fieldcount) = $sth->fetchrow;
392 # now, add subfields...
393 foreach my $field (@fields) {
394 my @subfields = $field->subfields();
396 foreach my $subfieldcount ( 0 .. $#subfields ) {
401 $field->indicator(1) . $field->indicator(2),
403 $subfields[$subfieldcount][0],
405 $subfields[$subfieldcount][1]
409 $dbh->do("unlock tables");
413 sub MARCaddsubfield {
415 # Add a new subfield to a tag into the DB.
417 $dbh, $bibid, $tagid, $tag_indicator,
418 $tagorder, $subfieldcode, $subfieldorder, $subfieldvalues
422 # if not value, end of job, we do nothing
423 if ( length($subfieldvalues) == 0 ) {
426 if ( not($subfieldcode) ) {
429 my @subfieldvalues = split /\|/, $subfieldvalues;
430 foreach my $subfieldvalue (@subfieldvalues) {
431 if ( length($subfieldvalue) > 255 ) {
433 "lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE"
437 "insert into marc_blob_subfield (subfieldvalue) values (?)");
438 $sth->execute($subfieldvalue);
440 $dbh->prepare("select max(blobidlink)from marc_blob_subfield");
442 my ($res) = $sth->fetchrow;
445 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?,?)"
447 $sth->execute( $bibid, ( sprintf "%03s", $tagid ), $tagorder,
448 $tag_indicator, $subfieldcode, $subfieldorder, $res );
450 if ( $sth->errstr ) {
452 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
454 $dbh->do("unlock tables");
459 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)"
462 $bibid, ( sprintf "%03s", $tagid ),
463 $tagorder, $tag_indicator,
464 $subfieldcode, $subfieldorder,
467 if ( $sth->errstr ) {
469 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
473 $dbh, $bibid, $tagid, $tagorder,
474 $subfieldcode, $subfieldorder, $subfieldvalue
481 # Returns MARC::Record of the biblio passed in parameter.
482 my ( $dbh, $bibid ) = @_;
483 my $record = MARC::Record->new();
485 #---- TODO : the leader is missing
486 $record->leader(' ');
489 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
490 from marc_subfield_table
491 where bibid=? order by tag,tagorder,subfieldcode
496 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
497 $sth->execute($bibid);
498 my $prevtagorder = 1;
501 my $field; # for >=10 tags
502 my $prevvalue; # for <10 tags
503 while ( my $row = $sth->fetchrow_hashref ) {
505 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
506 $sth2->execute( $row->{'valuebloblink'} );
507 my $row2 = $sth2->fetchrow_hashref;
509 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
511 if ( $row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag ) {
512 $previndicator .= " ";
513 if ( $prevtag < 10 ) {
514 $record->add_fields( ( sprintf "%03s", $prevtag ), $prevvalue )
515 unless $prevtag eq "XXX"; # ignore the 1st loop
518 $record->add_fields($field) unless $prevtag eq "XXX";
521 $prevtagorder = $row->{tagorder};
522 $prevtag = $row->{tag};
523 $previndicator = $row->{tag_indicator};
524 if ( $row->{tag} < 10 ) {
525 $prevvalue = $row->{subfieldvalue};
528 $field = MARC::Field->new(
529 ( sprintf "%03s", $prevtag ),
530 substr( $row->{tag_indicator} . ' ', 0, 1 ),
531 substr( $row->{tag_indicator} . ' ', 1, 1 ),
532 $row->{'subfieldcode'},
533 $row->{'subfieldvalue'}
538 if ( $row->{tag} < 10 ) {
539 $record->add_fields( ( sprintf "%03s", $row->{tag} ),
540 $row->{'subfieldvalue'} );
543 $field->add_subfields( $row->{'subfieldcode'},
544 $row->{'subfieldvalue'} );
546 $prevtag = $row->{tag};
547 $previndicator = $row->{tag_indicator};
551 # the last has not been included inside the loop... do it now !
552 if ( $prevtag ne "XXX" )
553 { # check that we have found something. Otherwise, prevtag is still XXX and we
554 # must return an empty record, not make MARC::Record fail because we try to
555 # create a record with XXX as field :-(
556 if ( $prevtag < 10 ) {
557 $record->add_fields( $prevtag, $prevvalue );
561 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
562 $record->add_fields($field);
570 # Returns MARC::Record of the biblio passed in parameter.
571 my ( $dbh, $bibid, $itemnumber ) = @_;
572 my $record = MARC::Record->new();
574 # search MARC tagorder
577 "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=?"
579 $sth2->execute( $bibid, $itemnumber );
580 my ($tagorder) = $sth2->fetchrow_array();
582 #---- TODO : the leader is missing
585 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
586 from marc_subfield_table
587 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
592 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
593 $sth->execute( $bibid, $tagorder );
594 while ( my $row = $sth->fetchrow_hashref ) {
595 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
596 $sth2->execute( $row->{'valuebloblink'} );
597 my $row2 = $sth2->fetchrow_hashref;
599 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
601 if ( $record->field( $row->{'tag'} ) ) {
604 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
605 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
606 if ( length( $row->{'tag'} ) < 3 ) {
607 $row->{'tag'} = "0" . $row->{'tag'};
609 $field = $record->field( $row->{'tag'} );
612 $field->add_subfields( $row->{'subfieldcode'},
613 $row->{'subfieldvalue'} );
614 $record->delete_field($field);
615 $record->add_fields($field);
619 if ( length( $row->{'tag'} ) < 3 ) {
620 $row->{'tag'} = "0" . $row->{'tag'};
623 MARC::Field->new( $row->{'tag'}, " ", " ",
624 $row->{'subfieldcode'} => $row->{'subfieldvalue'} );
625 $record->add_fields($temp);
633 my ( $dbh, $bibid, $record, $delete ) = @_;
634 my $oldrecord = &MARCgetbiblio( $dbh, $bibid );
635 if ( $oldrecord eq $record ) {
639 # 1st delete the biblio,
641 my $biblionumber = MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
642 &MARCdelbiblio( $dbh, $bibid, 1 );
643 &MARCaddbiblio( $dbh, $record, $biblionumber, $bibid );
647 my ( $dbh, $bibid, $keep_items ) = @_;
649 # if the keep_item is set to 1, then all items are preserved.
650 # This flag is set when the delbiblio is called by modbiblio
651 # due to a too complex structure of MARC (repeatable fields and subfields),
652 # the best solution for a modif is to delete / recreate the record.
654 # 1st of all, copy the MARC::Record to deletedbiblio table => if a true deletion, MARC data will be kept.
655 # if deletion called before MARCmodbiblio => won't do anything, as the oldbiblionumber doesn't
656 # exist in deletedbiblio table
657 my $record = MARCgetbiblio( $dbh, $bibid );
658 my $oldbiblionumber =
659 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
661 $dbh->prepare("update deletedbiblio set marc=? where biblionumber=?");
662 $copy2deleted->execute( $record->as_usmarc(), $oldbiblionumber );
664 # now, delete in MARC tables.
665 if ( $keep_items eq 1 ) {
667 #search item field code
670 "select tagfield from marc_subfield_structure where kohafield like 'items.%'"
673 my $itemtag = $sth->fetchrow_hashref->{tagfield};
675 "delete from marc_subfield_table where bibid=$bibid and tag<>$itemtag"
678 "delete from marc_word where bibid=$bibid and not (tagsubfield like \"$itemtag%\")"
682 $dbh->do("delete from marc_biblio where bibid=$bibid");
683 $dbh->do("delete from marc_subfield_table where bibid=$bibid");
684 $dbh->do("delete from marc_word where bibid=$bibid");
690 # delete the item passed in parameter in MARC tables.
691 my ( $dbh, $bibid, $itemnumber ) = @_;
693 # my $record = MARC::Record->new();
694 # search MARC tagorder
695 my $record = MARCgetitem( $dbh, $bibid, $itemnumber );
697 $dbh->prepare("update deleteditems set marc=? where itemnumber=?");
698 $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
702 "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=?"
704 $sth2->execute( $bibid, $itemnumber );
705 my ($tagorder) = $sth2->fetchrow_array();
708 "delete from marc_subfield_table where bibid=? and tagorder=?");
709 $sth->execute( $bibid, $tagorder );
713 my ( $dbh, $record, $bibid, $itemnumber, $delete ) = @_;
714 my $oldrecord = &MARCgetitem( $dbh, $bibid, $itemnumber );
716 # if nothing to change, don't waste time...
717 if ( $oldrecord eq $record ) {
721 # otherwise, skip through each subfield...
722 my @fields = $record->fields();
724 # search old MARC item
727 "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=?"
729 $sth2->execute( $bibid, $itemnumber );
730 my ($tagorder) = $sth2->fetchrow_array();
731 foreach my $field (@fields) {
732 my $oldfield = $oldrecord->field( $field->tag() );
733 my @subfields = $field->subfields();
734 my $subfieldorder = 0;
735 foreach my $subfield (@subfields) {
738 # warn "compare : $oldfield".$oldfield->subfield(@$subfield[0]);
740 or ( length( $oldfield->subfield( @$subfield[0] ) ) == 0 ) )
743 # just adding datas...
744 # warn "addfield : / $subfieldorder / @$subfield[0] - @$subfield[1]";
745 # warn "NEW subfield : $bibid,".$field->tag().",".$tagorder.",".@$subfield[0].",".$subfieldorder.",".@$subfield[1].")";
750 $field->indicator(1) . $field->indicator(2),
759 # warn "modfield : / $subfieldorder / @$subfield[0] - @$subfield[1]";
760 # modify he subfield if it's a different string
761 if ( $oldfield->subfield( @$subfield[0] ) ne @$subfield[1] ) {
762 my $subfieldid = &MARCfindsubfieldid(
764 $field->tag(), $tagorder,
765 @$subfield[0], $subfieldorder
768 # warn "changing : $subfieldid, $bibid,".$field->tag(),",$tagorder,@$subfield[0],@$subfield[1],$subfieldorder";
769 &MARCmodsubfield( $dbh, $subfieldid, @$subfield[1] );
776 sub MARCmodsubfield {
778 # Subroutine changes a subfield value given a subfieldid.
779 my ( $dbh, $subfieldid, $subfieldvalue ) = @_;
780 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
783 "select valuebloblink from marc_subfield_table where subfieldid=?");
784 $sth1->execute($subfieldid);
785 my ($oldvaluebloblink) = $sth1->fetchrow;
789 # if too long, use a bloblink
790 if ( length($subfieldvalue) > 255 ) {
792 # if already a bloblink, update it, otherwise, insert a new one.
793 if ($oldvaluebloblink) {
796 "update marc_blob_subfield set subfieldvalue=? where blobidlink=?"
798 $sth->execute( $subfieldvalue, $oldvaluebloblink );
803 "insert into marc_blob_subfield (subfieldvalue) values (?)");
804 $sth->execute($subfieldvalue);
806 $dbh->prepare("select max(blobidlink) from marc_blob_subfield");
808 my ($res) = $sth->fetchrow;
811 "update marc_subfield_table set subfieldvalue=null, valuebloblink=? where subfieldid=?"
813 $sth->execute( $res, $subfieldid );
818 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
821 "update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?"
823 $sth->execute( $subfieldvalue, $subfieldid );
825 $dbh->do("unlock tables");
829 "select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?"
831 $sth->execute($subfieldid);
832 my ( $bibid, $tagid, $tagorder, $subfieldcode, $x, $subfieldorder ) =
835 &MARCdelword( $dbh, $bibid, $tagid, $tagorder, $subfieldcode,
838 $dbh, $bibid, $tagid, $tagorder,
839 $subfieldcode, $subfieldorder, $subfieldvalue
841 return ( $subfieldid, $subfieldvalue );
844 sub MARCfindsubfield {
845 my ( $dbh, $bibid, $tag, $subfieldcode, $subfieldorder, $subfieldvalue ) =
847 my $resultcounter = 0;
851 "select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
852 my @bind_values = ( $bibid, $tag, $subfieldcode );
853 if ($subfieldvalue) {
854 $query .= " and subfieldvalue=?";
855 push ( @bind_values, $subfieldvalue );
858 if ( $subfieldorder < 1 ) {
861 $query .= " and subfieldorder=?";
862 push ( @bind_values, $subfieldorder );
864 my $sti = $dbh->prepare($query);
865 $sti->execute(@bind_values);
866 while ( ($subfieldid) = $sti->fetchrow ) {
868 $lastsubfieldid = $subfieldid;
870 if ( $resultcounter > 1 ) {
872 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
873 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
877 return $lastsubfieldid;
881 sub MARCfindsubfieldid {
882 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
883 my $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
884 where bibid=? and tag=? and tagorder=?
885 and subfieldcode=? and subfieldorder=?"
887 $sth->execute( $bibid, $tag, $tagorder, $subfield, $subfieldorder );
888 my ($res) = $sth->fetchrow;
890 $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
891 where bibid=? and tag=? and tagorder=?
894 $sth->execute( $bibid, $tag, $tagorder, $subfield );
895 ($res) = $sth->fetchrow;
900 sub MARCfind_frameworkcode {
901 my ( $dbh, $bibid ) = @_;
903 $dbh->prepare("select frameworkcode from marc_biblio where bibid=?");
904 $sth->execute($bibid);
905 my ($frameworkcode) = $sth->fetchrow;
906 return $frameworkcode;
909 sub MARCdelsubfield {
911 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
912 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
913 $dbh->do( "delete from marc_subfield_table where bibid='$bibid' and
914 tag='$tag' and tagorder='$tagorder'
915 and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
920 sub MARCkoha2marcBiblio {
922 # this function builds partial MARC::Record from the old koha-DB fields
923 my ( $dbh, $biblionumber, $biblioitemnumber ) = @_;
926 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
928 my $record = MARC::Record->new();
930 #--- if bibid, then retrieve old-style koha data
931 if ( $biblionumber > 0 ) {
934 "select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
935 from biblio where biblionumber=?"
937 $sth2->execute($biblionumber);
938 my $row = $sth2->fetchrow_hashref;
940 foreach $code ( keys %$row ) {
941 if ( $row->{$code} ) {
942 &MARCkoha2marcOnefield( $sth, $record, "biblio." . $code,
948 #--- if biblioitem, then retrieve old-style koha data
949 if ( $biblioitemnumber > 0 ) {
952 " SELECT biblioitemnumber,biblionumber,volume,number,classification,
953 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
954 volumedate,volumeddesc,timestamp,illus,pages,notes AS bnotes,size,place
956 WHERE biblioitemnumber=?
959 $sth2->execute($biblioitemnumber);
960 my $row = $sth2->fetchrow_hashref;
962 foreach $code ( keys %$row ) {
963 if ( $row->{$code} ) {
964 &MARCkoha2marcOnefield( $sth, $record, "biblioitems." . $code,
970 # other fields => additional authors, subjects, subtitles
973 " SELECT author FROM additionalauthors WHERE biblionumber=?");
974 $sth2->execute($biblionumber);
975 while ( my $row = $sth2->fetchrow_hashref ) {
976 &MARCkoha2marcOnefield( $sth, $record, "additionalauthors.author",
980 $dbh->prepare(" SELECT subject FROM bibliosubject WHERE biblionumber=?");
981 $sth2->execute($biblionumber);
982 while ( my $row = $sth2->fetchrow_hashref ) {
983 &MARCkoha2marcOnefield( $sth, $record, "bibliosubject.subject",
988 " SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?");
989 $sth2->execute($biblionumber);
990 while ( my $row = $sth2->fetchrow_hashref ) {
991 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.title",
992 $row->{'subtitle'} );
997 sub MARCkoha2marcItem {
999 # this function builds partial MARC::Record from the old koha-DB fields
1000 my ( $dbh, $biblionumber, $itemnumber ) = @_;
1002 # my $dbh=&C4Connect;
1005 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
1007 my $record = MARC::Record->new();
1009 #--- if item, then retrieve old-style koha data
1010 if ( $itemnumber > 0 ) {
1012 # print STDERR "prepare $biblionumber,$itemnumber\n";
1015 "SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
1016 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
1017 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,itemcallnumber,issues,renewals,
1018 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
1022 $sth2->execute($itemnumber);
1023 my $row = $sth2->fetchrow_hashref;
1025 foreach $code ( keys %$row ) {
1026 if ( $row->{$code} ) {
1027 &MARCkoha2marcOnefield( $sth, $record, "items." . $code,
1035 sub MARCkoha2marcSubtitle {
1037 # this function builds partial MARC::Record from the old koha-DB fields
1038 my ( $dbh, $bibnum, $subtitle ) = @_;
1041 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
1043 my $record = MARC::Record->new();
1044 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle",
1049 sub MARCkoha2marcOnefield {
1050 my ( $sth, $record, $kohafieldname, $value ) = @_;
1053 $sth->execute($kohafieldname);
1054 if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
1055 if ( $record->field($tagfield) ) {
1056 my $tag = $record->field($tagfield);
1058 $tag->add_subfields( $tagsubfield, $value );
1059 $record->delete_field($tag);
1060 $record->add_fields($tag);
1064 $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
1071 my ( $dbh, $rtags, $rsubfields, $rvalues, %indicators ) = @_;
1073 my $record = MARC::Record->new();
1075 # my %subfieldlist=();
1076 my $prevvalue; # if tag <10
1077 my $field; # if tag >=10
1078 for ( my $i = 0 ; $i < @$rtags ; $i++ ) {
1080 # rebuild MARC::Record
1081 if ( @$rtags[$i] ne $prevtag ) {
1082 if ( $prevtag < 10 ) {
1084 $record->add_fields( ( sprintf "%03s", $prevtag ),
1090 $record->add_fields($field);
1093 $indicators{ @$rtags[$i] } .= ' ';
1094 if ( @$rtags[$i] < 10 ) {
1095 $prevvalue = @$rvalues[$i];
1098 $field = MARC::Field->new(
1099 ( sprintf "%03s", @$rtags[$i] ),
1100 substr( $indicators{ @$rtags[$i] }, 0, 1 ),
1101 substr( $indicators{ @$rtags[$i] }, 1, 1 ),
1102 @$rsubfields[$i] => @$rvalues[$i]
1105 $prevtag = @$rtags[$i];
1108 if ( @$rtags[$i] < 10 ) {
1109 $prevvalue = @$rvalues[$i];
1112 if ( @$rvalues[$i] ) {
1113 $field->add_subfields( @$rsubfields[$i] => @$rvalues[$i] );
1116 $prevtag = @$rtags[$i];
1120 # the last has not been included inside the loop... do it now !
1121 $record->add_fields($field);
1123 # warn $record->as_formatted;
1128 my ( $dbh, $record ) = @_;
1131 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
1134 my $sth2 = $dbh->prepare("SHOW COLUMNS from biblio");
1138 # print STDERR $record->as_formatted;
1139 while ( ($field) = $sth2->fetchrow ) {
1141 &MARCmarc2kohaOneField( $sth, "biblio", $field, $record, $result );
1143 $sth2 = $dbh->prepare("SHOW COLUMNS from biblioitems");
1145 while ( ($field) = $sth2->fetchrow ) {
1146 if ( $field eq 'notes' ) { $field = 'bnotes'; }
1148 &MARCmarc2kohaOneField( $sth, "biblioitems", $field, $record,
1151 $sth2 = $dbh->prepare("SHOW COLUMNS from items");
1153 while ( ($field) = $sth2->fetchrow ) {
1155 &MARCmarc2kohaOneField( $sth, "items", $field, $record, $result );
1158 # additional authors : specific
1160 &MARCmarc2kohaOneField( $sth, "bibliosubtitle", "subtitle", $record,
1163 &MARCmarc2kohaOneField( $sth, "additionalauthors", "additionalauthors",
1166 # modify copyrightdate to keep only the 1st year found
1167 my $temp = $result->{'copyrightdate'};
1168 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1170 $result->{'copyrightdate'} = $1;
1172 else { # if no cYYYY, get the 1st date.
1173 $temp =~ m/(\d\d\d\d)/;
1174 $result->{'copyrightdate'} = $1;
1177 # modify publicationyear to keep only the 1st year found
1178 my $temp = $result->{'publicationyear'};
1179 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1181 $result->{'publicationyear'} = $1;
1183 else { # if no cYYYY, get the 1st date.
1184 $temp =~ m/(\d\d\d\d)/;
1185 $result->{'publicationyear'} = $1;
1190 sub MARCmarc2kohaOneField {
1192 # FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
1193 my ( $sth, $kohatable, $kohafield, $record, $result ) = @_;
1195 # warn "kohatable / $kohafield / $result / ";
1199 $sth->execute( $kohatable . "." . $kohafield );
1200 ( $tagfield, $subfield ) = $sth->fetchrow;
1201 foreach my $field ( $record->field($tagfield) ) {
1202 if ( $field->subfield($subfield) ) {
1203 if ( $result->{$kohafield} ) {
1204 $result->{$kohafield} .= " | " . $field->subfield($subfield);
1207 $result->{$kohafield} = $field->subfield($subfield);
1216 # split a subfield string and adds it into the word table.
1219 $dbh, $bibid, $tag, $tagorder,
1220 $subfieldid, $subfieldorder, $sentence
1223 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\})/ /g;
1224 my @words = split / /, $sentence;
1225 my $stopwords = C4::Context->stopwords;
1228 "insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word)
1229 values (?,concat(?,?),?,?,?,soundex(?))"
1231 foreach my $word (@words) {
1233 # we record only words one char long and not in stopwords hash
1234 if ( length($word) >= 1 and !( $stopwords->{ uc($word) } ) ) {
1236 $bibid, $tag, $tagorder, $subfieldid,
1237 $subfieldorder, $word, $word
1239 if ( $sth->err() ) {
1241 "ERROR ==> insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word) values ($bibid,concat($tag,$subfieldid),$tagorder,$subfieldorder,$word,soundex($word))\n";
1249 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
1250 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
1253 "delete from marc_word where bibid=? and tagsubfield=concat(?,?) and tagorder=? and subfieldorder=?"
1255 $sth->execute( $bibid, $tag, $subfield, $tagorder, $subfieldorder );
1260 # NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW
1263 # all the following subs are useful to manage MARC-DB with complete MARC records.
1264 # it's used with marcimport, and marc management tools
1267 =item ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
1269 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
1270 are builded from the MARC::Record. If they are passed, they are used.
1272 =item NEWnewitem($dbh, $record,$bibid);
1274 adds an item in the db.
1279 my ( $dbh, $record, $frameworkcode ) = @_;
1282 my $olddata = MARCmarc2koha( $dbh, $record );
1283 $oldbibnum = OLDnewbiblio( $dbh, $olddata );
1284 $olddata->{'biblionumber'} = $oldbibnum;
1285 $oldbibitemnum = OLDnewbiblioitem( $dbh, $olddata );
1287 # search subtiles, addiauthors and subjects
1288 my ( $tagfield, $tagsubfield ) =
1289 MARCfind_marc_from_kohafield( $dbh, "additionalauthors.author" );
1290 my @addiauthfields = $record->field($tagfield);
1291 foreach my $addiauthfield (@addiauthfields) {
1292 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1293 foreach my $subfieldcount ( 0 .. $#addiauthsubfields ) {
1294 OLDmodaddauthor( $dbh, $oldbibnum,
1295 $addiauthsubfields[$subfieldcount] );
1298 ( $tagfield, $tagsubfield ) =
1299 MARCfind_marc_from_kohafield( $dbh, "bibliosubtitle.title" );
1300 my @subtitlefields = $record->field($tagfield);
1301 foreach my $subtitlefield (@subtitlefields) {
1302 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1303 foreach my $subfieldcount ( 0 .. $#subtitlesubfields ) {
1304 OLDnewsubtitle( $dbh, $oldbibnum,
1305 $subtitlesubfields[$subfieldcount] );
1308 ( $tagfield, $tagsubfield ) =
1309 MARCfind_marc_from_kohafield( $dbh, "bibliosubject.subject" );
1310 my @subj = $record->field($tagfield);
1312 foreach my $subject (@subj) {
1313 my @subjsubfield = $subject->subfield($tagsubfield);
1314 foreach my $subfieldcount ( 0 .. $#subjsubfield ) {
1315 push @subjects, $subjsubfield[$subfieldcount];
1318 OLDmodsubject( $dbh, $oldbibnum, 1, @subjects );
1320 # we must add bibnum and bibitemnum in MARC::Record...
1321 # we build the new field with biblionumber and biblioitemnumber
1322 # we drop the original field
1323 # we add the new builded field.
1324 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
1325 # (steve and paul : thinks 090 is a good choice)
1328 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
1330 $sth->execute("biblio.biblionumber");
1331 ( my $tagfield1, my $tagsubfield1 ) = $sth->fetchrow;
1332 $sth->execute("biblioitems.biblioitemnumber");
1333 ( my $tagfield2, my $tagsubfield2 ) = $sth->fetchrow;
1334 if ( $tagfield1 != $tagfield2 ) {
1336 "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1338 "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1341 my $newfield = MARC::Field->new(
1342 $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
1343 "$tagsubfield2" => $oldbibitemnum
1346 # drop old field and create new one...
1347 my $old_field = $record->field($tagfield1);
1348 $record->delete_field($old_field);
1349 $record->add_fields($newfield);
1350 my $bibid = MARCaddbiblio( $dbh, $record, $oldbibnum, $frameworkcode );
1351 return ( $bibid, $oldbibnum, $oldbibitemnum );
1355 my ( $dbh, $record, $bibid, $frameworkcode ) = @_;
1356 $frameworkcode = "" unless $frameworkcode;
1357 &MARCmodbiblio( $dbh, $bibid, $record, 0 );
1358 my $oldbiblio = MARCmarc2koha( $dbh, $record );
1359 my $oldbiblionumber = OLDmodbiblio( $dbh, $oldbiblio );
1360 OLDmodbibitem( $dbh, $oldbiblio );
1362 # now, modify addi authors, subject, addititles.
1363 my ( $tagfield, $tagsubfield ) =
1364 MARCfind_marc_from_kohafield( $dbh, "additionalauthors.author" );
1365 my @addiauthfields = $record->field($tagfield);
1366 foreach my $addiauthfield (@addiauthfields) {
1367 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1368 foreach my $subfieldcount ( 0 .. $#addiauthsubfields ) {
1369 OLDmodaddauthor( $dbh, $oldbiblionumber,
1370 $addiauthsubfields[$subfieldcount] );
1373 ( $tagfield, $tagsubfield ) =
1374 MARCfind_marc_from_kohafield( $dbh, "bibliosubtitle.subtitle" );
1375 my @subtitlefields = $record->field($tagfield);
1376 foreach my $subtitlefield (@subtitlefields) {
1377 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1378 foreach my $subfieldcount ( 0 .. $#subtitlesubfields ) {
1379 OLDmodsubtitle( $dbh, $oldbiblionumber,
1380 $subtitlesubfields[$subfieldcount] );
1383 ( $tagfield, $tagsubfield ) =
1384 MARCfind_marc_from_kohafield( $dbh, "bibliosubject.subject" );
1385 my @subj = $record->field($tagfield);
1387 foreach my $subject (@subj) {
1388 my @subjsubfield = $subject->subfield($tagsubfield);
1389 foreach my $subfieldcount ( 0 .. $#subjsubfield ) {
1390 push @subjects, $subjsubfield[$subfieldcount];
1393 OLDmodsubject( $dbh, $oldbiblionumber, 1, @subjects );
1398 my ( $dbh, $bibid ) = @_;
1399 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1400 &OLDdelbiblio( $dbh, $biblio );
1403 "select biblioitemnumber from biblioitems where biblionumber=?");
1404 $sth->execute($biblio);
1405 while ( my ($biblioitemnumber) = $sth->fetchrow ) {
1406 OLDdeletebiblioitem( $dbh, $biblioitemnumber );
1408 &MARCdelbiblio( $dbh, $bibid, 0 );
1412 my ( $dbh, $record, $bibid ) = @_;
1414 # add item in old-DB
1415 my $item = &MARCmarc2koha( $dbh, $record );
1417 # needs old biblionumber and biblioitemnumber
1418 $item->{'biblionumber'} =
1419 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1422 "select biblioitemnumber from biblioitems where biblionumber=?");
1423 $sth->execute( $item->{'biblionumber'} );
1424 ( $item->{'biblioitemnumber'} ) = $sth->fetchrow;
1425 my ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, $item->{barcode} );
1427 # add itemnumber to MARC::Record before adding the item.
1430 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
1432 &MARCkoha2marcOnefield( $sth, $record, "items.itemnumber", $itemnumber );
1435 my $bib = &MARCadditem( $dbh, $record, $item->{'biblionumber'} );
1439 my ( $dbh, $record, $bibid, $itemnumber, $delete ) = @_;
1440 &MARCmoditem( $dbh, $record, $bibid, $itemnumber, $delete );
1441 my $olditem = MARCmarc2koha( $dbh, $record );
1442 OLDmoditem( $dbh, $olditem );
1446 my ( $dbh, $bibid, $itemnumber ) = @_;
1447 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1448 &OLDdelitem( $dbh, $itemnumber );
1449 &MARCdelitem( $dbh, $bibid, $itemnumber );
1454 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
1458 =item $biblionumber = OLDnewbiblio($dbh,$biblio);
1460 adds a record in biblio table. Datas are in the hash $biblio.
1462 =item $biblionumber = OLDmodbiblio($dbh,$biblio);
1464 modify a record in biblio table. Datas are in the hash $biblio.
1466 =item OLDmodsubtitle($dbh,$bibnum,$subtitle);
1468 modify subtitles in bibliosubtitle table.
1470 =item OLDmodaddauthor($dbh,$bibnum,$author);
1472 adds or modify additional authors
1473 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1475 =item $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1477 modify/adds subjects
1479 =item OLDmodbibitem($dbh, $biblioitem);
1483 =item OLDmodnote($dbh,$bibitemnum,$note
1485 modify a note for a biblioitem
1487 =item OLDnewbiblioitem($dbh,$biblioitem);
1489 adds a biblioitem ($biblioitem is a hash with the values)
1491 =item OLDnewsubject($dbh,$bibnum);
1495 =item OLDnewsubtitle($dbh,$bibnum,$subtitle);
1497 create a new subtitle
1499 =item ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1501 create a item. $item is a hash and $barcode the barcode.
1503 =item OLDmoditem($dbh,$item);
1507 =item OLDdelitem($dbh,$itemnum);
1511 =item OLDdeletebiblioitem($dbh,$biblioitemnumber);
1513 deletes a biblioitem
1514 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1516 =item OLDdelbiblio($dbh,$biblio);
1523 my ( $dbh, $biblio ) = @_;
1525 # my $dbh = &C4Connect;
1526 my $sth = $dbh->prepare("Select max(biblionumber) from biblio");
1528 my $data = $sth->fetchrow_arrayref;
1529 my $bibnum = $$data[0] + 1;
1532 if ( $biblio->{'seriestitle'} ) { $series = 1 }
1536 "insert into biblio set biblionumber = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?"
1539 $bibnum, $biblio->{'title'},
1540 $biblio->{'author'}, $biblio->{'copyrightdate'},
1541 $series, $biblio->{'seriestitle'},
1542 $biblio->{'notes'}, $biblio->{'abstract'}
1552 my ( $dbh, $biblio ) = @_;
1554 # my $dbh = C4Connect;
1561 "Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?, seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?"
1564 $biblio->{'title'}, $biblio->{'author'},
1565 $biblio->{'abstract'}, $biblio->{'copyrightdate'},
1566 $biblio->{'seriestitle'}, $biblio->{'serial'},
1567 $biblio->{'unititle'}, $biblio->{'notes'},
1568 $biblio->{'biblionumber'}
1572 return ( $biblio->{'biblionumber'} );
1575 sub OLDmodsubtitle {
1576 my ( $dbh, $bibnum, $subtitle ) = @_;
1579 "update bibliosubtitle set subtitle = ? where biblionumber = ?");
1580 $sth->execute( $subtitle, $bibnum );
1584 sub OLDmodaddauthor {
1585 my ( $dbh, $bibnum, @authors ) = @_;
1587 # my $dbh = C4Connect;
1589 $dbh->prepare("Delete from additionalauthors where biblionumber = ?");
1591 $sth->execute($bibnum);
1593 foreach my $author (@authors) {
1594 if ( $author ne '' ) {
1597 "Insert into additionalauthors set author = ?, biblionumber = ?"
1600 $sth->execute( $author, $bibnum );
1605 } # sub modaddauthor
1608 my ( $dbh, $bibnum, $force, @subject ) = @_;
1610 # my $dbh = C4Connect;
1611 my $count = @subject;
1613 for ( my $i = 0 ; $i < $count ; $i++ ) {
1614 $subject[$i] =~ s/^ //g;
1615 $subject[$i] =~ s/ $//g;
1618 "select * from catalogueentry where entrytype = 's' and catalogueentry = ?"
1620 $sth->execute( $subject[$i] );
1622 if ( my $data = $sth->fetchrow_hashref ) {
1625 if ( $force eq $subject[$i] || $force == 1 ) {
1627 # subject not in aut, chosen to force anway
1628 # so insert into cataloguentry so its in auth file
1631 "Insert into catalogueentry (entrytype,catalogueentry) values ('s',?)"
1634 $sth2->execute( $subject[$i] ) if ( $subject[$i] );
1639 "$subject[$i]\n does not exist in the subject authority file";
1642 "Select * from catalogueentry where entrytype = 's' and (catalogueentry like ? or catalogueentry like ? or catalogueentry like ?)"
1644 $sth2->execute( "$subject[$i] %", "% $subject[$i] %",
1646 while ( my $data = $sth2->fetchrow_hashref ) {
1647 $error .= "<br>$data->{'catalogueentry'}";
1654 if ( $error eq '' ) {
1656 $dbh->prepare("Delete from bibliosubject where biblionumber = ?");
1657 $sth->execute($bibnum);
1661 "Insert into bibliosubject (subject,biblionumber) values (?,?)");
1663 foreach $query (@subject) {
1664 $sth->execute( $query, $bibnum ) if ( $query && $bibnum );
1674 my ( $dbh, $biblioitem ) = @_;
1676 # my $dbh = C4Connect;
1679 $biblioitem->{'itemtype'} = $dbh->quote( $biblioitem->{'itemtype'} );
1680 $biblioitem->{'url'} = $dbh->quote( $biblioitem->{'url'} );
1681 $biblioitem->{'isbn'} = $dbh->quote( $biblioitem->{'isbn'} );
1682 $biblioitem->{'publishercode'} =
1683 $dbh->quote( $biblioitem->{'publishercode'} );
1684 $biblioitem->{'publicationyear'} =
1685 $dbh->quote( $biblioitem->{'publicationyear'} );
1686 $biblioitem->{'classification'} =
1687 $dbh->quote( $biblioitem->{'classification'} );
1688 $biblioitem->{'dewey'} = $dbh->quote( $biblioitem->{'dewey'} );
1689 $biblioitem->{'subclass'} = $dbh->quote( $biblioitem->{'subclass'} );
1690 $biblioitem->{'illus'} = $dbh->quote( $biblioitem->{'illus'} );
1691 $biblioitem->{'pages'} = $dbh->quote( $biblioitem->{'pages'} );
1692 $biblioitem->{'volumeddesc'} = $dbh->quote( $biblioitem->{'volumeddesc'} );
1693 $biblioitem->{'bnotes'} = $dbh->quote( $biblioitem->{'bnotes'} );
1694 $biblioitem->{'size'} = $dbh->quote( $biblioitem->{'size'} );
1695 $biblioitem->{'place'} = $dbh->quote( $biblioitem->{'place'} );
1697 $query = "Update biblioitems set
1698 itemtype = $biblioitem->{'itemtype'},
1699 url = $biblioitem->{'url'},
1700 isbn = $biblioitem->{'isbn'},
1701 publishercode = $biblioitem->{'publishercode'},
1702 publicationyear = $biblioitem->{'publicationyear'},
1703 classification = $biblioitem->{'classification'},
1704 dewey = $biblioitem->{'dewey'},
1705 subclass = $biblioitem->{'subclass'},
1706 illus = $biblioitem->{'illus'},
1707 pages = $biblioitem->{'pages'},
1708 volumeddesc = $biblioitem->{'volumeddesc'},
1709 notes = $biblioitem->{'bnotes'},
1710 size = $biblioitem->{'size'},
1711 place = $biblioitem->{'place'}
1712 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1715 if ( $dbh->errstr ) {
1723 my ( $dbh, $bibitemnum, $note ) = @_;
1725 # my $dbh=C4Connect;
1726 my $query = "update biblioitems set notes='$note' where
1727 biblioitemnumber='$bibitemnum'";
1728 my $sth = $dbh->prepare($query);
1735 sub OLDnewbiblioitem {
1736 my ( $dbh, $biblioitem ) = @_;
1738 # my $dbh = C4Connect;
1739 my $sth = $dbh->prepare("Select max(biblioitemnumber) from biblioitems");
1744 $data = $sth->fetchrow_arrayref;
1745 $bibitemnum = $$data[0] + 1;
1749 $sth = $dbh->prepare( "insert into biblioitems set
1750 biblioitemnumber = ?, biblionumber = ?,
1751 volume = ?, number = ?,
1752 classification = ?, itemtype = ?,
1754 issn = ?, dewey = ?,
1755 subclass = ?, publicationyear = ?,
1756 publishercode = ?, volumedate = ?,
1757 volumeddesc = ?, illus = ?,
1758 pages = ?, notes = ?,
1760 marc = ?, place = ?"
1763 $bibitemnum, $biblioitem->{'biblionumber'},
1764 $biblioitem->{'volume'}, $biblioitem->{'number'},
1765 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
1766 $biblioitem->{'url'}, $biblioitem->{'isbn'},
1767 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
1768 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
1769 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
1770 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
1771 $biblioitem->{'pages'}, $biblioitem->{'bnotes'},
1772 $biblioitem->{'size'}, $biblioitem->{'lccn'},
1773 $biblioitem->{'marc'}, $biblioitem->{'place'}
1778 return ($bibitemnum);
1782 my ( $dbh, $bibnum ) = @_;
1784 $dbh->prepare("insert into bibliosubject (biblionumber) values (?)");
1785 $sth->execute($bibnum);
1789 sub OLDnewsubtitle {
1790 my ( $dbh, $bibnum, $subtitle ) = @_;
1793 "insert into bibliosubtitle set biblionumber = ?, subtitle = ?");
1794 $sth->execute( $bibnum, $subtitle );
1799 my ( $dbh, $item, $barcode ) = @_;
1801 # my $dbh = C4Connect;
1802 my $sth = $dbh->prepare("Select max(itemnumber) from items");
1808 $data = $sth->fetchrow_hashref;
1809 $itemnumber = $data->{'max(itemnumber)'} + 1;
1812 # FIXME the "notforloan" field seems to be named "loan" in some places. workaround bugfix.
1813 if ( $item->{'loan'} ) {
1814 $item->{'notforloan'} = $item->{'loan'};
1817 # if dateaccessioned is provided, use it. Otherwise, set to NOW()
1818 if ( $item->{'dateaccessioned'} ) {
1819 $sth = $dbh->prepare( "Insert into items set
1820 itemnumber = ?, biblionumber = ?,
1821 biblioitemnumber = ?, barcode = ?,
1822 booksellerid = ?, dateaccessioned = ?,
1823 homebranch = ?, holdingbranch = ?,
1824 price = ?, replacementprice = ?,
1825 replacementpricedate = NOW(), itemnotes = ?,
1826 itemcallnumber =?, notforloan = ?
1830 $itemnumber, $item->{'biblionumber'},
1831 $item->{'biblioitemnumber'}, $barcode,
1832 $item->{'booksellerid'}, $item->{'dateaccessioned'},
1833 $item->{'homebranch'}, $item->{'holdingbranch'},
1834 $item->{'price'}, $item->{'replacementprice'},
1835 $item->{'itemnotes'}, $item->{'itemcallnumber'},
1836 $item->{'notforloan'}
1840 $sth = $dbh->prepare( "Insert into items set
1841 itemnumber = ?, biblionumber = ?,
1842 biblioitemnumber = ?, barcode = ?,
1843 booksellerid = ?, dateaccessioned = NOW(),
1844 homebranch = ?, holdingbranch = ?,
1845 price = ?, replacementprice = ?,
1846 replacementpricedate = NOW(), itemnotes = ?,
1847 itemcallnumber = ? , notforloan = ?
1851 $itemnumber, $item->{'biblionumber'},
1852 $item->{'biblioitemnumber'}, $barcode,
1853 $item->{'booksellerid'}, $item->{'homebranch'},
1854 $item->{'holdingbranch'}, $item->{'price'},
1855 $item->{'replacementprice'}, $item->{'itemnotes'},
1856 $item->{'itemcallnumber'}, $item->{'notforloan'}
1859 if ( defined $sth->errstr ) {
1860 $error .= $sth->errstr;
1863 return ( $itemnumber, $error );
1867 my ( $dbh, $item ) = @_;
1869 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1870 # my $dbh=C4Connect;
1871 $item->{'itemnum'} = $item->{'itemnumber'} unless $item->{'itemnum'};
1873 "update items set barcode=?,itemnotes=?,itemcallnumber=?,notforloan=? where itemnumber=?";
1875 $item->{'barcode'}, $item->{'notes'},
1876 $item->{'itemcallnumber'}, $item->{'notforloan'},
1879 if ( $item->{'barcode'} eq '' ) {
1880 $item->{'notforloan'} = 0 unless $item->{'notforloan'};
1881 $query = "update items set notforloan=? where itemnumber=?";
1882 @bind = ( $item->{'notforloan'}, $item->{'itemnum'} );
1884 if ( $item->{'lost'} ne '' ) {
1885 $query = "update items set biblioitemnumber=?,
1893 where itemnumber=?";
1895 $item->{'bibitemnum'}, $item->{'barcode'},
1896 $item->{'notes'}, $item->{'homebranch'},
1897 $item->{'lost'}, $item->{'wthdrawn'},
1898 $item->{'itemcallnumber'}, $item->{'notforloan'},
1902 if ( $item->{'replacement'} ne '' ) {
1903 $query =~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1905 my $sth = $dbh->prepare($query);
1906 $sth->execute(@bind);
1913 my ( $dbh, $itemnum ) = @_;
1915 # my $dbh=C4Connect;
1916 my $sth = $dbh->prepare("select * from items where itemnumber=?");
1917 $sth->execute($itemnum);
1918 my $data = $sth->fetchrow_hashref;
1920 my $query = "Insert into deleteditems set ";
1922 foreach my $temp ( keys %$data ) {
1923 $query .= "$temp = ?,";
1924 push ( @bind, $data->{$temp} );
1929 $sth = $dbh->prepare($query);
1930 $sth->execute(@bind);
1932 $sth = $dbh->prepare("Delete from items where itemnumber=?");
1933 $sth->execute($itemnum);
1939 sub OLDdeletebiblioitem {
1940 my ( $dbh, $biblioitemnumber ) = @_;
1942 # my $dbh = C4Connect;
1943 my $sth = $dbh->prepare( "Select * from biblioitems
1944 where biblioitemnumber = ?"
1948 $sth->execute($biblioitemnumber);
1950 if ( $results = $sth->fetchrow_hashref ) {
1954 "Insert into deletedbiblioitems (biblioitemnumber, biblionumber, volume, number, classification, itemtype,
1955 isbn, issn ,dewey ,subclass ,publicationyear ,publishercode ,volumedate ,volumeddesc ,timestamp ,illus ,
1956 pages ,notes ,size ,url ,lccn ) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
1960 $results->{biblioitemnumber}, $results->{biblionumber},
1961 $results->{volume}, $results->{number},
1962 $results->{classification}, $results->{itemtype},
1963 $results->{isbn}, $results->{issn},
1964 $results->{dewey}, $results->{subclass},
1965 $results->{publicationyear}, $results->{publishercode},
1966 $results->{volumedate}, $results->{volumeddesc},
1967 $results->{timestamp}, $results->{illus},
1968 $results->{pages}, $results->{notes},
1969 $results->{size}, $results->{url},
1973 $dbh->prepare("Delete from biblioitems where biblioitemnumber = ?");
1974 $sth2->execute($biblioitemnumber);
1979 # Now delete all the items attached to the biblioitem
1980 $sth = $dbh->prepare("Select * from items where biblioitemnumber = ?");
1981 $sth->execute($biblioitemnumber);
1983 while ( my $data = $sth->fetchrow_hashref ) {
1984 my $query = "Insert into deleteditems set ";
1986 foreach my $temp ( keys %$data ) {
1987 $query .= "$temp = ?,";
1988 push ( @bind, $data->{$temp} );
1991 my $sth2 = $dbh->prepare($query);
1992 $sth2->execute(@bind);
1995 $sth = $dbh->prepare("Delete from items where biblioitemnumber = ?");
1996 $sth->execute($biblioitemnumber);
2000 } # sub deletebiblioitem
2003 my ( $dbh, $biblio ) = @_;
2004 my $sth = $dbh->prepare("select * from biblio where biblionumber=?");
2005 $sth->execute($biblio);
2006 if ( my $data = $sth->fetchrow_hashref ) {
2008 my $query = "Insert into deletedbiblio set ";
2010 foreach my $temp ( keys %$data ) {
2011 $query .= "$temp = ?,";
2012 push ( @bind, $data->{$temp} );
2015 #replacing the last , by ",?)"
2017 $sth = $dbh->prepare($query);
2018 $sth->execute(@bind);
2020 $sth = $dbh->prepare("Delete from biblio where biblionumber=?");
2021 $sth->execute($biblio);
2035 my $dbh = C4::Context->dbh;
2038 my $sth = $dbh->prepare("Select count(*) from items where biblionumber=?");
2039 $sth->execute($biblio);
2040 my $data = $sth->fetchrow_hashref;
2042 return ( $data->{'count(*)'} );
2047 ($order, $ordernumber) = &getorder($biblioitemnumber, $biblionumber);
2049 Looks up the order with the given biblionumber and biblioitemnumber.
2051 Returns a two-element array. C<$ordernumber> is the order number.
2052 C<$order> is a reference-to-hash describing the order; its keys are
2053 fields from the biblio, biblioitems, aqorders, and aqorderbreakdown
2054 tables of the Koha database.
2059 # FIXME - This is effectively identical to &C4::Catalogue::getorder.
2060 # Pick one and stick with it.
2062 my ( $bi, $bib ) = @_;
2063 my $dbh = C4::Context->dbh;
2064 my $sth = $dbh->prepare( "Select ordernumber
2066 where biblionumber=? and biblioitemnumber=?"
2068 $sth->execute( $bib, $bi );
2070 # FIXME - Use fetchrow_array(), since we're only interested in the one
2072 my $ordnum = $sth->fetchrow_hashref;
2074 my $order = getsingleorder( $ordnum->{'ordernumber'} );
2075 return ( $order, $ordnum->{'ordernumber'} );
2078 =item getsingleorder
2080 $order = &getsingleorder($ordernumber);
2082 Looks up an order by order number.
2084 Returns a reference-to-hash describing the order. The keys of
2085 C<$order> are fields from the biblio, biblioitems, aqorders, and
2086 aqorderbreakdown tables of the Koha database.
2091 # FIXME - This is effectively identical to
2092 # &C4::Catalogue::getsingleorder.
2093 # Pick one and stick with it.
2094 sub getsingleorder {
2096 my $dbh = C4::Context->dbh;
2099 "Select * from biblio,biblioitems,aqorders left join aqorderbreakdown
2100 on aqorders.ordernumber=aqorderbreakdown.ordernumber
2101 where aqorders.ordernumber=?
2102 and biblio.biblionumber=aqorders.biblionumber
2103 and biblioitems.biblioitemnumber=aqorders.biblioitemnumber"
2105 $sth->execute($ordnum);
2106 my $data = $sth->fetchrow_hashref;
2113 my $dbh = C4::Context->dbh;
2114 my $bibnum = OLDnewbiblio( $dbh, $biblio );
2116 # finds new (MARC bibid
2117 # my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
2118 my $record = &MARCkoha2marcBiblio( $dbh, $bibnum );
2119 MARCaddbiblio( $dbh, $record, $bibnum );
2125 $biblionumber = &modbiblio($biblio);
2127 Update a biblio record.
2129 C<$biblio> is a reference-to-hash whose keys are the fields in the
2130 biblio table in the Koha database. All fields must be present, not
2131 just the ones you wish to change.
2133 C<&modbiblio> updates the record defined by
2134 C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
2136 C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
2143 my $dbh = C4::Context->dbh;
2144 my $biblionumber = OLDmodbiblio( $dbh, $biblio );
2145 my $record = MARCkoha2marcBiblio( $dbh, $biblionumber, $biblionumber );
2147 # finds new (MARC bibid
2148 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $biblionumber );
2149 MARCmodbiblio( $dbh, $bibid, $record, 0 );
2150 return ($biblionumber);
2155 &modsubtitle($biblionumber, $subtitle);
2157 Sets the subtitle of a book.
2159 C<$biblionumber> is the biblionumber of the book to modify.
2161 C<$subtitle> is the new subtitle.
2166 my ( $bibnum, $subtitle ) = @_;
2167 my $dbh = C4::Context->dbh;
2168 &OLDmodsubtitle( $dbh, $bibnum, $subtitle );
2173 &modaddauthor($biblionumber, $author);
2175 Replaces all additional authors for the book with biblio number
2176 C<$biblionumber> with C<$author>. If C<$author> is the empty string,
2177 C<&modaddauthor> deletes all additional authors.
2182 my ( $bibnum, @authors ) = @_;
2183 my $dbh = C4::Context->dbh;
2184 &OLDmodaddauthor( $dbh, $bibnum, @authors );
2185 } # sub modaddauthor
2189 $error = &modsubject($biblionumber, $force, @subjects);
2191 $force - a subject to force
2193 $error - Error message, or undef if successful.
2198 my ( $bibnum, $force, @subject ) = @_;
2199 my $dbh = C4::Context->dbh;
2200 my $error = &OLDmodsubject( $dbh, $bibnum, $force, @subject );
2205 my ($biblioitem) = @_;
2206 my $dbh = C4::Context->dbh;
2207 &OLDmodbibitem( $dbh, $biblioitem );
2211 my ( $bibitemnum, $note ) = @_;
2212 my $dbh = C4::Context->dbh;
2213 &OLDmodnote( $dbh, $bibitemnum, $note );
2217 my ($biblioitem) = @_;
2218 my $dbh = C4::Context->dbh;
2219 my $bibitemnum = &OLDnewbiblioitem( $dbh, $biblioitem );
2221 ################################################################
2222 ## Fix template and shift this to newbiblio
2223 my @subjects = split ( /\n/, $biblioitem->{'subjectheadings'} );
2224 modsubject( $biblioitem->{'biblionumber'}, 1, @subjects );
2226 ################################################################
2228 MARCkoha2marcBiblio( $dbh, 0, $bibitemnum )
2229 ; # the 0 means "do NOT retrieve biblio, only biblioitem, in the MARC record
2231 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh,
2232 $biblioitem->{biblionumber} );
2233 &MARCaddbiblio( $dbh, $MARCbiblio, $biblioitem->{biblionumber}, $bibid );
2234 return ($bibitemnum);
2239 my $dbh = C4::Context->dbh;
2240 &OLDnewsubject( $dbh, $bibnum );
2244 my ( $bibnum, $subtitle ) = @_;
2245 my $dbh = C4::Context->dbh;
2246 &OLDnewsubtitle( $dbh, $bibnum, $subtitle );
2250 my ( $item, @barcodes ) = @_;
2251 my $dbh = C4::Context->dbh;
2255 foreach my $barcode (@barcodes) {
2256 ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, uc($barcode) );
2259 &MARCkoha2marcItem( $dbh, $item->{biblionumber}, $itemnumber );
2260 &MARCadditem( $dbh, $MARCitem, $item->{biblionumber} );
2267 my $dbh = C4::Context->dbh;
2268 &OLDmoditem( $dbh, $item );
2270 &MARCkoha2marcItem( $dbh, $item->{'biblionumber'}, $item->{'itemnum'} );
2272 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $item->{biblionumber} );
2273 &MARCmoditem( $dbh, $MARCitem, $bibid, $item->{itemnum}, 0 );
2277 my ( $count, @barcodes ) = @_;
2278 my $dbh = C4::Context->dbh;
2280 my $sth = $dbh->prepare("Select * from items where barcode=?");
2281 for ( my $i = 0 ; $i < $count ; $i++ ) {
2282 $barcodes[$i] = uc $barcodes[$i];
2283 $sth->execute( $barcodes[$i] );
2284 if ( my $data = $sth->fetchrow_hashref ) {
2285 $error .= " Duplicate Barcode: $barcodes[$i]";
2293 my ($bibitemnum) = @_;
2294 my $dbh = C4::Context->dbh;
2297 $dbh->prepare("Select count(*) from items where biblioitemnumber=?");
2298 $sth->execute($bibitemnum);
2299 my $data = $sth->fetchrow_hashref;
2301 return ( $data->{'count(*)'} );
2306 my $dbh = C4::Context->dbh;
2307 &OLDdelitem( $dbh, $itemnum );
2310 sub deletebiblioitem {
2311 my ($biblioitemnumber) = @_;
2312 my $dbh = C4::Context->dbh;
2313 &OLDdeletebiblioitem( $dbh, $biblioitemnumber );
2314 } # sub deletebiblioitem
2318 my $dbh = C4::Context->dbh;
2319 &OLDdelbiblio( $dbh, $biblio );
2320 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $biblio );
2321 &MARCdelbiblio( $dbh, $bibid, 0 );
2325 my ($biblionumber) = @_;
2326 my $dbh = C4::Context->dbh;
2327 my $sth = $dbh->prepare("Select * from biblio where biblionumber = ?");
2329 # || die "Cannot prepare $query\n" . $dbh->errstr;
2333 $sth->execute($biblionumber);
2335 # || die "Cannot execute $query\n" . $sth->errstr;
2336 while ( my $data = $sth->fetchrow_hashref ) {
2337 $results[$count] = $data;
2342 return ( $count, @results );
2346 my ($biblioitemnum) = @_;
2347 my $dbh = C4::Context->dbh;
2348 my $sth = $dbh->prepare( "Select * from biblioitems where
2349 biblioitemnumber = ?"
2354 $sth->execute($biblioitemnum);
2356 while ( my $data = $sth->fetchrow_hashref ) {
2357 $results[$count] = $data;
2362 return ( $count, @results );
2363 } # sub getbiblioitem
2365 sub getbiblioitembybiblionumber {
2366 my ($biblionumber) = @_;
2367 my $dbh = C4::Context->dbh;
2368 my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?");
2372 $sth->execute($biblionumber);
2374 while ( my $data = $sth->fetchrow_hashref ) {
2375 $results[$count] = $data;
2380 return ( $count, @results );
2384 my $dbh = C4::Context->dbh;
2385 my $query = "select * from itemtypes order by description";
2386 my $sth = $dbh->prepare($query);
2388 # || die "Cannot prepare $query" . $dbh->errstr;
2394 # || die "Cannot execute $query\n" . $sth->errstr;
2395 while ( my $data = $sth->fetchrow_hashref ) {
2396 $results[$count] = $data;
2401 return ( $count, @results );
2402 } # sub getitemtypes
2404 sub getitemsbybiblioitem {
2405 my ($biblioitemnum) = @_;
2406 my $dbh = C4::Context->dbh;
2407 my $sth = $dbh->prepare( "Select * from items, biblio where
2408 biblio.biblionumber = items.biblionumber and biblioitemnumber
2412 # || die "Cannot prepare $query\n" . $dbh->errstr;
2416 $sth->execute($biblioitemnum);
2418 # || die "Cannot execute $query\n" . $sth->errstr;
2419 while ( my $data = $sth->fetchrow_hashref ) {
2420 $results[$count] = $data;
2425 return ( $count, @results );
2426 } # sub getitemsbybiblioitem
2430 # Subroutine to log changes to databases
2431 # Eventually, this subroutine will be used to create a log of all changes made,
2432 # with the possibility of "undo"ing some changes
2433 my $database = shift;
2434 if ( $database eq 'kohadb' ) {
2436 my $section = shift;
2438 my $original = shift;
2441 # print STDERR "KOHA: $type $section $item $original $new\n";
2443 elsif ( $database eq 'marc' ) {
2445 my $Record_ID = shift;
2448 my $subfield_ID = shift;
2449 my $original = shift;
2452 # print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2456 #------------------------------------------------
2458 #---------------------------------------
2459 # Find a biblio entry, or create a new one if it doesn't exist.
2460 # If a "subtitle" entry is in hash, add it to subtitle table
2461 sub getoraddbiblio {
2466 # FIXME - Unused argument
2467 $biblio, # hash ref to fields
2478 $dbh = C4::Context->dbh;
2480 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2481 $sth = $dbh->prepare( "select biblionumber
2483 where title=? and author=?
2484 and copyrightdate=? and seriestitle=?"
2487 $biblio->{title}, $biblio->{author},
2488 $biblio->{copyright}, $biblio->{seriestitle}
2491 ($biblionumber) = $sth->fetchrow;
2492 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2496 # Doesn't exist. Add new one.
2497 print "<PRE>Adding biblio</PRE>\n" if $debug;
2498 ( $biblionumber, $error ) = &newbiblio($biblio);
2499 if ($biblionumber) {
2500 print "<PRE>Added with biblio number=$biblionumber</PRE>\n"
2502 if ( $biblio->{subtitle} ) {
2503 &newsubtitle( $biblionumber, $biblio->{subtitle} );
2507 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2511 return $biblionumber, $error;
2513 } # sub getoraddbiblio
2517 # converts ISO 5426 coded string to ISO 8859-1
2518 # sloppy code : should be improved in next issue
2519 my ( $string, $encoding ) = @_;
2522 # $encoding = C4::Context->preference("marcflavour") unless $encoding;
2523 if ( $encoding eq "UNIMARC" ) {
2586 # this handles non-sorting blocks (if implementation requires this)
2587 $string = nsb_clean($_);
2589 elsif ( $encoding eq "USMARC" || $encoding eq "MARC21" ) {
2590 if (/[\xc1-\xff]/) {
2643 # this handles non-sorting blocks (if implementation requires this)
2644 $string = nsb_clean($_);
2651 my $NSB = '\x88'; # NSB : begin Non Sorting Block
2652 my $NSE = '\x89'; # NSE : Non Sorting Block end
2653 # handles non sorting blocks
2657 s/[ ]{0,1}$NSE/) /gm;
2662 END { } # module clean-up code here (global destructor)
2668 Koha Developement team <info@koha.org>
2670 Paul POULAIN paul.poulain@free.fr
2676 # Revision 1.95 2004/06/26 23:19:59 rangi
2677 # Fixing modaddauthor, and adding getitemtypes.
2678 # Also tidying up formatting of code
2680 # Revision 1.94 2004/06/17 08:16:32 tipaul
2681 # merging tag & subfield in marc_word for better perfs
2683 # Revision 1.93 2004/06/11 15:38:06 joshferraro
2684 # Changes MARCaddword to index words >= 1 char ... needed for more accurate
2685 # searches using SearchMarc routines.
2687 # Revision 1.92 2004/06/10 08:29:01 tipaul
2688 # MARC authority management (continued)
2690 # Revision 1.91 2004/06/03 10:03:01 tipaul
2691 # * frameworks and itemtypes are independant
2692 # * in the MARC editor, showing the + to duplicate a tag only if the tag is repeatable
2694 # Revision 1.90 2004/05/28 08:25:53 tipaul
2695 # hidding hidden & isurl constraints into MARC subfield structure
2697 # Revision 1.89 2004/05/27 21:47:21 rangi
2700 # Revision 1.88 2004/05/18 15:23:49 tipaul
2701 # framework management : 1 MARC framework for each itemtype
2703 # Revision 1.87 2004/05/18 11:54:07 tipaul
2704 # getitemtypes moved in Koha.pm
2706 # Revision 1.86 2004/05/03 09:19:22 tipaul
2707 # some fixes for mysql prepare & execute
2709 # Revision 1.85 2004/04/02 14:55:48 tipaul
2710 # renaming items.bulk field to items.itemcallnumber.
2711 # Will be used to store call number for libraries that don't use dewey classification.
2712 # Note it's related to ITEMS, not biblio.
2714 # Revision 1.84 2004/03/24 17:18:30 joshferraro
2715 # Fixes bug 749 by removing the comma on line 1488.
2717 # Revision 1.83 2004/03/15 14:31:50 tipaul
2718 # adding a minor check
2720 # Revision 1.82 2004/03/07 05:47:31 acli
2721 # Various updates/fixes from rel_2_0
2722 # Fixes for bugs 721 (templating), 727, and 734
2724 # Revision 1.81 2004/03/06 20:26:13 tipaul
2725 # adding seealso feature in MARC searches
2727 # Revision 1.80 2004/02/12 13:40:56 tipaul
2728 # deleting subs duplicated by error
2730 # Revision 1.79 2004/02/11 08:40:09 tipaul
2731 # synch'ing 2.0.0 branch and head
2733 # Revision 1.78.2.3 2004/02/10 13:15:46 tipaul
2734 # removing 2 warnings
2736 # Revision 1.78.2.2 2004/01/26 10:38:06 tipaul
2737 # dealing correctly "bulk" field
2739 # Revision 1.78.2.1 2004/01/13 17:29:53 tipaul
2740 # * minor html fixes
2741 # * adding publisher in acquisition process (& ordering basket by publisher)
2743 # Revision 1.78 2003/12/09 15:57:28 tipaul
2744 # rolling back to working char_decode sub
2746 # Revision 1.77 2003/12/03 17:47:14 tipaul
2747 # bugfixes for biblio deletion
2749 # Revision 1.76 2003/12/03 01:43:41 slef
2752 # Revision 1.75 2003/12/03 01:42:03 slef
2753 # bug 662 fixes securing DBI
2755 # Revision 1.74 2003/11/28 09:48:33 tipaul
2756 # bugfix : misusing prepare & execute => now using prepare(?) and execute($var)
2758 # Revision 1.73 2003/11/28 09:45:25 tipaul
2759 # bugfix for iso2709 file import in the "notforloan" field.
2761 # But notforloan field called "loan" somewhere, so in case "loan" is used, copied to "notforloan" to avoid a bug.
2763 # Revision 1.72 2003/11/24 17:40:14 tipaul
2766 # Revision 1.71 2003/11/24 16:28:49 tipaul
2767 # biblio & item deletion now works fine in MARC editor.
2768 # Stores deleted biblio/item in the marc field of the deletedbiblio/deleteditem table.
2770 # Revision 1.70 2003/11/24 13:29:55 tipaul
2771 # moving $id from beginning to end of file (70 commits... huge comments...)
2773 # Revision 1.69 2003/11/24 13:27:17 tipaul
2774 # fix for #380 (bibliosubject)
2776 # Revision 1.68 2003/11/06 17:18:30 tipaul
2779 # 1st draft for MARC biblio deletion.
2780 # Still does not work well, but at least, Biblio.pm compiles & it should'nt break too many things
2781 # (Note the trash in the MARCdetail, but don't use it, please :-) )
2783 # Revision 1.67 2003/10/25 08:46:27 tipaul
2784 # minor fixes for bilbio deletion (still buggy)
2786 # Revision 1.66 2003/10/17 10:02:56 tipaul
2787 # Indexing only words longer than 2 letters. Was >=2 before, & 2 letters words usually means nothing.
2789 # Revision 1.65 2003/10/14 09:45:29 tipaul
2790 # 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)
2792 # Revision 1.64 2003/10/06 15:20:51 tipaul
2793 # fix for 536 (subtitle error)
2795 # Revision 1.63 2003/10/01 13:25:49 tipaul
2796 # seems a char encoding problem modified something in char_decode sub... changing back to something that works...
2798 # Revision 1.62 2003/09/17 14:21:13 tipaul
2799 # fixing bug that makes a MARC biblio disappear when using full acquisition (order => recieve ==> MARC editor).
2800 # Before this 2 lines fix, the MARC biblio was deleted during recieve, and had to be entirely recreated :-(
2802 # Revision 1.61 2003/09/17 10:24:39 tipaul
2803 # notforloan value in itemtype was overwritting notforloan value in a given item.
2804 # I changed this behaviour :
2805 # if notforloan is set for a given item, and NOT for all items from this itemtype, the notforloan is kept.
2806 # If notforloan is set for itemtype, it's used (and impossible to loan a specific item from this itemtype)
2808 # Revision 1.60 2003/09/04 14:11:23 tipaul
2809 # fix for 593 (data duplication in MARC-DB)
2811 # Revision 1.58 2003/08/06 12:54:52 tipaul
2812 # fix for publicationyear : extracting numeric value from MARC string, like for copyrightdate.
2813 # (note that copyrightdate still extracted to get numeric format)
2815 # Revision 1.57 2003/07/15 23:09:18 slef
2816 # change show columns to use biblioitems bnotes too
2818 # Revision 1.56 2003/07/15 11:34:52 slef
2819 # fixes from paul email
2821 # Revision 1.55 2003/07/15 00:02:49 slef
2822 # Work on bug 515... can we do a single-side rename of notes to bnotes?
2824 # Revision 1.54 2003/07/11 11:51:32 tipaul
2825 # *** empty log message ***
2827 # Revision 1.52 2003/07/10 10:37:19 tipaul
2828 # fix for copyrightdate problem, #514
2830 # Revision 1.51 2003/07/02 14:47:17 tipaul
2831 # fix for #519 : items.dateaccessioned imports incorrectly
2833 # Revision 1.49 2003/06/17 11:21:13 tipaul
2834 # improvments/fixes for z3950 support.
2835 # * Works now even on ADD, not only on MODIFY
2836 # * able to search on ISBN, author, title
2838 # Revision 1.48 2003/06/16 09:22:53 rangi
2839 # Just added an order clause to getitemtypes
2841 # Revision 1.47 2003/05/20 16:22:44 tipaul
2842 # fixing typo in Biblio.pm POD
2844 # Revision 1.46 2003/05/19 13:45:18 tipaul
2845 # support for subtitles, additional authors, subject.
2846 # 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.
2847 # Note that some OLD-DB subs are strange (dummy ?) see OLDmodsubject, OLDmodsubtitle, OLDmodaddiauthor in C4/Biblio.pm
2848 # 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.
2850 # Revision 1.45 2003/04/29 16:50:49 tipaul
2851 # really proud of this commit :-)
2852 # z3950 search and import seems to works fine.
2853 # Let me explain how :
2854 # * a "search z3950" button is added in the addbiblio template.
2855 # * when clicked, a popup appears and z3950/search.pl is called
2856 # * z3950/search.pl calls addz3950search in the DB
2857 # * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table.
2858 # * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending.
2859 # * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled
2862 # * 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.
2863 # * 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.
2865 # Revision 1.44 2003/04/28 13:07:14 tipaul
2866 # Those fixes solves the "internal server error" with MARC::Record 1.12.
2867 # It was due to an illegal contruction in Koha : we tried to retrive subfields from <10 tags.
2868 # That's not possible. MARC::Record accepted this in 0.93 version, but it was fixed after.
2869 # Now, the construct/retrieving is OK !
2871 # Revision 1.43 2003/04/10 13:56:02 tipaul
2873 # * worked in 1.9.0, but not in 1.9.1 :
2874 # - modif of a biblio didn't work
2875 # - 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.
2877 # * did not work before :
2878 # - repeatable subfields now works correctly. Enter 2 subfields separated by | and they will be splitted during saving.
2879 # - dropped the last subfield of the MARC form :-(
2881 # Internal changes :
2882 # - 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.
2883 # Note the MARCdelbiblio has been rewritted to enable deletion of a biblio WITHOUT deleting items.
2885 # Revision 1.42 2003/04/04 08:41:11 tipaul
2886 # last commits before 1.9.1
2888 # Revision 1.41 2003/04/01 12:26:43 tipaul
2891 # Revision 1.40 2003/03/11 15:14:03 tipaul
2894 # Revision 1.39 2003/03/07 16:35:42 tipaul
2895 # * moving generic functions to Koha.pm
2896 # * improvement of SearchMarc.pm
2900 # Revision 1.38 2003/02/27 16:51:59 tipaul
2901 # * moving prepare / execute to ? form.
2904 # * road to 1.9.2 => acquisition and cataloguing merging
2906 # Revision 1.37 2003/02/12 11:03:03 tipaul
2907 # Support for 000 -> 010 fields.
2908 # Those fields doesn't have subfields.
2909 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
2910 # 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.
2912 # Revision 1.36 2003/02/12 11:01:01 tipaul
2913 # Support for 000 -> 010 fields.
2914 # Those fields doesn't have subfields.
2915 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
2916 # 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.
2918 # Revision 1.35 2003/02/03 18:46:00 acli
2919 # Minor factoring in C4/Biblio.pm, plus change to export the per-tag
2920 # 'mandatory' property to a per-subfield 'tag_mandatory' template parameter,
2921 # so that addbiblio.tmpl can distinguish between mandatory subfields in a
2922 # mandatory tag and mandatory subfields in an optional tag
2924 # Not-minor factoring in acqui.simple/addbiblio.pl to make the if-else blocks
2925 # smaller, and to add some POD; need further testing for this
2927 # Added function to check if a MARC subfield name is "koha-internal" (instead
2928 # of checking it for 'lib' and 'tag' everywhere); temporarily added to Koha.pm
2930 # Use above function in acqui.simple/additem.pl and search.marc/search.pl
2932 # Revision 1.34 2003/01/28 14:50:04 tipaul
2933 # fixing MARCmodbiblio API and reindenting code
2935 # Revision 1.33 2003/01/23 12:22:37 tipaul
2936 # adding char_decode to decode MARC21 or UNIMARC extended chars
2938 # Revision 1.32 2002/12/16 15:08:50 tipaul
2939 # small but important bugfix (fixes a problem in export)
2941 # Revision 1.31 2002/12/13 16:22:04 tipaul
2942 # 1st draft of marc export
2944 # Revision 1.30 2002/12/12 21:26:35 tipaul
2945 # YAB ! (Yet Another Bugfix) => related to biblio modif
2946 # (some warning cleaning too)
2948 # Revision 1.29 2002/12/12 16:35:00 tipaul
2949 # adding authentification with Auth.pm and
2950 # MAJOR BUGFIX on marc biblio modification
2952 # Revision 1.28 2002/12/10 13:30:03 tipaul
2953 # fugfixes from Dombes Abbey work
2955 # Revision 1.27 2002/11/19 12:36:16 tipaul
2957 # various bugfixes, improvments, and migration from acquisition.pm to biblio.pm
2959 # Revision 1.26 2002/11/12 15:58:43 tipaul
2962 # * 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)
2964 # Revision 1.25 2002/10/25 10:58:26 tipaul
2966 # * bugfixes and improvements
2968 # Revision 1.24 2002/10/24 12:09:01 arensb
2969 # Fixed "no title" warning when generating HTML documentation from POD.
2971 # Revision 1.23 2002/10/16 12:43:08 arensb
2972 # Added some FIXME comments.
2974 # Revision 1.22 2002/10/15 13:39:17 tipaul
2975 # removing Acquisition.pm
2976 # deleting unused code in biblio.pm, rewriting POD and answering most FIXME comments
2978 # Revision 1.21 2002/10/13 11:34:14 arensb
2979 # Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
2980 # Thus, $x = $x+2 becomes $x += 2, and so forth.
2982 # Revision 1.20 2002/10/13 08:28:32 arensb
2983 # Deleted unused variables.
2984 # Removed trailing whitespace.
2986 # Revision 1.19 2002/10/13 05:56:10 arensb
2987 # Added some FIXME comments.
2989 # Revision 1.18 2002/10/11 12:34:53 arensb
2990 # Replaced &requireDBI with C4::Context->dbh
2992 # Revision 1.17 2002/10/10 14:48:25 tipaul
2995 # Revision 1.16 2002/10/07 14:04:26 tipaul
2996 # road to 1.3.1 : viewing MARC biblio
2998 # Revision 1.15 2002/10/05 09:49:25 arensb
2999 # Merged with arensb-context branch: use C4::Context->dbh instead of
3000 # &C4Connect, and generally prefer C4::Context over C4::Database.
3002 # Revision 1.14 2002/10/03 11:28:18 tipaul
3003 # Extending Context.pm to add stopword management and using it in MARC-API.
3004 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
3006 # Revision 1.13 2002/10/02 16:26:44 tipaul
3009 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
3010 # Merged in changes from main branch.
3012 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
3013 # Added a whole mess of FIXME comments.
3015 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
3016 # Added some missing semicolons.
3018 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
3019 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
3022 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
3023 # Added a whole mess of FIXME comments.
3025 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
3026 # Added some missing semicolons.
3028 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
3029 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
3032 # Revision 1.12 2002/10/01 11:48:51 arensb
3033 # Added some FIXME comments, mostly marking duplicate functions.
3035 # Revision 1.11 2002/09/24 13:49:26 tipaul
3036 # long WAS the road to 1.3.0...
3037 # coming VERY SOON NOW...
3038 # modifying installer and buildrelease to update the DB
3040 # Revision 1.10 2002/09/22 16:50:08 arensb
3041 # Added some FIXME comments.
3043 # Revision 1.9 2002/09/20 12:57:46 tipaul
3044 # long is the road to 1.4.0
3045 # * MARCadditem and MARCmoditem now wroks
3046 # * various bugfixes in MARC management
3047 # !!! 1.3.0 should be released very soon now. Be careful !!!
3049 # Revision 1.8 2002/09/10 13:53:52 tipaul
3050 # MARC API continued...
3052 # * 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)
3054 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
3056 # Revision 1.7 2002/08/14 18:12:51 tonnesen
3057 # Added copyright statement to all .pl and .pm files
3059 # Revision 1.6 2002/07/25 13:40:31 tipaul
3060 # pod documenting the API.
3062 # Revision 1.5 2002/07/24 16:11:37 tipaul
3064 # Database.pm and Output.pm are almost not modified (var test...)
3066 # Biblio.pm is almost completly rewritten.
3068 # WHAT DOES IT ??? ==> END of Hitchcock suspens
3070 # 1st, it does... nothing...
3071 # 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 ...
3073 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
3074 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
3075 # * 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.
3076 # * 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.
3077 # 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 ;-)
3079 # 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.
3080 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.