4 # Revision 1.12 2002/10/01 11:48:51 arensb
5 # Added some FIXME comments, mostly marking duplicate functions.
7 # Revision 1.11 2002/09/24 13:49:26 tipaul
8 # long WAS the road to 1.3.0...
9 # coming VERY SOON NOW...
10 # modifying installer and buildrelease to update the DB
12 # Revision 1.10 2002/09/22 16:50:08 arensb
13 # Added some FIXME comments.
15 # Revision 1.9 2002/09/20 12:57:46 tipaul
16 # long is the road to 1.4.0
17 # * MARCadditem and MARCmoditem now wroks
18 # * various bugfixes in MARC management
19 # !!! 1.3.0 should be released very soon now. Be careful !!!
21 # Revision 1.8 2002/09/10 13:53:52 tipaul
22 # MARC API continued...
24 # * 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)
26 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
28 # Revision 1.7 2002/08/14 18:12:51 tonnesen
29 # Added copyright statement to all .pl and .pm files
31 # Revision 1.6 2002/07/25 13:40:31 tipaul
32 # pod documenting the API.
34 # Revision 1.5 2002/07/24 16:11:37 tipaul
36 # Database.pm and Output.pm are almost not modified (var test...)
38 # Biblio.pm is almost completly rewritten.
40 # WHAT DOES IT ??? ==> END of Hitchcock suspens
42 # 1st, it does... nothing...
43 # 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 ...
45 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
46 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
47 # * 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.
48 # * 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.
49 # 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 ;-)
51 # 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.
52 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
56 # move from 1.2 to 1.4 version :
57 # 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
58 # In the 1.4 version, we want to do 2 differents things :
59 # - keep populating the old-DB, that has a LOT less datas than MARC
60 # - populate the MARC-DB
61 # To populate the DBs we have 2 differents sources :
62 # - the standard acquisition system (through book sellers), that does'nt use MARC data
63 # - the MARC acquisition system, that uses MARC data.
65 # thus, we have 2 differents cases :
66 # - 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
67 # - 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.
68 # we MUST have an API for true MARC data, that populate MARC-DB then old-DB
70 # That's why we need 4 subs :
71 # all subs beginning by MARC manage only MARC tables. They manage MARC-DB with MARC::Record parameters
72 # all subs beginning by OLD manage only OLD-DB tables. They manage old-DB with old-DB parameters
73 # 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
74 # 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.
76 # only ALL and old-style API should be used in koha. MARC and OLD is used internally only
78 # 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.
79 # 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 ;-)
83 # Copyright 2000-2002 Katipo Communications
85 # This file is part of Koha.
87 # Koha is free software; you can redistribute it and/or modify it under the
88 # terms of the GNU General Public License as published by the Free Software
89 # Foundation; either version 2 of the License, or (at your option) any later
92 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
93 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
94 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
96 # You should have received a copy of the GNU General Public License along with
97 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
98 # Suite 330, Boston, MA 02111-1307 USA
105 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
107 # set the version for version checking
112 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
113 # as the old-style API and the ALL one are the only public functions.
116 &updateBiblio &updateBiblioItem &updateItem
117 &itemcount &newbiblio &newbiblioitem
118 &modnote &newsubject &newsubtitle
119 &modbiblio &checkitems
120 &newitems &modbibitem
121 &modsubtitle &modsubject &modaddauthor &moditem &countitems
122 &delitem &deletebiblioitem &delbiblio
123 &getitemtypes &getbiblio
124 &getbiblioitembybiblionumber
125 &getbiblioitem &getitemsbybiblioitem &isbnsearch
127 &newcompletebiblioitem
129 &ALLnewbiblio &ALLnewitem
132 &MARCaddbiblio &MARCadditem
133 &MARCmodsubfield &MARCaddsubfield
134 &MARCmodbiblio &MARCmoditem
136 &MARCkoha2marcBiblio &MARCmarc2koha &MARCkoha2marcItem
137 &MARCgetbiblio &MARCgetitem
138 &MARCaddword &MARCdelword
140 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
142 # your exported package globals go here,
143 # as well as any optionally exported functions
145 @EXPORT_OK = qw($Var1 %Hashit); # FIXME - These are never used
148 # non-exported package globals go here
149 use vars qw(@more $stuff); # FIXME - These are never used
151 # initalize package globals, first exported ones
153 # FIXME - These are never used
158 # then the others (which are still accessible as $Some::Module::stuff)
159 # FIXME - These are never used
163 # all file-scoped lexicals must be created before
164 # the functions below that use them.
166 # file-private lexicals go here
167 # FIXME - These are never used
169 my %secret_hash = ();
171 # here's a file-private function as a closure,
172 # callable as &$priv_func; it cannot be prototyped.
173 # FIXME - This is never used
174 my $priv_func = sub {
178 # make all your functions, whether exported or not;
182 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
185 # all the following subs takes a MARC::Record as parameter and manage
186 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
187 # ALLxxx subs (xxx deals with old-DB parameters, the ALLxxx deals with MARC-DB parameter)
192 all subs requires/use $dbh as 1st parameter.
193 NOTE : all those subs are private and must be used only inside Biblio.pm (called by a old API sub, or the ALLsub)
197 =head2 @tagslib = &MARCgettagslib($dbh,1|0);
198 last param is 1 for liblibrarian and 0 for libopac
199 returns a hash with tag/subfield meaning
201 =head2 ($tagfield,$tagsubfield) = &MARCfindmarc_from_kohafield($dbh,$kohafield);
202 finds MARC tag and subfield for a given kohafield
203 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
205 =head2 $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
206 finds a old-db biblio number for a given MARCbibid number
208 =head2 $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
209 finds a MARC bibid from a old-db biblionumber
211 =head2 &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
212 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
214 =head2 &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
215 adds a subfield in a biblio (in the MARC tables only).
217 =head2 $MARCRecord = &MARCgetbiblio($dbh,$bibid);
218 Returns a MARC::Record for the biblio $bibid.
220 =head2 &MARCmodbiblio($dbh,$bibid,$delete,$record);
221 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
222 if $delete == 1, every field/subfield not found is deleted in the biblio
223 otherwise, only data passed to MARCmodbiblio is managed.
224 thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
226 =head2 ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
227 MARCmodsubfield changes the value of a given subfield
229 =head2 $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
230 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
231 Returns -1 if more than 1 answer
233 =head2 $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
234 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
236 =head2 &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
237 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
239 =head2 &MARCdelbiblio($dbh,$bibid);
240 MARCdelbiblio delete biblio $bibid
242 =head2 $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
243 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
245 =head2 $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
246 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
248 =head2 $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
249 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
251 =head2 &MARCkoha2marcOnefield => used by MARCkoha2marc and should not be useful elsewhere
253 =head2 $olddb = &MARCmarc2koha($dbh,$MARCRecord);
254 builds a hash with old-db datas from a MARC::Record
256 =head2 &MARCmarc2kohaOnefield => used by MARCmarc2koha and should not be useful elsewhere
258 =head2 MARCaddword => used to manage MARC_word table and should not be useful elsewhere
260 =head2 MARCdelword => used to manage MARC_word table and should not be useful elsewhere
264 Paul POULAIN paul.poulain@free.fr
269 my ($dbh,$forlibrarian)= @_;
271 if ($forlibrarian eq 1) {
272 $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib from marc_subfield_structure");
274 $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib from marc_subfield_structure");
281 while ( ($tag,$subfield,$lib) = $sth->fetchrow) {
282 $res->{$tag}->{$subfield}=$lib;
287 sub MARCfind_marc_from_kohafield {
288 my ($dbh,$kohafield) = @_;
289 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
290 $sth->execute($kohafield);
291 my ($tagfield,$tagsubfield) = $sth->fetchrow;
292 return ($tagfield,$tagsubfield);
295 sub MARCfind_oldbiblionumber_from_MARCbibid {
296 my ($dbh,$MARCbibid) = @_;
297 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
298 $sth->execute($MARCbibid);
299 my ($biblionumber) = $sth->fetchrow;
300 return $biblionumber;
303 sub MARCfind_MARCbibid_from_oldbiblionumber {
304 my ($dbh,$oldbiblionumber) = @_;
305 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
306 $sth->execute($oldbiblionumber);
307 my ($bibid) = $sth->fetchrow;
312 # pass the MARC::Record to this function, and it will create the records in the marc tables
313 my ($dbh,$record,$biblionumber) = @_;
314 my @fields=$record->fields();
316 # adding main table, and retrieving bibid
317 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
318 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
319 $sth->execute($biblionumber);
320 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
322 ($bibid)=$sth->fetchrow;
325 # now, add subfields...
326 foreach my $field (@fields) {
327 my @subfields=$field->subfields();
329 foreach my $subfieldcount (0..$#subfields) {
330 &MARCaddsubfield($dbh,$bibid,
332 $field->indicator(1).$field->indicator(2),
334 $subfields[$subfieldcount][0],
336 $subfields[$subfieldcount][1]
340 $dbh->do("unlock tables");
345 # pass the MARC::Record to this function, and it will create the records in the marc tables
346 my ($dbh,$record,$biblionumber) = @_;
347 # search for MARC biblionumber
348 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
349 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
350 my @fields=$record->fields();
351 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
352 $sth->execute($bibid);
353 my ($fieldcount) = $sth->fetchrow;
354 # now, add subfields...
355 foreach my $field (@fields) {
356 my @subfields=$field->subfields();
358 foreach my $subfieldcount (0..$#subfields) {
359 &MARCaddsubfield($dbh,$bibid,
361 $field->indicator(1).$field->indicator(2),
363 $subfields[$subfieldcount][0],
365 $subfields[$subfieldcount][1]
369 $dbh->do("unlock tables");
373 sub MARCaddsubfield {
374 # Add a new subfield to a tag into the DB.
375 my ($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
376 # if not value, end of job, we do nothing
377 if (not($subfieldvalue)) {
380 if (not($subfieldcode)) {
383 if (length($subfieldvalue)>255) {
384 # $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
385 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
386 $sth->execute($subfieldvalue);
387 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
389 my ($res)=$sth->fetchrow;
390 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?)");
392 $sth->execute($bibid,'0'.$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
394 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
397 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
399 # $dbh->do("unlock tables");
401 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?)");
402 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
404 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
407 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
412 # Returns MARC::Record of the biblio passed in parameter.
414 my $record = MARC::Record->new();
415 #---- TODO : the leader is missing
416 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
417 from marc_subfield_table
418 where bibid=? order by tagorder,subfieldorder
420 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
421 $sth->execute($bibid);
422 while (my $row=$sth->fetchrow_hashref) {
423 if ($row->{'valuebloblink'}) { #---- search blob if there is one
424 $sth2->execute($row->{'valuebloblink'});
425 my $row2=$sth2->fetchrow_hashref;
427 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
429 if ($record->field($row->{'tag'})) {
431 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
432 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
433 if (length($row->{'tag'}) <3) {
434 $row->{'tag'} = "0".$row->{'tag'};
436 $field =$record->field($row->{'tag'});
438 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
439 $record->delete_field($field);
440 $record->add_fields($field);
443 if (length($row->{'tag'}) < 3) {
444 $row->{'tag'} = "0".$row->{'tag'};
446 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
447 $record->add_fields($temp);
454 # Returns MARC::Record of the biblio passed in parameter.
455 my ($dbh,$bibid,$itemnumber)=@_;
456 warn "MARCgetitem : $bibid, $itemnumber\n";
457 my $record = MARC::Record->new();
458 # search MARC tagorder
459 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=?");
460 $sth2->execute($bibid,$itemnumber);
461 my ($tagorder) = $sth2->fetchrow_array();
462 #---- TODO : the leader is missing
463 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
464 from marc_subfield_table
465 where bibid=? and tagorder=? order by subfieldorder
467 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
468 $sth->execute($bibid,$tagorder);
469 while (my $row=$sth->fetchrow_hashref) {
470 if ($row->{'valuebloblink'}) { #---- search blob if there is one
471 $sth2->execute($row->{'valuebloblink'});
472 my $row2=$sth2->fetchrow_hashref;
474 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
476 if ($record->field($row->{'tag'})) {
478 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
479 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
480 if (length($row->{'tag'}) <3) {
481 $row->{'tag'} = "0".$row->{'tag'};
483 $field =$record->field($row->{'tag'});
485 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
486 $record->delete_field($field);
487 $record->add_fields($field);
490 if (length($row->{'tag'}) < 3) {
491 $row->{'tag'} = "0".$row->{'tag'};
493 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
494 $record->add_fields($temp);
502 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
503 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
504 # if nothing to change, don't waste time...
505 if ($oldrecord eq $record) {
508 # otherwise, skip through each subfield...
509 my @fields = $record->fields();
511 foreach my $field (@fields) {
512 my $oldfield = $oldrecord->field($field->tag());
513 my @subfields=$field->subfields();
516 foreach my $subfield (@subfields) {
518 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
519 # just adding datas...
520 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
521 1,@$subfield[0],$subfieldorder,@$subfield[1]);
523 # modify he subfield if it's a different string
524 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
525 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
526 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
534 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
535 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
536 # if nothing to change, don't waste time...
537 if ($oldrecord eq $record) {
540 # otherwise, skip through each subfield...
541 my @fields = $record->fields();
542 # search old MARC item
543 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=?");
544 $sth2->execute($bibid,$itemnumber);
545 my ($tagorder) = $sth2->fetchrow_array();
546 foreach my $field (@fields) {
547 my $oldfield = $oldrecord->field($field->tag());
548 my @subfields=$field->subfields();
550 foreach my $subfield (@subfields) {
552 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
553 # just adding datas...
554 warn "ADD = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
555 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
556 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
558 # modify he subfield if it's a different string
559 warn "MODIFY = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
560 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
561 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
562 warn "MODIFY2 = $bibid, $subfieldid, ".@$subfield[1]."\n";
563 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
572 sub MARCmodsubfield {
573 # Subroutine changes a subfield value given a subfieldid.
574 my ($dbh, $subfieldid, $subfieldvalue )=@_;
575 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
576 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
577 $sth1->execute($subfieldid);
578 my ($oldvaluebloblink)=$sth1->fetchrow;
581 # if too long, use a bloblink
582 if (length($subfieldvalue)>255 ) {
583 # if already a bloblink, update it, otherwise, insert a new one.
584 if ($oldvaluebloblink) {
585 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
586 $sth->execute($subfieldvalue,$oldvaluebloblink);
588 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
589 $sth->execute($subfieldvalue);
590 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
592 my ($res)=$sth->fetchrow;
593 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
594 $sth->execute($subfieldid);
597 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
598 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
599 $sth->execute($subfieldvalue, $subfieldid);
601 $dbh->do("unlock tables");
603 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
604 $sth->execute($subfieldid);
605 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
607 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
608 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
609 return($subfieldid, $subfieldvalue);
612 sub MARCfindsubfield {
613 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
617 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
618 if ($subfieldvalue) {
619 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
621 if ($subfieldorder<1) {
624 $query .= " and subfieldorder=$subfieldorder";
626 my $sti=$dbh->prepare($query);
627 $sti->execute($bibid,$tag, $subfieldcode);
628 while (($subfieldid) = $sti->fetchrow) {
630 $lastsubfieldid=$subfieldid;
632 if ($resultcounter>1) {
633 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
634 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
637 return $lastsubfieldid;
641 sub MARCfindsubfieldid {
642 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
643 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
644 where bibid=? and tag=? and tagorder=?
645 and subfieldcode=? and subfieldorder=?");
646 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
647 my ($res) = $sth->fetchrow;
651 sub MARCdelsubfield {
652 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
653 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
654 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
655 tag='$tag' and tagorder='$tagorder'
656 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
661 # delete a biblio for a $bibid
662 my ($dbh,$bibid) = @_;
663 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
664 $dbh->do("delete from marc_biblio where bibid='$bibid'");
667 sub MARCkoha2marcBiblio {
668 # this function builds partial MARC::Record from the old koha-DB fields
669 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
670 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
671 my $record = MARC::Record->new();
672 #--- if bibid, then retrieve old-style koha data
673 if ($biblionumber>0) {
674 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
675 from biblio where biblionumber=?");
676 $sth2->execute($biblionumber);
677 my $row=$sth2->fetchrow_hashref;
679 foreach $code (keys %$row) {
681 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
685 #--- if biblioitem, then retrieve old-style koha data
686 if ($biblioitemnumber>0) {
687 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
688 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
689 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
691 WHERE biblionumber=? and biblioitemnumber=?
693 $sth2->execute($biblionumber,$biblioitemnumber);
694 my $row=$sth2->fetchrow_hashref;
696 foreach $code (keys %$row) {
698 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
703 # TODO : retrieve notes, additionalauthors
706 sub MARCkoha2marcItem {
707 # this function builds partial MARC::Record from the old koha-DB fields
708 my ($dbh,$biblionumber,$itemnumber) = @_;
709 # my $dbh=&C4Connect;
710 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
711 my $record = MARC::Record->new();
712 #--- if item, then retrieve old-style koha data
714 # print STDERR "prepare $biblionumber,$itemnumber\n";
715 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
716 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
717 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
718 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
720 WHERE itemnumber=?");
721 $sth2->execute($itemnumber);
722 my $row=$sth2->fetchrow_hashref;
724 foreach $code (keys %$row) {
726 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
731 # TODO : retrieve notes, additionalauthors
734 sub MARCkoha2marcSubtitle {
735 # this function builds partial MARC::Record from the old koha-DB fields
736 my ($dbh,$bibnum,$subtitle) = @_;
737 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
738 my $record = MARC::Record->new();
739 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
743 sub MARCkoha2marcOnefield {
744 my ($sth,$record,$kohafieldname,$value)=@_;
747 $sth->execute($kohafieldname);
748 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
749 if ($record->field($tagfield)) {
750 my $tag =$record->field($tagfield);
752 $tag->add_subfields($tagsubfield,$value);
753 $record->delete_field($tag);
754 $record->add_fields($tag);
757 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
764 my ($dbh,$record) = @_;
765 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
767 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
770 # print STDERR $record->as_formatted;
771 while (($field)=$sth2->fetchrow) {
772 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
774 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
777 while (($field)=$sth2->fetchrow) {
778 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
780 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
783 while (($field)=$sth2->fetchrow) {
784 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
786 # additional authors : specific
787 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
791 sub MARCmarc2kohaOneField {
792 # to check : if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
793 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
797 $sth->execute($kohatable.".".$kohafield);
798 ($tagfield,$subfield) = $sth->fetchrow;
799 foreach my $field ($record->field($tagfield)) {
800 if ($field->subfield($subfield)) {
801 if ($result->{$kohafield}) {
802 $result->{$kohafield} .= " | ".$field->subfield($subfield);
804 $result->{$kohafield}=$field->subfield($subfield);
812 # split a subfield string and adds it into the word table.
814 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
815 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
816 my @words = split / /,$sentence;
817 # build stopword list
818 my $sth2 =$dbh->prepare("select word from stopwords");
822 while(($stopword) = $sth2->fetchrow_array) {
823 $stopwords->{$stopword} = $stopword;
825 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
826 values (?,?,?,?,?,?,soundex(?))");
827 foreach my $word (@words) {
828 # we record only words longer than 2 car and not in stopwords hash
829 if (length($word)>1 and !($stopwords->{uc($word)})) {
830 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
832 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";
839 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
840 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
841 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
842 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
847 # ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL
850 # all the following subs are useful to manage MARC-DB with complete MARC records.
851 # it's used with marcimport, and marc management tools
856 all subs requires/use $dbh as 1st parameter.
857 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
861 =head2 (oldbibnum,$oldbibitemnum) = ALLnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
862 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
863 are builded from the MARC::Record. If they are passed, they are used.
865 =head2 ALLnewitem($dbh,$olditem);
866 adds an item in the db. $olditem is a old-db hash.
870 Paul POULAIN paul.poulain@free.fr
875 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
876 # note $oldbiblio and $oldbiblioitem are not mandatory.
877 # if not present, they will be builded from $record with MARCmarc2koha function
878 if (($oldbiblio) and not($oldbiblioitem)) {
879 print STDERR "ALLnewbiblio : missing parameter\n";
880 print "ALLnewbiblio : missing parameter : contact koha development team\n";
886 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
887 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
888 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
890 my $olddata = MARCmarc2koha($dbh,$record);
891 $oldbibnum = OLDnewbiblio($dbh,$olddata);
892 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
894 # we must add bibnum and bibitemnum in MARC::Record...
895 # we build the new field with biblionumber and biblioitemnumber
896 # we drop the original field
897 # we add the new builded field.
898 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
899 # (steve and paul : thinks 090 is a good choice)
900 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
901 $sth->execute("biblio.biblionumber");
902 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
903 $sth->execute("biblioitems.biblioitemnumber");
904 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
905 print STDERR "tag1 : $tagfield1 / $tagsubfield1\n tag2 : $tagfield2 / $tagsubfield2\n";
906 if ($tagsubfield1 != $tagsubfield2) {
907 print STDERR "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
908 print "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
911 my $newfield = MARC::Field->new( $tagfield1,'','',
912 "$tagsubfield1" => $oldbibnum,
913 "$tagsubfield2" => $oldbibitemnum);
914 # drop old field and create new one...
915 my $old_field = $record->field($tagfield1);
916 $record->delete_field($old_field);
917 $record->add_fields($newfield);
918 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
919 return ( $oldbibnum,$oldbibitemnum );
923 my ($dbh, $item) = @_;
926 ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{'barcode'});
927 # search MARC biblionumber
928 my $bibid=&MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{'biblionumber'});
930 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
931 $sth->execute($bibid);
932 my ($tagorder) = $sth->fetchrow;
935 # for each field, find MARC tag and subfield, and call the proper MARC sub
936 foreach my $itemkey (keys %$item) {
939 print STDERR "=============> $itemkey : ".$item->{$itemkey}."\n";
940 if ($itemkey eq "biblionumber" || $itemkey eq "biblioitemnumber") {
941 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"biblio.".$itemkey);
943 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"items.".$itemkey);
945 if ($tagfield && $item->{$itemkey} ne 'NULL') {
947 &MARCaddsubfield($dbh,
963 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
969 all subs requires/use $dbh as 1st parameter.
970 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
972 They all are the exact copy of 1.0/1.2 version of the sub
973 without the OLD. The OLDxxx is called by the original xxx sub.
974 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
976 WARNING : there is 1 difference between initialxxx and OLDxxx :
977 the db header $dbh is always passed as parameter
978 to avoid over-DB connexion
982 =head2 $biblionumber = OLDnewbiblio($dbh,$biblio);
983 adds a record in biblio table. Datas are in the hash $biblio.
985 =head2 $biblionumber = OLDmodbiblio($dbh,$biblio);
986 modify a record in biblio table. Datas are in the hash $biblio.
988 =head2 OLDmodsubtitle($dbh,$bibnum,$subtitle);
989 modify subtitles in bibliosubtitle table.
991 =head2 OLDmodaddauthor($dbh,$bibnum,$author);
992 adds or modify additional authors
993 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
995 =head2 $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
998 =head2 OLDmodbibitem($dbh, $biblioitem);
1001 =head2 OLDmodnote($dbh,$bibitemnum,$note
1002 modify a note for a biblioitem
1004 =head2 OLDnewbiblioitem($dbh,$biblioitem);
1005 adds a biblioitem ($biblioitem is a hash with the values)
1007 =head2 OLDnewsubject($dbh,$bibnum);
1009 =head2 OLDnewsubtitle($dbh,$bibnum,$subtitle);
1010 create a new subtitle
1012 =head2 ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1013 create a item. $item is a hash and $barcode the barcode.
1015 =head2 OLDmoditem($dbh,$item);
1018 =head2 OLDdelitem($dbh,$itemnum);
1021 =head2 OLDdeletebiblioitem($dbh,$biblioitemnumber);
1022 deletes a biblioitem
1023 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1025 =head2 OLDdelbiblio($dbh,$biblio);
1030 Paul POULAIN paul.poulain@free.fr
1035 my ($dbh,$biblio) = @_;
1036 # my $dbh = &C4Connect;
1037 my $query = "Select max(biblionumber) from biblio";
1038 my $sth = $dbh->prepare($query);
1040 my $data = $sth->fetchrow_arrayref;
1041 my $bibnum = $$data[0] + 1;
1044 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1045 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1046 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
1047 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
1048 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1049 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1050 if ($biblio->{'seriestitle'}) { $series = 1 };
1053 $query = "insert into biblio set
1054 biblionumber = $bibnum,
1055 title = $biblio->{'title'},
1056 author = $biblio->{'author'},
1057 copyrightdate = $biblio->{'copyright'},
1059 seriestitle = $biblio->{'seriestitle'},
1060 notes = $biblio->{'notes'},
1061 abstract = $biblio->{'abstract'}";
1063 $sth = $dbh->prepare($query);
1072 my ($dbh,$biblio) = @_;
1073 # my $dbh = C4Connect;
1077 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1078 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1079 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1080 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
1081 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
1082 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
1083 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
1084 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1086 $query = "Update biblio set
1087 title = $biblio->{'title'},
1088 author = $biblio->{'author'},
1089 abstract = $biblio->{'abstract'},
1090 copyrightdate = $biblio->{'copyrightdate'},
1091 seriestitle = $biblio->{'seriestitle'},
1092 serial = $biblio->{'serial'},
1093 unititle = $biblio->{'unititle'},
1094 notes = $biblio->{'notes'}
1095 where biblionumber = $biblio->{'biblionumber'}";
1096 $sth = $dbh->prepare($query);
1102 return($biblio->{'biblionumber'});
1105 sub OLDmodsubtitle {
1106 my ($dbh,$bibnum, $subtitle) = @_;
1107 # my $dbh = C4Connect;
1108 my $query = "update bibliosubtitle set
1109 subtitle = '$subtitle'
1110 where biblionumber = $bibnum";
1111 my $sth = $dbh->prepare($query);
1119 sub OLDmodaddauthor {
1120 my ($dbh,$bibnum, $author) = @_;
1121 # my $dbh = C4Connect;
1122 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1123 my $sth = $dbh->prepare($query);
1128 if ($author ne '') {
1129 $query = "Insert into additionalauthors set
1131 biblionumber = '$bibnum'";
1132 $sth = $dbh->prepare($query);
1140 } # sub modaddauthor
1144 my ($dbh,$bibnum, $force, @subject) = @_;
1145 # my $dbh = C4Connect;
1146 my $count = @subject;
1148 for (my $i = 0; $i < $count; $i++) {
1149 $subject[$i] =~ s/^ //g;
1150 $subject[$i] =~ s/ $//g;
1151 my $query = "select * from catalogueentry
1152 where entrytype = 's'
1153 and catalogueentry = '$subject[$i]'";
1154 my $sth = $dbh->prepare($query);
1157 if (my $data = $sth->fetchrow_hashref) {
1159 if ($force eq $subject[$i]) {
1160 # subject not in aut, chosen to force anway
1161 # so insert into cataloguentry so its in auth file
1162 $query = "Insert into catalogueentry
1163 (entrytype,catalogueentry)
1164 values ('s','$subject[$i]')";
1165 my $sth2 = $dbh->prepare($query);
1170 $error = "$subject[$i]\n does not exist in the subject authority file";
1171 $query = "Select * from catalogueentry
1172 where entrytype = 's'
1173 and (catalogueentry like '$subject[$i] %'
1174 or catalogueentry like '% $subject[$i] %'
1175 or catalogueentry like '% $subject[$i]')";
1176 my $sth2 = $dbh->prepare($query);
1179 while (my $data = $sth2->fetchrow_hashref) {
1180 $error = $error."<br>$data->{'catalogueentry'}";
1188 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1189 my $sth = $dbh->prepare($query);
1192 for (my $i = 0; $i < $count; $i++) {
1193 $sth = $dbh->prepare("Insert into bibliosubject
1194 values ('$subject[$i]', $bibnum)");
1206 my ($dbh,$biblioitem) = @_;
1207 # my $dbh = C4Connect;
1210 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1211 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1212 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1213 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1214 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1215 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1216 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1217 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1218 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1219 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1220 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1221 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1222 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1223 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1225 $query = "Update biblioitems set
1226 itemtype = $biblioitem->{'itemtype'},
1227 url = $biblioitem->{'url'},
1228 isbn = $biblioitem->{'isbn'},
1229 publishercode = $biblioitem->{'publishercode'},
1230 publicationyear = $biblioitem->{'publicationyear'},
1231 classification = $biblioitem->{'classification'},
1232 dewey = $biblioitem->{'dewey'},
1233 subclass = $biblioitem->{'subclass'},
1234 illus = $biblioitem->{'illus'},
1235 pages = $biblioitem->{'pages'},
1236 volumeddesc = $biblioitem->{'volumeddesc'},
1237 notes = $biblioitem->{'notes'},
1238 size = $biblioitem->{'size'},
1239 place = $biblioitem->{'place'}
1240 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1248 my ($dbh,$bibitemnum,$note)=@_;
1249 # my $dbh=C4Connect;
1250 my $query="update biblioitems set notes='$note' where
1251 biblioitemnumber='$bibitemnum'";
1252 my $sth=$dbh->prepare($query);
1258 sub OLDnewbiblioitem {
1259 my ($dbh,$biblioitem) = @_;
1260 # my $dbh = C4Connect;
1261 my $query = "Select max(biblioitemnumber) from biblioitems";
1262 my $sth = $dbh->prepare($query);
1266 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
1267 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
1268 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1269 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1270 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1271 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1272 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
1273 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1274 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1275 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1276 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1277 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
1278 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1279 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1280 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1281 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1282 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1283 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1284 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
1285 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
1288 $data = $sth->fetchrow_arrayref;
1289 $bibitemnum = $$data[0] + 1;
1293 $query = "insert into biblioitems set
1294 biblioitemnumber = $bibitemnum,
1295 biblionumber = $biblioitem->{'biblionumber'},
1296 volume = $biblioitem->{'volume'},
1297 number = $biblioitem->{'number'},
1298 classification = $biblioitem->{'classification'},
1299 itemtype = $biblioitem->{'itemtype'},
1300 url = $biblioitem->{'url'},
1301 isbn = $biblioitem->{'isbn'},
1302 issn = $biblioitem->{'issn'},
1303 dewey = $biblioitem->{'dewey'},
1304 subclass = $biblioitem->{'subclass'},
1305 publicationyear = $biblioitem->{'publicationyear'},
1306 publishercode = $biblioitem->{'publishercode'},
1307 volumedate = $biblioitem->{'volumedate'},
1308 volumeddesc = $biblioitem->{'volumeddesc'},
1309 illus = $biblioitem->{'illus'},
1310 pages = $biblioitem->{'pages'},
1311 notes = $biblioitem->{'notes'},
1312 size = $biblioitem->{'size'},
1313 lccn = $biblioitem->{'lccn'},
1314 marc = $biblioitem->{'marc'},
1315 place = $biblioitem->{'place'}";
1317 $sth = $dbh->prepare($query);
1321 return($bibitemnum);
1325 my ($dbh,$bibnum)=@_;
1326 # my $dbh=C4Connect;
1327 my $query="insert into bibliosubject (biblionumber) values
1329 my $sth=$dbh->prepare($query);
1336 sub OLDnewsubtitle {
1337 my ($dbh,$bibnum, $subtitle) = @_;
1338 # my $dbh = C4Connect;
1339 $subtitle = $dbh->quote($subtitle);
1340 my $query = "insert into bibliosubtitle set
1341 biblionumber = $bibnum,
1342 subtitle = $subtitle";
1343 my $sth = $dbh->prepare($query);
1353 my ($dbh,$item, $barcode) = @_;
1354 # my $dbh = C4Connect;
1355 my $query = "Select max(itemnumber) from items";
1356 my $sth = $dbh->prepare($query);
1362 $data = $sth->fetchrow_hashref;
1363 $itemnumber = $data->{'max(itemnumber)'} + 1;
1366 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
1367 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
1368 $item->{'price'} = $dbh->quote($item->{'price'});
1369 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
1370 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
1372 # foreach my $barcode (@barcodes) {
1373 # $barcode = uc($barcode);
1374 $barcode = $dbh->quote($barcode);
1375 $query = "Insert into items set
1376 itemnumber = $itemnumber,
1377 biblionumber = $item->{'biblionumber'},
1378 biblioitemnumber = $item->{'biblioitemnumber'},
1380 booksellerid = $item->{'booksellerid'},
1381 dateaccessioned = NOW(),
1382 homebranch = $item->{'homebranch'},
1383 holdingbranch = $item->{'homebranch'},
1384 price = $item->{'price'},
1385 replacementprice = $item->{'replacementprice'},
1386 replacementpricedate = NOW(),
1387 itemnotes = $item->{'itemnotes'}";
1388 if ($item->{'loan'}) {
1389 $query .= ",notforloan = $item->{'loan'}";
1392 $sth = $dbh->prepare($query);
1394 if (defined $sth->errstr) {
1395 $error .= $sth->errstr;
1400 return($itemnumber,$error);
1404 my ($dbh,$item) = @_;
1405 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1406 # my $dbh=C4Connect;
1407 my $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1408 barcode='$item->{'barcode'}',itemnotes='$item->{'notes'}'
1409 where itemnumber=$item->{'itemnum'}";
1410 if ($item->{'barcode'} eq ''){
1411 $query="update items set biblioitemnumber=$item->{'bibitemnum'},notforloan=$item->{'loan'} where itemnumber=$item->{'itemnum'}";
1413 if ($item->{'lost'} ne ''){
1414 $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1415 barcode='$item->{'barcode'}',
1416 itemnotes='$item->{'notes'}',
1417 homebranch='$item->{'homebranch'}',
1418 itemlost='$item->{'lost'}',
1419 wthdrawn='$item->{'wthdrawn'}'
1420 where itemnumber=$item->{'itemnum'}";
1422 if ($item->{'replacement'} ne ''){
1423 $query=~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1426 my $sth=$dbh->prepare($query);
1432 # FIXME - A nearly-identical function, &delitem, appears in
1435 my ($dbh,$itemnum)=@_;
1436 # my $dbh=C4Connect;
1437 my $query="select * from items where itemnumber=$itemnum";
1438 my $sth=$dbh->prepare($query);
1440 my @data=$sth->fetchrow_array;
1442 $query="Insert into deleteditems values (";
1443 foreach my $temp (@data){
1444 $query=$query."'$temp',";
1448 $sth=$dbh->prepare($query);
1451 $query = "Delete from items where itemnumber=$itemnum";
1452 $sth=$dbh->prepare($query);
1458 sub OLDdeletebiblioitem {
1459 my ($dbh,$biblioitemnumber) = @_;
1460 # my $dbh = C4Connect;
1461 my $query = "Select * from biblioitems
1462 where biblioitemnumber = $biblioitemnumber";
1463 my $sth = $dbh->prepare($query);
1468 if (@results = $sth->fetchrow_array) {
1469 $query = "Insert into deletedbiblioitems values (";
1470 foreach my $value (@results) {
1471 $value = $dbh->quote($value);
1472 $query .= "$value,";
1475 $query =~ s/\,$/\)/;
1478 $query = "Delete from biblioitems
1479 where biblioitemnumber = $biblioitemnumber";
1483 # Now delete all the items attached to the biblioitem
1484 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1485 $sth = $dbh->prepare($query);
1487 while (@results = $sth->fetchrow_array) {
1488 $query = "Insert into deleteditems values (";
1489 foreach my $value (@results) {
1490 $value = $dbh->quote($value);
1491 $query .= "$value,";
1493 $query =~ s/\,$/\)/;
1497 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1500 } # sub deletebiblioitem
1503 my ($dbh,$biblio)=@_;
1504 # my $dbh=C4Connect;
1505 my $query="select * from biblio where biblionumber=$biblio";
1506 my $sth=$dbh->prepare($query);
1508 if (my @data=$sth->fetchrow_array){
1510 $query="Insert into deletedbiblio values (";
1511 foreach my $temp (@data){
1512 $temp=~ s/\'/\\\'/g;
1513 $query=$query."'$temp',";
1517 $sth=$dbh->prepare($query);
1520 $query = "Delete from biblio where biblionumber=$biblio";
1521 $sth=$dbh->prepare($query);
1535 # FIXME - This is the same as &C4::Acquisitions::itemcount, but not
1536 # the same as &C4::Search::itemcount
1540 my $query="Select count(*) from items where biblionumber=$biblio";
1542 my $sth=$dbh->prepare($query);
1544 my $data=$sth->fetchrow_hashref;
1547 return($data->{'count(*)'});
1553 my $query="Select ordernumber
1555 where biblionumber=? and biblioitemnumber=?";
1556 my $sth=$dbh->prepare($query);
1557 $sth->execute($bib,$bi);
1558 my $ordnum=$sth->fetchrow_hashref;
1560 my $order=getsingleorder($ordnum->{'ordernumber'});
1563 return ($order,$ordnum->{'ordernumber'});
1566 # FIXME - This is practically the same function as
1567 # &C4::Acquisitions::getsingleorder and &C4::Catalogue::getsingleorder
1568 sub getsingleorder {
1571 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1572 where aqorders.ordernumber=?
1573 and biblio.biblionumber=aqorders.biblionumber and
1574 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1575 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1576 my $sth=$dbh->prepare($query);
1577 $sth->execute($ordnum);
1578 my $data=$sth->fetchrow_hashref;
1586 my $dbh = &C4Connect;
1587 my $bibnum=OLDnewbiblio($dbh,$biblio);
1595 my $dbh = C4Connect;
1596 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1598 return($biblionumber);
1602 my ($bibnum, $subtitle) = @_;
1603 my $dbh = C4Connect;
1604 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1609 # FIXME - This is functionally identical to
1610 # &C4::Acquisitions::modaddauthor
1612 my ($bibnum, $author) = @_;
1613 my $dbh = C4Connect;
1614 &OLDmodaddauthor($dbh,$bibnum,$author);
1616 } # sub modaddauthor
1620 my ($bibnum, $force, @subject) = @_;
1621 my $dbh = C4Connect;
1622 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1627 my ($biblioitem) = @_;
1628 my $dbh = C4Connect;
1629 &OLDmodbibitem($dbh,$biblioitem);
1630 my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
1631 &MARCmodbiblio($dbh,$biblioitem->{biblionumber},0,$MARCbibitem);
1636 my ($bibitemnum,$note)=@_;
1638 &OLDmodnote($dbh,$bibitemnum,$note);
1642 # FIXME - This is quite similar in effect to &C4::newbiblioitem,
1643 # except for the MARC stuff.
1645 my ($biblioitem) = @_;
1646 my $dbh = C4Connect;
1647 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1648 # print STDERR "bibitemnum : $bibitemnum\n";
1649 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1650 # print STDERR $MARCbiblio->as_formatted();
1651 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1652 return($bibitemnum);
1658 &OLDnewsubject($dbh,$bibnum);
1662 # FIXME - This is just a wrapper around &OLDnewsubtitle
1663 # FIXME - This is in effect the same as &C4::Acquisitions::newsubtitle
1665 my ($bibnum, $subtitle) = @_;
1666 my $dbh = C4Connect;
1667 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1672 my ($item, @barcodes) = @_;
1673 my $dbh = C4Connect;
1677 foreach my $barcode (@barcodes) {
1678 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1680 # print STDERR "biblionumber : $item->{biblionumber} / MARCbibid : $MARCbibid / itemnumber : $itemnumber\n";
1681 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1682 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1683 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1684 # print STDERR "MARCmodbiblio called\n";
1692 # my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1694 &OLDmoditem($dbh,$item);
1695 warn "biblionumber : $item->{'biblionumber'} / $item->{'itemnum'}\n";
1696 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1697 warn "before MARCmoditem : $item->{biblionumber}, $item->{'itemnum'}\n";
1698 warn $MARCitem->as_formatted();
1699 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1700 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1701 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1706 my ($count,@barcodes)=@_;
1709 for (my $i=0;$i<$count;$i++){
1710 $barcodes[$i]=uc $barcodes[$i];
1711 my $query="Select * from items where barcode='$barcodes[$i]'";
1712 my $sth=$dbh->prepare($query);
1714 if (my $data=$sth->fetchrow_hashref){
1715 $error.=" Duplicate Barcode: $barcodes[$i]";
1724 my ($bibitemnum)=@_;
1726 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1727 my $sth=$dbh->prepare($query);
1729 my $data=$sth->fetchrow_hashref;
1732 return($data->{'count(*)'});
1735 # FIXME - This is just a wrapper around &OLDdelitem, and acts
1736 # identically to &C4::Acquisitions::delitem
1740 &OLDdelitem($dbh,$itemnum);
1744 sub deletebiblioitem {
1745 my ($biblioitemnumber) = @_;
1746 my $dbh = C4Connect;
1747 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1749 } # sub deletebiblioitem
1755 &OLDdelbiblio($dbh,$biblio);
1760 my $dbh = C4Connect;
1761 my $query = "select * from itemtypes";
1762 my $sth = $dbh->prepare($query);
1763 # || die "Cannot prepare $query" . $dbh->errstr;
1768 # || die "Cannot execute $query\n" . $sth->errstr;
1769 while (my $data = $sth->fetchrow_hashref) {
1770 $results[$count] = $data;
1776 return($count, @results);
1777 } # sub getitemtypes
1780 my ($biblionumber) = @_;
1781 my $dbh = C4Connect;
1782 my $query = "Select * from biblio where biblionumber = $biblionumber";
1783 my $sth = $dbh->prepare($query);
1784 # || die "Cannot prepare $query\n" . $dbh->errstr;
1789 # || die "Cannot execute $query\n" . $sth->errstr;
1790 while (my $data = $sth->fetchrow_hashref) {
1791 $results[$count] = $data;
1797 return($count, @results);
1801 my ($biblioitemnum) = @_;
1802 my $dbh = C4Connect;
1803 my $query = "Select * from biblioitems where
1804 biblioitemnumber = $biblioitemnum";
1805 my $sth = $dbh->prepare($query);
1811 while (my $data = $sth->fetchrow_hashref) {
1812 $results[$count] = $data;
1818 return($count, @results);
1819 } # sub getbiblioitem
1821 sub getbiblioitembybiblionumber {
1822 my ($biblionumber) = @_;
1823 my $dbh = C4Connect;
1824 my $query = "Select * from biblioitems where biblionumber =
1826 my $sth = $dbh->prepare($query);
1832 while (my $data = $sth->fetchrow_hashref) {
1833 $results[$count] = $data;
1839 return($count, @results);
1842 sub getitemsbybiblioitem {
1843 my ($biblioitemnum) = @_;
1844 my $dbh = C4Connect;
1845 my $query = "Select * from items, biblio where
1846 biblio.biblionumber = items.biblionumber and biblioitemnumber
1848 my $sth = $dbh->prepare($query);
1849 # || die "Cannot prepare $query\n" . $dbh->errstr;
1854 # || die "Cannot execute $query\n" . $sth->errstr;
1855 while (my $data = $sth->fetchrow_hashref) {
1856 $results[$count] = $data;
1862 return($count, @results);
1863 } # sub getitemsbybiblioitem
1867 my $dbh = C4Connect;
1873 $isbn = $dbh->quote($isbn);
1874 $query = "Select biblio.* from biblio, biblioitems where
1875 biblio.biblionumber = biblioitems.biblionumber
1877 $sth = $dbh->prepare($query);
1880 while (my $data = $sth->fetchrow_hashref) {
1881 $results[$count] = $data;
1887 return($count, @results);
1891 # At the moment this is just a straight copy of the subject code. Needs heavy
1892 # modification to work for additional authors, obviously.
1893 # Check for additional author changes
1895 # my $newadditionalauthor='';
1896 # my $additionalauthors;
1897 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
1898 # $additionalauthors->{$newadditionalauthor}=1;
1899 # if ($origadditionalauthors->{$newadditionalauthor}) {
1900 # $additionalauthors->{$newadditionalauthor}=2;
1902 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
1903 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
1905 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
1907 # $subfields->{1}->{'Subfield_Mark'}='a';
1908 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
1911 # foreach $Record_ID (@marcrecords) {
1912 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1913 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
1917 # my $origadditionalauthor;
1918 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
1919 # if ($additionalauthors->{$origadditionalauthor} == 1) {
1920 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
1921 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
1922 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
1932 # Subroutine to log changes to databases
1933 # Eventually, this subroutine will be used to create a log of all changes made,
1934 # with the possibility of "undo"ing some changes
1936 if ($database eq 'kohadb') {
1942 print STDERR "KOHA: $type $section $item $original $new\n";
1943 } elsif ($database eq 'marc') {
1945 my $Record_ID=shift;
1948 my $subfield_ID=shift;
1951 print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
1955 #------------------------------------------------
1958 #---------------------------------------
1959 # Find a biblio entry, or create a new one if it doesn't exist.
1960 # If a "subtitle" entry is in hash, add it to subtitle table
1961 sub getoraddbiblio {
1965 $biblio, # hash ref to fields
1976 requireDBI($dbh,"getoraddbiblio");
1978 print "<PRE>Looking for biblio </PRE>\n" if $debug;
1979 $sth=$dbh->prepare("select biblionumber
1981 where title=? and author=?
1982 and copyrightdate=? and seriestitle=?");
1984 $biblio->{title}, $biblio->{author},
1985 $biblio->{copyright}, $biblio->{seriestitle} );
1987 ($biblionumber) = $sth->fetchrow;
1988 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
1990 # Doesn't exist. Add new one.
1991 print "<PRE>Adding biblio</PRE>\n" if $debug;
1992 ($biblionumber,$error)=&newbiblio($biblio);
1993 if ( $biblionumber ) {
1994 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
1995 if ( $biblio->{subtitle} ) {
1996 &newsubtitle($biblionumber,$biblio->{subtitle} );
1999 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2003 return $biblionumber,$error;
2005 } # sub getoraddbiblio
2009 # UNUSEFUL SUBs. Could be deleted, kept only until beta test
2010 # maybe useful for some MARC tricks steve used.
2013 sub OLD_MAYBE_DELETED_newBiblioItem {
2014 my ($env, $biblioitem) = @_;
2016 my $biblionumber=$biblioitem->{'biblionumber'};
2017 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2018 my $volume=$biblioitem->{'volume'};
2019 my $q_volume=$dbh->quote($volume);
2020 my $number=$biblioitem->{'number'};
2021 my $q_number=$dbh->quote($number);
2022 my $classification=$biblioitem->{'classification'};
2023 my $q_classification=$dbh->quote($classification);
2024 my $itemtype=$biblioitem->{'itemtype'};
2025 my $q_itemtype=$dbh->quote($itemtype);
2026 my $isbn=$biblioitem->{'isbn'};
2027 my $q_isbn=$dbh->quote($isbn);
2028 my $issn=$biblioitem->{'issn'};
2029 my $q_issn=$dbh->quote($issn);
2030 my $dewey=$biblioitem->{'dewey'};
2032 ($dewey == 0) && ($dewey='');
2033 my $subclass=$biblioitem->{'subclass'};
2034 my $q_subclass=$dbh->quote($subclass);
2035 my $publicationyear=$biblioitem->{'publicationyear'};
2036 my $publishercode=$biblioitem->{'publishercode'};
2037 my $q_publishercode=$dbh->quote($publishercode);
2038 my $volumedate=$biblioitem->{'volumedate'};
2039 my $q_volumedate=$dbh->quote($volumedate);
2040 my $illus=$biblioitem->{'illus'};
2041 my $q_illus=$dbh->quote($illus);
2042 my $pages=$biblioitem->{'pages'};
2043 my $q_pages=$dbh->quote($pages);
2044 my $notes=$biblioitem->{'notes'};
2045 my $q_notes=$dbh->quote($notes);
2046 my $size=$biblioitem->{'size'};
2047 my $q_size=$dbh->quote($size);
2048 my $place=$biblioitem->{'place'};
2049 my $q_place=$dbh->quote($place);
2050 my $lccn=$biblioitem->{'lccn'};
2051 my $q_lccn=$dbh->quote($lccn);
2054 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
2057 unless ($env->{'marconly'}) {
2058 #my $sth=$dbh->prepare("lock tables biblioitems write");
2060 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
2062 my ($biblioitemnumber) =$sth->fetchrow;
2063 $biblioitemnumber++;
2064 $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)");
2066 #my $sth=$dbh->prepare("unlock tables");
2071 # Should we check if there is already a biblioitem/amrc with the
2072 # same isbn/lccn/issn?
2074 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
2076 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
2077 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2079 my ($subtitle) = $sth->fetchrow;
2080 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2082 my @additionalauthors;
2083 while (my ($additionalauthor) = $sth->fetchrow) {
2084 push (@additionalauthors, $additionalauthor);
2086 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2089 while (my ($subject) = $sth->fetchrow) {
2090 push (@subjects, $subject);
2095 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
2097 my $Resource_ID=$dbh->{'mysql_insertid'};
2098 my $Record_ID=$Resource_ID;
2099 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
2105 $subfields->{1}->{'Subfield_Mark'}='a';
2106 $subfields->{1}->{'Subfield_Value'}=$title;
2108 $subfields->{2}->{'Subfield_Mark'}='b';
2109 $subfields->{2}->{'Subfield_Value'}=$subtitle;
2112 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2118 $subfields->{1}->{'Subfield_Mark'}='a';
2119 $subfields->{1}->{'Subfield_Value'}=$author;
2121 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2126 $subfields->{1}->{'Subfield_Mark'}='a';
2127 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
2129 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2134 $subfields->{1}->{'Subfield_Mark'}='a';
2135 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
2136 $subfields->{2}->{'Subfield_Mark'}='3';
2137 $subfields->{2}->{'Subfield_Value'}='biblio';
2139 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2141 # Additional Authors
2142 foreach (@additionalauthors) {
2144 (next) unless ($author);
2146 $subfields->{1}->{'Subfield_Mark'}='a';
2147 $subfields->{1}->{'Subfield_Value'}=$author;
2148 $subfields->{2}->{'Subfield_Mark'}='e';
2149 $subfields->{2}->{'Subfield_Value'}='author';
2151 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2155 (next) unless ($illus);
2157 $subfields->{1}->{'Subfield_Mark'}='a';
2158 $subfields->{1}->{'Subfield_Value'}=$illus;
2159 $subfields->{2}->{'Subfield_Mark'}='e';
2160 $subfields->{2}->{'Subfield_Value'}='illustrator';
2162 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2165 foreach (@subjects) {
2167 (next) unless ($subject);
2169 $subfields->{1}->{'Subfield_Mark'}='a';
2170 $subfields->{1}->{'Subfield_Value'}=$subject;
2172 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2179 $subfields->{1}->{'Subfield_Mark'}='a';
2180 $subfields->{1}->{'Subfield_Value'}=$isbn;
2182 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2187 $subfields->{1}->{'Subfield_Mark'}='a';
2188 $subfields->{1}->{'Subfield_Value'}=$lccn;
2190 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2195 $subfields->{1}->{'Subfield_Mark'}='a';
2196 $subfields->{1}->{'Subfield_Value'}=$issn;
2198 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2203 $subfields->{1}->{'Subfield_Mark'}='a';
2204 $subfields->{1}->{'Subfield_Value'}=$dewey;
2206 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2208 # DEWEY subclass and itemtype
2211 $subfields->{1}->{'Subfield_Mark'}='a';
2212 $subfields->{1}->{'Subfield_Value'}=$itemtype;
2213 $subfields->{2}->{'Subfield_Mark'}='b';
2214 $subfields->{2}->{'Subfield_Value'}=$subclass;
2215 $subfields->{3}->{'Subfield_Mark'}='c';
2216 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
2217 $subfields->{4}->{'Subfield_Mark'}='d';
2218 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
2220 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2225 $subfields->{1}->{'Subfield_Mark'}='a';
2226 $subfields->{1}->{'Subfield_Value'}=$place;
2227 $subfields->{2}->{'Subfield_Mark'}='b';
2228 $subfields->{2}->{'Subfield_Value'}=$publishercode;
2229 $subfields->{3}->{'Subfield_Mark'}='c';
2230 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
2231 if ($copyrightdate) {
2232 $subfields->{4}->{'Subfield_Mark'}='c';
2233 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
2236 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2239 if ($pages || $size) {
2241 $subfields->{1}->{'Subfield_Mark'}='a';
2242 $subfields->{1}->{'Subfield_Value'}=$pages;
2243 $subfields->{2}->{'Subfield_Mark'}='c';
2244 $subfields->{2}->{'Subfield_Value'}=$size;
2246 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2249 if ($volume || $number) {
2251 $subfields->{1}->{'Subfield_Mark'}='v';
2252 $subfields->{1}->{'Subfield_Value'}=$volume;
2253 $subfields->{2}->{'Subfield_Mark'}='n';
2254 $subfields->{2}->{'Subfield_Value'}=$number;
2256 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2261 $subfields->{1}->{'Subfield_Mark'}='a';
2262 $subfields->{1}->{'Subfield_Value'}=$notes;
2263 $subfields->{2}->{'Subfield_Mark'}='3';
2264 $subfields->{2}->{'Subfield_Value'}='biblioitem';
2266 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2270 return ($env, $Record_ID);
2273 sub OLD_MAYBE_DELETED_newItem {
2274 my ($env, $Record_ID, $item) = @_;
2276 my $barcode=$item->{'barcode'};
2277 my $q_barcode=$dbh->quote($barcode);
2278 my $biblionumber=$item->{'biblionumber'};
2279 my $biblioitemnumber=$item->{'biblioitemnumber'};
2280 my $dateaccessioned=$item->{'dateaccessioned'};
2281 my $booksellerid=$item->{'booksellerid'};
2282 my $q_booksellerid=$dbh->quote($booksellerid);
2283 my $homebranch=$item->{'homebranch'};
2284 my $q_homebranch=$dbh->quote($homebranch);
2285 my $holdingbranch=$item->{'holdingbranch'};
2286 my $price=$item->{'price'};
2287 my $replacementprice=$item->{'replacementprice'};
2288 my $replacementpricedate=$item->{'replacementpricedate'};
2289 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
2290 my $notforloan=$item->{'notforloan'};
2291 my $itemlost=$item->{'itemlost'};
2292 my $wthdrawn=$item->{'wthdrawn'};
2293 my $restricted=$item->{'restricted'};
2294 my $itemnotes=$item->{'itemnotes'};
2295 my $q_itemnotes=$dbh->quote($itemnotes);
2296 my $itemtype=$item->{'itemtype'};
2297 my $subclass=$item->{'subclass'};
2301 unless ($env->{'marconly'}) {
2302 my $sth=$dbh->prepare("select max(itemnumber) from items");
2304 my ($itemnumber) =$sth->fetchrow;
2306 $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)");
2313 $subfields->{1}->{'Subfield_Mark'}='p';
2314 $subfields->{1}->{'Subfield_Value'}=$barcode;
2315 $subfields->{2}->{'Subfield_Mark'}='d';
2316 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
2317 $subfields->{3}->{'Subfield_Mark'}='e';
2318 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
2319 $subfields->{4}->{'Subfield_Mark'}='b';
2320 $subfields->{4}->{'Subfield_Value'}=$homebranch;
2321 $subfields->{5}->{'Subfield_Mark'}='l';
2322 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
2323 $subfields->{6}->{'Subfield_Mark'}='c';
2324 $subfields->{6}->{'Subfield_Value'}=$price;
2325 $subfields->{7}->{'Subfield_Mark'}='c';
2326 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
2327 $subfields->{8}->{'Subfield_Mark'}='d';
2328 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
2330 $subfields->{9}->{'Subfield_Mark'}='h';
2331 $subfields->{9}->{'Subfield_Value'}='Not for loan';
2334 $subfields->{10}->{'Subfield_Mark'}='j';
2335 $subfields->{10}->{'Subfield_Value'}='Item lost';
2338 $subfields->{11}->{'Subfield_Mark'}='j';
2339 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
2342 $subfields->{12}->{'Subfield_Mark'}='z';
2343 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
2347 $env->{'linkage'}=1;
2348 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2349 $env->{'linkage'}=0;
2350 $env->{'linkid'}=$Tag_ID;
2353 $subfields2->{1}->{'Subfield_Mark'}='a';
2354 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
2355 $subfields2->{1}->{'Subfield_Mark'}='b';
2356 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
2357 $subfields2->{1}->{'Subfield_Mark'}='c';
2358 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
2359 $subfields2->{2}->{'Subfield_Mark'}='m';
2360 $subfields2->{2}->{'Subfield_Value'}=$subclass;
2361 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
2362 $env->{'linkid'}='';
2365 sub OLD_MAYBE_DELETED_updateBiblio {
2366 # Update the biblio with biblionumber $biblio->{'biblionumber'}
2367 # I guess this routine should search through all marc records for a record that
2368 # has the same biblionumber stored in it, and modify the MARC record as well as
2371 # Also, this subroutine should search through the $biblio object and compare it
2372 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
2373 # this logging feature to be usable to undo changes easily.
2375 my ($env, $biblio) = @_;
2377 my $biblionumber=$biblio->{'biblionumber'};
2379 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
2381 my $origbiblio=$sth->fetchrow_hashref;
2382 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2384 my ($subtitle)=$sth->fetchrow;
2385 $origbiblio->{'subtitle'}=$subtitle;
2386 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2388 my $origadditionalauthors;
2389 while (my ($author) = $sth->fetchrow) {
2390 push (@{$origbiblio->{'additionalauthors'}}, $author);
2391 $origadditionalauthors->{$author}=1;
2393 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2396 while (my ($subject) = $sth->fetchrow) {
2397 push (@{$origbiblio->{'subjects'}}, $subject);
2398 $origsubjects->{$subject}=1;
2402 # Obtain a list of MARC Record_ID's that are tied to this biblio
2403 $sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
2406 while (my ($bibid) = $sth->fetchrow) {
2407 push(@marcrecords, $bibid);
2411 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
2412 my $q_author=$dbh->quote($biblio->{'author'});
2413 logchange('kohadb', 'change', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
2414 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
2416 foreach $bibid (@marcrecords) {
2417 logchange('marc', 'change', $bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2418 changeSubfield($bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2421 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
2422 my $q_title=$dbh->quote($biblio->{'title'});
2423 logchange('kohadb', 'change', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
2424 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
2426 foreach $Record_ID (@marcrecords) {
2427 logchange('marc', 'change', $Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2428 changeSubfield($Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2431 if ($biblio->{'subtitle'} ne $origbiblio->{'subtitle'}) {
2432 my $q_subtitle=$dbh->quote($biblio->{'subtitle'});
2433 logchange('kohadb', 'change', 'biblio', 'subtitle', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2434 my $sti=$dbh->prepare("update bibliosubtitle set subtitle=$q_subtitle where biblionumber=$biblio->{'biblionumber'}");
2436 foreach $Record_ID (@marcrecords) {
2437 logchange('marc', 'change', $Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2438 changeSubfield($Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2441 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
2442 my $q_unititle=$dbh->quote($biblio->{'unititle'});
2443 logchange('kohadb', 'change', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
2444 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
2447 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
2448 my $q_notes=$dbh->quote($biblio->{'notes'});
2449 logchange('kohadb', 'change', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
2450 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
2452 foreach $Record_ID (@marcrecords) {
2453 logchange('marc', 'change', $Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2454 changeSubfield($Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2457 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
2458 my $q_serial=$dbh->quote($biblio->{'serial'});
2459 logchange('kohadb', 'change', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
2460 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
2463 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
2464 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
2465 logchange('kohadb', 'change', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2466 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
2468 foreach $Record_ID (@marcrecords) {
2469 logchange('marc', 'change', $Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2470 changeSubfield($Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2473 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
2474 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
2475 logchange('kohadb', 'change', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
2476 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
2478 foreach $Record_ID (@marcrecords) {
2479 logchange('marc', 'change', $Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2480 changeSubfield($Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2484 # Check for subject heading changes
2488 foreach $newsubject (@{$biblio->{'subject'}}) {
2489 $subjects->{$newsubject}=1;
2490 if ($origsubjects->{$newsubject}) {
2491 $subjects->{$newsubject}=2;
2493 my $q_newsubject=$dbh->quote($newsubject);
2494 my $sth=$dbh->prepare("insert into bibliosubject (subject,biblionumber) values ($q_newsubject, $biblionumber)");
2496 logchange('kohadb', 'add', 'biblio', 'subject', $newsubject);
2498 $subfields->{1}->{'Subfield_Mark'}='a';
2499 $subfields->{1}->{'Subfield_Value'}=$newsubject;
2502 foreach $Record_ID (@marcrecords) {
2503 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2504 logchange('marc', 'add', $Record_ID, '650', 'a', $newsubject);
2509 foreach $origsubject (keys %$origsubjects) {
2510 if ($subjects->{$origsubject} == 1) {
2511 my $q_origsubject=$dbh->quote($origsubject);
2512 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'subject', $origsubject);
2513 my $sth=$dbh->prepare("delete from bibliosubject where biblionumber=$biblionumber and subject=$q_origsubject");
2519 sub OLD_MAYBE_DELETED_updateBiblioItem {
2520 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
2522 # This routine should also check to see which fields are actually being
2523 # modified, and log all changes.
2525 my ($env, $biblioitem) = @_;
2528 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2529 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
2530 # obi = original biblioitem
2531 my $obi=$sth->fetchrow_hashref;
2532 $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");
2534 my ($Record_ID) = $sth->fetchrow;
2535 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
2536 logchange('kohadb', 'change', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2537 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
2538 logchange('marc', 'change', $Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2539 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2541 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
2542 logchange('kohadb', 'change', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
2543 my $q_volume=$dbh->quote($biblioitem->{'volume'});
2544 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
2545 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2546 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2548 if ($biblioitem->{'number'} ne $obi->{'number'}) {
2549 logchange('kohadb', 'change', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
2550 my $q_number=$dbh->quote($biblioitem->{'number'});
2551 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
2552 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2553 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2555 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
2556 logchange('kohadb', 'change', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2557 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
2558 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
2559 logchange('marc', 'change', $Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2560 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2562 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
2563 logchange('kohadb', 'change', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
2564 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
2565 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
2566 logchange('marc', 'change', $Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2567 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2569 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
2570 logchange('kohadb', 'change', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
2571 my $q_issn=$dbh->quote($biblioitem->{'issn'});
2572 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
2573 logchange('marc', 'change', $Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2574 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2576 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
2577 logchange('kohadb', 'change', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
2578 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
2579 logchange('marc', 'change', $Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2580 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2582 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
2583 logchange('kohadb', 'change', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
2584 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
2585 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
2586 logchange('marc', 'change', $Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2587 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2589 if ($biblioitem->{'place'} ne $obi->{'place'}) {
2590 logchange('kohadb', 'change', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
2591 my $q_place=$dbh->quote($biblioitem->{'place'});
2592 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
2593 logchange('marc', 'change', $Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2594 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2596 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
2597 logchange('kohadb', 'change', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2598 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
2599 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
2600 logchange('marc', 'change', $Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2601 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2603 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
2604 logchange('kohadb', 'change', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2605 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
2606 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
2607 logchange('marc', 'change', $Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2608 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2610 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
2611 logchange('kohadb', 'change', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
2612 my $q_illus=$dbh->quote($biblioitem->{'illus'});
2613 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
2614 logchange('marc', 'change', $Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2615 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2617 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
2618 logchange('kohadb', 'change', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
2619 my $q_pages=$dbh->quote($biblioitem->{'pages'});
2620 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
2621 logchange('marc', 'change', $Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2622 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2624 if ($biblioitem->{'size'} ne $obi->{'size'}) {
2625 logchange('kohadb', 'change', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
2626 my $q_size=$dbh->quote($biblioitem->{'size'});
2627 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
2628 logchange('marc', 'change', $Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2629 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2631 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
2632 logchange('kohadb', 'change', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
2633 my $q_notes=$dbh->quote($biblioitem->{'notes'});
2634 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
2635 logchange('marc', 'change', $Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2636 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2638 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
2639 logchange('kohadb', 'change', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
2640 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
2641 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
2642 logchange('marc', 'change', $Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2643 changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2650 sub OLD_MAYBE_DELETED_updateItem {
2651 # Update the item with itemnumber $item->{'itemnumber'}
2652 # This routine should also modify the corresponding MARC record data. (852 and
2653 # 876 tags with 876p tag the same as $item->{'barcode'}
2655 # This routine should also check to see which fields are actually being
2656 # modified, and log all changes.
2658 my ($env, $item) = @_;
2660 my $itemnumber=$item->{'itemnumber'};
2661 my $biblionumber=$item->{'biblionumber'};
2662 my $biblioitemnumber=$item->{'biblioitemnumber'};
2663 my $barcode=$item->{'barcode'};
2664 my $dateaccessioned=$item->{'dateaccessioned'};
2665 my $booksellerid=$item->{'booksellerid'};
2666 my $homebranch=$item->{'homebranch'};
2667 my $price=$item->{'price'};
2668 my $replacementprice=$item->{'replacementprice'};
2669 my $replacementpricedate=$item->{'replacementpricedate'};
2670 my $multivolume=$item->{'multivolume'};
2671 my $stack=$item->{'stack'};
2672 my $notforloan=$item->{'notforloan'};
2673 my $itemlost=$item->{'itemlost'};
2674 my $wthdrawn=$item->{'wthdrawn'};
2675 my $bulk=$item->{'bulk'};
2676 my $restricted=$item->{'restricted'};
2677 my $binding=$item->{'binding'};
2678 my $itemnotes=$item->{'itemnotes'};
2679 my $holdingbranch=$item->{'holdingbranch'};
2680 my $interim=$item->{'interim'};
2681 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
2683 my $olditem=$sth->fetchrow_hashref;
2684 my $q_barcode=$dbh->quote($olditem->{'barcode'});
2685 $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");
2687 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
2688 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
2690 my ($link) = $sth->fetchrow;
2691 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
2693 my ($Subfield852_ID) = $sth->fetchrow;
2695 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
2696 logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
2697 my $q_barcode=$dbh->quote($item->{'barcode'});
2698 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
2700 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
2701 logchange('marc', 'change', $Record_ID, '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
2703 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
2704 logchange('kohadb', 'change', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
2705 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
2706 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
2708 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
2709 logchange('marc', 'change', $Record_ID, '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
2711 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
2712 logchange('kohadb', 'change', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2713 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
2714 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
2716 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
2717 logchange('marc', 'change', $Record_ID, '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2719 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
2720 logchange('kohadb', 'change', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
2721 my $q_homebranch=$dbh->quote($item->{'homebranch'});
2722 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
2724 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
2725 logchange('marc', 'change', $Record_ID, '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
2727 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
2728 logchange('kohadb', 'change', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2729 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
2730 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
2732 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
2733 logchange('marc', 'change', $Record_ID, '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2735 if ($item->{'price'} ne $olditem->{'price'}) {
2736 logchange('kohadb', 'change', 'items', 'price', $olditem->{'price'}, $item->{'price'});
2737 my $q_price=$dbh->quote($item->{'price'});
2738 my $sth=$dbh->prepare("update items set price=$q_price where itemnumber=$itemnumber");
2740 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'price'}, $item->{'price'}, $Subfield876_ID);
2741 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'price'}, $item->{'price'});
2743 if ($item->{'itemnotes'} ne $olditem->{'itemnotes'}) {
2744 logchange('kohadb', 'change', 'items', 'itemnotes', $olditem->{'itemnotes'}, $item->{'itemnotes'});
2745 my $q_itemnotes=$dbh->quote($item->{'itemnotes'});
2746 my $sth=$dbh->prepare("update items set itemnotes=$q_itemnotes where itemnumber=$itemnumber");
2748 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'itemnotes'}, $item->{'itemnotes'}, $Subfield876_ID);
2749 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'itemnotes'}, $item->{'itemnotes'});
2751 if ($item->{'notforloan'} ne $olditem->{'notforloan'}) {
2752 logchange('kohadb', 'change', 'items', 'notforloan', $olditem->{'notforloan'}, $item->{'notforloan'});
2753 my $sth=$dbh->prepare("update items set notforloan=$notforloan where itemnumber=$itemnumber");
2755 if ($item->{'notforloan'}) {
2756 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2757 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2759 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2760 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2763 if ($item->{'itemlost'} ne $olditem->{'itemlost'}) {
2764 logchange('kohadb', 'change', 'items', 'itemlost', $olditem->{'itemlost'}, $item->{'itemlost'});
2765 my $sth=$dbh->prepare("update items set itemlost=$itemlost where itemnumber=$itemnumber");
2767 if ($item->{'itemlost'}) {
2768 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2769 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2771 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2772 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2775 if ($item->{'wthdrawn'} ne $olditem->{'wthdrawn'}) {
2776 logchange('kohadb', 'change', 'items', 'wthdrawn', $olditem->{'wthdrawn'}, $item->{'wthdrawn'});
2777 my $sth=$dbh->prepare("update items set wthdrawn=$wthdrawn where itemnumber=$itemnumber");
2779 if ($item->{'wthdrawn'}) {
2780 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2781 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2783 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2784 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2787 if ($item->{'restricted'} ne $olditem->{'restricted'}) {
2788 logchange('kohadb', 'change', 'items', 'restricted', $olditem->{'restricted'}, $item->{'restricted'});
2789 my $sth=$dbh->prepare("update items set restricted=$restricted where itemnumber=$itemnumber");
2791 if ($item->{'restricted'}) {
2792 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2793 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2795 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2796 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2803 # Add a biblioitem and related data to Koha database
2804 sub OLD_MAY_BE_DELETED_newcompletebiblioitem {
2809 $biblio, # hash ref to biblio record
2810 $biblioitem, # hash ref to biblioitem record
2811 $subjects, # list ref of subjects
2812 $addlauthors, # list ref of additional authors
2815 my ( $biblionumber, $biblioitemnumber, $error); # return values
2820 my $additionalauthor;
2823 requireDBI($dbh,"newcompletebiblioitem");
2825 print "<PRE>Trying to add biblio item Title=$biblio->{title} " .
2826 "ISBN=$biblioitem->{isbn} </PRE>\n" if $debug;
2828 # Make sure master biblio entry exists
2829 ($biblionumber,$error)=getoraddbiblio($dbh, $biblio);
2833 $biblioitem->{biblionumber}=$biblionumber;
2836 $biblioitemnumber=newbiblioitem($biblioitem);
2839 $sth=$dbh->prepare("insert into bibliosubject
2840 (biblionumber,subject)
2842 foreach $subjectheading (@{$subjects} ) {
2843 $sth->execute($biblionumber, $subjectheading)
2844 or $error.=$sth->errstr ;
2848 # Add additional authors
2849 $sth=$dbh->prepare("insert into additionalauthors
2850 (biblionumber,author)
2852 foreach $additionalauthor (@{$addlauthors} ) {
2853 $sth->execute($biblionumber, $additionalauthor)
2854 or $error.=$sth->errstr ;
2858 # couldn't get biblio
2860 $biblioitemnumber='';
2862 } # if no biblio error
2864 return ( $biblionumber, $biblioitemnumber, $error);
2866 } # sub newcompletebiblioitem
2870 # END OF UNUSEFUL SUBs
2874 END { } # module clean-up code here (global destructor)