4 # Revision 1.30 2002/12/12 21:26:35 tipaul
5 # YAB ! (Yet Another Bugfix) => related to biblio modif
6 # (some warning cleaning too)
8 # Revision 1.29 2002/12/12 16:35:00 tipaul
9 # adding authentification with Auth.pm and
10 # MAJOR BUGFIX on marc biblio modification
12 # Revision 1.28 2002/12/10 13:30:03 tipaul
13 # fugfixes from Dombes Abbey work
15 # Revision 1.27 2002/11/19 12:36:16 tipaul
17 # various bugfixes, improvments, and migration from acquisition.pm to biblio.pm
19 # Revision 1.26 2002/11/12 15:58:43 tipaul
22 # * adding value_builder : you can map a subfield in the marc_subfield_structure to a sub stored in "value_builder" directory. In this directory you can create screen used to build values with any method. In this commit is a 1st draft of the builder for 100$a unimarc french subfield, which is composed of 35 digits, with 12 differents values (only the 4th first are provided for instance)
24 # Revision 1.25 2002/10/25 10:58:26 tipaul
26 # * bugfixes and improvements
28 # Revision 1.24 2002/10/24 12:09:01 arensb
29 # Fixed "no title" warning when generating HTML documentation from POD.
31 # Revision 1.23 2002/10/16 12:43:08 arensb
32 # Added some FIXME comments.
34 # Revision 1.22 2002/10/15 13:39:17 tipaul
35 # removing Acquisition.pm
36 # deleting unused code in biblio.pm, rewriting POD and answering most FIXME comments
38 # Revision 1.21 2002/10/13 11:34:14 arensb
39 # Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
40 # Thus, $x = $x+2 becomes $x += 2, and so forth.
42 # Revision 1.20 2002/10/13 08:28:32 arensb
43 # Deleted unused variables.
44 # Removed trailing whitespace.
46 # Revision 1.19 2002/10/13 05:56:10 arensb
47 # Added some FIXME comments.
49 # Revision 1.18 2002/10/11 12:34:53 arensb
50 # Replaced &requireDBI with C4::Context->dbh
52 # Revision 1.17 2002/10/10 14:48:25 tipaul
55 # Revision 1.16 2002/10/07 14:04:26 tipaul
56 # road to 1.3.1 : viewing MARC biblio
58 # Revision 1.15 2002/10/05 09:49:25 arensb
59 # Merged with arensb-context branch: use C4::Context->dbh instead of
60 # &C4Connect, and generally prefer C4::Context over C4::Database.
62 # Revision 1.14 2002/10/03 11:28:18 tipaul
63 # Extending Context.pm to add stopword management and using it in MARC-API.
64 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
66 # Revision 1.13 2002/10/02 16:26:44 tipaul
69 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
70 # Merged in changes from main branch.
72 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
73 # Added a whole mess of FIXME comments.
75 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
76 # Added some missing semicolons.
78 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
79 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
82 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
83 # Added a whole mess of FIXME comments.
85 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
86 # Added some missing semicolons.
88 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
89 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
92 # Revision 1.12 2002/10/01 11:48:51 arensb
93 # Added some FIXME comments, mostly marking duplicate functions.
95 # Revision 1.11 2002/09/24 13:49:26 tipaul
96 # long WAS the road to 1.3.0...
97 # coming VERY SOON NOW...
98 # modifying installer and buildrelease to update the DB
100 # Revision 1.10 2002/09/22 16:50:08 arensb
101 # Added some FIXME comments.
103 # Revision 1.9 2002/09/20 12:57:46 tipaul
104 # long is the road to 1.4.0
105 # * MARCadditem and MARCmoditem now wroks
106 # * various bugfixes in MARC management
107 # !!! 1.3.0 should be released very soon now. Be careful !!!
109 # Revision 1.8 2002/09/10 13:53:52 tipaul
110 # MARC API continued...
112 # * 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)
114 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
116 # Revision 1.7 2002/08/14 18:12:51 tonnesen
117 # Added copyright statement to all .pl and .pm files
119 # Revision 1.6 2002/07/25 13:40:31 tipaul
120 # pod documenting the API.
122 # Revision 1.5 2002/07/24 16:11:37 tipaul
124 # Database.pm and Output.pm are almost not modified (var test...)
126 # Biblio.pm is almost completly rewritten.
128 # WHAT DOES IT ??? ==> END of Hitchcock suspens
130 # 1st, it does... nothing...
131 # 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 ...
133 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
134 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
135 # * 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.
136 # * 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.
137 # 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 "NEWxxx" : 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 ;-)
139 # 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.
140 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
144 # Copyright 2000-2002 Katipo Communications
146 # This file is part of Koha.
148 # Koha is free software; you can redistribute it and/or modify it under the
149 # terms of the GNU General Public License as published by the Free Software
150 # Foundation; either version 2 of the License, or (at your option) any later
153 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
154 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
155 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
157 # You should have received a copy of the GNU General Public License along with
158 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
159 # Suite 330, Boston, MA 02111-1307 USA
167 use vars qw($VERSION @ISA @EXPORT);
169 # set the version for version checking
174 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
175 # as the old-style API and the NEW one are the only public functions.
178 &updateBiblio &updateBiblioItem &updateItem
179 &itemcount &newbiblio &newbiblioitem
180 &modnote &newsubject &newsubtitle
181 &modbiblio &checkitems
182 &newitems &modbibitem
183 &modsubtitle &modsubject &modaddauthor &moditem &countitems
184 &delitem &deletebiblioitem &delbiblio
185 &getitemtypes &getbiblio
186 &getbiblioitembybiblionumber
187 &getbiblioitem &getitemsbybiblioitem &isbnsearch
189 &newcompletebiblioitem
191 &MARCfind_oldbiblionumber_from_MARCbibid
192 &MARCfind_MARCbibid_from_oldbiblionumber
193 &MARCfind_marc_from_kohafield
197 &NEWnewbiblio &NEWnewitem
198 &NEWmodbiblio &NEWmoditem
200 &MARCaddbiblio &MARCadditem
201 &MARCmodsubfield &MARCaddsubfield
202 &MARCmodbiblio &MARCmoditem
203 &MARCkoha2marcBiblio &MARCmarc2koha
204 &MARCkoha2marcItem &MARChtml2marc
205 &MARCgetbiblio &MARCgetitem
206 &MARCaddword &MARCdelword
211 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
214 # all the following subs takes a MARC::Record as parameter and manage
215 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
216 # NEWxxx subs (xxx deals with old-DB parameters, the NEWxxx deals with MARC-DB parameter)
220 C4::Biblio - acquisition, catalog management functions
224 move from 1.2 to 1.4 version :
225 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
226 In the 1.4 version, we want to do 2 differents things :
227 - keep populating the old-DB, that has a LOT less datas than MARC
228 - populate the MARC-DB
229 To populate the DBs we have 2 differents sources :
230 - the standard acquisition system (through book sellers), that does'nt use MARC data
231 - the MARC acquisition system, that uses MARC data.
233 Thus, we have 2 differents cases :
234 - 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
235 - 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. we MUST have an API for true MARC data, that populate MARC-DB then old-DB
237 That's why we need 4 subs :
238 all I<subs beginning by MARC> manage only MARC tables. They manage MARC-DB with MARC::Record parameters
239 all I<subs beginning by OLD> manage only OLD-DB tables. They manage old-DB with old-DB parameters
240 all I<subs beginning by NEW> 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
241 all I<subs beginning by seomething else> are the old-style API. They use old-DB as parameter, then call internally the OLD and MARC subs.
243 - NEW and old-style API should be used in koha to manage biblio
244 - MARCsubs are divided in 2 parts :
245 * some of them manage MARC parameters. They are heavily used in koha.
246 * some of them manage MARC biblio : they are mostly used by NEW and old-style subs.
247 - OLD are used internally only
249 all subs requires/use $dbh as 1st parameter.
251 I<NEWxxx related subs>
253 all subs requires/use $dbh as 1st parameter.
254 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
256 I<OLDxxx related subs>
258 all subs requires/use $dbh as 1st parameter.
259 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
261 They all are the exact copy of 1.0/1.2 version of the sub without the OLD.
262 The OLDxxx is called by the original xxx sub.
263 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
265 WARNING : there is 1 difference between initialxxx and OLDxxx :
266 the db header $dbh is always passed as parameter to avoid over-DB connexion
272 =item @tagslib = &MARCgettagslib($dbh,1|0);
274 last param is 1 for liblibrarian and 0 for libopac
275 returns a hash with tag/subfield meaning
276 =item ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,$kohafield);
278 finds MARC tag and subfield for a given kohafield
279 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
281 =item $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
283 finds a old-db biblio number for a given MARCbibid number
285 =item $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
287 finds a MARC bibid from a old-db biblionumber
289 =item $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
291 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
293 =item $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
295 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
297 =item $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
299 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
301 =item $olddb = &MARCmarc2koha($dbh,$MARCRecord);
303 builds a hash with old-db datas from a MARC::Record
305 =item &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
307 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
309 =item &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
311 adds a subfield in a biblio (in the MARC tables only).
313 =item $MARCRecord = &MARCgetbiblio($dbh,$bibid);
315 Returns a MARC::Record for the biblio $bibid.
317 =item &MARCmodbiblio($dbh,$bibid,$delete,$record);
319 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
320 if $delete == 1, every field/subfield not found is deleted in the biblio
321 otherwise, only data passed to MARCmodbiblio is managed.
322 thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
324 =item ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
326 MARCmodsubfield changes the value of a given subfield
328 =item $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
330 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
331 Returns -1 if more than 1 answer
333 =item $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
335 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
337 =item &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
339 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
341 =item &MARCdelbiblio($dbh,$bibid);
343 MARCdelbiblio delete biblio $bibid
345 =item &MARCkoha2marcOnefield
347 used by MARCkoha2marc and should not be useful elsewhere
349 =item &MARCmarc2kohaOnefield
351 used by MARCmarc2koha and should not be useful elsewhere
355 used to manage MARC_word table and should not be useful elsewhere
359 used to manage MARC_word table and should not be useful elsewhere
364 my ($dbh,$forlibrarian)= @_;
366 if ($forlibrarian eq 1) {
367 $sth=$dbh->prepare("select tagfield,liblibrarian as lib from marc_tag_structure order by tagfield");
369 $sth=$dbh->prepare("select tagfield,libopac as lib from marc_tag_structure order by tagfield");
372 my ($lib,$tag,$res,$tab,$mandatory,$repeatable);
373 while ( ($tag,$lib,$tab) = $sth->fetchrow) {
374 $res->{$tag}->{lib}=$lib;
375 $res->{$tab}->{tab}="";
378 if ($forlibrarian eq 1) {
379 $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder from marc_subfield_structure order by tagfield,tagsubfield");
381 $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder from marc_subfield_structure order by tagfield,tagsubfield");
386 my $authorised_value;
387 my $thesaurus_category;
389 while ( ($tag, $subfield, $lib, $tab, $mandatory, $repeatable,$authorised_value,$thesaurus_category,$value_builder) = $sth->fetchrow) {
390 $res->{$tag}->{$subfield}->{lib}=$lib;
391 $res->{$tag}->{$subfield}->{tab}=$tab;
392 $res->{$tag}->{$subfield}->{mandatory}=$mandatory;
393 $res->{$tag}->{$subfield}->{repeatable}=$repeatable;
394 $res->{$tag}->{$subfield}->{authorised_value}=$authorised_value;
395 $res->{$tag}->{$subfield}->{thesaurus_category}=$thesaurus_category;
396 $res->{$tag}->{$subfield}->{value_builder}=$value_builder;
401 sub MARCfind_marc_from_kohafield {
402 my ($dbh,$kohafield) = @_;
403 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
404 $sth->execute($kohafield);
405 my ($tagfield,$tagsubfield) = $sth->fetchrow;
406 return ($tagfield,$tagsubfield);
409 sub MARCfind_oldbiblionumber_from_MARCbibid {
410 my ($dbh,$MARCbibid) = @_;
411 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
412 $sth->execute($MARCbibid);
413 my ($biblionumber) = $sth->fetchrow;
414 return $biblionumber;
417 sub MARCfind_MARCbibid_from_oldbiblionumber {
418 my ($dbh,$oldbiblionumber) = @_;
419 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
420 $sth->execute($oldbiblionumber);
421 my ($bibid) = $sth->fetchrow;
426 # pass the MARC::Record to this function, and it will create the records in the marc tables
427 my ($dbh,$record,$biblionumber) = @_;
428 my @fields=$record->fields();
430 # adding main table, and retrieving bibid
431 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
432 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
433 $sth->execute($biblionumber);
434 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
436 ($bibid)=$sth->fetchrow;
439 # now, add subfields...
440 foreach my $field (@fields) {
441 my @subfields=$field->subfields();
443 foreach my $subfieldcount (0..$#subfields) {
444 &MARCaddsubfield($dbh,$bibid,
446 $field->indicator(1).$field->indicator(2),
448 $subfields[$subfieldcount][0],
450 $subfields[$subfieldcount][1]
454 $dbh->do("unlock tables");
459 # pass the MARC::Record to this function, and it will create the records in the marc tables
460 my ($dbh,$record,$biblionumber) = @_;
461 # warn "adding : ".$record->as_formatted();
462 # search for MARC biblionumber
463 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
464 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
465 my @fields=$record->fields();
466 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
467 $sth->execute($bibid);
468 my ($fieldcount) = $sth->fetchrow;
469 # now, add subfields...
470 foreach my $field (@fields) {
471 my @subfields=$field->subfields();
473 foreach my $subfieldcount (0..$#subfields) {
474 &MARCaddsubfield($dbh,$bibid,
476 $field->indicator(1).$field->indicator(2),
478 $subfields[$subfieldcount][0],
480 $subfields[$subfieldcount][1]
482 # warn "ADDING :$bibid,".
484 $field->indicator(1).$field->indicator(2).",
486 $subfields[$subfieldcount][0],
488 $subfields[$subfieldcount][1]";
491 $dbh->do("unlock tables");
495 sub MARCaddsubfield {
496 # Add a new subfield to a tag into the DB.
497 my ($dbh,$bibid,$tagid,$tag_indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
498 # if not value, end of job, we do nothing
499 if (length($subfieldvalue) ==0) {
502 if (not($subfieldcode)) {
505 if (length($subfieldvalue)>255) {
506 # $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
507 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
508 $sth->execute($subfieldvalue);
509 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
511 my ($res)=$sth->fetchrow;
512 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?,?)");
514 $sth->execute($bibid,'0'.$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$res);
516 $sth->execute($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$res);
519 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
521 # $dbh->do("unlock tables");
523 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)");
524 $sth->execute($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue);
526 print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
529 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
533 # Returns MARC::Record of the biblio passed in parameter.
535 my $record = MARC::Record->new();
536 #---- TODO : the leader is missing
537 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
538 from marc_subfield_table
539 where bibid=? order by tag,tagorder,subfieldcode
541 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
542 $sth->execute($bibid);
547 while (my $row=$sth->fetchrow_hashref) {
548 if ($row->{'valuebloblink'}) { #---- search blob if there is one
549 $sth2->execute($row->{'valuebloblink'});
550 my $row2=$sth2->fetchrow_hashref;
552 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
554 # warn "$row->{bibid} = $row->{tag} - $row->{subfieldcode} -> value : $row->{subfieldvalue}";
555 if ($row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag) {
556 if (length($prevtag) <3) {
557 $prevtag = "0".$prevtag;
560 # warn "NEW : subfieldcode : $prevtag";
561 my $field = MARC::Field->new( $prevtag, substr($previndicator,0,1), substr($previndicator,1,1), %subfieldlist);
562 # warn $field->as_formatted();
563 $record->add_fields($field);
564 $prevtagorder=$row->{tagorder};
565 $prevtag = $row->{tag};
566 $previndicator=$row->{tag_indicator};
568 %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
570 # warn "subfieldcode : $row->{'subfieldcode'} / value : $row->{'subfieldvalue'}, tag : $row->{tag}";
571 if (%subfieldlist->{$row->{'subfieldcode'}}) {
572 %subfieldlist->{$row->{'subfieldcode'}}.='|';
574 %subfieldlist->{$row->{'subfieldcode'}} .= $row->{'subfieldvalue'};
575 $prevtag= $row->{tag};
576 $previndicator=$row->{tag_indicator};
579 # the last has not been included inside the loop... do it now !
580 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
581 $record->add_fields($field);
585 # Returns MARC::Record of the biblio passed in parameter.
586 my ($dbh,$bibid,$itemnumber)=@_;
587 my $record = MARC::Record->new();
588 # search MARC tagorder
589 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=?");
590 $sth2->execute($bibid,$itemnumber);
591 my ($tagorder) = $sth2->fetchrow_array();
592 #---- TODO : the leader is missing
593 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
594 from marc_subfield_table
595 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
597 $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
598 $sth->execute($bibid,$tagorder);
599 while (my $row=$sth->fetchrow_hashref) {
600 if ($row->{'valuebloblink'}) { #---- search blob if there is one
601 $sth2->execute($row->{'valuebloblink'});
602 my $row2=$sth2->fetchrow_hashref;
604 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
606 if ($record->field($row->{'tag'})) {
608 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
609 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
610 if (length($row->{'tag'}) <3) {
611 $row->{'tag'} = "0".$row->{'tag'};
613 $field =$record->field($row->{'tag'});
615 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
616 $record->delete_field($field);
617 $record->add_fields($field);
620 if (length($row->{'tag'}) < 3) {
621 $row->{'tag'} = "0".$row->{'tag'};
623 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
624 $record->add_fields($temp);
632 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
633 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
634 # warn "OLD : ".$oldrecord->as_formatted();
635 # warn "----------------------------------\nNEW : ".$record->as_formatted();
637 # if nothing to change, don't waste time...
638 if ($oldrecord eq $record) {
639 # warn "NOTHING TO CHANGE";
642 # otherwise, skip through each subfield...
643 my @fields = $record->fields();
645 foreach my $field (@fields) {
646 my $oldfield = $oldrecord->field($field->tag());
647 my @subfields=$field->subfields();
650 foreach my $subfield (@subfields) {
652 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
653 # just adding datas...
654 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
655 1,@$subfield[0],$subfieldorder,@$subfield[1]);
657 # modify the subfield if it's a different string
658 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
659 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
660 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
669 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
670 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
671 # if nothing to change, don't waste time...
672 if ($oldrecord eq $record) {
673 # warn "nothing to change";
676 # warn "MARCmoditem : ".$record->as_formatted;
677 # warn "OLD : ".$oldrecord->as_formatted;
679 # otherwise, skip through each subfield...
680 my @fields = $record->fields();
681 # search old MARC item
682 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=?");
683 $sth2->execute($bibid,$itemnumber);
684 my ($tagorder) = $sth2->fetchrow_array();
685 foreach my $field (@fields) {
686 my $oldfield = $oldrecord->field($field->tag());
687 my @subfields=$field->subfields();
689 foreach my $subfield (@subfields) {
691 # warn "compare : $oldfield".$oldfield->subfield(@$subfield[0]);
692 if ($oldfield eq 0 or (length($oldfield->subfield(@$subfield[0])) ==0) ) {
693 # just adding datas...
694 # warn "addfield : / $subfieldorder / @$subfield[0] - @$subfield[1]";
695 # warn "NEW subfield : $bibid,".$field->tag().",".$tagorder.",".@$subfield[0].",".$subfieldorder.",".@$subfield[1].")";
696 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
697 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
699 # warn "modfield : / $subfieldorder / @$subfield[0] - @$subfield[1]";
700 # modify he subfield if it's a different string
701 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
702 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
703 # warn "changing : $subfieldid, $bibid,".$field->tag(),",$tagorder,@$subfield[0],@$subfield[1],$subfieldorder";
704 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
707 warn "nothing to change : ".$oldfield->subfield(@$subfield[0]);
715 sub MARCmodsubfield {
716 # Subroutine changes a subfield value given a subfieldid.
717 my ($dbh, $subfieldid, $subfieldvalue )=@_;
718 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
719 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
720 $sth1->execute($subfieldid);
721 my ($oldvaluebloblink)=$sth1->fetchrow;
724 # if too long, use a bloblink
725 if (length($subfieldvalue)>255 ) {
726 # if already a bloblink, update it, otherwise, insert a new one.
727 if ($oldvaluebloblink) {
728 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
729 $sth->execute($subfieldvalue,$oldvaluebloblink);
731 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
732 $sth->execute($subfieldvalue);
733 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
735 my ($res)=$sth->fetchrow;
736 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
737 $sth->execute($subfieldid);
740 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
741 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
742 $sth->execute($subfieldvalue, $subfieldid);
744 $dbh->do("unlock tables");
746 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
747 $sth->execute($subfieldid);
748 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
750 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
751 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
752 return($subfieldid, $subfieldvalue);
755 sub MARCfindsubfield {
756 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
760 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
761 if ($subfieldvalue) {
762 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
764 if ($subfieldorder<1) {
767 $query .= " and subfieldorder=$subfieldorder";
769 my $sti=$dbh->prepare($query);
770 $sti->execute($bibid,$tag, $subfieldcode);
771 while (($subfieldid) = $sti->fetchrow) {
773 $lastsubfieldid=$subfieldid;
775 if ($resultcounter>1) {
776 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
777 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
780 return $lastsubfieldid;
784 sub MARCfindsubfieldid {
785 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
786 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
787 where bibid=? and tag=? and tagorder=?
788 and subfieldcode=? and subfieldorder=?");
789 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
790 my ($res) = $sth->fetchrow;
792 $sth=$dbh->prepare("select subfieldid from marc_subfield_table
793 where bibid=? and tag=? and tagorder=?
794 and subfieldcode=?");
795 $sth->execute($bibid,$tag,$tagorder,$subfield);
796 ($res) = $sth->fetchrow;
801 sub MARCdelsubfield {
802 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
803 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
804 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
805 tag='$tag' and tagorder='$tagorder'
806 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
811 # delete a biblio for a $bibid
812 my ($dbh,$bibid) = @_;
813 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
814 $dbh->do("delete from marc_biblio where bibid='$bibid'");
817 sub MARCkoha2marcBiblio {
818 # this function builds partial MARC::Record from the old koha-DB fields
819 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
820 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
821 my $record = MARC::Record->new();
822 #--- if bibid, then retrieve old-style koha data
823 if ($biblionumber>0) {
824 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
825 from biblio where biblionumber=?");
826 $sth2->execute($biblionumber);
827 my $row=$sth2->fetchrow_hashref;
829 foreach $code (keys %$row) {
831 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
835 #--- if biblioitem, then retrieve old-style koha data
836 if ($biblioitemnumber>0) {
837 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
838 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
839 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
841 WHERE biblionumber=? and biblioitemnumber=?
843 $sth2->execute($biblionumber,$biblioitemnumber);
844 my $row=$sth2->fetchrow_hashref;
846 foreach $code (keys %$row) {
848 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
853 # TODO : retrieve notes, additionalauthors
856 sub MARCkoha2marcItem {
857 # this function builds partial MARC::Record from the old koha-DB fields
858 my ($dbh,$biblionumber,$itemnumber) = @_;
859 # my $dbh=&C4Connect;
860 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
861 my $record = MARC::Record->new();
862 #--- if item, then retrieve old-style koha data
864 # print STDERR "prepare $biblionumber,$itemnumber\n";
865 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
866 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
867 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
868 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
870 WHERE itemnumber=?");
871 $sth2->execute($itemnumber);
872 my $row=$sth2->fetchrow_hashref;
874 foreach $code (keys %$row) {
876 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
881 # TODO : retrieve notes, additionalauthors
884 sub MARCkoha2marcSubtitle {
885 # this function builds partial MARC::Record from the old koha-DB fields
886 my ($dbh,$bibnum,$subtitle) = @_;
887 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
888 my $record = MARC::Record->new();
889 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
893 sub MARCkoha2marcOnefield {
894 my ($sth,$record,$kohafieldname,$value)=@_;
897 $sth->execute($kohafieldname);
898 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
899 if ($record->field($tagfield)) {
900 my $tag =$record->field($tagfield);
902 $tag->add_subfields($tagsubfield,$value);
903 $record->delete_field($tag);
904 $record->add_fields($tag);
907 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
914 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
915 my $prevtag = @$rtags[0];
916 my $record = MARC::Record->new();
918 for (my $i=0; $i< @$rtags; $i++) {
919 # rebuild MARC::Record
920 if (@$rtags[$i] ne $prevtag) {
924 $indicators{$prevtag}.=' ';
925 my $field = MARC::Field->new( $prevtag, substr($indicators{$prevtag},0,1),substr($indicators{$prevtag},1,1), %subfieldlist);
926 $record->add_fields($field);
927 $prevtag = @$rtags[$i];
929 %subfieldlist->{@$rsubfields[$i]} = @$rvalues[$i];
931 # if (%subfieldlist->{@$rsubfields[$i]}) {
932 # %subfieldlist->{@$rsubfields[$i]} .= '|';
934 %subfieldlist->{@$rsubfields[$i]} .=@$rvalues[$i];
935 $prevtag= @$rtags[$i];
938 # the last has not been included inside the loop... do it now !
939 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
940 $record->add_fields($field);
945 my ($dbh,$record) = @_;
946 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
948 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
951 # print STDERR $record->as_formatted;
952 while (($field)=$sth2->fetchrow) {
953 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
955 $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
957 while (($field)=$sth2->fetchrow) {
958 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
960 $sth2=$dbh->prepare("SHOW COLUMNS from items");
962 while (($field)=$sth2->fetchrow) {
963 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
965 # additional authors : specific
966 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
970 sub MARCmarc2kohaOneField {
971 # FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
972 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
973 # warn "kohatable / $kohafield / $result / ";
977 $sth->execute($kohatable.".".$kohafield);
978 ($tagfield,$subfield) = $sth->fetchrow;
979 foreach my $field ($record->field($tagfield)) {
980 if ($field->subfield($subfield)) {
981 if ($result->{$kohafield}) {
982 $result->{$kohafield} .= " | ".$field->subfield($subfield);
984 $result->{$kohafield}=$field->subfield($subfield);
992 # split a subfield string and adds it into the word table.
994 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
995 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
996 my @words = split / /,$sentence;
997 my $stopwords= C4::Context->stopwords;
998 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
999 values (?,?,?,?,?,?,soundex(?))");
1000 foreach my $word (@words) {
1001 # we record only words longer than 2 car and not in stopwords hash
1002 if (length($word)>1 and !($stopwords->{uc($word)})) {
1003 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
1005 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";
1012 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
1013 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
1014 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
1015 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
1020 # NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW
1023 # all the following subs are useful to manage MARC-DB with complete MARC records.
1024 # it's used with marcimport, and marc management tools
1028 =item (oldbibnum,$oldbibitemnum) = NEWnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
1030 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
1031 are builded from the MARC::Record. If they are passed, they are used.
1033 =item NEWnewitem($dbh,$olditem);
1035 adds an item in the db. $olditem is a old-db hash.
1040 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
1041 # note $oldbiblio and $oldbiblioitem are not mandatory.
1042 # if not present, they will be builded from $record with MARCmarc2koha function
1043 if (($oldbiblio) and not($oldbiblioitem)) {
1044 print STDERR "NEWnewbiblio : missing parameter\n";
1045 print "NEWnewbiblio : missing parameter : contact koha development team\n";
1051 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
1052 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
1053 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
1055 my $olddata = MARCmarc2koha($dbh,$record);
1056 $oldbibnum = OLDnewbiblio($dbh,$olddata);
1057 $olddata->{'biblionumber'} = $oldbibnum;
1058 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
1060 # we must add bibnum and bibitemnum in MARC::Record...
1061 # we build the new field with biblionumber and biblioitemnumber
1062 # we drop the original field
1063 # we add the new builded field.
1064 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
1065 # (steve and paul : thinks 090 is a good choice)
1066 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
1067 $sth->execute("biblio.biblionumber");
1068 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
1069 $sth->execute("biblioitems.biblioitemnumber");
1070 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
1071 if ($tagfield1 != $tagfield2) {
1072 print STDERR "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1073 print "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1076 my $newfield = MARC::Field->new( $tagfield1,'','',
1077 "$tagsubfield1" => $oldbibnum,
1078 "$tagsubfield2" => $oldbibitemnum);
1079 # drop old field and create new one...
1080 my $old_field = $record->field($tagfield1);
1081 $record->delete_field($old_field);
1082 $record->add_fields($newfield);
1083 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
1084 return ($bibid,$oldbibnum,$oldbibitemnum );
1088 my ($dbh,$record,$bibid) =@_;
1089 &MARCmodbiblio($dbh,$record,$bibid);
1090 my $oldbiblio = MARCmarc2koha($dbh,$record);
1091 my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
1092 OLDmodbibitem($dbh,$oldbiblio);
1098 my ($dbh, $record,$bibid) = @_;
1099 # add item in old-DB
1100 my $item = &MARCmarc2koha($dbh,$record);
1101 # needs old biblionumber and biblioitemnumber
1102 $item->{'biblionumber'} = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
1103 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
1104 $sth->execute($item->{'biblionumber'});
1105 ($item->{'biblioitemnumber'}) = $sth->fetchrow;
1106 my ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{barcode});
1107 # add itemnumber to MARC::Record before adding the item.
1108 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
1109 &MARCkoha2marcOnefield($sth,$record,"items.itemnumber",$itemnumber);
1111 my $bib = &MARCadditem($dbh,$record,$item->{'biblionumber'});
1115 my ($dbh,$record,$bibid,$itemnumber,$delete) = @_;
1116 &MARCmoditem($dbh,$record,$bibid,$itemnumber,$delete);
1117 my $olditem = MARCmarc2koha($dbh,$record);
1118 OLDmoditem($dbh,$olditem);
1123 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
1127 =item $biblionumber = OLDnewbiblio($dbh,$biblio);
1129 adds a record in biblio table. Datas are in the hash $biblio.
1131 =item $biblionumber = OLDmodbiblio($dbh,$biblio);
1133 modify a record in biblio table. Datas are in the hash $biblio.
1135 =item OLDmodsubtitle($dbh,$bibnum,$subtitle);
1137 modify subtitles in bibliosubtitle table.
1139 =item OLDmodaddauthor($dbh,$bibnum,$author);
1141 adds or modify additional authors
1142 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1144 =item $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1146 modify/adds subjects
1148 =item OLDmodbibitem($dbh, $biblioitem);
1152 =item OLDmodnote($dbh,$bibitemnum,$note
1154 modify a note for a biblioitem
1156 =item OLDnewbiblioitem($dbh,$biblioitem);
1158 adds a biblioitem ($biblioitem is a hash with the values)
1160 =item OLDnewsubject($dbh,$bibnum);
1164 =item OLDnewsubtitle($dbh,$bibnum,$subtitle);
1166 create a new subtitle
1168 =item ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1170 create a item. $item is a hash and $barcode the barcode.
1172 =item OLDmoditem($dbh,$item);
1176 =item OLDdelitem($dbh,$itemnum);
1180 =item OLDdeletebiblioitem($dbh,$biblioitemnumber);
1182 deletes a biblioitem
1183 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1185 =item OLDdelbiblio($dbh,$biblio);
1192 my ($dbh,$biblio) = @_;
1193 # my $dbh = &C4Connect;
1194 my $query = "Select max(biblionumber) from biblio";
1195 my $sth = $dbh->prepare($query);
1197 my $data = $sth->fetchrow_arrayref;
1198 my $bibnum = $$data[0] + 1;
1201 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1202 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1203 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
1204 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
1205 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1206 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1207 if ($biblio->{'seriestitle'}) { $series = 1 };
1210 $query = "insert into biblio set
1211 biblionumber = $bibnum,
1212 title = $biblio->{'title'},
1213 author = $biblio->{'author'},
1214 copyrightdate = $biblio->{'copyright'},
1216 seriestitle = $biblio->{'seriestitle'},
1217 notes = $biblio->{'notes'},
1218 abstract = $biblio->{'abstract'}";
1220 $sth = $dbh->prepare($query);
1229 my ($dbh,$biblio) = @_;
1230 # my $dbh = C4Connect;
1234 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1235 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1236 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1237 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
1238 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
1239 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
1240 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
1241 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1243 $query = "Update biblio set
1244 title = $biblio->{'title'},
1245 author = $biblio->{'author'},
1246 abstract = $biblio->{'abstract'},
1247 copyrightdate = $biblio->{'copyrightdate'},
1248 seriestitle = $biblio->{'seriestitle'},
1249 serial = $biblio->{'serial'},
1250 unititle = $biblio->{'unititle'},
1251 notes = $biblio->{'notes'}
1252 where biblionumber = $biblio->{'biblionumber'}";
1253 $sth = $dbh->prepare($query);
1257 return($biblio->{'biblionumber'});
1260 sub OLDmodsubtitle {
1261 my ($dbh,$bibnum, $subtitle) = @_;
1262 # my $dbh = C4Connect;
1263 my $query = "update bibliosubtitle set
1264 subtitle = '$subtitle'
1265 where biblionumber = $bibnum";
1266 my $sth = $dbh->prepare($query);
1274 sub OLDmodaddauthor {
1275 my ($dbh,$bibnum, $author) = @_;
1276 # my $dbh = C4Connect;
1277 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1278 my $sth = $dbh->prepare($query);
1283 if ($author ne '') {
1284 $query = "Insert into additionalauthors set
1286 biblionumber = '$bibnum'";
1287 $sth = $dbh->prepare($query);
1293 } # sub modaddauthor
1297 my ($dbh,$bibnum, $force, @subject) = @_;
1298 # my $dbh = C4Connect;
1299 my $count = @subject;
1301 for (my $i = 0; $i < $count; $i++) {
1302 $subject[$i] =~ s/^ //g;
1303 $subject[$i] =~ s/ $//g;
1304 my $query = "select * from catalogueentry
1305 where entrytype = 's'
1306 and catalogueentry = '$subject[$i]'";
1307 my $sth = $dbh->prepare($query);
1310 if (my $data = $sth->fetchrow_hashref) {
1312 if ($force eq $subject[$i]) {
1313 # subject not in aut, chosen to force anway
1314 # so insert into cataloguentry so its in auth file
1315 $query = "Insert into catalogueentry
1316 (entrytype,catalogueentry)
1317 values ('s','$subject[$i]')";
1318 my $sth2 = $dbh->prepare($query);
1323 $error = "$subject[$i]\n does not exist in the subject authority file";
1324 $query = "Select * from catalogueentry
1325 where entrytype = 's'
1326 and (catalogueentry like '$subject[$i] %'
1327 or catalogueentry like '% $subject[$i] %'
1328 or catalogueentry like '% $subject[$i]')";
1329 my $sth2 = $dbh->prepare($query);
1332 while (my $data = $sth2->fetchrow_hashref) {
1333 $error .= "<br>$data->{'catalogueentry'}";
1341 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1342 my $sth = $dbh->prepare($query);
1345 for (my $i = 0; $i < $count; $i++) {
1346 $sth = $dbh->prepare("Insert into bibliosubject
1347 values ('$subject[$i]', $bibnum)");
1359 my ($dbh,$biblioitem) = @_;
1360 # my $dbh = C4Connect;
1363 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1364 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1365 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1366 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1367 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1368 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1369 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1370 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1371 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1372 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1373 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1374 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1375 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1376 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1378 $query = "Update biblioitems set
1379 itemtype = $biblioitem->{'itemtype'},
1380 url = $biblioitem->{'url'},
1381 isbn = $biblioitem->{'isbn'},
1382 publishercode = $biblioitem->{'publishercode'},
1383 publicationyear = $biblioitem->{'publicationyear'},
1384 classification = $biblioitem->{'classification'},
1385 dewey = $biblioitem->{'dewey'},
1386 subclass = $biblioitem->{'subclass'},
1387 illus = $biblioitem->{'illus'},
1388 pages = $biblioitem->{'pages'},
1389 volumeddesc = $biblioitem->{'volumeddesc'},
1390 notes = $biblioitem->{'notes'},
1391 size = $biblioitem->{'size'},
1392 place = $biblioitem->{'place'}
1393 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1401 my ($dbh,$bibitemnum,$note)=@_;
1402 # my $dbh=C4Connect;
1403 my $query="update biblioitems set notes='$note' where
1404 biblioitemnumber='$bibitemnum'";
1405 my $sth=$dbh->prepare($query);
1411 sub OLDnewbiblioitem {
1412 my ($dbh,$biblioitem) = @_;
1413 # my $dbh = C4Connect;
1414 my $query = "Select max(biblioitemnumber) from biblioitems";
1415 my $sth = $dbh->prepare($query);
1420 $data = $sth->fetchrow_arrayref;
1421 $bibitemnum = $$data[0] + 1;
1425 $sth = $dbh->prepare("insert into biblioitems set
1426 biblioitemnumber = ?, biblionumber = ?,
1427 volume = ?, number = ?,
1428 classification = ?, itemtype = ?,
1430 issn = ?, dewey = ?,
1431 subclass = ?, publicationyear = ?,
1432 publishercode = ?, volumedate = ?,
1433 volumeddesc = ?, illus = ?,
1434 pages = ?, notes = ?,
1436 marc = ?, place = ?");
1437 $sth->execute($bibitemnum, $biblioitem->{'biblionumber'},
1438 $biblioitem->{'volume'}, $biblioitem->{'number'},
1439 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
1440 $biblioitem->{'url'}, $biblioitem->{'isbn'},
1441 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
1442 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
1443 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
1444 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
1445 $biblioitem->{'pages'}, $biblioitem->{'notes'},
1446 $biblioitem->{'size'}, $biblioitem->{'lccn'},
1447 $biblioitem->{'marc'}, $biblioitem->{'place'});
1450 return($bibitemnum);
1454 my ($dbh,$bibnum)=@_;
1455 # my $dbh=C4Connect;
1456 my $query="insert into bibliosubject (biblionumber) values
1458 my $sth=$dbh->prepare($query);
1465 sub OLDnewsubtitle {
1466 my ($dbh,$bibnum, $subtitle) = @_;
1467 # my $dbh = C4Connect;
1468 $subtitle = $dbh->quote($subtitle);
1469 my $query = "insert into bibliosubtitle set
1470 biblionumber = $bibnum,
1471 subtitle = $subtitle";
1472 my $sth = $dbh->prepare($query);
1482 my ($dbh,$item, $barcode) = @_;
1483 # my $dbh = C4Connect;
1484 my $query = "Select max(itemnumber) from items";
1485 my $sth = $dbh->prepare($query);
1491 $data = $sth->fetchrow_hashref;
1492 $itemnumber = $data->{'max(itemnumber)'} + 1;
1495 $sth=$dbh->prepare("Insert into items set
1496 itemnumber = ?, biblionumber = ?,
1497 biblioitemnumber = ?, barcode = ?,
1498 booksellerid = ?, dateaccessioned = NOW(),
1499 homebranch = ?, holdingbranch = ?,
1500 price = ?, replacementprice = ?,
1501 replacementpricedate = NOW(), itemnotes = ?,
1504 $sth->execute($itemnumber, $item->{'biblionumber'},
1505 $item->{'biblioitemnumber'},$barcode,
1506 $item->{'booksellerid'},
1507 $item->{'homebranch'},$item->{'homebranch'},
1508 $item->{'price'},$item->{'replacementprice'},
1509 $item->{'itemnotes'},$item->{'loan'});
1512 if (defined $sth->errstr) {
1513 $error .= $sth->errstr;
1518 return($itemnumber,$error);
1522 my ($dbh,$item) = @_;
1523 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1524 # my $dbh=C4Connect;
1525 $item->{'itemnum'}=$item->{'itemnumber'} unless $item->{'itemnum'};
1526 my $query="update items set barcode='$item->{'barcode'}',itemnotes='$item->{'notes'}'
1527 where itemnumber=$item->{'itemnum'}";
1528 if ($item->{'barcode'} eq ''){
1529 $query="update items set notforloan=$item->{'loan'} where itemnumber=$item->{'itemnum'}";
1531 if ($item->{'lost'} ne ''){
1532 $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1533 barcode='$item->{'barcode'}',
1534 itemnotes='$item->{'notes'}',
1535 homebranch='$item->{'homebranch'}',
1536 itemlost='$item->{'lost'}',
1537 wthdrawn='$item->{'wthdrawn'}'
1538 where itemnumber=$item->{'itemnum'}";
1540 if ($item->{'replacement'} ne ''){
1541 $query=~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1543 my $sth=$dbh->prepare($query);
1550 my ($dbh,$itemnum)=@_;
1551 # my $dbh=C4Connect;
1552 my $query="select * from items where itemnumber=$itemnum";
1553 my $sth=$dbh->prepare($query);
1555 my @data=$sth->fetchrow_array;
1557 $query="Insert into deleteditems values (";
1558 foreach my $temp (@data){
1559 $query .= "'$temp',";
1563 $sth=$dbh->prepare($query);
1566 $query = "Delete from items where itemnumber=$itemnum";
1567 $sth=$dbh->prepare($query);
1573 sub OLDdeletebiblioitem {
1574 my ($dbh,$biblioitemnumber) = @_;
1575 # my $dbh = C4Connect;
1576 my $query = "Select * from biblioitems
1577 where biblioitemnumber = $biblioitemnumber";
1578 my $sth = $dbh->prepare($query);
1583 if (@results = $sth->fetchrow_array) {
1584 $query = "Insert into deletedbiblioitems values (";
1585 foreach my $value (@results) {
1586 $value = $dbh->quote($value);
1587 $query .= "$value,";
1590 $query =~ s/\,$/\)/;
1593 $query = "Delete from biblioitems
1594 where biblioitemnumber = $biblioitemnumber";
1598 # Now delete all the items attached to the biblioitem
1599 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1600 $sth = $dbh->prepare($query);
1602 while (@results = $sth->fetchrow_array) {
1603 $query = "Insert into deleteditems values (";
1604 foreach my $value (@results) {
1605 $value = $dbh->quote($value);
1606 $query .= "$value,";
1608 $query =~ s/\,$/\)/;
1612 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1615 } # sub deletebiblioitem
1618 my ($dbh,$biblio)=@_;
1619 # my $dbh=C4Connect;
1620 my $query="select * from biblio where biblionumber=$biblio";
1621 my $sth=$dbh->prepare($query);
1623 if (my @data=$sth->fetchrow_array){
1625 $query="Insert into deletedbiblio values (";
1626 foreach my $temp (@data){
1627 $temp=~ s/\'/\\\'/g;
1628 $query .= "'$temp',";
1632 $sth=$dbh->prepare($query);
1635 $query = "Delete from biblio where biblionumber=$biblio";
1636 $sth=$dbh->prepare($query);
1652 my $dbh = C4::Context->dbh;
1653 my $query="Select count(*) from items where biblionumber=$biblio";
1655 my $sth=$dbh->prepare($query);
1657 my $data=$sth->fetchrow_hashref;
1659 return($data->{'count(*)'});
1664 ($order, $ordernumber) = &getorder($biblioitemnumber, $biblionumber);
1666 Looks up the order with the given biblionumber and biblioitemnumber.
1668 Returns a two-element array. C<$ordernumber> is the order number.
1669 C<$order> is a reference-to-hash describing the order; its keys are
1670 fields from the biblio, biblioitems, aqorders, and aqorderbreakdown
1671 tables of the Koha database.
1675 # FIXME - This is effectively identical to &C4::Catalogue::getorder.
1676 # Pick one and stick with it.
1679 my $dbh = C4::Context->dbh;
1680 my $query="Select ordernumber
1682 where biblionumber=? and biblioitemnumber=?";
1683 my $sth=$dbh->prepare($query);
1684 $sth->execute($bib,$bi);
1685 # FIXME - Use fetchrow_array(), since we're only interested in the one
1687 my $ordnum=$sth->fetchrow_hashref;
1689 my $order=getsingleorder($ordnum->{'ordernumber'});
1691 return ($order,$ordnum->{'ordernumber'});
1694 =item getsingleorder
1696 $order = &getsingleorder($ordernumber);
1698 Looks up an order by order number.
1700 Returns a reference-to-hash describing the order. The keys of
1701 C<$order> are fields from the biblio, biblioitems, aqorders, and
1702 aqorderbreakdown tables of the Koha database.
1706 # FIXME - This is effectively identical to
1707 # &C4::Catalogue::getsingleorder.
1708 # Pick one and stick with it.
1709 sub getsingleorder {
1711 my $dbh = C4::Context->dbh;
1712 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1713 where aqorders.ordernumber=?
1714 and biblio.biblionumber=aqorders.biblionumber and
1715 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1716 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1717 my $sth=$dbh->prepare($query);
1718 $sth->execute($ordnum);
1719 my $data=$sth->fetchrow_hashref;
1726 my $dbh = C4::Context->dbh;
1727 my $bibnum=OLDnewbiblio($dbh,$biblio);
1734 $biblionumber = &modbiblio($biblio);
1736 Update a biblio record.
1738 C<$biblio> is a reference-to-hash whose keys are the fields in the
1739 biblio table in the Koha database. All fields must be present, not
1740 just the ones you wish to change.
1742 C<&modbiblio> updates the record defined by
1743 C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
1745 C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
1752 my $dbh = C4::Context->dbh;
1753 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1754 return($biblionumber);
1760 &modsubtitle($biblionumber, $subtitle);
1762 Sets the subtitle of a book.
1764 C<$biblionumber> is the biblionumber of the book to modify.
1766 C<$subtitle> is the new subtitle.
1771 my ($bibnum, $subtitle) = @_;
1772 my $dbh = C4::Context->dbh;
1773 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1778 &modaddauthor($biblionumber, $author);
1780 Replaces all additional authors for the book with biblio number
1781 C<$biblionumber> with C<$author>. If C<$author> is the empty string,
1782 C<&modaddauthor> deletes all additional authors.
1787 my ($bibnum, $author) = @_;
1788 my $dbh = C4::Context->dbh;
1789 &OLDmodaddauthor($dbh,$bibnum,$author);
1790 } # sub modaddauthor
1794 $error = &modsubject($biblionumber, $force, @subjects);
1796 $force - a subject to force
1798 $error - Error message, or undef if successful.
1803 my ($bibnum, $force, @subject) = @_;
1804 my $dbh = C4::Context->dbh;
1805 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1810 my ($biblioitem) = @_;
1811 my $dbh = C4::Context->dbh;
1812 &OLDmodbibitem($dbh,$biblioitem);
1813 my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
1814 &MARCmodbiblio($dbh,$biblioitem->{biblionumber},0,$MARCbibitem);
1818 my ($bibitemnum,$note)=@_;
1819 my $dbh = C4::Context->dbh;
1820 &OLDmodnote($dbh,$bibitemnum,$note);
1824 my ($biblioitem) = @_;
1825 my $dbh = C4::Context->dbh;
1826 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1827 # print STDERR "bibitemnum : $bibitemnum\n";
1828 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1829 # print STDERR $MARCbiblio->as_formatted();
1830 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1831 return($bibitemnum);
1836 my $dbh = C4::Context->dbh;
1837 &OLDnewsubject($dbh,$bibnum);
1841 my ($bibnum, $subtitle) = @_;
1842 my $dbh = C4::Context->dbh;
1843 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1847 my ($item, @barcodes) = @_;
1848 my $dbh = C4::Context->dbh;
1852 foreach my $barcode (@barcodes) {
1853 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1855 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1856 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1863 my $dbh = C4::Context->dbh;
1864 &OLDmoditem($dbh,$item);
1865 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1866 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1867 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1871 my ($count,@barcodes)=@_;
1872 my $dbh = C4::Context->dbh;
1874 for (my $i=0;$i<$count;$i++){
1875 $barcodes[$i]=uc $barcodes[$i];
1876 my $query="Select * from items where barcode='$barcodes[$i]'";
1877 my $sth=$dbh->prepare($query);
1879 if (my $data=$sth->fetchrow_hashref){
1880 $error.=" Duplicate Barcode: $barcodes[$i]";
1888 my ($bibitemnum)=@_;
1889 my $dbh = C4::Context->dbh;
1890 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1891 my $sth=$dbh->prepare($query);
1893 my $data=$sth->fetchrow_hashref;
1895 return($data->{'count(*)'});
1900 my $dbh = C4::Context->dbh;
1901 &OLDdelitem($dbh,$itemnum);
1904 sub deletebiblioitem {
1905 my ($biblioitemnumber) = @_;
1906 my $dbh = C4::Context->dbh;
1907 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1908 } # sub deletebiblioitem
1913 my $dbh = C4::Context->dbh;
1914 &OLDdelbiblio($dbh,$biblio);
1918 my $dbh = C4::Context->dbh;
1919 my $query = "select * from itemtypes";
1920 my $sth = $dbh->prepare($query);
1921 # || die "Cannot prepare $query" . $dbh->errstr;
1926 # || die "Cannot execute $query\n" . $sth->errstr;
1927 while (my $data = $sth->fetchrow_hashref) {
1928 $results[$count] = $data;
1933 return($count, @results);
1934 } # sub getitemtypes
1937 my ($biblionumber) = @_;
1938 my $dbh = C4::Context->dbh;
1939 my $query = "Select * from biblio where biblionumber = $biblionumber";
1940 my $sth = $dbh->prepare($query);
1941 # || die "Cannot prepare $query\n" . $dbh->errstr;
1946 # || die "Cannot execute $query\n" . $sth->errstr;
1947 while (my $data = $sth->fetchrow_hashref) {
1948 $results[$count] = $data;
1953 return($count, @results);
1957 my ($biblioitemnum) = @_;
1958 my $dbh = C4::Context->dbh;
1959 my $query = "Select * from biblioitems where
1960 biblioitemnumber = $biblioitemnum";
1961 my $sth = $dbh->prepare($query);
1967 while (my $data = $sth->fetchrow_hashref) {
1968 $results[$count] = $data;
1973 return($count, @results);
1974 } # sub getbiblioitem
1976 sub getbiblioitembybiblionumber {
1977 my ($biblionumber) = @_;
1978 my $dbh = C4::Context->dbh;
1979 my $query = "Select * from biblioitems where biblionumber =
1981 my $sth = $dbh->prepare($query);
1987 while (my $data = $sth->fetchrow_hashref) {
1988 $results[$count] = $data;
1993 return($count, @results);
1996 sub getitemsbybiblioitem {
1997 my ($biblioitemnum) = @_;
1998 my $dbh = C4::Context->dbh;
1999 my $query = "Select * from items, biblio where
2000 biblio.biblionumber = items.biblionumber and biblioitemnumber
2002 my $sth = $dbh->prepare($query);
2003 # || die "Cannot prepare $query\n" . $dbh->errstr;
2008 # || die "Cannot execute $query\n" . $sth->errstr;
2009 while (my $data = $sth->fetchrow_hashref) {
2010 $results[$count] = $data;
2015 return($count, @results);
2016 } # sub getitemsbybiblioitem
2020 my $dbh = C4::Context->dbh;
2026 $isbn = $dbh->quote($isbn);
2027 $query = "Select distinct biblio.* from biblio, biblioitems where
2028 biblio.biblionumber = biblioitems.biblionumber
2030 $sth = $dbh->prepare($query);
2033 while (my $data = $sth->fetchrow_hashref) {
2034 $results[$count] = $data;
2039 return($count, @results);
2043 # At the moment this is just a straight copy of the subject code. Needs heavy
2044 # modification to work for additional authors, obviously.
2045 # Check for additional author changes
2047 # my $newadditionalauthor='';
2048 # my $additionalauthors;
2049 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
2050 # $additionalauthors->{$newadditionalauthor}=1;
2051 # if ($origadditionalauthors->{$newadditionalauthor}) {
2052 # $additionalauthors->{$newadditionalauthor}=2;
2054 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
2055 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
2057 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
2059 # $subfields->{1}->{'Subfield_Mark'}='a';
2060 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
2063 # foreach $Record_ID (@marcrecords) {
2064 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2065 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
2069 # my $origadditionalauthor;
2070 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
2071 # if ($additionalauthors->{$origadditionalauthor} == 1) {
2072 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
2073 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
2074 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
2084 # Subroutine to log changes to databases
2085 # Eventually, this subroutine will be used to create a log of all changes made,
2086 # with the possibility of "undo"ing some changes
2088 if ($database eq 'kohadb') {
2094 # print STDERR "KOHA: $type $section $item $original $new\n";
2095 } elsif ($database eq 'marc') {
2097 my $Record_ID=shift;
2100 my $subfield_ID=shift;
2103 # print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2107 #------------------------------------------------
2110 #---------------------------------------
2111 # Find a biblio entry, or create a new one if it doesn't exist.
2112 # If a "subtitle" entry is in hash, add it to subtitle table
2113 sub getoraddbiblio {
2117 # FIXME - Unused argument
2118 $biblio, # hash ref to fields
2129 $dbh = C4::Context->dbh;
2131 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2132 $sth=$dbh->prepare("select biblionumber
2134 where title=? and author=?
2135 and copyrightdate=? and seriestitle=?");
2137 $biblio->{title}, $biblio->{author},
2138 $biblio->{copyright}, $biblio->{seriestitle} );
2140 ($biblionumber) = $sth->fetchrow;
2141 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2143 # Doesn't exist. Add new one.
2144 print "<PRE>Adding biblio</PRE>\n" if $debug;
2145 ($biblionumber,$error)=&newbiblio($biblio);
2146 if ( $biblionumber ) {
2147 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
2148 if ( $biblio->{subtitle} ) {
2149 &newsubtitle($biblionumber,$biblio->{subtitle} );
2152 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2156 return $biblionumber,$error;
2158 } # sub getoraddbiblio
2160 END { } # module clean-up code here (global destructor)
2166 Koha Developement team <info@koha.org>
2168 Paul POULAIN paul.poulain@free.fr