4 # Revision 1.17 2002/10/10 14:48:25 tipaul
7 # Revision 1.16 2002/10/07 14:04:26 tipaul
8 # road to 1.3.1 : viewing MARC biblio
10 # Revision 1.15 2002/10/05 09:49:25 arensb
11 # Merged with arensb-context branch: use C4::Context->dbh instead of
12 # &C4Connect, and generally prefer C4::Context over C4::Database.
14 # Revision 1.14 2002/10/03 11:28:18 tipaul
15 # Extending Context.pm to add stopword management and using it in MARC-API.
16 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
18 # Revision 1.13 2002/10/02 16:26:44 tipaul
21 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
22 # Merged in changes from main branch.
24 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
25 # Added a whole mess of FIXME comments.
27 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
28 # Added some missing semicolons.
30 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
31 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
34 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
35 # Added a whole mess of FIXME comments.
37 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
38 # Added some missing semicolons.
40 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
41 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
44 # Revision 1.12 2002/10/01 11:48:51 arensb
45 # Added some FIXME comments, mostly marking duplicate functions.
47 # Revision 1.11 2002/09/24 13:49:26 tipaul
48 # long WAS the road to 1.3.0...
49 # coming VERY SOON NOW...
50 # modifying installer and buildrelease to update the DB
52 # Revision 1.10 2002/09/22 16:50:08 arensb
53 # Added some FIXME comments.
55 # Revision 1.9 2002/09/20 12:57:46 tipaul
56 # long is the road to 1.4.0
57 # * MARCadditem and MARCmoditem now wroks
58 # * various bugfixes in MARC management
59 # !!! 1.3.0 should be released very soon now. Be careful !!!
61 # Revision 1.8 2002/09/10 13:53:52 tipaul
62 # MARC API continued...
64 # * 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)
66 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
68 # Revision 1.7 2002/08/14 18:12:51 tonnesen
69 # Added copyright statement to all .pl and .pm files
71 # Revision 1.6 2002/07/25 13:40:31 tipaul
72 # pod documenting the API.
74 # Revision 1.5 2002/07/24 16:11:37 tipaul
76 # Database.pm and Output.pm are almost not modified (var test...)
78 # Biblio.pm is almost completly rewritten.
80 # WHAT DOES IT ??? ==> END of Hitchcock suspens
82 # 1st, it does... nothing...
83 # 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 ...
85 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
86 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
87 # * 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.
88 # * 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.
89 # 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 "ALLxxx" : 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 ;-)
91 # 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.
92 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
96 # move from 1.2 to 1.4 version :
97 # 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
98 # In the 1.4 version, we want to do 2 differents things :
99 # - keep populating the old-DB, that has a LOT less datas than MARC
100 # - populate the MARC-DB
101 # To populate the DBs we have 2 differents sources :
102 # - the standard acquisition system (through book sellers), that does'nt use MARC data
103 # - the MARC acquisition system, that uses MARC data.
105 # thus, we have 2 differents cases :
106 # - 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
107 # - 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.
108 # we MUST have an API for true MARC data, that populate MARC-DB then old-DB
110 # That's why we need 4 subs :
111 # all subs beginning by MARC manage only MARC tables. They manage MARC-DB with MARC::Record parameters
112 # all subs beginning by OLD manage only OLD-DB tables. They manage old-DB with old-DB parameters
113 # all subs beginning by ALL 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
114 # all subs beginning by seomething else are the old-style API. They use old-DB as parameter, then call internally the OLD and MARC subs.
116 # only ALL and old-style API should be used in koha. MARC and OLD is used internally only
118 # Thus, we assume a nice translation to future versions : if we want in a 1.6 release completly forget old-DB, we can do it easily.
119 # in 1.4 version, the translations will be nicer, as we have NOTHING to do in code. Everything has to be done in Biblio.pm ;-)
123 # Copyright 2000-2002 Katipo Communications
125 # This file is part of Koha.
127 # Koha is free software; you can redistribute it and/or modify it under the
128 # terms of the GNU General Public License as published by the Free Software
129 # Foundation; either version 2 of the License, or (at your option) any later
132 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
133 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
134 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
136 # You should have received a copy of the GNU General Public License along with
137 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
138 # Suite 330, Boston, MA 02111-1307 USA
146 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
148 # set the version for version checking
153 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
154 # as the old-style API and the ALL one are the only public functions.
157 &updateBiblio &updateBiblioItem &updateItem
158 &itemcount &newbiblio &newbiblioitem
159 &modnote &newsubject &newsubtitle
160 &modbiblio &checkitems
161 &newitems &modbibitem
162 &modsubtitle &modsubject &modaddauthor &moditem &countitems
163 &delitem &deletebiblioitem &delbiblio
164 &getitemtypes &getbiblio
165 &getbiblioitembybiblionumber
166 &getbiblioitem &getitemsbybiblioitem &isbnsearch
168 &newcompletebiblioitem
170 &MARCfind_oldbiblionumber_from_MARCbibid
171 &MARCfind_MARCbibid_from_oldbiblionumber
173 &ALLnewbiblio &ALLnewitem
176 &MARCaddbiblio &MARCadditem
177 &MARCmodsubfield &MARCaddsubfield
178 &MARCmodbiblio &MARCmoditem
180 &MARCkoha2marcBiblio &MARCmarc2koha &MARCkoha2marcItem
181 &MARCgetbiblio &MARCgetitem
182 &MARCaddword &MARCdelword
187 # your exported package globals go here,
188 # as well as any optionally exported functions
190 @EXPORT_OK = qw($Var1 %Hashit); # FIXME - These are never used
194 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
197 # all the following subs takes a MARC::Record as parameter and manage
198 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
199 # ALLxxx subs (xxx deals with old-DB parameters, the ALLxxx deals with MARC-DB parameter)
204 all subs requires/use $dbh as 1st parameter.
205 NOTE : all those subs are private and must be used only inside Biblio.pm (called by a old API sub, or the ALLsub)
209 =head2 @tagslib = &MARCgettagslib($dbh,1|0);
210 last param is 1 for liblibrarian and 0 for libopac
211 returns a hash with tag/subfield meaning
213 =head2 ($tagfield,$tagsubfield) = &MARCfindmarc_from_kohafield($dbh,$kohafield);
214 finds MARC tag and subfield for a given kohafield
215 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
217 =head2 $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
218 finds a old-db biblio number for a given MARCbibid number
220 =head2 $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
221 finds a MARC bibid from a old-db biblionumber
223 =head2 &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
224 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
226 =head2 &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
227 adds a subfield in a biblio (in the MARC tables only).
229 =head2 $MARCRecord = &MARCgetbiblio($dbh,$bibid);
230 Returns a MARC::Record for the biblio $bibid.
232 =head2 &MARCmodbiblio($dbh,$bibid,$delete,$record);
233 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
234 if $delete == 1, every field/subfield not found is deleted in the biblio
235 otherwise, only data passed to MARCmodbiblio is managed.
236 thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
238 =head2 ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
239 MARCmodsubfield changes the value of a given subfield
241 =head2 $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
242 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
243 Returns -1 if more than 1 answer
245 =head2 $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
246 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
248 =head2 &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
249 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
251 =head2 &MARCdelbiblio($dbh,$bibid);
252 MARCdelbiblio delete biblio $bibid
254 =head2 $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
255 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
257 =head2 $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
258 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
260 =head2 $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
261 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
263 =head2 &MARCkoha2marcOnefield => used by MARCkoha2marc and should not be useful elsewhere
265 =head2 $olddb = &MARCmarc2koha($dbh,$MARCRecord);
266 builds a hash with old-db datas from a MARC::Record
268 =head2 &MARCmarc2kohaOnefield => used by MARCmarc2koha and should not be useful elsewhere
270 =head2 MARCaddword => used to manage MARC_word table and should not be useful elsewhere
272 =head2 MARCdelword => used to manage MARC_word table and should not be useful elsewhere
276 Paul POULAIN paul.poulain@free.fr
281 my ($dbh,$forlibrarian)= @_;
283 if ($forlibrarian eq 1) {
284 $sth=$dbh->prepare("select tagfield,liblibrarian as lib from marc_tag_structure");
286 $sth=$dbh->prepare("select tagfield,libopac as lib from marc_tag_structure");
289 my ($lib,$tag,$res,$tab);
290 while ( ($tag,$lib,$tab) = $sth->fetchrow) {
291 $res->{$tag}->{lib}=$lib;
292 $res->{$tab}->{tab}="";
295 if ($forlibrarian eq 1) {
296 $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure");
298 $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib,tab from marc_subfield_structure");
303 while ( ($tag,$subfield,$lib,$tab) = $sth->fetchrow) {
304 $res->{$tag}->{$subfield}->{lib}=$lib;
305 $res->{$tag}->{$subfield}->{tab}=$tab;
310 sub MARCfind_marc_from_kohafield {
311 my ($dbh,$kohafield) = @_;
312 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
313 $sth->execute($kohafield);
314 my ($tagfield,$tagsubfield) = $sth->fetchrow;
315 return ($tagfield,$tagsubfield);
318 sub MARCfind_oldbiblionumber_from_MARCbibid {
319 my ($dbh,$MARCbibid) = @_;
320 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
321 $sth->execute($MARCbibid);
322 my ($biblionumber) = $sth->fetchrow;
323 return $biblionumber;
326 sub MARCfind_MARCbibid_from_oldbiblionumber {
327 my ($dbh,$oldbiblionumber) = @_;
328 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
329 $sth->execute($oldbiblionumber);
330 my ($bibid) = $sth->fetchrow;
335 # pass the MARC::Record to this function, and it will create the records in the marc tables
336 my ($dbh,$record,$biblionumber) = @_;
337 my @fields=$record->fields();
339 # adding main table, and retrieving bibid
340 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
341 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
342 $sth->execute($biblionumber);
343 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
345 ($bibid)=$sth->fetchrow;
348 # now, add subfields...
349 foreach my $field (@fields) {
350 my @subfields=$field->subfields();
352 foreach my $subfieldcount (0..$#subfields) {
353 &MARCaddsubfield($dbh,$bibid,
355 $field->indicator(1).$field->indicator(2),
357 $subfields[$subfieldcount][0],
359 $subfields[$subfieldcount][1]
363 $dbh->do("unlock tables");
368 # pass the MARC::Record to this function, and it will create the records in the marc tables
369 my ($dbh,$record,$biblionumber) = @_;
370 # search for MARC biblionumber
371 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
372 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
373 my @fields=$record->fields();
374 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
375 $sth->execute($bibid);
376 my ($fieldcount) = $sth->fetchrow;
377 # now, add subfields...
378 foreach my $field (@fields) {
379 my @subfields=$field->subfields();
381 foreach my $subfieldcount (0..$#subfields) {
382 &MARCaddsubfield($dbh,$bibid,
384 $field->indicator(1).$field->indicator(2),
386 $subfields[$subfieldcount][0],
388 $subfields[$subfieldcount][1]
392 $dbh->do("unlock tables");
396 sub MARCaddsubfield {
397 # Add a new subfield to a tag into the DB.
398 my ($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
399 # if not value, end of job, we do nothing
400 if (not($subfieldvalue)) {
403 if (not($subfieldcode)) {
406 if (length($subfieldvalue)>255) {
407 # $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
408 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
409 $sth->execute($subfieldvalue);
410 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
412 my ($res)=$sth->fetchrow;
413 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?)");
415 $sth->execute($bibid,'0'.$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
417 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
420 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
422 # $dbh->do("unlock tables");
424 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?)");
425 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
427 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
430 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
435 # Returns MARC::Record of the biblio passed in parameter.
437 my $record = MARC::Record->new();
438 #---- TODO : the leader is missing
439 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
440 from marc_subfield_table
441 where bibid=? order by tagorder,subfieldorder
443 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
444 $sth->execute($bibid);
448 while (my $row=$sth->fetchrow_hashref) {
449 if ($row->{'valuebloblink'}) { #---- search blob if there is one
450 $sth2->execute($row->{'valuebloblink'});
451 my $row2=$sth2->fetchrow_hashref;
453 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
455 if ($row->{tagorder} ne $prevtagorder) {
456 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
457 $record->add_fields($field);
458 $prevtagorder=$row->{tagorder};
459 $prevtag = $row->{tag};
461 %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
463 %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
464 $prevtag= $row->{tag};
467 # the last has not been included inside the loop... do it now !
468 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
469 $record->add_fields($field);
473 # Returns MARC::Record of the biblio passed in parameter.
474 my ($dbh,$bibid,$itemnumber)=@_;
475 warn "MARCgetitem : $bibid, $itemnumber\n";
476 my $record = MARC::Record->new();
477 # search MARC tagorder
478 my $sth2 = $dbh->prepare("select tagorder from marc_subfield_table,marc_subfield_structure where marc_subfield_table.tag=marc_subfield_structure.tagfield and marc_subfield_table.subfieldcode=marc_subfield_structure.tagsubfield and bibid=? and kohafield='items.itemnumber' and subfieldvalue=?");
479 $sth2->execute($bibid,$itemnumber);
480 my ($tagorder) = $sth2->fetchrow_array();
481 #---- TODO : the leader is missing
482 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
483 from marc_subfield_table
484 where bibid=? and tagorder=? order by subfieldorder
486 # FIXME - There's already a $sth2 in this scope.
487 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
488 $sth->execute($bibid,$tagorder);
489 while (my $row=$sth->fetchrow_hashref) {
490 if ($row->{'valuebloblink'}) { #---- search blob if there is one
491 $sth2->execute($row->{'valuebloblink'});
492 my $row2=$sth2->fetchrow_hashref;
494 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
496 if ($record->field($row->{'tag'})) {
498 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
499 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
500 if (length($row->{'tag'}) <3) {
501 $row->{'tag'} = "0".$row->{'tag'};
503 $field =$record->field($row->{'tag'});
505 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
506 $record->delete_field($field);
507 $record->add_fields($field);
510 if (length($row->{'tag'}) < 3) {
511 $row->{'tag'} = "0".$row->{'tag'};
513 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
514 $record->add_fields($temp);
522 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
523 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
524 # if nothing to change, don't waste time...
525 if ($oldrecord eq $record) {
528 # otherwise, skip through each subfield...
529 my @fields = $record->fields();
531 foreach my $field (@fields) {
532 my $oldfield = $oldrecord->field($field->tag());
533 my @subfields=$field->subfields();
536 foreach my $subfield (@subfields) {
538 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
539 # just adding datas...
540 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
541 1,@$subfield[0],$subfieldorder,@$subfield[1]);
543 # modify he subfield if it's a different string
544 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
545 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
546 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
554 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
555 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
556 # if nothing to change, don't waste time...
557 if ($oldrecord eq $record) {
560 # otherwise, skip through each subfield...
561 my @fields = $record->fields();
562 # search old MARC item
563 my $sth2 = $dbh->prepare("select tagorder from marc_subfield_table,marc_subfield_structure where marc_subfield_table.tag=marc_subfield_structure.tagfield and marc_subfield_table.subfieldcode=marc_subfield_structure.tagsubfield and bibid=? and kohafield='items.itemnumber' and subfieldvalue=?");
564 $sth2->execute($bibid,$itemnumber);
565 my ($tagorder) = $sth2->fetchrow_array();
566 foreach my $field (@fields) {
567 my $oldfield = $oldrecord->field($field->tag());
568 my @subfields=$field->subfields();
570 foreach my $subfield (@subfields) {
572 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
573 # just adding datas...
574 warn "ADD = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
575 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
576 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
578 # modify he subfield if it's a different string
579 warn "MODIFY = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
580 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
581 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
582 warn "MODIFY2 = $bibid, $subfieldid, ".@$subfield[1]."\n";
583 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
592 sub MARCmodsubfield {
593 # Subroutine changes a subfield value given a subfieldid.
594 my ($dbh, $subfieldid, $subfieldvalue )=@_;
595 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
596 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
597 $sth1->execute($subfieldid);
598 my ($oldvaluebloblink)=$sth1->fetchrow;
601 # if too long, use a bloblink
602 if (length($subfieldvalue)>255 ) {
603 # if already a bloblink, update it, otherwise, insert a new one.
604 if ($oldvaluebloblink) {
605 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
606 $sth->execute($subfieldvalue,$oldvaluebloblink);
608 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
609 $sth->execute($subfieldvalue);
610 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
612 my ($res)=$sth->fetchrow;
613 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
614 $sth->execute($subfieldid);
617 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
618 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
619 $sth->execute($subfieldvalue, $subfieldid);
621 $dbh->do("unlock tables");
623 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
624 $sth->execute($subfieldid);
625 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
627 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
628 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
629 return($subfieldid, $subfieldvalue);
632 sub MARCfindsubfield {
633 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
637 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
638 if ($subfieldvalue) {
639 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
641 if ($subfieldorder<1) {
644 $query .= " and subfieldorder=$subfieldorder";
646 my $sti=$dbh->prepare($query);
647 $sti->execute($bibid,$tag, $subfieldcode);
648 while (($subfieldid) = $sti->fetchrow) {
650 $lastsubfieldid=$subfieldid;
652 if ($resultcounter>1) {
653 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
654 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
657 return $lastsubfieldid;
661 sub MARCfindsubfieldid {
662 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
663 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
664 where bibid=? and tag=? and tagorder=?
665 and subfieldcode=? and subfieldorder=?");
666 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
667 my ($res) = $sth->fetchrow;
671 sub MARCdelsubfield {
672 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
673 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
674 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
675 tag='$tag' and tagorder='$tagorder'
676 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
681 # delete a biblio for a $bibid
682 my ($dbh,$bibid) = @_;
683 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
684 $dbh->do("delete from marc_biblio where bibid='$bibid'");
687 sub MARCkoha2marcBiblio {
688 # this function builds partial MARC::Record from the old koha-DB fields
689 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
690 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
691 my $record = MARC::Record->new();
692 #--- if bibid, then retrieve old-style koha data
693 if ($biblionumber>0) {
694 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
695 from biblio where biblionumber=?");
696 $sth2->execute($biblionumber);
697 my $row=$sth2->fetchrow_hashref;
699 foreach $code (keys %$row) {
701 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
705 #--- if biblioitem, then retrieve old-style koha data
706 if ($biblioitemnumber>0) {
707 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
708 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
709 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
711 WHERE biblionumber=? and biblioitemnumber=?
713 $sth2->execute($biblionumber,$biblioitemnumber);
714 my $row=$sth2->fetchrow_hashref;
716 foreach $code (keys %$row) {
718 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
723 # TODO : retrieve notes, additionalauthors
726 sub MARCkoha2marcItem {
727 # this function builds partial MARC::Record from the old koha-DB fields
728 my ($dbh,$biblionumber,$itemnumber) = @_;
729 # my $dbh=&C4Connect;
730 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
731 my $record = MARC::Record->new();
732 #--- if item, then retrieve old-style koha data
734 # print STDERR "prepare $biblionumber,$itemnumber\n";
735 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
736 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
737 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
738 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
740 WHERE itemnumber=?");
741 $sth2->execute($itemnumber);
742 my $row=$sth2->fetchrow_hashref;
744 foreach $code (keys %$row) {
746 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
751 # TODO : retrieve notes, additionalauthors
754 sub MARCkoha2marcSubtitle {
755 # this function builds partial MARC::Record from the old koha-DB fields
756 my ($dbh,$bibnum,$subtitle) = @_;
757 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
758 my $record = MARC::Record->new();
759 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
763 sub MARCkoha2marcOnefield {
764 my ($sth,$record,$kohafieldname,$value)=@_;
767 $sth->execute($kohafieldname);
768 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
769 if ($record->field($tagfield)) {
770 my $tag =$record->field($tagfield);
772 $tag->add_subfields($tagsubfield,$value);
773 $record->delete_field($tag);
774 $record->add_fields($tag);
777 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
784 my ($dbh,$record) = @_;
785 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
787 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
790 # print STDERR $record->as_formatted;
791 while (($field)=$sth2->fetchrow) {
792 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
794 # FIXME - There's already a $sth2 in this scope.
795 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
797 # FIXME - There's already a $field in this scope.
799 while (($field)=$sth2->fetchrow) {
800 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
802 # FIXME - There's already a $sth2 in this scope.
803 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
805 # FIXME - There's already a $field in this scope.
807 while (($field)=$sth2->fetchrow) {
808 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
810 # additional authors : specific
811 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
815 sub MARCmarc2kohaOneField {
816 # to check : if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
817 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
821 $sth->execute($kohatable.".".$kohafield);
822 ($tagfield,$subfield) = $sth->fetchrow;
823 foreach my $field ($record->field($tagfield)) {
824 if ($field->subfield($subfield)) {
825 if ($result->{$kohafield}) {
826 $result->{$kohafield} .= " | ".$field->subfield($subfield);
828 $result->{$kohafield}=$field->subfield($subfield);
836 # split a subfield string and adds it into the word table.
838 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
839 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
840 my @words = split / /,$sentence;
841 # build stopword list
842 # my $sth2 =$dbh->prepare("select word from stopwords");
846 # while(($stopword) = $sth2->fetchrow_array) {
847 # $stopwords->{$stopword} = $stopword;
849 my $stopwords= C4::Context->stopwords;
850 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
851 values (?,?,?,?,?,?,soundex(?))");
852 foreach my $word (@words) {
853 # we record only words longer than 2 car and not in stopwords hash
854 if (length($word)>1 and !($stopwords->{uc($word)})) {
855 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
857 print STDERR "ERROR ==> insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word) values ($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,soundex($word))\n";
864 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
865 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
866 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
867 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
872 # ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL
875 # all the following subs are useful to manage MARC-DB with complete MARC records.
876 # it's used with marcimport, and marc management tools
881 all subs requires/use $dbh as 1st parameter.
882 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
886 =head2 (oldbibnum,$oldbibitemnum) = ALLnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
887 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
888 are builded from the MARC::Record. If they are passed, they are used.
890 =head2 ALLnewitem($dbh,$olditem);
891 adds an item in the db. $olditem is a old-db hash.
895 Paul POULAIN paul.poulain@free.fr
900 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
901 # note $oldbiblio and $oldbiblioitem are not mandatory.
902 # if not present, they will be builded from $record with MARCmarc2koha function
903 if (($oldbiblio) and not($oldbiblioitem)) {
904 print STDERR "ALLnewbiblio : missing parameter\n";
905 print "ALLnewbiblio : missing parameter : contact koha development team\n";
911 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
912 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
913 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
915 my $olddata = MARCmarc2koha($dbh,$record);
916 $oldbibnum = OLDnewbiblio($dbh,$olddata);
917 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
919 # we must add bibnum and bibitemnum in MARC::Record...
920 # we build the new field with biblionumber and biblioitemnumber
921 # we drop the original field
922 # we add the new builded field.
923 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
924 # (steve and paul : thinks 090 is a good choice)
925 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
926 $sth->execute("biblio.biblionumber");
927 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
928 $sth->execute("biblioitems.biblioitemnumber");
929 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
930 print STDERR "tag1 : $tagfield1 / $tagsubfield1\n tag2 : $tagfield2 / $tagsubfield2\n";
931 if ($tagsubfield1 != $tagsubfield2) {
932 print STDERR "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
933 print "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
936 my $newfield = MARC::Field->new( $tagfield1,'','',
937 "$tagsubfield1" => $oldbibnum,
938 "$tagsubfield2" => $oldbibitemnum);
939 # drop old field and create new one...
940 my $old_field = $record->field($tagfield1);
941 $record->delete_field($old_field);
942 $record->add_fields($newfield);
943 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
944 return ( $oldbibnum,$oldbibitemnum );
948 my ($dbh, $item) = @_;
951 ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{'barcode'});
952 # search MARC biblionumber
953 my $bibid=&MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{'biblionumber'});
955 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
956 $sth->execute($bibid);
957 my ($tagorder) = $sth->fetchrow;
960 # for each field, find MARC tag and subfield, and call the proper MARC sub
961 foreach my $itemkey (keys %$item) {
964 print STDERR "=============> $itemkey : ".$item->{$itemkey}."\n";
965 if ($itemkey eq "biblionumber" || $itemkey eq "biblioitemnumber") {
966 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"biblio.".$itemkey);
968 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"items.".$itemkey);
970 if ($tagfield && $item->{$itemkey} ne 'NULL') {
972 &MARCaddsubfield($dbh,
988 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
994 all subs requires/use $dbh as 1st parameter.
995 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
997 They all are the exact copy of 1.0/1.2 version of the sub
998 without the OLD. The OLDxxx is called by the original xxx sub.
999 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
1001 WARNING : there is 1 difference between initialxxx and OLDxxx :
1002 the db header $dbh is always passed as parameter
1003 to avoid over-DB connexion
1007 =head2 $biblionumber = OLDnewbiblio($dbh,$biblio);
1008 adds a record in biblio table. Datas are in the hash $biblio.
1010 =head2 $biblionumber = OLDmodbiblio($dbh,$biblio);
1011 modify a record in biblio table. Datas are in the hash $biblio.
1013 =head2 OLDmodsubtitle($dbh,$bibnum,$subtitle);
1014 modify subtitles in bibliosubtitle table.
1016 =head2 OLDmodaddauthor($dbh,$bibnum,$author);
1017 adds or modify additional authors
1018 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1020 =head2 $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1021 modify/adds subjects
1023 =head2 OLDmodbibitem($dbh, $biblioitem);
1026 =head2 OLDmodnote($dbh,$bibitemnum,$note
1027 modify a note for a biblioitem
1029 =head2 OLDnewbiblioitem($dbh,$biblioitem);
1030 adds a biblioitem ($biblioitem is a hash with the values)
1032 =head2 OLDnewsubject($dbh,$bibnum);
1034 =head2 OLDnewsubtitle($dbh,$bibnum,$subtitle);
1035 create a new subtitle
1037 =head2 ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1038 create a item. $item is a hash and $barcode the barcode.
1040 =head2 OLDmoditem($dbh,$item);
1043 =head2 OLDdelitem($dbh,$itemnum);
1046 =head2 OLDdeletebiblioitem($dbh,$biblioitemnumber);
1047 deletes a biblioitem
1048 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1050 =head2 OLDdelbiblio($dbh,$biblio);
1055 Paul POULAIN paul.poulain@free.fr
1060 my ($dbh,$biblio) = @_;
1061 # my $dbh = &C4Connect;
1062 my $query = "Select max(biblionumber) from biblio";
1063 my $sth = $dbh->prepare($query);
1065 my $data = $sth->fetchrow_arrayref;
1066 my $bibnum = $$data[0] + 1;
1069 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1070 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1071 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
1072 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
1073 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1074 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1075 if ($biblio->{'seriestitle'}) { $series = 1 };
1078 $query = "insert into biblio set
1079 biblionumber = $bibnum,
1080 title = $biblio->{'title'},
1081 author = $biblio->{'author'},
1082 copyrightdate = $biblio->{'copyright'},
1084 seriestitle = $biblio->{'seriestitle'},
1085 notes = $biblio->{'notes'},
1086 abstract = $biblio->{'abstract'}";
1088 $sth = $dbh->prepare($query);
1097 my ($dbh,$biblio) = @_;
1098 # my $dbh = C4Connect;
1102 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1103 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1104 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1105 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
1106 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
1107 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
1108 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
1109 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1111 $query = "Update biblio set
1112 title = $biblio->{'title'},
1113 author = $biblio->{'author'},
1114 abstract = $biblio->{'abstract'},
1115 copyrightdate = $biblio->{'copyrightdate'},
1116 seriestitle = $biblio->{'seriestitle'},
1117 serial = $biblio->{'serial'},
1118 unititle = $biblio->{'unititle'},
1119 notes = $biblio->{'notes'}
1120 where biblionumber = $biblio->{'biblionumber'}";
1121 $sth = $dbh->prepare($query);
1126 return($biblio->{'biblionumber'});
1129 sub OLDmodsubtitle {
1130 my ($dbh,$bibnum, $subtitle) = @_;
1131 # my $dbh = C4Connect;
1132 my $query = "update bibliosubtitle set
1133 subtitle = '$subtitle'
1134 where biblionumber = $bibnum";
1135 my $sth = $dbh->prepare($query);
1143 sub OLDmodaddauthor {
1144 my ($dbh,$bibnum, $author) = @_;
1145 # my $dbh = C4Connect;
1146 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1147 my $sth = $dbh->prepare($query);
1152 if ($author ne '') {
1153 $query = "Insert into additionalauthors set
1155 biblionumber = '$bibnum'";
1156 $sth = $dbh->prepare($query);
1162 } # sub modaddauthor
1166 my ($dbh,$bibnum, $force, @subject) = @_;
1167 # my $dbh = C4Connect;
1168 my $count = @subject;
1170 for (my $i = 0; $i < $count; $i++) {
1171 $subject[$i] =~ s/^ //g;
1172 $subject[$i] =~ s/ $//g;
1173 my $query = "select * from catalogueentry
1174 where entrytype = 's'
1175 and catalogueentry = '$subject[$i]'";
1176 my $sth = $dbh->prepare($query);
1179 if (my $data = $sth->fetchrow_hashref) {
1181 if ($force eq $subject[$i]) {
1182 # subject not in aut, chosen to force anway
1183 # so insert into cataloguentry so its in auth file
1184 $query = "Insert into catalogueentry
1185 (entrytype,catalogueentry)
1186 values ('s','$subject[$i]')";
1187 my $sth2 = $dbh->prepare($query);
1192 $error = "$subject[$i]\n does not exist in the subject authority file";
1193 $query = "Select * from catalogueentry
1194 where entrytype = 's'
1195 and (catalogueentry like '$subject[$i] %'
1196 or catalogueentry like '% $subject[$i] %'
1197 or catalogueentry like '% $subject[$i]')";
1198 my $sth2 = $dbh->prepare($query);
1201 while (my $data = $sth2->fetchrow_hashref) {
1202 $error = $error."<br>$data->{'catalogueentry'}";
1210 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1211 my $sth = $dbh->prepare($query);
1214 for (my $i = 0; $i < $count; $i++) {
1215 $sth = $dbh->prepare("Insert into bibliosubject
1216 values ('$subject[$i]', $bibnum)");
1228 my ($dbh,$biblioitem) = @_;
1229 # my $dbh = C4Connect;
1232 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1233 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1234 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1235 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1236 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1237 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1238 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1239 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1240 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1241 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1242 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1243 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1244 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1245 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1247 $query = "Update biblioitems set
1248 itemtype = $biblioitem->{'itemtype'},
1249 url = $biblioitem->{'url'},
1250 isbn = $biblioitem->{'isbn'},
1251 publishercode = $biblioitem->{'publishercode'},
1252 publicationyear = $biblioitem->{'publicationyear'},
1253 classification = $biblioitem->{'classification'},
1254 dewey = $biblioitem->{'dewey'},
1255 subclass = $biblioitem->{'subclass'},
1256 illus = $biblioitem->{'illus'},
1257 pages = $biblioitem->{'pages'},
1258 volumeddesc = $biblioitem->{'volumeddesc'},
1259 notes = $biblioitem->{'notes'},
1260 size = $biblioitem->{'size'},
1261 place = $biblioitem->{'place'}
1262 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1270 my ($dbh,$bibitemnum,$note)=@_;
1271 # my $dbh=C4Connect;
1272 my $query="update biblioitems set notes='$note' where
1273 biblioitemnumber='$bibitemnum'";
1274 my $sth=$dbh->prepare($query);
1280 sub OLDnewbiblioitem {
1281 my ($dbh,$biblioitem) = @_;
1282 # my $dbh = C4Connect;
1283 my $query = "Select max(biblioitemnumber) from biblioitems";
1284 my $sth = $dbh->prepare($query);
1288 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
1289 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
1290 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1291 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1292 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1293 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1294 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
1295 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1296 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1297 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1298 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1299 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
1300 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1301 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1302 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1303 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1304 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1305 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1306 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
1307 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
1310 $data = $sth->fetchrow_arrayref;
1311 $bibitemnum = $$data[0] + 1;
1315 $query = "insert into biblioitems set
1316 biblioitemnumber = $bibitemnum,
1317 biblionumber = $biblioitem->{'biblionumber'},
1318 volume = $biblioitem->{'volume'},
1319 number = $biblioitem->{'number'},
1320 classification = $biblioitem->{'classification'},
1321 itemtype = $biblioitem->{'itemtype'},
1322 url = $biblioitem->{'url'},
1323 isbn = $biblioitem->{'isbn'},
1324 issn = $biblioitem->{'issn'},
1325 dewey = $biblioitem->{'dewey'},
1326 subclass = $biblioitem->{'subclass'},
1327 publicationyear = $biblioitem->{'publicationyear'},
1328 publishercode = $biblioitem->{'publishercode'},
1329 volumedate = $biblioitem->{'volumedate'},
1330 volumeddesc = $biblioitem->{'volumeddesc'},
1331 illus = $biblioitem->{'illus'},
1332 pages = $biblioitem->{'pages'},
1333 notes = $biblioitem->{'notes'},
1334 size = $biblioitem->{'size'},
1335 lccn = $biblioitem->{'lccn'},
1336 marc = $biblioitem->{'marc'},
1337 place = $biblioitem->{'place'}";
1339 $sth = $dbh->prepare($query);
1343 return($bibitemnum);
1347 my ($dbh,$bibnum)=@_;
1348 # my $dbh=C4Connect;
1349 my $query="insert into bibliosubject (biblionumber) values
1351 my $sth=$dbh->prepare($query);
1358 sub OLDnewsubtitle {
1359 my ($dbh,$bibnum, $subtitle) = @_;
1360 # my $dbh = C4Connect;
1361 $subtitle = $dbh->quote($subtitle);
1362 my $query = "insert into bibliosubtitle set
1363 biblionumber = $bibnum,
1364 subtitle = $subtitle";
1365 my $sth = $dbh->prepare($query);
1375 my ($dbh,$item, $barcode) = @_;
1376 # my $dbh = C4Connect;
1377 my $query = "Select max(itemnumber) from items";
1378 my $sth = $dbh->prepare($query);
1384 $data = $sth->fetchrow_hashref;
1385 $itemnumber = $data->{'max(itemnumber)'} + 1;
1388 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
1389 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
1390 $item->{'price'} = $dbh->quote($item->{'price'});
1391 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
1392 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
1394 # foreach my $barcode (@barcodes) {
1395 # $barcode = uc($barcode);
1396 $barcode = $dbh->quote($barcode);
1397 $query = "Insert into items set
1398 itemnumber = $itemnumber,
1399 biblionumber = $item->{'biblionumber'},
1400 biblioitemnumber = $item->{'biblioitemnumber'},
1402 booksellerid = $item->{'booksellerid'},
1403 dateaccessioned = NOW(),
1404 homebranch = $item->{'homebranch'},
1405 holdingbranch = $item->{'homebranch'},
1406 price = $item->{'price'},
1407 replacementprice = $item->{'replacementprice'},
1408 replacementpricedate = NOW(),
1409 itemnotes = $item->{'itemnotes'}";
1410 if ($item->{'loan'}) {
1411 $query .= ",notforloan = $item->{'loan'}";
1414 $sth = $dbh->prepare($query);
1416 if (defined $sth->errstr) {
1417 $error .= $sth->errstr;
1422 return($itemnumber,$error);
1426 my ($dbh,$item) = @_;
1427 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1428 # my $dbh=C4Connect;
1429 my $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1430 barcode='$item->{'barcode'}',itemnotes='$item->{'notes'}'
1431 where itemnumber=$item->{'itemnum'}";
1432 if ($item->{'barcode'} eq ''){
1433 $query="update items set biblioitemnumber=$item->{'bibitemnum'},notforloan=$item->{'loan'} where itemnumber=$item->{'itemnum'}";
1435 if ($item->{'lost'} ne ''){
1436 $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1437 barcode='$item->{'barcode'}',
1438 itemnotes='$item->{'notes'}',
1439 homebranch='$item->{'homebranch'}',
1440 itemlost='$item->{'lost'}',
1441 wthdrawn='$item->{'wthdrawn'}'
1442 where itemnumber=$item->{'itemnum'}";
1444 if ($item->{'replacement'} ne ''){
1445 $query=~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1448 my $sth=$dbh->prepare($query);
1454 # FIXME - A nearly-identical function, &delitem, appears in
1457 my ($dbh,$itemnum)=@_;
1458 # my $dbh=C4Connect;
1459 my $query="select * from items where itemnumber=$itemnum";
1460 my $sth=$dbh->prepare($query);
1462 my @data=$sth->fetchrow_array;
1464 $query="Insert into deleteditems values (";
1465 foreach my $temp (@data){
1466 $query=$query."'$temp',";
1470 $sth=$dbh->prepare($query);
1473 $query = "Delete from items where itemnumber=$itemnum";
1474 $sth=$dbh->prepare($query);
1480 sub OLDdeletebiblioitem {
1481 my ($dbh,$biblioitemnumber) = @_;
1482 # my $dbh = C4Connect;
1483 my $query = "Select * from biblioitems
1484 where biblioitemnumber = $biblioitemnumber";
1485 my $sth = $dbh->prepare($query);
1490 if (@results = $sth->fetchrow_array) {
1491 $query = "Insert into deletedbiblioitems values (";
1492 foreach my $value (@results) {
1493 $value = $dbh->quote($value);
1494 $query .= "$value,";
1497 $query =~ s/\,$/\)/;
1500 $query = "Delete from biblioitems
1501 where biblioitemnumber = $biblioitemnumber";
1505 # Now delete all the items attached to the biblioitem
1506 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1507 $sth = $dbh->prepare($query);
1509 while (@results = $sth->fetchrow_array) {
1510 $query = "Insert into deleteditems values (";
1511 foreach my $value (@results) {
1512 $value = $dbh->quote($value);
1513 $query .= "$value,";
1515 $query =~ s/\,$/\)/;
1519 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1522 } # sub deletebiblioitem
1525 my ($dbh,$biblio)=@_;
1526 # my $dbh=C4Connect;
1527 my $query="select * from biblio where biblionumber=$biblio";
1528 my $sth=$dbh->prepare($query);
1530 if (my @data=$sth->fetchrow_array){
1532 $query="Insert into deletedbiblio values (";
1533 foreach my $temp (@data){
1534 $temp=~ s/\'/\\\'/g;
1535 $query=$query."'$temp',";
1539 $sth=$dbh->prepare($query);
1542 $query = "Delete from biblio where biblionumber=$biblio";
1543 $sth=$dbh->prepare($query);
1557 # FIXME - This is the same as &C4::Acquisitions::itemcount, but not
1558 # the same as &C4::Search::itemcount
1559 # Since they're both exported, acqui/acquire.pl doesn't compile with -w.
1562 my $dbh = C4::Context->dbh;
1563 my $query="Select count(*) from items where biblionumber=$biblio";
1565 my $sth=$dbh->prepare($query);
1567 my $data=$sth->fetchrow_hashref;
1569 return($data->{'count(*)'});
1574 my $dbh = C4::Context->dbh;
1575 my $query="Select ordernumber
1577 where biblionumber=? and biblioitemnumber=?";
1578 my $sth=$dbh->prepare($query);
1579 $sth->execute($bib,$bi);
1580 my $ordnum=$sth->fetchrow_hashref;
1582 my $order=getsingleorder($ordnum->{'ordernumber'});
1584 return ($order,$ordnum->{'ordernumber'});
1587 # FIXME - This is practically the same function as
1588 # &C4::Acquisitions::getsingleorder and &C4::Catalogue::getsingleorder
1589 sub getsingleorder {
1591 my $dbh = C4::Context->dbh;
1592 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1593 where aqorders.ordernumber=?
1594 and biblio.biblionumber=aqorders.biblionumber and
1595 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1596 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1597 my $sth=$dbh->prepare($query);
1598 $sth->execute($ordnum);
1599 my $data=$sth->fetchrow_hashref;
1604 # FIXME - This is in effect identical to &C4::Acquisitions::newbiblio.
1605 # Pick one and stick with it.
1608 my $dbh = C4::Context->dbh;
1609 my $bibnum=OLDnewbiblio($dbh,$biblio);
1614 # FIXME - This is in effect the same as &C4::Acquisitions::modbiblio.
1615 # Pick one and stick with it.
1618 my $dbh = C4::Context->dbh;
1619 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1620 return($biblionumber);
1623 # FIXME - This is in effect identical to &C4::Acquisitions::modsubtitle.
1624 # Pick one and stick with it.
1626 my ($bibnum, $subtitle) = @_;
1627 my $dbh = C4::Context->dbh;
1628 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1632 # FIXME - This is functionally identical to
1633 # &C4::Acquisitions::modaddauthor
1634 # Pick one and stick with it.
1636 my ($bibnum, $author) = @_;
1637 my $dbh = C4::Context->dbh;
1638 &OLDmodaddauthor($dbh,$bibnum,$author);
1639 } # sub modaddauthor
1642 # FIXME - This is in effect identical to &C4::Acquisitions::modsubject.
1643 # Pick one and stick with it.
1645 my ($bibnum, $force, @subject) = @_;
1646 my $dbh = C4::Context->dbh;
1647 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1651 # FIXME - This is very similar to &C4::Acquisitions::modbibitem.
1652 # Pick one and stick with it.
1654 my ($biblioitem) = @_;
1655 my $dbh = C4::Context->dbh;
1656 &OLDmodbibitem($dbh,$biblioitem);
1657 my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
1658 &MARCmodbiblio($dbh,$biblioitem->{biblionumber},0,$MARCbibitem);
1661 # FIXME - This is in effect identical to &C4::Acquisitions::modnote.
1662 # Pick one and stick with it.
1664 my ($bibitemnum,$note)=@_;
1665 my $dbh = C4::Context->dbh;
1666 &OLDmodnote($dbh,$bibitemnum,$note);
1669 # FIXME - This is quite similar in effect to &C4::newbiblioitem,
1670 # except for the MARC stuff. There's also a &newbiblioitem in
1671 # acqui.simple/addbookslccn.pl
1673 my ($biblioitem) = @_;
1674 my $dbh = C4::Context->dbh;
1675 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1676 # print STDERR "bibitemnum : $bibitemnum\n";
1677 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1678 # print STDERR $MARCbiblio->as_formatted();
1679 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1680 return($bibitemnum);
1683 # FIXME - This is in effect identical to &C4::Acquisitions::newsubject.
1684 # Pick one and stick with it.
1687 my $dbh = C4::Context->dbh;
1688 &OLDnewsubject($dbh,$bibnum);
1691 # FIXME - This is just a wrapper around &OLDnewsubtitle
1692 # FIXME - This is in effect the same as &C4::Acquisitions::newsubtitle
1694 my ($bibnum, $subtitle) = @_;
1695 my $dbh = C4::Context->dbh;
1696 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1699 # FIXME - This is different from &C4::Acquisitions::newitems, though
1700 # both are exported.
1702 my ($item, @barcodes) = @_;
1703 my $dbh = C4::Context->dbh;
1707 foreach my $barcode (@barcodes) {
1708 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1710 # print STDERR "biblionumber : $item->{biblionumber} / MARCbibid : $MARCbibid / itemnumber : $itemnumber\n";
1711 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1712 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1713 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1714 # print STDERR "MARCmodbiblio called\n";
1719 # FIXME - This appears to be functionally equivalent to
1720 # &C4::Acquisitions::moditem.
1721 # Pick one and stick with it.
1724 # my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1725 my $dbh = C4::Context->dbh;
1726 &OLDmoditem($dbh,$item);
1727 warn "biblionumber : $item->{'biblionumber'} / $item->{'itemnum'}\n";
1728 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1729 warn "before MARCmoditem : $item->{biblionumber}, $item->{'itemnum'}\n";
1730 warn $MARCitem->as_formatted();
1731 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1732 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1733 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1736 # FIXME - This is the same as &C4::Acquisitions::Checkitems.
1737 # Pick one and stick with it.
1739 my ($count,@barcodes)=@_;
1740 my $dbh = C4::Context->dbh;
1742 for (my $i=0;$i<$count;$i++){
1743 $barcodes[$i]=uc $barcodes[$i];
1744 my $query="Select * from items where barcode='$barcodes[$i]'";
1745 my $sth=$dbh->prepare($query);
1747 if (my $data=$sth->fetchrow_hashref){
1748 $error.=" Duplicate Barcode: $barcodes[$i]";
1755 # FIXME - This is identical to &C4::Acquisitions::countitems.
1756 # Pick one and stick with it.
1758 my ($bibitemnum)=@_;
1759 my $dbh = C4::Context->dbh;
1760 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1761 my $sth=$dbh->prepare($query);
1763 my $data=$sth->fetchrow_hashref;
1765 return($data->{'count(*)'});
1768 # FIXME - This is just a wrapper around &OLDdelitem, and acts
1769 # identically to &C4::Acquisitions::delitem
1770 # Pick one and stick with it.
1773 my $dbh = C4::Context->dbh;
1774 &OLDdelitem($dbh,$itemnum);
1777 # FIXME - This is functionally identical to
1778 # &C4::Acquisitions::deletebiblioitem.
1779 # Pick one and stick with it.
1780 sub deletebiblioitem {
1781 my ($biblioitemnumber) = @_;
1782 my $dbh = C4::Context->dbh;
1783 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1784 } # sub deletebiblioitem
1787 # FIXME - This is functionally identical to &C4::Acquisitions::delbiblio.
1788 # Pick one and stick with it.
1791 my $dbh = C4::Context->dbh;
1792 &OLDdelbiblio($dbh,$biblio);
1795 # FIXME - This is identical to &C4::Acquisitions::getitemtypes.
1796 # Pick one and stick with it.
1798 my $dbh = C4::Context->dbh;
1799 my $query = "select * from itemtypes";
1800 my $sth = $dbh->prepare($query);
1801 # || die "Cannot prepare $query" . $dbh->errstr;
1806 # || die "Cannot execute $query\n" . $sth->errstr;
1807 while (my $data = $sth->fetchrow_hashref) {
1808 $results[$count] = $data;
1813 return($count, @results);
1814 } # sub getitemtypes
1817 my ($biblionumber) = @_;
1818 my $dbh = C4::Context->dbh;
1819 my $query = "Select * from biblio where biblionumber = $biblionumber";
1820 my $sth = $dbh->prepare($query);
1821 # || die "Cannot prepare $query\n" . $dbh->errstr;
1826 # || die "Cannot execute $query\n" . $sth->errstr;
1827 while (my $data = $sth->fetchrow_hashref) {
1828 $results[$count] = $data;
1833 return($count, @results);
1836 # FIXME - This is identical to &C4::Acquisitions::getbiblioitem.
1837 # Pick one and stick with it.
1839 my ($biblioitemnum) = @_;
1840 my $dbh = C4::Context->dbh;
1841 my $query = "Select * from biblioitems where
1842 biblioitemnumber = $biblioitemnum";
1843 my $sth = $dbh->prepare($query);
1849 while (my $data = $sth->fetchrow_hashref) {
1850 $results[$count] = $data;
1855 return($count, @results);
1856 } # sub getbiblioitem
1858 # FIXME - This is identical to
1859 # &C4::Acquisitions::getbiblioitembybiblionumber.
1860 # Pick one and stick with it.
1861 sub getbiblioitembybiblionumber {
1862 my ($biblionumber) = @_;
1863 my $dbh = C4::Context->dbh;
1864 my $query = "Select * from biblioitems where biblionumber =
1866 my $sth = $dbh->prepare($query);
1872 while (my $data = $sth->fetchrow_hashref) {
1873 $results[$count] = $data;
1878 return($count, @results);
1881 # FIXME - This is identical to
1882 # &C4::Acquisitions::getbiblioitembybiblionumber.
1883 # Pick one and stick with it.
1884 sub getitemsbybiblioitem {
1885 my ($biblioitemnum) = @_;
1886 my $dbh = C4::Context->dbh;
1887 my $query = "Select * from items, biblio where
1888 biblio.biblionumber = items.biblionumber and biblioitemnumber
1890 my $sth = $dbh->prepare($query);
1891 # || die "Cannot prepare $query\n" . $dbh->errstr;
1896 # || die "Cannot execute $query\n" . $sth->errstr;
1897 while (my $data = $sth->fetchrow_hashref) {
1898 $results[$count] = $data;
1903 return($count, @results);
1904 } # sub getitemsbybiblioitem
1906 # FIXME - This is identical to &C4::Acquisitions::isbnsearch.
1907 # Pick one and stick with it.
1910 my $dbh = C4::Context->dbh;
1916 $isbn = $dbh->quote($isbn);
1917 $query = "Select biblio.* from biblio, biblioitems where
1918 biblio.biblionumber = biblioitems.biblionumber
1920 $sth = $dbh->prepare($query);
1923 while (my $data = $sth->fetchrow_hashref) {
1924 $results[$count] = $data;
1929 return($count, @results);
1933 # At the moment this is just a straight copy of the subject code. Needs heavy
1934 # modification to work for additional authors, obviously.
1935 # Check for additional author changes
1937 # my $newadditionalauthor='';
1938 # my $additionalauthors;
1939 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
1940 # $additionalauthors->{$newadditionalauthor}=1;
1941 # if ($origadditionalauthors->{$newadditionalauthor}) {
1942 # $additionalauthors->{$newadditionalauthor}=2;
1944 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
1945 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
1947 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
1949 # $subfields->{1}->{'Subfield_Mark'}='a';
1950 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
1953 # foreach $Record_ID (@marcrecords) {
1954 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1955 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
1959 # my $origadditionalauthor;
1960 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
1961 # if ($additionalauthors->{$origadditionalauthor} == 1) {
1962 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
1963 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
1964 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
1974 # Subroutine to log changes to databases
1975 # Eventually, this subroutine will be used to create a log of all changes made,
1976 # with the possibility of "undo"ing some changes
1978 if ($database eq 'kohadb') {
1984 print STDERR "KOHA: $type $section $item $original $new\n";
1985 } elsif ($database eq 'marc') {
1987 my $Record_ID=shift;
1990 my $subfield_ID=shift;
1993 print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
1997 #------------------------------------------------
2000 #---------------------------------------
2001 # Find a biblio entry, or create a new one if it doesn't exist.
2002 # If a "subtitle" entry is in hash, add it to subtitle table
2003 sub getoraddbiblio {
2007 $biblio, # hash ref to fields
2018 requireDBI($dbh,"getoraddbiblio");
2020 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2021 $sth=$dbh->prepare("select biblionumber
2023 where title=? and author=?
2024 and copyrightdate=? and seriestitle=?");
2026 $biblio->{title}, $biblio->{author},
2027 $biblio->{copyright}, $biblio->{seriestitle} );
2029 ($biblionumber) = $sth->fetchrow;
2030 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2032 # Doesn't exist. Add new one.
2033 print "<PRE>Adding biblio</PRE>\n" if $debug;
2034 ($biblionumber,$error)=&newbiblio($biblio);
2035 if ( $biblionumber ) {
2036 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
2037 if ( $biblio->{subtitle} ) {
2038 &newsubtitle($biblionumber,$biblio->{subtitle} );
2041 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2045 return $biblionumber,$error;
2047 } # sub getoraddbiblio
2051 # UNUSEFUL SUBs. Could be deleted, kept only until beta test
2052 # maybe useful for some MARC tricks steve used.
2055 sub OLD_MAYBE_DELETED_newBiblioItem {
2056 my ($env, $biblioitem) = @_;
2057 my $dbh = C4::Context->dbh;
2058 my $biblionumber=$biblioitem->{'biblionumber'};
2059 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2060 my $volume=$biblioitem->{'volume'};
2061 my $q_volume=$dbh->quote($volume);
2062 my $number=$biblioitem->{'number'};
2063 my $q_number=$dbh->quote($number);
2064 my $classification=$biblioitem->{'classification'};
2065 my $q_classification=$dbh->quote($classification);
2066 my $itemtype=$biblioitem->{'itemtype'};
2067 my $q_itemtype=$dbh->quote($itemtype);
2068 my $isbn=$biblioitem->{'isbn'};
2069 my $q_isbn=$dbh->quote($isbn);
2070 my $issn=$biblioitem->{'issn'};
2071 my $q_issn=$dbh->quote($issn);
2072 my $dewey=$biblioitem->{'dewey'};
2074 ($dewey == 0) && ($dewey='');
2075 my $subclass=$biblioitem->{'subclass'};
2076 my $q_subclass=$dbh->quote($subclass);
2077 my $publicationyear=$biblioitem->{'publicationyear'};
2078 my $publishercode=$biblioitem->{'publishercode'};
2079 my $q_publishercode=$dbh->quote($publishercode);
2080 my $volumedate=$biblioitem->{'volumedate'};
2081 my $q_volumedate=$dbh->quote($volumedate);
2082 my $illus=$biblioitem->{'illus'};
2083 my $q_illus=$dbh->quote($illus);
2084 my $pages=$biblioitem->{'pages'};
2085 my $q_pages=$dbh->quote($pages);
2086 my $notes=$biblioitem->{'notes'};
2087 my $q_notes=$dbh->quote($notes);
2088 my $size=$biblioitem->{'size'};
2089 my $q_size=$dbh->quote($size);
2090 my $place=$biblioitem->{'place'};
2091 my $q_place=$dbh->quote($place);
2092 my $lccn=$biblioitem->{'lccn'};
2093 my $q_lccn=$dbh->quote($lccn);
2096 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
2099 unless ($env->{'marconly'}) {
2100 #my $sth=$dbh->prepare("lock tables biblioitems write");
2102 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
2104 my ($biblioitemnumber) =$sth->fetchrow;
2105 $biblioitemnumber++;
2106 $sth=$dbh->prepare("insert into biblioitems (biblionumber,biblioitemnumber,volume,number,classification,itemtype,isbn,issn,dewey,subclass,publicationyear,publishercode,volumedate,illus,pages,notes,size,place,lccn) values ($biblionumber, $biblioitemnumber, $q_volume, $q_number, $q_classification, $q_itemtype, $q_isbn, $q_issn, $dewey, $q_subclass, $publicationyear, $q_publishercode, $q_volumedate, $q_illus, $q_pages,$q_notes, $q_size, $q_place, $q_lccn)");
2108 #my $sth=$dbh->prepare("unlock tables");
2113 # Should we check if there is already a biblioitem/amrc with the
2114 # same isbn/lccn/issn?
2116 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
2118 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
2119 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2121 my ($subtitle) = $sth->fetchrow;
2122 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2124 my @additionalauthors;
2125 while (my ($additionalauthor) = $sth->fetchrow) {
2126 push (@additionalauthors, $additionalauthor);
2128 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2131 while (my ($subject) = $sth->fetchrow) {
2132 push (@subjects, $subject);
2137 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
2139 my $Resource_ID=$dbh->{'mysql_insertid'};
2140 my $Record_ID=$Resource_ID;
2141 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
2147 $subfields->{1}->{'Subfield_Mark'}='a';
2148 $subfields->{1}->{'Subfield_Value'}=$title;
2150 $subfields->{2}->{'Subfield_Mark'}='b';
2151 $subfields->{2}->{'Subfield_Value'}=$subtitle;
2154 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2160 $subfields->{1}->{'Subfield_Mark'}='a';
2161 $subfields->{1}->{'Subfield_Value'}=$author;
2163 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2168 $subfields->{1}->{'Subfield_Mark'}='a';
2169 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
2171 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2176 $subfields->{1}->{'Subfield_Mark'}='a';
2177 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
2178 $subfields->{2}->{'Subfield_Mark'}='3';
2179 $subfields->{2}->{'Subfield_Value'}='biblio';
2181 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2183 # Additional Authors
2184 foreach (@additionalauthors) {
2186 (next) unless ($author);
2188 $subfields->{1}->{'Subfield_Mark'}='a';
2189 $subfields->{1}->{'Subfield_Value'}=$author;
2190 $subfields->{2}->{'Subfield_Mark'}='e';
2191 $subfields->{2}->{'Subfield_Value'}='author';
2193 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2197 (next) unless ($illus);
2199 $subfields->{1}->{'Subfield_Mark'}='a';
2200 $subfields->{1}->{'Subfield_Value'}=$illus;
2201 $subfields->{2}->{'Subfield_Mark'}='e';
2202 $subfields->{2}->{'Subfield_Value'}='illustrator';
2204 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2207 foreach (@subjects) {
2209 (next) unless ($subject);
2211 $subfields->{1}->{'Subfield_Mark'}='a';
2212 $subfields->{1}->{'Subfield_Value'}=$subject;
2214 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2221 $subfields->{1}->{'Subfield_Mark'}='a';
2222 $subfields->{1}->{'Subfield_Value'}=$isbn;
2224 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2229 $subfields->{1}->{'Subfield_Mark'}='a';
2230 $subfields->{1}->{'Subfield_Value'}=$lccn;
2232 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2237 $subfields->{1}->{'Subfield_Mark'}='a';
2238 $subfields->{1}->{'Subfield_Value'}=$issn;
2240 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2245 $subfields->{1}->{'Subfield_Mark'}='a';
2246 $subfields->{1}->{'Subfield_Value'}=$dewey;
2248 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2250 # DEWEY subclass and itemtype
2253 $subfields->{1}->{'Subfield_Mark'}='a';
2254 $subfields->{1}->{'Subfield_Value'}=$itemtype;
2255 $subfields->{2}->{'Subfield_Mark'}='b';
2256 $subfields->{2}->{'Subfield_Value'}=$subclass;
2257 $subfields->{3}->{'Subfield_Mark'}='c';
2258 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
2259 $subfields->{4}->{'Subfield_Mark'}='d';
2260 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
2262 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2267 $subfields->{1}->{'Subfield_Mark'}='a';
2268 $subfields->{1}->{'Subfield_Value'}=$place;
2269 $subfields->{2}->{'Subfield_Mark'}='b';
2270 $subfields->{2}->{'Subfield_Value'}=$publishercode;
2271 $subfields->{3}->{'Subfield_Mark'}='c';
2272 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
2273 if ($copyrightdate) {
2274 $subfields->{4}->{'Subfield_Mark'}='c';
2275 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
2278 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2281 if ($pages || $size) {
2283 $subfields->{1}->{'Subfield_Mark'}='a';
2284 $subfields->{1}->{'Subfield_Value'}=$pages;
2285 $subfields->{2}->{'Subfield_Mark'}='c';
2286 $subfields->{2}->{'Subfield_Value'}=$size;
2288 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2291 if ($volume || $number) {
2293 $subfields->{1}->{'Subfield_Mark'}='v';
2294 $subfields->{1}->{'Subfield_Value'}=$volume;
2295 $subfields->{2}->{'Subfield_Mark'}='n';
2296 $subfields->{2}->{'Subfield_Value'}=$number;
2298 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2303 $subfields->{1}->{'Subfield_Mark'}='a';
2304 $subfields->{1}->{'Subfield_Value'}=$notes;
2305 $subfields->{2}->{'Subfield_Mark'}='3';
2306 $subfields->{2}->{'Subfield_Value'}='biblioitem';
2308 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2311 return ($env, $Record_ID);
2314 sub OLD_MAYBE_DELETED_newItem {
2315 my ($env, $Record_ID, $item) = @_;
2316 my $dbh = C4::Context->dbh;
2317 my $barcode=$item->{'barcode'};
2318 my $q_barcode=$dbh->quote($barcode);
2319 my $biblionumber=$item->{'biblionumber'};
2320 my $biblioitemnumber=$item->{'biblioitemnumber'};
2321 my $dateaccessioned=$item->{'dateaccessioned'};
2322 my $booksellerid=$item->{'booksellerid'};
2323 my $q_booksellerid=$dbh->quote($booksellerid);
2324 my $homebranch=$item->{'homebranch'};
2325 my $q_homebranch=$dbh->quote($homebranch);
2326 my $holdingbranch=$item->{'holdingbranch'};
2327 my $price=$item->{'price'};
2328 my $replacementprice=$item->{'replacementprice'};
2329 my $replacementpricedate=$item->{'replacementpricedate'};
2330 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
2331 my $notforloan=$item->{'notforloan'};
2332 my $itemlost=$item->{'itemlost'};
2333 my $wthdrawn=$item->{'wthdrawn'};
2334 my $restricted=$item->{'restricted'};
2335 my $itemnotes=$item->{'itemnotes'};
2336 my $q_itemnotes=$dbh->quote($itemnotes);
2337 my $itemtype=$item->{'itemtype'};
2338 my $subclass=$item->{'subclass'};
2342 unless ($env->{'marconly'}) {
2343 my $sth=$dbh->prepare("select max(itemnumber) from items");
2345 my ($itemnumber) =$sth->fetchrow;
2347 $sth=$dbh->prepare("insert into items (itemnumber,biblionumber,biblioitemnumber,barcode,dateaccessioned,booksellerid,homebranch,price,replacementprice,replacementpricedate,notforloan,itemlost,wthdrawn,restricted,itemnotes) values ($itemnumber,$biblionumber,$biblioitemnumber,$q_barcode,$dateaccessioned,$q_booksellerid,$q_homebranch,$price,$q_replacementpricedate,$notforloan,$itemlost,$wthdrawn,$restricted,$q_itemnotes)");
2354 $subfields->{1}->{'Subfield_Mark'}='p';
2355 $subfields->{1}->{'Subfield_Value'}=$barcode;
2356 $subfields->{2}->{'Subfield_Mark'}='d';
2357 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
2358 $subfields->{3}->{'Subfield_Mark'}='e';
2359 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
2360 $subfields->{4}->{'Subfield_Mark'}='b';
2361 $subfields->{4}->{'Subfield_Value'}=$homebranch;
2362 $subfields->{5}->{'Subfield_Mark'}='l';
2363 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
2364 $subfields->{6}->{'Subfield_Mark'}='c';
2365 $subfields->{6}->{'Subfield_Value'}=$price;
2366 $subfields->{7}->{'Subfield_Mark'}='c';
2367 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
2368 $subfields->{8}->{'Subfield_Mark'}='d';
2369 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
2371 $subfields->{9}->{'Subfield_Mark'}='h';
2372 $subfields->{9}->{'Subfield_Value'}='Not for loan';
2375 $subfields->{10}->{'Subfield_Mark'}='j';
2376 $subfields->{10}->{'Subfield_Value'}='Item lost';
2379 $subfields->{11}->{'Subfield_Mark'}='j';
2380 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
2383 $subfields->{12}->{'Subfield_Mark'}='z';
2384 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
2388 $env->{'linkage'}=1;
2389 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2390 $env->{'linkage'}=0;
2391 $env->{'linkid'}=$Tag_ID;
2394 $subfields2->{1}->{'Subfield_Mark'}='a';
2395 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
2396 $subfields2->{1}->{'Subfield_Mark'}='b';
2397 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
2398 $subfields2->{1}->{'Subfield_Mark'}='c';
2399 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
2400 $subfields2->{2}->{'Subfield_Mark'}='m';
2401 $subfields2->{2}->{'Subfield_Value'}=$subclass;
2402 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
2403 $env->{'linkid'}='';
2406 sub OLD_MAYBE_DELETED_updateBiblio {
2407 # Update the biblio with biblionumber $biblio->{'biblionumber'}
2408 # I guess this routine should search through all marc records for a record that
2409 # has the same biblionumber stored in it, and modify the MARC record as well as
2412 # Also, this subroutine should search through the $biblio object and compare it
2413 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
2414 # this logging feature to be usable to undo changes easily.
2416 my ($env, $biblio) = @_;
2418 my $biblionumber=$biblio->{'biblionumber'};
2419 my $dbh = C4::Context->dbh;
2420 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
2422 my $origbiblio=$sth->fetchrow_hashref;
2423 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2425 my ($subtitle)=$sth->fetchrow;
2426 $origbiblio->{'subtitle'}=$subtitle;
2427 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2429 my $origadditionalauthors;
2430 while (my ($author) = $sth->fetchrow) {
2431 push (@{$origbiblio->{'additionalauthors'}}, $author);
2432 $origadditionalauthors->{$author}=1;
2434 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2437 while (my ($subject) = $sth->fetchrow) {
2438 push (@{$origbiblio->{'subjects'}}, $subject);
2439 $origsubjects->{$subject}=1;
2443 # Obtain a list of MARC Record_ID's that are tied to this biblio
2444 $sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
2447 while (my ($bibid) = $sth->fetchrow) {
2448 push(@marcrecords, $bibid);
2452 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
2453 my $q_author=$dbh->quote($biblio->{'author'});
2454 logchange('kohadb', 'change', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
2455 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
2457 foreach $bibid (@marcrecords) {
2458 logchange('marc', 'change', $bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2459 changeSubfield($bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2462 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
2463 my $q_title=$dbh->quote($biblio->{'title'});
2464 logchange('kohadb', 'change', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
2465 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
2467 foreach $Record_ID (@marcrecords) {
2468 logchange('marc', 'change', $Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2469 changeSubfield($Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2472 if ($biblio->{'subtitle'} ne $origbiblio->{'subtitle'}) {
2473 my $q_subtitle=$dbh->quote($biblio->{'subtitle'});
2474 logchange('kohadb', 'change', 'biblio', 'subtitle', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2475 my $sti=$dbh->prepare("update bibliosubtitle set subtitle=$q_subtitle where biblionumber=$biblio->{'biblionumber'}");
2477 foreach $Record_ID (@marcrecords) {
2478 logchange('marc', 'change', $Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2479 changeSubfield($Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2482 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
2483 my $q_unititle=$dbh->quote($biblio->{'unititle'});
2484 logchange('kohadb', 'change', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
2485 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
2488 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
2489 my $q_notes=$dbh->quote($biblio->{'notes'});
2490 logchange('kohadb', 'change', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
2491 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
2493 foreach $Record_ID (@marcrecords) {
2494 logchange('marc', 'change', $Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2495 changeSubfield($Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2498 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
2499 my $q_serial=$dbh->quote($biblio->{'serial'});
2500 logchange('kohadb', 'change', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
2501 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
2504 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
2505 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
2506 logchange('kohadb', 'change', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2507 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
2509 foreach $Record_ID (@marcrecords) {
2510 logchange('marc', 'change', $Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2511 changeSubfield($Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2514 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
2515 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
2516 logchange('kohadb', 'change', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
2517 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
2519 foreach $Record_ID (@marcrecords) {
2520 logchange('marc', 'change', $Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2521 changeSubfield($Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2525 # Check for subject heading changes
2529 foreach $newsubject (@{$biblio->{'subject'}}) {
2530 $subjects->{$newsubject}=1;
2531 if ($origsubjects->{$newsubject}) {
2532 $subjects->{$newsubject}=2;
2534 my $q_newsubject=$dbh->quote($newsubject);
2535 my $sth=$dbh->prepare("insert into bibliosubject (subject,biblionumber) values ($q_newsubject, $biblionumber)");
2537 logchange('kohadb', 'add', 'biblio', 'subject', $newsubject);
2539 $subfields->{1}->{'Subfield_Mark'}='a';
2540 $subfields->{1}->{'Subfield_Value'}=$newsubject;
2543 foreach $Record_ID (@marcrecords) {
2544 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2545 logchange('marc', 'add', $Record_ID, '650', 'a', $newsubject);
2550 foreach $origsubject (keys %$origsubjects) {
2551 if ($subjects->{$origsubject} == 1) {
2552 my $q_origsubject=$dbh->quote($origsubject);
2553 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'subject', $origsubject);
2554 my $sth=$dbh->prepare("delete from bibliosubject where biblionumber=$biblionumber and subject=$q_origsubject");
2560 sub OLD_MAYBE_DELETED_updateBiblioItem {
2561 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
2563 # This routine should also check to see which fields are actually being
2564 # modified, and log all changes.
2566 my ($env, $biblioitem) = @_;
2567 my $dbh = C4::Context->dbh;
2569 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2570 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
2571 # obi = original biblioitem
2572 my $obi=$sth->fetchrow_hashref;
2573 $sth=$dbh->prepare("select B.Record_ID from Bib_Table B, 0XX_Tag_Table T, 0XX_Subfield_Table S where B.Tag_0XX_ID=T.Tag_ID and T.Subfield_ID=S.Subfield_ID and T.Tag='090' and S.Subfield_Mark='c' and S.Subfield_Value=$biblioitemnumber");
2575 my ($Record_ID) = $sth->fetchrow;
2576 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
2577 logchange('kohadb', 'change', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2578 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
2579 logchange('marc', 'change', $Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2580 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2582 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
2583 logchange('kohadb', 'change', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
2584 my $q_volume=$dbh->quote($biblioitem->{'volume'});
2585 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
2586 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2587 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2589 if ($biblioitem->{'number'} ne $obi->{'number'}) {
2590 logchange('kohadb', 'change', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
2591 my $q_number=$dbh->quote($biblioitem->{'number'});
2592 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
2593 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2594 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2596 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
2597 logchange('kohadb', 'change', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2598 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
2599 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
2600 logchange('marc', 'change', $Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2601 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2603 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
2604 logchange('kohadb', 'change', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
2605 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
2606 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
2607 logchange('marc', 'change', $Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2608 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2610 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
2611 logchange('kohadb', 'change', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
2612 my $q_issn=$dbh->quote($biblioitem->{'issn'});
2613 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
2614 logchange('marc', 'change', $Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2615 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2617 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
2618 logchange('kohadb', 'change', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
2619 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
2620 logchange('marc', 'change', $Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2621 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2623 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
2624 logchange('kohadb', 'change', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
2625 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
2626 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
2627 logchange('marc', 'change', $Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2628 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2630 if ($biblioitem->{'place'} ne $obi->{'place'}) {
2631 logchange('kohadb', 'change', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
2632 my $q_place=$dbh->quote($biblioitem->{'place'});
2633 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
2634 logchange('marc', 'change', $Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2635 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2637 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
2638 logchange('kohadb', 'change', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2639 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
2640 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
2641 logchange('marc', 'change', $Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2642 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2644 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
2645 logchange('kohadb', 'change', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2646 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
2647 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
2648 logchange('marc', 'change', $Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2649 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2651 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
2652 logchange('kohadb', 'change', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
2653 my $q_illus=$dbh->quote($biblioitem->{'illus'});
2654 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
2655 logchange('marc', 'change', $Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2656 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2658 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
2659 logchange('kohadb', 'change', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
2660 my $q_pages=$dbh->quote($biblioitem->{'pages'});
2661 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
2662 logchange('marc', 'change', $Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2663 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2665 if ($biblioitem->{'size'} ne $obi->{'size'}) {
2666 logchange('kohadb', 'change', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
2667 my $q_size=$dbh->quote($biblioitem->{'size'});
2668 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
2669 logchange('marc', 'change', $Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2670 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2672 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
2673 logchange('kohadb', 'change', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
2674 my $q_notes=$dbh->quote($biblioitem->{'notes'});
2675 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
2676 logchange('marc', 'change', $Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2677 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2679 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
2680 logchange('kohadb', 'change', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
2681 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
2682 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
2683 logchange('marc', 'change', $Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2684 changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2689 sub OLD_MAYBE_DELETED_updateItem {
2690 # Update the item with itemnumber $item->{'itemnumber'}
2691 # This routine should also modify the corresponding MARC record data. (852 and
2692 # 876 tags with 876p tag the same as $item->{'barcode'}
2694 # This routine should also check to see which fields are actually being
2695 # modified, and log all changes.
2697 my ($env, $item) = @_;
2698 my $dbh = C4::Context->dbh;
2699 my $itemnumber=$item->{'itemnumber'};
2700 my $biblionumber=$item->{'biblionumber'};
2701 my $biblioitemnumber=$item->{'biblioitemnumber'};
2702 my $barcode=$item->{'barcode'};
2703 my $dateaccessioned=$item->{'dateaccessioned'};
2704 my $booksellerid=$item->{'booksellerid'};
2705 my $homebranch=$item->{'homebranch'};
2706 my $price=$item->{'price'};
2707 my $replacementprice=$item->{'replacementprice'};
2708 my $replacementpricedate=$item->{'replacementpricedate'};
2709 my $multivolume=$item->{'multivolume'};
2710 my $stack=$item->{'stack'};
2711 my $notforloan=$item->{'notforloan'};
2712 my $itemlost=$item->{'itemlost'};
2713 my $wthdrawn=$item->{'wthdrawn'};
2714 my $bulk=$item->{'bulk'};
2715 my $restricted=$item->{'restricted'};
2716 my $binding=$item->{'binding'};
2717 my $itemnotes=$item->{'itemnotes'};
2718 my $holdingbranch=$item->{'holdingbranch'};
2719 my $interim=$item->{'interim'};
2720 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
2722 my $olditem=$sth->fetchrow_hashref;
2723 my $q_barcode=$dbh->quote($olditem->{'barcode'});
2724 $sth=$dbh->prepare("select S.Subfield_ID, B.Record_ID from 8XX_Subfield_Table S, 8XX_Tag_Table T, Bib_Table B where B.Tag_8XX_ID=T.Tag_ID and T.Subfield_ID=S.Subfield_ID and Subfield_Mark='p' and Subfield_Value=$q_barcode");
2726 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
2727 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
2729 my ($link) = $sth->fetchrow;
2730 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
2732 my ($Subfield852_ID) = $sth->fetchrow;
2734 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
2735 logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
2736 my $q_barcode=$dbh->quote($item->{'barcode'});
2737 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
2739 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
2740 logchange('marc', 'change', $Record_ID, '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
2742 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
2743 logchange('kohadb', 'change', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
2744 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
2745 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
2747 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
2748 logchange('marc', 'change', $Record_ID, '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
2750 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
2751 logchange('kohadb', 'change', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2752 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
2753 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
2755 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
2756 logchange('marc', 'change', $Record_ID, '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2758 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
2759 logchange('kohadb', 'change', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
2760 my $q_homebranch=$dbh->quote($item->{'homebranch'});
2761 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
2763 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
2764 logchange('marc', 'change', $Record_ID, '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
2766 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
2767 logchange('kohadb', 'change', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2768 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
2769 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
2771 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
2772 logchange('marc', 'change', $Record_ID, '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2774 if ($item->{'price'} ne $olditem->{'price'}) {
2775 logchange('kohadb', 'change', 'items', 'price', $olditem->{'price'}, $item->{'price'});
2776 my $q_price=$dbh->quote($item->{'price'});
2777 my $sth=$dbh->prepare("update items set price=$q_price where itemnumber=$itemnumber");
2779 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'price'}, $item->{'price'}, $Subfield876_ID);
2780 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'price'}, $item->{'price'});
2782 if ($item->{'itemnotes'} ne $olditem->{'itemnotes'}) {
2783 logchange('kohadb', 'change', 'items', 'itemnotes', $olditem->{'itemnotes'}, $item->{'itemnotes'});
2784 my $q_itemnotes=$dbh->quote($item->{'itemnotes'});
2785 my $sth=$dbh->prepare("update items set itemnotes=$q_itemnotes where itemnumber=$itemnumber");
2787 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'itemnotes'}, $item->{'itemnotes'}, $Subfield876_ID);
2788 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'itemnotes'}, $item->{'itemnotes'});
2790 if ($item->{'notforloan'} ne $olditem->{'notforloan'}) {
2791 logchange('kohadb', 'change', 'items', 'notforloan', $olditem->{'notforloan'}, $item->{'notforloan'});
2792 my $sth=$dbh->prepare("update items set notforloan=$notforloan where itemnumber=$itemnumber");
2794 if ($item->{'notforloan'}) {
2795 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2796 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2798 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2799 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2802 if ($item->{'itemlost'} ne $olditem->{'itemlost'}) {
2803 logchange('kohadb', 'change', 'items', 'itemlost', $olditem->{'itemlost'}, $item->{'itemlost'});
2804 my $sth=$dbh->prepare("update items set itemlost=$itemlost where itemnumber=$itemnumber");
2806 if ($item->{'itemlost'}) {
2807 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2808 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2810 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2811 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2814 if ($item->{'wthdrawn'} ne $olditem->{'wthdrawn'}) {
2815 logchange('kohadb', 'change', 'items', 'wthdrawn', $olditem->{'wthdrawn'}, $item->{'wthdrawn'});
2816 my $sth=$dbh->prepare("update items set wthdrawn=$wthdrawn where itemnumber=$itemnumber");
2818 if ($item->{'wthdrawn'}) {
2819 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2820 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2822 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2823 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2826 if ($item->{'restricted'} ne $olditem->{'restricted'}) {
2827 logchange('kohadb', 'change', 'items', 'restricted', $olditem->{'restricted'}, $item->{'restricted'});
2828 my $sth=$dbh->prepare("update items set restricted=$restricted where itemnumber=$itemnumber");
2830 if ($item->{'restricted'}) {
2831 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2832 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2834 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2835 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2841 # Add a biblioitem and related data to Koha database
2842 sub OLD_MAY_BE_DELETED_newcompletebiblioitem {
2847 $biblio, # hash ref to biblio record
2848 $biblioitem, # hash ref to biblioitem record
2849 $subjects, # list ref of subjects
2850 $addlauthors, # list ref of additional authors
2853 my ( $biblionumber, $biblioitemnumber, $error); # return values
2858 my $additionalauthor;
2861 requireDBI($dbh,"newcompletebiblioitem");
2863 print "<PRE>Trying to add biblio item Title=$biblio->{title} " .
2864 "ISBN=$biblioitem->{isbn} </PRE>\n" if $debug;
2866 # Make sure master biblio entry exists
2867 ($biblionumber,$error)=getoraddbiblio($dbh, $biblio);
2871 $biblioitem->{biblionumber}=$biblionumber;
2874 $biblioitemnumber=newbiblioitem($biblioitem);
2877 $sth=$dbh->prepare("insert into bibliosubject
2878 (biblionumber,subject)
2880 foreach $subjectheading (@{$subjects} ) {
2881 $sth->execute($biblionumber, $subjectheading)
2882 or $error.=$sth->errstr ;
2886 # Add additional authors
2887 $sth=$dbh->prepare("insert into additionalauthors
2888 (biblionumber,author)
2890 foreach $additionalauthor (@{$addlauthors} ) {
2891 $sth->execute($biblionumber, $additionalauthor)
2892 or $error.=$sth->errstr ;
2896 # couldn't get biblio
2898 $biblioitemnumber='';
2900 } # if no biblio error
2902 return ( $biblionumber, $biblioitemnumber, $error);
2904 } # sub newcompletebiblioitem
2908 # END OF UNUSEFUL SUBs
2912 END { } # module clean-up code here (global destructor)