#!/usr/bin/perl # $Id$ # Copyright 2000-2002 Katipo Communications # # This file is part of Koha. # # Koha is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any later # version. # # Koha is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, # Suite 330, Boston, MA 02111-1307 USA use CGI; use strict; use C4::Auth; use C4::Output; use C4::Interface::CGI::Output; use C4::Biblio; use C4::Context; use C4::Koha; # XXX subfield_is_koha_internal_p use C4::Search; use HTML::Template; use MARC::File::USMARC; sub find_value { my ($tagfield,$insubfield,$record) = @_; my $result; my $indicator; foreach my $field ($record->field($tagfield)) { my @subfields = $field->subfields(); foreach my $subfield (@subfields) { if (@$subfield[0] eq $insubfield) { $result .= @$subfield[1]; $indicator = $field->indicator(1).$field->indicator(2); } } } return($indicator,$result); } my $input = new CGI; my $dbh = C4::Context->dbh; my $error = $input->param('error'); my $bibid = $input->param('bibid'); my $oldbiblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid); my $op = $input->param('op'); my $itemnum = $input->param('itemnum'); # find itemtype my $itemtype = &MARCfind_frameworkcode($dbh,$bibid); my $tagslib = &MARCgettagslib($dbh,1,$itemtype); my $record = MARCgetbiblio($dbh,$bibid); my $itemrecord; my $nextop="additem"; my @errors; # store errors found while checking data BEFORE saving item. #------------------------------------------------------------------------------------------------------------------------------ if ($op eq "additem") { #------------------------------------------------------------------------------------------------------------------------------ # rebuild my @tags = $input->param('tag'); my @subfields = $input->param('subfield'); my @values = $input->param('field_value'); # build indicator hash. my @ind_tag = $input->param('ind_tag'); my @indicator = $input->param('indicator'); my %indicators; for (my $i=0;$i<=$#ind_tag;$i++) { $indicators{$ind_tag[$i]} = $indicator[$i]; } my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values,%indicators); # check for item barcode # being unique my $oldbibid = MARCmarc2koha($dbh,$record); my $exists = itemdata($oldbibid->{'barcode'}); push @errors,"barcode_not_unique" if($exists); # MARC::Record builded => now, record in DB # if barcode exists, don't create, but report The problem. my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = NEWnewitem($dbh,$record,$bibid) unless ($exists); if ($exists) { $nextop = "additem"; $itemrecord = $record; } else { $nextop = "additem"; } #------------------------------------------------------------------------------------------------------------------------------ } elsif ($op eq "edititem") { #------------------------------------------------------------------------------------------------------------------------------ # retrieve item if exist => then, it's a modif $itemrecord = MARCgetitem($dbh,$bibid,$itemnum); $nextop="saveitem"; #------------------------------------------------------------------------------------------------------------------------------ } elsif ($op eq "delitem") { #------------------------------------------------------------------------------------------------------------------------------ # retrieve item if exist => then, it's a modif &NEWdelitem($dbh,$bibid,$itemnum); $nextop="additem"; #------------------------------------------------------------------------------------------------------------------------------ } elsif ($op eq "saveitem") { #------------------------------------------------------------------------------------------------------------------------------ # rebuild my @tags = $input->param('tag'); my @subfields = $input->param('subfield'); my @values = $input->param('field_value'); # build indicator hash. my @ind_tag = $input->param('ind_tag'); my @indicator = $input->param('indicator'); # my $itemnum = $input->param('itemnum'); my %indicators; for (my $i=0;$i<=$#ind_tag;$i++) { $indicators{$ind_tag[$i]} = $indicator[$i]; } my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values,%indicators); # MARC::Record builded => now, record in DB my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = NEWmoditem($dbh,$record,$bibid,$itemnum,0); $itemnum=""; $nextop="additem"; } # #------------------------------------------------------------------------------------------------------------------------------ # build screen with existing items. and "new" one #------------------------------------------------------------------------------------------------------------------------------ my %indicators; $indicators{995}=' '; # now, build existiing item list my $temp = MARCgetbiblio($dbh,$bibid); my @fields = $temp->fields(); my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code my @big_array; #---- finds where items.itemnumber is stored my ($itemtagfield,$itemtagsubfield) = &MARCfind_marc_from_kohafield($dbh,"items.itemnumber",$itemtype); my @itemnums; # array to store itemnums foreach my $field (@fields) { next if ($field->tag()<10); my @subf=$field->subfields; my %this_row; # loop through each subfield for my $i (0..$#subf) { next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} ne 10 && ($field->tag() ne $itemtagfield && $subf[$i][0] ne $itemtagsubfield)); $witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib} if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} eq 10); $this_row{$subf[$i][0]} =$subf[$i][1] if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} eq 10); push @itemnums,$this_row{$subf[$i][0]} =$subf[$i][1] if ($field->tag() eq $itemtagfield && $subf[$i][0] eq $itemtagsubfield); } if (%this_row) { push(@big_array, \%this_row); } } #fill big_row with missing datas foreach my $subfield_code (keys(%witness)) { for (my $i=0;$i<=$#big_array;$i++) { $big_array[$i]{$subfield_code}=" " unless ($big_array[$i]{$subfield_code}); } } # now, construct template ! my @item_value_loop; my @header_value_loop; for (my $i=0;$i<=$#big_array; $i++) { my $items_data; foreach my $subfield_code (sort keys(%witness)) { $items_data .="