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

(-)a/cataloguing/additem.pl (-15 / +111 lines)
Lines 33-38 use C4::ClassSource; Link Here
33
use C4::Dates;
33
use C4::Dates;
34
use List::MoreUtils qw/any/;
34
use List::MoreUtils qw/any/;
35
use C4::Search;
35
use C4::Search;
36
use Storable qw(thaw freeze);
37
use URI::Escape;
38
36
39
37
use MARC::File::XML;
40
use MARC::File::XML;
38
use URI::Escape;
41
use URI::Escape;
Lines 277-282 sub generate_subfield_form { Link Here
277
        return \%subfield_data;
280
        return \%subfield_data;
278
}
281
}
279
282
283
# Removes some subfields when prefilling items
284
# This function will remove any subfield that is not in the SubfieldsToUseWhenPrefill syspref
285
sub removeFieldsForPrefill {
286
287
    my $item = shift;
288
289
    # Getting item tag
290
    my ($tag, $subtag) = GetMarcFromKohaField("items.barcode", '');
291
292
    # Getting list of subfields to keep
293
    my $subfieldsToUseWhenPrefill = C4::Context->preference('SubfieldsToUseWhenPrefill');
294
295
    # Removing subfields that are not in the syspref
296
    if ($tag && $subfieldsToUseWhenPrefill) {
297
        my $field = $item->field($tag);
298
        my @subfieldsToUse= split(/ /,$subfieldsToUseWhenPrefill);
299
        foreach my $subfield ($field->subfields()) {
300
            if (!grep { $subfield->[0] eq $_ } @subfieldsToUse) {
301
                $field->delete_subfield(code => $subfield->[0]);
302
            }
303
304
        }
305
    }
306
307
    return $item;
308
309
}
280
310
281
my $input        = new CGI;
311
my $input        = new CGI;
282
my $error        = $input->param('error');
312
my $error        = $input->param('error');
Lines 315-323 my $oldrecord = TransformMarcToKoha($dbh,$record); Link Here
315
my $itemrecord;
345
my $itemrecord;
316
my $nextop="additem";
346
my $nextop="additem";
317
my @errors; # store errors found while checking data BEFORE saving item.
347
my @errors; # store errors found while checking data BEFORE saving item.
348
349
# Getting last created item cookie
350
my $prefillitem = C4::Context->preference('PrefillItem');
351
my $justaddeditem;
352
my $cookieitemrecord;
353
if ($prefillitem) {
354
    my $lastitemcookie = $input->cookie('LastCreatedItem');
355
    if ($lastitemcookie) {
356
	$lastitemcookie = uri_unescape($lastitemcookie);
357
	if ( thaw($lastitemcookie) ) {
358
	    $cookieitemrecord = thaw($lastitemcookie) ;
359
	    $cookieitemrecord = removeFieldsForPrefill($cookieitemrecord);
360
	}
361
    }
362
}
363
318
#-------------------------------------------------------------------------------
364
#-------------------------------------------------------------------------------
319
if ($op eq "additem") {
365
if ($op eq "additem") {
320
#-------------------------------------------------------------------------------
366
367
    #-------------------------------------------------------------------------------
321
    # rebuild
368
    # rebuild
322
    my @tags      = $input->param('tag');
369
    my @tags      = $input->param('tag');
323
    my @subfields = $input->param('subfield');
370
    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');
381
    my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
335
    my $number_of_copies           = $input->param('number_of_copies');
382
    my $number_of_copies           = $input->param('number_of_copies');
336
383
384
    # This is a bit tricky : if there is a cookie for the last created item and
385
    # we just added an item, the cookie value is not correct yet (it will be updated
386
    # next page). To prevent the form from being filled with outdated values, we
387
    # force the use of "add and duplicate" feature, so the form will be filled with 
388
    # correct values.
389
    $add_duplicate_submit = 1 if ($prefillitem);
390
    $justaddeditem = 1;
391
392
    # if autoBarcode is set to 'incremental', calculate barcode...
393
    # NOTE: This code is subject to change in 3.2 with the implemenation of ajax based autobarcode code
394
    # NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
395
    if ( C4::Context->preference('autoBarcode') eq 'incremental' ) {
396
        my ( $tagfield, $tagsubfield ) = &GetMarcFromKohaField( "items.barcode", $frameworkcode );
397
        unless ( $record->field($tagfield)->subfield($tagsubfield) ) {
398
            my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items");
399
            $sth_barcode->execute;
400
            my ($newbarcode) = $sth_barcode->fetchrow;
401
            $newbarcode++;
402
403
            # OK, we have the new barcode, now create the entry in MARC record
404
            my $fieldItem = $record->field($tagfield);
405
            $record->delete_field($fieldItem);
406
            $fieldItem->add_subfields( $tagsubfield => $newbarcode );
407
            $record->insert_fields_ordered($fieldItem);
408
        }
409
    }
410
411
337
    if (C4::Context->preference('autoBarcode') eq 'incremental') {
412
    if (C4::Context->preference('autoBarcode') eq 'incremental') {
338
        $record = _increment_barcode($record, $frameworkcode);
413
        $record = _increment_barcode($record, $frameworkcode);
339
    }
414
    }
340
415
341
    my $addedolditem = TransformMarcToKoha($dbh,$record);
416
    my $addedolditem = TransformMarcToKoha( $dbh, $record );
342
417
343
    # If we have to add or add & duplicate, we add the item
418
    # If we have to add or add & duplicate, we add the item
344
    if ($add_submit || $add_duplicate_submit) {
419
    if ( $add_submit || $add_duplicate_submit ) {
345
	# check for item barcode # being unique
420
346
	my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
421
        # check for item barcode # being unique
347
	push @errors,"barcode_not_unique" if($exist_itemnumber);
422
        my $exist_itemnumber = get_item_from_barcode( $addedolditem->{'barcode'} );
348
	# if barcode exists, don't create, but report The problem.
423
        push @errors, "barcode_not_unique" if ($exist_itemnumber);
349
    unless ($exist_itemnumber) {
424
350
	    my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber);
425
        # if barcode exists, don't create, but report The problem.
351
        set_item_default_location($oldbibitemnum);
426
        unless ($exist_itemnumber) {
352
    }
427
            my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber );
353
	$nextop = "additem";
428
            set_item_default_location($oldbibitemnum);
354
	if ($exist_itemnumber) {
429
355
	    $itemrecord = $record;
430
	  # Pushing the last created item cookie back
356
	}
431
	  if ($prefillitem && defined $record) {
432
                my $itemcookie = $input->cookie(
433
                    -name => 'LastCreatedItem',
434
                    # We uri_escape the whole freezed structure so we're sure we won't have any encoding problems
435
                    -value   => uri_escape( freeze( $record ) ),
436
                    -expires => ''
437
                );
438
439
		$cookie = ( $cookie, $itemcookie );
440
	    }
441
442
        }
443
        $nextop = "additem";
444
        if ($exist_itemnumber) {
445
            $itemrecord = $record;
446
        }
357
    }
447
    }
