From ebc08585d42500a18825c960eccd8004ff4928b0 Mon Sep 17 00:00:00 2001 From: tipaul Date: Tue, 22 Oct 2002 15:50:23 +0000 Subject: [PATCH] road to 1.3.2 : adding a biblio in MARC format. seems to work a few. still to do : * manage html checks (mandatory subfields...) * add list of acceptable values (authorities) * manage ## in MARC format * manage correctly repeatable fields and probably a LOT of bugfixes --- acqui.simple/addbiblio.pl | 286 ++++++++++++++---- acqui.simple/isbnsearch.pl | 125 +++----- acqui.simple/marcimport.pl | 15 +- .../default/en/acqui.simple/addbiblio.tmpl | 268 ++++++++++++++++ .../default/en/acqui.simple/addbiblio2.tmpl | 73 +++++ .../default/en/acqui.simple/isbnsearch.tmpl | 42 +++ 6 files changed, 664 insertions(+), 145 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio.tmpl create mode 100644 koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio2.tmpl create mode 100644 koha-tmpl/intranet-tmpl/default/en/acqui.simple/isbnsearch.tmpl diff --git a/acqui.simple/addbiblio.pl b/acqui.simple/addbiblio.pl index 1f980327f8..a34c10acd8 100755 --- a/acqui.simple/addbiblio.pl +++ b/acqui.simple/addbiblio.pl @@ -29,73 +29,235 @@ use CGI; use strict; use C4::Output; +use C4::Biblio; +use C4::Context; +use HTML::Template; +use MARC::File::USMARC; +sub find_value { + my ($tagfield,$subfield,$record) = @_; + my $result; + foreach my $field ($record->field($tagfield)) { + my @subfields = $field->subfields(); + foreach my $subfield (@subfields) { + if (@$subfield[0] eq $subfield) { + $result .= @$subfield[1]; + } + } + } +} +sub MARCfindbreeding { + my ($dbh,$isbn) = @_; + my $sth = $dbh->prepare("select file,marc from marc_breeding where isbn=?"); + $sth->execute($isbn); + my ($file,$marc) = $sth->fetchrow; + if ($marc) { + my $record = MARC::File::USMARC::decode($marc); + if (ref($record) eq undef) { + warn "not a MARC record !"; + return -1; + } else { + return $record; + } + } + warn "not MARC"; + return -1; + +} my $input = new CGI; my $error = $input->param('error'); +my $oldbiblionumber=$input->param('bib'); # if bib exists, it's a modif, not a new biblio. +my $isbn = $input->param('isbn'); +my $op = $input->param('op'); +my $dbh = C4::Context->dbh; +my $bibid; +if ($oldbiblionumber) {; + $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber) +}else { + $bibid = $input->param('bibid'); +} +my $template; -print $input->header; -print startpage(); -print startmenu('acquisitions'); - -print << "EOF"; -Adding a new Biblio
- - - - - -
Section One: Copyright Information
-EOF +my $tagslib = &MARCgettagslib($dbh,1); -if ($error eq "notitle") { - print << "EOF"; -

-

-Please Specify a Title -
-EOF -} # if +my $record = MARCgetbiblio($dbh,$bibid) if ($oldbiblionumber); +#my $record = MARCfindbreeding($dbh,$isbn) if ($isbn); -print << "EOF"; -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Title: *
Subtitle:
Author:
Series Title:
- (if applicable)
Copyright Date:
Abstract:
Notes:
-
-* Required -EOF +#------------------------------------------------------------------------------------------------------------------------------ +if ($op eq "addbiblio") { +#------------------------------------------------------------------------------------------------------------------------------ + # rebuild + my @tags = $input->param('tag[]'); + my @subfields = $input->param('subfield[]'); + my @values = $input->param('value[]'); + my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values); +# MARC::Record builded => now, record in DB + my ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbiblio($dbh,$record); +# build item screen. There is no item for instance. + my @loop_data =(); + my $i=0; + foreach my $tag (keys %{$tagslib}) { + my $previous_tag = ''; + # loop through each subfield + foreach my $subfield (keys %{$tagslib->{$tag}}) { + next if ($subfield eq 'lib'); + next if ($subfield eq 'tab'); + next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10"); + my %subfield_data; + $subfield_data{tag}=$tag; + $subfield_data{subfield}=$subfield; + $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib}; + $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory}; + $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable}; + $subfield_data{marc_value}=""; + push(@loop_data, \%subfield_data); + $i++ + } + } + $template = gettemplate("acqui.simple/addbiblio2.tmpl"); + $template->param(bibid => $bibid, + item => \@loop_data); +#------------------------------------------------------------------------------------------------------------------------------ +} elsif ($op eq "additem") { +#------------------------------------------------------------------------------------------------------------------------------ + my @tags = $input->param('tag[]'); + my @subfields = $input->param('subfield[]'); + my @values = $input->param('value[]'); + my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values); + my ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewitem($dbh,$record,$bibid); + # now, build existiing item list + my $temp = MARCgetbiblio($dbh,$bibid); + my @fields = $temp->fields(); + my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code + my @big_array; + foreach my $field (@fields) { + my @subf=$field->subfields; + my %this_row; + # loop through each subfield + for my $i (0..$#subf) { + next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} ne 10); + $witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib}; + $this_row{$subf[$i][0]} =$subf[$i][1]; + } + if (%this_row) { + push(@big_array, \%this_row); + } + } + #fill big_row with missing datas + foreach my $subfield_code (keys(%witness)) { + for (my $i=0;$i<=$#big_array;$i++) { + $big_array[$i]{$subfield_code}=" " unless ($big_array[$i]{$subfield_code}); + } + } + # now, construct template ! + my @item_value_loop; + my @header_value_loop; + for (my $i=0;$i<=$#big_array; $i++) { + my $items_data; + foreach my $subfield_code (keys(%witness)) { + $items_data .="".$big_array[$i]{$subfield_code}.""; + } + my %row_data; + $row_data{item_value} = $items_data; + push(@item_value_loop,\%row_data); + } + foreach my $subfield_code (keys(%witness)) { + my %header_value; + $header_value{header_value} = $witness{$subfield_code}; + push(@header_value_loop, \%header_value); + } -print endmenu(); -print endpage(); +# next item form + my @loop_data =(); + my $i=0; + foreach my $tag (keys %{$tagslib}) { + my $previous_tag = ''; + # loop through each subfield + foreach my $subfield (keys %{$tagslib->{$tag}}) { + next if ($subfield eq 'lib'); + next if ($subfield eq 'tab'); + next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10"); + my %subfield_data; + $subfield_data{tag}=$tag; + $subfield_data{subfield}=$subfield; + $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib}; + $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory}; + $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable}; + $subfield_data{marc_value}=""; + push(@loop_data, \%subfield_data); + $i++ + } + } + $template = gettemplate("acqui.simple/addbiblio2.tmpl"); + $template->param(item_loop => \@item_value_loop, + item_header_loop => \@header_value_loop, + bibid => $bibid, + item => \@loop_data); +#------------------------------------------------------------------------------------------------------------------------------ +} else { +#------------------------------------------------------------------------------------------------------------------------------ + $template = gettemplate("acqui.simple/addbiblio.tmpl"); + # fill arrays + my @loop_data =(); + my $tag; + # loop through each tab 0 through 9 + for (my $tabloop = 0; $tabloop<=9;$tabloop++) { + # loop through each tag + # my @fields = $record->fields(); + my @loop_data =(); + foreach my $tag (keys %{$tagslib}) { + my $previous_tag = ''; + my @subfields_data; + # loop through each subfield + foreach my $subfield (keys %{$tagslib->{$tag}}) { + next if ($subfield eq 'lib'); + next if ($subfield eq 'tab'); + next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop); + my %subfield_data; + $subfield_data{tag}=$tag; + $subfield_data{subfield}=$subfield; + $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib}; + $subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory}; + $subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable}; + if ($record ne -1) { + my $value ="";# &find_value($tag,$subfield,$record); + $subfield_data{marc_value}=""; + } else { + $subfield_data{marc_value}=""; + } + push(@subfields_data, \%subfield_data); + } + if ($#subfields_data>=0) { + my %tag_data; + $tag_data{tag}=$tag.' -'. $tagslib->{$tag}->{lib}; + $tag_data{subfield} = \@subfields_data; + push (@loop_data, \%tag_data); + } + } + $template->param($tabloop."XX" =>\@loop_data); + } + # now, build hidden datas => we store everything, even if we show only requested subfields. + my @loop_data =(); + my $i=0; + foreach my $tag (keys %{$tagslib}) { + my $previous_tag = ''; + # loop through each subfield + foreach my $subfield (keys %{$tagslib->{$tag}}) { + next if ($subfield eq 'lib'); + next if ($subfield eq 'tab'); + next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "-1"); + my %subfield_data; + $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib}; + $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory}; + $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable}; + $subfield_data{marc_value}=""; + push(@loop_data, \%subfield_data); + $i++ + } + } + $template->param( + biblionumber => $oldbiblionumber, + bibid => $bibid); +} +print "Content-Type: text/html\n\n", $template->output; diff --git a/acqui.simple/isbnsearch.pl b/acqui.simple/isbnsearch.pl index 4284912640..23147581de 100755 --- a/acqui.simple/isbnsearch.pl +++ b/acqui.simple/isbnsearch.pl @@ -24,6 +24,7 @@ use C4::Catalogue; use C4::Biblio; use C4::Search; use C4::Output; +use HTML::Template; my $input = new CGI; my $isbn = $input->param('isbn'); @@ -33,93 +34,53 @@ my $showoffset = $offset + 1; my $total; my $count; my @results; - +my $template = gettemplate("acqui.simple/isbnsearch.tmpl"); if (! $isbn) { - print $input->redirect('addbooks.pl'); + print $input->redirect('addbooks.pl'); } else { - if (! $offset) { - $offset = 0; - $showoffset = 1; - }; - if (! $num) { $num = 10 }; - ($count, @results) = isbnsearch($isbn); - - if ($count < ($offset + $num)) { - $total = $count; - } else { - $total = $offset + $num; - } # else - - print $input->header; - print startpage(); - print startmenu('acquisitions'); - - print << "EOF"; -Biblio Search Results
-
-You searched on ISBN $isbn, $count results found
-Results $showoffset to $total displayed -
-

