3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
26 use vars qw($VERSION @ISA @EXPORT);
28 # set the version for version checking
34 # don't forget MARCxxx subs are exported only for testing purposes. Should not be used
35 # as the old-style API and the NEW one are the only public functions.
38 &updateBiblio &updateBiblioItem &updateItem
39 &itemcount &newbiblio &newbiblioitem
40 &modnote &newsubject &newsubtitle
41 &modbiblio &checkitems
43 &modsubtitle &modsubject &modaddauthor &moditem &countitems
44 &delitem &deletebiblioitem &delbiblio
46 &getbiblioitembybiblionumber
47 &getbiblioitem &getitemsbybiblioitem
49 &newcompletebiblioitem
51 &MARCfind_oldbiblionumber_from_MARCbibid
52 &MARCfind_MARCbibid_from_oldbiblionumber
53 &MARCfind_marc_from_kohafield
55 &MARCfind_frameworkcode
58 &NEWnewbiblio &NEWnewitem
59 &NEWmodbiblio &NEWmoditem
60 &NEWdelbiblio &NEWdelitem
62 &MARCaddbiblio &MARCadditem
63 &MARCmodsubfield &MARCaddsubfield
64 &MARCmodbiblio &MARCmoditem
65 &MARCkoha2marcBiblio &MARCmarc2koha
66 &MARCkoha2marcItem &MARChtml2marc
67 &MARCgetbiblio &MARCgetitem
68 &MARCaddword &MARCdelword
76 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
79 # all the following subs takes a MARC::Record as parameter and manage
80 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
81 # NEWxxx subs (xxx deals with old-DB parameters, the NEWxxx deals with MARC-DB parameter)
85 C4::Biblio - acquisition, catalog management functions
89 move from 1.2 to 1.4 version :
90 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
91 In the 1.4 version, we want to do 2 differents things :
92 - keep populating the old-DB, that has a LOT less datas than MARC
93 - populate the MARC-DB
94 To populate the DBs we have 2 differents sources :
95 - the standard acquisition system (through book sellers), that does'nt use MARC data
96 - the MARC acquisition system, that uses MARC data.
98 Thus, we have 2 differents cases :
99 - with the standard acquisition system, we have non MARC data and want to populate old-DB and MARC-DB, knowing it's an incomplete MARC-record
100 - with the MARC acquisition system, we have MARC datas, and want to loose nothing in MARC-DB. So, we can't store datas in old-DB, then copy in MARC-DB. we MUST have an API for true MARC data, that populate MARC-DB then old-DB
102 That's why we need 4 subs :
103 all I<subs beginning by MARC> manage only MARC tables. They manage MARC-DB with MARC::Record parameters
104 all I<subs beginning by OLD> manage only OLD-DB tables. They manage old-DB with old-DB parameters
105 all I<subs beginning by NEW> manage both OLD-DB and MARC tables. They use MARC::Record as parameters. it's the API that MUST be used in MARC acquisition system
106 all I<subs beginning by seomething else> are the old-style API. They use old-DB as parameter, then call internally the OLD and MARC subs.
108 - NEW and old-style API should be used in koha to manage biblio
109 - MARCsubs are divided in 2 parts :
110 * some of them manage MARC parameters. They are heavily used in koha.
111 * some of them manage MARC biblio : they are mostly used by NEW and old-style subs.
112 - OLD are used internally only
114 all subs requires/use $dbh as 1st parameter.
116 I<NEWxxx related subs>
118 all subs requires/use $dbh as 1st parameter.
119 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
121 I<OLDxxx related subs>
123 all subs requires/use $dbh as 1st parameter.
124 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
126 They all are the exact copy of 1.0/1.2 version of the sub without the OLD.
127 The OLDxxx is called by the original xxx sub.
128 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
130 WARNING : there is 1 difference between initialxxx and OLDxxx :
131 the db header $dbh is always passed as parameter to avoid over-DB connexion
137 =item @tagslib = &MARCgettagslib($dbh,1|0,$itemtype);
139 last param is 1 for liblibrarian and 0 for libopac
140 $itemtype contains the itemtype framework reference. If empty or does not exist, the default one is used
141 returns a hash with tag/subfield meaning
142 =item ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,$kohafield);
144 finds MARC tag and subfield for a given kohafield
145 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
147 =item $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
149 finds a old-db biblio number for a given MARCbibid number
151 =item $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
153 finds a MARC bibid from a old-db biblionumber
155 =item $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
157 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
159 =item $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
161 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
163 =item $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
165 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
167 =item $olddb = &MARCmarc2koha($dbh,$MARCRecord);
169 builds a hash with old-db datas from a MARC::Record
171 =item &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
173 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
175 =item &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
177 adds a subfield in a biblio (in the MARC tables only).
179 =item $MARCRecord = &MARCgetbiblio($dbh,$bibid);
181 Returns a MARC::Record for the biblio $bibid.
183 =item &MARCmodbiblio($dbh,$bibid,$record,$frameworkcode,$delete);
185 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
186 It 1st delete the biblio, then recreates it.
187 WARNING : the $delete parameter is not used anymore (too much unsolvable cases).
188 =item ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
190 MARCmodsubfield changes the value of a given subfield
192 =item $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
194 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
195 Returns -1 if more than 1 answer
197 =item $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
199 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
201 =item &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
203 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
205 =item &MARCdelbiblio($dbh,$bibid);
207 MARCdelbiblio delete biblio $bibid
209 =item &MARCkoha2marcOnefield
211 used by MARCkoha2marc and should not be useful elsewhere
213 =item &MARCmarc2kohaOnefield
215 used by MARCmarc2koha and should not be useful elsewhere
219 used to manage MARC_word table and should not be useful elsewhere
223 used to manage MARC_word table and should not be useful elsewhere
228 my ( $dbh, $forlibrarian, $frameworkcode ) = @_;
229 $frameworkcode = "" unless $frameworkcode;
231 my $libfield = ( $forlibrarian eq 1 ) ? 'liblibrarian' : 'libopac';
233 # check that framework exists
236 "select count(*) from marc_tag_structure where frameworkcode=?");
237 $sth->execute($frameworkcode);
238 my ($total) = $sth->fetchrow;
239 $frameworkcode = "" unless ( $total > 0 );
242 "select tagfield,$libfield as lib,mandatory,repeatable from marc_tag_structure where frameworkcode=? order by tagfield"
244 $sth->execute($frameworkcode);
245 my ( $lib, $tag, $res, $tab, $mandatory, $repeatable );
247 while ( ( $tag, $lib, $mandatory, $repeatable ) = $sth->fetchrow ) {
248 $res->{$tag}->{lib} = $lib;
249 $res->{$tab}->{tab} = ""; # XXX
250 $res->{$tag}->{mandatory} = $mandatory;
251 $res->{$tag}->{repeatable} = $repeatable;
256 "select tagfield,tagsubfield,$libfield as lib,tab, mandatory, repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl from marc_subfield_structure where frameworkcode=? order by tagfield,tagsubfield"
258 $sth->execute($frameworkcode);
261 my $authorised_value;
270 ( $tag, $subfield, $lib, $tab,
271 $mandatory, $repeatable, $authorised_value, $authtypecode,
272 $value_builder, $kohafield, $seealso, $hidden,
277 $res->{$tag}->{$subfield}->{lib} = $lib;
278 $res->{$tag}->{$subfield}->{tab} = $tab;
279 $res->{$tag}->{$subfield}->{mandatory} = $mandatory;
280 $res->{$tag}->{$subfield}->{repeatable} = $repeatable;
281 $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
282 $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode;
283 $res->{$tag}->{$subfield}->{value_builder} = $value_builder;
284 $res->{$tag}->{$subfield}->{kohafield} = $kohafield;
285 $res->{$tag}->{$subfield}->{seealso} = $seealso;
286 $res->{$tag}->{$subfield}->{hidden} = $hidden;
287 $res->{$tag}->{$subfield}->{isurl} = $isurl;
292 sub MARCfind_marc_from_kohafield {
293 my ( $dbh, $kohafield,$frameworkcode ) = @_;
294 return 0, 0 unless $kohafield;
295 my $relations = C4::Context->marcfromkohafield;
296 return ($relations->{$frameworkcode}->{$kohafield}->[0],$relations->{$frameworkcode}->{$kohafield}->[1]);
299 # "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
301 # $sth->execute($frameworkcode,$kohafield);
302 # my ( $tagfield, $tagsubfield ) = $sth->fetchrow;
303 # return ( $tagfield, $tagsubfield );
306 sub MARCfind_oldbiblionumber_from_MARCbibid {
307 my ( $dbh, $MARCbibid ) = @_;
309 $dbh->prepare("select biblionumber from marc_biblio where bibid=?");
310 $sth->execute($MARCbibid);
311 my ($biblionumber) = $sth->fetchrow;
312 return $biblionumber;
315 sub MARCfind_MARCbibid_from_oldbiblionumber {
316 my ( $dbh, $oldbiblionumber ) = @_;
318 $dbh->prepare("select bibid from marc_biblio where biblionumber=?");
319 $sth->execute($oldbiblionumber);
320 my ($bibid) = $sth->fetchrow;
326 # pass the MARC::Record to this function, and it will create the records in the marc tables
327 my ($dbh,$record,$biblionumber,$frameworkcode,$bibid) = @_;
328 my @fields=$record->fields();
330 # adding main table, and retrieving bibid
331 # if bibid is sent, then it's not a true add, it's only a re-add, after a delete (ie, a mod)
332 # if bibid empty => true add, find a new bibid number
335 "lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ"
339 "insert into marc_biblio (datecreated,biblionumber,frameworkcode) values (now(),?,?)"
341 $sth->execute( $biblionumber, $frameworkcode );
342 $sth = $dbh->prepare("select max(bibid) from marc_biblio");
344 ($bibid) = $sth->fetchrow;
349 # now, add subfields...
350 foreach my $field (@fields) {
352 if ( $field->tag() < 10 ) {
353 &MARCaddsubfield( $dbh, $bibid, $field->tag(), '', $fieldcount, '',
357 my @subfields = $field->subfields();
358 foreach my $subfieldcount ( 0 .. $#subfields ) {
363 $field->indicator(1) . $field->indicator(2),
365 $subfields[$subfieldcount][0],
367 $subfields[$subfieldcount][1]
372 $dbh->do("unlock tables");
378 # pass the MARC::Record to this function, and it will create the records in the marc tables
379 my ($dbh,$record,$biblionumber) = @_;
380 # search for MARC biblionumber
381 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
382 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
383 my @fields=$record->fields();
384 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
385 $sth->execute($bibid);
386 my ($fieldcount) = $sth->fetchrow;
388 # now, add subfields...
389 foreach my $field (@fields) {
390 my @subfields = $field->subfields();
392 foreach my $subfieldcount ( 0 .. $#subfields ) {
397 $field->indicator(1) . $field->indicator(2),
399 $subfields[$subfieldcount][0],
401 $subfields[$subfieldcount][1]
405 $dbh->do("unlock tables");
409 sub MARCaddsubfield {
411 # Add a new subfield to a tag into the DB.
413 $dbh, $bibid, $tagid, $tag_indicator,
414 $tagorder, $subfieldcode, $subfieldorder, $subfieldvalues
417 # warn "$tagid / $subfieldcode / $subfieldvalues";
418 # if not value, end of job, we do nothing
419 # if ( length($subfieldvalues) == 0 ) {
422 if ( not($subfieldcode) ) {
425 my @subfieldvalues = split /\||#/, $subfieldvalues;
426 foreach my $subfieldvalue (@subfieldvalues) {
427 if ( length($subfieldvalue) > 255 ) {
429 "lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE"
433 "insert into marc_blob_subfield (subfieldvalue) values (?)");
434 $sth->execute($subfieldvalue);
436 $dbh->prepare("select max(blobidlink)from marc_blob_subfield");
438 my ($res) = $sth->fetchrow;
441 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?,?)"
443 $sth->execute( $bibid, ( sprintf "%03s", $tagid ), $tagorder,
444 $tag_indicator, $subfieldcode, $subfieldorder, $res );
446 if ( $sth->errstr ) {
448 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
450 $dbh->do("unlock tables");
455 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)"
458 $bibid, ( sprintf "%03s", $tagid ),
459 $tagorder, $tag_indicator,
460 $subfieldcode, $subfieldorder,
463 if ( $sth->errstr ) {
465 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
469 $dbh, $bibid, $tagid, $tagorder,
470 $subfieldcode, $subfieldorder, $subfieldvalue
477 # Returns MARC::Record of the biblio passed in parameter.
478 my ( $dbh, $bibid ) = @_;
479 my $record = MARC::Record->new();
481 #---- TODO : the leader is missing
482 $record->leader(' ');
485 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
486 from marc_subfield_table
487 where bibid=? order by tag,tagorder,subfieldcode
492 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
493 $sth->execute($bibid);
494 my $prevtagorder = 1;
497 my $field; # for >=10 tags
498 my $prevvalue; # for <10 tags
499 while ( my $row = $sth->fetchrow_hashref ) {
501 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
502 $sth2->execute( $row->{'valuebloblink'} );
503 my $row2 = $sth2->fetchrow_hashref;
505 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
507 if ( $row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag ) {
508 $previndicator .= " ";
509 if ( $prevtag < 10 ) {
510 $record->add_fields( ( sprintf "%03s", $prevtag ), $prevvalue )
511 unless $prevtag eq "XXX"; # ignore the 1st loop
514 $record->add_fields($field) unless $prevtag eq "XXX";
517 $prevtagorder = $row->{tagorder};
518 $prevtag = $row->{tag};
519 $previndicator = $row->{tag_indicator};
520 if ( $row->{tag} < 10 ) {
521 $prevvalue = $row->{subfieldvalue};
524 $field = MARC::Field->new(
525 ( sprintf "%03s", $prevtag ),
526 substr( $row->{tag_indicator} . ' ', 0, 1 ),
527 substr( $row->{tag_indicator} . ' ', 1, 1 ),
528 $row->{'subfieldcode'},
529 $row->{'subfieldvalue'}
534 if ( $row->{tag} < 10 ) {
535 $record->add_fields( ( sprintf "%03s", $row->{tag} ),
536 $row->{'subfieldvalue'} );
539 $field->add_subfields( $row->{'subfieldcode'},
540 $row->{'subfieldvalue'} );
542 $prevtag = $row->{tag};
543 $previndicator = $row->{tag_indicator};
547 # the last has not been included inside the loop... do it now !
548 if ( $prevtag ne "XXX" )
549 { # check that we have found something. Otherwise, prevtag is still XXX and we
550 # must return an empty record, not make MARC::Record fail because we try to
551 # create a record with XXX as field :-(
552 if ( $prevtag < 10 ) {
553 $record->add_fields( $prevtag, $prevvalue );
557 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
558 $record->add_fields($field);
566 # Returns MARC::Record of the biblio passed in parameter.
567 my ( $dbh, $bibid, $itemnumber ) = @_;
568 my $record = MARC::Record->new();
570 # search MARC tagorder
573 "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=?"
575 $sth2->execute( $bibid, $itemnumber );
576 my ($tagorder) = $sth2->fetchrow_array();
578 #---- TODO : the leader is missing
581 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
582 from marc_subfield_table
583 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
588 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
589 $sth->execute( $bibid, $tagorder );
590 while ( my $row = $sth->fetchrow_hashref ) {
591 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
592 $sth2->execute( $row->{'valuebloblink'} );
593 my $row2 = $sth2->fetchrow_hashref;
595 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
597 if ( $record->field( $row->{'tag'} ) ) {
600 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
601 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
602 if ( length( $row->{'tag'} ) < 3 ) {
603 $row->{'tag'} = "0" . $row->{'tag'};
605 $field = $record->field( $row->{'tag'} );
608 $field->add_subfields( $row->{'subfieldcode'},
609 $row->{'subfieldvalue'} );
610 $record->delete_field($field);
611 $record->add_fields($field);
615 if ( length( $row->{'tag'} ) < 3 ) {
616 $row->{'tag'} = "0" . $row->{'tag'};
619 MARC::Field->new( $row->{'tag'}, " ", " ",
620 $row->{'subfieldcode'} => $row->{'subfieldvalue'} );
621 $record->add_fields($temp);
629 my ($dbh,$bibid,$record,$frameworkcode,$delete)=@_;
630 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
631 if ($oldrecord eq $record) {
634 # 1st delete the biblio,
636 my $biblionumber = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
637 &MARCdelbiblio($dbh,$bibid,1);
638 &MARCaddbiblio($dbh,$record,$biblionumber,$frameworkcode,$bibid);
642 my ( $dbh, $bibid, $keep_items ) = @_;
644 # if the keep_item is set to 1, then all items are preserved.
645 # This flag is set when the delbiblio is called by modbiblio
646 # due to a too complex structure of MARC (repeatable fields and subfields),
647 # the best solution for a modif is to delete / recreate the record.
649 # 1st of all, copy the MARC::Record to deletedbiblio table => if a true deletion, MARC data will be kept.
650 # if deletion called before MARCmodbiblio => won't do anything, as the oldbiblionumber doesn't
651 # exist in deletedbiblio table
652 my $record = MARCgetbiblio( $dbh, $bibid );
653 my $oldbiblionumber =
654 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
656 $dbh->prepare("update deletedbiblio set marc=? where biblionumber=?");
657 $copy2deleted->execute( $record->as_usmarc(), $oldbiblionumber );
659 # now, delete in MARC tables.
660 if ( $keep_items eq 1 ) {
662 #search item field code
665 "select tagfield from marc_subfield_structure where kohafield like 'items.%'"
668 my $itemtag = $sth->fetchrow_hashref->{tagfield};
670 "delete from marc_subfield_table where bibid=$bibid and tag<>$itemtag"
673 "delete from marc_word where bibid=$bibid and not (tagsubfield like \"$itemtag%\")"
677 $dbh->do("delete from marc_biblio where bibid=$bibid");
678 $dbh->do("delete from marc_subfield_table where bibid=$bibid");
679 $dbh->do("delete from marc_word where bibid=$bibid");
685 # delete the item passed in parameter in MARC tables.
686 my ( $dbh, $bibid, $itemnumber ) = @_;
688 # my $record = MARC::Record->new();
689 # search MARC tagorder
690 my $record = MARCgetitem( $dbh, $bibid, $itemnumber );
692 $dbh->prepare("update deleteditems set marc=? where itemnumber=?");
693 $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
697 "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=?"
699 $sth2->execute( $bibid, $itemnumber );
700 my ($tagorder) = $sth2->fetchrow_array();
703 "delete from marc_subfield_table where bibid=? and tagorder=?");
704 $sth->execute( $bibid, $tagorder );
708 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
710 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
711 # if nothing to change, don't waste time...
712 if ($oldrecord eq $record) {
715 # otherwise, skip through each subfield...
716 my @fields = $record->fields();
717 # search old MARC item
718 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=?");
719 $sth2->execute($bibid,$itemnumber);
720 my ($tagorder) = $sth2->fetchrow_array();
721 foreach my $field (@fields) {
722 my $oldfield = $oldrecord->field($field->tag());
723 my @subfields=$field->subfields();
725 foreach my $subfield (@subfields) {
727 if ($oldfield eq 0 or (length($oldfield->subfield(@$subfield[0])) ==0) ) {
728 # just adding datas...
729 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
730 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
732 # modify he subfield if it's a different string
733 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
734 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
735 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
742 sub MARCmodsubfield {
744 # Subroutine changes a subfield value given a subfieldid.
745 my ( $dbh, $subfieldid, $subfieldvalue ) = @_;
746 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
749 "select valuebloblink from marc_subfield_table where subfieldid=?");
750 $sth1->execute($subfieldid);
751 my ($oldvaluebloblink) = $sth1->fetchrow;
755 # if too long, use a bloblink
756 if ( length($subfieldvalue) > 255 ) {
758 # if already a bloblink, update it, otherwise, insert a new one.
759 if ($oldvaluebloblink) {
762 "update marc_blob_subfield set subfieldvalue=? where blobidlink=?"
764 $sth->execute( $subfieldvalue, $oldvaluebloblink );
769 "insert into marc_blob_subfield (subfieldvalue) values (?)");
770 $sth->execute($subfieldvalue);
772 $dbh->prepare("select max(blobidlink) from marc_blob_subfield");
774 my ($res) = $sth->fetchrow;
777 "update marc_subfield_table set subfieldvalue=null, valuebloblink=? where subfieldid=?"
779 $sth->execute( $res, $subfieldid );
784 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
787 "update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?"
789 $sth->execute( $subfieldvalue, $subfieldid );
791 $dbh->do("unlock tables");
795 "select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?"
797 $sth->execute($subfieldid);
798 my ( $bibid, $tagid, $tagorder, $subfieldcode, $x, $subfieldorder ) =
801 &MARCdelword( $dbh, $bibid, $tagid, $tagorder, $subfieldcode,
804 $dbh, $bibid, $tagid, $tagorder,
805 $subfieldcode, $subfieldorder, $subfieldvalue
807 return ( $subfieldid, $subfieldvalue );
810 sub MARCfindsubfield {
811 my ( $dbh, $bibid, $tag, $subfieldcode, $subfieldorder, $subfieldvalue ) =
813 my $resultcounter = 0;
817 "select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
818 my @bind_values = ( $bibid, $tag, $subfieldcode );
819 if ($subfieldvalue) {
820 $query .= " and subfieldvalue=?";
821 push ( @bind_values, $subfieldvalue );
824 if ( $subfieldorder < 1 ) {
827 $query .= " and subfieldorder=?";
828 push ( @bind_values, $subfieldorder );
830 my $sti = $dbh->prepare($query);
831 $sti->execute(@bind_values);
832 while ( ($subfieldid) = $sti->fetchrow ) {
834 $lastsubfieldid = $subfieldid;
836 if ( $resultcounter > 1 ) {
838 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
839 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
843 return $lastsubfieldid;
847 sub MARCfindsubfieldid {
848 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
849 my $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
850 where bibid=? and tag=? and tagorder=?
851 and subfieldcode=? and subfieldorder=?"
853 $sth->execute( $bibid, $tag, $tagorder, $subfield, $subfieldorder );
854 my ($res) = $sth->fetchrow;
856 $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
857 where bibid=? and tag=? and tagorder=?
860 $sth->execute( $bibid, $tag, $tagorder, $subfield );
861 ($res) = $sth->fetchrow;
866 sub MARCfind_frameworkcode {
867 my ( $dbh, $bibid ) = @_;
869 $dbh->prepare("select frameworkcode from marc_biblio where bibid=?");
870 $sth->execute($bibid);
871 my ($frameworkcode) = $sth->fetchrow;
872 return $frameworkcode;
875 sub MARCdelsubfield {
877 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
878 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
879 $dbh->do( "delete from marc_subfield_table where bibid='$bibid' and
880 tag='$tag' and tagorder='$tagorder'
881 and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
886 sub MARCkoha2marcBiblio {
888 # this function builds partial MARC::Record from the old koha-DB fields
889 my ( $dbh, $biblionumber, $biblioitemnumber ) = @_;
892 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
894 my $record = MARC::Record->new();
896 #--- if bibid, then retrieve old-style koha data
897 if ( $biblionumber > 0 ) {
900 "select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
901 from biblio where biblionumber=?"
903 $sth2->execute($biblionumber);
904 my $row = $sth2->fetchrow_hashref;
906 foreach $code ( keys %$row ) {
907 if ( $row->{$code} ) {
908 &MARCkoha2marcOnefield( $sth, $record, "biblio." . $code,
914 #--- if biblioitem, then retrieve old-style koha data
915 if ( $biblioitemnumber > 0 ) {
918 " SELECT biblioitemnumber,biblionumber,volume,number,classification,
919 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
920 volumedate,volumeddesc,timestamp,illus,pages,notes AS bnotes,size,place
922 WHERE biblioitemnumber=?
925 $sth2->execute($biblioitemnumber);
926 my $row = $sth2->fetchrow_hashref;
928 foreach $code ( keys %$row ) {
929 if ( $row->{$code} ) {
930 &MARCkoha2marcOnefield( $sth, $record, "biblioitems." . $code,
936 # other fields => additional authors, subjects, subtitles
939 " SELECT author FROM additionalauthors WHERE biblionumber=?");
940 $sth2->execute($biblionumber);
941 while ( my $row = $sth2->fetchrow_hashref ) {
942 &MARCkoha2marcOnefield( $sth, $record, "additionalauthors.author",
943 $row->{'author'},'' );
946 $dbh->prepare(" SELECT subject FROM bibliosubject WHERE biblionumber=?");
947 $sth2->execute($biblionumber);
948 while ( my $row = $sth2->fetchrow_hashref ) {
949 &MARCkoha2marcOnefield( $sth, $record, "bibliosubject.subject",
950 $row->{'subject'},'' );
954 " SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?");
955 $sth2->execute($biblionumber);
956 while ( my $row = $sth2->fetchrow_hashref ) {
957 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.title",
958 $row->{'subtitle'},'' );
963 sub MARCkoha2marcItem {
965 # this function builds partial MARC::Record from the old koha-DB fields
966 my ( $dbh, $biblionumber, $itemnumber ) = @_;
968 # my $dbh=&C4Connect;
971 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
973 my $record = MARC::Record->new();
975 #--- if item, then retrieve old-style koha data
976 if ( $itemnumber > 0 ) {
978 # print STDERR "prepare $biblionumber,$itemnumber\n";
981 "SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
982 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
983 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,itemcallnumber,issues,renewals,
984 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
988 $sth2->execute($itemnumber);
989 my $row = $sth2->fetchrow_hashref;
991 foreach $code ( keys %$row ) {
992 if ( $row->{$code} ) {
993 &MARCkoha2marcOnefield( $sth, $record, "items." . $code,
1001 sub MARCkoha2marcSubtitle {
1003 # this function builds partial MARC::Record from the old koha-DB fields
1004 my ( $dbh, $bibnum, $subtitle ) = @_;
1007 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
1009 my $record = MARC::Record->new();
1010 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle",
1015 sub MARCkoha2marcOnefield {
1016 my ( $sth, $record, $kohafieldname, $value,$frameworkcode ) = @_;
1019 $sth->execute($frameworkcode,$kohafieldname);
1020 if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
1021 if ( $record->field($tagfield) ) {
1022 my $tag = $record->field($tagfield);
1024 $tag->add_subfields( $tagsubfield, $value );
1025 $record->delete_field($tag);
1026 $record->add_fields($tag);
1030 $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
1037 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
1039 my $record = MARC::Record->new();
1040 # my %subfieldlist=();
1041 my $prevvalue; # if tag <10
1042 my $field; # if tag >=10
1043 for (my $i=0; $i< @$rtags; $i++) {
1044 # rebuild MARC::Record
1045 # warn "0=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ";
1046 if (@$rtags[$i] ne $prevtag) {
1047 if ($prevtag < 10) {
1049 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
1053 $record->add_fields($field);
1056 $indicators{@$rtags[$i]}.=' ';
1057 if (@$rtags[$i] <10) {
1058 $prevvalue= @$rvalues[$i];
1060 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
1061 # warn "1=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
1063 $prevtag = @$rtags[$i];
1065 if (@$rtags[$i] <10) {
1066 $prevvalue=@$rvalues[$i];
1068 if (length(@$rvalues[$i])>0) {
1069 $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
1070 # warn "2=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
1073 $prevtag= @$rtags[$i];
1076 # the last has not been included inside the loop... do it now !
1077 $record->add_fields($field);
1078 # warn "HTML2MARC=".$record->as_formatted;
1083 my ($dbh,$record,$frameworkcode) = @_;
1084 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?");
1086 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
1089 while (($field)=$sth2->fetchrow) {
1090 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result,$frameworkcode);
1092 $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
1094 while (($field)=$sth2->fetchrow) {
1095 if ($field eq 'notes') { $field = 'bnotes'; }
1096 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result,$frameworkcode);
1098 $sth2=$dbh->prepare("SHOW COLUMNS from items");
1100 while (($field)=$sth2->fetchrow) {
1101 $result=&MARCmarc2kohaOneField($sth,"items",$field,$record,$result,$frameworkcode);
1103 # additional authors : specific
1104 $result = &MARCmarc2kohaOneField($sth,"bibliosubtitle","subtitle",$record,$result,$frameworkcode);
1105 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result,$frameworkcode);
1106 # modify copyrightdate to keep only the 1st year found
1107 my $temp = $result->{'copyrightdate'};
1108 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1110 $result->{'copyrightdate'} = $1;
1111 } else { # if no cYYYY, get the 1st date.
1112 $temp =~ m/(\d\d\d\d)/;
1113 $result->{'copyrightdate'} = $1;
1115 # modify publicationyear to keep only the 1st year found
1116 my $temp = $result->{'publicationyear'};
1117 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1119 $result->{'publicationyear'} = $1;
1120 } else { # if no cYYYY, get the 1st date.
1121 $temp =~ m/(\d\d\d\d)/;
1122 $result->{'publicationyear'} = $1;
1127 sub MARCmarc2kohaOneField {
1129 # FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
1130 my ( $sth, $kohatable, $kohafield, $record, $result,$frameworkcode ) = @_;
1131 # warn "kohatable / $kohafield / $result / ";
1135 $sth->execute($frameworkcode, $kohatable . "." . $kohafield );
1136 ( $tagfield, $subfield ) = $sth->fetchrow;
1137 foreach my $field ( $record->field($tagfield) ) {
1138 if ( $field->subfield($subfield) ) {
1139 if ( $result->{$kohafield} ) {
1140 $result->{$kohafield} .= " | " . $field->subfield($subfield);
1143 $result->{$kohafield} = $field->subfield($subfield);
1147 # warn "OneField for $kohatable.$kohafield and $frameworkcode=> $tagfield, $subfield";
1153 # split a subfield string and adds it into the word table.
1156 $dbh, $bibid, $tag, $tagorder,
1157 $subfieldid, $subfieldorder, $sentence
1160 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\})/ /g;
1161 my @words = split / /, $sentence;
1162 my $stopwords = C4::Context->stopwords;
1165 "insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word)
1166 values (?,concat(?,?),?,?,?,soundex(?))"
1168 foreach my $word (@words) {
1169 # we record only words one char long and not in stopwords hash
1170 if (length($word)>=1 and !($stopwords->{uc($word)})) {
1171 $sth->execute($bibid,$tag,$subfieldid,$tagorder,$subfieldorder,$word,$word);
1173 warn "ERROR ==> insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word) values ($bibid,concat($tag,$subfieldid),$tagorder,$subfieldorder,$word,soundex($word))\n";
1181 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
1182 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
1185 "delete from marc_word where bibid=? and tagsubfield=concat(?,?) and tagorder=? and subfieldorder=?"
1187 $sth->execute( $bibid, $tag, $subfield, $tagorder, $subfieldorder );
1192 # NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW
1195 # all the following subs are useful to manage MARC-DB with complete MARC records.
1196 # it's used with marcimport, and marc management tools
1199 =item ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
1201 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
1202 are builded from the MARC::Record. If they are passed, they are used.
1204 =item NEWnewitem($dbh, $record,$bibid);
1206 adds an item in the db.
1211 my ( $dbh, $record, $frameworkcode ) = @_;
1214 my $olddata = MARCmarc2koha( $dbh, $record,$frameworkcode );
1215 $oldbibnum = OLDnewbiblio( $dbh, $olddata );
1216 $olddata->{'biblionumber'} = $oldbibnum;
1217 $oldbibitemnum = OLDnewbiblioitem( $dbh, $olddata );
1219 # search subtiles, addiauthors and subjects
1220 my ( $tagfield, $tagsubfield ) =
1221 MARCfind_marc_from_kohafield( $dbh, "additionalauthors.author",$frameworkcode );
1222 my @addiauthfields = $record->field($tagfield);
1223 foreach my $addiauthfield (@addiauthfields) {
1224 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1225 foreach my $subfieldcount ( 0 .. $#addiauthsubfields ) {
1226 OLDmodaddauthor( $dbh, $oldbibnum,
1227 $addiauthsubfields[$subfieldcount] );
1230 ( $tagfield, $tagsubfield ) =
1231 MARCfind_marc_from_kohafield( $dbh, "bibliosubtitle.title",$frameworkcode );
1232 my @subtitlefields = $record->field($tagfield);
1233 foreach my $subtitlefield (@subtitlefields) {
1234 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1235 foreach my $subfieldcount ( 0 .. $#subtitlesubfields ) {
1236 OLDnewsubtitle( $dbh, $oldbibnum,
1237 $subtitlesubfields[$subfieldcount] );
1240 ( $tagfield, $tagsubfield ) =
1241 MARCfind_marc_from_kohafield( $dbh, "bibliosubject.subject",$frameworkcode );
1242 my @subj = $record->field($tagfield);
1244 foreach my $subject (@subj) {
1245 my @subjsubfield = $subject->subfield($tagsubfield);
1246 foreach my $subfieldcount ( 0 .. $#subjsubfield ) {
1247 push @subjects, $subjsubfield[$subfieldcount];
1250 OLDmodsubject( $dbh, $oldbibnum, 1, @subjects );
1252 # we must add bibnum and bibitemnum in MARC::Record...
1253 # we build the new field with biblionumber and biblioitemnumber
1254 # we drop the original field
1255 # we add the new builded field.
1256 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
1257 # (steve and paul : thinks 090 is a good choice)
1260 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
1262 $sth->execute("biblio.biblionumber");
1263 ( my $tagfield1, my $tagsubfield1 ) = $sth->fetchrow;
1264 $sth->execute("biblioitems.biblioitemnumber");
1265 ( my $tagfield2, my $tagsubfield2 ) = $sth->fetchrow;
1266 if ( $tagfield1 != $tagfield2 ) {
1268 "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1270 "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1273 my $newfield = MARC::Field->new(
1274 $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
1275 "$tagsubfield2" => $oldbibitemnum
1278 # drop old field and create new one...
1279 my $old_field = $record->field($tagfield1);
1280 $record->delete_field($old_field);
1281 $record->add_fields($newfield);
1282 my $bibid = MARCaddbiblio( $dbh, $record, $oldbibnum, $frameworkcode );
1283 return ( $bibid, $oldbibnum, $oldbibitemnum );
1287 my ($dbh,$record,$bibid,$frameworkcode) =@_;
1288 $frameworkcode="" unless $frameworkcode;
1289 &MARCmodbiblio($dbh,$bibid,$record,$frameworkcode,0);
1290 my $oldbiblio = MARCmarc2koha($dbh,$record,$frameworkcode);
1291 my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
1292 OLDmodbibitem($dbh,$oldbiblio);
1293 # now, modify addi authors, subject, addititles.
1294 my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"additionalauthors.author",$frameworkcode);
1295 my @addiauthfields = $record->field($tagfield);
1296 foreach my $addiauthfield (@addiauthfields) {
1297 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1298 foreach my $subfieldcount (0..$#addiauthsubfields) {
1299 OLDmodaddauthor($dbh,$oldbiblionumber,$addiauthsubfields[$subfieldcount]);
1302 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubtitle.subtitle",$frameworkcode);
1303 my @subtitlefields = $record->field($tagfield);
1304 foreach my $subtitlefield (@subtitlefields) {
1305 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1306 foreach my $subfieldcount (0..$#subtitlesubfields) {
1307 OLDmodsubtitle($dbh,$oldbiblionumber,$subtitlesubfields[$subfieldcount]);
1310 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject",$frameworkcode);
1311 my @subj = $record->field($tagfield);
1313 foreach my $subject (@subj) {
1314 my @subjsubfield = $subject->subfield($tagsubfield);
1315 foreach my $subfieldcount (0..$#subjsubfield) {
1316 push @subjects,$subjsubfield[$subfieldcount];
1319 OLDmodsubject($dbh,$oldbiblionumber,1,@subjects);
1324 my ( $dbh, $bibid ) = @_;
1325 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1326 &OLDdelbiblio( $dbh, $biblio );
1329 "select biblioitemnumber from biblioitems where biblionumber=?");
1330 $sth->execute($biblio);
1331 while ( my ($biblioitemnumber) = $sth->fetchrow ) {
1332 OLDdeletebiblioitem( $dbh, $biblioitemnumber );
1334 &MARCdelbiblio( $dbh, $bibid, 0 );
1338 my ( $dbh, $record, $bibid ) = @_;
1340 # add item in old-DB
1341 my $frameworkcode=MARCfind_frameworkcode($dbh,$bibid);
1342 my $item = &MARCmarc2koha( $dbh, $record,$frameworkcode );
1343 # needs old biblionumber and biblioitemnumber
1344 $item->{'biblionumber'} =
1345 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1348 "select biblioitemnumber from biblioitems where biblionumber=?");
1349 $sth->execute( $item->{'biblionumber'} );
1350 ( $item->{'biblioitemnumber'} ) = $sth->fetchrow;
1351 my ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, $item->{barcode} );
1353 # add itemnumber to MARC::Record before adding the item.
1356 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
1358 &MARCkoha2marcOnefield( $sth, $record, "items.itemnumber", $itemnumber,$frameworkcode );
1361 my $bib = &MARCadditem( $dbh, $record, $item->{'biblionumber'} );
1365 my ( $dbh, $record, $bibid, $itemnumber, $delete ) = @_;
1367 &MARCmoditem( $dbh, $record, $bibid, $itemnumber, $delete );
1368 my $frameworkcode=MARCfind_frameworkcode($dbh,$bibid);
1369 my $olditem = MARCmarc2koha( $dbh, $record,$frameworkcode );
1370 OLDmoditem( $dbh, $olditem );
1374 my ( $dbh, $bibid, $itemnumber ) = @_;
1375 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1376 &OLDdelitem( $dbh, $itemnumber );
1377 &MARCdelitem( $dbh, $bibid, $itemnumber );
1382 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
1386 =item $biblionumber = OLDnewbiblio($dbh,$biblio);
1388 adds a record in biblio table. Datas are in the hash $biblio.
1390 =item $biblionumber = OLDmodbiblio($dbh,$biblio);
1392 modify a record in biblio table. Datas are in the hash $biblio.
1394 =item OLDmodsubtitle($dbh,$bibnum,$subtitle);
1396 modify subtitles in bibliosubtitle table.
1398 =item OLDmodaddauthor($dbh,$bibnum,$author);
1400 adds or modify additional authors
1401 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1403 =item $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1405 modify/adds subjects
1407 =item OLDmodbibitem($dbh, $biblioitem);
1411 =item OLDmodnote($dbh,$bibitemnum,$note
1413 modify a note for a biblioitem
1415 =item OLDnewbiblioitem($dbh,$biblioitem);
1417 adds a biblioitem ($biblioitem is a hash with the values)
1419 =item OLDnewsubject($dbh,$bibnum);
1423 =item OLDnewsubtitle($dbh,$bibnum,$subtitle);
1425 create a new subtitle
1427 =item ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1429 create a item. $item is a hash and $barcode the barcode.
1431 =item OLDmoditem($dbh,$item);
1435 =item OLDdelitem($dbh,$itemnum);
1439 =item OLDdeletebiblioitem($dbh,$biblioitemnumber);
1441 deletes a biblioitem
1442 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1444 =item OLDdelbiblio($dbh,$biblio);
1451 my ( $dbh, $biblio ) = @_;
1453 # my $dbh = &C4Connect;
1454 my $sth = $dbh->prepare("Select max(biblionumber) from biblio");
1456 my $data = $sth->fetchrow_arrayref;
1457 my $bibnum = $$data[0] + 1;
1460 if ( $biblio->{'seriestitle'} ) { $series = 1 }
1464 "insert into biblio set biblionumber = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?"
1467 $bibnum, $biblio->{'title'},
1468 $biblio->{'author'}, $biblio->{'copyrightdate'},
1469 $biblio->{'serial'}, $biblio->{'seriestitle'},
1470 $biblio->{'notes'}, $biblio->{'abstract'}
1480 my ( $dbh, $biblio ) = @_;
1482 # my $dbh = C4Connect;
1489 "Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?, seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?"
1492 $biblio->{'title'}, $biblio->{'author'},
1493 $biblio->{'abstract'}, $biblio->{'copyrightdate'},
1494 $biblio->{'seriestitle'}, $biblio->{'serial'},
1495 $biblio->{'unititle'}, $biblio->{'notes'},
1496 $biblio->{'biblionumber'}
1500 return ( $biblio->{'biblionumber'} );
1503 sub OLDmodsubtitle {
1504 my ( $dbh, $bibnum, $subtitle ) = @_;
1507 "update bibliosubtitle set subtitle = ? where biblionumber = ?");
1508 $sth->execute( $subtitle, $bibnum );
1512 sub OLDmodaddauthor {
1513 my ( $dbh, $bibnum, @authors ) = @_;
1515 # my $dbh = C4Connect;
1517 $dbh->prepare("Delete from additionalauthors where biblionumber = ?");
1519 $sth->execute($bibnum);
1521 foreach my $author (@authors) {
1522 if ( $author ne '' ) {
1525 "Insert into additionalauthors set author = ?, biblionumber = ?"
1528 $sth->execute( $author, $bibnum );
1533 } # sub modaddauthor
1536 my ( $dbh, $bibnum, $force, @subject ) = @_;
1538 # my $dbh = C4Connect;
1539 my $count = @subject;
1541 for ( my $i = 0 ; $i < $count ; $i++ ) {
1542 $subject[$i] =~ s/^ //g;
1543 $subject[$i] =~ s/ $//g;
1546 "select * from catalogueentry where entrytype = 's' and catalogueentry = ?"
1548 $sth->execute( $subject[$i] );
1550 if ( my $data = $sth->fetchrow_hashref ) {
1553 if ( $force eq $subject[$i] || $force == 1 ) {
1555 # subject not in aut, chosen to force anway
1556 # so insert into cataloguentry so its in auth file
1559 "Insert into catalogueentry (entrytype,catalogueentry) values ('s',?)"
1562 $sth2->execute( $subject[$i] ) if ( $subject[$i] );
1567 "$subject[$i]\n does not exist in the subject authority file";
1570 "Select * from catalogueentry where entrytype = 's' and (catalogueentry like ? or catalogueentry like ? or catalogueentry like ?)"
1572 $sth2->execute( "$subject[$i] %", "% $subject[$i] %",
1574 while ( my $data = $sth2->fetchrow_hashref ) {
1575 $error .= "<br>$data->{'catalogueentry'}";
1582 if ( $error eq '' ) {
1584 $dbh->prepare("Delete from bibliosubject where biblionumber = ?");
1585 $sth->execute($bibnum);
1589 "Insert into bibliosubject (subject,biblionumber) values (?,?)");
1591 foreach $query (@subject) {
1592 $sth->execute( $query, $bibnum ) if ( $query && $bibnum );
1602 my ( $dbh, $biblioitem ) = @_;
1604 # my $dbh = C4Connect;
1607 $biblioitem->{'itemtype'} = $dbh->quote( $biblioitem->{'itemtype'} );
1608 $biblioitem->{'url'} = $dbh->quote( $biblioitem->{'url'} );
1609 $biblioitem->{'isbn'} = $dbh->quote( $biblioitem->{'isbn'} );
1610 $biblioitem->{'publishercode'} =
1611 $dbh->quote( $biblioitem->{'publishercode'} );
1612 $biblioitem->{'publicationyear'} =
1613 $dbh->quote( $biblioitem->{'publicationyear'} );
1614 $biblioitem->{'classification'} =
1615 $dbh->quote( $biblioitem->{'classification'} );
1616 $biblioitem->{'dewey'} = $dbh->quote( $biblioitem->{'dewey'} );
1617 $biblioitem->{'subclass'} = $dbh->quote( $biblioitem->{'subclass'} );
1618 $biblioitem->{'illus'} = $dbh->quote( $biblioitem->{'illus'} );
1619 $biblioitem->{'pages'} = $dbh->quote( $biblioitem->{'pages'} );
1620 $biblioitem->{'volumeddesc'} = $dbh->quote( $biblioitem->{'volumeddesc'} );
1621 $biblioitem->{'bnotes'} = $dbh->quote( $biblioitem->{'bnotes'} );
1622 $biblioitem->{'size'} = $dbh->quote( $biblioitem->{'size'} );
1623 $biblioitem->{'place'} = $dbh->quote( $biblioitem->{'place'} );
1625 $query = "Update biblioitems set
1626 itemtype = $biblioitem->{'itemtype'},
1627 url = $biblioitem->{'url'},
1628 isbn = $biblioitem->{'isbn'},
1629 publishercode = $biblioitem->{'publishercode'},
1630 publicationyear = $biblioitem->{'publicationyear'},
1631 classification = $biblioitem->{'classification'},
1632 dewey = $biblioitem->{'dewey'},
1633 subclass = $biblioitem->{'subclass'},
1634 illus = $biblioitem->{'illus'},
1635 pages = $biblioitem->{'pages'},
1636 volumeddesc = $biblioitem->{'volumeddesc'},
1637 notes = $biblioitem->{'bnotes'},
1638 size = $biblioitem->{'size'},
1639 place = $biblioitem->{'place'}
1640 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1643 if ( $dbh->errstr ) {
1651 my ( $dbh, $bibitemnum, $note ) = @_;
1653 # my $dbh=C4Connect;
1654 my $query = "update biblioitems set notes='$note' where
1655 biblioitemnumber='$bibitemnum'";
1656 my $sth = $dbh->prepare($query);
1663 sub OLDnewbiblioitem {
1664 my ( $dbh, $biblioitem ) = @_;
1666 # my $dbh = C4Connect;
1667 my $sth = $dbh->prepare("Select max(biblioitemnumber) from biblioitems");
1672 $data = $sth->fetchrow_arrayref;
1673 $bibitemnum = $$data[0] + 1;
1677 $sth = $dbh->prepare( "insert into biblioitems set
1678 biblioitemnumber = ?, biblionumber = ?,
1679 volume = ?, number = ?,
1680 classification = ?, itemtype = ?,
1682 issn = ?, dewey = ?,
1683 subclass = ?, publicationyear = ?,
1684 publishercode = ?, volumedate = ?,
1685 volumeddesc = ?, illus = ?,
1686 pages = ?, notes = ?,
1688 marc = ?, place = ?"
1691 $bibitemnum, $biblioitem->{'biblionumber'},
1692 $biblioitem->{'volume'}, $biblioitem->{'number'},
1693 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
1694 $biblioitem->{'url'}, $biblioitem->{'isbn'},
1695 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
1696 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
1697 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
1698 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
1699 $biblioitem->{'pages'}, $biblioitem->{'bnotes'},
1700 $biblioitem->{'size'}, $biblioitem->{'lccn'},
1701 $biblioitem->{'marc'}, $biblioitem->{'place'}
1706 return ($bibitemnum);
1710 my ( $dbh, $bibnum ) = @_;
1712 $dbh->prepare("insert into bibliosubject (biblionumber) values (?)");
1713 $sth->execute($bibnum);
1717 sub OLDnewsubtitle {
1718 my ( $dbh, $bibnum, $subtitle ) = @_;
1721 "insert into bibliosubtitle set biblionumber = ?, subtitle = ?");
1722 $sth->execute( $bibnum, $subtitle );
1727 my ( $dbh, $item, $barcode ) = @_;
1729 # my $dbh = C4Connect;
1730 my $sth = $dbh->prepare("Select max(itemnumber) from items");
1736 $data = $sth->fetchrow_hashref;
1737 $itemnumber = $data->{'max(itemnumber)'} + 1;
1740 # FIXME the "notforloan" field seems to be named "loan" in some places. workaround bugfix.
1741 if ( $item->{'loan'} ) {
1742 $item->{'notforloan'} = $item->{'loan'};
1745 # if dateaccessioned is provided, use it. Otherwise, set to NOW()
1746 if ( $item->{'dateaccessioned'} ) {
1747 $sth = $dbh->prepare( "Insert into items set
1748 itemnumber = ?, biblionumber = ?,
1749 biblioitemnumber = ?, barcode = ?,
1750 booksellerid = ?, dateaccessioned = ?,
1751 homebranch = ?, holdingbranch = ?,
1752 price = ?, replacementprice = ?,
1753 replacementpricedate = NOW(), itemnotes = ?,
1754 itemcallnumber =?, notforloan = ?,
1759 $itemnumber, $item->{'biblionumber'},
1760 $item->{'biblioitemnumber'}, $barcode,
1761 $item->{'booksellerid'}, $item->{'dateaccessioned'},
1762 $item->{'homebranch'}, $item->{'holdingbranch'},
1763 $item->{'price'}, $item->{'replacementprice'},
1764 $item->{'itemnotes'}, $item->{'itemcallnumber'},
1765 $item->{'notforloan'}, $item->{'location'}
1769 $sth = $dbh->prepare( "Insert into items set
1770 itemnumber = ?, biblionumber = ?,
1771 biblioitemnumber = ?, barcode = ?,
1772 booksellerid = ?, dateaccessioned = NOW(),
1773 homebranch = ?, holdingbranch = ?,
1774 price = ?, replacementprice = ?,
1775 replacementpricedate = NOW(), itemnotes = ?,
1776 itemcallnumber = ? , notforloan = ?,
1781 $itemnumber, $item->{'biblionumber'},
1782 $item->{'biblioitemnumber'}, $barcode,
1783 $item->{'booksellerid'}, $item->{'homebranch'},
1784 $item->{'holdingbranch'}, $item->{'price'},
1785 $item->{'replacementprice'}, $item->{'itemnotes'},
1786 $item->{'itemcallnumber'}, $item->{'notforloan'},
1790 if ( defined $sth->errstr ) {
1791 $error .= $sth->errstr;
1794 return ( $itemnumber, $error );
1798 my ( $dbh, $item ) = @_;
1800 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1801 # my $dbh=C4Connect;
1802 $item->{'itemnum'} = $item->{'itemnumber'} unless $item->{'itemnum'};
1803 my $query = "update items set barcode=?,itemnotes=?,itemcallnumber=?,notforloan=?,location=? where itemnumber=?";
1805 $item->{'barcode'}, $item->{'notes'},
1806 $item->{'itemcallnumber'}, $item->{'notforloan'},
1807 $item->{'location'}, $item->{'itemnum'}
1809 if ( $item->{'barcode'} eq '' ) {
1810 $item->{'notforloan'} = 0 unless $item->{'notforloan'};
1811 $query = "update items set notforloan=? where itemnumber=?";
1812 @bind = ( $item->{'notforloan'}, $item->{'itemnum'} );
1814 if ( $item->{'lost'} ne '' ) {
1815 $query = "update items set biblioitemnumber=?,
1825 $item->{'bibitemnum'}, $item->{'barcode'},
1826 $item->{'notes'}, $item->{'homebranch'},
1827 $item->{'lost'}, $item->{'wthdrawn'},
1828 $item->{'itemcallnumber'}, $item->{'notforloan'},
1829 $item->{'location'}, $item->{'itemnum'}
1831 if ($item->{homebranch}) {
1832 $query.=",homebranch=?";
1833 push @bind, $item->{homebranch};
1835 if ($item->{holdingbranch}) {
1836 $query.=",holdingbranch=?";
1837 push @bind, $item->{holdingbranch};
1839 $query.=" where itemnumber=?";
1841 if ( $item->{'replacement'} ne '' ) {
1842 $query =~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1844 my $sth = $dbh->prepare($query);
1845 $sth->execute(@bind);
1852 my ( $dbh, $itemnum ) = @_;
1854 # my $dbh=C4Connect;
1855 my $sth = $dbh->prepare("select * from items where itemnumber=?");
1856 $sth->execute($itemnum);
1857 my $data = $sth->fetchrow_hashref;
1859 my $query = "Insert into deleteditems set ";
1861 foreach my $temp ( keys %$data ) {
1862 $query .= "$temp = ?,";
1863 push ( @bind, $data->{$temp} );
1868 $sth = $dbh->prepare($query);
1869 $sth->execute(@bind);
1871 $sth = $dbh->prepare("Delete from items where itemnumber=?");
1872 $sth->execute($itemnum);
1878 sub OLDdeletebiblioitem {
1879 my ( $dbh, $biblioitemnumber ) = @_;
1881 # my $dbh = C4Connect;
1882 my $sth = $dbh->prepare( "Select * from biblioitems
1883 where biblioitemnumber = ?"
1887 $sth->execute($biblioitemnumber);
1889 if ( $results = $sth->fetchrow_hashref ) {
1893 "Insert into deletedbiblioitems (biblioitemnumber, biblionumber, volume, number, classification, itemtype,
1894 isbn, issn ,dewey ,subclass ,publicationyear ,publishercode ,volumedate ,volumeddesc ,timestamp ,illus ,
1895 pages ,notes ,size ,url ,lccn ) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
1899 $results->{biblioitemnumber}, $results->{biblionumber},
1900 $results->{volume}, $results->{number},
1901 $results->{classification}, $results->{itemtype},
1902 $results->{isbn}, $results->{issn},
1903 $results->{dewey}, $results->{subclass},
1904 $results->{publicationyear}, $results->{publishercode},
1905 $results->{volumedate}, $results->{volumeddesc},
1906 $results->{timestamp}, $results->{illus},
1907 $results->{pages}, $results->{notes},
1908 $results->{size}, $results->{url},
1912 $dbh->prepare("Delete from biblioitems where biblioitemnumber = ?");
1913 $sth2->execute($biblioitemnumber);
1918 # Now delete all the items attached to the biblioitem
1919 $sth = $dbh->prepare("Select * from items where biblioitemnumber = ?");
1920 $sth->execute($biblioitemnumber);
1922 while ( my $data = $sth->fetchrow_hashref ) {
1923 my $query = "Insert into deleteditems set ";
1925 foreach my $temp ( keys %$data ) {
1926 $query .= "$temp = ?,";
1927 push ( @bind, $data->{$temp} );
1930 my $sth2 = $dbh->prepare($query);
1931 $sth2->execute(@bind);
1934 $sth = $dbh->prepare("Delete from items where biblioitemnumber = ?");
1935 $sth->execute($biblioitemnumber);
1939 } # sub deletebiblioitem
1942 my ( $dbh, $biblio ) = @_;
1943 my $sth = $dbh->prepare("select * from biblio where biblionumber=?");
1944 $sth->execute($biblio);
1945 if ( my $data = $sth->fetchrow_hashref ) {
1947 my $query = "Insert into deletedbiblio set ";
1949 foreach my $temp ( keys %$data ) {
1950 $query .= "$temp = ?,";
1951 push ( @bind, $data->{$temp} );
1954 #replacing the last , by ",?)"
1956 $sth = $dbh->prepare($query);
1957 $sth->execute(@bind);
1959 $sth = $dbh->prepare("Delete from biblio where biblionumber=?");
1960 $sth->execute($biblio);
1974 my $dbh = C4::Context->dbh;
1977 my $sth = $dbh->prepare("Select count(*) from items where biblionumber=?");
1978 $sth->execute($biblio);
1979 my $data = $sth->fetchrow_hashref;
1981 return ( $data->{'count(*)'} );
1986 my $dbh = C4::Context->dbh;
1987 my $bibnum = OLDnewbiblio( $dbh, $biblio );
1988 # finds new (MARC bibid
1989 # my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
1990 my $record = &MARCkoha2marcBiblio( $dbh, $bibnum );
1991 MARCaddbiblio( $dbh, $record, $bibnum,'' );
1997 $biblionumber = &modbiblio($biblio);
1999 Update a biblio record.
2001 C<$biblio> is a reference-to-hash whose keys are the fields in the
2002 biblio table in the Koha database. All fields must be present, not
2003 just the ones you wish to change.
2005 C<&modbiblio> updates the record defined by
2006 C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
2008 C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
2015 my $dbh = C4::Context->dbh;
2016 my $biblionumber=OLDmodbiblio($dbh,$biblio);
2017 my $record = MARCkoha2marcBiblio($dbh,$biblionumber,$biblionumber);
2018 # finds new (MARC bibid
2019 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
2020 MARCmodbiblio($dbh,$bibid,$record,"",0);
2021 return($biblionumber);
2026 &modsubtitle($biblionumber, $subtitle);
2028 Sets the subtitle of a book.
2030 C<$biblionumber> is the biblionumber of the book to modify.
2032 C<$subtitle> is the new subtitle.
2037 my ( $bibnum, $subtitle ) = @_;
2038 my $dbh = C4::Context->dbh;
2039 &OLDmodsubtitle( $dbh, $bibnum, $subtitle );
2044 &modaddauthor($biblionumber, $author);
2046 Replaces all additional authors for the book with biblio number
2047 C<$biblionumber> with C<$author>. If C<$author> is the empty string,
2048 C<&modaddauthor> deletes all additional authors.
2053 my ( $bibnum, @authors ) = @_;
2054 my $dbh = C4::Context->dbh;
2055 &OLDmodaddauthor( $dbh, $bibnum, @authors );
2056 } # sub modaddauthor
2060 $error = &modsubject($biblionumber, $force, @subjects);
2062 $force - a subject to force
2064 $error - Error message, or undef if successful.
2069 my ( $bibnum, $force, @subject ) = @_;
2070 my $dbh = C4::Context->dbh;
2071 my $error = &OLDmodsubject( $dbh, $bibnum, $force, @subject );
2076 my ($biblioitem) = @_;
2077 my $dbh = C4::Context->dbh;
2078 &OLDmodbibitem( $dbh, $biblioitem );
2082 my ( $bibitemnum, $note ) = @_;
2083 my $dbh = C4::Context->dbh;
2084 &OLDmodnote( $dbh, $bibitemnum, $note );
2088 my ($biblioitem) = @_;
2089 my $dbh = C4::Context->dbh;
2090 my $bibitemnum = &OLDnewbiblioitem( $dbh, $biblioitem );
2093 MARCkoha2marcBiblio( $dbh, 0, $bibitemnum )
2094 ; # the 0 means "do NOT retrieve biblio, only biblioitem, in the MARC record
2096 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh,
2097 $biblioitem->{biblionumber} );
2098 &MARCaddbiblio( $dbh, $MARCbiblio, $biblioitem->{biblionumber}, '',$bibid );
2099 return ($bibitemnum);
2104 my $dbh = C4::Context->dbh;
2105 &OLDnewsubject( $dbh, $bibnum );
2109 my ( $bibnum, $subtitle ) = @_;
2110 my $dbh = C4::Context->dbh;
2111 &OLDnewsubtitle( $dbh, $bibnum, $subtitle );
2115 my ( $item, @barcodes ) = @_;
2116 my $dbh = C4::Context->dbh;
2120 foreach my $barcode (@barcodes) {
2121 ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, uc($barcode) );
2124 &MARCkoha2marcItem( $dbh, $item->{biblionumber}, $itemnumber );
2125 &MARCadditem( $dbh, $MARCitem, $item->{biblionumber} );
2132 my $dbh = C4::Context->dbh;
2133 &OLDmoditem( $dbh, $item );
2135 &MARCkoha2marcItem( $dbh, $item->{'biblionumber'}, $item->{'itemnum'} );
2137 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $item->{biblionumber} );
2138 &MARCmoditem( $dbh, $MARCitem, $bibid, $item->{itemnum}, 0 );
2142 my ( $count, @barcodes ) = @_;
2143 my $dbh = C4::Context->dbh;
2145 my $sth = $dbh->prepare("Select * from items where barcode=?");
2146 for ( my $i = 0 ; $i < $count ; $i++ ) {
2147 $barcodes[$i] = uc $barcodes[$i];
2148 $sth->execute( $barcodes[$i] );
2149 if ( my $data = $sth->fetchrow_hashref ) {
2150 $error .= " Duplicate Barcode: $barcodes[$i]";
2158 my ($bibitemnum) = @_;
2159 my $dbh = C4::Context->dbh;
2162 $dbh->prepare("Select count(*) from items where biblioitemnumber=?");
2163 $sth->execute($bibitemnum);
2164 my $data = $sth->fetchrow_hashref;
2166 return ( $data->{'count(*)'} );
2171 my $dbh = C4::Context->dbh;
2172 &OLDdelitem( $dbh, $itemnum );
2175 sub deletebiblioitem {
2176 my ($biblioitemnumber) = @_;
2177 my $dbh = C4::Context->dbh;
2178 &OLDdeletebiblioitem( $dbh, $biblioitemnumber );
2179 } # sub deletebiblioitem
2183 my $dbh = C4::Context->dbh;
2184 &OLDdelbiblio( $dbh, $biblio );
2185 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $biblio );
2186 &MARCdelbiblio( $dbh, $bibid, 0 );
2190 my ($biblionumber) = @_;
2191 my $dbh = C4::Context->dbh;
2192 my $sth = $dbh->prepare("Select * from biblio where biblionumber = ?");
2194 # || die "Cannot prepare $query\n" . $dbh->errstr;
2198 $sth->execute($biblionumber);
2200 # || die "Cannot execute $query\n" . $sth->errstr;
2201 while ( my $data = $sth->fetchrow_hashref ) {
2202 $results[$count] = $data;
2207 return ( $count, @results );
2211 my ($biblioitemnum) = @_;
2212 my $dbh = C4::Context->dbh;
2213 my $sth = $dbh->prepare( "Select * from biblioitems where
2214 biblioitemnumber = ?"
2219 $sth->execute($biblioitemnum);
2221 while ( my $data = $sth->fetchrow_hashref ) {
2222 $results[$count] = $data;
2227 return ( $count, @results );
2228 } # sub getbiblioitem
2230 sub getbiblioitembybiblionumber {
2231 my ($biblionumber) = @_;
2232 my $dbh = C4::Context->dbh;
2233 my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?");
2237 $sth->execute($biblionumber);
2239 while ( my $data = $sth->fetchrow_hashref ) {
2240 $results[$count] = $data;
2245 return ( $count, @results );
2249 my $dbh = C4::Context->dbh;
2250 my $query = "select * from itemtypes order by description";
2251 my $sth = $dbh->prepare($query);
2253 # || die "Cannot prepare $query" . $dbh->errstr;
2259 # || die "Cannot execute $query\n" . $sth->errstr;
2260 while ( my $data = $sth->fetchrow_hashref ) {
2261 $results[$count] = $data;
2266 return ( $count, @results );
2267 } # sub getitemtypes
2269 sub getitemsbybiblioitem {
2270 my ($biblioitemnum) = @_;
2271 my $dbh = C4::Context->dbh;
2272 my $sth = $dbh->prepare( "Select * from items, biblio where
2273 biblio.biblionumber = items.biblionumber and biblioitemnumber
2277 # || die "Cannot prepare $query\n" . $dbh->errstr;
2281 $sth->execute($biblioitemnum);
2283 # || die "Cannot execute $query\n" . $sth->errstr;
2284 while ( my $data = $sth->fetchrow_hashref ) {
2285 $results[$count] = $data;
2290 return ( $count, @results );
2291 } # sub getitemsbybiblioitem
2295 # Subroutine to log changes to databases
2296 # Eventually, this subroutine will be used to create a log of all changes made,
2297 # with the possibility of "undo"ing some changes
2298 my $database = shift;
2299 if ( $database eq 'kohadb' ) {
2301 my $section = shift;
2303 my $original = shift;
2306 # print STDERR "KOHA: $type $section $item $original $new\n";
2308 elsif ( $database eq 'marc' ) {
2310 my $Record_ID = shift;
2313 my $subfield_ID = shift;
2314 my $original = shift;
2317 # print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2321 #------------------------------------------------
2323 #---------------------------------------
2324 # Find a biblio entry, or create a new one if it doesn't exist.
2325 # If a "subtitle" entry is in hash, add it to subtitle table
2326 sub getoraddbiblio {
2331 # FIXME - Unused argument
2332 $biblio, # hash ref to fields
2343 $dbh = C4::Context->dbh;
2345 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2346 $sth = $dbh->prepare( "select biblionumber
2348 where title=? and author=?
2349 and copyrightdate=? and seriestitle=?"
2352 $biblio->{title}, $biblio->{author},
2353 $biblio->{copyright}, $biblio->{seriestitle}
2356 ($biblionumber) = $sth->fetchrow;
2357 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2361 # Doesn't exist. Add new one.
2362 print "<PRE>Adding biblio</PRE>\n" if $debug;
2363 ( $biblionumber, $error ) = &newbiblio($biblio);
2364 if ($biblionumber) {
2365 print "<PRE>Added with biblio number=$biblionumber</PRE>\n"
2367 if ( $biblio->{subtitle} ) {
2368 &newsubtitle( $biblionumber, $biblio->{subtitle} );
2372 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2376 return $biblionumber, $error;
2378 } # sub getoraddbiblio
2382 # converts ISO 5426 coded string to ISO 8859-1
2383 # sloppy code : should be improved in next issue
2384 my ( $string, $encoding ) = @_;
2387 # $encoding = C4::Context->preference("marcflavour") unless $encoding;
2388 if ( $encoding eq "UNIMARC" ) {
2451 # this handles non-sorting blocks (if implementation requires this)
2452 $string = nsb_clean($_);
2454 elsif ( $encoding eq "USMARC" || $encoding eq "MARC21" ) {
2455 if (/[\xc1-\xff]/) {
2508 # this handles non-sorting blocks (if implementation requires this)
2509 $string = nsb_clean($_);
2516 my $NSB = '\x88'; # NSB : begin Non Sorting Block
2517 my $NSE = '\x89'; # NSE : Non Sorting Block end
2518 # handles non sorting blocks
2522 s/[ ]{0,1}$NSE/) /gm;
2529 my $dbh = C4::Context->dbh;
2530 my $result = MARCmarc2koha($dbh,$record,'');
2531 # search duplicate on ISBN, easy and fast...
2532 my $sth = $dbh->prepare("select biblio.biblionumber,bibid,title from biblio,biblioitems,marc_biblio where biblio.biblionumber=biblioitems.biblionumber and marc_biblio.biblionumber=biblioitems.biblionumber and isbn=?");
2533 $sth->execute($result->{'isbn'});
2534 my ($biblionumber,$bibid,$title) = $sth->fetchrow;
2535 return $biblionumber,$bibid,$title if ($biblionumber);
2536 # a more complex search : build a request for SearchMarc::catalogsearch()
2537 my (@tags, @and_or, @excluding, @operator, @value, $offset,$length);
2538 # search on biblio.title
2539 my ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblio.title","");
2540 if ($record->field($tag)) {
2541 if ($record->field($tag)->subfields($subfield)) {
2542 push @tags, "'".$tag.$subfield."'";
2543 push @and_or, "and";
2544 push @excluding, "";
2545 push @operator, "contains";
2546 push @value, $record->field($tag)->subfield($subfield);
2547 # warn "for title, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2550 # ... and on biblio.author
2551 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblio.author","");
2552 if ($record->field($tag)) {
2553 if ($record->field($tag)->subfields($subfield)) {
2554 push @tags, "'".$tag.$subfield."'";
2555 push @and_or, "and";
2556 push @excluding, "";
2557 push @operator, "contains";
2558 push @value, $record->field($tag)->subfield($subfield);
2559 # warn "for author, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2562 # ... and on publicationyear.
2563 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.publicationyear","");
2564 if ($record->field($tag)) {
2565 if ($record->field($tag)->subfields($subfield)) {
2566 push @tags, "'".$tag.$subfield."'";
2567 push @and_or, "and";
2568 push @excluding, "";
2569 push @operator, "=";
2570 push @value, $record->field($tag)->subfield($subfield);
2571 # warn "for publicationyear, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2575 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.size","");
2576 if ($record->field($tag)) {
2577 if ($record->field($tag)->subfields($subfield)) {
2578 push @tags, "'".$tag.$subfield."'";
2579 push @and_or, "and";
2580 push @excluding, "";
2581 push @operator, "=";
2582 push @value, $record->field($tag)->subfield($subfield);
2583 # warn "for size, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2586 # ... and on publisher.
2587 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.publishercode","");
2588 if ($record->field($tag)) {
2589 if ($record->field($tag)->subfields($subfield)) {
2590 push @tags, "'".$tag.$subfield."'";
2591 push @and_or, "and";
2592 push @excluding, "";
2593 push @operator, "=";
2594 push @value, $record->field($tag)->subfield($subfield);
2595 # warn "for publishercode, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2598 # ... and on volume.
2599 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.volume","");
2600 if ($record->field($tag)) {
2601 if ($record->field($tag)->subfields($subfield)) {
2602 push @tags, "'".$tag.$subfield."'";
2603 push @and_or, "and";
2604 push @excluding, "";
2605 push @operator, "=";
2606 push @value, $record->field($tag)->subfield($subfield);
2607 # warn "for volume, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2611 my ($finalresult,$nbresult) = C4::SearchMarc::catalogsearch($dbh,\@tags,\@and_or,\@excluding,\@operator,\@value,0,10);
2612 # there is at least 1 result => return the 1st one
2614 # warn "$nbresult => ".@$finalresult[0]->{biblionumber},@$finalresult[0]->{bibid},@$finalresult[0]->{title};
2615 return @$finalresult[0]->{biblionumber},@$finalresult[0]->{bibid},@$finalresult[0]->{title};
2617 # no result, returns nothing
2621 END { } # module clean-up code here (global destructor)
2627 Koha Developement team <info@koha.org>
2629 Paul POULAIN paul.poulain@free.fr
2635 # Revision 1.113 2004/12/10 16:27:53 tipaul
2636 # limiting the number of search term to 8. There was no limit before, but 8 words seems to be the upper limit mySQL can deal with (in less than a second. tested on a DB with 13 000 items)
2637 # In 2.4, a new DB structure will highly speed things and this limit will be removed.
2638 # FindDuplicate is activated again, the perf problems were due to this problem.
2640 # Revision 1.112 2004/12/08 10:14:42 tipaul
2641 # * desactivate FindDuplicate
2644 # Revision 1.111 2004/11/25 17:39:44 tipaul
2645 # removing useless &branches in package declaration
2647 # Revision 1.110 2004/11/24 16:00:01 tipaul
2648 # removing sub branches (commited by chris for MARC=OFF bugfix, but sub branches is already in Acquisition.pm)
2650 # Revision 1.109 2004/11/24 15:58:31 tipaul
2651 # * critical fix for acquisition (see RC3 release notes)
2652 # * critical fix for duplicate finder
2654 # Revision 1.108 2004/11/19 19:41:22 rangi
2655 # Shifting branches() from deprecated C4::Catalogue to C4::Biblio
2656 # Allowing the non marc interface acquisitions to work.
2658 # Revision 1.107 2004/11/05 10:15:27 tipaul
2659 # Improving FindDuplicate to find duplicate records on adding biblio
2661 # Revision 1.106 2004/11/02 16:44:45 tipaul
2662 # new feature : checking for duplicate biblio.
2664 # For instance, it's only done on ISBN only. Will be improved soon.
2666 # When a duplicate is detected, the biblio is not saved, but the user is asked for a confirmations.
2668 # Revision 1.105 2004/09/23 16:15:37 tipaul
2671 # Revision 1.104 2004/09/16 15:06:46 tipaul
2672 # enabling # (| still possible too) for repeatable subfields
2674 # Revision 1.103 2004/09/06 14:17:34 tipaul
2675 # some commented warning added + 1 major bugfix => drop empty fields, NOT fields containing 0
2677 # Revision 1.102 2004/09/06 10:00:19 tipaul
2678 # adding a "location" field to the library.
2679 # This field is useful when the callnumber contains no information on the room where the item is stored.
2680 # With this field, we now have 3 levels of informations to find a book :
2685 # This should be versatile enough to solve any storing method.
2686 # This hack is quite simple, due to the nice Biblio.pm API. The MARC => koha db link is automatically managed. Just add the link in the parameters section.
2688 # Revision 1.101 2004/08/18 16:01:37 tipaul
2689 # modifs to support frameworkcodes
2691 # Revision 1.100 2004/08/13 16:37:25 tipaul
2692 # adding frameworkcode to API in some subs
2694 # Revision 1.99 2004/07/30 13:54:50 doxulting
2695 # Beginning of serial commit
2697 # Revision 1.98 2004/07/15 09:48:10 tipaul
2698 # * removing useless sub
2699 # * minor bugfix in moditem (managing homebranch & holdingbranch)
2701 # Revision 1.97 2004/07/02 15:53:53 tipaul
2702 # bugfix (due to frameworkcode field)
2704 # Revision 1.96 2004/06/29 16:07:10 tipaul
2705 # last sync for 2.1.0 release
2707 # Revision 1.95 2004/06/26 23:19:59 rangi
2708 # Fixing modaddauthor, and adding getitemtypes.
2709 # Also tidying up formatting of code
2711 # Revision 1.94 2004/06/17 08:16:32 tipaul
2712 # merging tag & subfield in marc_word for better perfs
2714 # Revision 1.93 2004/06/11 15:38:06 joshferraro
2715 # Changes MARCaddword to index words >= 1 char ... needed for more accurate
2716 # searches using SearchMarc routines.
2718 # Revision 1.92 2004/06/10 08:29:01 tipaul
2719 # MARC authority management (continued)
2721 # Revision 1.91 2004/06/03 10:03:01 tipaul
2722 # * frameworks and itemtypes are independant
2723 # * in the MARC editor, showing the + to duplicate a tag only if the tag is repeatable
2725 # Revision 1.90 2004/05/28 08:25:53 tipaul
2726 # hidding hidden & isurl constraints into MARC subfield structure
2728 # Revision 1.89 2004/05/27 21:47:21 rangi
2731 # Revision 1.88 2004/05/18 15:23:49 tipaul
2732 # framework management : 1 MARC framework for each itemtype
2734 # Revision 1.87 2004/05/18 11:54:07 tipaul
2735 # getitemtypes moved in Koha.pm
2737 # Revision 1.86 2004/05/03 09:19:22 tipaul
2738 # some fixes for mysql prepare & execute
2740 # Revision 1.85 2004/04/02 14:55:48 tipaul
2741 # renaming items.bulk field to items.itemcallnumber.
2742 # Will be used to store call number for libraries that don't use dewey classification.
2743 # Note it's related to ITEMS, not biblio.
2745 # Revision 1.84 2004/03/24 17:18:30 joshferraro
2746 # Fixes bug 749 by removing the comma on line 1488.
2748 # Revision 1.83 2004/03/15 14:31:50 tipaul
2749 # adding a minor check
2751 # Revision 1.82 2004/03/07 05:47:31 acli
2752 # Various updates/fixes from rel_2_0
2753 # Fixes for bugs 721 (templating), 727, and 734
2755 # Revision 1.81 2004/03/06 20:26:13 tipaul
2756 # adding seealso feature in MARC searches
2758 # Revision 1.80 2004/02/12 13:40:56 tipaul
2759 # deleting subs duplicated by error
2761 # Revision 1.79 2004/02/11 08:40:09 tipaul
2762 # synch'ing 2.0.0 branch and head
2764 # Revision 1.78.2.3 2004/02/10 13:15:46 tipaul
2765 # removing 2 warnings
2767 # Revision 1.78.2.2 2004/01/26 10:38:06 tipaul
2768 # dealing correctly "bulk" field
2770 # Revision 1.78.2.1 2004/01/13 17:29:53 tipaul
2771 # * minor html fixes
2772 # * adding publisher in acquisition process (& ordering basket by publisher)
2774 # Revision 1.78 2003/12/09 15:57:28 tipaul
2775 # rolling back to working char_decode sub
2777 # Revision 1.77 2003/12/03 17:47:14 tipaul
2778 # bugfixes for biblio deletion
2780 # Revision 1.76 2003/12/03 01:43:41 slef
2783 # Revision 1.75 2003/12/03 01:42:03 slef
2784 # bug 662 fixes securing DBI
2786 # Revision 1.74 2003/11/28 09:48:33 tipaul
2787 # bugfix : misusing prepare & execute => now using prepare(?) and execute($var)
2789 # Revision 1.73 2003/11/28 09:45:25 tipaul
2790 # bugfix for iso2709 file import in the "notforloan" field.
2792 # But notforloan field called "loan" somewhere, so in case "loan" is used, copied to "notforloan" to avoid a bug.
2794 # Revision 1.72 2003/11/24 17:40:14 tipaul
2797 # Revision 1.71 2003/11/24 16:28:49 tipaul
2798 # biblio & item deletion now works fine in MARC editor.
2799 # Stores deleted biblio/item in the marc field of the deletedbiblio/deleteditem table.
2801 # Revision 1.70 2003/11/24 13:29:55 tipaul
2802 # moving $id from beginning to end of file (70 commits... huge comments...)
2804 # Revision 1.69 2003/11/24 13:27:17 tipaul
2805 # fix for #380 (bibliosubject)
2807 # Revision 1.68 2003/11/06 17:18:30 tipaul
2810 # 1st draft for MARC biblio deletion.
2811 # Still does not work well, but at least, Biblio.pm compiles & it should'nt break too many things
2812 # (Note the trash in the MARCdetail, but don't use it, please :-) )
2814 # Revision 1.67 2003/10/25 08:46:27 tipaul
2815 # minor fixes for bilbio deletion (still buggy)
2817 # Revision 1.66 2003/10/17 10:02:56 tipaul
2818 # Indexing only words longer than 2 letters. Was >=2 before, & 2 letters words usually means nothing.
2820 # Revision 1.65 2003/10/14 09:45:29 tipaul
2821 # 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)
2823 # Revision 1.64 2003/10/06 15:20:51 tipaul
2824 # fix for 536 (subtitle error)
2826 # Revision 1.63 2003/10/01 13:25:49 tipaul
2827 # seems a char encoding problem modified something in char_decode sub... changing back to something that works...
2829 # Revision 1.62 2003/09/17 14:21:13 tipaul
2830 # fixing bug that makes a MARC biblio disappear when using full acquisition (order => recieve ==> MARC editor).
2831 # Before this 2 lines fix, the MARC biblio was deleted during recieve, and had to be entirely recreated :-(
2833 # Revision 1.61 2003/09/17 10:24:39 tipaul
2834 # notforloan value in itemtype was overwritting notforloan value in a given item.
2835 # I changed this behaviour :
2836 # if notforloan is set for a given item, and NOT for all items from this itemtype, the notforloan is kept.
2837 # If notforloan is set for itemtype, it's used (and impossible to loan a specific item from this itemtype)
2839 # Revision 1.60 2003/09/04 14:11:23 tipaul
2840 # fix for 593 (data duplication in MARC-DB)
2842 # Revision 1.58 2003/08/06 12:54:52 tipaul
2843 # fix for publicationyear : extracting numeric value from MARC string, like for copyrightdate.
2844 # (note that copyrightdate still extracted to get numeric format)
2846 # Revision 1.57 2003/07/15 23:09:18 slef
2847 # change show columns to use biblioitems bnotes too
2849 # Revision 1.56 2003/07/15 11:34:52 slef
2850 # fixes from paul email
2852 # Revision 1.55 2003/07/15 00:02:49 slef
2853 # Work on bug 515... can we do a single-side rename of notes to bnotes?
2855 # Revision 1.54 2003/07/11 11:51:32 tipaul
2856 # *** empty log message ***
2858 # Revision 1.52 2003/07/10 10:37:19 tipaul
2859 # fix for copyrightdate problem, #514
2861 # Revision 1.51 2003/07/02 14:47:17 tipaul
2862 # fix for #519 : items.dateaccessioned imports incorrectly
2864 # Revision 1.49 2003/06/17 11:21:13 tipaul
2865 # improvments/fixes for z3950 support.
2866 # * Works now even on ADD, not only on MODIFY
2867 # * able to search on ISBN, author, title
2869 # Revision 1.48 2003/06/16 09:22:53 rangi
2870 # Just added an order clause to getitemtypes
2872 # Revision 1.47 2003/05/20 16:22:44 tipaul
2873 # fixing typo in Biblio.pm POD
2875 # Revision 1.46 2003/05/19 13:45:18 tipaul
2876 # support for subtitles, additional authors, subject.
2877 # 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.
2878 # Note that some OLD-DB subs are strange (dummy ?) see OLDmodsubject, OLDmodsubtitle, OLDmodaddiauthor in C4/Biblio.pm
2879 # 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.
2881 # Revision 1.45 2003/04/29 16:50:49 tipaul
2882 # really proud of this commit :-)
2883 # z3950 search and import seems to works fine.
2884 # Let me explain how :
2885 # * a "search z3950" button is added in the addbiblio template.
2886 # * when clicked, a popup appears and z3950/search.pl is called
2887 # * z3950/search.pl calls addz3950search in the DB
2888 # * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table.
2889 # * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending.
2890 # * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled
2893 # * 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.
2894 # * 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.
2896 # Revision 1.44 2003/04/28 13:07:14 tipaul
2897 # Those fixes solves the "internal server error" with MARC::Record 1.12.
2898 # It was due to an illegal contruction in Koha : we tried to retrive subfields from <10 tags.
2899 # That's not possible. MARC::Record accepted this in 0.93 version, but it was fixed after.
2900 # Now, the construct/retrieving is OK !
2902 # Revision 1.43 2003/04/10 13:56:02 tipaul
2904 # * worked in 1.9.0, but not in 1.9.1 :
2905 # - modif of a biblio didn't work
2906 # - 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.
2908 # * did not work before :
2909 # - repeatable subfields now works correctly. Enter 2 subfields separated by | and they will be splitted during saving.
2910 # - dropped the last subfield of the MARC form :-(
2912 # Internal changes :
2913 # - 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.
2914 # Note the MARCdelbiblio has been rewritted to enable deletion of a biblio WITHOUT deleting items.
2916 # Revision 1.42 2003/04/04 08:41:11 tipaul
2917 # last commits before 1.9.1
2919 # Revision 1.41 2003/04/01 12:26:43 tipaul
2922 # Revision 1.40 2003/03/11 15:14:03 tipaul
2925 # Revision 1.39 2003/03/07 16:35:42 tipaul
2926 # * moving generic functions to Koha.pm
2927 # * improvement of SearchMarc.pm
2931 # Revision 1.38 2003/02/27 16:51:59 tipaul
2932 # * moving prepare / execute to ? form.
2935 # * road to 1.9.2 => acquisition and cataloguing merging
2937 # Revision 1.37 2003/02/12 11:03:03 tipaul
2938 # Support for 000 -> 010 fields.
2939 # Those fields doesn't have subfields.
2940 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
2941 # 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.
2943 # Revision 1.36 2003/02/12 11:01:01 tipaul
2944 # Support for 000 -> 010 fields.
2945 # Those fields doesn't have subfields.
2946 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
2947 # 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.
2949 # Revision 1.35 2003/02/03 18:46:00 acli
2950 # Minor factoring in C4/Biblio.pm, plus change to export the per-tag
2951 # 'mandatory' property to a per-subfield 'tag_mandatory' template parameter,
2952 # so that addbiblio.tmpl can distinguish between mandatory subfields in a
2953 # mandatory tag and mandatory subfields in an optional tag
2955 # Not-minor factoring in acqui.simple/addbiblio.pl to make the if-else blocks
2956 # smaller, and to add some POD; need further testing for this
2958 # Added function to check if a MARC subfield name is "koha-internal" (instead
2959 # of checking it for 'lib' and 'tag' everywhere); temporarily added to Koha.pm
2961 # Use above function in acqui.simple/additem.pl and search.marc/search.pl
2963 # Revision 1.34 2003/01/28 14:50:04 tipaul
2964 # fixing MARCmodbiblio API and reindenting code
2966 # Revision 1.33 2003/01/23 12:22:37 tipaul
2967 # adding char_decode to decode MARC21 or UNIMARC extended chars
2969 # Revision 1.32 2002/12/16 15:08:50 tipaul
2970 # small but important bugfix (fixes a problem in export)
2972 # Revision 1.31 2002/12/13 16:22:04 tipaul
2973 # 1st draft of marc export
2975 # Revision 1.30 2002/12/12 21:26:35 tipaul
2976 # YAB ! (Yet Another Bugfix) => related to biblio modif
2977 # (some warning cleaning too)
2979 # Revision 1.29 2002/12/12 16:35:00 tipaul
2980 # adding authentification with Auth.pm and
2981 # MAJOR BUGFIX on marc biblio modification
2983 # Revision 1.28 2002/12/10 13:30:03 tipaul
2984 # fugfixes from Dombes Abbey work
2986 # Revision 1.27 2002/11/19 12:36:16 tipaul
2988 # various bugfixes, improvments, and migration from acquisition.pm to biblio.pm
2990 # Revision 1.26 2002/11/12 15:58:43 tipaul
2993 # * 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)
2995 # Revision 1.25 2002/10/25 10:58:26 tipaul
2997 # * bugfixes and improvements
2999 # Revision 1.24 2002/10/24 12:09:01 arensb
3000 # Fixed "no title" warning when generating HTML documentation from POD.
3002 # Revision 1.23 2002/10/16 12:43:08 arensb
3003 # Added some FIXME comments.
3005 # Revision 1.22 2002/10/15 13:39:17 tipaul
3006 # removing Acquisition.pm
3007 # deleting unused code in biblio.pm, rewriting POD and answering most FIXME comments
3009 # Revision 1.21 2002/10/13 11:34:14 arensb
3010 # Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
3011 # Thus, $x = $x+2 becomes $x += 2, and so forth.
3013 # Revision 1.20 2002/10/13 08:28:32 arensb
3014 # Deleted unused variables.
3015 # Removed trailing whitespace.
3017 # Revision 1.19 2002/10/13 05:56:10 arensb
3018 # Added some FIXME comments.
3020 # Revision 1.18 2002/10/11 12:34:53 arensb
3021 # Replaced &requireDBI with C4::Context->dbh
3023 # Revision 1.17 2002/10/10 14:48:25 tipaul
3026 # Revision 1.16 2002/10/07 14:04:26 tipaul
3027 # road to 1.3.1 : viewing MARC biblio
3029 # Revision 1.15 2002/10/05 09:49:25 arensb
3030 # Merged with arensb-context branch: use C4::Context->dbh instead of
3031 # &C4Connect, and generally prefer C4::Context over C4::Database.
3033 # Revision 1.14 2002/10/03 11:28:18 tipaul
3034 # Extending Context.pm to add stopword management and using it in MARC-API.
3035 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
3037 # Revision 1.13 2002/10/02 16:26:44 tipaul
3040 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
3041 # Merged in changes from main branch.
3043 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
3044 # Added a whole mess of FIXME comments.
3046 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
3047 # Added some missing semicolons.
3049 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
3050 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
3053 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
3054 # Added a whole mess of FIXME comments.
3056 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
3057 # Added some missing semicolons.
3059 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
3060 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
3063 # Revision 1.12 2002/10/01 11:48:51 arensb
3064 # Added some FIXME comments, mostly marking duplicate functions.
3066 # Revision 1.11 2002/09/24 13:49:26 tipaul
3067 # long WAS the road to 1.3.0...
3068 # coming VERY SOON NOW...
3069 # modifying installer and buildrelease to update the DB
3071 # Revision 1.10 2002/09/22 16:50:08 arensb
3072 # Added some FIXME comments.
3074 # Revision 1.9 2002/09/20 12:57:46 tipaul
3075 # long is the road to 1.4.0
3076 # * MARCadditem and MARCmoditem now wroks
3077 # * various bugfixes in MARC management
3078 # !!! 1.3.0 should be released very soon now. Be careful !!!
3080 # Revision 1.8 2002/09/10 13:53:52 tipaul
3081 # MARC API continued...
3083 # * 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)
3085 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
3087 # Revision 1.7 2002/08/14 18:12:51 tonnesen
3088 # Added copyright statement to all .pl and .pm files
3090 # Revision 1.6 2002/07/25 13:40:31 tipaul
3091 # pod documenting the API.
3093 # Revision 1.5 2002/07/24 16:11:37 tipaul
3095 # Database.pm and Output.pm are almost not modified (var test...)
3097 # Biblio.pm is almost completly rewritten.
3099 # WHAT DOES IT ??? ==> END of Hitchcock suspens
3101 # 1st, it does... nothing...
3102 # 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 ...
3104 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
3105 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
3106 # * 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.
3107 # * 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.
3108 # 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 ;-)
3110 # 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.
3111 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.