[Koha-bugs] [Bug 7412] Pre-filling items in cataloguing
bugzilla-daemon at bugs.koha-community.org
bugzilla-daemon at bugs.koha-community.org
Sun Jun 10 12:21:10 CEST 2012
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=7412
Katrin Fischer <katrin.fischer at bsz-bw.de> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #7685|0 |1
is obsolete| |
--- Comment #20 from Katrin Fischer <katrin.fischer at bsz-bw.de> ---
Comment on attachment 7685
--> http://bugs.koha-community.org/bugzilla3/attachment.cgi?id=7685
proposed patch
>From f80b4d1115262d2cdace9eb7494da7c22116ebf0 Mon Sep 17 00:00:00 2001
>From: Matthias Meusburger <matthias.meusburger at biblibre.com>
>Date: Fri, 6 Jan 2012 14:55:45 +0100
>Subject: [PATCH] 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.
>If you want some subfields not to be prefilled, you can use the SubfieldsToDiscardWhenPrefill syspref.
>With a value of "f u v", the $f, $u and $v won't be prefilled, for example.
>---
> cataloguing/additem.pl | 123 +++++++++++++++++---
> installer/data/mysql/sysprefs.sql | 2 +
> installer/data/mysql/updatedatabase.pl | 16 +++-
> .../en/modules/admin/preferences/cataloguing.pref | 10 ++
> 4 files changed, 134 insertions(+), 17 deletions(-)
>
>diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl
>index a734d0f..b10c986 100755
>--- a/cataloguing/additem.pl
>+++ b/cataloguing/additem.pl
>@@ -32,6 +32,10 @@ use C4::Branch; # XXX subfield_is_koha_internal_p
> use C4::ClassSource;
> use C4::Dates;
> use List::MoreUtils qw/any/;
>+use Storable qw(thaw freeze);
>+use URI::Escape;
>+
>+
>
> use MARC::File::XML;
> use URI::Escape;
>@@ -275,6 +279,29 @@ sub generate_subfield_form {
> return \%subfield_data;
> }
>
>+# Removes some subfields (defined in the SubfieldsToDiscardWhenPrefill syspref) when prefilling items
>+sub removeFieldsForPrefill {
>+
>+ my $item = shift;
>+
>+ # Getting item tag
>+ my ($tag, $subtag) = GetMarcFromKohaField("items.barcode", '');
>+
>+ # Getting list of subfields to remove
>+ my $subfieldsToDiscardWhenPrefill = C4::Context->preference('SubfieldsToDiscardWhenPrefill');
>+
>+ # Removing subfields
>+ if ($tag && $subfieldsToDiscardWhenPrefill) {
>+ my $field = $item->field($tag);
>+ my @subfieldsToDiscard= split(/ /,$subfieldsToDiscardWhenPrefill);
>+ foreach my $subfieldsDiscard(@subfieldsToDiscard) {
>+ $field->delete_subfield(code => $subfieldsDiscard);
>+ }
>+ }
>+
>+ return $item;
>+
>+}
>
> my $input = new CGI;
> my $error = $input->param('error');
>@@ -315,9 +342,26 @@ my $oldrecord = TransformMarcToKoha($dbh,$record);
> my $itemrecord;
> my $nextop="additem";
> my @errors; # store errors found while checking data BEFORE saving item.
>+
>+# Getting last created item cookie
>+my $prefillitem = C4::Context->preference('PrefillItem');
>+my $justaddeditem;
>+my $cookieitemrecord;
>+if ($prefillitem) {
>+ my $lastitemcookie = $input->cookie('LastCreatedItem');
>+ if ($lastitemcookie) {
>+ $lastitemcookie = uri_unescape($lastitemcookie);
>+ if ( thaw($lastitemcookie) ) {
>+ $cookieitemrecord = thaw($lastitemcookie) ;
>+ $cookieitemrecord = removeFieldsForPrefill($cookieitemrecord);
>+ }
>+ }
>+}
>+
> #-------------------------------------------------------------------------------
> if ($op eq "additem") {
>-#-------------------------------------------------------------------------------
>+
>+ #-------------------------------------------------------------------------------
> # rebuild
> my @tags = $input->param('tag');
> my @subfields = $input->param('subfield');
>@@ -334,26 +378,69 @@ if ($op eq "additem") {
> my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
> my $number_of_copies = $input->param('number_of_copies');
>
>+ # This is a bit tricky : if there is a cookie for the last created item and
>+ # we just added an item, the cookie value is not correct yet (it will be updated
>+ # next page). To prevent the form from being filled with outdated values, we
>+ # force the use of "add and duplicate" feature, so the form will be filled with
>+ # correct values.
>+ $add_duplicate_submit = 1 if ($prefillitem);
>+ $justaddeditem = 1;
>+
>+ # if autoBarcode is set to 'incremental', calculate barcode...
>+ # NOTE: This code is subject to change in 3.2 with the implemenation of ajax based autobarcode code
>+ # NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
>+ if ( C4::Context->preference('autoBarcode') eq 'incremental' ) {
>+ my ( $tagfield, $tagsubfield ) = &GetMarcFromKohaField( "items.barcode", $frameworkcode );
>+ unless ( $record->field($tagfield)->subfield($tagsubfield) ) {
>+ my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items");
>+ $sth_barcode->execute;
>+ my ($newbarcode) = $sth_barcode->fetchrow;
>+ $newbarcode++;
>+
>+ # OK, we have the new barcode, now create the entry in MARC record
>+ my $fieldItem = $record->field($tagfield);
>+ $record->delete_field($fieldItem);
>+ $fieldItem->add_subfields( $tagsubfield => $newbarcode );
>+ $record->insert_fields_ordered($fieldItem);
>+ }
>+ }
>+
>+
> if (C4::Context->preference('autoBarcode') eq 'incremental') {
> $record = _increment_barcode($record, $frameworkcode);
> }
>
>- my $addedolditem = TransformMarcToKoha($dbh,$record);
>+ my $addedolditem = TransformMarcToKoha( $dbh, $record );
>
> # If we have to add or add & duplicate, we add the item
>- if ($add_submit || $add_duplicate_submit) {
>- # check for item barcode # being unique
>- my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
>- push @errors,"barcode_not_unique" if($exist_itemnumber);
>- # if barcode exists, don't create, but report The problem.
>- unless ($exist_itemnumber) {
>- my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber);
>- set_item_default_location($oldbibitemnum);
>- }
>- $nextop = "additem";
>- if ($exist_itemnumber) {
>- $itemrecord = $record;
>- }
>+ if ( $add_submit || $add_duplicate_submit ) {
>+
>+ # check for item barcode # being unique
>+ my $exist_itemnumber = get_item_from_barcode( $addedolditem->{'barcode'} );
>+ push @errors, "barcode_not_unique" if ($exist_itemnumber);
>+
>+ # if barcode exists, don't create, but report The problem.
>+ unless ($exist_itemnumber) {
>+ my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber );
>+ set_item_default_location($oldbibitemnum);
>+
>+ # Pushing the last created item cookie back
>+ if ($prefillitem && defined $record) {
>+ my $itemcookie = $input->cookie(
>+ -name => 'LastCreatedItem',
>+ # We uri_escape the whole freezed structure so we're sure we won't have any encoding problems
>+ -value => uri_escape( freeze( $record ) ),
>+ -expires => ''
>+ );
>+
>+ $cookie = ( $cookie, $itemcookie );
>+ }
>+
>+ }
>+ $nextop = "additem";
>+ if ($exist_itemnumber) {
>+ $itemrecord = $record;
>+ }
> }
>
> # If we have to add & duplicate
>@@ -370,6 +457,7 @@ if ($op eq "additem") {
> $fieldItem->delete_subfields($tagsubfield);
> $itemrecord->insert_fields_ordered($fieldItem);
> }
>+ $itemrecord = removeFieldsForPrefill($itemrecord) if ($prefillitem);
> }
>
> # If we have to add multiple copies
>@@ -698,6 +786,11 @@ if($itemrecord){
> }
> # and now we add fields that are empty
>
>+# Using last created item if it exists
>+
>+$itemrecord = $cookieitemrecord if ($prefillitem and not $justaddeditem and $op ne "edititem");
>+
>+# We generate form, and fill with values if defined
> foreach my $tag ( keys %{$tagslib}){
> foreach my $subtag (keys %{$tagslib->{$tag}}){
> next if subfield_is_koha_internal_p($subtag);
>diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql
>index 128c9b2..e9070a8 100755
>--- a/installer/data/mysql/sysprefs.sql
>+++ b/installer/data/mysql/sysprefs.sql
>@@ -328,4 +328,6 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('
> INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OpacKohaUrl','1',"Show 'Powered by Koha' text on OPAC footer.",NULL,NULL);
> 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');
> 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');
>+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');
>+INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SubfieldsToDiscardWhenPrefill','','Define a list of subfields to discard when prefilling items (separated by space)','','Free');
>
>diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
>index 67708fa..014b96e 100755
>--- a/installer/data/mysql/updatedatabase.pl
>+++ b/installer/data/mysql/updatedatabase.pl
>@@ -4585,6 +4585,20 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
> SetVersion($DBversion);
> }
>
>+$DBversion = "3.06.03.002";
>+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
>+ $dbh->do("
>+ 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');
>+ ");
>+
>+ $dbh->do(
>+ "INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SubfieldsToDiscardWhenPrefill','','Define a list of subfields to discard when prefilling items (separated by space)','','Free');"
>+ );
>+
>+ print "Upgrade to $DBversion done (Adding PrefillItem and SubfieldsToDiscardWhenPrefill sysprefs)\n";
>+ SetVersion($DBversion);
>+}
>+
> =head1 FUNCTIONS
>
> =head2 DropAllForeignKeys($table)
>@@ -4592,8 +4606,6 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
> Drop all foreign keys of the table $table
>
> =cut
>-
>-
> sub DropAllForeignKeys {
> my ($table) = @_;
> # get the table description
>diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
>index 10e1d13..885c73d 100644
>--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
>+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
>@@ -90,6 +90,16 @@ Cataloging:
> annual: generated in the form <year>-0001, <year>-0002.
> hbyymmincr: generated in the form <branchcode>yymm0001.
> "OFF": not generated automatically.
>+ -
>+ - When a new item is added, should it be prefilled with last created item values?
>+ - pref: PrefillItem
>+ choices:
>+ yes: the new item is prefilled with last created item values
>+ no: the new item is not prefilled with last created item values
>+ -
>+ - Define a list of subfields to discard when prefilling items (separated by space)
>+ - pref: SubfieldsToDiscardWhenPrefill
>+
> Display:
> -
> - 'Separate multiple displayed authors, series or subjects with '
>--
>1.7.5.4
>
--
You are receiving this mail because:
You are watching all bug changes.
More information about the Koha-bugs
mailing list