8 # Add info on biblioitems and items already entered as you enter new ones
12 # Copyright 2000-2002 Katipo Communications
14 # This file is part of Koha.
16 # Koha is free software; you can redistribute it and/or modify it under the
17 # terms of the GNU General Public License as published by the Free Software
18 # Foundation; either version 2 of the License, or (at your option) any later
21 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
22 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
23 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License along with
26 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
27 # Suite 330, Boston, MA 02111-1307 USA
35 use MARC::File::USMARC;
38 my ($tagfield,$subfield,$record) = @_;
40 foreach my $field ($record->field($tagfield)) {
41 my @subfields = $field->subfields();
42 foreach my $subfield (@subfields) {
43 if (@$subfield[0] eq $subfield) {
44 $result .= @$subfield[1];
50 sub MARCfindbreeding {
52 my $sth = $dbh->prepare("select file,marc from marc_breeding where isbn=?");
54 my ($file,$marc) = $sth->fetchrow;
56 my $record = MARC::File::USMARC::decode($marc);
57 if (ref($record) eq undef) {
58 warn "not a MARC record !";
69 my $error = $input->param('error');
70 my $oldbiblionumber=$input->param('bib'); # if bib exists, it's a modif, not a new biblio.
71 my $isbn = $input->param('isbn');
72 my $op = $input->param('op');
73 my $dbh = C4::Context->dbh;
75 if ($oldbiblionumber) {;
76 $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber)
78 $bibid = $input->param('bibid');
82 my $tagslib = &MARCgettagslib($dbh,1);
84 my $record = MARCgetbiblio($dbh,$bibid) if ($oldbiblionumber);
85 #my $record = MARCfindbreeding($dbh,$isbn) if ($isbn);
87 #------------------------------------------------------------------------------------------------------------------------------
88 if ($op eq "addbiblio") {
89 #------------------------------------------------------------------------------------------------------------------------------
91 my @tags = $input->param('tag[]');
92 my @subfields = $input->param('subfield[]');
93 my @values = $input->param('value[]');
94 my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values);
95 # MARC::Record builded => now, record in DB
96 my ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbiblio($dbh,$record);
97 # build item screen. There is no item for instance.
100 foreach my $tag (keys %{$tagslib}) {
101 my $previous_tag = '';
102 # loop through each subfield
103 foreach my $subfield (keys %{$tagslib->{$tag}}) {
104 next if ($subfield eq 'lib');
105 next if ($subfield eq 'tab');
106 next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10");
108 $subfield_data{tag}=$tag;
109 $subfield_data{subfield}=$subfield;
110 $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
111 $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
112 $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
113 $subfield_data{marc_value}="<input type=\"text\" name=\"value[]\">";
114 push(@loop_data, \%subfield_data);
118 $template = gettemplate("acqui.simple/addbiblio2.tmpl");
119 $template->param(bibid => $bibid,
120 item => \@loop_data);
121 #------------------------------------------------------------------------------------------------------------------------------
122 } elsif ($op eq "additem") {
123 #------------------------------------------------------------------------------------------------------------------------------
124 my @tags = $input->param('tag[]');
125 my @subfields = $input->param('subfield[]');
126 my @values = $input->param('value[]');
127 my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values);
128 my ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewitem($dbh,$record,$bibid);
129 # now, build existiing item list
130 my $temp = MARCgetbiblio($dbh,$bibid);
131 my @fields = $temp->fields();
132 my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
134 foreach my $field (@fields) {
135 my @subf=$field->subfields;
137 # loop through each subfield
138 for my $i (0..$#subf) {
139 next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} ne 10);
140 $witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib};
141 $this_row{$subf[$i][0]} =$subf[$i][1];
144 push(@big_array, \%this_row);
147 #fill big_row with missing datas
148 foreach my $subfield_code (keys(%witness)) {
149 for (my $i=0;$i<=$#big_array;$i++) {
150 $big_array[$i]{$subfield_code}=" " unless ($big_array[$i]{$subfield_code});
153 # now, construct template !
155 my @header_value_loop;
156 for (my $i=0;$i<=$#big_array; $i++) {
158 foreach my $subfield_code (keys(%witness)) {
159 $items_data .="<td>".$big_array[$i]{$subfield_code}."</td>";
162 $row_data{item_value} = $items_data;
163 push(@item_value_loop,\%row_data);
165 foreach my $subfield_code (keys(%witness)) {
167 $header_value{header_value} = $witness{$subfield_code};
168 push(@header_value_loop, \%header_value);
174 foreach my $tag (keys %{$tagslib}) {
175 my $previous_tag = '';
176 # loop through each subfield
177 foreach my $subfield (keys %{$tagslib->{$tag}}) {
178 next if ($subfield eq 'lib');
179 next if ($subfield eq 'tab');
180 next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10");
182 $subfield_data{tag}=$tag;
183 $subfield_data{subfield}=$subfield;
184 $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
185 $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
186 $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
187 $subfield_data{marc_value}="<input type=\"text\" name=\"value[]\">";
188 push(@loop_data, \%subfield_data);
192 $template = gettemplate("acqui.simple/addbiblio2.tmpl");
193 $template->param(item_loop => \@item_value_loop,
194 item_header_loop => \@header_value_loop,
196 item => \@loop_data);
197 #------------------------------------------------------------------------------------------------------------------------------
199 #------------------------------------------------------------------------------------------------------------------------------
200 $template = gettemplate("acqui.simple/addbiblio.tmpl");
204 # loop through each tab 0 through 9
205 for (my $tabloop = 0; $tabloop<=9;$tabloop++) {
206 # loop through each tag
207 # my @fields = $record->fields();
209 foreach my $tag (keys %{$tagslib}) {
210 my $previous_tag = '';
212 # loop through each subfield
213 foreach my $subfield (keys %{$tagslib->{$tag}}) {
214 next if ($subfield eq 'lib');
215 next if ($subfield eq 'tab');
216 next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
218 $subfield_data{tag}=$tag;
219 $subfield_data{subfield}=$subfield;
220 $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
221 $subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
222 $subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
224 my $value ="";# &find_value($tag,$subfield,$record);
225 $subfield_data{marc_value}="<input type=\"text\" name=\"value[]\" value=\"$value\">";
227 $subfield_data{marc_value}="<input type=\"text\" name=\"value[]\">";
229 push(@subfields_data, \%subfield_data);
231 if ($#subfields_data>=0) {
233 $tag_data{tag}=$tag.' -'. $tagslib->{$tag}->{lib};
234 $tag_data{subfield} = \@subfields_data;
235 push (@loop_data, \%tag_data);
238 $template->param($tabloop."XX" =>\@loop_data);
240 # now, build hidden datas => we store everything, even if we show only requested subfields.
243 foreach my $tag (keys %{$tagslib}) {
244 my $previous_tag = '';
245 # loop through each subfield
246 foreach my $subfield (keys %{$tagslib->{$tag}}) {
247 next if ($subfield eq 'lib');
248 next if ($subfield eq 'tab');
249 next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "-1");
251 $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
252 $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
253 $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
254 $subfield_data{marc_value}="<input type=\"hidden\" name=\"value[]\">";
255 push(@loop_data, \%subfield_data);
260 biblionumber => $oldbiblionumber,
263 print "Content-Type: text/html\n\n", $template->output;