4 # Revision 1.39 2003/03/07 16:35:42 tipaul
5 # * moving generic functions to Koha.pm
6 # * improvement of SearchMarc.pm
10 # Revision 1.38 2003/02/27 16:51:59 tipaul
11 # * moving prepare / execute to ? form.
14 # * road to 1.9.2 => acquisition and cataloguing merging
16 # Revision 1.37 2003/02/12 11:03:03 tipaul
17 # Support for 000 -> 010 fields.
18 # Those fields doesn't have subfields.
19 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
20 # Note it's only virtual : when rebuilding the MARC::Record, the koha API handle correctly "@" subfields => the resulting MARC record has a 00x field without subfield.
22 # Revision 1.36 2003/02/12 11:01:01 tipaul
23 # Support for 000 -> 010 fields.
24 # Those fields doesn't have subfields.
25 # In koha, we will use a specific "trick" : fields <10 will have a "virtual" subfield : "@".
26 # Note it's only virtual : when rebuilding the MARC::Record, the koha API handle correctly "@" subfields => the resulting MARC record has a 00x field without subfield.
28 # Revision 1.35 2003/02/03 18:46:00 acli
29 # Minor factoring in C4/Biblio.pm, plus change to export the per-tag
30 # 'mandatory' property to a per-subfield 'tag_mandatory' template parameter,
31 # so that addbiblio.tmpl can distinguish between mandatory subfields in a
32 # mandatory tag and mandatory subfields in an optional tag
34 # Not-minor factoring in acqui.simple/addbiblio.pl to make the if-else blocks
35 # smaller, and to add some POD; need further testing for this
37 # Added function to check if a MARC subfield name is "koha-internal" (instead
38 # of checking it for 'lib' and 'tag' everywhere); temporarily added to Koha.pm
40 # Use above function in acqui.simple/additem.pl and search.marc/search.pl
42 # Revision 1.34 2003/01/28 14:50:04 tipaul
43 # fixing MARCmodbiblio API and reindenting code
45 # Revision 1.33 2003/01/23 12:22:37 tipaul
46 # adding char_decode to decode MARC21 or UNIMARC extended chars
48 # Revision 1.32 2002/12/16 15:08:50 tipaul
49 # small but important bugfix (fixes a problem in export)
51 # Revision 1.31 2002/12/13 16:22:04 tipaul
52 # 1st draft of marc export
54 # Revision 1.30 2002/12/12 21:26:35 tipaul
55 # YAB ! (Yet Another Bugfix) => related to biblio modif
56 # (some warning cleaning too)
58 # Revision 1.29 2002/12/12 16:35:00 tipaul
59 # adding authentification with Auth.pm and
60 # MAJOR BUGFIX on marc biblio modification
62 # Revision 1.28 2002/12/10 13:30:03 tipaul
63 # fugfixes from Dombes Abbey work
65 # Revision 1.27 2002/11/19 12:36:16 tipaul
67 # various bugfixes, improvments, and migration from acquisition.pm to biblio.pm
69 # Revision 1.26 2002/11/12 15:58:43 tipaul
72 # * 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)
74 # Revision 1.25 2002/10/25 10:58:26 tipaul
76 # * bugfixes and improvements
78 # Revision 1.24 2002/10/24 12:09:01 arensb
79 # Fixed "no title" warning when generating HTML documentation from POD.
81 # Revision 1.23 2002/10/16 12:43:08 arensb
82 # Added some FIXME comments.
84 # Revision 1.22 2002/10/15 13:39:17 tipaul
85 # removing Acquisition.pm
86 # deleting unused code in biblio.pm, rewriting POD and answering most FIXME comments
88 # Revision 1.21 2002/10/13 11:34:14 arensb
89 # Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
90 # Thus, $x = $x+2 becomes $x += 2, and so forth.
92 # Revision 1.20 2002/10/13 08:28:32 arensb
93 # Deleted unused variables.
94 # Removed trailing whitespace.
96 # Revision 1.19 2002/10/13 05:56:10 arensb
97 # Added some FIXME comments.
99 # Revision 1.18 2002/10/11 12:34:53 arensb
100 # Replaced &requireDBI with C4::Context->dbh
102 # Revision 1.17 2002/10/10 14:48:25 tipaul
105 # Revision 1.16 2002/10/07 14:04:26 tipaul
106 # road to 1.3.1 : viewing MARC biblio
108 # Revision 1.15 2002/10/05 09:49:25 arensb
109 # Merged with arensb-context branch: use C4::Context->dbh instead of
110 # &C4Connect, and generally prefer C4::Context over C4::Database.
112 # Revision 1.14 2002/10/03 11:28:18 tipaul
113 # Extending Context.pm to add stopword management and using it in MARC-API.
114 # First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
116 # Revision 1.13 2002/10/02 16:26:44 tipaul
119 # Revision 1.12.2.4 2002/10/05 07:09:31 arensb
120 # Merged in changes from main branch.
122 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
123 # Added a whole mess of FIXME comments.
125 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
126 # Added some missing semicolons.
128 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
129 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
132 # Revision 1.12.2.3 2002/10/05 06:12:10 arensb
133 # Added a whole mess of FIXME comments.
135 # Revision 1.12.2.2 2002/10/05 04:03:14 arensb
136 # Added some missing semicolons.
138 # Revision 1.12.2.1 2002/10/04 02:24:01 arensb
139 # Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
142 # Revision 1.12 2002/10/01 11:48:51 arensb
143 # Added some FIXME comments, mostly marking duplicate functions.
145 # Revision 1.11 2002/09/24 13:49:26 tipaul
146 # long WAS the road to 1.3.0...
147 # coming VERY SOON NOW...
148 # modifying installer and buildrelease to update the DB
150 # Revision 1.10 2002/09/22 16:50:08 arensb
151 # Added some FIXME comments.
153 # Revision 1.9 2002/09/20 12:57:46 tipaul
154 # long is the road to 1.4.0
155 # * MARCadditem and MARCmoditem now wroks
156 # * various bugfixes in MARC management
157 # !!! 1.3.0 should be released very soon now. Be careful !!!
159 # Revision 1.8 2002/09/10 13:53:52 tipaul
160 # MARC API continued...
162 # * 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)
164 # Note : it should not be hard for marcimport and marcexport to re-link fields from internal tag/subfield to "legal" tag/subfield.
166 # Revision 1.7 2002/08/14 18:12:51 tonnesen
167 # Added copyright statement to all .pl and .pm files
169 # Revision 1.6 2002/07/25 13:40:31 tipaul
170 # pod documenting the API.
172 # Revision 1.5 2002/07/24 16:11:37 tipaul
174 # Database.pm and Output.pm are almost not modified (var test...)
176 # Biblio.pm is almost completly rewritten.
178 # WHAT DOES IT ??? ==> END of Hitchcock suspens
180 # 1st, it does... nothing...
181 # 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 ...
183 # All old-API functions have been cloned. for example, the "newbiblio" sub, now has become :
184 # * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio
185 # * 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.
186 # * 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.
187 # 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 ;-)
189 # 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.
190 # Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
194 # Copyright 2000-2002 Katipo Communications
196 # This file is part of Koha.
198 # Koha is free software; you can redistribute it and/or modify it under the
199 # terms of the GNU General Public License as published by the Free Software
200 # Foundation; either version 2 of the License, or (at your option) any later
203 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
204 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
205 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
207 # You should have received a copy of the GNU General Public License along with
208 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
209 # Suite 330, Boston, MA 02111-1307 USA
217 use vars qw($VERSION @ISA @EXPORT);
219 # set the version for version checking
224 # don't forget MARCxxx subs are here only for testing purposes. Should not be used
225 # as the old-style API and the NEW one are the only public functions.
228 &updateBiblio &updateBiblioItem &updateItem
229 &itemcount &newbiblio &newbiblioitem
230 &modnote &newsubject &newsubtitle
231 &modbiblio &checkitems
232 &newitems &modbibitem
233 &modsubtitle &modsubject &modaddauthor &moditem &countitems
234 &delitem &deletebiblioitem &delbiblio
235 &getitemtypes &getbiblio
236 &getbiblioitembybiblionumber
237 &getbiblioitem &getitemsbybiblioitem
239 &newcompletebiblioitem
241 &MARCfind_oldbiblionumber_from_MARCbibid
242 &MARCfind_MARCbibid_from_oldbiblionumber
243 &MARCfind_marc_from_kohafield
247 &NEWnewbiblio &NEWnewitem
248 &NEWmodbiblio &NEWmoditem
250 &MARCaddbiblio &MARCadditem
251 &MARCmodsubfield &MARCaddsubfield
252 &MARCmodbiblio &MARCmoditem
253 &MARCkoha2marcBiblio &MARCmarc2koha
254 &MARCkoha2marcItem &MARChtml2marc
255 &MARCgetbiblio &MARCgetitem
256 &MARCaddword &MARCdelword
262 # MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
265 # all the following subs takes a MARC::Record as parameter and manage
266 # the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
267 # NEWxxx subs (xxx deals with old-DB parameters, the NEWxxx deals with MARC-DB parameter)
271 C4::Biblio - acquisition, catalog management functions
275 move from 1.2 to 1.4 version :
276 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
277 In the 1.4 version, we want to do 2 differents things :
278 - keep populating the old-DB, that has a LOT less datas than MARC
279 - populate the MARC-DB
280 To populate the DBs we have 2 differents sources :
281 - the standard acquisition system (through book sellers), that does'nt use MARC data
282 - the MARC acquisition system, that uses MARC data.
284 Thus, we have 2 differents cases :
285 - 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
286 - 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
288 That's why we need 4 subs :
289 all I<subs beginning by MARC> manage only MARC tables. They manage MARC-DB with MARC::Record parameters
290 all I<subs beginning by OLD> manage only OLD-DB tables. They manage old-DB with old-DB parameters
291 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
292 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.
294 - NEW and old-style API should be used in koha to manage biblio
295 - MARCsubs are divided in 2 parts :
296 * some of them manage MARC parameters. They are heavily used in koha.
297 * some of them manage MARC biblio : they are mostly used by NEW and old-style subs.
298 - OLD are used internally only
300 all subs requires/use $dbh as 1st parameter.
302 I<NEWxxx related subs>
304 all subs requires/use $dbh as 1st parameter.
305 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
307 I<OLDxxx related subs>
309 all subs requires/use $dbh as 1st parameter.
310 those subs are used by the MARC-compliant version of koha : marc import, or marc management.
312 They all are the exact copy of 1.0/1.2 version of the sub without the OLD.
313 The OLDxxx is called by the original xxx sub.
314 the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
316 WARNING : there is 1 difference between initialxxx and OLDxxx :
317 the db header $dbh is always passed as parameter to avoid over-DB connexion
323 =item @tagslib = &MARCgettagslib($dbh,1|0);
325 last param is 1 for liblibrarian and 0 for libopac
326 returns a hash with tag/subfield meaning
327 =item ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,$kohafield);
329 finds MARC tag and subfield for a given kohafield
330 kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table
332 =item $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$MARCbibi);
334 finds a old-db biblio number for a given MARCbibid number
336 =item $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
338 finds a MARC bibid from a old-db biblionumber
340 =item $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
342 MARCkoha2marcBiblio is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB biblio/biblioitem
344 =item $MARCRecord = &MARCkoha2marcItem($dbh,$biblionumber,itemnumber);
346 MARCkoha2marcItem is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB item
348 =item $MARCRecord = &MARCkoha2marcSubtitle($dbh,$biblionumber,$subtitle);
350 MARCkoha2marcSubtitle is a wrapper between old-DB and MARC-DB. It returns a MARC::Record builded with old-DB subtitle
352 =item $olddb = &MARCmarc2koha($dbh,$MARCRecord);
354 builds a hash with old-db datas from a MARC::Record
356 =item &MARCaddbiblio($dbh,$MARC::Record,$biblionumber);
358 creates a biblio (in the MARC tables only). $biblionumber is the old-db biblionumber of the biblio
360 =item &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
362 adds a subfield in a biblio (in the MARC tables only).
364 =item $MARCRecord = &MARCgetbiblio($dbh,$bibid);
366 Returns a MARC::Record for the biblio $bibid.
368 =item &MARCmodbiblio($dbh,$bibid,$record,$delete);
370 MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
371 if $delete == 1, every field/subfield not found is deleted in the biblio
372 otherwise, only data passed to MARCmodbiblio is managed.
373 thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
375 =item ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
377 MARCmodsubfield changes the value of a given subfield
379 =item $subfieldid = &MARCfindsubfield($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue);
381 MARCfindsubfield returns a subfield number given a bibid/tag/subfieldvalue values.
382 Returns -1 if more than 1 answer
384 =item $subfieldid = &MARCfindsubfieldid($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
386 MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldorder
388 =item &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
390 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
392 =item &MARCdelbiblio($dbh,$bibid);
394 MARCdelbiblio delete biblio $bibid
396 =item &MARCkoha2marcOnefield
398 used by MARCkoha2marc and should not be useful elsewhere
400 =item &MARCmarc2kohaOnefield
402 used by MARCmarc2koha and should not be useful elsewhere
406 used to manage MARC_word table and should not be useful elsewhere
410 used to manage MARC_word table and should not be useful elsewhere
415 my ($dbh,$forlibrarian)= @_;
417 my $libfield = ($forlibrarian eq 1)? 'liblibrarian' : 'libopac';
418 $sth=$dbh->prepare("select tagfield,$libfield as lib,mandatory from marc_tag_structure order by tagfield");
420 my ($lib,$tag,$res,$tab,$mandatory,$repeatable);
421 while ( ($tag,$lib,$mandatory) = $sth->fetchrow) {
422 $res->{$tag}->{lib}=$lib;
423 $res->{$tab}->{tab}=""; # XXX
424 $res->{$tag}->{mandatory}=$mandatory;
427 $sth=$dbh->prepare("select tagfield,tagsubfield,$libfield as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder from marc_subfield_structure order by tagfield,tagsubfield");
431 my $authorised_value;
432 my $thesaurus_category;
434 while ( ($tag, $subfield, $lib, $tab, $mandatory, $repeatable,$authorised_value,$thesaurus_category,$value_builder) = $sth->fetchrow) {
435 $res->{$tag}->{$subfield}->{lib}=$lib;
436 $res->{$tag}->{$subfield}->{tab}=$tab;
437 $res->{$tag}->{$subfield}->{mandatory}=$mandatory;
438 $res->{$tag}->{$subfield}->{repeatable}=$repeatable;
439 $res->{$tag}->{$subfield}->{authorised_value}=$authorised_value;
440 $res->{$tag}->{$subfield}->{thesaurus_category}=$thesaurus_category;
441 $res->{$tag}->{$subfield}->{value_builder}=$value_builder;
446 sub MARCfind_marc_from_kohafield {
447 my ($dbh,$kohafield) = @_;
448 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
449 $sth->execute($kohafield);
450 my ($tagfield,$tagsubfield) = $sth->fetchrow;
451 return ($tagfield,$tagsubfield);
454 sub MARCfind_oldbiblionumber_from_MARCbibid {
455 my ($dbh,$MARCbibid) = @_;
456 my $sth=$dbh->prepare("select biblionumber from marc_biblio where bibid=?");
457 $sth->execute($MARCbibid);
458 my ($biblionumber) = $sth->fetchrow;
459 return $biblionumber;
462 sub MARCfind_MARCbibid_from_oldbiblionumber {
463 my ($dbh,$oldbiblionumber) = @_;
464 my $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=?");
465 $sth->execute($oldbiblionumber);
466 my ($bibid) = $sth->fetchrow;
471 # pass the MARC::Record to this function, and it will create the records in the marc tables
472 my ($dbh,$record,$biblionumber) = @_;
473 my @fields=$record->fields();
475 # adding main table, and retrieving bibid
476 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
477 my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)");
478 $sth->execute($biblionumber);
479 $sth=$dbh->prepare("select max(bibid) from marc_biblio");
481 ($bibid)=$sth->fetchrow;
484 # now, add subfields...
485 foreach my $field (@fields) {
487 if ($field->tag() <10) {
488 &MARCaddsubfield($dbh,$bibid,
497 my @subfields=$field->subfields();
498 foreach my $subfieldcount (0..$#subfields) {
499 &MARCaddsubfield($dbh,$bibid,
501 $field->indicator(1).$field->indicator(2),
503 $subfields[$subfieldcount][0],
505 $subfields[$subfieldcount][1]
510 $dbh->do("unlock tables");
515 # pass the MARC::Record to this function, and it will create the records in the marc tables
516 my ($dbh,$record,$biblionumber) = @_;
517 # warn "adding : ".$record->as_formatted();
518 # search for MARC biblionumber
519 $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ");
520 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
521 my @fields=$record->fields();
522 my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
523 $sth->execute($bibid);
524 my ($fieldcount) = $sth->fetchrow;
525 # now, add subfields...
526 foreach my $field (@fields) {
527 my @subfields=$field->subfields();
529 foreach my $subfieldcount (0..$#subfields) {
530 &MARCaddsubfield($dbh,$bibid,
532 $field->indicator(1).$field->indicator(2),
534 $subfields[$subfieldcount][0],
536 $subfields[$subfieldcount][1]
538 # warn "ADDING :$bibid,".
540 # $field->indicator(1).$field->indicator(2).",
542 # $subfields[$subfieldcount][0],
544 # $subfields[$subfieldcount][1]";
547 $dbh->do("unlock tables");
551 sub MARCaddsubfield {
552 # Add a new subfield to a tag into the DB.
553 my ($dbh,$bibid,$tagid,$tag_indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
554 # if not value, end of job, we do nothing
555 if (length($subfieldvalue) ==0) {
558 if (not($subfieldcode)) {
561 if (length($subfieldvalue)>255) {
562 # $dbh->do("lock tables marc_blob_subfield WRITE, marc_subfield_table WRITE");
563 my $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
564 $sth->execute($subfieldvalue);
565 $sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
567 my ($res)=$sth->fetchrow;
568 $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?,?)");
569 $sth->execute($bibid,(sprintf "%03s",$tagid),$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$res);
571 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";
573 # $dbh->do("unlock tables");
575 my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)");
576 $sth->execute($bibid,(sprintf "%03s",$tagid),$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue);
578 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";
581 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
585 # Returns MARC::Record of the biblio passed in parameter.
587 my $record = MARC::Record->new();
588 #---- TODO : the leader is missing
589 $record->leader(' ');
590 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
591 from marc_subfield_table
592 where bibid=? order by tag,tagorder,subfieldcode
594 my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
595 $sth->execute($bibid);
600 while (my $row=$sth->fetchrow_hashref) {
601 if ($row->{'valuebloblink'}) { #---- search blob if there is one
602 $sth2->execute($row->{'valuebloblink'});
603 my $row2=$sth2->fetchrow_hashref;
605 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
607 # warn "prev : $prevtag . ".$row->{tag}." => ".$row->{subfieldvalue};
608 if ($row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag) {
612 $record->add_fields((sprintf "%03s",$prevtag),%subfieldlist->{'@'});
614 $field = MARC::Field->new( (sprintf "%03s",$prevtag), substr($previndicator,0,1), substr($previndicator,1,1), %subfieldlist);
615 $record->add_fields($field);
618 $prevtagorder=$row->{tagorder};
619 $prevtag = $row->{tag};
620 $previndicator=$row->{tag_indicator};
622 %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
624 %subfieldlist->{$row->{'subfieldcode'}} .= $row->{'subfieldvalue'};
625 $prevtag= $row->{tag};
626 $previndicator=$row->{tag_indicator};
629 # the last has not been included inside the loop... do it now !
631 $record->add_fields($prevtag,%subfieldlist->{'@'});
633 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
634 $record->add_fields($field);
639 # Returns MARC::Record of the biblio passed in parameter.
640 my ($dbh,$bibid,$itemnumber)=@_;
641 my $record = MARC::Record->new();
642 # search MARC tagorder
643 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=?");
644 $sth2->execute($bibid,$itemnumber);
645 my ($tagorder) = $sth2->fetchrow_array();
646 #---- TODO : the leader is missing
647 my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
648 from marc_subfield_table
649 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
651 $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
652 $sth->execute($bibid,$tagorder);
653 while (my $row=$sth->fetchrow_hashref) {
654 if ($row->{'valuebloblink'}) { #---- search blob if there is one
655 $sth2->execute($row->{'valuebloblink'});
656 my $row2=$sth2->fetchrow_hashref;
658 $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
660 if ($record->field($row->{'tag'})) {
662 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
663 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
664 if (length($row->{'tag'}) <3) {
665 $row->{'tag'} = "0".$row->{'tag'};
667 $field =$record->field($row->{'tag'});
669 my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
670 $record->delete_field($field);
671 $record->add_fields($field);
674 if (length($row->{'tag'}) < 3) {
675 $row->{'tag'} = "0".$row->{'tag'};
677 my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
678 $record->add_fields($temp);
686 my ($dbh,$bibid,$record,$delete)=@_;
687 my $oldrecord=&MARCgetbiblio($dbh,$bibid);
688 if ($oldrecord eq $record) {
691 # otherwise, skip through each subfield...
692 my @fields = $record->fields();
694 foreach my $field (@fields) {
695 my $oldfield = $oldrecord->field($field->tag());
696 my @subfields=$field->subfields();
699 if ($field->tag() <10) {
700 if ($oldfield eq 0 or (! $oldfield->data()) ) {
701 &MARCaddsubfield($dbh,$bibid,$field->tag(),'',
702 1,'@',1,$field->data());
704 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,'@',$subfieldorder);
705 &MARCmodsubfield($dbh,$subfieldid,$field->data());
708 foreach my $subfield (@subfields) {
710 if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) {
711 # just adding datas...
712 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
713 1,@$subfield[0],$subfieldorder,@$subfield[1]);
715 # modify the subfield if it's a different string
716 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
717 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
718 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
726 my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
727 my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
728 # if nothing to change, don't waste time...
729 if ($oldrecord eq $record) {
730 # warn "nothing to change";
733 # warn "MARCmoditem : ".$record->as_formatted;
734 # warn "OLD : ".$oldrecord->as_formatted;
736 # otherwise, skip through each subfield...
737 my @fields = $record->fields();
738 # search old MARC item
739 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=?");
740 $sth2->execute($bibid,$itemnumber);
741 my ($tagorder) = $sth2->fetchrow_array();
742 foreach my $field (@fields) {
743 my $oldfield = $oldrecord->field($field->tag());
744 my @subfields=$field->subfields();
746 foreach my $subfield (@subfields) {
748 # warn "compare : $oldfield".$oldfield->subfield(@$subfield[0]);
749 if ($oldfield eq 0 or (length($oldfield->subfield(@$subfield[0])) ==0) ) {
750 # just adding datas...
751 # warn "addfield : / $subfieldorder / @$subfield[0] - @$subfield[1]";
752 # warn "NEW subfield : $bibid,".$field->tag().",".$tagorder.",".@$subfield[0].",".$subfieldorder.",".@$subfield[1].")";
753 &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
754 $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
756 # warn "modfield : / $subfieldorder / @$subfield[0] - @$subfield[1]";
757 # modify he subfield if it's a different string
758 if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
759 my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
760 # warn "changing : $subfieldid, $bibid,".$field->tag(),",$tagorder,@$subfield[0],@$subfield[1],$subfieldorder";
761 &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
769 sub MARCmodsubfield {
770 # Subroutine changes a subfield value given a subfieldid.
771 my ($dbh, $subfieldid, $subfieldvalue )=@_;
772 $dbh->do("lock tables marc_blob_subfield WRITE,marc_subfield_table WRITE");
773 my $sth1=$dbh->prepare("select valuebloblink from marc_subfield_table where subfieldid=?");
774 $sth1->execute($subfieldid);
775 my ($oldvaluebloblink)=$sth1->fetchrow;
778 # if too long, use a bloblink
779 if (length($subfieldvalue)>255 ) {
780 # if already a bloblink, update it, otherwise, insert a new one.
781 if ($oldvaluebloblink) {
782 $sth=$dbh->prepare("update marc_blob_subfield set subfieldvalue=? where blobidlink=?");
783 $sth->execute($subfieldvalue,$oldvaluebloblink);
785 $sth=$dbh->prepare("insert into marc_blob_subfield (subfieldvalue) values (?)");
786 $sth->execute($subfieldvalue);
787 $sth=$dbh->prepare("select max(blobidlink) from marc_blob_subfield");
789 my ($res)=$sth->fetchrow;
790 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=null, valuebloblink=$res where subfieldid=?");
791 $sth->execute($subfieldid);
794 # note this can leave orphan bloblink. Not a big problem, but we should build somewhere a orphan deleting script...
795 $sth=$dbh->prepare("update marc_subfield_table set subfieldvalue=?,valuebloblink=null where subfieldid=?");
796 $sth->execute($subfieldvalue, $subfieldid);
798 $dbh->do("unlock tables");
800 $sth=$dbh->prepare("select bibid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from marc_subfield_table where subfieldid=?");
801 $sth->execute($subfieldid);
802 my ($bibid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
804 &MARCdelword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
805 &MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
806 return($subfieldid, $subfieldvalue);
809 sub MARCfindsubfield {
810 my ($dbh,$bibid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
814 my $query="select subfieldid from marc_subfield_table where bibid=? and tag=? and subfieldcode=?";
815 if ($subfieldvalue) {
816 $query .= " and subfieldvalue=".$dbh->quote($subfieldvalue);
818 if ($subfieldorder<1) {
821 $query .= " and subfieldorder=$subfieldorder";
823 my $sti=$dbh->prepare($query);
824 $sti->execute($bibid,$tag, $subfieldcode);
825 while (($subfieldid) = $sti->fetchrow) {
827 $lastsubfieldid=$subfieldid;
829 if ($resultcounter>1) {
830 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
831 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
834 return $lastsubfieldid;
838 sub MARCfindsubfieldid {
839 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
840 my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
841 where bibid=? and tag=? and tagorder=?
842 and subfieldcode=? and subfieldorder=?");
843 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
844 my ($res) = $sth->fetchrow;
846 $sth=$dbh->prepare("select subfieldid from marc_subfield_table
847 where bibid=? and tag=? and tagorder=?
848 and subfieldcode=?");
849 $sth->execute($bibid,$tag,$tagorder,$subfield);
850 ($res) = $sth->fetchrow;
855 sub MARCdelsubfield {
856 # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
857 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
858 $dbh->do("delete from marc_subfield_table where bibid='$bibid' and
859 tag='$tag' and tagorder='$tagorder'
860 and subfieldcode='$subfield' and subfieldorder='$subfieldorder
865 # delete a biblio for a $bibid
866 my ($dbh,$bibid) = @_;
867 $dbh->do("delete from marc_subfield_table where bibid='$bibid'");
868 $dbh->do("delete from marc_biblio where bibid='$bibid'");
871 sub MARCkoha2marcBiblio {
872 # this function builds partial MARC::Record from the old koha-DB fields
873 my ($dbh,$biblionumber,$biblioitemnumber) = @_;
874 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
875 my $record = MARC::Record->new();
876 #--- if bibid, then retrieve old-style koha data
877 if ($biblionumber>0) {
878 my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
879 from biblio where biblionumber=?");
880 $sth2->execute($biblionumber);
881 my $row=$sth2->fetchrow_hashref;
883 foreach $code (keys %$row) {
885 &MARCkoha2marcOnefield($sth,$record,"biblio.".$code,$row->{$code});
889 #--- if biblioitem, then retrieve old-style koha data
890 if ($biblioitemnumber>0) {
891 my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
892 itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
893 volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
895 WHERE biblionumber=? and biblioitemnumber=?
897 $sth2->execute($biblionumber,$biblioitemnumber);
898 my $row=$sth2->fetchrow_hashref;
900 foreach $code (keys %$row) {
902 &MARCkoha2marcOnefield($sth,$record,"biblioitems.".$code,$row->{$code});
907 # TODO : retrieve notes, additionalauthors
910 sub MARCkoha2marcItem {
911 # this function builds partial MARC::Record from the old koha-DB fields
912 my ($dbh,$biblionumber,$itemnumber) = @_;
913 # my $dbh=&C4Connect;
914 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
915 my $record = MARC::Record->new();
916 #--- if item, then retrieve old-style koha data
918 # print STDERR "prepare $biblionumber,$itemnumber\n";
919 my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
920 booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
921 datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
922 reserves,restricted,binding,itemnotes,holdingbranch,timestamp
924 WHERE itemnumber=?");
925 $sth2->execute($itemnumber);
926 my $row=$sth2->fetchrow_hashref;
928 foreach $code (keys %$row) {
930 &MARCkoha2marcOnefield($sth,$record,"items.".$code,$row->{$code});
935 # TODO : retrieve notes, additionalauthors
938 sub MARCkoha2marcSubtitle {
939 # this function builds partial MARC::Record from the old koha-DB fields
940 my ($dbh,$bibnum,$subtitle) = @_;
941 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
942 my $record = MARC::Record->new();
943 &MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.subtitle",$subtitle);
947 sub MARCkoha2marcOnefield {
948 my ($sth,$record,$kohafieldname,$value)=@_;
951 $sth->execute($kohafieldname);
952 if (($tagfield,$tagsubfield)=$sth->fetchrow) {
953 if ($record->field($tagfield)) {
954 my $tag =$record->field($tagfield);
956 $tag->add_subfields($tagsubfield,$value);
957 $record->delete_field($tag);
958 $record->add_fields($tag);
961 $record->add_fields($tagfield," "," ",$tagsubfield => $value);
968 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
969 my $prevtag = @$rtags[0];
970 my $record = MARC::Record->new();
972 for (my $i=0; $i< @$rtags; $i++) {
973 # rebuild MARC::Record
974 if (@$rtags[$i] ne $prevtag) {
978 $indicators{$prevtag}.=' ';
980 $record->add_fields((sprintf "%03s",$prevtag),%subfieldlist->{'@'});
982 my $field = MARC::Field->new( (sprintf "%03s",$prevtag), substr($indicators{$prevtag},0,1),substr($indicators{$prevtag},1,1), %subfieldlist);
983 $record->add_fields($field);
985 $prevtag = @$rtags[$i];
987 %subfieldlist->{@$rsubfields[$i]} = @$rvalues[$i];
989 if (%subfieldlist->{@$rsubfields[$i]}) {
990 %subfieldlist->{@$rsubfields[$i]} .= '|';
992 %subfieldlist->{@$rsubfields[$i]} .=@$rvalues[$i];
993 $prevtag= @$rtags[$i];
996 # the last has not been included inside the loop... do it now !
997 my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
998 $record->add_fields($field);
1003 my ($dbh,$record) = @_;
1004 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
1006 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
1009 # print STDERR $record->as_formatted;
1010 while (($field)=$sth2->fetchrow) {
1011 $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
1013 $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
1015 while (($field)=$sth2->fetchrow) {
1016 $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
1018 $sth2=$dbh->prepare("SHOW COLUMNS from items");
1020 while (($field)=$sth2->fetchrow) {
1021 $result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
1023 # additional authors : specific
1024 $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
1028 sub MARCmarc2kohaOneField {
1029 # FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
1030 my ($sth,$kohatable,$kohafield,$record,$result)= @_;
1031 # warn "kohatable / $kohafield / $result / ";
1035 $sth->execute($kohatable.".".$kohafield);
1036 ($tagfield,$subfield) = $sth->fetchrow;
1037 foreach my $field ($record->field($tagfield)) {
1038 if ($field->subfield($subfield)) {
1039 if ($result->{$kohafield}) {
1040 $result->{$kohafield} .= " | ".$field->subfield($subfield);
1042 $result->{$kohafield}=$field->subfield($subfield);
1050 # split a subfield string and adds it into the word table.
1052 my ($dbh,$bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
1053 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
1054 my @words = split / /,$sentence;
1055 my $stopwords= C4::Context->stopwords;
1056 my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
1057 values (?,?,?,?,?,?,soundex(?))");
1058 foreach my $word (@words) {
1059 # we record only words longer than 2 car and not in stopwords hash
1060 if (length($word)>1 and !($stopwords->{uc($word)})) {
1061 $sth->execute($bibid,$tag,$tagorder,$subfieldid,$subfieldorder,$word,$word);
1063 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";
1070 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
1071 my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
1072 my $sth=$dbh->prepare("delete from marc_word where bibid=? and tag=? and tagorder=? and subfieldid=? and subfieldorder=?");
1073 $sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
1078 # NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW
1081 # all the following subs are useful to manage MARC-DB with complete MARC records.
1082 # it's used with marcimport, and marc management tools
1086 =item (oldbibnum,$oldbibitemnum) = NEWnewbibilio($dbh,$MARCRecord,$oldbiblio,$oldbiblioitem);
1088 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
1089 are builded from the MARC::Record. If they are passed, they are used.
1091 =item NEWnewitem($dbh,$olditem);
1093 adds an item in the db. $olditem is a old-db hash.
1098 my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
1099 # note $oldbiblio and $oldbiblioitem are not mandatory.
1100 # if not present, they will be builded from $record with MARCmarc2koha function
1101 if (($oldbiblio) and not($oldbiblioitem)) {
1102 print STDERR "NEWnewbiblio : missing parameter\n";
1103 print "NEWnewbiblio : missing parameter : contact koha development team\n";
1109 $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
1110 $oldbiblioitem->{'biblionumber'} = $oldbibnum;
1111 $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
1113 my $olddata = MARCmarc2koha($dbh,$record);
1114 $oldbibnum = OLDnewbiblio($dbh,$olddata);
1115 $olddata->{'biblionumber'} = $oldbibnum;
1116 $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
1118 # we must add bibnum and bibitemnum in MARC::Record...
1119 # we build the new field with biblionumber and biblioitemnumber
1120 # we drop the original field
1121 # we add the new builded field.
1122 # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
1123 # (steve and paul : thinks 090 is a good choice)
1124 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
1125 $sth->execute("biblio.biblionumber");
1126 (my $tagfield1, my $tagsubfield1) = $sth->fetchrow;
1127 $sth->execute("biblioitems.biblioitemnumber");
1128 (my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
1129 if ($tagfield1 != $tagfield2) {
1130 print STDERR "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1131 print "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
1134 my $newfield = MARC::Field->new( $tagfield1,'','',
1135 "$tagsubfield1" => $oldbibnum,
1136 "$tagsubfield2" => $oldbibitemnum);
1137 # drop old field and create new one...
1138 my $old_field = $record->field($tagfield1);
1139 $record->delete_field($old_field);
1140 $record->add_fields($newfield);
1141 my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
1142 return ($bibid,$oldbibnum,$oldbibitemnum );
1146 my ($dbh,$record,$bibid) =@_;
1147 &MARCmodbiblio($dbh,$bibid,$record,0);
1148 my $oldbiblio = MARCmarc2koha($dbh,$record);
1149 my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
1150 OLDmodbibitem($dbh,$oldbiblio);
1156 my ($dbh, $record,$bibid) = @_;
1157 # add item in old-DB
1158 my $item = &MARCmarc2koha($dbh,$record);
1159 # needs old biblionumber and biblioitemnumber
1160 $item->{'biblionumber'} = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
1161 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
1162 $sth->execute($item->{'biblionumber'});
1163 ($item->{'biblioitemnumber'}) = $sth->fetchrow;
1164 my ($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{barcode});
1165 # add itemnumber to MARC::Record before adding the item.
1166 my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
1167 &MARCkoha2marcOnefield($sth,$record,"items.itemnumber",$itemnumber);
1169 my $bib = &MARCadditem($dbh,$record,$item->{'biblionumber'});
1173 my ($dbh,$record,$bibid,$itemnumber,$delete) = @_;
1174 &MARCmoditem($dbh,$record,$bibid,$itemnumber,$delete);
1175 my $olditem = MARCmarc2koha($dbh,$record);
1176 OLDmoditem($dbh,$olditem);
1181 # OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
1185 =item $biblionumber = OLDnewbiblio($dbh,$biblio);
1187 adds a record in biblio table. Datas are in the hash $biblio.
1189 =item $biblionumber = OLDmodbiblio($dbh,$biblio);
1191 modify a record in biblio table. Datas are in the hash $biblio.
1193 =item OLDmodsubtitle($dbh,$bibnum,$subtitle);
1195 modify subtitles in bibliosubtitle table.
1197 =item OLDmodaddauthor($dbh,$bibnum,$author);
1199 adds or modify additional authors
1200 NOTE : Strange sub : seems to delete MANY and add only ONE author... maybe buggy ?
1202 =item $errors = OLDmodsubject($dbh,$bibnum, $force, @subject);
1204 modify/adds subjects
1206 =item OLDmodbibitem($dbh, $biblioitem);
1210 =item OLDmodnote($dbh,$bibitemnum,$note
1212 modify a note for a biblioitem
1214 =item OLDnewbiblioitem($dbh,$biblioitem);
1216 adds a biblioitem ($biblioitem is a hash with the values)
1218 =item OLDnewsubject($dbh,$bibnum);
1222 =item OLDnewsubtitle($dbh,$bibnum,$subtitle);
1224 create a new subtitle
1226 =item ($itemnumber,$errors)= OLDnewitems($dbh,$item,$barcode);
1228 create a item. $item is a hash and $barcode the barcode.
1230 =item OLDmoditem($dbh,$item);
1234 =item OLDdelitem($dbh,$itemnum);
1238 =item OLDdeletebiblioitem($dbh,$biblioitemnumber);
1240 deletes a biblioitem
1241 NOTE : not standard sub name. Should be OLDdelbiblioitem()
1243 =item OLDdelbiblio($dbh,$biblio);
1250 my ($dbh,$biblio) = @_;
1251 # my $dbh = &C4Connect;
1252 my $query = "Select max(biblionumber) from biblio";
1253 my $sth = $dbh->prepare($query);
1255 my $data = $sth->fetchrow_arrayref;
1256 my $bibnum = $$data[0] + 1;
1259 if ($biblio->{'seriestitle'}) { $series = 1 };
1261 $query = "insert into biblio set biblionumber = ?, title = ?, author = ?, copyrightdate = ?,
1262 serial = ?, seriestitle = ?, notes = ?, abstract = ?";
1263 $sth = $dbh->prepare($query);
1264 $sth->execute($bibnum,$biblio->{'title'},$biblio->{'author'},$biblio->{'copyright'},$series,$biblio->{'seriestitle'},$biblio->{'notes'},$biblio->{'abstract'});
1272 my ($dbh,$biblio) = @_;
1273 # my $dbh = C4Connect;
1277 $query = "Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?,
1278 seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?";
1279 $sth = $dbh->prepare($query);
1280 $sth->execute($biblio->{'title'},$biblio->{'author'},$biblio->{'abstract'},$biblio->{'copyrightdate'},
1281 $biblio->{'seriestitle'},$biblio->{'serial'},$biblio->{'unititle'},$biblio->{'notes'},$biblio->{'biblionumber'});
1284 return($biblio->{'biblionumber'});
1287 sub OLDmodsubtitle {
1288 my ($dbh,$bibnum, $subtitle) = @_;
1289 my $query = "update bibliosubtitle set subtitle = ? where biblionumber = ?";
1290 my $sth = $dbh->prepare($query);
1291 $sth->execute($subtitle,$bibnum);
1296 sub OLDmodaddauthor {
1297 my ($dbh,$bibnum, $author) = @_;
1298 # my $dbh = C4Connect;
1299 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
1300 my $sth = $dbh->prepare($query);
1305 if ($author ne '') {
1306 $query = "Insert into additionalauthors set
1309 $sth = $dbh->prepare($query);
1311 $sth->execute($author,$bibnum);
1315 } # sub modaddauthor
1319 my ($dbh,$bibnum, $force, @subject) = @_;
1320 # my $dbh = C4Connect;
1321 my $count = @subject;
1323 for (my $i = 0; $i < $count; $i++) {
1324 $subject[$i] =~ s/^ //g;
1325 $subject[$i] =~ s/ $//g;
1326 my $query = "select * from catalogueentry
1327 where entrytype = 's'
1328 and catalogueentry = '$subject[$i]'";
1329 my $sth = $dbh->prepare($query);
1332 if (my $data = $sth->fetchrow_hashref) {
1334 if ($force eq $subject[$i]) {
1335 # subject not in aut, chosen to force anway
1336 # so insert into cataloguentry so its in auth file
1337 $query = "Insert into catalogueentry
1338 (entrytype,catalogueentry)
1339 values ('s','$subject[$i]')";
1340 my $sth2 = $dbh->prepare($query);
1345 $error = "$subject[$i]\n does not exist in the subject authority file";
1346 $query = "Select * from catalogueentry
1347 where entrytype = 's'
1348 and (catalogueentry like '$subject[$i] %'
1349 or catalogueentry like '% $subject[$i] %'
1350 or catalogueentry like '% $subject[$i]')";
1351 my $sth2 = $dbh->prepare($query);
1354 while (my $data = $sth2->fetchrow_hashref) {
1355 $error .= "<br>$data->{'catalogueentry'}";
1363 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
1364 my $sth = $dbh->prepare($query);
1367 for (my $i = 0; $i < $count; $i++) {
1368 $sth = $dbh->prepare("Insert into bibliosubject
1369 values ('$subject[$i]', $bibnum)");
1381 my ($dbh,$biblioitem) = @_;
1382 # my $dbh = C4Connect;
1385 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
1386 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
1387 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
1388 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
1389 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
1390 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
1391 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
1392 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
1393 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
1394 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
1395 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
1396 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
1397 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
1398 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
1400 $query = "Update biblioitems set
1401 itemtype = $biblioitem->{'itemtype'},
1402 url = $biblioitem->{'url'},
1403 isbn = $biblioitem->{'isbn'},
1404 publishercode = $biblioitem->{'publishercode'},
1405 publicationyear = $biblioitem->{'publicationyear'},
1406 classification = $biblioitem->{'classification'},
1407 dewey = $biblioitem->{'dewey'},
1408 subclass = $biblioitem->{'subclass'},
1409 illus = $biblioitem->{'illus'},
1410 pages = $biblioitem->{'pages'},
1411 volumeddesc = $biblioitem->{'volumeddesc'},
1412 notes = $biblioitem->{'notes'},
1413 size = $biblioitem->{'size'},
1414 place = $biblioitem->{'place'}
1415 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
1423 my ($dbh,$bibitemnum,$note)=@_;
1424 # my $dbh=C4Connect;
1425 my $query="update biblioitems set notes='$note' where
1426 biblioitemnumber='$bibitemnum'";
1427 my $sth=$dbh->prepare($query);
1433 sub OLDnewbiblioitem {
1434 my ($dbh,$biblioitem) = @_;
1435 # my $dbh = C4Connect;
1436 my $query = "Select max(biblioitemnumber) from biblioitems";
1437 my $sth = $dbh->prepare($query);
1442 $data = $sth->fetchrow_arrayref;
1443 $bibitemnum = $$data[0] + 1;
1447 $sth = $dbh->prepare("insert into biblioitems set
1448 biblioitemnumber = ?, biblionumber = ?,
1449 volume = ?, number = ?,
1450 classification = ?, itemtype = ?,
1452 issn = ?, dewey = ?,
1453 subclass = ?, publicationyear = ?,
1454 publishercode = ?, volumedate = ?,
1455 volumeddesc = ?, illus = ?,
1456 pages = ?, notes = ?,
1458 marc = ?, place = ?");
1459 $sth->execute($bibitemnum, $biblioitem->{'biblionumber'},
1460 $biblioitem->{'volume'}, $biblioitem->{'number'},
1461 $biblioitem->{'classification'}, $biblioitem->{'itemtype'},
1462 $biblioitem->{'url'}, $biblioitem->{'isbn'},
1463 $biblioitem->{'issn'}, $biblioitem->{'dewey'},
1464 $biblioitem->{'subclass'}, $biblioitem->{'publicationyear'},
1465 $biblioitem->{'publishercode'}, $biblioitem->{'volumedate'},
1466 $biblioitem->{'volumeddesc'}, $biblioitem->{'illus'},
1467 $biblioitem->{'pages'}, $biblioitem->{'notes'},
1468 $biblioitem->{'size'}, $biblioitem->{'lccn'},
1469 $biblioitem->{'marc'}, $biblioitem->{'place'});
1472 return($bibitemnum);
1476 my ($dbh,$bibnum)=@_;
1477 # my $dbh=C4Connect;
1478 my $query="insert into bibliosubject (biblionumber) values
1480 my $sth=$dbh->prepare($query);
1487 sub OLDnewsubtitle {
1488 my ($dbh,$bibnum, $subtitle) = @_;
1489 # my $dbh = C4Connect;
1490 my $query = "insert into bibliosubtitle set
1493 my $sth = $dbh->prepare($query);
1495 $sth->execute($bibnum,$subtitle);
1503 my ($dbh,$item, $barcode) = @_;
1504 # my $dbh = C4Connect;
1505 my $query = "Select max(itemnumber) from items";
1506 my $sth = $dbh->prepare($query);
1512 $data = $sth->fetchrow_hashref;
1513 $itemnumber = $data->{'max(itemnumber)'} + 1;
1516 $sth=$dbh->prepare("Insert into items set
1517 itemnumber = ?, biblionumber = ?,
1518 biblioitemnumber = ?, barcode = ?,
1519 booksellerid = ?, dateaccessioned = NOW(),
1520 homebranch = ?, holdingbranch = ?,
1521 price = ?, replacementprice = ?,
1522 replacementpricedate = NOW(), itemnotes = ?,
1525 $sth->execute($itemnumber, $item->{'biblionumber'},
1526 $item->{'biblioitemnumber'},$barcode,
1527 $item->{'booksellerid'},
1528 $item->{'homebranch'},$item->{'homebranch'},
1529 $item->{'price'},$item->{'replacementprice'},
1530 $item->{'itemnotes'},$item->{'loan'});
1531 if (defined $sth->errstr) {
1532 $error .= $sth->errstr;
1535 return($itemnumber,$error);
1539 my ($dbh,$item) = @_;
1540 # my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1541 # my $dbh=C4Connect;
1542 $item->{'itemnum'}=$item->{'itemnumber'} unless $item->{'itemnum'};
1543 my $query="update items set barcode='$item->{'barcode'}',itemnotes='$item->{'notes'}'
1544 where itemnumber=$item->{'itemnum'}";
1545 if ($item->{'barcode'} eq ''){
1546 $query="update items set notforloan=$item->{'loan'} where itemnumber=$item->{'itemnum'}";
1548 if ($item->{'lost'} ne ''){
1549 $query="update items set biblioitemnumber=$item->{'bibitemnum'},
1550 barcode='$item->{'barcode'}',
1551 itemnotes='$item->{'notes'}',
1552 homebranch='$item->{'homebranch'}',
1553 itemlost='$item->{'lost'}',
1554 wthdrawn='$item->{'wthdrawn'}'
1555 where itemnumber=$item->{'itemnum'}";
1557 if ($item->{'replacement'} ne ''){
1558 $query=~ s/ where/,replacementprice='$item->{'replacement'}' where/;
1560 my $sth=$dbh->prepare($query);
1567 my ($dbh,$itemnum)=@_;
1568 # my $dbh=C4Connect;
1569 my $query="select * from items where itemnumber=$itemnum";
1570 my $sth=$dbh->prepare($query);
1572 my @data=$sth->fetchrow_array;
1574 $query="Insert into deleteditems values (";
1575 foreach my $temp (@data){
1576 $query .= "'$temp',";
1580 $sth=$dbh->prepare($query);
1583 $query = "Delete from items where itemnumber=$itemnum";
1584 $sth=$dbh->prepare($query);
1590 sub OLDdeletebiblioitem {
1591 my ($dbh,$biblioitemnumber) = @_;
1592 # my $dbh = C4Connect;
1593 my $query = "Select * from biblioitems
1594 where biblioitemnumber = $biblioitemnumber";
1595 my $sth = $dbh->prepare($query);
1600 if (@results = $sth->fetchrow_array) {
1601 $query = "Insert into deletedbiblioitems values (";
1602 foreach my $value (@results) {
1603 $value = $dbh->quote($value);
1604 $query .= "$value,";
1607 $query =~ s/\,$/\)/;
1610 $query = "Delete from biblioitems
1611 where biblioitemnumber = $biblioitemnumber";
1615 # Now delete all the items attached to the biblioitem
1616 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1617 $sth = $dbh->prepare($query);
1619 while (@results = $sth->fetchrow_array) {
1620 $query = "Insert into deleteditems values (";
1621 foreach my $value (@results) {
1622 $value = $dbh->quote($value);
1623 $query .= "$value,";
1625 $query =~ s/\,$/\)/;
1629 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1632 } # sub deletebiblioitem
1635 my ($dbh,$biblio)=@_;
1636 # my $dbh=C4Connect;
1637 my $query="select * from biblio where biblionumber=$biblio";
1638 my $sth=$dbh->prepare($query);
1640 if (my @data=$sth->fetchrow_array){
1642 $query="Insert into deletedbiblio values (";
1643 foreach my $temp (@data){
1644 $temp=~ s/\'/\\\'/g;
1645 $query .= "'$temp',";
1649 $sth=$dbh->prepare($query);
1652 $query = "Delete from biblio where biblionumber=$biblio";
1653 $sth=$dbh->prepare($query);
1669 my $dbh = C4::Context->dbh;
1670 my $query="Select count(*) from items where biblionumber=$biblio";
1672 my $sth=$dbh->prepare($query);
1674 my $data=$sth->fetchrow_hashref;
1676 return($data->{'count(*)'});
1681 ($order, $ordernumber) = &getorder($biblioitemnumber, $biblionumber);
1683 Looks up the order with the given biblionumber and biblioitemnumber.
1685 Returns a two-element array. C<$ordernumber> is the order number.
1686 C<$order> is a reference-to-hash describing the order; its keys are
1687 fields from the biblio, biblioitems, aqorders, and aqorderbreakdown
1688 tables of the Koha database.
1692 # FIXME - This is effectively identical to &C4::Catalogue::getorder.
1693 # Pick one and stick with it.
1696 my $dbh = C4::Context->dbh;
1697 my $query="Select ordernumber
1699 where biblionumber=? and biblioitemnumber=?";
1700 my $sth=$dbh->prepare($query);
1701 $sth->execute($bib,$bi);
1702 # FIXME - Use fetchrow_array(), since we're only interested in the one
1704 my $ordnum=$sth->fetchrow_hashref;
1706 my $order=getsingleorder($ordnum->{'ordernumber'});
1708 return ($order,$ordnum->{'ordernumber'});
1711 =item getsingleorder
1713 $order = &getsingleorder($ordernumber);
1715 Looks up an order by order number.
1717 Returns a reference-to-hash describing the order. The keys of
1718 C<$order> are fields from the biblio, biblioitems, aqorders, and
1719 aqorderbreakdown tables of the Koha database.
1723 # FIXME - This is effectively identical to
1724 # &C4::Catalogue::getsingleorder.
1725 # Pick one and stick with it.
1726 sub getsingleorder {
1728 my $dbh = C4::Context->dbh;
1729 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
1730 where aqorders.ordernumber=?
1731 and biblio.biblionumber=aqorders.biblionumber and
1732 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
1733 aqorders.ordernumber=aqorderbreakdown.ordernumber";
1734 my $sth=$dbh->prepare($query);
1735 $sth->execute($ordnum);
1736 my $data=$sth->fetchrow_hashref;
1743 my $dbh = C4::Context->dbh;
1744 my $bibnum=OLDnewbiblio($dbh,$biblio);
1751 $biblionumber = &modbiblio($biblio);
1753 Update a biblio record.
1755 C<$biblio> is a reference-to-hash whose keys are the fields in the
1756 biblio table in the Koha database. All fields must be present, not
1757 just the ones you wish to change.
1759 C<&modbiblio> updates the record defined by
1760 C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
1762 C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
1769 my $dbh = C4::Context->dbh;
1770 my $biblionumber=OLDmodbiblio($dbh,$biblio);
1771 return($biblionumber);
1777 &modsubtitle($biblionumber, $subtitle);
1779 Sets the subtitle of a book.
1781 C<$biblionumber> is the biblionumber of the book to modify.
1783 C<$subtitle> is the new subtitle.
1788 my ($bibnum, $subtitle) = @_;
1789 my $dbh = C4::Context->dbh;
1790 &OLDmodsubtitle($dbh,$bibnum,$subtitle);
1795 &modaddauthor($biblionumber, $author);
1797 Replaces all additional authors for the book with biblio number
1798 C<$biblionumber> with C<$author>. If C<$author> is the empty string,
1799 C<&modaddauthor> deletes all additional authors.
1804 my ($bibnum, $author) = @_;
1805 my $dbh = C4::Context->dbh;
1806 &OLDmodaddauthor($dbh,$bibnum,$author);
1807 } # sub modaddauthor
1811 $error = &modsubject($biblionumber, $force, @subjects);
1813 $force - a subject to force
1815 $error - Error message, or undef if successful.
1820 my ($bibnum, $force, @subject) = @_;
1821 my $dbh = C4::Context->dbh;
1822 my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
1827 my ($biblioitem) = @_;
1828 my $dbh = C4::Context->dbh;
1829 &OLDmodbibitem($dbh,$biblioitem);
1830 my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
1831 &MARCmodbiblio($dbh,$biblioitem->{biblionumber},$MARCbibitem,0);
1835 my ($bibitemnum,$note)=@_;
1836 my $dbh = C4::Context->dbh;
1837 &OLDmodnote($dbh,$bibitemnum,$note);
1841 my ($biblioitem) = @_;
1842 my $dbh = C4::Context->dbh;
1843 my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
1844 # print STDERR "bibitemnum : $bibitemnum\n";
1845 my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
1846 # print STDERR $MARCbiblio->as_formatted();
1847 &MARCaddbiblio($dbh,$MARCbiblio,$biblioitem->{biblionumber});
1848 return($bibitemnum);
1853 my $dbh = C4::Context->dbh;
1854 &OLDnewsubject($dbh,$bibnum);
1858 my ($bibnum, $subtitle) = @_;
1859 my $dbh = C4::Context->dbh;
1860 &OLDnewsubtitle($dbh,$bibnum,$subtitle);
1864 my ($item, @barcodes) = @_;
1865 my $dbh = C4::Context->dbh;
1869 foreach my $barcode (@barcodes) {
1870 ($itemnumber,$error)=&OLDnewitems($dbh,$item,uc($barcode));
1872 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{biblionumber},$itemnumber);
1873 &MARCadditem($dbh,$MARCitem,$item->{biblionumber});
1880 my $dbh = C4::Context->dbh;
1881 &OLDmoditem($dbh,$item);
1882 my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
1883 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
1884 &MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
1888 my ($count,@barcodes)=@_;
1889 my $dbh = C4::Context->dbh;
1891 for (my $i=0;$i<$count;$i++){
1892 $barcodes[$i]=uc $barcodes[$i];
1893 my $query="Select * from items where barcode='$barcodes[$i]'";
1894 my $sth=$dbh->prepare($query);
1896 if (my $data=$sth->fetchrow_hashref){
1897 $error.=" Duplicate Barcode: $barcodes[$i]";
1905 my ($bibitemnum)=@_;
1906 my $dbh = C4::Context->dbh;
1907 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1908 my $sth=$dbh->prepare($query);
1910 my $data=$sth->fetchrow_hashref;
1912 return($data->{'count(*)'});
1917 my $dbh = C4::Context->dbh;
1918 &OLDdelitem($dbh,$itemnum);
1921 sub deletebiblioitem {
1922 my ($biblioitemnumber) = @_;
1923 my $dbh = C4::Context->dbh;
1924 &OLDdeletebiblioitem($dbh,$biblioitemnumber);
1925 } # sub deletebiblioitem
1930 my $dbh = C4::Context->dbh;
1931 &OLDdelbiblio($dbh,$biblio);
1935 my $dbh = C4::Context->dbh;
1936 my $query = "select * from itemtypes";
1937 my $sth = $dbh->prepare($query);
1938 # || die "Cannot prepare $query" . $dbh->errstr;
1943 # || die "Cannot execute $query\n" . $sth->errstr;
1944 while (my $data = $sth->fetchrow_hashref) {
1945 $results[$count] = $data;
1950 return($count, @results);
1951 } # sub getitemtypes
1954 my ($biblionumber) = @_;
1955 my $dbh = C4::Context->dbh;
1956 my $query = "Select * from biblio where biblionumber = $biblionumber";
1957 my $sth = $dbh->prepare($query);
1958 # || die "Cannot prepare $query\n" . $dbh->errstr;
1963 # || die "Cannot execute $query\n" . $sth->errstr;
1964 while (my $data = $sth->fetchrow_hashref) {
1965 $results[$count] = $data;
1970 return($count, @results);
1974 my ($biblioitemnum) = @_;
1975 my $dbh = C4::Context->dbh;
1976 my $query = "Select * from biblioitems where
1977 biblioitemnumber = $biblioitemnum";
1978 my $sth = $dbh->prepare($query);
1984 while (my $data = $sth->fetchrow_hashref) {
1985 $results[$count] = $data;
1990 return($count, @results);
1991 } # sub getbiblioitem
1993 sub getbiblioitembybiblionumber {
1994 my ($biblionumber) = @_;
1995 my $dbh = C4::Context->dbh;
1996 my $query = "Select * from biblioitems where biblionumber =
1998 my $sth = $dbh->prepare($query);
2004 while (my $data = $sth->fetchrow_hashref) {
2005 $results[$count] = $data;
2010 return($count, @results);
2013 sub getitemsbybiblioitem {
2014 my ($biblioitemnum) = @_;
2015 my $dbh = C4::Context->dbh;
2016 my $query = "Select * from items, biblio where
2017 biblio.biblionumber = items.biblionumber and biblioitemnumber
2019 my $sth = $dbh->prepare($query);
2020 # || die "Cannot prepare $query\n" . $dbh->errstr;
2025 # || die "Cannot execute $query\n" . $sth->errstr;
2026 while (my $data = $sth->fetchrow_hashref) {
2027 $results[$count] = $data;
2032 return($count, @results);
2033 } # sub getitemsbybiblioitem
2037 # Subroutine to log changes to databases
2038 # Eventually, this subroutine will be used to create a log of all changes made,
2039 # with the possibility of "undo"ing some changes
2041 if ($database eq 'kohadb') {
2047 # print STDERR "KOHA: $type $section $item $original $new\n";
2048 } elsif ($database eq 'marc') {
2050 my $Record_ID=shift;
2053 my $subfield_ID=shift;
2056 # print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
2060 #------------------------------------------------
2063 #---------------------------------------
2064 # Find a biblio entry, or create a new one if it doesn't exist.
2065 # If a "subtitle" entry is in hash, add it to subtitle table
2066 sub getoraddbiblio {
2070 # FIXME - Unused argument
2071 $biblio, # hash ref to fields
2082 $dbh = C4::Context->dbh;
2084 print "<PRE>Looking for biblio </PRE>\n" if $debug;
2085 $sth=$dbh->prepare("select biblionumber
2087 where title=? and author=?
2088 and copyrightdate=? and seriestitle=?");
2090 $biblio->{title}, $biblio->{author},
2091 $biblio->{copyright}, $biblio->{seriestitle} );
2093 ($biblionumber) = $sth->fetchrow;
2094 print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
2096 # Doesn't exist. Add new one.
2097 print "<PRE>Adding biblio</PRE>\n" if $debug;
2098 ($biblionumber,$error)=&newbiblio($biblio);
2099 if ( $biblionumber ) {
2100 print "<PRE>Added with biblio number=$biblionumber</PRE>\n" if $debug;
2101 if ( $biblio->{subtitle} ) {
2102 &newsubtitle($biblionumber,$biblio->{subtitle} );
2105 print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
2109 return $biblionumber,$error;
2111 } # sub getoraddbiblio
2114 # converts ISO 5426 coded string to ISO 8859-1
2115 # sloppy code : should be improved in next issue
2118 if (C4::Context->preference("marcflavour") eq "UNIMARC") {
2235 # this handles non-sorting blocks (if implementation requires this)
2236 $string = nsb_clean($_) ;
2241 my $NSB = '\x88' ; # NSB : begin Non Sorting Block
2242 my $NSE = '\x89' ; # NSE : Non Sorting Block end
2243 # handles non sorting blocks
2247 s/[ ]{0,1}$NSE/) /gm ;
2252 END { } # module clean-up code here (global destructor)
2258 Koha Developement team <info@koha.org>
2260 Paul POULAIN paul.poulain@free.fr