4 # Revision 1.16 2002/10/07 14:04:26 tipaul
5 # road to 1.3.1 : viewing MARC biblio
7 # Revision 1.15 2002/10/05 09:49:25 arensb
8 # Merged with arensb-context branch: use C4::Context->dbh instead of
9 # &C4Connect, and generally prefer C4::Context over C4::Database.
11 # Revision 1.14 2002/10/03 11:28:18 tipaul
12 # Extending Context.pm to add stopword management and using it in MARC-API.
13 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
15 # Revision 1.13 2002/10/02 16:26:44 tipaul
18 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
19 # Merged in changes from main branch.
21 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
22 # Added a whole mess of FIXME comments.
24 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
25 # Added some missing semicolons.
27 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
28 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
31 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
32 # Added a whole mess of FIXME comments.
34 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
35 # Added some missing semicolons.
37 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
38 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
41 # Revision 1.12 2002/10/01 11:48:51 arensb
42 # Added some FIXME comments, mostly marking duplicate functions.
44 # Revision 1.11 2002/09/24 13:49:26 tipaul
45 # long WAS the road to 1.3.0...
46 # coming VERY SOON NOW...
47 # modifying installer and buildrelease to update the DB
49 # Revision 1.10 2002/09/22 16:50:08 arensb
50 # Added some FIXME comments.
52 # Revision 1.9 2002/09/20 12:57:46 tipaul
53 # long is the road to 1.4.0
54 # * MARCadditem and MARCmoditem now wroks
55 # * various bugfixes in MARC management
56 # !!! 1.3.0 should be released very soon now. Be careful !!!
58 # Revision 1.8 2002/09/10 13:53:52 tipaul
59 # MARC API continued...
61 # * 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)
63 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
65 # Revision 1.7 2002/08/14 18:12:51 tonnesen
66 # Added copyright statement to all .pl and .pm files
68 # Revision 1.6 2002/07/25 13:40:31 tipaul
69 # pod documenting the API.
71 # Revision 1.5 2002/07/24 16:11:37 tipaul
73 # Database.pm and Output.pm are almost not modified (var test...)
75 # Biblio.pm is almost completly rewritten.
77 # WHAT DOES IT ??? ==> END of Hitchcock suspens
79 # 1st, it does... nothing...
80 # 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 ...
82 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
83 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
84 # * 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.
85 # * 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.
86 # 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 ;-)
88 # 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.
89 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
93 # move from 1.2 to 1.4 version :
94 # 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
95 # In the 1.4 version, we want to do 2 differents things :
96 # - keep populating the old-DB, that has a LOT less datas than MARC
97 # - populate the MARC-DB
98 # To populate the DBs we have 2 differents sources :
99 # - the standard acquisition system (through book sellers), that does'nt use MARC data
100 # - the MARC acquisition system, that uses MARC data.
102 # thus, we have 2 differents cases :
103 # - with the standard acquisition system, we have non MARC data and want to populate old-DB and MARC-DB, knowing it's an incomplete MARC-record
104 # - with the MARC acquisition system, we have MARC datas, and want to loose nothing in MARC-DB. So, we can't store datas in old-DB, then copy in MARC-DB.
105 # we MUST have an API for true MARC data, that populate MARC-DB then old-DB
107 # That's why we need 4 subs :
108 # all subs beginning by MARC manage only MARC tables. They manage MARC-DB with MARC::Record parameters
109 # all subs beginning by OLD manage only OLD-DB tables. They manage old-DB with old-DB parameters
110 # 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
111 # 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.
113 # only ALL and old-style API should be used in koha. MARC and OLD is used internally only
115 # 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.
116 # 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 ;-)
120 # Copyright 2000-2002 Katipo Communications
122 # This file is part of Koha.
124 # Koha is free software; you can redistribute it and/or modify it under the
125 # terms of the GNU General Public License as published by the Free Software
126 # Foundation; either version 2 of the License, or (at your option) any later
129 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
130 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
131 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
133 # You should have received a copy of the GNU General Public License along with
134 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
135 # Suite 330, Boston, MA 02111-1307 USA
143 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
145 # set the version for version checking
150 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
151 # as the old-style API and the ALL one are the only public functions.
154 &updateBiblio &updateBiblioItem &updateItem
155 &itemcount &newbiblio &newbiblioitem
156 &modnote &newsubject &newsubtitle
157 &modbiblio &checkitems
158 &newitems &modbibitem
159 &modsubtitle &modsubject &modaddauthor &moditem &countitems
160 &delitem &deletebiblioitem &delbiblio
161 &getitemtypes &getbiblio
162 &getbiblioitembybiblionumber
163 &getbiblioitem &getitemsbybiblioitem &isbnsearch
165 &newcompletebiblioitem
167 &MARCfind_oldbiblionumber_from_MARCbibid
168 &MARCfind_MARCbibid_from_oldbiblionumber
170 &ALLnewbiblio &ALLnewitem
173 &MARCaddbiblio &MARCadditem
174 &MARCmodsubfield &MARCaddsubfield
175 &MARCmodbiblio &MARCmoditem
177 &MARCkoha2marcBiblio &MARCmarc2koha &MARCkoha2marcItem
178 &MARCgetbiblio &MARCgetitem
179 &MARCaddword &MARCdelword
184 # your exported package globals go here,
185 # as well as any optionally exported functions
187 @EXPORT_OK = qw($Var1 %Hashit); # FIXME - These are never used
191 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
194 # all the following subs takes a MARC::Record as parameter and manage
195 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
196 # ALLxxx subs (xxx deals with old-DB parameters, the ALLxxx deals with MARC-DB parameter)
201 all subs requires/use $dbh as 1st parameter.
202 NOTE : all those subs are private and must be used only inside Biblio.pm (called by a old API sub, or the ALLsub)
206 =head2 @tagslib = &MARCgettagslib($dbh,1|0);
207 last param is 1 for liblibrarian and 0 for libopac
208 returns a hash with tag/subfield meaning
210 =head2 ($tagfield,$tagsubfield) = &MARCfindmarc_from_kohafield($dbh,$kohafield);
211 finds MARC tag and subfield for a given kohafield
212 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
214 =head2 $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
215 finds a old-db biblio number for a given MARCbibid number
217 =head2 $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
218 finds a MARC bibid from a old-db biblionumber
220 =head2 &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
221 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
223 =head2 &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
224 adds a subfield in a biblio (in the MARC tables only).
226 =head2 $MARCRecord = &MARCgetbiblio($dbh,$bibid);
227 Returns a MARC::Record for the biblio $bibid.
229 =head2 &MARCmodbiblio($dbh,$bibid,$delete,$record);
230 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
231 if $delete == 1, every field/subfield not found is deleted in the biblio
232 otherwise, only data passed to MARCmodbiblio is managed.
233 thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
235 =head2 ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
236 MARCmodsubfield changes the value of a given subfield
238 =head2 $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
239 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
240 Returns -1 if more than 1 answer
242 =head2 $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
243 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
245 =head2 &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
246 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
248 =head2 &MARCdelbiblio($dbh,$bibid);
249 MARCdelbiblio delete biblio $bibid
251 =head2 $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
252 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
254 =head2 $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
255 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
257 =head2 $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
258 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
260 =head2 &MARCkoha2marcOnefield => used by MARCkoha2marc and should not be useful elsewhere
262 =head2 $olddb = &MARCmarc2koha($dbh,$MARCRecord);
263 builds a hash with old-db datas from a MARC::Record
265 =head2 &MARCmarc2kohaOnefield => used by MARCmarc2koha and should not be useful elsewhere
267 =head2 MARCaddword => used to manage MARC_word table and should not be useful elsewhere
269 =head2 MARCdelword => used to manage MARC_word table and should not be useful elsewhere
273 Paul POULAIN paul.poulain@free.fr
278 my ($dbh,$forlibrarian)= @_;
280 if ($forlibrarian eq 1) {
281 $sth=$dbh->prepare("select tagfield,liblibrarian as lib from marc_tag_structure");
283 $sth=$dbh->prepare("select tagfield,libopac as lib from marc_tag_structure");
286 my ($lib,$tag,$res,$tab);
287 while ( ($tag,$lib,$tab) = $sth->fetchrow) {
288 $res->{$tag}->{lib}=$lib;
289 $res->{$tab}->{tab}="";
292 if ($forlibrarian eq 1) {
293 $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian,tab as lib from marc_subfield_structure");
295 $sth=$dbh->prepare("select tagfield,tagsubfield,libopac,tab as lib from marc_subfield_structure");
300 while ( ($tag,$subfield,$lib,$tab) = $sth->fetchrow) {
301 $res->{$tag}->{$subfield}->{lib}=$lib;
302 $res->{$tag}->{$subfield}->{tab}=$tab;
308 sub MARCfind_marc_from_kohafield {
309 my ($dbh,$kohafield) = @_;
310 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
311 $sth->execute($kohafield);
312 my ($tagfield,$tagsubfield) = $sth->fetchrow;
313 return ($tagfield,$tagsubfield);
316 sub MARCfind_oldbiblionumber_from_MARCbibid {
317 my ($dbh,$MARCbibid) = @_;
318 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
319 $sth->execute($MARCbibid);
320 my ($biblionumber) = $sth->fetchrow;
321 return $biblionumber;
324 sub MARCfind_MARCbibid_from_oldbiblionumber {
325 my ($dbh,$oldbiblionumber) = @_;
326 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
327 $sth->execute($oldbiblionumber);
328 my ($bibid) = $sth->fetchrow;
333 # pass the MARC::Record to this function, and it will create the records in the marc tables
334 my ($dbh,$record,$biblionumber) = @_;
335 my @fields=$record->fields();
337 # adding main table, and retrieving bibid
338 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
339 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
340 $sth->execute($biblionumber);
341 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
343 ($bibid)=$sth->fetchrow;
346 # now, add subfields...
347 foreach my $field (@fields) {
348 my @subfields=$field->subfields();
350 foreach my $subfieldcount (0..$#subfields) {
351 &MARCaddsubfield($dbh,$bibid,
353 $field->indicator(1).$field->indicator(2),
355 $subfields[$subfieldcount][0],
357 $subfields[$subfieldcount][1]
361 $dbh->do("unlock tables");
366 # pass the MARC::Record to this function, and it will create the records in the marc tables
367 my ($dbh,$record,$biblionumber) = @_;
368 # search for MARC biblionumber
369 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
370 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
371 my @fields=$record->fields();
372 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
373 $sth->execute($bibid);
374 my ($fieldcount) = $sth->fetchrow;
375 # now, add subfields...
376 foreach my $field (@fields) {
377 my @subfields=$field->subfields();
379 foreach my $subfieldcount (0..$#subfields) {
380 &MARCaddsubfield($dbh,$bibid,
382 $field->indicator(1).$field->indicator(2),
384 $subfields[$subfieldcount][0],
386 $subfields[$subfieldcount][1]
390 $dbh->do("unlock tables");
394 sub MARCaddsubfield {
395 # Add a new subfield to a tag into the DB.
396 my ($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
397 # if not value, end of job, we do nothing
398 if (not($subfieldvalue)) {
401 if (not($subfieldcode)) {
404 if (length($subfieldvalue)>255) {
405 # $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
406 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
407 $sth->execute($subfieldvalue);
408 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
410 my ($res)=$sth->fetchrow;
411 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?)");
413 $sth->execute($bibid,'0'.$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
415 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
418 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
420 # $dbh->do("unlock tables");
422 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?)");
423 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
425 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
428 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
433 # Returns MARC::Record of the biblio passed in parameter.
435 my $record = MARC::Record->new();
436 #---- TODO : the leader is missing
437 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
438 from marc_subfield_table
439 where bibid=? order by tagorder,subfieldorder
441 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
442 $sth->execute($bibid);
443 while (my $row=$sth->fetchrow_hashref) {
444 if ($row->{'valuebloblink'}) { #---- search blob if there is one
445 $sth2->execute($row->{'valuebloblink'});
446 my $row2=$sth2->fetchrow_hashref;
448 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
450 if ($record->field($row->{'tag'})) {
452 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
453 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
454 if (length($row->{'tag'}) <3) {
455 $row->{'tag'} = "0".$row->{'tag'};
457 $field =$record->field($row->{'tag'});
459 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
460 $record->delete_field($field);
461 $record->add_fields($field);
464 if (length($row->{'tag'}) < 3) {
465 $row->{'tag'} = "0".$row->{'tag'};
467 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
468 $record->add_fields($temp);
475 # Returns MARC::Record of the biblio passed in parameter.
476 my ($dbh,$bibid,$itemnumber)=@_;
477 warn "MARCgetitem : $bibid, $itemnumber\n";
478 my $record = MARC::Record->new();
479 # search MARC tagorder
480 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=?");
481 $sth2->execute($bibid,$itemnumber);
482 my ($tagorder) = $sth2->fetchrow_array();
483 #---- TODO : the leader is missing
484 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
485 from marc_subfield_table
486 where bibid=? and tagorder=? order by subfieldorder
488 # FIXME - There's already a $sth2 in this scope.
489 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
490 $sth->execute($bibid,$tagorder);
491 while (my $row=$sth->fetchrow_hashref) {
492 if ($row->{'valuebloblink'}) { #---- search blob if there is one
493 $sth2->execute($row->{'valuebloblink'});
494 my $row2=$sth2->fetchrow_hashref;
496 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
498 if ($record->field($row->{'tag'})) {
500 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
501 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
502 if (length($row->{'tag'}) <3) {
503 $row->{'tag'} = "0".$row->{'tag'};
505 $field =$record->field($row->{'tag'});
507 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
508 $record->delete_field($field);
509 $record->add_fields($field);
512 if (length($row->{'tag'}) < 3) {
513 $row->{'tag'} = "0".$row->{'tag'};
515 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
516 $record->add_fields($temp);
524 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
525 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
526 # if nothing to change, don't waste time...
527 if ($oldrecord eq $record) {
530 # otherwise, skip through each subfield...
531 my @fields = $record->fields();
533 foreach my $field (@fields) {
534 my $oldfield = $oldrecord->field($field->tag());
535 my @subfields=$field->subfields();
538 foreach my $subfield (@subfields) {
540 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
541 # just adding datas...
542 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
543 1,@$subfield[0],$subfieldorder,@$subfield[1]);
545 # modify he subfield if it's a different string
546 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
547 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
548 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
556 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
557 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
558 # if nothing to change, don't waste time...
559 if ($oldrecord eq $record) {
562 # otherwise, skip through each subfield...
563 my @fields = $record->fields();
564 # search old MARC item
565 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=?");
566 $sth2->execute($bibid,$itemnumber);
567 my ($tagorder) = $sth2->fetchrow_array();
568 foreach my $field (@fields) {
569 my $oldfield = $oldrecord->field($field->tag());
570 my @subfields=$field->subfields();
572 foreach my $subfield (@subfields) {
574 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
575 # just adding datas...
576 warn "ADD = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
577 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
578 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
580 # modify he subfield if it's a different string
581 warn "MODIFY = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
582 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
583 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
584 warn "MODIFY2 = $bibid, $subfieldid, ".@$subfield[1]."\n";
585 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
594 sub MARCmodsubfield {
595 # Subroutine changes a subfield value given a subfieldid.
596 my ($dbh, $subfieldid, $subfieldvalue )=@_;
597 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
598 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
599 $sth1->execute($subfieldid);
600 my ($oldvaluebloblink)=$sth1->fetchrow;
603 # if too long, use a bloblink
604 if (length($subfieldvalue)>255 ) {
605 # if already a bloblink, update it, otherwise, insert a new one.
606 if ($oldvaluebloblink) {
607 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
608 $sth->execute($subfieldvalue,$oldvaluebloblink);
610 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
611 $sth->execute($subfieldvalue);
612 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
614 my ($res)=$sth->fetchrow;
615 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
616 $sth->execute($subfieldid);
619 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
620 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
621 $sth->execute($subfieldvalue, $subfieldid);
623 $dbh->do("unlock tables");
625 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
626 $sth->execute($subfieldid);
627 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
629 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
630 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
631 return($subfieldid, $subfieldvalue);
634 sub MARCfindsubfield {
635 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
639 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
640 if ($subfieldvalue) {
641 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
643 if ($subfieldorder<1) {
646 $query .= " and subfieldorder=$subfieldorder";
648 my $sti=$dbh->prepare($query);
649 $sti->execute($bibid,$tag, $subfieldcode);
650 while (($subfieldid) = $sti->fetchrow) {
652 $lastsubfieldid=$subfieldid;
654 if ($resultcounter>1) {
655 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
656 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
659 return $lastsubfieldid;
663 sub MARCfindsubfieldid {
664 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
665 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
666 where bibid=? and tag=? and tagorder=?
667 and subfieldcode=? and subfieldorder=?");
668 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
669 my ($res) = $sth->fetchrow;
673 sub MARCdelsubfield {
674 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
675 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
676 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
677 tag='$tag' and tagorder='$tagorder'
678 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
683 # delete a biblio for a $bibid
684 my ($dbh,$bibid) = @_;
685 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
686 $dbh->do("delete from marc_biblio where bibid='$bibid'");
689 sub MARCkoha2marcBiblio {
690 # this function builds partial MARC::Record from the old koha-DB fields
691 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
692 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
693 my $record = MARC::Record->new();
694 #--- if bibid, then retrieve old-style koha data
695 if ($biblionumber>0) {
696 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
697 from biblio where biblionumber=?");
698 $sth2->execute($biblionumber);
699 my $row=$sth2->fetchrow_hashref;
701 foreach $code (keys %$row) {
703 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
707 #--- if biblioitem, then retrieve old-style koha data
708 if ($biblioitemnumber>0) {
709 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
710 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
711 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
713 WHERE biblionumber=? and biblioitemnumber=?
715 $sth2->execute($biblionumber,$biblioitemnumber);
716 my $row=$sth2->fetchrow_hashref;
718 foreach $code (keys %$row) {
720 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
725 # TODO : retrieve notes, additionalauthors
728 sub MARCkoha2marcItem {
729 # this function builds partial MARC::Record from the old koha-DB fields
730 my ($dbh,$biblionumber,$itemnumber) = @_;
731 # my $dbh=&C4Connect;
732 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
733 my $record = MARC::Record->new();
734 #--- if item, then retrieve old-style koha data
736 # print STDERR "prepare $biblionumber,$itemnumber\n";
737 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
738 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
739 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
740 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
742 WHERE itemnumber=?");
743 $sth2->execute($itemnumber);
744 my $row=$sth2->fetchrow_hashref;
746 foreach $code (keys %$row) {
748 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
753 # TODO : retrieve notes, additionalauthors
756 sub MARCkoha2marcSubtitle {
757 # this function builds partial MARC::Record from the old koha-DB fields
758 my ($dbh,$bibnum,$subtitle) = @_;
759 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
760 my $record = MARC::Record->new();
761 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
765 sub MARCkoha2marcOnefield {
766 my ($sth,$record,$kohafieldname,$value)=@_;
769 $sth->execute($kohafieldname);
770 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
771 if ($record->field($tagfield)) {
772 my $tag =$record->field($tagfield);
774 $tag->add_subfields($tagsubfield,$value);
775 $record->delete_field($tag);
776 $record->add_fields($tag);
779 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
786 my ($dbh,$record) = @_;
787 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
789 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
792 # print STDERR $record->as_formatted;
793 while (($field)=$sth2->fetchrow) {
794 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
796 # FIXME - There's already a $sth2 in this scope.
797 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
799 # FIXME - There's already a $field in this scope.
801 while (($field)=$sth2->fetchrow) {
802 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
804 # FIXME - There's already a $sth2 in this scope.
805 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
807 # FIXME - There's already a $field in this scope.
809 while (($field)=$sth2->fetchrow) {
810 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
812 # additional authors : specific
813 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
817 sub MARCmarc2kohaOneField {
818 # to check : if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
819 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
823 $sth->execute($kohatable.".".$kohafield);
824 ($tagfield,$subfield) = $sth->fetchrow;
825 foreach my $field ($record->field($tagfield)) {
826 if ($field->subfield($subfield)) {
827 if ($result->{$kohafield}) {
828 $result->{$kohafield} .= " | ".$field->subfield($subfield);
830 $result->{$kohafield}=$field->subfield($subfield);
838 # split a subfield string and adds it into the word table.
840 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
841 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
842 my @words = split / /,$sentence;
843 # build stopword list
844 # my $sth2 =$dbh->prepare("select word from stopwords");
848 # while(($stopword) = $sth2->fetchrow_array) {
849 # $stopwords->{$stopword} = $stopword;
851 my $stopwords= C4::Context->stopwords;
852 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
853 values (?,?,?,?,?,?,soundex(?))");
854 foreach my $word (@words) {
855 # we record only words longer than 2 car and not in stopwords hash
856 if (length($word)>1 and !($stopwords->{uc($word)})) {
857 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
859 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";
866 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
867 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
868 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
869 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
874 # ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL
877 # all the following subs are useful to manage MARC-DB with complete MARC records.
878 # it's used with marcimport, and marc management tools
883 all subs requires/use $dbh as 1st parameter.
884 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
888 =head2 (oldbibnum,$oldbibitemnum) = ALLnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
889 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
890 are builded from the MARC::Record. If they are passed, they are used.
892 =head2 ALLnewitem($dbh,$olditem);
893 adds an item in the db. $olditem is a old-db hash.
897 Paul POULAIN paul.poulain@free.fr
902 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
903 # note $oldbiblio and $oldbiblioitem are not mandatory.
904 # if not present, they will be builded from $record with MARCmarc2koha function
905 if (($oldbiblio) and not($oldbiblioitem)) {
906 print STDERR "ALLnewbiblio : missing parameter\n";
907 print "ALLnewbiblio : missing parameter : contact koha development team\n";
913 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
914 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
915 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
917 my $olddata = MARCmarc2koha($dbh,$record);
918 $oldbibnum = OLDnewbiblio($dbh,$olddata);
919 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
921 # we must add bibnum and bibitemnum in MARC::Record...
922 # we build the new field with biblionumber and biblioitemnumber
923 # we drop the original field
924 # we add the new builded field.
925 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
926 # (steve and paul : thinks 090 is a good choice)
927 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
928 $sth->execute("biblio.biblionumber");
929 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
930 $sth->execute("biblioitems.biblioitemnumber");
931 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
932 print STDERR "tag1 : $tagfield1 / $tagsubfield1\n tag2 : $tagfield2 / $tagsubfield2\n";
933 if ($tagsubfield1 != $tagsubfield2) {
934 print STDERR "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
935 print "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
938 my $newfield = MARC::Field->new( $tagfield1,'','',
939 "$tagsubfield1" => $oldbibnum,
940 "$tagsubfield2" => $oldbibitemnum);
941 # drop old field and create new one...
942 my $old_field = $record->field($tagfield1);
943 $record->delete_field($old_field);
944 $record->add_fields($newfield);
945 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
946 return ( $oldbibnum,$oldbibitemnum );
950 my ($dbh, $item) = @_;
953 ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{'barcode'});
954 # search MARC biblionumber
955 my $bibid=&MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{'biblionumber'});
957 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
958 $sth->execute($bibid);
959 my ($tagorder) = $sth->fetchrow;
962 # for each field, find MARC tag and subfield, and call the proper MARC sub
963 foreach my $itemkey (keys %$item) {
966 print STDERR "=============> $itemkey : ".$item->{$itemkey}."\n";
967 if ($itemkey eq "biblionumber" || $itemkey eq "biblioitemnumber") {
968 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"biblio.".$itemkey);
970 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"items.".$itemkey);
972 if ($tagfield && $item->{$itemkey} ne 'NULL') {
974 &MARCaddsubfield($dbh,
990 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
996 all subs requires/use $dbh as 1st parameter.
997 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
999 They all are the exact copy of 1.0/1.2 version of the sub
1000 without the OLD. The OLDxxx is called by the original xxx sub.
1001 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
1003 WARNING : there is 1 difference between initialxxx and OLDxxx :
1004 the db header $dbh is always passed as parameter
1005 to avoid over-DB connexion
1009 =head2 $biblionumber = OLDnewbiblio($dbh,$biblio);
1010 adds a record in biblio table. Datas are in the hash $biblio.
1012 =head2 $biblionumber = OLDmodbiblio($dbh,$biblio);
1013 modify a record in biblio table. Datas are in the hash $biblio.
1015 =head2 OLDmodsubtitle($dbh,$bibnum,$subtitle);
1016 modify subtitles in bibliosubtitle table.
1018 =head2 OLDmodaddauthor($dbh,$bibnum,$author);
1019 adds or modify additional authors
1020 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1022 =head2 $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1023 modify/adds subjects
1025 =head2 OLDmodbibitem($dbh, $biblioitem);
1028 =head2 OLDmodnote($dbh,$bibitemnum,$note
1029 modify a note for a biblioitem
1031 =head2 OLDnewbiblioitem($dbh,$biblioitem);
1032 adds a biblioitem ($biblioitem is a hash with the values)
1034 =head2 OLDnewsubject($dbh,$bibnum);
1036 =head2 OLDnewsubtitle($dbh,$bibnum,$subtitle);
1037 create a new subtitle
1039 =head2 ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1040 create a item. $item is a hash and $barcode the barcode.
1042 =head2 OLDmoditem($dbh,$item);
1045 =head2 OLDdelitem($dbh,$itemnum);
1048 =head2 OLDdeletebiblioitem($dbh,$biblioitemnumber);
1049 deletes a biblioitem
1050 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1052 =head2 OLDdelbiblio($dbh,$biblio);
1057 Paul POULAIN paul.poulain@free.fr
1062 my ($dbh,$biblio) = @_;
1063 # my $dbh = &C4Connect;
1064 my $query = "Select max(biblionumber) from biblio";
1065 my $sth = $dbh->prepare($query);
1067 my $data = $sth->fetchrow_arrayref;
1068 my $bibnum = $$data[0] + 1;
1071 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1072 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1073 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
1074 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
1075 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1076 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1077 if ($biblio->{'seriestitle'}) { $series = 1 };
1080 $query = "insert into biblio set
1081 biblionumber = $bibnum,
1082 title = $biblio->{'title'},
1083 author = $biblio->{'author'},
1084 copyrightdate = $biblio->{'copyright'},
1086 seriestitle = $biblio->{'seriestitle'},
1087 notes = $biblio->{'notes'},
1088 abstract = $biblio->{'abstract'}";
1090 $sth = $dbh->prepare($query);
1099 my ($dbh,$biblio) = @_;
1100 # my $dbh = C4Connect;
1104 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1105 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1106 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1107 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
1108 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
1109 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
1110 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
1111 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1113 $query = "Update biblio set
1114 title = $biblio->{'title'},
1115 author = $biblio->{'author'},
1116 abstract = $biblio->{'abstract'},
1117 copyrightdate = $biblio->{'copyrightdate'},
1118 seriestitle = $biblio->{'seriestitle'},
1119 serial = $biblio->{'serial'},
1120 unititle = $biblio->{'unititle'},
1121 notes = $biblio->{'notes'}
1122 where biblionumber = $biblio->{'biblionumber'}";
1123 $sth = $dbh->prepare($query);
1128 return($biblio->{'biblionumber'});
1131 sub OLDmodsubtitle {
1132 my ($dbh,$bibnum, $subtitle) = @_;
1133 # my $dbh = C4Connect;
1134 my $query = "update bibliosubtitle set
1135 subtitle = '$subtitle'
1136 where biblionumber = $bibnum";
1137 my $sth = $dbh->prepare($query);
1145 sub OLDmodaddauthor {
1146 my ($dbh,$bibnum, $author) = @_;
1147 # my $dbh = C4Connect;
1148 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1149 my $sth = $dbh->prepare($query);
1154 if ($author ne '') {
1155 $query = "Insert into additionalauthors set
1157 biblionumber = '$bibnum'";
1158 $sth = $dbh->prepare($query);
1164 } # sub modaddauthor
1168 my ($dbh,$bibnum, $force, @subject) = @_;
1169 # my $dbh = C4Connect;
1170 my $count = @subject;
1172 for (my $i = 0; $i < $count; $i++) {
1173 $subject[$i] =~ s/^ //g;
1174 $subject[$i] =~ s/ $//g;
1175 my $query = "select * from catalogueentry
1176 where entrytype = 's'
1177 and catalogueentry = '$subject[$i]'";
1178 my $sth = $dbh->prepare($query);
1181 if (my $data = $sth->fetchrow_hashref) {
1183 if ($force eq $subject[$i]) {
1184 # subject not in aut, chosen to force anway
1185 # so insert into cataloguentry so its in auth file
1186 $query = "Insert into catalogueentry
1187 (entrytype,catalogueentry)
1188 values ('s','$subject[$i]')";
1189 my $sth2 = $dbh->prepare($query);
1194 $error = "$subject[$i]\n does not exist in the subject authority file";
1195 $query = "Select * from catalogueentry
1196 where entrytype = 's'
1197 and (catalogueentry like '$subject[$i] %'
1198 or catalogueentry like '% $subject[$i] %'
1199 or catalogueentry like '% $subject[$i]')";
1200 my $sth2 = $dbh->prepare($query);
1203 while (my $data = $sth2->fetchrow_hashref) {
1204 $error = $error."<br>$data->{'catalogueentry'}";
1212 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1213 my $sth = $dbh->prepare($query);
1216 for (my $i = 0; $i < $count; $i++) {
1217 $sth = $dbh->prepare("Insert into bibliosubject
1218 values ('$subject[$i]', $bibnum)");
1230 my ($dbh,$biblioitem) = @_;
1231 # my $dbh = C4Connect;
1234 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1235 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1236 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1237 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1238 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1239 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1240 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1241 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1242 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1243 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1244 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1245 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1246 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1247 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1249 $query = "Update biblioitems set
1250 itemtype = $biblioitem->{'itemtype'},
1251 url = $biblioitem->{'url'},
1252 isbn = $biblioitem->{'isbn'},
1253 publishercode = $biblioitem->{'publishercode'},
1254 publicationyear = $biblioitem->{'publicationyear'},
1255 classification = $biblioitem->{'classification'},
1256 dewey = $biblioitem->{'dewey'},
1257 subclass = $biblioitem->{'subclass'},
1258 illus = $biblioitem->{'illus'},
1259 pages = $biblioitem->{'pages'},
1260 volumeddesc = $biblioitem->{'volumeddesc'},
1261 notes = $biblioitem->{'notes'},
1262 size = $biblioitem->{'size'},
1263 place = $biblioitem->{'place'}
1264 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1272 my ($dbh,$bibitemnum,$note)=@_;
1273 # my $dbh=C4Connect;
1274 my $query="update biblioitems set notes='$note' where
1275 biblioitemnumber='$bibitemnum'";
1276 my $sth=$dbh->prepare($query);
1282 sub OLDnewbiblioitem {
1283 my ($dbh,$biblioitem) = @_;
1284 # my $dbh = C4Connect;
1285 my $query = "Select max(biblioitemnumber) from biblioitems";
1286 my $sth = $dbh->prepare($query);
1290 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
1291 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
1292 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1293 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1294 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1295 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1296 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
1297 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1298 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1299 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1300 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1301 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
1302 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1303 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1304 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1305 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1306 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1307 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1308 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
1309 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
1312 $data = $sth->fetchrow_arrayref;
1313 $bibitemnum = $$data[0] + 1;
1317 $query = "insert into biblioitems set
1318 biblioitemnumber = $bibitemnum,
1319 biblionumber = $biblioitem->{'biblionumber'},
1320 volume = $biblioitem->{'volume'},
1321 number = $biblioitem->{'number'},
1322 classification = $biblioitem->{'classification'},
1323 itemtype = $biblioitem->{'itemtype'},
1324 url = $biblioitem->{'url'},
1325 isbn = $biblioitem->{'isbn'},
1326 issn = $biblioitem->{'issn'},
1327 dewey = $biblioitem->{'dewey'},
1328 subclass = $biblioitem->{'subclass'},
1329 publicationyear = $biblioitem->{'publicationyear'},
1330 publishercode = $biblioitem->{'publishercode'},
1331 volumedate = $biblioitem->{'volumedate'},
1332 volumeddesc = $biblioitem->{'volumeddesc'},
1333 illus = $biblioitem->{'illus'},
1334 pages = $biblioitem->{'pages'},
1335 notes = $biblioitem->{'notes'},
1336 size = $biblioitem->{'size'},
1337 lccn = $biblioitem->{'lccn'},
1338 marc = $biblioitem->{'marc'},
1339 place = $biblioitem->{'place'}";
1341 $sth = $dbh->prepare($query);
1345 return($bibitemnum);
1349 my ($dbh,$bibnum)=@_;
1350 # my $dbh=C4Connect;
1351 my $query="insert into bibliosubject (biblionumber) values
1353 my $sth=$dbh->prepare($query);
1360 sub OLDnewsubtitle {
1361 my ($dbh,$bibnum, $subtitle) = @_;
1362 # my $dbh = C4Connect;
1363 $subtitle = $dbh->quote($subtitle);
1364 my $query = "insert into bibliosubtitle set
1365 biblionumber = $bibnum,
1366 subtitle = $subtitle";
1367 my $sth = $dbh->prepare($query);
1377 my ($dbh,$item, $barcode) = @_;
1378 # my $dbh = C4Connect;
1379 my $query = "Select max(itemnumber) from items";
1380 my $sth = $dbh->prepare($query);
1386 $data = $sth->fetchrow_hashref;
1387 $itemnumber = $data->{'max(itemnumber)'} + 1;
1390 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
1391 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
1392 $item->{'price'} = $dbh->quote($item->{'price'});
1393 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
1394 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
1396 # foreach my $barcode (@barcodes) {
1397 # $barcode = uc($barcode);
1398 $barcode = $dbh->quote($barcode);
1399 $query = "Insert into items set
1400 itemnumber = $itemnumber,
1401 biblionumber = $item->{'biblionumber'},
1402 biblioitemnumber = $item->{'biblioitemnumber'},
1404 booksellerid = $item->{'booksellerid'},
1405 dateaccessioned = NOW(),
1406 homebranch = $item->{'homebranch'},
1407 holdingbranch = $item->{'homebranch'},
1408 price = $item->{'price'},
1409 replacementprice = $item->{'replacementprice'},
1410 replacementpricedate = NOW(),
1411 itemnotes = $item->{'itemnotes'}";
1412 if ($item->{'loan'}) {
1413 $query .= ",notforloan = $item->{'loan'}";
1416 $sth = $dbh->prepare($query);
1418 if (defined $sth->errstr) {
1419 $error .= $sth->errstr;
1424 return($itemnumber,$error);
1428 my ($dbh,$item) = @_;
1429 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1430 # my $dbh=C4Connect;
1431 my $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1432 barcode='$item->{'barcode'}',itemnotes='$item->{'notes'}'
1433 where itemnumber=$item->{'itemnum'}";
1434 if ($item->{'barcode'} eq ''){
1435 $query="update items set biblioitemnumber=$item->{'bibitemnum'},notforloan=$item->{'loan'} where itemnumber=$item->{'itemnum'}";
1437 if ($item->{'lost'} ne ''){
1438 $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1439 barcode='$item->{'barcode'}',
1440 itemnotes='$item->{'notes'}',
1441 homebranch='$item->{'homebranch'}',
1442 itemlost='$item->{'lost'}',
1443 wthdrawn='$item->{'wthdrawn'}'
1444 where itemnumber=$item->{'itemnum'}";
1446 if ($item->{'replacement'} ne ''){
1447 $query=~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1450 my $sth=$dbh->prepare($query);
1456 # FIXME - A nearly-identical function, &delitem, appears in
1459 my ($dbh,$itemnum)=@_;
1460 # my $dbh=C4Connect;
1461 my $query="select * from items where itemnumber=$itemnum";
1462 my $sth=$dbh->prepare($query);
1464 my @data=$sth->fetchrow_array;
1466 $query="Insert into deleteditems values (";
1467 foreach my $temp (@data){
1468 $query=$query."'$temp',";
1472 $sth=$dbh->prepare($query);
1475 $query = "Delete from items where itemnumber=$itemnum";
1476 $sth=$dbh->prepare($query);
1482 sub OLDdeletebiblioitem {
1483 my ($dbh,$biblioitemnumber) = @_;
1484 # my $dbh = C4Connect;
1485 my $query = "Select * from biblioitems
1486 where biblioitemnumber = $biblioitemnumber";
1487 my $sth = $dbh->prepare($query);
1492 if (@results = $sth->fetchrow_array) {
1493 $query = "Insert into deletedbiblioitems values (";
1494 foreach my $value (@results) {
1495 $value = $dbh->quote($value);
1496 $query .= "$value,";
1499 $query =~ s/\,$/\)/;
1502 $query = "Delete from biblioitems
1503 where biblioitemnumber = $biblioitemnumber";
1507 # Now delete all the items attached to the biblioitem
1508 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1509 $sth = $dbh->prepare($query);
1511 while (@results = $sth->fetchrow_array) {
1512 $query = "Insert into deleteditems values (";
1513 foreach my $value (@results) {
1514 $value = $dbh->quote($value);
1515 $query .= "$value,";
1517 $query =~ s/\,$/\)/;
1521 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1524 } # sub deletebiblioitem
1527 my ($dbh,$biblio)=@_;
1528 # my $dbh=C4Connect;
1529 my $query="select * from biblio where biblionumber=$biblio";
1530 my $sth=$dbh->prepare($query);
1532 if (my @data=$sth->fetchrow_array){
1534 $query="Insert into deletedbiblio values (";
1535 foreach my $temp (@data){
1536 $temp=~ s/\'/\\\'/g;
1537 $query=$query."'$temp',";
1541 $sth=$dbh->prepare($query);
1544 $query = "Delete from biblio where biblionumber=$biblio";
1545 $sth=$dbh->prepare($query);
1559 # FIXME - This is the same as &C4::Acquisitions::itemcount, but not
1560 # the same as &C4::Search::itemcount
1561 # Since they're both exported, acqui/acquire.pl doesn't compile with -w.
1564 my $dbh = C4::Context->dbh;
1565 my $query="Select count(*) from items where biblionumber=$biblio";
1567 my $sth=$dbh->prepare($query);
1569 my $data=$sth->fetchrow_hashref;
1571 return($data->{'count(*)'});
1576 my $dbh = C4::Context->dbh;
1577 my $query="Select ordernumber
1579 where biblionumber=? and biblioitemnumber=?";
1580 my $sth=$dbh->prepare($query);
1581 $sth->execute($bib,$bi);
1582 my $ordnum=$sth->fetchrow_hashref;
1584 my $order=getsingleorder($ordnum->{'ordernumber'});
1586 return ($order,$ordnum->{'ordernumber'});
1589 # FIXME - This is practically the same function as
1590 # &C4::Acquisitions::getsingleorder and &C4::Catalogue::getsingleorder
1591 sub getsingleorder {
1593 my $dbh = C4::Context->dbh;
1594 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1595 where aqorders.ordernumber=?
1596 and biblio.biblionumber=aqorders.biblionumber and
1597 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1598 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1599 my $sth=$dbh->prepare($query);
1600 $sth->execute($ordnum);
1601 my $data=$sth->fetchrow_hashref;
1606 # FIXME - This is in effect identical to &C4::Acquisitions::newbiblio.
1607 # Pick one and stick with it.
1610 my $dbh = C4::Context->dbh;
1611 my $bibnum=OLDnewbiblio($dbh,$biblio);
1616 # FIXME - This is in effect the same as &C4::Acquisitions::modbiblio.
1617 # Pick one and stick with it.
1620 my $dbh = C4::Context->dbh;
1621 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1622 return($biblionumber);
1625 # FIXME - This is in effect identical to &C4::Acquisitions::modsubtitle.
1626 # Pick one and stick with it.
1628 my ($bibnum, $subtitle) = @_;
1629 my $dbh = C4::Context->dbh;
1630 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1634 # FIXME - This is functionally identical to
1635 # &C4::Acquisitions::modaddauthor
1636 # Pick one and stick with it.
1638 my ($bibnum, $author) = @_;
1639 my $dbh = C4::Context->dbh;
1640 &OLDmodaddauthor($dbh,$bibnum,$author);
1641 } # sub modaddauthor
1644 # FIXME - This is in effect identical to &C4::Acquisitions::modsubject.
1645 # Pick one and stick with it.
1647 my ($bibnum, $force, @subject) = @_;
1648 my $dbh = C4::Context->dbh;
1649 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1653 # FIXME - This is very similar to &C4::Acquisitions::modbibitem.
1654 # Pick one and stick with it.
1656 my ($biblioitem) = @_;
1657 my $dbh = C4::Context->dbh;
1658 &OLDmodbibitem($dbh,$biblioitem);
1659 my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
1660 &MARCmodbiblio($dbh,$biblioitem->{biblionumber},0,$MARCbibitem);
1663 # FIXME - This is in effect identical to &C4::Acquisitions::modnote.
1664 # Pick one and stick with it.
1666 my ($bibitemnum,$note)=@_;
1667 my $dbh = C4::Context->dbh;
1668 &OLDmodnote($dbh,$bibitemnum,$note);
1671 # FIXME - This is quite similar in effect to &C4::newbiblioitem,
1672 # except for the MARC stuff. There's also a &newbiblioitem in
1673 # acqui.simple/addbookslccn.pl
1675 my ($biblioitem) = @_;
1676 my $dbh = C4::Context->dbh;
1677 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1678 # print STDERR "bibitemnum : $bibitemnum\n";
1679 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1680 # print STDERR $MARCbiblio->as_formatted();
1681 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1682 return($bibitemnum);
1685 # FIXME - This is in effect identical to &C4::Acquisitions::newsubject.
1686 # Pick one and stick with it.
1689 my $dbh = C4::Context->dbh;
1690 &OLDnewsubject($dbh,$bibnum);
1693 # FIXME - This is just a wrapper around &OLDnewsubtitle
1694 # FIXME - This is in effect the same as &C4::Acquisitions::newsubtitle
1696 my ($bibnum, $subtitle) = @_;
1697 my $dbh = C4::Context->dbh;
1698 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1701 # FIXME - This is different from &C4::Acquisitions::newitems, though
1702 # both are exported.
1704 my ($item, @barcodes) = @_;
1705 my $dbh = C4::Context->dbh;
1709 foreach my $barcode (@barcodes) {
1710 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1712 # print STDERR "biblionumber : $item->{biblionumber} / MARCbibid : $MARCbibid / itemnumber : $itemnumber\n";
1713 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1714 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1715 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1716 # print STDERR "MARCmodbiblio called\n";
1721 # FIXME - This appears to be functionally equivalent to
1722 # &C4::Acquisitions::moditem.
1723 # Pick one and stick with it.
1726 # my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1727 my $dbh = C4::Context->dbh;
1728 &OLDmoditem($dbh,$item);
1729 warn "biblionumber : $item->{'biblionumber'} / $item->{'itemnum'}\n";
1730 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1731 warn "before MARCmoditem : $item->{biblionumber}, $item->{'itemnum'}\n";
1732 warn $MARCitem->as_formatted();
1733 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1734 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1735 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1738 # FIXME - This is the same as &C4::Acquisitions::Checkitems.
1739 # Pick one and stick with it.
1741 my ($count,@barcodes)=@_;
1742 my $dbh = C4::Context->dbh;
1744 for (my $i=0;$i<$count;$i++){
1745 $barcodes[$i]=uc $barcodes[$i];
1746 my $query="Select * from items where barcode='$barcodes[$i]'";
1747 my $sth=$dbh->prepare($query);
1749 if (my $data=$sth->fetchrow_hashref){
1750 $error.=" Duplicate Barcode: $barcodes[$i]";
1757 # FIXME - This is identical to &C4::Acquisitions::countitems.
1758 # Pick one and stick with it.
1760 my ($bibitemnum)=@_;
1761 my $dbh = C4::Context->dbh;
1762 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1763 my $sth=$dbh->prepare($query);
1765 my $data=$sth->fetchrow_hashref;
1767 return($data->{'count(*)'});
1770 # FIXME - This is just a wrapper around &OLDdelitem, and acts
1771 # identically to &C4::Acquisitions::delitem
1772 # Pick one and stick with it.
1775 my $dbh = C4::Context->dbh;
1776 &OLDdelitem($dbh,$itemnum);
1779 # FIXME - This is functionally identical to
1780 # &C4::Acquisitions::deletebiblioitem.
1781 # Pick one and stick with it.
1782 sub deletebiblioitem {
1783 my ($biblioitemnumber) = @_;
1784 my $dbh = C4::Context->dbh;
1785 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1786 } # sub deletebiblioitem
1789 # FIXME - This is functionally identical to &C4::Acquisitions::delbiblio.
1790 # Pick one and stick with it.
1793 my $dbh = C4::Context->dbh;
1794 &OLDdelbiblio($dbh,$biblio);
1797 # FIXME - This is identical to &C4::Acquisitions::getitemtypes.
1798 # Pick one and stick with it.
1800 my $dbh = C4::Context->dbh;
1801 my $query = "select * from itemtypes";
1802 my $sth = $dbh->prepare($query);
1803 # || die "Cannot prepare $query" . $dbh->errstr;
1808 # || die "Cannot execute $query\n" . $sth->errstr;
1809 while (my $data = $sth->fetchrow_hashref) {
1810 $results[$count] = $data;
1815 return($count, @results);
1816 } # sub getitemtypes
1819 my ($biblionumber) = @_;
1820 my $dbh = C4::Context->dbh;
1821 my $query = "Select * from biblio where biblionumber = $biblionumber";
1822 my $sth = $dbh->prepare($query);
1823 # || die "Cannot prepare $query\n" . $dbh->errstr;
1828 # || die "Cannot execute $query\n" . $sth->errstr;
1829 while (my $data = $sth->fetchrow_hashref) {
1830 $results[$count] = $data;
1835 return($count, @results);
1838 # FIXME - This is identical to &C4::Acquisitions::getbiblioitem.
1839 # Pick one and stick with it.
1841 my ($biblioitemnum) = @_;
1842 my $dbh = C4::Context->dbh;
1843 my $query = "Select * from biblioitems where
1844 biblioitemnumber = $biblioitemnum";
1845 my $sth = $dbh->prepare($query);
1851 while (my $data = $sth->fetchrow_hashref) {
1852 $results[$count] = $data;
1857 return($count, @results);
1858 } # sub getbiblioitem
1860 # FIXME - This is identical to
1861 # &C4::Acquisitions::getbiblioitembybiblionumber.
1862 # Pick one and stick with it.
1863 sub getbiblioitembybiblionumber {
1864 my ($biblionumber) = @_;
1865 my $dbh = C4::Context->dbh;
1866 my $query = "Select * from biblioitems where biblionumber =
1868 my $sth = $dbh->prepare($query);
1874 while (my $data = $sth->fetchrow_hashref) {
1875 $results[$count] = $data;
1880 return($count, @results);
1883 # FIXME - This is identical to
1884 # &C4::Acquisitions::getbiblioitembybiblionumber.
1885 # Pick one and stick with it.
1886 sub getitemsbybiblioitem {
1887 my ($biblioitemnum) = @_;
1888 my $dbh = C4::Context->dbh;
1889 my $query = "Select * from items, biblio where
1890 biblio.biblionumber = items.biblionumber and biblioitemnumber
1892 my $sth = $dbh->prepare($query);
1893 # || die "Cannot prepare $query\n" . $dbh->errstr;
1898 # || die "Cannot execute $query\n" . $sth->errstr;
1899 while (my $data = $sth->fetchrow_hashref) {
1900 $results[$count] = $data;
1905 return($count, @results);
1906 } # sub getitemsbybiblioitem
1908 # FIXME - This is identical to &C4::Acquisitions::isbnsearch.
1909 # Pick one and stick with it.
1912 my $dbh = C4::Context->dbh;
1918 $isbn = $dbh->quote($isbn);
1919 $query = "Select biblio.* from biblio, biblioitems where
1920 biblio.biblionumber = biblioitems.biblionumber
1922 $sth = $dbh->prepare($query);
1925 while (my $data = $sth->fetchrow_hashref) {
1926 $results[$count] = $data;
1931 return($count, @results);
1935 # At the moment this is just a straight copy of the subject code. Needs heavy
1936 # modification to work for additional authors, obviously.
1937 # Check for additional author changes
1939 # my $newadditionalauthor='';
1940 # my $additionalauthors;
1941 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
1942 # $additionalauthors->{$newadditionalauthor}=1;
1943 # if ($origadditionalauthors->{$newadditionalauthor}) {
1944 # $additionalauthors->{$newadditionalauthor}=2;
1946 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
1947 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
1949 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
1951 # $subfields->{1}->{'Subfield_Mark'}='a';
1952 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
1955 # foreach $Record_ID (@marcrecords) {
1956 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1957 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
1961 # my $origadditionalauthor;
1962 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
1963 # if ($additionalauthors->{$origadditionalauthor} == 1) {
1964 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
1965 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
1966 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
1976 # Subroutine to log changes to databases
1977 # Eventually, this subroutine will be used to create a log of all changes made,
1978 # with the possibility of "undo"ing some changes
1980 if ($database eq 'kohadb') {
1986 print STDERR "KOHA: $type $section $item $original $new\n";
1987 } elsif ($database eq 'marc') {
1989 my $Record_ID=shift;
1992 my $subfield_ID=shift;
1995 print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
1999 #------------------------------------------------
2002 #---------------------------------------
2003 # Find a biblio entry, or create a new one if it doesn't exist.
2004 # If a "subtitle" entry is in hash, add it to subtitle table
2005 sub getoraddbiblio {
2009 $biblio, # hash ref to fields
2020 requireDBI($dbh,"getoraddbiblio");
2022 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2023 $sth=$dbh->prepare("select biblionumber
2025 where title=? and author=?
2026 and copyrightdate=? and seriestitle=?");
2028 $biblio->{title}, $biblio->{author},
2029 $biblio->{copyright}, $biblio->{seriestitle} );
2031 ($biblionumber) = $sth->fetchrow;
2032 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2034 # Doesn't exist. Add new one.
2035 print "<PRE>Adding biblio</PRE>\n" if $debug;
2036 ($biblionumber,$error)=&newbiblio($biblio);
2037 if ( $biblionumber ) {
2038 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
2039 if ( $biblio->{subtitle} ) {
2040 &newsubtitle($biblionumber,$biblio->{subtitle} );
2043 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2047 return $biblionumber,$error;
2049 } # sub getoraddbiblio
2053 # UNUSEFUL SUBs. Could be deleted, kept only until beta test
2054 # maybe useful for some MARC tricks steve used.
2057 sub OLD_MAYBE_DELETED_newBiblioItem {
2058 my ($env, $biblioitem) = @_;
2059 my $dbh = C4::Context->dbh;
2060 my $biblionumber=$biblioitem->{'biblionumber'};
2061 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2062 my $volume=$biblioitem->{'volume'};
2063 my $q_volume=$dbh->quote($volume);
2064 my $number=$biblioitem->{'number'};
2065 my $q_number=$dbh->quote($number);
2066 my $classification=$biblioitem->{'classification'};
2067 my $q_classification=$dbh->quote($classification);
2068 my $itemtype=$biblioitem->{'itemtype'};
2069 my $q_itemtype=$dbh->quote($itemtype);
2070 my $isbn=$biblioitem->{'isbn'};
2071 my $q_isbn=$dbh->quote($isbn);
2072 my $issn=$biblioitem->{'issn'};
2073 my $q_issn=$dbh->quote($issn);
2074 my $dewey=$biblioitem->{'dewey'};
2076 ($dewey == 0) && ($dewey='');
2077 my $subclass=$biblioitem->{'subclass'};
2078 my $q_subclass=$dbh->quote($subclass);
2079 my $publicationyear=$biblioitem->{'publicationyear'};
2080 my $publishercode=$biblioitem->{'publishercode'};
2081 my $q_publishercode=$dbh->quote($publishercode);
2082 my $volumedate=$biblioitem->{'volumedate'};
2083 my $q_volumedate=$dbh->quote($volumedate);
2084 my $illus=$biblioitem->{'illus'};
2085 my $q_illus=$dbh->quote($illus);
2086 my $pages=$biblioitem->{'pages'};
2087 my $q_pages=$dbh->quote($pages);
2088 my $notes=$biblioitem->{'notes'};
2089 my $q_notes=$dbh->quote($notes);
2090 my $size=$biblioitem->{'size'};
2091 my $q_size=$dbh->quote($size);
2092 my $place=$biblioitem->{'place'};
2093 my $q_place=$dbh->quote($place);
2094 my $lccn=$biblioitem->{'lccn'};
2095 my $q_lccn=$dbh->quote($lccn);
2098 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
2101 unless ($env->{'marconly'}) {
2102 #my $sth=$dbh->prepare("lock tables biblioitems write");
2104 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
2106 my ($biblioitemnumber) =$sth->fetchrow;
2107 $biblioitemnumber++;
2108 $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)");
2110 #my $sth=$dbh->prepare("unlock tables");
2115 # Should we check if there is already a biblioitem/amrc with the
2116 # same isbn/lccn/issn?
2118 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
2120 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
2121 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2123 my ($subtitle) = $sth->fetchrow;
2124 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2126 my @additionalauthors;
2127 while (my ($additionalauthor) = $sth->fetchrow) {
2128 push (@additionalauthors, $additionalauthor);
2130 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2133 while (my ($subject) = $sth->fetchrow) {
2134 push (@subjects, $subject);
2139 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
2141 my $Resource_ID=$dbh->{'mysql_insertid'};
2142 my $Record_ID=$Resource_ID;
2143 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
2149 $subfields->{1}->{'Subfield_Mark'}='a';
2150 $subfields->{1}->{'Subfield_Value'}=$title;
2152 $subfields->{2}->{'Subfield_Mark'}='b';
2153 $subfields->{2}->{'Subfield_Value'}=$subtitle;
2156 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2162 $subfields->{1}->{'Subfield_Mark'}='a';
2163 $subfields->{1}->{'Subfield_Value'}=$author;
2165 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2170 $subfields->{1}->{'Subfield_Mark'}='a';
2171 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
2173 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2178 $subfields->{1}->{'Subfield_Mark'}='a';
2179 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
2180 $subfields->{2}->{'Subfield_Mark'}='3';
2181 $subfields->{2}->{'Subfield_Value'}='biblio';
2183 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2185 # Additional Authors
2186 foreach (@additionalauthors) {
2188 (next) unless ($author);
2190 $subfields->{1}->{'Subfield_Mark'}='a';
2191 $subfields->{1}->{'Subfield_Value'}=$author;
2192 $subfields->{2}->{'Subfield_Mark'}='e';
2193 $subfields->{2}->{'Subfield_Value'}='author';
2195 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2199 (next) unless ($illus);
2201 $subfields->{1}->{'Subfield_Mark'}='a';
2202 $subfields->{1}->{'Subfield_Value'}=$illus;
2203 $subfields->{2}->{'Subfield_Mark'}='e';
2204 $subfields->{2}->{'Subfield_Value'}='illustrator';
2206 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2209 foreach (@subjects) {
2211 (next) unless ($subject);
2213 $subfields->{1}->{'Subfield_Mark'}='a';
2214 $subfields->{1}->{'Subfield_Value'}=$subject;
2216 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2223 $subfields->{1}->{'Subfield_Mark'}='a';
2224 $subfields->{1}->{'Subfield_Value'}=$isbn;
2226 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2231 $subfields->{1}->{'Subfield_Mark'}='a';
2232 $subfields->{1}->{'Subfield_Value'}=$lccn;
2234 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2239 $subfields->{1}->{'Subfield_Mark'}='a';
2240 $subfields->{1}->{'Subfield_Value'}=$issn;
2242 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2247 $subfields->{1}->{'Subfield_Mark'}='a';
2248 $subfields->{1}->{'Subfield_Value'}=$dewey;
2250 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2252 # DEWEY subclass and itemtype
2255 $subfields->{1}->{'Subfield_Mark'}='a';
2256 $subfields->{1}->{'Subfield_Value'}=$itemtype;
2257 $subfields->{2}->{'Subfield_Mark'}='b';
2258 $subfields->{2}->{'Subfield_Value'}=$subclass;
2259 $subfields->{3}->{'Subfield_Mark'}='c';
2260 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
2261 $subfields->{4}->{'Subfield_Mark'}='d';
2262 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
2264 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2269 $subfields->{1}->{'Subfield_Mark'}='a';
2270 $subfields->{1}->{'Subfield_Value'}=$place;
2271 $subfields->{2}->{'Subfield_Mark'}='b';
2272 $subfields->{2}->{'Subfield_Value'}=$publishercode;
2273 $subfields->{3}->{'Subfield_Mark'}='c';
2274 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
2275 if ($copyrightdate) {
2276 $subfields->{4}->{'Subfield_Mark'}='c';
2277 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
2280 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2283 if ($pages || $size) {
2285 $subfields->{1}->{'Subfield_Mark'}='a';
2286 $subfields->{1}->{'Subfield_Value'}=$pages;
2287 $subfields->{2}->{'Subfield_Mark'}='c';
2288 $subfields->{2}->{'Subfield_Value'}=$size;
2290 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2293 if ($volume || $number) {
2295 $subfields->{1}->{'Subfield_Mark'}='v';
2296 $subfields->{1}->{'Subfield_Value'}=$volume;
2297 $subfields->{2}->{'Subfield_Mark'}='n';
2298 $subfields->{2}->{'Subfield_Value'}=$number;
2300 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2305 $subfields->{1}->{'Subfield_Mark'}='a';
2306 $subfields->{1}->{'Subfield_Value'}=$notes;
2307 $subfields->{2}->{'Subfield_Mark'}='3';
2308 $subfields->{2}->{'Subfield_Value'}='biblioitem';
2310 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2313 return ($env, $Record_ID);
2316 sub OLD_MAYBE_DELETED_newItem {
2317 my ($env, $Record_ID, $item) = @_;
2318 my $dbh = C4::Context->dbh;
2319 my $barcode=$item->{'barcode'};
2320 my $q_barcode=$dbh->quote($barcode);
2321 my $biblionumber=$item->{'biblionumber'};
2322 my $biblioitemnumber=$item->{'biblioitemnumber'};
2323 my $dateaccessioned=$item->{'dateaccessioned'};
2324 my $booksellerid=$item->{'booksellerid'};
2325 my $q_booksellerid=$dbh->quote($booksellerid);
2326 my $homebranch=$item->{'homebranch'};
2327 my $q_homebranch=$dbh->quote($homebranch);
2328 my $holdingbranch=$item->{'holdingbranch'};
2329 my $price=$item->{'price'};
2330 my $replacementprice=$item->{'replacementprice'};
2331 my $replacementpricedate=$item->{'replacementpricedate'};
2332 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
2333 my $notforloan=$item->{'notforloan'};
2334 my $itemlost=$item->{'itemlost'};
2335 my $wthdrawn=$item->{'wthdrawn'};
2336 my $restricted=$item->{'restricted'};
2337 my $itemnotes=$item->{'itemnotes'};
2338 my $q_itemnotes=$dbh->quote($itemnotes);
2339 my $itemtype=$item->{'itemtype'};
2340 my $subclass=$item->{'subclass'};
2344 unless ($env->{'marconly'}) {
2345 my $sth=$dbh->prepare("select max(itemnumber) from items");
2347 my ($itemnumber) =$sth->fetchrow;
2349 $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)");
2356 $subfields->{1}->{'Subfield_Mark'}='p';
2357 $subfields->{1}->{'Subfield_Value'}=$barcode;
2358 $subfields->{2}->{'Subfield_Mark'}='d';
2359 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
2360 $subfields->{3}->{'Subfield_Mark'}='e';
2361 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
2362 $subfields->{4}->{'Subfield_Mark'}='b';
2363 $subfields->{4}->{'Subfield_Value'}=$homebranch;
2364 $subfields->{5}->{'Subfield_Mark'}='l';
2365 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
2366 $subfields->{6}->{'Subfield_Mark'}='c';
2367 $subfields->{6}->{'Subfield_Value'}=$price;
2368 $subfields->{7}->{'Subfield_Mark'}='c';
2369 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
2370 $subfields->{8}->{'Subfield_Mark'}='d';
2371 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
2373 $subfields->{9}->{'Subfield_Mark'}='h';
2374 $subfields->{9}->{'Subfield_Value'}='Not for loan';
2377 $subfields->{10}->{'Subfield_Mark'}='j';
2378 $subfields->{10}->{'Subfield_Value'}='Item lost';
2381 $subfields->{11}->{'Subfield_Mark'}='j';
2382 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
2385 $subfields->{12}->{'Subfield_Mark'}='z';
2386 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
2390 $env->{'linkage'}=1;
2391 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2392 $env->{'linkage'}=0;
2393 $env->{'linkid'}=$Tag_ID;
2396 $subfields2->{1}->{'Subfield_Mark'}='a';
2397 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
2398 $subfields2->{1}->{'Subfield_Mark'}='b';
2399 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
2400 $subfields2->{1}->{'Subfield_Mark'}='c';
2401 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
2402 $subfields2->{2}->{'Subfield_Mark'}='m';
2403 $subfields2->{2}->{'Subfield_Value'}=$subclass;
2404 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
2405 $env->{'linkid'}='';
2408 sub OLD_MAYBE_DELETED_updateBiblio {
2409 # Update the biblio with biblionumber $biblio->{'biblionumber'}
2410 # I guess this routine should search through all marc records for a record that
2411 # has the same biblionumber stored in it, and modify the MARC record as well as
2414 # Also, this subroutine should search through the $biblio object and compare it
2415 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
2416 # this logging feature to be usable to undo changes easily.
2418 my ($env, $biblio) = @_;
2420 my $biblionumber=$biblio->{'biblionumber'};
2421 my $dbh = C4::Context->dbh;
2422 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
2424 my $origbiblio=$sth->fetchrow_hashref;
2425 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2427 my ($subtitle)=$sth->fetchrow;
2428 $origbiblio->{'subtitle'}=$subtitle;
2429 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2431 my $origadditionalauthors;
2432 while (my ($author) = $sth->fetchrow) {
2433 push (@{$origbiblio->{'additionalauthors'}}, $author);
2434 $origadditionalauthors->{$author}=1;
2436 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2439 while (my ($subject) = $sth->fetchrow) {
2440 push (@{$origbiblio->{'subjects'}}, $subject);
2441 $origsubjects->{$subject}=1;
2445 # Obtain a list of MARC Record_ID's that are tied to this biblio
2446 $sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
2449 while (my ($bibid) = $sth->fetchrow) {
2450 push(@marcrecords, $bibid);
2454 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
2455 my $q_author=$dbh->quote($biblio->{'author'});
2456 logchange('kohadb', 'change', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
2457 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
2459 foreach $bibid (@marcrecords) {
2460 logchange('marc', 'change', $bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2461 changeSubfield($bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2464 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
2465 my $q_title=$dbh->quote($biblio->{'title'});
2466 logchange('kohadb', 'change', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
2467 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
2469 foreach $Record_ID (@marcrecords) {
2470 logchange('marc', 'change', $Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2471 changeSubfield($Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2474 if ($biblio->{'subtitle'} ne $origbiblio->{'subtitle'}) {
2475 my $q_subtitle=$dbh->quote($biblio->{'subtitle'});
2476 logchange('kohadb', 'change', 'biblio', 'subtitle', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2477 my $sti=$dbh->prepare("update bibliosubtitle set subtitle=$q_subtitle where biblionumber=$biblio->{'biblionumber'}");
2479 foreach $Record_ID (@marcrecords) {
2480 logchange('marc', 'change', $Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2481 changeSubfield($Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2484 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
2485 my $q_unititle=$dbh->quote($biblio->{'unititle'});
2486 logchange('kohadb', 'change', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
2487 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
2490 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
2491 my $q_notes=$dbh->quote($biblio->{'notes'});
2492 logchange('kohadb', 'change', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
2493 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
2495 foreach $Record_ID (@marcrecords) {
2496 logchange('marc', 'change', $Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2497 changeSubfield($Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2500 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
2501 my $q_serial=$dbh->quote($biblio->{'serial'});
2502 logchange('kohadb', 'change', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
2503 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
2506 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
2507 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
2508 logchange('kohadb', 'change', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2509 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
2511 foreach $Record_ID (@marcrecords) {
2512 logchange('marc', 'change', $Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2513 changeSubfield($Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2516 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
2517 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
2518 logchange('kohadb', 'change', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
2519 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
2521 foreach $Record_ID (@marcrecords) {
2522 logchange('marc', 'change', $Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2523 changeSubfield($Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2527 # Check for subject heading changes
2531 foreach $newsubject (@{$biblio->{'subject'}}) {
2532 $subjects->{$newsubject}=1;
2533 if ($origsubjects->{$newsubject}) {
2534 $subjects->{$newsubject}=2;
2536 my $q_newsubject=$dbh->quote($newsubject);
2537 my $sth=$dbh->prepare("insert into bibliosubject (subject,biblionumber) values ($q_newsubject, $biblionumber)");
2539 logchange('kohadb', 'add', 'biblio', 'subject', $newsubject);
2541 $subfields->{1}->{'Subfield_Mark'}='a';
2542 $subfields->{1}->{'Subfield_Value'}=$newsubject;
2545 foreach $Record_ID (@marcrecords) {
2546 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2547 logchange('marc', 'add', $Record_ID, '650', 'a', $newsubject);
2552 foreach $origsubject (keys %$origsubjects) {
2553 if ($subjects->{$origsubject} == 1) {
2554 my $q_origsubject=$dbh->quote($origsubject);
2555 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'subject', $origsubject);
2556 my $sth=$dbh->prepare("delete from bibliosubject where biblionumber=$biblionumber and subject=$q_origsubject");
2562 sub OLD_MAYBE_DELETED_updateBiblioItem {
2563 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
2565 # This routine should also check to see which fields are actually being
2566 # modified, and log all changes.
2568 my ($env, $biblioitem) = @_;
2569 my $dbh = C4::Context->dbh;
2571 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2572 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
2573 # obi = original biblioitem
2574 my $obi=$sth->fetchrow_hashref;
2575 $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");
2577 my ($Record_ID) = $sth->fetchrow;
2578 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
2579 logchange('kohadb', 'change', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2580 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
2581 logchange('marc', 'change', $Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2582 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2584 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
2585 logchange('kohadb', 'change', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
2586 my $q_volume=$dbh->quote($biblioitem->{'volume'});
2587 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
2588 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2589 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2591 if ($biblioitem->{'number'} ne $obi->{'number'}) {
2592 logchange('kohadb', 'change', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
2593 my $q_number=$dbh->quote($biblioitem->{'number'});
2594 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
2595 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2596 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2598 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
2599 logchange('kohadb', 'change', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2600 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
2601 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
2602 logchange('marc', 'change', $Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2603 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2605 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
2606 logchange('kohadb', 'change', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
2607 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
2608 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
2609 logchange('marc', 'change', $Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2610 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2612 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
2613 logchange('kohadb', 'change', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
2614 my $q_issn=$dbh->quote($biblioitem->{'issn'});
2615 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
2616 logchange('marc', 'change', $Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2617 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2619 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
2620 logchange('kohadb', 'change', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
2621 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
2622 logchange('marc', 'change', $Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2623 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2625 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
2626 logchange('kohadb', 'change', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
2627 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
2628 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
2629 logchange('marc', 'change', $Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2630 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2632 if ($biblioitem->{'place'} ne $obi->{'place'}) {
2633 logchange('kohadb', 'change', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
2634 my $q_place=$dbh->quote($biblioitem->{'place'});
2635 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
2636 logchange('marc', 'change', $Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2637 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2639 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
2640 logchange('kohadb', 'change', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2641 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
2642 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
2643 logchange('marc', 'change', $Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2644 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2646 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
2647 logchange('kohadb', 'change', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2648 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
2649 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
2650 logchange('marc', 'change', $Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2651 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2653 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
2654 logchange('kohadb', 'change', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
2655 my $q_illus=$dbh->quote($biblioitem->{'illus'});
2656 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
2657 logchange('marc', 'change', $Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2658 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2660 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
2661 logchange('kohadb', 'change', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
2662 my $q_pages=$dbh->quote($biblioitem->{'pages'});
2663 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
2664 logchange('marc', 'change', $Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2665 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2667 if ($biblioitem->{'size'} ne $obi->{'size'}) {
2668 logchange('kohadb', 'change', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
2669 my $q_size=$dbh->quote($biblioitem->{'size'});
2670 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
2671 logchange('marc', 'change', $Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2672 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2674 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
2675 logchange('kohadb', 'change', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
2676 my $q_notes=$dbh->quote($biblioitem->{'notes'});
2677 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
2678 logchange('marc', 'change', $Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2679 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2681 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
2682 logchange('kohadb', 'change', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
2683 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
2684 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
2685 logchange('marc', 'change', $Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2686 changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2691 sub OLD_MAYBE_DELETED_updateItem {
2692 # Update the item with itemnumber $item->{'itemnumber'}
2693 # This routine should also modify the corresponding MARC record data. (852 and
2694 # 876 tags with 876p tag the same as $item->{'barcode'}
2696 # This routine should also check to see which fields are actually being
2697 # modified, and log all changes.
2699 my ($env, $item) = @_;
2700 my $dbh = C4::Context->dbh;
2701 my $itemnumber=$item->{'itemnumber'};
2702 my $biblionumber=$item->{'biblionumber'};
2703 my $biblioitemnumber=$item->{'biblioitemnumber'};
2704 my $barcode=$item->{'barcode'};
2705 my $dateaccessioned=$item->{'dateaccessioned'};
2706 my $booksellerid=$item->{'booksellerid'};
2707 my $homebranch=$item->{'homebranch'};
2708 my $price=$item->{'price'};
2709 my $replacementprice=$item->{'replacementprice'};
2710 my $replacementpricedate=$item->{'replacementpricedate'};
2711 my $multivolume=$item->{'multivolume'};
2712 my $stack=$item->{'stack'};
2713 my $notforloan=$item->{'notforloan'};
2714 my $itemlost=$item->{'itemlost'};
2715 my $wthdrawn=$item->{'wthdrawn'};
2716 my $bulk=$item->{'bulk'};
2717 my $restricted=$item->{'restricted'};
2718 my $binding=$item->{'binding'};
2719 my $itemnotes=$item->{'itemnotes'};
2720 my $holdingbranch=$item->{'holdingbranch'};
2721 my $interim=$item->{'interim'};
2722 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
2724 my $olditem=$sth->fetchrow_hashref;
2725 my $q_barcode=$dbh->quote($olditem->{'barcode'});
2726 $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");
2728 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
2729 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
2731 my ($link) = $sth->fetchrow;
2732 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
2734 my ($Subfield852_ID) = $sth->fetchrow;
2736 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
2737 logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
2738 my $q_barcode=$dbh->quote($item->{'barcode'});
2739 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
2741 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
2742 logchange('marc', 'change', $Record_ID, '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
2744 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
2745 logchange('kohadb', 'change', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
2746 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
2747 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
2749 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
2750 logchange('marc', 'change', $Record_ID, '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
2752 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
2753 logchange('kohadb', 'change', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2754 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
2755 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
2757 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
2758 logchange('marc', 'change', $Record_ID, '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2760 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
2761 logchange('kohadb', 'change', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
2762 my $q_homebranch=$dbh->quote($item->{'homebranch'});
2763 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
2765 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
2766 logchange('marc', 'change', $Record_ID, '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
2768 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
2769 logchange('kohadb', 'change', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2770 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
2771 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
2773 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
2774 logchange('marc', 'change', $Record_ID, '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2776 if ($item->{'price'} ne $olditem->{'price'}) {
2777 logchange('kohadb', 'change', 'items', 'price', $olditem->{'price'}, $item->{'price'});
2778 my $q_price=$dbh->quote($item->{'price'});
2779 my $sth=$dbh->prepare("update items set price=$q_price where itemnumber=$itemnumber");
2781 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'price'}, $item->{'price'}, $Subfield876_ID);
2782 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'price'}, $item->{'price'});
2784 if ($item->{'itemnotes'} ne $olditem->{'itemnotes'}) {
2785 logchange('kohadb', 'change', 'items', 'itemnotes', $olditem->{'itemnotes'}, $item->{'itemnotes'});
2786 my $q_itemnotes=$dbh->quote($item->{'itemnotes'});
2787 my $sth=$dbh->prepare("update items set itemnotes=$q_itemnotes where itemnumber=$itemnumber");
2789 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'itemnotes'}, $item->{'itemnotes'}, $Subfield876_ID);
2790 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'itemnotes'}, $item->{'itemnotes'});
2792 if ($item->{'notforloan'} ne $olditem->{'notforloan'}) {
2793 logchange('kohadb', 'change', 'items', 'notforloan', $olditem->{'notforloan'}, $item->{'notforloan'});
2794 my $sth=$dbh->prepare("update items set notforloan=$notforloan where itemnumber=$itemnumber");
2796 if ($item->{'notforloan'}) {
2797 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2798 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2800 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2801 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2804 if ($item->{'itemlost'} ne $olditem->{'itemlost'}) {
2805 logchange('kohadb', 'change', 'items', 'itemlost', $olditem->{'itemlost'}, $item->{'itemlost'});
2806 my $sth=$dbh->prepare("update items set itemlost=$itemlost where itemnumber=$itemnumber");
2808 if ($item->{'itemlost'}) {
2809 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2810 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2812 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2813 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2816 if ($item->{'wthdrawn'} ne $olditem->{'wthdrawn'}) {
2817 logchange('kohadb', 'change', 'items', 'wthdrawn', $olditem->{'wthdrawn'}, $item->{'wthdrawn'});
2818 my $sth=$dbh->prepare("update items set wthdrawn=$wthdrawn where itemnumber=$itemnumber");
2820 if ($item->{'wthdrawn'}) {
2821 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2822 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2824 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2825 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2828 if ($item->{'restricted'} ne $olditem->{'restricted'}) {
2829 logchange('kohadb', 'change', 'items', 'restricted', $olditem->{'restricted'}, $item->{'restricted'});
2830 my $sth=$dbh->prepare("update items set restricted=$restricted where itemnumber=$itemnumber");
2832 if ($item->{'restricted'}) {
2833 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2834 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2836 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2837 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2843 # Add a biblioitem and related data to Koha database
2844 sub OLD_MAY_BE_DELETED_newcompletebiblioitem {
2849 $biblio, # hash ref to biblio record
2850 $biblioitem, # hash ref to biblioitem record
2851 $subjects, # list ref of subjects
2852 $addlauthors, # list ref of additional authors
2855 my ( $biblionumber, $biblioitemnumber, $error); # return values
2860 my $additionalauthor;
2863 requireDBI($dbh,"newcompletebiblioitem");
2865 print "<PRE>Trying to add biblio item Title=$biblio->{title} " .
2866 "ISBN=$biblioitem->{isbn} </PRE>\n" if $debug;
2868 # Make sure master biblio entry exists
2869 ($biblionumber,$error)=getoraddbiblio($dbh, $biblio);
2873 $biblioitem->{biblionumber}=$biblionumber;
2876 $biblioitemnumber=newbiblioitem($biblioitem);
2879 $sth=$dbh->prepare("insert into bibliosubject
2880 (biblionumber,subject)
2882 foreach $subjectheading (@{$subjects} ) {
2883 $sth->execute($biblionumber, $subjectheading)
2884 or $error.=$sth->errstr ;
2888 # Add additional authors
2889 $sth=$dbh->prepare("insert into additionalauthors
2890 (biblionumber,author)
2892 foreach $additionalauthor (@{$addlauthors} ) {
2893 $sth->execute($biblionumber, $additionalauthor)
2894 or $error.=$sth->errstr ;
2898 # couldn't get biblio
2900 $biblioitemnumber='';
2902 } # if no biblio error
2904 return ( $biblionumber, $biblioitemnumber, $error);
2906 } # sub newcompletebiblioitem
2910 # END OF UNUSEFUL SUBs
2914 END { } # module clean-up code here (global destructor)