X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=cataloguing%2Fadditem.pl;h=6229f0c52715a6c007ca51301f057708a40372ed;hb=f09e2ca27ee89860dbdd0ca512735f37fbfaf8a6;hp=c6f9daf582f9b3603da3dd30031062fd5328811d;hpb=14422c8ed9df29a6b89e8afe69c4d05056618124;p=koha_fer diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index c6f9daf582..6229f0c527 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -1,7 +1,8 @@ #!/usr/bin/perl - # Copyright 2000-2002 Katipo Communications +# Copyright 2004-2010 BibLibre +# Parts Copyright Catalyst IT 2011 # # This file is part of Koha. # @@ -33,6 +34,7 @@ use C4::Dates; use List::MoreUtils qw/any/; use MARC::File::XML; +use URI::Escape; my $dbh = C4::Context->dbh; @@ -64,12 +66,16 @@ sub get_item_from_barcode { sub set_item_default_location { my $itemnumber = shift; + my $item = GetItem( $itemnumber ); if ( C4::Context->preference('NewItemsDefaultLocation') ) { - my $item = GetItem( $itemnumber ); $item->{'permanent_location'} = $item->{'location'}; $item->{'location'} = C4::Context->preference('NewItemsDefaultLocation'); ModItem( $item, undef, $itemnumber); } + else { + $item->{'permanent_location'} = $item->{'location'} if !defined($item->{'permanent_location'}); + ModItem( $item, undef, $itemnumber); + } } # NOTE: This code is subject to change in the future with the implemenation of ajax based autobarcode code @@ -94,7 +100,8 @@ sub _increment_barcode { sub generate_subfield_form { my ($tag, $subfieldtag, $value, $tagslib,$subfieldlib, $branches, $today_iso, $biblionumber, $temp, $loop_data, $i) = @_; - + + my $frameworkcode = &GetFrameworkCode($biblionumber); my %subfield_data; my $dbh = C4::Context->dbh; my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib"); @@ -138,6 +145,10 @@ sub generate_subfield_form { } } + if ($frameworkcode eq 'FA' && $subfieldlib->{kohafield} eq 'items.barcode'){ + my $input = new CGI; + $value = $input->param('barcode'); + } my $attributes_no_value = qq(tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" ); my $attributes = qq($attributes_no_value value="$value" ); @@ -149,7 +160,7 @@ sub generate_subfield_form { foreach my $thisbranch (@$branches) { push @authorised_values, $thisbranch->{value}; $authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname}; - $value = $thisbranch->{value} if $thisbranch->{selected}; + $value = $thisbranch->{value} if $thisbranch->{selected} && !$value; } } elsif ( $subfieldlib->{authorised_value} eq "itemtypes" ) { @@ -261,11 +272,12 @@ sub generate_subfield_form { my $input = new CGI; -my $dbh = C4::Context->dbh; my $error = $input->param('error'); my $biblionumber = $input->param('biblionumber'); my $itemnumber = $input->param('itemnumber'); my $op = $input->param('op'); +my $hostitemnumber = $input->param('hostitemnumber'); +my $marcflavour = C4::Context->preference("marcflavour"); my $frameworkcode = &GetFrameworkCode($biblionumber); @@ -280,7 +292,7 @@ if (not defined $userflags) { } my ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "cataloguing/additem.tmpl", + = get_template_and_user({template_name => "cataloguing/additem.tt", query => $input, type => "intranet", authnotrequired => 0, @@ -411,6 +423,14 @@ if ($op eq "additem") { } undef($itemrecord); } + } + if ($frameworkcode eq 'FA' && $input->param('borrowernumber')){ + my $redirect_string = 'borrowernumber=' . uri_escape($input->param('borrowernumber')) . + '&barcode=' . uri_escape($input->param('barcode')); + $redirect_string .= '&duedatespec=' . uri_escape($input->param('duedatespec')) . + '&stickyduedate=1'; + print $input->redirect("/cgi-bin/koha/circ/circulation.pl?" . $redirect_string); + exit; } @@ -484,6 +504,20 @@ if ($op eq "additem") { $itemnumber=""; } $nextop="additem"; +} elsif ($op eq "delinkitem"){ + my $analyticfield = '773'; + if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){ + $analyticfield = '773'; + } elsif ($marcflavour eq 'UNIMARC') { + $analyticfield = '461'; + } + foreach my $field ($record->field($analyticfield)){ + if ($field->subfield('9') eq $hostitemnumber){ + $record->delete_field($field); + last; + } + } + my $modbibresult = ModBiblio($record, $biblionumber,''); } # @@ -493,13 +527,39 @@ if ($op eq "additem") { # now, build existiing item list my $temp = GetMarcBiblio( $biblionumber ); -my @fields = $temp->fields(); #my @fields = $record->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) = &GetMarcFromKohaField("items.itemnumber", $frameworkcode); my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", $frameworkcode); +C4::Biblio::EmbedItemsInMarcBiblio($temp, $biblionumber); +my @fields = $temp->fields(); + + +my @hostitemnumbers; +my $analyticfield = '773'; +if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC') { + $analyticfield = '773'; +} elsif ($marcflavour eq 'UNIMARC') { + $analyticfield = '461'; +} +foreach my $hostfield ($temp->field($analyticfield)){ + if ($hostfield->subfield('0')){ + my $hostrecord = GetMarcBiblio($hostfield->subfield('0'), 1); + my ($itemfield, undef) = GetMarcFromKohaField( 'items.itemnumber', GetFrameworkCode($hostfield->subfield('0')) ); + foreach my $hostitem ($hostrecord->field($itemfield)){ + if ($hostitem->subfield('9') eq $hostfield->subfield('9')){ + push (@fields, $hostitem); + push (@hostitemnumbers, $hostfield->subfield('9')); + } + } + } +} + + foreach my $field (@fields) { next if ( $field->tag() < 10 ); @@ -531,6 +591,19 @@ foreach my $field (@fields) { } } $this_row{itemnumber} = $subfieldvalue if ($field->tag() eq $itemtagfield && $subfieldcode eq $itemtagsubfield); + foreach my $hostitemnumber (@hostitemnumbers){ + if ($this_row{itemnumber} eq $hostitemnumber){ + $this_row{hostitemflag} = 1; + $this_row{hostbiblionumber}= GetBiblionumberFromItemnumber($hostitemnumber); + last; + } + } + +# my $countanalytics=GetAnalyticsCount($this_row{itemnumber}); +# if ($countanalytics > 0){ +# $this_row{countanalytics} = $countanalytics; +# } + } if (%this_row) { push(@big_array, \%this_row); @@ -551,6 +624,9 @@ for my $row ( @big_array ) { $row_data{itemnumber} = $row->{itemnumber}; #reporting this_row values $row_data{'nomod'} = $row->{'nomod'}; + $row_data{'hostitemflag'} = $row->{'hostitemflag'}; + $row_data{'hostbiblionumber'} = $row->{'hostbiblionumber'}; +# $row_data{'countanalytics'} = $row->{'countanalytics'}; push(@item_value_loop,\%row_data); } foreach my $subfield_code (sort keys(%witness)) { @@ -569,10 +645,14 @@ my $onlymine = C4::Context->preference('IndependantBranches') && C4::Context->userenv && C4::Context->userenv->{flags}!=1 && C4::Context->userenv->{branch}; -my $branches = GetBranchesLoop(undef,$onlymine); # build once ahead of time, instead of multiple times later. +my $branch = C4::Context->userenv->{branch}; +if ($frameworkcode eq 'FA'){ + $branch = $input->param('branch'); +} +my $branches = GetBranchesLoop($branch,$onlymine); # build once ahead of time, instead of multiple times later. # We generate form, from actuel record -my @fields; +@fields = (); if($itemrecord){ foreach my $field ($itemrecord->fields()){ my $tag = $field->{_tag}; @@ -611,6 +691,7 @@ foreach my $tag ( keys %{$tagslib}){ } } } +@loop_data = sort {$a->{subfield} cmp $b->{subfield} } @loop_data; # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit. $template->param( title => $record->title() ) if ($record ne "-1"); @@ -628,6 +709,14 @@ $template->param( opisadd => ($nextop eq "saveitem") ? 0 : 1, C4::Search::enabled_staff_search_views, ); + +if ($frameworkcode eq 'FA'){ + $template->{VARS}->{'borrowernumber'}=$input->param('borrowernumber'); + $template->{VARS}->{'barcode'}=$input->param('barcode'); + $template->{VARS}->{'stickyduedate'}=$input->param('stickduedate'); + $template->{VARS}->{'duedatespec'}=$input->param('duedatespec'); +} + foreach my $error (@errors) { $template->param($error => 1); }