4 # Revision 1.19 2002/10/13 05:56:10 arensb
5 # Added some FIXME comments.
7 # Revision 1.18 2002/10/11 12:34:53 arensb
8 # Replaced &requireDBI with C4::Context->dbh
10 # Revision 1.17 2002/10/10 14:48:25 tipaul
13 # Revision 1.16 2002/10/07 14:04:26 tipaul
14 # road to 1.3.1 : viewing MARC biblio
16 # Revision 1.15 2002/10/05 09:49:25 arensb
17 # Merged with arensb-context branch: use C4::Context->dbh instead of
18 # &C4Connect, and generally prefer C4::Context over C4::Database.
20 # Revision 1.14 2002/10/03 11:28:18 tipaul
21 # Extending Context.pm to add stopword management and using it in MARC-API.
22 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
24 # Revision 1.13 2002/10/02 16:26:44 tipaul
27 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
28 # Merged in changes from main branch.
30 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
31 # Added a whole mess of FIXME comments.
33 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
34 # Added some missing semicolons.
36 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
37 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
40 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
41 # Added a whole mess of FIXME comments.
43 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
44 # Added some missing semicolons.
46 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
47 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
50 # Revision 1.12 2002/10/01 11:48:51 arensb
51 # Added some FIXME comments, mostly marking duplicate functions.
53 # Revision 1.11 2002/09/24 13:49:26 tipaul
54 # long WAS the road to 1.3.0...
55 # coming VERY SOON NOW...
56 # modifying installer and buildrelease to update the DB
58 # Revision 1.10 2002/09/22 16:50:08 arensb
59 # Added some FIXME comments.
61 # Revision 1.9 2002/09/20 12:57:46 tipaul
62 # long is the road to 1.4.0
63 # * MARCadditem and MARCmoditem now wroks
64 # * various bugfixes in MARC management
65 # !!! 1.3.0 should be released very soon now. Be careful !!!
67 # Revision 1.8 2002/09/10 13:53:52 tipaul
68 # MARC API continued...
70 # * 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)
72 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
74 # Revision 1.7 2002/08/14 18:12:51 tonnesen
75 # Added copyright statement to all .pl and .pm files
77 # Revision 1.6 2002/07/25 13:40:31 tipaul
78 # pod documenting the API.
80 # Revision 1.5 2002/07/24 16:11:37 tipaul
82 # Database.pm and Output.pm are almost not modified (var test...)
84 # Biblio.pm is almost completly rewritten.
86 # WHAT DOES IT ??? ==> END of Hitchcock suspens
88 # 1st, it does... nothing...
89 # 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 ...
91 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
92 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
93 # * 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.
94 # * 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.
95 # 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 ;-)
97 # 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.
98 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
102 # move from 1.2 to 1.4 version :
103 # 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
104 # In the 1.4 version, we want to do 2 differents things :
105 # - keep populating the old-DB, that has a LOT less datas than MARC
106 # - populate the MARC-DB
107 # To populate the DBs we have 2 differents sources :
108 # - the standard acquisition system (through book sellers), that does'nt use MARC data
109 # - the MARC acquisition system, that uses MARC data.
111 # thus, we have 2 differents cases :
112 # - 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
113 # - 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.
114 # we MUST have an API for true MARC data, that populate MARC-DB then old-DB
116 # That's why we need 4 subs :
117 # all subs beginning by MARC manage only MARC tables. They manage MARC-DB with MARC::Record parameters
118 # all subs beginning by OLD manage only OLD-DB tables. They manage old-DB with old-DB parameters
119 # 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
120 # 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.
122 # only ALL and old-style API should be used in koha. MARC and OLD is used internally only
124 # 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.
125 # 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 ;-)
129 # Copyright 2000-2002 Katipo Communications
131 # This file is part of Koha.
133 # Koha is free software; you can redistribute it and/or modify it under the
134 # terms of the GNU General Public License as published by the Free Software
135 # Foundation; either version 2 of the License, or (at your option) any later
138 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
139 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
140 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
142 # You should have received a copy of the GNU General Public License along with
143 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
144 # Suite 330, Boston, MA 02111-1307 USA
152 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
154 # set the version for version checking
159 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
160 # as the old-style API and the ALL one are the only public functions.
163 &updateBiblio &updateBiblioItem &updateItem
164 &itemcount &newbiblio &newbiblioitem
165 &modnote &newsubject &newsubtitle
166 &modbiblio &checkitems
167 &newitems &modbibitem
168 &modsubtitle &modsubject &modaddauthor &moditem &countitems
169 &delitem &deletebiblioitem &delbiblio
170 &getitemtypes &getbiblio
171 &getbiblioitembybiblionumber
172 &getbiblioitem &getitemsbybiblioitem &isbnsearch
174 &newcompletebiblioitem
176 &MARCfind_oldbiblionumber_from_MARCbibid
177 &MARCfind_MARCbibid_from_oldbiblionumber
179 &ALLnewbiblio &ALLnewitem
182 &MARCaddbiblio &MARCadditem
183 &MARCmodsubfield &MARCaddsubfield
184 &MARCmodbiblio &MARCmoditem
186 &MARCkoha2marcBiblio &MARCmarc2koha &MARCkoha2marcItem
187 &MARCgetbiblio &MARCgetitem
188 &MARCaddword &MARCdelword
193 # your exported package globals go here,
194 # as well as any optionally exported functions
196 @EXPORT_OK = qw($Var1 %Hashit); # FIXME - These are never used
200 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
203 # all the following subs takes a MARC::Record as parameter and manage
204 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
205 # ALLxxx subs (xxx deals with old-DB parameters, the ALLxxx deals with MARC-DB parameter)
210 all subs requires/use $dbh as 1st parameter.
211 NOTE : all those subs are private and must be used only inside Biblio.pm (called by a old API sub, or the ALLsub)
215 =head2 @tagslib = &MARCgettagslib($dbh,1|0);
216 last param is 1 for liblibrarian and 0 for libopac
217 returns a hash with tag/subfield meaning
219 =head2 ($tagfield,$tagsubfield) = &MARCfindmarc_from_kohafield($dbh,$kohafield);
220 finds MARC tag and subfield for a given kohafield
221 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
223 =head2 $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
224 finds a old-db biblio number for a given MARCbibid number
226 =head2 $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
227 finds a MARC bibid from a old-db biblionumber
229 =head2 &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
230 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
232 =head2 &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
233 adds a subfield in a biblio (in the MARC tables only).
235 =head2 $MARCRecord = &MARCgetbiblio($dbh,$bibid);
236 Returns a MARC::Record for the biblio $bibid.
238 =head2 &MARCmodbiblio($dbh,$bibid,$delete,$record);
239 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
240 if $delete == 1, every field/subfield not found is deleted in the biblio
241 otherwise, only data passed to MARCmodbiblio is managed.
242 thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
244 =head2 ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
245 MARCmodsubfield changes the value of a given subfield
247 =head2 $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
248 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
249 Returns -1 if more than 1 answer
251 =head2 $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
252 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
254 =head2 &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
255 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
257 =head2 &MARCdelbiblio($dbh,$bibid);
258 MARCdelbiblio delete biblio $bibid
260 =head2 $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
261 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
263 =head2 $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
264 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
266 =head2 $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
267 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
269 =head2 &MARCkoha2marcOnefield => used by MARCkoha2marc and should not be useful elsewhere
271 =head2 $olddb = &MARCmarc2koha($dbh,$MARCRecord);
272 builds a hash with old-db datas from a MARC::Record
274 =head2 &MARCmarc2kohaOnefield => used by MARCmarc2koha and should not be useful elsewhere
276 =head2 MARCaddword => used to manage MARC_word table and should not be useful elsewhere
278 =head2 MARCdelword => used to manage MARC_word table and should not be useful elsewhere
282 Paul POULAIN paul.poulain@free.fr
287 my ($dbh,$forlibrarian)= @_;
289 if ($forlibrarian eq 1) {
290 $sth=$dbh->prepare("select tagfield,liblibrarian as lib from marc_tag_structure");
292 $sth=$dbh->prepare("select tagfield,libopac as lib from marc_tag_structure");
295 my ($lib,$tag,$res,$tab);
296 while ( ($tag,$lib,$tab) = $sth->fetchrow) {
297 $res->{$tag}->{lib}=$lib;
298 $res->{$tab}->{tab}="";
301 if ($forlibrarian eq 1) {
302 $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure");
304 $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib,tab from marc_subfield_structure");
309 while ( ($tag,$subfield,$lib,$tab) = $sth->fetchrow) {
310 $res->{$tag}->{$subfield}->{lib}=$lib;
311 $res->{$tag}->{$subfield}->{tab}=$tab;
316 sub MARCfind_marc_from_kohafield {
317 my ($dbh,$kohafield) = @_;
318 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
319 $sth->execute($kohafield);
320 my ($tagfield,$tagsubfield) = $sth->fetchrow;
321 return ($tagfield,$tagsubfield);
324 sub MARCfind_oldbiblionumber_from_MARCbibid {
325 my ($dbh,$MARCbibid) = @_;
326 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
327 $sth->execute($MARCbibid);
328 my ($biblionumber) = $sth->fetchrow;
329 return $biblionumber;
332 sub MARCfind_MARCbibid_from_oldbiblionumber {
333 my ($dbh,$oldbiblionumber) = @_;
334 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
335 $sth->execute($oldbiblionumber);
336 my ($bibid) = $sth->fetchrow;
341 # pass the MARC::Record to this function, and it will create the records in the marc tables
342 my ($dbh,$record,$biblionumber) = @_;
343 my @fields=$record->fields();
345 # adding main table, and retrieving bibid
346 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
347 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
348 $sth->execute($biblionumber);
349 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
351 ($bibid)=$sth->fetchrow;
354 # now, add subfields...
355 foreach my $field (@fields) {
356 my @subfields=$field->subfields();
358 foreach my $subfieldcount (0..$#subfields) {
359 &MARCaddsubfield($dbh,$bibid,
361 $field->indicator(1).$field->indicator(2),
363 $subfields[$subfieldcount][0],
365 $subfields[$subfieldcount][1]
369 $dbh->do("unlock tables");
374 # pass the MARC::Record to this function, and it will create the records in the marc tables
375 my ($dbh,$record,$biblionumber) = @_;
376 # search for MARC biblionumber
377 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
378 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
379 my @fields=$record->fields();
380 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
381 $sth->execute($bibid);
382 my ($fieldcount) = $sth->fetchrow;
383 # now, add subfields...
384 foreach my $field (@fields) {
385 my @subfields=$field->subfields();
387 foreach my $subfieldcount (0..$#subfields) {
388 &MARCaddsubfield($dbh,$bibid,
390 $field->indicator(1).$field->indicator(2),
392 $subfields[$subfieldcount][0],
394 $subfields[$subfieldcount][1]
398 $dbh->do("unlock tables");
402 sub MARCaddsubfield {
403 # Add a new subfield to a tag into the DB.
404 my ($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
405 # if not value, end of job, we do nothing
406 if (not($subfieldvalue)) {
409 if (not($subfieldcode)) {
412 if (length($subfieldvalue)>255) {
413 # $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
414 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
415 $sth->execute($subfieldvalue);
416 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
418 my ($res)=$sth->fetchrow;
419 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?)");
421 $sth->execute($bibid,'0'.$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
423 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
426 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
428 # $dbh->do("unlock tables");
430 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?)");
431 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
433 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
436 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
441 # Returns MARC::Record of the biblio passed in parameter.
443 my $record = MARC::Record->new();
444 #---- TODO : the leader is missing
445 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
446 from marc_subfield_table
447 where bibid=? order by tagorder,subfieldorder
449 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
450 $sth->execute($bibid);
454 while (my $row=$sth->fetchrow_hashref) {
455 if ($row->{'valuebloblink'}) { #---- search blob if there is one
456 $sth2->execute($row->{'valuebloblink'});
457 my $row2=$sth2->fetchrow_hashref;
459 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
461 if ($row->{tagorder} ne $prevtagorder) {
462 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
463 $record->add_fields($field);
464 $prevtagorder=$row->{tagorder};
465 $prevtag = $row->{tag};
467 %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
469 %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
470 $prevtag= $row->{tag};
473 # the last has not been included inside the loop... do it now !
474 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
475 $record->add_fields($field);
479 # Returns MARC::Record of the biblio passed in parameter.
480 my ($dbh,$bibid,$itemnumber)=@_;
481 warn "MARCgetitem : $bibid, $itemnumber\n";
482 my $record = MARC::Record->new();
483 # search MARC tagorder
484 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=?");
485 $sth2->execute($bibid,$itemnumber);
486 my ($tagorder) = $sth2->fetchrow_array();
487 #---- TODO : the leader is missing
488 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
489 from marc_subfield_table
490 where bibid=? and tagorder=? order by subfieldorder
492 # FIXME - There's already a $sth2 in this scope.
493 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
494 $sth->execute($bibid,$tagorder);
495 while (my $row=$sth->fetchrow_hashref) {
496 if ($row->{'valuebloblink'}) { #---- search blob if there is one
497 $sth2->execute($row->{'valuebloblink'});
498 my $row2=$sth2->fetchrow_hashref;
500 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
502 if ($record->field($row->{'tag'})) {
504 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
505 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
506 if (length($row->{'tag'}) <3) {
507 $row->{'tag'} = "0".$row->{'tag'};
509 $field =$record->field($row->{'tag'});
511 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
512 $record->delete_field($field);
513 $record->add_fields($field);
516 if (length($row->{'tag'}) < 3) {
517 $row->{'tag'} = "0".$row->{'tag'};
519 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
520 $record->add_fields($temp);
528 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
529 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
530 # if nothing to change, don't waste time...
531 if ($oldrecord eq $record) {
534 # otherwise, skip through each subfield...
535 my @fields = $record->fields();
537 foreach my $field (@fields) {
538 my $oldfield = $oldrecord->field($field->tag());
539 my @subfields=$field->subfields();
542 foreach my $subfield (@subfields) {
544 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
545 # just adding datas...
546 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
547 1,@$subfield[0],$subfieldorder,@$subfield[1]);
549 # modify he subfield if it's a different string
550 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
551 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
552 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
560 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
561 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
562 # if nothing to change, don't waste time...
563 if ($oldrecord eq $record) {
566 # otherwise, skip through each subfield...
567 my @fields = $record->fields();
568 # search old MARC item
569 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=?");
570 $sth2->execute($bibid,$itemnumber);
571 my ($tagorder) = $sth2->fetchrow_array();
572 foreach my $field (@fields) {
573 my $oldfield = $oldrecord->field($field->tag());
574 my @subfields=$field->subfields();
576 foreach my $subfield (@subfields) {
578 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
579 # just adding datas...
580 warn "ADD = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
581 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
582 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
584 # modify he subfield if it's a different string
585 warn "MODIFY = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
586 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
587 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
588 warn "MODIFY2 = $bibid, $subfieldid, ".@$subfield[1]."\n";
589 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
598 sub MARCmodsubfield {
599 # Subroutine changes a subfield value given a subfieldid.
600 my ($dbh, $subfieldid, $subfieldvalue )=@_;
601 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
602 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
603 $sth1->execute($subfieldid);
604 my ($oldvaluebloblink)=$sth1->fetchrow;
607 # if too long, use a bloblink
608 if (length($subfieldvalue)>255 ) {
609 # if already a bloblink, update it, otherwise, insert a new one.
610 if ($oldvaluebloblink) {
611 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
612 $sth->execute($subfieldvalue,$oldvaluebloblink);
614 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
615 $sth->execute($subfieldvalue);
616 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
618 my ($res)=$sth->fetchrow;
619 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
620 $sth->execute($subfieldid);
623 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
624 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
625 $sth->execute($subfieldvalue, $subfieldid);
627 $dbh->do("unlock tables");
629 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
630 $sth->execute($subfieldid);
631 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
633 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
634 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
635 return($subfieldid, $subfieldvalue);
638 sub MARCfindsubfield {
639 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
643 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
644 if ($subfieldvalue) {
645 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
647 if ($subfieldorder<1) {
650 $query .= " and subfieldorder=$subfieldorder";
652 my $sti=$dbh->prepare($query);
653 $sti->execute($bibid,$tag, $subfieldcode);
654 while (($subfieldid) = $sti->fetchrow) {
656 $lastsubfieldid=$subfieldid;
658 if ($resultcounter>1) {
659 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
660 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
663 return $lastsubfieldid;
667 sub MARCfindsubfieldid {
668 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
669 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
670 where bibid=? and tag=? and tagorder=?
671 and subfieldcode=? and subfieldorder=?");
672 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
673 my ($res) = $sth->fetchrow;
677 sub MARCdelsubfield {
678 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
679 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
680 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
681 tag='$tag' and tagorder='$tagorder'
682 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
687 # delete a biblio for a $bibid
688 my ($dbh,$bibid) = @_;
689 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
690 $dbh->do("delete from marc_biblio where bibid='$bibid'");
693 sub MARCkoha2marcBiblio {
694 # this function builds partial MARC::Record from the old koha-DB fields
695 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
696 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
697 my $record = MARC::Record->new();
698 #--- if bibid, then retrieve old-style koha data
699 if ($biblionumber>0) {
700 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
701 from biblio where biblionumber=?");
702 $sth2->execute($biblionumber);
703 my $row=$sth2->fetchrow_hashref;
705 foreach $code (keys %$row) {
707 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
711 #--- if biblioitem, then retrieve old-style koha data
712 if ($biblioitemnumber>0) {
713 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
714 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
715 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
717 WHERE biblionumber=? and biblioitemnumber=?
719 $sth2->execute($biblionumber,$biblioitemnumber);
720 my $row=$sth2->fetchrow_hashref;
722 foreach $code (keys %$row) {
724 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
729 # TODO : retrieve notes, additionalauthors
732 sub MARCkoha2marcItem {
733 # this function builds partial MARC::Record from the old koha-DB fields
734 my ($dbh,$biblionumber,$itemnumber) = @_;
735 # my $dbh=&C4Connect;
736 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
737 my $record = MARC::Record->new();
738 #--- if item, then retrieve old-style koha data
740 # print STDERR "prepare $biblionumber,$itemnumber\n";
741 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
742 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
743 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
744 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
746 WHERE itemnumber=?");
747 $sth2->execute($itemnumber);
748 my $row=$sth2->fetchrow_hashref;
750 foreach $code (keys %$row) {
752 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
757 # TODO : retrieve notes, additionalauthors
760 sub MARCkoha2marcSubtitle {
761 # this function builds partial MARC::Record from the old koha-DB fields
762 my ($dbh,$bibnum,$subtitle) = @_;
763 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
764 my $record = MARC::Record->new();
765 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
769 sub MARCkoha2marcOnefield {
770 my ($sth,$record,$kohafieldname,$value)=@_;
773 $sth->execute($kohafieldname);
774 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
775 if ($record->field($tagfield)) {
776 my $tag =$record->field($tagfield);
778 $tag->add_subfields($tagsubfield,$value);
779 $record->delete_field($tag);
780 $record->add_fields($tag);
783 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
790 my ($dbh,$record) = @_;
791 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
793 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
796 # print STDERR $record->as_formatted;
797 while (($field)=$sth2->fetchrow) {
798 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
800 # FIXME - There's already a $sth2 in this scope.
801 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
803 # FIXME - There's already a $field in this scope.
805 while (($field)=$sth2->fetchrow) {
806 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
808 # FIXME - There's already a $sth2 in this scope.
809 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
811 # FIXME - There's already a $field in this scope.
813 while (($field)=$sth2->fetchrow) {
814 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
816 # additional authors : specific
817 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
821 sub MARCmarc2kohaOneField {
822 # to check : if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
823 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
827 $sth->execute($kohatable.".".$kohafield);
828 ($tagfield,$subfield) = $sth->fetchrow;
829 foreach my $field ($record->field($tagfield)) {
830 if ($field->subfield($subfield)) {
831 if ($result->{$kohafield}) {
832 $result->{$kohafield} .= " | ".$field->subfield($subfield);
834 $result->{$kohafield}=$field->subfield($subfield);
842 # split a subfield string and adds it into the word table.
844 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
845 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
846 my @words = split / /,$sentence;
847 # build stopword list
848 # my $sth2 =$dbh->prepare("select word from stopwords");
852 # while(($stopword) = $sth2->fetchrow_array) {
853 # $stopwords->{$stopword} = $stopword;
855 my $stopwords= C4::Context->stopwords;
856 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
857 values (?,?,?,?,?,?,soundex(?))");
858 foreach my $word (@words) {
859 # we record only words longer than 2 car and not in stopwords hash
860 if (length($word)>1 and !($stopwords->{uc($word)})) {
861 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
863 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";
870 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
871 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
872 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
873 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
878 # ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL
881 # all the following subs are useful to manage MARC-DB with complete MARC records.
882 # it's used with marcimport, and marc management tools
887 all subs requires/use $dbh as 1st parameter.
888 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
892 =head2 (oldbibnum,$oldbibitemnum) = ALLnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
893 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
894 are builded from the MARC::Record. If they are passed, they are used.
896 =head2 ALLnewitem($dbh,$olditem);
897 adds an item in the db. $olditem is a old-db hash.
901 Paul POULAIN paul.poulain@free.fr
906 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
907 # note $oldbiblio and $oldbiblioitem are not mandatory.
908 # if not present, they will be builded from $record with MARCmarc2koha function
909 if (($oldbiblio) and not($oldbiblioitem)) {
910 print STDERR "ALLnewbiblio : missing parameter\n";
911 print "ALLnewbiblio : missing parameter : contact koha development team\n";
917 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
918 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
919 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
921 my $olddata = MARCmarc2koha($dbh,$record);
922 $oldbibnum = OLDnewbiblio($dbh,$olddata);
923 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
925 # we must add bibnum and bibitemnum in MARC::Record...
926 # we build the new field with biblionumber and biblioitemnumber
927 # we drop the original field
928 # we add the new builded field.
929 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
930 # (steve and paul : thinks 090 is a good choice)
931 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
932 $sth->execute("biblio.biblionumber");
933 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
934 $sth->execute("biblioitems.biblioitemnumber");
935 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
936 print STDERR "tag1 : $tagfield1 / $tagsubfield1\n tag2 : $tagfield2 / $tagsubfield2\n";
937 if ($tagsubfield1 != $tagsubfield2) {
938 print STDERR "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
939 print "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
942 my $newfield = MARC::Field->new( $tagfield1,'','',
943 "$tagsubfield1" => $oldbibnum,
944 "$tagsubfield2" => $oldbibitemnum);
945 # drop old field and create new one...
946 my $old_field = $record->field($tagfield1);
947 $record->delete_field($old_field);
948 $record->add_fields($newfield);
949 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
950 return ( $oldbibnum,$oldbibitemnum );
954 my ($dbh, $item) = @_;
957 ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{'barcode'});
958 # search MARC biblionumber
959 my $bibid=&MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{'biblionumber'});
961 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
962 $sth->execute($bibid);
963 my ($tagorder) = $sth->fetchrow;
966 # for each field, find MARC tag and subfield, and call the proper MARC sub
967 foreach my $itemkey (keys %$item) {
970 print STDERR "=============> $itemkey : ".$item->{$itemkey}."\n";
971 if ($itemkey eq "biblionumber" || $itemkey eq "biblioitemnumber") {
972 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"biblio.".$itemkey);
974 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"items.".$itemkey);
976 if ($tagfield && $item->{$itemkey} ne 'NULL') {
978 &MARCaddsubfield($dbh,
994 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
1000 all subs requires/use $dbh as 1st parameter.
1001 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
1003 They all are the exact copy of 1.0/1.2 version of the sub
1004 without the OLD. The OLDxxx is called by the original xxx sub.
1005 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
1007 WARNING : there is 1 difference between initialxxx and OLDxxx :
1008 the db header $dbh is always passed as parameter
1009 to avoid over-DB connexion
1013 =head2 $biblionumber = OLDnewbiblio($dbh,$biblio);
1014 adds a record in biblio table. Datas are in the hash $biblio.
1016 =head2 $biblionumber = OLDmodbiblio($dbh,$biblio);
1017 modify a record in biblio table. Datas are in the hash $biblio.
1019 =head2 OLDmodsubtitle($dbh,$bibnum,$subtitle);
1020 modify subtitles in bibliosubtitle table.
1022 =head2 OLDmodaddauthor($dbh,$bibnum,$author);
1023 adds or modify additional authors
1024 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1026 =head2 $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1027 modify/adds subjects
1029 =head2 OLDmodbibitem($dbh, $biblioitem);
1032 =head2 OLDmodnote($dbh,$bibitemnum,$note
1033 modify a note for a biblioitem
1035 =head2 OLDnewbiblioitem($dbh,$biblioitem);
1036 adds a biblioitem ($biblioitem is a hash with the values)
1038 =head2 OLDnewsubject($dbh,$bibnum);
1040 =head2 OLDnewsubtitle($dbh,$bibnum,$subtitle);
1041 create a new subtitle
1043 =head2 ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1044 create a item. $item is a hash and $barcode the barcode.
1046 =head2 OLDmoditem($dbh,$item);
1049 =head2 OLDdelitem($dbh,$itemnum);
1052 =head2 OLDdeletebiblioitem($dbh,$biblioitemnumber);
1053 deletes a biblioitem
1054 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1056 =head2 OLDdelbiblio($dbh,$biblio);
1061 Paul POULAIN paul.poulain@free.fr
1066 my ($dbh,$biblio) = @_;
1067 # my $dbh = &C4Connect;
1068 my $query = "Select max(biblionumber) from biblio";
1069 my $sth = $dbh->prepare($query);
1071 my $data = $sth->fetchrow_arrayref;
1072 my $bibnum = $$data[0] + 1;
1075 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1076 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1077 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
1078 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
1079 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1080 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1081 if ($biblio->{'seriestitle'}) { $series = 1 };
1084 $query = "insert into biblio set
1085 biblionumber = $bibnum,
1086 title = $biblio->{'title'},
1087 author = $biblio->{'author'},
1088 copyrightdate = $biblio->{'copyright'},
1090 seriestitle = $biblio->{'seriestitle'},
1091 notes = $biblio->{'notes'},
1092 abstract = $biblio->{'abstract'}";
1094 $sth = $dbh->prepare($query);
1103 my ($dbh,$biblio) = @_;
1104 # my $dbh = C4Connect;
1108 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1109 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1110 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1111 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
1112 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
1113 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
1114 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
1115 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1117 $query = "Update biblio set
1118 title = $biblio->{'title'},
1119 author = $biblio->{'author'},
1120 abstract = $biblio->{'abstract'},
1121 copyrightdate = $biblio->{'copyrightdate'},
1122 seriestitle = $biblio->{'seriestitle'},
1123 serial = $biblio->{'serial'},
1124 unititle = $biblio->{'unititle'},
1125 notes = $biblio->{'notes'}
1126 where biblionumber = $biblio->{'biblionumber'}";
1127 $sth = $dbh->prepare($query);
1132 return($biblio->{'biblionumber'});
1135 sub OLDmodsubtitle {
1136 my ($dbh,$bibnum, $subtitle) = @_;
1137 # my $dbh = C4Connect;
1138 my $query = "update bibliosubtitle set
1139 subtitle = '$subtitle'
1140 where biblionumber = $bibnum";
1141 my $sth = $dbh->prepare($query);
1149 sub OLDmodaddauthor {
1150 my ($dbh,$bibnum, $author) = @_;
1151 # my $dbh = C4Connect;
1152 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1153 my $sth = $dbh->prepare($query);
1158 if ($author ne '') {
1159 $query = "Insert into additionalauthors set
1161 biblionumber = '$bibnum'";
1162 $sth = $dbh->prepare($query);
1168 } # sub modaddauthor
1172 my ($dbh,$bibnum, $force, @subject) = @_;
1173 # my $dbh = C4Connect;
1174 my $count = @subject;
1176 for (my $i = 0; $i < $count; $i++) {
1177 $subject[$i] =~ s/^ //g;
1178 $subject[$i] =~ s/ $//g;
1179 my $query = "select * from catalogueentry
1180 where entrytype = 's'
1181 and catalogueentry = '$subject[$i]'";
1182 my $sth = $dbh->prepare($query);
1185 if (my $data = $sth->fetchrow_hashref) {
1187 if ($force eq $subject[$i]) {
1188 # subject not in aut, chosen to force anway
1189 # so insert into cataloguentry so its in auth file
1190 $query = "Insert into catalogueentry
1191 (entrytype,catalogueentry)
1192 values ('s','$subject[$i]')";
1193 my $sth2 = $dbh->prepare($query);
1198 $error = "$subject[$i]\n does not exist in the subject authority file";
1199 $query = "Select * from catalogueentry
1200 where entrytype = 's'
1201 and (catalogueentry like '$subject[$i] %'
1202 or catalogueentry like '% $subject[$i] %'
1203 or catalogueentry like '% $subject[$i]')";
1204 my $sth2 = $dbh->prepare($query);
1207 while (my $data = $sth2->fetchrow_hashref) {
1208 $error = $error."<br>$data->{'catalogueentry'}"; # FIXME - .=
1216 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1217 my $sth = $dbh->prepare($query);
1220 for (my $i = 0; $i < $count; $i++) {
1221 $sth = $dbh->prepare("Insert into bibliosubject
1222 values ('$subject[$i]', $bibnum)");
1234 my ($dbh,$biblioitem) = @_;
1235 # my $dbh = C4Connect;
1238 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1239 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1240 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1241 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1242 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1243 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1244 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1245 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1246 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1247 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1248 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1249 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1250 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1251 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1253 $query = "Update biblioitems set
1254 itemtype = $biblioitem->{'itemtype'},
1255 url = $biblioitem->{'url'},
1256 isbn = $biblioitem->{'isbn'},
1257 publishercode = $biblioitem->{'publishercode'},
1258 publicationyear = $biblioitem->{'publicationyear'},
1259 classification = $biblioitem->{'classification'},
1260 dewey = $biblioitem->{'dewey'},
1261 subclass = $biblioitem->{'subclass'},
1262 illus = $biblioitem->{'illus'},
1263 pages = $biblioitem->{'pages'},
1264 volumeddesc = $biblioitem->{'volumeddesc'},
1265 notes = $biblioitem->{'notes'},
1266 size = $biblioitem->{'size'},
1267 place = $biblioitem->{'place'}
1268 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1276 my ($dbh,$bibitemnum,$note)=@_;
1277 # my $dbh=C4Connect;
1278 my $query="update biblioitems set notes='$note' where
1279 biblioitemnumber='$bibitemnum'";
1280 my $sth=$dbh->prepare($query);
1286 sub OLDnewbiblioitem {
1287 my ($dbh,$biblioitem) = @_;
1288 # my $dbh = C4Connect;
1289 my $query = "Select max(biblioitemnumber) from biblioitems";
1290 my $sth = $dbh->prepare($query);
1294 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
1295 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
1296 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1297 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1298 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1299 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1300 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
1301 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1302 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1303 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1304 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1305 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
1306 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1307 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1308 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1309 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1310 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1311 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1312 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
1313 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
1316 $data = $sth->fetchrow_arrayref;
1317 $bibitemnum = $$data[0] + 1;
1321 $query = "insert into biblioitems set
1322 biblioitemnumber = $bibitemnum,
1323 biblionumber = $biblioitem->{'biblionumber'},
1324 volume = $biblioitem->{'volume'},
1325 number = $biblioitem->{'number'},
1326 classification = $biblioitem->{'classification'},
1327 itemtype = $biblioitem->{'itemtype'},
1328 url = $biblioitem->{'url'},
1329 isbn = $biblioitem->{'isbn'},
1330 issn = $biblioitem->{'issn'},
1331 dewey = $biblioitem->{'dewey'},
1332 subclass = $biblioitem->{'subclass'},
1333 publicationyear = $biblioitem->{'publicationyear'},
1334 publishercode = $biblioitem->{'publishercode'},
1335 volumedate = $biblioitem->{'volumedate'},
1336 volumeddesc = $biblioitem->{'volumeddesc'},
1337 illus = $biblioitem->{'illus'},
1338 pages = $biblioitem->{'pages'},
1339 notes = $biblioitem->{'notes'},
1340 size = $biblioitem->{'size'},
1341 lccn = $biblioitem->{'lccn'},
1342 marc = $biblioitem->{'marc'},
1343 place = $biblioitem->{'place'}";
1345 $sth = $dbh->prepare($query);
1349 return($bibitemnum);
1353 my ($dbh,$bibnum)=@_;
1354 # my $dbh=C4Connect;
1355 my $query="insert into bibliosubject (biblionumber) values
1357 my $sth=$dbh->prepare($query);
1364 sub OLDnewsubtitle {
1365 my ($dbh,$bibnum, $subtitle) = @_;
1366 # my $dbh = C4Connect;
1367 $subtitle = $dbh->quote($subtitle);
1368 my $query = "insert into bibliosubtitle set
1369 biblionumber = $bibnum,
1370 subtitle = $subtitle";
1371 my $sth = $dbh->prepare($query);
1381 my ($dbh,$item, $barcode) = @_;
1382 # my $dbh = C4Connect;
1383 my $query = "Select max(itemnumber) from items";
1384 my $sth = $dbh->prepare($query);
1390 $data = $sth->fetchrow_hashref;
1391 $itemnumber = $data->{'max(itemnumber)'} + 1;
1394 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
1395 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
1396 $item->{'price'} = $dbh->quote($item->{'price'});
1397 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
1398 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
1400 # foreach my $barcode (@barcodes) {
1401 # $barcode = uc($barcode);
1402 $barcode = $dbh->quote($barcode);
1403 $query = "Insert into items set
1404 itemnumber = $itemnumber,
1405 biblionumber = $item->{'biblionumber'},
1406 biblioitemnumber = $item->{'biblioitemnumber'},
1408 booksellerid = $item->{'booksellerid'},
1409 dateaccessioned = NOW(),
1410 homebranch = $item->{'homebranch'},
1411 holdingbranch = $item->{'homebranch'},
1412 price = $item->{'price'},
1413 replacementprice = $item->{'replacementprice'},
1414 replacementpricedate = NOW(),
1415 itemnotes = $item->{'itemnotes'}";
1416 if ($item->{'loan'}) {
1417 $query .= ",notforloan = $item->{'loan'}";
1420 $sth = $dbh->prepare($query);
1422 if (defined $sth->errstr) {
1423 $error .= $sth->errstr;
1428 return($itemnumber,$error);
1432 my ($dbh,$item) = @_;
1433 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1434 # my $dbh=C4Connect;
1435 my $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1436 barcode='$item->{'barcode'}',itemnotes='$item->{'notes'}'
1437 where itemnumber=$item->{'itemnum'}";
1438 if ($item->{'barcode'} eq ''){
1439 $query="update items set biblioitemnumber=$item->{'bibitemnum'},notforloan=$item->{'loan'} where itemnumber=$item->{'itemnum'}";
1441 if ($item->{'lost'} ne ''){
1442 $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1443 barcode='$item->{'barcode'}',
1444 itemnotes='$item->{'notes'}',
1445 homebranch='$item->{'homebranch'}',
1446 itemlost='$item->{'lost'}',
1447 wthdrawn='$item->{'wthdrawn'}'
1448 where itemnumber=$item->{'itemnum'}";
1450 if ($item->{'replacement'} ne ''){
1451 $query=~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1454 my $sth=$dbh->prepare($query);
1460 # FIXME - A nearly-identical function, &delitem, appears in
1463 my ($dbh,$itemnum)=@_;
1464 # my $dbh=C4Connect;
1465 my $query="select * from items where itemnumber=$itemnum";
1466 my $sth=$dbh->prepare($query);
1468 my @data=$sth->fetchrow_array;
1470 $query="Insert into deleteditems values (";
1471 foreach my $temp (@data){
1472 $query=$query."'$temp',"; # FIXME - .=
1476 $sth=$dbh->prepare($query);
1479 $query = "Delete from items where itemnumber=$itemnum";
1480 $sth=$dbh->prepare($query);
1486 sub OLDdeletebiblioitem {
1487 my ($dbh,$biblioitemnumber) = @_;
1488 # my $dbh = C4Connect;
1489 my $query = "Select * from biblioitems
1490 where biblioitemnumber = $biblioitemnumber";
1491 my $sth = $dbh->prepare($query);
1496 if (@results = $sth->fetchrow_array) {
1497 $query = "Insert into deletedbiblioitems values (";
1498 foreach my $value (@results) {
1499 $value = $dbh->quote($value);
1500 $query .= "$value,";
1503 $query =~ s/\,$/\)/;
1506 $query = "Delete from biblioitems
1507 where biblioitemnumber = $biblioitemnumber";
1511 # Now delete all the items attached to the biblioitem
1512 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1513 $sth = $dbh->prepare($query);
1515 while (@results = $sth->fetchrow_array) {
1516 $query = "Insert into deleteditems values (";
1517 foreach my $value (@results) {
1518 $value = $dbh->quote($value);
1519 $query .= "$value,";
1521 $query =~ s/\,$/\)/;
1525 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1528 } # sub deletebiblioitem
1531 my ($dbh,$biblio)=@_;
1532 # my $dbh=C4Connect;
1533 my $query="select * from biblio where biblionumber=$biblio";
1534 my $sth=$dbh->prepare($query);
1536 if (my @data=$sth->fetchrow_array){
1538 $query="Insert into deletedbiblio values (";
1539 foreach my $temp (@data){
1540 $temp=~ s/\'/\\\'/g;
1541 $query=$query."'$temp',"; # FIXME - .=
1545 $sth=$dbh->prepare($query);
1548 $query = "Delete from biblio where biblionumber=$biblio";
1549 $sth=$dbh->prepare($query);
1563 # FIXME - This is the same as &C4::Acquisitions::itemcount, but not
1564 # the same as &C4::Search::itemcount
1565 # Since they're both exported, acqui/acquire.pl doesn't compile with -w.
1568 my $dbh = C4::Context->dbh;
1569 my $query="Select count(*) from items where biblionumber=$biblio";
1571 my $sth=$dbh->prepare($query);
1573 my $data=$sth->fetchrow_hashref;
1575 return($data->{'count(*)'});
1580 my $dbh = C4::Context->dbh;
1581 my $query="Select ordernumber
1583 where biblionumber=? and biblioitemnumber=?";
1584 my $sth=$dbh->prepare($query);
1585 $sth->execute($bib,$bi);
1586 my $ordnum=$sth->fetchrow_hashref;
1588 my $order=getsingleorder($ordnum->{'ordernumber'});
1590 return ($order,$ordnum->{'ordernumber'});
1593 # FIXME - This is practically the same function as
1594 # &C4::Acquisitions::getsingleorder and &C4::Catalogue::getsingleorder
1595 sub getsingleorder {
1597 my $dbh = C4::Context->dbh;
1598 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1599 where aqorders.ordernumber=?
1600 and biblio.biblionumber=aqorders.biblionumber and
1601 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1602 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1603 my $sth=$dbh->prepare($query);
1604 $sth->execute($ordnum);
1605 my $data=$sth->fetchrow_hashref;
1610 # FIXME - This is in effect identical to &C4::Acquisitions::newbiblio.
1611 # Pick one and stick with it.
1614 my $dbh = C4::Context->dbh;
1615 my $bibnum=OLDnewbiblio($dbh,$biblio);
1620 # FIXME - This is in effect the same as &C4::Acquisitions::modbiblio.
1621 # Pick one and stick with it.
1622 # FIXME - Get the POD from C4::Acquisitions
1625 my $dbh = C4::Context->dbh;
1626 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1627 return($biblionumber);
1630 # FIXME - This is in effect identical to &C4::Acquisitions::modsubtitle.
1631 # Pick one and stick with it.
1632 # FIXME - Get the POD from C4::Acquisitions
1634 my ($bibnum, $subtitle) = @_;
1635 my $dbh = C4::Context->dbh;
1636 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1640 # FIXME - This is functionally identical to
1641 # &C4::Acquisitions::modaddauthor
1642 # Pick one and stick with it.
1643 # FIXME - Get the POD from C4::Acquisitions
1645 my ($bibnum, $author) = @_;
1646 my $dbh = C4::Context->dbh;
1647 &OLDmodaddauthor($dbh,$bibnum,$author);
1648 } # sub modaddauthor
1651 # FIXME - This is in effect identical to &C4::Acquisitions::modsubject.
1652 # Pick one and stick with it.
1654 my ($bibnum, $force, @subject) = @_;
1655 my $dbh = C4::Context->dbh;
1656 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1660 # FIXME - This is very similar to &C4::Acquisitions::modbibitem.
1661 # Pick one and stick with it.
1663 my ($biblioitem) = @_;
1664 my $dbh = C4::Context->dbh;
1665 &OLDmodbibitem($dbh,$biblioitem);
1666 my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
1667 &MARCmodbiblio($dbh,$biblioitem->{biblionumber},0,$MARCbibitem);
1670 # FIXME - This is in effect identical to &C4::Acquisitions::modnote.
1671 # Pick one and stick with it.
1673 my ($bibitemnum,$note)=@_;
1674 my $dbh = C4::Context->dbh;
1675 &OLDmodnote($dbh,$bibitemnum,$note);
1678 # FIXME - This is quite similar in effect to &C4::newbiblioitem,
1679 # except for the MARC stuff. There's also a &newbiblioitem in
1680 # acqui.simple/addbookslccn.pl
1682 my ($biblioitem) = @_;
1683 my $dbh = C4::Context->dbh;
1684 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1685 # print STDERR "bibitemnum : $bibitemnum\n";
1686 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1687 # print STDERR $MARCbiblio->as_formatted();
1688 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1689 return($bibitemnum);
1692 # FIXME - This is in effect identical to &C4::Acquisitions::newsubject.
1693 # Pick one and stick with it.
1696 my $dbh = C4::Context->dbh;
1697 &OLDnewsubject($dbh,$bibnum);
1700 # FIXME - This is just a wrapper around &OLDnewsubtitle
1701 # FIXME - This is in effect the same as &C4::Acquisitions::newsubtitle
1703 my ($bibnum, $subtitle) = @_;
1704 my $dbh = C4::Context->dbh;
1705 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1708 # FIXME - This is different from &C4::Acquisitions::newitems, though
1709 # both are exported.
1711 my ($item, @barcodes) = @_;
1712 my $dbh = C4::Context->dbh;
1716 foreach my $barcode (@barcodes) {
1717 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1719 # print STDERR "biblionumber : $item->{biblionumber} / MARCbibid : $MARCbibid / itemnumber : $itemnumber\n";
1720 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1721 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1722 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1723 # print STDERR "MARCmodbiblio called\n";
1728 # FIXME - This appears to be functionally equivalent to
1729 # &C4::Acquisitions::moditem.
1730 # Pick one and stick with it.
1733 # my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1734 my $dbh = C4::Context->dbh;
1735 &OLDmoditem($dbh,$item);
1736 warn "biblionumber : $item->{'biblionumber'} / $item->{'itemnum'}\n";
1737 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1738 warn "before MARCmoditem : $item->{biblionumber}, $item->{'itemnum'}\n";
1739 warn $MARCitem->as_formatted();
1740 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1741 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1742 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1745 # FIXME - This is the same as &C4::Acquisitions::Checkitems.
1746 # Pick one and stick with it.
1748 my ($count,@barcodes)=@_;
1749 my $dbh = C4::Context->dbh;
1751 for (my $i=0;$i<$count;$i++){
1752 $barcodes[$i]=uc $barcodes[$i];
1753 my $query="Select * from items where barcode='$barcodes[$i]'";
1754 my $sth=$dbh->prepare($query);
1756 if (my $data=$sth->fetchrow_hashref){
1757 $error.=" Duplicate Barcode: $barcodes[$i]";
1764 # FIXME - This is identical to &C4::Acquisitions::countitems.
1765 # Pick one and stick with it.
1767 my ($bibitemnum)=@_;
1768 my $dbh = C4::Context->dbh;
1769 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1770 my $sth=$dbh->prepare($query);
1772 my $data=$sth->fetchrow_hashref;
1774 return($data->{'count(*)'});
1777 # FIXME - This is just a wrapper around &OLDdelitem, and acts
1778 # identically to &C4::Acquisitions::delitem
1779 # Pick one and stick with it.
1782 my $dbh = C4::Context->dbh;
1783 &OLDdelitem($dbh,$itemnum);
1786 # FIXME - This is functionally identical to
1787 # &C4::Acquisitions::deletebiblioitem.
1788 # Pick one and stick with it.
1789 sub deletebiblioitem {
1790 my ($biblioitemnumber) = @_;
1791 my $dbh = C4::Context->dbh;
1792 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1793 } # sub deletebiblioitem
1796 # FIXME - This is functionally identical to &C4::Acquisitions::delbiblio.
1797 # Pick one and stick with it.
1800 my $dbh = C4::Context->dbh;
1801 &OLDdelbiblio($dbh,$biblio);
1804 # FIXME - This is identical to &C4::Acquisitions::getitemtypes.
1805 # Pick one and stick with it.
1807 my $dbh = C4::Context->dbh;
1808 my $query = "select * from itemtypes";
1809 my $sth = $dbh->prepare($query);
1810 # || die "Cannot prepare $query" . $dbh->errstr;
1815 # || die "Cannot execute $query\n" . $sth->errstr;
1816 while (my $data = $sth->fetchrow_hashref) {
1817 $results[$count] = $data;
1822 return($count, @results);
1823 } # sub getitemtypes
1826 my ($biblionumber) = @_;
1827 my $dbh = C4::Context->dbh;
1828 my $query = "Select * from biblio where biblionumber = $biblionumber";
1829 my $sth = $dbh->prepare($query);
1830 # || die "Cannot prepare $query\n" . $dbh->errstr;
1835 # || die "Cannot execute $query\n" . $sth->errstr;
1836 while (my $data = $sth->fetchrow_hashref) {
1837 $results[$count] = $data;
1842 return($count, @results);
1845 # FIXME - This is identical to &C4::Acquisitions::getbiblioitem.
1846 # Pick one and stick with it.
1848 my ($biblioitemnum) = @_;
1849 my $dbh = C4::Context->dbh;
1850 my $query = "Select * from biblioitems where
1851 biblioitemnumber = $biblioitemnum";
1852 my $sth = $dbh->prepare($query);
1858 while (my $data = $sth->fetchrow_hashref) {
1859 $results[$count] = $data;
1864 return($count, @results);
1865 } # sub getbiblioitem
1867 # FIXME - This is identical to
1868 # &C4::Acquisitions::getbiblioitembybiblionumber.
1869 # Pick one and stick with it.
1870 sub getbiblioitembybiblionumber {
1871 my ($biblionumber) = @_;
1872 my $dbh = C4::Context->dbh;
1873 my $query = "Select * from biblioitems where biblionumber =
1875 my $sth = $dbh->prepare($query);
1881 while (my $data = $sth->fetchrow_hashref) {
1882 $results[$count] = $data;
1887 return($count, @results);
1890 # FIXME - This is identical to
1891 # &C4::Acquisitions::getbiblioitembybiblionumber.
1892 # Pick one and stick with it.
1893 sub getitemsbybiblioitem {
1894 my ($biblioitemnum) = @_;
1895 my $dbh = C4::Context->dbh;
1896 my $query = "Select * from items, biblio where
1897 biblio.biblionumber = items.biblionumber and biblioitemnumber
1899 my $sth = $dbh->prepare($query);
1900 # || die "Cannot prepare $query\n" . $dbh->errstr;
1905 # || die "Cannot execute $query\n" . $sth->errstr;
1906 while (my $data = $sth->fetchrow_hashref) {
1907 $results[$count] = $data;
1912 return($count, @results);
1913 } # sub getitemsbybiblioitem
1915 # FIXME - This is identical to &C4::Acquisitions::isbnsearch.
1916 # Pick one and stick with it.
1919 my $dbh = C4::Context->dbh;
1925 $isbn = $dbh->quote($isbn);
1926 $query = "Select biblio.* from biblio, biblioitems where
1927 biblio.biblionumber = biblioitems.biblionumber
1929 $sth = $dbh->prepare($query);
1932 while (my $data = $sth->fetchrow_hashref) {
1933 $results[$count] = $data;
1938 return($count, @results);
1942 # At the moment this is just a straight copy of the subject code. Needs heavy
1943 # modification to work for additional authors, obviously.
1944 # Check for additional author changes
1946 # my $newadditionalauthor='';
1947 # my $additionalauthors;
1948 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
1949 # $additionalauthors->{$newadditionalauthor}=1;
1950 # if ($origadditionalauthors->{$newadditionalauthor}) {
1951 # $additionalauthors->{$newadditionalauthor}=2;
1953 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
1954 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
1956 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
1958 # $subfields->{1}->{'Subfield_Mark'}='a';
1959 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
1962 # foreach $Record_ID (@marcrecords) {
1963 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1964 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
1968 # my $origadditionalauthor;
1969 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
1970 # if ($additionalauthors->{$origadditionalauthor} == 1) {
1971 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
1972 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
1973 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
1983 # Subroutine to log changes to databases
1984 # Eventually, this subroutine will be used to create a log of all changes made,
1985 # with the possibility of "undo"ing some changes
1987 if ($database eq 'kohadb') {
1993 print STDERR "KOHA: $type $section $item $original $new\n";
1994 } elsif ($database eq 'marc') {
1996 my $Record_ID=shift;
1999 my $subfield_ID=shift;
2002 print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2006 #------------------------------------------------
2009 #---------------------------------------
2010 # Find a biblio entry, or create a new one if it doesn't exist.
2011 # If a "subtitle" entry is in hash, add it to subtitle table
2012 sub getoraddbiblio {
2016 # FIXME - Unused argument
2017 $biblio, # hash ref to fields
2028 $dbh = C4::Context->dbh;
2030 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2031 $sth=$dbh->prepare("select biblionumber
2033 where title=? and author=?
2034 and copyrightdate=? and seriestitle=?");
2036 $biblio->{title}, $biblio->{author},
2037 $biblio->{copyright}, $biblio->{seriestitle} );
2039 ($biblionumber) = $sth->fetchrow;
2040 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2042 # Doesn't exist. Add new one.
2043 print "<PRE>Adding biblio</PRE>\n" if $debug;
2044 ($biblionumber,$error)=&newbiblio($biblio);
2045 if ( $biblionumber ) {
2046 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
2047 if ( $biblio->{subtitle} ) {
2048 &newsubtitle($biblionumber,$biblio->{subtitle} );
2051 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2055 return $biblionumber,$error;
2057 } # sub getoraddbiblio
2061 # UNUSEFUL SUBs. Could be deleted, kept only until beta test
2062 # maybe useful for some MARC tricks steve used.
2065 sub OLD_MAYBE_DELETED_newBiblioItem {
2066 my ($env, $biblioitem) = @_;
2067 my $dbh = C4::Context->dbh;
2068 my $biblionumber=$biblioitem->{'biblionumber'};
2069 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2070 my $volume=$biblioitem->{'volume'};
2071 my $q_volume=$dbh->quote($volume);
2072 my $number=$biblioitem->{'number'};
2073 my $q_number=$dbh->quote($number);
2074 my $classification=$biblioitem->{'classification'};
2075 my $q_classification=$dbh->quote($classification);
2076 my $itemtype=$biblioitem->{'itemtype'};
2077 my $q_itemtype=$dbh->quote($itemtype);
2078 my $isbn=$biblioitem->{'isbn'};
2079 my $q_isbn=$dbh->quote($isbn);
2080 my $issn=$biblioitem->{'issn'};
2081 my $q_issn=$dbh->quote($issn);
2082 my $dewey=$biblioitem->{'dewey'};
2084 ($dewey == 0) && ($dewey='');
2085 my $subclass=$biblioitem->{'subclass'};
2086 my $q_subclass=$dbh->quote($subclass);
2087 my $publicationyear=$biblioitem->{'publicationyear'};
2088 my $publishercode=$biblioitem->{'publishercode'};
2089 my $q_publishercode=$dbh->quote($publishercode);
2090 my $volumedate=$biblioitem->{'volumedate'};
2091 my $q_volumedate=$dbh->quote($volumedate);
2092 my $illus=$biblioitem->{'illus'};
2093 my $q_illus=$dbh->quote($illus);
2094 my $pages=$biblioitem->{'pages'};
2095 my $q_pages=$dbh->quote($pages);
2096 my $notes=$biblioitem->{'notes'};
2097 my $q_notes=$dbh->quote($notes);
2098 my $size=$biblioitem->{'size'};
2099 my $q_size=$dbh->quote($size);
2100 my $place=$biblioitem->{'place'};
2101 my $q_place=$dbh->quote($place);
2102 my $lccn=$biblioitem->{'lccn'};
2103 my $q_lccn=$dbh->quote($lccn);
2106 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
2109 unless ($env->{'marconly'}) {
2110 #my $sth=$dbh->prepare("lock tables biblioitems write");
2112 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
2114 my ($biblioitemnumber) =$sth->fetchrow;
2115 $biblioitemnumber++;
2116 $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)");
2118 #my $sth=$dbh->prepare("unlock tables");
2123 # Should we check if there is already a biblioitem/amrc with the
2124 # same isbn/lccn/issn?
2126 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
2128 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
2129 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2131 my ($subtitle) = $sth->fetchrow;
2132 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2134 my @additionalauthors;
2135 while (my ($additionalauthor) = $sth->fetchrow) {
2136 push (@additionalauthors, $additionalauthor);
2138 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2141 while (my ($subject) = $sth->fetchrow) {
2142 push (@subjects, $subject);
2147 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
2149 my $Resource_ID=$dbh->{'mysql_insertid'};
2150 my $Record_ID=$Resource_ID;
2151 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
2157 $subfields->{1}->{'Subfield_Mark'}='a';
2158 $subfields->{1}->{'Subfield_Value'}=$title;
2160 $subfields->{2}->{'Subfield_Mark'}='b';
2161 $subfields->{2}->{'Subfield_Value'}=$subtitle;
2164 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2170 $subfields->{1}->{'Subfield_Mark'}='a';
2171 $subfields->{1}->{'Subfield_Value'}=$author;
2173 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2178 $subfields->{1}->{'Subfield_Mark'}='a';
2179 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
2181 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2186 $subfields->{1}->{'Subfield_Mark'}='a';
2187 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
2188 $subfields->{2}->{'Subfield_Mark'}='3';
2189 $subfields->{2}->{'Subfield_Value'}='biblio';
2191 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2193 # Additional Authors
2194 foreach (@additionalauthors) {
2196 (next) unless ($author);
2198 $subfields->{1}->{'Subfield_Mark'}='a';
2199 $subfields->{1}->{'Subfield_Value'}=$author;
2200 $subfields->{2}->{'Subfield_Mark'}='e';
2201 $subfields->{2}->{'Subfield_Value'}='author';
2203 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2207 (next) unless ($illus);
2209 $subfields->{1}->{'Subfield_Mark'}='a';
2210 $subfields->{1}->{'Subfield_Value'}=$illus;
2211 $subfields->{2}->{'Subfield_Mark'}='e';
2212 $subfields->{2}->{'Subfield_Value'}='illustrator';
2214 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2217 foreach (@subjects) {
2219 (next) unless ($subject);
2221 $subfields->{1}->{'Subfield_Mark'}='a';
2222 $subfields->{1}->{'Subfield_Value'}=$subject;
2224 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2231 $subfields->{1}->{'Subfield_Mark'}='a';
2232 $subfields->{1}->{'Subfield_Value'}=$isbn;
2234 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2239 $subfields->{1}->{'Subfield_Mark'}='a';
2240 $subfields->{1}->{'Subfield_Value'}=$lccn;
2242 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2247 $subfields->{1}->{'Subfield_Mark'}='a';
2248 $subfields->{1}->{'Subfield_Value'}=$issn;
2250 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2255 $subfields->{1}->{'Subfield_Mark'}='a';
2256 $subfields->{1}->{'Subfield_Value'}=$dewey;
2258 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2260 # DEWEY subclass and itemtype
2263 $subfields->{1}->{'Subfield_Mark'}='a';
2264 $subfields->{1}->{'Subfield_Value'}=$itemtype;
2265 $subfields->{2}->{'Subfield_Mark'}='b';
2266 $subfields->{2}->{'Subfield_Value'}=$subclass;
2267 $subfields->{3}->{'Subfield_Mark'}='c';
2268 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
2269 $subfields->{4}->{'Subfield_Mark'}='d';
2270 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
2272 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2277 $subfields->{1}->{'Subfield_Mark'}='a';
2278 $subfields->{1}->{'Subfield_Value'}=$place;
2279 $subfields->{2}->{'Subfield_Mark'}='b';
2280 $subfields->{2}->{'Subfield_Value'}=$publishercode;
2281 $subfields->{3}->{'Subfield_Mark'}='c';
2282 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
2283 if ($copyrightdate) {
2284 $subfields->{4}->{'Subfield_Mark'}='c';
2285 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
2288 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2291 if ($pages || $size) {
2293 $subfields->{1}->{'Subfield_Mark'}='a';
2294 $subfields->{1}->{'Subfield_Value'}=$pages;
2295 $subfields->{2}->{'Subfield_Mark'}='c';
2296 $subfields->{2}->{'Subfield_Value'}=$size;
2298 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2301 if ($volume || $number) {
2303 $subfields->{1}->{'Subfield_Mark'}='v';
2304 $subfields->{1}->{'Subfield_Value'}=$volume;
2305 $subfields->{2}->{'Subfield_Mark'}='n';
2306 $subfields->{2}->{'Subfield_Value'}=$number;
2308 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2313 $subfields->{1}->{'Subfield_Mark'}='a';
2314 $subfields->{1}->{'Subfield_Value'}=$notes;
2315 $subfields->{2}->{'Subfield_Mark'}='3';
2316 $subfields->{2}->{'Subfield_Value'}='biblioitem';
2318 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2321 return ($env, $Record_ID);
2324 sub OLD_MAYBE_DELETED_newItem {
2325 my ($env, $Record_ID, $item) = @_;
2326 my $dbh = C4::Context->dbh;
2327 my $barcode=$item->{'barcode'};
2328 my $q_barcode=$dbh->quote($barcode);
2329 my $biblionumber=$item->{'biblionumber'};
2330 my $biblioitemnumber=$item->{'biblioitemnumber'};
2331 my $dateaccessioned=$item->{'dateaccessioned'};
2332 my $booksellerid=$item->{'booksellerid'};
2333 my $q_booksellerid=$dbh->quote($booksellerid);
2334 my $homebranch=$item->{'homebranch'};
2335 my $q_homebranch=$dbh->quote($homebranch);
2336 my $holdingbranch=$item->{'holdingbranch'};
2337 my $price=$item->{'price'};
2338 my $replacementprice=$item->{'replacementprice'};
2339 my $replacementpricedate=$item->{'replacementpricedate'};
2340 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
2341 my $notforloan=$item->{'notforloan'};
2342 my $itemlost=$item->{'itemlost'};
2343 my $wthdrawn=$item->{'wthdrawn'};
2344 my $restricted=$item->{'restricted'};
2345 my $itemnotes=$item->{'itemnotes'};
2346 my $q_itemnotes=$dbh->quote($itemnotes);
2347 my $itemtype=$item->{'itemtype'};
2348 my $subclass=$item->{'subclass'};
2352 unless ($env->{'marconly'}) {
2353 my $sth=$dbh->prepare("select max(itemnumber) from items");
2355 my ($itemnumber) =$sth->fetchrow;
2357 $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)");
2364 $subfields->{1}->{'Subfield_Mark'}='p';
2365 $subfields->{1}->{'Subfield_Value'}=$barcode;
2366 $subfields->{2}->{'Subfield_Mark'}='d';
2367 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
2368 $subfields->{3}->{'Subfield_Mark'}='e';
2369 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
2370 $subfields->{4}->{'Subfield_Mark'}='b';
2371 $subfields->{4}->{'Subfield_Value'}=$homebranch;
2372 $subfields->{5}->{'Subfield_Mark'}='l';
2373 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
2374 $subfields->{6}->{'Subfield_Mark'}='c';
2375 $subfields->{6}->{'Subfield_Value'}=$price;
2376 $subfields->{7}->{'Subfield_Mark'}='c';
2377 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
2378 $subfields->{8}->{'Subfield_Mark'}='d';
2379 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
2381 $subfields->{9}->{'Subfield_Mark'}='h';
2382 $subfields->{9}->{'Subfield_Value'}='Not for loan';
2385 $subfields->{10}->{'Subfield_Mark'}='j';
2386 $subfields->{10}->{'Subfield_Value'}='Item lost';
2389 $subfields->{11}->{'Subfield_Mark'}='j';
2390 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
2393 $subfields->{12}->{'Subfield_Mark'}='z';
2394 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
2398 $env->{'linkage'}=1;
2399 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2400 $env->{'linkage'}=0;
2401 $env->{'linkid'}=$Tag_ID;
2404 $subfields2->{1}->{'Subfield_Mark'}='a';
2405 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
2406 $subfields2->{1}->{'Subfield_Mark'}='b';
2407 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
2408 $subfields2->{1}->{'Subfield_Mark'}='c';
2409 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
2410 $subfields2->{2}->{'Subfield_Mark'}='m';
2411 $subfields2->{2}->{'Subfield_Value'}=$subclass;
2412 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
2413 $env->{'linkid'}='';
2416 sub OLD_MAYBE_DELETED_updateBiblio {
2417 # Update the biblio with biblionumber $biblio->{'biblionumber'}
2418 # I guess this routine should search through all marc records for a record that
2419 # has the same biblionumber stored in it, and modify the MARC record as well as
2422 # Also, this subroutine should search through the $biblio object and compare it
2423 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
2424 # this logging feature to be usable to undo changes easily.
2426 my ($env, $biblio) = @_;
2428 my $biblionumber=$biblio->{'biblionumber'};
2429 my $dbh = C4::Context->dbh;
2430 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
2432 my $origbiblio=$sth->fetchrow_hashref;
2433 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2435 my ($subtitle)=$sth->fetchrow;
2436 $origbiblio->{'subtitle'}=$subtitle;
2437 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2439 my $origadditionalauthors;
2440 while (my ($author) = $sth->fetchrow) {
2441 push (@{$origbiblio->{'additionalauthors'}}, $author);
2442 $origadditionalauthors->{$author}=1;
2444 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2447 while (my ($subject) = $sth->fetchrow) {
2448 push (@{$origbiblio->{'subjects'}}, $subject);
2449 $origsubjects->{$subject}=1;
2453 # Obtain a list of MARC Record_ID's that are tied to this biblio
2454 $sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
2457 while (my ($bibid) = $sth->fetchrow) {
2458 push(@marcrecords, $bibid);
2462 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
2463 my $q_author=$dbh->quote($biblio->{'author'});
2464 logchange('kohadb', 'change', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
2465 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
2467 foreach $bibid (@marcrecords) {
2468 logchange('marc', 'change', $bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2469 changeSubfield($bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2472 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
2473 my $q_title=$dbh->quote($biblio->{'title'});
2474 logchange('kohadb', 'change', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
2475 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
2477 foreach $Record_ID (@marcrecords) {
2478 logchange('marc', 'change', $Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2479 changeSubfield($Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2482 if ($biblio->{'subtitle'} ne $origbiblio->{'subtitle'}) {
2483 my $q_subtitle=$dbh->quote($biblio->{'subtitle'});
2484 logchange('kohadb', 'change', 'biblio', 'subtitle', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2485 my $sti=$dbh->prepare("update bibliosubtitle set subtitle=$q_subtitle where biblionumber=$biblio->{'biblionumber'}");
2487 foreach $Record_ID (@marcrecords) {
2488 logchange('marc', 'change', $Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2489 changeSubfield($Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2492 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
2493 my $q_unititle=$dbh->quote($biblio->{'unititle'});
2494 logchange('kohadb', 'change', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
2495 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
2498 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
2499 my $q_notes=$dbh->quote($biblio->{'notes'});
2500 logchange('kohadb', 'change', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
2501 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
2503 foreach $Record_ID (@marcrecords) {
2504 logchange('marc', 'change', $Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2505 changeSubfield($Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2508 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
2509 my $q_serial=$dbh->quote($biblio->{'serial'});
2510 logchange('kohadb', 'change', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
2511 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
2514 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
2515 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
2516 logchange('kohadb', 'change', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2517 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
2519 foreach $Record_ID (@marcrecords) {
2520 logchange('marc', 'change', $Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2521 changeSubfield($Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2524 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
2525 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
2526 logchange('kohadb', 'change', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
2527 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
2529 foreach $Record_ID (@marcrecords) {
2530 logchange('marc', 'change', $Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2531 changeSubfield($Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2535 # Check for subject heading changes
2539 foreach $newsubject (@{$biblio->{'subject'}}) {
2540 $subjects->{$newsubject}=1;
2541 if ($origsubjects->{$newsubject}) {
2542 $subjects->{$newsubject}=2;
2544 my $q_newsubject=$dbh->quote($newsubject);
2545 my $sth=$dbh->prepare("insert into bibliosubject (subject,biblionumber) values ($q_newsubject, $biblionumber)");
2547 logchange('kohadb', 'add', 'biblio', 'subject', $newsubject);
2549 $subfields->{1}->{'Subfield_Mark'}='a';
2550 $subfields->{1}->{'Subfield_Value'}=$newsubject;
2553 foreach $Record_ID (@marcrecords) {
2554 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2555 logchange('marc', 'add', $Record_ID, '650', 'a', $newsubject);
2560 foreach $origsubject (keys %$origsubjects) {
2561 if ($subjects->{$origsubject} == 1) {
2562 my $q_origsubject=$dbh->quote($origsubject);
2563 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'subject', $origsubject);
2564 my $sth=$dbh->prepare("delete from bibliosubject where biblionumber=$biblionumber and subject=$q_origsubject");
2570 sub OLD_MAYBE_DELETED_updateBiblioItem {
2571 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
2573 # This routine should also check to see which fields are actually being
2574 # modified, and log all changes.
2576 my ($env, $biblioitem) = @_;
2577 my $dbh = C4::Context->dbh;
2579 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2580 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
2581 # obi = original biblioitem
2582 my $obi=$sth->fetchrow_hashref;
2583 $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");
2585 my ($Record_ID) = $sth->fetchrow;
2586 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
2587 logchange('kohadb', 'change', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2588 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
2589 logchange('marc', 'change', $Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2590 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2592 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
2593 logchange('kohadb', 'change', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
2594 my $q_volume=$dbh->quote($biblioitem->{'volume'});
2595 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
2596 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2597 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2599 if ($biblioitem->{'number'} ne $obi->{'number'}) {
2600 logchange('kohadb', 'change', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
2601 my $q_number=$dbh->quote($biblioitem->{'number'});
2602 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
2603 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2604 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2606 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
2607 logchange('kohadb', 'change', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2608 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
2609 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
2610 logchange('marc', 'change', $Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2611 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2613 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
2614 logchange('kohadb', 'change', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
2615 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
2616 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
2617 logchange('marc', 'change', $Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2618 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2620 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
2621 logchange('kohadb', 'change', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
2622 my $q_issn=$dbh->quote($biblioitem->{'issn'});
2623 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
2624 logchange('marc', 'change', $Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2625 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2627 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
2628 logchange('kohadb', 'change', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
2629 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
2630 logchange('marc', 'change', $Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2631 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2633 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
2634 logchange('kohadb', 'change', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
2635 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
2636 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
2637 logchange('marc', 'change', $Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2638 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2640 if ($biblioitem->{'place'} ne $obi->{'place'}) {
2641 logchange('kohadb', 'change', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
2642 my $q_place=$dbh->quote($biblioitem->{'place'});
2643 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
2644 logchange('marc', 'change', $Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2645 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2647 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
2648 logchange('kohadb', 'change', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2649 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
2650 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
2651 logchange('marc', 'change', $Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2652 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2654 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
2655 logchange('kohadb', 'change', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2656 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
2657 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
2658 logchange('marc', 'change', $Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2659 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2661 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
2662 logchange('kohadb', 'change', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
2663 my $q_illus=$dbh->quote($biblioitem->{'illus'});
2664 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
2665 logchange('marc', 'change', $Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2666 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2668 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
2669 logchange('kohadb', 'change', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
2670 my $q_pages=$dbh->quote($biblioitem->{'pages'});
2671 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
2672 logchange('marc', 'change', $Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2673 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2675 if ($biblioitem->{'size'} ne $obi->{'size'}) {
2676 logchange('kohadb', 'change', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
2677 my $q_size=$dbh->quote($biblioitem->{'size'});
2678 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
2679 logchange('marc', 'change', $Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2680 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2682 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
2683 logchange('kohadb', 'change', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
2684 my $q_notes=$dbh->quote($biblioitem->{'notes'});
2685 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
2686 logchange('marc', 'change', $Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2687 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2689 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
2690 logchange('kohadb', 'change', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
2691 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
2692 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
2693 logchange('marc', 'change', $Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2694 changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2699 sub OLD_MAYBE_DELETED_updateItem {
2700 # Update the item with itemnumber $item->{'itemnumber'}
2701 # This routine should also modify the corresponding MARC record data. (852 and
2702 # 876 tags with 876p tag the same as $item->{'barcode'}
2704 # This routine should also check to see which fields are actually being
2705 # modified, and log all changes.
2707 my ($env, $item) = @_;
2708 my $dbh = C4::Context->dbh;
2709 my $itemnumber=$item->{'itemnumber'};
2710 my $biblionumber=$item->{'biblionumber'};
2711 my $biblioitemnumber=$item->{'biblioitemnumber'};
2712 my $barcode=$item->{'barcode'};
2713 my $dateaccessioned=$item->{'dateaccessioned'};
2714 my $booksellerid=$item->{'booksellerid'};
2715 my $homebranch=$item->{'homebranch'};
2716 my $price=$item->{'price'};
2717 my $replacementprice=$item->{'replacementprice'};
2718 my $replacementpricedate=$item->{'replacementpricedate'};
2719 my $multivolume=$item->{'multivolume'};
2720 my $stack=$item->{'stack'};
2721 my $notforloan=$item->{'notforloan'};
2722 my $itemlost=$item->{'itemlost'};
2723 my $wthdrawn=$item->{'wthdrawn'};
2724 my $bulk=$item->{'bulk'};
2725 my $restricted=$item->{'restricted'};
2726 my $binding=$item->{'binding'};
2727 my $itemnotes=$item->{'itemnotes'};
2728 my $holdingbranch=$item->{'holdingbranch'};
2729 my $interim=$item->{'interim'};
2730 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
2732 my $olditem=$sth->fetchrow_hashref;
2733 my $q_barcode=$dbh->quote($olditem->{'barcode'});
2734 $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");
2736 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
2737 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
2739 my ($link) = $sth->fetchrow;
2740 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
2742 my ($Subfield852_ID) = $sth->fetchrow;
2744 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
2745 logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
2746 my $q_barcode=$dbh->quote($item->{'barcode'});
2747 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
2749 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
2750 logchange('marc', 'change', $Record_ID, '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
2752 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
2753 logchange('kohadb', 'change', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
2754 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
2755 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
2757 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
2758 logchange('marc', 'change', $Record_ID, '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
2760 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
2761 logchange('kohadb', 'change', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2762 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
2763 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
2765 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
2766 logchange('marc', 'change', $Record_ID, '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2768 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
2769 logchange('kohadb', 'change', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
2770 my $q_homebranch=$dbh->quote($item->{'homebranch'});
2771 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
2773 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
2774 logchange('marc', 'change', $Record_ID, '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
2776 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
2777 logchange('kohadb', 'change', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2778 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
2779 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
2781 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
2782 logchange('marc', 'change', $Record_ID, '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2784 if ($item->{'price'} ne $olditem->{'price'}) {
2785 logchange('kohadb', 'change', 'items', 'price', $olditem->{'price'}, $item->{'price'});
2786 my $q_price=$dbh->quote($item->{'price'});
2787 my $sth=$dbh->prepare("update items set price=$q_price where itemnumber=$itemnumber");
2789 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'price'}, $item->{'price'}, $Subfield876_ID);
2790 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'price'}, $item->{'price'});
2792 if ($item->{'itemnotes'} ne $olditem->{'itemnotes'}) {
2793 logchange('kohadb', 'change', 'items', 'itemnotes', $olditem->{'itemnotes'}, $item->{'itemnotes'});
2794 my $q_itemnotes=$dbh->quote($item->{'itemnotes'});
2795 my $sth=$dbh->prepare("update items set itemnotes=$q_itemnotes where itemnumber=$itemnumber");
2797 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'itemnotes'}, $item->{'itemnotes'}, $Subfield876_ID);
2798 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'itemnotes'}, $item->{'itemnotes'});
2800 if ($item->{'notforloan'} ne $olditem->{'notforloan'}) {
2801 logchange('kohadb', 'change', 'items', 'notforloan', $olditem->{'notforloan'}, $item->{'notforloan'});
2802 my $sth=$dbh->prepare("update items set notforloan=$notforloan where itemnumber=$itemnumber");
2804 if ($item->{'notforloan'}) {
2805 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2806 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2808 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2809 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2812 if ($item->{'itemlost'} ne $olditem->{'itemlost'}) {
2813 logchange('kohadb', 'change', 'items', 'itemlost', $olditem->{'itemlost'}, $item->{'itemlost'});
2814 my $sth=$dbh->prepare("update items set itemlost=$itemlost where itemnumber=$itemnumber");
2816 if ($item->{'itemlost'}) {
2817 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2818 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2820 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2821 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2824 if ($item->{'wthdrawn'} ne $olditem->{'wthdrawn'}) {
2825 logchange('kohadb', 'change', 'items', 'wthdrawn', $olditem->{'wthdrawn'}, $item->{'wthdrawn'});
2826 my $sth=$dbh->prepare("update items set wthdrawn=$wthdrawn where itemnumber=$itemnumber");
2828 if ($item->{'wthdrawn'}) {
2829 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2830 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2832 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2833 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2836 if ($item->{'restricted'} ne $olditem->{'restricted'}) {
2837 logchange('kohadb', 'change', 'items', 'restricted', $olditem->{'restricted'}, $item->{'restricted'});
2838 my $sth=$dbh->prepare("update items set restricted=$restricted where itemnumber=$itemnumber");
2840 if ($item->{'restricted'}) {
2841 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2842 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2844 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2845 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2851 # Add a biblioitem and related data to Koha database
2852 sub OLD_MAY_BE_DELETED_newcompletebiblioitem {
2857 # FIXME - Unused argument
2858 $biblio, # hash ref to biblio record
2859 $biblioitem, # hash ref to biblioitem record
2860 $subjects, # list ref of subjects
2861 $addlauthors, # list ref of additional authors
2864 my ( $biblionumber, $biblioitemnumber, $error); # return values
2869 my $additionalauthor;
2872 $dbh = C4::Context->dbh;
2874 print "<PRE>Trying to add biblio item Title=$biblio->{title} " .
2875 "ISBN=$biblioitem->{isbn} </PRE>\n" if $debug;
2877 # Make sure master biblio entry exists
2878 ($biblionumber,$error)=getoraddbiblio($dbh, $biblio);
2882 $biblioitem->{biblionumber}=$biblionumber;
2885 $biblioitemnumber=newbiblioitem($biblioitem);
2888 $sth=$dbh->prepare("insert into bibliosubject
2889 (biblionumber,subject)
2891 foreach $subjectheading (@{$subjects} ) {
2892 $sth->execute($biblionumber, $subjectheading)
2893 or $error.=$sth->errstr ;
2897 # Add additional authors
2898 $sth=$dbh->prepare("insert into additionalauthors
2899 (biblionumber,author)
2901 foreach $additionalauthor (@{$addlauthors} ) {
2902 $sth->execute($biblionumber, $additionalauthor)
2903 or $error.=$sth->errstr ;
2907 # couldn't get biblio
2909 $biblioitemnumber='';
2911 } # if no biblio error
2913 return ( $biblionumber, $biblioitemnumber, $error);
2915 } # sub newcompletebiblioitem
2919 # END OF UNUSEFUL SUBs
2923 END { } # module clean-up code here (global destructor)