3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 * modsubscriptionhistory :to modify the subscription history
31 * serialchangestatus :to modify the status of this subscription
67 use C4
::Dates qw
/format_date format_date_in_iso/;
75 my $query = CGI
->new();
76 my $dbh = C4
::Context
->dbh;
77 my @serialids = $query->param('serialid');
78 my @serialseqs = $query->param('serialseq');
79 my @planneddates = $query->param('planneddate');
80 my @publisheddates = $query->param('publisheddate');
81 my @status = $query->param('status');
82 my @notes = $query->param('notes');
83 my @subscriptionids = $query->param('subscriptionid');
84 my $op = $query->param('op');
85 if ( scalar(@subscriptionids) == 1 && index( $subscriptionids[0], q
|,| ) > 0 ) {
86 @subscriptionids = split( /,/, $subscriptionids[0] );
91 # If user comes from subscription details
93 foreach my $subscriptionid (@subscriptionids) {
94 my $serstatus = $query->param('serstatus');
96 my @tmpser = GetSerials2
( $subscriptionid, $serstatus );
98 push @serialids, $_->{'serialid'};
104 unless ( scalar(@serialids) ) {
106 "serials-collection.pl?subscriptionid=" . join( ",", @subscriptionids );
109 print $query->redirect($string);
112 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
114 template_name
=> "serials/serials-edit.tmpl",
117 authnotrequired
=> 0,
118 flagsrequired
=> {serials
=> 'receive_serials'},
124 my %processedserialid;
126 my $today = C4
::Dates
->new();
127 foreach my $tmpserialid (@serialids) {
129 #filtering serialid for duplication
130 #NEW serial should appear only once and are created afterwards
131 if ( defined($tmpserialid)
132 && $tmpserialid =~ /^[0-9]+$/
133 && !$processedserialid{$tmpserialid} )
135 my $data = GetSerialInformation
($tmpserialid);
136 $data->{publisheddate
} = format_date
( $data->{publisheddate
} );
137 $data->{planneddate
} = format_date
( $data->{planneddate
} );
138 $data->{arriveddate
}=$today->output('syspref');
139 $data->{'editdisable'} = (
141 HasSubscriptionExpired
( $data->{subscriptionid
} )
142 && $data->{'status1'}
144 || $data->{'cannotedit'}
146 push @serialdatalist, $data;
147 $processedserialid{$tmpserialid} = 1;
150 my $bibdata = GetBiblioData
( $serialdatalist[0]->{'biblionumber'} );
153 my @subscriptionloop;
155 # check, for each subscription edited, that we have an empty item line if applicable for the subscription
156 my %processedsubscriptionid;
157 foreach my $subscriptionid (@subscriptionids) {
159 #Do not process subscriptionid twice if it was already processed.
160 if ( defined($subscriptionid)
161 && !$processedsubscriptionid{$subscriptionid} )
164 if ( $serialdatalist[0]->{'serialsadditems'} ) {
166 #Create New empty item
168 PrepareItemrecordDisplay
( $serialdatalist[0]->{'biblionumber'},
169 '', GetSubscription
($subscriptionid) );
170 $cell->{serialsadditems
} = 1;
172 $cell->{'subscriptionid'} = $subscriptionid;
173 $cell->{'itemid'} = "NNEW";
174 $cell->{'serialid'} = "NEW";
175 $cell->{'issuesatonce'} = 1;
176 push @newserialloop, $cell;
177 push @subscriptionloop,
179 'subscriptionid' => $subscriptionid,
180 'abouttoexpire' => abouttoexpire
($subscriptionid),
181 'subscriptionexpired' => HasSubscriptionExpired
($subscriptionid),
183 $processedsubscriptionid{$subscriptionid} = 1;
186 $template->param( newserialloop
=> \
@newserialloop );
187 $template->param( subscriptions
=> \
@subscriptionloop );
189 if ( $op and $op eq 'serialchangestatus' ) {
192 for ( my $i = 0 ; $i <= $#serialids ; $i++ ) {
194 if ( $serialids[$i] && $serialids[$i] eq "NEW" ) {
195 if ( $serialseqs[$i] ) {
197 #IF newserial was provided a name Then we have to create a newSerial
198 ### FIXME if NewIssue is modified to use subscription biblionumber, then biblionumber would not be useful.
199 $newserial = NewIssue
(
201 $subscriptionids[$i],
202 $serialdatalist[0]->{'biblionumber'},
204 format_date_in_iso
( $planneddates[$i] ),
205 format_date_in_iso
( $publisheddates[$i] ),
210 elsif ( $serialids[$i] ) {
214 format_date_in_iso
( $planneddates[$i] ),
215 format_date_in_iso
( $publisheddates[$i] ),
221 my @moditems = $query->param('moditem');
222 if ( scalar(@moditems) ) {
223 my @tags = $query->param('tag');
224 my @subfields = $query->param('subfield');
225 my @field_values = $query->param('field_value');
226 my @serials = $query->param('serial');
227 my @bibnums = $query->param('bibnum');
228 my @itemid = $query->param('itemid');
229 my @ind_tag = $query->param('ind_tag');
230 my @indicator = $query->param('indicator');
232 #Rebuilding ALL the data for items into a hash
233 # parting them on $itemid.
236 my $range = scalar(@itemid);
237 for ( my $i = 0 ; $i < $range ; $i++ ) {
238 unless ( $itemhash{ $itemid[$i] } ) {
239 if ( $serials[$countdistinct]
240 && $serials[$countdistinct] ne "NEW" )
242 $itemhash{ $itemid[$i] }->{'serial'} =
243 $serials[$countdistinct];
246 $itemhash{ $itemid[$i] }->{'serial'} = $newserial;
248 $itemhash{ $itemid[$i] }->{'bibnum'} = $bibnums[$countdistinct];
251 push @
{ $itemhash{ $itemid[$i] }->{'tags'} }, $tags[$i];
252 push @
{ $itemhash{ $itemid[$i] }->{'subfields'} }, $subfields[$i];
253 push @
{ $itemhash{ $itemid[$i] }->{'field_values'} },
255 push @
{ $itemhash{ $itemid[$i] }->{'ind_tag'} }, $ind_tag[$i];
256 push @
{ $itemhash{ $itemid[$i] }->{'indicator'} }, $indicator[$i];
258 foreach my $item ( keys %itemhash ) {
260 # Verify Itemization is "Valid", i.e. serial status is Arrived or Missing
262 for ( my $i = 0 ; $i < scalar(@serialids) ; $i++ ) {
264 $itemhash{$item}->{serial
} eq $serialids[$i]
265 || ( $itemhash{$item}->{serial
} == $newserial
266 && $serialids[$i] eq 'NEW' )
271 if ( $index >= 0 && $status[$index] == 2 ) {
272 my $xml = TransformHtmlToXml
(
273 $itemhash{$item}->{'tags'},
274 $itemhash{$item}->{'subfields'},
275 $itemhash{$item}->{'field_values'},
276 $itemhash{$item}->{'indicator'},
277 $itemhash{$item}->{'ind_tag'}
281 my $bib_record = MARC
::Record
::new_from_xml
( $xml, 'UTF-8' );
282 if ( $item =~ /^N/ ) {
286 # if autoBarcode is set to 'incremental', calculate barcode...
287 my ( $barcodetagfield, $barcodetagsubfield ) =
288 GetMarcFromKohaField
(
291 $serialdatalist[0]->{'biblionumber'}
294 if ( C4
::Context
->preference("autoBarcode") eq
297 if ( !$bib_record->field($barcodetagfield)
298 ->subfield($barcodetagsubfield) )
300 my $sth_barcode = $dbh->prepare(
301 "select max(abs(barcode)) from items");
302 $sth_barcode->execute;
303 my ($newbarcode) = $sth_barcode->fetchrow;
305 # OK, we have the new barcode, add the entry in MARC record # FIXME -> should be using barcode plugin here.
306 $bib_record->field($barcodetagfield)
307 ->update( $barcodetagsubfield => ++$newbarcode );
311 # check for item barcode # being unique
314 $bib_record->subfield(
315 $barcodetagfield, $barcodetagsubfield
319 $exists = GetItemnumberFromBarcode
(
320 $bib_record->subfield(
321 $barcodetagfield, $barcodetagsubfield
326 # push @errors,"barcode_not_unique" if($exists);
327 # if barcode exists, don't create, but report The problem.
329 push @errors, 'barcode_not_unique';
330 push @errseq, { serialseq
=> $serialseqs[$index] };
333 my ( $biblionumber, $bibitemnum, $itemnumber ) =
334 AddItemFromMarc
( $bib_record,
335 $itemhash{$item}->{bibnum
} );
336 AddItem2Serial
( $itemhash{$item}->{serial
},
343 my ( $oldbiblionumber, $oldbibnum, $itemnumber ) =
344 ModItemFromMarc
( $bib_record,
345 $itemhash{$item}->{'bibnum'}, $item );
353 $template->param( Errors
=> 1 );
355 $template->param( barcode_not_unique
=> 1, errseq
=> \
@errseq );
359 my $redirect = "serials-collection.pl?";
360 $redirect .= join( '&', map { "subscriptionid=" . $_ } sort @subscriptionids );# ID The sort necessary
361 print $query->redirect($redirect);
364 my $default_bib_view = get_default_view
();
367 serialsadditems
=> $serialdatalist[0]->{'serialsadditems'},
368 bibliotitle
=> $bibdata->{'title'},
369 biblionumber
=> $serialdatalist[0]->{'biblionumber'},
370 serialslist
=> \
@serialdatalist,
371 default_bib_view
=> $default_bib_view,
373 output_html_with_http_headers
$query, $cookie, $template->output;
375 sub get_default_view
{
376 my $defaultview = C4
::Context
->preference('IntranetBiblioDefaultView');
377 my $views = { C4
::Search
::enabled_staff_search_views
};
378 if ($defaultview eq 'isbd' && $views->{can_view_ISBD
}) {
380 } elsif ($defaultview eq 'marc' && $views->{can_view_MARC
}) {
382 } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC
}) {
383 return 'labeledMARCdetail';