3 # Contains all sub used for biblio management. tables :
4 # biblio, biblioitems, items
5 # bibliosubject, bibliosubtitle
12 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
14 # set the version for version checking
19 &MARCmodsubfield &MARCaddsubfield &MARCfindsubfield
20 &MARCaddbiblio &MARCnextsubfieldid &MARCkoha2marc
23 &newBiblio &newBiblioItem &newItem
24 &updateBiblio &updateBiblioItem &updateItem
25 &itemcount &newbiblio &newbiblioitem
26 &modnote &newsubject &newsubtitle
27 &newordernum &modbiblio &checkitems
29 &modsubtitle &modsubject &modaddauthor &moditem &countitems
30 &delitem &deletebiblioitem &delbiblio
31 &getitemtypes &getbiblio
32 &getbiblioitembybiblionumber
33 &getbiblioitem &getitemsbybiblioitem &isbnsearch
36 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
38 # your exported package globals go here,
39 # as well as any optionally exported functions
41 @EXPORT_OK = qw($Var1 %Hashit);
44 # non-exported package globals go here
45 use vars qw(@more $stuff);
47 # initalize package globals, first exported ones
53 # then the others (which are still accessible as $Some::Module::stuff)
57 # all file-scoped lexicals must be created before
58 # the functions below that use them.
60 # file-private lexicals go here
64 # here's a file-private function as a closure,
65 # callable as &$priv_func; it cannot be prototyped.
70 # make all your functions, whether exported or not;
73 # pass the MARC::Record to this function, and it will create the records in the marc tables
75 my @fields=$record->fields();
78 # adding main table, and retrieving bibid
79 $dbh->do("lock tables marc_biblio WRITE");
80 my $sth=$dbh->prepare("insert into marc_biblio (datecreated) values (now())");
82 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
84 ($bibid)=$sth->fetchrow;
85 # print "BIBID :::".$marcstructure->{bibid}."\n";
87 $dbh->do("unlock tables");
89 # now, add subfields...
90 foreach my $field (@fields) {
91 my @subfields=$field->subfields();
93 foreach my $subfieldcount (0..$#subfields) {
94 print $field->tag().":".$field->indicator(1).$field->indicator(2).":".$subfields[$subfieldcount][0].":".$subfields[$subfieldcount][1]."\n";
95 &MARCaddsubfield($bibid,
97 $field->indicator(1).$field->indicator(2),
99 $subfields[$subfieldcount][0],
101 $subfields[$subfieldcount][1]
108 # Returns MARC::Record of the biblio passed in parameter.
111 my $record = MARC::Record->new();
112 #---- TODO : the leader is missing (000 tag ?)
113 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
114 from marc_subfield_table
117 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
118 $sth->execute($bibid);
119 while (my $row=$sth->fetchrow_hashref) {
120 if ($row->{'valuebloblink'}) { #---- search blob if there is one
121 $sth2->execute($row->{'valuebloblink'});
122 my $row2=$sth2->fetchrow_hashref;
124 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
126 if ($record->field($row->{'tag'})) {
127 my $tag =$record->field($row->{'tag'});
129 $tag->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
130 $record->delete_field($tag);
131 $record->add_fields($tag);
134 $record->add_fields($row->{'tag'}," "," ",$row->{'subfieldcode'} => $row->{'subfieldvalue'});
141 sub MARCmodsubfield {
142 # Subroutine changes a subfield value given a subfieldid.
143 my ( $subfieldid, $subfieldvalue )=@_;
146 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
147 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
148 $sth1->execute($subfieldid);
149 my ($oldvaluebloblink)=$sth1->fetchrow;
152 # if too long, use a bloblink
153 if (length($subfieldvalue)>255 ) {
154 # if already a bloblink, update it, otherwise, insert a new one.
155 if ($oldvaluebloblink) {
156 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
157 $sth->execute($subfieldvalue,$oldvaluebloblink);
159 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
160 $sth->execute($subfieldvalue);
161 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
163 my ($res)=$sth->fetchrow;
164 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
165 $sth->execute($subfieldid);
168 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
169 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
170 $sth->execute($subfieldvalue, $subfieldid);
172 $dbh->do("unlock tables");
175 return($subfieldid, $subfieldvalue);
178 sub MARCfindsubfield {
179 # returns a subfields number given a bibid/tag/subfield values
180 my ($bibid,$tag,$subfieldcode,$subfieldvalue,$subfieldorder) = @_;
185 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
186 if ($subfieldvalue) {
187 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
189 if ($subfieldorder<1) {
192 $query .= " and subfieldorder=$subfieldorder";
194 my $sti=$dbh->prepare($query);
195 $sti->execute($bibid,$tag, $subfieldcode);
196 while (($subfieldid) = $sti->fetchrow) {
198 $lastsubfieldid=$subfieldid;
200 if ($resultcounter>1) {
201 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
202 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
205 return $lastsubfieldid;
209 sub MARCaddsubfield {
210 # Add a new subfield to a tag into the DB.
215 my $subfieldcode=shift;
216 my $subfieldorder=shift;
217 my $subfieldvalue=shift;
220 unless ($subfieldorder) {
221 my $sth=$dbh->prepare("select max(subfieldorder) from marc_subfield_table where tag=$tagid");
224 ($subfieldorder) = $sth->fetchrow;
230 if (length($subfieldvalue)>255) {
231 $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
232 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
233 $sth->execute($subfieldvalue);
234 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
236 my ($res)=$sth->fetchrow;
237 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?)");
238 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
239 $dbh->do("unlock tables");
241 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?)");
242 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
248 # this function builds MARC::Record from the old koha-DB fields
249 my ($biblionumber,$biblioitemnumber,$itemnumber) = @_;
251 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
252 my $record = MARC::Record->new();
253 #--- if bibid, then retrieve old-style koha data
254 if ($biblionumber>0) {
255 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
256 from biblio where biblionumber=?");
257 $sth2->execute($biblionumber);
258 my $row=$sth2->fetchrow_hashref;
260 foreach $code (keys %$row) {
262 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
266 #--- if biblioitem, then retrieve old-style koha data
267 if ($biblioitemnumber>0) {
268 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
269 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
270 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
272 WHERE biblionumber=? and biblioitemnumber=?
274 $sth2->execute($biblionumber,$biblioitemnumber);
275 my $row=$sth2->fetchrow_hashref;
277 foreach $code (keys %$row) {
279 &MARCkoha2marcOnefield($sth,$record,"biblioitem.".$code,$row->{$code});
283 #--- if item, then retrieve old-style koha data
285 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
286 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
287 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
288 reserves,restricted,binding,itemnotes,holdingbranch,interim,timestamp
290 WHERE biblionumber=? and itemnumber=?");
291 $sth2->execute($biblionumber,$itemnumber);
292 my $row=$sth2->fetchrow_hashref;
294 foreach $code (keys %$row) {
296 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
303 sub MARCkoha2marcOnefield {
304 my ($sth,$record,$kohafieldname,$value)=@_;
307 $sth->execute($kohafieldname);
308 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
309 if ($record->field($tagfield)) {
310 my $tag =$record->field($tagfield);
312 $tag->add_subfields($tagsubfield,$value);
313 $record->delete_field($tag);
314 $record->add_fields($tag);
317 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
324 # Update the biblio with biblionumber $biblio->{'biblionumber'}
325 # I guess this routine should search through all marc records for a record that
326 # has the same biblionumber stored in it, and modify the MARC record as well as
329 # Also, this subroutine should search through the $biblio object and compare it
330 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
331 # this logging feature to be usable to undo changes easily.
333 my ($env, $biblio) = @_;
335 my $biblionumber=$biblio->{'biblionumber'};
337 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
339 my $origbiblio=$sth->fetchrow_hashref;
340 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
342 my ($subtitle)=$sth->fetchrow;
343 $origbiblio->{'subtitle'}=$subtitle;
344 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
346 my $origadditionalauthors;
347 while (my ($author) = $sth->fetchrow) {
348 push (@{$origbiblio->{'additionalauthors'}}, $author);
349 $origadditionalauthors->{$author}=1;
351 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
354 while (my ($subject) = $sth->fetchrow) {
355 push (@{$origbiblio->{'subjects'}}, $subject);
356 $origsubjects->{$subject}=1;
360 # Obtain a list of MARC Record_ID's that are tied to this biblio
361 $sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
364 while (my ($bibid) = $sth->fetchrow) {
365 push(@marcrecords, $bibid);
369 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
370 my $q_author=$dbh->quote($biblio->{'author'});
371 logchange('kohadb', 'change', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
372 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
374 foreach $bibid (@marcrecords) {
375 logchange('marc', 'change', $bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
376 changeSubfield($bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
379 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
380 my $q_title=$dbh->quote($biblio->{'title'});
381 logchange('kohadb', 'change', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
382 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
384 foreach $Record_ID (@marcrecords) {
385 logchange('marc', 'change', $Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
386 changeSubfield($Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
389 if ($biblio->{'subtitle'} ne $origbiblio->{'subtitle'}) {
390 my $q_subtitle=$dbh->quote($biblio->{'subtitle'});
391 logchange('kohadb', 'change', 'biblio', 'subtitle', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
392 my $sti=$dbh->prepare("update bibliosubtitle set subtitle=$q_subtitle where biblionumber=$biblio->{'biblionumber'}");
394 foreach $Record_ID (@marcrecords) {
395 logchange('marc', 'change', $Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
396 changeSubfield($Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
399 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
400 my $q_unititle=$dbh->quote($biblio->{'unititle'});
401 logchange('kohadb', 'change', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
402 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
405 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
406 my $q_notes=$dbh->quote($biblio->{'notes'});
407 logchange('kohadb', 'change', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
408 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
410 foreach $Record_ID (@marcrecords) {
411 logchange('marc', 'change', $Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
412 changeSubfield($Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
415 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
416 my $q_serial=$dbh->quote($biblio->{'serial'});
417 logchange('kohadb', 'change', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
418 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
421 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
422 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
423 logchange('kohadb', 'change', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
424 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
426 foreach $Record_ID (@marcrecords) {
427 logchange('marc', 'change', $Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
428 changeSubfield($Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
431 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
432 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
433 logchange('kohadb', 'change', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
434 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
436 foreach $Record_ID (@marcrecords) {
437 logchange('marc', 'change', $Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
438 changeSubfield($Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
442 # Check for subject heading changes
446 foreach $newsubject (@{$biblio->{'subject'}}) {
447 $subjects->{$newsubject}=1;
448 if ($origsubjects->{$newsubject}) {
449 $subjects->{$newsubject}=2;
451 my $q_newsubject=$dbh->quote($newsubject);
452 my $sth=$dbh->prepare("insert into bibliosubject (subject,biblionumber) values ($q_newsubject, $biblionumber)");
454 logchange('kohadb', 'add', 'biblio', 'subject', $newsubject);
456 $subfields->{1}->{'Subfield_Mark'}='a';
457 $subfields->{1}->{'Subfield_Value'}=$newsubject;
460 foreach $Record_ID (@marcrecords) {
461 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
462 logchange('marc', 'add', $Record_ID, '650', 'a', $newsubject);
467 foreach $origsubject (keys %$origsubjects) {
468 if ($subjects->{$origsubject} == 1) {
469 my $q_origsubject=$dbh->quote($origsubject);
470 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'subject', $origsubject);
471 my $sth=$dbh->prepare("delete from bibliosubject where biblionumber=$biblionumber and subject=$q_origsubject");
478 my ($env, $biblioitem) = @_;
480 my $biblionumber=$biblioitem->{'biblionumber'};
481 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
482 my $volume=$biblioitem->{'volume'};
483 my $q_volume=$dbh->quote($volume);
484 my $number=$biblioitem->{'number'};
485 my $q_number=$dbh->quote($number);
486 my $classification=$biblioitem->{'classification'};
487 my $q_classification=$dbh->quote($classification);
488 my $itemtype=$biblioitem->{'itemtype'};
489 my $q_itemtype=$dbh->quote($itemtype);
490 my $isbn=$biblioitem->{'isbn'};
491 my $q_isbn=$dbh->quote($isbn);
492 my $issn=$biblioitem->{'issn'};
493 my $q_issn=$dbh->quote($issn);
494 my $dewey=$biblioitem->{'dewey'};
496 ($dewey == 0) && ($dewey='');
497 my $subclass=$biblioitem->{'subclass'};
498 my $q_subclass=$dbh->quote($subclass);
499 my $publicationyear=$biblioitem->{'publicationyear'};
500 my $publishercode=$biblioitem->{'publishercode'};
501 my $q_publishercode=$dbh->quote($publishercode);
502 my $volumedate=$biblioitem->{'volumedate'};
503 my $q_volumedate=$dbh->quote($volumedate);
504 my $illus=$biblioitem->{'illus'};
505 my $q_illus=$dbh->quote($illus);
506 my $pages=$biblioitem->{'pages'};
507 my $q_pages=$dbh->quote($pages);
508 my $notes=$biblioitem->{'notes'};
509 my $q_notes=$dbh->quote($notes);
510 my $size=$biblioitem->{'size'};
511 my $q_size=$dbh->quote($size);
512 my $place=$biblioitem->{'place'};
513 my $q_place=$dbh->quote($place);
514 my $lccn=$biblioitem->{'lccn'};
515 my $q_lccn=$dbh->quote($lccn);
518 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
521 unless ($env->{'marconly'}) {
522 #my $sth=$dbh->prepare("lock tables biblioitems write");
524 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
526 my ($biblioitemnumber) =$sth->fetchrow;
528 $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)");
530 #my $sth=$dbh->prepare("unlock tables");
535 # Should we check if there is already a biblioitem/marc with the
536 # same isbn/lccn/issn?
538 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
540 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
541 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
543 my ($subtitle) = $sth->fetchrow;
544 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
546 my @additionalauthors;
547 while (my ($additionalauthor) = $sth->fetchrow) {
548 push (@additionalauthors, $additionalauthor);
550 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
553 while (my ($subject) = $sth->fetchrow) {
554 push (@subjects, $subject);
559 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
561 my $Resource_ID=$dbh->{'mysql_insertid'};
562 my $Record_ID=$Resource_ID;
563 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
569 $subfields->{1}->{'Subfield_Mark'}='a';
570 $subfields->{1}->{'Subfield_Value'}=$title;
572 $subfields->{2}->{'Subfield_Mark'}='b';
573 $subfields->{2}->{'Subfield_Value'}=$subtitle;
576 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
582 $subfields->{1}->{'Subfield_Mark'}='a';
583 $subfields->{1}->{'Subfield_Value'}=$author;
585 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
590 $subfields->{1}->{'Subfield_Mark'}='a';
591 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
593 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
598 $subfields->{1}->{'Subfield_Mark'}='a';
599 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
600 $subfields->{2}->{'Subfield_Mark'}='3';
601 $subfields->{2}->{'Subfield_Value'}='biblio';
603 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
606 foreach (@additionalauthors) {
608 (next) unless ($author);
610 $subfields->{1}->{'Subfield_Mark'}='a';
611 $subfields->{1}->{'Subfield_Value'}=$author;
612 $subfields->{2}->{'Subfield_Mark'}='e';
613 $subfields->{2}->{'Subfield_Value'}='author';
615 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
619 (next) unless ($illus);
621 $subfields->{1}->{'Subfield_Mark'}='a';
622 $subfields->{1}->{'Subfield_Value'}=$illus;
623 $subfields->{2}->{'Subfield_Mark'}='e';
624 $subfields->{2}->{'Subfield_Value'}='illustrator';
626 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
629 foreach (@subjects) {
631 (next) unless ($subject);
633 $subfields->{1}->{'Subfield_Mark'}='a';
634 $subfields->{1}->{'Subfield_Value'}=$subject;
636 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
643 $subfields->{1}->{'Subfield_Mark'}='a';
644 $subfields->{1}->{'Subfield_Value'}=$isbn;
646 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
651 $subfields->{1}->{'Subfield_Mark'}='a';
652 $subfields->{1}->{'Subfield_Value'}=$lccn;
654 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
659 $subfields->{1}->{'Subfield_Mark'}='a';
660 $subfields->{1}->{'Subfield_Value'}=$issn;
662 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
667 $subfields->{1}->{'Subfield_Mark'}='a';
668 $subfields->{1}->{'Subfield_Value'}=$dewey;
670 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
672 # DEWEY subclass and itemtype
675 $subfields->{1}->{'Subfield_Mark'}='a';
676 $subfields->{1}->{'Subfield_Value'}=$itemtype;
677 $subfields->{2}->{'Subfield_Mark'}='b';
678 $subfields->{2}->{'Subfield_Value'}=$subclass;
679 $subfields->{3}->{'Subfield_Mark'}='c';
680 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
681 $subfields->{4}->{'Subfield_Mark'}='d';
682 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
684 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
689 $subfields->{1}->{'Subfield_Mark'}='a';
690 $subfields->{1}->{'Subfield_Value'}=$place;
691 $subfields->{2}->{'Subfield_Mark'}='b';
692 $subfields->{2}->{'Subfield_Value'}=$publishercode;
693 $subfields->{3}->{'Subfield_Mark'}='c';
694 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
695 if ($copyrightdate) {
696 $subfields->{4}->{'Subfield_Mark'}='c';
697 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
700 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
703 if ($pages || $size) {
705 $subfields->{1}->{'Subfield_Mark'}='a';
706 $subfields->{1}->{'Subfield_Value'}=$pages;
707 $subfields->{2}->{'Subfield_Mark'}='c';
708 $subfields->{2}->{'Subfield_Value'}=$size;
710 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
713 if ($volume || $number) {
715 $subfields->{1}->{'Subfield_Mark'}='v';
716 $subfields->{1}->{'Subfield_Value'}=$volume;
717 $subfields->{2}->{'Subfield_Mark'}='n';
718 $subfields->{2}->{'Subfield_Value'}=$number;
720 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
725 $subfields->{1}->{'Subfield_Mark'}='a';
726 $subfields->{1}->{'Subfield_Value'}=$notes;
727 $subfields->{2}->{'Subfield_Mark'}='3';
728 $subfields->{2}->{'Subfield_Value'}='biblioitem';
730 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
734 return ($env, $Record_ID);
737 sub updateBiblioItem {
738 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
740 # This routine should also check to see which fields are actually being
741 # modified, and log all changes.
743 my ($env, $biblioitem) = @_;
746 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
747 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
748 # obi = original biblioitem
749 my $obi=$sth->fetchrow_hashref;
750 $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");
752 my ($Record_ID) = $sth->fetchrow;
753 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
754 logchange('kohadb', 'change', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
755 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
756 logchange('marc', 'change', $Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
757 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
759 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
760 logchange('kohadb', 'change', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
761 my $q_volume=$dbh->quote($biblioitem->{'volume'});
762 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
763 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
764 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
766 if ($biblioitem->{'number'} ne $obi->{'number'}) {
767 logchange('kohadb', 'change', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
768 my $q_number=$dbh->quote($biblioitem->{'number'});
769 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
770 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
771 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
773 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
774 logchange('kohadb', 'change', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
775 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
776 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
777 logchange('marc', 'change', $Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
778 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
780 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
781 logchange('kohadb', 'change', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
782 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
783 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
784 logchange('marc', 'change', $Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
785 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
787 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
788 logchange('kohadb', 'change', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
789 my $q_issn=$dbh->quote($biblioitem->{'issn'});
790 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
791 logchange('marc', 'change', $Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
792 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
794 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
795 logchange('kohadb', 'change', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
796 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
797 logchange('marc', 'change', $Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
798 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
800 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
801 logchange('kohadb', 'change', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
802 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
803 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
804 logchange('marc', 'change', $Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
805 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
807 if ($biblioitem->{'place'} ne $obi->{'place'}) {
808 logchange('kohadb', 'change', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
809 my $q_place=$dbh->quote($biblioitem->{'place'});
810 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
811 logchange('marc', 'change', $Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
812 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
814 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
815 logchange('kohadb', 'change', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
816 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
817 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
818 logchange('marc', 'change', $Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
819 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
821 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
822 logchange('kohadb', 'change', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
823 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
824 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
825 logchange('marc', 'change', $Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
826 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
828 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
829 logchange('kohadb', 'change', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
830 my $q_illus=$dbh->quote($biblioitem->{'illus'});
831 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
832 logchange('marc', 'change', $Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
833 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
835 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
836 logchange('kohadb', 'change', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
837 my $q_pages=$dbh->quote($biblioitem->{'pages'});
838 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
839 logchange('marc', 'change', $Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
840 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
842 if ($biblioitem->{'size'} ne $obi->{'size'}) {
843 logchange('kohadb', 'change', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
844 my $q_size=$dbh->quote($biblioitem->{'size'});
845 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
846 logchange('marc', 'change', $Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
847 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
849 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
850 logchange('kohadb', 'change', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
851 my $q_notes=$dbh->quote($biblioitem->{'notes'});
852 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
853 logchange('marc', 'change', $Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
854 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
856 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
857 logchange('kohadb', 'change', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
858 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
859 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
860 logchange('marc', 'change', $Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
861 changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
870 my ($env, $Record_ID, $item) = @_;
872 my $barcode=$item->{'barcode'};
873 my $q_barcode=$dbh->quote($barcode);
874 my $biblionumber=$item->{'biblionumber'};
875 my $biblioitemnumber=$item->{'biblioitemnumber'};
876 my $dateaccessioned=$item->{'dateaccessioned'};
877 my $booksellerid=$item->{'booksellerid'};
878 my $q_booksellerid=$dbh->quote($booksellerid);
879 my $homebranch=$item->{'homebranch'};
880 my $q_homebranch=$dbh->quote($homebranch);
881 my $holdingbranch=$item->{'holdingbranch'};
882 my $price=$item->{'price'};
883 my $replacementprice=$item->{'replacementprice'};
884 my $replacementpricedate=$item->{'replacementpricedate'};
885 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
886 my $notforloan=$item->{'notforloan'};
887 my $itemlost=$item->{'itemlost'};
888 my $wthdrawn=$item->{'wthdrawn'};
889 my $restricted=$item->{'restricted'};
890 my $itemnotes=$item->{'itemnotes'};
891 my $q_itemnotes=$dbh->quote($itemnotes);
892 my $itemtype=$item->{'itemtype'};
893 my $subclass=$item->{'subclass'};
897 unless ($env->{'marconly'}) {
898 my $sth=$dbh->prepare("select max(itemnumber) from items");
900 my ($itemnumber) =$sth->fetchrow;
902 $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)");
909 $subfields->{1}->{'Subfield_Mark'}='p';
910 $subfields->{1}->{'Subfield_Value'}=$barcode;
911 $subfields->{2}->{'Subfield_Mark'}='d';
912 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
913 $subfields->{3}->{'Subfield_Mark'}='e';
914 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
915 $subfields->{4}->{'Subfield_Mark'}='b';
916 $subfields->{4}->{'Subfield_Value'}=$homebranch;
917 $subfields->{5}->{'Subfield_Mark'}='l';
918 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
919 $subfields->{6}->{'Subfield_Mark'}='c';
920 $subfields->{6}->{'Subfield_Value'}=$price;
921 $subfields->{7}->{'Subfield_Mark'}='c';
922 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
923 $subfields->{8}->{'Subfield_Mark'}='d';
924 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
926 $subfields->{9}->{'Subfield_Mark'}='h';
927 $subfields->{9}->{'Subfield_Value'}='Not for loan';
930 $subfields->{10}->{'Subfield_Mark'}='j';
931 $subfields->{10}->{'Subfield_Value'}='Item lost';
934 $subfields->{11}->{'Subfield_Mark'}='j';
935 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
938 $subfields->{12}->{'Subfield_Mark'}='z';
939 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
944 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
946 $env->{'linkid'}=$Tag_ID;
949 $subfields2->{1}->{'Subfield_Mark'}='a';
950 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
951 $subfields2->{1}->{'Subfield_Mark'}='b';
952 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
953 $subfields2->{1}->{'Subfield_Mark'}='c';
954 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
955 $subfields2->{2}->{'Subfield_Mark'}='m';
956 $subfields2->{2}->{'Subfield_Value'}=$subclass;
957 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
962 # Update the item with itemnumber $item->{'itemnumber'}
963 # This routine should also modify the corresponding MARC record data. (852 and
964 # 876 tags with 876p tag the same as $item->{'barcode'}
966 # This routine should also check to see which fields are actually being
967 # modified, and log all changes.
969 my ($env, $item) = @_;
971 my $itemnumber=$item->{'itemnumber'};
972 my $biblionumber=$item->{'biblionumber'};
973 my $biblioitemnumber=$item->{'biblioitemnumber'};
974 my $barcode=$item->{'barcode'};
975 my $dateaccessioned=$item->{'dateaccessioned'};
976 my $booksellerid=$item->{'booksellerid'};
977 my $homebranch=$item->{'homebranch'};
978 my $price=$item->{'price'};
979 my $replacementprice=$item->{'replacementprice'};
980 my $replacementpricedate=$item->{'replacementpricedate'};
981 my $multivolume=$item->{'multivolume'};
982 my $stack=$item->{'stack'};
983 my $notforloan=$item->{'notforloan'};
984 my $itemlost=$item->{'itemlost'};
985 my $wthdrawn=$item->{'wthdrawn'};
986 my $bulk=$item->{'bulk'};
987 my $restricted=$item->{'restricted'};
988 my $binding=$item->{'binding'};
989 my $itemnotes=$item->{'itemnotes'};
990 my $holdingbranch=$item->{'holdingbranch'};
991 my $interim=$item->{'interim'};
992 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
994 my $olditem=$sth->fetchrow_hashref;
995 my $q_barcode=$dbh->quote($olditem->{'barcode'});
996 $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");
998 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
999 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
1001 my ($link) = $sth->fetchrow;
1002 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
1004 my ($Subfield852_ID) = $sth->fetchrow;
1006 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
1007 logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
1008 my $q_barcode=$dbh->quote($item->{'barcode'});
1009 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
1011 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
1012 logchange('marc', 'change', $Record_ID, '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
1014 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
1015 logchange('kohadb', 'change', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
1016 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
1017 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
1019 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
1020 logchange('marc', 'change', $Record_ID, '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
1022 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
1023 logchange('kohadb', 'change', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
1024 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
1025 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
1027 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
1028 logchange('marc', 'change', $Record_ID, '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
1030 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
1031 logchange('kohadb', 'change', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
1032 my $q_homebranch=$dbh->quote($item->{'homebranch'});
1033 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
1035 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
1036 logchange('marc', 'change', $Record_ID, '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
1038 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
1039 logchange('kohadb', 'change', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
1040 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
1041 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
1043 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
1044 logchange('marc', 'change', $Record_ID, '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
1046 if ($item->{'price'} ne $olditem->{'price'}) {
1047 logchange('kohadb', 'change', 'items', 'price', $olditem->{'price'}, $item->{'price'});
1048 my $q_price=$dbh->quote($item->{'price'});
1049 my $sth=$dbh->prepare("update items set price=$q_price where itemnumber=$itemnumber");
1051 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'price'}, $item->{'price'}, $Subfield876_ID);
1052 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'price'}, $item->{'price'});
1054 if ($item->{'itemnotes'} ne $olditem->{'itemnotes'}) {
1055 logchange('kohadb', 'change', 'items', 'itemnotes', $olditem->{'itemnotes'}, $item->{'itemnotes'});
1056 my $q_itemnotes=$dbh->quote($item->{'itemnotes'});
1057 my $sth=$dbh->prepare("update items set itemnotes=$q_itemnotes where itemnumber=$itemnumber");
1059 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'itemnotes'}, $item->{'itemnotes'}, $Subfield876_ID);
1060 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'itemnotes'}, $item->{'itemnotes'});
1062 if ($item->{'notforloan'} ne $olditem->{'notforloan'}) {
1063 logchange('kohadb', 'change', 'items', 'notforloan', $olditem->{'notforloan'}, $item->{'notforloan'});
1064 my $sth=$dbh->prepare("update items set notforloan=$notforloan where itemnumber=$itemnumber");
1066 if ($item->{'notforloan'}) {
1067 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
1068 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
1070 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
1071 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
1074 if ($item->{'itemlost'} ne $olditem->{'itemlost'}) {
1075 logchange('kohadb', 'change', 'items', 'itemlost', $olditem->{'itemlost'}, $item->{'itemlost'});
1076 my $sth=$dbh->prepare("update items set itemlost=$itemlost where itemnumber=$itemnumber");
1078 if ($item->{'itemlost'}) {
1079 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
1080 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
1082 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
1083 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
1086 if ($item->{'wthdrawn'} ne $olditem->{'wthdrawn'}) {
1087 logchange('kohadb', 'change', 'items', 'wthdrawn', $olditem->{'wthdrawn'}, $item->{'wthdrawn'});
1088 my $sth=$dbh->prepare("update items set wthdrawn=$wthdrawn where itemnumber=$itemnumber");
1090 if ($item->{'wthdrawn'}) {
1091 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
1092 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
1094 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
1095 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
1098 if ($item->{'restricted'} ne $olditem->{'restricted'}) {
1099 logchange('kohadb', 'change', 'items', 'restricted', $olditem->{'restricted'}, $item->{'restricted'});
1100 my $sth=$dbh->prepare("update items set restricted=$restricted where itemnumber=$itemnumber");
1102 if ($item->{'restricted'}) {
1103 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
1104 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
1106 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
1107 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
1118 my $query="Select count(*) from items where biblionumber=$biblio";
1120 my $sth=$dbh->prepare($query);
1122 my $data=$sth->fetchrow_hashref;
1125 return($data->{'count(*)'});
1131 my $query="Select ordernumber from aqorders where biblionumber=$bib and
1132 biblioitemnumber='$bi'";
1133 my $sth=$dbh->prepare($query);
1135 my $ordnum=$sth->fetchrow_hashref;
1137 my $order=getsingleorder($ordnum->{'ordernumber'});
1140 return ($order,$ordnum->{'ordernumber'});
1143 sub getsingleorder {
1146 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1147 where aqorders.ordernumber='$ordnum'
1148 and biblio.biblionumber=aqorders.biblionumber and
1149 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1150 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1151 my $sth=$dbh->prepare($query);
1153 my $data=$sth->fetchrow_hashref;
1161 my $dbh = &C4Connect;
1162 my $query = "Select max(biblionumber) from biblio";
1163 my $sth = $dbh->prepare($query);
1165 my $data = $sth->fetchrow_arrayref;
1166 my $bibnum = $$data[0] + 1;
1169 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1170 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1171 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
1172 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
1173 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1174 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1175 if ($biblio->{'seriestitle'}) { $series = 1 };
1178 $query = "insert into biblio set
1179 biblionumber = $bibnum,
1180 title = $biblio->{'title'},
1181 author = $biblio->{'author'},
1182 copyrightdate = $biblio->{'copyright'},
1184 seriestitle = $biblio->{'seriestitle'},
1185 notes = $biblio->{'notes'},
1186 abstract = $biblio->{'abstract'}";
1188 $sth = $dbh->prepare($query);
1198 my $dbh = C4Connect;
1202 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1203 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1204 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1205 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
1206 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
1207 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
1208 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
1209 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1211 $query = "Update biblio set
1212 title = $biblio->{'title'},
1213 author = $biblio->{'author'},
1214 abstract = $biblio->{'abstract'},
1215 copyrightdate = $biblio->{'copyrightdate'},
1216 seriestitle = $biblio->{'seriestitle'},
1217 serial = $biblio->{'serial'},
1218 unititle = $biblio->{'unititle'},
1219 notes = $biblio->{'notes'}
1220 where biblionumber = $biblio->{'biblionumber'}";
1221 $sth = $dbh->prepare($query);
1227 return($biblio->{'biblionumber'});
1231 my ($bibnum, $subtitle) = @_;
1232 my $dbh = C4Connect;
1233 my $query = "update bibliosubtitle set
1234 subtitle = '$subtitle'
1235 where biblionumber = $bibnum";
1236 my $sth = $dbh->prepare($query);
1245 my ($bibnum, $author) = @_;
1246 my $dbh = C4Connect;
1247 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1248 my $sth = $dbh->prepare($query);
1253 if ($author ne '') {
1254 $query = "Insert into additionalauthors set
1256 biblionumber = '$bibnum'";
1257 $sth = $dbh->prepare($query);
1265 } # sub modaddauthor
1269 my ($bibnum, $force, @subject) = @_;
1270 my $dbh = C4Connect;
1271 my $count = @subject;
1273 for (my $i = 0; $i < $count; $i++) {
1274 $subject[$i] =~ s/^ //g;
1275 $subject[$i] =~ s/ $//g;
1276 my $query = "select * from catalogueentry
1277 where entrytype = 's'
1278 and catalogueentry = '$subject[$i]'";
1279 my $sth = $dbh->prepare($query);
1282 if (my $data = $sth->fetchrow_hashref) {
1284 if ($force eq $subject[$i]) {
1286 # subject not in aut, chosen to force anway
1287 # so insert into cataloguentry so its in auth file
1288 $query = "Insert into catalogueentry
1289 (entrytype,catalogueentry)
1290 values ('s','$subject[$i]')";
1291 my $sth2 = $dbh->prepare($query);
1298 $error = "$subject[$i]\n does not exist in the subject authority file";
1299 $query = "Select * from catalogueentry
1300 where entrytype = 's'
1301 and (catalogueentry like '$subject[$i] %'
1302 or catalogueentry like '% $subject[$i] %'
1303 or catalogueentry like '% $subject[$i]')";
1304 my $sth2 = $dbh->prepare($query);
1307 while (my $data = $sth2->fetchrow_hashref) {
1308 $error = $error."<br>$data->{'catalogueentry'}";
1317 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1318 my $sth = $dbh->prepare($query);
1323 for (my $i = 0; $i < $count; $i++) {
1324 $sth = $dbh->prepare("Insert into bibliosubject
1325 values ('$subject[$i]', $bibnum)");
1337 my ($biblioitem) = @_;
1338 my $dbh = C4Connect;
1341 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1342 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1343 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1344 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1345 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1346 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1347 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1348 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1349 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1350 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1351 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1352 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1353 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1354 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1356 $query = "Update biblioitems set
1357 itemtype = $biblioitem->{'itemtype'},
1358 url = $biblioitem->{'url'},
1359 isbn = $biblioitem->{'isbn'},
1360 publishercode = $biblioitem->{'publishercode'},
1361 publicationyear = $biblioitem->{'publicationyear'},
1362 classification = $biblioitem->{'classification'},
1363 dewey = $biblioitem->{'dewey'},
1364 subclass = $biblioitem->{'subclass'},
1365 illus = $biblioitem->{'illus'},
1366 pages = $biblioitem->{'pages'},
1367 volumeddesc = $biblioitem->{'volumeddesc'},
1368 notes = $biblioitem->{'notes'},
1369 size = $biblioitem->{'size'},
1370 place = $biblioitem->{'place'}
1371 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1379 my ($bibitemnum,$note)=@_;
1381 my $query="update biblioitems set notes='$note' where
1382 biblioitemnumber='$bibitemnum'";
1383 my $sth=$dbh->prepare($query);
1390 my ($biblioitem) = @_;
1391 my $dbh = C4Connect;
1392 my $query = "Select max(biblioitemnumber) from biblioitems";
1393 my $sth = $dbh->prepare($query);
1397 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
1398 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
1399 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1400 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1401 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1402 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1403 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
1404 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1405 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1406 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1407 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1408 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
1409 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1410 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1411 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1412 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1413 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1414 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1415 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
1416 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
1419 $data = $sth->fetchrow_arrayref;
1420 $bibitemnum = $$data[0] + 1;
1424 $query = "insert into biblioitems set
1425 biblioitemnumber = $bibitemnum,
1426 biblionumber = $biblioitem->{'biblionumber'},
1427 volume = $biblioitem->{'volume'},
1428 number = $biblioitem->{'number'},
1429 classification = $biblioitem->{'classification'},
1430 itemtype = $biblioitem->{'itemtype'},
1431 url = $biblioitem->{'url'},
1432 isbn = $biblioitem->{'isbn'},
1433 issn = $biblioitem->{'issn'},
1434 dewey = $biblioitem->{'dewey'},
1435 subclass = $biblioitem->{'subclass'},
1436 publicationyear = $biblioitem->{'publicationyear'},
1437 publishercode = $biblioitem->{'publishercode'},
1438 volumedate = $biblioitem->{'volumedate'},
1439 volumeddesc = $biblioitem->{'volumeddesc'},
1440 illus = $biblioitem->{'illus'},
1441 pages = $biblioitem->{'pages'},
1442 notes = $biblioitem->{'notes'},
1443 size = $biblioitem->{'size'},
1444 lccn = $biblioitem->{'lccn'},
1445 marc = $biblioitem->{'marc'},
1446 place = $biblioitem->{'place'}";
1448 $sth = $dbh->prepare($query);
1453 return($bibitemnum);
1459 my $query="insert into bibliosubject (biblionumber) values
1461 my $sth=$dbh->prepare($query);
1469 my ($bibnum, $subtitle) = @_;
1470 my $dbh = C4Connect;
1471 $subtitle = $dbh->quote($subtitle);
1472 my $query = "insert into bibliosubtitle set
1473 biblionumber = $bibnum,
1474 subtitle = $subtitle";
1475 my $sth = $dbh->prepare($query);
1485 my ($item, @barcodes) = @_;
1486 my $dbh = C4Connect;
1487 my $query = "Select max(itemnumber) from items";
1488 my $sth = $dbh->prepare($query);
1494 $data = $sth->fetchrow_hashref;
1495 $itemnumber = $data->{'max(itemnumber)'} + 1;
1498 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
1499 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
1500 $item->{'price'} = $dbh->quote($item->{'price'});
1501 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
1502 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
1504 foreach my $barcode (@barcodes) {
1505 $barcode = uc($barcode);
1506 $barcode = $dbh->quote($barcode);
1507 $query = "Insert into items set
1508 itemnumber = $itemnumber,
1509 biblionumber = $item->{'biblionumber'},
1510 biblioitemnumber = $item->{'biblioitemnumber'},
1512 booksellerid = $item->{'booksellerid'},
1513 dateaccessioned = NOW(),
1514 homebranch = $item->{'homebranch'},
1515 holdingbranch = $item->{'homebranch'},
1516 price = $item->{'price'},
1517 replacementprice = $item->{'replacementprice'},
1518 replacementpricedate = NOW(),
1519 itemnotes = $item->{'itemnotes'}";
1521 if ($item->{'loan'}) {
1523 notforloan = $item->{'loan'}";
1526 $sth = $dbh->prepare($query);
1529 $error .= $sth->errstr;
1540 my ($count,@barcodes)=@_;
1543 for (my $i=0;$i<$count;$i++){
1544 $barcodes[$i]=uc $barcodes[$i];
1545 my $query="Select * from items where barcode='$barcodes[$i]'";
1546 my $sth=$dbh->prepare($query);
1548 if (my $data=$sth->fetchrow_hashref){
1549 $error.=" Duplicate Barcode: $barcodes[$i]";
1558 my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1560 my $query="update items set biblioitemnumber=$bibitemnum,
1561 barcode='$barcode',itemnotes='$notes'
1562 where itemnumber=$itemnum";
1563 if ($barcode eq ''){
1564 $query="update items set biblioitemnumber=$bibitemnum,notforloan=$loan where itemnumber=$itemnum";
1567 $query="update items set biblioitemnumber=$bibitemnum,
1568 barcode='$barcode',itemnotes='$notes',homebranch='$homebranch',
1569 itemlost='$lost',wthdrawn='$wthdrawn' where itemnumber=$itemnum";
1571 if ($replacement ne ''){
1572 $query=~ s/ where/,replacementprice='$replacement' where/;
1575 my $sth=$dbh->prepare($query);
1582 my ($bibitemnum)=@_;
1584 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1585 my $sth=$dbh->prepare($query);
1587 my $data=$sth->fetchrow_hashref;
1590 return($data->{'count(*)'});
1596 my $query="select * from items where itemnumber=$itemnum";
1597 my $sth=$dbh->prepare($query);
1599 my @data=$sth->fetchrow_array;
1601 $query="Insert into deleteditems values (";
1602 foreach my $temp (@data){
1603 $query=$query."'$temp',";
1607 $sth=$dbh->prepare($query);
1610 $query = "Delete from items where itemnumber=$itemnum";
1611 $sth=$dbh->prepare($query);
1617 sub deletebiblioitem {
1618 my ($biblioitemnumber) = @_;
1619 my $dbh = C4Connect;
1620 my $query = "Select * from biblioitems
1621 where biblioitemnumber = $biblioitemnumber";
1622 my $sth = $dbh->prepare($query);
1627 if (@results = $sth->fetchrow_array) {
1629 $query = "Insert into deletedbiblioitems values (";
1630 foreach my $value (@results) {
1631 $value = $dbh->quote($value);
1632 $query .= "$value,";
1635 $query =~ s/\,$/\)/;
1638 $query = "Delete from biblioitems
1639 where biblioitemnumber = $biblioitemnumber";
1645 # Now delete all the items attached to the biblioitem
1647 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1648 $sth = $dbh->prepare($query);
1652 while (@results = $sth->fetchrow_array) {
1654 $query = "Insert into deleteditems values (";
1655 foreach my $value (@results) {
1656 $value = $dbh->quote($value);
1657 $query .= "$value,";
1660 $query =~ s/\,$/\)/;
1666 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1670 } # sub deletebiblioitem
1676 my $query="select * from biblio where biblionumber=$biblio";
1677 my $sth=$dbh->prepare($query);
1679 if (my @data=$sth->fetchrow_array){
1681 $query="Insert into deletedbiblio values (";
1682 foreach my $temp (@data){
1683 $temp=~ s/\'/\\\'/g;
1684 $query=$query."'$temp',";
1688 $sth=$dbh->prepare($query);
1691 $query = "Delete from biblio where biblionumber=$biblio";
1692 $sth=$dbh->prepare($query);
1702 my $dbh = C4Connect;
1703 my $query = "select * from itemtypes";
1704 my $sth = $dbh->prepare($query);
1705 # || die "Cannot prepare $query" . $dbh->errstr;
1710 # || die "Cannot execute $query\n" . $sth->errstr;
1711 while (my $data = $sth->fetchrow_hashref) {
1712 @results[$count] = $data;
1718 return($count, @results);
1719 } # sub getitemtypes
1722 my ($biblionumber) = @_;
1723 my $dbh = C4Connect;
1724 my $query = "Select * from biblio where biblionumber = $biblionumber";
1725 my $sth = $dbh->prepare($query);
1726 # || die "Cannot prepare $query\n" . $dbh->errstr;
1731 # || die "Cannot execute $query\n" . $sth->errstr;
1732 while (my $data = $sth->fetchrow_hashref) {
1733 $results[$count] = $data;
1739 return($count, @results);
1743 my ($biblioitemnum) = @_;
1744 my $dbh = C4Connect;
1745 my $query = "Select * from biblioitems where
1746 biblioitemnumber = $biblioitemnum";
1747 my $sth = $dbh->prepare($query);
1753 while (my $data = $sth->fetchrow_hashref) {
1754 $results[$count] = $data;
1760 return($count, @results);
1761 } # sub getbiblioitem
1763 sub getbiblioitembybiblionumber {
1764 my ($biblionumber) = @_;
1765 my $dbh = C4Connect;
1766 my $query = "Select * from biblioitems where biblionumber =
1768 my $sth = $dbh->prepare($query);
1774 while (my $data = $sth->fetchrow_hashref) {
1775 $results[$count] = $data;
1781 return($count, @results);
1784 sub getitemsbybiblioitem {
1785 my ($biblioitemnum) = @_;
1786 my $dbh = C4Connect;
1787 my $query = "Select * from items, biblio where
1788 biblio.biblionumber = items.biblionumber and biblioitemnumber
1790 my $sth = $dbh->prepare($query);
1791 # || die "Cannot prepare $query\n" . $dbh->errstr;
1796 # || die "Cannot execute $query\n" . $sth->errstr;
1797 while (my $data = $sth->fetchrow_hashref) {
1798 $results[$count] = $data;
1804 return($count, @results);
1805 } # sub getitemsbybiblioitem
1809 my $dbh = C4Connect;
1815 $isbn = $dbh->quote($isbn);
1816 $query = "Select biblio.* from biblio, biblioitems where
1817 biblio.biblionumber = biblioitems.biblionumber
1819 $sth = $dbh->prepare($query);
1822 while (my $data = $sth->fetchrow_hashref) {
1823 $results[$count] = $data;
1829 return($count, @results);
1832 # At the moment this is just a straight copy of the subject code. Needs heavy
1833 # modification to work for additional authors, obviously.
1834 # Check for additional author changes
1836 my $newadditionalauthor='';
1837 my $additionalauthors;
1838 foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
1839 $additionalauthors->{$newadditionalauthor}=1;
1840 if ($origadditionalauthors->{$newadditionalauthor}) {
1841 $additionalauthors->{$newadditionalauthor}=2;
1843 my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
1844 my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
1846 logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
1848 $subfields->{1}->{'Subfield_Mark'}='a';
1849 $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
1852 foreach $Record_ID (@marcrecords) {
1853 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1854 logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
1858 my $origadditionalauthor;
1859 foreach $origadditionalauthor (keys %$origadditionalauthors) {
1860 if ($additionalauthors->{$origadditionalauthor} == 1) {
1861 my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
1862 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
1863 my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
1873 # Subroutine to log changes to databases
1874 # Eventually, this subroutine will be used to create a log of all changes made,
1875 # with the possibility of "undo"ing some changes
1877 if ($database eq 'kohadb') {
1883 print STDERR "KOHA: $type $section $item $original $new\n";
1884 } elsif ($database eq 'marc') {
1886 my $Record_ID=shift;
1889 my $subfield_ID=shift;
1892 print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
1896 END { } # module clean-up code here (global destructor)