1 package C4::Catalogue; #asummes C4/Acquisitions.pm
3 # Continue working on updateItem!!!!!!
11 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
13 # set the version for version checking
17 @EXPORT = qw(&newBiblio &newBiblioItem &newItem &updateBiblio &updateBiblioItem
18 &updateItem &changeSubfield);
19 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
21 # your exported package globals go here,
22 # as well as any optionally exported functions
24 @EXPORT_OK = qw($Var1 %Hashit);
27 # non-exported package globals go here
28 use vars qw(@more $stuff);
30 # initalize package globals, first exported ones
36 # then the others (which are still accessible as $Some::Module::stuff)
40 # all file-scoped lexicals must be created before
41 # the functions below that use them.
43 # file-private lexicals go here
47 # here's a file-private function as a closure,
48 # callable as &$priv_func; it cannot be prototyped.
53 # make all your functions, whether exported or not;
58 # This subroutine makes no modifications to the MARC tables. MARC records are
59 # only created when new biblioitems are added.
60 my ($env, $biblio) = @_;
62 my $title=$biblio->{'title'};
63 my $q_title=$dbh->quote($title);
64 my $subtitle=$biblio->{'subtitle'};
65 my $q_subtitle=$dbh->quote($subtitle);
66 ($q_subtitle) || ($q_subtitle="''");
67 my $author=$biblio->{'author'};
68 my $q_author=$dbh->quote($author);
69 my $unititle=$biblio->{'unititle'};
70 my $q_unititle=$dbh->quote($unititle);
71 my $copyrightdate=$biblio->{'copyrightdate'};
72 my $serial=$biblio->{'serial'};
73 my $seriestitle=$biblio->{'seriestitle'};
74 my $q_seriestitle=$dbh->quote($seriestitle);
75 my $notes=$biblio->{'notes'};
76 my $q_notes=$dbh->quote($notes);
77 my $subject=$biblio->{'subject'};
78 my $additionalauthors=$biblio->{'additionalauthors'};
79 my $sth=$dbh->prepare("select max(biblionumber) from biblio");
81 my ($biblionumber) = $sth->fetchrow;
83 $sth=$dbh->prepare("insert into biblio (biblionumber,title,author,unititle,copyrightdate,serial,seriestitle,notes) values ($biblionumber,$q_title,$q_author,$q_unititle,$copyrightdate,$serial,$q_seriestitle,$q_notes)");
85 $sth=$dbh->prepare("insert into bibliosubtitle (biblionumber,subtitle) values ($biblionumber,$q_subtitle)");
88 my $q_subject=$dbh->quote($_);
89 my $sth=$dbh->prepare("insert into bibliosubject (biblionumber,subject) values ($biblionumber,$q_subject)");
92 foreach (@$additionalauthors) {
93 my $q_additionalauthor=$dbh->quote($_);
94 my $sth=$dbh->prepare("insert into additionalauthors (biblionumber,author) values ($biblionumber,$q_additionalauthor)");
101 # Subroutine changes a subfield value given a Record_ID, Tag, and Subfield_Mark.
102 # Routine should be made more robust. It currently checks to make sure that
103 # the existing Subfield_Value is the same as the one passed in. What if no
104 # subfield matches this Subfield_OldValue? Create a new Subfield? Maybe check
105 # to make sure that the mark is repeatable first and that no other subfield
106 # with that mark already exists? Ability to return errors and status?
108 # Also, currently, if more than one subfield matches the Record_ID, Tag,
109 # Subfield_Mark, and Subfield_OldValue, only the first one will be modified.
111 # Might be nice to be able to pass a Subfield_ID or Subfield_Key directly to
112 # this routine to remove ambiguity, if possible.
114 # Pass barcode to remove ambiguity for changes to individual items. Look up
115 # field link and sequence number based on barcode.
119 my $firstdigit=substr($tag, 0, 1);
120 my $Subfield_Mark=shift;
121 my $Subfield_OldValue=shift;
122 my $Subfield_Value=shift;
123 my $Subfield_ID=shift;
124 my $Subfield_Key=shift;
126 my $q_Subfield_Value=$dbh->quote($Subfield_Value);
128 # Great. Subfield_Key makes the record absolutely unique. Just make
130 my $sth=$dbh->prepare("update $firstdigit\XX_Subfield_Table set Subfield_Value=$q_Subfield_Value where Subfield_Key=$Subfield_Key");
132 } elsif ($Subfield_ID) {
133 # Subfield_ID does not make the record unique. Could be multiple
134 # records with the same mark. This is a bad situatoin.
135 my $sth=$dbh->prepare("select Subfield_Key, Subfield_Value from $firstdigit\XX_Subfield_Table where Subfield_Mark='$Subfield_Mark' and Subfield_ID=$Subfield_ID");
137 while (my ($key, $Value) = $sth->fetchrow) {
138 if ($Value eq $Subfield_OldValue) {
139 my $sti=$dbh->prepare("update $firstdigit\XX_Subfield_Table set Subfield_Value=$q_Subfield_Value where Subfield_Key=$key");
146 my $sth=$dbh->prepare("select S.Subfield_Key, S.Subfield_ID, S.Subfield_Value from Bib_Table B, $firstdigit\XX_Tag_Table T, $firstdigit\XX_Subfield_Table S where B.Record_ID=$Record_ID and B.Tag_$firstdigit\XX_ID=T.Tag_ID and T.Subfield_ID=S.Subfield_ID and S.Subfield_Mark='$Subfield_Mark'");
148 while (my ($key, $ID, $Value) = $sth->fetchrow) {
149 if ($Value eq $Subfield_OldValue) {
150 my $sti=$dbh->prepare("update $firstdigit\XX_Subfield_Table set Subfield_Value=$q_Subfield_Value where Subfield_Key=$key");
157 return($Subfield_ID, $Subfield_Key);
161 # Update the biblio with biblionumber $biblio->{'biblionumber'}
162 # I guess this routine should search through all marc records for a record that
163 # has the same biblionumber stored in it, and modify the MARC record as well as
166 # Also, this subroutine should search through the $biblio object and compare it
167 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
168 # this logging feature to be usable to undo changes easily.
170 # Need to add support for bibliosubject, additionalauthors, bibliosubtitle tables
172 my ($env, $biblio) = @_;
173 my $biblionumber=$biblio->{'biblionumber'};
175 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
177 my $origbiblio=$sth->fetchrow_hashref;
180 # Obtain a list of MARC Record_ID's that are tied to this biblio
181 $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_Value=$biblionumber and S.Subfield_Mark='c'");
184 while (my ($Record_ID) = $sth->fetchrow) {
185 push(@marcrecords, $Record_ID);
190 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
191 my $q_author=$dbh->quote($biblio->{'author'});
192 logchange('kohadb', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
193 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
195 logchange('marc', '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
196 foreach (@marcrecords) {
197 changeSubfield($_, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
200 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
201 my $q_title=$dbh->quote($biblio->{'title'});
202 logchange('kohadb', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
203 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
205 logchange('marc', '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
206 foreach (@marcrecords) {
207 changeSubfield($_, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
210 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
211 my $q_unititle=$dbh->quote($biblio->{'unititle'});
212 logchange('kohadb', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
213 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
216 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
217 my $q_notes=$dbh->quote($biblio->{'notes'});
218 logchange('kohadb', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
219 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
221 logchange('marc', '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
222 foreach (@marcrecords) {
223 changeSubfield($_, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
226 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
227 my $q_serial=$dbh->quote($biblio->{'serial'});
228 logchange('kohadb', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
229 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
232 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
233 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
234 logchange('kohadb', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
235 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
237 logchange('marc', '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
238 foreach (@marcrecords) {
239 changeSubfield($_, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
242 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
243 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
244 logchange('kohadb', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
245 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
247 logchange('marc', '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
248 foreach (@marcrecords) {
249 changeSubfield($_, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
255 # Subroutine to log changes to databases
257 if ($database eq 'kohadb') {
262 print "KOHA: $section $item $original $new\n";
263 } elsif ($database eq 'marc') {
266 my $subfield_ID=shift;
269 print "MARC: $tag $mark $subfield_ID $original $new\n";
274 # Subroutine to add a tag to an existing MARC Record. If a new linkage id is
275 # desired, set $env->{'linkage'} to 1. If an existing linkage id should be
276 # set, set $env->{'linkid'} to the link number.
277 my ($env, $Record_ID, $tag, $Indicator1, $Indicator2, $subfields) = @_;
279 ($Indicator1) || ($Indicator1=' ');
280 ($Indicator2) || ($Indicator2=' ');
281 my $firstdigit=substr($tag,0,1);
283 foreach (sort keys %$subfields) {
284 my $Subfield_Mark=$subfields->{$_}->{'Subfield_Mark'};
285 my $Subfield_Value=$subfields->{$_}->{'Subfield_Value'};
286 my $q_Subfield_Value=$dbh->quote($Subfield_Value);
288 my $sth=$dbh->prepare("insert into $firstdigit\XX_Subfield_Table (Subfield_ID, Subfield_Mark, Subfield_Value) values ($Subfield_ID, '$Subfield_Mark', $q_Subfield_Value)");
291 my $sth=$dbh->prepare("insert into $firstdigit\XX_Subfield_Table (Subfield_Mark, Subfield_Value) values ('$Subfield_Mark', $q_Subfield_Value)");
293 my $Subfield_Key=$dbh->{'mysql_insertid'};
294 $Subfield_ID=$Subfield_Key;
295 $sth=$dbh->prepare("update $firstdigit\XX_Subfield_Table set Subfield_ID=$Subfield_ID where Subfield_Key=$Subfield_Key");
299 if (my $linkid=$env->{'linkid'}) {
301 my $sth=$dbh->prepare("insert into $firstdigit\XX_Subfield_Table (Subfield_ID, Subfield_Mark, Subfield_Value) values ($Subfield_ID, '8', '$linkid')");
304 my $sth=$dbh->prepare("insert into $firstdigit\XX_Tag_Table (Indicator1, Indicator2, Tag, Subfield_ID) values ('$Indicator1', '$Indicator2', '$tag', $Subfield_ID)");
306 my $Tag_Key=$dbh->{'mysql_insertid'};
308 $sth=$dbh->prepare("update $firstdigit\XX_Tag_Table set Tag_ID=$Tag_ID where Tag_Key=$Tag_Key");
310 $sth=$dbh->prepare("insert into Bib_Table (Record_ID, Tag_$firstdigit\XX_ID) values ($Record_ID, $Tag_ID)");
312 if ($env->{'linkage'}) {
313 my $sth=$dbh->prepare("insert into $firstdigit\XX_Subfield_Table (Subfield_ID, Subfield_Mark, Subfield_Value) values ($Subfield_ID, '8', '$Tag_ID')");
319 return ($env, $Tag_ID);
323 my ($env, $biblioitem) = @_;
325 my $biblionumber=$biblioitem->{'biblionumber'};
326 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
327 my $volume=$biblioitem->{'volume'};
328 my $q_volume=$dbh->quote($volume);
329 my $number=$biblioitem->{'number'};
330 my $q_number=$dbh->quote($number);
331 my $classification=$biblioitem->{'classification'};
332 my $q_classification=$dbh->quote($classification);
333 my $itemtype=$biblioitem->{'itemtype'};
334 my $q_itemtype=$dbh->quote($itemtype);
335 my $isbn=$biblioitem->{'isbn'};
336 my $q_isbn=$dbh->quote($isbn);
337 my $issn=$biblioitem->{'issn'};
338 my $q_issn=$dbh->quote($issn);
339 my $dewey=$biblioitem->{'dewey'};
341 ($dewey == 0) && ($dewey='');
342 my $subclass=$biblioitem->{'subclass'};
343 my $q_subclass=$dbh->quote($subclass);
344 my $publicationyear=$biblioitem->{'publicationyear'};
345 my $publishercode=$biblioitem->{'publishercode'};
346 my $q_publishercode=$dbh->quote($publishercode);
347 my $volumedate=$biblioitem->{'volumedate'};
348 my $q_volumedate=$dbh->quote($volumedate);
349 my $illus=$biblioitem->{'illus'};
350 my $q_illus=$dbh->quote($illus);
351 my $pages=$biblioitem->{'pages'};
352 my $q_pages=$dbh->quote($pages);
353 my $notes=$biblioitem->{'notes'};
354 my $q_notes=$dbh->quote($notes);
355 my $size=$biblioitem->{'size'};
356 my $q_size=$dbh->quote($size);
357 my $place=$biblioitem->{'place'};
358 my $q_place=$dbh->quote($place);
359 my $lccn=$biblioitem->{'lccn'};
360 my $q_lccn=$dbh->quote($lccn);
363 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
366 unless ($env->{'marconly'}) {
367 #my $sth=$dbh->prepare("lock tables biblioitems write");
369 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
371 my ($biblioitemnumber) =$sth->fetchrow;
373 $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)");
375 #my $sth=$dbh->prepare("unlock tables");
380 # Should we check if there is already a biblioitem/marc with the
381 # same isbn/lccn/issn?
383 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
385 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
386 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
388 my ($subtitle) = $sth->fetchrow;
389 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
391 my @additionalauthors;
392 while (my ($additionalauthor) = $sth->fetchrow) {
393 push (@additionalauthors, $additionalauthor);
395 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
398 while (my ($subject) = $sth->fetchrow) {
399 push (@subjects, $subject);
404 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
406 my $Resource_ID=$dbh->{'mysql_insertid'};
407 my $Record_ID=$Resource_ID;
408 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
414 $subfields->{1}->{'Subfield_Mark'}='a';
415 $subfields->{1}->{'Subfield_Value'}=$title;
417 $subfields->{2}->{'Subfield_Mark'}='b';
418 $subfields->{2}->{'Subfield_Value'}=$subtitle;
421 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
427 $subfields->{1}->{'Subfield_Mark'}='a';
428 $subfields->{1}->{'Subfield_Value'}=$author;
430 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
435 $subfields->{1}->{'Subfield_Mark'}='a';
436 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
438 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
443 $subfields->{1}->{'Subfield_Mark'}='a';
444 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
445 $subfields->{2}->{'Subfield_Mark'}='3';
446 $subfields->{2}->{'Subfield_Value'}='biblio';
448 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
451 foreach (@additionalauthors) {
453 (next) unless ($author);
455 $subfields->{1}->{'Subfield_Mark'}='a';
456 $subfields->{1}->{'Subfield_Value'}=$author;
457 $subfields->{2}->{'Subfield_Mark'}='e';
458 $subfields->{2}->{'Subfield_Value'}='author';
460 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
464 (next) unless ($illus);
466 $subfields->{1}->{'Subfield_Mark'}='a';
467 $subfields->{1}->{'Subfield_Value'}=$illus;
468 $subfields->{2}->{'Subfield_Mark'}='e';
469 $subfields->{2}->{'Subfield_Value'}='illustrator';
471 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
474 foreach (@subjects) {
476 (next) unless ($subject);
478 $subfields->{1}->{'Subfield_Mark'}='a';
479 $subfields->{1}->{'Subfield_Value'}=$subject;
481 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
488 $subfields->{1}->{'Subfield_Mark'}='a';
489 $subfields->{1}->{'Subfield_Value'}=$isbn;
491 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
496 $subfields->{1}->{'Subfield_Mark'}='a';
497 $subfields->{1}->{'Subfield_Value'}=$lccn;
499 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
504 $subfields->{1}->{'Subfield_Mark'}='a';
505 $subfields->{1}->{'Subfield_Value'}=$issn;
507 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
512 $subfields->{1}->{'Subfield_Mark'}='a';
513 $subfields->{1}->{'Subfield_Value'}=$dewey;
515 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
517 # DEWEY subclass and itemtype
520 $subfields->{1}->{'Subfield_Mark'}='a';
521 $subfields->{1}->{'Subfield_Value'}=$itemtype;
522 $subfields->{2}->{'Subfield_Mark'}='b';
523 $subfields->{2}->{'Subfield_Value'}=$subclass;
524 $subfields->{3}->{'Subfield_Mark'}='c';
525 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
526 $subfields->{4}->{'Subfield_Mark'}='d';
527 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
529 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
534 $subfields->{1}->{'Subfield_Mark'}='a';
535 $subfields->{1}->{'Subfield_Value'}=$place;
536 $subfields->{2}->{'Subfield_Mark'}='b';
537 $subfields->{2}->{'Subfield_Value'}=$publishercode;
538 $subfields->{3}->{'Subfield_Mark'}='c';
539 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
540 if ($copyrightdate) {
541 $subfields->{4}->{'Subfield_Mark'}='c';
542 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
545 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
548 if ($pages || $size) {
550 $subfields->{1}->{'Subfield_Mark'}='a';
551 $subfields->{1}->{'Subfield_Value'}=$pages;
552 $subfields->{2}->{'Subfield_Mark'}='c';
553 $subfields->{2}->{'Subfield_Value'}=$size;
555 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
558 if ($volume || $number) {
560 $subfields->{1}->{'Subfield_Mark'}='v';
561 $subfields->{1}->{'Subfield_Value'}=$volume;
562 $subfields->{2}->{'Subfield_Mark'}='n';
563 $subfields->{2}->{'Subfield_Value'}=$number;
565 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
570 $subfields->{1}->{'Subfield_Mark'}='a';
571 $subfields->{1}->{'Subfield_Value'}=$notes;
572 $subfields->{2}->{'Subfield_Mark'}='3';
573 $subfields->{2}->{'Subfield_Value'}='biblioitem';
575 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
579 return ($env, $Record_ID);
582 sub updateBiblioItem {
583 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
585 # This routine should also check to see which fields are actually being
586 # modified, and log all changes.
588 my ($env, $biblioitem) = @_;
591 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
592 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
593 # obi = original biblioitem
594 my $obi=$sth->fetchrow_hashref;
595 $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");
597 my ($Record_ID) = $sth->fetchrow;
598 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
599 logchange('kohadb', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
600 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
601 logchange('marc', '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
602 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
604 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
605 logchange('kohadb', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
606 my $q_volume=$dbh->quote($biblioitem->{'volume'});
607 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
608 logchange('marc', '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
609 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
611 if ($biblioitem->{'number'} ne $obi->{'number'}) {
612 logchange('kohadb', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
613 my $q_number=$dbh->quote($biblioitem->{'number'});
614 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
615 logchange('marc', '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
616 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
618 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
619 logchange('kohadb', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
620 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
621 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
622 logchange('marc', '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
623 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
625 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
626 logchange('kohadb', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
627 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
628 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
629 logchange('marc', '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
630 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
632 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
633 logchange('kohadb', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
634 my $q_issn=$dbh->quote($biblioitem->{'issn'});
635 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
636 logchange('marc', '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
637 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
639 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
640 logchange('kohadb', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
641 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
642 logchange('marc', '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
643 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
645 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
646 logchange('kohadb', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
647 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
648 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
649 logchange('marc', '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
650 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
652 if ($biblioitem->{'place'} ne $obi->{'place'}) {
653 logchange('kohadb', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
654 my $q_place=$dbh->quote($biblioitem->{'place'});
655 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
656 logchange('marc', '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
657 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
659 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
660 logchange('kohadb', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
661 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
662 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
663 logchange('marc', '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
664 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
666 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
667 logchange('kohadb', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
668 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
669 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
670 logchange('marc', '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
671 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
673 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
674 logchange('kohadb', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
675 my $q_illus=$dbh->quote($biblioitem->{'illus'});
676 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
677 logchange('marc', '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
678 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
680 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
681 logchange('kohadb', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
682 my $q_pages=$dbh->quote($biblioitem->{'pages'});
683 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
684 logchange('marc', '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
685 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
687 if ($biblioitem->{'size'} ne $obi->{'size'}) {
688 logchange('kohadb', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
689 my $q_size=$dbh->quote($biblioitem->{'size'});
690 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
691 logchange('marc', '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
692 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
694 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
695 logchange('kohadb', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
696 my $q_notes=$dbh->quote($biblioitem->{'notes'});
697 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
698 logchange('marc', '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
699 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
701 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
702 logchange('kohadb', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
703 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
704 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
705 logchange('marc', '010', 'c', $obi->{'lccn'}, $biblioitem->{'lccn'});
706 changeSubfield($Record_ID, '010', 'c', $obi->{'lccn'}, $biblioitem->{'lccn'});
713 my ($env, $Record_ID, $item) = @_;
715 my $barcode=$item->{'barcode'};
716 my $q_barcode=$dbh->quote($barcode);
717 my $biblionumber=$item->{'biblionumber'};
718 my $biblioitemnumber=$item->{'biblioitemnumber'};
719 my $dateaccessioned=$item->{'dateaccessioned'};
720 my $booksellerid=$item->{'booksellerid'};
721 my $q_booksellerid=$dbh->quote($booksellerid);
722 my $homebranch=$item->{'homebranch'};
723 my $q_homebranch=$dbh->quote($homebranch);
724 my $holdingbranch=$item->{'holdingbranch'};
725 my $price=$item->{'price'};
726 my $replacementprice=$item->{'replacementprice'};
727 my $replacementpricedate=$item->{'replacementpricedate'};
728 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
729 my $notforloan=$item->{'notforloan'};
730 my $itemlost=$item->{'itemlost'};
731 my $wthdrawn=$item->{'wthdrawn'};
732 my $restricted=$item->{'restricted'};
733 my $itemnotes=$item->{'itemnotes'};
734 my $q_itemnotes=$dbh->quote($itemnotes);
735 my $itemtype=$item->{'itemtype'};
736 my $subclass=$item->{'subclass'};
740 unless ($env->{'marconly'}) {
741 my $sth=$dbh->prepare("select max(itemnumber) from items");
743 my ($itemnumber) =$sth->fetchrow;
745 $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)");
752 $subfields->{1}->{'Subfield_Mark'}='p';
753 $subfields->{1}->{'Subfield_Value'}=$barcode;
754 $subfields->{2}->{'Subfield_Mark'}='d';
755 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
756 $subfields->{3}->{'Subfield_Mark'}='e';
757 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
758 $subfields->{4}->{'Subfield_Mark'}='b';
759 $subfields->{4}->{'Subfield_Value'}=$homebranch;
760 $subfields->{5}->{'Subfield_Mark'}='l';
761 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
762 $subfields->{6}->{'Subfield_Mark'}='c';
763 $subfields->{6}->{'Subfield_Value'}=$price;
764 $subfields->{7}->{'Subfield_Mark'}='c';
765 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
766 $subfields->{8}->{'Subfield_Mark'}='d';
767 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
769 $subfields->{9}->{'Subfield_Mark'}='h';
770 $subfields->{9}->{'Subfield_Value'}='Not for loan';
773 $subfields->{10}->{'Subfield_Mark'}='j';
774 $subfields->{10}->{'Subfield_Value'}='Item lost';
777 $subfields->{11}->{'Subfield_Mark'}='j';
778 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
781 $subfields->{12}->{'Subfield_Mark'}='z';
782 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
787 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
789 $env->{'linkid'}=$Tag_ID;
792 $subfields2->{1}->{'Subfield_Mark'}='a';
793 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
794 $subfields2->{1}->{'Subfield_Mark'}='b';
795 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
796 $subfields2->{1}->{'Subfield_Mark'}='c';
797 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
798 $subfields2->{2}->{'Subfield_Mark'}='m';
799 $subfields2->{2}->{'Subfield_Value'}=$subclass;
800 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
805 # Update the item with itemnumber $item->{'itemnumber'}
806 # This routine should also modify the corresponding MARC record data. (852 and
807 # 876 tags with 876p tag the same as $item->{'barcode'}
809 # This routine should also check to see which fields are actually being
810 # modified, and log all changes.
812 my ($env, $item) = @_;
814 my $itemnumber=$item->{'itemnumber'};
815 my $biblionumber=$item->{'biblionumber'};
816 my $biblioitemnumber=$item->{'biblioitemnumber'};
817 my $barcode=$item->{'barcode'};
818 my $dateaccessioned=$item->{'dateaccessioned'};
819 my $booksellerid=$item->{'booksellerid'};
820 my $homebranch=$item->{'homebranch'};
821 my $price=$item->{'price'};
822 my $replacementprice=$item->{'replacementprice'};
823 my $replacementpricedate=$item->{'replacementpricedate'};
824 my $multivolume=$item->{'multivolume'};
825 my $stack=$item->{'stack'};
826 my $notforloan=$item->{'notforloan'};
827 my $itemlost=$item->{'itemlost'};
828 my $wthdrawn=$item->{'wthdrawn'};
829 my $bulk=$item->{'bulk'};
830 my $restricted=$item->{'restricted'};
831 my $binding=$item->{'binding'};
832 my $itemnotes=$item->{'itemnotes'};
833 my $holdingbranch=$item->{'holdingbranch'};
834 my $interim=$item->{'interim'};
835 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
837 my $olditem=$sth->fetchrow_hashref;
838 my $q_barcode=$dbh->quote($olditem->{'barcode'});
839 $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");
841 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
842 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
844 my ($link) = $sth->fetchrow;
845 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
847 my ($Subfield852_ID) = $sth->fetchrow;
849 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
850 logchange('kohadb', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
851 my $q_barcode=$dbh->quote($item->{'barcode'});
852 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
854 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
855 logchange('marc', '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
857 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
858 logchange('kohadb', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
859 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
860 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
862 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
863 logchange('marc', '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
865 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
866 logchange('kohadb', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
867 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
868 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
870 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
871 logchange('marc', '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
873 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
874 logchange('kohadb', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
875 my $q_homebranch=$dbh->quote($item->{'homebranch'});
876 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
878 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
879 logchange('marc', '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
881 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
882 logchange('kohadb', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
883 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
884 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
886 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
887 logchange('marc', '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
891 END { } # module clean-up code here (global destructor)