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
25 use MARC::File::USMARC;
27 use vars qw($VERSION @ISA @EXPORT);
29 # set the version for version checking
35 # don't forget MARCxxx subs are exported only for testing purposes. Should not be used
36 # as the old-style API and the NEW one are the only public functions.
39 &updateBiblio &updateBiblioItem &updateItem
40 &itemcount &newbiblio &newbiblioitem
41 &modnote &newsubject &newsubtitle
42 &modbiblio &checkitems
44 &modsubtitle &modsubject &modaddauthor &moditem &countitems
45 &delitem &deletebiblioitem &delbiblio
47 &getbiblioitembybiblionumber
48 &getbiblioitem &getitemsbybiblioitem
50 &newcompletebiblioitem
52 &MARCfind_oldbiblionumber_from_MARCbibid
53 &MARCfind_MARCbibid_from_oldbiblionumber
54 &MARCfind_marc_from_kohafield
56 &MARCfind_frameworkcode
59 &NEWnewbiblio &NEWnewitem
60 &NEWmodbiblio &NEWmoditem
61 &NEWdelbiblio &NEWdelitem
62 &NEWmodbiblioframework
64 &MARCaddbiblio &MARCadditem
65 &MARCmodsubfield &MARCaddsubfield
66 &MARCmodbiblio &MARCmoditem
67 &MARCkoha2marcBiblio &MARCmarc2koha
68 &MARCkoha2marcItem &MARChtml2marc
69 &MARCgetbiblio &MARCgetitem
70 &MARCaddword &MARCdelword
80 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
83 # all the following subs takes a MARC::Record as parameter and manage
84 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
85 # NEWxxx subs (xxx deals with old-DB parameters, the NEWxxx deals with MARC-DB parameter)
89 C4::Biblio - acquisition, catalog management functions
93 move from 1.2 to 1.4 version :
94 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
95 In the 1.4 version, we want to do 2 differents things :
96 - keep populating the old-DB, that has a LOT less datas than MARC
97 - populate the MARC-DB
98 To populate the DBs we have 2 differents sources :
99 - the standard acquisition system (through book sellers), that does'nt use MARC data
100 - the MARC acquisition system, that uses MARC data.
102 Thus, we have 2 differents cases :
103 - 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
104 - 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
106 That's why we need 4 subs :
107 all I<subs beginning by MARC> manage only MARC tables. They manage MARC-DB with MARC::Record parameters
108 all I<subs beginning by OLD> manage only OLD-DB tables. They manage old-DB with old-DB parameters
109 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
110 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.
112 - NEW and old-style API should be used in koha to manage biblio
113 - MARCsubs are divided in 2 parts :
114 * some of them manage MARC parameters. They are heavily used in koha.
115 * some of them manage MARC biblio : they are mostly used by NEW and old-style subs.
116 - OLD are used internally only
118 all subs requires/use $dbh as 1st parameter.
120 I<NEWxxx related subs>
122 all subs requires/use $dbh as 1st parameter.
123 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
125 I<OLDxxx related subs>
127 all subs requires/use $dbh as 1st parameter.
128 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
130 They all are the exact copy of 1.0/1.2 version of the sub without the OLD.
131 The OLDxxx is called by the original xxx sub.
132 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
134 WARNING : there is 1 difference between initialxxx and OLDxxx :
135 the db header $dbh is always passed as parameter to avoid over-DB connexion
141 =item @tagslib = &MARCgettagslib($dbh,1|0,$itemtype);
143 last param is 1 for liblibrarian and 0 for libopac
144 $itemtype contains the itemtype framework reference. If empty or does not exist, the default one is used
145 returns a hash with tag/subfield meaning
146 =item ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,$kohafield);
148 finds MARC tag and subfield for a given kohafield
149 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
151 =item $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
153 finds a old-db biblio number for a given MARCbibid number
155 =item $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
157 finds a MARC bibid from a old-db biblionumber
159 =item $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
161 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
163 =item $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
165 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
167 =item $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
169 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
171 =item $olddb = &MARCmarc2koha($dbh,$MARCRecord);
173 builds a hash with old-db datas from a MARC::Record
175 =item &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
177 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
179 =item &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
181 adds a subfield in a biblio (in the MARC tables only).
183 =item $MARCRecord = &MARCgetbiblio($dbh,$bibid);
185 Returns a MARC::Record for the biblio $bibid.
187 =item &MARCmodbiblio($dbh,$bibid,$record,$frameworkcode,$delete);
189 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
190 It 1st delete the biblio, then recreates it.
191 WARNING : the $delete parameter is not used anymore (too much unsolvable cases).
192 =item ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
194 MARCmodsubfield changes the value of a given subfield
196 =item $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
198 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
199 Returns -1 if more than 1 answer
201 =item $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
203 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
205 =item &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
207 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
208 If $subfieldorder is not set, delete all the $tag$subfield subfields
210 =item &MARCdelbiblio($dbh,$bibid);
212 MARCdelbiblio delete biblio $bibid
214 =item &MARCkoha2marcOnefield
216 used by MARCkoha2marc and should not be useful elsewhere
218 =item &MARCmarc2kohaOnefield
220 used by MARCmarc2koha and should not be useful elsewhere
224 used to manage MARC_word table and should not be useful elsewhere
228 used to manage MARC_word table and should not be useful elsewhere
233 my ( $dbh, $forlibrarian, $frameworkcode ) = @_;
234 $frameworkcode = "" unless $frameworkcode;
236 my $libfield = ( $forlibrarian eq 1 ) ? 'liblibrarian' : 'libopac';
238 # check that framework exists
241 "select count(*) from marc_tag_structure where frameworkcode=?");
242 $sth->execute($frameworkcode);
243 my ($total) = $sth->fetchrow;
244 $frameworkcode = "" unless ( $total > 0 );
247 "select tagfield,liblibrarian,libopac,mandatory,repeatable from marc_tag_structure where frameworkcode=? order by tagfield"
249 $sth->execute($frameworkcode);
250 my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable );
252 while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable ) = $sth->fetchrow ) {
253 $res->{$tag}->{lib} = ($forlibrarian or !$libopac)?$liblibrarian:$libopac;
254 $res->{$tab}->{tab} = ""; # XXX
255 $res->{$tag}->{mandatory} = $mandatory;
256 $res->{$tag}->{repeatable} = $repeatable;
261 "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"
263 $sth->execute($frameworkcode);
266 my $authorised_value;
276 ( $tag, $subfield, $liblibrarian, , $libopac, $tab,
277 $mandatory, $repeatable, $authorised_value, $authtypecode,
278 $value_builder, $kohafield, $seealso, $hidden,
283 $res->{$tag}->{$subfield}->{lib} = ($forlibrarian or !$libopac)?$liblibrarian:$libopac;
284 $res->{$tag}->{$subfield}->{tab} = $tab;
285 $res->{$tag}->{$subfield}->{mandatory} = $mandatory;
286 $res->{$tag}->{$subfield}->{repeatable} = $repeatable;
287 $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
288 $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode;
289 $res->{$tag}->{$subfield}->{value_builder} = $value_builder;
290 $res->{$tag}->{$subfield}->{kohafield} = $kohafield;
291 $res->{$tag}->{$subfield}->{seealso} = $seealso;
292 $res->{$tag}->{$subfield}->{hidden} = $hidden;
293 $res->{$tag}->{$subfield}->{isurl} = $isurl;
294 $res->{$tag}->{$subfield}->{link} = $link;
299 sub MARCfind_marc_from_kohafield {
300 my ( $dbh, $kohafield,$frameworkcode ) = @_;
301 return 0, 0 unless $kohafield;
302 my $relations = C4::Context->marcfromkohafield;
303 return ($relations->{$frameworkcode}->{$kohafield}->[0],$relations->{$frameworkcode}->{$kohafield}->[1]);
306 sub MARCfind_oldbiblionumber_from_MARCbibid {
307 my ( $dbh, $MARCbibid ) = @_;
309 $dbh->prepare("select biblionumber from marc_biblio where bibid=?");
310 $sth->execute($MARCbibid);
311 my ($biblionumber) = $sth->fetchrow;
312 return $biblionumber;
315 sub MARCfind_MARCbibid_from_oldbiblionumber {
316 my ( $dbh, $oldbiblionumber ) = @_;
318 $dbh->prepare("select bibid from marc_biblio where biblionumber=?");
319 $sth->execute($oldbiblionumber);
320 my ($bibid) = $sth->fetchrow;
326 # pass the MARC::Record to this function, and it will create the records in the marc tables
327 my ($dbh,$record,$biblionumber,$frameworkcode,$bibid) = @_;
328 my @fields=$record->fields();
330 # adding main table, and retrieving bibid
331 # if bibid is sent, then it's not a true add, it's only a re-add, after a delete (ie, a mod)
332 # if bibid empty => true add, find a new bibid number
335 "lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ"
339 "insert into marc_biblio (datecreated,biblionumber,frameworkcode) values (now(),?,?)"
341 $sth->execute( $biblionumber, $frameworkcode );
342 $sth = $dbh->prepare("select max(bibid) from marc_biblio");
344 ($bibid) = $sth->fetchrow;
349 # now, add subfields...
350 foreach my $field (@fields) {
352 if ( $field->tag() < 10 ) {
353 &MARCaddsubfield( $dbh, $bibid, $field->tag(), '', $fieldcount, '',
357 my @subfields = $field->subfields();
358 foreach my $subfieldcount ( 0 .. $#subfields ) {
363 $field->indicator(1) . $field->indicator(2),
365 $subfields[$subfieldcount][0],
367 $subfields[$subfieldcount][1]
373 &MARCaddsubfield($dbh,$bibid,'000','',$fieldcount+1,'',1,$record->leader);
374 $dbh->do("unlock tables");
380 # pass the MARC::Record to this function, and it will create the records in the marc tables
381 my ($dbh,$record,$biblionumber) = @_;
382 # search for MARC biblionumber
383 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
384 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
385 my @fields=$record->fields();
386 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
387 $sth->execute($bibid);
388 my ($fieldcount) = $sth->fetchrow;
390 # now, add subfields...
391 foreach my $field (@fields) {
392 my @subfields = $field->subfields();
394 foreach my $subfieldcount ( 0 .. $#subfields ) {
399 $field->indicator(1) . $field->indicator(2),
401 $subfields[$subfieldcount][0],
403 $subfields[$subfieldcount][1]
407 $dbh->do("unlock tables");
411 sub MARCaddsubfield {
413 # Add a new subfield to a tag into the DB.
415 $dbh, $bibid, $tagid, $tag_indicator,
416 $tagorder, $subfieldcode, $subfieldorder, $subfieldvalues
419 return unless $subfieldvalues;
420 # warn "$tagid / $subfieldcode / $subfieldvalues";
421 # if not value, end of job, we do nothing
422 # if ( length($subfieldvalues) == 0 ) {
425 if ( not($subfieldcode) ) {
428 my @subfieldvalues = split /\||#/, $subfieldvalues;
429 foreach my $subfieldvalue (@subfieldvalues) {
430 if ( length($subfieldvalue) > 255 ) {
432 "lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE"
436 "insert into marc_blob_subfield (subfieldvalue) values (?)");
437 $sth->execute($subfieldvalue);
439 $dbh->prepare("select max(blobidlink)from marc_blob_subfield");
441 my ($res) = $sth->fetchrow;
444 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?,?)"
446 $sth->execute( $bibid, ( sprintf "%03s", $tagid ), $tagorder,
447 $tag_indicator, $subfieldcode, $subfieldorder, $res );
449 if ( $sth->errstr ) {
451 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
453 $dbh->do("unlock tables");
458 "insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)"
461 $bibid, ( sprintf "%03s", $tagid ),
462 $tagorder, $tag_indicator,
463 $subfieldcode, $subfieldorder,
466 if ( $sth->errstr ) {
468 "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
472 $dbh, $bibid, $tagid, $tagorder,
473 $subfieldcode, $subfieldorder, $subfieldvalue
480 # Returns MARC::Record of the biblio passed in parameter.
481 my ( $dbh, $biblionumber ) = @_;
482 my $sth = $dbh->prepare('select marc from biblioitems where biblionumber=?');
483 $sth->execute($biblionumber);
484 my ($marc) = $sth->fetchrow;
485 my $record = MARC::File::USMARC::decode($marc);
486 warn "$biblionumber => $marc = ".$record->as_usmarc();
492 # Returns MARC::Record of the biblio passed in parameter.
493 my ( $dbh, $bibid, $itemnumber ) = @_;
494 my $record = MARC::Record->new();
496 # search MARC tagorder
499 "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=?"
501 $sth2->execute( $bibid, $itemnumber );
502 my ($tagorder) = $sth2->fetchrow_array();
504 #---- TODO : the leader is missing
507 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
508 from marc_subfield_table
509 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
514 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
515 $sth->execute( $bibid, $tagorder );
516 while ( my $row = $sth->fetchrow_hashref ) {
517 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
518 $sth2->execute( $row->{'valuebloblink'} );
519 my $row2 = $sth2->fetchrow_hashref;
521 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
523 if ( $record->field( $row->{'tag'} ) ) {
526 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
527 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
528 if ( length( $row->{'tag'} ) < 3 ) {
529 $row->{'tag'} = "0" . $row->{'tag'};
531 $field = $record->field( $row->{'tag'} );
534 $field->add_subfields( $row->{'subfieldcode'},
535 $row->{'subfieldvalue'} );
536 $record->delete_field($field);
537 $record->add_fields($field);
541 if ( length( $row->{'tag'} ) < 3 ) {
542 $row->{'tag'} = "0" . $row->{'tag'};
545 MARC::Field->new( $row->{'tag'}, " ", " ",
546 $row->{'subfieldcode'} => $row->{'subfieldvalue'} );
547 $record->add_fields($temp);
555 my ($dbh,$bibid,$record,$frameworkcode,$delete)=@_;
556 # 1st delete the biblio,
558 my $biblionumber = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
559 &MARCdelbiblio($dbh,$bibid,1);
560 &MARCaddbiblio($dbh,$record,$biblionumber,$frameworkcode,$bibid);
564 my ( $dbh, $bibid, $keep_items ) = @_;
566 # if the keep_item is set to 1, then all items are preserved.
567 # This flag is set when the delbiblio is called by modbiblio
568 # due to a too complex structure of MARC (repeatable fields and subfields),
569 # the best solution for a modif is to delete / recreate the record.
571 # 1st of all, copy the MARC::Record to deletedbiblio table => if a true deletion, MARC data will be kept.
572 # if deletion called before MARCmodbiblio => won't do anything, as the oldbiblionumber doesn't
573 # exist in deletedbiblio table
574 my $record = MARCgetbiblio( $dbh, $bibid );
575 my $oldbiblionumber =
576 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
578 $dbh->prepare("update deletedbiblio set marc=? where biblionumber=?");
579 $copy2deleted->execute( $record->as_usmarc(), $oldbiblionumber );
581 # now, delete in MARC tables.
582 if ( $keep_items eq 1 ) {
584 #search item field code
587 "select tagfield from marc_subfield_structure where kohafield like 'items.%'"
590 my $itemtag = $sth->fetchrow_hashref->{tagfield};
592 "delete from marc_subfield_table where bibid=$bibid and tag<>$itemtag"
595 "delete from marc_word where bibid=$bibid and not (tagsubfield like \"$itemtag%\")"
599 $dbh->do("delete from marc_biblio where bibid=$bibid");
600 $dbh->do("delete from marc_subfield_table where bibid=$bibid");
601 $dbh->do("delete from marc_word where bibid=$bibid");
607 # delete the item passed in parameter in MARC tables.
608 my ( $dbh, $bibid, $itemnumber ) = @_;
610 # my $record = MARC::Record->new();
611 # search MARC tagorder
612 my $record = MARCgetitem( $dbh, $bibid, $itemnumber );
614 $dbh->prepare("update deleteditems set marc=? where itemnumber=?");
615 $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
619 "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=?"
621 $sth2->execute( $bibid, $itemnumber );
622 my ($tagorder) = $sth2->fetchrow_array();
625 "delete from marc_subfield_table where bibid=? and tagorder=?");
626 $sth->execute( $bibid, $tagorder );
630 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
631 my $biblionumber = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
632 &MARCdelitem($dbh,$bibid,$itemnumber);
633 &MARCadditem($dbh,$record,$biblionumber);
636 sub MARCmodsubfield {
638 # Subroutine changes a subfield value given a subfieldid.
639 my ( $dbh, $subfieldid, $subfieldvalue ) = @_;
640 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
643 "select valuebloblink from marc_subfield_table where subfieldid=?");
644 $sth1->execute($subfieldid);
645 my ($oldvaluebloblink) = $sth1->fetchrow;
649 # if too long, use a bloblink
650 if ( length($subfieldvalue) > 255 ) {
652 # if already a bloblink, update it, otherwise, insert a new one.
653 if ($oldvaluebloblink) {
656 "update marc_blob_subfield set subfieldvalue=? where blobidlink=?"
658 $sth->execute( $subfieldvalue, $oldvaluebloblink );
663 "insert into marc_blob_subfield (subfieldvalue) values (?)");
664 $sth->execute($subfieldvalue);
666 $dbh->prepare("select max(blobidlink) from marc_blob_subfield");
668 my ($res) = $sth->fetchrow;
671 "update marc_subfield_table set subfieldvalue=null, valuebloblink=? where subfieldid=?"
673 $sth->execute( $res, $subfieldid );
678 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
681 "update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?"
683 $sth->execute( $subfieldvalue, $subfieldid );
685 $dbh->do("unlock tables");
689 "select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?"
691 $sth->execute($subfieldid);
692 my ( $bibid, $tagid, $tagorder, $subfieldcode, $x, $subfieldorder ) =
695 &MARCdelword( $dbh, $bibid, $tagid, $tagorder, $subfieldcode,
698 $dbh, $bibid, $tagid, $tagorder,
699 $subfieldcode, $subfieldorder, $subfieldvalue
701 return ( $subfieldid, $subfieldvalue );
704 sub MARCfindsubfield {
705 my ( $dbh, $bibid, $tag, $subfieldcode, $subfieldorder, $subfieldvalue ) =
707 my $resultcounter = 0;
711 "select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
712 my @bind_values = ( $bibid, $tag, $subfieldcode );
713 if ($subfieldvalue) {
714 $query .= " and subfieldvalue=?";
715 push ( @bind_values, $subfieldvalue );
718 if ( $subfieldorder < 1 ) {
721 $query .= " and subfieldorder=?";
722 push ( @bind_values, $subfieldorder );
724 my $sti = $dbh->prepare($query);
725 $sti->execute(@bind_values);
726 while ( ($subfieldid) = $sti->fetchrow ) {
728 $lastsubfieldid = $subfieldid;
730 if ( $resultcounter > 1 ) {
732 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
733 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
737 return $lastsubfieldid;
741 sub MARCfindsubfieldid {
742 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
743 my $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
744 where bibid=? and tag=? and tagorder=?
745 and subfieldcode=? and subfieldorder=?"
747 $sth->execute( $bibid, $tag, $tagorder, $subfield, $subfieldorder );
748 my ($res) = $sth->fetchrow;
750 $sth = $dbh->prepare( "select subfieldid from marc_subfield_table
751 where bibid=? and tag=? and tagorder=?
754 $sth->execute( $bibid, $tag, $tagorder, $subfield );
755 ($res) = $sth->fetchrow;
760 sub MARCfind_frameworkcode {
761 my ( $dbh, $biblionumber ) = @_;
763 $dbh->prepare("select frameworkcode from biblio where biblionumber=?");
764 $sth->execute($biblionumber);
765 my ($frameworkcode) = $sth->fetchrow;
766 return $frameworkcode;
769 sub MARCdelsubfield {
771 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
772 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
773 if ($subfieldorder) {
774 $dbh->do( "delete from marc_subfield_table where bibid='$bibid' and
775 tag='$tag' and tagorder='$tagorder'
776 and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
779 $dbh->do( "delete from marc_word where bibid='$bibid' and
780 tagsubfield='$tag$subfield' and tagorder='$tagorder'
781 and subfieldorder='$subfieldorder'
785 $dbh->do( "delete from marc_subfield_table where bibid='$bibid' and
786 tag='$tag' and tagorder='$tagorder'
787 and subfieldcode='$subfield'"
789 $dbh->do( "delete from marc_word where bibid='$bibid' and
790 tagsubfield='$tag$subfield' and tagorder='$tagorder'"
795 sub MARCkoha2marcBiblio {
797 # this function builds partial MARC::Record from the old koha-DB fields
798 my ( $dbh, $biblionumber, $biblioitemnumber ) = @_;
801 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
803 my $record = MARC::Record->new();
805 #--- if bibid, then retrieve old-style koha data
806 if ( $biblionumber > 0 ) {
809 "select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
810 from biblio where biblionumber=?"
812 $sth2->execute($biblionumber);
813 my $row = $sth2->fetchrow_hashref;
815 foreach $code ( keys %$row ) {
816 if ( $row->{$code} ) {
817 &MARCkoha2marcOnefield( $sth, $record, "biblio." . $code,
823 #--- if biblioitem, then retrieve old-style koha data
824 if ( $biblioitemnumber > 0 ) {
827 " SELECT biblioitemnumber,biblionumber,volume,number,classification,
828 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
829 volumedate,volumeddesc,timestamp,illus,pages,notes AS bnotes,size,place
831 WHERE biblioitemnumber=?
834 $sth2->execute($biblioitemnumber);
835 my $row = $sth2->fetchrow_hashref;
837 foreach $code ( keys %$row ) {
838 if ( $row->{$code} ) {
839 &MARCkoha2marcOnefield( $sth, $record, "biblioitems." . $code,
845 # other fields => additional authors, subjects, subtitles
848 " SELECT author FROM additionalauthors WHERE biblionumber=?");
849 $sth2->execute($biblionumber);
850 while ( my $row = $sth2->fetchrow_hashref ) {
851 &MARCkoha2marcOnefield( $sth, $record, "additionalauthors.author",
852 $row->{'author'},'' );
855 $dbh->prepare(" SELECT subject FROM bibliosubject WHERE biblionumber=?");
856 $sth2->execute($biblionumber);
857 while ( my $row = $sth2->fetchrow_hashref ) {
858 &MARCkoha2marcOnefield( $sth, $record, "bibliosubject.subject",
859 $row->{'subject'},'' );
863 " SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?");
864 $sth2->execute($biblionumber);
865 while ( my $row = $sth2->fetchrow_hashref ) {
866 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle",
867 $row->{'subtitle'},'' );
872 sub MARCkoha2marcItem {
874 # this function builds partial MARC::Record from the old koha-DB fields
875 my ( $dbh, $biblionumber, $itemnumber ) = @_;
877 # my $dbh=&C4Connect;
880 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
882 my $record = MARC::Record->new();
884 #--- if item, then retrieve old-style koha data
885 if ( $itemnumber > 0 ) {
887 # print STDERR "prepare $biblionumber,$itemnumber\n";
890 "SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
891 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
892 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,itemcallnumber,issues,renewals,
893 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
897 $sth2->execute($itemnumber);
898 my $row = $sth2->fetchrow_hashref;
900 foreach $code ( keys %$row ) {
901 if ( $row->{$code} ) {
902 &MARCkoha2marcOnefield( $sth, $record, "items." . $code,
910 sub MARCkoha2marcSubtitle {
912 # this function builds partial MARC::Record from the old koha-DB fields
913 my ( $dbh, $bibnum, $subtitle ) = @_;
916 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
918 my $record = MARC::Record->new();
919 &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle",
924 sub MARCkoha2marcOnefield {
925 my ( $sth, $record, $kohafieldname, $value,$frameworkcode ) = @_;
928 $sth->execute($frameworkcode,$kohafieldname);
929 if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
930 if ( $record->field($tagfield) ) {
931 my $tag = $record->field($tagfield);
933 $tag->add_subfields( $tagsubfield, $value );
934 $record->delete_field($tag);
935 $record->add_fields($tag);
939 $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
946 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
948 my $record = MARC::Record->new();
949 # my %subfieldlist=();
950 my $prevvalue; # if tag <10
951 my $field; # if tag >=10
952 for (my $i=0; $i< @$rtags; $i++) {
953 # rebuild MARC::Record
954 # warn "0=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ";
955 if (@$rtags[$i] ne $prevtag) {
958 if ($prevtag ne '000') {
959 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
961 $record->leader($prevvalue);
966 $record->add_fields($field);
969 $indicators{@$rtags[$i]}.=' ';
970 if (@$rtags[$i] <10) {
971 $prevvalue= @$rvalues[$i];
975 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
976 # warn "1=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
978 $prevtag = @$rtags[$i];
980 if (@$rtags[$i] <10) {
981 $prevvalue=@$rvalues[$i];
983 if (length(@$rvalues[$i])>0) {
984 $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
985 # warn "2=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
988 $prevtag= @$rtags[$i];
991 # the last has not been included inside the loop... do it now !
992 $record->add_fields($field) if $field;
993 # warn "HTML2MARC=".$record->as_formatted;
998 my ($dbh,$record,$frameworkcode) = @_;
999 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?");
1001 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
1004 while (($field)=$sth2->fetchrow) {
1005 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result,$frameworkcode);
1007 $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
1009 while (($field)=$sth2->fetchrow) {
1010 if ($field eq 'notes') { $field = 'bnotes'; }
1011 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result,$frameworkcode);
1013 $sth2=$dbh->prepare("SHOW COLUMNS from items");
1015 while (($field)=$sth2->fetchrow) {
1016 $result=&MARCmarc2kohaOneField($sth,"items",$field,$record,$result,$frameworkcode);
1018 # additional authors : specific
1019 $result = &MARCmarc2kohaOneField($sth,"bibliosubtitle","subtitle",$record,$result,$frameworkcode);
1020 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result,$frameworkcode);
1021 # modify copyrightdate to keep only the 1st year found
1022 my $temp = $result->{'copyrightdate'};
1023 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1025 $result->{'copyrightdate'} = $1;
1026 } else { # if no cYYYY, get the 1st date.
1027 $temp =~ m/(\d\d\d\d)/;
1028 $result->{'copyrightdate'} = $1;
1030 # modify publicationyear to keep only the 1st year found
1031 $temp = $result->{'publicationyear'};
1032 $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
1034 $result->{'publicationyear'} = $1;
1035 } else { # if no cYYYY, get the 1st date.
1036 $temp =~ m/(\d\d\d\d)/;
1037 $result->{'publicationyear'} = $1;
1042 sub MARCmarc2kohaOneField {
1044 # FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
1045 my ( $sth, $kohatable, $kohafield, $record, $result,$frameworkcode ) = @_;
1046 # warn "kohatable / $kohafield / $result / ";
1050 ( $tagfield, $subfield ) = MARCfind_marc_from_kohafield("",$kohatable.".".$kohafield,$frameworkcode);
1051 foreach my $field ( $record->field($tagfield) ) {
1052 if ($field->tag()<10) {
1053 if ($result->{$kohafield}) {
1054 $result->{$kohafield} .= " | ".$field->data();
1056 $result->{$kohafield} = $field->data();
1059 if ( $field->subfields ) {
1060 my @subfields = $field->subfields();
1061 foreach my $subfieldcount ( 0 .. $#subfields ) {
1062 if ($subfields[$subfieldcount][0] eq $subfield) {
1063 if ( $result->{$kohafield} ) {
1064 $result->{$kohafield} .= " | " . $subfields[$subfieldcount][1];
1067 $result->{$kohafield} = $subfields[$subfieldcount][1];
1074 # warn "OneField for $kohatable.$kohafield and $frameworkcode=> $tagfield, $subfield";
1080 # split a subfield string and adds it into the word table.
1083 $dbh, $bibid, $tag, $tagorder,
1084 $subfieldid, $subfieldorder, $sentence
1087 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\}|\/)/ /g;
1088 my @words = split / /, $sentence;
1089 my $stopwords = C4::Context->stopwords;
1092 "insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word)
1093 values (?,concat(?,?),?,?,?,soundex(?))"
1095 foreach my $word (@words) {
1096 # we record only words one char long and not in stopwords hash
1097 if (length($word)>=1 and !($stopwords->{uc($word)})) {
1098 $sth->execute($bibid,$tag,$subfieldid,$tagorder,$subfieldorder,$word,$word);
1100 warn "ERROR ==> insert into marc_word (bibid, tagsubfield, tagorder, subfieldorder, word, sndx_word) values ($bibid,concat($tag,$subfieldid),$tagorder,$subfieldorder,$word,soundex($word))\n";
1108 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
1109 my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
1112 "delete from marc_word where bibid=? and tagsubfield=concat(?,?) and tagorder=? and subfieldorder=?"
1114 $sth->execute( $bibid, $tag, $subfield, $tagorder, $subfieldorder );
1119 # NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW
1122 # all the following subs are useful to manage MARC-DB with complete MARC records.
1123 # it's used with marcimport, and marc management tools
1126 =item ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
1128 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
1129 are builded from the MARC::Record. If they are passed, they are used.
1131 =item NEWnewitem($dbh, $record,$bibid);
1133 adds an item in the db.
1138 my ( $dbh, $record, $frameworkcode ) = @_;
1141 my $olddata = MARCmarc2koha( $dbh, $record,$frameworkcode );
1142 $oldbibnum = OLDnewbiblio( $dbh, $olddata );
1143 $olddata->{'biblionumber'} = $oldbibnum;
1144 $oldbibitemnum = OLDnewbiblioitem( $dbh, $olddata );
1146 # search subtiles, addiauthors and subjects
1147 my ( $tagfield, $tagsubfield ) =
1148 MARCfind_marc_from_kohafield( $dbh, "additionalauthors.author",$frameworkcode );
1149 my @addiauthfields = $record->field($tagfield);
1150 foreach my $addiauthfield (@addiauthfields) {
1151 my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
1152 foreach my $subfieldcount ( 0 .. $#addiauthsubfields ) {
1153 OLDmodaddauthor( $dbh, $oldbibnum,
1154 $addiauthsubfields[$subfieldcount] );
1157 ( $tagfield, $tagsubfield ) =
1158 MARCfind_marc_from_kohafield( $dbh, "bibliosubtitle.subtitle",$frameworkcode );
1159 my @subtitlefields = $record->field($tagfield);
1160 foreach my $subtitlefield (@subtitlefields) {
1161 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1162 foreach my $subfieldcount ( 0 .. $#subtitlesubfields ) {
1163 OLDnewsubtitle( $dbh, $oldbibnum,
1164 $subtitlesubfields[$subfieldcount] );
1167 ( $tagfield, $tagsubfield ) =
1168 MARCfind_marc_from_kohafield( $dbh, "bibliosubject.subject",$frameworkcode );
1169 my @subj = $record->field($tagfield);
1171 foreach my $subject (@subj) {
1172 my @subjsubfield = $subject->subfield($tagsubfield);
1173 foreach my $subfieldcount ( 0 .. $#subjsubfield ) {
1174 push @subjects, $subjsubfield[$subfieldcount];
1177 OLDmodsubject( $dbh, $oldbibnum, 1, @subjects );
1179 # we must add bibnum and bibitemnum in MARC::Record...
1180 # we build the new field with biblionumber and biblioitemnumber
1181 # we drop the original field
1182 # we add the new builded field.
1183 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
1184 # (steve and paul : thinks 090 is a good choice)
1187 "select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
1189 $sth->execute("biblio.biblionumber");
1190 ( my $tagfield1, my $tagsubfield1 ) = $sth->fetchrow;
1191 $sth->execute("biblioitems.biblioitemnumber");
1192 ( my $tagfield2, my $tagsubfield2 ) = $sth->fetchrow;
1194 # biblionumber & biblioitemnumber are in different fields
1195 if ( $tagfield1 != $tagfield2 ) {
1196 # deal with biblionumber
1197 if ($tagfield1<10) {
1198 $newfield = MARC::Field->new(
1199 $tagfield1, $oldbibnum,
1202 $newfield = MARC::Field->new(
1203 $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
1206 # drop old field and create new one...
1207 my $old_field = $record->field($tagfield1);
1208 $record->delete_field($old_field);
1209 $record->add_fields($newfield);
1210 # deal with biblioitemnumber
1211 if ($tagfield2<10) {
1212 $newfield = MARC::Field->new(
1213 $tagfield2, $oldbibitemnum,
1216 $newfield = MARC::Field->new(
1217 $tagfield2, '', '', "$tagsubfield2" => $oldbibitemnum,
1220 # drop old field and create new one...
1221 $old_field = $record->field($tagfield2);
1222 $record->delete_field($old_field);
1223 $record->add_fields($newfield);
1224 # biblionumber & biblioitemnumber are in the same field (can't be <10 as fields <10 have only 1 value)
1226 my $newfield = MARC::Field->new(
1227 $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
1228 "$tagsubfield2" => $oldbibitemnum
1230 # drop old field and create new one...
1231 my $old_field = $record->field($tagfield1);
1232 $record->delete_field($old_field);
1233 $record->add_fields($newfield);
1235 # warn "REC : ".$record->as_formatted;
1236 my $bibid = MARCaddbiblio( $dbh, $record, $oldbibnum, $frameworkcode );
1237 return ( $bibid, $oldbibnum, $oldbibitemnum );
1240 sub NEWmodbiblioframework {
1241 my ($dbh,$bibid,$frameworkcode) =@_;
1242 my $sth = $dbh->prepare("Update marc_biblio SET frameworkcode=? WHERE bibid=$bibid");
1243 $sth->execute($frameworkcode);
1247 my ($dbh,$record,$bibid,$frameworkcode) =@_;
1248 $frameworkcode="" unless $frameworkcode;
1249 &MARCmodbiblio($dbh,$bibid,$record,$frameworkcode,0);
1250 my $oldbiblio = MARCmarc2koha($dbh,$record,$frameworkcode);
1251 my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
1252 OLDmodbibitem($dbh,$oldbiblio);
1253 # now, modify addi authors, subject, addititles.
1254 my ($tagfield,$tagsubfield) = 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,$oldbiblionumber,$addiauthsubfields[$subfieldcount]);
1262 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubtitle.subtitle",$frameworkcode);
1263 my @subtitlefields = $record->field($tagfield);
1264 foreach my $subtitlefield (@subtitlefields) {
1265 my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
1266 # delete & create subtitle again because OLDmodsubtitle can't handle new subtitles
1268 $dbh->do("delete from bibliosubtitle where biblionumber=$oldbiblionumber");
1269 foreach my $subfieldcount (0..$#subtitlesubfields) {
1270 foreach my $subtit(split /\||#/,$subtitlesubfields[$subfieldcount]) {
1271 OLDnewsubtitle($dbh,$oldbiblionumber,$subtit);
1275 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject",$frameworkcode);
1276 my @subj = $record->field($tagfield);
1278 foreach my $subject (@subj) {
1279 my @subjsubfield = $subject->subfield($tagsubfield);
1280 foreach my $subfieldcount (0..$#subjsubfield) {
1281 push @subjects,$subjsubfield[$subfieldcount];
1284 OLDmodsubject($dbh,$oldbiblionumber,1,@subjects);
1289 my ( $dbh, $bibid ) = @_;
1290 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1291 &OLDdelbiblio( $dbh, $biblio );
1294 "select biblioitemnumber from biblioitems where biblionumber=?");
1295 $sth->execute($biblio);
1296 while ( my ($biblioitemnumber) = $sth->fetchrow ) {
1297 OLDdeletebiblioitem( $dbh, $biblioitemnumber );
1299 &MARCdelbiblio( $dbh, $bibid, 0 );
1303 my ( $dbh, $record, $bibid ) = @_;
1305 # add item in old-DB
1306 my $frameworkcode=MARCfind_frameworkcode($dbh,$bibid);
1307 my $item = &MARCmarc2koha( $dbh, $record,$frameworkcode );
1308 # needs old biblionumber and biblioitemnumber
1309 $item->{'biblionumber'} =
1310 MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1313 "select biblioitemnumber from biblioitems where biblionumber=?");
1314 $sth->execute( $item->{'biblionumber'} );
1315 ( $item->{'biblioitemnumber'} ) = $sth->fetchrow;
1316 my ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, $item->{barcode} );
1318 # add itemnumber to MARC::Record before adding the item.
1321 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
1323 &MARCkoha2marcOnefield( $sth, $record, "items.itemnumber", $itemnumber,$frameworkcode );
1326 my $bib = &MARCadditem( $dbh, $record, $item->{'biblionumber'} );
1330 my ( $dbh, $record, $bibid, $itemnumber, $delete ) = @_;
1332 &MARCmoditem( $dbh, $record, $bibid, $itemnumber, $delete );
1333 my $frameworkcode=MARCfind_frameworkcode($dbh,$bibid);
1334 my $olditem = MARCmarc2koha( $dbh, $record,$frameworkcode );
1335 OLDmoditem( $dbh, $olditem );
1339 my ( $dbh, $bibid, $itemnumber ) = @_;
1340 my $biblio = &MARCfind_oldbiblionumber_from_MARCbibid( $dbh, $bibid );
1341 &OLDdelitem( $dbh, $itemnumber );
1342 &MARCdelitem( $dbh, $bibid, $itemnumber );
1347 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
1351 =item $biblionumber = OLDnewbiblio($dbh,$biblio);
1353 adds a record in biblio table. Datas are in the hash $biblio.
1355 =item $biblionumber = OLDmodbiblio($dbh,$biblio);
1357 modify a record in biblio table. Datas are in the hash $biblio.
1359 =item OLDmodsubtitle($dbh,$bibnum,$subtitle);
1361 modify subtitles in bibliosubtitle table.
1363 =item OLDmodaddauthor($dbh,$bibnum,$author);
1365 adds or modify additional authors
1366 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1368 =item $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1370 modify/adds subjects
1372 =item OLDmodbibitem($dbh, $biblioitem);
1376 =item OLDmodnote($dbh,$bibitemnum,$note
1378 modify a note for a biblioitem
1380 =item OLDnewbiblioitem($dbh,$biblioitem);
1382 adds a biblioitem ($biblioitem is a hash with the values)
1384 =item OLDnewsubject($dbh,$bibnum);
1388 =item OLDnewsubtitle($dbh,$bibnum,$subtitle);
1390 create a new subtitle
1392 =item ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1394 create a item. $item is a hash and $barcode the barcode.
1396 =item OLDmoditem($dbh,$item);
1400 =item OLDdelitem($dbh,$itemnum);
1404 =item OLDdeletebiblioitem($dbh,$biblioitemnumber);
1406 deletes a biblioitem
1407 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1409 =item OLDdelbiblio($dbh,$biblio);
1416 my ( $dbh, $biblio ) = @_;
1418 # my $dbh = &C4Connect;
1419 my $sth = $dbh->prepare("Select max(biblionumber) from biblio");
1421 my $data = $sth->fetchrow_arrayref;
1422 my $bibnum = $$data[0] + 1;
1425 if ( $biblio->{'seriestitle'} ) { $series = 1 }
1429 "insert into biblio set biblionumber = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?, unititle = ?"
1432 $bibnum, $biblio->{'title'},
1433 $biblio->{'author'}, $biblio->{'copyrightdate'},
1434 $biblio->{'serial'}, $biblio->{'seriestitle'},
1435 $biblio->{'notes'}, $biblio->{'abstract'},
1436 $biblio->{'unititle'},
1446 my ( $dbh, $biblio ) = @_;
1448 # my $dbh = C4Connect;
1455 "Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?, seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?"
1458 $biblio->{'title'}, $biblio->{'author'},
1459 $biblio->{'abstract'}, $biblio->{'copyrightdate'},
1460 $biblio->{'seriestitle'}, $biblio->{'serial'},
1461 $biblio->{'unititle'}, $biblio->{'notes'},
1462 $biblio->{'biblionumber'}
1466 return ( $biblio->{'biblionumber'} );
1469 sub OLDmodsubtitle {
1470 my ( $dbh, $bibnum, $subtitle ) = @_;
1473 "update bibliosubtitle set subtitle = ? where biblionumber = ?");
1474 $sth->execute( $subtitle, $bibnum );
1478 sub OLDmodaddauthor {
1479 my ( $dbh, $bibnum, @authors ) = @_;
1481 # my $dbh = C4Connect;
1483 $dbh->prepare("Delete from additionalauthors where biblionumber = ?");
1485 $sth->execute($bibnum);
1487 foreach my $author (@authors) {
1488 if ( $author ne '' ) {
1491 "Insert into additionalauthors set author = ?, biblionumber = ?"
1494 $sth->execute( $author, $bibnum );
1499 } # sub modaddauthor
1502 my ( $dbh, $bibnum, $force, @subject ) = @_;
1504 # my $dbh = C4Connect;
1505 my $count = @subject;
1507 for ( my $i = 0 ; $i < $count ; $i++ ) {
1508 $subject[$i] =~ s/^ //g;
1509 $subject[$i] =~ s/ $//g;
1512 "select * from catalogueentry where entrytype = 's' and catalogueentry = ?"
1514 $sth->execute( $subject[$i] );
1516 if ( my $data = $sth->fetchrow_hashref ) {
1519 if ( $force eq $subject[$i] || $force == 1 ) {
1521 # subject not in aut, chosen to force anway
1522 # so insert into cataloguentry so its in auth file
1525 "Insert into catalogueentry (entrytype,catalogueentry) values ('s',?)"
1528 $sth2->execute( $subject[$i] ) if ( $subject[$i] );
1533 "$subject[$i]\n does not exist in the subject authority file";
1536 "Select * from catalogueentry where entrytype = 's' and (catalogueentry like ? or catalogueentry like ? or catalogueentry like ?)"
1538 $sth2->execute( "$subject[$i] %", "% $subject[$i] %",
1540 while ( my $data = $sth2->fetchrow_hashref ) {
1541 $error .= "<br>$data->{'catalogueentry'}";
1548 if ( $error eq '' ) {
1550 $dbh->prepare("Delete from bibliosubject where biblionumber = ?");
1551 $sth->execute($bibnum);
1555 "Insert into bibliosubject (subject,biblionumber) values (?,?)");
1557 foreach $query (@subject) {
1558 $sth->execute( $query, $bibnum ) if ( $query && $bibnum );
1568 my ( $dbh, $biblioitem ) = @_;
1571 $biblioitem->{'itemtype'} = $dbh->quote( $biblioitem->{'itemtype'} );
1572 $biblioitem->{'url'} = $dbh->quote( $biblioitem->{'url'} );
1573 $biblioitem->{'isbn'} = $dbh->quote( $biblioitem->{'isbn'} );
1574 $biblioitem->{'issn'} = $dbh->quote( $biblioitem->{'issn'} );
1575 $biblioitem->{'publishercode'} =
1576 $dbh->quote( $biblioitem->{'publishercode'} );
1577 $biblioitem->{'publicationyear'} =
1578 $dbh->quote( $biblioitem->{'publicationyear'} );
1579 $biblioitem->{'classification'} =
1580 $dbh->quote( $biblioitem->{'classification'} );
1581 $biblioitem->{'dewey'} = $dbh->quote( $biblioitem->{'dewey'} );
1582 $biblioitem->{'subclass'} = $dbh->quote( $biblioitem->{'subclass'} );
1583 $biblioitem->{'illus'} = $dbh->quote( $biblioitem->{'illus'} );
1584 $biblioitem->{'pages'} = $dbh->quote( $biblioitem->{'pages'} );
1585 $biblioitem->{'volumeddesc'} = $dbh->quote( $biblioitem->{'volumeddesc'} );
1586 $biblioitem->{'bnotes'} = $dbh->quote( $biblioitem->{'bnotes'} );
1587 $biblioitem->{'size'} = $dbh->quote( $biblioitem->{'size'} );
1588 $biblioitem->{'place'} = $dbh->quote( $biblioitem->{'place'} );
1590 $query = "Update biblioitems set
1591 itemtype = $biblioitem->{'itemtype'},
1592 url = $biblioitem->{'url'},
1593 isbn = $biblioitem->{'isbn'},
1594 issn = $biblioitem->{'issn'},
1595 publishercode = $biblioitem->{'publishercode'},
1596 publicationyear = $biblioitem->{'publicationyear'},
1597 classification = $biblioitem->{'classification'},
1598 dewey = $biblioitem->{'dewey'},
1599 subclass = $biblioitem->{'subclass'},
1600 illus = $biblioitem->{'illus'},
1601 pages = $biblioitem->{'pages'},
1602 volumeddesc = $biblioitem->{'volumeddesc'},
1603 notes = $biblioitem->{'bnotes'},
1604 size = $biblioitem->{'size'},
1605 place = $biblioitem->{'place'}
1606 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1609 if ( $dbh->errstr ) {
1615 my ( $dbh, $bibitemnum, $note ) = @_;
1617 # my $dbh=C4Connect;
1618 my $query = "update biblioitems set notes='$note' where
1619 biblioitemnumber='$bibitemnum'";
1620 my $sth = $dbh->prepare($query);
1627 sub OLDnewbiblioitem {
1628 my ( $dbh, $biblioitem ) = @_;
1630 # my $dbh = C4Connect;
1631 my $sth = $dbh->prepare("Select max(biblioitemnumber) from biblioitems");
1636 $data = $sth->fetchrow_arrayref;
1637 $bibitemnum = $$data[0] + 1;
1641 $sth = $dbh->prepare( "insert into biblioitems set
1642 biblioitemnumber = ?, biblionumber = ?,
1643 volume = ?, number = ?,
1644 classification = ?, itemtype = ?,
1646 issn = ?, dewey = ?,
1647 subclass = ?, publicationyear = ?,
1648 publishercode = ?, volumedate = ?,
1649 volumeddesc = ?, illus = ?,
1650 pages = ?, notes = ?,
1652 marc = ?, place = ?"
1655 $bibitemnum, $biblioitem->{'biblionumber'},
1656 $biblioitem->{'volume'}, $biblioitem->{'number'},
1657 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
1658 $biblioitem->{'url'}, $biblioitem->{'isbn'},
1659 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
1660 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
1661 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
1662 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
1663 $biblioitem->{'pages'}, $biblioitem->{'bnotes'},
1664 $biblioitem->{'size'}, $biblioitem->{'lccn'},
1665 $biblioitem->{'marc'}, $biblioitem->{'place'}
1670 return ($bibitemnum);
1674 my ( $dbh, $bibnum ) = @_;
1676 $dbh->prepare("insert into bibliosubject (biblionumber) values (?)");
1677 $sth->execute($bibnum);
1681 sub OLDnewsubtitle {
1682 my ( $dbh, $bibnum, $subtitle ) = @_;
1685 "insert into bibliosubtitle set biblionumber = ?, subtitle = ?");
1686 $sth->execute( $bibnum, $subtitle ) if $subtitle;
1691 my ( $dbh, $item, $barcode ) = @_;
1693 # my $dbh = C4Connect;
1694 my $sth = $dbh->prepare("Select max(itemnumber) from items");
1700 $data = $sth->fetchrow_hashref;
1701 $itemnumber = $data->{'max(itemnumber)'} + 1;
1704 # FIXME the "notforloan" field seems to be named "loan" in some places. workaround bugfix.
1705 if ( $item->{'loan'} ) {
1706 $item->{'notforloan'} = $item->{'loan'};
1709 # if dateaccessioned is provided, use it. Otherwise, set to NOW()
1710 if ( $item->{'dateaccessioned'} ) {
1711 $sth = $dbh->prepare( "Insert into items set
1712 itemnumber = ?, biblionumber = ?,
1713 multivolumepart = ?,
1714 biblioitemnumber = ?, barcode = ?,
1715 booksellerid = ?, dateaccessioned = ?,
1716 homebranch = ?, holdingbranch = ?,
1717 price = ?, replacementprice = ?,
1718 replacementpricedate = NOW(), datelastseen = NOW(),
1719 multivolume = ?, stack = ?,
1720 itemlost = ?, wthdrawn = ?,
1721 paidfor = ?, itemnotes = ?,
1722 itemcallnumber =?, notforloan = ?,
1727 $itemnumber, $item->{'biblionumber'},
1728 $item->{'multivolumepart'},
1729 $item->{'biblioitemnumber'},$barcode,
1730 $item->{'booksellerid'}, $item->{'dateaccessioned'},
1731 $item->{'homebranch'}, $item->{'holdingbranch'},
1732 $item->{'price'}, $item->{'replacementprice'},
1733 $item->{multivolume}, $item->{stack},
1734 $item->{itemlost}, $item->{wthdrawn},
1735 $item->{paidfor}, $item->{'itemnotes'},
1736 $item->{'itemcallnumber'}, $item->{'notforloan'},
1741 $sth = $dbh->prepare( "Insert into items set
1742 itemnumber = ?, biblionumber = ?,
1743 multivolumepart = ?,
1744 biblioitemnumber = ?, barcode = ?,
1745 booksellerid = ?, dateaccessioned = NOW(),
1746 homebranch = ?, holdingbranch = ?,
1747 price = ?, replacementprice = ?,
1748 replacementpricedate = NOW(), datelastseen = NOW(),
1749 multivolume = ?, stack = ?,
1750 itemlost = ?, wthdrawn = ?,
1751 paidfor = ?, itemnotes = ?,
1752 itemcallnumber =?, notforloan = ?,
1757 $itemnumber, $item->{'biblionumber'},
1758 $item->{'multivolumepart'},
1759 $item->{'biblioitemnumber'},$barcode,
1760 $item->{'booksellerid'},
1761 $item->{'homebranch'}, $item->{'holdingbranch'},
1762 $item->{'price'}, $item->{'replacementprice'},
1763 $item->{multivolume}, $item->{stack},
1764 $item->{itemlost}, $item->{wthdrawn},
1765 $item->{paidfor}, $item->{'itemnotes'},
1766 $item->{'itemcallnumber'}, $item->{'notforloan'},
1770 if ( defined $sth->errstr ) {
1771 $error .= $sth->errstr;
1774 return ( $itemnumber, $error );
1778 my ( $dbh, $item ) = @_;
1779 $item->{'itemnum'} = $item->{'itemnumber'} unless $item->{'itemnum'};
1780 my $query = "update items set barcode=?,itemnotes=?,itemcallnumber=?,notforloan=?,location=?,multivolumepart=?,multivolume=?,stack=?,wthdrawn=?";
1782 $item->{'barcode'}, $item->{'notes'},
1783 $item->{'itemcallnumber'}, $item->{'notforloan'},
1784 $item->{'location'}, $item->{multivolumepart},
1785 $item->{multivolume}, $item->{stack},
1788 if ( $item->{'lost'} ne '' ) {
1789 $query = "update items set biblioitemnumber=?,barcode=?,itemnotes=?,homebranch=?,
1790 itemlost=?,wthdrawn=?,itemcallnumber=?,notforloan=?,
1791 location=?,multivolumepart=?,multivolume=?,stack=?,wthdrawn=?";
1793 $item->{'bibitemnum'}, $item->{'barcode'},
1794 $item->{'notes'}, $item->{'homebranch'},
1795 $item->{'lost'}, $item->{'wthdrawn'},
1796 $item->{'itemcallnumber'}, $item->{'notforloan'},
1797 $item->{'location'}, $item->{multivolumepart},
1798 $item->{multivolume}, $item->{stack},
1801 if ($item->{homebranch}) {
1802 $query.=",homebranch=?";
1803 push @bind, $item->{homebranch};
1805 if ($item->{holdingbranch}) {
1806 $query.=",holdingbranch=?";
1807 push @bind, $item->{holdingbranch};
1810 $query.=" where itemnumber=?";
1811 push @bind,$item->{'itemnum'};
1812 if ( $item->{'replacement'} ne '' ) {
1813 $query =~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1815 my $sth = $dbh->prepare($query);
1816 $sth->execute(@bind);
1823 my ( $dbh, $itemnum ) = @_;
1825 # my $dbh=C4Connect;
1826 my $sth = $dbh->prepare("select * from items where itemnumber=?");
1827 $sth->execute($itemnum);
1828 my $data = $sth->fetchrow_hashref;
1830 my $query = "Insert into deleteditems set ";
1832 foreach my $temp ( keys %$data ) {
1833 $query .= "$temp = ?,";
1834 push ( @bind, $data->{$temp} );
1839 $sth = $dbh->prepare($query);
1840 $sth->execute(@bind);
1842 $sth = $dbh->prepare("Delete from items where itemnumber=?");
1843 $sth->execute($itemnum);
1849 sub OLDdeletebiblioitem {
1850 my ( $dbh, $biblioitemnumber ) = @_;
1852 # my $dbh = C4Connect;
1853 my $sth = $dbh->prepare( "Select * from biblioitems
1854 where biblioitemnumber = ?"
1858 $sth->execute($biblioitemnumber);
1860 if ( $results = $sth->fetchrow_hashref ) {
1864 "Insert into deletedbiblioitems (biblioitemnumber, biblionumber, volume, number, classification, itemtype,
1865 isbn, issn ,dewey ,subclass ,publicationyear ,publishercode ,volumedate ,volumeddesc ,timestamp ,illus ,
1866 pages ,notes ,size ,url ,lccn ) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
1870 $results->{biblioitemnumber}, $results->{biblionumber},
1871 $results->{volume}, $results->{number},
1872 $results->{classification}, $results->{itemtype},
1873 $results->{isbn}, $results->{issn},
1874 $results->{dewey}, $results->{subclass},
1875 $results->{publicationyear}, $results->{publishercode},
1876 $results->{volumedate}, $results->{volumeddesc},
1877 $results->{timestamp}, $results->{illus},
1878 $results->{pages}, $results->{notes},
1879 $results->{size}, $results->{url},
1883 $dbh->prepare("Delete from biblioitems where biblioitemnumber = ?");
1884 $sth2->execute($biblioitemnumber);
1889 # Now delete all the items attached to the biblioitem
1890 $sth = $dbh->prepare("Select * from items where biblioitemnumber = ?");
1891 $sth->execute($biblioitemnumber);
1893 while ( my $data = $sth->fetchrow_hashref ) {
1894 my $query = "Insert into deleteditems set ";
1896 foreach my $temp ( keys %$data ) {
1897 $query .= "$temp = ?,";
1898 push ( @bind, $data->{$temp} );
1901 my $sth2 = $dbh->prepare($query);
1902 $sth2->execute(@bind);
1905 $sth = $dbh->prepare("Delete from items where biblioitemnumber = ?");
1906 $sth->execute($biblioitemnumber);
1910 } # sub deletebiblioitem
1913 my ( $dbh, $biblio ) = @_;
1914 my $sth = $dbh->prepare("select * from biblio where biblionumber=?");
1915 $sth->execute($biblio);
1916 if ( my $data = $sth->fetchrow_hashref ) {
1918 my $query = "Insert into deletedbiblio set ";
1920 foreach my $temp ( keys %$data ) {
1921 $query .= "$temp = ?,";
1922 push ( @bind, $data->{$temp} );
1925 #replacing the last , by ",?)"
1927 $sth = $dbh->prepare($query);
1928 $sth->execute(@bind);
1930 $sth = $dbh->prepare("Delete from biblio where biblionumber=?");
1931 $sth->execute($biblio);
1945 my $dbh = C4::Context->dbh;
1948 my $sth = $dbh->prepare("Select count(*) from items where biblionumber=?");
1949 $sth->execute($biblio);
1950 my $data = $sth->fetchrow_hashref;
1952 return ( $data->{'count(*)'} );
1957 my $dbh = C4::Context->dbh;
1958 my $bibnum = OLDnewbiblio( $dbh, $biblio );
1959 # finds new (MARC bibid
1960 # my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
1961 my $record = &MARCkoha2marcBiblio( $dbh, $bibnum );
1962 MARCaddbiblio( $dbh, $record, $bibnum,'' );
1968 $biblionumber = &modbiblio($biblio);
1970 Update a biblio record.
1972 C<$biblio> is a reference-to-hash whose keys are the fields in the
1973 biblio table in the Koha database. All fields must be present, not
1974 just the ones you wish to change.
1976 C<&modbiblio> updates the record defined by
1977 C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
1979 C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
1986 my $dbh = C4::Context->dbh;
1987 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1988 my $record = MARCkoha2marcBiblio($dbh,$biblionumber,$biblionumber);
1989 # finds new (MARC bibid
1990 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
1991 MARCmodbiblio($dbh,$bibid,$record,"",0);
1992 return($biblionumber);
1997 &modsubtitle($biblionumber, $subtitle);
1999 Sets the subtitle of a book.
2001 C<$biblionumber> is the biblionumber of the book to modify.
2003 C<$subtitle> is the new subtitle.
2008 my ( $bibnum, $subtitle ) = @_;
2009 my $dbh = C4::Context->dbh;
2010 &OLDmodsubtitle( $dbh, $bibnum, $subtitle );
2015 &modaddauthor($biblionumber, $author);
2017 Replaces all additional authors for the book with biblio number
2018 C<$biblionumber> with C<$author>. If C<$author> is the empty string,
2019 C<&modaddauthor> deletes all additional authors.
2024 my ( $bibnum, @authors ) = @_;
2025 my $dbh = C4::Context->dbh;
2026 &OLDmodaddauthor( $dbh, $bibnum, @authors );
2027 } # sub modaddauthor
2031 $error = &modsubject($biblionumber, $force, @subjects);
2033 $force - a subject to force
2035 $error - Error message, or undef if successful.
2040 my ( $bibnum, $force, @subject ) = @_;
2041 my $dbh = C4::Context->dbh;
2042 my $error = &OLDmodsubject( $dbh, $bibnum, $force, @subject );
2044 # When MARC is off, ensures that the MARC biblio table gets updated with new
2045 # subjects, of course, it deletes the biblio in marc, and then recreates.
2046 # This check is to ensure that no MARC data exists to lose.
2047 if (C4::Context->preference("MARC") eq '0'){
2048 my $MARCRecord = &MARCkoha2marcBiblio($dbh,$bibnum);
2049 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
2050 &MARCmodbiblio($dbh,$bibid, $MARCRecord);
2057 my ($biblioitem) = @_;
2058 my $dbh = C4::Context->dbh;
2059 &OLDmodbibitem( $dbh, $biblioitem );
2063 my ( $bibitemnum, $note ) = @_;
2064 my $dbh = C4::Context->dbh;
2065 &OLDmodnote( $dbh, $bibitemnum, $note );
2069 my ($biblioitem) = @_;
2070 my $dbh = C4::Context->dbh;
2071 my $bibitemnum = &OLDnewbiblioitem( $dbh, $biblioitem );
2074 MARCkoha2marcBiblio( $dbh, 0, $bibitemnum )
2075 ; # the 0 means "do NOT retrieve biblio, only biblioitem, in the MARC record
2077 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh,
2078 $biblioitem->{biblionumber} );
2079 &MARCaddbiblio( $dbh, $MARCbiblio, $biblioitem->{biblionumber}, '',$bibid );
2080 return ($bibitemnum);
2085 my $dbh = C4::Context->dbh;
2086 &OLDnewsubject( $dbh, $bibnum );
2090 my ( $bibnum, $subtitle ) = @_;
2091 my $dbh = C4::Context->dbh;
2092 &OLDnewsubtitle( $dbh, $bibnum, $subtitle );
2096 my ( $item, @barcodes ) = @_;
2097 my $dbh = C4::Context->dbh;
2101 foreach my $barcode (@barcodes) {
2102 ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, uc($barcode) );
2105 &MARCkoha2marcItem( $dbh, $item->{biblionumber}, $itemnumber );
2106 &MARCadditem( $dbh, $MARCitem, $item->{biblionumber} );
2113 my $dbh = C4::Context->dbh;
2114 &OLDmoditem( $dbh, $item );
2116 &MARCkoha2marcItem( $dbh, $item->{'biblionumber'}, $item->{'itemnum'} );
2118 &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $item->{biblionumber} );
2119 &MARCmoditem( $dbh, $MARCitem, $bibid, $item->{itemnum}, 0 );
2123 my ( $count, @barcodes ) = @_;
2124 my $dbh = C4::Context->dbh;
2126 my $sth = $dbh->prepare("Select * from items where barcode=?");
2127 for ( my $i = 0 ; $i < $count ; $i++ ) {
2128 $barcodes[$i] = uc $barcodes[$i];
2129 $sth->execute( $barcodes[$i] );
2130 if ( my $data = $sth->fetchrow_hashref ) {
2131 $error .= " Duplicate Barcode: $barcodes[$i]";
2139 my ($bibitemnum) = @_;
2140 my $dbh = C4::Context->dbh;
2143 $dbh->prepare("Select count(*) from items where biblioitemnumber=?");
2144 $sth->execute($bibitemnum);
2145 my $data = $sth->fetchrow_hashref;
2147 return ( $data->{'count(*)'} );
2152 my $dbh = C4::Context->dbh;
2153 &OLDdelitem( $dbh, $itemnum );
2156 sub deletebiblioitem {
2157 my ($biblioitemnumber) = @_;
2158 my $dbh = C4::Context->dbh;
2159 &OLDdeletebiblioitem( $dbh, $biblioitemnumber );
2160 } # sub deletebiblioitem
2164 my $dbh = C4::Context->dbh;
2165 &OLDdelbiblio( $dbh, $biblio );
2166 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber( $dbh, $biblio );
2167 &MARCdelbiblio( $dbh, $bibid, 0 );
2171 my ($biblionumber) = @_;
2172 my $dbh = C4::Context->dbh;
2173 my $sth = $dbh->prepare("Select * from biblio where biblionumber = ?");
2175 # || die "Cannot prepare $query\n" . $dbh->errstr;
2179 $sth->execute($biblionumber);
2181 # || die "Cannot execute $query\n" . $sth->errstr;
2182 while ( my $data = $sth->fetchrow_hashref ) {
2183 $results[$count] = $data;
2188 return ( $count, @results );
2192 my ($biblioitemnum) = @_;
2193 my $dbh = C4::Context->dbh;
2194 my $sth = $dbh->prepare( "Select * from biblioitems where
2195 biblioitemnumber = ?"
2200 $sth->execute($biblioitemnum);
2202 while ( my $data = $sth->fetchrow_hashref ) {
2203 $results[$count] = $data;
2208 return ( $count, @results );
2209 } # sub getbiblioitem
2211 sub getbiblioitembybiblionumber {
2212 my ($biblionumber) = @_;
2213 my $dbh = C4::Context->dbh;
2214 my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?");
2218 $sth->execute($biblionumber);
2220 while ( my $data = $sth->fetchrow_hashref ) {
2221 $results[$count] = $data;
2226 return ( $count, @results );
2230 my $dbh = C4::Context->dbh;
2231 my $query = "select * from itemtypes order by description";
2232 my $sth = $dbh->prepare($query);
2234 # || die "Cannot prepare $query" . $dbh->errstr;
2240 # || die "Cannot execute $query\n" . $sth->errstr;
2241 while ( my $data = $sth->fetchrow_hashref ) {
2242 $results[$count] = $data;
2247 return ( $count, @results );
2248 } # sub getitemtypes
2250 sub getitemsbybiblioitem {
2251 my ($biblioitemnum) = @_;
2252 my $dbh = C4::Context->dbh;
2253 my $sth = $dbh->prepare( "Select * from items, biblio where
2254 biblio.biblionumber = items.biblionumber and biblioitemnumber
2258 # || die "Cannot prepare $query\n" . $dbh->errstr;
2262 $sth->execute($biblioitemnum);
2264 # || die "Cannot execute $query\n" . $sth->errstr;
2265 while ( my $data = $sth->fetchrow_hashref ) {
2266 $results[$count] = $data;
2271 return ( $count, @results );
2272 } # sub getitemsbybiblioitem
2276 # Subroutine to log changes to databases
2277 # Eventually, this subroutine will be used to create a log of all changes made,
2278 # with the possibility of "undo"ing some changes
2279 my $database = shift;
2280 if ( $database eq 'kohadb' ) {
2282 my $section = shift;
2284 my $original = shift;
2287 # print STDERR "KOHA: $type $section $item $original $new\n";
2289 elsif ( $database eq 'marc' ) {
2291 my $Record_ID = shift;
2294 my $subfield_ID = shift;
2295 my $original = shift;
2298 # print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2302 #------------------------------------------------
2304 #---------------------------------------
2305 # Find a biblio entry, or create a new one if it doesn't exist.
2306 # If a "subtitle" entry is in hash, add it to subtitle table
2307 sub getoraddbiblio {
2312 # FIXME - Unused argument
2313 $biblio, # hash ref to fields
2324 $dbh = C4::Context->dbh;
2326 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2327 $sth = $dbh->prepare( "select biblionumber
2329 where title=? and author=?
2330 and copyrightdate=? and seriestitle=?"
2333 $biblio->{title}, $biblio->{author},
2334 $biblio->{copyright}, $biblio->{seriestitle}
2337 ($biblionumber) = $sth->fetchrow;
2338 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2342 # Doesn't exist. Add new one.
2343 print "<PRE>Adding biblio</PRE>\n" if $debug;
2344 ( $biblionumber, $error ) = &newbiblio($biblio);
2345 if ($biblionumber) {
2346 print "<PRE>Added with biblio number=$biblionumber</PRE>\n"
2348 if ( $biblio->{subtitle} ) {
2349 &newsubtitle( $biblionumber, $biblio->{subtitle} );
2353 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2357 return $biblionumber, $error;
2359 } # sub getoraddbiblio
2363 # converts ISO 5426 coded string to ISO 8859-1
2364 # sloppy code : should be improved in next issue
2365 my ( $string, $encoding ) = @_;
2368 # $encoding = C4::Context->preference("marcflavour") unless $encoding;
2369 if ( $encoding eq "UNIMARC" ) {
2438 # this handles non-sorting blocks (if implementation requires this)
2439 $string = nsb_clean($_);
2441 elsif ( $encoding eq "USMARC" || $encoding eq "MARC21" ) {
2442 if (/[\xc1-\xff]/) {
2495 # this handles non-sorting blocks (if implementation requires this)
2496 $string = nsb_clean($_);
2503 my $NSB = '\x88'; # NSB : begin Non Sorting Block
2504 my $NSE = '\x89'; # NSE : Non Sorting Block end
2505 # handles non sorting blocks
2509 s/[ ]{0,1}$NSE/) /gm;
2516 my $dbh = C4::Context->dbh;
2517 my $result = MARCmarc2koha($dbh,$record,'');
2519 my ($biblionumber,$bibid,$title);
2520 # search duplicate on ISBN, easy and fast...
2521 if ($result->{isbn}) {
2522 $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=?");
2523 $sth->execute($result->{'isbn'});
2524 ($biblionumber,$bibid,$title) = $sth->fetchrow;
2525 return $biblionumber,$bibid,$title if ($biblionumber);
2527 # a more complex search : build a request for SearchMarc::catalogsearch()
2528 my (@tags, @and_or, @excluding, @operator, @value, $offset,$length);
2529 # search on biblio.title
2530 my ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblio.title","");
2531 if ($record->field($tag)) {
2532 if ($record->field($tag)->subfields($subfield)) {
2533 push @tags, "'".$tag.$subfield."'";
2534 push @and_or, "and";
2535 push @excluding, "";
2536 push @operator, "contains";
2537 push @value, $record->field($tag)->subfield($subfield);
2538 # warn "for title, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2541 # ... and on biblio.author
2542 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblio.author","");
2543 if ($record->field($tag)) {
2544 if ($record->field($tag)->subfields($subfield)) {
2545 push @tags, "'".$tag.$subfield."'";
2546 push @and_or, "and";
2547 push @excluding, "";
2548 push @operator, "contains";
2549 push @value, $record->field($tag)->subfield($subfield);
2550 # warn "for author, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2553 # ... and on publicationyear.
2554 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.publicationyear","");
2555 if ($record->field($tag)) {
2556 if ($record->field($tag)->subfields($subfield)) {
2557 push @tags, "'".$tag.$subfield."'";
2558 push @and_or, "and";
2559 push @excluding, "";
2560 push @operator, "=";
2561 push @value, $record->field($tag)->subfield($subfield);
2562 # warn "for publicationyear, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2566 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.size","");
2567 if ($record->field($tag)) {
2568 if ($record->field($tag)->subfields($subfield)) {
2569 push @tags, "'".$tag.$subfield."'";
2570 push @and_or, "and";
2571 push @excluding, "";
2572 push @operator, "=";
2573 push @value, $record->field($tag)->subfield($subfield);
2574 # warn "for size, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2577 # ... and on publisher.
2578 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.publishercode","");
2579 if ($record->field($tag)) {
2580 if ($record->field($tag)->subfields($subfield)) {
2581 push @tags, "'".$tag.$subfield."'";
2582 push @and_or, "and";
2583 push @excluding, "";
2584 push @operator, "=";
2585 push @value, $record->field($tag)->subfield($subfield);
2586 # warn "for publishercode, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2589 # ... and on volume.
2590 ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.volume","");
2591 if ($record->field($tag)) {
2592 if ($record->field($tag)->subfields($subfield)) {
2593 push @tags, "'".$tag.$subfield."'";
2594 push @and_or, "and";
2595 push @excluding, "";
2596 push @operator, "=";
2597 push @value, $record->field($tag)->subfield($subfield);
2598 # warn "for volume, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
2602 my ($finalresult,$nbresult) = C4::SearchMarc::catalogsearch($dbh,\@tags,\@and_or,\@excluding,\@operator,\@value,0,10);
2603 # there is at least 1 result => return the 1st one
2605 # warn "$nbresult => ".@$finalresult[0]->{biblionumber},@$finalresult[0]->{bibid},@$finalresult[0]->{title};
2606 return @$finalresult[0]->{biblionumber},@$finalresult[0]->{bibid},@$finalresult[0]->{title};
2608 # no result, returns nothing
2615 if(substr($isbn, 0, 1) <=7) {
2616 $seg1 = substr($isbn, 0, 1);
2617 } elsif(substr($isbn, 0, 2) <= 94) {
2618 $seg1 = substr($isbn, 0, 2);
2619 } elsif(substr($isbn, 0, 3) <= 995) {
2620 $seg1 = substr($isbn, 0, 3);
2621 } elsif(substr($isbn, 0, 4) <= 9989) {
2622 $seg1 = substr($isbn, 0, 4);
2624 $seg1 = substr($isbn, 0, 5);
2626 my $x = substr($isbn, length($seg1));
2628 if(substr($x, 0, 2) <= 19) {
2629 # if(sTmp2 < 10) sTmp2 = "0" sTmp2;
2630 $seg2 = substr($x, 0, 2);
2631 } elsif(substr($x, 0, 3) <= 699) {
2632 $seg2 = substr($x, 0, 3);
2633 } elsif(substr($x, 0, 4) <= 8399) {
2634 $seg2 = substr($x, 0, 4);
2635 } elsif(substr($x, 0, 5) <= 89999) {
2636 $seg2 = substr($x, 0, 5);
2637 } elsif(substr($x, 0, 6) <= 9499999) {
2638 $seg2 = substr($x, 0, 6);
2640 $seg2 = substr($x, 0, 7);
2642 my $seg3=substr($x,length($seg2));
2643 $seg3=substr($seg3,0,length($seg3)-1) ;
2644 my $seg4 = substr($x, -1, 1);
2645 return "$seg1-$seg2-$seg3-$seg4";
2649 END { } # module clean-up code here (global destructor)
2655 Koha Developement team <info@koha.org>
2657 Paul POULAIN paul.poulain@free.fr
2663 # Revision 1.123 2005/08/09 14:10:28 tipaul
2664 # 1st commit to go to zebra.
2665 # don't update your cvs if you want to have a working head...
2667 # this commit contains :
2668 # * updater/updatedatabase : get rid with marc_* tables, but DON'T remove them. As a lot of things uses them, it would not be a good idea for instance to drop them. If you really want to play, you can rename them to test head without them but being still able to reintroduce them...
2669 # * Biblio.pm : modify MARCgetbiblio to find the raw marc record in biblioitems.marc field, not from marc_subfield_table, modify MARCfindframeworkcode to find frameworkcode in biblio.frameworkcode, modify some other subs to use biblio.biblionumber & get rid of bibid.
2670 # * other files : get rid of bibid and use biblionumber instead.
2673 # * does not do anything on zebra yet.
2674 # * if you rename marc_subfield_table, you can't search anymore.
2675 # * you can view a biblio & bibliodetails, go to MARC editor, but NOT save any modif.
2676 # * don't try to add a biblio, it would add data poorly... (don't try to delete either, it may work, but that would be a surprise ;-) )
2678 # IMPORTANT NOTE : you need MARC::XML package (http://search.cpan.org/~esummers/MARC-XML-0.7/lib/MARC/File/XML.pm), that requires a recent version of MARC::Record
2679 # Updatedatabase stores the iso2709 data in biblioitems.marc field & an xml version in biblioitems.marcxml Not sure we will keep it when releasing the stable version, but I think it's a good idea to have something readable in sql, at least for development stage.
2681 # Revision 1.122 2005/08/04 13:27:48 tipaul
2682 # synch'ing 2.2 and head
2684 # Revision 1.115.2.18 2005/08/02 07:45:44 tipaul
2685 # fix for bug http://bugs.koha.org/cgi-bin/bugzilla/show_bug.cgi?id=1009
2686 # (Not all items fields mapped to MARC)
2688 # Revision 1.115.2.17 2005/08/01 15:15:43 tipaul
2689 # adding decoder for Ä string
2691 # Revision 1.115.2.16 2005/07/28 19:56:15 tipaul
2692 # * removing a useless & CPU consuming call to MARCgetbiblio
2693 # * Leader management.
2694 # If you create a MARC tag "000", with a subfield '@', it will be managed as the leader.
2695 # Seems to work correctly.
2697 # Now going to create a plugin for leader()
2699 # Revision 1.115.2.15 2005/07/19 15:25:40 tipaul
2700 # * fixing a bug in subfield order when MARCgetbiblio
2701 # * 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.
2702 # * adding some diacritic decoding (Ä, Ü...)
2704 # Revision 1.115.2.14 2005/06/27 23:24:06 hdl
2705 # Display dashed ISBN
2707 # Revision 1.115.2.13 2005/05/31 12:44:26 tipaul
2708 # patch from Genji (Waylon R.) to update subjects in MARC tables when systempref has MARC=OFF
2710 # Revision 1.115.2.12 2005/05/30 11:22:41 tipaul
2711 # 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)
2713 # Revision 1.115.2.11 2005/05/25 15:48:43 tipaul
2714 # * removing my for variables already declared
2715 # * updating biblio.unititle field as well as other fields in biblio table
2717 # Revision 1.115.2.10 2005/05/25 09:30:50 hdl
2718 # Adding NEWmodbiblioframework feature
2719 # Used by addbiblio.pl when modifying a framework selection.
2721 # Revision 1.115.2.9 2005/04/07 10:05:25 tipaul
2722 # adding / to the list of symbols that are replace by spaces for searches
2724 # Revision 1.115.2.8 2005/03/25 16:23:49 tipaul
2725 # some improvements :
2726 # * return immediatly when a subfield is empty
2727 # * search duplicate on isbn must be done only when there is an isbn ;-)
2729 # Revision 1.115.2.7 2005/03/10 15:52:28 tipaul
2730 # * adding glass to opac marc detail.
2731 # * 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)
2732 # * fixing bug with libopac
2734 # Revision 1.115.2.6 2005/03/09 15:56:01 tipaul
2735 # Changing MARCmoditem to be like MARCmodbiblio : a modif is a delete & create.
2736 # Longer, but solves problems with repeated subfields.
2738 # The previous version was not buggy except under certain circumstances (a repeated subfield, that does not exist usually in items)
2740 # Revision 1.115.2.5 2005/02/24 13:54:04 tipaul
2741 # exporting MARCdelsubfield sub. It's used in authority merging.
2742 # Modifying it too to enable deletion of all subfields from a given tag/subfield or just one.
2744 # Revision 1.115.2.4 2005/02/17 12:44:25 tipaul
2745 # bug in acquisition : the title was also stored as subtitle.
2747 # Revision 1.115.2.3 2005/02/10 13:14:36 tipaul
2748 # * multiple main authors are now correctly handled in simple (non-MARC) view
2750 # Revision 1.115.2.2 2005/01/11 16:02:35 tipaul
2751 # in catalogue, modifs were not stored properly the non-MARC item DB. Affect only libraries without barcodes.
2753 # Revision 1.115.2.1 2005/01/11 14:45:37 tipaul
2754 # bugfix : issn were not stored correctly in non-MARC DB on biblio modification
2756 # Revision 1.115 2005/01/06 14:32:17 tipaul
2757 # improvement of speed for bulkmarcimport.
2758 # A sub had been forgotten to use the C4::Context->marcfromkohafield array, that caches DB datas.
2759 # this is only a little improvement for normal DB modif, but almost x2 the speed of bulkmarcimport... from 6records/seconds to more than 10.
2761 # Revision 1.114 2005/01/03 10:48:33 tipaul
2762 # * bugfix for the search on a MARC detail, when you clic on the magnifying glass (caused an internal server error)
2763 # * 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.
2765 # Revision 1.113 2004/12/10 16:27:53 tipaul
2766 # 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)
2767 # In 2.4, a new DB structure will highly speed things and this limit will be removed.
2768 # FindDuplicate is activated again, the perf problems were due to this problem.
2770 # Revision 1.112 2004/12/08 10:14:42 tipaul
2771 # * desactivate FindDuplicate
2774 # Revision 1.111 2004/11/25 17:39:44 tipaul
2775 # removing useless &branches in package declaration
2777 # Revision 1.110 2004/11/24 16:00:01 tipaul
2778 # removing sub branches (commited by chris for MARC=OFF bugfix, but sub branches is already in Acquisition.pm)
2780 # Revision 1.109 2004/11/24 15:58:31 tipaul
2781 # * critical fix for acquisition (see RC3 release notes)
2782 # * critical fix for duplicate finder
2784 # Revision 1.108 2004/11/19 19:41:22 rangi
2785 # Shifting branches() from deprecated C4::Catalogue to C4::Biblio
2786 # Allowing the non marc interface acquisitions to work.
2788 # Revision 1.107 2004/11/05 10:15:27 tipaul
2789 # Improving FindDuplicate to find duplicate records on adding biblio
2791 # Revision 1.106 2004/11/02 16:44:45 tipaul
2792 # new feature : checking for duplicate biblio.
2794 # For instance, it's only done on ISBN only. Will be improved soon.
2796 # When a duplicate is detected, the biblio is not saved, but the user is asked for a confirmations.
2798 # Revision 1.105 2004/09/23 16:15:37 tipaul
2801 # Revision 1.104 2004/09/16 15:06:46 tipaul
2802 # enabling # (| still possible too) for repeatable subfields
2804 # Revision 1.103 2004/09/06 14:17:34 tipaul
2805 # some commented warning added + 1 major bugfix => drop empty fields, NOT fields containing 0
2807 # Revision 1.102 2004/09/06 10:00:19 tipaul
2808 # adding a "location" field to the library.
2809 # This field is useful when the callnumber contains no information on the room where the item is stored.
2810 # With this field, we now have 3 levels of informations to find a book :
2815 # This should be versatile enough to solve any storing method.
2816 # 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.
2818 # Revision 1.101 2004/08/18 16:01:37 tipaul
2819 # modifs to support frameworkcodes
2821 # Revision 1.100 2004/08/13 16:37:25 tipaul
2822 # adding frameworkcode to API in some subs
2824 # Revision 1.99 2004/07/30 13:54:50 doxulting
2825 # Beginning of serial commit
2827 # Revision 1.98 2004/07/15 09:48:10 tipaul
2828 # * removing useless sub
2829 # * minor bugfix in moditem (managing homebranch & holdingbranch)
2831 # Revision 1.97 2004/07/02 15:53:53 tipaul
2832 # bugfix (due to frameworkcode field)
2834 # Revision 1.96 2004/06/29 16:07:10 tipaul
2835 # last sync for 2.1.0 release
2837 # Revision 1.95 2004/06/26 23:19:59 rangi
2838 # Fixing modaddauthor, and adding getitemtypes.
2839 # Also tidying up formatting of code
2841 # Revision 1.94 2004/06/17 08:16:32 tipaul
2842 # merging tag & subfield in marc_word for better perfs
2844 # Revision 1.93 2004/06/11 15:38:06 joshferraro
2845 # Changes MARCaddword to index words >= 1 char ... needed for more accurate
2846 # searches using SearchMarc routines.
2848 # Revision 1.92 2004/06/10 08:29:01 tipaul
2849 # MARC authority management (continued)
2851 # Revision 1.91 2004/06/03 10:03:01 tipaul
2852 # * frameworks and itemtypes are independant
2853 # * in the MARC editor, showing the + to duplicate a tag only if the tag is repeatable
2855 # Revision 1.90 2004/05/28 08:25:53 tipaul
2856 # hidding hidden & isurl constraints into MARC subfield structure
2858 # Revision 1.89 2004/05/27 21:47:21 rangi
2861 # Revision 1.88 2004/05/18 15:23:49 tipaul
2862 # framework management : 1 MARC framework for each itemtype
2864 # Revision 1.87 2004/05/18 11:54:07 tipaul
2865 # getitemtypes moved in Koha.pm
2867 # Revision 1.86 2004/05/03 09:19:22 tipaul
2868 # some fixes for mysql prepare & execute
2870 # Revision 1.85 2004/04/02 14:55:48 tipaul
2871 # renaming items.bulk field to items.itemcallnumber.
2872 # Will be used to store call number for libraries that don't use dewey classification.
2873 # Note it's related to ITEMS, not biblio.
2875 # Revision 1.84 2004/03/24 17:18:30 joshferraro
2876 # Fixes bug 749 by removing the comma on line 1488.
2878 # Revision 1.83 2004/03/15 14:31:50 tipaul
2879 # adding a minor check
2881 # Revision 1.82 2004/03/07 05:47:31 acli
2882 # Various updates/fixes from rel_2_0
2883 # Fixes for bugs 721 (templating), 727, and 734
2885 # Revision 1.81 2004/03/06 20:26:13 tipaul
2886 # adding seealso feature in MARC searches
2888 # Revision 1.80 2004/02/12 13:40:56 tipaul
2889 # deleting subs duplicated by error
2891 # Revision 1.79 2004/02/11 08:40:09 tipaul
2892 # synch'ing 2.0.0 branch and head
2894 # Revision 1.78.2.3 2004/02/10 13:15:46 tipaul
2895 # removing 2 warnings
2897 # Revision 1.78.2.2 2004/01/26 10:38:06 tipaul
2898 # dealing correctly "bulk" field
2900 # Revision 1.78.2.1 2004/01/13 17:29:53 tipaul
2901 # * minor html fixes
2902 # * adding publisher in acquisition process (& ordering basket by publisher)
2904 # Revision 1.78 2003/12/09 15:57:28 tipaul
2905 # rolling back to working char_decode sub
2907 # Revision 1.77 2003/12/03 17:47:14 tipaul
2908 # bugfixes for biblio deletion
2910 # Revision 1.76 2003/12/03 01:43:41 slef
2913 # Revision 1.75 2003/12/03 01:42:03 slef
2914 # bug 662 fixes securing DBI
2916 # Revision 1.74 2003/11/28 09:48:33 tipaul
2917 # bugfix : misusing prepare & execute => now using prepare(?) and execute($var)
2919 # Revision 1.73 2003/11/28 09:45:25 tipaul
2920 # bugfix for iso2709 file import in the "notforloan" field.
2922 # But notforloan field called "loan" somewhere, so in case "loan" is used, copied to "notforloan" to avoid a bug.
2924 # Revision 1.72 2003/11/24 17:40:14 tipaul
2927 # Revision 1.71 2003/11/24 16:28:49 tipaul
2928 # biblio & item deletion now works fine in MARC editor.
2929 # Stores deleted biblio/item in the marc field of the deletedbiblio/deleteditem table.
2931 # Revision 1.70 2003/11/24 13:29:55 tipaul
2932 # moving $id from beginning to end of file (70 commits... huge comments...)
2934 # Revision 1.69 2003/11/24 13:27:17 tipaul
2935 # fix for #380 (bibliosubject)
2937 # Revision 1.68 2003/11/06 17:18:30 tipaul
2940 # 1st draft for MARC biblio deletion.
2941 # Still does not work well, but at least, Biblio.pm compiles & it should'nt break too many things
2942 # (Note the trash in the MARCdetail, but don't use it, please :-) )
2944 # Revision 1.67 2003/10/25 08:46:27 tipaul
2945 # minor fixes for bilbio deletion (still buggy)
2947 # Revision 1.66 2003/10/17 10:02:56 tipaul
2948 # Indexing only words longer than 2 letters. Was >=2 before, & 2 letters words usually means nothing.
2950 # Revision 1.65 2003/10/14 09:45:29 tipaul
2951 # 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)
2953 # Revision 1.64 2003/10/06 15:20:51 tipaul
2954 # fix for 536 (subtitle error)
2956 # Revision 1.63 2003/10/01 13:25:49 tipaul
2957 # seems a char encoding problem modified something in char_decode sub... changing back to something that works...
2959 # Revision 1.62 2003/09/17 14:21:13 tipaul
2960 # fixing bug that makes a MARC biblio disappear when using full acquisition (order => recieve ==> MARC editor).
2961 # Before this 2 lines fix, the MARC biblio was deleted during recieve, and had to be entirely recreated :-(
2963 # Revision 1.61 2003/09/17 10:24:39 tipaul
2964 # notforloan value in itemtype was overwritting notforloan value in a given item.
2965 # I changed this behaviour :
2966 # if notforloan is set for a given item, and NOT for all items from this itemtype, the notforloan is kept.
2967 # If notforloan is set for itemtype, it's used (and impossible to loan a specific item from this itemtype)
2969 # Revision 1.60 2003/09/04 14:11:23 tipaul
2970 # fix for 593 (data duplication in MARC-DB)
2972 # Revision 1.58 2003/08/06 12:54:52 tipaul
2973 # fix for publicationyear : extracting numeric value from MARC string, like for copyrightdate.
2974 # (note that copyrightdate still extracted to get numeric format)
2976 # Revision 1.57 2003/07/15 23:09:18 slef
2977 # change show columns to use biblioitems bnotes too
2979 # Revision 1.56 2003/07/15 11:34:52 slef
2980 # fixes from paul email
2982 # Revision 1.55 2003/07/15 00:02:49 slef
2983 # Work on bug 515... can we do a single-side rename of notes to bnotes?
2985 # Revision 1.54 2003/07/11 11:51:32 tipaul
2986 # *** empty log message ***
2988 # Revision 1.52 2003/07/10 10:37:19 tipaul
2989 # fix for copyrightdate problem, #514
2991 # Revision 1.51 2003/07/02 14:47:17 tipaul
2992 # fix for #519 : items.dateaccessioned imports incorrectly
2994 # Revision 1.49 2003/06/17 11:21:13 tipaul
2995 # improvments/fixes for z3950 support.
2996 # * Works now even on ADD, not only on MODIFY
2997 # * able to search on ISBN, author, title
2999 # Revision 1.48 2003/06/16 09:22:53 rangi
3000 # Just added an order clause to getitemtypes
3002 # Revision 1.47 2003/05/20 16:22:44 tipaul
3003 # fixing typo in Biblio.pm POD
3005 # Revision 1.46 2003/05/19 13:45:18 tipaul
3006 # support for subtitles, additional authors, subject.
3007 # 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.
3008 # Note that some OLD-DB subs are strange (dummy ?) see OLDmodsubject, OLDmodsubtitle, OLDmodaddiauthor in C4/Biblio.pm
3009 # 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.
3011 # Revision 1.45 2003/04/29 16:50:49 tipaul
3012 # really proud of this commit :-)
3013 # z3950 search and import seems to works fine.
3014 # Let me explain how :
3015 # * a "search z3950" button is added in the addbiblio template.
3016 # * when clicked, a popup appears and z3950/search.pl is called
3017 # * z3950/search.pl calls addz3950search in the DB
3018 # * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table.
3019 # * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending.
3020 # * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled
3023 # * 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.
3024 # * 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.
3026 # Revision 1.44 2003/04/28 13:07:14 tipaul
3027 # Those fixes solves the "internal server error" with MARC::Record 1.12.
3028 # It was due to an illegal contruction in Koha : we tried to retrive subfields from <10 tags.
3029 # That's not possible. MARC::Record accepted this in 0.93 version, but it was fixed after.
3030 # Now, the construct/retrieving is OK !
3032 # Revision 1.43 2003/04/10 13:56:02 tipaul
3034 # * worked in 1.9.0, but not in 1.9.1 :
3035 # - modif of a biblio didn't work
3036 # - 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.
3038 # * did not work before :
3039 # - repeatable subfields now works correctly. Enter 2 subfields separated by | and they will be splitted during saving.
3040 # - dropped the last subfield of the MARC form :-(
3042 # Internal changes :
3043 # - 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.
3044 # Note the MARCdelbiblio has been rewritted to enable deletion of a biblio WITHOUT deleting items.
3046 # Revision 1.42 2003/04/04 08:41:11 tipaul
3047 # last commits before 1.9.1
3049 # Revision 1.41 2003/04/01 12:26:43 tipaul
3052 # Revision 1.40 2003/03/11 15:14:03 tipaul
3055 # Revision 1.39 2003/03/07 16:35:42 tipaul
3056 # * moving generic functions to Koha.pm
3057 # * improvement of SearchMarc.pm
3061 # Revision 1.38 2003/02/27 16:51:59 tipaul
3062 # * moving prepare / execute to ? form.
3065 # * road to 1.9.2 => acquisition and cataloguing merging
3067 # Revision 1.37 2003/02/12 11:03:03 tipaul
3068 # Support for 000 -> 010 fields.
3069 # Those fields doesn't have subfields.
3070 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
3071 # 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.
3073 # Revision 1.36 2003/02/12 11:01:01 tipaul
3074 # Support for 000 -> 010 fields.
3075 # Those fields doesn't have subfields.
3076 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
3077 # 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.
3079 # Revision 1.35 2003/02/03 18:46:00 acli
3080 # Minor factoring in C4/Biblio.pm, plus change to export the per-tag
3081 # 'mandatory' property to a per-subfield 'tag_mandatory' template parameter,
3082 # so that addbiblio.tmpl can distinguish between mandatory subfields in a
3083 # mandatory tag and mandatory subfields in an optional tag
3085 # Not-minor factoring in acqui.simple/addbiblio.pl to make the if-else blocks
3086 # smaller, and to add some POD; need further testing for this
3088 # Added function to check if a MARC subfield name is "koha-internal" (instead
3089 # of checking it for 'lib' and 'tag' everywhere); temporarily added to Koha.pm
3091 # Use above function in acqui.simple/additem.pl and search.marc/search.pl
3093 # Revision 1.34 2003/01/28 14:50:04 tipaul
3094 # fixing MARCmodbiblio API and reindenting code
3096 # Revision 1.33 2003/01/23 12:22:37 tipaul
3097 # adding char_decode to decode MARC21 or UNIMARC extended chars
3099 # Revision 1.32 2002/12/16 15:08:50 tipaul
3100 # small but important bugfix (fixes a problem in export)
3102 # Revision 1.31 2002/12/13 16:22:04 tipaul
3103 # 1st draft of marc export
3105 # Revision 1.30 2002/12/12 21:26:35 tipaul
3106 # YAB ! (Yet Another Bugfix) => related to biblio modif
3107 # (some warning cleaning too)
3109 # Revision 1.29 2002/12/12 16:35:00 tipaul
3110 # adding authentification with Auth.pm and
3111 # MAJOR BUGFIX on marc biblio modification
3113 # Revision 1.28 2002/12/10 13:30:03 tipaul
3114 # fugfixes from Dombes Abbey work
3116 # Revision 1.27 2002/11/19 12:36:16 tipaul
3118 # various bugfixes, improvments, and migration from acquisition.pm to biblio.pm
3120 # Revision 1.26 2002/11/12 15:58:43 tipaul
3123 # * 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)
3125 # Revision 1.25 2002/10/25 10:58:26 tipaul
3127 # * bugfixes and improvements
3129 # Revision 1.24 2002/10/24 12:09:01 arensb
3130 # Fixed "no title" warning when generating HTML documentation from POD.
3132 # Revision 1.23 2002/10/16 12:43:08 arensb
3133 # Added some FIXME comments.
3135 # Revision 1.22 2002/10/15 13:39:17 tipaul
3136 # removing Acquisition.pm
3137 # deleting unused code in biblio.pm, rewriting POD and answering most FIXME comments
3139 # Revision 1.21 2002/10/13 11:34:14 arensb
3140 # Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
3141 # Thus, $x = $x+2 becomes $x += 2, and so forth.
3143 # Revision 1.20 2002/10/13 08:28:32 arensb
3144 # Deleted unused variables.
3145 # Removed trailing whitespace.
3147 # Revision 1.19 2002/10/13 05:56:10 arensb
3148 # Added some FIXME comments.
3150 # Revision 1.18 2002/10/11 12:34:53 arensb
3151 # Replaced &requireDBI with C4::Context->dbh
3153 # Revision 1.17 2002/10/10 14:48:25 tipaul
3156 # Revision 1.16 2002/10/07 14:04:26 tipaul
3157 # road to 1.3.1 : viewing MARC biblio
3159 # Revision 1.15 2002/10/05 09:49:25 arensb
3160 # Merged with arensb-context branch: use C4::Context->dbh instead of
3161 # &C4Connect, and generally prefer C4::Context over C4::Database.
3163 # Revision 1.14 2002/10/03 11:28:18 tipaul
3164 # Extending Context.pm to add stopword management and using it in MARC-API.
3165 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
3167 # Revision 1.13 2002/10/02 16:26:44 tipaul
3170 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
3171 # Merged in changes from main branch.
3173 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
3174 # Added a whole mess of FIXME comments.
3176 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
3177 # Added some missing semicolons.
3179 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
3180 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
3183 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
3184 # Added a whole mess of FIXME comments.
3186 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
3187 # Added some missing semicolons.
3189 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
3190 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
3193 # Revision 1.12 2002/10/01 11:48:51 arensb
3194 # Added some FIXME comments, mostly marking duplicate functions.
3196 # Revision 1.11 2002/09/24 13:49:26 tipaul
3197 # long WAS the road to 1.3.0...
3198 # coming VERY SOON NOW...
3199 # modifying installer and buildrelease to update the DB
3201 # Revision 1.10 2002/09/22 16:50:08 arensb
3202 # Added some FIXME comments.
3204 # Revision 1.9 2002/09/20 12:57:46 tipaul
3205 # long is the road to 1.4.0
3206 # * MARCadditem and MARCmoditem now wroks
3207 # * various bugfixes in MARC management
3208 # !!! 1.3.0 should be released very soon now. Be careful !!!
3210 # Revision 1.8 2002/09/10 13:53:52 tipaul
3211 # MARC API continued...
3213 # * 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)
3215 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
3217 # Revision 1.7 2002/08/14 18:12:51 tonnesen
3218 # Added copyright statement to all .pl and .pm files
3220 # Revision 1.6 2002/07/25 13:40:31 tipaul
3221 # pod documenting the API.
3223 # Revision 1.5 2002/07/24 16:11:37 tipaul
3225 # Database.pm and Output.pm are almost not modified (var test...)
3227 # Biblio.pm is almost completly rewritten.
3229 # WHAT DOES IT ??? ==> END of Hitchcock suspens
3231 # 1st, it does... nothing...
3232 # 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 ...
3234 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
3235 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
3236 # * 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.
3237 # * 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.
3238 # 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 ;-)
3240 # 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.
3241 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.