4 # Revision 1.15 2002/10/05 09:49:25 arensb
5 # Merged with arensb-context branch: use C4::Context->dbh instead of
6 # &C4Connect, and generally prefer C4::Context over C4::Database.
8 # Revision 1.14 2002/10/03 11:28:18 tipaul
9 # Extending Context.pm to add stopword management and using it in MARC-API.
10 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
12 # Revision 1.13 2002/10/02 16:26:44 tipaul
15 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
16 # Merged in changes from main branch.
18 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
19 # Added a whole mess of FIXME comments.
21 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
22 # Added some missing semicolons.
24 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
25 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
28 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
29 # Added a whole mess of FIXME comments.
31 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
32 # Added some missing semicolons.
34 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
35 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
38 # Revision 1.12 2002/10/01 11:48:51 arensb
39 # Added some FIXME comments, mostly marking duplicate functions.
41 # Revision 1.11 2002/09/24 13:49:26 tipaul
42 # long WAS the road to 1.3.0...
43 # coming VERY SOON NOW...
44 # modifying installer and buildrelease to update the DB
46 # Revision 1.10 2002/09/22 16:50:08 arensb
47 # Added some FIXME comments.
49 # Revision 1.9 2002/09/20 12:57:46 tipaul
50 # long is the road to 1.4.0
51 # * MARCadditem and MARCmoditem now wroks
52 # * various bugfixes in MARC management
53 # !!! 1.3.0 should be released very soon now. Be careful !!!
55 # Revision 1.8 2002/09/10 13:53:52 tipaul
56 # MARC API continued...
58 # * 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)
60 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
62 # Revision 1.7 2002/08/14 18:12:51 tonnesen
63 # Added copyright statement to all .pl and .pm files
65 # Revision 1.6 2002/07/25 13:40:31 tipaul
66 # pod documenting the API.
68 # Revision 1.5 2002/07/24 16:11:37 tipaul
70 # Database.pm and Output.pm are almost not modified (var test...)
72 # Biblio.pm is almost completly rewritten.
74 # WHAT DOES IT ??? ==> END of Hitchcock suspens
76 # 1st, it does... nothing...
77 # 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 ...
79 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
80 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
81 # * 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.
82 # * 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.
83 # 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 ;-)
85 # 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.
86 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
90 # move from 1.2 to 1.4 version :
91 # 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
92 # In the 1.4 version, we want to do 2 differents things :
93 # - keep populating the old-DB, that has a LOT less datas than MARC
94 # - populate the MARC-DB
95 # To populate the DBs we have 2 differents sources :
96 # - the standard acquisition system (through book sellers), that does'nt use MARC data
97 # - the MARC acquisition system, that uses MARC data.
99 # thus, we have 2 differents cases :
100 # - 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
101 # - 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.
102 # we MUST have an API for true MARC data, that populate MARC-DB then old-DB
104 # That's why we need 4 subs :
105 # all subs beginning by MARC manage only MARC tables. They manage MARC-DB with MARC::Record parameters
106 # all subs beginning by OLD manage only OLD-DB tables. They manage old-DB with old-DB parameters
107 # 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
108 # 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.
110 # only ALL and old-style API should be used in koha. MARC and OLD is used internally only
112 # 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.
113 # 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 ;-)
117 # Copyright 2000-2002 Katipo Communications
119 # This file is part of Koha.
121 # Koha is free software; you can redistribute it and/or modify it under the
122 # terms of the GNU General Public License as published by the Free Software
123 # Foundation; either version 2 of the License, or (at your option) any later
126 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
127 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
128 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
130 # You should have received a copy of the GNU General Public License along with
131 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
132 # Suite 330, Boston, MA 02111-1307 USA
140 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
142 # set the version for version checking
147 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
148 # as the old-style API and the ALL one are the only public functions.
151 &updateBiblio &updateBiblioItem &updateItem
152 &itemcount &newbiblio &newbiblioitem
153 &modnote &newsubject &newsubtitle
154 &modbiblio &checkitems
155 &newitems &modbibitem
156 &modsubtitle &modsubject &modaddauthor &moditem &countitems
157 &delitem &deletebiblioitem &delbiblio
158 &getitemtypes &getbiblio
159 &getbiblioitembybiblionumber
160 &getbiblioitem &getitemsbybiblioitem &isbnsearch
162 &newcompletebiblioitem
164 &MARCfind_oldbiblionumber_from_MARCbibid
165 &MARCfind_MARCbibid_from_oldbiblionumber
167 &ALLnewbiblio &ALLnewitem
170 &MARCaddbiblio &MARCadditem
171 &MARCmodsubfield &MARCaddsubfield
172 &MARCmodbiblio &MARCmoditem
174 &MARCkoha2marcBiblio &MARCmarc2koha &MARCkoha2marcItem
175 &MARCgetbiblio &MARCgetitem
176 &MARCaddword &MARCdelword
181 # your exported package globals go here,
182 # as well as any optionally exported functions
184 @EXPORT_OK = qw($Var1 %Hashit); # FIXME - These are never used
188 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
191 # all the following subs takes a MARC::Record as parameter and manage
192 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
193 # ALLxxx subs (xxx deals with old-DB parameters, the ALLxxx deals with MARC-DB parameter)
198 all subs requires/use $dbh as 1st parameter.
199 NOTE : all those subs are private and must be used only inside Biblio.pm (called by a old API sub, or the ALLsub)
203 =head2 @tagslib = &MARCgettagslib($dbh,1|0);
204 last param is 1 for liblibrarian and 0 for libopac
205 returns a hash with tag/subfield meaning
207 =head2 ($tagfield,$tagsubfield) = &MARCfindmarc_from_kohafield($dbh,$kohafield);
208 finds MARC tag and subfield for a given kohafield
209 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
211 =head2 $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
212 finds a old-db biblio number for a given MARCbibid number
214 =head2 $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
215 finds a MARC bibid from a old-db biblionumber
217 =head2 &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
218 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
220 =head2 &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
221 adds a subfield in a biblio (in the MARC tables only).
223 =head2 $MARCRecord = &MARCgetbiblio($dbh,$bibid);
224 Returns a MARC::Record for the biblio $bibid.
226 =head2 &MARCmodbiblio($dbh,$bibid,$delete,$record);
227 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
228 if $delete == 1, every field/subfield not found is deleted in the biblio
229 otherwise, only data passed to MARCmodbiblio is managed.
230 thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
232 =head2 ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
233 MARCmodsubfield changes the value of a given subfield
235 =head2 $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
236 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
237 Returns -1 if more than 1 answer
239 =head2 $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
240 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
242 =head2 &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
243 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
245 =head2 &MARCdelbiblio($dbh,$bibid);
246 MARCdelbiblio delete biblio $bibid
248 =head2 $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
249 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
251 =head2 $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
252 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
254 =head2 $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
255 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
257 =head2 &MARCkoha2marcOnefield => used by MARCkoha2marc and should not be useful elsewhere
259 =head2 $olddb = &MARCmarc2koha($dbh,$MARCRecord);
260 builds a hash with old-db datas from a MARC::Record
262 =head2 &MARCmarc2kohaOnefield => used by MARCmarc2koha and should not be useful elsewhere
264 =head2 MARCaddword => used to manage MARC_word table and should not be useful elsewhere
266 =head2 MARCdelword => used to manage MARC_word table and should not be useful elsewhere
270 Paul POULAIN paul.poulain@free.fr
275 my ($dbh,$forlibrarian)= @_;
277 if ($forlibrarian eq 1) {
278 $sth=$dbh->prepare("select tagfield,liblibrarian as lib from marc_tag_structure");
280 $sth=$dbh->prepare("select tagfield,libopac as lib from marc_tag_structure");
284 while ( ($tag,$lib) = $sth->fetchrow) {
285 $res->{$tag}->{lib}=$lib;
288 if ($forlibrarian eq 1) {
289 $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib from marc_subfield_structure");
291 $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib from marc_subfield_structure");
296 while ( ($tag,$subfield,$lib) = $sth->fetchrow) {
297 $res->{$tag}->{$subfield}=$lib;
302 sub MARCfind_marc_from_kohafield {
303 my ($dbh,$kohafield) = @_;
304 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
305 $sth->execute($kohafield);
306 my ($tagfield,$tagsubfield) = $sth->fetchrow;
307 return ($tagfield,$tagsubfield);
310 sub MARCfind_oldbiblionumber_from_MARCbibid {
311 my ($dbh,$MARCbibid) = @_;
312 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
313 $sth->execute($MARCbibid);
314 my ($biblionumber) = $sth->fetchrow;
315 return $biblionumber;
318 sub MARCfind_MARCbibid_from_oldbiblionumber {
319 my ($dbh,$oldbiblionumber) = @_;
320 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
321 $sth->execute($oldbiblionumber);
322 my ($bibid) = $sth->fetchrow;
327 # pass the MARC::Record to this function, and it will create the records in the marc tables
328 my ($dbh,$record,$biblionumber) = @_;
329 my @fields=$record->fields();
331 # adding main table, and retrieving bibid
332 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
333 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
334 $sth->execute($biblionumber);
335 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
337 ($bibid)=$sth->fetchrow;
340 # now, add subfields...
341 foreach my $field (@fields) {
342 my @subfields=$field->subfields();
344 foreach my $subfieldcount (0..$#subfields) {
345 &MARCaddsubfield($dbh,$bibid,
347 $field->indicator(1).$field->indicator(2),
349 $subfields[$subfieldcount][0],
351 $subfields[$subfieldcount][1]
355 $dbh->do("unlock tables");
360 # pass the MARC::Record to this function, and it will create the records in the marc tables
361 my ($dbh,$record,$biblionumber) = @_;
362 # search for MARC biblionumber
363 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
364 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
365 my @fields=$record->fields();
366 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
367 $sth->execute($bibid);
368 my ($fieldcount) = $sth->fetchrow;
369 # now, add subfields...
370 foreach my $field (@fields) {
371 my @subfields=$field->subfields();
373 foreach my $subfieldcount (0..$#subfields) {
374 &MARCaddsubfield($dbh,$bibid,
376 $field->indicator(1).$field->indicator(2),
378 $subfields[$subfieldcount][0],
380 $subfields[$subfieldcount][1]
384 $dbh->do("unlock tables");
388 sub MARCaddsubfield {
389 # Add a new subfield to a tag into the DB.
390 my ($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
391 # if not value, end of job, we do nothing
392 if (not($subfieldvalue)) {
395 if (not($subfieldcode)) {
398 if (length($subfieldvalue)>255) {
399 # $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
400 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
401 $sth->execute($subfieldvalue);
402 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
404 my ($res)=$sth->fetchrow;
405 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?)");
407 $sth->execute($bibid,'0'.$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
409 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
412 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
414 # $dbh->do("unlock tables");
416 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?)");
417 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
419 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
422 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
427 # Returns MARC::Record of the biblio passed in parameter.
429 my $record = MARC::Record->new();
430 #---- TODO : the leader is missing
431 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
432 from marc_subfield_table
433 where bibid=? order by tagorder,subfieldorder
435 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
436 $sth->execute($bibid);
437 while (my $row=$sth->fetchrow_hashref) {
438 if ($row->{'valuebloblink'}) { #---- search blob if there is one
439 $sth2->execute($row->{'valuebloblink'});
440 my $row2=$sth2->fetchrow_hashref;
442 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
444 if ($record->field($row->{'tag'})) {
446 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
447 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
448 if (length($row->{'tag'}) <3) {
449 $row->{'tag'} = "0".$row->{'tag'};
451 $field =$record->field($row->{'tag'});
453 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
454 $record->delete_field($field);
455 $record->add_fields($field);
458 if (length($row->{'tag'}) < 3) {
459 $row->{'tag'} = "0".$row->{'tag'};
461 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
462 $record->add_fields($temp);
469 # Returns MARC::Record of the biblio passed in parameter.
470 my ($dbh,$bibid,$itemnumber)=@_;
471 warn "MARCgetitem : $bibid, $itemnumber\n";
472 my $record = MARC::Record->new();
473 # search MARC tagorder
474 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=?");
475 $sth2->execute($bibid,$itemnumber);
476 my ($tagorder) = $sth2->fetchrow_array();
477 #---- TODO : the leader is missing
478 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
479 from marc_subfield_table
480 where bibid=? and tagorder=? order by subfieldorder
482 # FIXME - There's already a $sth2 in this scope.
483 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
484 $sth->execute($bibid,$tagorder);
485 while (my $row=$sth->fetchrow_hashref) {
486 if ($row->{'valuebloblink'}) { #---- search blob if there is one
487 $sth2->execute($row->{'valuebloblink'});
488 my $row2=$sth2->fetchrow_hashref;
490 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
492 if ($record->field($row->{'tag'})) {
494 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
495 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
496 if (length($row->{'tag'}) <3) {
497 $row->{'tag'} = "0".$row->{'tag'};
499 $field =$record->field($row->{'tag'});
501 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
502 $record->delete_field($field);
503 $record->add_fields($field);
506 if (length($row->{'tag'}) < 3) {
507 $row->{'tag'} = "0".$row->{'tag'};
509 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
510 $record->add_fields($temp);
518 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
519 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
520 # if nothing to change, don't waste time...
521 if ($oldrecord eq $record) {
524 # otherwise, skip through each subfield...
525 my @fields = $record->fields();
527 foreach my $field (@fields) {
528 my $oldfield = $oldrecord->field($field->tag());
529 my @subfields=$field->subfields();
532 foreach my $subfield (@subfields) {
534 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
535 # just adding datas...
536 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
537 1,@$subfield[0],$subfieldorder,@$subfield[1]);
539 # modify he subfield if it's a different string
540 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
541 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
542 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
550 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
551 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
552 # if nothing to change, don't waste time...
553 if ($oldrecord eq $record) {
556 # otherwise, skip through each subfield...
557 my @fields = $record->fields();
558 # search old MARC item
559 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=?");
560 $sth2->execute($bibid,$itemnumber);
561 my ($tagorder) = $sth2->fetchrow_array();
562 foreach my $field (@fields) {
563 my $oldfield = $oldrecord->field($field->tag());
564 my @subfields=$field->subfields();
566 foreach my $subfield (@subfields) {
568 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
569 # just adding datas...
570 warn "ADD = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
571 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
572 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
574 # modify he subfield if it's a different string
575 warn "MODIFY = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
576 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
577 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
578 warn "MODIFY2 = $bibid, $subfieldid, ".@$subfield[1]."\n";
579 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
588 sub MARCmodsubfield {
589 # Subroutine changes a subfield value given a subfieldid.
590 my ($dbh, $subfieldid, $subfieldvalue )=@_;
591 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
592 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
593 $sth1->execute($subfieldid);
594 my ($oldvaluebloblink)=$sth1->fetchrow;
597 # if too long, use a bloblink
598 if (length($subfieldvalue)>255 ) {
599 # if already a bloblink, update it, otherwise, insert a new one.
600 if ($oldvaluebloblink) {
601 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
602 $sth->execute($subfieldvalue,$oldvaluebloblink);
604 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
605 $sth->execute($subfieldvalue);
606 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
608 my ($res)=$sth->fetchrow;
609 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
610 $sth->execute($subfieldid);
613 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
614 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
615 $sth->execute($subfieldvalue, $subfieldid);
617 $dbh->do("unlock tables");
619 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
620 $sth->execute($subfieldid);
621 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
623 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
624 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
625 return($subfieldid, $subfieldvalue);
628 sub MARCfindsubfield {
629 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
633 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
634 if ($subfieldvalue) {
635 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
637 if ($subfieldorder<1) {
640 $query .= " and subfieldorder=$subfieldorder";
642 my $sti=$dbh->prepare($query);
643 $sti->execute($bibid,$tag, $subfieldcode);
644 while (($subfieldid) = $sti->fetchrow) {
646 $lastsubfieldid=$subfieldid;
648 if ($resultcounter>1) {
649 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
650 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
653 return $lastsubfieldid;
657 sub MARCfindsubfieldid {
658 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
659 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
660 where bibid=? and tag=? and tagorder=?
661 and subfieldcode=? and subfieldorder=?");
662 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
663 my ($res) = $sth->fetchrow;
667 sub MARCdelsubfield {
668 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
669 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
670 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
671 tag='$tag' and tagorder='$tagorder'
672 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
677 # delete a biblio for a $bibid
678 my ($dbh,$bibid) = @_;
679 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
680 $dbh->do("delete from marc_biblio where bibid='$bibid'");
683 sub MARCkoha2marcBiblio {
684 # this function builds partial MARC::Record from the old koha-DB fields
685 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
686 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
687 my $record = MARC::Record->new();
688 #--- if bibid, then retrieve old-style koha data
689 if ($biblionumber>0) {
690 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
691 from biblio where biblionumber=?");
692 $sth2->execute($biblionumber);
693 my $row=$sth2->fetchrow_hashref;
695 foreach $code (keys %$row) {
697 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
701 #--- if biblioitem, then retrieve old-style koha data
702 if ($biblioitemnumber>0) {
703 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
704 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
705 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
707 WHERE biblionumber=? and biblioitemnumber=?
709 $sth2->execute($biblionumber,$biblioitemnumber);
710 my $row=$sth2->fetchrow_hashref;
712 foreach $code (keys %$row) {
714 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
719 # TODO : retrieve notes, additionalauthors
722 sub MARCkoha2marcItem {
723 # this function builds partial MARC::Record from the old koha-DB fields
724 my ($dbh,$biblionumber,$itemnumber) = @_;
725 # my $dbh=&C4Connect;
726 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
727 my $record = MARC::Record->new();
728 #--- if item, then retrieve old-style koha data
730 # print STDERR "prepare $biblionumber,$itemnumber\n";
731 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
732 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
733 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
734 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
736 WHERE itemnumber=?");
737 $sth2->execute($itemnumber);
738 my $row=$sth2->fetchrow_hashref;
740 foreach $code (keys %$row) {
742 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
747 # TODO : retrieve notes, additionalauthors
750 sub MARCkoha2marcSubtitle {
751 # this function builds partial MARC::Record from the old koha-DB fields
752 my ($dbh,$bibnum,$subtitle) = @_;
753 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
754 my $record = MARC::Record->new();
755 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
759 sub MARCkoha2marcOnefield {
760 my ($sth,$record,$kohafieldname,$value)=@_;
763 $sth->execute($kohafieldname);
764 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
765 if ($record->field($tagfield)) {
766 my $tag =$record->field($tagfield);
768 $tag->add_subfields($tagsubfield,$value);
769 $record->delete_field($tag);
770 $record->add_fields($tag);
773 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
780 my ($dbh,$record) = @_;
781 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
783 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
786 # print STDERR $record->as_formatted;
787 while (($field)=$sth2->fetchrow) {
788 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
790 # FIXME - There's already a $sth2 in this scope.
791 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
793 # FIXME - There's already a $field in this scope.
795 while (($field)=$sth2->fetchrow) {
796 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
798 # FIXME - There's already a $sth2 in this scope.
799 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
801 # FIXME - There's already a $field in this scope.
803 while (($field)=$sth2->fetchrow) {
804 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
806 # additional authors : specific
807 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
811 sub MARCmarc2kohaOneField {
812 # to check : if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
813 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
817 $sth->execute($kohatable.".".$kohafield);
818 ($tagfield,$subfield) = $sth->fetchrow;
819 foreach my $field ($record->field($tagfield)) {
820 if ($field->subfield($subfield)) {
821 if ($result->{$kohafield}) {
822 $result->{$kohafield} .= " | ".$field->subfield($subfield);
824 $result->{$kohafield}=$field->subfield($subfield);
832 # split a subfield string and adds it into the word table.
834 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
835 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
836 my @words = split / /,$sentence;
837 # build stopword list
838 # my $sth2 =$dbh->prepare("select word from stopwords");
842 # while(($stopword) = $sth2->fetchrow_array) {
843 # $stopwords->{$stopword} = $stopword;
845 my $stopwords= C4::Context->stopwords;
846 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
847 values (?,?,?,?,?,?,soundex(?))");
848 foreach my $word (@words) {
849 # we record only words longer than 2 car and not in stopwords hash
850 if (length($word)>1 and !($stopwords->{uc($word)})) {
851 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
853 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";
860 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
861 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
862 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
863 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
868 # ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL
871 # all the following subs are useful to manage MARC-DB with complete MARC records.
872 # it's used with marcimport, and marc management tools
877 all subs requires/use $dbh as 1st parameter.
878 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
882 =head2 (oldbibnum,$oldbibitemnum) = ALLnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
883 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
884 are builded from the MARC::Record. If they are passed, they are used.
886 =head2 ALLnewitem($dbh,$olditem);
887 adds an item in the db. $olditem is a old-db hash.
891 Paul POULAIN paul.poulain@free.fr
896 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
897 # note $oldbiblio and $oldbiblioitem are not mandatory.
898 # if not present, they will be builded from $record with MARCmarc2koha function
899 if (($oldbiblio) and not($oldbiblioitem)) {
900 print STDERR "ALLnewbiblio : missing parameter\n";
901 print "ALLnewbiblio : missing parameter : contact koha development team\n";
907 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
908 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
909 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
911 my $olddata = MARCmarc2koha($dbh,$record);
912 $oldbibnum = OLDnewbiblio($dbh,$olddata);
913 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
915 # we must add bibnum and bibitemnum in MARC::Record...
916 # we build the new field with biblionumber and biblioitemnumber
917 # we drop the original field
918 # we add the new builded field.
919 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
920 # (steve and paul : thinks 090 is a good choice)
921 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
922 $sth->execute("biblio.biblionumber");
923 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
924 $sth->execute("biblioitems.biblioitemnumber");
925 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
926 print STDERR "tag1 : $tagfield1 / $tagsubfield1\n tag2 : $tagfield2 / $tagsubfield2\n";
927 if ($tagsubfield1 != $tagsubfield2) {
928 print STDERR "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
929 print "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
932 my $newfield = MARC::Field->new( $tagfield1,'','',
933 "$tagsubfield1" => $oldbibnum,
934 "$tagsubfield2" => $oldbibitemnum);
935 # drop old field and create new one...
936 my $old_field = $record->field($tagfield1);
937 $record->delete_field($old_field);
938 $record->add_fields($newfield);
939 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
940 return ( $oldbibnum,$oldbibitemnum );
944 my ($dbh, $item) = @_;
947 ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{'barcode'});
948 # search MARC biblionumber
949 my $bibid=&MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{'biblionumber'});
951 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
952 $sth->execute($bibid);
953 my ($tagorder) = $sth->fetchrow;
956 # for each field, find MARC tag and subfield, and call the proper MARC sub
957 foreach my $itemkey (keys %$item) {
960 print STDERR "=============> $itemkey : ".$item->{$itemkey}."\n";
961 if ($itemkey eq "biblionumber" || $itemkey eq "biblioitemnumber") {
962 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"biblio.".$itemkey);
964 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"items.".$itemkey);
966 if ($tagfield && $item->{$itemkey} ne 'NULL') {
968 &MARCaddsubfield($dbh,
984 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
990 all subs requires/use $dbh as 1st parameter.
991 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
993 They all are the exact copy of 1.0/1.2 version of the sub
994 without the OLD. The OLDxxx is called by the original xxx sub.
995 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
997 WARNING : there is 1 difference between initialxxx and OLDxxx :
998 the db header $dbh is always passed as parameter
999 to avoid over-DB connexion
1003 =head2 $biblionumber = OLDnewbiblio($dbh,$biblio);
1004 adds a record in biblio table. Datas are in the hash $biblio.
1006 =head2 $biblionumber = OLDmodbiblio($dbh,$biblio);
1007 modify a record in biblio table. Datas are in the hash $biblio.
1009 =head2 OLDmodsubtitle($dbh,$bibnum,$subtitle);
1010 modify subtitles in bibliosubtitle table.
1012 =head2 OLDmodaddauthor($dbh,$bibnum,$author);
1013 adds or modify additional authors
1014 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1016 =head2 $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1017 modify/adds subjects
1019 =head2 OLDmodbibitem($dbh, $biblioitem);
1022 =head2 OLDmodnote($dbh,$bibitemnum,$note
1023 modify a note for a biblioitem
1025 =head2 OLDnewbiblioitem($dbh,$biblioitem);
1026 adds a biblioitem ($biblioitem is a hash with the values)
1028 =head2 OLDnewsubject($dbh,$bibnum);
1030 =head2 OLDnewsubtitle($dbh,$bibnum,$subtitle);
1031 create a new subtitle
1033 =head2 ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1034 create a item. $item is a hash and $barcode the barcode.
1036 =head2 OLDmoditem($dbh,$item);
1039 =head2 OLDdelitem($dbh,$itemnum);
1042 =head2 OLDdeletebiblioitem($dbh,$biblioitemnumber);
1043 deletes a biblioitem
1044 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1046 =head2 OLDdelbiblio($dbh,$biblio);
1051 Paul POULAIN paul.poulain@free.fr
1056 my ($dbh,$biblio) = @_;
1057 # my $dbh = &C4Connect;
1058 my $query = "Select max(biblionumber) from biblio";
1059 my $sth = $dbh->prepare($query);
1061 my $data = $sth->fetchrow_arrayref;
1062 my $bibnum = $$data[0] + 1;
1065 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1066 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1067 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
1068 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
1069 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1070 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1071 if ($biblio->{'seriestitle'}) { $series = 1 };
1074 $query = "insert into biblio set
1075 biblionumber = $bibnum,
1076 title = $biblio->{'title'},
1077 author = $biblio->{'author'},
1078 copyrightdate = $biblio->{'copyright'},
1080 seriestitle = $biblio->{'seriestitle'},
1081 notes = $biblio->{'notes'},
1082 abstract = $biblio->{'abstract'}";
1084 $sth = $dbh->prepare($query);
1093 my ($dbh,$biblio) = @_;
1094 # my $dbh = C4Connect;
1098 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1099 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1100 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1101 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
1102 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
1103 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
1104 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
1105 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1107 $query = "Update biblio set
1108 title = $biblio->{'title'},
1109 author = $biblio->{'author'},
1110 abstract = $biblio->{'abstract'},
1111 copyrightdate = $biblio->{'copyrightdate'},
1112 seriestitle = $biblio->{'seriestitle'},
1113 serial = $biblio->{'serial'},
1114 unititle = $biblio->{'unititle'},
1115 notes = $biblio->{'notes'}
1116 where biblionumber = $biblio->{'biblionumber'}";
1117 $sth = $dbh->prepare($query);
1122 return($biblio->{'biblionumber'});
1125 sub OLDmodsubtitle {
1126 my ($dbh,$bibnum, $subtitle) = @_;
1127 # my $dbh = C4Connect;
1128 my $query = "update bibliosubtitle set
1129 subtitle = '$subtitle'
1130 where biblionumber = $bibnum";
1131 my $sth = $dbh->prepare($query);
1139 sub OLDmodaddauthor {
1140 my ($dbh,$bibnum, $author) = @_;
1141 # my $dbh = C4Connect;
1142 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1143 my $sth = $dbh->prepare($query);
1148 if ($author ne '') {
1149 $query = "Insert into additionalauthors set
1151 biblionumber = '$bibnum'";
1152 $sth = $dbh->prepare($query);
1158 } # sub modaddauthor
1162 my ($dbh,$bibnum, $force, @subject) = @_;
1163 # my $dbh = C4Connect;
1164 my $count = @subject;
1166 for (my $i = 0; $i < $count; $i++) {
1167 $subject[$i] =~ s/^ //g;
1168 $subject[$i] =~ s/ $//g;
1169 my $query = "select * from catalogueentry
1170 where entrytype = 's'
1171 and catalogueentry = '$subject[$i]'";
1172 my $sth = $dbh->prepare($query);
1175 if (my $data = $sth->fetchrow_hashref) {
1177 if ($force eq $subject[$i]) {
1178 # subject not in aut, chosen to force anway
1179 # so insert into cataloguentry so its in auth file
1180 $query = "Insert into catalogueentry
1181 (entrytype,catalogueentry)
1182 values ('s','$subject[$i]')";
1183 my $sth2 = $dbh->prepare($query);
1188 $error = "$subject[$i]\n does not exist in the subject authority file";
1189 $query = "Select * from catalogueentry
1190 where entrytype = 's'
1191 and (catalogueentry like '$subject[$i] %'
1192 or catalogueentry like '% $subject[$i] %'
1193 or catalogueentry like '% $subject[$i]')";
1194 my $sth2 = $dbh->prepare($query);
1197 while (my $data = $sth2->fetchrow_hashref) {
1198 $error = $error."<br>$data->{'catalogueentry'}";
1206 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1207 my $sth = $dbh->prepare($query);
1210 for (my $i = 0; $i < $count; $i++) {
1211 $sth = $dbh->prepare("Insert into bibliosubject
1212 values ('$subject[$i]', $bibnum)");
1224 my ($dbh,$biblioitem) = @_;
1225 # my $dbh = C4Connect;
1228 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1229 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1230 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1231 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1232 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1233 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1234 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1235 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1236 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1237 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1238 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1239 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1240 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1241 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1243 $query = "Update biblioitems set
1244 itemtype = $biblioitem->{'itemtype'},
1245 url = $biblioitem->{'url'},
1246 isbn = $biblioitem->{'isbn'},
1247 publishercode = $biblioitem->{'publishercode'},
1248 publicationyear = $biblioitem->{'publicationyear'},
1249 classification = $biblioitem->{'classification'},
1250 dewey = $biblioitem->{'dewey'},
1251 subclass = $biblioitem->{'subclass'},
1252 illus = $biblioitem->{'illus'},
1253 pages = $biblioitem->{'pages'},
1254 volumeddesc = $biblioitem->{'volumeddesc'},
1255 notes = $biblioitem->{'notes'},
1256 size = $biblioitem->{'size'},
1257 place = $biblioitem->{'place'}
1258 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1266 my ($dbh,$bibitemnum,$note)=@_;
1267 # my $dbh=C4Connect;
1268 my $query="update biblioitems set notes='$note' where
1269 biblioitemnumber='$bibitemnum'";
1270 my $sth=$dbh->prepare($query);
1276 sub OLDnewbiblioitem {
1277 my ($dbh,$biblioitem) = @_;
1278 # my $dbh = C4Connect;
1279 my $query = "Select max(biblioitemnumber) from biblioitems";
1280 my $sth = $dbh->prepare($query);
1284 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
1285 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
1286 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1287 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1288 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1289 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1290 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
1291 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1292 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1293 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1294 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1295 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
1296 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1297 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1298 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1299 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1300 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1301 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1302 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
1303 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
1306 $data = $sth->fetchrow_arrayref;
1307 $bibitemnum = $$data[0] + 1;
1311 $query = "insert into biblioitems set
1312 biblioitemnumber = $bibitemnum,
1313 biblionumber = $biblioitem->{'biblionumber'},
1314 volume = $biblioitem->{'volume'},
1315 number = $biblioitem->{'number'},
1316 classification = $biblioitem->{'classification'},
1317 itemtype = $biblioitem->{'itemtype'},
1318 url = $biblioitem->{'url'},
1319 isbn = $biblioitem->{'isbn'},
1320 issn = $biblioitem->{'issn'},
1321 dewey = $biblioitem->{'dewey'},
1322 subclass = $biblioitem->{'subclass'},
1323 publicationyear = $biblioitem->{'publicationyear'},
1324 publishercode = $biblioitem->{'publishercode'},
1325 volumedate = $biblioitem->{'volumedate'},
1326 volumeddesc = $biblioitem->{'volumeddesc'},
1327 illus = $biblioitem->{'illus'},
1328 pages = $biblioitem->{'pages'},
1329 notes = $biblioitem->{'notes'},
1330 size = $biblioitem->{'size'},
1331 lccn = $biblioitem->{'lccn'},
1332 marc = $biblioitem->{'marc'},
1333 place = $biblioitem->{'place'}";
1335 $sth = $dbh->prepare($query);
1339 return($bibitemnum);
1343 my ($dbh,$bibnum)=@_;
1344 # my $dbh=C4Connect;
1345 my $query="insert into bibliosubject (biblionumber) values
1347 my $sth=$dbh->prepare($query);
1354 sub OLDnewsubtitle {
1355 my ($dbh,$bibnum, $subtitle) = @_;
1356 # my $dbh = C4Connect;
1357 $subtitle = $dbh->quote($subtitle);
1358 my $query = "insert into bibliosubtitle set
1359 biblionumber = $bibnum,
1360 subtitle = $subtitle";
1361 my $sth = $dbh->prepare($query);
1371 my ($dbh,$item, $barcode) = @_;
1372 # my $dbh = C4Connect;
1373 my $query = "Select max(itemnumber) from items";
1374 my $sth = $dbh->prepare($query);
1380 $data = $sth->fetchrow_hashref;
1381 $itemnumber = $data->{'max(itemnumber)'} + 1;
1384 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
1385 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
1386 $item->{'price'} = $dbh->quote($item->{'price'});
1387 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
1388 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
1390 # foreach my $barcode (@barcodes) {
1391 # $barcode = uc($barcode);
1392 $barcode = $dbh->quote($barcode);
1393 $query = "Insert into items set
1394 itemnumber = $itemnumber,
1395 biblionumber = $item->{'biblionumber'},
1396 biblioitemnumber = $item->{'biblioitemnumber'},
1398 booksellerid = $item->{'booksellerid'},
1399 dateaccessioned = NOW(),
1400 homebranch = $item->{'homebranch'},
1401 holdingbranch = $item->{'homebranch'},
1402 price = $item->{'price'},
1403 replacementprice = $item->{'replacementprice'},
1404 replacementpricedate = NOW(),
1405 itemnotes = $item->{'itemnotes'}";
1406 if ($item->{'loan'}) {
1407 $query .= ",notforloan = $item->{'loan'}";
1410 $sth = $dbh->prepare($query);
1412 if (defined $sth->errstr) {
1413 $error .= $sth->errstr;
1418 return($itemnumber,$error);
1422 my ($dbh,$item) = @_;
1423 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1424 # my $dbh=C4Connect;
1425 my $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1426 barcode='$item->{'barcode'}',itemnotes='$item->{'notes'}'
1427 where itemnumber=$item->{'itemnum'}";
1428 if ($item->{'barcode'} eq ''){
1429 $query="update items set biblioitemnumber=$item->{'bibitemnum'},notforloan=$item->{'loan'} where itemnumber=$item->{'itemnum'}";
1431 if ($item->{'lost'} ne ''){
1432 $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1433 barcode='$item->{'barcode'}',
1434 itemnotes='$item->{'notes'}',
1435 homebranch='$item->{'homebranch'}',
1436 itemlost='$item->{'lost'}',
1437 wthdrawn='$item->{'wthdrawn'}'
1438 where itemnumber=$item->{'itemnum'}";
1440 if ($item->{'replacement'} ne ''){
1441 $query=~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1444 my $sth=$dbh->prepare($query);
1450 # FIXME - A nearly-identical function, &delitem, appears in
1453 my ($dbh,$itemnum)=@_;
1454 # my $dbh=C4Connect;
1455 my $query="select * from items where itemnumber=$itemnum";
1456 my $sth=$dbh->prepare($query);
1458 my @data=$sth->fetchrow_array;
1460 $query="Insert into deleteditems values (";
1461 foreach my $temp (@data){
1462 $query=$query."'$temp',";
1466 $sth=$dbh->prepare($query);
1469 $query = "Delete from items where itemnumber=$itemnum";
1470 $sth=$dbh->prepare($query);
1476 sub OLDdeletebiblioitem {
1477 my ($dbh,$biblioitemnumber) = @_;
1478 # my $dbh = C4Connect;
1479 my $query = "Select * from biblioitems
1480 where biblioitemnumber = $biblioitemnumber";
1481 my $sth = $dbh->prepare($query);
1486 if (@results = $sth->fetchrow_array) {
1487 $query = "Insert into deletedbiblioitems values (";
1488 foreach my $value (@results) {
1489 $value = $dbh->quote($value);
1490 $query .= "$value,";
1493 $query =~ s/\,$/\)/;
1496 $query = "Delete from biblioitems
1497 where biblioitemnumber = $biblioitemnumber";
1501 # Now delete all the items attached to the biblioitem
1502 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1503 $sth = $dbh->prepare($query);
1505 while (@results = $sth->fetchrow_array) {
1506 $query = "Insert into deleteditems values (";
1507 foreach my $value (@results) {
1508 $value = $dbh->quote($value);
1509 $query .= "$value,";
1511 $query =~ s/\,$/\)/;
1515 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1518 } # sub deletebiblioitem
1521 my ($dbh,$biblio)=@_;
1522 # my $dbh=C4Connect;
1523 my $query="select * from biblio where biblionumber=$biblio";
1524 my $sth=$dbh->prepare($query);
1526 if (my @data=$sth->fetchrow_array){
1528 $query="Insert into deletedbiblio values (";
1529 foreach my $temp (@data){
1530 $temp=~ s/\'/\\\'/g;
1531 $query=$query."'$temp',";
1535 $sth=$dbh->prepare($query);
1538 $query = "Delete from biblio where biblionumber=$biblio";
1539 $sth=$dbh->prepare($query);
1553 # FIXME - This is the same as &C4::Acquisitions::itemcount, but not
1554 # the same as &C4::Search::itemcount
1555 # Since they're both exported, acqui/acquire.pl doesn't compile with -w.
1558 my $dbh = C4::Context->dbh;
1559 my $query="Select count(*) from items where biblionumber=$biblio";
1561 my $sth=$dbh->prepare($query);
1563 my $data=$sth->fetchrow_hashref;
1565 return($data->{'count(*)'});
1570 my $dbh = C4::Context->dbh;
1571 my $query="Select ordernumber
1573 where biblionumber=? and biblioitemnumber=?";
1574 my $sth=$dbh->prepare($query);
1575 $sth->execute($bib,$bi);
1576 my $ordnum=$sth->fetchrow_hashref;
1578 my $order=getsingleorder($ordnum->{'ordernumber'});
1580 return ($order,$ordnum->{'ordernumber'});
1583 # FIXME - This is practically the same function as
1584 # &C4::Acquisitions::getsingleorder and &C4::Catalogue::getsingleorder
1585 sub getsingleorder {
1587 my $dbh = C4::Context->dbh;
1588 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1589 where aqorders.ordernumber=?
1590 and biblio.biblionumber=aqorders.biblionumber and
1591 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1592 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1593 my $sth=$dbh->prepare($query);
1594 $sth->execute($ordnum);
1595 my $data=$sth->fetchrow_hashref;
1600 # FIXME - This is in effect identical to &C4::Acquisitions::newbiblio.
1601 # Pick one and stick with it.
1604 my $dbh = C4::Context->dbh;
1605 my $bibnum=OLDnewbiblio($dbh,$biblio);
1610 # FIXME - This is in effect the same as &C4::Acquisitions::modbiblio.
1611 # Pick one and stick with it.
1614 my $dbh = C4::Context->dbh;
1615 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1616 return($biblionumber);
1619 # FIXME - This is in effect identical to &C4::Acquisitions::modsubtitle.
1620 # Pick one and stick with it.
1622 my ($bibnum, $subtitle) = @_;
1623 my $dbh = C4::Context->dbh;
1624 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1628 # FIXME - This is functionally identical to
1629 # &C4::Acquisitions::modaddauthor
1630 # Pick one and stick with it.
1632 my ($bibnum, $author) = @_;
1633 my $dbh = C4::Context->dbh;
1634 &OLDmodaddauthor($dbh,$bibnum,$author);
1635 } # sub modaddauthor
1638 # FIXME - This is in effect identical to &C4::Acquisitions::modsubject.
1639 # Pick one and stick with it.
1641 my ($bibnum, $force, @subject) = @_;
1642 my $dbh = C4::Context->dbh;
1643 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1647 # FIXME - This is very similar to &C4::Acquisitions::modbibitem.
1648 # Pick one and stick with it.
1650 my ($biblioitem) = @_;
1651 my $dbh = C4::Context->dbh;
1652 &OLDmodbibitem($dbh,$biblioitem);
1653 my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
1654 &MARCmodbiblio($dbh,$biblioitem->{biblionumber},0,$MARCbibitem);
1657 # FIXME - This is in effect identical to &C4::Acquisitions::modnote.
1658 # Pick one and stick with it.
1660 my ($bibitemnum,$note)=@_;
1661 my $dbh = C4::Context->dbh;
1662 &OLDmodnote($dbh,$bibitemnum,$note);
1665 # FIXME - This is quite similar in effect to &C4::newbiblioitem,
1666 # except for the MARC stuff. There's also a &newbiblioitem in
1667 # acqui.simple/addbookslccn.pl
1669 my ($biblioitem) = @_;
1670 my $dbh = C4::Context->dbh;
1671 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1672 # print STDERR "bibitemnum : $bibitemnum\n";
1673 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1674 # print STDERR $MARCbiblio->as_formatted();
1675 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1676 return($bibitemnum);
1679 # FIXME - This is in effect identical to &C4::Acquisitions::newsubject.
1680 # Pick one and stick with it.
1683 my $dbh = C4::Context->dbh;
1684 &OLDnewsubject($dbh,$bibnum);
1687 # FIXME - This is just a wrapper around &OLDnewsubtitle
1688 # FIXME - This is in effect the same as &C4::Acquisitions::newsubtitle
1690 my ($bibnum, $subtitle) = @_;
1691 my $dbh = C4::Context->dbh;
1692 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1695 # FIXME - This is different from &C4::Acquisitions::newitems, though
1696 # both are exported.
1698 my ($item, @barcodes) = @_;
1699 my $dbh = C4::Context->dbh;
1703 foreach my $barcode (@barcodes) {
1704 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1706 # print STDERR "biblionumber : $item->{biblionumber} / MARCbibid : $MARCbibid / itemnumber : $itemnumber\n";
1707 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1708 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1709 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1710 # print STDERR "MARCmodbiblio called\n";
1715 # FIXME - This appears to be functionally equivalent to
1716 # &C4::Acquisitions::moditem.
1717 # Pick one and stick with it.
1720 # my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1721 my $dbh = C4::Context->dbh;
1722 &OLDmoditem($dbh,$item);
1723 warn "biblionumber : $item->{'biblionumber'} / $item->{'itemnum'}\n";
1724 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1725 warn "before MARCmoditem : $item->{biblionumber}, $item->{'itemnum'}\n";
1726 warn $MARCitem->as_formatted();
1727 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1728 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1729 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1732 # FIXME - This is the same as &C4::Acquisitions::Checkitems.
1733 # Pick one and stick with it.
1735 my ($count,@barcodes)=@_;
1736 my $dbh = C4::Context->dbh;
1738 for (my $i=0;$i<$count;$i++){
1739 $barcodes[$i]=uc $barcodes[$i];
1740 my $query="Select * from items where barcode='$barcodes[$i]'";
1741 my $sth=$dbh->prepare($query);
1743 if (my $data=$sth->fetchrow_hashref){
1744 $error.=" Duplicate Barcode: $barcodes[$i]";
1751 # FIXME - This is identical to &C4::Acquisitions::countitems.
1752 # Pick one and stick with it.
1754 my ($bibitemnum)=@_;
1755 my $dbh = C4::Context->dbh;
1756 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1757 my $sth=$dbh->prepare($query);
1759 my $data=$sth->fetchrow_hashref;
1761 return($data->{'count(*)'});
1764 # FIXME - This is just a wrapper around &OLDdelitem, and acts
1765 # identically to &C4::Acquisitions::delitem
1766 # Pick one and stick with it.
1769 my $dbh = C4::Context->dbh;
1770 &OLDdelitem($dbh,$itemnum);
1773 # FIXME - This is functionally identical to
1774 # &C4::Acquisitions::deletebiblioitem.
1775 # Pick one and stick with it.
1776 sub deletebiblioitem {
1777 my ($biblioitemnumber) = @_;
1778 my $dbh = C4::Context->dbh;
1779 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1780 } # sub deletebiblioitem
1783 # FIXME - This is functionally identical to &C4::Acquisitions::delbiblio.
1784 # Pick one and stick with it.
1787 my $dbh = C4::Context->dbh;
1788 &OLDdelbiblio($dbh,$biblio);
1791 # FIXME - This is identical to &C4::Acquisitions::getitemtypes.
1792 # Pick one and stick with it.
1794 my $dbh = C4::Context->dbh;
1795 my $query = "select * from itemtypes";
1796 my $sth = $dbh->prepare($query);
1797 # || die "Cannot prepare $query" . $dbh->errstr;
1802 # || die "Cannot execute $query\n" . $sth->errstr;
1803 while (my $data = $sth->fetchrow_hashref) {
1804 $results[$count] = $data;
1809 return($count, @results);
1810 } # sub getitemtypes
1813 my ($biblionumber) = @_;
1814 my $dbh = C4::Context->dbh;
1815 my $query = "Select * from biblio where biblionumber = $biblionumber";
1816 my $sth = $dbh->prepare($query);
1817 # || die "Cannot prepare $query\n" . $dbh->errstr;
1822 # || die "Cannot execute $query\n" . $sth->errstr;
1823 while (my $data = $sth->fetchrow_hashref) {
1824 $results[$count] = $data;
1829 return($count, @results);
1832 # FIXME - This is identical to &C4::Acquisitions::getbiblioitem.
1833 # Pick one and stick with it.
1835 my ($biblioitemnum) = @_;
1836 my $dbh = C4::Context->dbh;
1837 my $query = "Select * from biblioitems where
1838 biblioitemnumber = $biblioitemnum";
1839 my $sth = $dbh->prepare($query);
1845 while (my $data = $sth->fetchrow_hashref) {
1846 $results[$count] = $data;
1851 return($count, @results);
1852 } # sub getbiblioitem
1854 # FIXME - This is identical to
1855 # &C4::Acquisitions::getbiblioitembybiblionumber.
1856 # Pick one and stick with it.
1857 sub getbiblioitembybiblionumber {
1858 my ($biblionumber) = @_;
1859 my $dbh = C4::Context->dbh;
1860 my $query = "Select * from biblioitems where biblionumber =
1862 my $sth = $dbh->prepare($query);
1868 while (my $data = $sth->fetchrow_hashref) {
1869 $results[$count] = $data;
1874 return($count, @results);
1877 # FIXME - This is identical to
1878 # &C4::Acquisitions::getbiblioitembybiblionumber.
1879 # Pick one and stick with it.
1880 sub getitemsbybiblioitem {
1881 my ($biblioitemnum) = @_;
1882 my $dbh = C4::Context->dbh;
1883 my $query = "Select * from items, biblio where
1884 biblio.biblionumber = items.biblionumber and biblioitemnumber
1886 my $sth = $dbh->prepare($query);
1887 # || die "Cannot prepare $query\n" . $dbh->errstr;
1892 # || die "Cannot execute $query\n" . $sth->errstr;
1893 while (my $data = $sth->fetchrow_hashref) {
1894 $results[$count] = $data;
1899 return($count, @results);
1900 } # sub getitemsbybiblioitem
1902 # FIXME - This is identical to &C4::Acquisitions::isbnsearch.
1903 # Pick one and stick with it.
1906 my $dbh = C4::Context->dbh;
1912 $isbn = $dbh->quote($isbn);
1913 $query = "Select biblio.* from biblio, biblioitems where
1914 biblio.biblionumber = biblioitems.biblionumber
1916 $sth = $dbh->prepare($query);
1919 while (my $data = $sth->fetchrow_hashref) {
1920 $results[$count] = $data;
1925 return($count, @results);
1929 # At the moment this is just a straight copy of the subject code. Needs heavy
1930 # modification to work for additional authors, obviously.
1931 # Check for additional author changes
1933 # my $newadditionalauthor='';
1934 # my $additionalauthors;
1935 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
1936 # $additionalauthors->{$newadditionalauthor}=1;
1937 # if ($origadditionalauthors->{$newadditionalauthor}) {
1938 # $additionalauthors->{$newadditionalauthor}=2;
1940 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
1941 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
1943 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
1945 # $subfields->{1}->{'Subfield_Mark'}='a';
1946 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
1949 # foreach $Record_ID (@marcrecords) {
1950 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1951 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
1955 # my $origadditionalauthor;
1956 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
1957 # if ($additionalauthors->{$origadditionalauthor} == 1) {
1958 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
1959 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
1960 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
1970 # Subroutine to log changes to databases
1971 # Eventually, this subroutine will be used to create a log of all changes made,
1972 # with the possibility of "undo"ing some changes
1974 if ($database eq 'kohadb') {
1980 print STDERR "KOHA: $type $section $item $original $new\n";
1981 } elsif ($database eq 'marc') {
1983 my $Record_ID=shift;
1986 my $subfield_ID=shift;
1989 print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
1993 #------------------------------------------------
1996 #---------------------------------------
1997 # Find a biblio entry, or create a new one if it doesn't exist.
1998 # If a "subtitle" entry is in hash, add it to subtitle table
1999 sub getoraddbiblio {
2003 $biblio, # hash ref to fields
2014 requireDBI($dbh,"getoraddbiblio");
2016 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2017 $sth=$dbh->prepare("select biblionumber
2019 where title=? and author=?
2020 and copyrightdate=? and seriestitle=?");
2022 $biblio->{title}, $biblio->{author},
2023 $biblio->{copyright}, $biblio->{seriestitle} );
2025 ($biblionumber) = $sth->fetchrow;
2026 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2028 # Doesn't exist. Add new one.
2029 print "<PRE>Adding biblio</PRE>\n" if $debug;
2030 ($biblionumber,$error)=&newbiblio($biblio);
2031 if ( $biblionumber ) {
2032 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
2033 if ( $biblio->{subtitle} ) {
2034 &newsubtitle($biblionumber,$biblio->{subtitle} );
2037 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2041 return $biblionumber,$error;
2043 } # sub getoraddbiblio
2047 # UNUSEFUL SUBs. Could be deleted, kept only until beta test
2048 # maybe useful for some MARC tricks steve used.
2051 sub OLD_MAYBE_DELETED_newBiblioItem {
2052 my ($env, $biblioitem) = @_;
2053 my $dbh = C4::Context->dbh;
2054 my $biblionumber=$biblioitem->{'biblionumber'};
2055 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2056 my $volume=$biblioitem->{'volume'};
2057 my $q_volume=$dbh->quote($volume);
2058 my $number=$biblioitem->{'number'};
2059 my $q_number=$dbh->quote($number);
2060 my $classification=$biblioitem->{'classification'};
2061 my $q_classification=$dbh->quote($classification);
2062 my $itemtype=$biblioitem->{'itemtype'};
2063 my $q_itemtype=$dbh->quote($itemtype);
2064 my $isbn=$biblioitem->{'isbn'};
2065 my $q_isbn=$dbh->quote($isbn);
2066 my $issn=$biblioitem->{'issn'};
2067 my $q_issn=$dbh->quote($issn);
2068 my $dewey=$biblioitem->{'dewey'};
2070 ($dewey == 0) && ($dewey='');
2071 my $subclass=$biblioitem->{'subclass'};
2072 my $q_subclass=$dbh->quote($subclass);
2073 my $publicationyear=$biblioitem->{'publicationyear'};
2074 my $publishercode=$biblioitem->{'publishercode'};
2075 my $q_publishercode=$dbh->quote($publishercode);
2076 my $volumedate=$biblioitem->{'volumedate'};
2077 my $q_volumedate=$dbh->quote($volumedate);
2078 my $illus=$biblioitem->{'illus'};
2079 my $q_illus=$dbh->quote($illus);
2080 my $pages=$biblioitem->{'pages'};
2081 my $q_pages=$dbh->quote($pages);
2082 my $notes=$biblioitem->{'notes'};
2083 my $q_notes=$dbh->quote($notes);
2084 my $size=$biblioitem->{'size'};
2085 my $q_size=$dbh->quote($size);
2086 my $place=$biblioitem->{'place'};
2087 my $q_place=$dbh->quote($place);
2088 my $lccn=$biblioitem->{'lccn'};
2089 my $q_lccn=$dbh->quote($lccn);
2092 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
2095 unless ($env->{'marconly'}) {
2096 #my $sth=$dbh->prepare("lock tables biblioitems write");
2098 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
2100 my ($biblioitemnumber) =$sth->fetchrow;
2101 $biblioitemnumber++;
2102 $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)");
2104 #my $sth=$dbh->prepare("unlock tables");
2109 # Should we check if there is already a biblioitem/amrc with the
2110 # same isbn/lccn/issn?
2112 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
2114 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
2115 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2117 my ($subtitle) = $sth->fetchrow;
2118 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2120 my @additionalauthors;
2121 while (my ($additionalauthor) = $sth->fetchrow) {
2122 push (@additionalauthors, $additionalauthor);
2124 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2127 while (my ($subject) = $sth->fetchrow) {
2128 push (@subjects, $subject);
2133 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
2135 my $Resource_ID=$dbh->{'mysql_insertid'};
2136 my $Record_ID=$Resource_ID;
2137 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
2143 $subfields->{1}->{'Subfield_Mark'}='a';
2144 $subfields->{1}->{'Subfield_Value'}=$title;
2146 $subfields->{2}->{'Subfield_Mark'}='b';
2147 $subfields->{2}->{'Subfield_Value'}=$subtitle;
2150 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2156 $subfields->{1}->{'Subfield_Mark'}='a';
2157 $subfields->{1}->{'Subfield_Value'}=$author;
2159 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2164 $subfields->{1}->{'Subfield_Mark'}='a';
2165 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
2167 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2172 $subfields->{1}->{'Subfield_Mark'}='a';
2173 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
2174 $subfields->{2}->{'Subfield_Mark'}='3';
2175 $subfields->{2}->{'Subfield_Value'}='biblio';
2177 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2179 # Additional Authors
2180 foreach (@additionalauthors) {
2182 (next) unless ($author);
2184 $subfields->{1}->{'Subfield_Mark'}='a';
2185 $subfields->{1}->{'Subfield_Value'}=$author;
2186 $subfields->{2}->{'Subfield_Mark'}='e';
2187 $subfields->{2}->{'Subfield_Value'}='author';
2189 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2193 (next) unless ($illus);
2195 $subfields->{1}->{'Subfield_Mark'}='a';
2196 $subfields->{1}->{'Subfield_Value'}=$illus;
2197 $subfields->{2}->{'Subfield_Mark'}='e';
2198 $subfields->{2}->{'Subfield_Value'}='illustrator';
2200 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2203 foreach (@subjects) {
2205 (next) unless ($subject);
2207 $subfields->{1}->{'Subfield_Mark'}='a';
2208 $subfields->{1}->{'Subfield_Value'}=$subject;
2210 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2217 $subfields->{1}->{'Subfield_Mark'}='a';
2218 $subfields->{1}->{'Subfield_Value'}=$isbn;
2220 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2225 $subfields->{1}->{'Subfield_Mark'}='a';
2226 $subfields->{1}->{'Subfield_Value'}=$lccn;
2228 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2233 $subfields->{1}->{'Subfield_Mark'}='a';
2234 $subfields->{1}->{'Subfield_Value'}=$issn;
2236 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2241 $subfields->{1}->{'Subfield_Mark'}='a';
2242 $subfields->{1}->{'Subfield_Value'}=$dewey;
2244 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2246 # DEWEY subclass and itemtype
2249 $subfields->{1}->{'Subfield_Mark'}='a';
2250 $subfields->{1}->{'Subfield_Value'}=$itemtype;
2251 $subfields->{2}->{'Subfield_Mark'}='b';
2252 $subfields->{2}->{'Subfield_Value'}=$subclass;
2253 $subfields->{3}->{'Subfield_Mark'}='c';
2254 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
2255 $subfields->{4}->{'Subfield_Mark'}='d';
2256 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
2258 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2263 $subfields->{1}->{'Subfield_Mark'}='a';
2264 $subfields->{1}->{'Subfield_Value'}=$place;
2265 $subfields->{2}->{'Subfield_Mark'}='b';
2266 $subfields->{2}->{'Subfield_Value'}=$publishercode;
2267 $subfields->{3}->{'Subfield_Mark'}='c';
2268 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
2269 if ($copyrightdate) {
2270 $subfields->{4}->{'Subfield_Mark'}='c';
2271 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
2274 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2277 if ($pages || $size) {
2279 $subfields->{1}->{'Subfield_Mark'}='a';
2280 $subfields->{1}->{'Subfield_Value'}=$pages;
2281 $subfields->{2}->{'Subfield_Mark'}='c';
2282 $subfields->{2}->{'Subfield_Value'}=$size;
2284 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2287 if ($volume || $number) {
2289 $subfields->{1}->{'Subfield_Mark'}='v';
2290 $subfields->{1}->{'Subfield_Value'}=$volume;
2291 $subfields->{2}->{'Subfield_Mark'}='n';
2292 $subfields->{2}->{'Subfield_Value'}=$number;
2294 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2299 $subfields->{1}->{'Subfield_Mark'}='a';
2300 $subfields->{1}->{'Subfield_Value'}=$notes;
2301 $subfields->{2}->{'Subfield_Mark'}='3';
2302 $subfields->{2}->{'Subfield_Value'}='biblioitem';
2304 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2307 return ($env, $Record_ID);
2310 sub OLD_MAYBE_DELETED_newItem {
2311 my ($env, $Record_ID, $item) = @_;
2312 my $dbh = C4::Context->dbh;
2313 my $barcode=$item->{'barcode'};
2314 my $q_barcode=$dbh->quote($barcode);
2315 my $biblionumber=$item->{'biblionumber'};
2316 my $biblioitemnumber=$item->{'biblioitemnumber'};
2317 my $dateaccessioned=$item->{'dateaccessioned'};
2318 my $booksellerid=$item->{'booksellerid'};
2319 my $q_booksellerid=$dbh->quote($booksellerid);
2320 my $homebranch=$item->{'homebranch'};
2321 my $q_homebranch=$dbh->quote($homebranch);
2322 my $holdingbranch=$item->{'holdingbranch'};
2323 my $price=$item->{'price'};
2324 my $replacementprice=$item->{'replacementprice'};
2325 my $replacementpricedate=$item->{'replacementpricedate'};
2326 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
2327 my $notforloan=$item->{'notforloan'};
2328 my $itemlost=$item->{'itemlost'};
2329 my $wthdrawn=$item->{'wthdrawn'};
2330 my $restricted=$item->{'restricted'};
2331 my $itemnotes=$item->{'itemnotes'};
2332 my $q_itemnotes=$dbh->quote($itemnotes);
2333 my $itemtype=$item->{'itemtype'};
2334 my $subclass=$item->{'subclass'};
2338 unless ($env->{'marconly'}) {
2339 my $sth=$dbh->prepare("select max(itemnumber) from items");
2341 my ($itemnumber) =$sth->fetchrow;
2343 $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)");
2350 $subfields->{1}->{'Subfield_Mark'}='p';
2351 $subfields->{1}->{'Subfield_Value'}=$barcode;
2352 $subfields->{2}->{'Subfield_Mark'}='d';
2353 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
2354 $subfields->{3}->{'Subfield_Mark'}='e';
2355 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
2356 $subfields->{4}->{'Subfield_Mark'}='b';
2357 $subfields->{4}->{'Subfield_Value'}=$homebranch;
2358 $subfields->{5}->{'Subfield_Mark'}='l';
2359 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
2360 $subfields->{6}->{'Subfield_Mark'}='c';
2361 $subfields->{6}->{'Subfield_Value'}=$price;
2362 $subfields->{7}->{'Subfield_Mark'}='c';
2363 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
2364 $subfields->{8}->{'Subfield_Mark'}='d';
2365 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
2367 $subfields->{9}->{'Subfield_Mark'}='h';
2368 $subfields->{9}->{'Subfield_Value'}='Not for loan';
2371 $subfields->{10}->{'Subfield_Mark'}='j';
2372 $subfields->{10}->{'Subfield_Value'}='Item lost';
2375 $subfields->{11}->{'Subfield_Mark'}='j';
2376 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
2379 $subfields->{12}->{'Subfield_Mark'}='z';
2380 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
2384 $env->{'linkage'}=1;
2385 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2386 $env->{'linkage'}=0;
2387 $env->{'linkid'}=$Tag_ID;
2390 $subfields2->{1}->{'Subfield_Mark'}='a';
2391 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
2392 $subfields2->{1}->{'Subfield_Mark'}='b';
2393 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
2394 $subfields2->{1}->{'Subfield_Mark'}='c';
2395 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
2396 $subfields2->{2}->{'Subfield_Mark'}='m';
2397 $subfields2->{2}->{'Subfield_Value'}=$subclass;
2398 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
2399 $env->{'linkid'}='';
2402 sub OLD_MAYBE_DELETED_updateBiblio {
2403 # Update the biblio with biblionumber $biblio->{'biblionumber'}
2404 # I guess this routine should search through all marc records for a record that
2405 # has the same biblionumber stored in it, and modify the MARC record as well as
2408 # Also, this subroutine should search through the $biblio object and compare it
2409 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
2410 # this logging feature to be usable to undo changes easily.
2412 my ($env, $biblio) = @_;
2414 my $biblionumber=$biblio->{'biblionumber'};
2415 my $dbh = C4::Context->dbh;
2416 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
2418 my $origbiblio=$sth->fetchrow_hashref;
2419 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2421 my ($subtitle)=$sth->fetchrow;
2422 $origbiblio->{'subtitle'}=$subtitle;
2423 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2425 my $origadditionalauthors;
2426 while (my ($author) = $sth->fetchrow) {
2427 push (@{$origbiblio->{'additionalauthors'}}, $author);
2428 $origadditionalauthors->{$author}=1;
2430 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2433 while (my ($subject) = $sth->fetchrow) {
2434 push (@{$origbiblio->{'subjects'}}, $subject);
2435 $origsubjects->{$subject}=1;
2439 # Obtain a list of MARC Record_ID's that are tied to this biblio
2440 $sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
2443 while (my ($bibid) = $sth->fetchrow) {
2444 push(@marcrecords, $bibid);
2448 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
2449 my $q_author=$dbh->quote($biblio->{'author'});
2450 logchange('kohadb', 'change', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
2451 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
2453 foreach $bibid (@marcrecords) {
2454 logchange('marc', 'change', $bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2455 changeSubfield($bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2458 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
2459 my $q_title=$dbh->quote($biblio->{'title'});
2460 logchange('kohadb', 'change', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
2461 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
2463 foreach $Record_ID (@marcrecords) {
2464 logchange('marc', 'change', $Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2465 changeSubfield($Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2468 if ($biblio->{'subtitle'} ne $origbiblio->{'subtitle'}) {
2469 my $q_subtitle=$dbh->quote($biblio->{'subtitle'});
2470 logchange('kohadb', 'change', 'biblio', 'subtitle', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2471 my $sti=$dbh->prepare("update bibliosubtitle set subtitle=$q_subtitle where biblionumber=$biblio->{'biblionumber'}");
2473 foreach $Record_ID (@marcrecords) {
2474 logchange('marc', 'change', $Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2475 changeSubfield($Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2478 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
2479 my $q_unititle=$dbh->quote($biblio->{'unititle'});
2480 logchange('kohadb', 'change', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
2481 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
2484 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
2485 my $q_notes=$dbh->quote($biblio->{'notes'});
2486 logchange('kohadb', 'change', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
2487 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
2489 foreach $Record_ID (@marcrecords) {
2490 logchange('marc', 'change', $Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2491 changeSubfield($Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2494 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
2495 my $q_serial=$dbh->quote($biblio->{'serial'});
2496 logchange('kohadb', 'change', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
2497 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
2500 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
2501 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
2502 logchange('kohadb', 'change', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2503 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
2505 foreach $Record_ID (@marcrecords) {
2506 logchange('marc', 'change', $Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2507 changeSubfield($Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2510 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
2511 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
2512 logchange('kohadb', 'change', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
2513 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
2515 foreach $Record_ID (@marcrecords) {
2516 logchange('marc', 'change', $Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2517 changeSubfield($Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2521 # Check for subject heading changes
2525 foreach $newsubject (@{$biblio->{'subject'}}) {
2526 $subjects->{$newsubject}=1;
2527 if ($origsubjects->{$newsubject}) {
2528 $subjects->{$newsubject}=2;
2530 my $q_newsubject=$dbh->quote($newsubject);
2531 my $sth=$dbh->prepare("insert into bibliosubject (subject,biblionumber) values ($q_newsubject, $biblionumber)");
2533 logchange('kohadb', 'add', 'biblio', 'subject', $newsubject);
2535 $subfields->{1}->{'Subfield_Mark'}='a';
2536 $subfields->{1}->{'Subfield_Value'}=$newsubject;
2539 foreach $Record_ID (@marcrecords) {
2540 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2541 logchange('marc', 'add', $Record_ID, '650', 'a', $newsubject);
2546 foreach $origsubject (keys %$origsubjects) {
2547 if ($subjects->{$origsubject} == 1) {
2548 my $q_origsubject=$dbh->quote($origsubject);
2549 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'subject', $origsubject);
2550 my $sth=$dbh->prepare("delete from bibliosubject where biblionumber=$biblionumber and subject=$q_origsubject");
2556 sub OLD_MAYBE_DELETED_updateBiblioItem {
2557 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
2559 # This routine should also check to see which fields are actually being
2560 # modified, and log all changes.
2562 my ($env, $biblioitem) = @_;
2563 my $dbh = C4::Context->dbh;
2565 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2566 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
2567 # obi = original biblioitem
2568 my $obi=$sth->fetchrow_hashref;
2569 $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");
2571 my ($Record_ID) = $sth->fetchrow;
2572 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
2573 logchange('kohadb', 'change', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2574 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
2575 logchange('marc', 'change', $Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2576 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2578 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
2579 logchange('kohadb', 'change', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
2580 my $q_volume=$dbh->quote($biblioitem->{'volume'});
2581 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
2582 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2583 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2585 if ($biblioitem->{'number'} ne $obi->{'number'}) {
2586 logchange('kohadb', 'change', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
2587 my $q_number=$dbh->quote($biblioitem->{'number'});
2588 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
2589 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2590 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2592 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
2593 logchange('kohadb', 'change', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2594 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
2595 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
2596 logchange('marc', 'change', $Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2597 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2599 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
2600 logchange('kohadb', 'change', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
2601 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
2602 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
2603 logchange('marc', 'change', $Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2604 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2606 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
2607 logchange('kohadb', 'change', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
2608 my $q_issn=$dbh->quote($biblioitem->{'issn'});
2609 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
2610 logchange('marc', 'change', $Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2611 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2613 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
2614 logchange('kohadb', 'change', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
2615 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
2616 logchange('marc', 'change', $Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2617 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2619 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
2620 logchange('kohadb', 'change', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
2621 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
2622 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
2623 logchange('marc', 'change', $Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2624 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2626 if ($biblioitem->{'place'} ne $obi->{'place'}) {
2627 logchange('kohadb', 'change', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
2628 my $q_place=$dbh->quote($biblioitem->{'place'});
2629 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
2630 logchange('marc', 'change', $Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2631 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2633 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
2634 logchange('kohadb', 'change', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2635 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
2636 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
2637 logchange('marc', 'change', $Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2638 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2640 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
2641 logchange('kohadb', 'change', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2642 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
2643 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
2644 logchange('marc', 'change', $Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2645 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2647 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
2648 logchange('kohadb', 'change', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
2649 my $q_illus=$dbh->quote($biblioitem->{'illus'});
2650 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
2651 logchange('marc', 'change', $Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2652 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2654 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
2655 logchange('kohadb', 'change', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
2656 my $q_pages=$dbh->quote($biblioitem->{'pages'});
2657 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
2658 logchange('marc', 'change', $Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2659 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2661 if ($biblioitem->{'size'} ne $obi->{'size'}) {
2662 logchange('kohadb', 'change', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
2663 my $q_size=$dbh->quote($biblioitem->{'size'});
2664 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
2665 logchange('marc', 'change', $Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2666 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2668 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
2669 logchange('kohadb', 'change', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
2670 my $q_notes=$dbh->quote($biblioitem->{'notes'});
2671 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
2672 logchange('marc', 'change', $Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2673 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2675 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
2676 logchange('kohadb', 'change', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
2677 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
2678 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
2679 logchange('marc', 'change', $Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2680 changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2685 sub OLD_MAYBE_DELETED_updateItem {
2686 # Update the item with itemnumber $item->{'itemnumber'}
2687 # This routine should also modify the corresponding MARC record data. (852 and
2688 # 876 tags with 876p tag the same as $item->{'barcode'}
2690 # This routine should also check to see which fields are actually being
2691 # modified, and log all changes.
2693 my ($env, $item) = @_;
2694 my $dbh = C4::Context->dbh;
2695 my $itemnumber=$item->{'itemnumber'};
2696 my $biblionumber=$item->{'biblionumber'};
2697 my $biblioitemnumber=$item->{'biblioitemnumber'};
2698 my $barcode=$item->{'barcode'};
2699 my $dateaccessioned=$item->{'dateaccessioned'};
2700 my $booksellerid=$item->{'booksellerid'};
2701 my $homebranch=$item->{'homebranch'};
2702 my $price=$item->{'price'};
2703 my $replacementprice=$item->{'replacementprice'};
2704 my $replacementpricedate=$item->{'replacementpricedate'};
2705 my $multivolume=$item->{'multivolume'};
2706 my $stack=$item->{'stack'};
2707 my $notforloan=$item->{'notforloan'};
2708 my $itemlost=$item->{'itemlost'};
2709 my $wthdrawn=$item->{'wthdrawn'};
2710 my $bulk=$item->{'bulk'};
2711 my $restricted=$item->{'restricted'};
2712 my $binding=$item->{'binding'};
2713 my $itemnotes=$item->{'itemnotes'};
2714 my $holdingbranch=$item->{'holdingbranch'};
2715 my $interim=$item->{'interim'};
2716 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
2718 my $olditem=$sth->fetchrow_hashref;
2719 my $q_barcode=$dbh->quote($olditem->{'barcode'});
2720 $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");
2722 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
2723 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
2725 my ($link) = $sth->fetchrow;
2726 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
2728 my ($Subfield852_ID) = $sth->fetchrow;
2730 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
2731 logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
2732 my $q_barcode=$dbh->quote($item->{'barcode'});
2733 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
2735 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
2736 logchange('marc', 'change', $Record_ID, '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
2738 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
2739 logchange('kohadb', 'change', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
2740 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
2741 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
2743 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
2744 logchange('marc', 'change', $Record_ID, '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
2746 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
2747 logchange('kohadb', 'change', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2748 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
2749 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
2751 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
2752 logchange('marc', 'change', $Record_ID, '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2754 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
2755 logchange('kohadb', 'change', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
2756 my $q_homebranch=$dbh->quote($item->{'homebranch'});
2757 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
2759 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
2760 logchange('marc', 'change', $Record_ID, '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
2762 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
2763 logchange('kohadb', 'change', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2764 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
2765 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
2767 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
2768 logchange('marc', 'change', $Record_ID, '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2770 if ($item->{'price'} ne $olditem->{'price'}) {
2771 logchange('kohadb', 'change', 'items', 'price', $olditem->{'price'}, $item->{'price'});
2772 my $q_price=$dbh->quote($item->{'price'});
2773 my $sth=$dbh->prepare("update items set price=$q_price where itemnumber=$itemnumber");
2775 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'price'}, $item->{'price'}, $Subfield876_ID);
2776 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'price'}, $item->{'price'});
2778 if ($item->{'itemnotes'} ne $olditem->{'itemnotes'}) {
2779 logchange('kohadb', 'change', 'items', 'itemnotes', $olditem->{'itemnotes'}, $item->{'itemnotes'});
2780 my $q_itemnotes=$dbh->quote($item->{'itemnotes'});
2781 my $sth=$dbh->prepare("update items set itemnotes=$q_itemnotes where itemnumber=$itemnumber");
2783 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'itemnotes'}, $item->{'itemnotes'}, $Subfield876_ID);
2784 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'itemnotes'}, $item->{'itemnotes'});
2786 if ($item->{'notforloan'} ne $olditem->{'notforloan'}) {
2787 logchange('kohadb', 'change', 'items', 'notforloan', $olditem->{'notforloan'}, $item->{'notforloan'});
2788 my $sth=$dbh->prepare("update items set notforloan=$notforloan where itemnumber=$itemnumber");
2790 if ($item->{'notforloan'}) {
2791 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2792 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2794 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2795 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2798 if ($item->{'itemlost'} ne $olditem->{'itemlost'}) {
2799 logchange('kohadb', 'change', 'items', 'itemlost', $olditem->{'itemlost'}, $item->{'itemlost'});
2800 my $sth=$dbh->prepare("update items set itemlost=$itemlost where itemnumber=$itemnumber");
2802 if ($item->{'itemlost'}) {
2803 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2804 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2806 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2807 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2810 if ($item->{'wthdrawn'} ne $olditem->{'wthdrawn'}) {
2811 logchange('kohadb', 'change', 'items', 'wthdrawn', $olditem->{'wthdrawn'}, $item->{'wthdrawn'});
2812 my $sth=$dbh->prepare("update items set wthdrawn=$wthdrawn where itemnumber=$itemnumber");
2814 if ($item->{'wthdrawn'}) {
2815 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2816 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2818 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2819 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2822 if ($item->{'restricted'} ne $olditem->{'restricted'}) {
2823 logchange('kohadb', 'change', 'items', 'restricted', $olditem->{'restricted'}, $item->{'restricted'});
2824 my $sth=$dbh->prepare("update items set restricted=$restricted where itemnumber=$itemnumber");
2826 if ($item->{'restricted'}) {
2827 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2828 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2830 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2831 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2837 # Add a biblioitem and related data to Koha database
2838 sub OLD_MAY_BE_DELETED_newcompletebiblioitem {
2843 $biblio, # hash ref to biblio record
2844 $biblioitem, # hash ref to biblioitem record
2845 $subjects, # list ref of subjects
2846 $addlauthors, # list ref of additional authors
2849 my ( $biblionumber, $biblioitemnumber, $error); # return values
2854 my $additionalauthor;
2857 requireDBI($dbh,"newcompletebiblioitem");
2859 print "<PRE>Trying to add biblio item Title=$biblio->{title} " .
2860 "ISBN=$biblioitem->{isbn} </PRE>\n" if $debug;
2862 # Make sure master biblio entry exists
2863 ($biblionumber,$error)=getoraddbiblio($dbh, $biblio);
2867 $biblioitem->{biblionumber}=$biblionumber;
2870 $biblioitemnumber=newbiblioitem($biblioitem);
2873 $sth=$dbh->prepare("insert into bibliosubject
2874 (biblionumber,subject)
2876 foreach $subjectheading (@{$subjects} ) {
2877 $sth->execute($biblionumber, $subjectheading)
2878 or $error.=$sth->errstr ;
2882 # Add additional authors
2883 $sth=$dbh->prepare("insert into additionalauthors
2884 (biblionumber,author)
2886 foreach $additionalauthor (@{$addlauthors} ) {
2887 $sth->execute($biblionumber, $additionalauthor)
2888 or $error.=$sth->errstr ;
2892 # couldn't get biblio
2894 $biblioitemnumber='';
2896 } # if no biblio error
2898 return ( $biblionumber, $biblioitemnumber, $error);
2900 } # sub newcompletebiblioitem
2904 # END OF UNUSEFUL SUBs
2908 END { } # module clean-up code here (global destructor)