4 # Revision 1.20 2002/10/13 08:28:32 arensb
5 # Deleted unused variables.
6 # Removed trailing whitespace.
8 # Revision 1.19 2002/10/13 05:56:10 arensb
9 # Added some FIXME comments.
11 # Revision 1.18 2002/10/11 12:34:53 arensb
12 # Replaced &requireDBI with C4::Context->dbh
14 # Revision 1.17 2002/10/10 14:48:25 tipaul
17 # Revision 1.16 2002/10/07 14:04:26 tipaul
18 # road to 1.3.1 : viewing MARC biblio
20 # Revision 1.15 2002/10/05 09:49:25 arensb
21 # Merged with arensb-context branch: use C4::Context->dbh instead of
22 # &C4Connect, and generally prefer C4::Context over C4::Database.
24 # Revision 1.14 2002/10/03 11:28:18 tipaul
25 # Extending Context.pm to add stopword management and using it in MARC-API.
26 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
28 # Revision 1.13 2002/10/02 16:26:44 tipaul
31 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
32 # Merged in changes from main branch.
34 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
35 # Added a whole mess of FIXME comments.
37 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
38 # Added some missing semicolons.
40 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
41 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
44 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
45 # Added a whole mess of FIXME comments.
47 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
48 # Added some missing semicolons.
50 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
51 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
54 # Revision 1.12 2002/10/01 11:48:51 arensb
55 # Added some FIXME comments, mostly marking duplicate functions.
57 # Revision 1.11 2002/09/24 13:49:26 tipaul
58 # long WAS the road to 1.3.0...
59 # coming VERY SOON NOW...
60 # modifying installer and buildrelease to update the DB
62 # Revision 1.10 2002/09/22 16:50:08 arensb
63 # Added some FIXME comments.
65 # Revision 1.9 2002/09/20 12:57:46 tipaul
66 # long is the road to 1.4.0
67 # * MARCadditem and MARCmoditem now wroks
68 # * various bugfixes in MARC management
69 # !!! 1.3.0 should be released very soon now. Be careful !!!
71 # Revision 1.8 2002/09/10 13:53:52 tipaul
72 # MARC API continued...
74 # * 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)
76 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
78 # Revision 1.7 2002/08/14 18:12:51 tonnesen
79 # Added copyright statement to all .pl and .pm files
81 # Revision 1.6 2002/07/25 13:40:31 tipaul
82 # pod documenting the API.
84 # Revision 1.5 2002/07/24 16:11:37 tipaul
86 # Database.pm and Output.pm are almost not modified (var test...)
88 # Biblio.pm is almost completly rewritten.
90 # WHAT DOES IT ??? ==> END of Hitchcock suspens
92 # 1st, it does... nothing...
93 # 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 ...
95 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
96 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
97 # * 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.
98 # * 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.
99 # 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 ;-)
101 # 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.
102 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
106 # move from 1.2 to 1.4 version :
107 # 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
108 # In the 1.4 version, we want to do 2 differents things :
109 # - keep populating the old-DB, that has a LOT less datas than MARC
110 # - populate the MARC-DB
111 # To populate the DBs we have 2 differents sources :
112 # - the standard acquisition system (through book sellers), that does'nt use MARC data
113 # - the MARC acquisition system, that uses MARC data.
115 # thus, we have 2 differents cases :
116 # - 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
117 # - 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.
118 # we MUST have an API for true MARC data, that populate MARC-DB then old-DB
120 # That's why we need 4 subs :
121 # all subs beginning by MARC manage only MARC tables. They manage MARC-DB with MARC::Record parameters
122 # all subs beginning by OLD manage only OLD-DB tables. They manage old-DB with old-DB parameters
123 # 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
124 # 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.
126 # only ALL and old-style API should be used in koha. MARC and OLD is used internally only
128 # 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.
129 # 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 ;-)
133 # Copyright 2000-2002 Katipo Communications
135 # This file is part of Koha.
137 # Koha is free software; you can redistribute it and/or modify it under the
138 # terms of the GNU General Public License as published by the Free Software
139 # Foundation; either version 2 of the License, or (at your option) any later
142 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
143 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
144 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
146 # You should have received a copy of the GNU General Public License along with
147 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
148 # Suite 330, Boston, MA 02111-1307 USA
156 use vars qw($VERSION @ISA @EXPORT);
158 # set the version for version checking
163 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
164 # as the old-style API and the ALL one are the only public functions.
167 &updateBiblio &updateBiblioItem &updateItem
168 &itemcount &newbiblio &newbiblioitem
169 &modnote &newsubject &newsubtitle
170 &modbiblio &checkitems
171 &newitems &modbibitem
172 &modsubtitle &modsubject &modaddauthor &moditem &countitems
173 &delitem &deletebiblioitem &delbiblio
174 &getitemtypes &getbiblio
175 &getbiblioitembybiblionumber
176 &getbiblioitem &getitemsbybiblioitem &isbnsearch
178 &newcompletebiblioitem
180 &MARCfind_oldbiblionumber_from_MARCbibid
181 &MARCfind_MARCbibid_from_oldbiblionumber
183 &ALLnewbiblio &ALLnewitem
186 &MARCaddbiblio &MARCadditem
187 &MARCmodsubfield &MARCaddsubfield
188 &MARCmodbiblio &MARCmoditem
190 &MARCkoha2marcBiblio &MARCmarc2koha &MARCkoha2marcItem
191 &MARCgetbiblio &MARCgetitem
192 &MARCaddword &MARCdelword
197 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
200 # all the following subs takes a MARC::Record as parameter and manage
201 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
202 # ALLxxx subs (xxx deals with old-DB parameters, the ALLxxx deals with MARC-DB parameter)
207 all subs requires/use $dbh as 1st parameter.
208 NOTE : all those subs are private and must be used only inside Biblio.pm (called by a old API sub, or the ALLsub)
212 =head2 @tagslib = &MARCgettagslib($dbh,1|0);
213 last param is 1 for liblibrarian and 0 for libopac
214 returns a hash with tag/subfield meaning
216 =head2 ($tagfield,$tagsubfield) = &MARCfindmarc_from_kohafield($dbh,$kohafield);
217 finds MARC tag and subfield for a given kohafield
218 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
220 =head2 $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
221 finds a old-db biblio number for a given MARCbibid number
223 =head2 $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
224 finds a MARC bibid from a old-db biblionumber
226 =head2 &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
227 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
229 =head2 &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
230 adds a subfield in a biblio (in the MARC tables only).
232 =head2 $MARCRecord = &MARCgetbiblio($dbh,$bibid);
233 Returns a MARC::Record for the biblio $bibid.
235 =head2 &MARCmodbiblio($dbh,$bibid,$delete,$record);
236 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
237 if $delete == 1, every field/subfield not found is deleted in the biblio
238 otherwise, only data passed to MARCmodbiblio is managed.
239 thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
241 =head2 ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
242 MARCmodsubfield changes the value of a given subfield
244 =head2 $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
245 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
246 Returns -1 if more than 1 answer
248 =head2 $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
249 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
251 =head2 &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
252 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
254 =head2 &MARCdelbiblio($dbh,$bibid);
255 MARCdelbiblio delete biblio $bibid
257 =head2 $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
258 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
260 =head2 $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
261 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
263 =head2 $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
264 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
266 =head2 &MARCkoha2marcOnefield => used by MARCkoha2marc and should not be useful elsewhere
268 =head2 $olddb = &MARCmarc2koha($dbh,$MARCRecord);
269 builds a hash with old-db datas from a MARC::Record
271 =head2 &MARCmarc2kohaOnefield => used by MARCmarc2koha and should not be useful elsewhere
273 =head2 MARCaddword => used to manage MARC_word table and should not be useful elsewhere
275 =head2 MARCdelword => used to manage MARC_word table and should not be useful elsewhere
279 Paul POULAIN paul.poulain@free.fr
284 my ($dbh,$forlibrarian)= @_;
286 if ($forlibrarian eq 1) {
287 $sth=$dbh->prepare("select tagfield,liblibrarian as lib from marc_tag_structure");
289 $sth=$dbh->prepare("select tagfield,libopac as lib from marc_tag_structure");
292 my ($lib,$tag,$res,$tab);
293 while ( ($tag,$lib,$tab) = $sth->fetchrow) {
294 $res->{$tag}->{lib}=$lib;
295 $res->{$tab}->{tab}="";
298 if ($forlibrarian eq 1) {
299 $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure");
301 $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib,tab from marc_subfield_structure");
306 while ( ($tag,$subfield,$lib,$tab) = $sth->fetchrow) {
307 $res->{$tag}->{$subfield}->{lib}=$lib;
308 $res->{$tag}->{$subfield}->{tab}=$tab;
313 sub MARCfind_marc_from_kohafield {
314 my ($dbh,$kohafield) = @_;
315 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
316 $sth->execute($kohafield);
317 my ($tagfield,$tagsubfield) = $sth->fetchrow;
318 return ($tagfield,$tagsubfield);
321 sub MARCfind_oldbiblionumber_from_MARCbibid {
322 my ($dbh,$MARCbibid) = @_;
323 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
324 $sth->execute($MARCbibid);
325 my ($biblionumber) = $sth->fetchrow;
326 return $biblionumber;
329 sub MARCfind_MARCbibid_from_oldbiblionumber {
330 my ($dbh,$oldbiblionumber) = @_;
331 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
332 $sth->execute($oldbiblionumber);
333 my ($bibid) = $sth->fetchrow;
338 # pass the MARC::Record to this function, and it will create the records in the marc tables
339 my ($dbh,$record,$biblionumber) = @_;
340 my @fields=$record->fields();
342 # adding main table, and retrieving bibid
343 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
344 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
345 $sth->execute($biblionumber);
346 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
348 ($bibid)=$sth->fetchrow;
351 # now, add subfields...
352 foreach my $field (@fields) {
353 my @subfields=$field->subfields();
355 foreach my $subfieldcount (0..$#subfields) {
356 &MARCaddsubfield($dbh,$bibid,
358 $field->indicator(1).$field->indicator(2),
360 $subfields[$subfieldcount][0],
362 $subfields[$subfieldcount][1]
366 $dbh->do("unlock tables");
371 # pass the MARC::Record to this function, and it will create the records in the marc tables
372 my ($dbh,$record,$biblionumber) = @_;
373 # search for MARC biblionumber
374 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
375 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
376 my @fields=$record->fields();
377 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
378 $sth->execute($bibid);
379 my ($fieldcount) = $sth->fetchrow;
380 # now, add subfields...
381 foreach my $field (@fields) {
382 my @subfields=$field->subfields();
384 foreach my $subfieldcount (0..$#subfields) {
385 &MARCaddsubfield($dbh,$bibid,
387 $field->indicator(1).$field->indicator(2),
389 $subfields[$subfieldcount][0],
391 $subfields[$subfieldcount][1]
395 $dbh->do("unlock tables");
399 sub MARCaddsubfield {
400 # Add a new subfield to a tag into the DB.
401 my ($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
402 # if not value, end of job, we do nothing
403 if (not($subfieldvalue)) {
406 if (not($subfieldcode)) {
409 if (length($subfieldvalue)>255) {
410 # $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
411 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
412 $sth->execute($subfieldvalue);
413 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
415 my ($res)=$sth->fetchrow;
416 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?)");
418 $sth->execute($bibid,'0'.$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
420 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
423 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
425 # $dbh->do("unlock tables");
427 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?)");
428 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
430 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
433 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
438 # Returns MARC::Record of the biblio passed in parameter.
440 my $record = MARC::Record->new();
441 #---- TODO : the leader is missing
442 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
443 from marc_subfield_table
444 where bibid=? order by tagorder,subfieldorder
446 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
447 $sth->execute($bibid);
451 while (my $row=$sth->fetchrow_hashref) {
452 if ($row->{'valuebloblink'}) { #---- search blob if there is one
453 $sth2->execute($row->{'valuebloblink'});
454 my $row2=$sth2->fetchrow_hashref;
456 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
458 if ($row->{tagorder} ne $prevtagorder) {
459 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
460 $record->add_fields($field);
461 $prevtagorder=$row->{tagorder};
462 $prevtag = $row->{tag};
464 %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
466 %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
467 $prevtag= $row->{tag};
470 # the last has not been included inside the loop... do it now !
471 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
472 $record->add_fields($field);
476 # Returns MARC::Record of the biblio passed in parameter.
477 my ($dbh,$bibid,$itemnumber)=@_;
478 warn "MARCgetitem : $bibid, $itemnumber\n";
479 my $record = MARC::Record->new();
480 # search MARC tagorder
481 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=?");
482 $sth2->execute($bibid,$itemnumber);
483 my ($tagorder) = $sth2->fetchrow_array();
484 #---- TODO : the leader is missing
485 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
486 from marc_subfield_table
487 where bibid=? and tagorder=? order by subfieldorder
489 # FIXME - There's already a $sth2 in this scope.
490 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
491 $sth->execute($bibid,$tagorder);
492 while (my $row=$sth->fetchrow_hashref) {
493 if ($row->{'valuebloblink'}) { #---- search blob if there is one
494 $sth2->execute($row->{'valuebloblink'});
495 my $row2=$sth2->fetchrow_hashref;
497 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
499 if ($record->field($row->{'tag'})) {
501 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
502 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
503 if (length($row->{'tag'}) <3) {
504 $row->{'tag'} = "0".$row->{'tag'};
506 $field =$record->field($row->{'tag'});
508 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
509 $record->delete_field($field);
510 $record->add_fields($field);
513 if (length($row->{'tag'}) < 3) {
514 $row->{'tag'} = "0".$row->{'tag'};
516 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
517 $record->add_fields($temp);
525 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
526 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
527 # if nothing to change, don't waste time...
528 if ($oldrecord eq $record) {
531 # otherwise, skip through each subfield...
532 my @fields = $record->fields();
534 foreach my $field (@fields) {
535 my $oldfield = $oldrecord->field($field->tag());
536 my @subfields=$field->subfields();
539 foreach my $subfield (@subfields) {
541 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
542 # just adding datas...
543 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
544 1,@$subfield[0],$subfieldorder,@$subfield[1]);
546 # modify he subfield if it's a different string
547 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
548 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
549 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
557 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
558 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
559 # if nothing to change, don't waste time...
560 if ($oldrecord eq $record) {
563 # otherwise, skip through each subfield...
564 my @fields = $record->fields();
565 # search old MARC item
566 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=?");
567 $sth2->execute($bibid,$itemnumber);
568 my ($tagorder) = $sth2->fetchrow_array();
569 foreach my $field (@fields) {
570 my $oldfield = $oldrecord->field($field->tag());
571 my @subfields=$field->subfields();
573 foreach my $subfield (@subfields) {
575 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
576 # just adding datas...
577 warn "ADD = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
578 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
579 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
581 # modify he subfield if it's a different string
582 warn "MODIFY = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
583 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
584 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
585 warn "MODIFY2 = $bibid, $subfieldid, ".@$subfield[1]."\n";
586 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
595 sub MARCmodsubfield {
596 # Subroutine changes a subfield value given a subfieldid.
597 my ($dbh, $subfieldid, $subfieldvalue )=@_;
598 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
599 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
600 $sth1->execute($subfieldid);
601 my ($oldvaluebloblink)=$sth1->fetchrow;
604 # if too long, use a bloblink
605 if (length($subfieldvalue)>255 ) {
606 # if already a bloblink, update it, otherwise, insert a new one.
607 if ($oldvaluebloblink) {
608 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
609 $sth->execute($subfieldvalue,$oldvaluebloblink);
611 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
612 $sth->execute($subfieldvalue);
613 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
615 my ($res)=$sth->fetchrow;
616 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
617 $sth->execute($subfieldid);
620 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
621 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
622 $sth->execute($subfieldvalue, $subfieldid);
624 $dbh->do("unlock tables");
626 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
627 $sth->execute($subfieldid);
628 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
630 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
631 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
632 return($subfieldid, $subfieldvalue);
635 sub MARCfindsubfield {
636 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
640 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
641 if ($subfieldvalue) {
642 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
644 if ($subfieldorder<1) {
647 $query .= " and subfieldorder=$subfieldorder";
649 my $sti=$dbh->prepare($query);
650 $sti->execute($bibid,$tag, $subfieldcode);
651 while (($subfieldid) = $sti->fetchrow) {
653 $lastsubfieldid=$subfieldid;
655 if ($resultcounter>1) {
656 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
657 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
660 return $lastsubfieldid;
664 sub MARCfindsubfieldid {
665 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
666 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
667 where bibid=? and tag=? and tagorder=?
668 and subfieldcode=? and subfieldorder=?");
669 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
670 my ($res) = $sth->fetchrow;
674 sub MARCdelsubfield {
675 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
676 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
677 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
678 tag='$tag' and tagorder='$tagorder'
679 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
684 # delete a biblio for a $bibid
685 my ($dbh,$bibid) = @_;
686 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
687 $dbh->do("delete from marc_biblio where bibid='$bibid'");
690 sub MARCkoha2marcBiblio {
691 # this function builds partial MARC::Record from the old koha-DB fields
692 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
693 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
694 my $record = MARC::Record->new();
695 #--- if bibid, then retrieve old-style koha data
696 if ($biblionumber>0) {
697 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
698 from biblio where biblionumber=?");
699 $sth2->execute($biblionumber);
700 my $row=$sth2->fetchrow_hashref;
702 foreach $code (keys %$row) {
704 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
708 #--- if biblioitem, then retrieve old-style koha data
709 if ($biblioitemnumber>0) {
710 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
711 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
712 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
714 WHERE biblionumber=? and biblioitemnumber=?
716 $sth2->execute($biblionumber,$biblioitemnumber);
717 my $row=$sth2->fetchrow_hashref;
719 foreach $code (keys %$row) {
721 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
726 # TODO : retrieve notes, additionalauthors
729 sub MARCkoha2marcItem {
730 # this function builds partial MARC::Record from the old koha-DB fields
731 my ($dbh,$biblionumber,$itemnumber) = @_;
732 # my $dbh=&C4Connect;
733 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
734 my $record = MARC::Record->new();
735 #--- if item, then retrieve old-style koha data
737 # print STDERR "prepare $biblionumber,$itemnumber\n";
738 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
739 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
740 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
741 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
743 WHERE itemnumber=?");
744 $sth2->execute($itemnumber);
745 my $row=$sth2->fetchrow_hashref;
747 foreach $code (keys %$row) {
749 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
754 # TODO : retrieve notes, additionalauthors
757 sub MARCkoha2marcSubtitle {
758 # this function builds partial MARC::Record from the old koha-DB fields
759 my ($dbh,$bibnum,$subtitle) = @_;
760 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
761 my $record = MARC::Record->new();
762 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
766 sub MARCkoha2marcOnefield {
767 my ($sth,$record,$kohafieldname,$value)=@_;
770 $sth->execute($kohafieldname);
771 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
772 if ($record->field($tagfield)) {
773 my $tag =$record->field($tagfield);
775 $tag->add_subfields($tagsubfield,$value);
776 $record->delete_field($tag);
777 $record->add_fields($tag);
780 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
787 my ($dbh,$record) = @_;
788 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
790 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
793 # print STDERR $record->as_formatted;
794 while (($field)=$sth2->fetchrow) {
795 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
797 # FIXME - There's already a $sth2 in this scope.
798 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
800 # FIXME - There's already a $field in this scope.
802 while (($field)=$sth2->fetchrow) {
803 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
805 # FIXME - There's already a $sth2 in this scope.
806 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
808 # FIXME - There's already a $field in this scope.
810 while (($field)=$sth2->fetchrow) {
811 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
813 # additional authors : specific
814 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
818 sub MARCmarc2kohaOneField {
819 # to check : if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
820 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
824 $sth->execute($kohatable.".".$kohafield);
825 ($tagfield,$subfield) = $sth->fetchrow;
826 foreach my $field ($record->field($tagfield)) {
827 if ($field->subfield($subfield)) {
828 if ($result->{$kohafield}) {
829 $result->{$kohafield} .= " | ".$field->subfield($subfield);
831 $result->{$kohafield}=$field->subfield($subfield);
839 # split a subfield string and adds it into the word table.
841 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
842 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
843 my @words = split / /,$sentence;
844 # build stopword list
845 # my $sth2 =$dbh->prepare("select word from stopwords");
849 # while(($stopword) = $sth2->fetchrow_array) {
850 # $stopwords->{$stopword} = $stopword;
852 my $stopwords= C4::Context->stopwords;
853 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
854 values (?,?,?,?,?,?,soundex(?))");
855 foreach my $word (@words) {
856 # we record only words longer than 2 car and not in stopwords hash
857 if (length($word)>1 and !($stopwords->{uc($word)})) {
858 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
860 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";
867 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
868 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
869 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
870 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
875 # ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL
878 # all the following subs are useful to manage MARC-DB with complete MARC records.
879 # it's used with marcimport, and marc management tools
884 all subs requires/use $dbh as 1st parameter.
885 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
889 =head2 (oldbibnum,$oldbibitemnum) = ALLnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
890 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
891 are builded from the MARC::Record. If they are passed, they are used.
893 =head2 ALLnewitem($dbh,$olditem);
894 adds an item in the db. $olditem is a old-db hash.
898 Paul POULAIN paul.poulain@free.fr
903 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
904 # note $oldbiblio and $oldbiblioitem are not mandatory.
905 # if not present, they will be builded from $record with MARCmarc2koha function
906 if (($oldbiblio) and not($oldbiblioitem)) {
907 print STDERR "ALLnewbiblio : missing parameter\n";
908 print "ALLnewbiblio : missing parameter : contact koha development team\n";
914 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
915 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
916 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
918 my $olddata = MARCmarc2koha($dbh,$record);
919 $oldbibnum = OLDnewbiblio($dbh,$olddata);
920 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
922 # we must add bibnum and bibitemnum in MARC::Record...
923 # we build the new field with biblionumber and biblioitemnumber
924 # we drop the original field
925 # we add the new builded field.
926 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
927 # (steve and paul : thinks 090 is a good choice)
928 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
929 $sth->execute("biblio.biblionumber");
930 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
931 $sth->execute("biblioitems.biblioitemnumber");
932 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
933 print STDERR "tag1 : $tagfield1 / $tagsubfield1\n tag2 : $tagfield2 / $tagsubfield2\n";
934 if ($tagsubfield1 != $tagsubfield2) {
935 print STDERR "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
936 print "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
939 my $newfield = MARC::Field->new( $tagfield1,'','',
940 "$tagsubfield1" => $oldbibnum,
941 "$tagsubfield2" => $oldbibitemnum);
942 # drop old field and create new one...
943 my $old_field = $record->field($tagfield1);
944 $record->delete_field($old_field);
945 $record->add_fields($newfield);
946 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
947 return ( $oldbibnum,$oldbibitemnum );
951 my ($dbh, $item) = @_;
954 ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{'barcode'});
955 # search MARC biblionumber
956 my $bibid=&MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{'biblionumber'});
958 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
959 $sth->execute($bibid);
960 my ($tagorder) = $sth->fetchrow;
963 # for each field, find MARC tag and subfield, and call the proper MARC sub
964 foreach my $itemkey (keys %$item) {
967 print STDERR "=============> $itemkey : ".$item->{$itemkey}."\n";
968 if ($itemkey eq "biblionumber" || $itemkey eq "biblioitemnumber") {
969 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"biblio.".$itemkey);
971 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"items.".$itemkey);
973 if ($tagfield && $item->{$itemkey} ne 'NULL') {
975 &MARCaddsubfield($dbh,
991 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
997 all subs requires/use $dbh as 1st parameter.
998 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
1000 They all are the exact copy of 1.0/1.2 version of the sub
1001 without the OLD. The OLDxxx is called by the original xxx sub.
1002 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
1004 WARNING : there is 1 difference between initialxxx and OLDxxx :
1005 the db header $dbh is always passed as parameter
1006 to avoid over-DB connexion
1010 =head2 $biblionumber = OLDnewbiblio($dbh,$biblio);
1011 adds a record in biblio table. Datas are in the hash $biblio.
1013 =head2 $biblionumber = OLDmodbiblio($dbh,$biblio);
1014 modify a record in biblio table. Datas are in the hash $biblio.
1016 =head2 OLDmodsubtitle($dbh,$bibnum,$subtitle);
1017 modify subtitles in bibliosubtitle table.
1019 =head2 OLDmodaddauthor($dbh,$bibnum,$author);
1020 adds or modify additional authors
1021 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1023 =head2 $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1024 modify/adds subjects
1026 =head2 OLDmodbibitem($dbh, $biblioitem);
1029 =head2 OLDmodnote($dbh,$bibitemnum,$note
1030 modify a note for a biblioitem
1032 =head2 OLDnewbiblioitem($dbh,$biblioitem);
1033 adds a biblioitem ($biblioitem is a hash with the values)
1035 =head2 OLDnewsubject($dbh,$bibnum);
1037 =head2 OLDnewsubtitle($dbh,$bibnum,$subtitle);
1038 create a new subtitle
1040 =head2 ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1041 create a item. $item is a hash and $barcode the barcode.
1043 =head2 OLDmoditem($dbh,$item);
1046 =head2 OLDdelitem($dbh,$itemnum);
1049 =head2 OLDdeletebiblioitem($dbh,$biblioitemnumber);
1050 deletes a biblioitem
1051 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1053 =head2 OLDdelbiblio($dbh,$biblio);
1058 Paul POULAIN paul.poulain@free.fr
1063 my ($dbh,$biblio) = @_;
1064 # my $dbh = &C4Connect;
1065 my $query = "Select max(biblionumber) from biblio";
1066 my $sth = $dbh->prepare($query);
1068 my $data = $sth->fetchrow_arrayref;
1069 my $bibnum = $$data[0] + 1;
1072 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1073 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1074 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
1075 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
1076 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1077 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1078 if ($biblio->{'seriestitle'}) { $series = 1 };
1081 $query = "insert into biblio set
1082 biblionumber = $bibnum,
1083 title = $biblio->{'title'},
1084 author = $biblio->{'author'},
1085 copyrightdate = $biblio->{'copyright'},
1087 seriestitle = $biblio->{'seriestitle'},
1088 notes = $biblio->{'notes'},
1089 abstract = $biblio->{'abstract'}";
1091 $sth = $dbh->prepare($query);
1100 my ($dbh,$biblio) = @_;
1101 # my $dbh = C4Connect;
1105 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1106 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1107 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1108 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
1109 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
1110 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
1111 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
1112 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1114 $query = "Update biblio set
1115 title = $biblio->{'title'},
1116 author = $biblio->{'author'},
1117 abstract = $biblio->{'abstract'},
1118 copyrightdate = $biblio->{'copyrightdate'},
1119 seriestitle = $biblio->{'seriestitle'},
1120 serial = $biblio->{'serial'},
1121 unititle = $biblio->{'unititle'},
1122 notes = $biblio->{'notes'}
1123 where biblionumber = $biblio->{'biblionumber'}";
1124 $sth = $dbh->prepare($query);
1129 return($biblio->{'biblionumber'});
1132 sub OLDmodsubtitle {
1133 my ($dbh,$bibnum, $subtitle) = @_;
1134 # my $dbh = C4Connect;
1135 my $query = "update bibliosubtitle set
1136 subtitle = '$subtitle'
1137 where biblionumber = $bibnum";
1138 my $sth = $dbh->prepare($query);
1146 sub OLDmodaddauthor {
1147 my ($dbh,$bibnum, $author) = @_;
1148 # my $dbh = C4Connect;
1149 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1150 my $sth = $dbh->prepare($query);
1155 if ($author ne '') {
1156 $query = "Insert into additionalauthors set
1158 biblionumber = '$bibnum'";
1159 $sth = $dbh->prepare($query);
1165 } # sub modaddauthor
1169 my ($dbh,$bibnum, $force, @subject) = @_;
1170 # my $dbh = C4Connect;
1171 my $count = @subject;
1173 for (my $i = 0; $i < $count; $i++) {
1174 $subject[$i] =~ s/^ //g;
1175 $subject[$i] =~ s/ $//g;
1176 my $query = "select * from catalogueentry
1177 where entrytype = 's'
1178 and catalogueentry = '$subject[$i]'";
1179 my $sth = $dbh->prepare($query);
1182 if (my $data = $sth->fetchrow_hashref) {
1184 if ($force eq $subject[$i]) {
1185 # subject not in aut, chosen to force anway
1186 # so insert into cataloguentry so its in auth file
1187 $query = "Insert into catalogueentry
1188 (entrytype,catalogueentry)
1189 values ('s','$subject[$i]')";
1190 my $sth2 = $dbh->prepare($query);
1195 $error = "$subject[$i]\n does not exist in the subject authority file";
1196 $query = "Select * from catalogueentry
1197 where entrytype = 's'
1198 and (catalogueentry like '$subject[$i] %'
1199 or catalogueentry like '% $subject[$i] %'
1200 or catalogueentry like '% $subject[$i]')";
1201 my $sth2 = $dbh->prepare($query);
1204 while (my $data = $sth2->fetchrow_hashref) {
1205 $error = $error."<br>$data->{'catalogueentry'}"; # FIXME - .=
1213 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1214 my $sth = $dbh->prepare($query);
1217 for (my $i = 0; $i < $count; $i++) {
1218 $sth = $dbh->prepare("Insert into bibliosubject
1219 values ('$subject[$i]', $bibnum)");
1231 my ($dbh,$biblioitem) = @_;
1232 # my $dbh = C4Connect;
1235 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1236 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1237 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1238 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1239 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1240 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1241 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1242 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1243 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1244 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1245 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1246 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1247 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1248 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1250 $query = "Update biblioitems set
1251 itemtype = $biblioitem->{'itemtype'},
1252 url = $biblioitem->{'url'},
1253 isbn = $biblioitem->{'isbn'},
1254 publishercode = $biblioitem->{'publishercode'},
1255 publicationyear = $biblioitem->{'publicationyear'},
1256 classification = $biblioitem->{'classification'},
1257 dewey = $biblioitem->{'dewey'},
1258 subclass = $biblioitem->{'subclass'},
1259 illus = $biblioitem->{'illus'},
1260 pages = $biblioitem->{'pages'},
1261 volumeddesc = $biblioitem->{'volumeddesc'},
1262 notes = $biblioitem->{'notes'},
1263 size = $biblioitem->{'size'},
1264 place = $biblioitem->{'place'}
1265 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1273 my ($dbh,$bibitemnum,$note)=@_;
1274 # my $dbh=C4Connect;
1275 my $query="update biblioitems set notes='$note' where
1276 biblioitemnumber='$bibitemnum'";
1277 my $sth=$dbh->prepare($query);
1283 sub OLDnewbiblioitem {
1284 my ($dbh,$biblioitem) = @_;
1285 # my $dbh = C4Connect;
1286 my $query = "Select max(biblioitemnumber) from biblioitems";
1287 my $sth = $dbh->prepare($query);
1291 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
1292 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
1293 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1294 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1295 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1296 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1297 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
1298 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1299 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1300 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1301 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1302 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
1303 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1304 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1305 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1306 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1307 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1308 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1309 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
1310 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
1313 $data = $sth->fetchrow_arrayref;
1314 $bibitemnum = $$data[0] + 1;
1318 $query = "insert into biblioitems set
1319 biblioitemnumber = $bibitemnum,
1320 biblionumber = $biblioitem->{'biblionumber'},
1321 volume = $biblioitem->{'volume'},
1322 number = $biblioitem->{'number'},
1323 classification = $biblioitem->{'classification'},
1324 itemtype = $biblioitem->{'itemtype'},
1325 url = $biblioitem->{'url'},
1326 isbn = $biblioitem->{'isbn'},
1327 issn = $biblioitem->{'issn'},
1328 dewey = $biblioitem->{'dewey'},
1329 subclass = $biblioitem->{'subclass'},
1330 publicationyear = $biblioitem->{'publicationyear'},
1331 publishercode = $biblioitem->{'publishercode'},
1332 volumedate = $biblioitem->{'volumedate'},
1333 volumeddesc = $biblioitem->{'volumeddesc'},
1334 illus = $biblioitem->{'illus'},
1335 pages = $biblioitem->{'pages'},
1336 notes = $biblioitem->{'notes'},
1337 size = $biblioitem->{'size'},
1338 lccn = $biblioitem->{'lccn'},
1339 marc = $biblioitem->{'marc'},
1340 place = $biblioitem->{'place'}";
1342 $sth = $dbh->prepare($query);
1346 return($bibitemnum);
1350 my ($dbh,$bibnum)=@_;
1351 # my $dbh=C4Connect;
1352 my $query="insert into bibliosubject (biblionumber) values
1354 my $sth=$dbh->prepare($query);
1361 sub OLDnewsubtitle {
1362 my ($dbh,$bibnum, $subtitle) = @_;
1363 # my $dbh = C4Connect;
1364 $subtitle = $dbh->quote($subtitle);
1365 my $query = "insert into bibliosubtitle set
1366 biblionumber = $bibnum,
1367 subtitle = $subtitle";
1368 my $sth = $dbh->prepare($query);
1378 my ($dbh,$item, $barcode) = @_;
1379 # my $dbh = C4Connect;
1380 my $query = "Select max(itemnumber) from items";
1381 my $sth = $dbh->prepare($query);
1387 $data = $sth->fetchrow_hashref;
1388 $itemnumber = $data->{'max(itemnumber)'} + 1;
1391 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
1392 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
1393 $item->{'price'} = $dbh->quote($item->{'price'});
1394 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
1395 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
1397 # foreach my $barcode (@barcodes) {
1398 # $barcode = uc($barcode);
1399 $barcode = $dbh->quote($barcode);
1400 $query = "Insert into items set
1401 itemnumber = $itemnumber,
1402 biblionumber = $item->{'biblionumber'},
1403 biblioitemnumber = $item->{'biblioitemnumber'},
1405 booksellerid = $item->{'booksellerid'},
1406 dateaccessioned = NOW(),
1407 homebranch = $item->{'homebranch'},
1408 holdingbranch = $item->{'homebranch'},
1409 price = $item->{'price'},
1410 replacementprice = $item->{'replacementprice'},
1411 replacementpricedate = NOW(),
1412 itemnotes = $item->{'itemnotes'}";
1413 if ($item->{'loan'}) {
1414 $query .= ",notforloan = $item->{'loan'}";
1417 $sth = $dbh->prepare($query);
1419 if (defined $sth->errstr) {
1420 $error .= $sth->errstr;
1425 return($itemnumber,$error);
1429 my ($dbh,$item) = @_;
1430 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1431 # my $dbh=C4Connect;
1432 my $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1433 barcode='$item->{'barcode'}',itemnotes='$item->{'notes'}'
1434 where itemnumber=$item->{'itemnum'}";
1435 if ($item->{'barcode'} eq ''){
1436 $query="update items set biblioitemnumber=$item->{'bibitemnum'},notforloan=$item->{'loan'} where itemnumber=$item->{'itemnum'}";
1438 if ($item->{'lost'} ne ''){
1439 $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1440 barcode='$item->{'barcode'}',
1441 itemnotes='$item->{'notes'}',
1442 homebranch='$item->{'homebranch'}',
1443 itemlost='$item->{'lost'}',
1444 wthdrawn='$item->{'wthdrawn'}'
1445 where itemnumber=$item->{'itemnum'}";
1447 if ($item->{'replacement'} ne ''){
1448 $query=~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1451 my $sth=$dbh->prepare($query);
1457 # FIXME - A nearly-identical function, &delitem, appears in
1460 my ($dbh,$itemnum)=@_;
1461 # my $dbh=C4Connect;
1462 my $query="select * from items where itemnumber=$itemnum";
1463 my $sth=$dbh->prepare($query);
1465 my @data=$sth->fetchrow_array;
1467 $query="Insert into deleteditems values (";
1468 foreach my $temp (@data){
1469 $query=$query."'$temp',"; # FIXME - .=
1473 $sth=$dbh->prepare($query);
1476 $query = "Delete from items where itemnumber=$itemnum";
1477 $sth=$dbh->prepare($query);
1483 sub OLDdeletebiblioitem {
1484 my ($dbh,$biblioitemnumber) = @_;
1485 # my $dbh = C4Connect;
1486 my $query = "Select * from biblioitems
1487 where biblioitemnumber = $biblioitemnumber";
1488 my $sth = $dbh->prepare($query);
1493 if (@results = $sth->fetchrow_array) {
1494 $query = "Insert into deletedbiblioitems values (";
1495 foreach my $value (@results) {
1496 $value = $dbh->quote($value);
1497 $query .= "$value,";
1500 $query =~ s/\,$/\)/;
1503 $query = "Delete from biblioitems
1504 where biblioitemnumber = $biblioitemnumber";
1508 # Now delete all the items attached to the biblioitem
1509 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1510 $sth = $dbh->prepare($query);
1512 while (@results = $sth->fetchrow_array) {
1513 $query = "Insert into deleteditems values (";
1514 foreach my $value (@results) {
1515 $value = $dbh->quote($value);
1516 $query .= "$value,";
1518 $query =~ s/\,$/\)/;
1522 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1525 } # sub deletebiblioitem
1528 my ($dbh,$biblio)=@_;
1529 # my $dbh=C4Connect;
1530 my $query="select * from biblio where biblionumber=$biblio";
1531 my $sth=$dbh->prepare($query);
1533 if (my @data=$sth->fetchrow_array){
1535 $query="Insert into deletedbiblio values (";
1536 foreach my $temp (@data){
1537 $temp=~ s/\'/\\\'/g;
1538 $query=$query."'$temp',"; # FIXME - .=
1542 $sth=$dbh->prepare($query);
1545 $query = "Delete from biblio where biblionumber=$biblio";
1546 $sth=$dbh->prepare($query);
1560 # FIXME - This is the same as &C4::Acquisitions::itemcount, but not
1561 # the same as &C4::Search::itemcount
1562 # Since they're both exported, acqui/acquire.pl doesn't compile with -w.
1565 my $dbh = C4::Context->dbh;
1566 my $query="Select count(*) from items where biblionumber=$biblio";
1568 my $sth=$dbh->prepare($query);
1570 my $data=$sth->fetchrow_hashref;
1572 return($data->{'count(*)'});
1577 my $dbh = C4::Context->dbh;
1578 my $query="Select ordernumber
1580 where biblionumber=? and biblioitemnumber=?";
1581 my $sth=$dbh->prepare($query);
1582 $sth->execute($bib,$bi);
1583 my $ordnum=$sth->fetchrow_hashref;
1585 my $order=getsingleorder($ordnum->{'ordernumber'});
1587 return ($order,$ordnum->{'ordernumber'});
1590 # FIXME - This is practically the same function as
1591 # &C4::Acquisitions::getsingleorder and &C4::Catalogue::getsingleorder
1592 sub getsingleorder {
1594 my $dbh = C4::Context->dbh;
1595 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1596 where aqorders.ordernumber=?
1597 and biblio.biblionumber=aqorders.biblionumber and
1598 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1599 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1600 my $sth=$dbh->prepare($query);
1601 $sth->execute($ordnum);
1602 my $data=$sth->fetchrow_hashref;
1607 # FIXME - This is in effect identical to &C4::Acquisitions::newbiblio.
1608 # Pick one and stick with it.
1611 my $dbh = C4::Context->dbh;
1612 my $bibnum=OLDnewbiblio($dbh,$biblio);
1617 # FIXME - This is in effect the same as &C4::Acquisitions::modbiblio.
1618 # Pick one and stick with it.
1619 # FIXME - Get the POD from C4::Acquisitions
1622 my $dbh = C4::Context->dbh;
1623 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1624 return($biblionumber);
1627 # FIXME - This is in effect identical to &C4::Acquisitions::modsubtitle.
1628 # Pick one and stick with it.
1629 # FIXME - Get the POD from C4::Acquisitions
1631 my ($bibnum, $subtitle) = @_;
1632 my $dbh = C4::Context->dbh;
1633 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1637 # FIXME - This is functionally identical to
1638 # &C4::Acquisitions::modaddauthor
1639 # Pick one and stick with it.
1640 # FIXME - Get the POD from C4::Acquisitions
1642 my ($bibnum, $author) = @_;
1643 my $dbh = C4::Context->dbh;
1644 &OLDmodaddauthor($dbh,$bibnum,$author);
1645 } # sub modaddauthor
1648 # FIXME - This is in effect identical to &C4::Acquisitions::modsubject.
1649 # Pick one and stick with it.
1651 my ($bibnum, $force, @subject) = @_;
1652 my $dbh = C4::Context->dbh;
1653 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1657 # FIXME - This is very similar to &C4::Acquisitions::modbibitem.
1658 # Pick one and stick with it.
1660 my ($biblioitem) = @_;
1661 my $dbh = C4::Context->dbh;
1662 &OLDmodbibitem($dbh,$biblioitem);
1663 my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
1664 &MARCmodbiblio($dbh,$biblioitem->{biblionumber},0,$MARCbibitem);
1667 # FIXME - This is in effect identical to &C4::Acquisitions::modnote.
1668 # Pick one and stick with it.
1670 my ($bibitemnum,$note)=@_;
1671 my $dbh = C4::Context->dbh;
1672 &OLDmodnote($dbh,$bibitemnum,$note);
1675 # FIXME - This is quite similar in effect to &C4::newbiblioitem,
1676 # except for the MARC stuff. There's also a &newbiblioitem in
1677 # acqui.simple/addbookslccn.pl
1679 my ($biblioitem) = @_;
1680 my $dbh = C4::Context->dbh;
1681 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1682 # print STDERR "bibitemnum : $bibitemnum\n";
1683 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1684 # print STDERR $MARCbiblio->as_formatted();
1685 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1686 return($bibitemnum);
1689 # FIXME - This is in effect identical to &C4::Acquisitions::newsubject.
1690 # Pick one and stick with it.
1693 my $dbh = C4::Context->dbh;
1694 &OLDnewsubject($dbh,$bibnum);
1697 # FIXME - This is just a wrapper around &OLDnewsubtitle
1698 # FIXME - This is in effect the same as &C4::Acquisitions::newsubtitle
1700 my ($bibnum, $subtitle) = @_;
1701 my $dbh = C4::Context->dbh;
1702 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1705 # FIXME - This is different from &C4::Acquisitions::newitems, though
1706 # both are exported.
1708 my ($item, @barcodes) = @_;
1709 my $dbh = C4::Context->dbh;
1713 foreach my $barcode (@barcodes) {
1714 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1716 # print STDERR "biblionumber : $item->{biblionumber} / MARCbibid : $MARCbibid / itemnumber : $itemnumber\n";
1717 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1718 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1719 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1720 # print STDERR "MARCmodbiblio called\n";
1725 # FIXME - This appears to be functionally equivalent to
1726 # &C4::Acquisitions::moditem.
1727 # Pick one and stick with it.
1730 # my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1731 my $dbh = C4::Context->dbh;
1732 &OLDmoditem($dbh,$item);
1733 warn "biblionumber : $item->{'biblionumber'} / $item->{'itemnum'}\n";
1734 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1735 warn "before MARCmoditem : $item->{biblionumber}, $item->{'itemnum'}\n";
1736 warn $MARCitem->as_formatted();
1737 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1738 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1739 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1742 # FIXME - This is the same as &C4::Acquisitions::Checkitems.
1743 # Pick one and stick with it.
1745 my ($count,@barcodes)=@_;
1746 my $dbh = C4::Context->dbh;
1748 for (my $i=0;$i<$count;$i++){
1749 $barcodes[$i]=uc $barcodes[$i];
1750 my $query="Select * from items where barcode='$barcodes[$i]'";
1751 my $sth=$dbh->prepare($query);
1753 if (my $data=$sth->fetchrow_hashref){
1754 $error.=" Duplicate Barcode: $barcodes[$i]";
1761 # FIXME - This is identical to &C4::Acquisitions::countitems.
1762 # Pick one and stick with it.
1764 my ($bibitemnum)=@_;
1765 my $dbh = C4::Context->dbh;
1766 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1767 my $sth=$dbh->prepare($query);
1769 my $data=$sth->fetchrow_hashref;
1771 return($data->{'count(*)'});
1774 # FIXME - This is just a wrapper around &OLDdelitem, and acts
1775 # identically to &C4::Acquisitions::delitem
1776 # Pick one and stick with it.
1779 my $dbh = C4::Context->dbh;
1780 &OLDdelitem($dbh,$itemnum);
1783 # FIXME - This is functionally identical to
1784 # &C4::Acquisitions::deletebiblioitem.
1785 # Pick one and stick with it.
1786 sub deletebiblioitem {
1787 my ($biblioitemnumber) = @_;
1788 my $dbh = C4::Context->dbh;
1789 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1790 } # sub deletebiblioitem
1793 # FIXME - This is functionally identical to &C4::Acquisitions::delbiblio.
1794 # Pick one and stick with it.
1797 my $dbh = C4::Context->dbh;
1798 &OLDdelbiblio($dbh,$biblio);
1801 # FIXME - This is identical to &C4::Acquisitions::getitemtypes.
1802 # Pick one and stick with it.
1804 my $dbh = C4::Context->dbh;
1805 my $query = "select * from itemtypes";
1806 my $sth = $dbh->prepare($query);
1807 # || die "Cannot prepare $query" . $dbh->errstr;
1812 # || die "Cannot execute $query\n" . $sth->errstr;
1813 while (my $data = $sth->fetchrow_hashref) {
1814 $results[$count] = $data;
1819 return($count, @results);
1820 } # sub getitemtypes
1823 my ($biblionumber) = @_;
1824 my $dbh = C4::Context->dbh;
1825 my $query = "Select * from biblio where biblionumber = $biblionumber";
1826 my $sth = $dbh->prepare($query);
1827 # || die "Cannot prepare $query\n" . $dbh->errstr;
1832 # || die "Cannot execute $query\n" . $sth->errstr;
1833 while (my $data = $sth->fetchrow_hashref) {
1834 $results[$count] = $data;
1839 return($count, @results);
1842 # FIXME - This is identical to &C4::Acquisitions::getbiblioitem.
1843 # Pick one and stick with it.
1845 my ($biblioitemnum) = @_;
1846 my $dbh = C4::Context->dbh;
1847 my $query = "Select * from biblioitems where
1848 biblioitemnumber = $biblioitemnum";
1849 my $sth = $dbh->prepare($query);
1855 while (my $data = $sth->fetchrow_hashref) {
1856 $results[$count] = $data;
1861 return($count, @results);
1862 } # sub getbiblioitem
1864 # FIXME - This is identical to
1865 # &C4::Acquisitions::getbiblioitembybiblionumber.
1866 # Pick one and stick with it.
1867 sub getbiblioitembybiblionumber {
1868 my ($biblionumber) = @_;
1869 my $dbh = C4::Context->dbh;
1870 my $query = "Select * from biblioitems where biblionumber =
1872 my $sth = $dbh->prepare($query);
1878 while (my $data = $sth->fetchrow_hashref) {
1879 $results[$count] = $data;
1884 return($count, @results);
1887 # FIXME - This is identical to
1888 # &C4::Acquisitions::getbiblioitembybiblionumber.
1889 # Pick one and stick with it.
1890 sub getitemsbybiblioitem {
1891 my ($biblioitemnum) = @_;
1892 my $dbh = C4::Context->dbh;
1893 my $query = "Select * from items, biblio where
1894 biblio.biblionumber = items.biblionumber and biblioitemnumber
1896 my $sth = $dbh->prepare($query);
1897 # || die "Cannot prepare $query\n" . $dbh->errstr;
1902 # || die "Cannot execute $query\n" . $sth->errstr;
1903 while (my $data = $sth->fetchrow_hashref) {
1904 $results[$count] = $data;
1909 return($count, @results);
1910 } # sub getitemsbybiblioitem
1912 # FIXME - This is identical to &C4::Acquisitions::isbnsearch.
1913 # Pick one and stick with it.
1916 my $dbh = C4::Context->dbh;
1922 $isbn = $dbh->quote($isbn);
1923 $query = "Select biblio.* from biblio, biblioitems where
1924 biblio.biblionumber = biblioitems.biblionumber
1926 $sth = $dbh->prepare($query);
1929 while (my $data = $sth->fetchrow_hashref) {
1930 $results[$count] = $data;
1935 return($count, @results);
1939 # At the moment this is just a straight copy of the subject code. Needs heavy
1940 # modification to work for additional authors, obviously.
1941 # Check for additional author changes
1943 # my $newadditionalauthor='';
1944 # my $additionalauthors;
1945 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
1946 # $additionalauthors->{$newadditionalauthor}=1;
1947 # if ($origadditionalauthors->{$newadditionalauthor}) {
1948 # $additionalauthors->{$newadditionalauthor}=2;
1950 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
1951 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
1953 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
1955 # $subfields->{1}->{'Subfield_Mark'}='a';
1956 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
1959 # foreach $Record_ID (@marcrecords) {
1960 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1961 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
1965 # my $origadditionalauthor;
1966 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
1967 # if ($additionalauthors->{$origadditionalauthor} == 1) {
1968 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
1969 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
1970 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
1980 # Subroutine to log changes to databases
1981 # Eventually, this subroutine will be used to create a log of all changes made,
1982 # with the possibility of "undo"ing some changes
1984 if ($database eq 'kohadb') {
1990 print STDERR "KOHA: $type $section $item $original $new\n";
1991 } elsif ($database eq 'marc') {
1993 my $Record_ID=shift;
1996 my $subfield_ID=shift;
1999 print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2003 #------------------------------------------------
2006 #---------------------------------------
2007 # Find a biblio entry, or create a new one if it doesn't exist.
2008 # If a "subtitle" entry is in hash, add it to subtitle table
2009 sub getoraddbiblio {
2013 # FIXME - Unused argument
2014 $biblio, # hash ref to fields
2025 $dbh = C4::Context->dbh;
2027 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2028 $sth=$dbh->prepare("select biblionumber
2030 where title=? and author=?
2031 and copyrightdate=? and seriestitle=?");
2033 $biblio->{title}, $biblio->{author},
2034 $biblio->{copyright}, $biblio->{seriestitle} );
2036 ($biblionumber) = $sth->fetchrow;
2037 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2039 # Doesn't exist. Add new one.
2040 print "<PRE>Adding biblio</PRE>\n" if $debug;
2041 ($biblionumber,$error)=&newbiblio($biblio);
2042 if ( $biblionumber ) {
2043 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
2044 if ( $biblio->{subtitle} ) {
2045 &newsubtitle($biblionumber,$biblio->{subtitle} );
2048 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2052 return $biblionumber,$error;
2054 } # sub getoraddbiblio
2058 # UNUSEFUL SUBs. Could be deleted, kept only until beta test
2059 # maybe useful for some MARC tricks steve used.
2062 sub OLD_MAYBE_DELETED_newBiblioItem {
2063 my ($env, $biblioitem) = @_;
2064 my $dbh = C4::Context->dbh;
2065 my $biblionumber=$biblioitem->{'biblionumber'};
2066 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2067 my $volume=$biblioitem->{'volume'};
2068 my $q_volume=$dbh->quote($volume);
2069 my $number=$biblioitem->{'number'};
2070 my $q_number=$dbh->quote($number);
2071 my $classification=$biblioitem->{'classification'};
2072 my $q_classification=$dbh->quote($classification);
2073 my $itemtype=$biblioitem->{'itemtype'};
2074 my $q_itemtype=$dbh->quote($itemtype);
2075 my $isbn=$biblioitem->{'isbn'};
2076 my $q_isbn=$dbh->quote($isbn);
2077 my $issn=$biblioitem->{'issn'};
2078 my $q_issn=$dbh->quote($issn);
2079 my $dewey=$biblioitem->{'dewey'};
2081 ($dewey == 0) && ($dewey='');
2082 my $subclass=$biblioitem->{'subclass'};
2083 my $q_subclass=$dbh->quote($subclass);
2084 my $publicationyear=$biblioitem->{'publicationyear'};
2085 my $publishercode=$biblioitem->{'publishercode'};
2086 my $q_publishercode=$dbh->quote($publishercode);
2087 my $volumedate=$biblioitem->{'volumedate'};
2088 my $q_volumedate=$dbh->quote($volumedate);
2089 my $illus=$biblioitem->{'illus'};
2090 my $q_illus=$dbh->quote($illus);
2091 my $pages=$biblioitem->{'pages'};
2092 my $q_pages=$dbh->quote($pages);
2093 my $notes=$biblioitem->{'notes'};
2094 my $q_notes=$dbh->quote($notes);
2095 my $size=$biblioitem->{'size'};
2096 my $q_size=$dbh->quote($size);
2097 my $place=$biblioitem->{'place'};
2098 my $q_place=$dbh->quote($place);
2099 my $lccn=$biblioitem->{'lccn'};
2100 my $q_lccn=$dbh->quote($lccn);
2103 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
2106 unless ($env->{'marconly'}) {
2107 #my $sth=$dbh->prepare("lock tables biblioitems write");
2109 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
2111 my ($biblioitemnumber) =$sth->fetchrow;
2112 $biblioitemnumber++;
2113 $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)");
2115 #my $sth=$dbh->prepare("unlock tables");
2120 # Should we check if there is already a biblioitem/amrc with the
2121 # same isbn/lccn/issn?
2123 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
2125 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
2126 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2128 my ($subtitle) = $sth->fetchrow;
2129 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2131 my @additionalauthors;
2132 while (my ($additionalauthor) = $sth->fetchrow) {
2133 push (@additionalauthors, $additionalauthor);
2135 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2138 while (my ($subject) = $sth->fetchrow) {
2139 push (@subjects, $subject);
2144 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
2146 my $Resource_ID=$dbh->{'mysql_insertid'};
2147 my $Record_ID=$Resource_ID;
2148 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
2154 $subfields->{1}->{'Subfield_Mark'}='a';
2155 $subfields->{1}->{'Subfield_Value'}=$title;
2157 $subfields->{2}->{'Subfield_Mark'}='b';
2158 $subfields->{2}->{'Subfield_Value'}=$subtitle;
2161 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2167 $subfields->{1}->{'Subfield_Mark'}='a';
2168 $subfields->{1}->{'Subfield_Value'}=$author;
2170 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2175 $subfields->{1}->{'Subfield_Mark'}='a';
2176 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
2178 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2183 $subfields->{1}->{'Subfield_Mark'}='a';
2184 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
2185 $subfields->{2}->{'Subfield_Mark'}='3';
2186 $subfields->{2}->{'Subfield_Value'}='biblio';
2188 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2190 # Additional Authors
2191 foreach (@additionalauthors) {
2193 (next) unless ($author);
2195 $subfields->{1}->{'Subfield_Mark'}='a';
2196 $subfields->{1}->{'Subfield_Value'}=$author;
2197 $subfields->{2}->{'Subfield_Mark'}='e';
2198 $subfields->{2}->{'Subfield_Value'}='author';
2200 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2204 (next) unless ($illus);
2206 $subfields->{1}->{'Subfield_Mark'}='a';
2207 $subfields->{1}->{'Subfield_Value'}=$illus;
2208 $subfields->{2}->{'Subfield_Mark'}='e';
2209 $subfields->{2}->{'Subfield_Value'}='illustrator';
2211 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2214 foreach (@subjects) {
2216 (next) unless ($subject);
2218 $subfields->{1}->{'Subfield_Mark'}='a';
2219 $subfields->{1}->{'Subfield_Value'}=$subject;
2221 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2228 $subfields->{1}->{'Subfield_Mark'}='a';
2229 $subfields->{1}->{'Subfield_Value'}=$isbn;
2231 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2236 $subfields->{1}->{'Subfield_Mark'}='a';
2237 $subfields->{1}->{'Subfield_Value'}=$lccn;
2239 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2244 $subfields->{1}->{'Subfield_Mark'}='a';
2245 $subfields->{1}->{'Subfield_Value'}=$issn;
2247 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2252 $subfields->{1}->{'Subfield_Mark'}='a';
2253 $subfields->{1}->{'Subfield_Value'}=$dewey;
2255 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2257 # DEWEY subclass and itemtype
2260 $subfields->{1}->{'Subfield_Mark'}='a';
2261 $subfields->{1}->{'Subfield_Value'}=$itemtype;
2262 $subfields->{2}->{'Subfield_Mark'}='b';
2263 $subfields->{2}->{'Subfield_Value'}=$subclass;
2264 $subfields->{3}->{'Subfield_Mark'}='c';
2265 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
2266 $subfields->{4}->{'Subfield_Mark'}='d';
2267 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
2269 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2274 $subfields->{1}->{'Subfield_Mark'}='a';
2275 $subfields->{1}->{'Subfield_Value'}=$place;
2276 $subfields->{2}->{'Subfield_Mark'}='b';
2277 $subfields->{2}->{'Subfield_Value'}=$publishercode;
2278 $subfields->{3}->{'Subfield_Mark'}='c';
2279 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
2280 if ($copyrightdate) {
2281 $subfields->{4}->{'Subfield_Mark'}='c';
2282 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
2285 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2288 if ($pages || $size) {
2290 $subfields->{1}->{'Subfield_Mark'}='a';
2291 $subfields->{1}->{'Subfield_Value'}=$pages;
2292 $subfields->{2}->{'Subfield_Mark'}='c';
2293 $subfields->{2}->{'Subfield_Value'}=$size;
2295 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2298 if ($volume || $number) {
2300 $subfields->{1}->{'Subfield_Mark'}='v';
2301 $subfields->{1}->{'Subfield_Value'}=$volume;
2302 $subfields->{2}->{'Subfield_Mark'}='n';
2303 $subfields->{2}->{'Subfield_Value'}=$number;
2305 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2310 $subfields->{1}->{'Subfield_Mark'}='a';
2311 $subfields->{1}->{'Subfield_Value'}=$notes;
2312 $subfields->{2}->{'Subfield_Mark'}='3';
2313 $subfields->{2}->{'Subfield_Value'}='biblioitem';
2315 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2318 return ($env, $Record_ID);
2321 sub OLD_MAYBE_DELETED_newItem {
2322 my ($env, $Record_ID, $item) = @_;
2323 my $dbh = C4::Context->dbh;
2324 my $barcode=$item->{'barcode'};
2325 my $q_barcode=$dbh->quote($barcode);
2326 my $biblionumber=$item->{'biblionumber'};
2327 my $biblioitemnumber=$item->{'biblioitemnumber'};
2328 my $dateaccessioned=$item->{'dateaccessioned'};
2329 my $booksellerid=$item->{'booksellerid'};
2330 my $q_booksellerid=$dbh->quote($booksellerid);
2331 my $homebranch=$item->{'homebranch'};
2332 my $q_homebranch=$dbh->quote($homebranch);
2333 my $holdingbranch=$item->{'holdingbranch'};
2334 my $price=$item->{'price'};
2335 my $replacementprice=$item->{'replacementprice'};
2336 my $replacementpricedate=$item->{'replacementpricedate'};
2337 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
2338 my $notforloan=$item->{'notforloan'};
2339 my $itemlost=$item->{'itemlost'};
2340 my $wthdrawn=$item->{'wthdrawn'};
2341 my $restricted=$item->{'restricted'};
2342 my $itemnotes=$item->{'itemnotes'};
2343 my $q_itemnotes=$dbh->quote($itemnotes);
2344 my $itemtype=$item->{'itemtype'};
2345 my $subclass=$item->{'subclass'};
2349 unless ($env->{'marconly'}) {
2350 my $sth=$dbh->prepare("select max(itemnumber) from items");
2352 my ($itemnumber) =$sth->fetchrow;
2354 $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)");
2361 $subfields->{1}->{'Subfield_Mark'}='p';
2362 $subfields->{1}->{'Subfield_Value'}=$barcode;
2363 $subfields->{2}->{'Subfield_Mark'}='d';
2364 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
2365 $subfields->{3}->{'Subfield_Mark'}='e';
2366 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
2367 $subfields->{4}->{'Subfield_Mark'}='b';
2368 $subfields->{4}->{'Subfield_Value'}=$homebranch;
2369 $subfields->{5}->{'Subfield_Mark'}='l';
2370 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
2371 $subfields->{6}->{'Subfield_Mark'}='c';
2372 $subfields->{6}->{'Subfield_Value'}=$price;
2373 $subfields->{7}->{'Subfield_Mark'}='c';
2374 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
2375 $subfields->{8}->{'Subfield_Mark'}='d';
2376 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
2378 $subfields->{9}->{'Subfield_Mark'}='h';
2379 $subfields->{9}->{'Subfield_Value'}='Not for loan';
2382 $subfields->{10}->{'Subfield_Mark'}='j';
2383 $subfields->{10}->{'Subfield_Value'}='Item lost';
2386 $subfields->{11}->{'Subfield_Mark'}='j';
2387 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
2390 $subfields->{12}->{'Subfield_Mark'}='z';
2391 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
2395 $env->{'linkage'}=1;
2396 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2397 $env->{'linkage'}=0;
2398 $env->{'linkid'}=$Tag_ID;
2401 $subfields2->{1}->{'Subfield_Mark'}='a';
2402 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
2403 $subfields2->{1}->{'Subfield_Mark'}='b';
2404 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
2405 $subfields2->{1}->{'Subfield_Mark'}='c';
2406 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
2407 $subfields2->{2}->{'Subfield_Mark'}='m';
2408 $subfields2->{2}->{'Subfield_Value'}=$subclass;
2409 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
2410 $env->{'linkid'}='';
2413 sub OLD_MAYBE_DELETED_updateBiblio {
2414 # Update the biblio with biblionumber $biblio->{'biblionumber'}
2415 # I guess this routine should search through all marc records for a record that
2416 # has the same biblionumber stored in it, and modify the MARC record as well as
2419 # Also, this subroutine should search through the $biblio object and compare it
2420 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
2421 # this logging feature to be usable to undo changes easily.
2423 my ($env, $biblio) = @_;
2425 my $biblionumber=$biblio->{'biblionumber'};
2426 my $dbh = C4::Context->dbh;
2427 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
2429 my $origbiblio=$sth->fetchrow_hashref;
2430 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2432 my ($subtitle)=$sth->fetchrow;
2433 $origbiblio->{'subtitle'}=$subtitle;
2434 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2436 my $origadditionalauthors;
2437 while (my ($author) = $sth->fetchrow) {
2438 push (@{$origbiblio->{'additionalauthors'}}, $author);
2439 $origadditionalauthors->{$author}=1;
2441 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2444 while (my ($subject) = $sth->fetchrow) {
2445 push (@{$origbiblio->{'subjects'}}, $subject);
2446 $origsubjects->{$subject}=1;
2450 # Obtain a list of MARC Record_ID's that are tied to this biblio
2451 $sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
2454 while (my ($bibid) = $sth->fetchrow) {
2455 push(@marcrecords, $bibid);
2459 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
2460 my $q_author=$dbh->quote($biblio->{'author'});
2461 logchange('kohadb', 'change', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
2462 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
2464 foreach $bibid (@marcrecords) {
2465 logchange('marc', 'change', $bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2466 changeSubfield($bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2469 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
2470 my $q_title=$dbh->quote($biblio->{'title'});
2471 logchange('kohadb', 'change', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
2472 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
2474 foreach $Record_ID (@marcrecords) {
2475 logchange('marc', 'change', $Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2476 changeSubfield($Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2479 if ($biblio->{'subtitle'} ne $origbiblio->{'subtitle'}) {
2480 my $q_subtitle=$dbh->quote($biblio->{'subtitle'});
2481 logchange('kohadb', 'change', 'biblio', 'subtitle', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2482 my $sti=$dbh->prepare("update bibliosubtitle set subtitle=$q_subtitle where biblionumber=$biblio->{'biblionumber'}");
2484 foreach $Record_ID (@marcrecords) {
2485 logchange('marc', 'change', $Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2486 changeSubfield($Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2489 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
2490 my $q_unititle=$dbh->quote($biblio->{'unititle'});
2491 logchange('kohadb', 'change', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
2492 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
2495 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
2496 my $q_notes=$dbh->quote($biblio->{'notes'});
2497 logchange('kohadb', 'change', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
2498 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
2500 foreach $Record_ID (@marcrecords) {
2501 logchange('marc', 'change', $Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2502 changeSubfield($Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2505 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
2506 my $q_serial=$dbh->quote($biblio->{'serial'});
2507 logchange('kohadb', 'change', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
2508 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
2511 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
2512 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
2513 logchange('kohadb', 'change', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2514 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
2516 foreach $Record_ID (@marcrecords) {
2517 logchange('marc', 'change', $Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2518 changeSubfield($Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2521 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
2522 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
2523 logchange('kohadb', 'change', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
2524 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
2526 foreach $Record_ID (@marcrecords) {
2527 logchange('marc', 'change', $Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2528 changeSubfield($Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2532 # Check for subject heading changes
2536 foreach $newsubject (@{$biblio->{'subject'}}) {
2537 $subjects->{$newsubject}=1;
2538 if ($origsubjects->{$newsubject}) {
2539 $subjects->{$newsubject}=2;
2541 my $q_newsubject=$dbh->quote($newsubject);
2542 my $sth=$dbh->prepare("insert into bibliosubject (subject,biblionumber) values ($q_newsubject, $biblionumber)");
2544 logchange('kohadb', 'add', 'biblio', 'subject', $newsubject);
2546 $subfields->{1}->{'Subfield_Mark'}='a';
2547 $subfields->{1}->{'Subfield_Value'}=$newsubject;
2550 foreach $Record_ID (@marcrecords) {
2551 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2552 logchange('marc', 'add', $Record_ID, '650', 'a', $newsubject);
2557 foreach $origsubject (keys %$origsubjects) {
2558 if ($subjects->{$origsubject} == 1) {
2559 my $q_origsubject=$dbh->quote($origsubject);
2560 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'subject', $origsubject);
2561 my $sth=$dbh->prepare("delete from bibliosubject where biblionumber=$biblionumber and subject=$q_origsubject");
2567 sub OLD_MAYBE_DELETED_updateBiblioItem {
2568 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
2570 # This routine should also check to see which fields are actually being
2571 # modified, and log all changes.
2573 my ($env, $biblioitem) = @_;
2574 my $dbh = C4::Context->dbh;
2576 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2577 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
2578 # obi = original biblioitem
2579 my $obi=$sth->fetchrow_hashref;
2580 $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");
2582 my ($Record_ID) = $sth->fetchrow;
2583 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
2584 logchange('kohadb', 'change', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2585 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
2586 logchange('marc', 'change', $Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2587 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2589 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
2590 logchange('kohadb', 'change', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
2591 my $q_volume=$dbh->quote($biblioitem->{'volume'});
2592 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
2593 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2594 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2596 if ($biblioitem->{'number'} ne $obi->{'number'}) {
2597 logchange('kohadb', 'change', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
2598 my $q_number=$dbh->quote($biblioitem->{'number'});
2599 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
2600 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2601 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2603 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
2604 logchange('kohadb', 'change', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2605 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
2606 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
2607 logchange('marc', 'change', $Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2608 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2610 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
2611 logchange('kohadb', 'change', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
2612 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
2613 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
2614 logchange('marc', 'change', $Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2615 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2617 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
2618 logchange('kohadb', 'change', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
2619 my $q_issn=$dbh->quote($biblioitem->{'issn'});
2620 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
2621 logchange('marc', 'change', $Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2622 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2624 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
2625 logchange('kohadb', 'change', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
2626 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
2627 logchange('marc', 'change', $Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2628 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2630 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
2631 logchange('kohadb', 'change', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
2632 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
2633 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
2634 logchange('marc', 'change', $Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2635 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2637 if ($biblioitem->{'place'} ne $obi->{'place'}) {
2638 logchange('kohadb', 'change', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
2639 my $q_place=$dbh->quote($biblioitem->{'place'});
2640 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
2641 logchange('marc', 'change', $Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2642 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2644 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
2645 logchange('kohadb', 'change', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2646 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
2647 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
2648 logchange('marc', 'change', $Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2649 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2651 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
2652 logchange('kohadb', 'change', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2653 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
2654 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
2655 logchange('marc', 'change', $Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2656 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2658 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
2659 logchange('kohadb', 'change', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
2660 my $q_illus=$dbh->quote($biblioitem->{'illus'});
2661 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
2662 logchange('marc', 'change', $Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2663 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2665 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
2666 logchange('kohadb', 'change', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
2667 my $q_pages=$dbh->quote($biblioitem->{'pages'});
2668 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
2669 logchange('marc', 'change', $Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2670 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2672 if ($biblioitem->{'size'} ne $obi->{'size'}) {
2673 logchange('kohadb', 'change', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
2674 my $q_size=$dbh->quote($biblioitem->{'size'});
2675 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
2676 logchange('marc', 'change', $Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2677 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2679 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
2680 logchange('kohadb', 'change', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
2681 my $q_notes=$dbh->quote($biblioitem->{'notes'});
2682 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
2683 logchange('marc', 'change', $Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2684 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2686 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
2687 logchange('kohadb', 'change', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
2688 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
2689 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
2690 logchange('marc', 'change', $Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2691 changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2696 sub OLD_MAYBE_DELETED_updateItem {
2697 # Update the item with itemnumber $item->{'itemnumber'}
2698 # This routine should also modify the corresponding MARC record data. (852 and
2699 # 876 tags with 876p tag the same as $item->{'barcode'}
2701 # This routine should also check to see which fields are actually being
2702 # modified, and log all changes.
2704 my ($env, $item) = @_;
2705 my $dbh = C4::Context->dbh;
2706 my $itemnumber=$item->{'itemnumber'};
2707 my $biblionumber=$item->{'biblionumber'};
2708 my $biblioitemnumber=$item->{'biblioitemnumber'};
2709 my $barcode=$item->{'barcode'};
2710 my $dateaccessioned=$item->{'dateaccessioned'};
2711 my $booksellerid=$item->{'booksellerid'};
2712 my $homebranch=$item->{'homebranch'};
2713 my $price=$item->{'price'};
2714 my $replacementprice=$item->{'replacementprice'};
2715 my $replacementpricedate=$item->{'replacementpricedate'};
2716 my $multivolume=$item->{'multivolume'};
2717 my $stack=$item->{'stack'};
2718 my $notforloan=$item->{'notforloan'};
2719 my $itemlost=$item->{'itemlost'};
2720 my $wthdrawn=$item->{'wthdrawn'};
2721 my $bulk=$item->{'bulk'};
2722 my $restricted=$item->{'restricted'};
2723 my $binding=$item->{'binding'};
2724 my $itemnotes=$item->{'itemnotes'};
2725 my $holdingbranch=$item->{'holdingbranch'};
2726 my $interim=$item->{'interim'};
2727 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
2729 my $olditem=$sth->fetchrow_hashref;
2730 my $q_barcode=$dbh->quote($olditem->{'barcode'});
2731 $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");
2733 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
2734 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
2736 my ($link) = $sth->fetchrow;
2737 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
2739 my ($Subfield852_ID) = $sth->fetchrow;
2741 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
2742 logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
2743 my $q_barcode=$dbh->quote($item->{'barcode'});
2744 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
2746 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
2747 logchange('marc', 'change', $Record_ID, '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
2749 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
2750 logchange('kohadb', 'change', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
2751 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
2752 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
2754 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
2755 logchange('marc', 'change', $Record_ID, '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
2757 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
2758 logchange('kohadb', 'change', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2759 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
2760 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
2762 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
2763 logchange('marc', 'change', $Record_ID, '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2765 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
2766 logchange('kohadb', 'change', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
2767 my $q_homebranch=$dbh->quote($item->{'homebranch'});
2768 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
2770 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
2771 logchange('marc', 'change', $Record_ID, '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
2773 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
2774 logchange('kohadb', 'change', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2775 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
2776 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
2778 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
2779 logchange('marc', 'change', $Record_ID, '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2781 if ($item->{'price'} ne $olditem->{'price'}) {
2782 logchange('kohadb', 'change', 'items', 'price', $olditem->{'price'}, $item->{'price'});
2783 my $q_price=$dbh->quote($item->{'price'});
2784 my $sth=$dbh->prepare("update items set price=$q_price where itemnumber=$itemnumber");
2786 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'price'}, $item->{'price'}, $Subfield876_ID);
2787 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'price'}, $item->{'price'});
2789 if ($item->{'itemnotes'} ne $olditem->{'itemnotes'}) {
2790 logchange('kohadb', 'change', 'items', 'itemnotes', $olditem->{'itemnotes'}, $item->{'itemnotes'});
2791 my $q_itemnotes=$dbh->quote($item->{'itemnotes'});
2792 my $sth=$dbh->prepare("update items set itemnotes=$q_itemnotes where itemnumber=$itemnumber");
2794 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'itemnotes'}, $item->{'itemnotes'}, $Subfield876_ID);
2795 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'itemnotes'}, $item->{'itemnotes'});
2797 if ($item->{'notforloan'} ne $olditem->{'notforloan'}) {
2798 logchange('kohadb', 'change', 'items', 'notforloan', $olditem->{'notforloan'}, $item->{'notforloan'});
2799 my $sth=$dbh->prepare("update items set notforloan=$notforloan where itemnumber=$itemnumber");
2801 if ($item->{'notforloan'}) {
2802 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2803 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2805 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2806 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2809 if ($item->{'itemlost'} ne $olditem->{'itemlost'}) {
2810 logchange('kohadb', 'change', 'items', 'itemlost', $olditem->{'itemlost'}, $item->{'itemlost'});
2811 my $sth=$dbh->prepare("update items set itemlost=$itemlost where itemnumber=$itemnumber");
2813 if ($item->{'itemlost'}) {
2814 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2815 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2817 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2818 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2821 if ($item->{'wthdrawn'} ne $olditem->{'wthdrawn'}) {
2822 logchange('kohadb', 'change', 'items', 'wthdrawn', $olditem->{'wthdrawn'}, $item->{'wthdrawn'});
2823 my $sth=$dbh->prepare("update items set wthdrawn=$wthdrawn where itemnumber=$itemnumber");
2825 if ($item->{'wthdrawn'}) {
2826 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2827 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2829 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2830 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2833 if ($item->{'restricted'} ne $olditem->{'restricted'}) {
2834 logchange('kohadb', 'change', 'items', 'restricted', $olditem->{'restricted'}, $item->{'restricted'});
2835 my $sth=$dbh->prepare("update items set restricted=$restricted where itemnumber=$itemnumber");
2837 if ($item->{'restricted'}) {
2838 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2839 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2841 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2842 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2848 # Add a biblioitem and related data to Koha database
2849 sub OLD_MAY_BE_DELETED_newcompletebiblioitem {
2854 # FIXME - Unused argument
2855 $biblio, # hash ref to biblio record
2856 $biblioitem, # hash ref to biblioitem record
2857 $subjects, # list ref of subjects
2858 $addlauthors, # list ref of additional authors
2861 my ( $biblionumber, $biblioitemnumber, $error); # return values
2866 my $additionalauthor;
2869 $dbh = C4::Context->dbh;
2871 print "<PRE>Trying to add biblio item Title=$biblio->{title} " .
2872 "ISBN=$biblioitem->{isbn} </PRE>\n" if $debug;
2874 # Make sure master biblio entry exists
2875 ($biblionumber,$error)=getoraddbiblio($dbh, $biblio);
2879 $biblioitem->{biblionumber}=$biblionumber;
2882 $biblioitemnumber=newbiblioitem($biblioitem);
2885 $sth=$dbh->prepare("insert into bibliosubject
2886 (biblionumber,subject)
2888 foreach $subjectheading (@{$subjects} ) {
2889 $sth->execute($biblionumber, $subjectheading)
2890 or $error.=$sth->errstr ;
2894 # Add additional authors
2895 $sth=$dbh->prepare("insert into additionalauthors
2896 (biblionumber,author)
2898 foreach $additionalauthor (@{$addlauthors} ) {
2899 $sth->execute($biblionumber, $additionalauthor)
2900 or $error.=$sth->errstr ;
2904 # couldn't get biblio
2906 $biblioitemnumber='';
2908 } # if no biblio error
2910 return ( $biblionumber, $biblioitemnumber, $error);
2912 } # sub newcompletebiblioitem
2916 # END OF UNUSEFUL SUBs
2920 END { } # module clean-up code here (global destructor)