3 # Contains all sub used for biblio management. tables :
4 # biblio, biblioitems, items
5 # bibliosubject, bibliosubtitle
7 # move from 1.2 to 1.4 version :
8 # 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
9 # In the 1.4 version, we want to do 2 differents things :
10 # - keep populating the old-DB, that has a LOT less datas than MARC
11 # - populate the MARC-DB
12 # To populate the DBs we have 2 differents sources :
13 # - the standard acquisition system (through book sellers), that does'nt use MARC data
14 # - the MARC acquisition system, that uses MARC data.
16 # thus, we have 2 differents cases :
17 # - 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
18 # - 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.
19 # we MUST have an API for true MARC data, that populate MARC-DB then old-DB
21 # That's why we need 4 APIs :
22 # all subs beginning by MARC manage only MARC tables. They manage MARC-DB with MARC::Record parameters
23 # all subs beginning by OLD manage only OLD-DB tables. They manage old-DB with old-DB parameters
24 # 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
25 # 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.
27 # 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.
28 # 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 ;-)
37 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
39 # set the version for version checking
44 &MARCaddbiblio &MARCmodsubfield &MARCaddsubfield
49 &MARCaddword &MARCdelword
51 &newBiblio &newBiblioItem &newItem
52 &updateBiblio &updateBiblioItem &updateItem
53 &itemcount &newbiblio &newbiblioitem
54 &modnote &newsubject &newsubtitle
55 &modbiblio &checkitems
57 &modsubtitle &modsubject &modaddauthor &moditem &countitems
58 &delitem &deletebiblioitem &delbiblio
59 &getitemtypes &getbiblio
60 &getbiblioitembybiblionumber
61 &getbiblioitem &getitemsbybiblioitem &isbnsearch
64 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
66 # your exported package globals go here,
67 # as well as any optionally exported functions
69 @EXPORT_OK = qw($Var1 %Hashit);
72 # non-exported package globals go here
73 use vars qw(@more $stuff);
75 # initalize package globals, first exported ones
81 # then the others (which are still accessible as $Some::Module::stuff)
85 # all file-scoped lexicals must be created before
86 # the functions below that use them.
88 # file-private lexicals go here
92 # here's a file-private function as a closure,
93 # callable as &$priv_func; it cannot be prototyped.
98 # make all your functions, whether exported or not;
102 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
105 # all the following subs takes a MARC::Record as parameter and manage
106 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
107 # ALLxxx subs (xxx deals with old-DB parameters, the ALLxxx deals with MARC-DB parameter)
112 $biblio= MARC::Record->new();
114 $bibid = &MARCaddbiblio($dbh,$biblio);
118 Creates a biblio (in the MARC tables only).
122 Paul POULAIN paul.poulain@free.fr
127 # pass the MARC::Record to this function, and it will create the records in the marc tables
128 my ($dbh,$record) = @_;
129 my @fields=$record->fields();
131 # adding main table, and retrieving bibid
132 $dbh->do("lock tables marc_biblio WRITE");
133 my $sth=$dbh->prepare("insert into marc_biblio (datecreated) values (now())");
135 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
137 ($bibid)=$sth->fetchrow;
139 $dbh->do("unlock tables");
141 # now, add subfields...
142 foreach my $field (@fields) {
143 my @subfields=$field->subfields();
145 foreach my $subfieldcount (0..$#subfields) {
146 print $field->tag().":".$field->indicator(1).$field->indicator(2).":".$subfields[$subfieldcount][0].":".$subfields[$subfieldcount][1]."\n";
147 &MARCaddsubfield($dbh,$bibid,
149 $field->indicator(1).$field->indicator(2),
151 $subfields[$subfieldcount][0],
153 $subfields[$subfieldcount][1]
163 &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
167 Adds a subfield in a biblio (in the MARC tables only).
171 Paul POULAIN paul.poulain@free.fr
175 sub MARCaddsubfield {
176 # Add a new subfield to a tag into the DB.
182 my $subfieldcode=shift;
183 my $subfieldorder=shift;
184 my $subfieldvalue=shift;
186 unless ($subfieldorder) {
187 my $sth=$dbh->prepare("select max(subfieldorder) from marc_subfield_table where tag=$tagid");
190 ($subfieldorder) = $sth->fetchrow;
196 if (length($subfieldvalue)>255) {
197 $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
198 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
199 $sth->execute($subfieldvalue);
200 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
202 my ($res)=$sth->fetchrow;
203 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?)");
204 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
205 $dbh->do("unlock tables");
207 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?)");
208 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
210 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
216 $MARCRecord = &MARCgetbiblio($dbh,$bibid);
220 Returns a MARC::Record for the biblio $bibid.
224 Paul POULAIN paul.poulain@free.fr
229 # Returns MARC::Record of the biblio passed in parameter.
231 my $record = MARC::Record->new();
232 #---- TODO : the leader is missing
233 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
234 from marc_subfield_table
237 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
238 $sth->execute($bibid);
239 while (my $row=$sth->fetchrow_hashref) {
240 if ($row->{'valuebloblink'}) { #---- search blob if there is one
241 $sth2->execute($row->{'valuebloblink'});
242 my $row2=$sth2->fetchrow_hashref;
244 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
246 if ($record->field($row->{'tag'})) {
247 my $field =$record->field($row->{'tag'});
249 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
250 $record->delete_field($field);
251 $record->add_fields($field);
254 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
255 $record->add_fields($temp);
259 # print "----------------------\n".$record->as_formatted()."\n-----------------";
266 $MARCRecord = &MARCmodbiblio($dbh,$bibid);
270 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
271 if $delete == 1, every field/subfield not found is deleted in the biblio
272 otherwise, only data passed to MARCmodbiblio is managed.
273 thus, you can change only a small part of a biblio (like an item...)
277 Paul POULAIN paul.poulain@free.fr
282 my ($dbh,$bibid,$delete,$record)=@_;
283 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
284 # if nothing to change, don't waste time...
285 if ($oldrecord eq $record) {
286 # print "nothing to do \n";
289 # otherwise, skip through each subfield...
290 my @fields = $record->fields();
292 foreach my $field (@fields) {
293 #print "tag : ".$field->tag()."\n";
294 my $oldfield = $oldrecord->field($field->tag());
295 my @subfields=$field->subfields();
298 foreach my $subfield (@subfields) {
300 if ($oldfield eq 0) {
301 # just adding datas...
302 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
303 1,@$subfield[0],$subfieldorder,@$subfield[1]);
305 # modify he subfield if it's a different string
306 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
307 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
308 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
310 # print "nothing to change\n";
320 ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
324 MARCmodsubfield changes the value of a given subfield
328 Paul POULAIN paul.poulain@free.fr
332 sub MARCmodsubfield {
333 # Subroutine changes a subfield value given a subfieldid.
334 my ($dbh, $subfieldid, $subfieldvalue )=@_;
336 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
337 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
338 $sth1->execute($subfieldid);
339 my ($oldvaluebloblink)=$sth1->fetchrow;
342 # if too long, use a bloblink
343 if (length($subfieldvalue)>255 ) {
344 # if already a bloblink, update it, otherwise, insert a new one.
345 if ($oldvaluebloblink) {
346 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
347 $sth->execute($subfieldvalue,$oldvaluebloblink);
349 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
350 $sth->execute($subfieldvalue);
351 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
353 my ($res)=$sth->fetchrow;
354 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
355 $sth->execute($subfieldid);
358 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
359 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
360 $sth->execute($subfieldvalue, $subfieldid);
362 $dbh->do("unlock tables");
364 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
365 $sth->execute($subfieldid);
366 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
368 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
369 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
370 return($subfieldid, $subfieldvalue);
376 $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
380 MARCfindsubfield returns a subfield number given a bibid/tag/subfield values.
381 Returns -1 if more than 1 answer
385 Paul POULAIN paul.poulain@free.fr
389 sub MARCfindsubfield {
390 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
394 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
395 if ($subfieldvalue) {
396 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
398 if ($subfieldorder<1) {
401 $query .= " and subfieldorder=$subfieldorder";
403 my $sti=$dbh->prepare($query);
404 $sti->execute($bibid,$tag, $subfieldcode);
405 while (($subfieldid) = $sti->fetchrow) {
407 $lastsubfieldid=$subfieldid;
409 if ($resultcounter>1) {
410 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
411 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
414 return $lastsubfieldid;
421 $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
425 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
429 Paul POULAIN paul.poulain@free.fr
433 sub MARCfindsubfieldid {
434 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
435 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
436 where bibid=? and tag=? and tagorder=?
437 and subfieldcode=? and subfieldorder=?");
438 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
439 my ($res) = $sth->fetchrow;
446 &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
450 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
454 Paul POULAIN paul.poulain@free.fr
458 sub MARCdelsubfield {
459 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
460 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
461 # my $dbh=&C4Connect;
462 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
463 tag='$tag' and tagorder='$tagorder'
464 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
471 &MARCdelbiblio($dbh,$bibid);
475 MARCdelbiblio delete biblio $bibid
479 Paul POULAIN paul.poulain@free.fr
484 # delete a biblio for a $bibid
485 my ($dbh,$bibid) = @_;
486 # my $dbh=&C4Connect;
487 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
488 $dbh->do("delete from marc_biblio where bibid='$bibid'");
494 $MARCRecord = &MARCkoha2marc($dbh,$biblionumber,biblioitemnumber,itemnumber);
498 MARCkoha2marc is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem/item
502 Paul POULAIN paul.poulain@free.fr
507 # this function builds MARC::Record from the old koha-DB fields
508 my ($dbh,$biblionumber,$biblioitemnumber,$itemnumber) = @_;
509 # my $dbh=&C4Connect;
510 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
511 my $record = MARC::Record->new();
512 #--- if bibid, then retrieve old-style koha data
513 if ($biblionumber>0) {
514 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
515 from biblio where biblionumber=?");
516 $sth2->execute($biblionumber);
517 my $row=$sth2->fetchrow_hashref;
519 foreach $code (keys %$row) {
521 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
525 #--- if biblioitem, then retrieve old-style koha data
526 if ($biblioitemnumber>0) {
527 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
528 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
529 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
531 WHERE biblionumber=? and biblioitemnumber=?
533 $sth2->execute($biblionumber,$biblioitemnumber);
534 my $row=$sth2->fetchrow_hashref;
536 foreach $code (keys %$row) {
538 &MARCkoha2marcOnefield($sth,$record,"biblioitem.".$code,$row->{$code});
542 #--- if item, then retrieve old-style koha data
544 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
545 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
546 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
547 reserves,restricted,binding,itemnotes,holdingbranch,interim,timestamp
549 WHERE biblionumber=? and itemnumber=?");
550 $sth2->execute($biblionumber,$itemnumber);
551 my $row=$sth2->fetchrow_hashref;
553 foreach $code (keys %$row) {
555 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
560 # TODO : retrieve notes, additionalauthors
565 MARCkoha2marcOnefield is used by MARCkoha2marc and is not exported
569 Paul POULAIN paul.poulain@free.fr
572 sub MARCkoha2marcOnefield {
573 my ($sth,$record,$kohafieldname,$value)=@_;
576 $sth->execute($kohafieldname);
577 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
578 if ($record->field($tagfield)) {
579 my $tag =$record->field($tagfield);
581 $tag->add_subfields($tagsubfield,$value);
582 $record->delete_field($tag);
583 $record->add_fields($tag);
586 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
594 MARCaddword is used to manage MARC_word table and is not exported
598 Paul POULAIN paul.poulain@free.fr
603 # split a subfield string and adds it into the word table.
605 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
606 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
607 # TODO : remove stopwords
608 my @words = split / /,$sentence;
609 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
610 values (?,?,?,?,?,?,soundex(?))");
611 foreach my $word (@words) {
612 # we record only words longer than 2 car
613 if (length($word)>1) {
614 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
615 # print "($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word)\n";
622 MARCdelword is used to manage MARC_word table and is not exported
626 Paul POULAIN paul.poulain@free.fr
631 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
632 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
633 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
634 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
639 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
642 # all the following subs are the exact copy of 1.0/1.2 version of the sub
643 # without the OLD. The OLDxxx is called by the original xxx sub.
644 # the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
645 # WARNING : there is 1 difference between initialxxx and OLDxxx :
646 # the db header $dbh is always passed as parameter
647 # to avoid over-DB connexion
650 my ($dbh,$biblio) = @_;
651 # my $dbh = &C4Connect;
652 my $query = "Select max(biblionumber) from biblio";
653 my $sth = $dbh->prepare($query);
655 my $data = $sth->fetchrow_arrayref;
656 my $bibnum = $$data[0] + 1;
659 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
660 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
661 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
662 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
663 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
664 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
665 if ($biblio->{'seriestitle'}) { $series = 1 };
668 $query = "insert into biblio set
669 biblionumber = $bibnum,
670 title = $biblio->{'title'},
671 author = $biblio->{'author'},
672 copyrightdate = $biblio->{'copyright'},
674 seriestitle = $biblio->{'seriestitle'},
675 notes = $biblio->{'notes'},
676 abstract = $biblio->{'abstract'}";
678 $sth = $dbh->prepare($query);
687 my ($dbh,$biblio) = @_;
688 # my $dbh = C4Connect;
692 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
693 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
694 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
695 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
696 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
697 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
698 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
699 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
701 $query = "Update biblio set
702 title = $biblio->{'title'},
703 author = $biblio->{'author'},
704 abstract = $biblio->{'abstract'},
705 copyrightdate = $biblio->{'copyrightdate'},
706 seriestitle = $biblio->{'seriestitle'},
707 serial = $biblio->{'serial'},
708 unititle = $biblio->{'unititle'},
709 notes = $biblio->{'notes'}
710 where biblionumber = $biblio->{'biblionumber'}";
711 $sth = $dbh->prepare($query);
717 return($biblio->{'biblionumber'});
721 my ($dbh,$bibnum, $subtitle) = @_;
722 # my $dbh = C4Connect;
723 my $query = "update bibliosubtitle set
724 subtitle = '$subtitle'
725 where biblionumber = $bibnum";
726 my $sth = $dbh->prepare($query);
734 sub OLDmodaddauthor {
735 my ($dbh,$bibnum, $author) = @_;
736 # my $dbh = C4Connect;
737 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
738 my $sth = $dbh->prepare($query);
744 $query = "Insert into additionalauthors set
746 biblionumber = '$bibnum'";
747 $sth = $dbh->prepare($query);
759 my ($dbh,$bibnum, $force, @subject) = @_;
760 # my $dbh = C4Connect;
761 my $count = @subject;
763 for (my $i = 0; $i < $count; $i++) {
764 $subject[$i] =~ s/^ //g;
765 $subject[$i] =~ s/ $//g;
766 my $query = "select * from catalogueentry
767 where entrytype = 's'
768 and catalogueentry = '$subject[$i]'";
769 my $sth = $dbh->prepare($query);
772 if (my $data = $sth->fetchrow_hashref) {
774 if ($force eq $subject[$i]) {
775 # subject not in aut, chosen to force anway
776 # so insert into cataloguentry so its in auth file
777 $query = "Insert into catalogueentry
778 (entrytype,catalogueentry)
779 values ('s','$subject[$i]')";
780 my $sth2 = $dbh->prepare($query);
785 $error = "$subject[$i]\n does not exist in the subject authority file";
786 $query = "Select * from catalogueentry
787 where entrytype = 's'
788 and (catalogueentry like '$subject[$i] %'
789 or catalogueentry like '% $subject[$i] %'
790 or catalogueentry like '% $subject[$i]')";
791 my $sth2 = $dbh->prepare($query);
794 while (my $data = $sth2->fetchrow_hashref) {
795 $error = $error."<br>$data->{'catalogueentry'}";
803 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
804 my $sth = $dbh->prepare($query);
807 for (my $i = 0; $i < $count; $i++) {
808 $sth = $dbh->prepare("Insert into bibliosubject
809 values ('$subject[$i]', $bibnum)");
821 my ($dbh,$biblioitem) = @_;
822 # my $dbh = C4Connect;
825 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
826 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
827 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
828 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
829 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
830 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
831 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
832 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
833 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
834 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
835 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
836 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
837 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
838 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
840 $query = "Update biblioitems set
841 itemtype = $biblioitem->{'itemtype'},
842 url = $biblioitem->{'url'},
843 isbn = $biblioitem->{'isbn'},
844 publishercode = $biblioitem->{'publishercode'},
845 publicationyear = $biblioitem->{'publicationyear'},
846 classification = $biblioitem->{'classification'},
847 dewey = $biblioitem->{'dewey'},
848 subclass = $biblioitem->{'subclass'},
849 illus = $biblioitem->{'illus'},
850 pages = $biblioitem->{'pages'},
851 volumeddesc = $biblioitem->{'volumeddesc'},
852 notes = $biblioitem->{'notes'},
853 size = $biblioitem->{'size'},
854 place = $biblioitem->{'place'}
855 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
863 my ($dbh,$bibitemnum,$note)=@_;
865 my $query="update biblioitems set notes='$note' where
866 biblioitemnumber='$bibitemnum'";
867 my $sth=$dbh->prepare($query);
873 sub OLDnewbiblioitem {
874 my ($dbh,$biblioitem) = @_;
875 # my $dbh = C4Connect;
876 my $query = "Select max(biblioitemnumber) from biblioitems";
877 my $sth = $dbh->prepare($query);
881 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
882 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
883 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
884 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
885 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
886 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
887 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
888 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
889 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
890 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
891 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
892 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
893 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
894 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
895 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
896 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
897 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
898 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
899 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
900 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
903 $data = $sth->fetchrow_arrayref;
904 $bibitemnum = $$data[0] + 1;
908 $query = "insert into biblioitems set
909 biblioitemnumber = $bibitemnum,
910 biblionumber = $biblioitem->{'biblionumber'},
911 volume = $biblioitem->{'volume'},
912 number = $biblioitem->{'number'},
913 classification = $biblioitem->{'classification'},
914 itemtype = $biblioitem->{'itemtype'},
915 url = $biblioitem->{'url'},
916 isbn = $biblioitem->{'isbn'},
917 issn = $biblioitem->{'issn'},
918 dewey = $biblioitem->{'dewey'},
919 subclass = $biblioitem->{'subclass'},
920 publicationyear = $biblioitem->{'publicationyear'},
921 publishercode = $biblioitem->{'publishercode'},
922 volumedate = $biblioitem->{'volumedate'},
923 volumeddesc = $biblioitem->{'volumeddesc'},
924 illus = $biblioitem->{'illus'},
925 pages = $biblioitem->{'pages'},
926 notes = $biblioitem->{'notes'},
927 size = $biblioitem->{'size'},
928 lccn = $biblioitem->{'lccn'},
929 marc = $biblioitem->{'marc'},
930 place = $biblioitem->{'place'}";
932 $sth = $dbh->prepare($query);
941 my ($dbh,$bibnum)=@_;
943 my $query="insert into bibliosubject (biblionumber) values
945 my $sth=$dbh->prepare($query);
953 my ($dbh,$bibnum, $subtitle) = @_;
954 # my $dbh = C4Connect;
955 $subtitle = $dbh->quote($subtitle);
956 my $query = "insert into bibliosubtitle set
957 biblionumber = $bibnum,
958 subtitle = $subtitle";
959 my $sth = $dbh->prepare($query);
969 my ($dbh,$item, @barcodes) = @_;
970 # my $dbh = C4Connect;
971 my $query = "Select max(itemnumber) from items";
972 my $sth = $dbh->prepare($query);
978 $data = $sth->fetchrow_hashref;
979 $itemnumber = $data->{'max(itemnumber)'} + 1;
982 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
983 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
984 $item->{'price'} = $dbh->quote($item->{'price'});
985 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
986 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
988 foreach my $barcode (@barcodes) {
989 $barcode = uc($barcode);
990 $barcode = $dbh->quote($barcode);
991 $query = "Insert into items set
992 itemnumber = $itemnumber,
993 biblionumber = $item->{'biblionumber'},
994 biblioitemnumber = $item->{'biblioitemnumber'},
996 booksellerid = $item->{'booksellerid'},
997 dateaccessioned = NOW(),
998 homebranch = $item->{'homebranch'},
999 holdingbranch = $item->{'homebranch'},
1000 price = $item->{'price'},
1001 replacementprice = $item->{'replacementprice'},
1002 replacementpricedate = NOW(),
1003 itemnotes = $item->{'itemnotes'}";
1004 if ($item->{'loan'}) {
1005 $query .= ",notforloan = $item->{'loan'}";
1008 $sth = $dbh->prepare($query);
1010 if (defined $sth->errstr) {
1011 $error .= $sth->errstr;
1022 my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1023 # my $dbh=C4Connect;
1024 my $query="update items set biblioitemnumber=$bibitemnum,
1025 barcode='$barcode',itemnotes='$notes'
1026 where itemnumber=$itemnum";
1027 if ($barcode eq ''){
1028 $query="update items set biblioitemnumber=$bibitemnum,notforloan=$loan where itemnumber=$itemnum";
1031 $query="update items set biblioitemnumber=$bibitemnum,
1034 homebranch='$homebranch',
1036 wthdrawn='$wthdrawn'
1037 where itemnumber=$itemnum";
1039 if ($replacement ne ''){
1040 $query=~ s/ where/,replacementprice='$replacement' where/;
1043 my $sth=$dbh->prepare($query);
1050 my ($dbh,$itemnum)=@_;
1051 # my $dbh=C4Connect;
1052 my $query="select * from items where itemnumber=$itemnum";
1053 my $sth=$dbh->prepare($query);
1055 my @data=$sth->fetchrow_array;
1057 $query="Insert into deleteditems values (";
1058 foreach my $temp (@data){
1059 $query=$query."'$temp',";
1063 $sth=$dbh->prepare($query);
1066 $query = "Delete from items where itemnumber=$itemnum";
1067 $sth=$dbh->prepare($query);
1073 sub OLDdeletebiblioitem {
1074 my ($dbh,$biblioitemnumber) = @_;
1075 # my $dbh = C4Connect;
1076 my $query = "Select * from biblioitems
1077 where biblioitemnumber = $biblioitemnumber";
1078 my $sth = $dbh->prepare($query);
1083 if (@results = $sth->fetchrow_array) {
1084 $query = "Insert into deletedbiblioitems values (";
1085 foreach my $value (@results) {
1086 $value = $dbh->quote($value);
1087 $query .= "$value,";
1090 $query =~ s/\,$/\)/;
1093 $query = "Delete from biblioitems
1094 where biblioitemnumber = $biblioitemnumber";
1098 # Now delete all the items attached to the biblioitem
1099 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1100 $sth = $dbh->prepare($query);
1102 while (@results = $sth->fetchrow_array) {
1103 $query = "Insert into deleteditems values (";
1104 foreach my $value (@results) {
1105 $value = $dbh->quote($value);
1106 $query .= "$value,";
1108 $query =~ s/\,$/\)/;
1112 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1115 } # sub deletebiblioitem
1118 my ($dbh,$biblio)=@_;
1119 # my $dbh=C4Connect;
1120 my $query="select * from biblio where biblionumber=$biblio";
1121 my $sth=$dbh->prepare($query);
1123 if (my @data=$sth->fetchrow_array){
1125 $query="Insert into deletedbiblio values (";
1126 foreach my $temp (@data){
1127 $temp=~ s/\'/\\\'/g;
1128 $query=$query."'$temp',";
1132 $sth=$dbh->prepare($query);
1135 $query = "Delete from biblio where biblionumber=$biblio";
1136 $sth=$dbh->prepare($query);
1153 my $query="Select count(*) from items where biblionumber=$biblio";
1155 my $sth=$dbh->prepare($query);
1157 my $data=$sth->fetchrow_hashref;
1160 return($data->{'count(*)'});
1166 my $query="Select ordernumber
1168 where biblionumber=? and biblioitemnumber=?";
1169 my $sth=$dbh->prepare($query);
1170 $sth->execute($bib,$bi);
1171 my $ordnum=$sth->fetchrow_hashref;
1173 my $order=getsingleorder($ordnum->{'ordernumber'});
1176 return ($order,$ordnum->{'ordernumber'});
1179 sub getsingleorder {
1182 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1183 where aqorders.ordernumber=?
1184 and biblio.biblionumber=aqorders.biblionumber and
1185 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1186 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1187 my $sth=$dbh->prepare($query);
1188 $sth->execute($ordnum);
1189 my $data=$sth->fetchrow_hashref;
1197 my $dbh = &C4Connect;
1198 my $bibnum=OLDnewbiblio($dbh,$biblio);
1206 my $dbh = C4Connect;
1207 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1209 return($biblionumber);
1213 my ($bibnum, $subtitle) = @_;
1214 my $dbh = C4Connect;
1215 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1221 my ($bibnum, $author) = @_;
1222 my $dbh = C4Connect;
1223 &OLDmodaddauthor($dbh,$bibnum,$author);
1225 } # sub modaddauthor
1229 my ($bibnum, $force, @subject) = @_;
1230 my $dbh = C4Connect;
1231 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1236 my ($biblioitem) = @_;
1237 my $dbh = C4Connect;
1238 &OLDmodbibitem($dbh,$biblioitem);
1243 my ($bibitemnum,$note)=@_;
1245 &OLDmodnote($dbh,$bibitemnum,$note);
1250 my ($biblioitem) = @_;
1251 my $dbh = C4Connect;
1252 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1253 return($bibitemnum);
1259 &OLDnewsubject($dbh,$bibnum);
1264 my ($bibnum, $subtitle) = @_;
1265 my $dbh = C4Connect;
1266 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1272 my ($item, @barcodes) = @_;
1273 my $dbh = C4Connect;
1274 my $error=&OLDnewitems($dbh,$item,@barcodes);
1280 my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1282 &OLDmoditem($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement);
1287 my ($count,@barcodes)=@_;
1290 for (my $i=0;$i<$count;$i++){
1291 $barcodes[$i]=uc $barcodes[$i];
1292 my $query="Select * from items where barcode='$barcodes[$i]'";
1293 my $sth=$dbh->prepare($query);
1295 if (my $data=$sth->fetchrow_hashref){
1296 $error.=" Duplicate Barcode: $barcodes[$i]";
1305 my ($bibitemnum)=@_;
1307 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1308 my $sth=$dbh->prepare($query);
1310 my $data=$sth->fetchrow_hashref;
1313 return($data->{'count(*)'});
1319 &OLDdelitem($dbh,$itemnum);
1323 sub deletebiblioitem {
1324 my ($biblioitemnumber) = @_;
1325 my $dbh = C4Connect;
1326 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1328 } # sub deletebiblioitem
1334 &OLDdelbiblio($dbh,$biblio);
1339 my $dbh = C4Connect;
1340 my $query = "select * from itemtypes";
1341 my $sth = $dbh->prepare($query);
1342 # || die "Cannot prepare $query" . $dbh->errstr;
1347 # || die "Cannot execute $query\n" . $sth->errstr;
1348 while (my $data = $sth->fetchrow_hashref) {
1349 $results[$count] = $data;
1355 return($count, @results);
1356 } # sub getitemtypes
1359 my ($biblionumber) = @_;
1360 my $dbh = C4Connect;
1361 my $query = "Select * from biblio where biblionumber = $biblionumber";
1362 my $sth = $dbh->prepare($query);
1363 # || die "Cannot prepare $query\n" . $dbh->errstr;
1368 # || die "Cannot execute $query\n" . $sth->errstr;
1369 while (my $data = $sth->fetchrow_hashref) {
1370 $results[$count] = $data;
1376 return($count, @results);
1380 my ($biblioitemnum) = @_;
1381 my $dbh = C4Connect;
1382 my $query = "Select * from biblioitems where
1383 biblioitemnumber = $biblioitemnum";
1384 my $sth = $dbh->prepare($query);
1390 while (my $data = $sth->fetchrow_hashref) {
1391 $results[$count] = $data;
1397 return($count, @results);
1398 } # sub getbiblioitem
1400 sub getbiblioitembybiblionumber {
1401 my ($biblionumber) = @_;
1402 my $dbh = C4Connect;
1403 my $query = "Select * from biblioitems where biblionumber =
1405 my $sth = $dbh->prepare($query);
1411 while (my $data = $sth->fetchrow_hashref) {
1412 $results[$count] = $data;
1418 return($count, @results);
1421 sub getitemsbybiblioitem {
1422 my ($biblioitemnum) = @_;
1423 my $dbh = C4Connect;
1424 my $query = "Select * from items, biblio where
1425 biblio.biblionumber = items.biblionumber and biblioitemnumber
1427 my $sth = $dbh->prepare($query);
1428 # || die "Cannot prepare $query\n" . $dbh->errstr;
1433 # || die "Cannot execute $query\n" . $sth->errstr;
1434 while (my $data = $sth->fetchrow_hashref) {
1435 $results[$count] = $data;
1441 return($count, @results);
1442 } # sub getitemsbybiblioitem
1446 my $dbh = C4Connect;
1452 $isbn = $dbh->quote($isbn);
1453 $query = "Select biblio.* from biblio, biblioitems where
1454 biblio.biblionumber = biblioitems.biblionumber
1456 $sth = $dbh->prepare($query);
1459 while (my $data = $sth->fetchrow_hashref) {
1460 $results[$count] = $data;
1466 return($count, @results);
1470 # At the moment this is just a straight copy of the subject code. Needs heavy
1471 # modification to work for additional authors, obviously.
1472 # Check for additional author changes
1474 # my $newadditionalauthor='';
1475 # my $additionalauthors;
1476 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
1477 # $additionalauthors->{$newadditionalauthor}=1;
1478 # if ($origadditionalauthors->{$newadditionalauthor}) {
1479 # $additionalauthors->{$newadditionalauthor}=2;
1481 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
1482 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
1484 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
1486 # $subfields->{1}->{'Subfield_Mark'}='a';
1487 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
1490 # foreach $Record_ID (@marcrecords) {
1491 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1492 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
1496 # my $origadditionalauthor;
1497 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
1498 # if ($additionalauthors->{$origadditionalauthor} == 1) {
1499 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
1500 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
1501 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
1511 # Subroutine to log changes to databases
1512 # Eventually, this subroutine will be used to create a log of all changes made,
1513 # with the possibility of "undo"ing some changes
1515 if ($database eq 'kohadb') {
1521 print STDERR "KOHA: $type $section $item $original $new\n";
1522 } elsif ($database eq 'marc') {
1524 my $Record_ID=shift;
1527 my $subfield_ID=shift;
1530 print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
1536 # UNUSEFUL SUBs. Could be deleted, kept only until beta test
1537 # maybe useful for some MARC tricks steve used.
1540 sub OLD_MAYBE_DELETED_newBiblioItem {
1541 my ($env, $biblioitem) = @_;
1543 my $biblionumber=$biblioitem->{'biblionumber'};
1544 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
1545 my $volume=$biblioitem->{'volume'};
1546 my $q_volume=$dbh->quote($volume);
1547 my $number=$biblioitem->{'number'};
1548 my $q_number=$dbh->quote($number);
1549 my $classification=$biblioitem->{'classification'};
1550 my $q_classification=$dbh->quote($classification);
1551 my $itemtype=$biblioitem->{'itemtype'};
1552 my $q_itemtype=$dbh->quote($itemtype);
1553 my $isbn=$biblioitem->{'isbn'};
1554 my $q_isbn=$dbh->quote($isbn);
1555 my $issn=$biblioitem->{'issn'};
1556 my $q_issn=$dbh->quote($issn);
1557 my $dewey=$biblioitem->{'dewey'};
1559 ($dewey == 0) && ($dewey='');
1560 my $subclass=$biblioitem->{'subclass'};
1561 my $q_subclass=$dbh->quote($subclass);
1562 my $publicationyear=$biblioitem->{'publicationyear'};
1563 my $publishercode=$biblioitem->{'publishercode'};
1564 my $q_publishercode=$dbh->quote($publishercode);
1565 my $volumedate=$biblioitem->{'volumedate'};
1566 my $q_volumedate=$dbh->quote($volumedate);
1567 my $illus=$biblioitem->{'illus'};
1568 my $q_illus=$dbh->quote($illus);
1569 my $pages=$biblioitem->{'pages'};
1570 my $q_pages=$dbh->quote($pages);
1571 my $notes=$biblioitem->{'notes'};
1572 my $q_notes=$dbh->quote($notes);
1573 my $size=$biblioitem->{'size'};
1574 my $q_size=$dbh->quote($size);
1575 my $place=$biblioitem->{'place'};
1576 my $q_place=$dbh->quote($place);
1577 my $lccn=$biblioitem->{'lccn'};
1578 my $q_lccn=$dbh->quote($lccn);
1581 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
1584 unless ($env->{'marconly'}) {
1585 #my $sth=$dbh->prepare("lock tables biblioitems write");
1587 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
1589 my ($biblioitemnumber) =$sth->fetchrow;
1590 $biblioitemnumber++;
1591 $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)");
1593 #my $sth=$dbh->prepare("unlock tables");
1598 # Should we check if there is already a biblioitem/amrc with the
1599 # same isbn/lccn/issn?
1601 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
1603 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
1604 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
1606 my ($subtitle) = $sth->fetchrow;
1607 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
1609 my @additionalauthors;
1610 while (my ($additionalauthor) = $sth->fetchrow) {
1611 push (@additionalauthors, $additionalauthor);
1613 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
1616 while (my ($subject) = $sth->fetchrow) {
1617 push (@subjects, $subject);
1622 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
1624 my $Resource_ID=$dbh->{'mysql_insertid'};
1625 my $Record_ID=$Resource_ID;
1626 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
1632 $subfields->{1}->{'Subfield_Mark'}='a';
1633 $subfields->{1}->{'Subfield_Value'}=$title;
1635 $subfields->{2}->{'Subfield_Mark'}='b';
1636 $subfields->{2}->{'Subfield_Value'}=$subtitle;
1639 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1645 $subfields->{1}->{'Subfield_Mark'}='a';
1646 $subfields->{1}->{'Subfield_Value'}=$author;
1648 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1653 $subfields->{1}->{'Subfield_Mark'}='a';
1654 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
1656 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1661 $subfields->{1}->{'Subfield_Mark'}='a';
1662 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
1663 $subfields->{2}->{'Subfield_Mark'}='3';
1664 $subfields->{2}->{'Subfield_Value'}='biblio';
1666 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1668 # Additional Authors
1669 foreach (@additionalauthors) {
1671 (next) unless ($author);
1673 $subfields->{1}->{'Subfield_Mark'}='a';
1674 $subfields->{1}->{'Subfield_Value'}=$author;
1675 $subfields->{2}->{'Subfield_Mark'}='e';
1676 $subfields->{2}->{'Subfield_Value'}='author';
1678 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1682 (next) unless ($illus);
1684 $subfields->{1}->{'Subfield_Mark'}='a';
1685 $subfields->{1}->{'Subfield_Value'}=$illus;
1686 $subfields->{2}->{'Subfield_Mark'}='e';
1687 $subfields->{2}->{'Subfield_Value'}='illustrator';
1689 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1692 foreach (@subjects) {
1694 (next) unless ($subject);
1696 $subfields->{1}->{'Subfield_Mark'}='a';
1697 $subfields->{1}->{'Subfield_Value'}=$subject;
1699 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1706 $subfields->{1}->{'Subfield_Mark'}='a';
1707 $subfields->{1}->{'Subfield_Value'}=$isbn;
1709 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1714 $subfields->{1}->{'Subfield_Mark'}='a';
1715 $subfields->{1}->{'Subfield_Value'}=$lccn;
1717 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1722 $subfields->{1}->{'Subfield_Mark'}='a';
1723 $subfields->{1}->{'Subfield_Value'}=$issn;
1725 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1730 $subfields->{1}->{'Subfield_Mark'}='a';
1731 $subfields->{1}->{'Subfield_Value'}=$dewey;
1733 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1735 # DEWEY subclass and itemtype
1738 $subfields->{1}->{'Subfield_Mark'}='a';
1739 $subfields->{1}->{'Subfield_Value'}=$itemtype;
1740 $subfields->{2}->{'Subfield_Mark'}='b';
1741 $subfields->{2}->{'Subfield_Value'}=$subclass;
1742 $subfields->{3}->{'Subfield_Mark'}='c';
1743 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
1744 $subfields->{4}->{'Subfield_Mark'}='d';
1745 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
1747 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1752 $subfields->{1}->{'Subfield_Mark'}='a';
1753 $subfields->{1}->{'Subfield_Value'}=$place;
1754 $subfields->{2}->{'Subfield_Mark'}='b';
1755 $subfields->{2}->{'Subfield_Value'}=$publishercode;
1756 $subfields->{3}->{'Subfield_Mark'}='c';
1757 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
1758 if ($copyrightdate) {
1759 $subfields->{4}->{'Subfield_Mark'}='c';
1760 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
1763 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1766 if ($pages || $size) {
1768 $subfields->{1}->{'Subfield_Mark'}='a';
1769 $subfields->{1}->{'Subfield_Value'}=$pages;
1770 $subfields->{2}->{'Subfield_Mark'}='c';
1771 $subfields->{2}->{'Subfield_Value'}=$size;
1773 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1776 if ($volume || $number) {
1778 $subfields->{1}->{'Subfield_Mark'}='v';
1779 $subfields->{1}->{'Subfield_Value'}=$volume;
1780 $subfields->{2}->{'Subfield_Mark'}='n';
1781 $subfields->{2}->{'Subfield_Value'}=$number;
1783 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1788 $subfields->{1}->{'Subfield_Mark'}='a';
1789 $subfields->{1}->{'Subfield_Value'}=$notes;
1790 $subfields->{2}->{'Subfield_Mark'}='3';
1791 $subfields->{2}->{'Subfield_Value'}='biblioitem';
1793 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1797 return ($env, $Record_ID);
1800 sub OLD_MAYBE_DELETED_newItem {
1801 my ($env, $Record_ID, $item) = @_;
1803 my $barcode=$item->{'barcode'};
1804 my $q_barcode=$dbh->quote($barcode);
1805 my $biblionumber=$item->{'biblionumber'};
1806 my $biblioitemnumber=$item->{'biblioitemnumber'};
1807 my $dateaccessioned=$item->{'dateaccessioned'};
1808 my $booksellerid=$item->{'booksellerid'};
1809 my $q_booksellerid=$dbh->quote($booksellerid);
1810 my $homebranch=$item->{'homebranch'};
1811 my $q_homebranch=$dbh->quote($homebranch);
1812 my $holdingbranch=$item->{'holdingbranch'};
1813 my $price=$item->{'price'};
1814 my $replacementprice=$item->{'replacementprice'};
1815 my $replacementpricedate=$item->{'replacementpricedate'};
1816 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
1817 my $notforloan=$item->{'notforloan'};
1818 my $itemlost=$item->{'itemlost'};
1819 my $wthdrawn=$item->{'wthdrawn'};
1820 my $restricted=$item->{'restricted'};
1821 my $itemnotes=$item->{'itemnotes'};
1822 my $q_itemnotes=$dbh->quote($itemnotes);
1823 my $itemtype=$item->{'itemtype'};
1824 my $subclass=$item->{'subclass'};
1828 unless ($env->{'marconly'}) {
1829 my $sth=$dbh->prepare("select max(itemnumber) from items");
1831 my ($itemnumber) =$sth->fetchrow;
1833 $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)");
1840 $subfields->{1}->{'Subfield_Mark'}='p';
1841 $subfields->{1}->{'Subfield_Value'}=$barcode;
1842 $subfields->{2}->{'Subfield_Mark'}='d';
1843 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
1844 $subfields->{3}->{'Subfield_Mark'}='e';
1845 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
1846 $subfields->{4}->{'Subfield_Mark'}='b';
1847 $subfields->{4}->{'Subfield_Value'}=$homebranch;
1848 $subfields->{5}->{'Subfield_Mark'}='l';
1849 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
1850 $subfields->{6}->{'Subfield_Mark'}='c';
1851 $subfields->{6}->{'Subfield_Value'}=$price;
1852 $subfields->{7}->{'Subfield_Mark'}='c';
1853 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
1854 $subfields->{8}->{'Subfield_Mark'}='d';
1855 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
1857 $subfields->{9}->{'Subfield_Mark'}='h';
1858 $subfields->{9}->{'Subfield_Value'}='Not for loan';
1861 $subfields->{10}->{'Subfield_Mark'}='j';
1862 $subfields->{10}->{'Subfield_Value'}='Item lost';
1865 $subfields->{11}->{'Subfield_Mark'}='j';
1866 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
1869 $subfields->{12}->{'Subfield_Mark'}='z';
1870 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
1874 $env->{'linkage'}=1;
1875 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1876 $env->{'linkage'}=0;
1877 $env->{'linkid'}=$Tag_ID;
1880 $subfields2->{1}->{'Subfield_Mark'}='a';
1881 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
1882 $subfields2->{1}->{'Subfield_Mark'}='b';
1883 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
1884 $subfields2->{1}->{'Subfield_Mark'}='c';
1885 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
1886 $subfields2->{2}->{'Subfield_Mark'}='m';
1887 $subfields2->{2}->{'Subfield_Value'}=$subclass;
1888 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
1889 $env->{'linkid'}='';
1892 sub OLD_MAYBE_DELETED_updateBiblio {
1893 # Update the biblio with biblionumber $biblio->{'biblionumber'}
1894 # I guess this routine should search through all marc records for a record that
1895 # has the same biblionumber stored in it, and modify the MARC record as well as
1898 # Also, this subroutine should search through the $biblio object and compare it
1899 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
1900 # this logging feature to be usable to undo changes easily.
1902 my ($env, $biblio) = @_;
1904 my $biblionumber=$biblio->{'biblionumber'};
1906 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
1908 my $origbiblio=$sth->fetchrow_hashref;
1909 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
1911 my ($subtitle)=$sth->fetchrow;
1912 $origbiblio->{'subtitle'}=$subtitle;
1913 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
1915 my $origadditionalauthors;
1916 while (my ($author) = $sth->fetchrow) {
1917 push (@{$origbiblio->{'additionalauthors'}}, $author);
1918 $origadditionalauthors->{$author}=1;
1920 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
1923 while (my ($subject) = $sth->fetchrow) {
1924 push (@{$origbiblio->{'subjects'}}, $subject);
1925 $origsubjects->{$subject}=1;
1929 # Obtain a list of MARC Record_ID's that are tied to this biblio
1930 $sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
1933 while (my ($bibid) = $sth->fetchrow) {
1934 push(@marcrecords, $bibid);
1938 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
1939 my $q_author=$dbh->quote($biblio->{'author'});
1940 logchange('kohadb', 'change', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
1941 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
1943 foreach $bibid (@marcrecords) {
1944 logchange('marc', 'change', $bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
1945 changeSubfield($bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
1948 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
1949 my $q_title=$dbh->quote($biblio->{'title'});
1950 logchange('kohadb', 'change', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
1951 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
1953 foreach $Record_ID (@marcrecords) {
1954 logchange('marc', 'change', $Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
1955 changeSubfield($Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
1958 if ($biblio->{'subtitle'} ne $origbiblio->{'subtitle'}) {
1959 my $q_subtitle=$dbh->quote($biblio->{'subtitle'});
1960 logchange('kohadb', 'change', 'biblio', 'subtitle', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
1961 my $sti=$dbh->prepare("update bibliosubtitle set subtitle=$q_subtitle where biblionumber=$biblio->{'biblionumber'}");
1963 foreach $Record_ID (@marcrecords) {
1964 logchange('marc', 'change', $Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
1965 changeSubfield($Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
1968 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
1969 my $q_unititle=$dbh->quote($biblio->{'unititle'});
1970 logchange('kohadb', 'change', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
1971 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
1974 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
1975 my $q_notes=$dbh->quote($biblio->{'notes'});
1976 logchange('kohadb', 'change', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
1977 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
1979 foreach $Record_ID (@marcrecords) {
1980 logchange('marc', 'change', $Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
1981 changeSubfield($Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
1984 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
1985 my $q_serial=$dbh->quote($biblio->{'serial'});
1986 logchange('kohadb', 'change', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
1987 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
1990 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
1991 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
1992 logchange('kohadb', 'change', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
1993 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
1995 foreach $Record_ID (@marcrecords) {
1996 logchange('marc', 'change', $Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
1997 changeSubfield($Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2000 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
2001 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
2002 logchange('kohadb', 'change', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
2003 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
2005 foreach $Record_ID (@marcrecords) {
2006 logchange('marc', 'change', $Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2007 changeSubfield($Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2011 # Check for subject heading changes
2015 foreach $newsubject (@{$biblio->{'subject'}}) {
2016 $subjects->{$newsubject}=1;
2017 if ($origsubjects->{$newsubject}) {
2018 $subjects->{$newsubject}=2;
2020 my $q_newsubject=$dbh->quote($newsubject);
2021 my $sth=$dbh->prepare("insert into bibliosubject (subject,biblionumber) values ($q_newsubject, $biblionumber)");
2023 logchange('kohadb', 'add', 'biblio', 'subject', $newsubject);
2025 $subfields->{1}->{'Subfield_Mark'}='a';
2026 $subfields->{1}->{'Subfield_Value'}=$newsubject;
2029 foreach $Record_ID (@marcrecords) {
2030 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2031 logchange('marc', 'add', $Record_ID, '650', 'a', $newsubject);
2036 foreach $origsubject (keys %$origsubjects) {
2037 if ($subjects->{$origsubject} == 1) {
2038 my $q_origsubject=$dbh->quote($origsubject);
2039 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'subject', $origsubject);
2040 my $sth=$dbh->prepare("delete from bibliosubject where biblionumber=$biblionumber and subject=$q_origsubject");
2046 sub OLD_MAYBE_DELETED_updateBiblioItem {
2047 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
2049 # This routine should also check to see which fields are actually being
2050 # modified, and log all changes.
2052 my ($env, $biblioitem) = @_;
2055 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2056 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
2057 # obi = original biblioitem
2058 my $obi=$sth->fetchrow_hashref;
2059 $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");
2061 my ($Record_ID) = $sth->fetchrow;
2062 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
2063 logchange('kohadb', 'change', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2064 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
2065 logchange('marc', 'change', $Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2066 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2068 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
2069 logchange('kohadb', 'change', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
2070 my $q_volume=$dbh->quote($biblioitem->{'volume'});
2071 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
2072 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2073 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2075 if ($biblioitem->{'number'} ne $obi->{'number'}) {
2076 logchange('kohadb', 'change', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
2077 my $q_number=$dbh->quote($biblioitem->{'number'});
2078 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
2079 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2080 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2082 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
2083 logchange('kohadb', 'change', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2084 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
2085 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
2086 logchange('marc', 'change', $Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2087 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2089 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
2090 logchange('kohadb', 'change', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
2091 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
2092 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
2093 logchange('marc', 'change', $Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2094 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2096 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
2097 logchange('kohadb', 'change', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
2098 my $q_issn=$dbh->quote($biblioitem->{'issn'});
2099 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
2100 logchange('marc', 'change', $Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2101 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2103 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
2104 logchange('kohadb', 'change', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
2105 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
2106 logchange('marc', 'change', $Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2107 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2109 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
2110 logchange('kohadb', 'change', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
2111 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
2112 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
2113 logchange('marc', 'change', $Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2114 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2116 if ($biblioitem->{'place'} ne $obi->{'place'}) {
2117 logchange('kohadb', 'change', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
2118 my $q_place=$dbh->quote($biblioitem->{'place'});
2119 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
2120 logchange('marc', 'change', $Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2121 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2123 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
2124 logchange('kohadb', 'change', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2125 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
2126 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
2127 logchange('marc', 'change', $Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2128 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2130 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
2131 logchange('kohadb', 'change', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2132 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
2133 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
2134 logchange('marc', 'change', $Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2135 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2137 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
2138 logchange('kohadb', 'change', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
2139 my $q_illus=$dbh->quote($biblioitem->{'illus'});
2140 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
2141 logchange('marc', 'change', $Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2142 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2144 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
2145 logchange('kohadb', 'change', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
2146 my $q_pages=$dbh->quote($biblioitem->{'pages'});
2147 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
2148 logchange('marc', 'change', $Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2149 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2151 if ($biblioitem->{'size'} ne $obi->{'size'}) {
2152 logchange('kohadb', 'change', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
2153 my $q_size=$dbh->quote($biblioitem->{'size'});
2154 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
2155 logchange('marc', 'change', $Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2156 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2158 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
2159 logchange('kohadb', 'change', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
2160 my $q_notes=$dbh->quote($biblioitem->{'notes'});
2161 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
2162 logchange('marc', 'change', $Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2163 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2165 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
2166 logchange('kohadb', 'change', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
2167 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
2168 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
2169 logchange('marc', 'change', $Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2170 changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2177 sub OLD_MAYBE_DELETED_updateItem {
2178 # Update the item with itemnumber $item->{'itemnumber'}
2179 # This routine should also modify the corresponding MARC record data. (852 and
2180 # 876 tags with 876p tag the same as $item->{'barcode'}
2182 # This routine should also check to see which fields are actually being
2183 # modified, and log all changes.
2185 my ($env, $item) = @_;
2187 my $itemnumber=$item->{'itemnumber'};
2188 my $biblionumber=$item->{'biblionumber'};
2189 my $biblioitemnumber=$item->{'biblioitemnumber'};
2190 my $barcode=$item->{'barcode'};
2191 my $dateaccessioned=$item->{'dateaccessioned'};
2192 my $booksellerid=$item->{'booksellerid'};
2193 my $homebranch=$item->{'homebranch'};
2194 my $price=$item->{'price'};
2195 my $replacementprice=$item->{'replacementprice'};
2196 my $replacementpricedate=$item->{'replacementpricedate'};
2197 my $multivolume=$item->{'multivolume'};
2198 my $stack=$item->{'stack'};
2199 my $notforloan=$item->{'notforloan'};
2200 my $itemlost=$item->{'itemlost'};
2201 my $wthdrawn=$item->{'wthdrawn'};
2202 my $bulk=$item->{'bulk'};
2203 my $restricted=$item->{'restricted'};
2204 my $binding=$item->{'binding'};
2205 my $itemnotes=$item->{'itemnotes'};
2206 my $holdingbranch=$item->{'holdingbranch'};
2207 my $interim=$item->{'interim'};
2208 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
2210 my $olditem=$sth->fetchrow_hashref;
2211 my $q_barcode=$dbh->quote($olditem->{'barcode'});
2212 $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");
2214 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
2215 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
2217 my ($link) = $sth->fetchrow;
2218 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
2220 my ($Subfield852_ID) = $sth->fetchrow;
2222 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
2223 logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
2224 my $q_barcode=$dbh->quote($item->{'barcode'});
2225 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
2227 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
2228 logchange('marc', 'change', $Record_ID, '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
2230 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
2231 logchange('kohadb', 'change', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
2232 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
2233 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
2235 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
2236 logchange('marc', 'change', $Record_ID, '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
2238 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
2239 logchange('kohadb', 'change', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2240 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
2241 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
2243 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
2244 logchange('marc', 'change', $Record_ID, '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2246 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
2247 logchange('kohadb', 'change', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
2248 my $q_homebranch=$dbh->quote($item->{'homebranch'});
2249 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
2251 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
2252 logchange('marc', 'change', $Record_ID, '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
2254 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
2255 logchange('kohadb', 'change', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2256 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
2257 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
2259 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
2260 logchange('marc', 'change', $Record_ID, '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2262 if ($item->{'price'} ne $olditem->{'price'}) {
2263 logchange('kohadb', 'change', 'items', 'price', $olditem->{'price'}, $item->{'price'});
2264 my $q_price=$dbh->quote($item->{'price'});
2265 my $sth=$dbh->prepare("update items set price=$q_price where itemnumber=$itemnumber");
2267 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'price'}, $item->{'price'}, $Subfield876_ID);
2268 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'price'}, $item->{'price'});
2270 if ($item->{'itemnotes'} ne $olditem->{'itemnotes'}) {
2271 logchange('kohadb', 'change', 'items', 'itemnotes', $olditem->{'itemnotes'}, $item->{'itemnotes'});
2272 my $q_itemnotes=$dbh->quote($item->{'itemnotes'});
2273 my $sth=$dbh->prepare("update items set itemnotes=$q_itemnotes where itemnumber=$itemnumber");
2275 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'itemnotes'}, $item->{'itemnotes'}, $Subfield876_ID);
2276 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'itemnotes'}, $item->{'itemnotes'});
2278 if ($item->{'notforloan'} ne $olditem->{'notforloan'}) {
2279 logchange('kohadb', 'change', 'items', 'notforloan', $olditem->{'notforloan'}, $item->{'notforloan'});
2280 my $sth=$dbh->prepare("update items set notforloan=$notforloan where itemnumber=$itemnumber");
2282 if ($item->{'notforloan'}) {
2283 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2284 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2286 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2287 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2290 if ($item->{'itemlost'} ne $olditem->{'itemlost'}) {
2291 logchange('kohadb', 'change', 'items', 'itemlost', $olditem->{'itemlost'}, $item->{'itemlost'});
2292 my $sth=$dbh->prepare("update items set itemlost=$itemlost where itemnumber=$itemnumber");
2294 if ($item->{'itemlost'}) {
2295 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2296 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2298 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2299 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2302 if ($item->{'wthdrawn'} ne $olditem->{'wthdrawn'}) {
2303 logchange('kohadb', 'change', 'items', 'wthdrawn', $olditem->{'wthdrawn'}, $item->{'wthdrawn'});
2304 my $sth=$dbh->prepare("update items set wthdrawn=$wthdrawn where itemnumber=$itemnumber");
2306 if ($item->{'wthdrawn'}) {
2307 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2308 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2310 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2311 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2314 if ($item->{'restricted'} ne $olditem->{'restricted'}) {
2315 logchange('kohadb', 'change', 'items', 'restricted', $olditem->{'restricted'}, $item->{'restricted'});
2316 my $sth=$dbh->prepare("update items set restricted=$restricted where itemnumber=$itemnumber");
2318 if ($item->{'restricted'}) {
2319 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2320 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2322 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2323 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2332 # END OF UNUSEFUL SUBs
2336 END { } # module clean-up code here (global destructor)