4 # Revision 1.10 2002/09/22 16:50:08 arensb
5 # Added some FIXME comments.
7 # Revision 1.9 2002/09/20 12:57:46 tipaul
8 # long is the road to 1.4.0
9 # * MARCadditem and MARCmoditem now wroks
10 # * various bugfixes in MARC management
11 # !!! 1.3.0 should be released very soon now. Be careful !!!
13 # Revision 1.8 2002/09/10 13:53:52 tipaul
14 # MARC API continued...
16 # * 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)
18 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
20 # Revision 1.7 2002/08/14 18:12:51 tonnesen
21 # Added copyright statement to all .pl and .pm files
23 # Revision 1.6 2002/07/25 13:40:31 tipaul
24 # pod documenting the API.
26 # Revision 1.5 2002/07/24 16:11:37 tipaul
28 # Database.pm and Output.pm are almost not modified (var test...)
30 # Biblio.pm is almost completly rewritten.
32 # WHAT DOES IT ??? ==> END of Hitchcock suspens
34 # 1st, it does... nothing...
35 # 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 ...
37 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
38 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
39 # * 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.
40 # * 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.
41 # 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 ;-)
43 # 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.
44 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
48 # move from 1.2 to 1.4 version :
49 # 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
50 # In the 1.4 version, we want to do 2 differents things :
51 # - keep populating the old-DB, that has a LOT less datas than MARC
52 # - populate the MARC-DB
53 # To populate the DBs we have 2 differents sources :
54 # - the standard acquisition system (through book sellers), that does'nt use MARC data
55 # - the MARC acquisition system, that uses MARC data.
57 # thus, we have 2 differents cases :
58 # - 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
59 # - 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.
60 # we MUST have an API for true MARC data, that populate MARC-DB then old-DB
62 # That's why we need 4 subs :
63 # all subs beginning by MARC manage only MARC tables. They manage MARC-DB with MARC::Record parameters
64 # all subs beginning by OLD manage only OLD-DB tables. They manage old-DB with old-DB parameters
65 # 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
66 # 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.
68 # only ALL and old-style API should be used in koha. MARC and OLD is used internally only
70 # 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.
71 # 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 ;-)
75 # Copyright 2000-2002 Katipo Communications
77 # This file is part of Koha.
79 # Koha is free software; you can redistribute it and/or modify it under the
80 # terms of the GNU General Public License as published by the Free Software
81 # Foundation; either version 2 of the License, or (at your option) any later
84 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
85 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
86 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
88 # You should have received a copy of the GNU General Public License along with
89 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
90 # Suite 330, Boston, MA 02111-1307 USA
97 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
99 # set the version for version checking
104 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
105 # as the old-style API and the ALL one are the only public functions.
108 &updateBiblio &updateBiblioItem &updateItem
109 &itemcount &newbiblio &newbiblioitem
110 &modnote &newsubject &newsubtitle
111 &modbiblio &checkitems
112 &newitems &modbibitem
113 &modsubtitle &modsubject &modaddauthor &moditem &countitems
114 &delitem &deletebiblioitem &delbiblio
115 &getitemtypes &getbiblio
116 &getbiblioitembybiblionumber
117 &getbiblioitem &getitemsbybiblioitem &isbnsearch
119 &newcompletebiblioitem
121 &ALLnewbiblio &ALLnewitem
124 &MARCaddbiblio &MARCadditem
125 &MARCmodsubfield &MARCaddsubfield
126 &MARCmodbiblio &MARCmoditem
128 &MARCkoha2marcBiblio &MARCmarc2koha &MARCkoha2marcItem
129 &MARCgetbiblio &MARCgetitem
130 &MARCaddword &MARCdelword
132 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
134 # your exported package globals go here,
135 # as well as any optionally exported functions
137 @EXPORT_OK = qw($Var1 %Hashit); # FIXME - These are never used
140 # non-exported package globals go here
141 use vars qw(@more $stuff); # FIXME - These are never used
143 # initalize package globals, first exported ones
145 # FIXME - These are never used
150 # then the others (which are still accessible as $Some::Module::stuff)
151 # FIXME - These are never used
155 # all file-scoped lexicals must be created before
156 # the functions below that use them.
158 # file-private lexicals go here
159 # FIXME - These are never used
161 my %secret_hash = ();
163 # here's a file-private function as a closure,
164 # callable as &$priv_func; it cannot be prototyped.
165 # FIXME - This is never used
166 my $priv_func = sub {
170 # make all your functions, whether exported or not;
174 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
177 # all the following subs takes a MARC::Record as parameter and manage
178 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
179 # ALLxxx subs (xxx deals with old-DB parameters, the ALLxxx deals with MARC-DB parameter)
184 all subs requires/use $dbh as 1st parameter.
185 NOTE : all those subs are private and must be used only inside Biblio.pm (called by a old API sub, or the ALLsub)
189 =head2 @tagslib = &MARCgettagslib($dbh,1|0);
190 last param is 1 for liblibrarian and 0 for libopac
191 returns a hash with tag/subfield meaning
193 =head2 ($tagfield,$tagsubfield) = &MARCfindmarc_from_kohafield($dbh,$kohafield);
194 finds MARC tag and subfield for a given kohafield
195 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
197 =head2 $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
198 finds a old-db biblio number for a given MARCbibid number
200 =head2 $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
201 finds a MARC bibid from a old-db biblionumber
203 =head2 &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
204 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
206 =head2 &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
207 adds a subfield in a biblio (in the MARC tables only).
209 =head2 $MARCRecord = &MARCgetbiblio($dbh,$bibid);
210 Returns a MARC::Record for the biblio $bibid.
212 =head2 &MARCmodbiblio($dbh,$bibid,$delete,$record);
213 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
214 if $delete == 1, every field/subfield not found is deleted in the biblio
215 otherwise, only data passed to MARCmodbiblio is managed.
216 thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
218 =head2 ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
219 MARCmodsubfield changes the value of a given subfield
221 =head2 $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
222 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
223 Returns -1 if more than 1 answer
225 =head2 $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
226 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
228 =head2 &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
229 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
231 =head2 &MARCdelbiblio($dbh,$bibid);
232 MARCdelbiblio delete biblio $bibid
234 =head2 $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
235 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
237 =head2 $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
238 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
240 =head2 $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
241 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
243 =head2 &MARCkoha2marcOnefield => used by MARCkoha2marc and should not be useful elsewhere
245 =head2 $olddb = &MARCmarc2koha($dbh,$MARCRecord);
246 builds a hash with old-db datas from a MARC::Record
248 =head2 &MARCmarc2kohaOnefield => used by MARCmarc2koha and should not be useful elsewhere
250 =head2 MARCaddword => used to manage MARC_word table and should not be useful elsewhere
252 =head2 MARCdelword => used to manage MARC_word table and should not be useful elsewhere
256 Paul POULAIN paul.poulain@free.fr
261 my ($dbh,$forlibrarian)= @_;
263 if ($forlibrarian eq 1) {
264 $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib from marc_subfield_structure");
266 $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib from marc_subfield_structure");
273 while ( ($tag,$subfield,$lib) = $sth->fetchrow) {
274 $res->{$tag}->{$subfield}=$lib;
279 sub MARCfind_marc_from_kohafield {
280 my ($dbh,$kohafield) = @_;
281 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
282 $sth->execute($kohafield);
283 my ($tagfield,$tagsubfield) = $sth->fetchrow;
284 return ($tagfield,$tagsubfield);
287 sub MARCfind_oldbiblionumber_from_MARCbibid {
288 my ($dbh,$MARCbibid) = @_;
289 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
290 $sth->execute($MARCbibid);
291 my ($biblionumber) = $sth->fetchrow;
292 return $biblionumber;
295 sub MARCfind_MARCbibid_from_oldbiblionumber {
296 my ($dbh,$oldbiblionumber) = @_;
297 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
298 $sth->execute($oldbiblionumber);
299 my ($bibid) = $sth->fetchrow;
304 # pass the MARC::Record to this function, and it will create the records in the marc tables
305 my ($dbh,$record,$biblionumber) = @_;
306 my @fields=$record->fields();
308 # adding main table, and retrieving bibid
309 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
310 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
311 $sth->execute($biblionumber);
312 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
314 ($bibid)=$sth->fetchrow;
317 # now, add subfields...
318 foreach my $field (@fields) {
319 my @subfields=$field->subfields();
321 foreach my $subfieldcount (0..$#subfields) {
322 &MARCaddsubfield($dbh,$bibid,
324 $field->indicator(1).$field->indicator(2),
326 $subfields[$subfieldcount][0],
328 $subfields[$subfieldcount][1]
332 $dbh->do("unlock tables");
337 # pass the MARC::Record to this function, and it will create the records in the marc tables
338 my ($dbh,$record,$biblionumber) = @_;
339 # search for MARC biblionumber
340 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
341 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
342 my @fields=$record->fields();
343 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
344 $sth->execute($bibid);
345 my ($fieldcount) = $sth->fetchrow;
346 # now, add subfields...
347 foreach my $field (@fields) {
348 my @subfields=$field->subfields();
350 foreach my $subfieldcount (0..$#subfields) {
351 &MARCaddsubfield($dbh,$bibid,
353 $field->indicator(1).$field->indicator(2),
355 $subfields[$subfieldcount][0],
357 $subfields[$subfieldcount][1]
361 $dbh->do("unlock tables");
365 sub MARCaddsubfield {
366 # Add a new subfield to a tag into the DB.
367 my ($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
368 # if not value, end of job, we do nothing
369 if (not($subfieldvalue)) {
372 if (not($subfieldcode)) {
375 if (length($subfieldvalue)>255) {
376 # $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
377 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
378 $sth->execute($subfieldvalue);
379 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
381 my ($res)=$sth->fetchrow;
382 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?)");
384 $sth->execute($bibid,'0'.$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
386 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
389 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
391 # $dbh->do("unlock tables");
393 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?)");
394 $sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
396 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
399 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
404 # Returns MARC::Record of the biblio passed in parameter.
406 my $record = MARC::Record->new();
407 #---- TODO : the leader is missing
408 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
409 from marc_subfield_table
410 where bibid=? order by tagorder,subfieldorder
412 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
413 $sth->execute($bibid);
414 while (my $row=$sth->fetchrow_hashref) {
415 if ($row->{'valuebloblink'}) { #---- search blob if there is one
416 $sth2->execute($row->{'valuebloblink'});
417 my $row2=$sth2->fetchrow_hashref;
419 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
421 if ($record->field($row->{'tag'})) {
423 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
424 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
425 if (length($row->{'tag'}) <3) {
426 $row->{'tag'} = "0".$row->{'tag'};
428 $field =$record->field($row->{'tag'});
430 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
431 $record->delete_field($field);
432 $record->add_fields($field);
435 if (length($row->{'tag'}) < 3) {
436 $row->{'tag'} = "0".$row->{'tag'};
438 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
439 $record->add_fields($temp);
446 # Returns MARC::Record of the biblio passed in parameter.
447 my ($dbh,$bibid,$itemnumber)=@_;
448 warn "MARCgetitem : $bibid, $itemnumber\n";
449 my $record = MARC::Record->new();
450 # search MARC tagorder
451 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=?");
452 $sth2->execute($bibid,$itemnumber);
453 my ($tagorder) = $sth2->fetchrow_array();
454 #---- TODO : the leader is missing
455 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
456 from marc_subfield_table
457 where bibid=? and tagorder=? order by subfieldorder
459 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
460 $sth->execute($bibid,$tagorder);
461 while (my $row=$sth->fetchrow_hashref) {
462 if ($row->{'valuebloblink'}) { #---- search blob if there is one
463 $sth2->execute($row->{'valuebloblink'});
464 my $row2=$sth2->fetchrow_hashref;
466 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
468 if ($record->field($row->{'tag'})) {
470 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
471 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
472 if (length($row->{'tag'}) <3) {
473 $row->{'tag'} = "0".$row->{'tag'};
475 $field =$record->field($row->{'tag'});
477 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
478 $record->delete_field($field);
479 $record->add_fields($field);
482 if (length($row->{'tag'}) < 3) {
483 $row->{'tag'} = "0".$row->{'tag'};
485 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
486 $record->add_fields($temp);
494 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
495 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
496 # if nothing to change, don't waste time...
497 if ($oldrecord eq $record) {
500 # otherwise, skip through each subfield...
501 my @fields = $record->fields();
503 foreach my $field (@fields) {
504 my $oldfield = $oldrecord->field($field->tag());
505 my @subfields=$field->subfields();
508 foreach my $subfield (@subfields) {
510 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
511 # just adding datas...
512 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
513 1,@$subfield[0],$subfieldorder,@$subfield[1]);
515 # modify he subfield if it's a different string
516 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
517 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
518 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
526 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
527 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
528 # if nothing to change, don't waste time...
529 if ($oldrecord eq $record) {
532 # otherwise, skip through each subfield...
533 my @fields = $record->fields();
534 # search old MARC item
535 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=?");
536 $sth2->execute($bibid,$itemnumber);
537 my ($tagorder) = $sth2->fetchrow_array();
538 foreach my $field (@fields) {
539 my $oldfield = $oldrecord->field($field->tag());
540 my @subfields=$field->subfields();
542 foreach my $subfield (@subfields) {
544 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
545 # just adding datas...
546 warn "ADD = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
547 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
548 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
550 # modify he subfield if it's a different string
551 warn "MODIFY = $bibid,".$field->tag().",".$field->indicator(1).".".$field->indicator(2).", $tagorder,".@$subfield[0].",$subfieldorder,@$subfield[1])\n";
552 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
553 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
554 warn "MODIFY2 = $bibid, $subfieldid, ".@$subfield[1]."\n";
555 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
564 sub MARCmodsubfield {
565 # Subroutine changes a subfield value given a subfieldid.
566 my ($dbh, $subfieldid, $subfieldvalue )=@_;
567 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
568 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
569 $sth1->execute($subfieldid);
570 my ($oldvaluebloblink)=$sth1->fetchrow;
573 # if too long, use a bloblink
574 if (length($subfieldvalue)>255 ) {
575 # if already a bloblink, update it, otherwise, insert a new one.
576 if ($oldvaluebloblink) {
577 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
578 $sth->execute($subfieldvalue,$oldvaluebloblink);
580 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
581 $sth->execute($subfieldvalue);
582 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
584 my ($res)=$sth->fetchrow;
585 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
586 $sth->execute($subfieldid);
589 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
590 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
591 $sth->execute($subfieldvalue, $subfieldid);
593 $dbh->do("unlock tables");
595 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
596 $sth->execute($subfieldid);
597 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
599 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
600 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
601 return($subfieldid, $subfieldvalue);
604 sub MARCfindsubfield {
605 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
609 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
610 if ($subfieldvalue) {
611 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
613 if ($subfieldorder<1) {
616 $query .= " and subfieldorder=$subfieldorder";
618 my $sti=$dbh->prepare($query);
619 $sti->execute($bibid,$tag, $subfieldcode);
620 while (($subfieldid) = $sti->fetchrow) {
622 $lastsubfieldid=$subfieldid;
624 if ($resultcounter>1) {
625 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
626 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
629 return $lastsubfieldid;
633 sub MARCfindsubfieldid {
634 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
635 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
636 where bibid=? and tag=? and tagorder=?
637 and subfieldcode=? and subfieldorder=?");
638 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
639 my ($res) = $sth->fetchrow;
643 sub MARCdelsubfield {
644 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
645 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
646 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
647 tag='$tag' and tagorder='$tagorder'
648 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
653 # delete a biblio for a $bibid
654 my ($dbh,$bibid) = @_;
655 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
656 $dbh->do("delete from marc_biblio where bibid='$bibid'");
659 sub MARCkoha2marcBiblio {
660 # this function builds partial MARC::Record from the old koha-DB fields
661 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
662 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
663 my $record = MARC::Record->new();
664 #--- if bibid, then retrieve old-style koha data
665 if ($biblionumber>0) {
666 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
667 from biblio where biblionumber=?");
668 $sth2->execute($biblionumber);
669 my $row=$sth2->fetchrow_hashref;
671 foreach $code (keys %$row) {
673 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
677 #--- if biblioitem, then retrieve old-style koha data
678 if ($biblioitemnumber>0) {
679 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
680 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
681 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
683 WHERE biblionumber=? and biblioitemnumber=?
685 $sth2->execute($biblionumber,$biblioitemnumber);
686 my $row=$sth2->fetchrow_hashref;
688 foreach $code (keys %$row) {
690 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
695 # TODO : retrieve notes, additionalauthors
698 sub MARCkoha2marcItem {
699 # this function builds partial MARC::Record from the old koha-DB fields
700 my ($dbh,$biblionumber,$itemnumber) = @_;
701 # my $dbh=&C4Connect;
702 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
703 my $record = MARC::Record->new();
704 #--- if item, then retrieve old-style koha data
706 # print STDERR "prepare $biblionumber,$itemnumber\n";
707 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
708 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
709 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
710 reserves,restricted,binding,itemnotes,holdingbranch,interim,timestamp
712 WHERE itemnumber=?");
713 $sth2->execute($itemnumber);
714 my $row=$sth2->fetchrow_hashref;
716 foreach $code (keys %$row) {
718 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
723 # TODO : retrieve notes, additionalauthors
726 sub MARCkoha2marcSubtitle {
727 # this function builds partial MARC::Record from the old koha-DB fields
728 my ($dbh,$bibnum,$subtitle) = @_;
729 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
730 my $record = MARC::Record->new();
731 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
735 sub MARCkoha2marcOnefield {
736 my ($sth,$record,$kohafieldname,$value)=@_;
739 $sth->execute($kohafieldname);
740 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
741 if ($record->field($tagfield)) {
742 my $tag =$record->field($tagfield);
744 $tag->add_subfields($tagsubfield,$value);
745 $record->delete_field($tag);
746 $record->add_fields($tag);
749 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
756 my ($dbh,$record) = @_;
757 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
759 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
762 # print STDERR $record->as_formatted;
763 while (($field)=$sth2->fetchrow) {
764 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
766 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
769 while (($field)=$sth2->fetchrow) {
770 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
772 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
775 while (($field)=$sth2->fetchrow) {
776 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
778 # additional authors : specific
779 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
783 sub MARCmarc2kohaOneField {
784 # to check : if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
785 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
789 $sth->execute($kohatable.".".$kohafield);
790 ($tagfield,$subfield) = $sth->fetchrow;
791 foreach my $field ($record->field($tagfield)) {
792 if ($field->subfield($subfield)) {
793 if ($result->{$kohafield}) {
794 $result->{$kohafield} .= " | ".$field->subfield($subfield);
796 $result->{$kohafield}=$field->subfield($subfield);
804 # split a subfield string and adds it into the word table.
806 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
807 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
808 my @words = split / /,$sentence;
809 # build stopword list
810 my $sth2 =$dbh->prepare("select word from stopwords");
814 while(($stopword) = $sth2->fetchrow_array) {
815 $stopwords->{$stopword} = $stopword;
817 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
818 values (?,?,?,?,?,?,soundex(?))");
819 foreach my $word (@words) {
820 # we record only words longer than 2 car and not in stopwords hash
821 if (length($word)>1 and !($stopwords->{uc($word)})) {
822 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
824 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";
831 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
832 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
833 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
834 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
839 # ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL
842 # all the following subs are useful to manage MARC-DB with complete MARC records.
843 # it's used with marcimport, and marc management tools
848 all subs requires/use $dbh as 1st parameter.
849 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
853 =head2 (oldbibnum,$oldbibitemnum) = ALLnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
854 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
855 are builded from the MARC::Record. If they are passed, they are used.
857 =head2 ALLnewitem($dbh,$olditem);
858 adds an item in the db. $olditem is a old-db hash.
862 Paul POULAIN paul.poulain@free.fr
867 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
868 # note $oldbiblio and $oldbiblioitem are not mandatory.
869 # if not present, they will be builded from $record with MARCmarc2koha function
870 if (($oldbiblio) and not($oldbiblioitem)) {
871 print STDERR "ALLnewbiblio : missing parameter\n";
872 print "ALLnewbiblio : missing parameter : contact koha development team\n";
878 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
879 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
880 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
882 my $olddata = MARCmarc2koha($dbh,$record);
883 $oldbibnum = OLDnewbiblio($dbh,$olddata);
884 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
886 # we must add bibnum and bibitemnum in MARC::Record...
887 # we build the new field with biblionumber and biblioitemnumber
888 # we drop the original field
889 # we add the new builded field.
890 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
891 # (steve and paul : thinks 090 is a good choice)
892 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
893 $sth->execute("biblio.biblionumber");
894 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
895 $sth->execute("biblioitems.biblioitemnumber");
896 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
897 print STDERR "tag1 : $tagfield1 / $tagsubfield1\n tag2 : $tagfield2 / $tagsubfield2\n";
898 if ($tagsubfield1 != $tagsubfield2) {
899 print STDERR "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
900 print "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
903 my $newfield = MARC::Field->new( $tagfield1,'','',
904 "$tagsubfield1" => $oldbibnum,
905 "$tagsubfield2" => $oldbibitemnum);
906 # drop old field and create new one...
907 my $old_field = $record->field($tagfield1);
908 $record->delete_field($old_field);
909 $record->add_fields($newfield);
910 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
911 return ( $oldbibnum,$oldbibitemnum );
915 my ($dbh, $item) = @_;
918 ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{'barcode'});
919 # search MARC biblionumber
920 my $bibid=&MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{'biblionumber'});
922 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
923 $sth->execute($bibid);
924 my ($tagorder) = $sth->fetchrow;
927 # for each field, find MARC tag and subfield, and call the proper MARC sub
928 foreach my $itemkey (keys %$item) {
931 print STDERR "=============> $itemkey : ".$item->{$itemkey}."\n";
932 if ($itemkey eq "biblionumber" || $itemkey eq "biblioitemnumber") {
933 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"biblio.".$itemkey);
935 ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"items.".$itemkey);
937 if ($tagfield && $item->{$itemkey} ne 'NULL') {
939 &MARCaddsubfield($dbh,
955 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
961 all subs requires/use $dbh as 1st parameter.
962 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
964 They all are the exact copy of 1.0/1.2 version of the sub
965 without the OLD. The OLDxxx is called by the original xxx sub.
966 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
968 WARNING : there is 1 difference between initialxxx and OLDxxx :
969 the db header $dbh is always passed as parameter
970 to avoid over-DB connexion
974 =head2 $biblionumber = OLDnewbiblio($dbh,$biblio);
975 adds a record in biblio table. Datas are in the hash $biblio.
977 =head2 $biblionumber = OLDmodbiblio($dbh,$biblio);
978 modify a record in biblio table. Datas are in the hash $biblio.
980 =head2 OLDmodsubtitle($dbh,$bibnum,$subtitle);
981 modify subtitles in bibliosubtitle table.
983 =head2 OLDmodaddauthor($dbh,$bibnum,$author);
984 adds or modify additional authors
985 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
987 =head2 $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
990 =head2 OLDmodbibitem($dbh, $biblioitem);
993 =head2 OLDmodnote($dbh,$bibitemnum,$note
994 modify a note for a biblioitem
996 =head2 OLDnewbiblioitem($dbh,$biblioitem);
997 adds a biblioitem ($biblioitem is a hash with the values)
999 =head2 OLDnewsubject($dbh,$bibnum);
1001 =head2 OLDnewsubtitle($dbh,$bibnum,$subtitle);
1002 create a new subtitle
1004 =head2 ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1005 create a item. $item is a hash and $barcode the barcode.
1007 =head2 OLDmoditem($dbh,$item);
1010 =head2 OLDdelitem($dbh,$itemnum);
1013 =head2 OLDdeletebiblioitem($dbh,$biblioitemnumber);
1014 deletes a biblioitem
1015 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1017 =head2 OLDdelbiblio($dbh,$biblio);
1022 Paul POULAIN paul.poulain@free.fr
1027 my ($dbh,$biblio) = @_;
1028 # my $dbh = &C4Connect;
1029 my $query = "Select max(biblionumber) from biblio";
1030 my $sth = $dbh->prepare($query);
1032 my $data = $sth->fetchrow_arrayref;
1033 my $bibnum = $$data[0] + 1;
1036 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1037 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1038 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
1039 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
1040 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1041 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1042 if ($biblio->{'seriestitle'}) { $series = 1 };
1045 $query = "insert into biblio set
1046 biblionumber = $bibnum,
1047 title = $biblio->{'title'},
1048 author = $biblio->{'author'},
1049 copyrightdate = $biblio->{'copyright'},
1051 seriestitle = $biblio->{'seriestitle'},
1052 notes = $biblio->{'notes'},
1053 abstract = $biblio->{'abstract'}";
1055 $sth = $dbh->prepare($query);
1064 my ($dbh,$biblio) = @_;
1065 # my $dbh = C4Connect;
1069 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1070 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1071 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1072 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
1073 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
1074 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
1075 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
1076 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1078 $query = "Update biblio set
1079 title = $biblio->{'title'},
1080 author = $biblio->{'author'},
1081 abstract = $biblio->{'abstract'},
1082 copyrightdate = $biblio->{'copyrightdate'},
1083 seriestitle = $biblio->{'seriestitle'},
1084 serial = $biblio->{'serial'},
1085 unititle = $biblio->{'unititle'},
1086 notes = $biblio->{'notes'}
1087 where biblionumber = $biblio->{'biblionumber'}";
1088 $sth = $dbh->prepare($query);
1094 return($biblio->{'biblionumber'});
1097 sub OLDmodsubtitle {
1098 my ($dbh,$bibnum, $subtitle) = @_;
1099 # my $dbh = C4Connect;
1100 my $query = "update bibliosubtitle set
1101 subtitle = '$subtitle'
1102 where biblionumber = $bibnum";
1103 my $sth = $dbh->prepare($query);
1111 sub OLDmodaddauthor {
1112 my ($dbh,$bibnum, $author) = @_;
1113 # my $dbh = C4Connect;
1114 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1115 my $sth = $dbh->prepare($query);
1120 if ($author ne '') {
1121 $query = "Insert into additionalauthors set
1123 biblionumber = '$bibnum'";
1124 $sth = $dbh->prepare($query);
1132 } # sub modaddauthor
1136 my ($dbh,$bibnum, $force, @subject) = @_;
1137 # my $dbh = C4Connect;
1138 my $count = @subject;
1140 for (my $i = 0; $i < $count; $i++) {
1141 $subject[$i] =~ s/^ //g;
1142 $subject[$i] =~ s/ $//g;
1143 my $query = "select * from catalogueentry
1144 where entrytype = 's'
1145 and catalogueentry = '$subject[$i]'";
1146 my $sth = $dbh->prepare($query);
1149 if (my $data = $sth->fetchrow_hashref) {
1151 if ($force eq $subject[$i]) {
1152 # subject not in aut, chosen to force anway
1153 # so insert into cataloguentry so its in auth file
1154 $query = "Insert into catalogueentry
1155 (entrytype,catalogueentry)
1156 values ('s','$subject[$i]')";
1157 my $sth2 = $dbh->prepare($query);
1162 $error = "$subject[$i]\n does not exist in the subject authority file";
1163 $query = "Select * from catalogueentry
1164 where entrytype = 's'
1165 and (catalogueentry like '$subject[$i] %'
1166 or catalogueentry like '% $subject[$i] %'
1167 or catalogueentry like '% $subject[$i]')";
1168 my $sth2 = $dbh->prepare($query);
1171 while (my $data = $sth2->fetchrow_hashref) {
1172 $error = $error."<br>$data->{'catalogueentry'}";
1180 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1181 my $sth = $dbh->prepare($query);
1184 for (my $i = 0; $i < $count; $i++) {
1185 $sth = $dbh->prepare("Insert into bibliosubject
1186 values ('$subject[$i]', $bibnum)");
1198 my ($dbh,$biblioitem) = @_;
1199 # my $dbh = C4Connect;
1202 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1203 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1204 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1205 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1206 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1207 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1208 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1209 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1210 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1211 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1212 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1213 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1214 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1215 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1217 $query = "Update biblioitems set
1218 itemtype = $biblioitem->{'itemtype'},
1219 url = $biblioitem->{'url'},
1220 isbn = $biblioitem->{'isbn'},
1221 publishercode = $biblioitem->{'publishercode'},
1222 publicationyear = $biblioitem->{'publicationyear'},
1223 classification = $biblioitem->{'classification'},
1224 dewey = $biblioitem->{'dewey'},
1225 subclass = $biblioitem->{'subclass'},
1226 illus = $biblioitem->{'illus'},
1227 pages = $biblioitem->{'pages'},
1228 volumeddesc = $biblioitem->{'volumeddesc'},
1229 notes = $biblioitem->{'notes'},
1230 size = $biblioitem->{'size'},
1231 place = $biblioitem->{'place'}
1232 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1240 my ($dbh,$bibitemnum,$note)=@_;
1241 # my $dbh=C4Connect;
1242 my $query="update biblioitems set notes='$note' where
1243 biblioitemnumber='$bibitemnum'";
1244 my $sth=$dbh->prepare($query);
1250 sub OLDnewbiblioitem {
1251 my ($dbh,$biblioitem) = @_;
1252 # my $dbh = C4Connect;
1253 my $query = "Select max(biblioitemnumber) from biblioitems";
1254 my $sth = $dbh->prepare($query);
1258 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
1259 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
1260 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1261 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1262 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1263 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1264 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
1265 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1266 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1267 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1268 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1269 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
1270 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1271 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1272 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1273 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1274 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1275 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1276 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
1277 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
1280 $data = $sth->fetchrow_arrayref;
1281 $bibitemnum = $$data[0] + 1;
1285 $query = "insert into biblioitems set
1286 biblioitemnumber = $bibitemnum,
1287 biblionumber = $biblioitem->{'biblionumber'},
1288 volume = $biblioitem->{'volume'},
1289 number = $biblioitem->{'number'},
1290 classification = $biblioitem->{'classification'},
1291 itemtype = $biblioitem->{'itemtype'},
1292 url = $biblioitem->{'url'},
1293 isbn = $biblioitem->{'isbn'},
1294 issn = $biblioitem->{'issn'},
1295 dewey = $biblioitem->{'dewey'},
1296 subclass = $biblioitem->{'subclass'},
1297 publicationyear = $biblioitem->{'publicationyear'},
1298 publishercode = $biblioitem->{'publishercode'},
1299 volumedate = $biblioitem->{'volumedate'},
1300 volumeddesc = $biblioitem->{'volumeddesc'},
1301 illus = $biblioitem->{'illus'},
1302 pages = $biblioitem->{'pages'},
1303 notes = $biblioitem->{'notes'},
1304 size = $biblioitem->{'size'},
1305 lccn = $biblioitem->{'lccn'},
1306 marc = $biblioitem->{'marc'},
1307 place = $biblioitem->{'place'}";
1309 $sth = $dbh->prepare($query);
1313 return($bibitemnum);
1317 my ($dbh,$bibnum)=@_;
1318 # my $dbh=C4Connect;
1319 my $query="insert into bibliosubject (biblionumber) values
1321 my $sth=$dbh->prepare($query);
1328 sub OLDnewsubtitle {
1329 my ($dbh,$bibnum, $subtitle) = @_;
1330 # my $dbh = C4Connect;
1331 $subtitle = $dbh->quote($subtitle);
1332 my $query = "insert into bibliosubtitle set
1333 biblionumber = $bibnum,
1334 subtitle = $subtitle";
1335 my $sth = $dbh->prepare($query);
1345 my ($dbh,$item, $barcode) = @_;
1346 # my $dbh = C4Connect;
1347 my $query = "Select max(itemnumber) from items";
1348 my $sth = $dbh->prepare($query);
1354 $data = $sth->fetchrow_hashref;
1355 $itemnumber = $data->{'max(itemnumber)'} + 1;
1358 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
1359 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
1360 $item->{'price'} = $dbh->quote($item->{'price'});
1361 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
1362 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
1364 # foreach my $barcode (@barcodes) {
1365 # $barcode = uc($barcode);
1366 $barcode = $dbh->quote($barcode);
1367 $query = "Insert into items set
1368 itemnumber = $itemnumber,
1369 biblionumber = $item->{'biblionumber'},
1370 biblioitemnumber = $item->{'biblioitemnumber'},
1372 booksellerid = $item->{'booksellerid'},
1373 dateaccessioned = NOW(),
1374 homebranch = $item->{'homebranch'},
1375 holdingbranch = $item->{'homebranch'},
1376 price = $item->{'price'},
1377 replacementprice = $item->{'replacementprice'},
1378 replacementpricedate = NOW(),
1379 itemnotes = $item->{'itemnotes'}";
1380 if ($item->{'loan'}) {
1381 $query .= ",notforloan = $item->{'loan'}";
1384 $sth = $dbh->prepare($query);
1386 if (defined $sth->errstr) {
1387 $error .= $sth->errstr;
1392 return($itemnumber,$error);
1396 my ($dbh,$item) = @_;
1397 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1398 # my $dbh=C4Connect;
1399 my $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1400 barcode='$item->{'barcode'}',itemnotes='$item->{'notes'}'
1401 where itemnumber=$item->{'itemnum'}";
1402 if ($item->{'barcode'} eq ''){
1403 $query="update items set biblioitemnumber=$item->{'bibitemnum'},notforloan=$item->{'loan'} where itemnumber=$item->{'itemnum'}";
1405 if ($item->{'lost'} ne ''){
1406 $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1407 barcode='$item->{'barcode'}',
1408 itemnotes='$item->{'notes'}',
1409 homebranch='$item->{'homebranch'}',
1410 itemlost='$item->{'lost'}',
1411 wthdrawn='$item->{'wthdrawn'}'
1412 where itemnumber=$item->{'itemnum'}";
1414 if ($item->{'replacement'} ne ''){
1415 $query=~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1418 my $sth=$dbh->prepare($query);
1425 my ($dbh,$itemnum)=@_;
1426 # my $dbh=C4Connect;
1427 my $query="select * from items where itemnumber=$itemnum";
1428 my $sth=$dbh->prepare($query);
1430 my @data=$sth->fetchrow_array;
1432 $query="Insert into deleteditems values (";
1433 foreach my $temp (@data){
1434 $query=$query."'$temp',";
1438 $sth=$dbh->prepare($query);
1441 $query = "Delete from items where itemnumber=$itemnum";
1442 $sth=$dbh->prepare($query);
1448 sub OLDdeletebiblioitem {
1449 my ($dbh,$biblioitemnumber) = @_;
1450 # my $dbh = C4Connect;
1451 my $query = "Select * from biblioitems
1452 where biblioitemnumber = $biblioitemnumber";
1453 my $sth = $dbh->prepare($query);
1458 if (@results = $sth->fetchrow_array) {
1459 $query = "Insert into deletedbiblioitems values (";
1460 foreach my $value (@results) {
1461 $value = $dbh->quote($value);
1462 $query .= "$value,";
1465 $query =~ s/\,$/\)/;
1468 $query = "Delete from biblioitems
1469 where biblioitemnumber = $biblioitemnumber";
1473 # Now delete all the items attached to the biblioitem
1474 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1475 $sth = $dbh->prepare($query);
1477 while (@results = $sth->fetchrow_array) {
1478 $query = "Insert into deleteditems values (";
1479 foreach my $value (@results) {
1480 $value = $dbh->quote($value);
1481 $query .= "$value,";
1483 $query =~ s/\,$/\)/;
1487 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1490 } # sub deletebiblioitem
1493 my ($dbh,$biblio)=@_;
1494 # my $dbh=C4Connect;
1495 my $query="select * from biblio where biblionumber=$biblio";
1496 my $sth=$dbh->prepare($query);
1498 if (my @data=$sth->fetchrow_array){
1500 $query="Insert into deletedbiblio values (";
1501 foreach my $temp (@data){
1502 $temp=~ s/\'/\\\'/g;
1503 $query=$query."'$temp',";
1507 $sth=$dbh->prepare($query);
1510 $query = "Delete from biblio where biblionumber=$biblio";
1511 $sth=$dbh->prepare($query);
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 sub getsingleorder {
1557 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1558 where aqorders.ordernumber=?
1559 and biblio.biblionumber=aqorders.biblionumber and
1560 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1561 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1562 my $sth=$dbh->prepare($query);
1563 $sth->execute($ordnum);
1564 my $data=$sth->fetchrow_hashref;
1572 my $dbh = &C4Connect;
1573 my $bibnum=OLDnewbiblio($dbh,$biblio);
1581 my $dbh = C4Connect;
1582 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1584 return($biblionumber);
1588 my ($bibnum, $subtitle) = @_;
1589 my $dbh = C4Connect;
1590 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1596 my ($bibnum, $author) = @_;
1597 my $dbh = C4Connect;
1598 &OLDmodaddauthor($dbh,$bibnum,$author);
1600 } # sub modaddauthor
1604 my ($bibnum, $force, @subject) = @_;
1605 my $dbh = C4Connect;
1606 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1611 my ($biblioitem) = @_;
1612 my $dbh = C4Connect;
1613 &OLDmodbibitem($dbh,$biblioitem);
1614 my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
1615 &MARCmodbiblio($dbh,$biblioitem->{biblionumber},0,$MARCbibitem);
1620 my ($bibitemnum,$note)=@_;
1622 &OLDmodnote($dbh,$bibitemnum,$note);
1627 my ($biblioitem) = @_;
1628 my $dbh = C4Connect;
1629 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1630 # print STDERR "bibitemnum : $bibitemnum\n";
1631 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1632 # print STDERR $MARCbiblio->as_formatted();
1633 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1634 return($bibitemnum);
1640 &OLDnewsubject($dbh,$bibnum);
1645 my ($bibnum, $subtitle) = @_;
1646 my $dbh = C4Connect;
1647 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1652 my ($item, @barcodes) = @_;
1653 my $dbh = C4Connect;
1657 foreach my $barcode (@barcodes) {
1658 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1660 # print STDERR "biblionumber : $item->{biblionumber} / MARCbibid : $MARCbibid / itemnumber : $itemnumber\n";
1661 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1662 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1663 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1664 # print STDERR "MARCmodbiblio called\n";
1672 # my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1674 &OLDmoditem($dbh,$item);
1675 warn "biblionumber : $item->{'biblionumber'} / $item->{'itemnum'}\n";
1676 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1677 warn "before MARCmoditem : $item->{biblionumber}, $item->{'itemnum'}\n";
1678 warn $MARCitem->as_formatted();
1679 # print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
1680 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1681 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1686 my ($count,@barcodes)=@_;
1689 for (my $i=0;$i<$count;$i++){
1690 $barcodes[$i]=uc $barcodes[$i];
1691 my $query="Select * from items where barcode='$barcodes[$i]'";
1692 my $sth=$dbh->prepare($query);
1694 if (my $data=$sth->fetchrow_hashref){
1695 $error.=" Duplicate Barcode: $barcodes[$i]";
1704 my ($bibitemnum)=@_;
1706 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1707 my $sth=$dbh->prepare($query);
1709 my $data=$sth->fetchrow_hashref;
1712 return($data->{'count(*)'});
1718 &OLDdelitem($dbh,$itemnum);
1722 sub deletebiblioitem {
1723 my ($biblioitemnumber) = @_;
1724 my $dbh = C4Connect;
1725 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1727 } # sub deletebiblioitem
1733 &OLDdelbiblio($dbh,$biblio);
1738 my $dbh = C4Connect;
1739 my $query = "select * from itemtypes";
1740 my $sth = $dbh->prepare($query);
1741 # || die "Cannot prepare $query" . $dbh->errstr;
1746 # || die "Cannot execute $query\n" . $sth->errstr;
1747 while (my $data = $sth->fetchrow_hashref) {
1748 $results[$count] = $data;
1754 return($count, @results);
1755 } # sub getitemtypes
1758 my ($biblionumber) = @_;
1759 my $dbh = C4Connect;
1760 my $query = "Select * from biblio where biblionumber = $biblionumber";
1761 my $sth = $dbh->prepare($query);
1762 # || die "Cannot prepare $query\n" . $dbh->errstr;
1767 # || die "Cannot execute $query\n" . $sth->errstr;
1768 while (my $data = $sth->fetchrow_hashref) {
1769 $results[$count] = $data;
1775 return($count, @results);
1779 my ($biblioitemnum) = @_;
1780 my $dbh = C4Connect;
1781 my $query = "Select * from biblioitems where
1782 biblioitemnumber = $biblioitemnum";
1783 my $sth = $dbh->prepare($query);
1789 while (my $data = $sth->fetchrow_hashref) {
1790 $results[$count] = $data;
1796 return($count, @results);
1797 } # sub getbiblioitem
1799 sub getbiblioitembybiblionumber {
1800 my ($biblionumber) = @_;
1801 my $dbh = C4Connect;
1802 my $query = "Select * from biblioitems where biblionumber =
1804 my $sth = $dbh->prepare($query);
1810 while (my $data = $sth->fetchrow_hashref) {
1811 $results[$count] = $data;
1817 return($count, @results);
1820 sub getitemsbybiblioitem {
1821 my ($biblioitemnum) = @_;
1822 my $dbh = C4Connect;
1823 my $query = "Select * from items, biblio where
1824 biblio.biblionumber = items.biblionumber and biblioitemnumber
1826 my $sth = $dbh->prepare($query);
1827 # || die "Cannot prepare $query\n" . $dbh->errstr;
1832 # || die "Cannot execute $query\n" . $sth->errstr;
1833 while (my $data = $sth->fetchrow_hashref) {
1834 $results[$count] = $data;
1840 return($count, @results);
1841 } # sub getitemsbybiblioitem
1845 my $dbh = C4Connect;
1851 $isbn = $dbh->quote($isbn);
1852 $query = "Select biblio.* from biblio, biblioitems where
1853 biblio.biblionumber = biblioitems.biblionumber
1855 $sth = $dbh->prepare($query);
1858 while (my $data = $sth->fetchrow_hashref) {
1859 $results[$count] = $data;
1865 return($count, @results);
1869 # At the moment this is just a straight copy of the subject code. Needs heavy
1870 # modification to work for additional authors, obviously.
1871 # Check for additional author changes
1873 # my $newadditionalauthor='';
1874 # my $additionalauthors;
1875 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
1876 # $additionalauthors->{$newadditionalauthor}=1;
1877 # if ($origadditionalauthors->{$newadditionalauthor}) {
1878 # $additionalauthors->{$newadditionalauthor}=2;
1880 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
1881 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
1883 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
1885 # $subfields->{1}->{'Subfield_Mark'}='a';
1886 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
1889 # foreach $Record_ID (@marcrecords) {
1890 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
1891 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
1895 # my $origadditionalauthor;
1896 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
1897 # if ($additionalauthors->{$origadditionalauthor} == 1) {
1898 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
1899 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
1900 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
1910 # Subroutine to log changes to databases
1911 # Eventually, this subroutine will be used to create a log of all changes made,
1912 # with the possibility of "undo"ing some changes
1914 if ($database eq 'kohadb') {
1920 print STDERR "KOHA: $type $section $item $original $new\n";
1921 } elsif ($database eq 'marc') {
1923 my $Record_ID=shift;
1926 my $subfield_ID=shift;
1929 print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
1933 #------------------------------------------------
1936 #---------------------------------------
1937 # Find a biblio entry, or create a new one if it doesn't exist.
1938 # If a "subtitle" entry is in hash, add it to subtitle table
1939 sub getoraddbiblio {
1943 $biblio, # hash ref to fields
1954 requireDBI($dbh,"getoraddbiblio");
1956 print "<PRE>Looking for biblio </PRE>\n" if $debug;
1957 $sth=$dbh->prepare("select biblionumber
1959 where title=? and author=?
1960 and copyrightdate=? and seriestitle=?");
1962 $biblio->{title}, $biblio->{author},
1963 $biblio->{copyright}, $biblio->{seriestitle} );
1965 ($biblionumber) = $sth->fetchrow;
1966 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
1968 # Doesn't exist. Add new one.
1969 print "<PRE>Adding biblio</PRE>\n" if $debug;
1970 ($biblionumber,$error)=&newbiblio($biblio);
1971 if ( $biblionumber ) {
1972 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
1973 if ( $biblio->{subtitle} ) {
1974 &newsubtitle($biblionumber,$biblio->{subtitle} );
1977 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
1981 return $biblionumber,$error;
1983 } # sub getoraddbiblio
1987 # UNUSEFUL SUBs. Could be deleted, kept only until beta test
1988 # maybe useful for some MARC tricks steve used.
1991 sub OLD_MAYBE_DELETED_newBiblioItem {
1992 my ($env, $biblioitem) = @_;
1994 my $biblionumber=$biblioitem->{'biblionumber'};
1995 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
1996 my $volume=$biblioitem->{'volume'};
1997 my $q_volume=$dbh->quote($volume);
1998 my $number=$biblioitem->{'number'};
1999 my $q_number=$dbh->quote($number);
2000 my $classification=$biblioitem->{'classification'};
2001 my $q_classification=$dbh->quote($classification);
2002 my $itemtype=$biblioitem->{'itemtype'};
2003 my $q_itemtype=$dbh->quote($itemtype);
2004 my $isbn=$biblioitem->{'isbn'};
2005 my $q_isbn=$dbh->quote($isbn);
2006 my $issn=$biblioitem->{'issn'};
2007 my $q_issn=$dbh->quote($issn);
2008 my $dewey=$biblioitem->{'dewey'};
2010 ($dewey == 0) && ($dewey='');
2011 my $subclass=$biblioitem->{'subclass'};
2012 my $q_subclass=$dbh->quote($subclass);
2013 my $publicationyear=$biblioitem->{'publicationyear'};
2014 my $publishercode=$biblioitem->{'publishercode'};
2015 my $q_publishercode=$dbh->quote($publishercode);
2016 my $volumedate=$biblioitem->{'volumedate'};
2017 my $q_volumedate=$dbh->quote($volumedate);
2018 my $illus=$biblioitem->{'illus'};
2019 my $q_illus=$dbh->quote($illus);
2020 my $pages=$biblioitem->{'pages'};
2021 my $q_pages=$dbh->quote($pages);
2022 my $notes=$biblioitem->{'notes'};
2023 my $q_notes=$dbh->quote($notes);
2024 my $size=$biblioitem->{'size'};
2025 my $q_size=$dbh->quote($size);
2026 my $place=$biblioitem->{'place'};
2027 my $q_place=$dbh->quote($place);
2028 my $lccn=$biblioitem->{'lccn'};
2029 my $q_lccn=$dbh->quote($lccn);
2032 # Unless the $env->{'marconly'} flag is set, update the biblioitems table with
2035 unless ($env->{'marconly'}) {
2036 #my $sth=$dbh->prepare("lock tables biblioitems write");
2038 my $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems");
2040 my ($biblioitemnumber) =$sth->fetchrow;
2041 $biblioitemnumber++;
2042 $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)");
2044 #my $sth=$dbh->prepare("unlock tables");
2049 # Should we check if there is already a biblioitem/amrc with the
2050 # same isbn/lccn/issn?
2052 my $sth=$dbh->prepare("select title,unititle,seriestitle,copyrightdate,notes,author from biblio where biblionumber=$biblionumber");
2054 my ($title, $unititle,$seriestitle,$copyrightdate,$biblionotes,$author) = $sth->fetchrow;
2055 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2057 my ($subtitle) = $sth->fetchrow;
2058 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2060 my @additionalauthors;
2061 while (my ($additionalauthor) = $sth->fetchrow) {
2062 push (@additionalauthors, $additionalauthor);
2064 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2067 while (my ($subject) = $sth->fetchrow) {
2068 push (@subjects, $subject);
2073 $sth=$dbh->prepare("insert into Resource_Table (Record_ID) values (0)");
2075 my $Resource_ID=$dbh->{'mysql_insertid'};
2076 my $Record_ID=$Resource_ID;
2077 $sth=$dbh->prepare("update Resource_Table set Record_ID=$Record_ID where Resource_ID=$Resource_ID");
2083 $subfields->{1}->{'Subfield_Mark'}='a';
2084 $subfields->{1}->{'Subfield_Value'}=$title;
2086 $subfields->{2}->{'Subfield_Mark'}='b';
2087 $subfields->{2}->{'Subfield_Value'}=$subtitle;
2090 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2096 $subfields->{1}->{'Subfield_Mark'}='a';
2097 $subfields->{1}->{'Subfield_Value'}=$author;
2099 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2104 $subfields->{1}->{'Subfield_Mark'}='a';
2105 $subfields->{1}->{'Subfield_Value'}=$seriestitle;
2107 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2112 $subfields->{1}->{'Subfield_Mark'}='a';
2113 $subfields->{1}->{'Subfield_Value'}=$biblionotes;
2114 $subfields->{2}->{'Subfield_Mark'}='3';
2115 $subfields->{2}->{'Subfield_Value'}='biblio';
2117 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2119 # Additional Authors
2120 foreach (@additionalauthors) {
2122 (next) unless ($author);
2124 $subfields->{1}->{'Subfield_Mark'}='a';
2125 $subfields->{1}->{'Subfield_Value'}=$author;
2126 $subfields->{2}->{'Subfield_Mark'}='e';
2127 $subfields->{2}->{'Subfield_Value'}='author';
2129 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2133 (next) unless ($illus);
2135 $subfields->{1}->{'Subfield_Mark'}='a';
2136 $subfields->{1}->{'Subfield_Value'}=$illus;
2137 $subfields->{2}->{'Subfield_Mark'}='e';
2138 $subfields->{2}->{'Subfield_Value'}='illustrator';
2140 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2143 foreach (@subjects) {
2145 (next) unless ($subject);
2147 $subfields->{1}->{'Subfield_Mark'}='a';
2148 $subfields->{1}->{'Subfield_Value'}=$subject;
2150 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2157 $subfields->{1}->{'Subfield_Mark'}='a';
2158 $subfields->{1}->{'Subfield_Value'}=$isbn;
2160 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2165 $subfields->{1}->{'Subfield_Mark'}='a';
2166 $subfields->{1}->{'Subfield_Value'}=$lccn;
2168 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2173 $subfields->{1}->{'Subfield_Mark'}='a';
2174 $subfields->{1}->{'Subfield_Value'}=$issn;
2176 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2181 $subfields->{1}->{'Subfield_Mark'}='a';
2182 $subfields->{1}->{'Subfield_Value'}=$dewey;
2184 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2186 # DEWEY subclass and itemtype
2189 $subfields->{1}->{'Subfield_Mark'}='a';
2190 $subfields->{1}->{'Subfield_Value'}=$itemtype;
2191 $subfields->{2}->{'Subfield_Mark'}='b';
2192 $subfields->{2}->{'Subfield_Value'}=$subclass;
2193 $subfields->{3}->{'Subfield_Mark'}='c';
2194 $subfields->{3}->{'Subfield_Value'}=$biblionumber;
2195 $subfields->{4}->{'Subfield_Mark'}='d';
2196 $subfields->{4}->{'Subfield_Value'}=$biblioitemnumber;
2198 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2203 $subfields->{1}->{'Subfield_Mark'}='a';
2204 $subfields->{1}->{'Subfield_Value'}=$place;
2205 $subfields->{2}->{'Subfield_Mark'}='b';
2206 $subfields->{2}->{'Subfield_Value'}=$publishercode;
2207 $subfields->{3}->{'Subfield_Mark'}='c';
2208 $subfields->{3}->{'Subfield_Value'}=$publicationyear;
2209 if ($copyrightdate) {
2210 $subfields->{4}->{'Subfield_Mark'}='c';
2211 $subfields->{4}->{'Subfield_Value'}="c$copyrightdate";
2214 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2217 if ($pages || $size) {
2219 $subfields->{1}->{'Subfield_Mark'}='a';
2220 $subfields->{1}->{'Subfield_Value'}=$pages;
2221 $subfields->{2}->{'Subfield_Mark'}='c';
2222 $subfields->{2}->{'Subfield_Value'}=$size;
2224 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2227 if ($volume || $number) {
2229 $subfields->{1}->{'Subfield_Mark'}='v';
2230 $subfields->{1}->{'Subfield_Value'}=$volume;
2231 $subfields->{2}->{'Subfield_Mark'}='n';
2232 $subfields->{2}->{'Subfield_Value'}=$number;
2234 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2239 $subfields->{1}->{'Subfield_Mark'}='a';
2240 $subfields->{1}->{'Subfield_Value'}=$notes;
2241 $subfields->{2}->{'Subfield_Mark'}='3';
2242 $subfields->{2}->{'Subfield_Value'}='biblioitem';
2244 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2248 return ($env, $Record_ID);
2251 sub OLD_MAYBE_DELETED_newItem {
2252 my ($env, $Record_ID, $item) = @_;
2254 my $barcode=$item->{'barcode'};
2255 my $q_barcode=$dbh->quote($barcode);
2256 my $biblionumber=$item->{'biblionumber'};
2257 my $biblioitemnumber=$item->{'biblioitemnumber'};
2258 my $dateaccessioned=$item->{'dateaccessioned'};
2259 my $booksellerid=$item->{'booksellerid'};
2260 my $q_booksellerid=$dbh->quote($booksellerid);
2261 my $homebranch=$item->{'homebranch'};
2262 my $q_homebranch=$dbh->quote($homebranch);
2263 my $holdingbranch=$item->{'holdingbranch'};
2264 my $price=$item->{'price'};
2265 my $replacementprice=$item->{'replacementprice'};
2266 my $replacementpricedate=$item->{'replacementpricedate'};
2267 my $q_replacementpricedate=$dbh->quote($replacementpricedate);
2268 my $notforloan=$item->{'notforloan'};
2269 my $itemlost=$item->{'itemlost'};
2270 my $wthdrawn=$item->{'wthdrawn'};
2271 my $restricted=$item->{'restricted'};
2272 my $itemnotes=$item->{'itemnotes'};
2273 my $q_itemnotes=$dbh->quote($itemnotes);
2274 my $itemtype=$item->{'itemtype'};
2275 my $subclass=$item->{'subclass'};
2279 unless ($env->{'marconly'}) {
2280 my $sth=$dbh->prepare("select max(itemnumber) from items");
2282 my ($itemnumber) =$sth->fetchrow;
2284 $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)");
2291 $subfields->{1}->{'Subfield_Mark'}='p';
2292 $subfields->{1}->{'Subfield_Value'}=$barcode;
2293 $subfields->{2}->{'Subfield_Mark'}='d';
2294 $subfields->{2}->{'Subfield_Value'}=$dateaccessioned;
2295 $subfields->{3}->{'Subfield_Mark'}='e';
2296 $subfields->{3}->{'Subfield_Value'}=$booksellerid;
2297 $subfields->{4}->{'Subfield_Mark'}='b';
2298 $subfields->{4}->{'Subfield_Value'}=$homebranch;
2299 $subfields->{5}->{'Subfield_Mark'}='l';
2300 $subfields->{5}->{'Subfield_Value'}=$holdingbranch;
2301 $subfields->{6}->{'Subfield_Mark'}='c';
2302 $subfields->{6}->{'Subfield_Value'}=$price;
2303 $subfields->{7}->{'Subfield_Mark'}='c';
2304 $subfields->{7}->{'Subfield_Value'}=$replacementprice;
2305 $subfields->{8}->{'Subfield_Mark'}='d';
2306 $subfields->{8}->{'Subfield_Value'}=$replacementpricedate;
2308 $subfields->{9}->{'Subfield_Mark'}='h';
2309 $subfields->{9}->{'Subfield_Value'}='Not for loan';
2312 $subfields->{10}->{'Subfield_Mark'}='j';
2313 $subfields->{10}->{'Subfield_Value'}='Item lost';
2316 $subfields->{11}->{'Subfield_Mark'}='j';
2317 $subfields->{11}->{'Subfield_Value'}='Item withdrawn';
2320 $subfields->{12}->{'Subfield_Mark'}='z';
2321 $subfields->{12}->{'Subfield_Value'}=$itemnotes;
2325 $env->{'linkage'}=1;
2326 ($env, $Tag_ID) = addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2327 $env->{'linkage'}=0;
2328 $env->{'linkid'}=$Tag_ID;
2331 $subfields2->{1}->{'Subfield_Mark'}='a';
2332 $subfields2->{1}->{'Subfield_Value'}='Coast Mountains School District';
2333 $subfields2->{1}->{'Subfield_Mark'}='b';
2334 $subfields2->{1}->{'Subfield_Value'}=$homebranch;
2335 $subfields2->{1}->{'Subfield_Mark'}='c';
2336 $subfields2->{1}->{'Subfield_Value'}=$itemtype;
2337 $subfields2->{2}->{'Subfield_Mark'}='m';
2338 $subfields2->{2}->{'Subfield_Value'}=$subclass;
2339 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields2);
2340 $env->{'linkid'}='';
2343 sub OLD_MAYBE_DELETED_updateBiblio {
2344 # Update the biblio with biblionumber $biblio->{'biblionumber'}
2345 # I guess this routine should search through all marc records for a record that
2346 # has the same biblionumber stored in it, and modify the MARC record as well as
2349 # Also, this subroutine should search through the $biblio object and compare it
2350 # to the existing record and _LOG ALL CHANGES MADE_ in some way. I'd like for
2351 # this logging feature to be usable to undo changes easily.
2353 my ($env, $biblio) = @_;
2355 my $biblionumber=$biblio->{'biblionumber'};
2357 my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
2359 my $origbiblio=$sth->fetchrow_hashref;
2360 $sth=$dbh->prepare("select subtitle from bibliosubtitle where biblionumber=$biblionumber");
2362 my ($subtitle)=$sth->fetchrow;
2363 $origbiblio->{'subtitle'}=$subtitle;
2364 $sth=$dbh->prepare("select author from additionalauthors where biblionumber=$biblionumber");
2366 my $origadditionalauthors;
2367 while (my ($author) = $sth->fetchrow) {
2368 push (@{$origbiblio->{'additionalauthors'}}, $author);
2369 $origadditionalauthors->{$author}=1;
2371 $sth=$dbh->prepare("select subject from bibliosubject where biblionumber=$biblionumber");
2374 while (my ($subject) = $sth->fetchrow) {
2375 push (@{$origbiblio->{'subjects'}}, $subject);
2376 $origsubjects->{$subject}=1;
2380 # Obtain a list of MARC Record_ID's that are tied to this biblio
2381 $sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
2384 while (my ($bibid) = $sth->fetchrow) {
2385 push(@marcrecords, $bibid);
2389 if ($biblio->{'author'} ne $origbiblio->{'author'}) {
2390 my $q_author=$dbh->quote($biblio->{'author'});
2391 logchange('kohadb', 'change', 'biblio', 'author', $origbiblio->{'author'}, $biblio->{'author'});
2392 my $sti=$dbh->prepare("update biblio set author=$q_author where biblionumber=$biblio->{'biblionumber'}");
2394 foreach $bibid (@marcrecords) {
2395 logchange('marc', 'change', $bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2396 changeSubfield($bibid, '100', 'a', $origbiblio->{'author'}, $biblio->{'author'});
2399 if ($biblio->{'title'} ne $origbiblio->{'title'}) {
2400 my $q_title=$dbh->quote($biblio->{'title'});
2401 logchange('kohadb', 'change', 'biblio', 'title', $origbiblio->{'title'}, $biblio->{'title'});
2402 my $sti=$dbh->prepare("update biblio set title=$q_title where biblionumber=$biblio->{'biblionumber'}");
2404 foreach $Record_ID (@marcrecords) {
2405 logchange('marc', 'change', $Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2406 changeSubfield($Record_ID, '245', 'a', $origbiblio->{'title'}, $biblio->{'title'});
2409 if ($biblio->{'subtitle'} ne $origbiblio->{'subtitle'}) {
2410 my $q_subtitle=$dbh->quote($biblio->{'subtitle'});
2411 logchange('kohadb', 'change', 'biblio', 'subtitle', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2412 my $sti=$dbh->prepare("update bibliosubtitle set subtitle=$q_subtitle where biblionumber=$biblio->{'biblionumber'}");
2414 foreach $Record_ID (@marcrecords) {
2415 logchange('marc', 'change', $Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2416 changeSubfield($Record_ID, '245', 'b', $origbiblio->{'subtitle'}, $biblio->{'subtitle'});
2419 if ($biblio->{'unititle'} ne $origbiblio->{'unititle'}) {
2420 my $q_unititle=$dbh->quote($biblio->{'unititle'});
2421 logchange('kohadb', 'change', 'biblio', 'unititle', $origbiblio->{'unititle'}, $biblio->{'unititle'});
2422 my $sti=$dbh->prepare("update biblio set unititle=$q_unititle where biblionumber=$biblio->{'biblionumber'}");
2425 if ($biblio->{'notes'} ne $origbiblio->{'notes'}) {
2426 my $q_notes=$dbh->quote($biblio->{'notes'});
2427 logchange('kohadb', 'change', 'biblio', 'notes', $origbiblio->{'notes'}, $biblio->{'notes'});
2428 my $sti=$dbh->prepare("update biblio set notes=$q_notes where biblionumber=$biblio->{'biblionumber'}");
2430 foreach $Record_ID (@marcrecords) {
2431 logchange('marc', 'change', $Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2432 changeSubfield($Record_ID, '500', 'a', $origbiblio->{'notes'}, $biblio->{'notes'});
2435 if ($biblio->{'serial'} ne $origbiblio->{'serial'}) {
2436 my $q_serial=$dbh->quote($biblio->{'serial'});
2437 logchange('kohadb', 'change', 'biblio', 'serial', $origbiblio->{'serial'}, $biblio->{'serial'});
2438 my $sti=$dbh->prepare("update biblio set serial=$q_serial where biblionumber=$biblio->{'biblionumber'}");
2441 if ($biblio->{'seriestitle'} ne $origbiblio->{'seriestitle'}) {
2442 my $q_seriestitle=$dbh->quote($biblio->{'seriestitle'});
2443 logchange('kohadb', 'change', 'biblio', 'seriestitle', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2444 my $sti=$dbh->prepare("update biblio set seriestitle=$q_seriestitle where biblionumber=$biblio->{'biblionumber'}");
2446 foreach $Record_ID (@marcrecords) {
2447 logchange('marc', 'change', $Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2448 changeSubfield($Record_ID, '440', 'a', $origbiblio->{'seriestitle'}, $biblio->{'seriestitle'});
2451 if ($biblio->{'copyrightdate'} ne $origbiblio->{'copyrightdate'}) {
2452 my $q_copyrightdate=$dbh->quote($biblio->{'copyrightdate'});
2453 logchange('kohadb', 'change', 'biblio', 'copyrightdate', $origbiblio->{'copyrightdate'}, $biblio->{'copyrightdate'});
2454 my $sti=$dbh->prepare("update biblio set copyrightdate=$q_copyrightdate where biblionumber=$biblio->{'biblionumber'}");
2456 foreach $Record_ID (@marcrecords) {
2457 logchange('marc', 'change', $Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2458 changeSubfield($Record_ID, '260', 'c', "c$origbiblio->{'notes'}", "c$biblio->{'notes'}");
2462 # Check for subject heading changes
2466 foreach $newsubject (@{$biblio->{'subject'}}) {
2467 $subjects->{$newsubject}=1;
2468 if ($origsubjects->{$newsubject}) {
2469 $subjects->{$newsubject}=2;
2471 my $q_newsubject=$dbh->quote($newsubject);
2472 my $sth=$dbh->prepare("insert into bibliosubject (subject,biblionumber) values ($q_newsubject, $biblionumber)");
2474 logchange('kohadb', 'add', 'biblio', 'subject', $newsubject);
2476 $subfields->{1}->{'Subfield_Mark'}='a';
2477 $subfields->{1}->{'Subfield_Value'}=$newsubject;
2480 foreach $Record_ID (@marcrecords) {
2481 addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2482 logchange('marc', 'add', $Record_ID, '650', 'a', $newsubject);
2487 foreach $origsubject (keys %$origsubjects) {
2488 if ($subjects->{$origsubject} == 1) {
2489 my $q_origsubject=$dbh->quote($origsubject);
2490 logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'subject', $origsubject);
2491 my $sth=$dbh->prepare("delete from bibliosubject where biblionumber=$biblionumber and subject=$q_origsubject");
2497 sub OLD_MAYBE_DELETED_updateBiblioItem {
2498 # Update the biblioitem with biblioitemnumber $biblioitem->{'biblioitemnumber'}
2500 # This routine should also check to see which fields are actually being
2501 # modified, and log all changes.
2503 my ($env, $biblioitem) = @_;
2506 my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
2507 my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
2508 # obi = original biblioitem
2509 my $obi=$sth->fetchrow_hashref;
2510 $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");
2512 my ($Record_ID) = $sth->fetchrow;
2513 if ($biblioitem->{'biblionumber'} ne $obi->{'biblionumber'}) {
2514 logchange('kohadb', 'change', 'biblioitems', 'biblionumber', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2515 my $sth=$dbh->prepare("update biblioitems set biblionumber=$biblioitem->{'biblionumber'} where biblioitemnumber=$biblioitemnumber");
2516 logchange('marc', 'change', $Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2517 changeSubfield($Record_ID, '090', 'c', $obi->{'biblionumber'}, $biblioitem->{'biblionumber'});
2519 if ($biblioitem->{'volume'} ne $obi->{'volume'}) {
2520 logchange('kohadb', 'change', 'biblioitems', 'volume', $obi->{'volume'}, $biblioitem->{'volume'});
2521 my $q_volume=$dbh->quote($biblioitem->{'volume'});
2522 my $sth=$dbh->prepare("update biblioitems set volume=$q_volume where biblioitemnumber=$biblioitemnumber");
2523 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2524 changeSubfield($Record_ID, '440', 'v', $obi->{'volume'}, $biblioitem->{'volume'});
2526 if ($biblioitem->{'number'} ne $obi->{'number'}) {
2527 logchange('kohadb', 'change', 'biblioitems', 'number', $obi->{'number'}, $biblioitem->{'number'});
2528 my $q_number=$dbh->quote($biblioitem->{'number'});
2529 my $sth=$dbh->prepare("update biblioitems set number=$q_number where biblioitemnumber=$biblioitemnumber");
2530 logchange('marc', 'change', $Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2531 changeSubfield($Record_ID, '440', 'v', $obi->{'number'}, $biblioitem->{'number'});
2533 if ($biblioitem->{'itemtype'} ne $obi->{'itemtype'}) {
2534 logchange('kohadb', 'change', 'biblioitems', 'itemtype', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2535 my $q_itemtype=$dbh->quote($biblioitem->{'itemtype'});
2536 my $sth=$dbh->prepare("update biblioitems set itemtype=$q_itemtype where biblioitemnumber=$biblioitemnumber");
2537 logchange('marc', 'change', $Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2538 changeSubfield($Record_ID, '090', 'a', $obi->{'itemtype'}, $biblioitem->{'itemtype'});
2540 if ($biblioitem->{'isbn'} ne $obi->{'isbn'}) {
2541 logchange('kohadb', 'change', 'biblioitems', 'isbn', $obi->{'isbn'}, $biblioitem->{'isbn'});
2542 my $q_isbn=$dbh->quote($biblioitem->{'isbn'});
2543 my $sth=$dbh->prepare("update biblioitems set isbn=$q_isbn where biblioitemnumber=$biblioitemnumber");
2544 logchange('marc', 'change', $Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2545 changeSubfield($Record_ID, '020', 'a', $obi->{'isbn'}, $biblioitem->{'isbn'});
2547 if ($biblioitem->{'issn'} ne $obi->{'issn'}) {
2548 logchange('kohadb', 'change', 'biblioitems', 'issn', $obi->{'issn'}, $biblioitem->{'issn'});
2549 my $q_issn=$dbh->quote($biblioitem->{'issn'});
2550 my $sth=$dbh->prepare("update biblioitems set issn=$q_issn where biblioitemnumber=$biblioitemnumber");
2551 logchange('marc', 'change', $Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2552 changeSubfield($Record_ID, '022', 'a', $obi->{'issn'}, $biblioitem->{'issn'});
2554 if ($biblioitem->{'dewey'} ne $obi->{'dewey'}) {
2555 logchange('kohadb', 'change', 'biblioitems', 'dewey', $obi->{'dewey'}, $biblioitem->{'dewey'});
2556 my $sth=$dbh->prepare("update biblioitems set dewey=$biblioitem->{'dewey'} where biblioitemnumber=$biblioitemnumber");
2557 logchange('marc', 'change', $Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2558 changeSubfield($Record_ID, '082', 'a', $obi->{'dewey'}, $biblioitem->{'dewey'});
2560 if ($biblioitem->{'subclass'} ne $obi->{'subclass'}) {
2561 logchange('kohadb', 'change', 'biblioitems', 'subclass', $obi->{'subclass'}, $biblioitem->{'subclass'});
2562 my $q_subclass=$dbh->quote($biblioitem->{'subclass'});
2563 my $sth=$dbh->prepare("update biblioitems set subclass=$q_subclass where biblioitemnumber=$biblioitemnumber");
2564 logchange('marc', 'change', $Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2565 changeSubfield($Record_ID, '090', 'b', $obi->{'subclass'}, $biblioitem->{'subclass'});
2567 if ($biblioitem->{'place'} ne $obi->{'place'}) {
2568 logchange('kohadb', 'change', 'biblioitems', 'place', $obi->{'place'}, $biblioitem->{'place'});
2569 my $q_place=$dbh->quote($biblioitem->{'place'});
2570 my $sth=$dbh->prepare("update biblioitems set place=$q_place where biblioitemnumber=$biblioitemnumber");
2571 logchange('marc', 'change', $Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2572 changeSubfield($Record_ID, '260', 'a', $obi->{'place'}, $biblioitem->{'place'});
2574 if ($biblioitem->{'publishercode'} ne $obi->{'publishercode'}) {
2575 logchange('kohadb', 'change', 'biblioitems', 'publishercode', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2576 my $q_publishercode=$dbh->quote($biblioitem->{'publishercode'});
2577 my $sth=$dbh->prepare("update biblioitems set publishercode=$q_publishercode where biblioitemnumber=$biblioitemnumber");
2578 logchange('marc', 'change', $Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2579 changeSubfield($Record_ID, '260', 'b', $obi->{'publishercode'}, $biblioitem->{'publishercode'});
2581 if ($biblioitem->{'publicationyear'} ne $obi->{'publicationyear'}) {
2582 logchange('kohadb', 'change', 'biblioitems', 'publicationyear', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2583 my $q_publicationyear=$dbh->quote($biblioitem->{'publicationyear'});
2584 my $sth=$dbh->prepare("update biblioitems set publicationyear=$q_publicationyear where biblioitemnumber=$biblioitemnumber");
2585 logchange('marc', 'change', $Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2586 changeSubfield($Record_ID, '260', 'c', $obi->{'publicationyear'}, $biblioitem->{'publicationyear'});
2588 if ($biblioitem->{'illus'} ne $obi->{'illus'}) {
2589 logchange('kohadb', 'change', 'biblioitems', 'illus', $obi->{'illus'}, $biblioitem->{'illus'});
2590 my $q_illus=$dbh->quote($biblioitem->{'illus'});
2591 my $sth=$dbh->prepare("update biblioitems set illus=$q_illus where biblioitemnumber=$biblioitemnumber");
2592 logchange('marc', 'change', $Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2593 changeSubfield($Record_ID, '700', 'a', $obi->{'illus'}, $biblioitem->{'illus'});
2595 if ($biblioitem->{'pages'} ne $obi->{'pages'}) {
2596 logchange('kohadb', 'change', 'biblioitems', 'pages', $obi->{'pages'}, $biblioitem->{'pages'});
2597 my $q_pages=$dbh->quote($biblioitem->{'pages'});
2598 my $sth=$dbh->prepare("update biblioitems set pages=$q_pages where biblioitemnumber=$biblioitemnumber");
2599 logchange('marc', 'change', $Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2600 changeSubfield($Record_ID, '300', 'a', $obi->{'pages'}, $biblioitem->{'pages'});
2602 if ($biblioitem->{'size'} ne $obi->{'size'}) {
2603 logchange('kohadb', 'change', 'biblioitems', 'size', $obi->{'size'}, $biblioitem->{'size'});
2604 my $q_size=$dbh->quote($biblioitem->{'size'});
2605 my $sth=$dbh->prepare("update biblioitems set size=$q_size where biblioitemnumber=$biblioitemnumber");
2606 logchange('marc', 'change', $Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2607 changeSubfield($Record_ID, '300', 'c', $obi->{'size'}, $biblioitem->{'size'});
2609 if ($biblioitem->{'notes'} ne $obi->{'notes'}) {
2610 logchange('kohadb', 'change', 'biblioitems', 'notes', $obi->{'notes'}, $biblioitem->{'notes'});
2611 my $q_notes=$dbh->quote($biblioitem->{'notes'});
2612 my $sth=$dbh->prepare("update biblioitems set notes=$q_notes where biblioitemnumber=$biblioitemnumber");
2613 logchange('marc', 'change', $Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2614 changeSubfield($Record_ID, '500', 'a', $obi->{'notes'}, $biblioitem->{'notes'});
2616 if ($biblioitem->{'lccn'} ne $obi->{'lccn'}) {
2617 logchange('kohadb', 'change', 'biblioitems', 'lccn', $obi->{'lccn'}, $biblioitem->{'lccn'});
2618 my $q_lccn=$dbh->quote($biblioitem->{'lccn'});
2619 my $sth=$dbh->prepare("update biblioitems set lccn=$q_lccn where biblioitemnumber=$biblioitemnumber");
2620 logchange('marc', 'change', $Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2621 changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
2628 sub OLD_MAYBE_DELETED_updateItem {
2629 # Update the item with itemnumber $item->{'itemnumber'}
2630 # This routine should also modify the corresponding MARC record data. (852 and
2631 # 876 tags with 876p tag the same as $item->{'barcode'}
2633 # This routine should also check to see which fields are actually being
2634 # modified, and log all changes.
2636 my ($env, $item) = @_;
2638 my $itemnumber=$item->{'itemnumber'};
2639 my $biblionumber=$item->{'biblionumber'};
2640 my $biblioitemnumber=$item->{'biblioitemnumber'};
2641 my $barcode=$item->{'barcode'};
2642 my $dateaccessioned=$item->{'dateaccessioned'};
2643 my $booksellerid=$item->{'booksellerid'};
2644 my $homebranch=$item->{'homebranch'};
2645 my $price=$item->{'price'};
2646 my $replacementprice=$item->{'replacementprice'};
2647 my $replacementpricedate=$item->{'replacementpricedate'};
2648 my $multivolume=$item->{'multivolume'};
2649 my $stack=$item->{'stack'};
2650 my $notforloan=$item->{'notforloan'};
2651 my $itemlost=$item->{'itemlost'};
2652 my $wthdrawn=$item->{'wthdrawn'};
2653 my $bulk=$item->{'bulk'};
2654 my $restricted=$item->{'restricted'};
2655 my $binding=$item->{'binding'};
2656 my $itemnotes=$item->{'itemnotes'};
2657 my $holdingbranch=$item->{'holdingbranch'};
2658 my $interim=$item->{'interim'};
2659 my $sth=$dbh->prepare("select * from items where itemnumber=$itemnumber");
2661 my $olditem=$sth->fetchrow_hashref;
2662 my $q_barcode=$dbh->quote($olditem->{'barcode'});
2663 $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");
2665 my ($Subfield876_ID, $Record_ID) = $sth->fetchrow;
2666 $sth=$dbh->prepare("select Subfield_Value from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_ID=$Subfield876_ID");
2668 my ($link) = $sth->fetchrow;
2669 $sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
2671 my ($Subfield852_ID) = $sth->fetchrow;
2673 if ($item->{'barcode'} ne $olditem->{'barcode'}) {
2674 logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
2675 my $q_barcode=$dbh->quote($item->{'barcode'});
2676 my $sth=$dbh->prepare("update items set barcode=$q_barcode where itemnumber=$itemnumber");
2678 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'p', $olditem->{'barcode'}, $item->{'barcode'}, $Subfield876_ID);
2679 logchange('marc', 'change', $Record_ID, '876', 'p', $Subfield_Key, $olditem->{'barcode'}, $item->{'barcode'});
2681 if ($item->{'booksellerid'} ne $olditem->{'booksellerid'}) {
2682 logchange('kohadb', 'change', 'items', 'booksellerid', $olditem->{'booksellerid'}, $item->{'booksellerid'});
2683 my $q_booksellerid=$dbh->quote($item->{'booksellerid'});
2684 my $sth=$dbh->prepare("update items set booksellerid=$q_booksellerid where itemnumber=$itemnumber");
2686 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'e', $olditem->{'booksellerid'}, $item->{'booksellerid'}, $Subfield876_ID);
2687 logchange('marc', 'change', $Record_ID, '876', 'e', $Subfield_Key, $olditem->{'booksellerid'}, $item->{'booksellerid'});
2689 if ($item->{'dateaccessioned'} ne $olditem->{'dateaccessioned'}) {
2690 logchange('kohadb', 'change', 'items', 'dateaccessioned', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2691 my $q_dateaccessioned=$dbh->quote($item->{'dateaccessioned'});
2692 my $sth=$dbh->prepare("update items set dateaccessioned=$q_dateaccessioned where itemnumber=$itemnumber");
2694 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'd', $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'}, $Subfield876_ID);
2695 logchange('marc', 'change', $Record_ID, '876', 'd', $Subfield_Key, $olditem->{'dateaccessioned'}, $item->{'dateaccessioned'});
2697 if ($item->{'homebranch'} ne $olditem->{'homebranch'}) {
2698 logchange('kohadb', 'change', 'items', 'homebranch', $olditem->{'homebranch'}, $item->{'homebranch'});
2699 my $q_homebranch=$dbh->quote($item->{'homebranch'});
2700 my $sth=$dbh->prepare("update items set homebranch=$q_homebranch where itemnumber=$itemnumber");
2702 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'b', $olditem->{'homebranch'}, $item->{'homebranch'}, $Subfield876_ID);
2703 logchange('marc', 'change', $Record_ID, '876', 'b', $Subfield_Key, $olditem->{'homebranch'}, $item->{'homebranch'});
2705 if ($item->{'holdingbranch'} ne $olditem->{'holdingbranch'}) {
2706 logchange('kohadb', 'change', 'items', 'holdingbranch', $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2707 my $q_holdingbranch=$dbh->quote($item->{'holdingbranch'});
2708 my $sth=$dbh->prepare("update items set holdingbranch=$q_holdingbranch where itemnumber=$itemnumber");
2710 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'l', $olditem->{'holdingbranch'}, $item->{'holdingbranch'}, $Subfield876_ID);
2711 logchange('marc', 'change', $Record_ID, '876', 'l', $Subfield_Key, $olditem->{'holdingbranch'}, $item->{'holdingbranch'});
2713 if ($item->{'price'} ne $olditem->{'price'}) {
2714 logchange('kohadb', 'change', 'items', 'price', $olditem->{'price'}, $item->{'price'});
2715 my $q_price=$dbh->quote($item->{'price'});
2716 my $sth=$dbh->prepare("update items set price=$q_price where itemnumber=$itemnumber");
2718 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'price'}, $item->{'price'}, $Subfield876_ID);
2719 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'price'}, $item->{'price'});
2721 if ($item->{'itemnotes'} ne $olditem->{'itemnotes'}) {
2722 logchange('kohadb', 'change', 'items', 'itemnotes', $olditem->{'itemnotes'}, $item->{'itemnotes'});
2723 my $q_itemnotes=$dbh->quote($item->{'itemnotes'});
2724 my $sth=$dbh->prepare("update items set itemnotes=$q_itemnotes where itemnumber=$itemnumber");
2726 my ($Subfield_ID, $Subfield_Key) = changeSubfield($Record_ID, '876', 'c', $olditem->{'itemnotes'}, $item->{'itemnotes'}, $Subfield876_ID);
2727 logchange('marc', 'change', $Record_ID, '876', 'c', $Subfield_Key, $olditem->{'itemnotes'}, $item->{'itemnotes'});
2729 if ($item->{'notforloan'} ne $olditem->{'notforloan'}) {
2730 logchange('kohadb', 'change', 'items', 'notforloan', $olditem->{'notforloan'}, $item->{'notforloan'});
2731 my $sth=$dbh->prepare("update items set notforloan=$notforloan where itemnumber=$itemnumber");
2733 if ($item->{'notforloan'}) {
2734 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2735 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2737 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Not for loan', $Subfield876_ID);
2738 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Not for loan');
2741 if ($item->{'itemlost'} ne $olditem->{'itemlost'}) {
2742 logchange('kohadb', 'change', 'items', 'itemlost', $olditem->{'itemlost'}, $item->{'itemlost'});
2743 my $sth=$dbh->prepare("update items set itemlost=$itemlost where itemnumber=$itemnumber");
2745 if ($item->{'itemlost'}) {
2746 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2747 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2749 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Item lost', $Subfield876_ID);
2750 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Item lost');
2753 if ($item->{'wthdrawn'} ne $olditem->{'wthdrawn'}) {
2754 logchange('kohadb', 'change', 'items', 'wthdrawn', $olditem->{'wthdrawn'}, $item->{'wthdrawn'});
2755 my $sth=$dbh->prepare("update items set wthdrawn=$wthdrawn where itemnumber=$itemnumber");
2757 if ($item->{'wthdrawn'}) {
2758 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2759 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2761 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Withdrawn', $Subfield876_ID);
2762 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Withdrawn');
2765 if ($item->{'restricted'} ne $olditem->{'restricted'}) {
2766 logchange('kohadb', 'change', 'items', 'restricted', $olditem->{'restricted'}, $item->{'restricted'});
2767 my $sth=$dbh->prepare("update items set restricted=$restricted where itemnumber=$itemnumber");
2769 if ($item->{'restricted'}) {
2770 my ($Subfield_ID, $Subfield_Key) = addSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2771 logchange('marc', 'add', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2773 my ($Subfield_ID, $Subfield_Key) = deleteSubfield($Record_ID, '876', 'h', 'Restricted', $Subfield876_ID);
2774 logchange('marc', 'delete', $Record_ID, '876', 'h', $Subfield_Key, 'Restricted');
2781 # Add a biblioitem and related data to Koha database
2782 sub OLD_MAY_BE_DELETED_newcompletebiblioitem {
2787 $biblio, # hash ref to biblio record
2788 $biblioitem, # hash ref to biblioitem record
2789 $subjects, # list ref of subjects
2790 $addlauthors, # list ref of additional authors
2793 my ( $biblionumber, $biblioitemnumber, $error); # return values
2798 my $additionalauthor;
2801 requireDBI($dbh,"newcompletebiblioitem");
2803 print "<PRE>Trying to add biblio item Title=$biblio->{title} " .
2804 "ISBN=$biblioitem->{isbn} </PRE>\n" if $debug;
2806 # Make sure master biblio entry exists
2807 ($biblionumber,$error)=getoraddbiblio($dbh, $biblio);
2811 $biblioitem->{biblionumber}=$biblionumber;
2814 $biblioitemnumber=newbiblioitem($biblioitem);
2817 $sth=$dbh->prepare("insert into bibliosubject
2818 (biblionumber,subject)
2820 foreach $subjectheading (@{$subjects} ) {
2821 $sth->execute($biblionumber, $subjectheading)
2822 or $error.=$sth->errstr ;
2826 # Add additional authors
2827 $sth=$dbh->prepare("insert into additionalauthors
2828 (biblionumber,author)
2830 foreach $additionalauthor (@{$addlauthors} ) {
2831 $sth->execute($biblionumber, $additionalauthor)
2832 or $error.=$sth->errstr ;
2836 # couldn't get biblio
2838 $biblioitemnumber='';
2840 } # if no biblio error
2842 return ( $biblionumber, $biblioitemnumber, $error);
2844 } # sub newcompletebiblioitem
2848 # END OF UNUSEFUL SUBs
2852 END { } # module clean-up code here (global destructor)