358
448
359
    # If we have to add & duplicate
449
    # If we have to add & duplicate
Lines 370-375 if ($op eq "additem") { Link Here
370
            $fieldItem->delete_subfields($tagsubfield);
460
            $fieldItem->delete_subfields($tagsubfield);
371
            $itemrecord->insert_fields_ordered($fieldItem);
461
            $itemrecord->insert_fields_ordered($fieldItem);
372
        }
462
        }
463
	$itemrecord = removeFieldsForPrefill($itemrecord) if ($prefillitem);
373
    }
464
    }
374
465
375
    # If we have to add multiple copies
466
    # If we have to add multiple copies
Lines 693-698 if($itemrecord){ Link Here
693
            }
784
            }
694
    # and now we add fields that are empty
785
    # and now we add fields that are empty
695
786
787
# Using last created item if it exists
788
789
$itemrecord = $cookieitemrecord if ($prefillitem and not $justaddeditem and $op ne "edititem"); 
790
791
# We generate form, and fill with values if defined
696
foreach my $tag ( keys %{$tagslib}){
792
foreach my $tag ( keys %{$tagslib}){
697
    foreach my $subtag (keys %{$tagslib->{$tag}}){
793
    foreach my $subtag (keys %{$tagslib->{$tag}}){
698
        next if subfield_is_koha_internal_p($subtag);
794
        next if subfield_is_koha_internal_p($subtag);
(-)a/installer/data/mysql/sysprefs.sql (+3 lines)
Lines 360-362 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES Link Here
360
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('SocialNetworks','1','Enable/Disable social networks links in opac detail pages','','YesNo');
360
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('SocialNetworks','1','Enable/Disable social networks links in opac detail pages','','YesNo');
361
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('SubscriptionDuplicateDroppedInput','','','List of fields which must not be rewritten when a subscription is duplicated (Separated by pipe |)','Free');
361
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('SubscriptionDuplicateDroppedInput','','','List of fields which must not be rewritten when a subscription is duplicated (Separated by pipe |)','Free');
362
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('AutoResumeSuspendedHolds',  '1', NULL ,  'Allow suspended holds to be automatically resumed by a set date.',  'YesNo');
362
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('AutoResumeSuspendedHolds',  '1', NULL ,  'Allow suspended holds to be automatically resumed by a set date.',  'YesNo');
363
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');
364
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SubfieldsToUseWhenPrefill','','Define a list of subfields to use when prefilling items (separated by space)','','Free');
365
(-)a/installer/data/mysql/updatedatabase.pl (-2 / +19 lines)
Lines 4583-4588 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4583
    SetVersion($DBversion);
4583
    SetVersion($DBversion);
4584
}
4584
}
4585
4585
4586
<<<<<<< HEAD
4586
$DBversion = "3.07.00.005";
4587
$DBversion = "3.07.00.005";
4587
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4588
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4588
    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('BorrowerUnwantedField','','Name the fields you don''t need to store for a patron''s account',NULL,'free')");
4589
    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('BorrowerUnwantedField','','Name the fields you don''t need to store for a patron''s account',NULL,'free')");
Lines 5109-5114 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
5109
    SetVersion ($DBversion);
5110
    SetVersion ($DBversion);
5110
}
5111
}
5111
5112
5113
5114
5115
5116
5117
$DBversion = "3.06.03.002";
5118
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5119
    $dbh->do("
5120
    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');
5121
    ");
5122
5123
    $dbh->do(
5124
            "INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SubfieldsToUseWhenPrefill','','Define a list of subfields to use when prefilling items (separated by space)','','Free');"
5125
    );
5126
5127
    print "Upgrade to $DBversion done (Adding PrefillItem and SubfieldsToUseWhenPrefill sysprefs)\n";
5128
    SetVersion($DBversion);
5129
}
5130
5112
=head1 FUNCTIONS
5131
=head1 FUNCTIONS
5113
5132
5114
=head2 DropAllForeignKeys($table)
5133
=head2 DropAllForeignKeys($table)
Lines 5116-5123 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
5116
Drop all foreign keys of the table $table
5135
Drop all foreign keys of the table $table
5117
5136
5118
=cut
5137
=cut
5119
5120
5121
sub DropAllForeignKeys {
5138
sub DropAllForeignKeys {
5122
    my ($table) = @_;
5139
    my ($table) = @_;
5123
    # get the table description
5140
    # 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 use when prefilling items (separated by space)
101
            - pref: SubfieldsToUseWhenPrefill
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