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 from marc_subfield_structure where frameworkcode=? order by tagfield,tagsubfield"
258 $sth->execute($frameworkcode);
261 my $authorised_value;
270 ( $tag, $subfield, $lib, $tab,
271 $mandatory, $repeatable, $authorised_value, $authtypecode,
272 $value_builder, $kohafield, $seealso, $hidden,
277 $res->{$tag}->{$subfield}->{lib} = $lib;
278 $res->{$tag}->{$subfield}->{tab} = $tab;
279 $res->{$tag}->{$subfield}->{mandatory} = $mandatory;
280 $res->{$tag}->{$subfield}->{repeatable} = $repeatable;
281 $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
282 $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode;
283 $res->{$tag}->{$subfield}->{value_builder} = $value_builder;
284 $res->{$tag}->{$subfield}->{kohafield} = $kohafield;
285 $res->{$tag}->{$subfield}->{seealso} = $seealso;
286 $res->{$tag}->{$subfield}->{hidden} = $hidden;
287 $res->{$tag}->{$subfield}->{isurl} = $isurl;
292 sub MARCfind_marc_from_kohafield {
293 my ( $dbh, $kohafield,$frameworkcode ) = @_;
294 return 0, 0 unless $kohafield;
297 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
299 $sth->execute($frameworkcode,$kohafield);
300 my ( $tagfield, $tagsubfield ) = $sth->fetchrow;
301 return ( $tagfield, $tagsubfield );
304 sub MARCfind_oldbiblionumber_from_MARCbibid {
305 my ( $dbh, $MARCbibid ) = @_;
307 $dbh->prepare("select biblionumber from marc_biblio where bibid=?");
308 $sth->execute($MARCbibid);
309 my ($biblionumber) = $sth->fetchrow;
310 return $biblionumber;
313 sub MARCfind_MARCbibid_from_oldbiblionumber {
314 my ( $dbh, $oldbiblionumber ) = @_;
316 $dbh->prepare("select bibid from marc_biblio where biblionumber=?");
317 $sth->execute($oldbiblionumber);
318 my ($bibid) = $sth->fetchrow;
324 # pass the MARC::Record to this function, and it will create the records in the marc tables
325 my ($dbh,$record,$biblionumber,$frameworkcode,$bibid) = @_;
326 my @fields=$record->fields();
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) = @_;
378 # search for MARC biblionumber
379 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
380 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
381 my @fields=$record->fields();
382 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
383 $sth->execute($bibid);
384 my ($fieldcount) = $sth->fetchrow;
386 # now, add subfields...
387 foreach my $field (@fields) {
388 my @subfields = $field->subfields();
390 foreach my $subfieldcount ( 0 .. $#subfields ) {
395 $field->indicator(1) . $field->indicator(2),
397 $subfields[$subfieldcount][0],
399 $subfields[$subfieldcount][1]
403 $dbh->do("unlock tables");
407 sub MARCaddsubfield {
409 # Add a new subfield to a tag into the DB.
411 $dbh, $bibid, $tagid, $tag_indicator,
412 $tagorder, $subfieldcode, $subfieldorder, $subfieldvalues
415 # warn "$tagid / $subfieldcode / $subfieldvalues";
416 # if not value, end of job, we do nothing
417 # if ( length($subfieldvalues) == 0 ) {
420 if ( not($subfieldcode) ) {
423 my @subfieldvalues = split /\||#/, $subfieldvalues;
424 foreach my $subfieldvalue (@subfieldvalues) {
425 if ( length($subfieldvalue) > 255 ) {
427 "lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE"
431 "insert into marc_blob_subfield (subfieldvalue) values (?)");
432 $sth->execute($subfieldvalue);
434 $dbh->prepare("select max(blobidlink)from marc_blob_subfield");
436 my ($res) = $sth->fetchrow;
439 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?,?)"
441 $sth->execute( $bibid, ( sprintf "%03s", $tagid ), $tagorder,
442 $tag_indicator, $subfieldcode, $subfieldorder, $res );
444 if ( $sth->errstr ) {
446 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
448 $dbh->do("unlock tables");
453 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)"
456 $bibid, ( sprintf "%03s", $tagid ),
457 $tagorder, $tag_indicator,
458 $subfieldcode, $subfieldorder,
461 if ( $sth->errstr ) {
463 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
467 $dbh, $bibid, $tagid, $tagorder,
468 $subfieldcode, $subfieldorder, $subfieldvalue
475 # Returns MARC::Record of the biblio passed in parameter.
476 my ( $dbh, $bibid ) = @_;
477 my $record = MARC::Record->new();
479 #---- TODO : the leader is missing
480 $record->leader(' ');
483 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
484 from marc_subfield_table
485 where bibid=? order by tag,tagorder,subfieldcode
490 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
491 $sth->execute($bibid);
492 my $prevtagorder = 1;
495 my $field; # for >=10 tags
496 my $prevvalue; # for <10 tags
497 while ( my $row = $sth->fetchrow_hashref ) {
499 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
500 $sth2->execute( $row->{'valuebloblink'} );
501 my $row2 = $sth2->fetchrow_hashref;
503 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
505 if ( $row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag ) {
506 $previndicator .= " ";
507 if ( $prevtag < 10 ) {
508 $record->add_fields( ( sprintf "%03s", $prevtag ), $prevvalue )
509 unless $prevtag eq "XXX"; # ignore the 1st loop
512 $record->add_fields($field) unless $prevtag eq "XXX";
515 $prevtagorder = $row->{tagorder};
516 $prevtag = $row->{tag};
517 $previndicator = $row->{tag_indicator};
518 if ( $row->{tag} < 10 ) {
519 $prevvalue = $row->{subfieldvalue};
522 $field = MARC::Field->new(
523 ( sprintf "%03s", $prevtag ),
524 substr( $row->{tag_indicator} . ' ', 0, 1 ),
525 substr( $row->{tag_indicator} . ' ', 1, 1 ),
526 $row->{'subfieldcode'},
527 $row->{'subfieldvalue'}
532 if ( $row->{tag} < 10 ) {
533 $record->add_fields( ( sprintf "%03s", $row->{tag} ),
534 $row->{'subfieldvalue'} );
537 $field->add_subfields( $row->{'subfieldcode'},
538 $row->{'subfieldvalue'} );
540 $prevtag = $row->{tag};
541 $previndicator = $row->{tag_indicator};
545 # the last has not been included inside the loop... do it now !
546 if ( $prevtag ne "XXX" )
547 { # check that we have found something. Otherwise, prevtag is still XXX and we
548 # must return an empty record, not make MARC::Record fail because we try to
549 # create a record with XXX as field :-(
550 if ( $prevtag < 10 ) {
551 $record->add_fields( $prevtag, $prevvalue );
555 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
556 $record->add_fields($field);
564 # Returns MARC::Record of the biblio passed in parameter.
565 my ( $dbh, $bibid, $itemnumber ) = @_;
566 my $record = MARC::Record->new();
568 # search MARC tagorder
571 "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=?"
573 $sth2->execute( $bibid, $itemnumber );
574 my ($tagorder) = $sth2->fetchrow_array();
576 #---- TODO : the leader is missing
579 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
580 from marc_subfield_table
581 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
586 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
587 $sth->execute( $bibid, $tagorder );
588 while ( my $row = $sth->fetchrow_hashref ) {
589 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
590 $sth2->execute( $row->{'valuebloblink'} );
591 my $row2 = $sth2->fetchrow_hashref;
593 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
595 if ( $record->field( $row->{'tag'} ) ) {
598 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
599 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
600 if ( length( $row->{'tag'} ) < 3 ) {
601 $row->{'tag'} = "0" . $row->{'tag'};
603 $field = $record->field( $row->{'tag'} );
606 $field->add_subfields( $row->{'subfieldcode'},
607 $row->{'subfieldvalue'} );
608 $record->delete_field($field);
609 $record->add_fields($field);
613 if ( length( $row->{'tag'} ) < 3 ) {
614 $row->{'tag'} = "0" . $row->{'tag'};
617 MARC::Field->new( $row->{'tag'}, " ", " ",
618 $row->{'subfieldcode'} => $row->{'subfieldvalue'} );
619 $record->add_fields($temp);
627 my ($dbh,$bibid,$record,$frameworkcode,$delete)=@_;
628 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
629 if ($oldrecord eq $record) {
632 # 1st delete the biblio,
634 my $biblionumber = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
635 &MARCdelbiblio($dbh,$bibid,1);
636 &MARCaddbiblio($dbh,$record,$biblionumber,$frameworkcode,$bibid);
640 my ( $dbh, $bibid, $keep_items ) = @_;
642 # if the keep_item is set to 1, then all items are preserved.
643 # This flag is set when the delbiblio is called by modbiblio
644 # due to a too complex structure of MARC (repeatable fields and subfields),
645 # the best solution for a modif is to delete / recreate the record.
647 # 1st of all, copy the MARC::Record to deletedbiblio table => if a true deletion, MARC data will be kept.
648 # if deletion called before MARCmodbiblio => won't do anything, as the oldbiblionumber doesn't
649 # exist in deletedbiblio table
650 my $record = MARCgetbiblio( $dbh, $bibid );
651 my $oldbiblionumber =
652 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
654 $dbh->prepare("update deletedbiblio set marc=? where biblionumber=?");
655 $copy2deleted->execute( $record->as_usmarc(), $oldbiblionumber );
657 # now, delete in MARC tables.
658 if ( $keep_items eq 1 ) {
660 #search item field code
663 "select tagfield from marc_subfield_structure where kohafield like 'items.%'"
666 my $itemtag = $sth->fetchrow_hashref->{tagfield};
668 "delete from marc_subfield_table where bibid=$bibid and tag<>$itemtag"
671 "delete from marc_word where bibid=$bibid and not (tagsubfield like \"$itemtag%\")"
675 $dbh->do("delete from marc_biblio where bibid=$bibid");
676 $dbh->do("delete from marc_subfield_table where bibid=$bibid");
677 $dbh->do("delete from marc_word where bibid=$bibid");
683 # delete the item passed in parameter in MARC tables.
684 my ( $dbh, $bibid, $itemnumber ) = @_;
686 # my $record = MARC::Record->new();
687 # search MARC tagorder
688 my $record = MARCgetitem( $dbh, $bibid, $itemnumber );
690 $dbh->prepare("update deleteditems set marc=? where itemnumber=?");
691 $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
695 "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=?"
697 $sth2->execute( $bibid, $itemnumber );
698 my ($tagorder) = $sth2->fetchrow_array();
701 "delete from marc_subfield_table where bibid=? and tagorder=?");
702 $sth->execute( $bibid, $tagorder );
706 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
708 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
709 # if nothing to change, don't waste time...
710 if ($oldrecord eq $record) {
713 # otherwise, skip through each subfield...
714 my @fields = $record->fields();
715 # search old MARC item
716 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=?");
717 $sth2->execute($bibid,$itemnumber);
718 my ($tagorder) = $sth2->fetchrow_array();
719 foreach my $field (@fields) {
720 my $oldfield = $oldrecord->field($field->tag());
721 my @subfields=$field->subfields();
723 foreach my $subfield (@subfields) {
725 if ($oldfield eq 0 or (length($oldfield->subfield(@$subfield[0])) ==0) ) {
726 # just adding datas...
727 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
728 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
730 # modify he subfield if it's a different string
731 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
732 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
733 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
740 sub MARCmodsubfield {
742 # Subroutine changes a subfield value given a subfieldid.
743 my ( $dbh, $subfieldid, $subfieldvalue ) = @_;
744 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
747 "select valuebloblink from marc_subfield_table where subfieldid=?");
748 $sth1->execute($subfieldid);
749 my ($oldvaluebloblink) = $sth1->fetchrow;
753 # if too long, use a bloblink
754 if ( length($subfieldvalue) > 255 ) {
756 # if already a bloblink, update it, otherwise, insert a new one.
757 if ($oldvaluebloblink) {
760 "update marc_blob_subfield set subfieldvalue=? where blobidlink=?"
762 $sth->execute( $subfieldvalue, $oldvaluebloblink );
767 "insert into marc_blob_subfield (subfieldvalue) values (?)");
768 $sth->execute($subfieldvalue);
770 $dbh->prepare("select max(blobidlink) from marc_blob_subfield");
772 my ($res) = $sth->fetchrow;
775 "update marc_subfield_table set subfieldvalue=null, valuebloblink=? where subfieldid=?"
777 $sth->execute( $res, $subfieldid );
782 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
785 "update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?"
787 $sth->execute( $subfieldvalue, $subfieldid );
789 $dbh->do("unlock tables");
793 "select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?"
795 $sth->execute($subfieldid);
796 my ( $bibid, $tagid, $tagorder, $subfieldcode, $x, $subfieldorder ) =
799 &MARCdelword( $dbh, $bibid, $tagid, $tagorder, $subfieldcode,
802 $dbh, $bibid, $tagid, $tagorder,
803 $subfieldcode, $subfieldorder, $subfieldvalue
805 return ( $subfieldid, $subfieldvalue );
808 sub MARCfindsubfield {
809 my ( $dbh, $bibid, $tag, $subfieldcode, $subfieldorder, $subfieldvalue ) =
811 my $resultcounter = 0;
815 "select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
816 my @bind_values = ( $bibid, $tag, $subfieldcode );
817 if ($subfieldvalue) {
818 $query .= " and subfieldvalue=?";
819 push ( @bind_values, $subfieldvalue );
822 if ( $subfieldorder < 1 ) {
825 $query .= " and subfieldorder=?";
826 push ( @bind_values, $subfieldorder );
828 my $sti = $dbh->prepare($query);
829 $sti->execute(@bind_values);
830 while ( ($subfieldid) = $sti->fetchrow ) {
832 $lastsubfieldid = $subfieldid;
834 if ( $resultcounter > 1 ) {
836 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
837 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
841 return $lastsubfieldid;
845 sub MARCfindsubfieldid {
846 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
847 my $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
848 where bibid=? and tag=? and tagorder=?
849 and subfieldcode=? and subfieldorder=?"
851 $sth->execute( $bibid, $tag, $tagorder, $subfield, $subfieldorder );
852 my ($res) = $sth->fetchrow;
854 $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
855 where bibid=? and tag=? and tagorder=?
858 $sth->execute( $bibid, $tag, $tagorder, $subfield );
859 ($res) = $sth->fetchrow;
864 sub MARCfind_frameworkcode {
865 my ( $dbh, $bibid ) = @_;
867 $dbh->prepare("select frameworkcode from marc_biblio where bibid=?");
868 $sth->execute($bibid);
869 my ($frameworkcode) = $sth->fetchrow;
870 return $frameworkcode;
873 sub MARCdelsubfield {
875 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
876 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
877 $dbh->do( "delete from marc_subfield_table where bibid='$bibid' and
878 tag='$tag' and tagorder='$tagorder'
879 and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
884 sub MARCkoha2marcBiblio {
886 # this function builds partial MARC::Record from the old koha-DB fields
887 my ( $dbh, $biblionumber, $biblioitemnumber ) = @_;
890 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
892 my $record = MARC::Record->new();
894 #--- if bibid, then retrieve old-style koha data
895 if ( $biblionumber > 0 ) {
898 "select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
899 from biblio where biblionumber=?"
901 $sth2->execute($biblionumber);
902 my $row = $sth2->fetchrow_hashref;
904 foreach $code ( keys %$row ) {
905 if ( $row->{$code} ) {
906 &MARCkoha2marcOnefield( $sth, $record, "biblio." . $code,
912 #--- if biblioitem, then retrieve old-style koha data
913 if ( $biblioitemnumber > 0 ) {
916 " SELECT biblioitemnumber,biblionumber,volume,number,classification,
917 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
918 volumedate,volumeddesc,timestamp,illus,pages,notes AS bnotes,size,place
920 WHERE biblioitemnumber=?
923 $sth2->execute($biblioitemnumber);
924 my $row = $sth2->fetchrow_hashref;
926 foreach $code ( keys %$row ) {
927 if ( $row->{$code} ) {
928 &MARCkoha2marcOnefield( $sth, $record, "biblioitems." . $code,
934 # other fields => additional authors, subjects, subtitles
937 " SELECT author FROM additionalauthors WHERE biblionumber=?");
938 $sth2->execute($biblionumber);
939 while ( my $row = $sth2->fetchrow_hashref ) {
940 &MARCkoha2marcOnefield( $sth, $record, "additionalauthors.author",
941 $row->{'author'},'' );
944 $dbh->prepare(" SELECT subject FROM bibliosubject WHERE biblionumber=?");
945 $sth2->execute($biblionumber);
946 while ( my $row = $sth2->fetchrow_hashref ) {
947 &MARCkoha2marcOnefield( $sth, $record, "bibliosubject.subject",
948 $row->{'subject'},'' );
952 " SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?");
953 $sth2->execute($biblionumber);
954 while ( my $row = $sth2->fetchrow_hashref ) {
955 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.title",
956 $row->{'subtitle'},'' );
961 sub MARCkoha2marcItem {
963 # this function builds partial MARC::Record from the old koha-DB fields
964 my ( $dbh, $biblionumber, $itemnumber ) = @_;
966 # my $dbh=&C4Connect;
969 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
971 my $record = MARC::Record->new();
973 #--- if item, then retrieve old-style koha data
974 if ( $itemnumber > 0 ) {
976 # print STDERR "prepare $biblionumber,$itemnumber\n";
979 "SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
980 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
981 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,itemcallnumber,issues,renewals,
982 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
986 $sth2->execute($itemnumber);
987 my $row = $sth2->fetchrow_hashref;
989 foreach $code ( keys %$row ) {
990 if ( $row->{$code} ) {
991 &MARCkoha2marcOnefield( $sth, $record, "items." . $code,
999 sub MARCkoha2marcSubtitle {
1001 # this function builds partial MARC::Record from the old koha-DB fields
1002 my ( $dbh, $bibnum, $subtitle ) = @_;
1005 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
1007 my $record = MARC::Record->new();
1008 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle",
1013 sub MARCkoha2marcOnefield {
1014 my ( $sth, $record, $kohafieldname, $value,$frameworkcode ) = @_;
1017 $sth->execute($frameworkcode,$kohafieldname);
1018 if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
1019 if ( $record->field($tagfield) ) {
1020 my $tag = $record->field($tagfield);
1022 $tag->add_subfields( $tagsubfield, $value );
1023 $record->delete_field($tag);
1024 $record->add_fields($tag);
1028 $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
1035 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
1037 my $record = MARC::Record->new();
1038 # my %subfieldlist=();
1039 my $prevvalue; # if tag <10
1040 my $field; # if tag >=10
1041 for (my $i=0; $i< @$rtags; $i++) {
1042 # rebuild MARC::Record
1043 # warn "0=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ";
1044 if (@$rtags[$i] ne $prevtag) {
1045 if ($prevtag < 10) {
1047 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
1051 $record->add_fields($field);
1054 $indicators{@$rtags[$i]}.=' ';
1055 if (@$rtags[$i] <10) {
1056 $prevvalue= @$rvalues[$i];
1058 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
1059 # warn "1=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
1061 $prevtag = @$rtags[$i];
1063 if (@$rtags[$i] <10) {
1064 $prevvalue=@$rvalues[$i];
1066 if (length(@$rvalues[$i])>0) {
1067 $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
1068 # warn "2=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
1071 $prevtag= @$rtags[$i];
1074 # the last has not been included inside the loop... do it now !
1075 $record->add_fields($field);
1076 # warn "HTML2MARC=".$record->as_formatted;
1081 my ($dbh,$record,$frameworkcode) = @_;
1082 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?");
1084 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
1087 while (($field)=$sth2->fetchrow) {
1088 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result,$frameworkcode);
1090 $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
1092 while (($field)=$sth2->fetchrow) {
1093 if ($field eq 'notes') { $field = 'bnotes'; }
1094 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result,$frameworkcode);
1096 $sth2=$dbh->prepare("SHOW COLUMNS from items");
1098 while (($field)=$sth2->fetchrow) {
1099 $result=&MARCmarc2kohaOneField($sth,"items",$field,$record,$result,$frameworkcode);
1101 # additional authors : specific
1102 $result = &MARCmarc2kohaOneField($sth,"bibliosubtitle","subtitle",$record,$result,$frameworkcode);
1103 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result,$frameworkcode);
1104 # modify copyrightdate to keep only the 1st year found
1105 my $temp = $result->{'copyrightdate'};
1106 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1108 $result->{'copyrightdate'} = $1;
1109 } else { # if no cYYYY, get the 1st date.
1110 $temp =~ m/(\d\d\d\d)/;
1111 $result->{'copyrightdate'} = $1;
1113 # modify publicationyear to keep only the 1st year found
1114 my $temp = $result->{'publicationyear'};
1115 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1117 $result->{'publicationyear'} = $1;
1118 } else { # if no cYYYY, get the 1st date.
1119 $temp =~ m/(\d\d\d\d)/;
1120 $result->{'publicationyear'} = $1;
1125 sub MARCmarc2kohaOneField {
1127 # FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
1128 my ( $sth, $kohatable, $kohafield, $record, $result,$frameworkcode ) = @_;
1129 # warn "kohatable / $kohafield / $result / ";
1133 $sth->execute($frameworkcode, $kohatable . "." . $kohafield );
1134 ( $tagfield, $subfield ) = $sth->fetchrow;
1135 foreach my $field ( $record->field($tagfield) ) {
1136 if ( $field->subfield($subfield) ) {
1137 if ( $result->{$kohafield} ) {
1138 $result->{$kohafield} .= " | " . $field->subfield($subfield);
1141 $result->{$kohafield} = $field->subfield($subfield);
1145 # warn "OneField for $kohatable.$kohafield and $frameworkcode=> $tagfield, $subfield";
1151 # split a subfield string and adds it into the word table.
1154 $dbh, $bibid, $tag, $tagorder,
1155 $subfieldid, $subfieldorder, $sentence
1158 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\})/ /g;
1159 my @words = split / /, $sentence;
1160 my $stopwords = C4::Context->stopwords;
1163 "insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word)
1164 values (?,concat(?,?),?,?,?,soundex(?))"
1166 foreach my $word (@words) {
1167 # we record only words one char long and not in stopwords hash
1168 if (length($word)>=1 and !($stopwords->{uc($word)})) {
1169 $sth->execute($bibid,$tag,$subfieldid,$tagorder,$subfieldorder,$word,$word);
1171 warn "ERROR ==> insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word) values ($bibid,concat($tag,$subfieldid),$tagorder,$subfieldorder,$word,soundex($word))\n";
1179 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
1180 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
1183 "delete from marc_word where bibid=? and tagsubfield=concat(?,?) and tagorder=? and subfieldorder=?"
1185 $sth->execute( $bibid, $tag, $subfield, $tagorder, $subfieldorder );
1190 # NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW
1193 # all the following subs are useful to manage MARC-DB with complete MARC records.
1194 # it's used with marcimport, and marc management tools
1197 =item ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
1199 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
1200 are builded from the MARC::Record. If they are passed, they are used.
1202 =item NEWnewitem($dbh, $record,$bibid);
1204 adds an item in the db.
1209 my ( $dbh, $record, $frameworkcode ) = @_;
1212 my $olddata = MARCmarc2koha( $dbh, $record,$frameworkcode );
1213 $oldbibnum = OLDnewbiblio( $dbh, $olddata );
1214 $olddata->{'biblionumber'} = $oldbibnum;
1215 $oldbibitemnum = OLDnewbiblioitem( $dbh, $olddata );
1217 # search subtiles, addiauthors and subjects
1218 my ( $tagfield, $tagsubfield ) =
1219 MARCfind_marc_from_kohafield( $dbh, "additionalauthors.author",$frameworkcode );
1220 my @addiauthfields = $record->field($tagfield);
1221 foreach my $addiauthfield (@addiauthfields) {
1222 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1223 foreach my $subfieldcount ( 0 .. $#addiauthsubfields ) {
1224 OLDmodaddauthor( $dbh, $oldbibnum,
1225 $addiauthsubfields[$subfieldcount] );
1228 ( $tagfield, $tagsubfield ) =
1229 MARCfind_marc_from_kohafield( $dbh, "bibliosubtitle.title",$frameworkcode );
1230 my @subtitlefields = $record->field($tagfield);
1231 foreach my $subtitlefield (@subtitlefields) {
1232 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1233 foreach my $subfieldcount ( 0 .. $#subtitlesubfields ) {
1234 OLDnewsubtitle( $dbh, $oldbibnum,
1235 $subtitlesubfields[$subfieldcount] );
1238 ( $tagfield, $tagsubfield ) =
1239 MARCfind_marc_from_kohafield( $dbh, "bibliosubject.subject",$frameworkcode );
1240 my @subj = $record->field($tagfield);
1242 foreach my $subject (@subj) {
1243 my @subjsubfield = $subject->subfield($tagsubfield);
1244 foreach my $subfieldcount ( 0 .. $#subjsubfield ) {
1245 push @subjects, $subjsubfield[$subfieldcount];
1248 OLDmodsubject( $dbh, $oldbibnum, 1, @subjects );
1250 # we must add bibnum and bibitemnum in MARC::Record...
1251 # we build the new field with biblionumber and biblioitemnumber
1252 # we drop the original field
1253 # we add the new builded field.
1254 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
1255 # (steve and paul : thinks 090 is a good choice)
1258 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
1260 $sth->execute("biblio.biblionumber");
1261 ( my $tagfield1, my $tagsubfield1 ) = $sth->fetchrow;
1262 $sth->execute("biblioitems.biblioitemnumber");
1263 ( my $tagfield2, my $tagsubfield2 ) = $sth->fetchrow;
1264 if ( $tagfield1 != $tagfield2 ) {
1266 "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1268 "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1271 my $newfield = MARC::Field->new(
1272 $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
1273 "$tagsubfield2" => $oldbibitemnum
1276 # drop old field and create new one...
1277 my $old_field = $record->field($tagfield1);
1278 $record->delete_field($old_field);
1279 $record->add_fields($newfield);
1280 my $bibid = MARCaddbiblio( $dbh, $record, $oldbibnum, $frameworkcode );
1281 return ( $bibid, $oldbibnum, $oldbibitemnum );
1285 my ($dbh,$record,$bibid,$frameworkcode) =@_;
1286 $frameworkcode="" unless $frameworkcode;
1287 &MARCmodbiblio($dbh,$bibid,$record,$frameworkcode,0);
1288 my $oldbiblio = MARCmarc2koha($dbh,$record,$frameworkcode);
1289 my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
1290 OLDmodbibitem($dbh,$oldbiblio);
1291 # now, modify addi authors, subject, addititles.
1292 my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"additionalauthors.author",$frameworkcode);
1293 my @addiauthfields = $record->field($tagfield);
1294 foreach my $addiauthfield (@addiauthfields) {
1295 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1296 foreach my $subfieldcount (0..$#addiauthsubfields) {
1297 OLDmodaddauthor($dbh,$oldbiblionumber,$addiauthsubfields[$subfieldcount]);
1300 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubtitle.subtitle",$frameworkcode);
1301 my @subtitlefields = $record->field($tagfield);
1302 foreach my $subtitlefield (@subtitlefields) {
1303 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1304 foreach my $subfieldcount (0..$#subtitlesubfields) {
1305 OLDmodsubtitle($dbh,$oldbiblionumber,$subtitlesubfields[$subfieldcount]);
1308 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject",$frameworkcode);
1309 my @subj = $record->field($tagfield);
1311 foreach my $subject (@subj) {
1312 my @subjsubfield = $subject->subfield($tagsubfield);
1313 foreach my $subfieldcount (0..$#subjsubfield) {
1314 push @subjects,$subjsubfield[$subfieldcount];
1317 OLDmodsubject($dbh,$oldbiblionumber,1,@subjects);
1322 my ( $dbh, $bibid ) = @_;
1323 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1324 &OLDdelbiblio( $dbh, $biblio );
1327 "select biblioitemnumber from biblioitems where biblionumber=?");
1328 $sth->execute($biblio);
1329 while ( my ($biblioitemnumber) = $sth->fetchrow ) {
1330 OLDdeletebiblioitem( $dbh, $biblioitemnumber );
1332 &MARCdelbiblio( $dbh, $bibid, 0 );
1336 my ( $dbh, $record, $bibid ) = @_;
1338 # add item in old-DB
1339 my $frameworkcode=MARCfind_frameworkcode($dbh,$bibid);
1340 my $item = &MARCmarc2koha( $dbh, $record,$frameworkcode );
1341 # needs old biblionumber and biblioitemnumber
1342 $item->{'biblionumber'} =
1343 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1346 "select biblioitemnumber from biblioitems where biblionumber=?");
1347 $sth->execute( $item->{'biblionumber'} );
1348 ( $item->{'biblioitemnumber'} ) = $sth->fetchrow;
1349 my ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, $item->{barcode} );
1351 # add itemnumber to MARC::Record before adding the item.
1354 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
1356 &MARCkoha2marcOnefield( $sth, $record, "items.itemnumber", $itemnumber,$frameworkcode );
1359 my $bib = &MARCadditem( $dbh, $record, $item->{'biblionumber'} );
1363 my ( $dbh, $record, $bibid, $itemnumber, $delete ) = @_;
1365 &MARCmoditem( $dbh, $record, $bibid, $itemnumber, $delete );
1366 my $frameworkcode=MARCfind_frameworkcode($dbh,$bibid);
1367 my $olditem = MARCmarc2koha( $dbh, $record,$frameworkcode );
1368 OLDmoditem( $dbh, $olditem );
1372 my ( $dbh, $bibid, $itemnumber ) = @_;
1373 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1374 &OLDdelitem( $dbh, $itemnumber );
1375 &MARCdelitem( $dbh, $bibid, $itemnumber );
1380 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
1384 =item $biblionumber = OLDnewbiblio($dbh,$biblio);
1386 adds a record in biblio table. Datas are in the hash $biblio.
1388 =item $biblionumber = OLDmodbiblio($dbh,$biblio);
1390 modify a record in biblio table. Datas are in the hash $biblio.
1392 =item OLDmodsubtitle($dbh,$bibnum,$subtitle);
1394 modify subtitles in bibliosubtitle table.
1396 =item OLDmodaddauthor($dbh,$bibnum,$author);
1398 adds or modify additional authors
1399 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1401 =item $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1403 modify/adds subjects
1405 =item OLDmodbibitem($dbh, $biblioitem);
1409 =item OLDmodnote($dbh,$bibitemnum,$note
1411 modify a note for a biblioitem
1413 =item OLDnewbiblioitem($dbh,$biblioitem);
1415 adds a biblioitem ($biblioitem is a hash with the values)
1417 =item OLDnewsubject($dbh,$bibnum);
1421 =item OLDnewsubtitle($dbh,$bibnum,$subtitle);
1423 create a new subtitle
1425 =item ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1427 create a item. $item is a hash and $barcode the barcode.
1429 =item OLDmoditem($dbh,$item);
1433 =item OLDdelitem($dbh,$itemnum);
1437 =item OLDdeletebiblioitem($dbh,$biblioitemnumber);
1439 deletes a biblioitem
1440 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1442 =item OLDdelbiblio($dbh,$biblio);
1449 my ( $dbh, $biblio ) = @_;
1451 # my $dbh = &C4Connect;
1452 my $sth = $dbh->prepare("Select max(biblionumber) from biblio");
1454 my $data = $sth->fetchrow_arrayref;
1455 my $bibnum = $$data[0] + 1;
1458 if ( $biblio->{'seriestitle'} ) { $series = 1 }
1462 "insert into biblio set biblionumber = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?"
1465 $bibnum, $biblio->{'title'},
1466 $biblio->{'author'}, $biblio->{'copyrightdate'},
1467 $biblio->{'serial'}, $biblio->{'seriestitle'},
1468 $biblio->{'notes'}, $biblio->{'abstract'}
1478 my ( $dbh, $biblio ) = @_;
1480 # my $dbh = C4Connect;
1487 "Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?, seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?"
1490 $biblio->{'title'}, $biblio->{'author'},
1491 $biblio->{'abstract'}, $biblio->{'copyrightdate'},
1492 $biblio->{'seriestitle'}, $biblio->{'serial'},
1493 $biblio->{'unititle'}, $biblio->{'notes'},
1494 $biblio->{'biblionumber'}
1498 return ( $biblio->{'biblionumber'} );
1501 sub OLDmodsubtitle {
1502 my ( $dbh, $bibnum, $subtitle ) = @_;
1505 "update bibliosubtitle set subtitle = ? where biblionumber = ?");
1506 $sth->execute( $subtitle, $bibnum );
1510 sub OLDmodaddauthor {
1511 my ( $dbh, $bibnum, @authors ) = @_;
1513 # my $dbh = C4Connect;
1515 $dbh->prepare("Delete from additionalauthors where biblionumber = ?");
1517 $sth->execute($bibnum);
1519 foreach my $author (@authors) {
1520 if ( $author ne '' ) {
1523 "Insert into additionalauthors set author = ?, biblionumber = ?"
1526 $sth->execute( $author, $bibnum );
1531 } # sub modaddauthor
1534 my ( $dbh, $bibnum, $force, @subject ) = @_;
1536 # my $dbh = C4Connect;
1537 my $count = @subject;
1539 for ( my $i = 0 ; $i < $count ; $i++ ) {
1540 $subject[$i] =~ s/^ //g;
1541 $subject[$i] =~ s/ $//g;
1544 "select * from catalogueentry where entrytype = 's' and catalogueentry = ?"
1546 $sth->execute( $subject[$i] );
1548 if ( my $data = $sth->fetchrow_hashref ) {
1551 if ( $force eq $subject[$i] || $force == 1 ) {
1553 # subject not in aut, chosen to force anway
1554 # so insert into cataloguentry so its in auth file
1557 "Insert into catalogueentry (entrytype,catalogueentry) values ('s',?)"
1560 $sth2->execute( $subject[$i] ) if ( $subject[$i] );
1565 "$subject[$i]\n does not exist in the subject authority file";
1568 "Select * from catalogueentry where entrytype = 's' and (catalogueentry like ? or catalogueentry like ? or catalogueentry like ?)"
1570 $sth2->execute( "$subject[$i] %", "% $subject[$i] %",
1572 while ( my $data = $sth2->fetchrow_hashref ) {
1573 $error .= "<br>$data->{'catalogueentry'}";
1580 if ( $error eq '' ) {
1582 $dbh->prepare("Delete from bibliosubject where biblionumber = ?");
1583 $sth->execute($bibnum);
1587 "Insert into bibliosubject (subject,biblionumber) values (?,?)");
1589 foreach $query (@subject) {
1590 $sth->execute( $query, $bibnum ) if ( $query && $bibnum );
1600 my ( $dbh, $biblioitem ) = @_;
1602 # my $dbh = C4Connect;
1605 $biblioitem->{'itemtype'} = $dbh->quote( $biblioitem->{'itemtype'} );
1606 $biblioitem->{'url'} = $dbh->quote( $biblioitem->{'url'} );
1607 $biblioitem->{'isbn'} = $dbh->quote( $biblioitem->{'isbn'} );
1608 $biblioitem->{'publishercode'} =
1609 $dbh->quote( $biblioitem->{'publishercode'} );
1610 $biblioitem->{'publicationyear'} =
1611 $dbh->quote( $biblioitem->{'publicationyear'} );
1612 $biblioitem->{'classification'} =
1613 $dbh->quote( $biblioitem->{'classification'} );
1614 $biblioitem->{'dewey'} = $dbh->quote( $biblioitem->{'dewey'} );
1615 $biblioitem->{'subclass'} = $dbh->quote( $biblioitem->{'subclass'} );
1616 $biblioitem->{'illus'} = $dbh->quote( $biblioitem->{'illus'} );
1617 $biblioitem->{'pages'} = $dbh->quote( $biblioitem->{'pages'} );
1618 $biblioitem->{'volumeddesc'} = $dbh->quote( $biblioitem->{'volumeddesc'} );
1619 $biblioitem->{'bnotes'} = $dbh->quote( $biblioitem->{'bnotes'} );
1620 $biblioitem->{'size'} = $dbh->quote( $biblioitem->{'size'} );
1621 $biblioitem->{'place'} = $dbh->quote( $biblioitem->{'place'} );
1623 $query = "Update biblioitems set
1624 itemtype = $biblioitem->{'itemtype'},
1625 url = $biblioitem->{'url'},
1626 isbn = $biblioitem->{'isbn'},
1627 publishercode = $biblioitem->{'publishercode'},
1628 publicationyear = $biblioitem->{'publicationyear'},
1629 classification = $biblioitem->{'classification'},
1630 dewey = $biblioitem->{'dewey'},
1631 subclass = $biblioitem->{'subclass'},
1632 illus = $biblioitem->{'illus'},
1633 pages = $biblioitem->{'pages'},
1634 volumeddesc = $biblioitem->{'volumeddesc'},
1635 notes = $biblioitem->{'bnotes'},
1636 size = $biblioitem->{'size'},
1637 place = $biblioitem->{'place'}
1638 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1641 if ( $dbh->errstr ) {
1649 my ( $dbh, $bibitemnum, $note ) = @_;
1651 # my $dbh=C4Connect;
1652 my $query = "update biblioitems set notes='$note' where
1653 biblioitemnumber='$bibitemnum'";
1654 my $sth = $dbh->prepare($query);
1661 sub OLDnewbiblioitem {
1662 my ( $dbh, $biblioitem ) = @_;
1664 # my $dbh = C4Connect;
1665 my $sth = $dbh->prepare("Select max(biblioitemnumber) from biblioitems");
1670 $data = $sth->fetchrow_arrayref;
1671 $bibitemnum = $$data[0] + 1;
1675 $sth = $dbh->prepare( "insert into biblioitems set
1676 biblioitemnumber = ?, biblionumber = ?,
1677 volume = ?, number = ?,
1678 classification = ?, itemtype = ?,
1680 issn = ?, dewey = ?,
1681 subclass = ?, publicationyear = ?,
1682 publishercode = ?, volumedate = ?,
1683 volumeddesc = ?, illus = ?,
1684 pages = ?, notes = ?,
1686 marc = ?, place = ?"
1689 $bibitemnum, $biblioitem->{'biblionumber'},
1690 $biblioitem->{'volume'}, $biblioitem->{'number'},
1691 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
1692 $biblioitem->{'url'}, $biblioitem->{'isbn'},
1693 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
1694 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
1695 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
1696 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
1697 $biblioitem->{'pages'}, $biblioitem->{'bnotes'},
1698 $biblioitem->{'size'}, $biblioitem->{'lccn'},
1699 $biblioitem->{'marc'}, $biblioitem->{'place'}
1704 return ($bibitemnum);
1708 my ( $dbh, $bibnum ) = @_;
1710 $dbh->prepare("insert into bibliosubject (biblionumber) values (?)");
1711 $sth->execute($bibnum);
1715 sub OLDnewsubtitle {
1716 my ( $dbh, $bibnum, $subtitle ) = @_;
1719 "insert into bibliosubtitle set biblionumber = ?, subtitle = ?");
1720 $sth->execute( $bibnum, $subtitle );
1725 my ( $dbh, $item, $barcode ) = @_;
1727 # my $dbh = C4Connect;
1728 my $sth = $dbh->prepare("Select max(itemnumber) from items");
1734 $data = $sth->fetchrow_hashref;
1735 $itemnumber = $data->{'max(itemnumber)'} + 1;
1738 # FIXME the "notforloan" field seems to be named "loan" in some places. workaround bugfix.
1739 if ( $item->{'loan'} ) {
1740 $item->{'notforloan'} = $item->{'loan'};
1743 # if dateaccessioned is provided, use it. Otherwise, set to NOW()
1744 if ( $item->{'dateaccessioned'} ) {
1745 $sth = $dbh->prepare( "Insert into items set
1746 itemnumber = ?, biblionumber = ?,
1747 biblioitemnumber = ?, barcode = ?,
1748 booksellerid = ?, dateaccessioned = ?,
1749 homebranch = ?, holdingbranch = ?,
1750 price = ?, replacementprice = ?,
1751 replacementpricedate = NOW(), itemnotes = ?,
1752 itemcallnumber =?, notforloan = ?,
1757 $itemnumber, $item->{'biblionumber'},
1758 $item->{'biblioitemnumber'}, $barcode,
1759 $item->{'booksellerid'}, $item->{'dateaccessioned'},
1760 $item->{'homebranch'}, $item->{'holdingbranch'},
1761 $item->{'price'}, $item->{'replacementprice'},
1762 $item->{'itemnotes'}, $item->{'itemcallnumber'},
1763 $item->{'notforloan'}, $item->{'location'}
1767 $sth = $dbh->prepare( "Insert into items set
1768 itemnumber = ?, biblionumber = ?,
1769 biblioitemnumber = ?, barcode = ?,
1770 booksellerid = ?, dateaccessioned = NOW(),
1771 homebranch = ?, holdingbranch = ?,
1772 price = ?, replacementprice = ?,
1773 replacementpricedate = NOW(), itemnotes = ?,
1774 itemcallnumber = ? , notforloan = ?,
1779 $itemnumber, $item->{'biblionumber'},
1780 $item->{'biblioitemnumber'}, $barcode,
1781 $item->{'booksellerid'}, $item->{'homebranch'},
1782 $item->{'holdingbranch'}, $item->{'price'},
1783 $item->{'replacementprice'}, $item->{'itemnotes'},
1784 $item->{'itemcallnumber'}, $item->{'notforloan'},
1788 if ( defined $sth->errstr ) {
1789 $error .= $sth->errstr;
1792 return ( $itemnumber, $error );
1796 my ( $dbh, $item ) = @_;
1798 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1799 # my $dbh=C4Connect;
1800 $item->{'itemnum'} = $item->{'itemnumber'} unless $item->{'itemnum'};
1801 my $query = "update items set barcode=?,itemnotes=?,itemcallnumber=?,notforloan=? where itemnumber=?";
1803 $item->{'barcode'}, $item->{'notes'},
1804 $item->{'itemcallnumber'}, $item->{'notforloan'},
1807 if ( $item->{'barcode'} eq '' ) {
1808 $item->{'notforloan'} = 0 unless $item->{'notforloan'};
1809 $query = "update items set notforloan=? where itemnumber=?";
1810 @bind = ( $item->{'notforloan'}, $item->{'itemnum'} );
1812 if ( $item->{'lost'} ne '' ) {
1813 $query = "update items set biblioitemnumber=?,
1823 $item->{'bibitemnum'}, $item->{'barcode'},
1824 $item->{'notes'}, $item->{'homebranch'},
1825 $item->{'lost'}, $item->{'wthdrawn'},
1826 $item->{'itemcallnumber'}, $item->{'notforloan'},
1827 $item->{'location'}, $item->{'itemnum'}
1829 if ($item->{homebranch}) {
1830 $query.=",homebranch=?";
1831 push @bind, $item->{homebranch};
1833 if ($item->{holdingbranch}) {
1834 $query.=",holdingbranch=?";
1835 push @bind, $item->{holdingbranch};
1837 $query.=" where itemnumber=?";
1839 if ( $item->{'replacement'} ne '' ) {
1840 $query =~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1842 my $sth = $dbh->prepare($query);
1843 $sth->execute(@bind);
1850 my ( $dbh, $itemnum ) = @_;
1852 # my $dbh=C4Connect;
1853 my $sth = $dbh->prepare("select * from items where itemnumber=?");
1854 $sth->execute($itemnum);
1855 my $data = $sth->fetchrow_hashref;
1857 my $query = "Insert into deleteditems set ";
1859 foreach my $temp ( keys %$data ) {
1860 $query .= "$temp = ?,";
1861 push ( @bind, $data->{$temp} );
1866 $sth = $dbh->prepare($query);
1867 $sth->execute(@bind);
1869 $sth = $dbh->prepare("Delete from items where itemnumber=?");
1870 $sth->execute($itemnum);
1876 sub OLDdeletebiblioitem {
1877 my ( $dbh, $biblioitemnumber ) = @_;
1879 # my $dbh = C4Connect;
1880 my $sth = $dbh->prepare( "Select * from biblioitems
1881 where biblioitemnumber = ?"
1885 $sth->execute($biblioitemnumber);
1887 if ( $results = $sth->fetchrow_hashref ) {
1891 "Insert into deletedbiblioitems (biblioitemnumber, biblionumber, volume, number, classification, itemtype,
1892 isbn, issn ,dewey ,subclass ,publicationyear ,publishercode ,volumedate ,volumeddesc ,timestamp ,illus ,
1893 pages ,notes ,size ,url ,lccn ) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
1897 $results->{biblioitemnumber}, $results->{biblionumber},
1898 $results->{volume}, $results->{number},
1899 $results->{classification}, $results->{itemtype},
1900 $results->{isbn}, $results->{issn},
1901 $results->{dewey}, $results->{subclass},
1902 $results->{publicationyear}, $results->{publishercode},
1903 $results->{volumedate}, $results->{volumeddesc},
1904 $results->{timestamp}, $results->{illus},
1905 $results->{pages}, $results->{notes},
1906 $results->{size}, $results->{url},
1910 $dbh->prepare("Delete from biblioitems where biblioitemnumber = ?");
1911 $sth2->execute($biblioitemnumber);
1916 # Now delete all the items attached to the biblioitem
1917 $sth = $dbh->prepare("Select * from items where biblioitemnumber = ?");
1918 $sth->execute($biblioitemnumber);
1920 while ( my $data = $sth->fetchrow_hashref ) {
1921 my $query = "Insert into deleteditems set ";
1923 foreach my $temp ( keys %$data ) {
1924 $query .= "$temp = ?,";
1925 push ( @bind, $data->{$temp} );
1928 my $sth2 = $dbh->prepare($query);
1929 $sth2->execute(@bind);
1932 $sth = $dbh->prepare("Delete from items where biblioitemnumber = ?");
1933 $sth->execute($biblioitemnumber);
1937 } # sub deletebiblioitem
1940 my ( $dbh, $biblio ) = @_;
1941 my $sth = $dbh->prepare("select * from biblio where biblionumber=?");
1942 $sth->execute($biblio);
1943 if ( my $data = $sth->fetchrow_hashref ) {
1945 my $query = "Insert into deletedbiblio set ";
1947 foreach my $temp ( keys %$data ) {
1948 $query .= "$temp = ?,";
1949 push ( @bind, $data->{$temp} );
1952 #replacing the last , by ",?)"
1954 $sth = $dbh->prepare($query);
1955 $sth->execute(@bind);
1957 $sth = $dbh->prepare("Delete from biblio where biblionumber=?");
1958 $sth->execute($biblio);
1972 my $dbh = C4::Context->dbh;
1975 my $sth = $dbh->prepare("Select count(*) from items where biblionumber=?");
1976 $sth->execute($biblio);
1977 my $data = $sth->fetchrow_hashref;
1979 return ( $data->{'count(*)'} );
1984 my $dbh = C4::Context->dbh;
1985 my $bibnum = OLDnewbiblio( $dbh, $biblio );
1987 # finds new (MARC bibid
1988 # my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
1989 my $record = &MARCkoha2marcBiblio( $dbh, $bibnum );
1990 MARCaddbiblio( $dbh, $record, $bibnum,'' );
1996 $biblionumber = &modbiblio($biblio);
1998 Update a biblio record.
2000 C<$biblio> is a reference-to-hash whose keys are the fields in the
2001 biblio table in the Koha database. All fields must be present, not
2002 just the ones you wish to change.
2004 C<&modbiblio> updates the record defined by
2005 C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
2007 C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
2014 my $dbh = C4::Context->dbh;
2015 my $biblionumber=OLDmodbiblio($dbh,$biblio);
2016 my $record = MARCkoha2marcBiblio($dbh,$biblionumber,$biblionumber);
2017 # finds new (MARC bibid
2018 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
2019 MARCmodbiblio($dbh,$bibid,$record,"",0);
2020 return($biblionumber);
2025 &modsubtitle($biblionumber, $subtitle);
2027 Sets the subtitle of a book.
2029 C<$biblionumber> is the biblionumber of the book to modify.
2031 C<$subtitle> is the new subtitle.
2036 my ( $bibnum, $subtitle ) = @_;
2037 my $dbh = C4::Context->dbh;
2038 &OLDmodsubtitle( $dbh, $bibnum, $subtitle );
2043 &modaddauthor($biblionumber, $author);
2045 Replaces all additional authors for the book with biblio number
2046 C<$biblionumber> with C<$author>. If C<$author> is the empty string,
2047 C<&modaddauthor> deletes all additional authors.
2052 my ( $bibnum, @authors ) = @_;
2053 my $dbh = C4::Context->dbh;
2054 &OLDmodaddauthor( $dbh, $bibnum, @authors );
2055 } # sub modaddauthor
2059 $error = &modsubject($biblionumber, $force, @subjects);
2061 $force - a subject to force
2063 $error - Error message, or undef if successful.
2068 my ( $bibnum, $force, @subject ) = @_;
2069 my $dbh = C4::Context->dbh;
2070 my $error = &OLDmodsubject( $dbh, $bibnum, $force, @subject );
2075 my ($biblioitem) = @_;
2076 my $dbh = C4::Context->dbh;
2077 &OLDmodbibitem( $dbh, $biblioitem );
2081 my ( $bibitemnum, $note ) = @_;
2082 my $dbh = C4::Context->dbh;
2083 &OLDmodnote( $dbh, $bibitemnum, $note );
2087 my ($biblioitem) = @_;
2088 my $dbh = C4::Context->dbh;
2089 my $bibitemnum = &OLDnewbiblioitem( $dbh, $biblioitem );
2091 ################################################################
2092 ## Fix template and shift this to newbiblio
2093 my @subjects = split ( /\n/, $biblioitem->{'subjectheadings'} );
2094 modsubject( $biblioitem->{'biblionumber'}, 1, @subjects );
2096 ################################################################
2098 MARCkoha2marcBiblio( $dbh, 0, $bibitemnum )
2099 ; # the 0 means "do NOT retrieve biblio, only biblioitem, in the MARC record
2101 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh,
2102 $biblioitem->{biblionumber} );
2103 &MARCaddbiblio( $dbh, $MARCbiblio, $biblioitem->{biblionumber}, $bibid );
2104 return ($bibitemnum);
2109 my $dbh = C4::Context->dbh;
2110 &OLDnewsubject( $dbh, $bibnum );
2114 my ( $bibnum, $subtitle ) = @_;
2115 my $dbh = C4::Context->dbh;
2116 &OLDnewsubtitle( $dbh, $bibnum, $subtitle );
2120 my ( $item, @barcodes ) = @_;
2121 my $dbh = C4::Context->dbh;
2125 foreach my $barcode (@barcodes) {
2126 ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, uc($barcode) );
2129 &MARCkoha2marcItem( $dbh, $item->{biblionumber}, $itemnumber );
2130 &MARCadditem( $dbh, $MARCitem, $item->{biblionumber} );
2137 my $dbh = C4::Context->dbh;
2138 &OLDmoditem( $dbh, $item );
2140 &MARCkoha2marcItem( $dbh, $item->{'biblionumber'}, $item->{'itemnum'} );
2142 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $item->{biblionumber} );
2143 &MARCmoditem( $dbh, $MARCitem, $bibid, $item->{itemnum}, 0 );
2147 my ( $count, @barcodes ) = @_;
2148 my $dbh = C4::Context->dbh;
2150 my $sth = $dbh->prepare("Select * from items where barcode=?");
2151 for ( my $i = 0 ; $i < $count ; $i++ ) {
2152 $barcodes[$i] = uc $barcodes[$i];
2153 $sth->execute( $barcodes[$i] );
2154 if ( my $data = $sth->fetchrow_hashref ) {
2155 $error .= " Duplicate Barcode: $barcodes[$i]";
2163 my ($bibitemnum) = @_;
2164 my $dbh = C4::Context->dbh;
2167 $dbh->prepare("Select count(*) from items where biblioitemnumber=?");
2168 $sth->execute($bibitemnum);
2169 my $data = $sth->fetchrow_hashref;
2171 return ( $data->{'count(*)'} );
2176 my $dbh = C4::Context->dbh;
2177 &OLDdelitem( $dbh, $itemnum );
2180 sub deletebiblioitem {
2181 my ($biblioitemnumber) = @_;
2182 my $dbh = C4::Context->dbh;
2183 &OLDdeletebiblioitem( $dbh, $biblioitemnumber );
2184 } # sub deletebiblioitem
2188 my $dbh = C4::Context->dbh;
2189 &OLDdelbiblio( $dbh, $biblio );
2190 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $biblio );
2191 &MARCdelbiblio( $dbh, $bibid, 0 );
2195 my ($biblionumber) = @_;
2196 my $dbh = C4::Context->dbh;
2197 my $sth = $dbh->prepare("Select * from biblio where biblionumber = ?");
2199 # || die "Cannot prepare $query\n" . $dbh->errstr;
2203 $sth->execute($biblionumber);
2205 # || die "Cannot execute $query\n" . $sth->errstr;
2206 while ( my $data = $sth->fetchrow_hashref ) {
2207 $results[$count] = $data;
2212 return ( $count, @results );
2216 my ($biblioitemnum) = @_;
2217 my $dbh = C4::Context->dbh;
2218 my $sth = $dbh->prepare( "Select * from biblioitems where
2219 biblioitemnumber = ?"
2224 $sth->execute($biblioitemnum);
2226 while ( my $data = $sth->fetchrow_hashref ) {
2227 $results[$count] = $data;
2232 return ( $count, @results );
2233 } # sub getbiblioitem
2235 sub getbiblioitembybiblionumber {
2236 my ($biblionumber) = @_;
2237 my $dbh = C4::Context->dbh;
2238 my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?");
2242 $sth->execute($biblionumber);
2244 while ( my $data = $sth->fetchrow_hashref ) {
2245 $results[$count] = $data;
2250 return ( $count, @results );
2254 my $dbh = C4::Context->dbh;
2255 my $query = "select * from itemtypes order by description";
2256 my $sth = $dbh->prepare($query);
2258 # || die "Cannot prepare $query" . $dbh->errstr;
2264 # || die "Cannot execute $query\n" . $sth->errstr;
2265 while ( my $data = $sth->fetchrow_hashref ) {
2266 $results[$count] = $data;
2271 return ( $count, @results );
2272 } # sub getitemtypes
2274 sub getitemsbybiblioitem {
2275 my ($biblioitemnum) = @_;
2276 my $dbh = C4::Context->dbh;
2277 my $sth = $dbh->prepare( "Select * from items, biblio where
2278 biblio.biblionumber = items.biblionumber and biblioitemnumber
2282 # || die "Cannot prepare $query\n" . $dbh->errstr;
2286 $sth->execute($biblioitemnum);
2288 # || die "Cannot execute $query\n" . $sth->errstr;
2289 while ( my $data = $sth->fetchrow_hashref ) {
2290 $results[$count] = $data;
2295 return ( $count, @results );
2296 } # sub getitemsbybiblioitem
2300 # Subroutine to log changes to databases
2301 # Eventually, this subroutine will be used to create a log of all changes made,
2302 # with the possibility of "undo"ing some changes
2303 my $database = shift;
2304 if ( $database eq 'kohadb' ) {
2306 my $section = shift;
2308 my $original = shift;
2311 # print STDERR "KOHA: $type $section $item $original $new\n";
2313 elsif ( $database eq 'marc' ) {
2315 my $Record_ID = shift;
2318 my $subfield_ID = shift;
2319 my $original = shift;
2322 # print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2326 #------------------------------------------------
2328 #---------------------------------------
2329 # Find a biblio entry, or create a new one if it doesn't exist.
2330 # If a "subtitle" entry is in hash, add it to subtitle table
2331 sub getoraddbiblio {
2336 # FIXME - Unused argument
2337 $biblio, # hash ref to fields
2348 $dbh = C4::Context->dbh;
2350 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2351 $sth = $dbh->prepare( "select biblionumber
2353 where title=? and author=?
2354 and copyrightdate=? and seriestitle=?"
2357 $biblio->{title}, $biblio->{author},
2358 $biblio->{copyright}, $biblio->{seriestitle}
2361 ($biblionumber) = $sth->fetchrow;
2362 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2366 # Doesn't exist. Add new one.
2367 print "<PRE>Adding biblio</PRE>\n" if $debug;
2368 ( $biblionumber, $error ) = &newbiblio($biblio);
2369 if ($biblionumber) {
2370 print "<PRE>Added with biblio number=$biblionumber</PRE>\n"
2372 if ( $biblio->{subtitle} ) {
2373 &newsubtitle( $biblionumber, $biblio->{subtitle} );
2377 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2381 return $biblionumber, $error;
2383 } # sub getoraddbiblio
2387 # converts ISO 5426 coded string to ISO 8859-1
2388 # sloppy code : should be improved in next issue
2389 my ( $string, $encoding ) = @_;
2392 # $encoding = C4::Context->preference("marcflavour") unless $encoding;
2393 if ( $encoding eq "UNIMARC" ) {
2456 # this handles non-sorting blocks (if implementation requires this)
2457 $string = nsb_clean($_);
2459 elsif ( $encoding eq "USMARC" || $encoding eq "MARC21" ) {
2460 if (/[\xc1-\xff]/) {
2513 # this handles non-sorting blocks (if implementation requires this)
2514 $string = nsb_clean($_);
2521 my $NSB = '\x88'; # NSB : begin Non Sorting Block
2522 my $NSE = '\x89'; # NSE : Non Sorting Block end
2523 # handles non sorting blocks
2527 s/[ ]{0,1}$NSE/) /gm;
2534 my $dbh = C4::Context->dbh;
2535 my $result = MARCmarc2koha($dbh,$record,'');
2536 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=?");
2537 $sth->execute($result->{'isbn'});
2538 my ($biblionumber,$bibid,$title) = $sth->fetchrow;
2539 return $biblionumber,$bibid,$title;
2542 END { } # module clean-up code here (global destructor)
2548 Koha Developement team <info@koha.org>
2550 Paul POULAIN paul.poulain@free.fr
2556 # Revision 1.106 2004/11/02 16:44:45 tipaul
2557 # new feature : checking for duplicate biblio.
2559 # For instance, it's only done on ISBN only. Will be improved soon.
2561 # When a duplicate is detected, the biblio is not saved, but the user is asked for a confirmations.
2563 # Revision 1.105 2004/09/23 16:15:37 tipaul
2566 # Revision 1.104 2004/09/16 15:06:46 tipaul
2567 # enabling # (| still possible too) for repeatable subfields
2569 # Revision 1.103 2004/09/06 14:17:34 tipaul
2570 # some commented warning added + 1 major bugfix => drop empty fields, NOT fields containing 0
2572 # Revision 1.102 2004/09/06 10:00:19 tipaul
2573 # adding a "location" field to the library.
2574 # This field is useful when the callnumber contains no information on the room where the item is stored.
2575 # With this field, we now have 3 levels of informations to find a book :
2580 # This should be versatile enough to solve any storing method.
2581 # 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.
2583 # Revision 1.101 2004/08/18 16:01:37 tipaul
2584 # modifs to support frameworkcodes
2586 # Revision 1.100 2004/08/13 16:37:25 tipaul
2587 # adding frameworkcode to API in some subs
2589 # Revision 1.99 2004/07/30 13:54:50 doxulting
2590 # Beginning of serial commit
2592 # Revision 1.98 2004/07/15 09:48:10 tipaul
2593 # * removing useless sub
2594 # * minor bugfix in moditem (managing homebranch & holdingbranch)
2596 # Revision 1.97 2004/07/02 15:53:53 tipaul
2597 # bugfix (due to frameworkcode field)
2599 # Revision 1.96 2004/06/29 16:07:10 tipaul
2600 # last sync for 2.1.0 release
2602 # Revision 1.95 2004/06/26 23:19:59 rangi
2603 # Fixing modaddauthor, and adding getitemtypes.
2604 # Also tidying up formatting of code
2606 # Revision 1.94 2004/06/17 08:16:32 tipaul
2607 # merging tag & subfield in marc_word for better perfs
2609 # Revision 1.93 2004/06/11 15:38:06 joshferraro
2610 # Changes MARCaddword to index words >= 1 char ... needed for more accurate
2611 # searches using SearchMarc routines.
2613 # Revision 1.92 2004/06/10 08:29:01 tipaul
2614 # MARC authority management (continued)
2616 # Revision 1.91 2004/06/03 10:03:01 tipaul
2617 # * frameworks and itemtypes are independant
2618 # * in the MARC editor, showing the + to duplicate a tag only if the tag is repeatable
2620 # Revision 1.90 2004/05/28 08:25:53 tipaul
2621 # hidding hidden & isurl constraints into MARC subfield structure
2623 # Revision 1.89 2004/05/27 21:47:21 rangi
2626 # Revision 1.88 2004/05/18 15:23:49 tipaul
2627 # framework management : 1 MARC framework for each itemtype
2629 # Revision 1.87 2004/05/18 11:54:07 tipaul
2630 # getitemtypes moved in Koha.pm
2632 # Revision 1.86 2004/05/03 09:19:22 tipaul
2633 # some fixes for mysql prepare & execute
2635 # Revision 1.85 2004/04/02 14:55:48 tipaul
2636 # renaming items.bulk field to items.itemcallnumber.
2637 # Will be used to store call number for libraries that don't use dewey classification.
2638 # Note it's related to ITEMS, not biblio.
2640 # Revision 1.84 2004/03/24 17:18:30 joshferraro
2641 # Fixes bug 749 by removing the comma on line 1488.
2643 # Revision 1.83 2004/03/15 14:31:50 tipaul
2644 # adding a minor check
2646 # Revision 1.82 2004/03/07 05:47:31 acli
2647 # Various updates/fixes from rel_2_0
2648 # Fixes for bugs 721 (templating), 727, and 734
2650 # Revision 1.81 2004/03/06 20:26:13 tipaul
2651 # adding seealso feature in MARC searches
2653 # Revision 1.80 2004/02/12 13:40:56 tipaul
2654 # deleting subs duplicated by error
2656 # Revision 1.79 2004/02/11 08:40:09 tipaul
2657 # synch'ing 2.0.0 branch and head
2659 # Revision 1.78.2.3 2004/02/10 13:15:46 tipaul
2660 # removing 2 warnings
2662 # Revision 1.78.2.2 2004/01/26 10:38:06 tipaul
2663 # dealing correctly "bulk" field
2665 # Revision 1.78.2.1 2004/01/13 17:29:53 tipaul
2666 # * minor html fixes
2667 # * adding publisher in acquisition process (& ordering basket by publisher)
2669 # Revision 1.78 2003/12/09 15:57:28 tipaul
2670 # rolling back to working char_decode sub
2672 # Revision 1.77 2003/12/03 17:47:14 tipaul
2673 # bugfixes for biblio deletion
2675 # Revision 1.76 2003/12/03 01:43:41 slef
2678 # Revision 1.75 2003/12/03 01:42:03 slef
2679 # bug 662 fixes securing DBI
2681 # Revision 1.74 2003/11/28 09:48:33 tipaul
2682 # bugfix : misusing prepare & execute => now using prepare(?) and execute($var)
2684 # Revision 1.73 2003/11/28 09:45:25 tipaul
2685 # bugfix for iso2709 file import in the "notforloan" field.
2687 # But notforloan field called "loan" somewhere, so in case "loan" is used, copied to "notforloan" to avoid a bug.
2689 # Revision 1.72 2003/11/24 17:40:14 tipaul
2692 # Revision 1.71 2003/11/24 16:28:49 tipaul
2693 # biblio & item deletion now works fine in MARC editor.
2694 # Stores deleted biblio/item in the marc field of the deletedbiblio/deleteditem table.
2696 # Revision 1.70 2003/11/24 13:29:55 tipaul
2697 # moving $id from beginning to end of file (70 commits... huge comments...)
2699 # Revision 1.69 2003/11/24 13:27:17 tipaul
2700 # fix for #380 (bibliosubject)
2702 # Revision 1.68 2003/11/06 17:18:30 tipaul
2705 # 1st draft for MARC biblio deletion.
2706 # Still does not work well, but at least, Biblio.pm compiles & it should'nt break too many things
2707 # (Note the trash in the MARCdetail, but don't use it, please :-) )
2709 # Revision 1.67 2003/10/25 08:46:27 tipaul
2710 # minor fixes for bilbio deletion (still buggy)
2712 # Revision 1.66 2003/10/17 10:02:56 tipaul
2713 # Indexing only words longer than 2 letters. Was >=2 before, & 2 letters words usually means nothing.
2715 # Revision 1.65 2003/10/14 09:45:29 tipaul
2716 # 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)
2718 # Revision 1.64 2003/10/06 15:20:51 tipaul
2719 # fix for 536 (subtitle error)
2721 # Revision 1.63 2003/10/01 13:25:49 tipaul
2722 # seems a char encoding problem modified something in char_decode sub... changing back to something that works...
2724 # Revision 1.62 2003/09/17 14:21:13 tipaul
2725 # fixing bug that makes a MARC biblio disappear when using full acquisition (order => recieve ==> MARC editor).
2726 # Before this 2 lines fix, the MARC biblio was deleted during recieve, and had to be entirely recreated :-(
2728 # Revision 1.61 2003/09/17 10:24:39 tipaul
2729 # notforloan value in itemtype was overwritting notforloan value in a given item.
2730 # I changed this behaviour :
2731 # if notforloan is set for a given item, and NOT for all items from this itemtype, the notforloan is kept.
2732 # If notforloan is set for itemtype, it's used (and impossible to loan a specific item from this itemtype)
2734 # Revision 1.60 2003/09/04 14:11:23 tipaul
2735 # fix for 593 (data duplication in MARC-DB)
2737 # Revision 1.58 2003/08/06 12:54:52 tipaul
2738 # fix for publicationyear : extracting numeric value from MARC string, like for copyrightdate.
2739 # (note that copyrightdate still extracted to get numeric format)
2741 # Revision 1.57 2003/07/15 23:09:18 slef
2742 # change show columns to use biblioitems bnotes too
2744 # Revision 1.56 2003/07/15 11:34:52 slef
2745 # fixes from paul email
2747 # Revision 1.55 2003/07/15 00:02:49 slef
2748 # Work on bug 515... can we do a single-side rename of notes to bnotes?
2750 # Revision 1.54 2003/07/11 11:51:32 tipaul
2751 # *** empty log message ***
2753 # Revision 1.52 2003/07/10 10:37:19 tipaul
2754 # fix for copyrightdate problem, #514
2756 # Revision 1.51 2003/07/02 14:47:17 tipaul
2757 # fix for #519 : items.dateaccessioned imports incorrectly
2759 # Revision 1.49 2003/06/17 11:21:13 tipaul
2760 # improvments/fixes for z3950 support.
2761 # * Works now even on ADD, not only on MODIFY
2762 # * able to search on ISBN, author, title
2764 # Revision 1.48 2003/06/16 09:22:53 rangi
2765 # Just added an order clause to getitemtypes
2767 # Revision 1.47 2003/05/20 16:22:44 tipaul
2768 # fixing typo in Biblio.pm POD
2770 # Revision 1.46 2003/05/19 13:45:18 tipaul
2771 # support for subtitles, additional authors, subject.
2772 # 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.
2773 # Note that some OLD-DB subs are strange (dummy ?) see OLDmodsubject, OLDmodsubtitle, OLDmodaddiauthor in C4/Biblio.pm
2774 # 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.
2776 # Revision 1.45 2003/04/29 16:50:49 tipaul
2777 # really proud of this commit :-)
2778 # z3950 search and import seems to works fine.
2779 # Let me explain how :
2780 # * a "search z3950" button is added in the addbiblio template.
2781 # * when clicked, a popup appears and z3950/search.pl is called
2782 # * z3950/search.pl calls addz3950search in the DB
2783 # * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table.
2784 # * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending.
2785 # * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled
2788 # * 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.
2789 # * 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.
2791 # Revision 1.44 2003/04/28 13:07:14 tipaul
2792 # Those fixes solves the "internal server error" with MARC::Record 1.12.
2793 # It was due to an illegal contruction in Koha : we tried to retrive subfields from <10 tags.
2794 # That's not possible. MARC::Record accepted this in 0.93 version, but it was fixed after.
2795 # Now, the construct/retrieving is OK !
2797 # Revision 1.43 2003/04/10 13:56:02 tipaul
2799 # * worked in 1.9.0, but not in 1.9.1 :
2800 # - modif of a biblio didn't work
2801 # - 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.
2803 # * did not work before :
2804 # - repeatable subfields now works correctly. Enter 2 subfields separated by | and they will be splitted during saving.
2805 # - dropped the last subfield of the MARC form :-(
2807 # Internal changes :
2808 # - 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.
2809 # Note the MARCdelbiblio has been rewritted to enable deletion of a biblio WITHOUT deleting items.
2811 # Revision 1.42 2003/04/04 08:41:11 tipaul
2812 # last commits before 1.9.1
2814 # Revision 1.41 2003/04/01 12:26:43 tipaul
2817 # Revision 1.40 2003/03/11 15:14:03 tipaul
2820 # Revision 1.39 2003/03/07 16:35:42 tipaul
2821 # * moving generic functions to Koha.pm
2822 # * improvement of SearchMarc.pm
2826 # Revision 1.38 2003/02/27 16:51:59 tipaul
2827 # * moving prepare / execute to ? form.
2830 # * road to 1.9.2 => acquisition and cataloguing merging
2832 # Revision 1.37 2003/02/12 11:03:03 tipaul
2833 # Support for 000 -> 010 fields.
2834 # Those fields doesn't have subfields.
2835 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
2836 # 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.
2838 # Revision 1.36 2003/02/12 11:01:01 tipaul
2839 # Support for 000 -> 010 fields.
2840 # Those fields doesn't have subfields.
2841 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
2842 # 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.
2844 # Revision 1.35 2003/02/03 18:46:00 acli
2845 # Minor factoring in C4/Biblio.pm, plus change to export the per-tag
2846 # 'mandatory' property to a per-subfield 'tag_mandatory' template parameter,
2847 # so that addbiblio.tmpl can distinguish between mandatory subfields in a
2848 # mandatory tag and mandatory subfields in an optional tag
2850 # Not-minor factoring in acqui.simple/addbiblio.pl to make the if-else blocks
2851 # smaller, and to add some POD; need further testing for this
2853 # Added function to check if a MARC subfield name is "koha-internal" (instead
2854 # of checking it for 'lib' and 'tag' everywhere); temporarily added to Koha.pm
2856 # Use above function in acqui.simple/additem.pl and search.marc/search.pl
2858 # Revision 1.34 2003/01/28 14:50:04 tipaul
2859 # fixing MARCmodbiblio API and reindenting code
2861 # Revision 1.33 2003/01/23 12:22:37 tipaul
2862 # adding char_decode to decode MARC21 or UNIMARC extended chars
2864 # Revision 1.32 2002/12/16 15:08:50 tipaul
2865 # small but important bugfix (fixes a problem in export)
2867 # Revision 1.31 2002/12/13 16:22:04 tipaul
2868 # 1st draft of marc export
2870 # Revision 1.30 2002/12/12 21:26:35 tipaul
2871 # YAB ! (Yet Another Bugfix) => related to biblio modif
2872 # (some warning cleaning too)
2874 # Revision 1.29 2002/12/12 16:35:00 tipaul
2875 # adding authentification with Auth.pm and
2876 # MAJOR BUGFIX on marc biblio modification
2878 # Revision 1.28 2002/12/10 13:30:03 tipaul
2879 # fugfixes from Dombes Abbey work
2881 # Revision 1.27 2002/11/19 12:36:16 tipaul
2883 # various bugfixes, improvments, and migration from acquisition.pm to biblio.pm
2885 # Revision 1.26 2002/11/12 15:58:43 tipaul
2888 # * 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)
2890 # Revision 1.25 2002/10/25 10:58:26 tipaul
2892 # * bugfixes and improvements
2894 # Revision 1.24 2002/10/24 12:09:01 arensb
2895 # Fixed "no title" warning when generating HTML documentation from POD.
2897 # Revision 1.23 2002/10/16 12:43:08 arensb
2898 # Added some FIXME comments.
2900 # Revision 1.22 2002/10/15 13:39:17 tipaul
2901 # removing Acquisition.pm
2902 # deleting unused code in biblio.pm, rewriting POD and answering most FIXME comments
2904 # Revision 1.21 2002/10/13 11:34:14 arensb
2905 # Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
2906 # Thus, $x = $x+2 becomes $x += 2, and so forth.
2908 # Revision 1.20 2002/10/13 08:28:32 arensb
2909 # Deleted unused variables.
2910 # Removed trailing whitespace.
2912 # Revision 1.19 2002/10/13 05:56:10 arensb
2913 # Added some FIXME comments.
2915 # Revision 1.18 2002/10/11 12:34:53 arensb
2916 # Replaced &requireDBI with C4::Context->dbh
2918 # Revision 1.17 2002/10/10 14:48:25 tipaul
2921 # Revision 1.16 2002/10/07 14:04:26 tipaul
2922 # road to 1.3.1 : viewing MARC biblio
2924 # Revision 1.15 2002/10/05 09:49:25 arensb
2925 # Merged with arensb-context branch: use C4::Context->dbh instead of
2926 # &C4Connect, and generally prefer C4::Context over C4::Database.
2928 # Revision 1.14 2002/10/03 11:28:18 tipaul
2929 # Extending Context.pm to add stopword management and using it in MARC-API.
2930 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
2932 # Revision 1.13 2002/10/02 16:26:44 tipaul
2935 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
2936 # Merged in changes from main branch.
2938 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
2939 # Added a whole mess of FIXME comments.
2941 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
2942 # Added some missing semicolons.
2944 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
2945 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
2948 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
2949 # Added a whole mess of FIXME comments.
2951 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
2952 # Added some missing semicolons.
2954 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
2955 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
2958 # Revision 1.12 2002/10/01 11:48:51 arensb
2959 # Added some FIXME comments, mostly marking duplicate functions.
2961 # Revision 1.11 2002/09/24 13:49:26 tipaul
2962 # long WAS the road to 1.3.0...
2963 # coming VERY SOON NOW...
2964 # modifying installer and buildrelease to update the DB
2966 # Revision 1.10 2002/09/22 16:50:08 arensb
2967 # Added some FIXME comments.
2969 # Revision 1.9 2002/09/20 12:57:46 tipaul
2970 # long is the road to 1.4.0
2971 # * MARCadditem and MARCmoditem now wroks
2972 # * various bugfixes in MARC management
2973 # !!! 1.3.0 should be released very soon now. Be careful !!!
2975 # Revision 1.8 2002/09/10 13:53:52 tipaul
2976 # MARC API continued...
2978 # * 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)
2980 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
2982 # Revision 1.7 2002/08/14 18:12:51 tonnesen
2983 # Added copyright statement to all .pl and .pm files
2985 # Revision 1.6 2002/07/25 13:40:31 tipaul
2986 # pod documenting the API.
2988 # Revision 1.5 2002/07/24 16:11:37 tipaul
2990 # Database.pm and Output.pm are almost not modified (var test...)
2992 # Biblio.pm is almost completly rewritten.
2994 # WHAT DOES IT ??? ==> END of Hitchcock suspens
2996 # 1st, it does... nothing...
2997 # 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 ...
2999 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
3000 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
3001 # * 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.
3002 # * 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.
3003 # 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 ;-)
3005 # 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.
3006 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.