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
77 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
80 # all the following subs takes a MARC::Record as parameter and manage
81 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
82 # NEWxxx subs (xxx deals with old-DB parameters, the NEWxxx deals with MARC-DB parameter)
86 C4::Biblio - acquisition, catalog management functions
90 move from 1.2 to 1.4 version :
91 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
92 In the 1.4 version, we want to do 2 differents things :
93 - keep populating the old-DB, that has a LOT less datas than MARC
94 - populate the MARC-DB
95 To populate the DBs we have 2 differents sources :
96 - the standard acquisition system (through book sellers), that does'nt use MARC data
97 - the MARC acquisition system, that uses MARC data.
99 Thus, we have 2 differents cases :
100 - 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
101 - 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
103 That's why we need 4 subs :
104 all I<subs beginning by MARC> manage only MARC tables. They manage MARC-DB with MARC::Record parameters
105 all I<subs beginning by OLD> manage only OLD-DB tables. They manage old-DB with old-DB parameters
106 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
107 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.
109 - NEW and old-style API should be used in koha to manage biblio
110 - MARCsubs are divided in 2 parts :
111 * some of them manage MARC parameters. They are heavily used in koha.
112 * some of them manage MARC biblio : they are mostly used by NEW and old-style subs.
113 - OLD are used internally only
115 all subs requires/use $dbh as 1st parameter.
117 I<NEWxxx related subs>
119 all subs requires/use $dbh as 1st parameter.
120 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
122 I<OLDxxx related subs>
124 all subs requires/use $dbh as 1st parameter.
125 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
127 They all are the exact copy of 1.0/1.2 version of the sub without the OLD.
128 The OLDxxx is called by the original xxx sub.
129 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
131 WARNING : there is 1 difference between initialxxx and OLDxxx :
132 the db header $dbh is always passed as parameter to avoid over-DB connexion
138 =item @tagslib = &MARCgettagslib($dbh,1|0,$itemtype);
140 last param is 1 for liblibrarian and 0 for libopac
141 $itemtype contains the itemtype framework reference. If empty or does not exist, the default one is used
142 returns a hash with tag/subfield meaning
143 =item ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,$kohafield);
145 finds MARC tag and subfield for a given kohafield
146 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
148 =item $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
150 finds a old-db biblio number for a given MARCbibid number
152 =item $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
154 finds a MARC bibid from a old-db biblionumber
156 =item $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
158 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
160 =item $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
162 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
164 =item $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
166 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
168 =item $olddb = &MARCmarc2koha($dbh,$MARCRecord);
170 builds a hash with old-db datas from a MARC::Record
172 =item &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
174 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
176 =item &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
178 adds a subfield in a biblio (in the MARC tables only).
180 =item $MARCRecord = &MARCgetbiblio($dbh,$bibid);
182 Returns a MARC::Record for the biblio $bibid.
184 =item &MARCmodbiblio($dbh,$bibid,$record,$frameworkcode,$delete);
186 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
187 It 1st delete the biblio, then recreates it.
188 WARNING : the $delete parameter is not used anymore (too much unsolvable cases).
189 =item ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
191 MARCmodsubfield changes the value of a given subfield
193 =item $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
195 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
196 Returns -1 if more than 1 answer
198 =item $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
200 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
202 =item &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
204 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
206 =item &MARCdelbiblio($dbh,$bibid);
208 MARCdelbiblio delete biblio $bibid
210 =item &MARCkoha2marcOnefield
212 used by MARCkoha2marc and should not be useful elsewhere
214 =item &MARCmarc2kohaOnefield
216 used by MARCmarc2koha and should not be useful elsewhere
220 used to manage MARC_word table and should not be useful elsewhere
224 used to manage MARC_word table and should not be useful elsewhere
229 my ( $dbh, $forlibrarian, $frameworkcode ) = @_;
230 $frameworkcode = "" unless $frameworkcode;
232 my $libfield = ( $forlibrarian eq 1 ) ? 'liblibrarian' : 'libopac';
234 # check that framework exists
237 "select count(*) from marc_tag_structure where frameworkcode=?");
238 $sth->execute($frameworkcode);
239 my ($total) = $sth->fetchrow;
240 $frameworkcode = "" unless ( $total > 0 );
243 "select tagfield,$libfield as lib,mandatory,repeatable from marc_tag_structure where frameworkcode=? order by tagfield"
245 $sth->execute($frameworkcode);
246 my ( $lib, $tag, $res, $tab, $mandatory, $repeatable );
248 while ( ( $tag, $lib, $mandatory, $repeatable ) = $sth->fetchrow ) {
249 $res->{$tag}->{lib} = $lib;
250 $res->{$tab}->{tab} = ""; # XXX
251 $res->{$tag}->{mandatory} = $mandatory;
252 $res->{$tag}->{repeatable} = $repeatable;
257 "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"
259 $sth->execute($frameworkcode);
262 my $authorised_value;
271 ( $tag, $subfield, $lib, $tab,
272 $mandatory, $repeatable, $authorised_value, $authtypecode,
273 $value_builder, $kohafield, $seealso, $hidden,
278 $res->{$tag}->{$subfield}->{lib} = $lib;
279 $res->{$tag}->{$subfield}->{tab} = $tab;
280 $res->{$tag}->{$subfield}->{mandatory} = $mandatory;
281 $res->{$tag}->{$subfield}->{repeatable} = $repeatable;
282 $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
283 $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode;
284 $res->{$tag}->{$subfield}->{value_builder} = $value_builder;
285 $res->{$tag}->{$subfield}->{kohafield} = $kohafield;
286 $res->{$tag}->{$subfield}->{seealso} = $seealso;
287 $res->{$tag}->{$subfield}->{hidden} = $hidden;
288 $res->{$tag}->{$subfield}->{isurl} = $isurl;
293 sub MARCfind_marc_from_kohafield {
294 my ( $dbh, $kohafield,$frameworkcode ) = @_;
295 return 0, 0 unless $kohafield;
298 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
300 $sth->execute($frameworkcode,$kohafield);
301 my ( $tagfield, $tagsubfield ) = $sth->fetchrow;
302 return ( $tagfield, $tagsubfield );
305 sub MARCfind_oldbiblionumber_from_MARCbibid {
306 my ( $dbh, $MARCbibid ) = @_;
308 $dbh->prepare("select biblionumber from marc_biblio where bibid=?");
309 $sth->execute($MARCbibid);
310 my ($biblionumber) = $sth->fetchrow;
311 return $biblionumber;
314 sub MARCfind_MARCbibid_from_oldbiblionumber {
315 my ( $dbh, $oldbiblionumber ) = @_;
317 $dbh->prepare("select bibid from marc_biblio where biblionumber=?");
318 $sth->execute($oldbiblionumber);
319 my ($bibid) = $sth->fetchrow;
325 # pass the MARC::Record to this function, and it will create the records in the marc tables
326 my ($dbh,$record,$biblionumber,$frameworkcode,$bibid) = @_;
327 my @fields=$record->fields();
329 # adding main table, and retrieving bibid
330 # if bibid is sent, then it's not a true add, it's only a re-add, after a delete (ie, a mod)
331 # if bibid empty => true add, find a new bibid number
334 "lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ"
338 "insert into marc_biblio (datecreated,biblionumber,frameworkcode) values (now(),?,?)"
340 $sth->execute( $biblionumber, $frameworkcode );
341 $sth = $dbh->prepare("select max(bibid) from marc_biblio");
343 ($bibid) = $sth->fetchrow;
348 # now, add subfields...
349 foreach my $field (@fields) {
351 if ( $field->tag() < 10 ) {
352 &MARCaddsubfield( $dbh, $bibid, $field->tag(), '', $fieldcount, '',
356 my @subfields = $field->subfields();
357 foreach my $subfieldcount ( 0 .. $#subfields ) {
362 $field->indicator(1) . $field->indicator(2),
364 $subfields[$subfieldcount][0],
366 $subfields[$subfieldcount][1]
371 $dbh->do("unlock tables");
377 # pass the MARC::Record to this function, and it will create the records in the marc tables
378 my ($dbh,$record,$biblionumber) = @_;
379 # search for MARC biblionumber
380 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
381 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
382 my @fields=$record->fields();
383 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
384 $sth->execute($bibid);
385 my ($fieldcount) = $sth->fetchrow;
387 # now, add subfields...
388 foreach my $field (@fields) {
389 my @subfields = $field->subfields();
391 foreach my $subfieldcount ( 0 .. $#subfields ) {
396 $field->indicator(1) . $field->indicator(2),
398 $subfields[$subfieldcount][0],
400 $subfields[$subfieldcount][1]
404 $dbh->do("unlock tables");
408 sub MARCaddsubfield {
410 # Add a new subfield to a tag into the DB.
412 $dbh, $bibid, $tagid, $tag_indicator,
413 $tagorder, $subfieldcode, $subfieldorder, $subfieldvalues
416 # warn "$tagid / $subfieldcode / $subfieldvalues";
417 # if not value, end of job, we do nothing
418 # if ( length($subfieldvalues) == 0 ) {
421 if ( not($subfieldcode) ) {
424 my @subfieldvalues = split /\||#/, $subfieldvalues;
425 foreach my $subfieldvalue (@subfieldvalues) {
426 if ( length($subfieldvalue) > 255 ) {
428 "lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE"
432 "insert into marc_blob_subfield (subfieldvalue) values (?)");
433 $sth->execute($subfieldvalue);
435 $dbh->prepare("select max(blobidlink)from marc_blob_subfield");
437 my ($res) = $sth->fetchrow;
440 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?,?)"
442 $sth->execute( $bibid, ( sprintf "%03s", $tagid ), $tagorder,
443 $tag_indicator, $subfieldcode, $subfieldorder, $res );
445 if ( $sth->errstr ) {
447 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
449 $dbh->do("unlock tables");
454 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)"
457 $bibid, ( sprintf "%03s", $tagid ),
458 $tagorder, $tag_indicator,
459 $subfieldcode, $subfieldorder,
462 if ( $sth->errstr ) {
464 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
468 $dbh, $bibid, $tagid, $tagorder,
469 $subfieldcode, $subfieldorder, $subfieldvalue
476 # Returns MARC::Record of the biblio passed in parameter.
477 my ( $dbh, $bibid ) = @_;
478 my $record = MARC::Record->new();
480 #---- TODO : the leader is missing
481 $record->leader(' ');
484 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
485 from marc_subfield_table
486 where bibid=? order by tag,tagorder,subfieldcode
491 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
492 $sth->execute($bibid);
493 my $prevtagorder = 1;
496 my $field; # for >=10 tags
497 my $prevvalue; # for <10 tags
498 while ( my $row = $sth->fetchrow_hashref ) {
500 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
501 $sth2->execute( $row->{'valuebloblink'} );
502 my $row2 = $sth2->fetchrow_hashref;
504 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
506 if ( $row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag ) {
507 $previndicator .= " ";
508 if ( $prevtag < 10 ) {
509 $record->add_fields( ( sprintf "%03s", $prevtag ), $prevvalue )
510 unless $prevtag eq "XXX"; # ignore the 1st loop
513 $record->add_fields($field) unless $prevtag eq "XXX";
516 $prevtagorder = $row->{tagorder};
517 $prevtag = $row->{tag};
518 $previndicator = $row->{tag_indicator};
519 if ( $row->{tag} < 10 ) {
520 $prevvalue = $row->{subfieldvalue};
523 $field = MARC::Field->new(
524 ( sprintf "%03s", $prevtag ),
525 substr( $row->{tag_indicator} . ' ', 0, 1 ),
526 substr( $row->{tag_indicator} . ' ', 1, 1 ),
527 $row->{'subfieldcode'},
528 $row->{'subfieldvalue'}
533 if ( $row->{tag} < 10 ) {
534 $record->add_fields( ( sprintf "%03s", $row->{tag} ),
535 $row->{'subfieldvalue'} );
538 $field->add_subfields( $row->{'subfieldcode'},
539 $row->{'subfieldvalue'} );
541 $prevtag = $row->{tag};
542 $previndicator = $row->{tag_indicator};
546 # the last has not been included inside the loop... do it now !
547 if ( $prevtag ne "XXX" )
548 { # check that we have found something. Otherwise, prevtag is still XXX and we
549 # must return an empty record, not make MARC::Record fail because we try to
550 # create a record with XXX as field :-(
551 if ( $prevtag < 10 ) {
552 $record->add_fields( $prevtag, $prevvalue );
556 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
557 $record->add_fields($field);
565 # Returns MARC::Record of the biblio passed in parameter.
566 my ( $dbh, $bibid, $itemnumber ) = @_;
567 my $record = MARC::Record->new();
569 # search MARC tagorder
572 "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=?"
574 $sth2->execute( $bibid, $itemnumber );
575 my ($tagorder) = $sth2->fetchrow_array();
577 #---- TODO : the leader is missing
580 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
581 from marc_subfield_table
582 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
587 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
588 $sth->execute( $bibid, $tagorder );
589 while ( my $row = $sth->fetchrow_hashref ) {
590 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
591 $sth2->execute( $row->{'valuebloblink'} );
592 my $row2 = $sth2->fetchrow_hashref;
594 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
596 if ( $record->field( $row->{'tag'} ) ) {
599 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
600 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
601 if ( length( $row->{'tag'} ) < 3 ) {
602 $row->{'tag'} = "0" . $row->{'tag'};
604 $field = $record->field( $row->{'tag'} );
607 $field->add_subfields( $row->{'subfieldcode'},
608 $row->{'subfieldvalue'} );
609 $record->delete_field($field);
610 $record->add_fields($field);
614 if ( length( $row->{'tag'} ) < 3 ) {
615 $row->{'tag'} = "0" . $row->{'tag'};
618 MARC::Field->new( $row->{'tag'}, " ", " ",
619 $row->{'subfieldcode'} => $row->{'subfieldvalue'} );
620 $record->add_fields($temp);
628 my ($dbh,$bibid,$record,$frameworkcode,$delete)=@_;
629 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
630 if ($oldrecord eq $record) {
633 # 1st delete the biblio,
635 my $biblionumber = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
636 &MARCdelbiblio($dbh,$bibid,1);
637 &MARCaddbiblio($dbh,$record,$biblionumber,$frameworkcode,$bibid);
641 my ( $dbh, $bibid, $keep_items ) = @_;
643 # if the keep_item is set to 1, then all items are preserved.
644 # This flag is set when the delbiblio is called by modbiblio
645 # due to a too complex structure of MARC (repeatable fields and subfields),
646 # the best solution for a modif is to delete / recreate the record.
648 # 1st of all, copy the MARC::Record to deletedbiblio table => if a true deletion, MARC data will be kept.
649 # if deletion called before MARCmodbiblio => won't do anything, as the oldbiblionumber doesn't
650 # exist in deletedbiblio table
651 my $record = MARCgetbiblio( $dbh, $bibid );
652 my $oldbiblionumber =
653 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
655 $dbh->prepare("update deletedbiblio set marc=? where biblionumber=?");
656 $copy2deleted->execute( $record->as_usmarc(), $oldbiblionumber );
658 # now, delete in MARC tables.
659 if ( $keep_items eq 1 ) {
661 #search item field code
664 "select tagfield from marc_subfield_structure where kohafield like 'items.%'"
667 my $itemtag = $sth->fetchrow_hashref->{tagfield};
669 "delete from marc_subfield_table where bibid=$bibid and tag<>$itemtag"
672 "delete from marc_word where bibid=$bibid and not (tagsubfield like \"$itemtag%\")"
676 $dbh->do("delete from marc_biblio where bibid=$bibid");
677 $dbh->do("delete from marc_subfield_table where bibid=$bibid");
678 $dbh->do("delete from marc_word where bibid=$bibid");
684 # delete the item passed in parameter in MARC tables.
685 my ( $dbh, $bibid, $itemnumber ) = @_;
687 # my $record = MARC::Record->new();
688 # search MARC tagorder
689 my $record = MARCgetitem( $dbh, $bibid, $itemnumber );
691 $dbh->prepare("update deleteditems set marc=? where itemnumber=?");
692 $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
696 "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=?"
698 $sth2->execute( $bibid, $itemnumber );
699 my ($tagorder) = $sth2->fetchrow_array();
702 "delete from marc_subfield_table where bibid=? and tagorder=?");
703 $sth->execute( $bibid, $tagorder );
707 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
709 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
710 # if nothing to change, don't waste time...
711 if ($oldrecord eq $record) {
714 # otherwise, skip through each subfield...
715 my @fields = $record->fields();
716 # search old MARC item
717 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=?");
718 $sth2->execute($bibid,$itemnumber);
719 my ($tagorder) = $sth2->fetchrow_array();
720 foreach my $field (@fields) {
721 my $oldfield = $oldrecord->field($field->tag());
722 my @subfields=$field->subfields();
724 foreach my $subfield (@subfields) {
726 if ($oldfield eq 0 or (length($oldfield->subfield(@$subfield[0])) ==0) ) {
727 # just adding datas...
728 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
729 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
731 # modify he subfield if it's a different string
732 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
733 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
734 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
741 sub MARCmodsubfield {
743 # Subroutine changes a subfield value given a subfieldid.
744 my ( $dbh, $subfieldid, $subfieldvalue ) = @_;
745 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
748 "select valuebloblink from marc_subfield_table where subfieldid=?");
749 $sth1->execute($subfieldid);
750 my ($oldvaluebloblink) = $sth1->fetchrow;
754 # if too long, use a bloblink
755 if ( length($subfieldvalue) > 255 ) {
757 # if already a bloblink, update it, otherwise, insert a new one.
758 if ($oldvaluebloblink) {
761 "update marc_blob_subfield set subfieldvalue=? where blobidlink=?"
763 $sth->execute( $subfieldvalue, $oldvaluebloblink );
768 "insert into marc_blob_subfield (subfieldvalue) values (?)");
769 $sth->execute($subfieldvalue);
771 $dbh->prepare("select max(blobidlink) from marc_blob_subfield");
773 my ($res) = $sth->fetchrow;
776 "update marc_subfield_table set subfieldvalue=null, valuebloblink=? where subfieldid=?"
778 $sth->execute( $res, $subfieldid );
783 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
786 "update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?"
788 $sth->execute( $subfieldvalue, $subfieldid );
790 $dbh->do("unlock tables");
794 "select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?"
796 $sth->execute($subfieldid);
797 my ( $bibid, $tagid, $tagorder, $subfieldcode, $x, $subfieldorder ) =
800 &MARCdelword( $dbh, $bibid, $tagid, $tagorder, $subfieldcode,
803 $dbh, $bibid, $tagid, $tagorder,
804 $subfieldcode, $subfieldorder, $subfieldvalue
806 return ( $subfieldid, $subfieldvalue );
809 sub MARCfindsubfield {
810 my ( $dbh, $bibid, $tag, $subfieldcode, $subfieldorder, $subfieldvalue ) =
812 my $resultcounter = 0;
816 "select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
817 my @bind_values = ( $bibid, $tag, $subfieldcode );
818 if ($subfieldvalue) {
819 $query .= " and subfieldvalue=?";
820 push ( @bind_values, $subfieldvalue );
823 if ( $subfieldorder < 1 ) {
826 $query .= " and subfieldorder=?";
827 push ( @bind_values, $subfieldorder );
829 my $sti = $dbh->prepare($query);
830 $sti->execute(@bind_values);
831 while ( ($subfieldid) = $sti->fetchrow ) {
833 $lastsubfieldid = $subfieldid;
835 if ( $resultcounter > 1 ) {
837 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
838 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
842 return $lastsubfieldid;
846 sub MARCfindsubfieldid {
847 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
848 my $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
849 where bibid=? and tag=? and tagorder=?
850 and subfieldcode=? and subfieldorder=?"
852 $sth->execute( $bibid, $tag, $tagorder, $subfield, $subfieldorder );
853 my ($res) = $sth->fetchrow;
855 $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
856 where bibid=? and tag=? and tagorder=?
859 $sth->execute( $bibid, $tag, $tagorder, $subfield );
860 ($res) = $sth->fetchrow;
865 sub MARCfind_frameworkcode {
866 my ( $dbh, $bibid ) = @_;
868 $dbh->prepare("select frameworkcode from marc_biblio where bibid=?");
869 $sth->execute($bibid);
870 my ($frameworkcode) = $sth->fetchrow;
871 return $frameworkcode;
874 sub MARCdelsubfield {
876 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
877 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
878 $dbh->do( "delete from marc_subfield_table where bibid='$bibid' and
879 tag='$tag' and tagorder='$tagorder'
880 and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
885 sub MARCkoha2marcBiblio {
887 # this function builds partial MARC::Record from the old koha-DB fields
888 my ( $dbh, $biblionumber, $biblioitemnumber ) = @_;
891 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
893 my $record = MARC::Record->new();
895 #--- if bibid, then retrieve old-style koha data
896 if ( $biblionumber > 0 ) {
899 "select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
900 from biblio where biblionumber=?"
902 $sth2->execute($biblionumber);
903 my $row = $sth2->fetchrow_hashref;
905 foreach $code ( keys %$row ) {
906 if ( $row->{$code} ) {
907 &MARCkoha2marcOnefield( $sth, $record, "biblio." . $code,
913 #--- if biblioitem, then retrieve old-style koha data
914 if ( $biblioitemnumber > 0 ) {
917 " SELECT biblioitemnumber,biblionumber,volume,number,classification,
918 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
919 volumedate,volumeddesc,timestamp,illus,pages,notes AS bnotes,size,place
921 WHERE biblioitemnumber=?
924 $sth2->execute($biblioitemnumber);
925 my $row = $sth2->fetchrow_hashref;
927 foreach $code ( keys %$row ) {
928 if ( $row->{$code} ) {
929 &MARCkoha2marcOnefield( $sth, $record, "biblioitems." . $code,
935 # other fields => additional authors, subjects, subtitles
938 " SELECT author FROM additionalauthors WHERE biblionumber=?");
939 $sth2->execute($biblionumber);
940 while ( my $row = $sth2->fetchrow_hashref ) {
941 &MARCkoha2marcOnefield( $sth, $record, "additionalauthors.author",
942 $row->{'author'},'' );
945 $dbh->prepare(" SELECT subject FROM bibliosubject WHERE biblionumber=?");
946 $sth2->execute($biblionumber);
947 while ( my $row = $sth2->fetchrow_hashref ) {
948 &MARCkoha2marcOnefield( $sth, $record, "bibliosubject.subject",
949 $row->{'subject'},'' );
953 " SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?");
954 $sth2->execute($biblionumber);
955 while ( my $row = $sth2->fetchrow_hashref ) {
956 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.title",
957 $row->{'subtitle'},'' );
962 sub MARCkoha2marcItem {
964 # this function builds partial MARC::Record from the old koha-DB fields
965 my ( $dbh, $biblionumber, $itemnumber ) = @_;
967 # my $dbh=&C4Connect;
970 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
972 my $record = MARC::Record->new();
974 #--- if item, then retrieve old-style koha data
975 if ( $itemnumber > 0 ) {
977 # print STDERR "prepare $biblionumber,$itemnumber\n";
980 "SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
981 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
982 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,itemcallnumber,issues,renewals,
983 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
987 $sth2->execute($itemnumber);
988 my $row = $sth2->fetchrow_hashref;
990 foreach $code ( keys %$row ) {
991 if ( $row->{$code} ) {
992 &MARCkoha2marcOnefield( $sth, $record, "items." . $code,
1000 sub MARCkoha2marcSubtitle {
1002 # this function builds partial MARC::Record from the old koha-DB fields
1003 my ( $dbh, $bibnum, $subtitle ) = @_;
1006 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
1008 my $record = MARC::Record->new();
1009 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle",
1014 sub MARCkoha2marcOnefield {
1015 my ( $sth, $record, $kohafieldname, $value,$frameworkcode ) = @_;
1018 $sth->execute($frameworkcode,$kohafieldname);
1019 if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
1020 if ( $record->field($tagfield) ) {
1021 my $tag = $record->field($tagfield);
1023 $tag->add_subfields( $tagsubfield, $value );
1024 $record->delete_field($tag);
1025 $record->add_fields($tag);
1029 $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
1036 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
1038 my $record = MARC::Record->new();
1039 # my %subfieldlist=();
1040 my $prevvalue; # if tag <10
1041 my $field; # if tag >=10
1042 for (my $i=0; $i< @$rtags; $i++) {
1043 # rebuild MARC::Record
1044 # warn "0=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ";
1045 if (@$rtags[$i] ne $prevtag) {
1046 if ($prevtag < 10) {
1048 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
1052 $record->add_fields($field);
1055 $indicators{@$rtags[$i]}.=' ';
1056 if (@$rtags[$i] <10) {
1057 $prevvalue= @$rvalues[$i];
1059 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
1060 # warn "1=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
1062 $prevtag = @$rtags[$i];
1064 if (@$rtags[$i] <10) {
1065 $prevvalue=@$rvalues[$i];
1067 if (length(@$rvalues[$i])>0) {
1068 $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
1069 # warn "2=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
1072 $prevtag= @$rtags[$i];
1075 # the last has not been included inside the loop... do it now !
1076 $record->add_fields($field);
1077 # warn "HTML2MARC=".$record->as_formatted;
1082 my ($dbh,$record,$frameworkcode) = @_;
1083 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?");
1085 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
1088 while (($field)=$sth2->fetchrow) {
1089 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result,$frameworkcode);
1091 $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
1093 while (($field)=$sth2->fetchrow) {
1094 if ($field eq 'notes') { $field = 'bnotes'; }
1095 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result,$frameworkcode);
1097 $sth2=$dbh->prepare("SHOW COLUMNS from items");
1099 while (($field)=$sth2->fetchrow) {
1100 $result=&MARCmarc2kohaOneField($sth,"items",$field,$record,$result,$frameworkcode);
1102 # additional authors : specific
1103 $result = &MARCmarc2kohaOneField($sth,"bibliosubtitle","subtitle",$record,$result,$frameworkcode);
1104 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result,$frameworkcode);
1105 # modify copyrightdate to keep only the 1st year found
1106 my $temp = $result->{'copyrightdate'};
1107 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1109 $result->{'copyrightdate'} = $1;
1110 } else { # if no cYYYY, get the 1st date.
1111 $temp =~ m/(\d\d\d\d)/;
1112 $result->{'copyrightdate'} = $1;
1114 # modify publicationyear to keep only the 1st year found
1115 my $temp = $result->{'publicationyear'};
1116 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1118 $result->{'publicationyear'} = $1;
1119 } else { # if no cYYYY, get the 1st date.
1120 $temp =~ m/(\d\d\d\d)/;
1121 $result->{'publicationyear'} = $1;
1126 sub MARCmarc2kohaOneField {
1128 # FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
1129 my ( $sth, $kohatable, $kohafield, $record, $result,$frameworkcode ) = @_;
1130 # warn "kohatable / $kohafield / $result / ";
1134 $sth->execute($frameworkcode, $kohatable . "." . $kohafield );
1135 ( $tagfield, $subfield ) = $sth->fetchrow;
1136 foreach my $field ( $record->field($tagfield) ) {
1137 if ( $field->subfield($subfield) ) {
1138 if ( $result->{$kohafield} ) {
1139 $result->{$kohafield} .= " | " . $field->subfield($subfield);
1142 $result->{$kohafield} = $field->subfield($subfield);
1146 # warn "OneField for $kohatable.$kohafield and $frameworkcode=> $tagfield, $subfield";
1152 # split a subfield string and adds it into the word table.
1155 $dbh, $bibid, $tag, $tagorder,
1156 $subfieldid, $subfieldorder, $sentence
1159 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\})/ /g;
1160 my @words = split / /, $sentence;
1161 my $stopwords = C4::Context->stopwords;
1164 "insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word)
1165 values (?,concat(?,?),?,?,?,soundex(?))"
1167 foreach my $word (@words) {
1168 # we record only words one char long and not in stopwords hash
1169 if (length($word)>=1 and !($stopwords->{uc($word)})) {
1170 $sth->execute($bibid,$tag,$subfieldid,$tagorder,$subfieldorder,$word,$word);
1172 warn "ERROR ==> insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word) values ($bibid,concat($tag,$subfieldid),$tagorder,$subfieldorder,$word,soundex($word))\n";
1180 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
1181 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
1184 "delete from marc_word where bibid=? and tagsubfield=concat(?,?) and tagorder=? and subfieldorder=?"
1186 $sth->execute( $bibid, $tag, $subfield, $tagorder, $subfieldorder );
1191 # NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW
1194 # all the following subs are useful to manage MARC-DB with complete MARC records.
1195 # it's used with marcimport, and marc management tools
1198 =item ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
1200 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
1201 are builded from the MARC::Record. If they are passed, they are used.
1203 =item NEWnewitem($dbh, $record,$bibid);
1205 adds an item in the db.
1210 my ( $dbh, $record, $frameworkcode ) = @_;
1213 my $olddata = MARCmarc2koha( $dbh, $record,$frameworkcode );
1214 $oldbibnum = OLDnewbiblio( $dbh, $olddata );
1215 $olddata->{'biblionumber'} = $oldbibnum;
1216 $oldbibitemnum = OLDnewbiblioitem( $dbh, $olddata );
1218 # search subtiles, addiauthors and subjects
1219 my ( $tagfield, $tagsubfield ) =
1220 MARCfind_marc_from_kohafield( $dbh, "additionalauthors.author",$frameworkcode );
1221 my @addiauthfields = $record->field($tagfield);
1222 foreach my $addiauthfield (@addiauthfields) {
1223 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1224 foreach my $subfieldcount ( 0 .. $#addiauthsubfields ) {
1225 OLDmodaddauthor( $dbh, $oldbibnum,
1226 $addiauthsubfields[$subfieldcount] );
1229 ( $tagfield, $tagsubfield ) =
1230 MARCfind_marc_from_kohafield( $dbh, "bibliosubtitle.title",$frameworkcode );
1231 my @subtitlefields = $record->field($tagfield);
1232 foreach my $subtitlefield (@subtitlefields) {
1233 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1234 foreach my $subfieldcount ( 0 .. $#subtitlesubfields ) {
1235 OLDnewsubtitle( $dbh, $oldbibnum,
1236 $subtitlesubfields[$subfieldcount] );
1239 ( $tagfield, $tagsubfield ) =
1240 MARCfind_marc_from_kohafield( $dbh, "bibliosubject.subject",$frameworkcode );
1241 my @subj = $record->field($tagfield);
1243 foreach my $subject (@subj) {
1244 my @subjsubfield = $subject->subfield($tagsubfield);
1245 foreach my $subfieldcount ( 0 .. $#subjsubfield ) {
1246 push @subjects, $subjsubfield[$subfieldcount];
1249 OLDmodsubject( $dbh, $oldbibnum, 1, @subjects );
1251 # we must add bibnum and bibitemnum in MARC::Record...
1252 # we build the new field with biblionumber and biblioitemnumber
1253 # we drop the original field
1254 # we add the new builded field.
1255 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
1256 # (steve and paul : thinks 090 is a good choice)
1259 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
1261 $sth->execute("biblio.biblionumber");
1262 ( my $tagfield1, my $tagsubfield1 ) = $sth->fetchrow;
1263 $sth->execute("biblioitems.biblioitemnumber");
1264 ( my $tagfield2, my $tagsubfield2 ) = $sth->fetchrow;
1265 if ( $tagfield1 != $tagfield2 ) {
1267 "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1269 "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1272 my $newfield = MARC::Field->new(
1273 $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
1274 "$tagsubfield2" => $oldbibitemnum
1277 # drop old field and create new one...
1278 my $old_field = $record->field($tagfield1);
1279 $record->delete_field($old_field);
1280 $record->add_fields($newfield);
1281 my $bibid = MARCaddbiblio( $dbh, $record, $oldbibnum, $frameworkcode );
1282 return ( $bibid, $oldbibnum, $oldbibitemnum );
1286 my ($dbh,$record,$bibid,$frameworkcode) =@_;
1287 $frameworkcode="" unless $frameworkcode;
1288 &MARCmodbiblio($dbh,$bibid,$record,$frameworkcode,0);
1289 my $oldbiblio = MARCmarc2koha($dbh,$record,$frameworkcode);
1290 my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
1291 OLDmodbibitem($dbh,$oldbiblio);
1292 # now, modify addi authors, subject, addititles.
1293 my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"additionalauthors.author",$frameworkcode);
1294 my @addiauthfields = $record->field($tagfield);
1295 foreach my $addiauthfield (@addiauthfields) {
1296 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1297 foreach my $subfieldcount (0..$#addiauthsubfields) {
1298 OLDmodaddauthor($dbh,$oldbiblionumber,$addiauthsubfields[$subfieldcount]);
1301 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubtitle.subtitle",$frameworkcode);
1302 my @subtitlefields = $record->field($tagfield);
1303 foreach my $subtitlefield (@subtitlefields) {
1304 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1305 foreach my $subfieldcount (0..$#subtitlesubfields) {
1306 OLDmodsubtitle($dbh,$oldbiblionumber,$subtitlesubfields[$subfieldcount]);
1309 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject",$frameworkcode);
1310 my @subj = $record->field($tagfield);
1312 foreach my $subject (@subj) {
1313 my @subjsubfield = $subject->subfield($tagsubfield);
1314 foreach my $subfieldcount (0..$#subjsubfield) {
1315 push @subjects,$subjsubfield[$subfieldcount];
1318 OLDmodsubject($dbh,$oldbiblionumber,1,@subjects);
1323 my ( $dbh, $bibid ) = @_;
1324 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1325 &OLDdelbiblio( $dbh, $biblio );
1328 "select biblioitemnumber from biblioitems where biblionumber=?");
1329 $sth->execute($biblio);
1330 while ( my ($biblioitemnumber) = $sth->fetchrow ) {
1331 OLDdeletebiblioitem( $dbh, $biblioitemnumber );
1333 &MARCdelbiblio( $dbh, $bibid, 0 );
1337 my ( $dbh, $record, $bibid ) = @_;
1339 # add item in old-DB
1340 my $frameworkcode=MARCfind_frameworkcode($dbh,$bibid);
1341 my $item = &MARCmarc2koha( $dbh, $record,$frameworkcode );
1342 # needs old biblionumber and biblioitemnumber
1343 $item->{'biblionumber'} =
1344 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1347 "select biblioitemnumber from biblioitems where biblionumber=?");
1348 $sth->execute( $item->{'biblionumber'} );
1349 ( $item->{'biblioitemnumber'} ) = $sth->fetchrow;
1350 my ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, $item->{barcode} );
1352 # add itemnumber to MARC::Record before adding the item.
1355 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
1357 &MARCkoha2marcOnefield( $sth, $record, "items.itemnumber", $itemnumber,$frameworkcode );
1360 my $bib = &MARCadditem( $dbh, $record, $item->{'biblionumber'} );
1364 my ( $dbh, $record, $bibid, $itemnumber, $delete ) = @_;
1366 &MARCmoditem( $dbh, $record, $bibid, $itemnumber, $delete );
1367 my $frameworkcode=MARCfind_frameworkcode($dbh,$bibid);
1368 my $olditem = MARCmarc2koha( $dbh, $record,$frameworkcode );
1369 OLDmoditem( $dbh, $olditem );
1373 my ( $dbh, $bibid, $itemnumber ) = @_;
1374 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1375 &OLDdelitem( $dbh, $itemnumber );
1376 &MARCdelitem( $dbh, $bibid, $itemnumber );
1381 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
1385 =item $biblionumber = OLDnewbiblio($dbh,$biblio);
1387 adds a record in biblio table. Datas are in the hash $biblio.
1389 =item $biblionumber = OLDmodbiblio($dbh,$biblio);
1391 modify a record in biblio table. Datas are in the hash $biblio.
1393 =item OLDmodsubtitle($dbh,$bibnum,$subtitle);
1395 modify subtitles in bibliosubtitle table.
1397 =item OLDmodaddauthor($dbh,$bibnum,$author);
1399 adds or modify additional authors
1400 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1402 =item $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1404 modify/adds subjects
1406 =item OLDmodbibitem($dbh, $biblioitem);
1410 =item OLDmodnote($dbh,$bibitemnum,$note
1412 modify a note for a biblioitem
1414 =item OLDnewbiblioitem($dbh,$biblioitem);
1416 adds a biblioitem ($biblioitem is a hash with the values)
1418 =item OLDnewsubject($dbh,$bibnum);
1422 =item OLDnewsubtitle($dbh,$bibnum,$subtitle);
1424 create a new subtitle
1426 =item ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1428 create a item. $item is a hash and $barcode the barcode.
1430 =item OLDmoditem($dbh,$item);
1434 =item OLDdelitem($dbh,$itemnum);
1438 =item OLDdeletebiblioitem($dbh,$biblioitemnumber);
1440 deletes a biblioitem
1441 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1443 =item OLDdelbiblio($dbh,$biblio);
1450 my ( $dbh, $biblio ) = @_;
1452 # my $dbh = &C4Connect;
1453 my $sth = $dbh->prepare("Select max(biblionumber) from biblio");
1455 my $data = $sth->fetchrow_arrayref;
1456 my $bibnum = $$data[0] + 1;
1459 if ( $biblio->{'seriestitle'} ) { $series = 1 }
1463 "insert into biblio set biblionumber = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?"
1466 $bibnum, $biblio->{'title'},
1467 $biblio->{'author'}, $biblio->{'copyrightdate'},
1468 $biblio->{'serial'}, $biblio->{'seriestitle'},
1469 $biblio->{'notes'}, $biblio->{'abstract'}
1479 my ( $dbh, $biblio ) = @_;
1481 # my $dbh = C4Connect;
1488 "Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?, seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?"
1491 $biblio->{'title'}, $biblio->{'author'},
1492 $biblio->{'abstract'}, $biblio->{'copyrightdate'},
1493 $biblio->{'seriestitle'}, $biblio->{'serial'},
1494 $biblio->{'unititle'}, $biblio->{'notes'},
1495 $biblio->{'biblionumber'}
1499 return ( $biblio->{'biblionumber'} );
1502 sub OLDmodsubtitle {
1503 my ( $dbh, $bibnum, $subtitle ) = @_;
1506 "update bibliosubtitle set subtitle = ? where biblionumber = ?");
1507 $sth->execute( $subtitle, $bibnum );
1511 sub OLDmodaddauthor {
1512 my ( $dbh, $bibnum, @authors ) = @_;
1514 # my $dbh = C4Connect;
1516 $dbh->prepare("Delete from additionalauthors where biblionumber = ?");
1518 $sth->execute($bibnum);
1520 foreach my $author (@authors) {
1521 if ( $author ne '' ) {
1524 "Insert into additionalauthors set author = ?, biblionumber = ?"
1527 $sth->execute( $author, $bibnum );
1532 } # sub modaddauthor
1535 my ( $dbh, $bibnum, $force, @subject ) = @_;
1537 # my $dbh = C4Connect;
1538 my $count = @subject;
1540 for ( my $i = 0 ; $i < $count ; $i++ ) {
1541 $subject[$i] =~ s/^ //g;
1542 $subject[$i] =~ s/ $//g;
1545 "select * from catalogueentry where entrytype = 's' and catalogueentry = ?"
1547 $sth->execute( $subject[$i] );
1549 if ( my $data = $sth->fetchrow_hashref ) {
1552 if ( $force eq $subject[$i] || $force == 1 ) {
1554 # subject not in aut, chosen to force anway
1555 # so insert into cataloguentry so its in auth file
1558 "Insert into catalogueentry (entrytype,catalogueentry) values ('s',?)"
1561 $sth2->execute( $subject[$i] ) if ( $subject[$i] );
1566 "$subject[$i]\n does not exist in the subject authority file";
1569 "Select * from catalogueentry where entrytype = 's' and (catalogueentry like ? or catalogueentry like ? or catalogueentry like ?)"
1571 $sth2->execute( "$subject[$i] %", "% $subject[$i] %",
1573 while ( my $data = $sth2->fetchrow_hashref ) {
1574 $error .= "<br>$data->{'catalogueentry'}";
1581 if ( $error eq '' ) {
1583 $dbh->prepare("Delete from bibliosubject where biblionumber = ?");
1584 $sth->execute($bibnum);
1588 "Insert into bibliosubject (subject,biblionumber) values (?,?)");
1590 foreach $query (@subject) {
1591 $sth->execute( $query, $bibnum ) if ( $query && $bibnum );
1601 my ( $dbh, $biblioitem ) = @_;
1603 # my $dbh = C4Connect;
1606 $biblioitem->{'itemtype'} = $dbh->quote( $biblioitem->{'itemtype'} );
1607 $biblioitem->{'url'} = $dbh->quote( $biblioitem->{'url'} );
1608 $biblioitem->{'isbn'} = $dbh->quote( $biblioitem->{'isbn'} );
1609 $biblioitem->{'publishercode'} =
1610 $dbh->quote( $biblioitem->{'publishercode'} );
1611 $biblioitem->{'publicationyear'} =
1612 $dbh->quote( $biblioitem->{'publicationyear'} );
1613 $biblioitem->{'classification'} =
1614 $dbh->quote( $biblioitem->{'classification'} );
1615 $biblioitem->{'dewey'} = $dbh->quote( $biblioitem->{'dewey'} );
1616 $biblioitem->{'subclass'} = $dbh->quote( $biblioitem->{'subclass'} );
1617 $biblioitem->{'illus'} = $dbh->quote( $biblioitem->{'illus'} );
1618 $biblioitem->{'pages'} = $dbh->quote( $biblioitem->{'pages'} );
1619 $biblioitem->{'volumeddesc'} = $dbh->quote( $biblioitem->{'volumeddesc'} );
1620 $biblioitem->{'bnotes'} = $dbh->quote( $biblioitem->{'bnotes'} );
1621 $biblioitem->{'size'} = $dbh->quote( $biblioitem->{'size'} );
1622 $biblioitem->{'place'} = $dbh->quote( $biblioitem->{'place'} );
1624 $query = "Update biblioitems set
1625 itemtype = $biblioitem->{'itemtype'},
1626 url = $biblioitem->{'url'},
1627 isbn = $biblioitem->{'isbn'},
1628 publishercode = $biblioitem->{'publishercode'},
1629 publicationyear = $biblioitem->{'publicationyear'},
1630 classification = $biblioitem->{'classification'},
1631 dewey = $biblioitem->{'dewey'},
1632 subclass = $biblioitem->{'subclass'},
1633 illus = $biblioitem->{'illus'},
1634 pages = $biblioitem->{'pages'},
1635 volumeddesc = $biblioitem->{'volumeddesc'},
1636 notes = $biblioitem->{'bnotes'},
1637 size = $biblioitem->{'size'},
1638 place = $biblioitem->{'place'}
1639 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1642 if ( $dbh->errstr ) {
1650 my ( $dbh, $bibitemnum, $note ) = @_;
1652 # my $dbh=C4Connect;
1653 my $query = "update biblioitems set notes='$note' where
1654 biblioitemnumber='$bibitemnum'";
1655 my $sth = $dbh->prepare($query);
1662 sub OLDnewbiblioitem {
1663 my ( $dbh, $biblioitem ) = @_;
1665 # my $dbh = C4Connect;
1666 my $sth = $dbh->prepare("Select max(biblioitemnumber) from biblioitems");
1671 $data = $sth->fetchrow_arrayref;
1672 $bibitemnum = $$data[0] + 1;
1676 $sth = $dbh->prepare( "insert into biblioitems set
1677 biblioitemnumber = ?, biblionumber = ?,
1678 volume = ?, number = ?,
1679 classification = ?, itemtype = ?,
1681 issn = ?, dewey = ?,
1682 subclass = ?, publicationyear = ?,
1683 publishercode = ?, volumedate = ?,
1684 volumeddesc = ?, illus = ?,
1685 pages = ?, notes = ?,
1687 marc = ?, place = ?"
1690 $bibitemnum, $biblioitem->{'biblionumber'},
1691 $biblioitem->{'volume'}, $biblioitem->{'number'},
1692 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
1693 $biblioitem->{'url'}, $biblioitem->{'isbn'},
1694 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
1695 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
1696 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
1697 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
1698 $biblioitem->{'pages'}, $biblioitem->{'bnotes'},
1699 $biblioitem->{'size'}, $biblioitem->{'lccn'},
1700 $biblioitem->{'marc'}, $biblioitem->{'place'}
1705 return ($bibitemnum);
1709 my ( $dbh, $bibnum ) = @_;
1711 $dbh->prepare("insert into bibliosubject (biblionumber) values (?)");
1712 $sth->execute($bibnum);
1716 sub OLDnewsubtitle {
1717 my ( $dbh, $bibnum, $subtitle ) = @_;
1720 "insert into bibliosubtitle set biblionumber = ?, subtitle = ?");
1721 $sth->execute( $bibnum, $subtitle );
1726 my ( $dbh, $item, $barcode ) = @_;
1728 # my $dbh = C4Connect;
1729 my $sth = $dbh->prepare("Select max(itemnumber) from items");
1735 $data = $sth->fetchrow_hashref;
1736 $itemnumber = $data->{'max(itemnumber)'} + 1;
1739 # FIXME the "notforloan" field seems to be named "loan" in some places. workaround bugfix.
1740 if ( $item->{'loan'} ) {
1741 $item->{'notforloan'} = $item->{'loan'};
1744 # if dateaccessioned is provided, use it. Otherwise, set to NOW()
1745 if ( $item->{'dateaccessioned'} ) {
1746 $sth = $dbh->prepare( "Insert into items set
1747 itemnumber = ?, biblionumber = ?,
1748 biblioitemnumber = ?, barcode = ?,
1749 booksellerid = ?, dateaccessioned = ?,
1750 homebranch = ?, holdingbranch = ?,
1751 price = ?, replacementprice = ?,
1752 replacementpricedate = NOW(), itemnotes = ?,
1753 itemcallnumber =?, notforloan = ?,
1758 $itemnumber, $item->{'biblionumber'},
1759 $item->{'biblioitemnumber'}, $barcode,
1760 $item->{'booksellerid'}, $item->{'dateaccessioned'},
1761 $item->{'homebranch'}, $item->{'holdingbranch'},
1762 $item->{'price'}, $item->{'replacementprice'},
1763 $item->{'itemnotes'}, $item->{'itemcallnumber'},
1764 $item->{'notforloan'}, $item->{'location'}
1768 $sth = $dbh->prepare( "Insert into items set
1769 itemnumber = ?, biblionumber = ?,
1770 biblioitemnumber = ?, barcode = ?,
1771 booksellerid = ?, dateaccessioned = NOW(),
1772 homebranch = ?, holdingbranch = ?,
1773 price = ?, replacementprice = ?,
1774 replacementpricedate = NOW(), itemnotes = ?,
1775 itemcallnumber = ? , notforloan = ?,
1780 $itemnumber, $item->{'biblionumber'},
1781 $item->{'biblioitemnumber'}, $barcode,
1782 $item->{'booksellerid'}, $item->{'homebranch'},
1783 $item->{'holdingbranch'}, $item->{'price'},
1784 $item->{'replacementprice'}, $item->{'itemnotes'},
1785 $item->{'itemcallnumber'}, $item->{'notforloan'},
1789 if ( defined $sth->errstr ) {
1790 $error .= $sth->errstr;
1793 return ( $itemnumber, $error );
1797 my ( $dbh, $item ) = @_;
1799 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1800 # my $dbh=C4Connect;
1801 $item->{'itemnum'} = $item->{'itemnumber'} unless $item->{'itemnum'};
1802 my $query = "update items set barcode=?,itemnotes=?,itemcallnumber=?,notforloan=? where itemnumber=?";
1804 $item->{'barcode'}, $item->{'notes'},
1805 $item->{'itemcallnumber'}, $item->{'notforloan'},
1808 if ( $item->{'barcode'} eq '' ) {
1809 $item->{'notforloan'} = 0 unless $item->{'notforloan'};
1810 $query = "update items set notforloan=? where itemnumber=?";
1811 @bind = ( $item->{'notforloan'}, $item->{'itemnum'} );
1813 if ( $item->{'lost'} ne '' ) {
1814 $query = "update items set biblioitemnumber=?,
1824 $item->{'bibitemnum'}, $item->{'barcode'},
1825 $item->{'notes'}, $item->{'homebranch'},
1826 $item->{'lost'}, $item->{'wthdrawn'},
1827 $item->{'itemcallnumber'}, $item->{'notforloan'},
1828 $item->{'location'}, $item->{'itemnum'}
1830 if ($item->{homebranch}) {
1831 $query.=",homebranch=?";
1832 push @bind, $item->{homebranch};
1834 if ($item->{holdingbranch}) {
1835 $query.=",holdingbranch=?";
1836 push @bind, $item->{holdingbranch};
1838 $query.=" where itemnumber=?";
1840 if ( $item->{'replacement'} ne '' ) {
1841 $query =~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1843 my $sth = $dbh->prepare($query);
1844 $sth->execute(@bind);
1851 my ( $dbh, $itemnum ) = @_;
1853 # my $dbh=C4Connect;
1854 my $sth = $dbh->prepare("select * from items where itemnumber=?");
1855 $sth->execute($itemnum);
1856 my $data = $sth->fetchrow_hashref;
1858 my $query = "Insert into deleteditems set ";
1860 foreach my $temp ( keys %$data ) {
1861 $query .= "$temp = ?,";
1862 push ( @bind, $data->{$temp} );
1867 $sth = $dbh->prepare($query);
1868 $sth->execute(@bind);
1870 $sth = $dbh->prepare("Delete from items where itemnumber=?");
1871 $sth->execute($itemnum);
1877 sub OLDdeletebiblioitem {
1878 my ( $dbh, $biblioitemnumber ) = @_;
1880 # my $dbh = C4Connect;
1881 my $sth = $dbh->prepare( "Select * from biblioitems
1882 where biblioitemnumber = ?"
1886 $sth->execute($biblioitemnumber);
1888 if ( $results = $sth->fetchrow_hashref ) {
1892 "Insert into deletedbiblioitems (biblioitemnumber, biblionumber, volume, number, classification, itemtype,
1893 isbn, issn ,dewey ,subclass ,publicationyear ,publishercode ,volumedate ,volumeddesc ,timestamp ,illus ,
1894 pages ,notes ,size ,url ,lccn ) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
1898 $results->{biblioitemnumber}, $results->{biblionumber},
1899 $results->{volume}, $results->{number},
1900 $results->{classification}, $results->{itemtype},
1901 $results->{isbn}, $results->{issn},
1902 $results->{dewey}, $results->{subclass},
1903 $results->{publicationyear}, $results->{publishercode},
1904 $results->{volumedate}, $results->{volumeddesc},
1905 $results->{timestamp}, $results->{illus},
1906 $results->{pages}, $results->{notes},
1907 $results->{size}, $results->{url},
1911 $dbh->prepare("Delete from biblioitems where biblioitemnumber = ?");
1912 $sth2->execute($biblioitemnumber);
1917 # Now delete all the items attached to the biblioitem
1918 $sth = $dbh->prepare("Select * from items where biblioitemnumber = ?");
1919 $sth->execute($biblioitemnumber);
1921 while ( my $data = $sth->fetchrow_hashref ) {
1922 my $query = "Insert into deleteditems set ";
1924 foreach my $temp ( keys %$data ) {
1925 $query .= "$temp = ?,";
1926 push ( @bind, $data->{$temp} );
1929 my $sth2 = $dbh->prepare($query);
1930 $sth2->execute(@bind);
1933 $sth = $dbh->prepare("Delete from items where biblioitemnumber = ?");
1934 $sth->execute($biblioitemnumber);
1938 } # sub deletebiblioitem
1941 my ( $dbh, $biblio ) = @_;
1942 my $sth = $dbh->prepare("select * from biblio where biblionumber=?");
1943 $sth->execute($biblio);
1944 if ( my $data = $sth->fetchrow_hashref ) {
1946 my $query = "Insert into deletedbiblio set ";
1948 foreach my $temp ( keys %$data ) {
1949 $query .= "$temp = ?,";
1950 push ( @bind, $data->{$temp} );
1953 #replacing the last , by ",?)"
1955 $sth = $dbh->prepare($query);
1956 $sth->execute(@bind);
1958 $sth = $dbh->prepare("Delete from biblio where biblionumber=?");
1959 $sth->execute($biblio);
1973 my $dbh = C4::Context->dbh;
1976 my $sth = $dbh->prepare("Select count(*) from items where biblionumber=?");
1977 $sth->execute($biblio);
1978 my $data = $sth->fetchrow_hashref;
1980 return ( $data->{'count(*)'} );
1985 my $dbh = C4::Context->dbh;
1986 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 );
2092 ################################################################
2093 ## Fix template and shift this to newbiblio
2094 my @subjects = split ( /\n/, $biblioitem->{'subjectheadings'} );
2095 modsubject( $biblioitem->{'biblionumber'}, 1, @subjects );
2097 ################################################################
2099 MARCkoha2marcBiblio( $dbh, 0, $bibitemnum )
2100 ; # the 0 means "do NOT retrieve biblio, only biblioitem, in the MARC record
2102 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh,
2103 $biblioitem->{biblionumber} );
2104 &MARCaddbiblio( $dbh, $MARCbiblio, $biblioitem->{biblionumber}, $bibid );
2105 return ($bibitemnum);
2110 my $dbh = C4::Context->dbh;
2111 &OLDnewsubject( $dbh, $bibnum );
2115 my ( $bibnum, $subtitle ) = @_;
2116 my $dbh = C4::Context->dbh;
2117 &OLDnewsubtitle( $dbh, $bibnum, $subtitle );
2121 my ( $item, @barcodes ) = @_;
2122 my $dbh = C4::Context->dbh;
2126 foreach my $barcode (@barcodes) {
2127 ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, uc($barcode) );
2130 &MARCkoha2marcItem( $dbh, $item->{biblionumber}, $itemnumber );
2131 &MARCadditem( $dbh, $MARCitem, $item->{biblionumber} );
2138 my $dbh = C4::Context->dbh;
2139 &OLDmoditem( $dbh, $item );
2141 &MARCkoha2marcItem( $dbh, $item->{'biblionumber'}, $item->{'itemnum'} );
2143 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $item->{biblionumber} );
2144 &MARCmoditem( $dbh, $MARCitem, $bibid, $item->{itemnum}, 0 );
2148 my ( $count, @barcodes ) = @_;
2149 my $dbh = C4::Context->dbh;
2151 my $sth = $dbh->prepare("Select * from items where barcode=?");
2152 for ( my $i = 0 ; $i < $count ; $i++ ) {
2153 $barcodes[$i] = uc $barcodes[$i];
2154 $sth->execute( $barcodes[$i] );
2155 if ( my $data = $sth->fetchrow_hashref ) {
2156 $error .= " Duplicate Barcode: $barcodes[$i]";
2164 my ($bibitemnum) = @_;
2165 my $dbh = C4::Context->dbh;
2168 $dbh->prepare("Select count(*) from items where biblioitemnumber=?");
2169 $sth->execute($bibitemnum);
2170 my $data = $sth->fetchrow_hashref;
2172 return ( $data->{'count(*)'} );
2177 my $dbh = C4::Context->dbh;
2178 &OLDdelitem( $dbh, $itemnum );
2181 sub deletebiblioitem {
2182 my ($biblioitemnumber) = @_;
2183 my $dbh = C4::Context->dbh;
2184 &OLDdeletebiblioitem( $dbh, $biblioitemnumber );
2185 } # sub deletebiblioitem
2189 my $dbh = C4::Context->dbh;
2190 &OLDdelbiblio( $dbh, $biblio );
2191 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $biblio );
2192 &MARCdelbiblio( $dbh, $bibid, 0 );
2196 my ($biblionumber) = @_;
2197 my $dbh = C4::Context->dbh;
2198 my $sth = $dbh->prepare("Select * from biblio where biblionumber = ?");
2200 # || die "Cannot prepare $query\n" . $dbh->errstr;
2204 $sth->execute($biblionumber);
2206 # || die "Cannot execute $query\n" . $sth->errstr;
2207 while ( my $data = $sth->fetchrow_hashref ) {
2208 $results[$count] = $data;
2213 return ( $count, @results );
2217 my ($biblioitemnum) = @_;
2218 my $dbh = C4::Context->dbh;
2219 my $sth = $dbh->prepare( "Select * from biblioitems where
2220 biblioitemnumber = ?"
2225 $sth->execute($biblioitemnum);
2227 while ( my $data = $sth->fetchrow_hashref ) {
2228 $results[$count] = $data;
2233 return ( $count, @results );
2234 } # sub getbiblioitem
2236 sub getbiblioitembybiblionumber {
2237 my ($biblionumber) = @_;
2238 my $dbh = C4::Context->dbh;
2239 my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?");
2243 $sth->execute($biblionumber);
2245 while ( my $data = $sth->fetchrow_hashref ) {
2246 $results[$count] = $data;
2251 return ( $count, @results );
2255 my $dbh = C4::Context->dbh;
2256 my $query = "select * from itemtypes order by description";
2257 my $sth = $dbh->prepare($query);
2259 # || die "Cannot prepare $query" . $dbh->errstr;
2265 # || die "Cannot execute $query\n" . $sth->errstr;
2266 while ( my $data = $sth->fetchrow_hashref ) {
2267 $results[$count] = $data;
2272 return ( $count, @results );
2273 } # sub getitemtypes
2275 sub getitemsbybiblioitem {
2276 my ($biblioitemnum) = @_;
2277 my $dbh = C4::Context->dbh;
2278 my $sth = $dbh->prepare( "Select * from items, biblio where
2279 biblio.biblionumber = items.biblionumber and biblioitemnumber
2283 # || die "Cannot prepare $query\n" . $dbh->errstr;
2287 $sth->execute($biblioitemnum);
2289 # || die "Cannot execute $query\n" . $sth->errstr;
2290 while ( my $data = $sth->fetchrow_hashref ) {
2291 $results[$count] = $data;
2296 return ( $count, @results );
2297 } # sub getitemsbybiblioitem
2301 # Subroutine to log changes to databases
2302 # Eventually, this subroutine will be used to create a log of all changes made,
2303 # with the possibility of "undo"ing some changes
2304 my $database = shift;
2305 if ( $database eq 'kohadb' ) {
2307 my $section = shift;
2309 my $original = shift;
2312 # print STDERR "KOHA: $type $section $item $original $new\n";
2314 elsif ( $database eq 'marc' ) {
2316 my $Record_ID = shift;
2319 my $subfield_ID = shift;
2320 my $original = shift;
2323 # print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2327 #------------------------------------------------
2329 #---------------------------------------
2330 # Find a biblio entry, or create a new one if it doesn't exist.
2331 # If a "subtitle" entry is in hash, add it to subtitle table
2332 sub getoraddbiblio {
2337 # FIXME - Unused argument
2338 $biblio, # hash ref to fields
2349 $dbh = C4::Context->dbh;
2351 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2352 $sth = $dbh->prepare( "select biblionumber
2354 where title=? and author=?
2355 and copyrightdate=? and seriestitle=?"
2358 $biblio->{title}, $biblio->{author},
2359 $biblio->{copyright}, $biblio->{seriestitle}
2362 ($biblionumber) = $sth->fetchrow;
2363 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2367 # Doesn't exist. Add new one.
2368 print "<PRE>Adding biblio</PRE>\n" if $debug;
2369 ( $biblionumber, $error ) = &newbiblio($biblio);
2370 if ($biblionumber) {
2371 print "<PRE>Added with biblio number=$biblionumber</PRE>\n"
2373 if ( $biblio->{subtitle} ) {
2374 &newsubtitle( $biblionumber, $biblio->{subtitle} );
2378 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2382 return $biblionumber, $error;
2384 } # sub getoraddbiblio
2388 # converts ISO 5426 coded string to ISO 8859-1
2389 # sloppy code : should be improved in next issue
2390 my ( $string, $encoding ) = @_;
2393 # $encoding = C4::Context->preference("marcflavour") unless $encoding;
2394 if ( $encoding eq "UNIMARC" ) {
2457 # this handles non-sorting blocks (if implementation requires this)
2458 $string = nsb_clean($_);
2460 elsif ( $encoding eq "USMARC" || $encoding eq "MARC21" ) {
2461 if (/[\xc1-\xff]/) {
2514 # this handles non-sorting blocks (if implementation requires this)
2515 $string = nsb_clean($_);
2522 my $NSB = '\x88'; # NSB : begin Non Sorting Block
2523 my $NSE = '\x89'; # NSE : Non Sorting Block end
2524 # handles non sorting blocks
2528 s/[ ]{0,1}$NSE/) /gm;
2535 my $dbh = C4::Context->dbh;
2536 my $result = MARCmarc2koha($dbh,$record,'');
2537 # search duplicate on ISBN, easy and fast...
2538 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=?");
2539 $sth->execute($result->{'isbn'});
2540 my ($biblionumber,$bibid,$title) = $sth->fetchrow;
2541 return $biblionumber,$bibid,$title if ($biblionumber);
2542 # a more complex search : build a request for SearchMarc::catalogsearch()
2543 my (@tags, @and_or, @excluding, @operator, @value, $offset,$length);
2544 # search on biblio.title
2545 my ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblio.title","");
2546 if ($record->field($tag)) {
2547 if ($record->field($tag)->subfields($subfield)) {
2548 push @tags, "'".$tag.$subfield."'";
2549 push @and_or, "and";
2550 push @excluding, "";
2551 push @operator, "contains";
2552 push @value, $record->field($tag)->subfield($subfield);
2553 # warn "for title, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2556 # ... and on biblio.author
2557 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblio.author","");
2558 if ($record->field($tag)) {
2559 if ($record->field($tag)->subfields($subfield)) {
2560 push @tags, "'".$tag.$subfield."'";
2561 push @and_or, "and";
2562 push @excluding, "";
2563 push @operator, "contains";
2564 push @value, $record->field($tag)->subfield($subfield);
2565 # warn "for author, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2568 # ... and on publicationyear.
2569 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.publicationyear","");
2570 if ($record->field($tag)) {
2571 if ($record->field($tag)->subfields($subfield)) {
2572 push @tags, "'".$tag.$subfield."'";
2573 push @and_or, "and";
2574 push @excluding, "";
2575 push @operator, "contains";
2576 push @value, $record->field($tag)->subfield($subfield);
2577 # warn "for publicationyear, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2581 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.size","");
2582 if ($record->field($tag)) {
2583 if ($record->field($tag)->subfields($subfield)) {
2584 push @tags, "'".$tag.$subfield."'";
2585 push @and_or, "and";
2586 push @excluding, "";
2587 push @operator, "contains";
2588 push @value, $record->field($tag)->subfield($subfield);
2589 # warn "for size, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2592 # ... and on publisher.
2593 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.publishercode","");
2594 if ($record->field($tag)) {
2595 if ($record->field($tag)->subfields($subfield)) {
2596 push @tags, "'".$tag.$subfield."'";
2597 push @and_or, "and";
2598 push @excluding, "";
2599 push @operator, "contains";
2600 push @value, $record->field($tag)->subfield($subfield);
2601 # warn "for publishercode, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2604 # ... and on volume.
2605 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.volume","");
2606 if ($record->field($tag)) {
2607 if ($record->field($tag)->subfields($subfield)) {
2608 push @tags, "'".$tag.$subfield."'";
2609 push @and_or, "and";
2610 push @excluding, "";
2611 push @operator, "contains";
2612 push @value, $record->field($tag)->subfield($subfield);
2613 # warn "for volume, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2617 my ($finalresult,$nbresult) = C4::SearchMarc::catalogsearch($dbh,\@tags,\@and_or,\@excluding,\@operator,\@value,0,10);
2618 # there is at least 1 result => return the 1st one
2620 warn "$nbresult => ".@$finalresult[0]->{biblionumber},@$finalresult[0]->{bibid},@$finalresult[0]->{title};
2621 return @$finalresult[0]->{biblionumber},@$finalresult[0]->{bibid},@$finalresult[0]->{title};
2623 # no result, returns nothing
2628 my $dbh = C4::Context->dbh;
2629 my $sth = $dbh->prepare("Select * from branches order by branchname");
2633 while (my $data = $sth->fetchrow_hashref) {
2634 push(@results,$data);
2638 return(scalar(@results), @results);
2642 END { } # module clean-up code here (global destructor)
2648 Koha Developement team <info@koha.org>
2650 Paul POULAIN paul.poulain@free.fr
2656 # Revision 1.108 2004/11/19 19:41:22 rangi
2657 # Shifting branches() from deprecated C4::Catalogue to C4::Biblio
2658 # Allowing the non marc interface acquisitions to work.
2660 # Revision 1.107 2004/11/05 10:15:27 tipaul
2661 # Improving FindDuplicate to find duplicate records on adding biblio
2663 # Revision 1.106 2004/11/02 16:44:45 tipaul
2664 # new feature : checking for duplicate biblio.
2666 # For instance, it's only done on ISBN only. Will be improved soon.
2668 # When a duplicate is detected, the biblio is not saved, but the user is asked for a confirmations.
2670 # Revision 1.105 2004/09/23 16:15:37 tipaul
2673 # Revision 1.104 2004/09/16 15:06:46 tipaul
2674 # enabling # (| still possible too) for repeatable subfields
2676 # Revision 1.103 2004/09/06 14:17:34 tipaul
2677 # some commented warning added + 1 major bugfix => drop empty fields, NOT fields containing 0
2679 # Revision 1.102 2004/09/06 10:00:19 tipaul
2680 # adding a "location" field to the library.
2681 # This field is useful when the callnumber contains no information on the room where the item is stored.
2682 # With this field, we now have 3 levels of informations to find a book :
2687 # This should be versatile enough to solve any storing method.
2688 # 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.
2690 # Revision 1.101 2004/08/18 16:01:37 tipaul
2691 # modifs to support frameworkcodes
2693 # Revision 1.100 2004/08/13 16:37:25 tipaul
2694 # adding frameworkcode to API in some subs
2696 # Revision 1.99 2004/07/30 13:54:50 doxulting
2697 # Beginning of serial commit
2699 # Revision 1.98 2004/07/15 09:48:10 tipaul
2700 # * removing useless sub
2701 # * minor bugfix in moditem (managing homebranch & holdingbranch)
2703 # Revision 1.97 2004/07/02 15:53:53 tipaul
2704 # bugfix (due to frameworkcode field)
2706 # Revision 1.96 2004/06/29 16:07:10 tipaul
2707 # last sync for 2.1.0 release
2709 # Revision 1.95 2004/06/26 23:19:59 rangi
2710 # Fixing modaddauthor, and adding getitemtypes.
2711 # Also tidying up formatting of code
2713 # Revision 1.94 2004/06/17 08:16:32 tipaul
2714 # merging tag & subfield in marc_word for better perfs
2716 # Revision 1.93 2004/06/11 15:38:06 joshferraro
2717 # Changes MARCaddword to index words >= 1 char ... needed for more accurate
2718 # searches using SearchMarc routines.
2720 # Revision 1.92 2004/06/10 08:29:01 tipaul
2721 # MARC authority management (continued)
2723 # Revision 1.91 2004/06/03 10:03:01 tipaul
2724 # * frameworks and itemtypes are independant
2725 # * in the MARC editor, showing the + to duplicate a tag only if the tag is repeatable
2727 # Revision 1.90 2004/05/28 08:25:53 tipaul
2728 # hidding hidden & isurl constraints into MARC subfield structure
2730 # Revision 1.89 2004/05/27 21:47:21 rangi
2733 # Revision 1.88 2004/05/18 15:23:49 tipaul
2734 # framework management : 1 MARC framework for each itemtype
2736 # Revision 1.87 2004/05/18 11:54:07 tipaul
2737 # getitemtypes moved in Koha.pm
2739 # Revision 1.86 2004/05/03 09:19:22 tipaul
2740 # some fixes for mysql prepare & execute
2742 # Revision 1.85 2004/04/02 14:55:48 tipaul
2743 # renaming items.bulk field to items.itemcallnumber.
2744 # Will be used to store call number for libraries that don't use dewey classification.
2745 # Note it's related to ITEMS, not biblio.
2747 # Revision 1.84 2004/03/24 17:18:30 joshferraro
2748 # Fixes bug 749 by removing the comma on line 1488.
2750 # Revision 1.83 2004/03/15 14:31:50 tipaul
2751 # adding a minor check
2753 # Revision 1.82 2004/03/07 05:47:31 acli
2754 # Various updates/fixes from rel_2_0
2755 # Fixes for bugs 721 (templating), 727, and 734
2757 # Revision 1.81 2004/03/06 20:26:13 tipaul
2758 # adding seealso feature in MARC searches
2760 # Revision 1.80 2004/02/12 13:40:56 tipaul
2761 # deleting subs duplicated by error
2763 # Revision 1.79 2004/02/11 08:40:09 tipaul
2764 # synch'ing 2.0.0 branch and head
2766 # Revision 1.78.2.3 2004/02/10 13:15:46 tipaul
2767 # removing 2 warnings
2769 # Revision 1.78.2.2 2004/01/26 10:38:06 tipaul
2770 # dealing correctly "bulk" field
2772 # Revision 1.78.2.1 2004/01/13 17:29:53 tipaul
2773 # * minor html fixes
2774 # * adding publisher in acquisition process (& ordering basket by publisher)
2776 # Revision 1.78 2003/12/09 15:57:28 tipaul
2777 # rolling back to working char_decode sub
2779 # Revision 1.77 2003/12/03 17:47:14 tipaul
2780 # bugfixes for biblio deletion
2782 # Revision 1.76 2003/12/03 01:43:41 slef
2785 # Revision 1.75 2003/12/03 01:42:03 slef
2786 # bug 662 fixes securing DBI
2788 # Revision 1.74 2003/11/28 09:48:33 tipaul
2789 # bugfix : misusing prepare & execute => now using prepare(?) and execute($var)
2791 # Revision 1.73 2003/11/28 09:45:25 tipaul
2792 # bugfix for iso2709 file import in the "notforloan" field.
2794 # But notforloan field called "loan" somewhere, so in case "loan" is used, copied to "notforloan" to avoid a bug.
2796 # Revision 1.72 2003/11/24 17:40:14 tipaul
2799 # Revision 1.71 2003/11/24 16:28:49 tipaul
2800 # biblio & item deletion now works fine in MARC editor.
2801 # Stores deleted biblio/item in the marc field of the deletedbiblio/deleteditem table.
2803 # Revision 1.70 2003/11/24 13:29:55 tipaul
2804 # moving $id from beginning to end of file (70 commits... huge comments...)
2806 # Revision 1.69 2003/11/24 13:27:17 tipaul
2807 # fix for #380 (bibliosubject)
2809 # Revision 1.68 2003/11/06 17:18:30 tipaul
2812 # 1st draft for MARC biblio deletion.
2813 # Still does not work well, but at least, Biblio.pm compiles & it should'nt break too many things
2814 # (Note the trash in the MARCdetail, but don't use it, please :-) )
2816 # Revision 1.67 2003/10/25 08:46:27 tipaul
2817 # minor fixes for bilbio deletion (still buggy)
2819 # Revision 1.66 2003/10/17 10:02:56 tipaul
2820 # Indexing only words longer than 2 letters. Was >=2 before, & 2 letters words usually means nothing.
2822 # Revision 1.65 2003/10/14 09:45:29 tipaul
2823 # 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)
2825 # Revision 1.64 2003/10/06 15:20:51 tipaul
2826 # fix for 536 (subtitle error)
2828 # Revision 1.63 2003/10/01 13:25:49 tipaul
2829 # seems a char encoding problem modified something in char_decode sub... changing back to something that works...
2831 # Revision 1.62 2003/09/17 14:21:13 tipaul
2832 # fixing bug that makes a MARC biblio disappear when using full acquisition (order => recieve ==> MARC editor).
2833 # Before this 2 lines fix, the MARC biblio was deleted during recieve, and had to be entirely recreated :-(
2835 # Revision 1.61 2003/09/17 10:24:39 tipaul
2836 # notforloan value in itemtype was overwritting notforloan value in a given item.
2837 # I changed this behaviour :
2838 # if notforloan is set for a given item, and NOT for all items from this itemtype, the notforloan is kept.
2839 # If notforloan is set for itemtype, it's used (and impossible to loan a specific item from this itemtype)
2841 # Revision 1.60 2003/09/04 14:11:23 tipaul
2842 # fix for 593 (data duplication in MARC-DB)
2844 # Revision 1.58 2003/08/06 12:54:52 tipaul
2845 # fix for publicationyear : extracting numeric value from MARC string, like for copyrightdate.
2846 # (note that copyrightdate still extracted to get numeric format)
2848 # Revision 1.57 2003/07/15 23:09:18 slef
2849 # change show columns to use biblioitems bnotes too
2851 # Revision 1.56 2003/07/15 11:34:52 slef
2852 # fixes from paul email
2854 # Revision 1.55 2003/07/15 00:02:49 slef
2855 # Work on bug 515... can we do a single-side rename of notes to bnotes?
2857 # Revision 1.54 2003/07/11 11:51:32 tipaul
2858 # *** empty log message ***
2860 # Revision 1.52 2003/07/10 10:37:19 tipaul
2861 # fix for copyrightdate problem, #514
2863 # Revision 1.51 2003/07/02 14:47:17 tipaul
2864 # fix for #519 : items.dateaccessioned imports incorrectly
2866 # Revision 1.49 2003/06/17 11:21:13 tipaul
2867 # improvments/fixes for z3950 support.
2868 # * Works now even on ADD, not only on MODIFY
2869 # * able to search on ISBN, author, title
2871 # Revision 1.48 2003/06/16 09:22:53 rangi
2872 # Just added an order clause to getitemtypes
2874 # Revision 1.47 2003/05/20 16:22:44 tipaul
2875 # fixing typo in Biblio.pm POD
2877 # Revision 1.46 2003/05/19 13:45:18 tipaul
2878 # support for subtitles, additional authors, subject.
2879 # 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.
2880 # Note that some OLD-DB subs are strange (dummy ?) see OLDmodsubject, OLDmodsubtitle, OLDmodaddiauthor in C4/Biblio.pm
2881 # 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.
2883 # Revision 1.45 2003/04/29 16:50:49 tipaul
2884 # really proud of this commit :-)
2885 # z3950 search and import seems to works fine.
2886 # Let me explain how :
2887 # * a "search z3950" button is added in the addbiblio template.
2888 # * when clicked, a popup appears and z3950/search.pl is called
2889 # * z3950/search.pl calls addz3950search in the DB
2890 # * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table.
2891 # * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending.
2892 # * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled
2895 # * 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.
2896 # * 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.
2898 # Revision 1.44 2003/04/28 13:07:14 tipaul
2899 # Those fixes solves the "internal server error" with MARC::Record 1.12.
2900 # It was due to an illegal contruction in Koha : we tried to retrive subfields from <10 tags.
2901 # That's not possible. MARC::Record accepted this in 0.93 version, but it was fixed after.
2902 # Now, the construct/retrieving is OK !
2904 # Revision 1.43 2003/04/10 13:56:02 tipaul
2906 # * worked in 1.9.0, but not in 1.9.1 :
2907 # - modif of a biblio didn't work
2908 # - 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.
2910 # * did not work before :
2911 # - repeatable subfields now works correctly. Enter 2 subfields separated by | and they will be splitted during saving.
2912 # - dropped the last subfield of the MARC form :-(
2914 # Internal changes :
2915 # - 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.
2916 # Note the MARCdelbiblio has been rewritted to enable deletion of a biblio WITHOUT deleting items.
2918 # Revision 1.42 2003/04/04 08:41:11 tipaul
2919 # last commits before 1.9.1
2921 # Revision 1.41 2003/04/01 12:26:43 tipaul
2924 # Revision 1.40 2003/03/11 15:14:03 tipaul
2927 # Revision 1.39 2003/03/07 16:35:42 tipaul
2928 # * moving generic functions to Koha.pm
2929 # * improvement of SearchMarc.pm
2933 # Revision 1.38 2003/02/27 16:51:59 tipaul
2934 # * moving prepare / execute to ? form.
2937 # * road to 1.9.2 => acquisition and cataloguing merging
2939 # Revision 1.37 2003/02/12 11:03:03 tipaul
2940 # Support for 000 -> 010 fields.
2941 # Those fields doesn't have subfields.
2942 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
2943 # 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.
2945 # Revision 1.36 2003/02/12 11:01:01 tipaul
2946 # Support for 000 -> 010 fields.
2947 # Those fields doesn't have subfields.
2948 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
2949 # 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.
2951 # Revision 1.35 2003/02/03 18:46:00 acli
2952 # Minor factoring in C4/Biblio.pm, plus change to export the per-tag
2953 # 'mandatory' property to a per-subfield 'tag_mandatory' template parameter,
2954 # so that addbiblio.tmpl can distinguish between mandatory subfields in a
2955 # mandatory tag and mandatory subfields in an optional tag
2957 # Not-minor factoring in acqui.simple/addbiblio.pl to make the if-else blocks
2958 # smaller, and to add some POD; need further testing for this
2960 # Added function to check if a MARC subfield name is "koha-internal" (instead
2961 # of checking it for 'lib' and 'tag' everywhere); temporarily added to Koha.pm
2963 # Use above function in acqui.simple/additem.pl and search.marc/search.pl
2965 # Revision 1.34 2003/01/28 14:50:04 tipaul
2966 # fixing MARCmodbiblio API and reindenting code
2968 # Revision 1.33 2003/01/23 12:22:37 tipaul
2969 # adding char_decode to decode MARC21 or UNIMARC extended chars
2971 # Revision 1.32 2002/12/16 15:08:50 tipaul
2972 # small but important bugfix (fixes a problem in export)
2974 # Revision 1.31 2002/12/13 16:22:04 tipaul
2975 # 1st draft of marc export
2977 # Revision 1.30 2002/12/12 21:26:35 tipaul
2978 # YAB ! (Yet Another Bugfix) => related to biblio modif
2979 # (some warning cleaning too)
2981 # Revision 1.29 2002/12/12 16:35:00 tipaul
2982 # adding authentification with Auth.pm and
2983 # MAJOR BUGFIX on marc biblio modification
2985 # Revision 1.28 2002/12/10 13:30:03 tipaul
2986 # fugfixes from Dombes Abbey work
2988 # Revision 1.27 2002/11/19 12:36:16 tipaul
2990 # various bugfixes, improvments, and migration from acquisition.pm to biblio.pm
2992 # Revision 1.26 2002/11/12 15:58:43 tipaul
2995 # * 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)
2997 # Revision 1.25 2002/10/25 10:58:26 tipaul
2999 # * bugfixes and improvements
3001 # Revision 1.24 2002/10/24 12:09:01 arensb
3002 # Fixed "no title" warning when generating HTML documentation from POD.
3004 # Revision 1.23 2002/10/16 12:43:08 arensb
3005 # Added some FIXME comments.
3007 # Revision 1.22 2002/10/15 13:39:17 tipaul
3008 # removing Acquisition.pm
3009 # deleting unused code in biblio.pm, rewriting POD and answering most FIXME comments
3011 # Revision 1.21 2002/10/13 11:34:14 arensb
3012 # Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
3013 # Thus, $x = $x+2 becomes $x += 2, and so forth.
3015 # Revision 1.20 2002/10/13 08:28:32 arensb
3016 # Deleted unused variables.
3017 # Removed trailing whitespace.
3019 # Revision 1.19 2002/10/13 05:56:10 arensb
3020 # Added some FIXME comments.
3022 # Revision 1.18 2002/10/11 12:34:53 arensb
3023 # Replaced &requireDBI with C4::Context->dbh
3025 # Revision 1.17 2002/10/10 14:48:25 tipaul
3028 # Revision 1.16 2002/10/07 14:04:26 tipaul
3029 # road to 1.3.1 : viewing MARC biblio
3031 # Revision 1.15 2002/10/05 09:49:25 arensb
3032 # Merged with arensb-context branch: use C4::Context->dbh instead of
3033 # &C4Connect, and generally prefer C4::Context over C4::Database.
3035 # Revision 1.14 2002/10/03 11:28:18 tipaul
3036 # Extending Context.pm to add stopword management and using it in MARC-API.
3037 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
3039 # Revision 1.13 2002/10/02 16:26:44 tipaul
3042 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
3043 # Merged in changes from main branch.
3045 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
3046 # Added a whole mess of FIXME comments.
3048 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
3049 # Added some missing semicolons.
3051 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
3052 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
3055 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
3056 # Added a whole mess of FIXME comments.
3058 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
3059 # Added some missing semicolons.
3061 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
3062 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
3065 # Revision 1.12 2002/10/01 11:48:51 arensb
3066 # Added some FIXME comments, mostly marking duplicate functions.
3068 # Revision 1.11 2002/09/24 13:49:26 tipaul
3069 # long WAS the road to 1.3.0...
3070 # coming VERY SOON NOW...
3071 # modifying installer and buildrelease to update the DB
3073 # Revision 1.10 2002/09/22 16:50:08 arensb
3074 # Added some FIXME comments.
3076 # Revision 1.9 2002/09/20 12:57:46 tipaul
3077 # long is the road to 1.4.0
3078 # * MARCadditem and MARCmoditem now wroks
3079 # * various bugfixes in MARC management
3080 # !!! 1.3.0 should be released very soon now. Be careful !!!
3082 # Revision 1.8 2002/09/10 13:53:52 tipaul
3083 # MARC API continued...
3085 # * 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)
3087 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
3089 # Revision 1.7 2002/08/14 18:12:51 tonnesen
3090 # Added copyright statement to all .pl and .pm files
3092 # Revision 1.6 2002/07/25 13:40:31 tipaul
3093 # pod documenting the API.
3095 # Revision 1.5 2002/07/24 16:11:37 tipaul
3097 # Database.pm and Output.pm are almost not modified (var test...)
3099 # Biblio.pm is almost completly rewritten.
3101 # WHAT DOES IT ??? ==> END of Hitchcock suspens
3103 # 1st, it does... nothing...
3104 # 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 ...
3106 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
3107 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
3108 # * 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.
3109 # * 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.
3110 # 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 ;-)
3112 # 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.
3113 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.