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 my $error = $input->param('error');
48 my $bibid = $input->param('bibid');
49 my $op = $input->param('op');
50 my $dbh = C4::Context->dbh;
51 my $itemnum = $input->param('itemnum');
53 my $tagslib = &MARCgettagslib($dbh,1);
54 my $record = MARCgetbiblio($dbh,$bibid);
57 #------------------------------------------------------------------------------------------------------------------------------
58 if ($op eq "additem") {
59 #------------------------------------------------------------------------------------------------------------------------------
61 my @tags = $input->param('tag');
62 my @subfields = $input->param('subfield');
63 my @values = $input->param('field_value');
64 # build indicator hash.
65 my @ind_tag = $input->param('ind_tag');
66 my @indicator = $input->param('indicator');
68 for (my $i=0;$i<=$#ind_tag;$i++) {
69 $indicators{$ind_tag[$i]} = $indicator[$i];
71 my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values,%indicators);
72 # MARC::Record builded => now, record in DB
73 my ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewitem($dbh,$record,$bibid);
75 #------------------------------------------------------------------------------------------------------------------------------
76 } elsif ($op eq "edititem") {
77 #------------------------------------------------------------------------------------------------------------------------------
78 # retrieve item if exist => then, it's a modif
79 $itemrecord = MARCgetitem($dbh,$bibid,$itemnum);
81 #------------------------------------------------------------------------------------------------------------------------------
82 } elsif ($op eq "saveitem") {
83 #------------------------------------------------------------------------------------------------------------------------------
85 my @tags = $input->param('tag');
86 my @subfields = $input->param('subfield');
87 my @values = $input->param('field_value');
88 # build indicator hash.
89 my @ind_tag = $input->param('ind_tag');
90 my @indicator = $input->param('indicator');
92 for (my $i=0;$i<=$#ind_tag;$i++) {
93 $indicators{$ind_tag[$i]} = $indicator[$i];
95 my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values,%indicators);
96 # MARC::Record builded => now, record in DB
97 my ($bibid,$oldbibnum,$oldbibitemnum) = NEWmoditem($dbh,$record,$bibid,$itemnum,0);
102 #------------------------------------------------------------------------------------------------------------------------------
103 # build screen with existing items. and "new" one
104 #------------------------------------------------------------------------------------------------------------------------------
107 $indicators{995}=' ';
108 # now, build existiing item list
109 my $temp = MARCgetbiblio($dbh,$bibid);
110 my @fields = $temp->fields();
111 my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
113 #---- finds where items.itemnumber is stored
114 my ($itemtagfield,$itemtagsubfield) = &MARCfind_marc_from_kohafield($dbh,"items.itemnumber");
115 my @itemnums; # array to store itemnums
116 foreach my $field (@fields) {
117 my @subf=$field->subfields;
119 # loop through each subfield
120 for my $i (0..$#subf) {
121 next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} ne 10 && ($field->tag() ne $itemtagfield && $subf[$i][0] ne $itemtagsubfield));
122 $witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib} if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} eq 10);
123 $this_row{$subf[$i][0]} =$subf[$i][1] if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} eq 10);
124 push @itemnums,$this_row{$subf[$i][0]} =$subf[$i][1] if ($field->tag() eq $itemtagfield && $subf[$i][0] eq $itemtagsubfield);
127 push(@big_array, \%this_row);
130 #fill big_row with missing datas
131 foreach my $subfield_code (keys(%witness)) {
132 for (my $i=0;$i<=$#big_array;$i++) {
133 $big_array[$i]{$subfield_code}=" " unless ($big_array[$i]{$subfield_code});
136 # now, construct template !
138 my @header_value_loop;
139 for (my $i=0;$i<=$#big_array; $i++) {
141 foreach my $subfield_code (sort keys(%witness)) {
142 $items_data .="<td>".$big_array[$i]{$subfield_code}."</td>";
145 $row_data{item_value} = $items_data;
146 $row_data{itemnum} = $itemnums[$i];
147 push(@item_value_loop,\%row_data);
149 foreach my $subfield_code (sort keys(%witness)) {
151 $header_value{header_value} = $witness{$subfield_code};
152 push(@header_value_loop, \%header_value);
158 my $authorised_values_sth = $dbh->prepare("select authorised_value from authorised_values where category=?");
160 foreach my $tag (sort keys %{$tagslib}) {
161 my $previous_tag = '';
162 # loop through each subfield
163 foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
164 next if ($subfield eq 'lib');
165 next if ($subfield eq 'tab');
166 next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10");
168 $subfield_data{tag}=$tag;
169 $subfield_data{subfield}=$subfield;
170 $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
171 $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
172 $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
174 ($x,$value) = find_value($tag,$subfield,$itemrecord) if ($itemrecord);
175 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
176 my @authorised_values;
177 # builds list, depending on authorised value...
179 if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
180 my $sth=$dbh->prepare("select branchcode,branchname from branches");
182 push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
183 while (my ($branchcode,$branchname) = $sth->fetchrow_array) {
184 push @authorised_values, $branchcode;
187 } elsif ($tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes") {
188 my $sth=$dbh->prepare("select itemtype,description from itemtypes");
190 push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
191 while (my ($itemtype,$description) = $sth->fetchrow_array) {
192 push @authorised_values, $itemtype;
194 #---- "true" authorised value
196 $authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value});
197 push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
198 while ((my $value) = $authorised_values_sth->fetchrow_array) {
199 push @authorised_values, $value;
202 $subfield_data{marc_value}= CGI::scrolling_list(-name=>'field_value',
203 -values=> \@authorised_values,
208 } elsif ($tagslib->{$tag}->{$subfield}->{thesaurus_category}) {
209 $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>";
210 } elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
211 my $plugin="../value_builder/".$tagslib->{$tag}->{$subfield}->{'value_builder'};
213 my $extended_param = plugin_parameters($dbh,$record,$tagslib,$i,0);
214 $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>";
216 $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" value=\"$value\" size=50 maxlength=255>";
218 # $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
219 push(@loop_data, \%subfield_data);
223 my $template = gettemplate("acqui.simple/additem.tmpl");
224 # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
225 $template->param(item_loop => \@item_value_loop,
226 item_header_loop => \@header_value_loop,
231 print "Content-Type: text/html\n\n", $template->output;