4 # Revision 1.13 2002/10/02 16:26:44 tipaul
7 # Revision 1.12 2002/10/01 11:48:51 arensb
8 # Added some FIXME comments, mostly marking duplicate functions.
10 # Revision 1.11 2002/09/24 13:49:26 tipaul
11 # long WAS the road to 1.3.0...
12 # coming VERY SOON NOW...
13 # modifying installer and buildrelease to update the DB
15 # Revision 1.10 2002/09/22 16:50:08 arensb
16 # Added some FIXME comments.
18 # Revision 1.9 2002/09/20 12:57:46 tipaul
19 # long is the road to 1.4.0
20 # * MARCadditem and MARCmoditem now wroks
21 # * various bugfixes in MARC management
22 # !!! 1.3.0 should be released very soon now. Be careful !!!
24 # Revision 1.8 2002/09/10 13:53:52 tipaul
25 # MARC API continued...
27 # * multiple item management : MARCadditem and MARCmoditem have been added. They suppose that ALL the MARC field linked to koha-item are in the same MARC tag (on the same line of MARC file)
29 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
31 # Revision 1.7 2002/08/14 18:12:51 tonnesen
32 # Added copyright statement to all .pl and .pm files
34 # Revision 1.6 2002/07/25 13:40:31 tipaul
35 # pod documenting the API.
37 # Revision 1.5 2002/07/24 16:11:37 tipaul
39 # Database.pm and Output.pm are almost not modified (var test...)
41 # Biblio.pm is almost completly rewritten.
43 # WHAT DOES IT ??? ==> END of Hitchcock suspens
45 # 1st, it does... nothing...
46 # 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 ...
48 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
49 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
50 # * 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.
51 # * 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.
52 # 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 ;-)
54 # 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.
55 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
59 # move from 1.2 to 1.4 version :
60 # 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
61 # In the 1.4 version, we want to do 2 differents things :
62 # - keep populating the old-DB, that has a LOT less datas than MARC
63 # - populate the MARC-DB
64 # To populate the DBs we have 2 differents sources :
65 # - the standard acquisition system (through book sellers), that does'nt use MARC data
66 # - the MARC acquisition system, that uses MARC data.
68 # thus, we have 2 differents cases :
69 # - 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
70 # - 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.
71 # we MUST have an API for true MARC data, that populate MARC-DB then old-DB
73 # That's why we need 4 subs :
74 # all subs beginning by MARC manage only MARC tables. They manage MARC-DB with MARC::Record parameters
75 # all subs beginning by OLD manage only OLD-DB tables. They manage old-DB with old-DB parameters
76 # 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
77 # 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.
79 # only ALL and old-style API should be used in koha. MARC and OLD is used internally only
81 # 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.
82 # 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 ;-)
86 # Copyright 2000-2002 Katipo Communications
88 # This file is part of Koha.
90 # Koha is free software; you can redistribute it and/or modify it under the
91 # terms of the GNU General Public License as published by the Free Software
92 # Foundation; either version 2 of the License, or (at your option) any later
95 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
96 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
97 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
99 # You should have received a copy of the GNU General Public License along with
100 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
101 # Suite 330, Boston, MA 02111-1307 USA
108 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
110 # set the version for version checking
115 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
116 # as the old-style API and the ALL one are the only public functions.
119 &updateBiblio &updateBiblioItem &updateItem
120 &itemcount &newbiblio &newbiblioitem
121 &modnote &newsubject &newsubtitle
122 &modbiblio &checkitems
123 &newitems &modbibitem
124 &modsubtitle &modsubject &modaddauthor &moditem &countitems
125 &delitem &deletebiblioitem &delbiblio
126 &getitemtypes &getbiblio
127 &getbiblioitembybiblionumber
128 &getbiblioitem &getitemsbybiblioitem &isbnsearch
130 &newcompletebiblioitem
132 &MARCfind_oldbiblionumber_from_MARCbibid
133 &MARCfind_MARCbibid_from_oldbiblionumber
135 &ALLnewbiblio &ALLnewitem
138 &MARCaddbiblio &MARCadditem
139 &MARCmodsubfield &MARCaddsubfield
140 &MARCmodbiblio &MARCmoditem
142 &MARCkoha2marcBiblio &MARCmarc2koha &MARCkoha2marcItem
143 &MARCgetbiblio &MARCgetitem
144 &MARCaddword &MARCdelword
149 # your exported package globals go here,
150 # as well as any optionally exported functions
152 @EXPORT_OK = qw($Var1 %Hashit);
156 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
159 # all the following subs takes a MARC::Record as parameter and manage
160 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
161 # ALLxxx subs (xxx deals with old-DB parameters, the ALLxxx deals with MARC-DB parameter)
166 all subs requires/use $dbh as 1st parameter.
167 NOTE : all those subs are private and must be used only inside Biblio.pm (called by a old API sub, or the ALLsub)
171 =head2 @tagslib = &MARCgettagslib($dbh,1|0);
172 last param is 1 for liblibrarian and 0 for libopac
173 returns a hash with tag/subfield meaning
175 =head2 ($tagfield,$tagsubfield) = &MARCfindmarc_from_kohafield($dbh,$kohafield);
176 finds MARC tag and subfield for a given kohafield
177 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
179 =head2 $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
180 finds a old-db biblio number for a given MARCbibid number
182 =head2 $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
183 finds a MARC bibid from a old-db biblionumber
185 =head2 &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
186 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
188 =head2 &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
189 adds a subfield in a biblio (in the MARC tables only).
191 =head2 $MARCRecord = &MARCgetbiblio($dbh,$bibid);
192 Returns a MARC::Record for the biblio $bibid.
194 =head2 &MARCmodbiblio($dbh,$bibid,$delete,$record);
195 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
196 if $delete == 1, every field/subfield not found is deleted in the biblio
197 otherwise, only data passed to MARCmodbiblio is managed.
198 thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
200 =head2 ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
201 MARCmodsubfield changes the value of a given subfield
203 =head2 $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
204 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
205 Returns -1 if more than 1 answer
207 =head2 $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
208 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
210 =head2 &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
211 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
213 =head2 &MARCdelbiblio($dbh,$bibid);
214 MARCdelbiblio delete biblio $bibid
216 =head2 $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
217 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
219 =head2 $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
220 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
222 =head2 $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
223 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
225 =head2 &MARCkoha2marcOnefield => used by MARCkoha2marc and should not be useful elsewhere
227 =head2 $olddb = &MARCmarc2koha($dbh,$MARCRecord);
228 builds a hash with old-db datas from a MARC::Record
230 =head2 &MARCmarc2kohaOnefield => used by MARCmarc2koha and should not be useful elsewhere
232 =head2 MARCaddword => used to manage MARC_word table and should not be useful elsewhere
234 =head2 MARCdelword => used to manage MARC_word table and should not be useful elsewhere
238 Paul POULAIN paul.poulain@free.fr
243 my ($dbh,$forlibrarian)= @_;
245 if ($forlibrarian eq 1) {
246 $sth=$dbh->prepare("select tagfield,liblibrarian as lib from marc_tag_structure");
248 $sth=$dbh->prepare("select tagfield,libopac as lib from marc_tag_structure");
252 while ( ($tag,$lib) = $sth->fetchrow) {
253 $res->{$tag}->{lib}=$lib;
256 if ($forlibrarian eq 1) {
257 $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib from marc_subfield_structure");
259 $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib from marc_subfield_structure");
264 while ( ($tag,$subfield,$lib) = $sth->fetchrow) {
265 $res->{$tag}->{$subfield}=$lib;
270 sub MARCfind_marc_from_kohafield {
271 my ($dbh,$kohafield) = @_;
272 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
273 $sth->execute($kohafield);
274 my ($tagfield,$tagsubfield) = $sth->fetchrow;
275 return ($tagfield,$tagsubfield);
278 sub MARCfind_oldbiblionumber_from_MARCbibid {
279 my ($dbh,$MARCbibid) = @_;
280 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
281 $sth->execute($MARCbibid);
282 my ($biblionumber) = $sth->fetchrow;
283 return $biblionumber;
286 sub MARCfind_MARCbibid_from_oldbiblionumber {
287 my ($dbh,$oldbiblionumber) = @_;
288 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
289 $sth->execute($oldbiblionumber);
290 my ($bibid) = $sth->fetchrow;
295 # pass the MARC::Record to this function, and it will create the records in the marc tables
296 my ($dbh,$record,$biblionumber) = @_;
297 my @fields=$record->fields();
299 # adding main table, and retrieving bibid
300 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
301 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
302 $sth->execute($biblionumber);
303 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
305 ($bibid)=$sth->fetchrow;
308 # now, add subfields...
309 foreach my $field (@fields) {
310 my @subfields=$field->subfields();
312 foreach my $subfieldcount (0..$#subfields) {
313 &MARCaddsubfield($dbh,$bibid,
315 $field->indicator(1).$field->indicator(2),
317 $subfields[$subfieldcount][0],
319 $subfields[$subfieldcount][1]
323 $dbh->do("unlock tables");
328 # pass the MARC::Record to this function, and it will create the records in the marc tables
329 my ($dbh,$record,$biblionumber) = @_;
330 # search for MARC biblionumber
331 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
332 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
333 my @fields=$record->fields();
334 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
335 $sth->execute($bibid);
336 my ($fieldcount) = $sth->fetchrow;
337 # now, add subfields...
338 foreach my $field (@fields) {
339 my @subfields=$field->subfields();
341 foreach my $subfieldcount (0..$#subfields) {
342 &MARCaddsubfield($dbh,$bibid,
344 $field->indicator(1).$field->indicator(2),
346 $subfields[$subfieldcount][0],
348 $subfields[$subfieldcount][1]
352 $dbh->do("unlock tables");
356 sub MARCaddsubfield {
357 # Add a new subfield to a tag into the DB.
358 my ($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
359 # if not value, end of job, we do nothing
360 if (not($subfieldvalue)) {
363 if (not($subfieldcode)) {
366 if (length($subfieldvalue)>255) {
367 # $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
368 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
369 $sth->execute($subfieldvalue);
370 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
372 my ($res)=$sth->fetchrow;
373 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?)");
375 $sth->execute($bibid,'0'.$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
377 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
380 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
382 # $dbh->do("unlock tables");
384 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?)");
385 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
387 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
390 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
395 # Returns MARC::Record of the biblio passed in parameter.
397 my $record = MARC::Record->new();
398 #---- TODO : the leader is missing
399 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
400 from marc_subfield_table
401 where bibid=? order by tagorder,subfieldorder
403 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
404 $sth->execute($bibid);
405 while (my $row=$sth->fetchrow_hashref) {
406 if ($row->{'valuebloblink'}) { #---- search blob if there is one
407 $sth2->execute($row->{'valuebloblink'});
408 my $row2=$sth2->fetchrow_hashref;
410 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
412 if ($record->field($row->{'tag'})) {
414 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
415 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
416 if (length($row->{'tag'}) <3) {
417 $row->{'tag'} = "0".$row->{'tag'};
419 $field =$record->field($row->{'tag'});
421 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
422 $record->delete_field($field);
423 $record->add_fields($field);
426 if (length($row->{'tag'}) < 3) {
427 $row->{'tag'} = "0".$row->{'tag'};
429 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
430 $record->add_fields($temp);
437 # Returns MARC::Record of the biblio passed in parameter.
438 my ($dbh,$bibid,$itemnumber)=@_;
439 warn "MARCgetitem : $bibid, $itemnumber\n";
440 my $record = MARC::Record->new();
441 # search MARC tagorder
442 my $sth2 = $dbh->prepare("select tagorder from marc_subfield_table,marc_subfield_structure where marc_subfield_table.tag=marc_subfield_structure.tagfield and marc_subfield_table.subfieldcode=marc_subfield_structure.tagsubfield and bibid=? and kohafield='items.itemnumber' and subfieldvalue=?");
443 $sth2->execute($bibid,$itemnumber);
444 my ($tagorder) = $sth2->fetchrow_array();
445 #---- TODO : the leader is missing
446 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
447 from marc_subfield_table
448 where bibid=? and tagorder=? order by subfieldorder
450 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
451 $sth->execute($bibid,$tagorder);
452 while (my $row=$sth->fetchrow_hashref) {
453 if ($row->{'valuebloblink'}) { #---- search blob if there is one
454 $sth2->execute($row->{'valuebloblink'});
455 my $row2=$sth2->fetchrow_hashref;
457 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
459 if ($record->field($row->{'tag'})) {
461 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
462 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
463 if (length($row->{'tag'}) <3) {
464 $row->{'tag'} = "0".$row->{'tag'};
466 $field =$record->field($row->{'tag'});
468 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
469 $record->delete_field($field);
470 $record->add_fields($field);
473 if (length($row->{'tag'}) < 3) {
474 $row->{'tag'} = "0".$row->{'tag'};
476 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
477 $record->add_fields($temp);
485 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
486 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
487 # if nothing to change, don't waste time...
488 if ($oldrecord eq $record) {
491 # otherwise, skip through each subfield...
492 my @fields = $record->fields();
494 foreach my $field (@fields) {
495 my $oldfield = $oldrecord->field($field->tag());
496 my @subfields=$field->subfields();
499 foreach my $subfield (@subfields) {
501 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
502 # just adding datas...
503 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
504 1,@$subfield[0],$subfieldorder,@$subfield[1]);
506 # modify he subfield if it's a different string
507 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
508 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
509 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
517 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
518 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
519 # if nothing to change, don't waste time...
520 if ($oldrecord eq $record) {
523 # otherwise, skip through each subfield...
524 my @fields = $record->fields();
525 # search old MARC item
526 my $sth2 = $dbh->prepare("select tagorder from marc_subfield_table,marc_subfield_structure where marc_subfield_table.tag=marc_subfield_structure.tagfield and marc_subfield_table.subfieldcode=marc_subfield_structure.tagsubfield and bibid=? and kohafield='items.itemnumber' and subfieldvalue=?");
527 $sth2->execute($bibid,$itemnumber);
528 my ($tagorder) = $sth2->fetchrow_array();
529 foreach my $field (@fields) {
530 my $oldfield = $oldrecord->field($field->tag());
531 my @subfields=$field->subfields();
533 foreach my $subfield (@subfields) {
535 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
536 # just adding datas...
537 warn "ADD = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
538 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
539 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
541 # modify he subfield if it's a different string
542 warn "MODIFY = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
543 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
544 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
545 warn "MODIFY2 = $bibid, $subfieldid, ".@$subfield[1]."\n";
546 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
555 sub MARCmodsubfield {
556 # Subroutine changes a subfield value given a subfieldid.
557 my ($dbh, $subfieldid, $subfieldvalue )=@_;
558 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
559 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
560 $sth1->execute($subfieldid);
561 my ($oldvaluebloblink)=$sth1->fetchrow;
564 # if too long, use a bloblink
565 if (length($subfieldvalue)>255 ) {
566 # if already a bloblink, update it, otherwise, insert a new one.
567 if ($oldvaluebloblink) {
568 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
569 $sth->execute($subfieldvalue,$oldvaluebloblink);
571 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
572 $sth->execute($subfieldvalue);
573 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
575 my ($res)=$sth->fetchrow;
576 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
577 $sth->execute($subfieldid);
580 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
581 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
582 $sth->execute($subfieldvalue, $subfieldid);
584 $dbh->do("unlock tables");
586 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
587 $sth->execute($subfieldid);
588 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
590 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
591 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
592 return($subfieldid, $subfieldvalue);
595 sub MARCfindsubfield {
596 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
600 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
601 if ($subfieldvalue) {
602 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
604 if ($subfieldorder<1) {
607 $query .= " and subfieldorder=$subfieldorder";
609 my $sti=$dbh->prepare($query);
610 $sti->execute($bibid,$tag, $subfieldcode);
611 while (($subfieldid) = $sti->fetchrow) {
613 $lastsubfieldid=$subfieldid;
615 if ($resultcounter>1) {
616 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
617 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
620 return $lastsubfieldid;
624 sub MARCfindsubfieldid {
625 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
626 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
627 where bibid=? and tag=? and tagorder=?
628 and subfieldcode=? and subfieldorder=?");
629 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
630 my ($res) = $sth->fetchrow;
634 sub MARCdelsubfield {
635 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
636 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
637 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
638 tag='$tag' and tagorder='$tagorder'
639 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
644 # delete a biblio for a $bibid
645 my ($dbh,$bibid) = @_;
646 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
647 $dbh->do("delete from marc_biblio where bibid='$bibid'");
650 sub MARCkoha2marcBiblio {
651 # this function builds partial MARC::Record from the old koha-DB fields
652 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
653 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
654 my $record = MARC::Record->new();
655 #--- if bibid, then retrieve old-style koha data
656 if ($biblionumber>0) {
657 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
658 from biblio where biblionumber=?");
659 $sth2->execute($biblionumber);
660 my $row=$sth2->fetchrow_hashref;
662 foreach $code (keys %$row) {
664 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
668 #--- if biblioitem, then retrieve old-style koha data
669 if ($biblioitemnumber>0) {
670 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
671 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
672 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
674 WHERE biblionumber=? and biblioitemnumber=?
676 $sth2->execute($biblionumber,$biblioitemnumber);
677 my $row=$sth2->fetchrow_hashref;
679 foreach $code (keys %$row) {
681 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
686 # TODO : retrieve notes, additionalauthors
689 sub MARCkoha2marcItem {
690 # this function builds partial MARC::Record from the old koha-DB fields
691 my ($dbh,$biblionumber,$itemnumber) = @_;
692 # my $dbh=&C4Connect;
693 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
694 my $record = MARC::Record->new();
695 #--- if item, then retrieve old-style koha data
697 # print STDERR "prepare $biblionumber,$itemnumber\n";
698 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
699 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
700 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
701 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
703 WHERE itemnumber=?");
704 $sth2->execute($itemnumber);
705 my $row=$sth2->fetchrow_hashref;
707 foreach $code (keys %$row) {
709 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
714 # TODO : retrieve notes, additionalauthors
717 sub MARCkoha2marcSubtitle {
718 # this function builds partial MARC::Record from the old koha-DB fields
719 my ($dbh,$bibnum,$subtitle) = @_;
720 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
721 my $record = MARC::Record->new();
722 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
726 sub MARCkoha2marcOnefield {
727 my ($sth,$record,$kohafieldname,$value)=@_;
730 $sth->execute($kohafieldname);
731 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
732 if ($record->field($tagfield)) {
733 my $tag =$record->field($tagfield);
735 $tag->add_subfields($tagsubfield,$value);
736 $record->delete_field($tag);
737 $record->add_fields($tag);
740 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
747 my ($dbh,$record) = @_;
748 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
750 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
753 # print STDERR $record->as_formatted;
754 while (($field)=$sth2->fetchrow) {
755 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
757 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
760 while (($field)=$sth2->fetchrow) {
761 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
763 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
766 while (($field)=$sth2->fetchrow) {
767 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
769 # additional authors : specific
770 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
774 sub MARCmarc2kohaOneField {
775 # to check : if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
776 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
780 $sth->execute($kohatable.".".$kohafield);
781 ($tagfield,$subfield) = $sth->fetchrow;
782 foreach my $field ($record->field($tagfield)) {
783 if ($field->subfield($subfield)) {
784 if ($result->{$kohafield}) {
785 $result->{$kohafield} .= " | ".$field->subfield($subfield);
787 $result->{$kohafield}=$field->subfield($subfield);
795 # split a subfield string and adds it into the word table.
797 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
798 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
799 my @words = split / /,$sentence;
800 # build stopword list
801 my $sth2 =$dbh->prepare("select word from stopwords");
805 while(($stopword) = $sth2->fetchrow_array) {
806 $stopwords->{$stopword} = $stopword;
808 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
809 values (?,?,?,?,?,?,soundex(?))");
810 foreach my $word (@words) {
811 # we record only words longer than 2 car and not in stopwords hash
812 if (length($word)>1 and !($stopwords->{uc($word)})) {
813 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
815 print STDERR "ERROR ==> insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word) values ($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,soundex($word))\n";
822 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
823 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
824 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
825 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
830 # ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL
833 # all the following subs are useful to manage MARC-DB with complete MARC records.
834 # it's used with marcimport, and marc management tools
839 all subs requires/use $dbh as 1st parameter.
840 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
844 =head2 (oldbibnum,$oldbibitemnum) = ALLnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
845 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
846 are builded from the MARC::Record. If they are passed, they are used.
848 =head2 ALLnewitem($dbh,$olditem);
849 adds an item in the db. $olditem is a old-db hash.
853 Paul POULAIN paul.poulain@free.fr
858 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
859 # note $oldbiblio and $oldbiblioitem are not mandatory.
860 # if not present, they will be builded from $record with MARCmarc2koha function
861 if (($oldbiblio) and not($oldbiblioitem)) {
862 print STDERR "ALLnewbiblio : missing parameter\n";
863 print "ALLnewbiblio : missing parameter : contact koha development team\n";
869 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
870 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
871 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
873 my $olddata = MARCmarc2koha($dbh,$record);
874 $oldbibnum = OLDnewbiblio($dbh,$olddata);
875 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
877 # we must add bibnum and bibitemnum in MARC::Record...
878 # we build the new field with biblionumber and biblioitemnumber
879 # we drop the original field
880 # we add the new builded field.
881 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
882 # (steve and paul : thinks 090 is a good choice)
883 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
884 $sth->execute("biblio.biblionumber");
885 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
886 $sth->execute("biblioitems.biblioitemnumber");
887 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
888 print STDERR "tag1 : $tagfield1 / $tagsubfield1\n tag2 : $tagfield2 / $tagsubfield2\n";
889 if ($tagsubfield1 != $tagsubfield2) {
890 print STDERR "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
891 print "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
894 my $newfield = MARC::Field->new( $tagfield1,'','',
895 "$tagsubfield1" => $oldbibnum,
896 "$tagsubfield2" => $oldbibitemnum);
897 # drop old field and create new one...
898 my $old_field = $record->field($tagfield1);
899 $record->delete_field($old_field);
900 $record->add_fields($newfield);
901 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
902 return ( $oldbibnum,$oldbibitemnum );
906 my ($dbh, $item) = @_;
909 ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{'barcode'});
910 # search MARC biblionumber
911 my $bibid=&MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{'biblionumber'});
913 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
914 $sth->execute($bibid);
915 my ($tagorder) = $sth->fetchrow;
918 # for each field, find MARC tag and subfield, and call the proper MARC sub
919 foreach my $itemkey (keys %$item) {
922 print STDERR "=============> $itemkey : ".$item->{$itemkey}."\n";
923 if ($itemkey eq "biblionumber" || $itemkey eq "biblioitemnumber") {
924 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"biblio.".$itemkey);
926 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"items.".$itemkey);
928 if ($tagfield && $item->{$itemkey} ne 'NULL') {
930 &MARCaddsubfield($dbh,
946 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
952 all subs requires/use $dbh as 1st parameter.
953 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
955 They all are the exact copy of 1.0/1.2 version of the sub
956 without the OLD. The OLDxxx is called by the original xxx sub.
957 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
959 WARNING : there is 1 difference between initialxxx and OLDxxx :
960 the db header $dbh is always passed as parameter
961 to avoid over-DB connexion
965 =head2 $biblionumber = OLDnewbiblio($dbh,$biblio);
966 adds a record in biblio table. Datas are in the hash $biblio.
968 =head2 $biblionumber = OLDmodbiblio($dbh,$biblio);
969 modify a record in biblio table. Datas are in the hash $biblio.
971 =head2 OLDmodsubtitle($dbh,$bibnum,$subtitle);
972 modify subtitles in bibliosubtitle table.
974 =head2 OLDmodaddauthor($dbh,$bibnum,$author);
975 adds or modify additional authors
976 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
978 =head2 $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
981 =head2 OLDmodbibitem($dbh, $biblioitem);
984 =head2 OLDmodnote($dbh,$bibitemnum,$note
985 modify a note for a biblioitem
987 =head2 OLDnewbiblioitem($dbh,$biblioitem);
988 adds a biblioitem ($biblioitem is a hash with the values)
990 =head2 OLDnewsubject($dbh,$bibnum);
992 =head2 OLDnewsubtitle($dbh,$bibnum,$subtitle);
993 create a new subtitle
995 =head2 ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
996 create a item. $item is a hash and $barcode the barcode.
998 =head2 OLDmoditem($dbh,$item);
1001 =head2 OLDdelitem($dbh,$itemnum);
1004 =head2 OLDdeletebiblioitem($dbh,$biblioitemnumber);
1005 deletes a biblioitem
1006 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1008 =head2 OLDdelbiblio($dbh,$biblio);
1013 Paul POULAIN paul.poulain@free.fr
1018 my ($dbh,$biblio) = @_;
1019 # my $dbh = &C4Connect;
1020 my $query = "Select max(biblionumber) from biblio";
1021 my $sth = $dbh->prepare($query);
1023 my $data = $sth->fetchrow_arrayref;
1024 my $bibnum = $$data[0] + 1;
1027 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1028 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1029 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
1030 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
1031 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1032 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1033 if ($biblio->{'seriestitle'}) { $series = 1 };
1036 $query = "insert into biblio set
1037 biblionumber = $bibnum,
1038 title = $biblio->{'title'},
1039 author = $biblio->{'author'},
1040 copyrightdate = $biblio->{'copyright'},
1042 seriestitle = $biblio->{'seriestitle'},
1043 notes = $biblio->{'notes'},
1044 abstract = $biblio->{'abstract'}";
1046 $sth = $dbh->prepare($query);
1055 my ($dbh,$biblio) = @_;
1056 # my $dbh = C4Connect;
1060 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1061 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1062 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1063 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
1064 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
1065 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
1066 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
1067 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1069 $query = "Update biblio set
1070 title = $biblio->{'title'},
1071 author = $biblio->{'author'},
1072 abstract = $biblio->{'abstract'},
1073 copyrightdate = $biblio->{'copyrightdate'},
1074 seriestitle = $biblio->{'seriestitle'},
1075 serial = $biblio->{'serial'},
1076 unititle = $biblio->{'unititle'},
1077 notes = $biblio->{'notes'}
1078 where biblionumber = $biblio->{'biblionumber'}";
1079 $sth = $dbh->prepare($query);
1085 return($biblio->{'biblionumber'});
1088 sub OLDmodsubtitle {
1089 my ($dbh,$bibnum, $subtitle) = @_;
1090 # my $dbh = C4Connect;
1091 my $query = "update bibliosubtitle set
1092 subtitle = '$subtitle'
1093 where biblionumber = $bibnum";
1094 my $sth = $dbh->prepare($query);
1102 sub OLDmodaddauthor {
1103 my ($dbh,$bibnum, $author) = @_;
1104 # my $dbh = C4Connect;
1105 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1106 my $sth = $dbh->prepare($query);
1111 if ($author ne '') {
1112 $query = "Insert into additionalauthors set
1114 biblionumber = '$bibnum'";
1115 $sth = $dbh->prepare($query);
1123 } # sub modaddauthor
1127 my ($dbh,$bibnum, $force, @subject) = @_;
1128 # my $dbh = C4Connect;
1129 my $count = @subject;
1131 for (my $i = 0; $i < $count; $i++) {
1132 $subject[$i] =~ s/^ //g;
1133 $subject[$i] =~ s/ $//g;
1134 my $query = "select * from catalogueentry
1135 where entrytype = 's'
1136 and catalogueentry = '$subject[$i]'";
1137 my $sth = $dbh->prepare($query);
1140 if (my $data = $sth->fetchrow_hashref) {
1142 if ($force eq $subject[$i]) {
1143 # subject not in aut, chosen to force anway
1144 # so insert into cataloguentry so its in auth file
1145 $query = "Insert into catalogueentry
1146 (entrytype,catalogueentry)
1147 values ('s','$subject[$i]')";
1148 my $sth2 = $dbh->prepare($query);
1153 $error = "$subject[$i]\n does not exist in the subject authority file";
1154 $query = "Select * from catalogueentry
1155 where entrytype = 's'
1156 and (catalogueentry like '$subject[$i] %'
1157 or catalogueentry like '% $subject[$i] %'
1158 or catalogueentry like '% $subject[$i]')";
1159 my $sth2 = $dbh->prepare($query);
1162 while (my $data = $sth2->fetchrow_hashref) {
1163 $error = $error."<br>$data->{'catalogueentry'}";
1171 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1172 my $sth = $dbh->prepare($query);
1175 for (my $i = 0; $i < $count; $i++) {
1176 $sth = $dbh->prepare("Insert into bibliosubject
1177 values ('$subject[$i]', $bibnum)");
1189 my ($dbh,$biblioitem) = @_;
1190 # my $dbh = C4Connect;
1193 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1194 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1195 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1196 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1197 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1198 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1199 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1200 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1201 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1202 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1203 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1204 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1205 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1206 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1208 $query = "Update biblioitems set
1209 itemtype = $biblioitem->{'itemtype'},
1210 url = $biblioitem->{'url'},
1211 isbn = $biblioitem->{'isbn'},
1212 publishercode = $biblioitem->{'publishercode'},
1213 publicationyear = $biblioitem->{'publicationyear'},
1214 classification = $biblioitem->{'classification'},
1215 dewey = $biblioitem->{'dewey'},
1216 subclass = $biblioitem->{'subclass'},
1217 illus = $biblioitem->{'illus'},
1218 pages = $biblioitem->{'pages'},
1219 volumeddesc = $biblioitem->{'volumeddesc'},
1220 notes = $biblioitem->{'notes'},
1221 size = $biblioitem->{'size'},
1222 place = $biblioitem->{'place'}
1223 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1231 my ($dbh,$bibitemnum,$note)=@_;
1232 # my $dbh=C4Connect;
1233 my $query="update biblioitems set notes='$note' where
1234 biblioitemnumber='$bibitemnum'";
1235 my $sth=$dbh->prepare($query);
1241 sub OLDnewbiblioitem {
1242 my ($dbh,$biblioitem) = @_;
1243 # my $dbh = C4Connect;
1244 my $query = "Select max(biblioitemnumber) from biblioitems";
1245 my $sth = $dbh->prepare($query);
1249 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
1250 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
1251 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1252 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1253 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1254 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1255 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
1256 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1257 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1258 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1259 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1260 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
1261 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1262 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1263 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1264 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1265 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1266 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1267 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
1268 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
1271 $data = $sth->fetchrow_arrayref;
1272 $bibitemnum = $$data[0] + 1;
1276 $query = "insert into biblioitems set
1277 biblioitemnumber = $bibitemnum,
1278 biblionumber = $biblioitem->{'biblionumber'},
1279 volume = $biblioitem->{'volume'},
1280 number = $biblioitem->{'number'},
1281 classification = $biblioitem->{'classification'},
1282 itemtype = $biblioitem->{'itemtype'},
1283 url = $biblioitem->{'url'},
1284 isbn = $biblioitem->{'isbn'},
1285 issn = $biblioitem->{'issn'},
1286 dewey = $biblioitem->{'dewey'},
1287 subclass = $biblioitem->{'subclass'},
1288 publicationyear = $biblioitem->{'publicationyear'},
1289 publishercode = $biblioitem->{'publishercode'},
1290 volumedate = $biblioitem->{'volumedate'},
1291 volumeddesc = $biblioitem->{'volumeddesc'},
1292 illus = $biblioitem->{'illus'},
1293 pages = $biblioitem->{'pages'},
1294 notes = $biblioitem->{'notes'},
1295 size = $biblioitem->{'size'},
1296 lccn = $biblioitem->{'lccn'},
1297 marc = $biblioitem->{'marc'},
1298 place = $biblioitem->{'place'}";
1300 $sth = $dbh->prepare($query);
1304 return($bibitemnum);
1308 my ($dbh,$bibnum)=@_;
1309 # my $dbh=C4Connect;
1310 my $query="insert into bibliosubject (biblionumber) values
1312 my $sth=$dbh->prepare($query);
1319 sub OLDnewsubtitle {
1320 my ($dbh,$bibnum, $subtitle) = @_;
1321 # my $dbh = C4Connect;
1322 $subtitle = $dbh->quote($subtitle);
1323 my $query = "insert into bibliosubtitle set
1324 biblionumber = $bibnum,
1325 subtitle = $subtitle";
1326 my $sth = $dbh->prepare($query);
1336 my ($dbh,$item, $barcode) = @_;
1337 # my $dbh = C4Connect;
1338 my $query = "Select max(itemnumber) from items";
1339 my $sth = $dbh->prepare($query);
1345 $data = $sth->fetchrow_hashref;
1346 $itemnumber = $data->{'max(itemnumber)'} + 1;
1349 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
1350 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
1351 $item->{'price'} = $dbh->quote($item->{'price'});
1352 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
1353 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
1355 # foreach my $barcode (@barcodes) {
1356 # $barcode = uc($barcode);
1357 $barcode = $dbh->quote($barcode);
1358 $query = "Insert into items set
1359 itemnumber = $itemnumber,
1360 biblionumber = $item->{'biblionumber'},
1361 biblioitemnumber = $item->{'biblioitemnumber'},
1363 booksellerid = $item->{'booksellerid'},
1364 dateaccessioned = NOW(),
1365 homebranch = $item->{'homebranch'},
1366 holdingbranch = $item->{'homebranch'},
1367 price = $item->{'price'},
1368 replacementprice = $item->{'replacementprice'},
1369 replacementpricedate = NOW(),
1370 itemnotes = $item->{'itemnotes'}";
1371 if ($item->{'loan'}) {
1372 $query .= ",notforloan = $item->{'loan'}";
1375 $sth = $dbh->prepare($query);
1377 if (defined $sth->errstr) {
1378 $error .= $sth->errstr;
1383 return($itemnumber,$error);
1387 my ($dbh,$item) = @_;
1388 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1389 # my $dbh=C4Connect;
1390 my $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1391 barcode='$item->{'barcode'}',itemnotes='$item->{'notes'}'
1392 where itemnumber=$item->{'itemnum'}";
1393 if ($item->{'barcode'} eq ''){
1394 $query="update items set biblioitemnumber=$item->{'bibitemnum'},notforloan=$item->{'loan'} where itemnumber=$item->{'itemnum'}";
1396 if ($item->{'lost'} ne ''){
1397 $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1398 barcode='$item->{'barcode'}',
1399 itemnotes='$item->{'notes'}',
1400 homebranch='$item->{'homebranch'}',
1401 itemlost='$item->{'lost'}',
1402 wthdrawn='$item->{'wthdrawn'}'
1403 where itemnumber=$item->{'itemnum'}";
1405 if ($item->{'replacement'} ne ''){
1406 $query=~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1409 my $sth=$dbh->prepare($query);
1415 # FIXME - A nearly-identical function, &delitem, appears in
1418 my ($dbh,$itemnum)=@_;
1419 # my $dbh=C4Connect;
1420 my $query="select * from items where itemnumber=$itemnum";
1421 my $sth=$dbh->prepare($query);
1423 my @data=$sth->fetchrow_array;
1425 $query="Insert into deleteditems values (";
1426 foreach my $temp (@data){
1427 $query=$query."'$temp',";
1431 $sth=$dbh->prepare($query);
1434 $query = "Delete from items where itemnumber=$itemnum";
1435 $sth=$dbh->prepare($query);
1441 sub OLDdeletebiblioitem {
1442 my ($dbh,$biblioitemnumber) = @_;
1443 # my $dbh = C4Connect;
1444 my $query = "Select * from biblioitems
1445 where biblioitemnumber = $biblioitemnumber";
1446 my $sth = $dbh->prepare($query);
1451 if (@results = $sth->fetchrow_array) {
1452 $query = "Insert into deletedbiblioitems values (";
1453 foreach my $value (@results) {
1454 $value = $dbh->quote($value);
1455 $query .= "$value,";
1458 $query =~ s/\,$/\)/;
1461 $query = "Delete from biblioitems
1462 where biblioitemnumber = $biblioitemnumber";
1466 # Now delete all the items attached to the biblioitem
1467 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1468 $sth = $dbh->prepare($query);
1470 while (@results = $sth->fetchrow_array) {
1471 $query = "Insert into deleteditems values (";
1472 foreach my $value (@results) {
1473 $value = $dbh->quote($value);
1474 $query .= "$value,";
1476 $query =~ s/\,$/\)/;
1480 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1483 } # sub deletebiblioitem
1486 my ($dbh,$biblio)=@_;
1487 # my $dbh=C4Connect;
1488 my $query="select * from biblio where biblionumber=$biblio";
1489 my $sth=$dbh->prepare($query);
1491 if (my @data=$sth->fetchrow_array){
1493 $query="Insert into deletedbiblio values (";
1494 foreach my $temp (@data){
1495 $temp=~ s/\'/\\\'/g;
1496 $query=$query."'$temp',";
1500 $sth=$dbh->prepare($query);
1503 $query = "Delete from biblio where biblionumber=$biblio";
1504 $sth=$dbh->prepare($query);
1518 # FIXME - This is the same as &C4::Acquisitions::itemcount, but not
1519 # the same as &C4::Search::itemcount
1523 my $query="Select count(*) from items where biblionumber=$biblio";
1525 my $sth=$dbh->prepare($query);
1527 my $data=$sth->fetchrow_hashref;
1530 return($data->{'count(*)'});
1536 my $query="Select ordernumber
1538 where biblionumber=? and biblioitemnumber=?";
1539 my $sth=$dbh->prepare($query);
1540 $sth->execute($bib,$bi);
1541 my $ordnum=$sth->fetchrow_hashref;
1543 my $order=getsingleorder($ordnum->{'ordernumber'});
1546 return ($order,$ordnum->{'ordernumber'});
1549 # FIXME - This is practically the same function as
1550 # &C4::Acquisitions::getsingleorder and &C4::Catalogue::getsingleorder
1551 sub getsingleorder {
1554 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1555 where aqorders.ordernumber=?
1556 and biblio.biblionumber=aqorders.biblionumber and
1557 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1558 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1559 my $sth=$dbh->prepare($query);
1560 $sth->execute($ordnum);
1561 my $data=$sth->fetchrow_hashref;
1569 my $dbh = &C4Connect;
1570 my $bibnum=OLDnewbiblio($dbh,$biblio);
1578 my $dbh = C4Connect;
1579 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1581 return($biblionumber);
1585 my ($bibnum, $subtitle) = @_;
1586 my $dbh = C4Connect;
1587 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1592 # FIXME - This is functionally identical to
1593 # &C4::Acquisitions::modaddauthor
1595 my ($bibnum, $author) = @_;
1596 my $dbh = C4Connect;
1597 &OLDmodaddauthor($dbh,$bibnum,$author);
1599 } # sub modaddauthor
1603 my ($bibnum, $force, @subject) = @_;
1604 my $dbh = C4Connect;
1605 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1610 my ($biblioitem) = @_;
1611 my $dbh = C4Connect;
1612 &OLDmodbibitem($dbh,$biblioitem);
1613 my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
1614 &MARCmodbiblio($dbh,$biblioitem->{biblionumber},0,$MARCbibitem);
1619 my ($bibitemnum,$note)=@_;
1621 &OLDmodnote($dbh,$bibitemnum,$note);
1625 # FIXME - This is quite similar in effect to &C4::newbiblioitem,
1626 # except for the MARC stuff.
1628 my ($biblioitem) = @_;
1629 my $dbh = C4Connect;
1630 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1631 # print STDERR "bibitemnum : $bibitemnum\n";
1632 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1633 # print STDERR $MARCbiblio->as_formatted();
1634 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1635 return($bibitemnum);
1641 &OLDnewsubject($dbh,$bibnum);
1645 # FIXME - This is just a wrapper around &OLDnewsubtitle
1646 # FIXME - This is in effect the same as &C4::Acquisitions::newsubtitle
1648 my ($bibnum, $subtitle) = @_;
1649 my $dbh = C4Connect;
1650 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1655 my ($item, @barcodes) = @_;
1656 my $dbh = C4Connect;
1660 foreach my $barcode (@barcodes) {
1661 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1663 # print STDERR "biblionumber : $item->{biblionumber} / MARCbibid : $MARCbibid / itemnumber : $itemnumber\n";
1664 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1665 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1666 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1667 # print STDERR "MARCmodbiblio called\n";
1675 # my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1677 &OLDmoditem($dbh,$item);
1678 warn "biblionumber : $item->{'biblionumber'} / $item->{'itemnum'}\n";
1679 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1680 warn "before MARCmoditem : $item->{biblionumber}, $item->{'itemnum'}\n";
1681 warn $MARCitem->as_formatted();
1682 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1683 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1684 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1689 my ($count,@barcodes)=@_;
1692 for (my $i=0;$i<$count;$i++){
1693 $barcodes[$i]=uc $barcodes[$i];
1694 my $query="Select * from items where barcode='$barcodes[$i]'";
1695 my $sth=$dbh->prepare($query);
1697 if (my $data=$sth->fetchrow_hashref){
1698 $error.=" Duplicate Barcode: $barcodes[$i]";
1707 my ($bibitemnum)=@_;
1709 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1710 my $sth=$dbh->prepare($query);
1712 my $data=$sth->fetchrow_hashref;
1715 return($data->{'count(*)'});
1718 # FIXME - This is just a wrapper around &OLDdelitem, and acts
1719 # identically to &C4::Acquisitions::delitem
1723 &OLDdelitem($dbh,$itemnum);
1727 sub deletebiblioitem {
1728 my ($biblioitemnumber) = @_;
1729 my $dbh = C4Connect;
1730 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1732 } # sub deletebiblioitem
1738 &OLDdelbiblio($dbh,$biblio);
1743 my $dbh = C4Connect;
1744 my $query = "select * from itemtypes";
1745 my $sth = $dbh->prepare($query);
1746 # || die "Cannot prepare $query" . $dbh->errstr;
1751 # || die "Cannot execute $query\n" . $sth->errstr;
1752 while (my $data = $sth->fetchrow_hashref) {
1753 $results[$count] = $data;
1759 return($count, @results);
1760 } # sub getitemtypes
1763 my ($biblionumber) = @_;
1764 my $dbh = C4Connect;
1765 my $query = "Select * from biblio where biblionumber = $biblionumber";
1766 my $sth = $dbh->prepare($query);
1767 # || die "Cannot prepare $query\n" . $dbh->errstr;
1772 # || die "Cannot execute $query\n" . $sth->errstr;
1773 while (my $data = $sth->fetchrow_hashref) {
1774 $results[$count] = $data;
1780 return($count, @results);
1784 my ($biblioitemnum) = @_;
1785 my $dbh = C4Connect;
1786 my $query = "Select * from biblioitems where
1787 biblioitemnumber = $biblioitemnum";
1788 my $sth = $dbh->prepare($query);
1794 while (my $data = $sth->fetchrow_hashref) {
1795 $results[$count] = $data;
1801 return($count, @results);
1802 } # sub getbiblioitem
1804 sub getbiblioitembybiblionumber {
1805 my ($biblionumber) = @_;
1806 my $dbh = C4Connect;
1807 my $query = "Select * from biblioitems where biblionumber =
1809 my $sth = $dbh->prepare($query);
1815 while (my $data = $sth->fetchrow_hashref) {
1816 $results[$count] = $data;
1822 return($count, @results);
1825 sub getitemsbybiblioitem {
1826 my ($biblioitemnum) = @_;
1827 my $dbh = C4Connect;
1828 my $query = "Select * from items, biblio where
1829 biblio.biblionumber = items.biblionumber and biblioitemnumber
1831 my $sth = $dbh->prepare($query);
1832 # || die "Cannot prepare $query\n" . $dbh->errstr;
1837 # || die "Cannot execute $query\n" . $sth->errstr;
1838 while (my $data = $sth->fetchrow_hashref) {
1839 $results[$count] = $data;
1845 return($count, @results);
1846 } # sub getitemsbybiblioitem
1850 my $dbh = C4Connect;
1856 $isbn = $dbh->quote($isbn);
1857 $query = "Select biblio.* from biblio, biblioitems where
1858 biblio.biblionumber = biblioitems.biblionumber
1860 $sth = $dbh->prepare($query);
1863 while (my $data = $sth->fetchrow_hashref) {
1864 $results[$count] = $data;
1870 return($count, @results);
1874 # At the moment this is just a straight copy of the subject code. Needs heavy
1875 # modification to work for additional authors, obviously.
1876 # Check for additional author changes
1878 # my $newadditionalauthor='';
1879 # my $additionalauthors;
1880 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
1881 # $additionalauthors->{$newadditionalauthor}=1;
1882 # if ($origadditionalauthors->{$newadditionalauthor}) {
1883 # $additionalauthors->{$newadditionalauthor}=2;
1885 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
1886 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
1888 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
1890 # $subfields->{1}->{'Subfield_Mark'}='a';
1891 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
1894 # foreach $Record_ID (@marcrecords) {
1895 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1896 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
1900 # my $origadditionalauthor;
1901 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
1902 # if ($additionalauthors->{$origadditionalauthor} == 1) {
1903 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
1904 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
1905 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
1915 # Subroutine to log changes to databases
1916 # Eventually, this subroutine will be used to create a log of all changes made,
1917 # with the possibility of "undo"ing some changes
1919 if ($database eq 'kohadb') {
1925 print STDERR "KOHA: $type $section $item $original $new\n";
1926 } elsif ($database eq 'marc') {
1928 my $Record_ID=shift;
1931 my $subfield_ID=shift;
1934 print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
1938 #------------------------------------------------
1941 #---------------------------------------
1942 # Find a biblio entry, or create a new one if it doesn't exist.
1943 # If a "subtitle" entry is in hash, add it to subtitle table
1944 sub getoraddbiblio {
1948 $biblio, # hash ref to fields
1959 requireDBI($dbh,"getoraddbiblio");
1961 print "<PRE>Looking for biblio </PRE>\n" if $debug;
1962 $sth=$dbh->prepare("select biblionumber
1964 where title=? and author=?
1965 and copyrightdate=? and seriestitle=?");
1967 $biblio->{title}, $biblio->{author},
1968 $biblio->{copyright}, $biblio->{seriestitle} );
1970 ($biblionumber) = $sth->fetchrow;
1971 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
1973 # Doesn't exist. Add new one.
1974 print "<PRE>Adding biblio</PRE>\n" if $debug;
1975 ($biblionumber,$error)=&newbiblio($biblio);
1976 if ( $biblionumber ) {
1977 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
1978 if ( $biblio->{subtitle} ) {
1979 &newsubtitle($biblionumber,$biblio->{subtitle} );
1982 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
1986 return $biblionumber,$error;
1988 } # sub getoraddbiblio
1992 # UNUSEFUL SUBs. Could be deleted, kept only until beta test
1993 # maybe useful for some MARC tricks steve used.
1996 sub OLD_MAYBE_DELETED_newBiblioItem {
1997 my ($env, $biblioitem) = @_;
1999 my $biblionumber=$biblioitem->{'biblionumber'};
2000 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2001 my $volume=$biblioitem->{'volume'};
2002 my $q_volume=$dbh->quote($volume);
2003 my $number=$biblioitem->{'number'};
2004 my $q_number=$dbh->quote($number);
2005 my $classification=$biblioitem->{'classification'};
2006 my $q_classification=$dbh->quote($classification);
2007 my $itemtype=$biblioitem->{'itemtype'};
2008 my $q_itemtype=$dbh->quote($itemtype);
2009 my $isbn=$biblioitem->{'isbn'};
2010 my $q_isbn=$dbh->quote($isbn);
2011 my $issn=$biblioitem->{'issn'};
2012 my $q_issn=$dbh->quote($issn);
2013 my $dewey=$biblioitem->{'dewey'};
2015 ($dewey == 0) && ($dewey='');
2016 my $subclass=$biblioitem->{'subclass'};
2017 my $q_subclass=$dbh->quote($subclass);
2018 my $publicationyear=$biblioitem->{'publicationyear'};
2019 my $publishercode=$biblioitem->{'publishercode'};
2020 my $q_publishercode=$dbh->quote($publishercode);
2021 my $volumedate=$biblioitem->{'volumedate'};
2022 my $q_volumedate=$dbh->quote($volumedate);
2023 my $illus=$biblioitem->{'illus'};
2024 my $q_illus=$dbh->quote($illus);
2025 my $pages=$biblioitem->{'pages'};
2026 my $q_pages=$dbh->quote($pages);
2027 my $notes=$biblioitem->{'notes'};
2028 my $q_notes=$dbh->quote($notes);
2029 my $size=$biblioitem->{'size'};
2030 my $q_size=$dbh->quote($size);
2031 my $place=$biblioitem->{'place'};
2032 my $q_place=$dbh->quote($place);
2033 my $lccn=$biblioitem->{'lccn'};
2034 my $q_lccn=$dbh->quote($lccn);
2037 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
2040 unless ($env->{'marconly'}) {
2041 #my $sth=$dbh->prepare("lock tables biblioitems write");
2043 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
2045 my ($biblioitemnumber) =$sth->fetchrow;
2046 $biblioitemnumber++;
2047 $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)");
2049 #my $sth=$dbh->prepare("unlock tables");
2054 # Should we check if there is already a biblioitem/amrc with the
2055 # same isbn/lccn/issn?
2057 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
2059 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
2060 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2062 my ($subtitle) = $sth->fetchrow;
2063 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2065 my @additionalauthors;
2066 while (my ($additionalauthor) = $sth->fetchrow) {
2067 push (@additionalauthors, $additionalauthor);
2069 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2072 while (my ($subject) = $sth->fetchrow) {
2073 push (@subjects, $subject);
2078 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
2080 my $Resource_ID=$dbh->{'mysql_insertid'};
2081 my $Record_ID=$Resource_ID;
2082 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
2088 $subfields->{1}->{'Subfield_Mark'}='a';
2089 $subfields->{1}->{'Subfield_Value'}=$title;
2091 $subfields->{2}->{'Subfield_Mark'}='b';
2092 $subfields->{2}->{'Subfield_Value'}=$subtitle;
2095 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2101 $subfields->{1}->{'Subfield_Mark'}='a';
2102 $subfields->{1}->{'Subfield_Value'}=$author;
2104 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2109 $subfields->{1}->{'Subfield_Mark'}='a';
2110 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
2112 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2117 $subfields->{1}->{'Subfield_Mark'}='a';
2118 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
2119 $subfields->{2}->{'Subfield_Mark'}='3';
2120 $subfields->{2}->{'Subfield_Value'}='biblio';
2122 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2124 # Additional Authors
2125 foreach (@additionalauthors) {
2127 (next) unless ($author);
2129 $subfields->{1}->{'Subfield_Mark'}='a';
2130 $subfields->{1}->{'Subfield_Value'}=$author;
2131 $subfields->{2}->{'Subfield_Mark'}='e';
2132 $subfields->{2}->{'Subfield_Value'}='author';
2134 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2138 (next) unless ($illus);
2140 $subfields->{1}->{'Subfield_Mark'}='a';
2141 $subfields->{1}->{'Subfield_Value'}=$illus;
2142 $subfields->{2}->{'Subfield_Mark'}='e';
2143 $subfields->{2}->{'Subfield_Value'}='illustrator';
2145 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2148 foreach (@subjects) {
2150 (next) unless ($subject);
2152 $subfields->{1}->{'Subfield_Mark'}='a';
2153 $subfields->{1}->{'Subfield_Value'}=$subject;
2155 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2162 $subfields->{1}->{'Subfield_Mark'}='a';
2163 $subfields->{1}->{'Subfield_Value'}=$isbn;
2165 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2170 $subfields->{1}->{'Subfield_Mark'}='a';
2171 $subfields->{1}->{'Subfield_Value'}=$lccn;
2173 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2178 $subfields->{1}->{'Subfield_Mark'}='a';
2179 $subfields->{1}->{'Subfield_Value'}=$issn;
2181 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2186 $subfields->{1}->{'Subfield_Mark'}='a';
2187 $subfields->{1}->{'Subfield_Value'}=$dewey;
2189 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2191 # DEWEY subclass and itemtype
2194 $subfields->{1}->{'Subfield_Mark'}='a';
2195 $subfields->{1}->{'Subfield_Value'}=$itemtype;
2196 $subfields->{2}->{'Subfield_Mark'}='b';
2197 $subfields->{2}->{'Subfield_Value'}=$subclass;
2198 $subfields->{3}->{'Subfield_Mark'}='c';
2199 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
2200 $subfields->{4}->{'Subfield_Mark'}='d';
2201 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
2203 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2208 $subfields->{1}->{'Subfield_Mark'}='a';
2209 $subfields->{1}->{'Subfield_Value'}=$place;
2210 $subfields->{2}->{'Subfield_Mark'}='b';
2211 $subfields->{2}->{'Subfield_Value'}=$publishercode;
2212 $subfields->{3}->{'Subfield_Mark'}='c';
2213 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
2214 if ($copyrightdate) {
2215 $subfields->{4}->{'Subfield_Mark'}='c';
2216 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
2219 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2222 if ($pages || $size) {
2224 $subfields->{1}->{'Subfield_Mark'}='a';
2225 $subfields->{1}->{'Subfield_Value'}=$pages;
2226 $subfields->{2}->{'Subfield_Mark'}='c';
2227 $subfields->{2}->{'Subfield_Value'}=$size;
2229 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2232 if ($volume || $number) {
2234 $subfields->{1}->{'Subfield_Mark'}='v';
2235 $subfields->{1}->{'Subfield_Value'}=$volume;
2236 $subfields->{2}->{'Subfield_Mark'}='n';
2237 $subfields->{2}->{'Subfield_Value'}=$number;
2239 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2244 $subfields->{1}->{'Subfield_Mark'}='a';
2245 $subfields->{1}->{'Subfield_Value'}=$notes;
2246 $subfields->{2}->{'Subfield_Mark'}='3';
2247 $subfields->{2}->{'Subfield_Value'}='biblioitem';
2249 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2253 return ($env, $Record_ID);
2256 sub OLD_MAYBE_DELETED_newItem {
2257 my ($env, $Record_ID, $item) = @_;
2259 my $barcode=$item->{'barcode'};
2260 my $q_barcode=$dbh->quote($barcode);
2261 my $biblionumber=$item->{'biblionumber'};
2262 my $biblioitemnumber=$item->{'biblioitemnumber'};
2263 my $dateaccessioned=$item->{'dateaccessioned'};
2264 my $booksellerid=$item->{'booksellerid'};
2265 my $q_booksellerid=$dbh->quote($booksellerid);
2266 my $homebranch=$item->{'homebranch'};
2267 my $q_homebranch=$dbh->quote($homebranch);
2268 my $holdingbranch=$item->{'holdingbranch'};
2269 my $price=$item->{'price'};
2270 my $replacementprice=$item->{'replacementprice'};
2271 my $replacementpricedate=$item->{'replacementpricedate'};
2272 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
2273 my $notforloan=$item->{'notforloan'};
2274 my $itemlost=$item->{'itemlost'};
2275 my $wthdrawn=$item->{'wthdrawn'};
2276 my $restricted=$item->{'restricted'};
2277 my $itemnotes=$item->{'itemnotes'};
2278 my $q_itemnotes=$dbh->quote($itemnotes);
2279 my $itemtype=$item->{'itemtype'};
2280 my $subclass=$item->{'subclass'};
2284 unless ($env->{'marconly'}) {
2285 my $sth=$dbh->prepare("select max(itemnumber) from items");
2287 my ($itemnumber) =$sth->fetchrow;
2289 $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)");
2296 $subfields->{1}->{'Subfield_Mark'}='p';
2297 $subfields->{1}->{'Subfield_Value'}=$barcode;
2298 $subfields->{2}->{'Subfield_Mark'}='d';
2299 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
2300 $subfields->{3}->{'Subfield_Mark'}='e';
2301 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
2302 $subfields->{4}->{'Subfield_Mark'}='b';
2303 $subfields->{4}->{'Subfield_Value'}=$homebranch;
2304 $subfields->{5}->{'Subfield_Mark'}='l';
2305 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
2306 $subfields->{6}->{'Subfield_Mark'}='c';
2307 $subfields->{6}->{'Subfield_Value'}=$price;
2308 $subfields->{7}->{'Subfield_Mark'}='c';
2309 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
2310 $subfields->{8}->{'Subfield_Mark'}='d';
2311 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
2313 $subfields->{9}->{'Subfield_Mark'}='h';
2314 $subfields->{9}->{'Subfield_Value'}='Not for loan';
2317 $subfields->{10}->{'Subfield_Mark'}='j';
2318 $subfields->{10}->{'Subfield_Value'}='Item lost';
2321 $subfields->{11}->{'Subfield_Mark'}='j';
2322 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
2325 $subfields->{12}->{'Subfield_Mark'}='z';
2326 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
2330 $env->{'linkage'}=1;
2331 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2332 $env->{'linkage'}=0;
2333 $env->{'linkid'}=$Tag_ID;
2336 $subfields2->{1}->{'Subfield_Mark'}='a';
2337 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
2338 $subfields2->{1}->{'Subfield_Mark'}='b';
2339 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
2340 $subfields2->{1}->{'Subfield_Mark'}='c';
2341 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
2342 $subfields2->{2}->{'Subfield_Mark'}='m';
2343 $subfields2->{2}->{'Subfield_Value'}=$subclass;
2344 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
2345 $env->{'linkid'}='';
2348 sub OLD_MAYBE_DELETED_updateBiblio {
2349 # Update the biblio with biblionumber $biblio->{'biblionumber'}
2350 # I guess this routine should search through all marc records for a record that
2351 # has the same biblionumber stored in it, and modify the MARC record as well as
2354 # Also, this subroutine should search through the $biblio object and compare it
2355 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
2356 # this logging feature to be usable to undo changes easily.
2358 my ($env, $biblio) = @_;
2360 my $biblionumber=$biblio->{'biblionumber'};
2362 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
2364 my $origbiblio=$sth->fetchrow_hashref;
2365 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2367 my ($subtitle)=$sth->fetchrow;
2368 $origbiblio->{'subtitle'}=$subtitle;
2369 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2371 my $origadditionalauthors;
2372 while (my ($author) = $sth->fetchrow) {
2373 push (@{$origbiblio->{'additionalauthors'}}, $author);
2374 $origadditionalauthors->{$author}=1;
2376 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2379 while (my ($subject) = $sth->fetchrow) {
2380 push (@{$origbiblio->{'subjects'}}, $subject);
2381 $origsubjects->{$subject}=1;
2385 # Obtain a list of MARC Record_ID's that are tied to this biblio
2386 $sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
2389 while (my ($bibid) = $sth->fetchrow) {
2390 push(@marcrecords, $bibid);
2394 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
2395 my $q_author=$dbh->quote($biblio->{'author'});
2396 logchange('kohadb', 'change', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
2397 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
2399 foreach $bibid (@marcrecords) {
2400 logchange('marc', 'change', $bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2401 changeSubfield($bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2404 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
2405 my $q_title=$dbh->quote($biblio->{'title'});
2406 logchange('kohadb', 'change', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
2407 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
2409 foreach $Record_ID (@marcrecords) {
2410 logchange('marc', 'change', $Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2411 changeSubfield($Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2414 if ($biblio->{'subtitle'} ne $origbiblio->{'subtitle'}) {
2415 my $q_subtitle=$dbh->quote($biblio->{'subtitle'});
2416 logchange('kohadb', 'change', 'biblio', 'subtitle', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2417 my $sti=$dbh->prepare("update bibliosubtitle set subtitle=$q_subtitle where biblionumber=$biblio->{'biblionumber'}");
2419 foreach $Record_ID (@marcrecords) {
2420 logchange('marc', 'change', $Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2421 changeSubfield($Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2424 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
2425 my $q_unititle=$dbh->quote($biblio->{'unititle'});
2426 logchange('kohadb', 'change', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
2427 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
2430 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
2431 my $q_notes=$dbh->quote($biblio->{'notes'});
2432 logchange('kohadb', 'change', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
2433 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
2435 foreach $Record_ID (@marcrecords) {
2436 logchange('marc', 'change', $Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2437 changeSubfield($Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2440 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
2441 my $q_serial=$dbh->quote($biblio->{'serial'});
2442 logchange('kohadb', 'change', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
2443 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
2446 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
2447 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
2448 logchange('kohadb', 'change', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2449 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
2451 foreach $Record_ID (@marcrecords) {
2452 logchange('marc', 'change', $Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2453 changeSubfield($Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2456 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
2457 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
2458 logchange('kohadb', 'change', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
2459 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
2461 foreach $Record_ID (@marcrecords) {
2462 logchange('marc', 'change', $Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2463 changeSubfield($Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2467 # Check for subject heading changes
2471 foreach $newsubject (@{$biblio->{'subject'}}) {
2472 $subjects->{$newsubject}=1;
2473 if ($origsubjects->{$newsubject}) {
2474 $subjects->{$newsubject}=2;
2476 my $q_newsubject=$dbh->quote($newsubject);
2477 my $sth=$dbh->prepare("insert into bibliosubject (subject,biblionumber) values ($q_newsubject, $biblionumber)");
2479 logchange('kohadb', 'add', 'biblio', 'subject', $newsubject);
2481 $subfields->{1}->{'Subfield_Mark'}='a';
2482 $subfields->{1}->{'Subfield_Value'}=$newsubject;
2485 foreach $Record_ID (@marcrecords) {
2486 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2487 logchange('marc', 'add', $Record_ID, '650', 'a', $newsubject);
2492 foreach $origsubject (keys %$origsubjects) {
2493 if ($subjects->{$origsubject} == 1) {
2494 my $q_origsubject=$dbh->quote($origsubject);
2495 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'subject', $origsubject);
2496 my $sth=$dbh->prepare("delete from bibliosubject where biblionumber=$biblionumber and subject=$q_origsubject");
2502 sub OLD_MAYBE_DELETED_updateBiblioItem {
2503 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
2505 # This routine should also check to see which fields are actually being
2506 # modified, and log all changes.
2508 my ($env, $biblioitem) = @_;
2511 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2512 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
2513 # obi = original biblioitem
2514 my $obi=$sth->fetchrow_hashref;
2515 $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");
2517 my ($Record_ID) = $sth->fetchrow;
2518 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
2519 logchange('kohadb', 'change', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2520 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
2521 logchange('marc', 'change', $Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2522 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2524 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
2525 logchange('kohadb', 'change', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
2526 my $q_volume=$dbh->quote($biblioitem->{'volume'});
2527 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
2528 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2529 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2531 if ($biblioitem->{'number'} ne $obi->{'number'}) {
2532 logchange('kohadb', 'change', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
2533 my $q_number=$dbh->quote($biblioitem->{'number'});
2534 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
2535 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2536 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2538 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
2539 logchange('kohadb', 'change', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2540 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
2541 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
2542 logchange('marc', 'change', $Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2543 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2545 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
2546 logchange('kohadb', 'change', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
2547 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
2548 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
2549 logchange('marc', 'change', $Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2550 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2552 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
2553 logchange('kohadb', 'change', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
2554 my $q_issn=$dbh->quote($biblioitem->{'issn'});
2555 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
2556 logchange('marc', 'change', $Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2557 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2559 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
2560 logchange('kohadb', 'change', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
2561 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
2562 logchange('marc', 'change', $Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2563 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2565 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
2566 logchange('kohadb', 'change', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
2567 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
2568 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
2569 logchange('marc', 'change', $Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2570 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2572 if ($biblioitem->{'place'} ne $obi->{'place'}) {
2573 logchange('kohadb', 'change', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
2574 my $q_place=$dbh->quote($biblioitem->{'place'});
2575 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
2576 logchange('marc', 'change', $Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2577 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2579 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
2580 logchange('kohadb', 'change', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2581 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
2582 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
2583 logchange('marc', 'change', $Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2584 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2586 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
2587 logchange('kohadb', 'change', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2588 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
2589 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
2590 logchange('marc', 'change', $Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2591 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2593 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
2594 logchange('kohadb', 'change', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
2595 my $q_illus=$dbh->quote($biblioitem->{'illus'});
2596 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
2597 logchange('marc', 'change', $Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2598 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2600 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
2601 logchange('kohadb', 'change', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
2602 my $q_pages=$dbh->quote($biblioitem->{'pages'});
2603 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
2604 logchange('marc', 'change', $Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2605 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2607 if ($biblioitem->{'size'} ne $obi->{'size'}) {
2608 logchange('kohadb', 'change', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
2609 my $q_size=$dbh->quote($biblioitem->{'size'});
2610 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
2611 logchange('marc', 'change', $Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2612 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2614 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
2615 logchange('kohadb', 'change', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
2616 my $q_notes=$dbh->quote($biblioitem->{'notes'});
2617 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
2618 logchange('marc', 'change', $Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2619 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2621 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
2622 logchange('kohadb', 'change', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
2623 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
2624 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
2625 logchange('marc', 'change', $Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2626 changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2633 sub OLD_MAYBE_DELETED_updateItem {
2634 # Update the item with itemnumber $item->{'itemnumber'}
2635 # This routine should also modify the corresponding MARC record data. (852 and
2636 # 876 tags with 876p tag the same as $item->{'barcode'}
2638 # This routine should also check to see which fields are actually being
2639 # modified, and log all changes.
2641 my ($env, $item) = @_;
2643 my $itemnumber=$item->{'itemnumber'};
2644 my $biblionumber=$item->{'biblionumber'};
2645 my $biblioitemnumber=$item->{'biblioitemnumber'};
2646 my $barcode=$item->{'barcode'};
2647 my $dateaccessioned=$item->{'dateaccessioned'};
2648 my $booksellerid=$item->{'booksellerid'};
2649 my $homebranch=$item->{'homebranch'};
2650 my $price=$item->{'price'};
2651 my $replacementprice=$item->{'replacementprice'};
2652 my $replacementpricedate=$item->{'replacementpricedate'};
2653 my $multivolume=$item->{'multivolume'};
2654 my $stack=$item->{'stack'};
2655 my $notforloan=$item->{'notforloan'};
2656 my $itemlost=$item->{'itemlost'};
2657 my $wthdrawn=$item->{'wthdrawn'};
2658 my $bulk=$item->{'bulk'};
2659 my $restricted=$item->{'restricted'};
2660 my $binding=$item->{'binding'};
2661 my $itemnotes=$item->{'itemnotes'};
2662 my $holdingbranch=$item->{'holdingbranch'};
2663 my $interim=$item->{'interim'};
2664 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
2666 my $olditem=$sth->fetchrow_hashref;
2667 my $q_barcode=$dbh->quote($olditem->{'barcode'});
2668 $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");
2670 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
2671 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
2673 my ($link) = $sth->fetchrow;
2674 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
2676 my ($Subfield852_ID) = $sth->fetchrow;
2678 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
2679 logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
2680 my $q_barcode=$dbh->quote($item->{'barcode'});
2681 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
2683 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
2684 logchange('marc', 'change', $Record_ID, '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
2686 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
2687 logchange('kohadb', 'change', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
2688 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
2689 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
2691 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
2692 logchange('marc', 'change', $Record_ID, '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
2694 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
2695 logchange('kohadb', 'change', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2696 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
2697 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
2699 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
2700 logchange('marc', 'change', $Record_ID, '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2702 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
2703 logchange('kohadb', 'change', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
2704 my $q_homebranch=$dbh->quote($item->{'homebranch'});
2705 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
2707 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
2708 logchange('marc', 'change', $Record_ID, '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
2710 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
2711 logchange('kohadb', 'change', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2712 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
2713 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
2715 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
2716 logchange('marc', 'change', $Record_ID, '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2718 if ($item->{'price'} ne $olditem->{'price'}) {
2719 logchange('kohadb', 'change', 'items', 'price', $olditem->{'price'}, $item->{'price'});
2720 my $q_price=$dbh->quote($item->{'price'});
2721 my $sth=$dbh->prepare("update items set price=$q_price where itemnumber=$itemnumber");
2723 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'price'}, $item->{'price'}, $Subfield876_ID);
2724 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'price'}, $item->{'price'});
2726 if ($item->{'itemnotes'} ne $olditem->{'itemnotes'}) {
2727 logchange('kohadb', 'change', 'items', 'itemnotes', $olditem->{'itemnotes'}, $item->{'itemnotes'});
2728 my $q_itemnotes=$dbh->quote($item->{'itemnotes'});
2729 my $sth=$dbh->prepare("update items set itemnotes=$q_itemnotes where itemnumber=$itemnumber");
2731 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'itemnotes'}, $item->{'itemnotes'}, $Subfield876_ID);
2732 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'itemnotes'}, $item->{'itemnotes'});
2734 if ($item->{'notforloan'} ne $olditem->{'notforloan'}) {
2735 logchange('kohadb', 'change', 'items', 'notforloan', $olditem->{'notforloan'}, $item->{'notforloan'});
2736 my $sth=$dbh->prepare("update items set notforloan=$notforloan where itemnumber=$itemnumber");
2738 if ($item->{'notforloan'}) {
2739 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2740 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2742 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2743 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2746 if ($item->{'itemlost'} ne $olditem->{'itemlost'}) {
2747 logchange('kohadb', 'change', 'items', 'itemlost', $olditem->{'itemlost'}, $item->{'itemlost'});
2748 my $sth=$dbh->prepare("update items set itemlost=$itemlost where itemnumber=$itemnumber");
2750 if ($item->{'itemlost'}) {
2751 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2752 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2754 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2755 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2758 if ($item->{'wthdrawn'} ne $olditem->{'wthdrawn'}) {
2759 logchange('kohadb', 'change', 'items', 'wthdrawn', $olditem->{'wthdrawn'}, $item->{'wthdrawn'});
2760 my $sth=$dbh->prepare("update items set wthdrawn=$wthdrawn where itemnumber=$itemnumber");
2762 if ($item->{'wthdrawn'}) {
2763 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2764 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2766 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2767 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2770 if ($item->{'restricted'} ne $olditem->{'restricted'}) {
2771 logchange('kohadb', 'change', 'items', 'restricted', $olditem->{'restricted'}, $item->{'restricted'});
2772 my $sth=$dbh->prepare("update items set restricted=$restricted where itemnumber=$itemnumber");
2774 if ($item->{'restricted'}) {
2775 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2776 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2778 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2779 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2786 # Add a biblioitem and related data to Koha database
2787 sub OLD_MAY_BE_DELETED_newcompletebiblioitem {
2792 $biblio, # hash ref to biblio record
2793 $biblioitem, # hash ref to biblioitem record
2794 $subjects, # list ref of subjects
2795 $addlauthors, # list ref of additional authors
2798 my ( $biblionumber, $biblioitemnumber, $error); # return values
2803 my $additionalauthor;
2806 requireDBI($dbh,"newcompletebiblioitem");
2808 print "<PRE>Trying to add biblio item Title=$biblio->{title} " .
2809 "ISBN=$biblioitem->{isbn} </PRE>\n" if $debug;
2811 # Make sure master biblio entry exists
2812 ($biblionumber,$error)=getoraddbiblio($dbh, $biblio);
2816 $biblioitem->{biblionumber}=$biblionumber;
2819 $biblioitemnumber=newbiblioitem($biblioitem);
2822 $sth=$dbh->prepare("insert into bibliosubject
2823 (biblionumber,subject)
2825 foreach $subjectheading (@{$subjects} ) {
2826 $sth->execute($biblionumber, $subjectheading)
2827 or $error.=$sth->errstr ;
2831 # Add additional authors
2832 $sth=$dbh->prepare("insert into additionalauthors
2833 (biblionumber,author)
2835 foreach $additionalauthor (@{$addlauthors} ) {
2836 $sth->execute($biblionumber, $additionalauthor)
2837 or $error.=$sth->errstr ;
2841 # couldn't get biblio
2843 $biblioitemnumber='';
2845 } # if no biblio error
2847 return ( $biblionumber, $biblioitemnumber, $error);
2849 } # sub newcompletebiblioitem
2853 # END OF UNUSEFUL SUBs
2857 END { } # module clean-up code here (global destructor)