View | Details | Raw Unified | Return to bug 7412
Collapse All | Expand All

(-)a/cataloguing/additem.pl (-15 / +108 lines)
Lines 32-37 use C4::Branch; # XXX subfield_is_koha_internal_p Link Here
32
use C4::ClassSource;
32
use C4::ClassSource;
33
use C4::Dates;
33
use C4::Dates;
34
use List::MoreUtils qw/any/;
34
use List::MoreUtils qw/any/;
35
use Storable qw(thaw freeze);
36
use URI::Escape;
37
38
35
39
36
use MARC::File::XML;
40
use MARC::File::XML;
37
use URI::Escape;
41
use URI::Escape;
Lines 275-280 sub generate_subfield_form { Link Here
275
        return \%subfield_data;
279
        return \%subfield_data;
276
}
280
}
277
281
282
# Removes some subfields (defined in the SubfieldsToDiscardWhenPrefill syspref) when prefilling items
283
sub removeFieldsForPrefill {
284
285
    my $item = shift;
286
287
    # Getting item tag
288
    my ($tag, $subtag) = GetMarcFromKohaField("items.barcode", '');
289
290
    # Getting list of subfields to remove
291
    my $subfieldsToDiscardWhenPrefill = C4::Context->preference('SubfieldsToDiscardWhenPrefill');
292
293
    # Removing subfields
294
    if ($tag && $subfieldsToDiscardWhenPrefill) {
295
        my $field = $item->field($tag);
296
        my @subfieldsToDiscard= split(/ /,$subfieldsToDiscardWhenPrefill);
297
        foreach my $subfieldsDiscard(@subfieldsToDiscard) {
298
            $field->delete_subfield(code => $subfieldsDiscard);
299
        }
300
    }
301
302
    return $item;
303
304
}
278
305
279
my $input        = new CGI;
306
my $input        = new CGI;
280
my $error        = $input->param('error');
307
my $error        = $input->param('error');
Lines 315-323 my $oldrecord = TransformMarcToKoha($dbh,$record); Link Here
315
my $itemrecord;
342
my $itemrecord;
316
my $nextop="additem";
343
my $nextop="additem";
317
my @errors; # store errors found while checking data BEFORE saving item.
344
my @errors; # store errors found while checking data BEFORE saving item.
345
346
# Getting last created item cookie
347
my $prefillitem = C4::Context->preference('PrefillItem');
348
my $justaddeditem;
349
my $cookieitemrecord;
350
if ($prefillitem) {
351
    my $lastitemcookie = $input->cookie('LastCreatedItem');
352
    if ($lastitemcookie) {
353
	$lastitemcookie = uri_unescape($lastitemcookie);
354
	if ( thaw($lastitemcookie) ) {
355
	    $cookieitemrecord = thaw($lastitemcookie) ;
356
	    $cookieitemrecord = removeFieldsForPrefill($cookieitemrecord);
357
	}
358
    }
359
}
360
318
#-------------------------------------------------------------------------------
361
#-------------------------------------------------------------------------------
319
if ($op eq "additem") {
362
if ($op eq "additem") {
320
#-------------------------------------------------------------------------------
363
364
    #-------------------------------------------------------------------------------
321
    # rebuild
365
    # rebuild
322
    my @tags      = $input->param('tag');
366
    my @tags      = $input->param('tag');
323
    my @subfields = $input->param('subfield');
367
    my @subfields = $input->param('subfield');
Lines 334-359 if ($op eq "additem") { Link Here
334
    my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
378
    my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
335
    my $number_of_copies           = $input->param('number_of_copies');
379
    my $number_of_copies           = $input->param('number_of_copies');
336
380
381
    # This is a bit tricky : if there is a cookie for the last created item and
382
    # we just added an item, the cookie value is not correct yet (it will be updated
383
    # next page). To prevent the form from being filled with outdated values, we
384
    # force the use of "add and duplicate" feature, so the form will be filled with 
385
    # correct values.
386
    $add_duplicate_submit = 1 if ($prefillitem);
387
    $justaddeditem = 1;
388
389
    # if autoBarcode is set to 'incremental', calculate barcode...
390
    # NOTE: This code is subject to change in 3.2 with the implemenation of ajax based autobarcode code
391
    # NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
392
    if ( C4::Context->preference('autoBarcode') eq 'incremental' ) {
393
        my ( $tagfield, $tagsubfield ) = &GetMarcFromKohaField( "items.barcode", $frameworkcode );
394
        unless ( $record->field($tagfield)->subfield($tagsubfield) ) {
395
            my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items");
396
            $sth_barcode->execute;
397
            my ($newbarcode) = $sth_barcode->fetchrow;
398
            $newbarcode++;
399
400
            # OK, we have the new barcode, now create the entry in MARC record
401
            my $fieldItem = $record->field($tagfield);
402
            $record->delete_field($fieldItem);
403
            $fieldItem->add_subfields( $tagsubfield => $newbarcode );
404
            $record->insert_fields_ordered($fieldItem);
405
        }
406
    }
407
408
337
    if (C4::Context->preference('autoBarcode') eq 'incremental') {
409
    if (C4::Context->preference('autoBarcode') eq 'incremental') {
338
        $record = _increment_barcode($record, $frameworkcode);
410
        $record = _increment_barcode($record, $frameworkcode);
339
    }
411
    }
340
412
341
    my $addedolditem = TransformMarcToKoha($dbh,$record);
413
    my $addedolditem = TransformMarcToKoha( $dbh, $record );
342
414
343
    # If we have to add or add & duplicate, we add the item
415
    # If we have to add or add & duplicate, we add the item
344
    if ($add_submit || $add_duplicate_submit) {
416
    if ( $add_submit || $add_duplicate_submit ) {
345
	# check for item barcode # being unique
417
346
	my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
418
        # check for item barcode # being unique
347
	push @errors,"barcode_not_unique" if($exist_itemnumber);
419
        my $exist_itemnumber = get_item_from_barcode( $addedolditem->{'barcode'} );
348
	# if barcode exists, don't create, but report The problem.
420
        push @errors, "barcode_not_unique" if ($exist_itemnumber);
349
    unless ($exist_itemnumber) {
421
350
	    my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber);
422
        # if barcode exists, don't create, but report The problem.
351
        set_item_default_location($oldbibitemnum);
423
        unless ($exist_itemnumber) {
352
    }
424
            my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber );
353
	$nextop = "additem";
425
            set_item_default_location($oldbibitemnum);
354
	if ($exist_itemnumber) {
426
355
	    $itemrecord = $record;
427
	  # Pushing the last created item cookie back
356
	}
428
	  if ($prefillitem && defined $record) {
429
                my $itemcookie = $input->cookie(
430
                    -name => 'LastCreatedItem',
431
                    # We uri_escape the whole freezed structure so we're sure we won't have any encoding problems
432
                    -value   => uri_escape( freeze( $record ) ),
433
                    -expires => ''
434
                );
435
436
		$cookie = ( $cookie, $itemcookie );
437
	    }
438
439
        }
440
        $nextop = "additem";
441
        if ($exist_itemnumber) {
442
            $itemrecord = $record;
443
        }
357
    }
444
    }
358
445
359
    # If we have to add & duplicate
446
    # If we have to add & duplicate
Lines 370-375 if ($op eq "additem") { Link Here
370
            $fieldItem->delete_subfields($tagsubfield);
457
            $fieldItem->delete_subfields($tagsubfield);
371
            $itemrecord->insert_fields_ordered($fieldItem);
458
            $itemrecord->insert_fields_ordered($fieldItem);
372
        }
459
        }
