4 # Revision 1.18 2002/10/11 12:34:53 arensb
5 # Replaced &requireDBI with C4::Context->dbh
7 # Revision 1.17 2002/10/10 14:48:25 tipaul
10 # Revision 1.16 2002/10/07 14:04:26 tipaul
11 # road to 1.3.1 : viewing MARC biblio
13 # Revision 1.15 2002/10/05 09:49:25 arensb
14 # Merged with arensb-context branch: use C4::Context->dbh instead of
15 # &C4Connect, and generally prefer C4::Context over C4::Database.
17 # Revision 1.14 2002/10/03 11:28:18 tipaul
18 # Extending Context.pm to add stopword management and using it in MARC-API.
19 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
21 # Revision 1.13 2002/10/02 16:26:44 tipaul
24 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
25 # Merged in changes from main branch.
27 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
28 # Added a whole mess of FIXME comments.
30 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
31 # Added some missing semicolons.
33 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
34 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
37 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
38 # Added a whole mess of FIXME comments.
40 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
41 # Added some missing semicolons.
43 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
44 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
47 # Revision 1.12 2002/10/01 11:48:51 arensb
48 # Added some FIXME comments, mostly marking duplicate functions.
50 # Revision 1.11 2002/09/24 13:49:26 tipaul
51 # long WAS the road to 1.3.0...
52 # coming VERY SOON NOW...
53 # modifying installer and buildrelease to update the DB
55 # Revision 1.10 2002/09/22 16:50:08 arensb
56 # Added some FIXME comments.
58 # Revision 1.9 2002/09/20 12:57:46 tipaul
59 # long is the road to 1.4.0
60 # * MARCadditem and MARCmoditem now wroks
61 # * various bugfixes in MARC management
62 # !!! 1.3.0 should be released very soon now. Be careful !!!
64 # Revision 1.8 2002/09/10 13:53:52 tipaul
65 # MARC API continued...
67 # * 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)
69 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
71 # Revision 1.7 2002/08/14 18:12:51 tonnesen
72 # Added copyright statement to all .pl and .pm files
74 # Revision 1.6 2002/07/25 13:40:31 tipaul
75 # pod documenting the API.
77 # Revision 1.5 2002/07/24 16:11:37 tipaul
79 # Database.pm and Output.pm are almost not modified (var test...)
81 # Biblio.pm is almost completly rewritten.
83 # WHAT DOES IT ??? ==> END of Hitchcock suspens
85 # 1st, it does... nothing...
86 # 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 ...
88 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
89 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
90 # * 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.
91 # * 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.
92 # 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 ;-)
94 # 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.
95 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
99 # move from 1.2 to 1.4 version :
100 # 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
101 # In the 1.4 version, we want to do 2 differents things :
102 # - keep populating the old-DB, that has a LOT less datas than MARC
103 # - populate the MARC-DB
104 # To populate the DBs we have 2 differents sources :
105 # - the standard acquisition system (through book sellers), that does'nt use MARC data
106 # - the MARC acquisition system, that uses MARC data.
108 # thus, we have 2 differents cases :
109 # - 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
110 # - 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.
111 # we MUST have an API for true MARC data, that populate MARC-DB then old-DB
113 # That's why we need 4 subs :
114 # all subs beginning by MARC manage only MARC tables. They manage MARC-DB with MARC::Record parameters
115 # all subs beginning by OLD manage only OLD-DB tables. They manage old-DB with old-DB parameters
116 # 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
117 # 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.
119 # only ALL and old-style API should be used in koha. MARC and OLD is used internally only
121 # 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.
122 # 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 ;-)
126 # Copyright 2000-2002 Katipo Communications
128 # This file is part of Koha.
130 # Koha is free software; you can redistribute it and/or modify it under the
131 # terms of the GNU General Public License as published by the Free Software
132 # Foundation; either version 2 of the License, or (at your option) any later
135 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
136 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
137 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
139 # You should have received a copy of the GNU General Public License along with
140 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
141 # Suite 330, Boston, MA 02111-1307 USA
149 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
151 # set the version for version checking
156 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
157 # as the old-style API and the ALL one are the only public functions.
160 &updateBiblio &updateBiblioItem &updateItem
161 &itemcount &newbiblio &newbiblioitem
162 &modnote &newsubject &newsubtitle
163 &modbiblio &checkitems
164 &newitems &modbibitem
165 &modsubtitle &modsubject &modaddauthor &moditem &countitems
166 &delitem &deletebiblioitem &delbiblio
167 &getitemtypes &getbiblio
168 &getbiblioitembybiblionumber
169 &getbiblioitem &getitemsbybiblioitem &isbnsearch
171 &newcompletebiblioitem
173 &MARCfind_oldbiblionumber_from_MARCbibid
174 &MARCfind_MARCbibid_from_oldbiblionumber
176 &ALLnewbiblio &ALLnewitem
179 &MARCaddbiblio &MARCadditem
180 &MARCmodsubfield &MARCaddsubfield
181 &MARCmodbiblio &MARCmoditem
183 &MARCkoha2marcBiblio &MARCmarc2koha &MARCkoha2marcItem
184 &MARCgetbiblio &MARCgetitem
185 &MARCaddword &MARCdelword
190 # your exported package globals go here,
191 # as well as any optionally exported functions
193 @EXPORT_OK = qw($Var1 %Hashit); # FIXME - These are never used
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'}";
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',";
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',";
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.
1621 my $dbh = C4::Context->dbh;
1622 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1623 return($biblionumber);
1626 # FIXME - This is in effect identical to &C4::Acquisitions::modsubtitle.
1627 # Pick one and stick with it.
1629 my ($bibnum, $subtitle) = @_;
1630 my $dbh = C4::Context->dbh;
1631 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1635 # FIXME - This is functionally identical to
1636 # &C4::Acquisitions::modaddauthor
1637 # Pick one and stick with it.
1639 my ($bibnum, $author) = @_;
1640 my $dbh = C4::Context->dbh;
1641 &OLDmodaddauthor($dbh,$bibnum,$author);
1642 } # sub modaddauthor
1645 # FIXME - This is in effect identical to &C4::Acquisitions::modsubject.
1646 # Pick one and stick with it.
1648 my ($bibnum, $force, @subject) = @_;
1649 my $dbh = C4::Context->dbh;
1650 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1654 # FIXME - This is very similar to &C4::Acquisitions::modbibitem.
1655 # Pick one and stick with it.
1657 my ($biblioitem) = @_;
1658 my $dbh = C4::Context->dbh;
1659 &OLDmodbibitem($dbh,$biblioitem);
1660 my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
1661 &MARCmodbiblio($dbh,$biblioitem->{biblionumber},0,$MARCbibitem);
1664 # FIXME - This is in effect identical to &C4::Acquisitions::modnote.
1665 # Pick one and stick with it.
1667 my ($bibitemnum,$note)=@_;
1668 my $dbh = C4::Context->dbh;
1669 &OLDmodnote($dbh,$bibitemnum,$note);
1672 # FIXME - This is quite similar in effect to &C4::newbiblioitem,
1673 # except for the MARC stuff. There's also a &newbiblioitem in
1674 # acqui.simple/addbookslccn.pl
1676 my ($biblioitem) = @_;
1677 my $dbh = C4::Context->dbh;
1678 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1679 # print STDERR "bibitemnum : $bibitemnum\n";
1680 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1681 # print STDERR $MARCbiblio->as_formatted();
1682 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1683 return($bibitemnum);
1686 # FIXME - This is in effect identical to &C4::Acquisitions::newsubject.
1687 # Pick one and stick with it.
1690 my $dbh = C4::Context->dbh;
1691 &OLDnewsubject($dbh,$bibnum);
1694 # FIXME - This is just a wrapper around &OLDnewsubtitle
1695 # FIXME - This is in effect the same as &C4::Acquisitions::newsubtitle
1697 my ($bibnum, $subtitle) = @_;
1698 my $dbh = C4::Context->dbh;
1699 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1702 # FIXME - This is different from &C4::Acquisitions::newitems, though
1703 # both are exported.
1705 my ($item, @barcodes) = @_;
1706 my $dbh = C4::Context->dbh;
1710 foreach my $barcode (@barcodes) {
1711 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1713 # print STDERR "biblionumber : $item->{biblionumber} / MARCbibid : $MARCbibid / itemnumber : $itemnumber\n";
1714 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1715 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1716 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1717 # print STDERR "MARCmodbiblio called\n";
1722 # FIXME - This appears to be functionally equivalent to
1723 # &C4::Acquisitions::moditem.
1724 # Pick one and stick with it.
1727 # my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1728 my $dbh = C4::Context->dbh;
1729 &OLDmoditem($dbh,$item);
1730 warn "biblionumber : $item->{'biblionumber'} / $item->{'itemnum'}\n";
1731 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1732 warn "before MARCmoditem : $item->{biblionumber}, $item->{'itemnum'}\n";
1733 warn $MARCitem->as_formatted();
1734 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1735 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1736 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1739 # FIXME - This is the same as &C4::Acquisitions::Checkitems.
1740 # Pick one and stick with it.
1742 my ($count,@barcodes)=@_;
1743 my $dbh = C4::Context->dbh;
1745 for (my $i=0;$i<$count;$i++){
1746 $barcodes[$i]=uc $barcodes[$i];
1747 my $query="Select * from items where barcode='$barcodes[$i]'";
1748 my $sth=$dbh->prepare($query);
1750 if (my $data=$sth->fetchrow_hashref){
1751 $error.=" Duplicate Barcode: $barcodes[$i]";
1758 # FIXME - This is identical to &C4::Acquisitions::countitems.
1759 # Pick one and stick with it.
1761 my ($bibitemnum)=@_;
1762 my $dbh = C4::Context->dbh;
1763 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1764 my $sth=$dbh->prepare($query);
1766 my $data=$sth->fetchrow_hashref;
1768 return($data->{'count(*)'});
1771 # FIXME - This is just a wrapper around &OLDdelitem, and acts
1772 # identically to &C4::Acquisitions::delitem
1773 # Pick one and stick with it.
1776 my $dbh = C4::Context->dbh;
1777 &OLDdelitem($dbh,$itemnum);
1780 # FIXME - This is functionally identical to
1781 # &C4::Acquisitions::deletebiblioitem.
1782 # Pick one and stick with it.
1783 sub deletebiblioitem {
1784 my ($biblioitemnumber) = @_;
1785 my $dbh = C4::Context->dbh;
1786 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1787 } # sub deletebiblioitem
1790 # FIXME - This is functionally identical to &C4::Acquisitions::delbiblio.
1791 # Pick one and stick with it.
1794 my $dbh = C4::Context->dbh;
1795 &OLDdelbiblio($dbh,$biblio);
1798 # FIXME - This is identical to &C4::Acquisitions::getitemtypes.
1799 # Pick one and stick with it.
1801 my $dbh = C4::Context->dbh;
1802 my $query = "select * from itemtypes";
1803 my $sth = $dbh->prepare($query);
1804 # || die "Cannot prepare $query" . $dbh->errstr;
1809 # || die "Cannot execute $query\n" . $sth->errstr;
1810 while (my $data = $sth->fetchrow_hashref) {
1811 $results[$count] = $data;
1816 return($count, @results);
1817 } # sub getitemtypes
1820 my ($biblionumber) = @_;
1821 my $dbh = C4::Context->dbh;
1822 my $query = "Select * from biblio where biblionumber = $biblionumber";
1823 my $sth = $dbh->prepare($query);
1824 # || die "Cannot prepare $query\n" . $dbh->errstr;
1829 # || die "Cannot execute $query\n" . $sth->errstr;
1830 while (my $data = $sth->fetchrow_hashref) {
1831 $results[$count] = $data;
1836 return($count, @results);
1839 # FIXME - This is identical to &C4::Acquisitions::getbiblioitem.
1840 # Pick one and stick with it.
1842 my ($biblioitemnum) = @_;
1843 my $dbh = C4::Context->dbh;
1844 my $query = "Select * from biblioitems where
1845 biblioitemnumber = $biblioitemnum";
1846 my $sth = $dbh->prepare($query);
1852 while (my $data = $sth->fetchrow_hashref) {
1853 $results[$count] = $data;
1858 return($count, @results);
1859 } # sub getbiblioitem
1861 # FIXME - This is identical to
1862 # &C4::Acquisitions::getbiblioitembybiblionumber.
1863 # Pick one and stick with it.
1864 sub getbiblioitembybiblionumber {
1865 my ($biblionumber) = @_;
1866 my $dbh = C4::Context->dbh;
1867 my $query = "Select * from biblioitems where biblionumber =
1869 my $sth = $dbh->prepare($query);
1875 while (my $data = $sth->fetchrow_hashref) {
1876 $results[$count] = $data;
1881 return($count, @results);
1884 # FIXME - This is identical to
1885 # &C4::Acquisitions::getbiblioitembybiblionumber.
1886 # Pick one and stick with it.
1887 sub getitemsbybiblioitem {
1888 my ($biblioitemnum) = @_;
1889 my $dbh = C4::Context->dbh;
1890 my $query = "Select * from items, biblio where
1891 biblio.biblionumber = items.biblionumber and biblioitemnumber
1893 my $sth = $dbh->prepare($query);
1894 # || die "Cannot prepare $query\n" . $dbh->errstr;
1899 # || die "Cannot execute $query\n" . $sth->errstr;
1900 while (my $data = $sth->fetchrow_hashref) {
1901 $results[$count] = $data;
1906 return($count, @results);
1907 } # sub getitemsbybiblioitem
1909 # FIXME - This is identical to &C4::Acquisitions::isbnsearch.
1910 # Pick one and stick with it.
1913 my $dbh = C4::Context->dbh;
1919 $isbn = $dbh->quote($isbn);
1920 $query = "Select biblio.* from biblio, biblioitems where
1921 biblio.biblionumber = biblioitems.biblionumber
1923 $sth = $dbh->prepare($query);
1926 while (my $data = $sth->fetchrow_hashref) {
1927 $results[$count] = $data;
1932 return($count, @results);
1936 # At the moment this is just a straight copy of the subject code. Needs heavy
1937 # modification to work for additional authors, obviously.
1938 # Check for additional author changes
1940 # my $newadditionalauthor='';
1941 # my $additionalauthors;
1942 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
1943 # $additionalauthors->{$newadditionalauthor}=1;
1944 # if ($origadditionalauthors->{$newadditionalauthor}) {
1945 # $additionalauthors->{$newadditionalauthor}=2;
1947 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
1948 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
1950 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
1952 # $subfields->{1}->{'Subfield_Mark'}='a';
1953 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
1956 # foreach $Record_ID (@marcrecords) {
1957 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1958 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
1962 # my $origadditionalauthor;
1963 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
1964 # if ($additionalauthors->{$origadditionalauthor} == 1) {
1965 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
1966 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
1967 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
1977 # Subroutine to log changes to databases
1978 # Eventually, this subroutine will be used to create a log of all changes made,
1979 # with the possibility of "undo"ing some changes
1981 if ($database eq 'kohadb') {
1987 print STDERR "KOHA: $type $section $item $original $new\n";
1988 } elsif ($database eq 'marc') {
1990 my $Record_ID=shift;
1993 my $subfield_ID=shift;
1996 print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2000 #------------------------------------------------
2003 #---------------------------------------
2004 # Find a biblio entry, or create a new one if it doesn't exist.
2005 # If a "subtitle" entry is in hash, add it to subtitle table
2006 sub getoraddbiblio {
2010 # FIXME - Unused argument
2011 $biblio, # hash ref to fields
2022 $dbh = C4::Context->dbh;
2024 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2025 $sth=$dbh->prepare("select biblionumber
2027 where title=? and author=?
2028 and copyrightdate=? and seriestitle=?");
2030 $biblio->{title}, $biblio->{author},
2031 $biblio->{copyright}, $biblio->{seriestitle} );
2033 ($biblionumber) = $sth->fetchrow;
2034 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2036 # Doesn't exist. Add new one.
2037 print "<PRE>Adding biblio</PRE>\n" if $debug;
2038 ($biblionumber,$error)=&newbiblio($biblio);
2039 if ( $biblionumber ) {
2040 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
2041 if ( $biblio->{subtitle} ) {
2042 &newsubtitle($biblionumber,$biblio->{subtitle} );
2045 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2049 return $biblionumber,$error;
2051 } # sub getoraddbiblio
2055 # UNUSEFUL SUBs. Could be deleted, kept only until beta test
2056 # maybe useful for some MARC tricks steve used.
2059 sub OLD_MAYBE_DELETED_newBiblioItem {
2060 my ($env, $biblioitem) = @_;
2061 my $dbh = C4::Context->dbh;
2062 my $biblionumber=$biblioitem->{'biblionumber'};
2063 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2064 my $volume=$biblioitem->{'volume'};
2065 my $q_volume=$dbh->quote($volume);
2066 my $number=$biblioitem->{'number'};
2067 my $q_number=$dbh->quote($number);
2068 my $classification=$biblioitem->{'classification'};
2069 my $q_classification=$dbh->quote($classification);
2070 my $itemtype=$biblioitem->{'itemtype'};
2071 my $q_itemtype=$dbh->quote($itemtype);
2072 my $isbn=$biblioitem->{'isbn'};
2073 my $q_isbn=$dbh->quote($isbn);
2074 my $issn=$biblioitem->{'issn'};
2075 my $q_issn=$dbh->quote($issn);
2076 my $dewey=$biblioitem->{'dewey'};
2078 ($dewey == 0) && ($dewey='');
2079 my $subclass=$biblioitem->{'subclass'};
2080 my $q_subclass=$dbh->quote($subclass);
2081 my $publicationyear=$biblioitem->{'publicationyear'};
2082 my $publishercode=$biblioitem->{'publishercode'};
2083 my $q_publishercode=$dbh->quote($publishercode);
2084 my $volumedate=$biblioitem->{'volumedate'};
2085 my $q_volumedate=$dbh->quote($volumedate);
2086 my $illus=$biblioitem->{'illus'};
2087 my $q_illus=$dbh->quote($illus);
2088 my $pages=$biblioitem->{'pages'};
2089 my $q_pages=$dbh->quote($pages);
2090 my $notes=$biblioitem->{'notes'};
2091 my $q_notes=$dbh->quote($notes);
2092 my $size=$biblioitem->{'size'};
2093 my $q_size=$dbh->quote($size);
2094 my $place=$biblioitem->{'place'};
2095 my $q_place=$dbh->quote($place);
2096 my $lccn=$biblioitem->{'lccn'};
2097 my $q_lccn=$dbh->quote($lccn);
2100 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
2103 unless ($env->{'marconly'}) {
2104 #my $sth=$dbh->prepare("lock tables biblioitems write");
2106 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
2108 my ($biblioitemnumber) =$sth->fetchrow;
2109 $biblioitemnumber++;
2110 $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)");
2112 #my $sth=$dbh->prepare("unlock tables");
2117 # Should we check if there is already a biblioitem/amrc with the
2118 # same isbn/lccn/issn?
2120 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
2122 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
2123 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2125 my ($subtitle) = $sth->fetchrow;
2126 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2128 my @additionalauthors;
2129 while (my ($additionalauthor) = $sth->fetchrow) {
2130 push (@additionalauthors, $additionalauthor);
2132 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2135 while (my ($subject) = $sth->fetchrow) {
2136 push (@subjects, $subject);
2141 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
2143 my $Resource_ID=$dbh->{'mysql_insertid'};
2144 my $Record_ID=$Resource_ID;
2145 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
2151 $subfields->{1}->{'Subfield_Mark'}='a';
2152 $subfields->{1}->{'Subfield_Value'}=$title;
2154 $subfields->{2}->{'Subfield_Mark'}='b';
2155 $subfields->{2}->{'Subfield_Value'}=$subtitle;
2158 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2164 $subfields->{1}->{'Subfield_Mark'}='a';
2165 $subfields->{1}->{'Subfield_Value'}=$author;
2167 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2172 $subfields->{1}->{'Subfield_Mark'}='a';
2173 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
2175 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2180 $subfields->{1}->{'Subfield_Mark'}='a';
2181 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
2182 $subfields->{2}->{'Subfield_Mark'}='3';
2183 $subfields->{2}->{'Subfield_Value'}='biblio';
2185 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2187 # Additional Authors
2188 foreach (@additionalauthors) {
2190 (next) unless ($author);
2192 $subfields->{1}->{'Subfield_Mark'}='a';
2193 $subfields->{1}->{'Subfield_Value'}=$author;
2194 $subfields->{2}->{'Subfield_Mark'}='e';
2195 $subfields->{2}->{'Subfield_Value'}='author';
2197 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2201 (next) unless ($illus);
2203 $subfields->{1}->{'Subfield_Mark'}='a';
2204 $subfields->{1}->{'Subfield_Value'}=$illus;
2205 $subfields->{2}->{'Subfield_Mark'}='e';
2206 $subfields->{2}->{'Subfield_Value'}='illustrator';
2208 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2211 foreach (@subjects) {
2213 (next) unless ($subject);
2215 $subfields->{1}->{'Subfield_Mark'}='a';
2216 $subfields->{1}->{'Subfield_Value'}=$subject;
2218 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2225 $subfields->{1}->{'Subfield_Mark'}='a';
2226 $subfields->{1}->{'Subfield_Value'}=$isbn;
2228 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2233 $subfields->{1}->{'Subfield_Mark'}='a';
2234 $subfields->{1}->{'Subfield_Value'}=$lccn;
2236 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2241 $subfields->{1}->{'Subfield_Mark'}='a';
2242 $subfields->{1}->{'Subfield_Value'}=$issn;
2244 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2249 $subfields->{1}->{'Subfield_Mark'}='a';
2250 $subfields->{1}->{'Subfield_Value'}=$dewey;
2252 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2254 # DEWEY subclass and itemtype
2257 $subfields->{1}->{'Subfield_Mark'}='a';
2258 $subfields->{1}->{'Subfield_Value'}=$itemtype;
2259 $subfields->{2}->{'Subfield_Mark'}='b';
2260 $subfields->{2}->{'Subfield_Value'}=$subclass;
2261 $subfields->{3}->{'Subfield_Mark'}='c';
2262 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
2263 $subfields->{4}->{'Subfield_Mark'}='d';
2264 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
2266 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2271 $subfields->{1}->{'Subfield_Mark'}='a';
2272 $subfields->{1}->{'Subfield_Value'}=$place;
2273 $subfields->{2}->{'Subfield_Mark'}='b';
2274 $subfields->{2}->{'Subfield_Value'}=$publishercode;
2275 $subfields->{3}->{'Subfield_Mark'}='c';
2276 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
2277 if ($copyrightdate) {
2278 $subfields->{4}->{'Subfield_Mark'}='c';
2279 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
2282 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2285 if ($pages || $size) {
2287 $subfields->{1}->{'Subfield_Mark'}='a';
2288 $subfields->{1}->{'Subfield_Value'}=$pages;
2289 $subfields->{2}->{'Subfield_Mark'}='c';
2290 $subfields->{2}->{'Subfield_Value'}=$size;
2292 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2295 if ($volume || $number) {
2297 $subfields->{1}->{'Subfield_Mark'}='v';
2298 $subfields->{1}->{'Subfield_Value'}=$volume;
2299 $subfields->{2}->{'Subfield_Mark'}='n';
2300 $subfields->{2}->{'Subfield_Value'}=$number;
2302 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2307 $subfields->{1}->{'Subfield_Mark'}='a';
2308 $subfields->{1}->{'Subfield_Value'}=$notes;
2309 $subfields->{2}->{'Subfield_Mark'}='3';
2310 $subfields->{2}->{'Subfield_Value'}='biblioitem';
2312 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2315 return ($env, $Record_ID);
2318 sub OLD_MAYBE_DELETED_newItem {
2319 my ($env, $Record_ID, $item) = @_;
2320 my $dbh = C4::Context->dbh;
2321 my $barcode=$item->{'barcode'};
2322 my $q_barcode=$dbh->quote($barcode);
2323 my $biblionumber=$item->{'biblionumber'};
2324 my $biblioitemnumber=$item->{'biblioitemnumber'};
2325 my $dateaccessioned=$item->{'dateaccessioned'};
2326 my $booksellerid=$item->{'booksellerid'};
2327 my $q_booksellerid=$dbh->quote($booksellerid);
2328 my $homebranch=$item->{'homebranch'};
2329 my $q_homebranch=$dbh->quote($homebranch);
2330 my $holdingbranch=$item->{'holdingbranch'};
2331 my $price=$item->{'price'};
2332 my $replacementprice=$item->{'replacementprice'};
2333 my $replacementpricedate=$item->{'replacementpricedate'};
2334 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
2335 my $notforloan=$item->{'notforloan'};
2336 my $itemlost=$item->{'itemlost'};
2337 my $wthdrawn=$item->{'wthdrawn'};
2338 my $restricted=$item->{'restricted'};
2339 my $itemnotes=$item->{'itemnotes'};
2340 my $q_itemnotes=$dbh->quote($itemnotes);
2341 my $itemtype=$item->{'itemtype'};
2342 my $subclass=$item->{'subclass'};
2346 unless ($env->{'marconly'}) {
2347 my $sth=$dbh->prepare("select max(itemnumber) from items");
2349 my ($itemnumber) =$sth->fetchrow;
2351 $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)");
2358 $subfields->{1}->{'Subfield_Mark'}='p';
2359 $subfields->{1}->{'Subfield_Value'}=$barcode;
2360 $subfields->{2}->{'Subfield_Mark'}='d';
2361 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
2362 $subfields->{3}->{'Subfield_Mark'}='e';
2363 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
2364 $subfields->{4}->{'Subfield_Mark'}='b';
2365 $subfields->{4}->{'Subfield_Value'}=$homebranch;
2366 $subfields->{5}->{'Subfield_Mark'}='l';
2367 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
2368 $subfields->{6}->{'Subfield_Mark'}='c';
2369 $subfields->{6}->{'Subfield_Value'}=$price;
2370 $subfields->{7}->{'Subfield_Mark'}='c';
2371 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
2372 $subfields->{8}->{'Subfield_Mark'}='d';
2373 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
2375 $subfields->{9}->{'Subfield_Mark'}='h';
2376 $subfields->{9}->{'Subfield_Value'}='Not for loan';
2379 $subfields->{10}->{'Subfield_Mark'}='j';
2380 $subfields->{10}->{'Subfield_Value'}='Item lost';
2383 $subfields->{11}->{'Subfield_Mark'}='j';
2384 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
2387 $subfields->{12}->{'Subfield_Mark'}='z';
2388 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
2392 $env->{'linkage'}=1;
2393 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2394 $env->{'linkage'}=0;
2395 $env->{'linkid'}=$Tag_ID;
2398 $subfields2->{1}->{'Subfield_Mark'}='a';
2399 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
2400 $subfields2->{1}->{'Subfield_Mark'}='b';
2401 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
2402 $subfields2->{1}->{'Subfield_Mark'}='c';
2403 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
2404 $subfields2->{2}->{'Subfield_Mark'}='m';
2405 $subfields2->{2}->{'Subfield_Value'}=$subclass;
2406 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
2407 $env->{'linkid'}='';
2410 sub OLD_MAYBE_DELETED_updateBiblio {
2411 # Update the biblio with biblionumber $biblio->{'biblionumber'}
2412 # I guess this routine should search through all marc records for a record that
2413 # has the same biblionumber stored in it, and modify the MARC record as well as
2416 # Also, this subroutine should search through the $biblio object and compare it
2417 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
2418 # this logging feature to be usable to undo changes easily.
2420 my ($env, $biblio) = @_;
2422 my $biblionumber=$biblio->{'biblionumber'};
2423 my $dbh = C4::Context->dbh;
2424 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
2426 my $origbiblio=$sth->fetchrow_hashref;
2427 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2429 my ($subtitle)=$sth->fetchrow;
2430 $origbiblio->{'subtitle'}=$subtitle;
2431 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2433 my $origadditionalauthors;
2434 while (my ($author) = $sth->fetchrow) {
2435 push (@{$origbiblio->{'additionalauthors'}}, $author);
2436 $origadditionalauthors->{$author}=1;
2438 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2441 while (my ($subject) = $sth->fetchrow) {
2442 push (@{$origbiblio->{'subjects'}}, $subject);
2443 $origsubjects->{$subject}=1;
2447 # Obtain a list of MARC Record_ID's that are tied to this biblio
2448 $sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
2451 while (my ($bibid) = $sth->fetchrow) {
2452 push(@marcrecords, $bibid);
2456 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
2457 my $q_author=$dbh->quote($biblio->{'author'});
2458 logchange('kohadb', 'change', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
2459 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
2461 foreach $bibid (@marcrecords) {
2462 logchange('marc', 'change', $bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2463 changeSubfield($bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2466 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
2467 my $q_title=$dbh->quote($biblio->{'title'});
2468 logchange('kohadb', 'change', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
2469 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
2471 foreach $Record_ID (@marcrecords) {
2472 logchange('marc', 'change', $Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2473 changeSubfield($Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2476 if ($biblio->{'subtitle'} ne $origbiblio->{'subtitle'}) {
2477 my $q_subtitle=$dbh->quote($biblio->{'subtitle'});
2478 logchange('kohadb', 'change', 'biblio', 'subtitle', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2479 my $sti=$dbh->prepare("update bibliosubtitle set subtitle=$q_subtitle where biblionumber=$biblio->{'biblionumber'}");
2481 foreach $Record_ID (@marcrecords) {
2482 logchange('marc', 'change', $Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2483 changeSubfield($Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2486 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
2487 my $q_unititle=$dbh->quote($biblio->{'unititle'});
2488 logchange('kohadb', 'change', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
2489 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
2492 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
2493 my $q_notes=$dbh->quote($biblio->{'notes'});
2494 logchange('kohadb', 'change', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
2495 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
2497 foreach $Record_ID (@marcrecords) {
2498 logchange('marc', 'change', $Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2499 changeSubfield($Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2502 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
2503 my $q_serial=$dbh->quote($biblio->{'serial'});
2504 logchange('kohadb', 'change', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
2505 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
2508 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
2509 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
2510 logchange('kohadb', 'change', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2511 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
2513 foreach $Record_ID (@marcrecords) {
2514 logchange('marc', 'change', $Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2515 changeSubfield($Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2518 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
2519 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
2520 logchange('kohadb', 'change', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
2521 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
2523 foreach $Record_ID (@marcrecords) {
2524 logchange('marc', 'change', $Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2525 changeSubfield($Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2529 # Check for subject heading changes
2533 foreach $newsubject (@{$biblio->{'subject'}}) {
2534 $subjects->{$newsubject}=1;
2535 if ($origsubjects->{$newsubject}) {
2536 $subjects->{$newsubject}=2;
2538 my $q_newsubject=$dbh->quote($newsubject);
2539 my $sth=$dbh->prepare("insert into bibliosubject (subject,biblionumber) values ($q_newsubject, $biblionumber)");
2541 logchange('kohadb', 'add', 'biblio', 'subject', $newsubject);
2543 $subfields->{1}->{'Subfield_Mark'}='a';
2544 $subfields->{1}->{'Subfield_Value'}=$newsubject;
2547 foreach $Record_ID (@marcrecords) {
2548 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2549 logchange('marc', 'add', $Record_ID, '650', 'a', $newsubject);
2554 foreach $origsubject (keys %$origsubjects) {
2555 if ($subjects->{$origsubject} == 1) {
2556 my $q_origsubject=$dbh->quote($origsubject);
2557 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'subject', $origsubject);
2558 my $sth=$dbh->prepare("delete from bibliosubject where biblionumber=$biblionumber and subject=$q_origsubject");
2564 sub OLD_MAYBE_DELETED_updateBiblioItem {
2565 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
2567 # This routine should also check to see which fields are actually being
2568 # modified, and log all changes.
2570 my ($env, $biblioitem) = @_;
2571 my $dbh = C4::Context->dbh;
2573 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2574 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
2575 # obi = original biblioitem
2576 my $obi=$sth->fetchrow_hashref;
2577 $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");
2579 my ($Record_ID) = $sth->fetchrow;
2580 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
2581 logchange('kohadb', 'change', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2582 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
2583 logchange('marc', 'change', $Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2584 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2586 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
2587 logchange('kohadb', 'change', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
2588 my $q_volume=$dbh->quote($biblioitem->{'volume'});
2589 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
2590 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2591 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2593 if ($biblioitem->{'number'} ne $obi->{'number'}) {
2594 logchange('kohadb', 'change', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
2595 my $q_number=$dbh->quote($biblioitem->{'number'});
2596 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
2597 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2598 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2600 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
2601 logchange('kohadb', 'change', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2602 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
2603 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
2604 logchange('marc', 'change', $Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2605 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2607 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
2608 logchange('kohadb', 'change', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
2609 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
2610 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
2611 logchange('marc', 'change', $Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2612 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2614 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
2615 logchange('kohadb', 'change', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
2616 my $q_issn=$dbh->quote($biblioitem->{'issn'});
2617 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
2618 logchange('marc', 'change', $Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2619 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2621 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
2622 logchange('kohadb', 'change', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
2623 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
2624 logchange('marc', 'change', $Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2625 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2627 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
2628 logchange('kohadb', 'change', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
2629 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
2630 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
2631 logchange('marc', 'change', $Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2632 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2634 if ($biblioitem->{'place'} ne $obi->{'place'}) {
2635 logchange('kohadb', 'change', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
2636 my $q_place=$dbh->quote($biblioitem->{'place'});
2637 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
2638 logchange('marc', 'change', $Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2639 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2641 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
2642 logchange('kohadb', 'change', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2643 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
2644 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
2645 logchange('marc', 'change', $Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2646 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2648 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
2649 logchange('kohadb', 'change', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2650 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
2651 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
2652 logchange('marc', 'change', $Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2653 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2655 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
2656 logchange('kohadb', 'change', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
2657 my $q_illus=$dbh->quote($biblioitem->{'illus'});
2658 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
2659 logchange('marc', 'change', $Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2660 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2662 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
2663 logchange('kohadb', 'change', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
2664 my $q_pages=$dbh->quote($biblioitem->{'pages'});
2665 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
2666 logchange('marc', 'change', $Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2667 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2669 if ($biblioitem->{'size'} ne $obi->{'size'}) {
2670 logchange('kohadb', 'change', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
2671 my $q_size=$dbh->quote($biblioitem->{'size'});
2672 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
2673 logchange('marc', 'change', $Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2674 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2676 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
2677 logchange('kohadb', 'change', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
2678 my $q_notes=$dbh->quote($biblioitem->{'notes'});
2679 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
2680 logchange('marc', 'change', $Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2681 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2683 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
2684 logchange('kohadb', 'change', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
2685 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
2686 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
2687 logchange('marc', 'change', $Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2688 changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2693 sub OLD_MAYBE_DELETED_updateItem {
2694 # Update the item with itemnumber $item->{'itemnumber'}
2695 # This routine should also modify the corresponding MARC record data. (852 and
2696 # 876 tags with 876p tag the same as $item->{'barcode'}
2698 # This routine should also check to see which fields are actually being
2699 # modified, and log all changes.
2701 my ($env, $item) = @_;
2702 my $dbh = C4::Context->dbh;
2703 my $itemnumber=$item->{'itemnumber'};
2704 my $biblionumber=$item->{'biblionumber'};
2705 my $biblioitemnumber=$item->{'biblioitemnumber'};
2706 my $barcode=$item->{'barcode'};
2707 my $dateaccessioned=$item->{'dateaccessioned'};
2708 my $booksellerid=$item->{'booksellerid'};
2709 my $homebranch=$item->{'homebranch'};
2710 my $price=$item->{'price'};
2711 my $replacementprice=$item->{'replacementprice'};
2712 my $replacementpricedate=$item->{'replacementpricedate'};
2713 my $multivolume=$item->{'multivolume'};
2714 my $stack=$item->{'stack'};
2715 my $notforloan=$item->{'notforloan'};
2716 my $itemlost=$item->{'itemlost'};
2717 my $wthdrawn=$item->{'wthdrawn'};
2718 my $bulk=$item->{'bulk'};
2719 my $restricted=$item->{'restricted'};
2720 my $binding=$item->{'binding'};
2721 my $itemnotes=$item->{'itemnotes'};
2722 my $holdingbranch=$item->{'holdingbranch'};
2723 my $interim=$item->{'interim'};
2724 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
2726 my $olditem=$sth->fetchrow_hashref;
2727 my $q_barcode=$dbh->quote($olditem->{'barcode'});
2728 $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");
2730 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
2731 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
2733 my ($link) = $sth->fetchrow;
2734 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
2736 my ($Subfield852_ID) = $sth->fetchrow;
2738 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
2739 logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
2740 my $q_barcode=$dbh->quote($item->{'barcode'});
2741 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
2743 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
2744 logchange('marc', 'change', $Record_ID, '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
2746 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
2747 logchange('kohadb', 'change', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
2748 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
2749 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
2751 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
2752 logchange('marc', 'change', $Record_ID, '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
2754 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
2755 logchange('kohadb', 'change', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2756 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
2757 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
2759 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
2760 logchange('marc', 'change', $Record_ID, '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2762 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
2763 logchange('kohadb', 'change', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
2764 my $q_homebranch=$dbh->quote($item->{'homebranch'});
2765 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
2767 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
2768 logchange('marc', 'change', $Record_ID, '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
2770 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
2771 logchange('kohadb', 'change', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2772 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
2773 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
2775 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
2776 logchange('marc', 'change', $Record_ID, '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2778 if ($item->{'price'} ne $olditem->{'price'}) {
2779 logchange('kohadb', 'change', 'items', 'price', $olditem->{'price'}, $item->{'price'});
2780 my $q_price=$dbh->quote($item->{'price'});
2781 my $sth=$dbh->prepare("update items set price=$q_price where itemnumber=$itemnumber");
2783 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'price'}, $item->{'price'}, $Subfield876_ID);
2784 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'price'}, $item->{'price'});
2786 if ($item->{'itemnotes'} ne $olditem->{'itemnotes'}) {
2787 logchange('kohadb', 'change', 'items', 'itemnotes', $olditem->{'itemnotes'}, $item->{'itemnotes'});
2788 my $q_itemnotes=$dbh->quote($item->{'itemnotes'});
2789 my $sth=$dbh->prepare("update items set itemnotes=$q_itemnotes where itemnumber=$itemnumber");
2791 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'itemnotes'}, $item->{'itemnotes'}, $Subfield876_ID);
2792 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'itemnotes'}, $item->{'itemnotes'});
2794 if ($item->{'notforloan'} ne $olditem->{'notforloan'}) {
2795 logchange('kohadb', 'change', 'items', 'notforloan', $olditem->{'notforloan'}, $item->{'notforloan'});
2796 my $sth=$dbh->prepare("update items set notforloan=$notforloan where itemnumber=$itemnumber");
2798 if ($item->{'notforloan'}) {
2799 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2800 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2802 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2803 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2806 if ($item->{'itemlost'} ne $olditem->{'itemlost'}) {
2807 logchange('kohadb', 'change', 'items', 'itemlost', $olditem->{'itemlost'}, $item->{'itemlost'});
2808 my $sth=$dbh->prepare("update items set itemlost=$itemlost where itemnumber=$itemnumber");
2810 if ($item->{'itemlost'}) {
2811 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2812 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2814 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2815 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2818 if ($item->{'wthdrawn'} ne $olditem->{'wthdrawn'}) {
2819 logchange('kohadb', 'change', 'items', 'wthdrawn', $olditem->{'wthdrawn'}, $item->{'wthdrawn'});
2820 my $sth=$dbh->prepare("update items set wthdrawn=$wthdrawn where itemnumber=$itemnumber");
2822 if ($item->{'wthdrawn'}) {
2823 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2824 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2826 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2827 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2830 if ($item->{'restricted'} ne $olditem->{'restricted'}) {
2831 logchange('kohadb', 'change', 'items', 'restricted', $olditem->{'restricted'}, $item->{'restricted'});
2832 my $sth=$dbh->prepare("update items set restricted=$restricted where itemnumber=$itemnumber");
2834 if ($item->{'restricted'}) {
2835 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2836 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2838 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2839 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2845 # Add a biblioitem and related data to Koha database
2846 sub OLD_MAY_BE_DELETED_newcompletebiblioitem {
2851 # FIXME - Unused argument
2852 $biblio, # hash ref to biblio record
2853 $biblioitem, # hash ref to biblioitem record
2854 $subjects, # list ref of subjects
2855 $addlauthors, # list ref of additional authors
2858 my ( $biblionumber, $biblioitemnumber, $error); # return values
2863 my $additionalauthor;
2866 $dbh = C4::Context->dbh;
2868 print "<PRE>Trying to add biblio item Title=$biblio->{title} " .
2869 "ISBN=$biblioitem->{isbn} </PRE>\n" if $debug;
2871 # Make sure master biblio entry exists
2872 ($biblionumber,$error)=getoraddbiblio($dbh, $biblio);
2876 $biblioitem->{biblionumber}=$biblionumber;
2879 $biblioitemnumber=newbiblioitem($biblioitem);
2882 $sth=$dbh->prepare("insert into bibliosubject
2883 (biblionumber,subject)
2885 foreach $subjectheading (@{$subjects} ) {
2886 $sth->execute($biblionumber, $subjectheading)
2887 or $error.=$sth->errstr ;
2891 # Add additional authors
2892 $sth=$dbh->prepare("insert into additionalauthors
2893 (biblionumber,author)
2895 foreach $additionalauthor (@{$addlauthors} ) {
2896 $sth->execute($biblionumber, $additionalauthor)
2897 or $error.=$sth->errstr ;
2901 # couldn't get biblio
2903 $biblioitemnumber='';
2905 } # if no biblio error
2907 return ( $biblionumber, $biblioitemnumber, $error);
2909 } # sub newcompletebiblioitem
2913 # END OF UNUSEFUL SUBs
2917 END { } # module clean-up code here (global destructor)