4 # Revision 1.31 2002/12/13 16:22:04 tipaul
5 # 1st draft of marc export
7 # Revision 1.30 2002/12/12 21:26:35 tipaul
8 # YAB ! (Yet Another Bugfix) => related to biblio modif
9 # (some warning cleaning too)
11 # Revision 1.29 2002/12/12 16:35:00 tipaul
12 # adding authentification with Auth.pm and
13 # MAJOR BUGFIX on marc biblio modification
15 # Revision 1.28 2002/12/10 13:30:03 tipaul
16 # fugfixes from Dombes Abbey work
18 # Revision 1.27 2002/11/19 12:36:16 tipaul
20 # various bugfixes, improvments, and migration from acquisition.pm to biblio.pm
22 # Revision 1.26 2002/11/12 15:58:43 tipaul
25 # * 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)
27 # Revision 1.25 2002/10/25 10:58:26 tipaul
29 # * bugfixes and improvements
31 # Revision 1.24 2002/10/24 12:09:01 arensb
32 # Fixed "no title" warning when generating HTML documentation from POD.
34 # Revision 1.23 2002/10/16 12:43:08 arensb
35 # Added some FIXME comments.
37 # Revision 1.22 2002/10/15 13:39:17 tipaul
38 # removing Acquisition.pm
39 # deleting unused code in biblio.pm, rewriting POD and answering most FIXME comments
41 # Revision 1.21 2002/10/13 11:34:14 arensb
42 # Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
43 # Thus, $x = $x+2 becomes $x += 2, and so forth.
45 # Revision 1.20 2002/10/13 08:28:32 arensb
46 # Deleted unused variables.
47 # Removed trailing whitespace.
49 # Revision 1.19 2002/10/13 05:56:10 arensb
50 # Added some FIXME comments.
52 # Revision 1.18 2002/10/11 12:34:53 arensb
53 # Replaced &requireDBI with C4::Context->dbh
55 # Revision 1.17 2002/10/10 14:48:25 tipaul
58 # Revision 1.16 2002/10/07 14:04:26 tipaul
59 # road to 1.3.1 : viewing MARC biblio
61 # Revision 1.15 2002/10/05 09:49:25 arensb
62 # Merged with arensb-context branch: use C4::Context->dbh instead of
63 # &C4Connect, and generally prefer C4::Context over C4::Database.
65 # Revision 1.14 2002/10/03 11:28:18 tipaul
66 # Extending Context.pm to add stopword management and using it in MARC-API.
67 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
69 # Revision 1.13 2002/10/02 16:26:44 tipaul
72 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
73 # Merged in changes from main branch.
75 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
76 # Added a whole mess of FIXME comments.
78 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
79 # Added some missing semicolons.
81 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
82 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
85 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
86 # Added a whole mess of FIXME comments.
88 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
89 # Added some missing semicolons.
91 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
92 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
95 # Revision 1.12 2002/10/01 11:48:51 arensb
96 # Added some FIXME comments, mostly marking duplicate functions.
98 # Revision 1.11 2002/09/24 13:49:26 tipaul
99 # long WAS the road to 1.3.0...
100 # coming VERY SOON NOW...
101 # modifying installer and buildrelease to update the DB
103 # Revision 1.10 2002/09/22 16:50:08 arensb
104 # Added some FIXME comments.
106 # Revision 1.9 2002/09/20 12:57:46 tipaul
107 # long is the road to 1.4.0
108 # * MARCadditem and MARCmoditem now wroks
109 # * various bugfixes in MARC management
110 # !!! 1.3.0 should be released very soon now. Be careful !!!
112 # Revision 1.8 2002/09/10 13:53:52 tipaul
113 # MARC API continued...
115 # * 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)
117 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
119 # Revision 1.7 2002/08/14 18:12:51 tonnesen
120 # Added copyright statement to all .pl and .pm files
122 # Revision 1.6 2002/07/25 13:40:31 tipaul
123 # pod documenting the API.
125 # Revision 1.5 2002/07/24 16:11:37 tipaul
127 # Database.pm and Output.pm are almost not modified (var test...)
129 # Biblio.pm is almost completly rewritten.
131 # WHAT DOES IT ??? ==> END of Hitchcock suspens
133 # 1st, it does... nothing...
134 # 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 ...
136 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
137 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
138 # * 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.
139 # * 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.
140 # 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 ;-)
142 # 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.
143 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
147 # Copyright 2000-2002 Katipo Communications
149 # This file is part of Koha.
151 # Koha is free software; you can redistribute it and/or modify it under the
152 # terms of the GNU General Public License as published by the Free Software
153 # Foundation; either version 2 of the License, or (at your option) any later
156 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
157 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
158 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
160 # You should have received a copy of the GNU General Public License along with
161 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
162 # Suite 330, Boston, MA 02111-1307 USA
170 use vars qw($VERSION @ISA @EXPORT);
172 # set the version for version checking
177 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
178 # as the old-style API and the NEW one are the only public functions.
181 &updateBiblio &updateBiblioItem &updateItem
182 &itemcount &newbiblio &newbiblioitem
183 &modnote &newsubject &newsubtitle
184 &modbiblio &checkitems
185 &newitems &modbibitem
186 &modsubtitle &modsubject &modaddauthor &moditem &countitems
187 &delitem &deletebiblioitem &delbiblio
188 &getitemtypes &getbiblio
189 &getbiblioitembybiblionumber
190 &getbiblioitem &getitemsbybiblioitem &isbnsearch
192 &newcompletebiblioitem
194 &MARCfind_oldbiblionumber_from_MARCbibid
195 &MARCfind_MARCbibid_from_oldbiblionumber
196 &MARCfind_marc_from_kohafield
200 &NEWnewbiblio &NEWnewitem
201 &NEWmodbiblio &NEWmoditem
203 &MARCaddbiblio &MARCadditem
204 &MARCmodsubfield &MARCaddsubfield
205 &MARCmodbiblio &MARCmoditem
206 &MARCkoha2marcBiblio &MARCmarc2koha
207 &MARCkoha2marcItem &MARChtml2marc
208 &MARCgetbiblio &MARCgetitem
209 &MARCaddword &MARCdelword
214 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
217 # all the following subs takes a MARC::Record as parameter and manage
218 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
219 # NEWxxx subs (xxx deals with old-DB parameters, the NEWxxx deals with MARC-DB parameter)
223 C4::Biblio - acquisition, catalog management functions
227 move from 1.2 to 1.4 version :
228 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
229 In the 1.4 version, we want to do 2 differents things :
230 - keep populating the old-DB, that has a LOT less datas than MARC
231 - populate the MARC-DB
232 To populate the DBs we have 2 differents sources :
233 - the standard acquisition system (through book sellers), that does'nt use MARC data
234 - the MARC acquisition system, that uses MARC data.
236 Thus, we have 2 differents cases :
237 - 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
238 - 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
240 That's why we need 4 subs :
241 all I<subs beginning by MARC> manage only MARC tables. They manage MARC-DB with MARC::Record parameters
242 all I<subs beginning by OLD> manage only OLD-DB tables. They manage old-DB with old-DB parameters
243 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
244 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.
246 - NEW and old-style API should be used in koha to manage biblio
247 - MARCsubs are divided in 2 parts :
248 * some of them manage MARC parameters. They are heavily used in koha.
249 * some of them manage MARC biblio : they are mostly used by NEW and old-style subs.
250 - OLD are used internally only
252 all subs requires/use $dbh as 1st parameter.
254 I<NEWxxx related subs>
256 all subs requires/use $dbh as 1st parameter.
257 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
259 I<OLDxxx related subs>
261 all subs requires/use $dbh as 1st parameter.
262 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
264 They all are the exact copy of 1.0/1.2 version of the sub without the OLD.
265 The OLDxxx is called by the original xxx sub.
266 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
268 WARNING : there is 1 difference between initialxxx and OLDxxx :
269 the db header $dbh is always passed as parameter to avoid over-DB connexion
275 =item @tagslib = &MARCgettagslib($dbh,1|0);
277 last param is 1 for liblibrarian and 0 for libopac
278 returns a hash with tag/subfield meaning
279 =item ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,$kohafield);
281 finds MARC tag and subfield for a given kohafield
282 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
284 =item $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
286 finds a old-db biblio number for a given MARCbibid number
288 =item $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
290 finds a MARC bibid from a old-db biblionumber
292 =item $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
294 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
296 =item $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
298 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
300 =item $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
302 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
304 =item $olddb = &MARCmarc2koha($dbh,$MARCRecord);
306 builds a hash with old-db datas from a MARC::Record
308 =item &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
310 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
312 =item &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
314 adds a subfield in a biblio (in the MARC tables only).
316 =item $MARCRecord = &MARCgetbiblio($dbh,$bibid);
318 Returns a MARC::Record for the biblio $bibid.
320 =item &MARCmodbiblio($dbh,$bibid,$delete,$record);
322 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
323 if $delete == 1, every field/subfield not found is deleted in the biblio
324 otherwise, only data passed to MARCmodbiblio is managed.
325 thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
327 =item ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
329 MARCmodsubfield changes the value of a given subfield
331 =item $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
333 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
334 Returns -1 if more than 1 answer
336 =item $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
338 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
340 =item &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
342 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
344 =item &MARCdelbiblio($dbh,$bibid);
346 MARCdelbiblio delete biblio $bibid
348 =item &MARCkoha2marcOnefield
350 used by MARCkoha2marc and should not be useful elsewhere
352 =item &MARCmarc2kohaOnefield
354 used by MARCmarc2koha and should not be useful elsewhere
358 used to manage MARC_word table and should not be useful elsewhere
362 used to manage MARC_word table and should not be useful elsewhere
367 my ($dbh,$forlibrarian)= @_;
369 if ($forlibrarian eq 1) {
370 $sth=$dbh->prepare("select tagfield,liblibrarian as lib from marc_tag_structure order by tagfield");
372 $sth=$dbh->prepare("select tagfield,libopac as lib from marc_tag_structure order by tagfield");
375 my ($lib,$tag,$res,$tab,$mandatory,$repeatable);
376 while ( ($tag,$lib,$tab) = $sth->fetchrow) {
377 $res->{$tag}->{lib}=$lib;
378 $res->{$tab}->{tab}="";
381 if ($forlibrarian eq 1) {
382 $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");
384 $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");
389 my $authorised_value;
390 my $thesaurus_category;
392 while ( ($tag, $subfield, $lib, $tab, $mandatory, $repeatable,$authorised_value,$thesaurus_category,$value_builder) = $sth->fetchrow) {
393 $res->{$tag}->{$subfield}->{lib}=$lib;
394 $res->{$tag}->{$subfield}->{tab}=$tab;
395 $res->{$tag}->{$subfield}->{mandatory}=$mandatory;
396 $res->{$tag}->{$subfield}->{repeatable}=$repeatable;
397 $res->{$tag}->{$subfield}->{authorised_value}=$authorised_value;
398 $res->{$tag}->{$subfield}->{thesaurus_category}=$thesaurus_category;
399 $res->{$tag}->{$subfield}->{value_builder}=$value_builder;
404 sub MARCfind_marc_from_kohafield {
405 my ($dbh,$kohafield) = @_;
406 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
407 $sth->execute($kohafield);
408 my ($tagfield,$tagsubfield) = $sth->fetchrow;
409 return ($tagfield,$tagsubfield);
412 sub MARCfind_oldbiblionumber_from_MARCbibid {
413 my ($dbh,$MARCbibid) = @_;
414 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
415 $sth->execute($MARCbibid);
416 my ($biblionumber) = $sth->fetchrow;
417 return $biblionumber;
420 sub MARCfind_MARCbibid_from_oldbiblionumber {
421 my ($dbh,$oldbiblionumber) = @_;
422 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
423 $sth->execute($oldbiblionumber);
424 my ($bibid) = $sth->fetchrow;
429 # pass the MARC::Record to this function, and it will create the records in the marc tables
430 my ($dbh,$record,$biblionumber) = @_;
431 my @fields=$record->fields();
433 # adding main table, and retrieving bibid
434 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
435 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
436 $sth->execute($biblionumber);
437 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
439 ($bibid)=$sth->fetchrow;
442 # now, add subfields...
443 foreach my $field (@fields) {
444 my @subfields=$field->subfields();
446 foreach my $subfieldcount (0..$#subfields) {
447 &MARCaddsubfield($dbh,$bibid,
449 $field->indicator(1).$field->indicator(2),
451 $subfields[$subfieldcount][0],
453 $subfields[$subfieldcount][1]
457 $dbh->do("unlock tables");
462 # pass the MARC::Record to this function, and it will create the records in the marc tables
463 my ($dbh,$record,$biblionumber) = @_;
464 # warn "adding : ".$record->as_formatted();
465 # search for MARC biblionumber
466 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
467 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
468 my @fields=$record->fields();
469 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
470 $sth->execute($bibid);
471 my ($fieldcount) = $sth->fetchrow;
472 # now, add subfields...
473 foreach my $field (@fields) {
474 my @subfields=$field->subfields();
476 foreach my $subfieldcount (0..$#subfields) {
477 &MARCaddsubfield($dbh,$bibid,
479 $field->indicator(1).$field->indicator(2),
481 $subfields[$subfieldcount][0],
483 $subfields[$subfieldcount][1]
485 # warn "ADDING :$bibid,".
487 $field->indicator(1).$field->indicator(2).",
489 $subfields[$subfieldcount][0],
491 $subfields[$subfieldcount][1]";
494 $dbh->do("unlock tables");
498 sub MARCaddsubfield {
499 # Add a new subfield to a tag into the DB.
500 my ($dbh,$bibid,$tagid,$tag_indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
501 # if not value, end of job, we do nothing
502 if (length($subfieldvalue) ==0) {
505 if (not($subfieldcode)) {
508 if (length($subfieldvalue)>255) {
509 # $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
510 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
511 $sth->execute($subfieldvalue);
512 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
514 my ($res)=$sth->fetchrow;
515 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?,?)");
517 $sth->execute($bibid,'0'.$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$res);
519 $sth->execute($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$res);
522 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";
524 # $dbh->do("unlock tables");
526 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)");
527 $sth->execute($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue);
529 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";
532 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
536 # Returns MARC::Record of the biblio passed in parameter.
538 my $record = MARC::Record->new();
539 #---- TODO : the leader is missing
540 $record->leader(' ');
541 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
542 from marc_subfield_table
543 where bibid=? order by tag,tagorder,subfieldcode
545 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
546 $sth->execute($bibid);
551 while (my $row=$sth->fetchrow_hashref) {
552 if ($row->{'valuebloblink'}) { #---- search blob if there is one
553 $sth2->execute($row->{'valuebloblink'});
554 my $row2=$sth2->fetchrow_hashref;
556 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
558 # warn "$row->{bibid} = $row->{tag} - $row->{subfieldcode} -> value : $row->{subfieldvalue}";
559 if ($row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag) {
560 if (length($prevtag) <3) {
561 $prevtag = "0".$prevtag;
564 # warn "NEW : subfieldcode : $prevtag";
565 my $field = MARC::Field->new( $prevtag, substr($previndicator,0,1), substr($previndicator,1,1), %subfieldlist);
566 # warn $field->as_formatted();
567 $record->add_fields($field);
568 $prevtagorder=$row->{tagorder};
569 $prevtag = $row->{tag};
570 $previndicator=$row->{tag_indicator};
572 %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
574 # warn "subfieldcode : $row->{'subfieldcode'} / value : $row->{'subfieldvalue'}, tag : $row->{tag}";
575 if (%subfieldlist->{$row->{'subfieldcode'}}) {
576 %subfieldlist->{$row->{'subfieldcode'}}.='|';
578 %subfieldlist->{$row->{'subfieldcode'}} .= $row->{'subfieldvalue'};
579 $prevtag= $row->{tag};
580 $previndicator=$row->{tag_indicator};
583 # the last has not been included inside the loop... do it now !
584 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
585 $record->add_fields($field);
589 # Returns MARC::Record of the biblio passed in parameter.
590 my ($dbh,$bibid,$itemnumber)=@_;
591 my $record = MARC::Record->new();
592 # search MARC tagorder
593 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=?");
594 $sth2->execute($bibid,$itemnumber);
595 my ($tagorder) = $sth2->fetchrow_array();
596 #---- TODO : the leader is missing
597 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
598 from marc_subfield_table
599 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
601 $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
602 $sth->execute($bibid,$tagorder);
603 while (my $row=$sth->fetchrow_hashref) {
604 if ($row->{'valuebloblink'}) { #---- search blob if there is one
605 $sth2->execute($row->{'valuebloblink'});
606 my $row2=$sth2->fetchrow_hashref;
608 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
610 if ($record->field($row->{'tag'})) {
612 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
613 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
614 if (length($row->{'tag'}) <3) {
615 $row->{'tag'} = "0".$row->{'tag'};
617 $field =$record->field($row->{'tag'});
619 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
620 $record->delete_field($field);
621 $record->add_fields($field);
624 if (length($row->{'tag'}) < 3) {
625 $row->{'tag'} = "0".$row->{'tag'};
627 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
628 $record->add_fields($temp);
636 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
637 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
638 # warn "OLD : ".$oldrecord->as_formatted();
639 # warn "----------------------------------\nNEW : ".$record->as_formatted();
641 # if nothing to change, don't waste time...
642 if ($oldrecord eq $record) {
643 # warn "NOTHING TO CHANGE";
646 # otherwise, skip through each subfield...
647 my @fields = $record->fields();
649 foreach my $field (@fields) {
650 my $oldfield = $oldrecord->field($field->tag());
651 my @subfields=$field->subfields();
654 foreach my $subfield (@subfields) {
656 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
657 # just adding datas...
658 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
659 1,@$subfield[0],$subfieldorder,@$subfield[1]);
661 # modify the subfield if it's a different string
662 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
663 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
664 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
673 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
674 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
675 # if nothing to change, don't waste time...
676 if ($oldrecord eq $record) {
677 # warn "nothing to change";
680 # warn "MARCmoditem : ".$record->as_formatted;
681 # warn "OLD : ".$oldrecord->as_formatted;
683 # otherwise, skip through each subfield...
684 my @fields = $record->fields();
685 # search old MARC item
686 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=?");
687 $sth2->execute($bibid,$itemnumber);
688 my ($tagorder) = $sth2->fetchrow_array();
689 foreach my $field (@fields) {
690 my $oldfield = $oldrecord->field($field->tag());
691 my @subfields=$field->subfields();
693 foreach my $subfield (@subfields) {
695 # warn "compare : $oldfield".$oldfield->subfield(@$subfield[0]);
696 if ($oldfield eq 0 or (length($oldfield->subfield(@$subfield[0])) ==0) ) {
697 # just adding datas...
698 # warn "addfield : / $subfieldorder / @$subfield[0] - @$subfield[1]";
699 # warn "NEW subfield : $bibid,".$field->tag().",".$tagorder.",".@$subfield[0].",".$subfieldorder.",".@$subfield[1].")";
700 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
701 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
703 # warn "modfield : / $subfieldorder / @$subfield[0] - @$subfield[1]";
704 # modify he subfield if it's a different string
705 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
706 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
707 # warn "changing : $subfieldid, $bibid,".$field->tag(),",$tagorder,@$subfield[0],@$subfield[1],$subfieldorder";
708 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
711 warn "nothing to change : ".$oldfield->subfield(@$subfield[0]);
719 sub MARCmodsubfield {
720 # Subroutine changes a subfield value given a subfieldid.
721 my ($dbh, $subfieldid, $subfieldvalue )=@_;
722 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
723 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
724 $sth1->execute($subfieldid);
725 my ($oldvaluebloblink)=$sth1->fetchrow;
728 # if too long, use a bloblink
729 if (length($subfieldvalue)>255 ) {
730 # if already a bloblink, update it, otherwise, insert a new one.
731 if ($oldvaluebloblink) {
732 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
733 $sth->execute($subfieldvalue,$oldvaluebloblink);
735 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
736 $sth->execute($subfieldvalue);
737 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
739 my ($res)=$sth->fetchrow;
740 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
741 $sth->execute($subfieldid);
744 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
745 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
746 $sth->execute($subfieldvalue, $subfieldid);
748 $dbh->do("unlock tables");
750 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
751 $sth->execute($subfieldid);
752 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
754 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
755 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
756 return($subfieldid, $subfieldvalue);
759 sub MARCfindsubfield {
760 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
764 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
765 if ($subfieldvalue) {
766 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
768 if ($subfieldorder<1) {
771 $query .= " and subfieldorder=$subfieldorder";
773 my $sti=$dbh->prepare($query);
774 $sti->execute($bibid,$tag, $subfieldcode);
775 while (($subfieldid) = $sti->fetchrow) {
777 $lastsubfieldid=$subfieldid;
779 if ($resultcounter>1) {
780 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
781 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
784 return $lastsubfieldid;
788 sub MARCfindsubfieldid {
789 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
790 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
791 where bibid=? and tag=? and tagorder=?
792 and subfieldcode=? and subfieldorder=?");
793 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
794 my ($res) = $sth->fetchrow;
796 $sth=$dbh->prepare("select subfieldid from marc_subfield_table
797 where bibid=? and tag=? and tagorder=?
798 and subfieldcode=?");
799 $sth->execute($bibid,$tag,$tagorder,$subfield);
800 ($res) = $sth->fetchrow;
805 sub MARCdelsubfield {
806 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
807 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
808 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
809 tag='$tag' and tagorder='$tagorder'
810 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
815 # delete a biblio for a $bibid
816 my ($dbh,$bibid) = @_;
817 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
818 $dbh->do("delete from marc_biblio where bibid='$bibid'");
821 sub MARCkoha2marcBiblio {
822 # this function builds partial MARC::Record from the old koha-DB fields
823 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
824 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
825 my $record = MARC::Record->new();
826 #--- if bibid, then retrieve old-style koha data
827 if ($biblionumber>0) {
828 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
829 from biblio where biblionumber=?");
830 $sth2->execute($biblionumber);
831 my $row=$sth2->fetchrow_hashref;
833 foreach $code (keys %$row) {
835 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
839 #--- if biblioitem, then retrieve old-style koha data
840 if ($biblioitemnumber>0) {
841 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
842 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
843 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
845 WHERE biblionumber=? and biblioitemnumber=?
847 $sth2->execute($biblionumber,$biblioitemnumber);
848 my $row=$sth2->fetchrow_hashref;
850 foreach $code (keys %$row) {
852 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
857 # TODO : retrieve notes, additionalauthors
860 sub MARCkoha2marcItem {
861 # this function builds partial MARC::Record from the old koha-DB fields
862 my ($dbh,$biblionumber,$itemnumber) = @_;
863 # my $dbh=&C4Connect;
864 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
865 my $record = MARC::Record->new();
866 #--- if item, then retrieve old-style koha data
868 # print STDERR "prepare $biblionumber,$itemnumber\n";
869 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
870 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
871 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
872 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
874 WHERE itemnumber=?");
875 $sth2->execute($itemnumber);
876 my $row=$sth2->fetchrow_hashref;
878 foreach $code (keys %$row) {
880 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
885 # TODO : retrieve notes, additionalauthors
888 sub MARCkoha2marcSubtitle {
889 # this function builds partial MARC::Record from the old koha-DB fields
890 my ($dbh,$bibnum,$subtitle) = @_;
891 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
892 my $record = MARC::Record->new();
893 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
897 sub MARCkoha2marcOnefield {
898 my ($sth,$record,$kohafieldname,$value)=@_;
901 $sth->execute($kohafieldname);
902 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
903 if ($record->field($tagfield)) {
904 my $tag =$record->field($tagfield);
906 $tag->add_subfields($tagsubfield,$value);
907 $record->delete_field($tag);
908 $record->add_fields($tag);
911 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
918 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
919 my $prevtag = @$rtags[0];
920 my $record = MARC::Record->new();
922 for (my $i=0; $i< @$rtags; $i++) {
923 # rebuild MARC::Record
924 if (@$rtags[$i] ne $prevtag) {
928 $indicators{$prevtag}.=' ';
929 my $field = MARC::Field->new( $prevtag, substr($indicators{$prevtag},0,1),substr($indicators{$prevtag},1,1), %subfieldlist);
930 $record->add_fields($field);
931 $prevtag = @$rtags[$i];
933 %subfieldlist->{@$rsubfields[$i]} = @$rvalues[$i];
935 # if (%subfieldlist->{@$rsubfields[$i]}) {
936 # %subfieldlist->{@$rsubfields[$i]} .= '|';
938 %subfieldlist->{@$rsubfields[$i]} .=@$rvalues[$i];
939 $prevtag= @$rtags[$i];
942 # the last has not been included inside the loop... do it now !
943 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
944 $record->add_fields($field);
949 my ($dbh,$record) = @_;
950 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
952 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
955 # print STDERR $record->as_formatted;
956 while (($field)=$sth2->fetchrow) {
957 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
959 $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
961 while (($field)=$sth2->fetchrow) {
962 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
964 $sth2=$dbh->prepare("SHOW COLUMNS from items");
966 while (($field)=$sth2->fetchrow) {
967 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
969 # additional authors : specific
970 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
974 sub MARCmarc2kohaOneField {
975 # FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
976 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
977 # warn "kohatable / $kohafield / $result / ";
981 $sth->execute($kohatable.".".$kohafield);
982 ($tagfield,$subfield) = $sth->fetchrow;
983 foreach my $field ($record->field($tagfield)) {
984 if ($field->subfield($subfield)) {
985 if ($result->{$kohafield}) {
986 $result->{$kohafield} .= " | ".$field->subfield($subfield);
988 $result->{$kohafield}=$field->subfield($subfield);
996 # split a subfield string and adds it into the word table.
998 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
999 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
1000 my @words = split / /,$sentence;
1001 my $stopwords= C4::Context->stopwords;
1002 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
1003 values (?,?,?,?,?,?,soundex(?))");
1004 foreach my $word (@words) {
1005 # we record only words longer than 2 car and not in stopwords hash
1006 if (length($word)>1 and !($stopwords->{uc($word)})) {
1007 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
1009 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";
1016 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
1017 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
1018 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
1019 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
1024 # NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW
1027 # all the following subs are useful to manage MARC-DB with complete MARC records.
1028 # it's used with marcimport, and marc management tools
1032 =item (oldbibnum,$oldbibitemnum) = NEWnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
1034 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
1035 are builded from the MARC::Record. If they are passed, they are used.
1037 =item NEWnewitem($dbh,$olditem);
1039 adds an item in the db. $olditem is a old-db hash.
1044 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
1045 # note $oldbiblio and $oldbiblioitem are not mandatory.
1046 # if not present, they will be builded from $record with MARCmarc2koha function
1047 if (($oldbiblio) and not($oldbiblioitem)) {
1048 print STDERR "NEWnewbiblio : missing parameter\n";
1049 print "NEWnewbiblio : missing parameter : contact koha development team\n";
1055 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
1056 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
1057 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
1059 my $olddata = MARCmarc2koha($dbh,$record);
1060 $oldbibnum = OLDnewbiblio($dbh,$olddata);
1061 $olddata->{'biblionumber'} = $oldbibnum;
1062 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
1064 # we must add bibnum and bibitemnum in MARC::Record...
1065 # we build the new field with biblionumber and biblioitemnumber
1066 # we drop the original field
1067 # we add the new builded field.
1068 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
1069 # (steve and paul : thinks 090 is a good choice)
1070 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
1071 $sth->execute("biblio.biblionumber");
1072 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
1073 $sth->execute("biblioitems.biblioitemnumber");
1074 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
1075 if ($tagfield1 != $tagfield2) {
1076 print STDERR "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1077 print "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1080 my $newfield = MARC::Field->new( $tagfield1,'','',
1081 "$tagsubfield1" => $oldbibnum,
1082 "$tagsubfield2" => $oldbibitemnum);
1083 # drop old field and create new one...
1084 my $old_field = $record->field($tagfield1);
1085 $record->delete_field($old_field);
1086 $record->add_fields($newfield);
1087 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
1088 return ($bibid,$oldbibnum,$oldbibitemnum );
1092 my ($dbh,$record,$bibid) =@_;
1093 &MARCmodbiblio($dbh,$record,$bibid);
1094 my $oldbiblio = MARCmarc2koha($dbh,$record);
1095 my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
1096 OLDmodbibitem($dbh,$oldbiblio);
1102 my ($dbh, $record,$bibid) = @_;
1103 # add item in old-DB
1104 my $item = &MARCmarc2koha($dbh,$record);
1105 # needs old biblionumber and biblioitemnumber
1106 $item->{'biblionumber'} = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
1107 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
1108 $sth->execute($item->{'biblionumber'});
1109 ($item->{'biblioitemnumber'}) = $sth->fetchrow;
1110 my ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{barcode});
1111 # add itemnumber to MARC::Record before adding the item.
1112 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
1113 &MARCkoha2marcOnefield($sth,$record,"items.itemnumber",$itemnumber);
1115 my $bib = &MARCadditem($dbh,$record,$item->{'biblionumber'});
1119 my ($dbh,$record,$bibid,$itemnumber,$delete) = @_;
1120 &MARCmoditem($dbh,$record,$bibid,$itemnumber,$delete);
1121 my $olditem = MARCmarc2koha($dbh,$record);
1122 OLDmoditem($dbh,$olditem);
1127 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
1131 =item $biblionumber = OLDnewbiblio($dbh,$biblio);
1133 adds a record in biblio table. Datas are in the hash $biblio.
1135 =item $biblionumber = OLDmodbiblio($dbh,$biblio);
1137 modify a record in biblio table. Datas are in the hash $biblio.
1139 =item OLDmodsubtitle($dbh,$bibnum,$subtitle);
1141 modify subtitles in bibliosubtitle table.
1143 =item OLDmodaddauthor($dbh,$bibnum,$author);
1145 adds or modify additional authors
1146 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1148 =item $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1150 modify/adds subjects
1152 =item OLDmodbibitem($dbh, $biblioitem);
1156 =item OLDmodnote($dbh,$bibitemnum,$note
1158 modify a note for a biblioitem
1160 =item OLDnewbiblioitem($dbh,$biblioitem);
1162 adds a biblioitem ($biblioitem is a hash with the values)
1164 =item OLDnewsubject($dbh,$bibnum);
1168 =item OLDnewsubtitle($dbh,$bibnum,$subtitle);
1170 create a new subtitle
1172 =item ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1174 create a item. $item is a hash and $barcode the barcode.
1176 =item OLDmoditem($dbh,$item);
1180 =item OLDdelitem($dbh,$itemnum);
1184 =item OLDdeletebiblioitem($dbh,$biblioitemnumber);
1186 deletes a biblioitem
1187 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1189 =item OLDdelbiblio($dbh,$biblio);
1196 my ($dbh,$biblio) = @_;
1197 # my $dbh = &C4Connect;
1198 my $query = "Select max(biblionumber) from biblio";
1199 my $sth = $dbh->prepare($query);
1201 my $data = $sth->fetchrow_arrayref;
1202 my $bibnum = $$data[0] + 1;
1205 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1206 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1207 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
1208 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
1209 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1210 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1211 if ($biblio->{'seriestitle'}) { $series = 1 };
1214 $query = "insert into biblio set
1215 biblionumber = $bibnum,
1216 title = $biblio->{'title'},
1217 author = $biblio->{'author'},
1218 copyrightdate = $biblio->{'copyright'},
1220 seriestitle = $biblio->{'seriestitle'},
1221 notes = $biblio->{'notes'},
1222 abstract = $biblio->{'abstract'}";
1224 $sth = $dbh->prepare($query);
1233 my ($dbh,$biblio) = @_;
1234 # my $dbh = C4Connect;
1238 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1239 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1240 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1241 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
1242 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
1243 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
1244 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
1245 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1247 $query = "Update biblio set
1248 title = $biblio->{'title'},
1249 author = $biblio->{'author'},
1250 abstract = $biblio->{'abstract'},
1251 copyrightdate = $biblio->{'copyrightdate'},
1252 seriestitle = $biblio->{'seriestitle'},
1253 serial = $biblio->{'serial'},
1254 unititle = $biblio->{'unititle'},
1255 notes = $biblio->{'notes'}
1256 where biblionumber = $biblio->{'biblionumber'}";
1257 $sth = $dbh->prepare($query);
1261 return($biblio->{'biblionumber'});
1264 sub OLDmodsubtitle {
1265 my ($dbh,$bibnum, $subtitle) = @_;
1266 # my $dbh = C4Connect;
1267 my $query = "update bibliosubtitle set
1268 subtitle = '$subtitle'
1269 where biblionumber = $bibnum";
1270 my $sth = $dbh->prepare($query);
1278 sub OLDmodaddauthor {
1279 my ($dbh,$bibnum, $author) = @_;
1280 # my $dbh = C4Connect;
1281 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1282 my $sth = $dbh->prepare($query);
1287 if ($author ne '') {
1288 $query = "Insert into additionalauthors set
1290 biblionumber = '$bibnum'";
1291 $sth = $dbh->prepare($query);
1297 } # sub modaddauthor
1301 my ($dbh,$bibnum, $force, @subject) = @_;
1302 # my $dbh = C4Connect;
1303 my $count = @subject;
1305 for (my $i = 0; $i < $count; $i++) {
1306 $subject[$i] =~ s/^ //g;
1307 $subject[$i] =~ s/ $//g;
1308 my $query = "select * from catalogueentry
1309 where entrytype = 's'
1310 and catalogueentry = '$subject[$i]'";
1311 my $sth = $dbh->prepare($query);
1314 if (my $data = $sth->fetchrow_hashref) {
1316 if ($force eq $subject[$i]) {
1317 # subject not in aut, chosen to force anway
1318 # so insert into cataloguentry so its in auth file
1319 $query = "Insert into catalogueentry
1320 (entrytype,catalogueentry)
1321 values ('s','$subject[$i]')";
1322 my $sth2 = $dbh->prepare($query);
1327 $error = "$subject[$i]\n does not exist in the subject authority file";
1328 $query = "Select * from catalogueentry
1329 where entrytype = 's'
1330 and (catalogueentry like '$subject[$i] %'
1331 or catalogueentry like '% $subject[$i] %'
1332 or catalogueentry like '% $subject[$i]')";
1333 my $sth2 = $dbh->prepare($query);
1336 while (my $data = $sth2->fetchrow_hashref) {
1337 $error .= "<br>$data->{'catalogueentry'}";
1345 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1346 my $sth = $dbh->prepare($query);
1349 for (my $i = 0; $i < $count; $i++) {
1350 $sth = $dbh->prepare("Insert into bibliosubject
1351 values ('$subject[$i]', $bibnum)");
1363 my ($dbh,$biblioitem) = @_;
1364 # my $dbh = C4Connect;
1367 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1368 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1369 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1370 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1371 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1372 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1373 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1374 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1375 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1376 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1377 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1378 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1379 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1380 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1382 $query = "Update biblioitems set
1383 itemtype = $biblioitem->{'itemtype'},
1384 url = $biblioitem->{'url'},
1385 isbn = $biblioitem->{'isbn'},
1386 publishercode = $biblioitem->{'publishercode'},
1387 publicationyear = $biblioitem->{'publicationyear'},
1388 classification = $biblioitem->{'classification'},
1389 dewey = $biblioitem->{'dewey'},
1390 subclass = $biblioitem->{'subclass'},
1391 illus = $biblioitem->{'illus'},
1392 pages = $biblioitem->{'pages'},
1393 volumeddesc = $biblioitem->{'volumeddesc'},
1394 notes = $biblioitem->{'notes'},
1395 size = $biblioitem->{'size'},
1396 place = $biblioitem->{'place'}
1397 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1405 my ($dbh,$bibitemnum,$note)=@_;
1406 # my $dbh=C4Connect;
1407 my $query="update biblioitems set notes='$note' where
1408 biblioitemnumber='$bibitemnum'";
1409 my $sth=$dbh->prepare($query);
1415 sub OLDnewbiblioitem {
1416 my ($dbh,$biblioitem) = @_;
1417 # my $dbh = C4Connect;
1418 my $query = "Select max(biblioitemnumber) from biblioitems";
1419 my $sth = $dbh->prepare($query);
1424 $data = $sth->fetchrow_arrayref;
1425 $bibitemnum = $$data[0] + 1;
1429 $sth = $dbh->prepare("insert into biblioitems set
1430 biblioitemnumber = ?, biblionumber = ?,
1431 volume = ?, number = ?,
1432 classification = ?, itemtype = ?,
1434 issn = ?, dewey = ?,
1435 subclass = ?, publicationyear = ?,
1436 publishercode = ?, volumedate = ?,
1437 volumeddesc = ?, illus = ?,
1438 pages = ?, notes = ?,
1440 marc = ?, place = ?");
1441 $sth->execute($bibitemnum, $biblioitem->{'biblionumber'},
1442 $biblioitem->{'volume'}, $biblioitem->{'number'},
1443 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
1444 $biblioitem->{'url'}, $biblioitem->{'isbn'},
1445 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
1446 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
1447 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
1448 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
1449 $biblioitem->{'pages'}, $biblioitem->{'notes'},
1450 $biblioitem->{'size'}, $biblioitem->{'lccn'},
1451 $biblioitem->{'marc'}, $biblioitem->{'place'});
1454 return($bibitemnum);
1458 my ($dbh,$bibnum)=@_;
1459 # my $dbh=C4Connect;
1460 my $query="insert into bibliosubject (biblionumber) values
1462 my $sth=$dbh->prepare($query);
1469 sub OLDnewsubtitle {
1470 my ($dbh,$bibnum, $subtitle) = @_;
1471 # my $dbh = C4Connect;
1472 $subtitle = $dbh->quote($subtitle);
1473 my $query = "insert into bibliosubtitle set
1474 biblionumber = $bibnum,
1475 subtitle = $subtitle";
1476 my $sth = $dbh->prepare($query);
1486 my ($dbh,$item, $barcode) = @_;
1487 # my $dbh = C4Connect;
1488 my $query = "Select max(itemnumber) from items";
1489 my $sth = $dbh->prepare($query);
1495 $data = $sth->fetchrow_hashref;
1496 $itemnumber = $data->{'max(itemnumber)'} + 1;
1499 $sth=$dbh->prepare("Insert into items set
1500 itemnumber = ?, biblionumber = ?,
1501 biblioitemnumber = ?, barcode = ?,
1502 booksellerid = ?, dateaccessioned = NOW(),
1503 homebranch = ?, holdingbranch = ?,
1504 price = ?, replacementprice = ?,
1505 replacementpricedate = NOW(), itemnotes = ?,
1508 $sth->execute($itemnumber, $item->{'biblionumber'},
1509 $item->{'biblioitemnumber'},$barcode,
1510 $item->{'booksellerid'},
1511 $item->{'homebranch'},$item->{'homebranch'},
1512 $item->{'price'},$item->{'replacementprice'},
1513 $item->{'itemnotes'},$item->{'loan'});
1516 if (defined $sth->errstr) {
1517 $error .= $sth->errstr;
1522 return($itemnumber,$error);
1526 my ($dbh,$item) = @_;
1527 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1528 # my $dbh=C4Connect;
1529 $item->{'itemnum'}=$item->{'itemnumber'} unless $item->{'itemnum'};
1530 my $query="update items set barcode='$item->{'barcode'}',itemnotes='$item->{'notes'}'
1531 where itemnumber=$item->{'itemnum'}";
1532 if ($item->{'barcode'} eq ''){
1533 $query="update items set notforloan=$item->{'loan'} where itemnumber=$item->{'itemnum'}";
1535 if ($item->{'lost'} ne ''){
1536 $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1537 barcode='$item->{'barcode'}',
1538 itemnotes='$item->{'notes'}',
1539 homebranch='$item->{'homebranch'}',
1540 itemlost='$item->{'lost'}',
1541 wthdrawn='$item->{'wthdrawn'}'
1542 where itemnumber=$item->{'itemnum'}";
1544 if ($item->{'replacement'} ne ''){
1545 $query=~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1547 my $sth=$dbh->prepare($query);
1554 my ($dbh,$itemnum)=@_;
1555 # my $dbh=C4Connect;
1556 my $query="select * from items where itemnumber=$itemnum";
1557 my $sth=$dbh->prepare($query);
1559 my @data=$sth->fetchrow_array;
1561 $query="Insert into deleteditems values (";
1562 foreach my $temp (@data){
1563 $query .= "'$temp',";
1567 $sth=$dbh->prepare($query);
1570 $query = "Delete from items where itemnumber=$itemnum";
1571 $sth=$dbh->prepare($query);
1577 sub OLDdeletebiblioitem {
1578 my ($dbh,$biblioitemnumber) = @_;
1579 # my $dbh = C4Connect;
1580 my $query = "Select * from biblioitems
1581 where biblioitemnumber = $biblioitemnumber";
1582 my $sth = $dbh->prepare($query);
1587 if (@results = $sth->fetchrow_array) {
1588 $query = "Insert into deletedbiblioitems values (";
1589 foreach my $value (@results) {
1590 $value = $dbh->quote($value);
1591 $query .= "$value,";
1594 $query =~ s/\,$/\)/;
1597 $query = "Delete from biblioitems
1598 where biblioitemnumber = $biblioitemnumber";
1602 # Now delete all the items attached to the biblioitem
1603 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1604 $sth = $dbh->prepare($query);
1606 while (@results = $sth->fetchrow_array) {
1607 $query = "Insert into deleteditems values (";
1608 foreach my $value (@results) {
1609 $value = $dbh->quote($value);
1610 $query .= "$value,";
1612 $query =~ s/\,$/\)/;
1616 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1619 } # sub deletebiblioitem
1622 my ($dbh,$biblio)=@_;
1623 # my $dbh=C4Connect;
1624 my $query="select * from biblio where biblionumber=$biblio";
1625 my $sth=$dbh->prepare($query);
1627 if (my @data=$sth->fetchrow_array){
1629 $query="Insert into deletedbiblio values (";
1630 foreach my $temp (@data){
1631 $temp=~ s/\'/\\\'/g;
1632 $query .= "'$temp',";
1636 $sth=$dbh->prepare($query);
1639 $query = "Delete from biblio where biblionumber=$biblio";
1640 $sth=$dbh->prepare($query);
1656 my $dbh = C4::Context->dbh;
1657 my $query="Select count(*) from items where biblionumber=$biblio";
1659 my $sth=$dbh->prepare($query);
1661 my $data=$sth->fetchrow_hashref;
1663 return($data->{'count(*)'});
1668 ($order, $ordernumber) = &getorder($biblioitemnumber, $biblionumber);
1670 Looks up the order with the given biblionumber and biblioitemnumber.
1672 Returns a two-element array. C<$ordernumber> is the order number.
1673 C<$order> is a reference-to-hash describing the order; its keys are
1674 fields from the biblio, biblioitems, aqorders, and aqorderbreakdown
1675 tables of the Koha database.
1679 # FIXME - This is effectively identical to &C4::Catalogue::getorder.
1680 # Pick one and stick with it.
1683 my $dbh = C4::Context->dbh;
1684 my $query="Select ordernumber
1686 where biblionumber=? and biblioitemnumber=?";
1687 my $sth=$dbh->prepare($query);
1688 $sth->execute($bib,$bi);
1689 # FIXME - Use fetchrow_array(), since we're only interested in the one
1691 my $ordnum=$sth->fetchrow_hashref;
1693 my $order=getsingleorder($ordnum->{'ordernumber'});
1695 return ($order,$ordnum->{'ordernumber'});
1698 =item getsingleorder
1700 $order = &getsingleorder($ordernumber);
1702 Looks up an order by order number.
1704 Returns a reference-to-hash describing the order. The keys of
1705 C<$order> are fields from the biblio, biblioitems, aqorders, and
1706 aqorderbreakdown tables of the Koha database.
1710 # FIXME - This is effectively identical to
1711 # &C4::Catalogue::getsingleorder.
1712 # Pick one and stick with it.
1713 sub getsingleorder {
1715 my $dbh = C4::Context->dbh;
1716 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1717 where aqorders.ordernumber=?
1718 and biblio.biblionumber=aqorders.biblionumber and
1719 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1720 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1721 my $sth=$dbh->prepare($query);
1722 $sth->execute($ordnum);
1723 my $data=$sth->fetchrow_hashref;
1730 my $dbh = C4::Context->dbh;
1731 my $bibnum=OLDnewbiblio($dbh,$biblio);
1738 $biblionumber = &modbiblio($biblio);
1740 Update a biblio record.
1742 C<$biblio> is a reference-to-hash whose keys are the fields in the
1743 biblio table in the Koha database. All fields must be present, not
1744 just the ones you wish to change.
1746 C<&modbiblio> updates the record defined by
1747 C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
1749 C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
1756 my $dbh = C4::Context->dbh;
1757 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1758 return($biblionumber);
1764 &modsubtitle($biblionumber, $subtitle);
1766 Sets the subtitle of a book.
1768 C<$biblionumber> is the biblionumber of the book to modify.
1770 C<$subtitle> is the new subtitle.
1775 my ($bibnum, $subtitle) = @_;
1776 my $dbh = C4::Context->dbh;
1777 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1782 &modaddauthor($biblionumber, $author);
1784 Replaces all additional authors for the book with biblio number
1785 C<$biblionumber> with C<$author>. If C<$author> is the empty string,
1786 C<&modaddauthor> deletes all additional authors.
1791 my ($bibnum, $author) = @_;
1792 my $dbh = C4::Context->dbh;
1793 &OLDmodaddauthor($dbh,$bibnum,$author);
1794 } # sub modaddauthor
1798 $error = &modsubject($biblionumber, $force, @subjects);
1800 $force - a subject to force
1802 $error - Error message, or undef if successful.
1807 my ($bibnum, $force, @subject) = @_;
1808 my $dbh = C4::Context->dbh;
1809 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1814 my ($biblioitem) = @_;
1815 my $dbh = C4::Context->dbh;
1816 &OLDmodbibitem($dbh,$biblioitem);
1817 my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
1818 &MARCmodbiblio($dbh,$biblioitem->{biblionumber},0,$MARCbibitem);
1822 my ($bibitemnum,$note)=@_;
1823 my $dbh = C4::Context->dbh;
1824 &OLDmodnote($dbh,$bibitemnum,$note);
1828 my ($biblioitem) = @_;
1829 my $dbh = C4::Context->dbh;
1830 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1831 # print STDERR "bibitemnum : $bibitemnum\n";
1832 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1833 # print STDERR $MARCbiblio->as_formatted();
1834 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1835 return($bibitemnum);
1840 my $dbh = C4::Context->dbh;
1841 &OLDnewsubject($dbh,$bibnum);
1845 my ($bibnum, $subtitle) = @_;
1846 my $dbh = C4::Context->dbh;
1847 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1851 my ($item, @barcodes) = @_;
1852 my $dbh = C4::Context->dbh;
1856 foreach my $barcode (@barcodes) {
1857 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1859 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1860 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1867 my $dbh = C4::Context->dbh;
1868 &OLDmoditem($dbh,$item);
1869 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1870 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1871 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1875 my ($count,@barcodes)=@_;
1876 my $dbh = C4::Context->dbh;
1878 for (my $i=0;$i<$count;$i++){
1879 $barcodes[$i]=uc $barcodes[$i];
1880 my $query="Select * from items where barcode='$barcodes[$i]'";
1881 my $sth=$dbh->prepare($query);
1883 if (my $data=$sth->fetchrow_hashref){
1884 $error.=" Duplicate Barcode: $barcodes[$i]";
1892 my ($bibitemnum)=@_;
1893 my $dbh = C4::Context->dbh;
1894 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1895 my $sth=$dbh->prepare($query);
1897 my $data=$sth->fetchrow_hashref;
1899 return($data->{'count(*)'});
1904 my $dbh = C4::Context->dbh;
1905 &OLDdelitem($dbh,$itemnum);
1908 sub deletebiblioitem {
1909 my ($biblioitemnumber) = @_;
1910 my $dbh = C4::Context->dbh;
1911 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1912 } # sub deletebiblioitem
1917 my $dbh = C4::Context->dbh;
1918 &OLDdelbiblio($dbh,$biblio);
1922 my $dbh = C4::Context->dbh;
1923 my $query = "select * from itemtypes";
1924 my $sth = $dbh->prepare($query);
1925 # || die "Cannot prepare $query" . $dbh->errstr;
1930 # || die "Cannot execute $query\n" . $sth->errstr;
1931 while (my $data = $sth->fetchrow_hashref) {
1932 $results[$count] = $data;
1937 return($count, @results);
1938 } # sub getitemtypes
1941 my ($biblionumber) = @_;
1942 my $dbh = C4::Context->dbh;
1943 my $query = "Select * from biblio where biblionumber = $biblionumber";
1944 my $sth = $dbh->prepare($query);
1945 # || die "Cannot prepare $query\n" . $dbh->errstr;
1950 # || die "Cannot execute $query\n" . $sth->errstr;
1951 while (my $data = $sth->fetchrow_hashref) {
1952 $results[$count] = $data;
1957 return($count, @results);
1961 my ($biblioitemnum) = @_;
1962 my $dbh = C4::Context->dbh;
1963 my $query = "Select * from biblioitems where
1964 biblioitemnumber = $biblioitemnum";
1965 my $sth = $dbh->prepare($query);
1971 while (my $data = $sth->fetchrow_hashref) {
1972 $results[$count] = $data;
1977 return($count, @results);
1978 } # sub getbiblioitem
1980 sub getbiblioitembybiblionumber {
1981 my ($biblionumber) = @_;
1982 my $dbh = C4::Context->dbh;
1983 my $query = "Select * from biblioitems where biblionumber =
1985 my $sth = $dbh->prepare($query);
1991 while (my $data = $sth->fetchrow_hashref) {
1992 $results[$count] = $data;
1997 return($count, @results);
2000 sub getitemsbybiblioitem {
2001 my ($biblioitemnum) = @_;
2002 my $dbh = C4::Context->dbh;
2003 my $query = "Select * from items, biblio where
2004 biblio.biblionumber = items.biblionumber and biblioitemnumber
2006 my $sth = $dbh->prepare($query);
2007 # || die "Cannot prepare $query\n" . $dbh->errstr;
2012 # || die "Cannot execute $query\n" . $sth->errstr;
2013 while (my $data = $sth->fetchrow_hashref) {
2014 $results[$count] = $data;
2019 return($count, @results);
2020 } # sub getitemsbybiblioitem
2024 my $dbh = C4::Context->dbh;
2030 $isbn = $dbh->quote($isbn);
2031 $query = "Select distinct biblio.* from biblio, biblioitems where
2032 biblio.biblionumber = biblioitems.biblionumber
2034 $sth = $dbh->prepare($query);
2037 while (my $data = $sth->fetchrow_hashref) {
2038 $results[$count] = $data;
2043 return($count, @results);
2047 # At the moment this is just a straight copy of the subject code. Needs heavy
2048 # modification to work for additional authors, obviously.
2049 # Check for additional author changes
2051 # my $newadditionalauthor='';
2052 # my $additionalauthors;
2053 # foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
2054 # $additionalauthors->{$newadditionalauthor}=1;
2055 # if ($origadditionalauthors->{$newadditionalauthor}) {
2056 # $additionalauthors->{$newadditionalauthor}=2;
2058 # my $q_newadditionalauthor=$dbh->quote($newadditionalauthor);
2059 # my $sth=$dbh->prepare("insert into biblioadditionalauthors (additionalauthor,biblionumber) values ($q_newadditionalauthor, $biblionumber)");
2061 # logchange('kohadb', 'add', 'biblio', 'additionalauthor', $newadditionalauthor);
2063 # $subfields->{1}->{'Subfield_Mark'}='a';
2064 # $subfields->{1}->{'Subfield_Value'}=$newadditionalauthor;
2067 # foreach $Record_ID (@marcrecords) {
2068 # addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
2069 # logchange('marc', 'add', $Record_ID, '650', 'a', $newadditionalauthor);
2073 # my $origadditionalauthor;
2074 # foreach $origadditionalauthor (keys %$origadditionalauthors) {
2075 # if ($additionalauthors->{$origadditionalauthor} == 1) {
2076 # my $q_origadditionalauthor=$dbh->quote($origadditionalauthor);
2077 # logchange('kohadb', 'delete', 'biblio', '$biblionumber', 'additionalauthor', $origadditionalauthor);
2078 # my $sth=$dbh->prepare("delete from biblioadditionalauthors where biblionumber=$biblionumber and additionalauthor=$q_origadditionalauthor");
2088 # Subroutine to log changes to databases
2089 # Eventually, this subroutine will be used to create a log of all changes made,
2090 # with the possibility of "undo"ing some changes
2092 if ($database eq 'kohadb') {
2098 # print STDERR "KOHA: $type $section $item $original $new\n";
2099 } elsif ($database eq 'marc') {
2101 my $Record_ID=shift;
2104 my $subfield_ID=shift;
2107 # print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2111 #------------------------------------------------
2114 #---------------------------------------
2115 # Find a biblio entry, or create a new one if it doesn't exist.
2116 # If a "subtitle" entry is in hash, add it to subtitle table
2117 sub getoraddbiblio {
2121 # FIXME - Unused argument
2122 $biblio, # hash ref to fields
2133 $dbh = C4::Context->dbh;
2135 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2136 $sth=$dbh->prepare("select biblionumber
2138 where title=? and author=?
2139 and copyrightdate=? and seriestitle=?");
2141 $biblio->{title}, $biblio->{author},
2142 $biblio->{copyright}, $biblio->{seriestitle} );
2144 ($biblionumber) = $sth->fetchrow;
2145 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2147 # Doesn't exist. Add new one.
2148 print "<PRE>Adding biblio</PRE>\n" if $debug;
2149 ($biblionumber,$error)=&newbiblio($biblio);
2150 if ( $biblionumber ) {
2151 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
2152 if ( $biblio->{subtitle} ) {
2153 &newsubtitle($biblionumber,$biblio->{subtitle} );
2156 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2160 return $biblionumber,$error;
2162 } # sub getoraddbiblio
2164 END { } # module clean-up code here (global destructor)
2170 Koha Developement team <info@koha.org>
2172 Paul POULAIN paul.poulain@free.fr