460
	$itemrecord = removeFieldsForPrefill($itemrecord) if ($prefillitem);
373
    }
461
    }
374
462
375
    # If we have to add multiple copies
463
    # If we have to add multiple copies
Lines 698-703 if($itemrecord){ Link Here
698
            }
786
            }
699
    # and now we add fields that are empty
787
    # and now we add fields that are empty
700
788
789
# Using last created item if it exists
790
791
$itemrecord = $cookieitemrecord if ($prefillitem and not $justaddeditem and $op ne "edititem"); 
792
793
# We generate form, and fill with values if defined
701
foreach my $tag ( keys %{$tagslib}){
794
foreach my $tag ( keys %{$tagslib}){
702
    foreach my $subtag (keys %{$tagslib->{$tag}}){
795
    foreach my $subtag (keys %{$tagslib->{$tag}}){
703
        next if subfield_is_koha_internal_p($subtag);
796
        next if subfield_is_koha_internal_p($subtag);
(-)a/installer/data/mysql/sysprefs.sql (+2 lines)
Lines 328-331 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' Link Here
328
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OpacKohaUrl','1',"Show 'Powered by Koha' text on OPAC footer.",NULL,NULL);
328
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OpacKohaUrl','1',"Show 'Powered by Koha' text on OPAC footer.",NULL,NULL);
329
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('EasyAnalyticalRecords','0','If on, display in the catalogue screens tools to easily setup analytical record relationships','','YesNo');
329
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('EasyAnalyticalRecords','0','If on, display in the catalogue screens tools to easily setup analytical record relationships','','YesNo');
330
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacShowRecentComments',0,'If ON a link to recent comments will appear in the OPAC masthead',NULL,'YesNo');
330
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacShowRecentComments',0,'If ON a link to recent comments will appear in the OPAC masthead',NULL,'YesNo');
331
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('PrefillItem','0','When a new item is added, should it be prefilled with last created item values?','','YesNo');
332
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SubfieldsToDiscardWhenPrefill','','Define a list of subfields to discard when prefilling items (separated by space)','','Free');
331
333
(-)a/installer/data/mysql/updatedatabase.pl (-2 / +14 lines)
Lines 4585-4590 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4585
    SetVersion($DBversion);
4585
    SetVersion($DBversion);
4586
}
4586
}
4587
4587
4588
$DBversion = "3.06.03.002";
4589
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
4590
    $dbh->do("
4591
    INSERT IGNORE INTO `systempreferences` (variable,value,explanation,options,type) VALUES('PrefillItem','0','When a new item is added, should it be prefilled with last created item values?','','YesNo');
4592
    ");
4593
4594
    $dbh->do(
4595
            "INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SubfieldsToDiscardWhenPrefill','','Define a list of subfields to discard when prefilling items (separated by space)','','Free');"
4596
    );
4597
4598
    print "Upgrade to $DBversion done (Adding PrefillItem and SubfieldsToDiscardWhenPrefill sysprefs)\n";
4599
    SetVersion($DBversion);
4600
}
4601
4588
=head1 FUNCTIONS
4602
=head1 FUNCTIONS
4589
4603
4590
=head2 DropAllForeignKeys($table)
4604
=head2 DropAllForeignKeys($table)
Lines 4592-4599 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4592
Drop all foreign keys of the table $table
4606
Drop all foreign keys of the table $table
4593
4607
4594
=cut
4608
=cut
4595
4596
4597
sub DropAllForeignKeys {
4609
sub DropAllForeignKeys {
4598
    my ($table) = @_;
4610
    my ($table) = @_;
4599
    # get the table description
4611
    # get the table description
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (-1 / +10 lines)
Lines 90-95 Cataloging: Link Here
90
                  annual: generated in the form &lt;year&gt;-0001, &lt;year&gt;-0002.
90
                  annual: generated in the form &lt;year&gt;-0001, &lt;year&gt;-0002.
91
                  hbyymmincr: generated in the form &lt;branchcode&gt;yymm0001.
91
                  hbyymmincr: generated in the form &lt;branchcode&gt;yymm0001.
92
                  "OFF": not generated automatically.
92
                  "OFF": not generated automatically.
93
        -
94
            - When a new item is added, should it be prefilled with last created item values?
95
            - pref: PrefillItem
96
              choices:
97
                  yes: the new item is prefilled with last created item values
98
                  no: the new item is not prefilled with last created item values
99
        -
100
            - Define a list of subfields to discard when prefilling items (separated by space)
101
            - pref: SubfieldsToDiscardWhenPrefill
102
93
    Display:
103
    Display:
94
        -
104
        -
95
            - 'Separate multiple displayed authors, series or subjects with '
105
            - 'Separate multiple displayed authors, series or subjects with '
96
- 

Return to bug 7412