4 # Revision 1.7 2002/08/14 18:12:51 tonnesen
5 # Added copyright statement to all .pl and .pm files
7 # Revision 1.6 2002/07/25 13:40:31 tipaul
8 # pod documenting the API.
10 # Revision 1.5 2002/07/24 16:11:37 tipaul
12 # Database.pm and Output.pm are almost not modified (var test...)
14 # Biblio.pm is almost completly rewritten.
16 # WHAT DOES IT ??? ==> END of Hitchcock suspens
18 # 1st, it does... nothing...
19 # Every old API should be there. So if MARC-stuff is not done, the behaviour is EXACTLY the same (if there is no added bug, of course). So, if you use normal acquisition, you won't find anything new neither on screen or old-DB tables ...
21 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
22 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
23 # * a "OLDnewbiblio" sub, which is a copy/paste of the previous newbiblio sub. Then, when you want to add the MARC-DB stuff, you can modify the newbiblio sub without modifying the OLDnewbiblio one. If we correct a bug in 1.2 in newbiblio, we can do the same in main branch by correcting OLDnewbiblio.
24 # * The MARC stuff is usually done through a sub named MARCxxx where xxx is the same as OLDxxx. For example, newbiblio calls MARCnewbiblio. the MARCxxx subs use a MARC::Record as parameter.
25 # The last thing to solve was to manage biblios through real MARC import : they must populate the old-db, but must populate the MARC-DB too, without loosing information (if we go from MARC::Record to old-data then back to MARC::Record, we loose A LOT OF ROWS). To do this, there are subs beginning by "ALLxxx" : they manage datas with MARC::Record datas. they call OLDxxx sub too (to populate old-DB), but MARCxxx subs too, with a complete MARC::Record ;-)
27 # In Biblio.pm, there are some subs that permits to build a old-style record from a MARC::Record, and the opposite. There is also a sub finding a MARC-bibid from a old-biblionumber and the opposite too.
28 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
32 # move from 1.2 to 1.4 version :
33 # 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
34 # In the 1.4 version, we want to do 2 differents things :
35 # - keep populating the old-DB, that has a LOT less datas than MARC
36 # - populate the MARC-DB
37 # To populate the DBs we have 2 differents sources :
38 # - the standard acquisition system (through book sellers), that does'nt use MARC data
39 # - the MARC acquisition system, that uses MARC data.
41 # thus, we have 2 differents cases :
42 # - 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
43 # - 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.
44 # we MUST have an API for true MARC data, that populate MARC-DB then old-DB
46 # That's why we need 4 subs :
47 # all subs beginning by MARC manage only MARC tables. They manage MARC-DB with MARC::Record parameters
48 # all subs beginning by OLD manage only OLD-DB tables. They manage old-DB with old-DB parameters
49 # 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
50 # 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.
52 # only ALL and old-style API should be used in koha. MARC and OLD is used internally only
54 # 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.
55 # 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 ;-)
59 # Copyright 2000-2002 Katipo Communications
61 # This file is part of Koha.
63 # Koha is free software; you can redistribute it and/or modify it under the
64 # terms of the GNU General Public License as published by the Free Software
65 # Foundation; either version 2 of the License, or (at your option) any later
68 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
69 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
70 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
72 # You should have received a copy of the GNU General Public License along with
73 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
74 # Suite 330, Boston, MA 02111-1307 USA
81 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
83 # set the version for version checking
88 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
89 # as the old-style API and the ALL one are the only public functions.
92 &updateBiblio &updateBiblioItem &updateItem
93 &itemcount &newbiblio &newbiblioitem
94 &modnote &newsubject &newsubtitle
95 &modbiblio &checkitems
97 &modsubtitle &modsubject &modaddauthor &moditem &countitems
98 &delitem &deletebiblioitem &delbiblio
99 &getitemtypes &getbiblio
100 &getbiblioitembybiblionumber
101 &getbiblioitem &getitemsbybiblioitem &isbnsearch
103 &newcompletebiblioitem
105 &ALLnewbiblio &ALLnewitem
108 &MARCaddbiblio &MARCmodsubfield &MARCaddsubfield
111 &MARCkoha2marcBiblio &MARCmarc2koha
113 &MARCaddword &MARCdelword
115 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
117 # your exported package globals go here,
118 # as well as any optionally exported functions
120 @EXPORT_OK = qw($Var1 %Hashit);
123 # non-exported package globals go here
124 use vars qw(@more $stuff);
126 # initalize package globals, first exported ones
132 # then the others (which are still accessible as $Some::Module::stuff)
136 # all file-scoped lexicals must be created before
137 # the functions below that use them.
139 # file-private lexicals go here
141 my %secret_hash = ();
143 # here's a file-private function as a closure,
144 # callable as &$priv_func; it cannot be prototyped.
145 my $priv_func = sub {
149 # make all your functions, whether exported or not;
153 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
156 # all the following subs takes a MARC::Record as parameter and manage
157 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
158 # ALLxxx subs (xxx deals with old-DB parameters, the ALLxxx deals with MARC-DB parameter)
162 all subs requires/use $dbh as 1st parameter.
163 NOTE : all those subs are private and must be used only inside Biblio.pm (called by a old API sub, or the ALLsub)
167 =head2 @tagslib = &MARCgettagslib($dbh,1|0);
168 last param is 1 for liblibrarian and 0 for libopac
169 returns a hash with tag/subfield meaning
171 =head2 ($tagfield,$tagsubfield) = &MARCfindmarc_from_kohafield($dbh,$kohafield);
172 finds MARC tag and subfield for a given kohafield
173 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
175 =head2 $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
176 finds a old-db biblio number for a given MARCbibid number
178 =head2 $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
179 finds a MARC bibid from a old-db biblionumber
181 =head2 &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
182 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
184 =head2 &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
185 adds a subfield in a biblio (in the MARC tables only).
187 =head2 $MARCRecord = &MARCgetbiblio($dbh,$bibid);
188 Returns a MARC::Record for the biblio $bibid.
190 =head2 &MARCmodbiblio($dbh,$bibid,$delete,$record);
191 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
192 if $delete == 1, every field/subfield not found is deleted in the biblio
193 otherwise, only data passed to MARCmodbiblio is managed.
194 thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
196 =head2 ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
197 MARCmodsubfield changes the value of a given subfield
199 =head2 $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
200 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
201 Returns -1 if more than 1 answer
203 =head2 $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
204 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
206 =head2 &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
207 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
209 =head2 &MARCdelbiblio($dbh,$bibid);
210 MARCdelbiblio delete biblio $bibid
212 =head2 $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
213 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
215 =head2 $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
216 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
218 =head2 $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
219 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
221 =head2 &MARCkoha2marcOnefield => used by MARCkoha2marc and should not be useful elsewhere
223 =head2 $olddb = &MARCmarc2koha($dbh,$MARCRecord);
224 builds a hash with old-db datas from a MARC::Record
226 =head2 &MARCmarc2kohaOnefield => used by MARCmarc2koha and should not be useful elsewhere
228 =head2 MARCaddword => used to manage MARC_word table and should not be useful elsewhere
230 =head2 MARCdelword => used to manage MARC_word table and should not be useful elsewhere
234 Paul POULAIN paul.poulain@free.fr
239 my ($dbh,$forlibrarian)= @_;
241 if ($forlibrarian eq 1) {
242 $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib from marc_subfield_structure");
244 $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib from marc_subfield_structure");
251 while ( ($tag,$subfield,$lib) = $sth->fetchrow) {
252 $res->{$tag}->{$subfield}=$lib;
257 sub MARCfind_marc_from_kohafield {
258 my ($dbh,$kohafield) = @_;
259 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
260 $sth->execute($kohafield);
261 my ($tagfield,$tagsubfield) = $sth->fetchrow;
262 return ($tagfield,$tagsubfield);
265 sub MARCfind_oldbiblionumber_from_MARCbibid {
266 my ($dbh,$MARCbibid) = @_;
267 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
268 $sth->execute($MARCbibid);
269 my ($biblionumber) = $sth->fetchrow;
270 return $biblionumber;
273 sub MARCfind_MARCbibid_from_oldbiblionumber {
274 my ($dbh,$oldbiblionumber) = @_;
275 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
276 $sth->execute($oldbiblionumber);
277 my ($bibid) = $sth->fetchrow;
282 # pass the MARC::Record to this function, and it will create the records in the marc tables
283 my ($dbh,$record,$biblionumber) = @_;
284 my @fields=$record->fields();
286 # adding main table, and retrieving bibid
287 $dbh->do("lock tables marc_biblio WRITE");
288 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
289 $sth->execute($biblionumber);
290 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
292 ($bibid)=$sth->fetchrow;
294 $dbh->do("unlock tables");
296 # now, add subfields...
297 foreach my $field (@fields) {
298 my @subfields=$field->subfields();
300 foreach my $subfieldcount (0..$#subfields) {
301 # print $field->tag().":".$field->indicator(1).$field->indicator(2).":".$subfields[$subfieldcount][0].":".$subfields[$subfieldcount][1]."\n";
302 &MARCaddsubfield($dbh,$bibid,
304 $field->indicator(1).$field->indicator(2),
306 $subfields[$subfieldcount][0],
308 $subfields[$subfieldcount][1]
315 sub MARCaddsubfield {
316 # Add a new subfield to a tag into the DB.
322 my $subfieldcode=shift;
323 my $subfieldorder=shift;
324 my $subfieldvalue=shift;
326 # if not value, end of job, we do nothing
327 if (not($subfieldvalue)) {
330 if (not($subfieldcode)) {
333 unless ($subfieldorder) {
334 my $sth=$dbh->prepare("select max(subfieldorder) from marc_subfield_table where tag=$tagid");
337 ($subfieldorder) = $sth->fetchrow;
343 if (length($subfieldvalue)>255) {
344 $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
345 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
346 $sth->execute($subfieldvalue);
347 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
349 my ($res)=$sth->fetchrow;
350 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?)");
352 $sth->execute($bibid,'0'.$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
354 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
357 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
359 $dbh->do("unlock tables");
361 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?)");
362 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
364 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
367 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
372 # Returns MARC::Record of the biblio passed in parameter.
374 my $record = MARC::Record->new();
375 #---- TODO : the leader is missing
376 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
377 from marc_subfield_table
378 where bibid=? order by tagorder,subfieldorder
380 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
381 $sth->execute($bibid);
382 while (my $row=$sth->fetchrow_hashref) {
383 if ($row->{'valuebloblink'}) { #---- search blob if there is one
384 $sth2->execute($row->{'valuebloblink'});
385 my $row2=$sth2->fetchrow_hashref;
387 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
389 if ($record->field($row->{'tag'})) {
391 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
392 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
393 if (length($row->{'tag'}) <3) {
394 $row->{'tag'} = "0".$row->{'tag'};
396 $field =$record->field($row->{'tag'});
398 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
399 $record->delete_field($field);
400 $record->add_fields($field);
403 if (length($row->{'tag'}) < 3) {
404 $row->{'tag'} = "0".$row->{'tag'};
406 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
407 $record->add_fields($temp);
411 # print "----------------------\n".$record->as_formatted()."\n-----------------";
416 # NOT SURE THIS SUB WORKS WELL...
417 my ($dbh,$bibid,$delete,$record)=@_;
418 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
419 # if nothing to change, don't waste time...
420 if ($oldrecord eq $record) {
421 # print "nothing to do \n";
424 # otherwise, skip through each subfield...
425 my @fields = $record->fields();
427 foreach my $field (@fields) {
428 #print "tag : ".$field->tag()."\n";
429 my $oldfield = $oldrecord->field($field->tag());
430 my @subfields=$field->subfields();
433 foreach my $subfield (@subfields) {
435 if ($oldfield eq 0) {
436 # just adding datas...
437 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
438 1,@$subfield[0],$subfieldorder,@$subfield[1]);
440 # modify he subfield if it's a different string
441 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
442 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
443 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
445 # print "nothing to change\n";
452 sub MARCmodsubfield {
453 # Subroutine changes a subfield value given a subfieldid.
454 my ($dbh, $subfieldid, $subfieldvalue )=@_;
456 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
457 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
458 $sth1->execute($subfieldid);
459 my ($oldvaluebloblink)=$sth1->fetchrow;
462 # if too long, use a bloblink
463 if (length($subfieldvalue)>255 ) {
464 # if already a bloblink, update it, otherwise, insert a new one.
465 if ($oldvaluebloblink) {
466 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
467 $sth->execute($subfieldvalue,$oldvaluebloblink);
469 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
470 $sth->execute($subfieldvalue);
471 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
473 my ($res)=$sth->fetchrow;
474 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
475 $sth->execute($subfieldid);
478 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
479 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
480 $sth->execute($subfieldvalue, $subfieldid);
482 $dbh->do("unlock tables");
484 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
485 $sth->execute($subfieldid);
486 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
488 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
489 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
490 return($subfieldid, $subfieldvalue);
493 sub MARCfindsubfield {
494 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
498 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
499 if ($subfieldvalue) {
500 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
502 if ($subfieldorder<1) {
505 $query .= " and subfieldorder=$subfieldorder";
507 my $sti=$dbh->prepare($query);
508 $sti->execute($bibid,$tag, $subfieldcode);
509 while (($subfieldid) = $sti->fetchrow) {
511 $lastsubfieldid=$subfieldid;
513 if ($resultcounter>1) {
514 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
515 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
518 return $lastsubfieldid;
522 sub MARCfindsubfieldid {
523 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
524 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
525 where bibid=? and tag=? and tagorder=?
526 and subfieldcode=? and subfieldorder=?");
527 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
528 my ($res) = $sth->fetchrow;
532 sub MARCdelsubfield {
533 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
534 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
535 # my $dbh=&C4Connect;
536 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
537 tag='$tag' and tagorder='$tagorder'
538 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
543 # delete a biblio for a $bibid
544 my ($dbh,$bibid) = @_;
545 # my $dbh=&C4Connect;
546 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
547 $dbh->do("delete from marc_biblio where bibid='$bibid'");
550 sub MARCkoha2marcBiblio {
551 # this function builds partial MARC::Record from the old koha-DB fields
552 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
553 # my $dbh=&C4Connect;
554 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
555 my $record = MARC::Record->new();
556 #--- if bibid, then retrieve old-style koha data
557 if ($biblionumber>0) {
558 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
559 from biblio where biblionumber=?");
560 $sth2->execute($biblionumber);
561 my $row=$sth2->fetchrow_hashref;
563 foreach $code (keys %$row) {
565 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
569 #--- if biblioitem, then retrieve old-style koha data
570 if ($biblioitemnumber>0) {
571 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
572 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
573 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
575 WHERE biblionumber=? and biblioitemnumber=?
577 $sth2->execute($biblionumber,$biblioitemnumber);
578 my $row=$sth2->fetchrow_hashref;
580 foreach $code (keys %$row) {
582 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
587 # TODO : retrieve notes, additionalauthors
590 sub MARCkoha2marcItem {
591 # this function builds partial MARC::Record from the old koha-DB fields
592 my ($dbh,$biblionumber,$itemnumber) = @_;
593 # my $dbh=&C4Connect;
594 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
595 my $record = MARC::Record->new();
596 #--- if item, then retrieve old-style koha data
598 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
599 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
600 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
601 reserves,restricted,binding,itemnotes,holdingbranch,interim,timestamp
603 WHERE biblionumber=? and itemnumber=?");
604 $sth2->execute($biblionumber,$itemnumber);
605 my $row=$sth2->fetchrow_hashref;
607 foreach $code (keys %$row) {
609 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
614 # TODO : retrieve notes, additionalauthors
617 sub MARCkoha2marcSubtitle {
618 # this function builds partial MARC::Record from the old koha-DB fields
619 my ($dbh,$bibnum,$subtitle) = @_;
620 # my $dbh=&C4Connect;
621 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
622 my $record = MARC::Record->new();
623 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
627 sub MARCkoha2marcOnefield {
628 my ($sth,$record,$kohafieldname,$value)=@_;
631 $sth->execute($kohafieldname);
632 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
633 if ($record->field($tagfield)) {
634 my $tag =$record->field($tagfield);
636 $tag->add_subfields($tagsubfield,$value);
637 $record->delete_field($tag);
638 $record->add_fields($tag);
641 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
648 my ($dbh,$record) = @_;
649 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
651 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
654 # print STDERR $record->as_formatted;
655 while (($field)=$sth2->fetchrow) {
656 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
658 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
661 while (($field)=$sth2->fetchrow) {
662 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
664 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
667 while (($field)=$sth2->fetchrow) {
668 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
670 # additional authors : specific
671 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
672 # print STDERR $result."XXXX\n";
673 # foreach my $tmp (key $result) {
674 # print STDERR $result->{$tmp}."\n";
679 sub MARCmarc2kohaOneField {
680 # to check : if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
681 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
685 $sth->execute($kohatable.".".$kohafield);
686 ($tagfield,$subfield) = $sth->fetchrow;
687 foreach my $field ($record->field($tagfield)) {
688 if ($field->subfield($subfield)) {
689 if ($result->{$kohafield}) {
690 $result->{$kohafield} .= " | ".$field->subfield($subfield);
692 $result->{$kohafield}=$field->subfield($subfield);
700 # split a subfield string and adds it into the word table.
702 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
703 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
704 # TODO : remove stopwords
705 my @words = split / /,$sentence;
706 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
707 values (?,?,?,?,?,?,soundex(?))");
708 foreach my $word (@words) {
709 # we record only words longer than 2 car
710 if (length($word)>1) {
711 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
712 # print "($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word)\n";
718 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
719 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
720 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
721 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
726 # ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL
729 # all the following subs are useful to manage MARC-DB with complete MARC records.
730 # it's used with marcimport, and marc management tools
735 all subs requires/use $dbh as 1st parameter.
736 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
740 =head2 (oldbibnum,$oldbibitemnum) = ALLnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
741 creates a new biblio from a MARC::Record. The 3rd and 4th parameter are hashes and may be ignored. If only 2 params are passed to the sub, the old-db hashes
742 are builded from the MARC::Record. If they are passed, they are used.
744 =head2 ALLnewitem($dbh,$olditem);
745 adds an item in the db. $olditem is a old-db hash.
749 Paul POULAIN paul.poulain@free.fr
754 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
755 # note $oldbiblio and $oldbiblioitem are not mandatory.
756 # if not present, they will be builded from $record with MARCmarc2koha function
757 if (($oldbiblio) and not($oldbiblioitem)) {
758 print STDERR "ALLnewbiblio : missing parameter\n";
759 print "ALLnewbiblio : missing parameter : contact koha development team\n";
765 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
766 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
767 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
769 my $olddata = MARCmarc2koha($dbh,$record);
770 $oldbibnum = OLDnewbiblio($dbh,$olddata);
771 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
773 # we must add bibnum and bibitemnum in MARC::Record...
774 # we build the new field with biblionumber and biblioitemnumber
775 # we drop the original field
776 # we add the new builded field.
777 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
778 # (steve and paul : thinks 090 is a good choice)
779 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
780 $sth->execute("biblio.biblionumber");
781 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
782 $sth->execute("biblioitems.biblioitemnumber");
783 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
784 print STDERR "tag1 : $tagfield1 / $tagsubfield1\n tag2 : $tagfield2 / $tagsubfield2\n";
785 if ($tagsubfield1 != $tagsubfield2) {
786 print STDERR "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
787 print "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
790 my $newfield = MARC::Field->new( $tagfield1,'','',
791 "$tagsubfield1" => $oldbibnum,
792 "$tagsubfield2" => $oldbibitemnum);
793 # drop old field and create new one...
794 my $old_field = $record->field($tagfield1);
795 $record->delete_field($old_field);
796 $record->add_fields($newfield);
797 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
798 return ( $oldbibnum,$oldbibitemnum );
802 my ($dbh, $item) = @_;
805 ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{'barcode'});
806 # search MARC biblionumber
807 my $bibid=&MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{'biblionumber'});
809 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
810 $sth->execute($bibid);
811 my ($tagorder) = $sth->fetchrow;
814 # for each field, find MARC tag and subfield, and call the proper MARC sub
815 foreach my $itemkey (keys %$item) {
818 print STDERR "=============> $itemkey : ".$item->{$itemkey}."\n";
819 if ($itemkey eq "biblionumber" || $itemkey eq "biblioitemnumber") {
820 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"biblio.".$itemkey);
822 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"items.".$itemkey);
824 if ($tagfield && $item->{$itemkey} ne 'NULL') {
826 &MARCaddsubfield($dbh,
842 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
848 all subs requires/use $dbh as 1st parameter.
849 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
851 They all are the exact copy of 1.0/1.2 version of the sub
852 without the OLD. The OLDxxx is called by the original xxx sub.
853 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
855 WARNING : there is 1 difference between initialxxx and OLDxxx :
856 the db header $dbh is always passed as parameter
857 to avoid over-DB connexion
861 =head2 $biblionumber = OLDnewbiblio($dbh,$biblio);
862 adds a record in biblio table. Datas are in the hash $biblio.
864 =head2 $biblionumber = OLDmodbiblio($dbh,$biblio);
865 modify a record in biblio table. Datas are in the hash $biblio.
867 =head2 OLDmodsubtitle($dbh,$bibnum,$subtitle);
868 modify subtitles in bibliosubtitle table.
870 =head2 OLDmodaddauthor($dbh,$bibnum,$author);
871 adds or modify additional authors
872 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
874 =head2 $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
877 =head2 OLDmodbibitem($dbh, $biblioitem);
880 =head2 OLDmodnote($dbh,$bibitemnum,$note
881 modify a note for a biblioitem
883 =head2 OLDnewbiblioitem($dbh,$biblioitem);
884 adds a biblioitem ($biblioitem is a hash with the values)
886 =head2 OLDnewsubject($dbh,$bibnum);
888 =head2 OLDnewsubtitle($dbh,$bibnum,$subtitle);
889 create a new subtitle
891 =head2 ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
892 create a item. $item is a hash and $barcode the barcode.
894 =head2 OLDmoditem($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement);
896 NOTE : not standard API-style. Should be rewriten to be OLDmoditem($dbh,$item) where $item is a hash
898 =head2 OLDdelitem($dbh,$itemnum);
901 =head2 OLDdeletebiblioitem($dbh,$biblioitemnumber);
903 NOTE : not standard sub name. Should be OLDdelbiblioitem()
905 =head2 OLDdelbiblio($dbh,$biblio);
910 Paul POULAIN paul.poulain@free.fr
915 my ($dbh,$biblio) = @_;
916 # my $dbh = &C4Connect;
917 my $query = "Select max(biblionumber) from biblio";
918 my $sth = $dbh->prepare($query);
920 my $data = $sth->fetchrow_arrayref;
921 my $bibnum = $$data[0] + 1;
924 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
925 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
926 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
927 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
928 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
929 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
930 if ($biblio->{'seriestitle'}) { $series = 1 };
933 $query = "insert into biblio set
934 biblionumber = $bibnum,
935 title = $biblio->{'title'},
936 author = $biblio->{'author'},
937 copyrightdate = $biblio->{'copyright'},
939 seriestitle = $biblio->{'seriestitle'},
940 notes = $biblio->{'notes'},
941 abstract = $biblio->{'abstract'}";
943 $sth = $dbh->prepare($query);
952 my ($dbh,$biblio) = @_;
953 # my $dbh = C4Connect;
957 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
958 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
959 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
960 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
961 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
962 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
963 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
964 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
966 $query = "Update biblio set
967 title = $biblio->{'title'},
968 author = $biblio->{'author'},
969 abstract = $biblio->{'abstract'},
970 copyrightdate = $biblio->{'copyrightdate'},
971 seriestitle = $biblio->{'seriestitle'},
972 serial = $biblio->{'serial'},
973 unititle = $biblio->{'unititle'},
974 notes = $biblio->{'notes'}
975 where biblionumber = $biblio->{'biblionumber'}";
976 $sth = $dbh->prepare($query);
982 return($biblio->{'biblionumber'});
986 my ($dbh,$bibnum, $subtitle) = @_;
987 # my $dbh = C4Connect;
988 my $query = "update bibliosubtitle set
989 subtitle = '$subtitle'
990 where biblionumber = $bibnum";
991 my $sth = $dbh->prepare($query);
999 sub OLDmodaddauthor {
1000 my ($dbh,$bibnum, $author) = @_;
1001 # my $dbh = C4Connect;
1002 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1003 my $sth = $dbh->prepare($query);
1008 if ($author ne '') {
1009 $query = "Insert into additionalauthors set
1011 biblionumber = '$bibnum'";
1012 $sth = $dbh->prepare($query);
1020 } # sub modaddauthor
1024 my ($dbh,$bibnum, $force, @subject) = @_;
1025 # my $dbh = C4Connect;
1026 my $count = @subject;
1028 for (my $i = 0; $i < $count; $i++) {
1029 $subject[$i] =~ s/^ //g;
1030 $subject[$i] =~ s/ $//g;
1031 my $query = "select * from catalogueentry
1032 where entrytype = 's'
1033 and catalogueentry = '$subject[$i]'";
1034 my $sth = $dbh->prepare($query);
1037 if (my $data = $sth->fetchrow_hashref) {
1039 if ($force eq $subject[$i]) {
1040 # subject not in aut, chosen to force anway
1041 # so insert into cataloguentry so its in auth file
1042 $query = "Insert into catalogueentry
1043 (entrytype,catalogueentry)
1044 values ('s','$subject[$i]')";
1045 my $sth2 = $dbh->prepare($query);
1050 $error = "$subject[$i]\n does not exist in the subject authority file";
1051 $query = "Select * from catalogueentry
1052 where entrytype = 's'
1053 and (catalogueentry like '$subject[$i] %'
1054 or catalogueentry like '% $subject[$i] %'
1055 or catalogueentry like '% $subject[$i]')";
1056 my $sth2 = $dbh->prepare($query);
1059 while (my $data = $sth2->fetchrow_hashref) {
1060 $error = $error."<br>$data->{'catalogueentry'}";
1068 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1069 my $sth = $dbh->prepare($query);
1072 for (my $i = 0; $i < $count; $i++) {
1073 $sth = $dbh->prepare("Insert into bibliosubject
1074 values ('$subject[$i]', $bibnum)");
1086 my ($dbh,$biblioitem) = @_;
1087 # my $dbh = C4Connect;
1090 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1091 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1092 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1093 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1094 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1095 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1096 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1097 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1098 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1099 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1100 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1101 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1102 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1103 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1105 $query = "Update biblioitems set
1106 itemtype = $biblioitem->{'itemtype'},
1107 url = $biblioitem->{'url'},
1108 isbn = $biblioitem->{'isbn'},
1109 publishercode = $biblioitem->{'publishercode'},
1110 publicationyear = $biblioitem->{'publicationyear'},
1111 classification = $biblioitem->{'classification'},
1112 dewey = $biblioitem->{'dewey'},
1113 subclass = $biblioitem->{'subclass'},
1114 illus = $biblioitem->{'illus'},
1115 pages = $biblioitem->{'pages'},
1116 volumeddesc = $biblioitem->{'volumeddesc'},
1117 notes = $biblioitem->{'notes'},
1118 size = $biblioitem->{'size'},
1119 place = $biblioitem->{'place'}
1120 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1128 my ($dbh,$bibitemnum,$note)=@_;
1129 # my $dbh=C4Connect;
1130 my $query="update biblioitems set notes='$note' where
1131 biblioitemnumber='$bibitemnum'";
1132 my $sth=$dbh->prepare($query);
1138 sub OLDnewbiblioitem {
1139 my ($dbh,$biblioitem) = @_;
1140 # my $dbh = C4Connect;
1141 my $query = "Select max(biblioitemnumber) from biblioitems";
1142 my $sth = $dbh->prepare($query);
1146 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
1147 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
1148 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1149 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1150 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1151 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1152 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
1153 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1154 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1155 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1156 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1157 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
1158 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1159 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1160 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1161 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1162 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1163 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1164 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
1165 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
1168 $data = $sth->fetchrow_arrayref;
1169 $bibitemnum = $$data[0] + 1;
1173 $query = "insert into biblioitems set
1174 biblioitemnumber = $bibitemnum,
1175 biblionumber = $biblioitem->{'biblionumber'},
1176 volume = $biblioitem->{'volume'},
1177 number = $biblioitem->{'number'},
1178 classification = $biblioitem->{'classification'},
1179 itemtype = $biblioitem->{'itemtype'},
1180 url = $biblioitem->{'url'},
1181 isbn = $biblioitem->{'isbn'},
1182 issn = $biblioitem->{'issn'},
1183 dewey = $biblioitem->{'dewey'},
1184 subclass = $biblioitem->{'subclass'},
1185 publicationyear = $biblioitem->{'publicationyear'},
1186 publishercode = $biblioitem->{'publishercode'},
1187 volumedate = $biblioitem->{'volumedate'},
1188 volumeddesc = $biblioitem->{'volumeddesc'},
1189 illus = $biblioitem->{'illus'},
1190 pages = $biblioitem->{'pages'},
1191 notes = $biblioitem->{'notes'},
1192 size = $biblioitem->{'size'},
1193 lccn = $biblioitem->{'lccn'},
1194 marc = $biblioitem->{'marc'},
1195 place = $biblioitem->{'place'}";
1197 $sth = $dbh->prepare($query);
1201 return($bibitemnum);
1205 my ($dbh,$bibnum)=@_;
1206 # my $dbh=C4Connect;
1207 my $query="insert into bibliosubject (biblionumber) values
1209 my $sth=$dbh->prepare($query);
1216 sub OLDnewsubtitle {
1217 my ($dbh,$bibnum, $subtitle) = @_;
1218 # my $dbh = C4Connect;
1219 $subtitle = $dbh->quote($subtitle);
1220 my $query = "insert into bibliosubtitle set
1221 biblionumber = $bibnum,
1222 subtitle = $subtitle";
1223 my $sth = $dbh->prepare($query);
1233 my ($dbh,$item, $barcode) = @_;
1234 # my $dbh = C4Connect;
1235 my $query = "Select max(itemnumber) from items";
1236 my $sth = $dbh->prepare($query);
1242 $data = $sth->fetchrow_hashref;
1243 $itemnumber = $data->{'max(itemnumber)'} + 1;
1246 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
1247 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
1248 $item->{'price'} = $dbh->quote($item->{'price'});
1249 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
1250 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
1252 # foreach my $barcode (@barcodes) {
1253 # $barcode = uc($barcode);
1254 $barcode = $dbh->quote($barcode);
1255 $query = "Insert into items set
1256 itemnumber = $itemnumber,
1257 biblionumber = $item->{'biblionumber'},
1258 biblioitemnumber = $item->{'biblioitemnumber'},
1260 booksellerid = $item->{'booksellerid'},
1261 dateaccessioned = NOW(),
1262 homebranch = $item->{'homebranch'},
1263 holdingbranch = $item->{'homebranch'},
1264 price = $item->{'price'},
1265 replacementprice = $item->{'replacementprice'},
1266 replacementpricedate = NOW(),
1267 itemnotes = $item->{'itemnotes'}";
1268 if ($item->{'loan'}) {
1269 $query .= ",notforloan = $item->{'loan'}";
1272 $sth = $dbh->prepare($query);
1274 if (defined $sth->errstr) {
1275 $error .= $sth->errstr;
1280 return($itemnumber,$error);
1284 my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1285 # my $dbh=C4Connect;
1286 my $query="update items set biblioitemnumber=$bibitemnum,
1287 barcode='$barcode',itemnotes='$notes'
1288 where itemnumber=$itemnum";
1289 if ($barcode eq ''){
1290 $query="update items set biblioitemnumber=$bibitemnum,notforloan=$loan where itemnumber=$itemnum";
1293 $query="update items set biblioitemnumber=$bibitemnum,
1296 homebranch='$homebranch',
1298 wthdrawn='$wthdrawn'
1299 where itemnumber=$itemnum";
1301 if ($replacement ne ''){
1302 $query=~ s/ where/,replacementprice='$replacement' where/;
1305 my $sth=$dbh->prepare($query);
1312 my ($dbh,$itemnum)=@_;
1313 # my $dbh=C4Connect;
1314 my $query="select * from items where itemnumber=$itemnum";
1315 my $sth=$dbh->prepare($query);
1317 my @data=$sth->fetchrow_array;
1319 $query="Insert into deleteditems values (";
1320 foreach my $temp (@data){
1321 $query=$query."'$temp',";
1325 $sth=$dbh->prepare($query);
1328 $query = "Delete from items where itemnumber=$itemnum";
1329 $sth=$dbh->prepare($query);
1335 sub OLDdeletebiblioitem {
1336 my ($dbh,$biblioitemnumber) = @_;
1337 # my $dbh = C4Connect;
1338 my $query = "Select * from biblioitems
1339 where biblioitemnumber = $biblioitemnumber";
1340 my $sth = $dbh->prepare($query);
1345 if (@results = $sth->fetchrow_array) {
1346 $query = "Insert into deletedbiblioitems values (";
1347 foreach my $value (@results) {
1348 $value = $dbh->quote($value);
1349 $query .= "$value,";
1352 $query =~ s/\,$/\)/;
1355 $query = "Delete from biblioitems
1356 where biblioitemnumber = $biblioitemnumber";
1360 # Now delete all the items attached to the biblioitem
1361 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1362 $sth = $dbh->prepare($query);
1364 while (@results = $sth->fetchrow_array) {
1365 $query = "Insert into deleteditems values (";
1366 foreach my $value (@results) {
1367 $value = $dbh->quote($value);
1368 $query .= "$value,";
1370 $query =~ s/\,$/\)/;
1374 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1377 } # sub deletebiblioitem
1380 my ($dbh,$biblio)=@_;
1381 # my $dbh=C4Connect;
1382 my $query="select * from biblio where biblionumber=$biblio";
1383 my $sth=$dbh->prepare($query);
1385 if (my @data=$sth->fetchrow_array){
1387 $query="Insert into deletedbiblio values (";
1388 foreach my $temp (@data){
1389 $temp=~ s/\'/\\\'/g;
1390 $query=$query."'$temp',";
1394 $sth=$dbh->prepare($query);
1397 $query = "Delete from biblio where biblionumber=$biblio";
1398 $sth=$dbh->prepare($query);
1415 my $query="Select count(*) from items where biblionumber=$biblio";
1417 my $sth=$dbh->prepare($query);
1419 my $data=$sth->fetchrow_hashref;
1422 return($data->{'count(*)'});
1428 my $query="Select ordernumber
1430 where biblionumber=? and biblioitemnumber=?";
1431 my $sth=$dbh->prepare($query);
1432 $sth->execute($bib,$bi);
1433 my $ordnum=$sth->fetchrow_hashref;
1435 my $order=getsingleorder($ordnum->{'ordernumber'});
1438 return ($order,$ordnum->{'ordernumber'});
1441 sub getsingleorder {
1444 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1445 where aqorders.ordernumber=?
1446 and biblio.biblionumber=aqorders.biblionumber and
1447 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1448 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1449 my $sth=$dbh->prepare($query);
1450 $sth->execute($ordnum);
1451 my $data=$sth->fetchrow_hashref;
1459 my $dbh = &C4Connect;
1460 my $bibnum=OLDnewbiblio($dbh,$biblio);
1468 my $dbh = C4Connect;
1469 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1471 return($biblionumber);
1475 my ($bibnum, $subtitle) = @_;
1476 my $dbh = C4Connect;
1477 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1483 my ($bibnum, $author) = @_;
1484 my $dbh = C4Connect;
1485 &OLDmodaddauthor($dbh,$bibnum,$author);
1487 } # sub modaddauthor
1491 my ($bibnum, $force, @subject) = @_;
1492 my $dbh = C4Connect;
1493 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1498 my ($biblioitem) = @_;
1499 my $dbh = C4Connect;
1500 &OLDmodbibitem($dbh,$biblioitem);
1505 my ($bibitemnum,$note)=@_;
1507 &OLDmodnote($dbh,$bibitemnum,$note);
1512 my ($biblioitem) = @_;
1513 my $dbh = C4Connect;
1514 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1515 # print STDERR "bibitemnum : $bibitemnum\n";
1516 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1517 # print STDERR $MARCbiblio->as_formatted();
1518 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1519 return($bibitemnum);
1525 &OLDnewsubject($dbh,$bibnum);
1530 my ($bibnum, $subtitle) = @_;
1531 my $dbh = C4Connect;
1532 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1538 my ($item, @barcodes) = @_;
1539 my $dbh = C4Connect;
1543 foreach my $barcode (@barcodes) {
1544 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1552 my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1554 &OLDmoditem($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement);
1559 my ($count,@barcodes)=@_;
1562 for (my $i=0;$i<$count;$i++){
1563 $barcodes[$i]=uc $barcodes[$i];
1564 my $query="Select * from items where barcode='$barcodes[$i]'";
1565 my $sth=$dbh->prepare($query);
1567 if (my $data=$sth->fetchrow_hashref){
1568 $error.=" Duplicate Barcode: $barcodes[$i]";
1577 my ($bibitemnum)=@_;
1579 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1580 my $sth=$dbh->prepare($query);
1582 my $data=$sth->fetchrow_hashref;
1585 return($data->{'count(*)'});
1591 &OLDdelitem($dbh,$itemnum);
1595 sub deletebiblioitem {
1596 my ($biblioitemnumber) = @_;
1597 my $dbh = C4Connect;
1598 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1600 } # sub deletebiblioitem
1606 &OLDdelbiblio($dbh,$biblio);
1611 my $dbh = C4Connect;
1612 my $query = "select * from itemtypes";
1613 my $sth = $dbh->prepare($query);
1614 # || die "Cannot prepare $query" . $dbh->errstr;
1619 # || die "Cannot execute $query\n" . $sth->errstr;
1620 while (my $data = $sth->fetchrow_hashref) {
1621 $results[$count] = $data;
1627 return($count, @results);
1628 } # sub getitemtypes
1631 my ($biblionumber) = @_;
1632 my $dbh = C4Connect;
1633 my $query = "Select * from biblio where biblionumber = $biblionumber";
1634 my $sth = $dbh->prepare($query);
1635 # || die "Cannot prepare $query\n" . $dbh->errstr;
1640 # || die "Cannot execute $query\n" . $sth->errstr;
1641 while (my $data = $sth->fetchrow_hashref) {
1642 $results[$count] = $data;
1648 return($count, @results);
1652 my ($biblioitemnum) = @_;
1653 my $dbh = C4Connect;
1654 my $query = "Select * from biblioitems where
1655 biblioitemnumber = $biblioitemnum";
1656 my $sth = $dbh->prepare($query);
1662 while (my $data = $sth->fetchrow_hashref) {
1663 $results[$count] = $data;
1669 return($count, @results);
1670 } # sub getbiblioitem
1672 sub getbiblioitembybiblionumber {
1673 my ($biblionumber) = @_;
1674 my $dbh = C4Connect;
1675 my $query = "Select * from biblioitems where biblionumber =
1677 my $sth = $dbh->prepare($query);
1683 while (my $data = $sth->fetchrow_hashref) {
1684 $results[$count] = $data;
1690 return($count, @results);
1693 sub getitemsbybiblioitem {
1694 my ($biblioitemnum) = @_;
1695 my $dbh = C4Connect;
1696 my $query = "Select * from items, biblio where
1697 biblio.biblionumber = items.biblionumber and biblioitemnumber
1699 my $sth = $dbh->prepare($query);
1700 # || die "Cannot prepare $query\n" . $dbh->errstr;
1705 # || die "Cannot execute $query\n" . $sth->errstr;
1706 while (my $data = $sth->fetchrow_hashref) {
1707 $results[$count] = $data;
1713 return($count, @results);
1714 } # sub getitemsbybiblioitem
1718 my $dbh = C4Connect;
1724 $isbn = $dbh->quote($isbn);
1725 $query = "Select biblio.* from biblio, biblioitems where
1726 biblio.biblionumber = biblioitems.biblionumber
1728 $sth = $dbh->prepare($query);
1731 while (my $data = $sth->fetchrow_hashref) {
1732 $results[$count] = $data;
1738 return($count, @results);
1742 # At the moment this is just a straight copy of the subject code. Needs heavy
1743 # modification to work for additional authors, obviously.
1744 # Check for additional author changes
1746 # my $newadditionalauthor='';
1747 # my $additionalauthors;
1748 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
1749 # $additionalauthors->{$newadditionalauthor}=1;
1750 # if ($origadditionalauthors->{$newadditionalauthor}) {
1751 # $additionalauthors->{$newadditionalauthor}=2;
1753 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
1754 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
1756 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
1758 # $subfields->{1}->{'Subfield_Mark'}='a';
1759 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
1762 # foreach $Record_ID (@marcrecords) {
1763 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1764 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
1768 # my $origadditionalauthor;
1769 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
1770 # if ($additionalauthors->{$origadditionalauthor} == 1) {
1771 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
1772 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
1773 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
1783 # Subroutine to log changes to databases
1784 # Eventually, this subroutine will be used to create a log of all changes made,
1785 # with the possibility of "undo"ing some changes
1787 if ($database eq 'kohadb') {
1793 print STDERR "KOHA: $type $section $item $original $new\n";
1794 } elsif ($database eq 'marc') {
1796 my $Record_ID=shift;
1799 my $subfield_ID=shift;
1802 print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
1806 #------------------------------------------------
1809 #---------------------------------------
1810 # Find a biblio entry, or create a new one if it doesn't exist.
1811 # If a "subtitle" entry is in hash, add it to subtitle table
1812 sub getoraddbiblio {
1816 $biblio, # hash ref to fields
1827 requireDBI($dbh,"getoraddbiblio");
1829 print "<PRE>Looking for biblio </PRE>\n" if $debug;
1830 $sth=$dbh->prepare("select biblionumber
1832 where title=? and author=?
1833 and copyrightdate=? and seriestitle=?");
1835 $biblio->{title}, $biblio->{author},
1836 $biblio->{copyright}, $biblio->{seriestitle} );
1838 ($biblionumber) = $sth->fetchrow;
1839 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
1841 # Doesn't exist. Add new one.
1842 print "<PRE>Adding biblio</PRE>\n" if $debug;
1843 ($biblionumber,$error)=&newbiblio($biblio);
1844 if ( $biblionumber ) {
1845 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
1846 if ( $biblio->{subtitle} ) {
1847 &newsubtitle($biblionumber,$biblio->{subtitle} );
1850 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
1854 return $biblionumber,$error;
1856 } # sub getoraddbiblio
1860 # UNUSEFUL SUBs. Could be deleted, kept only until beta test
1861 # maybe useful for some MARC tricks steve used.
1864 sub OLD_MAYBE_DELETED_newBiblioItem {
1865 my ($env, $biblioitem) = @_;
1867 my $biblionumber=$biblioitem->{'biblionumber'};
1868 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
1869 my $volume=$biblioitem->{'volume'};
1870 my $q_volume=$dbh->quote($volume);
1871 my $number=$biblioitem->{'number'};
1872 my $q_number=$dbh->quote($number);
1873 my $classification=$biblioitem->{'classification'};
1874 my $q_classification=$dbh->quote($classification);
1875 my $itemtype=$biblioitem->{'itemtype'};
1876 my $q_itemtype=$dbh->quote($itemtype);
1877 my $isbn=$biblioitem->{'isbn'};
1878 my $q_isbn=$dbh->quote($isbn);
1879 my $issn=$biblioitem->{'issn'};
1880 my $q_issn=$dbh->quote($issn);
1881 my $dewey=$biblioitem->{'dewey'};
1883 ($dewey == 0) && ($dewey='');
1884 my $subclass=$biblioitem->{'subclass'};
1885 my $q_subclass=$dbh->quote($subclass);
1886 my $publicationyear=$biblioitem->{'publicationyear'};
1887 my $publishercode=$biblioitem->{'publishercode'};
1888 my $q_publishercode=$dbh->quote($publishercode);
1889 my $volumedate=$biblioitem->{'volumedate'};
1890 my $q_volumedate=$dbh->quote($volumedate);
1891 my $illus=$biblioitem->{'illus'};
1892 my $q_illus=$dbh->quote($illus);
1893 my $pages=$biblioitem->{'pages'};
1894 my $q_pages=$dbh->quote($pages);
1895 my $notes=$biblioitem->{'notes'};
1896 my $q_notes=$dbh->quote($notes);
1897 my $size=$biblioitem->{'size'};
1898 my $q_size=$dbh->quote($size);
1899 my $place=$biblioitem->{'place'};
1900 my $q_place=$dbh->quote($place);
1901 my $lccn=$biblioitem->{'lccn'};
1902 my $q_lccn=$dbh->quote($lccn);
1905 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
1908 unless ($env->{'marconly'}) {
1909 #my $sth=$dbh->prepare("lock tables biblioitems write");
1911 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
1913 my ($biblioitemnumber) =$sth->fetchrow;
1914 $biblioitemnumber++;
1915 $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)");
1917 #my $sth=$dbh->prepare("unlock tables");
1922 # Should we check if there is already a biblioitem/amrc with the
1923 # same isbn/lccn/issn?
1925 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
1927 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
1928 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
1930 my ($subtitle) = $sth->fetchrow;
1931 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
1933 my @additionalauthors;
1934 while (my ($additionalauthor) = $sth->fetchrow) {
1935 push (@additionalauthors, $additionalauthor);
1937 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
1940 while (my ($subject) = $sth->fetchrow) {
1941 push (@subjects, $subject);
1946 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
1948 my $Resource_ID=$dbh->{'mysql_insertid'};
1949 my $Record_ID=$Resource_ID;
1950 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
1956 $subfields->{1}->{'Subfield_Mark'}='a';
1957 $subfields->{1}->{'Subfield_Value'}=$title;
1959 $subfields->{2}->{'Subfield_Mark'}='b';
1960 $subfields->{2}->{'Subfield_Value'}=$subtitle;
1963 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1969 $subfields->{1}->{'Subfield_Mark'}='a';
1970 $subfields->{1}->{'Subfield_Value'}=$author;
1972 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1977 $subfields->{1}->{'Subfield_Mark'}='a';
1978 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
1980 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1985 $subfields->{1}->{'Subfield_Mark'}='a';
1986 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
1987 $subfields->{2}->{'Subfield_Mark'}='3';
1988 $subfields->{2}->{'Subfield_Value'}='biblio';
1990 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1992 # Additional Authors
1993 foreach (@additionalauthors) {
1995 (next) unless ($author);
1997 $subfields->{1}->{'Subfield_Mark'}='a';
1998 $subfields->{1}->{'Subfield_Value'}=$author;
1999 $subfields->{2}->{'Subfield_Mark'}='e';
2000 $subfields->{2}->{'Subfield_Value'}='author';
2002 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2006 (next) unless ($illus);
2008 $subfields->{1}->{'Subfield_Mark'}='a';
2009 $subfields->{1}->{'Subfield_Value'}=$illus;
2010 $subfields->{2}->{'Subfield_Mark'}='e';
2011 $subfields->{2}->{'Subfield_Value'}='illustrator';
2013 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2016 foreach (@subjects) {
2018 (next) unless ($subject);
2020 $subfields->{1}->{'Subfield_Mark'}='a';
2021 $subfields->{1}->{'Subfield_Value'}=$subject;
2023 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2030 $subfields->{1}->{'Subfield_Mark'}='a';
2031 $subfields->{1}->{'Subfield_Value'}=$isbn;
2033 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2038 $subfields->{1}->{'Subfield_Mark'}='a';
2039 $subfields->{1}->{'Subfield_Value'}=$lccn;
2041 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2046 $subfields->{1}->{'Subfield_Mark'}='a';
2047 $subfields->{1}->{'Subfield_Value'}=$issn;
2049 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2054 $subfields->{1}->{'Subfield_Mark'}='a';
2055 $subfields->{1}->{'Subfield_Value'}=$dewey;
2057 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2059 # DEWEY subclass and itemtype
2062 $subfields->{1}->{'Subfield_Mark'}='a';
2063 $subfields->{1}->{'Subfield_Value'}=$itemtype;
2064 $subfields->{2}->{'Subfield_Mark'}='b';
2065 $subfields->{2}->{'Subfield_Value'}=$subclass;
2066 $subfields->{3}->{'Subfield_Mark'}='c';
2067 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
2068 $subfields->{4}->{'Subfield_Mark'}='d';
2069 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
2071 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2076 $subfields->{1}->{'Subfield_Mark'}='a';
2077 $subfields->{1}->{'Subfield_Value'}=$place;
2078 $subfields->{2}->{'Subfield_Mark'}='b';
2079 $subfields->{2}->{'Subfield_Value'}=$publishercode;
2080 $subfields->{3}->{'Subfield_Mark'}='c';
2081 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
2082 if ($copyrightdate) {
2083 $subfields->{4}->{'Subfield_Mark'}='c';
2084 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
2087 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2090 if ($pages || $size) {
2092 $subfields->{1}->{'Subfield_Mark'}='a';
2093 $subfields->{1}->{'Subfield_Value'}=$pages;
2094 $subfields->{2}->{'Subfield_Mark'}='c';
2095 $subfields->{2}->{'Subfield_Value'}=$size;
2097 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2100 if ($volume || $number) {
2102 $subfields->{1}->{'Subfield_Mark'}='v';
2103 $subfields->{1}->{'Subfield_Value'}=$volume;
2104 $subfields->{2}->{'Subfield_Mark'}='n';
2105 $subfields->{2}->{'Subfield_Value'}=$number;
2107 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2112 $subfields->{1}->{'Subfield_Mark'}='a';
2113 $subfields->{1}->{'Subfield_Value'}=$notes;
2114 $subfields->{2}->{'Subfield_Mark'}='3';
2115 $subfields->{2}->{'Subfield_Value'}='biblioitem';
2117 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2121 return ($env, $Record_ID);
2124 sub OLD_MAYBE_DELETED_newItem {
2125 my ($env, $Record_ID, $item) = @_;
2127 my $barcode=$item->{'barcode'};
2128 my $q_barcode=$dbh->quote($barcode);
2129 my $biblionumber=$item->{'biblionumber'};
2130 my $biblioitemnumber=$item->{'biblioitemnumber'};
2131 my $dateaccessioned=$item->{'dateaccessioned'};
2132 my $booksellerid=$item->{'booksellerid'};
2133 my $q_booksellerid=$dbh->quote($booksellerid);
2134 my $homebranch=$item->{'homebranch'};
2135 my $q_homebranch=$dbh->quote($homebranch);
2136 my $holdingbranch=$item->{'holdingbranch'};
2137 my $price=$item->{'price'};
2138 my $replacementprice=$item->{'replacementprice'};
2139 my $replacementpricedate=$item->{'replacementpricedate'};
2140 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
2141 my $notforloan=$item->{'notforloan'};
2142 my $itemlost=$item->{'itemlost'};
2143 my $wthdrawn=$item->{'wthdrawn'};
2144 my $restricted=$item->{'restricted'};
2145 my $itemnotes=$item->{'itemnotes'};
2146 my $q_itemnotes=$dbh->quote($itemnotes);
2147 my $itemtype=$item->{'itemtype'};
2148 my $subclass=$item->{'subclass'};
2152 unless ($env->{'marconly'}) {
2153 my $sth=$dbh->prepare("select max(itemnumber) from items");
2155 my ($itemnumber) =$sth->fetchrow;
2157 $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)");
2164 $subfields->{1}->{'Subfield_Mark'}='p';
2165 $subfields->{1}->{'Subfield_Value'}=$barcode;
2166 $subfields->{2}->{'Subfield_Mark'}='d';
2167 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
2168 $subfields->{3}->{'Subfield_Mark'}='e';
2169 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
2170 $subfields->{4}->{'Subfield_Mark'}='b';
2171 $subfields->{4}->{'Subfield_Value'}=$homebranch;
2172 $subfields->{5}->{'Subfield_Mark'}='l';
2173 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
2174 $subfields->{6}->{'Subfield_Mark'}='c';
2175 $subfields->{6}->{'Subfield_Value'}=$price;
2176 $subfields->{7}->{'Subfield_Mark'}='c';
2177 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
2178 $subfields->{8}->{'Subfield_Mark'}='d';
2179 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
2181 $subfields->{9}->{'Subfield_Mark'}='h';
2182 $subfields->{9}->{'Subfield_Value'}='Not for loan';
2185 $subfields->{10}->{'Subfield_Mark'}='j';
2186 $subfields->{10}->{'Subfield_Value'}='Item lost';
2189 $subfields->{11}->{'Subfield_Mark'}='j';
2190 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
2193 $subfields->{12}->{'Subfield_Mark'}='z';
2194 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
2198 $env->{'linkage'}=1;
2199 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2200 $env->{'linkage'}=0;
2201 $env->{'linkid'}=$Tag_ID;
2204 $subfields2->{1}->{'Subfield_Mark'}='a';
2205 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
2206 $subfields2->{1}->{'Subfield_Mark'}='b';
2207 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
2208 $subfields2->{1}->{'Subfield_Mark'}='c';
2209 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
2210 $subfields2->{2}->{'Subfield_Mark'}='m';
2211 $subfields2->{2}->{'Subfield_Value'}=$subclass;
2212 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
2213 $env->{'linkid'}='';
2216 sub OLD_MAYBE_DELETED_updateBiblio {
2217 # Update the biblio with biblionumber $biblio->{'biblionumber'}
2218 # I guess this routine should search through all marc records for a record that
2219 # has the same biblionumber stored in it, and modify the MARC record as well as
2222 # Also, this subroutine should search through the $biblio object and compare it
2223 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
2224 # this logging feature to be usable to undo changes easily.
2226 my ($env, $biblio) = @_;
2228 my $biblionumber=$biblio->{'biblionumber'};
2230 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
2232 my $origbiblio=$sth->fetchrow_hashref;
2233 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2235 my ($subtitle)=$sth->fetchrow;
2236 $origbiblio->{'subtitle'}=$subtitle;
2237 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2239 my $origadditionalauthors;
2240 while (my ($author) = $sth->fetchrow) {
2241 push (@{$origbiblio->{'additionalauthors'}}, $author);
2242 $origadditionalauthors->{$author}=1;
2244 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2247 while (my ($subject) = $sth->fetchrow) {
2248 push (@{$origbiblio->{'subjects'}}, $subject);
2249 $origsubjects->{$subject}=1;
2253 # Obtain a list of MARC Record_ID's that are tied to this biblio
2254 $sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
2257 while (my ($bibid) = $sth->fetchrow) {
2258 push(@marcrecords, $bibid);
2262 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
2263 my $q_author=$dbh->quote($biblio->{'author'});
2264 logchange('kohadb', 'change', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
2265 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
2267 foreach $bibid (@marcrecords) {
2268 logchange('marc', 'change', $bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2269 changeSubfield($bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2272 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
2273 my $q_title=$dbh->quote($biblio->{'title'});
2274 logchange('kohadb', 'change', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
2275 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
2277 foreach $Record_ID (@marcrecords) {
2278 logchange('marc', 'change', $Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2279 changeSubfield($Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2282 if ($biblio->{'subtitle'} ne $origbiblio->{'subtitle'}) {
2283 my $q_subtitle=$dbh->quote($biblio->{'subtitle'});
2284 logchange('kohadb', 'change', 'biblio', 'subtitle', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2285 my $sti=$dbh->prepare("update bibliosubtitle set subtitle=$q_subtitle where biblionumber=$biblio->{'biblionumber'}");
2287 foreach $Record_ID (@marcrecords) {
2288 logchange('marc', 'change', $Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2289 changeSubfield($Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2292 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
2293 my $q_unititle=$dbh->quote($biblio->{'unititle'});
2294 logchange('kohadb', 'change', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
2295 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
2298 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
2299 my $q_notes=$dbh->quote($biblio->{'notes'});
2300 logchange('kohadb', 'change', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
2301 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
2303 foreach $Record_ID (@marcrecords) {
2304 logchange('marc', 'change', $Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2305 changeSubfield($Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2308 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
2309 my $q_serial=$dbh->quote($biblio->{'serial'});
2310 logchange('kohadb', 'change', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
2311 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
2314 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
2315 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
2316 logchange('kohadb', 'change', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2317 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
2319 foreach $Record_ID (@marcrecords) {
2320 logchange('marc', 'change', $Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2321 changeSubfield($Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2324 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
2325 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
2326 logchange('kohadb', 'change', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
2327 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
2329 foreach $Record_ID (@marcrecords) {
2330 logchange('marc', 'change', $Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2331 changeSubfield($Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2335 # Check for subject heading changes
2339 foreach $newsubject (@{$biblio->{'subject'}}) {
2340 $subjects->{$newsubject}=1;
2341 if ($origsubjects->{$newsubject}) {
2342 $subjects->{$newsubject}=2;
2344 my $q_newsubject=$dbh->quote($newsubject);
2345 my $sth=$dbh->prepare("insert into bibliosubject (subject,biblionumber) values ($q_newsubject, $biblionumber)");
2347 logchange('kohadb', 'add', 'biblio', 'subject', $newsubject);
2349 $subfields->{1}->{'Subfield_Mark'}='a';
2350 $subfields->{1}->{'Subfield_Value'}=$newsubject;
2353 foreach $Record_ID (@marcrecords) {
2354 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2355 logchange('marc', 'add', $Record_ID, '650', 'a', $newsubject);
2360 foreach $origsubject (keys %$origsubjects) {
2361 if ($subjects->{$origsubject} == 1) {
2362 my $q_origsubject=$dbh->quote($origsubject);
2363 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'subject', $origsubject);
2364 my $sth=$dbh->prepare("delete from bibliosubject where biblionumber=$biblionumber and subject=$q_origsubject");
2370 sub OLD_MAYBE_DELETED_updateBiblioItem {
2371 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
2373 # This routine should also check to see which fields are actually being
2374 # modified, and log all changes.
2376 my ($env, $biblioitem) = @_;
2379 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2380 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
2381 # obi = original biblioitem
2382 my $obi=$sth->fetchrow_hashref;
2383 $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");
2385 my ($Record_ID) = $sth->fetchrow;
2386 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
2387 logchange('kohadb', 'change', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2388 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
2389 logchange('marc', 'change', $Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2390 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2392 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
2393 logchange('kohadb', 'change', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
2394 my $q_volume=$dbh->quote($biblioitem->{'volume'});
2395 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
2396 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2397 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2399 if ($biblioitem->{'number'} ne $obi->{'number'}) {
2400 logchange('kohadb', 'change', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
2401 my $q_number=$dbh->quote($biblioitem->{'number'});
2402 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
2403 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2404 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2406 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
2407 logchange('kohadb', 'change', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2408 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
2409 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
2410 logchange('marc', 'change', $Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2411 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2413 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
2414 logchange('kohadb', 'change', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
2415 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
2416 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
2417 logchange('marc', 'change', $Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2418 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2420 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
2421 logchange('kohadb', 'change', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
2422 my $q_issn=$dbh->quote($biblioitem->{'issn'});
2423 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
2424 logchange('marc', 'change', $Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2425 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2427 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
2428 logchange('kohadb', 'change', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
2429 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
2430 logchange('marc', 'change', $Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2431 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2433 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
2434 logchange('kohadb', 'change', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
2435 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
2436 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
2437 logchange('marc', 'change', $Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2438 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2440 if ($biblioitem->{'place'} ne $obi->{'place'}) {
2441 logchange('kohadb', 'change', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
2442 my $q_place=$dbh->quote($biblioitem->{'place'});
2443 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
2444 logchange('marc', 'change', $Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2445 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2447 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
2448 logchange('kohadb', 'change', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2449 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
2450 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
2451 logchange('marc', 'change', $Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2452 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2454 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
2455 logchange('kohadb', 'change', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2456 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
2457 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
2458 logchange('marc', 'change', $Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2459 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2461 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
2462 logchange('kohadb', 'change', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
2463 my $q_illus=$dbh->quote($biblioitem->{'illus'});
2464 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
2465 logchange('marc', 'change', $Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2466 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2468 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
2469 logchange('kohadb', 'change', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
2470 my $q_pages=$dbh->quote($biblioitem->{'pages'});
2471 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
2472 logchange('marc', 'change', $Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2473 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2475 if ($biblioitem->{'size'} ne $obi->{'size'}) {
2476 logchange('kohadb', 'change', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
2477 my $q_size=$dbh->quote($biblioitem->{'size'});
2478 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
2479 logchange('marc', 'change', $Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2480 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2482 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
2483 logchange('kohadb', 'change', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
2484 my $q_notes=$dbh->quote($biblioitem->{'notes'});
2485 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
2486 logchange('marc', 'change', $Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2487 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2489 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
2490 logchange('kohadb', 'change', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
2491 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
2492 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
2493 logchange('marc', 'change', $Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2494 changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2501 sub OLD_MAYBE_DELETED_updateItem {
2502 # Update the item with itemnumber $item->{'itemnumber'}
2503 # This routine should also modify the corresponding MARC record data. (852 and
2504 # 876 tags with 876p tag the same as $item->{'barcode'}
2506 # This routine should also check to see which fields are actually being
2507 # modified, and log all changes.
2509 my ($env, $item) = @_;
2511 my $itemnumber=$item->{'itemnumber'};
2512 my $biblionumber=$item->{'biblionumber'};
2513 my $biblioitemnumber=$item->{'biblioitemnumber'};
2514 my $barcode=$item->{'barcode'};
2515 my $dateaccessioned=$item->{'dateaccessioned'};
2516 my $booksellerid=$item->{'booksellerid'};
2517 my $homebranch=$item->{'homebranch'};
2518 my $price=$item->{'price'};
2519 my $replacementprice=$item->{'replacementprice'};
2520 my $replacementpricedate=$item->{'replacementpricedate'};
2521 my $multivolume=$item->{'multivolume'};
2522 my $stack=$item->{'stack'};
2523 my $notforloan=$item->{'notforloan'};
2524 my $itemlost=$item->{'itemlost'};
2525 my $wthdrawn=$item->{'wthdrawn'};
2526 my $bulk=$item->{'bulk'};
2527 my $restricted=$item->{'restricted'};
2528 my $binding=$item->{'binding'};
2529 my $itemnotes=$item->{'itemnotes'};
2530 my $holdingbranch=$item->{'holdingbranch'};
2531 my $interim=$item->{'interim'};
2532 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
2534 my $olditem=$sth->fetchrow_hashref;
2535 my $q_barcode=$dbh->quote($olditem->{'barcode'});
2536 $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");
2538 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
2539 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
2541 my ($link) = $sth->fetchrow;
2542 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
2544 my ($Subfield852_ID) = $sth->fetchrow;
2546 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
2547 logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
2548 my $q_barcode=$dbh->quote($item->{'barcode'});
2549 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
2551 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
2552 logchange('marc', 'change', $Record_ID, '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
2554 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
2555 logchange('kohadb', 'change', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
2556 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
2557 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
2559 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
2560 logchange('marc', 'change', $Record_ID, '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
2562 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
2563 logchange('kohadb', 'change', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2564 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
2565 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
2567 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
2568 logchange('marc', 'change', $Record_ID, '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2570 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
2571 logchange('kohadb', 'change', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
2572 my $q_homebranch=$dbh->quote($item->{'homebranch'});
2573 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
2575 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
2576 logchange('marc', 'change', $Record_ID, '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
2578 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
2579 logchange('kohadb', 'change', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2580 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
2581 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
2583 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
2584 logchange('marc', 'change', $Record_ID, '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2586 if ($item->{'price'} ne $olditem->{'price'}) {
2587 logchange('kohadb', 'change', 'items', 'price', $olditem->{'price'}, $item->{'price'});
2588 my $q_price=$dbh->quote($item->{'price'});
2589 my $sth=$dbh->prepare("update items set price=$q_price where itemnumber=$itemnumber");
2591 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'price'}, $item->{'price'}, $Subfield876_ID);
2592 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'price'}, $item->{'price'});
2594 if ($item->{'itemnotes'} ne $olditem->{'itemnotes'}) {
2595 logchange('kohadb', 'change', 'items', 'itemnotes', $olditem->{'itemnotes'}, $item->{'itemnotes'});
2596 my $q_itemnotes=$dbh->quote($item->{'itemnotes'});
2597 my $sth=$dbh->prepare("update items set itemnotes=$q_itemnotes where itemnumber=$itemnumber");
2599 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'itemnotes'}, $item->{'itemnotes'}, $Subfield876_ID);
2600 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'itemnotes'}, $item->{'itemnotes'});
2602 if ($item->{'notforloan'} ne $olditem->{'notforloan'}) {
2603 logchange('kohadb', 'change', 'items', 'notforloan', $olditem->{'notforloan'}, $item->{'notforloan'});
2604 my $sth=$dbh->prepare("update items set notforloan=$notforloan where itemnumber=$itemnumber");
2606 if ($item->{'notforloan'}) {
2607 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2608 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2610 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2611 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2614 if ($item->{'itemlost'} ne $olditem->{'itemlost'}) {
2615 logchange('kohadb', 'change', 'items', 'itemlost', $olditem->{'itemlost'}, $item->{'itemlost'});
2616 my $sth=$dbh->prepare("update items set itemlost=$itemlost where itemnumber=$itemnumber");
2618 if ($item->{'itemlost'}) {
2619 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2620 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2622 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2623 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2626 if ($item->{'wthdrawn'} ne $olditem->{'wthdrawn'}) {
2627 logchange('kohadb', 'change', 'items', 'wthdrawn', $olditem->{'wthdrawn'}, $item->{'wthdrawn'});
2628 my $sth=$dbh->prepare("update items set wthdrawn=$wthdrawn where itemnumber=$itemnumber");
2630 if ($item->{'wthdrawn'}) {
2631 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2632 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2634 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2635 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2638 if ($item->{'restricted'} ne $olditem->{'restricted'}) {
2639 logchange('kohadb', 'change', 'items', 'restricted', $olditem->{'restricted'}, $item->{'restricted'});
2640 my $sth=$dbh->prepare("update items set restricted=$restricted where itemnumber=$itemnumber");
2642 if ($item->{'restricted'}) {
2643 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2644 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2646 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2647 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2654 # Add a biblioitem and related data to Koha database
2655 sub OLD_MAY_BE_DELETED_newcompletebiblioitem {
2660 $biblio, # hash ref to biblio record
2661 $biblioitem, # hash ref to biblioitem record
2662 $subjects, # list ref of subjects
2663 $addlauthors, # list ref of additional authors
2666 my ( $biblionumber, $biblioitemnumber, $error); # return values
2671 my $additionalauthor;
2674 requireDBI($dbh,"newcompletebiblioitem");
2676 print "<PRE>Trying to add biblio item Title=$biblio->{title} " .
2677 "ISBN=$biblioitem->{isbn} </PRE>\n" if $debug;
2679 # Make sure master biblio entry exists
2680 ($biblionumber,$error)=getoraddbiblio($dbh, $biblio);
2684 $biblioitem->{biblionumber}=$biblionumber;
2687 $biblioitemnumber=newbiblioitem($biblioitem);
2690 $sth=$dbh->prepare("insert into bibliosubject
2691 (biblionumber,subject)
2693 foreach $subjectheading (@{$subjects} ) {
2694 $sth->execute($biblionumber, $subjectheading)
2695 or $error.=$sth->errstr ;
2699 # Add additional authors
2700 $sth=$dbh->prepare("insert into additionalauthors
2701 (biblionumber,author)
2703 foreach $additionalauthor (@{$addlauthors} ) {
2704 $sth->execute($biblionumber, $additionalauthor)
2705 or $error.=$sth->errstr ;
2709 # couldn't get biblio
2711 $biblioitemnumber='';
2713 } # if no biblio error
2715 return ( $biblionumber, $biblioitemnumber, $error);
2717 } # sub newcompletebiblioitem
2721 # END OF UNUSEFUL SUBs
2725 END { } # module clean-up code here (global destructor)