Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Bug 7412: Pre-filling items in cataloguing

Pre-filling of items: remember what was in the previous item filled, to be able to create multiple items quickly.

By default, all subfields are prefilled when the PrefillItem syspref is on, unless you specify which fields
you want to prefill in the SubfieldsToUseWhenPrefill syspref.
With a value of "f u v", only the $f, $u and $v will be prefilled, for example.

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Rebased and QAed.
  • Loading branch information...
commit 245d6634fe446d76ad16494ed8e75ff5fe7687e5 1 parent 7e6690f
Matthias Meusburger veggiematts authored PaulPoulain committed
112 cataloguing/additem.pl
@@ -33,6 +33,9 @@
33 33 use C4::Dates;
34 34 use List::MoreUtils qw/any/;
35 35 use C4::Search;
  36 +use Storable qw(thaw freeze);
  37 +use URI::Escape;
  38 +
36 39
37 40 use MARC::File::XML;
38 41 use URI::Escape;
@@ -277,6 +280,33 @@ sub generate_subfield_form {
277 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 311 my $input = new CGI;
282 312 my $error = $input->param('error');
@@ -315,9 +345,26 @@ sub generate_subfield_form {
315 345 my $itemrecord;
316 346 my $nextop="additem";
317 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 365 if ($op eq "additem") {
320   -#-------------------------------------------------------------------------------
  366 +
  367 + #-------------------------------------------------------------------------------
321 368 # rebuild
322 369 my @tags = $input->param('tag');
323 370 my @subfields = $input->param('subfield');
@@ -334,26 +381,55 @@ sub generate_subfield_form {
334 381 my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
335 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 + if ( C4::Context->preference('autoBarcode') eq 'incremental' ) {
  394 + $record = _increment_barcode($record, $frameworkcode);
  395 + }
  396 +
  397 +
337 398 if (C4::Context->preference('autoBarcode') eq 'incremental') {
338 399 $record = _increment_barcode($record, $frameworkcode);
339 400 }
340 401
341   - my $addedolditem = TransformMarcToKoha($dbh,$record);
  402 + my $addedolditem = TransformMarcToKoha( $dbh, $record );
342 403
343 404 # If we have to add or add & duplicate, we add the item
344   - if ($add_submit || $add_duplicate_submit) {
345   - # check for item barcode # being unique
346   - my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
347   - push @errors,"barcode_not_unique" if($exist_itemnumber);
348   - # if barcode exists, don't create, but report The problem.
349   - unless ($exist_itemnumber) {
350   - my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber);
351   - set_item_default_location($oldbibitemnum);
352   - }
353   - $nextop = "additem";
354   - if ($exist_itemnumber) {
355   - $itemrecord = $record;
356   - }
  405 + if ( $add_submit || $add_duplicate_submit ) {
  406 +
  407 + # check for item barcode # being unique
  408 + my $exist_itemnumber = get_item_from_barcode( $addedolditem->{'barcode'} );
  409 + push @errors, "barcode_not_unique" if ($exist_itemnumber);
  410 +
  411 + # if barcode exists, don't create, but report The problem.
  412 + unless ($exist_itemnumber) {
  413 + my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber );
  414 + set_item_default_location($oldbibitemnum);
  415 +
  416 + # Pushing the last created item cookie back
  417 + if ($prefillitem && defined $record) {
  418 + my $itemcookie = $input->cookie(
  419 + -name => 'LastCreatedItem',
  420 + # We uri_escape the whole freezed structure so we're sure we won't have any encoding problems
  421 + -value => uri_escape_utf8( freeze( $record ) ),
  422 + -expires => ''
  423 + );
  424 +
  425 + $cookie = [ $cookie, $itemcookie ];
  426 + }
  427 +
  428 + }
  429 + $nextop = "additem";
  430 + if ($exist_itemnumber) {
  431 + $itemrecord = $record;
  432 + }
357 433 }
358 434
359 435 # If we have to add & duplicate
@@ -370,6 +446,7 @@ sub generate_subfield_form {
370 446 $fieldItem->delete_subfields($tagsubfield);
371 447 $itemrecord->insert_fields_ordered($fieldItem);
372 448 }
  449 + $itemrecord = removeFieldsForPrefill($itemrecord) if ($prefillitem);
373 450 }
374 451
375 452 # If we have to add multiple copies
@@ -696,6 +773,11 @@ sub generate_subfield_form {
696 773 }
697 774 # and now we add fields that are empty
698 775
  776 +# Using last created item if it exists
  777 +
  778 +$itemrecord = $cookieitemrecord if ($prefillitem and not $justaddeditem and $op ne "edititem");
  779 +
  780 +# We generate form, and fill with values if defined
699 781 foreach my $tag ( keys %{$tagslib}){
700 782 foreach my $subtag (keys %{$tagslib->{$tag}}){
701 783 next if subfield_is_koha_internal_p($subtag);
2  installer/data/mysql/sysprefs.sql
@@ -367,3 +367,5 @@ INSERT INTO systempreferences (variable,value,explanation,type) VALUES('EnableBo
367 367 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('UpdateTotalIssuesOnCirc','0','Whether to update the totalissues field in the biblio on each circ.',NULL,'YesNo');
368 368 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('IntranetSlipPrinterJS','','Use this JavaScript for printing slips. Define at least function printThenClose(). For use e.g. with Firefox PlugIn jsPrintSetup, see http://jsprintsetup.mozdev.org/','','Free');
369 369 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacSuppressionByIPRange','','Restrict the suppression to IP adresses outside of the IP range','','free');
  370 +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');
  371 +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SubfieldsToUseWhenPrefill','','Define a list of subfields to use when prefilling items (separated by space)','','Free');
14 installer/data/mysql/updatedatabase.pl
@@ -5669,6 +5669,18 @@ sub stocknumber_checker { #code reused later on
5669 5669 $dbh->do("UPDATE auth_subfield_structure SET frameworkcode = 'PERSO_NAME' WHERE frameworkcode = 'PERSO_CODE'");
5670 5670 $dbh->do("UPDATE auth_subfield_structure SET frameworkcode = 'CORPO_NAME' WHERE frameworkcode = 'ORGO_CODE'");
5671 5671 print "Upgrade to $DBversion done (Bug 8207: correct typo in authority types)\n";
  5672 + SetVersion ($DBversion);
  5673 +}
  5674 +
  5675 +$DBversion = "3.09.00.035";
  5676 +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
  5677 + $dbh->do("
  5678 + 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');
  5679 + ");
  5680 + $dbh->do(
  5681 + "INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SubfieldsToUseWhenPrefill','','Define a list of subfields to use when prefilling items (separated by space)','','Free');
  5682 + ");
  5683 + print "Upgrade to $DBversion done (Adding PrefillItem and SubfieldsToUseWhenPrefill sysprefs)\n";
5672 5684 SetVersion($DBversion);
5673 5685 }
5674 5686
@@ -5694,8 +5706,6 @@ =head2 DropAllForeignKeys($table)
5694 5706 Drop all foreign keys of the table $table
5695 5707
5696 5708 =cut
5697   -
5698   -
5699 5709 sub DropAllForeignKeys {
5700 5710 my ($table) = @_;
5701 5711 # get the table description
10 koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
@@ -95,6 +95,16 @@ Cataloging:
95 95 hbyymmincr: generated in the form &lt;branchcode&gt;yymm0001.
96 96 EAN13: incremental EAN-13 barcodes
97 97 "OFF": not generated automatically.
  98 + -
  99 + - When a new item is added, should it be prefilled with last created item values?
  100 + - pref: PrefillItem
  101 + choices:
  102 + yes: the new item is prefilled with last created item values
  103 + no: the new item is not prefilled with last created item values
  104 + -
  105 + - Define a list of subfields to use when prefilling items (separated by space)
  106 + - pref: SubfieldsToUseWhenPrefill
  107 +
98 108 Display:
99 109 -
100 110 - 'Separate multiple displayed authors, series or subjects with '

0 comments on commit 245d663

Please sign in to comment.
Something went wrong with that request. Please try again.