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

(-)a/cataloguing/additem.pl (-15 / +104 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
sub removeFieldsForPrefill {
283
    #FIXME: this is not generic enough. We could define fields to remove in a syspref.
284
    my $item = shift;
285
    # Getting item tag
286
    my ($tag, $subtag) = GetMarcFromKohaField("items.barcode", '');
287
    if ($tag) {
288
        my $field = $item->field($tag);
289
        if ($field) {
290
            $field->delete_subfield(code => 'f');
291
            $field->delete_subfield(code => 'k');
292
            $field->delete_subfield(code => 'u');
293
            $field->delete_subfield(code => 'v');
294
            $field->delete_subfield(code => 'x');
295
            $field->delete_subfield(code => 'z');
296
        }
297
    }
298
    return $item;
299
300
}
278
301
279
my $input        = new CGI;
302
my $input        = new CGI;
280
my $error        = $input->param('error');
303
my $error        = $input->param('error');
Lines 315-323 my $oldrecord = TransformMarcToKoha($dbh,$record); Link Here
315
my $itemrecord;
338
my $itemrecord;
316
my $nextop="additem";
339
my $nextop="additem";
317
my @errors; # store errors found while checking data BEFORE saving item.
340
my @errors; # store errors found while checking data BEFORE saving item.
341
342
# Getting last created item cookie
343
my $prefillitem = C4::Context->preference('PrefillItem');
344
my $justaddeditem;
345
my $cookieitemrecord;
346
if ($prefillitem) {
347
    my $lastitemcookie = $input->cookie('LastCreatedItem');
348
    if ($lastitemcookie) {
349
	$lastitemcookie = uri_unescape($lastitemcookie);
350
	if ( thaw($lastitemcookie) ) {
351
	    $cookieitemrecord = thaw($lastitemcookie) ;
352
	    $cookieitemrecord = removeFieldsForPrefill($cookieitemrecord);
353
	}
354
    }
355
}
356
318
#-------------------------------------------------------------------------------
357
#-------------------------------------------------------------------------------
319
if ($op eq "additem") {
358
if ($op eq "additem") {
320
#-------------------------------------------------------------------------------
359
360
    #-------------------------------------------------------------------------------
321
    # rebuild
361
    # rebuild
322
    my @tags      = $input->param('tag');
362
    my @tags      = $input->param('tag');
323
    my @subfields = $input->param('subfield');
363
    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');
374
    my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
335
    my $number_of_copies           = $input->param('number_of_copies');
375
    my $number_of_copies           = $input->param('number_of_copies');
336
376
377
    # This is a bit tricky : if there is a cookie for the last created item and
378
    # we just added an item, the cookie value is not correct yet (it will be updated
379
    # next page). To prevent the form from being filled with outdated values, we
380
    # force the use of "add and duplicate" feature, so the form will be filled with 
381
    # correct values.
382
    $add_duplicate_submit = 1 if ($prefillitem);
383
    $justaddeditem = 1;
384
385
    # if autoBarcode is set to 'incremental', calculate barcode...
386
    # NOTE: This code is subject to change in 3.2 with the implemenation of ajax based autobarcode code
387
    # NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
388
    if ( C4::Context->preference('autoBarcode') eq 'incremental' ) {
389
        my ( $tagfield, $tagsubfield ) = &GetMarcFromKohaField( "items.barcode", $frameworkcode );
390
        unless ( $record->field($tagfield)->subfield($tagsubfield) ) {
391
            my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items");
392
            $sth_barcode->execute;
393
            my ($newbarcode) = $sth_barcode->fetchrow;
394
            $newbarcode++;
395
396
            # OK, we have the new barcode, now create the entry in MARC record
397
            my $fieldItem = $record->field($tagfield);
398
            $record->delete_field($fieldItem);
399
            $fieldItem->add_subfields( $tagsubfield => $newbarcode );
400
            $record->insert_fields_ordered($fieldItem);
401
        }
402
    }
403
404
337
    if (C4::Context->preference('autoBarcode') eq 'incremental') {
405
    if (C4::Context->preference('autoBarcode') eq 'incremental') {
338
        $record = _increment_barcode($record, $frameworkcode);
406
        $record = _increment_barcode($record, $frameworkcode);
339
    }
407
    }
340
408
341
    my $addedolditem = TransformMarcToKoha($dbh,$record);
409
    my $addedolditem = TransformMarcToKoha( $dbh, $record );
342
410
343
    # If we have to add or add & duplicate, we add the item
411
    # If we have to add or add & duplicate, we add the item
344
    if ($add_submit || $add_duplicate_submit) {
412
    if ( $add_submit || $add_duplicate_submit ) {
345
	# check for item barcode # being unique
413
346
	my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
414
        # check for item barcode # being unique
347
	push @errors,"barcode_not_unique" if($exist_itemnumber);
415
        my $exist_itemnumber = get_item_from_barcode( $addedolditem->{'barcode'} );
348
	# if barcode exists, don't create, but report The problem.
416
        push @errors, "barcode_not_unique" if ($exist_itemnumber);
349
    unless ($exist_itemnumber) {
417
350
	    my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber);
418
        # if barcode exists, don't create, but report The problem.
351
        set_item_default_location($oldbibitemnum);
419
        unless ($exist_itemnumber) {
352
    }
420
            my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber );
353
	$nextop = "additem";
421
            set_item_default_location($oldbibitemnum);
354
	if ($exist_itemnumber) {
422
355
	    $itemrecord = $record;
423
	  # Pushing the last created item cookie back
356
	}
424
	  if ($prefillitem && defined $record) {
425
                my $itemcookie = $input->cookie(
426
                    -name => 'LastCreatedItem',
427
                    # We uri_escape the whole freezed structure so we're sure we won't have any encoding problems
428
                    -value   => uri_escape( freeze( $record ) ),
429
                    -expires => ''
430
                );
431
432
		$cookie = ( $cookie, $itemcookie );
433
	    }
434
435
        }
436
        $nextop = "additem";
437
        if ($exist_itemnumber) {
438
            $itemrecord = $record;
439
        }
357
    }
440
    }
358
441
359
    # If we have to add & duplicate
442
    # If we have to add & duplicate
Lines 370-375 if ($op eq "additem") { Link Here
370
            $fieldItem->delete_subfields($tagsubfield);
453
            $fieldItem->delete_subfields($tagsubfield);
371
            $itemrecord->insert_fields_ordered($fieldItem);
454
            $itemrecord->insert_fields_ordered($fieldItem);
372
        }
455
        }
