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");
109 $subfield_data{tag}=$tag;
110 $subfield_data{subfield}=$subfield;
111 $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
112 $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
113 $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
114 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
115 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=\"field_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");
205 my $authorised_values_sth = $dbh->prepare("select authorised_value from authorised_values where category=?");
206 # loop through each tab 0 through 9
207 for (my $tabloop = 0; $tabloop<=9;$tabloop++) {
208 # loop through each tag
209 # my @fields = $record->fields();
211 foreach my $tag (keys %{$tagslib}) {
212 my $previous_tag = '';
214 # loop through each subfield
215 foreach my $subfield (keys %{$tagslib->{$tag}}) {
216 next if ($subfield eq 'lib');
217 next if ($subfield eq 'tab');
218 next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
220 $subfield_data{tag}=$tag;
221 $subfield_data{subfield}=$subfield;
222 $subfield_data{marc_lib}="<DIV id=\"error$i\">".$tagslib->{$tag}->{$subfield}->{lib}."</div>";
223 $subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
224 $subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
226 my $value = find_value($tag,$subfield,$record);
227 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
228 $authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value});
229 my @authorised_values;
230 push @authorised_values, "" unless ($subfield_data{mandatory});
231 while ((my $value) = $authorised_values_sth->fetchrow_array) {
232 push @authorised_values, $value;
234 $subfield_data{marc_value}= CGI::scrolling_list(-name=>'field_value',
235 -values=> \@authorised_values,
241 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" value=\"$value\">";
244 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
245 $authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value});
246 my @authorised_values;
247 push @authorised_values, "" unless ($subfield_data{mandatory});
248 while ((my $value) = $authorised_values_sth->fetchrow_array) {
249 push @authorised_values, $value;
251 $subfield_data{marc_value}= CGI::scrolling_list(-name=>'field_value',
252 -values=> \@authorised_values,
257 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
260 push(@subfields_data, \%subfield_data);
263 if ($#subfields_data>=0) {
265 $tag_data{tag}=$tag.' -'. $tagslib->{$tag}->{lib};
266 $tag_data{subfield} = \@subfields_data;
267 push (@loop_data, \%tag_data);
270 $template->param($tabloop."XX" =>\@loop_data);
272 # now, build hidden datas => we store everything, even if we show only requested subfields.
275 foreach my $tag (keys %{$tagslib}) {
276 my $previous_tag = '';
277 # loop through each subfield
278 foreach my $subfield (keys %{$tagslib->{$tag}}) {
279 next if ($subfield eq 'lib');
280 next if ($subfield eq 'tab');
281 next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "-1");
283 $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
284 $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
285 $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
286 $subfield_data{marc_value}="<input type=\"hidden\" name=\"field_value\">";
287 push(@loop_data, \%subfield_data);
292 biblionumber => $oldbiblionumber,
295 print "Content-Type: text/html\n\n", $template->output;