4 # Revision 1.14 2002/10/03 11:28:18 tipaul
5 # Extending Context.pm to add stopword management and using it in MARC-API.
6 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
8 # Revision 1.13 2002/10/02 16:26:44 tipaul
11 # Revision 1.12 2002/10/01 11:48:51 arensb
12 # Added some FIXME comments, mostly marking duplicate functions.
14 # Revision 1.11 2002/09/24 13:49:26 tipaul
15 # long WAS the road to 1.3.0...
16 # coming VERY SOON NOW...
17 # modifying installer and buildrelease to update the DB
19 # Revision 1.10 2002/09/22 16:50:08 arensb
20 # Added some FIXME comments.
22 # Revision 1.9 2002/09/20 12:57:46 tipaul
23 # long is the road to 1.4.0
24 # * MARCadditem and MARCmoditem now wroks
25 # * various bugfixes in MARC management
26 # !!! 1.3.0 should be released very soon now. Be careful !!!
28 # Revision 1.8 2002/09/10 13:53:52 tipaul
29 # MARC API continued...
31 # * 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)
33 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
35 # Revision 1.7 2002/08/14 18:12:51 tonnesen
36 # Added copyright statement to all .pl and .pm files
38 # Revision 1.6 2002/07/25 13:40:31 tipaul
39 # pod documenting the API.
41 # Revision 1.5 2002/07/24 16:11:37 tipaul
43 # Database.pm and Output.pm are almost not modified (var test...)
45 # Biblio.pm is almost completly rewritten.
47 # WHAT DOES IT ??? ==> END of Hitchcock suspens
49 # 1st, it does... nothing...
50 # 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 ...
52 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
53 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
54 # * 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.
55 # * 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.
56 # 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 ;-)
58 # 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.
59 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
63 # move from 1.2 to 1.4 version :
64 # 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
65 # In the 1.4 version, we want to do 2 differents things :
66 # - keep populating the old-DB, that has a LOT less datas than MARC
67 # - populate the MARC-DB
68 # To populate the DBs we have 2 differents sources :
69 # - the standard acquisition system (through book sellers), that does'nt use MARC data
70 # - the MARC acquisition system, that uses MARC data.
72 # thus, we have 2 differents cases :
73 # - 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
74 # - 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.
75 # we MUST have an API for true MARC data, that populate MARC-DB then old-DB
77 # That's why we need 4 subs :
78 # all subs beginning by MARC manage only MARC tables. They manage MARC-DB with MARC::Record parameters
79 # all subs beginning by OLD manage only OLD-DB tables. They manage old-DB with old-DB parameters
80 # 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
81 # 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.
83 # only ALL and old-style API should be used in koha. MARC and OLD is used internally only
85 # 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.
86 # 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 ;-)
90 # Copyright 2000-2002 Katipo Communications
92 # This file is part of Koha.
94 # Koha is free software; you can redistribute it and/or modify it under the
95 # terms of the GNU General Public License as published by the Free Software
96 # Foundation; either version 2 of the License, or (at your option) any later
99 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
100 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
101 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
103 # You should have received a copy of the GNU General Public License along with
104 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
105 # Suite 330, Boston, MA 02111-1307 USA
112 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
114 # set the version for version checking
119 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
120 # as the old-style API and the ALL one are the only public functions.
123 &updateBiblio &updateBiblioItem &updateItem
124 &itemcount &newbiblio &newbiblioitem
125 &modnote &newsubject &newsubtitle
126 &modbiblio &checkitems
127 &newitems &modbibitem
128 &modsubtitle &modsubject &modaddauthor &moditem &countitems
129 &delitem &deletebiblioitem &delbiblio
130 &getitemtypes &getbiblio
131 &getbiblioitembybiblionumber
132 &getbiblioitem &getitemsbybiblioitem &isbnsearch
134 &newcompletebiblioitem
136 &MARCfind_oldbiblionumber_from_MARCbibid
137 &MARCfind_MARCbibid_from_oldbiblionumber
139 &ALLnewbiblio &ALLnewitem
142 &MARCaddbiblio &MARCadditem
143 &MARCmodsubfield &MARCaddsubfield
144 &MARCmodbiblio &MARCmoditem
146 &MARCkoha2marcBiblio &MARCmarc2koha &MARCkoha2marcItem
147 &MARCgetbiblio &MARCgetitem
148 &MARCaddword &MARCdelword
153 # your exported package globals go here,
154 # as well as any optionally exported functions
156 @EXPORT_OK = qw($Var1 %Hashit);
160 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
163 # all the following subs takes a MARC::Record as parameter and manage
164 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
165 # ALLxxx subs (xxx deals with old-DB parameters, the ALLxxx deals with MARC-DB parameter)
170 all subs requires/use $dbh as 1st parameter.
171 NOTE : all those subs are private and must be used only inside Biblio.pm (called by a old API sub, or the ALLsub)
175 =head2 @tagslib = &MARCgettagslib($dbh,1|0);
176 last param is 1 for liblibrarian and 0 for libopac
177 returns a hash with tag/subfield meaning
179 =head2 ($tagfield,$tagsubfield) = &MARCfindmarc_from_kohafield($dbh,$kohafield);
180 finds MARC tag and subfield for a given kohafield
181 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
183 =head2 $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
184 finds a old-db biblio number for a given MARCbibid number
186 =head2 $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
187 finds a MARC bibid from a old-db biblionumber
189 =head2 &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
190 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
192 =head2 &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
193 adds a subfield in a biblio (in the MARC tables only).
195 =head2 $MARCRecord = &MARCgetbiblio($dbh,$bibid);
196 Returns a MARC::Record for the biblio $bibid.
198 =head2 &MARCmodbiblio($dbh,$bibid,$delete,$record);
199 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
200 if $delete == 1, every field/subfield not found is deleted in the biblio
201 otherwise, only data passed to MARCmodbiblio is managed.
202 thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
204 =head2 ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
205 MARCmodsubfield changes the value of a given subfield
207 =head2 $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
208 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
209 Returns -1 if more than 1 answer
211 =head2 $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
212 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
214 =head2 &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
215 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
217 =head2 &MARCdelbiblio($dbh,$bibid);
218 MARCdelbiblio delete biblio $bibid
220 =head2 $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
221 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
223 =head2 $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
224 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
226 =head2 $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
227 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
229 =head2 &MARCkoha2marcOnefield => used by MARCkoha2marc and should not be useful elsewhere
231 =head2 $olddb = &MARCmarc2koha($dbh,$MARCRecord);
232 builds a hash with old-db datas from a MARC::Record
234 =head2 &MARCmarc2kohaOnefield => used by MARCmarc2koha and should not be useful elsewhere
236 =head2 MARCaddword => used to manage MARC_word table and should not be useful elsewhere
238 =head2 MARCdelword => used to manage MARC_word table and should not be useful elsewhere
242 Paul POULAIN paul.poulain@free.fr
247 my ($dbh,$forlibrarian)= @_;
249 if ($forlibrarian eq 1) {
250 $sth=$dbh->prepare("select tagfield,liblibrarian as lib from marc_tag_structure");
252 $sth=$dbh->prepare("select tagfield,libopac as lib from marc_tag_structure");
256 while ( ($tag,$lib) = $sth->fetchrow) {
257 $res->{$tag}->{lib}=$lib;
260 if ($forlibrarian eq 1) {
261 $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib from marc_subfield_structure");
263 $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib from marc_subfield_structure");
268 while ( ($tag,$subfield,$lib) = $sth->fetchrow) {
269 $res->{$tag}->{$subfield}=$lib;
274 sub MARCfind_marc_from_kohafield {
275 my ($dbh,$kohafield) = @_;
276 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
277 $sth->execute($kohafield);
278 my ($tagfield,$tagsubfield) = $sth->fetchrow;
279 return ($tagfield,$tagsubfield);
282 sub MARCfind_oldbiblionumber_from_MARCbibid {
283 my ($dbh,$MARCbibid) = @_;
284 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
285 $sth->execute($MARCbibid);
286 my ($biblionumber) = $sth->fetchrow;
287 return $biblionumber;
290 sub MARCfind_MARCbibid_from_oldbiblionumber {
291 my ($dbh,$oldbiblionumber) = @_;
292 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
293 $sth->execute($oldbiblionumber);
294 my ($bibid) = $sth->fetchrow;
299 # pass the MARC::Record to this function, and it will create the records in the marc tables
300 my ($dbh,$record,$biblionumber) = @_;
301 my @fields=$record->fields();
303 # adding main table, and retrieving bibid
304 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
305 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
306 $sth->execute($biblionumber);
307 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
309 ($bibid)=$sth->fetchrow;
312 # now, add subfields...
313 foreach my $field (@fields) {
314 my @subfields=$field->subfields();
316 foreach my $subfieldcount (0..$#subfields) {
317 &MARCaddsubfield($dbh,$bibid,
319 $field->indicator(1).$field->indicator(2),
321 $subfields[$subfieldcount][0],
323 $subfields[$subfieldcount][1]
327 $dbh->do("unlock tables");
332 # pass the MARC::Record to this function, and it will create the records in the marc tables
333 my ($dbh,$record,$biblionumber) = @_;
334 # search for MARC biblionumber
335 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
336 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
337 my @fields=$record->fields();
338 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
339 $sth->execute($bibid);
340 my ($fieldcount) = $sth->fetchrow;
341 # now, add subfields...
342 foreach my $field (@fields) {
343 my @subfields=$field->subfields();
345 foreach my $subfieldcount (0..$#subfields) {
346 &MARCaddsubfield($dbh,$bibid,
348 $field->indicator(1).$field->indicator(2),
350 $subfields[$subfieldcount][0],
352 $subfields[$subfieldcount][1]
356 $dbh->do("unlock tables");
360 sub MARCaddsubfield {
361 # Add a new subfield to a tag into the DB.
362 my ($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
363 # if not value, end of job, we do nothing
364 if (not($subfieldvalue)) {
367 if (not($subfieldcode)) {
370 if (length($subfieldvalue)>255) {
371 # $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
372 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
373 $sth->execute($subfieldvalue);
374 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
376 my ($res)=$sth->fetchrow;
377 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?)");
379 $sth->execute($bibid,'0'.$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
381 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
384 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
386 # $dbh->do("unlock tables");
388 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?)");
389 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
391 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
394 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
399 # Returns MARC::Record of the biblio passed in parameter.
401 my $record = MARC::Record->new();
402 #---- TODO : the leader is missing
403 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
404 from marc_subfield_table
405 where bibid=? order by tagorder,subfieldorder
407 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
408 $sth->execute($bibid);
409 while (my $row=$sth->fetchrow_hashref) {
410 if ($row->{'valuebloblink'}) { #---- search blob if there is one
411 $sth2->execute($row->{'valuebloblink'});
412 my $row2=$sth2->fetchrow_hashref;
414 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
416 if ($record->field($row->{'tag'})) {
418 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
419 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
420 if (length($row->{'tag'}) <3) {
421 $row->{'tag'} = "0".$row->{'tag'};
423 $field =$record->field($row->{'tag'});
425 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
426 $record->delete_field($field);
427 $record->add_fields($field);
430 if (length($row->{'tag'}) < 3) {
431 $row->{'tag'} = "0".$row->{'tag'};
433 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
434 $record->add_fields($temp);
441 # Returns MARC::Record of the biblio passed in parameter.
442 my ($dbh,$bibid,$itemnumber)=@_;
443 warn "MARCgetitem : $bibid, $itemnumber\n";
444 my $record = MARC::Record->new();
445 # search MARC tagorder
446 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=?");
447 $sth2->execute($bibid,$itemnumber);
448 my ($tagorder) = $sth2->fetchrow_array();
449 #---- TODO : the leader is missing
450 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
451 from marc_subfield_table
452 where bibid=? and tagorder=? order by subfieldorder
454 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
455 $sth->execute($bibid,$tagorder);
456 while (my $row=$sth->fetchrow_hashref) {
457 if ($row->{'valuebloblink'}) { #---- search blob if there is one
458 $sth2->execute($row->{'valuebloblink'});
459 my $row2=$sth2->fetchrow_hashref;
461 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
463 if ($record->field($row->{'tag'})) {
465 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
466 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
467 if (length($row->{'tag'}) <3) {
468 $row->{'tag'} = "0".$row->{'tag'};
470 $field =$record->field($row->{'tag'});
472 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
473 $record->delete_field($field);
474 $record->add_fields($field);
477 if (length($row->{'tag'}) < 3) {
478 $row->{'tag'} = "0".$row->{'tag'};
480 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
481 $record->add_fields($temp);
489 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
490 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
491 # if nothing to change, don't waste time...
492 if ($oldrecord eq $record) {
495 # otherwise, skip through each subfield...
496 my @fields = $record->fields();
498 foreach my $field (@fields) {
499 my $oldfield = $oldrecord->field($field->tag());
500 my @subfields=$field->subfields();
503 foreach my $subfield (@subfields) {
505 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
506 # just adding datas...
507 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
508 1,@$subfield[0],$subfieldorder,@$subfield[1]);
510 # modify he subfield if it's a different string
511 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
512 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
513 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
521 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
522 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
523 # if nothing to change, don't waste time...
524 if ($oldrecord eq $record) {
527 # otherwise, skip through each subfield...
528 my @fields = $record->fields();
529 # search old MARC item
530 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=?");
531 $sth2->execute($bibid,$itemnumber);
532 my ($tagorder) = $sth2->fetchrow_array();
533 foreach my $field (@fields) {
534 my $oldfield = $oldrecord->field($field->tag());
535 my @subfields=$field->subfields();
537 foreach my $subfield (@subfields) {
539 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
540 # just adding datas...
541 warn "ADD = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
542 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
543 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
545 # modify he subfield if it's a different string
546 warn "MODIFY = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
547 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
548 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
549 warn "MODIFY2 = $bibid, $subfieldid, ".@$subfield[1]."\n";
550 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
559 sub MARCmodsubfield {
560 # Subroutine changes a subfield value given a subfieldid.
561 my ($dbh, $subfieldid, $subfieldvalue )=@_;
562 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
563 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
564 $sth1->execute($subfieldid);
565 my ($oldvaluebloblink)=$sth1->fetchrow;
568 # if too long, use a bloblink
569 if (length($subfieldvalue)>255 ) {
570 # if already a bloblink, update it, otherwise, insert a new one.
571 if ($oldvaluebloblink) {
572 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
573 $sth->execute($subfieldvalue,$oldvaluebloblink);
575 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
576 $sth->execute($subfieldvalue);
577 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
579 my ($res)=$sth->fetchrow;
580 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
581 $sth->execute($subfieldid);
584 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
585 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
586 $sth->execute($subfieldvalue, $subfieldid);
588 $dbh->do("unlock tables");
590 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
591 $sth->execute($subfieldid);
592 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
594 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
595 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
596 return($subfieldid, $subfieldvalue);
599 sub MARCfindsubfield {
600 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
604 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
605 if ($subfieldvalue) {
606 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
608 if ($subfieldorder<1) {
611 $query .= " and subfieldorder=$subfieldorder";
613 my $sti=$dbh->prepare($query);
614 $sti->execute($bibid,$tag, $subfieldcode);
615 while (($subfieldid) = $sti->fetchrow) {
617 $lastsubfieldid=$subfieldid;
619 if ($resultcounter>1) {
620 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
621 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
624 return $lastsubfieldid;
628 sub MARCfindsubfieldid {
629 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
630 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
631 where bibid=? and tag=? and tagorder=?
632 and subfieldcode=? and subfieldorder=?");
633 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
634 my ($res) = $sth->fetchrow;
638 sub MARCdelsubfield {
639 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
640 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
641 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
642 tag='$tag' and tagorder='$tagorder'
643 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
648 # delete a biblio for a $bibid
649 my ($dbh,$bibid) = @_;
650 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
651 $dbh->do("delete from marc_biblio where bibid='$bibid'");
654 sub MARCkoha2marcBiblio {
655 # this function builds partial MARC::Record from the old koha-DB fields
656 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
657 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
658 my $record = MARC::Record->new();
659 #--- if bibid, then retrieve old-style koha data
660 if ($biblionumber>0) {
661 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
662 from biblio where biblionumber=?");
663 $sth2->execute($biblionumber);
664 my $row=$sth2->fetchrow_hashref;
666 foreach $code (keys %$row) {
668 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
672 #--- if biblioitem, then retrieve old-style koha data
673 if ($biblioitemnumber>0) {
674 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
675 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
676 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
678 WHERE biblionumber=? and biblioitemnumber=?
680 $sth2->execute($biblionumber,$biblioitemnumber);
681 my $row=$sth2->fetchrow_hashref;
683 foreach $code (keys %$row) {
685 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
690 # TODO : retrieve notes, additionalauthors
693 sub MARCkoha2marcItem {
694 # this function builds partial MARC::Record from the old koha-DB fields
695 my ($dbh,$biblionumber,$itemnumber) = @_;
696 # my $dbh=&C4Connect;
697 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
698 my $record = MARC::Record->new();
699 #--- if item, then retrieve old-style koha data
701 # print STDERR "prepare $biblionumber,$itemnumber\n";
702 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
703 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
704 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
705 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
707 WHERE itemnumber=?");
708 $sth2->execute($itemnumber);
709 my $row=$sth2->fetchrow_hashref;
711 foreach $code (keys %$row) {
713 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
718 # TODO : retrieve notes, additionalauthors
721 sub MARCkoha2marcSubtitle {
722 # this function builds partial MARC::Record from the old koha-DB fields
723 my ($dbh,$bibnum,$subtitle) = @_;
724 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
725 my $record = MARC::Record->new();
726 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
730 sub MARCkoha2marcOnefield {
731 my ($sth,$record,$kohafieldname,$value)=@_;
734 $sth->execute($kohafieldname);
735 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
736 if ($record->field($tagfield)) {
737 my $tag =$record->field($tagfield);
739 $tag->add_subfields($tagsubfield,$value);
740 $record->delete_field($tag);
741 $record->add_fields($tag);
744 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
751 my ($dbh,$record) = @_;
752 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
754 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
757 # print STDERR $record->as_formatted;
758 while (($field)=$sth2->fetchrow) {
759 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
761 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
764 while (($field)=$sth2->fetchrow) {
765 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
767 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
770 while (($field)=$sth2->fetchrow) {
771 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
773 # additional authors : specific
774 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
778 sub MARCmarc2kohaOneField {
779 # to check : if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
780 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
784 $sth->execute($kohatable.".".$kohafield);
785 ($tagfield,$subfield) = $sth->fetchrow;
786 foreach my $field ($record->field($tagfield)) {
787 if ($field->subfield($subfield)) {
788 if ($result->{$kohafield}) {
789 $result->{$kohafield} .= " | ".$field->subfield($subfield);
791 $result->{$kohafield}=$field->subfield($subfield);
799 # split a subfield string and adds it into the word table.
801 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
802 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
803 my @words = split / /,$sentence;
804 # build stopword list
805 # my $sth2 =$dbh->prepare("select word from stopwords");
809 # while(($stopword) = $sth2->fetchrow_array) {
810 # $stopwords->{$stopword} = $stopword;
812 my $stopwords= C4::Context->stopwords;
813 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
814 values (?,?,?,?,?,?,soundex(?))");
815 foreach my $word (@words) {
816 # we record only words longer than 2 car and not in stopwords hash
817 if (length($word)>1 and !($stopwords->{uc($word)})) {
818 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
820 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";
827 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
828 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
829 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
830 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
835 # ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL
838 # all the following subs are useful to manage MARC-DB with complete MARC records.
839 # it's used with marcimport, and marc management tools
844 all subs requires/use $dbh as 1st parameter.
845 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
849 =head2 (oldbibnum,$oldbibitemnum) = ALLnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
850 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
851 are builded from the MARC::Record. If they are passed, they are used.
853 =head2 ALLnewitem($dbh,$olditem);
854 adds an item in the db. $olditem is a old-db hash.
858 Paul POULAIN paul.poulain@free.fr
863 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
864 # note $oldbiblio and $oldbiblioitem are not mandatory.
865 # if not present, they will be builded from $record with MARCmarc2koha function
866 if (($oldbiblio) and not($oldbiblioitem)) {
867 print STDERR "ALLnewbiblio : missing parameter\n";
868 print "ALLnewbiblio : missing parameter : contact koha development team\n";
874 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
875 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
876 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
878 my $olddata = MARCmarc2koha($dbh,$record);
879 $oldbibnum = OLDnewbiblio($dbh,$olddata);
880 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
882 # we must add bibnum and bibitemnum in MARC::Record...
883 # we build the new field with biblionumber and biblioitemnumber
884 # we drop the original field
885 # we add the new builded field.
886 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
887 # (steve and paul : thinks 090 is a good choice)
888 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
889 $sth->execute("biblio.biblionumber");
890 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
891 $sth->execute("biblioitems.biblioitemnumber");
892 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
893 print STDERR "tag1 : $tagfield1 / $tagsubfield1\n tag2 : $tagfield2 / $tagsubfield2\n";
894 if ($tagsubfield1 != $tagsubfield2) {
895 print STDERR "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
896 print "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
899 my $newfield = MARC::Field->new( $tagfield1,'','',
900 "$tagsubfield1" => $oldbibnum,
901 "$tagsubfield2" => $oldbibitemnum);
902 # drop old field and create new one...
903 my $old_field = $record->field($tagfield1);
904 $record->delete_field($old_field);
905 $record->add_fields($newfield);
906 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
907 return ( $oldbibnum,$oldbibitemnum );
911 my ($dbh, $item) = @_;
914 ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{'barcode'});
915 # search MARC biblionumber
916 my $bibid=&MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{'biblionumber'});
918 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
919 $sth->execute($bibid);
920 my ($tagorder) = $sth->fetchrow;
923 # for each field, find MARC tag and subfield, and call the proper MARC sub
924 foreach my $itemkey (keys %$item) {
927 print STDERR "=============> $itemkey : ".$item->{$itemkey}."\n";
928 if ($itemkey eq "biblionumber" || $itemkey eq "biblioitemnumber") {
929 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"biblio.".$itemkey);
931 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"items.".$itemkey);
933 if ($tagfield && $item->{$itemkey} ne 'NULL') {
935 &MARCaddsubfield($dbh,
951 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
957 all subs requires/use $dbh as 1st parameter.
958 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
960 They all are the exact copy of 1.0/1.2 version of the sub
961 without the OLD. The OLDxxx is called by the original xxx sub.
962 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
964 WARNING : there is 1 difference between initialxxx and OLDxxx :
965 the db header $dbh is always passed as parameter
966 to avoid over-DB connexion
970 =head2 $biblionumber = OLDnewbiblio($dbh,$biblio);
971 adds a record in biblio table. Datas are in the hash $biblio.
973 =head2 $biblionumber = OLDmodbiblio($dbh,$biblio);
974 modify a record in biblio table. Datas are in the hash $biblio.
976 =head2 OLDmodsubtitle($dbh,$bibnum,$subtitle);
977 modify subtitles in bibliosubtitle table.
979 =head2 OLDmodaddauthor($dbh,$bibnum,$author);
980 adds or modify additional authors
981 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
983 =head2 $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
986 =head2 OLDmodbibitem($dbh, $biblioitem);
989 =head2 OLDmodnote($dbh,$bibitemnum,$note
990 modify a note for a biblioitem
992 =head2 OLDnewbiblioitem($dbh,$biblioitem);
993 adds a biblioitem ($biblioitem is a hash with the values)
995 =head2 OLDnewsubject($dbh,$bibnum);
997 =head2 OLDnewsubtitle($dbh,$bibnum,$subtitle);
998 create a new subtitle
1000 =head2 ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1001 create a item. $item is a hash and $barcode the barcode.
1003 =head2 OLDmoditem($dbh,$item);
1006 =head2 OLDdelitem($dbh,$itemnum);
1009 =head2 OLDdeletebiblioitem($dbh,$biblioitemnumber);
1010 deletes a biblioitem
1011 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1013 =head2 OLDdelbiblio($dbh,$biblio);
1018 Paul POULAIN paul.poulain@free.fr
1023 my ($dbh,$biblio) = @_;
1024 # my $dbh = &C4Connect;
1025 my $query = "Select max(biblionumber) from biblio";
1026 my $sth = $dbh->prepare($query);
1028 my $data = $sth->fetchrow_arrayref;
1029 my $bibnum = $$data[0] + 1;
1032 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1033 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1034 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
1035 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
1036 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1037 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1038 if ($biblio->{'seriestitle'}) { $series = 1 };
1041 $query = "insert into biblio set
1042 biblionumber = $bibnum,
1043 title = $biblio->{'title'},
1044 author = $biblio->{'author'},
1045 copyrightdate = $biblio->{'copyright'},
1047 seriestitle = $biblio->{'seriestitle'},
1048 notes = $biblio->{'notes'},
1049 abstract = $biblio->{'abstract'}";
1051 $sth = $dbh->prepare($query);
1060 my ($dbh,$biblio) = @_;
1061 # my $dbh = C4Connect;
1065 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1066 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1067 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1068 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
1069 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
1070 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
1071 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
1072 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1074 $query = "Update biblio set
1075 title = $biblio->{'title'},
1076 author = $biblio->{'author'},
1077 abstract = $biblio->{'abstract'},
1078 copyrightdate = $biblio->{'copyrightdate'},
1079 seriestitle = $biblio->{'seriestitle'},
1080 serial = $biblio->{'serial'},
1081 unititle = $biblio->{'unititle'},
1082 notes = $biblio->{'notes'}
1083 where biblionumber = $biblio->{'biblionumber'}";
1084 $sth = $dbh->prepare($query);
1090 return($biblio->{'biblionumber'});
1093 sub OLDmodsubtitle {
1094 my ($dbh,$bibnum, $subtitle) = @_;
1095 # my $dbh = C4Connect;
1096 my $query = "update bibliosubtitle set
1097 subtitle = '$subtitle'
1098 where biblionumber = $bibnum";
1099 my $sth = $dbh->prepare($query);
1107 sub OLDmodaddauthor {
1108 my ($dbh,$bibnum, $author) = @_;
1109 # my $dbh = C4Connect;
1110 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1111 my $sth = $dbh->prepare($query);
1116 if ($author ne '') {
1117 $query = "Insert into additionalauthors set
1119 biblionumber = '$bibnum'";
1120 $sth = $dbh->prepare($query);
1128 } # sub modaddauthor
1132 my ($dbh,$bibnum, $force, @subject) = @_;
1133 # my $dbh = C4Connect;
1134 my $count = @subject;
1136 for (my $i = 0; $i < $count; $i++) {
1137 $subject[$i] =~ s/^ //g;
1138 $subject[$i] =~ s/ $//g;
1139 my $query = "select * from catalogueentry
1140 where entrytype = 's'
1141 and catalogueentry = '$subject[$i]'";
1142 my $sth = $dbh->prepare($query);
1145 if (my $data = $sth->fetchrow_hashref) {
1147 if ($force eq $subject[$i]) {
1148 # subject not in aut, chosen to force anway
1149 # so insert into cataloguentry so its in auth file
1150 $query = "Insert into catalogueentry
1151 (entrytype,catalogueentry)
1152 values ('s','$subject[$i]')";
1153 my $sth2 = $dbh->prepare($query);
1158 $error = "$subject[$i]\n does not exist in the subject authority file";
1159 $query = "Select * from catalogueentry
1160 where entrytype = 's'
1161 and (catalogueentry like '$subject[$i] %'
1162 or catalogueentry like '% $subject[$i] %'
1163 or catalogueentry like '% $subject[$i]')";
1164 my $sth2 = $dbh->prepare($query);
1167 while (my $data = $sth2->fetchrow_hashref) {
1168 $error = $error."<br>$data->{'catalogueentry'}";
1176 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1177 my $sth = $dbh->prepare($query);
1180 for (my $i = 0; $i < $count; $i++) {
1181 $sth = $dbh->prepare("Insert into bibliosubject
1182 values ('$subject[$i]', $bibnum)");
1194 my ($dbh,$biblioitem) = @_;
1195 # my $dbh = C4Connect;
1198 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1199 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1200 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1201 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1202 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1203 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1204 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1205 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1206 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1207 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1208 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1209 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1210 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1211 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1213 $query = "Update biblioitems set
1214 itemtype = $biblioitem->{'itemtype'},
1215 url = $biblioitem->{'url'},
1216 isbn = $biblioitem->{'isbn'},
1217 publishercode = $biblioitem->{'publishercode'},
1218 publicationyear = $biblioitem->{'publicationyear'},
1219 classification = $biblioitem->{'classification'},
1220 dewey = $biblioitem->{'dewey'},
1221 subclass = $biblioitem->{'subclass'},
1222 illus = $biblioitem->{'illus'},
1223 pages = $biblioitem->{'pages'},
1224 volumeddesc = $biblioitem->{'volumeddesc'},
1225 notes = $biblioitem->{'notes'},
1226 size = $biblioitem->{'size'},
1227 place = $biblioitem->{'place'}
1228 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1236 my ($dbh,$bibitemnum,$note)=@_;
1237 # my $dbh=C4Connect;
1238 my $query="update biblioitems set notes='$note' where
1239 biblioitemnumber='$bibitemnum'";
1240 my $sth=$dbh->prepare($query);
1246 sub OLDnewbiblioitem {
1247 my ($dbh,$biblioitem) = @_;
1248 # my $dbh = C4Connect;
1249 my $query = "Select max(biblioitemnumber) from biblioitems";
1250 my $sth = $dbh->prepare($query);
1254 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
1255 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
1256 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1257 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1258 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1259 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1260 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
1261 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1262 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1263 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1264 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1265 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
1266 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1267 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1268 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1269 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1270 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1271 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1272 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
1273 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
1276 $data = $sth->fetchrow_arrayref;
1277 $bibitemnum = $$data[0] + 1;
1281 $query = "insert into biblioitems set
1282 biblioitemnumber = $bibitemnum,
1283 biblionumber = $biblioitem->{'biblionumber'},
1284 volume = $biblioitem->{'volume'},
1285 number = $biblioitem->{'number'},
1286 classification = $biblioitem->{'classification'},
1287 itemtype = $biblioitem->{'itemtype'},
1288 url = $biblioitem->{'url'},
1289 isbn = $biblioitem->{'isbn'},
1290 issn = $biblioitem->{'issn'},
1291 dewey = $biblioitem->{'dewey'},
1292 subclass = $biblioitem->{'subclass'},
1293 publicationyear = $biblioitem->{'publicationyear'},
1294 publishercode = $biblioitem->{'publishercode'},
1295 volumedate = $biblioitem->{'volumedate'},
1296 volumeddesc = $biblioitem->{'volumeddesc'},
1297 illus = $biblioitem->{'illus'},
1298 pages = $biblioitem->{'pages'},
1299 notes = $biblioitem->{'notes'},
1300 size = $biblioitem->{'size'},
1301 lccn = $biblioitem->{'lccn'},
1302 marc = $biblioitem->{'marc'},
1303 place = $biblioitem->{'place'}";
1305 $sth = $dbh->prepare($query);
1309 return($bibitemnum);
1313 my ($dbh,$bibnum)=@_;
1314 # my $dbh=C4Connect;
1315 my $query="insert into bibliosubject (biblionumber) values
1317 my $sth=$dbh->prepare($query);
1324 sub OLDnewsubtitle {
1325 my ($dbh,$bibnum, $subtitle) = @_;
1326 # my $dbh = C4Connect;
1327 $subtitle = $dbh->quote($subtitle);
1328 my $query = "insert into bibliosubtitle set
1329 biblionumber = $bibnum,
1330 subtitle = $subtitle";
1331 my $sth = $dbh->prepare($query);
1341 my ($dbh,$item, $barcode) = @_;
1342 # my $dbh = C4Connect;
1343 my $query = "Select max(itemnumber) from items";
1344 my $sth = $dbh->prepare($query);
1350 $data = $sth->fetchrow_hashref;
1351 $itemnumber = $data->{'max(itemnumber)'} + 1;
1354 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
1355 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
1356 $item->{'price'} = $dbh->quote($item->{'price'});
1357 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
1358 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
1360 # foreach my $barcode (@barcodes) {
1361 # $barcode = uc($barcode);
1362 $barcode = $dbh->quote($barcode);
1363 $query = "Insert into items set
1364 itemnumber = $itemnumber,
1365 biblionumber = $item->{'biblionumber'},
1366 biblioitemnumber = $item->{'biblioitemnumber'},
1368 booksellerid = $item->{'booksellerid'},
1369 dateaccessioned = NOW(),
1370 homebranch = $item->{'homebranch'},
1371 holdingbranch = $item->{'homebranch'},
1372 price = $item->{'price'},
1373 replacementprice = $item->{'replacementprice'},
1374 replacementpricedate = NOW(),
1375 itemnotes = $item->{'itemnotes'}";
1376 if ($item->{'loan'}) {
1377 $query .= ",notforloan = $item->{'loan'}";
1380 $sth = $dbh->prepare($query);
1382 if (defined $sth->errstr) {
1383 $error .= $sth->errstr;
1388 return($itemnumber,$error);
1392 my ($dbh,$item) = @_;
1393 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1394 # my $dbh=C4Connect;
1395 my $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1396 barcode='$item->{'barcode'}',itemnotes='$item->{'notes'}'
1397 where itemnumber=$item->{'itemnum'}";
1398 if ($item->{'barcode'} eq ''){
1399 $query="update items set biblioitemnumber=$item->{'bibitemnum'},notforloan=$item->{'loan'} where itemnumber=$item->{'itemnum'}";
1401 if ($item->{'lost'} ne ''){
1402 $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1403 barcode='$item->{'barcode'}',
1404 itemnotes='$item->{'notes'}',
1405 homebranch='$item->{'homebranch'}',
1406 itemlost='$item->{'lost'}',
1407 wthdrawn='$item->{'wthdrawn'}'
1408 where itemnumber=$item->{'itemnum'}";
1410 if ($item->{'replacement'} ne ''){
1411 $query=~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1414 my $sth=$dbh->prepare($query);
1420 # FIXME - A nearly-identical function, &delitem, appears in
1423 my ($dbh,$itemnum)=@_;
1424 # my $dbh=C4Connect;
1425 my $query="select * from items where itemnumber=$itemnum";
1426 my $sth=$dbh->prepare($query);
1428 my @data=$sth->fetchrow_array;
1430 $query="Insert into deleteditems values (";
1431 foreach my $temp (@data){
1432 $query=$query."'$temp',";
1436 $sth=$dbh->prepare($query);
1439 $query = "Delete from items where itemnumber=$itemnum";
1440 $sth=$dbh->prepare($query);
1446 sub OLDdeletebiblioitem {
1447 my ($dbh,$biblioitemnumber) = @_;
1448 # my $dbh = C4Connect;
1449 my $query = "Select * from biblioitems
1450 where biblioitemnumber = $biblioitemnumber";
1451 my $sth = $dbh->prepare($query);
1456 if (@results = $sth->fetchrow_array) {
1457 $query = "Insert into deletedbiblioitems values (";
1458 foreach my $value (@results) {
1459 $value = $dbh->quote($value);
1460 $query .= "$value,";
1463 $query =~ s/\,$/\)/;
1466 $query = "Delete from biblioitems
1467 where biblioitemnumber = $biblioitemnumber";
1471 # Now delete all the items attached to the biblioitem
1472 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1473 $sth = $dbh->prepare($query);
1475 while (@results = $sth->fetchrow_array) {
1476 $query = "Insert into deleteditems values (";
1477 foreach my $value (@results) {
1478 $value = $dbh->quote($value);
1479 $query .= "$value,";
1481 $query =~ s/\,$/\)/;
1485 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1488 } # sub deletebiblioitem
1491 my ($dbh,$biblio)=@_;
1492 # my $dbh=C4Connect;
1493 my $query="select * from biblio where biblionumber=$biblio";
1494 my $sth=$dbh->prepare($query);
1496 if (my @data=$sth->fetchrow_array){
1498 $query="Insert into deletedbiblio values (";
1499 foreach my $temp (@data){
1500 $temp=~ s/\'/\\\'/g;
1501 $query=$query."'$temp',";
1505 $sth=$dbh->prepare($query);
1508 $query = "Delete from biblio where biblionumber=$biblio";
1509 $sth=$dbh->prepare($query);
1523 # FIXME - This is the same as &C4::Acquisitions::itemcount, but not
1524 # the same as &C4::Search::itemcount
1528 my $query="Select count(*) from items where biblionumber=$biblio";
1530 my $sth=$dbh->prepare($query);
1532 my $data=$sth->fetchrow_hashref;
1535 return($data->{'count(*)'});
1541 my $query="Select ordernumber
1543 where biblionumber=? and biblioitemnumber=?";
1544 my $sth=$dbh->prepare($query);
1545 $sth->execute($bib,$bi);
1546 my $ordnum=$sth->fetchrow_hashref;
1548 my $order=getsingleorder($ordnum->{'ordernumber'});
1551 return ($order,$ordnum->{'ordernumber'});
1554 # FIXME - This is practically the same function as
1555 # &C4::Acquisitions::getsingleorder and &C4::Catalogue::getsingleorder
1556 sub getsingleorder {
1559 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1560 where aqorders.ordernumber=?
1561 and biblio.biblionumber=aqorders.biblionumber and
1562 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1563 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1564 my $sth=$dbh->prepare($query);
1565 $sth->execute($ordnum);
1566 my $data=$sth->fetchrow_hashref;
1574 my $dbh = &C4Connect;
1575 my $bibnum=OLDnewbiblio($dbh,$biblio);
1583 my $dbh = C4Connect;
1584 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1586 return($biblionumber);
1590 my ($bibnum, $subtitle) = @_;
1591 my $dbh = C4Connect;
1592 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1597 # FIXME - This is functionally identical to
1598 # &C4::Acquisitions::modaddauthor
1600 my ($bibnum, $author) = @_;
1601 my $dbh = C4Connect;
1602 &OLDmodaddauthor($dbh,$bibnum,$author);
1604 } # sub modaddauthor
1608 my ($bibnum, $force, @subject) = @_;
1609 my $dbh = C4Connect;
1610 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1615 my ($biblioitem) = @_;
1616 my $dbh = C4Connect;
1617 &OLDmodbibitem($dbh,$biblioitem);
1618 my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
1619 &MARCmodbiblio($dbh,$biblioitem->{biblionumber},0,$MARCbibitem);
1624 my ($bibitemnum,$note)=@_;
1626 &OLDmodnote($dbh,$bibitemnum,$note);
1630 # FIXME - This is quite similar in effect to &C4::newbiblioitem,
1631 # except for the MARC stuff.
1633 my ($biblioitem) = @_;
1634 my $dbh = C4Connect;
1635 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1636 # print STDERR "bibitemnum : $bibitemnum\n";
1637 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1638 # print STDERR $MARCbiblio->as_formatted();
1639 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1640 return($bibitemnum);
1646 &OLDnewsubject($dbh,$bibnum);
1650 # FIXME - This is just a wrapper around &OLDnewsubtitle
1651 # FIXME - This is in effect the same as &C4::Acquisitions::newsubtitle
1653 my ($bibnum, $subtitle) = @_;
1654 my $dbh = C4Connect;
1655 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1660 my ($item, @barcodes) = @_;
1661 my $dbh = C4Connect;
1665 foreach my $barcode (@barcodes) {
1666 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1668 # print STDERR "biblionumber : $item->{biblionumber} / MARCbibid : $MARCbibid / itemnumber : $itemnumber\n";
1669 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1670 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1671 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1672 # print STDERR "MARCmodbiblio called\n";
1680 # my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1682 &OLDmoditem($dbh,$item);
1683 warn "biblionumber : $item->{'biblionumber'} / $item->{'itemnum'}\n";
1684 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1685 warn "before MARCmoditem : $item->{biblionumber}, $item->{'itemnum'}\n";
1686 warn $MARCitem->as_formatted();
1687 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1688 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1689 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1694 my ($count,@barcodes)=@_;
1697 for (my $i=0;$i<$count;$i++){
1698 $barcodes[$i]=uc $barcodes[$i];
1699 my $query="Select * from items where barcode='$barcodes[$i]'";
1700 my $sth=$dbh->prepare($query);
1702 if (my $data=$sth->fetchrow_hashref){
1703 $error.=" Duplicate Barcode: $barcodes[$i]";
1712 my ($bibitemnum)=@_;
1714 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1715 my $sth=$dbh->prepare($query);
1717 my $data=$sth->fetchrow_hashref;
1720 return($data->{'count(*)'});
1723 # FIXME - This is just a wrapper around &OLDdelitem, and acts
1724 # identically to &C4::Acquisitions::delitem
1728 &OLDdelitem($dbh,$itemnum);
1732 sub deletebiblioitem {
1733 my ($biblioitemnumber) = @_;
1734 my $dbh = C4Connect;
1735 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1737 } # sub deletebiblioitem
1743 &OLDdelbiblio($dbh,$biblio);
1748 my $dbh = C4Connect;
1749 my $query = "select * from itemtypes";
1750 my $sth = $dbh->prepare($query);
1751 # || die "Cannot prepare $query" . $dbh->errstr;
1756 # || die "Cannot execute $query\n" . $sth->errstr;
1757 while (my $data = $sth->fetchrow_hashref) {
1758 $results[$count] = $data;
1764 return($count, @results);
1765 } # sub getitemtypes
1768 my ($biblionumber) = @_;
1769 my $dbh = C4Connect;
1770 my $query = "Select * from biblio where biblionumber = $biblionumber";
1771 my $sth = $dbh->prepare($query);
1772 # || die "Cannot prepare $query\n" . $dbh->errstr;
1777 # || die "Cannot execute $query\n" . $sth->errstr;
1778 while (my $data = $sth->fetchrow_hashref) {
1779 $results[$count] = $data;
1785 return($count, @results);
1789 my ($biblioitemnum) = @_;
1790 my $dbh = C4Connect;
1791 my $query = "Select * from biblioitems where
1792 biblioitemnumber = $biblioitemnum";
1793 my $sth = $dbh->prepare($query);
1799 while (my $data = $sth->fetchrow_hashref) {
1800 $results[$count] = $data;
1806 return($count, @results);
1807 } # sub getbiblioitem
1809 sub getbiblioitembybiblionumber {
1810 my ($biblionumber) = @_;
1811 my $dbh = C4Connect;
1812 my $query = "Select * from biblioitems where biblionumber =
1814 my $sth = $dbh->prepare($query);
1820 while (my $data = $sth->fetchrow_hashref) {
1821 $results[$count] = $data;
1827 return($count, @results);
1830 sub getitemsbybiblioitem {
1831 my ($biblioitemnum) = @_;
1832 my $dbh = C4Connect;
1833 my $query = "Select * from items, biblio where
1834 biblio.biblionumber = items.biblionumber and biblioitemnumber
1836 my $sth = $dbh->prepare($query);
1837 # || die "Cannot prepare $query\n" . $dbh->errstr;
1842 # || die "Cannot execute $query\n" . $sth->errstr;
1843 while (my $data = $sth->fetchrow_hashref) {
1844 $results[$count] = $data;
1850 return($count, @results);
1851 } # sub getitemsbybiblioitem
1855 my $dbh = C4Connect;
1861 $isbn = $dbh->quote($isbn);
1862 $query = "Select biblio.* from biblio, biblioitems where
1863 biblio.biblionumber = biblioitems.biblionumber
1865 $sth = $dbh->prepare($query);
1868 while (my $data = $sth->fetchrow_hashref) {
1869 $results[$count] = $data;
1875 return($count, @results);
1879 # At the moment this is just a straight copy of the subject code. Needs heavy
1880 # modification to work for additional authors, obviously.
1881 # Check for additional author changes
1883 # my $newadditionalauthor='';
1884 # my $additionalauthors;
1885 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
1886 # $additionalauthors->{$newadditionalauthor}=1;
1887 # if ($origadditionalauthors->{$newadditionalauthor}) {
1888 # $additionalauthors->{$newadditionalauthor}=2;
1890 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
1891 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
1893 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
1895 # $subfields->{1}->{'Subfield_Mark'}='a';
1896 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
1899 # foreach $Record_ID (@marcrecords) {
1900 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1901 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
1905 # my $origadditionalauthor;
1906 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
1907 # if ($additionalauthors->{$origadditionalauthor} == 1) {
1908 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
1909 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
1910 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
1920 # Subroutine to log changes to databases
1921 # Eventually, this subroutine will be used to create a log of all changes made,
1922 # with the possibility of "undo"ing some changes
1924 if ($database eq 'kohadb') {
1930 print STDERR "KOHA: $type $section $item $original $new\n";
1931 } elsif ($database eq 'marc') {
1933 my $Record_ID=shift;
1936 my $subfield_ID=shift;
1939 print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
1943 #------------------------------------------------
1946 #---------------------------------------
1947 # Find a biblio entry, or create a new one if it doesn't exist.
1948 # If a "subtitle" entry is in hash, add it to subtitle table
1949 sub getoraddbiblio {
1953 $biblio, # hash ref to fields
1964 requireDBI($dbh,"getoraddbiblio");
1966 print "<PRE>Looking for biblio </PRE>\n" if $debug;
1967 $sth=$dbh->prepare("select biblionumber
1969 where title=? and author=?
1970 and copyrightdate=? and seriestitle=?");
1972 $biblio->{title}, $biblio->{author},
1973 $biblio->{copyright}, $biblio->{seriestitle} );
1975 ($biblionumber) = $sth->fetchrow;
1976 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
1978 # Doesn't exist. Add new one.
1979 print "<PRE>Adding biblio</PRE>\n" if $debug;
1980 ($biblionumber,$error)=&newbiblio($biblio);
1981 if ( $biblionumber ) {
1982 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
1983 if ( $biblio->{subtitle} ) {
1984 &newsubtitle($biblionumber,$biblio->{subtitle} );
1987 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
1991 return $biblionumber,$error;
1993 } # sub getoraddbiblio
1997 # UNUSEFUL SUBs. Could be deleted, kept only until beta test
1998 # maybe useful for some MARC tricks steve used.
2001 sub OLD_MAYBE_DELETED_newBiblioItem {
2002 my ($env, $biblioitem) = @_;
2004 my $biblionumber=$biblioitem->{'biblionumber'};
2005 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2006 my $volume=$biblioitem->{'volume'};
2007 my $q_volume=$dbh->quote($volume);
2008 my $number=$biblioitem->{'number'};
2009 my $q_number=$dbh->quote($number);
2010 my $classification=$biblioitem->{'classification'};
2011 my $q_classification=$dbh->quote($classification);
2012 my $itemtype=$biblioitem->{'itemtype'};
2013 my $q_itemtype=$dbh->quote($itemtype);
2014 my $isbn=$biblioitem->{'isbn'};
2015 my $q_isbn=$dbh->quote($isbn);
2016 my $issn=$biblioitem->{'issn'};
2017 my $q_issn=$dbh->quote($issn);
2018 my $dewey=$biblioitem->{'dewey'};
2020 ($dewey == 0) && ($dewey='');
2021 my $subclass=$biblioitem->{'subclass'};
2022 my $q_subclass=$dbh->quote($subclass);
2023 my $publicationyear=$biblioitem->{'publicationyear'};
2024 my $publishercode=$biblioitem->{'publishercode'};
2025 my $q_publishercode=$dbh->quote($publishercode);
2026 my $volumedate=$biblioitem->{'volumedate'};
2027 my $q_volumedate=$dbh->quote($volumedate);
2028 my $illus=$biblioitem->{'illus'};
2029 my $q_illus=$dbh->quote($illus);
2030 my $pages=$biblioitem->{'pages'};
2031 my $q_pages=$dbh->quote($pages);
2032 my $notes=$biblioitem->{'notes'};
2033 my $q_notes=$dbh->quote($notes);
2034 my $size=$biblioitem->{'size'};
2035 my $q_size=$dbh->quote($size);
2036 my $place=$biblioitem->{'place'};
2037 my $q_place=$dbh->quote($place);
2038 my $lccn=$biblioitem->{'lccn'};
2039 my $q_lccn=$dbh->quote($lccn);
2042 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
2045 unless ($env->{'marconly'}) {
2046 #my $sth=$dbh->prepare("lock tables biblioitems write");
2048 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
2050 my ($biblioitemnumber) =$sth->fetchrow;
2051 $biblioitemnumber++;
2052 $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)");
2054 #my $sth=$dbh->prepare("unlock tables");
2059 # Should we check if there is already a biblioitem/amrc with the
2060 # same isbn/lccn/issn?
2062 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
2064 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
2065 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2067 my ($subtitle) = $sth->fetchrow;
2068 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2070 my @additionalauthors;
2071 while (my ($additionalauthor) = $sth->fetchrow) {
2072 push (@additionalauthors, $additionalauthor);
2074 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2077 while (my ($subject) = $sth->fetchrow) {
2078 push (@subjects, $subject);
2083 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
2085 my $Resource_ID=$dbh->{'mysql_insertid'};
2086 my $Record_ID=$Resource_ID;
2087 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
2093 $subfields->{1}->{'Subfield_Mark'}='a';
2094 $subfields->{1}->{'Subfield_Value'}=$title;
2096 $subfields->{2}->{'Subfield_Mark'}='b';
2097 $subfields->{2}->{'Subfield_Value'}=$subtitle;
2100 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2106 $subfields->{1}->{'Subfield_Mark'}='a';
2107 $subfields->{1}->{'Subfield_Value'}=$author;
2109 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2114 $subfields->{1}->{'Subfield_Mark'}='a';
2115 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
2117 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2122 $subfields->{1}->{'Subfield_Mark'}='a';
2123 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
2124 $subfields->{2}->{'Subfield_Mark'}='3';
2125 $subfields->{2}->{'Subfield_Value'}='biblio';
2127 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2129 # Additional Authors
2130 foreach (@additionalauthors) {
2132 (next) unless ($author);
2134 $subfields->{1}->{'Subfield_Mark'}='a';
2135 $subfields->{1}->{'Subfield_Value'}=$author;
2136 $subfields->{2}->{'Subfield_Mark'}='e';
2137 $subfields->{2}->{'Subfield_Value'}='author';
2139 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2143 (next) unless ($illus);
2145 $subfields->{1}->{'Subfield_Mark'}='a';
2146 $subfields->{1}->{'Subfield_Value'}=$illus;
2147 $subfields->{2}->{'Subfield_Mark'}='e';
2148 $subfields->{2}->{'Subfield_Value'}='illustrator';
2150 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2153 foreach (@subjects) {
2155 (next) unless ($subject);
2157 $subfields->{1}->{'Subfield_Mark'}='a';
2158 $subfields->{1}->{'Subfield_Value'}=$subject;
2160 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2167 $subfields->{1}->{'Subfield_Mark'}='a';
2168 $subfields->{1}->{'Subfield_Value'}=$isbn;
2170 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2175 $subfields->{1}->{'Subfield_Mark'}='a';
2176 $subfields->{1}->{'Subfield_Value'}=$lccn;
2178 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2183 $subfields->{1}->{'Subfield_Mark'}='a';
2184 $subfields->{1}->{'Subfield_Value'}=$issn;
2186 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2191 $subfields->{1}->{'Subfield_Mark'}='a';
2192 $subfields->{1}->{'Subfield_Value'}=$dewey;
2194 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2196 # DEWEY subclass and itemtype
2199 $subfields->{1}->{'Subfield_Mark'}='a';
2200 $subfields->{1}->{'Subfield_Value'}=$itemtype;
2201 $subfields->{2}->{'Subfield_Mark'}='b';
2202 $subfields->{2}->{'Subfield_Value'}=$subclass;
2203 $subfields->{3}->{'Subfield_Mark'}='c';
2204 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
2205 $subfields->{4}->{'Subfield_Mark'}='d';
2206 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
2208 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2213 $subfields->{1}->{'Subfield_Mark'}='a';
2214 $subfields->{1}->{'Subfield_Value'}=$place;
2215 $subfields->{2}->{'Subfield_Mark'}='b';
2216 $subfields->{2}->{'Subfield_Value'}=$publishercode;
2217 $subfields->{3}->{'Subfield_Mark'}='c';
2218 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
2219 if ($copyrightdate) {
2220 $subfields->{4}->{'Subfield_Mark'}='c';
2221 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
2224 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2227 if ($pages || $size) {
2229 $subfields->{1}->{'Subfield_Mark'}='a';
2230 $subfields->{1}->{'Subfield_Value'}=$pages;
2231 $subfields->{2}->{'Subfield_Mark'}='c';
2232 $subfields->{2}->{'Subfield_Value'}=$size;
2234 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2237 if ($volume || $number) {
2239 $subfields->{1}->{'Subfield_Mark'}='v';
2240 $subfields->{1}->{'Subfield_Value'}=$volume;
2241 $subfields->{2}->{'Subfield_Mark'}='n';
2242 $subfields->{2}->{'Subfield_Value'}=$number;
2244 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2249 $subfields->{1}->{'Subfield_Mark'}='a';
2250 $subfields->{1}->{'Subfield_Value'}=$notes;
2251 $subfields->{2}->{'Subfield_Mark'}='3';
2252 $subfields->{2}->{'Subfield_Value'}='biblioitem';
2254 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2258 return ($env, $Record_ID);
2261 sub OLD_MAYBE_DELETED_newItem {
2262 my ($env, $Record_ID, $item) = @_;
2264 my $barcode=$item->{'barcode'};
2265 my $q_barcode=$dbh->quote($barcode);
2266 my $biblionumber=$item->{'biblionumber'};
2267 my $biblioitemnumber=$item->{'biblioitemnumber'};
2268 my $dateaccessioned=$item->{'dateaccessioned'};
2269 my $booksellerid=$item->{'booksellerid'};
2270 my $q_booksellerid=$dbh->quote($booksellerid);
2271 my $homebranch=$item->{'homebranch'};
2272 my $q_homebranch=$dbh->quote($homebranch);
2273 my $holdingbranch=$item->{'holdingbranch'};
2274 my $price=$item->{'price'};
2275 my $replacementprice=$item->{'replacementprice'};
2276 my $replacementpricedate=$item->{'replacementpricedate'};
2277 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
2278 my $notforloan=$item->{'notforloan'};
2279 my $itemlost=$item->{'itemlost'};
2280 my $wthdrawn=$item->{'wthdrawn'};
2281 my $restricted=$item->{'restricted'};
2282 my $itemnotes=$item->{'itemnotes'};
2283 my $q_itemnotes=$dbh->quote($itemnotes);
2284 my $itemtype=$item->{'itemtype'};
2285 my $subclass=$item->{'subclass'};
2289 unless ($env->{'marconly'}) {
2290 my $sth=$dbh->prepare("select max(itemnumber) from items");
2292 my ($itemnumber) =$sth->fetchrow;
2294 $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)");
2301 $subfields->{1}->{'Subfield_Mark'}='p';
2302 $subfields->{1}->{'Subfield_Value'}=$barcode;
2303 $subfields->{2}->{'Subfield_Mark'}='d';
2304 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
2305 $subfields->{3}->{'Subfield_Mark'}='e';
2306 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
2307 $subfields->{4}->{'Subfield_Mark'}='b';
2308 $subfields->{4}->{'Subfield_Value'}=$homebranch;
2309 $subfields->{5}->{'Subfield_Mark'}='l';
2310 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
2311 $subfields->{6}->{'Subfield_Mark'}='c';
2312 $subfields->{6}->{'Subfield_Value'}=$price;
2313 $subfields->{7}->{'Subfield_Mark'}='c';
2314 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
2315 $subfields->{8}->{'Subfield_Mark'}='d';
2316 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
2318 $subfields->{9}->{'Subfield_Mark'}='h';
2319 $subfields->{9}->{'Subfield_Value'}='Not for loan';
2322 $subfields->{10}->{'Subfield_Mark'}='j';
2323 $subfields->{10}->{'Subfield_Value'}='Item lost';
2326 $subfields->{11}->{'Subfield_Mark'}='j';
2327 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
2330 $subfields->{12}->{'Subfield_Mark'}='z';
2331 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
2335 $env->{'linkage'}=1;
2336 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2337 $env->{'linkage'}=0;
2338 $env->{'linkid'}=$Tag_ID;
2341 $subfields2->{1}->{'Subfield_Mark'}='a';
2342 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
2343 $subfields2->{1}->{'Subfield_Mark'}='b';
2344 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
2345 $subfields2->{1}->{'Subfield_Mark'}='c';
2346 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
2347 $subfields2->{2}->{'Subfield_Mark'}='m';
2348 $subfields2->{2}->{'Subfield_Value'}=$subclass;
2349 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
2350 $env->{'linkid'}='';
2353 sub OLD_MAYBE_DELETED_updateBiblio {
2354 # Update the biblio with biblionumber $biblio->{'biblionumber'}
2355 # I guess this routine should search through all marc records for a record that
2356 # has the same biblionumber stored in it, and modify the MARC record as well as
2359 # Also, this subroutine should search through the $biblio object and compare it
2360 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
2361 # this logging feature to be usable to undo changes easily.
2363 my ($env, $biblio) = @_;
2365 my $biblionumber=$biblio->{'biblionumber'};
2367 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
2369 my $origbiblio=$sth->fetchrow_hashref;
2370 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2372 my ($subtitle)=$sth->fetchrow;
2373 $origbiblio->{'subtitle'}=$subtitle;
2374 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2376 my $origadditionalauthors;
2377 while (my ($author) = $sth->fetchrow) {
2378 push (@{$origbiblio->{'additionalauthors'}}, $author);
2379 $origadditionalauthors->{$author}=1;
2381 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2384 while (my ($subject) = $sth->fetchrow) {
2385 push (@{$origbiblio->{'subjects'}}, $subject);
2386 $origsubjects->{$subject}=1;
2390 # Obtain a list of MARC Record_ID's that are tied to this biblio
2391 $sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
2394 while (my ($bibid) = $sth->fetchrow) {
2395 push(@marcrecords, $bibid);
2399 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
2400 my $q_author=$dbh->quote($biblio->{'author'});
2401 logchange('kohadb', 'change', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
2402 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
2404 foreach $bibid (@marcrecords) {
2405 logchange('marc', 'change', $bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2406 changeSubfield($bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2409 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
2410 my $q_title=$dbh->quote($biblio->{'title'});
2411 logchange('kohadb', 'change', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
2412 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
2414 foreach $Record_ID (@marcrecords) {
2415 logchange('marc', 'change', $Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2416 changeSubfield($Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2419 if ($biblio->{'subtitle'} ne $origbiblio->{'subtitle'}) {
2420 my $q_subtitle=$dbh->quote($biblio->{'subtitle'});
2421 logchange('kohadb', 'change', 'biblio', 'subtitle', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2422 my $sti=$dbh->prepare("update bibliosubtitle set subtitle=$q_subtitle where biblionumber=$biblio->{'biblionumber'}");
2424 foreach $Record_ID (@marcrecords) {
2425 logchange('marc', 'change', $Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2426 changeSubfield($Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2429 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
2430 my $q_unititle=$dbh->quote($biblio->{'unititle'});
2431 logchange('kohadb', 'change', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
2432 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
2435 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
2436 my $q_notes=$dbh->quote($biblio->{'notes'});
2437 logchange('kohadb', 'change', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
2438 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
2440 foreach $Record_ID (@marcrecords) {
2441 logchange('marc', 'change', $Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2442 changeSubfield($Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2445 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
2446 my $q_serial=$dbh->quote($biblio->{'serial'});
2447 logchange('kohadb', 'change', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
2448 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
2451 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
2452 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
2453 logchange('kohadb', 'change', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2454 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
2456 foreach $Record_ID (@marcrecords) {
2457 logchange('marc', 'change', $Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2458 changeSubfield($Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2461 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
2462 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
2463 logchange('kohadb', 'change', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
2464 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
2466 foreach $Record_ID (@marcrecords) {
2467 logchange('marc', 'change', $Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2468 changeSubfield($Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2472 # Check for subject heading changes
2476 foreach $newsubject (@{$biblio->{'subject'}}) {
2477 $subjects->{$newsubject}=1;
2478 if ($origsubjects->{$newsubject}) {
2479 $subjects->{$newsubject}=2;
2481 my $q_newsubject=$dbh->quote($newsubject);
2482 my $sth=$dbh->prepare("insert into bibliosubject (subject,biblionumber) values ($q_newsubject, $biblionumber)");
2484 logchange('kohadb', 'add', 'biblio', 'subject', $newsubject);
2486 $subfields->{1}->{'Subfield_Mark'}='a';
2487 $subfields->{1}->{'Subfield_Value'}=$newsubject;
2490 foreach $Record_ID (@marcrecords) {
2491 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2492 logchange('marc', 'add', $Record_ID, '650', 'a', $newsubject);
2497 foreach $origsubject (keys %$origsubjects) {
2498 if ($subjects->{$origsubject} == 1) {
2499 my $q_origsubject=$dbh->quote($origsubject);
2500 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'subject', $origsubject);
2501 my $sth=$dbh->prepare("delete from bibliosubject where biblionumber=$biblionumber and subject=$q_origsubject");
2507 sub OLD_MAYBE_DELETED_updateBiblioItem {
2508 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
2510 # This routine should also check to see which fields are actually being
2511 # modified, and log all changes.
2513 my ($env, $biblioitem) = @_;
2516 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2517 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
2518 # obi = original biblioitem
2519 my $obi=$sth->fetchrow_hashref;
2520 $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");
2522 my ($Record_ID) = $sth->fetchrow;
2523 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
2524 logchange('kohadb', 'change', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2525 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
2526 logchange('marc', 'change', $Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2527 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2529 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
2530 logchange('kohadb', 'change', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
2531 my $q_volume=$dbh->quote($biblioitem->{'volume'});
2532 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
2533 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2534 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2536 if ($biblioitem->{'number'} ne $obi->{'number'}) {
2537 logchange('kohadb', 'change', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
2538 my $q_number=$dbh->quote($biblioitem->{'number'});
2539 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
2540 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2541 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2543 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
2544 logchange('kohadb', 'change', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2545 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
2546 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
2547 logchange('marc', 'change', $Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2548 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2550 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
2551 logchange('kohadb', 'change', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
2552 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
2553 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
2554 logchange('marc', 'change', $Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2555 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2557 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
2558 logchange('kohadb', 'change', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
2559 my $q_issn=$dbh->quote($biblioitem->{'issn'});
2560 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
2561 logchange('marc', 'change', $Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2562 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2564 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
2565 logchange('kohadb', 'change', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
2566 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
2567 logchange('marc', 'change', $Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2568 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2570 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
2571 logchange('kohadb', 'change', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
2572 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
2573 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
2574 logchange('marc', 'change', $Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2575 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2577 if ($biblioitem->{'place'} ne $obi->{'place'}) {
2578 logchange('kohadb', 'change', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
2579 my $q_place=$dbh->quote($biblioitem->{'place'});
2580 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
2581 logchange('marc', 'change', $Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2582 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2584 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
2585 logchange('kohadb', 'change', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2586 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
2587 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
2588 logchange('marc', 'change', $Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2589 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2591 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
2592 logchange('kohadb', 'change', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2593 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
2594 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
2595 logchange('marc', 'change', $Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2596 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2598 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
2599 logchange('kohadb', 'change', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
2600 my $q_illus=$dbh->quote($biblioitem->{'illus'});
2601 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
2602 logchange('marc', 'change', $Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2603 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2605 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
2606 logchange('kohadb', 'change', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
2607 my $q_pages=$dbh->quote($biblioitem->{'pages'});
2608 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
2609 logchange('marc', 'change', $Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2610 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2612 if ($biblioitem->{'size'} ne $obi->{'size'}) {
2613 logchange('kohadb', 'change', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
2614 my $q_size=$dbh->quote($biblioitem->{'size'});
2615 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
2616 logchange('marc', 'change', $Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2617 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2619 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
2620 logchange('kohadb', 'change', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
2621 my $q_notes=$dbh->quote($biblioitem->{'notes'});
2622 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
2623 logchange('marc', 'change', $Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2624 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2626 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
2627 logchange('kohadb', 'change', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
2628 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
2629 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
2630 logchange('marc', 'change', $Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2631 changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2638 sub OLD_MAYBE_DELETED_updateItem {
2639 # Update the item with itemnumber $item->{'itemnumber'}
2640 # This routine should also modify the corresponding MARC record data. (852 and
2641 # 876 tags with 876p tag the same as $item->{'barcode'}
2643 # This routine should also check to see which fields are actually being
2644 # modified, and log all changes.
2646 my ($env, $item) = @_;
2648 my $itemnumber=$item->{'itemnumber'};
2649 my $biblionumber=$item->{'biblionumber'};
2650 my $biblioitemnumber=$item->{'biblioitemnumber'};
2651 my $barcode=$item->{'barcode'};
2652 my $dateaccessioned=$item->{'dateaccessioned'};
2653 my $booksellerid=$item->{'booksellerid'};
2654 my $homebranch=$item->{'homebranch'};
2655 my $price=$item->{'price'};
2656 my $replacementprice=$item->{'replacementprice'};
2657 my $replacementpricedate=$item->{'replacementpricedate'};
2658 my $multivolume=$item->{'multivolume'};
2659 my $stack=$item->{'stack'};
2660 my $notforloan=$item->{'notforloan'};
2661 my $itemlost=$item->{'itemlost'};
2662 my $wthdrawn=$item->{'wthdrawn'};
2663 my $bulk=$item->{'bulk'};
2664 my $restricted=$item->{'restricted'};
2665 my $binding=$item->{'binding'};
2666 my $itemnotes=$item->{'itemnotes'};
2667 my $holdingbranch=$item->{'holdingbranch'};
2668 my $interim=$item->{'interim'};
2669 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
2671 my $olditem=$sth->fetchrow_hashref;
2672 my $q_barcode=$dbh->quote($olditem->{'barcode'});
2673 $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");
2675 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
2676 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
2678 my ($link) = $sth->fetchrow;
2679 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
2681 my ($Subfield852_ID) = $sth->fetchrow;
2683 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
2684 logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
2685 my $q_barcode=$dbh->quote($item->{'barcode'});
2686 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
2688 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
2689 logchange('marc', 'change', $Record_ID, '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
2691 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
2692 logchange('kohadb', 'change', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
2693 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
2694 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
2696 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
2697 logchange('marc', 'change', $Record_ID, '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
2699 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
2700 logchange('kohadb', 'change', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2701 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
2702 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
2704 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
2705 logchange('marc', 'change', $Record_ID, '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2707 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
2708 logchange('kohadb', 'change', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
2709 my $q_homebranch=$dbh->quote($item->{'homebranch'});
2710 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
2712 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
2713 logchange('marc', 'change', $Record_ID, '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
2715 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
2716 logchange('kohadb', 'change', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2717 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
2718 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
2720 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
2721 logchange('marc', 'change', $Record_ID, '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2723 if ($item->{'price'} ne $olditem->{'price'}) {
2724 logchange('kohadb', 'change', 'items', 'price', $olditem->{'price'}, $item->{'price'});
2725 my $q_price=$dbh->quote($item->{'price'});
2726 my $sth=$dbh->prepare("update items set price=$q_price where itemnumber=$itemnumber");
2728 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'price'}, $item->{'price'}, $Subfield876_ID);
2729 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'price'}, $item->{'price'});
2731 if ($item->{'itemnotes'} ne $olditem->{'itemnotes'}) {
2732 logchange('kohadb', 'change', 'items', 'itemnotes', $olditem->{'itemnotes'}, $item->{'itemnotes'});
2733 my $q_itemnotes=$dbh->quote($item->{'itemnotes'});
2734 my $sth=$dbh->prepare("update items set itemnotes=$q_itemnotes where itemnumber=$itemnumber");
2736 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'itemnotes'}, $item->{'itemnotes'}, $Subfield876_ID);
2737 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'itemnotes'}, $item->{'itemnotes'});
2739 if ($item->{'notforloan'} ne $olditem->{'notforloan'}) {
2740 logchange('kohadb', 'change', 'items', 'notforloan', $olditem->{'notforloan'}, $item->{'notforloan'});
2741 my $sth=$dbh->prepare("update items set notforloan=$notforloan where itemnumber=$itemnumber");
2743 if ($item->{'notforloan'}) {
2744 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2745 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2747 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2748 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2751 if ($item->{'itemlost'} ne $olditem->{'itemlost'}) {
2752 logchange('kohadb', 'change', 'items', 'itemlost', $olditem->{'itemlost'}, $item->{'itemlost'});
2753 my $sth=$dbh->prepare("update items set itemlost=$itemlost where itemnumber=$itemnumber");
2755 if ($item->{'itemlost'}) {
2756 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2757 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2759 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2760 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2763 if ($item->{'wthdrawn'} ne $olditem->{'wthdrawn'}) {
2764 logchange('kohadb', 'change', 'items', 'wthdrawn', $olditem->{'wthdrawn'}, $item->{'wthdrawn'});
2765 my $sth=$dbh->prepare("update items set wthdrawn=$wthdrawn where itemnumber=$itemnumber");
2767 if ($item->{'wthdrawn'}) {
2768 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2769 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2771 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2772 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2775 if ($item->{'restricted'} ne $olditem->{'restricted'}) {
2776 logchange('kohadb', 'change', 'items', 'restricted', $olditem->{'restricted'}, $item->{'restricted'});
2777 my $sth=$dbh->prepare("update items set restricted=$restricted where itemnumber=$itemnumber");
2779 if ($item->{'restricted'}) {
2780 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2781 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2783 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2784 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2791 # Add a biblioitem and related data to Koha database
2792 sub OLD_MAY_BE_DELETED_newcompletebiblioitem {
2797 $biblio, # hash ref to biblio record
2798 $biblioitem, # hash ref to biblioitem record
2799 $subjects, # list ref of subjects
2800 $addlauthors, # list ref of additional authors
2803 my ( $biblionumber, $biblioitemnumber, $error); # return values
2808 my $additionalauthor;
2811 requireDBI($dbh,"newcompletebiblioitem");
2813 print "<PRE>Trying to add biblio item Title=$biblio->{title} " .
2814 "ISBN=$biblioitem->{isbn} </PRE>\n" if $debug;
2816 # Make sure master biblio entry exists
2817 ($biblionumber,$error)=getoraddbiblio($dbh, $biblio);
2821 $biblioitem->{biblionumber}=$biblionumber;
2824 $biblioitemnumber=newbiblioitem($biblioitem);
2827 $sth=$dbh->prepare("insert into bibliosubject
2828 (biblionumber,subject)
2830 foreach $subjectheading (@{$subjects} ) {
2831 $sth->execute($biblionumber, $subjectheading)
2832 or $error.=$sth->errstr ;
2836 # Add additional authors
2837 $sth=$dbh->prepare("insert into additionalauthors
2838 (biblionumber,author)
2840 foreach $additionalauthor (@{$addlauthors} ) {
2841 $sth->execute($biblionumber, $additionalauthor)
2842 or $error.=$sth->errstr ;
2846 # couldn't get biblio
2848 $biblioitemnumber='';
2850 } # if no biblio error
2852 return ( $biblionumber, $biblioitemnumber, $error);
2854 } # sub newcompletebiblioitem
2858 # END OF UNUSEFUL SUBs
2862 END { } # module clean-up code here (global destructor)