2 # Copyright 2000-2002 Katipo Communications
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along with
16 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
17 # Suite 330, Boston, MA 02111-1307 USA
25 use vars qw($VERSION @ISA @EXPORT);
27 # set the version for version checking
32 # don't forget MARCxxx subs are exported only for testing purposes. Should not be used
33 # as the old-style API and the NEW one are the only public functions.
36 &updateBiblio &updateBiblioItem &updateItem
37 &itemcount &newbiblio &newbiblioitem
38 &modnote &newsubject &newsubtitle
39 &modbiblio &checkitems
41 &modsubtitle &modsubject &modaddauthor &moditem &countitems
42 &delitem &deletebiblioitem &delbiblio
43 &getitemtypes &getbiblio
44 &getbiblioitembybiblionumber
45 &getbiblioitem &getitemsbybiblioitem
47 &newcompletebiblioitem
49 &MARCfind_oldbiblionumber_from_MARCbibid
50 &MARCfind_MARCbibid_from_oldbiblionumber
51 &MARCfind_marc_from_kohafield
55 &NEWnewbiblio &NEWnewitem
56 &NEWmodbiblio &NEWmoditem
57 &NEWdelbiblio &NEWdelitem
59 &MARCaddbiblio &MARCadditem
60 &MARCmodsubfield &MARCaddsubfield
61 &MARCmodbiblio &MARCmoditem
62 &MARCkoha2marcBiblio &MARCmarc2koha
63 &MARCkoha2marcItem &MARChtml2marc
64 &MARCgetbiblio &MARCgetitem
65 &MARCaddword &MARCdelword
71 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
74 # all the following subs takes a MARC::Record as parameter and manage
75 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
76 # NEWxxx subs (xxx deals with old-DB parameters, the NEWxxx deals with MARC-DB parameter)
80 C4::Biblio - acquisition, catalog management functions
84 move from 1.2 to 1.4 version :
85 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
86 In the 1.4 version, we want to do 2 differents things :
87 - keep populating the old-DB, that has a LOT less datas than MARC
88 - populate the MARC-DB
89 To populate the DBs we have 2 differents sources :
90 - the standard acquisition system (through book sellers), that does'nt use MARC data
91 - the MARC acquisition system, that uses MARC data.
93 Thus, we have 2 differents cases :
94 - 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
95 - 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
97 That's why we need 4 subs :
98 all I<subs beginning by MARC> manage only MARC tables. They manage MARC-DB with MARC::Record parameters
99 all I<subs beginning by OLD> manage only OLD-DB tables. They manage old-DB with old-DB parameters
100 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
101 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.
103 - NEW and old-style API should be used in koha to manage biblio
104 - MARCsubs are divided in 2 parts :
105 * some of them manage MARC parameters. They are heavily used in koha.
106 * some of them manage MARC biblio : they are mostly used by NEW and old-style subs.
107 - OLD are used internally only
109 all subs requires/use $dbh as 1st parameter.
111 I<NEWxxx related subs>
113 all subs requires/use $dbh as 1st parameter.
114 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
116 I<OLDxxx 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 They all are the exact copy of 1.0/1.2 version of the sub without the OLD.
122 The OLDxxx is called by the original xxx sub.
123 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
125 WARNING : there is 1 difference between initialxxx and OLDxxx :
126 the db header $dbh is always passed as parameter to avoid over-DB connexion
132 =item @tagslib = &MARCgettagslib($dbh,1|0);
134 last param is 1 for liblibrarian and 0 for libopac
135 returns a hash with tag/subfield meaning
136 =item ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,$kohafield);
138 finds MARC tag and subfield for a given kohafield
139 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
141 =item $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
143 finds a old-db biblio number for a given MARCbibid number
145 =item $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
147 finds a MARC bibid from a old-db biblionumber
149 =item $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
151 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
153 =item $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
155 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
157 =item $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
159 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
161 =item $olddb = &MARCmarc2koha($dbh,$MARCRecord);
163 builds a hash with old-db datas from a MARC::Record
165 =item &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
167 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
169 =item &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
171 adds a subfield in a biblio (in the MARC tables only).
173 =item $MARCRecord = &MARCgetbiblio($dbh,$bibid);
175 Returns a MARC::Record for the biblio $bibid.
177 =item &MARCmodbiblio($dbh,$bibid,$record,$delete);
179 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
180 It 1st delete the biblio, then recreates it.
181 WARNING : the $delete parameter is not used anymore (too much unsolvable cases).
182 =item ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
184 MARCmodsubfield changes the value of a given subfield
186 =item $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
188 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
189 Returns -1 if more than 1 answer
191 =item $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
193 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
195 =item &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
197 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
199 =item &MARCdelbiblio($dbh,$bibid);
201 MARCdelbiblio delete biblio $bibid
203 =item &MARCkoha2marcOnefield
205 used by MARCkoha2marc and should not be useful elsewhere
207 =item &MARCmarc2kohaOnefield
209 used by MARCmarc2koha and should not be useful elsewhere
213 used to manage MARC_word table and should not be useful elsewhere
217 used to manage MARC_word table and should not be useful elsewhere
222 my ($dbh,$forlibrarian)= @_;
224 my $libfield = ($forlibrarian eq 1)? 'liblibrarian' : 'libopac';
225 $sth=$dbh->prepare("select tagfield,$libfield as lib,mandatory from marc_tag_structure order by tagfield");
227 my ($lib,$tag,$res,$tab,$mandatory,$repeatable);
228 while ( ($tag,$lib,$mandatory) = $sth->fetchrow) {
229 $res->{$tag}->{lib}=$lib;
230 $res->{$tab}->{tab}=""; # XXX
231 $res->{$tag}->{mandatory}=$mandatory;
234 $sth=$dbh->prepare("select tagfield,tagsubfield,$libfield as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder,kohafield,seealso from marc_subfield_structure order by tagfield,tagsubfield");
238 my $authorised_value;
239 my $thesaurus_category;
243 while ( ($tag, $subfield, $lib, $tab, $mandatory, $repeatable,$authorised_value,$thesaurus_category,$value_builder,$kohafield,$seealso) = $sth->fetchrow) {
244 $res->{$tag}->{$subfield}->{lib}=$lib;
245 $res->{$tag}->{$subfield}->{tab}=$tab;
246 $res->{$tag}->{$subfield}->{mandatory}=$mandatory;
247 $res->{$tag}->{$subfield}->{repeatable}=$repeatable;
248 $res->{$tag}->{$subfield}->{authorised_value}=$authorised_value;
249 $res->{$tag}->{$subfield}->{thesaurus_category}=$thesaurus_category;
250 $res->{$tag}->{$subfield}->{value_builder}=$value_builder;
251 $res->{$tag}->{$subfield}->{kohafield}=$kohafield;
252 $res->{$tag}->{$subfield}->{seealso}=$seealso;
257 sub MARCfind_marc_from_kohafield {
258 my ($dbh,$kohafield) = @_;
259 return 0,0 unless $kohafield;
260 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
261 $sth->execute($kohafield);
262 my ($tagfield,$tagsubfield) = $sth->fetchrow;
263 return ($tagfield,$tagsubfield);
266 sub MARCfind_oldbiblionumber_from_MARCbibid {
267 my ($dbh,$MARCbibid) = @_;
268 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
269 $sth->execute($MARCbibid);
270 my ($biblionumber) = $sth->fetchrow;
271 return $biblionumber;
274 sub MARCfind_MARCbibid_from_oldbiblionumber {
275 my ($dbh,$oldbiblionumber) = @_;
276 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
277 $sth->execute($oldbiblionumber);
278 my ($bibid) = $sth->fetchrow;
283 # pass the MARC::Record to this function, and it will create the records in the marc tables
284 my ($dbh,$record,$biblionumber,$bibid) = @_;
285 my @fields=$record->fields();
286 # warn "IN MARCaddbiblio $bibid => ".$record->as_formatted;
288 # adding main table, and retrieving bibid
289 # if bibid is sent, then it's not a true add, it's only a re-add, after a delete (ie, a mod)
290 # if bibid empty => true add, find a new bibid number
292 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
293 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
294 $sth->execute($biblionumber);
295 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
297 ($bibid)=$sth->fetchrow;
301 # now, add subfields...
302 foreach my $field (@fields) {
304 if ($field->tag() <10) {
305 &MARCaddsubfield($dbh,$bibid,
314 my @subfields=$field->subfields();
315 foreach my $subfieldcount (0..$#subfields) {
316 &MARCaddsubfield($dbh,$bibid,
318 $field->indicator(1).$field->indicator(2),
320 $subfields[$subfieldcount][0],
322 $subfields[$subfieldcount][1]
327 $dbh->do("unlock tables");
332 # pass the MARC::Record to this function, and it will create the records in the marc tables
333 my ($dbh,$record,$biblionumber) = @_;
334 # warn "adding : ".$record->as_formatted();
335 # search for MARC biblionumber
336 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
337 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
338 my @fields=$record->fields();
339 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
340 $sth->execute($bibid);
341 my ($fieldcount) = $sth->fetchrow;
342 # now, add subfields...
343 foreach my $field (@fields) {
344 my @subfields=$field->subfields();
346 foreach my $subfieldcount (0..$#subfields) {
347 &MARCaddsubfield($dbh,$bibid,
349 $field->indicator(1).$field->indicator(2),
351 $subfields[$subfieldcount][0],
353 $subfields[$subfieldcount][1]
357 $dbh->do("unlock tables");
361 sub MARCaddsubfield {
362 # Add a new subfield to a tag into the DB.
363 my ($dbh,$bibid,$tagid,$tag_indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalues) = @_;
364 # if not value, end of job, we do nothing
365 if (length($subfieldvalues) ==0) {
368 if (not($subfieldcode)) {
371 my @subfieldvalues = split /\|/,$subfieldvalues;
372 foreach my $subfieldvalue (@subfieldvalues) {
373 if (length($subfieldvalue)>255) {
374 $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
375 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
376 $sth->execute($subfieldvalue);
377 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
379 my ($res)=$sth->fetchrow;
380 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?,?)");
381 $sth->execute($bibid,(sprintf "%03s",$tagid),$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$res);
383 warn "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
385 $dbh->do("unlock tables");
387 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)");
388 $sth->execute($bibid,(sprintf "%03s",$tagid),$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue);
390 warn "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
393 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
398 # Returns MARC::Record of the biblio passed in parameter.
400 my $record = MARC::Record->new();
401 #---- TODO : the leader is missing
402 $record->leader(' ');
403 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
404 from marc_subfield_table
405 where bibid=? order by tag,tagorder,subfieldcode
407 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
408 $sth->execute($bibid);
412 my $field; # for >=10 tags
413 my $prevvalue; # for <10 tags
414 while (my $row=$sth->fetchrow_hashref) {
415 if ($row->{'valuebloblink'}) { #---- search blob if there is one
416 $sth2->execute($row->{'valuebloblink'});
417 my $row2=$sth2->fetchrow_hashref;
419 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
421 if ($row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag) {
424 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue) unless $prevtag eq "XXX"; # ignore the 1st loop
426 $record->add_fields($field) unless $prevtag eq "XXX";
429 $prevtagorder=$row->{tagorder};
430 $prevtag = $row->{tag};
431 $previndicator=$row->{tag_indicator};
432 if ($row->{tag}<10) {
433 $prevvalue = $row->{subfieldvalue};
435 $field = MARC::Field->new((sprintf "%03s",$prevtag), substr($row->{tag_indicator}.' ',0,1), substr($row->{tag_indicator}.' ',1,1), $row->{'subfieldcode'}, $row->{'subfieldvalue'} );
438 if ($row->{tag} <10) {
439 $record->add_fields((sprintf "%03s",$row->{tag}), $row->{'subfieldvalue'});
441 $field->add_subfields($row->{'subfieldcode'}, $row->{'subfieldvalue'} );
443 $prevtag= $row->{tag};
444 $previndicator=$row->{tag_indicator};
447 # the last has not been included inside the loop... do it now !
448 if ($prevtag ne "XXX") { # check that we have found something. Otherwise, prevtag is still XXX and we
449 # must return an empty record, not make MARC::Record fail because we try to
450 # create a record with XXX as field :-(
452 $record->add_fields($prevtag,$prevvalue);
454 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
455 $record->add_fields($field);
461 # Returns MARC::Record of the biblio passed in parameter.
462 my ($dbh,$bibid,$itemnumber)=@_;
463 my $record = MARC::Record->new();
464 # search MARC tagorder
465 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=?");
466 $sth2->execute($bibid,$itemnumber);
467 my ($tagorder) = $sth2->fetchrow_array();
468 #---- TODO : the leader is missing
469 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
470 from marc_subfield_table
471 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
473 $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
474 $sth->execute($bibid,$tagorder);
475 while (my $row=$sth->fetchrow_hashref) {
476 if ($row->{'valuebloblink'}) { #---- search blob if there is one
477 $sth2->execute($row->{'valuebloblink'});
478 my $row2=$sth2->fetchrow_hashref;
480 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
482 if ($record->field($row->{'tag'})) {
484 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
485 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
486 if (length($row->{'tag'}) <3) {
487 $row->{'tag'} = "0".$row->{'tag'};
489 $field =$record->field($row->{'tag'});
491 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
492 $record->delete_field($field);
493 $record->add_fields($field);
496 if (length($row->{'tag'}) < 3) {
497 $row->{'tag'} = "0".$row->{'tag'};
499 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
500 $record->add_fields($temp);
508 my ($dbh,$bibid,$record,$delete)=@_;
509 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
510 if ($oldrecord eq $record) {
513 # 1st delete the biblio,
515 my $biblionumber = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
516 &MARCdelbiblio($dbh,$bibid,1);
517 &MARCaddbiblio($dbh,$record,$biblionumber,$bibid);
521 my ($dbh,$bibid,$keep_items) = @_;
522 # if the keep_item is set to 1, then all items are preserved.
523 # This flag is set when the delbiblio is called by modbiblio
524 # due to a too complex structure of MARC (repeatable fields and subfields),
525 # the best solution for a modif is to delete / recreate the record.
527 # 1st of all, copy the MARC::Record to deletedbiblio table => if a true deletion, MARC data will be kept.
528 # if deletion called before MARCmodbiblio => won't do anything, as the oldbiblionumber doesn't
529 # exist in deletedbiblio table
530 my $record = MARCgetbiblio($dbh,$bibid);
531 my $oldbiblionumber = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
532 my $copy2deleted=$dbh->prepare("update deletedbiblio set marc=? where biblionumber=?");
533 $copy2deleted->execute($record->as_usmarc(),$oldbiblionumber);
534 # now, delete in MARC tables.
535 if ($keep_items eq 1) {
536 #search item field code
537 my $sth = $dbh->prepare("select tagfield from marc_subfield_structure where kohafield like 'items.%'");
539 my $itemtag = $sth->fetchrow_hashref->{tagfield};
540 $dbh->do("delete from marc_subfield_table where bibid=$bibid and tag<>$itemtag");
541 $dbh->do("delete from marc_word where bibid=$bibid and tag<>$itemtag");
543 $dbh->do("delete from marc_biblio where bibid=$bibid");
544 $dbh->do("delete from marc_subfield_table where bibid=$bibid");
545 $dbh->do("delete from marc_word where bibid=$bibid");
550 # delete the item passed in parameter in MARC tables.
551 my ($dbh,$bibid,$itemnumber)=@_;
552 # my $record = MARC::Record->new();
553 # search MARC tagorder
554 my $record = MARCgetitem($dbh,$bibid,$itemnumber);
555 my $copy2deleted=$dbh->prepare("update deleteditems set marc=? where itemnumber=?");
556 $copy2deleted->execute($record->as_usmarc(),$itemnumber);
558 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=?");
559 $sth2->execute($bibid,$itemnumber);
560 my ($tagorder) = $sth2->fetchrow_array();
561 my $sth=$dbh->prepare("delete from marc_subfield_table where bibid=? and tagorder=?");
562 $sth->execute($bibid,$tagorder);
566 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
567 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
568 # if nothing to change, don't waste time...
569 if ($oldrecord eq $record) {
572 # otherwise, skip through each subfield...
573 my @fields = $record->fields();
574 # search old MARC item
575 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=?");
576 $sth2->execute($bibid,$itemnumber);
577 my ($tagorder) = $sth2->fetchrow_array();
578 foreach my $field (@fields) {
579 my $oldfield = $oldrecord->field($field->tag());
580 my @subfields=$field->subfields();
582 foreach my $subfield (@subfields) {
584 # warn "compare : $oldfield".$oldfield->subfield(@$subfield[0]);
585 if ($oldfield eq 0 or (length($oldfield->subfield(@$subfield[0])) ==0) ) {
586 # just adding datas...
587 # warn "addfield : / $subfieldorder / @$subfield[0] - @$subfield[1]";
588 # warn "NEW subfield : $bibid,".$field->tag().",".$tagorder.",".@$subfield[0].",".$subfieldorder.",".@$subfield[1].")";
589 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
590 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
592 # warn "modfield : / $subfieldorder / @$subfield[0] - @$subfield[1]";
593 # modify he subfield if it's a different string
594 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
595 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
596 # warn "changing : $subfieldid, $bibid,".$field->tag(),",$tagorder,@$subfield[0],@$subfield[1],$subfieldorder";
597 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
605 sub MARCmodsubfield {
606 # Subroutine changes a subfield value given a subfieldid.
607 my ($dbh, $subfieldid, $subfieldvalue )=@_;
608 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
609 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
610 $sth1->execute($subfieldid);
611 my ($oldvaluebloblink)=$sth1->fetchrow;
614 # if too long, use a bloblink
615 if (length($subfieldvalue)>255 ) {
616 # if already a bloblink, update it, otherwise, insert a new one.
617 if ($oldvaluebloblink) {
618 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
619 $sth->execute($subfieldvalue,$oldvaluebloblink);
621 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
622 $sth->execute($subfieldvalue);
623 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
625 my ($res)=$sth->fetchrow;
626 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=? where subfieldid=?");
627 $sth->execute($res,$subfieldid);
630 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
631 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
632 $sth->execute($subfieldvalue, $subfieldid);
634 $dbh->do("unlock tables");
636 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
637 $sth->execute($subfieldid);
638 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
640 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
641 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
642 return($subfieldid, $subfieldvalue);
645 sub MARCfindsubfield {
646 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
650 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
651 my @bind_values = ($bibid,$tag, $subfieldcode);
652 if ($subfieldvalue) {
653 $query .= " and subfieldvalue=?";
654 push(@bind_values,$subfieldvalue);
656 if ($subfieldorder<1) {
659 $query .= " and subfieldorder=?";
660 push(@bind_values,$subfieldorder);
662 my $sti=$dbh->prepare($query);
663 $sti->execute(@bind_values);
664 while (($subfieldid) = $sti->fetchrow) {
666 $lastsubfieldid=$subfieldid;
668 if ($resultcounter>1) {
669 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
670 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
673 return $lastsubfieldid;
677 sub MARCfindsubfieldid {
678 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
679 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
680 where bibid=? and tag=? and tagorder=?
681 and subfieldcode=? and subfieldorder=?");
682 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
683 my ($res) = $sth->fetchrow;
685 $sth=$dbh->prepare("select subfieldid from marc_subfield_table
686 where bibid=? and tag=? and tagorder=?
687 and subfieldcode=?");
688 $sth->execute($bibid,$tag,$tagorder,$subfield);
689 ($res) = $sth->fetchrow;
694 sub MARCdelsubfield {
695 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
696 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
697 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
698 tag='$tag' and tagorder='$tagorder'
699 and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
703 sub MARCkoha2marcBiblio {
704 # this function builds partial MARC::Record from the old koha-DB fields
705 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
706 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
707 my $record = MARC::Record->new();
708 #--- if bibid, then retrieve old-style koha data
709 if ($biblionumber>0) {
710 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
711 from biblio where biblionumber=?");
712 $sth2->execute($biblionumber);
713 my $row=$sth2->fetchrow_hashref;
715 foreach $code (keys %$row) {
717 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
721 #--- if biblioitem, then retrieve old-style koha data
722 if ($biblioitemnumber>0) {
723 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
724 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
725 volumedate,volumeddesc,timestamp,illus,pages,notes AS bnotes,size,place
727 WHERE biblioitemnumber=?
729 $sth2->execute($biblioitemnumber);
730 my $row=$sth2->fetchrow_hashref;
732 foreach $code (keys %$row) {
734 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
738 # other fields => additional authors, subjects, subtitles
739 my $sth2=$dbh->prepare(" SELECT author FROM additionalauthors WHERE biblionumber=?");
740 $sth2->execute($biblionumber);
741 while (my $row=$sth2->fetchrow_hashref) {
742 &MARCkoha2marcOnefield($sth,$record,"additionalauthors.author",$row->{'author'});
744 my $sth2=$dbh->prepare(" SELECT subject FROM bibliosubject WHERE biblionumber=?");
745 $sth2->execute($biblionumber);
746 while (my $row=$sth2->fetchrow_hashref) {
747 &MARCkoha2marcOnefield($sth,$record,"bibliosubject.subject",$row->{'subject'});
749 my $sth2=$dbh->prepare(" SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?");
750 $sth2->execute($biblionumber);
751 while (my $row=$sth2->fetchrow_hashref) {
752 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.title",$row->{'subtitle'});
757 sub MARCkoha2marcItem {
758 # this function builds partial MARC::Record from the old koha-DB fields
759 my ($dbh,$biblionumber,$itemnumber) = @_;
760 # my $dbh=&C4Connect;
761 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
762 my $record = MARC::Record->new();
763 #--- if item, then retrieve old-style koha data
765 # print STDERR "prepare $biblionumber,$itemnumber\n";
766 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
767 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
768 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,itemcallnumber,issues,renewals,
769 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
771 WHERE itemnumber=?");
772 $sth2->execute($itemnumber);
773 my $row=$sth2->fetchrow_hashref;
775 foreach $code (keys %$row) {
777 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
784 sub MARCkoha2marcSubtitle {
785 # this function builds partial MARC::Record from the old koha-DB fields
786 my ($dbh,$bibnum,$subtitle) = @_;
787 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
788 my $record = MARC::Record->new();
789 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
793 sub MARCkoha2marcOnefield {
794 my ($sth,$record,$kohafieldname,$value)=@_;
797 $sth->execute($kohafieldname);
798 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
799 if ($record->field($tagfield)) {
800 my $tag =$record->field($tagfield);
802 $tag->add_subfields($tagsubfield,$value);
803 $record->delete_field($tag);
804 $record->add_fields($tag);
807 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
814 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
816 my $record = MARC::Record->new();
817 # my %subfieldlist=();
818 my $prevvalue; # if tag <10
819 my $field; # if tag >=10
820 for (my $i=0; $i< @$rtags; $i++) {
821 # rebuild MARC::Record
822 if (@$rtags[$i] ne $prevtag) {
825 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
829 $record->add_fields($field);
832 $indicators{@$rtags[$i]}.=' ';
833 if (@$rtags[$i] <10) {
834 $prevvalue= @$rvalues[$i];
836 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
838 $prevtag = @$rtags[$i];
840 if (@$rtags[$i] <10) {
841 $prevvalue=@$rvalues[$i];
844 $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
847 $prevtag= @$rtags[$i];
850 # the last has not been included inside the loop... do it now !
851 $record->add_fields($field);
852 # warn $record->as_formatted;
857 my ($dbh,$record) = @_;
858 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
860 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
863 # print STDERR $record->as_formatted;
864 while (($field)=$sth2->fetchrow) {
865 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
867 $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
869 while (($field)=$sth2->fetchrow) {
870 if ($field eq 'notes') { $field = 'bnotes'; }
871 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
873 $sth2=$dbh->prepare("SHOW COLUMNS from items");
875 while (($field)=$sth2->fetchrow) {
876 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
878 # additional authors : specific
879 $result = &MARCmarc2kohaOneField($sth,"bibliosubtitle","subtitle",$record,$result);
880 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
881 # modify copyrightdate to keep only the 1st year found
882 my $temp = $result->{'copyrightdate'};
883 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
885 $result->{'copyrightdate'} = $1;
886 } else { # if no cYYYY, get the 1st date.
887 $temp =~ m/(\d\d\d\d)/;
888 $result->{'copyrightdate'} = $1;
890 # modify publicationyear to keep only the 1st year found
891 my $temp = $result->{'publicationyear'};
892 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
894 $result->{'publicationyear'} = $1;
895 } else { # if no cYYYY, get the 1st date.
896 $temp =~ m/(\d\d\d\d)/;
897 $result->{'publicationyear'} = $1;
902 sub MARCmarc2kohaOneField {
903 # FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
904 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
905 # warn "kohatable / $kohafield / $result / ";
909 $sth->execute($kohatable.".".$kohafield);
910 ($tagfield,$subfield) = $sth->fetchrow;
911 foreach my $field ($record->field($tagfield)) {
912 if ($field->subfield($subfield)) {
913 if ($result->{$kohafield}) {
914 $result->{$kohafield} .= " | ".$field->subfield($subfield);
916 $result->{$kohafield}=$field->subfield($subfield);
924 # split a subfield string and adds it into the word table.
926 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
927 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\})/ /g;
928 my @words = split / /,$sentence;
929 my $stopwords= C4::Context->stopwords;
930 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
931 values (?,?,?,?,?,?,soundex(?))");
932 foreach my $word (@words) {
933 # we record only words longer than 2 car and not in stopwords hash
934 if (length($word)>2 and !($stopwords->{uc($word)})) {
935 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
937 warn "ERROR ==> insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word) values ($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,soundex($word))\n";
944 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
945 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
946 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
947 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
952 # NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW
955 # all the following subs are useful to manage MARC-DB with complete MARC records.
956 # it's used with marcimport, and marc management tools
960 =item ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
962 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
963 are builded from the MARC::Record. If they are passed, they are used.
965 =item NEWnewitem($dbh, $record,$bibid);
967 adds an item in the db.
972 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
973 # note $oldbiblio and $oldbiblioitem are not mandatory.
974 # if not present, they will be builded from $record with MARCmarc2koha function
975 if (($oldbiblio) and not($oldbiblioitem)) {
976 print STDERR "NEWnewbiblio : missing parameter\n";
977 print "NEWnewbiblio : missing parameter : contact koha development team\n";
983 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
984 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
985 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
987 my $olddata = MARCmarc2koha($dbh,$record);
988 $oldbibnum = OLDnewbiblio($dbh,$olddata);
989 $olddata->{'biblionumber'} = $oldbibnum;
990 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
992 # search subtiles, addiauthors and subjects
993 my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"additionalauthors.author");
994 my @addiauthfields = $record->field($tagfield);
995 foreach my $addiauthfield (@addiauthfields) {
996 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
997 foreach my $subfieldcount (0..$#addiauthsubfields) {
998 OLDmodaddauthor($dbh,$oldbibnum,$addiauthsubfields[$subfieldcount]);
1001 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubtitle.title");
1002 my @subtitlefields = $record->field($tagfield);
1003 foreach my $subtitlefield (@subtitlefields) {
1004 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1005 foreach my $subfieldcount (0..$#subtitlesubfields) {
1006 OLDnewsubtitle($dbh,$oldbibnum,$subtitlesubfields[$subfieldcount]);
1009 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject");
1010 my @subj = $record->field($tagfield);
1012 foreach my $subject (@subj) {
1013 my @subjsubfield = $subject->subfield($tagsubfield);
1014 foreach my $subfieldcount (0..$#subjsubfield) {
1015 push @subjects,$subjsubfield[$subfieldcount];
1018 OLDmodsubject($dbh,$oldbibnum,1,@subjects);
1019 # we must add bibnum and bibitemnum in MARC::Record...
1020 # we build the new field with biblionumber and biblioitemnumber
1021 # we drop the original field
1022 # we add the new builded field.
1023 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
1024 # (steve and paul : thinks 090 is a good choice)
1025 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
1026 $sth->execute("biblio.biblionumber");
1027 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
1028 $sth->execute("biblioitems.biblioitemnumber");
1029 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
1030 if ($tagfield1 != $tagfield2) {
1031 warn "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1032 print "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1035 my $newfield = MARC::Field->new( $tagfield1,'','',
1036 "$tagsubfield1" => $oldbibnum,
1037 "$tagsubfield2" => $oldbibitemnum);
1038 # drop old field and create new one...
1039 my $old_field = $record->field($tagfield1);
1040 $record->delete_field($old_field);
1041 $record->add_fields($newfield);
1042 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
1043 return ($bibid,$oldbibnum,$oldbibitemnum );
1047 my ($dbh,$record,$bibid) =@_;
1048 &MARCmodbiblio($dbh,$bibid,$record,0);
1049 my $oldbiblio = MARCmarc2koha($dbh,$record);
1050 my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
1051 OLDmodbibitem($dbh,$oldbiblio);
1052 # now, modify addi authors, subject, addititles.
1053 my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"additionalauthors.author");
1054 my @addiauthfields = $record->field($tagfield);
1055 foreach my $addiauthfield (@addiauthfields) {
1056 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1057 foreach my $subfieldcount (0..$#addiauthsubfields) {
1058 OLDmodaddauthor($dbh,$oldbiblionumber,$addiauthsubfields[$subfieldcount]);
1061 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubtitle.subtitle");
1062 my @subtitlefields = $record->field($tagfield);
1063 foreach my $subtitlefield (@subtitlefields) {
1064 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1065 foreach my $subfieldcount (0..$#subtitlesubfields) {
1066 OLDmodsubtitle($dbh,$oldbiblionumber,$subtitlesubfields[$subfieldcount]);
1069 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject");
1070 my @subj = $record->field($tagfield);
1072 foreach my $subject (@subj) {
1073 my @subjsubfield = $subject->subfield($tagsubfield);
1074 foreach my $subfieldcount (0..$#subjsubfield) {
1075 push @subjects,$subjsubfield[$subfieldcount];
1078 OLDmodsubject($dbh,$oldbiblionumber,1,@subjects);
1083 my ($dbh,$bibid)=@_;
1084 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
1085 &OLDdelbiblio($dbh,$biblio);
1086 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
1087 $sth->execute($biblio);
1088 while(my ($biblioitemnumber) = $sth->fetchrow) {
1089 OLDdeletebiblioitem($dbh,$biblioitemnumber);
1091 &MARCdelbiblio($dbh,$bibid,0);
1096 my ($dbh, $record,$bibid) = @_;
1097 # add item in old-DB
1098 my $item = &MARCmarc2koha($dbh,$record);
1099 # needs old biblionumber and biblioitemnumber
1100 $item->{'biblionumber'} = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
1101 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
1102 $sth->execute($item->{'biblionumber'});
1103 ($item->{'biblioitemnumber'}) = $sth->fetchrow;
1104 my ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{barcode});
1105 # add itemnumber to MARC::Record before adding the item.
1106 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
1107 &MARCkoha2marcOnefield($sth,$record,"items.itemnumber",$itemnumber);
1109 my $bib = &MARCadditem($dbh,$record,$item->{'biblionumber'});
1113 my ($dbh,$record,$bibid,$itemnumber,$delete) = @_;
1114 &MARCmoditem($dbh,$record,$bibid,$itemnumber,$delete);
1115 my $olditem = MARCmarc2koha($dbh,$record);
1116 OLDmoditem($dbh,$olditem);
1120 my ($dbh,$bibid,$itemnumber)=@_;
1121 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
1122 &OLDdelitem($dbh,$itemnumber);
1123 &MARCdelitem($dbh,$bibid,$itemnumber);
1128 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
1132 =item $biblionumber = OLDnewbiblio($dbh,$biblio);
1134 adds a record in biblio table. Datas are in the hash $biblio.
1136 =item $biblionumber = OLDmodbiblio($dbh,$biblio);
1138 modify a record in biblio table. Datas are in the hash $biblio.
1140 =item OLDmodsubtitle($dbh,$bibnum,$subtitle);
1142 modify subtitles in bibliosubtitle table.
1144 =item OLDmodaddauthor($dbh,$bibnum,$author);
1146 adds or modify additional authors
1147 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1149 =item $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1151 modify/adds subjects
1153 =item OLDmodbibitem($dbh, $biblioitem);
1157 =item OLDmodnote($dbh,$bibitemnum,$note
1159 modify a note for a biblioitem
1161 =item OLDnewbiblioitem($dbh,$biblioitem);
1163 adds a biblioitem ($biblioitem is a hash with the values)
1165 =item OLDnewsubject($dbh,$bibnum);
1169 =item OLDnewsubtitle($dbh,$bibnum,$subtitle);
1171 create a new subtitle
1173 =item ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1175 create a item. $item is a hash and $barcode the barcode.
1177 =item OLDmoditem($dbh,$item);
1181 =item OLDdelitem($dbh,$itemnum);
1185 =item OLDdeletebiblioitem($dbh,$biblioitemnumber);
1187 deletes a biblioitem
1188 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1190 =item OLDdelbiblio($dbh,$biblio);
1197 my ($dbh,$biblio) = @_;
1198 # my $dbh = &C4Connect;
1199 my $sth = $dbh->prepare("Select max(biblionumber) from biblio");
1201 my $data = $sth->fetchrow_arrayref;
1202 my $bibnum = $$data[0] + 1;
1205 if ($biblio->{'seriestitle'}) { $series = 1 };
1207 $sth = $dbh->prepare("insert into biblio set biblionumber = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?");
1208 $sth->execute($bibnum,$biblio->{'title'},$biblio->{'author'},$biblio->{'copyrightdate'},$series,$biblio->{'seriestitle'},$biblio->{'notes'},$biblio->{'abstract'});
1216 my ($dbh,$biblio) = @_;
1217 # my $dbh = C4Connect;
1222 $sth = $dbh->prepare("Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?, seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?");
1223 $sth->execute($biblio->{'title'},$biblio->{'author'},$biblio->{'abstract'},$biblio->{'copyrightdate'}, $biblio->{'seriestitle'},$biblio->{'serial'},$biblio->{'unititle'},$biblio->{'notes'},$biblio->{'biblionumber'});
1226 return($biblio->{'biblionumber'});
1229 sub OLDmodsubtitle {
1230 my ($dbh,$bibnum, $subtitle) = @_;
1231 my $sth = $dbh->prepare("update bibliosubtitle set subtitle = ? where biblionumber = ?");
1232 $sth->execute($subtitle,$bibnum);
1237 sub OLDmodaddauthor {
1238 my ($dbh,$bibnum, $author) = @_;
1239 # my $dbh = C4Connect;
1240 my $sth = $dbh->prepare("Delete from additionalauthors where biblionumber = ?");
1242 $sth->execute($bibnum);
1245 if ($author ne '') {
1246 $sth = $dbh->prepare("Insert into additionalauthors set author = ?, biblionumber = ?");
1248 $sth->execute($author,$bibnum);
1252 } # sub modaddauthor
1256 my ($dbh,$bibnum, $force, @subject) = @_;
1257 # my $dbh = C4Connect;
1258 my $count = @subject;
1260 for (my $i = 0; $i < $count; $i++) {
1261 $subject[$i] =~ s/^ //g;
1262 $subject[$i] =~ s/ $//g;
1263 my $sth = $dbh->prepare("select * from catalogueentry where entrytype = 's' and catalogueentry = ?");
1264 $sth->execute($subject[$i]);
1266 if (my $data = $sth->fetchrow_hashref) {
1268 if ($force eq $subject[$i] || $force == 1) {
1269 # subject not in aut, chosen to force anway
1270 # so insert into cataloguentry so its in auth file
1271 my $sth2 = $dbh->prepare("Insert into catalogueentry (entrytype,catalogueentry) values ('s',?)");
1273 $sth2->execute($subject[$i]);
1276 $error = "$subject[$i]\n does not exist in the subject authority file";
1277 my $sth2 = $dbh->prepare("Select * from catalogueentry where entrytype = 's' and (catalogueentry like ? or catalogueentry like ? or catalogueentry like ?)");
1278 $sth2->execute("$subject[$i] %","% $subject[$i] %","% $subject[$i]");
1279 while (my $data = $sth2->fetchrow_hashref) {
1280 $error .= "<br>$data->{'catalogueentry'}";
1288 my $sth = $dbh->prepare("Delete from bibliosubject where biblionumber = ?");
1289 $sth->execute($bibnum);
1291 $sth = $dbh->prepare("Insert into bibliosubject values (?,?)");
1293 foreach $query (@subject) {
1294 $sth->execute($query,$bibnum);
1304 my ($dbh,$biblioitem) = @_;
1305 # my $dbh = C4Connect;
1308 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1309 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1310 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1311 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1312 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1313 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1314 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1315 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1316 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1317 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1318 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1319 $biblioitem->{'bnotes'} = $dbh->quote($biblioitem->{'bnotes'});
1320 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1321 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1323 $query = "Update biblioitems set
1324 itemtype = $biblioitem->{'itemtype'},
1325 url = $biblioitem->{'url'},
1326 isbn = $biblioitem->{'isbn'},
1327 publishercode = $biblioitem->{'publishercode'},
1328 publicationyear = $biblioitem->{'publicationyear'},
1329 classification = $biblioitem->{'classification'},
1330 dewey = $biblioitem->{'dewey'},
1331 subclass = $biblioitem->{'subclass'},
1332 illus = $biblioitem->{'illus'},
1333 pages = $biblioitem->{'pages'},
1334 volumeddesc = $biblioitem->{'volumeddesc'},
1335 notes = $biblioitem->{'bnotes'},
1336 size = $biblioitem->{'size'},
1337 place = $biblioitem->{'place'}
1338 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1348 my ($dbh,$bibitemnum,$note)=@_;
1349 # my $dbh=C4Connect;
1350 my $query="update biblioitems set notes='$note' where
1351 biblioitemnumber='$bibitemnum'";
1352 my $sth=$dbh->prepare($query);
1358 sub OLDnewbiblioitem {
1359 my ($dbh,$biblioitem) = @_;
1360 # my $dbh = C4Connect;
1361 my $sth = $dbh->prepare("Select max(biblioitemnumber) from biblioitems");
1366 $data = $sth->fetchrow_arrayref;
1367 $bibitemnum = $$data[0] + 1;
1371 $sth = $dbh->prepare("insert into biblioitems set
1372 biblioitemnumber = ?, biblionumber = ?,
1373 volume = ?, number = ?,
1374 classification = ?, itemtype = ?,
1376 issn = ?, dewey = ?,
1377 subclass = ?, publicationyear = ?,
1378 publishercode = ?, volumedate = ?,
1379 volumeddesc = ?, illus = ?,
1380 pages = ?, notes = ?,
1382 marc = ?, place = ?");
1383 $sth->execute($bibitemnum, $biblioitem->{'biblionumber'},
1384 $biblioitem->{'volume'}, $biblioitem->{'number'},
1385 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
1386 $biblioitem->{'url'}, $biblioitem->{'isbn'},
1387 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
1388 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
1389 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
1390 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
1391 $biblioitem->{'pages'}, $biblioitem->{'bnotes'},
1392 $biblioitem->{'size'}, $biblioitem->{'lccn'},
1393 $biblioitem->{'marc'}, $biblioitem->{'place'});
1396 return($bibitemnum);
1400 my ($dbh,$bibnum)=@_;
1401 my $sth=$dbh->prepare("insert into bibliosubject (biblionumber) values (?)");
1402 $sth->execute($bibnum);
1406 sub OLDnewsubtitle {
1407 my ($dbh,$bibnum, $subtitle) = @_;
1408 my $sth = $dbh->prepare("insert into bibliosubtitle set biblionumber = ?, subtitle = ?");
1409 $sth->execute($bibnum,$subtitle);
1415 my ($dbh,$item, $barcode) = @_;
1416 # my $dbh = C4Connect;
1417 my $sth = $dbh->prepare("Select max(itemnumber) from items");
1423 $data = $sth->fetchrow_hashref;
1424 $itemnumber = $data->{'max(itemnumber)'} + 1;
1426 # FIXME the "notforloan" field seems to be named "loan" in some places. workaround bugfix.
1427 if ($item->{'loan'}) {
1428 $item->{'notforloan'} = $item->{'loan'};
1430 # if dateaccessioned is provided, use it. Otherwise, set to NOW()
1431 if ($item->{'dateaccessioned'}) {
1432 $sth=$dbh->prepare("Insert into items set
1433 itemnumber = ?, biblionumber = ?,
1434 biblioitemnumber = ?, barcode = ?,
1435 booksellerid = ?, dateaccessioned = ?,
1436 homebranch = ?, holdingbranch = ?,
1437 price = ?, replacementprice = ?,
1438 replacementpricedate = NOW(), itemnotes = ?,
1439 itemcallnumber =?, notforloan = ?
1441 $sth->execute($itemnumber, $item->{'biblionumber'},
1442 $item->{'biblioitemnumber'},$barcode,
1443 $item->{'booksellerid'},$item->{'dateaccessioned'},
1444 $item->{'homebranch'},$item->{'holdingbranch'},
1445 $item->{'price'},$item->{'replacementprice'},
1446 $item->{'itemnotes'},$item->{'itemcallnumber'},$item->{'notforloan'});
1448 $sth=$dbh->prepare("Insert into items set
1449 itemnumber = ?, biblionumber = ?,
1450 biblioitemnumber = ?, barcode = ?,
1451 booksellerid = ?, dateaccessioned = NOW(),
1452 homebranch = ?, holdingbranch = ?,
1453 price = ?, replacementprice = ?,
1454 replacementpricedate = NOW(), itemnotes = ?,
1455 itemcallnumber = ? , notforloan = ?
1457 $sth->execute($itemnumber, $item->{'biblionumber'},
1458 $item->{'biblioitemnumber'},$barcode,
1459 $item->{'booksellerid'},
1460 $item->{'homebranch'},$item->{'holdingbranch'},
1461 $item->{'price'},$item->{'replacementprice'},
1462 $item->{'itemnotes'},$item->{'itemcallnumber'},$item->{'notforloan'});
1464 if (defined $sth->errstr) {
1465 $error .= $sth->errstr;
1468 return($itemnumber,$error);
1472 my ($dbh,$item) = @_;
1473 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1474 # my $dbh=C4Connect;
1475 $item->{'itemnum'}=$item->{'itemnumber'} unless $item->{'itemnum'};
1476 my $query="update items set barcode=?,itemnotes=?,itemcallnumber=?,notforloan=? where itemnumber=?";
1477 my @bind = ($item->{'barcode'},$item->{'notes'},$item->{'itemcallnumber'},$item->{'notforloan'},$item->{'itemnum'});
1478 if ($item->{'barcode'} eq ''){
1479 $item->{'notforloan'}=0 unless $item->{'notforloan'};
1480 $query="update items set notforloan=? where itemnumber=?";
1481 @bind = ($item->{'notforloan'},$item->{'itemnum'});
1483 if ($item->{'lost'} ne ''){
1484 $query="update items set biblioitemnumber=?,
1492 where itemnumber=?";
1493 @bind = ($item->{'bibitemnum'},$item->{'barcode'},$item->{'notes'},$item->{'homebranch'},$item->{'lost'},$item->{'wthdrawn'},$item->{'itemcallnumber'},$item->{'notforloan'},$item->{'itemnum'});
1495 if ($item->{'replacement'} ne ''){
1496 $query=~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1498 my $sth=$dbh->prepare($query);
1499 $sth->execute(@bind);
1505 my ($dbh,$itemnum)=@_;
1506 # my $dbh=C4Connect;
1507 my $sth=$dbh->prepare("select * from items where itemnumber=?");
1508 $sth->execute($itemnum);
1509 my $data=$sth->fetchrow_hashref;
1511 my $query="Insert into deleteditems set ";
1513 foreach my $temp (keys %$data){
1514 $query .= "$temp = ?,";
1515 push(@bind,$data->{$temp});
1519 $sth=$dbh->prepare($query);
1520 $sth->execute(@bind);
1522 $sth=$dbh->prepare("Delete from items where itemnumber=?");
1523 $sth->execute($itemnum);
1528 sub OLDdeletebiblioitem {
1529 my ($dbh,$biblioitemnumber) = @_;
1530 # my $dbh = C4Connect;
1531 my $sth = $dbh->prepare("Select * from biblioitems
1532 where biblioitemnumber = ?");
1535 $sth->execute($biblioitemnumber);
1537 if ($results = $sth->fetchrow_hashref) {
1539 $sth=$dbh->prepare("Insert into deletedbiblioitems (biblioitemnumber, biblionumber, volume, number, classification, itemtype,
1540 isbn, issn ,dewey ,subclass ,publicationyear ,publishercode ,volumedate ,volumeddesc ,timestamp ,illus ,
1541 pages ,notes ,size ,url ,lccn ) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
1543 $sth->execute($results->{biblioitemnumber}, $results->{biblionumber}, $results->{volume}, $results->{number}, $results->{classification}, $results->{itemtype},
1544 $results->{isbn}, $results->{issn} ,$results->{dewey} ,$results->{subclass} ,$results->{publicationyear} ,$results->{publishercode} ,$results->{volumedate} ,$results->{volumeddesc} ,$results->{timestamp} ,$results->{illus} ,
1545 $results->{pages} ,$results->{notes} ,$results->{size} ,$results->{url} ,$results->{lccn} );
1546 my $sth2 = $dbh->prepare("Delete from biblioitems where biblioitemnumber = ?");
1547 $sth2->execute($biblioitemnumber);
1551 # Now delete all the items attached to the biblioitem
1552 $sth = $dbh->prepare("Select * from items where biblioitemnumber = ?");
1553 $sth->execute($biblioitemnumber);
1555 while (my $data = $sth->fetchrow_hashref) {
1556 my $query="Insert into deleteditems set ";
1558 foreach my $temp (keys %$data){
1559 $query .= "$temp = ?,";
1560 push(@bind,$data->{$temp});
1563 my $sth2=$dbh->prepare($query);
1564 $sth2->execute(@bind);
1567 $sth = $dbh->prepare("Delete from items where biblioitemnumber = ?");
1568 $sth->execute($biblioitemnumber);
1571 } # sub deletebiblioitem
1574 my ($dbh,$biblio)=@_;
1575 my $sth=$dbh->prepare("select * from biblio where biblionumber=?");
1576 $sth->execute($biblio);
1577 if (my $data=$sth->fetchrow_hashref){
1579 my $query="Insert into deletedbiblio set ";
1581 foreach my $temp (keys %$data){
1582 $query .= "$temp = ?,";
1583 push(@bind,$data->{$temp});
1585 #replacing the last , by ",?)"
1587 $sth=$dbh->prepare($query);
1588 $sth->execute(@bind);
1590 $sth=$dbh->prepare("Delete from biblio where biblionumber=?");
1591 $sth->execute($biblio);
1605 my $dbh = C4::Context->dbh;
1607 my $sth=$dbh->prepare("Select count(*) from items where biblionumber=?");
1608 $sth->execute($biblio);
1609 my $data=$sth->fetchrow_hashref;
1611 return($data->{'count(*)'});
1616 ($order, $ordernumber) = &getorder($biblioitemnumber, $biblionumber);
1618 Looks up the order with the given biblionumber and biblioitemnumber.
1620 Returns a two-element array. C<$ordernumber> is the order number.
1621 C<$order> is a reference-to-hash describing the order; its keys are
1622 fields from the biblio, biblioitems, aqorders, and aqorderbreakdown
1623 tables of the Koha database.
1627 # FIXME - This is effectively identical to &C4::Catalogue::getorder.
1628 # Pick one and stick with it.
1631 my $dbh = C4::Context->dbh;
1632 my $sth=$dbh->prepare("Select ordernumber
1634 where biblionumber=? and biblioitemnumber=?");
1635 $sth->execute($bib,$bi);
1636 # FIXME - Use fetchrow_array(), since we're only interested in the one
1638 my $ordnum=$sth->fetchrow_hashref;
1640 my $order=getsingleorder($ordnum->{'ordernumber'});
1641 return ($order,$ordnum->{'ordernumber'});
1644 =item getsingleorder
1646 $order = &getsingleorder($ordernumber);
1648 Looks up an order by order number.
1650 Returns a reference-to-hash describing the order. The keys of
1651 C<$order> are fields from the biblio, biblioitems, aqorders, and
1652 aqorderbreakdown tables of the Koha database.
1656 # FIXME - This is effectively identical to
1657 # &C4::Catalogue::getsingleorder.
1658 # Pick one and stick with it.
1659 sub getsingleorder {
1661 my $dbh = C4::Context->dbh;
1662 my $sth=$dbh->prepare("Select * from biblio,biblioitems,aqorders left join aqorderbreakdown
1663 on aqorders.ordernumber=aqorderbreakdown.ordernumber
1664 where aqorders.ordernumber=?
1665 and biblio.biblionumber=aqorders.biblionumber
1666 and biblioitems.biblioitemnumber=aqorders.biblioitemnumber");
1667 $sth->execute($ordnum);
1668 my $data=$sth->fetchrow_hashref;
1675 my $dbh = C4::Context->dbh;
1676 my $bibnum=OLDnewbiblio($dbh,$biblio);
1677 # finds new (MARC bibid
1678 # my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
1679 my $record = &MARCkoha2marcBiblio($dbh,$bibnum);
1680 MARCaddbiblio($dbh,$record,$bibnum);
1686 $biblionumber = &modbiblio($biblio);
1688 Update a biblio record.
1690 C<$biblio> is a reference-to-hash whose keys are the fields in the
1691 biblio table in the Koha database. All fields must be present, not
1692 just the ones you wish to change.
1694 C<&modbiblio> updates the record defined by
1695 C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
1697 C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
1704 my $dbh = C4::Context->dbh;
1705 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1706 my $record = MARCkoha2marcBiblio($dbh,$biblionumber,$biblionumber);
1707 # finds new (MARC bibid
1708 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
1709 MARCmodbiblio($dbh,$bibid,$record,0);
1710 return($biblionumber);
1715 &modsubtitle($biblionumber, $subtitle);
1717 Sets the subtitle of a book.
1719 C<$biblionumber> is the biblionumber of the book to modify.
1721 C<$subtitle> is the new subtitle.
1726 my ($bibnum, $subtitle) = @_;
1727 my $dbh = C4::Context->dbh;
1728 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1733 &modaddauthor($biblionumber, $author);
1735 Replaces all additional authors for the book with biblio number
1736 C<$biblionumber> with C<$author>. If C<$author> is the empty string,
1737 C<&modaddauthor> deletes all additional authors.
1742 my ($bibnum, $author) = @_;
1743 my $dbh = C4::Context->dbh;
1744 &OLDmodaddauthor($dbh,$bibnum,$author);
1745 } # sub modaddauthor
1749 $error = &modsubject($biblionumber, $force, @subjects);
1751 $force - a subject to force
1753 $error - Error message, or undef if successful.
1758 my ($bibnum, $force, @subject) = @_;
1759 my $dbh = C4::Context->dbh;
1760 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1765 my ($biblioitem) = @_;
1766 my $dbh = C4::Context->dbh;
1767 &OLDmodbibitem($dbh,$biblioitem);
1771 my ($bibitemnum,$note)=@_;
1772 my $dbh = C4::Context->dbh;
1773 &OLDmodnote($dbh,$bibitemnum,$note);
1777 my ($biblioitem) = @_;
1778 my $dbh = C4::Context->dbh;
1779 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1780 my $MARCbiblio= MARCkoha2marcBiblio($dbh,0,$bibitemnum); # the 0 means "do NOT retrieve biblio, only biblioitem, in the MARC record
1781 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblioitem->{biblionumber});
1782 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber},$bibid);
1783 return($bibitemnum);
1788 my $dbh = C4::Context->dbh;
1789 &OLDnewsubject($dbh,$bibnum);
1793 my ($bibnum, $subtitle) = @_;
1794 my $dbh = C4::Context->dbh;
1795 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1799 my ($item, @barcodes) = @_;
1800 my $dbh = C4::Context->dbh;
1804 foreach my $barcode (@barcodes) {
1805 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1807 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1808 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1815 my $dbh = C4::Context->dbh;
1816 &OLDmoditem($dbh,$item);
1817 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1818 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1819 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1823 my ($count,@barcodes)=@_;
1824 my $dbh = C4::Context->dbh;
1826 my $sth=$dbh->prepare("Select * from items where barcode=?");
1827 for (my $i=0;$i<$count;$i++){
1828 $barcodes[$i]=uc $barcodes[$i];
1829 $sth->execute($barcodes[$i]);
1830 if (my $data=$sth->fetchrow_hashref){
1831 $error.=" Duplicate Barcode: $barcodes[$i]";
1839 my ($bibitemnum)=@_;
1840 my $dbh = C4::Context->dbh;
1842 my $sth=$dbh->prepare("Select count(*) from items where biblioitemnumber=?");
1843 $sth->execute($bibitemnum);
1844 my $data=$sth->fetchrow_hashref;
1846 return($data->{'count(*)'});
1851 my $dbh = C4::Context->dbh;
1852 &OLDdelitem($dbh,$itemnum);
1855 sub deletebiblioitem {
1856 my ($biblioitemnumber) = @_;
1857 my $dbh = C4::Context->dbh;
1858 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1859 } # sub deletebiblioitem
1864 my $dbh = C4::Context->dbh;
1865 &OLDdelbiblio($dbh,$biblio);
1866 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblio);
1867 &MARCdelbiblio($dbh,$bibid,0);
1871 my $dbh = C4::Context->dbh;
1872 my $sth = $dbh->prepare("select * from itemtypes order by description");
1877 while (my $data = $sth->fetchrow_hashref) {
1878 $results[$count] = $data;
1883 return($count, @results);
1884 } # sub getitemtypes
1887 my ($biblionumber) = @_;
1888 my $dbh = C4::Context->dbh;
1889 my $sth = $dbh->prepare("Select * from biblio where biblionumber = ?");
1890 # || die "Cannot prepare $query\n" . $dbh->errstr;
1894 $sth->execute($biblionumber);
1895 # || die "Cannot execute $query\n" . $sth->errstr;
1896 while (my $data = $sth->fetchrow_hashref) {
1897 $results[$count] = $data;
1902 return($count, @results);
1906 my ($biblioitemnum) = @_;
1907 my $dbh = C4::Context->dbh;
1908 my $sth = $dbh->prepare("Select * from biblioitems where
1909 biblioitemnumber = ?");
1913 $sth->execute($biblioitemnum);
1915 while (my $data = $sth->fetchrow_hashref) {
1916 $results[$count] = $data;
1921 return($count, @results);
1922 } # sub getbiblioitem
1924 sub getbiblioitembybiblionumber {
1925 my ($biblionumber) = @_;
1926 my $dbh = C4::Context->dbh;
1927 my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?");
1931 $sth->execute($biblionumber);
1933 while (my $data = $sth->fetchrow_hashref) {
1934 $results[$count] = $data;
1939 return($count, @results);
1942 sub getitemsbybiblioitem {
1943 my ($biblioitemnum) = @_;
1944 my $dbh = C4::Context->dbh;
1945 my $sth = $dbh->prepare("Select * from items, biblio where
1946 biblio.biblionumber = items.biblionumber and biblioitemnumber
1948 # || die "Cannot prepare $query\n" . $dbh->errstr;
1952 $sth->execute($biblioitemnum);
1953 # || die "Cannot execute $query\n" . $sth->errstr;
1954 while (my $data = $sth->fetchrow_hashref) {
1955 $results[$count] = $data;
1960 return($count, @results);
1961 } # sub getitemsbybiblioitem
1965 # Subroutine to log changes to databases
1966 # Eventually, this subroutine will be used to create a log of all changes made,
1967 # with the possibility of "undo"ing some changes
1969 if ($database eq 'kohadb') {
1975 # print STDERR "KOHA: $type $section $item $original $new\n";
1976 } elsif ($database eq 'marc') {
1978 my $Record_ID=shift;
1981 my $subfield_ID=shift;
1984 # print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
1988 #------------------------------------------------
1991 #---------------------------------------
1992 # Find a biblio entry, or create a new one if it doesn't exist.
1993 # If a "subtitle" entry is in hash, add it to subtitle table
1994 sub getoraddbiblio {
1998 # FIXME - Unused argument
1999 $biblio, # hash ref to fields
2010 $dbh = C4::Context->dbh;
2012 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2013 $sth=$dbh->prepare("select biblionumber
2015 where title=? and author=?
2016 and copyrightdate=? and seriestitle=?");
2018 $biblio->{title}, $biblio->{author},
2019 $biblio->{copyright}, $biblio->{seriestitle} );
2021 ($biblionumber) = $sth->fetchrow;
2022 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2024 # Doesn't exist. Add new one.
2025 print "<PRE>Adding biblio</PRE>\n" if $debug;
2026 ($biblionumber,$error)=&newbiblio($biblio);
2027 if ( $biblionumber ) {
2028 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
2029 if ( $biblio->{subtitle} ) {
2030 &newsubtitle($biblionumber,$biblio->{subtitle} );
2033 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2037 return $biblionumber,$error;
2039 } # sub getoraddbiblio
2042 # converts ISO 5426 coded string to ISO 8859-1
2043 # sloppy code : should be improved in next issue
2044 my ($string,$encoding) = @_ ;
2046 # $encoding = C4::Context->preference("marcflavour") unless $encoding;
2047 if ($encoding eq "UNIMARC") {
2109 # this handles non-sorting blocks (if implementation requires this)
2110 $string = nsb_clean($_) ;
2111 } elsif ($encoding eq "USMARC" || $encoding eq "MARC21") {
2164 # this handles non-sorting blocks (if implementation requires this)
2165 $string = nsb_clean($_) ;
2172 my $NSB = '\x88' ; # NSB : begin Non Sorting Block
2173 my $NSE = '\x89' ; # NSE : Non Sorting Block end
2174 # handles non sorting blocks
2178 s/[ ]{0,1}$NSE/) /gm ;
2183 END { } # module clean-up code here (global destructor)
2189 Koha Developement team <info@koha.org>
2191 Paul POULAIN paul.poulain@free.fr
2197 # Revision 1.85 2004/04/02 14:55:48 tipaul
2198 # renaming items.bulk field to items.itemcallnumber.
2199 # Will be used to store call number for libraries that don't use dewey classification.
2200 # Note it's related to ITEMS, not biblio.
2202 # Revision 1.84 2004/03/24 17:18:30 joshferraro
2203 # Fixes bug 749 by removing the comma on line 1488.
2205 # Revision 1.83 2004/03/15 14:31:50 tipaul
2206 # adding a minor check
2208 # Revision 1.82 2004/03/07 05:47:31 acli
2209 # Various updates/fixes from rel_2_0
2210 # Fixes for bugs 721 (templating), 727, and 734
2212 # Revision 1.81 2004/03/06 20:26:13 tipaul
2213 # adding seealso feature in MARC searches
2215 # Revision 1.80 2004/02/12 13:40:56 tipaul
2216 # deleting subs duplicated by error
2218 # Revision 1.79 2004/02/11 08:40:09 tipaul
2219 # synch'ing 2.0.0 branch and head
2221 # Revision 1.78.2.3 2004/02/10 13:15:46 tipaul
2222 # removing 2 warnings
2224 # Revision 1.78.2.2 2004/01/26 10:38:06 tipaul
2225 # dealing correctly "bulk" field
2227 # Revision 1.78.2.1 2004/01/13 17:29:53 tipaul
2228 # * minor html fixes
2229 # * adding publisher in acquisition process (& ordering basket by publisher)
2231 # Revision 1.78 2003/12/09 15:57:28 tipaul
2232 # rolling back to working char_decode sub
2234 # Revision 1.77 2003/12/03 17:47:14 tipaul
2235 # bugfixes for biblio deletion
2237 # Revision 1.76 2003/12/03 01:43:41 slef
2240 # Revision 1.75 2003/12/03 01:42:03 slef
2241 # bug 662 fixes securing DBI
2243 # Revision 1.74 2003/11/28 09:48:33 tipaul
2244 # bugfix : misusing prepare & execute => now using prepare(?) and execute($var)
2246 # Revision 1.73 2003/11/28 09:45:25 tipaul
2247 # bugfix for iso2709 file import in the "notforloan" field.
2249 # But notforloan field called "loan" somewhere, so in case "loan" is used, copied to "notforloan" to avoid a bug.
2251 # Revision 1.72 2003/11/24 17:40:14 tipaul
2254 # Revision 1.71 2003/11/24 16:28:49 tipaul
2255 # biblio & item deletion now works fine in MARC editor.
2256 # Stores deleted biblio/item in the marc field of the deletedbiblio/deleteditem table.
2258 # Revision 1.70 2003/11/24 13:29:55 tipaul
2259 # moving $id from beginning to end of file (70 commits... huge comments...)
2261 # Revision 1.69 2003/11/24 13:27:17 tipaul
2262 # fix for #380 (bibliosubject)
2264 # Revision 1.68 2003/11/06 17:18:30 tipaul
2267 # 1st draft for MARC biblio deletion.
2268 # Still does not work well, but at least, Biblio.pm compiles & it should'nt break too many things
2269 # (Note the trash in the MARCdetail, but don't use it, please :-) )
2271 # Revision 1.67 2003/10/25 08:46:27 tipaul
2272 # minor fixes for bilbio deletion (still buggy)
2274 # Revision 1.66 2003/10/17 10:02:56 tipaul
2275 # Indexing only words longer than 2 letters. Was >=2 before, & 2 letters words usually means nothing.
2277 # Revision 1.65 2003/10/14 09:45:29 tipaul
2278 # 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)
2280 # Revision 1.64 2003/10/06 15:20:51 tipaul
2281 # fix for 536 (subtitle error)
2283 # Revision 1.63 2003/10/01 13:25:49 tipaul
2284 # seems a char encoding problem modified something in char_decode sub... changing back to something that works...
2286 # Revision 1.62 2003/09/17 14:21:13 tipaul
2287 # fixing bug that makes a MARC biblio disappear when using full acquisition (order => recieve ==> MARC editor).
2288 # Before this 2 lines fix, the MARC biblio was deleted during recieve, and had to be entirely recreated :-(
2290 # Revision 1.61 2003/09/17 10:24:39 tipaul
2291 # notforloan value in itemtype was overwritting notforloan value in a given item.
2292 # I changed this behaviour :
2293 # if notforloan is set for a given item, and NOT for all items from this itemtype, the notforloan is kept.
2294 # If notforloan is set for itemtype, it's used (and impossible to loan a specific item from this itemtype)
2296 # Revision 1.60 2003/09/04 14:11:23 tipaul
2297 # fix for 593 (data duplication in MARC-DB)
2299 # Revision 1.58 2003/08/06 12:54:52 tipaul
2300 # fix for publicationyear : extracting numeric value from MARC string, like for copyrightdate.
2301 # (note that copyrightdate still extracted to get numeric format)
2303 # Revision 1.57 2003/07/15 23:09:18 slef
2304 # change show columns to use biblioitems bnotes too
2306 # Revision 1.56 2003/07/15 11:34:52 slef
2307 # fixes from paul email
2309 # Revision 1.55 2003/07/15 00:02:49 slef
2310 # Work on bug 515... can we do a single-side rename of notes to bnotes?
2312 # Revision 1.54 2003/07/11 11:51:32 tipaul
2313 # *** empty log message ***
2315 # Revision 1.52 2003/07/10 10:37:19 tipaul
2316 # fix for copyrightdate problem, #514
2318 # Revision 1.51 2003/07/02 14:47:17 tipaul
2319 # fix for #519 : items.dateaccessioned imports incorrectly
2321 # Revision 1.49 2003/06/17 11:21:13 tipaul
2322 # improvments/fixes for z3950 support.
2323 # * Works now even on ADD, not only on MODIFY
2324 # * able to search on ISBN, author, title
2326 # Revision 1.48 2003/06/16 09:22:53 rangi
2327 # Just added an order clause to getitemtypes
2329 # Revision 1.47 2003/05/20 16:22:44 tipaul
2330 # fixing typo in Biblio.pm POD
2332 # Revision 1.46 2003/05/19 13:45:18 tipaul
2333 # support for subtitles, additional authors, subject.
2334 # 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.
2335 # Note that some OLD-DB subs are strange (dummy ?) see OLDmodsubject, OLDmodsubtitle, OLDmodaddiauthor in C4/Biblio.pm
2336 # 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.
2338 # Revision 1.45 2003/04/29 16:50:49 tipaul
2339 # really proud of this commit :-)
2340 # z3950 search and import seems to works fine.
2341 # Let me explain how :
2342 # * a "search z3950" button is added in the addbiblio template.
2343 # * when clicked, a popup appears and z3950/search.pl is called
2344 # * z3950/search.pl calls addz3950search in the DB
2345 # * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table.
2346 # * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending.
2347 # * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled
2350 # * 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.
2351 # * 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.
2353 # Revision 1.44 2003/04/28 13:07:14 tipaul
2354 # Those fixes solves the "internal server error" with MARC::Record 1.12.
2355 # It was due to an illegal contruction in Koha : we tried to retrive subfields from <10 tags.
2356 # That's not possible. MARC::Record accepted this in 0.93 version, but it was fixed after.
2357 # Now, the construct/retrieving is OK !
2359 # Revision 1.43 2003/04/10 13:56:02 tipaul
2361 # * worked in 1.9.0, but not in 1.9.1 :
2362 # - modif of a biblio didn't work
2363 # - 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.
2365 # * did not work before :
2366 # - repeatable subfields now works correctly. Enter 2 subfields separated by | and they will be splitted during saving.
2367 # - dropped the last subfield of the MARC form :-(
2369 # Internal changes :
2370 # - 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.
2371 # Note the MARCdelbiblio has been rewritted to enable deletion of a biblio WITHOUT deleting items.
2373 # Revision 1.42 2003/04/04 08:41:11 tipaul
2374 # last commits before 1.9.1
2376 # Revision 1.41 2003/04/01 12:26:43 tipaul
2379 # Revision 1.40 2003/03/11 15:14:03 tipaul
2382 # Revision 1.39 2003/03/07 16:35:42 tipaul
2383 # * moving generic functions to Koha.pm
2384 # * improvement of SearchMarc.pm
2388 # Revision 1.38 2003/02/27 16:51:59 tipaul
2389 # * moving prepare / execute to ? form.
2392 # * road to 1.9.2 => acquisition and cataloguing merging
2394 # Revision 1.37 2003/02/12 11:03:03 tipaul
2395 # Support for 000 -> 010 fields.
2396 # Those fields doesn't have subfields.
2397 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
2398 # 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.
2400 # Revision 1.36 2003/02/12 11:01:01 tipaul
2401 # Support for 000 -> 010 fields.
2402 # Those fields doesn't have subfields.
2403 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
2404 # 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.
2406 # Revision 1.35 2003/02/03 18:46:00 acli
2407 # Minor factoring in C4/Biblio.pm, plus change to export the per-tag
2408 # 'mandatory' property to a per-subfield 'tag_mandatory' template parameter,
2409 # so that addbiblio.tmpl can distinguish between mandatory subfields in a
2410 # mandatory tag and mandatory subfields in an optional tag
2412 # Not-minor factoring in acqui.simple/addbiblio.pl to make the if-else blocks
2413 # smaller, and to add some POD; need further testing for this
2415 # Added function to check if a MARC subfield name is "koha-internal" (instead
2416 # of checking it for 'lib' and 'tag' everywhere); temporarily added to Koha.pm
2418 # Use above function in acqui.simple/additem.pl and search.marc/search.pl
2420 # Revision 1.34 2003/01/28 14:50:04 tipaul
2421 # fixing MARCmodbiblio API and reindenting code
2423 # Revision 1.33 2003/01/23 12:22:37 tipaul
2424 # adding char_decode to decode MARC21 or UNIMARC extended chars
2426 # Revision 1.32 2002/12/16 15:08:50 tipaul
2427 # small but important bugfix (fixes a problem in export)
2429 # Revision 1.31 2002/12/13 16:22:04 tipaul
2430 # 1st draft of marc export
2432 # Revision 1.30 2002/12/12 21:26:35 tipaul
2433 # YAB ! (Yet Another Bugfix) => related to biblio modif
2434 # (some warning cleaning too)
2436 # Revision 1.29 2002/12/12 16:35:00 tipaul
2437 # adding authentification with Auth.pm and
2438 # MAJOR BUGFIX on marc biblio modification
2440 # Revision 1.28 2002/12/10 13:30:03 tipaul
2441 # fugfixes from Dombes Abbey work
2443 # Revision 1.27 2002/11/19 12:36:16 tipaul
2445 # various bugfixes, improvments, and migration from acquisition.pm to biblio.pm
2447 # Revision 1.26 2002/11/12 15:58:43 tipaul
2450 # * 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)
2452 # Revision 1.25 2002/10/25 10:58:26 tipaul
2454 # * bugfixes and improvements
2456 # Revision 1.24 2002/10/24 12:09:01 arensb
2457 # Fixed "no title" warning when generating HTML documentation from POD.
2459 # Revision 1.23 2002/10/16 12:43:08 arensb
2460 # Added some FIXME comments.
2462 # Revision 1.22 2002/10/15 13:39:17 tipaul
2463 # removing Acquisition.pm
2464 # deleting unused code in biblio.pm, rewriting POD and answering most FIXME comments
2466 # Revision 1.21 2002/10/13 11:34:14 arensb
2467 # Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
2468 # Thus, $x = $x+2 becomes $x += 2, and so forth.
2470 # Revision 1.20 2002/10/13 08:28:32 arensb
2471 # Deleted unused variables.
2472 # Removed trailing whitespace.
2474 # Revision 1.19 2002/10/13 05:56:10 arensb
2475 # Added some FIXME comments.
2477 # Revision 1.18 2002/10/11 12:34:53 arensb
2478 # Replaced &requireDBI with C4::Context->dbh
2480 # Revision 1.17 2002/10/10 14:48:25 tipaul
2483 # Revision 1.16 2002/10/07 14:04:26 tipaul
2484 # road to 1.3.1 : viewing MARC biblio
2486 # Revision 1.15 2002/10/05 09:49:25 arensb
2487 # Merged with arensb-context branch: use C4::Context->dbh instead of
2488 # &C4Connect, and generally prefer C4::Context over C4::Database.
2490 # Revision 1.14 2002/10/03 11:28:18 tipaul
2491 # Extending Context.pm to add stopword management and using it in MARC-API.
2492 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
2494 # Revision 1.13 2002/10/02 16:26:44 tipaul
2497 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
2498 # Merged in changes from main branch.
2500 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
2501 # Added a whole mess of FIXME comments.
2503 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
2504 # Added some missing semicolons.
2506 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
2507 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
2510 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
2511 # Added a whole mess of FIXME comments.
2513 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
2514 # Added some missing semicolons.
2516 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
2517 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
2520 # Revision 1.12 2002/10/01 11:48:51 arensb
2521 # Added some FIXME comments, mostly marking duplicate functions.
2523 # Revision 1.11 2002/09/24 13:49:26 tipaul
2524 # long WAS the road to 1.3.0...
2525 # coming VERY SOON NOW...
2526 # modifying installer and buildrelease to update the DB
2528 # Revision 1.10 2002/09/22 16:50:08 arensb
2529 # Added some FIXME comments.
2531 # Revision 1.9 2002/09/20 12:57:46 tipaul
2532 # long is the road to 1.4.0
2533 # * MARCadditem and MARCmoditem now wroks
2534 # * various bugfixes in MARC management
2535 # !!! 1.3.0 should be released very soon now. Be careful !!!
2537 # Revision 1.8 2002/09/10 13:53:52 tipaul
2538 # MARC API continued...
2540 # * 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)
2542 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
2544 # Revision 1.7 2002/08/14 18:12:51 tonnesen
2545 # Added copyright statement to all .pl and .pm files
2547 # Revision 1.6 2002/07/25 13:40:31 tipaul
2548 # pod documenting the API.
2550 # Revision 1.5 2002/07/24 16:11:37 tipaul
2552 # Database.pm and Output.pm are almost not modified (var test...)
2554 # Biblio.pm is almost completly rewritten.
2556 # WHAT DOES IT ??? ==> END of Hitchcock suspens
2558 # 1st, it does... nothing...
2559 # 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 ...
2561 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
2562 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
2563 # * 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.
2564 # * 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.
2565 # 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 ;-)
2567 # 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.
2568 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.