4 # Revision 1.34 2003/01/28 14:50:04 tipaul
5 # fixing MARCmodbiblio API and reindenting code
7 # Revision 1.33 2003/01/23 12:22:37 tipaul
8 # adding char_decode to decode MARC21 or UNIMARC extended chars
10 # Revision 1.32 2002/12/16 15:08:50 tipaul
11 # small but important bugfix (fixes a problem in export)
13 # Revision 1.31 2002/12/13 16:22:04 tipaul
14 # 1st draft of marc export
16 # Revision 1.30 2002/12/12 21:26:35 tipaul
17 # YAB ! (Yet Another Bugfix) => related to biblio modif
18 # (some warning cleaning too)
20 # Revision 1.29 2002/12/12 16:35:00 tipaul
21 # adding authentification with Auth.pm and
22 # MAJOR BUGFIX on marc biblio modification
24 # Revision 1.28 2002/12/10 13:30:03 tipaul
25 # fugfixes from Dombes Abbey work
27 # Revision 1.27 2002/11/19 12:36:16 tipaul
29 # various bugfixes, improvments, and migration from acquisition.pm to biblio.pm
31 # Revision 1.26 2002/11/12 15:58:43 tipaul
34 # * 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)
36 # Revision 1.25 2002/10/25 10:58:26 tipaul
38 # * bugfixes and improvements
40 # Revision 1.24 2002/10/24 12:09:01 arensb
41 # Fixed "no title" warning when generating HTML documentation from POD.
43 # Revision 1.23 2002/10/16 12:43:08 arensb
44 # Added some FIXME comments.
46 # Revision 1.22 2002/10/15 13:39:17 tipaul
47 # removing Acquisition.pm
48 # deleting unused code in biblio.pm, rewriting POD and answering most FIXME comments
50 # Revision 1.21 2002/10/13 11:34:14 arensb
51 # Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
52 # Thus, $x = $x+2 becomes $x += 2, and so forth.
54 # Revision 1.20 2002/10/13 08:28:32 arensb
55 # Deleted unused variables.
56 # Removed trailing whitespace.
58 # Revision 1.19 2002/10/13 05:56:10 arensb
59 # Added some FIXME comments.
61 # Revision 1.18 2002/10/11 12:34:53 arensb
62 # Replaced &requireDBI with C4::Context->dbh
64 # Revision 1.17 2002/10/10 14:48:25 tipaul
67 # Revision 1.16 2002/10/07 14:04:26 tipaul
68 # road to 1.3.1 : viewing MARC biblio
70 # Revision 1.15 2002/10/05 09:49:25 arensb
71 # Merged with arensb-context branch: use C4::Context->dbh instead of
72 # &C4Connect, and generally prefer C4::Context over C4::Database.
74 # Revision 1.14 2002/10/03 11:28:18 tipaul
75 # Extending Context.pm to add stopword management and using it in MARC-API.
76 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
78 # Revision 1.13 2002/10/02 16:26:44 tipaul
81 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
82 # Merged in changes from main branch.
84 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
85 # Added a whole mess of FIXME comments.
87 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
88 # Added some missing semicolons.
90 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
91 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
94 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
95 # Added a whole mess of FIXME comments.
97 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
98 # Added some missing semicolons.
100 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
101 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
104 # Revision 1.12 2002/10/01 11:48:51 arensb
105 # Added some FIXME comments, mostly marking duplicate functions.
107 # Revision 1.11 2002/09/24 13:49:26 tipaul
108 # long WAS the road to 1.3.0...
109 # coming VERY SOON NOW...
110 # modifying installer and buildrelease to update the DB
112 # Revision 1.10 2002/09/22 16:50:08 arensb
113 # Added some FIXME comments.
115 # Revision 1.9 2002/09/20 12:57:46 tipaul
116 # long is the road to 1.4.0
117 # * MARCadditem and MARCmoditem now wroks
118 # * various bugfixes in MARC management
119 # !!! 1.3.0 should be released very soon now. Be careful !!!
121 # Revision 1.8 2002/09/10 13:53:52 tipaul
122 # MARC API continued...
124 # * 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)
126 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
128 # Revision 1.7 2002/08/14 18:12:51 tonnesen
129 # Added copyright statement to all .pl and .pm files
131 # Revision 1.6 2002/07/25 13:40:31 tipaul
132 # pod documenting the API.
134 # Revision 1.5 2002/07/24 16:11:37 tipaul
136 # Database.pm and Output.pm are almost not modified (var test...)
138 # Biblio.pm is almost completly rewritten.
140 # WHAT DOES IT ??? ==> END of Hitchcock suspens
142 # 1st, it does... nothing...
143 # 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 ...
145 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
146 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
147 # * 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.
148 # * 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.
149 # 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 ;-)
151 # 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.
152 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
156 # Copyright 2000-2002 Katipo Communications
158 # This file is part of Koha.
160 # Koha is free software; you can redistribute it and/or modify it under the
161 # terms of the GNU General Public License as published by the Free Software
162 # Foundation; either version 2 of the License, or (at your option) any later
165 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
166 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
167 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
169 # You should have received a copy of the GNU General Public License along with
170 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
171 # Suite 330, Boston, MA 02111-1307 USA
179 use vars qw($VERSION @ISA @EXPORT);
181 # set the version for version checking
186 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
187 # as the old-style API and the NEW one are the only public functions.
190 &updateBiblio &updateBiblioItem &updateItem
191 &itemcount &newbiblio &newbiblioitem
192 &modnote &newsubject &newsubtitle
193 &modbiblio &checkitems
194 &newitems &modbibitem
195 &modsubtitle &modsubject &modaddauthor &moditem &countitems
196 &delitem &deletebiblioitem &delbiblio
197 &getitemtypes &getbiblio
198 &getbiblioitembybiblionumber
199 &getbiblioitem &getitemsbybiblioitem
201 &newcompletebiblioitem
203 &MARCfind_oldbiblionumber_from_MARCbibid
204 &MARCfind_MARCbibid_from_oldbiblionumber
205 &MARCfind_marc_from_kohafield
209 &NEWnewbiblio &NEWnewitem
210 &NEWmodbiblio &NEWmoditem
212 &MARCaddbiblio &MARCadditem
213 &MARCmodsubfield &MARCaddsubfield
214 &MARCmodbiblio &MARCmoditem
215 &MARCkoha2marcBiblio &MARCmarc2koha
216 &MARCkoha2marcItem &MARChtml2marc
217 &MARCgetbiblio &MARCgetitem
218 &MARCaddword &MARCdelword
224 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
227 # all the following subs takes a MARC::Record as parameter and manage
228 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
229 # NEWxxx subs (xxx deals with old-DB parameters, the NEWxxx deals with MARC-DB parameter)
233 C4::Biblio - acquisition, catalog management functions
237 move from 1.2 to 1.4 version :
238 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
239 In the 1.4 version, we want to do 2 differents things :
240 - keep populating the old-DB, that has a LOT less datas than MARC
241 - populate the MARC-DB
242 To populate the DBs we have 2 differents sources :
243 - the standard acquisition system (through book sellers), that does'nt use MARC data
244 - the MARC acquisition system, that uses MARC data.
246 Thus, we have 2 differents cases :
247 - 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
248 - 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
250 That's why we need 4 subs :
251 all I<subs beginning by MARC> manage only MARC tables. They manage MARC-DB with MARC::Record parameters
252 all I<subs beginning by OLD> manage only OLD-DB tables. They manage old-DB with old-DB parameters
253 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
254 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.
256 - NEW and old-style API should be used in koha to manage biblio
257 - MARCsubs are divided in 2 parts :
258 * some of them manage MARC parameters. They are heavily used in koha.
259 * some of them manage MARC biblio : they are mostly used by NEW and old-style subs.
260 - OLD are used internally only
262 all subs requires/use $dbh as 1st parameter.
264 I<NEWxxx related subs>
266 all subs requires/use $dbh as 1st parameter.
267 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
269 I<OLDxxx related subs>
271 all subs requires/use $dbh as 1st parameter.
272 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
274 They all are the exact copy of 1.0/1.2 version of the sub without the OLD.
275 The OLDxxx is called by the original xxx sub.
276 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
278 WARNING : there is 1 difference between initialxxx and OLDxxx :
279 the db header $dbh is always passed as parameter to avoid over-DB connexion
285 =item @tagslib = &MARCgettagslib($dbh,1|0);
287 last param is 1 for liblibrarian and 0 for libopac
288 returns a hash with tag/subfield meaning
289 =item ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,$kohafield);
291 finds MARC tag and subfield for a given kohafield
292 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
294 =item $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
296 finds a old-db biblio number for a given MARCbibid number
298 =item $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
300 finds a MARC bibid from a old-db biblionumber
302 =item $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
304 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
306 =item $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
308 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
310 =item $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
312 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
314 =item $olddb = &MARCmarc2koha($dbh,$MARCRecord);
316 builds a hash with old-db datas from a MARC::Record
318 =item &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
320 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
322 =item &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
324 adds a subfield in a biblio (in the MARC tables only).
326 =item $MARCRecord = &MARCgetbiblio($dbh,$bibid);
328 Returns a MARC::Record for the biblio $bibid.
330 =item &MARCmodbiblio($dbh,$bibid,$record,$delete);
332 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
333 if $delete == 1, every field/subfield not found is deleted in the biblio
334 otherwise, only data passed to MARCmodbiblio is managed.
335 thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
337 =item ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
339 MARCmodsubfield changes the value of a given subfield
341 =item $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
343 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
344 Returns -1 if more than 1 answer
346 =item $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
348 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
350 =item &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
352 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
354 =item &MARCdelbiblio($dbh,$bibid);
356 MARCdelbiblio delete biblio $bibid
358 =item &MARCkoha2marcOnefield
360 used by MARCkoha2marc and should not be useful elsewhere
362 =item &MARCmarc2kohaOnefield
364 used by MARCmarc2koha and should not be useful elsewhere
368 used to manage MARC_word table and should not be useful elsewhere
372 used to manage MARC_word table and should not be useful elsewhere
377 my ($dbh,$forlibrarian)= @_;
379 if ($forlibrarian eq 1) {
380 $sth=$dbh->prepare("select tagfield,liblibrarian as lib from marc_tag_structure order by tagfield");
382 $sth=$dbh->prepare("select tagfield,libopac as lib from marc_tag_structure order by tagfield");
385 my ($lib,$tag,$res,$tab,$mandatory,$repeatable);
386 while ( ($tag,$lib,$tab) = $sth->fetchrow) {
387 $res->{$tag}->{lib}=$lib;
388 $res->{$tab}->{tab}="";
391 if ($forlibrarian eq 1) {
392 $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");
394 $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");
399 my $authorised_value;
400 my $thesaurus_category;
402 while ( ($tag, $subfield, $lib, $tab, $mandatory, $repeatable,$authorised_value,$thesaurus_category,$value_builder) = $sth->fetchrow) {
403 $res->{$tag}->{$subfield}->{lib}=$lib;
404 $res->{$tag}->{$subfield}->{tab}=$tab;
405 $res->{$tag}->{$subfield}->{mandatory}=$mandatory;
406 $res->{$tag}->{$subfield}->{repeatable}=$repeatable;
407 $res->{$tag}->{$subfield}->{authorised_value}=$authorised_value;
408 $res->{$tag}->{$subfield}->{thesaurus_category}=$thesaurus_category;
409 $res->{$tag}->{$subfield}->{value_builder}=$value_builder;
414 sub MARCfind_marc_from_kohafield {
415 my ($dbh,$kohafield) = @_;
416 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
417 $sth->execute($kohafield);
418 my ($tagfield,$tagsubfield) = $sth->fetchrow;
419 return ($tagfield,$tagsubfield);
422 sub MARCfind_oldbiblionumber_from_MARCbibid {
423 my ($dbh,$MARCbibid) = @_;
424 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
425 $sth->execute($MARCbibid);
426 my ($biblionumber) = $sth->fetchrow;
427 return $biblionumber;
430 sub MARCfind_MARCbibid_from_oldbiblionumber {
431 my ($dbh,$oldbiblionumber) = @_;
432 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
433 $sth->execute($oldbiblionumber);
434 my ($bibid) = $sth->fetchrow;
439 # pass the MARC::Record to this function, and it will create the records in the marc tables
440 my ($dbh,$record,$biblionumber) = @_;
441 my @fields=$record->fields();
443 # adding main table, and retrieving bibid
444 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
445 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
446 $sth->execute($biblionumber);
447 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
449 ($bibid)=$sth->fetchrow;
452 # now, add subfields...
453 foreach my $field (@fields) {
454 my @subfields=$field->subfields();
456 foreach my $subfieldcount (0..$#subfields) {
457 &MARCaddsubfield($dbh,$bibid,
459 $field->indicator(1).$field->indicator(2),
461 $subfields[$subfieldcount][0],
463 $subfields[$subfieldcount][1]
467 $dbh->do("unlock tables");
472 # pass the MARC::Record to this function, and it will create the records in the marc tables
473 my ($dbh,$record,$biblionumber) = @_;
474 # warn "adding : ".$record->as_formatted();
475 # search for MARC biblionumber
476 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
477 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
478 my @fields=$record->fields();
479 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
480 $sth->execute($bibid);
481 my ($fieldcount) = $sth->fetchrow;
482 # now, add subfields...
483 foreach my $field (@fields) {
484 my @subfields=$field->subfields();
486 foreach my $subfieldcount (0..$#subfields) {
487 &MARCaddsubfield($dbh,$bibid,
489 $field->indicator(1).$field->indicator(2),
491 $subfields[$subfieldcount][0],
493 $subfields[$subfieldcount][1]
495 # warn "ADDING :$bibid,".
497 $field->indicator(1).$field->indicator(2).",
499 $subfields[$subfieldcount][0],
501 $subfields[$subfieldcount][1]";
504 $dbh->do("unlock tables");
508 sub MARCaddsubfield {
509 # Add a new subfield to a tag into the DB.
510 my ($dbh,$bibid,$tagid,$tag_indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
511 # if not value, end of job, we do nothing
512 if (length($subfieldvalue) ==0) {
515 if (not($subfieldcode)) {
518 if (length($subfieldvalue)>255) {
519 # $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
520 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
521 $sth->execute($subfieldvalue);
522 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
524 my ($res)=$sth->fetchrow;
525 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?,?)");
527 $sth->execute($bibid,'0'.$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$res);
529 $sth->execute($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$res);
532 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";
534 # $dbh->do("unlock tables");
536 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)");
537 $sth->execute($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue);
539 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";
542 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
546 # Returns MARC::Record of the biblio passed in parameter.
548 my $record = MARC::Record->new();
549 #---- TODO : the leader is missing
550 $record->leader(' ');
551 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
552 from marc_subfield_table
553 where bibid=? order by tag,tagorder,subfieldcode
555 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
556 $sth->execute($bibid);
561 while (my $row=$sth->fetchrow_hashref) {
562 if ($row->{'valuebloblink'}) { #---- search blob if there is one
563 $sth2->execute($row->{'valuebloblink'});
564 my $row2=$sth2->fetchrow_hashref;
566 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
568 if ($row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag) {
569 if (length($prevtag) <3) {
570 $prevtag = "0".$prevtag;
573 my $field = MARC::Field->new( $prevtag, substr($previndicator,0,1), substr($previndicator,1,1), %subfieldlist);
575 $record->add_fields($field);
576 $prevtagorder=$row->{tagorder};
577 $prevtag = $row->{tag};
578 $previndicator=$row->{tag_indicator};
580 %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
582 %subfieldlist->{$row->{'subfieldcode'}} .= $row->{'subfieldvalue'};
583 $prevtag= $row->{tag};
584 $previndicator=$row->{tag_indicator};
587 # the last has not been included inside the loop... do it now !
588 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
589 $record->add_fields($field);
593 # Returns MARC::Record of the biblio passed in parameter.
594 my ($dbh,$bibid,$itemnumber)=@_;
595 my $record = MARC::Record->new();
596 # search MARC tagorder
597 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=?");
598 $sth2->execute($bibid,$itemnumber);
599 my ($tagorder) = $sth2->fetchrow_array();
600 #---- TODO : the leader is missing
601 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
602 from marc_subfield_table
603 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
605 $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
606 $sth->execute($bibid,$tagorder);
607 while (my $row=$sth->fetchrow_hashref) {
608 if ($row->{'valuebloblink'}) { #---- search blob if there is one
609 $sth2->execute($row->{'valuebloblink'});
610 my $row2=$sth2->fetchrow_hashref;
612 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
614 if ($record->field($row->{'tag'})) {
616 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
617 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
618 if (length($row->{'tag'}) <3) {
619 $row->{'tag'} = "0".$row->{'tag'};
621 $field =$record->field($row->{'tag'});
623 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
624 $record->delete_field($field);
625 $record->add_fields($field);
628 if (length($row->{'tag'}) < 3) {
629 $row->{'tag'} = "0".$row->{'tag'};
631 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
632 $record->add_fields($temp);
640 my ($dbh,$bibid,$record,$delete)=@_;
641 # my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
642 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
643 # warn "OLD : ".$oldrecord->as_formatted();
644 # warn "----------------------------------\nNEW : ".$record->as_formatted();
646 # if nothing to change, don't waste time...
647 if ($oldrecord eq $record) {
648 # warn "NOTHING TO CHANGE";
651 # otherwise, skip through each subfield...
652 my @fields = $record->fields();
654 foreach my $field (@fields) {
655 my $oldfield = $oldrecord->field($field->tag());
656 my @subfields=$field->subfields();
659 foreach my $subfield (@subfields) {
661 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
662 # just adding datas...
663 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
664 1,@$subfield[0],$subfieldorder,@$subfield[1]);
666 # modify the subfield if it's a different string
667 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
668 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
669 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
678 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
679 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
680 # if nothing to change, don't waste time...
681 if ($oldrecord eq $record) {
682 # warn "nothing to change";
685 # warn "MARCmoditem : ".$record->as_formatted;
686 # warn "OLD : ".$oldrecord->as_formatted;
688 # otherwise, skip through each subfield...
689 my @fields = $record->fields();
690 # search old MARC item
691 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=?");
692 $sth2->execute($bibid,$itemnumber);
693 my ($tagorder) = $sth2->fetchrow_array();
694 foreach my $field (@fields) {
695 my $oldfield = $oldrecord->field($field->tag());
696 my @subfields=$field->subfields();
698 foreach my $subfield (@subfields) {
700 # warn "compare : $oldfield".$oldfield->subfield(@$subfield[0]);
701 if ($oldfield eq 0 or (length($oldfield->subfield(@$subfield[0])) ==0) ) {
702 # just adding datas...
703 # warn "addfield : / $subfieldorder / @$subfield[0] - @$subfield[1]";
704 # warn "NEW subfield : $bibid,".$field->tag().",".$tagorder.",".@$subfield[0].",".$subfieldorder.",".@$subfield[1].")";
705 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
706 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
708 # warn "modfield : / $subfieldorder / @$subfield[0] - @$subfield[1]";
709 # modify he subfield if it's a different string
710 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
711 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
712 # warn "changing : $subfieldid, $bibid,".$field->tag(),",$tagorder,@$subfield[0],@$subfield[1],$subfieldorder";
713 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
716 warn "nothing to change : ".$oldfield->subfield(@$subfield[0]);
724 sub MARCmodsubfield {
725 # Subroutine changes a subfield value given a subfieldid.
726 my ($dbh, $subfieldid, $subfieldvalue )=@_;
727 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
728 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
729 $sth1->execute($subfieldid);
730 my ($oldvaluebloblink)=$sth1->fetchrow;
733 # if too long, use a bloblink
734 if (length($subfieldvalue)>255 ) {
735 # if already a bloblink, update it, otherwise, insert a new one.
736 if ($oldvaluebloblink) {
737 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
738 $sth->execute($subfieldvalue,$oldvaluebloblink);
740 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
741 $sth->execute($subfieldvalue);
742 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
744 my ($res)=$sth->fetchrow;
745 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
746 $sth->execute($subfieldid);
749 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
750 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
751 $sth->execute($subfieldvalue, $subfieldid);
753 $dbh->do("unlock tables");
755 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
756 $sth->execute($subfieldid);
757 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
759 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
760 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
761 return($subfieldid, $subfieldvalue);
764 sub MARCfindsubfield {
765 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
769 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
770 if ($subfieldvalue) {
771 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
773 if ($subfieldorder<1) {
776 $query .= " and subfieldorder=$subfieldorder";
778 my $sti=$dbh->prepare($query);
779 $sti->execute($bibid,$tag, $subfieldcode);
780 while (($subfieldid) = $sti->fetchrow) {
782 $lastsubfieldid=$subfieldid;
784 if ($resultcounter>1) {
785 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
786 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
789 return $lastsubfieldid;
793 sub MARCfindsubfieldid {
794 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
795 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
796 where bibid=? and tag=? and tagorder=?
797 and subfieldcode=? and subfieldorder=?");
798 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
799 my ($res) = $sth->fetchrow;
801 $sth=$dbh->prepare("select subfieldid from marc_subfield_table
802 where bibid=? and tag=? and tagorder=?
803 and subfieldcode=?");
804 $sth->execute($bibid,$tag,$tagorder,$subfield);
805 ($res) = $sth->fetchrow;
810 sub MARCdelsubfield {
811 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
812 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
813 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
814 tag='$tag' and tagorder='$tagorder'
815 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
820 # delete a biblio for a $bibid
821 my ($dbh,$bibid) = @_;
822 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
823 $dbh->do("delete from marc_biblio where bibid='$bibid'");
826 sub MARCkoha2marcBiblio {
827 # this function builds partial MARC::Record from the old koha-DB fields
828 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
829 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
830 my $record = MARC::Record->new();
831 #--- if bibid, then retrieve old-style koha data
832 if ($biblionumber>0) {
833 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
834 from biblio where biblionumber=?");
835 $sth2->execute($biblionumber);
836 my $row=$sth2->fetchrow_hashref;
838 foreach $code (keys %$row) {
840 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
844 #--- if biblioitem, then retrieve old-style koha data
845 if ($biblioitemnumber>0) {
846 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
847 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
848 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
850 WHERE biblionumber=? and biblioitemnumber=?
852 $sth2->execute($biblionumber,$biblioitemnumber);
853 my $row=$sth2->fetchrow_hashref;
855 foreach $code (keys %$row) {
857 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
862 # TODO : retrieve notes, additionalauthors
865 sub MARCkoha2marcItem {
866 # this function builds partial MARC::Record from the old koha-DB fields
867 my ($dbh,$biblionumber,$itemnumber) = @_;
868 # my $dbh=&C4Connect;
869 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
870 my $record = MARC::Record->new();
871 #--- if item, then retrieve old-style koha data
873 # print STDERR "prepare $biblionumber,$itemnumber\n";
874 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
875 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
876 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
877 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
879 WHERE itemnumber=?");
880 $sth2->execute($itemnumber);
881 my $row=$sth2->fetchrow_hashref;
883 foreach $code (keys %$row) {
885 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
890 # TODO : retrieve notes, additionalauthors
893 sub MARCkoha2marcSubtitle {
894 # this function builds partial MARC::Record from the old koha-DB fields
895 my ($dbh,$bibnum,$subtitle) = @_;
896 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
897 my $record = MARC::Record->new();
898 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
902 sub MARCkoha2marcOnefield {
903 my ($sth,$record,$kohafieldname,$value)=@_;
906 $sth->execute($kohafieldname);
907 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
908 if ($record->field($tagfield)) {
909 my $tag =$record->field($tagfield);
911 $tag->add_subfields($tagsubfield,$value);
912 $record->delete_field($tag);
913 $record->add_fields($tag);
916 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
923 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
924 my $prevtag = @$rtags[0];
925 my $record = MARC::Record->new();
927 for (my $i=0; $i< @$rtags; $i++) {
928 # rebuild MARC::Record
929 if (@$rtags[$i] ne $prevtag) {
933 $indicators{$prevtag}.=' ';
934 my $field = MARC::Field->new( $prevtag, substr($indicators{$prevtag},0,1),substr($indicators{$prevtag},1,1), %subfieldlist);
935 $record->add_fields($field);
936 $prevtag = @$rtags[$i];
938 %subfieldlist->{@$rsubfields[$i]} = @$rvalues[$i];
940 # if (%subfieldlist->{@$rsubfields[$i]}) {
941 # %subfieldlist->{@$rsubfields[$i]} .= '|';
943 %subfieldlist->{@$rsubfields[$i]} .=@$rvalues[$i];
944 $prevtag= @$rtags[$i];
947 # the last has not been included inside the loop... do it now !
948 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
949 $record->add_fields($field);
954 my ($dbh,$record) = @_;
955 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
957 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
960 # print STDERR $record->as_formatted;
961 while (($field)=$sth2->fetchrow) {
962 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
964 $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
966 while (($field)=$sth2->fetchrow) {
967 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
969 $sth2=$dbh->prepare("SHOW COLUMNS from items");
971 while (($field)=$sth2->fetchrow) {
972 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
974 # additional authors : specific
975 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
979 sub MARCmarc2kohaOneField {
980 # FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
981 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
982 # warn "kohatable / $kohafield / $result / ";
986 $sth->execute($kohatable.".".$kohafield);
987 ($tagfield,$subfield) = $sth->fetchrow;
988 foreach my $field ($record->field($tagfield)) {
989 if ($field->subfield($subfield)) {
990 if ($result->{$kohafield}) {
991 $result->{$kohafield} .= " | ".$field->subfield($subfield);
993 $result->{$kohafield}=$field->subfield($subfield);
1001 # split a subfield string and adds it into the word table.
1003 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
1004 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
1005 my @words = split / /,$sentence;
1006 my $stopwords= C4::Context->stopwords;
1007 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
1008 values (?,?,?,?,?,?,soundex(?))");
1009 foreach my $word (@words) {
1010 # we record only words longer than 2 car and not in stopwords hash
1011 if (length($word)>1 and !($stopwords->{uc($word)})) {
1012 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
1014 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";
1021 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
1022 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
1023 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
1024 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
1029 # NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW
1032 # all the following subs are useful to manage MARC-DB with complete MARC records.
1033 # it's used with marcimport, and marc management tools
1037 =item (oldbibnum,$oldbibitemnum) = NEWnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
1039 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
1040 are builded from the MARC::Record. If they are passed, they are used.
1042 =item NEWnewitem($dbh,$olditem);
1044 adds an item in the db. $olditem is a old-db hash.
1049 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
1050 # note $oldbiblio and $oldbiblioitem are not mandatory.
1051 # if not present, they will be builded from $record with MARCmarc2koha function
1052 if (($oldbiblio) and not($oldbiblioitem)) {
1053 print STDERR "NEWnewbiblio : missing parameter\n";
1054 print "NEWnewbiblio : missing parameter : contact koha development team\n";
1060 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
1061 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
1062 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
1064 my $olddata = MARCmarc2koha($dbh,$record);
1065 $oldbibnum = OLDnewbiblio($dbh,$olddata);
1066 $olddata->{'biblionumber'} = $oldbibnum;
1067 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
1069 # we must add bibnum and bibitemnum in MARC::Record...
1070 # we build the new field with biblionumber and biblioitemnumber
1071 # we drop the original field
1072 # we add the new builded field.
1073 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
1074 # (steve and paul : thinks 090 is a good choice)
1075 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
1076 $sth->execute("biblio.biblionumber");
1077 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
1078 $sth->execute("biblioitems.biblioitemnumber");
1079 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
1080 if ($tagfield1 != $tagfield2) {
1081 print STDERR "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1082 print "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1085 my $newfield = MARC::Field->new( $tagfield1,'','',
1086 "$tagsubfield1" => $oldbibnum,
1087 "$tagsubfield2" => $oldbibitemnum);
1088 # drop old field and create new one...
1089 my $old_field = $record->field($tagfield1);
1090 $record->delete_field($old_field);
1091 $record->add_fields($newfield);
1092 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
1093 return ($bibid,$oldbibnum,$oldbibitemnum );
1097 my ($dbh,$record,$bibid) =@_;
1098 &MARCmodbiblio($dbh,$bibid,$record,0);
1099 my $oldbiblio = MARCmarc2koha($dbh,$record);
1100 my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
1101 OLDmodbibitem($dbh,$oldbiblio);
1107 my ($dbh, $record,$bibid) = @_;
1108 # add item in old-DB
1109 my $item = &MARCmarc2koha($dbh,$record);
1110 # needs old biblionumber and biblioitemnumber
1111 $item->{'biblionumber'} = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
1112 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
1113 $sth->execute($item->{'biblionumber'});
1114 ($item->{'biblioitemnumber'}) = $sth->fetchrow;
1115 my ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{barcode});
1116 # add itemnumber to MARC::Record before adding the item.
1117 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
1118 &MARCkoha2marcOnefield($sth,$record,"items.itemnumber",$itemnumber);
1120 my $bib = &MARCadditem($dbh,$record,$item->{'biblionumber'});
1124 my ($dbh,$record,$bibid,$itemnumber,$delete) = @_;
1125 &MARCmoditem($dbh,$record,$bibid,$itemnumber,$delete);
1126 my $olditem = MARCmarc2koha($dbh,$record);
1127 OLDmoditem($dbh,$olditem);
1132 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
1136 =item $biblionumber = OLDnewbiblio($dbh,$biblio);
1138 adds a record in biblio table. Datas are in the hash $biblio.
1140 =item $biblionumber = OLDmodbiblio($dbh,$biblio);
1142 modify a record in biblio table. Datas are in the hash $biblio.
1144 =item OLDmodsubtitle($dbh,$bibnum,$subtitle);
1146 modify subtitles in bibliosubtitle table.
1148 =item OLDmodaddauthor($dbh,$bibnum,$author);
1150 adds or modify additional authors
1151 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1153 =item $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1155 modify/adds subjects
1157 =item OLDmodbibitem($dbh, $biblioitem);
1161 =item OLDmodnote($dbh,$bibitemnum,$note
1163 modify a note for a biblioitem
1165 =item OLDnewbiblioitem($dbh,$biblioitem);
1167 adds a biblioitem ($biblioitem is a hash with the values)
1169 =item OLDnewsubject($dbh,$bibnum);
1173 =item OLDnewsubtitle($dbh,$bibnum,$subtitle);
1175 create a new subtitle
1177 =item ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1179 create a item. $item is a hash and $barcode the barcode.
1181 =item OLDmoditem($dbh,$item);
1185 =item OLDdelitem($dbh,$itemnum);
1189 =item OLDdeletebiblioitem($dbh,$biblioitemnumber);
1191 deletes a biblioitem
1192 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1194 =item OLDdelbiblio($dbh,$biblio);
1201 my ($dbh,$biblio) = @_;
1202 # my $dbh = &C4Connect;
1203 my $query = "Select max(biblionumber) from biblio";
1204 my $sth = $dbh->prepare($query);
1206 my $data = $sth->fetchrow_arrayref;
1207 my $bibnum = $$data[0] + 1;
1210 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1211 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1212 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
1213 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
1214 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1215 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1216 if ($biblio->{'seriestitle'}) { $series = 1 };
1219 $query = "insert into biblio set
1220 biblionumber = $bibnum,
1221 title = $biblio->{'title'},
1222 author = $biblio->{'author'},
1223 copyrightdate = $biblio->{'copyright'},
1225 seriestitle = $biblio->{'seriestitle'},
1226 notes = $biblio->{'notes'},
1227 abstract = $biblio->{'abstract'}";
1229 $sth = $dbh->prepare($query);
1238 my ($dbh,$biblio) = @_;
1239 # my $dbh = C4Connect;
1243 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
1244 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
1245 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
1246 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
1247 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
1248 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
1249 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
1250 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
1252 $query = "Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?,
1253 seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?";
1254 $sth = $dbh->prepare($query);
1255 $sth->execute($biblio->{'title'},$biblio->{'author'},$biblio->{'abstract'},$biblio->{'copyrightdate'},
1256 $biblio->{'seriestitle'},$biblio->{'serial'},$biblio->{'unititle'},$biblio->{'notes'},$biblio->{'biblionumber'});
1259 return($biblio->{'biblionumber'});
1262 sub OLDmodsubtitle {
1263 my ($dbh,$bibnum, $subtitle) = @_;
1264 # my $dbh = C4Connect;
1265 my $query = "update bibliosubtitle set
1266 subtitle = '$subtitle'
1267 where biblionumber = $bibnum";
1268 my $sth = $dbh->prepare($query);
1276 sub OLDmodaddauthor {
1277 my ($dbh,$bibnum, $author) = @_;
1278 # my $dbh = C4Connect;
1279 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1280 my $sth = $dbh->prepare($query);
1285 if ($author ne '') {
1286 $query = "Insert into additionalauthors set
1288 biblionumber = '$bibnum'";
1289 $sth = $dbh->prepare($query);
1295 } # sub modaddauthor
1299 my ($dbh,$bibnum, $force, @subject) = @_;
1300 # my $dbh = C4Connect;
1301 my $count = @subject;
1303 for (my $i = 0; $i < $count; $i++) {
1304 $subject[$i] =~ s/^ //g;
1305 $subject[$i] =~ s/ $//g;
1306 my $query = "select * from catalogueentry
1307 where entrytype = 's'
1308 and catalogueentry = '$subject[$i]'";
1309 my $sth = $dbh->prepare($query);
1312 if (my $data = $sth->fetchrow_hashref) {
1314 if ($force eq $subject[$i]) {
1315 # subject not in aut, chosen to force anway
1316 # so insert into cataloguentry so its in auth file
1317 $query = "Insert into catalogueentry
1318 (entrytype,catalogueentry)
1319 values ('s','$subject[$i]')";
1320 my $sth2 = $dbh->prepare($query);
1325 $error = "$subject[$i]\n does not exist in the subject authority file";
1326 $query = "Select * from catalogueentry
1327 where entrytype = 's'
1328 and (catalogueentry like '$subject[$i] %'
1329 or catalogueentry like '% $subject[$i] %'
1330 or catalogueentry like '% $subject[$i]')";
1331 my $sth2 = $dbh->prepare($query);
1334 while (my $data = $sth2->fetchrow_hashref) {
1335 $error .= "<br>$data->{'catalogueentry'}";
1343 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1344 my $sth = $dbh->prepare($query);
1347 for (my $i = 0; $i < $count; $i++) {
1348 $sth = $dbh->prepare("Insert into bibliosubject
1349 values ('$subject[$i]', $bibnum)");
1361 my ($dbh,$biblioitem) = @_;
1362 # my $dbh = C4Connect;
1365 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1366 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1367 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1368 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1369 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1370 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1371 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1372 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1373 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1374 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1375 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1376 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1377 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1378 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1380 $query = "Update biblioitems set
1381 itemtype = $biblioitem->{'itemtype'},
1382 url = $biblioitem->{'url'},
1383 isbn = $biblioitem->{'isbn'},
1384 publishercode = $biblioitem->{'publishercode'},
1385 publicationyear = $biblioitem->{'publicationyear'},
1386 classification = $biblioitem->{'classification'},
1387 dewey = $biblioitem->{'dewey'},
1388 subclass = $biblioitem->{'subclass'},
1389 illus = $biblioitem->{'illus'},
1390 pages = $biblioitem->{'pages'},
1391 volumeddesc = $biblioitem->{'volumeddesc'},
1392 notes = $biblioitem->{'notes'},
1393 size = $biblioitem->{'size'},
1394 place = $biblioitem->{'place'}
1395 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1403 my ($dbh,$bibitemnum,$note)=@_;
1404 # my $dbh=C4Connect;
1405 my $query="update biblioitems set notes='$note' where
1406 biblioitemnumber='$bibitemnum'";
1407 my $sth=$dbh->prepare($query);
1413 sub OLDnewbiblioitem {
1414 my ($dbh,$biblioitem) = @_;
1415 # my $dbh = C4Connect;
1416 my $query = "Select max(biblioitemnumber) from biblioitems";
1417 my $sth = $dbh->prepare($query);
1422 $data = $sth->fetchrow_arrayref;
1423 $bibitemnum = $$data[0] + 1;
1427 $sth = $dbh->prepare("insert into biblioitems set
1428 biblioitemnumber = ?, biblionumber = ?,
1429 volume = ?, number = ?,
1430 classification = ?, itemtype = ?,
1432 issn = ?, dewey = ?,
1433 subclass = ?, publicationyear = ?,
1434 publishercode = ?, volumedate = ?,
1435 volumeddesc = ?, illus = ?,
1436 pages = ?, notes = ?,
1438 marc = ?, place = ?");
1439 $sth->execute($bibitemnum, $biblioitem->{'biblionumber'},
1440 $biblioitem->{'volume'}, $biblioitem->{'number'},
1441 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
1442 $biblioitem->{'url'}, $biblioitem->{'isbn'},
1443 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
1444 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
1445 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
1446 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
1447 $biblioitem->{'pages'}, $biblioitem->{'notes'},
1448 $biblioitem->{'size'}, $biblioitem->{'lccn'},
1449 $biblioitem->{'marc'}, $biblioitem->{'place'});
1452 return($bibitemnum);
1456 my ($dbh,$bibnum)=@_;
1457 # my $dbh=C4Connect;
1458 my $query="insert into bibliosubject (biblionumber) values
1460 my $sth=$dbh->prepare($query);
1467 sub OLDnewsubtitle {
1468 my ($dbh,$bibnum, $subtitle) = @_;
1469 # my $dbh = C4Connect;
1470 $subtitle = $dbh->quote($subtitle);
1471 my $query = "insert into bibliosubtitle set
1472 biblionumber = $bibnum,
1473 subtitle = $subtitle";
1474 my $sth = $dbh->prepare($query);
1484 my ($dbh,$item, $barcode) = @_;
1485 # my $dbh = C4Connect;
1486 my $query = "Select max(itemnumber) from items";
1487 my $sth = $dbh->prepare($query);
1493 $data = $sth->fetchrow_hashref;
1494 $itemnumber = $data->{'max(itemnumber)'} + 1;
1497 $sth=$dbh->prepare("Insert into items set
1498 itemnumber = ?, biblionumber = ?,
1499 biblioitemnumber = ?, barcode = ?,
1500 booksellerid = ?, dateaccessioned = NOW(),
1501 homebranch = ?, holdingbranch = ?,
1502 price = ?, replacementprice = ?,
1503 replacementpricedate = NOW(), itemnotes = ?,
1506 $sth->execute($itemnumber, $item->{'biblionumber'},
1507 $item->{'biblioitemnumber'},$barcode,
1508 $item->{'booksellerid'},
1509 $item->{'homebranch'},$item->{'homebranch'},
1510 $item->{'price'},$item->{'replacementprice'},
1511 $item->{'itemnotes'},$item->{'loan'});
1514 if (defined $sth->errstr) {
1515 $error .= $sth->errstr;
1520 return($itemnumber,$error);
1524 my ($dbh,$item) = @_;
1525 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1526 # my $dbh=C4Connect;
1527 $item->{'itemnum'}=$item->{'itemnumber'} unless $item->{'itemnum'};
1528 my $query="update items set barcode='$item->{'barcode'}',itemnotes='$item->{'notes'}'
1529 where itemnumber=$item->{'itemnum'}";
1530 if ($item->{'barcode'} eq ''){
1531 $query="update items set notforloan=$item->{'loan'} where itemnumber=$item->{'itemnum'}";
1533 if ($item->{'lost'} ne ''){
1534 $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1535 barcode='$item->{'barcode'}',
1536 itemnotes='$item->{'notes'}',
1537 homebranch='$item->{'homebranch'}',
1538 itemlost='$item->{'lost'}',
1539 wthdrawn='$item->{'wthdrawn'}'
1540 where itemnumber=$item->{'itemnum'}";
1542 if ($item->{'replacement'} ne ''){
1543 $query=~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1545 my $sth=$dbh->prepare($query);
1552 my ($dbh,$itemnum)=@_;
1553 # my $dbh=C4Connect;
1554 my $query="select * from items where itemnumber=$itemnum";
1555 my $sth=$dbh->prepare($query);
1557 my @data=$sth->fetchrow_array;
1559 $query="Insert into deleteditems values (";
1560 foreach my $temp (@data){
1561 $query .= "'$temp',";
1565 $sth=$dbh->prepare($query);
1568 $query = "Delete from items where itemnumber=$itemnum";
1569 $sth=$dbh->prepare($query);
1575 sub OLDdeletebiblioitem {
1576 my ($dbh,$biblioitemnumber) = @_;
1577 # my $dbh = C4Connect;
1578 my $query = "Select * from biblioitems
1579 where biblioitemnumber = $biblioitemnumber";
1580 my $sth = $dbh->prepare($query);
1585 if (@results = $sth->fetchrow_array) {
1586 $query = "Insert into deletedbiblioitems values (";
1587 foreach my $value (@results) {
1588 $value = $dbh->quote($value);
1589 $query .= "$value,";
1592 $query =~ s/\,$/\)/;
1595 $query = "Delete from biblioitems
1596 where biblioitemnumber = $biblioitemnumber";
1600 # Now delete all the items attached to the biblioitem
1601 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1602 $sth = $dbh->prepare($query);
1604 while (@results = $sth->fetchrow_array) {
1605 $query = "Insert into deleteditems values (";
1606 foreach my $value (@results) {
1607 $value = $dbh->quote($value);
1608 $query .= "$value,";
1610 $query =~ s/\,$/\)/;
1614 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1617 } # sub deletebiblioitem
1620 my ($dbh,$biblio)=@_;
1621 # my $dbh=C4Connect;
1622 my $query="select * from biblio where biblionumber=$biblio";
1623 my $sth=$dbh->prepare($query);
1625 if (my @data=$sth->fetchrow_array){
1627 $query="Insert into deletedbiblio values (";
1628 foreach my $temp (@data){
1629 $temp=~ s/\'/\\\'/g;
1630 $query .= "'$temp',";
1634 $sth=$dbh->prepare($query);
1637 $query = "Delete from biblio where biblionumber=$biblio";
1638 $sth=$dbh->prepare($query);
1654 my $dbh = C4::Context->dbh;
1655 my $query="Select count(*) from items where biblionumber=$biblio";
1657 my $sth=$dbh->prepare($query);
1659 my $data=$sth->fetchrow_hashref;
1661 return($data->{'count(*)'});
1666 ($order, $ordernumber) = &getorder($biblioitemnumber, $biblionumber);
1668 Looks up the order with the given biblionumber and biblioitemnumber.
1670 Returns a two-element array. C<$ordernumber> is the order number.
1671 C<$order> is a reference-to-hash describing the order; its keys are
1672 fields from the biblio, biblioitems, aqorders, and aqorderbreakdown
1673 tables of the Koha database.
1677 # FIXME - This is effectively identical to &C4::Catalogue::getorder.
1678 # Pick one and stick with it.
1681 my $dbh = C4::Context->dbh;
1682 my $query="Select ordernumber
1684 where biblionumber=? and biblioitemnumber=?";
1685 my $sth=$dbh->prepare($query);
1686 $sth->execute($bib,$bi);
1687 # FIXME - Use fetchrow_array(), since we're only interested in the one
1689 my $ordnum=$sth->fetchrow_hashref;
1691 my $order=getsingleorder($ordnum->{'ordernumber'});
1693 return ($order,$ordnum->{'ordernumber'});
1696 =item getsingleorder
1698 $order = &getsingleorder($ordernumber);
1700 Looks up an order by order number.
1702 Returns a reference-to-hash describing the order. The keys of
1703 C<$order> are fields from the biblio, biblioitems, aqorders, and
1704 aqorderbreakdown tables of the Koha database.
1708 # FIXME - This is effectively identical to
1709 # &C4::Catalogue::getsingleorder.
1710 # Pick one and stick with it.
1711 sub getsingleorder {
1713 my $dbh = C4::Context->dbh;
1714 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1715 where aqorders.ordernumber=?
1716 and biblio.biblionumber=aqorders.biblionumber and
1717 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1718 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1719 my $sth=$dbh->prepare($query);
1720 $sth->execute($ordnum);
1721 my $data=$sth->fetchrow_hashref;
1728 my $dbh = C4::Context->dbh;
1729 my $bibnum=OLDnewbiblio($dbh,$biblio);
1736 $biblionumber = &modbiblio($biblio);
1738 Update a biblio record.
1740 C<$biblio> is a reference-to-hash whose keys are the fields in the
1741 biblio table in the Koha database. All fields must be present, not
1742 just the ones you wish to change.
1744 C<&modbiblio> updates the record defined by
1745 C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
1747 C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
1754 my $dbh = C4::Context->dbh;
1755 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1756 return($biblionumber);
1762 &modsubtitle($biblionumber, $subtitle);
1764 Sets the subtitle of a book.
1766 C<$biblionumber> is the biblionumber of the book to modify.
1768 C<$subtitle> is the new subtitle.
1773 my ($bibnum, $subtitle) = @_;
1774 my $dbh = C4::Context->dbh;
1775 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1780 &modaddauthor($biblionumber, $author);
1782 Replaces all additional authors for the book with biblio number
1783 C<$biblionumber> with C<$author>. If C<$author> is the empty string,
1784 C<&modaddauthor> deletes all additional authors.
1789 my ($bibnum, $author) = @_;
1790 my $dbh = C4::Context->dbh;
1791 &OLDmodaddauthor($dbh,$bibnum,$author);
1792 } # sub modaddauthor
1796 $error = &modsubject($biblionumber, $force, @subjects);
1798 $force - a subject to force
1800 $error - Error message, or undef if successful.
1805 my ($bibnum, $force, @subject) = @_;
1806 my $dbh = C4::Context->dbh;
1807 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1812 my ($biblioitem) = @_;
1813 my $dbh = C4::Context->dbh;
1814 &OLDmodbibitem($dbh,$biblioitem);
1815 my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
1816 &MARCmodbiblio($dbh,$biblioitem->{biblionumber},$MARCbibitem,0);
1820 my ($bibitemnum,$note)=@_;
1821 my $dbh = C4::Context->dbh;
1822 &OLDmodnote($dbh,$bibitemnum,$note);
1826 my ($biblioitem) = @_;
1827 my $dbh = C4::Context->dbh;
1828 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1829 # print STDERR "bibitemnum : $bibitemnum\n";
1830 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1831 # print STDERR $MARCbiblio->as_formatted();
1832 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1833 return($bibitemnum);
1838 my $dbh = C4::Context->dbh;
1839 &OLDnewsubject($dbh,$bibnum);
1843 my ($bibnum, $subtitle) = @_;
1844 my $dbh = C4::Context->dbh;
1845 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1849 my ($item, @barcodes) = @_;
1850 my $dbh = C4::Context->dbh;
1854 foreach my $barcode (@barcodes) {
1855 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1857 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1858 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1865 my $dbh = C4::Context->dbh;
1866 &OLDmoditem($dbh,$item);
1867 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1868 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1869 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1873 my ($count,@barcodes)=@_;
1874 my $dbh = C4::Context->dbh;
1876 for (my $i=0;$i<$count;$i++){
1877 $barcodes[$i]=uc $barcodes[$i];
1878 my $query="Select * from items where barcode='$barcodes[$i]'";
1879 my $sth=$dbh->prepare($query);
1881 if (my $data=$sth->fetchrow_hashref){
1882 $error.=" Duplicate Barcode: $barcodes[$i]";
1890 my ($bibitemnum)=@_;
1891 my $dbh = C4::Context->dbh;
1892 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1893 my $sth=$dbh->prepare($query);
1895 my $data=$sth->fetchrow_hashref;
1897 return($data->{'count(*)'});
1902 my $dbh = C4::Context->dbh;
1903 &OLDdelitem($dbh,$itemnum);
1906 sub deletebiblioitem {
1907 my ($biblioitemnumber) = @_;
1908 my $dbh = C4::Context->dbh;
1909 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1910 } # sub deletebiblioitem
1915 my $dbh = C4::Context->dbh;
1916 &OLDdelbiblio($dbh,$biblio);
1920 my $dbh = C4::Context->dbh;
1921 my $query = "select * from itemtypes";
1922 my $sth = $dbh->prepare($query);
1923 # || die "Cannot prepare $query" . $dbh->errstr;
1928 # || die "Cannot execute $query\n" . $sth->errstr;
1929 while (my $data = $sth->fetchrow_hashref) {
1930 $results[$count] = $data;
1935 return($count, @results);
1936 } # sub getitemtypes
1939 my ($biblionumber) = @_;
1940 my $dbh = C4::Context->dbh;
1941 my $query = "Select * from biblio where biblionumber = $biblionumber";
1942 my $sth = $dbh->prepare($query);
1943 # || die "Cannot prepare $query\n" . $dbh->errstr;
1948 # || die "Cannot execute $query\n" . $sth->errstr;
1949 while (my $data = $sth->fetchrow_hashref) {
1950 $results[$count] = $data;
1955 return($count, @results);
1959 my ($biblioitemnum) = @_;
1960 my $dbh = C4::Context->dbh;
1961 my $query = "Select * from biblioitems where
1962 biblioitemnumber = $biblioitemnum";
1963 my $sth = $dbh->prepare($query);
1969 while (my $data = $sth->fetchrow_hashref) {
1970 $results[$count] = $data;
1975 return($count, @results);
1976 } # sub getbiblioitem
1978 sub getbiblioitembybiblionumber {
1979 my ($biblionumber) = @_;
1980 my $dbh = C4::Context->dbh;
1981 my $query = "Select * from biblioitems where biblionumber =
1983 my $sth = $dbh->prepare($query);
1989 while (my $data = $sth->fetchrow_hashref) {
1990 $results[$count] = $data;
1995 return($count, @results);
1998 sub getitemsbybiblioitem {
1999 my ($biblioitemnum) = @_;
2000 my $dbh = C4::Context->dbh;
2001 my $query = "Select * from items, biblio where
2002 biblio.biblionumber = items.biblionumber and biblioitemnumber
2004 my $sth = $dbh->prepare($query);
2005 # || die "Cannot prepare $query\n" . $dbh->errstr;
2010 # || die "Cannot execute $query\n" . $sth->errstr;
2011 while (my $data = $sth->fetchrow_hashref) {
2012 $results[$count] = $data;
2017 return($count, @results);
2018 } # sub getitemsbybiblioitem
2022 # Subroutine to log changes to databases
2023 # Eventually, this subroutine will be used to create a log of all changes made,
2024 # with the possibility of "undo"ing some changes
2026 if ($database eq 'kohadb') {
2032 # print STDERR "KOHA: $type $section $item $original $new\n";
2033 } elsif ($database eq 'marc') {
2035 my $Record_ID=shift;
2038 my $subfield_ID=shift;
2041 # print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2045 #------------------------------------------------
2048 #---------------------------------------
2049 # Find a biblio entry, or create a new one if it doesn't exist.
2050 # If a "subtitle" entry is in hash, add it to subtitle table
2051 sub getoraddbiblio {
2055 # FIXME - Unused argument
2056 $biblio, # hash ref to fields
2067 $dbh = C4::Context->dbh;
2069 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2070 $sth=$dbh->prepare("select biblionumber
2072 where title=? and author=?
2073 and copyrightdate=? and seriestitle=?");
2075 $biblio->{title}, $biblio->{author},
2076 $biblio->{copyright}, $biblio->{seriestitle} );
2078 ($biblionumber) = $sth->fetchrow;
2079 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2081 # Doesn't exist. Add new one.
2082 print "<PRE>Adding biblio</PRE>\n" if $debug;
2083 ($biblionumber,$error)=&newbiblio($biblio);
2084 if ( $biblionumber ) {
2085 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
2086 if ( $biblio->{subtitle} ) {
2087 &newsubtitle($biblionumber,$biblio->{subtitle} );
2090 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2094 return $biblionumber,$error;
2096 } # sub getoraddbiblio
2099 # converts ISO 5426 coded string to ISO 8859-1
2100 # sloppy code : should be improved in next issue
2103 if (C4::Context->preference("marcflavour") eq "UNIMARC") {
2220 # this handles non-sorting blocks (if implementation requires this)
2221 $string = nsb_clean($_) ;
2226 my $NSB = '\x88' ; # NSB : begin Non Sorting Block
2227 my $NSE = '\x89' ; # NSE : Non Sorting Block end
2228 # handles non sorting blocks
2232 s/[ ]{0,1}$NSE/) /gm ;
2237 END { } # module clean-up code here (global destructor)
2243 Koha Developement team <info@koha.org>
2245 Paul POULAIN paul.poulain@free.fr