4 # Revision 1.21 2002/10/13 11:34:14 arensb
5 # Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
6 # Thus, $x = $x+2 becomes $x += 2, and so forth.
8 # Revision 1.20 2002/10/13 08:28:32 arensb
9 # Deleted unused variables.
10 # Removed trailing whitespace.
12 # Revision 1.19 2002/10/13 05:56:10 arensb
13 # Added some FIXME comments.
15 # Revision 1.18 2002/10/11 12:34:53 arensb
16 # Replaced &requireDBI with C4::Context->dbh
18 # Revision 1.17 2002/10/10 14:48:25 tipaul
21 # Revision 1.16 2002/10/07 14:04:26 tipaul
22 # road to 1.3.1 : viewing MARC biblio
24 # Revision 1.15 2002/10/05 09:49:25 arensb
25 # Merged with arensb-context branch: use C4::Context->dbh instead of
26 # &C4Connect, and generally prefer C4::Context over C4::Database.
28 # Revision 1.14 2002/10/03 11:28:18 tipaul
29 # Extending Context.pm to add stopword management and using it in MARC-API.
30 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
32 # Revision 1.13 2002/10/02 16:26:44 tipaul
35 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
36 # Merged in changes from main branch.
38 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
39 # Added a whole mess of FIXME comments.
41 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
42 # Added some missing semicolons.
44 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
45 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
48 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
49 # Added a whole mess of FIXME comments.
51 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
52 # Added some missing semicolons.
54 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
55 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
58 # Revision 1.12 2002/10/01 11:48:51 arensb
59 # Added some FIXME comments, mostly marking duplicate functions.
61 # Revision 1.11 2002/09/24 13:49:26 tipaul
62 # long WAS the road to 1.3.0...
63 # coming VERY SOON NOW...
64 # modifying installer and buildrelease to update the DB
66 # Revision 1.10 2002/09/22 16:50:08 arensb
67 # Added some FIXME comments.
69 # Revision 1.9 2002/09/20 12:57:46 tipaul
70 # long is the road to 1.4.0
71 # * MARCadditem and MARCmoditem now wroks
72 # * various bugfixes in MARC management
73 # !!! 1.3.0 should be released very soon now. Be careful !!!
75 # Revision 1.8 2002/09/10 13:53:52 tipaul
76 # MARC API continued...
78 # * 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)
80 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
82 # Revision 1.7 2002/08/14 18:12:51 tonnesen
83 # Added copyright statement to all .pl and .pm files
85 # Revision 1.6 2002/07/25 13:40:31 tipaul
86 # pod documenting the API.
88 # Revision 1.5 2002/07/24 16:11:37 tipaul
90 # Database.pm and Output.pm are almost not modified (var test...)
92 # Biblio.pm is almost completly rewritten.
94 # WHAT DOES IT ??? ==> END of Hitchcock suspens
96 # 1st, it does... nothing...
97 # 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 ...
99 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
100 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
101 # * 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.
102 # * 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.
103 # 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 ;-)
105 # 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.
106 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
110 # move from 1.2 to 1.4 version :
111 # 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
112 # In the 1.4 version, we want to do 2 differents things :
113 # - keep populating the old-DB, that has a LOT less datas than MARC
114 # - populate the MARC-DB
115 # To populate the DBs we have 2 differents sources :
116 # - the standard acquisition system (through book sellers), that does'nt use MARC data
117 # - the MARC acquisition system, that uses MARC data.
119 # thus, we have 2 differents cases :
120 # - 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
121 # - 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.
122 # we MUST have an API for true MARC data, that populate MARC-DB then old-DB
124 # That's why we need 4 subs :
125 # all subs beginning by MARC manage only MARC tables. They manage MARC-DB with MARC::Record parameters
126 # all subs beginning by OLD manage only OLD-DB tables. They manage old-DB with old-DB parameters
127 # 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
128 # 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.
130 # only ALL and old-style API should be used in koha. MARC and OLD is used internally only
132 # 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.
133 # 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 ;-)
137 # Copyright 2000-2002 Katipo Communications
139 # This file is part of Koha.
141 # Koha is free software; you can redistribute it and/or modify it under the
142 # terms of the GNU General Public License as published by the Free Software
143 # Foundation; either version 2 of the License, or (at your option) any later
146 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
147 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
148 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
150 # You should have received a copy of the GNU General Public License along with
151 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
152 # Suite 330, Boston, MA 02111-1307 USA
160 use vars qw($VERSION @ISA @EXPORT);
162 # set the version for version checking
167 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
168 # as the old-style API and the ALL one are the only public functions.
171 &updateBiblio &updateBiblioItem &updateItem
172 &itemcount &newbiblio &newbiblioitem
173 &modnote &newsubject &newsubtitle
174 &modbiblio &checkitems
175 &newitems &modbibitem
176 &modsubtitle &modsubject &modaddauthor &moditem &countitems
177 &delitem &deletebiblioitem &delbiblio
178 &getitemtypes &getbiblio
179 &getbiblioitembybiblionumber
180 &getbiblioitem &getitemsbybiblioitem &isbnsearch
182 &newcompletebiblioitem
184 &MARCfind_oldbiblionumber_from_MARCbibid
185 &MARCfind_MARCbibid_from_oldbiblionumber
187 &ALLnewbiblio &ALLnewitem
190 &MARCaddbiblio &MARCadditem
191 &MARCmodsubfield &MARCaddsubfield
192 &MARCmodbiblio &MARCmoditem
194 &MARCkoha2marcBiblio &MARCmarc2koha &MARCkoha2marcItem
195 &MARCgetbiblio &MARCgetitem
196 &MARCaddword &MARCdelword
201 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
204 # all the following subs takes a MARC::Record as parameter and manage
205 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
206 # ALLxxx subs (xxx deals with old-DB parameters, the ALLxxx deals with MARC-DB parameter)
211 all subs requires/use $dbh as 1st parameter.
212 NOTE : all those subs are private and must be used only inside Biblio.pm (called by a old API sub, or the ALLsub)
216 =head2 @tagslib = &MARCgettagslib($dbh,1|0);
217 last param is 1 for liblibrarian and 0 for libopac
218 returns a hash with tag/subfield meaning
220 =head2 ($tagfield,$tagsubfield) = &MARCfindmarc_from_kohafield($dbh,$kohafield);
221 finds MARC tag and subfield for a given kohafield
222 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
224 =head2 $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
225 finds a old-db biblio number for a given MARCbibid number
227 =head2 $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
228 finds a MARC bibid from a old-db biblionumber
230 =head2 &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
231 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
233 =head2 &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
234 adds a subfield in a biblio (in the MARC tables only).
236 =head2 $MARCRecord = &MARCgetbiblio($dbh,$bibid);
237 Returns a MARC::Record for the biblio $bibid.
239 =head2 &MARCmodbiblio($dbh,$bibid,$delete,$record);
240 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
241 if $delete == 1, every field/subfield not found is deleted in the biblio
242 otherwise, only data passed to MARCmodbiblio is managed.
243 thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
245 =head2 ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
246 MARCmodsubfield changes the value of a given subfield
248 =head2 $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
249 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
250 Returns -1 if more than 1 answer
252 =head2 $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
253 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
255 =head2 &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
256 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
258 =head2 &MARCdelbiblio($dbh,$bibid);
259 MARCdelbiblio delete biblio $bibid
261 =head2 $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
262 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
264 =head2 $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
265 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
267 =head2 $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
268 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
270 =head2 &MARCkoha2marcOnefield => used by MARCkoha2marc and should not be useful elsewhere
272 =head2 $olddb = &MARCmarc2koha($dbh,$MARCRecord);
273 builds a hash with old-db datas from a MARC::Record
275 =head2 &MARCmarc2kohaOnefield => used by MARCmarc2koha and should not be useful elsewhere
277 =head2 MARCaddword => used to manage MARC_word table and should not be useful elsewhere
279 =head2 MARCdelword => used to manage MARC_word table and should not be useful elsewhere
283 Paul POULAIN paul.poulain@free.fr
288 my ($dbh,$forlibrarian)= @_;
290 if ($forlibrarian eq 1) {
291 $sth=$dbh->prepare("select tagfield,liblibrarian as lib from marc_tag_structure");
293 $sth=$dbh->prepare("select tagfield,libopac as lib from marc_tag_structure");
296 my ($lib,$tag,$res,$tab);
297 while ( ($tag,$lib,$tab) = $sth->fetchrow) {
298 $res->{$tag}->{lib}=$lib;
299 $res->{$tab}->{tab}="";
302 if ($forlibrarian eq 1) {
303 $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure");
305 $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib,tab from marc_subfield_structure");
310 while ( ($tag,$subfield,$lib,$tab) = $sth->fetchrow) {
311 $res->{$tag}->{$subfield}->{lib}=$lib;
312 $res->{$tag}->{$subfield}->{tab}=$tab;
317 sub MARCfind_marc_from_kohafield {
318 my ($dbh,$kohafield) = @_;
319 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
320 $sth->execute($kohafield);
321 my ($tagfield,$tagsubfield) = $sth->fetchrow;
322 return ($tagfield,$tagsubfield);
325 sub MARCfind_oldbiblionumber_from_MARCbibid {
326 my ($dbh,$MARCbibid) = @_;
327 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
328 $sth->execute($MARCbibid);
329 my ($biblionumber) = $sth->fetchrow;
330 return $biblionumber;
333 sub MARCfind_MARCbibid_from_oldbiblionumber {
334 my ($dbh,$oldbiblionumber) = @_;
335 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
336 $sth->execute($oldbiblionumber);
337 my ($bibid) = $sth->fetchrow;
342 # pass the MARC::Record to this function, and it will create the records in the marc tables
343 my ($dbh,$record,$biblionumber) = @_;
344 my @fields=$record->fields();
346 # adding main table, and retrieving bibid
347 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
348 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
349 $sth->execute($biblionumber);
350 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
352 ($bibid)=$sth->fetchrow;
355 # now, add subfields...
356 foreach my $field (@fields) {
357 my @subfields=$field->subfields();
359 foreach my $subfieldcount (0..$#subfields) {
360 &MARCaddsubfield($dbh,$bibid,
362 $field->indicator(1).$field->indicator(2),
364 $subfields[$subfieldcount][0],
366 $subfields[$subfieldcount][1]
370 $dbh->do("unlock tables");
375 # pass the MARC::Record to this function, and it will create the records in the marc tables
376 my ($dbh,$record,$biblionumber) = @_;
377 # search for MARC biblionumber
378 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
379 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
380 my @fields=$record->fields();
381 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
382 $sth->execute($bibid);
383 my ($fieldcount) = $sth->fetchrow;
384 # now, add subfields...
385 foreach my $field (@fields) {
386 my @subfields=$field->subfields();
388 foreach my $subfieldcount (0..$#subfields) {
389 &MARCaddsubfield($dbh,$bibid,
391 $field->indicator(1).$field->indicator(2),
393 $subfields[$subfieldcount][0],
395 $subfields[$subfieldcount][1]
399 $dbh->do("unlock tables");
403 sub MARCaddsubfield {
404 # Add a new subfield to a tag into the DB.
405 my ($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
406 # if not value, end of job, we do nothing
407 if (not($subfieldvalue)) {
410 if (not($subfieldcode)) {
413 if (length($subfieldvalue)>255) {
414 # $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
415 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
416 $sth->execute($subfieldvalue);
417 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
419 my ($res)=$sth->fetchrow;
420 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?)");
422 $sth->execute($bibid,'0'.$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
424 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
427 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
429 # $dbh->do("unlock tables");
431 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?)");
432 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
434 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
437 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
442 # Returns MARC::Record of the biblio passed in parameter.
444 my $record = MARC::Record->new();
445 #---- TODO : the leader is missing
446 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
447 from marc_subfield_table
448 where bibid=? order by tagorder,subfieldorder
450 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
451 $sth->execute($bibid);
455 while (my $row=$sth->fetchrow_hashref) {
456 if ($row->{'valuebloblink'}) { #---- search blob if there is one
457 $sth2->execute($row->{'valuebloblink'});
458 my $row2=$sth2->fetchrow_hashref;
460 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
462 if ($row->{tagorder} ne $prevtagorder) {
463 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
464 $record->add_fields($field);
465 $prevtagorder=$row->{tagorder};
466 $prevtag = $row->{tag};
468 %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
470 %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
471 $prevtag= $row->{tag};
474 # the last has not been included inside the loop... do it now !
475 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
476 $record->add_fields($field);
480 # Returns MARC::Record of the biblio passed in parameter.
481 my ($dbh,$bibid,$itemnumber)=@_;
482 warn "MARCgetitem : $bibid, $itemnumber\n";
483 my $record = MARC::Record->new();
484 # search MARC tagorder
485 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=?");
486 $sth2->execute($bibid,$itemnumber);
487 my ($tagorder) = $sth2->fetchrow_array();
488 #---- TODO : the leader is missing
489 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
490 from marc_subfield_table
491 where bibid=? and tagorder=? order by subfieldorder
493 # FIXME - There's already a $sth2 in this scope.
494 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
495 $sth->execute($bibid,$tagorder);
496 while (my $row=$sth->fetchrow_hashref) {
497 if ($row->{'valuebloblink'}) { #---- search blob if there is one
498 $sth2->execute($row->{'valuebloblink'});
499 my $row2=$sth2->fetchrow_hashref;
501 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
503 if ($record->field($row->{'tag'})) {
505 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
506 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
507 if (length($row->{'tag'}) <3) {
508 $row->{'tag'} = "0".$row->{'tag'};
510 $field =$record->field($row->{'tag'});
512 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
513 $record->delete_field($field);
514 $record->add_fields($field);
517 if (length($row->{'tag'}) < 3) {
518 $row->{'tag'} = "0".$row->{'tag'};
520 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
521 $record->add_fields($temp);
529 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
530 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
531 # if nothing to change, don't waste time...
532 if ($oldrecord eq $record) {
535 # otherwise, skip through each subfield...
536 my @fields = $record->fields();
538 foreach my $field (@fields) {
539 my $oldfield = $oldrecord->field($field->tag());
540 my @subfields=$field->subfields();
543 foreach my $subfield (@subfields) {
545 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
546 # just adding datas...
547 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
548 1,@$subfield[0],$subfieldorder,@$subfield[1]);
550 # modify he subfield if it's a different string
551 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
552 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
553 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
561 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
562 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
563 # if nothing to change, don't waste time...
564 if ($oldrecord eq $record) {
567 # otherwise, skip through each subfield...
568 my @fields = $record->fields();
569 # search old MARC item
570 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=?");
571 $sth2->execute($bibid,$itemnumber);
572 my ($tagorder) = $sth2->fetchrow_array();
573 foreach my $field (@fields) {
574 my $oldfield = $oldrecord->field($field->tag());
575 my @subfields=$field->subfields();
577 foreach my $subfield (@subfields) {
579 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
580 # just adding datas...
581 warn "ADD = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
582 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
583 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
585 # modify he subfield if it's a different string
586 warn "MODIFY = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
587 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
588 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
589 warn "MODIFY2 = $bibid, $subfieldid, ".@$subfield[1]."\n";
590 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
599 sub MARCmodsubfield {
600 # Subroutine changes a subfield value given a subfieldid.
601 my ($dbh, $subfieldid, $subfieldvalue )=@_;
602 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
603 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
604 $sth1->execute($subfieldid);
605 my ($oldvaluebloblink)=$sth1->fetchrow;
608 # if too long, use a bloblink
609 if (length($subfieldvalue)>255 ) {
610 # if already a bloblink, update it, otherwise, insert a new one.
611 if ($oldvaluebloblink) {
612 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
613 $sth->execute($subfieldvalue,$oldvaluebloblink);
615 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
616 $sth->execute($subfieldvalue);
617 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
619 my ($res)=$sth->fetchrow;
620 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
621 $sth->execute($subfieldid);
624 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
625 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
626 $sth->execute($subfieldvalue, $subfieldid);
628 $dbh->do("unlock tables");
630 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
631 $sth->execute($subfieldid);
632 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
634 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
635 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
636 return($subfieldid, $subfieldvalue);
639 sub MARCfindsubfield {
640 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
644 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
645 if ($subfieldvalue) {
646 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
648 if ($subfieldorder<1) {
651 $query .= " and subfieldorder=$subfieldorder";
653 my $sti=$dbh->prepare($query);
654 $sti->execute($bibid,$tag, $subfieldcode);
655 while (($subfieldid) = $sti->fetchrow) {
657 $lastsubfieldid=$subfieldid;
659 if ($resultcounter>1) {
660 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
661 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
664 return $lastsubfieldid;
668 sub MARCfindsubfieldid {
669 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
670 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
671 where bibid=? and tag=? and tagorder=?
672 and subfieldcode=? and subfieldorder=?");
673 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
674 my ($res) = $sth->fetchrow;
678 sub MARCdelsubfield {
679 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
680 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
681 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
682 tag='$tag' and tagorder='$tagorder'
683 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
688 # delete a biblio for a $bibid
689 my ($dbh,$bibid) = @_;
690 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
691 $dbh->do("delete from marc_biblio where bibid='$bibid'");
694 sub MARCkoha2marcBiblio {
695 # this function builds partial MARC::Record from the old koha-DB fields
696 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
697 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
698 my $record = MARC::Record->new();
699 #--- if bibid, then retrieve old-style koha data
700 if ($biblionumber>0) {
701 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
702 from biblio where biblionumber=?");
703 $sth2->execute($biblionumber);
704 my $row=$sth2->fetchrow_hashref;
706 foreach $code (keys %$row) {
708 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
712 #--- if biblioitem, then retrieve old-style koha data
713 if ($biblioitemnumber>0) {
714 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
715 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
716 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
718 WHERE biblionumber=? and biblioitemnumber=?
720 $sth2->execute($biblionumber,$biblioitemnumber);
721 my $row=$sth2->fetchrow_hashref;
723 foreach $code (keys %$row) {
725 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
730 # TODO : retrieve notes, additionalauthors
733 sub MARCkoha2marcItem {
734 # this function builds partial MARC::Record from the old koha-DB fields
735 my ($dbh,$biblionumber,$itemnumber) = @_;
736 # my $dbh=&C4Connect;
737 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
738 my $record = MARC::Record->new();
739 #--- if item, then retrieve old-style koha data
741 # print STDERR "prepare $biblionumber,$itemnumber\n";
742 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
743 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
744 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
745 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
747 WHERE itemnumber=?");
748 $sth2->execute($itemnumber);
749 my $row=$sth2->fetchrow_hashref;
751 foreach $code (keys %$row) {
753 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
758 # TODO : retrieve notes, additionalauthors
761 sub MARCkoha2marcSubtitle {
762 # this function builds partial MARC::Record from the old koha-DB fields
763 my ($dbh,$bibnum,$subtitle) = @_;
764 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
765 my $record = MARC::Record->new();
766 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
770 sub MARCkoha2marcOnefield {
771 my ($sth,$record,$kohafieldname,$value)=@_;
774 $sth->execute($kohafieldname);
775 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
776 if ($record->field($tagfield)) {
777 my $tag =$record->field($tagfield);
779 $tag->add_subfields($tagsubfield,$value);
780 $record->delete_field($tag);
781 $record->add_fields($tag);
784 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
791 my ($dbh,$record) = @_;
792 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
794 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
797 # print STDERR $record->as_formatted;
798 while (($field)=$sth2->fetchrow) {
799 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
801 # FIXME - There's already a $sth2 in this scope.
802 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
804 # FIXME - There's already a $field in this scope.
806 while (($field)=$sth2->fetchrow) {
807 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
809 # FIXME - There's already a $sth2 in this scope.
810 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
812 # FIXME - There's already a $field in this scope.
814 while (($field)=$sth2->fetchrow) {
815 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
817 # additional authors : specific
818 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
822 sub MARCmarc2kohaOneField {
823 # to check : if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
824 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
828 $sth->execute($kohatable.".".$kohafield);
829 ($tagfield,$subfield) = $sth->fetchrow;
830 foreach my $field ($record->field($tagfield)) {
831 if ($field->subfield($subfield)) {
832 if ($result->{$kohafield}) {
833 $result->{$kohafield} .= " | ".$field->subfield($subfield);
835 $result->{$kohafield}=$field->subfield($subfield);
843 # split a subfield string and adds it into the word table.
845 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
846 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
847 my @words = split / /,$sentence;
848 # build stopword list
849 # my $sth2 =$dbh->prepare("select word from stopwords");
853 # while(($stopword) = $sth2->fetchrow_array) {
854 # $stopwords->{$stopword} = $stopword;
856 my $stopwords= C4::Context->stopwords;
857 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
858 values (?,?,?,?,?,?,soundex(?))");
859 foreach my $word (@words) {
860 # we record only words longer than 2 car and not in stopwords hash
861 if (length($word)>1 and !($stopwords->{uc($word)})) {
862 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
864 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";
871 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
872 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
873 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
874 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
879 # ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL
882 # all the following subs are useful to manage MARC-DB with complete MARC records.
883 # it's used with marcimport, and marc management tools
888 all subs requires/use $dbh as 1st parameter.
889 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
893 =head2 (oldbibnum,$oldbibitemnum) = ALLnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
894 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
895 are builded from the MARC::Record. If they are passed, they are used.
897 =head2 ALLnewitem($dbh,$olditem);
898 adds an item in the db. $olditem is a old-db hash.
902 Paul POULAIN paul.poulain@free.fr
907 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
908 # note $oldbiblio and $oldbiblioitem are not mandatory.
909 # if not present, they will be builded from $record with MARCmarc2koha function
910 if (($oldbiblio) and not($oldbiblioitem)) {
911 print STDERR "ALLnewbiblio : missing parameter\n";
912 print "ALLnewbiblio : missing parameter : contact koha development team\n";
918 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
919 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
920 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
922 my $olddata = MARCmarc2koha($dbh,$record);
923 $oldbibnum = OLDnewbiblio($dbh,$olddata);
924 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
926 # we must add bibnum and bibitemnum in MARC::Record...
927 # we build the new field with biblionumber and biblioitemnumber
928 # we drop the original field
929 # we add the new builded field.
930 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
931 # (steve and paul : thinks 090 is a good choice)
932 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
933 $sth->execute("biblio.biblionumber");
934 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
935 $sth->execute("biblioitems.biblioitemnumber");
936 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
937 print STDERR "tag1 : $tagfield1 / $tagsubfield1\n tag2 : $tagfield2 / $tagsubfield2\n";
938 if ($tagsubfield1 != $tagsubfield2) {
939 print STDERR "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
940 print "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
943 my $newfield = MARC::Field->new( $tagfield1,'','',
944 "$tagsubfield1" => $oldbibnum,
945 "$tagsubfield2" => $oldbibitemnum);
946 # drop old field and create new one...
947 my $old_field = $record->field($tagfield1);
948 $record->delete_field($old_field);
949 $record->add_fields($newfield);
950 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
951 return ( $oldbibnum,$oldbibitemnum );
955 my ($dbh, $item) = @_;
958 ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{'barcode'});
959 # search MARC biblionumber
960 my $bibid=&MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{'biblionumber'});
962 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
963 $sth->execute($bibid);
964 my ($tagorder) = $sth->fetchrow;
967 # for each field, find MARC tag and subfield, and call the proper MARC sub
968 foreach my $itemkey (keys %$item) {
971 print STDERR "=============> $itemkey : ".$item->{$itemkey}."\n";
972 if ($itemkey eq "biblionumber" || $itemkey eq "biblioitemnumber") {
973 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"biblio.".$itemkey);
975 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"items.".$itemkey);
977 if ($tagfield && $item->{$itemkey} ne 'NULL') {
979 &MARCaddsubfield($dbh,
995 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
1001 all subs requires/use $dbh as 1st parameter.
1002 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
1004 They all are the exact copy of 1.0/1.2 version of the sub
1005 without the OLD. The OLDxxx is called by the original xxx sub.
1006 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
1008 WARNING : there is 1 difference between initialxxx and OLDxxx :
1009 the db header $dbh is always passed as parameter
1010 to avoid over-DB connexion
1014 =head2 $biblionumber = OLDnewbiblio($dbh,$biblio);
1015 adds a record in biblio table. Datas are in the hash $biblio.
1017 =head2 $biblionumber = OLDmodbiblio($dbh,$biblio);
1018 modify a record in biblio table. Datas are in the hash $biblio.
1020 =head2 OLDmodsubtitle($dbh,$bibnum,$subtitle);
1021 modify subtitles in bibliosubtitle table.
1023 =head2 OLDmodaddauthor($dbh,$bibnum,$author);
1024 adds or modify additional authors
1025 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1027 =head2 $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1028 modify/adds subjects
1030 =head2 OLDmodbibitem($dbh, $biblioitem);
1033 =head2 OLDmodnote($dbh,$bibitemnum,$note
1034 modify a note for a biblioitem
1036 =head2 OLDnewbiblioitem($dbh,$biblioitem);
1037 adds a biblioitem ($biblioitem is a hash with the values)
1039 =head2 OLDnewsubject($dbh,$bibnum);
1041 =head2 OLDnewsubtitle($dbh,$bibnum,$subtitle);
1042 create a new subtitle
1044 =head2 ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1045 create a item. $item is a hash and $barcode the barcode.
1047 =head2 OLDmoditem($dbh,$item);
1050 =head2 OLDdelitem($dbh,$itemnum);
1053 =head2 OLDdeletebiblioitem($dbh,$biblioitemnumber);
1054 deletes a biblioitem
1055 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1057 =head2 OLDdelbiblio($dbh,$biblio);
1062 Paul POULAIN paul.poulain@free.fr
1067 my ($dbh,$biblio) = @_;
1068 # my $dbh = &C4Connect;
1069 my $query = "Select max(biblionumber) from biblio";
1070 my $sth = $dbh->prepare($query);
1072 my $data = $sth->fetchrow_arrayref;
1073 my $bibnum = $$data[0] + 1;
1076 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1077 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1078 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
1079 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
1080 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1081 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1082 if ($biblio->{'seriestitle'}) { $series = 1 };
1085 $query = "insert into biblio set
1086 biblionumber = $bibnum,
1087 title = $biblio->{'title'},
1088 author = $biblio->{'author'},
1089 copyrightdate = $biblio->{'copyright'},
1091 seriestitle = $biblio->{'seriestitle'},
1092 notes = $biblio->{'notes'},
1093 abstract = $biblio->{'abstract'}";
1095 $sth = $dbh->prepare($query);
1104 my ($dbh,$biblio) = @_;
1105 # my $dbh = C4Connect;
1109 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1110 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1111 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1112 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
1113 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
1114 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
1115 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
1116 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1118 $query = "Update biblio set
1119 title = $biblio->{'title'},
1120 author = $biblio->{'author'},
1121 abstract = $biblio->{'abstract'},
1122 copyrightdate = $biblio->{'copyrightdate'},
1123 seriestitle = $biblio->{'seriestitle'},
1124 serial = $biblio->{'serial'},
1125 unititle = $biblio->{'unititle'},
1126 notes = $biblio->{'notes'}
1127 where biblionumber = $biblio->{'biblionumber'}";
1128 $sth = $dbh->prepare($query);
1133 return($biblio->{'biblionumber'});
1136 sub OLDmodsubtitle {
1137 my ($dbh,$bibnum, $subtitle) = @_;
1138 # my $dbh = C4Connect;
1139 my $query = "update bibliosubtitle set
1140 subtitle = '$subtitle'
1141 where biblionumber = $bibnum";
1142 my $sth = $dbh->prepare($query);
1150 sub OLDmodaddauthor {
1151 my ($dbh,$bibnum, $author) = @_;
1152 # my $dbh = C4Connect;
1153 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1154 my $sth = $dbh->prepare($query);
1159 if ($author ne '') {
1160 $query = "Insert into additionalauthors set
1162 biblionumber = '$bibnum'";
1163 $sth = $dbh->prepare($query);
1169 } # sub modaddauthor
1173 my ($dbh,$bibnum, $force, @subject) = @_;
1174 # my $dbh = C4Connect;
1175 my $count = @subject;
1177 for (my $i = 0; $i < $count; $i++) {
1178 $subject[$i] =~ s/^ //g;
1179 $subject[$i] =~ s/ $//g;
1180 my $query = "select * from catalogueentry
1181 where entrytype = 's'
1182 and catalogueentry = '$subject[$i]'";
1183 my $sth = $dbh->prepare($query);
1186 if (my $data = $sth->fetchrow_hashref) {
1188 if ($force eq $subject[$i]) {
1189 # subject not in aut, chosen to force anway
1190 # so insert into cataloguentry so its in auth file
1191 $query = "Insert into catalogueentry
1192 (entrytype,catalogueentry)
1193 values ('s','$subject[$i]')";
1194 my $sth2 = $dbh->prepare($query);
1199 $error = "$subject[$i]\n does not exist in the subject authority file";
1200 $query = "Select * from catalogueentry
1201 where entrytype = 's'
1202 and (catalogueentry like '$subject[$i] %'
1203 or catalogueentry like '% $subject[$i] %'
1204 or catalogueentry like '% $subject[$i]')";
1205 my $sth2 = $dbh->prepare($query);
1208 while (my $data = $sth2->fetchrow_hashref) {
1209 $error .= "<br>$data->{'catalogueentry'}";
1217 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1218 my $sth = $dbh->prepare($query);
1221 for (my $i = 0; $i < $count; $i++) {
1222 $sth = $dbh->prepare("Insert into bibliosubject
1223 values ('$subject[$i]', $bibnum)");
1235 my ($dbh,$biblioitem) = @_;
1236 # my $dbh = C4Connect;
1239 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1240 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1241 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1242 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1243 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1244 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1245 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1246 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1247 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1248 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1249 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1250 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1251 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1252 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1254 $query = "Update biblioitems set
1255 itemtype = $biblioitem->{'itemtype'},
1256 url = $biblioitem->{'url'},
1257 isbn = $biblioitem->{'isbn'},
1258 publishercode = $biblioitem->{'publishercode'},
1259 publicationyear = $biblioitem->{'publicationyear'},
1260 classification = $biblioitem->{'classification'},
1261 dewey = $biblioitem->{'dewey'},
1262 subclass = $biblioitem->{'subclass'},
1263 illus = $biblioitem->{'illus'},
1264 pages = $biblioitem->{'pages'},
1265 volumeddesc = $biblioitem->{'volumeddesc'},
1266 notes = $biblioitem->{'notes'},
1267 size = $biblioitem->{'size'},
1268 place = $biblioitem->{'place'}
1269 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1277 my ($dbh,$bibitemnum,$note)=@_;
1278 # my $dbh=C4Connect;
1279 my $query="update biblioitems set notes='$note' where
1280 biblioitemnumber='$bibitemnum'";
1281 my $sth=$dbh->prepare($query);
1287 sub OLDnewbiblioitem {
1288 my ($dbh,$biblioitem) = @_;
1289 # my $dbh = C4Connect;
1290 my $query = "Select max(biblioitemnumber) from biblioitems";
1291 my $sth = $dbh->prepare($query);
1295 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
1296 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
1297 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1298 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1299 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1300 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1301 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
1302 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1303 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1304 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1305 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1306 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
1307 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1308 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1309 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1310 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1311 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1312 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1313 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
1314 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
1317 $data = $sth->fetchrow_arrayref;
1318 $bibitemnum = $$data[0] + 1;
1322 $query = "insert into biblioitems set
1323 biblioitemnumber = $bibitemnum,
1324 biblionumber = $biblioitem->{'biblionumber'},
1325 volume = $biblioitem->{'volume'},
1326 number = $biblioitem->{'number'},
1327 classification = $biblioitem->{'classification'},
1328 itemtype = $biblioitem->{'itemtype'},
1329 url = $biblioitem->{'url'},
1330 isbn = $biblioitem->{'isbn'},
1331 issn = $biblioitem->{'issn'},
1332 dewey = $biblioitem->{'dewey'},
1333 subclass = $biblioitem->{'subclass'},
1334 publicationyear = $biblioitem->{'publicationyear'},
1335 publishercode = $biblioitem->{'publishercode'},
1336 volumedate = $biblioitem->{'volumedate'},
1337 volumeddesc = $biblioitem->{'volumeddesc'},
1338 illus = $biblioitem->{'illus'},
1339 pages = $biblioitem->{'pages'},
1340 notes = $biblioitem->{'notes'},
1341 size = $biblioitem->{'size'},
1342 lccn = $biblioitem->{'lccn'},
1343 marc = $biblioitem->{'marc'},
1344 place = $biblioitem->{'place'}";
1346 $sth = $dbh->prepare($query);
1350 return($bibitemnum);
1354 my ($dbh,$bibnum)=@_;
1355 # my $dbh=C4Connect;
1356 my $query="insert into bibliosubject (biblionumber) values
1358 my $sth=$dbh->prepare($query);
1365 sub OLDnewsubtitle {
1366 my ($dbh,$bibnum, $subtitle) = @_;
1367 # my $dbh = C4Connect;
1368 $subtitle = $dbh->quote($subtitle);
1369 my $query = "insert into bibliosubtitle set
1370 biblionumber = $bibnum,
1371 subtitle = $subtitle";
1372 my $sth = $dbh->prepare($query);
1382 my ($dbh,$item, $barcode) = @_;
1383 # my $dbh = C4Connect;
1384 my $query = "Select max(itemnumber) from items";
1385 my $sth = $dbh->prepare($query);
1391 $data = $sth->fetchrow_hashref;
1392 $itemnumber = $data->{'max(itemnumber)'} + 1;
1395 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
1396 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
1397 $item->{'price'} = $dbh->quote($item->{'price'});
1398 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
1399 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
1401 # foreach my $barcode (@barcodes) {
1402 # $barcode = uc($barcode);
1403 $barcode = $dbh->quote($barcode);
1404 $query = "Insert into items set
1405 itemnumber = $itemnumber,
1406 biblionumber = $item->{'biblionumber'},
1407 biblioitemnumber = $item->{'biblioitemnumber'},
1409 booksellerid = $item->{'booksellerid'},
1410 dateaccessioned = NOW(),
1411 homebranch = $item->{'homebranch'},
1412 holdingbranch = $item->{'homebranch'},
1413 price = $item->{'price'},
1414 replacementprice = $item->{'replacementprice'},
1415 replacementpricedate = NOW(),
1416 itemnotes = $item->{'itemnotes'}";
1417 if ($item->{'loan'}) {
1418 $query .= ",notforloan = $item->{'loan'}";
1421 $sth = $dbh->prepare($query);
1423 if (defined $sth->errstr) {
1424 $error .= $sth->errstr;
1429 return($itemnumber,$error);
1433 my ($dbh,$item) = @_;
1434 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1435 # my $dbh=C4Connect;
1436 my $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1437 barcode='$item->{'barcode'}',itemnotes='$item->{'notes'}'
1438 where itemnumber=$item->{'itemnum'}";
1439 if ($item->{'barcode'} eq ''){
1440 $query="update items set biblioitemnumber=$item->{'bibitemnum'},notforloan=$item->{'loan'} where itemnumber=$item->{'itemnum'}";
1442 if ($item->{'lost'} ne ''){
1443 $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1444 barcode='$item->{'barcode'}',
1445 itemnotes='$item->{'notes'}',
1446 homebranch='$item->{'homebranch'}',
1447 itemlost='$item->{'lost'}',
1448 wthdrawn='$item->{'wthdrawn'}'
1449 where itemnumber=$item->{'itemnum'}";
1451 if ($item->{'replacement'} ne ''){
1452 $query=~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1455 my $sth=$dbh->prepare($query);
1461 # FIXME - A nearly-identical function, &delitem, appears in
1464 my ($dbh,$itemnum)=@_;
1465 # my $dbh=C4Connect;
1466 my $query="select * from items where itemnumber=$itemnum";
1467 my $sth=$dbh->prepare($query);
1469 my @data=$sth->fetchrow_array;
1471 $query="Insert into deleteditems values (";
1472 foreach my $temp (@data){
1473 $query .= "'$temp',";
1477 $sth=$dbh->prepare($query);
1480 $query = "Delete from items where itemnumber=$itemnum";
1481 $sth=$dbh->prepare($query);
1487 sub OLDdeletebiblioitem {
1488 my ($dbh,$biblioitemnumber) = @_;
1489 # my $dbh = C4Connect;
1490 my $query = "Select * from biblioitems
1491 where biblioitemnumber = $biblioitemnumber";
1492 my $sth = $dbh->prepare($query);
1497 if (@results = $sth->fetchrow_array) {
1498 $query = "Insert into deletedbiblioitems values (";
1499 foreach my $value (@results) {
1500 $value = $dbh->quote($value);
1501 $query .= "$value,";
1504 $query =~ s/\,$/\)/;
1507 $query = "Delete from biblioitems
1508 where biblioitemnumber = $biblioitemnumber";
1512 # Now delete all the items attached to the biblioitem
1513 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1514 $sth = $dbh->prepare($query);
1516 while (@results = $sth->fetchrow_array) {
1517 $query = "Insert into deleteditems values (";
1518 foreach my $value (@results) {
1519 $value = $dbh->quote($value);
1520 $query .= "$value,";
1522 $query =~ s/\,$/\)/;
1526 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1529 } # sub deletebiblioitem
1532 my ($dbh,$biblio)=@_;
1533 # my $dbh=C4Connect;
1534 my $query="select * from biblio where biblionumber=$biblio";
1535 my $sth=$dbh->prepare($query);
1537 if (my @data=$sth->fetchrow_array){
1539 $query="Insert into deletedbiblio values (";
1540 foreach my $temp (@data){
1541 $temp=~ s/\'/\\\'/g;
1542 $query .= "'$temp',";
1546 $sth=$dbh->prepare($query);
1549 $query = "Delete from biblio where biblionumber=$biblio";
1550 $sth=$dbh->prepare($query);
1564 # FIXME - This is the same as &C4::Acquisitions::itemcount, but not
1565 # the same as &C4::Search::itemcount
1566 # Since they're both exported, acqui/acquire.pl doesn't compile with -w.
1569 my $dbh = C4::Context->dbh;
1570 my $query="Select count(*) from items where biblionumber=$biblio";
1572 my $sth=$dbh->prepare($query);
1574 my $data=$sth->fetchrow_hashref;
1576 return($data->{'count(*)'});
1581 my $dbh = C4::Context->dbh;
1582 my $query="Select ordernumber
1584 where biblionumber=? and biblioitemnumber=?";
1585 my $sth=$dbh->prepare($query);
1586 $sth->execute($bib,$bi);
1587 my $ordnum=$sth->fetchrow_hashref;
1589 my $order=getsingleorder($ordnum->{'ordernumber'});
1591 return ($order,$ordnum->{'ordernumber'});
1594 # FIXME - This is practically the same function as
1595 # &C4::Acquisitions::getsingleorder and &C4::Catalogue::getsingleorder
1596 sub getsingleorder {
1598 my $dbh = C4::Context->dbh;
1599 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1600 where aqorders.ordernumber=?
1601 and biblio.biblionumber=aqorders.biblionumber and
1602 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1603 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1604 my $sth=$dbh->prepare($query);
1605 $sth->execute($ordnum);
1606 my $data=$sth->fetchrow_hashref;
1611 # FIXME - This is in effect identical to &C4::Acquisitions::newbiblio.
1612 # Pick one and stick with it.
1615 my $dbh = C4::Context->dbh;
1616 my $bibnum=OLDnewbiblio($dbh,$biblio);
1621 # FIXME - This is in effect the same as &C4::Acquisitions::modbiblio.
1622 # Pick one and stick with it.
1623 # FIXME - Get the POD from C4::Acquisitions
1626 my $dbh = C4::Context->dbh;
1627 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1628 return($biblionumber);
1631 # FIXME - This is in effect identical to &C4::Acquisitions::modsubtitle.
1632 # Pick one and stick with it.
1633 # FIXME - Get the POD from C4::Acquisitions
1635 my ($bibnum, $subtitle) = @_;
1636 my $dbh = C4::Context->dbh;
1637 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1641 # FIXME - This is functionally identical to
1642 # &C4::Acquisitions::modaddauthor
1643 # Pick one and stick with it.
1644 # FIXME - Get the POD from C4::Acquisitions
1646 my ($bibnum, $author) = @_;
1647 my $dbh = C4::Context->dbh;
1648 &OLDmodaddauthor($dbh,$bibnum,$author);
1649 } # sub modaddauthor
1652 # FIXME - This is in effect identical to &C4::Acquisitions::modsubject.
1653 # Pick one and stick with it.
1655 my ($bibnum, $force, @subject) = @_;
1656 my $dbh = C4::Context->dbh;
1657 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1661 # FIXME - This is very similar to &C4::Acquisitions::modbibitem.
1662 # Pick one and stick with it.
1664 my ($biblioitem) = @_;
1665 my $dbh = C4::Context->dbh;
1666 &OLDmodbibitem($dbh,$biblioitem);
1667 my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
1668 &MARCmodbiblio($dbh,$biblioitem->{biblionumber},0,$MARCbibitem);
1671 # FIXME - This is in effect identical to &C4::Acquisitions::modnote.
1672 # Pick one and stick with it.
1674 my ($bibitemnum,$note)=@_;
1675 my $dbh = C4::Context->dbh;
1676 &OLDmodnote($dbh,$bibitemnum,$note);
1679 # FIXME - This is quite similar in effect to &C4::newbiblioitem,
1680 # except for the MARC stuff. There's also a &newbiblioitem in
1681 # acqui.simple/addbookslccn.pl
1683 my ($biblioitem) = @_;
1684 my $dbh = C4::Context->dbh;
1685 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1686 # print STDERR "bibitemnum : $bibitemnum\n";
1687 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1688 # print STDERR $MARCbiblio->as_formatted();
1689 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1690 return($bibitemnum);
1693 # FIXME - This is in effect identical to &C4::Acquisitions::newsubject.
1694 # Pick one and stick with it.
1697 my $dbh = C4::Context->dbh;
1698 &OLDnewsubject($dbh,$bibnum);
1701 # FIXME - This is just a wrapper around &OLDnewsubtitle
1702 # FIXME - This is in effect the same as &C4::Acquisitions::newsubtitle
1704 my ($bibnum, $subtitle) = @_;
1705 my $dbh = C4::Context->dbh;
1706 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1709 # FIXME - This is different from &C4::Acquisitions::newitems, though
1710 # both are exported.
1712 my ($item, @barcodes) = @_;
1713 my $dbh = C4::Context->dbh;
1717 foreach my $barcode (@barcodes) {
1718 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1720 # print STDERR "biblionumber : $item->{biblionumber} / MARCbibid : $MARCbibid / itemnumber : $itemnumber\n";
1721 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1722 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1723 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1724 # print STDERR "MARCmodbiblio called\n";
1729 # FIXME - This appears to be functionally equivalent to
1730 # &C4::Acquisitions::moditem.
1731 # Pick one and stick with it.
1734 # my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1735 my $dbh = C4::Context->dbh;
1736 &OLDmoditem($dbh,$item);
1737 warn "biblionumber : $item->{'biblionumber'} / $item->{'itemnum'}\n";
1738 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1739 warn "before MARCmoditem : $item->{biblionumber}, $item->{'itemnum'}\n";
1740 warn $MARCitem->as_formatted();
1741 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1742 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1743 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1746 # FIXME - This is the same as &C4::Acquisitions::Checkitems.
1747 # Pick one and stick with it.
1749 my ($count,@barcodes)=@_;
1750 my $dbh = C4::Context->dbh;
1752 for (my $i=0;$i<$count;$i++){
1753 $barcodes[$i]=uc $barcodes[$i];
1754 my $query="Select * from items where barcode='$barcodes[$i]'";
1755 my $sth=$dbh->prepare($query);
1757 if (my $data=$sth->fetchrow_hashref){
1758 $error.=" Duplicate Barcode: $barcodes[$i]";
1765 # FIXME - This is identical to &C4::Acquisitions::countitems.
1766 # Pick one and stick with it.
1768 my ($bibitemnum)=@_;
1769 my $dbh = C4::Context->dbh;
1770 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1771 my $sth=$dbh->prepare($query);
1773 my $data=$sth->fetchrow_hashref;
1775 return($data->{'count(*)'});
1778 # FIXME - This is just a wrapper around &OLDdelitem, and acts
1779 # identically to &C4::Acquisitions::delitem
1780 # Pick one and stick with it.
1783 my $dbh = C4::Context->dbh;
1784 &OLDdelitem($dbh,$itemnum);
1787 # FIXME - This is functionally identical to
1788 # &C4::Acquisitions::deletebiblioitem.
1789 # Pick one and stick with it.
1790 sub deletebiblioitem {
1791 my ($biblioitemnumber) = @_;
1792 my $dbh = C4::Context->dbh;
1793 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1794 } # sub deletebiblioitem
1797 # FIXME - This is functionally identical to &C4::Acquisitions::delbiblio.
1798 # Pick one and stick with it.
1801 my $dbh = C4::Context->dbh;
1802 &OLDdelbiblio($dbh,$biblio);
1805 # FIXME - This is identical to &C4::Acquisitions::getitemtypes.
1806 # Pick one and stick with it.
1808 my $dbh = C4::Context->dbh;
1809 my $query = "select * from itemtypes";
1810 my $sth = $dbh->prepare($query);
1811 # || die "Cannot prepare $query" . $dbh->errstr;
1816 # || die "Cannot execute $query\n" . $sth->errstr;
1817 while (my $data = $sth->fetchrow_hashref) {
1818 $results[$count] = $data;
1823 return($count, @results);
1824 } # sub getitemtypes
1827 my ($biblionumber) = @_;
1828 my $dbh = C4::Context->dbh;
1829 my $query = "Select * from biblio where biblionumber = $biblionumber";
1830 my $sth = $dbh->prepare($query);
1831 # || die "Cannot prepare $query\n" . $dbh->errstr;
1836 # || die "Cannot execute $query\n" . $sth->errstr;
1837 while (my $data = $sth->fetchrow_hashref) {
1838 $results[$count] = $data;
1843 return($count, @results);
1846 # FIXME - This is identical to &C4::Acquisitions::getbiblioitem.
1847 # Pick one and stick with it.
1849 my ($biblioitemnum) = @_;
1850 my $dbh = C4::Context->dbh;
1851 my $query = "Select * from biblioitems where
1852 biblioitemnumber = $biblioitemnum";
1853 my $sth = $dbh->prepare($query);
1859 while (my $data = $sth->fetchrow_hashref) {
1860 $results[$count] = $data;
1865 return($count, @results);
1866 } # sub getbiblioitem
1868 # FIXME - This is identical to
1869 # &C4::Acquisitions::getbiblioitembybiblionumber.
1870 # Pick one and stick with it.
1871 sub getbiblioitembybiblionumber {
1872 my ($biblionumber) = @_;
1873 my $dbh = C4::Context->dbh;
1874 my $query = "Select * from biblioitems where biblionumber =
1876 my $sth = $dbh->prepare($query);
1882 while (my $data = $sth->fetchrow_hashref) {
1883 $results[$count] = $data;
1888 return($count, @results);
1891 # FIXME - This is identical to
1892 # &C4::Acquisitions::getbiblioitembybiblionumber.
1893 # Pick one and stick with it.
1894 sub getitemsbybiblioitem {
1895 my ($biblioitemnum) = @_;
1896 my $dbh = C4::Context->dbh;
1897 my $query = "Select * from items, biblio where
1898 biblio.biblionumber = items.biblionumber and biblioitemnumber
1900 my $sth = $dbh->prepare($query);
1901 # || die "Cannot prepare $query\n" . $dbh->errstr;
1906 # || die "Cannot execute $query\n" . $sth->errstr;
1907 while (my $data = $sth->fetchrow_hashref) {
1908 $results[$count] = $data;
1913 return($count, @results);
1914 } # sub getitemsbybiblioitem
1916 # FIXME - This is identical to &C4::Acquisitions::isbnsearch.
1917 # Pick one and stick with it.
1920 my $dbh = C4::Context->dbh;
1926 $isbn = $dbh->quote($isbn);
1927 $query = "Select biblio.* from biblio, biblioitems where
1928 biblio.biblionumber = biblioitems.biblionumber
1930 $sth = $dbh->prepare($query);
1933 while (my $data = $sth->fetchrow_hashref) {
1934 $results[$count] = $data;
1939 return($count, @results);
1943 # At the moment this is just a straight copy of the subject code. Needs heavy
1944 # modification to work for additional authors, obviously.
1945 # Check for additional author changes
1947 # my $newadditionalauthor='';
1948 # my $additionalauthors;
1949 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
1950 # $additionalauthors->{$newadditionalauthor}=1;
1951 # if ($origadditionalauthors->{$newadditionalauthor}) {
1952 # $additionalauthors->{$newadditionalauthor}=2;
1954 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
1955 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
1957 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
1959 # $subfields->{1}->{'Subfield_Mark'}='a';
1960 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
1963 # foreach $Record_ID (@marcrecords) {
1964 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1965 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
1969 # my $origadditionalauthor;
1970 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
1971 # if ($additionalauthors->{$origadditionalauthor} == 1) {
1972 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
1973 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
1974 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
1984 # Subroutine to log changes to databases
1985 # Eventually, this subroutine will be used to create a log of all changes made,
1986 # with the possibility of "undo"ing some changes
1988 if ($database eq 'kohadb') {
1994 print STDERR "KOHA: $type $section $item $original $new\n";
1995 } elsif ($database eq 'marc') {
1997 my $Record_ID=shift;
2000 my $subfield_ID=shift;
2003 print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2007 #------------------------------------------------
2010 #---------------------------------------
2011 # Find a biblio entry, or create a new one if it doesn't exist.
2012 # If a "subtitle" entry is in hash, add it to subtitle table
2013 sub getoraddbiblio {
2017 # FIXME - Unused argument
2018 $biblio, # hash ref to fields
2029 $dbh = C4::Context->dbh;
2031 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2032 $sth=$dbh->prepare("select biblionumber
2034 where title=? and author=?
2035 and copyrightdate=? and seriestitle=?");
2037 $biblio->{title}, $biblio->{author},
2038 $biblio->{copyright}, $biblio->{seriestitle} );
2040 ($biblionumber) = $sth->fetchrow;
2041 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2043 # Doesn't exist. Add new one.
2044 print "<PRE>Adding biblio</PRE>\n" if $debug;
2045 ($biblionumber,$error)=&newbiblio($biblio);
2046 if ( $biblionumber ) {
2047 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
2048 if ( $biblio->{subtitle} ) {
2049 &newsubtitle($biblionumber,$biblio->{subtitle} );
2052 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2056 return $biblionumber,$error;
2058 } # sub getoraddbiblio
2062 # UNUSEFUL SUBs. Could be deleted, kept only until beta test
2063 # maybe useful for some MARC tricks steve used.
2066 sub OLD_MAYBE_DELETED_newBiblioItem {
2067 my ($env, $biblioitem) = @_;
2068 my $dbh = C4::Context->dbh;
2069 my $biblionumber=$biblioitem->{'biblionumber'};
2070 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2071 my $volume=$biblioitem->{'volume'};
2072 my $q_volume=$dbh->quote($volume);
2073 my $number=$biblioitem->{'number'};
2074 my $q_number=$dbh->quote($number);
2075 my $classification=$biblioitem->{'classification'};
2076 my $q_classification=$dbh->quote($classification);
2077 my $itemtype=$biblioitem->{'itemtype'};
2078 my $q_itemtype=$dbh->quote($itemtype);
2079 my $isbn=$biblioitem->{'isbn'};
2080 my $q_isbn=$dbh->quote($isbn);
2081 my $issn=$biblioitem->{'issn'};
2082 my $q_issn=$dbh->quote($issn);
2083 my $dewey=$biblioitem->{'dewey'};
2085 ($dewey == 0) && ($dewey='');
2086 my $subclass=$biblioitem->{'subclass'};
2087 my $q_subclass=$dbh->quote($subclass);
2088 my $publicationyear=$biblioitem->{'publicationyear'};
2089 my $publishercode=$biblioitem->{'publishercode'};
2090 my $q_publishercode=$dbh->quote($publishercode);
2091 my $volumedate=$biblioitem->{'volumedate'};
2092 my $q_volumedate=$dbh->quote($volumedate);
2093 my $illus=$biblioitem->{'illus'};
2094 my $q_illus=$dbh->quote($illus);
2095 my $pages=$biblioitem->{'pages'};
2096 my $q_pages=$dbh->quote($pages);
2097 my $notes=$biblioitem->{'notes'};
2098 my $q_notes=$dbh->quote($notes);
2099 my $size=$biblioitem->{'size'};
2100 my $q_size=$dbh->quote($size);
2101 my $place=$biblioitem->{'place'};
2102 my $q_place=$dbh->quote($place);
2103 my $lccn=$biblioitem->{'lccn'};
2104 my $q_lccn=$dbh->quote($lccn);
2107 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
2110 unless ($env->{'marconly'}) {
2111 #my $sth=$dbh->prepare("lock tables biblioitems write");
2113 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
2115 my ($biblioitemnumber) =$sth->fetchrow;
2116 $biblioitemnumber++;
2117 $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)");
2119 #my $sth=$dbh->prepare("unlock tables");
2124 # Should we check if there is already a biblioitem/amrc with the
2125 # same isbn/lccn/issn?
2127 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
2129 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
2130 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2132 my ($subtitle) = $sth->fetchrow;
2133 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2135 my @additionalauthors;
2136 while (my ($additionalauthor) = $sth->fetchrow) {
2137 push (@additionalauthors, $additionalauthor);
2139 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2142 while (my ($subject) = $sth->fetchrow) {
2143 push (@subjects, $subject);
2148 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
2150 my $Resource_ID=$dbh->{'mysql_insertid'};
2151 my $Record_ID=$Resource_ID;
2152 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
2158 $subfields->{1}->{'Subfield_Mark'}='a';
2159 $subfields->{1}->{'Subfield_Value'}=$title;
2161 $subfields->{2}->{'Subfield_Mark'}='b';
2162 $subfields->{2}->{'Subfield_Value'}=$subtitle;
2165 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2171 $subfields->{1}->{'Subfield_Mark'}='a';
2172 $subfields->{1}->{'Subfield_Value'}=$author;
2174 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2179 $subfields->{1}->{'Subfield_Mark'}='a';
2180 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
2182 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2187 $subfields->{1}->{'Subfield_Mark'}='a';
2188 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
2189 $subfields->{2}->{'Subfield_Mark'}='3';
2190 $subfields->{2}->{'Subfield_Value'}='biblio';
2192 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2194 # Additional Authors
2195 foreach (@additionalauthors) {
2197 (next) unless ($author);
2199 $subfields->{1}->{'Subfield_Mark'}='a';
2200 $subfields->{1}->{'Subfield_Value'}=$author;
2201 $subfields->{2}->{'Subfield_Mark'}='e';
2202 $subfields->{2}->{'Subfield_Value'}='author';
2204 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2208 (next) unless ($illus);
2210 $subfields->{1}->{'Subfield_Mark'}='a';
2211 $subfields->{1}->{'Subfield_Value'}=$illus;
2212 $subfields->{2}->{'Subfield_Mark'}='e';
2213 $subfields->{2}->{'Subfield_Value'}='illustrator';
2215 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2218 foreach (@subjects) {
2220 (next) unless ($subject);
2222 $subfields->{1}->{'Subfield_Mark'}='a';
2223 $subfields->{1}->{'Subfield_Value'}=$subject;
2225 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2232 $subfields->{1}->{'Subfield_Mark'}='a';
2233 $subfields->{1}->{'Subfield_Value'}=$isbn;
2235 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2240 $subfields->{1}->{'Subfield_Mark'}='a';
2241 $subfields->{1}->{'Subfield_Value'}=$lccn;
2243 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2248 $subfields->{1}->{'Subfield_Mark'}='a';
2249 $subfields->{1}->{'Subfield_Value'}=$issn;
2251 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2256 $subfields->{1}->{'Subfield_Mark'}='a';
2257 $subfields->{1}->{'Subfield_Value'}=$dewey;
2259 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2261 # DEWEY subclass and itemtype
2264 $subfields->{1}->{'Subfield_Mark'}='a';
2265 $subfields->{1}->{'Subfield_Value'}=$itemtype;
2266 $subfields->{2}->{'Subfield_Mark'}='b';
2267 $subfields->{2}->{'Subfield_Value'}=$subclass;
2268 $subfields->{3}->{'Subfield_Mark'}='c';
2269 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
2270 $subfields->{4}->{'Subfield_Mark'}='d';
2271 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
2273 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2278 $subfields->{1}->{'Subfield_Mark'}='a';
2279 $subfields->{1}->{'Subfield_Value'}=$place;
2280 $subfields->{2}->{'Subfield_Mark'}='b';
2281 $subfields->{2}->{'Subfield_Value'}=$publishercode;
2282 $subfields->{3}->{'Subfield_Mark'}='c';
2283 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
2284 if ($copyrightdate) {
2285 $subfields->{4}->{'Subfield_Mark'}='c';
2286 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
2289 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2292 if ($pages || $size) {
2294 $subfields->{1}->{'Subfield_Mark'}='a';
2295 $subfields->{1}->{'Subfield_Value'}=$pages;
2296 $subfields->{2}->{'Subfield_Mark'}='c';
2297 $subfields->{2}->{'Subfield_Value'}=$size;
2299 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2302 if ($volume || $number) {
2304 $subfields->{1}->{'Subfield_Mark'}='v';
2305 $subfields->{1}->{'Subfield_Value'}=$volume;
2306 $subfields->{2}->{'Subfield_Mark'}='n';
2307 $subfields->{2}->{'Subfield_Value'}=$number;
2309 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2314 $subfields->{1}->{'Subfield_Mark'}='a';
2315 $subfields->{1}->{'Subfield_Value'}=$notes;
2316 $subfields->{2}->{'Subfield_Mark'}='3';
2317 $subfields->{2}->{'Subfield_Value'}='biblioitem';
2319 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2322 return ($env, $Record_ID);
2325 sub OLD_MAYBE_DELETED_newItem {
2326 my ($env, $Record_ID, $item) = @_;
2327 my $dbh = C4::Context->dbh;
2328 my $barcode=$item->{'barcode'};
2329 my $q_barcode=$dbh->quote($barcode);
2330 my $biblionumber=$item->{'biblionumber'};
2331 my $biblioitemnumber=$item->{'biblioitemnumber'};
2332 my $dateaccessioned=$item->{'dateaccessioned'};
2333 my $booksellerid=$item->{'booksellerid'};
2334 my $q_booksellerid=$dbh->quote($booksellerid);
2335 my $homebranch=$item->{'homebranch'};
2336 my $q_homebranch=$dbh->quote($homebranch);
2337 my $holdingbranch=$item->{'holdingbranch'};
2338 my $price=$item->{'price'};
2339 my $replacementprice=$item->{'replacementprice'};
2340 my $replacementpricedate=$item->{'replacementpricedate'};
2341 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
2342 my $notforloan=$item->{'notforloan'};
2343 my $itemlost=$item->{'itemlost'};
2344 my $wthdrawn=$item->{'wthdrawn'};
2345 my $restricted=$item->{'restricted'};
2346 my $itemnotes=$item->{'itemnotes'};
2347 my $q_itemnotes=$dbh->quote($itemnotes);
2348 my $itemtype=$item->{'itemtype'};
2349 my $subclass=$item->{'subclass'};
2353 unless ($env->{'marconly'}) {
2354 my $sth=$dbh->prepare("select max(itemnumber) from items");
2356 my ($itemnumber) =$sth->fetchrow;
2358 $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)");
2365 $subfields->{1}->{'Subfield_Mark'}='p';
2366 $subfields->{1}->{'Subfield_Value'}=$barcode;
2367 $subfields->{2}->{'Subfield_Mark'}='d';
2368 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
2369 $subfields->{3}->{'Subfield_Mark'}='e';
2370 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
2371 $subfields->{4}->{'Subfield_Mark'}='b';
2372 $subfields->{4}->{'Subfield_Value'}=$homebranch;
2373 $subfields->{5}->{'Subfield_Mark'}='l';
2374 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
2375 $subfields->{6}->{'Subfield_Mark'}='c';
2376 $subfields->{6}->{'Subfield_Value'}=$price;
2377 $subfields->{7}->{'Subfield_Mark'}='c';
2378 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
2379 $subfields->{8}->{'Subfield_Mark'}='d';
2380 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
2382 $subfields->{9}->{'Subfield_Mark'}='h';
2383 $subfields->{9}->{'Subfield_Value'}='Not for loan';
2386 $subfields->{10}->{'Subfield_Mark'}='j';
2387 $subfields->{10}->{'Subfield_Value'}='Item lost';
2390 $subfields->{11}->{'Subfield_Mark'}='j';
2391 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
2394 $subfields->{12}->{'Subfield_Mark'}='z';
2395 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
2399 $env->{'linkage'}=1;
2400 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2401 $env->{'linkage'}=0;
2402 $env->{'linkid'}=$Tag_ID;
2405 $subfields2->{1}->{'Subfield_Mark'}='a';
2406 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
2407 $subfields2->{1}->{'Subfield_Mark'}='b';
2408 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
2409 $subfields2->{1}->{'Subfield_Mark'}='c';
2410 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
2411 $subfields2->{2}->{'Subfield_Mark'}='m';
2412 $subfields2->{2}->{'Subfield_Value'}=$subclass;
2413 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
2414 $env->{'linkid'}='';
2417 sub OLD_MAYBE_DELETED_updateBiblio {
2418 # Update the biblio with biblionumber $biblio->{'biblionumber'}
2419 # I guess this routine should search through all marc records for a record that
2420 # has the same biblionumber stored in it, and modify the MARC record as well as
2423 # Also, this subroutine should search through the $biblio object and compare it
2424 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
2425 # this logging feature to be usable to undo changes easily.
2427 my ($env, $biblio) = @_;
2429 my $biblionumber=$biblio->{'biblionumber'};
2430 my $dbh = C4::Context->dbh;
2431 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
2433 my $origbiblio=$sth->fetchrow_hashref;
2434 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2436 my ($subtitle)=$sth->fetchrow;
2437 $origbiblio->{'subtitle'}=$subtitle;
2438 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2440 my $origadditionalauthors;
2441 while (my ($author) = $sth->fetchrow) {
2442 push (@{$origbiblio->{'additionalauthors'}}, $author);
2443 $origadditionalauthors->{$author}=1;
2445 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2448 while (my ($subject) = $sth->fetchrow) {
2449 push (@{$origbiblio->{'subjects'}}, $subject);
2450 $origsubjects->{$subject}=1;
2454 # Obtain a list of MARC Record_ID's that are tied to this biblio
2455 $sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
2458 while (my ($bibid) = $sth->fetchrow) {
2459 push(@marcrecords, $bibid);
2463 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
2464 my $q_author=$dbh->quote($biblio->{'author'});
2465 logchange('kohadb', 'change', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
2466 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
2468 foreach $bibid (@marcrecords) {
2469 logchange('marc', 'change', $bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2470 changeSubfield($bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2473 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
2474 my $q_title=$dbh->quote($biblio->{'title'});
2475 logchange('kohadb', 'change', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
2476 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
2478 foreach $Record_ID (@marcrecords) {
2479 logchange('marc', 'change', $Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2480 changeSubfield($Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2483 if ($biblio->{'subtitle'} ne $origbiblio->{'subtitle'}) {
2484 my $q_subtitle=$dbh->quote($biblio->{'subtitle'});
2485 logchange('kohadb', 'change', 'biblio', 'subtitle', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2486 my $sti=$dbh->prepare("update bibliosubtitle set subtitle=$q_subtitle where biblionumber=$biblio->{'biblionumber'}");
2488 foreach $Record_ID (@marcrecords) {
2489 logchange('marc', 'change', $Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2490 changeSubfield($Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2493 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
2494 my $q_unititle=$dbh->quote($biblio->{'unititle'});
2495 logchange('kohadb', 'change', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
2496 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
2499 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
2500 my $q_notes=$dbh->quote($biblio->{'notes'});
2501 logchange('kohadb', 'change', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
2502 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
2504 foreach $Record_ID (@marcrecords) {
2505 logchange('marc', 'change', $Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2506 changeSubfield($Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2509 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
2510 my $q_serial=$dbh->quote($biblio->{'serial'});
2511 logchange('kohadb', 'change', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
2512 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
2515 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
2516 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
2517 logchange('kohadb', 'change', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2518 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
2520 foreach $Record_ID (@marcrecords) {
2521 logchange('marc', 'change', $Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2522 changeSubfield($Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2525 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
2526 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
2527 logchange('kohadb', 'change', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
2528 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
2530 foreach $Record_ID (@marcrecords) {
2531 logchange('marc', 'change', $Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2532 changeSubfield($Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2536 # Check for subject heading changes
2540 foreach $newsubject (@{$biblio->{'subject'}}) {
2541 $subjects->{$newsubject}=1;
2542 if ($origsubjects->{$newsubject}) {
2543 $subjects->{$newsubject}=2;
2545 my $q_newsubject=$dbh->quote($newsubject);
2546 my $sth=$dbh->prepare("insert into bibliosubject (subject,biblionumber) values ($q_newsubject, $biblionumber)");
2548 logchange('kohadb', 'add', 'biblio', 'subject', $newsubject);
2550 $subfields->{1}->{'Subfield_Mark'}='a';
2551 $subfields->{1}->{'Subfield_Value'}=$newsubject;
2554 foreach $Record_ID (@marcrecords) {
2555 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2556 logchange('marc', 'add', $Record_ID, '650', 'a', $newsubject);
2561 foreach $origsubject (keys %$origsubjects) {
2562 if ($subjects->{$origsubject} == 1) {
2563 my $q_origsubject=$dbh->quote($origsubject);
2564 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'subject', $origsubject);
2565 my $sth=$dbh->prepare("delete from bibliosubject where biblionumber=$biblionumber and subject=$q_origsubject");
2571 sub OLD_MAYBE_DELETED_updateBiblioItem {
2572 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
2574 # This routine should also check to see which fields are actually being
2575 # modified, and log all changes.
2577 my ($env, $biblioitem) = @_;
2578 my $dbh = C4::Context->dbh;
2580 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2581 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
2582 # obi = original biblioitem
2583 my $obi=$sth->fetchrow_hashref;
2584 $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");
2586 my ($Record_ID) = $sth->fetchrow;
2587 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
2588 logchange('kohadb', 'change', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2589 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
2590 logchange('marc', 'change', $Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2591 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2593 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
2594 logchange('kohadb', 'change', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
2595 my $q_volume=$dbh->quote($biblioitem->{'volume'});
2596 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
2597 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2598 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2600 if ($biblioitem->{'number'} ne $obi->{'number'}) {
2601 logchange('kohadb', 'change', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
2602 my $q_number=$dbh->quote($biblioitem->{'number'});
2603 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
2604 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2605 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2607 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
2608 logchange('kohadb', 'change', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2609 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
2610 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
2611 logchange('marc', 'change', $Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2612 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2614 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
2615 logchange('kohadb', 'change', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
2616 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
2617 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
2618 logchange('marc', 'change', $Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2619 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2621 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
2622 logchange('kohadb', 'change', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
2623 my $q_issn=$dbh->quote($biblioitem->{'issn'});
2624 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
2625 logchange('marc', 'change', $Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2626 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2628 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
2629 logchange('kohadb', 'change', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
2630 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
2631 logchange('marc', 'change', $Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2632 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2634 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
2635 logchange('kohadb', 'change', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
2636 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
2637 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
2638 logchange('marc', 'change', $Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2639 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2641 if ($biblioitem->{'place'} ne $obi->{'place'}) {
2642 logchange('kohadb', 'change', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
2643 my $q_place=$dbh->quote($biblioitem->{'place'});
2644 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
2645 logchange('marc', 'change', $Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2646 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2648 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
2649 logchange('kohadb', 'change', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2650 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
2651 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
2652 logchange('marc', 'change', $Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2653 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2655 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
2656 logchange('kohadb', 'change', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2657 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
2658 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
2659 logchange('marc', 'change', $Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2660 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2662 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
2663 logchange('kohadb', 'change', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
2664 my $q_illus=$dbh->quote($biblioitem->{'illus'});
2665 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
2666 logchange('marc', 'change', $Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2667 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2669 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
2670 logchange('kohadb', 'change', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
2671 my $q_pages=$dbh->quote($biblioitem->{'pages'});
2672 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
2673 logchange('marc', 'change', $Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2674 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2676 if ($biblioitem->{'size'} ne $obi->{'size'}) {
2677 logchange('kohadb', 'change', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
2678 my $q_size=$dbh->quote($biblioitem->{'size'});
2679 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
2680 logchange('marc', 'change', $Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2681 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2683 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
2684 logchange('kohadb', 'change', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
2685 my $q_notes=$dbh->quote($biblioitem->{'notes'});
2686 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
2687 logchange('marc', 'change', $Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2688 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2690 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
2691 logchange('kohadb', 'change', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
2692 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
2693 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
2694 logchange('marc', 'change', $Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2695 changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2700 sub OLD_MAYBE_DELETED_updateItem {
2701 # Update the item with itemnumber $item->{'itemnumber'}
2702 # This routine should also modify the corresponding MARC record data. (852 and
2703 # 876 tags with 876p tag the same as $item->{'barcode'}
2705 # This routine should also check to see which fields are actually being
2706 # modified, and log all changes.
2708 my ($env, $item) = @_;
2709 my $dbh = C4::Context->dbh;
2710 my $itemnumber=$item->{'itemnumber'};
2711 my $biblionumber=$item->{'biblionumber'};
2712 my $biblioitemnumber=$item->{'biblioitemnumber'};
2713 my $barcode=$item->{'barcode'};
2714 my $dateaccessioned=$item->{'dateaccessioned'};
2715 my $booksellerid=$item->{'booksellerid'};
2716 my $homebranch=$item->{'homebranch'};
2717 my $price=$item->{'price'};
2718 my $replacementprice=$item->{'replacementprice'};
2719 my $replacementpricedate=$item->{'replacementpricedate'};
2720 my $multivolume=$item->{'multivolume'};
2721 my $stack=$item->{'stack'};
2722 my $notforloan=$item->{'notforloan'};
2723 my $itemlost=$item->{'itemlost'};
2724 my $wthdrawn=$item->{'wthdrawn'};
2725 my $bulk=$item->{'bulk'};
2726 my $restricted=$item->{'restricted'};
2727 my $binding=$item->{'binding'};
2728 my $itemnotes=$item->{'itemnotes'};
2729 my $holdingbranch=$item->{'holdingbranch'};
2730 my $interim=$item->{'interim'};
2731 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
2733 my $olditem=$sth->fetchrow_hashref;
2734 my $q_barcode=$dbh->quote($olditem->{'barcode'});
2735 $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");
2737 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
2738 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
2740 my ($link) = $sth->fetchrow;
2741 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
2743 my ($Subfield852_ID) = $sth->fetchrow;
2745 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
2746 logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
2747 my $q_barcode=$dbh->quote($item->{'barcode'});
2748 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
2750 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
2751 logchange('marc', 'change', $Record_ID, '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
2753 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
2754 logchange('kohadb', 'change', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
2755 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
2756 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
2758 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
2759 logchange('marc', 'change', $Record_ID, '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
2761 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
2762 logchange('kohadb', 'change', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2763 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
2764 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
2766 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
2767 logchange('marc', 'change', $Record_ID, '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2769 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
2770 logchange('kohadb', 'change', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
2771 my $q_homebranch=$dbh->quote($item->{'homebranch'});
2772 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
2774 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
2775 logchange('marc', 'change', $Record_ID, '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
2777 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
2778 logchange('kohadb', 'change', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2779 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
2780 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
2782 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
2783 logchange('marc', 'change', $Record_ID, '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2785 if ($item->{'price'} ne $olditem->{'price'}) {
2786 logchange('kohadb', 'change', 'items', 'price', $olditem->{'price'}, $item->{'price'});
2787 my $q_price=$dbh->quote($item->{'price'});
2788 my $sth=$dbh->prepare("update items set price=$q_price where itemnumber=$itemnumber");
2790 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'price'}, $item->{'price'}, $Subfield876_ID);
2791 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'price'}, $item->{'price'});
2793 if ($item->{'itemnotes'} ne $olditem->{'itemnotes'}) {
2794 logchange('kohadb', 'change', 'items', 'itemnotes', $olditem->{'itemnotes'}, $item->{'itemnotes'});
2795 my $q_itemnotes=$dbh->quote($item->{'itemnotes'});
2796 my $sth=$dbh->prepare("update items set itemnotes=$q_itemnotes where itemnumber=$itemnumber");
2798 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'itemnotes'}, $item->{'itemnotes'}, $Subfield876_ID);
2799 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'itemnotes'}, $item->{'itemnotes'});
2801 if ($item->{'notforloan'} ne $olditem->{'notforloan'}) {
2802 logchange('kohadb', 'change', 'items', 'notforloan', $olditem->{'notforloan'}, $item->{'notforloan'});
2803 my $sth=$dbh->prepare("update items set notforloan=$notforloan where itemnumber=$itemnumber");
2805 if ($item->{'notforloan'}) {
2806 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2807 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2809 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2810 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2813 if ($item->{'itemlost'} ne $olditem->{'itemlost'}) {
2814 logchange('kohadb', 'change', 'items', 'itemlost', $olditem->{'itemlost'}, $item->{'itemlost'});
2815 my $sth=$dbh->prepare("update items set itemlost=$itemlost where itemnumber=$itemnumber");
2817 if ($item->{'itemlost'}) {
2818 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2819 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2821 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2822 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2825 if ($item->{'wthdrawn'} ne $olditem->{'wthdrawn'}) {
2826 logchange('kohadb', 'change', 'items', 'wthdrawn', $olditem->{'wthdrawn'}, $item->{'wthdrawn'});
2827 my $sth=$dbh->prepare("update items set wthdrawn=$wthdrawn where itemnumber=$itemnumber");
2829 if ($item->{'wthdrawn'}) {
2830 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2831 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2833 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2834 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2837 if ($item->{'restricted'} ne $olditem->{'restricted'}) {
2838 logchange('kohadb', 'change', 'items', 'restricted', $olditem->{'restricted'}, $item->{'restricted'});
2839 my $sth=$dbh->prepare("update items set restricted=$restricted where itemnumber=$itemnumber");
2841 if ($item->{'restricted'}) {
2842 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2843 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2845 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2846 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2852 # Add a biblioitem and related data to Koha database
2853 sub OLD_MAY_BE_DELETED_newcompletebiblioitem {
2858 # FIXME - Unused argument
2859 $biblio, # hash ref to biblio record
2860 $biblioitem, # hash ref to biblioitem record
2861 $subjects, # list ref of subjects
2862 $addlauthors, # list ref of additional authors
2865 my ( $biblionumber, $biblioitemnumber, $error); # return values
2870 my $additionalauthor;
2873 $dbh = C4::Context->dbh;
2875 print "<PRE>Trying to add biblio item Title=$biblio->{title} " .
2876 "ISBN=$biblioitem->{isbn} </PRE>\n" if $debug;
2878 # Make sure master biblio entry exists
2879 ($biblionumber,$error)=getoraddbiblio($dbh, $biblio);
2883 $biblioitem->{biblionumber}=$biblionumber;
2886 $biblioitemnumber=newbiblioitem($biblioitem);
2889 $sth=$dbh->prepare("insert into bibliosubject
2890 (biblionumber,subject)
2892 foreach $subjectheading (@{$subjects} ) {
2893 $sth->execute($biblionumber, $subjectheading)
2894 or $error.=$sth->errstr ;
2898 # Add additional authors
2899 $sth=$dbh->prepare("insert into additionalauthors
2900 (biblionumber,author)
2902 foreach $additionalauthor (@{$addlauthors} ) {
2903 $sth->execute($biblionumber, $additionalauthor)
2904 or $error.=$sth->errstr ;
2908 # couldn't get biblio
2910 $biblioitemnumber='';
2912 } # if no biblio error
2914 return ( $biblionumber, $biblioitemnumber, $error);
2916 } # sub newcompletebiblioitem
2920 # END OF UNUSEFUL SUBs
2924 END { } # module clean-up code here (global destructor)