Add New Biblio

-
-

- - - - - - -EOF + if (! $offset) { + $offset = 0; + $showoffset = 1; + }; + if (! $num) { $num = 10 }; + ($count, @results) = isbnsearch($isbn); - for (my $i = $offset; $i < $total; $i++) { - if ($i % 2) { - print << "EOF"; - -EOF + if ($count < ($offset + $num)) { + $total = $count; } else { - print << "EOF"; - -EOF + $total = $offset + $num; } # else - print << "EOF"; - - - - -EOF - } # for - - print << "EOF"; - - - - - -
TITLEAUTHOR©
$results[$i]->{'title'}$results[$i]->{'author'}$results[$i]->{'copyrightdate'}
   
-
-EOF - - for (my $i = 0; ($i * $num) < $count; $i++) { - my $newoffset = $i * $num; - my $shownumber = $i + 1; - print << "EOF"; -$shownumber -EOF - } # for - - print << "EOF"; -

-Results per page: -5 -10 -20 -50 -

-
-

 

-EOF + my @loop_data = (); + my $toggle; + for (my $i = $offset; $i < $total; $i++) { + if ($i % 2) { + $toggle="#ffffcc"; + } else { + $toggle="white"; + } + my %row_data; # get a fresh hash for the row data + $row_data{toggle} = $toggle; + $row_data{biblionumber} =$results[$i]->{'biblionumber'}; + $row_data{title} = $results[$i]->{'title'}; + $row_data{author} = $results[$i]->{'author'}; + $row_data{copyrightdate} = $results[$i]->{'copyrightdate'}; + push(@loop_data, \%row_data); + } + my @loop_links = (); + for (my $i = 0; ($i * $num) < $count; $i++) { + my %row_data; + $row_data{newoffset} = $i * $num; + $row_data{shownumber} = $i + 1; + $row_data{num} = $num; + push (@loop_links,\%row_data); + } # for + $template->param(isbn => $isbn, + showoffset => $showoffset, + total => $total, + offset => $offset, + loop => \@loop_data, + loop_links => \@loop_links); - print endmenu(); - print endpage(); + print "Content-Type: text/html\n\n", $template->output; } # else diff --git a/acqui.simple/marcimport.pl b/acqui.simple/marcimport.pl index debc88fe3a..ef8d311187 100755 --- a/acqui.simple/marcimport.pl +++ b/acqui.simple/marcimport.pl @@ -36,7 +36,7 @@ use DBI; # Koha modules used use C4::Context; #use C4::Database; -use C4::Acquisitions; +#use C4::Acquisitions; use C4::Output; use C4::Input; use C4::Biblio; @@ -117,6 +117,9 @@ if ($uploadmarc && length($uploadmarc)>0) { ($breedingresult) = $searchbreeding->fetchrow; } if (!$breedingresult || $overwrite_biblio) { + if ($oldbiblio->{isbn} eq '0025003402') { + warn "IMPORT => $marcarray[$i]\x1D')"; + } $insertsql ->execute($filename,$oldbiblio->{isbn}.$oldbiblio->{issn},$marcarray[$i]."\x1D')"); $imported++; } else { @@ -793,6 +796,16 @@ sub FormatMarcText { #--------------- # log cleared, as marcimport is (almost) rewritten from scratch. # $Log$ +# Revision 1.21 2002/10/22 15:50:23 tipaul +# road to 1.3.2 : adding a biblio in MARC format. +# seems to work a few. +# still to do : +# * manage html checks (mandatory subfields...) +# * add list of acceptable values (authorities) +# * manage ## in MARC format +# * manage correctly repeatable fields +# and probably a LOT of bugfixes +# # Revision 1.20 2002/10/16 12:46:19 arensb # Added a FIXME comment. # diff --git a/koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio.tmpl b/koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio.tmpl new file mode 100644 index 0000000000..672a7d9d08 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio.tmpl @@ -0,0 +1,268 @@ + + +
+ + + + + + + +
MARC biblio :
+ + + + + + + + + + + + + + +
0xx
1xx
2xx
3xx
4xx
5xx
6xx
7xx
8xx
9xx
+
+ +
+ + + + + + + + + + + + +
  + + "> + "> +
+
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + diff --git a/koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio2.tmpl b/koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio2.tmpl new file mode 100644 index 0000000000..2c14424764 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio2.tmpl @@ -0,0 +1,73 @@ + +
+ + + + + + + +
MARC biblio :
+ + + + + + + + + + + + + + +
           + + "> +
+
+
+
+
+ + + + +
Existing items
+ + + + + + + + + +
+
+

+ + + + +
New items
+ + + + + + + + +
  + + "> + "> +
+ +
+
+ + + diff --git a/koha-tmpl/intranet-tmpl/default/en/acqui.simple/isbnsearch.tmpl b/koha-tmpl/intranet-tmpl/default/en/acqui.simple/isbnsearch.tmpl new file mode 100644 index 0000000000..6f4a5797c9 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/default/en/acqui.simple/isbnsearch.tmpl @@ -0,0 +1,42 @@ + + +Biblio Search Results
+
+You searched on ISBN , results found
+Results to displayed + +

+ + + + + + + + + + + "> + + + + + + +
TITLEAUTHOR©Items
">">Edit...
+
+ + &offset=&num="> + +

+Results per page: +offset=&num=5">5 +&offset=&num=10">10 +&offset=&num=20">20 +&offset=&num=50">50 +

+
+

 

+ -- 2.39.5