@@ -, +, @@ Bug 5725 : Follow up fixing permissions thanks to Paul Poulain Bug 5725 follow up Owen noticed the batchedit was not working. This was because we made a patch months ago to change the GetBiblio API (the 1st returned arg is useless) This patch is not in main trunk, resulting in the error owen has noticed. This patch goes back to official API (even if it is clumsy : the patch we did does not apply anymore) Bug 5725 : MT #2991 (Feature) Batch biblio modifications This patch add a new feature of batch biblio modifications, it permit to select biblios from basket, and modify fields of them setting Rebased to fix whitespace issues. --- C4/Biblio.pm | 90 ++++++++ installer/data/mysql/updatedatabase.pl | 10 +- koha-tmpl/intranet-tmpl/prog/en/js/basket.js | 6 + .../intranet-tmpl/prog/en/modules/basket/basket.tt | 7 + .../prog/en/modules/tools/batchedit.tt | 227 ++++++++++++++++++++ kohaversion.pl | 2 +- tools/batchedit.pl | 222 +++++++++++++++++++ 7 files changed, 562 insertions(+), 2 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchedit.tt create mode 100755 tools/batchedit.pl --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -128,6 +128,7 @@ BEGIN { &TransformHtmlToXml &PrepareItemrecordDisplay &GetNoZebraIndexes + &BatchModField ); } @@ -3681,6 +3682,95 @@ sub get_biblio_authorised_values { return $authorised_values; } +=head3 BatchModField + + Mod subfields in field record + + returns 1,$record if succeed + returns 0,$record if Action was not processed + returns -1 if no record + returns -2 if no action done on record + +=cut + +sub BatchModField { + my ( $record, $field, $subfield, $action, $condval, $nocond, $repval ) = @_; + + return -1 unless $record; + $condval=NormalizeString($condval); + my $condition=qr/$condval/; + + if($action eq "add"){ + for my $rfield ($record->field($field)){ + $rfield->add_subfields( $subfield => $repval ); + } + return 1; + }elsif($action eq "addfield"){ + my $new_field = MARC::Field->new($field,'','', + $subfield => $repval); + $record->insert_fields_ordered($new_field); + return 1; + } else { + my $done=0; + for my $rfield ($record->field($field)) { + if ($subfield && $subfield ne "@"){ + my @subfields = $rfield->subfields(); + my @subfields_to_add; + foreach my $subf (@subfields) { + if ($subf->[0] eq $subfield){ + $subf->[1]=NormalizeString($subf->[1]); + if ( $action eq "mod" ) { + if ( $nocond ne "true" && $subf->[1] =~ s/$condition/$repval/) { + $done=1; + } + if ($nocond eq "true"){ + $subf->[1] = $repval; + $done=1; + } + } elsif ( $action eq "del" ) { + if ( $subf->[1] =~ m/$condition/ || $nocond eq "true" ) { + $done=1; + next; + } + } + } + push @subfields_to_add,@$subf; + } + if ($done){ + if (@subfields_to_add){ + $rfield->replace_with(MARC::Field->new($rfield->tag,$rfield->indicator(1),$rfield->indicator(2),@subfields_to_add)); + } + else { + my $count= $record->delete_field($rfield); + } + } + } + else { + if ($action eq "del"){ + my $count=$record->delete_field($rfield); + $done=1; + } + else { + if ($field < 10){ + my $value=$record->field($field)->data(); + if ($value=~ s/$condition/$repval/){ + $record->field($field)->update($value); + $done=1; + + } + if ( $nocond eq 'true'){ + $record->field($field)->update($repval); + $done=1; + } + } + } + } + } + return ($done,$record); + } + return -2; +} + 1; __END__ --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -4365,11 +4365,19 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { $DBversion = "3.05.00.004"; if (C4::Context->preference("Version") < TransformToNum($DBversion)) { - $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ShowReviewerPhoto',1,'If ON, photo of reviewer will be shown beside comments in OPAC',NULL,'YesNo');"); + $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ShowReviewerPhoto',1,'If ON, photo of reviewer will be shown beside comments in OPAC',NULL,'YesNo')"); print "Upgrade to $DBversion done (Add syspref ShowReviewerPhoto)\n"; SetVersion($DBversion); } +$DBversion = "3.05.00.005"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'batchedit', 'Batch editing biblios')"); + print "Upgrade to $DBversion done (batch edit permission)\n"; + SetVersion($DBversion); +} + + =head1 FUNCTIONS =head2 DropAllForeignKeys($table) --- a/koha-tmpl/intranet-tmpl/prog/en/js/basket.js +++ a/koha-tmpl/intranet-tmpl/prog/en/js/basket.js @@ -433,4 +433,10 @@ $(document).ready(function(){ if(basketcount){ updateBasket(basketcount); } }); +function batchEdit(){ + var valCookie = readCookie(nameCookie); + var strCookie = nameParam + "=" + valCookie; + var loc = CGIBIN + "tools/batchedit.pl?" + strCookie; + window.opener.location = loc; +} --- a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt @@ -86,6 +86,13 @@ function placeHold () { [% IF ( verbose ) %]Brief Display[% ELSE %]More Details[% END %] + [% IF ( CAN_user_tools_batchedit ) %] +