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,$insubfield,$record) = @_;
41 foreach my $field ($record->field($tagfield)) {
42 my @subfields = $field->subfields();
43 foreach my $subfield (@subfields) {
44 if (@$subfield[0] eq $insubfield) {
45 $result .= @$subfield[1];
46 $indicator = $field->indicator(1).$field->indicator(2);
50 return($indicator,$result);
53 sub MARCfindbreeding {
55 my $sth = $dbh->prepare("select file,marc from marc_breeding where isbn=?");
57 my ($file,$marc) = $sth->fetchrow;
59 my $record = MARC::File::USMARC::decode($marc);
60 if (ref($record) eq undef) {
61 warn "not a MARC record : $marc";
71 my $error = $input->param('error');
72 my $oldbiblionumber=$input->param('bib'); # if bib exists, it's a modif, not a new biblio.
73 my $isbn = $input->param('isbn');
74 my $op = $input->param('op');
75 my $dbh = C4::Context->dbh;
77 if ($oldbiblionumber) {;
78 $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber)
80 $bibid = $input->param('bibid');
84 my $tagslib = &MARCgettagslib($dbh,1);
86 my $record = MARCgetbiblio($dbh,$bibid) if ($oldbiblionumber);
87 my $record = MARCfindbreeding($dbh,$isbn) if ($isbn);
89 #------------------------------------------------------------------------------------------------------------------------------
90 if ($op eq "addbiblio") {
91 #------------------------------------------------------------------------------------------------------------------------------
93 my @tags = $input->param('tag');
94 my @subfields = $input->param('subfield');
95 my @values = $input->param('field_value');
96 # build indicator hash.
97 my @ind_tag = $input->param('ind_tag');
98 my @indicator = $input->param('indicator');
100 for (my $i=0;$i<=$#ind_tag;$i++) {
101 $indicators{$ind_tag[$i]} = $indicator[$i];
103 my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values,%indicators);
104 # warn "record ".$record->as_formatted();
105 # MARC::Record builded => now, record in DB
106 my ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbiblio($dbh,$record);
107 my $authorised_values_sth = $dbh->prepare("select authorised_value from authorised_values where category=?");
108 # build item screen. There is no item for instance.
111 foreach my $tag (keys %{$tagslib}) {
112 my $previous_tag = '';
113 # loop through each subfield
114 foreach my $subfield (keys %{$tagslib->{$tag}}) {
115 next if ($subfield eq 'lib');
116 next if ($subfield eq 'tab');
117 next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10");
120 $subfield_data{tag}=$tag;
121 $subfield_data{subfield}=$subfield;
122 $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
123 $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
124 $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
125 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
126 $authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value});
127 my @authorised_values;
128 push @authorised_values, "" unless ($subfield_data{mandatory});
129 while ((my $value) = $authorised_values_sth->fetchrow_array) {
130 push @authorised_values, $value;
132 $subfield_data{marc_value}= CGI::scrolling_list(-name=>'field_value',
133 -values=> \@authorised_values,
137 } elsif ($tagslib->{$tag}->{$subfield}->{thesaurus_category}) {
138 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" DISABLE READONLY> <a href=\"javascript:Dopop('../thesaurus_popup.pl?category=$tagslib->{$tag}->{$subfield}->{thesaurus_category}&index=$i',$i)\">...</a>";
140 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
142 push(@loop_data, \%subfield_data);
145 $template = gettemplate("acqui.simple/addbiblio2.tmpl");
146 $template->param(bibid => $bibid,
147 item => \@loop_data);
148 #------------------------------------------------------------------------------------------------------------------------------
149 } elsif ($op eq "additem") {
150 #------------------------------------------------------------------------------------------------------------------------------
151 my @tags = $input->param('tag');
152 my @subfields = $input->param('subfield');
153 my @values = $input->param('field_value');
154 # my @ind_tag = $input->param('ind_tag');
155 # my @indicator = $input->param('indicator');
157 # for (my $i=0;$i<=$#ind_tag;$i++) {
158 # $indicators{$ind_tag[$i]} = $indicator[$i];
161 $indicators{995}=' ';
162 warn "REs : $tags[0] - $tags[1] - $subfields[0] - $subfields[1] - $values[0] - $values[1]";
163 my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values,%indicators);
164 my ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewitem($dbh,$record,$bibid);
165 # now, build existiing item list
166 my $temp = MARCgetbiblio($dbh,$bibid);
167 my @fields = $temp->fields();
168 my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
170 foreach my $field (@fields) {
171 my @subf=$field->subfields;
173 # loop through each subfield
174 for my $i (0..$#subf) {
175 next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} ne 10);
176 $witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib};
177 $this_row{$subf[$i][0]} =$subf[$i][1];
180 push(@big_array, \%this_row);
183 #fill big_row with missing datas
184 foreach my $subfield_code (keys(%witness)) {
185 for (my $i=0;$i<=$#big_array;$i++) {
186 $big_array[$i]{$subfield_code}=" " unless ($big_array[$i]{$subfield_code});
189 # now, construct template !
191 my @header_value_loop;
192 for (my $i=0;$i<=$#big_array; $i++) {
194 foreach my $subfield_code (keys(%witness)) {
195 $items_data .="<td>".$big_array[$i]{$subfield_code}."</td>";
198 $row_data{item_value} = $items_data;
199 push(@item_value_loop,\%row_data);
201 foreach my $subfield_code (keys(%witness)) {
203 $header_value{header_value} = $witness{$subfield_code};
204 push(@header_value_loop, \%header_value);
210 foreach my $tag (keys %{$tagslib}) {
211 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 "10");
218 $subfield_data{tag}=$tag;
219 $subfield_data{subfield}=$subfield;
220 $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
221 $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
222 $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
223 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
224 push(@loop_data, \%subfield_data);
228 $template = gettemplate("acqui.simple/addbiblio2.tmpl");
229 $template->param(item_loop => \@item_value_loop,
230 item_header_loop => \@header_value_loop,
232 item => \@loop_data);
233 #------------------------------------------------------------------------------------------------------------------------------
235 #------------------------------------------------------------------------------------------------------------------------------
236 $template = gettemplate("acqui.simple/addbiblio.tmpl");
241 my $authorised_values_sth = $dbh->prepare("select authorised_value from authorised_values where category=?");
242 # loop through each tab 0 through 9
243 for (my $tabloop = 0; $tabloop<=9;$tabloop++) {
244 # my @fields = $record->fields();
246 foreach my $tag (keys %{$tagslib}) {
247 my $previous_tag = '';
250 # loop through each subfield
251 foreach my $subfield (keys %{$tagslib->{$tag}}) {
252 next if ($subfield eq 'lib'); # skip lib and tabs, which are koha internal
253 next if ($subfield eq 'tab');
254 next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
256 $subfield_data{tag}=$tag;
257 $subfield_data{subfield}=$subfield;
258 $subfield_data{marc_lib}="<DIV id=\"error$i\">".$tagslib->{$tag}->{$subfield}->{lib}."</div>";
259 $subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
260 $subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
261 # if breeding is not empty
263 my ($x,$value) = find_value($tag,$subfield,$record);
264 $indicator = $x if $x;
265 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
266 $authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value});
267 my @authorised_values;
268 push @authorised_values, "" unless ($subfield_data{mandatory});
269 while ((my $value) = $authorised_values_sth->fetchrow_array) {
270 push @authorised_values, $value;
272 $subfield_data{marc_value}= CGI::scrolling_list(-name=>'field_value',
273 -values=> \@authorised_values,
278 } elsif ($tagslib->{$tag}->{$subfield}->{thesaurus_category}) {
279 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" DISABLE READONLY> <a href=\"javascript:Dopop('../thesaurus_popup.pl?category=$tagslib->{$tag}->{$subfield}->{thesaurus_category}&index=$i',$i)\">...</a>";
280 } elsif ($tagslib->{$tag}->{$subfield}->{value_builder}) {
281 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" DISABLE READONLY> <a href=\"javascript:Dopop('../value_builder/$tagslib->{$tag}->{$subfield}->{value_builder}?index=$i',$i)\">...</a>";
283 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" value=\"$value\">";
285 # if breeding is empty
287 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
288 $authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value});
289 my @authorised_values;
290 push @authorised_values, "" unless ($subfield_data{mandatory});
291 while ((my $value) = $authorised_values_sth->fetchrow_array) {
292 push @authorised_values, $value;
294 $subfield_data{marc_value}= CGI::scrolling_list(-name=>'field_value',
295 -values=> \@authorised_values,
299 } elsif ($tagslib->{$tag}->{$subfield}->{thesaurus_category}) {
300 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" DISABLE READONLY> <a href=\"javascript:Dopop('../thesaurus_popup.pl?category=$tagslib->{$tag}->{$subfield}->{thesaurus_category}&index=$i',$i)\">...</a>";
301 } elsif ($tagslib->{$tag}->{$subfield}->{value_builder}) {
302 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" DISABLE READONLY> <a href=\"javascript:Dopop('../value_builder/$tagslib->{$tag}->{$subfield}->{value_builder}?index=$i',$i)\">...</a>";
304 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
307 push(@subfields_data, \%subfield_data);
310 if ($#subfields_data>=0) {
313 $tag_data{tag_lib} = $tagslib->{$tag}->{lib};
314 $tag_data{indicator} = $indicator;
315 $tag_data{subfield_loop} = \@subfields_data;
316 push (@loop_data, \%tag_data);
319 $template->param($tabloop."XX" =>\@loop_data);
321 # now, build hidden datas => we store everything, even if we show only requested subfields.
324 foreach my $tag (keys %{$tagslib}) {
325 my $previous_tag = '';
326 # loop through each subfield
327 foreach my $subfield (keys %{$tagslib->{$tag}}) {
328 next if ($subfield eq 'lib');
329 next if ($subfield eq 'tab');
330 next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "-1");
332 $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
333 $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
334 $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
335 $subfield_data{marc_value}="<input type=\"hidden\" name=\"field_value[]\">";
336 push(@loop_data, \%subfield_data);
341 biblionumber => $oldbiblionumber,
344 print "Content-Type: text/html\n\n", $template->output;