5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA 02111-1307 USA
28 use MARC::File::USMARC;
31 my ($tagfield,$insubfield,$record) = @_;
32 # warn "$tagfield / $insubfield // ";
35 foreach my $field ($record->field($tagfield)) {
36 my @subfields = $field->subfields();
37 foreach my $subfield (@subfields) {
38 if (@$subfield[0] eq $insubfield) {
39 $result .= @$subfield[1];
40 $indicator = $field->indicator(1).$field->indicator(2);
44 return($indicator,$result);
47 sub MARCfindbreeding {
49 my $sth = $dbh->prepare("select file,marc from marc_breeding where isbn=?");
51 my ($file,$marc) = $sth->fetchrow;
53 my $record = MARC::File::USMARC::decode($marc);
54 if (ref($record) eq undef) {
64 my $error = $input->param('error');
65 my $oldbiblionumber=$input->param('oldbiblionumber'); # if bib exists, it's a modif, not a new biblio.
66 my $isbn = $input->param('isbn');
67 my $op = $input->param('op');
68 my $dbh = C4::Context->dbh;
70 if ($oldbiblionumber) {
71 $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber);
73 $bibid = $input->param('bibid');
77 my $tagslib = &MARCgettagslib($dbh,1);
79 $record = MARCgetbiblio($dbh,$bibid) if ($bibid);
80 $record = MARCfindbreeding($dbh,$isbn) if ($isbn);
85 #------------------------------------------------------------------------------------------------------------------------------
86 if ($op eq "addbiblio") {
87 #------------------------------------------------------------------------------------------------------------------------------
89 my @tags = $input->param('tag');
90 my @subfields = $input->param('subfield');
91 my @values = $input->param('field_value');
92 # build indicator hash.
93 my @ind_tag = $input->param('ind_tag');
94 my @indicator = $input->param('indicator');
96 for (my $i=0;$i<=$#ind_tag;$i++) {
97 $indicators{$ind_tag[$i]} = $indicator[$i];
99 my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values,%indicators);
100 # MARC::Record builded => now, record in DB
104 ($bibid,$oldbibnum,$oldbibitemnum) = NEWmodbiblio($dbh,$record,$bibid);
106 ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbiblio($dbh,$record);
108 # now, redirect to additem page
109 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=additem.pl?bibid=$bibid\"></html>";
111 #------------------------------------------------------------------------------------------------------------------------------
113 #------------------------------------------------------------------------------------------------------------------------------
114 $template = gettemplate("acqui.simple/addbiblio.tmpl");
119 my $authorised_values_sth = $dbh->prepare("select authorised_value from authorised_values where category=?");
120 # loop through each tab 0 through 9
121 for (my $tabloop = 0; $tabloop<=9;$tabloop++) {
122 # my @fields = $record->fields();
124 foreach my $tag (sort(keys (%{$tagslib}))) {
125 my $previous_tag = '';
128 # loop through each subfield
129 foreach my $subfield (sort(keys %{$tagslib->{$tag}})) {
130 next if ($subfield eq 'lib'); # skip lib and tabs, which are koha internal
131 next if ($subfield eq 'tab');
132 next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
134 $subfield_data{tag}=$tag;
135 $subfield_data{subfield}=$subfield;
136 $subfield_data{marc_lib}="<DIV id=\"error$i\">".$tagslib->{$tag}->{$subfield}->{lib}."</div>";
137 $subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
138 $subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
139 # if breeding is not empty
141 my ($x,$value) = find_value($tag,$subfield,$record);
142 $indicator = $x if $x;
143 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
144 my @authorised_values;
145 # builds list, depending on authorised value...
147 if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
148 my $sth=$dbh->prepare("select branchcode,branchname from branches");
150 push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
151 while (my ($branchcode,$branchname) = $sth->fetchrow_array) {
152 push @authorised_values, $branchcode;
155 } elsif ($tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes") {
156 my $sth=$dbh->prepare("select itemtype,description from itemtypes");
158 push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
159 while (my ($itemtype,$description) = $sth->fetchrow_array) {
160 push @authorised_values, $itemtype;
162 #---- "true" authorised value
164 $authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value});
165 push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
166 while ((my $value) = $authorised_values_sth->fetchrow_array) {
167 push @authorised_values, $value;
170 $subfield_data{marc_value}= CGI::scrolling_list(-name=>'field_value',
171 -values=> \@authorised_values,
176 } elsif ($tagslib->{$tag}->{$subfield}->{thesaurus_category}) {
177 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" size=47 maxlength=255 DISABLE READONLY> <a href=\"javascript:Dopop('../thesaurus_popup.pl?category=$tagslib->{$tag}->{$subfield}->{thesaurus_category}&index=$i',$i)\">...</a>"; #"
178 } elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
179 my $plugin="../value_builder/".$tagslib->{$tag}->{$subfield}->{'value_builder'};
181 my $extended_param = plugin_parameters($dbh,$record,$tagslib,$i,$tabloop);
182 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" size=47 maxlength=255 DISABLE READONLY> <a href=\"javascript:Dopop('../plugin_launcher.pl?plugin_name=$tagslib->{$tag}->{$subfield}->{value_builder}&index=$i$extended_param',$i)\">...</a>";
184 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" value=\"$value\" size=50 maxlength=255>";
186 # if breeding is empty
189 ($x,$value) = find_value($tag,$subfield,$record) if ($record ne -1);
190 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
191 my @authorised_values;
192 # builds list, depending on authorised value...
194 if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
195 my $sth=$dbh->prepare("select branchcode,branchname from branches");
197 push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
198 while (my ($branchcode,$branchname) = $sth->fetchrow_array) {
199 push @authorised_values, $branchcode;
202 } elsif ($tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes") {
203 my $sth=$dbh->prepare("select itemtype,description from itemtypes");
205 push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
206 while (my ($itemtype,$description) = $sth->fetchrow_array) {
207 push @authorised_values, $itemtype;
209 #---- "true" authorised value
211 $authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value});
212 push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
213 while ((my $value) = $authorised_values_sth->fetchrow_array) {
214 push @authorised_values, $value;
217 $subfield_data{marc_value}= CGI::scrolling_list(-name=>'field_value',
218 -values=> \@authorised_values,
223 } elsif ($tagslib->{$tag}->{$subfield}->{thesaurus_category}) {
224 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" size=47 maxlength=255 DISABLE READONLY> <a href=\"javascript:Dopop('../thesaurus_popup.pl?category=$tagslib->{$tag}->{$subfield}->{thesaurus_category}&index=$i',$i)\">...</a>";
225 } elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
226 my $plugin="../value_builder/".$tagslib->{$tag}->{$subfield}->{'value_builder'};
228 my $extended_param = plugin_parameters($dbh,$record,$tagslib,$i,$tabloop);
229 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" size=47 maxlength=255 DISABLE READONLY> <a href=\"javascript:Dopop('../plugin_launcher.pl?plugin_name=$tagslib->{$tag}->{$subfield}->{value_builder}&index=$i$extended_param',$i)\">...</a>";
231 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" size=50 maxlength=255>";
234 push(@subfields_data, \%subfield_data);
237 if ($#subfields_data>=0) {
240 $tag_data{tag_lib} = $tagslib->{$tag}->{lib};
241 $tag_data{indicator} = $indicator;
242 $tag_data{subfield_loop} = \@subfields_data;
243 push (@loop_data, \%tag_data);
246 $template->param($tabloop."XX" =>\@loop_data);
248 # now, build hidden datas => we store everything, even if we show only requested subfields.
251 foreach my $tag (keys %{$tagslib}) {
252 my $previous_tag = '';
253 # loop through each subfield
254 foreach my $subfield (keys %{$tagslib->{$tag}}) {
255 next if ($subfield eq 'lib');
256 next if ($subfield eq 'tab');
257 next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "-1");
259 $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
260 $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
261 $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
262 $subfield_data{marc_value}="<input type=\"hidden\" name=\"field_value[]\">";
263 push(@loop_data, \%subfield_data);
268 oldbiblionumber => $oldbiblionumber,
271 print "Content-Type: text/html\n\n", $template->output;