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 &newordernum &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 my $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,$subfieldid,$subfieldorder) = $sth->fetchrow;
367 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
368 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
369 return($subfieldid, $subfieldvalue);
375 $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
379 MARCfindsubfield returns a subfield number given a bibid/tag/subfield values.
380 Returns -1 if more than 1 answer
384 Paul POULAIN paul.poulain@free.fr
388 sub MARCfindsubfield {
389 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
393 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
394 if ($subfieldvalue) {
395 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
397 if ($subfieldorder<1) {
400 $query .= " and subfieldorder=$subfieldorder";
402 my $sti=$dbh->prepare($query);
403 $sti->execute($bibid,$tag, $subfieldcode);
404 while (($subfieldid) = $sti->fetchrow) {
406 $lastsubfieldid=$subfieldid;
408 if ($resultcounter>1) {
409 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
410 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
413 return $lastsubfieldid;
420 $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
424 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
428 Paul POULAIN paul.poulain@free.fr
432 sub MARCfindsubfieldid {
433 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
434 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
435 where bibid=? and tag=? and tagorder=?
436 and subfieldcode=? and subfieldorder=?");
437 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
438 my ($res) = $sth->fetchrow;
445 &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
449 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
453 Paul POULAIN paul.poulain@free.fr
457 sub MARCdelsubfield {
458 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
459 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
460 # my $dbh=&C4Connect;
461 my $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
462 tag='$tag' and tagorder='$tagorder'
463 and subfieldcode='$subfield'and subfieldorder='$subfieldorder
470 &MARCdelbiblio($dbh,$bibid);
474 MARCdelbiblio delete biblio $bibid
478 Paul POULAIN paul.poulain@free.fr
483 # delete a biblio for a $bibid
484 my ($dbh,$bibid) = @_;
485 # my $dbh=&C4Connect;
486 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
487 $dbh->do("delete from marc_biblio where bibid='$bibid'");
493 $MARCRecord = &MARCkoha2marc($dbh,$biblionumber,biblioitemnumber,itemnumber);
497 MARCkoha2marc is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem/item
501 Paul POULAIN paul.poulain@free.fr
506 # this function builds MARC::Record from the old koha-DB fields
507 my ($dbh,$biblionumber,$biblioitemnumber,$itemnumber) = @_;
508 # my $dbh=&C4Connect;
509 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
510 my $record = MARC::Record->new();
511 #--- if bibid, then retrieve old-style koha data
512 if ($biblionumber>0) {
513 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
514 from biblio where biblionumber=?");
515 $sth2->execute($biblionumber);
516 my $row=$sth2->fetchrow_hashref;
518 foreach $code (keys %$row) {
520 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
524 #--- if biblioitem, then retrieve old-style koha data
525 if ($biblioitemnumber>0) {
526 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
527 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
528 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
530 WHERE biblionumber=? and biblioitemnumber=?
532 $sth2->execute($biblionumber,$biblioitemnumber);
533 my $row=$sth2->fetchrow_hashref;
535 foreach $code (keys %$row) {
537 &MARCkoha2marcOnefield($sth,$record,"biblioitem.".$code,$row->{$code});
541 #--- if item, then retrieve old-style koha data
543 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
544 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
545 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
546 reserves,restricted,binding,itemnotes,holdingbranch,interim,timestamp
548 WHERE biblionumber=? and itemnumber=?");
549 $sth2->execute($biblionumber,$itemnumber);
550 my $row=$sth2->fetchrow_hashref;
552 foreach $code (keys %$row) {
554 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
559 # TODO : retrieve notes, additionalauthors
564 MARCkoha2marcOnefield is used by MARCkoha2marc and is not exported
568 Paul POULAIN paul.poulain@free.fr
571 sub MARCkoha2marcOnefield {
572 my ($sth,$record,$kohafieldname,$value)=@_;
575 $sth->execute($kohafieldname);
576 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
577 if ($record->field($tagfield)) {
578 my $tag =$record->field($tagfield);
580 $tag->add_subfields($tagsubfield,$value);
581 $record->delete_field($tag);
582 $record->add_fields($tag);
585 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
593 MARCaddword is used to manage MARC_word table and is not exported
597 Paul POULAIN paul.poulain@free.fr
602 # split a subfield string and adds it into the word table.
604 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
605 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
606 # TODO : remove stopwords
607 my @words = split / /,$sentence;
608 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
609 values (?,?,?,?,?,?,soundex(?))");
610 foreach my $word (@words) {
611 # we record only words longer than 2 car
612 if (length($word)>1) {
613 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
614 # print "($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word)\n";
621 MARCdelword is used to manage MARC_word table and is not exported
625 Paul POULAIN paul.poulain@free.fr
630 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
631 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
632 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
633 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
638 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
641 # all the following subs are the exact copy of 1.0/1.2 version of the sub
642 # without the OLD. The OLDxxx is called by the original xxx sub.
643 # the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
644 # WARNING : there is 1 difference between initialxxx and OLDxxx :
645 # the db header $dbh is always passed as parameter
646 # to avoid over-DB connexion
649 my ($dbh,$biblio) = @_;
650 # my $dbh = &C4Connect;
651 my $query = "Select max(biblionumber) from biblio";
652 my $sth = $dbh->prepare($query);
654 my $data = $sth->fetchrow_arrayref;
655 my $bibnum = $$data[0] + 1;
658 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
659 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
660 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
661 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
662 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
663 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
664 if ($biblio->{'seriestitle'}) { $series = 1 };
667 $query = "insert into biblio set
668 biblionumber = $bibnum,
669 title = $biblio->{'title'},
670 author = $biblio->{'author'},
671 copyrightdate = $biblio->{'copyright'},
673 seriestitle = $biblio->{'seriestitle'},
674 notes = $biblio->{'notes'},
675 abstract = $biblio->{'abstract'}";
677 $sth = $dbh->prepare($query);
686 my ($dbh,$biblio) = @_;
687 # my $dbh = C4Connect;
691 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
692 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
693 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
694 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
695 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
696 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
697 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
698 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
700 $query = "Update biblio set
701 title = $biblio->{'title'},
702 author = $biblio->{'author'},
703 abstract = $biblio->{'abstract'},
704 copyrightdate = $biblio->{'copyrightdate'},
705 seriestitle = $biblio->{'seriestitle'},
706 serial = $biblio->{'serial'},
707 unititle = $biblio->{'unititle'},
708 notes = $biblio->{'notes'}
709 where biblionumber = $biblio->{'biblionumber'}";
710 $sth = $dbh->prepare($query);
716 return($biblio->{'biblionumber'});
720 my ($dbh,$bibnum, $subtitle) = @_;
721 # my $dbh = C4Connect;
722 my $query = "update bibliosubtitle set
723 subtitle = '$subtitle'
724 where biblionumber = $bibnum";
725 my $sth = $dbh->prepare($query);
733 sub OLDmodaddauthor {
734 my ($dbh,$bibnum, $author) = @_;
735 # my $dbh = C4Connect;
736 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
737 my $sth = $dbh->prepare($query);
743 $query = "Insert into additionalauthors set
745 biblionumber = '$bibnum'";
746 $sth = $dbh->prepare($query);
758 my ($dbh,$bibnum, $force, @subject) = @_;
759 # my $dbh = C4Connect;
760 my $count = @subject;
762 for (my $i = 0; $i < $count; $i++) {
763 $subject[$i] =~ s/^ //g;
764 $subject[$i] =~ s/ $//g;
765 my $query = "select * from catalogueentry
766 where entrytype = 's'
767 and catalogueentry = '$subject[$i]'";
768 my $sth = $dbh->prepare($query);
771 if (my $data = $sth->fetchrow_hashref) {
773 if ($force eq $subject[$i]) {
774 # subject not in aut, chosen to force anway
775 # so insert into cataloguentry so its in auth file
776 $query = "Insert into catalogueentry
777 (entrytype,catalogueentry)
778 values ('s','$subject[$i]')";
779 my $sth2 = $dbh->prepare($query);
784 $error = "$subject[$i]\n does not exist in the subject authority file";
785 $query = "Select * from catalogueentry
786 where entrytype = 's'
787 and (catalogueentry like '$subject[$i] %'
788 or catalogueentry like '% $subject[$i] %'
789 or catalogueentry like '% $subject[$i]')";
790 my $sth2 = $dbh->prepare($query);
793 while (my $data = $sth2->fetchrow_hashref) {
794 $error = $error."<br>$data->{'catalogueentry'}";
802 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
803 my $sth = $dbh->prepare($query);
806 for (my $i = 0; $i < $count; $i++) {
807 $sth = $dbh->prepare("Insert into bibliosubject
808 values ('$subject[$i]', $bibnum)");
820 my ($dbh,$biblioitem) = @_;
821 # my $dbh = C4Connect;
824 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
825 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
826 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
827 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
828 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
829 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
830 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
831 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
832 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
833 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
834 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
835 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
836 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
837 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
839 $query = "Update biblioitems set
840 itemtype = $biblioitem->{'itemtype'},
841 url = $biblioitem->{'url'},
842 isbn = $biblioitem->{'isbn'},
843 publishercode = $biblioitem->{'publishercode'},
844 publicationyear = $biblioitem->{'publicationyear'},
845 classification = $biblioitem->{'classification'},
846 dewey = $biblioitem->{'dewey'},
847 subclass = $biblioitem->{'subclass'},
848 illus = $biblioitem->{'illus'},
849 pages = $biblioitem->{'pages'},
850 volumeddesc = $biblioitem->{'volumeddesc'},
851 notes = $biblioitem->{'notes'},
852 size = $biblioitem->{'size'},
853 place = $biblioitem->{'place'}
854 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
862 my ($dbh,$bibitemnum,$note)=@_;
864 my $query="update biblioitems set notes='$note' where
865 biblioitemnumber='$bibitemnum'";
866 my $sth=$dbh->prepare($query);
872 sub OLDnewbiblioitem {
873 my ($dbh,$biblioitem) = @_;
874 # my $dbh = C4Connect;
875 my $query = "Select max(biblioitemnumber) from biblioitems";
876 my $sth = $dbh->prepare($query);
880 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
881 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
882 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
883 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
884 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
885 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
886 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
887 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
888 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
889 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
890 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
891 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
892 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
893 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
894 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
895 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
896 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
897 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
898 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
899 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
902 $data = $sth->fetchrow_arrayref;
903 $bibitemnum = $$data[0] + 1;
907 $query = "insert into biblioitems set
908 biblioitemnumber = $bibitemnum,
909 biblionumber = $biblioitem->{'biblionumber'},
910 volume = $biblioitem->{'volume'},
911 number = $biblioitem->{'number'},
912 classification = $biblioitem->{'classification'},
913 itemtype = $biblioitem->{'itemtype'},
914 url = $biblioitem->{'url'},
915 isbn = $biblioitem->{'isbn'},
916 issn = $biblioitem->{'issn'},
917 dewey = $biblioitem->{'dewey'},
918 subclass = $biblioitem->{'subclass'},
919 publicationyear = $biblioitem->{'publicationyear'},
920 publishercode = $biblioitem->{'publishercode'},
921 volumedate = $biblioitem->{'volumedate'},
922 volumeddesc = $biblioitem->{'volumeddesc'},
923 illus = $biblioitem->{'illus'},
924 pages = $biblioitem->{'pages'},
925 notes = $biblioitem->{'notes'},
926 size = $biblioitem->{'size'},
927 lccn = $biblioitem->{'lccn'},
928 marc = $biblioitem->{'marc'},
929 place = $biblioitem->{'place'}";
931 $sth = $dbh->prepare($query);
940 my ($dbh,$bibnum)=@_;
942 my $query="insert into bibliosubject (biblionumber) values
944 my $sth=$dbh->prepare($query);
952 my ($dbh,$bibnum, $subtitle) = @_;
953 # my $dbh = C4Connect;
954 $subtitle = $dbh->quote($subtitle);
955 my $query = "insert into bibliosubtitle set
956 biblionumber = $bibnum,
957 subtitle = $subtitle";
958 my $sth = $dbh->prepare($query);
968 my ($dbh,$item, @barcodes) = @_;
969 # my $dbh = C4Connect;
970 my $query = "Select max(itemnumber) from items";
971 my $sth = $dbh->prepare($query);
977 $data = $sth->fetchrow_hashref;
978 $itemnumber = $data->{'max(itemnumber)'} + 1;
981 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
982 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
983 $item->{'price'} = $dbh->quote($item->{'price'});
984 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
985 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
987 foreach my $barcode (@barcodes) {
988 $barcode = uc($barcode);
989 $barcode = $dbh->quote($barcode);
990 $query = "Insert into items set
991 itemnumber = $itemnumber,
992 biblionumber = $item->{'biblionumber'},
993 biblioitemnumber = $item->{'biblioitemnumber'},
995 booksellerid = $item->{'booksellerid'},
996 dateaccessioned = NOW(),
997 homebranch = $item->{'homebranch'},
998 holdingbranch = $item->{'homebranch'},
999 price = $item->{'price'},
1000 replacementprice = $item->{'replacementprice'},
1001 replacementpricedate = NOW(),
1002 itemnotes = $item->{'itemnotes'}";
1003 if ($item->{'loan'}) {
1004 $query .= ",notforloan = $item->{'loan'}";
1007 $sth = $dbh->prepare($query);
1010 $error .= $sth->errstr;
1021 my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1022 # my $dbh=C4Connect;
1023 my $query="update items set biblioitemnumber=$bibitemnum,
1024 barcode='$barcode',itemnotes='$notes'
1025 where itemnumber=$itemnum";
1026 if ($barcode eq ''){
1027 $query="update items set biblioitemnumber=$bibitemnum,notforloan=$loan where itemnumber=$itemnum";
1030 $query="update items set biblioitemnumber=$bibitemnum,
1033 homebranch='$homebranch',
1035 wthdrawn='$wthdrawn'
1036 where itemnumber=$itemnum";
1038 if ($replacement ne ''){
1039 $query=~ s/ where/,replacementprice='$replacement' where/;
1042 my $sth=$dbh->prepare($query);
1049 my ($dbh,$itemnum)=@_;
1050 # my $dbh=C4Connect;
1051 my $query="select * from items where itemnumber=$itemnum";
1052 my $sth=$dbh->prepare($query);
1054 my @data=$sth->fetchrow_array;
1056 $query="Insert into deleteditems values (";
1057 foreach my $temp (@data){
1058 $query=$query."'$temp',";
1062 $sth=$dbh->prepare($query);
1065 $query = "Delete from items where itemnumber=$itemnum";
1066 $sth=$dbh->prepare($query);
1072 sub OLDdeletebiblioitem {
1073 my ($dbh,$biblioitemnumber) = @_;
1074 # my $dbh = C4Connect;
1075 my $query = "Select * from biblioitems
1076 where biblioitemnumber = $biblioitemnumber";
1077 my $sth = $dbh->prepare($query);
1082 if (@results = $sth->fetchrow_array) {
1083 $query = "Insert into deletedbiblioitems values (";
1084 foreach my $value (@results) {
1085 $value = $dbh->quote($value);
1086 $query .= "$value,";
1089 $query =~ s/\,$/\)/;
1092 $query = "Delete from biblioitems
1093 where biblioitemnumber = $biblioitemnumber";
1097 # Now delete all the items attached to the biblioitem
1098 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1099 $sth = $dbh->prepare($query);
1101 while (@results = $sth->fetchrow_array) {
1102 $query = "Insert into deleteditems values (";
1103 foreach my $value (@results) {
1104 $value = $dbh->quote($value);
1105 $query .= "$value,";
1107 $query =~ s/\,$/\)/;
1111 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1114 } # sub deletebiblioitem
1117 my ($dbh,$biblio)=@_;
1118 # my $dbh=C4Connect;
1119 my $query="select * from biblio where biblionumber=$biblio";
1120 my $sth=$dbh->prepare($query);
1122 if (my @data=$sth->fetchrow_array){
1124 $query="Insert into deletedbiblio values (";
1125 foreach my $temp (@data){
1126 $temp=~ s/\'/\\\'/g;
1127 $query=$query."'$temp',";
1131 $sth=$dbh->prepare($query);
1134 $query = "Delete from biblio where biblionumber=$biblio";
1135 $sth=$dbh->prepare($query);
1152 my $query="Select count(*) from items where biblionumber=$biblio";
1154 my $sth=$dbh->prepare($query);
1156 my $data=$sth->fetchrow_hashref;
1159 return($data->{'count(*)'});
1165 my $query="Select ordernumber
1167 where biblionumber=? and biblioitemnumber=?";
1168 my $sth=$dbh->prepare($query);
1169 $sth->execute($bib,$bi);
1170 my $ordnum=$sth->fetchrow_hashref;
1172 my $order=getsingleorder($ordnum->{'ordernumber'});
1175 return ($order,$ordnum->{'ordernumber'});
1178 sub getsingleorder {
1181 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1182 where aqorders.ordernumber=?
1183 and biblio.biblionumber=aqorders.biblionumber and
1184 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1185 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1186 my $sth=$dbh->prepare($query);
1187 $sth->execute($ordnum);
1188 my $data=$sth->fetchrow_hashref;
1196 my $dbh = &C4Connect;
1197 my $bibnum=OLDnewbiblio($dbh,$biblio);
1205 my $dbh = C4Connect;
1206 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1208 return($biblionumber);
1212 my ($bibnum, $subtitle) = @_;
1213 my $dbh = C4Connect;
1214 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1220 my ($bibnum, $author) = @_;
1221 my $dbh = C4Connect;
1222 &OLDmodaddauthor($dbh,$bibnum,$author);
1224 } # sub modaddauthor
1228 my ($bibnum, $force, @subject) = @_;
1229 my $dbh = C4Connect;
1230 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1235 my ($biblioitem) = @_;
1236 my $dbh = C4Connect;
1237 &OLDmodbibitem($dbh,$biblioitem);
1242 my ($bibitemnum,$note)=@_;
1244 &OLDmodnote($dbh,$bibitemnum,$note);
1249 my ($biblioitem) = @_;
1250 my $dbh = C4Connect;
1251 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1252 return($bibitemnum);
1258 &OLDnewsubject($dbh,$bibnum);
1263 my ($bibnum, $subtitle) = @_;
1264 my $dbh = C4Connect;
1265 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1271 my ($item, @barcodes) = @_;
1272 my $dbh = C4Connect;
1273 my $error=&OLDnewitems($dbh,$item,@barcodes);
1279 my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1281 &OLDmoditem($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement);
1286 my ($count,@barcodes)=@_;
1289 for (my $i=0;$i<$count;$i++){
1290 $barcodes[$i]=uc $barcodes[$i];
1291 my $query="Select * from items where barcode='$barcodes[$i]'";
1292 my $sth=$dbh->prepare($query);
1294 if (my $data=$sth->fetchrow_hashref){
1295 $error.=" Duplicate Barcode: $barcodes[$i]";
1304 my ($bibitemnum)=@_;
1306 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1307 my $sth=$dbh->prepare($query);
1309 my $data=$sth->fetchrow_hashref;
1312 return($data->{'count(*)'});
1318 &OLDdelitem($dbh,$itemnum);
1322 sub deletebiblioitem {
1323 my ($biblioitemnumber) = @_;
1324 my $dbh = C4Connect;
1325 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1327 } # sub deletebiblioitem
1333 &OLDdelbiblio($dbh,$biblio);
1338 my $dbh = C4Connect;
1339 my $query = "select * from itemtypes";
1340 my $sth = $dbh->prepare($query);
1341 # || die "Cannot prepare $query" . $dbh->errstr;
1346 # || die "Cannot execute $query\n" . $sth->errstr;
1347 while (my $data = $sth->fetchrow_hashref) {
1348 @results[$count] = $data;
1354 return($count, @results);
1355 } # sub getitemtypes
1358 my ($biblionumber) = @_;
1359 my $dbh = C4Connect;
1360 my $query = "Select * from biblio where biblionumber = $biblionumber";
1361 my $sth = $dbh->prepare($query);
1362 # || die "Cannot prepare $query\n" . $dbh->errstr;
1367 # || die "Cannot execute $query\n" . $sth->errstr;
1368 while (my $data = $sth->fetchrow_hashref) {
1369 $results[$count] = $data;
1375 return($count, @results);
1379 my ($biblioitemnum) = @_;
1380 my $dbh = C4Connect;
1381 my $query = "Select * from biblioitems where
1382 biblioitemnumber = $biblioitemnum";
1383 my $sth = $dbh->prepare($query);
1389 while (my $data = $sth->fetchrow_hashref) {
1390 $results[$count] = $data;
1396 return($count, @results);
1397 } # sub getbiblioitem
1399 sub getbiblioitembybiblionumber {
1400 my ($biblionumber) = @_;
1401 my $dbh = C4Connect;
1402 my $query = "Select * from biblioitems where biblionumber =
1404 my $sth = $dbh->prepare($query);
1410 while (my $data = $sth->fetchrow_hashref) {
1411 $results[$count] = $data;
1417 return($count, @results);
1420 sub getitemsbybiblioitem {
1421 my ($biblioitemnum) = @_;
1422 my $dbh = C4Connect;
1423 my $query = "Select * from items, biblio where
1424 biblio.biblionumber = items.biblionumber and biblioitemnumber
1426 my $sth = $dbh->prepare($query);
1427 # || die "Cannot prepare $query\n" . $dbh->errstr;
1432 # || die "Cannot execute $query\n" . $sth->errstr;
1433 while (my $data = $sth->fetchrow_hashref) {
1434 $results[$count] = $data;
1440 return($count, @results);
1441 } # sub getitemsbybiblioitem
1445 my $dbh = C4Connect;
1451 $isbn = $dbh->quote($isbn);
1452 $query = "Select biblio.* from biblio, biblioitems where
1453 biblio.biblionumber = biblioitems.biblionumber
1455 $sth = $dbh->prepare($query);
1458 while (my $data = $sth->fetchrow_hashref) {
1459 $results[$count] = $data;
1465 return($count, @results);
1469 # At the moment this is just a straight copy of the subject code. Needs heavy
1470 # modification to work for additional authors, obviously.
1471 # Check for additional author changes
1473 # my $newadditionalauthor='';
1474 # my $additionalauthors;
1475 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
1476 # $additionalauthors->{$newadditionalauthor}=1;
1477 # if ($origadditionalauthors->{$newadditionalauthor}) {
1478 # $additionalauthors->{$newadditionalauthor}=2;
1480 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
1481 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
1483 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
1485 # $subfields->{1}->{'Subfield_Mark'}='a';
1486 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
1489 # foreach $Record_ID (@marcrecords) {
1490 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1491 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
1495 # my $origadditionalauthor;
1496 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
1497 # if ($additionalauthors->{$origadditionalauthor} == 1) {
1498 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
1499 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
1500 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
1510 # Subroutine to log changes to databases
1511 # Eventually, this subroutine will be used to create a log of all changes made,
1512 # with the possibility of "undo"ing some changes
1514 if ($database eq 'kohadb') {
1520 print STDERR "KOHA: $type $section $item $original $new\n";
1521 } elsif ($database eq 'marc') {
1523 my $Record_ID=shift;
1526 my $subfield_ID=shift;
1529 print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
1535 # UNUSEFUL SUBs. Could be deleted, kept only until beta test
1536 # maybe useful for some MARC tricks steve used.
1539 sub OLD_MAYBE_DELETED_newBiblioItem {
1540 my ($env, $biblioitem) = @_;
1542 my $biblionumber=$biblioitem->{'biblionumber'};
1543 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
1544 my $volume=$biblioitem->{'volume'};
1545 my $q_volume=$dbh->quote($volume);
1546 my $number=$biblioitem->{'number'};
1547 my $q_number=$dbh->quote($number);
1548 my $classification=$biblioitem->{'classification'};
1549 my $q_classification=$dbh->quote($classification);
1550 my $itemtype=$biblioitem->{'itemtype'};
1551 my $q_itemtype=$dbh->quote($itemtype);
1552 my $isbn=$biblioitem->{'isbn'};
1553 my $q_isbn=$dbh->quote($isbn);
1554 my $issn=$biblioitem->{'issn'};
1555 my $q_issn=$dbh->quote($issn);
1556 my $dewey=$biblioitem->{'dewey'};
1558 ($dewey == 0) && ($dewey='');
1559 my $subclass=$biblioitem->{'subclass'};
1560 my $q_subclass=$dbh->quote($subclass);
1561 my $publicationyear=$biblioitem->{'publicationyear'};
1562 my $publishercode=$biblioitem->{'publishercode'};
1563 my $q_publishercode=$dbh->quote($publishercode);
1564 my $volumedate=$biblioitem->{'volumedate'};
1565 my $q_volumedate=$dbh->quote($volumedate);
1566 my $illus=$biblioitem->{'illus'};
1567 my $q_illus=$dbh->quote($illus);
1568 my $pages=$biblioitem->{'pages'};
1569 my $q_pages=$dbh->quote($pages);
1570 my $notes=$biblioitem->{'notes'};
1571 my $q_notes=$dbh->quote($notes);
1572 my $size=$biblioitem->{'size'};
1573 my $q_size=$dbh->quote($size);
1574 my $place=$biblioitem->{'place'};
1575 my $q_place=$dbh->quote($place);
1576 my $lccn=$biblioitem->{'lccn'};
1577 my $q_lccn=$dbh->quote($lccn);
1580 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
1583 unless ($env->{'marconly'}) {
1584 #my $sth=$dbh->prepare("lock tables biblioitems write");
1586 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
1588 my ($biblioitemnumber) =$sth->fetchrow;
1589 $biblioitemnumber++;
1590 $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)");
1592 #my $sth=$dbh->prepare("unlock tables");
1597 # Should we check if there is already a biblioitem/amrc with the
1598 # same isbn/lccn/issn?
1600 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
1602 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
1603 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
1605 my ($subtitle) = $sth->fetchrow;
1606 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
1608 my @additionalauthors;
1609 while (my ($additionalauthor) = $sth->fetchrow) {
1610 push (@additionalauthors, $additionalauthor);
1612 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
1615 while (my ($subject) = $sth->fetchrow) {
1616 push (@subjects, $subject);
1621 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
1623 my $Resource_ID=$dbh->{'mysql_insertid'};
1624 my $Record_ID=$Resource_ID;
1625 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
1631 $subfields->{1}->{'Subfield_Mark'}='a';
1632 $subfields->{1}->{'Subfield_Value'}=$title;
1634 $subfields->{2}->{'Subfield_Mark'}='b';
1635 $subfields->{2}->{'Subfield_Value'}=$subtitle;
1638 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1644 $subfields->{1}->{'Subfield_Mark'}='a';
1645 $subfields->{1}->{'Subfield_Value'}=$author;
1647 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1652 $subfields->{1}->{'Subfield_Mark'}='a';
1653 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
1655 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1660 $subfields->{1}->{'Subfield_Mark'}='a';
1661 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
1662 $subfields->{2}->{'Subfield_Mark'}='3';
1663 $subfields->{2}->{'Subfield_Value'}='biblio';
1665 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1667 # Additional Authors
1668 foreach (@additionalauthors) {
1670 (next) unless ($author);
1672 $subfields->{1}->{'Subfield_Mark'}='a';
1673 $subfields->{1}->{'Subfield_Value'}=$author;
1674 $subfields->{2}->{'Subfield_Mark'}='e';
1675 $subfields->{2}->{'Subfield_Value'}='author';
1677 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1681 (next) unless ($illus);
1683 $subfields->{1}->{'Subfield_Mark'}='a';
1684 $subfields->{1}->{'Subfield_Value'}=$illus;
1685 $subfields->{2}->{'Subfield_Mark'}='e';
1686 $subfields->{2}->{'Subfield_Value'}='illustrator';
1688 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1691 foreach (@subjects) {
1693 (next) unless ($subject);
1695 $subfields->{1}->{'Subfield_Mark'}='a';
1696 $subfields->{1}->{'Subfield_Value'}=$subject;
1698 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1705 $subfields->{1}->{'Subfield_Mark'}='a';
1706 $subfields->{1}->{'Subfield_Value'}=$isbn;
1708 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1713 $subfields->{1}->{'Subfield_Mark'}='a';
1714 $subfields->{1}->{'Subfield_Value'}=$lccn;
1716 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1721 $subfields->{1}->{'Subfield_Mark'}='a';
1722 $subfields->{1}->{'Subfield_Value'}=$issn;
1724 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1729 $subfields->{1}->{'Subfield_Mark'}='a';
1730 $subfields->{1}->{'Subfield_Value'}=$dewey;
1732 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1734 # DEWEY subclass and itemtype
1737 $subfields->{1}->{'Subfield_Mark'}='a';
1738 $subfields->{1}->{'Subfield_Value'}=$itemtype;
1739 $subfields->{2}->{'Subfield_Mark'}='b';
1740 $subfields->{2}->{'Subfield_Value'}=$subclass;
1741 $subfields->{3}->{'Subfield_Mark'}='c';
1742 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
1743 $subfields->{4}->{'Subfield_Mark'}='d';
1744 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
1746 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1751 $subfields->{1}->{'Subfield_Mark'}='a';
1752 $subfields->{1}->{'Subfield_Value'}=$place;
1753 $subfields->{2}->{'Subfield_Mark'}='b';
1754 $subfields->{2}->{'Subfield_Value'}=$publishercode;
1755 $subfields->{3}->{'Subfield_Mark'}='c';
1756 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
1757 if ($copyrightdate) {
1758 $subfields->{4}->{'Subfield_Mark'}='c';
1759 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
1762 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1765 if ($pages || $size) {
1767 $subfields->{1}->{'Subfield_Mark'}='a';
1768 $subfields->{1}->{'Subfield_Value'}=$pages;
1769 $subfields->{2}->{'Subfield_Mark'}='c';
1770 $subfields->{2}->{'Subfield_Value'}=$size;
1772 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1775 if ($volume || $number) {
1777 $subfields->{1}->{'Subfield_Mark'}='v';
1778 $subfields->{1}->{'Subfield_Value'}=$volume;
1779 $subfields->{2}->{'Subfield_Mark'}='n';
1780 $subfields->{2}->{'Subfield_Value'}=$number;
1782 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1787 $subfields->{1}->{'Subfield_Mark'}='a';
1788 $subfields->{1}->{'Subfield_Value'}=$notes;
1789 $subfields->{2}->{'Subfield_Mark'}='3';
1790 $subfields->{2}->{'Subfield_Value'}='biblioitem';
1792 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1796 return ($env, $Record_ID);
1799 sub OLD_MAYBE_DELETED_newItem {
1800 my ($env, $Record_ID, $item) = @_;
1802 my $barcode=$item->{'barcode'};
1803 my $q_barcode=$dbh->quote($barcode);
1804 my $biblionumber=$item->{'biblionumber'};
1805 my $biblioitemnumber=$item->{'biblioitemnumber'};
1806 my $dateaccessioned=$item->{'dateaccessioned'};
1807 my $booksellerid=$item->{'booksellerid'};
1808 my $q_booksellerid=$dbh->quote($booksellerid);
1809 my $homebranch=$item->{'homebranch'};
1810 my $q_homebranch=$dbh->quote($homebranch);
1811 my $holdingbranch=$item->{'holdingbranch'};
1812 my $price=$item->{'price'};
1813 my $replacementprice=$item->{'replacementprice'};
1814 my $replacementpricedate=$item->{'replacementpricedate'};
1815 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
1816 my $notforloan=$item->{'notforloan'};
1817 my $itemlost=$item->{'itemlost'};
1818 my $wthdrawn=$item->{'wthdrawn'};
1819 my $restricted=$item->{'restricted'};
1820 my $itemnotes=$item->{'itemnotes'};
1821 my $q_itemnotes=$dbh->quote($itemnotes);
1822 my $itemtype=$item->{'itemtype'};
1823 my $subclass=$item->{'subclass'};
1827 unless ($env->{'marconly'}) {
1828 my $sth=$dbh->prepare("select max(itemnumber) from items");
1830 my ($itemnumber) =$sth->fetchrow;
1832 $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)");
1839 $subfields->{1}->{'Subfield_Mark'}='p';
1840 $subfields->{1}->{'Subfield_Value'}=$barcode;
1841 $subfields->{2}->{'Subfield_Mark'}='d';
1842 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
1843 $subfields->{3}->{'Subfield_Mark'}='e';
1844 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
1845 $subfields->{4}->{'Subfield_Mark'}='b';
1846 $subfields->{4}->{'Subfield_Value'}=$homebranch;
1847 $subfields->{5}->{'Subfield_Mark'}='l';
1848 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
1849 $subfields->{6}->{'Subfield_Mark'}='c';
1850 $subfields->{6}->{'Subfield_Value'}=$price;
1851 $subfields->{7}->{'Subfield_Mark'}='c';
1852 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
1853 $subfields->{8}->{'Subfield_Mark'}='d';
1854 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
1856 $subfields->{9}->{'Subfield_Mark'}='h';
1857 $subfields->{9}->{'Subfield_Value'}='Not for loan';
1860 $subfields->{10}->{'Subfield_Mark'}='j';
1861 $subfields->{10}->{'Subfield_Value'}='Item lost';
1864 $subfields->{11}->{'Subfield_Mark'}='j';
1865 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
1868 $subfields->{12}->{'Subfield_Mark'}='z';
1869 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
1873 $env->{'linkage'}=1;
1874 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1875 $env->{'linkage'}=0;
1876 $env->{'linkid'}=$Tag_ID;
1879 $subfields2->{1}->{'Subfield_Mark'}='a';
1880 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
1881 $subfields2->{1}->{'Subfield_Mark'}='b';
1882 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
1883 $subfields2->{1}->{'Subfield_Mark'}='c';
1884 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
1885 $subfields2->{2}->{'Subfield_Mark'}='m';
1886 $subfields2->{2}->{'Subfield_Value'}=$subclass;
1887 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
1888 $env->{'linkid'}='';
1891 sub OLD_MAYBE_DELETED_updateBiblio {
1892 # Update the biblio with biblionumber $biblio->{'biblionumber'}
1893 # I guess this routine should search through all marc records for a record that
1894 # has the same biblionumber stored in it, and modify the MARC record as well as
1897 # Also, this subroutine should search through the $biblio object and compare it
1898 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
1899 # this logging feature to be usable to undo changes easily.
1901 my ($env, $biblio) = @_;
1903 my $biblionumber=$biblio->{'biblionumber'};
1905 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
1907 my $origbiblio=$sth->fetchrow_hashref;
1908 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
1910 my ($subtitle)=$sth->fetchrow;
1911 $origbiblio->{'subtitle'}=$subtitle;
1912 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
1914 my $origadditionalauthors;
1915 while (my ($author) = $sth->fetchrow) {
1916 push (@{$origbiblio->{'additionalauthors'}}, $author);
1917 $origadditionalauthors->{$author}=1;
1919 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
1922 while (my ($subject) = $sth->fetchrow) {
1923 push (@{$origbiblio->{'subjects'}}, $subject);
1924 $origsubjects->{$subject}=1;
1928 # Obtain a list of MARC Record_ID's that are tied to this biblio
1929 $sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
1932 while (my ($bibid) = $sth->fetchrow) {
1933 push(@marcrecords, $bibid);
1937 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
1938 my $q_author=$dbh->quote($biblio->{'author'});
1939 logchange('kohadb', 'change', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
1940 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
1942 foreach $bibid (@marcrecords) {
1943 logchange('marc', 'change', $bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
1944 changeSubfield($bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
1947 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
1948 my $q_title=$dbh->quote($biblio->{'title'});
1949 logchange('kohadb', 'change', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
1950 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
1952 foreach $Record_ID (@marcrecords) {
1953 logchange('marc', 'change', $Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
1954 changeSubfield($Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
1957 if ($biblio->{'subtitle'} ne $origbiblio->{'subtitle'}) {
1958 my $q_subtitle=$dbh->quote($biblio->{'subtitle'});
1959 logchange('kohadb', 'change', 'biblio', 'subtitle', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
1960 my $sti=$dbh->prepare("update bibliosubtitle set subtitle=$q_subtitle where biblionumber=$biblio->{'biblionumber'}");
1962 foreach $Record_ID (@marcrecords) {
1963 logchange('marc', 'change', $Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
1964 changeSubfield($Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
1967 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
1968 my $q_unititle=$dbh->quote($biblio->{'unititle'});
1969 logchange('kohadb', 'change', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
1970 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
1973 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
1974 my $q_notes=$dbh->quote($biblio->{'notes'});
1975 logchange('kohadb', 'change', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
1976 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
1978 foreach $Record_ID (@marcrecords) {
1979 logchange('marc', 'change', $Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
1980 changeSubfield($Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
1983 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
1984 my $q_serial=$dbh->quote($biblio->{'serial'});
1985 logchange('kohadb', 'change', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
1986 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
1989 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
1990 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
1991 logchange('kohadb', 'change', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
1992 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
1994 foreach $Record_ID (@marcrecords) {
1995 logchange('marc', 'change', $Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
1996 changeSubfield($Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
1999 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
2000 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
2001 logchange('kohadb', 'change', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
2002 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
2004 foreach $Record_ID (@marcrecords) {
2005 logchange('marc', 'change', $Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2006 changeSubfield($Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2010 # Check for subject heading changes
2014 foreach $newsubject (@{$biblio->{'subject'}}) {
2015 $subjects->{$newsubject}=1;
2016 if ($origsubjects->{$newsubject}) {
2017 $subjects->{$newsubject}=2;
2019 my $q_newsubject=$dbh->quote($newsubject);
2020 my $sth=$dbh->prepare("insert into bibliosubject (subject,biblionumber) values ($q_newsubject, $biblionumber)");
2022 logchange('kohadb', 'add', 'biblio', 'subject', $newsubject);
2024 $subfields->{1}->{'Subfield_Mark'}='a';
2025 $subfields->{1}->{'Subfield_Value'}=$newsubject;
2028 foreach $Record_ID (@marcrecords) {
2029 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2030 logchange('marc', 'add', $Record_ID, '650', 'a', $newsubject);
2035 foreach $origsubject (keys %$origsubjects) {
2036 if ($subjects->{$origsubject} == 1) {
2037 my $q_origsubject=$dbh->quote($origsubject);
2038 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'subject', $origsubject);
2039 my $sth=$dbh->prepare("delete from bibliosubject where biblionumber=$biblionumber and subject=$q_origsubject");
2045 sub OLD_MAYBE_DELETED_updateBiblioItem {
2046 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
2048 # This routine should also check to see which fields are actually being
2049 # modified, and log all changes.
2051 my ($env, $biblioitem) = @_;
2054 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2055 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
2056 # obi = original biblioitem
2057 my $obi=$sth->fetchrow_hashref;
2058 $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");
2060 my ($Record_ID) = $sth->fetchrow;
2061 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
2062 logchange('kohadb', 'change', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2063 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
2064 logchange('marc', 'change', $Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2065 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2067 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
2068 logchange('kohadb', 'change', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
2069 my $q_volume=$dbh->quote($biblioitem->{'volume'});
2070 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
2071 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2072 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2074 if ($biblioitem->{'number'} ne $obi->{'number'}) {
2075 logchange('kohadb', 'change', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
2076 my $q_number=$dbh->quote($biblioitem->{'number'});
2077 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
2078 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2079 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2081 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
2082 logchange('kohadb', 'change', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2083 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
2084 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
2085 logchange('marc', 'change', $Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2086 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2088 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
2089 logchange('kohadb', 'change', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
2090 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
2091 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
2092 logchange('marc', 'change', $Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2093 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2095 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
2096 logchange('kohadb', 'change', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
2097 my $q_issn=$dbh->quote($biblioitem->{'issn'});
2098 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
2099 logchange('marc', 'change', $Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2100 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2102 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
2103 logchange('kohadb', 'change', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
2104 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
2105 logchange('marc', 'change', $Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2106 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2108 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
2109 logchange('kohadb', 'change', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
2110 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
2111 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
2112 logchange('marc', 'change', $Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2113 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2115 if ($biblioitem->{'place'} ne $obi->{'place'}) {
2116 logchange('kohadb', 'change', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
2117 my $q_place=$dbh->quote($biblioitem->{'place'});
2118 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
2119 logchange('marc', 'change', $Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2120 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2122 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
2123 logchange('kohadb', 'change', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2124 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
2125 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
2126 logchange('marc', 'change', $Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2127 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2129 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
2130 logchange('kohadb', 'change', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2131 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
2132 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
2133 logchange('marc', 'change', $Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2134 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2136 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
2137 logchange('kohadb', 'change', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
2138 my $q_illus=$dbh->quote($biblioitem->{'illus'});
2139 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
2140 logchange('marc', 'change', $Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2141 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2143 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
2144 logchange('kohadb', 'change', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
2145 my $q_pages=$dbh->quote($biblioitem->{'pages'});
2146 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
2147 logchange('marc', 'change', $Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2148 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2150 if ($biblioitem->{'size'} ne $obi->{'size'}) {
2151 logchange('kohadb', 'change', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
2152 my $q_size=$dbh->quote($biblioitem->{'size'});
2153 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
2154 logchange('marc', 'change', $Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2155 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2157 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
2158 logchange('kohadb', 'change', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
2159 my $q_notes=$dbh->quote($biblioitem->{'notes'});
2160 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
2161 logchange('marc', 'change', $Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2162 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2164 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
2165 logchange('kohadb', 'change', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
2166 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
2167 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
2168 logchange('marc', 'change', $Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2169 changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2176 sub OLD_MAYBE_DELETED_updateItem {
2177 # Update the item with itemnumber $item->{'itemnumber'}
2178 # This routine should also modify the corresponding MARC record data. (852 and
2179 # 876 tags with 876p tag the same as $item->{'barcode'}
2181 # This routine should also check to see which fields are actually being
2182 # modified, and log all changes.
2184 my ($env, $item) = @_;
2186 my $itemnumber=$item->{'itemnumber'};
2187 my $biblionumber=$item->{'biblionumber'};
2188 my $biblioitemnumber=$item->{'biblioitemnumber'};
2189 my $barcode=$item->{'barcode'};
2190 my $dateaccessioned=$item->{'dateaccessioned'};
2191 my $booksellerid=$item->{'booksellerid'};
2192 my $homebranch=$item->{'homebranch'};
2193 my $price=$item->{'price'};
2194 my $replacementprice=$item->{'replacementprice'};
2195 my $replacementpricedate=$item->{'replacementpricedate'};
2196 my $multivolume=$item->{'multivolume'};
2197 my $stack=$item->{'stack'};
2198 my $notforloan=$item->{'notforloan'};
2199 my $itemlost=$item->{'itemlost'};
2200 my $wthdrawn=$item->{'wthdrawn'};
2201 my $bulk=$item->{'bulk'};
2202 my $restricted=$item->{'restricted'};
2203 my $binding=$item->{'binding'};
2204 my $itemnotes=$item->{'itemnotes'};
2205 my $holdingbranch=$item->{'holdingbranch'};
2206 my $interim=$item->{'interim'};
2207 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
2209 my $olditem=$sth->fetchrow_hashref;
2210 my $q_barcode=$dbh->quote($olditem->{'barcode'});
2211 $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");
2213 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
2214 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
2216 my ($link) = $sth->fetchrow;
2217 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
2219 my ($Subfield852_ID) = $sth->fetchrow;
2221 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
2222 logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
2223 my $q_barcode=$dbh->quote($item->{'barcode'});
2224 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
2226 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
2227 logchange('marc', 'change', $Record_ID, '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
2229 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
2230 logchange('kohadb', 'change', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
2231 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
2232 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
2234 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
2235 logchange('marc', 'change', $Record_ID, '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
2237 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
2238 logchange('kohadb', 'change', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2239 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
2240 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
2242 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
2243 logchange('marc', 'change', $Record_ID, '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2245 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
2246 logchange('kohadb', 'change', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
2247 my $q_homebranch=$dbh->quote($item->{'homebranch'});
2248 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
2250 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
2251 logchange('marc', 'change', $Record_ID, '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
2253 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
2254 logchange('kohadb', 'change', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2255 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
2256 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
2258 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
2259 logchange('marc', 'change', $Record_ID, '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2261 if ($item->{'price'} ne $olditem->{'price'}) {
2262 logchange('kohadb', 'change', 'items', 'price', $olditem->{'price'}, $item->{'price'});
2263 my $q_price=$dbh->quote($item->{'price'});
2264 my $sth=$dbh->prepare("update items set price=$q_price where itemnumber=$itemnumber");
2266 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'price'}, $item->{'price'}, $Subfield876_ID);
2267 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'price'}, $item->{'price'});
2269 if ($item->{'itemnotes'} ne $olditem->{'itemnotes'}) {
2270 logchange('kohadb', 'change', 'items', 'itemnotes', $olditem->{'itemnotes'}, $item->{'itemnotes'});
2271 my $q_itemnotes=$dbh->quote($item->{'itemnotes'});
2272 my $sth=$dbh->prepare("update items set itemnotes=$q_itemnotes where itemnumber=$itemnumber");
2274 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'itemnotes'}, $item->{'itemnotes'}, $Subfield876_ID);
2275 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'itemnotes'}, $item->{'itemnotes'});
2277 if ($item->{'notforloan'} ne $olditem->{'notforloan'}) {
2278 logchange('kohadb', 'change', 'items', 'notforloan', $olditem->{'notforloan'}, $item->{'notforloan'});
2279 my $sth=$dbh->prepare("update items set notforloan=$notforloan where itemnumber=$itemnumber");
2281 if ($item->{'notforloan'}) {
2282 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2283 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2285 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2286 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2289 if ($item->{'itemlost'} ne $olditem->{'itemlost'}) {
2290 logchange('kohadb', 'change', 'items', 'itemlost', $olditem->{'itemlost'}, $item->{'itemlost'});
2291 my $sth=$dbh->prepare("update items set itemlost=$itemlost where itemnumber=$itemnumber");
2293 if ($item->{'itemlost'}) {
2294 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2295 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2297 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2298 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2301 if ($item->{'wthdrawn'} ne $olditem->{'wthdrawn'}) {
2302 logchange('kohadb', 'change', 'items', 'wthdrawn', $olditem->{'wthdrawn'}, $item->{'wthdrawn'});
2303 my $sth=$dbh->prepare("update items set wthdrawn=$wthdrawn where itemnumber=$itemnumber");
2305 if ($item->{'wthdrawn'}) {
2306 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2307 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2309 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2310 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2313 if ($item->{'restricted'} ne $olditem->{'restricted'}) {
2314 logchange('kohadb', 'change', 'items', 'restricted', $olditem->{'restricted'}, $item->{'restricted'});
2315 my $sth=$dbh->prepare("update items set restricted=$restricted where itemnumber=$itemnumber");
2317 if ($item->{'restricted'}) {
2318 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2319 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2321 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2322 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2331 # END OF UNUSEFUL SUBs
2335 END { } # module clean-up code here (global destructor)