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
61 &NEWmodbiblioframework
63 &MARCaddbiblio &MARCadditem
64 &MARCmodsubfield &MARCaddsubfield
65 &MARCmodbiblio &MARCmoditem
66 &MARCkoha2marcBiblio &MARCmarc2koha
67 &MARCkoha2marcItem &MARChtml2marc
68 &MARCgetbiblio &MARCgetitem
69 &MARCaddword &MARCdelword
81 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
84 # all the following subs takes a MARC::Record as parameter and manage
85 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
86 # NEWxxx subs (xxx deals with old-DB parameters, the NEWxxx deals with MARC-DB parameter)
90 C4::Biblio - acquisition, catalog management functions
94 move from 1.2 to 1.4 version :
95 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
96 In the 1.4 version, we want to do 2 differents things :
97 - keep populating the old-DB, that has a LOT less datas than MARC
98 - populate the MARC-DB
99 To populate the DBs we have 2 differents sources :
100 - the standard acquisition system (through book sellers), that does'nt use MARC data
101 - the MARC acquisition system, that uses MARC data.
103 Thus, we have 2 differents cases :
104 - 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
105 - 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
107 That's why we need 4 subs :
108 all I<subs beginning by MARC> manage only MARC tables. They manage MARC-DB with MARC::Record parameters
109 all I<subs beginning by OLD> manage only OLD-DB tables. They manage old-DB with old-DB parameters
110 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
111 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.
113 - NEW and old-style API should be used in koha to manage biblio
114 - MARCsubs are divided in 2 parts :
115 * some of them manage MARC parameters. They are heavily used in koha.
116 * some of them manage MARC biblio : they are mostly used by NEW and old-style subs.
117 - OLD are used internally only
119 all subs requires/use $dbh as 1st parameter.
121 I<NEWxxx 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 I<OLDxxx related subs>
128 all subs requires/use $dbh as 1st parameter.
129 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
131 They all are the exact copy of 1.0/1.2 version of the sub without the OLD.
132 The OLDxxx is called by the original xxx sub.
133 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
135 WARNING : there is 1 difference between initialxxx and OLDxxx :
136 the db header $dbh is always passed as parameter to avoid over-DB connexion
142 =item @tagslib = &MARCgettagslib($dbh,1|0,$itemtype);
144 last param is 1 for liblibrarian and 0 for libopac
145 $itemtype contains the itemtype framework reference. If empty or does not exist, the default one is used
146 returns a hash with tag/subfield meaning
147 =item ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,$kohafield);
149 finds MARC tag and subfield for a given kohafield
150 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
152 =item $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
154 finds a old-db biblio number for a given MARCbibid number
156 =item $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
158 finds a MARC bibid from a old-db biblionumber
160 =item $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
162 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
164 =item $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
166 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
168 =item $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
170 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
172 =item $olddb = &MARCmarc2koha($dbh,$MARCRecord);
174 builds a hash with old-db datas from a MARC::Record
176 =item &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
178 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
180 =item &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
182 adds a subfield in a biblio (in the MARC tables only).
184 =item $MARCRecord = &MARCgetbiblio($dbh,$bibid);
186 Returns a MARC::Record for the biblio $bibid.
188 =item &MARCmodbiblio($dbh,$bibid,$record,$frameworkcode,$delete);
190 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
191 It 1st delete the biblio, then recreates it.
192 WARNING : the $delete parameter is not used anymore (too much unsolvable cases).
193 =item ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
195 MARCmodsubfield changes the value of a given subfield
197 =item $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
199 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
200 Returns -1 if more than 1 answer
202 =item $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
204 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
206 =item &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
208 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
209 If $subfieldorder is not set, delete all the $tag$subfield subfields
211 =item &MARCdelbiblio($dbh,$bibid);
213 MARCdelbiblio delete biblio $bibid
215 =item &MARCkoha2marcOnefield
217 used by MARCkoha2marc and should not be useful elsewhere
219 =item &MARCmarc2kohaOnefield
221 used by MARCmarc2koha and should not be useful elsewhere
225 used to manage MARC_word table and should not be useful elsewhere
229 used to manage MARC_word table and should not be useful elsewhere
234 my ( $dbh, $forlibrarian, $frameworkcode ) = @_;
235 $frameworkcode = "" unless $frameworkcode;
237 my $libfield = ( $forlibrarian eq 1 ) ? 'liblibrarian' : 'libopac';
239 # check that framework exists
242 "select count(*) from marc_tag_structure where frameworkcode=?");
243 $sth->execute($frameworkcode);
244 my ($total) = $sth->fetchrow;
245 $frameworkcode = "" unless ( $total > 0 );
248 "select tagfield,liblibrarian,libopac,mandatory,repeatable from marc_tag_structure where frameworkcode=? order by tagfield"
250 $sth->execute($frameworkcode);
251 my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable );
253 while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable ) = $sth->fetchrow ) {
254 $res->{$tag}->{lib} = ($forlibrarian or !$libopac)?$liblibrarian:$libopac;
255 $res->{$tab}->{tab} = ""; # XXX
256 $res->{$tag}->{mandatory} = $mandatory;
257 $res->{$tag}->{repeatable} = $repeatable;
262 "select tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link from marc_subfield_structure where frameworkcode=? order by tagfield,tagsubfield"
264 $sth->execute($frameworkcode);
267 my $authorised_value;
277 ( $tag, $subfield, $liblibrarian, , $libopac, $tab,
278 $mandatory, $repeatable, $authorised_value, $authtypecode,
279 $value_builder, $kohafield, $seealso, $hidden,
284 $res->{$tag}->{$subfield}->{lib} = ($forlibrarian or !$libopac)?$liblibrarian:$libopac;
285 $res->{$tag}->{$subfield}->{tab} = $tab;
286 $res->{$tag}->{$subfield}->{mandatory} = $mandatory;
287 $res->{$tag}->{$subfield}->{repeatable} = $repeatable;
288 $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
289 $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode;
290 $res->{$tag}->{$subfield}->{value_builder} = $value_builder;
291 $res->{$tag}->{$subfield}->{kohafield} = $kohafield;
292 $res->{$tag}->{$subfield}->{seealso} = $seealso;
293 $res->{$tag}->{$subfield}->{hidden} = $hidden;
294 $res->{$tag}->{$subfield}->{isurl} = $isurl;
295 $res->{$tag}->{$subfield}->{link} = $link;
300 sub MARCfind_marc_from_kohafield {
301 my ( $dbh, $kohafield,$frameworkcode ) = @_;
302 return 0, 0 unless $kohafield;
303 my $relations = C4::Context->marcfromkohafield;
304 return ($relations->{$frameworkcode}->{$kohafield}->[0],$relations->{$frameworkcode}->{$kohafield}->[1]);
307 sub MARCfind_oldbiblionumber_from_MARCbibid {
308 my ( $dbh, $MARCbibid ) = @_;
310 $dbh->prepare("select biblionumber from marc_biblio where bibid=?");
311 $sth->execute($MARCbibid);
312 my ($biblionumber) = $sth->fetchrow;
313 return $biblionumber;
316 sub MARCfind_MARCbibid_from_oldbiblionumber {
317 my ( $dbh, $oldbiblionumber ) = @_;
319 $dbh->prepare("select bibid from marc_biblio where biblionumber=?");
320 $sth->execute($oldbiblionumber);
321 my ($bibid) = $sth->fetchrow;
327 # pass the MARC::Record to this function, and it will create the records in the marc tables
328 my ($dbh,$record,$biblionumber,$frameworkcode,$bibid) = @_;
329 my @fields=$record->fields();
331 # adding main table, and retrieving bibid
332 # if bibid is sent, then it's not a true add, it's only a re-add, after a delete (ie, a mod)
333 # if bibid empty => true add, find a new bibid number
336 "lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ"
340 "insert into marc_biblio (datecreated,biblionumber,frameworkcode) values (now(),?,?)"
342 $sth->execute( $biblionumber, $frameworkcode );
343 $sth = $dbh->prepare("select max(bibid) from marc_biblio");
345 ($bibid) = $sth->fetchrow;
350 # now, add subfields...
351 foreach my $field (@fields) {
353 if ( $field->tag() < 10 ) {
354 &MARCaddsubfield( $dbh, $bibid, $field->tag(), '', $fieldcount, '',
358 my @subfields = $field->subfields();
359 foreach my $subfieldcount ( 0 .. $#subfields ) {
364 $field->indicator(1) . $field->indicator(2),
366 $subfields[$subfieldcount][0],
368 $subfields[$subfieldcount][1]
374 &MARCaddsubfield($dbh,$bibid,'000','',$fieldcount+1,'',1,$record->leader);
375 $dbh->do("unlock tables");
381 # pass the MARC::Record to this function, and it will create the records in the marc tables
382 my ($dbh,$record,$biblionumber) = @_;
383 # search for MARC biblionumber
384 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
385 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
386 my @fields=$record->fields();
387 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
388 $sth->execute($bibid);
389 my ($fieldcount) = $sth->fetchrow;
391 # now, add subfields...
392 foreach my $field (@fields) {
393 unless ($field->tag<100){
394 my @subfields = $field->subfields();
396 foreach my $subfieldcount ( 0 .. $#subfields ) {
401 $field->indicator(1) . $field->indicator(2),
403 $subfields[$subfieldcount][0],
405 $subfields[$subfieldcount][1]
410 $dbh->do("unlock tables");
414 sub MARCaddsubfield {
416 # Add a new subfield to a tag into the DB.
418 $dbh, $bibid, $tagid, $tag_indicator,
419 $tagorder, $subfieldcode, $subfieldorder, $subfieldvalues
422 return unless defined($subfieldvalues);
423 # warn "$tagid / $subfieldcode / $subfieldvalues";
424 # if not value, end of job, we do nothing
425 # if ( length($subfieldvalues) == 0 ) {
428 if ( not($subfieldcode) ) {
429 $subfieldcode = ' ' unless $subfieldcode eq '0';
431 my @subfieldvalues; # = split /\||#/, $subfieldvalues;
432 push @subfieldvalues,$subfieldvalues;
433 foreach my $subfieldvalue (@subfieldvalues) {
434 if ( length($subfieldvalue) > 255 ) {
436 "lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE"
440 "insert into marc_blob_subfield (subfieldvalue) values (?)");
441 $sth->execute($subfieldvalue);
443 $dbh->prepare("select max(blobidlink)from marc_blob_subfield");
445 my ($res) = $sth->fetchrow;
448 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?,?)"
450 $sth->execute( $bibid, ( sprintf "%03s", $tagid ), $tagorder,
451 $tag_indicator, $subfieldcode, $subfieldorder, $res );
453 if ( $sth->errstr ) {
455 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
457 $dbh->do("unlock tables");
462 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)"
465 $bibid, ( sprintf "%03s", $tagid ),
466 $tagorder, $tag_indicator,
467 $subfieldcode, $subfieldorder,
470 if ( $sth->errstr ) {
472 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
476 $dbh, $bibid, $tagid, $tagorder,
477 $subfieldcode, $subfieldorder, $subfieldvalue
484 # Returns MARC::Record of the biblio passed in parameter.
485 my ( $dbh, $bibid ) = @_;
486 my $record = MARC::Record->new();
490 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
491 from marc_subfield_table
492 where bibid=? order by tag,tagorder,subfieldorder
497 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
498 $sth->execute($bibid);
499 my $prevtagorder = 1;
502 my $field; # for >=10 tags
503 my $prevvalue; # for <10 tags
504 while ( my $row = $sth->fetchrow_hashref ) {
506 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
507 $sth2->execute( $row->{'valuebloblink'} );
508 my $row2 = $sth2->fetchrow_hashref;
510 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
512 if ( $row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag ) {
513 $previndicator .= " ";
514 if ( $prevtag < 10 ) {
515 if ($prevtag ne '000') {
516 $record->add_fields( ( sprintf "%03s", $prevtag ), $prevvalue ) unless $prevtag eq "XXX"; # ignore the 1st loop
518 $record->leader(sprintf("%-24s",$prevvalue));
522 $record->add_fields($field) unless $prevtag eq "XXX";
525 $prevtagorder = $row->{tagorder};
526 $prevtag = $row->{tag};
527 $previndicator = $row->{tag_indicator};
528 if ( $row->{tag} < 10 ) {
529 $prevvalue = $row->{subfieldvalue};
532 $field = MARC::Field->new(
533 ( sprintf "%03s", $prevtag ),
534 substr( $row->{tag_indicator} . ' ', 0, 1 ),
535 substr( $row->{tag_indicator} . ' ', 1, 1 ),
536 $row->{'subfieldcode'},
537 $row->{'subfieldvalue'}
542 if ( $row->{tag} < 10 ) {
543 $record->add_fields( ( sprintf "%03s", $row->{tag} ),
544 $row->{'subfieldvalue'} );
547 $field->add_subfields( $row->{'subfieldcode'},
548 $row->{'subfieldvalue'} );
550 $prevtag = $row->{tag};
551 $previndicator = $row->{tag_indicator};
555 # the last has not been included inside the loop... do it now !
556 if ( $prevtag ne "XXX" )
557 { # check that we have found something. Otherwise, prevtag is still XXX and we
558 # must return an empty record, not make MARC::Record fail because we try to
559 # create a record with XXX as field :-(
560 if ( $prevtag < 10 ) {
561 $record->add_fields( $prevtag, $prevvalue );
565 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
566 $record->add_fields($field);
574 # Returns MARC::Record of the biblio passed in parameter.
575 my ( $dbh, $bibid, $itemnumber ) = @_;
576 my $record = MARC::Record->new();
578 # search MARC tagorder
581 "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=?"
583 $sth2->execute( $bibid, $itemnumber );
584 my ($tagorder) = $sth2->fetchrow_array();
586 #---- TODO : the leader is missing
589 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
590 from marc_subfield_table
591 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
596 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
597 $sth->execute( $bibid, $tagorder );
598 while ( my $row = $sth->fetchrow_hashref ) {
599 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
600 $sth2->execute( $row->{'valuebloblink'} );
601 my $row2 = $sth2->fetchrow_hashref;
603 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
605 if ( $record->field( $row->{'tag'} ) ) {
608 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
609 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
610 if ( length( $row->{'tag'} ) < 3 ) {
611 $row->{'tag'} = "0" . $row->{'tag'};
613 $field = $record->field( $row->{'tag'} );
616 $field->add_subfields( $row->{'subfieldcode'},
617 $row->{'subfieldvalue'} );
618 $record->delete_field($field);
619 $record->add_fields($field);
623 if ( length( $row->{'tag'} ) < 3 ) {
624 $row->{'tag'} = "0" . $row->{'tag'};
627 MARC::Field->new( $row->{'tag'}, " ", " ",
628 $row->{'subfieldcode'} => $row->{'subfieldvalue'} );
629 $record->add_fields($temp);
637 my ($dbh,$bibid,$record,$frameworkcode,$delete)=@_;
638 # 1st delete the biblio,
640 my $biblionumber = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
641 &MARCdelbiblio($dbh,$bibid,1);
642 &MARCaddbiblio($dbh,$record,$biblionumber,$frameworkcode,$bibid);
646 my ( $dbh, $bibid, $keep_items ) = @_;
648 # if the keep_item is set to 1, then all items are preserved.
649 # This flag is set when the delbiblio is called by modbiblio
650 # due to a too complex structure of MARC (repeatable fields and subfields),
651 # the best solution for a modif is to delete / recreate the record.
653 # 1st of all, copy the MARC::Record to deletedbiblio table => if a true deletion, MARC data will be kept.
654 # if deletion called before MARCmodbiblio => won't do anything, as the oldbiblionumber doesn't
655 # exist in deletedbiblio table
656 my $record = MARCgetbiblio( $dbh, $bibid );
657 my $oldbiblionumber =
658 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
660 $dbh->prepare("update deletedbiblio set marc=? where biblionumber=?");
661 $copy2deleted->execute( $record->as_usmarc(), $oldbiblionumber );
663 # now, delete in MARC tables.
664 if ( $keep_items eq 1 ) {
666 #search item field code
669 "select tagfield from marc_subfield_structure where kohafield like 'items.%'"
672 my $itemtag = $sth->fetchrow_hashref->{tagfield};
674 "delete from marc_subfield_table where bibid=$bibid and tag<>$itemtag"
677 "delete from marc_word where bibid=$bibid and not (tagsubfield like \"$itemtag%\")"
681 $dbh->do("delete from marc_biblio where bibid=$bibid");
682 $dbh->do("delete from marc_subfield_table where bibid=$bibid");
683 $dbh->do("delete from marc_word where bibid=$bibid");
689 # delete the item passed in parameter in MARC tables.
690 my ( $dbh, $bibid, $itemnumber ) = @_;
692 # my $record = MARC::Record->new();
693 # search MARC tagorder
694 my $record = MARCgetitem( $dbh, $bibid, $itemnumber );
696 $dbh->prepare("update deleteditems set marc=? where itemnumber=?");
697 $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
701 "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=?"
703 $sth2->execute( $bibid, $itemnumber );
704 my ($tagorder) = $sth2->fetchrow_array();
707 "delete from marc_subfield_table where bibid=? and tagorder=?");
708 $sth->execute( $bibid, $tagorder );
712 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
713 my $biblionumber = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
714 &MARCdelitem($dbh,$bibid,$itemnumber);
715 &MARCadditem($dbh,$record,$biblionumber);
718 sub MARCmodsubfield {
720 # Subroutine changes a subfield value given a subfieldid.
721 my ( $dbh, $subfieldid, $subfieldvalue ) = @_;
722 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
725 "select valuebloblink from marc_subfield_table where subfieldid=?");
726 $sth1->execute($subfieldid);
727 my ($oldvaluebloblink) = $sth1->fetchrow;
731 # if too long, use a bloblink
732 if ( length($subfieldvalue) > 255 ) {
734 # if already a bloblink, update it, otherwise, insert a new one.
735 if ($oldvaluebloblink) {
738 "update marc_blob_subfield set subfieldvalue=? where blobidlink=?"
740 $sth->execute( $subfieldvalue, $oldvaluebloblink );
745 "insert into marc_blob_subfield (subfieldvalue) values (?)");
746 $sth->execute($subfieldvalue);
748 $dbh->prepare("select max(blobidlink) from marc_blob_subfield");
750 my ($res) = $sth->fetchrow;
753 "update marc_subfield_table set subfieldvalue=null, valuebloblink=? where subfieldid=?"
755 $sth->execute( $res, $subfieldid );
760 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
763 "update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?"
765 $sth->execute( $subfieldvalue, $subfieldid );
767 $dbh->do("unlock tables");
771 "select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?"
773 $sth->execute($subfieldid);
774 my ( $bibid, $tagid, $tagorder, $subfieldcode, $x, $subfieldorder ) =
777 &MARCdelword( $dbh, $bibid, $tagid, $tagorder, $subfieldcode,
780 $dbh, $bibid, $tagid, $tagorder,
781 $subfieldcode, $subfieldorder, $subfieldvalue
783 return ( $subfieldid, $subfieldvalue );
786 sub MARCfindsubfield {
787 my ( $dbh, $bibid, $tag, $subfieldcode, $subfieldorder, $subfieldvalue ) =
789 my $resultcounter = 0;
793 "select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
794 my @bind_values = ( $bibid, $tag, $subfieldcode );
795 if ($subfieldvalue) {
796 $query .= " and subfieldvalue=?";
797 push ( @bind_values, $subfieldvalue );
800 if ( $subfieldorder < 1 ) {
803 $query .= " and subfieldorder=?";
804 push ( @bind_values, $subfieldorder );
806 my $sti = $dbh->prepare($query);
807 $sti->execute(@bind_values);
808 while ( ($subfieldid) = $sti->fetchrow ) {
810 $lastsubfieldid = $subfieldid;
812 if ( $resultcounter > 1 ) {
814 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
815 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
819 return $lastsubfieldid;
823 sub MARCfindsubfieldid {
824 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
825 my $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
826 where bibid=? and tag=? and tagorder=?
827 and subfieldcode=? and subfieldorder=?"
829 $sth->execute( $bibid, $tag, $tagorder, $subfield, $subfieldorder );
830 my ($res) = $sth->fetchrow;
832 $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
833 where bibid=? and tag=? and tagorder=?
836 $sth->execute( $bibid, $tag, $tagorder, $subfield );
837 ($res) = $sth->fetchrow;
842 sub MARCfind_frameworkcode {
843 my ( $dbh, $bibid ) = @_;
845 $dbh->prepare("select frameworkcode from marc_biblio where bibid=?");
846 $sth->execute($bibid);
847 my ($frameworkcode) = $sth->fetchrow;
848 return $frameworkcode;
851 sub MARCdelsubfield {
853 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
854 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
855 if ($subfieldorder) {
856 $dbh->do( "delete from marc_subfield_table where bibid='$bibid' and
857 tag='$tag' and tagorder='$tagorder'
858 and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
861 $dbh->do( "delete from marc_word where bibid='$bibid' and
862 tagsubfield='$tag$subfield' and tagorder='$tagorder'
863 and subfieldorder='$subfieldorder'
867 $dbh->do( "delete from marc_subfield_table where bibid='$bibid' and
868 tag='$tag' and tagorder='$tagorder'
869 and subfieldcode='$subfield'"
871 $dbh->do( "delete from marc_word where bibid='$bibid' and
872 tagsubfield='$tag$subfield' and tagorder='$tagorder'"
877 sub MARCkoha2marcBiblio {
879 # this function builds partial MARC::Record from the old koha-DB fields
880 my ( $dbh, $biblionumber, $biblioitemnumber ) = @_;
883 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
885 my $record = MARC::Record->new();
887 #--- if bibid, then retrieve old-style koha data
888 if ( $biblionumber > 0 ) {
891 "select biblionumber,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
892 from biblio where biblionumber=?"
894 $sth2->execute($biblionumber);
895 my $row = $sth2->fetchrow_hashref;
897 foreach $code ( keys %$row ) {
898 if ( $row->{$code} ) {
899 &MARCkoha2marcOnefield( $sth, $record, "biblio." . $code,
903 #for an unknown reason, mysql fetchrow_hashref returns author BEFORE the title, even if you want it after
904 # that makes a problem for UNIMARC where we have 200 $atitle $fauthor => the record appears $f $a.
905 # this dirty hack fixes the problem
906 $sth2 = $dbh->prepare("select author from biblio where biblionumber=?");
907 $sth2->execute($biblionumber);
908 $row = $sth2->fetchrow_hashref;
910 foreach $code ( keys %$row ) {
911 if ( $row->{$code} ) {
912 &MARCkoha2marcOnefield( $sth, $record, "biblio." . $code,
918 #--- if biblioitem, then retrieve old-style koha data
919 if ( $biblioitemnumber > 0 ) {
922 " SELECT biblioitemnumber,biblionumber,volume,number,classification,
923 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
924 volumedate,volumeddesc,timestamp,illus,pages,notes AS bnotes,size,place
926 WHERE biblioitemnumber=?
929 $sth2->execute($biblioitemnumber);
930 my $row = $sth2->fetchrow_hashref;
932 foreach $code ( keys %$row ) {
933 if ( $row->{$code} ) {
934 &MARCkoha2marcOnefield( $sth, $record, "biblioitems." . $code,
940 # other fields => additional authors, subjects, subtitles
943 " SELECT author FROM additionalauthors WHERE biblionumber=?");
944 $sth2->execute($biblionumber);
945 while ( my $row = $sth2->fetchrow_hashref ) {
946 &MARCkoha2marcOnefield( $sth, $record, "additionalauthors.author",
947 $row->{'author'},'' );
950 $dbh->prepare(" SELECT subject FROM bibliosubject WHERE biblionumber=?");
951 $sth2->execute($biblionumber);
952 while ( my $row = $sth2->fetchrow_hashref ) {
953 &MARCkoha2marcOnefield( $sth, $record, "bibliosubject.subject",
954 $row->{'subject'},'' );
958 " SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?");
959 $sth2->execute($biblionumber);
960 while ( my $row = $sth2->fetchrow_hashref ) {
961 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle",
962 $row->{'subtitle'},'' );
967 sub MARCkoha2marcItem {
969 # this function builds partial MARC::Record from the old koha-DB fields
970 my ( $dbh, $biblionumber, $itemnumber ) = @_;
972 # my $dbh=&C4Connect;
975 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
977 my $record = MARC::Record->new();
979 #--- if item, then retrieve old-style koha data
980 if ( $itemnumber > 0 ) {
982 # print STDERR "prepare $biblionumber,$itemnumber\n";
985 "SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
986 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
987 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,itemcallnumber,issues,renewals,
988 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
992 $sth2->execute($itemnumber);
993 my $row = $sth2->fetchrow_hashref;
995 foreach $code ( keys %$row ) {
996 if ( $row->{$code} ) {
997 &MARCkoha2marcOnefield( $sth, $record, "items." . $code,
1005 sub MARCkoha2marcSubtitle {
1007 # this function builds partial MARC::Record from the old koha-DB fields
1008 my ( $dbh, $bibnum, $subtitle ) = @_;
1011 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
1013 my $record = MARC::Record->new();
1014 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle",
1019 sub MARCkoha2marcOnefield {
1020 my ( $sth, $record, $kohafieldname, $value,$frameworkcode ) = @_;
1023 $sth->execute($frameworkcode,$kohafieldname);
1024 if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
1025 if ( $record->field($tagfield) ) {
1026 my $tag = $record->field($tagfield);
1028 $tag->add_subfields( $tagsubfield, $value );
1029 $record->delete_field($tag);
1030 $record->add_fields($tag);
1034 $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
1041 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
1043 my $record = MARC::Record->new();
1044 # my %subfieldlist=();
1045 my $prevvalue; # if tag <10
1046 my $field; # if tag >=10
1047 for (my $i=0; $i< @$rtags; $i++) {
1048 # rebuild MARC::Record
1049 # warn "0=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ";
1050 if (@$rtags[$i] ne $prevtag) {
1051 if ($prevtag < 10) {
1053 if ($prevtag ne '000') {
1054 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
1056 $record->leader($prevvalue);
1061 $record->add_fields($field);
1064 $indicators{@$rtags[$i]}.=' ';
1065 if (@$rtags[$i] <10) {
1066 $prevvalue= @$rvalues[$i];
1070 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
1071 # warn "1=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
1073 $prevtag = @$rtags[$i];
1075 if (@$rtags[$i] <10) {
1076 $prevvalue=@$rvalues[$i];
1078 if (length(@$rvalues[$i])>0) {
1079 $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
1080 # warn "2=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
1083 $prevtag= @$rtags[$i];
1086 # the last has not been included inside the loop... do it now !
1087 $record->add_fields($field) if $field;
1088 # warn "HTML2MARC=".$record->as_formatted;
1093 my ($dbh,$record,$frameworkcode) = @_;
1094 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?");
1096 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
1099 while (($field)=$sth2->fetchrow) {
1100 # warn "biblio.".$field;
1101 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result,$frameworkcode);
1103 $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
1105 while (($field)=$sth2->fetchrow) {
1106 if ($field eq 'notes') { $field = 'bnotes'; }
1107 # warn "biblioitems".$field;
1108 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result,$frameworkcode);
1110 $sth2=$dbh->prepare("SHOW COLUMNS from items");
1112 while (($field)=$sth2->fetchrow) {
1113 # warn "items".$field;
1114 $result=&MARCmarc2kohaOneField($sth,"items",$field,$record,$result,$frameworkcode);
1116 # additional authors : specific
1117 $result = &MARCmarc2kohaOneField($sth,"bibliosubtitle","subtitle",$record,$result,$frameworkcode);
1118 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result,$frameworkcode);
1119 # modify copyrightdate to keep only the 1st year found
1120 my $temp = $result->{'copyrightdate'};
1122 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1124 $result->{'copyrightdate'} = $1;
1125 } else { # if no cYYYY, get the 1st date.
1126 $temp =~ m/(\d\d\d\d)/;
1127 $result->{'copyrightdate'} = $1;
1130 # modify publicationyear to keep only the 1st year found
1131 $temp = $result->{'publicationyear'};
1133 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1135 $result->{'publicationyear'} = $1;
1136 } else { # if no cYYYY, get the 1st date.
1137 $temp =~ m/(\d\d\d\d)/;
1138 $result->{'publicationyear'} = $1;
1144 sub MARCmarc2kohaOneField {
1146 # FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
1147 my ( $sth, $kohatable, $kohafield, $record, $result,$frameworkcode ) = @_;
1148 # warn "kohatable / $kohafield / $result / ";
1152 ( $tagfield, $subfield ) = MARCfind_marc_from_kohafield("",$kohatable.".".$kohafield,$frameworkcode);
1153 if (($tagfield) && $record->field($tagfield)) {
1154 my $field =$record->field($tagfield);
1155 if ($field->tag()<10) {
1156 if ($result->{$kohafield}) {
1157 # Reverse array filled with elements from repeated subfields
1158 # from first to last to avoid last to first concatenation of
1159 # elements in Koha DB. -- thd
1160 $result->{$kohafield} .= " | " . reverse($field->data());
1162 $result->{$kohafield} = $field->data() ;
1165 if ( $field->subfields ) {
1166 my @subfields = $field->subfields();
1167 foreach my $subfieldcount ( 0 .. $#subfields ) {
1168 if ($subfields[$subfieldcount][0] eq $subfield) {
1169 if ( $result->{$kohafield} ) {
1170 $result->{$kohafield} .= " | " . $subfields[$subfieldcount][1] if ($subfields[$subfieldcount][1]);
1173 $result->{$kohafield} = $subfields[$subfieldcount][1] if ($subfields[$subfieldcount][1]);
1180 # warn "OneField for $kohatable.$kohafield and $frameworkcode=> $tagfield, $subfield";
1186 # split a subfield string and adds it into the word table.
1189 $dbh, $bibid, $tag, $tagorder,
1190 $subfieldid, $subfieldorder, $sentence
1193 $sentence =~ s/(\.|\?|\:|\!|;|\'|,|\-|\"|\(|\)|\[|\]|\{|\}|\/)/ /g;
1194 my @words = split / /, $sentence;
1195 my $stopwords = C4::Context->stopwords;
1198 "insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word)
1199 values (?,concat(?,?),?,?,?,soundex(?))"
1201 foreach my $word (@words) {
1202 # we record only words one char long and not in stopwords hash
1203 if (length($word)>=1 and !($stopwords->{uc($word)})) {
1204 $sth->execute($bibid,$tag,$subfieldid,$tagorder,$subfieldorder,$word,$word);
1206 warn "ERROR ==> insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word) values ($bibid,concat($tag,$subfieldid),$tagorder,$subfieldorder,$word,soundex($word))\n";
1214 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
1215 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
1218 "delete from marc_word where bibid=? and tagsubfield=concat(?,?) and tagorder=? and subfieldorder=?"
1220 $sth->execute( $bibid, $tag, $subfield, $tagorder, $subfieldorder );
1225 # NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW
1228 # all the following subs are useful to manage MARC-DB with complete MARC records.
1229 # it's used with marcimport, and marc management tools
1232 =item ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
1234 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
1235 are builded from the MARC::Record. If they are passed, they are used.
1237 =item NEWnewitem($dbh, $record,$bibid);
1239 adds an item in the db.
1244 my ( $dbh, $record, $frameworkcode ) = @_;
1247 my $olddata = MARCmarc2koha( $dbh, $record,$frameworkcode );
1248 $oldbibnum = OLDnewbiblio( $dbh, $olddata );
1249 $olddata->{'biblionumber'} = $oldbibnum;
1250 $oldbibitemnum = OLDnewbiblioitem( $dbh, $olddata );
1252 # search subtiles, addiauthors and subjects
1253 my ( $tagfield, $tagsubfield ) =
1254 MARCfind_marc_from_kohafield( $dbh, "additionalauthors.author",$frameworkcode );
1255 my @addiauthfields = $record->field($tagfield);
1256 foreach my $addiauthfield (@addiauthfields) {
1257 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1258 foreach my $subfieldcount ( 0 .. $#addiauthsubfields ) {
1259 OLDmodaddauthor( $dbh, $oldbibnum,
1260 $addiauthsubfields[$subfieldcount] );
1263 ( $tagfield, $tagsubfield ) =
1264 MARCfind_marc_from_kohafield( $dbh, "bibliosubtitle.subtitle",$frameworkcode );
1265 my @subtitlefields = $record->field($tagfield);
1266 foreach my $subtitlefield (@subtitlefields) {
1267 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1268 foreach my $subfieldcount ( 0 .. $#subtitlesubfields ) {
1269 OLDnewsubtitle( $dbh, $oldbibnum,
1270 $subtitlesubfields[$subfieldcount] );
1273 ( $tagfield, $tagsubfield ) =
1274 MARCfind_marc_from_kohafield( $dbh, "bibliosubject.subject",$frameworkcode );
1275 my @subj = $record->field($tagfield);
1277 foreach my $subject (@subj) {
1278 my @subjsubfield = $subject->subfield($tagsubfield);
1279 foreach my $subfieldcount ( 0 .. $#subjsubfield ) {
1280 push @subjects, $subjsubfield[$subfieldcount];
1283 OLDmodsubject( $dbh, $oldbibnum, 1, @subjects );
1285 # we must add bibnum and bibitemnum in MARC::Record...
1286 # we build the new field with biblionumber and biblioitemnumber
1287 # we drop the original field
1288 # we add the new builded field.
1289 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
1290 # (steve and paul : thinks 090 is a good choice)
1293 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
1295 $sth->execute("biblio.biblionumber");
1296 ( my $tagfield1, my $tagsubfield1 ) = $sth->fetchrow;
1297 $sth->execute("biblioitems.biblioitemnumber");
1298 ( my $tagfield2, my $tagsubfield2 ) = $sth->fetchrow;
1300 # biblionumber & biblioitemnumber are in different fields
1301 if ( $tagfield1 != $tagfield2 ) {
1302 # deal with biblionumber
1303 if ($tagfield1<10) {
1304 $newfield = MARC::Field->new(
1305 $tagfield1, $oldbibnum,
1308 $newfield = MARC::Field->new(
1309 $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
1312 # drop old field and create new one...
1313 my $old_field = $record->field($tagfield1);
1314 $record->delete_field($old_field);
1315 $record->add_fields($newfield);
1316 # deal with biblioitemnumber
1317 if ($tagfield2<10) {
1318 $newfield = MARC::Field->new(
1319 $tagfield2, $oldbibitemnum,
1322 $newfield = MARC::Field->new(
1323 $tagfield2, '', '', "$tagsubfield2" => $oldbibitemnum,
1326 # drop old field and create new one...
1327 $old_field = $record->field($tagfield2);
1328 $record->delete_field($old_field);
1329 $record->add_fields($newfield);
1330 # biblionumber & biblioitemnumber are in the same field (can't be <10 as fields <10 have only 1 value)
1332 my $newfield = MARC::Field->new(
1333 $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
1334 "$tagsubfield2" => $oldbibitemnum
1336 # drop old field and create new one...
1337 my $old_field = $record->field($tagfield1);
1338 $record->delete_field($old_field);
1339 $record->add_fields($newfield);
1341 # warn "REC : ".$record->as_formatted;
1342 my $bibid = MARCaddbiblio( $dbh, $record, $oldbibnum, $frameworkcode );
1343 return ( $bibid, $oldbibnum, $oldbibitemnum );
1346 sub NEWmodbiblioframework {
1347 my ($dbh,$bibid,$frameworkcode) =@_;
1348 my $sth = $dbh->prepare("Update marc_biblio SET frameworkcode=? WHERE bibid=$bibid");
1349 $sth->execute($frameworkcode);
1353 my ($dbh,$record,$bibid,$frameworkcode) =@_;
1354 $frameworkcode="" unless $frameworkcode;
1355 &MARCmodbiblio($dbh,$bibid,$record,$frameworkcode,0);
1356 my $oldbiblio = MARCmarc2koha($dbh,$record,$frameworkcode);
1357 my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
1358 OLDmodbibitem($dbh,$oldbiblio);
1359 # now, modify addi authors, subject, addititles.
1360 my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"additionalauthors.author",$frameworkcode);
1361 my @addiauthfields = $record->field($tagfield);
1362 foreach my $addiauthfield (@addiauthfields) {
1363 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1364 $dbh->do("delete from additionalauthors where biblionumber=$oldbiblionumber");
1365 foreach my $subfieldcount (0..$#addiauthsubfields) {
1366 OLDmodaddauthor($dbh,$oldbiblionumber,$addiauthsubfields[$subfieldcount]);
1369 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubtitle.subtitle",$frameworkcode);
1370 my @subtitlefields = $record->field($tagfield);
1371 foreach my $subtitlefield (@subtitlefields) {
1372 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1373 # delete & create subtitle again because OLDmodsubtitle can't handle new subtitles
1375 $dbh->do("delete from bibliosubtitle where biblionumber=$oldbiblionumber");
1376 foreach my $subfieldcount (0..$#subtitlesubfields) {
1377 foreach my $subtit(split /\||#/,$subtitlesubfields[$subfieldcount]) {
1378 OLDnewsubtitle($dbh,$oldbiblionumber,$subtit);
1382 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject",$frameworkcode);
1383 my @subj = $record->field($tagfield);
1385 foreach my $subject (@subj) {
1386 my @subjsubfield = $subject->subfield($tagsubfield);
1387 foreach my $subfieldcount (0..$#subjsubfield) {
1388 push @subjects,$subjsubfield[$subfieldcount];
1391 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"items.itemnotes",$frameworkcode);
1392 my @notes = $record->field($tagfield);
1394 foreach my $note (@notes) {
1395 my @itemnotefields = $note->subfield($tagsubfield);
1396 foreach my $subfieldcount (0..$#itemnotes) {
1397 push @itemnotes,$itemnotefields[$subfieldcount];
1400 OLDmodsubject($dbh,$oldbiblionumber,1,@subjects);
1405 my ( $dbh, $bibid ) = @_;
1406 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1407 &OLDdelbiblio( $dbh, $biblio );
1410 "select biblioitemnumber from biblioitems where biblionumber=?");
1411 $sth->execute($biblio);
1412 while ( my ($biblioitemnumber) = $sth->fetchrow ) {
1413 OLDdeletebiblioitem( $dbh, $biblioitemnumber );
1415 &MARCdelbiblio( $dbh, $bibid, 0 );
1419 my ( $dbh, $record, $bibid ) = @_;
1421 # add item in old-DB
1422 my $frameworkcode=MARCfind_frameworkcode($dbh,$bibid);
1423 my $item = &MARCmarc2koha( $dbh, $record,$frameworkcode );
1424 # needs old biblionumber and biblioitemnumber
1425 $item->{'biblionumber'} =
1426 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1429 "select biblioitemnumber from biblioitems where biblionumber=?");
1430 $sth->execute( $item->{'biblionumber'} );
1431 ( $item->{'biblioitemnumber'} ) = $sth->fetchrow;
1432 my ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, $item->{barcode} );
1434 # add itemnumber to MARC::Record before adding the item.
1437 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
1439 &MARCkoha2marcOnefield( $sth, $record, "items.itemnumber", $itemnumber,$frameworkcode );
1442 my $bib = &MARCadditem( $dbh, $record, $item->{'biblionumber'} );
1446 my ( $dbh, $record, $bibid, $itemnumber, $delete ) = @_;
1447 &MARCmoditem( $dbh, $record, $bibid, $itemnumber, $delete );
1448 my $frameworkcode=MARCfind_frameworkcode($dbh,$bibid);
1449 my $olditem = MARCmarc2koha( $dbh, $record,$frameworkcode );
1450 OLDmoditem( $dbh, $olditem );
1454 my ( $dbh, $bibid, $itemnumber ) = @_;
1455 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1456 &OLDdelitem( $dbh, $itemnumber );
1457 &MARCdelitem( $dbh, $bibid, $itemnumber );
1462 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
1466 =item $biblionumber = OLDnewbiblio($dbh,$biblio);
1468 adds a record in biblio table. Datas are in the hash $biblio.
1470 =item $biblionumber = OLDmodbiblio($dbh,$biblio);
1472 modify a record in biblio table. Datas are in the hash $biblio.
1474 =item OLDmodsubtitle($dbh,$bibnum,$subtitle);
1476 modify subtitles in bibliosubtitle table.
1478 =item OLDmodaddauthor($dbh,$bibnum,$author);
1480 adds or modify additional authors
1481 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1483 =item $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1485 modify/adds subjects
1487 =item OLDmodbibitem($dbh, $biblioitem);
1491 =item OLDmodnote($dbh,$bibitemnum,$note
1493 modify a note for a biblioitem
1495 =item OLDnewbiblioitem($dbh,$biblioitem);
1497 adds a biblioitem ($biblioitem is a hash with the values)
1499 =item OLDnewsubject($dbh,$bibnum);
1503 =item OLDnewsubtitle($dbh,$bibnum,$subtitle);
1505 create a new subtitle
1507 =item ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1509 create a item. $item is a hash and $barcode the barcode.
1511 =item OLDmoditem($dbh,$item);
1515 =item OLDdelitem($dbh,$itemnum);
1519 =item OLDdeletebiblioitem($dbh,$biblioitemnumber);
1521 deletes a biblioitem
1522 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1524 =item OLDdelbiblio($dbh,$biblio);
1531 my ( $dbh, $biblio ) = @_;
1533 # my $dbh = &C4Connect;
1534 my $sth = $dbh->prepare("Select max(biblionumber) from biblio");
1536 my $data = $sth->fetchrow_arrayref;
1537 my $bibnum = $$data[0] + 1;
1540 if ( $biblio->{'seriestitle'} ) { $series = 1 }
1544 "insert into biblio set biblionumber = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?, unititle = ?"
1547 $bibnum, $biblio->{'title'},
1548 $biblio->{'author'}, $biblio->{'copyrightdate'},
1549 $biblio->{'serial'}, $biblio->{'seriestitle'},
1550 $biblio->{'notes'}, $biblio->{'abstract'},
1551 $biblio->{'unititle'},
1561 my ( $dbh, $biblio ) = @_;
1563 # my $dbh = C4Connect;
1570 "Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?, seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?"
1573 $biblio->{'title'}, $biblio->{'author'},
1574 $biblio->{'abstract'}, $biblio->{'copyrightdate'},
1575 $biblio->{'seriestitle'}, $biblio->{'serial'},
1576 $biblio->{'unititle'}, $biblio->{'notes'},
1577 $biblio->{'biblionumber'}
1581 return ( $biblio->{'biblionumber'} );
1584 sub OLDmodsubtitle {
1585 my ( $dbh, $bibnum, $subtitle ) = @_;
1588 "update bibliosubtitle set subtitle = ? where biblionumber = ?");
1589 $sth->execute( $subtitle, $bibnum );
1593 sub OLDmodaddauthor {
1594 my ( $dbh, $bibnum, @authors ) = @_;
1596 # my $dbh = C4Connect;
1598 $dbh->prepare("Delete from additionalauthors where biblionumber = ?");
1600 $sth->execute($bibnum);
1602 foreach my $author (@authors) {
1603 if ( $author ne '' ) {
1606 "Insert into additionalauthors set author = ?, biblionumber = ?"
1609 $sth->execute( $author, $bibnum );
1614 } # sub modaddauthor
1617 my ( $dbh, $bibnum, $force, @subject ) = @_;
1619 # my $dbh = C4Connect;
1620 my $count = @subject;
1622 for ( my $i = 0 ; $i < $count ; $i++ ) {
1623 $subject[$i] =~ s/^ //g;
1624 $subject[$i] =~ s/ $//g;
1627 "select * from catalogueentry where entrytype = 's' and catalogueentry = ?"
1629 $sth->execute( $subject[$i] );
1631 if ( my $data = $sth->fetchrow_hashref ) {
1634 if ( $force eq $subject[$i] || $force == 1 ) {
1636 # subject not in aut, chosen to force anway
1637 # so insert into cataloguentry so its in auth file
1640 "Insert into catalogueentry (entrytype,catalogueentry) values ('s',?)"
1643 $sth2->execute( $subject[$i] ) if ( $subject[$i] );
1648 "$subject[$i]\n does not exist in the subject authority file";
1651 "Select * from catalogueentry where entrytype = 's' and (catalogueentry like ? or catalogueentry like ? or catalogueentry like ?)"
1653 $sth2->execute( "$subject[$i] %", "% $subject[$i] %",
1655 while ( my $data = $sth2->fetchrow_hashref ) {
1656 $error .= "<br>$data->{'catalogueentry'}";
1665 $dbh->prepare("Delete from bibliosubject where biblionumber = ?");
1666 $sth->execute($bibnum);
1670 "Insert into bibliosubject (subject,biblionumber) values (?,?)");
1672 foreach $query (@subject) {
1673 $sth->execute( $query, $bibnum ) if ( $query && $bibnum );
1683 my ( $dbh, $biblioitem ) = @_;
1686 $biblioitem->{'itemtype'} = $dbh->quote( $biblioitem->{'itemtype'} );
1687 $biblioitem->{'url'} = $dbh->quote( $biblioitem->{'url'} );
1688 $biblioitem->{'isbn'} = $dbh->quote( $biblioitem->{'isbn'} );
1689 $biblioitem->{'issn'} = $dbh->quote( $biblioitem->{'issn'} );
1690 $biblioitem->{'publishercode'} =
1691 $dbh->quote( $biblioitem->{'publishercode'} );
1692 $biblioitem->{'publicationyear'} =
1693 $dbh->quote( $biblioitem->{'publicationyear'} );
1694 $biblioitem->{'classification'} =
1695 $dbh->quote( $biblioitem->{'classification'} );
1696 $biblioitem->{'dewey'} = $dbh->quote( $biblioitem->{'dewey'} );
1697 $biblioitem->{'subclass'} = $dbh->quote( $biblioitem->{'subclass'} );
1698 $biblioitem->{'illus'} = $dbh->quote( $biblioitem->{'illus'} );
1699 $biblioitem->{'pages'} = $dbh->quote( $biblioitem->{'pages'} );
1700 $biblioitem->{'volumeddesc'} = $dbh->quote( $biblioitem->{'volumeddesc'} );
1701 $biblioitem->{'volumedate'} = $dbh->quote( $biblioitem->{'volumedate'} );
1702 $biblioitem->{'bnotes'} = $dbh->quote( $biblioitem->{'bnotes'} );
1703 $biblioitem->{'size'} = $dbh->quote( $biblioitem->{'size'} );
1704 $biblioitem->{'place'} = $dbh->quote( $biblioitem->{'place'} );
1705 $biblioitem->{'volume'} = $dbh->quote( $biblioitem->{'volume'} );
1706 $biblioitem->{'number'} = $dbh->quote( $biblioitem->{'number'} );
1707 $biblioitem->{'lccn'} = $dbh->quote( $biblioitem->{'lccn'} );
1709 $query = "Update biblioitems set
1710 itemtype = $biblioitem->{'itemtype'},
1711 url = $biblioitem->{'url'},
1712 isbn = $biblioitem->{'isbn'},
1713 issn = $biblioitem->{'issn'},
1714 publishercode = $biblioitem->{'publishercode'},
1715 publicationyear = $biblioitem->{'publicationyear'},
1716 classification = $biblioitem->{'classification'},
1717 dewey = $biblioitem->{'dewey'},
1718 subclass = $biblioitem->{'subclass'},
1719 illus = $biblioitem->{'illus'},
1720 pages = $biblioitem->{'pages'},
1721 volumeddesc = $biblioitem->{'volumeddesc'},
1722 volumedate = $biblioitem->{'volumedate'},
1723 notes = $biblioitem->{'bnotes'},
1724 size = $biblioitem->{'size'},
1725 place = $biblioitem->{'place'},
1726 volume = $biblioitem->{'volume'},
1727 number = $biblioitem->{'number'},
1728 lccn = $biblioitem->{'lccn'}
1730 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1733 if ( $dbh->errstr ) {
1739 my ( $dbh, $bibitemnum, $note ) = @_;
1741 # my $dbh=C4Connect;
1742 my $query = "update biblioitems set notes='$note' where
1743 biblioitemnumber='$bibitemnum'";
1744 my $sth = $dbh->prepare($query);
1751 sub OLDnewbiblioitem {
1752 my ( $dbh, $biblioitem ) = @_;
1754 # my $dbh = C4Connect;
1755 my $sth = $dbh->prepare("Select max(biblioitemnumber) from biblioitems");
1760 $data = $sth->fetchrow_arrayref;
1761 $bibitemnum = $$data[0] + 1;
1765 $sth = $dbh->prepare( "insert into biblioitems set
1766 biblioitemnumber = ?, biblionumber = ?,
1767 volume = ?, number = ?,
1768 classification = ?, itemtype = ?,
1770 issn = ?, dewey = ?,
1771 subclass = ?, publicationyear = ?,
1772 publishercode = ?, volumedate = ?,
1773 volumeddesc = ?, illus = ?,
1774 pages = ?, notes = ?,
1776 marc = ?, place = ?"
1779 $bibitemnum, $biblioitem->{'biblionumber'},
1780 $biblioitem->{'volume'}, $biblioitem->{'number'},
1781 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
1782 $biblioitem->{'url'}, $biblioitem->{'isbn'},
1783 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
1784 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
1785 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
1786 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
1787 $biblioitem->{'pages'}, $biblioitem->{'bnotes'},
1788 $biblioitem->{'size'}, $biblioitem->{'lccn'},
1789 $biblioitem->{'marc'}, $biblioitem->{'place'}
1794 return ($bibitemnum);
1798 my ( $dbh, $bibnum ) = @_;
1800 $dbh->prepare("insert into bibliosubject (biblionumber) values (?)");
1801 $sth->execute($bibnum);
1805 sub OLDnewsubtitle {
1806 my ( $dbh, $bibnum, $subtitle ) = @_;
1809 "insert into bibliosubtitle set biblionumber = ?, subtitle = ?");
1810 $sth->execute( $bibnum, $subtitle ) if $subtitle;
1815 my ( $dbh, $item, $barcode ) = @_;
1817 # my $dbh = C4Connect;
1818 my $sth = $dbh->prepare("Select max(itemnumber) from items");
1824 my ($maxitemnumber)= $sth->fetchrow;
1825 $itemnumber = $maxitemnumber + 1;
1828 # FIXME the "notforloan" field seems to be named "loan" in some places. workaround bugfix.
1829 if ( $item->{'loan'} ) {
1830 $item->{'notforloan'} = $item->{'loan'};
1833 # if dateaccessioned is provided, use it. Otherwise, set to NOW()
1834 if ( $item->{'dateaccessioned'} ) {
1835 $sth = $dbh->prepare( "Insert into items set
1836 itemnumber = ?, biblionumber = ?,
1837 multivolumepart = ?,
1838 biblioitemnumber = ?, barcode = ?,
1839 booksellerid = ?, dateaccessioned = ?,
1840 homebranch = ?, holdingbranch = ?,
1841 price = ?, replacementprice = ?,
1842 replacementpricedate = NOW(), datelastseen = NOW(),
1843 multivolume = ?, stack = ?,
1844 itemlost = ?, wthdrawn = ?,
1845 paidfor = ?, itemnotes = ?,
1846 itemcallnumber =?, notforloan = ?,
1851 $itemnumber, $item->{'biblionumber'},
1852 $item->{'multivolumepart'},
1853 $item->{'biblioitemnumber'},$barcode,
1854 $item->{'booksellerid'}, $item->{'dateaccessioned'},
1855 $item->{'homebranch'}, $item->{'holdingbranch'},
1856 $item->{'price'}, $item->{'replacementprice'},
1857 $item->{multivolume}, $item->{stack},
1858 $item->{itemlost}, $item->{wthdrawn},
1859 $item->{paidfor}, $item->{'itemnotes'},
1860 $item->{'itemcallnumber'}, $item->{'notforloan'},
1865 $sth = $dbh->prepare( "Insert into items set
1866 itemnumber = ?, biblionumber = ?,
1867 multivolumepart = ?,
1868 biblioitemnumber = ?, barcode = ?,
1869 booksellerid = ?, dateaccessioned = NOW(),
1870 homebranch = ?, holdingbranch = ?,
1871 price = ?, replacementprice = ?,
1872 replacementpricedate = NOW(), datelastseen = NOW(),
1873 multivolume = ?, stack = ?,
1874 itemlost = ?, wthdrawn = ?,
1875 paidfor = ?, itemnotes = ?,
1876 itemcallnumber =?, notforloan = ?,
1881 $itemnumber, $item->{'biblionumber'},
1882 $item->{'multivolumepart'},
1883 $item->{'biblioitemnumber'},$barcode,
1884 $item->{'booksellerid'},
1885 $item->{'homebranch'}, $item->{'holdingbranch'},
1886 $item->{'price'}, $item->{'replacementprice'},
1887 $item->{multivolume}, $item->{stack},
1888 $item->{itemlost}, $item->{wthdrawn},
1889 $item->{paidfor}, $item->{'itemnotes'},
1890 $item->{'itemcallnumber'}, $item->{'notforloan'},
1894 if ( defined $sth->errstr ) {
1895 $error .= $sth->errstr;
1898 return ( $itemnumber, $error );
1902 my ( $dbh, $item ) = @_;
1903 $item->{'itemnum'} = $item->{'itemnumber'} unless $item->{'itemnum'};
1904 my $query = "update items set barcode=?,itemnotes=?,itemcallnumber=?,notforloan=?,location=?,multivolumepart=?,multivolume=?,stack=?,wthdrawn=?";
1906 $item->{'barcode'}, $item->{'itemnotes'},
1907 $item->{'itemcallnumber'}, $item->{'notforloan'},
1908 $item->{'location'}, $item->{multivolumepart},
1909 $item->{multivolume}, $item->{stack},
1912 if ( $item->{'lost'} ne '' ) {
1913 $query = "update items set biblioitemnumber=?,barcode=?,itemnotes=?,homebranch=?,
1914 itemlost=?,wthdrawn=?,itemcallnumber=?,notforloan=?,
1915 location=?,multivolumepart=?,multivolume=?,stack=?,wthdrawn=?";
1917 $item->{'bibitemnum'}, $item->{'barcode'},
1918 $item->{'itemnotes'}, $item->{'homebranch'},
1919 $item->{'lost'}, $item->{'wthdrawn'},
1920 $item->{'itemcallnumber'}, $item->{'notforloan'},
1921 $item->{'location'}, $item->{multivolumepart},
1922 $item->{multivolume}, $item->{stack},
1925 if ($item->{homebranch}) {
1926 $query.=",homebranch=?";
1927 push @bind, $item->{homebranch};
1929 if ($item->{holdingbranch}) {
1930 $query.=",holdingbranch=?";
1931 push @bind, $item->{holdingbranch};
1934 $query.=" where itemnumber=?";
1935 push @bind,$item->{'itemnum'};
1936 if ( $item->{'replacement'} ne '' ) {
1937 $query =~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1939 my $sth = $dbh->prepare($query);
1940 $sth->execute(@bind);
1947 my ( $dbh, $itemnum ) = @_;
1949 # my $dbh=C4Connect;
1950 my $sth = $dbh->prepare("select * from items where itemnumber=?");
1951 $sth->execute($itemnum);
1952 my $data = $sth->fetchrow_hashref;
1954 my $query = "Insert into deleteditems set ";
1956 foreach my $temp ( keys %$data ) {
1957 $query .= "$temp = ?,";
1958 push ( @bind, $data->{$temp} );
1963 $sth = $dbh->prepare($query);
1964 $sth->execute(@bind);
1966 $sth = $dbh->prepare("Delete from items where itemnumber=?");
1967 $sth->execute($itemnum);
1973 sub OLDdeletebiblioitem {
1974 my ( $dbh, $biblioitemnumber ) = @_;
1976 # my $dbh = C4Connect;
1977 my $sth = $dbh->prepare( "Select * from biblioitems
1978 where biblioitemnumber = ?"
1982 $sth->execute($biblioitemnumber);
1984 if ( $results = $sth->fetchrow_hashref ) {
1988 "Insert into deletedbiblioitems (biblioitemnumber, biblionumber, volume, number, classification, itemtype,
1989 isbn, issn ,dewey ,subclass ,publicationyear ,publishercode ,volumedate ,volumeddesc ,timestamp ,illus ,
1990 pages ,notes ,size ,url ,lccn ) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
1994 $results->{biblioitemnumber}, $results->{biblionumber},
1995 $results->{volume}, $results->{number},
1996 $results->{classification}, $results->{itemtype},
1997 $results->{isbn}, $results->{issn},
1998 $results->{dewey}, $results->{subclass},
1999 $results->{publicationyear}, $results->{publishercode},
2000 $results->{volumedate}, $results->{volumeddesc},
2001 $results->{timestamp}, $results->{illus},
2002 $results->{pages}, $results->{notes},
2003 $results->{size}, $results->{url},
2007 $dbh->prepare("Delete from biblioitems where biblioitemnumber = ?");
2008 $sth2->execute($biblioitemnumber);
2013 # Now delete all the items attached to the biblioitem
2014 $sth = $dbh->prepare("Select * from items where biblioitemnumber = ?");
2015 $sth->execute($biblioitemnumber);
2017 while ( my $data = $sth->fetchrow_hashref ) {
2018 my $query = "Insert into deleteditems set ";
2020 foreach my $temp ( keys %$data ) {
2021 next if ($temp =~/itemcallnumber/);
2022 $query .= "$temp = ?,";
2023 push ( @bind, $data->{$temp} );
2026 my $sth2 = $dbh->prepare($query);
2027 $sth2->execute(@bind);
2030 $sth = $dbh->prepare("Delete from items where biblioitemnumber = ?");
2031 $sth->execute($biblioitemnumber);
2035 } # sub deletebiblioitem
2038 my ( $dbh, $biblio ) = @_;
2039 my $sth = $dbh->prepare("select * from biblio where biblionumber=?");
2040 $sth->execute($biblio);
2041 if ( my $data = $sth->fetchrow_hashref ) {
2043 my $query = "Insert into deletedbiblio set ";
2045 foreach my $temp ( keys %$data ) {
2046 $query .= "$temp = ?,";
2047 push ( @bind, $data->{$temp} );
2050 #replacing the last , by ",?)"
2052 $sth = $dbh->prepare($query);
2053 $sth->execute(@bind);
2055 $sth = $dbh->prepare("Delete from biblio where biblionumber=?");
2056 $sth->execute($biblio);
2070 my $dbh = C4::Context->dbh;
2073 my $sth = $dbh->prepare("Select count(*) from items where biblionumber=?");
2074 $sth->execute($biblio);
2075 my $data = $sth->fetchrow_hashref;
2077 return ( $data->{'count(*)'} );
2082 my $dbh = C4::Context->dbh;
2083 my $bibnum = OLDnewbiblio( $dbh, $biblio );
2084 # finds new (MARC bibid
2085 # my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
2086 my $record = &MARCkoha2marcBiblio( $dbh, $bibnum );
2087 MARCaddbiblio( $dbh, $record, $bibnum,'' );
2093 $biblionumber = &modbiblio($biblio);
2095 Update a biblio record.
2097 C<$biblio> is a reference-to-hash whose keys are the fields in the
2098 biblio table in the Koha database. All fields must be present, not
2099 just the ones you wish to change.
2101 C<&modbiblio> updates the record defined by
2102 C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
2104 C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
2111 my $dbh = C4::Context->dbh;
2112 my $biblionumber=OLDmodbiblio($dbh,$biblio);
2113 my $record = MARCkoha2marcBiblio($dbh,$biblionumber,$biblionumber);
2114 # finds new (MARC bibid
2115 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
2116 MARCmodbiblio($dbh,$bibid,$record,"",0);
2117 return($biblionumber);
2122 &modsubtitle($biblionumber, $subtitle);
2124 Sets the subtitle of a book.
2126 C<$biblionumber> is the biblionumber of the book to modify.
2128 C<$subtitle> is the new subtitle.
2133 my ( $bibnum, $subtitle ) = @_;
2134 my $dbh = C4::Context->dbh;
2135 &OLDmodsubtitle( $dbh, $bibnum, $subtitle );
2140 &modaddauthor($biblionumber, $author);
2142 Replaces all additional authors for the book with biblio number
2143 C<$biblionumber> with C<$author>. If C<$author> is the empty string,
2144 C<&modaddauthor> deletes all additional authors.
2149 my ( $bibnum, @authors ) = @_;
2150 my $dbh = C4::Context->dbh;
2151 &OLDmodaddauthor( $dbh, $bibnum, @authors );
2152 } # sub modaddauthor
2156 $error = &modsubject($biblionumber, $force, @subjects);
2158 $force - a subject to force
2160 $error - Error message, or undef if successful.
2165 my ( $bibnum, $force, @subject ) = @_;
2166 my $dbh = C4::Context->dbh;
2167 my $error = &OLDmodsubject( $dbh, $bibnum, $force, @subject );
2169 # When MARC is off, ensures that the MARC biblio table gets updated with new
2170 # subjects, of course, it deletes the biblio in marc, and then recreates.
2171 # This check is to ensure that no MARC data exists to lose.
2172 if (C4::Context->preference("MARC") eq '0'){
2173 my $MARCRecord = &MARCkoha2marcBiblio($dbh,$bibnum);
2174 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
2175 &MARCmodbiblio($dbh,$bibid, $MARCRecord);
2182 my ($biblioitem) = @_;
2183 my $dbh = C4::Context->dbh;
2184 &OLDmodbibitem( $dbh, $biblioitem );
2188 my ( $bibitemnum, $note ) = @_;
2189 my $dbh = C4::Context->dbh;
2190 &OLDmodnote( $dbh, $bibitemnum, $note );
2194 my ($biblioitem) = @_;
2195 my $dbh = C4::Context->dbh;
2196 my $bibitemnum = &OLDnewbiblioitem( $dbh, $biblioitem );
2199 MARCkoha2marcBiblio( $dbh, $biblioitem->{biblionumber}, $bibitemnum );
2200 # the 0 means "do NOT retrieve biblio, only biblioitem, in the MARC record
2202 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh,
2203 $biblioitem->{biblionumber} );
2204 # delete biblio, as we will reintroduce it the line after
2205 # the biblio is complete from MARCkoha2marcBiblio (3 lines before)
2206 &MARCdelbiblio($dbh,$bibid,1);
2207 &MARCaddbiblio( $dbh, $MARCbiblio, $biblioitem->{biblionumber}, '',$bibid );
2208 return ($bibitemnum);
2213 my $dbh = C4::Context->dbh;
2214 &OLDnewsubject( $dbh, $bibnum );
2218 my ( $bibnum, $subtitle ) = @_;
2219 my $dbh = C4::Context->dbh;
2220 &OLDnewsubtitle( $dbh, $bibnum, $subtitle );
2224 my ( $item, @barcodes ) = @_;
2225 my $dbh = C4::Context->dbh;
2229 foreach my $barcode (@barcodes) {
2230 ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, uc($barcode) );
2233 &MARCkoha2marcItem( $dbh, $item->{biblionumber}, $itemnumber );
2234 &MARCadditem( $dbh, $MARCitem, $item->{biblionumber} );
2241 my $dbh = C4::Context->dbh;
2242 &OLDmoditem( $dbh, $item );
2244 &MARCkoha2marcItem( $dbh, $item->{'biblionumber'}, $item->{'itemnum'} );
2246 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $item->{biblionumber} );
2247 &MARCmoditem( $dbh, $MARCitem, $bibid, $item->{itemnum}, 0 );
2251 my ( $count, @barcodes ) = @_;
2252 my $dbh = C4::Context->dbh;
2254 my $sth = $dbh->prepare("Select * from items where barcode=?");
2255 for ( my $i = 0 ; $i < $count ; $i++ ) {
2256 $barcodes[$i] = uc $barcodes[$i];
2257 $sth->execute( $barcodes[$i] );
2258 if ( my $data = $sth->fetchrow_hashref ) {
2259 $error .= " Duplicate Barcode: $barcodes[$i]";
2267 my ($bibitemnum) = @_;
2268 my $dbh = C4::Context->dbh;
2271 $dbh->prepare("Select count(*) from items where biblioitemnumber=?");
2272 $sth->execute($bibitemnum);
2273 my $data = $sth->fetchrow_hashref;
2275 return ( $data->{'count(*)'} );
2280 my $dbh = C4::Context->dbh;
2281 &OLDdelitem( $dbh, $itemnum );
2284 sub deletebiblioitem {
2285 my ($biblioitemnumber) = @_;
2286 my $dbh = C4::Context->dbh;
2287 &OLDdeletebiblioitem( $dbh, $biblioitemnumber );
2288 } # sub deletebiblioitem
2292 my $dbh = C4::Context->dbh;
2293 &OLDdelbiblio( $dbh, $biblio );
2294 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $biblio );
2295 &MARCdelbiblio( $dbh, $bibid, 0 );
2299 my ($biblionumber) = @_;
2300 my $dbh = C4::Context->dbh;
2301 my $sth = $dbh->prepare("Select * from biblio where biblionumber = ?");
2303 # || die "Cannot prepare $query\n" . $dbh->errstr;
2307 $sth->execute($biblionumber);
2309 # || die "Cannot execute $query\n" . $sth->errstr;
2310 while ( my $data = $sth->fetchrow_hashref ) {
2311 $results[$count] = $data;
2316 return ( $count, @results );
2320 my ($biblioitemnum) = @_;
2321 my $dbh = C4::Context->dbh;
2322 my $sth = $dbh->prepare( "Select * from biblioitems where
2323 biblioitemnumber = ?"
2328 $sth->execute($biblioitemnum);
2330 while ( my $data = $sth->fetchrow_hashref ) {
2331 $results[$count] = $data;
2336 return ( $count, @results );
2337 } # sub getbiblioitem
2339 sub getbiblioitembybiblionumber {
2340 my ($biblionumber) = @_;
2341 my $dbh = C4::Context->dbh;
2342 my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?");
2346 $sth->execute($biblionumber);
2348 while ( my $data = $sth->fetchrow_hashref ) {
2349 $results[$count] = $data;
2354 return ( $count, @results );
2358 my $dbh = C4::Context->dbh;
2359 my $query = "select * from itemtypes order by description";
2360 my $sth = $dbh->prepare($query);
2362 # || die "Cannot prepare $query" . $dbh->errstr;
2368 # || die "Cannot execute $query\n" . $sth->errstr;
2369 while ( my $data = $sth->fetchrow_hashref ) {
2370 $results[$count] = $data;
2375 return ( $count, @results );
2376 } # sub getitemtypes
2378 sub getitemsbybiblioitem {
2379 my ($biblioitemnum) = @_;
2380 my $dbh = C4::Context->dbh;
2381 my $sth = $dbh->prepare( "Select * from items, biblio where
2382 biblio.biblionumber = items.biblionumber and biblioitemnumber
2386 # || die "Cannot prepare $query\n" . $dbh->errstr;
2390 $sth->execute($biblioitemnum);
2392 # || die "Cannot execute $query\n" . $sth->errstr;
2393 while ( my $data = $sth->fetchrow_hashref ) {
2394 $results[$count] = $data;
2399 return ( $count, @results );
2400 } # sub getitemsbybiblioitem
2404 # Subroutine to log changes to databases
2405 # Eventually, this subroutine will be used to create a log of all changes made,
2406 # with the possibility of "undo"ing some changes
2407 my $database = shift;
2408 if ( $database eq 'kohadb' ) {
2410 my $section = shift;
2412 my $original = shift;
2415 # print STDERR "KOHA: $type $section $item $original $new\n";
2417 elsif ( $database eq 'marc' ) {
2419 my $Record_ID = shift;
2422 my $subfield_ID = shift;
2423 my $original = shift;
2426 # print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2430 #------------------------------------------------
2432 #---------------------------------------
2433 # Find a biblio entry, or create a new one if it doesn't exist.
2434 # If a "subtitle" entry is in hash, add it to subtitle table
2435 sub getoraddbiblio {
2440 # FIXME - Unused argument
2441 $biblio, # hash ref to fields
2452 $dbh = C4::Context->dbh;
2454 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2455 $sth = $dbh->prepare( "select biblionumber
2457 where title=? and author=?
2458 and copyrightdate=? and seriestitle=?"
2461 $biblio->{title}, $biblio->{author},
2462 $biblio->{copyright}, $biblio->{seriestitle}
2465 ($biblionumber) = $sth->fetchrow;
2466 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2470 # Doesn't exist. Add new one.
2471 print "<PRE>Adding biblio</PRE>\n" if $debug;
2472 ( $biblionumber, $error ) = &newbiblio($biblio);
2473 if ($biblionumber) {
2474 print "<PRE>Added with biblio number=$biblionumber</PRE>\n"
2476 if ( $biblio->{subtitle} ) {
2477 &newsubtitle( $biblionumber, $biblio->{subtitle} );
2481 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2485 return $biblionumber, $error;
2487 } # sub getoraddbiblio
2491 # converts ISO 5426 coded string to ISO 8859-1
2492 # sloppy code : should be improved in next issue
2493 my ( $string, $encoding ) = @_;
2496 # $encoding = C4::Context->preference("marcflavour") unless $encoding;
2497 if ( $encoding eq "UNIMARC" ) {
2566 # this handles non-sorting blocks (if implementation requires this)
2567 $string = nsb_clean($_);
2569 elsif ( $encoding eq "USMARC" || $encoding eq "MARC21" ) {
2570 if (/[\xc1-\xff]/) {
2623 # this handles non-sorting blocks (if implementation requires this)
2624 $string = nsb_clean($_);
2631 my $NSB = '\x88'; # NSB : begin Non Sorting Block
2632 my $NSE = '\x89'; # NSE : Non Sorting Block end
2633 # handles non sorting blocks
2637 s/[ ]{0,1}$NSE/) /gm;
2644 my $dbh = C4::Context->dbh;
2645 my $result = MARCmarc2koha($dbh,$record,'');
2647 my ($biblionumber,$bibid,$title);
2648 # search duplicate on ISBN, easy and fast...
2649 if ($result->{isbn}) {
2650 $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=?");
2651 $sth->execute($result->{'isbn'});
2652 ($biblionumber,$bibid,$title) = $sth->fetchrow;
2653 return $biblionumber,$bibid,$title if ($biblionumber);
2655 # a more complex search : build a request for SearchMarc::catalogsearch()
2656 my (@tags, @and_or, @excluding, @operator, @value, $offset,$length);
2657 # search on biblio.title
2658 my ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblio.title","");
2659 if ($record->field($tag)) {
2660 if ($record->field($tag)->subfields($subfield)) {
2661 push @tags, "'".$tag.$subfield."'";
2662 push @and_or, "and";
2663 push @excluding, "";
2664 push @operator, "contains";
2665 push @value, $record->field($tag)->subfield($subfield);
2666 # warn "for title, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2669 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubtitle.subtitle","");
2670 if ($record->field($tag)) {
2671 if ($record->field($tag)->subfields($subfield)) {
2672 push @tags, "'".$tag.$subfield."'";
2673 push @and_or, "and";
2674 push @excluding, "";
2675 push @operator, "contains";
2676 push @value, $record->field($tag)->subfield($subfield);
2677 # warn "for title, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2680 # ... and on biblio.author
2681 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblio.author","");
2682 if ($record->field($tag)) {
2683 if ($record->field($tag)->subfields($subfield)) {
2684 push @tags, "'".$tag.$subfield."'";
2685 push @and_or, "and";
2686 push @excluding, "";
2687 push @operator, "contains";
2688 push @value, $record->field($tag)->subfield($subfield);
2689 # warn "for author, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2692 # ... and on publicationyear.
2693 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.publicationyear","");
2694 if ($record->field($tag)) {
2695 if ($record->field($tag)->subfields($subfield)) {
2696 push @tags, "'".$tag.$subfield."'";
2697 push @and_or, "and";
2698 push @excluding, "";
2699 push @operator, "=";
2700 push @value, $record->field($tag)->subfield($subfield);
2701 # warn "for publicationyear, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2705 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.size","");
2706 if ($record->field($tag)) {
2707 if ($record->field($tag)->subfields($subfield)) {
2708 push @tags, "'".$tag.$subfield."'";
2709 push @and_or, "and";
2710 push @excluding, "";
2711 push @operator, "=";
2712 push @value, $record->field($tag)->subfield($subfield);
2713 # warn "for size, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2716 # ... and on publisher.
2717 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.publishercode","");
2718 if ($record->field($tag)) {
2719 if ($record->field($tag)->subfields($subfield)) {
2720 push @tags, "'".$tag.$subfield."'";
2721 push @and_or, "and";
2722 push @excluding, "";
2723 push @operator, "=";
2724 push @value, $record->field($tag)->subfield($subfield);
2725 # warn "for publishercode, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2728 # ... and on volume.
2729 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.volume","");
2730 if ($record->field($tag)) {
2731 if ($record->field($tag)->subfields($subfield)) {
2732 push @tags, "'".$tag.$subfield."'";
2733 push @and_or, "and";
2734 push @excluding, "";
2735 push @operator, "=";
2736 push @value, $record->field($tag)->subfield($subfield);
2737 # warn "for volume, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2741 my ($finalresult,$nbresult) = C4::SearchMarc::catalogsearch($dbh,\@tags,\@and_or,\@excluding,\@operator,\@value,0,10);
2742 # there is at least 1 result => return the 1st one
2744 # warn "$nbresult => ".@$finalresult[0]->{biblionumber},@$finalresult[0]->{bibid},@$finalresult[0]->{title};
2745 return @$finalresult[0]->{biblionumber},@$finalresult[0]->{bibid},@$finalresult[0]->{title};
2747 # no result, returns nothing
2754 if(substr($isbn, 0, 1) <=7) {
2755 $seg1 = substr($isbn, 0, 1);
2756 } elsif(substr($isbn, 0, 2) <= 94) {
2757 $seg1 = substr($isbn, 0, 2);
2758 } elsif(substr($isbn, 0, 3) <= 995) {
2759 $seg1 = substr($isbn, 0, 3);
2760 } elsif(substr($isbn, 0, 4) <= 9989) {
2761 $seg1 = substr($isbn, 0, 4);
2763 $seg1 = substr($isbn, 0, 5);
2765 my $x = substr($isbn, length($seg1));
2767 if(substr($x, 0, 2) <= 19) {
2768 # if(sTmp2 < 10) sTmp2 = "0" sTmp2;
2769 $seg2 = substr($x, 0, 2);
2770 } elsif(substr($x, 0, 3) <= 699) {
2771 $seg2 = substr($x, 0, 3);
2772 } elsif(substr($x, 0, 4) <= 8399) {
2773 $seg2 = substr($x, 0, 4);
2774 } elsif(substr($x, 0, 5) <= 89999) {
2775 $seg2 = substr($x, 0, 5);
2776 } elsif(substr($x, 0, 6) <= 9499999) {
2777 $seg2 = substr($x, 0, 6);
2779 $seg2 = substr($x, 0, 7);
2781 my $seg3=substr($x,length($seg2));
2782 $seg3=substr($seg3,0,length($seg3)-1) ;
2783 my $seg4 = substr($x, -1, 1);
2784 return "$seg1-$seg2-$seg3-$seg4";
2787 =head2 getitemstatus
2789 $itemstatushash = &getitemstatus($fwkcode);
2790 returns information about status.
2791 Can be MARC dependant.
2792 fwkcode is optional.
2793 But basically could be can be loan or not
2794 Create a status selector with the following code
2796 =head3 in PERL SCRIPT
2798 my $itemstatushash = getitemstatus;
2800 foreach my $thisstatus (keys %$itemstatushash) {
2801 my %row =(value => $thisstatus,
2802 statusname => $itemstatushash->{$thisstatus}->{'statusname'},
2804 push @itemstatusloop, \%row;
2806 $template->param(statusloop=>\@itemstatusloop);
2810 <select name="statusloop">
2811 <option value="">Default</option>
2812 <!-- TMPL_LOOP name="statusloop" -->
2813 <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="statusname" --></option>
2819 # returns a reference to a hash of references to status...
2822 my $dbh = C4::Context->dbh;
2824 $fwk='' unless ($fwk);
2825 my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.notforloan",$fwk);
2826 if ($tag and $subfield){
2827 my $sth = $dbh->prepare("select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?");
2828 $sth->execute($tag,$subfield,$fwk);
2829 if (my ($authorisedvaluecat)=$sth->fetchrow){
2830 my $authvalsth=$dbh->prepare("select authorised_value, lib from authorised_values where category=? order by lib");
2831 $authvalsth->execute($authorisedvaluecat);
2832 while (my ($authorisedvalue, $lib)=$authvalsth->fetchrow){
2833 $itemstatus{$authorisedvalue}=$lib;
2835 $authvalsth->finish;
2836 return \%itemstatus;
2846 $itemstatus{"1"}="Not For Loan";
2847 return \%itemstatus;
2849 =head2 getitemlocation
2851 $itemlochash = &getitemlocation($fwk);
2852 returns informations about location.
2853 where fwk stands for an optional framework code.
2854 Create a location selector with the following code
2856 =head3 in PERL SCRIPT
2858 my $itemlochash = getitemlocation;
2860 foreach my $thisloc (keys %$itemlochash) {
2861 my $selected = 1 if $thisbranch eq $branch;
2862 my %row =(locval => $thisloc,
2863 selected => $selected,
2864 locname => $itemlochash->{$thisloc},
2866 push @itemlocloop, \%row;
2868 $template->param(itemlocationloop => \@itemlocloop);
2871 <select name="location">
2872 <option value="">Default</option>
2873 <!-- TMPL_LOOP name="itemlocationloop" -->
2874 <option value="<!-- TMPL_VAR name="locval" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="locname" --></option>
2879 sub getitemlocation {
2880 # returns a reference to a hash of references to location...
2883 my $dbh = C4::Context->dbh;
2885 $fwk='' unless ($fwk);
2886 my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.location",$fwk);
2887 if ($tag and $subfield){
2888 my $sth = $dbh->prepare("select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?");
2889 $sth->execute($tag,$subfield,$fwk);
2890 if (my ($authorisedvaluecat)=$sth->fetchrow){
2891 my $authvalsth=$dbh->prepare("select authorised_value, lib from authorised_values where category=? order by lib");
2892 $authvalsth->execute($authorisedvaluecat);
2893 while (my ($authorisedvalue, $lib)=$authvalsth->fetchrow){
2894 $itemlocation{$authorisedvalue}=$lib;
2896 $authvalsth->finish;
2897 return \%itemlocation;
2907 $itemlocation{"1"}="Not For Loan";
2908 return \%itemlocation;
2911 END { } # module clean-up code here (global destructor)
2917 Koha Developement team <info@koha.org>
2919 Paul POULAIN paul.poulain@free.fr
2925 # Revision 1.146 2006/02/25 07:43:49 kados
2926 # Reverting to last version because the fix I committed breaks tag
2927 # repeatability. Note that there is still a problem with the Koha
2928 # MARC editor saving blank tags and subfields in a record!
2930 # Revision 1.115.2.30 2006/02/20 09:18:57 thd
2931 # Reverse array filled with elements from repeated subfields from first to last
2932 # to avoid last to first concatenation of elements in Koha DB.
2934 # Revision 1.115.2.29 2006/02/07 15:33:35 hdl
2935 # Adding a new system preference : serialsadditem
2937 # Adding two functions in Biblio.pm : getitemlocation and getitemstatus (helpful to get location list and status list, status is supposed to be in relation with items.notforloan)
2939 # Adding a new function in Bull.pm : serialsitemize which take serial id and item information and creates the item
2940 # Modifying statecollection to add a new line (used for data input)
2942 # Revision 1.115.2.28 2006/01/30 16:06:26 hdl
2943 # BugFix : leader management was annoying for MARCadditem. Changing. Avoiding fields which tag is under 100. (Could be a simple different from 000) But in UNIMARC, fields under 100 donot have subfields.
2945 # Some Improvements on notes and subject management
2947 # Revision 1.115.2.27 2006/01/05 15:13:55 tipaul
2948 # bugfix with $0 subfield
2950 # Revision 1.115.2.26 2005/12/14 13:08:47 tipaul
2951 # * fix for items.notes that is not correctly handled in the non-MARC part of the DB
2952 # * for an unknown reason, mysql fetchrow_hashref returns author BEFORE the title, even if you want it after that makes a problem for UNIMARC where we have 200 $atitle $fauthor => the record appears $f $a.
2953 # * handling better biblio/biblioitems creation from an acquisition : the biblio is deleted & recreated to avoid strange things like a repeated 200 field in UNIMARC.
2955 # Revision 1.115.2.25 2005/10/28 13:46:50 doxulting
2956 # There was a bug : Even if you erased the marc field linked to additionalauthors.authors the additionalauthors stayed in database. Now : delete before recreating
2958 # Revision 1.115.2.24 2005/10/26 16:37:24 doxulting
2959 # It was impossible to add a subfield with value : 0. Was a problem for loan status.
2961 # Revision 1.115.2.23 2005/09/28 14:35:56 hdl
2962 # ordering search results by branch.
2963 # Adding independant Branch Management to getBranches in Koha.pm
2965 # Revision 1.115.2.22 2005/09/14 10:05:12 tipaul
2967 # * leader alignment when leader is <24 => should be left aligned, not right !
2968 # * trailing , in an update recently modified
2970 # Revision 1.115.2.21 2005/09/09 16:11:51 tipaul
2971 # adding missing fields in biblioitems update
2973 # Revision 1.115.2.20 2005/09/01 13:43:33 hdl
2974 # Fixing a bug for marcimport.
2975 # Verifying that a record tag exists before getting its value
2977 # Revision 1.115.2.19 2005/08/26 12:28:57 hdl
2978 # Adding a test on a temporary value before processing it in Biblio.pm
2979 # Adding branchcode fields to aqbookfund and aqbasket.
2981 # Revision 1.115.2.18 2005/08/02 07:45:44 tipaul
2982 # fix for bug http://bugs.koha.org/cgi-bin/bugzilla/show_bug.cgi?id=1009
2983 # (Not all items fields mapped to MARC)
2985 # Revision 1.115.2.17 2005/08/01 15:15:43 tipaul
2986 # adding decoder for Ä string
2988 # Revision 1.115.2.16 2005/07/28 19:56:15 tipaul
2989 # * removing a useless & CPU consuming call to MARCgetbiblio
2990 # * Leader management.
2991 # If you create a MARC tag "000", with a subfield '@', it will be managed as the leader.
2992 # Seems to work correctly.
2994 # Now going to create a plugin for leader()
2996 # Revision 1.115.2.15 2005/07/19 15:25:40 tipaul
2997 # * fixing a bug in subfield order when MARCgetbiblio
2998 # * getting rid with the limit "biblionumber & biblioitemnumber must be in the same tag". So, we can put biblionumber in 001 (field that has no subfields, so we can't put biblioitemnumber in this field), and use biblionumber as identifier in the MARC biblio too. Still to be deeply tested.
2999 # * adding some diacritic decoding (Ä, Ü...)
3001 # Revision 1.115.2.14 2005/06/27 23:24:06 hdl
3002 # Display dashed ISBN
3004 # Revision 1.115.2.13 2005/05/31 12:44:26 tipaul
3005 # patch from Genji (Waylon R.) to update subjects in MARC tables when systempref has MARC=OFF
3007 # Revision 1.115.2.12 2005/05/30 11:22:41 tipaul
3008 # fixing a bug : when a field was repeated, the last field was also repeated. (Was due to the "empty" field in html between fields : to separate fields, in html, an empty field is automatically added. in MARChtml2marc, this empty field was not discarded correctly)
3010 # Revision 1.115.2.11 2005/05/25 15:48:43 tipaul
3011 # * removing my for variables already declared
3012 # * updating biblio.unititle field as well as other fields in biblio table
3014 # Revision 1.115.2.10 2005/05/25 09:30:50 hdl
3015 # Adding NEWmodbiblioframework feature
3016 # Used by addbiblio.pl when modifying a framework selection.
3018 # Revision 1.115.2.9 2005/04/07 10:05:25 tipaul
3019 # adding / to the list of symbols that are replace by spaces for searches
3021 # Revision 1.115.2.8 2005/03/25 16:23:49 tipaul
3022 # some improvements :
3023 # * return immediatly when a subfield is empty
3024 # * search duplicate on isbn must be done only when there is an isbn ;-)
3026 # Revision 1.115.2.7 2005/03/10 15:52:28 tipaul
3027 # * adding glass to opac marc detail.
3028 # * changing glasses behaviour : It now appears only on subfields that have a "link" value. Avoid useless glasses and removes nothing. **** WARNING **** : if you don't change you MARC parameters, glasses DISAPPEAR, because no subfields have a link value. So you MUST "reactivate" them manually. If you want to enable the search glass on field 225$a (collection in UNIMARC), just put 225a to "link" field (Koha >> parameters >> framework >> 225 field >> subfield >> modify $a >> enter 225a in link input field (without quotes or anything else)
3029 # * fixing bug with libopac
3031 # Revision 1.115.2.6 2005/03/09 15:56:01 tipaul
3032 # Changing MARCmoditem to be like MARCmodbiblio : a modif is a delete & create.
3033 # Longer, but solves problems with repeated subfields.
3035 # The previous version was not buggy except under certain circumstances (a repeated subfield, that does not exist usually in items)
3037 # Revision 1.115.2.5 2005/02/24 13:54:04 tipaul
3038 # exporting MARCdelsubfield sub. It's used in authority merging.
3039 # Modifying it too to enable deletion of all subfields from a given tag/subfield or just one.
3041 # Revision 1.115.2.4 2005/02/17 12:44:25 tipaul
3042 # bug in acquisition : the title was also stored as subtitle.
3044 # Revision 1.115.2.3 2005/02/10 13:14:36 tipaul
3045 # * multiple main authors are now correctly handled in simple (non-MARC) view
3047 # Revision 1.115.2.2 2005/01/11 16:02:35 tipaul
3048 # in catalogue, modifs were not stored properly the non-MARC item DB. Affect only libraries without barcodes.
3050 # Revision 1.115.2.1 2005/01/11 14:45:37 tipaul
3051 # bugfix : issn were not stored correctly in non-MARC DB on biblio modification
3053 # Revision 1.115 2005/01/06 14:32:17 tipaul
3054 # improvement of speed for bulkmarcimport.
3055 # A sub had been forgotten to use the C4::Context->marcfromkohafield array, that caches DB datas.
3056 # this is only a little improvement for normal DB modif, but almost x2 the speed of bulkmarcimport... from 6records/seconds to more than 10.
3058 # Revision 1.114 2005/01/03 10:48:33 tipaul
3059 # * bugfix for the search on a MARC detail, when you clic on the magnifying glass (caused an internal server error)
3060 # * partial support of the "linkage" MARC feature : if you enter a "link" on a MARC subfield, the magnifying glass won't search on the field, but on the linked field. I agree it's a partial support. Will be improved, but I need to investigate MARC21 & UNIMARC diffs on this topic.
3062 # Revision 1.113 2004/12/10 16:27:53 tipaul
3063 # 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)
3064 # In 2.4, a new DB structure will highly speed things and this limit will be removed.
3065 # FindDuplicate is activated again, the perf problems were due to this problem.
3067 # Revision 1.112 2004/12/08 10:14:42 tipaul
3068 # * desactivate FindDuplicate
3071 # Revision 1.111 2004/11/25 17:39:44 tipaul
3072 # removing useless &branches in package declaration
3074 # Revision 1.110 2004/11/24 16:00:01 tipaul
3075 # removing sub branches (commited by chris for MARC=OFF bugfix, but sub branches is already in Acquisition.pm)
3077 # Revision 1.109 2004/11/24 15:58:31 tipaul
3078 # * critical fix for acquisition (see RC3 release notes)
3079 # * critical fix for duplicate finder
3081 # Revision 1.108 2004/11/19 19:41:22 rangi
3082 # Shifting branches() from deprecated C4::Catalogue to C4::Biblio
3083 # Allowing the non marc interface acquisitions to work.
3085 # Revision 1.107 2004/11/05 10:15:27 tipaul
3086 # Improving FindDuplicate to find duplicate records on adding biblio
3088 # Revision 1.106 2004/11/02 16:44:45 tipaul
3089 # new feature : checking for duplicate biblio.
3091 # For instance, it's only done on ISBN only. Will be improved soon.
3093 # When a duplicate is detected, the biblio is not saved, but the user is asked for a confirmations.
3095 # Revision 1.105 2004/09/23 16:15:37 tipaul
3098 # Revision 1.104 2004/09/16 15:06:46 tipaul
3099 # enabling # (| still possible too) for repeatable subfields
3101 # Revision 1.103 2004/09/06 14:17:34 tipaul
3102 # some commented warning added + 1 major bugfix => drop empty fields, NOT fields containing 0
3104 # Revision 1.102 2004/09/06 10:00:19 tipaul
3105 # adding a "location" field to the library.
3106 # This field is useful when the callnumber contains no information on the room where the item is stored.
3107 # With this field, we now have 3 levels of informations to find a book :
3112 # This should be versatile enough to solve any storing method.
3113 # 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.
3115 # Revision 1.101 2004/08/18 16:01:37 tipaul
3116 # modifs to support frameworkcodes
3118 # Revision 1.100 2004/08/13 16:37:25 tipaul
3119 # adding frameworkcode to API in some subs
3121 # Revision 1.99 2004/07/30 13:54:50 doxulting
3122 # Beginning of serial commit
3124 # Revision 1.98 2004/07/15 09:48:10 tipaul
3125 # * removing useless sub
3126 # * minor bugfix in moditem (managing homebranch & holdingbranch)
3128 # Revision 1.97 2004/07/02 15:53:53 tipaul
3129 # bugfix (due to frameworkcode field)
3131 # Revision 1.96 2004/06/29 16:07:10 tipaul
3132 # last sync for 2.1.0 release
3134 # Revision 1.95 2004/06/26 23:19:59 rangi
3135 # Fixing modaddauthor, and adding getitemtypes.
3136 # Also tidying up formatting of code
3138 # Revision 1.94 2004/06/17 08:16:32 tipaul
3139 # merging tag & subfield in marc_word for better perfs
3141 # Revision 1.93 2004/06/11 15:38:06 joshferraro
3142 # Changes MARCaddword to index words >= 1 char ... needed for more accurate
3143 # searches using SearchMarc routines.
3145 # Revision 1.92 2004/06/10 08:29:01 tipaul
3146 # MARC authority management (continued)
3148 # Revision 1.91 2004/06/03 10:03:01 tipaul
3149 # * frameworks and itemtypes are independant
3150 # * in the MARC editor, showing the + to duplicate a tag only if the tag is repeatable
3152 # Revision 1.90 2004/05/28 08:25:53 tipaul
3153 # hidding hidden & isurl constraints into MARC subfield structure
3155 # Revision 1.89 2004/05/27 21:47:21 rangi
3158 # Revision 1.88 2004/05/18 15:23:49 tipaul
3159 # framework management : 1 MARC framework for each itemtype
3161 # Revision 1.87 2004/05/18 11:54:07 tipaul
3162 # getitemtypes moved in Koha.pm
3164 # Revision 1.86 2004/05/03 09:19:22 tipaul
3165 # some fixes for mysql prepare & execute
3167 # Revision 1.85 2004/04/02 14:55:48 tipaul
3168 # renaming items.bulk field to items.itemcallnumber.
3169 # Will be used to store call number for libraries that don't use dewey classification.
3170 # Note it's related to ITEMS, not biblio.
3172 # Revision 1.84 2004/03/24 17:18:30 joshferraro
3173 # Fixes bug 749 by removing the comma on line 1488.
3175 # Revision 1.83 2004/03/15 14:31:50 tipaul
3176 # adding a minor check
3178 # Revision 1.82 2004/03/07 05:47:31 acli
3179 # Various updates/fixes from rel_2_0
3180 # Fixes for bugs 721 (templating), 727, and 734
3182 # Revision 1.81 2004/03/06 20:26:13 tipaul
3183 # adding seealso feature in MARC searches
3185 # Revision 1.80 2004/02/12 13:40:56 tipaul
3186 # deleting subs duplicated by error
3188 # Revision 1.79 2004/02/11 08:40:09 tipaul
3189 # synch'ing 2.0.0 branch and head
3191 # Revision 1.78.2.3 2004/02/10 13:15:46 tipaul
3192 # removing 2 warnings
3194 # Revision 1.78.2.2 2004/01/26 10:38:06 tipaul
3195 # dealing correctly "bulk" field
3197 # Revision 1.78.2.1 2004/01/13 17:29:53 tipaul
3198 # * minor html fixes
3199 # * adding publisher in acquisition process (& ordering basket by publisher)
3201 # Revision 1.78 2003/12/09 15:57:28 tipaul
3202 # rolling back to working char_decode sub
3204 # Revision 1.77 2003/12/03 17:47:14 tipaul
3205 # bugfixes for biblio deletion
3207 # Revision 1.76 2003/12/03 01:43:41 slef
3210 # Revision 1.75 2003/12/03 01:42:03 slef
3211 # bug 662 fixes securing DBI
3213 # Revision 1.74 2003/11/28 09:48:33 tipaul
3214 # bugfix : misusing prepare & execute => now using prepare(?) and execute($var)
3216 # Revision 1.73 2003/11/28 09:45:25 tipaul
3217 # bugfix for iso2709 file import in the "notforloan" field.
3219 # But notforloan field called "loan" somewhere, so in case "loan" is used, copied to "notforloan" to avoid a bug.
3221 # Revision 1.72 2003/11/24 17:40:14 tipaul
3224 # Revision 1.71 2003/11/24 16:28:49 tipaul
3225 # biblio & item deletion now works fine in MARC editor.
3226 # Stores deleted biblio/item in the marc field of the deletedbiblio/deleteditem table.
3228 # Revision 1.70 2003/11/24 13:29:55 tipaul
3229 # moving $id from beginning to end of file (70 commits... huge comments...)
3231 # Revision 1.69 2003/11/24 13:27:17 tipaul
3232 # fix for #380 (bibliosubject)
3234 # Revision 1.68 2003/11/06 17:18:30 tipaul
3237 # 1st draft for MARC biblio deletion.
3238 # Still does not work well, but at least, Biblio.pm compiles & it should'nt break too many things
3239 # (Note the trash in the MARCdetail, but don't use it, please :-) )
3241 # Revision 1.67 2003/10/25 08:46:27 tipaul
3242 # minor fixes for bilbio deletion (still buggy)
3244 # Revision 1.66 2003/10/17 10:02:56 tipaul
3245 # Indexing only words longer than 2 letters. Was >=2 before, & 2 letters words usually means nothing.
3247 # Revision 1.65 2003/10/14 09:45:29 tipaul
3248 # 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)
3250 # Revision 1.64 2003/10/06 15:20:51 tipaul
3251 # fix for 536 (subtitle error)
3253 # Revision 1.63 2003/10/01 13:25:49 tipaul
3254 # seems a char encoding problem modified something in char_decode sub... changing back to something that works...
3256 # Revision 1.62 2003/09/17 14:21:13 tipaul
3257 # fixing bug that makes a MARC biblio disappear when using full acquisition (order => recieve ==> MARC editor).
3258 # Before this 2 lines fix, the MARC biblio was deleted during recieve, and had to be entirely recreated :-(
3260 # Revision 1.61 2003/09/17 10:24:39 tipaul
3261 # notforloan value in itemtype was overwritting notforloan value in a given item.
3262 # I changed this behaviour :
3263 # if notforloan is set for a given item, and NOT for all items from this itemtype, the notforloan is kept.
3264 # If notforloan is set for itemtype, it's used (and impossible to loan a specific item from this itemtype)
3266 # Revision 1.60 2003/09/04 14:11:23 tipaul
3267 # fix for 593 (data duplication in MARC-DB)
3269 # Revision 1.58 2003/08/06 12:54:52 tipaul
3270 # fix for publicationyear : extracting numeric value from MARC string, like for copyrightdate.
3271 # (note that copyrightdate still extracted to get numeric format)
3273 # Revision 1.57 2003/07/15 23:09:18 slef
3274 # change show columns to use biblioitems bnotes too
3276 # Revision 1.56 2003/07/15 11:34:52 slef
3277 # fixes from paul email
3279 # Revision 1.55 2003/07/15 00:02:49 slef
3280 # Work on bug 515... can we do a single-side rename of notes to bnotes?
3282 # Revision 1.54 2003/07/11 11:51:32 tipaul
3283 # *** empty log message ***
3285 # Revision 1.52 2003/07/10 10:37:19 tipaul
3286 # fix for copyrightdate problem, #514
3288 # Revision 1.51 2003/07/02 14:47:17 tipaul
3289 # fix for #519 : items.dateaccessioned imports incorrectly
3291 # Revision 1.49 2003/06/17 11:21:13 tipaul
3292 # improvments/fixes for z3950 support.
3293 # * Works now even on ADD, not only on MODIFY
3294 # * able to search on ISBN, author, title
3296 # Revision 1.48 2003/06/16 09:22:53 rangi
3297 # Just added an order clause to getitemtypes
3299 # Revision 1.47 2003/05/20 16:22:44 tipaul
3300 # fixing typo in Biblio.pm POD
3302 # Revision 1.46 2003/05/19 13:45:18 tipaul
3303 # support for subtitles, additional authors, subject.
3304 # 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.
3305 # Note that some OLD-DB subs are strange (dummy ?) see OLDmodsubject, OLDmodsubtitle, OLDmodaddiauthor in C4/Biblio.pm
3306 # 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.
3308 # Revision 1.45 2003/04/29 16:50:49 tipaul
3309 # really proud of this commit :-)
3310 # z3950 search and import seems to works fine.
3311 # Let me explain how :
3312 # * a "search z3950" button is added in the addbiblio template.
3313 # * when clicked, a popup appears and z3950/search.pl is called
3314 # * z3950/search.pl calls addz3950search in the DB
3315 # * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table.
3316 # * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending.
3317 # * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled
3320 # * 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.
3321 # * 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.
3323 # Revision 1.44 2003/04/28 13:07:14 tipaul
3324 # Those fixes solves the "internal server error" with MARC::Record 1.12.
3325 # It was due to an illegal contruction in Koha : we tried to retrive subfields from <10 tags.
3326 # That's not possible. MARC::Record accepted this in 0.93 version, but it was fixed after.
3327 # Now, the construct/retrieving is OK !
3329 # Revision 1.43 2003/04/10 13:56:02 tipaul
3331 # * worked in 1.9.0, but not in 1.9.1 :
3332 # - modif of a biblio didn't work
3333 # - 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.
3335 # * did not work before :
3336 # - repeatable subfields now works correctly. Enter 2 subfields separated by | and they will be splitted during saving.
3337 # - dropped the last subfield of the MARC form :-(
3339 # Internal changes :
3340 # - 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.
3341 # Note the MARCdelbiblio has been rewritted to enable deletion of a biblio WITHOUT deleting items.
3343 # Revision 1.42 2003/04/04 08:41:11 tipaul
3344 # last commits before 1.9.1
3346 # Revision 1.41 2003/04/01 12:26:43 tipaul
3349 # Revision 1.40 2003/03/11 15:14:03 tipaul
3352 # Revision 1.39 2003/03/07 16:35:42 tipaul
3353 # * moving generic functions to Koha.pm
3354 # * improvement of SearchMarc.pm
3358 # Revision 1.38 2003/02/27 16:51:59 tipaul
3359 # * moving prepare / execute to ? form.
3362 # * road to 1.9.2 => acquisition and cataloguing merging
3364 # Revision 1.37 2003/02/12 11:03:03 tipaul
3365 # Support for 000 -> 010 fields.
3366 # Those fields doesn't have subfields.
3367 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
3368 # 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.
3370 # Revision 1.36 2003/02/12 11:01:01 tipaul
3371 # Support for 000 -> 010 fields.
3372 # Those fields doesn't have subfields.
3373 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
3374 # 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.
3376 # Revision 1.35 2003/02/03 18:46:00 acli
3377 # Minor factoring in C4/Biblio.pm, plus change to export the per-tag
3378 # 'mandatory' property to a per-subfield 'tag_mandatory' template parameter,
3379 # so that addbiblio.tmpl can distinguish between mandatory subfields in a
3380 # mandatory tag and mandatory subfields in an optional tag
3382 # Not-minor factoring in acqui.simple/addbiblio.pl to make the if-else blocks
3383 # smaller, and to add some POD; need further testing for this
3385 # Added function to check if a MARC subfield name is "koha-internal" (instead
3386 # of checking it for 'lib' and 'tag' everywhere); temporarily added to Koha.pm
3388 # Use above function in acqui.simple/additem.pl and search.marc/search.pl
3390 # Revision 1.34 2003/01/28 14:50:04 tipaul
3391 # fixing MARCmodbiblio API and reindenting code
3393 # Revision 1.33 2003/01/23 12:22:37 tipaul
3394 # adding char_decode to decode MARC21 or UNIMARC extended chars
3396 # Revision 1.32 2002/12/16 15:08:50 tipaul
3397 # small but important bugfix (fixes a problem in export)
3399 # Revision 1.31 2002/12/13 16:22:04 tipaul
3400 # 1st draft of marc export
3402 # Revision 1.30 2002/12/12 21:26:35 tipaul
3403 # YAB ! (Yet Another Bugfix) => related to biblio modif
3404 # (some warning cleaning too)
3406 # Revision 1.29 2002/12/12 16:35:00 tipaul
3407 # adding authentification with Auth.pm and
3408 # MAJOR BUGFIX on marc biblio modification
3410 # Revision 1.28 2002/12/10 13:30:03 tipaul
3411 # fugfixes from Dombes Abbey work
3413 # Revision 1.27 2002/11/19 12:36:16 tipaul
3415 # various bugfixes, improvments, and migration from acquisition.pm to biblio.pm
3417 # Revision 1.26 2002/11/12 15:58:43 tipaul
3420 # * 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)
3422 # Revision 1.25 2002/10/25 10:58:26 tipaul
3424 # * bugfixes and improvements
3426 # Revision 1.24 2002/10/24 12:09:01 arensb
3427 # Fixed "no title" warning when generating HTML documentation from POD.
3429 # Revision 1.23 2002/10/16 12:43:08 arensb
3430 # Added some FIXME comments.
3432 # Revision 1.22 2002/10/15 13:39:17 tipaul
3433 # removing Acquisition.pm
3434 # deleting unused code in biblio.pm, rewriting POD and answering most FIXME comments
3436 # Revision 1.21 2002/10/13 11:34:14 arensb
3437 # Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
3438 # Thus, $x = $x+2 becomes $x += 2, and so forth.
3440 # Revision 1.20 2002/10/13 08:28:32 arensb
3441 # Deleted unused variables.
3442 # Removed trailing whitespace.
3444 # Revision 1.19 2002/10/13 05:56:10 arensb
3445 # Added some FIXME comments.
3447 # Revision 1.18 2002/10/11 12:34:53 arensb
3448 # Replaced &requireDBI with C4::Context->dbh
3450 # Revision 1.17 2002/10/10 14:48:25 tipaul
3453 # Revision 1.16 2002/10/07 14:04:26 tipaul
3454 # road to 1.3.1 : viewing MARC biblio
3456 # Revision 1.15 2002/10/05 09:49:25 arensb
3457 # Merged with arensb-context branch: use C4::Context->dbh instead of
3458 # &C4Connect, and generally prefer C4::Context over C4::Database.
3460 # Revision 1.14 2002/10/03 11:28:18 tipaul
3461 # Extending Context.pm to add stopword management and using it in MARC-API.
3462 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
3464 # Revision 1.13 2002/10/02 16:26:44 tipaul
3467 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
3468 # Merged in changes from main branch.
3470 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
3471 # Added a whole mess of FIXME comments.
3473 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
3474 # Added some missing semicolons.
3476 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
3477 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
3480 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
3481 # Added a whole mess of FIXME comments.
3483 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
3484 # Added some missing semicolons.
3486 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
3487 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
3490 # Revision 1.12 2002/10/01 11:48:51 arensb
3491 # Added some FIXME comments, mostly marking duplicate functions.
3493 # Revision 1.11 2002/09/24 13:49:26 tipaul
3494 # long WAS the road to 1.3.0...
3495 # coming VERY SOON NOW...
3496 # modifying installer and buildrelease to update the DB
3498 # Revision 1.10 2002/09/22 16:50:08 arensb
3499 # Added some FIXME comments.
3501 # Revision 1.9 2002/09/20 12:57:46 tipaul
3502 # long is the road to 1.4.0
3503 # * MARCadditem and MARCmoditem now wroks
3504 # * various bugfixes in MARC management
3505 # !!! 1.3.0 should be released very soon now. Be careful !!!
3507 # Revision 1.8 2002/09/10 13:53:52 tipaul
3508 # MARC API continued...
3510 # * 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)
3512 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
3514 # Revision 1.7 2002/08/14 18:12:51 tonnesen
3515 # Added copyright statement to all .pl and .pm files
3517 # Revision 1.6 2002/07/25 13:40:31 tipaul
3518 # pod documenting the API.
3520 # Revision 1.5 2002/07/24 16:11:37 tipaul
3522 # Database.pm and Output.pm are almost not modified (var test...)
3524 # Biblio.pm is almost completly rewritten.
3526 # WHAT DOES IT ??? ==> END of Hitchcock suspens
3528 # 1st, it does... nothing...
3529 # 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 ...
3531 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
3532 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
3533 # * 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.
3534 # * 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.
3535 # 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 ;-)
3537 # 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.
3538 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.