456
	$itemrecord = removeFieldsForPrefill($itemrecord) if ($prefillitem);
373
    }
457
    }
374
458
375
    # If we have to add multiple copies
459
    # If we have to add multiple copies
Lines 698-703 if($itemrecord){ Link Here
698
            }
782
            }
699
    # and now we add fields that are empty
783
    # and now we add fields that are empty
700
784
785
# Using last created item if it exists
786
787
$itemrecord = $cookieitemrecord if ($prefillitem and not $justaddeditem and $op ne "edititem"); 
788
789
# We generate form, and fill with values if defined
701
foreach my $tag ( keys %{$tagslib}){
790
foreach my $tag ( keys %{$tagslib}){
702
    foreach my $subtag (keys %{$tagslib->{$tag}}){
791
    foreach my $subtag (keys %{$tagslib->{$tag}}){
703
        next if subfield_is_koha_internal_p($subtag);
792
        next if subfield_is_koha_internal_p($subtag);
(-)a/installer/data/mysql/sysprefs.sql (-1 / +1 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
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');
(-)a/installer/data/mysql/updatedatabase.pl (-2 / +9 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
    print "Upgrade to $DBversion done (Adding PrefillItem syspref)\n";
4594
    SetVersion($DBversion);
4595
}
4596
4588
=head1 FUNCTIONS
4597
=head1 FUNCTIONS
4589
4598
4590
=head2 DropAllForeignKeys($table)
4599
=head2 DropAllForeignKeys($table)
Lines 4592-4599 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4592
Drop all foreign keys of the table $table
4601
Drop all foreign keys of the table $table
4593
4602
4594
=cut
4603
=cut
4595
4596
4597
sub DropAllForeignKeys {
4604
sub DropAllForeignKeys {
4598
    my ($table) = @_;
4605
    my ($table) = @_;
4599
    # get the table description
4606
    # get the table description
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (-1 / +6 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
93
    Display:
99
    Display:
94
        -
100
        -
95
            - 'Separate multiple displayed authors, series or subjects with '
101
            - 'Separate multiple displayed authors, series or subjects with '
96
- 

Return to bug 7412