1 package C4::Catalogue; #asummes C4/Acquisitions.pm
7 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
9 # set the version for version checking
13 @EXPORT = qw(&newBiblio &newBiblioItem &newItem &updateBiblio &updateBiblioItem
14 &updateItem &changeSubfield);
15 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
17 # your exported package globals go here,
18 # as well as any optionally exported functions
20 @EXPORT_OK = qw($Var1 %Hashit);
23 # non-exported package globals go here
24 use vars qw(@more $stuff);
26 # initalize package globals, first exported ones
32 # then the others (which are still accessible as $Some::Module::stuff)
36 # all file-scoped lexicals must be created before
37 # the functions below that use them.
39 # file-private lexicals go here
43 # here's a file-private function as a closure,
44 # callable as &$priv_func; it cannot be prototyped.
49 # make all your functions, whether exported or not;
54 # This subroutine makes no modifications to the MARC tables. MARC records are
55 # only created when new biblioitems are added.
56 my ($env, $biblio) = @_;
57 my $title=$biblio->{'title'};
58 my $q_title=$dbh->quote($title);
59 my $subtitle=$biblio->{'subtitle'};
60 my $q_subtitle=$dbh->quote($subtitle);
61 ($q_subtitle) || ($q_subtitle="''");
62 my $author=$biblio->{'author'};
63 my $q_author=$dbh->quote($author);
64 my $unititle=$biblio->{'unititle'};
65 my $q_unititle=$dbh->quote($unititle);
66 my $copyrightdate=$biblio->{'copyrightdate'};
67 my $serial=$biblio->{'serial'};
68 my $seriestitle=$biblio->{'seriestitle'};
69 my $q_seriestitle=$dbh->quote($seriestitle);
70 my $notes=$biblio->{'notes'};
71 my $q_notes=$dbh->quote($notes);
72 my $subject=$biblio->{'subject'};
73 my $additionalauthors=$biblio->{'additionalauthors'};
74 my $sth=$dbh->prepare("select max(biblionumber) from biblio");
76 my ($biblionumber) = $sth->fetchrow;
78 $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)");
80 $sth=$dbh->prepare("insert into bibliosubtitle (biblionumber,subtitle) values ($biblionumber,$q_subtitle)");
83 my $q_subject=$dbh->quote($_);
84 my $sth=$dbh->prepare("insert into bibliosubject (biblionumber,subject) values ($biblionumber,$q_subject)");
87 foreach (@$additionalauthors) {
88 my $q_additionalauthor=$dbh->quote($_);
89 my $sth=$dbh->prepare("insert into additionalauthors (biblionumber,author) values ($biblionumber,$q_additionalauthor)");
96 # Subroutine changes a subfield value given a Record_ID, Tag, and Subfield_Mark.
97 # Routine should be made more robust. It currently checks to make sure that
98 # the existing Subfield_Value is the same as the one passed in. What if no
99 # subfield matches this Subfield_OldValue? Create a new Subfield? Maybe check
100 # to make sure that the mark is repeatable first and that no other subfield
101 # with that mark already exists? Ability to return errors and status?
103 # Also, currently, if more than one subfield matches the Record_ID, Tag,
104 # Subfield_Mark, and Subfield_OldValue, only the first one will be modified.
106 # Might be nice to be able to pass a Subfield_ID directly to this routine to
107 # remove ambiguity, if possible.
111 my $firstdigit=substr($tag, 0, 1);
112 my $Subfield_Mark=shift;
113 my $Subfield_OldValue=shift;
114 my $Subfield_Value=shift;
116 my $sth=$dbh->prepare("select 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'");
118 while (my ($ID, $Value) = $sth->fetchrow) {
119 if ($Value eq $Subfield_OldValue) {
120 my $q_Subfield_Value=$dbh->quote($Subfield_Value);
121 my $sti=$dbh->prepare("update $firstdigit\XX_Subfield_Table set Subfield_Value=$q_Subfield_Value where Subfield_ID=$ID");
129 # Update the biblio with biblionumber $biblio->{'biblionumber'}
130 # I guess this routine should search through all marc records for a record that
131 # has the same biblionumber stored in it, and modify the MARC record as well as
134 # Also, this subroutine should search through the $biblio object and compare it
135 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
136 # this logging feature to be usable to undo changes easily.
138 # Need to add support for bibliosubject, additionalauthors, bibliosubtitle tables
140 my ($env, $biblio) = @_;
141 my $biblionumber=$biblio->{'biblionumber'};
143 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
145 my $origbiblio=$sth->fetchrow_hashref;
148 # Obtain a list of MARC Record_ID's that are tied to this biblio
149 $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'");
152 while (my ($Record_ID) = $sth->fetchrow) {
153 push(@marcrecords, $Record_ID);
158 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
159 my $q_author=$dbh->quote($biblio->{'author'});
160 logchange('kohadb', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
161 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
163 logchange('marc', '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
164 foreach (@marcrecords) {
165 changeSubfield($_, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
168 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
169 my $q_title=$dbh->quote($biblio->{'title'});
170 logchange('kohadb', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
171 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
173 logchange('marc', '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
174 foreach (@marcrecords) {
175 changeSubfield($_, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
178 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
179 my $q_unititle=$dbh->quote($biblio->{'unititle'});
180 logchange('kohadb', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
181 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
184 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
185 my $q_notes=$dbh->quote($biblio->{'notes'});
186 logchange('kohadb', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
187 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
189 logchange('marc', '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
190 foreach (@marcrecords) {
191 changeSubfield($_, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
194 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
195 my $q_serial=$dbh->quote($biblio->{'serial'});
196 logchange('kohadb', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
197 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
200 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
201 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
202 logchange('kohadb', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
203 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
205 logchange('marc', '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
206 foreach (@marcrecords) {
207 changeSubfield($_, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
210 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
211 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
212 logchange('kohadb', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
213 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
215 logchange('marc', '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
216 foreach (@marcrecords) {
217 changeSubfield($_, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
223 # Subroutine to log changes to databases
232 # Subroutine to add a tag to an existing MARC Record. If a new linkage id is
233 # desired, set $env->{'linkage'} to 1. If an existing linkage id should be
234 # set, set $env->{'linkid'} to the link number.
235 my ($env, $Record_ID, $tag, $Indicator1, $Indicator2, $subfields) = @_;
237 ($Indicator1) || ($Indicator1=' ');
238 ($Indicator2) || ($Indicator2=' ');
239 my $firstdigit=substr($tag,0,1);
241 foreach (sort keys %$subfields) {
242 my $Subfield_Mark=$subfields->{$_}->{'Subfield_Mark'};
243 my $Subfield_Value=$subfields->{$_}->{'Subfield_Value'};
244 my $q_Subfield_Value=$dbh->quote($Subfield_Value);
246 my $sth=$dbh->prepare("insert into $firstdigit\XX_Subfield_Table (Subfield_ID, Subfield_Mark, Subfield_Value) values ($Subfield_ID, '$Subfield_Mark', $q_Subfield_Value)");
249 my $sth=$dbh->prepare("insert into $firstdigit\XX_Subfield_Table (Subfield_Mark, Subfield_Value) values ('$Subfield_Mark', $q_Subfield_Value)");
251 my $Subfield_Key=$dbh->{'mysql_insertid'};
252 $Subfield_ID=$Subfield_Key;
253 $sth=$dbh->prepare("update $firstdigit\XX_Subfield_Table set Subfield_ID=$Subfield_ID where Subfield_Key=$Subfield_Key");
257 if (my $linkid=$env->{'linkid'}) {
259 my $sth=$dbh->prepare("insert into $firstdigit\XX_Subfield_Table (Subfield_ID, Subfield_Mark, Subfield_Value) values ($Subfield_ID, '8', '$linkid')");
262 my $sth=$dbh->prepare("insert into $firstdigit\XX_Tag_Table (Indicator1, Indicator2, Tag, Subfield_ID) values ('$Indicator1', '$Indicator2', '$tag', $Subfield_ID)");
264 my $Tag_Key=$dbh->{'mysql_insertid'};
266 $sth=$dbh->prepare("update $firstdigit\XX_Tag_Table set Tag_ID=$Tag_ID where Tag_Key=$Tag_Key");
268 $sth=$dbh->prepare("insert into Bib_Table (Record_ID, Tag_$firstdigit\XX_ID) values ($Record_ID, $Tag_ID)");
270 if ($env->{'linkage'}) {
271 my $sth=$dbh->prepare("insert into $firstdigit\XX_Subfield_Table (Subfield_ID, Subfield_Mark, Subfield_Value) values ($Subfield_ID, '8', '$Tag_ID')");
277 return ($env, $Tag_ID);
281 my ($env, $biblioitem) = @_;
283 my $biblionumber=$biblioitem->{'biblionumber'};
284 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
285 my $volume=$biblioitem->{'volume'};
286 my $q_volume=$dbh->quote($volume);
287 my $number=$biblioitem->{'number'};
288 my $q_number=$dbh->quote($number);
289 my $classification=$biblioitem->{'classification'};
290 my $q_classification=$dbh->quote($classification);
291 my $itemtype=$biblioitem->{'itemtype'};
292 my $q_itemtype=$dbh->quote($itemtype);
293 my $isbn=$biblioitem->{'isbn'};
294 my $q_isbn=$dbh->quote($isbn);
295 my $issn=$biblioitem->{'issn'};
296 my $q_issn=$dbh->quote($issn);
297 my $dewey=$biblioitem->{'dewey'};
299 ($dewey == 0) && ($dewey='');
300 my $subclass=$biblioitem->{'subclass'};
301 my $q_subclass=$dbh->quote($subclass);
302 my $publicationyear=$biblioitem->{'publicationyear'};
303 my $publishercode=$biblioitem->{'publishercode'};
304 my $q_publishercode=$dbh->quote($publishercode);
305 my $volumedate=$biblioitem->{'volumedate'};
306 my $q_volumedate=$dbh->quote($volumedate);
307 my $illus=$biblioitem->{'illus'};
308 my $q_illus=$dbh->quote($illus);
309 my $pages=$biblioitem->{'pages'};
310 my $q_pages=$dbh->quote($pages);
311 my $notes=$biblioitem->{'notes'};
312 my $q_notes=$dbh->quote($notes);
313 my $size=$biblioitem->{'size'};
314 my $q_size=$dbh->quote($size);
315 my $place=$biblioitem->{'place'};
316 my $q_place=$dbh->quote($place);
317 my $lccn=$biblioitem->{'lccn'};
318 my $q_lccn=$dbh->quote($lccn);
321 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
324 unless ($env->{'marconly'}) {
325 #my $sth=$dbh->prepare("lock tables biblioitems write");
327 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
329 my ($biblioitemnumber) =$sth->fetchrow;
331 $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, $q_publicationyear, $q_publishercode, $q_volumedate, $q_illus, $q_pages,$q_notes, $q_size, $q_place, $q_lccn)");
333 #my $sth=$dbh->prepare("unlock tables");
338 # Should we check if there is already a biblioitem/marc with the
339 # same isbn/lccn/issn?
341 $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
343 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
344 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
346 my ($subtitle) = $sth->fetchrow;
347 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
349 my @additionalauthors;
350 while (my ($additionalauthor) = $sth->fetchrow) {
351 push (@additionalauthors, $additionalauthor);
353 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
356 while (my ($subject) = $sth->fetchrow) {
357 push (@subjects, $subject);
362 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
364 my $Resource_ID=$dbh->{'mysql_insertid'};
365 my $Record_ID=$Resource_ID;
366 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
372 $subfields->{1}->{'Subfield_Mark'}='a';
373 $subfields->{1}->{'Subfield_Value'}=$title;
375 $subfields->{2}->{'Subfield_Mark'}='b';
376 $subfields->{2}->{'Subfield_Value'}=$subtitle;
379 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
385 $subfields->{1}->{'Subfield_Mark'}='a';
386 $subfields->{1}->{'Subfield_Value'}=$author;
388 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
393 $subfields->{1}->{'Subfield_Mark'}='a';
394 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
396 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
401 $subfields->{1}->{'Subfield_Mark'}='a';
402 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
403 $subfields->{2}->{'Subfield_Mark'}='3';
404 $subfields->{2}->{'Subfield_Value'}='biblio';
406 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
409 foreach (@additionalauthors) {
411 (next) unless ($author);
413 $subfields->{1}->{'Subfield_Mark'}='a';
414 $subfields->{1}->{'Subfield_Value'}=$author;
415 $subfields->{2}->{'Subfield_Mark'}='e';
416 $subfields->{2}->{'Subfield_Value'}='author';
418 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
422 (next) unless ($illus);
424 $subfields->{1}->{'Subfield_Mark'}='a';
425 $subfields->{1}->{'Subfield_Value'}=$illus;
426 $subfields->{2}->{'Subfield_Mark'}='e';
427 $subfields->{2}->{'Subfield_Value'}='illustrator';
429 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
432 foreach (@subjects) {
434 (next) unless ($subject);
436 $subfields->{1}->{'Subfield_Mark'}='a';
437 $subfields->{1}->{'Subfield_Value'}=$subject;
439 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
446 $subfields->{1}->{'Subfield_Mark'}='a';
447 $subfields->{1}->{'Subfield_Value'}=$isbn;
449 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
454 $subfields->{1}->{'Subfield_Mark'}='a';
455 $subfields->{1}->{'Subfield_Value'}=$lccn;
457 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
462 $subfields->{1}->{'Subfield_Mark'}='a';
463 $subfields->{1}->{'Subfield_Value'}=$issn;
465 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
470 $subfields->{1}->{'Subfield_Mark'}='a';
471 $subfields->{1}->{'Subfield_Value'}=$dewey;
473 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
475 # DEWEY subclass and itemtype
478 $subfields->{1}->{'Subfield_Mark'}='a';
479 $subfields->{1}->{'Subfield_Value'}=$itemtype;
480 $subfields->{2}->{'Subfield_Mark'}='b';
481 $subfields->{2}->{'Subfield_Value'}=$subclass;
482 $subfields->{3}->{'Subfield_Mark'}='c';
483 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
484 $subfields->{4}->{'Subfield_Mark'}='d';
485 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
487 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
492 $subfields->{1}->{'Subfield_Mark'}='a';
493 $subfields->{1}->{'Subfield_Value'}=$place;
494 $subfields->{2}->{'Subfield_Mark'}='b';
495 $subfields->{2}->{'Subfield_Value'}=$publishercode;
496 $subfields->{3}->{'Subfield_Mark'}='c';
497 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
498 if ($copyrightdate) {
499 $subfields->{4}->{'Subfield_Mark'}='c';
500 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
503 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
506 if ($pages || $size) {
508 $subfields->{1}->{'Subfield_Mark'}='a';
509 $subfields->{1}->{'Subfield_Value'}=$pages;
510 $subfields->{2}->{'Subfield_Mark'}='c';
511 $subfields->{2}->{'Subfield_Value'}=$size;
513 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
516 if ($volume || $number) {
518 $subfields->{1}->{'Subfield_Mark'}='v';
519 $subfields->{1}->{'Subfield_Value'}=$volume;
520 $subfields->{2}->{'Subfield_Mark'}='n';
521 $subfields->{2}->{'Subfield_Value'}=$number;
523 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
528 $subfields->{1}->{'Subfield_Mark'}='a';
529 $subfields->{1}->{'Subfield_Value'}=$notes;
530 $subfields->{2}->{'Subfield_Mark'}='3';
531 $subfields->{2}->{'Subfield_Value'}='biblioitem';
533 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
537 return ($env, $Record_ID);
540 sub updateBiblioItem {
541 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
542 # This routine should also modify the corresponding MARC record data.
544 # This routine should also check to see which fields are actually being
545 # modified, and log all changes.
547 my ($env, $biblioitem) = @_;
550 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
551 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
552 # obi = original biblioitem
553 my $obi=$sth->fetchrow_hashref;
554 $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");
556 my ($Record_ID) = $sth->fetchrow;
557 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
558 logchange('kohadb', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
559 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
560 logchange('marc', '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
561 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
563 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
564 logchange('kohadb', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
565 my $q_volume=$dbh->quote($biblioitem->{'volume'});
566 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
567 logchange('marc', '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
568 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
570 if ($biblioitem->{'number'} ne $obi->{'number'}) {
571 logchange('kohadb', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
572 my $q_number=$dbh->quote($biblioitem->{'number'});
573 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
574 logchange('marc', '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
575 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
577 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
578 logchange('kohadb', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
579 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
580 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
581 logchange('marc', '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
582 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
584 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
585 logchange('kohadb', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
586 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
587 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
588 logchange('marc', '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
589 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
591 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
592 logchange('kohadb', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
593 my $q_issn=$dbh->quote($biblioitem->{'issn'});
594 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
595 logchange('marc', '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
596 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
598 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
599 logchange('kohadb', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
600 my $sth=$dbh->prepare("update biblioitems set dewey=$dewey where biblioitemnumber=$biblioitemnumber");
601 logchange('marc', '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
602 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
604 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
605 logchange('kohadb', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
606 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
607 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
608 logchange('marc', '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
609 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
611 if ($biblioitem->{'place'} ne $obi->{'place'}) {
612 logchange('kohadb', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
613 my $q_place=$dbh->quote($biblioitem->{'place'});
614 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
615 logchange('marc', '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
616 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
618 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
619 logchange('kohadb', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
620 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
621 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
622 logchange('marc', '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
623 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
625 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
626 logchange('kohadb', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
627 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
628 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
629 logchange('marc', '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
630 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
632 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
633 logchange('kohadb', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
634 my $q_illus=$dbh->quote($biblioitem->{'illus'});
635 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
636 logchange('marc', '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
637 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
639 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
640 logchange('kohadb', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
641 my $q_pages=$dbh->quote($biblioitem->{'pages'});
642 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
643 logchange('marc', '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
644 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
646 if ($biblioitem->{'size'} ne $obi->{'size'}) {
647 logchange('kohadb', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
648 my $q_size=$dbh->quote($biblioitem->{'size'});
649 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
650 logchange('marc', '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
651 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
653 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
654 logchange('kohadb', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
655 my $q_notes=$dbh->quote($biblioitem->{'notes'});
656 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
657 logchange('marc', '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
658 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
660 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
661 logchange('kohadb', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
662 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
663 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
664 logchange('marc', '010', 'c', $obi->{'lccn'}, $biblioitem->{'lccn'});
665 changeSubfield($Record_ID, '010', 'c', $obi->{'lccn'}, $biblioitem->{'lccn'});
672 my ($env, $Record_ID, $item) = @_;
674 my $barcode=$item->{'barcode'};
675 my $dateaccessioned=$item->{'dateaccessioned'};
676 my $booksellerid=$item->{'booksellerid'};
677 my $homebranch=$item->{'homebranch'};
678 my $holdingbranch=$item->{'holdingbranch'};
679 my $price=$item->{'price'};
680 my $replacementprice=$item->{'replacementprice'};
681 my $replacementpricedate=$item->{'replacementpricedate'};
682 my $notforloan=$item->{'notforloan'};
683 my $itemlost=$item->{'itemlost'};
684 my $wthdrawn=$item->{'wthdrawn'};
685 my $restricted=$item->{'restricted'};
686 my $itemnotes=$item->{'itemnotes'};
687 my $itemtype=$item->{'itemtype'};
688 my $subclass=$item->{'subclass'};
692 unless ($env->{'marconly'}) {
693 my $sth=$dbh->prepare("select max(itemnumber) from items");
695 my ($itemnumber) =$sth->fetchrow;
697 $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)");
704 $subfields->{1}->{'Subfield_Mark'}='p';
705 $subfields->{1}->{'Subfield_Value'}=$barcode;
706 $subfields->{2}->{'Subfield_Mark'}='d';
707 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
708 $subfields->{3}->{'Subfield_Mark'}='e';
709 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
710 $subfields->{4}->{'Subfield_Mark'}='b';
711 $subfields->{4}->{'Subfield_Value'}=$homebranch;
712 $subfields->{5}->{'Subfield_Mark'}='l';
713 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
714 $subfields->{6}->{'Subfield_Mark'}='c';
715 $subfields->{6}->{'Subfield_Value'}=$price;
716 $subfields->{7}->{'Subfield_Mark'}='c';
717 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
718 $subfields->{8}->{'Subfield_Mark'}='d';
719 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
721 $subfields->{9}->{'Subfield_Mark'}='h';
722 $subfields->{9}->{'Subfield_Value'}='Not for loan';
725 $subfields->{10}->{'Subfield_Mark'}='j';
726 $subfields->{10}->{'Subfield_Value'}='Item lost';
729 $subfields->{11}->{'Subfield_Mark'}='j';
730 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
733 $subfields->{12}->{'Subfield_Mark'}='z';
734 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
739 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
741 $env->{'linkid'}=$Tag_ID;
744 $subfields2->{1}->{'Subfield_Mark'}='a';
745 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
746 $subfields2->{1}->{'Subfield_Mark'}='b';
747 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
748 $subfields2->{1}->{'Subfield_Mark'}='c';
749 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
750 $subfields2->{2}->{'Subfield_Mark'}='m';
751 $subfields2->{2}->{'Subfield_Value'}=$subclass;
752 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
757 # Update the item with itemnumber $item->{'itemnumber'}
758 # This routine should also modify the corresponding MARC record data. (852 and
759 # 876 tags with 876p tag the same as $item->{'barcode'}
761 # This routine should also check to see which fields are actually being
762 # modified, and log all changes.
764 my ($env, $item) = @_;
767 END { } # module clean-up code here (global destructor)