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,$frameworkcode,$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 # adding main table, and retrieving bibid
327 # if bibid is sent, then it's not a true add, it's only a re-add, after a delete (ie, a mod)
328 # if bibid empty => true add, find a new bibid number
331 "lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ"
335 "insert into marc_biblio (datecreated,biblionumber,frameworkcode) values (now(),?,?)"
337 $sth->execute( $biblionumber, $frameworkcode );
338 $sth = $dbh->prepare("select max(bibid) from marc_biblio");
340 ($bibid) = $sth->fetchrow;
345 # now, add subfields...
346 foreach my $field (@fields) {
348 if ( $field->tag() < 10 ) {
349 &MARCaddsubfield( $dbh, $bibid, $field->tag(), '', $fieldcount, '',
353 my @subfields = $field->subfields();
354 foreach my $subfieldcount ( 0 .. $#subfields ) {
359 $field->indicator(1) . $field->indicator(2),
361 $subfields[$subfieldcount][0],
363 $subfields[$subfieldcount][1]
368 $dbh->do("unlock tables");
374 # pass the MARC::Record to this function, and it will create the records in the marc tables
375 my ($dbh,$record,$biblionumber) = @_;
376 # search for MARC biblionumber
377 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
378 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
379 my @fields=$record->fields();
380 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
381 $sth->execute($bibid);
382 my ($fieldcount) = $sth->fetchrow;
384 # now, add subfields...
385 foreach my $field (@fields) {
386 my @subfields = $field->subfields();
388 foreach my $subfieldcount ( 0 .. $#subfields ) {
393 $field->indicator(1) . $field->indicator(2),
395 $subfields[$subfieldcount][0],
397 $subfields[$subfieldcount][1]
401 $dbh->do("unlock tables");
405 sub MARCaddsubfield {
407 # Add a new subfield to a tag into the DB.
409 $dbh, $bibid, $tagid, $tag_indicator,
410 $tagorder, $subfieldcode, $subfieldorder, $subfieldvalues
414 # if not value, end of job, we do nothing
415 if ( length($subfieldvalues) == 0 ) {
418 if ( not($subfieldcode) ) {
421 my @subfieldvalues = split /\|/, $subfieldvalues;
422 foreach my $subfieldvalue (@subfieldvalues) {
423 if ( length($subfieldvalue) > 255 ) {
425 "lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE"
429 "insert into marc_blob_subfield (subfieldvalue) values (?)");
430 $sth->execute($subfieldvalue);
432 $dbh->prepare("select max(blobidlink)from marc_blob_subfield");
434 my ($res) = $sth->fetchrow;
437 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?,?)"
439 $sth->execute( $bibid, ( sprintf "%03s", $tagid ), $tagorder,
440 $tag_indicator, $subfieldcode, $subfieldorder, $res );
442 if ( $sth->errstr ) {
444 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
446 $dbh->do("unlock tables");
451 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)"
454 $bibid, ( sprintf "%03s", $tagid ),
455 $tagorder, $tag_indicator,
456 $subfieldcode, $subfieldorder,
459 if ( $sth->errstr ) {
461 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
465 $dbh, $bibid, $tagid, $tagorder,
466 $subfieldcode, $subfieldorder, $subfieldvalue
473 # Returns MARC::Record of the biblio passed in parameter.
474 my ( $dbh, $bibid ) = @_;
475 my $record = MARC::Record->new();
477 #---- TODO : the leader is missing
478 $record->leader(' ');
481 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
482 from marc_subfield_table
483 where bibid=? order by tag,tagorder,subfieldcode
488 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
489 $sth->execute($bibid);
490 my $prevtagorder = 1;
493 my $field; # for >=10 tags
494 my $prevvalue; # for <10 tags
495 while ( my $row = $sth->fetchrow_hashref ) {
497 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
498 $sth2->execute( $row->{'valuebloblink'} );
499 my $row2 = $sth2->fetchrow_hashref;
501 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
503 if ( $row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag ) {
504 $previndicator .= " ";
505 if ( $prevtag < 10 ) {
506 $record->add_fields( ( sprintf "%03s", $prevtag ), $prevvalue )
507 unless $prevtag eq "XXX"; # ignore the 1st loop
510 $record->add_fields($field) unless $prevtag eq "XXX";
513 $prevtagorder = $row->{tagorder};
514 $prevtag = $row->{tag};
515 $previndicator = $row->{tag_indicator};
516 if ( $row->{tag} < 10 ) {
517 $prevvalue = $row->{subfieldvalue};
520 $field = MARC::Field->new(
521 ( sprintf "%03s", $prevtag ),
522 substr( $row->{tag_indicator} . ' ', 0, 1 ),
523 substr( $row->{tag_indicator} . ' ', 1, 1 ),
524 $row->{'subfieldcode'},
525 $row->{'subfieldvalue'}
530 if ( $row->{tag} < 10 ) {
531 $record->add_fields( ( sprintf "%03s", $row->{tag} ),
532 $row->{'subfieldvalue'} );
535 $field->add_subfields( $row->{'subfieldcode'},
536 $row->{'subfieldvalue'} );
538 $prevtag = $row->{tag};
539 $previndicator = $row->{tag_indicator};
543 # the last has not been included inside the loop... do it now !
544 if ( $prevtag ne "XXX" )
545 { # check that we have found something. Otherwise, prevtag is still XXX and we
546 # must return an empty record, not make MARC::Record fail because we try to
547 # create a record with XXX as field :-(
548 if ( $prevtag < 10 ) {
549 $record->add_fields( $prevtag, $prevvalue );
553 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
554 $record->add_fields($field);
562 # Returns MARC::Record of the biblio passed in parameter.
563 my ( $dbh, $bibid, $itemnumber ) = @_;
564 my $record = MARC::Record->new();
566 # search MARC tagorder
569 "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=?"
571 $sth2->execute( $bibid, $itemnumber );
572 my ($tagorder) = $sth2->fetchrow_array();
574 #---- TODO : the leader is missing
577 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
578 from marc_subfield_table
579 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
584 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
585 $sth->execute( $bibid, $tagorder );
586 while ( my $row = $sth->fetchrow_hashref ) {
587 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
588 $sth2->execute( $row->{'valuebloblink'} );
589 my $row2 = $sth2->fetchrow_hashref;
591 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
593 if ( $record->field( $row->{'tag'} ) ) {
596 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
597 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
598 if ( length( $row->{'tag'} ) < 3 ) {
599 $row->{'tag'} = "0" . $row->{'tag'};
601 $field = $record->field( $row->{'tag'} );
604 $field->add_subfields( $row->{'subfieldcode'},
605 $row->{'subfieldvalue'} );
606 $record->delete_field($field);
607 $record->add_fields($field);
611 if ( length( $row->{'tag'} ) < 3 ) {
612 $row->{'tag'} = "0" . $row->{'tag'};
615 MARC::Field->new( $row->{'tag'}, " ", " ",
616 $row->{'subfieldcode'} => $row->{'subfieldvalue'} );
617 $record->add_fields($temp);
625 my ($dbh,$bibid,$record,$frameworkcode,$delete)=@_;
626 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
627 if ($oldrecord eq $record) {
630 # 1st delete the biblio,
632 my $biblionumber = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
633 &MARCdelbiblio($dbh,$bibid,1);
634 &MARCaddbiblio($dbh,$record,$biblionumber,$frameworkcode,$bibid);
638 my ( $dbh, $bibid, $keep_items ) = @_;
640 # if the keep_item is set to 1, then all items are preserved.
641 # This flag is set when the delbiblio is called by modbiblio
642 # due to a too complex structure of MARC (repeatable fields and subfields),
643 # the best solution for a modif is to delete / recreate the record.
645 # 1st of all, copy the MARC::Record to deletedbiblio table => if a true deletion, MARC data will be kept.
646 # if deletion called before MARCmodbiblio => won't do anything, as the oldbiblionumber doesn't
647 # exist in deletedbiblio table
648 my $record = MARCgetbiblio( $dbh, $bibid );
649 my $oldbiblionumber =
650 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
652 $dbh->prepare("update deletedbiblio set marc=? where biblionumber=?");
653 $copy2deleted->execute( $record->as_usmarc(), $oldbiblionumber );
655 # now, delete in MARC tables.
656 if ( $keep_items eq 1 ) {
658 #search item field code
661 "select tagfield from marc_subfield_structure where kohafield like 'items.%'"
664 my $itemtag = $sth->fetchrow_hashref->{tagfield};
666 "delete from marc_subfield_table where bibid=$bibid and tag<>$itemtag"
669 "delete from marc_word where bibid=$bibid and not (tagsubfield like \"$itemtag%\")"
673 $dbh->do("delete from marc_biblio where bibid=$bibid");
674 $dbh->do("delete from marc_subfield_table where bibid=$bibid");
675 $dbh->do("delete from marc_word where bibid=$bibid");
681 # delete the item passed in parameter in MARC tables.
682 my ( $dbh, $bibid, $itemnumber ) = @_;
684 # my $record = MARC::Record->new();
685 # search MARC tagorder
686 my $record = MARCgetitem( $dbh, $bibid, $itemnumber );
688 $dbh->prepare("update deleteditems set marc=? where itemnumber=?");
689 $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
693 "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=?"
695 $sth2->execute( $bibid, $itemnumber );
696 my ($tagorder) = $sth2->fetchrow_array();
699 "delete from marc_subfield_table where bibid=? and tagorder=?");
700 $sth->execute( $bibid, $tagorder );
704 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
705 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
706 # if nothing to change, don't waste time...
707 if ($oldrecord eq $record) {
710 # otherwise, skip through each subfield...
711 my @fields = $record->fields();
712 # search old MARC item
713 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=?");
714 $sth2->execute($bibid,$itemnumber);
715 my ($tagorder) = $sth2->fetchrow_array();
716 foreach my $field (@fields) {
717 my $oldfield = $oldrecord->field($field->tag());
718 my @subfields=$field->subfields();
720 foreach my $subfield (@subfields) {
722 if ($oldfield eq 0 or (length($oldfield->subfield(@$subfield[0])) ==0) ) {
723 # just adding datas...
724 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
725 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
727 # modify he subfield if it's a different string
728 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
729 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
730 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
737 sub MARCmodsubfield {
739 # Subroutine changes a subfield value given a subfieldid.
740 my ( $dbh, $subfieldid, $subfieldvalue ) = @_;
741 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
744 "select valuebloblink from marc_subfield_table where subfieldid=?");
745 $sth1->execute($subfieldid);
746 my ($oldvaluebloblink) = $sth1->fetchrow;
750 # if too long, use a bloblink
751 if ( length($subfieldvalue) > 255 ) {
753 # if already a bloblink, update it, otherwise, insert a new one.
754 if ($oldvaluebloblink) {
757 "update marc_blob_subfield set subfieldvalue=? where blobidlink=?"
759 $sth->execute( $subfieldvalue, $oldvaluebloblink );
764 "insert into marc_blob_subfield (subfieldvalue) values (?)");
765 $sth->execute($subfieldvalue);
767 $dbh->prepare("select max(blobidlink) from marc_blob_subfield");
769 my ($res) = $sth->fetchrow;
772 "update marc_subfield_table set subfieldvalue=null, valuebloblink=? where subfieldid=?"
774 $sth->execute( $res, $subfieldid );
779 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
782 "update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?"
784 $sth->execute( $subfieldvalue, $subfieldid );
786 $dbh->do("unlock tables");
790 "select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?"
792 $sth->execute($subfieldid);
793 my ( $bibid, $tagid, $tagorder, $subfieldcode, $x, $subfieldorder ) =
796 &MARCdelword( $dbh, $bibid, $tagid, $tagorder, $subfieldcode,
799 $dbh, $bibid, $tagid, $tagorder,
800 $subfieldcode, $subfieldorder, $subfieldvalue
802 return ( $subfieldid, $subfieldvalue );
805 sub MARCfindsubfield {
806 my ( $dbh, $bibid, $tag, $subfieldcode, $subfieldorder, $subfieldvalue ) =
808 my $resultcounter = 0;
812 "select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
813 my @bind_values = ( $bibid, $tag, $subfieldcode );
814 if ($subfieldvalue) {
815 $query .= " and subfieldvalue=?";
816 push ( @bind_values, $subfieldvalue );
819 if ( $subfieldorder < 1 ) {
822 $query .= " and subfieldorder=?";
823 push ( @bind_values, $subfieldorder );
825 my $sti = $dbh->prepare($query);
826 $sti->execute(@bind_values);
827 while ( ($subfieldid) = $sti->fetchrow ) {
829 $lastsubfieldid = $subfieldid;
831 if ( $resultcounter > 1 ) {
833 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
834 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
838 return $lastsubfieldid;
842 sub MARCfindsubfieldid {
843 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
844 my $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
845 where bibid=? and tag=? and tagorder=?
846 and subfieldcode=? and subfieldorder=?"
848 $sth->execute( $bibid, $tag, $tagorder, $subfield, $subfieldorder );
849 my ($res) = $sth->fetchrow;
851 $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
852 where bibid=? and tag=? and tagorder=?
855 $sth->execute( $bibid, $tag, $tagorder, $subfield );
856 ($res) = $sth->fetchrow;
861 sub MARCfind_frameworkcode {
862 my ( $dbh, $bibid ) = @_;
864 $dbh->prepare("select frameworkcode from marc_biblio where bibid=?");
865 $sth->execute($bibid);
866 my ($frameworkcode) = $sth->fetchrow;
867 return $frameworkcode;
870 sub MARCdelsubfield {
872 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
873 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
874 $dbh->do( "delete from marc_subfield_table where bibid='$bibid' and
875 tag='$tag' and tagorder='$tagorder'
876 and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
881 sub MARCkoha2marcBiblio {
883 # this function builds partial MARC::Record from the old koha-DB fields
884 my ( $dbh, $biblionumber, $biblioitemnumber ) = @_;
887 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
889 my $record = MARC::Record->new();
891 #--- if bibid, then retrieve old-style koha data
892 if ( $biblionumber > 0 ) {
895 "select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
896 from biblio where biblionumber=?"
898 $sth2->execute($biblionumber);
899 my $row = $sth2->fetchrow_hashref;
901 foreach $code ( keys %$row ) {
902 if ( $row->{$code} ) {
903 &MARCkoha2marcOnefield( $sth, $record, "biblio." . $code,
909 #--- if biblioitem, then retrieve old-style koha data
910 if ( $biblioitemnumber > 0 ) {
913 " SELECT biblioitemnumber,biblionumber,volume,number,classification,
914 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
915 volumedate,volumeddesc,timestamp,illus,pages,notes AS bnotes,size,place
917 WHERE biblioitemnumber=?
920 $sth2->execute($biblioitemnumber);
921 my $row = $sth2->fetchrow_hashref;
923 foreach $code ( keys %$row ) {
924 if ( $row->{$code} ) {
925 &MARCkoha2marcOnefield( $sth, $record, "biblioitems." . $code,
931 # other fields => additional authors, subjects, subtitles
934 " SELECT author FROM additionalauthors WHERE biblionumber=?");
935 $sth2->execute($biblionumber);
936 while ( my $row = $sth2->fetchrow_hashref ) {
937 &MARCkoha2marcOnefield( $sth, $record, "additionalauthors.author",
941 $dbh->prepare(" SELECT subject FROM bibliosubject WHERE biblionumber=?");
942 $sth2->execute($biblionumber);
943 while ( my $row = $sth2->fetchrow_hashref ) {
944 &MARCkoha2marcOnefield( $sth, $record, "bibliosubject.subject",
949 " SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?");
950 $sth2->execute($biblionumber);
951 while ( my $row = $sth2->fetchrow_hashref ) {
952 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.title",
953 $row->{'subtitle'} );
958 sub MARCkoha2marcItem {
960 # this function builds partial MARC::Record from the old koha-DB fields
961 my ( $dbh, $biblionumber, $itemnumber ) = @_;
963 # my $dbh=&C4Connect;
966 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
968 my $record = MARC::Record->new();
970 #--- if item, then retrieve old-style koha data
971 if ( $itemnumber > 0 ) {
973 # print STDERR "prepare $biblionumber,$itemnumber\n";
976 "SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
977 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
978 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,itemcallnumber,issues,renewals,
979 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
983 $sth2->execute($itemnumber);
984 my $row = $sth2->fetchrow_hashref;
986 foreach $code ( keys %$row ) {
987 if ( $row->{$code} ) {
988 &MARCkoha2marcOnefield( $sth, $record, "items." . $code,
996 sub MARCkoha2marcSubtitle {
998 # this function builds partial MARC::Record from the old koha-DB fields
999 my ( $dbh, $bibnum, $subtitle ) = @_;
1002 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
1004 my $record = MARC::Record->new();
1005 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle",
1010 sub MARCkoha2marcOnefield {
1011 my ( $sth, $record, $kohafieldname, $value ) = @_;
1014 $sth->execute($kohafieldname);
1015 if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
1016 if ( $record->field($tagfield) ) {
1017 my $tag = $record->field($tagfield);
1019 $tag->add_subfields( $tagsubfield, $value );
1020 $record->delete_field($tag);
1021 $record->add_fields($tag);
1025 $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
1032 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
1034 my $record = MARC::Record->new();
1035 # my %subfieldlist=();
1036 my $prevvalue; # if tag <10
1037 my $field; # if tag >=10
1038 for (my $i=0; $i< @$rtags; $i++) {
1039 # rebuild MARC::Record
1040 if (@$rtags[$i] ne $prevtag) {
1041 if ($prevtag < 10) {
1043 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
1047 $record->add_fields($field);
1050 $indicators{@$rtags[$i]}.=' ';
1051 if (@$rtags[$i] <10) {
1052 $prevvalue= @$rvalues[$i];
1054 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
1056 $prevtag = @$rtags[$i];
1058 if (@$rtags[$i] <10) {
1059 $prevvalue=@$rvalues[$i];
1061 if (@$rvalues[$i]) {
1062 $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
1065 $prevtag= @$rtags[$i];
1068 # the last has not been included inside the loop... do it now !
1069 $record->add_fields($field);
1074 my ($dbh,$record) = @_;
1075 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
1077 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
1080 while (($field)=$sth2->fetchrow) {
1081 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
1083 $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
1085 while (($field)=$sth2->fetchrow) {
1086 if ($field eq 'notes') { $field = 'bnotes'; }
1087 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
1089 $sth2=$dbh->prepare("SHOW COLUMNS from items");
1091 while (($field)=$sth2->fetchrow) {
1092 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
1094 # additional authors : specific
1095 $result = &MARCmarc2kohaOneField($sth,"bibliosubtitle","subtitle",$record,$result);
1096 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
1097 # modify copyrightdate to keep only the 1st year found
1098 my $temp = $result->{'copyrightdate'};
1099 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1101 $result->{'copyrightdate'} = $1;
1102 } else { # if no cYYYY, get the 1st date.
1103 $temp =~ m/(\d\d\d\d)/;
1104 $result->{'copyrightdate'} = $1;
1106 # modify publicationyear to keep only the 1st year found
1107 my $temp = $result->{'publicationyear'};
1108 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1110 $result->{'publicationyear'} = $1;
1111 } else { # if no cYYYY, get the 1st date.
1112 $temp =~ m/(\d\d\d\d)/;
1113 $result->{'publicationyear'} = $1;
1118 sub MARCmarc2kohaOneField {
1120 # FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
1121 my ( $sth, $kohatable, $kohafield, $record, $result ) = @_;
1123 # warn "kohatable / $kohafield / $result / ";
1127 $sth->execute( $kohatable . "." . $kohafield );
1128 ( $tagfield, $subfield ) = $sth->fetchrow;
1129 foreach my $field ( $record->field($tagfield) ) {
1130 if ( $field->subfield($subfield) ) {
1131 if ( $result->{$kohafield} ) {
1132 $result->{$kohafield} .= " | " . $field->subfield($subfield);
1135 $result->{$kohafield} = $field->subfield($subfield);
1144 # split a subfield string and adds it into the word table.
1147 $dbh, $bibid, $tag, $tagorder,
1148 $subfieldid, $subfieldorder, $sentence
1151 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\})/ /g;
1152 my @words = split / /, $sentence;
1153 my $stopwords = C4::Context->stopwords;
1156 "insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word)
1157 values (?,concat(?,?),?,?,?,soundex(?))"
1159 foreach my $word (@words) {
1160 # we record only words one char long and not in stopwords hash
1161 if (length($word)>=1 and !($stopwords->{uc($word)})) {
1162 $sth->execute($bibid,$tag,$subfieldid,$tagorder,$subfieldorder,$word,$word);
1164 warn "ERROR ==> insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word) values ($bibid,concat($tag,$subfieldid),$tagorder,$subfieldorder,$word,soundex($word))\n";
1172 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
1173 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
1176 "delete from marc_word where bibid=? and tagsubfield=concat(?,?) and tagorder=? and subfieldorder=?"
1178 $sth->execute( $bibid, $tag, $subfield, $tagorder, $subfieldorder );
1183 # NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW
1186 # all the following subs are useful to manage MARC-DB with complete MARC records.
1187 # it's used with marcimport, and marc management tools
1190 =item ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
1192 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
1193 are builded from the MARC::Record. If they are passed, they are used.
1195 =item NEWnewitem($dbh, $record,$bibid);
1197 adds an item in the db.
1202 my ( $dbh, $record, $frameworkcode ) = @_;
1205 my $olddata = MARCmarc2koha( $dbh, $record );
1206 $oldbibnum = OLDnewbiblio( $dbh, $olddata );
1207 $olddata->{'biblionumber'} = $oldbibnum;
1208 $oldbibitemnum = OLDnewbiblioitem( $dbh, $olddata );
1210 # search subtiles, addiauthors and subjects
1211 my ( $tagfield, $tagsubfield ) =
1212 MARCfind_marc_from_kohafield( $dbh, "additionalauthors.author" );
1213 my @addiauthfields = $record->field($tagfield);
1214 foreach my $addiauthfield (@addiauthfields) {
1215 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1216 foreach my $subfieldcount ( 0 .. $#addiauthsubfields ) {
1217 OLDmodaddauthor( $dbh, $oldbibnum,
1218 $addiauthsubfields[$subfieldcount] );
1221 ( $tagfield, $tagsubfield ) =
1222 MARCfind_marc_from_kohafield( $dbh, "bibliosubtitle.title" );
1223 my @subtitlefields = $record->field($tagfield);
1224 foreach my $subtitlefield (@subtitlefields) {
1225 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1226 foreach my $subfieldcount ( 0 .. $#subtitlesubfields ) {
1227 OLDnewsubtitle( $dbh, $oldbibnum,
1228 $subtitlesubfields[$subfieldcount] );
1231 ( $tagfield, $tagsubfield ) =
1232 MARCfind_marc_from_kohafield( $dbh, "bibliosubject.subject" );
1233 my @subj = $record->field($tagfield);
1235 foreach my $subject (@subj) {
1236 my @subjsubfield = $subject->subfield($tagsubfield);
1237 foreach my $subfieldcount ( 0 .. $#subjsubfield ) {
1238 push @subjects, $subjsubfield[$subfieldcount];
1241 OLDmodsubject( $dbh, $oldbibnum, 1, @subjects );
1243 # we must add bibnum and bibitemnum in MARC::Record...
1244 # we build the new field with biblionumber and biblioitemnumber
1245 # we drop the original field
1246 # we add the new builded field.
1247 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
1248 # (steve and paul : thinks 090 is a good choice)
1251 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
1253 $sth->execute("biblio.biblionumber");
1254 ( my $tagfield1, my $tagsubfield1 ) = $sth->fetchrow;
1255 $sth->execute("biblioitems.biblioitemnumber");
1256 ( my $tagfield2, my $tagsubfield2 ) = $sth->fetchrow;
1257 if ( $tagfield1 != $tagfield2 ) {
1259 "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1261 "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1264 my $newfield = MARC::Field->new(
1265 $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
1266 "$tagsubfield2" => $oldbibitemnum
1269 # drop old field and create new one...
1270 my $old_field = $record->field($tagfield1);
1271 $record->delete_field($old_field);
1272 $record->add_fields($newfield);
1273 my $bibid = MARCaddbiblio( $dbh, $record, $oldbibnum, $frameworkcode );
1274 return ( $bibid, $oldbibnum, $oldbibitemnum );
1278 my ($dbh,$record,$bibid,$frameworkcode) =@_;
1279 $frameworkcode="" unless $frameworkcode;
1280 &MARCmodbiblio($dbh,$bibid,$record,$frameworkcode,0);
1281 my $oldbiblio = MARCmarc2koha($dbh,$record);
1282 my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
1283 OLDmodbibitem($dbh,$oldbiblio);
1284 # now, modify addi authors, subject, addititles.
1285 my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"additionalauthors.author");
1286 my @addiauthfields = $record->field($tagfield);
1287 foreach my $addiauthfield (@addiauthfields) {
1288 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1289 foreach my $subfieldcount (0..$#addiauthsubfields) {
1290 OLDmodaddauthor($dbh,$oldbiblionumber,$addiauthsubfields[$subfieldcount]);
1293 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubtitle.subtitle");
1294 my @subtitlefields = $record->field($tagfield);
1295 foreach my $subtitlefield (@subtitlefields) {
1296 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1297 foreach my $subfieldcount (0..$#subtitlesubfields) {
1298 OLDmodsubtitle($dbh,$oldbiblionumber,$subtitlesubfields[$subfieldcount]);
1301 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject");
1302 my @subj = $record->field($tagfield);
1304 foreach my $subject (@subj) {
1305 my @subjsubfield = $subject->subfield($tagsubfield);
1306 foreach my $subfieldcount (0..$#subjsubfield) {
1307 push @subjects,$subjsubfield[$subfieldcount];
1310 OLDmodsubject($dbh,$oldbiblionumber,1,@subjects);
1315 my ( $dbh, $bibid ) = @_;
1316 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1317 &OLDdelbiblio( $dbh, $biblio );
1320 "select biblioitemnumber from biblioitems where biblionumber=?");
1321 $sth->execute($biblio);
1322 while ( my ($biblioitemnumber) = $sth->fetchrow ) {
1323 OLDdeletebiblioitem( $dbh, $biblioitemnumber );
1325 &MARCdelbiblio( $dbh, $bibid, 0 );
1329 my ( $dbh, $record, $bibid ) = @_;
1331 # add item in old-DB
1332 my $item = &MARCmarc2koha( $dbh, $record );
1334 # needs old biblionumber and biblioitemnumber
1335 $item->{'biblionumber'} =
1336 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1339 "select biblioitemnumber from biblioitems where biblionumber=?");
1340 $sth->execute( $item->{'biblionumber'} );
1341 ( $item->{'biblioitemnumber'} ) = $sth->fetchrow;
1342 my ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, $item->{barcode} );
1344 # add itemnumber to MARC::Record before adding the item.
1347 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
1349 &MARCkoha2marcOnefield( $sth, $record, "items.itemnumber", $itemnumber );
1352 my $bib = &MARCadditem( $dbh, $record, $item->{'biblionumber'} );
1356 my ( $dbh, $record, $bibid, $itemnumber, $delete ) = @_;
1357 &MARCmoditem( $dbh, $record, $bibid, $itemnumber, $delete );
1358 my $olditem = MARCmarc2koha( $dbh, $record );
1359 OLDmoditem( $dbh, $olditem );
1363 my ( $dbh, $bibid, $itemnumber ) = @_;
1364 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1365 &OLDdelitem( $dbh, $itemnumber );
1366 &MARCdelitem( $dbh, $bibid, $itemnumber );
1371 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
1375 =item $biblionumber = OLDnewbiblio($dbh,$biblio);
1377 adds a record in biblio table. Datas are in the hash $biblio.
1379 =item $biblionumber = OLDmodbiblio($dbh,$biblio);
1381 modify a record in biblio table. Datas are in the hash $biblio.
1383 =item OLDmodsubtitle($dbh,$bibnum,$subtitle);
1385 modify subtitles in bibliosubtitle table.
1387 =item OLDmodaddauthor($dbh,$bibnum,$author);
1389 adds or modify additional authors
1390 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1392 =item $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1394 modify/adds subjects
1396 =item OLDmodbibitem($dbh, $biblioitem);
1400 =item OLDmodnote($dbh,$bibitemnum,$note
1402 modify a note for a biblioitem
1404 =item OLDnewbiblioitem($dbh,$biblioitem);
1406 adds a biblioitem ($biblioitem is a hash with the values)
1408 =item OLDnewsubject($dbh,$bibnum);
1412 =item OLDnewsubtitle($dbh,$bibnum,$subtitle);
1414 create a new subtitle
1416 =item ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1418 create a item. $item is a hash and $barcode the barcode.
1420 =item OLDmoditem($dbh,$item);
1424 =item OLDdelitem($dbh,$itemnum);
1428 =item OLDdeletebiblioitem($dbh,$biblioitemnumber);
1430 deletes a biblioitem
1431 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1433 =item OLDdelbiblio($dbh,$biblio);
1440 my ( $dbh, $biblio ) = @_;
1442 # my $dbh = &C4Connect;
1443 my $sth = $dbh->prepare("Select max(biblionumber) from biblio");
1445 my $data = $sth->fetchrow_arrayref;
1446 my $bibnum = $$data[0] + 1;
1449 if ( $biblio->{'seriestitle'} ) { $series = 1 }
1453 "insert into biblio set biblionumber = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?"
1456 $bibnum, $biblio->{'title'},
1457 $biblio->{'author'}, $biblio->{'copyrightdate'},
1458 $series, $biblio->{'seriestitle'},
1459 $biblio->{'notes'}, $biblio->{'abstract'}
1469 my ( $dbh, $biblio ) = @_;
1471 # my $dbh = C4Connect;
1478 "Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?, seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?"
1481 $biblio->{'title'}, $biblio->{'author'},
1482 $biblio->{'abstract'}, $biblio->{'copyrightdate'},
1483 $biblio->{'seriestitle'}, $biblio->{'serial'},
1484 $biblio->{'unititle'}, $biblio->{'notes'},
1485 $biblio->{'biblionumber'}
1489 return ( $biblio->{'biblionumber'} );
1492 sub OLDmodsubtitle {
1493 my ( $dbh, $bibnum, $subtitle ) = @_;
1496 "update bibliosubtitle set subtitle = ? where biblionumber = ?");
1497 $sth->execute( $subtitle, $bibnum );
1501 sub OLDmodaddauthor {
1502 my ( $dbh, $bibnum, @authors ) = @_;
1504 # my $dbh = C4Connect;
1506 $dbh->prepare("Delete from additionalauthors where biblionumber = ?");
1508 $sth->execute($bibnum);
1510 foreach my $author (@authors) {
1511 if ( $author ne '' ) {
1514 "Insert into additionalauthors set author = ?, biblionumber = ?"
1517 $sth->execute( $author, $bibnum );
1522 } # sub modaddauthor
1525 my ( $dbh, $bibnum, $force, @subject ) = @_;
1527 # my $dbh = C4Connect;
1528 my $count = @subject;
1530 for ( my $i = 0 ; $i < $count ; $i++ ) {
1531 $subject[$i] =~ s/^ //g;
1532 $subject[$i] =~ s/ $//g;
1535 "select * from catalogueentry where entrytype = 's' and catalogueentry = ?"
1537 $sth->execute( $subject[$i] );
1539 if ( my $data = $sth->fetchrow_hashref ) {
1542 if ( $force eq $subject[$i] || $force == 1 ) {
1544 # subject not in aut, chosen to force anway
1545 # so insert into cataloguentry so its in auth file
1548 "Insert into catalogueentry (entrytype,catalogueentry) values ('s',?)"
1551 $sth2->execute( $subject[$i] ) if ( $subject[$i] );
1556 "$subject[$i]\n does not exist in the subject authority file";
1559 "Select * from catalogueentry where entrytype = 's' and (catalogueentry like ? or catalogueentry like ? or catalogueentry like ?)"
1561 $sth2->execute( "$subject[$i] %", "% $subject[$i] %",
1563 while ( my $data = $sth2->fetchrow_hashref ) {
1564 $error .= "<br>$data->{'catalogueentry'}";
1571 if ( $error eq '' ) {
1573 $dbh->prepare("Delete from bibliosubject where biblionumber = ?");
1574 $sth->execute($bibnum);
1578 "Insert into bibliosubject (subject,biblionumber) values (?,?)");
1580 foreach $query (@subject) {
1581 $sth->execute( $query, $bibnum ) if ( $query && $bibnum );
1591 my ( $dbh, $biblioitem ) = @_;
1593 # my $dbh = C4Connect;
1596 $biblioitem->{'itemtype'} = $dbh->quote( $biblioitem->{'itemtype'} );
1597 $biblioitem->{'url'} = $dbh->quote( $biblioitem->{'url'} );
1598 $biblioitem->{'isbn'} = $dbh->quote( $biblioitem->{'isbn'} );
1599 $biblioitem->{'publishercode'} =
1600 $dbh->quote( $biblioitem->{'publishercode'} );
1601 $biblioitem->{'publicationyear'} =
1602 $dbh->quote( $biblioitem->{'publicationyear'} );
1603 $biblioitem->{'classification'} =
1604 $dbh->quote( $biblioitem->{'classification'} );
1605 $biblioitem->{'dewey'} = $dbh->quote( $biblioitem->{'dewey'} );
1606 $biblioitem->{'subclass'} = $dbh->quote( $biblioitem->{'subclass'} );
1607 $biblioitem->{'illus'} = $dbh->quote( $biblioitem->{'illus'} );
1608 $biblioitem->{'pages'} = $dbh->quote( $biblioitem->{'pages'} );
1609 $biblioitem->{'volumeddesc'} = $dbh->quote( $biblioitem->{'volumeddesc'} );
1610 $biblioitem->{'bnotes'} = $dbh->quote( $biblioitem->{'bnotes'} );
1611 $biblioitem->{'size'} = $dbh->quote( $biblioitem->{'size'} );
1612 $biblioitem->{'place'} = $dbh->quote( $biblioitem->{'place'} );
1614 $query = "Update biblioitems set
1615 itemtype = $biblioitem->{'itemtype'},
1616 url = $biblioitem->{'url'},
1617 isbn = $biblioitem->{'isbn'},
1618 publishercode = $biblioitem->{'publishercode'},
1619 publicationyear = $biblioitem->{'publicationyear'},
1620 classification = $biblioitem->{'classification'},
1621 dewey = $biblioitem->{'dewey'},
1622 subclass = $biblioitem->{'subclass'},
1623 illus = $biblioitem->{'illus'},
1624 pages = $biblioitem->{'pages'},
1625 volumeddesc = $biblioitem->{'volumeddesc'},
1626 notes = $biblioitem->{'bnotes'},
1627 size = $biblioitem->{'size'},
1628 place = $biblioitem->{'place'}
1629 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1632 if ( $dbh->errstr ) {
1640 my ( $dbh, $bibitemnum, $note ) = @_;
1642 # my $dbh=C4Connect;
1643 my $query = "update biblioitems set notes='$note' where
1644 biblioitemnumber='$bibitemnum'";
1645 my $sth = $dbh->prepare($query);
1652 sub OLDnewbiblioitem {
1653 my ( $dbh, $biblioitem ) = @_;
1655 # my $dbh = C4Connect;
1656 my $sth = $dbh->prepare("Select max(biblioitemnumber) from biblioitems");
1661 $data = $sth->fetchrow_arrayref;
1662 $bibitemnum = $$data[0] + 1;
1666 $sth = $dbh->prepare( "insert into biblioitems set
1667 biblioitemnumber = ?, biblionumber = ?,
1668 volume = ?, number = ?,
1669 classification = ?, itemtype = ?,
1671 issn = ?, dewey = ?,
1672 subclass = ?, publicationyear = ?,
1673 publishercode = ?, volumedate = ?,
1674 volumeddesc = ?, illus = ?,
1675 pages = ?, notes = ?,
1677 marc = ?, place = ?"
1680 $bibitemnum, $biblioitem->{'biblionumber'},
1681 $biblioitem->{'volume'}, $biblioitem->{'number'},
1682 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
1683 $biblioitem->{'url'}, $biblioitem->{'isbn'},
1684 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
1685 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
1686 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
1687 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
1688 $biblioitem->{'pages'}, $biblioitem->{'bnotes'},
1689 $biblioitem->{'size'}, $biblioitem->{'lccn'},
1690 $biblioitem->{'marc'}, $biblioitem->{'place'}
1695 return ($bibitemnum);
1699 my ( $dbh, $bibnum ) = @_;
1701 $dbh->prepare("insert into bibliosubject (biblionumber) values (?)");
1702 $sth->execute($bibnum);
1706 sub OLDnewsubtitle {
1707 my ( $dbh, $bibnum, $subtitle ) = @_;
1710 "insert into bibliosubtitle set biblionumber = ?, subtitle = ?");
1711 $sth->execute( $bibnum, $subtitle );
1716 my ( $dbh, $item, $barcode ) = @_;
1718 # my $dbh = C4Connect;
1719 my $sth = $dbh->prepare("Select max(itemnumber) from items");
1725 $data = $sth->fetchrow_hashref;
1726 $itemnumber = $data->{'max(itemnumber)'} + 1;
1729 # FIXME the "notforloan" field seems to be named "loan" in some places. workaround bugfix.
1730 if ( $item->{'loan'} ) {
1731 $item->{'notforloan'} = $item->{'loan'};
1734 # if dateaccessioned is provided, use it. Otherwise, set to NOW()
1735 if ( $item->{'dateaccessioned'} ) {
1736 $sth = $dbh->prepare( "Insert into items set
1737 itemnumber = ?, biblionumber = ?,
1738 biblioitemnumber = ?, barcode = ?,
1739 booksellerid = ?, dateaccessioned = ?,
1740 homebranch = ?, holdingbranch = ?,
1741 price = ?, replacementprice = ?,
1742 replacementpricedate = NOW(), itemnotes = ?,
1743 itemcallnumber =?, notforloan = ?
1747 $itemnumber, $item->{'biblionumber'},
1748 $item->{'biblioitemnumber'}, $barcode,
1749 $item->{'booksellerid'}, $item->{'dateaccessioned'},
1750 $item->{'homebranch'}, $item->{'holdingbranch'},
1751 $item->{'price'}, $item->{'replacementprice'},
1752 $item->{'itemnotes'}, $item->{'itemcallnumber'},
1753 $item->{'notforloan'}
1757 $sth = $dbh->prepare( "Insert into items set
1758 itemnumber = ?, biblionumber = ?,
1759 biblioitemnumber = ?, barcode = ?,
1760 booksellerid = ?, dateaccessioned = NOW(),
1761 homebranch = ?, holdingbranch = ?,
1762 price = ?, replacementprice = ?,
1763 replacementpricedate = NOW(), itemnotes = ?,
1764 itemcallnumber = ? , notforloan = ?
1768 $itemnumber, $item->{'biblionumber'},
1769 $item->{'biblioitemnumber'}, $barcode,
1770 $item->{'booksellerid'}, $item->{'homebranch'},
1771 $item->{'holdingbranch'}, $item->{'price'},
1772 $item->{'replacementprice'}, $item->{'itemnotes'},
1773 $item->{'itemcallnumber'}, $item->{'notforloan'}
1776 if ( defined $sth->errstr ) {
1777 $error .= $sth->errstr;
1780 return ( $itemnumber, $error );
1784 my ( $dbh, $item ) = @_;
1786 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1787 # my $dbh=C4Connect;
1788 $item->{'itemnum'} = $item->{'itemnumber'} unless $item->{'itemnum'};
1790 "update items set barcode=?,itemnotes=?,itemcallnumber=?,notforloan=? where itemnumber=?";
1792 $item->{'barcode'}, $item->{'notes'},
1793 $item->{'itemcallnumber'}, $item->{'notforloan'},
1796 if ( $item->{'barcode'} eq '' ) {
1797 $item->{'notforloan'} = 0 unless $item->{'notforloan'};
1798 $query = "update items set notforloan=? where itemnumber=?";
1799 @bind = ( $item->{'notforloan'}, $item->{'itemnum'} );
1801 if ( $item->{'lost'} ne '' ) {
1802 $query = "update items set biblioitemnumber=?,
1810 where itemnumber=?";
1812 $item->{'bibitemnum'}, $item->{'barcode'},
1813 $item->{'notes'}, $item->{'homebranch'},
1814 $item->{'lost'}, $item->{'wthdrawn'},
1815 $item->{'itemcallnumber'}, $item->{'notforloan'},
1819 if ( $item->{'replacement'} ne '' ) {
1820 $query =~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1822 my $sth = $dbh->prepare($query);
1823 $sth->execute(@bind);
1830 my ( $dbh, $itemnum ) = @_;
1832 # my $dbh=C4Connect;
1833 my $sth = $dbh->prepare("select * from items where itemnumber=?");
1834 $sth->execute($itemnum);
1835 my $data = $sth->fetchrow_hashref;
1837 my $query = "Insert into deleteditems set ";
1839 foreach my $temp ( keys %$data ) {
1840 $query .= "$temp = ?,";
1841 push ( @bind, $data->{$temp} );
1846 $sth = $dbh->prepare($query);
1847 $sth->execute(@bind);
1849 $sth = $dbh->prepare("Delete from items where itemnumber=?");
1850 $sth->execute($itemnum);
1856 sub OLDdeletebiblioitem {
1857 my ( $dbh, $biblioitemnumber ) = @_;
1859 # my $dbh = C4Connect;
1860 my $sth = $dbh->prepare( "Select * from biblioitems
1861 where biblioitemnumber = ?"
1865 $sth->execute($biblioitemnumber);
1867 if ( $results = $sth->fetchrow_hashref ) {
1871 "Insert into deletedbiblioitems (biblioitemnumber, biblionumber, volume, number, classification, itemtype,
1872 isbn, issn ,dewey ,subclass ,publicationyear ,publishercode ,volumedate ,volumeddesc ,timestamp ,illus ,
1873 pages ,notes ,size ,url ,lccn ) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
1877 $results->{biblioitemnumber}, $results->{biblionumber},
1878 $results->{volume}, $results->{number},
1879 $results->{classification}, $results->{itemtype},
1880 $results->{isbn}, $results->{issn},
1881 $results->{dewey}, $results->{subclass},
1882 $results->{publicationyear}, $results->{publishercode},
1883 $results->{volumedate}, $results->{volumeddesc},
1884 $results->{timestamp}, $results->{illus},
1885 $results->{pages}, $results->{notes},
1886 $results->{size}, $results->{url},
1890 $dbh->prepare("Delete from biblioitems where biblioitemnumber = ?");
1891 $sth2->execute($biblioitemnumber);
1896 # Now delete all the items attached to the biblioitem
1897 $sth = $dbh->prepare("Select * from items where biblioitemnumber = ?");
1898 $sth->execute($biblioitemnumber);
1900 while ( my $data = $sth->fetchrow_hashref ) {
1901 my $query = "Insert into deleteditems set ";
1903 foreach my $temp ( keys %$data ) {
1904 $query .= "$temp = ?,";
1905 push ( @bind, $data->{$temp} );
1908 my $sth2 = $dbh->prepare($query);
1909 $sth2->execute(@bind);
1912 $sth = $dbh->prepare("Delete from items where biblioitemnumber = ?");
1913 $sth->execute($biblioitemnumber);
1917 } # sub deletebiblioitem
1920 my ( $dbh, $biblio ) = @_;
1921 my $sth = $dbh->prepare("select * from biblio where biblionumber=?");
1922 $sth->execute($biblio);
1923 if ( my $data = $sth->fetchrow_hashref ) {
1925 my $query = "Insert into deletedbiblio set ";
1927 foreach my $temp ( keys %$data ) {
1928 $query .= "$temp = ?,";
1929 push ( @bind, $data->{$temp} );
1932 #replacing the last , by ",?)"
1934 $sth = $dbh->prepare($query);
1935 $sth->execute(@bind);
1937 $sth = $dbh->prepare("Delete from biblio where biblionumber=?");
1938 $sth->execute($biblio);
1952 my $dbh = C4::Context->dbh;
1955 my $sth = $dbh->prepare("Select count(*) from items where biblionumber=?");
1956 $sth->execute($biblio);
1957 my $data = $sth->fetchrow_hashref;
1959 return ( $data->{'count(*)'} );
1964 ($order, $ordernumber) = &getorder($biblioitemnumber, $biblionumber);
1966 Looks up the order with the given biblionumber and biblioitemnumber.
1968 Returns a two-element array. C<$ordernumber> is the order number.
1969 C<$order> is a reference-to-hash describing the order; its keys are
1970 fields from the biblio, biblioitems, aqorders, and aqorderbreakdown
1971 tables of the Koha database.
1976 # FIXME - This is effectively identical to &C4::Catalogue::getorder.
1977 # Pick one and stick with it.
1979 my ( $bi, $bib ) = @_;
1980 my $dbh = C4::Context->dbh;
1981 my $sth = $dbh->prepare( "Select ordernumber
1983 where biblionumber=? and biblioitemnumber=?"
1985 $sth->execute( $bib, $bi );
1987 # FIXME - Use fetchrow_array(), since we're only interested in the one
1989 my $ordnum = $sth->fetchrow_hashref;
1991 my $order = getsingleorder( $ordnum->{'ordernumber'} );
1992 return ( $order, $ordnum->{'ordernumber'} );
1995 =item getsingleorder
1997 $order = &getsingleorder($ordernumber);
1999 Looks up an order by order number.
2001 Returns a reference-to-hash describing the order. The keys of
2002 C<$order> are fields from the biblio, biblioitems, aqorders, and
2003 aqorderbreakdown tables of the Koha database.
2008 # FIXME - This is effectively identical to
2009 # &C4::Catalogue::getsingleorder.
2010 # Pick one and stick with it.
2011 sub getsingleorder {
2013 my $dbh = C4::Context->dbh;
2016 "Select * from biblio,biblioitems,aqorders left join aqorderbreakdown
2017 on aqorders.ordernumber=aqorderbreakdown.ordernumber
2018 where aqorders.ordernumber=?
2019 and biblio.biblionumber=aqorders.biblionumber
2020 and biblioitems.biblioitemnumber=aqorders.biblioitemnumber"
2022 $sth->execute($ordnum);
2023 my $data = $sth->fetchrow_hashref;
2030 my $dbh = C4::Context->dbh;
2031 my $bibnum = OLDnewbiblio( $dbh, $biblio );
2033 # finds new (MARC bibid
2034 # my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
2035 my $record = &MARCkoha2marcBiblio( $dbh, $bibnum );
2036 MARCaddbiblio( $dbh, $record, $bibnum );
2042 $biblionumber = &modbiblio($biblio);
2044 Update a biblio record.
2046 C<$biblio> is a reference-to-hash whose keys are the fields in the
2047 biblio table in the Koha database. All fields must be present, not
2048 just the ones you wish to change.
2050 C<&modbiblio> updates the record defined by
2051 C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
2053 C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
2060 my $dbh = C4::Context->dbh;
2061 my $biblionumber=OLDmodbiblio($dbh,$biblio);
2062 my $record = MARCkoha2marcBiblio($dbh,$biblionumber,$biblionumber);
2063 # finds new (MARC bibid
2064 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
2065 MARCmodbiblio($dbh,$bibid,$record,"",0);
2066 return($biblionumber);
2071 &modsubtitle($biblionumber, $subtitle);
2073 Sets the subtitle of a book.
2075 C<$biblionumber> is the biblionumber of the book to modify.
2077 C<$subtitle> is the new subtitle.
2082 my ( $bibnum, $subtitle ) = @_;
2083 my $dbh = C4::Context->dbh;
2084 &OLDmodsubtitle( $dbh, $bibnum, $subtitle );
2089 &modaddauthor($biblionumber, $author);
2091 Replaces all additional authors for the book with biblio number
2092 C<$biblionumber> with C<$author>. If C<$author> is the empty string,
2093 C<&modaddauthor> deletes all additional authors.
2098 my ( $bibnum, @authors ) = @_;
2099 my $dbh = C4::Context->dbh;
2100 &OLDmodaddauthor( $dbh, $bibnum, @authors );
2101 } # sub modaddauthor
2105 $error = &modsubject($biblionumber, $force, @subjects);
2107 $force - a subject to force
2109 $error - Error message, or undef if successful.
2114 my ( $bibnum, $force, @subject ) = @_;
2115 my $dbh = C4::Context->dbh;
2116 my $error = &OLDmodsubject( $dbh, $bibnum, $force, @subject );
2121 my ($biblioitem) = @_;
2122 my $dbh = C4::Context->dbh;
2123 &OLDmodbibitem( $dbh, $biblioitem );
2127 my ( $bibitemnum, $note ) = @_;
2128 my $dbh = C4::Context->dbh;
2129 &OLDmodnote( $dbh, $bibitemnum, $note );
2133 my ($biblioitem) = @_;
2134 my $dbh = C4::Context->dbh;
2135 my $bibitemnum = &OLDnewbiblioitem( $dbh, $biblioitem );
2137 ################################################################
2138 ## Fix template and shift this to newbiblio
2139 my @subjects = split ( /\n/, $biblioitem->{'subjectheadings'} );
2140 modsubject( $biblioitem->{'biblionumber'}, 1, @subjects );
2142 ################################################################
2144 MARCkoha2marcBiblio( $dbh, 0, $bibitemnum )
2145 ; # the 0 means "do NOT retrieve biblio, only biblioitem, in the MARC record
2147 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh,
2148 $biblioitem->{biblionumber} );
2149 &MARCaddbiblio( $dbh, $MARCbiblio, $biblioitem->{biblionumber}, $bibid );
2150 return ($bibitemnum);
2155 my $dbh = C4::Context->dbh;
2156 &OLDnewsubject( $dbh, $bibnum );
2160 my ( $bibnum, $subtitle ) = @_;
2161 my $dbh = C4::Context->dbh;
2162 &OLDnewsubtitle( $dbh, $bibnum, $subtitle );
2166 my ( $item, @barcodes ) = @_;
2167 my $dbh = C4::Context->dbh;
2171 foreach my $barcode (@barcodes) {
2172 ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, uc($barcode) );
2175 &MARCkoha2marcItem( $dbh, $item->{biblionumber}, $itemnumber );
2176 &MARCadditem( $dbh, $MARCitem, $item->{biblionumber} );
2183 my $dbh = C4::Context->dbh;
2184 &OLDmoditem( $dbh, $item );
2186 &MARCkoha2marcItem( $dbh, $item->{'biblionumber'}, $item->{'itemnum'} );
2188 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $item->{biblionumber} );
2189 &MARCmoditem( $dbh, $MARCitem, $bibid, $item->{itemnum}, 0 );
2193 my ( $count, @barcodes ) = @_;
2194 my $dbh = C4::Context->dbh;
2196 my $sth = $dbh->prepare("Select * from items where barcode=?");
2197 for ( my $i = 0 ; $i < $count ; $i++ ) {
2198 $barcodes[$i] = uc $barcodes[$i];
2199 $sth->execute( $barcodes[$i] );
2200 if ( my $data = $sth->fetchrow_hashref ) {
2201 $error .= " Duplicate Barcode: $barcodes[$i]";
2209 my ($bibitemnum) = @_;
2210 my $dbh = C4::Context->dbh;
2213 $dbh->prepare("Select count(*) from items where biblioitemnumber=?");
2214 $sth->execute($bibitemnum);
2215 my $data = $sth->fetchrow_hashref;
2217 return ( $data->{'count(*)'} );
2222 my $dbh = C4::Context->dbh;
2223 &OLDdelitem( $dbh, $itemnum );
2226 sub deletebiblioitem {
2227 my ($biblioitemnumber) = @_;
2228 my $dbh = C4::Context->dbh;
2229 &OLDdeletebiblioitem( $dbh, $biblioitemnumber );
2230 } # sub deletebiblioitem
2234 my $dbh = C4::Context->dbh;
2235 &OLDdelbiblio( $dbh, $biblio );
2236 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $biblio );
2237 &MARCdelbiblio( $dbh, $bibid, 0 );
2241 my ($biblionumber) = @_;
2242 my $dbh = C4::Context->dbh;
2243 my $sth = $dbh->prepare("Select * from biblio where biblionumber = ?");
2245 # || die "Cannot prepare $query\n" . $dbh->errstr;
2249 $sth->execute($biblionumber);
2251 # || die "Cannot execute $query\n" . $sth->errstr;
2252 while ( my $data = $sth->fetchrow_hashref ) {
2253 $results[$count] = $data;
2258 return ( $count, @results );
2262 my ($biblioitemnum) = @_;
2263 my $dbh = C4::Context->dbh;
2264 my $sth = $dbh->prepare( "Select * from biblioitems where
2265 biblioitemnumber = ?"
2270 $sth->execute($biblioitemnum);
2272 while ( my $data = $sth->fetchrow_hashref ) {
2273 $results[$count] = $data;
2278 return ( $count, @results );
2279 } # sub getbiblioitem
2281 sub getbiblioitembybiblionumber {
2282 my ($biblionumber) = @_;
2283 my $dbh = C4::Context->dbh;
2284 my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?");
2288 $sth->execute($biblionumber);
2290 while ( my $data = $sth->fetchrow_hashref ) {
2291 $results[$count] = $data;
2296 return ( $count, @results );
2300 my $dbh = C4::Context->dbh;
2301 my $query = "select * from itemtypes order by description";
2302 my $sth = $dbh->prepare($query);
2304 # || die "Cannot prepare $query" . $dbh->errstr;
2310 # || die "Cannot execute $query\n" . $sth->errstr;
2311 while ( my $data = $sth->fetchrow_hashref ) {
2312 $results[$count] = $data;
2317 return ( $count, @results );
2318 } # sub getitemtypes
2320 sub getitemsbybiblioitem {
2321 my ($biblioitemnum) = @_;
2322 my $dbh = C4::Context->dbh;
2323 my $sth = $dbh->prepare( "Select * from items, biblio where
2324 biblio.biblionumber = items.biblionumber and biblioitemnumber
2328 # || die "Cannot prepare $query\n" . $dbh->errstr;
2332 $sth->execute($biblioitemnum);
2334 # || die "Cannot execute $query\n" . $sth->errstr;
2335 while ( my $data = $sth->fetchrow_hashref ) {
2336 $results[$count] = $data;
2341 return ( $count, @results );
2342 } # sub getitemsbybiblioitem
2346 # Subroutine to log changes to databases
2347 # Eventually, this subroutine will be used to create a log of all changes made,
2348 # with the possibility of "undo"ing some changes
2349 my $database = shift;
2350 if ( $database eq 'kohadb' ) {
2352 my $section = shift;
2354 my $original = shift;
2357 # print STDERR "KOHA: $type $section $item $original $new\n";
2359 elsif ( $database eq 'marc' ) {
2361 my $Record_ID = shift;
2364 my $subfield_ID = shift;
2365 my $original = shift;
2368 # print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2372 #------------------------------------------------
2374 #---------------------------------------
2375 # Find a biblio entry, or create a new one if it doesn't exist.
2376 # If a "subtitle" entry is in hash, add it to subtitle table
2377 sub getoraddbiblio {
2382 # FIXME - Unused argument
2383 $biblio, # hash ref to fields
2394 $dbh = C4::Context->dbh;
2396 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2397 $sth = $dbh->prepare( "select biblionumber
2399 where title=? and author=?
2400 and copyrightdate=? and seriestitle=?"
2403 $biblio->{title}, $biblio->{author},
2404 $biblio->{copyright}, $biblio->{seriestitle}
2407 ($biblionumber) = $sth->fetchrow;
2408 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2412 # Doesn't exist. Add new one.
2413 print "<PRE>Adding biblio</PRE>\n" if $debug;
2414 ( $biblionumber, $error ) = &newbiblio($biblio);
2415 if ($biblionumber) {
2416 print "<PRE>Added with biblio number=$biblionumber</PRE>\n"
2418 if ( $biblio->{subtitle} ) {
2419 &newsubtitle( $biblionumber, $biblio->{subtitle} );
2423 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2427 return $biblionumber, $error;
2429 } # sub getoraddbiblio
2433 # converts ISO 5426 coded string to ISO 8859-1
2434 # sloppy code : should be improved in next issue
2435 my ( $string, $encoding ) = @_;
2438 # $encoding = C4::Context->preference("marcflavour") unless $encoding;
2439 if ( $encoding eq "UNIMARC" ) {
2502 # this handles non-sorting blocks (if implementation requires this)
2503 $string = nsb_clean($_);
2505 elsif ( $encoding eq "USMARC" || $encoding eq "MARC21" ) {
2506 if (/[\xc1-\xff]/) {
2559 # this handles non-sorting blocks (if implementation requires this)
2560 $string = nsb_clean($_);
2567 my $NSB = '\x88'; # NSB : begin Non Sorting Block
2568 my $NSE = '\x89'; # NSE : Non Sorting Block end
2569 # handles non sorting blocks
2573 s/[ ]{0,1}$NSE/) /gm;
2578 END { } # module clean-up code here (global destructor)
2584 Koha Developement team <info@koha.org>
2586 Paul POULAIN paul.poulain@free.fr
2592 # Revision 1.96 2004/06/29 16:07:10 tipaul
2593 # last sync for 2.1.0 release
2595 # Revision 1.95 2004/06/26 23:19:59 rangi
2596 # Fixing modaddauthor, and adding getitemtypes.
2597 # Also tidying up formatting of code
2599 # Revision 1.94 2004/06/17 08:16:32 tipaul
2600 # merging tag & subfield in marc_word for better perfs
2602 # Revision 1.93 2004/06/11 15:38:06 joshferraro
2603 # Changes MARCaddword to index words >= 1 char ... needed for more accurate
2604 # searches using SearchMarc routines.
2606 # Revision 1.92 2004/06/10 08:29:01 tipaul
2607 # MARC authority management (continued)
2609 # Revision 1.91 2004/06/03 10:03:01 tipaul
2610 # * frameworks and itemtypes are independant
2611 # * in the MARC editor, showing the + to duplicate a tag only if the tag is repeatable
2613 # Revision 1.90 2004/05/28 08:25:53 tipaul
2614 # hidding hidden & isurl constraints into MARC subfield structure
2616 # Revision 1.89 2004/05/27 21:47:21 rangi
2619 # Revision 1.88 2004/05/18 15:23:49 tipaul
2620 # framework management : 1 MARC framework for each itemtype
2622 # Revision 1.87 2004/05/18 11:54:07 tipaul
2623 # getitemtypes moved in Koha.pm
2625 # Revision 1.86 2004/05/03 09:19:22 tipaul
2626 # some fixes for mysql prepare & execute
2628 # Revision 1.85 2004/04/02 14:55:48 tipaul
2629 # renaming items.bulk field to items.itemcallnumber.
2630 # Will be used to store call number for libraries that don't use dewey classification.
2631 # Note it's related to ITEMS, not biblio.
2633 # Revision 1.84 2004/03/24 17:18:30 joshferraro
2634 # Fixes bug 749 by removing the comma on line 1488.
2636 # Revision 1.83 2004/03/15 14:31:50 tipaul
2637 # adding a minor check
2639 # Revision 1.82 2004/03/07 05:47:31 acli
2640 # Various updates/fixes from rel_2_0
2641 # Fixes for bugs 721 (templating), 727, and 734
2643 # Revision 1.81 2004/03/06 20:26:13 tipaul
2644 # adding seealso feature in MARC searches
2646 # Revision 1.80 2004/02/12 13:40:56 tipaul
2647 # deleting subs duplicated by error
2649 # Revision 1.79 2004/02/11 08:40:09 tipaul
2650 # synch'ing 2.0.0 branch and head
2652 # Revision 1.78.2.3 2004/02/10 13:15:46 tipaul
2653 # removing 2 warnings
2655 # Revision 1.78.2.2 2004/01/26 10:38:06 tipaul
2656 # dealing correctly "bulk" field
2658 # Revision 1.78.2.1 2004/01/13 17:29:53 tipaul
2659 # * minor html fixes
2660 # * adding publisher in acquisition process (& ordering basket by publisher)
2662 # Revision 1.78 2003/12/09 15:57:28 tipaul
2663 # rolling back to working char_decode sub
2665 # Revision 1.77 2003/12/03 17:47:14 tipaul
2666 # bugfixes for biblio deletion
2668 # Revision 1.76 2003/12/03 01:43:41 slef
2671 # Revision 1.75 2003/12/03 01:42:03 slef
2672 # bug 662 fixes securing DBI
2674 # Revision 1.74 2003/11/28 09:48:33 tipaul
2675 # bugfix : misusing prepare & execute => now using prepare(?) and execute($var)
2677 # Revision 1.73 2003/11/28 09:45:25 tipaul
2678 # bugfix for iso2709 file import in the "notforloan" field.
2680 # But notforloan field called "loan" somewhere, so in case "loan" is used, copied to "notforloan" to avoid a bug.
2682 # Revision 1.72 2003/11/24 17:40:14 tipaul
2685 # Revision 1.71 2003/11/24 16:28:49 tipaul
2686 # biblio & item deletion now works fine in MARC editor.
2687 # Stores deleted biblio/item in the marc field of the deletedbiblio/deleteditem table.
2689 # Revision 1.70 2003/11/24 13:29:55 tipaul
2690 # moving $id from beginning to end of file (70 commits... huge comments...)
2692 # Revision 1.69 2003/11/24 13:27:17 tipaul
2693 # fix for #380 (bibliosubject)
2695 # Revision 1.68 2003/11/06 17:18:30 tipaul
2698 # 1st draft for MARC biblio deletion.
2699 # Still does not work well, but at least, Biblio.pm compiles & it should'nt break too many things
2700 # (Note the trash in the MARCdetail, but don't use it, please :-) )
2702 # Revision 1.67 2003/10/25 08:46:27 tipaul
2703 # minor fixes for bilbio deletion (still buggy)
2705 # Revision 1.66 2003/10/17 10:02:56 tipaul
2706 # Indexing only words longer than 2 letters. Was >=2 before, & 2 letters words usually means nothing.
2708 # Revision 1.65 2003/10/14 09:45:29 tipaul
2709 # 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)
2711 # Revision 1.64 2003/10/06 15:20:51 tipaul
2712 # fix for 536 (subtitle error)
2714 # Revision 1.63 2003/10/01 13:25:49 tipaul
2715 # seems a char encoding problem modified something in char_decode sub... changing back to something that works...
2717 # Revision 1.62 2003/09/17 14:21:13 tipaul
2718 # fixing bug that makes a MARC biblio disappear when using full acquisition (order => recieve ==> MARC editor).
2719 # Before this 2 lines fix, the MARC biblio was deleted during recieve, and had to be entirely recreated :-(
2721 # Revision 1.61 2003/09/17 10:24:39 tipaul
2722 # notforloan value in itemtype was overwritting notforloan value in a given item.
2723 # I changed this behaviour :
2724 # if notforloan is set for a given item, and NOT for all items from this itemtype, the notforloan is kept.
2725 # If notforloan is set for itemtype, it's used (and impossible to loan a specific item from this itemtype)
2727 # Revision 1.60 2003/09/04 14:11:23 tipaul
2728 # fix for 593 (data duplication in MARC-DB)
2730 # Revision 1.58 2003/08/06 12:54:52 tipaul
2731 # fix for publicationyear : extracting numeric value from MARC string, like for copyrightdate.
2732 # (note that copyrightdate still extracted to get numeric format)
2734 # Revision 1.57 2003/07/15 23:09:18 slef
2735 # change show columns to use biblioitems bnotes too
2737 # Revision 1.56 2003/07/15 11:34:52 slef
2738 # fixes from paul email
2740 # Revision 1.55 2003/07/15 00:02:49 slef
2741 # Work on bug 515... can we do a single-side rename of notes to bnotes?
2743 # Revision 1.54 2003/07/11 11:51:32 tipaul
2744 # *** empty log message ***
2746 # Revision 1.52 2003/07/10 10:37:19 tipaul
2747 # fix for copyrightdate problem, #514
2749 # Revision 1.51 2003/07/02 14:47:17 tipaul
2750 # fix for #519 : items.dateaccessioned imports incorrectly
2752 # Revision 1.49 2003/06/17 11:21:13 tipaul
2753 # improvments/fixes for z3950 support.
2754 # * Works now even on ADD, not only on MODIFY
2755 # * able to search on ISBN, author, title
2757 # Revision 1.48 2003/06/16 09:22:53 rangi
2758 # Just added an order clause to getitemtypes
2760 # Revision 1.47 2003/05/20 16:22:44 tipaul
2761 # fixing typo in Biblio.pm POD
2763 # Revision 1.46 2003/05/19 13:45:18 tipaul
2764 # support for subtitles, additional authors, subject.
2765 # 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.
2766 # Note that some OLD-DB subs are strange (dummy ?) see OLDmodsubject, OLDmodsubtitle, OLDmodaddiauthor in C4/Biblio.pm
2767 # 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.
2769 # Revision 1.45 2003/04/29 16:50:49 tipaul
2770 # really proud of this commit :-)
2771 # z3950 search and import seems to works fine.
2772 # Let me explain how :
2773 # * a "search z3950" button is added in the addbiblio template.
2774 # * when clicked, a popup appears and z3950/search.pl is called
2775 # * z3950/search.pl calls addz3950search in the DB
2776 # * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table.
2777 # * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending.
2778 # * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled
2781 # * 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.
2782 # * 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.
2784 # Revision 1.44 2003/04/28 13:07:14 tipaul
2785 # Those fixes solves the "internal server error" with MARC::Record 1.12.
2786 # It was due to an illegal contruction in Koha : we tried to retrive subfields from <10 tags.
2787 # That's not possible. MARC::Record accepted this in 0.93 version, but it was fixed after.
2788 # Now, the construct/retrieving is OK !
2790 # Revision 1.43 2003/04/10 13:56:02 tipaul
2792 # * worked in 1.9.0, but not in 1.9.1 :
2793 # - modif of a biblio didn't work
2794 # - 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.
2796 # * did not work before :
2797 # - repeatable subfields now works correctly. Enter 2 subfields separated by | and they will be splitted during saving.
2798 # - dropped the last subfield of the MARC form :-(
2800 # Internal changes :
2801 # - 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.
2802 # Note the MARCdelbiblio has been rewritted to enable deletion of a biblio WITHOUT deleting items.
2804 # Revision 1.42 2003/04/04 08:41:11 tipaul
2805 # last commits before 1.9.1
2807 # Revision 1.41 2003/04/01 12:26:43 tipaul
2810 # Revision 1.40 2003/03/11 15:14:03 tipaul
2813 # Revision 1.39 2003/03/07 16:35:42 tipaul
2814 # * moving generic functions to Koha.pm
2815 # * improvement of SearchMarc.pm
2819 # Revision 1.38 2003/02/27 16:51:59 tipaul
2820 # * moving prepare / execute to ? form.
2823 # * road to 1.9.2 => acquisition and cataloguing merging
2825 # Revision 1.37 2003/02/12 11:03:03 tipaul
2826 # Support for 000 -> 010 fields.
2827 # Those fields doesn't have subfields.
2828 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
2829 # 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.
2831 # Revision 1.36 2003/02/12 11:01:01 tipaul
2832 # Support for 000 -> 010 fields.
2833 # Those fields doesn't have subfields.
2834 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
2835 # 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.
2837 # Revision 1.35 2003/02/03 18:46:00 acli
2838 # Minor factoring in C4/Biblio.pm, plus change to export the per-tag
2839 # 'mandatory' property to a per-subfield 'tag_mandatory' template parameter,
2840 # so that addbiblio.tmpl can distinguish between mandatory subfields in a
2841 # mandatory tag and mandatory subfields in an optional tag
2843 # Not-minor factoring in acqui.simple/addbiblio.pl to make the if-else blocks
2844 # smaller, and to add some POD; need further testing for this
2846 # Added function to check if a MARC subfield name is "koha-internal" (instead
2847 # of checking it for 'lib' and 'tag' everywhere); temporarily added to Koha.pm
2849 # Use above function in acqui.simple/additem.pl and search.marc/search.pl
2851 # Revision 1.34 2003/01/28 14:50:04 tipaul
2852 # fixing MARCmodbiblio API and reindenting code
2854 # Revision 1.33 2003/01/23 12:22:37 tipaul
2855 # adding char_decode to decode MARC21 or UNIMARC extended chars
2857 # Revision 1.32 2002/12/16 15:08:50 tipaul
2858 # small but important bugfix (fixes a problem in export)
2860 # Revision 1.31 2002/12/13 16:22:04 tipaul
2861 # 1st draft of marc export
2863 # Revision 1.30 2002/12/12 21:26:35 tipaul
2864 # YAB ! (Yet Another Bugfix) => related to biblio modif
2865 # (some warning cleaning too)
2867 # Revision 1.29 2002/12/12 16:35:00 tipaul
2868 # adding authentification with Auth.pm and
2869 # MAJOR BUGFIX on marc biblio modification
2871 # Revision 1.28 2002/12/10 13:30:03 tipaul
2872 # fugfixes from Dombes Abbey work
2874 # Revision 1.27 2002/11/19 12:36:16 tipaul
2876 # various bugfixes, improvments, and migration from acquisition.pm to biblio.pm
2878 # Revision 1.26 2002/11/12 15:58:43 tipaul
2881 # * 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)
2883 # Revision 1.25 2002/10/25 10:58:26 tipaul
2885 # * bugfixes and improvements
2887 # Revision 1.24 2002/10/24 12:09:01 arensb
2888 # Fixed "no title" warning when generating HTML documentation from POD.
2890 # Revision 1.23 2002/10/16 12:43:08 arensb
2891 # Added some FIXME comments.
2893 # Revision 1.22 2002/10/15 13:39:17 tipaul
2894 # removing Acquisition.pm
2895 # deleting unused code in biblio.pm, rewriting POD and answering most FIXME comments
2897 # Revision 1.21 2002/10/13 11:34:14 arensb
2898 # Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
2899 # Thus, $x = $x+2 becomes $x += 2, and so forth.
2901 # Revision 1.20 2002/10/13 08:28:32 arensb
2902 # Deleted unused variables.
2903 # Removed trailing whitespace.
2905 # Revision 1.19 2002/10/13 05:56:10 arensb
2906 # Added some FIXME comments.
2908 # Revision 1.18 2002/10/11 12:34:53 arensb
2909 # Replaced &requireDBI with C4::Context->dbh
2911 # Revision 1.17 2002/10/10 14:48:25 tipaul
2914 # Revision 1.16 2002/10/07 14:04:26 tipaul
2915 # road to 1.3.1 : viewing MARC biblio
2917 # Revision 1.15 2002/10/05 09:49:25 arensb
2918 # Merged with arensb-context branch: use C4::Context->dbh instead of
2919 # &C4Connect, and generally prefer C4::Context over C4::Database.
2921 # Revision 1.14 2002/10/03 11:28:18 tipaul
2922 # Extending Context.pm to add stopword management and using it in MARC-API.
2923 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
2925 # Revision 1.13 2002/10/02 16:26:44 tipaul
2928 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
2929 # Merged in changes from main branch.
2931 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
2932 # Added a whole mess of FIXME comments.
2934 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
2935 # Added some missing semicolons.
2937 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
2938 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
2941 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
2942 # Added a whole mess of FIXME comments.
2944 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
2945 # Added some missing semicolons.
2947 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
2948 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
2951 # Revision 1.12 2002/10/01 11:48:51 arensb
2952 # Added some FIXME comments, mostly marking duplicate functions.
2954 # Revision 1.11 2002/09/24 13:49:26 tipaul
2955 # long WAS the road to 1.3.0...
2956 # coming VERY SOON NOW...
2957 # modifying installer and buildrelease to update the DB
2959 # Revision 1.10 2002/09/22 16:50:08 arensb
2960 # Added some FIXME comments.
2962 # Revision 1.9 2002/09/20 12:57:46 tipaul
2963 # long is the road to 1.4.0
2964 # * MARCadditem and MARCmoditem now wroks
2965 # * various bugfixes in MARC management
2966 # !!! 1.3.0 should be released very soon now. Be careful !!!
2968 # Revision 1.8 2002/09/10 13:53:52 tipaul
2969 # MARC API continued...
2971 # * 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)
2973 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
2975 # Revision 1.7 2002/08/14 18:12:51 tonnesen
2976 # Added copyright statement to all .pl and .pm files
2978 # Revision 1.6 2002/07/25 13:40:31 tipaul
2979 # pod documenting the API.
2981 # Revision 1.5 2002/07/24 16:11:37 tipaul
2983 # Database.pm and Output.pm are almost not modified (var test...)
2985 # Biblio.pm is almost completly rewritten.
2987 # WHAT DOES IT ??? ==> END of Hitchcock suspens
2989 # 1st, it does... nothing...
2990 # 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 ...
2992 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
2993 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
2994 # * 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.
2995 # * 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.
2996 # 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 ;-)
2998 # 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.
2999 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.